mirror of
http://cgit.git.savannah.gnu.org/git/grub.git
synced 2026-04-28 14:33:34 +00:00
Compare commits
264 Commits
phcoder/c3
...
phcoder/ve
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2cdd6159d7 | ||
|
|
ba5401b197 | ||
|
|
4f280d955e | ||
|
|
09bd17faaa | ||
|
|
aa93127ed8 | ||
|
|
c4b8bec5fe | ||
|
|
70b555a52a | ||
|
|
c6eaa982d1 | ||
|
|
5c3fd1b135 | ||
|
|
b0b1b81a11 | ||
|
|
c4313c812d | ||
|
|
4f8471532d | ||
|
|
d11ced1e1f | ||
|
|
058df7b5a9 | ||
|
|
265292f2b0 | ||
|
|
656c3b0d7f | ||
|
|
3edabad8fe | ||
|
|
848bed9d92 | ||
|
|
216950a4ee | ||
|
|
ac6b41b89f | ||
|
|
5a865b3786 | ||
|
|
fcbb723d4b | ||
|
|
24e37a8852 | ||
|
|
9808c3ef95 | ||
|
|
1daa716c70 | ||
|
|
461bfab7b7 | ||
|
|
d08c968514 | ||
|
|
a35ac85430 | ||
|
|
d9f7de0ae3 | ||
|
|
dc6e1b5af8 | ||
|
|
ede6c96893 | ||
|
|
a827807a13 | ||
|
|
1073ddb120 | ||
|
|
4341f82af0 | ||
|
|
c2ea443446 | ||
|
|
608bec5112 | ||
|
|
6dec3a26b3 | ||
|
|
b43b8cacc8 | ||
|
|
37865c2c4a | ||
|
|
5a0c548ba3 | ||
|
|
b0bad6fd94 | ||
|
|
e54c99aaff | ||
|
|
d454509bb8 | ||
|
|
007f0b407f | ||
|
|
4bd4a88725 | ||
|
|
6cef7f6079 | ||
|
|
ec4af117c6 | ||
|
|
8014b7b337 | ||
|
|
fcea891e17 | ||
|
|
c42cb97f08 | ||
|
|
bcf3c55531 | ||
|
|
fb93c75bdd | ||
|
|
641bb15fa4 | ||
|
|
f34ed1f53c | ||
|
|
892dfbe113 | ||
|
|
951306c509 | ||
|
|
512bb31cbc | ||
|
|
2fb8cd26a9 | ||
|
|
529818738f | ||
|
|
8a96fc4093 | ||
|
|
f3df8f961f | ||
|
|
ec4aca088a | ||
|
|
fcb1528d93 | ||
|
|
c36c0e05f1 | ||
|
|
c96cfac167 | ||
|
|
bf94ef7fbd | ||
|
|
5412028d19 | ||
|
|
c65d35b08b | ||
|
|
a5bd52990e | ||
|
|
1d4e3db907 | ||
|
|
4e5414b2a1 | ||
|
|
1402cdd96a | ||
|
|
31932a267c | ||
|
|
393cc59195 | ||
|
|
dac87d6032 | ||
|
|
42e24b6006 | ||
|
|
08438d783f | ||
|
|
34fe0b5901 | ||
|
|
377c121170 | ||
|
|
43b444e593 | ||
|
|
ea20dd2b22 | ||
|
|
3d173955f0 | ||
|
|
68c6cec061 | ||
|
|
0704e83a1b | ||
|
|
f14c77f501 | ||
|
|
0fd9fa565b | ||
|
|
6f5aa28bc2 | ||
|
|
a134ef1ab9 | ||
|
|
255b9e0bea | ||
|
|
b53f595b3e | ||
|
|
6371e9c104 | ||
|
|
d15f17b2a0 | ||
|
|
a0413e2677 | ||
|
|
43dbf83aa2 | ||
|
|
bec592aa87 | ||
|
|
79fc008935 | ||
|
|
bf9c561670 | ||
|
|
afa9dda37e | ||
|
|
cde63a3bb0 | ||
|
|
bf0e59cebf | ||
|
|
a2932fbe8a | ||
|
|
972765fe82 | ||
|
|
07662af7ae | ||
|
|
562c406763 | ||
|
|
ce95549cc5 | ||
|
|
a3e9da054d | ||
|
|
130234bc78 | ||
|
|
7b4c54c4ad | ||
|
|
0d2345774d | ||
|
|
c9a8d037a8 | ||
|
|
f8c3af3b61 | ||
|
|
0af7539bd2 | ||
|
|
0d663b50b9 | ||
|
|
28511b0da9 | ||
|
|
e1b099fb69 | ||
|
|
fbca374105 | ||
|
|
5f311e86d2 | ||
|
|
0de3eeb623 | ||
|
|
b67a95ecad | ||
|
|
5500cefccd | ||
|
|
d73976fdff | ||
|
|
1fbb2b4b39 | ||
|
|
c221ea06b5 | ||
|
|
72c28509fa | ||
|
|
7e5fcb0b34 | ||
|
|
6ae55ce103 | ||
|
|
c69d1858f1 | ||
|
|
4231927e44 | ||
|
|
a620876e3b | ||
|
|
f2b6c20a25 | ||
|
|
ba89c19f49 | ||
|
|
9862b24121 | ||
|
|
e563928ba4 | ||
|
|
a0bf403f66 | ||
|
|
4e0f8f66e3 | ||
|
|
c831d2073b | ||
|
|
52408aa946 | ||
|
|
58590cb2ef | ||
|
|
b524fa27f5 | ||
|
|
e045af148a | ||
|
|
13f7ead3a1 | ||
|
|
7a5b301e3a | ||
|
|
abf9beb7d6 | ||
|
|
f4d35d49e3 | ||
|
|
6714d7ecff | ||
|
|
5b8ddf6e03 | ||
|
|
76eac44af3 | ||
|
|
ee83919e93 | ||
|
|
3c3e96d044 | ||
|
|
15aee573d2 | ||
|
|
7f2a856fae | ||
|
|
9545a8fd04 | ||
|
|
082bc9f77b | ||
|
|
d017ea8ede | ||
|
|
8207874e5d | ||
|
|
102e435d81 | ||
|
|
51f375d688 | ||
|
|
ca028db3d4 | ||
|
|
0f076d75d0 | ||
|
|
86ef66d977 | ||
|
|
5bcb7d394c | ||
|
|
df21fff504 | ||
|
|
73a9c742fe | ||
|
|
dd3969e7ec | ||
|
|
36212460d3 | ||
|
|
2ebef43cf6 | ||
|
|
8c26dace6f | ||
|
|
070e190305 | ||
|
|
109189ce01 | ||
|
|
b00e4c2bd9 | ||
|
|
06a3b0b214 | ||
|
|
5486a4e12b | ||
|
|
eb9f401fc1 | ||
|
|
94c56a4c65 | ||
|
|
1b782e902e | ||
|
|
15dfea842c | ||
|
|
054d1325e9 | ||
|
|
0678b5d629 | ||
|
|
be4e9d20a5 | ||
|
|
bc220962e3 | ||
|
|
625934ec0f | ||
|
|
e3745f9087 | ||
|
|
01d50c2539 | ||
|
|
8d69065f52 | ||
|
|
59ec05bcf8 | ||
|
|
fabde8324d | ||
|
|
5cae910665 | ||
|
|
25492a0f04 | ||
|
|
080a20861c | ||
|
|
f96b34224e | ||
|
|
a2ab8c2172 | ||
|
|
ce01054ec3 | ||
|
|
feef882f98 | ||
|
|
eba6db6323 | ||
|
|
6e1ace590a | ||
|
|
7c35f65aac | ||
|
|
4598cafa7d | ||
|
|
6f4189ffc1 | ||
|
|
127cfea8be | ||
|
|
22aa31bcc3 | ||
|
|
e72de13b9e | ||
|
|
342d6edb97 | ||
|
|
e5c9300191 | ||
|
|
d9a3bfead8 | ||
|
|
1933d37371 | ||
|
|
b29638222e | ||
|
|
8ad190cac2 | ||
|
|
281baeecd3 | ||
|
|
df4df4d887 | ||
|
|
2d425ffdd5 | ||
|
|
67dba97e45 | ||
|
|
7290bb5623 | ||
|
|
ff84a9b868 | ||
|
|
605eecc985 | ||
|
|
b6a03dfd32 | ||
|
|
5f2b285bf8 | ||
|
|
ae3b83a4d4 | ||
|
|
dab148891e | ||
|
|
64e2d139fe | ||
|
|
0edd750e50 | ||
|
|
cc2ed41039 | ||
|
|
7c6c2ad42c | ||
|
|
47e67d809c | ||
|
|
92bbf25714 | ||
|
|
95440b41d3 | ||
|
|
f826d914e2 | ||
|
|
77002c65d3 | ||
|
|
d4561cd080 | ||
|
|
9b4256bf05 | ||
|
|
eefa3239c2 | ||
|
|
4f8fe948b9 | ||
|
|
b95e926788 | ||
|
|
26533fe6bc | ||
|
|
29862fdc3a | ||
|
|
9daf7aae8b | ||
|
|
a4b1326f0d | ||
|
|
dbb0f9fa4f | ||
|
|
e9d71db53a | ||
|
|
6c35ce72ba | ||
|
|
f3c84fa798 | ||
|
|
5db2190f2c | ||
|
|
1bff60e5aa | ||
|
|
8fe17d91af | ||
|
|
66768b99f1 | ||
|
|
962b69d950 | ||
|
|
528256932b | ||
|
|
269a522c7d | ||
|
|
5a5a3c6963 | ||
|
|
670c43af27 | ||
|
|
dc27d254f2 | ||
|
|
31f6506c57 | ||
|
|
9fecb0588e | ||
|
|
aafd205c92 | ||
|
|
bd60f5a207 | ||
|
|
725548a285 | ||
|
|
d5cc487d39 | ||
|
|
fa2af21ec8 | ||
|
|
0e075ac385 | ||
|
|
57e7f1b775 | ||
|
|
67d9ce82ac | ||
|
|
12bf87466f | ||
|
|
97c41e1216 | ||
|
|
8ab2675ede | ||
|
|
efc04d65c7 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -246,3 +246,4 @@ build-aux/test-driver
|
||||
/garbage-gen
|
||||
/garbage-gen.exe
|
||||
/grub-fs-tester
|
||||
grub-core/build-grub-module-verifier
|
||||
|
||||
7
INSTALL
7
INSTALL
@@ -15,15 +15,14 @@ configuring the GRUB.
|
||||
Note: older versions may work but support is limited
|
||||
|
||||
Experimental support for clang 3.3 or later (results in much bigger binaries)
|
||||
for i386, x86_64, arm (except thumb), arm64, mips(el), powerpc, sparc64
|
||||
for i386, x86_64, arm (including thumb), arm64, mips(el), powerpc, sparc64
|
||||
Note: clang 3.2 or later works for i386 and x86_64 targets but results in
|
||||
much bigger binaries.
|
||||
earlier versions not tested
|
||||
Note: clang 3.2 or later works for arm
|
||||
None of tested clang versions generated usable thumb code
|
||||
earlier versions not tested
|
||||
Note: clang 3.3 or later works for arm64
|
||||
earlier versions have no arm64 support
|
||||
Note: clang on arm64 is not supported due to
|
||||
https://llvm.org/bugs/show_bug.cgi?id=26030
|
||||
Note: clang 3.3 or later works for mips(el)
|
||||
earlier versions fail to generate .reginfo and hence gprel relocations
|
||||
fail.
|
||||
|
||||
70
Makefile.am
70
Makefile.am
@@ -145,109 +145,116 @@ if COND_real_platform
|
||||
|
||||
if COND_i386_coreboot
|
||||
QEMU32=qemu-system-i386
|
||||
MINIMUM_CPU_LINUX=pentium2
|
||||
endif
|
||||
|
||||
if COND_i386_multiboot
|
||||
QEMU32=qemu-system-i386
|
||||
MINIMUM_CPU_LINUX=pentium2
|
||||
endif
|
||||
|
||||
if COND_i386_ieee1275
|
||||
QEMU32=qemu-system-i386
|
||||
MINIMUM_CPU_LINUX=pentium2
|
||||
endif
|
||||
|
||||
if COND_i386_qemu
|
||||
QEMU32=qemu-system-i386
|
||||
MINIMUM_CPU_LINUX=pentium2
|
||||
endif
|
||||
|
||||
if COND_i386_pc
|
||||
QEMU32=qemu-system-i386
|
||||
MINIMUM_CPU_LINUX=pentium2
|
||||
endif
|
||||
|
||||
if COND_i386_efi
|
||||
QEMU32=qemu-system-i386
|
||||
MINIMUM_CPU_LINUX=pentium2
|
||||
endif
|
||||
|
||||
if COND_x86_64_efi
|
||||
QEMU32=qemu-system-x86_64
|
||||
MINIMUM_CPU_LINUX=core2duo
|
||||
endif
|
||||
|
||||
linux.init.x86_64: $(srcdir)/grub-core/tests/boot/linux.init-x86_64.S $(srcdir)/grub-core/tests/boot/qemu-shutdown-x86.S
|
||||
$(TARGET_CC) -o $@ $< -m64 -nostdlib -nostdinc -DSUCCESSFUL_BOOT_STRING=\"$(SUCCESSFUL_BOOT_STRING)\"
|
||||
$(TARGET_CC) -o $@ $< -static -m64 -nostdlib -nostdinc -DSUCCESSFUL_BOOT_STRING=\"$(SUCCESSFUL_BOOT_STRING)\"
|
||||
|
||||
linux.init.i386: $(srcdir)/grub-core/tests/boot/linux.init-i386.S $(srcdir)/grub-core/tests/boot/qemu-shutdown-x86.S
|
||||
$(TARGET_CC) -o $@ $< -m32 -nostdlib -nostdinc -DSUCCESSFUL_BOOT_STRING=\"$(SUCCESSFUL_BOOT_STRING)\"
|
||||
$(TARGET_CC) -o $@ $< -static -m32 -nostdlib -nostdinc -DSUCCESSFUL_BOOT_STRING=\"$(SUCCESSFUL_BOOT_STRING)\"
|
||||
|
||||
linux.init.mips: $(srcdir)/grub-core/tests/boot/linux.init-mips.S
|
||||
$(TARGET_CC) -o $@ $< -nostdlib -nostdinc -DSUCCESSFUL_BOOT_STRING=\"$(SUCCESSFUL_BOOT_STRING)\"
|
||||
$(TARGET_CC) -o $@ $< -static -nostdlib -nostdinc -DSUCCESSFUL_BOOT_STRING=\"$(SUCCESSFUL_BOOT_STRING)\"
|
||||
|
||||
linux.init.ppc: $(srcdir)/grub-core/tests/boot/linux.init-ppc.S
|
||||
$(TARGET_CC) -o $@ $< -nostdlib -nostdinc -DSUCCESSFUL_BOOT_STRING=\"$(SUCCESSFUL_BOOT_STRING)\"
|
||||
$(TARGET_CC) -o $@ $< -static -nostdlib -nostdinc -DSUCCESSFUL_BOOT_STRING=\"$(SUCCESSFUL_BOOT_STRING)\"
|
||||
|
||||
linux.init.mipsel: $(srcdir)/grub-core/tests/boot/linux.init-mips.S
|
||||
$(TARGET_CC) -o $@ $< -nostdlib -nostdinc -DSUCCESSFUL_BOOT_STRING=\"$(SUCCESSFUL_BOOT_STRING)\"
|
||||
$(TARGET_CC) -o $@ $< -static -nostdlib -nostdinc -DSUCCESSFUL_BOOT_STRING=\"$(SUCCESSFUL_BOOT_STRING)\"
|
||||
|
||||
linux.init.loongson: $(srcdir)/grub-core/tests/boot/linux.init-mips.S
|
||||
$(TARGET_CC) -o $@ $< -nostdlib -nostdinc -DSUCCESSFUL_BOOT_STRING=\"$(SUCCESSFUL_BOOT_STRING)\" -DREBOOT=1
|
||||
$(TARGET_CC) -o $@ $< -static -nostdlib -nostdinc -DSUCCESSFUL_BOOT_STRING=\"$(SUCCESSFUL_BOOT_STRING)\" -DREBOOT=1
|
||||
|
||||
multiboot.elf: $(srcdir)/grub-core/tests/boot/kernel-i386.S $(srcdir)/grub-core/tests/boot/qemu-shutdown-x86.S
|
||||
$(TARGET_CC) -o $@ $< -DSUCCESSFUL_BOOT_STRING=\"$(SUCCESSFUL_BOOT_STRING)\" -ffreestanding -nostdlib -nostdinc -DTARGET_MULTIBOOT=1 -Wl,--build-id=none -Wl,-N -Wl,-Ttext,0x100000 -m32 -I$(srcdir)/include
|
||||
$(TARGET_CC) -o $@ $< -DSUCCESSFUL_BOOT_STRING=\"$(SUCCESSFUL_BOOT_STRING)\" -static -ffreestanding -nostdlib -nostdinc -DTARGET_MULTIBOOT=1 -Wl,--build-id=none -Wl,-N -Wl,-Ttext,0x100000 -m32 -I$(srcdir)/include
|
||||
|
||||
kfreebsd.elf: $(srcdir)/grub-core/tests/boot/kernel-i386.S $(srcdir)/grub-core/tests/boot/qemu-shutdown-x86.S
|
||||
$(TARGET_CC) -o $@ $< -DSUCCESSFUL_BOOT_STRING=\"$(SUCCESSFUL_BOOT_STRING)\" -ffreestanding -nostdlib -nostdinc -Wl,--build-id=none -Wl,-N -Wl,-Ttext,0x100000 -m32 -I$(srcdir)/include
|
||||
$(TARGET_CC) -o $@ $< -DSUCCESSFUL_BOOT_STRING=\"$(SUCCESSFUL_BOOT_STRING)\" -static -ffreestanding -nostdlib -nostdinc -Wl,--build-id=none -Wl,-N -Wl,-Ttext,0x100000 -m32 -I$(srcdir)/include
|
||||
|
||||
kfreebsd.aout: kfreebsd.elf
|
||||
$(TARGET_OBJCOPY) -O a.out-i386-linux $< $@ -R .note.gnu.build-id -R .note.gnu.gold-version
|
||||
$(TARGET_OBJCOPY) -O a.out-i386-linux $< $@ -j .text
|
||||
|
||||
pc-chainloader.elf: $(srcdir)/grub-core/tests/boot/kernel-8086.S $(srcdir)/grub-core/tests/boot/qemu-shutdown-x86.S
|
||||
$(TARGET_CC) -o $@ $< -DTARGET_CHAINLOADER=1 -DSUCCESSFUL_BOOT_STRING=\"$(SUCCESSFUL_BOOT_STRING)\" -ffreestanding -nostdlib -nostdinc -Wl,--build-id=none -Wl,-N -Wl,-Ttext,0x7c00 -m32
|
||||
$(TARGET_CC) -o $@ $< -static -DTARGET_CHAINLOADER=1 -DSUCCESSFUL_BOOT_STRING=\"$(SUCCESSFUL_BOOT_STRING)\" -ffreestanding -nostdlib -nostdinc -Wl,--build-id=none -Wl,-N -Wl,-Ttext,0x7c00 -m32
|
||||
|
||||
pc-chainloader.bin: pc-chainloader.elf
|
||||
$(TARGET_OBJCOPY) -O binary --strip-unneeded -R .note -R .comment -R .note.gnu.build-id -R .reginfo -R .rel.dyn -R .note.gnu.gold-version $< $@;
|
||||
|
||||
ntldr.elf: $(srcdir)/grub-core/tests/boot/kernel-8086.S $(srcdir)/grub-core/tests/boot/qemu-shutdown-x86.S
|
||||
$(TARGET_CC) -o $@ $< -DTARGET_NTLDR=1 -DSUCCESSFUL_BOOT_STRING=\"$(SUCCESSFUL_BOOT_STRING)\" -ffreestanding -nostdlib -nostdinc -Wl,--build-id=none -Wl,-N -Wl,-Ttext,0 -m32
|
||||
$(TARGET_CC) -o $@ $< -DTARGET_NTLDR=1 -DSUCCESSFUL_BOOT_STRING=\"$(SUCCESSFUL_BOOT_STRING)\" -static -ffreestanding -nostdlib -nostdinc -Wl,--build-id=none -Wl,-N -Wl,-Ttext,0 -m32
|
||||
|
||||
ntldr.bin: ntldr.elf
|
||||
$(TARGET_OBJCOPY) -O binary --strip-unneeded -R .note -R .comment -R .note.gnu.build-id -R .reginfo -R .rel.dyn -R .note.gnu.gold-version $< $@;
|
||||
$(TARGET_OBJCOPY) -O binary --strip-unneeded -j .text $< $@;
|
||||
|
||||
multiboot2.elf: $(srcdir)/grub-core/tests/boot/kernel-i386.S $(srcdir)/grub-core/tests/boot/qemu-shutdown-x86.S
|
||||
$(TARGET_CC) -o $@ $< -DSUCCESSFUL_BOOT_STRING=\"$(SUCCESSFUL_BOOT_STRING)\" -ffreestanding -nostdlib -nostdinc -Wl,--build-id=none -Wl,-N -Wl,-Ttext,0x100000 -m32 -I$(srcdir)/include -DTARGET_MULTIBOOT2=1
|
||||
$(TARGET_CC) -static -o $@ $< -DSUCCESSFUL_BOOT_STRING=\"$(SUCCESSFUL_BOOT_STRING)\" -ffreestanding -nostdlib -nostdinc -Wl,--build-id=none -Wl,-N -Wl,-Ttext,0x100000 -m32 -I$(srcdir)/include -DTARGET_MULTIBOOT2=1
|
||||
|
||||
kfreebsd.init.x86_64: $(srcdir)/grub-core/tests/boot/kfreebsd.init-x86_64.S $(srcdir)/grub-core/tests/boot/qemu-shutdown-x86.S
|
||||
$(TARGET_CC) -o $@ $< -m64 -nostdlib -nostdinc -DSUCCESSFUL_BOOT_STRING=\"$(SUCCESSFUL_BOOT_STRING)\" && freebsd-brandelf -t FreeBSD $@
|
||||
$(TARGET_CC) -o $@ $< -m64 -static -nostdlib -nostdinc -DSUCCESSFUL_BOOT_STRING=\"$(SUCCESSFUL_BOOT_STRING)\" && freebsd-brandelf -t FreeBSD $@
|
||||
|
||||
kfreebsd.init.i386: $(srcdir)/grub-core/tests/boot/kfreebsd.init-i386.S $(srcdir)/grub-core/tests/boot/qemu-shutdown-x86.S
|
||||
$(TARGET_CC) -o $@ $< -m32 -nostdlib -nostdinc -DSUCCESSFUL_BOOT_STRING=\"$(SUCCESSFUL_BOOT_STRING)\" && freebsd-brandelf -t FreeBSD $@
|
||||
$(TARGET_CC) -o $@ $< -m32 -static -nostdlib -nostdinc -DSUCCESSFUL_BOOT_STRING=\"$(SUCCESSFUL_BOOT_STRING)\" && freebsd-brandelf -t FreeBSD $@
|
||||
|
||||
knetbsd.init.i386: $(srcdir)/grub-core/tests/boot/kbsd.init-i386.S $(srcdir)/grub-core/tests/boot/qemu-shutdown-x86.S
|
||||
$(TARGET_CC) -o $@ $< -m32 -nostdlib -nostdinc -DTARGET_NETBSD=1 -DSUCCESSFUL_BOOT_STRING=\"$(SUCCESSFUL_BOOT_STRING)\"
|
||||
$(TARGET_CC) -o $@ $< -m32 -static -nostdlib -nostdinc -DTARGET_NETBSD=1 -DSUCCESSFUL_BOOT_STRING=\"$(SUCCESSFUL_BOOT_STRING)\"
|
||||
|
||||
kopenbsd.init.i386: $(srcdir)/grub-core/tests/boot/kbsd.init-i386.S $(srcdir)/grub-core/tests/boot/qemu-shutdown-x86.S
|
||||
$(TARGET_CC) -o $@ $< -m32 -nostdlib -nostdinc -DTARGET_OPENBSD=1 -DSUCCESSFUL_BOOT_STRING=\"$(SUCCESSFUL_BOOT_STRING)\"
|
||||
$(TARGET_CC) -o $@ $< -m32 -static -nostdlib -nostdinc -DTARGET_OPENBSD=1 -DSUCCESSFUL_BOOT_STRING=\"$(SUCCESSFUL_BOOT_STRING)\"
|
||||
|
||||
knetbsd.init.x86_64: $(srcdir)/grub-core/tests/boot/kbsd.init-x86_64.S $(srcdir)/grub-core/tests/boot/qemu-shutdown-x86.S
|
||||
$(TARGET_CC) -o $@ $< -m64 -DTARGET_NETBSD=1 -nostdlib -nostdinc -DSUCCESSFUL_BOOT_STRING=\"$(SUCCESSFUL_BOOT_STRING)\"
|
||||
$(TARGET_CC) -o $@ $< -m64 -DTARGET_NETBSD=1 -static -nostdlib -nostdinc -DSUCCESSFUL_BOOT_STRING=\"$(SUCCESSFUL_BOOT_STRING)\"
|
||||
|
||||
kopenbsd.init.x86_64: $(srcdir)/grub-core/tests/boot/kbsd.init-x86_64.S $(srcdir)/grub-core/tests/boot/qemu-shutdown-x86.S
|
||||
$(TARGET_CC) -o $@ $< -m64 -DTARGET_OPENBSD=1 -nostdlib -nostdinc -DSUCCESSFUL_BOOT_STRING=\"$(SUCCESSFUL_BOOT_STRING)\"
|
||||
$(TARGET_CC) -o $@ $< -m64 -DTARGET_OPENBSD=1 -static -nostdlib -nostdinc -DSUCCESSFUL_BOOT_STRING=\"$(SUCCESSFUL_BOOT_STRING)\"
|
||||
|
||||
linux-initramfs.mips: linux.init.mips Makefile
|
||||
TDIR=`mktemp -d "$${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` && cp $< $$TDIR/init && (cd $$TDIR && echo ./init | cpio --quiet --dereference -o -H newc) | gzip > $@ && rm -rf $$TDIR
|
||||
TDIR=`mktemp -d "$${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` && cp $< $$TDIR/init && (cd $$TDIR && echo ./init | cpio -R 0:0 --quiet --dereference -o -H newc) | gzip > $@ && rm -rf $$TDIR
|
||||
|
||||
linux-initramfs.ppc: linux.init.ppc Makefile
|
||||
TDIR=`mktemp -d "$${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` && cp $< $$TDIR/init && (cd $$TDIR && echo ./init | cpio --quiet --dereference -o -H newc) | gzip > $@ && rm -rf $$TDIR
|
||||
TDIR=`mktemp -d "$${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` && cp $< $$TDIR/init && (cd $$TDIR && echo ./init | cpio -R 0:0 --quiet --dereference -o -H newc) | gzip > $@ && rm -rf $$TDIR
|
||||
|
||||
linux-initramfs.mipsel: linux.init.mipsel Makefile
|
||||
TDIR=`mktemp -d "$${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` && cp $< $$TDIR/init && (cd $$TDIR && echo ./init | cpio --quiet --dereference -o -H newc) | gzip > $@ && rm -rf $$TDIR
|
||||
TDIR=`mktemp -d "$${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` && cp $< $$TDIR/init && (cd $$TDIR && echo ./init | cpio -R 0:0 --quiet --dereference -o -H newc) | gzip > $@ && rm -rf $$TDIR
|
||||
|
||||
linux-initramfs.loongson: linux.init.loongson Makefile
|
||||
TDIR=`mktemp -d "$${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` && cp $< $$TDIR/init && (cd $$TDIR && echo ./init | cpio --quiet --dereference -o -H newc) | gzip > $@ && rm -rf $$TDIR
|
||||
TDIR=`mktemp -d "$${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` && cp $< $$TDIR/init && (cd $$TDIR && echo ./init | cpio -R 0:0 --quiet --dereference -o -H newc) | gzip > $@ && rm -rf $$TDIR
|
||||
|
||||
linux-initramfs.i386: linux.init.i386 Makefile
|
||||
TDIR=`mktemp -d "$${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` && cp $< $$TDIR/init && (cd $$TDIR && echo ./init | cpio --quiet --dereference -o -H newc) | gzip > $@ && rm -rf $$TDIR
|
||||
TDIR=`mktemp -d "$${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` && cp $< $$TDIR/init && (cd $$TDIR && echo ./init | cpio -R 0:0 --quiet --dereference -o -H newc) | gzip > $@ && rm -rf $$TDIR
|
||||
|
||||
linux-initramfs.x86_64: linux.init.x86_64 Makefile
|
||||
TDIR=`mktemp -d "$${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` && cp $< $$TDIR/init && (cd $$TDIR && echo ./init | cpio --quiet --dereference -o -H newc) | gzip > $@ && rm -rf $$TDIR
|
||||
TDIR=`mktemp -d "$${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` && cp $< $$TDIR/init && (cd $$TDIR && echo ./init | cpio -R 0:0 --quiet --dereference -o -H newc) | gzip > $@ && rm -rf $$TDIR
|
||||
|
||||
kfreebsd-mfsroot.i386.img: kfreebsd.init.i386 Makefile
|
||||
TDIR=`mktemp -d "$${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` && mkdir $$TDIR/dev && mkdir $$TDIR/sbin && cp $< $$TDIR/sbin/init && makefs -t ffs -s 30m -f 1000 -o minfree=0,version=1 $@ $$TDIR && rm -rf $$TDIR
|
||||
@@ -306,7 +313,7 @@ bootcheck-knetbsd-x86_64: knetbsd.miniroot-image.x86_64.gz $(GRUB_PAYLOADS_DIR)/
|
||||
./grub-shell --timeout=$(BOOTCHECK_TIMEOUT) --qemu=qemu-system-x86_64 --files=/miniroot.gz=knetbsd.miniroot-image.x86_64.gz --files=/knetbsd=$(GRUB_PAYLOADS_DIR)/knetbsd.x86_64 $(srcdir)/grub-core/tests/boot/knetbsd.cfg | grep $(SUCCESSFUL_BOOT_STRING) > /dev/null
|
||||
|
||||
bootcheck-linux-i386: linux-initramfs.i386 $(GRUB_PAYLOADS_DIR)/linux.i386 $(srcdir)/grub-core/tests/boot/linux.cfg grub-shell
|
||||
./grub-shell --timeout=$(BOOTCHECK_TIMEOUT) --qemu=$(QEMU32) --files=/initrd=linux-initramfs.i386 --files=/linux=$(GRUB_PAYLOADS_DIR)/linux.i386 $(srcdir)/grub-core/tests/boot/linux.cfg | grep $(SUCCESSFUL_BOOT_STRING) > /dev/null
|
||||
./grub-shell --timeout=$(BOOTCHECK_TIMEOUT) --qemu=$(QEMU32) --files=/initrd=linux-initramfs.i386 --files=/linux=$(GRUB_PAYLOADS_DIR)/linux.i386 $(srcdir)/grub-core/tests/boot/linux.cfg --qemu-opts="-cpu $(MINIMUM_CPU_LINUX)" | grep $(SUCCESSFUL_BOOT_STRING) > /dev/null
|
||||
|
||||
bootcheck-linux-x86_64: linux-initramfs.x86_64 $(GRUB_PAYLOADS_DIR)/linux.x86_64 $(srcdir)/grub-core/tests/boot/linux.cfg grub-shell
|
||||
./grub-shell --timeout=$(BOOTCHECK_TIMEOUT) --qemu=qemu-system-x86_64 --files=/initrd=linux-initramfs.x86_64 --files=/linux=$(GRUB_PAYLOADS_DIR)/linux.x86_64 $(srcdir)/grub-core/tests/boot/linux.cfg | grep $(SUCCESSFUL_BOOT_STRING) > /dev/null
|
||||
@@ -369,6 +376,12 @@ if COND_i386_coreboot
|
||||
BOOTCHECKS = bootcheck-kfreebsd-aout bootcheck-kopenbsd-i386 bootcheck-kopenbsd-x86_64 bootcheck-multiboot bootcheck-multiboot2 bootcheck-linux-i386 bootcheck-linux-x86_64 bootcheck-knetbsd-x86_64 bootcheck-kfreebsd-x86_64 bootcheck-kfreebsd-i386
|
||||
endif
|
||||
|
||||
if COND_i386_ieee1275
|
||||
# *BSD requires ACPI
|
||||
#legacy protocol (linux16) makes early BIOS calls.
|
||||
BOOTCHECKS = bootcheck-kfreebsd-aout bootcheck-multiboot bootcheck-multiboot2 bootcheck-linux-i386 bootcheck-linux-x86_64
|
||||
endif
|
||||
|
||||
if COND_i386_pc
|
||||
#pc chainloader by definition is only for i386-pc
|
||||
#ntldr and bootmgr require BIOS.
|
||||
@@ -409,8 +422,9 @@ BOOTCHECK_TIMEOUT=180
|
||||
bootcheck: $(BOOTCHECKS)
|
||||
|
||||
if COND_i386_coreboot
|
||||
default_payload.elf: grub-mkstandalone grub-mkimage
|
||||
pkgdatadir=. ./grub-mkstandalone --grub-mkimage=./grub-mkimage -O i386-coreboot -o $@ --modules='ahci pata ehci uhci ohci usb_keyboard usbms part_msdos xfs ext2 fat at_keyboard part_gpt usbserial_usbdebug cbfs' --install-modules='ls linux search configfile normal cbtime cbls memrw iorw minicmd lsmmap lspci halt reboot hexdump pcidump regexp setpci lsacpi chain test serial multiboot cbmemc linux16 gzio echo help' --fonts= --themes= --locales= -d grub-core/ /boot/grub/grub.cfg=$(srcdir)/coreboot.cfg
|
||||
default_payload.elf: grub-mkstandalone grub-mkimage FORCE
|
||||
test -f $@ && rm $@ || true
|
||||
pkgdatadir=. ./grub-mkstandalone --grub-mkimage=./grub-mkimage -O i386-coreboot -o $@ --modules='ahci pata ehci uhci ohci usb_keyboard usbms part_msdos ext2 fat at_keyboard part_gpt usbserial_usbdebug cbfs' --install-modules='ls linux search configfile normal cbtime cbls memrw iorw minicmd lsmmap lspci halt reboot hexdump pcidump regexp setpci lsacpi chain test serial multiboot cbmemc linux16 gzio echo help syslinuxcfg xnu $(shell cat grub-core/fs.lst) password_pbkdf2 $(EXTRA_PAYLOAD_MODULES)' --fonts= --themes= --locales= -d grub-core/ /boot/grub/grub.cfg=$(srcdir)/coreboot.cfg
|
||||
endif
|
||||
|
||||
endif
|
||||
|
||||
@@ -172,6 +172,8 @@ program = {
|
||||
|
||||
common = util/grub-mkimage.c;
|
||||
common = util/mkimage.c;
|
||||
common = util/grub-mkimage32.c;
|
||||
common = util/grub-mkimage64.c;
|
||||
common = util/resolve.c;
|
||||
common = grub-core/kern/emu/argp_common.c;
|
||||
common = grub-core/osdep/init.c;
|
||||
@@ -414,7 +416,7 @@ program = {
|
||||
ldadd = libgrubgcry.a;
|
||||
ldadd = libgrubkern.a;
|
||||
ldadd = grub-core/gnulib/libgnu.a;
|
||||
ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM)';
|
||||
ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBUTIL) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM)';
|
||||
};
|
||||
|
||||
data = {
|
||||
@@ -510,6 +512,8 @@ program = {
|
||||
common = util/render-label.c;
|
||||
common = util/glue-efi.c;
|
||||
common = util/mkimage.c;
|
||||
common = util/grub-mkimage32.c;
|
||||
common = util/grub-mkimage64.c;
|
||||
common = util/grub-install-common.c;
|
||||
common = util/setup_bios.c;
|
||||
common = util/setup_sparc.c;
|
||||
@@ -552,6 +556,8 @@ program = {
|
||||
common = util/render-label.c;
|
||||
common = util/glue-efi.c;
|
||||
common = util/mkimage.c;
|
||||
common = util/grub-mkimage32.c;
|
||||
common = util/grub-mkimage64.c;
|
||||
common = util/grub-install-common.c;
|
||||
common = util/setup_bios.c;
|
||||
common = util/setup_sparc.c;
|
||||
@@ -595,6 +601,8 @@ program = {
|
||||
common = util/grub-install.c;
|
||||
common = util/probe.c;
|
||||
common = util/mkimage.c;
|
||||
common = util/grub-mkimage32.c;
|
||||
common = util/grub-mkimage64.c;
|
||||
common = util/grub-install-common.c;
|
||||
common = util/setup_bios.c;
|
||||
common = util/setup_sparc.c;
|
||||
@@ -632,6 +640,8 @@ program = {
|
||||
common = util/grub-mknetdir.c;
|
||||
|
||||
common = util/mkimage.c;
|
||||
common = util/grub-mkimage32.c;
|
||||
common = util/grub-mkimage64.c;
|
||||
common = util/grub-install-common.c;
|
||||
common = util/setup_bios.c;
|
||||
common = util/setup_sparc.c;
|
||||
|
||||
14
NEWS
14
NEWS
@@ -18,6 +18,7 @@ New in 2.02:
|
||||
* ZFS features support.
|
||||
* ZFS LZ4 support.
|
||||
* XFS V5 format support.
|
||||
* LVM RAID1 support.
|
||||
|
||||
* New/improved terminal and video support:
|
||||
* Monochrome text (matching `hercules' in GRUB Legacy).
|
||||
@@ -49,6 +50,9 @@ New in 2.02:
|
||||
* Improve TFTP robustness.
|
||||
* Parse `nd' disk names in GRUB Legacy configuration files.
|
||||
* Issue separate DNS queries for IPv4 and IPv6.
|
||||
* Support IPv6 Router Advertisement to configure default router.
|
||||
* New variable net_<interface>_next_server containing next server
|
||||
from BOOTP reply.
|
||||
|
||||
* Coreboot improvements:
|
||||
* CBFS support both in on-disk images (loopback) and flash.
|
||||
@@ -96,6 +100,8 @@ New in 2.02:
|
||||
EFI Stall. If everything fails, use hardcoded frequency 800MHz.
|
||||
* Support Hyper-V Gen2 platforms which lack PIT for TSC calibration.
|
||||
* Map UEFI Persistent Memory to E820 persistent memory.
|
||||
* New Xen loader on ARM64.
|
||||
* Respect alignment requirement for block device IO buffers on EFI.
|
||||
|
||||
* Security:
|
||||
* Add optional facility to enforce that all files read by the core image
|
||||
@@ -134,6 +140,11 @@ New in 2.02:
|
||||
menu entry immediately.
|
||||
* New `file' command and grub-file utility to check file types.
|
||||
* New syslinux configuration file parser.
|
||||
* Set menu entry class to primary OS name returned by os-prober to display
|
||||
OS specific icon.
|
||||
* On Linux x86 detect EFI word size in grub-install and automatically select
|
||||
correct platform (x86_64-efi or i386-efi) to install. Requires Linux kernel
|
||||
4.0 or higher.
|
||||
|
||||
* Build system:
|
||||
* Remove all uses of nested functions; GRUB no longer requires an
|
||||
@@ -160,6 +171,9 @@ New in 2.02:
|
||||
* emu libusb support removed (was broken and unmaintained).
|
||||
* powerpc64le compile support.
|
||||
* Use fixed timestamp when generating GRUB image for reproducible builds.
|
||||
* Verify at build time that modules contain only supported relocations and their
|
||||
structure matches what boot-time module loader expects.
|
||||
* Do not require fonts on powerpc-ieee1275.
|
||||
|
||||
* Revision control moved to git.
|
||||
|
||||
|
||||
4
TODO
4
TODO
@@ -7,7 +7,3 @@ glance. So write to <grub-devel@gnu.org> first.
|
||||
For bug tracking, refer to:
|
||||
|
||||
http://savannah.gnu.org/bugs/?group=grub
|
||||
|
||||
Our wiki also lists some areas that need work:
|
||||
|
||||
http://grub.enbug.org/
|
||||
|
||||
52
acinclude.m4
52
acinclude.m4
@@ -390,6 +390,58 @@ else
|
||||
[fi]
|
||||
])
|
||||
|
||||
AC_DEFUN([grub_CHECK_LINK_PIE],[
|
||||
[# Position independent executable.
|
||||
link_nopie_needed=no]
|
||||
AC_MSG_CHECKING([whether linker needs disabling of PIE to work])
|
||||
AC_LANG_CONFTEST([AC_LANG_SOURCE([[]])])
|
||||
|
||||
[if eval "$ac_compile -Wl,-r,-d -nostdlib -Werror -o conftest.o" 2> /dev/null; then]
|
||||
AC_MSG_RESULT([no])
|
||||
[# Should we clear up other files as well, having called `AC_LANG_CONFTEST'?
|
||||
rm -f conftest.o
|
||||
else
|
||||
link_nopie_needed=yes]
|
||||
AC_MSG_RESULT([yes])
|
||||
[fi]
|
||||
])
|
||||
|
||||
|
||||
dnl Check if the Linker supports `-no-pie'.
|
||||
AC_DEFUN([grub_CHECK_NO_PIE],
|
||||
[AC_MSG_CHECKING([whether linker accepts -no-pie])
|
||||
AC_CACHE_VAL(grub_cv_cc_ld_no_pie,
|
||||
[save_LDFLAGS="$LDFLAGS"
|
||||
LDFLAGS="$LDFLAGS -no-pie -nostdlib -Werror"
|
||||
AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
|
||||
[grub_cv_cc_ld_no_pie=yes],
|
||||
[grub_cv_cc_ld_no_pie=no])
|
||||
LDFLAGS="$save_LDFLAGS"
|
||||
])
|
||||
AC_MSG_RESULT([$grub_cv_cc_ld_no_pie])
|
||||
nopie_possible=no
|
||||
if test "x$grub_cv_cc_ld_no_pie" = xyes ; then
|
||||
nopie_possible=yes
|
||||
fi
|
||||
])
|
||||
|
||||
AC_DEFUN([grub_CHECK_NO_PIE_ONEWORD],
|
||||
[AC_MSG_CHECKING([whether linker accepts -nopie])
|
||||
AC_CACHE_VAL(grub_cv_cc_ld_no_pie_oneword,
|
||||
[save_LDFLAGS="$LDFLAGS"
|
||||
LDFLAGS="$LDFLAGS -nopie -nostdlib -Werror"
|
||||
AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
|
||||
[grub_cv_cc_ld_no_pie_oneword=yes],
|
||||
[grub_cv_cc_ld_no_pie_oneword=no])
|
||||
LDFLAGS="$save_LDFLAGS"
|
||||
])
|
||||
AC_MSG_RESULT([$grub_cv_cc_ld_no_pie_oneword])
|
||||
nopie_oneword_possible=no
|
||||
if test "x$grub_cv_cc_ld_no_pie_oneword" = xyes ; then
|
||||
nopie_oneword_possible=yes
|
||||
fi
|
||||
])
|
||||
|
||||
dnl Check if the C compiler supports `-fPIC'.
|
||||
AC_DEFUN([grub_CHECK_PIC],[
|
||||
[# Position independent executable.
|
||||
|
||||
@@ -1,12 +1,16 @@
|
||||
/* on x86 old clang doesn't support .code16
|
||||
newer clang supports it but creates 6-byte jumps instead of 3-byte ones
|
||||
which makes us go over boot sector size. */
|
||||
which makes us go over boot sector size.
|
||||
Starting with 3.9 clang emits 3-byte jumps but still creates 8-bytes movl
|
||||
instead of 5-bytes, so code overflows into data. */
|
||||
|
||||
.code16
|
||||
jmp far
|
||||
.org 4
|
||||
jmp nearer
|
||||
.org 6
|
||||
movl nearer, %ebx
|
||||
.org 11
|
||||
.space 100
|
||||
nearer:
|
||||
.space 200
|
||||
|
||||
@@ -86,9 +86,11 @@ CPPFLAGS_TERMINAL_LIST += '-Dgrub_term_register_output(...)=OUTPUT_TERMINAL_LIST
|
||||
CPPFLAGS_COMMAND_LIST = '-Dgrub_register_command(...)=COMMAND_LIST_MARKER(__VA_ARGS__)'
|
||||
CPPFLAGS_COMMAND_LIST += '-Dgrub_register_extcmd(...)=EXTCOMMAND_LIST_MARKER(__VA_ARGS__)'
|
||||
CPPFLAGS_COMMAND_LIST += '-Dgrub_register_command_p1(...)=P1COMMAND_LIST_MARKER(__VA_ARGS__)'
|
||||
CPPFLAGS_FDT_LIST := '-Dgrub_fdtbus_register(...)=FDT_DRIVER_LIST_MARKER(__VA_ARGS__)'
|
||||
CPPFLAGS_MARKER = $(CPPFLAGS_FS_LIST) $(CPPFLAGS_VIDEO_LIST) \
|
||||
$(CPPFLAGS_PARTTOOL_LIST) $(CPPFLAGS_PARTMAP_LIST) \
|
||||
$(CPPFLAGS_TERMINAL_LIST) $(CPPFLAGS_COMMAND_LIST)
|
||||
$(CPPFLAGS_TERMINAL_LIST) $(CPPFLAGS_COMMAND_LIST) \
|
||||
$(CPPFLAGS_FDT_LIST)
|
||||
|
||||
# Define these variables to calm down automake
|
||||
|
||||
|
||||
86
configure.ac
86
configure.ac
@@ -31,7 +31,7 @@ dnl (such as BUILD_CC, BUILD_CFLAGS, etc.) for the build type and variables
|
||||
dnl with the prefix "TARGET_" (such as TARGET_CC, TARGET_CFLAGS, etc.) are
|
||||
dnl used for the target type. See INSTALL for full list of variables.
|
||||
|
||||
AC_INIT([GRUB],[2.02~beta2],[bug-grub@gnu.org])
|
||||
AC_INIT([GRUB],[2.03],[bug-grub@gnu.org])
|
||||
|
||||
AC_CONFIG_AUX_DIR([build-aux])
|
||||
|
||||
@@ -167,6 +167,7 @@ case "$target_cpu"-"$platform" in
|
||||
mipsel-fuloong) platform=loongson ;;
|
||||
mipsel-loongson) ;;
|
||||
arm-uboot) ;;
|
||||
arm-coreboot) ;;
|
||||
arm-efi) ;;
|
||||
arm64-efi) ;;
|
||||
*-emu) ;;
|
||||
@@ -373,7 +374,10 @@ case "$host_os" in
|
||||
;;
|
||||
*)
|
||||
AC_CHECK_SIZEOF(off_t)
|
||||
test x"$ac_cv_sizeof_off_t" = x8 || AC_MSG_ERROR([Large file support is required]);;
|
||||
if test x"$ac_cv_sizeof_off_t" != x8 ; then
|
||||
AC_CHECK_SIZEOF(off64_t)
|
||||
test x"$ac_cv_sizeof_off64_t" = x8 || AC_MSG_ERROR([Large file support is required])
|
||||
fi;;
|
||||
esac
|
||||
|
||||
if test x$USE_NLS = xno; then
|
||||
@@ -388,7 +392,15 @@ fi
|
||||
|
||||
# Check for functions and headers.
|
||||
AC_CHECK_FUNCS(posix_memalign memalign getextmntent)
|
||||
AC_CHECK_HEADERS(sys/param.h sys/mount.h sys/mnttab.h sys/mkdev.h limits.h)
|
||||
AC_CHECK_HEADERS(sys/param.h sys/mount.h sys/mnttab.h limits.h)
|
||||
|
||||
# glibc 2.25 still includes sys/sysmacros.h in sys/types.h but emits deprecation
|
||||
# warning which causes compilation failure later with -Werror. So use -Werror here
|
||||
# as well to force proper sys/sysmacros.h detection.
|
||||
SAVED_CFLAGS="$CFLAGS"
|
||||
CFLAGS="$HOST_CFLAGS -Werror"
|
||||
AC_HEADER_MAJOR
|
||||
CFLAGS="$SAVED_CFLAGS"
|
||||
|
||||
AC_CHECK_MEMBERS([struct statfs.f_fstypename],,,[$ac_includes_default
|
||||
#include <sys/param.h>
|
||||
@@ -448,6 +460,16 @@ case "$build_os" in
|
||||
esac
|
||||
AC_SUBST(BUILD_EXEEXT)
|
||||
|
||||
# In some build environments like termux /bin/sh is not a valid
|
||||
# shebang. Use $SHELL instead if it's executable and /bin/sh isn't
|
||||
BUILD_SHEBANG=/bin/sh
|
||||
for she in /bin/sh "$SHELL"; do
|
||||
if test -x "$she" ; then
|
||||
BUILD_SHEBANG="$she"
|
||||
fi
|
||||
done
|
||||
AC_SUBST(BUILD_SHEBANG)
|
||||
|
||||
# For gnulib.
|
||||
gl_INIT
|
||||
|
||||
@@ -1144,14 +1166,23 @@ if test "$target_cpu"-"$platform" = x86_64-efi; then
|
||||
fi
|
||||
|
||||
if test "x$target_cpu" = xarm; then
|
||||
AC_CACHE_CHECK([whether option -mlong-calls works], grub_cv_cc_mlong_calls, [
|
||||
CFLAGS="$TARGET_CFLAGS -mlong-calls -Werror"
|
||||
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
|
||||
[grub_cv_cc_mlong_calls=yes],
|
||||
[grub_cv_cc_mlong_calls=no])
|
||||
AC_CACHE_CHECK([for options to disable movt and movw], grub_cv_target_cc_mno_movt, [
|
||||
grub_cv_target_cc_mno_movt=no
|
||||
for cand in "-mno-movt" \
|
||||
"-mllvm -arm-use-movt=0"; do
|
||||
if test x"$grub_cv_target_cc_mno_movt" != xno ; then
|
||||
break
|
||||
fi
|
||||
CFLAGS="$TARGET_CFLAGS $cand -Werror"
|
||||
CPPFLAGS="$TARGET_CPPFLAGS"
|
||||
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
|
||||
[grub_cv_target_cc_mno_movt="$cand"], [])
|
||||
done
|
||||
])
|
||||
if test "x$grub_cv_cc_mlong_calls" = xyes; then
|
||||
TARGET_CFLAGS="$TARGET_CFLAGS -mlong-calls"
|
||||
|
||||
if test x"$grub_cv_target_cc_mno_movt" != xno ; then
|
||||
# A trick so that clang doesn't see it on link stage
|
||||
TARGET_CPPFLAGS="$TARGET_CPPFLAGS $grub_cv_target_cc_mno_movt"
|
||||
fi
|
||||
AC_CACHE_CHECK([whether option -mthumb-interwork works], grub_cv_cc_mthumb_interwork, [
|
||||
CFLAGS="$TARGET_CFLAGS -mthumb-interwork -Werror"
|
||||
@@ -1184,13 +1215,26 @@ CFLAGS="$TARGET_CFLAGS"
|
||||
|
||||
# Position independent executable.
|
||||
grub_CHECK_PIE
|
||||
grub_CHECK_NO_PIE
|
||||
grub_CHECK_NO_PIE_ONEWORD
|
||||
grub_CHECK_LINK_PIE
|
||||
[# Need that, because some distributions ship compilers that include
|
||||
# `-fPIE' in the default specs.
|
||||
# `-fPIE' or '-fpie' and '-pie' in the default specs.
|
||||
if [ x"$pie_possible" = xyes ]; then
|
||||
TARGET_CFLAGS="$TARGET_CFLAGS -fno-PIE"
|
||||
TARGET_CFLAGS="$TARGET_CFLAGS -fno-PIE -fno-pie"
|
||||
fi
|
||||
|
||||
if [ x"$link_nopie_needed" = xyes ] || [ x"$pie_possible" = xyes ]; then
|
||||
if [ x"$nopie_possible" = xyes ]; then
|
||||
TARGET_LDFLAGS="$TARGET_LDFLAGS -no-pie"
|
||||
fi
|
||||
if [ x"$nopie_oneword_possible" = xyes ]; then
|
||||
TARGET_LDFLAGS="$TARGET_LDFLAGS -nopie"
|
||||
fi
|
||||
fi]
|
||||
|
||||
CFLAGS="$TARGET_CFLAGS"
|
||||
LDFLAGS="$TARGET_LDFLAGS"
|
||||
|
||||
# Position independent executable.
|
||||
grub_CHECK_PIC
|
||||
@@ -1199,9 +1243,12 @@ grub_CHECK_PIC
|
||||
# and reload $gp in every function.
|
||||
# GCC implements it using symbol __gnu_local_gp in non-PIC as well.
|
||||
# However with clang we need PIC for this reloading to happen.
|
||||
# With arm64 we need relocations that are in some way representable in
|
||||
# PE as we need to support arm64-efi. Without -fPIC clang generates
|
||||
# movk's which aren't representable.
|
||||
# Since default varies across dictributions use either -fPIC or -fno-PIC
|
||||
# explicitly.
|
||||
if ( test x$target_cpu = xmips || test x$target_cpu = xmipsel ) && test "x$grub_cv_cc_target_clang" = xyes ; then
|
||||
if ( test x$target_cpu = xmips || test x$target_cpu = xmipsel || test x$target_cpu = xarm64 ) && test "x$grub_cv_cc_target_clang" = xyes ; then
|
||||
TARGET_CFLAGS="$TARGET_CFLAGS -fPIC"
|
||||
elif [ x"$pic_possible" = xyes ]; then
|
||||
TARGET_CFLAGS="$TARGET_CFLAGS -fno-PIC"
|
||||
@@ -1554,11 +1601,11 @@ if test x"$grub_build_mkfont_excuse" = x ; then
|
||||
else
|
||||
enable_build_grub_mkfont=no
|
||||
fi
|
||||
if test x"$enable_build_grub_mkfont" = xno && ( test "x$platform" = xqemu || test "x$platform" = xloongson || test "x$platform" = xqemu_mips || test "x$target_cpu"-"$platform" = xpowerpc-ieee1275 || test "x$platform" = xcoreboot ); then
|
||||
if test x"$enable_build_grub_mkfont" = xno && ( test "x$platform" = xqemu || test "x$platform" = xloongson || test "x$platform" = xqemu_mips || test "x$platform" = xcoreboot ); then
|
||||
if test x"$grub_build_mkfont_excuse" = x ; then
|
||||
AC_MSG_ERROR([qemu, powerpc-ieee1275, coreboot and loongson ports needs build-time grub-mkfont])
|
||||
AC_MSG_ERROR([qemu, coreboot and loongson ports need build-time grub-mkfont])
|
||||
else
|
||||
AC_MSG_ERROR([qemu, powerpc-ieee1275, coreboot and loongson ports needs build-time grub-mkfont ($grub_build_mkfont_excuse)])
|
||||
AC_MSG_ERROR([qemu, coreboot and loongson ports need build-time grub-mkfont ($grub_build_mkfont_excuse)])
|
||||
fi
|
||||
fi
|
||||
|
||||
@@ -1628,11 +1675,11 @@ if test x"$enable_build_grub_mkfont" = xno ; then
|
||||
FONT_SOURCE=
|
||||
fi
|
||||
|
||||
if test "x$FONT_SOURCE" = x && ( test "x$platform" = xqemu || test "x$platform" = xloongson || test "x$platform" = xqemu_mips || test "x$target_cpu"-"$platform" = xpowerpc-ieee1275 || test "x$platform" = xcoreboot ); then
|
||||
if test "x$FONT_SOURCE" = x && ( test "x$platform" = xqemu || test "x$platform" = xloongson || test "x$platform" = xqemu_mips || test "x$platform" = xcoreboot ); then
|
||||
if test x"$grub_build_mkfont_excuse" = x ; then
|
||||
AC_MSG_ERROR([qemu, powerpc-ieee1275, coreboot and loongson ports need unifont])
|
||||
AC_MSG_ERROR([qemu, coreboot and loongson ports need unifont])
|
||||
else
|
||||
AC_MSG_ERROR([qemu, powerpc-ieee1275, coreboot and loongson ports need unifont ($grub_build_mkfont_excuse)])
|
||||
AC_MSG_ERROR([qemu, coreboot and loongson ports need unifont ($grub_build_mkfont_excuse)])
|
||||
fi
|
||||
fi
|
||||
|
||||
@@ -1872,6 +1919,7 @@ AM_CONDITIONAL([COND_mipsel], [test x$target_cpu = xmipsel])
|
||||
AM_CONDITIONAL([COND_mipseb], [test x$target_cpu = xmips])
|
||||
AM_CONDITIONAL([COND_arm], [test x$target_cpu = xarm ])
|
||||
AM_CONDITIONAL([COND_arm_uboot], [test x$target_cpu = xarm -a x$platform = xuboot])
|
||||
AM_CONDITIONAL([COND_arm_coreboot], [test x$target_cpu = xarm -a x$platform = xcoreboot])
|
||||
AM_CONDITIONAL([COND_arm_efi], [test x$target_cpu = xarm -a x$platform = xefi])
|
||||
AM_CONDITIONAL([COND_arm64], [test x$target_cpu = xarm64 ])
|
||||
AM_CONDITIONAL([COND_arm64_efi], [test x$target_cpu = xarm64 -a x$platform = xefi])
|
||||
|
||||
@@ -84,6 +84,7 @@ This edition documents version @value{VERSION}.
|
||||
* Video Subsystem::
|
||||
* PFF2 Font File Format::
|
||||
* Graphical Menu Software Design::
|
||||
* Verifiers framework::
|
||||
* Copying This Manual:: Copying This Manual
|
||||
* Index::
|
||||
@end menu
|
||||
@@ -1949,6 +1950,58 @@ the graphics mode that was in use before @code{grub_video_setup()} was called
|
||||
might fix some of the problems.
|
||||
|
||||
|
||||
@node Verifiers framework
|
||||
@chapter Verifiers framework
|
||||
|
||||
To register your own verifier call @samp{grub_verifier_register} with a
|
||||
structure pointing to your functions.
|
||||
|
||||
The interface is inspired by hash interface with @samp{init}/@samp{write}/@samp{fini}.
|
||||
|
||||
There are eesntially 2 ways of using it: hashing and whole-file verification:
|
||||
|
||||
With hashing approach:
|
||||
During @samp{init} you decide whether you want to check given file and init context.
|
||||
In @samp{write} you update you hashing state.
|
||||
In @samp{fini} you check that hash matches the expected value/passes some check/...
|
||||
|
||||
With whole-file verification:
|
||||
During @samp{init} you decide whether you want to check given file and init context.
|
||||
In @samp{write} you verify file and return error if it fails.
|
||||
You don't have @samp{fini}.
|
||||
|
||||
Additional @samp{verify_string} receives various strings like kernel parameters to
|
||||
verify. Returning no error means successful verification and an error stops the current
|
||||
action.
|
||||
|
||||
Detailed description of API:
|
||||
|
||||
Every time a file is opened your @samp{init} function is called with file descriptor
|
||||
and file type. Your function can have following outcomes:
|
||||
|
||||
@itemize
|
||||
|
||||
@item returning no error and setting @samp{*flags} to @samp{GRUB_VERIFY_FLAGS_SKIP_VERIFICATION}.
|
||||
In this case your verifier will not be called anymore and your verifier is considered
|
||||
to have skipped verification
|
||||
|
||||
@item returning error. Then opening of the fail will fail due to failed verification.
|
||||
|
||||
@item returning no error and not setting @samp{*flags} to @samp{GRUB_VERIFY_FLAGS_SKIP_VERIFICATION}
|
||||
In this case verification is done as described in following section
|
||||
|
||||
@end itemize
|
||||
|
||||
In the third case your @samp{write} will be called with chunks of file. If you need the whole file in a single
|
||||
chunk then during @samp{init} set bit @samp{GRUB_VERIFY_FLAGS_SINGLE_CHUNK} in @samp{*flags}.
|
||||
During @samp{init} you may set @samp{*context} if you need additional context. At every iteration you may return
|
||||
an error and the the file will be considered as having failed the verification. If you return no error then
|
||||
verification continues.
|
||||
|
||||
Optionally at the end of the file @samp{fini} if it exists is called with just the context. If you return
|
||||
no error during any of @samp{init}, @samp{write} and @samp{fini} then the file is considered as having
|
||||
succeded verification.
|
||||
|
||||
@node Copying This Manual
|
||||
@appendix Copying This Manual
|
||||
|
||||
|
||||
@@ -2446,6 +2446,10 @@ The boot file name provided by DHCP. Read-only.
|
||||
The name of the DHCP server responsible for these boot parameters.
|
||||
Read-only.
|
||||
|
||||
@item net_@var{<interface>}_next_server
|
||||
The IP address of the next (usually, TFTP) server provided by DHCP.
|
||||
Read-only.
|
||||
|
||||
@item net_default_interface
|
||||
Initially set to name of network interface that was used to load grub.
|
||||
Read-write, although setting it affects only interpretation of
|
||||
@@ -2538,6 +2542,8 @@ team are:
|
||||
85:3
|
||||
@item Asus EeePC 1005PE
|
||||
84:1 (unconfirmed)
|
||||
@item LENOVO ThinkPad T410s (2912W1C)
|
||||
101:3
|
||||
@end table
|
||||
|
||||
To take full advantage of this function, install GRUB into the MBR
|
||||
@@ -3060,6 +3066,7 @@ These variables have special meaning to GRUB.
|
||||
* net_@var{<interface>}_hostname::
|
||||
* net_@var{<interface>}_ip::
|
||||
* net_@var{<interface>}_mac::
|
||||
* net_@var{<interface>}_next_server::
|
||||
* net_@var{<interface>}_rootpath::
|
||||
* net_default_interface::
|
||||
* net_default_ip::
|
||||
@@ -3211,9 +3218,10 @@ source for more details.
|
||||
@node default
|
||||
@subsection default
|
||||
|
||||
If this variable is set, it identifies a menu entry that should be selected
|
||||
by default, possibly after a timeout (@pxref{timeout}). The entry may be
|
||||
identified by number or by id.
|
||||
If this variable is set, it identifies a menu entry that should be
|
||||
selected by default, possibly after a timeout (@pxref{timeout}). The
|
||||
entry may be identified by number (starting from 0 at each level of
|
||||
the hierarchy), by title, or by id.
|
||||
|
||||
For example, if you have:
|
||||
|
||||
@@ -3229,24 +3237,26 @@ then you can make this the default using:
|
||||
default=example-gnu-linux
|
||||
@end example
|
||||
|
||||
If the entry is in a submenu, then it must be identified using the titles of
|
||||
each of the submenus starting from the top level followed by the number or
|
||||
title of the menu entry itself, separated by @samp{>}. For example, take
|
||||
the following menu structure:
|
||||
If the entry is in a submenu, then it must be identified using the
|
||||
number, title, or id of each of the submenus starting from the top
|
||||
level, followed by the number, title, or id of the menu entry itself,
|
||||
with each element separated by @samp{>}. For example, take the
|
||||
following menu structure:
|
||||
|
||||
@example
|
||||
Submenu 1
|
||||
Menu Entry 1
|
||||
Menu Entry 2
|
||||
Submenu 2
|
||||
Submenu 3
|
||||
Menu Entry 3
|
||||
Menu Entry 4
|
||||
Menu Entry 5
|
||||
GNU/Hurd --id gnu-hurd
|
||||
Standard Boot --id=gnu-hurd-std
|
||||
Rescue shell --id=gnu-hurd-rescue
|
||||
Other platforms --id=other
|
||||
Minix --id=minix
|
||||
Version 3.4.0 --id=minix-3.4.0
|
||||
Version 3.3.0 --id=minix-3.3.0
|
||||
GRUB Invaders --id=grub-invaders
|
||||
@end example
|
||||
|
||||
``Menu Entry 3'' would then be identified as
|
||||
@samp{Submenu 2>Submenu 3>Menu Entry 3}.
|
||||
The more recent release of Minix would then be identified as
|
||||
@samp{Other platforms>Minix>Version 3.4.0}, or as @samp{1>0>0}, or as
|
||||
@samp{other>minix>minix-3.4.0}.
|
||||
|
||||
This variable is often set by @samp{GRUB_DEFAULT} (@pxref{Simple
|
||||
configuration}), @command{grub-set-default}, or @command{grub-reboot}.
|
||||
@@ -3420,6 +3430,12 @@ The default is the value of @samp{color_normal} (@pxref{color_normal}).
|
||||
@xref{Network}.
|
||||
|
||||
|
||||
@node net_@var{<interface>}_next_server
|
||||
@subsection net_@var{<interface>}_next_server
|
||||
|
||||
@xref{Network}.
|
||||
|
||||
|
||||
@node net_@var{<interface>}_rootpath
|
||||
@subsection net_@var{<interface>}_rootpath
|
||||
|
||||
@@ -4073,12 +4089,15 @@ after @command{configfile} returns.
|
||||
@node cpuid
|
||||
@subsection cpuid
|
||||
|
||||
@deffn Command cpuid [-l]
|
||||
@deffn Command cpuid [-l] [-p]
|
||||
Check for CPU features. This command is only available on x86 systems.
|
||||
|
||||
With the @option{-l} option, return true if the CPU supports long mode
|
||||
(64-bit).
|
||||
|
||||
With the @option{-p} option, return true if the CPU supports Physical
|
||||
Address Extension (PAE).
|
||||
|
||||
If invoked without options, this command currently behaves as if it had been
|
||||
invoked with @option{-l}. This may change in the future.
|
||||
@end deffn
|
||||
@@ -5042,6 +5061,8 @@ the length of @var{string} is zero
|
||||
@var{expression} is false
|
||||
@item @var{expression1} @code{-a} @var{expression2}
|
||||
both @var{expression1} and @var{expression2} are true
|
||||
@item @var{expression1} @var{expression2}
|
||||
both @var{expression1} and @var{expression2} are true. This syntax is not POSIX-compliant and is not recommended.
|
||||
@item @var{expression1} @code{-o} @var{expression2}
|
||||
either @var{expression1} or @var{expression2} is true
|
||||
@end table
|
||||
|
||||
10
gentpl.py
10
gentpl.py
@@ -31,7 +31,8 @@ GRUB_PLATFORMS = [ "emu", "i386_pc", "i386_efi", "i386_qemu", "i386_coreboot",
|
||||
"i386_xen", "x86_64_xen",
|
||||
"mips_loongson", "sparc64_ieee1275",
|
||||
"powerpc_ieee1275", "mips_arc", "ia64_efi",
|
||||
"mips_qemu_mips", "arm_uboot", "arm_efi", "arm64_efi" ]
|
||||
"mips_qemu_mips", "arm_uboot", "arm_efi", "arm64_efi",
|
||||
"arm_coreboot"]
|
||||
|
||||
GROUPS = {}
|
||||
|
||||
@@ -44,7 +45,7 @@ GROUPS["x86"] = GROUPS["i386"] + GROUPS["x86_64"]
|
||||
GROUPS["mips"] = [ "mips_loongson", "mips_qemu_mips", "mips_arc" ]
|
||||
GROUPS["sparc64"] = [ "sparc64_ieee1275" ]
|
||||
GROUPS["powerpc"] = [ "powerpc_ieee1275" ]
|
||||
GROUPS["arm"] = [ "arm_uboot", "arm_efi" ]
|
||||
GROUPS["arm"] = [ "arm_uboot", "arm_efi", "arm_coreboot" ]
|
||||
GROUPS["arm64"] = [ "arm64_efi" ]
|
||||
|
||||
# Groups based on firmware
|
||||
@@ -52,6 +53,7 @@ GROUPS["efi"] = [ "i386_efi", "x86_64_efi", "ia64_efi", "arm_efi", "arm64_efi"
|
||||
GROUPS["ieee1275"] = [ "i386_ieee1275", "sparc64_ieee1275", "powerpc_ieee1275" ]
|
||||
GROUPS["uboot"] = [ "arm_uboot" ]
|
||||
GROUPS["xen"] = [ "i386_xen", "x86_64_xen" ]
|
||||
GROUPS["coreboot"] = [ "i386_coreboot", "arm_coreboot" ]
|
||||
|
||||
# emu is a special case so many core functionality isn't needed on this platform
|
||||
GROUPS["noemu"] = GRUB_PLATFORMS[:]; GROUPS["noemu"].remove("emu")
|
||||
@@ -61,10 +63,10 @@ GROUPS["cmos"] = GROUPS["x86"][:] + ["mips_loongson", "mips_qemu_mips",
|
||||
"sparc64_ieee1275", "powerpc_ieee1275"]
|
||||
GROUPS["cmos"].remove("i386_efi"); GROUPS["cmos"].remove("x86_64_efi");
|
||||
GROUPS["pci"] = GROUPS["x86"] + ["mips_loongson"]
|
||||
GROUPS["usb"] = GROUPS["pci"]
|
||||
GROUPS["usb"] = GROUPS["pci"] + ["arm_coreboot"]
|
||||
|
||||
# If gfxterm is main output console integrate it into kernel
|
||||
GROUPS["videoinkernel"] = ["mips_loongson", "i386_coreboot" ]
|
||||
GROUPS["videoinkernel"] = ["mips_loongson", "i386_coreboot", "arm_coreboot" ]
|
||||
GROUPS["videomodules"] = GRUB_PLATFORMS[:];
|
||||
for i in GROUPS["videoinkernel"]: GROUPS["videomodules"].remove(i)
|
||||
|
||||
|
||||
@@ -107,11 +107,12 @@ KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/efi/disk.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/i386/tsc.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/acpi.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/pci.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/i386/pmtimer.h
|
||||
endif
|
||||
|
||||
if COND_i386_coreboot
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/i386/tsc.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/i386/coreboot/lbio.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/coreboot/lbio.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/video.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/video_fb.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/gfxterm.h
|
||||
@@ -162,6 +163,7 @@ KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/efi/disk.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/i386/tsc.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/pci.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/acpi.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/i386/pmtimer.h
|
||||
endif
|
||||
|
||||
if COND_ia64_efi
|
||||
@@ -237,6 +239,20 @@ KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/lib/arg.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/arm/system.h
|
||||
endif
|
||||
|
||||
if COND_arm_coreboot
|
||||
KERNEL_HEADER_FILES += $(top_builddir)/include/grub/keyboard_layouts.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/arm/system.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/video.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/video_fb.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/gfxterm.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/font.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/bufio.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/fdt.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/dma.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/arm/coreboot/kernel.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/fdtbus.h
|
||||
endif
|
||||
|
||||
if COND_arm_efi
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/arm/efi/loader.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/efi/efi.h
|
||||
@@ -276,7 +292,7 @@ BUILT_SOURCES += symlist.h
|
||||
|
||||
symlist.c: symlist.h gensymlist.sh
|
||||
$(TARGET_CPP) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS_KERNEL) $(CPPFLAGS) -DGRUB_SYMBOL_GENERATOR=1 symlist.h > symlist.p || (rm -f symlist.p; exit 1)
|
||||
cat symlist.p | /bin/sh $(srcdir)/gensymlist.sh $(top_builddir)/config.h $(KERNEL_HEADER_FILES) >$@ || (rm -f $@; exit 1)
|
||||
cat symlist.p | $(SHELL) $(srcdir)/gensymlist.sh $(top_builddir)/config.h $(KERNEL_HEADER_FILES) >$@ || (rm -f $@; exit 1)
|
||||
rm -f symlist.p
|
||||
CLEANFILES += symlist.c
|
||||
BUILT_SOURCES += symlist.c
|
||||
@@ -356,6 +372,16 @@ terminal.lst: $(MARKER_FILES)
|
||||
platform_DATA += terminal.lst
|
||||
CLEANFILES += terminal.lst
|
||||
|
||||
fdt.lst: $(MARKER_FILES)
|
||||
(for pp in $^; do \
|
||||
b=`basename $$pp .marker`; \
|
||||
sed -n \
|
||||
-e "/FDT_DRIVER_LIST_MARKER *( *\"/{s/.*( *\"\([^\"]*\)\".*/i\1: $$b/;p;}" \
|
||||
-e "/FDT_DRIVER_LIST_MARKER *( *\"/{s/.*( *\"\([^\"]*\)\".*/o\1: $$b/;p;}" $$pp; \
|
||||
done) | sort -u > $@
|
||||
platform_DATA += fdt.lst
|
||||
CLEANFILES += fdt.lst
|
||||
|
||||
parttool.lst: $(MARKER_FILES)
|
||||
(for pp in $^; do \
|
||||
b=`basename $$pp .marker`; \
|
||||
|
||||
@@ -90,8 +90,10 @@ kernel = {
|
||||
i386_qemu_cppflags = '-DGRUB_BOOT_MACHINE_LINK_ADDR=$(GRUB_BOOT_MACHINE_LINK_ADDR)';
|
||||
emu_cflags = '$(CFLAGS_GNULIB)';
|
||||
emu_cppflags = '$(CPPFLAGS_GNULIB)';
|
||||
arm_uboot_ldflags = '-Wl,-Ttext=0x08000000';
|
||||
arm_uboot_ldflags = '-Wl,-r,-d';
|
||||
arm_uboot_stripflags = '--strip-unneeded -K start -R .note -R .comment -R .note.gnu.gold-version';
|
||||
arm_coreboot_ldflags = '-Wl,-r,-d';
|
||||
arm_coreboot_stripflags = '--strip-unneeded -K start -R .note -R .comment -R .note.gnu.gold-version';
|
||||
|
||||
i386_pc_startup = kern/i386/pc/startup.S;
|
||||
i386_efi_startup = kern/i386/efi/startup.S;
|
||||
@@ -105,7 +107,8 @@ kernel = {
|
||||
mips_startup = kern/mips/startup.S;
|
||||
sparc64_ieee1275_startup = kern/sparc64/ieee1275/crt0.S;
|
||||
powerpc_ieee1275_startup = kern/powerpc/ieee1275/startup.S;
|
||||
arm_uboot_startup = kern/arm/uboot/startup.S;
|
||||
arm_uboot_startup = kern/arm/startup.S;
|
||||
arm_coreboot_startup = kern/arm/startup.S;
|
||||
arm_efi_startup = kern/arm/efi/startup.S;
|
||||
arm64_efi_startup = kern/arm64/efi/startup.S;
|
||||
|
||||
@@ -149,6 +152,21 @@ kernel = {
|
||||
uboot = kern/uboot/init.c;
|
||||
uboot = kern/uboot/hw.c;
|
||||
uboot = term/uboot/console.c;
|
||||
arm_uboot = kern/arm/uboot/init.c;
|
||||
arm_uboot = kern/arm/uboot/uboot.S;
|
||||
|
||||
arm_coreboot = kern/arm/coreboot/init.c;
|
||||
arm_coreboot = kern/arm/coreboot/timer.c;
|
||||
arm_coreboot = kern/arm/coreboot/coreboot.S;
|
||||
arm_coreboot = lib/fdt.c;
|
||||
arm_coreboot = bus/fdt.c;
|
||||
arm_coreboot = term/ps2.c;
|
||||
arm_coreboot = term/arm/pl050.c;
|
||||
arm_coreboot = term/arm/cros.c;
|
||||
arm_coreboot = term/arm/cros_ec.c;
|
||||
arm_coreboot = bus/spi/rk3288_spi.c;
|
||||
arm_coreboot = commands/keylayouts.c;
|
||||
arm_coreboot = kern/arm/coreboot/dma.c;
|
||||
|
||||
terminfoinkernel = term/terminfo.c;
|
||||
terminfoinkernel = term/tparm.c;
|
||||
@@ -164,7 +182,7 @@ kernel = {
|
||||
i386_multiboot = kern/i386/coreboot/init.c;
|
||||
i386_qemu = kern/i386/qemu/init.c;
|
||||
i386_coreboot_multiboot_qemu = term/i386/pc/vga_text.c;
|
||||
i386_coreboot = video/i386/coreboot/cbfb.c;
|
||||
coreboot = video/coreboot/cbfb.c;
|
||||
|
||||
efi = disk/efi/efidisk.c;
|
||||
efi = kern/efi/efi.c;
|
||||
@@ -212,8 +230,10 @@ kernel = {
|
||||
|
||||
arm_efi = kern/arm/efi/init.c;
|
||||
arm_efi = kern/arm/efi/misc.c;
|
||||
arm_efi = kern/efi/fdt.c;
|
||||
|
||||
arm64_efi = kern/arm/efi/init.c;
|
||||
arm64_efi = kern/arm64/efi/init.c;
|
||||
arm64_efi = kern/efi/fdt.c;
|
||||
|
||||
i386_pc = kern/i386/pc/init.c;
|
||||
i386_pc = kern/i386/pc/mmap.c;
|
||||
@@ -223,8 +243,10 @@ kernel = {
|
||||
i386_qemu = kern/vga_init.c;
|
||||
i386_qemu = kern/i386/qemu/mmap.c;
|
||||
|
||||
i386_coreboot = kern/i386/coreboot/mmap.c;
|
||||
coreboot = kern/coreboot/mmap.c;
|
||||
i386_coreboot = kern/i386/coreboot/cbtable.c;
|
||||
coreboot = kern/coreboot/cbtable.c;
|
||||
arm_coreboot = kern/arm/coreboot/cbtable.c;
|
||||
|
||||
i386_multiboot = kern/i386/multiboot_mmap.c;
|
||||
|
||||
@@ -236,6 +258,7 @@ kernel = {
|
||||
mips_qemu_mips = term/ns8250.c;
|
||||
mips_qemu_mips = term/serial.c;
|
||||
mips_qemu_mips = term/at_keyboard.c;
|
||||
mips_qemu_mips = term/ps2.c;
|
||||
mips_qemu_mips = commands/boot.c;
|
||||
mips_qemu_mips = commands/keylayouts.c;
|
||||
mips_qemu_mips = term/i386/pc/vga_text.c;
|
||||
@@ -251,6 +274,7 @@ kernel = {
|
||||
mips_loongson = bus/pci.c;
|
||||
mips_loongson = kern/mips/loongson/init.c;
|
||||
mips_loongson = term/at_keyboard.c;
|
||||
mips_loongson = term/ps2.c;
|
||||
mips_loongson = commands/boot.c;
|
||||
mips_loongson = term/serial.c;
|
||||
mips_loongson = video/sm712.c;
|
||||
@@ -572,7 +596,10 @@ module = {
|
||||
module = {
|
||||
name = ehci;
|
||||
common = bus/usb/ehci.c;
|
||||
arm_coreboot = bus/usb/ehci-fdt.c;
|
||||
pci = bus/usb/ehci-pci.c;
|
||||
enable = pci;
|
||||
enable = arm_coreboot;
|
||||
};
|
||||
|
||||
module = {
|
||||
@@ -639,6 +666,7 @@ module = {
|
||||
module = {
|
||||
name = cbtable;
|
||||
common = kern/i386/coreboot/cbtable.c;
|
||||
common = kern/coreboot/cbtable.c;
|
||||
enable = i386_pc;
|
||||
enable = i386_efi;
|
||||
enable = i386_qemu;
|
||||
@@ -752,6 +780,7 @@ module = {
|
||||
enable = arm_efi;
|
||||
enable = arm64_efi;
|
||||
enable = arm_uboot;
|
||||
enable = arm_coreboot;
|
||||
};
|
||||
|
||||
module = {
|
||||
@@ -835,7 +864,8 @@ module = {
|
||||
efi = lib/efi/halt.c;
|
||||
ieee1275 = lib/ieee1275/halt.c;
|
||||
emu = lib/emu/halt.c;
|
||||
uboot = lib/uboot/halt.c;
|
||||
uboot = lib/dummy/halt.c;
|
||||
arm_coreboot = lib/dummy/halt.c;
|
||||
};
|
||||
|
||||
module = {
|
||||
@@ -853,6 +883,7 @@ module = {
|
||||
mips_qemu_mips = lib/mips/qemu_mips/reboot.c;
|
||||
xen = lib/xen/reboot.c;
|
||||
uboot = lib/uboot/reboot.c;
|
||||
arm_coreboot = lib/dummy/reboot.c;
|
||||
common = commands/reboot.c;
|
||||
};
|
||||
|
||||
@@ -868,6 +899,11 @@ module = {
|
||||
cppflags = '-I$(srcdir)/lib/posix_wrap';
|
||||
};
|
||||
|
||||
module = {
|
||||
name = verify_helper;
|
||||
common = commands/verify_helper.c;
|
||||
};
|
||||
|
||||
module = {
|
||||
name = hdparm;
|
||||
common = commands/hdparm.c;
|
||||
@@ -1531,6 +1567,7 @@ module = {
|
||||
i386_xen = lib/i386/xen/relocator.S;
|
||||
x86_64_xen = lib/x86_64/xen/relocator.S;
|
||||
xen = lib/i386/relocator_common_c.c;
|
||||
x86_64_efi = lib/x86_64/efi/relocator.c;
|
||||
|
||||
extra_dist = lib/i386/relocator_common.S;
|
||||
extra_dist = kern/powerpc/cache_flush.S;
|
||||
@@ -1545,7 +1582,8 @@ module = {
|
||||
name = datetime;
|
||||
cmos = lib/cmos_datetime.c;
|
||||
efi = lib/efi/datetime.c;
|
||||
uboot = lib/uboot/datetime.c;
|
||||
uboot = lib/dummy/datetime.c;
|
||||
arm_coreboot = lib/dummy/datetime.c;
|
||||
sparc64_ieee1275 = lib/ieee1275/datetime.c;
|
||||
powerpc_ieee1275 = lib/ieee1275/datetime.c;
|
||||
sparc64_ieee1275 = lib/ieee1275/cmos.c;
|
||||
@@ -1685,7 +1723,32 @@ module = {
|
||||
x86 = loader/i386/xnu.c;
|
||||
x86 = loader/xnu.c;
|
||||
|
||||
enable = x86;
|
||||
/* Code is pretty generic but relies on RNG which
|
||||
is available only on few platforms. It's not a
|
||||
big deal as xnu needs ACPI anyway and we have
|
||||
RNG on all platforms with ACPI.
|
||||
*/
|
||||
enable = i386_multiboot;
|
||||
enable = i386_coreboot;
|
||||
enable = i386_pc;
|
||||
enable = i386_efi;
|
||||
enable = x86_64_efi;
|
||||
};
|
||||
|
||||
module = {
|
||||
name = random;
|
||||
x86 = lib/i386/random.c;
|
||||
common = lib/random.c;
|
||||
|
||||
i386_multiboot = kern/i386/tsc_pmtimer.c;
|
||||
i386_coreboot = kern/i386/tsc_pmtimer.c;
|
||||
i386_pc = kern/i386/tsc_pmtimer.c;
|
||||
|
||||
enable = i386_multiboot;
|
||||
enable = i386_coreboot;
|
||||
enable = i386_pc;
|
||||
enable = i386_efi;
|
||||
enable = x86_64_efi;
|
||||
};
|
||||
|
||||
module = {
|
||||
@@ -1841,6 +1904,7 @@ module = {
|
||||
module = {
|
||||
name = at_keyboard;
|
||||
common = term/at_keyboard.c;
|
||||
common = term/ps2.c;
|
||||
enable = x86;
|
||||
};
|
||||
|
||||
@@ -1933,6 +1997,11 @@ module = {
|
||||
common = tests/example_functional_test.c;
|
||||
};
|
||||
|
||||
module = {
|
||||
name = strtoull_test;
|
||||
common = tests/strtoull_test.c;
|
||||
};
|
||||
|
||||
module = {
|
||||
name = setjmp_test;
|
||||
common = tests/setjmp_test.c;
|
||||
|
||||
256
grub-core/bus/fdt.c
Normal file
256
grub-core/bus/fdt.c
Normal file
@@ -0,0 +1,256 @@
|
||||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 2016 Free Software Foundation, Inc.
|
||||
*
|
||||
* GRUB is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* GRUB is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <grub/fdtbus.h>
|
||||
#include <grub/fdt.h>
|
||||
#include <grub/term.h>
|
||||
|
||||
static const void *dtb;
|
||||
static grub_size_t root_address_cells, root_size_cells;
|
||||
/* Pointer to this symbol signals invalid mapping. */
|
||||
char grub_fdtbus_invalid_mapping[1];
|
||||
|
||||
struct grub_fdtbus_dev *devs;
|
||||
struct grub_fdtbus_driver *drivers;
|
||||
|
||||
int
|
||||
grub_fdtbus_is_compatible (const char *compat_string,
|
||||
const struct grub_fdtbus_dev *dev)
|
||||
{
|
||||
grub_size_t compatible_size;
|
||||
const char *compatible = grub_fdt_get_prop (dtb, dev->node, "compatible",
|
||||
&compatible_size);
|
||||
if (!compatible)
|
||||
return 0;
|
||||
const char *compatible_end = compatible + compatible_size;
|
||||
while (compatible < compatible_end)
|
||||
{
|
||||
if (grub_strcmp (compat_string, compatible) == 0)
|
||||
return 1;
|
||||
compatible += grub_strlen (compatible) + 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
fdtbus_scan (struct grub_fdtbus_dev *parent)
|
||||
{
|
||||
int node;
|
||||
for (node = grub_fdt_first_node (dtb, parent ? parent->node : 0); node >= 0;
|
||||
node = grub_fdt_next_node (dtb, node))
|
||||
{
|
||||
struct grub_fdtbus_dev *dev;
|
||||
struct grub_fdtbus_driver *driver;
|
||||
dev = grub_zalloc (sizeof (*dev));
|
||||
if (!dev)
|
||||
{
|
||||
grub_print_error ();
|
||||
return;
|
||||
}
|
||||
dev->node = node;
|
||||
dev->next = devs;
|
||||
dev->parent = parent;
|
||||
devs = dev;
|
||||
FOR_LIST_ELEMENTS(driver, drivers)
|
||||
if (!dev->driver && grub_fdtbus_is_compatible (driver->compatible, dev))
|
||||
{
|
||||
grub_dprintf ("fdtbus", "Attaching %s\n", driver->compatible);
|
||||
if (driver->attach (dev) == GRUB_ERR_NONE)
|
||||
{
|
||||
grub_dprintf ("fdtbus", "Attached %s\n", driver->compatible);
|
||||
dev->driver = driver;
|
||||
break;
|
||||
}
|
||||
grub_print_error ();
|
||||
}
|
||||
fdtbus_scan (dev);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
grub_fdtbus_register (struct grub_fdtbus_driver *driver)
|
||||
{
|
||||
struct grub_fdtbus_dev *dev;
|
||||
grub_dprintf ("fdtbus", "Registering %s\n", driver->compatible);
|
||||
grub_list_push (GRUB_AS_LIST_P (&drivers),
|
||||
GRUB_AS_LIST (driver));
|
||||
for (dev = devs; dev; dev = dev->next)
|
||||
if (!dev->driver && grub_fdtbus_is_compatible (driver->compatible, dev))
|
||||
{
|
||||
grub_dprintf ("fdtbus", "Attaching %s (%p)\n", driver->compatible, dev);
|
||||
if (driver->attach (dev) == GRUB_ERR_NONE)
|
||||
{
|
||||
grub_dprintf ("fdtbus", "Attached %s\n", driver->compatible);
|
||||
dev->driver = driver;
|
||||
}
|
||||
grub_print_error ();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
grub_fdtbus_unregister (struct grub_fdtbus_driver *driver)
|
||||
{
|
||||
grub_list_remove (GRUB_AS_LIST (driver));
|
||||
struct grub_fdtbus_dev *dev;
|
||||
for (dev = devs; dev; dev = dev->next)
|
||||
if (dev->driver == driver)
|
||||
{
|
||||
if (driver->detach)
|
||||
driver->detach(dev);
|
||||
dev->driver = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
grub_fdtbus_init (const void *dtb_in, grub_size_t size)
|
||||
{
|
||||
if (!dtb_in || grub_fdt_check_header (dtb_in, size) < 0)
|
||||
grub_fatal ("invalid FDT");
|
||||
dtb = dtb_in;
|
||||
const grub_uint32_t *prop = grub_fdt_get_prop (dtb, 0, "#address-cells", 0);
|
||||
if (prop)
|
||||
root_address_cells = grub_be_to_cpu32 (*prop);
|
||||
else
|
||||
root_address_cells = 1;
|
||||
|
||||
prop = grub_fdt_get_prop (dtb, 0, "#size-cells", 0);
|
||||
if (prop)
|
||||
root_size_cells = grub_be_to_cpu32 (*prop);
|
||||
else
|
||||
root_size_cells = 1;
|
||||
|
||||
fdtbus_scan (0);
|
||||
}
|
||||
|
||||
static int
|
||||
get_address_cells (const struct grub_fdtbus_dev *dev)
|
||||
{
|
||||
const grub_uint32_t *prop;
|
||||
if (!dev)
|
||||
return root_address_cells;
|
||||
prop = grub_fdt_get_prop (dtb, dev->node, "#address-cells", 0);
|
||||
if (prop)
|
||||
return grub_be_to_cpu32 (*prop);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
get_size_cells (const struct grub_fdtbus_dev *dev)
|
||||
{
|
||||
const grub_uint32_t *prop;
|
||||
if (!dev)
|
||||
return root_size_cells;
|
||||
prop = grub_fdt_get_prop (dtb, dev->node, "#size-cells", 0);
|
||||
if (prop)
|
||||
return grub_be_to_cpu32 (*prop);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static grub_uint64_t
|
||||
get64 (const grub_uint32_t *reg, grub_size_t cells)
|
||||
{
|
||||
grub_uint64_t val = 0;
|
||||
if (cells >= 1)
|
||||
val = grub_be_to_cpu32 (reg[cells - 1]);
|
||||
if (cells >= 2)
|
||||
val |= ((grub_uint64_t) grub_be_to_cpu32 (reg[cells - 2])) << 32;
|
||||
return val;
|
||||
}
|
||||
|
||||
static volatile void *
|
||||
translate (const struct grub_fdtbus_dev *dev, const grub_uint32_t *reg)
|
||||
{
|
||||
volatile void *ret;
|
||||
const grub_uint32_t *ranges;
|
||||
grub_size_t ranges_size, cells_per_mapping;
|
||||
grub_size_t parent_address_cells, child_address_cells, child_size_cells;
|
||||
grub_size_t nmappings, i;
|
||||
if (dev == 0)
|
||||
{
|
||||
grub_uint64_t val;
|
||||
val = get64 (reg, root_address_cells);
|
||||
if (sizeof (void *) == 4 && (val >> 32))
|
||||
return grub_fdtbus_invalid_mapping;
|
||||
return (void *) (grub_addr_t) val;
|
||||
}
|
||||
ranges = grub_fdt_get_prop (dtb, dev->node, "ranges", &ranges_size);
|
||||
if (!ranges)
|
||||
return grub_fdtbus_invalid_mapping;
|
||||
if (ranges_size == 0)
|
||||
return translate (dev->parent, reg);
|
||||
parent_address_cells = get_address_cells (dev->parent);
|
||||
child_address_cells = get_address_cells (dev);
|
||||
child_size_cells = get_size_cells (dev);
|
||||
cells_per_mapping = parent_address_cells + child_address_cells + child_size_cells;
|
||||
nmappings = ranges_size / 4 / cells_per_mapping;
|
||||
for (i = 0; i < nmappings; i++)
|
||||
{
|
||||
const grub_uint32_t *child_addr = &ranges[i * cells_per_mapping];
|
||||
const grub_uint32_t *parent_addr = child_addr + child_address_cells;
|
||||
grub_uint64_t child_size = get64 (parent_addr + parent_address_cells, child_size_cells);
|
||||
|
||||
if (child_address_cells > 2 && grub_memcmp (reg, child_addr, (child_address_cells - 2) * 4) != 0)
|
||||
continue;
|
||||
if (get64 (reg, child_address_cells) < get64 (child_addr, child_address_cells))
|
||||
continue;
|
||||
|
||||
grub_uint64_t offset = get64 (reg, child_address_cells) - get64 (child_addr, child_address_cells);
|
||||
if (offset >= child_size)
|
||||
continue;
|
||||
|
||||
ret = translate (dev->parent, parent_addr);
|
||||
if (grub_fdtbus_is_mapping_valid (ret))
|
||||
ret = (volatile char *) ret + offset;
|
||||
return ret;
|
||||
}
|
||||
return grub_fdtbus_invalid_mapping;
|
||||
}
|
||||
|
||||
volatile void *
|
||||
grub_fdtbus_map_reg (const struct grub_fdtbus_dev *dev, int regno, grub_size_t *size)
|
||||
{
|
||||
grub_size_t address_cells, size_cells;
|
||||
address_cells = get_address_cells (dev->parent);
|
||||
size_cells = get_size_cells (dev->parent);
|
||||
const grub_uint32_t *reg = grub_fdt_get_prop (dtb, dev->node, "reg", 0);
|
||||
if (size && size_cells)
|
||||
*size = reg[(address_cells + size_cells) * regno + address_cells];
|
||||
if (size && !size_cells)
|
||||
*size = 0;
|
||||
return translate (dev->parent, reg + (address_cells + size_cells) * regno);
|
||||
}
|
||||
|
||||
const char *
|
||||
grub_fdtbus_get_name (const struct grub_fdtbus_dev *dev)
|
||||
{
|
||||
return grub_fdt_get_nodename (dtb, dev->node);
|
||||
}
|
||||
|
||||
const void *
|
||||
grub_fdtbus_get_prop (const struct grub_fdtbus_dev *dev,
|
||||
const char *name,
|
||||
grub_uint32_t *len)
|
||||
{
|
||||
return grub_fdt_get_prop (dtb, dev->node, name, len);
|
||||
}
|
||||
|
||||
const void *
|
||||
grub_fdtbus_get_fdt (void)
|
||||
{
|
||||
return dtb;
|
||||
}
|
||||
103
grub-core/bus/spi/rk3288_spi.c
Normal file
103
grub-core/bus/spi/rk3288_spi.c
Normal file
@@ -0,0 +1,103 @@
|
||||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
*
|
||||
* Copyright (C) 2012 Google Inc.
|
||||
* Copyright (C) 2016 Free Software Foundation, Inc.
|
||||
*
|
||||
* This is based on depthcharge code.
|
||||
*
|
||||
* GRUB is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* GRUB is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <grub/mm.h>
|
||||
#include <grub/time.h>
|
||||
#include <grub/misc.h>
|
||||
#include <grub/fdtbus.h>
|
||||
#include <grub/machine/kernel.h>
|
||||
|
||||
static grub_err_t
|
||||
spi_send (const struct grub_fdtbus_dev *dev, const void *data, grub_size_t sz)
|
||||
{
|
||||
const grub_uint8_t *ptr = data, *end = ptr + sz;
|
||||
volatile grub_uint32_t *spi = grub_fdtbus_map_reg (dev, 0, 0);
|
||||
spi[2] = 0;
|
||||
spi[1] = sz - 1;
|
||||
spi[0] = ((1 << 18) | spi[0]) & ~(1 << 19);
|
||||
spi[2] = 1;
|
||||
while (ptr < end)
|
||||
{
|
||||
while (spi[9] & 2);
|
||||
spi[256] = *ptr++;
|
||||
}
|
||||
while (spi[9] & 1);
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
static grub_err_t
|
||||
spi_receive (const struct grub_fdtbus_dev *dev, void *data, grub_size_t sz)
|
||||
{
|
||||
grub_uint8_t *ptr = data, *end = ptr + sz;
|
||||
volatile grub_uint32_t *spi = grub_fdtbus_map_reg (dev, 0, 0);
|
||||
spi[2] = 0;
|
||||
spi[1] = sz - 1;
|
||||
spi[0] = ((1 << 19) | spi[0]) & ~(1 << 18);
|
||||
spi[2] = 1;
|
||||
while (ptr < end)
|
||||
{
|
||||
while (spi[9] & 8);
|
||||
*ptr++ = spi[512];
|
||||
}
|
||||
while (spi[9] & 1);
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
static grub_err_t
|
||||
spi_start (const struct grub_fdtbus_dev *dev)
|
||||
{
|
||||
volatile grub_uint32_t *spi = grub_fdtbus_map_reg (dev, 0, 0);
|
||||
spi[3] = 1;
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
static void
|
||||
spi_stop (const struct grub_fdtbus_dev *dev)
|
||||
{
|
||||
volatile grub_uint32_t *spi = grub_fdtbus_map_reg (dev, 0, 0);
|
||||
spi[3] = 0;
|
||||
}
|
||||
|
||||
static grub_err_t
|
||||
spi_attach(const struct grub_fdtbus_dev *dev)
|
||||
{
|
||||
if (!grub_fdtbus_is_mapping_valid (grub_fdtbus_map_reg (dev, 0, 0)))
|
||||
return GRUB_ERR_IO;
|
||||
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
static struct grub_fdtbus_driver spi =
|
||||
{
|
||||
.compatible = "rockchip,rk3288-spi",
|
||||
.attach = spi_attach,
|
||||
.send = spi_send,
|
||||
.receive = spi_receive,
|
||||
.start = spi_start,
|
||||
.stop = spi_stop,
|
||||
};
|
||||
|
||||
void
|
||||
grub_rk3288_spi_init (void)
|
||||
{
|
||||
grub_fdtbus_register (&spi);
|
||||
}
|
||||
45
grub-core/bus/usb/ehci-fdt.c
Normal file
45
grub-core/bus/usb/ehci-fdt.c
Normal file
@@ -0,0 +1,45 @@
|
||||
/* ehci.c - EHCI Support. */
|
||||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 2011 Free Software Foundation, Inc.
|
||||
*
|
||||
* GRUB is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* GRUB is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <grub/misc.h>
|
||||
#include <grub/mm.h>
|
||||
#include <grub/time.h>
|
||||
#include <grub/usb.h>
|
||||
#include <grub/fdtbus.h>
|
||||
|
||||
static grub_err_t
|
||||
ehci_attach(const struct grub_fdtbus_dev *dev)
|
||||
{
|
||||
grub_dprintf ("ehci", "Found generic-ehci\n");
|
||||
|
||||
grub_ehci_init_device (grub_fdtbus_map_reg (dev, 0, 0));
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct grub_fdtbus_driver ehci =
|
||||
{
|
||||
.compatible = "generic-ehci",
|
||||
.attach = ehci_attach
|
||||
};
|
||||
|
||||
void
|
||||
grub_ehci_pci_scan (void)
|
||||
{
|
||||
grub_fdtbus_register (&ehci);
|
||||
}
|
||||
208
grub-core/bus/usb/ehci-pci.c
Normal file
208
grub-core/bus/usb/ehci-pci.c
Normal file
@@ -0,0 +1,208 @@
|
||||
/* ehci.c - EHCI Support. */
|
||||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 2011 Free Software Foundation, Inc.
|
||||
*
|
||||
* GRUB is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* GRUB is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <grub/pci.h>
|
||||
#include <grub/cpu/pci.h>
|
||||
#include <grub/cs5536.h>
|
||||
#include <grub/misc.h>
|
||||
#include <grub/mm.h>
|
||||
#include <grub/time.h>
|
||||
#include <grub/usb.h>
|
||||
|
||||
#define GRUB_EHCI_PCI_SBRN_REG 0x60
|
||||
#define GRUB_EHCI_ADDR_MEM_MASK (~0xff)
|
||||
|
||||
/* USBLEGSUP bits and related OS OWNED byte offset */
|
||||
enum
|
||||
{
|
||||
GRUB_EHCI_BIOS_OWNED = (1 << 16),
|
||||
GRUB_EHCI_OS_OWNED = (1 << 24)
|
||||
};
|
||||
|
||||
/* PCI iteration function... */
|
||||
static int
|
||||
grub_ehci_pci_iter (grub_pci_device_t dev, grub_pci_id_t pciid,
|
||||
void *data __attribute__ ((unused)))
|
||||
{
|
||||
volatile grub_uint32_t *regs;
|
||||
grub_uint32_t base, base_h;
|
||||
grub_uint32_t eecp_offset;
|
||||
grub_uint32_t usblegsup = 0;
|
||||
grub_uint64_t maxtime;
|
||||
grub_uint32_t interf;
|
||||
grub_uint32_t subclass;
|
||||
grub_uint32_t class;
|
||||
grub_uint8_t release;
|
||||
grub_uint32_t class_code;
|
||||
|
||||
grub_dprintf ("ehci", "EHCI grub_ehci_pci_iter: begin\n");
|
||||
|
||||
if (pciid == GRUB_CS5536_PCIID)
|
||||
{
|
||||
grub_uint64_t basereg;
|
||||
|
||||
basereg = grub_cs5536_read_msr (dev, GRUB_CS5536_MSR_USB_EHCI_BASE);
|
||||
if (!(basereg & GRUB_CS5536_MSR_USB_BASE_MEMORY_ENABLE))
|
||||
{
|
||||
/* Shouldn't happen. */
|
||||
grub_dprintf ("ehci", "No EHCI address is assigned\n");
|
||||
return 0;
|
||||
}
|
||||
base = (basereg & GRUB_CS5536_MSR_USB_BASE_ADDR_MASK);
|
||||
basereg |= GRUB_CS5536_MSR_USB_BASE_BUS_MASTER;
|
||||
basereg &= ~GRUB_CS5536_MSR_USB_BASE_PME_ENABLED;
|
||||
basereg &= ~GRUB_CS5536_MSR_USB_BASE_PME_STATUS;
|
||||
basereg &= ~GRUB_CS5536_MSR_USB_BASE_SMI_ENABLE;
|
||||
grub_cs5536_write_msr (dev, GRUB_CS5536_MSR_USB_EHCI_BASE, basereg);
|
||||
}
|
||||
else
|
||||
{
|
||||
grub_pci_address_t addr;
|
||||
addr = grub_pci_make_address (dev, GRUB_PCI_REG_CLASS);
|
||||
class_code = grub_pci_read (addr) >> 8;
|
||||
interf = class_code & 0xFF;
|
||||
subclass = (class_code >> 8) & 0xFF;
|
||||
class = class_code >> 16;
|
||||
|
||||
/* If this is not an EHCI controller, just return. */
|
||||
if (class != 0x0c || subclass != 0x03 || interf != 0x20)
|
||||
return 0;
|
||||
|
||||
grub_dprintf ("ehci", "EHCI grub_ehci_pci_iter: class OK\n");
|
||||
|
||||
/* Check Serial Bus Release Number */
|
||||
addr = grub_pci_make_address (dev, GRUB_EHCI_PCI_SBRN_REG);
|
||||
release = grub_pci_read_byte (addr);
|
||||
if (release != 0x20)
|
||||
{
|
||||
grub_dprintf ("ehci", "EHCI grub_ehci_pci_iter: Wrong SBRN: %0x\n",
|
||||
release);
|
||||
return 0;
|
||||
}
|
||||
grub_dprintf ("ehci", "EHCI grub_ehci_pci_iter: bus rev. num. OK\n");
|
||||
|
||||
/* Determine EHCI EHCC registers base address. */
|
||||
addr = grub_pci_make_address (dev, GRUB_PCI_REG_ADDRESS_REG0);
|
||||
base = grub_pci_read (addr);
|
||||
addr = grub_pci_make_address (dev, GRUB_PCI_REG_ADDRESS_REG1);
|
||||
base_h = grub_pci_read (addr);
|
||||
/* Stop if registers are mapped above 4G - GRUB does not currently
|
||||
* work with registers mapped above 4G */
|
||||
if (((base & GRUB_PCI_ADDR_MEM_TYPE_MASK) != GRUB_PCI_ADDR_MEM_TYPE_32)
|
||||
&& (base_h != 0))
|
||||
{
|
||||
grub_dprintf ("ehci",
|
||||
"EHCI grub_ehci_pci_iter: registers above 4G are not supported\n");
|
||||
return 0;
|
||||
}
|
||||
base &= GRUB_PCI_ADDR_MEM_MASK;
|
||||
if (!base)
|
||||
{
|
||||
grub_dprintf ("ehci",
|
||||
"EHCI: EHCI is not mapped\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Set bus master - needed for coreboot, VMware, broken BIOSes etc. */
|
||||
addr = grub_pci_make_address (dev, GRUB_PCI_REG_COMMAND);
|
||||
grub_pci_write_word(addr,
|
||||
GRUB_PCI_COMMAND_MEM_ENABLED
|
||||
| GRUB_PCI_COMMAND_BUS_MASTER
|
||||
| grub_pci_read_word(addr));
|
||||
|
||||
grub_dprintf ("ehci", "EHCI grub_ehci_pci_iter: 32-bit EHCI OK\n");
|
||||
}
|
||||
|
||||
grub_dprintf ("ehci", "EHCI grub_ehci_pci_iter: iobase of EHCC: %08x\n",
|
||||
(base & GRUB_EHCI_ADDR_MEM_MASK));
|
||||
|
||||
regs = grub_pci_device_map_range (dev,
|
||||
(base & GRUB_EHCI_ADDR_MEM_MASK),
|
||||
0x100);
|
||||
|
||||
/* Is there EECP ? */
|
||||
eecp_offset = (grub_le_to_cpu32 (regs[2]) >> 8) & 0xff;
|
||||
|
||||
/* Determine and change ownership. */
|
||||
/* EECP offset valid in HCCPARAMS */
|
||||
/* Ownership can be changed via EECP only */
|
||||
if (pciid != GRUB_CS5536_PCIID && eecp_offset >= 0x40)
|
||||
{
|
||||
grub_pci_address_t pciaddr_eecp;
|
||||
pciaddr_eecp = grub_pci_make_address (dev, eecp_offset);
|
||||
|
||||
usblegsup = grub_pci_read (pciaddr_eecp);
|
||||
if (usblegsup & GRUB_EHCI_BIOS_OWNED)
|
||||
{
|
||||
grub_boot_time ("Taking ownership of EHCI controller");
|
||||
grub_dprintf ("ehci",
|
||||
"EHCI grub_ehci_pci_iter: EHCI owned by: BIOS\n");
|
||||
/* Ownership change - set OS_OWNED bit */
|
||||
grub_pci_write (pciaddr_eecp, usblegsup | GRUB_EHCI_OS_OWNED);
|
||||
/* Ensure PCI register is written */
|
||||
grub_pci_read (pciaddr_eecp);
|
||||
|
||||
/* Wait for finish of ownership change, EHCI specification
|
||||
* doesn't say how long it can take... */
|
||||
maxtime = grub_get_time_ms () + 1000;
|
||||
while ((grub_pci_read (pciaddr_eecp) & GRUB_EHCI_BIOS_OWNED)
|
||||
&& (grub_get_time_ms () < maxtime));
|
||||
if (grub_pci_read (pciaddr_eecp) & GRUB_EHCI_BIOS_OWNED)
|
||||
{
|
||||
grub_dprintf ("ehci",
|
||||
"EHCI grub_ehci_pci_iter: EHCI change ownership timeout");
|
||||
/* Change ownership in "hard way" - reset BIOS ownership */
|
||||
grub_pci_write (pciaddr_eecp, GRUB_EHCI_OS_OWNED);
|
||||
/* Ensure PCI register is written */
|
||||
grub_pci_read (pciaddr_eecp);
|
||||
}
|
||||
}
|
||||
else if (usblegsup & GRUB_EHCI_OS_OWNED)
|
||||
/* XXX: What to do in this case - nothing ? Can it happen ? */
|
||||
grub_dprintf ("ehci", "EHCI grub_ehci_pci_iter: EHCI owned by: OS\n");
|
||||
else
|
||||
{
|
||||
grub_dprintf ("ehci",
|
||||
"EHCI grub_ehci_pci_iter: EHCI owned by: NONE\n");
|
||||
/* XXX: What to do in this case ? Can it happen ?
|
||||
* Is code below correct ? */
|
||||
/* Ownership change - set OS_OWNED bit */
|
||||
grub_pci_write (pciaddr_eecp, GRUB_EHCI_OS_OWNED);
|
||||
/* Ensure PCI register is written */
|
||||
grub_pci_read (pciaddr_eecp);
|
||||
}
|
||||
|
||||
/* Disable SMI, just to be sure. */
|
||||
pciaddr_eecp = grub_pci_make_address (dev, eecp_offset + 4);
|
||||
grub_pci_write (pciaddr_eecp, 0);
|
||||
/* Ensure PCI register is written */
|
||||
grub_pci_read (pciaddr_eecp);
|
||||
}
|
||||
|
||||
grub_dprintf ("ehci", "inithw: EHCI grub_ehci_pci_iter: ownership OK\n");
|
||||
|
||||
grub_ehci_init_device (regs);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
grub_ehci_pci_scan (void)
|
||||
{
|
||||
grub_pci_iterate (grub_ehci_pci_iter, NULL);
|
||||
}
|
||||
@@ -22,13 +22,11 @@
|
||||
#include <grub/usb.h>
|
||||
#include <grub/usbtrans.h>
|
||||
#include <grub/misc.h>
|
||||
#include <grub/pci.h>
|
||||
#include <grub/cpu/pci.h>
|
||||
#include <grub/cpu/io.h>
|
||||
#include <grub/time.h>
|
||||
#include <grub/loader.h>
|
||||
#include <grub/cs5536.h>
|
||||
#include <grub/disk.h>
|
||||
#include <grub/dma.h>
|
||||
#include <grub/cache.h>
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
@@ -38,8 +36,6 @@ GRUB_MOD_LICENSE ("GPLv3+");
|
||||
* - is not supporting interrupt transfers
|
||||
*/
|
||||
|
||||
#define GRUB_EHCI_PCI_SBRN_REG 0x60
|
||||
|
||||
/* Capability registers offsets */
|
||||
enum
|
||||
{
|
||||
@@ -53,7 +49,6 @@ enum
|
||||
#define GRUB_EHCI_EECP_MASK (0xff << 8)
|
||||
#define GRUB_EHCI_EECP_SHIFT 8
|
||||
|
||||
#define GRUB_EHCI_ADDR_MEM_MASK (~0xff)
|
||||
#define GRUB_EHCI_POINTER_MASK (~0x1f)
|
||||
|
||||
/* Capability register SPARAMS bits */
|
||||
@@ -84,13 +79,6 @@ enum
|
||||
|
||||
#define GRUB_EHCI_QH_EMPTY 1
|
||||
|
||||
/* USBLEGSUP bits and related OS OWNED byte offset */
|
||||
enum
|
||||
{
|
||||
GRUB_EHCI_BIOS_OWNED = (1 << 16),
|
||||
GRUB_EHCI_OS_OWNED = (1 << 24)
|
||||
};
|
||||
|
||||
/* Operational registers offsets */
|
||||
enum
|
||||
{
|
||||
@@ -337,6 +325,21 @@ struct grub_ehci
|
||||
|
||||
static struct grub_ehci *ehci;
|
||||
|
||||
static void
|
||||
sync_all_caches (struct grub_ehci *e)
|
||||
{
|
||||
if (!e)
|
||||
return;
|
||||
if (e->td_virt)
|
||||
grub_arch_sync_dma_caches (e->td_virt, sizeof (struct grub_ehci_td) *
|
||||
GRUB_EHCI_N_TD);
|
||||
if (e->qh_virt)
|
||||
grub_arch_sync_dma_caches (e->qh_virt, sizeof (struct grub_ehci_qh) *
|
||||
GRUB_EHCI_N_QH);
|
||||
if (e->framelist_virt)
|
||||
grub_arch_sync_dma_caches (e->framelist_virt, 4096);
|
||||
}
|
||||
|
||||
/* EHCC registers access functions */
|
||||
static inline grub_uint32_t
|
||||
grub_ehci_ehcc_read32 (struct grub_ehci *e, grub_uint32_t addr)
|
||||
@@ -437,9 +440,12 @@ grub_ehci_reset (struct grub_ehci *e)
|
||||
{
|
||||
grub_uint64_t maxtime;
|
||||
|
||||
sync_all_caches (e);
|
||||
|
||||
grub_dprintf ("ehci", "reset\n");
|
||||
|
||||
grub_ehci_oper_write32 (e, GRUB_EHCI_COMMAND,
|
||||
GRUB_EHCI_CMD_HC_RESET
|
||||
| grub_ehci_oper_read32 (e, GRUB_EHCI_COMMAND));
|
||||
GRUB_EHCI_CMD_HC_RESET);
|
||||
/* Ensure command is written */
|
||||
grub_ehci_oper_read32 (e, GRUB_EHCI_COMMAND);
|
||||
/* XXX: How long time could take reset of HC ? */
|
||||
@@ -455,116 +461,24 @@ grub_ehci_reset (struct grub_ehci *e)
|
||||
}
|
||||
|
||||
/* PCI iteration function... */
|
||||
static int
|
||||
grub_ehci_pci_iter (grub_pci_device_t dev, grub_pci_id_t pciid,
|
||||
void *data __attribute__ ((unused)))
|
||||
void
|
||||
grub_ehci_init_device (volatile void *regs)
|
||||
{
|
||||
grub_uint8_t release;
|
||||
grub_uint32_t class_code;
|
||||
grub_uint32_t interf;
|
||||
grub_uint32_t subclass;
|
||||
grub_uint32_t class;
|
||||
grub_uint32_t base, base_h;
|
||||
struct grub_ehci *e;
|
||||
grub_uint32_t eecp_offset;
|
||||
grub_uint32_t fp;
|
||||
int i;
|
||||
grub_uint32_t usblegsup = 0;
|
||||
grub_uint64_t maxtime;
|
||||
grub_uint32_t n_ports;
|
||||
grub_uint8_t caplen;
|
||||
|
||||
grub_dprintf ("ehci", "EHCI grub_ehci_pci_iter: begin\n");
|
||||
|
||||
if (pciid == GRUB_CS5536_PCIID)
|
||||
{
|
||||
grub_uint64_t basereg;
|
||||
|
||||
basereg = grub_cs5536_read_msr (dev, GRUB_CS5536_MSR_USB_EHCI_BASE);
|
||||
if (!(basereg & GRUB_CS5536_MSR_USB_BASE_MEMORY_ENABLE))
|
||||
{
|
||||
/* Shouldn't happen. */
|
||||
grub_dprintf ("ehci", "No EHCI address is assigned\n");
|
||||
return 0;
|
||||
}
|
||||
base = (basereg & GRUB_CS5536_MSR_USB_BASE_ADDR_MASK);
|
||||
basereg |= GRUB_CS5536_MSR_USB_BASE_BUS_MASTER;
|
||||
basereg &= ~GRUB_CS5536_MSR_USB_BASE_PME_ENABLED;
|
||||
basereg &= ~GRUB_CS5536_MSR_USB_BASE_PME_STATUS;
|
||||
basereg &= ~GRUB_CS5536_MSR_USB_BASE_SMI_ENABLE;
|
||||
grub_cs5536_write_msr (dev, GRUB_CS5536_MSR_USB_EHCI_BASE, basereg);
|
||||
}
|
||||
else
|
||||
{
|
||||
grub_pci_address_t addr;
|
||||
addr = grub_pci_make_address (dev, GRUB_PCI_REG_CLASS);
|
||||
class_code = grub_pci_read (addr) >> 8;
|
||||
interf = class_code & 0xFF;
|
||||
subclass = (class_code >> 8) & 0xFF;
|
||||
class = class_code >> 16;
|
||||
|
||||
/* If this is not an EHCI controller, just return. */
|
||||
if (class != 0x0c || subclass != 0x03 || interf != 0x20)
|
||||
return 0;
|
||||
|
||||
grub_dprintf ("ehci", "EHCI grub_ehci_pci_iter: class OK\n");
|
||||
|
||||
/* Check Serial Bus Release Number */
|
||||
addr = grub_pci_make_address (dev, GRUB_EHCI_PCI_SBRN_REG);
|
||||
release = grub_pci_read_byte (addr);
|
||||
if (release != 0x20)
|
||||
{
|
||||
grub_dprintf ("ehci", "EHCI grub_ehci_pci_iter: Wrong SBRN: %0x\n",
|
||||
release);
|
||||
return 0;
|
||||
}
|
||||
grub_dprintf ("ehci", "EHCI grub_ehci_pci_iter: bus rev. num. OK\n");
|
||||
|
||||
/* Determine EHCI EHCC registers base address. */
|
||||
addr = grub_pci_make_address (dev, GRUB_PCI_REG_ADDRESS_REG0);
|
||||
base = grub_pci_read (addr);
|
||||
addr = grub_pci_make_address (dev, GRUB_PCI_REG_ADDRESS_REG1);
|
||||
base_h = grub_pci_read (addr);
|
||||
/* Stop if registers are mapped above 4G - GRUB does not currently
|
||||
* work with registers mapped above 4G */
|
||||
if (((base & GRUB_PCI_ADDR_MEM_TYPE_MASK) != GRUB_PCI_ADDR_MEM_TYPE_32)
|
||||
&& (base_h != 0))
|
||||
{
|
||||
grub_dprintf ("ehci",
|
||||
"EHCI grub_ehci_pci_iter: registers above 4G are not supported\n");
|
||||
return 0;
|
||||
}
|
||||
base &= GRUB_PCI_ADDR_MEM_MASK;
|
||||
if (!base)
|
||||
{
|
||||
grub_dprintf ("ehci",
|
||||
"EHCI: EHCI is not mapped\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Set bus master - needed for coreboot, VMware, broken BIOSes etc. */
|
||||
addr = grub_pci_make_address (dev, GRUB_PCI_REG_COMMAND);
|
||||
grub_pci_write_word(addr,
|
||||
GRUB_PCI_COMMAND_MEM_ENABLED
|
||||
| GRUB_PCI_COMMAND_BUS_MASTER
|
||||
| grub_pci_read_word(addr));
|
||||
|
||||
grub_dprintf ("ehci", "EHCI grub_ehci_pci_iter: 32-bit EHCI OK\n");
|
||||
}
|
||||
|
||||
/* Allocate memory for the controller and fill basic values. */
|
||||
e = grub_zalloc (sizeof (*e));
|
||||
if (!e)
|
||||
return 1;
|
||||
return;
|
||||
e->framelist_chunk = NULL;
|
||||
e->td_chunk = NULL;
|
||||
e->qh_chunk = NULL;
|
||||
e->iobase_ehcc = grub_pci_device_map_range (dev,
|
||||
(base & GRUB_EHCI_ADDR_MEM_MASK),
|
||||
0x100);
|
||||
e->iobase_ehcc = regs;
|
||||
|
||||
grub_dprintf ("ehci", "EHCI grub_ehci_pci_iter: iobase of EHCC: %08x\n",
|
||||
(base & GRUB_EHCI_ADDR_MEM_MASK));
|
||||
grub_dprintf ("ehci", "EHCI grub_ehci_pci_iter: CAPLEN: %02x\n",
|
||||
grub_ehci_ehcc_read8 (e, GRUB_EHCI_EHCC_CAPLEN));
|
||||
grub_dprintf ("ehci", "EHCI grub_ehci_pci_iter: VERSION: %04x\n",
|
||||
@@ -580,7 +494,7 @@ grub_ehci_pci_iter (grub_pci_device_t dev, grub_pci_id_t pciid,
|
||||
if (caplen & (sizeof (grub_uint32_t) - 1))
|
||||
{
|
||||
grub_dprintf ("ehci", "Unaligned caplen\n");
|
||||
return 0;
|
||||
return;
|
||||
}
|
||||
e->iobase = ((volatile grub_uint32_t *) e->iobase_ehcc
|
||||
+ (caplen / sizeof (grub_uint32_t)));
|
||||
@@ -591,7 +505,7 @@ grub_ehci_pci_iter (grub_pci_device_t dev, grub_pci_id_t pciid,
|
||||
|
||||
grub_dprintf ("ehci",
|
||||
"EHCI grub_ehci_pci_iter: iobase of oper. regs: %08x\n",
|
||||
(base & GRUB_EHCI_ADDR_MEM_MASK) + caplen);
|
||||
(grub_addr_t) e->iobase_ehcc + caplen);
|
||||
grub_dprintf ("ehci", "EHCI grub_ehci_pci_iter: COMMAND: %08x\n",
|
||||
grub_ehci_oper_read32 (e, GRUB_EHCI_COMMAND));
|
||||
grub_dprintf ("ehci", "EHCI grub_ehci_pci_iter: STATUS: %08x\n",
|
||||
@@ -607,10 +521,6 @@ grub_ehci_pci_iter (grub_pci_device_t dev, grub_pci_id_t pciid,
|
||||
grub_dprintf ("ehci", "EHCI grub_ehci_pci_iter: CONFIG_FLAG: %08x\n",
|
||||
grub_ehci_oper_read32 (e, GRUB_EHCI_CONFIG_FLAG));
|
||||
|
||||
/* Is there EECP ? */
|
||||
eecp_offset = (grub_ehci_ehcc_read32 (e, GRUB_EHCI_EHCC_CPARAMS)
|
||||
& GRUB_EHCI_EECP_MASK) >> GRUB_EHCI_EECP_SHIFT;
|
||||
|
||||
/* Check format of data structures requested by EHCI */
|
||||
/* XXX: In fact it is not used at any place, it is prepared for future
|
||||
* This implementation uses 32-bits pointers only */
|
||||
@@ -714,65 +624,6 @@ grub_ehci_pci_iter (grub_pci_device_t dev, grub_pci_id_t pciid,
|
||||
|
||||
grub_dprintf ("ehci", "EHCI grub_ehci_pci_iter: QH/TD init. OK\n");
|
||||
|
||||
/* Determine and change ownership. */
|
||||
/* EECP offset valid in HCCPARAMS */
|
||||
/* Ownership can be changed via EECP only */
|
||||
if (pciid != GRUB_CS5536_PCIID && eecp_offset >= 0x40)
|
||||
{
|
||||
grub_pci_address_t pciaddr_eecp;
|
||||
pciaddr_eecp = grub_pci_make_address (dev, eecp_offset);
|
||||
|
||||
usblegsup = grub_pci_read (pciaddr_eecp);
|
||||
if (usblegsup & GRUB_EHCI_BIOS_OWNED)
|
||||
{
|
||||
grub_boot_time ("Taking ownership of EHCI controller");
|
||||
grub_dprintf ("ehci",
|
||||
"EHCI grub_ehci_pci_iter: EHCI owned by: BIOS\n");
|
||||
/* Ownership change - set OS_OWNED bit */
|
||||
grub_pci_write (pciaddr_eecp, usblegsup | GRUB_EHCI_OS_OWNED);
|
||||
/* Ensure PCI register is written */
|
||||
grub_pci_read (pciaddr_eecp);
|
||||
|
||||
/* Wait for finish of ownership change, EHCI specification
|
||||
* doesn't say how long it can take... */
|
||||
maxtime = grub_get_time_ms () + 1000;
|
||||
while ((grub_pci_read (pciaddr_eecp) & GRUB_EHCI_BIOS_OWNED)
|
||||
&& (grub_get_time_ms () < maxtime));
|
||||
if (grub_pci_read (pciaddr_eecp) & GRUB_EHCI_BIOS_OWNED)
|
||||
{
|
||||
grub_dprintf ("ehci",
|
||||
"EHCI grub_ehci_pci_iter: EHCI change ownership timeout");
|
||||
/* Change ownership in "hard way" - reset BIOS ownership */
|
||||
grub_pci_write (pciaddr_eecp, GRUB_EHCI_OS_OWNED);
|
||||
/* Ensure PCI register is written */
|
||||
grub_pci_read (pciaddr_eecp);
|
||||
}
|
||||
}
|
||||
else if (usblegsup & GRUB_EHCI_OS_OWNED)
|
||||
/* XXX: What to do in this case - nothing ? Can it happen ? */
|
||||
grub_dprintf ("ehci", "EHCI grub_ehci_pci_iter: EHCI owned by: OS\n");
|
||||
else
|
||||
{
|
||||
grub_dprintf ("ehci",
|
||||
"EHCI grub_ehci_pci_iter: EHCI owned by: NONE\n");
|
||||
/* XXX: What to do in this case ? Can it happen ?
|
||||
* Is code below correct ? */
|
||||
/* Ownership change - set OS_OWNED bit */
|
||||
grub_pci_write (pciaddr_eecp, GRUB_EHCI_OS_OWNED);
|
||||
/* Ensure PCI register is written */
|
||||
grub_pci_read (pciaddr_eecp);
|
||||
}
|
||||
|
||||
/* Disable SMI, just to be sure. */
|
||||
pciaddr_eecp = grub_pci_make_address (dev, eecp_offset + 4);
|
||||
grub_pci_write (pciaddr_eecp, 0);
|
||||
/* Ensure PCI register is written */
|
||||
grub_pci_read (pciaddr_eecp);
|
||||
|
||||
}
|
||||
|
||||
grub_dprintf ("ehci", "inithw: EHCI grub_ehci_pci_iter: ownership OK\n");
|
||||
|
||||
/* Now we can setup EHCI (maybe...) */
|
||||
|
||||
/* Check if EHCI is halted and halt it if not */
|
||||
@@ -840,11 +691,13 @@ grub_ehci_pci_iter (grub_pci_device_t dev, grub_pci_id_t pciid,
|
||||
e->next = ehci;
|
||||
ehci = e;
|
||||
|
||||
sync_all_caches (e);
|
||||
|
||||
grub_dprintf ("ehci", "EHCI grub_ehci_pci_iter: OK at all\n");
|
||||
|
||||
grub_dprintf ("ehci",
|
||||
"EHCI grub_ehci_pci_iter: iobase of oper. regs: %08x\n",
|
||||
(base & GRUB_EHCI_ADDR_MEM_MASK));
|
||||
(grub_addr_t) regs);
|
||||
grub_dprintf ("ehci", "EHCI grub_ehci_pci_iter: COMMAND: %08x\n",
|
||||
grub_ehci_oper_read32 (e, GRUB_EHCI_COMMAND));
|
||||
grub_dprintf ("ehci", "EHCI grub_ehci_pci_iter: STATUS: %08x\n",
|
||||
@@ -860,7 +713,7 @@ grub_ehci_pci_iter (grub_pci_device_t dev, grub_pci_id_t pciid,
|
||||
grub_dprintf ("ehci", "EHCI grub_ehci_pci_iter: CONFIG_FLAG: %08x\n",
|
||||
grub_ehci_oper_read32 (e, GRUB_EHCI_CONFIG_FLAG));
|
||||
|
||||
return 0;
|
||||
return;
|
||||
|
||||
fail:
|
||||
if (e)
|
||||
@@ -874,7 +727,7 @@ fail:
|
||||
}
|
||||
grub_free (e);
|
||||
|
||||
return 0;
|
||||
return;
|
||||
}
|
||||
|
||||
static int
|
||||
@@ -1020,6 +873,7 @@ grub_ehci_find_qh (struct grub_ehci *e, grub_usb_transfer_t transfer)
|
||||
/* Found proper existing (and linked) QH, do setup of QH */
|
||||
grub_dprintf ("ehci", "find_qh: found, QH=%p\n", qh_iter);
|
||||
grub_ehci_setup_qh (qh_iter, transfer);
|
||||
sync_all_caches (e);
|
||||
return qh_iter;
|
||||
}
|
||||
|
||||
@@ -1121,7 +975,7 @@ grub_ehci_free_tds (struct grub_ehci *e, grub_ehci_td_t td,
|
||||
token = grub_le_to_cpu32 (td->token);
|
||||
to_transfer = (token & GRUB_EHCI_TOTAL_MASK) >> GRUB_EHCI_TOTAL_OFF;
|
||||
|
||||
/* Check state of TD - if it did not transfered
|
||||
/* Check state of TD - if it did not transfer
|
||||
* whole data then set last_trans - it should be last executed TD
|
||||
* in case when something went wrong. */
|
||||
if (transfer && (td->size != to_transfer))
|
||||
@@ -1289,16 +1143,28 @@ grub_ehci_setup_transfer (grub_usb_controller_t dev,
|
||||
grub_ehci_td_t td_prev = NULL;
|
||||
int i;
|
||||
struct grub_ehci_transfer_controller_data *cdata;
|
||||
grub_uint32_t status;
|
||||
|
||||
sync_all_caches (e);
|
||||
|
||||
/* Check if EHCI is running and AL is enabled */
|
||||
if ((grub_ehci_oper_read32 (e, GRUB_EHCI_STATUS)
|
||||
& GRUB_EHCI_ST_HC_HALTED) != 0)
|
||||
status = grub_ehci_oper_read32 (e, GRUB_EHCI_STATUS);
|
||||
if ((status & GRUB_EHCI_ST_HC_HALTED) != 0)
|
||||
/* XXX: Fix it: Currently we don't do anything to restart EHCI */
|
||||
return GRUB_USB_ERR_INTERNAL;
|
||||
if ((grub_ehci_oper_read32 (e, GRUB_EHCI_STATUS)
|
||||
{
|
||||
grub_dprintf ("ehci", "setup_transfer: halted, status = 0x%x\n",
|
||||
status);
|
||||
return GRUB_USB_ERR_INTERNAL;
|
||||
}
|
||||
status = grub_ehci_oper_read32 (e, GRUB_EHCI_STATUS);
|
||||
if ((status
|
||||
& (GRUB_EHCI_ST_AS_STATUS | GRUB_EHCI_ST_PS_STATUS)) == 0)
|
||||
/* XXX: Fix it: Currently we don't do anything to restart EHCI */
|
||||
return GRUB_USB_ERR_INTERNAL;
|
||||
{
|
||||
grub_dprintf ("ehci", "setup_transfer: no AS/PS, status = 0x%x\n",
|
||||
status);
|
||||
return GRUB_USB_ERR_INTERNAL;
|
||||
}
|
||||
|
||||
/* Allocate memory for controller transfer data. */
|
||||
cdata = grub_malloc (sizeof (*cdata));
|
||||
@@ -1310,6 +1176,7 @@ grub_ehci_setup_transfer (grub_usb_controller_t dev,
|
||||
cdata->qh_virt = grub_ehci_find_qh (e, transfer);
|
||||
if (!cdata->qh_virt)
|
||||
{
|
||||
grub_dprintf ("ehci", "setup_transfer: no QH\n");
|
||||
grub_free (cdata);
|
||||
return GRUB_USB_ERR_INTERNAL;
|
||||
}
|
||||
@@ -1319,6 +1186,7 @@ grub_ehci_setup_transfer (grub_usb_controller_t dev,
|
||||
cdata->td_alt_virt = grub_ehci_alloc_td (e);
|
||||
if (!cdata->td_alt_virt)
|
||||
{
|
||||
grub_dprintf ("ehci", "setup_transfer: no TDs\n");
|
||||
grub_free (cdata);
|
||||
return GRUB_USB_ERR_INTERNAL;
|
||||
}
|
||||
@@ -1345,6 +1213,7 @@ grub_ehci_setup_transfer (grub_usb_controller_t dev,
|
||||
grub_ehci_free_tds (e, cdata->td_first_virt, NULL, &actual);
|
||||
|
||||
grub_free (cdata);
|
||||
grub_dprintf ("ehci", "setup_transfer: no TD\n");
|
||||
return GRUB_USB_ERR_INTERNAL;
|
||||
}
|
||||
|
||||
@@ -1386,6 +1255,8 @@ grub_ehci_setup_transfer (grub_usb_controller_t dev,
|
||||
* i.e. reset token */
|
||||
cdata->qh_virt->td_overlay.token = grub_cpu_to_le32_compile_time (0);
|
||||
|
||||
sync_all_caches (e);
|
||||
|
||||
/* Finito */
|
||||
transfer->controller_data = cdata;
|
||||
|
||||
@@ -1434,6 +1305,8 @@ grub_ehci_parse_notrun (grub_usb_controller_t dev,
|
||||
grub_ehci_free_td (e, cdata->td_alt_virt);
|
||||
grub_free (cdata);
|
||||
|
||||
sync_all_caches (e);
|
||||
|
||||
/* Additionally, do something with EHCI to make it running (what?) */
|
||||
/* Try enable EHCI and AL */
|
||||
grub_ehci_oper_write32 (e, GRUB_EHCI_COMMAND,
|
||||
@@ -1469,6 +1342,8 @@ grub_ehci_parse_halt (grub_usb_controller_t dev,
|
||||
grub_ehci_free_td (e, cdata->td_alt_virt);
|
||||
grub_free (cdata);
|
||||
|
||||
sync_all_caches (e);
|
||||
|
||||
/* Evaluation of error code - currently we don't have GRUB USB error
|
||||
* codes for some EHCI states, GRUB_USB_ERR_DATA is used for them.
|
||||
* Order of evaluation is critical, specially bubble/stall. */
|
||||
@@ -1502,6 +1377,8 @@ grub_ehci_parse_success (grub_usb_controller_t dev,
|
||||
grub_ehci_free_td (e, cdata->td_alt_virt);
|
||||
grub_free (cdata);
|
||||
|
||||
sync_all_caches (e);
|
||||
|
||||
return GRUB_USB_ERR_NONE;
|
||||
}
|
||||
|
||||
@@ -1515,6 +1392,8 @@ grub_ehci_check_transfer (grub_usb_controller_t dev,
|
||||
transfer->controller_data;
|
||||
grub_uint32_t token, token_ftd;
|
||||
|
||||
sync_all_caches (e);
|
||||
|
||||
grub_dprintf ("ehci",
|
||||
"check_transfer: EHCI STATUS=%08x, cdata=%p, qh=%p\n",
|
||||
grub_ehci_oper_read32 (e, GRUB_EHCI_STATUS),
|
||||
@@ -1581,6 +1460,9 @@ grub_ehci_cancel_transfer (grub_usb_controller_t dev,
|
||||
int i;
|
||||
grub_uint64_t maxtime;
|
||||
grub_uint32_t qh_phys;
|
||||
|
||||
sync_all_caches (e);
|
||||
|
||||
grub_uint32_t interrupt =
|
||||
cdata->qh_virt->ep_cap & GRUB_EHCI_SMASK_MASK;
|
||||
|
||||
@@ -1600,6 +1482,7 @@ grub_ehci_cancel_transfer (grub_usb_controller_t dev,
|
||||
grub_ehci_free_tds (e, cdata->td_first_virt, transfer, &actual);
|
||||
grub_ehci_free_td (e, cdata->td_alt_virt);
|
||||
grub_free (cdata);
|
||||
sync_all_caches (e);
|
||||
grub_dprintf ("ehci", "cancel_transfer: end - EHCI not running\n");
|
||||
return GRUB_USB_ERR_NONE;
|
||||
}
|
||||
@@ -1622,6 +1505,8 @@ grub_ehci_cancel_transfer (grub_usb_controller_t dev,
|
||||
/* Unlink QH from AL */
|
||||
e->qh_virt[i].qh_hptr = cdata->qh_virt->qh_hptr;
|
||||
|
||||
sync_all_caches (e);
|
||||
|
||||
/* If this is an interrupt transfer, we just wait for the periodic
|
||||
* schedule to advance a few times and then assume that the EHCI
|
||||
* controller has read the updated QH. */
|
||||
@@ -1676,6 +1561,8 @@ grub_ehci_cancel_transfer (grub_usb_controller_t dev,
|
||||
|
||||
grub_dprintf ("ehci", "cancel_transfer: end\n");
|
||||
|
||||
sync_all_caches (e);
|
||||
|
||||
return GRUB_USB_ERR_NONE;
|
||||
}
|
||||
|
||||
@@ -1777,11 +1664,6 @@ grub_ehci_detect_dev (grub_usb_controller_t dev, int port, int *changed)
|
||||
|
||||
status = grub_ehci_port_read (e, port);
|
||||
|
||||
grub_dprintf ("ehci", "detect_dev: EHCI STATUS: %08x\n",
|
||||
grub_ehci_oper_read32 (e, GRUB_EHCI_STATUS));
|
||||
grub_dprintf ("ehci", "detect_dev: iobase=%p, port=%d, status=0x%02x\n",
|
||||
e->iobase, port, status);
|
||||
|
||||
/* Connect Status Change bit - it detects change of connection */
|
||||
if (status & GRUB_EHCI_PORT_CONNECT_CH)
|
||||
{
|
||||
@@ -1842,12 +1724,6 @@ grub_ehci_detect_dev (grub_usb_controller_t dev, int port, int *changed)
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
grub_ehci_inithw (void)
|
||||
{
|
||||
grub_pci_iterate (grub_ehci_pci_iter, NULL);
|
||||
}
|
||||
|
||||
static grub_err_t
|
||||
grub_ehci_restore_hw (void)
|
||||
{
|
||||
@@ -1948,7 +1824,7 @@ GRUB_MOD_INIT (ehci)
|
||||
grub_stop_disk_firmware ();
|
||||
|
||||
grub_boot_time ("Initing EHCI hardware");
|
||||
grub_ehci_inithw ();
|
||||
grub_ehci_pci_scan ();
|
||||
grub_boot_time ("Registering EHCI driver");
|
||||
grub_usb_controller_dev_register (&usb_controller);
|
||||
grub_boot_time ("EHCI driver registered");
|
||||
|
||||
@@ -18,12 +18,13 @@
|
||||
*/
|
||||
|
||||
#include <grub/dl.h>
|
||||
#include <grub/pci.h>
|
||||
#include <grub/dma.h>
|
||||
#include <grub/mm.h>
|
||||
#include <grub/misc.h>
|
||||
#include <grub/usb.h>
|
||||
#include <grub/usbtrans.h>
|
||||
#include <grub/time.h>
|
||||
#include <grub/cache.h>
|
||||
|
||||
|
||||
static inline unsigned int
|
||||
@@ -101,6 +102,8 @@ grub_usb_control_msg (grub_usb_device_t dev,
|
||||
data_addr = grub_dma_get_phys (data_chunk);
|
||||
grub_memcpy ((char *) data, data_in, size);
|
||||
|
||||
grub_arch_sync_dma_caches (data, size);
|
||||
|
||||
grub_dprintf ("usb",
|
||||
"control: reqtype=0x%02x req=0x%02x val=0x%02x idx=0x%02x size=%lu\n",
|
||||
reqtype, request, value, index, (unsigned long)size);
|
||||
@@ -161,6 +164,8 @@ grub_usb_control_msg (grub_usb_device_t dev,
|
||||
setupdata->value = value;
|
||||
setupdata->index = index;
|
||||
setupdata->length = size;
|
||||
grub_arch_sync_dma_caches (setupdata, sizeof (*setupdata));
|
||||
|
||||
transfer->transactions[0].size = sizeof (*setupdata);
|
||||
transfer->transactions[0].pid = GRUB_USB_TRANSFER_TYPE_SETUP;
|
||||
transfer->transactions[0].data = setupdata_addr;
|
||||
@@ -202,11 +207,13 @@ grub_usb_control_msg (grub_usb_device_t dev,
|
||||
grub_free (transfer->transactions);
|
||||
|
||||
grub_free (transfer);
|
||||
grub_dma_free (data_chunk);
|
||||
grub_dma_free (setupdata_chunk);
|
||||
|
||||
grub_arch_sync_dma_caches (data, size0);
|
||||
grub_memcpy (data_in, (char *) data, size0);
|
||||
|
||||
grub_dma_free (data_chunk);
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
@@ -236,7 +243,10 @@ grub_usb_bulk_setup_readwrite (grub_usb_device_t dev,
|
||||
data = grub_dma_get_virt (data_chunk);
|
||||
data_addr = grub_dma_get_phys (data_chunk);
|
||||
if (type == GRUB_USB_TRANSFER_TYPE_OUT)
|
||||
grub_memcpy ((char *) data, data_in, size);
|
||||
{
|
||||
grub_memcpy ((char *) data, data_in, size);
|
||||
grub_arch_sync_dma_caches (data, size);
|
||||
}
|
||||
|
||||
/* Create a transfer. */
|
||||
transfer = grub_malloc (sizeof (struct grub_usb_transfer));
|
||||
@@ -306,9 +316,13 @@ grub_usb_bulk_finish_readwrite (grub_usb_transfer_t transfer)
|
||||
dev->toggle[transfer->endpoint] = toggle;
|
||||
|
||||
if (transfer->dir == GRUB_USB_TRANSFER_TYPE_IN)
|
||||
grub_memcpy (transfer->data, (void *)
|
||||
grub_dma_get_virt (transfer->data_chunk),
|
||||
transfer->size + 1);
|
||||
{
|
||||
grub_arch_sync_dma_caches (grub_dma_get_virt (transfer->data_chunk),
|
||||
transfer->size + 1);
|
||||
grub_memcpy (transfer->data, (void *)
|
||||
grub_dma_get_virt (transfer->data_chunk),
|
||||
transfer->size + 1);
|
||||
}
|
||||
|
||||
grub_free (transfer->transactions);
|
||||
grub_dma_free (transfer->data_chunk);
|
||||
|
||||
@@ -593,6 +593,9 @@ grub_cmd_acpi (struct grub_extcmd_context *ctxt, int argc, char **args)
|
||||
if (! table->addr)
|
||||
{
|
||||
free_tables ();
|
||||
grub_free (exclude);
|
||||
grub_free (load_only);
|
||||
grub_free (table);
|
||||
return grub_errno;
|
||||
}
|
||||
table->next = acpi_tables;
|
||||
@@ -632,7 +635,7 @@ grub_cmd_acpi (struct grub_extcmd_context *ctxt, int argc, char **args)
|
||||
grub_size_t size;
|
||||
char *buf;
|
||||
|
||||
file = grub_file_open (args[i]);
|
||||
file = grub_file_open (args[i], GRUB_FILE_TYPE_ACPI_TABLE);
|
||||
if (! file)
|
||||
{
|
||||
free_tables ();
|
||||
@@ -758,10 +761,10 @@ grub_cmd_acpi (struct grub_extcmd_context *ctxt, int argc, char **args)
|
||||
struct grub_efi_guid acpi = GRUB_EFI_ACPI_TABLE_GUID;
|
||||
struct grub_efi_guid acpi20 = GRUB_EFI_ACPI_20_TABLE_GUID;
|
||||
|
||||
grub_efi_system_table->boot_services->install_configuration_table
|
||||
(&acpi20, grub_acpi_get_rsdpv2 ());
|
||||
grub_efi_system_table->boot_services->install_configuration_table
|
||||
(&acpi, grub_acpi_get_rsdpv1 ());
|
||||
efi_call_2 (grub_efi_system_table->boot_services->install_configuration_table,
|
||||
&acpi20, grub_acpi_get_rsdpv2 ());
|
||||
efi_call_2 (grub_efi_system_table->boot_services->install_configuration_table,
|
||||
&acpi, grub_acpi_get_rsdpv1 ());
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@@ -121,8 +121,8 @@ grub_cmd_blocklist (grub_command_t cmd __attribute__ ((unused)),
|
||||
if (argc < 1)
|
||||
return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected"));
|
||||
|
||||
grub_file_filter_disable_compression ();
|
||||
file = grub_file_open (args[0]);
|
||||
file = grub_file_open (args[0], GRUB_FILE_TYPE_PRINT_BLOCKLIST
|
||||
| GRUB_FILE_TYPE_NO_DECOMPRESS);
|
||||
if (! file)
|
||||
return grub_errno;
|
||||
|
||||
|
||||
@@ -56,7 +56,7 @@ grub_cmd_cat (grub_extcmd_context_t ctxt, int argc, char **args)
|
||||
if (argc != 1)
|
||||
return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected"));
|
||||
|
||||
file = grub_file_open (args[0]);
|
||||
file = grub_file_open (args[0], GRUB_FILE_TYPE_CAT);
|
||||
if (! file)
|
||||
return grub_errno;
|
||||
|
||||
@@ -140,10 +140,13 @@ grub_cmd_cat (grub_extcmd_context_t ctxt, int argc, char **args)
|
||||
grub_setcolorstate (GRUB_TERM_COLOR_STANDARD);
|
||||
}
|
||||
|
||||
grub_setcolorstate (GRUB_TERM_COLOR_HIGHLIGHT);
|
||||
for (j = 0; j < utcount; j++)
|
||||
grub_printf ("<%x>", (unsigned int) utbuf[j]);
|
||||
grub_setcolorstate (GRUB_TERM_COLOR_STANDARD);
|
||||
if (utcount)
|
||||
{
|
||||
grub_setcolorstate (GRUB_TERM_COLOR_HIGHLIGHT);
|
||||
for (j = 0; j < utcount; j++)
|
||||
grub_printf ("<%x>", (unsigned int) utbuf[j]);
|
||||
grub_setcolorstate (GRUB_TERM_COLOR_STANDARD);
|
||||
}
|
||||
|
||||
grub_xputs ("\n");
|
||||
grub_refresh ();
|
||||
|
||||
@@ -45,8 +45,8 @@ grub_cmd_cmp (grub_command_t cmd __attribute__ ((unused)),
|
||||
grub_printf_ (N_("Compare file `%s' with `%s':\n"), args[0],
|
||||
args[1]);
|
||||
|
||||
file1 = grub_file_open (args[0]);
|
||||
file2 = grub_file_open (args[1]);
|
||||
file1 = grub_file_open (args[0], GRUB_FILE_TYPE_CMP);
|
||||
file2 = grub_file_open (args[1], GRUB_FILE_TYPE_CMP);
|
||||
if (! file1 || ! file2)
|
||||
goto cleanup;
|
||||
|
||||
|
||||
@@ -169,7 +169,7 @@ grub_cmd_loadbios (grub_command_t cmd __attribute__ ((unused)),
|
||||
|
||||
if (argc > 1)
|
||||
{
|
||||
file = grub_file_open (argv[1]);
|
||||
file = grub_file_open (argv[1], GRUB_FILE_TYPE_VBE_DUMP);
|
||||
if (! file)
|
||||
return grub_errno;
|
||||
|
||||
@@ -183,7 +183,7 @@ grub_cmd_loadbios (grub_command_t cmd __attribute__ ((unused)),
|
||||
return grub_errno;
|
||||
}
|
||||
|
||||
file = grub_file_open (argv[0]);
|
||||
file = grub_file_open (argv[0], GRUB_FILE_TYPE_VBE_DUMP);
|
||||
if (! file)
|
||||
return grub_errno;
|
||||
|
||||
|
||||
@@ -163,7 +163,7 @@ grub_cmd_file (grub_extcmd_context_t ctxt, int argc, char **args)
|
||||
if (type == -1)
|
||||
return grub_error (GRUB_ERR_BAD_ARGUMENT, "no type specified");
|
||||
|
||||
file = grub_file_open (args[0]);
|
||||
file = grub_file_open (args[0], GRUB_FILE_TYPE_XNU_KERNEL);
|
||||
if (!file)
|
||||
return grub_errno;
|
||||
switch (type)
|
||||
@@ -546,7 +546,8 @@ grub_cmd_file (grub_extcmd_context_t ctxt, int argc, char **args)
|
||||
case IS_XNU64:
|
||||
case IS_XNU32:
|
||||
{
|
||||
macho = grub_macho_open (args[0], (type == IS_XNU64));
|
||||
macho = grub_macho_open (args[0], GRUB_FILE_TYPE_XNU_KERNEL,
|
||||
(type == IS_XNU64));
|
||||
if (!macho)
|
||||
break;
|
||||
/* FIXME: more checks? */
|
||||
|
||||
@@ -113,7 +113,7 @@ check_list (const gcry_md_spec_t *hash, const char *hashfilename,
|
||||
if (hash->mdlen > GRUB_CRYPTO_MAX_MDLEN)
|
||||
return grub_error (GRUB_ERR_BUG, "mdlen is too long");
|
||||
|
||||
hashlist = grub_file_open (hashfilename);
|
||||
hashlist = grub_file_open (hashfilename, GRUB_FILE_TYPE_HASHLIST);
|
||||
if (!hashlist)
|
||||
return grub_errno;
|
||||
|
||||
@@ -141,17 +141,15 @@ check_list (const gcry_md_spec_t *hash, const char *hashfilename,
|
||||
filename = grub_xasprintf ("%s/%s", prefix, p);
|
||||
if (!filename)
|
||||
return grub_errno;
|
||||
if (!uncompress)
|
||||
grub_file_filter_disable_compression ();
|
||||
file = grub_file_open (filename);
|
||||
file = grub_file_open (filename, GRUB_FILE_TYPE_TO_HASH
|
||||
| (!uncompress ? GRUB_FILE_TYPE_NO_DECOMPRESS
|
||||
: 0));
|
||||
grub_free (filename);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!uncompress)
|
||||
grub_file_filter_disable_compression ();
|
||||
file = grub_file_open (p);
|
||||
}
|
||||
file = grub_file_open (p, GRUB_FILE_TYPE_TO_HASH
|
||||
| (!uncompress ? GRUB_FILE_TYPE_NO_DECOMPRESS
|
||||
: 0));
|
||||
if (!file)
|
||||
{
|
||||
grub_file_close (hashlist);
|
||||
@@ -242,9 +240,9 @@ grub_cmd_hashsum (struct grub_extcmd_context *ctxt,
|
||||
grub_file_t file;
|
||||
grub_err_t err;
|
||||
unsigned j;
|
||||
if (!uncompress)
|
||||
grub_file_filter_disable_compression ();
|
||||
file = grub_file_open (args[i]);
|
||||
file = grub_file_open (args[i], GRUB_FILE_TYPE_TO_HASH
|
||||
| (!uncompress ? GRUB_FILE_TYPE_NO_DECOMPRESS
|
||||
: 0));
|
||||
if (!file)
|
||||
{
|
||||
if (!keep)
|
||||
|
||||
@@ -328,6 +328,7 @@ grub_cmd_hdparm (grub_extcmd_context_t ctxt, int argc, char **args)
|
||||
ata = ((struct grub_scsi *) disk->data)->data;
|
||||
break;
|
||||
}
|
||||
/* FALLTHROUGH */
|
||||
default:
|
||||
grub_disk_close (disk);
|
||||
return grub_error (GRUB_ERR_IO, "not an ATA device");
|
||||
|
||||
@@ -90,7 +90,7 @@ grub_cmd_hexdump (grub_extcmd_context_t ctxt, int argc, char **args)
|
||||
{
|
||||
grub_file_t file;
|
||||
|
||||
file = grub_file_open (args[0]);
|
||||
file = grub_file_open (args[0], GRUB_FILE_TYPE_HEXCAT);
|
||||
if (! file)
|
||||
return 0;
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ static grub_err_t
|
||||
grub_cmd_cmostest (struct grub_command *cmd __attribute__ ((unused)),
|
||||
int argc, char *argv[])
|
||||
{
|
||||
int byte, bit;
|
||||
int byte = 0, bit = 0;
|
||||
grub_err_t err;
|
||||
grub_uint8_t value;
|
||||
|
||||
@@ -67,7 +67,7 @@ static grub_err_t
|
||||
grub_cmd_cmosclean (struct grub_command *cmd __attribute__ ((unused)),
|
||||
int argc, char *argv[])
|
||||
{
|
||||
int byte, bit;
|
||||
int byte = 0, bit = 0;
|
||||
grub_err_t err;
|
||||
grub_uint8_t value;
|
||||
|
||||
@@ -85,7 +85,7 @@ static grub_err_t
|
||||
grub_cmd_cmosset (struct grub_command *cmd __attribute__ ((unused)),
|
||||
int argc, char *argv[])
|
||||
{
|
||||
int byte, bit;
|
||||
int byte = 0, bit = 0;
|
||||
grub_err_t err;
|
||||
grub_uint8_t value;
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
#include <grub/misc.h>
|
||||
#include <grub/command.h>
|
||||
#include <grub/i18n.h>
|
||||
#include <grub/i386/coreboot/lbio.h>
|
||||
#include <grub/coreboot/lbio.h>
|
||||
#include <grub/i386/tsc.h>
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
#include <grub/misc.h>
|
||||
#include <grub/command.h>
|
||||
#include <grub/i18n.h>
|
||||
#include <grub/i386/coreboot/lbio.h>
|
||||
#include <grub/coreboot/lbio.h>
|
||||
#include <grub/i386/tsc.h>
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
79
grub-core/commands/i386/nthibr.c
Normal file
79
grub-core/commands/i386/nthibr.c
Normal file
@@ -0,0 +1,79 @@
|
||||
/* nthibr.c - tests whether an MS Windows system partition is hibernated */
|
||||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 2013 Peter Lustig
|
||||
* Copyright (C) 2013 Free Software Foundation, Inc.
|
||||
*
|
||||
* GRUB is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* GRUB is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <grub/types.h>
|
||||
#include <grub/mm.h>
|
||||
#include <grub/file.h>
|
||||
#include <grub/misc.h>
|
||||
#include <grub/dl.h>
|
||||
#include <grub/command.h>
|
||||
#include <grub/err.h>
|
||||
#include <grub/i18n.h>
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
static grub_err_t
|
||||
grub_cmd_nthibr (grub_command_t cmd __attribute__ ((unused)),
|
||||
int argc, char **args)
|
||||
{
|
||||
grub_uint8_t hibr_file_magic[4];
|
||||
grub_file_t hibr_file = 0;
|
||||
|
||||
if (argc != 1)
|
||||
return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("one argument expected"));
|
||||
|
||||
hibr_file = grub_file_open (args[0], GRUB_FILE_TYPE_FILE_ID);
|
||||
if (!hibr_file)
|
||||
return grub_errno;
|
||||
|
||||
/* Try to read magic number of 'hiberfil.sys' */
|
||||
if (grub_file_read (hibr_file, hibr_file_magic,
|
||||
sizeof (hibr_file_magic))
|
||||
!= (grub_ssize_t) sizeof (hibr_file_magic))
|
||||
{
|
||||
if (!grub_errno)
|
||||
grub_error (GRUB_ERR_TEST_FAILURE, "false");
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if (!(grub_memcmp ("hibr", hibr_file_magic, sizeof (hibr_file_magic)) == 0
|
||||
|| grub_memcmp ("HIBR", hibr_file_magic, sizeof (hibr_file_magic)) == 0))
|
||||
grub_error (GRUB_ERR_TEST_FAILURE, "false");
|
||||
|
||||
exit:
|
||||
grub_file_close (hibr_file);
|
||||
|
||||
return grub_errno;
|
||||
}
|
||||
|
||||
static grub_command_t cmd;
|
||||
|
||||
GRUB_MOD_INIT (check_nt_hiberfil)
|
||||
{
|
||||
cmd = grub_register_command ("check_nt_hiberfil", grub_cmd_nthibr,
|
||||
N_("FILE"),
|
||||
N_("Test whether a hiberfil.sys is "
|
||||
"in hibernated state."));
|
||||
}
|
||||
|
||||
GRUB_MOD_FINI (check_nt_hiberfil)
|
||||
{
|
||||
grub_unregister_command (cmd);
|
||||
}
|
||||
@@ -93,7 +93,7 @@ grub_cmd_play (grub_command_t cmd __attribute__ ((unused)),
|
||||
grub_uint32_t tempo;
|
||||
grub_file_t file;
|
||||
|
||||
file = grub_file_open (args[0]);
|
||||
file = grub_file_open (args[0], GRUB_FILE_TYPE_AUDIO);
|
||||
|
||||
if (! file)
|
||||
return grub_errno;
|
||||
|
||||
@@ -220,7 +220,7 @@ grub_cmd_keymap (struct grub_command *cmd __attribute__ ((unused)),
|
||||
else
|
||||
filename = argv[0];
|
||||
|
||||
file = grub_file_open (filename);
|
||||
file = grub_file_open (filename, GRUB_FILE_TYPE_KEYBOARD_LAYOUT);
|
||||
if (! file)
|
||||
goto fail;
|
||||
|
||||
|
||||
@@ -55,7 +55,7 @@ legacy_file (const char *filename)
|
||||
if (!suffix)
|
||||
return grub_errno;
|
||||
|
||||
file = grub_file_open (filename);
|
||||
file = grub_file_open (filename, GRUB_FILE_TYPE_CONFIG);
|
||||
if (! file)
|
||||
{
|
||||
grub_free (suffix);
|
||||
@@ -253,6 +253,7 @@ grub_cmd_legacy_kernel (struct grub_command *mycmd __attribute__ ((unused)),
|
||||
struct grub_command *cmd;
|
||||
char **cutargs;
|
||||
int cutargc;
|
||||
grub_err_t err = GRUB_ERR_NONE;
|
||||
|
||||
for (i = 0; i < 2; i++)
|
||||
{
|
||||
@@ -314,6 +315,8 @@ grub_cmd_legacy_kernel (struct grub_command *mycmd __attribute__ ((unused)),
|
||||
return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected"));
|
||||
|
||||
cutargs = grub_malloc (sizeof (cutargs[0]) * (argc - 1));
|
||||
if (!cutargs)
|
||||
return grub_errno;
|
||||
cutargc = argc - 1;
|
||||
grub_memcpy (cutargs + 1, args + 2, sizeof (cutargs[0]) * (argc - 2));
|
||||
cutargs[0] = args[0];
|
||||
@@ -333,7 +336,7 @@ grub_cmd_legacy_kernel (struct grub_command *mycmd __attribute__ ((unused)),
|
||||
if (!(cmd->func) (cmd, cutargc, cutargs))
|
||||
{
|
||||
kernel_type = LINUX;
|
||||
return GRUB_ERR_NONE;
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
grub_errno = GRUB_ERR_NONE;
|
||||
@@ -348,7 +351,7 @@ grub_cmd_legacy_kernel (struct grub_command *mycmd __attribute__ ((unused)),
|
||||
if (!(cmd->func) (cmd, argc, args))
|
||||
{
|
||||
kernel_type = MULTIBOOT;
|
||||
return GRUB_ERR_NONE;
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
grub_errno = GRUB_ERR_NONE;
|
||||
@@ -413,7 +416,7 @@ grub_cmd_legacy_kernel (struct grub_command *mycmd __attribute__ ((unused)),
|
||||
if (!(cmd->func) (cmd, cutargc, cutargs))
|
||||
{
|
||||
kernel_type = KFREEBSD;
|
||||
return GRUB_ERR_NONE;
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
grub_errno = GRUB_ERR_NONE;
|
||||
@@ -422,6 +425,8 @@ grub_cmd_legacy_kernel (struct grub_command *mycmd __attribute__ ((unused)),
|
||||
char **bsdargs;
|
||||
int bsdargc;
|
||||
char bsddevname[sizeof ("wdXXXXXXXXXXXXY")];
|
||||
int found = 0;
|
||||
|
||||
if (bsd_device == -1)
|
||||
{
|
||||
bsdargs = cutargs;
|
||||
@@ -432,6 +437,11 @@ grub_cmd_legacy_kernel (struct grub_command *mycmd __attribute__ ((unused)),
|
||||
char rbuf[3] = "-r";
|
||||
bsdargc = cutargc + 2;
|
||||
bsdargs = grub_malloc (sizeof (bsdargs[0]) * bsdargc);
|
||||
if (!bsdargs)
|
||||
{
|
||||
err = grub_errno;
|
||||
goto out;
|
||||
}
|
||||
grub_memcpy (bsdargs, args, argc * sizeof (bsdargs[0]));
|
||||
bsdargs[argc] = rbuf;
|
||||
bsdargs[argc + 1] = bsddevname;
|
||||
@@ -447,7 +457,8 @@ grub_cmd_legacy_kernel (struct grub_command *mycmd __attribute__ ((unused)),
|
||||
if (!(cmd->func) (cmd, bsdargc, bsdargs))
|
||||
{
|
||||
kernel_type = KNETBSD;
|
||||
return GRUB_ERR_NONE;
|
||||
found = 1;
|
||||
goto free_bsdargs;
|
||||
}
|
||||
}
|
||||
grub_errno = GRUB_ERR_NONE;
|
||||
@@ -460,20 +471,28 @@ grub_cmd_legacy_kernel (struct grub_command *mycmd __attribute__ ((unused)),
|
||||
if (!(cmd->func) (cmd, bsdargc, bsdargs))
|
||||
{
|
||||
kernel_type = KOPENBSD;
|
||||
return GRUB_ERR_NONE;
|
||||
found = 1;
|
||||
goto free_bsdargs;
|
||||
}
|
||||
}
|
||||
grub_errno = GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
free_bsdargs:
|
||||
if (bsdargs != cutargs)
|
||||
grub_free (bsdargs);
|
||||
if (found)
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
}
|
||||
while (0);
|
||||
|
||||
return grub_error (GRUB_ERR_BAD_OS, "couldn't load file %s",
|
||||
args[0]);
|
||||
err = grub_error (GRUB_ERR_BAD_OS, "couldn't load file %s",
|
||||
args[0]);
|
||||
out:
|
||||
grub_free (cutargs);
|
||||
return err;
|
||||
}
|
||||
|
||||
static grub_err_t
|
||||
@@ -498,7 +517,7 @@ grub_cmd_legacy_initrd (struct grub_command *mycmd __attribute__ ((unused)),
|
||||
#endif
|
||||
);
|
||||
|
||||
return cmd->func (cmd, argc, args);
|
||||
return cmd->func (cmd, argc ? 1 : 0, args);
|
||||
}
|
||||
if (kernel_type == MULTIBOOT)
|
||||
{
|
||||
@@ -534,15 +553,17 @@ grub_cmd_legacy_initrdnounzip (struct grub_command *mycmd __attribute__ ((unused
|
||||
char **newargs;
|
||||
grub_err_t err;
|
||||
char nounzipbuf[10] = "--nounzip";
|
||||
|
||||
cmd = grub_command_find ("module");
|
||||
if (!cmd)
|
||||
return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("can't find command `%s'"),
|
||||
"module");
|
||||
|
||||
newargs = grub_malloc ((argc + 1) * sizeof (newargs[0]));
|
||||
if (!newargs)
|
||||
return grub_errno;
|
||||
grub_memcpy (newargs + 1, args, argc * sizeof (newargs[0]));
|
||||
newargs[0] = nounzipbuf;
|
||||
cmd = grub_command_find ("module");
|
||||
if (!cmd)
|
||||
return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("can't find command `%s'"),
|
||||
"module");
|
||||
|
||||
err = cmd->func (cmd, argc + 1, newargs);
|
||||
grub_free (newargs);
|
||||
|
||||
@@ -44,7 +44,8 @@ static const struct grub_arg_option options[] =
|
||||
PUBKEY filter (that insists upon properly signed files) as well. PUBKEY
|
||||
filter is restored before the function returns. */
|
||||
static grub_file_t
|
||||
open_envblk_file (char *filename, int untrusted)
|
||||
open_envblk_file (char *filename,
|
||||
enum grub_file_type type)
|
||||
{
|
||||
grub_file_t file;
|
||||
char *buf = 0;
|
||||
@@ -72,13 +73,7 @@ open_envblk_file (char *filename, int untrusted)
|
||||
grub_strcpy (filename + len + 1, GRUB_ENVBLK_DEFCFG);
|
||||
}
|
||||
|
||||
/* The filters that are disabled will be re-enabled by the call to
|
||||
grub_file_open() after this particular file is opened. */
|
||||
grub_file_filter_disable_compression ();
|
||||
if (untrusted)
|
||||
grub_file_filter_disable_pubkey ();
|
||||
|
||||
file = grub_file_open (filename);
|
||||
file = grub_file_open (filename, type);
|
||||
|
||||
grub_free (buf);
|
||||
return file;
|
||||
@@ -171,7 +166,10 @@ grub_cmd_load_env (grub_extcmd_context_t ctxt, int argc, char **args)
|
||||
whitelist.list = args;
|
||||
|
||||
/* state[0] is the -f flag; state[1] is the --skip-sig flag */
|
||||
file = open_envblk_file ((state[0].set) ? state[0].arg : 0, state[1].set);
|
||||
file = open_envblk_file ((state[0].set) ? state[0].arg : 0,
|
||||
GRUB_FILE_TYPE_LOADENV
|
||||
| (state[1].set
|
||||
? GRUB_FILE_TYPE_SKIP_SIGNATURE : 0));
|
||||
if (! file)
|
||||
return grub_errno;
|
||||
|
||||
@@ -206,7 +204,10 @@ grub_cmd_list_env (grub_extcmd_context_t ctxt,
|
||||
grub_file_t file;
|
||||
grub_envblk_t envblk;
|
||||
|
||||
file = open_envblk_file ((state[0].set) ? state[0].arg : 0, 0);
|
||||
file = open_envblk_file ((state[0].set) ? state[0].arg : 0,
|
||||
GRUB_FILE_TYPE_LOADENV
|
||||
| (state[1].set
|
||||
? GRUB_FILE_TYPE_SKIP_SIGNATURE : 0));
|
||||
if (! file)
|
||||
return grub_errno;
|
||||
|
||||
@@ -390,7 +391,8 @@ grub_cmd_save_env (grub_extcmd_context_t ctxt, int argc, char **args)
|
||||
return grub_error (GRUB_ERR_BAD_ARGUMENT, "no variable is specified");
|
||||
|
||||
file = open_envblk_file ((state[0].set) ? state[0].arg : 0,
|
||||
1 /* allow untrusted */);
|
||||
GRUB_FILE_TYPE_SAVEENV
|
||||
| GRUB_FILE_TYPE_SKIP_SIGNATURE);
|
||||
if (! file)
|
||||
return grub_errno;
|
||||
|
||||
|
||||
@@ -129,8 +129,8 @@ print_files_long (const char *filename, const struct grub_dirhook_info *info,
|
||||
|
||||
/* XXX: For ext2fs symlinks are detected as files while they
|
||||
should be reported as directories. */
|
||||
grub_file_filter_disable_compression ();
|
||||
file = grub_file_open (pathname);
|
||||
file = grub_file_open (pathname, GRUB_FILE_TYPE_GET_SIZE
|
||||
| GRUB_FILE_TYPE_NO_DECOMPRESS);
|
||||
if (! file)
|
||||
{
|
||||
grub_errno = 0;
|
||||
@@ -225,8 +225,8 @@ grub_ls_list_files (char *dirname, int longlist, int all, int human)
|
||||
struct grub_dirhook_info info;
|
||||
grub_errno = 0;
|
||||
|
||||
grub_file_filter_disable_compression ();
|
||||
file = grub_file_open (dirname);
|
||||
file = grub_file_open (dirname, GRUB_FILE_TYPE_GET_SIZE
|
||||
| GRUB_FILE_TYPE_NO_DECOMPRESS);
|
||||
if (! file)
|
||||
goto fail;
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ grub_mini_cmd_cat (struct grub_command *cmd __attribute__ ((unused)),
|
||||
if (argc < 1)
|
||||
return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected"));
|
||||
|
||||
file = grub_file_open (argv[0]);
|
||||
file = grub_file_open (argv[0], GRUB_FILE_TYPE_CAT);
|
||||
if (! file)
|
||||
return grub_errno;
|
||||
|
||||
|
||||
@@ -79,6 +79,7 @@ get_uuid (const char *name, char **uuid, int getnative)
|
||||
case GRUB_DISK_DEVICE_XEN:
|
||||
if (getnative)
|
||||
break;
|
||||
/* FALLTHROUGH */
|
||||
|
||||
/* Virtual disks. */
|
||||
/* GRUB dynamically generated files. */
|
||||
@@ -198,7 +199,10 @@ grub_cmd_nativedisk (grub_command_t cmd __attribute__ ((unused)),
|
||||
return grub_errno;
|
||||
|
||||
if (get_uuid (NULL, &uuid_root, 0))
|
||||
return grub_errno;
|
||||
{
|
||||
grub_free (mods);
|
||||
return grub_errno;
|
||||
}
|
||||
|
||||
prefdev = grub_file_get_device_name (prefix);
|
||||
if (grub_errno)
|
||||
@@ -210,6 +214,8 @@ grub_cmd_nativedisk (grub_command_t cmd __attribute__ ((unused)),
|
||||
if (get_uuid (prefdev, &uuid_prefix, 0))
|
||||
{
|
||||
grub_free (uuid_root);
|
||||
grub_free (prefdev);
|
||||
grub_free (mods);
|
||||
return grub_errno;
|
||||
}
|
||||
|
||||
@@ -236,7 +242,8 @@ grub_cmd_nativedisk (grub_command_t cmd __attribute__ ((unused)),
|
||||
if (! filename)
|
||||
goto fail;
|
||||
|
||||
file = grub_file_open (filename);
|
||||
file = grub_file_open (filename,
|
||||
GRUB_FILE_TYPE_GRUB_MODULE);
|
||||
grub_free (filename);
|
||||
if (! file)
|
||||
goto fail;
|
||||
@@ -289,12 +296,15 @@ grub_cmd_nativedisk (grub_command_t cmd __attribute__ ((unused)),
|
||||
}
|
||||
grub_free (uuid_root);
|
||||
grub_free (uuid_prefix);
|
||||
grub_free (prefdev);
|
||||
grub_free (mods);
|
||||
|
||||
return GRUB_ERR_NONE;
|
||||
|
||||
fail:
|
||||
grub_free (uuid_root);
|
||||
grub_free (uuid_prefix);
|
||||
grub_free (prefdev);
|
||||
|
||||
for (i = 0; i < mods_loaded; i++)
|
||||
if (mods[i])
|
||||
@@ -302,6 +312,8 @@ grub_cmd_nativedisk (grub_command_t cmd __attribute__ ((unused)),
|
||||
mods[i]->fini = 0;
|
||||
grub_dl_unload (mods[i]);
|
||||
}
|
||||
grub_free (mods);
|
||||
|
||||
return grub_errno;
|
||||
}
|
||||
|
||||
|
||||
@@ -193,7 +193,7 @@ grub_cmd_parttool (grub_command_t cmd __attribute__ ((unused)),
|
||||
{
|
||||
grub_file_t file;
|
||||
|
||||
file = grub_file_open (filename);
|
||||
file = grub_file_open (filename, GRUB_FILE_TYPE_GRUB_MODULE_LIST);
|
||||
if (file)
|
||||
{
|
||||
char *buf = 0;
|
||||
@@ -283,6 +283,7 @@ grub_cmd_parttool (grub_command_t cmd __attribute__ ((unused)),
|
||||
}
|
||||
if (! cur)
|
||||
{
|
||||
grub_free (parsed);
|
||||
grub_device_close (dev);
|
||||
return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("unknown argument `%s'"),
|
||||
args[i]);
|
||||
|
||||
@@ -45,6 +45,7 @@ check_password (const char *user, const char *entered, void *pin)
|
||||
grub_uint8_t *buf;
|
||||
struct pbkdf2_password *pass = pin;
|
||||
gcry_err_code_t err;
|
||||
grub_err_t ret;
|
||||
|
||||
buf = grub_malloc (pass->buflen);
|
||||
if (!buf)
|
||||
@@ -55,17 +56,17 @@ check_password (const char *user, const char *entered, void *pin)
|
||||
pass->salt, pass->saltlen, pass->c,
|
||||
buf, pass->buflen);
|
||||
if (err)
|
||||
ret = grub_crypto_gcry_error (err);
|
||||
else if (grub_crypto_memcmp (buf, pass->expected, pass->buflen) != 0)
|
||||
ret = GRUB_ACCESS_DENIED;
|
||||
else
|
||||
{
|
||||
grub_free (buf);
|
||||
return grub_crypto_gcry_error (err);
|
||||
grub_auth_authenticate (user);
|
||||
ret = GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
if (grub_crypto_memcmp (buf, pass->expected, pass->buflen) != 0)
|
||||
return GRUB_ACCESS_DENIED;
|
||||
|
||||
grub_auth_authenticate (user);
|
||||
|
||||
return GRUB_ERR_NONE;
|
||||
grub_free (buf);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static inline int
|
||||
|
||||
@@ -64,7 +64,7 @@ iterate_device (const char *name, void *data)
|
||||
/* Skip floppy drives when requested. */
|
||||
if (ctx->no_floppy &&
|
||||
name[0] == 'f' && name[1] == 'd' && name[2] >= '0' && name[2] <= '9')
|
||||
return 0;
|
||||
return 1;
|
||||
|
||||
#ifdef DO_SEARCH_FS_UUID
|
||||
#define compare_fn grub_strcasecmp
|
||||
@@ -81,8 +81,8 @@ iterate_device (const char *name, void *data)
|
||||
if (! buf)
|
||||
return 1;
|
||||
|
||||
grub_file_filter_disable_compression ();
|
||||
file = grub_file_open (buf);
|
||||
file = grub_file_open (buf, GRUB_FILE_TYPE_FS_SEARCH
|
||||
| GRUB_FILE_TYPE_NO_DECOMPRESS);
|
||||
if (file)
|
||||
{
|
||||
found = 1;
|
||||
|
||||
@@ -355,8 +355,8 @@ test_parse (char **args, int *argn, int argc)
|
||||
if (grub_strcmp (args[*argn], "-s") == 0)
|
||||
{
|
||||
grub_file_t file;
|
||||
grub_file_filter_disable_compression ();
|
||||
file = grub_file_open (args[*argn + 1]);
|
||||
file = grub_file_open (args[*argn + 1], GRUB_FILE_TYPE_GET_SIZE
|
||||
| GRUB_FILE_TYPE_NO_DECOMPRESS);
|
||||
update_val (file && (grub_file_size (file) != 0), &ctx);
|
||||
if (file)
|
||||
grub_file_close (file);
|
||||
|
||||
@@ -57,7 +57,7 @@ grub_cmd_testload (struct grub_command *cmd __attribute__ ((unused)),
|
||||
if (argc < 1)
|
||||
return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected"));
|
||||
|
||||
file = grub_file_open (argv[0]);
|
||||
file = grub_file_open (argv[0], GRUB_FILE_TYPE_TESTLOAD);
|
||||
if (! file)
|
||||
return grub_errno;
|
||||
|
||||
|
||||
@@ -61,7 +61,7 @@ grub_cmd_testspeed (grub_extcmd_context_t ctxt, int argc, char **args)
|
||||
if (buffer == NULL)
|
||||
return grub_errno;
|
||||
|
||||
file = grub_file_open (args[0]);
|
||||
file = grub_file_open (args[0], GRUB_FILE_TYPE_TESTLOAD);
|
||||
if (file == NULL)
|
||||
goto quit;
|
||||
|
||||
|
||||
@@ -30,16 +30,10 @@
|
||||
#include <grub/env.h>
|
||||
#include <grub/kernel.h>
|
||||
#include <grub/extcmd.h>
|
||||
#include <grub/verify.h>
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
struct grub_verified
|
||||
{
|
||||
grub_file_t file;
|
||||
void *buf;
|
||||
};
|
||||
typedef struct grub_verified *grub_verified_t;
|
||||
|
||||
enum
|
||||
{
|
||||
OPTION_SKIP_SIG = 0
|
||||
@@ -324,19 +318,19 @@ grub_load_public_key (grub_file_t f)
|
||||
if (grub_file_read (f, &l, sizeof (l)) != sizeof (l))
|
||||
{
|
||||
grub_error (GRUB_ERR_BAD_SIGNATURE, N_("bad signature"));
|
||||
goto fail;
|
||||
break;
|
||||
}
|
||||
|
||||
lb = (grub_be_to_cpu16 (l) + GRUB_CHAR_BIT - 1) / GRUB_CHAR_BIT;
|
||||
if (lb > READBUF_SIZE - sizeof (grub_uint16_t))
|
||||
{
|
||||
grub_error (GRUB_ERR_BAD_SIGNATURE, N_("bad signature"));
|
||||
goto fail;
|
||||
break;
|
||||
}
|
||||
if (grub_file_read (f, buffer + sizeof (grub_uint16_t), lb) != (grub_ssize_t) lb)
|
||||
{
|
||||
grub_error (GRUB_ERR_BAD_SIGNATURE, N_("bad signature"));
|
||||
goto fail;
|
||||
break;
|
||||
}
|
||||
grub_memcpy (buffer, &l, sizeof (l));
|
||||
|
||||
@@ -346,10 +340,16 @@ grub_load_public_key (grub_file_t f)
|
||||
buffer, lb + sizeof (grub_uint16_t), 0))
|
||||
{
|
||||
grub_error (GRUB_ERR_BAD_SIGNATURE, N_("bad signature"));
|
||||
goto fail;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (i < pkalgos[pk].nmpipub)
|
||||
{
|
||||
grub_free (sk);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
GRUB_MD_SHA1->final (fingerprint_context);
|
||||
|
||||
grub_memcpy (sk->fingerprint, GRUB_MD_SHA1->read (fingerprint_context), 20);
|
||||
@@ -439,22 +439,26 @@ rsa_pad (gcry_mpi_t *hmpi, grub_uint8_t *hval,
|
||||
return ret;
|
||||
}
|
||||
|
||||
struct grub_pubkey_context
|
||||
{
|
||||
grub_file_t sig;
|
||||
struct signature_v4_header v4;
|
||||
grub_uint8_t v;
|
||||
const gcry_md_spec_t *hash;
|
||||
void *hash_context;
|
||||
};
|
||||
|
||||
static grub_err_t
|
||||
grub_verify_signature_real (char *buf, grub_size_t size,
|
||||
grub_file_t f, grub_file_t sig,
|
||||
struct grub_public_key *pkey)
|
||||
grub_verify_signature_init (struct grub_pubkey_context *ctxt, grub_file_t sig)
|
||||
{
|
||||
grub_size_t len;
|
||||
grub_uint8_t v;
|
||||
grub_uint8_t h;
|
||||
grub_uint8_t t;
|
||||
grub_uint8_t pk;
|
||||
const gcry_md_spec_t *hash;
|
||||
struct signature_v4_header v4;
|
||||
grub_err_t err;
|
||||
grub_size_t i;
|
||||
gcry_mpi_t mpis[10];
|
||||
grub_uint8_t type = 0;
|
||||
grub_uint8_t pk;
|
||||
|
||||
grub_memset (ctxt, 0, sizeof (*ctxt));
|
||||
|
||||
err = read_packet_header (sig, &type, &len);
|
||||
if (err)
|
||||
@@ -463,18 +467,18 @@ grub_verify_signature_real (char *buf, grub_size_t size,
|
||||
if (type != 0x2)
|
||||
return grub_error (GRUB_ERR_BAD_SIGNATURE, N_("bad signature"));
|
||||
|
||||
if (grub_file_read (sig, &v, sizeof (v)) != sizeof (v))
|
||||
if (grub_file_read (sig, &ctxt->v, sizeof (ctxt->v)) != sizeof (ctxt->v))
|
||||
return grub_error (GRUB_ERR_BAD_SIGNATURE, N_("bad signature"));
|
||||
|
||||
if (v != 4)
|
||||
if (ctxt->v != 4)
|
||||
return grub_error (GRUB_ERR_BAD_SIGNATURE, N_("bad signature"));
|
||||
|
||||
if (grub_file_read (sig, &v4, sizeof (v4)) != sizeof (v4))
|
||||
if (grub_file_read (sig, &ctxt->v4, sizeof (ctxt->v4)) != sizeof (ctxt->v4))
|
||||
return grub_error (GRUB_ERR_BAD_SIGNATURE, N_("bad signature"));
|
||||
|
||||
h = v4.hash;
|
||||
t = v4.type;
|
||||
pk = v4.pkeyalgo;
|
||||
h = ctxt->v4.hash;
|
||||
t = ctxt->v4.type;
|
||||
pk = ctxt->v4.pkeyalgo;
|
||||
|
||||
if (t != 0)
|
||||
return grub_error (GRUB_ERR_BAD_SIGNATURE, N_("bad signature"));
|
||||
@@ -485,183 +489,232 @@ grub_verify_signature_real (char *buf, grub_size_t size,
|
||||
if (pk >= ARRAY_SIZE (pkalgos) || pkalgos[pk].name == NULL)
|
||||
return grub_error (GRUB_ERR_BAD_SIGNATURE, N_("bad signature"));
|
||||
|
||||
hash = grub_crypto_lookup_md_by_name (hashes[h]);
|
||||
if (!hash)
|
||||
ctxt->hash = grub_crypto_lookup_md_by_name (hashes[h]);
|
||||
if (!ctxt->hash)
|
||||
return grub_error (GRUB_ERR_BAD_SIGNATURE, "hash `%s' not loaded", hashes[h]);
|
||||
|
||||
grub_dprintf ("crypt", "alive\n");
|
||||
|
||||
{
|
||||
void *context = NULL;
|
||||
unsigned char *hval;
|
||||
grub_ssize_t rem = grub_be_to_cpu16 (v4.hashed_sub);
|
||||
grub_uint32_t headlen = grub_cpu_to_be32 (rem + 6);
|
||||
grub_uint8_t s;
|
||||
grub_uint16_t unhashed_sub;
|
||||
grub_ssize_t r;
|
||||
grub_uint8_t hash_start[2];
|
||||
gcry_mpi_t hmpi;
|
||||
grub_uint64_t keyid = 0;
|
||||
struct grub_public_subkey *sk;
|
||||
grub_uint8_t *readbuf = NULL;
|
||||
ctxt->sig = sig;
|
||||
|
||||
context = grub_zalloc (hash->contextsize);
|
||||
readbuf = grub_zalloc (READBUF_SIZE);
|
||||
if (!context || !readbuf)
|
||||
goto fail;
|
||||
ctxt->hash_context = grub_zalloc (ctxt->hash->contextsize);
|
||||
if (!ctxt->hash_context)
|
||||
return grub_errno;
|
||||
|
||||
hash->init (context);
|
||||
if (buf)
|
||||
hash->write (context, buf, size);
|
||||
else
|
||||
while (1)
|
||||
{
|
||||
r = grub_file_read (f, readbuf, READBUF_SIZE);
|
||||
if (r < 0)
|
||||
goto fail;
|
||||
if (r == 0)
|
||||
break;
|
||||
hash->write (context, readbuf, r);
|
||||
}
|
||||
ctxt->hash->init (ctxt->hash_context);
|
||||
|
||||
hash->write (context, &v, sizeof (v));
|
||||
hash->write (context, &v4, sizeof (v4));
|
||||
while (rem)
|
||||
{
|
||||
r = grub_file_read (sig, readbuf,
|
||||
rem < READBUF_SIZE ? rem : READBUF_SIZE);
|
||||
if (r < 0)
|
||||
goto fail;
|
||||
if (r == 0)
|
||||
break;
|
||||
hash->write (context, readbuf, r);
|
||||
rem -= r;
|
||||
}
|
||||
hash->write (context, &v, sizeof (v));
|
||||
s = 0xff;
|
||||
hash->write (context, &s, sizeof (s));
|
||||
hash->write (context, &headlen, sizeof (headlen));
|
||||
r = grub_file_read (sig, &unhashed_sub, sizeof (unhashed_sub));
|
||||
if (r != sizeof (unhashed_sub))
|
||||
goto fail;
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
static grub_err_t
|
||||
grub_pubkey_write (void *ctxt_, void *buf, grub_size_t size)
|
||||
{
|
||||
struct grub_pubkey_context *ctxt = ctxt_;
|
||||
ctxt->hash->write (ctxt->hash_context, buf, size);
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
static grub_err_t
|
||||
grub_verify_signature_real (struct grub_pubkey_context *ctxt,
|
||||
struct grub_public_key *pkey)
|
||||
{
|
||||
gcry_mpi_t mpis[10];
|
||||
grub_uint8_t pk = ctxt->v4.pkeyalgo;
|
||||
grub_size_t i;
|
||||
grub_uint8_t *readbuf = NULL;
|
||||
unsigned char *hval;
|
||||
grub_ssize_t rem = grub_be_to_cpu16 (ctxt->v4.hashed_sub);
|
||||
grub_uint32_t headlen = grub_cpu_to_be32 (rem + 6);
|
||||
grub_uint8_t s;
|
||||
grub_uint16_t unhashed_sub;
|
||||
grub_ssize_t r;
|
||||
grub_uint8_t hash_start[2];
|
||||
gcry_mpi_t hmpi;
|
||||
grub_uint64_t keyid = 0;
|
||||
struct grub_public_subkey *sk;
|
||||
|
||||
readbuf = grub_malloc (READBUF_SIZE);
|
||||
if (!readbuf)
|
||||
goto fail;
|
||||
|
||||
ctxt->hash->write (ctxt->hash_context, &ctxt->v, sizeof (ctxt->v));
|
||||
ctxt->hash->write (ctxt->hash_context, &ctxt->v4, sizeof (ctxt->v4));
|
||||
while (rem)
|
||||
{
|
||||
grub_uint8_t *ptr;
|
||||
grub_uint32_t l;
|
||||
rem = grub_be_to_cpu16 (unhashed_sub);
|
||||
if (rem > READBUF_SIZE)
|
||||
r = grub_file_read (ctxt->sig, readbuf,
|
||||
rem < READBUF_SIZE ? rem : READBUF_SIZE);
|
||||
if (r < 0)
|
||||
goto fail;
|
||||
r = grub_file_read (sig, readbuf, rem);
|
||||
if (r != rem)
|
||||
if (r == 0)
|
||||
break;
|
||||
ctxt->hash->write (ctxt->hash_context, readbuf, r);
|
||||
rem -= r;
|
||||
}
|
||||
ctxt->hash->write (ctxt->hash_context, &ctxt->v, sizeof (ctxt->v));
|
||||
s = 0xff;
|
||||
ctxt->hash->write (ctxt->hash_context, &s, sizeof (s));
|
||||
ctxt->hash->write (ctxt->hash_context, &headlen, sizeof (headlen));
|
||||
r = grub_file_read (ctxt->sig, &unhashed_sub, sizeof (unhashed_sub));
|
||||
if (r != sizeof (unhashed_sub))
|
||||
goto fail;
|
||||
{
|
||||
grub_uint8_t *ptr;
|
||||
grub_uint32_t l;
|
||||
rem = grub_be_to_cpu16 (unhashed_sub);
|
||||
if (rem > READBUF_SIZE)
|
||||
goto fail;
|
||||
r = grub_file_read (ctxt->sig, readbuf, rem);
|
||||
if (r != rem)
|
||||
goto fail;
|
||||
for (ptr = readbuf; ptr < readbuf + rem; ptr += l)
|
||||
{
|
||||
if (*ptr < 192)
|
||||
l = *ptr++;
|
||||
else if (*ptr < 255)
|
||||
{
|
||||
if (ptr + 1 >= readbuf + rem)
|
||||
break;
|
||||
l = (((ptr[0] & ~192) << GRUB_CHAR_BIT) | ptr[1]) + 192;
|
||||
ptr += 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (ptr + 5 >= readbuf + rem)
|
||||
break;
|
||||
l = grub_be_to_cpu32 (grub_get_unaligned32 (ptr + 1));
|
||||
ptr += 5;
|
||||
}
|
||||
if (*ptr == 0x10 && l >= 8)
|
||||
keyid = grub_get_unaligned64 (ptr + 1);
|
||||
}
|
||||
}
|
||||
|
||||
ctxt->hash->final (ctxt->hash_context);
|
||||
|
||||
grub_dprintf ("crypt", "alive\n");
|
||||
|
||||
hval = ctxt->hash->read (ctxt->hash_context);
|
||||
|
||||
if (grub_file_read (ctxt->sig, hash_start, sizeof (hash_start)) != sizeof (hash_start))
|
||||
goto fail;
|
||||
if (grub_memcmp (hval, hash_start, sizeof (hash_start)) != 0)
|
||||
goto fail;
|
||||
|
||||
grub_dprintf ("crypt", "@ %x\n", (int)grub_file_tell (ctxt->sig));
|
||||
|
||||
for (i = 0; i < pkalgos[pk].nmpisig; i++)
|
||||
{
|
||||
grub_uint16_t l;
|
||||
grub_size_t lb;
|
||||
grub_dprintf ("crypt", "alive\n");
|
||||
if (grub_file_read (ctxt->sig, &l, sizeof (l)) != sizeof (l))
|
||||
goto fail;
|
||||
for (ptr = readbuf; ptr < readbuf + rem; ptr += l)
|
||||
{
|
||||
if (*ptr < 192)
|
||||
l = *ptr++;
|
||||
else if (*ptr < 255)
|
||||
{
|
||||
if (ptr + 1 >= readbuf + rem)
|
||||
break;
|
||||
l = (((ptr[0] & ~192) << GRUB_CHAR_BIT) | ptr[1]) + 192;
|
||||
ptr += 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (ptr + 5 >= readbuf + rem)
|
||||
break;
|
||||
l = grub_be_to_cpu32 (grub_get_unaligned32 (ptr + 1));
|
||||
ptr += 5;
|
||||
}
|
||||
if (*ptr == 0x10 && l >= 8)
|
||||
keyid = grub_get_unaligned64 (ptr + 1);
|
||||
}
|
||||
grub_dprintf ("crypt", "alive\n");
|
||||
lb = (grub_be_to_cpu16 (l) + 7) / 8;
|
||||
grub_dprintf ("crypt", "l = 0x%04x\n", grub_be_to_cpu16 (l));
|
||||
if (lb > READBUF_SIZE - sizeof (grub_uint16_t))
|
||||
goto fail;
|
||||
grub_dprintf ("crypt", "alive\n");
|
||||
if (grub_file_read (ctxt->sig, readbuf + sizeof (grub_uint16_t), lb) != (grub_ssize_t) lb)
|
||||
goto fail;
|
||||
grub_dprintf ("crypt", "alive\n");
|
||||
grub_memcpy (readbuf, &l, sizeof (l));
|
||||
grub_dprintf ("crypt", "alive\n");
|
||||
|
||||
if (gcry_mpi_scan (&mpis[i], GCRYMPI_FMT_PGP,
|
||||
readbuf, lb + sizeof (grub_uint16_t), 0))
|
||||
goto fail;
|
||||
grub_dprintf ("crypt", "alive\n");
|
||||
}
|
||||
|
||||
hash->final (context);
|
||||
|
||||
grub_dprintf ("crypt", "alive\n");
|
||||
|
||||
hval = hash->read (context);
|
||||
|
||||
if (grub_file_read (sig, hash_start, sizeof (hash_start)) != sizeof (hash_start))
|
||||
if (pkey)
|
||||
sk = grub_crypto_pk_locate_subkey (keyid, pkey);
|
||||
else
|
||||
sk = grub_crypto_pk_locate_subkey_in_trustdb (keyid);
|
||||
if (!sk)
|
||||
{
|
||||
/* TRANSLATORS: %08x is 32-bit key id. */
|
||||
grub_error (GRUB_ERR_BAD_SIGNATURE, N_("public key %08x not found"),
|
||||
keyid);
|
||||
goto fail;
|
||||
if (grub_memcmp (hval, hash_start, sizeof (hash_start)) != 0)
|
||||
}
|
||||
|
||||
if (pkalgos[pk].pad (&hmpi, hval, ctxt->hash, sk))
|
||||
goto fail;
|
||||
if (!*pkalgos[pk].algo)
|
||||
{
|
||||
grub_dl_load (pkalgos[pk].module);
|
||||
grub_errno = GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
if (!*pkalgos[pk].algo)
|
||||
{
|
||||
grub_error (GRUB_ERR_BAD_SIGNATURE, N_("module `%s' isn't loaded"),
|
||||
pkalgos[pk].module);
|
||||
goto fail;
|
||||
}
|
||||
if ((*pkalgos[pk].algo)->verify (0, hmpi, mpis, sk->mpis, 0, 0))
|
||||
goto fail;
|
||||
|
||||
grub_dprintf ("crypt", "@ %x\n", (int)grub_file_tell (sig));
|
||||
grub_free (readbuf);
|
||||
|
||||
for (i = 0; i < pkalgos[pk].nmpisig; i++)
|
||||
{
|
||||
grub_uint16_t l;
|
||||
grub_size_t lb;
|
||||
grub_dprintf ("crypt", "alive\n");
|
||||
if (grub_file_read (sig, &l, sizeof (l)) != sizeof (l))
|
||||
goto fail;
|
||||
grub_dprintf ("crypt", "alive\n");
|
||||
lb = (grub_be_to_cpu16 (l) + 7) / 8;
|
||||
grub_dprintf ("crypt", "l = 0x%04x\n", grub_be_to_cpu16 (l));
|
||||
if (lb > READBUF_SIZE - sizeof (grub_uint16_t))
|
||||
goto fail;
|
||||
grub_dprintf ("crypt", "alive\n");
|
||||
if (grub_file_read (sig, readbuf + sizeof (grub_uint16_t), lb) != (grub_ssize_t) lb)
|
||||
goto fail;
|
||||
grub_dprintf ("crypt", "alive\n");
|
||||
grub_memcpy (readbuf, &l, sizeof (l));
|
||||
grub_dprintf ("crypt", "alive\n");
|
||||
return GRUB_ERR_NONE;
|
||||
|
||||
if (gcry_mpi_scan (&mpis[i], GCRYMPI_FMT_PGP,
|
||||
readbuf, lb + sizeof (grub_uint16_t), 0))
|
||||
goto fail;
|
||||
grub_dprintf ("crypt", "alive\n");
|
||||
}
|
||||
fail:
|
||||
grub_free (readbuf);
|
||||
if (!grub_errno)
|
||||
return grub_error (GRUB_ERR_BAD_SIGNATURE, N_("bad signature"));
|
||||
return grub_errno;
|
||||
}
|
||||
|
||||
if (pkey)
|
||||
sk = grub_crypto_pk_locate_subkey (keyid, pkey);
|
||||
else
|
||||
sk = grub_crypto_pk_locate_subkey_in_trustdb (keyid);
|
||||
if (!sk)
|
||||
{
|
||||
/* TRANSLATORS: %08x is 32-bit key id. */
|
||||
grub_error (GRUB_ERR_BAD_SIGNATURE, N_("public key %08x not found"),
|
||||
keyid);
|
||||
goto fail;
|
||||
}
|
||||
static void
|
||||
grub_pubkey_close_real (struct grub_pubkey_context *ctxt)
|
||||
{
|
||||
if (ctxt->sig)
|
||||
grub_file_close (ctxt->sig);
|
||||
if (ctxt->hash_context)
|
||||
grub_free (ctxt->hash_context);
|
||||
}
|
||||
|
||||
if (pkalgos[pk].pad (&hmpi, hval, hash, sk))
|
||||
goto fail;
|
||||
if (!*pkalgos[pk].algo)
|
||||
{
|
||||
grub_dl_load (pkalgos[pk].module);
|
||||
grub_errno = GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
if (!*pkalgos[pk].algo)
|
||||
{
|
||||
grub_error (GRUB_ERR_BAD_SIGNATURE, N_("module `%s' isn't loaded"),
|
||||
pkalgos[pk].module);
|
||||
goto fail;
|
||||
}
|
||||
if ((*pkalgos[pk].algo)->verify (0, hmpi, mpis, sk->mpis, 0, 0))
|
||||
goto fail;
|
||||
|
||||
grub_free (context);
|
||||
grub_free (readbuf);
|
||||
|
||||
return GRUB_ERR_NONE;
|
||||
|
||||
fail:
|
||||
grub_free (context);
|
||||
grub_free (readbuf);
|
||||
if (!grub_errno)
|
||||
return grub_error (GRUB_ERR_BAD_SIGNATURE, N_("bad signature"));
|
||||
return grub_errno;
|
||||
}
|
||||
static void
|
||||
grub_pubkey_close (void *ctxt)
|
||||
{
|
||||
grub_pubkey_close_real (ctxt);
|
||||
grub_free (ctxt);
|
||||
}
|
||||
|
||||
grub_err_t
|
||||
grub_verify_signature (grub_file_t f, grub_file_t sig,
|
||||
struct grub_public_key *pkey)
|
||||
{
|
||||
return grub_verify_signature_real (0, 0, f, sig, pkey);
|
||||
grub_err_t err;
|
||||
struct grub_pubkey_context ctxt;
|
||||
grub_uint8_t *readbuf = NULL;
|
||||
err = grub_verify_signature_init (&ctxt, sig);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
readbuf = grub_zalloc (READBUF_SIZE);
|
||||
if (!readbuf)
|
||||
goto fail;
|
||||
|
||||
while (1)
|
||||
{
|
||||
grub_ssize_t r;
|
||||
r = grub_file_read (f, readbuf, READBUF_SIZE);
|
||||
if (r < 0)
|
||||
goto fail;
|
||||
if (r == 0)
|
||||
break;
|
||||
err = grub_pubkey_write (&ctxt, readbuf, r);
|
||||
if (err)
|
||||
return err;
|
||||
}
|
||||
|
||||
grub_verify_signature_real (&ctxt, pkey);
|
||||
fail:
|
||||
grub_pubkey_close_real (&ctxt);
|
||||
return grub_errno;
|
||||
}
|
||||
|
||||
static grub_err_t
|
||||
@@ -674,10 +727,12 @@ grub_cmd_trust (grub_extcmd_context_t ctxt,
|
||||
if (argc < 1)
|
||||
return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("one argument expected"));
|
||||
|
||||
grub_file_filter_disable_compression ();
|
||||
if (ctxt->state[OPTION_SKIP_SIG].set)
|
||||
grub_file_filter_disable_pubkey ();
|
||||
pkf = grub_file_open (args[0]);
|
||||
pkf = grub_file_open (args[0],
|
||||
GRUB_FILE_TYPE_PUBLIC_KEY_TRUST
|
||||
| GRUB_FILE_TYPE_NO_DECOMPRESS
|
||||
| (ctxt->state[OPTION_SKIP_SIG].set
|
||||
? GRUB_FILE_TYPE_SKIP_SIGNATURE
|
||||
: 0));
|
||||
if (!pkf)
|
||||
return grub_errno;
|
||||
pk = grub_load_public_key (pkf);
|
||||
@@ -765,10 +820,12 @@ grub_cmd_verify_signature (grub_extcmd_context_t ctxt,
|
||||
if (argc > 2)
|
||||
{
|
||||
grub_file_t pkf;
|
||||
grub_file_filter_disable_compression ();
|
||||
if (ctxt->state[OPTION_SKIP_SIG].set)
|
||||
grub_file_filter_disable_pubkey ();
|
||||
pkf = grub_file_open (args[2]);
|
||||
pkf = grub_file_open (args[2],
|
||||
GRUB_FILE_TYPE_PUBLIC_KEY
|
||||
| GRUB_FILE_TYPE_NO_DECOMPRESS
|
||||
| (ctxt->state[OPTION_SKIP_SIG].set
|
||||
? GRUB_FILE_TYPE_SKIP_SIGNATURE
|
||||
: 0));
|
||||
if (!pkf)
|
||||
return grub_errno;
|
||||
pk = grub_load_public_key (pkf);
|
||||
@@ -780,16 +837,16 @@ grub_cmd_verify_signature (grub_extcmd_context_t ctxt,
|
||||
grub_file_close (pkf);
|
||||
}
|
||||
|
||||
grub_file_filter_disable_all ();
|
||||
f = grub_file_open (args[0]);
|
||||
f = grub_file_open (args[0], GRUB_FILE_TYPE_VERIFY_SIGNATURE);
|
||||
if (!f)
|
||||
{
|
||||
err = grub_errno;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
grub_file_filter_disable_all ();
|
||||
sig = grub_file_open (args[1]);
|
||||
sig = grub_file_open (args[1],
|
||||
GRUB_FILE_TYPE_SIGNATURE
|
||||
| GRUB_FILE_TYPE_NO_DECOMPRESS);
|
||||
if (!sig)
|
||||
{
|
||||
err = grub_errno;
|
||||
@@ -809,135 +866,52 @@ grub_cmd_verify_signature (grub_extcmd_context_t ctxt,
|
||||
|
||||
static int sec = 0;
|
||||
|
||||
static void
|
||||
verified_free (grub_verified_t verified)
|
||||
{
|
||||
if (verified)
|
||||
{
|
||||
grub_free (verified->buf);
|
||||
grub_free (verified);
|
||||
}
|
||||
}
|
||||
|
||||
static grub_ssize_t
|
||||
verified_read (struct grub_file *file, char *buf, grub_size_t len)
|
||||
{
|
||||
grub_verified_t verified = file->data;
|
||||
|
||||
grub_memcpy (buf, (char *) verified->buf + file->offset, len);
|
||||
return len;
|
||||
}
|
||||
|
||||
static grub_err_t
|
||||
verified_close (struct grub_file *file)
|
||||
{
|
||||
grub_verified_t verified = file->data;
|
||||
|
||||
grub_file_close (verified->file);
|
||||
verified_free (verified);
|
||||
file->data = 0;
|
||||
|
||||
/* device and name are freed by parent */
|
||||
file->device = 0;
|
||||
file->name = 0;
|
||||
|
||||
return grub_errno;
|
||||
}
|
||||
|
||||
struct grub_fs verified_fs =
|
||||
{
|
||||
.name = "verified_read",
|
||||
.read = verified_read,
|
||||
.close = verified_close
|
||||
};
|
||||
|
||||
static grub_file_t
|
||||
grub_pubkey_open (grub_file_t io, const char *filename)
|
||||
grub_pubkey_init (grub_file_t io, enum grub_file_type type __attribute__ ((unused)),
|
||||
void **context, enum grub_verify_flags *flags)
|
||||
{
|
||||
grub_file_t sig;
|
||||
char *fsuf, *ptr;
|
||||
grub_err_t err;
|
||||
grub_file_filter_t curfilt[GRUB_FILE_FILTER_MAX];
|
||||
grub_file_t ret;
|
||||
grub_verified_t verified;
|
||||
|
||||
if (!sec)
|
||||
return io;
|
||||
if (io->device->disk &&
|
||||
(io->device->disk->dev->id == GRUB_DISK_DEVICE_MEMDISK_ID
|
||||
|| io->device->disk->dev->id == GRUB_DISK_DEVICE_PROCFS_ID))
|
||||
return io;
|
||||
fsuf = grub_malloc (grub_strlen (filename) + sizeof (".sig"));
|
||||
{
|
||||
*flags = GRUB_VERIFY_FLAGS_SKIP_VERIFICATION;
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
fsuf = grub_malloc (grub_strlen (io->name) + sizeof (".sig"));
|
||||
if (!fsuf)
|
||||
return NULL;
|
||||
ptr = grub_stpcpy (fsuf, filename);
|
||||
return grub_errno;
|
||||
ptr = grub_stpcpy (fsuf, io->name);
|
||||
grub_memcpy (ptr, ".sig", sizeof (".sig"));
|
||||
|
||||
grub_memcpy (curfilt, grub_file_filters_enabled,
|
||||
sizeof (curfilt));
|
||||
grub_file_filter_disable_all ();
|
||||
sig = grub_file_open (fsuf);
|
||||
grub_memcpy (grub_file_filters_enabled, curfilt,
|
||||
sizeof (curfilt));
|
||||
sig = grub_file_open (fsuf, GRUB_FILE_TYPE_SIGNATURE);
|
||||
grub_free (fsuf);
|
||||
if (!sig)
|
||||
return NULL;
|
||||
return grub_errno;
|
||||
|
||||
ret = grub_malloc (sizeof (*ret));
|
||||
if (!ret)
|
||||
{
|
||||
grub_file_close (sig);
|
||||
return NULL;
|
||||
}
|
||||
*ret = *io;
|
||||
|
||||
ret->fs = &verified_fs;
|
||||
ret->not_easily_seekable = 0;
|
||||
if (ret->size >> (sizeof (grub_size_t) * GRUB_CHAR_BIT - 1))
|
||||
{
|
||||
grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
|
||||
"big file signature isn't implemented yet");
|
||||
grub_file_close (sig);
|
||||
grub_free (ret);
|
||||
return NULL;
|
||||
}
|
||||
verified = grub_malloc (sizeof (*verified));
|
||||
if (!verified)
|
||||
struct grub_pubkey_context *ctxt = grub_malloc (sizeof (*ctxt));
|
||||
if (!ctxt)
|
||||
{
|
||||
grub_file_close (sig);
|
||||
grub_free (ret);
|
||||
return NULL;
|
||||
return grub_errno;
|
||||
}
|
||||
verified->buf = grub_malloc (ret->size);
|
||||
if (!verified->buf)
|
||||
{
|
||||
grub_file_close (sig);
|
||||
grub_free (verified);
|
||||
grub_free (ret);
|
||||
return NULL;
|
||||
}
|
||||
if (grub_file_read (io, verified->buf, ret->size) != (grub_ssize_t) ret->size)
|
||||
{
|
||||
if (!grub_errno)
|
||||
grub_error (GRUB_ERR_FILE_READ_ERROR, N_("premature end of file %s"),
|
||||
filename);
|
||||
grub_file_close (sig);
|
||||
verified_free (verified);
|
||||
grub_free (ret);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
err = grub_verify_signature_real (verified->buf, ret->size, 0, sig, NULL);
|
||||
grub_file_close (sig);
|
||||
err = grub_verify_signature_init (ctxt, sig);
|
||||
if (err)
|
||||
{
|
||||
verified_free (verified);
|
||||
grub_free (ret);
|
||||
return NULL;
|
||||
grub_pubkey_close (ctxt);
|
||||
return err;
|
||||
}
|
||||
verified->file = io;
|
||||
ret->data = verified;
|
||||
return ret;
|
||||
*context = ctxt;
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
static grub_err_t
|
||||
grub_pubkey_fini (void *ctxt)
|
||||
{
|
||||
return grub_verify_signature_real (ctxt, NULL);
|
||||
}
|
||||
|
||||
static char *
|
||||
@@ -961,8 +935,16 @@ struct grub_fs pseudo_fs =
|
||||
{
|
||||
.name = "pseudo",
|
||||
.read = pseudo_read
|
||||
};
|
||||
};
|
||||
|
||||
struct grub_file_verifier grub_pubkey_verifier =
|
||||
{
|
||||
.name = "pgp",
|
||||
.init = grub_pubkey_init,
|
||||
.fini = grub_pubkey_fini,
|
||||
.write = grub_pubkey_write,
|
||||
.close = grub_pubkey_close,
|
||||
};
|
||||
|
||||
static grub_extcmd_t cmd, cmd_trust;
|
||||
static grub_command_t cmd_distrust, cmd_list;
|
||||
@@ -977,8 +959,6 @@ GRUB_MOD_INIT(verify)
|
||||
sec = 1;
|
||||
else
|
||||
sec = 0;
|
||||
|
||||
grub_file_filter_register (GRUB_FILE_FILTER_PUBKEY, grub_pubkey_open);
|
||||
|
||||
grub_register_variable_hook ("check_signatures", 0, grub_env_write_sec);
|
||||
grub_env_export ("check_signatures");
|
||||
@@ -1024,11 +1004,13 @@ GRUB_MOD_INIT(verify)
|
||||
cmd_distrust = grub_register_command ("distrust", grub_cmd_distrust,
|
||||
N_("PUBKEY_ID"),
|
||||
N_("Remove PUBKEY_ID from trusted keys."));
|
||||
|
||||
grub_verifier_register (&grub_pubkey_verifier);
|
||||
}
|
||||
|
||||
GRUB_MOD_FINI(verify)
|
||||
{
|
||||
grub_file_filter_unregister (GRUB_FILE_FILTER_PUBKEY);
|
||||
grub_verifier_unregister (&grub_pubkey_verifier);
|
||||
grub_unregister_extcmd (cmd);
|
||||
grub_unregister_extcmd (cmd_trust);
|
||||
grub_unregister_command (cmd_list);
|
||||
|
||||
186
grub-core/commands/verify_helper.c
Normal file
186
grub-core/commands/verify_helper.c
Normal file
@@ -0,0 +1,186 @@
|
||||
#include <grub/file.h>
|
||||
#include <grub/verify.h>
|
||||
#include <grub/dl.h>
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
struct grub_file_verifier *grub_file_verifiers;
|
||||
|
||||
struct grub_verified
|
||||
{
|
||||
grub_file_t file;
|
||||
void *buf;
|
||||
};
|
||||
typedef struct grub_verified *grub_verified_t;
|
||||
|
||||
static void
|
||||
verified_free (grub_verified_t verified)
|
||||
{
|
||||
if (verified)
|
||||
{
|
||||
grub_free (verified->buf);
|
||||
grub_free (verified);
|
||||
}
|
||||
}
|
||||
|
||||
static grub_ssize_t
|
||||
verified_read (struct grub_file *file, char *buf, grub_size_t len)
|
||||
{
|
||||
grub_verified_t verified = file->data;
|
||||
|
||||
grub_memcpy (buf, (char *) verified->buf + file->offset, len);
|
||||
return len;
|
||||
}
|
||||
|
||||
static grub_err_t
|
||||
verified_close (struct grub_file *file)
|
||||
{
|
||||
grub_verified_t verified = file->data;
|
||||
|
||||
grub_file_close (verified->file);
|
||||
verified_free (verified);
|
||||
file->data = 0;
|
||||
|
||||
/* device and name are freed by parent */
|
||||
file->device = 0;
|
||||
file->name = 0;
|
||||
|
||||
return grub_errno;
|
||||
}
|
||||
|
||||
struct grub_fs verified_fs =
|
||||
{
|
||||
.name = "verified_read",
|
||||
.read = verified_read,
|
||||
.close = verified_close
|
||||
};
|
||||
|
||||
static grub_file_t
|
||||
grub_verify_helper_open (grub_file_t io, enum grub_file_type type)
|
||||
{
|
||||
grub_verified_t verified = 0;
|
||||
struct grub_file_verifier *ver;
|
||||
void *context;
|
||||
grub_file_t ret = 0;
|
||||
grub_err_t err;
|
||||
|
||||
if ((type & GRUB_FILE_TYPE_MASK) == GRUB_FILE_TYPE_SIGNATURE
|
||||
|| (type & GRUB_FILE_TYPE_MASK) == GRUB_FILE_TYPE_VERIFY_SIGNATURE
|
||||
|| (type & GRUB_FILE_TYPE_SKIP_SIGNATURE))
|
||||
return io;
|
||||
|
||||
if (io->device->disk &&
|
||||
(io->device->disk->dev->id == GRUB_DISK_DEVICE_MEMDISK_ID
|
||||
|| io->device->disk->dev->id == GRUB_DISK_DEVICE_PROCFS_ID))
|
||||
return io;
|
||||
|
||||
FOR_LIST_ELEMENTS(ver, grub_file_verifiers)
|
||||
{
|
||||
enum grub_verify_flags flags = 0;
|
||||
err = ver->init (io, type, &context, &flags);
|
||||
if (err)
|
||||
goto fail_noclose;
|
||||
if (!(flags & GRUB_VERIFY_FLAGS_SKIP_VERIFICATION))
|
||||
break;
|
||||
}
|
||||
if (!ver)
|
||||
/* No verifiers wanted to verify. Just return underlying file. */
|
||||
return io;
|
||||
|
||||
ret = grub_malloc (sizeof (*ret));
|
||||
if (!ret)
|
||||
{
|
||||
goto fail;
|
||||
}
|
||||
*ret = *io;
|
||||
|
||||
ret->fs = &verified_fs;
|
||||
ret->not_easily_seekable = 0;
|
||||
if (ret->size >> (sizeof (grub_size_t) * GRUB_CHAR_BIT - 1))
|
||||
{
|
||||
grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
|
||||
"big file signature isn't implemented yet");
|
||||
goto fail;
|
||||
}
|
||||
verified = grub_malloc (sizeof (*verified));
|
||||
if (!verified)
|
||||
{
|
||||
goto fail;
|
||||
}
|
||||
verified->buf = grub_malloc (ret->size);
|
||||
if (!verified->buf)
|
||||
{
|
||||
goto fail;
|
||||
}
|
||||
if (grub_file_read (io, verified->buf, ret->size) != (grub_ssize_t) ret->size)
|
||||
{
|
||||
if (!grub_errno)
|
||||
grub_error (GRUB_ERR_FILE_READ_ERROR, N_("premature end of file %s"),
|
||||
io->name);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
err = ver->write (context, verified->buf, ret->size);
|
||||
if (err)
|
||||
goto fail;
|
||||
|
||||
err = ver->fini ? ver->fini (context) : GRUB_ERR_NONE;
|
||||
if (err)
|
||||
goto fail;
|
||||
|
||||
ver->close (context);
|
||||
|
||||
FOR_LIST_ELEMENTS_NEXT(ver, grub_file_verifiers)
|
||||
{
|
||||
enum grub_verify_flags flags = 0;
|
||||
err = ver->init (io, type, &context, &flags);
|
||||
if (err)
|
||||
goto fail_noclose;
|
||||
if (flags & GRUB_VERIFY_FLAGS_SKIP_VERIFICATION)
|
||||
continue;
|
||||
err = ver->write (context, verified->buf, ret->size);
|
||||
if (err)
|
||||
goto fail;
|
||||
|
||||
err = ver->fini ? ver->fini (context) : GRUB_ERR_NONE;
|
||||
if (err)
|
||||
goto fail;
|
||||
|
||||
ver->close (context);
|
||||
}
|
||||
|
||||
verified->file = io;
|
||||
ret->data = verified;
|
||||
return ret;
|
||||
|
||||
fail:
|
||||
ver->close (context);
|
||||
fail_noclose:
|
||||
verified_free (verified);
|
||||
grub_free (ret);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
grub_err_t
|
||||
grub_verify_string (char *str, enum grub_verify_string_type type)
|
||||
{
|
||||
struct grub_file_verifier *ver;
|
||||
FOR_LIST_ELEMENTS(ver, grub_file_verifiers)
|
||||
{
|
||||
grub_err_t err;
|
||||
err = ver->verify_string ? ver->verify_string (str, type) : GRUB_ERR_NONE;
|
||||
if (err)
|
||||
return err;
|
||||
}
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
GRUB_MOD_INIT(verify_helper)
|
||||
{
|
||||
grub_file_filter_register (GRUB_FILE_FILTER_VERIFY, grub_verify_helper_open);
|
||||
}
|
||||
|
||||
GRUB_MOD_FINI(verify_helper)
|
||||
{
|
||||
grub_file_filter_unregister (GRUB_FILE_FILTER_VERIFY);
|
||||
}
|
||||
@@ -32,7 +32,7 @@ GRUB_MOD_LICENSE ("GPLv3+");
|
||||
struct grub_ahci_cmd_head
|
||||
{
|
||||
grub_uint32_t config;
|
||||
grub_uint32_t transfered;
|
||||
grub_uint32_t transferred;
|
||||
grub_uint64_t command_table_base;
|
||||
grub_uint32_t unused[4];
|
||||
};
|
||||
@@ -954,7 +954,7 @@ grub_ahci_readwrite_real (struct grub_ahci_device *dev,
|
||||
grub_dprintf ("ahci", "AHCI tfd = %x\n",
|
||||
dev->hba->ports[dev->port].task_file_data);
|
||||
|
||||
dev->command_list[0].transfered = 0;
|
||||
dev->command_list[0].transferred = 0;
|
||||
dev->command_list[0].command_table_base
|
||||
= grub_dma_get_phys (dev->command_table_chunk);
|
||||
|
||||
@@ -1044,7 +1044,7 @@ grub_ahci_readwrite_real (struct grub_ahci_device *dev,
|
||||
dev->hba->ports[dev->port].command_issue,
|
||||
dev->hba->ports[dev->port].intstatus,
|
||||
dev->hba->ports[dev->port].task_file_data,
|
||||
dev->command_list[0].transfered,
|
||||
dev->command_list[0].transferred,
|
||||
dev->hba->ports[dev->port].sata_error,
|
||||
((grub_uint32_t *) grub_dma_get_virt (dev->rfis))[0x00],
|
||||
((grub_uint32_t *) grub_dma_get_virt (dev->rfis))[0x18]);
|
||||
|
||||
@@ -282,6 +282,7 @@ grub_cryptodisk_endecrypt (struct grub_cryptodisk *dev,
|
||||
break;
|
||||
case GRUB_CRYPTODISK_MODE_IV_PLAIN64:
|
||||
iv[1] = grub_cpu_to_le32 (sector >> 32);
|
||||
/* FALLTHROUGH */
|
||||
case GRUB_CRYPTODISK_MODE_IV_PLAIN:
|
||||
iv[0] = grub_cpu_to_le32 (sector & 0xFFFFFFFF);
|
||||
break;
|
||||
|
||||
@@ -80,11 +80,26 @@ make_devices (void)
|
||||
/* This should not happen... Why? */
|
||||
continue;
|
||||
|
||||
/* iPXE adds stub Block IO protocol to loaded image device handle. It is
|
||||
completely non-functional and simply returns an error for every method.
|
||||
So attempt to detect and skip it. Magic number is literal "iPXE" and
|
||||
check block size as well */
|
||||
/* FIXME: shoud we close it? We do not do it elsewhere */
|
||||
if (bio->media && bio->media->media_id == 0x69505845U &&
|
||||
bio->media->block_size == 1)
|
||||
continue;
|
||||
|
||||
d = grub_malloc (sizeof (*d));
|
||||
if (! d)
|
||||
{
|
||||
/* Uggh. */
|
||||
grub_free (handles);
|
||||
while (devices)
|
||||
{
|
||||
d = devices->next;
|
||||
grub_free (devices);
|
||||
devices = d;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -209,7 +224,7 @@ name_devices (struct grub_efidisk_data *devices)
|
||||
{
|
||||
case GRUB_EFI_HARD_DRIVE_DEVICE_PATH_SUBTYPE:
|
||||
is_hard_drive = 1;
|
||||
/* Fall through by intention. */
|
||||
/* Intentionally fall through. */
|
||||
case GRUB_EFI_CDROM_DEVICE_PATH_SUBTYPE:
|
||||
{
|
||||
struct grub_efidisk_data *parent, *parent2;
|
||||
@@ -487,8 +502,15 @@ grub_efidisk_open (const char *name, struct grub_disk *disk)
|
||||
m = d->block_io->media;
|
||||
/* FIXME: Probably it is better to store the block size in the disk,
|
||||
and total sectors should be replaced with total blocks. */
|
||||
grub_dprintf ("efidisk", "m = %p, last block = %llx, block size = %x\n",
|
||||
m, (unsigned long long) m->last_block, m->block_size);
|
||||
grub_dprintf ("efidisk",
|
||||
"m = %p, last block = %llx, block size = %x, io align = %x\n",
|
||||
m, (unsigned long long) m->last_block, m->block_size,
|
||||
m->io_align);
|
||||
|
||||
/* Ensure required buffer alignment is a power of two (or is zero). */
|
||||
if (m->io_align & (m->io_align - 1))
|
||||
return grub_error (GRUB_ERR_IO, "invalid buffer alignment %d", m->io_align);
|
||||
|
||||
disk->total_sectors = m->last_block + 1;
|
||||
/* Don't increase this value due to bug in some EFI. */
|
||||
disk->max_agglomerate = 0xa0000 >> (GRUB_DISK_CACHE_BITS + GRUB_DISK_SECTOR_BITS);
|
||||
@@ -518,15 +540,42 @@ grub_efidisk_readwrite (struct grub_disk *disk, grub_disk_addr_t sector,
|
||||
{
|
||||
struct grub_efidisk_data *d;
|
||||
grub_efi_block_io_t *bio;
|
||||
grub_efi_status_t status;
|
||||
grub_size_t io_align, num_bytes;
|
||||
char *aligned_buf;
|
||||
|
||||
d = disk->data;
|
||||
bio = d->block_io;
|
||||
|
||||
return efi_call_5 ((wr ? bio->write_blocks : bio->read_blocks), bio,
|
||||
bio->media->media_id,
|
||||
(grub_efi_uint64_t) sector,
|
||||
(grub_efi_uintn_t) size << disk->log_sector_size,
|
||||
buf);
|
||||
/* Set alignment to 1 if 0 specified */
|
||||
io_align = bio->media->io_align ? bio->media->io_align : 1;
|
||||
num_bytes = size << disk->log_sector_size;
|
||||
|
||||
if ((grub_addr_t) buf & (io_align - 1))
|
||||
{
|
||||
aligned_buf = grub_memalign (io_align, num_bytes);
|
||||
if (! aligned_buf)
|
||||
return GRUB_EFI_OUT_OF_RESOURCES;
|
||||
if (wr)
|
||||
grub_memcpy (aligned_buf, buf, num_bytes);
|
||||
}
|
||||
else
|
||||
{
|
||||
aligned_buf = buf;
|
||||
}
|
||||
|
||||
status = efi_call_5 ((wr ? bio->write_blocks : bio->read_blocks), bio,
|
||||
bio->media->media_id, (grub_efi_uint64_t) sector,
|
||||
(grub_efi_uintn_t) num_bytes, aligned_buf);
|
||||
|
||||
if ((grub_addr_t) buf & (io_align - 1))
|
||||
{
|
||||
if (!wr)
|
||||
grub_memcpy (buf, aligned_buf, num_bytes);
|
||||
grub_free (aligned_buf);
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
static grub_err_t
|
||||
@@ -541,7 +590,9 @@ grub_efidisk_read (struct grub_disk *disk, grub_disk_addr_t sector,
|
||||
|
||||
status = grub_efidisk_readwrite (disk, sector, size, buf, 0);
|
||||
|
||||
if (status != GRUB_EFI_SUCCESS)
|
||||
if (status == GRUB_EFI_NO_MEDIA)
|
||||
return grub_error (GRUB_ERR_OUT_OF_RANGE, N_("no media in `%s'"), disk->name);
|
||||
else if (status != GRUB_EFI_SUCCESS)
|
||||
return grub_error (GRUB_ERR_READ_ERROR,
|
||||
N_("failure reading sector 0x%llx from `%s'"),
|
||||
(unsigned long long) sector,
|
||||
@@ -562,7 +613,9 @@ grub_efidisk_write (struct grub_disk *disk, grub_disk_addr_t sector,
|
||||
|
||||
status = grub_efidisk_readwrite (disk, sector, size, (char *) buf, 1);
|
||||
|
||||
if (status != GRUB_EFI_SUCCESS)
|
||||
if (status == GRUB_EFI_NO_MEDIA)
|
||||
return grub_error (GRUB_ERR_OUT_OF_RANGE, N_("no media in `%s'"), disk->name);
|
||||
else if (status != GRUB_EFI_SUCCESS)
|
||||
return grub_error (GRUB_ERR_WRITE_ERROR,
|
||||
N_("failure writing sector 0x%llx to `%s'"),
|
||||
(unsigned long long) sector, disk->name);
|
||||
|
||||
@@ -92,7 +92,8 @@ grub_cmd_loopback (grub_extcmd_context_t ctxt, int argc, char **args)
|
||||
if (argc < 2)
|
||||
return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected"));
|
||||
|
||||
file = grub_file_open (args[1]);
|
||||
file = grub_file_open (args[1], GRUB_FILE_TYPE_LOOPBACK
|
||||
| GRUB_FILE_TYPE_NO_DECOMPRESS);
|
||||
if (! file)
|
||||
return grub_errno;
|
||||
|
||||
|
||||
@@ -154,7 +154,10 @@ grub_efiemu_init_segments (grub_efiemu_segment_t *segs, const Elf_Ehdr *e)
|
||||
s->sh_flags & SHF_EXECINSTR ? GRUB_EFI_RUNTIME_SERVICES_CODE
|
||||
: GRUB_EFI_RUNTIME_SERVICES_DATA);
|
||||
if (seg->handle < 0)
|
||||
return grub_errno;
|
||||
{
|
||||
grub_free (seg);
|
||||
return grub_errno;
|
||||
}
|
||||
seg->off = 0;
|
||||
}
|
||||
|
||||
@@ -343,7 +346,7 @@ SUFFIX (grub_efiemu_loadcore_init) (void *core, const char *filename,
|
||||
return grub_error (GRUB_ERR_BAD_MODULE, N_("this ELF file is not of the right type"));
|
||||
|
||||
/* Make sure that every section is within the core. */
|
||||
if ((grub_size_t) core_size < e->e_shoff + e->e_shentsize * e->e_shnum)
|
||||
if ((grub_size_t) core_size < e->e_shoff + (grub_uint32_t) e->e_shentsize * e->e_shnum)
|
||||
return grub_error (GRUB_ERR_BAD_OS, N_("premature end of file %s"),
|
||||
filename);
|
||||
|
||||
|
||||
@@ -187,7 +187,7 @@ grub_efiemu_load_file (const char *filename)
|
||||
grub_file_t file;
|
||||
grub_err_t err;
|
||||
|
||||
file = grub_file_open (filename);
|
||||
file = grub_file_open (filename, GRUB_FILE_TYPE_GRUB_MODULE);
|
||||
if (! file)
|
||||
return grub_errno;
|
||||
|
||||
@@ -196,7 +196,7 @@ grub_efiemu_load_file (const char *filename)
|
||||
{
|
||||
grub_file_close (file);
|
||||
grub_efiemu_unload ();
|
||||
return grub_errno;
|
||||
return err;
|
||||
}
|
||||
|
||||
grub_dprintf ("efiemu", "mm initialized\n");
|
||||
|
||||
@@ -99,7 +99,8 @@ grub_efiemu_request_memalign (grub_size_t align, grub_size_t size,
|
||||
grub_size_t align_overhead;
|
||||
struct grub_efiemu_memrequest *ret, *cur, *prev;
|
||||
/* Check that the request is correct */
|
||||
if (type >= GRUB_EFI_MAX_MEMORY_TYPE || type <= GRUB_EFI_LOADER_CODE)
|
||||
if (type <= GRUB_EFI_LOADER_CODE || type == GRUB_EFI_PERSISTENT_MEMORY ||
|
||||
type >= GRUB_EFI_MAX_MEMORY_TYPE)
|
||||
return -2;
|
||||
|
||||
/* Add new size to requested size */
|
||||
@@ -166,6 +167,13 @@ efiemu_alloc_requests (void)
|
||||
GRUB_EFI_MEMORY_MAPPED_IO,
|
||||
GRUB_EFI_MEMORY_MAPPED_IO_PORT_SPACE,
|
||||
GRUB_EFI_PAL_CODE
|
||||
|
||||
/*
|
||||
* These are not allocatable:
|
||||
* GRUB_EFI_RESERVED_MEMORY_TYPE
|
||||
* GRUB_EFI_PERSISTENT_MEMORY
|
||||
* >= GRUB_EFI_MAX_MEMORY_TYPE
|
||||
*/
|
||||
};
|
||||
|
||||
/* Compute total memory needed */
|
||||
@@ -402,9 +410,14 @@ fill_hook (grub_uint64_t addr, grub_uint64_t size, grub_memory_type_t type,
|
||||
return grub_efiemu_add_to_mmap (addr, size,
|
||||
GRUB_EFI_ACPI_MEMORY_NVS);
|
||||
|
||||
case GRUB_MEMORY_PERSISTENT:
|
||||
case GRUB_MEMORY_PERSISTENT_LEGACY:
|
||||
return grub_efiemu_add_to_mmap (addr, size,
|
||||
GRUB_EFI_PERSISTENT_MEMORY);
|
||||
default:
|
||||
grub_dprintf ("efiemu",
|
||||
"Unknown memory type %d. Assuming unusable\n", type);
|
||||
/* FALLTHROUGH */
|
||||
case GRUB_MEMORY_RESERVED:
|
||||
return grub_efiemu_add_to_mmap (addr, size,
|
||||
GRUB_EFI_UNUSABLE_MEMORY);
|
||||
@@ -445,7 +458,7 @@ grub_efiemu_mmap_iterate (grub_memory_hook_t hook, void *hook_data)
|
||||
case GRUB_EFI_MEMORY_MAPPED_IO:
|
||||
case GRUB_EFI_MEMORY_MAPPED_IO_PORT_SPACE:
|
||||
case GRUB_EFI_PAL_CODE:
|
||||
case GRUB_EFI_MAX_MEMORY_TYPE:
|
||||
default:
|
||||
hook (efiemu_mmap[i].physical_start, efiemu_mmap[i].num_pages * 4096,
|
||||
GRUB_MEMORY_RESERVED, hook_data);
|
||||
break;
|
||||
@@ -468,6 +481,12 @@ grub_efiemu_mmap_iterate (grub_memory_hook_t hook, void *hook_data)
|
||||
hook (efiemu_mmap[i].physical_start, efiemu_mmap[i].num_pages * 4096,
|
||||
GRUB_MEMORY_NVS, hook_data);
|
||||
break;
|
||||
|
||||
case GRUB_EFI_PERSISTENT_MEMORY:
|
||||
hook (efiemu_mmap[i].physical_start, efiemu_mmap[i].num_pages * 4096,
|
||||
GRUB_MEMORY_PERSISTENT, hook_data);
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -503,7 +522,8 @@ grub_efiemu_mmap_sort_and_uniq (void)
|
||||
[GRUB_EFI_ACPI_MEMORY_NVS] = 3,
|
||||
[GRUB_EFI_MEMORY_MAPPED_IO] = 4,
|
||||
[GRUB_EFI_MEMORY_MAPPED_IO_PORT_SPACE] = 4,
|
||||
[GRUB_EFI_PAL_CODE] = 4
|
||||
[GRUB_EFI_PAL_CODE] = 4,
|
||||
[GRUB_EFI_PERSISTENT_MEMORY] = 4
|
||||
};
|
||||
|
||||
int i, j, k, done;
|
||||
|
||||
@@ -83,10 +83,16 @@ SUFFIX (grub_efiemu_prepare) (struct grub_efiemu_prepare_hook *prepare_hooks,
|
||||
((grub_uint8_t *) grub_efiemu_mm_obtain_request (handle) + off);
|
||||
|
||||
/* Put pointer to the list of configuration tables in system table */
|
||||
grub_efiemu_write_value
|
||||
(&(SUFFIX (grub_efiemu_system_table)->configuration_table), 0,
|
||||
conftable_handle, 0, 1,
|
||||
sizeof (SUFFIX (grub_efiemu_system_table)->configuration_table));
|
||||
err = grub_efiemu_write_value
|
||||
(&(SUFFIX (grub_efiemu_system_table)->configuration_table), 0,
|
||||
conftable_handle, 0, 1,
|
||||
sizeof (SUFFIX (grub_efiemu_system_table)->configuration_table));
|
||||
if (err)
|
||||
{
|
||||
grub_efiemu_unload ();
|
||||
return err;
|
||||
}
|
||||
|
||||
SUFFIX(grub_efiemu_system_table)->num_table_entries = cntconftables;
|
||||
|
||||
/* Fill the list of configuration tables */
|
||||
|
||||
@@ -418,7 +418,7 @@ grub_font_load (const char *filename)
|
||||
#endif
|
||||
|
||||
if (filename[0] == '(' || filename[0] == '/' || filename[0] == '+')
|
||||
file = grub_buffile_open (filename, 1024);
|
||||
file = grub_buffile_open (filename, GRUB_FILE_TYPE_FONT, 1024);
|
||||
else
|
||||
{
|
||||
const char *prefix = grub_env_get ("prefix");
|
||||
@@ -438,7 +438,7 @@ grub_font_load (const char *filename)
|
||||
ptr = grub_stpcpy (ptr, filename);
|
||||
ptr = grub_stpcpy (ptr, ".pf2");
|
||||
*ptr = 0;
|
||||
file = grub_buffile_open (fullname, 1024);
|
||||
file = grub_buffile_open (fullname, GRUB_FILE_TYPE_FONT, 1024);
|
||||
grub_free (fullname);
|
||||
}
|
||||
if (!file)
|
||||
|
||||
@@ -227,11 +227,11 @@ grub_btrfs_read_logical (struct grub_btrfs_data *data,
|
||||
static grub_err_t
|
||||
read_sblock (grub_disk_t disk, struct grub_btrfs_superblock *sb)
|
||||
{
|
||||
struct grub_btrfs_superblock sblock;
|
||||
unsigned i;
|
||||
grub_err_t err = GRUB_ERR_NONE;
|
||||
for (i = 0; i < ARRAY_SIZE (superblock_sectors); i++)
|
||||
{
|
||||
struct grub_btrfs_superblock sblock;
|
||||
/* Don't try additional superblocks beyond device size. */
|
||||
if (i && (grub_le_to_cpu64 (sblock.this_device.size)
|
||||
>> GRUB_DISK_SECTOR_BITS) <= superblock_sectors[i])
|
||||
|
||||
@@ -189,7 +189,11 @@ struct grub_fshelp_node {
|
||||
struct grub_fat_data *data;
|
||||
|
||||
grub_uint8_t attr;
|
||||
grub_ssize_t file_size;
|
||||
#ifndef MODE_EXFAT
|
||||
grub_uint32_t file_size;
|
||||
#else
|
||||
grub_uint64_t file_size;
|
||||
#endif
|
||||
grub_uint32_t file_cluster;
|
||||
grub_uint32_t cur_cluster_num;
|
||||
grub_uint32_t cur_cluster;
|
||||
|
||||
@@ -1308,6 +1308,7 @@ grub_hfs_open (struct grub_file *file, const char *name)
|
||||
if (grub_hfs_find_dir (data, name, &found, GRUB_FSHELP_REG))
|
||||
{
|
||||
grub_free (data);
|
||||
grub_free (found);
|
||||
grub_dl_unref (my_mod);
|
||||
return grub_errno;
|
||||
}
|
||||
|
||||
@@ -750,19 +750,15 @@ grub_iso9660_iterate_dir (grub_fshelp_node_t dir,
|
||||
|
||||
if (dir->data->joliet && !ctx.filename)
|
||||
{
|
||||
char *oldname, *semicolon;
|
||||
char *semicolon;
|
||||
|
||||
oldname = name;
|
||||
ctx.filename = grub_iso9660_convert_string
|
||||
((grub_uint8_t *) oldname, dirent.namelen >> 1);
|
||||
((grub_uint8_t *) name, dirent.namelen >> 1);
|
||||
|
||||
semicolon = grub_strrchr (ctx.filename, ';');
|
||||
if (semicolon)
|
||||
*semicolon = '\0';
|
||||
|
||||
if (ctx.filename_alloc)
|
||||
grub_free (oldname);
|
||||
|
||||
ctx.filename_alloc = 1;
|
||||
}
|
||||
|
||||
|
||||
@@ -104,7 +104,7 @@ decomp_block (struct grub_ntfs_comp *cc, grub_uint8_t *dest)
|
||||
if (tag & 1)
|
||||
{
|
||||
grub_uint32_t i, len, delta, code, lmask, dshift;
|
||||
grub_uint16_t word;
|
||||
grub_uint16_t word = 0;
|
||||
|
||||
if (decomp_get16 (cc, &word))
|
||||
return grub_errno;
|
||||
|
||||
@@ -823,7 +823,12 @@ direct_read (struct grub_squash_data *data,
|
||||
curread = data->blksz - boff;
|
||||
if (curread > len)
|
||||
curread = len;
|
||||
if (!(ino->block_sizes[i]
|
||||
if (!ino->block_sizes[i])
|
||||
{
|
||||
/* Sparse block */
|
||||
grub_memset (buf, '\0', curread);
|
||||
}
|
||||
else if (!(ino->block_sizes[i]
|
||||
& grub_cpu_to_le32_compile_time (SQUASH_BLOCK_UNCOMPRESSED)))
|
||||
{
|
||||
char *block;
|
||||
@@ -873,36 +878,57 @@ direct_read (struct grub_squash_data *data,
|
||||
|
||||
|
||||
static grub_ssize_t
|
||||
grub_squash_read_data (struct grub_squash_data *data,
|
||||
struct grub_squash_cache_inode *ino,
|
||||
grub_off_t off, char *buf, grub_size_t len)
|
||||
grub_squash_read (grub_file_t file, char *buf, grub_size_t len)
|
||||
{
|
||||
struct grub_squash_data *data = file->data;
|
||||
struct grub_squash_cache_inode *ino = &data->ino;
|
||||
grub_off_t off = file->offset;
|
||||
grub_err_t err;
|
||||
grub_uint64_t a = 0, b;
|
||||
grub_uint64_t a, b;
|
||||
grub_uint32_t fragment = 0;
|
||||
int compressed = 0;
|
||||
struct grub_squash_frag_desc frag;
|
||||
grub_off_t direct_len;
|
||||
grub_uint64_t mask = grub_le_to_cpu32 (data->sb.block_size) - 1;
|
||||
grub_size_t orig_len = len;
|
||||
|
||||
switch (ino->ino.type)
|
||||
{
|
||||
case grub_cpu_to_le16_compile_time (SQUASH_TYPE_LONG_REGULAR):
|
||||
a = grub_le_to_cpu64 (ino->ino.long_file.chunk);
|
||||
fragment = grub_le_to_cpu32 (ino->ino.long_file.fragment);
|
||||
break;
|
||||
case grub_cpu_to_le16_compile_time (SQUASH_TYPE_REGULAR):
|
||||
a = grub_le_to_cpu32 (ino->ino.file.chunk);
|
||||
fragment = grub_le_to_cpu32 (ino->ino.file.fragment);
|
||||
break;
|
||||
}
|
||||
|
||||
if (fragment == 0xffffffff)
|
||||
return direct_read (data, ino, off, buf, len);
|
||||
/* Squash may pack file tail as fragment. So read initial part directly and
|
||||
get tail from fragments */
|
||||
direct_len = fragment == 0xffffffff ? file->size : file->size & ~mask;
|
||||
if (off < direct_len)
|
||||
{
|
||||
grub_size_t read_len = direct_len - off;
|
||||
grub_ssize_t res;
|
||||
|
||||
if (read_len > len)
|
||||
read_len = len;
|
||||
res = direct_read (data, ino, off, buf, read_len);
|
||||
if ((grub_size_t) res != read_len)
|
||||
return -1; /* FIXME: is short read possible here? */
|
||||
len -= read_len;
|
||||
if (!len)
|
||||
return read_len;
|
||||
buf += read_len;
|
||||
off = 0;
|
||||
}
|
||||
else
|
||||
off -= direct_len;
|
||||
|
||||
err = read_chunk (data, &frag, sizeof (frag),
|
||||
data->fragments, sizeof (frag) * fragment);
|
||||
if (err)
|
||||
return -1;
|
||||
a += grub_le_to_cpu64 (frag.offset);
|
||||
a = grub_le_to_cpu64 (frag.offset);
|
||||
compressed = !(frag.size & grub_cpu_to_le32_compile_time (SQUASH_BLOCK_UNCOMPRESSED));
|
||||
if (ino->ino.type == grub_cpu_to_le16_compile_time (SQUASH_TYPE_LONG_REGULAR))
|
||||
b = grub_le_to_cpu32 (ino->ino.long_file.offset) + off;
|
||||
@@ -943,16 +969,7 @@ grub_squash_read_data (struct grub_squash_data *data,
|
||||
if (err)
|
||||
return -1;
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
static grub_ssize_t
|
||||
grub_squash_read (grub_file_t file, char *buf, grub_size_t len)
|
||||
{
|
||||
struct grub_squash_data *data = file->data;
|
||||
|
||||
return grub_squash_read_data (data, &data->ino,
|
||||
file->offset, buf, len);
|
||||
return orig_len;
|
||||
}
|
||||
|
||||
static grub_err_t
|
||||
|
||||
@@ -76,8 +76,13 @@ GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
/* incompat feature flags */
|
||||
#define XFS_SB_FEAT_INCOMPAT_FTYPE (1 << 0) /* filetype in dirent */
|
||||
#define XFS_SB_FEAT_INCOMPAT_SPINODES (1 << 1) /* sparse inode chunks */
|
||||
#define XFS_SB_FEAT_INCOMPAT_META_UUID (1 << 2) /* metadata UUID */
|
||||
|
||||
/* We do not currently verify metadata UUID so it is safe to read such filesystem */
|
||||
#define XFS_SB_FEAT_INCOMPAT_SUPPORTED \
|
||||
(XFS_SB_FEAT_INCOMPAT_FTYPE)
|
||||
(XFS_SB_FEAT_INCOMPAT_FTYPE | \
|
||||
XFS_SB_FEAT_INCOMPAT_META_UUID)
|
||||
|
||||
struct grub_xfs_sblock
|
||||
{
|
||||
@@ -775,7 +780,10 @@ grub_xfs_iterate_dir (grub_fshelp_node_t dir,
|
||||
c = de->name[de->len];
|
||||
de->name[de->len] = '\0';
|
||||
if (iterate_dir_call_hook (ino, de->name, &ctx))
|
||||
return 1;
|
||||
{
|
||||
de->name[de->len] = c;
|
||||
return 1;
|
||||
}
|
||||
de->name[de->len] = c;
|
||||
|
||||
de = grub_xfs_inline_next_de(dir->data, head, de);
|
||||
|
||||
@@ -3132,7 +3132,7 @@ make_mdn (dnode_end_t * mdn, struct grub_zfs_data *data)
|
||||
{
|
||||
void *osp;
|
||||
blkptr_t *bp;
|
||||
grub_size_t ospsize;
|
||||
grub_size_t ospsize = 0;
|
||||
grub_err_t err;
|
||||
|
||||
grub_dprintf ("zfs", "endian = %d\n", mdn->endian);
|
||||
|
||||
@@ -184,6 +184,8 @@ LZ4_uncompress_unknownOutputSize(const char *source,
|
||||
}
|
||||
}
|
||||
/* copy literals */
|
||||
if ((grub_addr_t) length > ~(grub_addr_t)op)
|
||||
goto _output_error;
|
||||
cpy = op + length;
|
||||
if ((cpy > oend - COPYLENGTH) ||
|
||||
(ip + length > iend - COPYLENGTH)) {
|
||||
|
||||
@@ -425,7 +425,7 @@ grub_cmd_zfs_key (grub_extcmd_context_t ctxt, int argc, char **args)
|
||||
if (argc > 0)
|
||||
{
|
||||
grub_file_t file;
|
||||
file = grub_file_open (args[0]);
|
||||
file = grub_file_open (args[0], GRUB_FILE_TYPE_ZFS_ENCRYPTION_KEY);
|
||||
if (!file)
|
||||
return grub_errno;
|
||||
real_size = grub_file_read (file, buf, 1024);
|
||||
|
||||
@@ -336,6 +336,7 @@ grub_gdb_trap (int trap_no)
|
||||
/* sAA..AA: Step one instruction from AA..AA(optional). */
|
||||
case 's':
|
||||
stepping = 1;
|
||||
/* FALLTHROUGH */
|
||||
|
||||
/* cAA..AA: Continue at address AA..AA(optional). */
|
||||
case 'c':
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#! /bin/sh
|
||||
#! @BUILD_SHEBANG@
|
||||
set -e
|
||||
|
||||
# Copyright (C) 2010 Free Software Foundation, Inc.
|
||||
@@ -94,6 +94,6 @@ else
|
||||
rm -f $tmpfile.bin
|
||||
fi
|
||||
if test x@platform@ != xemu; then
|
||||
./build-grub-module-verifier@BUILD_EXEEXT@ $tmpfile @target_cpu@
|
||||
./build-grub-module-verifier@BUILD_EXEEXT@ $tmpfile @target_cpu@ @platform@
|
||||
fi
|
||||
mv $tmpfile $outfile
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#! /bin/sh
|
||||
#! @BUILD_SHEBANG@
|
||||
set -e
|
||||
|
||||
# Copyright (C) 2010 Free Software Foundation, Inc.
|
||||
|
||||
@@ -291,7 +291,7 @@ grub_mofile_open (struct grub_gettext_context *ctx,
|
||||
/* Using fd_mo and not another variable because
|
||||
it's needed for grub_gettext_get_info. */
|
||||
|
||||
fd = grub_file_open (filename);
|
||||
fd = grub_file_open (filename, GRUB_FILE_TYPE_GETTEXT_CATALOG);
|
||||
|
||||
if (!fd)
|
||||
return grub_errno;
|
||||
|
||||
@@ -45,6 +45,7 @@ grub_font_draw_string (const char *str, grub_font_t font,
|
||||
grub_uint32_t *logical;
|
||||
grub_ssize_t logical_len, visual_len;
|
||||
struct grub_unicode_glyph *visual, *ptr;
|
||||
grub_err_t err;
|
||||
|
||||
logical_len = grub_utf8_to_ucs4_alloc (str, &logical, 0);
|
||||
if (logical_len < 0)
|
||||
@@ -56,24 +57,28 @@ grub_font_draw_string (const char *str, grub_font_t font,
|
||||
if (visual_len < 0)
|
||||
return grub_errno;
|
||||
|
||||
err = GRUB_ERR_NONE;
|
||||
for (ptr = visual, x = left_x; ptr < visual + visual_len; ptr++)
|
||||
{
|
||||
grub_err_t err;
|
||||
struct grub_font_glyph *glyph;
|
||||
glyph = grub_font_construct_glyph (font, ptr);
|
||||
if (!glyph)
|
||||
return grub_errno;
|
||||
{
|
||||
err = grub_errno;
|
||||
goto out;
|
||||
}
|
||||
err = grub_font_draw_glyph (glyph, color, x, baseline_y);
|
||||
x += glyph->device_width;
|
||||
if (err)
|
||||
return err;
|
||||
goto out;
|
||||
x += glyph->device_width;
|
||||
}
|
||||
|
||||
out:
|
||||
for (ptr = visual; ptr < visual + visual_len; ptr++)
|
||||
grub_unicode_destroy_glyph (ptr);
|
||||
grub_free (visual);
|
||||
|
||||
return GRUB_ERR_NONE;
|
||||
return err;
|
||||
}
|
||||
|
||||
/* Get the width in pixels of the specified UTF-8 string, when rendered in
|
||||
|
||||
@@ -63,14 +63,14 @@ grub_gfxmenu_try (int entry, grub_menu_t menu, int nested)
|
||||
return grub_error (GRUB_ERR_FILE_NOT_FOUND, N_("variable `%s' isn't set"),
|
||||
"theme");
|
||||
|
||||
instance = grub_zalloc (sizeof (*instance));
|
||||
if (!instance)
|
||||
return grub_errno;
|
||||
|
||||
err = grub_video_get_info (&mode_info);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
instance = grub_zalloc (sizeof (*instance));
|
||||
if (!instance)
|
||||
return grub_errno;
|
||||
|
||||
if (theme_path[0] != '/' && theme_path[0] != '(')
|
||||
{
|
||||
const char *prefix;
|
||||
|
||||
@@ -743,7 +743,7 @@ grub_gfxmenu_view_load_theme (grub_gfxmenu_view_t view, const char *theme_path)
|
||||
p.view = view;
|
||||
p.theme_dir = grub_get_dirname (theme_path);
|
||||
|
||||
file = grub_file_open (theme_path);
|
||||
file = grub_file_open (theme_path, GRUB_FILE_TYPE_THEME);
|
||||
if (! file)
|
||||
{
|
||||
grub_free (p.theme_dir);
|
||||
|
||||
14
grub-core/gnulib-fix-gcc7-fallthrough.diff
Normal file
14
grub-core/gnulib-fix-gcc7-fallthrough.diff
Normal file
@@ -0,0 +1,14 @@
|
||||
diff --git grub-core/gnulib/regexec.c grub-core/gnulib/regexec.c
|
||||
index f632cd4..a7776f0 100644
|
||||
--- grub-core/gnulib/regexec.c
|
||||
+++ grub-core/gnulib/regexec.c
|
||||
@@ -4099,6 +4099,9 @@ check_node_accept (const re_match_context_t *mctx, const re_token_t *node,
|
||||
case OP_UTF8_PERIOD:
|
||||
if (ch >= ASCII_CHARS)
|
||||
return false;
|
||||
+#if defined __GNUC__ && __GNUC__ >= 7
|
||||
+ __attribute__ ((fallthrough));
|
||||
+#endif
|
||||
/* FALLTHROUGH */
|
||||
#endif
|
||||
case OP_PERIOD:
|
||||
@@ -4099,6 +4099,9 @@ check_node_accept (const re_match_context_t *mctx, const re_token_t *node,
|
||||
case OP_UTF8_PERIOD:
|
||||
if (ch >= ASCII_CHARS)
|
||||
return false;
|
||||
#if defined __GNUC__ && __GNUC__ >= 7
|
||||
__attribute__ ((fallthrough));
|
||||
#endif
|
||||
/* FALLTHROUGH */
|
||||
#endif
|
||||
case OP_PERIOD:
|
||||
|
||||
@@ -43,7 +43,8 @@ typedef struct grub_bufio *grub_bufio_t;
|
||||
static struct grub_fs grub_bufio_fs;
|
||||
|
||||
grub_file_t
|
||||
grub_bufio_open (grub_file_t io, int size)
|
||||
grub_bufio_open (grub_file_t io,
|
||||
grub_size_t size)
|
||||
{
|
||||
grub_file_t file;
|
||||
grub_bufio_t bufio = 0;
|
||||
@@ -57,7 +58,7 @@ grub_bufio_open (grub_file_t io, int size)
|
||||
else if (size > GRUB_BUFIO_MAX_SIZE)
|
||||
size = GRUB_BUFIO_MAX_SIZE;
|
||||
|
||||
if ((size < 0) || ((unsigned) size > io->size))
|
||||
if (size > io->size)
|
||||
size = ((io->size > GRUB_BUFIO_MAX_SIZE) ? GRUB_BUFIO_MAX_SIZE :
|
||||
io->size);
|
||||
|
||||
@@ -81,11 +82,12 @@ grub_bufio_open (grub_file_t io, int size)
|
||||
}
|
||||
|
||||
grub_file_t
|
||||
grub_buffile_open (const char *name, int size)
|
||||
grub_buffile_open (const char *name, enum grub_file_type type,
|
||||
grub_size_t size)
|
||||
{
|
||||
grub_file_t io, file;
|
||||
|
||||
io = grub_file_open (name);
|
||||
io = grub_file_open (name, type);
|
||||
if (! io)
|
||||
return 0;
|
||||
|
||||
|
||||
@@ -1125,11 +1125,14 @@ initialize_tables (grub_gzio_t gzio)
|
||||
even if IO does not contain data compressed by gzip, return a valid file
|
||||
object. Note that this function won't close IO, even if an error occurs. */
|
||||
static grub_file_t
|
||||
grub_gzio_open (grub_file_t io, const char *name __attribute__ ((unused)))
|
||||
grub_gzio_open (grub_file_t io, enum grub_file_type type)
|
||||
{
|
||||
grub_file_t file;
|
||||
grub_gzio_t gzio = 0;
|
||||
|
||||
if (type & GRUB_FILE_TYPE_NO_DECOMPRESS)
|
||||
return io;
|
||||
|
||||
file = (grub_file_t) grub_zalloc (sizeof (*file));
|
||||
if (! file)
|
||||
return 0;
|
||||
|
||||
@@ -407,12 +407,14 @@ CORRUPTED:
|
||||
}
|
||||
|
||||
static grub_file_t
|
||||
grub_lzopio_open (grub_file_t io,
|
||||
const char *name __attribute__ ((unused)))
|
||||
grub_lzopio_open (grub_file_t io, enum grub_file_type type)
|
||||
{
|
||||
grub_file_t file;
|
||||
grub_lzopio_t lzopio;
|
||||
|
||||
if (type & GRUB_FILE_TYPE_NO_DECOMPRESS)
|
||||
return io;
|
||||
|
||||
file = (grub_file_t) grub_zalloc (sizeof (*file));
|
||||
if (!file)
|
||||
return 0;
|
||||
|
||||
@@ -69,7 +69,8 @@ grub_file_offset_close (grub_file_t file)
|
||||
}
|
||||
|
||||
grub_file_t
|
||||
grub_file_offset_open (grub_file_t parent, grub_off_t start, grub_off_t size)
|
||||
grub_file_offset_open (grub_file_t parent, enum grub_file_type type,
|
||||
grub_off_t start, grub_off_t size)
|
||||
{
|
||||
struct grub_offset_file *off_data;
|
||||
grub_file_t off_file, last_off_file;
|
||||
@@ -95,10 +96,10 @@ grub_file_offset_open (grub_file_t parent, grub_off_t start, grub_off_t size)
|
||||
last_off_file = NULL;
|
||||
for (filter = GRUB_FILE_FILTER_COMPRESSION_FIRST;
|
||||
off_file && filter <= GRUB_FILE_FILTER_COMPRESSION_LAST; filter++)
|
||||
if (grub_file_filters_enabled[filter])
|
||||
if (grub_file_filters[filter])
|
||||
{
|
||||
last_off_file = off_file;
|
||||
off_file = grub_file_filters_enabled[filter] (off_file, parent->name);
|
||||
off_file = grub_file_filters[filter] (off_file, type);
|
||||
}
|
||||
|
||||
if (!off_file)
|
||||
|
||||
@@ -169,12 +169,14 @@ ERROR:
|
||||
}
|
||||
|
||||
static grub_file_t
|
||||
grub_xzio_open (grub_file_t io,
|
||||
const char *name __attribute__ ((unused)))
|
||||
grub_xzio_open (grub_file_t io, enum grub_file_type type)
|
||||
{
|
||||
grub_file_t file;
|
||||
grub_xzio_t xzio;
|
||||
|
||||
if (type & GRUB_FILE_TYPE_NO_DECOMPRESS)
|
||||
return io;
|
||||
|
||||
file = (grub_file_t) grub_zalloc (sizeof (*file));
|
||||
if (!file)
|
||||
return 0;
|
||||
|
||||
@@ -32,3 +32,88 @@ grub_byte_checksum (void *base, grub_size_t size)
|
||||
ret += *ptr;
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void *
|
||||
grub_acpi_rsdt_find_table (struct grub_acpi_table_header *rsdt, const char *sig)
|
||||
{
|
||||
grub_size_t s;
|
||||
grub_unaligned_uint32_t *ptr;
|
||||
|
||||
if (!rsdt)
|
||||
return 0;
|
||||
|
||||
if (grub_memcmp (rsdt->signature, "RSDT", 4) != 0)
|
||||
return 0;
|
||||
|
||||
ptr = (grub_unaligned_uint32_t *) (rsdt + 1);
|
||||
s = (rsdt->length - sizeof (*rsdt)) / sizeof (grub_uint32_t);
|
||||
for (; s; s--, ptr++)
|
||||
{
|
||||
struct grub_acpi_table_header *tbl;
|
||||
tbl = (struct grub_acpi_table_header *) (grub_addr_t) ptr->val;
|
||||
if (grub_memcmp (tbl->signature, sig, 4) == 0)
|
||||
return tbl;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void *
|
||||
grub_acpi_xsdt_find_table (struct grub_acpi_table_header *xsdt, const char *sig)
|
||||
{
|
||||
grub_size_t s;
|
||||
grub_unaligned_uint64_t *ptr;
|
||||
|
||||
if (!xsdt)
|
||||
return 0;
|
||||
|
||||
if (grub_memcmp (xsdt->signature, "XSDT", 4) != 0)
|
||||
return 0;
|
||||
|
||||
ptr = (grub_unaligned_uint64_t *) (xsdt + 1);
|
||||
s = (xsdt->length - sizeof (*xsdt)) / sizeof (grub_uint32_t);
|
||||
for (; s; s--, ptr++)
|
||||
{
|
||||
struct grub_acpi_table_header *tbl;
|
||||
#if GRUB_CPU_SIZEOF_VOID_P != 8
|
||||
if (ptr->val >> 32)
|
||||
continue;
|
||||
#endif
|
||||
tbl = (struct grub_acpi_table_header *) (grub_addr_t) ptr->val;
|
||||
if (grub_memcmp (tbl->signature, sig, 4) == 0)
|
||||
return tbl;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct grub_acpi_fadt *
|
||||
grub_acpi_find_fadt (void)
|
||||
{
|
||||
struct grub_acpi_fadt *fadt = 0;
|
||||
struct grub_acpi_rsdp_v10 *rsdpv1;
|
||||
struct grub_acpi_rsdp_v20 *rsdpv2;
|
||||
rsdpv1 = grub_machine_acpi_get_rsdpv1 ();
|
||||
if (rsdpv1)
|
||||
fadt = grub_acpi_rsdt_find_table ((struct grub_acpi_table_header *)
|
||||
(grub_addr_t) rsdpv1->rsdt_addr,
|
||||
GRUB_ACPI_FADT_SIGNATURE);
|
||||
if (fadt)
|
||||
return fadt;
|
||||
rsdpv2 = grub_machine_acpi_get_rsdpv2 ();
|
||||
if (rsdpv2)
|
||||
fadt = grub_acpi_rsdt_find_table ((struct grub_acpi_table_header *)
|
||||
(grub_addr_t) rsdpv2->rsdpv1.rsdt_addr,
|
||||
GRUB_ACPI_FADT_SIGNATURE);
|
||||
if (fadt)
|
||||
return fadt;
|
||||
if (rsdpv2
|
||||
#if GRUB_CPU_SIZEOF_VOID_P != 8
|
||||
&& !(rsdpv2->xsdt_addr >> 32)
|
||||
#endif
|
||||
)
|
||||
fadt = grub_acpi_xsdt_find_table ((struct grub_acpi_table_header *)
|
||||
(grub_addr_t) rsdpv2->xsdt_addr,
|
||||
GRUB_ACPI_FADT_SIGNATURE);
|
||||
if (fadt)
|
||||
return fadt;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -29,6 +29,8 @@ void grub_arm_clean_dcache_range_armv6 (grub_addr_t start, grub_addr_t end,
|
||||
grub_addr_t dlinesz);
|
||||
void grub_arm_clean_dcache_range_armv7 (grub_addr_t start, grub_addr_t end,
|
||||
grub_addr_t dlinesz);
|
||||
void grub_arm_clean_dcache_range_poc_armv7 (grub_addr_t start, grub_addr_t end,
|
||||
grub_addr_t dlinesz);
|
||||
void grub_arm_invalidate_icache_range_armv6 (grub_addr_t start, grub_addr_t end,
|
||||
grub_addr_t dlinesz);
|
||||
void grub_arm_invalidate_icache_range_armv7 (grub_addr_t start, grub_addr_t end,
|
||||
@@ -252,6 +254,38 @@ grub_arch_sync_caches (void *address, grub_size_t len)
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
grub_arch_sync_dma_caches (volatile void *address, grub_size_t len)
|
||||
{
|
||||
grub_addr_t start = (grub_addr_t) address;
|
||||
grub_addr_t end = start + len;
|
||||
|
||||
if (type == ARCH_UNKNOWN)
|
||||
probe_caches ();
|
||||
start = ALIGN_DOWN (start, grub_arch_cache_max_linesz);
|
||||
end = ALIGN_UP (end, grub_arch_cache_max_linesz);
|
||||
switch (type)
|
||||
{
|
||||
case ARCH_ARMV6:
|
||||
grub_arm_clean_dcache_range_armv6 (start, end, grub_arch_cache_dlinesz);
|
||||
grub_arm_invalidate_icache_range_armv6 (start, end,
|
||||
grub_arch_cache_ilinesz);
|
||||
break;
|
||||
case ARCH_ARMV5_WRITE_THROUGH:
|
||||
case ARCH_ARMV6_UNIFIED:
|
||||
grub_arm_clean_dcache_range_armv6 (start, end, grub_arch_cache_dlinesz);
|
||||
break;
|
||||
case ARCH_ARMV7:
|
||||
grub_arm_clean_dcache_range_poc_armv7 (start, end, grub_arch_cache_dlinesz);
|
||||
grub_arm_invalidate_icache_range_armv7 (start, end,
|
||||
grub_arch_cache_ilinesz);
|
||||
break;
|
||||
/* Pacify GCC. */
|
||||
case ARCH_UNKNOWN:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
grub_arm_disable_caches_mmu (void)
|
||||
{
|
||||
|
||||
@@ -33,6 +33,18 @@
|
||||
# define ISB isb
|
||||
#define ARMV7 1
|
||||
|
||||
FUNCTION(grub_arm_clean_dcache_range_poc_armv7)
|
||||
DSB
|
||||
@ Clean data cache for range to point-of-coherence
|
||||
1: cmp r0, r1
|
||||
bge 2f
|
||||
mcr p15, 0, r0, c7, c14, 1 @ DCCMVAC
|
||||
add r0, r0, r2 @ Next line
|
||||
b 1b
|
||||
2: DSB
|
||||
bx lr
|
||||
|
||||
|
||||
@ r0 - CLIDR
|
||||
@ r1 - LoC
|
||||
@ r2 - current level
|
||||
|
||||
40
grub-core/kern/arm/coreboot/cbtable.c
Normal file
40
grub-core/kern/arm/coreboot/cbtable.c
Normal file
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 2007,2008,2013 Free Software Foundation, Inc.
|
||||
*
|
||||
* GRUB is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* GRUB is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <grub/coreboot/lbio.h>
|
||||
#include <grub/types.h>
|
||||
#include <grub/err.h>
|
||||
#include <grub/misc.h>
|
||||
#include <grub/dl.h>
|
||||
#include <grub/arm/startup.h>
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
#pragma GCC diagnostic ignored "-Wcast-align"
|
||||
|
||||
grub_linuxbios_table_header_t
|
||||
grub_linuxbios_get_tables (void)
|
||||
{
|
||||
grub_linuxbios_table_header_t table_header
|
||||
= (grub_linuxbios_table_header_t) grub_arm_saved_registers.r[0];
|
||||
|
||||
if (!grub_linuxbios_check_signature (table_header))
|
||||
return 0;
|
||||
|
||||
return table_header;
|
||||
}
|
||||
44
grub-core/kern/arm/coreboot/coreboot.S
Normal file
44
grub-core/kern/arm/coreboot/coreboot.S
Normal file
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 2016 Free Software Foundation, Inc.
|
||||
*
|
||||
* GRUB is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* GRUB is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <grub/symbol.h>
|
||||
|
||||
.file "coreboot.S"
|
||||
.text
|
||||
.syntax unified
|
||||
#if !defined (__thumb2__)
|
||||
.arch armv7a
|
||||
.arm
|
||||
#else
|
||||
.arch armv7
|
||||
.thumb
|
||||
#endif
|
||||
|
||||
FUNCTION(grub_arm_pfr1)
|
||||
mrc p15, 0, r0, c0, c1, 1
|
||||
bx lr
|
||||
|
||||
FUNCTION(grub_armv7_get_timer_value)
|
||||
isb
|
||||
mrrc p15, 1, r0, r1, c14
|
||||
bx lr
|
||||
|
||||
FUNCTION(grub_armv7_get_timer_frequency)
|
||||
mrc p15, 0, r0, c14, c0, 0
|
||||
bx lr
|
||||
|
||||
59
grub-core/kern/arm/coreboot/dma.c
Normal file
59
grub-core/kern/arm/coreboot/dma.c
Normal file
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 2007,2009 Free Software Foundation, Inc.
|
||||
*
|
||||
* GRUB is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* GRUB is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <grub/dl.h>
|
||||
#include <grub/dma.h>
|
||||
#include <grub/mm.h>
|
||||
#include <grub/misc.h>
|
||||
#include <grub/mm_private.h>
|
||||
#include <grub/cache.h>
|
||||
|
||||
struct grub_pci_dma_chunk *
|
||||
grub_memalign_dma32 (grub_size_t align, grub_size_t size)
|
||||
{
|
||||
void *ret;
|
||||
if (align < 64)
|
||||
align = 64;
|
||||
size = ALIGN_UP (size, align);
|
||||
ret = grub_memalign (align, size);
|
||||
if (!ret)
|
||||
return 0;
|
||||
grub_arch_sync_dma_caches (ret, size);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void
|
||||
grub_dma_free (struct grub_pci_dma_chunk *ch)
|
||||
{
|
||||
grub_size_t size = (((struct grub_mm_header *) ch) - 1)->size * GRUB_MM_ALIGN;
|
||||
grub_arch_sync_dma_caches (ch, size);
|
||||
grub_free (ch);
|
||||
}
|
||||
|
||||
volatile void *
|
||||
grub_dma_get_virt (struct grub_pci_dma_chunk *ch)
|
||||
{
|
||||
return (void *) ch;
|
||||
}
|
||||
|
||||
grub_uint32_t
|
||||
grub_dma_get_phys (struct grub_pci_dma_chunk *ch)
|
||||
{
|
||||
return (grub_uint32_t) (grub_addr_t) ch;
|
||||
}
|
||||
|
||||
151
grub-core/kern/arm/coreboot/init.c
Normal file
151
grub-core/kern/arm/coreboot/init.c
Normal file
@@ -0,0 +1,151 @@
|
||||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 2002,2003,2004,2005,2006,2007,2008,2009,2013 Free Software Foundation, Inc.
|
||||
*
|
||||
* GRUB is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* GRUB is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <grub/kernel.h>
|
||||
#include <grub/mm.h>
|
||||
#include <grub/memory.h>
|
||||
#include <grub/machine/console.h>
|
||||
#include <grub/machine/kernel.h>
|
||||
#include <grub/offsets.h>
|
||||
#include <grub/types.h>
|
||||
#include <grub/err.h>
|
||||
#include <grub/dl.h>
|
||||
#include <grub/misc.h>
|
||||
#include <grub/loader.h>
|
||||
#include <grub/env.h>
|
||||
#include <grub/cache.h>
|
||||
#include <grub/time.h>
|
||||
#include <grub/symbol.h>
|
||||
#include <grub/video.h>
|
||||
#include <grub/coreboot/lbio.h>
|
||||
#include <grub/fdtbus.h>
|
||||
|
||||
extern grub_uint8_t _start[];
|
||||
extern grub_uint8_t _end[];
|
||||
extern grub_uint8_t _edata[];
|
||||
grub_addr_t start_of_ram = ~(grub_addr_t)0;
|
||||
|
||||
void __attribute__ ((noreturn))
|
||||
grub_exit (void)
|
||||
{
|
||||
/* We can't use grub_fatal() in this function. This would create an infinite
|
||||
loop, since grub_fatal() calls grub_abort() which in turn calls grub_exit(). */
|
||||
while (1)
|
||||
grub_cpu_idle ();
|
||||
}
|
||||
|
||||
static grub_uint64_t modend;
|
||||
static int have_memory = 0;
|
||||
|
||||
/* Helper for grub_machine_init. */
|
||||
static int
|
||||
heap_init (grub_uint64_t addr, grub_uint64_t size, grub_memory_type_t type,
|
||||
void *data __attribute__ ((unused)))
|
||||
{
|
||||
grub_uint64_t begin = addr, end = addr + size;
|
||||
|
||||
#if GRUB_CPU_SIZEOF_VOID_P == 4
|
||||
/* Restrict ourselves to 32-bit memory space. */
|
||||
if (begin > GRUB_ULONG_MAX)
|
||||
return 0;
|
||||
if (end > GRUB_ULONG_MAX)
|
||||
end = GRUB_ULONG_MAX;
|
||||
#endif
|
||||
|
||||
if (start_of_ram > begin)
|
||||
start_of_ram = begin;
|
||||
|
||||
if (type != GRUB_MEMORY_AVAILABLE)
|
||||
return 0;
|
||||
|
||||
if (modend && begin < modend)
|
||||
{
|
||||
if (begin < (grub_addr_t)_start)
|
||||
{
|
||||
grub_mm_init_region ((void *) (grub_addr_t) begin, (grub_size_t) ((grub_addr_t)_start - begin));
|
||||
have_memory = 1;
|
||||
}
|
||||
begin = modend;
|
||||
}
|
||||
|
||||
/* Avoid DMA problems. */
|
||||
if (end >= 0xfe000000)
|
||||
end = 0xfe000000;
|
||||
|
||||
if (end <= begin)
|
||||
return 0;
|
||||
|
||||
grub_mm_init_region ((void *) (grub_addr_t) begin, (grub_size_t) (end - begin));
|
||||
|
||||
have_memory = 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
grub_machine_init (void)
|
||||
{
|
||||
struct grub_module_header *header;
|
||||
void *dtb = 0;
|
||||
grub_size_t dtb_size = 0;
|
||||
|
||||
modend = grub_modules_get_end ();
|
||||
|
||||
grub_video_coreboot_fb_early_init ();
|
||||
|
||||
grub_machine_mmap_iterate (heap_init, NULL);
|
||||
if (!have_memory)
|
||||
grub_fatal ("No memory found");
|
||||
|
||||
grub_video_coreboot_fb_late_init ();
|
||||
|
||||
grub_font_init ();
|
||||
grub_gfxterm_init ();
|
||||
|
||||
FOR_MODULES (header)
|
||||
if (header->type == OBJ_TYPE_DTB)
|
||||
{
|
||||
char *dtb_orig_addr, *dtb_copy;
|
||||
dtb_orig_addr = (char *) header + sizeof (struct grub_module_header);
|
||||
|
||||
dtb_size = header->size - sizeof (struct grub_module_header);
|
||||
dtb = dtb_copy = grub_malloc (dtb_size);
|
||||
grub_memmove (dtb_copy, dtb_orig_addr, dtb_size);
|
||||
break;
|
||||
}
|
||||
if (!dtb)
|
||||
grub_fatal ("No DTB found");
|
||||
grub_fdtbus_init (dtb, dtb_size);
|
||||
|
||||
grub_rk3288_spi_init ();
|
||||
|
||||
grub_machine_timer_init ();
|
||||
grub_cros_init ();
|
||||
grub_pl050_init ();
|
||||
}
|
||||
|
||||
void
|
||||
grub_machine_get_bootlocation (char **device __attribute__ ((unused)),
|
||||
char **path __attribute__ ((unused)))
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
grub_machine_fini (int flags __attribute__ ((unused)))
|
||||
{
|
||||
}
|
||||
101
grub-core/kern/arm/coreboot/timer.c
Normal file
101
grub-core/kern/arm/coreboot/timer.c
Normal file
@@ -0,0 +1,101 @@
|
||||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 2016 Free Software Foundation, Inc.
|
||||
*
|
||||
* GRUB is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* GRUB is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <grub/mm.h>
|
||||
#include <grub/machine/kernel.h>
|
||||
#include <grub/types.h>
|
||||
#include <grub/err.h>
|
||||
#include <grub/time.h>
|
||||
#include <grub/fdtbus.h>
|
||||
#include <grub/misc.h>
|
||||
|
||||
grub_uint64_t
|
||||
grub_armv7_get_timer_value(void);
|
||||
|
||||
grub_uint32_t
|
||||
grub_armv7_get_timer_frequency(void);
|
||||
|
||||
grub_uint32_t
|
||||
grub_arm_pfr1(void);
|
||||
|
||||
static int have_timer = 0;
|
||||
static volatile grub_uint32_t *sp804_regs;
|
||||
|
||||
static grub_uint64_t
|
||||
sp804_get_time_ms (void)
|
||||
{
|
||||
static grub_uint32_t high, last_low;
|
||||
grub_uint32_t low = ~sp804_regs[1];
|
||||
if (last_low > low)
|
||||
high++;
|
||||
last_low = low;
|
||||
return grub_divmod64 ((((grub_uint64_t) high) << 32) | low,
|
||||
1000, 0);
|
||||
}
|
||||
|
||||
static grub_err_t
|
||||
sp804_attach(const struct grub_fdtbus_dev *dev)
|
||||
{
|
||||
if (have_timer)
|
||||
return GRUB_ERR_NONE;
|
||||
sp804_regs = grub_fdtbus_map_reg (dev, 0, 0);
|
||||
if (!grub_fdtbus_is_mapping_valid (sp804_regs))
|
||||
return grub_error (GRUB_ERR_IO, "could not map sp804: %p", sp804_regs);
|
||||
grub_install_get_time_ms (sp804_get_time_ms);
|
||||
have_timer = 1;
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
struct grub_fdtbus_driver sp804 =
|
||||
{
|
||||
.compatible = "arm,sp804",
|
||||
.attach = sp804_attach
|
||||
};
|
||||
|
||||
static grub_uint32_t timer_frequency_in_khz;
|
||||
|
||||
static grub_uint64_t
|
||||
generic_get_time_ms (void)
|
||||
{
|
||||
return grub_divmod64 (grub_armv7_get_timer_value(), timer_frequency_in_khz, 0);
|
||||
}
|
||||
|
||||
static int
|
||||
try_generic_timer (void)
|
||||
{
|
||||
if (((grub_arm_pfr1 () >> 16) & 0xf) != 1)
|
||||
return 0;
|
||||
grub_printf ("freq = %x\n", grub_armv7_get_timer_frequency());
|
||||
timer_frequency_in_khz = 0x016e3600 / 1000; //grub_armv7_get_timer_frequency() / 1000;
|
||||
if (timer_frequency_in_khz == 0)
|
||||
return 0;
|
||||
grub_install_get_time_ms (generic_get_time_ms);
|
||||
have_timer = 1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
void
|
||||
grub_machine_timer_init (void)
|
||||
{
|
||||
grub_fdtbus_register (&sp804);
|
||||
|
||||
if (!have_timer)
|
||||
try_generic_timer ();
|
||||
if (!have_timer)
|
||||
grub_fatal ("No timer found");
|
||||
}
|
||||
@@ -173,6 +173,8 @@ grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr,
|
||||
sym_addr += grub_arm_thm_call_get_offset ((grub_uint16_t *) target);
|
||||
|
||||
grub_dprintf ("dl", " sym_addr = 0x%08x\n", sym_addr);
|
||||
if (ELF_ST_TYPE (sym->st_info) != STT_FUNC)
|
||||
sym_addr |= 1;
|
||||
|
||||
offset = sym_addr - (grub_uint32_t) target;
|
||||
|
||||
@@ -227,13 +229,16 @@ grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr,
|
||||
|
||||
sym_addr += grub_arm_thm_jump19_get_offset ((grub_uint16_t *) target);
|
||||
|
||||
if (ELF_ST_TYPE (sym->st_info) != STT_FUNC)
|
||||
sym_addr |= 1;
|
||||
|
||||
offset = sym_addr - (grub_uint32_t) target;
|
||||
|
||||
if (!grub_arm_thm_jump19_check_offset (offset)
|
||||
|| !(sym_addr & 1))
|
||||
{
|
||||
struct trampoline_thumb *tp = mod->gotptr;
|
||||
mod->gotptr = tp + 1;
|
||||
struct trampoline_thumb *tp = mod->trampptr;
|
||||
mod->trampptr = tp + 1;
|
||||
grub_memcpy (tp->template, thumb_template, sizeof (tp->template));
|
||||
tp->neg_addr = -sym_addr - 4;
|
||||
offset = ((grub_uint8_t *) tp - (grub_uint8_t *) target - 4) | 1;
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
* GRUB is called from U-Boot as a Linux Kernel type image, which
|
||||
* means among other things that it always enters in ARM state.
|
||||
*
|
||||
* coreboot starts in ARM mode as well.
|
||||
*
|
||||
* Overview of GRUB image layout:
|
||||
*
|
||||
@@ -55,10 +56,6 @@ FUNCTION(_start)
|
||||
VARIABLE(grub_total_module_size)
|
||||
.long 0
|
||||
|
||||
VARIABLE(grub_uboot_machine_type)
|
||||
.long 0
|
||||
VARIABLE(grub_uboot_boot_data)
|
||||
.long 0
|
||||
VARIABLE(grub_modbase)
|
||||
.long 0
|
||||
bss_start_ptr:
|
||||
@@ -66,34 +63,73 @@ bss_start_ptr:
|
||||
end_ptr:
|
||||
.long EXT_C(_end)
|
||||
|
||||
@ Memory map at start:
|
||||
@ * text+data
|
||||
@ * list relocations
|
||||
@ * modules
|
||||
@ Before we enter C, we need to apply the relocations
|
||||
@ and get following map:
|
||||
@ * text+data
|
||||
@ * BSS (cleared)
|
||||
@ * stack
|
||||
@ * modules
|
||||
@
|
||||
@ To make things easier we ensure
|
||||
@ that BSS+stack is larger than list of relocations
|
||||
@ by increasing stack if necessarry.
|
||||
@ This allows us to always unconditionally copy backwards
|
||||
@ Currently list of relocations is ~5K and stack is set
|
||||
@ to be at least 256K
|
||||
|
||||
FUNCTION(codestart)
|
||||
@ Store context: Machine ID, atags/dtb, ...
|
||||
@ U-Boot API signature is stored on the U-Boot heap
|
||||
@ Stack pointer used as start address for signature probing
|
||||
mov r12, sp
|
||||
adr sp, entry_state
|
||||
push {r4-r12,lr} @ store U-Boot context (sp in r12)
|
||||
push {r0-r12,lr} @ store U-Boot context (sp in r12)
|
||||
|
||||
str r1, EXT_C(grub_uboot_machine_type)
|
||||
str r2, EXT_C(grub_uboot_boot_data)
|
||||
|
||||
@ Modules have been stored as a blob in BSS,
|
||||
@ they need to be manually relocated to _end
|
||||
adr r1, _start
|
||||
ldr r0, bss_start_ptr @ src
|
||||
add r0, r0, r1
|
||||
|
||||
add r0, r0, #(GRUB_KERNEL_MACHINE_MOD_ALIGN - 1)
|
||||
mvn r2, #(GRUB_KERNEL_MACHINE_MOD_ALIGN - 1)
|
||||
and r0, r0, r2
|
||||
1:
|
||||
ldr r3, [r0], #4 @load next offset
|
||||
@ both -2 and -1 are treated the same as we have only one type of relocs
|
||||
@ -2 means "end of this type of relocs" and -1 means "end of all relocs"
|
||||
add r2, r3, #2
|
||||
cmp r2, #1
|
||||
bls reloc_done
|
||||
@ Adjust next offset
|
||||
ldr r2, [r3, r1]
|
||||
add r2, r2, r1
|
||||
str r2, [r3, r1]
|
||||
b 1b
|
||||
|
||||
reloc_done:
|
||||
|
||||
@ Modules have been stored as a blob
|
||||
@ they need to be manually relocated to _end
|
||||
add r0, r0, #(GRUB_KERNEL_MACHINE_MOD_ALIGN - 1)
|
||||
mvn r1, #(GRUB_KERNEL_MACHINE_MOD_ALIGN - 1)
|
||||
and r0, r0, r1
|
||||
and r0, r0, r1 @ src = aligned end of relocations
|
||||
|
||||
ldr r1, end_ptr @ dst = End of BSS
|
||||
ldr r2, grub_total_module_size @ blob size
|
||||
|
||||
add r1, r1, #GRUB_KERNEL_MACHINE_STACK_SIZE
|
||||
and r1, r1, #~0x7 @ Ensure 8-byte alignment
|
||||
|
||||
sub sp, r1, #8
|
||||
add r1, r1, #1024
|
||||
|
||||
str r1, EXT_C(grub_modbase)
|
||||
|
||||
/* Coreboot already places modules at right place. */
|
||||
#ifndef GRUB_MACHINE_COREBOOT
|
||||
add r1, r1, r2
|
||||
add r0, r0, r2
|
||||
sub r1, r1, #4
|
||||
@@ -103,6 +139,7 @@ FUNCTION(codestart)
|
||||
str r3, [r1], #-4 @ *dst-- = r3
|
||||
subs r2, #4 @ remaining -= 4
|
||||
bne 1b @ while remaining != 0
|
||||
#endif
|
||||
|
||||
@ Since we _are_ the C run-time, we need to manually zero the BSS
|
||||
@ region before continuing
|
||||
@@ -120,64 +157,21 @@ FUNCTION(codestart)
|
||||
|
||||
b EXT_C(grub_main)
|
||||
|
||||
/*
|
||||
* uboot_syscall():
|
||||
* This function is effectively a veneer, so it cannot
|
||||
* modify the stack or corrupt any registers other than
|
||||
* r12 (ip). Furthermore it needs to restore r8 for
|
||||
* U-Boot (Global Data Pointer) and preserve it for Grub.
|
||||
*/
|
||||
FUNCTION(grub_uboot_syscall)
|
||||
str r8, transition_space
|
||||
str lr, transition_space + 4
|
||||
str r9, transition_space + 8
|
||||
|
||||
ldr r8, gd_backup
|
||||
ldr r9, gd_backup + 4
|
||||
|
||||
bl do_syscall
|
||||
|
||||
ldr r8, transition_space
|
||||
ldr lr, transition_space + 4
|
||||
ldr r9, transition_space + 8
|
||||
|
||||
bx lr
|
||||
do_syscall:
|
||||
|
||||
ldr ip, grub_uboot_syscall_ptr
|
||||
bx ip
|
||||
|
||||
FUNCTION(grub_uboot_return)
|
||||
adr sp, entry_state_end
|
||||
pop {r4-r12, lr}
|
||||
mov sp, r12
|
||||
bx lr
|
||||
|
||||
|
||||
.align 3
|
||||
@ U-boot context stack space
|
||||
entry_state_end:
|
||||
@ U-boot/coreboot context stack space
|
||||
VARIABLE(grub_arm_saved_registers)
|
||||
.long 0 @ r0
|
||||
.long 0 @ r1
|
||||
.long 0 @ r2
|
||||
.long 0 @ r3
|
||||
.long 0 @ r4
|
||||
.long 0 @ r5
|
||||
.long 0 @ r6
|
||||
.long 0 @ r7
|
||||
gd_backup:
|
||||
.long 0 @ r8 - U-Boot global data pointer up to 2013-09-21
|
||||
.long 0 @ r9 - U-Boot global data pointer 2013-09-21 onwards
|
||||
.long 0 @ r8
|
||||
.long 0 @ r9
|
||||
.long 0 @ r10
|
||||
.long 0 @ r11
|
||||
VARIABLE(grub_uboot_search_hint)@ U-Boot stack pointer -
|
||||
.long 0 @ also API signature address hint.
|
||||
.long 0 @ sp
|
||||
.long 0 @ lr
|
||||
entry_state: @ backup for U-Boot context
|
||||
|
||||
@ GRUB context stack space
|
||||
transition_space:
|
||||
.long 0 @ r8
|
||||
.long 0 @ lr
|
||||
.long 0 @ r9
|
||||
|
||||
VARIABLE(grub_uboot_syscall_ptr)
|
||||
.long 0 @
|
||||
|
||||
END
|
||||
entry_state:
|
||||
70
grub-core/kern/arm/uboot/init.c
Normal file
70
grub-core/kern/arm/uboot/init.c
Normal file
@@ -0,0 +1,70 @@
|
||||
/* init.c - generic U-Boot initialization and finalization */
|
||||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 2016 Free Software Foundation, Inc.
|
||||
*
|
||||
* GRUB is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* GRUB is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <grub/uboot/uboot.h>
|
||||
#include <grub/arm/startup.h>
|
||||
#include <grub/uboot/api_public.h>
|
||||
|
||||
extern int (*grub_uboot_syscall_ptr) (int, int *, ...);
|
||||
|
||||
grub_uint32_t
|
||||
grub_uboot_get_machine_type (void)
|
||||
{
|
||||
return grub_arm_saved_registers.r[1];
|
||||
}
|
||||
|
||||
grub_addr_t
|
||||
grub_uboot_get_boot_data (void)
|
||||
{
|
||||
return grub_arm_saved_registers.r[2];
|
||||
}
|
||||
|
||||
int
|
||||
grub_uboot_api_init (void)
|
||||
{
|
||||
struct api_signature *start, *end;
|
||||
struct api_signature *p;
|
||||
grub_addr_t grub_uboot_search_hint = grub_arm_saved_registers.sp;
|
||||
if (grub_uboot_search_hint)
|
||||
{
|
||||
/* Extended search range to work around Trim Slice U-Boot issue */
|
||||
start = (struct api_signature *) ((grub_uboot_search_hint & ~0x000fffff)
|
||||
- 0x00500000);
|
||||
end =
|
||||
(struct api_signature *) ((grub_addr_t) start + UBOOT_API_SEARCH_LEN -
|
||||
API_SIG_MAGLEN + 0x00500000);
|
||||
}
|
||||
else
|
||||
{
|
||||
start = 0;
|
||||
end = (struct api_signature *) (256 * 1024 * 1024);
|
||||
}
|
||||
|
||||
/* Structure alignment is (at least) 8 bytes */
|
||||
for (p = start; p < end; p = (void *) ((grub_addr_t) p + 8))
|
||||
{
|
||||
if (grub_memcmp (&(p->magic), API_SIG_MAGIC, API_SIG_MAGLEN) == 0)
|
||||
{
|
||||
grub_uboot_syscall_ptr = p->syscall;
|
||||
return p->version;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
73
grub-core/kern/arm/uboot/uboot.S
Normal file
73
grub-core/kern/arm/uboot/uboot.S
Normal file
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 2013 Free Software Foundation, Inc.
|
||||
*
|
||||
* GRUB is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* GRUB is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <grub/offsets.h>
|
||||
#include <grub/symbol.h>
|
||||
#include <grub/machine/kernel.h>
|
||||
|
||||
/*
|
||||
* uboot_syscall():
|
||||
* This function is effectively a veneer, so it cannot
|
||||
* modify the stack or corrupt any registers other than
|
||||
* r12 (ip). Furthermore it needs to restore r8 for
|
||||
* U-Boot (Global Data Pointer) and preserve it for Grub.
|
||||
*/
|
||||
FUNCTION(grub_uboot_syscall)
|
||||
str r8, transition_space
|
||||
str lr, transition_space + 4
|
||||
str r9, transition_space + 8
|
||||
|
||||
ldr ip, saved_registers_ptr
|
||||
ldr r8, [ip, #4 * 8]
|
||||
ldr r9, [ip, #4 * 9]
|
||||
|
||||
bl do_syscall
|
||||
|
||||
ldr r8, transition_space
|
||||
ldr lr, transition_space + 4
|
||||
ldr r9, transition_space + 8
|
||||
|
||||
bx lr
|
||||
do_syscall:
|
||||
|
||||
ldr ip, grub_uboot_syscall_ptr
|
||||
bx ip
|
||||
|
||||
FUNCTION(grub_uboot_return)
|
||||
ldr ip, saved_registers_ptr
|
||||
ldr sp, [ip, #4 * 4]
|
||||
pop {r4-r12, lr}
|
||||
mov sp, r12
|
||||
bx lr
|
||||
|
||||
|
||||
.align 3
|
||||
|
||||
@ GRUB context stack space
|
||||
transition_space:
|
||||
.long 0 @ r8
|
||||
.long 0 @ lr
|
||||
.long 0 @ r9
|
||||
|
||||
saved_registers_ptr:
|
||||
.long EXT_C(grub_arm_saved_registers)
|
||||
|
||||
VARIABLE(grub_uboot_syscall_ptr)
|
||||
.long 0 @
|
||||
|
||||
END
|
||||
@@ -25,14 +25,9 @@
|
||||
#include <grub/i18n.h>
|
||||
#include <grub/cpu/reloc.h>
|
||||
|
||||
struct trampoline
|
||||
{
|
||||
#define LDR 0x58000050
|
||||
#define BR 0xd61f0200
|
||||
grub_uint32_t ldr; /* ldr x16, 8 */
|
||||
grub_uint32_t br; /* br x16 */
|
||||
grub_uint64_t addr;
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* Check if EHDR is a valid ELF header.
|
||||
@@ -53,42 +48,6 @@ grub_arch_dl_check_header (void *ehdr)
|
||||
|
||||
#pragma GCC diagnostic ignored "-Wcast-align"
|
||||
|
||||
grub_err_t
|
||||
grub_arch_dl_get_tramp_got_size (const void *ehdr, grub_size_t *tramp,
|
||||
grub_size_t *got)
|
||||
{
|
||||
const Elf_Ehdr *e = ehdr;
|
||||
const Elf_Shdr *s;
|
||||
unsigned i;
|
||||
|
||||
*tramp = 0;
|
||||
*got = 0;
|
||||
|
||||
for (i = 0, s = (const Elf_Shdr *) ((grub_addr_t) e + e->e_shoff);
|
||||
i < e->e_shnum;
|
||||
i++, s = (const Elf_Shdr *) ((grub_addr_t) s + e->e_shentsize))
|
||||
if (s->sh_type == SHT_REL || s->sh_type == SHT_RELA)
|
||||
{
|
||||
const Elf_Rel *rel, *max;
|
||||
|
||||
for (rel = (const Elf_Rel *) ((grub_addr_t) e + s->sh_offset),
|
||||
max = rel + s->sh_size / s->sh_entsize;
|
||||
rel < max;
|
||||
rel = (const Elf_Rel *) ((grub_addr_t) rel + s->sh_entsize))
|
||||
switch (ELF_R_TYPE (rel->r_info))
|
||||
{
|
||||
case R_AARCH64_CALL26:
|
||||
case R_AARCH64_JUMP26:
|
||||
{
|
||||
*tramp += sizeof (struct trampoline);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
/*
|
||||
* Unified function for both REL and RELA
|
||||
*/
|
||||
@@ -97,6 +56,7 @@ grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr,
|
||||
Elf_Shdr *s, grub_dl_segment_t seg)
|
||||
{
|
||||
Elf_Rel *rel, *max;
|
||||
unsigned unmatched_adr_got_page = 0;
|
||||
|
||||
for (rel = (Elf_Rel *) ((char *) ehdr + s->sh_offset),
|
||||
max = (Elf_Rel *) ((char *) rel + s->sh_size);
|
||||
@@ -132,6 +92,12 @@ grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr,
|
||||
*abs_place = (grub_uint64_t) sym_addr;
|
||||
}
|
||||
break;
|
||||
case R_AARCH64_ADD_ABS_LO12_NC:
|
||||
grub_arm64_set_abs_lo12 (place, sym_addr);
|
||||
break;
|
||||
case R_AARCH64_LDST64_ABS_LO12_NC:
|
||||
grub_arm64_set_abs_lo12_ldst64 (place, sym_addr);
|
||||
break;
|
||||
case R_AARCH64_CALL26:
|
||||
case R_AARCH64_JUMP26:
|
||||
{
|
||||
@@ -139,7 +105,7 @@ grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr,
|
||||
|
||||
if (!grub_arm_64_check_xxxx26_offset (offset))
|
||||
{
|
||||
struct trampoline *tp = mod->trampptr;
|
||||
struct grub_arm64_trampoline *tp = mod->trampptr;
|
||||
mod->trampptr = tp + 1;
|
||||
tp->ldr = LDR;
|
||||
tp->br = BR;
|
||||
@@ -154,6 +120,68 @@ grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr,
|
||||
grub_arm64_set_xxxx26_offset (place, offset);
|
||||
}
|
||||
break;
|
||||
case R_AARCH64_PREL32:
|
||||
{
|
||||
grub_int64_t value;
|
||||
Elf64_Word *addr32 = place;
|
||||
value = ((grub_int32_t) *addr32) + sym_addr -
|
||||
(Elf64_Xword) (grub_addr_t) seg->addr - rel->r_offset;
|
||||
if (value != (grub_int32_t) value)
|
||||
return grub_error (GRUB_ERR_BAD_MODULE, "relocation out of range");
|
||||
grub_dprintf("dl", " reloc_prel32 %p => 0x%016llx\n",
|
||||
place, (unsigned long long) sym_addr);
|
||||
*addr32 = value;
|
||||
}
|
||||
break;
|
||||
case R_AARCH64_ADR_GOT_PAGE:
|
||||
{
|
||||
grub_uint64_t *gp = mod->gotptr;
|
||||
Elf_Rela *rel2;
|
||||
grub_int64_t gpoffset = ((grub_uint64_t) gp & ~0xfffULL) - (((grub_uint64_t) place) & ~0xfffULL);
|
||||
*gp = (grub_uint64_t) sym_addr;
|
||||
mod->gotptr = gp + 1;
|
||||
unmatched_adr_got_page++;
|
||||
grub_dprintf("dl", " reloc_got %p => 0x%016llx (0x%016llx)\n",
|
||||
place, (unsigned long long) sym_addr, (unsigned long long) gp);
|
||||
if (!grub_arm64_check_hi21_signed (gpoffset))
|
||||
return grub_error (GRUB_ERR_BAD_MODULE,
|
||||
"HI21 out of range");
|
||||
grub_arm64_set_hi21(place, gpoffset);
|
||||
for (rel2 = (Elf_Rela *) ((char *) rel + s->sh_entsize);
|
||||
rel2 < (Elf_Rela *) max;
|
||||
rel2 = (Elf_Rela *) ((char *) rel2 + s->sh_entsize))
|
||||
if (ELF_R_SYM (rel2->r_info)
|
||||
== ELF_R_SYM (rel->r_info)
|
||||
&& ((Elf_Rela *) rel)->r_addend == rel2->r_addend
|
||||
&& ELF_R_TYPE (rel2->r_info) == R_AARCH64_LD64_GOT_LO12_NC)
|
||||
{
|
||||
grub_arm64_set_abs_lo12_ldst64 ((void *) ((grub_addr_t) seg->addr + rel2->r_offset),
|
||||
(grub_uint64_t)gp);
|
||||
break;
|
||||
}
|
||||
if (rel2 >= (Elf_Rela *) max)
|
||||
return grub_error (GRUB_ERR_BAD_MODULE,
|
||||
"ADR_GOT_PAGE without matching LD64_GOT_LO12_NC");
|
||||
}
|
||||
break;
|
||||
case R_AARCH64_LD64_GOT_LO12_NC:
|
||||
if (unmatched_adr_got_page == 0)
|
||||
return grub_error (GRUB_ERR_BAD_MODULE,
|
||||
"LD64_GOT_LO12_NC without matching ADR_GOT_PAGE");
|
||||
unmatched_adr_got_page--;
|
||||
break;
|
||||
case R_AARCH64_ADR_PREL_PG_HI21:
|
||||
{
|
||||
grub_int64_t offset = (sym_addr & ~0xfffULL) - (((grub_uint64_t) place) & ~0xfffULL);
|
||||
|
||||
if (!grub_arm64_check_hi21_signed (offset))
|
||||
return grub_error (GRUB_ERR_BAD_MODULE,
|
||||
"HI21 out of range");
|
||||
|
||||
grub_arm64_set_hi21 (place, offset);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
|
||||
N_("relocation 0x%x is not implemented yet"),
|
||||
|
||||
@@ -53,3 +53,82 @@ grub_arm64_set_xxxx26_offset (grub_uint32_t *place, grub_int64_t offset)
|
||||
*place &= insmask;
|
||||
*place |= grub_cpu_to_le32 (offset >> 2) & ~insmask;
|
||||
}
|
||||
|
||||
int
|
||||
grub_arm64_check_hi21_signed (grub_int64_t offset)
|
||||
{
|
||||
if (offset != (grub_int64_t)(grub_int32_t)offset)
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
void
|
||||
grub_arm64_set_hi21 (grub_uint32_t *place, grub_int64_t offset)
|
||||
{
|
||||
const grub_uint32_t insmask = grub_cpu_to_le32_compile_time (0x9f00001f);
|
||||
grub_uint32_t val;
|
||||
|
||||
offset >>= 12;
|
||||
|
||||
val = ((offset & 3) << 29) | (((offset >> 2) & 0x7ffff) << 5);
|
||||
|
||||
*place &= insmask;
|
||||
*place |= grub_cpu_to_le32 (val) & ~insmask;
|
||||
}
|
||||
|
||||
void
|
||||
grub_arm64_set_abs_lo12 (grub_uint32_t *place, grub_int64_t target)
|
||||
{
|
||||
const grub_uint32_t insmask = grub_cpu_to_le32_compile_time (0xffc003ff);
|
||||
|
||||
*place &= insmask;
|
||||
*place |= grub_cpu_to_le32 (target << 10) & ~insmask;
|
||||
}
|
||||
|
||||
void
|
||||
grub_arm64_set_abs_lo12_ldst64 (grub_uint32_t *place, grub_int64_t target)
|
||||
{
|
||||
const grub_uint32_t insmask = grub_cpu_to_le32_compile_time (0xfff803ff);
|
||||
|
||||
*place &= insmask;
|
||||
*place |= grub_cpu_to_le32 (target << 7) & ~insmask;
|
||||
}
|
||||
|
||||
#pragma GCC diagnostic ignored "-Wcast-align"
|
||||
|
||||
grub_err_t
|
||||
grub_arm64_dl_get_tramp_got_size (const void *ehdr, grub_size_t *tramp,
|
||||
grub_size_t *got)
|
||||
{
|
||||
const Elf64_Ehdr *e = ehdr;
|
||||
const Elf64_Shdr *s;
|
||||
unsigned i;
|
||||
|
||||
*tramp = 0;
|
||||
*got = 0;
|
||||
|
||||
for (i = 0, s = (Elf64_Shdr *) ((char *) e + grub_le_to_cpu64 (e->e_shoff));
|
||||
i < grub_le_to_cpu16 (e->e_shnum);
|
||||
i++, s = (Elf64_Shdr *) ((char *) s + grub_le_to_cpu16 (e->e_shentsize)))
|
||||
if (s->sh_type == grub_cpu_to_le32_compile_time (SHT_REL)
|
||||
|| s->sh_type == grub_cpu_to_le32_compile_time (SHT_RELA))
|
||||
{
|
||||
const Elf64_Rela *rel, *max;
|
||||
|
||||
for (rel = (Elf64_Rela *) ((char *) e + grub_le_to_cpu64 (s->sh_offset)),
|
||||
max = (const Elf64_Rela *) ((char *) rel + grub_le_to_cpu64 (s->sh_size));
|
||||
rel < max; rel = (const Elf64_Rela *) ((char *) rel + grub_le_to_cpu64 (s->sh_entsize)))
|
||||
switch (ELF64_R_TYPE (rel->r_info))
|
||||
{
|
||||
case R_AARCH64_CALL26:
|
||||
case R_AARCH64_JUMP26:
|
||||
*tramp += sizeof (struct grub_arm64_trampoline);
|
||||
break;
|
||||
case R_AARCH64_ADR_GOT_PAGE:
|
||||
*got += 8;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
60
grub-core/kern/arm64/efi/init.c
Normal file
60
grub-core/kern/arm64/efi/init.c
Normal file
@@ -0,0 +1,60 @@
|
||||
/* init.c - initialize an arm-based EFI system */
|
||||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 2013 Free Software Foundation, Inc.
|
||||
*
|
||||
* GRUB is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* GRUB is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <grub/env.h>
|
||||
#include <grub/kernel.h>
|
||||
#include <grub/misc.h>
|
||||
#include <grub/mm.h>
|
||||
#include <grub/time.h>
|
||||
#include <grub/efi/efi.h>
|
||||
#include <grub/loader.h>
|
||||
|
||||
static grub_uint64_t timer_frequency_in_khz;
|
||||
|
||||
static grub_uint64_t
|
||||
grub_efi_get_time_ms (void)
|
||||
{
|
||||
grub_uint64_t tmr;
|
||||
asm volatile("mrs %0, cntvct_el0" : "=r" (tmr));
|
||||
|
||||
return tmr / timer_frequency_in_khz;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
grub_machine_init (void)
|
||||
{
|
||||
grub_uint64_t timer_frequency;
|
||||
|
||||
grub_efi_init ();
|
||||
|
||||
asm volatile("mrs %0, cntfrq_el0" : "=r" (timer_frequency));
|
||||
timer_frequency_in_khz = timer_frequency / 1000;
|
||||
|
||||
grub_install_get_time_ms (grub_efi_get_time_ms);
|
||||
}
|
||||
|
||||
void
|
||||
grub_machine_fini (int flags)
|
||||
{
|
||||
if (!(flags & GRUB_LOADER_FLAG_NORETURN))
|
||||
return;
|
||||
|
||||
grub_efi_fini ();
|
||||
}
|
||||
72
grub-core/kern/coreboot/cbtable.c
Normal file
72
grub-core/kern/coreboot/cbtable.c
Normal file
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 2007,2008,2013 Free Software Foundation, Inc.
|
||||
*
|
||||
* GRUB is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* GRUB is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <grub/i386/coreboot/memory.h>
|
||||
#include <grub/coreboot/lbio.h>
|
||||
#include <grub/types.h>
|
||||
#include <grub/err.h>
|
||||
#include <grub/misc.h>
|
||||
#include <grub/dl.h>
|
||||
|
||||
#pragma GCC diagnostic ignored "-Wcast-align"
|
||||
|
||||
/* Helper for grub_linuxbios_table_iterate. */
|
||||
int
|
||||
grub_linuxbios_check_signature (grub_linuxbios_table_header_t tbl_header)
|
||||
{
|
||||
if (! grub_memcmp (tbl_header->signature, "LBIO", 4))
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
grub_err_t
|
||||
grub_linuxbios_table_iterate (int (*hook) (grub_linuxbios_table_item_t,
|
||||
void *),
|
||||
void *hook_data)
|
||||
{
|
||||
grub_linuxbios_table_header_t table_header = grub_linuxbios_get_tables ();
|
||||
grub_linuxbios_table_item_t table_item;
|
||||
|
||||
if (!table_header)
|
||||
return 0;
|
||||
|
||||
signature_found:
|
||||
|
||||
table_item =
|
||||
(grub_linuxbios_table_item_t) ((char *) table_header +
|
||||
table_header->header_size);
|
||||
for (; table_item < (grub_linuxbios_table_item_t) ((char *) table_header
|
||||
+ table_header->header_size
|
||||
+ table_header->table_size);
|
||||
table_item = (grub_linuxbios_table_item_t) ((char *) table_item + table_item->size))
|
||||
{
|
||||
if (table_item->tag == GRUB_LINUXBIOS_MEMBER_LINK
|
||||
&& grub_linuxbios_check_signature ((grub_linuxbios_table_header_t) (grub_addr_t)
|
||||
*(grub_uint64_t *) (table_item + 1)))
|
||||
{
|
||||
table_header = (grub_linuxbios_table_header_t) (grub_addr_t)
|
||||
*(grub_uint64_t *) (table_item + 1);
|
||||
goto signature_found;
|
||||
}
|
||||
if (hook (table_item, hook_data))
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -16,8 +16,8 @@
|
||||
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <grub/machine/memory.h>
|
||||
#include <grub/machine/lbio.h>
|
||||
#include <grub/memory.h>
|
||||
#include <grub/coreboot/lbio.h>
|
||||
#include <grub/types.h>
|
||||
#include <grub/err.h>
|
||||
#include <grub/misc.h>
|
||||
@@ -49,6 +49,7 @@ iterate_linuxbios_table (grub_linuxbios_table_item_t table_item, void *data)
|
||||
{
|
||||
grub_uint64_t start = mem_region->addr;
|
||||
grub_uint64_t end = mem_region->addr + mem_region->size;
|
||||
#ifdef __i386__
|
||||
/* Mark region 0xa0000 - 0x100000 as reserved. */
|
||||
if (start < 0x100000 && end >= 0xa0000
|
||||
&& mem_region->type == GRUB_MACHINE_MEMORY_AVAILABLE)
|
||||
@@ -75,6 +76,7 @@ iterate_linuxbios_table (grub_linuxbios_table_item_t table_item, void *data)
|
||||
if (end <= start)
|
||||
continue;
|
||||
}
|
||||
#endif
|
||||
if (ctx->hook (start, end - start,
|
||||
/* Multiboot mmaps match with the coreboot mmap
|
||||
definition. Therefore, we can just pass type
|
||||
@@ -333,8 +333,11 @@ grub_dl_resolve_symbols (grub_dl_t mod, Elf_Ehdr *e)
|
||||
if (s->sh_type == SHT_SYMTAB)
|
||||
break;
|
||||
|
||||
/* Module without symbol table may still be used to pull in dependencies.
|
||||
We verify at build time that such modules do not contain any relocations
|
||||
that may reference symbol table. */
|
||||
if (i == e->e_shnum)
|
||||
return grub_error (GRUB_ERR_BAD_MODULE, N_("no symbol table"));
|
||||
return GRUB_ERR_NONE;
|
||||
|
||||
#ifdef GRUB_MODULES_MACHINE_READONLY
|
||||
mod->symtab = grub_malloc (s->sh_size);
|
||||
@@ -576,6 +579,9 @@ grub_dl_relocate_symbols (grub_dl_t mod, void *ehdr)
|
||||
|
||||
if (seg)
|
||||
{
|
||||
if (!mod->symtab)
|
||||
return grub_error (GRUB_ERR_BAD_MODULE, "relocation without symbol table");
|
||||
|
||||
err = grub_arch_dl_relocate_symbols (mod, ehdr, s, seg);
|
||||
if (err)
|
||||
return err;
|
||||
@@ -605,7 +611,7 @@ grub_dl_load_core_noinit (void *addr, grub_size_t size)
|
||||
}
|
||||
|
||||
/* Make sure that every section is within the core. */
|
||||
if (size < e->e_shoff + e->e_shentsize * e->e_shnum)
|
||||
if (size < e->e_shoff + (grub_uint32_t) e->e_shentsize * e->e_shnum)
|
||||
{
|
||||
grub_error (GRUB_ERR_BAD_OS, "ELF sections outside core");
|
||||
return 0;
|
||||
@@ -682,7 +688,7 @@ grub_dl_load_file (const char *filename)
|
||||
|
||||
grub_boot_time ("Loading module %s", filename);
|
||||
|
||||
file = grub_file_open (filename);
|
||||
file = grub_file_open (filename, GRUB_FILE_TYPE_GRUB_MODULE);
|
||||
if (! file)
|
||||
return 0;
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user