merge with mainline

This commit is contained in:
BVK Chaitanya 2010-08-12 12:02:48 +05:30
commit 163dd4f7e9
63 changed files with 3999 additions and 1439 deletions

View file

@ -1,5 +1,6 @@
00_header 00_header
10_* 10_*
20_linux_xen
30_os-prober 30_os-prober
40_custom 40_custom
41_custom 41_custom
@ -39,6 +40,7 @@ grub-fstest
grub_fstest_init.c grub_fstest_init.c
grub_fstest_init.h grub_fstest_init.h
grub-install grub-install
grub-macho2img
grub-mk* grub-mk*
grub-pbkdf2 grub-pbkdf2
grub-pe2elf grub-pe2elf

678
ChangeLog
View file

@ -1,3 +1,681 @@
2010-08-12 BVK Chaitanya <bvk.groups@gmail.com>
"continue" command support to GRUB script.
* script/execute.c (grub_script_execute_cmdwhile): Continue support.
(grub_script_break): Continue support.
* script/main.c (grub_script_init): Register continue command.
(grub_script_fini): Unregister continue command.
* tests/grub_script_continue.in: New testcase.
* conf/tests.rmk: Rules for new testcase.
2010-08-12 BVK Chaitanya <bvk@dbook>
"break" command support to GRUB script.
* conf/common.rmk: Rule updates to grub-script-check.
* include/grub/misc.h (grub_min): New function.
* include/grub/script_sh.h (grub_script_init): New prototype.
(grub_script_fini): New prototype.
(grub_script_break): New prototype.
* script/main.c (grub_script_init): New function.
(grub_script_fini): New function.
* script/execute.c (grub_script_break): New function.
* normal/main.c: Calls to grub_script_{init,fini}.
* util/grub-script-check.c (grub_script_break): New function.
* tests/grub_script_break.in: New testcase.
* conf/tests.rmk: Rules for new test case.
2010-08-12 BVK Chaitanya <bvk.groups@gmail.com>
Function parameters support to GRUB script.
* script/yylex.l (VARIABLE): Regular expression update.
* script/function.c (grub_script_function_call): Moved ...
* script/execute.c (grub_script_function_call): ... to here.
(grub_script_execute_arglist_to_argv): Removed.
(grub_script_arglist_to_argv): New function.
* script/argv.c: New file.
(grub_script_argv_free): New function.
(grub_script_argv_next): Likewise.
(grub_script_argv_append): Likewise.
(grub_script_argv_split_append): Likewise.
* include/grub/script_sh.h (grub_script_argv): New struct.
(grub_script_argv_free): New function.
(grub_script_argv_next): Likewise.
(grub_script_argv_append): Likewise.
(grub_script_argv_split_append): Likewise.
* conf/common.rmk (normal.mod): New source script/argv.c.
* tests/grub_script_echo1.in: More tests.
* tests/grub_script_vars1.in: Likewise.
* tests/grub_script_functions.in: New test case.
* conf/tests.rmk: Rules for new testcase.
2010-08-12 BVK Chaitanya <bvk.groups@gmail.com>
Remove grub_script_cmdblock struct.
* include/grub/script_sh.h: Remove grub_script_cmdblock.
* script/parser.y: Likewise.
* script/execute.c: Rename cmdblock suffix to cmdlist.
* script/script.c: Likewise.
* util/grub-script-check.c: Likewise.
2010-08-11 Yves Blusseau <blusseau@zetam.org>
* .bzrignore: add grub-macho2img
2010-08-11 Vladimir Serbinenko <phcoder@gmail.com>
* kern/i386/qemu/init.c (grub_qemu_init_cirrus): Fix compilation error.
2010-08-11 Vladimir Serbinenko <phcoder@gmail.com>
Remove the dump of sm712 initialisation sequence.
* include/grub/pci.h (GRUB_PCI_CLASS_SUBCLASS_VGA): New const.
* include/grub/vga.h (GRUB_VGA_IO_ARX_READ): New register.
(GRUB_VGA_IO_MISC_WRITE): Likewise.
(GRUB_VGA_CR_*): Added many registers.
(GRUB_VGA_SR_*): Likewise.
(GRUB_VGA_GR_*): Likewise.
(grub_vga_write_arx): New function.
(grub_video_hw_config): New struct.
(grub_vga_set_geometry): New function.
* kern/i386/qemu/init.c (load_palette): Use grub_vga_write_arx and
GRUB_PCI_CLASS_SUBCLASS_VGA.
* video/cirrus.c (grub_video_cirrus_setup): Use grub_vga_set_geometry.
* video/sm712.c (grub_sm712_write_reg): New function
(grub_sm712_read_reg): Likewise.
(grub_sm712_sr_write): Likewise.
(grub_sm712_gr_write): Likewise.
(grub_sm712_cr_write): Likewise.
(grub_sm712_write_arx): Likewise.
(grub_sm712_cr_shadow_write): Likewise.
(grub_sm712_write_dda_lookup): Likewise.
(grub_video_sm712_setup): Initialise the video rather then
blindly replay the dump.
(main) [TEST]: Add a routine to be able to compile as standalone for
tests.
* video/sm712_init.c (sm712_init): Removed.
(sm712_sr_seq1): New array.
(sm712_sr_seq2): Likewise.
2010-08-10 Vladimir Serbinenko <phcoder@gmail.com>
* include/grub/vga.h: Add missing grub/pci.h include.
2010-08-10 Yves Blusseau <blusseau@zetam.org>
* util/grub-macho2img.c (main): fix typo
2010-08-10 Vladimir Serbinenko <phcoder@gmail.com>
* include/grub/vga.h (grub_vga_gr_write): Add GRUB_MACHINE_PCI_IO_BASE.
(grub_vga_gr_read): Likewise.
(grub_vga_cr_write): Likewise.
(grub_vga_cr_read): Likewise.
(grub_vga_sr_write): Likewise.
(grub_vga_sr_read): Likewise.
(grub_vga_palette_read): Likewise.
(grub_vga_palette_write): Likewise.
* video/sm712.c (GRUB_SM712_REG_BASE): New definition.
(grub_sm712_sr_read): New function.
(grub_video_sm712_setup): Use grub_vga_sr_write and grub_sm712_sr_read.
* video/sm712_init.c (sm712_init): Substract GRUB_MACHINE_PCI_IO_BASE.
2010-08-09 Robert Millan <rmh@gnu.org>
* kern/emu/misc.c (grub_make_system_path_relative_to_its_root): Filter
out unused variables on non-ZFS build.
2010-08-08 Robert Millan <rmh@gnu.org>
Fix path generation for sub-filesystems in ZFS.
* kern/emu/misc.c (grub_make_system_path_relative_to_its_root): Add
missing slash.
2010-08-08 Robert Millan <rmh@gnu.org>
* util/grub-fstest.c (read_file, cmd_cmp): Improve error message.
2010-08-08 Robert Millan <rmh@gnu.org>
* util/grub.d/10_kfreebsd.in: When files required for ZFS do not
exist, issue a proper error message (rely on `ls' for translated
strings).
2010-08-08 Robert Millan <rmh@gnu.org>
Fix grub-probe invocation.
* util/grub.d/10_kfreebsd.in: s/label/fs_label/g.
2010-08-04 Robert Millan <rmh@gnu.org>
* configure.ac: Remove checks for getfsstat() and getmntany().
Add checks for `<sys/param.h>' and `<sys/mount.h>'.
* kern/emu/misc.c [HAVE_GETMNTANY]: Remove `<sys/mnttab.h>'.
[HAVE_SYS_PARAM_H]: Include `<sys/param.h>'.
[HAVE_SYS_MOUNT_H]: Include `<sys/mount.h>'.
[HAVE_LIBZFS && HAVE_LIBNVPAIR] (find_mount_point_from_dir): Remove
function.
(grub_find_zpool_from_dir): Use statfs() instead of indirect matching
via find_mount_point_from_dir() and getfsstat() / getmntany().
2010-08-04 Robert Millan <rmh@gnu.org>
* include/grub/emu/misc.h (grub_find_mount_point_from_dir)
(grub_find_zpool_from_mount_point): Merge into ...
(grub_find_zpool_from_dir): ... this.
* kern/emu/misc.c: Likewise.
* kern/emu/misc.c
(grub_make_system_path_relative_to_its_root): Replace
grub_find_mount_point_from_dir() / grub_find_zpool_from_mount_point()
with grub_find_zpool_from_dir().
* kern/emu/getroot.c (find_root_device_from_libzfs): Likewise.
2010-08-04 Robert Millan <rmh@gnu.org>
Support OpenSolaris in ZFS device resolution.
* configure.ac: Check for getmntany().
* kern/emu/misc.c [HAVE_GETMNTANY]: Include `<sys/mnttab.h>'.
[HAVE_GETMNTANY] (grub_find_zpool_from_mount_point): Add OpenSolaris
support.
2010-08-03 Robert Millan <rmh@gnu.org>
Fix grub-emu build.
* include/grub/util/misc.h: Move `<grub/util/libzfs.h>' to ...
* include/grub/emu/misc.h: ... here.
* include/grub/util/misc.h (grub_get_libzfs_handle): Move function ...
* include/grub/emu/misc.h (grub_get_libzfs_handle): ... here.
* util/misc.c: Remove `<grub/util/libzfs.h>'.
[HAVE_LIBZFS] (libzfs_handle, fini_libzfs)
(grub_get_libzfs_handle): Move to ...
* kern/emu/misc.c [HAVE_LIBZFS] (__libzfs_handle, fini_libzfs)
(grub_get_libzfs_handle): ... here.
2010-08-03 BVK Chaitanya <bvk.groups@gmail.com>
* script/execute.c (grub_script_execute_cmdline): Check for NULL
as command name case.
2010-08-02 Colin Watson <cjwatson@ubuntu.com>
* disk/raid.c (insert_array): Select unique numbers for named arrays
as well, for use as keys in the disk cache.
2010-08-01 Robert Millan <rmh@gnu.org>
* util/grub.d/10_kfreebsd.in: Initialize ${kfreebsd_device} as the
kFreeBSD device name, except on ZFS where the filesystem label is
used.
(kfreebsd_entry): On ZFS root, load `opensolaris.ko', `zfs.ko' and
`/boot/zfs/zpool.cache'.
Set mountfrom kernel variable using ${kfreebsd_device}.
2010-08-01 Robert Millan <rmh@gnu.org>
Make it even harder to use uninitialized `libzfs_handle' (and
make the interface a bit simpler).
* include/grub/util/misc.h (grub_util_init_libzfs)
(libzfs_handle): Remove.
(grub_get_libzfs_handle): New prototype.
* util/misc.c [HAVE_LIBZFS] (libzfs_handle): Add `static'
attribute.
(grub_util_init_libzfs): Remove.
(grub_get_libzfs_handle): New function.
* kern/emu/getroot.c (find_root_device_from_libzfs): Use
grub_get_libzfs_handle() to obtain a libzfs handle instead of
accessing `libzfs_handle' directly.
2010-08-01 Robert Millan <rmh@gnu.org>
* include/grub/emu/misc.h (grub_find_mount_point_from_dir)
(grub_find_zpool_from_mount_point): New function prototypes.
* kern/emu/getroot.c [HAVE_GETFSSTAT]: Move `<sys/mount.h>' to ...
* kern/emu/misc.c [HAVE_GETFSSTAT]: ... here.
* kern/emu/getroot.c (find_mount_point_from_dir): Move to ...
* kern/emu/misc.c (grub_find_mount_point_from_dir): ... this. Remove
`static' attribute.
* kern/emu/getroot.c (find_root_device_from_libzfs): Split code for
finding zpool from mount point into ...
* kern/emu/misc.c (grub_find_zpool_from_mount_point): ... this.
* kern/emu/misc.c (grub_make_system_path_relative_to_its_root): When
requested path is part of a ZFS pool, use
grub_find_zpool_from_mount_point() to detect its filesystem name,
and generate a path with `/fsname@path' syntax.
2010-08-01 Colin Watson <cjwatson@ubuntu.com>
* include/grub/util/libzfs.h (libzfs_init): Set argument list to
(void) rather than () so that this is a proper prototype.
2010-08-01 Vladimir Serbinenko <phcoder@gmail.com>
* lib/arg.c (grub_arg_show_help): Add the necessary spacing.
2010-08-01 Vladimir Serbinenko <phcoder@gmail.com>
* kern/emu/getroot.c (find_mount_point_from_dir): Compile only if
[HAVE_LIBZFS && HAVE_LIBNVPAIR]
2010-08-01 Colin Watson <cjwatson@ubuntu.com>
* util/grub-mkrescue.in: Remove ${efi_dir} after building efi.img.
2010-08-01 Colin Watson <cjwatson@ubuntu.com>
* script/yylex.l (NAME): Remove [:digit:], redundant with [:alnum:].
2010-08-01 Colin Watson <cjwatson@ubuntu.com>
* docs/grub.texi (Simple configuration): Document GRUB_CMDLINE_XEN
and GRUB_CMDLINE_XEN_DEFAULT. Recommend setting
GRUB_GFXPAYLOAD_LINUX=text rather than unsetting it in order to
disable gfxpayload.
(Shell-like scripting): Add real content.
(Serial terminal): Suggest `terminal_input serial; terminal_output
serial' rather than putting the two commands on separate lines,
since console input will be inoperative after the first command.
(menuentry): Document --class, --users, and --hotkey options.
(terminfo): Describe what `visually-ordered UTF-8' means (thanks,
Vladimir Serbinenko).
2010-08-01 Vladimir Serbinenko <phcoder@gmail.com>
2010-08-01 Colin Watson <cjwatson@ubuntu.com>
* kern/misc.c (grub_memset): Optimise to reduce cache stalls.
2010-08-01 Robert Millan <rmh@gnu.org>
* include/grub/emu/misc.h (grub_find_mount_point_from_dir)
(grub_find_zpool_from_mount_point): New function prototypes.
* kern/emu/getroot.c [HAVE_GETFSSTAT]: Move `<sys/mount.h>' to ...
* kern/emu/misc.c [HAVE_GETFSSTAT]: ... here.
* kern/emu/getroot.c (find_mount_point_from_dir): Move to ...
* kern/emu/misc.c (grub_find_mount_point_from_dir): ... this. Remove
`static' attribute.
* kern/emu/getroot.c (find_root_device_from_libzfs): Split code for
finding zpool from mount point into ...
* kern/emu/misc.c (grub_find_zpool_from_mount_point): ... this.
* kern/emu/misc.c (grub_make_system_path_relative_to_its_root): When
requested path is part of a ZFS pool, use
grub_find_zpool_from_mount_point() to detect its filesystem name,
and generate a path with `/fsname@path' syntax.
2010-08-01 Robert Millan <rmh@gnu.org>
Prevent accidental use of uninitialized libzfs_handle.
* util/grub-probe.c (main): Move grub_util_init_libzfs() call to ...
* kern/emu/getroot.c (find_root_device_from_libzfs): ... here.
* util/misc.c (grub_util_init_libzfs): Make this function idempotent.
2010-08-01 Colin Watson <cjwatson@ubuntu.com>
* util/grub.d/20_linux_xen.in: Don't use UUID for LVM root (matching
util/grub.d/10_linux.in). Fixes Debian bug #591093.
2010-08-01 Robert Millan <rmh@gnu.org>
* kern/emu/getroot.c: Include `<grub/util/misc.h>'.
2010-07-31 Robert Millan <rmh@gnu.org>
* util/grub.d/10_kfreebsd.in: Make module handling more generic.
2010-07-31 Robert Millan <rmh@gnu.org>
* kern/emu/misc.c: Add missing license header.
2010-07-31 Robert Millan <rmh@gnu.org>
* configure.ac: Check for `libzfs.h' and `libnvpair.h'.
* include/grub/util/libnvpair.h: Include `<config.h>'.
[HAVE_LIBNVPAIR_H]: Include `<libnvpair.h>' instead of
declaring libnvpair prototypes ourselves.
* include/grub/util/libzfs.h: Include `<config.h>'.
[HAVE_LIBZFS_H]: Include `<libzfs.h>' instead of
declaring libzfs prototypes ourselves.
(libzfs_handle): Moved to ...
* include/grub/util/misc.h (libzfs_handle): ... here.
Include `<grub/util/libzfs.h>'.
2010-07-30 Robert Millan <rmh@gnu.org>
* include/grub/emu/misc.h: Add missing license header.
2010-07-30 Robert Millan <rmh@gnu.org>
Enable `grub-probe -t device' resolution on ZFS.
* configure.ac: Check for getfsstat(), libzfs and libnvpair.
* include/grub/util/libnvpair.h: New file.
* include/grub/util/libzfs.h: New file.
* kern/emu/getroot.c: Include `<assert.h>' and `<error.h>'.
[HAVE_LIBZFS && HAVE_LIBNVPAIR]: Include `<grub/util/libzfs.h>' and
`<grub/util/libnvpair.h>'.
[HAVE_GETFSSTAT]: Include `<sys/mount.h>'.
(find_mount_point_from_dir): New static function.
[HAVE_LIBZFS && HAVE_LIBNVPAIR] (find_root_device_from_libzfs): New
function.
[HAVE_LIBZFS && HAVE_LIBNVPAIR] (grub_guess_root_device): Use
find_root_device_from_libzfs() before ressorting to find_root_device().
* include/grub/util/misc.h (grub_util_init_libzfs): New function
prototype.
* util/misc.c: Include `<grub/util/libzfs.h>'.
(grub_util_init_libzfs): New function.
[HAVE_LIBZFS] (libzfs_handle): New global variable.
[HAVE_LIBZFS] (fini_libzfs): New static function.
(grub_util_init_libzfs): New function.
* util/grub-probe.c (main): Call grub_util_init_libzfs().
2010-07-30 Robert Millan <rmh@gnu.org>
* include/grub/emu/misc.h (grub_make_system_path_relative_to_its_root)
(xmalloc, xrealloc, xstrdup, xasprintf): Add
`warn_unused_result' attribute.
* include/grub/misc.h (grub_strdup, grub_strndup, grub_strlen)
(grub_xasprintf, grub_xvasprintf): Likewise.
* include/grub/emu/misc.h (xasprintf): Remove duplicate prototype.
2010-07-29 Robert Millan <rmh@gnu.org>
* util/grub-probe.c (PRINT_FS_LABEL): New enum value.
(probe): Handle `PRINT_FS_LABEL'.
(main): Handle `-t fs_label'.
2010-07-29 Robert Millan <rmh@gnu.org>
* configure.ac: Remove grub-mkisofs checks.
2010-07-28 Vladimir Serbinenko <phcoder@gmail.com>
* util/ieee1275/grub-install.in: Don't use empty grub_device.
Reported by: Lennart Sorensen.
2010-07-20 Vladimir Serbinenko <phcoder@gmail.com>
* util/grub.d/00_header.in: Remove compatibility with terminal.mod
prior to terminal_input/terminal_output separation. It's been over 1.5
years and those versions weren't widely deployed.
2010-07-22 Colin Watson <cjwatson@ubuntu.com>
* disk/raid.c (insert_array): Don't count named arrays when looking
for unused array numbers.
Reported and tested by: Michael Guntsche.
2010-07-20 Colin Watson <cjwatson@ubuntu.com>
* bus/usb/emu/usb.c (grub_usb_poll_devices): Add a dummy
implementation of this so that grub-emu links again, with a note
that this should support hotplugging in the future.
2010-07-20 Colin Watson <cjwatson@ubuntu.com>
* kern/emu/getroot.c (grub_util_get_grub_dev): Use xasprintf.
2010-07-20 Colin Watson <cjwatson@ubuntu.com>
* disk/loopback.c (grub_cmd_loopback): Don't leak a grub_file_t
handle on failure.
(grub_loopback_close): Remove empty function.
(grub_loopback_dev): Remove close method.
2010-07-20 Colin Watson <cjwatson@ubuntu.com>
Disable EFI cursor when the EFI console becomes inactive.
* term/efi/console.c (grub_efi_console_init): New function.
(grub_efi_console_fini): New function.
(grub_console_term_output): Register init and fini methods.
2010-07-20 Vladimir Serbinenko <phcoder@gmail.com>
* tests/util/grub-shell-tester.in: Remove bashism and declare as
sh script.
2010-07-20 Vladimir Serbinenko <phcoder@gmail.com>
* disk/loopback.c (grub_loopback): Replace filename with file.
(delete_loopback): Handle new semantics.
(grub_cmd_loopback): Likewise.
(grub_loopback_iterate): Likewise.
(grub_loopback_close): Likewise.
2010-07-20 Vladimir Serbinenko <phcoder@gmail.com>
* util/i386/efi/grub-install.in: Revert to platform-specific behaviour
with -p "".
Reported by: Tito Keitel.
2010-07-20 Vladimir Serbinenko <phcoder@gmail.com>
* docs/grub.texi (Naming convention): Document new naming convention.
2010-07-20 Vadim Solomin <vadic052@gmail.com>
2010-07-20 Colin Watson <cjwatson@ubuntu.com>
Generate device.map in something closer to the old ordering.
* util/deviceiter.c (struct device): New declaration.
(compare_file_names): Rename to ...
(compare_devices): ... this. Sort by kernel name in preference to
the stable by-id name, but keep the latter as a fallback comparison.
Update header comment.
(grub_util_iterate_devices) [__linux__]: Construct and sort an array
of `struct device' rather than of plain file names.
2010-07-20 Thomas Frauendorfer <Thomas.Frauendorfer@googlemail.com>
* lib/i386/relocator_asm.S [! __x86_64__]: Don't try to disable amd64
on i386.
2010-07-20 Vladimir Serbinenko <phcoder@gmail.com>
* commands/acpi.c (setup_common_tables): Use sizeof instead of
hardcoding size.
(setv1table): Likewise.
2010-07-20 Colin Watson <cjwatson@ubuntu.com>
* disk/raid.c (insert_array): Use md/%s to name mdadm 1.x devices,
removing the homehost if present.
* kern/emu/getroot.c (get_mdadm_name) [__linux__]: New function.
(grub_util_get_grub_dev): Use md/%s to name mdadm 1.x devices,
removing the homehost if present.
(grub_util_get_grub_dev) [__linux__]: Get the array name from mdadm
if possible.
* util/i386/pc/grub-setup.c (main): Handle md/* devices.
* disk/dmraid_nvidia.c (grub_dmraid_nv_detect): Add start_sector
parameter. Set its pointer target to 0.
* disk/mdraid_linux.c (grub_mdraid_detect): Add start_sector
parameter. Set its pointer target to 0 for 0.9 metadata, or to the
`data_offset' value from the superblock for 1.x metadata.
* disk/raid.c (grub_raid_read): Offset reads by the start sector of
data on the device.
(insert_array): Record the start sector of data on the device.
(grub_raid_register): Pass start_sector parameters to
grub_raid_list->detect and insert_array.
* include/grub/raid.h (struct grub_raid_array): Add start_sector
member.
(struct grub_raid): Add start_sector parameter to `detect'.
* disk/mdraid_linux.c (struct grub_raid_super_1x): Remove
__attribute__ ((packed)), leaving a comment.
(grub_mdraid_detect): Split out 0.9 and 1.x detection to ...
(grub_mdraid_detect_09): ... here and ...
(grub_mdraid_detect_1x): ... here.
2010-07-20 Peter Henn <peter.henn@web.de>
* disk/mdraid_linux.c (grub_mdraid_detect): Fix calculation of 1.x
chunk size and disk size, which are already given as sector counts
as distinct from the 0.90 units. Fetch the correct device number
from the role table instead of using the table index.
2010-07-20 Felix Zielcke <fzielcke@z-51.de>
* disk/dmraid_nvidia.c (grub_dmraid_nv_detect): Set array->name to NULL.
* disk/mdraid_linux.c (grub_raid_super_1x): New structure.
(WriteMostly1): New macro.
Set array->name to NULL for metadata format 0.90. Add support for
metadata 1.x. Fix some comments.
* disk/raid.c (): Add support for name based RAID arrays. Fix a
few comments.
* util/getroot.c (grub_util_get_grub_dev): Add support for
/dev/md/name style devices.
2010-07-20 Colin Watson <cjwatson@ubuntu.com>
* .bzrignore: Ignore 20_linux_xen.
2010-07-17 Colin Watson <cjwatson@ubuntu.com>
* util/import_unicode.py: Remove unnecessary imports.
2010-07-17 Aleš Nesrsta <starous@volny.cz>
Hotplugging and USB hub support.
* bus/usb/ohci.c (grub_ohci_td): Add convenience fields.
(grub_ohci): Likewise.
(GRUB_OHCI_REG_CONTROL_BULK_ENABLE): New definition.
(GRUB_OHCI_REG_CONTROL_CONTROL_ENABLE): Likewise.
(GRUB_OHCI_RESET_CONNECT_CHANGE): Likewise.
(GRUB_OHCI_CTRL_EDS): Likewise.
(GRUB_OHCI_BULK_EDS): Likewise.
(GRUB_OHCI_TDS): Likewise.
(GRUB_OHCI_ED_ADDR_MASK): Likewise.
(grub_ohci_ed_phys2virt): New function.
(grub_ohci_virt_to_phys): Likewise.
(grub_ohci_td_phys2virt): Likewise.
(grub_ohci_td_virt2phys): Likewise.
(grub_ohci_pci_iter): Allocate memory and don't wait for stable
attachment.
(grub_ohci_find_ed): New function.
(grub_ohci_alloc_td): Likewise.
(grub_ohci_free_td): Likewise.
(grub_ohci_free_tds): Likewise.
(grub_ohci_transfer): Use previously allocated memory.
(grub_ohci_portstatus): Reset status changed bit.
(grub_ohci_detect_dev): Supply status changed.
(grub_ohci_fini_hw): Free memory.
(grub_ohci_restore_hw): Reallocate memory.
* bus/usb/uhci.c (grub_uhci_portstatus): Don't reset on disable.
Reset status change.
(grub_uhci_detect_dev): Supply status_change.
* bus/usb/usb.c (attach_hooks): New var.
(grub_usb_device_attach): New function.
(grub_usb_register_attach_hook_class): Likewise.
(grub_usb_unregister_attach_hook_class): Likewise.
* bus/usb/usbhub.c (grub_usb_hub_add_dev): Handle errors correctly.
(grub_usb_add_hub): Reset connection changed bit.
(attach_root_port): New function.
(grub_usb_root_hub): Likewise.
(poll_nonroot_hub): Likewise.
(grub_usb_poll_devices): Likewise.
* commands/usbtest.c (grub_cmd_usbtest): Poll devices before listing.
* disk/usbms.c (grub_usbms_open): Use device hooks.
(grub_usbms_iterate) :Poll devices.
(grub_usbms_finddevs): Split into ...
(grub_usbms_attach): ... this ...
(grub_usbms_attach): ... and this.
* include/grub/usb.h (grub_usb_controller_dev): Supply status_changed
in detect_dev.
(grub_usb_interface): New fields attached and detach_hook.
(grub_usb_attach_hook_class): New type.
(grub_usb_attach_desc): New struct.
(grub_usb_register_attach_hook_class): New function.
(grub_usb_unregister_attach_hook_class): Likewise.
(grub_usb_poll_devices): Likewise.
(grub_usb_device_attach): Likewise.
* include/grub/usbtrans.h (GRUB_USB_HUB_FEATURE_C_CONNECTED): New const.
(GRUB_USB_HUB_STATUS_C_CONNECTED): Likewise.
2010-07-17 Vladimir Serbinenko <phcoder@gmail.com>
* include/grub/bsdlabel.h (GRUB_PC_PARTITION_BSD_LABEL_WHOLE_DISK_PARTITION): New definition.
* partmap/bsdlabel.c (bsdlabel_partition_map_iterate): Use FreeBSD
delta determination style. Works with most NetBSD partitions too.
2010-07-17 Vladimir Serbinenko <phcoder@gmail.com>
* kern/partition.c [GRUB_UTIL]: Add missing util/misc.h inclusion.
* partmap/bsdlabel.c [GRUB_UTIL]: Likewise.
2010-07-17 Vladimir Serbinenko <phcoder@gmail.com>
* disk/scsi.c (grub_scsi_open): Fix incorrect pointer dereference.
2010-07-14 Anton Blanchard <anton@samba.org>
* loader/powerpc/ieee1275/linux.c (grub_cmd_linux): Do not reject
ET_DYN files.
2010-07-14 Grégoire Sutre <gregoire.sutre@gmail.com>
* Makefile.in: Use the substituted @USE_NLS@ instead of ENABLE_NLS.
2010-07-14 Grégoire Sutre <gregoire.sutre@gmail.com>
* kern/partition.c (grub_partition_check_containment): New function to
check that a partition is physically contained in a parent. Since
offsets are relative (and non-negative), this reduces to checking that
the partition ends before its parent.
(grub_partition_map_probe): Discard out-of-range sub-partitions.
(grub_partition_iterate): Likewise.
* include/grub/partition.h (grub_partition_map): Slightly more detailed
comments.
* partmap/bsdlabel.c (bsdlabel_partition_map_iterate): Discard
partitions that start before their parent, and add debug printfs.
2010-07-13 Colin Watson <cjwatson@ubuntu.com>
* Makefile.in (.SUFFIX): Spell correctly, as ...
(.SUFFIXES): ... this. Fixes bug where `make foo' (where foo is a
bare module name without `.mod', e.g. `test') tried to invoke a
Modula-2 compiler.
2010-07-13 Colin Watson <cjwatson@ubuntu.com>
* README: Point to the Info manual.
2010-07-13 Jiro SEKIBA <jir@unicus.jp>
* fs/nilfs2.c: fix macro NILFS_2ND_SUPER_BLOCK to calculate
2nd superblock position from partition size.
2010-07-10 Colin Watson <cjwatson@ubuntu.com> 2010-07-10 Colin Watson <cjwatson@ubuntu.com>
* Makefile.in (MAINTAINER_CLEANFILES): Remove * Makefile.in (MAINTAINER_CLEANFILES): Remove

View file

@ -53,7 +53,7 @@ XGETTEXT = @XGETTEXT@
MSGMERGE = @MSGMERGE@ MSGMERGE = @MSGMERGE@
MSGFMT = @MSGFMT@ MSGFMT = @MSGFMT@
ifdef ENABLE_NLS ifeq (@USE_NLS@,yes)
LINGUAS = $(shell for i in $(srcdir)/po/*.po ; do \ LINGUAS = $(shell for i in $(srcdir)/po/*.po ; do \
if test -e $$i ; then echo $$i ; fi ; \ if test -e $$i ; then echo $$i ; fi ; \
done | sed -e "s,.*/po/\(.*\)\.po$$,\1,") done | sed -e "s,.*/po/\(.*\)\.po$$,\1,")
@ -524,8 +524,8 @@ check: all $(UNIT_TESTS) $(FUNCTIONAL_TESTS) $(SCRIPTED_TESTS)
$(builddir)/$$file; \ $(builddir)/$$file; \
done done
.SUFFIX: .SUFFIXES:
.SUFFIX: .c .o .S .d .SUFFIXES: .c .o .S .d
# Regenerate configure and Makefile automatically. # Regenerate configure and Makefile automatically.
$(srcdir)/aclocal.m4: configure.ac acinclude.m4 $(srcdir)/aclocal.m4: configure.ac acinclude.m4

12
README
View file

@ -10,5 +10,13 @@ GRUB 2 data and program files.
Please visit the official web page of GRUB 2, for more information. Please visit the official web page of GRUB 2, for more information.
The URL is <http://www.gnu.org/software/grub/grub.html>. The URL is <http://www.gnu.org/software/grub/grub.html>.
For now, there is not much documentation yet. Please look at the GRUB More extensive documentation is available in the Info manual,
Wiki <http://grub.enbug.org> for testing procedures. accessible using 'info grub' after building and installing GRUB 2.
Please look at the GRUB Wiki <http://grub.enbug.org> for testing
procedures.
There are a number of important user-visible differences from the
first version of GRUB, now known as GRUB Legacy. For a summary, please
see:
info grub Introduction 'Changes from GRUB Legacy'

View file

@ -78,6 +78,12 @@ grub_libusb_devices (void)
return GRUB_USB_ERR_NONE; return GRUB_USB_ERR_NONE;
} }
void
grub_usb_poll_devices (void)
{
/* TODO: recheck grub_usb_devs */
}
int int
grub_usb_iterate (int (*hook) (grub_usb_device_t dev)) grub_usb_iterate (int (*hook) (grub_usb_device_t dev))

File diff suppressed because it is too large Load diff

View file

