(OFDISK_HASH_SZ): Define.
(ofdisk_hash): New hash table.
(ofdisk_hash_fn, ofdisk_hash_find, ofdisk_hash_add): New functions.
(grub_ofdisk_open): Use ofdisk_hash_ent address as disk->id
instead of device phandle which is not unique.
slots are of type grub_ieee1275_cell_t.
(grub_nand_read): Likewise.
* kern/ieee1275/ieee1275.c (IEEE1275_PHANDLE_INVALID,
IEEE1275_IHANDLE_INVALID): Use grub_ieee1275_cell_t since these
macros are used to compare values in arg/ret block of the call.
(grub_ieee1275_finddevice, grub_ieee1275_get_property,
grub_ieee1275_next_property, grub_ieee1275_get_property_length,
grub_ieee1275_instance_to_package, grub_ieee1275_package_to_path,
grub_ieee1275_instance_to_path, grub_ieee1275_write,
grub_ieee1275_read, grub_ieee1275_seek, grub_ieee1275_peer,
grub_ieee1275_child, grub_ieee1275_parent, grub_ieee1275_open,
grub_ieee1275_close, grub_ieee1275_set_property,
grub_ieee1275_set_color): All ieee1275 call arg slots are of type
grub_ieee1275_cell_t.
* kern/ieee1275/openfw.c (grub_map): Likewise.
* include/grub/ieee1275/ieee1275.h (grub_ieee1275_ihandle_t,
grub_ieee1275_phandle_t): Define as grub_unit32_t type.
Reapply fix from 2008-07-28 which was accidentally reverted; also
perform the same fix to a similar check in same function.
* disk/raid.c (grub_raid_scan_device): Do not abort when two disks
with the same number are found, just use issue a warning with
grub_dprintf(), as this error has been reported to be non-fatal.
Leak fixes
* kern/disk.c (grub_disk_cache_store): Invalidate previous cache
in case of collision
* disk/scsi.c (grub_scsi_open): free scsi in case of error
* disk/ata.c (grub_ata_wait_status): Replace by ...
(grub_ata_wait_not_busy): ... this function. Checks only BSY bit,
other status bits may be invalid while BSY is asserted.
(grub_ata_check_ready): New function.
(grub_ata_cmd): Removed.
(grub_ata_wait_drq): New function.
(grub_ata_strncpy): Remove inline.
(grub_ata_pio_read): Reduce to actual block transfer. BSY wait
and error check now done by grub_ata_wait_drq ().
(grub_ata_pio_write): Likewise.
(grub_atapi_identify): Set DEV before check for !BSY. Use
grub_ata_wait_drq () to wait for data.
(grub_ata_device_initialize): Add status register check to
detect missing SATA slave devices. Add debug messages.
(grub_atapi_wait_drq): Use grub_ata_wait_not_busy ().
(grub_atapi_packet): Set DEV before check for !BSY. Replace
transfer loop by grub_ata_pio_write ().
(grub_ata_identify): Set DEV before check for !BSY. Use
grub_ata_wait_drq () to wait for data.
(grub_ata_setaddress): Set DEV before check for !BSY.
(grub_ata_readwrite): Remove duplicate code, handle batch/rest and
read/write in one loop. Fix invalid command on write. Fix incomplete
command on (size % batch) == 0. Add missing error check after write of
last block. Add debug messages.
(grub_atapi_read): Replace transfer loop by grub_ata_pio_read ().
* disk/ata.c (GRUB_ATAPI_REG_*): New defines.
(GRUB_ATAPI_IREASON_*): Likewise.
(grub_ata_pio_write): Fix timeout error return.
(grub_atapi_identify): Add grub_ata_wait () after cmd.
(grub_atapi_wait_drq): New function.
(grub_atapi_packet): New parameter `size'.
Use grub_atapi_wait_drq () and direct write instead of
grub_ata_pio_write ().
(grub_atapi_read): Replace grub_ata_pio_read () by a loop which
reads the number of bytes requested by the device for each DRQ
assertion.
(grub_atapi_write): Remove old implementation, return not
implemented instead.
* disk/scsi.c (grub_scsi_read10): Use scsi->blocksize instead
of 512 to calculate data size.
(grub_scsi_read12): Likewise.
(grub_scsi_write10): Likewise.
(grub_scsi_write12): Likewise.
(grub_scsi_read): Adjust size according to blocksize.
Add checks for invalid blocksize and unaligned transfer.
* disk/ata.c (enum grub_ata_commands): Remove EXEC_DEV_DIAGNOSTICS.
(enum grub_ata_timeout_milliseconds): New enum.
(grub_ata_wait_status): Add parameter milliseconds.
(grub_ata_cmd): Remove variable `err'. Remove wait for !DRQ to allow
recovery from timed-out commands.
(grub_ata_pio_read): Add parameter milliseconds. Fix error return,
return grub_errno instead of REG_ERROR.
(grub_ata_pio_write): Add parameter milliseconds.
(grub_atapi_identify): Fix size of ATAPI IDENTIFY sector.
Pass milliseconds to grub_ata_wait_status () and
grub_ata_pio_read ().
(grub_atapi_packet): Pass milliseconds to grub_ata_pio_write ().
(grub_ata_identify): Remove variable `ataerr'. Pass milliseconds to
grub_ata_wait_status (). Fix IDENTIFY timeout check.
(grub_ata_device_initialize): Remove EXECUTE DEVICE DIAGNOSTICS.
It is not suitable for device detection, because DEV bit is ignored,
the command may run too long, and not all devices set the signature
properly.
(grub_ata_pciinit): Clear grub_errno before grub_ata_device_initialize ().
(grub_ata_setaddress): Pass milliseconds to grub_ata_wait_status ().
Fix device selection, DEV bit must be set first to address the registers
of the correct device.
(grub_ata_readwrite): Pass milliseconds to grub_ata_wait_status () and
grub_ata_pio_read/write ().
(grub_atapi_read): Pass milliseconds to grub_ata_pio_read ().
(grub_atapi_write): Pass milliseconds to grub_ata_pio_write ().
* disk/lvm.c (grub_lvm_scan_device): Fix possible NULL value handling
(add a missing NULL check, and correct them by moving the pointer
operations after the actual check).
* disk/lvm.c (grub_lvm_scan_device): Allocate buffer space for the
circular metadata worst case scenario. If the metadata is circular
then copy the wrap in place.
* include/grub/lvm.h: Add GRUB_LVM_MDA_HEADER_SIZE, from the LVM2
project lib/format_text/layout.h
Circular metadata bug found and patch debugged by Jan Derk Gerlings.
* disk/ata.c (grub_apapi_open): Initialize devfnd, no need to set
scsi->name and scsi->luns, as they will be set in grub_scsi_open.
* disk/scsi.c (grub_scsi_open): Don't call p->close (scsi) here when
error occurs, as grub_disk_open will call grub_disk_close, which will
call p->close (scsi).
* conf/common.rmk (grub_probe_SOURCES): Add disk/mdraid_linux.c.
(grub_fstest_SOURCES): Add disk/raid5_recover.c, disk/raid6_recover.c,
disk/mdraid_linux.c and disk/dmraid_nvidia.c and lib/crc.c.
(pkglib_MODULES): Add raid5rec.mod, raid6rec.mod, mdraid.mod and
dm_nv.mod.
(raid5rec_mod_SOURCES): New macro.
(raid5rec_mod_CFLAGS): Likewise.
(raid5rec_mod_LDFLAGS): Likewise.
(raid6rec_mod_SOURCES): Likewise.
(raid6rec_mod_CFLAGS): Likewise.
(raid6rec_mod_LDFLAGS): Likewise.
(mdraid_mod_SOURCES): Likewise.
(mdraid_mod_CFLAGS): Likewise.
(mdraid_mod_LDFLAGS): Likewise.
(dm_nv_mod_SOURCES): Likewise.
(dm_nv_mod_CFLAGS): Likewise.
(dm_nv_mod_LDFLAGS): Likewise.
* conf/i386-pc.rmk (grub_setup_SOURCES): Add disk/mdraid_linux.c.
(grub_emu_SOURCES): Add disk/raid5_recover.c, disk/raid6_recover.c,
disk/mdraid_linux.c and disk/dmraid_nvidia.c.
* conf/i386-coreboot.rmk (grub_emu_SOURCES): Add disk/raid5_recover.c,
disk/raid6_recover.c, disk/mdraid_linux.c and disk/dmraid_nvidia.c.
* conf/i386-efi.rmk (grub_emu_SOURCES): Likewise.
* conf/x86_64-efi.rmk (grub_emu_SOURCES): Likewise.
* conf/i386-ieee1275.rmk (grub_emu_SOURCES): Likewise.
* conf/powerpc-ieee1275.rmk (grub_emu_SOURCES): Likewise.
* disk/raid5_recover.c: New file.
* disk/raid6_recover.c: Likewise.
* disk/mdraid_linux.c: Likewise.
* disk/dmraid_nvidia.c: Likewise.
* disk/i386/pc/biosdisk.c: Set total_sectors of cdrom device to
ULONG_MAX.
* disk/raid.c (grub_raid_open): Use the size of the smallest disk to
calculate the size of raid device.
(grub_raid_read): Simplify raid0 code. Support raid4, raid6 and four
different layout of raid5.
(grub_raid_scan_device): Remove code specific to mdraid.
(grub_raid_list): New variable.
(free_array): New function.
(grub_raid_register): Likewise.
(grub_raid_unregister): Likewise.
(grub_raid_rescan): Likewise.
(GRUB_MOD_INIT): Don't iterate device here.
(GRUB_MOD_FINI): Use free_array to release resource.
* include/grub/raid.h: Remove macro and structure specific to mdraid.
(grub_raid5_recover_func_t): New function variable type.
(grub_raid6_recover_func_t): Likewise.
(grub_raid5_recover_func): New variable.
(grub_raid6_recover_func): Likewise.
(grub_raid_register): New function.
(grub_raid_unregister): Likewise.
(grub_raid_rescan): Likewise.
(grub_raid_block_xor): Likewise.
* util/grub-fstest.c: Add #include <grub/raid.h> and <grub/lib/crc.h>.
(CMD_CRC): New macro.
(part): Removed.
(read_file): Handle device as well as file.
(cmd_crc): New function.
(fstest): Handle multiple disks.
(options): Remove part, raw and long, add root and diskcount.
(usage): Add crc, remove -p, -r, -l, add -r and -c.
(main): Find the first non option entry and ignore subsequence options,
add handling for the new options, support multiple disks.
* util/grub-probe.c (probe): Add mdraid to abstraction_name.
* disk/ata.c (grub_ata_regget): Change return type to
`grub_uint8_t'.
(grub_ata_regget2): Likewise.
(grub_ata_wait_status): New function.
(grub_ata_wait_busy): Removed function, updated all users to use
`grub_ata_wait_status'.
(grub_ata_wait_drq): Likewise.
(grub_ata_cmd): New function.
(grub_ata_pio_read): Change return type to `grub_uint8_t'. Add
error handling.
(grub_ata_pio_write): Add error handling.
(grub_atapi_identify): Likewise.
(grub_atapi_packet): Use `grub_ata_cmd' and improve error
handling.
(grub_ata_identify): Use `grub_ata_cmd' and improve error
handling. Actually use the detected registers. Reorder the
detection logic such that it is easier to read.
(grub_ata_pciinit): Do not assign the same ID to each controller.
(grub_ata_setaddress): Use `grub_ata_cmd' and improve error
handling.
(grub_atapi_readsector): Check the result of `grub_ata_pio_read'.
* include/grub/err.h (grub_err_t): Add `GRUB_ERR_TIMEOUT'.
* disk/memdisk.c (memdisk_size): Don't initialize.
(GRUB_MOD_INIT(memdisk)): Find memdisk using grub_module_iterate().
* include/grub/i386/pc/kernel.h
(GRUB_KERNEL_MACHINE_MEMDISK_IMAGE_SIZE): Remove macro.
(GRUB_KERNEL_MACHINE_PREFIX, GRUB_KERNEL_MACHINE_DATA_END): Shift.
(grub_memdisk_image_size, grub_arch_memdisk_addr)
(grub_arch_memdisk_size): Remove.
* include/grub/kernel.h (struct grub_module_header): Remove `offset'
field (was only used to transfer a constant). Add `type' field to
support multiple module types.
(grub_module_iterate): New function.
* kern/device.c (grub_device_open): Do not hide error messages
when grub_disk_open() fails. Use grub_print_error() instead.
* kern/i386/pc/init.c (grub_arch_modules_addr)
(grub_arch_memdisk_size): Remove functions.
(grub_arch_modules_addr): Return the module address in high memory
(now that it isn't copied anymore).
* kern/i386/pc/startup.S (grub_memdisk_image_size): Remove variable.
(codestart): Don't add grub_memdisk_image_size to %ecx in LZMA
decompression routine (grub_total_module_size already includes that
now). Don't copy modules back to low memory.
* kern/main.c: Include `<grub/mm.h>'.
(grub_load_modules): Split out (and use) ...
(grub_module_iterate): ... this function, which iterates through
module objects and runs a hook.
Comment out grub_mm_init_region() call, as it would cause non-ELF
modules to be overwritten.
* util/i386/pc/grub-mkimage.c (generate_image): Instead of appending
the memdisk image in its own region, make it part of the module list.
* util/elf/grub-mkimage.c (options): Add "memdisk"|'m' option.
(main): Parse --memdisk|-m option, and pass user-provided path as
parameter to generate_image().
(add_segments): Pass `memdisk_path' down to load_modules().
(load_modules): Embed memdisk image in module section when requested.
* util/i386/efi/grub-mkimage.c (make_mods_section): Initialize
`header.type' instead of `header.offset'.
* conf/powerpc-ieee1275.rmk (pkglib_MODULES): Add `memdisk.mod'.
(memdisk_mod_SOURCES, memdisk_mod_CFLAGS)
(memdisk_mod_LDFLAGS): New variables.
* conf/i386-coreboot.rmk: Likewise.
* conf/i386-ieee1275.rmk: Likewise.
* disk/raid.c (grub_raid_scan_device): Do not abort when two disks
with the same number are found, just use issue a warning with
grub_dprintf(), as this error has been reported to be non-fatal.
This fixes a performance issue when pc & gpt partmap iterators
didn't abort iteration even after our hook found what it was
looking for (often causing expensive probes of non-existant drives).
Some callers relied on previous buggy behaviour, since they would
rise an error when their own hooks caused early abortion of its
iteration.
* kern/device.c (grub_device_open): Improve error message.
* disk/lvm.c (grub_lvm_open): Likewise.
* disk/raid.c (grub_raid_open): Likewise.
* partmap/pc.c (pc_partition_map_iterate): Abort parent iteration
when hook requests it, independently of grub_errno.
(pc_partition_map_probe): Do not fail when find_func() caused
early abortion of pc_partition_map_iterate().
* partmap/gpt.c (gpt_partition_map_iterate): Abort parent iteration
when hook requests it, independently of grub_errno.
(gpt_partition_map_probe): Do not fail when find_func() caused
early abortion of gpt_partition_map_iterate().
* kern/partition.c (grub_partition_iterate): Abort parent iteration
when hook requests it, independently of grub_errno. Do not fail when
part_map_iterate_hook() caused early abortion of p->iterate().
* util/biosdisk.c (grub_util_biosdisk_get_grub_dev): Do not fail
when grub_partition_iterate() returned with non-zero.
* disk/ata.c (grub_ata_pio_write): Check status before writing,
like we do in grub_ata_pio_read().
(grub_ata_readwrite): Always write individual sectors. Fix the
sector count for the remainder.
(grub_ata_write): Enable writing to ATA devices. Correctly
report error for ATAPI devices.
* disk/ata.c (grub_ata_readwrite): Don't increment sector number
for every read sector, we already increment it for the whole
batch. This fixes reading more than 256 sectors at once.
* disk/raid.c: Cast grub_dprintf() arguments to unsigned long
long if the format specifier expects it.
* partmap/gpt.c (gpt_partition_map_iterate): Likewise.
* partmap/pc.c (pc_partition_map_iterate): Likewise.
* fs/ntfs.c (grub_ntfs_uuid): Cast data->uuid to unsigned long
long to fix a warning.
* fs/reiserfs.c (grub_reiserfs_read): Change casts in
grub_dprintf() arguments to fix warnings.
* disk/i386/pc/biosdisk.c (grub_biosdisk_iterate): Iterate through
floppies after everything else, to ensure floppy drive isn't accessed
unnecessarily (patch from Bean).
* Makefile.in (RMKFILES): Add missing arch i386-ieee1275 and
i386-linuxbios.
* commands/hexdump.c (grub_cmd_hexdump): Support dumping of device,
change the buffer size to 4096 for cdrom device.
* conf/i386-ieee1275.rmk (pkglib_MODULES): Add _linux.mod, linux.mod
and nand.mod.
(_linux_mod_SOURCES): New variable.
(_linux_mod_CFLAGS): Likewise.
(_linux_mod_LDFLAGS): Likewise.
(linux_mod_SOURCES): Likewise.
(linux_mod_CFLAGS): Likewise.
(linux_mod_LDFLAGS): Likewise.
(nand_mod_SOURCES): Likewise.
(nand_mod_CFLAGS): Likewise.
(nand_mod_LDFLAGS): Likewise.
* disk/ieee1275/ofdisk.c (grub_ofdisk_open): Return
GRUB_ERR_UNKNOWN_DEVICE instead of GRUB_ERR_BAD_DEVICE if no device
type property. (nand device in olpc don't have this property)
* include/grub/disk.h (grub_disk_dev_id): New macro
GRUB_DISK_DEVICE_NAND_ID.
* include/grub/i386/ieee1275/loader.h (grub_rescue_cmd_linux): New
function prototype.
(grub_rescue_cmd_initrd): Likewise.
* include/grub/i386/linux.h (GRUB_LINUX_OFW_SIGNATURE): New macro.
(linux_kernel_params): Add new member ofw_signature, ofw_num_items,
ofw_cif_handler and ofw_idt, adjust padding number.
* include/grub/i386/pc/memory.h (grub_upper_mem): Export it if
GRUB_MACHINE_IEEE1275 is defined.
* include/grub/ieee1275/ieee1275.h (grub_available_iterate):
Use NESTED_FUNC_ATTR attribute on the hook parameter.
* kern/powerpc/ieee1275/init.c (grub_claim_heap): Use NESTED_FUNC_ATTR
on nested function heap_init.
(grub_upper_mem): New variable for i386-ieee1275.
(grub_get_extended_memory): New function for i386-ieee1275.
(grub_machine_init): Call grub_get_extended_memory for i386-ieee1275.
* kern/powerpc/ieee1275/openfw.c (grub_available_iterate): Use
NESTED_FUNC_ATTR on the hook parameter. Don't quit if no device type
property.
* loader/i386/ieee1275/linux.c: New file.
* loader/i386/ieee1275/linux_normal.c: New file.
* disk/ieee1275/nand.c: New file.