mirror of
http://cgit.git.savannah.gnu.org/git/grub.git
synced 2026-04-28 14:33:34 +00:00
Compare commits
2 Commits
phcoder/ve
...
phcoder/te
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dfabe9ce4a | ||
|
|
ccaf9c7bcc |
@@ -86,11 +86,9 @@ 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_FDT_LIST)
|
||||
$(CPPFLAGS_TERMINAL_LIST) $(CPPFLAGS_COMMAND_LIST)
|
||||
|
||||
# Define these variables to calm down automake
|
||||
|
||||
|
||||
@@ -167,7 +167,6 @@ case "$target_cpu"-"$platform" in
|
||||
mipsel-fuloong) platform=loongson ;;
|
||||
mipsel-loongson) ;;
|
||||
arm-uboot) ;;
|
||||
arm-coreboot) ;;
|
||||
arm-efi) ;;
|
||||
arm64-efi) ;;
|
||||
*-emu) ;;
|
||||
@@ -1919,7 +1918,6 @@ 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,7 +84,6 @@ 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
|
||||
@@ -1950,58 +1949,6 @@ 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
|
||||
|
||||
|
||||
10
gentpl.py
10
gentpl.py
@@ -31,8 +31,7 @@ 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",
|
||||
"arm_coreboot"]
|
||||
"mips_qemu_mips", "arm_uboot", "arm_efi", "arm64_efi" ]
|
||||
|
||||
GROUPS = {}
|
||||
|
||||
@@ -45,7 +44,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", "arm_coreboot" ]
|
||||
GROUPS["arm"] = [ "arm_uboot", "arm_efi" ]
|
||||
GROUPS["arm64"] = [ "arm64_efi" ]
|
||||
|
||||
# Groups based on firmware
|
||||
@@ -53,7 +52,6 @@ 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")
|
||||
@@ -63,10 +61,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"] + ["arm_coreboot"]
|
||||
GROUPS["usb"] = GROUPS["pci"]
|
||||
|
||||
# If gfxterm is main output console integrate it into kernel
|
||||
GROUPS["videoinkernel"] = ["mips_loongson", "i386_coreboot", "arm_coreboot" ]
|
||||
GROUPS["videoinkernel"] = ["mips_loongson", "i386_coreboot" ]
|
||||
GROUPS["videomodules"] = GRUB_PLATFORMS[:];
|
||||
for i in GROUPS["videoinkernel"]: GROUPS["videomodules"].remove(i)
|
||||
|
||||
|
||||
@@ -112,7 +112,7 @@ endif
|
||||
|
||||
if COND_i386_coreboot
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/i386/tsc.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/coreboot/lbio.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/i386/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
|
||||
@@ -239,20 +239,6 @@ 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
|
||||
@@ -372,16 +358,6 @@ 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`; \
|
||||
|
||||
@@ -92,8 +92,6 @@ kernel = {
|
||||
emu_cppflags = '$(CPPFLAGS_GNULIB)';
|
||||
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;
|
||||
@@ -107,8 +105,7 @@ 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/startup.S;
|
||||
arm_coreboot_startup = kern/arm/startup.S;
|
||||
arm_uboot_startup = kern/arm/uboot/startup.S;
|
||||
arm_efi_startup = kern/arm/efi/startup.S;
|
||||
arm64_efi_startup = kern/arm64/efi/startup.S;
|
||||
|
||||
@@ -152,21 +149,6 @@ 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;
|
||||
@@ -182,7 +164,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;
|
||||
coreboot = video/coreboot/cbfb.c;
|
||||
i386_coreboot = video/i386/coreboot/cbfb.c;
|
||||
|
||||
efi = disk/efi/efidisk.c;
|
||||
efi = kern/efi/efi.c;
|
||||
@@ -243,10 +225,8 @@ kernel = {
|
||||
i386_qemu = kern/vga_init.c;
|
||||
i386_qemu = kern/i386/qemu/mmap.c;
|
||||
|
||||
coreboot = kern/coreboot/mmap.c;
|
||||
i386_coreboot = kern/i386/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;
|
||||
|
||||
@@ -258,7 +238,6 @@ 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;
|
||||
@@ -274,7 +253,6 @@ 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;
|
||||
@@ -596,10 +574,7 @@ 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 = {
|
||||
@@ -666,7 +641,6 @@ module = {
|
||||
module = {
|
||||
name = cbtable;
|
||||
common = kern/i386/coreboot/cbtable.c;
|
||||
common = kern/coreboot/cbtable.c;
|
||||
enable = i386_pc;
|
||||
enable = i386_efi;
|
||||
enable = i386_qemu;
|
||||
@@ -780,7 +754,6 @@ module = {
|
||||
enable = arm_efi;
|
||||
enable = arm64_efi;
|
||||
enable = arm_uboot;
|
||||
enable = arm_coreboot;
|
||||
};
|
||||
|
||||
module = {
|
||||
@@ -864,8 +837,7 @@ module = {
|
||||
efi = lib/efi/halt.c;
|
||||
ieee1275 = lib/ieee1275/halt.c;
|
||||
emu = lib/emu/halt.c;
|
||||
uboot = lib/dummy/halt.c;
|
||||
arm_coreboot = lib/dummy/halt.c;
|
||||
uboot = lib/uboot/halt.c;
|
||||
};
|
||||
|
||||
module = {
|
||||
@@ -883,7 +855,6 @@ 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;
|
||||
};
|
||||
|
||||
@@ -899,11 +870,6 @@ module = {
|
||||
cppflags = '-I$(srcdir)/lib/posix_wrap';
|
||||
};
|
||||
|
||||
module = {
|
||||
name = verify_helper;
|
||||
common = commands/verify_helper.c;
|
||||
};
|
||||
|
||||
module = {
|
||||
name = hdparm;
|
||||
common = commands/hdparm.c;
|
||||
@@ -1582,8 +1548,7 @@ module = {
|
||||
name = datetime;
|
||||
cmos = lib/cmos_datetime.c;
|
||||
efi = lib/efi/datetime.c;
|
||||
uboot = lib/dummy/datetime.c;
|
||||
arm_coreboot = lib/dummy/datetime.c;
|
||||
uboot = lib/uboot/datetime.c;
|
||||
sparc64_ieee1275 = lib/ieee1275/datetime.c;
|
||||
powerpc_ieee1275 = lib/ieee1275/datetime.c;
|
||||
sparc64_ieee1275 = lib/ieee1275/cmos.c;
|
||||
@@ -1904,7 +1869,6 @@ module = {
|
||||
module = {
|
||||
name = at_keyboard;
|
||||
common = term/at_keyboard.c;
|
||||
common = term/ps2.c;
|
||||
enable = x86;
|
||||
};
|
||||
|
||||
@@ -1997,11 +1961,6 @@ 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;
|
||||
|
||||
@@ -1,256 +0,0 @@
|
||||
/*
|
||||
* 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;
|
||||
}
|
||||
@@ -1,103 +0,0 @@
|
||||
/*
|
||||
* 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);
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
/* 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);
|
||||
}
|
||||
@@ -1,208 +0,0 @@
|
||||
/* 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,10 +22,13 @@
|
||||
#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+");
|
||||
@@ -36,6 +39,8 @@ GRUB_MOD_LICENSE ("GPLv3+");
|
||||
* - is not supporting interrupt transfers
|
||||
*/
|
||||
|
||||
#define GRUB_EHCI_PCI_SBRN_REG 0x60
|
||||
|
||||
/* Capability registers offsets */
|
||||
enum
|
||||
{
|
||||
@@ -49,6 +54,7 @@ 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 */
|
||||
@@ -79,6 +85,13 @@ 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
|
||||
{
|
||||
@@ -442,10 +455,9 @@ grub_ehci_reset (struct grub_ehci *e)
|
||||
|
||||
sync_all_caches (e);
|
||||
|
||||
grub_dprintf ("ehci", "reset\n");
|
||||
|
||||
grub_ehci_oper_write32 (e, GRUB_EHCI_COMMAND,
|
||||
GRUB_EHCI_CMD_HC_RESET);
|
||||
GRUB_EHCI_CMD_HC_RESET
|
||||
| grub_ehci_oper_read32 (e, GRUB_EHCI_COMMAND));
|
||||
/* Ensure command is written */
|
||||
grub_ehci_oper_read32 (e, GRUB_EHCI_COMMAND);
|
||||
/* XXX: How long time could take reset of HC ? */
|
||||
@@ -461,24 +473,116 @@ grub_ehci_reset (struct grub_ehci *e)
|
||||
}
|
||||
|
||||
/* PCI iteration function... */
|
||||
void
|
||||
grub_ehci_init_device (volatile void *regs)
|
||||
static int
|
||||
grub_ehci_pci_iter (grub_pci_device_t dev, grub_pci_id_t pciid,
|
||||
void *data __attribute__ ((unused)))
|
||||
{
|
||||
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;
|
||||
return 1;
|
||||
e->framelist_chunk = NULL;
|
||||
e->td_chunk = NULL;
|
||||
e->qh_chunk = NULL;
|
||||
e->iobase_ehcc = regs;
|
||||
e->iobase_ehcc = grub_pci_device_map_range (dev,
|
||||
(base & GRUB_EHCI_ADDR_MEM_MASK),
|
||||
0x100);
|
||||
|
||||
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",
|
||||
@@ -494,7 +598,7 @@ grub_ehci_init_device (volatile void *regs)
|
||||
if (caplen & (sizeof (grub_uint32_t) - 1))
|
||||
{
|
||||
grub_dprintf ("ehci", "Unaligned caplen\n");
|
||||
return;
|
||||
return 0;
|
||||
}
|
||||
e->iobase = ((volatile grub_uint32_t *) e->iobase_ehcc
|
||||
+ (caplen / sizeof (grub_uint32_t)));
|
||||
@@ -505,7 +609,7 @@ grub_ehci_init_device (volatile void *regs)
|
||||
|
||||
grub_dprintf ("ehci",
|
||||
"EHCI grub_ehci_pci_iter: iobase of oper. regs: %08x\n",
|
||||
(grub_addr_t) e->iobase_ehcc + caplen);
|
||||
(base & GRUB_EHCI_ADDR_MEM_MASK) + 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",
|
||||
@@ -521,6 +625,10 @@ grub_ehci_init_device (volatile void *regs)
|
||||
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 */
|
||||
@@ -624,6 +732,65 @@ grub_ehci_init_device (volatile void *regs)
|
||||
|
||||
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 */
|
||||
@@ -697,7 +864,7 @@ grub_ehci_init_device (volatile void *regs)
|
||||
|
||||
grub_dprintf ("ehci",
|
||||
"EHCI grub_ehci_pci_iter: iobase of oper. regs: %08x\n",
|
||||
(grub_addr_t) regs);
|
||||
(base & GRUB_EHCI_ADDR_MEM_MASK));
|
||||
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",
|
||||
@@ -713,7 +880,7 @@ grub_ehci_init_device (volatile void *regs)
|
||||
grub_dprintf ("ehci", "EHCI grub_ehci_pci_iter: CONFIG_FLAG: %08x\n",
|
||||
grub_ehci_oper_read32 (e, GRUB_EHCI_CONFIG_FLAG));
|
||||
|
||||
return;
|
||||
return 0;
|
||||
|
||||
fail:
|
||||
if (e)
|
||||
@@ -727,7 +894,7 @@ fail:
|
||||
}
|
||||
grub_free (e);
|
||||
|
||||
return;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
@@ -1724,6 +1891,12 @@ 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)
|
||||
{
|
||||
@@ -1824,7 +1997,7 @@ GRUB_MOD_INIT (ehci)
|
||||
grub_stop_disk_firmware ();
|
||||
|
||||
grub_boot_time ("Initing EHCI hardware");
|
||||
grub_ehci_pci_scan ();
|
||||
grub_ehci_inithw ();
|
||||
grub_boot_time ("Registering EHCI driver");
|
||||
grub_usb_controller_dev_register (&usb_controller);
|
||||
grub_boot_time ("EHCI driver registered");
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
*/
|
||||
|
||||
#include <grub/dl.h>
|
||||
#include <grub/dma.h>
|
||||
#include <grub/pci.h>
|
||||
#include <grub/mm.h>
|
||||
#include <grub/misc.h>
|
||||
#include <grub/usb.h>
|
||||
|
||||
@@ -635,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], GRUB_FILE_TYPE_ACPI_TABLE);
|
||||
file = grub_file_open (args[i]);
|
||||
if (! file)
|
||||
{
|
||||
free_tables ();
|
||||
|
||||
@@ -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"));
|
||||
|
||||
file = grub_file_open (args[0], GRUB_FILE_TYPE_PRINT_BLOCKLIST
|
||||
| GRUB_FILE_TYPE_NO_DECOMPRESS);
|
||||
grub_file_filter_disable_compression ();
|
||||
file = grub_file_open (args[0]);
|
||||
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], GRUB_FILE_TYPE_CAT);
|
||||
file = grub_file_open (args[0]);
|
||||
if (! file)
|
||||
return grub_errno;
|
||||
|
||||
|
||||
@@ -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], GRUB_FILE_TYPE_CMP);
|
||||
file2 = grub_file_open (args[1], GRUB_FILE_TYPE_CMP);
|
||||
file1 = grub_file_open (args[0]);
|
||||
file2 = grub_file_open (args[1]);
|
||||
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], GRUB_FILE_TYPE_VBE_DUMP);
|
||||
file = grub_file_open (argv[1]);
|
||||
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], GRUB_FILE_TYPE_VBE_DUMP);
|
||||
file = grub_file_open (argv[0]);
|
||||
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], GRUB_FILE_TYPE_XNU_KERNEL);
|
||||
file = grub_file_open (args[0]);
|
||||
if (!file)
|
||||
return grub_errno;
|
||||
switch (type)
|
||||
@@ -546,8 +546,7 @@ grub_cmd_file (grub_extcmd_context_t ctxt, int argc, char **args)
|
||||
case IS_XNU64:
|
||||
case IS_XNU32:
|
||||
{
|
||||
macho = grub_macho_open (args[0], GRUB_FILE_TYPE_XNU_KERNEL,
|
||||
(type == IS_XNU64));
|
||||
macho = grub_macho_open (args[0], (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, GRUB_FILE_TYPE_HASHLIST);
|
||||
hashlist = grub_file_open (hashfilename);
|
||||
if (!hashlist)
|
||||
return grub_errno;
|
||||
|
||||
@@ -141,15 +141,17 @@ check_list (const gcry_md_spec_t *hash, const char *hashfilename,
|
||||
filename = grub_xasprintf ("%s/%s", prefix, p);
|
||||
if (!filename)
|
||||
return grub_errno;
|
||||
file = grub_file_open (filename, GRUB_FILE_TYPE_TO_HASH
|
||||
| (!uncompress ? GRUB_FILE_TYPE_NO_DECOMPRESS
|
||||
: 0));
|
||||
if (!uncompress)
|
||||
grub_file_filter_disable_compression ();
|
||||
file = grub_file_open (filename);
|
||||
grub_free (filename);
|
||||
}
|
||||
else
|
||||
file = grub_file_open (p, GRUB_FILE_TYPE_TO_HASH
|
||||
| (!uncompress ? GRUB_FILE_TYPE_NO_DECOMPRESS
|
||||
: 0));
|
||||
{
|
||||
if (!uncompress)
|
||||
grub_file_filter_disable_compression ();
|
||||
file = grub_file_open (p);
|
||||
}
|
||||
if (!file)
|
||||
{
|
||||
grub_file_close (hashlist);
|
||||
@@ -240,9 +242,9 @@ grub_cmd_hashsum (struct grub_extcmd_context *ctxt,
|
||||
grub_file_t file;
|
||||
grub_err_t err;
|
||||
unsigned j;
|
||||
file = grub_file_open (args[i], GRUB_FILE_TYPE_TO_HASH
|
||||
| (!uncompress ? GRUB_FILE_TYPE_NO_DECOMPRESS
|
||||
: 0));
|
||||
if (!uncompress)
|
||||
grub_file_filter_disable_compression ();
|
||||
file = grub_file_open (args[i]);
|
||||
if (!file)
|
||||
{
|
||||
if (!keep)
|
||||
|
||||
@@ -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], GRUB_FILE_TYPE_HEXCAT);
|
||||
file = grub_file_open (args[0]);
|
||||
if (! file)
|
||||
return 0;
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
#include <grub/misc.h>
|
||||
#include <grub/command.h>
|
||||
#include <grub/i18n.h>
|
||||
#include <grub/coreboot/lbio.h>
|
||||
#include <grub/i386/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/coreboot/lbio.h>
|
||||
#include <grub/i386/coreboot/lbio.h>
|
||||
#include <grub/i386/tsc.h>
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
@@ -1,79 +0,0 @@
|
||||
/* 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], GRUB_FILE_TYPE_AUDIO);
|
||||
file = grub_file_open (args[0]);
|
||||
|
||||
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, GRUB_FILE_TYPE_KEYBOARD_LAYOUT);
|
||||
file = grub_file_open (filename);
|
||||
if (! file)
|
||||
goto fail;
|
||||
|
||||
|
||||
@@ -55,7 +55,7 @@ legacy_file (const char *filename)
|
||||
if (!suffix)
|
||||
return grub_errno;
|
||||
|
||||
file = grub_file_open (filename, GRUB_FILE_TYPE_CONFIG);
|
||||
file = grub_file_open (filename);
|
||||
if (! file)
|
||||
{
|
||||
grub_free (suffix);
|
||||
|
||||
@@ -44,8 +44,7 @@ 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,
|
||||
enum grub_file_type type)
|
||||
open_envblk_file (char *filename, int untrusted)
|
||||
{
|
||||
grub_file_t file;
|
||||
char *buf = 0;
|
||||
@@ -73,7 +72,13 @@ open_envblk_file (char *filename,
|
||||
grub_strcpy (filename + len + 1, GRUB_ENVBLK_DEFCFG);
|
||||
}
|
||||
|
||||
file = grub_file_open (filename, type);
|
||||
/* 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);
|
||||
|
||||
grub_free (buf);
|
||||
return file;
|
||||
@@ -166,10 +171,7 @@ 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,
|
||||
GRUB_FILE_TYPE_LOADENV
|
||||
| (state[1].set
|
||||
? GRUB_FILE_TYPE_SKIP_SIGNATURE : 0));
|
||||
file = open_envblk_file ((state[0].set) ? state[0].arg : 0, state[1].set);
|
||||
if (! file)
|
||||
return grub_errno;
|
||||
|
||||
@@ -204,10 +206,7 @@ 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,
|
||||
GRUB_FILE_TYPE_LOADENV
|
||||
| (state[1].set
|
||||
? GRUB_FILE_TYPE_SKIP_SIGNATURE : 0));
|
||||
file = open_envblk_file ((state[0].set) ? state[0].arg : 0, 0);
|
||||
if (! file)
|
||||
return grub_errno;
|
||||
|
||||
@@ -391,8 +390,7 @@ 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,
|
||||
GRUB_FILE_TYPE_SAVEENV
|
||||
| GRUB_FILE_TYPE_SKIP_SIGNATURE);
|
||||
1 /* allow untrusted */);
|
||||
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. */
|
||||
file = grub_file_open (pathname, GRUB_FILE_TYPE_GET_SIZE
|
||||
| GRUB_FILE_TYPE_NO_DECOMPRESS);
|
||||
grub_file_filter_disable_compression ();
|
||||
file = grub_file_open (pathname);
|
||||
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;
|
||||
|
||||
file = grub_file_open (dirname, GRUB_FILE_TYPE_GET_SIZE
|
||||
| GRUB_FILE_TYPE_NO_DECOMPRESS);
|
||||
grub_file_filter_disable_compression ();
|
||||
file = grub_file_open (dirname);
|
||||
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], GRUB_FILE_TYPE_CAT);
|
||||
file = grub_file_open (argv[0]);
|
||||
if (! file)
|
||||
return grub_errno;
|
||||
|
||||
|
||||
@@ -242,8 +242,7 @@ grub_cmd_nativedisk (grub_command_t cmd __attribute__ ((unused)),
|
||||
if (! filename)
|
||||
goto fail;
|
||||
|
||||
file = grub_file_open (filename,
|
||||
GRUB_FILE_TYPE_GRUB_MODULE);
|
||||
file = grub_file_open (filename);
|
||||
grub_free (filename);
|
||||
if (! file)
|
||||
goto fail;
|
||||
|
||||
@@ -193,7 +193,7 @@ grub_cmd_parttool (grub_command_t cmd __attribute__ ((unused)),
|
||||
{
|
||||
grub_file_t file;
|
||||
|
||||
file = grub_file_open (filename, GRUB_FILE_TYPE_GRUB_MODULE_LIST);
|
||||
file = grub_file_open (filename);
|
||||
if (file)
|
||||
{
|
||||
char *buf = 0;
|
||||
|
||||
@@ -81,8 +81,8 @@ iterate_device (const char *name, void *data)
|
||||
if (! buf)
|
||||
return 1;
|
||||
|
||||
file = grub_file_open (buf, GRUB_FILE_TYPE_FS_SEARCH
|
||||
| GRUB_FILE_TYPE_NO_DECOMPRESS);
|
||||
grub_file_filter_disable_compression ();
|
||||
file = grub_file_open (buf);
|
||||
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;
|
||||
file = grub_file_open (args[*argn + 1], GRUB_FILE_TYPE_GET_SIZE
|
||||
| GRUB_FILE_TYPE_NO_DECOMPRESS);
|
||||
grub_file_filter_disable_compression ();
|
||||
file = grub_file_open (args[*argn + 1]);
|
||||
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], GRUB_FILE_TYPE_TESTLOAD);
|
||||
file = grub_file_open (argv[0]);
|
||||
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], GRUB_FILE_TYPE_TESTLOAD);
|
||||
file = grub_file_open (args[0]);
|
||||
if (file == NULL)
|
||||
goto quit;
|
||||
|
||||
|
||||
@@ -30,10 +30,16 @@
|
||||
#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
|
||||
@@ -439,26 +445,22 @@ 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_init (struct grub_pubkey_context *ctxt, grub_file_t sig)
|
||||
grub_verify_signature_real (char *buf, grub_size_t size,
|
||||
grub_file_t f, grub_file_t sig,
|
||||
struct grub_public_key *pkey)
|
||||
{
|
||||
grub_size_t len;
|
||||
grub_uint8_t v;
|
||||
grub_uint8_t h;
|
||||
grub_uint8_t t;
|
||||
grub_err_t err;
|
||||
grub_uint8_t type = 0;
|
||||
grub_uint8_t pk;
|
||||
|
||||
grub_memset (ctxt, 0, sizeof (*ctxt));
|
||||
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;
|
||||
|
||||
err = read_packet_header (sig, &type, &len);
|
||||
if (err)
|
||||
@@ -467,18 +469,18 @@ grub_verify_signature_init (struct grub_pubkey_context *ctxt, grub_file_t sig)
|
||||
if (type != 0x2)
|
||||
return grub_error (GRUB_ERR_BAD_SIGNATURE, N_("bad signature"));
|
||||
|
||||
if (grub_file_read (sig, &ctxt->v, sizeof (ctxt->v)) != sizeof (ctxt->v))
|
||||
if (grub_file_read (sig, &v, sizeof (v)) != sizeof (v))
|
||||
return grub_error (GRUB_ERR_BAD_SIGNATURE, N_("bad signature"));
|
||||
|
||||
if (ctxt->v != 4)
|
||||
if (v != 4)
|
||||
return grub_error (GRUB_ERR_BAD_SIGNATURE, N_("bad signature"));
|
||||
|
||||
if (grub_file_read (sig, &ctxt->v4, sizeof (ctxt->v4)) != sizeof (ctxt->v4))
|
||||
if (grub_file_read (sig, &v4, sizeof (v4)) != sizeof (v4))
|
||||
return grub_error (GRUB_ERR_BAD_SIGNATURE, N_("bad signature"));
|
||||
|
||||
h = ctxt->v4.hash;
|
||||
t = ctxt->v4.type;
|
||||
pk = ctxt->v4.pkeyalgo;
|
||||
h = v4.hash;
|
||||
t = v4.type;
|
||||
pk = v4.pkeyalgo;
|
||||
|
||||
if (t != 0)
|
||||
return grub_error (GRUB_ERR_BAD_SIGNATURE, N_("bad signature"));
|
||||
@@ -489,232 +491,183 @@ grub_verify_signature_init (struct grub_pubkey_context *ctxt, grub_file_t sig)
|
||||
if (pk >= ARRAY_SIZE (pkalgos) || pkalgos[pk].name == NULL)
|
||||
return grub_error (GRUB_ERR_BAD_SIGNATURE, N_("bad signature"));
|
||||
|
||||
ctxt->hash = grub_crypto_lookup_md_by_name (hashes[h]);
|
||||
if (!ctxt->hash)
|
||||
hash = grub_crypto_lookup_md_by_name (hashes[h]);
|
||||
if (!hash)
|
||||
return grub_error (GRUB_ERR_BAD_SIGNATURE, "hash `%s' not loaded", hashes[h]);
|
||||
|
||||
grub_dprintf ("crypt", "alive\n");
|
||||
|
||||
ctxt->sig = sig;
|
||||
|
||||
ctxt->hash_context = grub_zalloc (ctxt->hash->contextsize);
|
||||
if (!ctxt->hash_context)
|
||||
return grub_errno;
|
||||
|
||||
ctxt->hash->init (ctxt->hash_context);
|
||||
|
||||
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)
|
||||
{
|
||||
r = grub_file_read (ctxt->sig, readbuf,
|
||||
rem < READBUF_SIZE ? rem : READBUF_SIZE);
|
||||
if (r < 0)
|
||||
goto fail;
|
||||
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)
|
||||
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;
|
||||
|
||||
context = grub_zalloc (hash->contextsize);
|
||||
readbuf = grub_zalloc (READBUF_SIZE);
|
||||
if (!context || !readbuf)
|
||||
goto fail;
|
||||
r = grub_file_read (ctxt->sig, readbuf, rem);
|
||||
if (r != rem)
|
||||
goto fail;
|
||||
for (ptr = readbuf; ptr < readbuf + rem; ptr += l)
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
hash->write (context, &v, sizeof (v));
|
||||
hash->write (context, &v4, sizeof (v4));
|
||||
while (rem)
|
||||
{
|
||||
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);
|
||||
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;
|
||||
{
|
||||
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 (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);
|
||||
}
|
||||
}
|
||||
|
||||
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))
|
||||
goto fail;
|
||||
if (grub_memcmp (hval, hash_start, sizeof (hash_start)) != 0)
|
||||
goto fail;
|
||||
|
||||
grub_dprintf ("crypt", "@ %x\n", (int)grub_file_tell (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 (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");
|
||||
|
||||
if (gcry_mpi_scan (&mpis[i], GCRYMPI_FMT_PGP,
|
||||
readbuf, lb + sizeof (grub_uint16_t), 0))
|
||||
goto fail;
|
||||
grub_dprintf ("crypt", "alive\n");
|
||||
}
|
||||
|
||||
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 (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;
|
||||
}
|
||||
|
||||
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;
|
||||
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");
|
||||
}
|
||||
|
||||
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 (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_free (readbuf);
|
||||
|
||||
return GRUB_ERR_NONE;
|
||||
|
||||
fail:
|
||||
grub_free (readbuf);
|
||||
if (!grub_errno)
|
||||
return grub_error (GRUB_ERR_BAD_SIGNATURE, N_("bad signature"));
|
||||
return grub_errno;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
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;
|
||||
return grub_verify_signature_real (0, 0, f, sig, pkey);
|
||||
}
|
||||
|
||||
static grub_err_t
|
||||
@@ -727,12 +680,10 @@ grub_cmd_trust (grub_extcmd_context_t ctxt,
|
||||
if (argc < 1)
|
||||
return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("one argument expected"));
|
||||
|
||||
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));
|
||||
grub_file_filter_disable_compression ();
|
||||
if (ctxt->state[OPTION_SKIP_SIG].set)
|
||||
grub_file_filter_disable_pubkey ();
|
||||
pkf = grub_file_open (args[0]);
|
||||
if (!pkf)
|
||||
return grub_errno;
|
||||
pk = grub_load_public_key (pkf);
|
||||
@@ -820,12 +771,10 @@ grub_cmd_verify_signature (grub_extcmd_context_t ctxt,
|
||||
if (argc > 2)
|
||||
{
|
||||
grub_file_t pkf;
|
||||
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));
|
||||
grub_file_filter_disable_compression ();
|
||||
if (ctxt->state[OPTION_SKIP_SIG].set)
|
||||
grub_file_filter_disable_pubkey ();
|
||||
pkf = grub_file_open (args[2]);
|
||||
if (!pkf)
|
||||
return grub_errno;
|
||||
pk = grub_load_public_key (pkf);
|
||||
@@ -837,16 +786,16 @@ grub_cmd_verify_signature (grub_extcmd_context_t ctxt,
|
||||
grub_file_close (pkf);
|
||||
}
|
||||
|
||||
f = grub_file_open (args[0], GRUB_FILE_TYPE_VERIFY_SIGNATURE);
|
||||
grub_file_filter_disable_all ();
|
||||
f = grub_file_open (args[0]);
|
||||
if (!f)
|
||||
{
|
||||
err = grub_errno;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
sig = grub_file_open (args[1],
|
||||
GRUB_FILE_TYPE_SIGNATURE
|
||||
| GRUB_FILE_TYPE_NO_DECOMPRESS);
|
||||
grub_file_filter_disable_all ();
|
||||
sig = grub_file_open (args[1]);
|
||||
if (!sig)
|
||||
{
|
||||
err = grub_errno;
|
||||
@@ -866,52 +815,135 @@ 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
|
||||
grub_pubkey_init (grub_file_t io, enum grub_file_type type __attribute__ ((unused)),
|
||||
void **context, enum grub_verify_flags *flags)
|
||||
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_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)
|
||||
{
|
||||
*flags = GRUB_VERIFY_FLAGS_SKIP_VERIFICATION;
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
fsuf = grub_malloc (grub_strlen (io->name) + sizeof (".sig"));
|
||||
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"));
|
||||
if (!fsuf)
|
||||
return grub_errno;
|
||||
ptr = grub_stpcpy (fsuf, io->name);
|
||||
return NULL;
|
||||
ptr = grub_stpcpy (fsuf, filename);
|
||||
grub_memcpy (ptr, ".sig", sizeof (".sig"));
|
||||
|
||||
sig = grub_file_open (fsuf, GRUB_FILE_TYPE_SIGNATURE);
|
||||
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));
|
||||
grub_free (fsuf);
|
||||
if (!sig)
|
||||
return grub_errno;
|
||||
return NULL;
|
||||
|
||||
|
||||
struct grub_pubkey_context *ctxt = grub_malloc (sizeof (*ctxt));
|
||||
if (!ctxt)
|
||||
ret = grub_malloc (sizeof (*ret));
|
||||
if (!ret)
|
||||
{
|
||||
grub_file_close (sig);
|
||||
return grub_errno;
|
||||
return NULL;
|
||||
}
|
||||
err = grub_verify_signature_init (ctxt, sig);
|
||||
*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)
|
||||
{
|
||||
grub_file_close (sig);
|
||||
grub_free (ret);
|
||||
return NULL;
|
||||
}
|
||||
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);
|
||||
if (err)
|
||||
{
|
||||
grub_pubkey_close (ctxt);
|
||||
return err;
|
||||
verified_free (verified);
|
||||
grub_free (ret);
|
||||
return NULL;
|
||||
}
|
||||
*context = ctxt;
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
static grub_err_t
|
||||
grub_pubkey_fini (void *ctxt)
|
||||
{
|
||||
return grub_verify_signature_real (ctxt, NULL);
|
||||
verified->file = io;
|
||||
ret->data = verified;
|
||||
return ret;
|
||||
}
|
||||
|
||||
static char *
|
||||
@@ -935,16 +967,8 @@ 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;
|
||||
@@ -959,6 +983,8 @@ 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");
|
||||
@@ -1004,13 +1030,11 @@ 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_verifier_unregister (&grub_pubkey_verifier);
|
||||
grub_file_filter_unregister (GRUB_FILE_FILTER_PUBKEY);
|
||||
grub_unregister_extcmd (cmd);
|
||||
grub_unregister_extcmd (cmd_trust);
|
||||
grub_unregister_command (cmd_list);
|
||||
|
||||
@@ -1,186 +0,0 @@
|
||||
#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);
|
||||
}
|
||||
@@ -92,8 +92,7 @@ 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], GRUB_FILE_TYPE_LOOPBACK
|
||||
| GRUB_FILE_TYPE_NO_DECOMPRESS);
|
||||
file = grub_file_open (args[1]);
|
||||
if (! file)
|
||||
return grub_errno;
|
||||
|
||||
|
||||
@@ -187,7 +187,7 @@ grub_efiemu_load_file (const char *filename)
|
||||
grub_file_t file;
|
||||
grub_err_t err;
|
||||
|
||||
file = grub_file_open (filename, GRUB_FILE_TYPE_GRUB_MODULE);
|
||||
file = grub_file_open (filename);
|
||||
if (! file)
|
||||
return grub_errno;
|
||||
|
||||
|
||||
@@ -418,7 +418,7 @@ grub_font_load (const char *filename)
|
||||
#endif
|
||||
|
||||
if (filename[0] == '(' || filename[0] == '/' || filename[0] == '+')
|
||||
file = grub_buffile_open (filename, GRUB_FILE_TYPE_FONT, 1024);
|
||||
file = grub_buffile_open (filename, 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, GRUB_FILE_TYPE_FONT, 1024);
|
||||
file = grub_buffile_open (fullname, 1024);
|
||||
grub_free (fullname);
|
||||
}
|
||||
if (!file)
|
||||
|
||||
@@ -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], GRUB_FILE_TYPE_ZFS_ENCRYPTION_KEY);
|
||||
file = grub_file_open (args[0]);
|
||||
if (!file)
|
||||
return grub_errno;
|
||||
real_size = grub_file_read (file, buf, 1024);
|
||||
|
||||
@@ -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, GRUB_FILE_TYPE_GETTEXT_CATALOG);
|
||||
fd = grub_file_open (filename);
|
||||
|
||||
if (!fd)
|
||||
return grub_errno;
|
||||
|
||||
@@ -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, GRUB_FILE_TYPE_THEME);
|
||||
file = grub_file_open (theme_path);
|
||||
if (! file)
|
||||
{
|
||||
grub_free (p.theme_dir);
|
||||
|
||||
@@ -43,8 +43,7 @@ typedef struct grub_bufio *grub_bufio_t;
|
||||
static struct grub_fs grub_bufio_fs;
|
||||
|
||||
grub_file_t
|
||||
grub_bufio_open (grub_file_t io,
|
||||
grub_size_t size)
|
||||
grub_bufio_open (grub_file_t io, int size)
|
||||
{
|
||||
grub_file_t file;
|
||||
grub_bufio_t bufio = 0;
|
||||
@@ -58,7 +57,7 @@ grub_bufio_open (grub_file_t io,
|
||||
else if (size > GRUB_BUFIO_MAX_SIZE)
|
||||
size = GRUB_BUFIO_MAX_SIZE;
|
||||
|
||||
if (size > io->size)
|
||||
if ((size < 0) || ((unsigned) size > io->size))
|
||||
size = ((io->size > GRUB_BUFIO_MAX_SIZE) ? GRUB_BUFIO_MAX_SIZE :
|
||||
io->size);
|
||||
|
||||
@@ -82,12 +81,11 @@ grub_bufio_open (grub_file_t io,
|
||||
}
|
||||
|
||||
grub_file_t
|
||||
grub_buffile_open (const char *name, enum grub_file_type type,
|
||||
grub_size_t size)
|
||||
grub_buffile_open (const char *name, int size)
|
||||
{
|
||||
grub_file_t io, file;
|
||||
|
||||
io = grub_file_open (name, type);
|
||||
io = grub_file_open (name);
|
||||
if (! io)
|
||||
return 0;
|
||||
|
||||
|
||||
@@ -1125,14 +1125,11 @@ 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, enum grub_file_type type)
|
||||
grub_gzio_open (grub_file_t io, const char *name __attribute__ ((unused)))
|
||||
{
|
||||
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,14 +407,12 @@ CORRUPTED:
|
||||
}
|
||||
|
||||
static grub_file_t
|
||||
grub_lzopio_open (grub_file_t io, enum grub_file_type type)
|
||||
grub_lzopio_open (grub_file_t io,
|
||||
const char *name __attribute__ ((unused)))
|
||||
{
|
||||
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,8 +69,7 @@ grub_file_offset_close (grub_file_t file)
|
||||
}
|
||||
|
||||
grub_file_t
|
||||
grub_file_offset_open (grub_file_t parent, enum grub_file_type type,
|
||||
grub_off_t start, grub_off_t size)
|
||||
grub_file_offset_open (grub_file_t parent, grub_off_t start, grub_off_t size)
|
||||
{
|
||||
struct grub_offset_file *off_data;
|
||||
grub_file_t off_file, last_off_file;
|
||||
@@ -96,10 +95,10 @@ grub_file_offset_open (grub_file_t parent, enum grub_file_type type,
|
||||
last_off_file = NULL;
|
||||
for (filter = GRUB_FILE_FILTER_COMPRESSION_FIRST;
|
||||
off_file && filter <= GRUB_FILE_FILTER_COMPRESSION_LAST; filter++)
|
||||
if (grub_file_filters[filter])
|
||||
if (grub_file_filters_enabled[filter])
|
||||
{
|
||||
last_off_file = off_file;
|
||||
off_file = grub_file_filters[filter] (off_file, type);
|
||||
off_file = grub_file_filters_enabled[filter] (off_file, parent->name);
|
||||
}
|
||||
|
||||
if (!off_file)
|
||||
|
||||
@@ -169,14 +169,12 @@ ERROR:
|
||||
}
|
||||
|
||||
static grub_file_t
|
||||
grub_xzio_open (grub_file_t io, enum grub_file_type type)
|
||||
grub_xzio_open (grub_file_t io,
|
||||
const char *name __attribute__ ((unused)))
|
||||
{
|
||||
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;
|
||||
|
||||
@@ -29,8 +29,6 @@ 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,
|
||||
@@ -254,38 +252,6 @@ 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,18 +33,6 @@
|
||||
# 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
|
||||
|
||||
@@ -1,40 +0,0 @@
|
||||
/*
|
||||
* 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;
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
/*
|
||||
* 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
|
||||
|
||||
@@ -1,59 +0,0 @@
|
||||
/*
|
||||
* 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;
|
||||
}
|
||||
|
||||
@@ -1,151 +0,0 @@
|
||||
/*
|
||||
* 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)))
|
||||
{
|
||||
}
|
||||
@@ -1,101 +0,0 @@
|
||||
/*
|
||||
* 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");
|
||||
}
|
||||
@@ -1,70 +0,0 @@
|
||||
/* 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;
|
||||
}
|
||||
@@ -24,7 +24,6 @@
|
||||
* 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:
|
||||
*
|
||||
@@ -87,7 +86,7 @@ FUNCTION(codestart)
|
||||
@ Stack pointer used as start address for signature probing
|
||||
mov r12, sp
|
||||
adr sp, entry_state
|
||||
push {r0-r12,lr} @ store U-Boot context (sp in r12)
|
||||
push {r1-r12,lr} @ store U-Boot context (sp in r12)
|
||||
|
||||
adr r1, _start
|
||||
ldr r0, bss_start_ptr @ src
|
||||
@@ -128,8 +127,6 @@ reloc_done:
|
||||
|
||||
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
|
||||
@@ -139,7 +136,6 @@ reloc_done:
|
||||
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
|
||||
@@ -157,21 +153,69 @@ reloc_done:
|
||||
|
||||
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/coreboot context stack space
|
||||
VARIABLE(grub_arm_saved_registers)
|
||||
.long 0 @ r0
|
||||
@ U-boot context stack space
|
||||
entry_state_end:
|
||||
VARIABLE(grub_uboot_machine_type)
|
||||
.long 0 @ r1
|
||||
VARIABLE(grub_uboot_boot_data)
|
||||
.long 0 @ r2
|
||||
.long 0 @ r3
|
||||
.long 0 @ r4
|
||||
.long 0 @ r5
|
||||
.long 0 @ r6
|
||||
.long 0 @ r7
|
||||
.long 0 @ r8
|
||||
.long 0 @ r9
|
||||
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 @ r10
|
||||
.long 0 @ r11
|
||||
.long 0 @ sp
|
||||
VARIABLE(grub_uboot_search_hint)@ U-Boot stack pointer -
|
||||
.long 0 @ also API signature address hint.
|
||||
.long 0 @ lr
|
||||
entry_state:
|
||||
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
|
||||
@@ -1,73 +0,0 @@
|
||||
/*
|
||||
* 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
|
||||
@@ -1,72 +0,0 @@
|
||||
/*
|
||||
* 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;
|
||||
}
|
||||
@@ -688,7 +688,7 @@ grub_dl_load_file (const char *filename)
|
||||
|
||||
grub_boot_time ("Loading module %s", filename);
|
||||
|
||||
file = grub_file_open (filename, GRUB_FILE_TYPE_GRUB_MODULE);
|
||||
file = grub_file_open (filename);
|
||||
if (! file)
|
||||
return 0;
|
||||
|
||||
|
||||
@@ -136,12 +136,12 @@ fail:
|
||||
}
|
||||
|
||||
grub_elf_t
|
||||
grub_elf_open (const char *name, enum grub_file_type type)
|
||||
grub_elf_open (const char *name)
|
||||
{
|
||||
grub_file_t file;
|
||||
grub_elf_t elf;
|
||||
|
||||
file = grub_file_open (name, type);
|
||||
file = grub_file_open (name);
|
||||
if (! file)
|
||||
return 0;
|
||||
|
||||
|
||||
@@ -28,7 +28,8 @@
|
||||
|
||||
void (*EXPORT_VAR (grub_grubnet_fini)) (void);
|
||||
|
||||
grub_file_filter_t grub_file_filters[GRUB_FILE_FILTER_MAX];
|
||||
grub_file_filter_t grub_file_filters_all[GRUB_FILE_FILTER_MAX];
|
||||
grub_file_filter_t grub_file_filters_enabled[GRUB_FILE_FILTER_MAX];
|
||||
|
||||
/* Get the device part of the filename NAME. It is enclosed by parentheses. */
|
||||
char *
|
||||
@@ -58,7 +59,7 @@ grub_file_get_device_name (const char *name)
|
||||
}
|
||||
|
||||
grub_file_t
|
||||
grub_file_open (const char *name, enum grub_file_type type)
|
||||
grub_file_open (const char *name)
|
||||
{
|
||||
grub_device_t device = 0;
|
||||
grub_file_t file = 0, last_file = 0;
|
||||
@@ -113,20 +114,18 @@ grub_file_open (const char *name, enum grub_file_type type)
|
||||
file->name = grub_strdup (name);
|
||||
grub_errno = GRUB_ERR_NONE;
|
||||
|
||||
for (filter = 0; file && filter < ARRAY_SIZE (grub_file_filters);
|
||||
for (filter = 0; file && filter < ARRAY_SIZE (grub_file_filters_enabled);
|
||||
filter++)
|
||||
if (grub_file_filters[filter])
|
||||
if (grub_file_filters_enabled[filter])
|
||||
{
|
||||
last_file = file;
|
||||
file = grub_file_filters[filter] (file, type);
|
||||
if (file && file != last_file)
|
||||
{
|
||||
file->name = grub_strdup (name);
|
||||
grub_errno = GRUB_ERR_NONE;
|
||||
}
|
||||
file = grub_file_filters_enabled[filter] (file, name);
|
||||
}
|
||||
if (!file)
|
||||
grub_file_close (last_file);
|
||||
|
||||
grub_memcpy (grub_file_filters_enabled, grub_file_filters_all,
|
||||
sizeof (grub_file_filters_enabled));
|
||||
|
||||
return file;
|
||||
|
||||
@@ -138,6 +137,9 @@ grub_file_open (const char *name, enum grub_file_type type)
|
||||
|
||||
grub_free (file);
|
||||
|
||||
grub_memcpy (grub_file_filters_enabled, grub_file_filters_all,
|
||||
sizeof (grub_file_filters_enabled));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
*/
|
||||
|
||||
#include <grub/i386/coreboot/memory.h>
|
||||
#include <grub/coreboot/lbio.h>
|
||||
#include <grub/i386/coreboot/lbio.h>
|
||||
#include <grub/types.h>
|
||||
#include <grub/err.h>
|
||||
#include <grub/misc.h>
|
||||
@@ -25,20 +25,59 @@
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
grub_linuxbios_table_header_t
|
||||
grub_linuxbios_get_tables (void)
|
||||
/* Helper for grub_linuxbios_table_iterate. */
|
||||
static int
|
||||
check_signature (grub_linuxbios_table_header_t tbl_header)
|
||||
{
|
||||
grub_linuxbios_table_header_t table_header;
|
||||
/* Assuming table_header is aligned to its size (8 bytes). */
|
||||
for (table_header = (grub_linuxbios_table_header_t) 0x500;
|
||||
table_header < (grub_linuxbios_table_header_t) 0x1000; table_header++)
|
||||
if (grub_linuxbios_check_signature (table_header))
|
||||
return table_header;
|
||||
|
||||
for (table_header = (grub_linuxbios_table_header_t) 0xf0000;
|
||||
table_header < (grub_linuxbios_table_header_t) 0x100000; table_header++)
|
||||
if (grub_linuxbios_check_signature (table_header))
|
||||
return table_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_table_item_t table_item;
|
||||
|
||||
/* Assuming table_header is aligned to its size (8 bytes). */
|
||||
|
||||
for (table_header = (grub_linuxbios_table_header_t) 0x500;
|
||||
table_header < (grub_linuxbios_table_header_t) 0x1000; table_header++)
|
||||
if (check_signature (table_header))
|
||||
goto signature_found;
|
||||
|
||||
for (table_header = (grub_linuxbios_table_header_t) 0xf0000;
|
||||
table_header < (grub_linuxbios_table_header_t) 0x100000; table_header++)
|
||||
if (check_signature (table_header))
|
||||
goto signature_found;
|
||||
|
||||
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
|
||||
&& 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/memory.h>
|
||||
#include <grub/coreboot/lbio.h>
|
||||
#include <grub/machine/memory.h>
|
||||
#include <grub/machine/lbio.h>
|
||||
#include <grub/types.h>
|
||||
#include <grub/err.h>
|
||||
#include <grub/misc.h>
|
||||
@@ -49,7 +49,6 @@ 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)
|
||||
@@ -76,7 +75,6 @@ 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
|
||||
@@ -391,13 +391,12 @@ grub_strtoull (const char *str, char **end, int base)
|
||||
unsigned long digit;
|
||||
|
||||
digit = grub_tolower (*str) - '0';
|
||||
if (digit >= 'a' - '0')
|
||||
digit += '0' - 'a' + 10;
|
||||
else if (digit > 9)
|
||||
break;
|
||||
|
||||
if (digit >= (unsigned long) base)
|
||||
break;
|
||||
if (digit > 9)
|
||||
{
|
||||
digit += '0' - 'a' + 10;
|
||||
if (digit >= (unsigned long) base)
|
||||
break;
|
||||
}
|
||||
|
||||
found = 1;
|
||||
|
||||
|
||||
@@ -36,14 +36,30 @@
|
||||
extern char __bss_start[];
|
||||
extern char _end[];
|
||||
extern grub_size_t grub_total_module_size;
|
||||
extern int (*grub_uboot_syscall_ptr) (int, int *, ...);
|
||||
static unsigned long timer_start;
|
||||
|
||||
extern grub_uint32_t grub_uboot_machine_type;
|
||||
extern grub_addr_t grub_uboot_boot_data;
|
||||
|
||||
void
|
||||
grub_exit (void)
|
||||
{
|
||||
grub_uboot_return (0);
|
||||
}
|
||||
|
||||
grub_uint32_t
|
||||
grub_uboot_get_machine_type (void)
|
||||
{
|
||||
return grub_uboot_machine_type;
|
||||
}
|
||||
|
||||
grub_addr_t
|
||||
grub_uboot_get_boot_data (void)
|
||||
{
|
||||
return grub_uboot_boot_data;
|
||||
}
|
||||
|
||||
static grub_uint64_t
|
||||
uboot_timer_ms (void)
|
||||
{
|
||||
|
||||
@@ -39,13 +39,48 @@
|
||||
* returns: 0 if the call not found, 1 if serviced
|
||||
*/
|
||||
|
||||
extern int (*grub_uboot_syscall_ptr) (int, int *, ...);
|
||||
extern int grub_uboot_syscall (int, int *, ...);
|
||||
extern grub_addr_t grub_uboot_search_hint;
|
||||
|
||||
static struct sys_info uboot_sys_info;
|
||||
static struct mem_region uboot_mem_info[5];
|
||||
static struct device_info * devices;
|
||||
static int num_devices;
|
||||
|
||||
int
|
||||
grub_uboot_api_init (void)
|
||||
{
|
||||
struct api_signature *start, *end;
|
||||
struct api_signature *p;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/*
|
||||
* All functions below are wrappers around the grub_uboot_syscall() function
|
||||
|
||||
@@ -62,13 +62,12 @@ unsigned int grub_loader_cmdline_size (int argc, char *argv[])
|
||||
return size;
|
||||
}
|
||||
|
||||
grub_err_t
|
||||
grub_create_loader_cmdline (int argc, char *argv[], char *buf,
|
||||
grub_size_t size, enum grub_verify_string_type type)
|
||||
int grub_create_loader_cmdline (int argc, char *argv[], char *buf,
|
||||
grub_size_t size)
|
||||
{
|
||||
int i, space;
|
||||
unsigned int arg_size;
|
||||
char *c, *orig_buf = buf;
|
||||
char *c;
|
||||
|
||||
for (i = 0; i < argc; i++)
|
||||
{
|
||||
@@ -105,5 +104,5 @@ grub_create_loader_cmdline (int argc, char *argv[], char *buf,
|
||||
|
||||
*buf = 0;
|
||||
|
||||
return grub_verify_string (orig_buf, type);
|
||||
return i;
|
||||
}
|
||||
|
||||
@@ -1,32 +0,0 @@
|
||||
/*
|
||||
* 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/misc.h>
|
||||
#include <grub/mm.h>
|
||||
#include <grub/kernel.h>
|
||||
#include <grub/loader.h>
|
||||
|
||||
void
|
||||
grub_reboot (void)
|
||||
{
|
||||
grub_machine_fini (GRUB_LOADER_FLAG_NORETURN);
|
||||
|
||||
/* Just stop here */
|
||||
|
||||
while (1);
|
||||
}
|
||||
@@ -102,13 +102,13 @@ static grub_uint32_t *get_next_node (const void *fdt, char *node_name)
|
||||
static int get_mem_rsvmap_size (const void *fdt)
|
||||
{
|
||||
int size = 0;
|
||||
grub_unaligned_uint64_t *ptr = (void *) ((grub_addr_t) fdt
|
||||
+ grub_fdt_get_off_mem_rsvmap (fdt));
|
||||
grub_uint64_t *ptr = (void *) ((grub_addr_t) fdt
|
||||
+ grub_fdt_get_off_mem_rsvmap (fdt));
|
||||
|
||||
do
|
||||
{
|
||||
size += 2 * sizeof(*ptr);
|
||||
if (!ptr[0].val && !ptr[1].val)
|
||||
if (!*ptr && !*(ptr + 1))
|
||||
return size;
|
||||
ptr += 2;
|
||||
} while ((grub_addr_t) ptr <= (grub_addr_t) fdt + grub_fdt_get_totalsize (fdt)
|
||||
@@ -229,7 +229,7 @@ static int rearrange_blocks (void *fdt, unsigned int clearance)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static grub_uint32_t *find_prop (const void *fdt, unsigned int nodeoffset,
|
||||
static grub_uint32_t *find_prop (void *fdt, unsigned int nodeoffset,
|
||||
const char *name)
|
||||
{
|
||||
grub_uint32_t *prop = (void *) ((grub_addr_t) fdt
|
||||
@@ -268,9 +268,9 @@ static grub_uint32_t *find_prop (const void *fdt, unsigned int nodeoffset,
|
||||
the size allocated for the FDT; if this function is called before the other
|
||||
functions in this file and returns success, the other functions are
|
||||
guaranteed not to access memory locations outside the allocated memory. */
|
||||
int grub_fdt_check_header_nosize (const void *fdt)
|
||||
int grub_fdt_check_header_nosize (void *fdt)
|
||||
{
|
||||
if (((grub_addr_t) fdt & 0x3) || (grub_fdt_get_magic (fdt) != FDT_MAGIC)
|
||||
if (((grub_addr_t) fdt & 0x7) || (grub_fdt_get_magic (fdt) != FDT_MAGIC)
|
||||
|| (grub_fdt_get_version (fdt) < FDT_SUPPORTED_VERSION)
|
||||
|| (grub_fdt_get_last_comp_version (fdt) > FDT_SUPPORTED_VERSION)
|
||||
|| (grub_fdt_get_off_dt_struct (fdt) & 0x00000003)
|
||||
@@ -286,7 +286,7 @@ int grub_fdt_check_header_nosize (const void *fdt)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int grub_fdt_check_header (const void *fdt, unsigned int size)
|
||||
int grub_fdt_check_header (void *fdt, unsigned int size)
|
||||
{
|
||||
if (size < sizeof (grub_fdt_header_t)
|
||||
|| (grub_fdt_get_totalsize (fdt) > size)
|
||||
@@ -295,29 +295,41 @@ int grub_fdt_check_header (const void *fdt, unsigned int size)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const grub_uint32_t *
|
||||
advance_token (const void *fdt, const grub_uint32_t *token, const grub_uint32_t *end, int skip_current)
|
||||
/* Find a direct sub-node of a given parent node. */
|
||||
int grub_fdt_find_subnode (const void *fdt, unsigned int parentoffset,
|
||||
const char *name)
|
||||
{
|
||||
for (; token < end; skip_current = 0)
|
||||
grub_uint32_t *token, *end;
|
||||
char *node_name;
|
||||
|
||||
if (parentoffset & 0x3)
|
||||
return -1;
|
||||
token = (void *) ((grub_addr_t) fdt + grub_fdt_get_off_dt_struct(fdt)
|
||||
+ parentoffset);
|
||||
end = (void *) struct_end (fdt);
|
||||
if ((token >= end) || (grub_be_to_cpu32(*token) != FDT_BEGIN_NODE))
|
||||
return -1;
|
||||
SKIP_NODE_NAME(node_name, token, end);
|
||||
while (token < end)
|
||||
{
|
||||
switch (grub_be_to_cpu32 (*token))
|
||||
switch (grub_be_to_cpu32(*token))
|
||||
{
|
||||
case FDT_BEGIN_NODE:
|
||||
if (skip_current)
|
||||
{
|
||||
token = get_next_node (fdt, (char *) (token + 1));
|
||||
continue;
|
||||
}
|
||||
char *ptr;
|
||||
for (ptr = (char *) (token + 1); *ptr && ptr < (char *) end; ptr++);
|
||||
if (ptr >= (char *) end)
|
||||
return 0;
|
||||
return token;
|
||||
node_name = (char *) (token + 1);
|
||||
if (node_name + grub_strlen (name) >= (char *) end)
|
||||
return -1;
|
||||
if (!grub_strcmp (node_name, name))
|
||||
return (int) ((grub_addr_t) token - (grub_addr_t) fdt
|
||||
- grub_fdt_get_off_dt_struct (fdt));
|
||||
token = get_next_node (fdt, node_name);
|
||||
if (!token)
|
||||
return -1;
|
||||
break;
|
||||
case FDT_PROP:
|
||||
/* Skip property token and following data (len, nameoff and property
|
||||
value). */
|
||||
if (token >= end - 1)
|
||||
return 0;
|
||||
return -1;
|
||||
token += prop_entry_size(grub_be_to_cpu32(*(token + 1)))
|
||||
/ sizeof(*token);
|
||||
break;
|
||||
@@ -325,74 +337,10 @@ advance_token (const void *fdt, const grub_uint32_t *token, const grub_uint32_t
|
||||
token++;
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int grub_fdt_next_node (const void *fdt, unsigned int currentoffset)
|
||||
{
|
||||
const grub_uint32_t *token = (const grub_uint32_t *) fdt + (currentoffset + grub_fdt_get_off_dt_struct (fdt)) / 4;
|
||||
token = advance_token (fdt, token, (const void *) struct_end (fdt), 1);
|
||||
if (!token)
|
||||
return -1;
|
||||
return (int) ((grub_addr_t) token - (grub_addr_t) fdt
|
||||
- grub_fdt_get_off_dt_struct (fdt));
|
||||
}
|
||||
|
||||
int grub_fdt_first_node (const void *fdt, unsigned int parentoffset)
|
||||
{
|
||||
const grub_uint32_t *token, *end;
|
||||
char *node_name;
|
||||
|
||||
if (parentoffset & 0x3)
|
||||
return -1;
|
||||
token = (const void *) ((grub_addr_t) fdt + grub_fdt_get_off_dt_struct(fdt)
|
||||
+ parentoffset);
|
||||
end = (const void *) struct_end (fdt);
|
||||
if ((token >= end) || (grub_be_to_cpu32(*token) != FDT_BEGIN_NODE))
|
||||
return -1;
|
||||
SKIP_NODE_NAME(node_name, token, end);
|
||||
token = advance_token (fdt, token, end, 0);
|
||||
if (!token)
|
||||
return -1;
|
||||
return (int) ((grub_addr_t) token - (grub_addr_t) fdt
|
||||
- grub_fdt_get_off_dt_struct (fdt));
|
||||
}
|
||||
|
||||
/* Find a direct sub-node of a given parent node. */
|
||||
int grub_fdt_find_subnode (const void *fdt, unsigned int parentoffset,
|
||||
const char *name)
|
||||
{
|
||||
const grub_uint32_t *token, *end;
|
||||
const char *node_name;
|
||||
int skip_current = 0;
|
||||
|
||||
if (parentoffset & 0x3)
|
||||
return -1;
|
||||
token = (const void *) ((grub_addr_t) fdt + grub_fdt_get_off_dt_struct(fdt)
|
||||
+ parentoffset);
|
||||
end = (const void *) struct_end (fdt);
|
||||
if ((token >= end) || (grub_be_to_cpu32(*token) != FDT_BEGIN_NODE))
|
||||
return -1;
|
||||
SKIP_NODE_NAME(node_name, token, end);
|
||||
while (1) {
|
||||
token = advance_token (fdt, token, end, skip_current);
|
||||
if (!token)
|
||||
return -1;
|
||||
skip_current = 1;
|
||||
node_name = (const char *) token + 4;
|
||||
if (grub_strcmp (node_name, name) == 0)
|
||||
return (int) ((grub_addr_t) token - (grub_addr_t) fdt
|
||||
- grub_fdt_get_off_dt_struct (fdt));
|
||||
}
|
||||
}
|
||||
|
||||
const char *
|
||||
grub_fdt_get_nodename (const void *fdt, unsigned int nodeoffset)
|
||||
{
|
||||
return (const char *) fdt + grub_fdt_get_off_dt_struct(fdt) + nodeoffset + 4;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int grub_fdt_add_subnode (void *fdt, unsigned int parentoffset,
|
||||
@@ -411,24 +359,6 @@ int grub_fdt_add_subnode (void *fdt, unsigned int parentoffset,
|
||||
return add_subnode (fdt, parentoffset, name);
|
||||
}
|
||||
|
||||
const void *
|
||||
grub_fdt_get_prop (const void *fdt, unsigned int nodeoffset, const char *name,
|
||||
grub_uint32_t *len)
|
||||
{
|
||||
grub_uint32_t *prop;
|
||||
if ((nodeoffset >= grub_fdt_get_size_dt_struct (fdt)) || (nodeoffset & 0x3)
|
||||
|| (grub_be_to_cpu32(*(grub_uint32_t *) ((grub_addr_t) fdt
|
||||
+ grub_fdt_get_off_dt_struct (fdt) + nodeoffset))
|
||||
!= FDT_BEGIN_NODE))
|
||||
return 0;
|
||||
prop = find_prop (fdt, nodeoffset, name);
|
||||
if (!prop)
|
||||
return 0;
|
||||
if (len)
|
||||
*len = grub_be_to_cpu32 (*(prop + 1));
|
||||
return prop + 3;
|
||||
}
|
||||
|
||||
int grub_fdt_set_prop (void *fdt, unsigned int nodeoffset, const char *name,
|
||||
const void *val, grub_uint32_t len)
|
||||
{
|
||||
|
||||
@@ -696,7 +696,7 @@ syslinux_parse_real (struct syslinux_menu *menu)
|
||||
char *buf = NULL;
|
||||
grub_err_t err = GRUB_ERR_NONE;
|
||||
|
||||
file = grub_file_open (menu->filename, GRUB_FILE_TYPE_CONFIG);
|
||||
file = grub_file_open (menu->filename);
|
||||
if (!file)
|
||||
return grub_errno;
|
||||
while ((grub_free (buf), buf = grub_file_getline (file)))
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
#include <grub/types.h>
|
||||
#include <grub/symbol.h>
|
||||
#include <grub/uboot/uboot.h>
|
||||
#include <grub/datetime.h>
|
||||
#include <grub/dl.h>
|
||||
|
||||
@@ -29,12 +30,12 @@ grub_err_t
|
||||
grub_get_datetime (struct grub_datetime *datetime __attribute__ ((unused)))
|
||||
{
|
||||
return grub_error (GRUB_ERR_INVALID_COMMAND,
|
||||
"can\'t get datetime on this machine");
|
||||
"can\'t get datetime using U-Boot");
|
||||
}
|
||||
|
||||
grub_err_t
|
||||
grub_set_datetime (struct grub_datetime * datetime __attribute__ ((unused)))
|
||||
{
|
||||
return grub_error (GRUB_ERR_INVALID_COMMAND,
|
||||
"can\'t set datetime on this machine");
|
||||
"can\'t set datetime using U-Boot");
|
||||
}
|
||||
@@ -28,7 +28,6 @@
|
||||
#include <grub/cpu/linux.h>
|
||||
#include <grub/lib/cmdline.h>
|
||||
#include <grub/linux.h>
|
||||
#include <grub/verify.h>
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
@@ -43,7 +42,7 @@ static grub_size_t linux_size;
|
||||
static char *linux_args;
|
||||
|
||||
static grub_uint32_t machine_type;
|
||||
static const void *current_fdt;
|
||||
static void *fdt_addr;
|
||||
|
||||
typedef void (*kernel_entry_t) (int, unsigned long, void *);
|
||||
|
||||
@@ -55,9 +54,9 @@ typedef void (*kernel_entry_t) (int, unsigned long, void *);
|
||||
#define LINUX_FDT_PHYS_OFFSET (LINUX_INITRD_PHYS_OFFSET - 0x10000)
|
||||
|
||||
static grub_size_t
|
||||
get_atag_size (const grub_uint32_t *atag)
|
||||
get_atag_size (grub_uint32_t *atag)
|
||||
{
|
||||
const grub_uint32_t *atag0 = atag;
|
||||
grub_uint32_t *atag0 = atag;
|
||||
while (atag[0] && atag[1])
|
||||
atag += atag[0];
|
||||
return atag - atag0;
|
||||
@@ -69,11 +68,10 @@ get_atag_size (const grub_uint32_t *atag)
|
||||
* Merges in command line parameters and sets up initrd addresses.
|
||||
*/
|
||||
static grub_err_t
|
||||
linux_prepare_atag (void *target_atag)
|
||||
linux_prepare_atag (void)
|
||||
{
|
||||
const grub_uint32_t *atag_orig = (const grub_uint32_t *) current_fdt;
|
||||
grub_uint32_t *tmp_atag, *to;
|
||||
const grub_uint32_t *from;
|
||||
grub_uint32_t *atag_orig = (grub_uint32_t *) fdt_addr;
|
||||
grub_uint32_t *tmp_atag, *from, *to;
|
||||
grub_size_t tmp_size;
|
||||
grub_size_t arg_size = grub_strlen (linux_args);
|
||||
char *cmdline_orig = NULL;
|
||||
@@ -144,7 +142,7 @@ linux_prepare_atag (void *target_atag)
|
||||
to += 2;
|
||||
|
||||
/* Copy updated FDT to its launch location */
|
||||
grub_memcpy (target_atag, tmp_atag, sizeof (grub_uint32_t) * (to - tmp_atag));
|
||||
grub_memcpy (atag_orig, tmp_atag, sizeof (grub_uint32_t) * (to - tmp_atag));
|
||||
grub_free (tmp_atag);
|
||||
|
||||
grub_dprintf ("loader", "ATAG updated for Linux boot\n");
|
||||
@@ -158,19 +156,19 @@ linux_prepare_atag (void *target_atag)
|
||||
* Merges in command line parameters and sets up initrd addresses.
|
||||
*/
|
||||
static grub_err_t
|
||||
linux_prepare_fdt (void *target_fdt)
|
||||
linux_prepare_fdt (void)
|
||||
{
|
||||
int node;
|
||||
int retval;
|
||||
int tmp_size;
|
||||
void *tmp_fdt;
|
||||
|
||||
tmp_size = grub_fdt_get_totalsize (current_fdt) + 0x100 + grub_strlen (linux_args);
|
||||
tmp_size = grub_fdt_get_totalsize (fdt_addr) + 0x100 + grub_strlen (linux_args);
|
||||
tmp_fdt = grub_malloc (tmp_size);
|
||||
if (!tmp_fdt)
|
||||
return grub_errno;
|
||||
|
||||
grub_memcpy (tmp_fdt, current_fdt, grub_fdt_get_totalsize (current_fdt));
|
||||
grub_memcpy (tmp_fdt, fdt_addr, grub_fdt_get_totalsize (fdt_addr));
|
||||
grub_fdt_set_totalsize (tmp_fdt, tmp_size);
|
||||
|
||||
/* Find or create '/chosen' node */
|
||||
@@ -211,7 +209,7 @@ linux_prepare_fdt (void *target_fdt)
|
||||
}
|
||||
|
||||
/* Copy updated FDT to its launch location */
|
||||
grub_memcpy (target_fdt, tmp_fdt, tmp_size);
|
||||
grub_memcpy (fdt_addr, tmp_fdt, tmp_size);
|
||||
grub_free (tmp_fdt);
|
||||
|
||||
grub_dprintf ("loader", "FDT updated for Linux boot\n");
|
||||
@@ -228,17 +226,16 @@ linux_boot (void)
|
||||
{
|
||||
kernel_entry_t linuxmain;
|
||||
int fdt_valid, atag_valid;
|
||||
void *target_fdt = 0;
|
||||
|
||||
fdt_valid = (current_fdt && grub_fdt_check_header_nosize (current_fdt) == 0);
|
||||
atag_valid = ((((const grub_uint16_t *) current_fdt)[3] & ~3) == 0x5440
|
||||
&& *((const grub_uint32_t *) current_fdt));
|
||||
fdt_valid = (fdt_addr && grub_fdt_check_header_nosize (fdt_addr) == 0);
|
||||
atag_valid = ((((grub_uint16_t *) fdt_addr)[3] & ~3) == 0x5440
|
||||
&& *((grub_uint32_t *) fdt_addr));
|
||||
grub_dprintf ("loader", "atag: %p, %x, %x, %s, %s\n",
|
||||
current_fdt,
|
||||
((const grub_uint16_t *) current_fdt)[3],
|
||||
*((const grub_uint32_t *) current_fdt),
|
||||
(const char *) current_fdt,
|
||||
(const char *) current_fdt + 1);
|
||||
fdt_addr,
|
||||
((grub_uint16_t *) fdt_addr)[3],
|
||||
*((grub_uint32_t *) fdt_addr),
|
||||
(char *) fdt_addr,
|
||||
(char *) fdt_addr + 1);
|
||||
|
||||
if (!fdt_valid && machine_type == GRUB_ARM_MACHINE_TYPE_FDT)
|
||||
return grub_error (GRUB_ERR_FILE_NOT_FOUND,
|
||||
@@ -248,40 +245,23 @@ linux_boot (void)
|
||||
|
||||
grub_dprintf ("loader", "Kernel at: 0x%x\n", linux_addr);
|
||||
|
||||
if (fdt_valid || atag_valid)
|
||||
{
|
||||
#ifdef GRUB_MACHINE_EFI
|
||||
grub_size_t size;
|
||||
if (fdt_valid)
|
||||
size = grub_fdt_get_totalsize (fdt_addr);
|
||||
else
|
||||
size = 4 * get_atag_size (atag_orig);
|
||||
size += grub_strlen (linux_args) + 256;
|
||||
target_fdt = grub_efi_allocate_loader_memory (LINUX_FDT_PHYS_OFFSET, size);
|
||||
if (!fdt_addr)
|
||||
return grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("out of memory"));
|
||||
#else
|
||||
target_fdt = (void *) LINUX_FDT_ADDRESS;
|
||||
#endif
|
||||
}
|
||||
|
||||
if (fdt_valid)
|
||||
{
|
||||
grub_err_t err;
|
||||
|
||||
err = linux_prepare_fdt (target_fdt);
|
||||
err = linux_prepare_fdt ();
|
||||
if (err)
|
||||
return err;
|
||||
grub_dprintf ("loader", "FDT @ %p\n", target_fdt);
|
||||
grub_dprintf ("loader", "FDT @ 0x%p\n", fdt_addr);
|
||||
}
|
||||
else if (atag_valid)
|
||||
{
|
||||
grub_err_t err;
|
||||
|
||||
err = linux_prepare_atag (target_fdt);
|
||||
err = linux_prepare_atag ();
|
||||
if (err)
|
||||
return err;
|
||||
grub_dprintf ("loader", "ATAG @ %p\n", target_fdt);
|
||||
grub_dprintf ("loader", "ATAG @ 0x%p\n", fdt_addr);
|
||||
}
|
||||
|
||||
grub_dprintf ("loader", "Jumping to Linux...\n");
|
||||
@@ -305,7 +285,7 @@ linux_boot (void)
|
||||
|
||||
grub_arm_disable_caches_mmu ();
|
||||
|
||||
linuxmain (0, machine_type, target_fdt);
|
||||
linuxmain (0, machine_type, fdt_addr);
|
||||
|
||||
return grub_error (GRUB_ERR_BAD_OS, "Linux call returned");
|
||||
}
|
||||
@@ -400,11 +380,8 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
|
||||
|
||||
/* Create kernel command line. */
|
||||
grub_memcpy (linux_args, LINUX_IMAGE, sizeof (LINUX_IMAGE));
|
||||
err = grub_create_loader_cmdline (argc, argv,
|
||||
linux_args + sizeof (LINUX_IMAGE) - 1, size,
|
||||
GRUB_VERIFY_KERNEL_CMDLINE);
|
||||
if (err)
|
||||
goto fail;
|
||||
grub_create_loader_cmdline (argc, argv,
|
||||
linux_args + sizeof (LINUX_IMAGE) - 1, size);
|
||||
|
||||
return GRUB_ERR_NONE;
|
||||
|
||||
@@ -467,26 +444,11 @@ fail:
|
||||
static grub_err_t
|
||||
load_dtb (grub_file_t dtb, int size)
|
||||
{
|
||||
void *new_fdt = grub_zalloc (size);
|
||||
if (!new_fdt)
|
||||
return grub_errno;
|
||||
grub_dprintf ("loader", "Loading device tree to %p\n",
|
||||
new_fdt);
|
||||
if ((grub_file_read (dtb, new_fdt, size) != size)
|
||||
|| (grub_fdt_check_header (new_fdt, size) != 0))
|
||||
{
|
||||
grub_free (new_fdt);
|
||||
return grub_error (GRUB_ERR_BAD_OS, N_("invalid device tree"));
|
||||
}
|
||||
|
||||
grub_fdt_set_totalsize (new_fdt, size);
|
||||
current_fdt = new_fdt;
|
||||
/*
|
||||
* We've successfully loaded an FDT, so any machine type passed
|
||||
* from firmware is now obsolete.
|
||||
*/
|
||||
machine_type = GRUB_ARM_MACHINE_TYPE_FDT;
|
||||
if ((grub_file_read (dtb, fdt_addr, size) != size)
|
||||
|| (grub_fdt_check_header (fdt_addr, size) != 0))
|
||||
return grub_error (GRUB_ERR_BAD_OS, N_("invalid device tree"));
|
||||
|
||||
grub_fdt_set_totalsize (fdt_addr, size);
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
@@ -502,13 +464,42 @@ grub_cmd_devicetree (grub_command_t cmd __attribute__ ((unused)),
|
||||
|
||||
dtb = grub_file_open (argv[0]);
|
||||
if (!dtb)
|
||||
return grub_errno;
|
||||
goto out;
|
||||
|
||||
size = grub_file_size (dtb);
|
||||
if (size == 0)
|
||||
grub_error (GRUB_ERR_BAD_OS, "empty file");
|
||||
else
|
||||
load_dtb (dtb, size);
|
||||
{
|
||||
grub_error (GRUB_ERR_BAD_OS, "empty file");
|
||||
goto out;
|
||||
}
|
||||
|
||||
#ifdef GRUB_MACHINE_EFI
|
||||
fdt_addr = grub_efi_allocate_loader_memory (LINUX_FDT_PHYS_OFFSET, size);
|
||||
if (!fdt_addr)
|
||||
{
|
||||
grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("out of memory"));
|
||||
goto out;
|
||||
}
|
||||
#else
|
||||
fdt_addr = (void *) LINUX_FDT_ADDRESS;
|
||||
#endif
|
||||
|
||||
grub_dprintf ("loader", "Loading device tree to 0x%08x\n",
|
||||
(grub_addr_t) fdt_addr);
|
||||
load_dtb (dtb, size);
|
||||
if (grub_errno != GRUB_ERR_NONE)
|
||||
{
|
||||
fdt_addr = NULL;
|
||||
goto out;
|
||||
}
|
||||
|
||||
/*
|
||||
* We've successfully loaded an FDT, so any machine type passed
|
||||
* from firmware is now obsolete.
|
||||
*/
|
||||
machine_type = GRUB_ARM_MACHINE_TYPE_FDT;
|
||||
|
||||
out:
|
||||
grub_file_close (dtb);
|
||||
|
||||
return grub_errno;
|
||||
@@ -526,7 +517,7 @@ GRUB_MOD_INIT (linux)
|
||||
/* TRANSLATORS: DTB stands for device tree blob. */
|
||||
0, N_("Load DTB file."));
|
||||
my_mod = mod;
|
||||
current_fdt = grub_arm_firmware_get_boot_data ();
|
||||
fdt_addr = (void *) grub_arm_firmware_get_boot_data ();
|
||||
machine_type = grub_arm_firmware_get_machine_type ();
|
||||
}
|
||||
|
||||
|
||||
@@ -31,7 +31,6 @@
|
||||
#include <grub/efi/pe32.h>
|
||||
#include <grub/i18n.h>
|
||||
#include <grub/lib/cmdline.h>
|
||||
#include <grub/verify.h>
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
@@ -306,12 +305,9 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
|
||||
goto fail;
|
||||
}
|
||||
grub_memcpy (linux_args, LINUX_IMAGE, sizeof (LINUX_IMAGE));
|
||||
err = grub_create_loader_cmdline (argc, argv,
|
||||
linux_args + sizeof (LINUX_IMAGE) - 1,
|
||||
cmdline_size,
|
||||
GRUB_VERIFY_KERNEL_CMDLINE);
|
||||
if (err)
|
||||
goto fail;
|
||||
grub_create_loader_cmdline (argc, argv,
|
||||
linux_args + sizeof (LINUX_IMAGE) - 1,
|
||||
cmdline_size);
|
||||
|
||||
if (grub_errno == GRUB_ERR_NONE)
|
||||
{
|
||||
|
||||
@@ -219,7 +219,7 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)),
|
||||
|
||||
b = grub_efi_system_table->boot_services;
|
||||
|
||||
file = grub_file_open (filename, GRUB_FILE_TYPE_EFI_CHAINLOADED_IMAGE);
|
||||
file = grub_file_open (filename);
|
||||
if (! file)
|
||||
goto fail;
|
||||
|
||||
|
||||
@@ -35,7 +35,6 @@
|
||||
#include <grub/ns8250.h>
|
||||
#include <grub/bsdlabel.h>
|
||||
#include <grub/crypto.h>
|
||||
#include <grub/verify.h>
|
||||
#ifdef GRUB_MACHINE_PCBIOS
|
||||
#include <grub/machine/int.h>
|
||||
#endif
|
||||
@@ -417,8 +416,6 @@ grub_freebsd_add_meta_module (const char *filename, const char *type,
|
||||
grub_addr_t addr, grub_uint32_t size)
|
||||
{
|
||||
const char *name;
|
||||
grub_err_t err;
|
||||
|
||||
name = grub_strrchr (filename, '/');
|
||||
if (name)
|
||||
name++;
|
||||
@@ -472,9 +469,6 @@ grub_freebsd_add_meta_module (const char *filename, const char *type,
|
||||
*(p++) = ' ';
|
||||
}
|
||||
*p = 0;
|
||||
err = grub_verify_string (cmdline, GRUB_VERIFY_MODULE_CMDLINE);
|
||||
if (err)
|
||||
return err;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1463,7 +1457,7 @@ grub_bsd_load (int argc, char *argv[])
|
||||
goto fail;
|
||||
}
|
||||
|
||||
file = grub_file_open (argv[0], GRUB_FILE_TYPE_BSD_KERNEL);
|
||||
file = grub_file_open (argv[0]);
|
||||
if (!file)
|
||||
goto fail;
|
||||
|
||||
@@ -1540,7 +1534,7 @@ grub_cmd_freebsd (grub_extcmd_context_t ctxt, int argc, char *argv[])
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
file = grub_file_open (argv[0], GRUB_FILE_TYPE_BSD_KERNEL);
|
||||
file = grub_file_open (argv[0]);
|
||||
if (! file)
|
||||
return grub_errno;
|
||||
|
||||
@@ -1699,7 +1693,7 @@ grub_cmd_netbsd (grub_extcmd_context_t ctxt, int argc, char *argv[])
|
||||
{
|
||||
grub_file_t file;
|
||||
|
||||
file = grub_file_open (argv[0], GRUB_FILE_TYPE_BSD_KERNEL);
|
||||
file = grub_file_open (argv[0]);
|
||||
if (! file)
|
||||
return grub_errno;
|
||||
|
||||
@@ -1808,7 +1802,7 @@ grub_cmd_freebsd_loadenv (grub_command_t cmd __attribute__ ((unused)),
|
||||
goto fail;
|
||||
}
|
||||
|
||||
file = grub_file_open (argv[0], GRUB_FILE_TYPE_FREEBSD_ENV);
|
||||
file = grub_file_open (argv[0]);
|
||||
if ((!file) || (!file->size))
|
||||
goto fail;
|
||||
|
||||
@@ -1913,7 +1907,7 @@ grub_cmd_freebsd_module (grub_command_t cmd __attribute__ ((unused)),
|
||||
return 0;
|
||||
}
|
||||
|
||||
file = grub_file_open (argv[0], GRUB_FILE_TYPE_FREEBSD_MODULE);
|
||||
file = grub_file_open (argv[0]);
|
||||
if ((!file) || (!file->size))
|
||||
goto fail;
|
||||
|
||||
@@ -1964,7 +1958,7 @@ grub_netbsd_module_load (char *filename, grub_uint32_t type)
|
||||
void *src;
|
||||
grub_err_t err;
|
||||
|
||||
file = grub_file_open (filename, GRUB_FILE_TYPE_NETBSD_MODULE);
|
||||
file = grub_file_open (filename);
|
||||
if ((!file) || (!file->size))
|
||||
goto fail;
|
||||
|
||||
@@ -2054,7 +2048,7 @@ grub_cmd_freebsd_module_elf (grub_command_t cmd __attribute__ ((unused)),
|
||||
return 0;
|
||||
}
|
||||
|
||||
file = grub_file_open (argv[0], GRUB_FILE_TYPE_FREEBSD_MODULE_ELF);
|
||||
file = grub_file_open (argv[0]);
|
||||
if (!file)
|
||||
return grub_errno;
|
||||
if (!file->size)
|
||||
@@ -2094,7 +2088,7 @@ grub_cmd_openbsd_ramdisk (grub_command_t cmd __attribute__ ((unused)),
|
||||
if (!openbsd_ramdisk.max_size)
|
||||
return grub_error (GRUB_ERR_BAD_OS, "your kOpenBSD doesn't support ramdisk");
|
||||
|
||||
file = grub_file_open (args[0], GRUB_FILE_TYPE_OPENBSD_RAMDISK);
|
||||
file = grub_file_open (args[0]);
|
||||
if (! file)
|
||||
return grub_errno;
|
||||
|
||||
|
||||
@@ -439,7 +439,7 @@ grub_cmd_chain (grub_command_t cmd __attribute__ ((unused)),
|
||||
|
||||
grub_loader_unset ();
|
||||
|
||||
file = grub_file_open (argv[0], GRUB_FILE_TYPE_COREBOOT_CHAINLOADER);
|
||||
file = grub_file_open (argv[0]);
|
||||
if (!file)
|
||||
return grub_errno;
|
||||
|
||||
|
||||
@@ -695,7 +695,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
|
||||
goto fail;
|
||||
}
|
||||
|
||||
file = grub_file_open (argv[0], GRUB_FILE_TYPE_LINUX_KERNEL);
|
||||
file = grub_file_open (argv[0]);
|
||||
if (! file)
|
||||
goto fail;
|
||||
|
||||
@@ -1012,17 +1012,11 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
|
||||
if (!linux_cmdline)
|
||||
goto fail;
|
||||
grub_memcpy (linux_cmdline, LINUX_IMAGE, sizeof (LINUX_IMAGE));
|
||||
{
|
||||
grub_err_t err;
|
||||
err = grub_create_loader_cmdline (argc, argv,
|
||||
linux_cmdline
|
||||
+ sizeof (LINUX_IMAGE) - 1,
|
||||
maximal_cmdline_size
|
||||
- (sizeof (LINUX_IMAGE) - 1),
|
||||
GRUB_VERIFY_KERNEL_CMDLINE);
|
||||
if (err)
|
||||
goto fail;
|
||||
}
|
||||
grub_create_loader_cmdline (argc, argv,
|
||||
linux_cmdline
|
||||
+ sizeof (LINUX_IMAGE) - 1,
|
||||
maximal_cmdline_size
|
||||
- (sizeof (LINUX_IMAGE) - 1));
|
||||
|
||||
len = prot_file_size;
|
||||
if (grub_file_read (file, prot_mode_mem, len) != len && !grub_errno)
|
||||
|
||||
@@ -673,8 +673,10 @@ grub_multiboot_init_mbi (int argc, char *argv[])
|
||||
return grub_errno;
|
||||
cmdline_size = len;
|
||||
|
||||
return grub_create_loader_cmdline (argc, argv, cmdline,
|
||||
cmdline_size, GRUB_VERIFY_KERNEL_CMDLINE);
|
||||
grub_create_loader_cmdline (argc, argv, cmdline,
|
||||
cmdline_size);
|
||||
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
grub_err_t
|
||||
@@ -683,7 +685,6 @@ grub_multiboot_add_module (grub_addr_t start, grub_size_t size,
|
||||
{
|
||||
struct module *newmod;
|
||||
grub_size_t len = 0;
|
||||
grub_err_t err;
|
||||
|
||||
newmod = grub_malloc (sizeof (*newmod));
|
||||
if (!newmod)
|
||||
@@ -703,13 +704,8 @@ grub_multiboot_add_module (grub_addr_t start, grub_size_t size,
|
||||
newmod->cmdline_size = len;
|
||||
total_modcmd += ALIGN_UP (len, 4);
|
||||
|
||||
err = grub_create_loader_cmdline (argc, argv, newmod->cmdline,
|
||||
newmod->cmdline_size, GRUB_VERIFY_MODULE_CMDLINE);
|
||||
if (err)
|
||||
{
|
||||
grub_free (newmod);
|
||||
return grub_errno;
|
||||
}
|
||||
grub_create_loader_cmdline (argc, argv, newmod->cmdline,
|
||||
newmod->cmdline_size);
|
||||
|
||||
if (modules_last)
|
||||
modules_last->next = newmod;
|
||||
|
||||
@@ -156,8 +156,8 @@ grub_chainloader_cmd (const char *filename, grub_chainloader_flags_t flags)
|
||||
|
||||
grub_dl_ref (my_mod);
|
||||
|
||||
file = grub_file_open (filename, GRUB_FILE_TYPE_PCCHAINLOADER
|
||||
| GRUB_FILE_TYPE_NO_DECOMPRESS);
|
||||
grub_file_filter_disable_compression ();
|
||||
file = grub_file_open (filename);
|
||||
if (! file)
|
||||
goto fail;
|
||||
|
||||
|
||||
@@ -110,7 +110,7 @@ grub_cmd_freedos (grub_command_t cmd __attribute__ ((unused)),
|
||||
if (!rel)
|
||||
goto fail;
|
||||
|
||||
file = grub_file_open (argv[0], GRUB_FILE_TYPE_FREEDOS);
|
||||
file = grub_file_open (argv[0]);
|
||||
if (! file)
|
||||
goto fail;
|
||||
|
||||
|
||||
@@ -139,7 +139,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
|
||||
goto fail;
|
||||
}
|
||||
|
||||
file = grub_file_open (argv[0], GRUB_FILE_TYPE_LINUX_KERNEL);
|
||||
file = grub_file_open (argv[0]);
|
||||
if (! file)
|
||||
goto fail;
|
||||
|
||||
@@ -334,14 +334,11 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
|
||||
/* Create kernel command line. */
|
||||
grub_memcpy ((char *)grub_linux_real_chunk + GRUB_LINUX_CL_OFFSET,
|
||||
LINUX_IMAGE, sizeof (LINUX_IMAGE));
|
||||
err = grub_create_loader_cmdline (argc, argv,
|
||||
(char *)grub_linux_real_chunk
|
||||
+ GRUB_LINUX_CL_OFFSET + sizeof (LINUX_IMAGE) - 1,
|
||||
maximal_cmdline_size
|
||||
- (sizeof (LINUX_IMAGE) - 1),
|
||||
GRUB_VERIFY_KERNEL_CMDLINE);
|
||||
if (err)
|
||||
goto fail;
|
||||
grub_create_loader_cmdline (argc, argv,
|
||||
(char *)grub_linux_real_chunk
|
||||
+ GRUB_LINUX_CL_OFFSET + sizeof (LINUX_IMAGE) - 1,
|
||||
maximal_cmdline_size
|
||||
- (sizeof (LINUX_IMAGE) - 1));
|
||||
|
||||
if (grub_linux_is_bzimage)
|
||||
grub_linux_prot_target = GRUB_LINUX_BZIMAGE_ADDR;
|
||||
|
||||
@@ -90,7 +90,7 @@ grub_cmd_ntldr (grub_command_t cmd __attribute__ ((unused)),
|
||||
if (!rel)
|
||||
goto fail;
|
||||
|
||||
file = grub_file_open (argv[0], GRUB_FILE_TYPE_NTLDR);
|
||||
file = grub_file_open (argv[0]);
|
||||
if (! file)
|
||||
goto fail;
|
||||
|
||||
|
||||
@@ -33,7 +33,6 @@
|
||||
#include <grub/mm.h>
|
||||
#include <grub/cpu/relocator.h>
|
||||
#include <grub/extcmd.h>
|
||||
#include <grub/verify.h>
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
@@ -414,7 +413,7 @@ grub_cmd_plan9 (grub_extcmd_context_t ctxt, int argc, char *argv[])
|
||||
if (!rel)
|
||||
goto fail;
|
||||
|
||||
fill_ctx.file = grub_file_open (argv[0], GRUB_FILE_TYPE_PLAN9_KERNEL);
|
||||
fill_ctx.file = grub_file_open (argv[0]);
|
||||
if (! fill_ctx.file)
|
||||
goto fail;
|
||||
|
||||
@@ -506,7 +505,6 @@ grub_cmd_plan9 (grub_extcmd_context_t ctxt, int argc, char *argv[])
|
||||
configptr = grub_stpcpy (configptr, "bootfile=");
|
||||
configptr = grub_stpcpy (configptr, bootpath);
|
||||
*configptr++ = '\n';
|
||||
char *cmdline = configptr;
|
||||
{
|
||||
int i;
|
||||
for (i = 1; i < argc; i++)
|
||||
@@ -515,15 +513,6 @@ grub_cmd_plan9 (grub_extcmd_context_t ctxt, int argc, char *argv[])
|
||||
*configptr++ = '\n';
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
grub_err_t err;
|
||||
*configptr = '\0';
|
||||
err = grub_verify_string (cmdline, GRUB_VERIFY_KERNEL_CMDLINE);
|
||||
if (err)
|
||||
goto fail;
|
||||
}
|
||||
|
||||
configptr = grub_stpcpy (configptr, fill_ctx.pmap);
|
||||
|
||||
{
|
||||
|
||||
@@ -99,7 +99,7 @@ grub_cmd_pxechain (grub_command_t cmd __attribute__ ((unused)),
|
||||
if (!rel)
|
||||
goto fail;
|
||||
|
||||
file = grub_file_open (argv[0], GRUB_FILE_TYPE_PXECHAINLOADER);
|
||||
file = grub_file_open (argv[0]);
|
||||
if (! file)
|
||||
goto fail;
|
||||
|
||||
|
||||
@@ -99,7 +99,7 @@ grub_cmd_truecrypt (grub_command_t cmd __attribute__ ((unused)),
|
||||
|
||||
grub_dl_ref (my_mod);
|
||||
|
||||
file = grub_file_open (argv[0], GRUB_FILE_TYPE_TRUECRYPT);
|
||||
file = grub_file_open (argv[0]);
|
||||
if (! file)
|
||||
goto fail;
|
||||
|
||||
|
||||
@@ -40,7 +40,6 @@
|
||||
#include <grub/xen_file.h>
|
||||
#include <grub/linux.h>
|
||||
#include <grub/i386/memory.h>
|
||||
#include <grub/verify.h>
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
@@ -648,11 +647,8 @@ grub_cmd_xen (grub_command_t cmd __attribute__ ((unused)),
|
||||
grub_create_loader_cmdline (argc - 1, argv + 1,
|
||||
(char *) xen_state.next_start.cmd_line,
|
||||
sizeof (xen_state.next_start.cmd_line) - 1);
|
||||
err = grub_verify_string (xen_state.next_start.cmd_line, GRUB_VERIFY_MODULE_CMDLINE);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
file = grub_file_open (argv[0], GRUB_FILE_TYPE_LINUX_KERNEL);
|
||||
file = grub_file_open (argv[0]);
|
||||
if (!file)
|
||||
return grub_errno;
|
||||
|
||||
@@ -897,8 +893,9 @@ grub_cmd_module (grub_command_t cmd __attribute__ ((unused)),
|
||||
|
||||
xen_state.max_addr = ALIGN_UP (xen_state.max_addr, PAGE_SIZE);
|
||||
|
||||
file = grub_file_open (argv[0], GRUB_FILE_TYPE_LINUX_INITRD |
|
||||
(nounzip ? GRUB_FILE_TYPE_NO_DECOMPRESS : 0));
|
||||
if (nounzip)
|
||||
grub_file_filter_disable_compression ();
|
||||
file = grub_file_open (argv[0]);
|
||||
if (!file)
|
||||
return grub_errno;
|
||||
size = grub_file_size (file);
|
||||
@@ -912,9 +909,6 @@ grub_cmd_module (grub_command_t cmd __attribute__ ((unused)),
|
||||
|
||||
grub_create_loader_cmdline (argc - 1, argv + 1,
|
||||
get_virtual_current_address (ch), cmdline_len);
|
||||
err = grub_verify_string (get_virtual_current_address (ch), GRUB_VERIFY_MODULE_CMDLINE);
|
||||
if (err)
|
||||
goto fail;
|
||||
|
||||
xen_state.module_info_page[xen_state.n_modules].cmdline =
|
||||
xen_state.max_addr - xen_state.modules_target_start;
|
||||
|
||||
@@ -78,7 +78,7 @@ grub_xen_file (grub_file_t file)
|
||||
Trim it. */
|
||||
if (grub_memcmp (magic, XZ_MAGIC, sizeof (XZ_MAGIC) - 1) == 0)
|
||||
payload_length -= 4;
|
||||
off_file = grub_file_offset_open (file, GRUB_FILE_TYPE_LINUX_KERNEL, payload_offset,
|
||||
off_file = grub_file_offset_open (file, payload_offset,
|
||||
payload_length);
|
||||
if (!off_file)
|
||||
goto fail;
|
||||
|
||||
@@ -487,7 +487,7 @@ grub_cmd_devprop_load (grub_command_t cmd __attribute__ ((unused)),
|
||||
if (argc != 1)
|
||||
return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected"));
|
||||
|
||||
file = grub_file_open (args[0], GRUB_FILE_XNU_DEVPROP);
|
||||
file = grub_file_open (args[0]);
|
||||
if (! file)
|
||||
return grub_errno;
|
||||
size = grub_file_size (file);
|
||||
|
||||
@@ -33,7 +33,6 @@
|
||||
#include <grub/i18n.h>
|
||||
#include <grub/env.h>
|
||||
#include <grub/linux.h>
|
||||
#include <grub/verify.h>
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
@@ -544,12 +543,6 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
|
||||
p = grub_stpcpy (p, argv[i]);
|
||||
}
|
||||
cmdline[10] = '=';
|
||||
|
||||
*p = '\0';
|
||||
|
||||
err = grub_verify_string (cmdline, GRUB_VERIFY_KERNEL_CMDLINE);
|
||||
if (err)
|
||||
goto fail;
|
||||
|
||||
boot_param->command_line = (grub_uint64_t) cmdline;
|
||||
boot_param->efi_systab = (grub_uint64_t) grub_efi_system_table;
|
||||
|
||||
@@ -173,6 +173,7 @@ grub_initrd_init (int argc, char *argv[],
|
||||
eptr = grub_strchr (ptr, ':');
|
||||
if (eptr)
|
||||
{
|
||||
grub_file_filter_disable_compression ();
|
||||
initrd_ctx->components[i].newc_name = grub_strndup (ptr, eptr - ptr);
|
||||
if (!initrd_ctx->components[i].newc_name)
|
||||
{
|
||||
@@ -197,9 +198,8 @@ grub_initrd_init (int argc, char *argv[],
|
||||
root = 0;
|
||||
newc = 0;
|
||||
}
|
||||
initrd_ctx->components[i].file = grub_file_open (fname,
|
||||
GRUB_FILE_TYPE_LINUX_INITRD
|
||||
| GRUB_FILE_TYPE_NO_DECOMPRESS);
|
||||
grub_file_filter_disable_compression ();
|
||||
initrd_ctx->components[i].file = grub_file_open (fname);
|
||||
if (!initrd_ctx->components[i].file)
|
||||
{
|
||||
grub_initrd_close (initrd_ctx);
|
||||
|
||||
@@ -188,12 +188,12 @@ fail:
|
||||
}
|
||||
|
||||
grub_macho_t
|
||||
grub_macho_open (const char *name, enum grub_file_type type, int is_64bit)
|
||||
grub_macho_open (const char *name, int is_64bit)
|
||||
{
|
||||
grub_file_t file;
|
||||
grub_macho_t macho;
|
||||
|
||||
file = grub_file_open (name, type);
|
||||
file = grub_file_open (name);
|
||||
if (! file)
|
||||
return 0;
|
||||
|
||||
|
||||
@@ -237,7 +237,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
|
||||
if (argc == 0)
|
||||
return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected"));
|
||||
|
||||
elf = grub_elf_open (argv[0], GRUB_FILE_TYPE_LINUX_KERNEL);
|
||||
elf = grub_elf_open (argv[0]);
|
||||
if (! elf)
|
||||
return grub_errno;
|
||||
|
||||
@@ -327,8 +327,6 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
|
||||
linux_argv++;
|
||||
linux_args += ALIGN_UP (sizeof ("a0"), 4);
|
||||
|
||||
char *params = linux_args;
|
||||
|
||||
#ifdef GRUB_MACHINE_MIPS_LOONGSON
|
||||
{
|
||||
unsigned mtype = grub_arch_machine;
|
||||
@@ -354,12 +352,6 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
|
||||
linux_args += ALIGN_UP (grub_strlen (argv[i]) + 1, 4);
|
||||
}
|
||||
|
||||
*linux_args = '\0';
|
||||
|
||||
err = grub_verify_string (params, GRUB_VERIFY_KERNEL_CMDLINE);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
/* Reserve space for rd arguments. */
|
||||
rd_addr_arg_off = (grub_uint8_t *) linux_args - (grub_uint8_t *) playground;
|
||||
linux_args += ALIGN_UP (sizeof ("rd_start=0xXXXXXXXXXXXXXXXX"), 4);
|
||||
|
||||
@@ -306,16 +306,14 @@ grub_cmd_multiboot (grub_command_t cmd __attribute__ ((unused)),
|
||||
if (argc == 0)
|
||||
return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected"));
|
||||
|
||||
file = grub_file_open (argv[0], GRUB_FILE_TYPE_MULTIBOOT_KERNEL);
|
||||
file = grub_file_open (argv[0]);
|
||||
if (! file)
|
||||
return grub_errno;
|
||||
|
||||
grub_dl_ref (my_mod);
|
||||
|
||||
/* Skip filename. */
|
||||
err = grub_multiboot_init_mbi (argc - 1, argv + 1);
|
||||
if (err)
|
||||
goto fail;
|
||||
grub_multiboot_init_mbi (argc - 1, argv + 1);
|
||||
|
||||
grub_relocator_unload (grub_multiboot_relocator);
|
||||
grub_multiboot_relocator = grub_relocator_new ();
|
||||
@@ -374,8 +372,10 @@ grub_cmd_module (grub_command_t cmd __attribute__ ((unused)),
|
||||
return grub_error (GRUB_ERR_BAD_ARGUMENT,
|
||||
N_("you need to load the kernel first"));
|
||||
|
||||
file = grub_file_open (argv[0], GRUB_FILE_TYPE_MULTIBOOT_MODULE
|
||||
| (nounzip ? GRUB_FILE_TYPE_NO_DECOMPRESS : 0));
|
||||
if (nounzip)
|
||||
grub_file_filter_disable_compression ();
|
||||
|
||||
file = grub_file_open (argv[0]);
|
||||
if (! file)
|
||||
return grub_errno;
|
||||
|
||||
|
||||
@@ -1074,8 +1074,10 @@ grub_multiboot_init_mbi (int argc, char *argv[])
|
||||
return grub_errno;
|
||||
cmdline_size = len;
|
||||
|
||||
return grub_create_loader_cmdline (argc, argv, cmdline, cmdline_size,
|
||||
GRUB_VERIFY_KERNEL_CMDLINE);
|
||||
grub_create_loader_cmdline (argc, argv, cmdline,
|
||||
cmdline_size);
|
||||
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
grub_err_t
|
||||
@@ -1084,7 +1086,6 @@ grub_multiboot_add_module (grub_addr_t start, grub_size_t size,
|
||||
{
|
||||
struct module *newmod;
|
||||
grub_size_t len = 0;
|
||||
grub_err_t err;
|
||||
|
||||
newmod = grub_malloc (sizeof (*newmod));
|
||||
if (!newmod)
|
||||
@@ -1103,10 +1104,8 @@ grub_multiboot_add_module (grub_addr_t start, grub_size_t size,
|
||||
newmod->cmdline_size = len;
|
||||
total_modcmd += ALIGN_UP (len, MULTIBOOT_TAG_ALIGN);
|
||||
|
||||
err = grub_create_loader_cmdline (argc, argv, newmod->cmdline,
|
||||
newmod->cmdline_size, GRUB_VERIFY_MODULE_CMDLINE);
|
||||
if (err)
|
||||
return err;
|
||||
grub_create_loader_cmdline (argc, argv, newmod->cmdline,
|
||||
newmod->cmdline_size);
|
||||
|
||||
if (modules_last)
|
||||
modules_last->next = newmod;
|
||||
|
||||
@@ -302,9 +302,8 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
|
||||
|
||||
/* Create kernel command line. */
|
||||
grub_memcpy (linux_args, LINUX_IMAGE, sizeof (LINUX_IMAGE));
|
||||
if (grub_create_loader_cmdline (argc, argv, linux_args + sizeof (LINUX_IMAGE) - 1,
|
||||
size))
|
||||
goto out;
|
||||
grub_create_loader_cmdline (argc, argv, linux_args + sizeof (LINUX_IMAGE) - 1,
|
||||
size);
|
||||
|
||||
out:
|
||||
|
||||
|
||||
@@ -340,9 +340,8 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
|
||||
|
||||
/* Create kernel command line. */
|
||||
grub_memcpy (linux_args, LINUX_IMAGE, sizeof (LINUX_IMAGE));
|
||||
if (grub_create_loader_cmdline (argc, argv, linux_args + sizeof (LINUX_IMAGE) - 1,
|
||||
size, GRUB_VERIFY_KERNEL_CMDLINE))
|
||||
goto out;
|
||||
grub_create_loader_cmdline (argc, argv, linux_args + sizeof (LINUX_IMAGE) - 1,
|
||||
size);
|
||||
|
||||
out:
|
||||
if (elf)
|
||||
|
||||
@@ -33,7 +33,6 @@
|
||||
#include <grub/extcmd.h>
|
||||
#include <grub/env.h>
|
||||
#include <grub/i18n.h>
|
||||
#include <grub/verify.h>
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
@@ -352,7 +351,7 @@ grub_cmd_xnu_kernel (grub_command_t cmd __attribute__ ((unused)),
|
||||
|
||||
grub_xnu_unload ();
|
||||
|
||||
macho = grub_macho_open (args[0], GRUB_FILE_TYPE_XNU_KERNEL, 0);
|
||||
macho = grub_macho_open (args[0], 0);
|
||||
if (! macho)
|
||||
return grub_errno;
|
||||
|
||||
@@ -426,10 +425,6 @@ grub_cmd_xnu_kernel (grub_command_t cmd __attribute__ ((unused)),
|
||||
if (ptr != grub_xnu_cmdline)
|
||||
*(ptr - 1) = 0;
|
||||
|
||||
err = grub_verify_string (grub_xnu_cmdline, GRUB_VERIFY_KERNEL_CMDLINE);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
#if defined (__i386) && !defined (GRUB_MACHINE_EFI)
|
||||
err = grub_efiemu_autocore ();
|
||||
if (err)
|
||||
@@ -461,7 +456,7 @@ grub_cmd_xnu_kernel64 (grub_command_t cmd __attribute__ ((unused)),
|
||||
|
||||
grub_xnu_unload ();
|
||||
|
||||
macho = grub_macho_open (args[0], GRUB_FILE_TYPE_XNU_KERNEL, 1);
|
||||
macho = grub_macho_open (args[0], 1);
|
||||
if (! macho)
|
||||
return grub_errno;
|
||||
|
||||
@@ -539,10 +534,6 @@ grub_cmd_xnu_kernel64 (grub_command_t cmd __attribute__ ((unused)),
|
||||
if (ptr != grub_xnu_cmdline)
|
||||
*(ptr - 1) = 0;
|
||||
|
||||
err = grub_verify_string (grub_xnu_cmdline, GRUB_VERIFY_KERNEL_CMDLINE);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
#if defined (__i386) && !defined (GRUB_MACHINE_EFI)
|
||||
err = grub_efiemu_autocore ();
|
||||
if (err)
|
||||
@@ -683,7 +674,7 @@ grub_xnu_load_driver (char *infoplistname, grub_file_t binaryfile,
|
||||
macho = 0;
|
||||
|
||||
if (infoplistname)
|
||||
infoplist = grub_file_open (infoplistname, GRUB_FILE_TYPE_XNU_INFO_PLIST);
|
||||
infoplist = grub_file_open (infoplistname);
|
||||
else
|
||||
infoplist = 0;
|
||||
grub_errno = GRUB_ERR_NONE;
|
||||
@@ -780,7 +771,7 @@ grub_cmd_xnu_mkext (grub_command_t cmd __attribute__ ((unused)),
|
||||
if (! grub_xnu_heap_size)
|
||||
return grub_error (GRUB_ERR_BAD_OS, N_("you need to load the kernel first"));
|
||||
|
||||
file = grub_file_open (args[0], GRUB_FILE_TYPE_XNU_MKEXT);
|
||||
file = grub_file_open (args[0]);
|
||||
if (! file)
|
||||
return grub_errno;
|
||||
|
||||
@@ -894,7 +885,7 @@ grub_cmd_xnu_ramdisk (grub_command_t cmd __attribute__ ((unused)),
|
||||
if (! grub_xnu_heap_size)
|
||||
return grub_error (GRUB_ERR_BAD_OS, N_("you need to load the kernel first"));
|
||||
|
||||
file = grub_file_open (args[0], GRUB_FILE_TYPE_XNU_RAMDISK);
|
||||
file = grub_file_open (args[0]);
|
||||
if (! file)
|
||||
return grub_errno;
|
||||
|
||||
@@ -934,7 +925,7 @@ grub_xnu_check_os_bundle_required (char *plistname,
|
||||
if (binname)
|
||||
*binname = 0;
|
||||
|
||||
file = grub_file_open (plistname, GRUB_FILE_TYPE_XNU_INFO_PLIST);
|
||||
file = grub_file_open (plistname);
|
||||
if (! file)
|
||||
return 0;
|
||||
|
||||
@@ -1219,7 +1210,7 @@ grub_xnu_load_kext_from_dir (char *dirname, const char *osbundlerequired,
|
||||
grub_strcpy (binname + grub_strlen (binname), "/");
|
||||
grub_strcpy (binname + grub_strlen (binname), binsuffix);
|
||||
grub_dprintf ("xnu", "%s:%s\n", ctx.plistname, binname);
|
||||
binfile = grub_file_open (binname, GRUB_FILE_TYPE_XNU_KEXT);
|
||||
binfile = grub_file_open (binname);
|
||||
if (! binfile)
|
||||
grub_errno = GRUB_ERR_NONE;
|
||||
|
||||
@@ -1262,7 +1253,7 @@ grub_cmd_xnu_kext (grub_command_t cmd __attribute__ ((unused)),
|
||||
/* User explicitly specified plist and binary. */
|
||||
if (grub_strcmp (args[1], "-") != 0)
|
||||
{
|
||||
binfile = grub_file_open (args[1], GRUB_FILE_TYPE_XNU_KEXT);
|
||||
binfile = grub_file_open (args[1]);
|
||||
if (! binfile)
|
||||
return grub_errno;
|
||||
}
|
||||
|
||||
@@ -53,8 +53,8 @@ grub_xnu_resume (char *imagename)
|
||||
grub_addr_t target_image;
|
||||
grub_err_t err;
|
||||
|
||||
file = grub_file_open (imagename, GRUB_FILE_TYPE_XNU_HIBERNATE_IMAGE
|
||||
| GRUB_FILE_TYPE_NO_DECOMPRESS);
|
||||
grub_file_filter_disable_compression ();
|
||||
file = grub_file_open (imagename);
|
||||
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