@ -612,8 +612,23 @@ grub_uhci_portstatus (grub_usb_controller_t dev,
status = grub_uhci_readreg16 (u, reg); status = grub_uhci_readreg16 (u, reg);
grub_dprintf ("uhci", "detect=0x%02x\n", status); grub_dprintf ("uhci", "detect=0x%02x\n", status);
if (!enable) /* We don't need reset port */
{
/* Disable the port. */
grub_uhci_writereg16 (u, reg, 0 << 2);
grub_dprintf ("uhci", "waiting for the port to be disabled\n");
endtime = grub_get_time_ms () + 1000;
while ((grub_uhci_readreg16 (u, reg) & (1 << 2)))
if (grub_get_time_ms () > endtime)
return grub_error (GRUB_ERR_IO, "UHCI Timed out");
status = grub_uhci_readreg16 (u, reg);
grub_dprintf ("uhci", ">3detect=0x%02x\n", status);
return GRUB_ERR_NONE;
}
/* Reset the port. */ /* Reset the port. */
grub_uhci_writereg16 (u, reg, enable << 9); grub_uhci_writereg16 (u, reg, 1 << 9);
/* Wait for the reset to complete. XXX: How long exactly? */ /* Wait for the reset to complete. XXX: How long exactly? */
grub_millisleep (50); /* For root hub should be nominaly 50ms */ grub_millisleep (50); /* For root hub should be nominaly 50ms */
@ -623,16 +638,20 @@ grub_uhci_portstatus (grub_usb_controller_t dev,
grub_millisleep (10); grub_millisleep (10);
/* Enable the port. */ /* Enable the port. */
grub_uhci_writereg16 (u, reg, enable << 2); grub_uhci_writereg16 (u, reg, 1 << 2);
grub_millisleep (10); grub_millisleep (10);
grub_dprintf ("uhci", "waiting for the port to be enabled\n"); grub_dprintf ("uhci", "waiting for the port to be enabled\n");
endtime = grub_get_time_ms () + 1000; endtime = grub_get_time_ms () + 1000;
while (! (grub_uhci_readreg16 (u, reg) & (1 << 2))) while (! ((status = grub_uhci_readreg16 (u, reg)) & (1 << 2)))
if (grub_get_time_ms () > endtime) if (grub_get_time_ms () > endtime)
return grub_error (GRUB_ERR_IO, "UHCI Timed out"); return grub_error (GRUB_ERR_IO, "UHCI Timed out");
/* Reset bit Connect Status Change */
grub_uhci_writereg16 (u, reg, status | (1 << 1));
/* Read final port status */
status = grub_uhci_readreg16 (u, reg); status = grub_uhci_readreg16 (u, reg);
grub_dprintf ("uhci", ">3detect=0x%02x\n", status); grub_dprintf ("uhci", ">3detect=0x%02x\n", status);
@ -641,7 +660,7 @@ grub_uhci_portstatus (grub_usb_controller_t dev,
} }
static grub_usb_speed_t static grub_usb_speed_t
grub_uhci_detect_dev (grub_usb_controller_t dev, int port) grub_uhci_detect_dev (grub_usb_controller_t dev, int port, int *changed)
{ {
struct grub_uhci *u = (struct grub_uhci *) dev->data; struct grub_uhci *u = (struct grub_uhci *) dev->data;
int reg; int reg;
@ -661,6 +680,9 @@ grub_uhci_detect_dev (grub_usb_controller_t dev, int port)
grub_dprintf ("uhci", "detect=0x%02x port=%d\n", status, port); grub_dprintf ("uhci", "detect=0x%02x port=%d\n", status, port);
/* Connect Status Change bit - it detects change of connection */
*changed = ((status & (1 << 1)) != 0);
if (! (status & 1)) if (! (status & 1))
return GRUB_USB_SPEED_NONE; return GRUB_USB_SPEED_NONE;
else if (status & (1 << 8)) else if (status & (1 << 8))

View file

@ -21,8 +21,10 @@
#include <grub/mm.h> #include <grub/mm.h>
#include <grub/usb.h> #include <grub/usb.h>
#include <grub/misc.h> #include <grub/misc.h>
#include <grub/list.h>
static grub_usb_controller_dev_t grub_usb_list; static grub_usb_controller_dev_t grub_usb_list;
struct grub_usb_attach_desc *attach_hooks;
void void
grub_usb_controller_dev_register (grub_usb_controller_dev_t usb) grub_usb_controller_dev_register (grub_usb_controller_dev_t usb)
@ -232,3 +234,75 @@ grub_usb_device_initialize (grub_usb_device_t dev)
return err; return err;
} }
void grub_usb_device_attach (grub_usb_device_t dev)
{
int i;
/* XXX: Just check configuration 0 for now. */
for (i = 0; i < dev->config[0].descconf->numif; i++)
{
struct grub_usb_desc_if *interf;
struct grub_usb_attach_desc *desc;
interf = dev->config[0].interf[i].descif;
grub_dprintf ("usb", "iterate: interf=%d, class=%d, subclass=%d, protocol=%d\n",
i, interf->class, interf->subclass, interf->protocol);
if (dev->config[0].interf[i].attached)
continue;
for (desc = attach_hooks; desc; desc = desc->next)
if (interf->class == desc->class && desc->hook (dev, 0, i))
dev->config[0].interf[i].attached = 1;
}
}
void
grub_usb_register_attach_hook_class (struct grub_usb_attach_desc *desc)
{
auto int usb_iterate (grub_usb_device_t dev);
int usb_iterate (grub_usb_device_t usbdev)
{
struct grub_usb_desc_device *descdev = &usbdev->descdev;
int i;
if (descdev->class != 0 || descdev->subclass || descdev->protocol != 0
|| descdev->configcnt == 0)
return 0;
/* XXX: Just check configuration 0 for now. */
for (i = 0; i < usbdev->config[0].descconf->numif; i++)
{
struct grub_usb_desc_if *interf;
interf = usbdev->config[0].interf[i].descif;
grub_dprintf ("usb", "iterate: interf=%d, class=%d, subclass=%d, protocol=%d\n",
i, interf->class, interf->subclass, interf->protocol);
if (usbdev->config[0].interf[i].attached)
continue;
if (interf->class != desc->class)
continue;
if (desc->hook (usbdev, 0, i))
usbdev->config[0].interf[i].attached = 1;
}
return 0;
}
desc->next = attach_hooks;
attach_hooks = desc;
grub_usb_iterate (usb_iterate);
}
void
grub_usb_unregister_attach_hook_class (struct grub_usb_attach_desc *desc)
{
grub_list_remove (GRUB_AS_LIST_P (&attach_hooks), GRUB_AS_LIST (desc));
}

View file

@ -23,8 +23,21 @@
#include <grub/misc.h> #include <grub/misc.h>
#include <grub/time.h> #include <grub/time.h>
#define GRUB_USBHUB_MAX_DEVICES 128
/* USB Supports 127 devices, with device 0 as special case. */ /* USB Supports 127 devices, with device 0 as special case. */
static struct grub_usb_device *grub_usb_devs[128]; static struct grub_usb_device *grub_usb_devs[GRUB_USBHUB_MAX_DEVICES];
struct grub_usb_hub
{
struct grub_usb_hub *next;
grub_usb_controller_t controller;
int nports;
grub_usb_speed_t *speed;
grub_usb_device_t dev;
};
struct grub_usb_hub *hubs;
/* Add a device that currently has device number 0 and resides on /* Add a device that currently has device number 0 and resides on
CONTROLLER, the Hub reported that the device speed is SPEED. */ CONTROLLER, the Hub reported that the device speed is SPEED. */
@ -33,6 +46,7 @@ grub_usb_hub_add_dev (grub_usb_controller_t controller, grub_usb_speed_t speed)
{ {
grub_usb_device_t dev; grub_usb_device_t dev;
int i; int i;
grub_usb_err_t err;
dev = grub_zalloc (sizeof (struct grub_usb_device)); dev = grub_zalloc (sizeof (struct grub_usb_device));
if (! dev) if (! dev)
@ -41,31 +55,51 @@ grub_usb_hub_add_dev (grub_usb_controller_t controller, grub_usb_speed_t speed)
dev->controller = *controller; dev->controller = *controller;
dev->speed = speed; dev->speed = speed;
grub_usb_device_initialize (dev); err = grub_usb_device_initialize (dev);
if (err)
{
grub_free (dev);
return NULL;
}
/* Assign a new address to the device. */ /* Assign a new address to the device. */
for (i = 1; i < 128; i++) for (i = 1; i < GRUB_USBHUB_MAX_DEVICES; i++)
{ {
if (! grub_usb_devs[i]) if (! grub_usb_devs[i])
break; break;
} }
if (i == 128) if (i == GRUB_USBHUB_MAX_DEVICES)
{ {
grub_error (GRUB_ERR_IO, "can't assign address to USB device"); grub_error (GRUB_ERR_IO, "can't assign address to USB device");
for (i = 0; i < 8; i++)
grub_free (dev->config[i].descconf);
grub_free (dev);
return NULL; return NULL;
} }
grub_usb_control_msg (dev, err = grub_usb_control_msg (dev,
(GRUB_USB_REQTYPE_OUT (GRUB_USB_REQTYPE_OUT
| GRUB_USB_REQTYPE_STANDARD | GRUB_USB_REQTYPE_STANDARD
| GRUB_USB_REQTYPE_TARGET_DEV), | GRUB_USB_REQTYPE_TARGET_DEV),
GRUB_USB_REQ_SET_ADDRESS, GRUB_USB_REQ_SET_ADDRESS,
i, 0, 0, NULL); i, 0, 0, NULL);
if (err)
{
for (i = 0; i < 8; i++)
grub_free (dev->config[i].descconf);
grub_free (dev);
return NULL;
}
dev->addr = i; dev->addr = i;
dev->initialized = 1; dev->initialized = 1;
grub_usb_devs[i] = dev; grub_usb_devs[i] = dev;
/* Wait "recovery interval", spec. says 2ms */
grub_millisleep (2);
grub_usb_device_attach (dev);
return dev; return dev;
} }
@ -181,6 +215,21 @@ grub_usb_add_hub (grub_usb_device_t dev)
if (err || !(status & GRUB_USB_HUB_STATUS_C_PORT_RESET) ) if (err || !(status & GRUB_USB_HUB_STATUS_C_PORT_RESET) )
continue; continue;
/* Wait a recovery time after reset, spec. says 10ms */
grub_millisleep (10);
/* Do reset of connection change bit */
err = grub_usb_control_msg (dev, (GRUB_USB_REQTYPE_OUT
| GRUB_USB_REQTYPE_CLASS
| GRUB_USB_REQTYPE_TARGET_OTHER),
GRUB_USB_REQ_CLEAR_FEATURE,
GRUB_USB_HUB_FEATURE_C_CONNECTED,
i, 0, 0);
/* Just ignore the device if the Hub reports some error */
if (err)
continue;
grub_dprintf ("usb", "Hub port - cleared connection change\n");
/* Add the device and assign a device address to it. */ /* Add the device and assign a device address to it. */
grub_dprintf ("usb", "Call hub_add_dev - port %d\n", i); grub_dprintf ("usb", "Call hub_add_dev - port %d\n", i);
next_dev = grub_usb_hub_add_dev (&dev->controller, speed); next_dev = grub_usb_hub_add_dev (&dev->controller, speed);
@ -196,49 +245,237 @@ grub_usb_add_hub (grub_usb_device_t dev)
return GRUB_ERR_NONE; return GRUB_ERR_NONE;
} }
grub_usb_err_t static void
grub_usb_root_hub (grub_usb_controller_t controller) attach_root_port (grub_usb_controller_t controller, int portno,
grub_usb_speed_t speed)
{ {
grub_err_t err;
int ports;
int i;
/* Query the number of ports the root Hub has. */
ports = controller->dev->hubports (controller);
for (i = 0; i < ports; i++)
{
grub_usb_speed_t speed = controller->dev->detect_dev (controller, i);
if (speed != GRUB_USB_SPEED_NONE)
{
grub_usb_device_t dev; grub_usb_device_t dev;
grub_err_t err;
/* Disable the port. XXX: Why? */
err = controller->dev->portstatus (controller, portno, 0);
if (err)
return;
/* Enable the port. */ /* Enable the port. */
err = controller->dev->portstatus (controller, i, 1); err = controller->dev->portstatus (controller, portno, 1);
if (err) if (err)
continue; return;
/* Enable the port and create a device. */ /* Enable the port and create a device. */
dev = grub_usb_hub_add_dev (controller, speed); dev = grub_usb_hub_add_dev (controller, speed);
if (! dev) if (! dev)
continue; return;
/* If the device is a Hub, scan it for more devices. */ /* If the device is a Hub, scan it for more devices. */
if (dev->descdev.class == 0x09) if (dev->descdev.class == 0x09)
grub_usb_add_hub (dev); grub_usb_add_hub (dev);
}
grub_usb_err_t
grub_usb_root_hub (grub_usb_controller_t controller)
{
int i;
struct grub_usb_hub *hub;
int changed=0;
hub = grub_malloc (sizeof (*hub));
if (!hub)
return GRUB_USB_ERR_INTERNAL;
hub->next = hubs;
hubs = hub;
hub->controller = grub_malloc (sizeof (*controller));
if (!hub->controller)
{
grub_free (hub);
return GRUB_USB_ERR_INTERNAL;
} }
grub_memcpy (hub->controller, controller, sizeof (*controller));
hub->dev = 0;
/* Query the number of ports the root Hub has. */
hub->nports = controller->dev->hubports (controller);
hub->speed = grub_malloc (sizeof (hub->speed[0]) * hub->nports);
if (!hub->speed)
{
grub_free (hub->controller);
grub_free (hub);
return GRUB_USB_ERR_INTERNAL;
}
for (i = 0; i < hub->nports; i++)
{
hub->speed[i] = controller->dev->detect_dev (hub->controller, i,
&changed);
if (hub->speed[i] != GRUB_USB_SPEED_NONE)
attach_root_port (hub->controller, i, hub->speed[i]);
} }
return GRUB_USB_ERR_NONE; return GRUB_USB_ERR_NONE;
} }
static void
poll_nonroot_hub (grub_usb_device_t dev)
{
struct grub_usb_usb_hubdesc hubdesc;
grub_err_t err;
int i;
grub_uint64_t timeout;
grub_usb_device_t next_dev;
err = grub_usb_control_msg (dev, (GRUB_USB_REQTYPE_IN
| GRUB_USB_REQTYPE_CLASS
| GRUB_USB_REQTYPE_TARGET_DEV),
GRUB_USB_REQ_GET_DESCRIPTOR,
(GRUB_USB_DESCRIPTOR_HUB << 8) | 0,
0, sizeof (hubdesc), (char *) &hubdesc);
if (err)
return;
/* Iterate over the Hub ports. */
for (i = 1; i <= hubdesc.portcnt; i++)
{
grub_uint32_t status;
/* Get the port status. */
err = grub_usb_control_msg (dev, (GRUB_USB_REQTYPE_IN
| GRUB_USB_REQTYPE_CLASS
| GRUB_USB_REQTYPE_TARGET_OTHER),
GRUB_USB_REQ_GET_STATUS,
0, i, sizeof (status), (char *) &status);
/* Just ignore the device if the Hub does not report the
status. */
if (err)
continue;
/* Connected and status of connection changed ? */
if ((status & GRUB_USB_HUB_STATUS_CONNECTED)
&& (status & GRUB_USB_HUB_STATUS_C_CONNECTED))
{
grub_usb_speed_t speed;
/* Determine the device speed. */
if (status & GRUB_USB_HUB_STATUS_LOWSPEED)
speed = GRUB_USB_SPEED_LOW;
else
{
if (status & GRUB_USB_HUB_STATUS_HIGHSPEED)
speed = GRUB_USB_SPEED_HIGH;
else
speed = GRUB_USB_SPEED_FULL;
}
/* A device is actually connected to this port.
* Now do reset of port. */
err = grub_usb_control_msg (dev, (GRUB_USB_REQTYPE_OUT
| GRUB_USB_REQTYPE_CLASS
| GRUB_USB_REQTYPE_TARGET_OTHER),
GRUB_USB_REQ_SET_FEATURE,
GRUB_USB_HUB_FEATURE_PORT_RESET,
i, 0, 0);
/* If the Hub does not cooperate for this port, just skip
the port. */
if (err)
continue;
/* Wait for reset procedure done */
timeout = grub_get_time_ms () + 1000;
do
{
/* Get the port status. */
err = grub_usb_control_msg (dev, (GRUB_USB_REQTYPE_IN
| GRUB_USB_REQTYPE_CLASS
| GRUB_USB_REQTYPE_TARGET_OTHER),
GRUB_USB_REQ_GET_STATUS,
0, i, sizeof (status), (char *) &status);
}
while (!err &&
!(status & GRUB_USB_HUB_STATUS_C_PORT_RESET) &&
(grub_get_time_ms() < timeout) );
if (err || !(status & GRUB_USB_HUB_STATUS_C_PORT_RESET) )
continue;
/* Wait a recovery time after reset, spec. says 10ms */
grub_millisleep (10);
/* Do reset of connection change bit */
err = grub_usb_control_msg (dev, (GRUB_USB_REQTYPE_OUT
| GRUB_USB_REQTYPE_CLASS
| GRUB_USB_REQTYPE_TARGET_OTHER),
GRUB_USB_REQ_CLEAR_FEATURE,
GRUB_USB_HUB_FEATURE_C_CONNECTED,
i, 0, 0);
/* Just ignore the device if the Hub reports some error */
if (err)
continue;
/* Add the device and assign a device address to it. */
next_dev = grub_usb_hub_add_dev (&dev->controller, speed);
if (! next_dev)
continue;
/* If the device is a Hub, scan it for more devices. */
if (next_dev->descdev.class == 0x09)
grub_usb_add_hub (next_dev);
}
}
return;
}
void
grub_usb_poll_devices (void)
{
struct grub_usb_hub *hub;
int i;
for (hub = hubs; hub; hub = hub->next)
{
int changed=0;
/* Do we have to recheck number of ports? */
/* No, it should be never changed, it should be constant. */
for (i = 0; i < hub->nports; i++)
{
grub_usb_speed_t speed;
speed = hub->controller->dev->detect_dev (hub->controller, i,
&changed);
if (speed != GRUB_USB_SPEED_NONE)
{
if (changed)
attach_root_port (hub->controller, i, speed);
}
/* XXX: There should be also handling
* of disconnected devices. */
hub->speed[i] = speed;
}
}
/* We should check changes of non-root hubs too. */
for (i = 0; i < GRUB_USBHUB_MAX_DEVICES; i++)
{
grub_usb_device_t dev = grub_usb_devs[i];
if (dev && dev->descdev.class == 0x09)
{
poll_nonroot_hub (dev);
}
}
}
int int
grub_usb_iterate (int (*hook) (grub_usb_device_t dev)) grub_usb_iterate (int (*hook) (grub_usb_device_t dev))
{ {
int i; int i;
for (i = 0; i < 128; i++) for (i = 0; i < GRUB_USBHUB_MAX_DEVICES; i++)
{ {
if (grub_usb_devs[i]) if (grub_usb_devs[i])
{ {

View file

@ -81,7 +81,7 @@ grub_usb_control_msg (grub_usb_device_t dev,
else else
max = 64; max = 64;
grub_dprintf ("usb", "transfer = %p, dev = %p\n", transfer, dev); grub_dprintf ("usb", "control: transfer = %p, dev = %p\n", transfer, dev);
datablocks = (size + max - 1) / max; datablocks = (size + max - 1) / max;
@ -146,6 +146,7 @@ grub_usb_control_msg (grub_usb_device_t dev,
transfer->transactions[datablocks + 1].toggle = 1; transfer->transactions[datablocks + 1].toggle = 1;
err = dev->controller.dev->transfer (&dev->controller, transfer); err = dev->controller.dev->transfer (&dev->controller, transfer);
grub_dprintf ("usb", "control: err=%d\n", err);
grub_free (transfer->transactions); grub_free (transfer->transactions);
@ -174,6 +175,8 @@ grub_usb_bulk_readwrite (grub_usb_device_t dev,
struct grub_pci_dma_chunk *data_chunk; struct grub_pci_dma_chunk *data_chunk;
grub_size_t size = size0; grub_size_t size = size0;
grub_dprintf ("usb", "bulk: size=0x%02x type=%d\n", size, type);
/* FIXME: avoid allocation any kind of buffer in a first place. */ /* FIXME: avoid allocation any kind of buffer in a first place. */
data_chunk = grub_memalign_dma32 (128, size); data_chunk = grub_memalign_dma32 (128, size);
if (!data_chunk) if (!data_chunk)
@ -248,7 +251,7 @@ grub_usb_bulk_readwrite (grub_usb_device_t dev,
toggle = transfer->transactions[transfer->last_trans].toggle ? 0 : 1; toggle = transfer->transactions[transfer->last_trans].toggle ? 0 : 1;
else else
toggle = dev->toggle[endpoint]; /* Nothing done, take original */ toggle = dev->toggle[endpoint]; /* Nothing done, take original */
grub_dprintf ("usb", "toggle=%d\n", toggle); grub_dprintf ("usb", "bulk: err=%d, toggle=%d\n", err, toggle);
dev->toggle[endpoint] = toggle; dev->toggle[endpoint] = toggle;
grub_free (transfer->transactions); grub_free (transfer->transactions);

View file

@ -325,7 +325,8 @@ setup_common_tables (void)
/* If it's FADT correct DSDT and FACS addresses. */ /* If it's FADT correct DSDT and FACS addresses. */
fadt = (struct grub_acpi_fadt *) cur->addr; fadt = (struct grub_acpi_fadt *) cur->addr;
if (grub_memcmp (fadt->hdr.signature, "FACP", 4) == 0) if (grub_memcmp (fadt->hdr.signature, "FACP",
sizeof (fadt->hdr.signature)) == 0)
{ {
fadt->dsdt_addr = PTR_TO_UINT32 (table_dsdt); fadt->dsdt_addr = PTR_TO_UINT32 (table_dsdt);
fadt->facs_addr = facs_addr; fadt->facs_addr = facs_addr;
@ -351,16 +352,16 @@ setup_common_tables (void)
rsdt_addr = rsdt = (struct grub_acpi_table_header *) playground_ptr; rsdt_addr = rsdt = (struct grub_acpi_table_header *) playground_ptr;
playground_ptr += sizeof (struct grub_acpi_table_header) + 4 * numoftables; playground_ptr += sizeof (struct grub_acpi_table_header) + 4 * numoftables;
rsdt_entry = (grub_uint32_t *)(rsdt + 1); rsdt_entry = (grub_uint32_t *) (rsdt + 1);
/* Fill RSDT header. */ /* Fill RSDT header. */
grub_memcpy (&(rsdt->signature), "RSDT", 4); grub_memcpy (&(rsdt->signature), "RSDT", 4);
rsdt->length = sizeof (struct grub_acpi_table_header) + 4 * numoftables; rsdt->length = sizeof (struct grub_acpi_table_header) + 4 * numoftables;
rsdt->revision = 1; rsdt->revision = 1;
grub_memcpy (&(rsdt->oemid), root_oemid, 6); grub_memcpy (&(rsdt->oemid), root_oemid, sizeof (rsdt->oemid));
grub_memcpy (&(rsdt->oemtable), root_oemtable, 4); grub_memcpy (&(rsdt->oemtable), root_oemtable, sizeof (rsdt->oemtable));
rsdt->oemrev = root_oemrev; rsdt->oemrev = root_oemrev;
grub_memcpy (&(rsdt->creator_id), root_creator_id, 6); grub_memcpy (&(rsdt->creator_id), root_creator_id, sizeof (rsdt->creator_id));
rsdt->creator_rev = root_creator_rev; rsdt->creator_rev = root_creator_rev;
for (cur = acpi_tables; cur; cur = cur->next) for (cur = acpi_tables; cur; cur = cur->next)
@ -378,7 +379,8 @@ setv1table (void)
/* Create RSDP. */ /* Create RSDP. */
rsdpv1_new = (struct grub_acpi_rsdp_v10 *) playground_ptr; rsdpv1_new = (struct grub_acpi_rsdp_v10 *) playground_ptr;
playground_ptr += sizeof (struct grub_acpi_rsdp_v10); playground_ptr += sizeof (struct grub_acpi_rsdp_v10);
grub_memcpy (&(rsdpv1_new->signature), "RSD PTR ", 8); grub_memcpy (&(rsdpv1_new->signature), "RSD PTR ",
sizeof (rsdpv1_new->signature));
grub_memcpy (&(rsdpv1_new->oemid), root_oemid, sizeof (rsdpv1_new->oemid)); grub_memcpy (&(rsdpv1_new->oemid), root_oemid, sizeof (rsdpv1_new->oemid));
rsdpv1_new->revision = 0; rsdpv1_new->revision = 0;
rsdpv1_new->rsdt_addr = PTR_TO_UINT32 (rsdt_addr); rsdpv1_new->rsdt_addr = PTR_TO_UINT32 (rsdt_addr);

View file

@ -194,6 +194,8 @@ grub_cmd_usbtest (grub_command_t cmd __attribute__ ((unused)),
int argc __attribute__ ((unused)), int argc __attribute__ ((unused)),
char **args __attribute__ ((unused))) char **args __attribute__ ((unused)))
{ {
grub_usb_poll_devices ();
grub_printf ("USB devices:\n\n"); grub_printf ("USB devices:\n\n");
grub_usb_iterate (usb_iterate); grub_usb_iterate (usb_iterate);

View file

@ -246,15 +246,9 @@ else
AC_PATH_PROG(HELP2MAN, help2man) AC_PATH_PROG(HELP2MAN, help2man)
fi fi
# Check for functions. # Check for functions and headers.
AC_CHECK_FUNCS(posix_memalign memalign asprintf vasprintf) AC_CHECK_FUNCS(posix_memalign memalign asprintf vasprintf)
AC_CHECK_HEADERS(libzfs.h libnvpair.h sys/param.h sys/mount.h)
# For grub-mkisofs
AC_HEADER_MAJOR
AC_HEADER_DIRENT
AC_CHECK_FUNCS(memmove sbrk strdup lstat getuid getgid)
AC_CHECK_HEADERS(sys/mkdev.h sys/sysmacros.h malloc.h termios.h sys/types.h)
AC_CHECK_HEADERS(unistd.h string.h strings.h sys/stat.h sys/fcntl.h limits.h)
# For opendisk() and getrawpartition() on NetBSD. # For opendisk() and getrawpartition() on NetBSD.
# Used in util/deviceiter.c and in util/hostdisk.c. # Used in util/deviceiter.c and in util/hostdisk.c.
@ -806,6 +800,15 @@ if test x"$device_mapper_excuse" = x ; then
[device_mapper_excuse="need devmapper library"]) [device_mapper_excuse="need devmapper library"])
fi fi
AC_CHECK_LIB([zfs], [libzfs_init],
[LDFLAGS="$LDFLAGS -lzfs"
AC_DEFINE([HAVE_LIBZFS], [1],
[Define to 1 if you have the ZFS library.])],)
AC_CHECK_LIB([nvpair], [nvlist_print],
[LDFLAGS="$LDFLAGS -lnvpair"
AC_DEFINE([HAVE_LIBNVPAIR], [1],
[Define to 1 if you have the NVPAIR library.])],)
AC_SUBST(ASFLAGS) AC_SUBST(ASFLAGS)
# Output files. # Output files.

View file

@ -89,7 +89,8 @@ struct grub_nv_super
} __attribute__ ((packed)); } __attribute__ ((packed));
static grub_err_t static grub_err_t
grub_dmraid_nv_detect (grub_disk_t disk, struct grub_raid_array *array) grub_dmraid_nv_detect (grub_disk_t disk, struct grub_raid_array *array,
grub_disk_addr_t *start_sector)
{ {
grub_disk_addr_t sector; grub_disk_addr_t sector;
struct grub_nv_super sb; struct grub_nv_super sb;
@ -132,6 +133,7 @@ grub_dmraid_nv_detect (grub_disk_t disk, struct grub_raid_array *array)
"unsupported RAID level: %d", sb.array.raid_level); "unsupported RAID level: %d", sb.array.raid_level);
} }
array->name = NULL;
array->number = 0; array->number = 0;
array->total_devs = sb.array.total_volumes; array->total_devs = sb.array.total_volumes;
array->chunk_size = sb.array.stripe_block_size; array->chunk_size = sb.array.stripe_block_size;
@ -144,6 +146,8 @@ grub_dmraid_nv_detect (grub_disk_t disk, struct grub_raid_array *array)
grub_memcpy (array->uuid, (char *) &sb.array.signature, grub_memcpy (array->uuid, (char *) &sb.array.signature,
sizeof (sb.array.signature)); sizeof (sb.array.signature));
*start_sector = 0;
return 0; return 0;
} }

View file

@ -28,7 +28,7 @@
struct grub_loopback struct grub_loopback
{ {
char *devname; char *devname;
char *filename; grub_file_t file;
int has_partitions; int has_partitions;
struct grub_loopback *next; struct grub_loopback *next;
}; };
@ -63,7 +63,7 @@ delete_loopback (const char *name)
*prev = dev->next; *prev = dev->next;
grub_free (dev->devname); grub_free (dev->devname);
grub_free (dev->filename); grub_file_close (dev->file);
grub_free (dev); grub_free (dev);
return 0; return 0;
@ -76,6 +76,7 @@ grub_cmd_loopback (grub_extcmd_t cmd, int argc, char **args)
struct grub_arg_list *state = state = cmd->state; struct grub_arg_list *state = state = cmd->state;
grub_file_t file; grub_file_t file;
struct grub_loopback *newdev; struct grub_loopback *newdev;
grub_err_t ret;
if (argc < 1) if (argc < 1)
return grub_error (GRUB_ERR_BAD_ARGUMENT, "device name required"); return grub_error (GRUB_ERR_BAD_ARGUMENT, "device name required");
@ -91,9 +92,6 @@ grub_cmd_loopback (grub_extcmd_t cmd, int argc, char **args)
if (! file) if (! file)
return grub_errno; return grub_errno;
/* Close the file, the only reason for opening it is validation. */
grub_file_close (file);
/* First try to replace the old device. */ /* First try to replace the old device. */
for (newdev = loopback_list; newdev; newdev = newdev->next) for (newdev = loopback_list; newdev; newdev = newdev->next)
if (grub_strcmp (newdev->devname, args[0]) == 0) if (grub_strcmp (newdev->devname, args[0]) == 0)
@ -103,10 +101,10 @@ grub_cmd_loopback (grub_extcmd_t cmd, int argc, char **args)
{ {
char *newname = grub_strdup (args[1]); char *newname = grub_strdup (args[1]);
if (! newname) if (! newname)
return grub_errno; goto fail;
grub_free (newdev->filename); grub_file_close (newdev->file);
newdev->filename = newname; newdev->file = file;
/* Set has_partitions when `--partitions' was used. */ /* Set has_partitions when `--partitions' was used. */
newdev->has_partitions = state[1].set; newdev->has_partitions = state[1].set;
@ -117,22 +115,16 @@ grub_cmd_loopback (grub_extcmd_t cmd, int argc, char **args)
/* Unable to replace it, make a new entry. */ /* Unable to replace it, make a new entry. */
newdev = grub_malloc (sizeof (struct grub_loopback)); newdev = grub_malloc (sizeof (struct grub_loopback));
if (! newdev) if (! newdev)
return grub_errno; goto fail;
newdev->devname = grub_strdup (args[0]); newdev->devname = grub_strdup (args[0]);
if (! newdev->devname) if (! newdev->devname)
{ {
grub_free (newdev); grub_free (newdev);
return grub_errno; goto fail;
} }
newdev->filename = grub_strdup (args[1]); newdev->file = file;
if (! newdev->filename)
{
grub_free (newdev->devname);
grub_free (newdev);
return grub_errno;
}
/* Set has_partitions when `--partitions' was used. */ /* Set has_partitions when `--partitions' was used. */
newdev->has_partitions = state[1].set; newdev->has_partitions = state[1].set;
@ -142,6 +134,11 @@ grub_cmd_loopback (grub_extcmd_t cmd, int argc, char **args)
loopback_list = newdev; loopback_list = newdev;
return 0; return 0;
fail:
ret = grub_errno;
grub_file_close (file);
return ret;
} }
@ -160,7 +157,6 @@ grub_loopback_iterate (int (*hook) (const char *name))
static grub_err_t static grub_err_t
grub_loopback_open (const char *name, grub_disk_t disk) grub_loopback_open (const char *name, grub_disk_t disk)
{ {
grub_file_t file;
struct grub_loopback *dev; struct grub_loopback *dev;
for (dev = loopback_list; dev; dev = dev->next) for (dev = loopback_list; dev; dev = dev->next)
@ -170,29 +166,17 @@ grub_loopback_open (const char *name, grub_disk_t disk)
if (! dev) if (! dev)
return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "can't open device"); return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "can't open device");
file = grub_file_open (dev->filename);
if (! file)
return grub_errno;
/* Use the filesize for the disk size, round up to a complete sector. */ /* Use the filesize for the disk size, round up to a complete sector. */
disk->total_sectors = ((file->size + GRUB_DISK_SECTOR_SIZE - 1) disk->total_sectors = ((dev->file->size + GRUB_DISK_SECTOR_SIZE - 1)
/ GRUB_DISK_SECTOR_SIZE); / GRUB_DISK_SECTOR_SIZE);
disk->id = (unsigned long) dev; disk->id = (unsigned long) dev;
disk->has_partitions = dev->has_partitions; disk->has_partitions = dev->has_partitions;
disk->data = file; disk->data = dev->file;
return 0; return 0;
} }
static void
grub_loopback_close (grub_disk_t disk)
{
grub_file_t file = (grub_file_t) disk->data;
grub_file_close (file);
}
static grub_err_t static grub_err_t
grub_loopback_read (grub_disk_t disk, grub_disk_addr_t sector, grub_loopback_read (grub_disk_t disk, grub_disk_addr_t sector,
grub_size_t size, char *buf) grub_size_t size, char *buf)
@ -234,7 +218,6 @@ static struct grub_disk_dev grub_loopback_dev =
.id = GRUB_DISK_DEVICE_LOOPBACK_ID, .id = GRUB_DISK_DEVICE_LOOPBACK_ID,
.iterate = grub_loopback_iterate, .iterate = grub_loopback_iterate,
.open = grub_loopback_open, .open = grub_loopback_open,
.close = grub_loopback_close,
.read = grub_loopback_read, .read = grub_loopback_read,
.write = grub_loopback_write, .write = grub_loopback_write,
.next = 0 .next = 0

View file

@ -1,7 +1,7 @@
/* mdraid_linux.c - module to handle linux softraid. */ /* mdraid_linux.c - module to handle Linux Software RAID. */
/* /*
* GRUB -- GRand Unified Bootloader * GRUB -- GRand Unified Bootloader
* Copyright (C) 2008 Free Software Foundation, Inc. * Copyright (C) 2008,2009,2010 Free Software Foundation, Inc.
* *
* GRUB is free software: you can redistribute it and/or modify * GRUB is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -159,63 +159,254 @@ struct grub_raid_super_09
struct grub_raid_disk_09 this_disk; struct grub_raid_disk_09 this_disk;
} __attribute__ ((packed)); } __attribute__ ((packed));
static grub_err_t /*
grub_mdraid_detect (grub_disk_t disk, struct grub_raid_array *array) * The version-1 superblock :
* All numeric fields are little-endian.
*
* Total size: 256 bytes plus 2 per device.
* 1K allows 384 devices.
*/
struct grub_raid_super_1x
{
/* Constant array information - 128 bytes. */
grub_uint32_t magic; /* MD_SB_MAGIC: 0xa92b4efc - little endian. */
grub_uint32_t major_version; /* 1. */
grub_uint32_t feature_map; /* Bit 0 set if 'bitmap_offset' is meaningful. */
grub_uint32_t pad0; /* Always set to 0 when writing. */
grub_uint8_t set_uuid[16]; /* User-space generated. */
char set_name[32]; /* Set and interpreted by user-space. */
grub_uint64_t ctime; /* Lo 40 bits are seconds, top 24 are microseconds or 0. */
grub_uint32_t level; /* -4 (multipath), -1 (linear), 0,1,4,5. */
grub_uint32_t layout; /* only for raid5 and raid10 currently. */
grub_uint64_t size; /* Used size of component devices, in 512byte sectors. */
grub_uint32_t chunksize; /* In 512byte sectors. */
grub_uint32_t raid_disks;
grub_uint32_t bitmap_offset; /* Sectors after start of superblock that bitmap starts
* NOTE: signed, so bitmap can be before superblock
* only meaningful of feature_map[0] is set.
*/
/* These are only valid with feature bit '4'. */
grub_uint32_t new_level; /* New level we are reshaping to. */
grub_uint64_t reshape_position; /* Next address in array-space for reshape. */
grub_uint32_t delta_disks; /* Change in number of raid_disks. */
grub_uint32_t new_layout; /* New layout. */
grub_uint32_t new_chunk; /* New chunk size (512byte sectors). */
grub_uint8_t pad1[128 - 124]; /* Set to 0 when written. */
/* Constant this-device information - 64 bytes. */
grub_uint64_t data_offset; /* Sector start of data, often 0. */
grub_uint64_t data_size; /* Sectors in this device that can be used for data. */
grub_uint64_t super_offset; /* Sector start of this superblock. */
grub_uint64_t recovery_offset; /* Sectors before this offset (from data_offset) have been recovered. */
grub_uint32_t dev_number; /* Permanent identifier of this device - not role in raid. */
grub_uint32_t cnt_corrected_read; /* Number of read errors that were corrected by re-writing. */
grub_uint8_t device_uuid[16]; /* User-space setable, ignored by kernel. */
grub_uint8_t devflags; /* Per-device flags. Only one defined... */
grub_uint8_t pad2[64 - 57]; /* Set to 0 when writing. */
/* Array state information - 64 bytes. */
grub_uint64_t utime; /* 40 bits second, 24 btes microseconds. */
grub_uint64_t events; /* Incremented when superblock updated. */
grub_uint64_t resync_offset; /* Data before this offset (from data_offset) known to be in sync. */
grub_uint32_t sb_csum; /* Checksum upto devs[max_dev]. */
grub_uint32_t max_dev; /* Size of devs[] array to consider. */
grub_uint8_t pad3[64 - 32]; /* Set to 0 when writing. */
/* Device state information. Indexed by dev_number.
* 2 bytes per device.
* Note there are no per-device state flags. State information is rolled
* into the 'roles' value. If a device is spare or faulty, then it doesn't
* have a meaningful role.
*/
grub_uint16_t dev_roles[0]; /* Role in array, or 0xffff for a spare, or 0xfffe for faulty. */
};
/* Could be __attribute__ ((packed)), but since all members in this struct
are already appropriately aligned, we can omit this and avoid suboptimal
assembly in some cases. */
#define WriteMostly1 1 /* Mask for writemostly flag in above devflags. */
static grub_err_t
grub_mdraid_detect_09 (grub_disk_addr_t sector,
struct grub_raid_super_09 *sb,
struct grub_raid_array *array,
grub_disk_addr_t *start_sector)
{ {
grub_disk_addr_t sector;
grub_uint64_t size;
struct grub_raid_super_09 sb;
grub_uint32_t *uuid; grub_uint32_t *uuid;
/* The sector where the RAID superblock is stored, if available. */ if (sb->major_version != 0 || sb->minor_version != 90)
size = grub_disk_get_size (disk);
sector = NEW_SIZE_SECTORS (size);
if (grub_disk_read (disk, sector, 0, SB_BYTES, &sb))
return grub_errno;
/* Look whether there is a RAID superblock. */
if (sb.md_magic != SB_MAGIC)
return grub_error (GRUB_ERR_OUT_OF_RANGE, "not raid");
/* FIXME: Also support version 1.0. */
if (sb.major_version != 0 || sb.minor_version != 90)
return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
"unsupported RAID version: %d.%d", "unsupported RAID version: %d.%d",
sb.major_version, sb.minor_version); sb->major_version, sb->minor_version);
/* FIXME: Check the checksum. */ /* FIXME: Check the checksum. */
/* Multipath. */ /* Multipath. */
if ((int) sb.level == -4) if ((int) sb->level == -4)
sb.level = 1; sb->level = 1;
if (sb.level != 0 && sb.level != 1 && sb.level != 4 && if (sb->level != 0 && sb->level != 1 && sb->level != 4 &&
sb.level != 5 && sb.level != 6 && sb.level != 10) sb->level != 5 && sb->level != 6 && sb->level != 10)
return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
"unsupported RAID level: %d", sb.level); "unsupported RAID level: %d", sb->level);
array->number = sb.md_minor; array->name = NULL;
array->level = sb.level; array->number = sb->md_minor;
array->layout = sb.layout; array->level = sb->level;
array->total_devs = sb.raid_disks; array->layout = sb->layout;
array->disk_size = (sb.size) ? sb.size * 2 : sector; array->total_devs = sb->raid_disks;
array->chunk_size = sb.chunk_size >> 9; array->disk_size = (sb->size) ? sb->size * 2 : sector;
array->index = sb.this_disk.number; array->chunk_size = sb->chunk_size >> 9;
array->index = sb->this_disk.number;
array->uuid_len = 16; array->uuid_len = 16;
array->uuid = grub_malloc (16); array->uuid = grub_malloc (16);
if (!array->uuid) if (!array->uuid)
return grub_errno; return grub_errno;
uuid = (grub_uint32_t *) array->uuid; uuid = (grub_uint32_t *) array->uuid;
uuid[0] = sb.set_uuid0; uuid[0] = sb->set_uuid0;
uuid[1] = sb.set_uuid1; uuid[1] = sb->set_uuid1;
uuid[2] = sb.set_uuid2; uuid[2] = sb->set_uuid2;
uuid[3] = sb.set_uuid3; uuid[3] = sb->set_uuid3;
*start_sector = 0;
return 0; return 0;
} }
static grub_err_t
grub_mdraid_detect_1x (grub_disk_t disk, grub_disk_addr_t sector,
struct grub_raid_super_1x *sb,
struct grub_raid_array *array,
grub_disk_addr_t *start_sector)
{
grub_uint64_t sb_size;
struct grub_raid_super_1x *real_sb;
if (sb->major_version != 1)
return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
"Unsupported RAID version: %d",
sb->major_version);
/* Multipath. */
if ((int) sb->level == -4)
sb->level = 1;
if (sb->level != 0 && sb->level != 1 && sb->level != 4 &&
sb->level != 5 && sb->level != 6 && sb->level != 10)
return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
"Unsupported RAID level: %d", sb->level);
/* 1.x superblocks don't have a fixed size on disk. So we have to
read it again now that we now the max device count. */
sb_size = sizeof (struct grub_raid_super_1x) + 2 * grub_le_to_cpu32 (sb->max_dev);
real_sb = grub_malloc (sb_size);
if (! real_sb)
return grub_errno;
if (grub_disk_read (disk, sector, 0, sb_size, real_sb))
{
grub_free (real_sb);
return grub_errno;
}
array->name = grub_strdup (real_sb->set_name);
if (! array->name)
{
grub_free (real_sb);
return grub_errno;
}
array->number = 0;
array->level = grub_le_to_cpu32 (real_sb->level);
array->layout = grub_le_to_cpu32 (real_sb->layout);
array->total_devs = grub_le_to_cpu32 (real_sb->raid_disks);
array->disk_size = grub_le_to_cpu64 (real_sb->size);
array->chunk_size = grub_le_to_cpu32 (real_sb->chunksize);
if (grub_le_to_cpu32 (real_sb->dev_number) <
grub_le_to_cpu32 (real_sb->max_dev))
array->index = grub_le_to_cpu16
(real_sb->dev_roles[grub_le_to_cpu32 (real_sb->dev_number)]);
else
array->index = 0xffff; /* disk will be later not used! */
array->uuid_len = 16;
array->uuid = grub_malloc (16);
if (!array->uuid)
{
grub_free (real_sb);
return grub_errno;
}
grub_memcpy (array->uuid, real_sb->set_uuid, 16);
*start_sector = real_sb->data_offset;
grub_free (real_sb);
return 0;
}
static grub_err_t
grub_mdraid_detect (grub_disk_t disk, struct grub_raid_array *array,
grub_disk_addr_t *start_sector)
{
grub_disk_addr_t sector;
grub_uint64_t size;
struct grub_raid_super_09 sb_09;
struct grub_raid_super_1x sb_1x;
grub_uint8_t minor_version;
/* The sector where the mdraid 0.90 superblock is stored, if available. */
size = grub_disk_get_size (disk);
sector = NEW_SIZE_SECTORS (size);
if (grub_disk_read (disk, sector, 0, SB_BYTES, &sb_09))
return grub_errno;
/* Look whether there is a mdraid 0.90 superblock. */
if (sb_09.md_magic == SB_MAGIC)
return grub_mdraid_detect_09 (sector, &sb_09, array, start_sector);
/* Check for an 1.x superblock.
* It's always aligned to a 4K boundary
* and depending on the minor version it can be:
* 0: At least 8K, but less than 12K, from end of device
* 1: At start of device
* 2: 4K from start of device.
*/
for (minor_version = 0; minor_version < 3; ++minor_version)
{
switch (minor_version)
{
case 0:
sector = (size - 8 * 2) & ~(4 * 2 - 1);
break;
case 1:
sector = 0;
break;
case 2:
sector = 4 * 2;
break;
}
if (grub_disk_read (disk, sector, 0, sizeof (struct grub_raid_super_1x),
&sb_1x))
return grub_errno;
if (sb_1x.magic == SB_MAGIC)
return grub_mdraid_detect_1x (disk, sector, &sb_1x, array,
start_sector);
}
/* Neither 0.90 nor 1.x. */
return grub_error (GRUB_ERR_OUT_OF_RANGE, "not raid");
}
static struct grub_raid grub_mdraid_dev = { static struct grub_raid grub_mdraid_dev = {
.name = "mdraid", .name = "mdraid",
.detect = grub_mdraid_detect, .detect = grub_mdraid_detect,

View file

@ -1,7 +1,7 @@
/* raid.c - module to read RAID arrays. */ /* raid.c - module to read RAID arrays. */
/* /*
* GRUB -- GRand Unified Bootloader * GRUB -- GRand Unified Bootloader
* Copyright (C) 2006,2007,2008,2009 Free Software Foundation, Inc. * Copyright (C) 2006,2007,2008,2009,2010 Free Software Foundation, Inc.
* *
* GRUB is free software: you can redistribute it and/or modify * GRUB is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -254,6 +254,7 @@ grub_raid_read (grub_disk_t disk, grub_disk_addr_t sector,
grub_errno = GRUB_ERR_NONE; grub_errno = GRUB_ERR_NONE;
err = grub_disk_read (array->device[k], err = grub_disk_read (array->device[k],
array->start_sector[k] +
read_sector + j * far_ofs + b, read_sector + j * far_ofs + b,
0, 0,
read_size << GRUB_DISK_SECTOR_BITS, read_size << GRUB_DISK_SECTOR_BITS,
@ -366,6 +367,7 @@ grub_raid_read (grub_disk_t disk, grub_disk_addr_t sector,
grub_errno = GRUB_ERR_NONE; grub_errno = GRUB_ERR_NONE;
err = grub_disk_read (array->device[disknr], err = grub_disk_read (array->device[disknr],
array->start_sector[disknr] +
read_sector + b, 0, read_sector + b, 0,
read_size << GRUB_DISK_SECTOR_BITS, read_size << GRUB_DISK_SECTOR_BITS,
buf); buf);
@ -475,7 +477,7 @@ grub_raid_write (grub_disk_t disk __attribute ((unused)),
static grub_err_t static grub_err_t
insert_array (grub_disk_t disk, struct grub_raid_array *new_array, insert_array (grub_disk_t disk, struct grub_raid_array *new_array,
const char *scanner_name) grub_disk_addr_t start_sector, const char *scanner_name)
{ {
struct grub_raid_array *array = 0, *p; struct grub_raid_array *array = 0, *p;
@ -502,7 +504,7 @@ insert_array (grub_disk_t disk, struct grub_raid_array *new_array,
if (array->device[new_array->index] != NULL) if (array->device[new_array->index] != NULL)
/* We found multiple devices with the same number. Again, /* We found multiple devices with the same number. Again,
this shouldn't happen.*/ this shouldn't happen. */
grub_dprintf ("raid", "Found two disks with the number %d?!?", grub_dprintf ("raid", "Found two disks with the number %d?!?",
new_array->number); new_array->number);
@ -524,18 +526,24 @@ insert_array (grub_disk_t disk, struct grub_raid_array *new_array,
*array = *new_array; *array = *new_array;
array->nr_devs = 0; array->nr_devs = 0;
grub_memset (&array->device, 0, sizeof (array->device)); grub_memset (&array->device, 0, sizeof (array->device));
grub_memset (&array->start_sector, 0, sizeof (array->start_sector));
/* Check whether we don't have multiple arrays with the same number. */ if (! array->name)
{
for (p = array_list; p != NULL; p = p->next) for (p = array_list; p != NULL; p = p->next)
{ {
if (p->number == array->number) if (! p->name && p->number == array->number)
break; break;
} }
}
if (p) if (array->name || p)
{ {
/* The number is already in use, so we need to find an new number. */ /* The number is already in use, so we need to find a new one.
int i = 0; (Or, in the case of named arrays, the array doesn't have its
own number, but we need one that doesn't clash for use as a key
in the disk cache. */
int i = array->name ? 0x40000000 : 0;
while (1) while (1)
{ {
@ -545,7 +553,7 @@ insert_array (grub_disk_t disk, struct grub_raid_array *new_array,
break; break;
} }
if (!p) if (! p)
{ {
/* We found an unused number. */ /* We found an unused number. */
array->number = i; array->number = i;
@ -556,6 +564,10 @@ insert_array (grub_disk_t disk, struct grub_raid_array *new_array,
} }
} }
/* mdraid 1.x superblocks have only a name stored not a number.
Use it directly as GRUB device. */
if (! array->name)
{
array->name = grub_xasprintf ("md%d", array->number); array->name = grub_xasprintf ("md%d", array->number);
if (! array->name) if (! array->name)
{ {
@ -564,6 +576,25 @@ insert_array (grub_disk_t disk, struct grub_raid_array *new_array,
return grub_errno; return grub_errno;
} }
}
else
{
/* Strip off the homehost if present. */
char *colon = grub_strchr (array->name, ':');
char *new_name = grub_xasprintf ("md/%s",
colon ? colon + 1 : array->name);
if (! new_name)
{
grub_free (array->uuid);
grub_free (array);
return grub_errno;
}
grub_free (array->name);
array->name = new_name;
}
grub_dprintf ("raid", "Found array %s (%s)\n", array->name, grub_dprintf ("raid", "Found array %s (%s)\n", array->name,
scanner_name); scanner_name);
@ -580,6 +611,7 @@ insert_array (grub_disk_t disk, struct grub_raid_array *new_array,
/* Add the device to the array. */ /* Add the device to the array. */
array->device[new_array->index] = disk; array->device[new_array->index] = disk;
array->start_sector[new_array->index] = start_sector;
array->nr_devs++; array->nr_devs++;
return 0; return 0;
@ -621,6 +653,7 @@ grub_raid_register (grub_raid_t raid)
{ {
grub_disk_t disk; grub_disk_t disk;
struct grub_raid_array array; struct grub_raid_array array;
grub_disk_addr_t start_sector;
grub_dprintf ("raid", "Scanning for RAID devices on disk %s\n", name); grub_dprintf ("raid", "Scanning for RAID devices on disk %s\n", name);
@ -629,8 +662,8 @@ grub_raid_register (grub_raid_t raid)
return 0; return 0;
if ((disk->total_sectors != GRUB_ULONG_MAX) && if ((disk->total_sectors != GRUB_ULONG_MAX) &&
(! grub_raid_list->detect (disk, &array)) && (! grub_raid_list->detect (disk, &array, &start_sector)) &&
(! insert_array (disk, &array, grub_raid_list->name))) (! insert_array (disk, &array, start_sector, grub_raid_list->name)))
return 0; return 0;
/* This error usually means it's not raid, no need to display /* This error usually means it's not raid, no need to display

View file

@ -402,7 +402,7 @@ grub_scsi_open (const char *name, grub_disk_t disk)
if (p->open (bus, scsi)) if (p->open (bus, scsi))
continue; continue;
disk->id = grub_make_scsi_id (scsi->dev->id, bus, lun); disk->id = grub_make_scsi_id (p->id, bus, lun);
disk->data = scsi; disk->data = scsi;
scsi->dev = p; scsi->dev = p;
scsi->lun = lun; scsi->lun = lun;

View file

@ -52,20 +52,19 @@ struct grub_usbms_dev
int luns; int luns;
int config;
int interface; int interface;
struct grub_usb_desc_endp *in; struct grub_usb_desc_endp *in;
struct grub_usb_desc_endp *out; struct grub_usb_desc_endp *out;
int in_maxsz; int in_maxsz;
int out_maxsz; int out_maxsz;
struct grub_usbms_dev *next;
}; };
typedef struct grub_usbms_dev *grub_usbms_dev_t; typedef struct grub_usbms_dev *grub_usbms_dev_t;
static grub_usbms_dev_t grub_usbms_dev_list; /* FIXME: remove limit. */
#define MAX_USBMS_DEVICES 128
static int devcnt; static grub_usbms_dev_t grub_usbms_devices[MAX_USBMS_DEVICES];
static grub_err_t static grub_err_t
grub_usbms_reset (grub_usb_device_t dev, int interface) grub_usbms_reset (grub_usb_device_t dev, int interface)
@ -74,58 +73,53 @@ grub_usbms_reset (grub_usb_device_t dev, int interface)
} }
static void static void
grub_usbms_finddevs (void) grub_usbms_detach (grub_usb_device_t usbdev, int config, int interface)
{ {
auto int usb_iterate (grub_usb_device_t dev); unsigned i;
for (i = 0; i < ARRAY_SIZE (grub_usbms_devices); i++)
int usb_iterate (grub_usb_device_t usbdev) if (grub_usbms_devices[i] && grub_usbms_devices[i]->dev == usbdev
&& grub_usbms_devices[i]->interface == interface
&& grub_usbms_devices[i]->config == config)
{ {
grub_usb_err_t err; grub_free (grub_usbms_devices[i]);
struct grub_usb_desc_device *descdev = &usbdev->descdev; grub_usbms_devices[i] = 0;
int i; }
}
if (descdev->class != 0 || descdev->subclass || descdev->protocol != 0 static int
|| descdev->configcnt == 0) grub_usbms_attach (grub_usb_device_t usbdev, int configno, int interfno)
return 0; {
struct grub_usb_desc_if *interf
/* XXX: Just check configuration 0 for now. */ = usbdev->config[configno].interf[interfno].descif;
for (i = 0; i < usbdev->config[0].descconf->numif; i++)
{
struct grub_usbms_dev *usbms;
struct grub_usb_desc_if *interf;
int j; int j;
grub_uint8_t luns = 0; grub_uint8_t luns = 0;
unsigned curnum;
grub_usb_err_t err;
grub_dprintf ("usbms", "alive\n"); for (curnum = 0; curnum < ARRAY_SIZE (grub_usbms_devices); curnum++)
if (!grub_usbms_devices[curnum])
break;
interf = usbdev->config[0].interf[i].descif; if (curnum == ARRAY_SIZE (grub_usbms_devices))
return 0;
/* If this is not a USB Mass Storage device with a supported interf = usbdev->config[configno].interf[interfno].descif;
protocol, just skip it. */
grub_dprintf ("usbms", "iterate: interf=%d, class=%d, subclass=%d, protocol=%d\n",
i, interf->class, interf->subclass, interf->protocol);
if (interf->class != GRUB_USB_CLASS_MASS_STORAGE if ((interf->subclass != GRUB_USBMS_SUBCLASS_BULK
|| ( interf->subclass != GRUB_USBMS_SUBCLASS_BULK &&
/* Experimental support of RBC, MMC-2, UFI, SFF-8070i devices */ /* Experimental support of RBC, MMC-2, UFI, SFF-8070i devices */
interf->subclass != GRUB_USBMS_SUBCLASS_RBC && && interf->subclass != GRUB_USBMS_SUBCLASS_RBC
interf->subclass != GRUB_USBMS_SUBCLASS_MMC2 && && interf->subclass != GRUB_USBMS_SUBCLASS_MMC2
interf->subclass != GRUB_USBMS_SUBCLASS_UFI && && interf->subclass != GRUB_USBMS_SUBCLASS_UFI
interf->subclass != GRUB_USBMS_SUBCLASS_SFF8070 ) && interf->subclass != GRUB_USBMS_SUBCLASS_SFF8070 )
|| interf->protocol != GRUB_USBMS_PROTOCOL_BULK) || interf->protocol != GRUB_USBMS_PROTOCOL_BULK)
{ return 0;
continue;
}
grub_dprintf ("usbms", "alive\n"); grub_usbms_devices[curnum] = grub_zalloc (sizeof (struct grub_usbms_dev));
if (! grub_usbms_devices[curnum])
return 0;
devcnt++; grub_usbms_devices[curnum]->dev = usbdev;
usbms = grub_zalloc (sizeof (struct grub_usbms_dev)); grub_usbms_devices[curnum]->interface = interfno;
if (! usbms)
return 1;
usbms->dev = usbdev;
usbms->interface = i;
grub_dprintf ("usbms", "alive\n"); grub_dprintf ("usbms", "alive\n");
@ -134,29 +128,30 @@ grub_usbms_finddevs (void)
for (j = 0; j < interf->endpointcnt; j++) for (j = 0; j < interf->endpointcnt; j++)
{ {
struct grub_usb_desc_endp *endp; struct grub_usb_desc_endp *endp;
endp = &usbdev->config[0].interf[i].descendp[j]; endp = &usbdev->config[0].interf[interfno].descendp[j];
if ((endp->endp_addr & 128) && (endp->attrib & 3) == 2) if ((endp->endp_addr & 128) && (endp->attrib & 3) == 2)
{ {
/* Bulk IN endpoint. */ /* Bulk IN endpoint. */
usbms->in = endp; grub_usbms_devices[curnum]->in = endp;
/* Clear Halt is not possible yet! */ /* Clear Halt is not possible yet! */
/* grub_usb_clear_halt (usbdev, endp->endp_addr); */ /* grub_usb_clear_halt (usbdev, endp->endp_addr); */
usbms->in_maxsz = endp->maxpacket; grub_usbms_devices[curnum]->in_maxsz = endp->maxpacket;
} }
else if (!(endp->endp_addr & 128) && (endp->attrib & 3) == 2) else if (!(endp->endp_addr & 128) && (endp->attrib & 3) == 2)
{ {
/* Bulk OUT endpoint. */ /* Bulk OUT endpoint. */
usbms->out = endp; grub_usbms_devices[curnum]->out = endp;
/* Clear Halt is not possible yet! */ /* Clear Halt is not possible yet! */
/* grub_usb_clear_halt (usbdev, endp->endp_addr); */ /* grub_usb_clear_halt (usbdev, endp->endp_addr); */
usbms->out_maxsz = endp->maxpacket; grub_usbms_devices[curnum]->out_maxsz = endp->maxpacket;
} }
} }
if (!usbms->in || !usbms->out) if (!grub_usbms_devices[curnum]->in || !grub_usbms_devices[curnum]->out)
{ {
grub_free (usbms); grub_free (grub_usbms_devices[curnum]);
grub_usbms_devices[curnum] = 0;
return 0; return 0;
} }
@ -166,32 +161,30 @@ grub_usbms_finddevs (void)
grub_usb_set_configuration (usbdev, 1); grub_usb_set_configuration (usbdev, 1);
/* Query the amount of LUNs. */ /* Query the amount of LUNs. */
err = grub_usb_control_msg (usbdev, 0xA1, 254, err = grub_usb_control_msg (usbdev, 0xA1, 254, 0, interfno, 1, (char *) &luns);
0, i, 1, (char *) &luns);
if (err) if (err)
{ {
/* In case of a stall, clear the stall. */ /* In case of a stall, clear the stall. */
if (err == GRUB_USB_ERR_STALL) if (err == GRUB_USB_ERR_STALL)
{ {
grub_usb_clear_halt (usbdev, usbms->in->endp_addr); grub_usb_clear_halt (usbdev, grub_usbms_devices[curnum]->in->endp_addr);
grub_usb_clear_halt (usbdev, usbms->out->endp_addr); grub_usb_clear_halt (usbdev, grub_usbms_devices[curnum]->out->endp_addr);
} }
/* Just set the amount of LUNs to one. */ /* Just set the amount of LUNs to one. */
grub_errno = GRUB_ERR_NONE; grub_errno = GRUB_ERR_NONE;
usbms->luns = 1; grub_usbms_devices[curnum]->luns = 1;
} }
else else
/* luns = 0 means one LUN with ID 0 present ! */ /* luns = 0 means one LUN with ID 0 present ! */
/* We get from device not number of LUNs but highest /* We get from device not number of LUNs but highest
* LUN number. LUNs are numbered from 0, * LUN number. LUNs are numbered from 0,
* i.e. number of LUNs is luns+1 ! */ * i.e. number of LUNs is luns+1 ! */
usbms->luns = luns + 1; grub_usbms_devices[curnum]->luns = luns + 1;
grub_dprintf ("usbms", "alive\n"); grub_dprintf ("usbms", "alive\n");
usbms->next = grub_usbms_dev_list; usbdev->config[configno].interf[interfno].detach_hook = grub_usbms_detach;
grub_usbms_dev_list = usbms;
#if 0 /* All this part should be probably deleted. #if 0 /* All this part should be probably deleted.
* This make trouble on some devices if they are not in * This make trouble on some devices if they are not in
@ -206,17 +199,7 @@ grub_usbms_finddevs (void)
grub_usb_clear_halt (usbdev, usbms->out->endp_addr); grub_usb_clear_halt (usbdev, usbms->out->endp_addr);
#endif #endif
return 0; return 1;
}
grub_dprintf ("usbms", "alive\n");
return 0;
}
grub_dprintf ("usbms", "alive\n");
grub_usb_iterate (usb_iterate);
grub_dprintf ("usbms", "alive\n");
} }
@ -224,14 +207,15 @@ grub_usbms_finddevs (void)
static int static int
grub_usbms_iterate (int (*hook) (int bus, int luns)) grub_usbms_iterate (int (*hook) (int bus, int luns))
{ {
grub_usbms_dev_t p; unsigned i;
int cnt = 0;
for (p = grub_usbms_dev_list; p; p = p->next) grub_usb_poll_devices ();
for (i = 0; i < ARRAY_SIZE (grub_usbms_devices); i++)
if (grub_usbms_devices[i])
{ {
if (hook (cnt, p->luns)) if (hook (i, grub_usbms_devices[i]->luns))
return 1; return 1;
cnt++;
} }
return 0; return 0;
@ -248,7 +232,6 @@ grub_usbms_transfer (struct grub_scsi *scsi, grub_size_t cmdsize, char *cmd,
grub_usb_err_t err = GRUB_USB_ERR_NONE; grub_usb_err_t err = GRUB_USB_ERR_NONE;
grub_usb_err_t errCSW = GRUB_USB_ERR_NONE; grub_usb_err_t errCSW = GRUB_USB_ERR_NONE;
int retrycnt = 3 + 1; int retrycnt = 3 + 1;
grub_size_t i;
retry: retry:
retrycnt--; retrycnt--;
@ -304,8 +287,11 @@ grub_usbms_transfer (struct grub_scsi *scsi, grub_size_t cmdsize, char *cmd,
/* Debug print of received data. */ /* Debug print of received data. */
grub_dprintf ("usb", "buf:\n"); grub_dprintf ("usb", "buf:\n");
if (size <= 64) if (size <= 64)
for (i=0; i<size; i++) {
grub_dprintf ("usb", "0x%02" PRIxGRUB_SIZE ": 0x%02x\n", i, buf[i]); unsigned i;
for (i = 0; i < size; i++)
grub_dprintf ("usb", "0x%02x: 0x%02x\n", i, buf[i]);
}
else else
grub_dprintf ("usb", "Too much data for debug print...\n"); grub_dprintf ("usb", "Too much data for debug print...\n");
} }
@ -313,7 +299,11 @@ grub_usbms_transfer (struct grub_scsi *scsi, grub_size_t cmdsize, char *cmd,
{ {
err = grub_usb_bulk_write (dev->dev, dev->out->endp_addr, size, buf); err = grub_usb_bulk_write (dev->dev, dev->out->endp_addr, size, buf);
grub_dprintf ("usb", "write: %d %d\n", err, GRUB_USB_ERR_STALL); grub_dprintf ("usb", "write: %d %d\n", err, GRUB_USB_ERR_STALL);
grub_dprintf ("usb", "buf:\n"); grub_dprintf ("usb", "First 16 bytes of sent data:\n %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n",
buf[ 0], buf[ 1], buf[ 2], buf[ 3],
buf[ 4], buf[ 5], buf[ 6], buf[ 7],
buf[ 8], buf[ 9], buf[10], buf[11],
buf[12], buf[13], buf[14], buf[15]);
if (err) if (err)
{ {
if (err == GRUB_USB_ERR_STALL) if (err == GRUB_USB_ERR_STALL)
@ -322,8 +312,11 @@ grub_usbms_transfer (struct grub_scsi *scsi, grub_size_t cmdsize, char *cmd,
} }
/* Debug print of sent data. */ /* Debug print of sent data. */
if (size <= 256) if (size <= 256)
{
unsigned i;
for (i=0; i<size; i++) for (i=0; i<size; i++)
grub_dprintf ("usb", "0x%02" PRIxGRUB_SIZE ": 0x%02x\n", i, buf[i]); grub_dprintf ("usb", "0x%02x: 0x%02x\n", i, buf[i]);
}
else else
grub_dprintf ("usb", "Too much data for debug print...\n"); grub_dprintf ("usb", "Too much data for debug print...\n");
} }
@ -393,24 +386,16 @@ grub_usbms_write (struct grub_scsi *scsi, grub_size_t cmdsize, char *cmd,
static grub_err_t static grub_err_t
grub_usbms_open (int devnum, struct grub_scsi *scsi) grub_usbms_open (int devnum, struct grub_scsi *scsi)
{ {
grub_usbms_dev_t p; grub_usb_poll_devices ();
int i = 0;
for (p = grub_usbms_dev_list; p; p = p->next)
{
/* Check if this is the devnumth device. */
if (devnum == i)
{
scsi->data = p;
scsi->luns = p->luns;
return GRUB_ERR_NONE;
}
i++;
}
if (!grub_usbms_devices[devnum])
return grub_error (GRUB_ERR_UNKNOWN_DEVICE, return grub_error (GRUB_ERR_UNKNOWN_DEVICE,
"not a USB Mass Storage device"); "unknown USB Mass Storage device");
scsi->data = grub_usbms_devices[devnum];
scsi->luns = grub_usbms_devices[devnum]->luns;
return GRUB_ERR_NONE;
} }
static struct grub_scsi_dev grub_usbms_dev = static struct grub_scsi_dev grub_usbms_dev =
@ -423,13 +408,28 @@ static struct grub_scsi_dev grub_usbms_dev =
.write = grub_usbms_write .write = grub_usbms_write
}; };
struct grub_usb_attach_desc attach_hook =
{
.class = GRUB_USB_CLASS_MASS_STORAGE,
.hook = grub_usbms_attach
};
GRUB_MOD_INIT(usbms) GRUB_MOD_INIT(usbms)
{ {
grub_usbms_finddevs (); grub_usb_register_attach_hook_class (&attach_hook);
grub_scsi_dev_register (&grub_usbms_dev); grub_scsi_dev_register (&grub_usbms_dev);
} }
GRUB_MOD_FINI(usbms) GRUB_MOD_FINI(usbms)
{ {
unsigned i;
for (i = 0; i < ARRAY_SIZE (grub_usbms_devices); i++)
{
grub_usbms_devices[i]->dev->config[grub_usbms_devices[i]->config]
.interf[grub_usbms_devices[i]->interface].detach_hook = 0;
grub_usbms_devices[i]->dev->config[grub_usbms_devices[i]->config]
.interf[grub_usbms_devices[i]->interface].attached = 0;
}
grub_usb_unregister_attach_hook_class (&attach_hook);
grub_scsi_dev_unregister (&grub_usbms_dev); grub_scsi_dev_unregister (&grub_usbms_dev);
} }

View file

@ -444,12 +444,13 @@ disk. The number @samp{0} is the drive number, which is counted from
disk. disk.
@example @example
(hd0,2) (hd0,msdos2)
@end example @end example
Here, @samp{hd} means it is a hard disk drive. The first integer Here, @samp{hd} means it is a hard disk drive. The first integer
@samp{0} indicates the drive number, that is, the first hard disk, while @samp{0} indicates the drive number, that is, the first hard disk,
the second integer, @samp{1}, indicates the partition number (or the the string @samp{msdos} indicates the partition scheme, while
the second integer, @samp{2}, indicates the partition number (or the
@sc{pc} slice number in the BSD terminology). The partition numbers are @sc{pc} slice number in the BSD terminology). The partition numbers are
counted from @emph{one}, not from zero (as was the case in previous counted from @emph{one}, not from zero (as was the case in previous
versions of GRUB). This expression means the second partition of the versions of GRUB). This expression means the second partition of the
@ -457,7 +458,7 @@ first hard disk drive. In this case, GRUB uses one partition of the
disk, instead of the whole disk. disk, instead of the whole disk.
@example @example
(hd0,5) (hd0,msdos5)
@end example @end example
This specifies the first @dfn{extended partition} of the first hard disk This specifies the first @dfn{extended partition} of the first hard disk
@ -466,18 +467,15 @@ counted from @samp{5}, regardless of the actual number of primary
partitions on your hard disk. partitions on your hard disk.
@example @example
(hd1,a) (hd1,msdos1,bsd1)
@end example @end example
This means the BSD @samp{a} partition of the second hard disk. If you This means the BSD @samp{a} partition on first @sc{pc} slice number
need to specify which @sc{pc} slice number should be used, use something of the second hard disk.
like this: @samp{(hd1,1,a)}. If the @sc{pc} slice number is omitted,
GRUB searches for the first @sc{pc} slice which has a BSD @samp{a}
partition.
Of course, to actually access the disks or partitions with GRUB, you Of course, to actually access the disks or partitions with GRUB, you
need to use the device specification in a command, like @samp{set need to use the device specification in a command, like @samp{set
root=(fd0)} or @samp{parttool (hd0,3) hidden-}. To help you find out root=(fd0)} or @samp{parttool (hd0,msdos3) hidden-}. To help you find out
which number specifies a partition you want, the GRUB command-line which number specifies a partition you want, the GRUB command-line
(@pxref{Command-line interface}) options have argument (@pxref{Command-line interface}) options have argument
completion. This means that, for example, you only need to type completion. This means that, for example, you only need to type
@ -501,7 +499,7 @@ Now the question is, how to specify a file? Again, consider an
example: example:
@example @example
(hd0,1)/vmlinuz (hd0,msdos1)/vmlinuz
@end example @end example
This specifies the file named @samp{vmlinuz}, found on the first This specifies the file named @samp{vmlinuz}, found on the first
@ -1064,6 +1062,11 @@ only to the default menu entry, after those listed in
As @samp{GRUB_CMDLINE_LINUX} and @samp{GRUB_CMDLINE_LINUX_DEFAULT}, but for As @samp{GRUB_CMDLINE_LINUX} and @samp{GRUB_CMDLINE_LINUX_DEFAULT}, but for
NetBSD. NetBSD.
@item GRUB_CMDLINE_XEN
@itemx GRUB_CMDLINE_XEN_DEFAULT
As @samp{GRUB_CMDLINE_LINUX} and @samp{GRUB_CMDLINE_LINUX_DEFAULT}, but for
Linux and Xen.
@item GRUB_DISABLE_LINUX_UUID @item GRUB_DISABLE_LINUX_UUID
Normally, @command{grub-mkconfig} will generate menu entries that use Normally, @command{grub-mkconfig} will generate menu entries that use
universally-unique identifiers (UUIDs) to identify the root filesystem to universally-unique identifiers (UUIDs) to identify the root filesystem to
@ -1115,8 +1118,8 @@ try several modes in sequence.
Depending on your kernel, your distribution, your graphics card, and the Depending on your kernel, your distribution, your graphics card, and the
phase of the moon, note that using this option may cause GNU/Linux to suffer phase of the moon, note that using this option may cause GNU/Linux to suffer
from various display problems, particularly during the early part of the from various display problems, particularly during the early part of the
boot sequence. If you have problems, simply unset this option and GRUB will boot sequence. If you have problems, set this option to @samp{text} and
tell Linux to boot in normal text mode. GRUB will tell Linux to boot in normal text mode.
@item GRUB_DISABLE_OS_PROBER @item GRUB_DISABLE_OS_PROBER
Normally, @command{grub-mkconfig} will try to use the external Normally, @command{grub-mkconfig} will try to use the external
@ -1145,6 +1148,142 @@ that file, making sure to leave at least the first two lines intact.
@node Shell-like scripting @node Shell-like scripting
@section Writing full configuration files directly @section Writing full configuration files directly
@c Some of this section is derived from the GNU Bash manual page, also
@c copyrighted by the FSF.
@file{grub.cfg} is written in GRUB's built-in scripting language, which has
a syntax quite similar to that of GNU Bash and other Bourne shell
derivatives.
@heading Words
A @dfn{word} is a sequence of characters considered as a single unit by
GRUB. Words are separated by @dfn{metacharacters}, which are the following
plus space, tab, and newline:
@example
@{ @} | & $ ; < >
@end example
Quoting may be used to include metacharacters in words; see below.
@heading Reserved words
Reserved words have a special meaning to GRUB. The following words are
recognised as reserved when unquoted and either the first word of a simple
command or the third word of a @code{for} command:
@example
! [[ ]] @{ @}
case do done elif else esac fi for function
if in menuentry select then time until while
@end example
Not all of these reserved words have a useful purpose yet; some are reserved
for future expansion.
@heading Quoting
Quoting is used to remove the special meaning of certain characters or
words. It can be used to treat metacharacters as part of a word, to prevent
reserved words from being recognised as such, and to prevent variable
expansion.
There are three quoting mechanisms: the escape character, single quotes, and
double quotes.
A non-quoted backslash (\) is the @dfn{escape character}. It preserves the
literal value of the next character that follows, with the exception of
newline.
Enclosing characters in single quotes preserves the literal value of each
character within the quotes. A single quote may not occur between single
quotes, even when preceded by a backslash.
Enclosing characters in double quotes preserves the literal value of all
characters within the quotes, with the exception of @samp{$} and @samp{\}.
The @samp{$} character retains its special meaning within double quotes.
The backslash retains its special meaning only when followed by one of the
following characters: @samp{$}, @samp{"}, @samp{\}, or newline. A
backslash-newline pair is treated as a line continuation (that is, it is
removed from the input stream and effectively ignored). A double quote may
be quoted within double quotes by preceding it with a backslash.
@heading Variable expansion
The @samp{$} character introduces variable expansion. The variable name to
be expanded may be enclosed in braces, which are optional but serve to
protect the variable to be expanded from characters immediately following it
which could be interpreted as part of the name.
Normal variable names begin with an alphabetic character, followed by zero
or more alphanumeric characters.
Positional variable names consist of one or more digits. These are reserved
for future expansion.
The special variable name @samp{?} expands to the exit status of the most
recently executed command.
@heading Comments
A word beginning with @samp{#} causes that word and all remaining characters
on that line to be ignored.
@heading Simple commands
A @dfn{simple command} is a sequence of words separated by spaces or tabs
and terminated by a semicolon or a newline. The first word specifies the
command to be executed. The remaining words are passed as arguments to the
invoked command.
The return value of a simple command is its exit status.
@heading Compound commands
A @dfn{compound command} is one of the following:
@table @asis
@item for @var{name} in @var{word} @dots{}; do @var{list}; done
The list of words following @code{in} is expanded, generating a list of
items. The variable @var{name} is set to each element of this list in turn,
and @var{list} is executed each time. The return value is the exit status
of the last command that executes. If the expansion of the items following
@code{in} results in an empty list, no commands are executed, and the return
status is 0.
@item if @var{list}; then @var{list}; [elif @var{list}; then @var{list};] @dots{} [else @var{list};] fi
The @code{if} @var{list} is executed. If its exit status is zero, the
@code{then} @var{list} is executed. Otherwise, each @code{elif} @var{list}
is executed in turn, and if its exit status is zero, the corresponding
@code{then} @var{list} is executed and the command completes. Otherwise,
the @code{else} @var{list} is executed, if present. The exit status is the
exit status of the last command executed, or zero if no condition tested
true.
@item while @var{cond}; do @var{list}; done
@itemx until @var{cond}; do @var{list}; done
The @code{while} command continuously executes the @code{do} @var{list} as
long as the last command in @var{cond} returns an exit status of zero. The
@code{until} command is identical to the @code{while} command, except that
the test is negated; the @code{do} @var{list} is executed as long as the
last command in @var{cond} returns a non-zero exit status. The exit status
of the @code{while} and @code{until} commands is the exit status of the last
@code{do} @var{list} command executed, or zero if none was executed.
@item function @var{name} @{ @var{command}; @dots{} @}
This defines a function named @var{name}. The @dfn{body} of the function is
the list of commands within braces, each of which must be terminated with a
semicolon or a newline. This list of commands will be executed whenever
@var{name} is specified as the name of a simple command. Function
definitions do not affect the exit status in @code{$?}. When executed, the
exit status of a function is the exit status of the last command executed in
the body.
@item menuentry @var{title} [@option{--class=class} @dots{}] [@option{--users=users}] [@option{--hotkey=key}] @{ @var{command}; @dots{} @}
@xref{menuentry}.
@end table
@node Embedded configuration @node Embedded configuration
@section Embedding a configuration file into GRUB @section Embedding a configuration file into GRUB
@ -1310,8 +1449,7 @@ simple. Here is an example:
@example @example
@group @group
grub> @kbd{serial --unit=0 --speed=9600} grub> @kbd{serial --unit=0 --speed=9600}
grub> @kbd{terminal_input serial} grub> @kbd{terminal_input serial; terminal_output serial}
grub> @kbd{terminal_output serial}
@end group @end group
@end example @end example
@ -1322,11 +1460,14 @@ command accepts many other options, so please refer to @ref{serial},
for more details. for more details.
The commands @command{terminal_input} (@pxref{terminal_input}) and The commands @command{terminal_input} (@pxref{terminal_input}) and
@command{terminal_output} (@pxref{terminal_output} choose which type of @command{terminal_output} (@pxref{terminal_output}) choose which type of
terminal you want to use. In the case above, the terminal will be a terminal you want to use. In the case above, the terminal will be a
serial terminal, but you can also pass @code{console} to the command, serial terminal, but you can also pass @code{console} to the command,
as @samp{terminal serial console}. In this case, a terminal in which as @samp{terminal serial console}. In this case, a terminal in which
you press any key will be selected as a GRUB terminal. you press any key will be selected as a GRUB terminal. In the example above,
note that you need to put both commands on the same command line, as you
will lose the ability to type commands on the console after the first
command.
However, note that GRUB assumes that your terminal emulator is However, note that GRUB assumes that your terminal emulator is
compatible with VT100 by default. This is true for most terminal compatible with VT100 by default. This is true for most terminal
@ -1791,9 +1932,26 @@ These commands can only be used in the menu:
@node menuentry @node menuentry
@subsection menuentry @subsection menuentry
@deffn Command title name @dots{} @deffn Command menuentry @var{title} @
Start a new boot entry, and set its name to the contents of the rest of [@option{--class=class} @dots{}] [@option{--users=users}] @
the line, starting with the first non-space character. [@option{--hotkey=key}] @
@{ @var{command}; @dots{} @}
This defines a GRUB menu entry named @var{title}. When this entry is
selected from the menu, GRUB will set the @var{chosen} environment variable
to @var{title}, execute the list of commands given within braces, and if the
last command in the list returned successfully and a kernel was loaded it
will execute the @command{boot} command.
The @option{--class} option may be used any number of times to group menu
entries into classes. Menu themes may display different classes using
different styles.
The @option{--users} option grants specific users access to specific menu
entries. @xref{Security}.
The @option{--hotkey} option associates a hotkey with a menu entry.
@var{key} may be a single letter, or one of the aliases @samp{backspace},
@samp{tab}, or @samp{delete}.
@end deffn @end deffn
@ -1887,7 +2045,9 @@ The @option{-a} (@option{--ascii}), @option{-u} (@option{--utf8}), and
@option{-v} (@option{--visual-utf8}) options control how non-ASCII text is @option{-v} (@option{--visual-utf8}) options control how non-ASCII text is
displayed. @option{-a} specifies an ASCII-only terminal; @option{-u} displayed. @option{-a} specifies an ASCII-only terminal; @option{-u}
specifies logically-ordered UTF-8; and @option{-v} specifies specifies logically-ordered UTF-8; and @option{-v} specifies
visually-ordered UTF-8. "visually-ordered UTF-8" (in other words, arranged such that a terminal
emulator without bidirectional text support will display right-to-left text
in the proper order; this is not really proper UTF-8, but a workaround).
If no option or terminal type is specified, the current terminal type is If no option or terminal type is specified, the current terminal type is
printed. printed.

View file

@ -52,9 +52,9 @@
/* nilfs 1st super block posission from beginning of the partition /* nilfs 1st super block posission from beginning of the partition
in 512 block size */ in 512 block size */
#define NILFS_1ST_SUPER_BLOCK 2 #define NILFS_1ST_SUPER_BLOCK 2
/* nilfs 2nd super block posission from end of the partition /* nilfs 2nd super block posission from beginning of the partition
in 512 block size */ in 512 block size */
#define NILFS_2ND_SUPER_BLOCK 8 #define NILFS_2ND_SUPER_BLOCK(devsize) (((devsize >> 3) - 1) << 3)
struct grub_nilfs2_inode struct grub_nilfs2_inode
{ {
@ -729,7 +729,7 @@ grub_nilfs2_load_sb (struct grub_nilfs2_data *data)
if (partition_size != GRUB_DISK_SIZE_UNKNOWN) if (partition_size != GRUB_DISK_SIZE_UNKNOWN)
{ {
/* Read second super block. */ /* Read second super block. */
grub_disk_read (disk, partition_size - NILFS_2ND_SUPER_BLOCK, 0, grub_disk_read (disk, NILFS_2ND_SUPER_BLOCK (partition_size), 0,
sizeof (struct grub_nilfs2_super_block), &sb2); sizeof (struct grub_nilfs2_super_block), &sb2);
/* Make sure if 2nd super block is valid. */ /* Make sure if 2nd super block is valid. */
valid[1] = grub_nilfs2_valid_sb (&sb2); valid[1] = grub_nilfs2_valid_sb (&sb2);

View file

@ -63,6 +63,8 @@
#define GRUB_PC_PARTITION_OPENBSD_TYPE_NTFS 18 #define GRUB_PC_PARTITION_OPENBSD_TYPE_NTFS 18
#define GRUB_PC_PARTITION_OPENBSD_TYPE_RAID 19 #define GRUB_PC_PARTITION_OPENBSD_TYPE_RAID 19
#define GRUB_PC_PARTITION_BSD_LABEL_WHOLE_DISK_PARTITION 2
/* The BSD partition entry. */ /* The BSD partition entry. */
struct grub_partition_bsd_entry struct grub_partition_bsd_entry
{ {

View file

@ -1,8 +1,27 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2010 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/>.
*/
#ifndef GRUB_EMU_MISC_H #ifndef GRUB_EMU_MISC_H
#define GRUB_EMU_MISC_H 1 #define GRUB_EMU_MISC_H 1
#include <grub/symbol.h> #include <grub/symbol.h>
#include <grub/types.h> #include <grub/types.h>
#include <grub/util/libzfs.h>
#ifdef __CYGWIN__ #ifdef __CYGWIN__
# include <sys/fcntl.h> # include <sys/fcntl.h>
@ -26,12 +45,16 @@ extern const char *program_name;
void grub_init_all (void); void grub_init_all (void);
void grub_fini_all (void); void grub_fini_all (void);
char *grub_make_system_path_relative_to_its_root (const char *path); void grub_find_zpool_from_dir (const char *dir,
char **poolname, char **poolfs);
void * EXPORT_FUNC(xmalloc) (grub_size_t size); char *grub_make_system_path_relative_to_its_root (const char *path)
void * EXPORT_FUNC(xrealloc) (void *ptr, grub_size_t size); __attribute__ ((warn_unused_result));
char * EXPORT_FUNC(xstrdup) (const char *str);
char * EXPORT_FUNC(xasprintf) (const char *fmt, ...); void * EXPORT_FUNC(xmalloc) (grub_size_t size) __attribute__ ((warn_unused_result));
void * EXPORT_FUNC(xrealloc) (void *ptr, grub_size_t size) __attribute__ ((warn_unused_result));
char * EXPORT_FUNC(xstrdup) (const char *str) __attribute__ ((warn_unused_result));
char * EXPORT_FUNC(xasprintf) (const char *fmt, ...) __attribute__ ((warn_unused_result));
void EXPORT_FUNC(grub_util_warn) (const char *fmt, ...); void EXPORT_FUNC(grub_util_warn) (const char *fmt, ...);
void EXPORT_FUNC(grub_util_info) (const char *fmt, ...); void EXPORT_FUNC(grub_util_info) (const char *fmt, ...);
@ -45,11 +68,12 @@ int EXPORT_FUNC(vasprintf) (char **buf, const char *fmt, va_list ap);
int EXPORT_FUNC(asprintf) (char **buf, const char *fmt, ...); int EXPORT_FUNC(asprintf) (char **buf, const char *fmt, ...);
#endif #endif
char * EXPORT_FUNC(xasprintf) (const char *fmt, ...);
extern char * canonicalize_file_name (const char *path); extern char * canonicalize_file_name (const char *path);
#ifdef HAVE_DEVICE_MAPPER #ifdef HAVE_DEVICE_MAPPER
int grub_device_mapper_supported (void); int grub_device_mapper_supported (void);
#endif #endif
libzfs_handle_t *grub_get_libzfs_handle (void);
#endif /* GRUB_EMU_MISC_H */ #endif /* GRUB_EMU_MISC_H */

View file

@ -231,10 +231,10 @@ grub_strtol (const char *str, char **end, int base)
} }
} }
char *EXPORT_FUNC(grub_strdup) (const char *s); char *EXPORT_FUNC(grub_strdup) (const char *s) __attribute__ ((warn_unused_result));
char *EXPORT_FUNC(grub_strndup) (const char *s, grub_size_t n); char *EXPORT_FUNC(grub_strndup) (const char *s, grub_size_t n) __attribute__ ((warn_unused_result));
void *EXPORT_FUNC(grub_memset) (void *s, int c, grub_size_t n); void *EXPORT_FUNC(grub_memset) (void *s, int c, grub_size_t n);
grub_size_t EXPORT_FUNC(grub_strlen) (const char *s); grub_size_t EXPORT_FUNC(grub_strlen) (const char *s) __attribute__ ((warn_unused_result));
int EXPORT_FUNC(grub_printf) (const char *fmt, ...) __attribute__ ((format (printf, 1, 2))); int EXPORT_FUNC(grub_printf) (const char *fmt, ...) __attribute__ ((format (printf, 1, 2)));
int EXPORT_FUNC(grub_printf_) (const char *fmt, ...) __attribute__ ((format (printf, 1, 2))); int EXPORT_FUNC(grub_printf_) (const char *fmt, ...) __attribute__ ((format (printf, 1, 2)));
@ -261,8 +261,8 @@ int EXPORT_FUNC(grub_snprintf) (char *str, grub_size_t n, const char *fmt, ...)
int EXPORT_FUNC(grub_vsnprintf) (char *str, grub_size_t n, const char *fmt, int EXPORT_FUNC(grub_vsnprintf) (char *str, grub_size_t n, const char *fmt,
va_list args); va_list args);
char *EXPORT_FUNC(grub_xasprintf) (const char *fmt, ...) char *EXPORT_FUNC(grub_xasprintf) (const char *fmt, ...)
__attribute__ ((format (printf, 1, 2))); __attribute__ ((format (printf, 1, 2))) __attribute__ ((warn_unused_result));
char *EXPORT_FUNC(grub_xvasprintf) (const char *fmt, va_list args); char *EXPORT_FUNC(grub_xvasprintf) (const char *fmt, va_list args) __attribute__ ((warn_unused_result));
void EXPORT_FUNC(grub_exit) (void) __attribute__ ((noreturn)); void EXPORT_FUNC(grub_exit) (void) __attribute__ ((noreturn));
void EXPORT_FUNC(grub_abort) (void) __attribute__ ((noreturn)); void EXPORT_FUNC(grub_abort) (void) __attribute__ ((noreturn));
grub_uint64_t EXPORT_FUNC(grub_divmod64) (grub_uint64_t n, grub_uint64_t EXPORT_FUNC(grub_divmod64) (grub_uint64_t n,

View file

@ -48,7 +48,7 @@ struct grub_partition
/* The partition number. */ /* The partition number. */
int number; int number;
/* The start sector. */ /* The start sector (relative to parent). */
grub_disk_addr_t start; grub_disk_addr_t start;
/* The length in sector units. */ /* The length in sector units. */
@ -60,7 +60,7 @@ struct grub_partition
/* The index of this partition in the partition table. */ /* The index of this partition in the partition table. */
int index; int index;
/* Parent partition map. */ /* Parent partition (physically contains this partition). */
struct grub_partition *parent; struct grub_partition *parent;
/* The type partition map. */ /* The type partition map. */

View file

@ -80,6 +80,7 @@
#define GRUB_PCI_STATUS_DEVSEL_TIMING_SHIFT 9 #define GRUB_PCI_STATUS_DEVSEL_TIMING_SHIFT 9
#define GRUB_PCI_STATUS_DEVSEL_TIMING_MASK 0x0600 #define GRUB_PCI_STATUS_DEVSEL_TIMING_MASK 0x0600
#define GRUB_PCI_CLASS_SUBCLASS_VGA 0x0300
#ifndef ASM_FILE #ifndef ASM_FILE
typedef grub_uint32_t grub_pci_id_t; typedef grub_uint32_t grub_pci_id_t;

View file

@ -1,7 +1,7 @@
/* raid.h - On disk structures for RAID. */ /* raid.h - On disk structures for RAID. */
/* /*
* GRUB -- GRand Unified Bootloader * GRUB -- GRand Unified Bootloader
* Copyright (C) 2006,2007,2008 Free Software Foundation, Inc. * Copyright (C) 2006,2007,2008,2010 Free Software Foundation, Inc.
* *
* GRUB is free software: you can redistribute it and/or modify * GRUB is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -51,6 +51,8 @@ struct grub_raid_array
char *name; /* That will be "md<number>". */ char *name; /* That will be "md<number>". */
unsigned int nr_devs; /* The number of devices we've found so far. */ unsigned int nr_devs; /* The number of devices we've found so far. */
grub_disk_t device[GRUB_RAID_MAX_DEVICES]; /* Array of total_devs devices. */ grub_disk_t device[GRUB_RAID_MAX_DEVICES]; /* Array of total_devs devices. */
grub_disk_addr_t start_sector[GRUB_RAID_MAX_DEVICES];
/* Start of each device, in 512 byte sectors. */
struct grub_raid_array *next; struct grub_raid_array *next;
}; };
@ -58,7 +60,8 @@ struct grub_raid
{ {
const char *name; const char *name;
grub_err_t (*detect) (grub_disk_t disk, struct grub_raid_array *array); grub_err_t (*detect) (grub_disk_t disk, struct grub_raid_array *array,
grub_disk_addr_t *start_sector);
struct grub_raid *next; struct grub_raid *next;
}; };

View file

@ -104,7 +104,7 @@ struct grub_usb_controller_dev
grub_err_t (*portstatus) (grub_usb_controller_t dev, unsigned int port, grub_err_t (*portstatus) (grub_usb_controller_t dev, unsigned int port,
unsigned int enable); unsigned int enable);
grub_usb_speed_t (*detect_dev) (grub_usb_controller_t dev, int port); grub_usb_speed_t (*detect_dev) (grub_usb_controller_t dev, int port, int *changed);
/* The next host controller. */ /* The next host controller. */
struct grub_usb_controller_dev *next; struct grub_usb_controller_dev *next;
@ -125,6 +125,13 @@ struct grub_usb_interface
struct grub_usb_desc_if *descif; struct grub_usb_desc_if *descif;
struct grub_usb_desc_endp *descendp; struct grub_usb_desc_endp *descendp;
/* A driver is handling this interface. Do we need to support multiple drivers
for single interface?
*/
int attached;
void (*detach_hook) (struct grub_usb_device *dev, int config, int interface);
}; };
struct grub_usb_configuration struct grub_usb_configuration
@ -207,4 +214,21 @@ grub_usb_get_config_interface (struct grub_usb_desc_config *config)
return interf; return interf;
} }
typedef int (*grub_usb_attach_hook_class) (grub_usb_device_t usbdev,
int configno, int interfno);
struct grub_usb_attach_desc
{
struct grub_usb_attach_desc *next;
int class;
grub_usb_attach_hook_class hook;
};
void grub_usb_register_attach_hook_class (struct grub_usb_attach_desc *desc);
void grub_usb_unregister_attach_hook_class (struct grub_usb_attach_desc *desc);
void grub_usb_poll_devices (void);
void grub_usb_device_attach (grub_usb_device_t dev);
#endif /* GRUB_USB_H */ #endif /* GRUB_USB_H */

View file

@ -93,10 +93,12 @@ typedef struct grub_usb_transfer *grub_usb_transfer_t;
#define GRUB_USB_HUB_FEATURE_PORT_RESET 0x04 #define GRUB_USB_HUB_FEATURE_PORT_RESET 0x04
#define GRUB_USB_HUB_FEATURE_PORT_POWER 0x08 #define GRUB_USB_HUB_FEATURE_PORT_POWER 0x08
#define GRUB_USB_HUB_FEATURE_C_CONNECTED 0x10
#define GRUB_USB_HUB_STATUS_CONNECTED (1 << 0) #define GRUB_USB_HUB_STATUS_CONNECTED (1 << 0)
#define GRUB_USB_HUB_STATUS_LOWSPEED (1 << 9) #define GRUB_USB_HUB_STATUS_LOWSPEED (1 << 9)
#define GRUB_USB_HUB_STATUS_HIGHSPEED (1 << 10) #define GRUB_USB_HUB_STATUS_HIGHSPEED (1 << 10)
#define GRUB_USB_HUB_STATUS_C_CONNECTED (1 << 16)
#define GRUB_USB_HUB_STATUS_C_PORT_RESET (1 << 20) #define GRUB_USB_HUB_STATUS_C_PORT_RESET (1 << 20)
struct grub_usb_packet_setup struct grub_usb_packet_setup

View file

@ -0,0 +1,39 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2010 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/>.
*/
#ifndef GRUB_LIBNVPAIR_UTIL_HEADER
#define GRUB_LIBNVPAIR_UTIL_HEADER 1
#include <config.h>
#ifdef HAVE_LIBNVPAIR_H
#include <libnvpair.h>
#else /* ! HAVE_LIBNVPAIR_H */
#include <stdio.h> /* FILE */
typedef void nvlist_t;
int nvlist_lookup_string (nvlist_t *, const char *, char **);
int nvlist_lookup_nvlist (nvlist_t *, const char *, nvlist_t **);
int nvlist_lookup_nvlist_array (nvlist_t *, const char *, nvlist_t ***, unsigned int *);
void nvlist_print (FILE *, nvlist_t *);
#endif /* ! HAVE_LIBNVPAIR_H */
#endif

View file

@ -0,0 +1,45 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2010 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/>.
*/
#ifndef GRUB_LIBZFS_UTIL_HEADER
#define GRUB_LIBZFS_UTIL_HEADER 1
#include <config.h>
#ifdef HAVE_LIBZFS_H
#include <libzfs.h>
#else /* ! HAVE_LIBZFS_H */
#include <grub/util/libnvpair.h>
typedef void libzfs_handle_t;
typedef void zpool_handle_t;
extern libzfs_handle_t *libzfs_init (void);
extern void libzfs_fini (libzfs_handle_t *);
extern zpool_handle_t *zpool_open (libzfs_handle_t *, const char *);
extern void zpool_close (zpool_handle_t *);
extern int zpool_get_physpath (zpool_handle_t *, const char *);
extern nvlist_t *zpool_get_config (zpool_handle_t *, nvlist_t **);
#endif /* ! HAVE_LIBZFS_H */
#endif

View file

@ -19,9 +19,13 @@
#ifndef GRUB_VGA_HEADER #ifndef GRUB_VGA_HEADER
#define GRUB_VGA_HEADER 1 #define GRUB_VGA_HEADER 1
#include <grub/pci.h>
enum enum
{ {
GRUB_VGA_IO_ARX = 0x3c0, GRUB_VGA_IO_ARX = 0x3c0,
GRUB_VGA_IO_ARX_READ = 0x3c1,
GRUB_VGA_IO_MISC_WRITE = 0x3c2,
GRUB_VGA_IO_SR_INDEX = 0x3c4, GRUB_VGA_IO_SR_INDEX = 0x3c4,
GRUB_VGA_IO_SR_DATA = 0x3c5, GRUB_VGA_IO_SR_DATA = 0x3c5,
GRUB_VGA_IO_PIXEL_MASK = 0x3c6, GRUB_VGA_IO_PIXEL_MASK = 0x3c6,
@ -39,8 +43,15 @@ enum
enum enum
{ {
GRUB_VGA_CR_WIDTH = 0x01, GRUB_VGA_CR_HTOTAL = 0x00,
GRUB_VGA_CR_HORIZ_END = 0x01,
GRUB_VGA_CR_HBLANK_START = 0x02,
GRUB_VGA_CR_HBLANK_END = 0x03,
GRUB_VGA_CR_HORIZ_SYNC_PULSE_START = 0x04,
GRUB_VGA_CR_HORIZ_SYNC_PULSE_END = 0x05,
GRUB_VGA_CR_VERT_TOTAL = 0x06,
GRUB_VGA_CR_OVERFLOW = 0x07, GRUB_VGA_CR_OVERFLOW = 0x07,
GRUB_VGA_CR_BYTE_PANNING = 0x08,
GRUB_VGA_CR_CELL_HEIGHT = 0x09, GRUB_VGA_CR_CELL_HEIGHT = 0x09,
GRUB_VGA_CR_CURSOR_START = 0x0a, GRUB_VGA_CR_CURSOR_START = 0x0a,
GRUB_VGA_CR_CURSOR_END = 0x0b, GRUB_VGA_CR_CURSOR_END = 0x0b,
@ -48,14 +59,71 @@ enum
GRUB_VGA_CR_START_ADDR_LOW_REGISTER = 0x0d, GRUB_VGA_CR_START_ADDR_LOW_REGISTER = 0x0d,
GRUB_VGA_CR_CURSOR_ADDR_HIGH = 0x0e, GRUB_VGA_CR_CURSOR_ADDR_HIGH = 0x0e,
GRUB_VGA_CR_CURSOR_ADDR_LOW = 0x0f, GRUB_VGA_CR_CURSOR_ADDR_LOW = 0x0f,
GRUB_VGA_CR_VSYNC_START = 0x10,
GRUB_VGA_CR_VSYNC_END = 0x11, GRUB_VGA_CR_VSYNC_END = 0x11,
GRUB_VGA_CR_HEIGHT = 0x12, GRUB_VGA_CR_VDISPLAY_END = 0x12,
GRUB_VGA_CR_PITCH = 0x13, GRUB_VGA_CR_PITCH = 0x13,
GRUB_VGA_CR_UNDERLINE_LOCATION = 0x14,
GRUB_VGA_CR_VERTICAL_BLANK_START = 0x15,
GRUB_VGA_CR_VERTICAL_BLANK_END = 0x16,
GRUB_VGA_CR_MODE = 0x17, GRUB_VGA_CR_MODE = 0x17,
GRUB_VGA_CR_LINE_COMPARE = 0x18, GRUB_VGA_CR_LINE_COMPARE = 0x18,
}; };
enum
{
GRUB_VGA_CR_BYTE_PANNING_NORMAL = 0
};
enum
{
GRUB_VGA_CR_UNDERLINE_LOCATION_DWORD_MODE = 0x40
};
enum
{
GRUB_VGA_IO_MISC_COLOR = 0x01,
GRUB_VGA_IO_MISC_ENABLE_VRAM_ACCESS = 0x02,
GRUB_VGA_IO_MISC_EXTERNAL_CLOCK_0 = 0x08,
GRUB_VGA_IO_MISC_28MHZ = 0x04,
GRUB_VGA_IO_MISC_UPPER_64K = 0x20,
GRUB_VGA_IO_MISC_NEGATIVE_HORIZ_POLARITY = 0x40,
GRUB_VGA_IO_MISC_NEGATIVE_VERT_POLARITY = 0x80,
};
enum
{
GRUB_VGA_ARX_MODE = 0x10,
GRUB_VGA_ARX_OVERSCAN = 0x11,
GRUB_VGA_ARX_COLOR_PLANE_ENABLE = 0x12,
GRUB_VGA_ARX_HORIZONTAL_PANNING = 0x13,
GRUB_VGA_ARX_COLOR_SELECT = 0x14
};
enum
{
GRUB_VGA_ARX_MODE_TEXT = 0x00,
GRUB_VGA_ARX_MODE_GRAPHICS = 0x01,
GRUB_VGA_ARX_MODE_ENABLE_256COLOR = 0x40
};
#define GRUB_VGA_CR_WIDTH_DIVISOR 8 #define GRUB_VGA_CR_WIDTH_DIVISOR 8
#define GRUB_VGA_CR_OVERFLOW_VERT_DISPLAY_ENABLE_END1_SHIFT 7
#define GRUB_VGA_CR_OVERFLOW_VERT_DISPLAY_ENABLE_END1_MASK 0x02
#define GRUB_VGA_CR_OVERFLOW_VERT_DISPLAY_ENABLE_END2_SHIFT 3
#define GRUB_VGA_CR_OVERFLOW_VERT_DISPLAY_ENABLE_END2_MASK 0x40
#define GRUB_VGA_CR_OVERFLOW_VERT_TOTAL1_SHIFT 8
#define GRUB_VGA_CR_OVERFLOW_VERT_TOTAL1_MASK 0x01
#define GRUB_VGA_CR_OVERFLOW_VERT_TOTAL2_SHIFT 4
#define GRUB_VGA_CR_OVERFLOW_VERT_TOTAL2_MASK 0x20
#define GRUB_VGA_CR_OVERFLOW_VSYNC_START1_SHIFT 6
#define GRUB_VGA_CR_OVERFLOW_VSYNC_START1_MASK 0x04
#define GRUB_VGA_CR_OVERFLOW_VSYNC_START2_SHIFT 2
#define GRUB_VGA_CR_OVERFLOW_VSYNC_START2_MASK 0x80
#define GRUB_VGA_CR_OVERFLOW_HEIGHT1_SHIFT 7 #define GRUB_VGA_CR_OVERFLOW_HEIGHT1_SHIFT 7
#define GRUB_VGA_CR_OVERFLOW_HEIGHT1_MASK 0x02 #define GRUB_VGA_CR_OVERFLOW_HEIGHT1_MASK 0x02
#define GRUB_VGA_CR_OVERFLOW_HEIGHT2_SHIFT 3 #define GRUB_VGA_CR_OVERFLOW_HEIGHT2_SHIFT 3
@ -65,7 +133,9 @@ enum
#define GRUB_VGA_CR_CELL_HEIGHT_LINE_COMPARE_MASK 0x40 #define GRUB_VGA_CR_CELL_HEIGHT_LINE_COMPARE_MASK 0x40
#define GRUB_VGA_CR_CELL_HEIGHT_LINE_COMPARE_SHIFT 3 #define GRUB_VGA_CR_CELL_HEIGHT_LINE_COMPARE_SHIFT 3
#define GRUB_VGA_CR_CELL_HEIGHT_VERTICAL_BLANK_MASK 0x20
#define GRUB_VGA_CR_CELL_HEIGHT_VERTICAL_BLANK_SHIFT 4
#define GRUB_VGA_CR_CELL_HEIGHT_DOUBLE_SCAN 0x80
enum enum
{ {
GRUB_VGA_CR_CURSOR_START_DISABLE = (1 << 5) GRUB_VGA_CR_CURSOR_START_DISABLE = (1 << 5)
@ -77,17 +147,26 @@ enum
{ {
GRUB_VGA_CR_MODE_NO_CGA = 0x01, GRUB_VGA_CR_MODE_NO_CGA = 0x01,
GRUB_VGA_CR_MODE_NO_HERCULES = 0x02, GRUB_VGA_CR_MODE_NO_HERCULES = 0x02,
GRUB_VGA_CR_MODE_ADDRESS_WRAP = 0x20,
GRUB_VGA_CR_MODE_BYTE_MODE = 0x40, GRUB_VGA_CR_MODE_BYTE_MODE = 0x40,
GRUB_VGA_CR_MODE_TIMING_ENABLE = 0x80 GRUB_VGA_CR_MODE_TIMING_ENABLE = 0x80
}; };
enum enum
{ {
GRUB_VGA_SR_RESET = 0,
GRUB_VGA_SR_CLOCKING_MODE = 1, GRUB_VGA_SR_CLOCKING_MODE = 1,
GRUB_VGA_SR_MAP_MASK_REGISTER = 2, GRUB_VGA_SR_MAP_MASK_REGISTER = 2,
GRUB_VGA_SR_CHAR_MAP_SELECT = 3,
GRUB_VGA_SR_MEMORY_MODE = 4, GRUB_VGA_SR_MEMORY_MODE = 4,
}; };
enum
{
GRUB_VGA_SR_RESET_ASYNC = 1,
GRUB_VGA_SR_RESET_SYNC = 2
};
enum enum
{ {
GRUB_VGA_SR_CLOCKING_MODE_8_DOT_CLOCK = 1 GRUB_VGA_SR_CLOCKING_MODE_8_DOT_CLOCK = 1
@ -96,19 +175,33 @@ enum
enum enum
{ {
GRUB_VGA_SR_MEMORY_MODE_NORMAL = 0, GRUB_VGA_SR_MEMORY_MODE_NORMAL = 0,
GRUB_VGA_SR_MEMORY_MODE_CHAIN4 = 8 GRUB_VGA_SR_MEMORY_MODE_EXTERNAL_VIDEO_MEMORY = 2,
GRUB_VGA_SR_MEMORY_MODE_SEQUENTIAL_ADDRESSING = 4,
GRUB_VGA_SR_MEMORY_MODE_CHAIN4 = 8,
}; };
enum enum
{ {
GRUB_VGA_GR_SET_RESET_PLANE = 0,
GRUB_VGA_GR_SET_RESET_PLANE_ENABLE = 1,
GRUB_VGA_GR_COLOR_COMPARE = 2,
GRUB_VGA_GR_DATA_ROTATE = 3, GRUB_VGA_GR_DATA_ROTATE = 3,
GRUB_VGA_GR_READ_MAP_REGISTER = 4, GRUB_VGA_GR_READ_MAP_REGISTER = 4,
GRUB_VGA_GR_MODE = 5, GRUB_VGA_GR_MODE = 5,
GRUB_VGA_GR_GR6 = 6, GRUB_VGA_GR_GR6 = 6,
GRUB_VGA_GR_COLOR_COMPARE_DISABLE = 7,
GRUB_VGA_GR_BITMASK = 8, GRUB_VGA_GR_BITMASK = 8,
GRUB_VGA_GR_MAX GRUB_VGA_GR_MAX
}; };
#define GRUB_VGA_ALL_PLANES 0xf
#define GRUB_VGA_NO_PLANES 0x0
enum
{
GRUB_VGA_GR_DATA_ROTATE_NOP = 0
};
enum enum
{ {
GRUB_VGA_TEXT_TEXT_PLANE = 0, GRUB_VGA_TEXT_TEXT_PLANE = 0,
@ -119,6 +212,7 @@ enum
enum enum
{ {
GRUB_VGA_GR_GR6_GRAPHICS_MODE = 1, GRUB_VGA_GR_GR6_GRAPHICS_MODE = 1,
GRUB_VGA_GR_GR6_MMAP_A0 = (1 << 2),
GRUB_VGA_GR_GR6_MMAP_CGA = (3 << 2) GRUB_VGA_GR_GR6_MMAP_CGA = (3 << 2)
}; };
@ -126,70 +220,152 @@ enum
{ {
GRUB_VGA_GR_MODE_READ_MODE1 = 0x08, GRUB_VGA_GR_MODE_READ_MODE1 = 0x08,
GRUB_VGA_GR_MODE_ODD_EVEN = 0x10, GRUB_VGA_GR_MODE_ODD_EVEN = 0x10,
GRUB_VGA_GR_MODE_ODD_EVEN_SHIFT = 0x20,
GRUB_VGA_GR_MODE_256_COLOR = 0x40 GRUB_VGA_GR_MODE_256_COLOR = 0x40
}; };
static inline void static inline void
grub_vga_gr_write (grub_uint8_t val, grub_uint8_t addr) grub_vga_gr_write (grub_uint8_t val, grub_uint8_t addr)
{ {
grub_outb (addr, GRUB_VGA_IO_GR_INDEX); grub_outb (addr, GRUB_MACHINE_PCI_IO_BASE + GRUB_VGA_IO_GR_INDEX);
grub_outb (val, GRUB_VGA_IO_GR_DATA); grub_outb (val, GRUB_MACHINE_PCI_IO_BASE + GRUB_VGA_IO_GR_DATA);
} }
static inline grub_uint8_t static inline grub_uint8_t
grub_vga_gr_read (grub_uint8_t addr) grub_vga_gr_read (grub_uint8_t addr)
{ {
grub_outb (addr, GRUB_VGA_IO_GR_INDEX); grub_outb (addr, GRUB_MACHINE_PCI_IO_BASE + GRUB_VGA_IO_GR_INDEX);
return grub_inb (GRUB_VGA_IO_GR_DATA); return grub_inb (GRUB_MACHINE_PCI_IO_BASE + GRUB_VGA_IO_GR_DATA);
} }
static inline void static inline void
grub_vga_cr_write (grub_uint8_t val, grub_uint8_t addr) grub_vga_cr_write (grub_uint8_t val, grub_uint8_t addr)
{ {
grub_outb (addr, GRUB_VGA_IO_CR_INDEX); grub_outb (addr, GRUB_MACHINE_PCI_IO_BASE + GRUB_VGA_IO_CR_INDEX);
grub_outb (val, GRUB_VGA_IO_CR_DATA); grub_outb (val, GRUB_MACHINE_PCI_IO_BASE + GRUB_VGA_IO_CR_DATA);
} }
static inline grub_uint8_t static inline grub_uint8_t
grub_vga_cr_read (grub_uint8_t addr) grub_vga_cr_read (grub_uint8_t addr)
{ {
grub_outb (addr, GRUB_VGA_IO_CR_INDEX); grub_outb (addr, GRUB_MACHINE_PCI_IO_BASE + GRUB_VGA_IO_CR_INDEX);
return grub_inb (GRUB_VGA_IO_CR_DATA); return grub_inb (GRUB_MACHINE_PCI_IO_BASE + GRUB_VGA_IO_CR_DATA);
} }
static inline void static inline void
grub_vga_sr_write (grub_uint8_t val, grub_uint8_t addr) grub_vga_sr_write (grub_uint8_t val, grub_uint8_t addr)
{ {
grub_outb (addr, GRUB_VGA_IO_SR_INDEX); grub_outb (addr, GRUB_MACHINE_PCI_IO_BASE + GRUB_VGA_IO_SR_INDEX);
grub_outb (val, GRUB_VGA_IO_SR_DATA); grub_outb (val, GRUB_MACHINE_PCI_IO_BASE + GRUB_VGA_IO_SR_DATA);
} }
static inline grub_uint8_t static inline grub_uint8_t
grub_vga_sr_read (grub_uint8_t addr) grub_vga_sr_read (grub_uint8_t addr)
{ {
grub_outb (addr, GRUB_VGA_IO_SR_INDEX); grub_outb (addr, GRUB_MACHINE_PCI_IO_BASE + GRUB_VGA_IO_SR_INDEX);
return grub_inb (GRUB_VGA_IO_SR_DATA); return grub_inb (GRUB_MACHINE_PCI_IO_BASE + GRUB_VGA_IO_SR_DATA);
} }
static inline void static inline void
grub_vga_palette_read (grub_uint8_t addr, grub_uint8_t *r, grub_uint8_t *g, grub_vga_palette_read (grub_uint8_t addr, grub_uint8_t *r, grub_uint8_t *g,
grub_uint8_t *b) grub_uint8_t *b)
{ {
grub_outb (addr, GRUB_VGA_IO_PALLETTE_READ_INDEX); grub_outb (addr, GRUB_MACHINE_PCI_IO_BASE + GRUB_VGA_IO_PALLETTE_READ_INDEX);
*r = grub_inb (GRUB_VGA_IO_PALLETTE_DATA); *r = grub_inb (GRUB_MACHINE_PCI_IO_BASE + GRUB_VGA_IO_PALLETTE_DATA);
*g = grub_inb (GRUB_VGA_IO_PALLETTE_DATA); *g = grub_inb (GRUB_MACHINE_PCI_IO_BASE + GRUB_VGA_IO_PALLETTE_DATA);
*b = grub_inb (GRUB_VGA_IO_PALLETTE_DATA); *b = grub_inb (GRUB_MACHINE_PCI_IO_BASE + GRUB_VGA_IO_PALLETTE_DATA);
} }
static inline void static inline void
grub_vga_palette_write (grub_uint8_t addr, grub_uint8_t r, grub_uint8_t g, grub_vga_palette_write (grub_uint8_t addr, grub_uint8_t r, grub_uint8_t g,
grub_uint8_t b) grub_uint8_t b)
{ {
grub_outb (addr, GRUB_VGA_IO_PALLETTE_WRITE_INDEX); grub_outb (addr, GRUB_MACHINE_PCI_IO_BASE + GRUB_VGA_IO_PALLETTE_WRITE_INDEX);
grub_outb (r, GRUB_VGA_IO_PALLETTE_DATA); grub_outb (r, GRUB_MACHINE_PCI_IO_BASE + GRUB_VGA_IO_PALLETTE_DATA);
grub_outb (g, GRUB_VGA_IO_PALLETTE_DATA); grub_outb (g, GRUB_MACHINE_PCI_IO_BASE + GRUB_VGA_IO_PALLETTE_DATA);
grub_outb (b, GRUB_VGA_IO_PALLETTE_DATA); grub_outb (b, GRUB_MACHINE_PCI_IO_BASE + GRUB_VGA_IO_PALLETTE_DATA);
} }
static inline void
grub_vga_write_arx (grub_uint8_t val, grub_uint8_t addr)
{
grub_inb (GRUB_MACHINE_PCI_IO_BASE + GRUB_VGA_IO_INPUT_STATUS1_REGISTER);
grub_outb (addr, GRUB_MACHINE_PCI_IO_BASE + GRUB_VGA_IO_ARX);
grub_inb (GRUB_MACHINE_PCI_IO_BASE + GRUB_VGA_IO_ARX_READ);
grub_outb (val, GRUB_MACHINE_PCI_IO_BASE + GRUB_VGA_IO_ARX);
}
struct grub_video_hw_config
{
unsigned vertical_total;
unsigned vertical_blank_start;
unsigned vertical_blank_end;
unsigned vertical_sync_start;
unsigned vertical_sync_end;
unsigned line_compare;
unsigned vdisplay_end;
unsigned pitch;
unsigned horizontal_total;
unsigned horizontal_blank_start;
unsigned horizontal_blank_end;
unsigned horizontal_sync_pulse_start;
unsigned horizontal_sync_pulse_end;
unsigned horizontal_end;
};
static inline void
grub_vga_set_geometry (struct grub_video_hw_config *config,
void (*cr_write) (grub_uint8_t val, grub_uint8_t addr))
{
unsigned vertical_total = config->vertical_total - 2;
unsigned vertical_blank_start = config->vertical_blank_start - 1;
unsigned vdisplay_end = config->vdisplay_end - 1;
grub_uint8_t overflow, cell_height_reg;
/* Disable CR0-7 write protection. */
cr_write (0, GRUB_VGA_CR_VSYNC_END);
overflow = ((vertical_total >> GRUB_VGA_CR_OVERFLOW_VERT_TOTAL1_SHIFT)
& GRUB_VGA_CR_OVERFLOW_VERT_TOTAL1_MASK)
| ((vertical_total >> GRUB_VGA_CR_OVERFLOW_VERT_TOTAL2_SHIFT)
& GRUB_VGA_CR_OVERFLOW_VERT_TOTAL2_MASK)
| ((config->vertical_sync_start >> GRUB_VGA_CR_OVERFLOW_VSYNC_START2_SHIFT)
& GRUB_VGA_CR_OVERFLOW_VSYNC_START2_MASK)
| ((config->vertical_sync_start >> GRUB_VGA_CR_OVERFLOW_VSYNC_START1_SHIFT)
& GRUB_VGA_CR_OVERFLOW_VSYNC_START1_MASK)
| ((vdisplay_end >> GRUB_VGA_CR_OVERFLOW_VERT_DISPLAY_ENABLE_END1_SHIFT)
& GRUB_VGA_CR_OVERFLOW_VERT_DISPLAY_ENABLE_END1_MASK)
| ((vdisplay_end >> GRUB_VGA_CR_OVERFLOW_VERT_DISPLAY_ENABLE_END2_SHIFT)
& GRUB_VGA_CR_OVERFLOW_VERT_DISPLAY_ENABLE_END2_MASK)
| ((config->vertical_sync_start >> GRUB_VGA_CR_OVERFLOW_VSYNC_START1_SHIFT)
& GRUB_VGA_CR_OVERFLOW_VSYNC_START1_MASK)
| ((config->line_compare >> GRUB_VGA_CR_OVERFLOW_LINE_COMPARE_SHIFT)
& GRUB_VGA_CR_OVERFLOW_LINE_COMPARE_MASK);
cell_height_reg = ((vertical_blank_start
>> GRUB_VGA_CR_CELL_HEIGHT_VERTICAL_BLANK_SHIFT)
& GRUB_VGA_CR_CELL_HEIGHT_VERTICAL_BLANK_MASK)
| ((config->line_compare >> GRUB_VGA_CR_CELL_HEIGHT_LINE_COMPARE_SHIFT)
& GRUB_VGA_CR_CELL_HEIGHT_LINE_COMPARE_MASK);
cr_write (config->horizontal_total - 1, GRUB_VGA_CR_HTOTAL);
cr_write (config->horizontal_end - 1, GRUB_VGA_CR_HORIZ_END);
cr_write (config->horizontal_blank_start - 1, GRUB_VGA_CR_HBLANK_START);
cr_write (config->horizontal_blank_end, GRUB_VGA_CR_HBLANK_END);
cr_write (config->horizontal_sync_pulse_start,
GRUB_VGA_CR_HORIZ_SYNC_PULSE_START);
cr_write (config->horizontal_sync_pulse_end,
GRUB_VGA_CR_HORIZ_SYNC_PULSE_END);
cr_write (vertical_total & 0xff, GRUB_VGA_CR_VERT_TOTAL);
cr_write (overflow, GRUB_VGA_CR_OVERFLOW);
cr_write (cell_height_reg, GRUB_VGA_CR_CELL_HEIGHT);
cr_write (config->vertical_sync_start & 0xff, GRUB_VGA_CR_VSYNC_START);
cr_write (config->vertical_sync_end & 0x0f, GRUB_VGA_CR_VSYNC_END);
cr_write (vdisplay_end & 0xff, GRUB_VGA_CR_VDISPLAY_END);
cr_write (config->pitch & 0xff, GRUB_VGA_CR_PITCH);
cr_write (vertical_blank_start & 0xff, GRUB_VGA_CR_VERTICAL_BLANK_START);
cr_write (config->vertical_blank_end & 0xff, GRUB_VGA_CR_VERTICAL_BLANK_END);
cr_write (config->line_compare & 0xff, GRUB_VGA_CR_LINE_COMPARE);
}
#endif #endif

View file

@ -1,7 +1,7 @@
/* getroot.c - Get root device */ /* getroot.c - Get root device */
/* /*
* GRUB -- GRand Unified Bootloader * GRUB -- GRand Unified Bootloader
* Copyright (C) 1999,2000,2001,2002,2003,2006,2007,2008,2009 Free Software Foundation, Inc. * Copyright (C) 1999,2000,2001,2002,2003,2006,2007,2008,2009,2010 Free Software Foundation, Inc.
* *
* GRUB is free software: you can redistribute it and/or modify * GRUB is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -20,14 +20,17 @@
#include <config.h> #include <config.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/types.h> #include <sys/types.h>
#include <assert.h>
#include <fcntl.h> #include <fcntl.h>
#include <unistd.h> #include <unistd.h>
#include <string.h> #include <string.h>
#include <dirent.h> #include <dirent.h>
#include <errno.h> #include <errno.h>
#include <error.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdint.h> #include <stdint.h>
#include <grub/util/misc.h>
#ifdef __GNU__ #ifdef __GNU__
#include <hurd.h> #include <hurd.h>
@ -36,6 +39,16 @@
#include <sys/mman.h> #include <sys/mman.h>
#endif #endif
#ifdef __linux__
# include <sys/types.h>
# include <sys/wait.h>
#endif
#if defined(HAVE_LIBZFS) && defined(HAVE_LIBNVPAIR)
# include <grub/util/libzfs.h>
# include <grub/util/libnvpair.h>
#endif
#include <grub/mm.h> #include <grub/mm.h>
#include <grub/misc.h> #include <grub/misc.h>
#include <grub/emu/misc.h> #include <grub/emu/misc.h>
@ -161,6 +174,53 @@ find_root_device_from_mountinfo (const char *dir)
#endif /* __linux__ */ #endif /* __linux__ */
#if defined(HAVE_LIBZFS) && defined(HAVE_LIBNVPAIR)
static char *
find_root_device_from_libzfs (const char *dir)
{
char *device;
char *poolname;
char *poolfs;
grub_find_zpool_from_dir (dir, &poolname, &poolfs);
if (! poolname)
return NULL;
{
zpool_handle_t *zpool;
nvlist_t *nvlist;
nvlist_t **nvlist_array;
unsigned int nvlist_count;
zpool = zpool_open (grub_get_libzfs_handle (), poolname);
nvlist = zpool_get_config (zpool, NULL);
if (nvlist_lookup_nvlist (nvlist, "vdev_tree", &nvlist) != 0)
error (1, errno, "nvlist_lookup_nvlist (\"vdev_tree\")");
if (nvlist_lookup_nvlist_array (nvlist, "children", &nvlist_array, &nvlist_count) != 0)
error (1, errno, "nvlist_lookup_nvlist_array (\"children\")");
do
{
assert (nvlist_count > 0);
} while (nvlist_lookup_nvlist_array (nvlist_array[0], "children",
&nvlist_array, &nvlist_count) == 0);
if (nvlist_lookup_string (nvlist_array[0], "path", &device) != 0)
error (1, errno, "nvlist_lookup_string (\"path\")");
zpool_close (zpool);
}
free (poolname);
if (poolfs)
free (poolfs);
return device;
}
#endif
#ifdef __MINGW32__ #ifdef __MINGW32__
static char * static char *
@ -453,6 +513,12 @@ grub_guess_root_device (const char *dir)
return os_dev; return os_dev;
#endif /* __linux__ */ #endif /* __linux__ */
#if defined(HAVE_LIBZFS) && defined(HAVE_LIBNVPAIR)
os_dev = find_root_device_from_libzfs (dir);
if (os_dev)
return os_dev;
#endif
if (stat (dir, &st) < 0) if (stat (dir, &st) < 0)
grub_util_error ("cannot stat `%s'", dir); grub_util_error ("cannot stat `%s'", dir);
@ -516,10 +582,89 @@ grub_util_get_dev_abstraction (const char *os_dev __attribute__((unused)))
return GRUB_DEV_ABSTRACTION_NONE; return GRUB_DEV_ABSTRACTION_NONE;
} }
#ifdef __linux__
static char *
get_mdadm_name (const char *os_dev)
{
int mdadm_pipe[2];
pid_t mdadm_pid;
char *name = NULL;
if (pipe (mdadm_pipe) < 0)
{
grub_util_warn ("Unable to create pipe for mdadm: %s", strerror (errno));
return NULL;
}
mdadm_pid = fork ();
if (mdadm_pid < 0)
grub_util_warn ("Unable to fork mdadm: %s", strerror (errno));
else if (mdadm_pid == 0)
{
/* Child. */
char *argv[5];
close (mdadm_pipe[0]);
dup2 (mdadm_pipe[1], STDOUT_FILENO);
close (mdadm_pipe[1]);
/* execvp has inconvenient types, hence the casts. None of these
strings will actually be modified. */
argv[0] = (char *) "mdadm";
argv[1] = (char *) "--detail";
argv[2] = (char *) "--export";
argv[3] = (char *) os_dev;
argv[4] = NULL;
execvp ("mdadm", argv);
exit (127);
}
else
{
/* Parent. Read mdadm's output. */
FILE *mdadm;
char *buf = NULL;
size_t len = 0;
close (mdadm_pipe[1]);
mdadm = fdopen (mdadm_pipe[0], "r");
if (! mdadm)
{
grub_util_warn ("Unable to open stream from mdadm: %s",
strerror (errno));
goto out;
}
while (getline (&buf, &len, mdadm) > 0)
{
if (strncmp (buf, "MD_NAME=", sizeof ("MD_NAME=") - 1) == 0)
{
char *name_start, *colon;
size_t name_len;
free (name);
name_start = buf + sizeof ("MD_NAME=") - 1;
/* Strip off the homehost if present. */
colon = strchr (name_start, ':');
name = strdup (colon ? colon + 1 : name_start);
name_len = strlen (name);
if (name[name_len - 1] == '\n')
name[name_len - 1] = '\0';
}
}
out:
close (mdadm_pipe[0]);
waitpid (mdadm_pid, NULL, 0);
}
return name;
}
#endif /* __linux__ */
char * char *
grub_util_get_grub_dev (const char *os_dev) grub_util_get_grub_dev (const char *os_dev)
{ {
char *grub_dev; char *grub_dev = NULL;
switch (grub_util_get_dev_abstraction (os_dev)) switch (grub_util_get_dev_abstraction (os_dev))
{ {
@ -600,9 +745,36 @@ grub_util_get_grub_dev (const char *os_dev)
grub_dev = xasprintf ("md%s", p); grub_dev = xasprintf ("md%s", p);
free (p); free (p);
} }
else if (os_dev[7] == '/')
{
/* mdraid 1.x with a free name. */
char *p , *q;
p = strdup (os_dev + sizeof ("/dev/md/") - 1);
q = strchr (p, 'p');
if (q)
*q = ',';
grub_dev = xasprintf ("md/%s", p);
free (p);
}
else else
grub_util_error ("unknown kind of RAID device `%s'", os_dev); grub_util_error ("unknown kind of RAID device `%s'", os_dev);
#ifdef __linux__
{
char *mdadm_name = get_mdadm_name (os_dev);
if (mdadm_name)
{
free (grub_dev);
grub_dev = xasprintf ("md/%s", mdadm_name);
free (mdadm_name);
}
}
#endif /* __linux__ */
break; break;
default: /* GRUB_DEV_ABSTRACTION_NONE */ default: /* GRUB_DEV_ABSTRACTION_NONE */

View file

@ -1,6 +1,25 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2002,2003,2005,2006,2007,2008,2009,2010 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 <config.h> #include <config.h>
#include <errno.h> #include <errno.h>
#include <error.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdint.h> #include <stdint.h>
@ -26,6 +45,22 @@
# include <libdevmapper.h> # include <libdevmapper.h>
#endif #endif
#ifdef HAVE_LIBZFS
# include <grub/util/libzfs.h>
#endif
#ifdef HAVE_LIBNVPAIR
# include <grub/util/libnvpair.h>
#endif
#ifdef HAVE_SYS_PARAM_H
# include <sys/param.h>
#endif
#ifdef HAVE_SYS_MOUNT_H
# include <sys/mount.h>
#endif
int verbosity; int verbosity;
void void
@ -218,23 +253,82 @@ get_win32_path (const char *path)
} }
#endif #endif
#ifdef HAVE_LIBZFS
static libzfs_handle_t *__libzfs_handle;
static void
fini_libzfs (void)
{
libzfs_fini (__libzfs_handle);
}
libzfs_handle_t *
grub_get_libzfs_handle (void)
{
if (! __libzfs_handle)
{
__libzfs_handle = libzfs_init ();
atexit (fini_libzfs);
}
return __libzfs_handle;
}
#endif /* HAVE_LIBZFS */
#if defined(HAVE_LIBZFS) && defined(HAVE_LIBNVPAIR)
/* ZFS has similar problems to those of btrfs (see above). */
void
grub_find_zpool_from_dir (const char *dir, char **poolname, char **poolfs)
{
struct statfs mnt;
char *slash;
*poolname = *poolfs = NULL;
if (statfs (dir, &mnt) != 0)
return;
*poolname = xstrdup (mnt.f_mntfromname);
slash = strchr (*poolname, '/');
if (slash)
{
*slash = '\0';
*poolfs = xstrdup (slash + 1);
}
else
*poolfs = xstrdup ("");
}
#endif
/* This function never prints trailing slashes (so that its output /* This function never prints trailing slashes (so that its output
can be appended a slash unconditionally). */ can be appended a slash unconditionally). */
char * char *
grub_make_system_path_relative_to_its_root (const char *path) grub_make_system_path_relative_to_its_root (const char *path)
{ {
struct stat st; struct stat st;
char *p, *buf, *buf2, *buf3; char *p, *buf, *buf2, *buf3, *ret;
uintptr_t offset = 0; uintptr_t offset = 0;
dev_t num; dev_t num;
size_t len; size_t len;
#if defined(HAVE_LIBZFS) && defined(HAVE_LIBNVPAIR)
char *poolfs = NULL;
#endif
/* canonicalize. */ /* canonicalize. */
p = canonicalize_file_name (path); p = canonicalize_file_name (path);
if (p == NULL) if (p == NULL)
grub_util_error ("failed to get canonical path of %s", path); grub_util_error ("failed to get canonical path of %s", path);
#if defined(HAVE_LIBZFS) && defined(HAVE_LIBNVPAIR)
/* For ZFS sub-pool filesystems, could be extended to others (btrfs?). */
{
char *dummy;
grub_find_zpool_from_dir (p, &dummy, &poolfs);
}
#endif
len = strlen (p) + 1; len = strlen (p) + 1;
buf = xstrdup (p); buf = xstrdup (p);
free (p); free (p);
@ -313,7 +407,17 @@ grub_make_system_path_relative_to_its_root (const char *path)
len--; len--;
} }
return buf3; #if defined(HAVE_LIBZFS) && defined(HAVE_LIBNVPAIR)
if (poolfs)
{
ret = xasprintf ("/%s/@%s", poolfs, buf3);
free (buf3);
}
else
#endif
ret = buf3;
return ret;
} }
#ifdef HAVE_DEVICE_MAPPER #ifdef HAVE_DEVICE_MAPPER

View file

@ -69,10 +69,7 @@ load_palette (void)
{ {
unsigned i; unsigned i;
for (i = 0; i < 16; i++) for (i = 0; i < 16; i++)
{ grub_vga_write_arx (i, i);
grub_outb (i, GRUB_VGA_IO_ARX);
grub_outb (i, GRUB_VGA_IO_ARX);
}
for (i = 0; i < ARRAY_SIZE (colors); i++) for (i = 0; i < ARRAY_SIZE (colors); i++)
grub_vga_palette_write (i, colors[i].r, colors[i].g, colors[i].b); grub_vga_palette_write (i, colors[i].r, colors[i].g, colors[i].b);
@ -90,7 +87,7 @@ grub_qemu_init_cirrus (void)
addr = grub_pci_make_address (dev, GRUB_PCI_REG_CLASS); addr = grub_pci_make_address (dev, GRUB_PCI_REG_CLASS);
class = grub_pci_read (addr); class = grub_pci_read (addr);
if (((class >> 16) & 0xffff) != 0x0300) if (((class >> 16) & 0xffff) != GRUB_PCI_CLASS_SUBCLASS_VGA)
return 0; return 0;
/* FIXME: chooose addresses dynamically. */ /* FIXME: chooose addresses dynamically. */
@ -110,7 +107,7 @@ grub_qemu_init_cirrus (void)
grub_pci_iterate (find_card); grub_pci_iterate (find_card);
grub_outb (1, 0x3c2); grub_outb (GRUB_VGA_IO_MISC_COLOR, GRUB_VGA_IO_MISC_WRITE);
load_font (); load_font ();
@ -124,11 +121,11 @@ grub_qemu_init_cirrus (void)
GRUB_VGA_SR_MAP_MASK_REGISTER); GRUB_VGA_SR_MAP_MASK_REGISTER);
grub_vga_cr_write (15, GRUB_VGA_CR_CELL_HEIGHT); grub_vga_cr_write (15, GRUB_VGA_CR_CELL_HEIGHT);
grub_vga_cr_write (79, GRUB_VGA_CR_WIDTH); grub_vga_cr_write (79, GRUB_VGA_CR_HORIZ_END);
grub_vga_cr_write (40, GRUB_VGA_CR_PITCH); grub_vga_cr_write (40, GRUB_VGA_CR_PITCH);
int vert = 25 * 16; int vert = 25 * 16;
grub_vga_cr_write (vert & 0xff, GRUB_VGA_CR_HEIGHT); grub_vga_cr_write (vert & 0xff, GRUB_VGA_CR_VDISPLAY_END);
grub_vga_cr_write (((vert >> GRUB_VGA_CR_OVERFLOW_HEIGHT1_SHIFT) grub_vga_cr_write (((vert >> GRUB_VGA_CR_OVERFLOW_HEIGHT1_SHIFT)
& GRUB_VGA_CR_OVERFLOW_HEIGHT1_MASK) & GRUB_VGA_CR_OVERFLOW_HEIGHT1_MASK)
| ((vert >> GRUB_VGA_CR_OVERFLOW_HEIGHT2_SHIFT) | ((vert >> GRUB_VGA_CR_OVERFLOW_HEIGHT2_SHIFT)
@ -137,10 +134,8 @@ grub_qemu_init_cirrus (void)
load_palette (); load_palette ();
grub_outb (0x10, 0x3c0); grub_vga_write_arx (GRUB_VGA_ARX_MODE_TEXT, GRUB_VGA_ARX_MODE);
grub_outb (0, 0x3c1); grub_vga_write_arx (0, GRUB_VGA_ARX_COLOR_SELECT);
grub_outb (0x14, 0x3c0);
grub_outb (0, 0x3c1);
grub_vga_sr_write (GRUB_VGA_SR_CLOCKING_MODE_8_DOT_CLOCK, grub_vga_sr_write (GRUB_VGA_SR_CLOCKING_MODE_8_DOT_CLOCK,
GRUB_VGA_SR_CLOCKING_MODE); GRUB_VGA_SR_CLOCKING_MODE);

View file

@ -518,12 +518,39 @@ grub_strndup (const char *s, grub_size_t n)
} }
void * void *
grub_memset (void *s, int c, grub_size_t n) grub_memset (void *s, int c, grub_size_t len)
{ {
unsigned char *p = (unsigned char *) s; void *p = s;
grub_uint8_t pattern8 = c;
while (n--) if (len >= 3 * sizeof (unsigned long))
*p++ = (unsigned char) c; {
unsigned long patternl = 0;
grub_size_t i;
for (i = 0; i < sizeof (unsigned long); i++)
patternl |= ((unsigned long) pattern8) << (8 * i);
while (len > 0 && (((grub_addr_t) p) & (sizeof (unsigned long) - 1)))
{
*(grub_uint8_t *) p = pattern8;
p = (grub_uint8_t *) p + 1;
len--;
}
while (len >= sizeof (unsigned long))
{
*(unsigned long *) p = patternl;
p = (unsigned long *) p + 1;
len -= sizeof (unsigned long);
}
}
while (len > 0)
{
*(grub_uint8_t *) p = pattern8;
p = (grub_uint8_t *) p + 1;
len--;
}
return s; return s;
} }

View file

@ -21,8 +21,43 @@
#include <grub/partition.h> #include <grub/partition.h>
#include <grub/disk.h> #include <grub/disk.h>
#ifdef GRUB_UTIL
#include <grub/util/misc.h>
#endif
grub_partition_map_t grub_partition_map_list; grub_partition_map_t grub_partition_map_list;
/*
* Checks that disk->partition contains part. This function assumes that the
* start of part is relative to the start of disk->partition. Returns 1 if
* disk->partition is null.
*/
static int
grub_partition_check_containment (const grub_disk_t disk,
const grub_partition_t part)
{
if (disk->partition == NULL)
return 1;
if (part->start + part->len > disk->partition->len)
{
char *partname;
partname = grub_partition_get_name (disk->partition);
grub_dprintf ("partition", "sub-partition %s%d of (%s,%s) ends after parent.\n",
part->partmap->name, part->number + 1, disk->name, partname);
#ifdef GRUB_UTIL
grub_util_warn ("Discarding improperly nested partition (%s,%s,%s%d)",
disk->name, partname, part->partmap->name, part->number + 1);
#endif
grub_free (partname);
return 0;
}
return 1;
}
static grub_partition_t static grub_partition_t
grub_partition_map_probe (const grub_partition_map_t partmap, grub_partition_map_probe (const grub_partition_map_t partmap,
grub_disk_t disk, int partnum) grub_disk_t disk, int partnum)
@ -31,11 +66,15 @@ grub_partition_map_probe (const grub_partition_map_t partmap,
auto int find_func (grub_disk_t d, const grub_partition_t partition); auto int find_func (grub_disk_t d, const grub_partition_t partition);
int find_func (grub_disk_t d __attribute__ ((unused)), int find_func (grub_disk_t dsk,
const grub_partition_t partition) const grub_partition_t partition)
{ {
if (partnum == partition->number) if (partnum != partition->number)
{ return 0;
if (!(grub_partition_check_containment (dsk, partition)))
return 0;
p = (grub_partition_t) grub_malloc (sizeof (*p)); p = (grub_partition_t) grub_malloc (sizeof (*p));
if (! p) if (! p)
return 1; return 1;
@ -44,9 +83,6 @@ grub_partition_map_probe (const grub_partition_map_t partmap,
return 1; return 1;
} }
return 0;
}
partmap->iterate (disk, find_func); partmap->iterate (disk, find_func);
if (grub_errno) if (grub_errno)
goto fail; goto fail;
@ -138,6 +174,10 @@ grub_partition_iterate (struct grub_disk *disk,
const grub_partition_t partition) const grub_partition_t partition)
{ {
struct grub_partition p = *partition; struct grub_partition p = *partition;
if (!(grub_partition_check_containment (dsk, partition)))
return 0;
p.parent = dsk->partition; p.parent = dsk->partition;
dsk->partition = 0; dsk->partition = 0;
if (hook (dsk, &p)) if (hook (dsk, &p))

View file

@ -144,8 +144,10 @@ grub_arg_show_help (grub_extcmd_t cmd)
} }
} }
/* FIXME: add spacing back. */ while (spacing--)
grub_xputs (_(opt->doc)); grub_xputs (" ");
grub_printf ("%s\n", _(opt->doc));
switch (opt->shortarg) switch (opt->shortarg)
{ {

View file

@ -157,11 +157,13 @@ LOCAL(cont1):
andl $(~GRUB_MEMORY_CPU_CR0_PAGING_ON), %eax andl $(~GRUB_MEMORY_CPU_CR0_PAGING_ON), %eax
movl %eax, %cr0 movl %eax, %cr0
#ifdef __x86_64__
/* Disable amd64. */ /* Disable amd64. */
movl $GRUB_MEMORY_CPU_AMD64_MSR, %ecx movl $GRUB_MEMORY_CPU_AMD64_MSR, %ecx
rdmsr rdmsr
andl $(~GRUB_MEMORY_CPU_AMD64_MSR_ON), %eax andl $(~GRUB_MEMORY_CPU_AMD64_MSR_ON), %eax
wrmsr wrmsr
#endif
/* Turn off PAE. */ /* Turn off PAE. */
movl %cr4, %eax movl %cr4, %eax

View file

@ -220,7 +220,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
if (! elf) if (! elf)
goto out; goto out;
if (elf->ehdr.ehdr32.e_type != ET_EXEC) if (elf->ehdr.ehdr32.e_type != ET_EXEC && elf->ehdr.ehdr32.e_type != ET_DYN)
{ {
grub_error (GRUB_ERR_UNKNOWN_OS, grub_error (GRUB_ERR_UNKNOWN_OS,
"this ELF file is not of the right type"); "this ELF file is not of the right type");

View file

@ -24,6 +24,10 @@
#include <grub/misc.h> #include <grub/misc.h>
#include <grub/dl.h> #include <grub/dl.h>
#ifdef GRUB_UTIL
#include <grub/util/misc.h>
#endif
static struct grub_partition_map grub_bsdlabel_partition_map; static struct grub_partition_map grub_bsdlabel_partition_map;
@ -37,9 +41,6 @@ bsdlabel_partition_map_iterate (grub_disk_t disk,
grub_disk_addr_t delta = 0; grub_disk_addr_t delta = 0;
unsigned pos; unsigned pos;
/* BSDLabel offsets are absolute even when it's embed inside partition. */
delta = grub_partition_get_start (disk->partition);
/* Read the BSD label. */ /* Read the BSD label. */
if (grub_disk_read (disk, GRUB_PC_PARTITION_BSD_LABEL_SECTOR, if (grub_disk_read (disk, GRUB_PC_PARTITION_BSD_LABEL_SECTOR,
0, sizeof (label), &label)) 0, sizeof (label), &label))
@ -49,30 +50,79 @@ bsdlabel_partition_map_iterate (grub_disk_t disk,
if (label.magic != grub_cpu_to_le32 (GRUB_PC_PARTITION_BSD_LABEL_MAGIC)) if (label.magic != grub_cpu_to_le32 (GRUB_PC_PARTITION_BSD_LABEL_MAGIC))
return grub_error (GRUB_ERR_BAD_PART_TABLE, "no signature"); return grub_error (GRUB_ERR_BAD_PART_TABLE, "no signature");
/* A kludge to determine a base of be.offset. */
if (GRUB_PC_PARTITION_BSD_LABEL_WHOLE_DISK_PARTITION
< grub_cpu_to_le16 (label.num_partitions))
{
struct grub_partition_bsd_entry whole_disk_be;
pos = sizeof (label) + GRUB_PC_PARTITION_BSD_LABEL_SECTOR
* GRUB_DISK_SECTOR_SIZE + sizeof (struct grub_partition_bsd_entry)
* GRUB_PC_PARTITION_BSD_LABEL_WHOLE_DISK_PARTITION;
if (grub_disk_read (disk, pos / GRUB_DISK_SECTOR_SIZE,
pos % GRUB_DISK_SECTOR_SIZE, sizeof (whole_disk_be),
&whole_disk_be))
return grub_errno;
delta = grub_le_to_cpu32 (whole_disk_be.offset);
}
pos = sizeof (label) + GRUB_PC_PARTITION_BSD_LABEL_SECTOR pos = sizeof (label) + GRUB_PC_PARTITION_BSD_LABEL_SECTOR
* GRUB_DISK_SECTOR_SIZE; * GRUB_DISK_SECTOR_SIZE;
for (p.number = 0; for (p.number = 0;
p.number < grub_cpu_to_le16 (label.num_partitions); p.number < grub_cpu_to_le16 (label.num_partitions);
p.number++) p.number++, pos += sizeof (struct grub_partition_bsd_entry))
{ {
struct grub_partition_bsd_entry be; struct grub_partition_bsd_entry be;
if (p.number == GRUB_PC_PARTITION_BSD_LABEL_WHOLE_DISK_PARTITION)
continue;
p.offset = pos / GRUB_DISK_SECTOR_SIZE; p.offset = pos / GRUB_DISK_SECTOR_SIZE;
p.index = pos % GRUB_DISK_SECTOR_SIZE; p.index = pos % GRUB_DISK_SECTOR_SIZE;
if (grub_disk_read (disk, p.offset, p.index, sizeof (be), &be)) if (grub_disk_read (disk, p.offset, p.index, sizeof (be), &be))
return grub_errno; return grub_errno;
p.start = grub_le_to_cpu32 (be.offset) - delta; p.start = grub_le_to_cpu32 (be.offset);
p.len = grub_le_to_cpu32 (be.size); p.len = grub_le_to_cpu32 (be.size);
p.partmap = &grub_bsdlabel_partition_map; p.partmap = &grub_bsdlabel_partition_map;
if (be.fs_type != GRUB_PC_PARTITION_BSD_TYPE_UNUSED) grub_dprintf ("partition",
"partition %d: type 0x%x, start 0x%llx, len 0x%llx\n",
p.number, be.fs_type,
(unsigned long long) p.start,
(unsigned long long) p.len);
if (p.len == 0)
continue;
if (p.start < delta)
{
#ifdef GRUB_UTIL
char *partname;
#endif
grub_dprintf ("partition",
"partition %d: invalid start (found 0x%llx, wanted >= 0x%llx)\n",
p.number,
(unsigned long long) p.start,
(unsigned long long) delta);
#ifdef GRUB_UTIL
/* disk->partition != NULL as 0 < delta */
partname = grub_partition_get_name (disk->partition);
grub_util_warn ("Discarding improperly nested partition (%s,%s,%s%d)",
disk->name, partname, p.partmap->name, p.number + 1);
grub_free (partname);
#endif
continue;
}
p.start -= delta;
if (hook (disk, &p)) if (hook (disk, &p))
return grub_errno; return grub_errno;
pos += sizeof (struct grub_partition_bsd_entry);
} }
return GRUB_ERR_NONE; return GRUB_ERR_NONE;

View file

@ -20,6 +20,7 @@
#include <grub/mm.h> #include <grub/mm.h>
#include <grub/script_sh.h> #include <grub/script_sh.h>
/* Return nearest power of two that is >= v. */
static unsigned static unsigned
round_up_exp (unsigned v) round_up_exp (unsigned v)
{ {

View file

@ -328,7 +328,7 @@ grub_script_execute_cmdline (struct grub_script_cmd *cmd)
struct grub_script_argv argv = { 0, 0 }; struct grub_script_argv argv = { 0, 0 };
/* Lookup the command. */ /* Lookup the command. */
if (grub_script_arglist_to_argv (cmdline->arglist, &argv)) if (grub_script_arglist_to_argv (cmdline->arglist, &argv) || ! argv.args[0])
return grub_errno; return grub_errno;
cmdname = argv.args[0]; cmdname = argv.args[0];

View file

@ -116,7 +116,7 @@ COMMENT #.*$
CHAR [^{}|&$;<> \t\n\'\"\\] CHAR [^{}|&$;<> \t\n\'\"\\]
DIGITS [[:digit:]]+ DIGITS [[:digit:]]+
NAME [[:alpha:]_][[:alnum:][:digit:]_]* NAME [[:alpha:]_][[:alnum:]_]*
ESC \\. ESC \\.
SPECIAL \?|\#|\*|\@ SPECIAL \?|\#|\*|\@

View file

@ -311,6 +311,20 @@ grub_console_setcursor (struct grub_term_output *term __attribute__ ((unused)),
efi_call_2 (o->enable_cursor, o, on); efi_call_2 (o->enable_cursor, o, on);
} }
static grub_err_t
grub_efi_console_init (struct grub_term_output *term)
{
grub_console_setcursor (term, 1);
return 0;
}
static grub_err_t
grub_efi_console_fini (struct grub_term_output *term)
{
grub_console_setcursor (term, 0);
return 0;
}
static struct grub_term_input grub_console_term_input = static struct grub_term_input grub_console_term_input =
{ {
.name = "console", .name = "console",
@ -321,6 +335,8 @@ static struct grub_term_input grub_console_term_input =
static struct grub_term_output grub_console_term_output = static struct grub_term_output grub_console_term_output =
{ {
.name = "console", .name = "console",
.init = grub_efi_console_init,
.fini = grub_efi_console_fini,
.putchar = grub_console_putchar, .putchar = grub_console_putchar,
.getwh = grub_console_getwh, .getwh = grub_console_getwh,
.getxy = grub_console_getxy, .getxy = grub_console_getxy,

View file

@ -1,4 +1,4 @@
#! /bin/bash -e #! /bin/sh -e
# Compares GRUB script output with BASH output. # Compares GRUB script output with BASH output.
# Copyright (C) 2009,2010 Free Software Foundation, Inc. # Copyright (C) 2009,2010 Free Software Foundation, Inc.
@ -84,7 +84,7 @@ done
if [ "x${source}" = x ] ; then if [ "x${source}" = x ] ; then
tmpfile=`mktemp` tmpfile=`mktemp`
while read; do while read REPLY; do
echo $REPLY >> ${tmpfile} echo $REPLY >> ${tmpfile}
done done
source=${tmpfile} source=${tmpfile}

View file

@ -467,13 +467,30 @@ clear_seen_devices (void)
} }
#ifdef __linux__ #ifdef __linux__
/* Like strcmp, but doesn't require a cast for use as a qsort comparator. */ struct device
static int
compare_file_names (const void *a, const void *b)
{ {
const char *left = *(const char **) a; char *stable;
const char *right = *(const char **) b; char *kernel;
return strcmp (left, right); };
/* Sort by the kernel name for preference since that most closely matches
older device.map files, but sort by stable by-id names as a fallback.
This is because /dev/disk/by-id/ usually has a few alternative
identifications of devices (e.g. ATA vs. SATA).
check_device_readable_unique will ensure that we only get one for any
given disk, but sort the list so that the choice of which one we get is
stable. */
static int
compare_devices (const void *a, const void *b)
{
const struct device *left = (const struct device *) a;
const struct device *right = (const struct device *) b;
int ret;
ret = strcmp (left->kernel, right->kernel);
if (ret)
return ret;
else
return strcmp (left->stable, right->stable);
} }
#endif /* __linux__ */ #endif /* __linux__ */
@ -507,10 +524,10 @@ grub_util_iterate_devices (int NESTED_FUNC_ATTR (*hook) (const char *, int),
if (dir) if (dir)
{ {
struct dirent *entry; struct dirent *entry;
char **names; struct device *devs;
size_t names_len = 0, names_max = 1024, i; size_t devs_len = 0, devs_max = 1024, i;
names = xmalloc (names_max * sizeof (*names)); devs = xmalloc (devs_max * sizeof (*devs));
/* Dump all the directory entries into names, resizing if /* Dump all the directory entries into names, resizing if
necessary. */ necessary. */
@ -526,35 +543,34 @@ grub_util_iterate_devices (int NESTED_FUNC_ATTR (*hook) (const char *, int),
/* Skip RAID entries; they are handled by upper layers. */ /* Skip RAID entries; they are handled by upper layers. */
if (strncmp (entry->d_name, "md-", sizeof ("md-") - 1) == 0) if (strncmp (entry->d_name, "md-", sizeof ("md-") - 1) == 0)
continue; continue;
if (names_len >= names_max) if (devs_len >= devs_max)
{ {
names_max *= 2; devs_max *= 2;
names = xrealloc (names, names_max * sizeof (*names)); devs = xrealloc (devs, devs_max * sizeof (*devs));
} }
names[names_len++] = xasprintf (entry->d_name); devs[devs_len].stable =
xasprintf ("/dev/disk/by-id/%s", entry->d_name);
devs[devs_len].kernel =
canonicalize_file_name (devs[devs_len].stable);
devs_len++;
} }
/* /dev/disk/by-id/ usually has a few alternative identifications of qsort (devs, devs_len, sizeof (*devs), &compare_devices);
devices (e.g. ATA vs. SATA). check_device_readable_unique will
ensure that we only get one for any given disk, but sort the list
so that the choice of which one we get is stable. */
qsort (names, names_len, sizeof (*names), &compare_file_names);
closedir (dir); closedir (dir);
/* Now add all the devices in sorted order. */ /* Now add all the devices in sorted order. */
for (i = 0; i < names_len; ++i) for (i = 0; i < devs_len; ++i)
{ {
char *path = xasprintf ("/dev/disk/by-id/%s", names[i]); if (check_device_readable_unique (devs[i].stable))
if (check_device_readable_unique (path))
{ {
if (hook (path, 0)) if (hook (devs[i].stable, 0))
goto out; goto out;
} }
free (path); free (devs[i].stable);
free (names[i]); free (devs[i].kernel);
} }
free (names); free (devs);
} }
} }

View file

@ -157,7 +157,7 @@ read_file (char *pathname, int (*hook) (grub_off_t ofs, char *buf, int len))
sz = grub_file_read (file, buf, (len > BUF_SIZE) ? BUF_SIZE : len); sz = grub_file_read (file, buf, (len > BUF_SIZE) ? BUF_SIZE : len);
if (sz < 0) if (sz < 0)
{ {
grub_util_error ("read error at offset %llu", ofs); grub_util_error ("read error at offset %llu: %s", ofs, grub_errmsg);
break; break;
} }
@ -211,7 +211,7 @@ cmd_cmp (char *src, char *dest)
{ {
if ((int) fread (buf_1, 1, len, ff) != len) if ((int) fread (buf_1, 1, len, ff) != len)
{ {
grub_util_error ("read error at offset %llu", ofs); grub_util_error ("read error at offset %llu: %s", ofs, grub_errmsg);
return 1; return 1;
} }

View file

@ -79,7 +79,7 @@ main (int argc, char **argv)
fclose (in); fclose (in);
fclose (out); fclose (out);
free (buf); free (buf);
printf ("Invalid Mach-O fle\n"); printf ("Invalid Mach-O file\n");
return 4; return 4;
} }
curcmd = (struct grub_macho_segment32 *) (buf + sizeof (*head)); curcmd = (struct grub_macho_segment32 *) (buf + sizeof (*head));

View file

@ -296,6 +296,7 @@ if test -e "${efi64_dir}" || test -e "${efi32_dir}"; then
mformat -C -f 2880 -L 16 -i "${iso9660_dir}"/efi.img :: mformat -C -f 2880 -L 16 -i "${iso9660_dir}"/efi.img ::
mcopy -s -i "${iso9660_dir}"/efi.img ${efi_dir}/efi ::/ mcopy -s -i "${iso9660_dir}"/efi.img ${efi_dir}/efi ::/
rm -rf ${efi_dir}
grub_mkisofs_arguments="${grub_mkisofs_arguments} --efi-boot efi.img" grub_mkisofs_arguments="${grub_mkisofs_arguments} --efi-boot efi.img"
fi fi

View file

@ -50,6 +50,7 @@
enum { enum {
PRINT_FS, PRINT_FS,
PRINT_FS_UUID, PRINT_FS_UUID,
PRINT_FS_LABEL,
PRINT_DRIVE, PRINT_DRIVE,
PRINT_DEVICE, PRINT_DEVICE,
PRINT_PARTMAP, PRINT_PARTMAP,
@ -291,6 +292,16 @@ probe (const char *path, char *device_name)
printf ("%s\n", uuid); printf ("%s\n", uuid);
} }
else if (print == PRINT_FS_LABEL)
{
char *label;
if (! fs->label)
grub_util_error ("%s does not support labels", fs->name);
fs->label (dev, &label);
printf ("%s\n", label);
}
end: end:
if (dev) if (dev)
@ -326,7 +337,7 @@ Probe device information for a given path (or device, if the -d option is given)
\n\ \n\
-d, --device given argument is a system device, not a path\n\ -d, --device given argument is a system device, not a path\n\
-m, --device-map=FILE use FILE as the device map [default=%s]\n\ -m, --device-map=FILE use FILE as the device map [default=%s]\n\
-t, --target=(fs|fs_uuid|drive|device|partmap|abstraction)\n\ -t, --target=(fs|fs_uuid|fs_label|drive|device|partmap|abstraction)\n\
print filesystem module, GRUB drive, system device, partition map module or abstraction module [default=fs]\n\ print filesystem module, GRUB drive, system device, partition map module or abstraction module [default=fs]\n\
-h, --help display this message and exit\n\ -h, --help display this message and exit\n\
-V, --version print version information and exit\n\ -V, --version print version information and exit\n\
@ -375,6 +386,8 @@ main (int argc, char *argv[])
print = PRINT_FS; print = PRINT_FS;
else if (!strcmp (optarg, "fs_uuid")) else if (!strcmp (optarg, "fs_uuid"))
print = PRINT_FS_UUID; print = PRINT_FS_UUID;
else if (!strcmp (optarg, "fs_label"))
print = PRINT_FS_LABEL;
else if (!strcmp (optarg, "drive")) else if (!strcmp (optarg, "drive"))
print = PRINT_DRIVE; print = PRINT_DRIVE;
else if (!strcmp (optarg, "device")) else if (!strcmp (optarg, "device"))

View file

@ -73,7 +73,6 @@ grub_script_shift (grub_command_t cmd __attribute__((unused)),
return 0; return 0;
} }
char * char *
grub_script_execute_argument_to_string (struct grub_script_arg *arg __attribute__ ((unused))) grub_script_execute_argument_to_string (struct grub_script_arg *arg __attribute__ ((unused)))
{ {

View file

@ -137,11 +137,7 @@ case x${GRUB_TERMINAL_INPUT} in
;; ;;
x*) x*)
cat << EOF cat << EOF
if terminal_input ${GRUB_TERMINAL_INPUT} ; then true ; else terminal_input ${GRUB_TERMINAL_INPUT}
# For backward compatibility with versions of terminal.mod that don't
# understand terminal_input
terminal ${GRUB_TERMINAL_INPUT}
fi
EOF EOF
;; ;;
esac esac
@ -152,11 +148,7 @@ case x${GRUB_TERMINAL_OUTPUT} in
;; ;;
x*) x*)
cat << EOF cat << EOF
if terminal_output ${GRUB_TERMINAL_OUTPUT} ; then true ; else terminal_output ${GRUB_TERMINAL_OUTPUT}
# For backward compatibility with versions of terminal.mod that don't
# understand terminal_output
terminal ${GRUB_TERMINAL_OUTPUT}
fi
EOF EOF
;; ;;
esac esac

View file

@ -51,6 +51,10 @@ kfreebsd_entry ()
if [ -z "${prepare_boot_cache}" ]; then if [ -z "${prepare_boot_cache}" ]; then
prepare_boot_cache="$(prepare_grub_to_access_device ${GRUB_DEVICE_BOOT} | sed -e "s/^/\t/")" prepare_boot_cache="$(prepare_grub_to_access_device ${GRUB_DEVICE_BOOT} | sed -e "s/^/\t/")"
fi fi
if [ -z "${prepare_module_dir_cache}" ]; then
prepare_module_dir_cache="$(prepare_grub_to_access_device $(grub-probe -t device "${module_dir}") | sed -e "s/^/\t/")"
fi
printf '%s\n' "${prepare_boot_cache}" printf '%s\n' "${prepare_boot_cache}"
cat << EOF cat << EOF
echo '$(printf "$(gettext_quoted "Loading kernel of FreeBSD %s ...")" ${version})' echo '$(printf "$(gettext_quoted "Loading kernel of FreeBSD %s ...")" ${version})'
@ -63,14 +67,35 @@ EOF
EOF EOF
fi fi
if test -n "${acpi_ko}" ; then if test -e "${module_dir}/acpi.ko" ; then
printf '%s\n' "${prepare_module_dir_cache}"
cat << EOF cat << EOF
kfreebsd_module_elf ${acpi_ko_rel_dirname}/${acpi_ko_basename} kfreebsd_module_elf ${module_dir_rel}/acpi.ko
EOF EOF
fi fi
case "${kfreebsd_fs}" in
zfs)
for i in "${module_dir}/opensolaris.ko" "${module_dir}/zfs.ko" \
"${dirname}/zfs/zpool.cache" ; do
ls "$i" > /dev/null
done
printf '%s\n' "${prepare_module_dir_cache}"
cat << EOF cat << EOF
set kFreeBSD.vfs.root.mountfrom=${kfreebsd_fs}:${GRUB_DEVICE} kfreebsd_module_elf ${module_dir_rel}/opensolaris.ko
kfreebsd_module_elf ${module_dir_rel}/zfs.ko
EOF
printf '%s\n' "${prepare_boot_cache}"
cat << EOF
kfreebsd_module ${rel_dirname}/zfs/zpool.cache type=/boot/zfs/zpool.cache
EOF
;;
esac
cat << EOF
set kFreeBSD.vfs.root.mountfrom=${kfreebsd_fs}:${kfreebsd_device}
set kFreeBSD.vfs.root.mountfrom.options=rw set kFreeBSD.vfs.root.mountfrom.options=rw
} }
EOF EOF
@ -100,22 +125,25 @@ while [ "x$list" != "x" ] ; do
*) kfreebsd_fs=${GRUB_FS} ;; *) kfreebsd_fs=${GRUB_FS} ;;
esac esac
case ${GRUB_FS} in
zfs) kfreebsd_device=$(grub-probe -t fs_label --device ${GRUB_DEVICE}) ;;
*) kfreebsd_device=${GRUB_DEVICE} ;;
esac
version=`echo $basename | sed -e "s,^[^0-9]*-,,g;s/\.gz$//g"` version=`echo $basename | sed -e "s,^[^0-9]*-,,g;s/\.gz$//g"`
alt_version=`echo $version | sed -e "s,\.old$,,g"` alt_version=`echo $version | sed -e "s,\.old$,,g"`
acpi_ko= module_dir=
for i in "/lib/modules/${version}/acpi.ko" "/lib/modules/${alt_version}/acpi.ko" \ for i in "/lib/modules/${version}" "/lib/modules/${alt_version}" \
"/boot/kernel/acpi.ko"; do "/boot/kernel"; do
if test -e "$i" ; then if test -e "$i" ; then
acpi_ko="$i" module_dir="$i"
break break
fi fi
done done
if test -n "${acpi_ko}" ; then if test -n "${module_dir}" ; then
echo "Found ACPI module: ${acpi_ko}" >&2 echo "Found kernel module directory: ${module_dir}" >&2
acpi_ko_basename=`basename ${acpi_ko}` module_dir_rel=$(make_system_path_relative_to_its_root $module_dir)
acpi_ko_dirname=`dirname ${acpi_ko}`
acpi_ko_rel_dirname=`make_system_path_relative_to_its_root $acpi_ko_dirname`
fi fi
kfreebsd_entry "${OS}" "${version}" kfreebsd_entry "${OS}" "${version}"

View file

@ -44,7 +44,8 @@ case ${GRUB_DEVICE} in
esac esac
if [ "x${GRUB_DEVICE_UUID}" = "x" ] || [ "x${GRUB_DISABLE_LINUX_UUID}" = "xtrue" ] \ if [ "x${GRUB_DEVICE_UUID}" = "x" ] || [ "x${GRUB_DISABLE_LINUX_UUID}" = "xtrue" ] \
|| ! test -e "/dev/disk/by-uuid/${GRUB_DEVICE_UUID}" ; then || ! test -e "/dev/disk/by-uuid/${GRUB_DEVICE_UUID}" \
|| uses_abstraction "${GRUB_DEVICE}" lvm; then
LINUX_ROOT_DEVICE=${GRUB_DEVICE} LINUX_ROOT_DEVICE=${GRUB_DEVICE}
else else
LINUX_ROOT_DEVICE=UUID=${GRUB_DEVICE_UUID} LINUX_ROOT_DEVICE=UUID=${GRUB_DEVICE_UUID}

View file

@ -246,7 +246,7 @@ devabstraction_module=`$grub_probe --target=abstraction --device-map=${device_ma
# The order in this list is critical. Be careful when modifying it. # The order in this list is critical. Be careful when modifying it.
modules="$modules $fs_module $partmap_module $devabstraction_module" modules="$modules $fs_module $partmap_module $devabstraction_module"
$grub_mkimage -O ${target_cpu}-efi --output=${grubdir}/grub.efi $modules || exit 1 $grub_mkimage -p "" -O ${target_cpu}-efi --output=${grubdir}/grub.efi $modules || exit 1
# Prompt the user to check if the device map is correct. # Prompt the user to check if the device map is correct.
echo "Installation finished. No error reported." echo "Installation finished. No error reported."

View file

@ -812,14 +812,14 @@ main (int argc, char *argv[])
must_embed = 1; must_embed = 1;
if (root_dev[0] == 'm' && root_dev[1] == 'd' if (root_dev[0] == 'm' && root_dev[1] == 'd'
&& root_dev[2] >= '0' && root_dev[2] <= '9') && ((root_dev[2] >= '0' && root_dev[2] <= '9') || root_dev[2] == '/'))
{ {
/* FIXME: we can avoid this on RAID1. */ /* FIXME: we can avoid this on RAID1. */
must_embed = 1; must_embed = 1;
} }
if (dest_dev[0] == 'm' && dest_dev[1] == 'd' if (dest_dev[0] == 'm' && dest_dev[1] == 'd'
&& dest_dev[2] >= '0' && dest_dev[2] <= '9') && ((dest_dev[2] >= '0' && dest_dev[2] <= '9') || dest_dev[2] == '/'))
{ {
char **devicelist; char **devicelist;
int i; int i;

View file

@ -212,7 +212,7 @@ fi
# this command is allowed to fail (--target=fs already grants us that the # this command is allowed to fail (--target=fs already grants us that the
# filesystem will be accessible). # filesystem will be accessible).
partmap_module= partmap_module=
for x in `$grub_probe --target=partmap --device ${grub_device} 2> /dev/null`; do for x in `$grub_probe --target=partmap --device-map=${device_map} ${grubdir} 2> /dev/null`; do
partmap_module="$partmap_module part_$x"; partmap_module="$partmap_module part_$x";
done done

View file

@ -18,8 +18,6 @@
import re import re
import sys import sys
import os
import datetime
if len (sys.argv) < 3: if len (sys.argv) < 3:
print ("Usage: %s SOURCE DESTINATION" % sys.argv[0]) print ("Usage: %s SOURCE DESTINATION" % sys.argv[0])

View file

@ -293,7 +293,8 @@ grub_util_init_nls (void)
textdomain (PACKAGE); textdomain (PACKAGE);
#endif /* (defined(ENABLE_NLS) && ENABLE_NLS) */ #endif /* (defined(ENABLE_NLS) && ENABLE_NLS) */
} }
#endif
#endif /* GRUB_UTIL */
int int
grub_dl_ref (grub_dl_t mod) grub_dl_ref (grub_dl_t mod)

View file

@ -334,10 +334,15 @@ grub_video_cirrus_setup (unsigned int width, unsigned int height,
} }
{ {
int pitch_reg, overflow_reg = 0, line_compare = 0x3ff; struct grub_video_hw_config config = {
.pitch = pitch / GRUB_VGA_CR_PITCH_DIVISOR,
.line_compare = 0x3ff,
.vdisplay_end = height - 1,
.horizontal_end = width / GRUB_VGA_CR_WIDTH_DIVISOR
};
grub_uint8_t sr_ext = 0, hidden_dac = 0; grub_uint8_t sr_ext = 0, hidden_dac = 0;
pitch_reg = pitch / GRUB_VGA_CR_PITCH_DIVISOR; grub_vga_set_geometry (&config, grub_vga_cr_write);
grub_vga_gr_write (GRUB_VGA_GR_MODE_256_COLOR | GRUB_VGA_GR_MODE_READ_MODE1, grub_vga_gr_write (GRUB_VGA_GR_MODE_256_COLOR | GRUB_VGA_GR_MODE_READ_MODE1,
GRUB_VGA_GR_MODE); GRUB_VGA_GR_MODE);
@ -345,32 +350,10 @@ grub_video_cirrus_setup (unsigned int width, unsigned int height,
grub_vga_sr_write (GRUB_VGA_SR_MEMORY_MODE_NORMAL, GRUB_VGA_SR_MEMORY_MODE); grub_vga_sr_write (GRUB_VGA_SR_MEMORY_MODE_NORMAL, GRUB_VGA_SR_MEMORY_MODE);
/* Disable CR0-7 write protection. */ grub_vga_cr_write ((config.pitch >> CIRRUS_CR_EXTENDED_DISPLAY_PITCH_SHIFT)
grub_vga_cr_write (0, GRUB_VGA_CR_VSYNC_END);
grub_vga_cr_write (width / GRUB_VGA_CR_WIDTH_DIVISOR - 1,
GRUB_VGA_CR_WIDTH);
grub_vga_cr_write ((height - 1) & 0xff, GRUB_VGA_CR_HEIGHT);
overflow_reg |= (((height - 1) >> GRUB_VGA_CR_OVERFLOW_HEIGHT1_SHIFT) &
GRUB_VGA_CR_OVERFLOW_HEIGHT1_MASK)
| (((height - 1) >> GRUB_VGA_CR_OVERFLOW_HEIGHT2_SHIFT) &
GRUB_VGA_CR_OVERFLOW_HEIGHT2_MASK);
grub_vga_cr_write (pitch_reg & 0xff, GRUB_VGA_CR_PITCH);
grub_vga_cr_write (line_compare & 0xff, GRUB_VGA_CR_LINE_COMPARE);
overflow_reg |= (line_compare >> GRUB_VGA_CR_OVERFLOW_LINE_COMPARE_SHIFT)
& GRUB_VGA_CR_OVERFLOW_LINE_COMPARE_MASK;
grub_vga_cr_write (overflow_reg, GRUB_VGA_CR_OVERFLOW);
grub_vga_cr_write ((pitch_reg >> CIRRUS_CR_EXTENDED_DISPLAY_PITCH_SHIFT)
& CIRRUS_CR_EXTENDED_DISPLAY_PITCH_MASK, & CIRRUS_CR_EXTENDED_DISPLAY_PITCH_MASK,
CIRRUS_CR_EXTENDED_DISPLAY); CIRRUS_CR_EXTENDED_DISPLAY);
grub_vga_cr_write ((line_compare >> GRUB_VGA_CR_CELL_HEIGHT_LINE_COMPARE_SHIFT)
& GRUB_VGA_CR_CELL_HEIGHT_LINE_COMPARE_MASK, GRUB_VGA_CR_CELL_HEIGHT);
grub_vga_cr_write (GRUB_VGA_CR_MODE_TIMING_ENABLE grub_vga_cr_write (GRUB_VGA_CR_MODE_TIMING_ENABLE
| GRUB_VGA_CR_MODE_BYTE_MODE | GRUB_VGA_CR_MODE_BYTE_MODE
| GRUB_VGA_CR_MODE_NO_HERCULES | GRUB_VGA_CR_MODE_NO_CGA, | GRUB_VGA_CR_MODE_NO_HERCULES | GRUB_VGA_CR_MODE_NO_CGA,

View file

@ -26,10 +26,168 @@
#include <grub/video.h> #include <grub/video.h>
#include <grub/video_fb.h> #include <grub/video_fb.h>
#include <grub/pci.h> #include <grub/pci.h>
#include <grub/vga.h>
#include "sm712_init.c" #include "sm712_init.c"
#define GRUB_SM712_TOTAL_MEMORY_SPACE 0x700400 #define GRUB_SM712_TOTAL_MEMORY_SPACE 0x700400
#define GRUB_SM712_REG_BASE 0x700000
#define GRUB_SM712_PCIID 0x0712126f
enum
{
GRUB_SM712_SR_TV_CONTROL = 0x65,
GRUB_SM712_SR_RAM_LUT = 0x66,
GRUB_SM712_SR_CLOCK_CONTROL1 = 0x68,
GRUB_SM712_SR_CLOCK_CONTROL2 = 0x69,
GRUB_SM712_SR_VCLK_NUM = 0x6c,
GRUB_SM712_SR_VCLK_DENOM = 0x6d,
GRUB_SM712_SR_VCLK2_NUM = 0x6e,
GRUB_SM712_SR_VCLK2_DENOM = 0x6f,
GRUB_SM712_SR_POPUP_ICON_LOW = 0x80,
GRUB_SM712_SR_POPUP_ICON_HIGH = 0x81,
GRUB_SM712_SR_POPUP_ICON_CTRL = 0x82,
GRUB_SM712_SR_POPUP_ICON_COLOR1 = 0x84,
GRUB_SM712_SR_POPUP_ICON_COLOR2 = 0x85,
GRUB_SM712_SR_POPUP_ICON_COLOR3 = 0x86,
GRUB_SM712_SR_HW_CURSOR_UPPER_LEFT_X_LOW = 0x88,
GRUB_SM712_SR_HW_CURSOR_UPPER_LEFT_X_HIGH = 0x89,
GRUB_SM712_SR_HW_CURSOR_UPPER_LEFT_Y_LOW = 0x8a,
GRUB_SM712_SR_HW_CURSOR_UPPER_LEFT_Y_HIGH = 0x8b,
GRUB_SM712_SR_HW_CURSOR_FG_COLOR = 0x8c,
GRUB_SM712_SR_HW_CURSOR_BG_COLOR = 0x8d,
GRUB_SM712_SR_POPUP_ICON_X_LOW = 0x90,
GRUB_SM712_SR_POPUP_ICON_X_HIGH = 0x91,
GRUB_SM712_SR_POPUP_ICON_Y_LOW = 0x92,
GRUB_SM712_SR_POPUP_ICON_Y_HIGH = 0x93,
GRUB_SM712_SR_PANEL_HW_VIDEO_CONTROL = 0xa0,
GRUB_SM712_SR_PANEL_HW_VIDEO_COLOR_KEY_LOW = 0xa1,
GRUB_SM712_SR_PANEL_HW_VIDEO_COLOR_KEY_HIGH = 0xa2,
GRUB_SM712_SR_PANEL_HW_VIDEO_COLOR_KEY_MASK_LOW = 0xa3,
GRUB_SM712_SR_PANEL_HW_VIDEO_COLOR_KEY_MASK_HIGH = 0xa4,
GRUB_SM712_SR_PANEL_HW_VIDEO_RED_CONSTANT = 0xa5,
GRUB_SM712_SR_PANEL_HW_VIDEO_GREEN_CONSTANT = 0xa6,
GRUB_SM712_SR_PANEL_HW_VIDEO_BLUE_CONSTANT = 0xa7,
GRUB_SM712_SR_PANEL_HW_VIDEO_TOP_BOUNDARY = 0xa8,
GRUB_SM712_SR_PANEL_HW_VIDEO_LEFT_BOUNDARY = 0xa9,
GRUB_SM712_SR_PANEL_HW_VIDEO_BOTTOM_BOUNDARY = 0xaa,
GRUB_SM712_SR_PANEL_HW_VIDEO_RIGHT_BOUNDARY = 0xab,
GRUB_SM712_SR_PANEL_HW_VIDEO_TOP_LEFT_OVERFLOW_BOUNDARY = 0xac,
GRUB_SM712_SR_PANEL_HW_VIDEO_BOTTOM_RIGHT_OVERFLOW_BOUNDARY = 0xad,
GRUB_SM712_SR_PANEL_HW_VIDEO_VERTICAL_STRETCH_FACTOR = 0xae,
GRUB_SM712_SR_PANEL_HW_VIDEO_HORIZONTAL_STRETCH_FACTOR = 0xaf,
};
enum
{
GRUB_SM712_SR_TV_CRT_SRAM = 0x00,
GRUB_SM712_SR_TV_LCD_SRAM = 0x08
};
enum
{
GRUB_SM712_SR_TV_ALT_CLOCK = 0x00,
GRUB_SM712_SR_TV_FREE_RUN_CLOCK = 0x04
};
enum
{
GRUB_SM712_SR_TV_CLOCK_CKIN_NTSC = 0x00,
GRUB_SM712_SR_TV_CLOCK_REFCLK_PAL = 0x04
};
enum
{
GRUB_SM712_SR_TV_HSYNC = 0x00,
GRUB_SM712_SR_TV_COMPOSITE_HSYNC = 0x01
};
enum
{
GRUB_SM712_SR_RAM_LUT_NORMAL = 0,
GRUB_SM712_SR_RAM_LUT_LCD_RAM_OFF = 0x80,
GRUB_SM712_SR_RAM_LUT_CRT_RAM_OFF = 0x40,
GRUB_SM712_SR_RAM_LUT_LCD_RAM_NO_WRITE = 0x20,
GRUB_SM712_SR_RAM_LUT_CRT_RAM_NO_WRITE = 0x10,
GRUB_SM712_SR_RAM_LUT_CRT_8BIT = 0x08,
GRUB_SM712_SR_RAM_LUT_CRT_GAMMA = 0x04
};
enum
{
GRUB_SM712_SR_CLOCK_CONTROL1_VCLK_FROM_CCR = 0x40,
GRUB_SM712_SR_CLOCK_CONTROL1_8DOT_CLOCK = 0x10,
};
enum
{
GRUB_SM712_SR_CLOCK_CONTROL2_PROGRAM_VCLOCK = 0x03
};
#define GRUB_SM712_SR_POPUP_ICON_HIGH_MASK 0x7
#define GRUB_SM712_SR_POPUP_ICON_HIGH_HW_CURSOR_EN 0x80
enum
{
GRUB_SM712_SR_POPUP_ICON_CTRL_DISABLED = 0,
GRUB_SM712_SR_POPUP_ICON_CTRL_ZOOM_ENABLED = 0x40,
GRUB_SM712_SR_POPUP_ICON_CTRL_ENABLED = 0x80
};
#define RGB332_BLACK 0
#define RGB332_WHITE 0xff
enum
{
GRUB_SM712_CR_OVERFLOW_INTERLACE = 0x30,
GRUB_SM712_CR_INTERLACE_RETRACE = 0x31,
GRUB_SM712_CR_TV_VDISPLAY_START = 0x32,
GRUB_SM712_CR_TV_VDISPLAY_END_HIGH = 0x33,
GRUB_SM712_CR_TV_VDISPLAY_END_LOW = 0x34,
GRUB_SM712_CR_DDA_CONTROL_LOW = 0x35,
GRUB_SM712_CR_DDA_CONTROL_HIGH = 0x36,
GRUB_SM712_CR_TV_EQUALIZER = 0x38,
GRUB_SM712_CR_TV_SERRATION = 0x39,
GRUB_SM712_CR_HSYNC_CTRL = 0x3a,
GRUB_SM712_CR_DEBUG = 0x3c,
GRUB_SM712_CR_SHADOW_VGA_HTOTAL = 0x40,
GRUB_SM712_CR_SHADOW_VGA_HBLANK_START = 0x41,
GRUB_SM712_CR_SHADOW_VGA_HBLANK_END = 0x42,
GRUB_SM712_CR_SHADOW_VGA_HRETRACE_START = 0x43,
GRUB_SM712_CR_SHADOW_VGA_HRETRACE_END = 0x44,
GRUB_SM712_CR_SHADOW_VGA_VERTICAL_TOTAL = 0x45,
GRUB_SM712_CR_SHADOW_VGA_VBLANK_START = 0x46,
GRUB_SM712_CR_SHADOW_VGA_VBLANK_END = 0x47,
GRUB_SM712_CR_SHADOW_VGA_VRETRACE_START = 0x48,
GRUB_SM712_CR_SHADOW_VGA_VRETRACE_END = 0x49,
GRUB_SM712_CR_SHADOW_VGA_OVERFLOW = 0x4a,
GRUB_SM712_CR_SHADOW_VGA_CELL_HEIGHT = 0x4b,
GRUB_SM712_CR_SHADOW_VGA_HDISPLAY_END = 0x4c,
GRUB_SM712_CR_SHADOW_VGA_VDISPLAY_END = 0x4d,
GRUB_SM712_CR_DDA_LOOKUP_REG3_START = 0x90,
GRUB_SM712_CR_DDA_LOOKUP_REG2_START = 0x91,
GRUB_SM712_CR_DDA_LOOKUP_REG1_START = 0xa0,
GRUB_SM712_CR_VCENTERING_OFFSET = 0xa6,
GRUB_SM712_CR_HCENTERING_OFFSET = 0xa7,
};
#define GRUB_SM712_CR_DEBUG_NONE 0
#define SM712_DDA_REG3_COMPARE_SHIFT 2
#define SM712_DDA_REG3_COMPARE_MASK 0xfc
#define SM712_DDA_REG3_DDA_SHIFT 8
#define SM712_DDA_REG3_DDA_MASK 0x3
#define SM712_DDA_REG2_DDA_MASK 0xff
#define SM712_DDA_REG2_VCENTER_MASK 0x3f
static struct
{
grub_uint8_t compare;
grub_uint16_t dda;
grub_uint8_t vcentering;
} dda_lookups[] = {
{ 21, 469, 2},
{ 23, 477, 2},
{ 33, 535, 2},
{ 35, 682, 21},
{ 34, 675, 2},
{ 55, 683, 6},
};
static struct static struct
{ {
@ -42,6 +200,7 @@ static struct
grub_pci_device_t dev; grub_pci_device_t dev;
} framebuffer; } framebuffer;
#ifndef TEST
static grub_err_t static grub_err_t
grub_video_sm712_video_init (void) grub_video_sm712_video_init (void)
{ {
@ -60,6 +219,118 @@ grub_video_sm712_video_fini (void)
return grub_video_fb_fini (); return grub_video_fb_fini ();
} }
#endif
static inline void
grub_sm712_write_reg (grub_uint8_t val, grub_uint16_t addr)
{
#ifdef TEST
printf (" {1, 0x%x, 0x%x},\n", addr, val);
#else
*(volatile grub_uint8_t *) (framebuffer.ptr + GRUB_SM712_REG_BASE
+ addr) = val;
#endif
}
static inline grub_uint8_t
grub_sm712_read_reg (grub_uint16_t addr)
{
#ifdef TEST
printf (" {-1, 0x%x, 0x5},\n", addr);
#else
return *(volatile grub_uint8_t *) (framebuffer.ptr + GRUB_SM712_REG_BASE
+ addr);
#endif
}
static inline grub_uint8_t
grub_sm712_sr_read (grub_uint8_t addr)
{
grub_sm712_write_reg (addr, GRUB_VGA_IO_SR_INDEX);
return grub_sm712_read_reg (GRUB_VGA_IO_SR_DATA);
}
static inline void
grub_sm712_sr_write (grub_uint8_t val, grub_uint8_t addr)
{
grub_sm712_write_reg (addr, GRUB_VGA_IO_SR_INDEX);
grub_sm712_write_reg (val, GRUB_VGA_IO_SR_DATA);
}
static inline void
grub_sm712_gr_write (grub_uint8_t val, grub_uint8_t addr)
{
grub_sm712_write_reg (addr, GRUB_VGA_IO_GR_INDEX);
grub_sm712_write_reg (val, GRUB_VGA_IO_GR_DATA);
}
static inline void
grub_sm712_cr_write (grub_uint8_t val, grub_uint8_t addr)
{
grub_sm712_write_reg (addr, GRUB_VGA_IO_CR_INDEX);
grub_sm712_write_reg (val, GRUB_VGA_IO_CR_DATA);
}
static inline void
grub_sm712_write_arx (grub_uint8_t val, grub_uint8_t addr)
{
grub_sm712_read_reg (GRUB_VGA_IO_INPUT_STATUS1_REGISTER);
grub_sm712_write_reg (addr, GRUB_VGA_IO_ARX);
grub_sm712_read_reg (GRUB_VGA_IO_ARX_READ);
grub_sm712_write_reg (val, GRUB_VGA_IO_ARX);
}
static inline void
grub_sm712_cr_shadow_write (grub_uint8_t val, grub_uint8_t addr)
{
grub_uint8_t mapping[] =
{
[GRUB_VGA_CR_HTOTAL] = GRUB_SM712_CR_SHADOW_VGA_HTOTAL,
[GRUB_VGA_CR_HORIZ_END] = 0xff,
[GRUB_VGA_CR_HBLANK_START] = GRUB_SM712_CR_SHADOW_VGA_HBLANK_START,
[GRUB_VGA_CR_HBLANK_END] = GRUB_SM712_CR_SHADOW_VGA_HBLANK_END,
[GRUB_VGA_CR_HORIZ_SYNC_PULSE_START] = GRUB_SM712_CR_SHADOW_VGA_HRETRACE_START,
[GRUB_VGA_CR_HORIZ_SYNC_PULSE_END] = GRUB_SM712_CR_SHADOW_VGA_HRETRACE_END,
[GRUB_VGA_CR_VERT_TOTAL] = GRUB_SM712_CR_SHADOW_VGA_VERTICAL_TOTAL,
[GRUB_VGA_CR_OVERFLOW] = GRUB_SM712_CR_SHADOW_VGA_OVERFLOW,
[GRUB_VGA_CR_BYTE_PANNING] = 0xff,
[GRUB_VGA_CR_CELL_HEIGHT] = GRUB_SM712_CR_SHADOW_VGA_CELL_HEIGHT,
[GRUB_VGA_CR_CURSOR_START] = 0xff,
[GRUB_VGA_CR_CURSOR_END] = 0xff,
[GRUB_VGA_CR_START_ADDR_HIGH_REGISTER] = 0xff,
[GRUB_VGA_CR_START_ADDR_LOW_REGISTER] = 0xff,
[GRUB_VGA_CR_CURSOR_ADDR_HIGH] = 0xff,
[GRUB_VGA_CR_CURSOR_ADDR_LOW] = 0xff,
[GRUB_VGA_CR_VSYNC_START] = GRUB_SM712_CR_SHADOW_VGA_VRETRACE_START,
[GRUB_VGA_CR_VSYNC_END] = GRUB_SM712_CR_SHADOW_VGA_VRETRACE_END,
[GRUB_VGA_CR_VDISPLAY_END] = GRUB_SM712_CR_SHADOW_VGA_VDISPLAY_END,
[GRUB_VGA_CR_PITCH] = GRUB_SM712_CR_SHADOW_VGA_HDISPLAY_END,
[GRUB_VGA_CR_UNDERLINE_LOCATION] = 0xff,
[GRUB_VGA_CR_VERTICAL_BLANK_START] = GRUB_SM712_CR_SHADOW_VGA_VBLANK_START,
[GRUB_VGA_CR_VERTICAL_BLANK_END] = GRUB_SM712_CR_SHADOW_VGA_VBLANK_END,
[GRUB_VGA_CR_MODE] = 0xff,
[GRUB_VGA_CR_LINE_COMPARE] = 0xff
};
if (addr >= ARRAY_SIZE (mapping) || mapping[addr] == 0xff)
return;
grub_sm712_cr_write (val, mapping[addr]);
}
static inline void
grub_sm712_write_dda_lookup (int idx, grub_uint8_t compare, grub_uint16_t dda,
grub_uint8_t vcentering)
{
grub_sm712_cr_write (((compare << SM712_DDA_REG3_COMPARE_SHIFT)
& SM712_DDA_REG3_COMPARE_MASK)
| ((dda >> SM712_DDA_REG3_DDA_SHIFT)
& SM712_DDA_REG3_DDA_MASK),
GRUB_SM712_CR_DDA_LOOKUP_REG3_START + 2 * idx);
grub_sm712_cr_write (dda & SM712_DDA_REG2_DDA_MASK,
GRUB_SM712_CR_DDA_LOOKUP_REG2_START + 2 * idx);
grub_sm712_cr_write (vcentering & SM712_DDA_REG2_VCENTER_MASK,
GRUB_SM712_CR_DDA_LOOKUP_REG1_START + idx);
}
static grub_err_t static grub_err_t
grub_video_sm712_setup (unsigned int width, unsigned int height, grub_video_sm712_setup (unsigned int width, unsigned int height,
@ -70,6 +341,7 @@ grub_video_sm712_setup (unsigned int width, unsigned int height,
int found = 0; int found = 0;
unsigned i; unsigned i;
#ifndef TEST
auto int NESTED_FUNC_ATTR find_card (grub_pci_device_t dev, grub_pci_id_t pciid __attribute__ ((unused))); auto int NESTED_FUNC_ATTR find_card (grub_pci_device_t dev, grub_pci_id_t pciid __attribute__ ((unused)));
int NESTED_FUNC_ATTR find_card (grub_pci_device_t dev, grub_pci_id_t pciid __attribute__ ((unused))) int NESTED_FUNC_ATTR find_card (grub_pci_device_t dev, grub_pci_id_t pciid __attribute__ ((unused)))
{ {
@ -79,7 +351,8 @@ grub_video_sm712_setup (unsigned int width, unsigned int height,
addr = grub_pci_make_address (dev, GRUB_PCI_REG_CLASS); addr = grub_pci_make_address (dev, GRUB_PCI_REG_CLASS);
class = grub_pci_read (addr); class = grub_pci_read (addr);
if (((class >> 16) & 0xffff) != 0x0300 || pciid != 0x0712126f) if (((class >> 16) & 0xffff) != GRUB_PCI_CLASS_SUBCLASS_VGA
|| pciid != GRUB_SM712_PCIID)
return 0; return 0;
found = 1; found = 1;
@ -103,7 +376,7 @@ grub_video_sm712_setup (unsigned int width, unsigned int height,
grub_pci_iterate (find_card); grub_pci_iterate (find_card);
if (!found) if (!found)
return grub_error (GRUB_ERR_IO, "Couldn't find graphics card"); return grub_error (GRUB_ERR_IO, "Couldn't find graphics card");
#endif
/* Fill mode info details. */ /* Fill mode info details. */
framebuffer.mode_info.width = 1024; framebuffer.mode_info.width = 1024;
framebuffer.mode_info.height = 600; framebuffer.mode_info.height = 600;
@ -120,8 +393,12 @@ grub_video_sm712_setup (unsigned int width, unsigned int height,
framebuffer.mode_info.blue_field_pos = 0; framebuffer.mode_info.blue_field_pos = 0;
framebuffer.mode_info.reserved_mask_size = 0; framebuffer.mode_info.reserved_mask_size = 0;
framebuffer.mode_info.reserved_field_pos = 0; framebuffer.mode_info.reserved_field_pos = 0;
framebuffer.mode_info.blit_format = grub_video_get_blit_format (&framebuffer.mode_info); #ifndef TEST
framebuffer.mode_info.blit_format
= grub_video_get_blit_format (&framebuffer.mode_info);
#endif
#ifndef TEST
if (found && framebuffer.base == 0) if (found && framebuffer.base == 0)
{ {
grub_pci_address_t addr; grub_pci_address_t addr;
@ -139,47 +416,280 @@ grub_video_sm712_setup (unsigned int width, unsigned int height,
addr = grub_pci_make_address (framebuffer.dev, GRUB_PCI_REG_COMMAND); addr = grub_pci_make_address (framebuffer.dev, GRUB_PCI_REG_COMMAND);
grub_pci_write (addr, 0x7); grub_pci_write (addr, 0x7);
} }
#endif
/* We can safely discard volatile attribute. */ /* We can safely discard volatile attribute. */
#ifndef TEST
framebuffer.ptr framebuffer.ptr
= (void *) grub_pci_device_map_range (framebuffer.dev, = (void *) grub_pci_device_map_range (framebuffer.dev,
framebuffer.base, framebuffer.base,
GRUB_SM712_TOTAL_MEMORY_SPACE); GRUB_SM712_TOTAL_MEMORY_SPACE);
#endif
framebuffer.mapped = 1; framebuffer.mapped = 1;
/* Initialise SM712. */ /* Initialise SM712. */
grub_outb (0x18, GRUB_MACHINE_PCI_IO_BASE + 0x3c4); #ifndef TEST
grub_outb (0x11, GRUB_MACHINE_PCI_IO_BASE + 0x3c5); /* FIXME */
grub_vga_sr_write (0x11, 0x18);
#endif
#ifndef TEST
/* Prevent garbage from appearing on the screen. */ /* Prevent garbage from appearing on the screen. */
grub_memset (framebuffer.ptr, 0, grub_memset (framebuffer.ptr, 0,
framebuffer.mode_info.height * framebuffer.mode_info.pitch); framebuffer.mode_info.height * framebuffer.mode_info.pitch);
#endif
for (i = 0; i < ARRAY_SIZE (sm712_init); i++) /* FIXME */
switch (sm712_init[i].directive) grub_sm712_sr_write (0, 0x21);
grub_sm712_sr_write (0x7a, 0x62);
grub_sm712_sr_write (0x16, 0x6a);
grub_sm712_sr_write (0x2, 0x6b);
grub_sm712_write_reg (0, GRUB_VGA_IO_PIXEL_MASK);
grub_sm712_sr_write (GRUB_VGA_SR_RESET_ASYNC, GRUB_VGA_SR_RESET);
grub_sm712_write_reg (GRUB_VGA_IO_MISC_NEGATIVE_VERT_POLARITY
| GRUB_VGA_IO_MISC_NEGATIVE_HORIZ_POLARITY
| GRUB_VGA_IO_MISC_UPPER_64K
| GRUB_VGA_IO_MISC_EXTERNAL_CLOCK_0
| GRUB_VGA_IO_MISC_ENABLE_VRAM_ACCESS
| GRUB_VGA_IO_MISC_COLOR, GRUB_VGA_IO_MISC_WRITE);
grub_sm712_sr_write (GRUB_VGA_SR_RESET_ASYNC | GRUB_VGA_SR_RESET_SYNC,
GRUB_VGA_SR_RESET);
grub_sm712_sr_write (GRUB_VGA_SR_CLOCKING_MODE_8_DOT_CLOCK,
GRUB_VGA_SR_CLOCKING_MODE);
grub_sm712_sr_write (GRUB_VGA_ALL_PLANES, GRUB_VGA_SR_MAP_MASK_REGISTER);
grub_sm712_sr_write (0, GRUB_VGA_SR_CHAR_MAP_SELECT);
grub_sm712_sr_write (GRUB_VGA_SR_MEMORY_MODE_CHAIN4
| GRUB_VGA_SR_MEMORY_MODE_SEQUENTIAL_ADDRESSING
| GRUB_VGA_SR_MEMORY_MODE_EXTERNAL_VIDEO_MEMORY,
GRUB_VGA_SR_MEMORY_MODE);
for (i = 0; i < ARRAY_SIZE (sm712_sr_seq1); i++)
grub_sm712_sr_write (sm712_sr_seq1[i], 0x10 + i);
for (i = 0; i < ARRAY_SIZE (sm712_sr_seq2); i++)
grub_sm712_sr_write (sm712_sr_seq2[i], 0x30 + i);
/* Undocumented. */
grub_sm712_sr_write (0x1a, 0x63);
/* Undocumented. */
grub_sm712_sr_write (0x1a, 0x64);
grub_sm712_sr_write (GRUB_SM712_SR_TV_CRT_SRAM | GRUB_SM712_SR_TV_ALT_CLOCK
| GRUB_SM712_SR_TV_CLOCK_CKIN_NTSC
| GRUB_SM712_SR_TV_HSYNC,
GRUB_SM712_SR_TV_CONTROL);
grub_sm712_sr_write (GRUB_SM712_SR_RAM_LUT_NORMAL, GRUB_SM712_SR_RAM_LUT);
/* Undocumented. */
grub_sm712_sr_write (0x00, 0x67);
grub_sm712_sr_write (GRUB_SM712_SR_CLOCK_CONTROL1_VCLK_FROM_CCR
| GRUB_SM712_SR_CLOCK_CONTROL1_8DOT_CLOCK,
GRUB_SM712_SR_CLOCK_CONTROL1);
grub_sm712_sr_write (GRUB_SM712_SR_CLOCK_CONTROL2_PROGRAM_VCLOCK,
GRUB_SM712_SR_CLOCK_CONTROL2);
grub_sm712_sr_write (82, GRUB_SM712_SR_VCLK_NUM);
grub_sm712_sr_write (137, GRUB_SM712_SR_VCLK_DENOM);
grub_sm712_sr_write (9, GRUB_SM712_SR_VCLK2_NUM);
grub_sm712_sr_write (2, GRUB_SM712_SR_VCLK2_DENOM);
/* FIXME */
grub_sm712_sr_write (0x04, 0x70);
/* FIXME */
grub_sm712_sr_write (0x45, 0x71);
/* Undocumented */
grub_sm712_sr_write (0x30, 0x72);
/* Undocumented */
grub_sm712_sr_write (0x30, 0x73);
/* Undocumented */
grub_sm712_sr_write (0x40, 0x74);
/* Undocumented */
grub_sm712_sr_write (0x20, 0x75);
grub_sm712_sr_write (0xff, GRUB_SM712_SR_POPUP_ICON_LOW);
grub_sm712_sr_write (GRUB_SM712_SR_POPUP_ICON_HIGH_MASK,
GRUB_SM712_SR_POPUP_ICON_HIGH);
grub_sm712_sr_write (GRUB_SM712_SR_POPUP_ICON_CTRL_DISABLED,
GRUB_SM712_SR_POPUP_ICON_CTRL);
/* Undocumented */
grub_sm712_sr_write (0x0, 0x83);
grub_sm712_sr_write (8, GRUB_SM712_SR_POPUP_ICON_COLOR1);
grub_sm712_sr_write (0, GRUB_SM712_SR_POPUP_ICON_COLOR2);
grub_sm712_sr_write (0x42, GRUB_SM712_SR_POPUP_ICON_COLOR3);
/* Undocumented */
grub_sm712_sr_write (0x3a, 0x87);
/* Why theese coordinates? */
grub_sm712_sr_write (0x59, GRUB_SM712_SR_HW_CURSOR_UPPER_LEFT_X_LOW);
grub_sm712_sr_write (0x02, GRUB_SM712_SR_HW_CURSOR_UPPER_LEFT_X_HIGH);
grub_sm712_sr_write (0x44, GRUB_SM712_SR_HW_CURSOR_UPPER_LEFT_Y_LOW);
grub_sm712_sr_write (0x02, GRUB_SM712_SR_HW_CURSOR_UPPER_LEFT_Y_HIGH);
grub_sm712_sr_write (RGB332_BLACK, GRUB_SM712_SR_HW_CURSOR_FG_COLOR);
grub_sm712_sr_write (RGB332_WHITE, GRUB_SM712_SR_HW_CURSOR_BG_COLOR);
/* Undocumented */
grub_sm712_sr_write (0x3a, 0x8e);
grub_sm712_sr_write (0x3a, 0x8f);
grub_sm712_sr_write (0, GRUB_SM712_SR_POPUP_ICON_X_LOW);
grub_sm712_sr_write (0, GRUB_SM712_SR_POPUP_ICON_X_HIGH);
grub_sm712_sr_write (0, GRUB_SM712_SR_POPUP_ICON_Y_LOW);
grub_sm712_sr_write (0, GRUB_SM712_SR_POPUP_ICON_Y_HIGH);
grub_sm712_sr_write (0, GRUB_SM712_SR_PANEL_HW_VIDEO_CONTROL);
grub_sm712_sr_write (0x10, GRUB_SM712_SR_PANEL_HW_VIDEO_COLOR_KEY_LOW);
grub_sm712_sr_write (0x08, GRUB_SM712_SR_PANEL_HW_VIDEO_COLOR_KEY_HIGH);
grub_sm712_sr_write (0x00, GRUB_SM712_SR_PANEL_HW_VIDEO_COLOR_KEY_MASK_LOW);
grub_sm712_sr_write (0x02, GRUB_SM712_SR_PANEL_HW_VIDEO_COLOR_KEY_MASK_HIGH);
grub_sm712_sr_write (0xed, GRUB_SM712_SR_PANEL_HW_VIDEO_RED_CONSTANT);
grub_sm712_sr_write (0xed, GRUB_SM712_SR_PANEL_HW_VIDEO_GREEN_CONSTANT);
grub_sm712_sr_write (0xed, GRUB_SM712_SR_PANEL_HW_VIDEO_BLUE_CONSTANT);
grub_sm712_sr_write (0x7b, GRUB_SM712_SR_PANEL_HW_VIDEO_TOP_BOUNDARY);
grub_sm712_sr_write (0xfb, GRUB_SM712_SR_PANEL_HW_VIDEO_LEFT_BOUNDARY);
grub_sm712_sr_write (0xff, GRUB_SM712_SR_PANEL_HW_VIDEO_BOTTOM_BOUNDARY);
grub_sm712_sr_write (0xff, GRUB_SM712_SR_PANEL_HW_VIDEO_RIGHT_BOUNDARY);
/* Doesn't match documentation? */
grub_sm712_sr_write (0x97, GRUB_SM712_SR_PANEL_HW_VIDEO_TOP_LEFT_OVERFLOW_BOUNDARY);
grub_sm712_sr_write (0xef, GRUB_SM712_SR_PANEL_HW_VIDEO_BOTTOM_RIGHT_OVERFLOW_BOUNDARY);
grub_sm712_sr_write (0xbf, GRUB_SM712_SR_PANEL_HW_VIDEO_VERTICAL_STRETCH_FACTOR);
grub_sm712_sr_write (0xdf, GRUB_SM712_SR_PANEL_HW_VIDEO_HORIZONTAL_STRETCH_FACTOR);
grub_sm712_gr_write (GRUB_VGA_NO_PLANES, GRUB_VGA_GR_SET_RESET_PLANE);
grub_sm712_gr_write (GRUB_VGA_NO_PLANES, GRUB_VGA_GR_SET_RESET_PLANE_ENABLE);
grub_sm712_gr_write (GRUB_VGA_NO_PLANES, GRUB_VGA_GR_COLOR_COMPARE);
grub_sm712_gr_write (GRUB_VGA_GR_DATA_ROTATE_NOP, GRUB_VGA_GR_DATA_ROTATE);
grub_sm712_gr_write (GRUB_VGA_NO_PLANES, GRUB_VGA_GR_READ_MAP_REGISTER);
grub_sm712_gr_write (GRUB_VGA_GR_MODE_256_COLOR, GRUB_VGA_GR_MODE);
grub_sm712_gr_write (GRUB_VGA_GR_GR6_MMAP_A0
| GRUB_VGA_GR_GR6_GRAPHICS_MODE, GRUB_VGA_GR_GR6);
grub_sm712_gr_write (GRUB_VGA_ALL_PLANES, GRUB_VGA_GR_COLOR_COMPARE_DISABLE);
grub_sm712_gr_write (0xff, GRUB_VGA_GR_BITMASK);
/* Write palette mapping. */
for (i = 0; i < 16; i++)
grub_sm712_write_arx (i, i);
grub_sm712_write_arx (GRUB_VGA_ARX_MODE_ENABLE_256COLOR
| GRUB_VGA_ARX_MODE_GRAPHICS, GRUB_VGA_ARX_MODE);
grub_sm712_write_arx (0, GRUB_VGA_ARX_OVERSCAN);
grub_sm712_write_arx (GRUB_VGA_ALL_PLANES, GRUB_VGA_ARX_COLOR_PLANE_ENABLE);
grub_sm712_write_arx (0, GRUB_VGA_ARX_HORIZONTAL_PANNING);
grub_sm712_write_arx (0, GRUB_VGA_ARX_COLOR_SELECT);
/* FIXME: compute this generically. */
{ {
case 1: struct grub_video_hw_config config =
*(volatile grub_uint8_t *) ((char *) framebuffer.ptr
+ sm712_init[i].addr) = sm712_init[i].val;
break;
case -1:
{ {
grub_uint8_t val = *(volatile grub_uint8_t *) .vertical_total = 806,
((char *) framebuffer.ptr + sm712_init[i].addr); .vertical_blank_start = 0x300,
(void) val; .vertical_blank_end = 0,
} .vertical_sync_start = 0x303,
break; .vertical_sync_end = 0x9,
case 2: .line_compare = 0x3ff,
*(volatile grub_uint16_t *) ((char *) framebuffer.ptr .vdisplay_end = 0x300,
+ sm712_init[i].addr) = sm712_init[i].val; .pitch = 0x80,
break; .horizontal_total = 164,
case 4: .horizontal_end = 128,
*(volatile grub_uint32_t *) ((char *) framebuffer.ptr .horizontal_blank_start = 128,
+ sm712_init[i].addr) = sm712_init[i].val; .horizontal_blank_end = 0,
break; .horizontal_sync_pulse_start = 133,
.horizontal_sync_pulse_end = 22
};
grub_vga_set_geometry (&config, grub_sm712_cr_write);
config.horizontal_sync_pulse_start = 134;
config.horizontal_sync_pulse_end = 21;
config.vertical_sync_start = 0x301;
config.vertical_sync_end = 0x0;
config.line_compare = 0x0ff;
config.vdisplay_end = 0x258;
config.pitch = 0x7f;
grub_vga_set_geometry (&config, grub_sm712_cr_shadow_write);
} }
err = grub_video_fb_create_render_target_from_pointer (&framebuffer.render_target, &framebuffer.mode_info, framebuffer.ptr); grub_sm712_cr_write (GRUB_VGA_CR_BYTE_PANNING_NORMAL,
GRUB_VGA_CR_BYTE_PANNING);
grub_sm712_cr_write (0, GRUB_VGA_CR_CURSOR_START);
grub_sm712_cr_write (0, GRUB_VGA_CR_CURSOR_END);
grub_sm712_cr_write (0, GRUB_VGA_CR_START_ADDR_HIGH_REGISTER);
grub_sm712_cr_write (0, GRUB_VGA_CR_START_ADDR_LOW_REGISTER);
grub_sm712_cr_write (0, GRUB_VGA_CR_CURSOR_ADDR_HIGH);
grub_sm712_cr_write (0, GRUB_VGA_CR_CURSOR_ADDR_LOW);
grub_sm712_cr_write (GRUB_VGA_CR_UNDERLINE_LOCATION_DWORD_MODE,
GRUB_VGA_CR_UNDERLINE_LOCATION);
grub_sm712_cr_write (GRUB_VGA_CR_MODE_ADDRESS_WRAP
| GRUB_VGA_CR_MODE_BYTE_MODE
| GRUB_VGA_CR_MODE_TIMING_ENABLE
| GRUB_VGA_CR_MODE_NO_CGA
| GRUB_VGA_CR_MODE_NO_HERCULES,
GRUB_VGA_CR_MODE);
grub_sm712_cr_write (0, GRUB_SM712_CR_OVERFLOW_INTERLACE);
grub_sm712_cr_write (0, GRUB_SM712_CR_INTERLACE_RETRACE);
grub_sm712_cr_write (0, GRUB_SM712_CR_TV_VDISPLAY_START);
grub_sm712_cr_write (0, GRUB_SM712_CR_TV_VDISPLAY_END_HIGH);
grub_sm712_cr_write (0, GRUB_SM712_CR_TV_VDISPLAY_END_LOW);
grub_sm712_cr_write (0x80, GRUB_SM712_CR_DDA_CONTROL_LOW);
grub_sm712_cr_write (0x02, GRUB_SM712_CR_DDA_CONTROL_HIGH);
/* Undocumented */
grub_sm712_cr_write (0x20, 0x37);
grub_sm712_cr_write (0, GRUB_SM712_CR_TV_EQUALIZER);
grub_sm712_cr_write (0, GRUB_SM712_CR_TV_SERRATION);
grub_sm712_cr_write (0, GRUB_SM712_CR_HSYNC_CTRL);
/* Undocumented */
grub_sm712_cr_write (0x40, 0x3b);
grub_sm712_cr_write (GRUB_SM712_CR_DEBUG_NONE, GRUB_SM712_CR_DEBUG);
/* Undocumented */
grub_sm712_cr_write (0xff, 0x3d);
grub_sm712_cr_write (0x46, 0x3e);
grub_sm712_cr_write (0x91, 0x3f);
for (i = 0; i < ARRAY_SIZE (dda_lookups); i++)
grub_sm712_write_dda_lookup (i, dda_lookups[i].compare, dda_lookups[i].dda,
dda_lookups[i].vcentering);
/* Undocumented */
grub_sm712_cr_write (0, 0x9c);
grub_sm712_cr_write (0, 0x9d);
grub_sm712_cr_write (0, 0x9e);
grub_sm712_cr_write (0, 0x9f);
grub_sm712_cr_write (0, GRUB_SM712_CR_VCENTERING_OFFSET);
grub_sm712_cr_write (0, GRUB_SM712_CR_HCENTERING_OFFSET);
grub_sm712_write_reg (GRUB_VGA_IO_MISC_NEGATIVE_HORIZ_POLARITY
| GRUB_VGA_IO_MISC_UPPER_64K
| GRUB_VGA_IO_MISC_28MHZ
| GRUB_VGA_IO_MISC_ENABLE_VRAM_ACCESS
| GRUB_VGA_IO_MISC_COLOR,
GRUB_VGA_IO_MISC_WRITE);
#ifndef TEST
/* Undocumented? */
*(volatile grub_uint32_t *) ((char *) framebuffer.ptr + 0x40c00c) = 0;
*(volatile grub_uint32_t *) ((char *) framebuffer.ptr + 0x40c040) = 0;
*(volatile grub_uint32_t *) ((char *) framebuffer.ptr + 0x40c000) = 0x20000;
*(volatile grub_uint32_t *) ((char *) framebuffer.ptr + 0x40c010) = 0x1020100;
#endif
(void) grub_sm712_sr_read (0x16);
#ifndef TEST
err = grub_video_fb_create_render_target_from_pointer (&framebuffer
.render_target,
&framebuffer.mode_info,
framebuffer.ptr);
if (err) if (err)
return err; return err;
@ -192,9 +702,12 @@ grub_video_sm712_setup (unsigned int width, unsigned int height,
/* Copy default palette to initialize emulated palette. */ /* Copy default palette to initialize emulated palette. */
err = grub_video_fb_set_palette (0, GRUB_VIDEO_FBSTD_NUMCOLORS, err = grub_video_fb_set_palette (0, GRUB_VIDEO_FBSTD_NUMCOLORS,
grub_video_fbstd_colors); grub_video_fbstd_colors);
#endif
return err; return err;
} }
#ifndef TEST
static grub_err_t static grub_err_t
grub_video_sm712_swap_buffers (void) grub_video_sm712_swap_buffers (void)
{ {
@ -223,7 +736,6 @@ grub_video_sm712_get_info_and_fini (struct grub_video_mode_info *mode_info,
return GRUB_ERR_NONE; return GRUB_ERR_NONE;
} }
static struct grub_video_adapter grub_video_sm712_adapter = static struct grub_video_adapter grub_video_sm712_adapter =
{ {
.name = "SM712 Video Driver", .name = "SM712 Video Driver",
@ -266,3 +778,10 @@ GRUB_MOD_FINI(video_sm712)
{ {
grub_video_unregister (&grub_video_sm712_adapter); grub_video_unregister (&grub_video_sm712_adapter);
} }
#else
int
main ()
{
grub_video_sm712_setup (1024, 600, 0, 0);
}
#endif

View file

@ -1,546 +1,14 @@
/* Following sequence is a capture of sm712 initialisation sequence. */ /* Following sequence is a capture of sm712 initialisation sequence. */
static struct static grub_uint8_t sm712_sr_seq1[] =
{ { 0xc8, 0x40, 0x14, 0x60, 0x0, 0xa, 0x92, 0x0,
int directive; 0x51, 0x00, 0x01, 0x00, 0x0, 0x0, 0x00, 0x0,
grub_uint32_t addr; 0xc4, 0x30, 0x02, 0x00, 0x1 };
grub_uint32_t val;
} sm712_init[] = static grub_uint8_t sm712_sr_seq2[] =
{ { 0x28, 0x03, 0x24, 0x09, 0xc0, 0x3a, 0x3a, 0x3a,
{1, 0x7003c4, 0x21}, 0x3a, 0x3a, 0x3a, 0x3a, 0x00, 0x00, 0x03, 0xff,
{1, 0x7003c5, 0x0}, 0x00, 0xfc, 0x00, 0x00, 0x20, 0x18, 0x00, 0xfc,
{1, 0x7003c4, 0x62}, 0x20, 0x0c, 0x44, 0x20, 0x00, 0x00, 0x00, 0x3a,
{1, 0x7003c5, 0x7a}, 0x06, 0x68, 0xa7, 0x7f, 0x83, 0x24, 0xff, 0x03,
{1, 0x7003c4, 0x6a}, 0x00, 0x60, 0x59, 0x3a, 0x3a, 0x00, 0x00, 0x3a,
{1, 0x7003c5, 0x16}, 0x01, 0x80 };
{1, 0x7003c4, 0x6b},
{1, 0x7003c5, 0x2},
{1, 0x7003c6, 0x0},
{1, 0x7003c4, 0x0},
{1, 0x7003c5, 0x1},
{1, 0x7003c2, 0xeb},
{1, 0x7003c4, 0x0},
{1, 0x7003c5, 0x3},
{1, 0x7003c4, 0x1},
{1, 0x7003c5, 0x1},
{1, 0x7003c4, 0x2},
{1, 0x7003c5, 0xf},
{1, 0x7003c4, 0x3},
{1, 0x7003c5, 0x0},
{1, 0x7003c4, 0x4},
{1, 0x7003c5, 0xe},
{1, 0x7003c4, 0x10},
{1, 0x7003c5, 0xc8},
{1, 0x7003c4, 0x11},
{1, 0x7003c5, 0x40},
{1, 0x7003c4, 0x12},
{1, 0x7003c5, 0x14},
{1, 0x7003c4, 0x13},
{1, 0x7003c5, 0x60},
{1, 0x7003c4, 0x14},
{1, 0x7003c5, 0x0},
{1, 0x7003c4, 0x15},
{1, 0x7003c5, 0xa},
{1, 0x7003c4, 0x16},
{1, 0x7003c5, 0x92},
{1, 0x7003c4, 0x17},
{1, 0x7003c5, 0x0},
{1, 0x7003c4, 0x18},
{1, 0x7003c5, 0x51},
{1, 0x7003c4, 0x19},
{1, 0x7003c5, 0x0},
{1, 0x7003c4, 0x1a},
{1, 0x7003c5, 0x1},
{1, 0x7003c4, 0x1b},
{1, 0x7003c5, 0x0},
{1, 0x7003c4, 0x1c},
{1, 0x7003c5, 0x0},
{1, 0x7003c4, 0x1d},
{1, 0x7003c5, 0x0},
{1, 0x7003c4, 0x1e},
{1, 0x7003c5, 0x0},
{1, 0x7003c4, 0x1f},
{1, 0x7003c5, 0x0},
{1, 0x7003c4, 0x20},
{1, 0x7003c5, 0xc4},
{1, 0x7003c4, 0x21},
{1, 0x7003c5, 0x30},
{1, 0x7003c4, 0x22},
{1, 0x7003c5, 0x2},
{1, 0x7003c4, 0x23},
{1, 0x7003c5, 0x0},
{1, 0x7003c4, 0x24},
{1, 0x7003c5, 0x1},
{1, 0x7003c4, 0x30},
{1, 0x7003c5, 0x28},
{1, 0x7003c4, 0x31},
{1, 0x7003c5, 0x3},
{1, 0x7003c4, 0x32},
{1, 0x7003c5, 0x24},
{1, 0x7003c4, 0x33},
{1, 0x7003c5, 0x9},
{1, 0x7003c4, 0x34},
{1, 0x7003c5, 0xc0},
{1, 0x7003c4, 0x35},
{1, 0x7003c5, 0x3a},
{1, 0x7003c4, 0x36},
{1, 0x7003c5, 0x3a},
{1, 0x7003c4, 0x37},
{1, 0x7003c5, 0x3a},
{1, 0x7003c4, 0x38},
{1, 0x7003c5, 0x3a},
{1, 0x7003c4, 0x39},
{1, 0x7003c5, 0x3a},
{1, 0x7003c4, 0x3a},
{1, 0x7003c5, 0x3a},
{1, 0x7003c4, 0x3b},
{1, 0x7003c5, 0x3a},
{1, 0x7003c4, 0x3c},
{1, 0x7003c5, 0x0},
{1, 0x7003c4, 0x3d},
{1, 0x7003c5, 0x0},
{1, 0x7003c4, 0x3e},
{1, 0x7003c5, 0x3},
{1, 0x7003c4, 0x3f},
{1, 0x7003c5, 0xff},
{1, 0x7003c4, 0x40},
{1, 0x7003c5, 0x0},
{1, 0x7003c4, 0x41},
{1, 0x7003c5, 0xfc},
{1, 0x7003c4, 0x42},
{1, 0x7003c5, 0x0},
{1, 0x7003c4, 0x43},
{1, 0x7003c5, 0x0},
{1, 0x7003c4, 0x44},
{1, 0x7003c5, 0x20},
{1, 0x7003c4, 0x45},
{1, 0x7003c5, 0x18},
{1, 0x7003c4, 0x46},
{1, 0x7003c5, 0x0},
{1, 0x7003c4, 0x47},
{1, 0x7003c5, 0xfc},
{1, 0x7003c4, 0x48},
{1, 0x7003c5, 0x20},
{1, 0x7003c4, 0x49},
{1, 0x7003c5, 0xc},
{1, 0x7003c4, 0x4a},
{1, 0x7003c5, 0x44},
{1, 0x7003c4, 0x4b},
{1, 0x7003c5, 0x20},
{1, 0x7003c4, 0x4c},
{1, 0x7003c5, 0x0},
{1, 0x7003c4, 0x4d},
{1, 0x7003c5, 0x0},
{1, 0x7003c4, 0x4e},
{1, 0x7003c5, 0x0},
{1, 0x7003c4, 0x4f},
{1, 0x7003c5, 0x3a},
{1, 0x7003c4, 0x50},
{1, 0x7003c5, 0x6},
{1, 0x7003c4, 0x51},
{1, 0x7003c5, 0x68},
{1, 0x7003c4, 0x52},
{1, 0x7003c5, 0xa7},
{1, 0x7003c4, 0x53},
{1, 0x7003c5, 0x7f},
{1, 0x7003c4, 0x54},
{1, 0x7003c5, 0x83},
{1, 0x7003c4, 0x55},
{1, 0x7003c5, 0x24},
{1, 0x7003c4, 0x56},
{1, 0x7003c5, 0xff},
{1, 0x7003c4, 0x57},
{1, 0x7003c5, 0x3},
{1, 0x7003c4, 0x58},
{1, 0x7003c5, 0x0},
{1, 0x7003c4, 0x59},
{1, 0x7003c5, 0x60},
{1, 0x7003c4, 0x5a},
{1, 0x7003c5, 0x59},
{1, 0x7003c4, 0x5b},
{1, 0x7003c5, 0x3a},
{1, 0x7003c4, 0x5c},
{1, 0x7003c5, 0x3a},
{1, 0x7003c4, 0x5d},
{1, 0x7003c5, 0x0},
{1, 0x7003c4, 0x5e},
{1, 0x7003c5, 0x0},
{1, 0x7003c4, 0x5f},
{1, 0x7003c5, 0x3a},
{1, 0x7003c4, 0x60},
{1, 0x7003c5, 0x1},
{1, 0x7003c4, 0x61},
{1, 0x7003c5, 0x80},
{1, 0x7003c4, 0x63},
{1, 0x7003c5, 0x1a},
{1, 0x7003c4, 0x64},
{1, 0x7003c5, 0x1a},
{1, 0x7003c4, 0x65},
{1, 0x7003c5, 0x0},
{1, 0x7003c4, 0x66},
{1, 0x7003c5, 0x0},
{1, 0x7003c4, 0x67},
{1, 0x7003c5, 0x0},
{1, 0x7003c4, 0x68},
{1, 0x7003c5, 0x50},
{1, 0x7003c4, 0x69},
{1, 0x7003c5, 0x3},
{1, 0x7003c4, 0x6c},
{1, 0x7003c5, 0x52},
{1, 0x7003c4, 0x6d},
{1, 0x7003c5, 0x89},
{1, 0x7003c4, 0x6e},
{1, 0x7003c5, 0x9},
{1, 0x7003c4, 0x6f},
{1, 0x7003c5, 0x2},
{1, 0x7003c4, 0x70},
{1, 0x7003c5, 0x4},
{1, 0x7003c4, 0x71},
{1, 0x7003c5, 0x45},
{1, 0x7003c4, 0x72},
{1, 0x7003c5, 0x30},
{1, 0x7003c4, 0x73},
{1, 0x7003c5, 0x30},
{1, 0x7003c4, 0x74},
{1, 0x7003c5, 0x40},
{1, 0x7003c4, 0x75},
{1, 0x7003c5, 0x20},
{1, 0x7003c4, 0x80},
{1, 0x7003c5, 0xff},
{1, 0x7003c4, 0x81},
{1, 0x7003c5, 0x7},
{1, 0x7003c4, 0x82},
{1, 0x7003c5, 0x0},
{1, 0x7003c4, 0x83},
{1, 0x7003c5, 0x0},
{1, 0x7003c4, 0x84},
{1, 0x7003c5, 0x8},
{1, 0x7003c4, 0x85},
{1, 0x7003c5, 0x0},
{1, 0x7003c4, 0x86},
{1, 0x7003c5, 0x42},
{1, 0x7003c4, 0x87},
{1, 0x7003c5, 0x3a},
{1, 0x7003c4, 0x88},
{1, 0x7003c5, 0x59},
{1, 0x7003c4, 0x89},
{1, 0x7003c5, 0x2},
{1, 0x7003c4, 0x8a},
{1, 0x7003c5, 0x44},
{1, 0x7003c4, 0x8b},
{1, 0x7003c5, 0x2},
{1, 0x7003c4, 0x8c},
{1, 0x7003c5, 0x0},
{1, 0x7003c4, 0x8d},
{1, 0x7003c5, 0xff},
{1, 0x7003c4, 0x8e},
{1, 0x7003c5, 0x3a},
{1, 0x7003c4, 0x8f},
{1, 0x7003c5, 0x3a},
{1, 0x7003c4, 0x90},
{1, 0x7003c5, 0x0},
{1, 0x7003c4, 0x91},
{1, 0x7003c5, 0x0},
{1, 0x7003c4, 0x92},
{1, 0x7003c5, 0x0},
{1, 0x7003c4, 0x93},
{1, 0x7003c5, 0x0},
{1, 0x7003c4, 0xa0},
{1, 0x7003c5, 0x0},
{1, 0x7003c4, 0xa1},
{1, 0x7003c5, 0x10},
{1, 0x7003c4, 0xa2},
{1, 0x7003c5, 0x8},
{1, 0x7003c4, 0xa3},
{1, 0x7003c5, 0x0},
{1, 0x7003c4, 0xa4},
{1, 0x7003c5, 0x2},
{1, 0x7003c4, 0xa5},
{1, 0x7003c5, 0xed},
{1, 0x7003c4, 0xa6},
{1, 0x7003c5, 0xed},
{1, 0x7003c4, 0xa7},
{1, 0x7003c5, 0xed},
{1, 0x7003c4, 0xa8},
{1, 0x7003c5, 0x7b},
{1, 0x7003c4, 0xa9},
{1, 0x7003c5, 0xfb},
{1, 0x7003c4, 0xaa},
{1, 0x7003c5, 0xff},
{1, 0x7003c4, 0xab},
{1, 0x7003c5, 0xff},
{1, 0x7003c4, 0xac},
{1, 0x7003c5, 0x97},
{1, 0x7003c4, 0xad},
{1, 0x7003c5, 0xef},
{1, 0x7003c4, 0xae},
{1, 0x7003c5, 0xbf},
{1, 0x7003c4, 0xaf},
{1, 0x7003c5, 0xdf},
{1, 0x7003ce, 0x0},
{1, 0x7003cf, 0x0},
{1, 0x7003ce, 0x1},
{1, 0x7003cf, 0x0},
{1, 0x7003ce, 0x2},
{1, 0x7003cf, 0x0},
{1, 0x7003ce, 0x3},
{1, 0x7003cf, 0x0},
{1, 0x7003ce, 0x4},
{1, 0x7003cf, 0x0},
{1, 0x7003ce, 0x5},
{1, 0x7003cf, 0x40},
{1, 0x7003ce, 0x6},
{1, 0x7003cf, 0x5},
{1, 0x7003ce, 0x7},
{1, 0x7003cf, 0xf},
{1, 0x7003ce, 0x8},
{1, 0x7003cf, 0xff},
{-1, 0x7003da, 0x5},
{1, 0x7003c0, 0x0},
{-1, 0x7003c1, 0x3e},
{1, 0x7003c0, 0x0},
{-1, 0x7003da, 0x5},
{1, 0x7003c0, 0x1},
{-1, 0x7003c1, 0x3b},
{1, 0x7003c0, 0x1},
{-1, 0x7003da, 0x5},
{1, 0x7003c0, 0x2},
{-1, 0x7003c1, 0x3f},
{1, 0x7003c0, 0x2},
{-1, 0x7003da, 0x5},
{1, 0x7003c0, 0x3},
{-1, 0x7003c1, 0x3f},
{1, 0x7003c0, 0x3},
{-1, 0x7003da, 0x5},
{1, 0x7003c0, 0x4},
{-1, 0x7003c1, 0x3b},
{1, 0x7003c0, 0x4},
{-1, 0x7003da, 0x5},
{1, 0x7003c0, 0x5},
{-1, 0x7003c1, 0x2f},
{1, 0x7003c0, 0x5},
{-1, 0x7003da, 0x5},
{1, 0x7003c0, 0x6},
{-1, 0x7003c1, 0x3f},
{1, 0x7003c0, 0x6},
{-1, 0x7003da, 0x5},
{1, 0x7003c0, 0x7},
{-1, 0x7003c1, 0x3f},
{1, 0x7003c0, 0x7},
{-1, 0x7003da, 0x5},
{1, 0x7003c0, 0x8},
{-1, 0x7003c1, 0x3f},
{1, 0x7003c0, 0x8},
{-1, 0x7003da, 0x5},
{1, 0x7003c0, 0x9},
{-1, 0x7003c1, 0x3d},
{1, 0x7003c0, 0x9},
{-1, 0x7003da, 0x5},
{1, 0x7003c0, 0xa},
{-1, 0x7003c1, 0x1f},
{1, 0x7003c0, 0xa},
{-1, 0x7003da, 0x5},
{1, 0x7003c0, 0xb},
{-1, 0x7003c1, 0x1f},
{1, 0x7003c0, 0xb},
{-1, 0x7003da, 0x5},
{1, 0x7003c0, 0xc},
{-1, 0x7003c1, 0x3f},
{1, 0x7003c0, 0xc},
{-1, 0x7003da, 0x5},
{1, 0x7003c0, 0xd},
{-1, 0x7003c1, 0x3f},
{1, 0x7003c0, 0xd},
{-1, 0x7003da, 0x5},
{1, 0x7003c0, 0xe},
{-1, 0x7003c1, 0x3f},
{1, 0x7003c0, 0xe},
{-1, 0x7003da, 0x5},
{1, 0x7003c0, 0xf},
{-1, 0x7003c1, 0x2e},
{1, 0x7003c0, 0xf},
{-1, 0x7003da, 0x5},
{1, 0x7003c0, 0x10},
{-1, 0x7003c1, 0x0},
{1, 0x7003c0, 0x41},
{-1, 0x7003da, 0x5},
{1, 0x7003c0, 0x11},
{-1, 0x7003c1, 0x0},
{1, 0x7003c0, 0x0},
{-1, 0x7003da, 0x5},
{1, 0x7003c0, 0x12},
{-1, 0x7003c1, 0x0},
{1, 0x7003c0, 0xf},
{-1, 0x7003da, 0x5},
{1, 0x7003c0, 0x13},
{-1, 0x7003c1, 0x0},
{1, 0x7003c0, 0x0},
{-1, 0x7003da, 0x5},
{1, 0x7003c0, 0x14},
{-1, 0x7003c1, 0x0},
{1, 0x7003c0, 0x0},
{1, 0x7003d4, 0x0},
{1, 0x7003d5, 0xa3},
{1, 0x7003d4, 0x1},
{1, 0x7003d5, 0x7f},
{1, 0x7003d4, 0x2},
{1, 0x7003d5, 0x7f},
{1, 0x7003d4, 0x3},
{1, 0x7003d5, 0x0},
{1, 0x7003d4, 0x4},
{1, 0x7003d5, 0x85},
{1, 0x7003d4, 0x5},
{1, 0x7003d5, 0x16},
{1, 0x7003d4, 0x6},
{1, 0x7003d5, 0x24},
{1, 0x7003d4, 0x7},
{1, 0x7003d5, 0xf5},
{1, 0x7003d4, 0x8},
{1, 0x7003d5, 0x0},
{1, 0x7003d4, 0x9},
{1, 0x7003d5, 0x60},
{1, 0x7003d4, 0xa},
{1, 0x7003d5, 0x0},
{1, 0x7003d4, 0xb},
{1, 0x7003d5, 0x0},
{1, 0x7003d4, 0xc},
{1, 0x7003d5, 0x0},
{1, 0x7003d4, 0xd},
{1, 0x7003d5, 0x0},
{1, 0x7003d4, 0xe},
{1, 0x7003d5, 0x0},
{1, 0x7003d4, 0xf},
{1, 0x7003d5, 0x0},
{1, 0x7003d4, 0x10},
{1, 0x7003d5, 0x3},
{1, 0x7003d4, 0x11},
{1, 0x7003d5, 0x9},
{1, 0x7003d4, 0x12},
{1, 0x7003d5, 0xff},
{1, 0x7003d4, 0x13},
{1, 0x7003d5, 0x80},
{1, 0x7003d4, 0x14},
{1, 0x7003d5, 0x40},
{1, 0x7003d4, 0x15},
{1, 0x7003d5, 0xff},
{1, 0x7003d4, 0x16},
{1, 0x7003d5, 0x0},
{1, 0x7003d4, 0x17},
{1, 0x7003d5, 0xe3},
{1, 0x7003d4, 0x18},
{1, 0x7003d5, 0xff},
{1, 0x7003d4, 0x30},
{1, 0x7003d5, 0x0},
{1, 0x7003d4, 0x31},
{1, 0x7003d5, 0x0},
{1, 0x7003d4, 0x32},
{1, 0x7003d5, 0x0},
{1, 0x7003d4, 0x33},
{1, 0x7003d5, 0x0},
{1, 0x7003d4, 0x34},
{1, 0x7003d5, 0x0},
{1, 0x7003d4, 0x35},
{1, 0x7003d5, 0x80},
{1, 0x7003d4, 0x36},
{1, 0x7003d5, 0x2},
{1, 0x7003d4, 0x37},
{1, 0x7003d5, 0x20},
{1, 0x7003d4, 0x38},
{1, 0x7003d5, 0x0},
{1, 0x7003d4, 0x39},
{1, 0x7003d5, 0x0},
{1, 0x7003d4, 0x3a},
{1, 0x7003d5, 0x0},
{1, 0x7003d4, 0x3b},
{1, 0x7003d5, 0x40},
{1, 0x7003d4, 0x3c},
{1, 0x7003d5, 0x0},
{1, 0x7003d4, 0x3d},
{1, 0x7003d5, 0xff},
{1, 0x7003d4, 0x3e},
{1, 0x7003d5, 0x46},
{1, 0x7003d4, 0x3f},
{1, 0x7003d5, 0x91},
{1, 0x7003d4, 0x40},
{1, 0x7003d5, 0xa3},
{1, 0x7003d4, 0x41},
{1, 0x7003d5, 0x7f},
{1, 0x7003d4, 0x42},
{1, 0x7003d5, 0x0},
{1, 0x7003d4, 0x43},
{1, 0x7003d5, 0x86},
{1, 0x7003d4, 0x44},
{1, 0x7003d5, 0x15},
{1, 0x7003d4, 0x45},
{1, 0x7003d5, 0x24},
{1, 0x7003d4, 0x46},
{1, 0x7003d5, 0xff},
{1, 0x7003d4, 0x47},
{1, 0x7003d5, 0x0},
{1, 0x7003d4, 0x48},
{1, 0x7003d5, 0x1},
{1, 0x7003d4, 0x49},
{1, 0x7003d5, 0x7},
{1, 0x7003d4, 0x4a},
{1, 0x7003d5, 0xe5},
{1, 0x7003d4, 0x4b},
{1, 0x7003d5, 0x20},
{1, 0x7003d4, 0x4c},
{1, 0x7003d5, 0x7f},
{1, 0x7003d4, 0x4d},
{1, 0x7003d5, 0x57},
{1, 0x7003d4, 0x90},
{1, 0x7003d5, 0x55},
{1, 0x7003d4, 0x91},
{1, 0x7003d5, 0xd5},
{1, 0x7003d4, 0x92},
{1, 0x7003d5, 0x5d},
{1, 0x7003d4, 0x93},
{1, 0x7003d5, 0xdd},
{1, 0x7003d4, 0x94},
{1, 0x7003d5, 0x86},
{1, 0x7003d4, 0x95},
{1, 0x7003d5, 0x17},
{1, 0x7003d4, 0x96},
{1, 0x7003d5, 0x8e},
{1, 0x7003d4, 0x97},
{1, 0x7003d5, 0xaa},
{1, 0x7003d4, 0x98},
{1, 0x7003d5, 0x8a},
{1, 0x7003d4, 0x99},
{1, 0x7003d5, 0xa3},
{1, 0x7003d4, 0x9a},
{1, 0x7003d5, 0xde},
{1, 0x7003d4, 0x9b},
{1, 0x7003d5, 0xab},
{1, 0x7003d4, 0x9c},
{1, 0x7003d5, 0x0},
{1, 0x7003d4, 0x9d},
{1, 0x7003d5, 0x0},
{1, 0x7003d4, 0x9e},
{1, 0x7003d5, 0x0},
{1, 0x7003d4, 0x9f},
{1, 0x7003d5, 0x0},
{1, 0x7003d4, 0xa0},
{1, 0x7003d5, 0x2},
{1, 0x7003d4, 0xa1},
{1, 0x7003d5, 0x2},
{1, 0x7003d4, 0xa2},
{1, 0x7003d5, 0x2},
{1, 0x7003d4, 0xa3},
{1, 0x7003d5, 0x15},
{1, 0x7003d4, 0xa4},
{1, 0x7003d5, 0x2},
{1, 0x7003d4, 0xa5},
{1, 0x7003d5, 0x6},
{1, 0x7003d4, 0xa6},
{1, 0x7003d5, 0x0},
{1, 0x7003d4, 0xa7},
{1, 0x7003d5, 0x0},
{1, 0x7003c2, 0x67},
{4, 0x40c00c, 0x0},
{4, 0x40c040, 0x0},
{4, 0x40c000, 0x20000},
{4, 0x40c010, 0x1020100},
{1, 0x7003c4, 0x16},
{-1, 0x7003c5, 0x17}
};