From 2c40cc7868265137b8b8e0bbfc16f004d792c8cf Mon Sep 17 00:00:00 2001 From: Robert Millan Date: Mon, 18 Jan 2010 14:17:47 +0000 Subject: [PATCH 001/869] Import Tristan Gingold's ia64 port (based on patch sent to grub-devel by Tristan in 2008-01-28) --- ChangeLog.ia64 | 45 ++ Makefile.in | 3 +- commands/efi/acpi.c | 193 ++++++++ commands/efi/memmap.c | 143 ++++++ commands/efi/systab.c | 258 +++++++++++ conf/ia64-efi.rmk | 122 +++++ configure.ac | 5 +- geninit.sh | 2 +- genmk.rb | 2 +- include/grub/dl.h | 14 +- include/grub/efi/efi.h | 7 + include/grub/ia64/efi/kernel.h | 33 ++ include/grub/ia64/efi/loader.h | 30 ++ include/grub/ia64/efi/misc.h | 24 + include/grub/ia64/efi/time.h | 23 + include/grub/ia64/setjmp.h | 31 ++ include/grub/ia64/time.h | 28 ++ include/grub/ia64/types.h | 32 ++ include/grub/kernel.h | 2 +- kern/dl.c | 23 + kern/efi/mm.c | 90 ++-- kern/ia64/efi/elf_ia64_efi.lds | 84 ++++ kern/ia64/efi/init.c | 59 +++ kern/ia64/efi/startup.S | 40 ++ kern/ia64/trampoline.S | 38 ++ loader/ia64/efi/linux.c | 776 +++++++++++++++++++++++++++++++ loader/ia64/efi/linux_normal.c | 107 +++++ normal/ia64/longjmp.S | 162 +++++++ normal/ia64/setjmp.S | 171 +++++++ util/ia64/efi/elf2pe.c | 812 +++++++++++++++++++++++++++++++++ util/ia64/efi/grub-install.in | 233 ++++++++++ util/ia64/efi/pe32.h | 237 ++++++++++ 32 files changed, 3791 insertions(+), 38 deletions(-) create mode 100644 ChangeLog.ia64 create mode 100644 commands/efi/acpi.c create mode 100644 commands/efi/memmap.c create mode 100644 commands/efi/systab.c create mode 100644 conf/ia64-efi.rmk create mode 100644 include/grub/ia64/efi/kernel.h create mode 100644 include/grub/ia64/efi/loader.h create mode 100644 include/grub/ia64/efi/misc.h create mode 100644 include/grub/ia64/efi/time.h create mode 100644 include/grub/ia64/setjmp.h create mode 100644 include/grub/ia64/time.h create mode 100644 include/grub/ia64/types.h create mode 100644 kern/ia64/efi/elf_ia64_efi.lds create mode 100644 kern/ia64/efi/init.c create mode 100644 kern/ia64/efi/startup.S create mode 100644 kern/ia64/trampoline.S create mode 100644 loader/ia64/efi/linux.c create mode 100644 loader/ia64/efi/linux_normal.c create mode 100644 normal/ia64/longjmp.S create mode 100644 normal/ia64/setjmp.S create mode 100644 util/ia64/efi/elf2pe.c create mode 100644 util/ia64/efi/grub-install.in create mode 100644 util/ia64/efi/pe32.h diff --git a/ChangeLog.ia64 b/ChangeLog.ia64 new file mode 100644 index 000000000..35417bec0 --- /dev/null +++ b/ChangeLog.ia64 @@ -0,0 +1,45 @@ +2008-01-28 Tristan Gingold + + * geninit.sh: Call _init with a null argument. + * configure.ac: Add ia64-efi target. + * Makefile.in (STRIP_FLAGS): Declare (overriden on ia64). + (RMKFILES): Add ia64-efi.rmk + * genmk.rb: Use STRIP_FLAGS for strip. + * util/ia64/efi/grub-install.in: New file. + * util/ia64/efi/pe32.h: New file. + * util/ia64/efi/elf2pe.c: New file. + * normal/ia64/setjmp.S: New file (from glibc). + * normal/ia64/longjmp.S: New file (from glibc). + * loader/ia64/efi/linux_normal.c: New file. + * loader/ia64/efi/linux.c: New file. + * conf/ia64-efi.rmk: New file. + * commands/efi/systab.c: New file. + * commands/efi/memmap.c: New file. + * commands/efi/acpi.c: New file. + * include/grub/efi/efi.h: Declare grub_efi_allocate_boot_pages and + grub_efi_free_boot_pages. + * include/grub/kernel.h: Export grub_machine_fini. + * include/grub/dl.h: Use attribute instead of raw asm statement. + Use grub_module as prefix to make identification easier. + * include/grub/ia64/efi/time.h: New file. + * include/grub/ia64/efi/misc.h: New file. + * include/grub/ia64/efi/loader.h: New file. + * include/grub/ia64/efi/kernel.h: New file. + * include/grub/ia64/time.h: New file. + * include/grub/ia64/setjmp.h: New file. + * include/grub/ia64/types.h: New file. + * kern/efi/mm.c (BYTES_TO_PAGES): Round instead of truncating. + (grub_efi_allocate_boot_pages): Low level interface to allocate_pages. + (grub_efi_free_boot_pages): Low level interface to free_pages. + (grub_efi_allocate_pages): Call grub_efi_allocate_boot_pages. + (grub_efi_free_pages): Call grubčefi_free_boot_pages. + (add_memory_regions): Add debug message in ifdef. + (add_memory_regions): Add debug message in ifdef. + (grub_efi_mm_init): Do not constraint memory map length, add space for + a few more entries. + * kern/dl.c (grub_init_module): New function. Register an already + linked module. + * kern/ia64/efi/elf_ia64_efi.lds: New file. + * kern/ia64/efi/startup.S: New file. + * kern/ia64/efi/init.c: New file. + * kern/ia64/trampoline.S: New file. diff --git a/Makefile.in b/Makefile.in index 84b4e9c7c..134505d3c 100644 --- a/Makefile.in +++ b/Makefile.in @@ -67,6 +67,7 @@ TARGET_CFLAGS = @TARGET_CFLAGS@ TARGET_CPPFLAGS = @TARGET_CPPFLAGS@ -I. -Iinclude -I$(srcdir)/include \ -Wall -W TARGET_LDFLAGS = @TARGET_LDFLAGS@ +STRIP_FLAGS=--strip-unneeded -K grub_mod_init -K grub_mod_fini -R .note -R .comment OBJCOPY = @OBJCOPY@ STRIP = @STRIP@ NM = @NM@ @@ -83,7 +84,7 @@ enable_grub_emu = @enable_grub_emu@ ### General variables. RMKFILES = $(addprefix conf/,common.rmk i386-pc.rmk powerpc-ieee1275.rmk \ - sparc64-ieee1275.rmk i386-efi.rmk) + sparc64-ieee1275.rmk i386-efi.rmk ia64-efi.rmk) MKFILES = $(patsubst %.rmk,%.mk,$(RMKFILES)) PKGLIB = $(pkglib_IMAGES) $(pkglib_MODULES) $(pkglib_PROGRAMS) \ diff --git a/commands/efi/acpi.c b/commands/efi/acpi.c new file mode 100644 index 000000000..ea9783f00 --- /dev/null +++ b/commands/efi/acpi.c @@ -0,0 +1,193 @@ +/* acpi.c - Display acpi. */ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2008 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 . + */ +#include +#include +#include +#include + +static grub_uint32_t read16 (grub_uint8_t *p) +{ + return p[0] | (p[1] << 8); +} + +static grub_uint32_t read32 (grub_uint8_t *p) +{ + return p[0] | (p[1] << 8) | (p[2] << 16) | (p[3] << 24); +} + +static grub_uint64_t read64 (grub_uint8_t *p) +{ + grub_uint32_t l, h; + l = read32(p); + h = read32(p + 4); + return l | (((grub_uint64_t)h) << 32); +} + +static void +disp_acpi_table (grub_uint8_t *t) +{ + int i; + grub_printf ("%c%c%c%c %4dB rev=%d OEM=", t[0], t[1], t[2], t[3], + read32 (t + 4), t[8]); + for (i = 0; i < 6; i++) + grub_printf ("%c", t[10 + i]); + grub_printf (" "); + for (i = 0; i < 8; i++) + grub_printf ("%c", t[16 + i]); + grub_printf (" V=%08lx ", read32 (t + 24)); + for (i = 0; i < 4; i++) + grub_printf ("%c", t[28 + i]); + grub_printf (" %08lx\n", read32 (t + 32)); + +} + +static void +disp_acpi_apic_table (grub_uint8_t *t) +{ + grub_uint8_t *d; + grub_uint32_t len; + grub_uint32_t flags; + + disp_acpi_table (t); + grub_printf ("Local APIC=%08lx Flags=%08lx\n", + read32 (t + 36), read32 (t + 40)); + len = read32 (t + 4); + len -= 44; + d = t + 44; + while (len > 0) + { + grub_uint32_t l = d[1]; + grub_printf (" type=%x l=%d ", d[0], l); + + switch (d[0]) + { + case 2: + grub_printf ("Int Override bus=%x src=%x GSI=%08x Flags=%04x", + d[2], d[3], read32 (d + 4), read16 (d + 8)); + break; + case 6: + grub_printf ("IOSAPIC Id=%02x GSI=%08x Addr=%016llx", + d[2], read32 (d + 4), read64 (d + 8)); + break; + case 7: + flags = read32 (d + 8); + grub_printf ("LSAPIC ProcId=%02x ID=%02x EID=%02x Flags=%x", + d[2], d[3], d[4], flags); + if (flags & 1) + grub_printf (" Enabled"); + else + grub_printf (" Disabled"); + if (l >= 17) + grub_printf ("\n" + " UID val=%08x, Str=%s", read32 (d + 12), d + 16); + break; + case 8: + grub_printf ("Platform INT flags=%04x type=%02x (", + read16 (d + 2), d[4]); + if (d[4] <= 3) + { + static const char * const platint_type[4] = + {"Nul", "PMI", "INIT", "CPEI"}; + grub_printf ("%s", platint_type[d[4]]); + } + else + grub_printf ("??"); + grub_printf (") ID=%02x EID=%02x\n", d[5], d[6]); + grub_printf (" IOSAPIC Vec=%02x GSI=%08x source flags=%08x", + d[7], read32 (d + 8), read32 (d + 12)); + break; + default: + grub_printf (" ??"); + } + grub_printf ("\n"); + d += l; + len -= l; + } +} + +static void +disp_acpi_xsdt_table (grub_uint8_t *t) +{ + grub_uint32_t len; + grub_uint8_t *desc; + + disp_acpi_table (t); + len = read32 (t + 4) - 36; + desc = t + 36; + while (len > 0) + { + t = read64 (desc); + + if (t[0] == 'A' && t[1] == 'P' && t[2] == 'I' && t[3] == 'C') + disp_acpi_apic_table (t); + else + disp_acpi_table (t); + desc += 8; + len -= 8; + } +} + +static void +disp_acpi_rsdt_table (grub_uint8_t *t) +{ + grub_uint32_t len; + grub_uint8_t *desc; + + disp_acpi_table (t); + len = read32 (t + 4) - 36; + desc = t + 36; + while (len > 0) + { + t = read32 (desc); + + if (t != NULL) + disp_acpi_table (t); + desc += 4; + len -= 4; + } +} + +void +disp_acpi_rsdp_table (grub_uint8_t *rsdp) +{ + grub_uint8_t *t = rsdp; + int i; + grub_uint8_t *xsdt; + + grub_printf ("RSDP signature:"); + for (i = 0; i < 8; i++) + grub_printf ("%c", t[i]); + grub_printf (" chksum:%02x, OEM-ID: ", t[8]); + for (i = 0; i < 6; i++) + grub_printf ("%c", t[9 + i]); + grub_printf (" rev=%d\n", t[15]); + grub_printf ("RSDT=%08lx", read32 (t + 16)); + if (t[15] == 2) + { + xsdt = read64 (t + 24); + grub_printf (" len=%d XSDT=%016llx\n", read32 (t + 20), xsdt); + grub_printf ("\n"); + disp_acpi_xsdt_table (xsdt); + } + else + { + grub_printf ("\n"); + disp_acpi_rsdt_table (read32 (t + 16)); + } +} diff --git a/commands/efi/memmap.c b/commands/efi/memmap.c new file mode 100644 index 000000000..a3ce82841 --- /dev/null +++ b/commands/efi/memmap.c @@ -0,0 +1,143 @@ +/* memmap.c - Display memory map. */ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2008 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 . + */ +#include +#include +#include +#include +#include +#include + +#define ADD_MEMORY_DESCRIPTOR(desc, size) \ + ((grub_efi_memory_descriptor_t *) ((char *) (desc) + (size))) + +static grub_err_t +grub_cmd_memmap (struct grub_arg_list *state, int argc, char **args) +{ + grub_efi_uintn_t map_size; + grub_efi_memory_descriptor_t *memory_map; + grub_efi_memory_descriptor_t *memory_map_end; + grub_efi_memory_descriptor_t *desc; + grub_efi_uintn_t desc_size; + + map_size = 0; + if (grub_efi_get_memory_map (&map_size, NULL, NULL, &desc_size, 0) < 0) + return 0; + + memory_map = grub_malloc (map_size); + if (memory_map == NULL) + return 0; + if (grub_efi_get_memory_map (&map_size, memory_map, NULL, &desc_size, 0) < 0) + goto fail; + + grub_set_more (1); + + grub_printf + ("Type Physical start - end #Pages " + " Size Attributes\n"); + memory_map_end = ADD_MEMORY_DESCRIPTOR(memory_map, map_size); + for (desc = memory_map; + desc < memory_map_end; + desc = ADD_MEMORY_DESCRIPTOR (desc, desc_size)) + { + grub_efi_uintn_t size; + grub_efi_uint64_t attr; + static const char types_str[][9] = + { + "reserved", + "ldr-code", + "ldr-data", + "BS-code ", + "BS-data ", + "RT-code ", + "RT-data ", + "conv-mem", + "unusable", + "ACPI-rec", + "ACPI-nvs", + "MMIO ", + "IO-ports", + "PAL-code" + }; + if (desc->type < sizeof (types_str) / sizeof (types_str[0])) + grub_printf ("%s ", types_str[desc->type]); + else + grub_printf ("Unk %02x ", desc->type); + + grub_printf (" %016llx-%016llx %08lx", + desc->physical_start, + desc->physical_start + (desc->num_pages << 12) - 1, + desc->num_pages); + + size = desc->num_pages << (12 - 10); + if (size < 1024) + grub_printf (" %4uKB", size); + else + { + size /= 1024; + if (size < 1024) + grub_printf (" %4uMB", size); + else + { + size /= 1024; + grub_printf (" %4uGB", size); + } + } + + attr = desc->attribute; + if (attr & GRUB_EFI_MEMORY_RUNTIME) + grub_printf (" RT"); + if (attr & GRUB_EFI_MEMORY_UC) + grub_printf (" UC"); + if (attr & GRUB_EFI_MEMORY_WC) + grub_printf (" WC"); + if (attr & GRUB_EFI_MEMORY_WT) + grub_printf (" WT"); + if (attr & GRUB_EFI_MEMORY_WB) + grub_printf (" WB"); + if (attr & GRUB_EFI_MEMORY_UCE) + grub_printf (" UCE"); + if (attr & GRUB_EFI_MEMORY_WP) + grub_printf (" WP"); + if (attr & GRUB_EFI_MEMORY_RP) + grub_printf (" RP"); + if (attr & GRUB_EFI_MEMORY_XP) + grub_printf (" XP"); + + grub_printf ("\n"); + } + + grub_set_more (0); + + fail: + grub_free (memory_map); + return 0; +} + +GRUB_MOD_INIT(memmap) +{ + (void)mod; /* To stop warning. */ + grub_register_command ("memmap", grub_cmd_memmap, GRUB_COMMAND_FLAG_BOTH, + "memmap", + "Display memory map.", NULL); +} + +GRUB_MOD_FINI(memmap) +{ + grub_unregister_command ("memmap"); +} diff --git a/commands/efi/systab.c b/commands/efi/systab.c new file mode 100644 index 000000000..1d90ca9ca --- /dev/null +++ b/commands/efi/systab.c @@ -0,0 +1,258 @@ +/* systab.c - Display EFI systab. */ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2008 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 . + */ +#include +#include +#include +#include +#include +#include + +#define ACPI_20_TABLE_GUID \ +{0x8868e871,0xe4f1,0x11d3,{0xbc,0x22,0x0,0x80,0xc7,0x3c,0x88,0x81}} +#define ACPI_TABLE_GUID \ +{0xeb9d2d30,0x2d88,0x11d3,{0x9a,0x16,0x0,0x90,0x27,0x3f,0xc1,0x4d}} +#define SAL_SYSTEM_TABLE_GUID \ +{0xeb9d2d32,0x2d88,0x11d3,{0x9a,0x16,0x0,0x90,0x27,0x3f,0xc1,0x4d}} +#define SMBIOS_TABLE_GUID \ +{0xeb9d2d31,0x2d88,0x11d3,{0x9a,0x16,0x0,0x90,0x27,0x3f,0xc1,0x4d}} +#define MPS_TABLE_GUID \ +{0xeb9d2d2f,0x2d88,0x11d3,{0x9a,0x16,0x0,0x90,0x27,0x3f,0xc1,0x4d}} +#define HCDP_TABLE_GUID \ +{0xf951938d,0x620b,0x42ef,{0x82,0x79,0xa8,0x4b,0x79,0x61,0x78,0x98}} + +struct guid_mapping +{ + grub_efi_guid_t guid; + const char *name; + void (*disp)(struct guid_mapping *map, void *table); +}; + +static void disp_sal (struct guid_mapping *map, void *table); +static void disp_acpi (struct guid_mapping *map, void *table); + +static const struct guid_mapping guid_mappings[] = + { + { ACPI_20_TABLE_GUID, "ACPI-2.0", disp_acpi}, + { ACPI_TABLE_GUID, "ACPI-1.0", disp_acpi}, + { SAL_SYSTEM_TABLE_GUID, "SAL", disp_sal}, + { SMBIOS_TABLE_GUID, "SMBIOS",NULL}, + { MPS_TABLE_GUID, "MPS", NULL}, + { HCDP_TABLE_GUID, "HCDP", NULL} + }; + +struct sal_system_table +{ + grub_uint32_t signature; + grub_uint32_t total_table_len; + grub_uint16_t sal_rev; + grub_uint16_t entry_count; + grub_uint8_t checksum; + grub_uint8_t reserved1[7]; + grub_uint16_t sal_a_version; + grub_uint16_t sal_b_version; + grub_uint8_t oem_id[32]; + grub_uint8_t product_id[32]; + grub_uint8_t reserved2[8]; +}; + +static void +disp_sal (struct guid_mapping *map, void *table) +{ + struct sal_system_table *t = table; + grub_uint8_t *desc = table; + grub_uint32_t len, l; + + grub_printf ("SAL rev: %02x, signature: %x, len:%x\n", + t->sal_rev, t->signature, t->total_table_len); + grub_printf ("nbr entry: %d, chksum: %02x, SAL version A: %02x B: %02x\n", + t->entry_count, t->checksum, + t->sal_a_version, t->sal_b_version); + grub_printf ("OEM-ID: %-32s\n", t->oem_id); + grub_printf ("Product-ID: %-32s\n", t->product_id); + + desc += sizeof (struct sal_system_table); + len = t->total_table_len - sizeof (struct sal_system_table); + while (len > 0) + { + switch (*desc) + { + case 0: + l = 48; + grub_printf (" Entry point: PAL=%016lx SAL=%016lx GP=%016lx\n", + *(grub_uint64_t*)(desc + 8), + *(grub_uint64_t*)(desc + 16), + *(grub_uint64_t*)(desc + 24)); + break; + case 1: + l = 32; + grub_printf (" Memory descriptor entry addr=%016llx len=%uKB\n", + *(grub_uint64_t*)(desc + 8), + *(grub_uint32_t*)(desc + 16) * 4); + grub_printf (" sal_used=%d attr=%x AR=%x attr_mask=%x " + "type=%x usage=%x\n", + desc[1], desc[2], desc[3], desc[4], desc[5], desc[6]); + break; + case 2: + l = 16; + grub_printf (" Platform features: %02x", desc[1]); + if (desc[1] & 0x01) + grub_printf (" BusLock"); + if (desc[1] & 0x02) + grub_printf (" IrqRedirect"); + if (desc[1] & 0x04) + grub_printf (" IPIRedirect"); + grub_printf ("\n"); + break; + case 3: + l = 32; + grub_printf (" TR type=%d num=%d va=%016llx pte=%016llx\n", + desc[1], desc[2], + *(grub_uint64_t *)(desc + 8), + *(grub_uint64_t *)(desc + 16)); + break; + case 4: + l = 16; + grub_printf (" PTC coherence nbr=%d addr=%016llx\n", + desc[1], *(grub_uint64_t *)(desc + 8)); + break; + case 5: + l = 16; + grub_printf (" AP wake-up: mec=%d vect=%x\n", + desc[1], *(grub_uint64_t *)(desc + 8)); + break; + default: + grub_printf (" unknown entry %d\n", *desc); + return; + } + desc += l; + len -= l; + } +} + +static void +disp_acpi (struct guid_mapping *map, void *table) +{ + disp_acpi_rsdp_table (table); +} + +static void +disp_systab (void) +{ + grub_efi_char16_t *vendor; + const grub_efi_system_table_t *st = grub_efi_system_table; + grub_efi_configuration_table_t *t; + unsigned int i; + + grub_printf ("Signature: %016llx revision: %08x\n", + st->hdr.signature, st->hdr.revision); + grub_printf ("Vendor: "); + for (vendor = st->firmware_vendor; *vendor; vendor++) + grub_printf ("%c", *vendor); + grub_printf (", Version=%x\n", st->firmware_revision); + + grub_printf ("%ld tables:\n", st->num_table_entries); + t = st->configuration_table; + for (i = 0; i < st->num_table_entries; i++) + { + unsigned int j; + + grub_printf ("%016llx ", (grub_uint64_t)t->vendor_table); + + grub_printf ("%08x-%04x-%04x-", + t->vendor_guid.data1, t->vendor_guid.data2, + t->vendor_guid.data3); + for (j = 0; j < 8; j++) + grub_printf ("%02x", t->vendor_guid.data4[j]); + + for (j = 0; j < sizeof (guid_mappings)/sizeof(guid_mappings[0]); j++) + if (grub_memcmp (&guid_mappings[j].guid, &t->vendor_guid, + sizeof (grub_efi_guid_t)) == 0) + grub_printf (" %s", guid_mappings[j].name); + + grub_printf ("\n"); + t++; + } +} + +static void +disp_systab_entry (const char *name) +{ + const grub_efi_system_table_t *st = grub_efi_system_table; + grub_efi_configuration_table_t *t; + unsigned int i; + struct guid_mapping *map; + + map = NULL; + for (i = 0; i < sizeof (guid_mappings)/sizeof(guid_mappings[0]); i++) + if (grub_strcmp (guid_mappings[i].name, name) == 0) + { + map = &guid_mappings[i]; + break; + } + if (map == NULL) + { + grub_printf ("System table '%s' unknown\n", name); + return; + } + if (map->disp == NULL) + { + grub_printf ("Don't know how to display table '%s'\n", name); + return; + } + t = st->configuration_table; + for (i = 0; i < st->num_table_entries; i++) + { + if (grub_memcmp (&map->guid, &t->vendor_guid, + sizeof (grub_efi_guid_t)) == 0) + { + grub_set_more (1); + (*map->disp)(map, t->vendor_table); + grub_set_more (0); + return; + } + t++; + } + grub_printf ("Systab '%s' not found\n", map->name); +} + +static grub_err_t +grub_cmd_systab (struct grub_arg_list *state, int argc, char **args) +{ + int i; + + if (argc == 0) + disp_systab (); + else + for (i = 0; i < argc; i++) + disp_systab_entry (args[i]); + return 0; +} + +GRUB_MOD_INIT(systab) +{ + (void)mod; /* To stop warning. */ + grub_register_command ("systab", grub_cmd_systab, GRUB_COMMAND_FLAG_BOTH, + "systab [NAME]", + "Display EFI system table.", NULL); +} + +GRUB_MOD_FINI(systab) +{ + grub_unregister_command ("systab"); +} diff --git a/conf/ia64-efi.rmk b/conf/ia64-efi.rmk new file mode 100644 index 000000000..ce72d14c0 --- /dev/null +++ b/conf/ia64-efi.rmk @@ -0,0 +1,122 @@ +# -*- makefile -*- + +COMMON_ASFLAGS = -nostdinc -fno-builtin +COMMON_CFLAGS = -fno-builtin -fpic -minline-int-divide-max-throughput +COMMON_LDFLAGS = -melf_64 -nostdlib + +STRIP_FLAGS=-R .note -R .comment -X + +# Utilities. +bin_UTILITIES = grub-elf2pe +#sbin_UTILITIES = grub-emu + +# Scripts. +sbin_SCRIPTS = grub-install + +# For grub-install. +grub_install_SOURCES = util/ia64/efi/grub-install.in + +pkgdata_DATA += kern/ia64/efi/elf_ia64_efi.lds + +# For grub-elf2pe +grub_elf2pe_SOURCES = util/ia64/efi/elf2pe.c + +# For grub-emu. +grub_emu_SOURCES = commands/boot.c commands/cat.c commands/cmp.c \ + commands/configfile.c commands/help.c \ + commands/terminal.c commands/ls.c commands/test.c \ + commands/search.c commands/blocklist.c \ + disk/loopback.c \ + fs/affs.c fs/ext2.c fs/fat.c fs/fshelp.c fs/hfs.c fs/iso9660.c \ + fs/jfs.c fs/minix.c fs/sfs.c fs/ufs.c fs/xfs.c fs/hfsplus.c \ + io/gzio.c \ + kern/device.c kern/disk.c kern/dl.c kern/env.c kern/err.c \ + normal/execute.c kern/file.c kern/fs.c normal/lexer.c \ + kern/loader.c kern/main.c kern/misc.c kern/parser.c \ + grub_script.tab.c kern/partition.c kern/rescue.c kern/term.c \ + normal/arg.c normal/cmdline.c normal/command.c normal/function.c\ + normal/completion.c normal/main.c \ + normal/menu.c normal/menu_entry.c normal/misc.c normal/script.c \ + partmap/amiga.c partmap/apple.c partmap/pc.c partmap/sun.c \ + partmap/acorn.c partmap/gpt.c \ + util/console.c util/grub-emu.c util/misc.c \ + util/i386/pc/misc.c grub_emu_init.c + +grub_emu_LDFLAGS = $(LIBCURSES) + +# Modules. +pkglib_MODULES = kernel.mod normal.mod _chain.mod chain.mod \ + _linux.mod linux.mod memmap.mod systab.mod + +# For kernel.mod. +kernel_mod_EXPORTS = no +kernel_mod_SOURCES = kern/ia64/efi/startup.S \ + kern/ia64/trampoline.S \ + kern/main.c kern/device.c \ + kern/disk.c kern/dl.c kern/file.c kern/fs.c kern/err.c \ + kern/misc.c kern/mm.c kern/loader.c kern/rescue.c kern/term.c \ + kern/i386/dl.c kern/ia64/efi/init.c kern/parser.c kern/partition.c \ + kern/env.c symlist.c kern/efi/efi.c kern/efi/init.c kern/efi/mm.c \ + term/efi/console.c disk/efi/efidisk.c +kernel_mod_HEADERS = arg.h boot.h device.h disk.h dl.h elf.h env.h err.h \ + file.h fs.h kernel.h loader.h misc.h mm.h net.h parser.h partition.h \ + pc_partition.h rescue.h symbol.h term.h types.h cache.h \ + i386/efi/time.h efi/efi.h efi/time.h efi/disk.h ia64/efi/misc.h +kernel_mod_CFLAGS = $(COMMON_CFLAGS) +kernel_mod_ASFLAGS = $(COMMON_ASFLAGS) +kernel_mod_LDFLAGS = $(COMMON_LDFLAGS) + +MOSTLYCLEANFILES += symlist.c +MOSTLYCLEANFILES += symlist.c kernel_syms.lst +DEFSYMFILES += kernel_syms.lst + +symlist.c: $(addprefix include/grub/,$(kernel_mod_HEADERS)) config.h gensymlist.sh + /bin/sh gensymlist.sh $(filter %.h,$^) > $@ || (rm -f $@; exit 1) + +kernel_syms.lst: $(addprefix include/grub/,$(kernel_mod_HEADERS)) config.h genkernsyms.sh + /bin/sh genkernsyms.sh $(filter %.h,$^) > $@ || (rm -f $@; exit 1) + +# For normal.mod. +normal_mod_DEPENDENCIES = grub_script.tab.c grub_script.tab.h +normal_mod_SOURCES = normal/arg.c normal/cmdline.c normal/command.c \ + normal/completion.c normal/execute.c \ + normal/function.c normal/lexer.c normal/main.c normal/menu.c \ + normal/menu_entry.c normal/misc.c grub_script.tab.c \ + normal/script.c \ + normal/ia64/setjmp.S normal/ia64/longjmp.S normal/color.c + +normal_mod_CFLAGS = $(COMMON_CFLAGS) +normal_mod_ASFLAGS = $(COMMON_ASFLAGS) +normal_mod_LDFLAGS = $(COMMON_LDFLAGS) + +# For _chain.mod. +_chain_mod_SOURCES = loader/efi/chainloader.c +_chain_mod_CFLAGS = $(COMMON_CFLAGS) +_chain_mod_LDFLAGS = $(COMMON_LDFLAGS) + +# For chain.mod. +chain_mod_SOURCES = loader/efi/chainloader_normal.c +chain_mod_CFLAGS = $(COMMON_CFLAGS) +chain_mod_LDFLAGS = $(COMMON_LDFLAGS) + +# For _linux.mod. +_linux_mod_SOURCES = loader/ia64/efi/linux.c +_linux_mod_CFLAGS = $(COMMON_CFLAGS) +_linux_mod_LDFLAGS = $(COMMON_LDFLAGS) + +# For linux.mod. +linux_mod_SOURCES = loader/ia64/efi/linux_normal.c +linux_mod_CFLAGS = $(COMMON_CFLAGS) +linux_mod_LDFLAGS = $(COMMON_LDFLAGS) + +# For memmap.mod. +memmap_mod_SOURCES = commands/efi/memmap.c +memmap_mod_CFLAGS = $(COMMON_CFLAGS) +memmap_mod_LDFLAGS = $(COMMON_LDFLAGS) + +# For systab.mod. +systab_mod_SOURCES = commands/efi/systab.c commands/efi/acpi.c +systab_mod_CFLAGS = $(COMMON_CFLAGS) +systab_mod_LDFLAGS = $(COMMON_LDFLAGS) + +include $(srcdir)/conf/common.mk diff --git a/configure.ac b/configure.ac index b3f73e0bd..895b5ffc3 100644 --- a/configure.ac +++ b/configure.ac @@ -53,7 +53,8 @@ case "$target_cpu" in powerpc) ;; powerpc64) target_cpu=powerpc target_m32=1;; sparc64) ;; - *) AC_MSG_ERROR([unsupported CPU type]) ;; + ia64) ;; + *) AC_MSG_ERROR([unsupported CPU type $target_cpu]) ;; esac # Specify the platform (such as firmware). @@ -68,6 +69,7 @@ if test "x$with_platform" = x; then i386-*) platform=pc ;; powerpc-*) platform=ieee1275 ;; sparc64-*) platform=ieee1275 ;; + ia64*) platform=efi ;; *) AC_MSG_ERROR([unsupported machine type]) ;; esac else @@ -82,6 +84,7 @@ case "$target_cpu"-"$platform" in i386-ieee1275) ;; powerpc-ieee1275) ;; sparc64-ieee1275) ;; + ia64-efi) ;; *) AC_MSG_ERROR([unsupported machine type]) ;; esac diff --git a/geninit.sh b/geninit.sh index 43d2d1640..31a6d660b 100644 --- a/geninit.sh +++ b/geninit.sh @@ -49,7 +49,7 @@ EOF while read line; do file=`echo $line | cut -f1 -d:` if echo $@ | grep $file >/dev/null; then - echo $line | sed -e 's/.*GRUB_MOD_INIT *(\([a-zA-Z0-9_]*\)).*/ grub_\1_init ();/' + echo $line | sed -e 's/.*GRUB_MOD_INIT *(\([a-zA-Z0-9_]*\)).*/ grub_\1_init (0);/' fi done < ${lst} diff --git a/genmk.rb b/genmk.rb index 43dbeacf5..e4abd56d5 100644 --- a/genmk.rb +++ b/genmk.rb @@ -115,7 +115,7 @@ UNDSYMFILES += #{undsym} #{@name}: #{pre_obj} #{mod_obj} -rm -f $@ $(TARGET_CC) $(#{prefix}_LDFLAGS) $(TARGET_LDFLAGS) -Wl,-r,-d -o $@ $^ - $(STRIP) --strip-unneeded -K grub_mod_init -K grub_mod_fini -R .note -R .comment $@ + $(STRIP) $(STRIP_FLAGS) $@ #{pre_obj}: $(#{prefix}_DEPENDENCIES) #{objs_str} -rm -f $@ diff --git a/include/grub/dl.h b/include/grub/dl.h index b630c6fcd..017846d79 100644 --- a/include/grub/dl.h +++ b/include/grub/dl.h @@ -26,25 +26,27 @@ #define GRUB_MOD_INIT(name) \ static void grub_mod_init (grub_dl_t mod __attribute__ ((unused))) __attribute__ ((used)); \ -void grub_##name##_init (void); \ +void grub_module_##name##_init (grub_dl_t); \ void \ -grub_##name##_init (void) { grub_mod_init (0); } \ +grub_module_##name##_init (grub_dl_t mod) { grub_mod_init (mod); } \ static void \ grub_mod_init (grub_dl_t mod __attribute__ ((unused))) #define GRUB_MOD_FINI(name) \ static void grub_mod_fini (void) __attribute__ ((used)); \ -void grub_##name##_fini (void); \ +void grub_module_##name##_fini (void); \ void \ -grub_##name##_fini (void) { grub_mod_fini (); } \ +grub_module_##name##_fini (void) { grub_mod_fini (); } \ static void \ grub_mod_fini (void) #define GRUB_MOD_NAME(name) \ -__asm__ (".section .modname,\"S\"\n.string \"" #name "\"\n.previous") +static const char grub_module_name_##name[] \ + __attribute__((section(".modname"), __used__)) = #name #define GRUB_MOD_DEP(name) \ -__asm__ (".section .moddeps,\"S\"\n.string \"" #name "\"\n.previous") +static const char grub_module_depend_##name[] \ + __attribute__((section(".moddeps"), __used__)) = #name struct grub_dl_segment { diff --git a/include/grub/efi/efi.h b/include/grub/efi/efi.h index fbc6be985..c45cbed02 100644 --- a/include/grub/efi/efi.h +++ b/include/grub/efi/efi.h @@ -42,6 +42,13 @@ EXPORT_FUNC(grub_efi_allocate_pages) (grub_efi_physical_address_t address, grub_efi_uintn_t pages); void EXPORT_FUNC(grub_efi_free_pages) (grub_efi_physical_address_t address, grub_efi_uintn_t pages); +void * +EXPORT_FUNC(grub_efi_allocate_boot_pages) (grub_efi_physical_address_t address, + grub_efi_uintn_t pages); +void +EXPORT_FUNC(grub_efi_free_boot_pages) (grub_efi_physical_address_t address, + grub_efi_uintn_t pages); + int EXPORT_FUNC(grub_efi_get_memory_map) (grub_efi_uintn_t *memory_map_size, grub_efi_memory_descriptor_t *memory_map, diff --git a/include/grub/ia64/efi/kernel.h b/include/grub/ia64/efi/kernel.h new file mode 100644 index 000000000..c0549f41a --- /dev/null +++ b/include/grub/ia64/efi/kernel.h @@ -0,0 +1,33 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2002,2003,2007 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 . + */ + +#ifndef GRUB_MACHINE_KERNEL_HEADER +#define GRUB_MACHINE_KERNEL_HEADER 1 + +/* The prefix which points to the directory where GRUB modules and its + configuration file are located. */ +extern char grub_prefix[]; + +/* The offset of GRUB_PREFIX. */ +#define GRUB_KERNEL_MACHINE_PREFIX 0x8 + +/* End of the data section. */ +#define GRUB_KERNEL_MACHINE_DATA_END 0x50 + +#endif /* ! GRUB_MACHINE_KERNEL_HEADER */ + diff --git a/include/grub/ia64/efi/loader.h b/include/grub/ia64/efi/loader.h new file mode 100644 index 000000000..623ae5c49 --- /dev/null +++ b/include/grub/ia64/efi/loader.h @@ -0,0 +1,30 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2008 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 . + */ + +#ifndef GRUB_LOADER_MACHINE_HEADER +#define GRUB_LOADER_MACHINE_HEADER 1 + +/* It is necessary to export these functions, because normal mode commands + reuse rescue mode commands. */ +void grub_rescue_cmd_linux (int argc, char *argv[]); +void grub_rescue_cmd_initrd (int argc, char *argv[]); +void grub_rescue_cmd_module (int argc, char *argv[]); +void grub_rescue_cmd_relocate (int argc, char *argv[]); +void grub_rescue_cmd_fpswa (int argc, char *argv[]); + +#endif /* ! GRUB_LOADER_MACHINE_HEADER */ diff --git a/include/grub/ia64/efi/misc.h b/include/grub/ia64/efi/misc.h new file mode 100644 index 000000000..2037f7c24 --- /dev/null +++ b/include/grub/ia64/efi/misc.h @@ -0,0 +1,24 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2008 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 . + */ + +void EXPORT_FUNC (memset) (void); +void EXPORT_FUNC (__ia64_trampoline) (void); +void EXPORT_FUNC (grub_init_modules) (void); + +extern unsigned long EXPORT_VAR (__gp); + diff --git a/include/grub/ia64/efi/time.h b/include/grub/ia64/efi/time.h new file mode 100644 index 000000000..897ce9c00 --- /dev/null +++ b/include/grub/ia64/efi/time.h @@ -0,0 +1,23 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2008 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 . + */ +#ifndef GRUB_MACHINE_TIME_HEADER +#define GRUB_MACHINE_TIME_HEADER 1 + +#include + +#endif /* ! GRUB_MACHINE_TIME_HEADER */ diff --git a/include/grub/ia64/setjmp.h b/include/grub/ia64/setjmp.h new file mode 100644 index 000000000..c3b2d3be7 --- /dev/null +++ b/include/grub/ia64/setjmp.h @@ -0,0 +1,31 @@ +/* Define the machine-dependent type `jmp_buf'. Linux/IA-64 version. + Copyright (C) 1999, 2000 Free Software Foundation, Inc. + Contributed by David Mosberger-Tang . + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + The GNU C Library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with the GNU C Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + +/* User code must not depend on the internal representation of jmp_buf. */ + +#define _JBLEN 70 + +/* the __jmp_buf element type should be __float80 per ABI... */ +typedef long grub_jmp_buf[_JBLEN] __attribute__ ((aligned (16))); /* guarantees 128-bit alignment! */ + +#define grub_setjmp setjmp +#define grub_longjmp longjmp + +int grub_setjmp (grub_jmp_buf env); +void grub_longjmp (grub_jmp_buf env, int val) __attribute__ ((noreturn)); diff --git a/include/grub/ia64/time.h b/include/grub/ia64/time.h new file mode 100644 index 000000000..5db7ff4f1 --- /dev/null +++ b/include/grub/ia64/time.h @@ -0,0 +1,28 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2007 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 . + */ + +#ifndef KERNEL_CPU_TIME_HEADER +#define KERNEL_CPU_TIME_HEADER 1 + +static __inline void +grub_cpu_idle (void) +{ + /* FIXME: not implemented */ +} + +#endif /* ! KERNEL_CPU_TIME_HEADER */ diff --git a/include/grub/ia64/types.h b/include/grub/ia64/types.h new file mode 100644 index 000000000..91a546dd2 --- /dev/null +++ b/include/grub/ia64/types.h @@ -0,0 +1,32 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2008 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 . + */ + +#ifndef GRUB_TYPES_CPU_HEADER +#define GRUB_TYPES_CPU_HEADER 1 + +/* The size of void *. */ +#define GRUB_TARGET_SIZEOF_VOID_P 8 + +/* The size of long. */ +#define GRUB_TARGET_SIZEOF_LONG 8 + +/* ia64 is little-endian (usually). */ +#undef GRUB_TARGET_WORDS_BIGENDIAN + + +#endif /* ! GRUB_TYPES_CPU_HEADER */ diff --git a/include/grub/kernel.h b/include/grub/kernel.h index 4a4e2cc41..b1b8f5930 100644 --- a/include/grub/kernel.h +++ b/include/grub/kernel.h @@ -53,7 +53,7 @@ void grub_main (void); void grub_machine_init (void); /* The machine-specific finalization. */ -void grub_machine_fini (void); +void EXPORT_FUNC (grub_machine_fini) (void); /* The machine-specific prefix initialization. */ void grub_machine_set_prefix (void); diff --git a/kern/dl.c b/kern/dl.c index 9e8c24aba..c6c6f00ec 100644 --- a/kern/dl.c +++ b/kern/dl.c @@ -579,6 +579,29 @@ grub_dl_load_core (void *addr, grub_size_t size) return mod; } +void +grub_init_module (const char *name, + void (*init)(grub_dl_t), void (*fini)(void)) +{ + grub_dl_t mod; + + mod = (grub_dl_t) grub_malloc (sizeof (*mod)); + if (! mod) + return; + + mod->name = name; + mod->ref_count = 1; + mod->dep = 0; + mod->segment = 0; + mod->init = init; + mod->fini = fini; + + grub_dl_call_init (mod); + + /* Can't fail. */ + grub_dl_add (mod); +} + /* Load a module from the file FILENAME. */ grub_dl_t grub_dl_load_file (const char *filename) diff --git a/kern/efi/mm.c b/kern/efi/mm.c index 9cd096d7d..6e55e3655 100644 --- a/kern/efi/mm.c +++ b/kern/efi/mm.c @@ -22,16 +22,14 @@ #include #include +//#define DEBUG_MM + #define NEXT_MEMORY_DESCRIPTOR(desc, size) \ ((grub_efi_memory_descriptor_t *) ((char *) (desc) + (size))) -#define BYTES_TO_PAGES(bytes) ((bytes) >> 12) +#define BYTES_TO_PAGES(bytes) ((bytes + 0xfff) >> 12) #define PAGES_TO_BYTES(pages) ((pages) << 12) -/* The size of a memory map obtained from the firmware. This must be - a multiplier of 4KB. */ -#define MEMORY_MAP_SIZE 0x1000 - /* Maintain the list of allocated pages. */ struct allocated_page { @@ -49,11 +47,10 @@ static struct allocated_page *allocated_pages = 0; #define MIN_HEAP_SIZE 0x100000 #define MAX_HEAP_SIZE (16 * 0x100000) - /* Allocate pages. Return the pointer to the first of allocated pages. */ void * -grub_efi_allocate_pages (grub_efi_physical_address_t address, - grub_efi_uintn_t pages) +grub_efi_allocate_boot_pages (grub_efi_physical_address_t address, + grub_efi_uintn_t pages) { grub_efi_allocate_type_t type; grub_efi_status_t status; @@ -87,14 +84,34 @@ grub_efi_allocate_pages (grub_efi_physical_address_t address, { /* Uggh, the address 0 was allocated... This is too annoying, so reallocate another one. */ - address = 0xffffffff; status = b->allocate_pages (type, GRUB_EFI_LOADER_DATA, pages, &address); - grub_efi_free_pages (0, pages); + grub_efi_free_boot_pages (0, pages); if (status != GRUB_EFI_SUCCESS) return 0; } - if (allocated_pages) + return (void *)address; +} + +/* Free pages starting from ADDRESS. */ +void +grub_efi_free_boot_pages (grub_efi_physical_address_t address, + grub_efi_uintn_t pages) +{ + grub_efi_boot_services_t *b; + + b = grub_efi_system_table->boot_services; + b->free_pages (address, pages); +} + +/* Allocate pages. Return the pointer to the first of allocated pages. */ +void * +grub_efi_allocate_pages (grub_efi_physical_address_t address, + grub_efi_uintn_t pages) +{ + address = grub_efi_allocate_boot_pages (address, pages); + + if (address != 0 && allocated_pages) { unsigned i; @@ -118,8 +135,6 @@ void grub_efi_free_pages (grub_efi_physical_address_t address, grub_efi_uintn_t pages) { - grub_efi_boot_services_t *b; - if (allocated_pages && ((grub_efi_physical_address_t) ((grub_addr_t) allocated_pages) != address)) @@ -133,9 +148,8 @@ grub_efi_free_pages (grub_efi_physical_address_t address, break; } } - - b = grub_efi_system_table->boot_services; - b->free_pages (address, pages); + + grub_efi_free_boot_pages (address, pages); } /* Get the memory map as defined in the EFI spec. Return 1 if successful, @@ -278,7 +292,11 @@ add_memory_regions (grub_efi_memory_descriptor_t *memory_map, grub_efi_uint64_t required_pages) { grub_efi_memory_descriptor_t *desc; - + +#ifdef DEBUG_MM + grub_printf ("mm: required_pages=%lu\n", required_pages); +#endif + for (desc = memory_map; desc < memory_map_end; desc = NEXT_MEMORY_DESCRIPTOR (desc, desc_size)) @@ -303,6 +321,10 @@ add_memory_regions (grub_efi_memory_descriptor_t *memory_map, grub_mm_init_region (addr, PAGES_TO_BYTES (pages)); +#ifdef DEBUG_MM + grub_printf ("mm: add %lu pages from %p\n", pages, addr); +#endif + required_pages -= pages; if (required_pages == 0) break; @@ -344,6 +366,8 @@ grub_efi_mm_init (void) grub_efi_uintn_t desc_size; grub_efi_uint64_t total_pages; grub_efi_uint64_t required_pages; + grub_efi_uintn_t memory_map_size; + int res; /* First of all, allocate pages to maintain allocations. */ allocated_pages @@ -352,26 +376,35 @@ grub_efi_mm_init (void) grub_fatal ("cannot allocate memory"); grub_memset (allocated_pages, 0, ALLOCATED_PAGES_SIZE); - + /* Prepare a memory region to store two memory maps. */ - memory_map = grub_efi_allocate_pages (0, - 2 * BYTES_TO_PAGES (MEMORY_MAP_SIZE)); + memory_map_size = 0; + res = grub_efi_get_memory_map (&memory_map_size, NULL, 0, &desc_size, 0); + if (res != 0) + grub_fatal ("cannot get memory map size"); + + /* Add space for a few more entries as allocating pages can increase + memory map size. */ + memory_map_size += 4 * desc_size; + + memory_map = grub_efi_allocate_pages + (0, 2 * BYTES_TO_PAGES (memory_map_size)); if (! memory_map) grub_fatal ("cannot allocate memory"); - filtered_memory_map = NEXT_MEMORY_DESCRIPTOR (memory_map, MEMORY_MAP_SIZE); + filtered_memory_map = NEXT_MEMORY_DESCRIPTOR (memory_map, memory_map_size); /* Obtain descriptors for available memory. */ - map_size = MEMORY_MAP_SIZE; + map_size = memory_map_size; - if (grub_efi_get_memory_map (&map_size, memory_map, 0, &desc_size, 0) < 0) + if (grub_efi_get_memory_map (&map_size, memory_map, 0, &desc_size, 0) <= 0) grub_fatal ("cannot get memory map"); memory_map_end = NEXT_MEMORY_DESCRIPTOR (memory_map, map_size); filtered_memory_map_end = filter_memory_map (memory_map, filtered_memory_map, desc_size, memory_map_end); - + /* By default, request a quarter of the available memory. */ total_pages = get_total_pages (filtered_memory_map, desc_size, filtered_memory_map_end); @@ -391,7 +424,7 @@ grub_efi_mm_init (void) #if 0 /* For debug. */ - map_size = MEMORY_MAP_SIZE; + map_size = memory_map_size; if (grub_efi_get_memory_map (&map_size, memory_map, 0, &desc_size, 0) < 0) grub_fatal ("cannot get memory map"); @@ -404,7 +437,7 @@ grub_efi_mm_init (void) /* Release the memory maps. */ grub_efi_free_pages ((grub_addr_t) memory_map, - 2 * BYTES_TO_PAGES (MEMORY_MAP_SIZE)); + 2 * BYTES_TO_PAGES (memory_map_size)); } void @@ -420,10 +453,13 @@ grub_efi_mm_fini (void) p = allocated_pages + i; if (p->addr != 0) - grub_efi_free_pages ((grub_addr_t) p->addr, p->num_pages); + { + grub_efi_free_pages ((grub_addr_t) p->addr, p->num_pages); + } } grub_efi_free_pages ((grub_addr_t) allocated_pages, BYTES_TO_PAGES (ALLOCATED_PAGES_SIZE)); + allocated_pages = 0; } } diff --git a/kern/ia64/efi/elf_ia64_efi.lds b/kern/ia64/efi/elf_ia64_efi.lds new file mode 100644 index 000000000..b6889d4af --- /dev/null +++ b/kern/ia64/efi/elf_ia64_efi.lds @@ -0,0 +1,84 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2008 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 . + */ +OUTPUT_FORMAT("elf64-ia64-little") +OUTPUT_ARCH(ia64) +ENTRY(_start) +SECTIONS +{ + . = 0x240; + .text : + { + *(.text) + *(.text.*) + *(.rodata) + *(.rodata.*) + /* Reserve space for the entry point descriptor. */ + . = ALIGN(16); + QUAD(0) + QUAD(0) + } + . = ALIGN(0x20); + .got : + { + *(.got.plt) + *(.got) + . = ALIGN(0x10); + } + .opd : + { + *(.opd) + } + .sdata : + { + *(.srodata) + *(.sdata) + *(.sbss) + *(.scommon) + . = ALIGN(0x10); + } + .data : + { + *(.data*) + *(.dynbss) + *(.bss) + *(COMMON) + . = ALIGN(0x10); + } + .dynamic : { *(.dynamic) } + + . = ALIGN(4096); + .interp : { *(.interp) } + .plt : { *(.plt) } + .rela : + { + *(.rela.text*) + *(.rela.data*) + *(.rela.sdata) + *(.rela.got) + } + .hash : { *(.hash) } + .dynsym : { *(.dynsym) } + .dynstr : { *(.dynstr) } + /DISCARD/ : + { + *(.IA_64.unwind*) + *(.IA64.unwind*) + *(.moddeps) + *(.modname) + } +} diff --git a/kern/ia64/efi/init.c b/kern/ia64/efi/init.c new file mode 100644 index 000000000..c85ef6c42 --- /dev/null +++ b/kern/ia64/efi/init.c @@ -0,0 +1,59 @@ +/* init.c - initialize an ia64-based EFI system */ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2008 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 . + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +void +grub_machine_init (void) +{ + grub_efi_init (); + grub_init_modules (); +} + +void +grub_machine_fini (void) +{ + grub_efi_fini (); +} + +void +grub_machine_set_prefix (void) +{ + grub_efi_set_prefix (); +} + +void +grub_arch_sync_caches (void *address, grub_size_t len) +{ + /* Cache line length is at least 32. */ + grub_uint64_t a = (grub_uint64_t)address & ~0x1f; + + /* Flush data. */ + for (len = (len + 31) & ~0x1f; len > 0; len -= 0x20, a += 0x20) + asm volatile ("fc.i %0" : : "r" (a)); + /* Sync and serialize. Maybe extra. */ + asm volatile (";; sync.i;; srlz.i;;"); +} diff --git a/kern/ia64/efi/startup.S b/kern/ia64/efi/startup.S new file mode 100644 index 000000000..9ba6858d9 --- /dev/null +++ b/kern/ia64/efi/startup.S @@ -0,0 +1,40 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2008 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 . + */ + .text + .psr abi64 + .psr lsb + .lsb + + .global _start + .proc _start +_start: + alloc loc0=ar.pfs,2,4,0,0 + mov loc1=rp + addl loc2=@gprel(grub_efi_image_handle),gp + addl loc3=@gprel(grub_efi_system_table),gp + ;; + st8 [loc2]=in0 + st8 [loc3]=in1 + br.call.sptk.few rp=grub_main + ;; + mov ar.pfs=loc0 + mov rp=loc1 + ;; + br.ret.sptk.few rp + + .endp _start diff --git a/kern/ia64/trampoline.S b/kern/ia64/trampoline.S new file mode 100644 index 000000000..376b7bae0 --- /dev/null +++ b/kern/ia64/trampoline.S @@ -0,0 +1,38 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2008 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 . + */ + .text + .psr abi64 + .psr lsb + .lsb + + .proc __ia64_trampoline + .global __ia64_trampoline +__ia64_trampoline: + // Read address of the real descriptor + ld8 r2=[r1],8 + ;; + // Read chain + ld8 r15=[r1] + // Read pc + ld8 r3=[r2],8 + ;; + // Read gp + ld8 r1=[r2] + mov b6=r3 + br.many b6 + .endp __ia64_trampoline diff --git a/loader/ia64/efi/linux.c b/loader/ia64/efi/linux.c new file mode 100644 index 000000000..04c4638f8 --- /dev/null +++ b/loader/ia64/efi/linux.c @@ -0,0 +1,776 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2008 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 . + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +/* #include */ +#include +#include +#include +#include + +#define ALIGN_MIN (256*1024*1024) + +#define GRUB_ELF_SEARCH 1024 + +#define BOOT_PARAM_SIZE 16384 + +struct ia64_boot_param { + grub_uint64_t command_line; /* physical address of command line. */ + grub_uint64_t efi_systab; /* physical address of EFI system table */ + grub_uint64_t efi_memmap; /* physical address of EFI memory map */ + grub_uint64_t efi_memmap_size; /* size of EFI memory map */ + grub_uint64_t efi_memdesc_size; /* size of an EFI memory map descriptor */ + grub_uint32_t efi_memdesc_version; /* memory descriptor version */ + struct { + grub_uint16_t num_cols; /* number of columns on console output dev */ + grub_uint16_t num_rows; /* number of rows on console output device */ + grub_uint16_t orig_x; /* cursor's x position */ + grub_uint16_t orig_y; /* cursor's y position */ + } console_info; + grub_uint64_t fpswa; /* physical address of the fpswa interface */ + grub_uint64_t initrd_start; + grub_uint64_t initrd_size; + grub_uint64_t domain_start; /* boot domain address. */ + grub_uint64_t domain_size; /* how big is the boot domain */ + grub_uint64_t modules_chain; + grub_uint64_t modules_nbr; +}; + +struct ia64_boot_module { + grub_uint64_t mod_start; + grub_uint64_t mod_end; + + /* Module command line */ + grub_uint64_t cmdline; + + grub_uint64_t next; +}; + +typedef struct { + grub_uint32_t revision; + grub_uint32_t reserved; + void *fpswa; +} fpswa_interface_t; +static fpswa_interface_t *fpswa; + +#define NEXT_MEMORY_DESCRIPTOR(desc, size) \ + ((grub_efi_memory_descriptor_t *) ((char *) (desc) + (size))) + +static grub_dl_t my_mod; + +static int loaded; + +/* Kernel base and size. */ +static void *kernel_mem; +static grub_efi_uintn_t kernel_pages; +static grub_uint64_t entry; + +/* Initrd base and size. */ +static void *initrd_mem; +static grub_efi_uintn_t initrd_pages; +static grub_efi_uintn_t initrd_size; + +static struct ia64_boot_param *boot_param; +static grub_efi_uintn_t boot_param_pages; +static struct ia64_boot_module *last_module = NULL; + +/* Can linux kernel be relocated ? */ +#define RELOCATE_OFF 0 /* No. */ +#define RELOCATE_ON 1 /* Yes. */ +#define RELOCATE_FORCE 2 /* Always - used to debug. */ +static int relocate = RELOCATE_OFF; + +static inline grub_size_t +page_align (grub_size_t size) +{ + return (size + (1 << 12) - 1) & (~((1 << 12) - 1)); +} + +static void +query_fpswa (void) +{ + grub_efi_handle_t fpswa_image; + grub_efi_boot_services_t *bs; + grub_efi_status_t status; + grub_efi_uintn_t size; + static const grub_efi_guid_t fpswa_protocol = + { 0xc41b6531, 0x97b9, 0x11d3, + {0x9a, 0x29, 0x0, 0x90, 0x27, 0x3f, 0xc1, 0x4d} }; + + if (fpswa != NULL) + return; + + size = sizeof(grub_efi_handle_t); + + bs = grub_efi_system_table->boot_services; + status = bs->locate_handle (GRUB_EFI_BY_PROTOCOL, + &fpswa_protocol, + NULL, &size, &fpswa_image); + if (status != GRUB_EFI_SUCCESS) + { + grub_printf("Could not locate FPSWA driver\n"); + return; + } + status = bs->handle_protocol (fpswa_image, &fpswa_protocol, &fpswa); + if (status != GRUB_EFI_SUCCESS) + { + grub_printf ("Fpswa protocol not able find the interface\n"); + return; + } +} + +/* Find the optimal number of pages for the memory map. Is it better to + move this code to efi/mm.c? */ +static grub_efi_uintn_t +find_mmap_size (void) +{ + static grub_efi_uintn_t mmap_size = 0; + + if (mmap_size != 0) + return mmap_size; + + mmap_size = (1 << 12); + while (1) + { + int ret; + grub_efi_memory_descriptor_t *mmap; + grub_efi_uintn_t desc_size; + + mmap = grub_malloc (mmap_size); + if (! mmap) + return 0; + + ret = grub_efi_get_memory_map (&mmap_size, mmap, 0, &desc_size, 0); + grub_free (mmap); + + if (ret < 0) + grub_fatal ("cannot get memory map"); + else if (ret > 0) + break; + + mmap_size += (1 << 12); + } + + /* Increase the size a bit for safety, because GRUB allocates more on + later, and EFI itself may allocate more. */ + mmap_size += (1 << 12); + + return page_align (mmap_size); +} + +static void +free_pages (void) +{ + if (kernel_mem) + { + grub_efi_free_boot_pages ((grub_addr_t) kernel_mem, kernel_pages); + kernel_mem = 0; + } + + if (initrd_mem) + { + grub_efi_free_boot_pages ((grub_addr_t) initrd_mem, initrd_pages); + initrd_mem = 0; + } + + if (boot_param) + { + struct ia64_boot_module *mod; + struct ia64_boot_module *next_mod; + + /* Free modules. */ + mod = (struct ia64_boot_module *)boot_param->modules_chain; + while (mod != 0) + { + next_mod = (struct ia64_boot_module *)mod->next; + + grub_efi_free_boot_pages + (mod->mod_start, page_align (mod->mod_end - mod->mod_start) >> 12); + grub_efi_free_boot_pages ((grub_efi_physical_address_t)mod, 1); + + mod = next_mod; + } + + /* Free bootparam. */ + grub_efi_free_boot_pages ((grub_efi_physical_address_t)boot_param, + boot_param_pages); + boot_param = 0; + } +} + +static void * +allocate_pages (grub_uint64_t align, grub_uint64_t size_pages, + grub_uint64_t nobase) +{ + grub_uint64_t size; + grub_efi_uintn_t desc_size; + grub_efi_memory_descriptor_t *mmap, *mmap_end; + grub_efi_uintn_t mmap_size, tmp_mmap_size; + grub_efi_memory_descriptor_t *desc; + void *mem = NULL; + + size = size_pages << 12; + + mmap_size = find_mmap_size (); + + /* Read the memory map temporarily, to find free space. */ + mmap = grub_malloc (mmap_size); + if (! mmap) + return 0; + + tmp_mmap_size = mmap_size; + if (grub_efi_get_memory_map (&tmp_mmap_size, mmap, 0, &desc_size, 0) <= 0) + grub_fatal ("cannot get memory map"); + + mmap_end = NEXT_MEMORY_DESCRIPTOR (mmap, tmp_mmap_size); + + /* First, find free pages for the real mode code + and the memory map buffer. */ + for (desc = mmap; + desc < mmap_end; + desc = NEXT_MEMORY_DESCRIPTOR (desc, desc_size)) + { + grub_uint64_t start, end; + grub_uint64_t aligned_start; + + if (desc->type != GRUB_EFI_CONVENTIONAL_MEMORY) + continue; + + start = desc->physical_start; + end = start + (desc->num_pages << 12); + /* Align is a power of 2. */ + aligned_start = (start + align - 1) & ~(align - 1); + if (aligned_start + size > end) + continue; + if (aligned_start == nobase) + aligned_start += align; + if (aligned_start + size > end) + continue; + mem = grub_efi_allocate_pages (aligned_start, size_pages); + if (! mem) + grub_fatal ("cannot allocate pages"); + break; + } + + if (! mem) + { + grub_error (GRUB_ERR_OUT_OF_MEMORY, "cannot allocate memory"); + goto fail; + } + + grub_free (mmap); + return mem; + + fail: + grub_free (mmap); + free_pages (); + return 0; +} + +static void +set_boot_param_console (void) +{ + grub_efi_simple_text_output_interface_t *conout; + grub_efi_uintn_t cols, rows; + + conout = grub_efi_system_table->con_out; + if (conout->query_mode (conout, conout->mode->mode, &cols, &rows) + != GRUB_EFI_SUCCESS) + return; + + grub_dprintf("linux", + "Console info: cols=%lu rows=%lu x=%u y=%u\n", + cols, rows, + conout->mode->cursor_column, conout->mode->cursor_row); + + boot_param->console_info.num_cols = cols; + boot_param->console_info.num_rows = rows; + boot_param->console_info.orig_x = conout->mode->cursor_column; + boot_param->console_info.orig_y = conout->mode->cursor_row; +} + +static grub_err_t +grub_linux_boot (void) +{ + grub_efi_uintn_t mmap_size; + grub_efi_uintn_t map_key; + grub_efi_uintn_t desc_size; + grub_efi_uint32_t desc_version; + grub_efi_memory_descriptor_t *mmap_buf; + + /* FPSWA. */ + query_fpswa (); + boot_param->fpswa = (grub_uint64_t)fpswa; + + /* Initrd. */ + boot_param->initrd_start = (grub_uint64_t)initrd_mem; + boot_param->initrd_size = (grub_uint64_t)initrd_size; + + set_boot_param_console (); + + grub_printf ("Jump to %016lx\n", entry); + + grub_machine_fini (); + + /* MDT. + Must be done after grub_machine_fini because map_key is used by + exit_boot_services. */ + mmap_size = find_mmap_size (); + mmap_buf = grub_efi_allocate_boot_pages (0, page_align (mmap_size) >> 12); + if (! mmap_buf) + grub_fatal ("cannot allocate memory map"); + if (grub_efi_get_memory_map (&mmap_size, mmap_buf, &map_key, + &desc_size, &desc_version) <= 0) + grub_fatal ("cannot get memory map"); + + boot_param->efi_memmap = (grub_uint64_t)mmap_buf; + boot_param->efi_memmap_size = mmap_size; + boot_param->efi_memdesc_size = desc_size; + boot_param->efi_memdesc_version = desc_version; + + if (! grub_efi_exit_boot_services (map_key)) + grub_fatal ("cannot exit boot services"); + + /* See you next boot. */ + asm volatile ("mov r28=%1; br.sptk.few %0" :: "b"(entry),"r"(boot_param)); + + /* Never reach here. */ + return GRUB_ERR_NONE; +} + +static grub_err_t +grub_linux_unload (void) +{ + free_pages (); + grub_dl_unref (my_mod); + loaded = 0; + return GRUB_ERR_NONE; +} + +static grub_err_t +grub_load_elf64 (grub_file_t file, void *buffer) +{ + Elf64_Ehdr *ehdr = (Elf64_Ehdr *) buffer; + Elf64_Phdr *phdr; + int i; + grub_uint64_t low_addr; + grub_uint64_t high_addr; + grub_uint64_t align; + grub_uint64_t reloc_offset; + + if (ehdr->e_ident[EI_CLASS] != ELFCLASS64) + return grub_error (GRUB_ERR_UNKNOWN_OS, "invalid ELF class"); + + if (ehdr->e_ident[EI_MAG0] != ELFMAG0 + || ehdr->e_ident[EI_MAG1] != ELFMAG1 + || ehdr->e_ident[EI_MAG2] != ELFMAG2 + || ehdr->e_ident[EI_MAG3] != ELFMAG3 + || ehdr->e_version != EV_CURRENT + || ehdr->e_ident[EI_DATA] != ELFDATA2LSB + || ehdr->e_machine != EM_IA_64) + return grub_error(GRUB_ERR_UNKNOWN_OS, "no valid ELF header found"); + + if (ehdr->e_type != ET_EXEC) + return grub_error (GRUB_ERR_UNKNOWN_OS, "invalid ELF file type"); + + /* FIXME: Should we support program headers at strange locations? */ + if (ehdr->e_phoff + ehdr->e_phnum * ehdr->e_phentsize > GRUB_ELF_SEARCH) + return grub_error (GRUB_ERR_BAD_OS, "program header at a too high offset"); + + entry = ehdr->e_entry; + + /* Compute low, high and align addresses. */ + low_addr = ~0UL; + high_addr = 0; + align = 0; + for (i = 0; i < ehdr->e_phnum; i++) + { + phdr = (Elf64_Phdr *) ((char *) buffer + ehdr->e_phoff + + i * ehdr->e_phentsize); + if (phdr->p_type == PT_LOAD) + { + if (phdr->p_paddr < low_addr) + low_addr = phdr->p_paddr; + if (phdr->p_paddr + phdr->p_memsz > high_addr) + high_addr = phdr->p_paddr + phdr->p_memsz; + if (phdr->p_align > align) + align = phdr->p_align; + } + } + + if (align < ALIGN_MIN) + align = ALIGN_MIN; + + if (high_addr == 0) + return grub_error (GRUB_ERR_BAD_OS, "no program entries"); + + kernel_pages = page_align (high_addr - low_addr) >> 12; + + if (relocate != RELOCATE_FORCE) + { + kernel_mem = grub_efi_allocate_boot_pages (low_addr, kernel_pages); + reloc_offset = 0; + } + /* Try to relocate. */ + if (! kernel_mem && relocate != RELOCATE_OFF) + { + kernel_mem = allocate_pages (align, kernel_pages, low_addr); + if (kernel_mem) + { + reloc_offset = kernel_mem - low_addr; + grub_printf (" Relocated at %p (offset=%016llx)\n", + kernel_mem, reloc_offset); + entry += reloc_offset; + } + } + if (! kernel_mem) + return grub_error (GRUB_ERR_OUT_OF_MEMORY, + "cannot allocate memory for OS"); + + /* Load every loadable segment in memory. */ + for (i = 0; i < ehdr->e_phnum; i++) + { + phdr = (Elf64_Phdr *) ((char *) buffer + ehdr->e_phoff + + i * ehdr->e_phentsize); + if (phdr->p_type == PT_LOAD) + { + grub_printf (" [paddr=%llx load=%llx memsz=%08llx " + "off=%lx flags=%x]\n", + phdr->p_paddr, phdr->p_paddr + reloc_offset, + phdr->p_memsz, phdr->p_offset, phdr->p_flags); + + if (grub_file_seek (file, phdr->p_offset) == -1) + return grub_error (GRUB_ERR_BAD_OS, + "invalid offset in program header"); + + if (grub_file_read (file, (void *)(phdr->p_paddr + reloc_offset), + phdr->p_filesz) + != (grub_ssize_t) phdr->p_filesz) + return grub_error (GRUB_ERR_BAD_OS, + "couldn't read segment from file"); + + if (phdr->p_filesz < phdr->p_memsz) + grub_memset + ((char *)(phdr->p_paddr + reloc_offset + phdr->p_filesz), + 0, phdr->p_memsz - phdr->p_filesz); + + /* Sync caches if necessary. */ + if (phdr->p_flags & PF_X) + grub_arch_sync_caches + ((void *)(phdr->p_paddr + reloc_offset), phdr->p_memsz); + } + } + loaded = 1; + return 0; +} + +void +grub_rescue_cmd_linux (int argc, char *argv[]) +{ + grub_file_t file = 0; + char buffer[GRUB_ELF_SEARCH]; + char *cmdline, *p; + grub_ssize_t len; + int i; + + grub_dl_ref (my_mod); + + grub_loader_unset (); + + if (argc == 0) + { + grub_error (GRUB_ERR_BAD_ARGUMENT, "No kernel specified"); + goto fail; + } + + file = grub_gzfile_open (argv[0], 1); + if (! file) + { + grub_error (GRUB_ERR_BAD_ARGUMENT, "Couldn't open file"); + goto fail; + } + + len = grub_file_read (file, buffer, sizeof (buffer)); + if (len < (grub_ssize_t)sizeof (Elf64_Ehdr)) + { + grub_error (GRUB_ERR_BAD_OS, "File too small"); + goto fail; + } + + grub_printf ("Loading linux: %s\n", argv[0]); + + if (grub_load_elf64 (file, buffer)) + goto fail; + + len = sizeof("BOOT_IMAGE=") + 8; + for (i = 0; i < argc; i++) + len += grub_strlen (argv[i]) + 1; + len += sizeof (struct ia64_boot_param) + 256; /* Room for extensions. */ + boot_param_pages = page_align (len) >> 12; + boot_param = grub_efi_allocate_boot_pages (0, boot_param_pages); + if (boot_param == 0) + { + grub_error (GRUB_ERR_OUT_OF_MEMORY, + "cannot allocate memory for bootparams"); + goto fail; + } + + grub_memset (boot_param, 0, len); + cmdline = ((char *)(boot_param + 1)) + 256; + + /* Build cmdline. */ + p = grub_stpcpy (cmdline, "BOOT_IMAGE"); + for (i = 0; i < argc; i++) + { + *p++ = ' '; + p = grub_stpcpy (p, argv[i]); + } + cmdline[10] = '='; + + boot_param->command_line = (grub_uint64_t)cmdline; + boot_param->efi_systab = (grub_uint64_t)grub_efi_system_table; + + grub_errno = GRUB_ERR_NONE; + + grub_loader_set (grub_linux_boot, grub_linux_unload, 0); + + fail: + if (file) + grub_file_close (file); + + if (grub_errno != GRUB_ERR_NONE) + { + grub_efi_free_boot_pages ((grub_efi_physical_address_t)boot_param, + boot_param_pages); + grub_dl_unref (my_mod); + } +} + +void +grub_rescue_cmd_initrd (int argc, char *argv[]) +{ + grub_file_t file = 0; + + if (argc == 0) + { + grub_error (GRUB_ERR_BAD_ARGUMENT, "No module specified"); + goto fail; + } + + if (! loaded) + { + grub_error (GRUB_ERR_BAD_ARGUMENT, "You need to load the kernel first."); + goto fail; + } + + file = grub_gzfile_open (argv[0], 1); + if (! file) + goto fail; + + grub_printf ("Loading initrd: %s\n",argv[0]); + + initrd_size = grub_file_size (file); + initrd_pages = (page_align (initrd_size) >> 12); + initrd_mem = grub_efi_allocate_boot_pages (0, initrd_pages); + if (! initrd_mem) + grub_fatal ("cannot allocate pages"); + + grub_printf (" [addr=0x%lx, size=0x%lx]\n", + (grub_uint64_t)initrd_mem, initrd_size); + + if (grub_file_read (file, initrd_mem, initrd_size) + != (grub_ssize_t)initrd_size) + { + grub_error (GRUB_ERR_FILE_READ_ERROR, "Couldn't read file"); + goto fail; + } + fail: + if (file) + grub_file_close (file); +} + +void +grub_rescue_cmd_module (int argc, char *argv[]) +{ + grub_file_t file = 0; + grub_ssize_t size, len = 0; + char *module = 0, *cmdline = 0, *p; + struct ia64_boot_module *mod = NULL; + int i; + + if (argc == 0) + { + grub_error (GRUB_ERR_BAD_ARGUMENT, "No module specified"); + goto fail; + } + + if (!boot_param) + { + grub_error (GRUB_ERR_BAD_ARGUMENT, + "You need to load the multiboot kernel first"); + goto fail; + } + + file = grub_gzfile_open (argv[0], 1); + if (! file) + goto fail; + + size = grub_file_size (file); + module = grub_efi_allocate_boot_pages (0, page_align (size) >> 12); + if (! module) + goto fail; + + grub_printf ("Module %s [addr=%llx + %lx]\n", + argv[0], (grub_uint64_t)module, size); + + if (grub_file_read (file, module, size) != size) + { + grub_error (GRUB_ERR_FILE_READ_ERROR, "Couldn't read file"); + goto fail; + } + + len = sizeof (struct ia64_boot_module); + for (i = 0; i < argc; i++) + len += grub_strlen (argv[i]) + 1; + + if (len > 4096) + { + grub_error (GRUB_ERR_OUT_OF_RANGE, "module command line too long"); + goto fail; + } + mod = grub_efi_allocate_boot_pages (0, 1); + if (! mod) + goto fail; + + p = (char *)(mod + 1); + + mod->mod_start = (grub_uint64_t)module; + mod->mod_end = (grub_uint64_t)module + size; + mod->cmdline = (grub_uint64_t)p; + mod->next = 0; + + if (last_module) + last_module->next = (grub_uint64_t)mod; + else + { + last_module = mod; + boot_param->modules_chain = (grub_uint64_t)mod; + } + boot_param->modules_nbr++; + + /* Copy command line. */ + for (i = 0; i < argc; i++) + { + p = grub_stpcpy (p, argv[i]); + *(p++) = ' '; + } + + /* Remove the space after the last word. */ + *(--p) = '\0'; + + + fail: + if (file) + grub_file_close (file); + + if (grub_errno != GRUB_ERR_NONE) + { + grub_free (module); + grub_free (cmdline); + } +} + +void +grub_rescue_cmd_relocate (int argc, char *argv[]) +{ + static const char * const vals[] = { "off", "on", "force"}; + unsigned int i; + + if (argc == 0) + { + grub_printf ("relocate is %s\n", vals[relocate]); + } + else if (argc == 1) + { + if (kernel_mem != NULL) + grub_printf ("Warning: kernel already loaded!\n"); + for (i = 0; i < sizeof (vals)/sizeof(vals[0]); i++) + if (grub_strcmp (argv[0], vals[i]) == 0) + { + relocate = i; + return; + } + grub_error (GRUB_ERR_BAD_ARGUMENT, "unknown relocate value"); + } + else + { + grub_error (GRUB_ERR_BAD_ARGUMENT, "accept 0 or 1 argument"); + } +} + + +void +grub_rescue_cmd_fpswa (int argc, char *argv[] __attribute__((unused))) +{ + if (argc != 0) + { + grub_error (GRUB_ERR_BAD_ARGUMENT, "Arguments not expected"); + return; + } + query_fpswa (); + if (fpswa == NULL) + grub_printf ("No FPSWA loaded\n"); + else + grub_printf ("FPSWA revision: %x\n", fpswa->revision); +} + +GRUB_MOD_INIT(linux) +{ + grub_rescue_register_command ("linux", + grub_rescue_cmd_linux, + "load linux"); + grub_rescue_register_command ("initrd", + grub_rescue_cmd_initrd, + "load initrd"); + grub_rescue_register_command ("module", grub_rescue_cmd_module, + "load a multiboot module"); + grub_rescue_register_command ("relocate", grub_rescue_cmd_relocate, + "set relocate feature"); + grub_rescue_register_command ("fpswa", grub_rescue_cmd_fpswa, + "load fpswa"); + my_mod = mod; +} + +GRUB_MOD_FINI(linux) +{ + grub_rescue_unregister_command ("linux"); + grub_rescue_unregister_command ("initrd"); + grub_rescue_unregister_command ("module"); + grub_rescue_unregister_command ("relocate"); + grub_rescue_unregister_command ("fpswa"); +} diff --git a/loader/ia64/efi/linux_normal.c b/loader/ia64/efi/linux_normal.c new file mode 100644 index 000000000..3a567b09f --- /dev/null +++ b/loader/ia64/efi/linux_normal.c @@ -0,0 +1,107 @@ +/* linux_normal.c - boot linux */ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2008 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 . + */ + +#include +#include +#include +#include + +static grub_err_t +grub_normal_linux_command (struct grub_arg_list *state __attribute__ ((unused)), + int argc, char **args) +{ + grub_rescue_cmd_linux (argc, args); + return grub_errno; +} + + +static grub_err_t +grub_normal_initrd_command (struct grub_arg_list *state __attribute__ ((unused)), + int argc, char **args) +{ + grub_rescue_cmd_initrd (argc, args); + return grub_errno; +} + +static grub_err_t +grub_normal_cmd_module (struct grub_arg_list *state __attribute__ ((unused)), + int argc, char **args) +{ + grub_rescue_cmd_module (argc, args); + return grub_errno; +} + +static grub_err_t +grub_normal_cmd_relocate (struct grub_arg_list *state __attribute__ ((unused)), + int argc, char **args) +{ + grub_rescue_cmd_relocate (argc, args); + return grub_errno; +} + +static grub_err_t +grub_normal_cmd_fpswa (struct grub_arg_list *state __attribute__ ((unused)), + int argc, char **args) +{ + grub_rescue_cmd_fpswa (argc, args); + return grub_errno; +} + +GRUB_MOD_INIT(linux_normal) +{ + (void) mod; /* To stop warning. */ + grub_register_command + ("linux", grub_normal_linux_command, + GRUB_COMMAND_FLAG_BOTH | GRUB_COMMAND_FLAG_NO_ARG_PARSE, + "linux FILE [ARGS...]", + "Load a linux kernel.", 0); + + grub_register_command + ("initrd", grub_normal_initrd_command, + GRUB_COMMAND_FLAG_BOTH | GRUB_COMMAND_FLAG_NO_ARG_PARSE, + "initrd FILE", + "Load an initrd.", 0); + + grub_register_command + ("module", grub_normal_cmd_module, + GRUB_COMMAND_FLAG_BOTH | GRUB_COMMAND_FLAG_NO_ARG_PARSE, + "module FILE [ARGS...]", + "Load a Multiboot module.", 0); + + grub_register_command + ("relocate", grub_normal_cmd_relocate, + GRUB_COMMAND_FLAG_BOTH | GRUB_COMMAND_FLAG_NO_ARG_PARSE, + "relocate [on|off|force]", + "Set relocate feature.", 0); + + grub_register_command + ("fpswa", grub_normal_cmd_fpswa, + GRUB_COMMAND_FLAG_BOTH | GRUB_COMMAND_FLAG_NO_ARG_PARSE, + "fpswa", + "Display FPSWA version.", 0); +} + +GRUB_MOD_FINI(linux_normal) +{ + grub_unregister_command ("linux"); + grub_unregister_command ("initrd"); + grub_unregister_command ("normal"); + grub_unregister_command ("relocate"); + grub_unregister_command ("fpswa"); +} diff --git a/normal/ia64/longjmp.S b/normal/ia64/longjmp.S new file mode 100644 index 000000000..23dec8687 --- /dev/null +++ b/normal/ia64/longjmp.S @@ -0,0 +1,162 @@ +/* Copyright (C) 1999, 2000, 2001, 2002 Free Software Foundation, Inc. + Contributed by David Mosberger-Tang . + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. + + Note that __sigsetjmp() did NOT flush the register stack. Instead, + we do it here since __longjmp() is usually much less frequently + invoked than __sigsetjmp(). The only difficulty is that __sigsetjmp() + didn't (and wouldn't be able to) save ar.rnat either. This is a problem + because if we're not careful, we could end up loading random NaT bits. + There are two cases: + + (i) ar.bsp < ia64_rse_rnat_addr(jmpbuf.ar_bsp) + ar.rnat contains the desired bits---preserve ar.rnat + across loadrs and write to ar.bspstore + + (ii) ar.bsp >= ia64_rse_rnat_addr(jmpbuf.ar_bsp) + The desired ar.rnat is stored in + ia64_rse_rnat_addr(jmpbuf.ar_bsp). Load those + bits into ar.rnat after setting ar.bspstore. */ + + + +# define pPos p6 /* is rotate count positive? */ +# define pNeg p7 /* is rotate count negative? */ + + + /* __longjmp(__jmp_buf buf, int val) */ + + .text + .global longjmp + .proc longjmp +longjmp: + alloc r8=ar.pfs,2,1,0,0 + mov r27=ar.rsc + add r2=0x98,in0 // r2 <- &jmpbuf.orig_jmp_buf_addr + ;; + ld8 r8=[r2],-16 // r8 <- orig_jmp_buf_addr + mov r10=ar.bsp + and r11=~0x3,r27 // clear ar.rsc.mode + ;; + flushrs // flush dirty regs to backing store (must be first in insn grp) + ld8 r23=[r2],8 // r23 <- jmpbuf.ar_bsp + sub r8=r8,in0 // r8 <- &orig_jmpbuf - &jmpbuf + ;; + ld8 r25=[r2] // r25 <- jmpbuf.ar_unat + extr.u r8=r8,3,6 // r8 <- (&orig_jmpbuf - &jmpbuf)/8 & 0x3f + ;; + cmp.lt pNeg,pPos=r8,r0 + mov r2=in0 + ;; +(pPos) mov r16=r8 +(pNeg) add r16=64,r8 +(pPos) sub r17=64,r8 +(pNeg) sub r17=r0,r8 + ;; + mov ar.rsc=r11 // put RSE in enforced lazy mode + shr.u r8=r25,r16 + add r3=8,in0 // r3 <- &jmpbuf.r1 + shl r9=r25,r17 + ;; + or r25=r8,r9 + ;; + mov r26=ar.rnat + mov ar.unat=r25 // setup ar.unat (NaT bits for r1, r4-r7, and r12) + ;; + ld8.fill.nta sp=[r2],16 // r12 (sp) + ld8.fill.nta gp=[r3],16 // r1 (gp) + dep r11=-1,r23,3,6 // r11 <- ia64_rse_rnat_addr(jmpbuf.ar_bsp) + ;; + ld8.nta r16=[r2],16 // caller's unat + ld8.nta r17=[r3],16 // fpsr + ;; + ld8.fill.nta r4=[r2],16 // r4 + ld8.fill.nta r5=[r3],16 // r5 (gp) + cmp.geu p8,p0=r10,r11 // p8 <- (ar.bsp >= jmpbuf.ar_bsp) + ;; + ld8.fill.nta r6=[r2],16 // r6 + ld8.fill.nta r7=[r3],16 // r7 + ;; + mov ar.unat=r16 // restore caller's unat + mov ar.fpsr=r17 // restore fpsr + ;; + ld8.nta r16=[r2],16 // b0 + ld8.nta r17=[r3],16 // b1 + ;; +(p8) ld8 r26=[r11] // r26 <- *ia64_rse_rnat_addr(jmpbuf.ar_bsp) + mov ar.bspstore=r23 // restore ar.bspstore + ;; + ld8.nta r18=[r2],16 // b2 + ld8.nta r19=[r3],16 // b3 + ;; + ld8.nta r20=[r2],16 // b4 + ld8.nta r21=[r3],16 // b5 + ;; + ld8.nta r11=[r2],16 // ar.pfs + ld8.nta r22=[r3],56 // ar.lc + ;; + ld8.nta r24=[r2],32 // pr + mov b0=r16 + ;; + ldf.fill.nta f2=[r2],32 + ldf.fill.nta f3=[r3],32 + mov b1=r17 + ;; + ldf.fill.nta f4=[r2],32 + ldf.fill.nta f5=[r3],32 + mov b2=r18 + ;; + ldf.fill.nta f16=[r2],32 + ldf.fill.nta f17=[r3],32 + mov b3=r19 + ;; + ldf.fill.nta f18=[r2],32 + ldf.fill.nta f19=[r3],32 + mov b4=r20 + ;; + ldf.fill.nta f20=[r2],32 + ldf.fill.nta f21=[r3],32 + mov b5=r21 + ;; + ldf.fill.nta f22=[r2],32 + ldf.fill.nta f23=[r3],32 + mov ar.lc=r22 + ;; + ldf.fill.nta f24=[r2],32 + ldf.fill.nta f25=[r3],32 + cmp.eq p8,p9=0,in1 + ;; + ldf.fill.nta f26=[r2],32 + ldf.fill.nta f27=[r3],32 + mov ar.pfs=r11 + ;; + ldf.fill.nta f28=[r2],32 + ldf.fill.nta f29=[r3],32 + ;; + ldf.fill.nta f30=[r2] + ldf.fill.nta f31=[r3] +(p8) mov r8=1 + + mov ar.rnat=r26 // restore ar.rnat + ;; + mov ar.rsc=r27 // restore ar.rsc +(p9) mov r8=in1 + + invala // virt. -> phys. regnum mapping may change + mov pr=r24,-1 + br.ret.dptk.few rp + .endp longjmp diff --git a/normal/ia64/setjmp.S b/normal/ia64/setjmp.S new file mode 100644 index 000000000..4bc2103b7 --- /dev/null +++ b/normal/ia64/setjmp.S @@ -0,0 +1,171 @@ +/* Copyright (C) 1999, 2000, 2001, 2002 Free Software Foundation, Inc. + Contributed by David Mosberger-Tang . + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. + + The layout of the jmp_buf is as follows. This is subject to change + and user-code should never depend on the particular layout of + jmp_buf! + + + offset: description: + ------- ------------ + 0x000 stack pointer (r12) ; unchangeable (see _JMPBUF_UNWINDS) + 0x008 r1 (gp) + 0x010 caller's unat + 0x018 fpsr + 0x020 r4 + 0x028 r5 + 0x030 r6 + 0x038 r7 + 0x040 rp (b0) + 0x048 b1 + 0x050 b2 + 0x058 b3 + 0x060 b4 + 0x068 b5 + 0x070 ar.pfs + 0x078 ar.lc + 0x080 pr + 0x088 ar.bsp ; unchangeable (see __longjmp.S) + 0x090 ar.unat + 0x098 &__jmp_buf ; address of the jmpbuf (needed to locate NaT bits in unat) + 0x0a0 f2 + 0x0b0 f3 + 0x0c0 f4 + 0x0d0 f5 + 0x0e0 f16 + 0x0f0 f17 + 0x100 f18 + 0x110 f19 + 0x120 f20 + 0x130 f21 + 0x130 f22 + 0x140 f23 + 0x150 f24 + 0x160 f25 + 0x170 f26 + 0x180 f27 + 0x190 f28 + 0x1a0 f29 + 0x1b0 f30 + 0x1c0 f31 */ + + + /* The following two entry points are the traditional entry points: */ + + .text + .global setjmp + .proc setjmp +setjmp: + alloc r8=ar.pfs,2,0,0,0 + mov in1=1 + br.cond.sptk.many __sigsetjmp + .endp setjmp + + /* __sigsetjmp(__jmp_buf buf, int savemask) */ + + .proc __sigsetjmp +__sigsetjmp: + //.prologue ASM_UNW_PRLG_RP|ASM_UNW_PRLG_PFS, ASM_UNW_PRLG_GRSAVE(2) + alloc loc1=ar.pfs,2,2,2,0 + mov r16=ar.unat + ;; + mov r17=ar.fpsr + mov r2=in0 + add r3=8,in0 + ;; + st8.spill.nta [r2]=sp,16 // r12 (sp) + st8.spill.nta [r3]=gp,16 // r1 (gp) + ;; + st8.nta [r2]=r16,16 // save caller's unat + st8.nta [r3]=r17,16 // save fpsr + add r8=0xa0,in0 + ;; + st8.spill.nta [r2]=r4,16 // r4 + st8.spill.nta [r3]=r5,16 // r5 + add r9=0xb0,in0 + ;; + stf.spill.nta [r8]=f2,32 + stf.spill.nta [r9]=f3,32 + mov loc0=rp + .body + ;; + stf.spill.nta [r8]=f4,32 + stf.spill.nta [r9]=f5,32 + mov r17=b1 + ;; + stf.spill.nta [r8]=f16,32 + stf.spill.nta [r9]=f17,32 + mov r18=b2 + ;; + stf.spill.nta [r8]=f18,32 + stf.spill.nta [r9]=f19,32 + mov r19=b3 + ;; + stf.spill.nta [r8]=f20,32 + stf.spill.nta [r9]=f21,32 + mov r20=b4 + ;; + stf.spill.nta [r8]=f22,32 + stf.spill.nta [r9]=f23,32 + mov r21=b5 + ;; + stf.spill.nta [r8]=f24,32 + stf.spill.nta [r9]=f25,32 + mov r22=ar.lc + ;; + stf.spill.nta [r8]=f26,32 + stf.spill.nta [r9]=f27,32 + mov r24=pr + ;; + stf.spill.nta [r8]=f28,32 + stf.spill.nta [r9]=f29,32 + ;; + stf.spill.nta [r8]=f30 + stf.spill.nta [r9]=f31 + + st8.spill.nta [r2]=r6,16 // r6 + st8.spill.nta [r3]=r7,16 // r7 + ;; + mov r23=ar.bsp + mov r25=ar.unat + mov out0=in0 + + st8.nta [r2]=loc0,16 // b0 + st8.nta [r3]=r17,16 // b1 + mov out1=in1 + ;; + st8.nta [r2]=r18,16 // b2 + st8.nta [r3]=r19,16 // b3 + ;; + st8.nta [r2]=r20,16 // b4 + st8.nta [r3]=r21,16 // b5 + ;; + st8.nta [r2]=loc1,16 // ar.pfs + st8.nta [r3]=r22,16 // ar.lc + ;; + st8.nta [r2]=r24,16 // pr + st8.nta [r3]=r23,16 // ar.bsp + ;; + st8.nta [r2]=r25 // ar.unat + st8.nta [r3]=in0 // &__jmp_buf + mov r8=0 + mov rp=loc0 + mov ar.pfs=loc1 + br.ret.sptk.many rp + + .endp __sigsetjmp diff --git a/util/ia64/efi/elf2pe.c b/util/ia64/efi/elf2pe.c new file mode 100644 index 000000000..23687fe68 --- /dev/null +++ b/util/ia64/efi/elf2pe.c @@ -0,0 +1,812 @@ +/* elf2pe.c - convert elf binary to PE/Coff. */ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2008 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 . + */ +#include +#include +#include +#include +#include +#include + +#if defined(i386) +#define USE_ELF32 +#define USE_PE32 +#define ELF_MACHINE EM_386 +#define EFI_MACHINE PE32_MACHINE_I386 +#elif defined(__ia64__) +#define USE_ELF64 +#define USE_PE32PLUS +#define ELF_MACHINE EM_IA_64 +#define EFI_MACHINE PE32_MACHINE_IA64 +#else +#error "unknown architecture" +#endif + +#include "pe32.h" + +const char *filename; + +int +is_elf_header(uint8_t *buffer) +{ + return (buffer[EI_MAG0] == ELFMAG0 + && buffer[EI_MAG1] == ELFMAG1 + && buffer[EI_MAG2] == ELFMAG2 + && buffer[EI_MAG3] == ELFMAG3); +} + +#ifdef USE_ELF32 +typedef Elf32_Shdr Elf_Shdr; +typedef Elf32_Ehdr Elf_Ehdr; +typedef Elf32_Rel Elf_Rel; +typedef Elf32_Rela Elf_Rela; +typedef Elf32_Sym Elf_Sym; +#define ELFCLASS ELFCLASS32 +#define ELF_R_TYPE(r) ELF32_R_TYPE(r) +#define ELF_R_SYM(r) ELF32_R_SYM(r) +#else +typedef Elf64_Shdr Elf_Shdr; +typedef Elf64_Ehdr Elf_Ehdr; +typedef Elf64_Rel Elf_Rel; +typedef Elf64_Rela Elf_Rela; +typedef Elf64_Sym Elf_Sym; +#define ELFCLASS ELFCLASS64 +#define ELF_R_TYPE(r) ELF64_R_TYPE(r) +#define ELF_R_SYM(r) ELF64_R_SYM(r) +#endif + +#ifdef __ia64__ +#define ELF_ETYPE ET_DYN +#else +#define ELF_ETYPE ET_EXEC +#endif + +/* Well known ELF structures. */ +Elf_Ehdr *ehdr; +Elf_Shdr *shdr_base; +Elf_Shdr *shdr_dynamic; +const uint8_t *shdr_str; + +/* PE section alignment. */ +const uint32_t coff_alignment = 0x20; +const uint32_t coff_nbr_sections = 4; + +/* Current offset in coff file. */ +uint32_t coff_offset; + +/* Result Coff file in memory. */ +uint8_t *coff_file; + +/* Offset in Coff file of headers and sections. */ +uint32_t nt_hdr_offset; +uint32_t table_offset; +uint32_t text_offset; +uint32_t data_offset; +uint32_t reloc_offset; + +#ifdef __ia64__ +uint32_t coff_entry_descr_offset; +uint32_t coff_entry_descr_func; +uint64_t plt_base; +#endif + +/* ELF sections to offset in Coff file. */ +uint32_t *coff_sections_offset; + +struct pe32_fixup_block *coff_base_rel; +uint16_t *coff_entry_rel; + +uint32_t +coff_align(uint32_t offset) +{ + return (offset + coff_alignment - 1) & ~(coff_alignment - 1); +} + +Elf_Shdr * +get_shdr_by_index(uint32_t num) +{ + if (num >= ehdr->e_shnum) + return NULL; + return (Elf_Shdr*)((uint8_t*)shdr_base + num * ehdr->e_shentsize); +} + +int +check_elf_header (void) +{ + /* Note: Magic has already been tested. */ + if (ehdr->e_ident[EI_CLASS] != ELFCLASS) + return 0; + if (ehdr->e_ident[EI_DATA] != ELFDATA2LSB) + return 0; + if (ehdr->e_type != ELF_ETYPE) + return 0; + if (ehdr->e_machine != ELF_MACHINE) + return 0; + if (ehdr->e_version != EV_CURRENT) + return 0; + + shdr_base = (Elf_Shdr *)((uint8_t *)ehdr + ehdr->e_shoff); + + coff_sections_offset = + (uint32_t *)malloc (ehdr->e_shnum * sizeof (uint32_t)); + memset (coff_sections_offset, 0, ehdr->e_shnum * sizeof(uint32_t)); + + if (ehdr->e_shstrndx != SHN_UNDEF) + shdr_str = (uint8_t*)ehdr + shdr_base[ehdr->e_shstrndx].sh_offset; + else + shdr_str = NULL; + + return 1; +} + +int +is_text_shdr (Elf_Shdr *shdr) +{ + if (shdr->sh_type != SHT_PROGBITS) { + return 0; + } +#ifdef __ia64__ + return (shdr->sh_flags & (SHF_EXECINSTR | SHF_ALLOC)) + == (SHF_ALLOC | SHF_EXECINSTR); +#else + return (shdr->sh_flags & (SHF_WRITE | SHF_ALLOC)) == SHF_ALLOC; +#endif +} + +int +is_data_shdr (Elf_Shdr *shdr) +{ + if (shdr->sh_type != SHT_PROGBITS && shdr->sh_type != SHT_NOBITS) { + return 0; + } + return (shdr->sh_flags & (SHF_WRITE | SHF_ALLOC)) == (SHF_ALLOC | SHF_WRITE); +} + +void +create_section_header (const char *name, uint32_t offset, uint32_t size, + uint32_t flags) +{ + struct pe32_section_header *hdr; + hdr = (struct pe32_section_header*)(coff_file + table_offset); + + strcpy (hdr->name, name); + hdr->virtual_size = size; + hdr->virtual_address = offset; + hdr->raw_data_size = size; + hdr->raw_data_offset = offset; + hdr->relocations_offset = 0; + hdr->line_numbers_offset = 0; + hdr->num_relocations = 0; + hdr->num_line_numbers = 0; + hdr->characteristics = flags; + + table_offset += sizeof (struct pe32_section_header); +} + +int +scan_sections (void) +{ + uint32_t i; + struct pe32_dos_header *doshdr; + struct pe32_nt_header *nt_hdr; + uint32_t coff_entry = 0; + int status = 0; + + coff_offset = 0; + + /* Coff file start with a DOS header. */ + coff_offset = sizeof(struct pe32_dos_header); + nt_hdr_offset = coff_offset; + coff_offset += sizeof(struct pe32_nt_header); + table_offset = coff_offset; + coff_offset += coff_nbr_sections * sizeof(struct pe32_section_header); + + /* First text sections. */ + coff_offset = coff_align(coff_offset); + text_offset = coff_offset; + for (i = 0; i < ehdr->e_shnum; i++) { + Elf_Shdr *shdr = get_shdr_by_index (i); + if (is_text_shdr (shdr)) { + /* Relocate entry. */ + if (ehdr->e_entry >= shdr->sh_addr + && ehdr->e_entry < shdr->sh_addr + shdr->sh_size) { + coff_entry = coff_offset + ehdr->e_entry - shdr->sh_addr; + } + coff_sections_offset[i] = coff_offset; + coff_offset += shdr->sh_size; +#ifdef __ia64__ + if (coff_sections_offset[i] != shdr->sh_addr) { + fprintf (stderr, + "Section %s: Coff offset (%x) != Elf offset (%lx)", + shdr_str + shdr->sh_name, + coff_sections_offset[i], + shdr->sh_addr); + status = -1; + } +#endif + } + if (shdr->sh_type == SHT_DYNAMIC) { + shdr_dynamic = shdr; + } + } +#ifdef __ia64__ + /* 16 bytes are reserved (by the ld script) for the entry point descriptor. + */ + coff_entry_descr_offset = coff_offset - 16; +#endif + + coff_offset = coff_align (coff_offset); + + /* Then data sections. */ + data_offset = coff_offset; + for (i = 0; i < ehdr->e_shnum; i++) { + Elf_Shdr *shdr = get_shdr_by_index (i); + if (is_data_shdr (shdr)) { + coff_sections_offset[i] = coff_offset; + coff_offset += shdr->sh_size; +#ifdef __ia64__ + if (coff_sections_offset[i] != shdr->sh_addr) { + fprintf (stderr, + "Section %s: Coff offset (%x) != Elf offset (%lx)", + shdr_str + shdr->sh_name, + coff_sections_offset[i], + shdr->sh_addr); + status = -1; + } +#endif + } + } + coff_offset = coff_align (coff_offset); + + reloc_offset = coff_offset; + + /* Allocate base Coff file. Will be expanded later for relocations. */ + coff_file = (uint8_t *)malloc (coff_offset); + memset (coff_file, 0, coff_offset); + + /* Fill headers. */ + doshdr = (struct pe32_dos_header *)coff_file; + doshdr->magic = 0x5A4D; + doshdr->new_hdr_offset = nt_hdr_offset; + + nt_hdr = (struct pe32_nt_header*)(coff_file + nt_hdr_offset); + + memcpy (nt_hdr->signature, "PE\0", 4); + + nt_hdr->coff_header.machine = EFI_MACHINE; + nt_hdr->coff_header.num_sections = coff_nbr_sections; + nt_hdr->coff_header.time = time (NULL); + nt_hdr->coff_header.symtab_offset = 0; + nt_hdr->coff_header.num_symbols = 0; + nt_hdr->coff_header.optional_header_size = sizeof(nt_hdr->optional_header); + nt_hdr->coff_header.characteristics = PE32_EXECUTABLE_IMAGE + | PE32_LINE_NUMS_STRIPPED + | PE32_LOCAL_SYMS_STRIPPED + | PE32_32BIT_MACHINE; + +#ifdef USE_PE32 + nt_hdr->optional_header.magic = PE32_PE32_MAGIC; +#else + nt_hdr->optional_header.magic = PE32_PE64_MAGIC; +#endif + nt_hdr->optional_header.code_size = data_offset - text_offset; + nt_hdr->optional_header.data_size = reloc_offset - data_offset; + nt_hdr->optional_header.bss_size = 0; +#ifdef __ia64__ + nt_hdr->optional_header.entry_addr = coff_entry_descr_offset; + coff_entry_descr_func = coff_entry; +#else + nt_hdr->optional_header.entry_addr = coff_entry; +#endif + nt_hdr->optional_header.code_base = text_offset; + +#ifdef USE_PE32 + nt_hdr->optional_header.data_base = data_offset; +#endif + nt_hdr->optional_header.image_base = 0; + nt_hdr->optional_header.section_alignment = coff_alignment; + nt_hdr->optional_header.file_alignment = coff_alignment; + nt_hdr->optional_header.image_size = 0; + + nt_hdr->optional_header.header_size = text_offset; + nt_hdr->optional_header.num_data_directories = PE32_NUM_DATA_DIRECTORIES; + + /* Section headers. */ + create_section_header (".text", text_offset, data_offset - text_offset, + PE32_SCN_CNT_CODE + | PE32_SCN_MEM_EXECUTE + | PE32_SCN_MEM_READ); + create_section_header (".data", data_offset, reloc_offset - data_offset, + PE32_SCN_CNT_INITIALIZED_DATA + | PE32_SCN_MEM_WRITE + | PE32_SCN_MEM_READ); +#ifdef __ia64__ + if (shdr_dynamic != NULL) + { + Elf64_Dyn *dyn = (Elf64_Dyn*)((uint8_t*)ehdr + shdr_dynamic->sh_offset); + while (dyn->d_tag != DT_NULL) + { + if (dyn->d_tag == DT_PLTGOT) + plt_base = dyn->d_un.d_ptr; + dyn++; + } + } +#endif + return status; +} + +int +write_sections (int (*filter)(Elf_Shdr *)) +{ + uint32_t idx; + int status = 0; + + /* First: copy sections. */ + for (idx = 0; idx < ehdr->e_shnum; idx++) + { + Elf_Shdr *shdr = get_shdr_by_index (idx); + if ((*filter)(shdr)) + { + switch (shdr->sh_type) { + case SHT_PROGBITS: + /* Copy. */ + memcpy (coff_file + coff_sections_offset[idx], + (uint8_t*)ehdr + shdr->sh_offset, + shdr->sh_size); + break; + case SHT_NOBITS: + memset (coff_file + coff_sections_offset[idx], 0, shdr->sh_size); + break; + case SHT_DYNAMIC: + break; + default: + fprintf (stderr, "unhandled section type %x", + (unsigned int)shdr->sh_type); + status = -1; + } + } + } + + /* Second: apply relocations. */ + for (idx = 0; idx < ehdr->e_shnum; idx++) + { + Elf_Shdr *rel_shdr = get_shdr_by_index (idx); + if (rel_shdr->sh_type != SHT_REL && rel_shdr->sh_type != SHT_RELA) + continue; + Elf_Shdr *sec_shdr = get_shdr_by_index (rel_shdr->sh_info); + uint32_t sec_offset = coff_sections_offset[rel_shdr->sh_info]; + + if (rel_shdr->sh_info == 0 || (*filter)(sec_shdr)) + { + uint32_t rel_idx; + Elf_Shdr *symtab_shdr = get_shdr_by_index(rel_shdr->sh_link); + uint8_t *symtab = (uint8_t*)ehdr + symtab_shdr->sh_offset; + + if (rel_shdr->sh_type == SHT_REL) + { + for (rel_idx = 0; + rel_idx < rel_shdr->sh_size; + rel_idx += rel_shdr->sh_entsize) + { + Elf_Rel *rel = (Elf_Rel *) + ((uint8_t*)ehdr + rel_shdr->sh_offset + rel_idx); + Elf_Sym *sym = (Elf_Sym *) + (symtab + + ELF_R_SYM(rel->r_info) * symtab_shdr->sh_entsize); + Elf_Shdr *sym_shdr; + uint8_t *targ; + + if (sym->st_shndx == SHN_UNDEF + || sym->st_shndx == SHN_ABS + || sym->st_shndx > ehdr->e_shnum) + { + fprintf (stderr, "bad symbol definition"); + status = -1; + } + sym_shdr = get_shdr_by_index(sym->st_shndx); + + /* Note: r_offset in a memory address. + Convert it to a pointer in the coff file. */ + targ = coff_file + sec_offset + + (rel->r_offset - sec_shdr->sh_addr); + + switch (ELF_R_TYPE(rel->r_info)) { + case R_386_NONE: + break; + case R_386_32: + /* Absolute relocation. */ + *(uint32_t *)targ = *(uint32_t *)targ - sym_shdr->sh_addr + + coff_sections_offset[sym->st_shndx]; + break; + case R_386_PC32: + /* Relative relocation: Symbol - Ip + Addend */ + *(uint32_t *)targ = *(uint32_t *)targ + + (coff_sections_offset[sym->st_shndx] + - sym_shdr->sh_addr) + - (sec_offset - sec_shdr->sh_addr); + break; + default: + fprintf (stderr, "unhandled relocation type %lx", + ELF_R_TYPE(rel->r_info)); + status = -1; + } + } + } + else if (rel_shdr->sh_type == SHT_RELA) + { + for (rel_idx = 0; + rel_idx < rel_shdr->sh_size; + rel_idx += rel_shdr->sh_entsize) { + Elf_Rela *rela = (Elf_Rela *) + ((uint8_t*)ehdr + rel_shdr->sh_offset + rel_idx); + Elf_Sym *sym = (Elf_Sym *) + (symtab + ELF_R_SYM(rela->r_info) * symtab_shdr->sh_entsize); + Elf_Shdr *sym_shdr; + uint8_t *targ; + + if (ELF_R_TYPE(rela->r_info) == R_IA64_NONE) + continue; + +#if 0 + if (sym->st_shndx == SHN_UNDEF + || sym->st_shndx == SHN_ABS + || sym->st_shndx > ehdr->e_shnum) { + fprintf (stderr, "bad symbol definition %d", + ELF_R_SYM(rela->r_info)); + } +#endif + sym_shdr = get_shdr_by_index (sym->st_shndx); + + /* Note: r_offset in a memory address. + Convert it to a pointer in the coff file. */ + targ = coff_file + sec_offset + + (rela->r_offset - sec_shdr->sh_addr); + + switch (ELF_R_TYPE(rela->r_info)) { + case R_IA64_IPLTLSB: + /* If there is a descriptor with the same function + pointer as the ELF entry point, use that + descriptor for the PE/Coff entry. */ + if (*(uint64_t*)targ == ehdr->e_entry) { + struct pe32_nt_header *nt_hdr; + + nt_hdr = + (struct pe32_nt_header*)(coff_file + nt_hdr_offset); + nt_hdr->optional_header.entry_addr = targ - coff_file; + } + break; + case R_IA64_REL64LSB: + case R_IA64_NONE: + break; + default: + fprintf (stderr, + "unhandled relocation type %lx in section %d", + ELF_R_TYPE(rela->r_info), rel_shdr->sh_info); + status = -1; + } + } + } + } + } + return status; +} + +void +coff_add_fixup_entry (uint16_t val) +{ + *coff_entry_rel = val; + coff_entry_rel++; + coff_base_rel->block_size += 2; + coff_offset += 2; +} + +void +coff_add_fixup (uint32_t offset, uint8_t type) +{ + if (coff_base_rel == NULL + || coff_base_rel->page_rva != (offset & ~0xfff)) { + if (coff_base_rel != NULL) { + /* Add a null entry (is it required ?) */ + coff_add_fixup_entry (0); + /* Pad for alignment. */ + if (coff_offset % 4 != 0) + coff_add_fixup_entry (0); + } + + coff_file = realloc + (coff_file, + coff_offset + sizeof(struct pe32_fixup_block) + 2*0x1000); + memset(coff_file + coff_offset, 0, + sizeof(struct pe32_fixup_block) + 2*0x1000); + + coff_base_rel = (struct pe32_fixup_block*)(coff_file + coff_offset); + coff_base_rel->page_rva = offset & ~0xfff; + coff_base_rel->block_size = sizeof(struct pe32_fixup_block); + + coff_entry_rel = (uint16_t *)(coff_base_rel + 1); + coff_offset += sizeof(struct pe32_fixup_block); + } + + /* Fill the entry. */ + coff_add_fixup_entry ((type << 12) | (offset & 0xfff)); +} + +int +write_relocations(void) +{ + uint32_t idx; + struct pe32_nt_header *nt_hdr; + struct pe32_data_directory *dir; + int status = 0; + + for (idx = 0; idx < ehdr->e_shnum; idx++) + { + Elf_Shdr *rel_shdr = get_shdr_by_index (idx); + if (rel_shdr->sh_type == SHT_REL) + { + Elf_Shdr *sec_shdr = get_shdr_by_index (rel_shdr->sh_info); + if (is_text_shdr(sec_shdr) || is_data_shdr(sec_shdr)) + { + uint32_t rel_idx; + for (rel_idx = 0; + rel_idx < rel_shdr->sh_size; + rel_idx += rel_shdr->sh_entsize) + { + Elf_Rel *rel = (Elf_Rel *) + ((uint8_t*)ehdr + rel_shdr->sh_offset + rel_idx); + + switch (ELF_R_TYPE(rel->r_info)) + { + case R_386_NONE: + case R_386_PC32: + break; + case R_386_32: + coff_add_fixup(coff_sections_offset[rel_shdr->sh_info] + + (rel->r_offset - sec_shdr->sh_addr), + PE32_REL_BASED_HIGHLOW); + break; + default: + fprintf (stderr, "unhandled relocation type %lx", + ELF_R_TYPE(rel->r_info)); + status = -1; + } + } + } + } + else if (rel_shdr->sh_type == SHT_RELA) + { + Elf_Shdr *sec_shdr = get_shdr_by_index(rel_shdr->sh_info); + if (rel_shdr->sh_info == 0 + || is_text_shdr(sec_shdr) || is_data_shdr(sec_shdr)) + { + uint32_t rel_idx; + for (rel_idx = 0; + rel_idx < rel_shdr->sh_size; + rel_idx += rel_shdr->sh_entsize) { + Elf_Rela *rela = (Elf_Rela *) + ((uint8_t*)ehdr + rel_shdr->sh_offset + rel_idx); + uint32_t Loc = coff_sections_offset[rel_shdr->sh_info] + + (rela->r_offset - sec_shdr->sh_addr); + + switch (ELF_R_TYPE(rela->r_info)) + { + case R_IA64_IPLTLSB: + coff_add_fixup(Loc, PE32_REL_BASED_DIR64); + coff_add_fixup(Loc + 8, PE32_REL_BASED_DIR64); + break; + case R_IA64_REL64LSB: + coff_add_fixup(Loc, PE32_REL_BASED_DIR64); + break; + case R_IA64_DIR64LSB: + coff_add_fixup(Loc, PE32_REL_BASED_DIR64); + break; + case R_IA64_IMM64: + coff_add_fixup(Loc, PE32_REL_BASED_IA64_IMM64); + break; + case R_IA64_PCREL21B: + case R_IA64_PCREL64LSB: + case R_IA64_SECREL32LSB: + case R_IA64_SEGREL64LSB: + break; + case R_IA64_GPREL22: + case R_IA64_LTOFF22X: + case R_IA64_LDXMOV: + case R_IA64_LTOFF_FPTR22: + case R_IA64_NONE: + break; + default: + fprintf (stderr, "unhandled relocation type %lx", + ELF_R_TYPE(rela->r_info)); + status = -1; + } + } + } + } + } + +#ifdef __ia64__ + coff_add_fixup (coff_entry_descr_offset, PE32_REL_BASED_DIR64); + coff_add_fixup (coff_entry_descr_offset + 8, PE32_REL_BASED_DIR64); +#endif + + /* Pad by adding empty entries. */ + while (coff_offset & (coff_alignment - 1)) + coff_add_fixup_entry (0); + + create_section_header (".reloc", reloc_offset, coff_offset - reloc_offset, + PE32_SCN_CNT_INITIALIZED_DATA + | PE32_SCN_MEM_DISCARDABLE + | PE32_SCN_MEM_READ); + + nt_hdr = (struct pe32_nt_header *)(coff_file + nt_hdr_offset); + dir = &nt_hdr->optional_header.base_relocation_table; + dir->rva = reloc_offset; + dir->size = coff_offset - reloc_offset; + + return status; +} + +void +write_debug(void) +{ + uint32_t len = strlen(filename) + 1; + uint32_t debug_offset = coff_offset; + struct pe32_nt_header *nt_hdr; + struct pe32_data_directory *data_dir; + struct pe32_debug_directory_entry *dir; + struct pe32_debug_codeview_nb10_entry *nb10; + + coff_offset += sizeof (struct pe32_debug_directory_entry) + + sizeof(struct pe32_debug_codeview_nb10_entry) + + len; + coff_offset = coff_align(coff_offset); + + coff_file = realloc + (coff_file, coff_offset); + memset(coff_file + debug_offset, 0, coff_offset - debug_offset); + + dir = (struct pe32_debug_directory_entry*)(coff_file + debug_offset); + dir->type = PE32_DEBUG_TYPE_CODEVIEW; + dir->data_size = sizeof(struct pe32_debug_directory_entry) + len; + dir->rva = debug_offset + sizeof(struct pe32_debug_directory_entry); + dir->file_offset = debug_offset + sizeof(struct pe32_debug_directory_entry); + + nb10 = (struct pe32_debug_codeview_nb10_entry*)(dir + 1); + nb10->signature = PE32_CODEVIEW_SIGNATURE_NB10; + strcpy (nb10->filename, filename); + + create_section_header (".debug", debug_offset, coff_offset - debug_offset, + PE32_SCN_CNT_INITIALIZED_DATA + | PE32_SCN_MEM_DISCARDABLE + | PE32_SCN_MEM_READ); + + nt_hdr = (struct pe32_nt_header *)(coff_file + nt_hdr_offset); + data_dir = &nt_hdr->optional_header.debug; + data_dir->rva = debug_offset; + data_dir->size = coff_offset - debug_offset; +} + +int +convert_elf (uint8_t **file_buffer, unsigned int *file_length) +{ + struct pe32_nt_header *nt_hdr; + + /* Check header, read section table. */ + ehdr = (Elf_Ehdr*)*file_buffer; + if (!check_elf_header ()) + return -1; + + /* Compute sections new address. */ + if (scan_sections () != 0) + return -2; + + /* Write and relocate sections. */ + if (write_sections (is_text_shdr) != 0) + return -3; + +#ifdef __ia64__ + *(uint64_t*)(coff_file + coff_entry_descr_offset) = coff_entry_descr_func; + *(uint64_t*)(coff_file + coff_entry_descr_offset + 8) = plt_base; +#endif + + if (write_sections (is_data_shdr) != 0) + return -4; + + /* Translate and write relocations. */ + if (write_relocations () != 0) + return -5; + + /* Write debug info. */ + write_debug (); + + nt_hdr = (struct pe32_nt_header *)(coff_file + nt_hdr_offset); + nt_hdr->optional_header.image_size = coff_offset; + + nt_hdr->optional_header.subsystem = PE32_SUBSYSTEM_EFI_APPLICATION; + + /* Replace. */ + free (*file_buffer); + *file_buffer = coff_file; + *file_length = coff_offset; + + return 0; +} + +int +main (int argc, char **argv) +{ + FILE *f; + unsigned int size; + uint8_t *buffer; + const char *outfile; + int status; + + if (argc != 3) + { + fprintf (stderr, "usage: %s elf-file pe-file\n", argv[0]); + exit (1); + } + + filename = argv[1]; + outfile = argv[2]; + f = fopen (filename, "rb"); + fseek (f, 0, SEEK_END); + size = ftell (f); + fseek (f, 0, SEEK_SET); + + buffer = malloc (size); + if (buffer == NULL) + { + fprintf (stderr, "cannot allocate %u bytes of memory\n", size); + exit (2); + } + if (fread (buffer, size, 1, f) != 1) + { + fprintf (stderr, "cannot read %s\n", filename); + exit (2); + } + fclose (f); + + if (!is_elf_header (buffer)) + { + fprintf (stderr, "%s is not an elf file\n", filename); + exit (2); + } + + status = convert_elf (&buffer, &size); + if (status != 0) + { + fprintf (stderr, "cannot convert %s to pe (err=%d)\n", filename, status); + exit (2); + } + + f = fopen (outfile, "wb"); + if (f == NULL) + { + fprintf (stderr, "cannot open %s\n", outfile); + exit (2); + } + if (fwrite (buffer, size, 1, f) != 1) + { + fprintf (stderr, "cannot write to %s\n", outfile); + exit (2); + } + fclose (f); + + return 0; +} diff --git a/util/ia64/efi/grub-install.in b/util/ia64/efi/grub-install.in new file mode 100644 index 000000000..63b0c9f6c --- /dev/null +++ b/util/ia64/efi/grub-install.in @@ -0,0 +1,233 @@ +#! /bin/sh + +# Install GRUB on your EFI partition. +# Copyright (C) 1999,2000,2001,2002,2003,2004,2005,2006,2007,2008 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 . + + +# Initialize some variables. +prefix=@prefix@ +exec_prefix=@exec_prefix@ +sbindir=@sbindir@ +bindir=@bindir@ +libdir=@libdir@ +datadir=@datadir@ +PACKAGE_NAME=@PACKAGE_NAME@ +PACKAGE_TARNAME=@PACKAGE_TARNAME@ +PACKAGE_VERSION=@PACKAGE_VERSION@ +target_cpu=@target_cpu@ +platform=@platform@ +pkglibdir=${libdir}/${PACKAGE_TARNAME}/${target_cpu}-${platform} +pkgdatadir=${datadir}/${PACKAGE_TARNAME} + + +TARGET_CC=@TARGET_CC@ +TARGET_CFLAGS="@TARGET_CFLAGS@" +TARGET_CPPFLAGS="@TARGET_CPPFLAGS@" +TARGET_LDFLAGS="@TARGET_LDFLAGS@" +OBJCOPY=@OBJCOPY@ + +grub_setup=${sbindir}/grub-setup +grub_mkimage=${bindir}/grub-mkimage +grub_mkdevicemap=${sbindir}/grub-mkdevicemap +grub_probefs=${sbindir}/grub-probefs +rootdir= +grub_prefix=/boot/grub +modules= + +install_device= +recheck=no +debug=no + +# Usage: usage +# Print the usage. +usage () { + cat <. +EOF +} + +# Check the arguments. +for option in "$@"; do + case "$option" in + -h | --help) + usage + exit 0 ;; + -v | --version) + echo "grub-install (GNU GRUB ${PACKAGE_VERSION})" + exit 0 ;; + --modules=*) + modules=`echo "$option" | sed 's/--modules=//'` ;; + --root-directory=*) + rootdir=`echo "$option" | sed 's/--root-directory=//'` ;; + --grub-setup=*) + grub_setup=`echo "$option" | sed 's/--grub-setup=//'` ;; + --grub-mkimage=*) + grub_mkimage=`echo "$option" | sed 's/--grub-mkimage=//'` ;; + --grub-mkdevicemap=*) + grub_mkdevicemap=`echo "$option" | sed 's/--grub-mkdevicemap=//'` ;; + --grub-probefs=*) + grub_probefs=`echo "$option" | sed 's/--grub-probefs=//'` ;; + --pkglibdir=*) + pkglibdir=`echo "$option" | sed 's/--pkglibdir=//'` ;; + --pkgdatadir=*) + pkgdatadir=`echo "$option" | sed 's/--pkgdatadir=//'` ;; + --recheck) + recheck=yes ;; + # This is an undocumented feature... + --debug) + debug=yes ;; + -*) + echo "Unrecognized option \`$option'" 1>&2 + usage + exit 1 + ;; + *) + if test "x$install_device" != x; then + echo "More than one install_devices?" 1>&2 + usage + exit 1 + fi + install_device="${option}" ;; + esac +done + +#if test "x$install_device" = x; then +# echo "install_device not specified." 1>&2 +# usage +# exit 1 +#fi + +# If the debugging feature is enabled, print commands. +if test $debug = yes; then + set -x +fi + +# Initialize these directories here, since ROOTDIR was initialized. +bootdir=${rootdir}/boot/efi + +grubdir=${bootdir}/grub +device_map=${grubdir}/device.map + +# Create the GRUB directory if it is not present. +test -d "$bootdir" || mkdir "$bootdir" || exit 1 +test -d "$grubdir" || mkdir "$grubdir" || exit 1 + +# Copy the GRUB images to the GRUB directory. +if false; then + for file in ${grubdir}/*.mod ${grubdir}/*.lst; do + if test -f $file; then + rm -f $file || exit 1 + fi + done + for file in ${pkglibdir}/*.mod ${pkglibdir}/*.lst; do + cp -f $file ${grubdir} || exit 1 + done +fi + +# Create the core image. First, auto-detect the filesystme module. +#fs_module=`$grub_probefs --device-map=${device_map} ${grubdir}` +#if test "x$fs_module" = x -a "x$modules" = x; then +# echo "Auto-detection of a filesystem module failed." 1>&2 +# echo "Please specify the module with the option \`--modules' explicitly." 1>&2 +# exit 1 +#fi + +# Typically, _chain and pc are required. +modules="$modules $fs_module _chain" + +modules="kernel gzio gpt fat normal ls cat fshelp help _linux linux $modules" +modules="$modules memmap systab boot" + +if [ $debug = yes ]; then + tmpdir=. +else + tmpdir=`mktemp -d /tmp/grub.XXXXXXXXXX` || exit 1 + trap "rm -rf $tmpdir" 1 2 13 15 +fi + +# Generate init/fini for modules. +modfile=$tmpdir/mod.c +echo "/* Dummy modules. */" > $modfile +list="" +init_list="" +fini_list="" +for m in $modules; do + file="$pkglibdir/${m}.mod" + name=`nm $file | sed -n "/ r grub_module_name/ s/.* r grub_module_name_\(.*\)/\1/p"` + init=`nm $file | sed -n "/ T grub_module_.*_init/ s/.* T //p"` + fini=`nm $file | sed -n "/ T grub_module_.*_fini/ s/.* T //p"` + init_list="$init_list $init" + fini_list="$fini_list $fini" + arg="\"$name\",${init:-0},${fini:-0}" + list="$list $arg" +done +echo "extern void grub_init_module (const char *, void (*init)(void *), void (*fini)(void));" >> $modfile +echo "extern void grub_init_modules (void);" >> $modfile +for m in $init_list; do + echo "extern void $m(void *);" >> $modfile +done +for m in $fini_list; do + echo "extern void $m(void);" >> $modfile +done +echo "void grub_init_modules (void)" >> $modfile +echo "{" >> $modfile +for m in $list; do + echo " grub_init_module($m);" >> $modfile +done +echo "}" >> $modfile + +$TARGET_CC -c $TARGET_CFLAGS -o $tmpdir/mod.o $modfile + +mod_objs= +for m in $modules; do mod_objs="$mod_objs $pkglibdir/${m}.mod"; done + +ld -pie -nostdlib -T $pkgdatadir/elf_ia64_efi.lds \ + $mod_objs $tmpdir/mod.o -o $tmpdir/grub.elf + + +if ! $bindir/grub-elf2pe $tmpdir/grub.elf $grubdir/grub.efi; then + echo "Failed to build efi binary" + [ $debug = no ] && rm -rf $tmpdir + exit 1 +fi + +echo "grub.efi generated" + +[ $debug = no ] && rm -rf $tmpdir + +# Bye. +exit 0 diff --git a/util/ia64/efi/pe32.h b/util/ia64/efi/pe32.h new file mode 100644 index 000000000..391e70c26 --- /dev/null +++ b/util/ia64/efi/pe32.h @@ -0,0 +1,237 @@ +/* pe32.h - PE/Coff definitions. */ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2008 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 . + */ +#ifdef USE_PE32PLUS +typedef uint64_t pe32_uintptr_t; +#else +typedef uint32_t pe32_uintptr_t; +#endif + +struct pe32_coff_header +{ + uint16_t machine; + uint16_t num_sections; + uint32_t time; + uint32_t symtab_offset; + uint32_t num_symbols; + uint16_t optional_header_size; + uint16_t characteristics; +}; + +#define PE32_MACHINE_I386 0x014c +#define PE32_MACHINE_IA64 0x0200 +#define PE32_MACHINE_EBC 0x0EBC +#define PE32_MACHINE_X64 0x8664 + +#define PE32_RELOCS_STRIPPED 0x0001 +#define PE32_EXECUTABLE_IMAGE 0x0002 +#define PE32_LINE_NUMS_STRIPPED 0x0004 +#define PE32_LOCAL_SYMS_STRIPPED 0x0008 +#define PE32_AGGRESSIVE_WS_TRIM 0x0010 +#define PE32_LARGE_ADDRESS_AWARE 0x0020 +#define PE32_16BIT_MACHINE 0x0040 +#define PE32_BYTES_REVERSED_LO 0x0080 +#define PE32_32BIT_MACHINE 0x0100 +#define PE32_DEBUG_STRIPPED 0x0200 +#define PE32_REMOVABLE_RUN_FROM_SWAP 0x0400 +#define PE32_SYSTEM 0x1000 +#define PE32_DLL 0x2000 +#define PE32_UP_SYSTEM_ONLY 0x4000 +#define PE32_BYTES_REVERSED_HI 0x8000 + +struct pe32_data_directory +{ + uint32_t rva; + uint32_t size; +}; + +struct pe32_optional_header +{ + uint16_t magic; + uint8_t major_linker_version; + uint8_t minor_linker_version; + uint32_t code_size; + uint32_t data_size; + uint32_t bss_size; + uint32_t entry_addr; + uint32_t code_base; + +#ifndef USE_PE32PLUS + uint32_t data_base; +#endif + + pe32_uintptr_t image_base; + uint32_t section_alignment; + uint32_t file_alignment; + uint16_t major_os_version; + uint16_t minor_os_version; + uint16_t major_image_version; + uint16_t minor_image_version; + uint16_t major_subsystem_version; + uint16_t minor_subsystem_version; + uint32_t reserved; + uint32_t image_size; + uint32_t header_size; + uint32_t checksum; + uint16_t subsystem; + uint16_t dll_characteristics; + pe32_uintptr_t stack_reserve_size; + pe32_uintptr_t stack_commit_size; + pe32_uintptr_t heap_reserve_size; + pe32_uintptr_t heap_commit_size; + uint32_t loader_flags; + uint32_t num_data_directories; + + /* Data directories. */ + struct pe32_data_directory export_table; + struct pe32_data_directory import_table; + struct pe32_data_directory resource_table; + struct pe32_data_directory exception_table; + struct pe32_data_directory certificate_table; + struct pe32_data_directory base_relocation_table; + struct pe32_data_directory debug; + struct pe32_data_directory architecture; + struct pe32_data_directory global_ptr; + struct pe32_data_directory tls_table; + struct pe32_data_directory load_config_table; + struct pe32_data_directory bound_import; + struct pe32_data_directory iat; + struct pe32_data_directory delay_import_descriptor; + struct pe32_data_directory com_runtime_header; + struct pe32_data_directory reserved_entry; +}; + +#define PE32_PE32_MAGIC 0x10b +#define PE32_PE64_MAGIC 0x20b + +#define PE32_SUBSYSTEM_EFI_APPLICATION 10 +#define PE32_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER 11 +#define PE32_SUBSYSTEM_EFI_RUNTIME_DRIVER 12 +#define PE32_SUBSYSTEM_EFI_EFI_ROM 13 + +#define PE32_NUM_DATA_DIRECTORIES 16 + +struct pe32_section_header +{ + char name[8]; + uint32_t virtual_size; + uint32_t virtual_address; + uint32_t raw_data_size; + uint32_t raw_data_offset; + uint32_t relocations_offset; + uint32_t line_numbers_offset; + uint16_t num_relocations; + uint16_t num_line_numbers; + uint32_t characteristics; +}; + +#define PE32_SCN_CNT_CODE 0x00000020 +#define PE32_SCN_CNT_INITIALIZED_DATA 0x00000040 +#define PE32_SCN_MEM_DISCARDABLE 0x02000000 +#define PE32_SCN_MEM_EXECUTE 0x20000000 +#define PE32_SCN_MEM_READ 0x40000000 +#define PE32_SCN_MEM_WRITE 0x80000000 + +struct pe32_dos_header +{ + uint16_t magic; // Magic number + uint16_t cblp; // Bytes on last page of file + uint16_t cp; // Pages in file + uint16_t crlc; // Relocations + uint16_t cparhdr; // Size of header in paragraphs + uint16_t minalloc; // Minimum extra paragraphs needed + uint16_t maxalloc; // Maximum extra paragraphs needed + uint16_t ss; // Initial (relative) SS value + uint16_t sp; // Initial SP value + uint16_t csum; // Checksum + uint16_t ip; // Initial IP value + uint16_t cs; // Initial (relative) CS value + uint16_t lfa_rlc; // File address of relocation table + uint16_t ov_no; // Overlay number + uint16_t res[4]; // Reserved words + uint16_t oem_id; // OEM identifier (for e_oeminfo) + uint16_t oem_info; // OEM information; e_oemid specific + uint16_t res2[10]; // Reserved words + uint32_t new_hdr_offset; + + uint16_t stub[0x20]; +}; + +struct pe32_nt_header +{ + /* This is always PE\0\0. */ + char signature[4]; + + /* The COFF file header. */ + struct pe32_coff_header coff_header; + + /* The Optional header. */ + struct pe32_optional_header optional_header; +}; + +struct pe32_base_relocation +{ + uint32_t page_rva; + uint32_t block_size; +}; + +struct pe32_fixup_block +{ + uint32_t page_rva; + uint32_t block_size; + uint16_t entries[0]; +}; + +#define PE32_FIXUP_ENTRY(type, offset) (((type) << 12) | (offset)) + +#define PE32_REL_BASED_ABSOLUTE 0 +#define PE32_REL_BASED_HIGHLOW 3 +#define PE32_REL_BASED_IA64_IMM64 9 +#define PE32_REL_BASED_DIR64 10 + +#define PE32_DEBUG_TYPE_CODEVIEW 2 +struct pe32_debug_directory_entry { + uint32_t characteristics; + uint32_t time; + uint16_t major_version; + uint16_t minor_version; + uint32_t type; + uint32_t data_size; + uint32_t rva; + uint32_t file_offset; +}; + +#define PE32_CODEVIEW_SIGNATURE_NB10 0x3031424E // "NB10" +struct pe32_debug_codeview_nb10_entry { + uint32_t signature; // "NB10" + uint32_t unknown[3]; + char filename[0]; /* Filename of .PDB */ +}; + + +#if 1 +#define pe32_check(name, x) extern char pe32_check_##name [x ? 1 : -1] +#ifdef USE_PE32PLUS +#define PE32_HEADER_SIZE 112 +#else +#define PE32_HEADER_SIZE 96 +#endif + +pe32_check(optional_header, sizeof (struct pe32_optional_header) == PE32_HEADER_SIZE + PE32_NUM_DATA_DIRECTORIES * 8); +#endif + From c8298743f3b1caf683789c60c7daf0e00a34b48d Mon Sep 17 00:00:00 2001 From: Robert Millan Date: Mon, 18 Jan 2010 14:24:17 +0000 Subject: [PATCH 002/869] Second version of the patch (sent to grub-devel in 2008-01-29) --- ChangeLog.ia64 | 1 - Makefile.in | 7 +++---- commands/efi/acpi.c | 11 ++++------- conf/ia64-efi.rmk | 9 +++++++-- config.h.in | 4 ++-- include/grub/ia64/efi/kernel.h | 2 +- include/grub/ia64/setjmp.h | 2 +- include/grub/ia64/time.h | 2 +- kern/ia64/trampoline.S | 8 ++++---- loader/ia64/efi/linux.c | 12 ++++++++---- loader/ia64/efi/linux_normal.c | 2 +- normal/ia64/longjmp.S | 2 +- normal/ia64/setjmp.S | 2 +- util/ia64/efi/elf2pe.c | 4 ++-- 14 files changed, 36 insertions(+), 32 deletions(-) diff --git a/ChangeLog.ia64 b/ChangeLog.ia64 index 35417bec0..64562fb23 100644 --- a/ChangeLog.ia64 +++ b/ChangeLog.ia64 @@ -3,7 +3,6 @@ * geninit.sh: Call _init with a null argument. * configure.ac: Add ia64-efi target. * Makefile.in (STRIP_FLAGS): Declare (overriden on ia64). - (RMKFILES): Add ia64-efi.rmk * genmk.rb: Use STRIP_FLAGS for strip. * util/ia64/efi/grub-install.in: New file. * util/ia64/efi/pe32.h: New file. diff --git a/Makefile.in b/Makefile.in index 134505d3c..5e8e07dbb 100644 --- a/Makefile.in +++ b/Makefile.in @@ -83,8 +83,7 @@ enable_grub_emu = @enable_grub_emu@ ### General variables. -RMKFILES = $(addprefix conf/,common.rmk i386-pc.rmk powerpc-ieee1275.rmk \ - sparc64-ieee1275.rmk i386-efi.rmk ia64-efi.rmk) +RMKFILES = $(wildcard $(srcdir)/conf/*.rmk) MKFILES = $(patsubst %.rmk,%.mk,$(RMKFILES)) PKGLIB = $(pkglib_IMAGES) $(pkglib_MODULES) $(pkglib_PROGRAMS) \ @@ -98,13 +97,13 @@ MOSTLYCLEANFILES = DISTCLEANFILES = config.status config.cache config.log config.h \ Makefile stamp-h include/grub/cpu include/grub/machine \ gensymlist.sh genkernsyms.sh -MAINTAINER_CLEANFILES = $(srcdir)/configure $(addprefix $(srcdir)/,$(MKFILES)) +MAINTAINER_CLEANFILES = $(srcdir)/configure $(MKFILES) # The default target. all: all-local ### Include an arch-specific Makefile. -$(addprefix $(srcdir)/,$(MKFILES)): %.mk: %.rmk genmk.rb +$(MKFILES): %.mk: %.rmk genmk.rb if test "x$(RUBY)" = x; then \ touch $@; \ else \ diff --git a/commands/efi/acpi.c b/commands/efi/acpi.c index ea9783f00..e65fa0702 100644 --- a/commands/efi/acpi.c +++ b/commands/efi/acpi.c @@ -1,4 +1,4 @@ -/* acpi.c - Display acpi. */ +/* acpi.c - Display acpi tables. */ /* * GRUB -- GRand Unified Bootloader * Copyright (C) 2008 Free Software Foundation, Inc. @@ -23,20 +23,17 @@ static grub_uint32_t read16 (grub_uint8_t *p) { - return p[0] | (p[1] << 8); + return grub_le_to_cpu16 (*(grub_uint16_t *)p); } static grub_uint32_t read32 (grub_uint8_t *p) { - return p[0] | (p[1] << 8) | (p[2] << 16) | (p[3] << 24); + return grub_le_to_cpu32 (*(grub_uint32_t *)p); } static grub_uint64_t read64 (grub_uint8_t *p) { - grub_uint32_t l, h; - l = read32(p); - h = read32(p + 4); - return l | (((grub_uint64_t)h) << 32); + return grub_le_to_cpu64 (*(grub_uint64_t *)p); } static void diff --git a/conf/ia64-efi.rmk b/conf/ia64-efi.rmk index ce72d14c0..d65fda6d5 100644 --- a/conf/ia64-efi.rmk +++ b/conf/ia64-efi.rmk @@ -20,6 +20,7 @@ pkgdata_DATA += kern/ia64/efi/elf_ia64_efi.lds # For grub-elf2pe grub_elf2pe_SOURCES = util/ia64/efi/elf2pe.c +grub_elf2pe_CFLAGS = -DELF2PE_IA64 # For grub-emu. grub_emu_SOURCES = commands/boot.c commands/cat.c commands/cmp.c \ @@ -27,8 +28,12 @@ grub_emu_SOURCES = commands/boot.c commands/cat.c commands/cmp.c \ commands/terminal.c commands/ls.c commands/test.c \ commands/search.c commands/blocklist.c \ disk/loopback.c \ - fs/affs.c fs/ext2.c fs/fat.c fs/fshelp.c fs/hfs.c fs/iso9660.c \ - fs/jfs.c fs/minix.c fs/sfs.c fs/ufs.c fs/xfs.c fs/hfsplus.c \ + \ + fs/affs.c fs/cpio.c fs/ext2.c fs/fat.c fs/hfs.c \ + fs/hfsplus.c fs/iso9660.c fs/jfs.c fs/minix.c \ + fs/ntfs.c fs/ntfscomp.c fs/reiserfs.c fs/sfs.c \ + fs/ufs.c fs/xfs.c \ + \ io/gzio.c \ kern/device.c kern/disk.c kern/dl.c kern/env.c kern/err.c \ normal/execute.c kern/file.c kern/fs.c normal/lexer.c \ diff --git a/config.h.in b/config.h.in index 1aef2123b..c22d5b12b 100644 --- a/config.h.in +++ b/config.h.in @@ -88,10 +88,10 @@ /* Define to the version of this package. */ #undef PACKAGE_VERSION -/* The size of `long', as computed by sizeof. */ +/* The size of a `long', as computed by sizeof. */ #undef SIZEOF_LONG -/* The size of `void *', as computed by sizeof. */ +/* The size of a `void *', as computed by sizeof. */ #undef SIZEOF_VOID_P /* Define it to either start or _start */ diff --git a/include/grub/ia64/efi/kernel.h b/include/grub/ia64/efi/kernel.h index c0549f41a..af1a35b51 100644 --- a/include/grub/ia64/efi/kernel.h +++ b/include/grub/ia64/efi/kernel.h @@ -1,6 +1,6 @@ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2002,2003,2007 Free Software Foundation, Inc. + * Copyright (C) 2002,2003,2007,2008 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 diff --git a/include/grub/ia64/setjmp.h b/include/grub/ia64/setjmp.h index c3b2d3be7..7689a73dd 100644 --- a/include/grub/ia64/setjmp.h +++ b/include/grub/ia64/setjmp.h @@ -1,5 +1,5 @@ /* Define the machine-dependent type `jmp_buf'. Linux/IA-64 version. - Copyright (C) 1999, 2000 Free Software Foundation, Inc. + Copyright (C) 1999, 2000, 2008 Free Software Foundation, Inc. Contributed by David Mosberger-Tang . The GNU C Library is free software; you can redistribute it and/or diff --git a/include/grub/ia64/time.h b/include/grub/ia64/time.h index 5db7ff4f1..03ee79fa4 100644 --- a/include/grub/ia64/time.h +++ b/include/grub/ia64/time.h @@ -1,6 +1,6 @@ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2007 Free Software Foundation, Inc. + * Copyright (C) 2007, 2008 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 diff --git a/kern/ia64/trampoline.S b/kern/ia64/trampoline.S index 376b7bae0..e91991041 100644 --- a/kern/ia64/trampoline.S +++ b/kern/ia64/trampoline.S @@ -23,15 +23,15 @@ .proc __ia64_trampoline .global __ia64_trampoline __ia64_trampoline: - // Read address of the real descriptor + /* Read address of the real descriptor. */ ld8 r2=[r1],8 ;; - // Read chain + /* Read chain. */ ld8 r15=[r1] - // Read pc + /* Read pc. */ ld8 r3=[r2],8 ;; - // Read gp + /* Read gp. */ ld8 r1=[r2] mov b6=r3 br.many b6 diff --git a/loader/ia64/efi/linux.c b/loader/ia64/efi/linux.c index 04c4638f8..47f51c5da 100644 --- a/loader/ia64/efi/linux.c +++ b/loader/ia64/efi/linux.c @@ -39,14 +39,16 @@ #define BOOT_PARAM_SIZE 16384 -struct ia64_boot_param { +struct ia64_boot_param +{ grub_uint64_t command_line; /* physical address of command line. */ grub_uint64_t efi_systab; /* physical address of EFI system table */ grub_uint64_t efi_memmap; /* physical address of EFI memory map */ grub_uint64_t efi_memmap_size; /* size of EFI memory map */ grub_uint64_t efi_memdesc_size; /* size of an EFI memory map descriptor */ grub_uint32_t efi_memdesc_version; /* memory descriptor version */ - struct { + struct + { grub_uint16_t num_cols; /* number of columns on console output dev */ grub_uint16_t num_rows; /* number of rows on console output device */ grub_uint16_t orig_x; /* cursor's x position */ @@ -61,7 +63,8 @@ struct ia64_boot_param { grub_uint64_t modules_nbr; }; -struct ia64_boot_module { +struct ia64_boot_module +{ grub_uint64_t mod_start; grub_uint64_t mod_end; @@ -71,7 +74,8 @@ struct ia64_boot_module { grub_uint64_t next; }; -typedef struct { +typedef struct +{ grub_uint32_t revision; grub_uint32_t reserved; void *fpswa; diff --git a/loader/ia64/efi/linux_normal.c b/loader/ia64/efi/linux_normal.c index 3a567b09f..ec18c4b9b 100644 --- a/loader/ia64/efi/linux_normal.c +++ b/loader/ia64/efi/linux_normal.c @@ -101,7 +101,7 @@ GRUB_MOD_FINI(linux_normal) { grub_unregister_command ("linux"); grub_unregister_command ("initrd"); - grub_unregister_command ("normal"); + grub_unregister_command ("module"); grub_unregister_command ("relocate"); grub_unregister_command ("fpswa"); } diff --git a/normal/ia64/longjmp.S b/normal/ia64/longjmp.S index 23dec8687..729bdc76e 100644 --- a/normal/ia64/longjmp.S +++ b/normal/ia64/longjmp.S @@ -1,4 +1,4 @@ -/* Copyright (C) 1999, 2000, 2001, 2002 Free Software Foundation, Inc. +/* Copyright (C) 1999, 2000, 2001, 2002, 2008 Free Software Foundation, Inc. Contributed by David Mosberger-Tang . The GNU C Library is free software; you can redistribute it and/or diff --git a/normal/ia64/setjmp.S b/normal/ia64/setjmp.S index 4bc2103b7..0851885c5 100644 --- a/normal/ia64/setjmp.S +++ b/normal/ia64/setjmp.S @@ -1,4 +1,4 @@ -/* Copyright (C) 1999, 2000, 2001, 2002 Free Software Foundation, Inc. +/* Copyright (C) 1999, 2000, 2001, 2002, 2008 Free Software Foundation, Inc. Contributed by David Mosberger-Tang . The GNU C Library is free software; you can redistribute it and/or diff --git a/util/ia64/efi/elf2pe.c b/util/ia64/efi/elf2pe.c index 23687fe68..2840e3337 100644 --- a/util/ia64/efi/elf2pe.c +++ b/util/ia64/efi/elf2pe.c @@ -23,12 +23,12 @@ #include #include -#if defined(i386) +#if defined(ELF2PE_I386) #define USE_ELF32 #define USE_PE32 #define ELF_MACHINE EM_386 #define EFI_MACHINE PE32_MACHINE_I386 -#elif defined(__ia64__) +#elif defined(ELF2PE_IA64) #define USE_ELF64 #define USE_PE32PLUS #define ELF_MACHINE EM_IA_64 From 45220d832e50f01524abe27892ab4a71619868be Mon Sep 17 00:00:00 2001 From: Robert Millan Date: Mon, 18 Jan 2010 14:28:03 +0000 Subject: [PATCH 003/869] Third version of the patch (sent to grub-devel in 2008-01-30) --- include/grub/ia64/efi/loader.h | 2 +- loader/ia64/efi/linux.c | 103 +++++++++++++++++---------------- loader/ia64/efi/linux_normal.c | 12 ++-- util/ia64/efi/elf2pe.c | 20 +++---- 4 files changed, 69 insertions(+), 68 deletions(-) diff --git a/include/grub/ia64/efi/loader.h b/include/grub/ia64/efi/loader.h index 623ae5c49..5471a81b5 100644 --- a/include/grub/ia64/efi/loader.h +++ b/include/grub/ia64/efi/loader.h @@ -23,7 +23,7 @@ reuse rescue mode commands. */ void grub_rescue_cmd_linux (int argc, char *argv[]); void grub_rescue_cmd_initrd (int argc, char *argv[]); -void grub_rescue_cmd_module (int argc, char *argv[]); +void grub_rescue_cmd_payload (int argc, char *argv[]); void grub_rescue_cmd_relocate (int argc, char *argv[]); void grub_rescue_cmd_fpswa (int argc, char *argv[]); diff --git a/loader/ia64/efi/linux.c b/loader/ia64/efi/linux.c index 47f51c5da..031bc20dd 100644 --- a/loader/ia64/efi/linux.c +++ b/loader/ia64/efi/linux.c @@ -27,7 +27,7 @@ #include #include #include -/* #include */ +#include #include #include #include @@ -59,16 +59,16 @@ struct ia64_boot_param grub_uint64_t initrd_size; grub_uint64_t domain_start; /* boot domain address. */ grub_uint64_t domain_size; /* how big is the boot domain */ - grub_uint64_t modules_chain; - grub_uint64_t modules_nbr; + grub_uint64_t payloads_chain; + grub_uint64_t payloads_nbr; }; -struct ia64_boot_module +struct ia64_boot_payload { - grub_uint64_t mod_start; - grub_uint64_t mod_end; + grub_uint64_t start; + grub_uint64_t length; - /* Module command line */ + /* Payload command line */ grub_uint64_t cmdline; grub_uint64_t next; @@ -101,7 +101,7 @@ static grub_efi_uintn_t initrd_size; static struct ia64_boot_param *boot_param; static grub_efi_uintn_t boot_param_pages; -static struct ia64_boot_module *last_module = NULL; +static struct ia64_boot_payload *last_payload = NULL; /* Can linux kernel be relocated ? */ #define RELOCATE_OFF 0 /* No. */ @@ -133,14 +133,15 @@ query_fpswa (void) bs = grub_efi_system_table->boot_services; status = bs->locate_handle (GRUB_EFI_BY_PROTOCOL, - &fpswa_protocol, + (void *)&fpswa_protocol, NULL, &size, &fpswa_image); if (status != GRUB_EFI_SUCCESS) { grub_printf("Could not locate FPSWA driver\n"); return; } - status = bs->handle_protocol (fpswa_image, &fpswa_protocol, &fpswa); + status = bs->handle_protocol (fpswa_image, + (void *)&fpswa_protocol, (void *)&fpswa); if (status != GRUB_EFI_SUCCESS) { grub_printf ("Fpswa protocol not able find the interface\n"); @@ -204,20 +205,20 @@ free_pages (void) if (boot_param) { - struct ia64_boot_module *mod; - struct ia64_boot_module *next_mod; + struct ia64_boot_payload *payload; + struct ia64_boot_payload *next_payload; - /* Free modules. */ - mod = (struct ia64_boot_module *)boot_param->modules_chain; - while (mod != 0) + /* Free payloads. */ + payload = (struct ia64_boot_payload *)boot_param->payloads_chain; + while (payload != 0) { - next_mod = (struct ia64_boot_module *)mod->next; + next_payload = (struct ia64_boot_payload *)payload->next; grub_efi_free_boot_pages - (mod->mod_start, page_align (mod->mod_end - mod->mod_start) >> 12); - grub_efi_free_boot_pages ((grub_efi_physical_address_t)mod, 1); + (payload->start, page_align (payload->length) >> 12); + grub_efi_free_boot_pages ((grub_efi_physical_address_t)payload, 1); - mod = next_mod; + payload = next_payload; } /* Free bootparam. */ @@ -446,8 +447,8 @@ grub_load_elf64 (grub_file_t file, void *buffer) kernel_mem = allocate_pages (align, kernel_pages, low_addr); if (kernel_mem) { - reloc_offset = kernel_mem - low_addr; - grub_printf (" Relocated at %p (offset=%016llx)\n", + reloc_offset = (grub_uint64_t)kernel_mem - low_addr; + grub_printf (" Relocated at %p (offset=%016lx)\n", kernel_mem, reloc_offset); entry += reloc_offset; } @@ -463,12 +464,12 @@ grub_load_elf64 (grub_file_t file, void *buffer) + i * ehdr->e_phentsize); if (phdr->p_type == PT_LOAD) { - grub_printf (" [paddr=%llx load=%llx memsz=%08llx " + grub_printf (" [paddr=%lx load=%lx memsz=%08lx " "off=%lx flags=%x]\n", phdr->p_paddr, phdr->p_paddr + reloc_offset, phdr->p_memsz, phdr->p_offset, phdr->p_flags); - if (grub_file_seek (file, phdr->p_offset) == -1) + if (grub_file_seek (file, phdr->p_offset) == (grub_off_t)-1) return grub_error (GRUB_ERR_BAD_OS, "invalid offset in program header"); @@ -582,7 +583,7 @@ grub_rescue_cmd_initrd (int argc, char *argv[]) if (argc == 0) { - grub_error (GRUB_ERR_BAD_ARGUMENT, "No module specified"); + grub_error (GRUB_ERR_BAD_ARGUMENT, "No filename specified"); goto fail; } @@ -619,12 +620,12 @@ grub_rescue_cmd_initrd (int argc, char *argv[]) } void -grub_rescue_cmd_module (int argc, char *argv[]) +grub_rescue_cmd_payload (int argc, char *argv[]) { grub_file_t file = 0; grub_ssize_t size, len = 0; - char *module = 0, *cmdline = 0, *p; - struct ia64_boot_module *mod = NULL; + char *base = 0, *cmdline = 0, *p; + struct ia64_boot_payload *payload = NULL; int i; if (argc == 0) @@ -636,7 +637,7 @@ grub_rescue_cmd_module (int argc, char *argv[]) if (!boot_param) { grub_error (GRUB_ERR_BAD_ARGUMENT, - "You need to load the multiboot kernel first"); + "You need to load the kernel first"); goto fail; } @@ -645,47 +646,47 @@ grub_rescue_cmd_module (int argc, char *argv[]) goto fail; size = grub_file_size (file); - module = grub_efi_allocate_boot_pages (0, page_align (size) >> 12); - if (! module) + base = grub_efi_allocate_boot_pages (0, page_align (size) >> 12); + if (! base) goto fail; - grub_printf ("Module %s [addr=%llx + %lx]\n", - argv[0], (grub_uint64_t)module, size); + grub_printf ("Payload %s [addr=%lx + %lx]\n", + argv[0], (grub_uint64_t)base, size); - if (grub_file_read (file, module, size) != size) + if (grub_file_read (file, base, size) != size) { grub_error (GRUB_ERR_FILE_READ_ERROR, "Couldn't read file"); goto fail; } - len = sizeof (struct ia64_boot_module); + len = sizeof (struct ia64_boot_payload); for (i = 0; i < argc; i++) len += grub_strlen (argv[i]) + 1; if (len > 4096) { - grub_error (GRUB_ERR_OUT_OF_RANGE, "module command line too long"); + grub_error (GRUB_ERR_OUT_OF_RANGE, "payload command line too long"); goto fail; } - mod = grub_efi_allocate_boot_pages (0, 1); - if (! mod) + payload = grub_efi_allocate_boot_pages (0, 1); + if (! payload) goto fail; - p = (char *)(mod + 1); + p = (char *)(payload + 1); - mod->mod_start = (grub_uint64_t)module; - mod->mod_end = (grub_uint64_t)module + size; - mod->cmdline = (grub_uint64_t)p; - mod->next = 0; + payload->start = (grub_uint64_t)base; + payload->length = size; + payload->cmdline = (grub_uint64_t)p; + payload->next = 0; - if (last_module) - last_module->next = (grub_uint64_t)mod; + if (last_payload) + last_payload->next = (grub_uint64_t)payload; else { - last_module = mod; - boot_param->modules_chain = (grub_uint64_t)mod; + last_payload = payload; + boot_param->payloads_chain = (grub_uint64_t)payload; } - boot_param->modules_nbr++; + boot_param->payloads_nbr++; /* Copy command line. */ for (i = 0; i < argc; i++) @@ -704,7 +705,7 @@ grub_rescue_cmd_module (int argc, char *argv[]) if (grub_errno != GRUB_ERR_NONE) { - grub_free (module); + grub_free (base); grub_free (cmdline); } } @@ -761,8 +762,8 @@ GRUB_MOD_INIT(linux) grub_rescue_register_command ("initrd", grub_rescue_cmd_initrd, "load initrd"); - grub_rescue_register_command ("module", grub_rescue_cmd_module, - "load a multiboot module"); + grub_rescue_register_command ("payload", grub_rescue_cmd_payload, + "load an additional file"); grub_rescue_register_command ("relocate", grub_rescue_cmd_relocate, "set relocate feature"); grub_rescue_register_command ("fpswa", grub_rescue_cmd_fpswa, @@ -774,7 +775,7 @@ GRUB_MOD_FINI(linux) { grub_rescue_unregister_command ("linux"); grub_rescue_unregister_command ("initrd"); - grub_rescue_unregister_command ("module"); + grub_rescue_unregister_command ("payload"); grub_rescue_unregister_command ("relocate"); grub_rescue_unregister_command ("fpswa"); } diff --git a/loader/ia64/efi/linux_normal.c b/loader/ia64/efi/linux_normal.c index ec18c4b9b..b5ddffb0d 100644 --- a/loader/ia64/efi/linux_normal.c +++ b/loader/ia64/efi/linux_normal.c @@ -40,10 +40,10 @@ grub_normal_initrd_command (struct grub_arg_list *state __attribute__ ((unused)) } static grub_err_t -grub_normal_cmd_module (struct grub_arg_list *state __attribute__ ((unused)), +grub_normal_cmd_payload (struct grub_arg_list *state __attribute__ ((unused)), int argc, char **args) { - grub_rescue_cmd_module (argc, args); + grub_rescue_cmd_payload (argc, args); return grub_errno; } @@ -79,10 +79,10 @@ GRUB_MOD_INIT(linux_normal) "Load an initrd.", 0); grub_register_command - ("module", grub_normal_cmd_module, + ("payload", grub_normal_cmd_payload, GRUB_COMMAND_FLAG_BOTH | GRUB_COMMAND_FLAG_NO_ARG_PARSE, - "module FILE [ARGS...]", - "Load a Multiboot module.", 0); + "payload FILE [ARGS...]", + "Load an additional file.", 0); grub_register_command ("relocate", grub_normal_cmd_relocate, @@ -101,7 +101,7 @@ GRUB_MOD_FINI(linux_normal) { grub_unregister_command ("linux"); grub_unregister_command ("initrd"); - grub_unregister_command ("module"); + grub_unregister_command ("payload"); grub_unregister_command ("relocate"); grub_unregister_command ("fpswa"); } diff --git a/util/ia64/efi/elf2pe.c b/util/ia64/efi/elf2pe.c index 2840e3337..66d28bde8 100644 --- a/util/ia64/efi/elf2pe.c +++ b/util/ia64/efi/elf2pe.c @@ -70,7 +70,7 @@ typedef Elf64_Sym Elf_Sym; #define ELF_R_SYM(r) ELF64_R_SYM(r) #endif -#ifdef __ia64__ +#ifdef ELF2PE_IA64 #define ELF_ETYPE ET_DYN #else #define ELF_ETYPE ET_EXEC @@ -99,7 +99,7 @@ uint32_t text_offset; uint32_t data_offset; uint32_t reloc_offset; -#ifdef __ia64__ +#ifdef ELF2PE_IA64 uint32_t coff_entry_descr_offset; uint32_t coff_entry_descr_func; uint64_t plt_base; @@ -160,7 +160,7 @@ is_text_shdr (Elf_Shdr *shdr) if (shdr->sh_type != SHT_PROGBITS) { return 0; } -#ifdef __ia64__ +#ifdef ELF2PE_IA64 return (shdr->sh_flags & (SHF_EXECINSTR | SHF_ALLOC)) == (SHF_ALLOC | SHF_EXECINSTR); #else @@ -229,7 +229,7 @@ scan_sections (void) } coff_sections_offset[i] = coff_offset; coff_offset += shdr->sh_size; -#ifdef __ia64__ +#ifdef ELF2PE_IA64 if (coff_sections_offset[i] != shdr->sh_addr) { fprintf (stderr, "Section %s: Coff offset (%x) != Elf offset (%lx)", @@ -244,7 +244,7 @@ scan_sections (void) shdr_dynamic = shdr; } } -#ifdef __ia64__ +#ifdef ELF2PE_IA64 /* 16 bytes are reserved (by the ld script) for the entry point descriptor. */ coff_entry_descr_offset = coff_offset - 16; @@ -259,7 +259,7 @@ scan_sections (void) if (is_data_shdr (shdr)) { coff_sections_offset[i] = coff_offset; coff_offset += shdr->sh_size; -#ifdef __ia64__ +#ifdef ELF2PE_IA64 if (coff_sections_offset[i] != shdr->sh_addr) { fprintf (stderr, "Section %s: Coff offset (%x) != Elf offset (%lx)", @@ -307,7 +307,7 @@ scan_sections (void) nt_hdr->optional_header.code_size = data_offset - text_offset; nt_hdr->optional_header.data_size = reloc_offset - data_offset; nt_hdr->optional_header.bss_size = 0; -#ifdef __ia64__ +#ifdef ELF2PE_IA64 nt_hdr->optional_header.entry_addr = coff_entry_descr_offset; coff_entry_descr_func = coff_entry; #else @@ -335,7 +335,7 @@ scan_sections (void) PE32_SCN_CNT_INITIALIZED_DATA | PE32_SCN_MEM_WRITE | PE32_SCN_MEM_READ); -#ifdef __ia64__ +#ifdef ELF2PE_IA64 if (shdr_dynamic != NULL) { Elf64_Dyn *dyn = (Elf64_Dyn*)((uint8_t*)ehdr + shdr_dynamic->sh_offset); @@ -639,7 +639,7 @@ write_relocations(void) } } -#ifdef __ia64__ +#ifdef ELF2PE_IA64 coff_add_fixup (coff_entry_descr_offset, PE32_REL_BASED_DIR64); coff_add_fixup (coff_entry_descr_offset + 8, PE32_REL_BASED_DIR64); #endif @@ -719,7 +719,7 @@ convert_elf (uint8_t **file_buffer, unsigned int *file_length) if (write_sections (is_text_shdr) != 0) return -3; -#ifdef __ia64__ +#ifdef ELF2PE_IA64 *(uint64_t*)(coff_file + coff_entry_descr_offset) = coff_entry_descr_func; *(uint64_t*)(coff_file + coff_entry_descr_offset + 8) = plt_base; #endif From 85312e19336ae0f773b811f1f9f69832d6ef1f75 Mon Sep 17 00:00:00 2001 From: Robert Millan Date: Mon, 18 Jan 2010 16:14:58 +0000 Subject: [PATCH 004/869] kernel.h adjustments to fix build --- ChangeLog.ia64 | 2 ++ include/grub/ia64/efi/kernel.h | 13 +++++++------ include/grub/ia64/kernel.h | 25 +++++++++++++++++++++++++ 3 files changed, 34 insertions(+), 6 deletions(-) create mode 100644 include/grub/ia64/kernel.h diff --git a/ChangeLog.ia64 b/ChangeLog.ia64 index 64562fb23..453cbd88c 100644 --- a/ChangeLog.ia64 +++ b/ChangeLog.ia64 @@ -1,4 +1,5 @@ 2008-01-28 Tristan Gingold +2010-01-18 Robert Millan * geninit.sh: Call _init with a null argument. * configure.ac: Add ia64-efi target. @@ -24,6 +25,7 @@ * include/grub/ia64/efi/misc.h: New file. * include/grub/ia64/efi/loader.h: New file. * include/grub/ia64/efi/kernel.h: New file. + * include/grub/ia64/kernel.h: New file. * include/grub/ia64/time.h: New file. * include/grub/ia64/setjmp.h: New file. * include/grub/ia64/types.h: New file. diff --git a/include/grub/ia64/efi/kernel.h b/include/grub/ia64/efi/kernel.h index af1a35b51..ae75380f0 100644 --- a/include/grub/ia64/efi/kernel.h +++ b/include/grub/ia64/efi/kernel.h @@ -1,6 +1,6 @@ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2002,2003,2007,2008 Free Software Foundation, Inc. + * Copyright (C) 2002,2003,2007,2008,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 @@ -19,15 +19,16 @@ #ifndef GRUB_MACHINE_KERNEL_HEADER #define GRUB_MACHINE_KERNEL_HEADER 1 -/* The prefix which points to the directory where GRUB modules and its - configuration file are located. */ -extern char grub_prefix[]; - /* The offset of GRUB_PREFIX. */ #define GRUB_KERNEL_MACHINE_PREFIX 0x8 /* End of the data section. */ #define GRUB_KERNEL_MACHINE_DATA_END 0x50 -#endif /* ! GRUB_MACHINE_KERNEL_HEADER */ +#ifndef ASM_FILE +/* The prefix which points to the directory where GRUB modules and its + configuration file are located. */ +extern char grub_prefix[]; +#endif +#endif /* ! GRUB_MACHINE_KERNEL_HEADER */ diff --git a/include/grub/ia64/kernel.h b/include/grub/ia64/kernel.h new file mode 100644 index 000000000..c5496a00b --- /dev/null +++ b/include/grub/ia64/kernel.h @@ -0,0 +1,25 @@ +/* + * 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 . + */ + +#ifndef GRUB_CPU_KERNEL_HEADER +#define GRUB_CPU_KERNEL_HEADER 1 + +#define GRUB_MOD_ALIGN 0x1 +#define GRUB_MOD_GAP 0x0 + +#endif /* ! GRUB_CPU_KERNEL_HEADER */ From c5565c52925a729ffeb275ff1a848376dd6bd543 Mon Sep 17 00:00:00 2001 From: Robert Millan Date: Mon, 18 Jan 2010 17:35:27 +0000 Subject: [PATCH 005/869] Rewrite ia64-efi.rmk --- conf/ia64-efi.rmk | 138 ++++++++++++---------------------------------- 1 file changed, 36 insertions(+), 102 deletions(-) diff --git a/conf/ia64-efi.rmk b/conf/ia64-efi.rmk index d65fda6d5..34f028606 100644 --- a/conf/ia64-efi.rmk +++ b/conf/ia64-efi.rmk @@ -2,126 +2,60 @@ COMMON_ASFLAGS = -nostdinc -fno-builtin COMMON_CFLAGS = -fno-builtin -fpic -minline-int-divide-max-throughput -COMMON_LDFLAGS = -melf_64 -nostdlib +COMMON_LDFLAGS = -melf_64 -nostdlib -STRIP_FLAGS=-R .note -R .comment -X +STRIP_FLAGS = -R .note -R .comment -X -# Utilities. -bin_UTILITIES = grub-elf2pe -#sbin_UTILITIES = grub-emu +# Used by various components. These rules need to precede them. +script/lexer.c_DEPENDENCIES = grub_script.tab.h -# Scripts. -sbin_SCRIPTS = grub-install +bin_UTILITIES += grub-elf2pe +grub_elf2pe_SOURCES = util/ia64/efi/elf2pe.c +grub_elf2pe_CFLAGS = -DELF2PE_IA64 -# For grub-install. +sbin_SCRIPTS += grub-install grub_install_SOURCES = util/ia64/efi/grub-install.in pkgdata_DATA += kern/ia64/efi/elf_ia64_efi.lds -# For grub-elf2pe -grub_elf2pe_SOURCES = util/ia64/efi/elf2pe.c -grub_elf2pe_CFLAGS = -DELF2PE_IA64 +pkglib_MODULES = kernel.img -# For grub-emu. -grub_emu_SOURCES = commands/boot.c commands/cat.c commands/cmp.c \ - commands/configfile.c commands/help.c \ - commands/terminal.c commands/ls.c commands/test.c \ - commands/search.c commands/blocklist.c \ - disk/loopback.c \ - \ - fs/affs.c fs/cpio.c fs/ext2.c fs/fat.c fs/hfs.c \ - fs/hfsplus.c fs/iso9660.c fs/jfs.c fs/minix.c \ - fs/ntfs.c fs/ntfscomp.c fs/reiserfs.c fs/sfs.c \ - fs/ufs.c fs/xfs.c \ - \ - io/gzio.c \ - kern/device.c kern/disk.c kern/dl.c kern/env.c kern/err.c \ - normal/execute.c kern/file.c kern/fs.c normal/lexer.c \ - kern/loader.c kern/main.c kern/misc.c kern/parser.c \ - grub_script.tab.c kern/partition.c kern/rescue.c kern/term.c \ - normal/arg.c normal/cmdline.c normal/command.c normal/function.c\ - normal/completion.c normal/main.c \ - normal/menu.c normal/menu_entry.c normal/misc.c normal/script.c \ - partmap/amiga.c partmap/apple.c partmap/pc.c partmap/sun.c \ - partmap/acorn.c partmap/gpt.c \ - util/console.c util/grub-emu.c util/misc.c \ - util/i386/pc/misc.c grub_emu_init.c - -grub_emu_LDFLAGS = $(LIBCURSES) - -# Modules. -pkglib_MODULES = kernel.mod normal.mod _chain.mod chain.mod \ - _linux.mod linux.mod memmap.mod systab.mod - -# For kernel.mod. -kernel_mod_EXPORTS = no -kernel_mod_SOURCES = kern/ia64/efi/startup.S \ - kern/ia64/trampoline.S \ +kernel_img_EXPORTS = no +kernel_img_SOURCES = kern/ia64/efi/startup.S kern/ia64/trampoline.S \ kern/main.c kern/device.c \ - kern/disk.c kern/dl.c kern/file.c kern/fs.c kern/err.c \ - kern/misc.c kern/mm.c kern/loader.c kern/rescue.c kern/term.c \ - kern/i386/dl.c kern/ia64/efi/init.c kern/parser.c kern/partition.c \ + kern/disk.c kern/file.c kern/fs.c kern/err.c \ + kern/misc.c kern/mm.c kern/term.c \ + kern/rescue_parser.c kern/rescue_reader.c \ + kern/ia64/efi/init.c kern/parser.c kern/partition.c \ kern/env.c symlist.c kern/efi/efi.c kern/efi/init.c kern/efi/mm.c \ - term/efi/console.c disk/efi/efidisk.c -kernel_mod_HEADERS = arg.h boot.h device.h disk.h dl.h elf.h env.h err.h \ - file.h fs.h kernel.h loader.h misc.h mm.h net.h parser.h partition.h \ - pc_partition.h rescue.h symbol.h term.h types.h cache.h \ - i386/efi/time.h efi/efi.h efi/time.h efi/disk.h ia64/efi/misc.h -kernel_mod_CFLAGS = $(COMMON_CFLAGS) -kernel_mod_ASFLAGS = $(COMMON_ASFLAGS) -kernel_mod_LDFLAGS = $(COMMON_LDFLAGS) + term/efi/console.c disk/efi/efidisk.c \ + kern/time.c kern/list.c kern/handler.c kern/command.c kern/corecmd.c \ + kern/generic/rtc_get_time_ms.c \ + kern/generic/millisleep.c \ + commands/boot.c \ + loader/ia64/efi/linux.c \ + commands/halt.c \ + commands/reboot.c \ + commands/efi/memmap.c \ + commands/efi/systab.c \ + commands/efi/acpi2.c +kernel_img_HEADERS = boot.h cache.h device.h disk.h dl.h elf.h elfload.h \ + env.h err.h file.h fs.h kernel.h loader.h misc.h mm.h net.h parser.h \ + partition.h msdos_partition.h reader.h symbol.h term.h time.h types.h \ + cache.h ia64/efi/misc.h \ + efi/efi.h efi/time.h efi/disk.h i386/pit.h list.h handler.h command.h i18n.h +kernel_img_CFLAGS = $(COMMON_CFLAGS) +kernel_img_ASFLAGS = $(COMMON_ASFLAGS) +kernel_img_LDFLAGS = $(COMMON_LDFLAGS) MOSTLYCLEANFILES += symlist.c MOSTLYCLEANFILES += symlist.c kernel_syms.lst DEFSYMFILES += kernel_syms.lst -symlist.c: $(addprefix include/grub/,$(kernel_mod_HEADERS)) config.h gensymlist.sh +symlist.c: $(addprefix include/grub/,$(kernel_img_HEADERS)) config.h gensymlist.sh /bin/sh gensymlist.sh $(filter %.h,$^) > $@ || (rm -f $@; exit 1) -kernel_syms.lst: $(addprefix include/grub/,$(kernel_mod_HEADERS)) config.h genkernsyms.sh +kernel_syms.lst: $(addprefix include/grub/,$(kernel_img_HEADERS)) config.h genkernsyms.sh /bin/sh genkernsyms.sh $(filter %.h,$^) > $@ || (rm -f $@; exit 1) -# For normal.mod. -normal_mod_DEPENDENCIES = grub_script.tab.c grub_script.tab.h -normal_mod_SOURCES = normal/arg.c normal/cmdline.c normal/command.c \ - normal/completion.c normal/execute.c \ - normal/function.c normal/lexer.c normal/main.c normal/menu.c \ - normal/menu_entry.c normal/misc.c grub_script.tab.c \ - normal/script.c \ - normal/ia64/setjmp.S normal/ia64/longjmp.S normal/color.c - -normal_mod_CFLAGS = $(COMMON_CFLAGS) -normal_mod_ASFLAGS = $(COMMON_ASFLAGS) -normal_mod_LDFLAGS = $(COMMON_LDFLAGS) - -# For _chain.mod. -_chain_mod_SOURCES = loader/efi/chainloader.c -_chain_mod_CFLAGS = $(COMMON_CFLAGS) -_chain_mod_LDFLAGS = $(COMMON_LDFLAGS) - -# For chain.mod. -chain_mod_SOURCES = loader/efi/chainloader_normal.c -chain_mod_CFLAGS = $(COMMON_CFLAGS) -chain_mod_LDFLAGS = $(COMMON_LDFLAGS) - -# For _linux.mod. -_linux_mod_SOURCES = loader/ia64/efi/linux.c -_linux_mod_CFLAGS = $(COMMON_CFLAGS) -_linux_mod_LDFLAGS = $(COMMON_LDFLAGS) - -# For linux.mod. -linux_mod_SOURCES = loader/ia64/efi/linux_normal.c -linux_mod_CFLAGS = $(COMMON_CFLAGS) -linux_mod_LDFLAGS = $(COMMON_LDFLAGS) - -# For memmap.mod. -memmap_mod_SOURCES = commands/efi/memmap.c -memmap_mod_CFLAGS = $(COMMON_CFLAGS) -memmap_mod_LDFLAGS = $(COMMON_LDFLAGS) - -# For systab.mod. -systab_mod_SOURCES = commands/efi/systab.c commands/efi/acpi.c -systab_mod_CFLAGS = $(COMMON_CFLAGS) -systab_mod_LDFLAGS = $(COMMON_LDFLAGS) - include $(srcdir)/conf/common.mk From 4e9fe6a2940955d0e84e02b058391409e5c00e9d Mon Sep 17 00:00:00 2001 From: Robert Millan Date: Mon, 18 Jan 2010 17:36:16 +0000 Subject: [PATCH 006/869] Adjust loader for new command interface. --- loader/ia64/efi/linux.c | 51 ++++++++++------ loader/ia64/efi/linux_normal.c | 107 --------------------------------- 2 files changed, 32 insertions(+), 126 deletions(-) delete mode 100644 loader/ia64/efi/linux_normal.c diff --git a/loader/ia64/efi/linux.c b/loader/ia64/efi/linux.c index 031bc20dd..9020efd28 100644 --- a/loader/ia64/efi/linux.c +++ b/loader/ia64/efi/linux.c @@ -1,6 +1,6 @@ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2008 Free Software Foundation, Inc. + * Copyright (C) 2008,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 @@ -23,7 +23,7 @@ #include #include #include -#include +#include #include #include #include @@ -756,26 +756,39 @@ grub_rescue_cmd_fpswa (int argc, char *argv[] __attribute__((unused))) GRUB_MOD_INIT(linux) { - grub_rescue_register_command ("linux", - grub_rescue_cmd_linux, - "load linux"); - grub_rescue_register_command ("initrd", - grub_rescue_cmd_initrd, - "load initrd"); - grub_rescue_register_command ("payload", grub_rescue_cmd_payload, - "load an additional file"); - grub_rescue_register_command ("relocate", grub_rescue_cmd_relocate, - "set relocate feature"); - grub_rescue_register_command ("fpswa", grub_rescue_cmd_fpswa, - "load fpswa"); + grub_register_extcmd ("linux", grub_normal_linux_command, + GRUB_COMMAND_FLAG_BOTH | GRUB_COMMAND_FLAG_NO_ARG_PARSE, + "linux FILE [ARGS...]", + "Load Linux.", 0); + + grub_register_extcmd ("initrd", grub_normal_initrd_command, + GRUB_COMMAND_FLAG_BOTH | GRUB_COMMAND_FLAG_NO_ARG_PARSE, + "initrd FILE", + "Load initrd.", 0); + + grub_register_extcmd ("payload", grub_normal_cmd_payload, + GRUB_COMMAND_FLAG_BOTH | GRUB_COMMAND_FLAG_NO_ARG_PARSE, + "payload FILE [ARGS...]", + "Load an additional file.", 0); + + grub_register_extcmd ("relocate", grub_normal_cmd_relocate, + GRUB_COMMAND_FLAG_BOTH | GRUB_COMMAND_FLAG_NO_ARG_PARSE, + "relocate [on|off|force]", + "Set relocate feature.", 0); + + grub_register_extcmd ("fpswa", grub_normal_cmd_fpswa, + GRUB_COMMAND_FLAG_BOTH | GRUB_COMMAND_FLAG_NO_ARG_PARSE, + "fpswa", + "Display FPSWA version.", 0); + my_mod = mod; } GRUB_MOD_FINI(linux) { - grub_rescue_unregister_command ("linux"); - grub_rescue_unregister_command ("initrd"); - grub_rescue_unregister_command ("payload"); - grub_rescue_unregister_command ("relocate"); - grub_rescue_unregister_command ("fpswa"); + grub_unregister_command ("linux"); + grub_unregister_command ("initrd"); + grub_unregister_command ("payload"); + grub_unregister_command ("relocate"); + grub_unregister_command ("fpswa"); } diff --git a/loader/ia64/efi/linux_normal.c b/loader/ia64/efi/linux_normal.c deleted file mode 100644 index b5ddffb0d..000000000 --- a/loader/ia64/efi/linux_normal.c +++ /dev/null @@ -1,107 +0,0 @@ -/* linux_normal.c - boot linux */ -/* - * GRUB -- GRand Unified Bootloader - * Copyright (C) 2008 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 . - */ - -#include -#include -#include -#include - -static grub_err_t -grub_normal_linux_command (struct grub_arg_list *state __attribute__ ((unused)), - int argc, char **args) -{ - grub_rescue_cmd_linux (argc, args); - return grub_errno; -} - - -static grub_err_t -grub_normal_initrd_command (struct grub_arg_list *state __attribute__ ((unused)), - int argc, char **args) -{ - grub_rescue_cmd_initrd (argc, args); - return grub_errno; -} - -static grub_err_t -grub_normal_cmd_payload (struct grub_arg_list *state __attribute__ ((unused)), - int argc, char **args) -{ - grub_rescue_cmd_payload (argc, args); - return grub_errno; -} - -static grub_err_t -grub_normal_cmd_relocate (struct grub_arg_list *state __attribute__ ((unused)), - int argc, char **args) -{ - grub_rescue_cmd_relocate (argc, args); - return grub_errno; -} - -static grub_err_t -grub_normal_cmd_fpswa (struct grub_arg_list *state __attribute__ ((unused)), - int argc, char **args) -{ - grub_rescue_cmd_fpswa (argc, args); - return grub_errno; -} - -GRUB_MOD_INIT(linux_normal) -{ - (void) mod; /* To stop warning. */ - grub_register_command - ("linux", grub_normal_linux_command, - GRUB_COMMAND_FLAG_BOTH | GRUB_COMMAND_FLAG_NO_ARG_PARSE, - "linux FILE [ARGS...]", - "Load a linux kernel.", 0); - - grub_register_command - ("initrd", grub_normal_initrd_command, - GRUB_COMMAND_FLAG_BOTH | GRUB_COMMAND_FLAG_NO_ARG_PARSE, - "initrd FILE", - "Load an initrd.", 0); - - grub_register_command - ("payload", grub_normal_cmd_payload, - GRUB_COMMAND_FLAG_BOTH | GRUB_COMMAND_FLAG_NO_ARG_PARSE, - "payload FILE [ARGS...]", - "Load an additional file.", 0); - - grub_register_command - ("relocate", grub_normal_cmd_relocate, - GRUB_COMMAND_FLAG_BOTH | GRUB_COMMAND_FLAG_NO_ARG_PARSE, - "relocate [on|off|force]", - "Set relocate feature.", 0); - - grub_register_command - ("fpswa", grub_normal_cmd_fpswa, - GRUB_COMMAND_FLAG_BOTH | GRUB_COMMAND_FLAG_NO_ARG_PARSE, - "fpswa", - "Display FPSWA version.", 0); -} - -GRUB_MOD_FINI(linux_normal) -{ - grub_unregister_command ("linux"); - grub_unregister_command ("initrd"); - grub_unregister_command ("payload"); - grub_unregister_command ("relocate"); - grub_unregister_command ("fpswa"); -} From cba4bdc6a3aa122435d5ec7c96192b01ad3efe9a Mon Sep 17 00:00:00 2001 From: Robert Millan Date: Mon, 18 Jan 2010 17:36:55 +0000 Subject: [PATCH 007/869] Move normal/ia64 to lib/ia64 --- {normal => lib}/ia64/longjmp.S | 0 {normal => lib}/ia64/setjmp.S | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename {normal => lib}/ia64/longjmp.S (100%) rename {normal => lib}/ia64/setjmp.S (100%) diff --git a/normal/ia64/longjmp.S b/lib/ia64/longjmp.S similarity index 100% rename from normal/ia64/longjmp.S rename to lib/ia64/longjmp.S diff --git a/normal/ia64/setjmp.S b/lib/ia64/setjmp.S similarity index 100% rename from normal/ia64/setjmp.S rename to lib/ia64/setjmp.S From 78cd36e08da585214aec7643d0d82b1dc5d643e2 Mon Sep 17 00:00:00 2001 From: Robert Millan Date: Mon, 18 Jan 2010 17:37:19 +0000 Subject: [PATCH 008/869] Disable grub-mkelfimage. --- conf/common.rmk | 7 ------- 1 file changed, 7 deletions(-) diff --git a/conf/common.rmk b/conf/common.rmk index ffcdf045c..d97461753 100644 --- a/conf/common.rmk +++ b/conf/common.rmk @@ -11,13 +11,6 @@ else grub_mkdevicemap_SOURCES += util/devicemap.c endif -# For grub-mkelfimage. -bin_UTILITIES += grub-mkelfimage -grub_mkelfimage_SOURCES = gnulib/progname.c \ - util/elf/grub-mkimage.c util/misc.c \ - util/resolve.c -util/elf/grub-mkimage.c_DEPENDENCIES = Makefile - # For grub-probe. sbin_UTILITIES += grub-probe util/grub-probe.c_DEPENDENCIES = grub_probe_init.h From cdefd058dc54e6538a98de6809cf28c729bc7b9e Mon Sep 17 00:00:00 2001 From: Robert Millan Date: Mon, 18 Jan 2010 17:37:51 +0000 Subject: [PATCH 009/869] grub_*_init() has no argument. Also add branch-specific "module_" prefix. --- geninit.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/geninit.sh b/geninit.sh index 31a6d660b..15e9c76a6 100644 --- a/geninit.sh +++ b/geninit.sh @@ -49,7 +49,7 @@ EOF while read line; do file=`echo $line | cut -f1 -d:` if echo $@ | grep $file >/dev/null; then - echo $line | sed -e 's/.*GRUB_MOD_INIT *(\([a-zA-Z0-9_]*\)).*/ grub_\1_init (0);/' + echo $line | sed -e 's/.*GRUB_MOD_INIT *(\([a-zA-Z0-9_]*\)).*/ grub_module_\1_init ();/' fi done < ${lst} @@ -66,7 +66,7 @@ EOF while read line; do file=`echo $line | cut -f1 -d:` if echo $@ | grep $file >/dev/null; then - echo $line | sed -e 's/.*GRUB_MOD_INIT *(\([a-zA-Z0-9_]*\)).*/ grub_\1_fini ();/' + echo $line | sed -e 's/.*GRUB_MOD_INIT *(\([a-zA-Z0-9_]*\)).*/ grub_module_\1_fini ();/' fi done < ${lst} From 394ec6b646e72f8831a3d61db15433d1471fcf3f Mon Sep 17 00:00:00 2001 From: Robert Millan Date: Mon, 18 Jan 2010 17:38:39 +0000 Subject: [PATCH 010/869] Adjust for new command interface. --- commands/efi/memmap.c | 8 ++++---- commands/efi/systab.c | 10 +++++----- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/commands/efi/memmap.c b/commands/efi/memmap.c index a3ce82841..d49e02080 100644 --- a/commands/efi/memmap.c +++ b/commands/efi/memmap.c @@ -132,12 +132,12 @@ grub_cmd_memmap (struct grub_arg_list *state, int argc, char **args) GRUB_MOD_INIT(memmap) { (void)mod; /* To stop warning. */ - grub_register_command ("memmap", grub_cmd_memmap, GRUB_COMMAND_FLAG_BOTH, - "memmap", - "Display memory map.", NULL); + grub_register_extcmd ("memmap", grub_cmd_memmap, GRUB_COMMAND_FLAG_BOTH, + "memmap", + "Display memory map.", NULL); } GRUB_MOD_FINI(memmap) { - grub_unregister_command ("memmap"); + grub_unregister_extcmd ("memmap"); } diff --git a/commands/efi/systab.c b/commands/efi/systab.c index 1d90ca9ca..27a2cde83 100644 --- a/commands/efi/systab.c +++ b/commands/efi/systab.c @@ -246,13 +246,13 @@ grub_cmd_systab (struct grub_arg_list *state, int argc, char **args) GRUB_MOD_INIT(systab) { - (void)mod; /* To stop warning. */ - grub_register_command ("systab", grub_cmd_systab, GRUB_COMMAND_FLAG_BOTH, - "systab [NAME]", - "Display EFI system table.", NULL); + (void) mod; /* To stop warning. */ + grub_register_extcmd ("systab", grub_cmd_systab, GRUB_COMMAND_FLAG_BOTH, + "systab [NAME]", + "Display EFI system table.", NULL); } GRUB_MOD_FINI(systab) { - grub_unregister_command ("systab"); + grub_unregister_extcmd ("systab"); } From d8a7de8d019702c5448e47f2d19db034f73b051b Mon Sep 17 00:00:00 2001 From: Robert Millan Date: Mon, 18 Jan 2010 17:39:04 +0000 Subject: [PATCH 011/869] Remove memset() declaration (provided by ) --- include/grub/ia64/efi/misc.h | 1 - 1 file changed, 1 deletion(-) diff --git a/include/grub/ia64/efi/misc.h b/include/grub/ia64/efi/misc.h index 2037f7c24..2b99dda62 100644 --- a/include/grub/ia64/efi/misc.h +++ b/include/grub/ia64/efi/misc.h @@ -16,7 +16,6 @@ * along with GRUB. If not, see . */ -void EXPORT_FUNC (memset) (void); void EXPORT_FUNC (__ia64_trampoline) (void); void EXPORT_FUNC (grub_init_modules) (void); From e300c41cb28abbfbd6cff98d2cfd3d38d870f3db Mon Sep 17 00:00:00 2001 From: Robert Millan Date: Mon, 18 Jan 2010 17:39:35 +0000 Subject: [PATCH 012/869] Disable calls to loadable modules (not supported yet) --- kern/main.c | 4 +++- kern/mm.c | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/kern/main.c b/kern/main.c index 7250c73e0..8626c256d 100644 --- a/kern/main.c +++ b/kern/main.c @@ -57,6 +57,7 @@ grub_module_iterate (int (*hook) (struct grub_module_header *header)) static void grub_load_modules (void) { +#if 0 auto int hook (struct grub_module_header *); int hook (struct grub_module_header *header) { @@ -72,6 +73,7 @@ grub_load_modules (void) } grub_module_iterate (hook); +#endif } static void @@ -136,7 +138,7 @@ static void grub_load_normal_mode (void) { /* Load the module. */ - grub_dl_load ("normal"); +// grub_dl_load ("normal"); /* Something went wrong. Print errors here to let user know why we're entering rescue mode. */ grub_print_error (); diff --git a/kern/mm.c b/kern/mm.c index ef97b018e..5d008dc4a 100644 --- a/kern/mm.c +++ b/kern/mm.c @@ -330,7 +330,7 @@ grub_memalign (grub_size_t align, grub_size_t size) case 1: /* Unload unneeded modules. */ - grub_dl_unload_unneeded (); +// grub_dl_unload_unneeded (); count++; goto again; From 4931b0984b1a526c6c86a47b200c2dbb58d2fa50 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 3 Mar 2010 20:09:48 +0100 Subject: [PATCH 013/869] Network infrastructure --- commands/net.c | 296 ++++++++++++++++++++++++++++++++++++++++++ commands/probe.c | 2 +- conf/common.rmk | 6 + include/grub/device.h | 6 +- include/grub/err.h | 5 +- include/grub/net.h | 248 +++++++++++++++++++++++++++++------ kern/fs.c | 2 +- 7 files changed, 522 insertions(+), 43 deletions(-) create mode 100644 commands/net.c diff --git a/commands/net.c b/commands/net.c new file mode 100644 index 000000000..288ba4c2a --- /dev/null +++ b/commands/net.c @@ -0,0 +1,296 @@ +/* + * 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 . + */ + +#include +#include +#include +#include +#include + +struct grub_net_route *grub_net_routes = NULL; +struct grub_net_network_level_interface *grub_net_network_level_interfaces = NULL; +struct grub_net_card *grub_net_cards = NULL; +struct grub_net_network_level_protocol *grub_net_network_level_protocols = NULL; + +grub_err_t +grub_net_resolve_address (struct grub_net_network_level_protocol **prot, + char *name, + grub_net_network_level_address_t *addr) +{ + FOR_NET_NETWORK_LEVEL_PROTOCOLS (*prot) + { + grub_err_t err; + err = grub_net_resolve_address_in_protocol (*prot, name, addr); + if (err == GRUB_ERR_NET_BAD_ADDRESS) + { + grub_errno = GRUB_ERR_NONE; + continue; + } + if (err) + return err; + return GRUB_ERR_NONE; + } + return grub_error (GRUB_ERR_NET_BAD_ADDRESS, N_("Unrecognised address %s"), + name); +} + +grub_err_t +grub_net_route_address (grub_net_network_level_address_t addr, + grub_net_network_level_address_t *gateway, + struct grub_net_network_level_interface **interf) +{ + struct grub_net_route *route; + int depth = 0; + int routecnt = 0; + struct grub_net_network_level_protocol *prot = NULL; + grub_net_network_level_address_t curtarget = addr; + + *gateway = addr; + + FOR_NET_ROUTES(route) + routecnt++; + + for (depth = 0; depth < routecnt + 2; depth++) + { + FOR_NET_ROUTES(route) + { + if (depth && prot != route->prot) + continue; + prot = route->prot; + if (!route->prot->match_net (route->target, curtarget)) + continue; + + if (route->is_gateway) + { + if (depth == 0) + *gateway = route->gw; + curtarget = route->gw; + break; + } + *interf = route->interface; + return GRUB_ERR_NONE; + } + if (route == NULL) + return grub_error (GRUB_ERR_NET_NO_ROUTE, "destination unreachable"); + } + + return grub_error (GRUB_ERR_NET_ROUTE_LOOP, "route loop detected"); +} + +static grub_err_t +grub_cmd_deladdr (struct grub_command *cmd __attribute__ ((unused)), + int argc, char **args) +{ + struct grub_net_network_level_interface *inter; + + if (argc != 4) + return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("one argument expected")); + + FOR_NET_NETWORK_LEVEL_INTERFACES (inter) + if (grub_strcmp (inter->name, args[1])) + break; + if (inter == NULL) + return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("address not found")); + + inter->protocol->fini (inter); + grub_net_network_level_interface_unregister (inter); + grub_free (inter->name); + grub_free (inter); + + return GRUB_ERR_NONE; +} + +static grub_err_t +grub_cmd_addaddr (struct grub_command *cmd __attribute__ ((unused)), + int argc, char **args) +{ + struct grub_net_card *card; + struct grub_net_network_level_protocol *prot; + grub_err_t err; + grub_net_network_level_address_t addr; + struct grub_net_network_level_interface *inter; + + if (argc != 4) + return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("four arguments expected")); + + FOR_NET_CARDS (card) + if (grub_strcmp (card->name, args[1])) + break; + if (card == NULL) + return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("card not found")); + + FOR_NET_NETWORK_LEVEL_PROTOCOLS (prot) + if (grub_strcmp (prot->name, args[2])) + break; + + if (card == NULL) + return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("protocol not found")); + + err = grub_net_resolve_address_in_protocol (prot, args[3], &addr); + if (err) + return err; + + inter = grub_zalloc (sizeof (*inter)); + if (!inter) + return grub_errno; + + inter->name = grub_strdup (args[0]); + inter->protocol = prot; + grub_memcpy (&(inter->address), &addr, sizeof (inter->address)); + inter->card = card; + + err = prot->init (inter); + if (err) + { + grub_free (inter->name); + grub_free (inter); + return err; + } + grub_net_network_level_interface_register (inter); + + return GRUB_ERR_NONE; +} + +static grub_err_t +grub_cmd_delroute (struct grub_command *cmd __attribute__ ((unused)), + int argc, char **args) +{ + struct grub_net_route *route; + struct grub_net_route **prev; + + if (argc != 1) + return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("one argument expected")); + + for (prev = &grub_net_routes, route = *prev; route; prev = &((*prev)->next), + route = *prev) + if (grub_strcmp (route->name, args[0]) == 0) + { + *prev = route->next; + grub_free (route->name); + grub_free (route); + } + + return GRUB_ERR_NONE; +} + +static grub_err_t +grub_cmd_addroute (struct grub_command *cmd __attribute__ ((unused)), + int argc, char **args) +{ + struct grub_net_network_level_protocol *prot; + struct grub_net_route *route; + + if (argc < 3) + return grub_error (GRUB_ERR_BAD_ARGUMENT, + N_("At least 3 arguments are expected")); + + route = grub_zalloc (sizeof (*route)); + if (!route) + return grub_errno; + + route->name = grub_strdup (args[0]); + if (!route->name) + { + grub_free (route); + return grub_errno; + } + + FOR_NET_NETWORK_LEVEL_PROTOCOLS(prot) + { + grub_err_t err; + err = prot->net_ntoa (args[1], &(route->target)); + if (err == GRUB_ERR_NET_BAD_ADDRESS) + { + grub_errno = GRUB_ERR_NONE; + continue; + } + if (err) + return err; + break; + } + + if (!prot) + { + grub_free (route->name); + grub_free (route); + return grub_error (GRUB_ERR_NET_BAD_ADDRESS, + N_("Unrecognised address %s"), args[1]); + } + + if (grub_strcmp (args[2], "gw") == 0 && argc >= 4) + { + grub_err_t err; + route->is_gateway = 1; + err = grub_net_resolve_address_in_protocol (prot, + args[3], &(route->gw)); + if (err) + { + grub_free (route->name); + grub_free (route); + return err; + } + } + else + { + struct grub_net_network_level_interface *inter; + route->is_gateway = 0; + + FOR_NET_NETWORK_LEVEL_INTERFACES (inter) + if (grub_strcmp (inter->name, args[2])) + break; + + if (!inter) + { + grub_free (route->name); + grub_free (route); + return grub_error (GRUB_ERR_BAD_ARGUMENT, + N_("Unrecognised interface %s"), args[2]); + } + route->interface = inter; + } + + grub_net_route_register (route); + + return GRUB_ERR_NONE; +} + +static grub_command_t cmd_addaddr, cmd_deladdr, cmd_addroute, cmd_delroute; + +GRUB_MOD_INIT(net) +{ + cmd_addaddr = grub_register_command ("net_add_addr", grub_cmd_addaddr, + "SHORTNAME CARD PROTOCOL ADDRESS", + N_("Add a network address.")); + cmd_deladdr = grub_register_command ("net_del_addr", grub_cmd_deladdr, + "SHORTNAME", + N_("Delete a network address.")); + cmd_addroute = grub_register_command ("net_add_route", grub_cmd_addroute, + "SHORTNAME NET [INTERFACE| gw GATEWAY]", + N_("Add a network route.")); + cmd_delroute = grub_register_command ("net_del_route", grub_cmd_delroute, + "SHORTNAME", + N_("Delete a network route.")); +} + +GRUB_MOD_FINI(net) +{ + grub_unregister_command (cmd_addaddr); + grub_unregister_command (cmd_deladdr); + grub_unregister_command (cmd_addroute); + grub_unregister_command (cmd_delroute); +} diff --git a/commands/probe.c b/commands/probe.c index c2cc599e9..002ede85e 100644 --- a/commands/probe.c +++ b/commands/probe.c @@ -72,7 +72,7 @@ grub_cmd_probe (grub_extcmd_t cmd, int argc, char **args) { const char *val = "none"; if (dev->net) - val = dev->net->dev->name; + val = dev->net->name; if (dev->disk) val = dev->disk->dev->name; if (state[0].set) diff --git a/conf/common.rmk b/conf/common.rmk index 0f67622b5..cee808a35 100644 --- a/conf/common.rmk +++ b/conf/common.rmk @@ -828,4 +828,10 @@ bin_UTILITIES += grub-mkpasswd-pbkdf2 grub_mkpasswd_pbkdf2_SOURCES = gnulib/progname.c gnulib/getdelim.c gnulib/getline.c util/grub-mkpasswd-pbkdf2.c lib/crypto.c lib/libgcrypt-grub/cipher/sha512.c lib/pbkdf2.c util/misc.c kern/emu/misc.c kern/emu/mm.c kern/err.c grub_mkpasswd_pbkdf2_CFLAGS += -Wno-missing-field-initializers -Wno-error -I$(srcdir)/lib/libgcrypt_wrap -DGRUB_MKPASSWD=1 +pkglib_MODULES += net.mod +net_mod_SOURCES = commands/net.c +net_mod_CFLAGS = $(COMMON_CFLAGS) +net_mod_LDFLAGS = $(COMMON_LDFLAGS) + include $(srcdir)/conf/gcry.mk + diff --git a/include/grub/device.h b/include/grub/device.h index f0e8a8ca8..d68c26e66 100644 --- a/include/grub/device.h +++ b/include/grub/device.h @@ -24,8 +24,12 @@ #include struct grub_disk; -struct grub_net; struct grub_fs; +struct grub_net +{ + char *name; + struct grub_fs *fs; +}; struct grub_device { diff --git a/include/grub/err.h b/include/grub/err.h index e44705389..493796d62 100644 --- a/include/grub/err.h +++ b/include/grub/err.h @@ -54,7 +54,10 @@ typedef enum GRUB_ERR_MENU, GRUB_ERR_TIMEOUT, GRUB_ERR_IO, - GRUB_ERR_ACCESS_DENIED + GRUB_ERR_ACCESS_DENIED, + GRUB_ERR_NET_BAD_ADDRESS, + GRUB_ERR_NET_ROUTE_LOOP, + GRUB_ERR_NET_NO_ROUTE } grub_err_t; diff --git a/include/grub/net.h b/include/grub/net.h index c6d71d5b6..4ca873f74 100644 --- a/include/grub/net.h +++ b/include/grub/net.h @@ -1,6 +1,6 @@ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2002,2007 Free Software Foundation, Inc. + * 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 @@ -19,54 +19,224 @@ #ifndef GRUB_NET_HEADER #define GRUB_NET_HEADER 1 -#include -#include #include +#include +#include -struct grub_net; +struct grub_net_card; -struct grub_net_dev +struct grub_net_card_driver { - /* The device name. */ - const char *name; - - /* FIXME: Just a template. */ - int (*probe) (struct grub_net *net, const void *addr); - void (*reset) (struct grub_net *net); - int (*poll) (struct grub_net *net); - void (*transmit) (struct grub_net *net, const void *destip, - unsigned srcsock, unsigned destsock, const void *packet); - void (*disable) (struct grub_net *net); - - /* The next net device. */ - struct grub_net_dev *next; + grub_err_t (*send) (struct grub_net_card *dev, void *buf, + grub_size_t buflen); + grub_size_t (*recv) (struct grub_net_card *dev, void *buf, + grub_size_t buflen); }; -typedef struct grub_net_dev *grub_net_dev_t; -struct grub_fs; - -struct grub_net +struct grub_net_card { - /* The net name. */ - const char *name; - - /* The underlying disk device. */ - grub_net_dev_t dev; - - /* The binding filesystem. */ - struct grub_fs *fs; - - /* FIXME: More data would be required, such as an IP address, a mask, - a gateway, etc. */ - - /* Device-specific data. */ + struct grub_net_card *next; + char *name; + struct grub_net_card_driver *driver; void *data; }; -typedef struct grub_net *grub_net_t; -/* FIXME: How to abstract networks? More consideration is necessary. */ +struct grub_net_network_level_interface; + +typedef union grub_net_network_level_address +{ + grub_uint32_t ipv4; +} grub_net_network_level_netaddress_t; + +typedef union grub_net_network_level_netaddress +{ + struct { + grub_uint32_t base; + int masksize; + } ipv4; +} grub_net_network_level_address_t; + +typedef enum grub_network_level_protocol_id +{ + GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4 +} grub_network_level_protocol_id_t; + +struct grub_net_network_level_interface; + +struct grub_net_network_level_protocol +{ + struct grub_net_network_level_protocol *next; + char *name; + grub_network_level_protocol_id_t id; + grub_err_t (*ntoa) (char *name, grub_net_network_level_address_t *addr); + char * (*aton) (union grub_net_network_level_address addr); + grub_err_t (*net_ntoa) (char *name, + grub_net_network_level_netaddress_t *addr); + char * (*net_aton) (grub_net_network_level_netaddress_t addr); + int (* match_net) (grub_net_network_level_netaddress_t net, + grub_net_network_level_address_t addr); + grub_err_t (*init) (struct grub_net_network_level_interface *dev); + grub_err_t (*fini) (struct grub_net_network_level_interface *dev); + grub_err_t (*send) (struct grub_net_network_level_interface *dev, void *buf, + grub_size_t buflen); + grub_size_t (*recv) (struct grub_net_network_level_interface *dev, void *buf, + grub_size_t buflen); +}; + +struct grub_net_network_level_interface +{ + struct grub_net_network_level_interface *next; + char *name; + /* Underlying protocol. */ + struct grub_net_network_level_protocol *protocol; + struct grub_net_card *card; + union grub_net_network_level_address address; + void *data; +}; + +struct grub_net_route +{ + struct grub_net_route *next; + grub_net_network_level_netaddress_t target; + char *name; + struct grub_net_network_level_protocol *prot; + int is_gateway; + union + { + struct grub_net_network_level_interface *interface; + grub_net_network_level_address_t gw; + }; +}; + +struct grub_net_session; + +struct grub_net_session_level_protocol +{ + void (*close) (struct grub_net_session *session); + grub_ssize_t (*recv) (struct grub_net_session *session, void *buf, + grub_size_t size); + grub_err_t (*send) (struct grub_net_session *session, void *buf, + grub_size_t size); +}; + +struct grub_net_session +{ + struct grub_net_session_level_protocol *protocol; + void *data; +}; + +static inline void +grub_net_session_close (struct grub_net_session *session) +{ + session->protocol->close (session); +} + +static inline grub_err_t +grub_net_session_send (struct grub_net_session *session, void *buf, + grub_size_t size) +{ + return session->protocol->send (session, buf, size); +} + +static inline grub_ssize_t +grub_net_session_recv (struct grub_net_session *session, void *buf, + grub_size_t size) +{ + return session->protocol->recv (session, buf, size); +} + +extern struct grub_net_network_level_interface *grub_net_network_level_interfaces; + +static inline void +grub_net_network_level_interface_register (struct grub_net_network_level_interface *inter) +{ + grub_list_push (GRUB_AS_LIST_P (&grub_net_network_level_interfaces), + GRUB_AS_LIST (inter)); +} + +static inline void +grub_net_network_level_interface_unregister (struct grub_net_network_level_interface *inter) +{ + grub_list_remove (GRUB_AS_LIST_P (&grub_net_network_level_interfaces), + GRUB_AS_LIST (inter)); +} + +#define FOR_NET_NETWORK_LEVEL_INTERFACES(var) for (var = grub_net_network_level_interfaces; var; var = var->next) + +extern struct grub_net_route *grub_net_routes; + +static inline void +grub_net_route_register (struct grub_net_route *route) +{ + grub_list_push (GRUB_AS_LIST_P (&grub_net_routes), + GRUB_AS_LIST (route)); +} + +static inline void +grub_net_route_unregister (struct grub_net_route *route) +{ + grub_list_remove (GRUB_AS_LIST_P (&grub_net_routes), + GRUB_AS_LIST (route)); +} + +#define FOR_NET_ROUTES(var) for (var = grub_net_routes; var; var = var->next) + +extern struct grub_net_card *grub_net_cards; + +static inline void +grub_net_card_register (struct grub_net_card *card) +{ + grub_list_push (GRUB_AS_LIST_P (&grub_net_cards), + GRUB_AS_LIST (card)); +} + +static inline void +grub_net_card_unregister (struct grub_net_card *card) +{ + grub_list_remove (GRUB_AS_LIST_P (&grub_net_cards), + GRUB_AS_LIST (card)); +} + +#define FOR_NET_CARDS(var) for (var = grub_net_cards; var; var = var->next) + +extern struct grub_net_network_level_protocol *grub_net_network_level_protocols; + +static inline void +grub_net_network_level_protocol_register (struct grub_net_network_level_protocol *prot) +{ + grub_list_push (GRUB_AS_LIST_P (&grub_net_network_level_protocols), + GRUB_AS_LIST (prot)); +} + +static inline void +grub_net_network_level_protocol_unregister (struct grub_net_network_level_protocol *prot) +{ + grub_list_remove (GRUB_AS_LIST_P (&grub_net_network_level_protocols), + GRUB_AS_LIST (prot)); +} + +#define FOR_NET_NETWORK_LEVEL_PROTOCOLS(var) for ((var) = grub_net_network_level_protocols; (var); (var) = (var)->next) + +static inline grub_err_t +grub_net_resolve_address_in_protocol (struct grub_net_network_level_protocol *prot, + char *name, + grub_net_network_level_address_t *addr) +{ + return prot->ntoa (name, addr); +} + +struct grub_net_session * +grub_net_open_tcp (char *address, grub_uint16_t port); + +grub_err_t +grub_net_resolve_address (struct grub_net_network_level_protocol **prot, + char *name, + grub_net_network_level_address_t *addr); + +grub_err_t +grub_net_route_address (grub_net_network_level_address_t addr, + grub_net_network_level_address_t *gateway, + struct grub_net_network_level_interface **interf); -/* Note: Networks are very different from disks, because networks must - be initialized before used, and the status is persistent. */ #endif /* ! GRUB_NET_HEADER */ diff --git a/kern/fs.c b/kern/fs.c index cf800f4cc..8ffb93c8b 100644 --- a/kern/fs.c +++ b/kern/fs.c @@ -94,7 +94,7 @@ grub_fs_probe (grub_device_t device) count--; } } - else if (device->net->fs) + else if (device->net) return device->net->fs; grub_error (GRUB_ERR_UNKNOWN_FS, "unknown filesystem"); From 1bf0e31cfb90a05389715ebda22734dff7f38d7c Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 3 Mar 2010 20:09:48 +0100 Subject: [PATCH 014/869] Network infrastructure --- commands/net.c | 296 ++++++++++++++++++++++++++++++++++++++++++ commands/probe.c | 2 +- conf/common.rmk | 6 + include/grub/device.h | 6 +- include/grub/err.h | 5 +- include/grub/net.h | 248 +++++++++++++++++++++++++++++------ kern/fs.c | 2 +- 7 files changed, 522 insertions(+), 43 deletions(-) create mode 100644 commands/net.c diff --git a/commands/net.c b/commands/net.c new file mode 100644 index 000000000..288ba4c2a --- /dev/null +++ b/commands/net.c @@ -0,0 +1,296 @@ +/* + * 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 . + */ + +#include +#include +#include +#include +#include + +struct grub_net_route *grub_net_routes = NULL; +struct grub_net_network_level_interface *grub_net_network_level_interfaces = NULL; +struct grub_net_card *grub_net_cards = NULL; +struct grub_net_network_level_protocol *grub_net_network_level_protocols = NULL; + +grub_err_t +grub_net_resolve_address (struct grub_net_network_level_protocol **prot, + char *name, + grub_net_network_level_address_t *addr) +{ + FOR_NET_NETWORK_LEVEL_PROTOCOLS (*prot) + { + grub_err_t err; + err = grub_net_resolve_address_in_protocol (*prot, name, addr); + if (err == GRUB_ERR_NET_BAD_ADDRESS) + { + grub_errno = GRUB_ERR_NONE; + continue; + } + if (err) + return err; + return GRUB_ERR_NONE; + } + return grub_error (GRUB_ERR_NET_BAD_ADDRESS, N_("Unrecognised address %s"), + name); +} + +grub_err_t +grub_net_route_address (grub_net_network_level_address_t addr, + grub_net_network_level_address_t *gateway, + struct grub_net_network_level_interface **interf) +{ + struct grub_net_route *route; + int depth = 0; + int routecnt = 0; + struct grub_net_network_level_protocol *prot = NULL; + grub_net_network_level_address_t curtarget = addr; + + *gateway = addr; + + FOR_NET_ROUTES(route) + routecnt++; + + for (depth = 0; depth < routecnt + 2; depth++) + { + FOR_NET_ROUTES(route) + { + if (depth && prot != route->prot) + continue; + prot = route->prot; + if (!route->prot->match_net (route->target, curtarget)) + continue; + + if (route->is_gateway) + { + if (depth == 0) + *gateway = route->gw; + curtarget = route->gw; + break; + } + *interf = route->interface; + return GRUB_ERR_NONE; + } + if (route == NULL) + return grub_error (GRUB_ERR_NET_NO_ROUTE, "destination unreachable"); + } + + return grub_error (GRUB_ERR_NET_ROUTE_LOOP, "route loop detected"); +} + +static grub_err_t +grub_cmd_deladdr (struct grub_command *cmd __attribute__ ((unused)), + int argc, char **args) +{ + struct grub_net_network_level_interface *inter; + + if (argc != 4) + return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("one argument expected")); + + FOR_NET_NETWORK_LEVEL_INTERFACES (inter) + if (grub_strcmp (inter->name, args[1])) + break; + if (inter == NULL) + return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("address not found")); + + inter->protocol->fini (inter); + grub_net_network_level_interface_unregister (inter); + grub_free (inter->name); + grub_free (inter); + + return GRUB_ERR_NONE; +} + +static grub_err_t +grub_cmd_addaddr (struct grub_command *cmd __attribute__ ((unused)), + int argc, char **args) +{ + struct grub_net_card *card; + struct grub_net_network_level_protocol *prot; + grub_err_t err; + grub_net_network_level_address_t addr; + struct grub_net_network_level_interface *inter; + + if (argc != 4) + return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("four arguments expected")); + + FOR_NET_CARDS (card) + if (grub_strcmp (card->name, args[1])) + break; + if (card == NULL) + return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("card not found")); + + FOR_NET_NETWORK_LEVEL_PROTOCOLS (prot) + if (grub_strcmp (prot->name, args[2])) + break; + + if (card == NULL) + return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("protocol not found")); + + err = grub_net_resolve_address_in_protocol (prot, args[3], &addr); + if (err) + return err; + + inter = grub_zalloc (sizeof (*inter)); + if (!inter) + return grub_errno; + + inter->name = grub_strdup (args[0]); + inter->protocol = prot; + grub_memcpy (&(inter->address), &addr, sizeof (inter->address)); + inter->card = card; + + err = prot->init (inter); + if (err) + { + grub_free (inter->name); + grub_free (inter); + return err; + } + grub_net_network_level_interface_register (inter); + + return GRUB_ERR_NONE; +} + +static grub_err_t +grub_cmd_delroute (struct grub_command *cmd __attribute__ ((unused)), + int argc, char **args) +{ + struct grub_net_route *route; + struct grub_net_route **prev; + + if (argc != 1) + return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("one argument expected")); + + for (prev = &grub_net_routes, route = *prev; route; prev = &((*prev)->next), + route = *prev) + if (grub_strcmp (route->name, args[0]) == 0) + { + *prev = route->next; + grub_free (route->name); + grub_free (route); + } + + return GRUB_ERR_NONE; +} + +static grub_err_t +grub_cmd_addroute (struct grub_command *cmd __attribute__ ((unused)), + int argc, char **args) +{ + struct grub_net_network_level_protocol *prot; + struct grub_net_route *route; + + if (argc < 3) + return grub_error (GRUB_ERR_BAD_ARGUMENT, + N_("At least 3 arguments are expected")); + + route = grub_zalloc (sizeof (*route)); + if (!route) + return grub_errno; + + route->name = grub_strdup (args[0]); + if (!route->name) + { + grub_free (route); + return grub_errno; + } + + FOR_NET_NETWORK_LEVEL_PROTOCOLS(prot) + { + grub_err_t err; + err = prot->net_ntoa (args[1], &(route->target)); + if (err == GRUB_ERR_NET_BAD_ADDRESS) + { + grub_errno = GRUB_ERR_NONE; + continue; + } + if (err) + return err; + break; + } + + if (!prot) + { + grub_free (route->name); + grub_free (route); + return grub_error (GRUB_ERR_NET_BAD_ADDRESS, + N_("Unrecognised address %s"), args[1]); + } + + if (grub_strcmp (args[2], "gw") == 0 && argc >= 4) + { + grub_err_t err; + route->is_gateway = 1; + err = grub_net_resolve_address_in_protocol (prot, + args[3], &(route->gw)); + if (err) + { + grub_free (route->name); + grub_free (route); + return err; + } + } + else + { + struct grub_net_network_level_interface *inter; + route->is_gateway = 0; + + FOR_NET_NETWORK_LEVEL_INTERFACES (inter) + if (grub_strcmp (inter->name, args[2])) + break; + + if (!inter) + { + grub_free (route->name); + grub_free (route); + return grub_error (GRUB_ERR_BAD_ARGUMENT, + N_("Unrecognised interface %s"), args[2]); + } + route->interface = inter; + } + + grub_net_route_register (route); + + return GRUB_ERR_NONE; +} + +static grub_command_t cmd_addaddr, cmd_deladdr, cmd_addroute, cmd_delroute; + +GRUB_MOD_INIT(net) +{ + cmd_addaddr = grub_register_command ("net_add_addr", grub_cmd_addaddr, + "SHORTNAME CARD PROTOCOL ADDRESS", + N_("Add a network address.")); + cmd_deladdr = grub_register_command ("net_del_addr", grub_cmd_deladdr, + "SHORTNAME", + N_("Delete a network address.")); + cmd_addroute = grub_register_command ("net_add_route", grub_cmd_addroute, + "SHORTNAME NET [INTERFACE| gw GATEWAY]", + N_("Add a network route.")); + cmd_delroute = grub_register_command ("net_del_route", grub_cmd_delroute, + "SHORTNAME", + N_("Delete a network route.")); +} + +GRUB_MOD_FINI(net) +{ + grub_unregister_command (cmd_addaddr); + grub_unregister_command (cmd_deladdr); + grub_unregister_command (cmd_addroute); + grub_unregister_command (cmd_delroute); +} diff --git a/commands/probe.c b/commands/probe.c index c2cc599e9..002ede85e 100644 --- a/commands/probe.c +++ b/commands/probe.c @@ -72,7 +72,7 @@ grub_cmd_probe (grub_extcmd_t cmd, int argc, char **args) { const char *val = "none"; if (dev->net) - val = dev->net->dev->name; + val = dev->net->name; if (dev->disk) val = dev->disk->dev->name; if (state[0].set) diff --git a/conf/common.rmk b/conf/common.rmk index 7effa8af3..f1ed1478d 100644 --- a/conf/common.rmk +++ b/conf/common.rmk @@ -779,4 +779,10 @@ bin_UTILITIES += grub-mkpasswd-pbkdf2 grub_mkpasswd_pbkdf2_SOURCES = gnulib/progname.c gnulib/getdelim.c gnulib/getline.c util/grub-mkpasswd-pbkdf2.c lib/crypto.c lib/libgcrypt-grub/cipher/sha512.c lib/pbkdf2.c util/misc.c kern/err.c grub_mkpasswd_pbkdf2_CFLAGS += -Wno-missing-field-initializers -Wno-error -I$(srcdir)/lib/libgcrypt_wrap -DGRUB_MKPASSWD=1 +pkglib_MODULES += net.mod +net_mod_SOURCES = commands/net.c +net_mod_CFLAGS = $(COMMON_CFLAGS) +net_mod_LDFLAGS = $(COMMON_LDFLAGS) + include $(srcdir)/conf/gcry.mk + diff --git a/include/grub/device.h b/include/grub/device.h index f0e8a8ca8..d68c26e66 100644 --- a/include/grub/device.h +++ b/include/grub/device.h @@ -24,8 +24,12 @@ #include struct grub_disk; -struct grub_net; struct grub_fs; +struct grub_net +{ + char *name; + struct grub_fs *fs; +}; struct grub_device { diff --git a/include/grub/err.h b/include/grub/err.h index e44705389..493796d62 100644 --- a/include/grub/err.h +++ b/include/grub/err.h @@ -54,7 +54,10 @@ typedef enum GRUB_ERR_MENU, GRUB_ERR_TIMEOUT, GRUB_ERR_IO, - GRUB_ERR_ACCESS_DENIED + GRUB_ERR_ACCESS_DENIED, + GRUB_ERR_NET_BAD_ADDRESS, + GRUB_ERR_NET_ROUTE_LOOP, + GRUB_ERR_NET_NO_ROUTE } grub_err_t; diff --git a/include/grub/net.h b/include/grub/net.h index c6d71d5b6..4ca873f74 100644 --- a/include/grub/net.h +++ b/include/grub/net.h @@ -1,6 +1,6 @@ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2002,2007 Free Software Foundation, Inc. + * 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 @@ -19,54 +19,224 @@ #ifndef GRUB_NET_HEADER #define GRUB_NET_HEADER 1 -#include -#include #include +#include +#include -struct grub_net; +struct grub_net_card; -struct grub_net_dev +struct grub_net_card_driver { - /* The device name. */ - const char *name; - - /* FIXME: Just a template. */ - int (*probe) (struct grub_net *net, const void *addr); - void (*reset) (struct grub_net *net); - int (*poll) (struct grub_net *net); - void (*transmit) (struct grub_net *net, const void *destip, - unsigned srcsock, unsigned destsock, const void *packet); - void (*disable) (struct grub_net *net); - - /* The next net device. */ - struct grub_net_dev *next; + grub_err_t (*send) (struct grub_net_card *dev, void *buf, + grub_size_t buflen); + grub_size_t (*recv) (struct grub_net_card *dev, void *buf, + grub_size_t buflen); }; -typedef struct grub_net_dev *grub_net_dev_t; -struct grub_fs; - -struct grub_net +struct grub_net_card { - /* The net name. */ - const char *name; - - /* The underlying disk device. */ - grub_net_dev_t dev; - - /* The binding filesystem. */ - struct grub_fs *fs; - - /* FIXME: More data would be required, such as an IP address, a mask, - a gateway, etc. */ - - /* Device-specific data. */ + struct grub_net_card *next; + char *name; + struct grub_net_card_driver *driver; void *data; }; -typedef struct grub_net *grub_net_t; -/* FIXME: How to abstract networks? More consideration is necessary. */ +struct grub_net_network_level_interface; + +typedef union grub_net_network_level_address +{ + grub_uint32_t ipv4; +} grub_net_network_level_netaddress_t; + +typedef union grub_net_network_level_netaddress +{ + struct { + grub_uint32_t base; + int masksize; + } ipv4; +} grub_net_network_level_address_t; + +typedef enum grub_network_level_protocol_id +{ + GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4 +} grub_network_level_protocol_id_t; + +struct grub_net_network_level_interface; + +struct grub_net_network_level_protocol +{ + struct grub_net_network_level_protocol *next; + char *name; + grub_network_level_protocol_id_t id; + grub_err_t (*ntoa) (char *name, grub_net_network_level_address_t *addr); + char * (*aton) (union grub_net_network_level_address addr); + grub_err_t (*net_ntoa) (char *name, + grub_net_network_level_netaddress_t *addr); + char * (*net_aton) (grub_net_network_level_netaddress_t addr); + int (* match_net) (grub_net_network_level_netaddress_t net, + grub_net_network_level_address_t addr); + grub_err_t (*init) (struct grub_net_network_level_interface *dev); + grub_err_t (*fini) (struct grub_net_network_level_interface *dev); + grub_err_t (*send) (struct grub_net_network_level_interface *dev, void *buf, + grub_size_t buflen); + grub_size_t (*recv) (struct grub_net_network_level_interface *dev, void *buf, + grub_size_t buflen); +}; + +struct grub_net_network_level_interface +{ + struct grub_net_network_level_interface *next; + char *name; + /* Underlying protocol. */ + struct grub_net_network_level_protocol *protocol; + struct grub_net_card *card; + union grub_net_network_level_address address; + void *data; +}; + +struct grub_net_route +{ + struct grub_net_route *next; + grub_net_network_level_netaddress_t target; + char *name; + struct grub_net_network_level_protocol *prot; + int is_gateway; + union + { + struct grub_net_network_level_interface *interface; + grub_net_network_level_address_t gw; + }; +}; + +struct grub_net_session; + +struct grub_net_session_level_protocol +{ + void (*close) (struct grub_net_session *session); + grub_ssize_t (*recv) (struct grub_net_session *session, void *buf, + grub_size_t size); + grub_err_t (*send) (struct grub_net_session *session, void *buf, + grub_size_t size); +}; + +struct grub_net_session +{ + struct grub_net_session_level_protocol *protocol; + void *data; +}; + +static inline void +grub_net_session_close (struct grub_net_session *session) +{ + session->protocol->close (session); +} + +static inline grub_err_t +grub_net_session_send (struct grub_net_session *session, void *buf, + grub_size_t size) +{ + return session->protocol->send (session, buf, size); +} + +static inline grub_ssize_t +grub_net_session_recv (struct grub_net_session *session, void *buf, + grub_size_t size) +{ + return session->protocol->recv (session, buf, size); +} + +extern struct grub_net_network_level_interface *grub_net_network_level_interfaces; + +static inline void +grub_net_network_level_interface_register (struct grub_net_network_level_interface *inter) +{ + grub_list_push (GRUB_AS_LIST_P (&grub_net_network_level_interfaces), + GRUB_AS_LIST (inter)); +} + +static inline void +grub_net_network_level_interface_unregister (struct grub_net_network_level_interface *inter) +{ + grub_list_remove (GRUB_AS_LIST_P (&grub_net_network_level_interfaces), + GRUB_AS_LIST (inter)); +} + +#define FOR_NET_NETWORK_LEVEL_INTERFACES(var) for (var = grub_net_network_level_interfaces; var; var = var->next) + +extern struct grub_net_route *grub_net_routes; + +static inline void +grub_net_route_register (struct grub_net_route *route) +{ + grub_list_push (GRUB_AS_LIST_P (&grub_net_routes), + GRUB_AS_LIST (route)); +} + +static inline void +grub_net_route_unregister (struct grub_net_route *route) +{ + grub_list_remove (GRUB_AS_LIST_P (&grub_net_routes), + GRUB_AS_LIST (route)); +} + +#define FOR_NET_ROUTES(var) for (var = grub_net_routes; var; var = var->next) + +extern struct grub_net_card *grub_net_cards; + +static inline void +grub_net_card_register (struct grub_net_card *card) +{ + grub_list_push (GRUB_AS_LIST_P (&grub_net_cards), + GRUB_AS_LIST (card)); +} + +static inline void +grub_net_card_unregister (struct grub_net_card *card) +{ + grub_list_remove (GRUB_AS_LIST_P (&grub_net_cards), + GRUB_AS_LIST (card)); +} + +#define FOR_NET_CARDS(var) for (var = grub_net_cards; var; var = var->next) + +extern struct grub_net_network_level_protocol *grub_net_network_level_protocols; + +static inline void +grub_net_network_level_protocol_register (struct grub_net_network_level_protocol *prot) +{ + grub_list_push (GRUB_AS_LIST_P (&grub_net_network_level_protocols), + GRUB_AS_LIST (prot)); +} + +static inline void +grub_net_network_level_protocol_unregister (struct grub_net_network_level_protocol *prot) +{ + grub_list_remove (GRUB_AS_LIST_P (&grub_net_network_level_protocols), + GRUB_AS_LIST (prot)); +} + +#define FOR_NET_NETWORK_LEVEL_PROTOCOLS(var) for ((var) = grub_net_network_level_protocols; (var); (var) = (var)->next) + +static inline grub_err_t +grub_net_resolve_address_in_protocol (struct grub_net_network_level_protocol *prot, + char *name, + grub_net_network_level_address_t *addr) +{ + return prot->ntoa (name, addr); +} + +struct grub_net_session * +grub_net_open_tcp (char *address, grub_uint16_t port); + +grub_err_t +grub_net_resolve_address (struct grub_net_network_level_protocol **prot, + char *name, + grub_net_network_level_address_t *addr); + +grub_err_t +grub_net_route_address (grub_net_network_level_address_t addr, + grub_net_network_level_address_t *gateway, + struct grub_net_network_level_interface **interf); -/* Note: Networks are very different from disks, because networks must - be initialized before used, and the status is persistent. */ #endif /* ! GRUB_NET_HEADER */ diff --git a/kern/fs.c b/kern/fs.c index 0c456377f..7bd1445b0 100644 --- a/kern/fs.c +++ b/kern/fs.c @@ -124,7 +124,7 @@ grub_fs_probe (grub_device_t device) count--; } } - else if (device->net->fs) + else if (device->net) return device->net->fs; grub_error (GRUB_ERR_UNKNOWN_FS, "unknown filesystem"); From 066528b4b18ed5870be40ef333bc85d2344ee812 Mon Sep 17 00:00:00 2001 From: "Manoel R. Abranches" Date: Tue, 27 Apr 2010 18:05:35 -0300 Subject: [PATCH 015/869] Initial Implementation of TFTP protocol and new protocol structs. --- conf/powerpc-ieee1275.rmk | 8 +- include/grub/net.h | 19 ++++- include/grub/net/arp.h | 23 ++++++ include/grub/net/device.h | 7 ++ include/grub/net/ethernet.h | 12 +++ include/grub/net/ieee1275/interface.h | 21 ++++++ include/grub/net/interface.h | 17 +++++ include/grub/net/ip.h | 25 +++++++ include/grub/net/netbuff.h | 27 +++++++ include/grub/net/protocol.h | 50 +++++++++++++ include/grub/net/tftp.h | 74 +++++++++++++++++++ include/grub/net/type_net.h | 7 ++ include/grub/net/udp.h | 22 ++++++ net/arp.c | 0 net/device.c | 0 net/ethernet.c | 54 ++++++++++++++ net/ieee1275/interface.c | 80 ++++++++++++++++++++ net/interface.c | 0 net/ip.c | 95 ++++++++++++++++++++++++ net/netbuff.c | 72 ++++++++++++++++++ net/protocol.c | 21 ++++++ net/tftp.c | 102 ++++++++++++++++++++++++++ net/udp.c | 59 +++++++++++++++ 23 files changed, 789 insertions(+), 6 deletions(-) create mode 100644 include/grub/net/arp.h create mode 100644 include/grub/net/device.h create mode 100644 include/grub/net/ethernet.h create mode 100644 include/grub/net/ieee1275/interface.h create mode 100644 include/grub/net/interface.h create mode 100644 include/grub/net/ip.h create mode 100644 include/grub/net/netbuff.h create mode 100644 include/grub/net/protocol.h create mode 100644 include/grub/net/tftp.h create mode 100644 include/grub/net/type_net.h create mode 100644 include/grub/net/udp.h create mode 100644 net/arp.c create mode 100644 net/device.c create mode 100644 net/ethernet.c create mode 100644 net/ieee1275/interface.c create mode 100644 net/interface.c create mode 100644 net/ip.c create mode 100644 net/netbuff.c create mode 100644 net/protocol.c create mode 100644 net/tftp.c create mode 100644 net/udp.c diff --git a/conf/powerpc-ieee1275.rmk b/conf/powerpc-ieee1275.rmk index be95b30ba..14d04f93e 100644 --- a/conf/powerpc-ieee1275.rmk +++ b/conf/powerpc-ieee1275.rmk @@ -3,7 +3,10 @@ # Images. -kernel_img_HEADERS += ieee1275/ieee1275.h +<<<<<<< TREE +kernel_img_HEADERS += ieee1275/ieee1275.h \ + command.h i18n.h env_private.h net/ip.h net/udp.h net/ethernet.h net/arp.h net/tftp.h\ + net/ieee1275/interface.h net/type_net.h net.h net/interface.h net/protocol.h net/netbuff.h # Programs pkglib_PROGRAMS = kernel.img @@ -20,7 +23,8 @@ kernel_img_SOURCES = kern/powerpc/ieee1275/startup.S kern/ieee1275/cmain.c \ kern/ieee1275/openfw.c disk/ieee1275/ofdisk.c \ kern/parser.c kern/partition.c kern/env.c kern/$(target_cpu)/dl.c \ kern/generic/millisleep.c kern/time.c \ - symlist.c kern/$(target_cpu)/cache.S + symlist.c kern/$(target_cpu)/cache.S net/ip.c net/tftp.c net/udp.c net/ethernet.c net/arp.c \ + net/ieee1275/interface.c net/interface.c net/protocol.c net/netbuff.c kernel_img_CFLAGS = $(COMMON_CFLAGS) kernel_img_ASFLAGS = $(COMMON_ASFLAGS) kernel_img_LDFLAGS += $(COMMON_LDFLAGS) -Wl,-N,-S,-Ttext,0x200000,-Bstatic diff --git a/include/grub/net.h b/include/grub/net.h index 4ca873f74..75efd51d6 100644 --- a/include/grub/net.h +++ b/include/grub/net.h @@ -22,15 +22,20 @@ #include #include #include +#include struct grub_net_card; struct grub_net_card_driver { - grub_err_t (*send) (struct grub_net_card *dev, void *buf, - grub_size_t buflen); - grub_size_t (*recv) (struct grub_net_card *dev, void *buf, - grub_size_t buflen); + grub_err_t (*send) (struct grub_net_card *dev,struct grub_net_buff *nb); + grub_size_t (*recv) (struct grub_net_card *dev,struct grub_net_buff *nb); +}; + +struct grub_net_addr +{ + grub_uint8_t *addr; + grub_size_t len; }; struct grub_net_card @@ -38,6 +43,12 @@ struct grub_net_card struct grub_net_card *next; char *name; struct grub_net_card_driver *driver; + /*transport layer address*/ + struct grub_net_addr *tla; + /*internet layer address*/ + struct grub_net_addr *ila; + /*link layer address*/ + struct grub_net_addr *lla; void *data; }; diff --git a/include/grub/net/arp.h b/include/grub/net/arp.h new file mode 100644 index 000000000..0ac2ec832 --- /dev/null +++ b/include/grub/net/arp.h @@ -0,0 +1,23 @@ +#ifndef GRUB_NET_ARP_HEADER +#define GRUB_NET_ARP_HEADER 1 + +#include +struct arprequest { + grub_int16_t hwtype; /* hardware type (must be ARPHRD_ETHER) */ + grub_int16_t protocol; /* protocol type (must be ETH_P_IP) */ + grub_int8_t hwlen; /* hardware address length (must be 6) */ + grub_int8_t protolen; /* protocol address length (must be 4) */ + grub_uint16_t opcode; /* ARP opcode */ + grub_uint8_t shwaddr[6]; /* sender's hardware address */ + grub_uint32_t sipaddr; /* sender's IP address */ + grub_uint8_t thwaddr[6]; /* target's hardware address */ + grub_uint32_t tipaddr; /* target's IP address */ +}__attribute__ ((packed)); + + +struct arp_pkt{ + struct etherhdr ether; + struct arprequest arpr; +} __attribute__ ((packed)); + +#endif diff --git a/include/grub/net/device.h b/include/grub/net/device.h new file mode 100644 index 000000000..9f1b9bf1d --- /dev/null +++ b/include/grub/net/device.h @@ -0,0 +1,7 @@ +struct grub_net_card +{ + struct grub_net_card *next; + char *name; + struct grub_net_card_driver *driver; + void *data; +}; diff --git a/include/grub/net/ethernet.h b/include/grub/net/ethernet.h new file mode 100644 index 000000000..46aa04f60 --- /dev/null +++ b/include/grub/net/ethernet.h @@ -0,0 +1,12 @@ +#ifndef GRUB_NET_ETHERNET_HEADER +#define GRUB_NET_ETHERNET_HEADER 1 +#include +struct etherhdr { + grub_uint8_t dst[6]; + grub_uint8_t src[6]; + grub_uint16_t type; +} __attribute__ ((packed)) ; + +void ethernet_ini(void); +void ethernet_fini(void); +#endif diff --git a/include/grub/net/ieee1275/interface.h b/include/grub/net/ieee1275/interface.h new file mode 100644 index 000000000..edc242cab --- /dev/null +++ b/include/grub/net/ieee1275/interface.h @@ -0,0 +1,21 @@ +#ifndef GRUB_IEEE1275_INTERFACE_HEADER +#define GRUB_IEEE1275_INTERFACE_HEADER 1 + +#include +#include +#include + +grub_ofnet_t EXPORT_VAR(grub_net); + +grub_bootp_t EXPORT_VAR(bootp_pckt); +grub_uint32_t get_server_ip(void); +grub_uint32_t get_client_ip(void); +grub_uint8_t* get_server_mac (void); +grub_uint8_t* get_client_mac (void); + +int send_card_buffer (void *buffer,int buff_len); +int get_card_buffer (void *buffer,int buff_len); +int card_open (void); +int card_close (void); + +#endif diff --git a/include/grub/net/interface.h b/include/grub/net/interface.h new file mode 100644 index 000000000..0e11c86ba --- /dev/null +++ b/include/grub/net/interface.h @@ -0,0 +1,17 @@ +#ifndef GRUB_INTERFACE_HEADER +#define GRUB_INTERFACE_HEADER +#include +#include +/* +extern struct grub_net_topprotocol; + +struct grub_net_interface +{ + struct grub_net_card *card; + struct grub_net_topprotocol* topprot; + struct grub_net_addr *tla; + struct grub_net_addr *ila; + struct grub_net_addr *lla; +}; +*/ +#endif diff --git a/include/grub/net/ip.h b/include/grub/net/ip.h new file mode 100644 index 000000000..e1f45dcfa --- /dev/null +++ b/include/grub/net/ip.h @@ -0,0 +1,25 @@ +#ifndef GRUB_NET_IP_HEADER +#define GRUB_NET_IP_HEADER 1 +#include + + +struct iphdr { + grub_uint8_t verhdrlen; + grub_uint8_t service; + grub_uint16_t len; + grub_uint16_t ident; + grub_uint16_t frags; + grub_uint8_t ttl; + grub_uint8_t protocol; + grub_uint16_t chksum; + grub_uint32_t src; + grub_uint32_t dest; +} __attribute__ ((packed)) ; + +#define IP_UDP 17 /* UDP protocol */ +#define IP_BROADCAST 0xFFFFFFFF + +grub_uint16_t ipchksum(void *ipv, int len); +void ipv4_ini(void); +void ipv4_fini(void); +#endif diff --git a/include/grub/net/netbuff.h b/include/grub/net/netbuff.h new file mode 100644 index 000000000..7d63be1f5 --- /dev/null +++ b/include/grub/net/netbuff.h @@ -0,0 +1,27 @@ +#ifndef GRUB_NETBUFF_HEADER +#define GRUB_NETBUFF_HEADER + +#include + +#define NETBUFF_ALIGN 2048 +#define NETBUFFMINLEN 64 + +struct grub_net_buff +{ + /*Pointer to the start of the buffer*/ + char *head; + /*Pointer to the data */ + char *data; + /*Pointer to the tail */ + char *tail; + /*Pointer to the end of the buffer*/ + char *end; +}; + +grub_err_t grub_netbuff_put (struct grub_net_buff *net_buff ,grub_size_t len); +grub_err_t grub_netbuff_unput (struct grub_net_buff *net_buff ,grub_size_t len); +grub_err_t grub_netbuff_push (struct grub_net_buff *net_buff ,grub_size_t len); +grub_err_t grub_netbuff_pull (struct grub_net_buff *net_buff ,grub_size_t len); +grub_err_t grub_netbuff_reserve (struct grub_net_buff *net_buff ,grub_size_t len); +struct grub_net_buff * grub_netbuff_alloc ( grub_size_t len ); +#endif diff --git a/include/grub/net/protocol.h b/include/grub/net/protocol.h new file mode 100644 index 000000000..2c979481b --- /dev/null +++ b/include/grub/net/protocol.h @@ -0,0 +1,50 @@ +#ifndef GRUB_PROTOCOL_HEADER +#define GRUB_PROTOCOL_HEADER +#include +#include +#include +#include +struct protocol_operations; +struct grub_net_protocol; +struct grub_net_interface; + +struct grub_net_protocol +{ + struct grub_net_protocol *next; + char *name; + grub_err_t (*open) (struct grub_net_interface* inf, + struct grub_net_protocol *prot, struct grub_net_buff *nb); + grub_err_t (*open_confirm) (struct grub_net_interface *inf, + struct grub_net_protocol *prot, struct grub_net_buff *nb); + grub_err_t (*get_payload) (struct grub_net_interface *inf, + struct grub_net_protocol *prot, struct grub_net_buff *nb); + grub_err_t (*get_payload_confirm) (struct grub_net_interface* inf, + struct grub_net_protocol *prot, struct grub_net_buff *nb); + grub_err_t (*close) (struct grub_net_interface *inf, + struct grub_net_protocol *prot, struct grub_net_buff *nb); + grub_err_t (*send) (struct grub_net_interface *inf , + struct grub_net_protocol *prot, struct grub_net_buff *nb); + grub_err_t (*recv) (struct grub_net_interface *inf , + struct grub_net_protocol *prot, struct grub_net_buff *nb); +}; + +typedef struct grub_net_protocol *grub_net_protocol_t; + +struct grub_net_interface +{ + struct grub_net_card *card; + struct grub_net_protocol* prot; + char *path; + char *username; + char *password; + /*transport layer addres*/ + struct grub_net_addr *tla; + /*internet layer addres*/ + struct grub_net_addr *ila; + /*link layer addres*/ + struct grub_net_addr *lla; +}; + +void grub_protocol_register (grub_net_protocol_t prot); +void grub_protocol_unregister (grub_net_protocol_t prot); +#endif diff --git a/include/grub/net/tftp.h b/include/grub/net/tftp.h new file mode 100644 index 000000000..4148096c5 --- /dev/null +++ b/include/grub/net/tftp.h @@ -0,0 +1,74 @@ +#ifndef GRUB_NET_TFTP_HEADER +#define GRUB_NET_TFTP_HEADER 1 + +#include +#include +#include + +/* IP port for the MTFTP server used for Intel's PXE */ +#define MTFTP_SERVER_PORT 75 +#define MTFTP_CLIENT_PORT 76 + +#define TFTP_DEFAULTSIZE_PACKET 512 +#define TFTP_MAX_PACKET 1432 + +/* IP port for the TFTP server */ +#define TFTP_SERVER_PORT 69 +#define TFTP_CLIENT_PORT 2000 + + +/* We define these based on what's in arpa/tftp.h. We just like our + * names better, cause they're clearer */ +#define TFTP_RRQ 1 +#define TFTP_WRQ 2 +#define TFTP_DATA 3 +#define TFTP_ACK 4 +#define TFTP_ERROR 5 +#define TFTP_OACK 6 + +#define TFTP_CODE_EOF 1 +#define TFTP_CODE_MORE 2 +#define TFTP_CODE_ERROR 3 +#define TFTP_CODE_BOOT 4 +#define TFTP_CODE_CFG 5 + +#define TFTP_EUNDEF 0 /* not defined */ +#define TFTP_ENOTFOUND 1 /* file not found */ +#define TFTP_EACCESS 2 /* access violation */ +#define TFTP_ENOSPACE 3 /* disk full or allocation exceeded */ +#define TFTP_EBADOP 4 /* illegal TFTP operation */ +#define TFTP_EBADID 5 /* unknown transfer ID */ +#define TFTP_EEXISTS 6 /* file already exists */ +#define TFTP_ENOUSER 7 /* no such user */ +#define TFTP_DEFAULT_FILENAME "kernel" + + + + + + /* * own here because this is cleaner, and maps to the same data layout. + * */ +struct tftphdr { + grub_uint16_t opcode; + union { + grub_int8_t rrq[TFTP_DEFAULTSIZE_PACKET]; + struct { + grub_uint16_t block; + grub_int8_t download[TFTP_MAX_PACKET]; + } data; + struct { + grub_uint16_t block; + } ack; + struct { + grub_uint16_t errcode; + grub_int8_t errmsg[TFTP_DEFAULTSIZE_PACKET]; + } err; + struct { + grub_int8_t data[TFTP_DEFAULTSIZE_PACKET+2]; + } oack; + } u; +} __attribute__ ((packed)) ; + +void tftp_ini(void); +void tftp_fini(void); +#endif diff --git a/include/grub/net/type_net.h b/include/grub/net/type_net.h new file mode 100644 index 000000000..33f2d802d --- /dev/null +++ b/include/grub/net/type_net.h @@ -0,0 +1,7 @@ +#ifndef GRUB_TYPES_NET_HEADER +#define GRUB_TYPES_NET_HEADER 1 + +#define UDP_PCKT 0x11 +#define IP_PCKT 0x0800 + +#endif diff --git a/include/grub/net/udp.h b/include/grub/net/udp.h new file mode 100644 index 000000000..dbfcecef0 --- /dev/null +++ b/include/grub/net/udp.h @@ -0,0 +1,22 @@ +#ifndef GRUB_NET_UDP_HEADER +#define GRUB_NET_UDP_HEADER 1 +#include +/* +typedef enum + { + GRUB_PROT_TFTP + } protocol_type; +*/ + +#define GRUB_PROT_TFTP 1 + +struct udphdr { + grub_uint16_t src; + grub_uint16_t dst; + grub_uint16_t len; + grub_uint16_t chksum; +} __attribute__ ((packed)); + +void udp_ini(void); +void udp_fini(void); +#endif diff --git a/net/arp.c b/net/arp.c new file mode 100644 index 000000000..e69de29bb diff --git a/net/device.c b/net/device.c new file mode 100644 index 000000000..e69de29bb diff --git a/net/ethernet.c b/net/ethernet.c new file mode 100644 index 000000000..fc64803e7 --- /dev/null +++ b/net/ethernet.c @@ -0,0 +1,54 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +static grub_err_t +send_ethernet_packet (struct grub_net_interface *inf, struct grub_net_protocol *prot __attribute__ ((unused)) + ,struct grub_net_buff *nb) +{ + + struct etherhdr *eth; + grub_err_t err; + + if((err = grub_netbuff_push (nb,sizeof(*eth)) ) != GRUB_ERR_NONE) + return err; + eth = (struct etherhdr *) nb->data; + grub_memcpy (eth->src,inf->card->lla->addr,6 * sizeof (grub_uint8_t )); + grub_memcpy (eth->dst,inf->lla->addr,6 * sizeof (grub_uint8_t )); + eth->type = 0x0800; + + return inf->card->driver->send(inf->card,nb); +} + +static struct grub_net_protocol grub_ethernet_protocol = +{ + .name = "udp", + .send = send_ethernet_packet +}; + +void ethernet_ini(void) +{ + grub_protocol_register (&grub_ethernet_protocol); +} + +void ethernet_fini(void) +{ + grub_protocol_unregister (&grub_ethernet_protocol); +} +/* +int read_ethernet_packet(buffer,bufflen, int type) +{ + + struct etherhdr eth; + eth.type = 0; + + get_card_buffer (ð,sizeof (eth)); + + + +}*/ diff --git a/net/ieee1275/interface.c b/net/ieee1275/interface.c new file mode 100644 index 000000000..5a246ffa5 --- /dev/null +++ b/net/ieee1275/interface.c @@ -0,0 +1,80 @@ +#include +#include + +grub_uint32_t get_server_ip (void) +{ + return bootp_pckt->siaddr; +} + +grub_uint32_t get_client_ip (void) +{ + return bootp_pckt->yiaddr; +} + +grub_uint8_t* get_server_mac (void) +{ + grub_uint8_t *mac; + + mac = grub_malloc (6 * sizeof(grub_uint8_t)); + mac[0] = 0x00 ; + mac[1] = 0x11 ; + mac[2] = 0x25 ; + mac[3] = 0xca ; + mac[4] = 0x1f ; + mac[5] = 0x01 ; + + return mac; + +} + +grub_uint8_t* get_client_mac (void) +{ + grub_uint8_t *mac; + + mac = grub_malloc (6 * sizeof (grub_uint8_t)); + mac[0] = 0x0a ; + mac[1] = 0x11 ; + mac[2] = 0xbd ; + mac[3] = 0xe3 ; + mac[4] = 0xe3 ; + mac[5] = 0x04 ; + + return mac; +} + +static grub_ieee1275_ihandle_t handle; +int card_open (void) +{ + + grub_ieee1275_open (grub_net->dev , &handle); + return 1;//error + +} +int card_close (void) +{ + + if (handle) + grub_ieee1275_close (handle); + return 0; +} + + +int send_card_buffer (void *buffer,int buff_len) +{ + + int actual; + + grub_ieee1275_write (handle,buffer,buff_len,&actual); + + return actual; +} + +int get_card_buffer (void *buffer,int buff_len) +{ + + int actual; + + grub_ieee1275_read (handle,buffer,buff_len,&actual); + + return actual; +} diff --git a/net/interface.c b/net/interface.c new file mode 100644 index 000000000..e69de29bb diff --git a/net/ip.c b/net/ip.c new file mode 100644 index 000000000..c669ff6d7 --- /dev/null +++ b/net/ip.c @@ -0,0 +1,95 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +struct grub_net_protocol *grub_ipv4_prot; + +grub_uint16_t +ipchksum(void *ipv, int len) +{ + grub_uint16_t *ip = (grub_uint16_t *)ipv; + grub_uint32_t sum = 0; + + + len >>= 1; + while (len--) { + sum += *(ip++); + if (sum > 0xFFFF) + sum -= 0xFFFF; + } + + return((~sum) & 0x0000FFFF); +} + + +static grub_err_t +send_ip_packet (struct grub_net_interface *inf, struct grub_net_protocol *prot, struct grub_net_buff *nb ) +{ + + struct iphdr *iph; + grub_err_t err; + + if((err = grub_netbuff_push(nb,sizeof(*iph)) ) != GRUB_ERR_NONE) + return err; + iph = (struct iphdr *) nb->data; + + /*FIXME dont work in litte endian machines*/ + //grub_uint8_t ver = 4; + //grub_uint8_t hdrlen = sizeof (struct iphdr)/4; + iph->verhdrlen = (4<<4 | 5); + iph->service = 0; + iph->len = sizeof(*iph); + iph->ident = 0x2b5f; + iph->frags = 0; + iph->ttl = 0xff; + iph->protocol = 0x11; + //grub_memcpy(&(iph->src) ,inf->card->ila->addr,inf->card->ila->len); + iph->src = *((grub_uint32_t *)inf->card->ila->addr); + //grub_memcpy(&(iph->dest) ,inf->ila->addr,inf->ila->len); + iph->dest = *((grub_uint32_t *)inf->ila->addr); + + iph->chksum = 0 ; + iph->chksum = ipchksum((void *)nb->head, sizeof(*iph)); + + + return prot->next->send(inf,prot->next,nb); +} + +static struct grub_net_protocol grub_ipv4_protocol = +{ + .name = "ipv4", + .send = send_ip_packet, + .recv = NULL +}; + +void ipv4_ini(void) +{ + grub_protocol_register (&grub_ipv4_protocol); +} + +void ipv4_fini(void) +{ + grub_protocol_unregister (&grub_ipv4_protocol); +} + +/* +int read_ip_packet (void *buffer,int *bufflen) +{ + struct iphdr iph; + iph.protocol = 0; + + while ( iph.protocol != IP_UDP) + { + read_ethernet_packet(buffer,bufflen,IP_PROTOCOL); + grub_memcpy (&iph,buffer,sizeof (iph)); + } + + buffer += sizeof (iph); + *buff_len -= sizeof (iph); + +}*/ diff --git a/net/netbuff.c b/net/netbuff.c new file mode 100644 index 000000000..342260f43 --- /dev/null +++ b/net/netbuff.c @@ -0,0 +1,72 @@ +/* + * 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 . + */ + +#include +#include +#include +#include + + +grub_err_t grub_netbuff_put (struct grub_net_buff *net_buff ,grub_size_t len) +{ + net_buff->tail += len; + if (net_buff->tail > net_buff->end) + return grub_error (GRUB_ERR_OUT_OF_RANGE, "out of the packet range."); + return GRUB_ERR_NONE; +} + +grub_err_t grub_netbuff_unput (struct grub_net_buff *net_buff ,grub_size_t len) +{ + net_buff->tail -= len; + if (net_buff->tail < net_buff->head) + return grub_error (GRUB_ERR_OUT_OF_RANGE, "out of the packet range."); + return GRUB_ERR_NONE; +} + +grub_err_t grub_netbuff_push (struct grub_net_buff *net_buff ,grub_size_t len) +{ + net_buff->data -= len; + if (net_buff->data < net_buff->head) + return grub_error (GRUB_ERR_OUT_OF_RANGE, "out of the packet range."); + return GRUB_ERR_NONE; +} + +grub_err_t grub_netbuff_pull (struct grub_net_buff *net_buff ,grub_size_t len) +{ + net_buff->data += len; + if (net_buff->data > net_buff->end) + return grub_error (GRUB_ERR_OUT_OF_RANGE, "out of the packet range."); + return GRUB_ERR_NONE; +} + +grub_err_t grub_netbuff_reserve (struct grub_net_buff *net_buff ,grub_size_t len) +{ + net_buff->data += len; + net_buff->tail += len; + if ((net_buff->tail > net_buff->end) || (net_buff->data > net_buff->end)) + return grub_error (GRUB_ERR_OUT_OF_RANGE, "out of the packet range."); + return GRUB_ERR_NONE; +} + +struct grub_net_buff * grub_netbuff_alloc ( grub_size_t len ) +{ + if (len < NETBUFFMINLEN) + len = NETBUFFMINLEN; + len = ALIGN_UP (len,NETBUFF_ALIGN); + return (struct grub_net_buff *) grub_memalign (len,NETBUFF_ALIGN); +} diff --git a/net/protocol.c b/net/protocol.c new file mode 100644 index 000000000..a6117dc2c --- /dev/null +++ b/net/protocol.c @@ -0,0 +1,21 @@ +#include + +static grub_net_protocol_t grub_net_protocols; + +void grub_protocol_register (grub_net_protocol_t prot) +{ + prot->next = grub_net_protocols; + grub_net_protocols = prot; +} + +void grub_protocol_unregister (grub_net_protocol_t prot) +{ + grub_net_protocol_t *p, q; + + for (p = &grub_net_protocols, q = *p; q; p = &(q->next), q = q->next) + if (q == prot) + { + *p = q->next; + break; + } +} diff --git a/net/tftp.c b/net/tftp.c new file mode 100644 index 000000000..fdca184e9 --- /dev/null +++ b/net/tftp.c @@ -0,0 +1,102 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/*send read request*/ +static grub_err_t +send_tftp_rr (struct grub_net_interface *inf, struct grub_net_protocol *prot,struct grub_net_buff *nb) +{ + /*Start TFTP header*/ + + struct tftphdr *tftph; + char *rrq; + int rrqlen; + int hdrlen; + grub_err_t err; + + if((err = grub_netbuff_push (nb,sizeof(*tftph))) != GRUB_ERR_NONE) + return err; + + tftph = (struct tftphdr *) nb->data; + + rrq = (char *) tftph->u.rrq; + rrqlen = 0; + + tftph->opcode = TFTP_RRQ; + grub_strcpy (rrq,inf->path); + rrqlen += grub_strlen (inf->path) + 1; + rrq += grub_strlen (inf->path) + 1; + /*passar opcoes como parametro ou usar default?*/ + + grub_strcpy (rrq,"octet"); + rrqlen += grub_strlen ("octet") + 1; + rrq += grub_strlen ("octet") + 1; + + grub_strcpy (rrq,"blksize"); + rrqlen += grub_strlen("blksize") + 1; + rrq += grub_strlen ("blksize") + 1; + + grub_strcpy (rrq,"1024"); + rrqlen += grub_strlen ("1024") + 1; + rrq += grub_strlen ("1024") + 1; + + grub_strcpy (rrq,"tsize"); + rrqlen += grub_strlen ("tsize") + 1; + rrq += grub_strlen ("tsize") + 1; + + grub_strcpy (rrq,"0"); + rrqlen += grub_strlen ("0") + 1; + rrq += grub_strlen ("0") + 1; + hdrlen = sizeof (tftph->opcode) + rrqlen; + + grub_netbuff_unput (nb,nb->tail - (nb->data+hdrlen)); + + return prot->next->send(inf,prot->next,nb); +} + +/* +int send_tftp_ack(int block, int port){ + + tftp_t pckt; + int pcktlen; + pckt.opcode = TFTP_ACK; + pckt.u.ack.block = block; + pcktlen = sizeof (pckt.opcode) + sizeof (pckt.u.ack.block); + + port = 4; + return 0;// send_udp_packet (&pckt,pcktlen,TFTP_CLIENT_PORT,port); +} + +*/ + +static struct grub_net_protocol grub_tftp_protocol = +{ + .name = "tftp", + .open = send_tftp_rr + +}; + +void tftp_ini(void) +{ + grub_protocol_register (&grub_tftp_protocol); +} + +void tftp_fini(void) +{ + grub_protocol_unregister (&grub_tftp_protocol); +} +/* +int read_tftp_pckt (grub_uint16_t port, void *buffer, int &buff_len){ + + + read_udp_packet (port,buffer,buff_len); + + +}*/ diff --git a/net/udp.c b/net/udp.c new file mode 100644 index 000000000..600eec542 --- /dev/null +++ b/net/udp.c @@ -0,0 +1,59 @@ +#include +#include +#include +#include +#include +/*Assumes that there is allocated memory to the header before the buffer address. */ +static grub_err_t +send_udp_packet (struct grub_net_interface *inf, struct grub_net_protocol *prot, struct grub_net_buff *nb) +{ + + struct udphdr *udph; + grub_err_t err; + + if((err = grub_netbuff_push (nb,sizeof(*udph)) ) != GRUB_ERR_NONE) + return err; + + udph = (struct udphdr *) nb->data; + udph->src = *((grub_uint16_t *) inf->card->tla->addr); + udph->dst = *((grub_uint16_t *) inf->tla->addr); + /*no chksum*/ + udph->chksum = 0; + udph->len = sizeof (sizeof (*udph)) + nb->end - nb->head; + + return prot->next->send(inf,prot->next,nb); +} + +static struct grub_net_protocol grub_udp_protocol = +{ + .name = "udp", + .send = send_udp_packet +}; + +void udp_ini(void) +{ + grub_protocol_register (&grub_udp_protocol); +} + +void udp_fini(void) +{ + grub_protocol_unregister (&grub_udp_protocol); +} + +/* +int read_udp_packet (grub_uint16_t port,void *buffer,int *buff_len) +{ + + struct udphdr udph; + udph.dst = 0; + + while ( udph.dst != port) + { + read_ip_packet (buffer,bufflen); + grub_memcpy (&udph,buffer,sizeof (udph)); + } + + buffer += sizeof (udph); + *buff_len -= sizeof (udph); + +}*/ From 8d402bc9a8041f0ed15290901e0ff5f115ed5cc0 Mon Sep 17 00:00:00 2001 From: "Manoel R. Abranches" Date: Thu, 29 Apr 2010 17:56:09 -0300 Subject: [PATCH 016/869] small change in the interface structure. --- include/grub/net.h | 14 ++++++++++++++ include/grub/net/interface.h | 18 ++++++++++++++---- include/grub/net/protocol.h | 33 +++++++++------------------------ net/ethernet.c | 3 ++- net/ip.c | 5 +++-- net/tftp.c | 5 +++-- net/udp.c | 5 +++-- 7 files changed, 48 insertions(+), 35 deletions(-) diff --git a/include/grub/net.h b/include/grub/net.h index 75efd51d6..f021f0e9c 100644 --- a/include/grub/net.h +++ b/include/grub/net.h @@ -26,8 +26,22 @@ struct grub_net_card; +typedef enum +{ + GRUB_NET_TFTP_ID, + GRUB_NET_UDP_ID, + GRUB_NET_IPV4_ID, + GRUB_NET_IPV6_ID, + GRUB_NET_ETHERNET_ID, + GRUB_NET_ARP_ID, + GRUB_NET_DHCP_ID + +}protocol_type_t; + struct grub_net_card_driver { + grub_err_t (*init) (struct grub_net_card *dev); + grub_err_t (*fini) (struct grub_net_card *dev); grub_err_t (*send) (struct grub_net_card *dev,struct grub_net_buff *nb); grub_size_t (*recv) (struct grub_net_card *dev,struct grub_net_buff *nb); }; diff --git a/include/grub/net/interface.h b/include/grub/net/interface.h index 0e11c86ba..2e0ddfcc8 100644 --- a/include/grub/net/interface.h +++ b/include/grub/net/interface.h @@ -2,16 +2,26 @@ #define GRUB_INTERFACE_HEADER #include #include -/* -extern struct grub_net_topprotocol; + +struct grub_net_protstack +{ + struct grub_net_protstack *next; + struct grub_net_protocol* prot; +}; struct grub_net_interface { struct grub_net_card *card; - struct grub_net_topprotocol* topprot; + struct grub_net_protstack* protstack; + char *path; + char *username; + char *password; + /*transport layer addres*/ struct grub_net_addr *tla; + /*internet layer addres*/ struct grub_net_addr *ila; + /*link layer addres*/ struct grub_net_addr *lla; }; -*/ + #endif diff --git a/include/grub/net/protocol.h b/include/grub/net/protocol.h index 2c979481b..1efc2ab7b 100644 --- a/include/grub/net/protocol.h +++ b/include/grub/net/protocol.h @@ -4,47 +4,32 @@ #include #include #include -struct protocol_operations; + struct grub_net_protocol; struct grub_net_interface; +struct grub_net_protstack; struct grub_net_protocol { struct grub_net_protocol *next; char *name; grub_err_t (*open) (struct grub_net_interface* inf, - struct grub_net_protocol *prot, struct grub_net_buff *nb); + struct grub_net_protstack *protstack, struct grub_net_buff *nb); grub_err_t (*open_confirm) (struct grub_net_interface *inf, - struct grub_net_protocol *prot, struct grub_net_buff *nb); + struct grub_net_protstack *protstack, struct grub_net_buff *nb); grub_err_t (*get_payload) (struct grub_net_interface *inf, - struct grub_net_protocol *prot, struct grub_net_buff *nb); + struct grub_net_protstack *protstack, struct grub_net_buff *nb); grub_err_t (*get_payload_confirm) (struct grub_net_interface* inf, - struct grub_net_protocol *prot, struct grub_net_buff *nb); + struct grub_net_protstack *protstack, struct grub_net_buff *nb); grub_err_t (*close) (struct grub_net_interface *inf, - struct grub_net_protocol *prot, struct grub_net_buff *nb); + struct grub_net_protstack *protstack, struct grub_net_buff *nb); grub_err_t (*send) (struct grub_net_interface *inf , - struct grub_net_protocol *prot, struct grub_net_buff *nb); + struct grub_net_protstack *protstack, struct grub_net_buff *nb); grub_err_t (*recv) (struct grub_net_interface *inf , - struct grub_net_protocol *prot, struct grub_net_buff *nb); + struct grub_net_protstack *protstack, struct grub_net_buff *nb); }; typedef struct grub_net_protocol *grub_net_protocol_t; - -struct grub_net_interface -{ - struct grub_net_card *card; - struct grub_net_protocol* prot; - char *path; - char *username; - char *password; - /*transport layer addres*/ - struct grub_net_addr *tla; - /*internet layer addres*/ - struct grub_net_addr *ila; - /*link layer addres*/ - struct grub_net_addr *lla; -}; - void grub_protocol_register (grub_net_protocol_t prot); void grub_protocol_unregister (grub_net_protocol_t prot); #endif diff --git a/net/ethernet.c b/net/ethernet.c index fc64803e7..8c13966c1 100644 --- a/net/ethernet.c +++ b/net/ethernet.c @@ -6,9 +6,10 @@ #include #include #include +#include static grub_err_t -send_ethernet_packet (struct grub_net_interface *inf, struct grub_net_protocol *prot __attribute__ ((unused)) +send_ethernet_packet (struct grub_net_interface *inf,struct grub_net_protstack *protstack __attribute__ ((unused)) ,struct grub_net_buff *nb) { diff --git a/net/ip.c b/net/ip.c index c669ff6d7..6fe58adb0 100644 --- a/net/ip.c +++ b/net/ip.c @@ -5,6 +5,7 @@ #include #include #include +#include #include struct grub_net_protocol *grub_ipv4_prot; @@ -28,7 +29,7 @@ ipchksum(void *ipv, int len) static grub_err_t -send_ip_packet (struct grub_net_interface *inf, struct grub_net_protocol *prot, struct grub_net_buff *nb ) +send_ip_packet (struct grub_net_interface *inf, struct grub_net_protstack *protstack, struct grub_net_buff *nb ) { struct iphdr *iph; @@ -57,7 +58,7 @@ send_ip_packet (struct grub_net_interface *inf, struct grub_net_protocol *prot, iph->chksum = ipchksum((void *)nb->head, sizeof(*iph)); - return prot->next->send(inf,prot->next,nb); + return protstack->next->prot->send(inf,protstack->next,nb); } static struct grub_net_protocol grub_ipv4_protocol = diff --git a/net/tftp.c b/net/tftp.c index fdca184e9..3f481fe58 100644 --- a/net/tftp.c +++ b/net/tftp.c @@ -8,10 +8,11 @@ #include #include #include +#include /*send read request*/ static grub_err_t -send_tftp_rr (struct grub_net_interface *inf, struct grub_net_protocol *prot,struct grub_net_buff *nb) +send_tftp_rr (struct grub_net_interface *inf, struct grub_net_protstack *protstack,struct grub_net_buff *nb) { /*Start TFTP header*/ @@ -58,7 +59,7 @@ send_tftp_rr (struct grub_net_interface *inf, struct grub_net_protocol *prot,str grub_netbuff_unput (nb,nb->tail - (nb->data+hdrlen)); - return prot->next->send(inf,prot->next,nb); + return protstack->next->prot->send(inf,protstack->next,nb); } /* diff --git a/net/udp.c b/net/udp.c index 600eec542..2a4a7690b 100644 --- a/net/udp.c +++ b/net/udp.c @@ -3,9 +3,10 @@ #include #include #include +#include /*Assumes that there is allocated memory to the header before the buffer address. */ static grub_err_t -send_udp_packet (struct grub_net_interface *inf, struct grub_net_protocol *prot, struct grub_net_buff *nb) +send_udp_packet (struct grub_net_interface *inf, struct grub_net_protstack *protstack, struct grub_net_buff *nb) { struct udphdr *udph; @@ -21,7 +22,7 @@ send_udp_packet (struct grub_net_interface *inf, struct grub_net_protocol *prot, udph->chksum = 0; udph->len = sizeof (sizeof (*udph)) + nb->end - nb->head; - return prot->next->send(inf,prot->next,nb); + return protstack->next->prot->send(inf,protstack->next,nb); } static struct grub_net_protocol grub_udp_protocol = From d17a9fea4ac98b3aebea13f2b280c98afcd19c03 Mon Sep 17 00:00:00 2001 From: "Manoel R. Abranches" Date: Mon, 21 Jun 2010 19:05:14 -0300 Subject: [PATCH 017/869] Add interface struct for communication between protocols and protocols stack. Changed the protocols structs to use one struct for each layer. --- include/grub/net/arp.h | 8 +- include/grub/net/ieee1275/interface.h | 14 ++-- include/grub/net/interface.h | 77 ++++++++++++++---- include/grub/net/netbuff.h | 3 + include/grub/net/protocol.h | 110 ++++++++++++++++++++------ include/grub/net/tftp.h | 6 +- include/grub/net/type_net.h | 25 ++++++ include/grub/net/udp.h | 19 ++--- 8 files changed, 194 insertions(+), 68 deletions(-) diff --git a/include/grub/net/arp.h b/include/grub/net/arp.h index 0ac2ec832..86ae2deea 100644 --- a/include/grub/net/arp.h +++ b/include/grub/net/arp.h @@ -2,7 +2,7 @@ #define GRUB_NET_ARP_HEADER 1 #include -struct arprequest { +struct arphdr{ grub_int16_t hwtype; /* hardware type (must be ARPHRD_ETHER) */ grub_int16_t protocol; /* protocol type (must be ETH_P_IP) */ grub_int8_t hwlen; /* hardware address length (must be 6) */ @@ -14,10 +14,4 @@ struct arprequest { grub_uint32_t tipaddr; /* target's IP address */ }__attribute__ ((packed)); - -struct arp_pkt{ - struct etherhdr ether; - struct arprequest arpr; -} __attribute__ ((packed)); - #endif diff --git a/include/grub/net/ieee1275/interface.h b/include/grub/net/ieee1275/interface.h index edc242cab..16f624c05 100644 --- a/include/grub/net/ieee1275/interface.h +++ b/include/grub/net/ieee1275/interface.h @@ -4,17 +4,15 @@ #include #include #include +#include -grub_ofnet_t EXPORT_VAR(grub_net); -grub_bootp_t EXPORT_VAR(bootp_pckt); -grub_uint32_t get_server_ip(void); -grub_uint32_t get_client_ip(void); -grub_uint8_t* get_server_mac (void); -grub_uint8_t* get_client_mac (void); +grub_ofnet_t grub_net; -int send_card_buffer (void *buffer,int buff_len); -int get_card_buffer (void *buffer,int buff_len); +grub_bootp_t bootp_pckt; + +int send_card_buffer (struct grub_net_buff *pack); +int get_card_packet (struct grub_net_buff *pack); int card_open (void); int card_close (void); diff --git a/include/grub/net/interface.h b/include/grub/net/interface.h index 2e0ddfcc8..4d100fd75 100644 --- a/include/grub/net/interface.h +++ b/include/grub/net/interface.h @@ -1,27 +1,70 @@ #ifndef GRUB_INTERFACE_HEADER #define GRUB_INTERFACE_HEADER -#include -#include +//#include +#include +#include +#include -struct grub_net_protstack +struct grub_net_protocol_stack { - struct grub_net_protstack *next; - struct grub_net_protocol* prot; + struct grub_net_protocol_stack *next; + char *name; + grub_net_protocol_id_t id; + void *interface; }; -struct grub_net_interface +struct grub_net_application_transport_interface { - struct grub_net_card *card; - struct grub_net_protstack* protstack; - char *path; - char *username; - char *password; - /*transport layer addres*/ - struct grub_net_addr *tla; - /*internet layer addres*/ - struct grub_net_addr *ila; - /*link layer addres*/ - struct grub_net_addr *lla; + struct grub_net_transport_network_interface *inner_layer; + void *data; + struct grub_net_application_layer_protocol *app_prot; + struct grub_net_transport_layer_protocol *trans_prot; }; +struct grub_net_transport_network_interface +{ + struct grub_net_network_link_interface *inner_layer; + void *data; + struct grub_net_transport_layer_protocol *trans_prot; + struct grub_net_network_layer_protocol *net_prot; +}; + +struct grub_net_network_link_interface +{ + void *data; + struct grub_net_network_layer_protocol *net_prot; + struct grub_net_link_layer_protocol *link_prot; +}; + + +extern struct grub_net_protocol_stack *grub_net_protocol_stacks; +static inline void +grub_net_stack_register (struct grub_net_protocol_stack *stack) +{ + + grub_list_push (GRUB_AS_LIST_P (&grub_net_protocol_stacks), + GRUB_AS_LIST (stack)); +} +/* +void grub_net_stack_unregister (struct grub_net_protocol_stack *stack) +{ + grub_list_remove (GRUB_AS_LIST_P (&grub_net_protocol_stacks), + GRUB_AS_LIST (stack)); +}*/ + +struct grub_net_protocol_stack *grub_net_protocol_stack_get (char *name); + +/* +static inline void +grub_net_interface_application_transport_register (struct grub_net_application_transport_interface); +static inline void +grub_net_interface_application_transport_unregister (struct grub_net_application_transport_interface); +static inline void +grub_net_interface_transport_network_register (struct grub_net_transport_network_interface); +static inline void +grub_net_interface_transport_network_unregister (struct grub_net_transport_network_interface); +static inline void +grub_net_interface_network_link_register (struct grub_net_network_link_interface); +static inline void +grub_net_interface_network_link_unregister (struct grub_net_network_link_interface);*/ #endif diff --git a/include/grub/net/netbuff.h b/include/grub/net/netbuff.h index 7d63be1f5..8ce508ead 100644 --- a/include/grub/net/netbuff.h +++ b/include/grub/net/netbuff.h @@ -23,5 +23,8 @@ grub_err_t grub_netbuff_unput (struct grub_net_buff *net_buff ,grub_size_t len); grub_err_t grub_netbuff_push (struct grub_net_buff *net_buff ,grub_size_t len); grub_err_t grub_netbuff_pull (struct grub_net_buff *net_buff ,grub_size_t len); grub_err_t grub_netbuff_reserve (struct grub_net_buff *net_buff ,grub_size_t len); +grub_err_t grub_netbuff_clear (struct grub_net_buff *net_buff); struct grub_net_buff * grub_netbuff_alloc ( grub_size_t len ); +grub_err_t grub_netbuff_free (struct grub_net_buff *net_buff); +grub_err_t grub_netbuff_clear (struct grub_net_buff *net_buff); #endif diff --git a/include/grub/net/protocol.h b/include/grub/net/protocol.h index 1efc2ab7b..b7a3e5d3b 100644 --- a/include/grub/net/protocol.h +++ b/include/grub/net/protocol.h @@ -1,35 +1,101 @@ #ifndef GRUB_PROTOCOL_HEADER #define GRUB_PROTOCOL_HEADER #include -#include +#include #include -#include +#include struct grub_net_protocol; -struct grub_net_interface; -struct grub_net_protstack; +struct grub_net_protocol_stack; +struct grub_net_network_layer_interface; -struct grub_net_protocol + +typedef enum grub_network_layer_protocol_id { - struct grub_net_protocol *next; + GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4 +} grub_network_layer_protocol_id_t; + +struct grub_net_application_layer_protocol +{ + struct grub_net_application_layer_protocol *next; char *name; - grub_err_t (*open) (struct grub_net_interface* inf, - struct grub_net_protstack *protstack, struct grub_net_buff *nb); - grub_err_t (*open_confirm) (struct grub_net_interface *inf, - struct grub_net_protstack *protstack, struct grub_net_buff *nb); - grub_err_t (*get_payload) (struct grub_net_interface *inf, - struct grub_net_protstack *protstack, struct grub_net_buff *nb); - grub_err_t (*get_payload_confirm) (struct grub_net_interface* inf, - struct grub_net_protstack *protstack, struct grub_net_buff *nb); - grub_err_t (*close) (struct grub_net_interface *inf, - struct grub_net_protstack *protstack, struct grub_net_buff *nb); - grub_err_t (*send) (struct grub_net_interface *inf , - struct grub_net_protstack *protstack, struct grub_net_buff *nb); - grub_err_t (*recv) (struct grub_net_interface *inf , - struct grub_net_protstack *protstack, struct grub_net_buff *nb); + grub_net_protocol_id_t id; + int (*get_file_size) (struct grub_net_network_layer_interface* inf, + struct grub_net_protocol_stack *protocol_stack, struct grub_net_buff *nb,char *filename); + grub_err_t (*open) (struct grub_net_network_layer_interface* inf, + struct grub_net_protocol_stack *protocol_stack, struct grub_net_buff *nb,char *filename); + grub_err_t (*send_ack) (struct grub_net_network_layer_interface* inf, + struct grub_net_protocol_stack *protocol_stack, struct grub_net_buff *nb); + grub_err_t (*send) (struct grub_net_network_layer_interface *inf, + struct grub_net_protocol_stack *protocol_stack, struct grub_net_buff *nb); + grub_err_t (*recv) (struct grub_net_network_layer_interface *inf, + struct grub_net_protocol_stack *protocol_stack, struct grub_net_buff *nb); + grub_err_t (*close) (struct grub_net_network_layer_interface *inf, + struct grub_net_protocol_stack *protocol_stack, struct grub_net_buff *nb); }; +struct grub_net_transport_layer_protocol +{ + struct grub_net_transport_layer_protocol *next; + char *name; + grub_net_protocol_id_t id; + //grub_transport_layer_protocol_id_t id; + grub_err_t (*open) (struct grub_net_network_layer_interface* inf, + struct grub_net_application_transport_interface *app_trans_inf, struct grub_net_buff *nb); + grub_err_t (*send_ack) (struct grub_net_network_layer_interface* inf, + struct grub_net_protocol_stack *protocol_stack, struct grub_net_buff *nb); + grub_err_t (*send) (struct grub_net_network_layer_interface *inf, + struct grub_net_application_transport_interface *app_trans_inf, struct grub_net_buff *nb); + grub_err_t (*recv) (struct grub_net_network_layer_interface *inf, + struct grub_net_application_transport_interface *app_trans_inf, struct grub_net_buff *nb); + grub_err_t (*close) (struct grub_net_network_layer_interface *inf, + struct grub_net_protocol_stack *protocol_stack, struct grub_net_buff *nb); +}; + +struct grub_net_network_layer_protocol +{ + struct grub_net_network_layer_protocol *next; + char *name; + grub_net_protocol_id_t id; + //grub_network_layer_protocol_id_t id; + grub_err_t (*ntoa) (char *name, grub_net_network_layer_address_t *addr); + char * (*aton) (union grub_net_network_layer_address addr); + grub_err_t (*net_ntoa) (char *name, + grub_net_network_layer_netaddress_t *addr); + char * (*net_aton) (grub_net_network_layer_netaddress_t addr); + int (* match_net) (grub_net_network_layer_netaddress_t net, + grub_net_network_layer_address_t addr); + grub_err_t (*send) (struct grub_net_network_layer_interface *inf , + struct grub_net_transport_network_interface *trans_net_inf, struct grub_net_buff *nb); + grub_err_t (*recv) (struct grub_net_network_layer_interface *inf , + struct grub_net_transport_network_interface *trans_net_inf, struct grub_net_buff *nb); +}; + +struct grub_net_link_layer_protocol +{ + + struct grub_net_link_layer_protocol *next; + char *name; + grub_net_protocol_id_t id; + grub_err_t (*send) (struct grub_net_network_layer_interface *inf , + struct grub_net_network_link_interface *net_link_inf, struct grub_net_buff *nb); + grub_err_t (*recv) (struct grub_net_network_layer_interface *inf , + struct grub_net_network_link_interface *net_link_inf, struct grub_net_buff *nb); +}; + +extern struct grub_net_network_layer_protocol *grub_net_network_layer_protocols; + typedef struct grub_net_protocol *grub_net_protocol_t; -void grub_protocol_register (grub_net_protocol_t prot); -void grub_protocol_unregister (grub_net_protocol_t prot); +void grub_net_application_layer_protocol_register (struct grub_net_application_layer_protocol *prot); +void grub_net_application_layer_protocol_unregister (struct grub_net_application_layer_protocol *prot); +struct grub_net_application_layer_protocol *grub_net_application_layer_protocol_get (grub_net_protocol_id_t id); +void grub_net_transport_layer_protocol_register (struct grub_net_transport_layer_protocol *prot); +void grub_net_transport_layer_protocol_unregister (struct grub_net_transport_layer_protocol *prot); +struct grub_net_transport_layer_protocol *grub_net_transport_layer_protocol_get (grub_net_protocol_id_t id); +void grub_net_network_layer_protocol_register (struct grub_net_network_layer_protocol *prot); +void grub_net_network_layer_protocol_unregister (struct grub_net_network_layer_protocol *prot); +struct grub_net_network_layer_protocol *grub_net_network_layer_protocol_get (grub_net_protocol_id_t id); +void grub_net_link_layer_protocol_register (struct grub_net_link_layer_protocol *prot); +void grub_net_link_layer_protocol_unregister (struct grub_net_link_layer_protocol *prot); +struct grub_net_link_layer_protocol *grub_net_link_layer_protocol_get (grub_net_protocol_id_t id); #endif diff --git a/include/grub/net/tftp.h b/include/grub/net/tftp.h index 4148096c5..1f1c48616 100644 --- a/include/grub/net/tftp.h +++ b/include/grub/net/tftp.h @@ -14,7 +14,7 @@ /* IP port for the TFTP server */ #define TFTP_SERVER_PORT 69 -#define TFTP_CLIENT_PORT 2000 +#define TFTP_CLIENT_PORT 26300 /* We define these based on what's in arpa/tftp.h. We just like our @@ -42,10 +42,6 @@ #define TFTP_ENOUSER 7 /* no such user */ #define TFTP_DEFAULT_FILENAME "kernel" - - - - /* * own here because this is cleaner, and maps to the same data layout. * */ struct tftphdr { diff --git a/include/grub/net/type_net.h b/include/grub/net/type_net.h index 33f2d802d..276c50bf9 100644 --- a/include/grub/net/type_net.h +++ b/include/grub/net/type_net.h @@ -1,7 +1,32 @@ #ifndef GRUB_TYPES_NET_HEADER #define GRUB_TYPES_NET_HEADER 1 +#include + #define UDP_PCKT 0x11 #define IP_PCKT 0x0800 +typedef enum +{ + GRUB_NET_TFTP_ID, + GRUB_NET_UDP_ID, + GRUB_NET_IPV4_ID, + GRUB_NET_IPV6_ID, + GRUB_NET_ETHERNET_ID, + GRUB_NET_ARP_ID, + GRUB_NET_DHCP_ID +}grub_net_protocol_id_t; + +typedef union grub_net_network_layer_address +{ + grub_uint32_t ipv4; +} grub_net_network_layer_netaddress_t; + +typedef union grub_net_network_layer_netaddress +{ + struct { + grub_uint32_t base; + int masksize; + } ipv4; +} grub_net_network_layer_address_t; #endif diff --git a/include/grub/net/udp.h b/include/grub/net/udp.h index dbfcecef0..dfc1776a4 100644 --- a/include/grub/net/udp.h +++ b/include/grub/net/udp.h @@ -1,22 +1,23 @@ #ifndef GRUB_NET_UDP_HEADER #define GRUB_NET_UDP_HEADER 1 #include -/* -typedef enum - { - GRUB_PROT_TFTP - } protocol_type; -*/ -#define GRUB_PROT_TFTP 1 - -struct udphdr { +struct udphdr +{ grub_uint16_t src; grub_uint16_t dst; grub_uint16_t len; grub_uint16_t chksum; } __attribute__ ((packed)); +struct udp_interf +{ + grub_uint16_t src; + grub_uint16_t dst; +}; + + + void udp_ini(void); void udp_fini(void); #endif From c3639ae731b7043f641090b38995a73aceda70c9 Mon Sep 17 00:00:00 2001 From: "Manoel R. Abranches" Date: Mon, 21 Jun 2010 19:13:26 -0300 Subject: [PATCH 018/869] File manipulation. Based in OF implementation. For debug porpouse and will be changed later. --- fs/ieee1275/ofnet.c | 355 ++++++++++++++++++++++++++++++++++ include/grub/ieee1275/ofnet.h | 95 +++++++++ 2 files changed, 450 insertions(+) create mode 100644 fs/ieee1275/ofnet.c create mode 100644 include/grub/ieee1275/ofnet.h diff --git a/fs/ieee1275/ofnet.c b/fs/ieee1275/ofnet.c new file mode 100644 index 000000000..196aadcf2 --- /dev/null +++ b/fs/ieee1275/ofnet.c @@ -0,0 +1,355 @@ +/* ofnet.c - Driver to provide access to the ofnet filesystem */ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2008 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 . + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define BUFFERADDR 0X00000000 +#define BUFFERSIZE 0x02000000 +#define U64MAXSIZE 18446744073709551615ULL + + +//static grub_ieee1275_ihandle_t handle = 0; + + +static int +grub_ofnet_iterate (int (*hook) (const char *name)) +{ + if (hook ("net")) + return 1; + return 0; +} + +static grub_err_t +grub_ofnet_open (const char *name, grub_disk_t disk) +{ + + + if (grub_strcmp (name, "network")) + return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "not a net disk"); + + disk->total_sectors = U64MAXSIZE; + disk->id = (unsigned long) "net"; + + disk->has_partitions = 0; + disk->data = 0; + + return GRUB_ERR_NONE; +} + +static void +grub_ofnet_close (grub_disk_t disk __attribute((unused))) +{ +} + +static grub_err_t +grub_ofnet_read (grub_disk_t disk __attribute((unused)), + grub_disk_addr_t sector __attribute((unused)), + grub_size_t size __attribute((unused)), + char *buf __attribute((unused))) +{ + return GRUB_ERR_NONE; +} + +static grub_err_t +grub_ofnet_write (grub_disk_t disk __attribute((unused)), + grub_disk_addr_t sector __attribute((unused)), + grub_size_t size __attribute((unused)), + const char *buf __attribute((unused))) +{ + return GRUB_ERR_NONE; +} + +static struct grub_disk_dev grub_ofnet_dev = + { + .name = "net", + .id = GRUB_DISK_DEVICE_OFNET_ID, + .iterate = grub_ofnet_iterate, + .open = grub_ofnet_open, + .close = grub_ofnet_close, + .read = grub_ofnet_read, + .write = grub_ofnet_write, + .next = 0 + }; + +static grub_err_t +grub_ofnetfs_dir (grub_device_t device , + const char *path __attribute((unused)), + int (*hook) (const char *filename, + const struct grub_dirhook_info *info) __attribute((unused))) +{ + if(grub_strcmp (device->disk->name,"network")) + { + return grub_error (GRUB_ERR_BAD_FS, "not an net filesystem"); + } + return GRUB_ERR_NONE; +} + +static grub_ssize_t +grub_ofnetfs_read (grub_file_t file, char *buf, grub_size_t len) +{ + grub_size_t actual; + actual = len <= (file->size - file->offset)?len:file->size - file->offset; + grub_memcpy(buf, (void *)( (grub_addr_t) file->data + (grub_addr_t)file->offset), actual); + return actual; +} + +static grub_err_t +grub_ofnetfs_close (grub_file_t file) +{ + grub_ieee1275_release ((grub_addr_t) file->data,file->size); + + return GRUB_ERR_NONE; +} + +static grub_err_t +grub_ofnetfs_open (struct grub_file *file , const char *name ) +{ + //void *buffer; + //grub_addr_t addr; + if (name[0] == '/') + name++; + if(grub_strcmp (file->device->disk->name,"network")) + { + + return 1; + } + grub_printf("name = %s\n",name); + + struct grub_net_protocol_stack *stack; + struct grub_net_buff *pack; + struct grub_net_application_transport_interface *app_interface; + int file_size; + char *datap; + int amount = 0; + grub_addr_t found_addr; + + stack = grub_net_protocol_stack_get ("tftp"); + app_interface = (struct grub_net_application_transport_interface *) stack->interface; + pack = grub_netbuff_alloc (80*1024); + grub_netbuff_reserve (pack,80*1024); + file_size = app_interface->app_prot->get_file_size(NULL,stack,pack,(char *) name); + + + for (found_addr = 0x800000; found_addr < + 2000 * 0x100000; found_addr += 0x100000) + { + grub_printf("traing to claim %d bytes at 0x%x\n",file_size,found_addr); + if (grub_claimmap (found_addr , file_size) != -1) + break; + } + grub_printf("Claimed %d bytes at 0x%x\n",file_size,found_addr); + file->data = (void *) found_addr; + grub_printf("file->data = 0x%x\n",(int)file->data); + grub_printf("file_size = %d\n",file_size); + grub_printf("OPEN\n"); + grub_netbuff_clear(pack); + grub_netbuff_reserve (pack,80*1024); + app_interface->app_prot->open (NULL,stack,pack,(char *) name); + + do { + //if (app_interface->app_prot->recv (NULL,stack,pack) == GRUB_ERR_NONE) + grub_printf("RECEIVE PACKET\n"); + grub_netbuff_clear(pack); + grub_netbuff_reserve (pack,80*1024); + app_interface->app_prot->recv (NULL,stack,pack); + if (grub_errno != GRUB_ERR_NONE) + return grub_errno; + grub_printf("RECEIVED PACKET\n"); + // { + grub_printf("payload_size= %d\n",pack->tail - pack->data); + grub_printf("amount= %d\n",amount); + grub_printf("file_size= %d\n",file_size); + datap = (char *)file->data + amount; + amount += (pack->tail - pack->data); + grub_printf("datap = 0x%x\n",(int)datap ); + // amount += pack->tail - pack->data; + grub_memcpy(datap, pack->data, pack->tail - pack->data); + grub_printf("SEND ACK\n"); + + grub_netbuff_clear(pack); + grub_netbuff_reserve (pack,80*1024); + app_interface->app_prot->send_ack (NULL,stack,pack); + + if (grub_errno != GRUB_ERR_NONE) + return grub_errno; + + grub_printf("SENT ACK\n"); + //} + // file->data = grub_realloc(file->data,amount); + + }while (amount < file_size); + grub_printf("transfer complete\n"); + file->size = file_size; + +// grub_netbuff_free(pack); + /*Start ARP header*/ + // arp.arpr.hwtype = 0x1; /* hardware type (must be ARPHRD_ETHER) */ + // arp.arpr.protocol = 0x0800; /* protocol type (must be ETH_P_IP) */ + // arp.arpr.hwlen = 0x6; /* hardware address length (must be 6) */ + // arp.arpr.protolen = 0x4; /* protocol address length (must be 4) */ + // arp.arpr.opcode = 0x1; /* ARP opcode */ + + + /*arp.arpr.shwaddr[0] =0x0a ; + arp.arpr.shwaddr[1] =0x11 ; + arp.arpr.shwaddr[2] =0xbd ; + arp.arpr.shwaddr[3] =0xe3 ; + arp.arpr.shwaddr[4] =0xe3 ; + arp.arpr.shwaddr[5] =0x04 ; + arp.arpr.sipaddr = dhcp_pckt -> yiaddr; */ /* sender's IP address */ + /*arp.arpr.thwaddr[0] =0; + arp.arpr.thwaddr[1] =0; + arp.arpr.thwaddr[2] =0; + arp.arpr.thwaddr[3] =0; + arp.arpr.thwaddr[4] =0; + arp.arpr.thwaddr[5] =0; + arp.arpr.tipaddr = dhcp_pckt -> siaddr; */ /* target's IP address */ + /*END ARP header */ + return grub_errno; +} + + +static grub_err_t +grub_ofnetfs_label (grub_device_t device __attribute ((unused)), + char **label __attribute ((unused))) +{ + *label = 0; + return GRUB_ERR_NONE; +} + +static struct grub_fs grub_ofnetfs_fs = + { + .name = "ofnetfs", + .dir = grub_ofnetfs_dir, + .open = grub_ofnetfs_open, + .read = grub_ofnetfs_read, + .close = grub_ofnetfs_close, + .label = grub_ofnetfs_label, + .next = 0 + }; + +static char * +grub_ieee1275_get_devargs (const char *path) +{ + int len; + char *colon = grub_strchr (path, ':'); + len = colon - path; + if (! colon) + return 0; + + return grub_strndup (path,len); +} + +static int +grub_ofnet_detect (void) +{ + + char *devalias; + char bootpath[64]; /* XXX check length */ + grub_ieee1275_phandle_t root; + grub_uint32_t net_type; + + grub_ieee1275_finddevice ("/chosen", &grub_ieee1275_chosen); + if (grub_ieee1275_get_property (grub_ieee1275_chosen, "bootpath", &bootpath, + sizeof (bootpath), 0)) + { + /* Should never happen. */ + grub_printf ("/chosen/bootpath property missing!\n"); + return 0; + } + devalias = grub_ieee1275_get_aliasdevname (bootpath); + + if (grub_strcmp(devalias ,"network")) + return 0; + + grub_net = grub_malloc (sizeof *grub_net ); + grub_net->name = "net"; + grub_net->dev = grub_ieee1275_get_devargs (bootpath); + grub_ieee1275_finddevice ("/", &root); + grub_ieee1275_get_integer_property (root, "ibm,fw-net-compatibility", + &net_type, sizeof net_type, 0); + grub_printf("root = %d\n",root); + grub_printf("net_type= %d\n",net_type); + grub_net->type = net_type; + + return 1; +} + + +#define IPMASK 0x000000FF +#define IPSIZE 16 +#define IPTEMPLATE "%d.%d.%d.%d" +char * +grub_ip2str (grub_uint32_t ip) +{ + char* str_ip; +// str_ip = grub_malloc(IPSIZE); + str_ip = grub_xasprintf (IPTEMPLATE, ip >> 24 & IPMASK, ip >> 16 & IPMASK, ip >> 8 & IPMASK, ip & IPMASK); + grub_printf ("str_ip = %s\n",str_ip); + grub_printf ("template = "IPTEMPLATE"\n" , ip >> 24 & IPMASK, ip >> 16 & IPMASK, ip >> 8 & IPMASK, ip & IPMASK); + return str_ip; +} + +void +grub_get_netinfo (grub_ofnet_t netinfo,grub_bootp_t packet) +{ + netinfo->sip = grub_ip2str(packet->siaddr); + netinfo->cip = grub_ip2str(packet->yiaddr); + netinfo->gat = grub_ip2str(packet->giaddr); + grub_printf("packet->siaddr = %x\n",packet->siaddr); + grub_printf("netinfo-> = %s\n",netinfo->sip); + grub_printf("packet->yiaddr = %x\n",packet->yiaddr); + grub_printf("netinfo-> = %s\n",netinfo->cip); + grub_printf("packet->giaddr = %x\n",packet->giaddr); + grub_printf("netinfo-> = %s\n",netinfo->gat); +} +void +grub_ofnet_init(void) +{ + tftp_ini (); + bootp_pckt = grub_getbootp (); + if(grub_ofnet_detect ()) + { + grub_get_netinfo (grub_net, bootp_pckt ); + grub_disk_dev_register (&grub_ofnet_dev); + grub_fs_register (&grub_ofnetfs_fs); + } + card_open (); +} +void +grub_ofnet_fini(void) +{ + grub_fs_unregister (&grub_ofnetfs_fs); + grub_disk_dev_unregister (&grub_ofnet_dev); +} diff --git a/include/grub/ieee1275/ofnet.h b/include/grub/ieee1275/ofnet.h new file mode 100644 index 000000000..7daadf61d --- /dev/null +++ b/include/grub/ieee1275/ofnet.h @@ -0,0 +1,95 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2002,2007 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 . + */ + +#ifndef GRUB_OFNET_HEADER +#define GRUB_OFNET_HEADER 1 + +#include +#include +#include + +extern void grub_ofnet_init(void); +extern void grub_ofnet_fini(void); +/* +struct grub_net; + +struct grub_net_dev +{ + / The device name. / + const char *name; + + / FIXME: Just a template. / + int (*probe) (struct grub_net *net, const void *addr); + void (*reset) (struct grub_net *net); + int (*poll) (struct grub_net *net); + void (*transmit) (struct grub_net *net, const void *destip, + unsigned srcsock, unsigned destsock, const void *packet); + void (*disable) (struct grub_net *net); + + / The next net device. / + struct grub_net_dev *next; +}; +typedef struct grub_net_dev *grub_net_dev_t; + +struct grub_fs; +*/ +struct grub_ofnet +{ + /* The net name. */ + const char *name; + + /* The OF device string. */ + char *dev; + /*server ip*/ + char *sip; + /*client ip*/ + char *cip; + /*gateway*/ + char *gat; + /**/ + int type; +}; + +typedef struct grub_ofnet *grub_ofnet_t; + +struct grub_bootp { + grub_uint8_t op; /* 1 = BOOTREQUEST, 2 = BOOTREPLY */ + grub_uint8_t htype; /* Hardware address type. */ + grub_uint8_t hlen; /* Hardware address length */ + grub_uint8_t hops; /* Used by gateways in cross-gateway booting. */ + grub_uint32_t xid; /* Transaction ID */ + grub_uint16_t secs; /* Seconds elapsed. */ + grub_uint16_t unused; /* Unused. */ + grub_uint32_t ciaddr; /* Client IP address, */ + grub_uint32_t yiaddr; /* Client IP address filled by server. */ + grub_uint32_t siaddr; /* Server IP address. */ + grub_uint32_t giaddr; /* Gateway IP address. */ + unsigned char chaddr [16]; /* Client hardware address */ + char sname [64]; /* Server name */ + char file [128]; /* Boot filename */ +// grub_uint32_t filesize ; /*File size (testing)*/ + unsigned char vend [64]; +}; + +typedef struct grub_bootp* grub_bootp_t; + +char * grub_get_filestr(const char * ); +char * grub_ip2str (grub_uint32_t ip); +void grub_get_netinfo (grub_ofnet_t netinfo,grub_bootp_t packet); +grub_bootp_t grub_getbootp (void); +#endif /* ! GRUB_NET_HEADER */ From 60cdb895da65aaa09dcb256d03063c3a711a61e2 Mon Sep 17 00:00:00 2001 From: "Manoel R. Abranches" Date: Mon, 21 Jun 2010 19:15:45 -0300 Subject: [PATCH 019/869] Adaptation for the new protocols and interface structs. implementation of receive in the protocols. Also all unwanted packets are discarded. --- commands/net.c | 38 ++++---- include/grub/net.h | 118 ++++++------------------ net/ethernet.c | 88 ++++++++++++------ net/interface.c | 38 ++++++++ net/ip.c | 66 ++++++++++---- net/netbuff.c | 41 +++++++-- net/protocol.c | 50 ++++++---- net/tftp.c | 223 ++++++++++++++++++++++++++++++++++++++------- net/udp.c | 69 +++++++++++--- 9 files changed, 505 insertions(+), 226 deletions(-) diff --git a/commands/net.c b/commands/net.c index 288ba4c2a..b8ceb36f4 100644 --- a/commands/net.c +++ b/commands/net.c @@ -23,14 +23,14 @@ #include struct grub_net_route *grub_net_routes = NULL; -struct grub_net_network_level_interface *grub_net_network_level_interfaces = NULL; +struct grub_net_network_layer_interface *grub_net_network_layer_interfaces = NULL; struct grub_net_card *grub_net_cards = NULL; -struct grub_net_network_level_protocol *grub_net_network_level_protocols = NULL; +struct grub_net_network_layer_protocol *grub_net_network_layer_protocols = NULL; grub_err_t -grub_net_resolve_address (struct grub_net_network_level_protocol **prot, +grub_net_resolve_address (struct grub_net_network_layer_protocol **prot, char *name, - grub_net_network_level_address_t *addr) + grub_net_network_layer_address_t *addr) { FOR_NET_NETWORK_LEVEL_PROTOCOLS (*prot) { @@ -50,15 +50,15 @@ grub_net_resolve_address (struct grub_net_network_level_protocol **prot, } grub_err_t -grub_net_route_address (grub_net_network_level_address_t addr, - grub_net_network_level_address_t *gateway, - struct grub_net_network_level_interface **interf) +grub_net_route_address (grub_net_network_layer_address_t addr, + grub_net_network_layer_address_t *gateway, + struct grub_net_network_layer_interface **interf) { struct grub_net_route *route; int depth = 0; int routecnt = 0; - struct grub_net_network_level_protocol *prot = NULL; - grub_net_network_level_address_t curtarget = addr; + struct grub_net_network_layer_protocol *prot = NULL; + grub_net_network_layer_address_t curtarget = addr; *gateway = addr; @@ -96,7 +96,7 @@ static grub_err_t grub_cmd_deladdr (struct grub_command *cmd __attribute__ ((unused)), int argc, char **args) { - struct grub_net_network_level_interface *inter; + struct grub_net_network_layer_interface *inter; if (argc != 4) return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("one argument expected")); @@ -107,8 +107,8 @@ grub_cmd_deladdr (struct grub_command *cmd __attribute__ ((unused)), if (inter == NULL) return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("address not found")); - inter->protocol->fini (inter); - grub_net_network_level_interface_unregister (inter); +// inter->protocol->fini (inter); + grub_net_network_layer_interface_unregister (inter); grub_free (inter->name); grub_free (inter); @@ -120,10 +120,10 @@ grub_cmd_addaddr (struct grub_command *cmd __attribute__ ((unused)), int argc, char **args) { struct grub_net_card *card; - struct grub_net_network_level_protocol *prot; + struct grub_net_network_layer_protocol *prot; grub_err_t err; - grub_net_network_level_address_t addr; - struct grub_net_network_level_interface *inter; + grub_net_network_layer_address_t addr; + struct grub_net_network_layer_interface *inter; if (argc != 4) return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("four arguments expected")); @@ -154,14 +154,14 @@ grub_cmd_addaddr (struct grub_command *cmd __attribute__ ((unused)), grub_memcpy (&(inter->address), &addr, sizeof (inter->address)); inter->card = card; - err = prot->init (inter); + // err = prot->init (inter); if (err) { grub_free (inter->name); grub_free (inter); return err; } - grub_net_network_level_interface_register (inter); + grub_net_network_layer_interface_register (inter); return GRUB_ERR_NONE; } @@ -192,7 +192,7 @@ static grub_err_t grub_cmd_addroute (struct grub_command *cmd __attribute__ ((unused)), int argc, char **args) { - struct grub_net_network_level_protocol *prot; + struct grub_net_network_layer_protocol *prot; struct grub_net_route *route; if (argc < 3) @@ -247,7 +247,7 @@ grub_cmd_addroute (struct grub_command *cmd __attribute__ ((unused)), } else { - struct grub_net_network_level_interface *inter; + struct grub_net_network_layer_interface *inter; route->is_gateway = 0; FOR_NET_NETWORK_LEVEL_INTERFACES (inter) diff --git a/include/grub/net.h b/include/grub/net.h index f021f0e9c..abb8a3167 100644 --- a/include/grub/net.h +++ b/include/grub/net.h @@ -23,20 +23,11 @@ #include #include #include +#include +#include struct grub_net_card; -typedef enum -{ - GRUB_NET_TFTP_ID, - GRUB_NET_UDP_ID, - GRUB_NET_IPV4_ID, - GRUB_NET_IPV6_ID, - GRUB_NET_ETHERNET_ID, - GRUB_NET_ARP_ID, - GRUB_NET_DHCP_ID - -}protocol_type_t; struct grub_net_card_driver { @@ -66,76 +57,36 @@ struct grub_net_card void *data; }; -struct grub_net_network_level_interface; +//struct grub_net_network_layer_interface; -typedef union grub_net_network_level_address +struct grub_net_network_layer_interface { - grub_uint32_t ipv4; -} grub_net_network_level_netaddress_t; - -typedef union grub_net_network_level_netaddress -{ - struct { - grub_uint32_t base; - int masksize; - } ipv4; -} grub_net_network_level_address_t; - -typedef enum grub_network_level_protocol_id -{ - GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4 -} grub_network_level_protocol_id_t; - -struct grub_net_network_level_interface; - -struct grub_net_network_level_protocol -{ - struct grub_net_network_level_protocol *next; - char *name; - grub_network_level_protocol_id_t id; - grub_err_t (*ntoa) (char *name, grub_net_network_level_address_t *addr); - char * (*aton) (union grub_net_network_level_address addr); - grub_err_t (*net_ntoa) (char *name, - grub_net_network_level_netaddress_t *addr); - char * (*net_aton) (grub_net_network_level_netaddress_t addr); - int (* match_net) (grub_net_network_level_netaddress_t net, - grub_net_network_level_address_t addr); - grub_err_t (*init) (struct grub_net_network_level_interface *dev); - grub_err_t (*fini) (struct grub_net_network_level_interface *dev); - grub_err_t (*send) (struct grub_net_network_level_interface *dev, void *buf, - grub_size_t buflen); - grub_size_t (*recv) (struct grub_net_network_level_interface *dev, void *buf, - grub_size_t buflen); -}; - -struct grub_net_network_level_interface -{ - struct grub_net_network_level_interface *next; + struct grub_net_network_layer_interface *next; char *name; /* Underlying protocol. */ - struct grub_net_network_level_protocol *protocol; + struct grub_net_network_layer_protocol *protocol; struct grub_net_card *card; - union grub_net_network_level_address address; + union grub_net_network_layer_address address; void *data; }; struct grub_net_route { struct grub_net_route *next; - grub_net_network_level_netaddress_t target; + grub_net_network_layer_netaddress_t target; char *name; - struct grub_net_network_level_protocol *prot; + struct grub_net_network_layer_protocol *prot; int is_gateway; union { - struct grub_net_network_level_interface *interface; - grub_net_network_level_address_t gw; + struct grub_net_network_layer_interface *interface; + grub_net_network_layer_address_t gw; }; }; struct grub_net_session; -struct grub_net_session_level_protocol +struct grub_net_session_layer_protocol { void (*close) (struct grub_net_session *session); grub_ssize_t (*recv) (struct grub_net_session *session, void *buf, @@ -146,7 +97,7 @@ struct grub_net_session_level_protocol struct grub_net_session { - struct grub_net_session_level_protocol *protocol; + struct grub_net_session_layer_protocol *protocol; void *data; }; @@ -170,23 +121,23 @@ grub_net_session_recv (struct grub_net_session *session, void *buf, return session->protocol->recv (session, buf, size); } -extern struct grub_net_network_level_interface *grub_net_network_level_interfaces; +struct grub_net_network_layer_interface *grub_net_network_layer_interfaces; static inline void -grub_net_network_level_interface_register (struct grub_net_network_level_interface *inter) +grub_net_network_layer_interface_register (struct grub_net_network_layer_interface *inter) { - grub_list_push (GRUB_AS_LIST_P (&grub_net_network_level_interfaces), + grub_list_push (GRUB_AS_LIST_P (&grub_net_network_layer_interfaces), GRUB_AS_LIST (inter)); } static inline void -grub_net_network_level_interface_unregister (struct grub_net_network_level_interface *inter) +grub_net_network_layer_interface_unregister (struct grub_net_network_layer_interface *inter) { - grub_list_remove (GRUB_AS_LIST_P (&grub_net_network_level_interfaces), + grub_list_remove (GRUB_AS_LIST_P (&grub_net_network_layer_interfaces), GRUB_AS_LIST (inter)); } -#define FOR_NET_NETWORK_LEVEL_INTERFACES(var) for (var = grub_net_network_level_interfaces; var; var = var->next) +#define FOR_NET_NETWORK_LEVEL_INTERFACES(var) for (var = grub_net_network_layer_interfaces; var; var = var->next) extern struct grub_net_route *grub_net_routes; @@ -224,28 +175,13 @@ grub_net_card_unregister (struct grub_net_card *card) #define FOR_NET_CARDS(var) for (var = grub_net_cards; var; var = var->next) -extern struct grub_net_network_level_protocol *grub_net_network_level_protocols; -static inline void -grub_net_network_level_protocol_register (struct grub_net_network_level_protocol *prot) -{ - grub_list_push (GRUB_AS_LIST_P (&grub_net_network_level_protocols), - GRUB_AS_LIST (prot)); -} - -static inline void -grub_net_network_level_protocol_unregister (struct grub_net_network_level_protocol *prot) -{ - grub_list_remove (GRUB_AS_LIST_P (&grub_net_network_level_protocols), - GRUB_AS_LIST (prot)); -} - -#define FOR_NET_NETWORK_LEVEL_PROTOCOLS(var) for ((var) = grub_net_network_level_protocols; (var); (var) = (var)->next) +#define FOR_NET_NETWORK_LEVEL_PROTOCOLS(var) for ((var) = grub_net_network_layer_protocols; (var); (var) = (var)->next) static inline grub_err_t -grub_net_resolve_address_in_protocol (struct grub_net_network_level_protocol *prot, +grub_net_resolve_address_in_protocol (struct grub_net_network_layer_protocol *prot, char *name, - grub_net_network_level_address_t *addr) + grub_net_network_layer_address_t *addr) { return prot->ntoa (name, addr); } @@ -254,14 +190,14 @@ struct grub_net_session * grub_net_open_tcp (char *address, grub_uint16_t port); grub_err_t -grub_net_resolve_address (struct grub_net_network_level_protocol **prot, +grub_net_resolve_address (struct grub_net_network_layer_protocol **prot, char *name, - grub_net_network_level_address_t *addr); + grub_net_network_layer_address_t *addr); grub_err_t -grub_net_route_address (grub_net_network_level_address_t addr, - grub_net_network_level_address_t *gateway, - struct grub_net_network_level_interface **interf); +grub_net_route_address (grub_net_network_layer_address_t addr, + grub_net_network_layer_address_t *gateway, + struct grub_net_network_layer_interface **interf); #endif /* ! GRUB_NET_HEADER */ diff --git a/net/ethernet.c b/net/ethernet.c index 8c13966c1..a4bdbff5b 100644 --- a/net/ethernet.c +++ b/net/ethernet.c @@ -5,51 +5,85 @@ #include #include #include -#include #include +#include static grub_err_t -send_ethernet_packet (struct grub_net_interface *inf,struct grub_net_protstack *protstack __attribute__ ((unused)) - ,struct grub_net_buff *nb) +send_ethernet_packet (struct grub_net_network_layer_interface *inf __attribute__ ((unused)), + struct grub_net_network_link_interface *net_link_inf __attribute__ ((unused)) ,struct grub_net_buff *nb) { - struct etherhdr *eth; - grub_err_t err; - - if((err = grub_netbuff_push (nb,sizeof(*eth)) ) != GRUB_ERR_NONE) - return err; + struct etherhdr *eth; + + grub_netbuff_push (nb,sizeof(*eth)); eth = (struct etherhdr *) nb->data; - grub_memcpy (eth->src,inf->card->lla->addr,6 * sizeof (grub_uint8_t )); - grub_memcpy (eth->dst,inf->lla->addr,6 * sizeof (grub_uint8_t )); + eth->dst[0] =0x00; + eth->dst[1] =0x11; + eth->dst[2] =0x25; + eth->dst[3] =0xca; + eth->dst[4] =0x1f; + eth->dst[5] =0x01; + eth->src[0] =0x0a; + eth->src[1] =0x11; + eth->src[2] =0xbd; + eth->src[3] =0xe3; + eth->src[4] =0xe3; + eth->src[5] =0x04; + eth->type = 0x0800; - - return inf->card->driver->send(inf->card,nb); + + return send_card_buffer(nb); +// return inf->card->driver->send(inf->card,nb); } -static struct grub_net_protocol grub_ethernet_protocol = + +static grub_err_t +recv_ethernet_packet (struct grub_net_network_layer_interface *inf __attribute__ ((unused)), + struct grub_net_network_link_interface *net_link_inf __attribute__ ((unused)) ,struct grub_net_buff *nb) { - .name = "udp", - .send = send_ethernet_packet + struct etherhdr *eth; + while (1) + { + get_card_packet (nb); + eth = (struct etherhdr *) nb->data; + /*change for grub_memcmp*/ + if( eth->src[0] == 0x00 && eth->src[1] == 0x11 && eth->src[2] == 0x25 && + eth->src[3] == 0xca && eth->src[4] == 0x1f && eth->src[5] == 0x01 && eth->type == 0x800) + { + //grub_printf("ethernet eth->dst %x:%x:%x:%x:%x:%x\n",eth->dst[0], + // eth->dst[1],eth->dst[2],eth->dst[3],eth->dst[4],eth->dst[5]); + // grub_printf("ethernet eth->src %x:%x:%x:%x:%x:%x\n",eth->src[0],eth->src[1], + // eth->src[2],eth->src[3],eth->src[4],eth->src[5]); + //grub_printf("ethernet eth->type 0x%x\n",eth->type); + //grub_printf("out from ethernet\n"); + grub_netbuff_pull(nb,sizeof(*eth)); + return 0; + } + } +/* - get ethernet header + - verify if the next layer is the desired one. + - if not. get another packet. + - remove ethernet header from buffer*/ + return 0; +} + + +static struct grub_net_link_layer_protocol grub_ethernet_protocol = +{ + .name = "ethernet", + .id = GRUB_NET_ETHERNET_ID, + .send = send_ethernet_packet, + .recv = recv_ethernet_packet }; void ethernet_ini(void) { - grub_protocol_register (&grub_ethernet_protocol); + grub_net_link_layer_protocol_register (&grub_ethernet_protocol); } void ethernet_fini(void) { - grub_protocol_unregister (&grub_ethernet_protocol); + grub_net_link_layer_protocol_unregister (&grub_ethernet_protocol); } -/* -int read_ethernet_packet(buffer,bufflen, int type) -{ - - struct etherhdr eth; - eth.type = 0; - - get_card_buffer (ð,sizeof (eth)); - -}*/ diff --git a/net/interface.c b/net/interface.c index e69de29bb..bacabf4cb 100644 --- a/net/interface.c +++ b/net/interface.c @@ -0,0 +1,38 @@ +/*#include + +#define INTERFACE_REGISTER_FUNCTIONS(layerprevious,layernext) \ +struct grub_net_##layername_layer_protocol *grub_net_##layername_layer_protocols;\ +\ +void grub_net_##layerprevious_##layernext_interface_register (struct grub_net_##layername_layer_protocol *prot)\ +{\ + grub_list_push (GRUB_AS_LIST_P (&grub_net_##layername_layer_protocols),\ + GRUB_AS_LIST (prot));\ +}\ +\ +void grub_net_##layerprevious_##layernext_interface_unregister (struct grub_net_##layername_layer_protocol *prot);\ +{\ + grub_list_remove (GRUB_AS_LIST_P (&grub_net_##layername_layer_protocols),\ + GRUB_AS_LIST (prot));\ +}\ + +INTERFACE_REGISTER_FUNCTIONS("application","transport"); +INTERFACE_REGISTER_FUNCTIONS("transport","network"); +INTERFACE_REGISTER_FUNCTIONS("network","link"); +INTERFACE_REGISTER_FUNCTIONS("link");*/ + +#include +#include +struct grub_net_protocol_stack *grub_net_protocol_stacks; +struct grub_net_protocol_stack + *grub_net_protocol_stack_get (char *name) +{ + struct grub_net_protocol_stack *p; + + for (p = grub_net_protocol_stacks; p; p = p->next) + { + if (!grub_strcmp(p->name,name)) + return p; + } + + return NULL; +} diff --git a/net/ip.c b/net/ip.c index 6fe58adb0..5eaa74f90 100644 --- a/net/ip.c +++ b/net/ip.c @@ -1,11 +1,11 @@ #include -#include #include #include #include -#include -#include #include +#include +#include +#include #include struct grub_net_protocol *grub_ipv4_prot; @@ -29,14 +29,14 @@ ipchksum(void *ipv, int len) static grub_err_t -send_ip_packet (struct grub_net_interface *inf, struct grub_net_protstack *protstack, struct grub_net_buff *nb ) +send_ip_packet (struct grub_net_network_layer_interface *inf, + struct grub_net_transport_network_interface *trans_net_inf, struct grub_net_buff *nb ) { struct iphdr *iph; - grub_err_t err; + static int id = 0x2400; - if((err = grub_netbuff_push(nb,sizeof(*iph)) ) != GRUB_ERR_NONE) - return err; + grub_netbuff_push(nb,sizeof(*iph)); iph = (struct iphdr *) nb->data; /*FIXME dont work in litte endian machines*/ @@ -44,38 +44,64 @@ send_ip_packet (struct grub_net_interface *inf, struct grub_net_protstack *prots //grub_uint8_t hdrlen = sizeof (struct iphdr)/4; iph->verhdrlen = (4<<4 | 5); iph->service = 0; - iph->len = sizeof(*iph); - iph->ident = 0x2b5f; + iph->len = nb->tail - nb-> data;//sizeof(*iph); + iph->ident = ++id; iph->frags = 0; iph->ttl = 0xff; iph->protocol = 0x11; - //grub_memcpy(&(iph->src) ,inf->card->ila->addr,inf->card->ila->len); - iph->src = *((grub_uint32_t *)inf->card->ila->addr); - //grub_memcpy(&(iph->dest) ,inf->ila->addr,inf->ila->len); - iph->dest = *((grub_uint32_t *)inf->ila->addr); + iph->src = (grub_uint32_t) bootp_pckt -> yiaddr; //inf->address.ipv4; // *((grub_uint32_t *)inf->card->ila->addr); + iph->dest = (grub_uint32_t) bootp_pckt -> siaddr;//inf->address.ipv4;// *((grub_uint32_t *)inf->ila->addr); iph->chksum = 0 ; - iph->chksum = ipchksum((void *)nb->head, sizeof(*iph)); + iph->chksum = ipchksum((void *)nb->data, sizeof(*iph)); - - return protstack->next->prot->send(inf,protstack->next,nb); + return trans_net_inf->inner_layer->link_prot->send(inf,trans_net_inf->inner_layer,nb); + //return protstack->next->prot->send(inf,protstack->next,nb); } -static struct grub_net_protocol grub_ipv4_protocol = +static grub_err_t +recv_ip_packet (struct grub_net_network_layer_interface *inf, + struct grub_net_transport_network_interface *trans_net_inf, struct grub_net_buff *nb ) +{ + + struct iphdr *iph; + while (1) + { + trans_net_inf->inner_layer->link_prot->recv(inf,trans_net_inf->inner_layer,nb); + iph = (struct iphdr *) nb->data; + if (iph->dest == 0x0908eaaa && iph->src == 0x0908ea92 && iph->protocol == 0x11) + { + grub_netbuff_pull(nb,sizeof(*iph)); + return 0; + } + } +/* grub_printf("ip.src 0x%x\n",iph->src); + grub_printf("ip.dst 0x%x\n",iph->dest); + grub_printf("ip.len 0x%x\n",iph->len); + grub_printf("ip.protocol 0x%x\n",iph->protocol); + */ + /* - get ip header + - verify if is the next layer is correct + -*/ + return 0; +} + +static struct grub_net_network_layer_protocol grub_ipv4_protocol = { .name = "ipv4", + .id = GRUB_NET_IPV4_ID, .send = send_ip_packet, - .recv = NULL + .recv = recv_ip_packet }; void ipv4_ini(void) { - grub_protocol_register (&grub_ipv4_protocol); + grub_net_network_layer_protocol_register (&grub_ipv4_protocol); } void ipv4_fini(void) { - grub_protocol_unregister (&grub_ipv4_protocol); + grub_net_network_layer_protocol_unregister (&grub_ipv4_protocol); } /* diff --git a/net/netbuff.c b/net/netbuff.c index 342260f43..136d55bc4 100644 --- a/net/netbuff.c +++ b/net/netbuff.c @@ -26,7 +26,7 @@ grub_err_t grub_netbuff_put (struct grub_net_buff *net_buff ,grub_size_t len) { net_buff->tail += len; if (net_buff->tail > net_buff->end) - return grub_error (GRUB_ERR_OUT_OF_RANGE, "out of the packet range."); + return grub_error (GRUB_ERR_OUT_OF_RANGE, "put out of the packet range."); return GRUB_ERR_NONE; } @@ -34,15 +34,20 @@ grub_err_t grub_netbuff_unput (struct grub_net_buff *net_buff ,grub_size_t len) { net_buff->tail -= len; if (net_buff->tail < net_buff->head) - return grub_error (GRUB_ERR_OUT_OF_RANGE, "out of the packet range."); + return grub_error (GRUB_ERR_OUT_OF_RANGE, "unput out of the packet range."); return GRUB_ERR_NONE; } grub_err_t grub_netbuff_push (struct grub_net_buff *net_buff ,grub_size_t len) { net_buff->data -= len; +/* grub_printf("push len =%d\n",len); + grub_printf("pack->head =%x\n",(unsigned int)net_buff->head); + grub_printf("pack->data =%x\n",(unsigned int)net_buff->data); + grub_printf("pack->tail =%x\n",(unsigned int)net_buff->tail); + grub_printf("pack->end =%x\n",(unsigned int)net_buff->end);*/ if (net_buff->data < net_buff->head) - return grub_error (GRUB_ERR_OUT_OF_RANGE, "out of the packet range."); + return grub_error (GRUB_ERR_OUT_OF_RANGE, "push out of the packet range."); return GRUB_ERR_NONE; } @@ -50,7 +55,7 @@ grub_err_t grub_netbuff_pull (struct grub_net_buff *net_buff ,grub_size_t len) { net_buff->data += len; if (net_buff->data > net_buff->end) - return grub_error (GRUB_ERR_OUT_OF_RANGE, "out of the packet range."); + return grub_error (GRUB_ERR_OUT_OF_RANGE, "pull out of the packet range."); return GRUB_ERR_NONE; } @@ -59,14 +64,36 @@ grub_err_t grub_netbuff_reserve (struct grub_net_buff *net_buff ,grub_size_t len net_buff->data += len; net_buff->tail += len; if ((net_buff->tail > net_buff->end) || (net_buff->data > net_buff->end)) - return grub_error (GRUB_ERR_OUT_OF_RANGE, "out of the packet range."); + return grub_error (GRUB_ERR_OUT_OF_RANGE, "reserve out of the packet range."); return GRUB_ERR_NONE; } -struct grub_net_buff * grub_netbuff_alloc ( grub_size_t len ) +struct grub_net_buff *grub_netbuff_alloc ( grub_size_t len ) { + struct grub_net_buff *nb; + void *data; + if (len < NETBUFFMINLEN) len = NETBUFFMINLEN; + len = ALIGN_UP (len,NETBUFF_ALIGN); - return (struct grub_net_buff *) grub_memalign (len,NETBUFF_ALIGN); + data = grub_memalign (len + sizeof (*nb),NETBUFF_ALIGN); + nb = (struct grub_net_buff *) ((int)data + len); + nb->head = nb->data = nb->tail = data; + nb->end = (char *) nb; + + return nb; +} + +grub_err_t grub_netbuff_free (struct grub_net_buff *net_buff) +{ + grub_free (net_buff); + return 0; + +} + +grub_err_t grub_netbuff_clear (struct grub_net_buff *net_buff) +{ + net_buff->data = net_buff->tail = net_buff->head; + return 0; } diff --git a/net/protocol.c b/net/protocol.c index a6117dc2c..05d4471d2 100644 --- a/net/protocol.c +++ b/net/protocol.c @@ -1,21 +1,37 @@ #include +#include +#include -static grub_net_protocol_t grub_net_protocols; - -void grub_protocol_register (grub_net_protocol_t prot) -{ - prot->next = grub_net_protocols; - grub_net_protocols = prot; +#define PROTOCOL_REGISTER_FUNCTIONS(layername) \ +struct grub_net_##layername##_layer_protocol *grub_net_##layername##_layer_protocols;\ +\ +void grub_net_##layername##_layer_protocol_register (struct grub_net_##layername##_layer_protocol *prot)\ +{\ + grub_list_push (GRUB_AS_LIST_P (&grub_net_##layername##_layer_protocols),\ + GRUB_AS_LIST (prot));\ +}\ +\ +void grub_net_##layername##_layer_protocol_unregister (struct grub_net_##layername##_layer_protocol *prot)\ +{\ + grub_list_remove (GRUB_AS_LIST_P (&grub_net_##layername##_layer_protocols),\ + GRUB_AS_LIST (prot));\ +}\ +\ +struct grub_net_##layername##_layer_protocol \ + *grub_net_##layername##_layer_protocol_get (grub_net_protocol_id_t id)\ +{\ + struct grub_net_##layername##_layer_protocol *p;\ +\ + for (p = grub_net_##layername##_layer_protocols; p; p = p->next)\ + {\ + if (p->id == id)\ + return p;\ + }\ + \ + return NULL; \ } -void grub_protocol_unregister (grub_net_protocol_t prot) -{ - grub_net_protocol_t *p, q; - - for (p = &grub_net_protocols, q = *p; q; p = &(q->next), q = q->next) - if (q == prot) - { - *p = q->next; - break; - } -} +PROTOCOL_REGISTER_FUNCTIONS(application); +PROTOCOL_REGISTER_FUNCTIONS(transport); +PROTOCOL_REGISTER_FUNCTIONS(network); +PROTOCOL_REGISTER_FUNCTIONS(link); diff --git a/net/tftp.c b/net/tftp.c index 3f481fe58..1f04ef47e 100644 --- a/net/tftp.c +++ b/net/tftp.c @@ -4,42 +4,94 @@ #include #include #include -#include #include #include -#include #include +#include +#include +#include + +int block,rrq_count=0; +struct { + int block_size; + int size; +} tftp_file; + + +char *get_tok_val(char **tok, char **val, char **str_opt,char *end); +void process_option(char *tok, char *val); + +char *get_tok_val(char **tok, char **val,char **str_opt,char *end) +{ + char *p = *str_opt; + *tok = p; + p += grub_strlen(p) + 1; + + if(p > end) + return NULL; + + *val = p; + p += grub_strlen(p) + 1; + *str_opt = p; + return *tok; +} + +void process_option(char *tok, char *val) +{ + if (!grub_strcmp(tok,"blksize")) + { + tftp_file.block_size = grub_strtoul (val,NULL,0); + return; + } + + if (!grub_strcmp(tok,"tsize")) + { + tftp_file.size = grub_strtoul (val,NULL,0); + return; + } + +} + +//void tftp_open (char *options); /*send read request*/ static grub_err_t -send_tftp_rr (struct grub_net_interface *inf, struct grub_net_protstack *protstack,struct grub_net_buff *nb) +tftp_open (struct grub_net_network_layer_interface *inf __attribute((unused)), + struct grub_net_protocol_stack *protstack,struct grub_net_buff *nb, char *filename) { - /*Start TFTP header*/ - struct tftphdr *tftph; char *rrq; int rrqlen; int hdrlen; - grub_err_t err; + struct udp_interf *udp_interf; + struct grub_net_application_transport_interface *app_interface = (struct grub_net_application_transport_interface *) protstack->interface; - if((err = grub_netbuff_push (nb,sizeof(*tftph))) != GRUB_ERR_NONE) - return err; + app_interface = (struct grub_net_application_transport_interface *) protstack->interface; + grub_netbuff_push (nb,sizeof (*tftph)); + udp_interf = (struct udp_interf *) app_interface->data; + udp_interf->src = TFTP_CLIENT_PORT + rrq_count++; + grub_printf("open tfpt udp_port = %d\n",udp_interf->src); + udp_interf->dst = TFTP_SERVER_PORT; tftph = (struct tftphdr *) nb->data; rrq = (char *) tftph->u.rrq; rrqlen = 0; tftph->opcode = TFTP_RRQ; - grub_strcpy (rrq,inf->path); - rrqlen += grub_strlen (inf->path) + 1; - rrq += grub_strlen (inf->path) + 1; + grub_strcpy (rrq,filename); + rrqlen += grub_strlen (filename) + 1; + rrq += grub_strlen (filename) + 1; /*passar opcoes como parametro ou usar default?*/ grub_strcpy (rrq,"octet"); rrqlen += grub_strlen ("octet") + 1; rrq += grub_strlen ("octet") + 1; + //grub_strcpy (rrq,"netascii"); + //rrqlen += grub_strlen ("netascii") + 1; + //rrq += grub_strlen ("netascii") + 1; + grub_strcpy (rrq,"blksize"); rrqlen += grub_strlen("blksize") + 1; rrq += grub_strlen ("blksize") + 1; @@ -59,39 +111,146 @@ send_tftp_rr (struct grub_net_interface *inf, struct grub_net_protstack *protsta grub_netbuff_unput (nb,nb->tail - (nb->data+hdrlen)); - return protstack->next->prot->send(inf,protstack->next,nb); + app_interface->trans_prot->send (inf,protstack->interface,nb); + /*Receive OACK*/ + return app_interface->app_prot->recv(inf,protstack,nb); } -/* -int send_tftp_ack(int block, int port){ - - tftp_t pckt; - int pcktlen; - pckt.opcode = TFTP_ACK; - pckt.u.ack.block = block; - pcktlen = sizeof (pckt.opcode) + sizeof (pckt.u.ack.block); - - port = 4; - return 0;// send_udp_packet (&pckt,pcktlen,TFTP_CLIENT_PORT,port); -} - -*/ - -static struct grub_net_protocol grub_tftp_protocol = +static grub_err_t +tftp_receive (struct grub_net_network_layer_interface *inf __attribute((unused)), + struct grub_net_protocol_stack *protstack,struct grub_net_buff *nb) { - .name = "tftp", - .open = send_tftp_rr + struct tftphdr *tftph; + char *token,*value,*temp; + struct grub_net_application_transport_interface *app_interface = + (struct grub_net_application_transport_interface *) protstack->interface; + + app_interface->trans_prot->recv (inf,protstack->interface,nb); + + tftph = (struct tftphdr *) nb->data; + switch (tftph->opcode) + { + case TFTP_OACK: + /*process oack packet*/ + temp = (char *) tftph->u.oack.data; + while(get_tok_val(&token,&value,&temp,nb->tail)) + { + grub_printf("tok = <%s> val = <%s>\n",token,value); + process_option(token,value); + } + + //buff_clean + nb->data = nb->tail; + grub_printf("OACK---------------------------------------------------------\n"); + grub_printf("block_size=%d\n",tftp_file.block_size); + grub_printf("file_size=%d\n",tftp_file.size); + grub_printf("OACK---------------------------------------------------------\n"); + block = 0; + break; + case TFTP_DATA: + grub_netbuff_pull (nb,sizeof (tftph->opcode) + sizeof (tftph->u.data.block)); + if (tftph->u.data.block == block + 1) + block = tftph->u.data.block; + else + grub_netbuff_clear(nb); + break; + case TFTP_ERROR: + nb->data = nb->tail; + break; + } + return 0;// tftp_send_ack (inf,protstack,nb,tftph->u.data.block); + /*remove tftp header and return. + nb should now contain only the payload*/ +} + +static grub_err_t +tftp_send_ack (struct grub_net_network_layer_interface *inf __attribute((unused)), + struct grub_net_protocol_stack *protstack,struct grub_net_buff *nb) +{ + struct tftphdr *tftph; + struct grub_net_application_transport_interface *app_interface = (struct grub_net_application_transport_interface *) protstack->interface; + + nb->data = nb->tail = nb->end; + + grub_netbuff_push (nb,sizeof (tftph->opcode) + sizeof (tftph->u.ack.block)); + + tftph = (struct tftphdr *) nb->data; + tftph->opcode = TFTP_ACK; + tftph->u.ack.block = block; + + return app_interface->trans_prot->send (inf,protstack->interface,nb); +} + +static int tftp_file_size (struct grub_net_network_layer_interface* inf , + struct grub_net_protocol_stack *protocol_stack , struct grub_net_buff *nb ,char *filename ) +{ + + tftp_open (inf, protocol_stack,nb, filename); + return tftp_file.size; +} + +static grub_err_t +tftp_close (struct grub_net_network_layer_interface *inf __attribute((unused)), + struct grub_net_protocol_stack *protstack __attribute((unused)),struct grub_net_buff *nb __attribute((unused))) +{ + + return 0; +} + +static struct grub_net_application_transport_interface grub_net_tftp_app_trans_interf; +static struct grub_net_transport_network_interface grub_net_tftp_trans_net_interf; +static struct grub_net_network_link_interface grub_net_tftp_net_link_interf; +static struct grub_net_protocol_stack grub_net_tftp_stack = +{ + .name = "tftp", + .id = GRUB_NET_TFTP_ID, + .interface = (void *) &grub_net_tftp_app_trans_interf + }; +static struct grub_net_application_layer_protocol grub_tftp_protocol = +{ + .name = "tftp", + .id = GRUB_NET_TFTP_ID, + .open = tftp_open, + .recv = tftp_receive, + .send_ack = tftp_send_ack, + .get_file_size = tftp_file_size, + .close = tftp_close +}; + +static struct udp_interf tftp_udp_interf; + void tftp_ini(void) { - grub_protocol_register (&grub_tftp_protocol); + + ethernet_ini (); + ipv4_ini (); + udp_ini (); + grub_net_application_layer_protocol_register (&grub_tftp_protocol); + grub_net_stack_register (&grub_net_tftp_stack); + + grub_net_tftp_app_trans_interf.app_prot = &grub_tftp_protocol; + grub_net_tftp_app_trans_interf.trans_prot = grub_net_transport_layer_protocol_get (GRUB_NET_UDP_ID); + grub_net_tftp_app_trans_interf.inner_layer = &grub_net_tftp_trans_net_interf; + grub_net_tftp_app_trans_interf.data = &tftp_udp_interf; + + grub_net_tftp_trans_net_interf.trans_prot = grub_net_tftp_app_trans_interf.trans_prot; + grub_net_tftp_trans_net_interf.net_prot = grub_net_network_layer_protocol_get (GRUB_NET_IPV4_ID); + grub_net_tftp_trans_net_interf.inner_layer = &grub_net_tftp_net_link_interf; + + grub_net_tftp_net_link_interf.net_prot = grub_net_tftp_trans_net_interf.net_prot; + grub_net_tftp_net_link_interf.link_prot = grub_net_link_layer_protocol_get (GRUB_NET_ETHERNET_ID) ; + + } void tftp_fini(void) { - grub_protocol_unregister (&grub_tftp_protocol); + + + grub_net_application_layer_protocol_unregister (&grub_tftp_protocol); } /* int read_tftp_pckt (grub_uint16_t port, void *buffer, int &buff_len){ diff --git a/net/udp.c b/net/udp.c index 2a4a7690b..fb81aef93 100644 --- a/net/udp.c +++ b/net/udp.c @@ -4,41 +4,84 @@ #include #include #include -/*Assumes that there is allocated memory to the header before the buffer address. */ + static grub_err_t -send_udp_packet (struct grub_net_interface *inf, struct grub_net_protstack *protstack, struct grub_net_buff *nb) +send_udp_packet (struct grub_net_network_layer_interface *inf, + struct grub_net_application_transport_interface *app_trans_inf, struct grub_net_buff *nb) { struct udphdr *udph; - grub_err_t err; + struct udp_interf *udp_interf; - if((err = grub_netbuff_push (nb,sizeof(*udph)) ) != GRUB_ERR_NONE) - return err; + grub_netbuff_push (nb,sizeof(*udph)); udph = (struct udphdr *) nb->data; - udph->src = *((grub_uint16_t *) inf->card->tla->addr); - udph->dst = *((grub_uint16_t *) inf->tla->addr); + udp_interf = (struct udp_interf *) app_trans_inf->data; + udph->src = udp_interf->src; + udph->dst = udp_interf->dst; + /*no chksum*/ udph->chksum = 0; - udph->len = sizeof (sizeof (*udph)) + nb->end - nb->head; + udph->len = nb->tail - nb->data; - return protstack->next->prot->send(inf,protstack->next,nb); + return app_trans_inf->inner_layer->net_prot->send(inf,app_trans_inf->inner_layer,nb); } -static struct grub_net_protocol grub_udp_protocol = +static grub_err_t +receive_udp_packet (struct grub_net_network_layer_interface *inf, + struct grub_net_application_transport_interface *app_trans_inf, struct grub_net_buff *nb) +{ + + struct udphdr *udph; + struct udp_interf *udp_interf; + udp_interf = (struct udp_interf *) app_trans_inf->data; + + while(1) + { + app_trans_inf->inner_layer->net_prot->recv(inf,app_trans_inf->inner_layer,nb); + + udph = (struct udphdr *) nb->data; + // grub_printf("udph->dst %d\n",udph->dst); + // grub_printf("udp_interf->src %d\n",udp_interf->src); + if (udph->dst == udp_interf->src) + { + grub_netbuff_pull (nb,sizeof(*udph)); + + // udp_interf->src = udph->dst; + udp_interf->dst = udph->src; + + // grub_printf("udph->dst %d\n",udph->dst); + // grub_printf("udph->src %d\n",udph->src); + // grub_printf("udph->len %d\n",udph->len); + // grub_printf("udph->chksum %x\n",udph->chksum); + + /* - get udp header.. + - verify if is in the desired port + - if not. get another packet + - remove udp header*/ + + return 0; + } + } +} + + +static struct grub_net_transport_layer_protocol grub_udp_protocol = { .name = "udp", - .send = send_udp_packet + .id = GRUB_NET_UDP_ID, + .send = send_udp_packet, + .recv = receive_udp_packet }; void udp_ini(void) { - grub_protocol_register (&grub_udp_protocol); + grub_net_transport_layer_protocol_register (&grub_udp_protocol); } void udp_fini(void) { - grub_protocol_unregister (&grub_udp_protocol); + grub_net_transport_layer_protocol_unregister (&grub_udp_protocol); } /* From 8c599704a75bad68bd4d903fc1b111cba91bd354 Mon Sep 17 00:00:00 2001 From: "Manoel R. Abranches" Date: Mon, 21 Jun 2010 19:20:55 -0300 Subject: [PATCH 020/869] Network code specific for ieee1275 machines. Used to parse BOOTP packet from the server and use write/read on the network card. May be removed later. --- conf/powerpc-ieee1275.rmk | 3 +- include/grub/disk.h | 3 +- include/grub/ieee1275/ieee1275.h | 3 +- kern/ieee1275/init.c | 4 +- kern/ieee1275/openfw.c | 68 ++++++++++++++++-- kern/main.c | 8 +-- net/ieee1275/interface.c | 120 ++++++++++++++++++------------- 7 files changed, 144 insertions(+), 65 deletions(-) diff --git a/conf/powerpc-ieee1275.rmk b/conf/powerpc-ieee1275.rmk index 14d04f93e..ead6d4230 100644 --- a/conf/powerpc-ieee1275.rmk +++ b/conf/powerpc-ieee1275.rmk @@ -24,7 +24,8 @@ kernel_img_SOURCES = kern/powerpc/ieee1275/startup.S kern/ieee1275/cmain.c \ kern/parser.c kern/partition.c kern/env.c kern/$(target_cpu)/dl.c \ kern/generic/millisleep.c kern/time.c \ symlist.c kern/$(target_cpu)/cache.S net/ip.c net/tftp.c net/udp.c net/ethernet.c net/arp.c \ - net/ieee1275/interface.c net/interface.c net/protocol.c net/netbuff.c + net/ieee1275/interface.c net/interface.c net/protocol.c net/netbuff.c \ + fs/ieee1275/ofnet.c kernel_img_CFLAGS = $(COMMON_CFLAGS) kernel_img_ASFLAGS = $(COMMON_ASFLAGS) kernel_img_LDFLAGS += $(COMMON_LDFLAGS) -Wl,-N,-S,-Ttext,0x200000,-Bstatic diff --git a/include/grub/disk.h b/include/grub/disk.h index e7f807e0e..1bdfb639b 100644 --- a/include/grub/disk.h +++ b/include/grub/disk.h @@ -42,7 +42,8 @@ enum grub_disk_dev_id GRUB_DISK_DEVICE_PXE_ID, GRUB_DISK_DEVICE_SCSI_ID, GRUB_DISK_DEVICE_FILE_ID, - GRUB_DISK_DEVICE_LUKS_ID + GRUB_DISK_DEVICE_LUKS_ID, + GRUB_DISK_DEVICE_OFNET_ID }; struct grub_disk; diff --git a/include/grub/ieee1275/ieee1275.h b/include/grub/ieee1275/ieee1275.h index b30909c68..f4c8b4edf 100644 --- a/include/grub/ieee1275/ieee1275.h +++ b/include/grub/ieee1275/ieee1275.h @@ -182,9 +182,8 @@ EXPORT_FUNC(grub_ieee1275_map) (grub_addr_t phys, grub_addr_t virt, char *EXPORT_FUNC(grub_ieee1275_encode_devname) (const char *path); char *EXPORT_FUNC(grub_ieee1275_get_filename) (const char *path); - int EXPORT_FUNC(grub_ieee1275_devices_iterate) (int (*hook) (struct grub_ieee1275_devalias * alias)); - +char *EXPORT_FUNC(grub_ieee1275_get_aliasdevname) (const char *path); #endif /* ! GRUB_IEEE1275_HEADER */ diff --git a/kern/ieee1275/init.c b/kern/ieee1275/init.c index b7e5c337e..1e108c920 100644 --- a/kern/ieee1275/init.c +++ b/kern/ieee1275/init.c @@ -32,6 +32,7 @@ #include #include #include +#include /* The minimal heap size we can live with. */ #define HEAP_MIN_SIZE (unsigned long) (2 * 1024 * 1024) @@ -223,13 +224,14 @@ grub_machine_init (void) grub_ssize_t actual; grub_ieee1275_init (); - + grub_console_init (); #ifdef __i386__ grub_get_extended_memory (); #endif grub_claim_heap (); grub_ofdisk_init (); + grub_ofnet_init(); /* Process commandline. */ if (grub_ieee1275_get_property (grub_ieee1275_chosen, "bootargs", &args, diff --git a/kern/ieee1275/openfw.c b/kern/ieee1275/openfw.c index 5693f3be0..337fc4b7e 100644 --- a/kern/ieee1275/openfw.c +++ b/kern/ieee1275/openfw.c @@ -22,11 +22,13 @@ #include #include #include +#include enum grub_ieee1275_parse_type { GRUB_PARSE_FILENAME, GRUB_PARSE_PARTITION, + GRUB_PARSE_DEVICE }; /* Walk children of 'devpath', calling hook for each. */ @@ -366,12 +368,14 @@ grub_ieee1275_parse_args (const char *path, enum grub_ieee1275_parse_type ptype) ret = grub_strndup (args, (grub_size_t)(comma - args)); } } - else + + else if (!grub_strcmp ("network", type)) + { + if (ptype == GRUB_PARSE_DEVICE) + ret = grub_strdup(device); + } + else { - /* XXX Handle net devices by configuring & registering a grub_net_dev - here, then return its name? - Example path: "net:,,,,,". */ grub_printf ("Unsupported type %s for device %s\n", type, device); } @@ -381,6 +385,12 @@ fail: return ret; } +char * +grub_ieee1275_get_aliasdevname (const char *path) +{ + return grub_ieee1275_parse_args (path, GRUB_PARSE_DEVICE); +} + char * grub_ieee1275_get_filename (const char *path) { @@ -432,3 +442,51 @@ grub_halt (void) grub_ieee1275_interpret ("power-off", 0); grub_ieee1275_interpret ("poweroff", 0); } + +static const struct +{ + char *name; + int offset; +} + +bootp_response_properties[] = +{ + { .name = "bootp-response", .offset = 0 }, + { .name = "dhcp-response", .offset = 0 }, + { .name = "bootpreply-packet", .offset = 0x2a }, +}; + +#define SIZE(X) ( sizeof (X) / sizeof(X[0])) + +grub_bootp_t +grub_getbootp( void ) +{ + grub_bootp_t packet = grub_malloc(sizeof *packet); + void *bootp_response = NULL; + grub_ssize_t size; + unsigned int i; + // grub_ieee1275_finddevice ("/chosen", &grub_ieee1275_chosen); + for ( i = 0; i < SIZE(bootp_response_properties); i++) + { + if (grub_ieee1275_get_property_length (grub_ieee1275_chosen, + bootp_response_properties[i].name, &size)>=0) + break; + } + + if ( size <0 ) + { + grub_printf("Error to get bootp\n"); + return NULL; + } + + if (grub_ieee1275_get_property (grub_ieee1275_chosen, bootp_response_properties[i].name , bootp_response , + size, 0) < 0) + { + grub_printf("Error to get bootp\n"); + return NULL; + } + + packet = (void *) ((int)bootp_response + bootp_response_properties[i].offset); + return packet; +} + diff --git a/kern/main.c b/kern/main.c index 8b6c8a180..3320c4a68 100644 --- a/kern/main.c +++ b/kern/main.c @@ -95,14 +95,14 @@ grub_load_modules (void) grub_module_iterate (hook); } - +/* static void grub_load_config (void) { auto int hook (struct grub_module_header *); int hook (struct grub_module_header *header) { - /* Not an embedded config, skip. */ + / Not an embedded config, skip. / if (header->type != OBJ_TYPE_CONFIG) return 0; @@ -113,7 +113,7 @@ grub_load_config (void) grub_module_iterate (hook); } - +*/ /* Write hook for the environment variables of root. Remove surrounding parentheses, if any. */ static char * @@ -192,7 +192,7 @@ grub_main (void) grub_register_core_commands (); - grub_load_config (); + //grub_load_config (); grub_load_normal_mode (); grub_rescue_run (); } diff --git a/net/ieee1275/interface.c b/net/ieee1275/interface.c index 5a246ffa5..fbd887ad2 100644 --- a/net/ieee1275/interface.c +++ b/net/ieee1275/interface.c @@ -1,55 +1,21 @@ #include +#include #include - -grub_uint32_t get_server_ip (void) -{ - return bootp_pckt->siaddr; -} - -grub_uint32_t get_client_ip (void) -{ - return bootp_pckt->yiaddr; -} - -grub_uint8_t* get_server_mac (void) -{ - grub_uint8_t *mac; - - mac = grub_malloc (6 * sizeof(grub_uint8_t)); - mac[0] = 0x00 ; - mac[1] = 0x11 ; - mac[2] = 0x25 ; - mac[3] = 0xca ; - mac[4] = 0x1f ; - mac[5] = 0x01 ; - - return mac; - -} - -grub_uint8_t* get_client_mac (void) -{ - grub_uint8_t *mac; - - mac = grub_malloc (6 * sizeof (grub_uint8_t)); - mac[0] = 0x0a ; - mac[1] = 0x11 ; - mac[2] = 0xbd ; - mac[3] = 0xe3 ; - mac[4] = 0xe3 ; - mac[5] = 0x04 ; - - return mac; -} +#include +#include +#include +#include +#include static grub_ieee1275_ihandle_t handle; int card_open (void) { grub_ieee1275_open (grub_net->dev , &handle); - return 1;//error + return 0; } + int card_close (void) { @@ -59,22 +25,74 @@ int card_close (void) } -int send_card_buffer (void *buffer,int buff_len) +int send_card_buffer (struct grub_net_buff *pack) { - int actual; - - grub_ieee1275_write (handle,buffer,buff_len,&actual); + int actual; + //grub_printf("packet size transmited: %d\n",pack->tail - pack->data); + grub_ieee1275_write (handle,pack->data,pack->tail - pack->data,&actual); +// grub_printf("actual transmited %d\n",actual); return actual; } -int get_card_buffer (void *buffer,int buff_len) +int get_card_packet (struct grub_net_buff *pack __attribute__ ((unused))) { - int actual; + int actual; + char *datap; + struct iphdr *iph; + struct etherhdr *eth; + struct arphdr *arph; + pack->data = pack->tail = pack->head; + datap = pack->data; + do + { + grub_ieee1275_read (handle,datap,sizeof (*eth),&actual); + // if (actual <= 0) + // grub_millisleep(10); - grub_ieee1275_read (handle,buffer,buff_len,&actual); - - return actual; + }while (actual <= 0); + eth = (struct etherhdr *) datap; + datap += sizeof(*eth); + + // grub_printf("ethernet eth->dst %x:%x:%x:%x:%x:%x\n",eth->dst[0], + // eth->dst[1],eth->dst[2],eth->dst[3],eth->dst[4],eth->dst[5]); + // grub_printf("ethernet eth->src %x:%x:%x:%x:%x:%x\n",eth->src[0],eth->src[1], + // eth->src[2],eth->src[3],eth->src[4],eth->src[5]); +// grub_printf ("eth.type 0x%x\n",eth->type); + + switch (eth->type) + { + case 0x806: + + grub_ieee1275_read (handle,datap,sizeof (*arph),&actual); + arph = (struct arphdr *) datap; + + grub_netbuff_put (pack,sizeof (*eth) + sizeof (*arph)); + break; + case 0x800: + grub_ieee1275_read (handle,datap,sizeof (*iph),&actual); + iph = (struct iphdr *) datap; + datap += sizeof(*iph); + + // grub_printf("ip.src 0x%x\n",iph->src); + // grub_printf("ip.dst 0x%x\n",iph->dest); + // grub_printf("ip.len 0x%x\n",iph->len); + // grub_printf("ip.protocol 0x%x\n",iph->protocol); + + grub_ieee1275_read (handle,datap,iph->len - sizeof (*iph),&actual); + + + grub_netbuff_put (pack,sizeof (*eth) + iph->len); + break; + case 0x86DD: + grub_printf("Ipv6 not yet implemented.\n"); + break; + default: + grub_printf("Unknow packet %x\n",eth->type); + break; + } +// grub_printf("packsize %d\n",pack->tail - pack->data); + return 0;// sizeof (eth) + iph.len; } From bf6d9eeb531e19d88c1705688468b89ea44c9031 Mon Sep 17 00:00:00 2001 From: "Manoel R. Abranches" Date: Wed, 23 Jun 2010 14:47:55 -0300 Subject: [PATCH 021/869] Abort transference when getting file size. --- net/tftp.c | 38 ++++++++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 6 deletions(-) diff --git a/net/tftp.c b/net/tftp.c index 1f04ef47e..8e89ed1f4 100644 --- a/net/tftp.c +++ b/net/tftp.c @@ -71,7 +71,6 @@ tftp_open (struct grub_net_network_layer_interface *inf __attribute((unused)), udp_interf = (struct udp_interf *) app_interface->data; udp_interf->src = TFTP_CLIENT_PORT + rrq_count++; - grub_printf("open tfpt udp_port = %d\n",udp_interf->src); udp_interf->dst = TFTP_SERVER_PORT; tftph = (struct tftphdr *) nb->data; @@ -135,16 +134,15 @@ tftp_receive (struct grub_net_network_layer_interface *inf __attribute((unused)) temp = (char *) tftph->u.oack.data; while(get_tok_val(&token,&value,&temp,nb->tail)) { - grub_printf("tok = <%s> val = <%s>\n",token,value); process_option(token,value); } //buff_clean nb->data = nb->tail; - grub_printf("OACK---------------------------------------------------------\n"); - grub_printf("block_size=%d\n",tftp_file.block_size); - grub_printf("file_size=%d\n",tftp_file.size); - grub_printf("OACK---------------------------------------------------------\n"); + // grub_printf("OACK---------------------------------------------------------\n"); + //grub_printf("block_size=%d\n",tftp_file.block_size); + // grub_printf("file_size=%d\n",tftp_file.size); + // grub_printf("OACK---------------------------------------------------------\n"); block = 0; break; case TFTP_DATA: @@ -182,11 +180,39 @@ tftp_send_ack (struct grub_net_network_layer_interface *inf __attribute((unused) return app_interface->trans_prot->send (inf,protstack->interface,nb); } +static grub_err_t +tftp_send_err (struct grub_net_network_layer_interface *inf __attribute((unused)), + struct grub_net_protocol_stack *protstack,struct grub_net_buff *nb, char *errmsg, int errcode) +{ + + struct tftphdr *tftph; + struct grub_net_application_transport_interface *app_interface + = (struct grub_net_application_transport_interface *) protstack->interface; + int msglen = 0; + int hdrlen = 0; + nb->data = nb->tail = nb->end; + + grub_netbuff_push (nb,sizeof (*tftph)); + + tftph = (struct tftphdr *) nb->data; + tftph->opcode = TFTP_ERROR; + tftph->u.err.errcode = errcode; + + grub_strcpy ((char *)tftph->u.err.errmsg,errmsg); + msglen += grub_strlen (errmsg) + 1; + hdrlen = sizeof (tftph->opcode) + sizeof (tftph->u.err.errcode) + msglen; + grub_netbuff_unput (nb,nb->tail - (nb->data + hdrlen)); + + return app_interface->trans_prot->send (inf,protstack->interface,nb); +} + static int tftp_file_size (struct grub_net_network_layer_interface* inf , struct grub_net_protocol_stack *protocol_stack , struct grub_net_buff *nb ,char *filename ) { tftp_open (inf, protocol_stack,nb, filename); + tftp_send_err (inf, protocol_stack,nb,"Abort transference.",0); + return tftp_file.size; } From 1edb7287ff681aa6889e397ab4c891ea93246f2f Mon Sep 17 00:00:00 2001 From: "Manoel R. Abranches" Date: Wed, 23 Jun 2010 14:49:46 -0300 Subject: [PATCH 022/869] Parse ipv6 header on incoming packets. --- conf/powerpc-ieee1275.rmk | 1 - fs/ieee1275/ofnet.c | 31 +++++++++++++++---------------- include/grub/net/ip.h | 12 ++++++++++++ net/ieee1275/interface.c | 14 ++++++++++++-- 4 files changed, 39 insertions(+), 19 deletions(-) diff --git a/conf/powerpc-ieee1275.rmk b/conf/powerpc-ieee1275.rmk index ead6d4230..f0faef489 100644 --- a/conf/powerpc-ieee1275.rmk +++ b/conf/powerpc-ieee1275.rmk @@ -3,7 +3,6 @@ # Images. -<<<<<<< TREE kernel_img_HEADERS += ieee1275/ieee1275.h \ command.h i18n.h env_private.h net/ip.h net/udp.h net/ethernet.h net/arp.h net/tftp.h\ net/ieee1275/interface.h net/type_net.h net.h net/interface.h net/protocol.h net/netbuff.h diff --git a/fs/ieee1275/ofnet.c b/fs/ieee1275/ofnet.c index 196aadcf2..3bbb5c227 100644 --- a/fs/ieee1275/ofnet.c +++ b/fs/ieee1275/ofnet.c @@ -145,7 +145,7 @@ grub_ofnetfs_open (struct grub_file *file , const char *name ) return 1; } - grub_printf("name = %s\n",name); + // grub_printf("name = %s\n",name); struct grub_net_protocol_stack *stack; struct grub_net_buff *pack; @@ -164,38 +164,37 @@ grub_ofnetfs_open (struct grub_file *file , const char *name ) for (found_addr = 0x800000; found_addr < + 2000 * 0x100000; found_addr += 0x100000) { - grub_printf("traing to claim %d bytes at 0x%x\n",file_size,found_addr); +// grub_printf("trying to claim %d bytes at 0x%x\n",file_size,found_addr); if (grub_claimmap (found_addr , file_size) != -1) break; } - grub_printf("Claimed %d bytes at 0x%x\n",file_size,found_addr); +// grub_printf("Claimed %d bytes at 0x%x\n",file_size,found_addr); file->data = (void *) found_addr; - grub_printf("file->data = 0x%x\n",(int)file->data); - grub_printf("file_size = %d\n",file_size); - grub_printf("OPEN\n"); +// grub_printf("file->data = 0x%x\n",(int)file->data); +// grub_printf("file_size = %d\n",file_size); +// grub_printf("OPEN\n"); grub_netbuff_clear(pack); grub_netbuff_reserve (pack,80*1024); app_interface->app_prot->open (NULL,stack,pack,(char *) name); do { //if (app_interface->app_prot->recv (NULL,stack,pack) == GRUB_ERR_NONE) - grub_printf("RECEIVE PACKET\n"); +// grub_printf("RECEIVE PACKET\n"); grub_netbuff_clear(pack); grub_netbuff_reserve (pack,80*1024); app_interface->app_prot->recv (NULL,stack,pack); if (grub_errno != GRUB_ERR_NONE) return grub_errno; - grub_printf("RECEIVED PACKET\n"); +// grub_printf("RECEIVED PACKET\n"); // { - grub_printf("payload_size= %d\n",pack->tail - pack->data); - grub_printf("amount= %d\n",amount); - grub_printf("file_size= %d\n",file_size); +// grub_printf("payload_size= %d\n",pack->tail - pack->data); +// grub_printf("amount= %d\n",amount); +// grub_printf("file_size= %d\n",file_size); datap = (char *)file->data + amount; amount += (pack->tail - pack->data); - grub_printf("datap = 0x%x\n",(int)datap ); - // amount += pack->tail - pack->data; +// grub_printf("datap = 0x%x\n",(int)datap ); grub_memcpy(datap, pack->data, pack->tail - pack->data); - grub_printf("SEND ACK\n"); +// grub_printf("SEND ACK\n"); grub_netbuff_clear(pack); grub_netbuff_reserve (pack,80*1024); @@ -204,12 +203,12 @@ grub_ofnetfs_open (struct grub_file *file , const char *name ) if (grub_errno != GRUB_ERR_NONE) return grub_errno; - grub_printf("SENT ACK\n"); +// grub_printf("SENT ACK\n"); //} // file->data = grub_realloc(file->data,amount); }while (amount < file_size); - grub_printf("transfer complete\n"); +// grub_printf("transfer complete\n"); file->size = file_size; // grub_netbuff_free(pack); diff --git a/include/grub/net/ip.h b/include/grub/net/ip.h index e1f45dcfa..cb119ac6f 100644 --- a/include/grub/net/ip.h +++ b/include/grub/net/ip.h @@ -16,6 +16,18 @@ struct iphdr { grub_uint32_t dest; } __attribute__ ((packed)) ; +struct ip6hdr +{ + grub_uint8_t version:4, + priority:4; + grub_uint8_t flow_lbl[3]; + grub_uint16_t payload_len; + grub_uint8_t nexthdr; + grub_uint8_t hop_limit; + grub_uint8_t saddr[16]; + grub_uint8_t daddr[16]; +} __attribute__ ((packed)); + #define IP_UDP 17 /* UDP protocol */ #define IP_BROADCAST 0xFFFFFFFF diff --git a/net/ieee1275/interface.c b/net/ieee1275/interface.c index fbd887ad2..1100ee85d 100644 --- a/net/ieee1275/interface.c +++ b/net/ieee1275/interface.c @@ -44,6 +44,7 @@ int get_card_packet (struct grub_net_buff *pack __attribute__ ((unused))) struct iphdr *iph; struct etherhdr *eth; struct arphdr *arph; + struct ip6hdr *ip6h; pack->data = pack->tail = pack->head; datap = pack->data; do @@ -86,11 +87,20 @@ int get_card_packet (struct grub_net_buff *pack __attribute__ ((unused))) grub_netbuff_put (pack,sizeof (*eth) + iph->len); break; + case 0x86DD: - grub_printf("Ipv6 not yet implemented.\n"); + grub_printf("!!!!!!!!!!!!!!!!!IPV6 packet received!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n"); + grub_ieee1275_read (handle,datap,sizeof (*ip6h),&actual); + ip6h = (struct ip6hdr *) datap; + grub_printf("ip6hdr->payload_len = %x\n",ip6h->payload_len); + grub_printf("ip6hdr->nexthdr = %x\n",ip6h->nexthdr); + + datap += sizeof(*ip6h); + grub_ieee1275_read (handle,datap,ip6h->payload_len - sizeof (*ip6h),&actual); break; + default: - grub_printf("Unknow packet %x\n",eth->type); + grub_printf("Unknow packet %x\n",eth->type); break; } // grub_printf("packsize %d\n",pack->tail - pack->data); From 3ec6213b179b3b82611e4caa35dae37a16fd2045 Mon Sep 17 00:00:00 2001 From: "Manoel R. Abranches" Date: Tue, 29 Jun 2010 06:50:15 -0300 Subject: [PATCH 023/869] Clean Debug messages --- fs/ieee1275/ofnet.c | 75 ++++++++++--------------------------- include/grub/net/type_net.h | 1 + net/ethernet.c | 6 +++ net/ieee1275/interface.c | 16 -------- net/ip.c | 7 ++++ net/netbuff.c | 7 +--- net/tftp.c | 6 ++- net/udp.c | 8 +++- 8 files changed, 46 insertions(+), 80 deletions(-) diff --git a/fs/ieee1275/ofnet.c b/fs/ieee1275/ofnet.c index 3bbb5c227..a9d16e7e0 100644 --- a/fs/ieee1275/ofnet.c +++ b/fs/ieee1275/ofnet.c @@ -56,7 +56,7 @@ grub_ofnet_open (const char *name, grub_disk_t disk) { - if (grub_strcmp (name, "network")) + if (grub_strcmp (name, "net")) return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "not a net disk"); disk->total_sectors = U64MAXSIZE; @@ -109,7 +109,7 @@ grub_ofnetfs_dir (grub_device_t device , int (*hook) (const char *filename, const struct grub_dirhook_info *info) __attribute((unused))) { - if(grub_strcmp (device->disk->name,"network")) + if(grub_strcmp (device->disk->name,"net")) { return grub_error (GRUB_ERR_BAD_FS, "not an net filesystem"); } @@ -140,7 +140,7 @@ grub_ofnetfs_open (struct grub_file *file , const char *name ) //grub_addr_t addr; if (name[0] == '/') name++; - if(grub_strcmp (file->device->disk->name,"network")) + if(grub_strcmp (file->device->disk->name,"net")) { return 1; @@ -161,80 +161,43 @@ grub_ofnetfs_open (struct grub_file *file , const char *name ) grub_netbuff_reserve (pack,80*1024); file_size = app_interface->app_prot->get_file_size(NULL,stack,pack,(char *) name); - for (found_addr = 0x800000; found_addr < + 2000 * 0x100000; found_addr += 0x100000) { -// grub_printf("trying to claim %d bytes at 0x%x\n",file_size,found_addr); if (grub_claimmap (found_addr , file_size) != -1) break; } -// grub_printf("Claimed %d bytes at 0x%x\n",file_size,found_addr); file->data = (void *) found_addr; -// grub_printf("file->data = 0x%x\n",(int)file->data); -// grub_printf("file_size = %d\n",file_size); -// grub_printf("OPEN\n"); + grub_netbuff_clear(pack); grub_netbuff_reserve (pack,80*1024); app_interface->app_prot->open (NULL,stack,pack,(char *) name); - do { - //if (app_interface->app_prot->recv (NULL,stack,pack) == GRUB_ERR_NONE) -// grub_printf("RECEIVE PACKET\n"); + do + { grub_netbuff_clear(pack); grub_netbuff_reserve (pack,80*1024); app_interface->app_prot->recv (NULL,stack,pack); if (grub_errno != GRUB_ERR_NONE) - return grub_errno; -// grub_printf("RECEIVED PACKET\n"); - // { -// grub_printf("payload_size= %d\n",pack->tail - pack->data); -// grub_printf("amount= %d\n",amount); -// grub_printf("file_size= %d\n",file_size); - datap = (char *)file->data + amount; - amount += (pack->tail - pack->data); -// grub_printf("datap = 0x%x\n",(int)datap ); - grub_memcpy(datap, pack->data, pack->tail - pack->data); -// grub_printf("SEND ACK\n"); - + goto error; + if ((pack->tail - pack->data)) + { + // file->data = grub_realloc(file->data,amount + pack->tail - pack->data); + datap = (char *)file->data + amount; + amount += (pack->tail - pack->data); + grub_memcpy(datap , pack->data, pack->tail - pack->data); + } grub_netbuff_clear(pack); grub_netbuff_reserve (pack,80*1024); app_interface->app_prot->send_ack (NULL,stack,pack); if (grub_errno != GRUB_ERR_NONE) - return grub_errno; - -// grub_printf("SENT ACK\n"); - //} - // file->data = grub_realloc(file->data,amount); + goto error; }while (amount < file_size); -// grub_printf("transfer complete\n"); - file->size = file_size; - -// grub_netbuff_free(pack); - /*Start ARP header*/ - // arp.arpr.hwtype = 0x1; /* hardware type (must be ARPHRD_ETHER) */ - // arp.arpr.protocol = 0x0800; /* protocol type (must be ETH_P_IP) */ - // arp.arpr.hwlen = 0x6; /* hardware address length (must be 6) */ - // arp.arpr.protolen = 0x4; /* protocol address length (must be 4) */ - // arp.arpr.opcode = 0x1; /* ARP opcode */ - - - /*arp.arpr.shwaddr[0] =0x0a ; - arp.arpr.shwaddr[1] =0x11 ; - arp.arpr.shwaddr[2] =0xbd ; - arp.arpr.shwaddr[3] =0xe3 ; - arp.arpr.shwaddr[4] =0xe3 ; - arp.arpr.shwaddr[5] =0x04 ; - arp.arpr.sipaddr = dhcp_pckt -> yiaddr; */ /* sender's IP address */ - /*arp.arpr.thwaddr[0] =0; - arp.arpr.thwaddr[1] =0; - arp.arpr.thwaddr[2] =0; - arp.arpr.thwaddr[3] =0; - arp.arpr.thwaddr[4] =0; - arp.arpr.thwaddr[5] =0; - arp.arpr.tipaddr = dhcp_pckt -> siaddr; */ /* target's IP address */ - /*END ARP header */ + file->size = file_size; + + error: + grub_netbuff_free(pack); return grub_errno; } diff --git a/include/grub/net/type_net.h b/include/grub/net/type_net.h index 276c50bf9..a1717d6a7 100644 --- a/include/grub/net/type_net.h +++ b/include/grub/net/type_net.h @@ -5,6 +5,7 @@ #define UDP_PCKT 0x11 #define IP_PCKT 0x0800 +#define TIMEOUT_TIME_MS 3*1000 typedef enum { GRUB_NET_TFTP_ID, diff --git a/net/ethernet.c b/net/ethernet.c index a4bdbff5b..2bcb8107d 100644 --- a/net/ethernet.c +++ b/net/ethernet.c @@ -7,6 +7,7 @@ #include #include #include +#include static grub_err_t send_ethernet_packet (struct grub_net_network_layer_interface *inf __attribute__ ((unused)), @@ -42,6 +43,8 @@ recv_ethernet_packet (struct grub_net_network_layer_interface *inf __attribute__ struct grub_net_network_link_interface *net_link_inf __attribute__ ((unused)) ,struct grub_net_buff *nb) { struct etherhdr *eth; + grub_uint64_t start_time, current_time; + start_time = grub_get_time_ms(); while (1) { get_card_packet (nb); @@ -59,6 +62,9 @@ recv_ethernet_packet (struct grub_net_network_layer_interface *inf __attribute__ grub_netbuff_pull(nb,sizeof(*eth)); return 0; } + current_time = grub_get_time_ms(); + if (current_time - start_time > TIMEOUT_TIME_MS) + return grub_error (GRUB_ERR_TIMEOUT, "Time out."); } /* - get ethernet header - verify if the next layer is the desired one. diff --git a/net/ieee1275/interface.c b/net/ieee1275/interface.c index 1100ee85d..be9810fb2 100644 --- a/net/ieee1275/interface.c +++ b/net/ieee1275/interface.c @@ -29,9 +29,7 @@ int send_card_buffer (struct grub_net_buff *pack) { int actual; - //grub_printf("packet size transmited: %d\n",pack->tail - pack->data); grub_ieee1275_write (handle,pack->data,pack->tail - pack->data,&actual); -// grub_printf("actual transmited %d\n",actual); return actual; } @@ -50,18 +48,11 @@ int get_card_packet (struct grub_net_buff *pack __attribute__ ((unused))) do { grub_ieee1275_read (handle,datap,sizeof (*eth),&actual); - // if (actual <= 0) - // grub_millisleep(10); }while (actual <= 0); eth = (struct etherhdr *) datap; datap += sizeof(*eth); - // grub_printf("ethernet eth->dst %x:%x:%x:%x:%x:%x\n",eth->dst[0], - // eth->dst[1],eth->dst[2],eth->dst[3],eth->dst[4],eth->dst[5]); - // grub_printf("ethernet eth->src %x:%x:%x:%x:%x:%x\n",eth->src[0],eth->src[1], - // eth->src[2],eth->src[3],eth->src[4],eth->src[5]); -// grub_printf ("eth.type 0x%x\n",eth->type); switch (eth->type) { @@ -77,10 +68,6 @@ int get_card_packet (struct grub_net_buff *pack __attribute__ ((unused))) iph = (struct iphdr *) datap; datap += sizeof(*iph); - // grub_printf("ip.src 0x%x\n",iph->src); - // grub_printf("ip.dst 0x%x\n",iph->dest); - // grub_printf("ip.len 0x%x\n",iph->len); - // grub_printf("ip.protocol 0x%x\n",iph->protocol); grub_ieee1275_read (handle,datap,iph->len - sizeof (*iph),&actual); @@ -89,11 +76,8 @@ int get_card_packet (struct grub_net_buff *pack __attribute__ ((unused))) break; case 0x86DD: - grub_printf("!!!!!!!!!!!!!!!!!IPV6 packet received!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n"); grub_ieee1275_read (handle,datap,sizeof (*ip6h),&actual); ip6h = (struct ip6hdr *) datap; - grub_printf("ip6hdr->payload_len = %x\n",ip6h->payload_len); - grub_printf("ip6hdr->nexthdr = %x\n",ip6h->nexthdr); datap += sizeof(*ip6h); grub_ieee1275_read (handle,datap,ip6h->payload_len - sizeof (*ip6h),&actual); diff --git a/net/ip.c b/net/ip.c index 5eaa74f90..044cfde6b 100644 --- a/net/ip.c +++ b/net/ip.c @@ -7,6 +7,7 @@ #include #include #include +#include struct grub_net_protocol *grub_ipv4_prot; @@ -65,6 +66,8 @@ recv_ip_packet (struct grub_net_network_layer_interface *inf, { struct iphdr *iph; + grub_uint64_t start_time, current_time; + start_time = grub_get_time_ms(); while (1) { trans_net_inf->inner_layer->link_prot->recv(inf,trans_net_inf->inner_layer,nb); @@ -74,6 +77,10 @@ recv_ip_packet (struct grub_net_network_layer_interface *inf, grub_netbuff_pull(nb,sizeof(*iph)); return 0; } + + current_time = grub_get_time_ms(); + if (current_time - start_time > TIMEOUT_TIME_MS) + return grub_error (GRUB_ERR_TIMEOUT, "Time out."); } /* grub_printf("ip.src 0x%x\n",iph->src); grub_printf("ip.dst 0x%x\n",iph->dest); diff --git a/net/netbuff.c b/net/netbuff.c index 136d55bc4..ce52233b6 100644 --- a/net/netbuff.c +++ b/net/netbuff.c @@ -41,11 +41,6 @@ grub_err_t grub_netbuff_unput (struct grub_net_buff *net_buff ,grub_size_t len) grub_err_t grub_netbuff_push (struct grub_net_buff *net_buff ,grub_size_t len) { net_buff->data -= len; -/* grub_printf("push len =%d\n",len); - grub_printf("pack->head =%x\n",(unsigned int)net_buff->head); - grub_printf("pack->data =%x\n",(unsigned int)net_buff->data); - grub_printf("pack->tail =%x\n",(unsigned int)net_buff->tail); - grub_printf("pack->end =%x\n",(unsigned int)net_buff->end);*/ if (net_buff->data < net_buff->head) return grub_error (GRUB_ERR_OUT_OF_RANGE, "push out of the packet range."); return GRUB_ERR_NONE; @@ -87,7 +82,7 @@ struct grub_net_buff *grub_netbuff_alloc ( grub_size_t len ) grub_err_t grub_netbuff_free (struct grub_net_buff *net_buff) { - grub_free (net_buff); + grub_free (net_buff->head); return 0; } diff --git a/net/tftp.c b/net/tftp.c index 8e89ed1f4..dff0f134c 100644 --- a/net/tftp.c +++ b/net/tftp.c @@ -70,7 +70,7 @@ tftp_open (struct grub_net_network_layer_interface *inf __attribute((unused)), grub_netbuff_push (nb,sizeof (*tftph)); udp_interf = (struct udp_interf *) app_interface->data; - udp_interf->src = TFTP_CLIENT_PORT + rrq_count++; + udp_interf->src = TFTP_CLIENT_PORT;// + rrq_count++; udp_interf->dst = TFTP_SERVER_PORT; tftph = (struct tftphdr *) nb->data; @@ -112,6 +112,8 @@ tftp_open (struct grub_net_network_layer_interface *inf __attribute((unused)), app_interface->trans_prot->send (inf,protstack->interface,nb); /*Receive OACK*/ + grub_netbuff_clear (nb); + grub_netbuff_reserve (nb,80*1024); return app_interface->app_prot->recv(inf,protstack,nb); } @@ -211,6 +213,8 @@ static int tftp_file_size (struct grub_net_network_layer_interface* inf , { tftp_open (inf, protocol_stack,nb, filename); + grub_netbuff_clear (nb); + grub_netbuff_reserve (nb,80*1024); tftp_send_err (inf, protocol_stack,nb,"Abort transference.",0); return tftp_file.size; diff --git a/net/udp.c b/net/udp.c index fb81aef93..0321fd58a 100644 --- a/net/udp.c +++ b/net/udp.c @@ -4,6 +4,7 @@ #include #include #include +#include static grub_err_t send_udp_packet (struct grub_net_network_layer_interface *inf, @@ -35,7 +36,8 @@ receive_udp_packet (struct grub_net_network_layer_interface *inf, struct udphdr *udph; struct udp_interf *udp_interf; udp_interf = (struct udp_interf *) app_trans_inf->data; - + grub_uint64_t start_time, current_time; + start_time = grub_get_time_ms(); while(1) { app_trans_inf->inner_layer->net_prot->recv(inf,app_trans_inf->inner_layer,nb); @@ -62,6 +64,10 @@ receive_udp_packet (struct grub_net_network_layer_interface *inf, return 0; } + current_time = grub_get_time_ms(); + if (current_time - start_time > TIMEOUT_TIME_MS) + return grub_error (GRUB_ERR_TIMEOUT, "Time out."); + } } From f8795693f1c3caa557b8658ac3d8661b1f84b739 Mon Sep 17 00:00:00 2001 From: Paulo de Rezende Pinatti Date: Tue, 13 Jul 2010 11:22:35 -0300 Subject: [PATCH 024/869] Added support to netdisk specified in the form (net,protocol,server_ip,username,password) an to list its information with command ls. * fs/ieee1275/ofnet.c (grub_ofnet_open): parse parameters to determine netdisk data * fs/ieee1275/ofnet.c (grub_ofnet_close): dealloc netdisk data * include/grub/disk.h: added struct grub_netdisk_data * include/grub/ieee1275/ofnet.h: added newline * kern/disk.c (grub_disk_open): ignore partition check for netdisk * normal/misc.c (grub_normal_print_device_info): added support to list netdisk information --- fs/ieee1275/ofnet.c | 159 ++++++++++++++++++++++++++++++++-- include/grub/disk.h | 17 ++++ include/grub/ieee1275/ofnet.h | 1 + kern/disk.c | 4 +- normal/misc.c | 39 +++++++++ 5 files changed, 213 insertions(+), 7 deletions(-) diff --git a/fs/ieee1275/ofnet.c b/fs/ieee1275/ofnet.c index a9d16e7e0..9010317ba 100644 --- a/fs/ieee1275/ofnet.c +++ b/fs/ieee1275/ofnet.c @@ -42,6 +42,85 @@ //static grub_ieee1275_ihandle_t handle = 0; +static const char * +find_sep (const char *name) +{ + const char *p = name; + char c = *p; + + if (c == '\0') + return NULL; + + do + { + if (c == '\\' && *p == ',') + p++; + else if (c == ',') + return p - 1; + } while ((c = *p++) != '\0'); + return p - 1; +} + +static grub_err_t +retrieve_field(const char *src, char **field, const char **rest) +{ + const char *p; + grub_size_t len; + + p = find_sep(src); + if (! p) + { + *field = NULL; + *rest = src; + return 0; + } + + len = p - src; + *field = grub_malloc (len + 1); + if (! *field) + { + return grub_error (GRUB_ERR_OUT_OF_MEMORY, "fail to alloc memory"); + } + + grub_memcpy (*field, src, len); + (*field)[len] = '\0'; + + if (*p == '\0') + *rest = p; + else + *rest = p + 1; + return 0; +} + +static grub_err_t +parse_ip (const char *val, grub_uint32_t *ip, const char **rest) +{ + grub_uint32_t newip = 0; + unsigned long t; + int i; + const char *ptr = val; + + for (i = 0; i < 4; i++) + { + t = grub_strtoul (ptr, (char **) &ptr, 0); + if (grub_errno) + return grub_errno; + if (t & ~0xff) + return grub_error (GRUB_ERR_OUT_OF_RANGE, "Invalid IP."); + newip >>= 8; + newip |= (t << 24); + if (i != 3 && *ptr != '.') + return grub_error (GRUB_ERR_OUT_OF_RANGE, "Invalid IP."); + ptr++; + } + ptr = ptr - 1; + if ( *ptr != '\0' && *ptr != ',') + return grub_error (GRUB_ERR_OUT_OF_RANGE, "Invalid IP."); + *ip = newip; + if (rest) + *rest = ptr; + return 0; +} static int grub_ofnet_iterate (int (*hook) (const char *name)) @@ -54,23 +133,93 @@ grub_ofnet_iterate (int (*hook) (const char *name)) static grub_err_t grub_ofnet_open (const char *name, grub_disk_t disk) { - + grub_err_t err; + const char *p1, *p2; + char *user = NULL, *pwd = NULL; + grub_netdisk_data_t data; + grub_netdisk_protocol_t proto; + grub_uint32_t server_ip = 0; if (grub_strcmp (name, "net")) - return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "not a net disk"); + return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "not a net disk"); - disk->total_sectors = U64MAXSIZE; + p1 = find_sep(disk->name); + if (! p1 || *p1 == '\0') + return grub_error (GRUB_ERR_BAD_ARGUMENT, "arguments missing"); + p1++; + + // parse protocol + p2 = find_sep(p1); + if (! p2) + return grub_error (GRUB_ERR_BAD_ARGUMENT, "no protocol specified"); + if ((p2 - p1 == 4) && (! grub_strncasecmp(p1, "tftp", p2 - p1))) + proto = GRUB_NETDISK_PROTOCOL_TFTP; + else + return grub_error (GRUB_ERR_BAD_ARGUMENT, "invalid protocol specified"); + + // parse server ip + if ( *p2 == '\0') + return grub_error (GRUB_ERR_BAD_ARGUMENT, "no server ip specified"); + p1 = p2 + 1; + err = parse_ip(p1, &server_ip, &p2); + if (err) + return err; + + // parse username (optional) + if ( *p2 == ',') + p2++; + err = retrieve_field(p2, &user, &p1); + if (err) + return err; + if (user) + { + // parse password (optional) + err = retrieve_field(p1, &pwd, &p2); + if (err) + { + grub_free(user); + return err; + } + } + + if (! disk->data) + { + data = grub_malloc (sizeof(*data)); + disk->data = data; + } + else + { + data = disk->data; + if (data->username) + grub_free(data->username); + if (data->password) + grub_free(data->password); + } + data->protocol = proto; + data->server_ip = server_ip; + data->username = user; + data->password = pwd; + + disk->total_sectors = 0; disk->id = (unsigned long) "net"; disk->has_partitions = 0; - disk->data = 0; return GRUB_ERR_NONE; } static void -grub_ofnet_close (grub_disk_t disk __attribute((unused))) +grub_ofnet_close (grub_disk_t disk) { + grub_netdisk_data_t data = disk->data; + if (data) + { + if (data->username) + grub_free(data->username); + if (data->password) + grub_free(data->password); + grub_free(data); + } } static grub_err_t diff --git a/include/grub/disk.h b/include/grub/disk.h index 1bdfb639b..dc8bc5018 100644 --- a/include/grub/disk.h +++ b/include/grub/disk.h @@ -119,6 +119,23 @@ struct grub_disk }; typedef struct grub_disk *grub_disk_t; +/* Net Disk */ +enum grub_netdisk_protocol +{ + GRUB_NETDISK_PROTOCOL_TFTP +}; +typedef enum grub_netdisk_protocol grub_netdisk_protocol_t; + +struct grub_netdisk_data +{ + grub_netdisk_protocol_t protocol; + grub_uint32_t server_ip; + grub_uint32_t port; + char *username; + char *password; +}; +typedef struct grub_netdisk_data *grub_netdisk_data_t; + #ifdef GRUB_UTIL struct grub_disk_memberlist { diff --git a/include/grub/ieee1275/ofnet.h b/include/grub/ieee1275/ofnet.h index 7daadf61d..a26c22235 100644 --- a/include/grub/ieee1275/ofnet.h +++ b/include/grub/ieee1275/ofnet.h @@ -25,6 +25,7 @@ extern void grub_ofnet_init(void); extern void grub_ofnet_fini(void); + /* struct grub_net; diff --git a/kern/disk.c b/kern/disk.c index ccd5f200f..051e59aca 100644 --- a/kern/disk.c +++ b/kern/disk.c @@ -281,7 +281,7 @@ grub_disk_open (const char *name) goto fail; } - if (p && ! disk->has_partitions) + if (p && ! disk->has_partitions && grub_strcmp (raw, "net")) { grub_error (GRUB_ERR_BAD_DEVICE, "no partition on this disk"); goto fail; @@ -289,7 +289,7 @@ grub_disk_open (const char *name) disk->dev = dev; - if (p) + if (p && grub_strcmp (raw, "net")) { disk->partition = grub_partition_probe (disk, p + 1); if (! disk->partition) diff --git a/normal/misc.c b/normal/misc.c index 17ba372ce..d53fe711c 100644 --- a/normal/misc.c +++ b/normal/misc.c @@ -32,8 +32,47 @@ grub_err_t grub_normal_print_device_info (const char *name) { grub_device_t dev; + grub_netdisk_data_t data; char *p; + if ((! grub_strcmp(name, "net")) || (! grub_strncmp(name, "net,", 4))) + { + grub_printf_ (N_("Device network:")); + grub_putchar (' '); + + dev = grub_device_open (name); + if (! dev || ! dev->disk || ! dev->disk->data) + grub_printf ("%s", _("Network information not available")); + else + { + data = dev->disk->data; + grub_putchar ('\n'); + grub_putchar ('\t'); + if (data->protocol == GRUB_NETDISK_PROTOCOL_TFTP) + grub_printf_(N_("Protocol: %s"), "TFTP"); + else + grub_printf_(N_("Protocol: %s"), "Unknown"); + grub_putchar ('\n'); + grub_putchar ('\t'); + grub_printf_(N_("Server IP: %d.%d.%d.%d"), data->server_ip & 0xff, data->server_ip >> 8 & 0xff, data->server_ip >> 16 & 0xff, data->server_ip >> 24 & 0xff); + if (data->username) + { + grub_putchar ('\n'); + grub_putchar ('\t'); + grub_printf_(N_("Username: %s"), data->username); + if (data->password) + { + grub_putchar ('\n'); + grub_putchar ('\t'); + grub_printf_(N_("Password: %s"), data->password); + } + } + } + grub_putchar ('\n'); + + return GRUB_ERR_NONE; + } + p = grub_strchr (name, ','); if (p) { From 7e8b77c03359b2537dee39ded103b2f126157dd8 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 19 Jul 2010 21:22:54 +0200 Subject: [PATCH 025/869] AHCI skeleton --- conf/i386.rmk | 5 + disk/ahci.c | 311 ++++++++++++++++++++++++++++++++++++++++++++ include/grub/scsi.h | 3 +- 3 files changed, 318 insertions(+), 1 deletion(-) create mode 100644 disk/ahci.c diff --git a/conf/i386.rmk b/conf/i386.rmk index b1df584a6..54edb468b 100644 --- a/conf/i386.rmk +++ b/conf/i386.rmk @@ -36,6 +36,11 @@ ata_mod_SOURCES = disk/ata.c ata_mod_CFLAGS = $(COMMON_CFLAGS) ata_mod_LDFLAGS = $(COMMON_LDFLAGS) +pkglib_MODULES += ahci.mod +ahci_mod_SOURCES = disk/ahci.c +ahci_mod_CFLAGS = $(COMMON_CFLAGS) +ahci_mod_LDFLAGS = $(COMMON_LDFLAGS) + # For setpci.mod pkglib_MODULES += setpci.mod setpci_mod_SOURCES = commands/setpci.c diff --git a/disk/ahci.c b/disk/ahci.c new file mode 100644 index 000000000..1372fd651 --- /dev/null +++ b/disk/ahci.c @@ -0,0 +1,311 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 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 . + */ + +#include +#include +#include +#include +#include +#include + +struct grub_ahci_cmd_head +{ + grub_uint32_t unused[8]; +}; + +struct grub_ahci_hba_port +{ + grub_uint64_t command_list_base; + grub_uint32_t unused[12]; + grub_uint32_t sata_active; + grub_uint32_t command_issue; + grub_uint32_t unused[16]; +}; + +struct grub_ahci_hba +{ + grub_uint32_t cap; +#define GRUB_AHCI_HBA_CAP_MASK 0x1f + grub_uint32_t global_control; +#define GRUB_AHCI_HBA_GLOBAL_CONTROL_AHCI_EN 0x80000000 + grub_uint32_t ports_implemented; + grub_uint32_t unused1[7]; + grub_uint32_t bios_handoff; +#define GRUB_AHCI_BIOS_HANDOFF_BIOS_OWNED 1 +#define GRUB_AHCI_BIOS_HANDOFF_OS_OWNED 2 +#define GRUB_AHCI_BIOS_HANDOFF_OS_OWNERSHIP_CHANGED 8 +#define GRUB_AHCI_BIOS_HANDOFF_RWC 8 + grub_uint32_t unused2[53]; + struct grub_ahci_hba_port ports[32]; +}; + +struct grub_ahci_device +{ + struct grub_ahci_device *next; + volatile struct grub_ahci_hba *hba; + int port; + int num; + struct grub_pci_dma_chunk *command_list_chunk; + volatile struct grub_ahci_cmd_head *command_list; +}; + +static struct grub_ahci_device *grub_ahci_devices; +static int numdevs; + +static int NESTED_FUNC_ATTR +grub_ahci_pciinit (grub_pci_device_t dev, + grub_pci_id_t pciid __attribute__ ((unused))) +{ + grub_pci_address_t addr; + grub_uint32_t class; + grub_uint32_t bar; + int nports; + volatile struct grub_ahci_hba *hba; + + /* Read class. */ + addr = grub_pci_make_address (dev, GRUB_PCI_REG_CLASS); + class = grub_pci_read (addr); + + /* Check if this class ID matches that of a PCI IDE Controller. */ + if (class >> 8 != 0x010601) + return 0; + + addr = grub_pci_make_address (dev, GRUB_PCI_REG_ADDRESS_REG5); + bar = grub_pci_read (addr); + + if (bar & (GRUB_PCI_ADDR_SPACE_MASK | GRUB_PCI_ADDR_MEM_TYPE_MASK + | GRUB_PCI_ADDR_MEM_PREFETCH) + != (GRUB_PCI_ADDR_SPACE_MEMORY | GRUB_PCI_ADDR_MEM_TYPE_32)) + return 0; + + hba = grub_pci_device_map_range (dev, bar & GRUB_PCI_ADDR_MEM_MASK, + sizeof (hba)); + + hba->global_control |= GRUB_AHCI_HBA_GLOBAL_CONTROL_AHCI_EN; + + nports = hba->cap & GRUB_AHCI_HBA_CAP_MASK; + + if (! (hba->bios_handoff & GRUB_AHCI_BIOS_HANDOFF_OS_OWNED)) + { + grub_uint64_t endtime; + + grub_dprintf ("ahci", "Requesting AHCI ownership\n"); + hba->bios_handoff = (hba->bios_handoff & ~GRUB_AHCI_BIOS_HANDOFF_RWC) + | GRUB_AHCI_BIOS_HANDOFF_OS_OWNED; + grub_dprintf ("ahci", "Waiting for BIOS to give up ownership\n"); + endtime = grub_get_time_ms () + 1000; + while ((hba->bios_handoff & GRUB_AHCI_BIOS_HANDOFF_BIOS_OWNED) + && grub_get_time_ms () < endtime); + if (hba->bios_handoff & GRUB_AHCI_BIOS_HANDOFF_BIOS_OWNED) + { + grub_dprintf ("ahci", "Forcibly taking ownership\n"); + hba->bios_handoff = GRUB_AHCI_BIOS_HANDOFF_OS_OWNED; + hba->bios_handoff |= GRUB_AHCI_BIOS_HANDOFF_OS_OWNERSHIP_CHANGED; + } + else + grub_dprintf ("ahci", "AHCI ownership obtained\n"); + } + else + grub_dprintf ("ahci", "AHCI is already in OS mode\n"); + + for (i = 0; i < nports; i++) + { + struct grub_ahci_device *adev; + struct grub_pci_dma_chunk *command_list; + + if (!(hba->ports_implemented & (1 << i))) + continue; + + command_list = grub_memalign_dma32 (1024, + sizeof (struct grub_ahci_cmd_head)); + if (!command_list) + return 1; + + adev = grub_malloc (sizeof (*adev)); + if (!adev) + { + grub_dma_free (command_list); + return 1; + } + + adev->hba = hba; + adev->port = i; + adev->num = numdevs++; + adev->command_list_chunk = command_list; + adev->command_list = grub_dma_get_virt (command_list); + adev->hba->ports[i].command_list_base = grub_dma_get_phys (command_list); + grub_list_push (GRUB_AS_LIST_P (&grub_ahci_devices), + GRUB_AS_LIST (adev)); + } + + return 0; +} + +static grub_err_t +grub_ahci_initialize (void) +{ + grub_pci_iterate (grub_ahci_pciinit); + return grub_errno; +} + + + + +static int +grub_ahci_iterate (int (*hook) (int bus, int luns)) +{ + struct grub_ahci_device *dev; + + FOR_LIST_ELEMENTS(dev, grub_ahci_devices) + if (hook (dev->num, 1)) + return 1; + + return 0; +} + +#if 0 +static int +find_free_cmd_slot (struct grub_ahci_device *dev) +{ + int i; + for (i = 0; i < 32; i++) + { + if (dev->hda->ports[dev->port].command_issue & (1 << i)) + continue; + if (dev->hda->ports[dev->port].sata_active & (1 << i)) + continue; + return i; + } + return -1; +} +#endif + +static grub_err_t +grub_ahci_packet (struct grub_ahci_device *dev, char *packet, + grub_size_t size) +{ + + return GRUB_ERR_NONE; +} + +static grub_err_t +grub_ahci_read (struct grub_scsi *scsi, + grub_size_t cmdsize __attribute__((unused)), + char *cmd, grub_size_t size, char *buf) +{ + struct grub_ahci_device *dev = (struct grub_ahci_device *) scsi->data; + + grub_dprintf("ahci", "grub_ahci_read (size=%llu)\n", (unsigned long long) size); + + if (grub_atapi_packet (dev, cmd, size)) + return grub_errno; + + grub_size_t nread = 0; + while (nread < size) + { + /* Wait for !BSY, DRQ, I/O, !C/D. */ + if (grub_atapi_wait_drq (dev, GRUB_ATAPI_IREASON_DATA_IN, GRUB_ATA_TOUT_DATA)) + return grub_errno; + + /* Get byte count for this DRQ assertion. */ + unsigned cnt = grub_ata_regget (dev, GRUB_ATAPI_REG_CNTHIGH) << 8 + | grub_ata_regget (dev, GRUB_ATAPI_REG_CNTLOW); + grub_dprintf("ata", "DRQ count=%u\n", cnt); + + /* Count of last transfer may be uneven. */ + if (! (0 < cnt && cnt <= size - nread && (! (cnt & 1) || cnt == size - nread))) + return grub_error (GRUB_ERR_READ_ERROR, "invalid ATAPI transfer count"); + + /* Read the data. */ + grub_ata_pio_read (dev, buf + nread, cnt); + + if (cnt & 1) + buf[nread + cnt - 1] = (char) grub_le_to_cpu16 (grub_inw (dev->ioaddress + GRUB_ATA_REG_DATA)); + + nread += cnt; + } + + return GRUB_ERR_NONE; +} + +static grub_err_t +grub_ahci_write (struct grub_scsi *scsi __attribute__((unused)), + grub_size_t cmdsize __attribute__((unused)), + char *cmd __attribute__((unused)), + grub_size_t size __attribute__((unused)), + char *buf __attribute__((unused))) +{ + // XXX: scsi.mod does not use write yet. + return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, "AHCI write not implemented"); +} + +static grub_err_t +grub_ahci_open (int devnum, struct grub_scsi *scsi) +{ + struct grub_ahci_device *dev; + + FOR_LIST_ELEMENTS(dev, grub_ahci_devices) + { + if (dev->num == devnum) + break; + } + + grub_dprintf ("ata", "opening AHCI dev `ahci%d'\n", devnum); + + if (! dev) + return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "no such AHCI device"); + + scsi->data = dev; + + return GRUB_ERR_NONE; +} + + +static struct grub_scsi_dev grub_ahci_dev = + { + .name = "ahci", + .id = GRUB_SCSI_SUBSYSTEM_AHCI, + .iterate = grub_ahci_iterate, + .open = grub_ahci_open, + .read = grub_ahci_read, + .write = grub_ahci_write + }; + + + +GRUB_MOD_INIT(ahci) +{ + /* To prevent two drivers operating on the same disks. */ + grub_disk_firmware_is_tainted = 1; + if (grub_disk_firmware_fini) + { + grub_disk_firmware_fini (); + grub_disk_firmware_fini = NULL; + } + + /* AHCI initialization. */ + grub_ahci_initialize (); + + /* AHCI devices are handled by scsi.mod. */ + grub_scsi_dev_register (&grub_ahci_dev); +} + +GRUB_MOD_FINI(ahci) +{ + grub_scsi_dev_unregister (&grub_ahci_dev); +} diff --git a/include/grub/scsi.h b/include/grub/scsi.h index b3c60f3e8..289cd8e4a 100644 --- a/include/grub/scsi.h +++ b/include/grub/scsi.h @@ -29,7 +29,8 @@ struct grub_scsi; enum { GRUB_SCSI_SUBSYSTEM_USBMS, - GRUB_SCSI_SUBSYSTEM_ATAPI + GRUB_SCSI_SUBSYSTEM_ATAPI, + GRUB_SCSI_SUBSYSTEM_AHCI }; #define GRUB_SCSI_ID_SUBSYSTEM_SHIFT 24 From 818a356eb196a2c2ca5af7d580b9920c8564ebcc Mon Sep 17 00:00:00 2001 From: Paulo de Rezende Pinatti Date: Thu, 29 Jul 2010 16:36:17 -0300 Subject: [PATCH 026/869] Fixed get_card_packet to correctly read data from network card into buffer. * net/ieee1275/interface.c (get_card_packet): read data regardless of ethernet header --- net/ieee1275/interface.c | 54 +++------------------------------------- 1 file changed, 4 insertions(+), 50 deletions(-) diff --git a/net/ieee1275/interface.c b/net/ieee1275/interface.c index be9810fb2..342044041 100644 --- a/net/ieee1275/interface.c +++ b/net/ieee1275/interface.c @@ -1,9 +1,4 @@ #include -#include -#include -#include -#include -#include #include #include @@ -37,56 +32,15 @@ int send_card_buffer (struct grub_net_buff *pack) int get_card_packet (struct grub_net_buff *pack __attribute__ ((unused))) { - int actual; - char *datap; - struct iphdr *iph; - struct etherhdr *eth; - struct arphdr *arph; - struct ip6hdr *ip6h; + int actual, rc; pack->data = pack->tail = pack->head; - datap = pack->data; do { - grub_ieee1275_read (handle,datap,sizeof (*eth),&actual); + rc = grub_ieee1275_read (handle,pack->data,1500,&actual); - }while (actual <= 0); - eth = (struct etherhdr *) datap; - datap += sizeof(*eth); - + }while (actual <= 0 || rc < 0); + grub_netbuff_put (pack, actual); - switch (eth->type) - { - case 0x806: - - grub_ieee1275_read (handle,datap,sizeof (*arph),&actual); - arph = (struct arphdr *) datap; - - grub_netbuff_put (pack,sizeof (*eth) + sizeof (*arph)); - break; - case 0x800: - grub_ieee1275_read (handle,datap,sizeof (*iph),&actual); - iph = (struct iphdr *) datap; - datap += sizeof(*iph); - - - grub_ieee1275_read (handle,datap,iph->len - sizeof (*iph),&actual); - - - grub_netbuff_put (pack,sizeof (*eth) + iph->len); - break; - - case 0x86DD: - grub_ieee1275_read (handle,datap,sizeof (*ip6h),&actual); - ip6h = (struct ip6hdr *) datap; - - datap += sizeof(*ip6h); - grub_ieee1275_read (handle,datap,ip6h->payload_len - sizeof (*ip6h),&actual); - break; - - default: - grub_printf("Unknow packet %x\n",eth->type); - break; - } // grub_printf("packsize %d\n",pack->tail - pack->data); return 0;// sizeof (eth) + iph.len; } From 11d1ea5df607d8d2e6463f482f24e92c9cb609be Mon Sep 17 00:00:00 2001 From: "Manoel R. Abranches" Date: Thu, 29 Jul 2010 17:52:54 -0300 Subject: [PATCH 027/869] Use server and client IP from the bootp packet. --- net/ip.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/net/ip.c b/net/ip.c index 044cfde6b..65b0f2b70 100644 --- a/net/ip.c +++ b/net/ip.c @@ -72,7 +72,9 @@ recv_ip_packet (struct grub_net_network_layer_interface *inf, { trans_net_inf->inner_layer->link_prot->recv(inf,trans_net_inf->inner_layer,nb); iph = (struct iphdr *) nb->data; - if (iph->dest == 0x0908eaaa && iph->src == 0x0908ea92 && iph->protocol == 0x11) + if (iph->protocol == 0x11 && + iph->dest == (grub_uint32_t) bootp_pckt -> yiaddr && + iph->src == (grub_uint32_t) bootp_pckt -> siaddr ) { grub_netbuff_pull(nb,sizeof(*iph)); return 0; @@ -82,11 +84,11 @@ recv_ip_packet (struct grub_net_network_layer_interface *inf, if (current_time - start_time > TIMEOUT_TIME_MS) return grub_error (GRUB_ERR_TIMEOUT, "Time out."); } -/* grub_printf("ip.src 0x%x\n",iph->src); - grub_printf("ip.dst 0x%x\n",iph->dest); - grub_printf("ip.len 0x%x\n",iph->len); - grub_printf("ip.protocol 0x%x\n",iph->protocol); - */ +// grub_printf("ip.src 0x%x\n",iph->src); +// grub_printf("ip.dst 0x%x\n",iph->dest); +// grub_printf("ip.len 0x%x\n",iph->len); +// grub_printf("ip.protocol 0x%x\n",iph->protocol); + /* - get ip header - verify if is the next layer is correct -*/ From f89661762a82b0784965ca27d88473e704648cf2 Mon Sep 17 00:00:00 2001 From: "Manoel R. Abranches" Date: Thu, 29 Jul 2010 18:07:09 -0300 Subject: [PATCH 028/869] Only open the card in netboot. --- fs/ieee1275/ofnet.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/fs/ieee1275/ofnet.c b/fs/ieee1275/ofnet.c index 9010317ba..82b5235cc 100644 --- a/fs/ieee1275/ofnet.c +++ b/fs/ieee1275/ofnet.c @@ -141,6 +141,7 @@ grub_ofnet_open (const char *name, grub_disk_t disk) grub_uint32_t server_ip = 0; if (grub_strcmp (name, "net")) + return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "not a net disk"); p1 = find_sep(disk->name); @@ -258,7 +259,7 @@ grub_ofnetfs_dir (grub_device_t device , int (*hook) (const char *filename, const struct grub_dirhook_info *info) __attribute((unused))) { - if(grub_strcmp (device->disk->name,"net")) + if(grub_strncmp (device->disk->name,"net",3)) { return grub_error (GRUB_ERR_BAD_FS, "not an net filesystem"); } @@ -287,9 +288,10 @@ grub_ofnetfs_open (struct grub_file *file , const char *name ) { //void *buffer; //grub_addr_t addr; + if (name[0] == '/') name++; - if(grub_strcmp (file->device->disk->name,"net")) + if(grub_strncmp (file->device->disk->name,"net",3)) { return 1; @@ -311,15 +313,17 @@ grub_ofnetfs_open (struct grub_file *file , const char *name ) file_size = app_interface->app_prot->get_file_size(NULL,stack,pack,(char *) name); for (found_addr = 0x800000; found_addr < + 2000 * 0x100000; found_addr += 0x100000) - { - if (grub_claimmap (found_addr , file_size) != -1) - break; - } + { + if (grub_claimmap (found_addr , file_size) != -1) + break; + } file->data = (void *) found_addr; grub_netbuff_clear(pack); grub_netbuff_reserve (pack,80*1024); app_interface->app_prot->open (NULL,stack,pack,(char *) name); + if (grub_errno != GRUB_ERR_NONE) + goto error; do { @@ -401,7 +405,7 @@ grub_ofnet_detect (void) } devalias = grub_ieee1275_get_aliasdevname (bootpath); - if (grub_strcmp(devalias ,"network")) + if (grub_strncmp(devalias ,"net",3)) return 0; grub_net = grub_malloc (sizeof *grub_net ); @@ -455,8 +459,8 @@ grub_ofnet_init(void) grub_get_netinfo (grub_net, bootp_pckt ); grub_disk_dev_register (&grub_ofnet_dev); grub_fs_register (&grub_ofnetfs_fs); + card_open (); } - card_open (); } void grub_ofnet_fini(void) From 17ef14c91669b1c7a8c32f106148c142a488a9c4 Mon Sep 17 00:00:00 2001 From: "Manoel R. Abranches" Date: Thu, 29 Jul 2010 18:13:00 -0300 Subject: [PATCH 029/869] Process errot packets in TFTP reply. --- net/tftp.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/net/tftp.c b/net/tftp.c index dff0f134c..0fb43105d 100644 --- a/net/tftp.c +++ b/net/tftp.c @@ -140,7 +140,7 @@ tftp_receive (struct grub_net_network_layer_interface *inf __attribute((unused)) } //buff_clean - nb->data = nb->tail; + grub_netbuff_clear(nb); // grub_printf("OACK---------------------------------------------------------\n"); //grub_printf("block_size=%d\n",tftp_file.block_size); // grub_printf("file_size=%d\n",tftp_file.size); @@ -155,7 +155,8 @@ tftp_receive (struct grub_net_network_layer_interface *inf __attribute((unused)) grub_netbuff_clear(nb); break; case TFTP_ERROR: - nb->data = nb->tail; + grub_netbuff_clear (nb); + return grub_error (GRUB_ERR_ACCESS_DENIED, (char *)tftph->u.err.errmsg); break; } From 7c978f06900fc81e185bc0c8977f935c0185927c Mon Sep 17 00:00:00 2001 From: "Manoel R. Abranches" Date: Thu, 29 Jul 2010 18:17:01 -0300 Subject: [PATCH 030/869] Implement the size field. --- include/grub/net/ethernet.h | 24 ++++++++++++-- net/ethernet.c | 65 ++++++++++++++++++++----------------- 2 files changed, 58 insertions(+), 31 deletions(-) diff --git a/include/grub/net/ethernet.h b/include/grub/net/ethernet.h index 46aa04f60..9043a5f02 100644 --- a/include/grub/net/ethernet.h +++ b/include/grub/net/ethernet.h @@ -1,11 +1,31 @@ #ifndef GRUB_NET_ETHERNET_HEADER #define GRUB_NET_ETHERNET_HEADER 1 #include -struct etherhdr { +#define LLCADDRMASK 0x7f + +struct etherhdr +{ grub_uint8_t dst[6]; grub_uint8_t src[6]; grub_uint16_t type; -} __attribute__ ((packed)) ; +} __attribute__ ((packed)); + +#define PCP (x) x & 0xe000 +#define CFI (x) x & 0x1000 +#define VID (x) x & 0x0fff + +struct llchdr +{ +grub_uint8_t dsap; +grub_uint8_t ssap; +grub_uint8_t ctrl; +} __attribute__ ((packed)); + +struct snaphdr +{ +grub_uint8_t oui[3]; +grub_uint16_t type; +} __attribute__ ((packed)); void ethernet_ini(void); void ethernet_fini(void); diff --git a/net/ethernet.c b/net/ethernet.c index 2bcb8107d..ab5992133 100644 --- a/net/ethernet.c +++ b/net/ethernet.c @@ -18,19 +18,13 @@ send_ethernet_packet (struct grub_net_network_layer_interface *inf __attribute__ grub_netbuff_push (nb,sizeof(*eth)); eth = (struct etherhdr *) nb->data; - eth->dst[0] =0x00; - eth->dst[1] =0x11; - eth->dst[2] =0x25; - eth->dst[3] =0xca; - eth->dst[4] =0x1f; - eth->dst[5] =0x01; - eth->src[0] =0x0a; - eth->src[1] =0x11; - eth->src[2] =0xbd; - eth->src[3] =0xe3; - eth->src[4] =0xe3; - eth->src[5] =0x04; - + eth->dst[0] = 0x00; + eth->dst[1] = 0x11; + eth->dst[2] = 0x25; + eth->dst[3] = 0xca; + eth->dst[4] = 0x1f; + eth->dst[5] = 0x01; + grub_memcpy (eth->src, bootp_pckt -> chaddr,6); eth->type = 0x0800; return send_card_buffer(nb); @@ -44,25 +38,38 @@ recv_ethernet_packet (struct grub_net_network_layer_interface *inf __attribute__ { struct etherhdr *eth; grub_uint64_t start_time, current_time; + struct llchdr *llch; + struct snaphdr *snaph; + grub_uint16_t type; start_time = grub_get_time_ms(); - while (1) - { - get_card_packet (nb); - eth = (struct etherhdr *) nb->data; + while (1) + { + get_card_packet (nb); + eth = (struct etherhdr *) nb->data; + type = eth->type; + grub_netbuff_pull(nb,sizeof (*eth)); + // grub_printf("ethernet type 58 %x\n",type); + // grub_printf("ethernet eth->type 58 %x\n",type); + if (eth->type <=1500) + { + llch = (struct llchdr *) nb->data; + type = llch->dsap & LLCADDRMASK; + + if (llch->dsap == 0xaa && llch->ssap == 0xaa && llch->ctrl == 0x3) + { + grub_netbuff_pull (nb,sizeof(*llch)); + snaph = (struct snaphdr *) nb->data; + type = snaph->type; + } + } + /*change for grub_memcmp*/ - if( eth->src[0] == 0x00 && eth->src[1] == 0x11 && eth->src[2] == 0x25 && - eth->src[3] == 0xca && eth->src[4] == 0x1f && eth->src[5] == 0x01 && eth->type == 0x800) - { - //grub_printf("ethernet eth->dst %x:%x:%x:%x:%x:%x\n",eth->dst[0], - // eth->dst[1],eth->dst[2],eth->dst[3],eth->dst[4],eth->dst[5]); - // grub_printf("ethernet eth->src %x:%x:%x:%x:%x:%x\n",eth->src[0],eth->src[1], - // eth->src[2],eth->src[3],eth->src[4],eth->src[5]); - //grub_printf("ethernet eth->type 0x%x\n",eth->type); - //grub_printf("out from ethernet\n"); - grub_netbuff_pull(nb,sizeof(*eth)); + //if( eth->src[0] == 0x00 && eth->src[1] == 0x11 && eth->src[2] == 0x25 && + // eth->src[3] == 0xca && eth->src[4] == 0x1f && eth->src[5] == 0x01 && type == 0x800) + if(type == 0x800) return 0; - } - current_time = grub_get_time_ms(); + + current_time = grub_get_time_ms (); if (current_time - start_time > TIMEOUT_TIME_MS) return grub_error (GRUB_ERR_TIMEOUT, "Time out."); } From 10830203a09d8afdb8f10ab322042bbcdecece16 Mon Sep 17 00:00:00 2001 From: Paulo de Rezende Pinatti Date: Fri, 13 Aug 2010 14:42:16 -0300 Subject: [PATCH 031/869] Added ARP protocol to network stack and fixed bug in grub_netbuff_alloc function. * include/grub/net/arp.h: added arp header, arp cache entry and related constants and functions * net/arp.c: added functions arp_init_table, arp_find_entry, arp_resolve and arp_receive * net/ethernet.c (send_ethernet_packet): replaced hardcoded hardware address by parameter target_addr * net/ethernet.c (recv_ethernet_packet): added call to arp_receive when packet is of type 0x803 (ARP) and only return when packet is of type determined by parameter ethertype * net/ip.c (send_ip_packet): added call to arp_resolve to determine hardware address of destination * net/netbuff.c (grub_netbuff_alloc): fixed swapped parameters in call to grub_memalign --- fs/ieee1275/ofnet.c | 48 +++++--- include/grub/net/arp.h | 49 +++++++-- include/grub/net/interface.h | 2 +- include/grub/net/ip.h | 1 + include/grub/net/protocol.h | 10 +- net/arp.c | 207 +++++++++++++++++++++++++++++++++++ net/ethernet.c | 38 ++++--- net/interface.c | 1 - net/ip.c | 27 ++++- net/netbuff.c | 2 +- net/tftp.c | 4 +- normal/misc.c | 2 +- 12 files changed, 335 insertions(+), 56 deletions(-) diff --git a/fs/ieee1275/ofnet.c b/fs/ieee1275/ofnet.c index 82b5235cc..cf7eeb5b2 100644 --- a/fs/ieee1275/ofnet.c +++ b/fs/ieee1275/ofnet.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -95,7 +96,7 @@ retrieve_field(const char *src, char **field, const char **rest) static grub_err_t parse_ip (const char *val, grub_uint32_t *ip, const char **rest) { - grub_uint32_t newip = 0; + grub_uint8_t *p = (grub_uint8_t *) ip; unsigned long t; int i; const char *ptr = val; @@ -107,8 +108,7 @@ parse_ip (const char *val, grub_uint32_t *ip, const char **rest) return grub_errno; if (t & ~0xff) return grub_error (GRUB_ERR_OUT_OF_RANGE, "Invalid IP."); - newip >>= 8; - newip |= (t << 24); + p[i] = (grub_uint8_t) t; if (i != 3 && *ptr != '.') return grub_error (GRUB_ERR_OUT_OF_RANGE, "Invalid IP."); ptr++; @@ -116,7 +116,6 @@ parse_ip (const char *val, grub_uint32_t *ip, const char **rest) ptr = ptr - 1; if ( *ptr != '\0' && *ptr != ',') return grub_error (GRUB_ERR_OUT_OF_RANGE, "Invalid IP."); - *ip = newip; if (rest) *rest = ptr; return 0; @@ -305,12 +304,33 @@ grub_ofnetfs_open (struct grub_file *file , const char *name ) char *datap; int amount = 0; grub_addr_t found_addr; + grub_netdisk_data_t netdisk_data = (grub_netdisk_data_t) file->device->disk->data; + // TODO: replace getting IP and MAC from bootp by routing functions + struct grub_net_network_layer_interface net_interface; + struct grub_net_card net_card; + struct grub_net_addr ila, lla; + ila.addr = (grub_uint8_t *) &(bootp_pckt->yiaddr); + ila.len = 4; + lla.addr = (grub_uint8_t *) &(bootp_pckt->chaddr); + lla.len = 6; + net_card.ila = &ila; + net_card.lla = &lla; + net_interface.card = &net_card; + // END TODO + + if(! netdisk_data) + return grub_error (GRUB_ERR_BAD_ARGUMENT, "arguments missing"); + + if(netdisk_data->protocol == GRUB_NETDISK_PROTOCOL_TFTP) + stack = grub_net_protocol_stack_get ("tftp"); + else + return grub_error (GRUB_ERR_BAD_ARGUMENT, "invalid protocol specified"); - stack = grub_net_protocol_stack_get ("tftp"); app_interface = (struct grub_net_application_transport_interface *) stack->interface; - pack = grub_netbuff_alloc (80*1024); - grub_netbuff_reserve (pack,80*1024); - file_size = app_interface->app_prot->get_file_size(NULL,stack,pack,(char *) name); + app_interface->inner_layer->data = (void *) &(netdisk_data->server_ip); + pack = grub_netbuff_alloc (2048); + grub_netbuff_reserve (pack,2048); + file_size = app_interface->app_prot->get_file_size(&net_interface,stack,pack,(char *) name); for (found_addr = 0x800000; found_addr < + 2000 * 0x100000; found_addr += 0x100000) { @@ -320,16 +340,16 @@ grub_ofnetfs_open (struct grub_file *file , const char *name ) file->data = (void *) found_addr; grub_netbuff_clear(pack); - grub_netbuff_reserve (pack,80*1024); - app_interface->app_prot->open (NULL,stack,pack,(char *) name); + grub_netbuff_reserve (pack,2048); + app_interface->app_prot->open (&net_interface,stack,pack,(char *) name); if (grub_errno != GRUB_ERR_NONE) goto error; do { grub_netbuff_clear(pack); - grub_netbuff_reserve (pack,80*1024); - app_interface->app_prot->recv (NULL,stack,pack); + grub_netbuff_reserve (pack,2048); + app_interface->app_prot->recv (&net_interface,stack,pack); if (grub_errno != GRUB_ERR_NONE) goto error; if ((pack->tail - pack->data)) @@ -340,8 +360,8 @@ grub_ofnetfs_open (struct grub_file *file , const char *name ) grub_memcpy(datap , pack->data, pack->tail - pack->data); } grub_netbuff_clear(pack); - grub_netbuff_reserve (pack,80*1024); - app_interface->app_prot->send_ack (NULL,stack,pack); + grub_netbuff_reserve (pack,2048); + app_interface->app_prot->send_ack (&net_interface,stack,pack); if (grub_errno != GRUB_ERR_NONE) goto error; diff --git a/include/grub/net/arp.h b/include/grub/net/arp.h index 86ae2deea..75260aeb3 100644 --- a/include/grub/net/arp.h +++ b/include/grub/net/arp.h @@ -1,17 +1,42 @@ #ifndef GRUB_NET_ARP_HEADER #define GRUB_NET_ARP_HEADER 1 +#include +#include +#include -#include -struct arphdr{ - grub_int16_t hwtype; /* hardware type (must be ARPHRD_ETHER) */ - grub_int16_t protocol; /* protocol type (must be ETH_P_IP) */ - grub_int8_t hwlen; /* hardware address length (must be 6) */ - grub_int8_t protolen; /* protocol address length (must be 4) */ - grub_uint16_t opcode; /* ARP opcode */ - grub_uint8_t shwaddr[6]; /* sender's hardware address */ - grub_uint32_t sipaddr; /* sender's IP address */ - grub_uint8_t thwaddr[6]; /* target's hardware address */ - grub_uint32_t tipaddr; /* target's IP address */ -}__attribute__ ((packed)); +/* IANA ARP constant to define hardware type as ethernet */ +#define ARPHRD_ETHERNET 1 +/* IANA Ethertype */ +#define ARP_ETHERTYPE 0x806 + +/* Size for cache table */ +#define SIZE_ARP_TABLE 5 + +/* ARP header operation codes */ +#define ARP_REQUEST 1 +#define ARP_REPLY 2 + +struct arp_entry { + grub_uint8_t avail; + struct grub_net_network_layer_protocol *nl_protocol; + struct grub_net_link_layer_protocol *ll_protocol; + struct grub_net_addr nl_address; + struct grub_net_addr ll_address; +}; + +struct arphdr { + grub_uint16_t hrd; + grub_uint16_t pro; + grub_uint8_t hln; + grub_uint8_t pln; + grub_uint16_t op; +} __attribute__ ((packed)); + +extern grub_err_t arp_receive(struct grub_net_network_layer_interface *inf __attribute__ ((unused)), +struct grub_net_network_link_interface *net_link_inf, struct grub_net_buff *nb); + +extern grub_err_t arp_resolve(struct grub_net_network_layer_interface *inf __attribute__ ((unused)), +struct grub_net_network_link_interface *net_link_inf, struct grub_net_addr *proto_addr, +struct grub_net_addr *hw_addr); #endif diff --git a/include/grub/net/interface.h b/include/grub/net/interface.h index 4d100fd75..cf24dd22e 100644 --- a/include/grub/net/interface.h +++ b/include/grub/net/interface.h @@ -37,7 +37,7 @@ struct grub_net_network_link_interface }; -extern struct grub_net_protocol_stack *grub_net_protocol_stacks; +struct grub_net_protocol_stack *grub_net_protocol_stacks; static inline void grub_net_stack_register (struct grub_net_protocol_stack *stack) { diff --git a/include/grub/net/ip.h b/include/grub/net/ip.h index cb119ac6f..5baacd439 100644 --- a/include/grub/net/ip.h +++ b/include/grub/net/ip.h @@ -2,6 +2,7 @@ #define GRUB_NET_IP_HEADER 1 #include +#define IP_ETHERTYPE 0x800 /* IANA Ethertype */ struct iphdr { grub_uint8_t verhdrlen; diff --git a/include/grub/net/protocol.h b/include/grub/net/protocol.h index b7a3e5d3b..ffc3dd719 100644 --- a/include/grub/net/protocol.h +++ b/include/grub/net/protocol.h @@ -8,7 +8,7 @@ struct grub_net_protocol; struct grub_net_protocol_stack; struct grub_net_network_layer_interface; - +struct grub_net_addr; typedef enum grub_network_layer_protocol_id { @@ -57,6 +57,7 @@ struct grub_net_network_layer_protocol struct grub_net_network_layer_protocol *next; char *name; grub_net_protocol_id_t id; + grub_uint16_t type; /* IANA Ethertype */ //grub_network_layer_protocol_id_t id; grub_err_t (*ntoa) (char *name, grub_net_network_layer_address_t *addr); char * (*aton) (union grub_net_network_layer_address addr); @@ -76,11 +77,14 @@ struct grub_net_link_layer_protocol struct grub_net_link_layer_protocol *next; char *name; + grub_uint16_t type; /* ARP hardware type */ grub_net_protocol_id_t id; grub_err_t (*send) (struct grub_net_network_layer_interface *inf , - struct grub_net_network_link_interface *net_link_inf, struct grub_net_buff *nb); + struct grub_net_network_link_interface *net_link_inf, struct grub_net_buff *nb, + struct grub_net_addr target_addr, grub_uint16_t ethertype); grub_err_t (*recv) (struct grub_net_network_layer_interface *inf , - struct grub_net_network_link_interface *net_link_inf, struct grub_net_buff *nb); + struct grub_net_network_link_interface *net_link_inf, struct grub_net_buff *nb, + grub_uint16_t ethertype); }; extern struct grub_net_network_layer_protocol *grub_net_network_layer_protocols; diff --git a/net/arp.c b/net/arp.c index e69de29bb..c02ea011d 100644 --- a/net/arp.c +++ b/net/arp.c @@ -0,0 +1,207 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static struct arp_entry arp_table[SIZE_ARP_TABLE]; +static grub_int8_t new_table_entry = -1; + +static void arp_init_table(void) +{ + struct arp_entry *entry = &(arp_table[0]); + for(;entry<=&(arp_table[SIZE_ARP_TABLE-1]);entry++) + { + entry->avail = 0; + entry->nl_protocol = NULL; + entry->ll_protocol = NULL; + entry->nl_address.addr = NULL; + entry->nl_address.len = 0; + entry->ll_address.addr = NULL; + entry->ll_address.len = 0; + } + new_table_entry = 0; +} + +static struct arp_entry * +arp_find_entry(struct grub_net_network_link_interface *net_link_inf, const void *proto_address, grub_uint8_t address_len) +{ + grub_uint8_t i; + for(i=0;i < SIZE_ARP_TABLE; i++) + { + if(arp_table[i].avail == 1 && + arp_table[i].nl_protocol->type == net_link_inf->net_prot->type && + arp_table[i].ll_protocol->type == net_link_inf->link_prot->type && + (!grub_memcmp(arp_table[i].nl_address.addr, proto_address, address_len))) + return &(arp_table[i]); + } + return NULL; +} + +grub_err_t arp_resolve(struct grub_net_network_layer_interface *inf __attribute__ ((unused)), +struct grub_net_network_link_interface *net_link_inf, struct grub_net_addr *proto_addr, +struct grub_net_addr *hw_addr) +{ + struct arp_entry *entry; + struct grub_net_buff *nb; + struct arphdr *arp_header; + struct grub_net_addr target_hw_addr; + grub_uint8_t *aux, i; + + /* Check cache table */ + entry = arp_find_entry(net_link_inf, proto_addr->addr, proto_addr->len); + if (entry) + { + hw_addr->addr = grub_malloc(entry->ll_address.len); + if (! hw_addr->addr) + return grub_error (GRUB_ERR_OUT_OF_MEMORY, "fail to alloc memory"); + grub_memcpy(hw_addr->addr, entry->ll_address.addr, entry->ll_address.len); + hw_addr->len = entry->ll_address.len; + return GRUB_ERR_NONE; + } + /* Build a request packet */ + nb = grub_netbuff_alloc (2048); + grub_netbuff_reserve(nb, 2048); + grub_netbuff_push(nb, sizeof(*arp_header) + 2*(inf->card->lla->len + inf->card->ila->len)); + arp_header = (struct arphdr *)nb->data; + arp_header->hrd = net_link_inf->link_prot->type; + arp_header->pro = net_link_inf->net_prot->type; + arp_header->hln = inf->card->lla->len; + arp_header->pln = inf->card->ila->len; + arp_header->op = ARP_REQUEST; + aux = (grub_uint8_t *)arp_header + sizeof(*arp_header); + /* Sender hardware address */ + grub_memcpy(aux, inf->card->lla->addr, inf->card->lla->len); + aux += inf->card->lla->len; + /* Sender protocol address */ + grub_memcpy(aux, inf->card->ila->addr, inf->card->ila->len); + aux += inf->card->ila->len; + /* Target hardware address */ + for(i=0; i < inf->card->lla->len; i++) + aux[i] = 0x00; + aux += inf->card->lla->len; + /* Target protocol address */ + grub_memcpy(aux, proto_addr->addr, inf->card->ila->len); + + target_hw_addr.addr = grub_malloc(inf->card->lla->len); + target_hw_addr.len = inf->card->lla->len; + for(i=0; i < target_hw_addr.len; i++) + (target_hw_addr.addr)[i] = 0xFF; + net_link_inf->link_prot->send(inf, net_link_inf, nb, target_hw_addr, ARP_ETHERTYPE); + grub_free(target_hw_addr.addr); + grub_netbuff_clear(nb); + grub_netbuff_reserve(nb, 2048); + + grub_uint64_t start_time, current_time; + start_time = grub_get_time_ms(); + do + { + net_link_inf->link_prot->recv(inf, net_link_inf, nb, ARP_ETHERTYPE); + /* Now check cache table again */ + entry = arp_find_entry(net_link_inf, proto_addr->addr, proto_addr->len); + if (entry) + { + hw_addr->addr = grub_malloc(entry->ll_address.len); + if (! hw_addr->addr) + return grub_error (GRUB_ERR_OUT_OF_MEMORY, "fail to alloc memory"); + grub_memcpy(hw_addr->addr, entry->ll_address.addr, entry->ll_address.len); + hw_addr->len = entry->ll_address.len; + grub_netbuff_clear(nb); + return GRUB_ERR_NONE; + } + current_time = grub_get_time_ms(); + if (current_time - start_time > TIMEOUT_TIME_MS) + break; + } while (! entry); + grub_netbuff_clear(nb); + return grub_error (GRUB_ERR_TIMEOUT, "Timeout: could not resolve hardware address."); +} + +grub_err_t arp_receive(struct grub_net_network_layer_interface *inf __attribute__ ((unused)), +struct grub_net_network_link_interface *net_link_inf, struct grub_net_buff *nb) +{ + struct arphdr *arp_header = (struct arphdr *)nb->data; + struct arp_entry *entry; + grub_uint8_t merge = 0; + + /* Verify hardware type, protocol type, hardware address length, protocol address length */ + if (arp_header->hrd != net_link_inf->link_prot->type || arp_header->pro != net_link_inf->net_prot->type || + arp_header->hln != inf->card->lla->len || arp_header->pln != inf->card->ila->len) + return GRUB_ERR_NONE; + + grub_uint8_t *sender_hardware_address, *sender_protocol_address, *target_hardware_address, *target_protocol_address; + sender_hardware_address = (grub_uint8_t *)arp_header + sizeof(*arp_header); + sender_protocol_address = sender_hardware_address + arp_header->hln; + target_hardware_address = sender_protocol_address + arp_header->pln; + target_protocol_address = target_hardware_address + arp_header->hln; + /* Check if the sender is in the cache table */ + entry = arp_find_entry(net_link_inf, sender_protocol_address, arp_header->pln); + /* Update sender hardware address */ + if (entry) + { + if (entry->ll_address.addr) + grub_free(entry->ll_address.addr); + entry->ll_address.addr = grub_malloc(arp_header->hln); + if (! entry->ll_address.addr) + return grub_error (GRUB_ERR_OUT_OF_MEMORY, "fail to alloc memory"); + grub_memcpy(entry->ll_address.addr, sender_hardware_address, arp_header->hln); + entry->ll_address.len = arp_header->hln; + merge = 1; + } + /* Am I the protocol address target? */ + if (! grub_memcmp(target_protocol_address, inf->card->ila->addr, arp_header->pln)) + { + /* Add sender to cache table */ + if (! merge) + { + if (new_table_entry == -1) + arp_init_table(); + entry = &(arp_table[new_table_entry]); + entry->avail = 1; + entry->ll_protocol = net_link_inf->link_prot; + entry->nl_protocol = net_link_inf->net_prot; + if (entry->nl_address.addr) + grub_free(entry->nl_address.addr); + entry->nl_address.addr = grub_malloc(arp_header->pln); + if (! entry->nl_address.addr) + return grub_error (GRUB_ERR_OUT_OF_MEMORY, "fail to alloc memory"); + grub_memcpy(entry->nl_address.addr, sender_protocol_address, arp_header->pln); + entry->nl_address.len = arp_header->pln; + if (entry->ll_address.addr) + grub_free(entry->ll_address.addr); + entry->ll_address.addr = grub_malloc(arp_header->hln); + if (! entry->ll_address.addr) + return grub_error (GRUB_ERR_OUT_OF_MEMORY, "fail to alloc memory"); + grub_memcpy(entry->ll_address.addr, sender_hardware_address, arp_header->hln); + entry->ll_address.len = arp_header->hln; + new_table_entry++; + if (new_table_entry == SIZE_ARP_TABLE) + new_table_entry = 0; + } + if (arp_header->op == ARP_REQUEST) + { + struct grub_net_addr aux; + /* Swap hardware fields */ + grub_memcpy(target_hardware_address, sender_hardware_address, arp_header->hln); + grub_memcpy(sender_hardware_address, inf->card->lla->addr, arp_header->hln); + /* Swap protocol fields */ + aux.addr = grub_malloc(arp_header->pln); + if (! aux.addr) + return grub_error (GRUB_ERR_OUT_OF_MEMORY, "fail to alloc memory"); + grub_memcpy(aux.addr, sender_protocol_address, arp_header->pln); + grub_memcpy(sender_protocol_address, target_protocol_address, arp_header->pln); + grub_memcpy(target_protocol_address, aux.addr, arp_header->pln); + grub_free(aux.addr); + /* Change operation to REPLY and send packet */ + arp_header->op = ARP_REPLY; + aux.addr = target_hardware_address; + aux.len = arp_header->hln; + net_link_inf->link_prot->send(inf, net_link_inf, nb, aux, ARP_ETHERTYPE); + } + } + return GRUB_ERR_NONE; +} diff --git a/net/ethernet.c b/net/ethernet.c index ab5992133..14bc41c5b 100644 --- a/net/ethernet.c +++ b/net/ethernet.c @@ -8,24 +8,21 @@ #include #include #include +#include static grub_err_t send_ethernet_packet (struct grub_net_network_layer_interface *inf __attribute__ ((unused)), - struct grub_net_network_link_interface *net_link_inf __attribute__ ((unused)) ,struct grub_net_buff *nb) +struct grub_net_network_link_interface *net_link_inf __attribute__ ((unused)) ,struct grub_net_buff *nb, +struct grub_net_addr target_addr, grub_uint16_t ethertype) { struct etherhdr *eth; grub_netbuff_push (nb,sizeof(*eth)); eth = (struct etherhdr *) nb->data; - eth->dst[0] = 0x00; - eth->dst[1] = 0x11; - eth->dst[2] = 0x25; - eth->dst[3] = 0xca; - eth->dst[4] = 0x1f; - eth->dst[5] = 0x01; - grub_memcpy (eth->src, bootp_pckt -> chaddr,6); - eth->type = 0x0800; + grub_memcpy(eth->dst, target_addr.addr, target_addr.len); + grub_memcpy(eth->src, bootp_pckt->chaddr, 6); + eth->type = ethertype; return send_card_buffer(nb); // return inf->card->driver->send(inf->card,nb); @@ -34,7 +31,8 @@ send_ethernet_packet (struct grub_net_network_layer_interface *inf __attribute__ static grub_err_t recv_ethernet_packet (struct grub_net_network_layer_interface *inf __attribute__ ((unused)), - struct grub_net_network_link_interface *net_link_inf __attribute__ ((unused)) ,struct grub_net_buff *nb) +struct grub_net_network_link_interface *net_link_inf __attribute__ ((unused)) ,struct grub_net_buff *nb, +grub_uint16_t ethertype) { struct etherhdr *eth; grub_uint64_t start_time, current_time; @@ -63,12 +61,17 @@ recv_ethernet_packet (struct grub_net_network_layer_interface *inf __attribute__ } } - /*change for grub_memcmp*/ - //if( eth->src[0] == 0x00 && eth->src[1] == 0x11 && eth->src[2] == 0x25 && - // eth->src[3] == 0xca && eth->src[4] == 0x1f && eth->src[5] == 0x01 && type == 0x800) - if(type == 0x800) - return 0; - + /* ARP packet */ + if (type == ARP_ETHERTYPE) + { + arp_receive(inf, net_link_inf, nb); + if (ethertype == ARP_ETHERTYPE) + return GRUB_ERR_NONE; + } + /* IP packet */ + else if(type == IP_ETHERTYPE && ethertype == IP_ETHERTYPE) + return GRUB_ERR_NONE; + current_time = grub_get_time_ms (); if (current_time - start_time > TIMEOUT_TIME_MS) return grub_error (GRUB_ERR_TIMEOUT, "Time out."); @@ -77,7 +80,7 @@ recv_ethernet_packet (struct grub_net_network_layer_interface *inf __attribute__ - verify if the next layer is the desired one. - if not. get another packet. - remove ethernet header from buffer*/ - return 0; + return GRUB_ERR_NONE; } @@ -85,6 +88,7 @@ static struct grub_net_link_layer_protocol grub_ethernet_protocol = { .name = "ethernet", .id = GRUB_NET_ETHERNET_ID, + .type = ARPHRD_ETHERNET, .send = send_ethernet_packet, .recv = recv_ethernet_packet }; diff --git a/net/interface.c b/net/interface.c index bacabf4cb..f17b3e66b 100644 --- a/net/interface.c +++ b/net/interface.c @@ -22,7 +22,6 @@ INTERFACE_REGISTER_FUNCTIONS("link");*/ #include #include -struct grub_net_protocol_stack *grub_net_protocol_stacks; struct grub_net_protocol_stack *grub_net_protocol_stack_get (char *name) { diff --git a/net/ip.c b/net/ip.c index 65b0f2b70..142f33e70 100644 --- a/net/ip.c +++ b/net/ip.c @@ -1,6 +1,7 @@ #include #include #include +#include #include #include #include @@ -36,6 +37,8 @@ send_ip_packet (struct grub_net_network_layer_interface *inf, struct iphdr *iph; static int id = 0x2400; + struct grub_net_addr nl_target_addr, ll_target_addr; + grub_err_t rc; grub_netbuff_push(nb,sizeof(*iph)); iph = (struct iphdr *) nb->data; @@ -51,12 +54,26 @@ send_ip_packet (struct grub_net_network_layer_interface *inf, iph->ttl = 0xff; iph->protocol = 0x11; iph->src = (grub_uint32_t) bootp_pckt -> yiaddr; //inf->address.ipv4; // *((grub_uint32_t *)inf->card->ila->addr); - iph->dest = (grub_uint32_t) bootp_pckt -> siaddr;//inf->address.ipv4;// *((grub_uint32_t *)inf->ila->addr); + // iph->dest = (grub_uint32_t) bootp_pckt -> siaddr;//inf->address.ipv4;// *((grub_uint32_t *)inf->ila->addr); + iph->dest = *((grub_uint32_t *) (trans_net_inf->data)); iph->chksum = 0 ; iph->chksum = ipchksum((void *)nb->data, sizeof(*iph)); - return trans_net_inf->inner_layer->link_prot->send(inf,trans_net_inf->inner_layer,nb); + /* Determine link layer target address via ARP */ + nl_target_addr.len = sizeof(iph->dest); + nl_target_addr.addr = grub_malloc(nl_target_addr.len); + if (! nl_target_addr.addr) + return grub_error (GRUB_ERR_OUT_OF_MEMORY, "fail to alloc memory"); + grub_memcpy(nl_target_addr.addr, &(iph->dest), nl_target_addr.len); + rc = arp_resolve(inf, trans_net_inf->inner_layer, &nl_target_addr, &ll_target_addr); + grub_free(nl_target_addr.addr); + if (rc != GRUB_ERR_NONE) + return rc; + + rc = trans_net_inf->inner_layer->link_prot->send(inf,trans_net_inf->inner_layer,nb,ll_target_addr, IP_ETHERTYPE); + grub_free(ll_target_addr.addr); + return rc; //return protstack->next->prot->send(inf,protstack->next,nb); } @@ -70,11 +87,12 @@ recv_ip_packet (struct grub_net_network_layer_interface *inf, start_time = grub_get_time_ms(); while (1) { - trans_net_inf->inner_layer->link_prot->recv(inf,trans_net_inf->inner_layer,nb); + trans_net_inf->inner_layer->link_prot->recv(inf,trans_net_inf->inner_layer,nb,IP_ETHERTYPE); iph = (struct iphdr *) nb->data; if (iph->protocol == 0x11 && iph->dest == (grub_uint32_t) bootp_pckt -> yiaddr && - iph->src == (grub_uint32_t) bootp_pckt -> siaddr ) + //iph->src == (grub_uint32_t) bootp_pckt -> siaddr ) + iph->src == *((grub_uint32_t *) (trans_net_inf->data)) ) { grub_netbuff_pull(nb,sizeof(*iph)); return 0; @@ -99,6 +117,7 @@ static struct grub_net_network_layer_protocol grub_ipv4_protocol = { .name = "ipv4", .id = GRUB_NET_IPV4_ID, + .type = IP_ETHERTYPE, .send = send_ip_packet, .recv = recv_ip_packet }; diff --git a/net/netbuff.c b/net/netbuff.c index ce52233b6..4f6a1da84 100644 --- a/net/netbuff.c +++ b/net/netbuff.c @@ -72,7 +72,7 @@ struct grub_net_buff *grub_netbuff_alloc ( grub_size_t len ) len = NETBUFFMINLEN; len = ALIGN_UP (len,NETBUFF_ALIGN); - data = grub_memalign (len + sizeof (*nb),NETBUFF_ALIGN); + data = grub_memalign (NETBUFF_ALIGN, len + sizeof (*nb)); nb = (struct grub_net_buff *) ((int)data + len); nb->head = nb->data = nb->tail = data; nb->end = (char *) nb; diff --git a/net/tftp.c b/net/tftp.c index 0fb43105d..2aeae38e9 100644 --- a/net/tftp.c +++ b/net/tftp.c @@ -113,7 +113,7 @@ tftp_open (struct grub_net_network_layer_interface *inf __attribute((unused)), app_interface->trans_prot->send (inf,protstack->interface,nb); /*Receive OACK*/ grub_netbuff_clear (nb); - grub_netbuff_reserve (nb,80*1024); + grub_netbuff_reserve (nb,2048); return app_interface->app_prot->recv(inf,protstack,nb); } @@ -215,7 +215,7 @@ static int tftp_file_size (struct grub_net_network_layer_interface* inf , tftp_open (inf, protocol_stack,nb, filename); grub_netbuff_clear (nb); - grub_netbuff_reserve (nb,80*1024); + grub_netbuff_reserve (nb,2048); tftp_send_err (inf, protocol_stack,nb,"Abort transference.",0); return tftp_file.size; diff --git a/normal/misc.c b/normal/misc.c index d53fe711c..30967e174 100644 --- a/normal/misc.c +++ b/normal/misc.c @@ -54,7 +54,7 @@ grub_normal_print_device_info (const char *name) grub_printf_(N_("Protocol: %s"), "Unknown"); grub_putchar ('\n'); grub_putchar ('\t'); - grub_printf_(N_("Server IP: %d.%d.%d.%d"), data->server_ip & 0xff, data->server_ip >> 8 & 0xff, data->server_ip >> 16 & 0xff, data->server_ip >> 24 & 0xff); + grub_printf_(N_("Server IP: %d.%d.%d.%d"), data->server_ip >> 24 & 0xff, data->server_ip >> 16 & 0xff, data->server_ip >> 8 & 0xff, data->server_ip & 0xff); if (data->username) { grub_putchar ('\n'); From f15f9c5029692d3ff5c4731cde9bc11e1214f7ac Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 1 Sep 2010 02:41:21 +0200 Subject: [PATCH 032/869] Remove leftover modules --- grub-core/Makefile.core.def | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def index 76437f5a5..925f2b7f6 100644 --- a/grub-core/Makefile.core.def +++ b/grub-core/Makefile.core.def @@ -1425,15 +1425,3 @@ module = { common = commands/efi/memmap.c; enable = ia64_efi; }; - -module = { - name = systab; - common = commands/efi/systab.c; - enable = ia64_efi; -}; - -module = { - name = acpi2; - common = commands/efi/acpi2.c; - enable = ia64_efi; -}; From b764f436e78a5899c4b6912cc68768fcf68aeef3 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 1 Sep 2010 03:03:15 +0200 Subject: [PATCH 033/869] Add ia64 setjmp implementation to the list --- grub-core/lib/setjmp.S | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/grub-core/lib/setjmp.S b/grub-core/lib/setjmp.S index c39c91b9c..b04fd7439 100644 --- a/grub-core/lib/setjmp.S +++ b/grub-core/lib/setjmp.S @@ -8,6 +8,8 @@ #include "./mips/setjmp.S" #elif defined(__powerpc__) #include "./powerpc/setjmp.S" +#elif defined(__ia64__) +#include "./ia64/setjmp.S" #else -#error "Unknwon target cpu type" +#error "Unknown target cpu type" #endif From afef75b254473c065af83beb605857ca8b8a21dd Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 1 Sep 2010 03:05:36 +0200 Subject: [PATCH 034/869] Use finish boot services and switch to new command line interface in linux loader --- grub-core/loader/ia64/efi/linux.c | 95 ++++++++++++++++--------------- 1 file changed, 49 insertions(+), 46 deletions(-) diff --git a/grub-core/loader/ia64/efi/linux.c b/grub-core/loader/ia64/efi/linux.c index 9020efd28..12c769a16 100644 --- a/grub-core/loader/ia64/efi/linux.c +++ b/grub-core/loader/ia64/efi/linux.c @@ -327,6 +327,7 @@ grub_linux_boot (void) grub_efi_uintn_t desc_size; grub_efi_uint32_t desc_version; grub_efi_memory_descriptor_t *mmap_buf; + grub_err_t err; /* FPSWA. */ query_fpswa (); @@ -349,18 +350,16 @@ grub_linux_boot (void) mmap_buf = grub_efi_allocate_boot_pages (0, page_align (mmap_size) >> 12); if (! mmap_buf) grub_fatal ("cannot allocate memory map"); - if (grub_efi_get_memory_map (&mmap_size, mmap_buf, &map_key, - &desc_size, &desc_version) <= 0) - grub_fatal ("cannot get memory map"); + err = grub_efi_finish_boot_services (&mmap_size, mmap_buf, &map_key, + &desc_size, &desc_version); + if (err) + return err; boot_param->efi_memmap = (grub_uint64_t)mmap_buf; boot_param->efi_memmap_size = mmap_size; boot_param->efi_memdesc_size = desc_size; boot_param->efi_memdesc_version = desc_version; - if (! grub_efi_exit_boot_services (map_key)) - grub_fatal ("cannot exit boot services"); - /* See you next boot. */ asm volatile ("mov r28=%1; br.sptk.few %0" :: "b"(entry),"r"(boot_param)); @@ -494,8 +493,9 @@ grub_load_elf64 (grub_file_t file, void *buffer) return 0; } -void -grub_rescue_cmd_linux (int argc, char *argv[]) +static grub_err_t +grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), + int argc, char *argv[]) { grub_file_t file = 0; char buffer[GRUB_ELF_SEARCH]; @@ -574,10 +574,12 @@ grub_rescue_cmd_linux (int argc, char *argv[]) boot_param_pages); grub_dl_unref (my_mod); } + return grub_errno; } -void -grub_rescue_cmd_initrd (int argc, char *argv[]) +static grub_err_t +grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), + int argc, char *argv[]) { grub_file_t file = 0; @@ -617,10 +619,12 @@ grub_rescue_cmd_initrd (int argc, char *argv[]) fail: if (file) grub_file_close (file); + return grub_errno; } -void -grub_rescue_cmd_payload (int argc, char *argv[]) +static grub_err_t +grub_cmd_payload (grub_command_t cmd __attribute__ ((unused)), + int argc, char *argv[]) { grub_file_t file = 0; grub_ssize_t size, len = 0; @@ -708,10 +712,12 @@ grub_rescue_cmd_payload (int argc, char *argv[]) grub_free (base); grub_free (cmdline); } + return grub_errno; } -void -grub_rescue_cmd_relocate (int argc, char *argv[]) +static grub_err_t +grub_cmd_relocate (grub_command_t cmd __attribute__ ((unused)), + int argc, char *argv[]) { static const char * const vals[] = { "off", "on", "force"}; unsigned int i; @@ -719,6 +725,7 @@ grub_rescue_cmd_relocate (int argc, char *argv[]) if (argc == 0) { grub_printf ("relocate is %s\n", vals[relocate]); + return GRUB_ERR_NONE; } else if (argc == 1) { @@ -728,67 +735,63 @@ grub_rescue_cmd_relocate (int argc, char *argv[]) if (grub_strcmp (argv[0], vals[i]) == 0) { relocate = i; - return; + return GRUB_ERR_NONE; } - grub_error (GRUB_ERR_BAD_ARGUMENT, "unknown relocate value"); + return grub_error (GRUB_ERR_BAD_ARGUMENT, "unknown relocate value"); } else { - grub_error (GRUB_ERR_BAD_ARGUMENT, "accept 0 or 1 argument"); + return grub_error (GRUB_ERR_BAD_ARGUMENT, "accept 0 or 1 argument"); } + } -void -grub_rescue_cmd_fpswa (int argc, char *argv[] __attribute__((unused))) +static grub_err_t +grub_cmd_fpswa (grub_command_t cmd __attribute__ ((unused)), + int argc, char *argv[] __attribute__((unused))) { if (argc != 0) { - grub_error (GRUB_ERR_BAD_ARGUMENT, "Arguments not expected"); - return; + return grub_error (GRUB_ERR_BAD_ARGUMENT, "Arguments not expected"); } query_fpswa (); if (fpswa == NULL) grub_printf ("No FPSWA loaded\n"); else grub_printf ("FPSWA revision: %x\n", fpswa->revision); + return GRUB_ERR_NONE; } +static grub_command_t cmd_linux, cmd_initrd, cmd_payload, cmd_relocate, cmd_fpswa; + GRUB_MOD_INIT(linux) { - grub_register_extcmd ("linux", grub_normal_linux_command, - GRUB_COMMAND_FLAG_BOTH | GRUB_COMMAND_FLAG_NO_ARG_PARSE, - "linux FILE [ARGS...]", - "Load Linux.", 0); + cmd_linux = grub_register_command ("linux", grub_cmd_linux, + "FILE [ARGS...]", "Load Linux."); - grub_register_extcmd ("initrd", grub_normal_initrd_command, - GRUB_COMMAND_FLAG_BOTH | GRUB_COMMAND_FLAG_NO_ARG_PARSE, - "initrd FILE", - "Load initrd.", 0); + cmd_initrd = grub_register_command ("initrd", grub_cmd_initrd, + "FILE", "Load initrd."); - grub_register_extcmd ("payload", grub_normal_cmd_payload, - GRUB_COMMAND_FLAG_BOTH | GRUB_COMMAND_FLAG_NO_ARG_PARSE, - "payload FILE [ARGS...]", - "Load an additional file.", 0); + cmd_payload = grub_register_command ("payload", grub_cmd_payload, + "FILE [ARGS...]", + "Load an additional file."); - grub_register_extcmd ("relocate", grub_normal_cmd_relocate, - GRUB_COMMAND_FLAG_BOTH | GRUB_COMMAND_FLAG_NO_ARG_PARSE, - "relocate [on|off|force]", - "Set relocate feature.", 0); + cmd_relocate = grub_register_command ("relocate", grub_cmd_relocate, + "[on|off|force]", + "Set relocate feature."); - grub_register_extcmd ("fpswa", grub_normal_cmd_fpswa, - GRUB_COMMAND_FLAG_BOTH | GRUB_COMMAND_FLAG_NO_ARG_PARSE, - "fpswa", - "Display FPSWA version.", 0); + cmd_fpswa = grub_register_command ("fpswa", grub_cmd_fpswa, + "", "Display FPSWA version."); my_mod = mod; } GRUB_MOD_FINI(linux) { - grub_unregister_command ("linux"); - grub_unregister_command ("initrd"); - grub_unregister_command ("payload"); - grub_unregister_command ("relocate"); - grub_unregister_command ("fpswa"); + grub_unregister_command (cmd_linux); + grub_unregister_command (cmd_initrd); + grub_unregister_command (cmd_payload); + grub_unregister_command (cmd_relocate); + grub_unregister_command (cmd_fpswa); } From c84a9b54ad9e957adb8414620af52a2a414419d0 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 1 Sep 2010 09:43:36 +0200 Subject: [PATCH 035/869] remove allocate_boot_pages and free_boot_pages. They are pointless now --- grub-core/loader/ia64/efi/linux.c | 32 +++++++++++++++---------------- include/grub/efi/efi.h | 7 ------- 2 files changed, 16 insertions(+), 23 deletions(-) diff --git a/grub-core/loader/ia64/efi/linux.c b/grub-core/loader/ia64/efi/linux.c index 12c769a16..61b261599 100644 --- a/grub-core/loader/ia64/efi/linux.c +++ b/grub-core/loader/ia64/efi/linux.c @@ -193,13 +193,13 @@ free_pages (void) { if (kernel_mem) { - grub_efi_free_boot_pages ((grub_addr_t) kernel_mem, kernel_pages); + grub_efi_free_pages ((grub_addr_t) kernel_mem, kernel_pages); kernel_mem = 0; } if (initrd_mem) { - grub_efi_free_boot_pages ((grub_addr_t) initrd_mem, initrd_pages); + grub_efi_free_pages ((grub_addr_t) initrd_mem, initrd_pages); initrd_mem = 0; } @@ -214,16 +214,16 @@ free_pages (void) { next_payload = (struct ia64_boot_payload *)payload->next; - grub_efi_free_boot_pages + grub_efi_free_pages (payload->start, page_align (payload->length) >> 12); - grub_efi_free_boot_pages ((grub_efi_physical_address_t)payload, 1); + grub_efi_free_pages ((grub_efi_physical_address_t)payload, 1); payload = next_payload; } /* Free bootparam. */ - grub_efi_free_boot_pages ((grub_efi_physical_address_t)boot_param, - boot_param_pages); + grub_efi_free_pages ((grub_efi_physical_address_t)boot_param, + boot_param_pages); boot_param = 0; } } @@ -347,7 +347,7 @@ grub_linux_boot (void) Must be done after grub_machine_fini because map_key is used by exit_boot_services. */ mmap_size = find_mmap_size (); - mmap_buf = grub_efi_allocate_boot_pages (0, page_align (mmap_size) >> 12); + mmap_buf = grub_efi_allocate_pages (0, page_align (mmap_size) >> 12); if (! mmap_buf) grub_fatal ("cannot allocate memory map"); err = grub_efi_finish_boot_services (&mmap_size, mmap_buf, &map_key, @@ -437,7 +437,7 @@ grub_load_elf64 (grub_file_t file, void *buffer) if (relocate != RELOCATE_FORCE) { - kernel_mem = grub_efi_allocate_boot_pages (low_addr, kernel_pages); + kernel_mem = grub_efi_allocate_pages (low_addr, kernel_pages); reloc_offset = 0; } /* Try to relocate. */ @@ -537,7 +537,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), len += grub_strlen (argv[i]) + 1; len += sizeof (struct ia64_boot_param) + 256; /* Room for extensions. */ boot_param_pages = page_align (len) >> 12; - boot_param = grub_efi_allocate_boot_pages (0, boot_param_pages); + boot_param = grub_efi_allocate_pages (0, boot_param_pages); if (boot_param == 0) { grub_error (GRUB_ERR_OUT_OF_MEMORY, @@ -557,8 +557,8 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), } cmdline[10] = '='; - boot_param->command_line = (grub_uint64_t)cmdline; - boot_param->efi_systab = (grub_uint64_t)grub_efi_system_table; + boot_param->command_line = (grub_uint64_t) cmdline; + boot_param->efi_systab = (grub_uint64_t) grub_efi_system_table; grub_errno = GRUB_ERR_NONE; @@ -570,8 +570,8 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), if (grub_errno != GRUB_ERR_NONE) { - grub_efi_free_boot_pages ((grub_efi_physical_address_t)boot_param, - boot_param_pages); + grub_efi_free_pages ((grub_efi_physical_address_t) boot_param, + boot_param_pages); grub_dl_unref (my_mod); } return grub_errno; @@ -603,7 +603,7 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), initrd_size = grub_file_size (file); initrd_pages = (page_align (initrd_size) >> 12); - initrd_mem = grub_efi_allocate_boot_pages (0, initrd_pages); + initrd_mem = grub_efi_allocate_pages (0, initrd_pages); if (! initrd_mem) grub_fatal ("cannot allocate pages"); @@ -650,7 +650,7 @@ grub_cmd_payload (grub_command_t cmd __attribute__ ((unused)), goto fail; size = grub_file_size (file); - base = grub_efi_allocate_boot_pages (0, page_align (size) >> 12); + base = grub_efi_allocate_pages (0, page_align (size) >> 12); if (! base) goto fail; @@ -672,7 +672,7 @@ grub_cmd_payload (grub_command_t cmd __attribute__ ((unused)), grub_error (GRUB_ERR_OUT_OF_RANGE, "payload command line too long"); goto fail; } - payload = grub_efi_allocate_boot_pages (0, 1); + payload = grub_efi_allocate_pages (0, 1); if (! payload) goto fail; diff --git a/include/grub/efi/efi.h b/include/grub/efi/efi.h index ea354e5ce..e9c57dd11 100644 --- a/include/grub/efi/efi.h +++ b/include/grub/efi/efi.h @@ -42,13 +42,6 @@ EXPORT_FUNC(grub_efi_allocate_pages) (grub_efi_physical_address_t address, grub_efi_uintn_t pages); void EXPORT_FUNC(grub_efi_free_pages) (grub_efi_physical_address_t address, grub_efi_uintn_t pages); -void * -EXPORT_FUNC(grub_efi_allocate_boot_pages) (grub_efi_physical_address_t address, - grub_efi_uintn_t pages); -void -EXPORT_FUNC(grub_efi_free_boot_pages) (grub_efi_physical_address_t address, - grub_efi_uintn_t pages); - int EXPORT_FUNC(grub_efi_get_memory_map) (grub_efi_uintn_t *memory_map_size, grub_efi_memory_descriptor_t *memory_map, From 07329a9ac9a2ea530d4e904541d1587e0b2c5cf1 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 1 Sep 2010 09:44:32 +0200 Subject: [PATCH 036/869] Fix some compilation problems --- Makefile.util.def | 1 + grub-core/commands/efi/memmap.c | 27 +++++++++++++++------------ grub-core/kern/dl.c | 10 +++++++++- include/grub/dl.h | 8 ++++---- include/grub/ia64/efi/memory.h | 1 + include/grub/ia64/efi/misc.h | 4 ++++ 6 files changed, 34 insertions(+), 17 deletions(-) create mode 100644 include/grub/ia64/efi/memory.h diff --git a/Makefile.util.def b/Makefile.util.def index 28e66a067..24adba282 100644 --- a/Makefile.util.def +++ b/Makefile.util.def @@ -365,6 +365,7 @@ script = { i386_efi = util/i386/efi/grub-install.in; x86_64_efi = util/i386/efi/grub-install.in; + ia64_efi = util/grub-install.in; i386_ieee1275 = util/ieee1275/grub-install.in; powerpc_ieee1275 = util/ieee1275/grub-install.in; diff --git a/grub-core/commands/efi/memmap.c b/grub-core/commands/efi/memmap.c index d49e02080..e7c140cff 100644 --- a/grub-core/commands/efi/memmap.c +++ b/grub-core/commands/efi/memmap.c @@ -22,12 +22,15 @@ #include #include #include +#include #define ADD_MEMORY_DESCRIPTOR(desc, size) \ ((grub_efi_memory_descriptor_t *) ((char *) (desc) + (size))) static grub_err_t -grub_cmd_memmap (struct grub_arg_list *state, int argc, char **args) +grub_cmd_memmap (grub_command_t cmd __attribute__ ((unused)), + int argc __attribute__ ((unused)), + char **args __attribute__ ((unused))) { grub_efi_uintn_t map_size; grub_efi_memory_descriptor_t *memory_map; @@ -80,22 +83,22 @@ grub_cmd_memmap (struct grub_arg_list *state, int argc, char **args) grub_printf ("Unk %02x ", desc->type); grub_printf (" %016llx-%016llx %08lx", - desc->physical_start, - desc->physical_start + (desc->num_pages << 12) - 1, - desc->num_pages); + (unsigned long long) desc->physical_start, + (unsigned long long) desc->physical_start + (desc->num_pages << 12) - 1, + (unsigned long) desc->num_pages); size = desc->num_pages << (12 - 10); if (size < 1024) - grub_printf (" %4uKB", size); + grub_printf (" %4uKB", (unsigned) size); else { size /= 1024; if (size < 1024) - grub_printf (" %4uMB", size); + grub_printf (" %4uMB", (unsigned) size); else { size /= 1024; - grub_printf (" %4uGB", size); + grub_printf (" %4uGB", (unsigned) size); } } @@ -129,15 +132,15 @@ grub_cmd_memmap (struct grub_arg_list *state, int argc, char **args) return 0; } +static grub_command_t cmd; + GRUB_MOD_INIT(memmap) { - (void)mod; /* To stop warning. */ - grub_register_extcmd ("memmap", grub_cmd_memmap, GRUB_COMMAND_FLAG_BOTH, - "memmap", - "Display memory map.", NULL); + cmd = grub_register_command ("memmap", grub_cmd_memmap, + "", "Display memory map."); } GRUB_MOD_FINI(memmap) { - grub_unregister_extcmd ("memmap"); + grub_unregister_command (cmd); } diff --git a/grub-core/kern/dl.c b/grub-core/kern/dl.c index fe3fd0014..4d7929073 100644 --- a/grub-core/kern/dl.c +++ b/grub-core/kern/dl.c @@ -37,6 +37,10 @@ #define GRUB_MODULES_MACHINE_READONLY #endif +#ifdef __ia64__ +#include +#endif + grub_dl_t grub_dl_head = 0; @@ -545,6 +549,7 @@ grub_dl_load_core (void *addr, grub_size_t size) return mod; } +#ifdef __ia64__ void grub_init_module (const char *name, void (*init)(grub_dl_t), void (*fini)(void)) @@ -555,7 +560,7 @@ grub_init_module (const char *name, if (! mod) return; - mod->name = name; + mod->name = (char *) name; mod->ref_count = 1; mod->dep = 0; mod->segment = 0; @@ -567,6 +572,7 @@ grub_init_module (const char *name, /* Can't fail. */ grub_dl_add (mod); } +#endif /* Load a module from the file FILENAME. */ grub_dl_t @@ -686,6 +692,7 @@ grub_dl_unload (grub_dl_t mod) return 1; } +#ifdef __ia64__ /* Unload unneeded modules. */ void grub_dl_unload_unneeded (void) @@ -705,3 +712,4 @@ grub_dl_unload_unneeded (void) p = p->next; } } +#endif diff --git a/include/grub/dl.h b/include/grub/dl.h index 04577a003..8195e948c 100644 --- a/include/grub/dl.h +++ b/include/grub/dl.h @@ -34,9 +34,9 @@ #ifndef GRUB_MOD_INIT #define GRUB_MOD_INIT(name) \ static void grub_mod_init (grub_dl_t mod __attribute__ ((unused))) __attribute__ ((used)); \ -void grub_module_##name##_init (grub_dl_t); \ +void grub_##name##_init (grub_dl_t); \ void \ -grub_module_##name##_init (grub_dl_t mod) { grub_mod_init (mod); } \ +grub_##name##_init (grub_dl_t mod) { grub_mod_init (mod); } \ static void \ grub_mod_init (grub_dl_t mod __attribute__ ((unused))) #endif @@ -44,9 +44,9 @@ grub_mod_init (grub_dl_t mod __attribute__ ((unused))) #ifndef GRUB_MOD_FINI #define GRUB_MOD_FINI(name) \ static void grub_mod_fini (void) __attribute__ ((used)); \ -void grub_module_##name##_fini (void); \ +void grub_##name##_fini (void); \ void \ -grub_module_##name##_fini (void) { grub_mod_fini (); } \ +grub_##name##_fini (void) { grub_mod_fini (); } \ static void \ grub_mod_fini (void) #endif diff --git a/include/grub/ia64/efi/memory.h b/include/grub/ia64/efi/memory.h new file mode 100644 index 000000000..c9a61bb77 --- /dev/null +++ b/include/grub/ia64/efi/memory.h @@ -0,0 +1 @@ +#include diff --git a/include/grub/ia64/efi/misc.h b/include/grub/ia64/efi/misc.h index 2b99dda62..4f9c69e32 100644 --- a/include/grub/ia64/efi/misc.h +++ b/include/grub/ia64/efi/misc.h @@ -19,5 +19,9 @@ void EXPORT_FUNC (__ia64_trampoline) (void); void EXPORT_FUNC (grub_init_modules) (void); +void +grub_init_module (const char *name, + void (*init)(grub_dl_t), void (*fini)(void)); + extern unsigned long EXPORT_VAR (__gp); From 4bec80482ea423c27c6de7a008d15ba44f8fbbfd Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 1 Sep 2010 10:21:05 +0200 Subject: [PATCH 037/869] Remove few bad hunks --- grub-core/kern/dl.c | 2 -- grub-core/loader/ia64/efi/linux.c | 1 - include/grub/ia64/efi/loader.h | 30 ------------------------------ 3 files changed, 33 deletions(-) delete mode 100644 include/grub/ia64/efi/loader.h diff --git a/grub-core/kern/dl.c b/grub-core/kern/dl.c index 4d7929073..4d112811f 100644 --- a/grub-core/kern/dl.c +++ b/grub-core/kern/dl.c @@ -692,7 +692,6 @@ grub_dl_unload (grub_dl_t mod) return 1; } -#ifdef __ia64__ /* Unload unneeded modules. */ void grub_dl_unload_unneeded (void) @@ -712,4 +711,3 @@ grub_dl_unload_unneeded (void) p = p->next; } } -#endif diff --git a/grub-core/loader/ia64/efi/linux.c b/grub-core/loader/ia64/efi/linux.c index 61b261599..d9b4c338b 100644 --- a/grub-core/loader/ia64/efi/linux.c +++ b/grub-core/loader/ia64/efi/linux.c @@ -17,7 +17,6 @@ */ #include -#include #include #include #include diff --git a/include/grub/ia64/efi/loader.h b/include/grub/ia64/efi/loader.h deleted file mode 100644 index 5471a81b5..000000000 --- a/include/grub/ia64/efi/loader.h +++ /dev/null @@ -1,30 +0,0 @@ -/* - * GRUB -- GRand Unified Bootloader - * Copyright (C) 2008 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 . - */ - -#ifndef GRUB_LOADER_MACHINE_HEADER -#define GRUB_LOADER_MACHINE_HEADER 1 - -/* It is necessary to export these functions, because normal mode commands - reuse rescue mode commands. */ -void grub_rescue_cmd_linux (int argc, char *argv[]); -void grub_rescue_cmd_initrd (int argc, char *argv[]); -void grub_rescue_cmd_payload (int argc, char *argv[]); -void grub_rescue_cmd_relocate (int argc, char *argv[]); -void grub_rescue_cmd_fpswa (int argc, char *argv[]); - -#endif /* ! GRUB_LOADER_MACHINE_HEADER */ From 9a9852df79f459b52d51214ed51863b1828d42b1 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Thu, 2 Sep 2010 00:07:55 +0200 Subject: [PATCH 038/869] Hook network protocols --- grub-core/Makefile.am | 1 + grub-core/commands/net.c | 33 +++++++++++++++++++++++++++++++++ grub-core/kern/device.c | 23 ++++++++++++++++------- grub-core/kern/fs.c | 2 +- include/grub/device.h | 7 +------ include/grub/net.h | 37 +++++++++++++++++++++++++++++++++++-- 6 files changed, 87 insertions(+), 16 deletions(-) diff --git a/grub-core/Makefile.am b/grub-core/Makefile.am index 5d13d0313..1fcc3d00d 100644 --- a/grub-core/Makefile.am +++ b/grub-core/Makefile.am @@ -74,6 +74,7 @@ KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/term.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/time.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/mm_private.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/boot.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/net.h if COND_i386_pc KERNEL_HEADER_FILES += $(top_builddir)/include/grub/machine/memory.h diff --git a/grub-core/commands/net.c b/grub-core/commands/net.c index 288ba4c2a..904c61a92 100644 --- a/grub-core/commands/net.c +++ b/grub-core/commands/net.c @@ -269,6 +269,37 @@ grub_cmd_addroute (struct grub_command *cmd __attribute__ ((unused)), return GRUB_ERR_NONE; } +grub_net_app_level_t grub_net_app_level_list; + +static grub_net_t +grub_net_open_real (const char *name) +{ + const char *comma = grub_strchr (name, ','); + grub_net_app_level_t proto; + + if (!comma) + comma = name + grub_strlen (name); + FOR_NET_APP_LEVEL (proto) + { + if (comma - name == (grub_ssize_t) grub_strlen (proto->name) + && grub_memcmp (proto->name, name, comma - name) == 0) + { + grub_net_t ret = grub_malloc (sizeof (*ret)); + if (!ret) + return NULL; + ret->protocol = proto; + ret->name = grub_strdup (name); + if (!ret->name) + { + grub_free (ret); + return NULL; + } + return ret; + } + } + return NULL; +} + static grub_command_t cmd_addaddr, cmd_deladdr, cmd_addroute, cmd_delroute; GRUB_MOD_INIT(net) @@ -285,6 +316,7 @@ GRUB_MOD_INIT(net) cmd_delroute = grub_register_command ("net_del_route", grub_cmd_delroute, "SHORTNAME", N_("Delete a network route.")); + grub_net_open = grub_net_open_real; } GRUB_MOD_FINI(net) @@ -293,4 +325,5 @@ GRUB_MOD_FINI(net) grub_unregister_command (cmd_deladdr); grub_unregister_command (cmd_addroute); grub_unregister_command (cmd_delroute); + grub_net_open = NULL; } diff --git a/grub-core/kern/device.c b/grub-core/kern/device.c index 4273fedfe..9de545910 100644 --- a/grub-core/kern/device.c +++ b/grub-core/kern/device.c @@ -26,6 +26,8 @@ #include #include +grub_net_t (*grub_net_open) (const char *name) = NULL; + grub_device_t grub_device_open (const char *name) { @@ -46,15 +48,16 @@ grub_device_open (const char *name) if (! dev) goto fail; + dev->net = NULL; /* Try to open a disk. */ - disk = grub_disk_open (name); - if (! disk) - goto fail; + dev->disk = grub_disk_open (name); + if (dev->disk) + return dev; + if (grub_net_open) + dev->net = grub_net_open (name); - dev->disk = disk; - dev->net = 0; /* FIXME */ - - return dev; + if (dev->net) + return dev; fail: if (disk) @@ -71,6 +74,12 @@ grub_device_close (grub_device_t device) if (device->disk) grub_disk_close (device->disk); + if (device->net) + { + grub_free (device->net->name); + grub_free (device->net); + } + grub_free (device); return grub_errno; diff --git a/grub-core/kern/fs.c b/grub-core/kern/fs.c index 8ffb93c8b..c4d6efa96 100644 --- a/grub-core/kern/fs.c +++ b/grub-core/kern/fs.c @@ -95,7 +95,7 @@ grub_fs_probe (grub_device_t device) } } else if (device->net) - return device->net->fs; + return device->net->protocol; grub_error (GRUB_ERR_UNKNOWN_FS, "unknown filesystem"); return 0; diff --git a/include/grub/device.h b/include/grub/device.h index d68c26e66..f3e43bf60 100644 --- a/include/grub/device.h +++ b/include/grub/device.h @@ -24,12 +24,7 @@ #include struct grub_disk; -struct grub_fs; -struct grub_net -{ - char *name; - struct grub_fs *fs; -}; +struct grub_net; struct grub_device { diff --git a/include/grub/net.h b/include/grub/net.h index 4ca873f74..b5e852f9b 100644 --- a/include/grub/net.h +++ b/include/grub/net.h @@ -22,6 +22,17 @@ #include #include #include +#include + +typedef struct grub_fs *grub_net_app_level_t; + +typedef struct grub_net +{ + char *name; + grub_net_app_level_t protocol; +} *grub_net_t; + +extern grub_net_t (*EXPORT_VAR (grub_net_open)) (const char *name); struct grub_net_card; @@ -46,7 +57,7 @@ struct grub_net_network_level_interface; typedef union grub_net_network_level_address { grub_uint32_t ipv4; -} grub_net_network_level_netaddress_t; +} grub_net_network_level_address_t; typedef union grub_net_network_level_netaddress { @@ -54,7 +65,7 @@ typedef union grub_net_network_level_netaddress grub_uint32_t base; int masksize; } ipv4; -} grub_net_network_level_address_t; +} grub_net_network_level_netaddress_t; typedef enum grub_network_level_protocol_id { @@ -163,6 +174,28 @@ grub_net_network_level_interface_unregister (struct grub_net_network_level_inter #define FOR_NET_NETWORK_LEVEL_INTERFACES(var) for (var = grub_net_network_level_interfaces; var; var = var->next) +extern grub_net_app_level_t grub_net_app_level_list; + +#ifndef GRUB_LST_GENERATOR +static inline void +grub_net_app_level_register (grub_net_app_level_t proto) +{ + grub_list_push (GRUB_AS_LIST_P (&grub_net_app_level_list), + GRUB_AS_LIST (proto)); +} +#endif + +static inline void +grub_net_app_level_unregister (grub_net_app_level_t proto) +{ + grub_list_remove (GRUB_AS_LIST_P (&grub_net_app_level_list), + GRUB_AS_LIST (proto)); +} + +#define FOR_NET_APP_LEVEL(var) FOR_LIST_ELEMENTS((var), \ + (grub_net_app_level_list)) + + extern struct grub_net_route *grub_net_routes; static inline void From 03b170647d564e2211bb9f3745b18d67eb0c4158 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Thu, 2 Sep 2010 17:18:02 +0200 Subject: [PATCH 039/869] Restructure pxe --- Makefile.util.def | 1 + grub-core/commands/ls.c | 13 ++ grub-core/commands/net.c | 361 +++++++++++++++++++++++++++---------- grub-core/fs/i386/pc/pxe.c | 268 +++++++++++++-------------- include/grub/net.h | 131 +++----------- 5 files changed, 433 insertions(+), 341 deletions(-) diff --git a/Makefile.util.def b/Makefile.util.def index 35bcd81b2..fe6894306 100644 --- a/Makefile.util.def +++ b/Makefile.util.def @@ -30,6 +30,7 @@ library = { common = grub-core/commands/blocklist.c; common = grub-core/commands/extcmd.c; common = grub-core/commands/ls.c; + common = grub-core/commands/net.c; common = grub-core/disk/dmraid_nvidia.c; common = grub-core/disk/host.c; common = grub-core/disk/loopback.c; diff --git a/grub-core/commands/ls.c b/grub-core/commands/ls.c index 9ee0a7a31..3179d271e 100644 --- a/grub-core/commands/ls.c +++ b/grub-core/commands/ls.c @@ -31,6 +31,7 @@ #include #include #include +#include static const struct grub_arg_option options[] = { @@ -45,6 +46,8 @@ static const char grub_human_sizes[] = {' ', 'K', 'M', 'G', 'T'}; static grub_err_t grub_ls_list_devices (int longlist) { + grub_net_app_level_t proto; + auto int grub_ls_print_devices (const char *name); int grub_ls_print_devices (const char *name) { @@ -58,6 +61,16 @@ grub_ls_list_devices (int longlist) grub_device_iterate (grub_ls_print_devices); grub_xputs ("\n"); + + grub_puts_ (N_ ("Network protocols:\n")); + + FOR_NET_APP_LEVEL (proto) + { + grub_printf ("%s ", proto->name); + } + + grub_xputs ("\n"); + grub_refresh (); return 0; diff --git a/grub-core/commands/net.c b/grub-core/commands/net.c index 904c61a92..2062e1bd0 100644 --- a/grub-core/commands/net.c +++ b/grub-core/commands/net.c @@ -22,30 +22,135 @@ #include #include +struct grub_net_route +{ + struct grub_net_route *next; + grub_net_network_level_netaddress_t target; + char *name; + struct grub_net_network_level_protocol *prot; + int is_gateway; + union + { + struct grub_net_network_level_interface *interface; + grub_net_network_level_address_t gw; + }; +}; + struct grub_net_route *grub_net_routes = NULL; struct grub_net_network_level_interface *grub_net_network_level_interfaces = NULL; struct grub_net_card *grub_net_cards = NULL; struct grub_net_network_level_protocol *grub_net_network_level_protocols = NULL; -grub_err_t -grub_net_resolve_address (struct grub_net_network_level_protocol **prot, - char *name, - grub_net_network_level_address_t *addr) +static inline void +grub_net_network_level_interface_register (struct grub_net_network_level_interface *inter) { - FOR_NET_NETWORK_LEVEL_PROTOCOLS (*prot) + grub_list_push (GRUB_AS_LIST_P (&grub_net_network_level_interfaces), + GRUB_AS_LIST (inter)); +} + +static inline void +grub_net_network_level_interface_unregister (struct grub_net_network_level_interface *inter) +{ + grub_list_remove (GRUB_AS_LIST_P (&grub_net_network_level_interfaces), + GRUB_AS_LIST (inter)); +} + +#define FOR_NET_NETWORK_LEVEL_INTERFACES(var) for (var = grub_net_network_level_interfaces; var; var = var->next) + +static inline void +grub_net_route_register (struct grub_net_route *route) +{ + grub_list_push (GRUB_AS_LIST_P (&grub_net_routes), + GRUB_AS_LIST (route)); +} + +static inline void +grub_net_route_unregister (struct grub_net_route *route) +{ + grub_list_remove (GRUB_AS_LIST_P (&grub_net_routes), + GRUB_AS_LIST (route)); +} + +#define FOR_NET_ROUTES(var) for (var = grub_net_routes; var; var = var->next) + +static int +parse_ip (const char *val, grub_uint32_t *ip, const char **rest) +{ + grub_uint32_t newip = 0; + unsigned long t; + int i; + const char *ptr = val; + + for (i = 0; i < 4; i++) { - grub_err_t err; - err = grub_net_resolve_address_in_protocol (*prot, name, addr); - if (err == GRUB_ERR_NET_BAD_ADDRESS) + t = grub_strtoul (ptr, (char **) &ptr, 0); + if (grub_errno) { grub_errno = GRUB_ERR_NONE; - continue; + return 0; } - if (err) - return err; + if (t & ~0xff) + return 0; + newip >>= 8; + newip |= (t << 24); + if (i != 3 && *ptr != '.') + return 0; + ptr++; + } + *ip = newip; + if (rest) + *rest = ptr - 1; + return 0; +} + +static int +match_net (const grub_net_network_level_netaddress_t *net, + const grub_net_network_level_address_t *addr) +{ + if (net->type != addr->type) + return 0; + switch (net->type) + { + case GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4: + { + grub_int32_t mask = (1 << net->ipv4.masksize) - 1; + return ((net->ipv4.base & mask) == (addr->ipv4 & mask)); + } + } + return 0; +} + +grub_err_t +grub_net_resolve_address (const char *name, + grub_net_network_level_address_t *addr) +{ + if (parse_ip (name, &addr->ipv4, NULL)) + { + addr->type = GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4; return GRUB_ERR_NONE; } - return grub_error (GRUB_ERR_NET_BAD_ADDRESS, N_("Unrecognised address %s"), + return grub_error (GRUB_ERR_NET_BAD_ADDRESS, N_("unrecognised address %s"), + name); +} + +grub_err_t +grub_net_resolve_net_address (const char *name, + grub_net_network_level_netaddress_t *addr) +{ + const char *rest; + if (parse_ip (name, &addr->ipv4.base, &rest)) + { + addr->type = GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4; + if (*rest == '/') + { + addr->ipv4.masksize = grub_strtoul (rest + 1, NULL, 0); + if (!grub_errno) + return GRUB_ERR_NONE; + } + addr->ipv4.masksize = 32; + return GRUB_ERR_NONE; + } + return grub_error (GRUB_ERR_NET_BAD_ADDRESS, N_("unrecognised address %s"), name); } @@ -71,8 +176,7 @@ grub_net_route_address (grub_net_network_level_address_t addr, { if (depth && prot != route->prot) continue; - prot = route->prot; - if (!route->prot->match_net (route->target, curtarget)) + if (!match_net (&route->target, &curtarget)) continue; if (route->is_gateway) @@ -107,7 +211,6 @@ grub_cmd_deladdr (struct grub_command *cmd __attribute__ ((unused)), if (inter == NULL) return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("address not found")); - inter->protocol->fini (inter); grub_net_network_level_interface_unregister (inter); grub_free (inter->name); grub_free (inter); @@ -115,18 +218,35 @@ grub_cmd_deladdr (struct grub_command *cmd __attribute__ ((unused)), return GRUB_ERR_NONE; } +struct grub_net_network_level_interface * +grub_net_add_addr (const char *name, struct grub_net_card *card, + grub_net_network_level_address_t addr) +{ + struct grub_net_network_level_interface *inter; + + inter = grub_zalloc (sizeof (*inter)); + if (!inter) + return NULL; + + inter->name = grub_strdup (name); + grub_memcpy (&(inter->address), &addr, sizeof (inter->address)); + inter->card = card; + + grub_net_network_level_interface_register (inter); + + return inter; +} + static grub_err_t grub_cmd_addaddr (struct grub_command *cmd __attribute__ ((unused)), int argc, char **args) { struct grub_net_card *card; - struct grub_net_network_level_protocol *prot; - grub_err_t err; grub_net_network_level_address_t addr; - struct grub_net_network_level_interface *inter; + grub_err_t err; - if (argc != 4) - return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("four arguments expected")); + if (argc != 3) + return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("three arguments expected")); FOR_NET_CARDS (card) if (grub_strcmp (card->name, args[1])) @@ -134,36 +254,12 @@ grub_cmd_addaddr (struct grub_command *cmd __attribute__ ((unused)), if (card == NULL) return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("card not found")); - FOR_NET_NETWORK_LEVEL_PROTOCOLS (prot) - if (grub_strcmp (prot->name, args[2])) - break; - - if (card == NULL) - return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("protocol not found")); - - err = grub_net_resolve_address_in_protocol (prot, args[3], &addr); + err = grub_net_resolve_address (args[2], &addr); if (err) return err; - inter = grub_zalloc (sizeof (*inter)); - if (!inter) - return grub_errno; - - inter->name = grub_strdup (args[0]); - inter->protocol = prot; - grub_memcpy (&(inter->address), &addr, sizeof (inter->address)); - inter->card = card; - - err = prot->init (inter); - if (err) - { - grub_free (inter->name); - grub_free (inter); - return err; - } - grub_net_network_level_interface_register (inter); - - return GRUB_ERR_NONE; + grub_net_add_addr (args[0], card, addr); + return grub_errno; } static grub_err_t @@ -188,84 +284,157 @@ grub_cmd_delroute (struct grub_command *cmd __attribute__ ((unused)), return GRUB_ERR_NONE; } -static grub_err_t -grub_cmd_addroute (struct grub_command *cmd __attribute__ ((unused)), - int argc, char **args) +grub_err_t +grub_net_add_route (const char *name, + grub_net_network_level_netaddress_t target, + struct grub_net_network_level_interface *inter) { - struct grub_net_network_level_protocol *prot; struct grub_net_route *route; - if (argc < 3) - return grub_error (GRUB_ERR_BAD_ARGUMENT, - N_("At least 3 arguments are expected")); - route = grub_zalloc (sizeof (*route)); if (!route) return grub_errno; - route->name = grub_strdup (args[0]); + route->name = grub_strdup (name); if (!route->name) { grub_free (route); return grub_errno; } - FOR_NET_NETWORK_LEVEL_PROTOCOLS(prot) - { - grub_err_t err; - err = prot->net_ntoa (args[1], &(route->target)); - if (err == GRUB_ERR_NET_BAD_ADDRESS) - { - grub_errno = GRUB_ERR_NONE; - continue; - } - if (err) - return err; - break; - } - - if (!prot) + route->target = target; + route->is_gateway = 0; + route->interface = inter; + + grub_net_route_register (route); + + return GRUB_ERR_NONE; +} + +grub_err_t +grub_net_add_route_gw (const char *name, + grub_net_network_level_netaddress_t target, + grub_net_network_level_address_t gw) +{ + struct grub_net_route *route; + + route = grub_zalloc (sizeof (*route)); + if (!route) + return grub_errno; + + route->name = grub_strdup (name); + if (!route->name) { - grub_free (route->name); grub_free (route); - return grub_error (GRUB_ERR_NET_BAD_ADDRESS, - N_("Unrecognised address %s"), args[1]); + return grub_errno; } + route->target = target; + route->is_gateway = 1; + route->gw = gw; + + grub_net_route_register (route); + + return GRUB_ERR_NONE; +} + +static grub_err_t +grub_cmd_addroute (struct grub_command *cmd __attribute__ ((unused)), + int argc, char **args) +{ + grub_net_network_level_netaddress_t target; + if (argc < 3) + return grub_error (GRUB_ERR_BAD_ARGUMENT, + N_("At least 3 arguments are expected")); + + grub_net_resolve_net_address (args[1], &target); + if (grub_strcmp (args[2], "gw") == 0 && argc >= 4) { grub_err_t err; - route->is_gateway = 1; - err = grub_net_resolve_address_in_protocol (prot, - args[3], &(route->gw)); + grub_net_network_level_address_t gw; + + err = grub_net_resolve_address (args[3], &gw); if (err) - { - grub_free (route->name); - grub_free (route); - return err; - } + return err; + return grub_net_add_route_gw (args[0], target, gw); } else { struct grub_net_network_level_interface *inter; - route->is_gateway = 0; FOR_NET_NETWORK_LEVEL_INTERFACES (inter) if (grub_strcmp (inter->name, args[2])) break; if (!inter) - { - grub_free (route->name); - grub_free (route); - return grub_error (GRUB_ERR_BAD_ARGUMENT, - N_("Unrecognised interface %s"), args[2]); - } - route->interface = inter; + return grub_error (GRUB_ERR_BAD_ARGUMENT, + N_("unrecognised interface %s"), args[2]); + return grub_net_add_route (args[0], target, inter); } +} - grub_net_route_register (route); +static void +print_net_address (const grub_net_network_level_netaddress_t *target) +{ + switch (target->type) + { + case GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4: + grub_printf ("%d.%d.%d.%d/%d ", ((target->ipv4.base >> 24) & 0xff), + ((target->ipv4.base >> 16) & 0xff), + ((target->ipv4.base >> 8) & 0xff), + ((target->ipv4.base >> 0) & 0xff), + target->ipv4.masksize); + break; + } +} +static void +print_address (const grub_net_network_level_address_t *target) +{ + switch (target->type) + { + case GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4: + grub_printf ("%d.%d.%d.%d ", ((target->ipv4 >> 24) & 0xff), + ((target->ipv4 >> 16) & 0xff), + ((target->ipv4 >> 8) & 0xff), + ((target->ipv4 >> 0) & 0xff)); + break; + } +} + +static grub_err_t +grub_cmd_listroutes (struct grub_command *cmd __attribute__ ((unused)), + int argc __attribute__ ((unused)), + char **args __attribute__ ((unused))) +{ + struct grub_net_route *route; + FOR_NET_ROUTES(route) + { + grub_printf ("%s ", route->name); + print_net_address (&route->target); + if (route->is_gateway) + { + grub_printf ("gw "); + print_address (&route->gw); + } + else + grub_printf ("%s", route->interface->name); + } + return GRUB_ERR_NONE; +} + +static grub_err_t +grub_cmd_listcards (struct grub_command *cmd __attribute__ ((unused)), + int argc __attribute__ ((unused)), + char **args __attribute__ ((unused))) +{ + struct grub_net_card *card; + FOR_NET_CARDS(card) + { + grub_printf ("%s ", card->name); + } + grub_printf ("\n"); return GRUB_ERR_NONE; } @@ -301,11 +470,12 @@ grub_net_open_real (const char *name) } static grub_command_t cmd_addaddr, cmd_deladdr, cmd_addroute, cmd_delroute; +static grub_command_t cmd_lsroutes, cmd_lscards; GRUB_MOD_INIT(net) { cmd_addaddr = grub_register_command ("net_add_addr", grub_cmd_addaddr, - "SHORTNAME CARD PROTOCOL ADDRESS", + "SHORTNAME CARD ADDRESS", N_("Add a network address.")); cmd_deladdr = grub_register_command ("net_del_addr", grub_cmd_deladdr, "SHORTNAME", @@ -316,6 +486,11 @@ GRUB_MOD_INIT(net) cmd_delroute = grub_register_command ("net_del_route", grub_cmd_delroute, "SHORTNAME", N_("Delete a network route.")); + cmd_lsroutes = grub_register_command ("net_ls_routes", grub_cmd_listroutes, + "", N_("list network routes")); + cmd_lscards = grub_register_command ("net_ls_cards", grub_cmd_listcards, + "", N_("list network cards")); + grub_net_open = grub_net_open_real; } @@ -325,5 +500,7 @@ GRUB_MOD_FINI(net) grub_unregister_command (cmd_deladdr); grub_unregister_command (cmd_addroute); grub_unregister_command (cmd_delroute); + grub_unregister_command (cmd_lsroutes); + grub_unregister_command (cmd_lscards); grub_net_open = NULL; } diff --git a/grub-core/fs/i386/pc/pxe.c b/grub-core/fs/i386/pc/pxe.c index 0dd44a30a..20d0e1979 100644 --- a/grub-core/fs/i386/pc/pxe.c +++ b/grub-core/fs/i386/pc/pxe.c @@ -18,9 +18,8 @@ */ #include -#include +#include #include -#include #include #include #include @@ -33,13 +32,7 @@ #define SEGMENT(x) ((x) >> 4) #define OFFSET(x) ((x) & 0xF) #define SEGOFS(x) ((SEGMENT(x) << 16) + OFFSET(x)) -#define LINEAR(x) (void *) (((x >> 16) <<4) + (x & 0xFFFF)) - -struct grub_pxe_disk_data -{ - grub_uint32_t server_ip; - grub_uint32_t gateway_ip; -}; +#define LINEAR(x) (void *) (((x >> 16) << 4) + (x & 0xFFFF)) struct grub_pxenv *grub_pxe_pxenv; static grub_uint32_t grub_pxe_your_ip; @@ -53,6 +46,8 @@ struct grub_pxe_data { grub_uint32_t packet_number; grub_uint32_t block_size; + grub_uint32_t server_ip; + grub_uint32_t gateway_ip; char filename[0]; }; @@ -95,55 +90,33 @@ grub_pxe_scan (void) return ret; } -static int -grub_pxe_iterate (int (*hook) (const char *name)) +static grub_err_t +grub_pxefs_dir (grub_device_t device __attribute__ ((unused)), + const char *path __attribute__ ((unused)), + int (*hook) (const char *filename, + const struct grub_dirhook_info *info) + __attribute__ ((unused))) { - if (hook ("pxe")) - return 1; - return 0; + return GRUB_ERR_NONE; } static grub_err_t -parse_ip (const char *val, grub_uint32_t *ip, const char **rest) +grub_pxefs_open (struct grub_file *file, const char *name) { - grub_uint32_t newip = 0; - unsigned long t; - int i; - const char *ptr = val; - - for (i = 0; i < 4; i++) + union { - t = grub_strtoul (ptr, (char **) &ptr, 0); - if (grub_errno) - return grub_errno; - if (t & ~0xff) - return grub_error (GRUB_ERR_OUT_OF_RANGE, "Invalid IP."); - newip >>= 8; - newip |= (t << 24); - if (i != 3 && *ptr != '.') - return grub_error (GRUB_ERR_OUT_OF_RANGE, "Invalid IP."); - ptr++; - } - *ip = newip; - if (rest) - *rest = ptr - 1; - return 0; -} - -static grub_err_t -grub_pxe_open (const char *name, grub_disk_t disk) -{ - struct grub_pxe_disk_data *data; - - if (grub_strcmp (name, "pxe") != 0 - && grub_strncmp (name, "pxe:", sizeof ("pxe:") - 1) != 0) - return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "not a pxe disk"); + struct grub_pxenv_tftp_get_fsize c1; + struct grub_pxenv_tftp_open c2; + } c; + struct grub_pxe_data *data; + grub_file_t file_int, bufio; data = grub_malloc (sizeof (*data)); if (!data) return grub_errno; - if (grub_strncmp (name, "pxe:", sizeof ("pxe:") - 1) == 0) +#if 0 + if (grub_strncmp (file->device->net->name, "pxe:", sizeof ("pxe:") - 1) == 0) { const char *ptr; grub_err_t err; @@ -161,93 +134,44 @@ grub_pxe_open (const char *name, grub_disk_t disk) else data->gateway_ip = grub_pxe_default_gateway_ip; } - else + else +#endif { - data->server_ip = grub_pxe_default_server_ip; - data->gateway_ip = grub_pxe_default_gateway_ip; + grub_net_network_level_address_t addr; + grub_net_network_level_address_t gateway; + struct grub_net_network_level_interface *interf; + grub_err_t err; + + if (grub_strncmp (file->device->net->name, + "pxe,", sizeof ("pxe,") - 1) == 0) + { + const char *ptr; + + ptr = name + sizeof ("pxe,") - 1; + err = grub_net_resolve_address (name + sizeof ("pxe,") - 1, &addr); + if (err) + return err; + } + else + { + addr.ipv4 = grub_pxe_default_server_ip; + addr.type = GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4; + } + err = grub_net_route_address (addr, &gateway, &interf); + if (err) + return err; + data->server_ip = addr.ipv4; + data->gateway_ip = gateway.ipv4; } - disk->total_sectors = 0; - disk->id = (unsigned long) data; - - disk->has_partitions = 0; - disk->data = data; - - return GRUB_ERR_NONE; -} - -static void -grub_pxe_close (grub_disk_t disk) -{ - grub_free (disk->data); -} - -static grub_err_t -grub_pxe_read (grub_disk_t disk __attribute((unused)), - grub_disk_addr_t sector __attribute((unused)), - grub_size_t size __attribute((unused)), - char *buf __attribute((unused))) -{ - return GRUB_ERR_OUT_OF_RANGE; -} - -static grub_err_t -grub_pxe_write (grub_disk_t disk __attribute((unused)), - grub_disk_addr_t sector __attribute((unused)), - grub_size_t size __attribute((unused)), - const char *buf __attribute((unused))) -{ - return GRUB_ERR_OUT_OF_RANGE; -} - -static struct grub_disk_dev grub_pxe_dev = - { - .name = "pxe", - .id = GRUB_DISK_DEVICE_PXE_ID, - .iterate = grub_pxe_iterate, - .open = grub_pxe_open, - .close = grub_pxe_close, - .read = grub_pxe_read, - .write = grub_pxe_write, - .next = 0 - }; - -static grub_err_t -grub_pxefs_dir (grub_device_t device, - const char *path __attribute__ ((unused)), - int (*hook) (const char *filename, - const struct grub_dirhook_info *info) - __attribute__ ((unused))) -{ - if (device->disk->dev->id != GRUB_DISK_DEVICE_PXE_ID) - return grub_error (GRUB_ERR_IO, "not a pxe disk"); - - return GRUB_ERR_NONE; -} - -static grub_err_t -grub_pxefs_open (struct grub_file *file, const char *name) -{ - union - { - struct grub_pxenv_tftp_get_fsize c1; - struct grub_pxenv_tftp_open c2; - } c; - struct grub_pxe_data *data; - struct grub_pxe_disk_data *disk_data = file->device->disk->data; - grub_file_t file_int, bufio; - - if (file->device->disk->dev->id != GRUB_DISK_DEVICE_PXE_ID) - return grub_error (GRUB_ERR_IO, "not a pxe disk"); - if (curr_file != 0) { grub_pxe_call (GRUB_PXENV_TFTP_CLOSE, &c.c2, pxe_rm_entry); curr_file = 0; } - c.c1.server_ip = disk_data->server_ip; - c.c1.gateway_ip = disk_data->gateway_ip; + c.c1.server_ip = data->server_ip; + c.c1.gateway_ip = data->gateway_ip; grub_strcpy ((char *)&c.c1.filename[0], name); grub_pxe_call (GRUB_PXENV_TFTP_GET_FSIZE, &c.c1, pxe_rm_entry); if (c.c1.status) @@ -297,7 +221,6 @@ grub_pxefs_read (grub_file_t file, char *buf, grub_size_t len) { struct grub_pxenv_tftp_read c; struct grub_pxe_data *data; - struct grub_pxe_disk_data *disk_data = file->device->disk->data; grub_uint32_t pn, r; data = file->data; @@ -317,8 +240,8 @@ grub_pxefs_read (grub_file_t file, char *buf, grub_size_t len) if (curr_file != 0) grub_pxe_call (GRUB_PXENV_TFTP_CLOSE, &o, pxe_rm_entry); - o.server_ip = disk_data->server_ip; - o.gateway_ip = disk_data->gateway_ip; + o.server_ip = data->server_ip; + o.gateway_ip = data->gateway_ip; grub_strcpy ((char *)&o.filename[0], data->filename); o.tftp_port = grub_cpu_to_be16 (GRUB_PXE_TFTP_PORT); o.packet_size = grub_pxe_blksize; @@ -513,18 +436,46 @@ grub_pxe_detect (void) grub_pxe_pxenv = pxenv; } +static grub_size_t +grub_pxe_recv (struct grub_net_card *dev __attribute__ ((unused)), + void *buf __attribute__ ((unused)), + grub_size_t buflen __attribute__ ((unused))) +{ + return 0; +} + +static grub_err_t +grub_pxe_send (struct grub_net_card *dev __attribute__ ((unused)), + void *buf __attribute__ ((unused)), + grub_size_t buflen __attribute__ ((unused))) +{ + return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, "not implemented"); +} + +struct grub_net_card_driver grub_pxe_card_driver = +{ + .send = grub_pxe_send, + .recv = grub_pxe_recv +}; + +struct grub_net_card grub_pxe_card = +{ + .driver = &grub_pxe_card_driver, + .name = "pxe" +}; + void grub_pxe_unload (void) { if (grub_pxe_pxenv) { - grub_fs_unregister (&grub_pxefs_fs); - grub_disk_dev_unregister (&grub_pxe_dev); - + grub_net_app_level_unregister (&grub_pxefs_fs); + grub_net_card_unregister (&grub_pxe_card); grub_pxe_pxenv = 0; } } +#if 0 static void set_ip_env (char *varname, grub_uint32_t ip) { @@ -556,7 +507,9 @@ write_ip_env (grub_uint32_t *ip, const char *val) return buf; } +#endif +#if 0 static char * grub_env_write_pxe_default_server (struct grub_env_var *var __attribute__ ((unused)), @@ -572,6 +525,7 @@ grub_env_write_pxe_default_gateway (struct grub_env_var *var { return write_ip_env (&grub_pxe_default_gateway_ip, val); } +#endif static char * grub_env_write_pxe_blocksize (struct grub_env_var *var __attribute__ ((unused)), @@ -598,34 +552,58 @@ grub_env_write_pxe_blocksize (struct grub_env_var *var __attribute__ ((unused)), return buf; } - GRUB_MOD_INIT(pxe) { grub_pxe_detect (); if (grub_pxe_pxenv) { char *buf; + grub_net_network_level_address_t addr; + struct grub_net_network_level_interface *inter; + +#if 0 + grub_register_variable_hook ("pxe_default_server", 0, + grub_env_write_pxe_default_server); + grub_register_variable_hook ("pxe_default_gateway", 0, + grub_env_write_pxe_default_gateway); +#endif + grub_register_variable_hook ("pxe_blksize", 0, + grub_env_write_pxe_blocksize); buf = grub_xasprintf ("%d", grub_pxe_blksize); if (buf) grub_env_set ("pxe_blksize", buf); grub_free (buf); +#if 0 set_ip_env ("pxe_default_server", grub_pxe_default_server_ip); - set_ip_env ("pxe_default_gateway", grub_pxe_default_gateway_ip); - set_ip_env ("net_pxe_ip", grub_pxe_your_ip); - grub_register_variable_hook ("pxe_default_server", 0, - grub_env_write_pxe_default_server); - grub_register_variable_hook ("pxe_default_gateway", 0, - grub_env_write_pxe_default_gateway); +#endif - /* XXX: Is it possible to change IP in PXE? */ - grub_register_variable_hook ("net_pxe_ip", 0, - grub_env_write_readonly); - grub_register_variable_hook ("pxe_blksize", 0, - grub_env_write_pxe_blocksize); - grub_disk_dev_register (&grub_pxe_dev); - grub_fs_register (&grub_pxefs_fs); + grub_net_app_level_register (&grub_pxefs_fs); + grub_net_card_register (&grub_pxe_card); + addr.type = GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4; + addr.ipv4 = grub_pxe_your_ip; + inter = grub_net_add_addr ("pxe", &grub_pxe_card, addr); + if (grub_pxe_default_gateway_ip) + { + grub_net_network_level_netaddress_t target; + grub_net_network_level_address_t gw; + + target.type = GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4; + target.ipv4.base = grub_pxe_default_server_ip; + target.ipv4.masksize = 32; + gw.type = GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4; + gw.ipv4 = grub_pxe_default_gateway_ip; + grub_net_add_route_gw ("pxe_default", target, gw); + } + { + grub_net_network_level_netaddress_t target; + target.type = GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4; + target.ipv4.base = grub_pxe_default_gateway_ip ? + : grub_pxe_default_server_ip; + target.ipv4.masksize = 32; + grub_net_add_route ("pxe_default", target, inter); + } } } diff --git a/include/grub/net.h b/include/grub/net.h index b5e852f9b..84e881efe 100644 --- a/include/grub/net.h +++ b/include/grub/net.h @@ -54,71 +54,37 @@ struct grub_net_card struct grub_net_network_level_interface; +typedef enum grub_network_level_protocol_id +{ + GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4 +} grub_network_level_protocol_id_t; + typedef union grub_net_network_level_address { + grub_network_level_protocol_id_t type; grub_uint32_t ipv4; } grub_net_network_level_address_t; typedef union grub_net_network_level_netaddress { + grub_network_level_protocol_id_t type; struct { grub_uint32_t base; int masksize; } ipv4; } grub_net_network_level_netaddress_t; -typedef enum grub_network_level_protocol_id -{ - GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4 -} grub_network_level_protocol_id_t; - struct grub_net_network_level_interface; -struct grub_net_network_level_protocol -{ - struct grub_net_network_level_protocol *next; - char *name; - grub_network_level_protocol_id_t id; - grub_err_t (*ntoa) (char *name, grub_net_network_level_address_t *addr); - char * (*aton) (union grub_net_network_level_address addr); - grub_err_t (*net_ntoa) (char *name, - grub_net_network_level_netaddress_t *addr); - char * (*net_aton) (grub_net_network_level_netaddress_t addr); - int (* match_net) (grub_net_network_level_netaddress_t net, - grub_net_network_level_address_t addr); - grub_err_t (*init) (struct grub_net_network_level_interface *dev); - grub_err_t (*fini) (struct grub_net_network_level_interface *dev); - grub_err_t (*send) (struct grub_net_network_level_interface *dev, void *buf, - grub_size_t buflen); - grub_size_t (*recv) (struct grub_net_network_level_interface *dev, void *buf, - grub_size_t buflen); -}; - struct grub_net_network_level_interface { struct grub_net_network_level_interface *next; char *name; - /* Underlying protocol. */ - struct grub_net_network_level_protocol *protocol; struct grub_net_card *card; union grub_net_network_level_address address; void *data; }; -struct grub_net_route -{ - struct grub_net_route *next; - grub_net_network_level_netaddress_t target; - char *name; - struct grub_net_network_level_protocol *prot; - int is_gateway; - union - { - struct grub_net_network_level_interface *interface; - grub_net_network_level_address_t gw; - }; -}; - struct grub_net_session; struct grub_net_session_level_protocol @@ -156,24 +122,12 @@ grub_net_session_recv (struct grub_net_session *session, void *buf, return session->protocol->recv (session, buf, size); } +struct grub_net_network_level_interface * +grub_net_add_addr (const char *name, struct grub_net_card *card, + grub_net_network_level_address_t addr); + extern struct grub_net_network_level_interface *grub_net_network_level_interfaces; -static inline void -grub_net_network_level_interface_register (struct grub_net_network_level_interface *inter) -{ - grub_list_push (GRUB_AS_LIST_P (&grub_net_network_level_interfaces), - GRUB_AS_LIST (inter)); -} - -static inline void -grub_net_network_level_interface_unregister (struct grub_net_network_level_interface *inter) -{ - grub_list_remove (GRUB_AS_LIST_P (&grub_net_network_level_interfaces), - GRUB_AS_LIST (inter)); -} - -#define FOR_NET_NETWORK_LEVEL_INTERFACES(var) for (var = grub_net_network_level_interfaces; var; var = var->next) - extern grub_net_app_level_t grub_net_app_level_list; #ifndef GRUB_LST_GENERATOR @@ -195,25 +149,6 @@ grub_net_app_level_unregister (grub_net_app_level_t proto) #define FOR_NET_APP_LEVEL(var) FOR_LIST_ELEMENTS((var), \ (grub_net_app_level_list)) - -extern struct grub_net_route *grub_net_routes; - -static inline void -grub_net_route_register (struct grub_net_route *route) -{ - grub_list_push (GRUB_AS_LIST_P (&grub_net_routes), - GRUB_AS_LIST (route)); -} - -static inline void -grub_net_route_unregister (struct grub_net_route *route) -{ - grub_list_remove (GRUB_AS_LIST_P (&grub_net_routes), - GRUB_AS_LIST (route)); -} - -#define FOR_NET_ROUTES(var) for (var = grub_net_routes; var; var = var->next) - extern struct grub_net_card *grub_net_cards; static inline void @@ -232,44 +167,32 @@ grub_net_card_unregister (struct grub_net_card *card) #define FOR_NET_CARDS(var) for (var = grub_net_cards; var; var = var->next) -extern struct grub_net_network_level_protocol *grub_net_network_level_protocols; - -static inline void -grub_net_network_level_protocol_register (struct grub_net_network_level_protocol *prot) -{ - grub_list_push (GRUB_AS_LIST_P (&grub_net_network_level_protocols), - GRUB_AS_LIST (prot)); -} - -static inline void -grub_net_network_level_protocol_unregister (struct grub_net_network_level_protocol *prot) -{ - grub_list_remove (GRUB_AS_LIST_P (&grub_net_network_level_protocols), - GRUB_AS_LIST (prot)); -} - -#define FOR_NET_NETWORK_LEVEL_PROTOCOLS(var) for ((var) = grub_net_network_level_protocols; (var); (var) = (var)->next) - -static inline grub_err_t -grub_net_resolve_address_in_protocol (struct grub_net_network_level_protocol *prot, - char *name, - grub_net_network_level_address_t *addr) -{ - return prot->ntoa (name, addr); -} - struct grub_net_session * grub_net_open_tcp (char *address, grub_uint16_t port); grub_err_t -grub_net_resolve_address (struct grub_net_network_level_protocol **prot, - char *name, +grub_net_resolve_address (const char *name, grub_net_network_level_address_t *addr); +grub_err_t +grub_net_resolve_net_address (const char *name, + grub_net_network_level_netaddress_t *addr); + grub_err_t grub_net_route_address (grub_net_network_level_address_t addr, grub_net_network_level_address_t *gateway, struct grub_net_network_level_interface **interf); +grub_err_t +grub_net_add_route (const char *name, + grub_net_network_level_netaddress_t target, + struct grub_net_network_level_interface *inter); + +grub_err_t +grub_net_add_route_gw (const char *name, + grub_net_network_level_netaddress_t target, + grub_net_network_level_address_t gw); + + #endif /* ! GRUB_NET_HEADER */ From e571f2332e90dec534f0b8beb1a943b699c1271b Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Thu, 2 Sep 2010 18:15:59 +0200 Subject: [PATCH 040/869] Fix regressions by previous commits --- grub-core/commands/ls.c | 6 ++++-- grub-core/commands/net.c | 38 +++++++++++++++++++++++++------------- grub-core/fs/i386/pc/pxe.c | 8 ++++---- grub-core/kern/device.c | 7 +++++-- include/grub/net.h | 22 ++++++++++++++-------- 5 files changed, 52 insertions(+), 29 deletions(-) diff --git a/grub-core/commands/ls.c b/grub-core/commands/ls.c index 3179d271e..300c21cc9 100644 --- a/grub-core/commands/ls.c +++ b/grub-core/commands/ls.c @@ -47,6 +47,7 @@ static grub_err_t grub_ls_list_devices (int longlist) { grub_net_app_level_t proto; + int first = 1; auto int grub_ls_print_devices (const char *name); int grub_ls_print_devices (const char *name) @@ -62,10 +63,11 @@ grub_ls_list_devices (int longlist) grub_device_iterate (grub_ls_print_devices); grub_xputs ("\n"); - grub_puts_ (N_ ("Network protocols:\n")); - FOR_NET_APP_LEVEL (proto) { + if (first) + grub_puts_ (N_ ("Network protocols:")); + first = 0; grub_printf ("%s ", proto->name); } diff --git a/grub-core/commands/net.c b/grub-core/commands/net.c index 2062e1bd0..9d28c2ff7 100644 --- a/grub-core/commands/net.c +++ b/grub-core/commands/net.c @@ -97,7 +97,7 @@ parse_ip (const char *val, grub_uint32_t *ip, const char **rest) return 0; ptr++; } - *ip = newip; + *ip = grub_cpu_to_le32 (newip); if (rest) *rest = ptr - 1; return 0; @@ -114,7 +114,8 @@ match_net (const grub_net_network_level_netaddress_t *net, case GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4: { grub_int32_t mask = (1 << net->ipv4.masksize) - 1; - return ((net->ipv4.base & mask) == (addr->ipv4 & mask)); + return ((grub_be_to_cpu32 (net->ipv4.base) & mask) + == (grub_be_to_cpu32 (addr->ipv4) & mask)); } } return 0; @@ -380,13 +381,17 @@ print_net_address (const grub_net_network_level_netaddress_t *target) switch (target->type) { case GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4: - grub_printf ("%d.%d.%d.%d/%d ", ((target->ipv4.base >> 24) & 0xff), - ((target->ipv4.base >> 16) & 0xff), - ((target->ipv4.base >> 8) & 0xff), - ((target->ipv4.base >> 0) & 0xff), - target->ipv4.masksize); - break; + { + grub_uint32_t n = grub_be_to_cpu32 (target->ipv4.base); + grub_printf ("%d.%d.%d.%d/%d ", ((n >> 24) & 0xff), + ((n >> 16) & 0xff), + ((n >> 8) & 0xff), + ((n >> 0) & 0xff), + target->ipv4.masksize); + } + return; } + grub_printf ("Unknown address type %d\n", target->type); } static void @@ -395,12 +400,16 @@ print_address (const grub_net_network_level_address_t *target) switch (target->type) { case GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4: - grub_printf ("%d.%d.%d.%d ", ((target->ipv4 >> 24) & 0xff), - ((target->ipv4 >> 16) & 0xff), - ((target->ipv4 >> 8) & 0xff), - ((target->ipv4 >> 0) & 0xff)); - break; + { + grub_uint32_t n = grub_be_to_cpu32 (target->ipv4); + grub_printf ("%d.%d.%d.%d ", ((n >> 24) & 0xff), + ((n >> 16) & 0xff), + ((n >> 8) & 0xff), + ((n >> 0) & 0xff)); + } + return; } + grub_printf ("Unknown address type %d\n", target->type); } static grub_err_t @@ -420,6 +429,7 @@ grub_cmd_listroutes (struct grub_command *cmd __attribute__ ((unused)), } else grub_printf ("%s", route->interface->name); + grub_printf ("\n"); } return GRUB_ERR_NONE; } @@ -466,6 +476,8 @@ grub_net_open_real (const char *name) return ret; } } + grub_error (GRUB_ERR_UNKNOWN_DEVICE, "no such device"); + return NULL; } diff --git a/grub-core/fs/i386/pc/pxe.c b/grub-core/fs/i386/pc/pxe.c index eac3bf770..85d138bb0 100644 --- a/grub-core/fs/i386/pc/pxe.c +++ b/grub-core/fs/i386/pc/pxe.c @@ -306,7 +306,7 @@ grub_pxefs_label (grub_device_t device __attribute ((unused)), static struct grub_fs grub_pxefs_fs = { - .name = "pxefs", + .name = "pxe", .dir = grub_pxefs_dir, .open = grub_pxefs_open, .read = grub_pxefs_read, @@ -590,7 +590,7 @@ GRUB_MOD_INIT(pxe) addr.type = GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4; addr.ipv4 = grub_pxe_your_ip; inter = grub_net_add_addr ("pxe", &grub_pxe_card, addr); - if (grub_pxe_default_gateway_ip) + if (grub_pxe_default_gateway_ip != grub_pxe_default_server_ip) { grub_net_network_level_netaddress_t target; grub_net_network_level_address_t gw; @@ -600,7 +600,7 @@ GRUB_MOD_INIT(pxe) target.ipv4.masksize = 32; gw.type = GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4; gw.ipv4 = grub_pxe_default_gateway_ip; - grub_net_add_route_gw ("pxe_default", target, gw); + grub_net_add_route_gw ("pxe_gw", target, gw); } { grub_net_network_level_netaddress_t target; @@ -608,7 +608,7 @@ GRUB_MOD_INIT(pxe) target.ipv4.base = grub_pxe_default_gateway_ip ? : grub_pxe_default_server_ip; target.ipv4.masksize = 32; - grub_net_add_route ("pxe_default", target, inter); + grub_net_add_route ("pxe", target, inter); } } } diff --git a/grub-core/kern/device.c b/grub-core/kern/device.c index 9de545910..545487a6b 100644 --- a/grub-core/kern/device.c +++ b/grub-core/kern/device.c @@ -53,8 +53,11 @@ grub_device_open (const char *name) dev->disk = grub_disk_open (name); if (dev->disk) return dev; - if (grub_net_open) - dev->net = grub_net_open (name); + if (grub_net_open && grub_errno == GRUB_ERR_UNKNOWN_DEVICE) + { + grub_errno = GRUB_ERR_NONE; + dev->net = grub_net_open (name); + } if (dev->net) return dev; diff --git a/include/grub/net.h b/include/grub/net.h index 84e881efe..4efd79f79 100644 --- a/include/grub/net.h +++ b/include/grub/net.h @@ -59,19 +59,25 @@ typedef enum grub_network_level_protocol_id GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4 } grub_network_level_protocol_id_t; -typedef union grub_net_network_level_address +typedef struct grub_net_network_level_address { grub_network_level_protocol_id_t type; - grub_uint32_t ipv4; + union + { + grub_uint32_t ipv4; + }; } grub_net_network_level_address_t; -typedef union grub_net_network_level_netaddress +typedef struct grub_net_network_level_netaddress { grub_network_level_protocol_id_t type; - struct { - grub_uint32_t base; - int masksize; - } ipv4; + union + { + struct { + grub_uint32_t base; + int masksize; + } ipv4; + }; } grub_net_network_level_netaddress_t; struct grub_net_network_level_interface; @@ -81,7 +87,7 @@ struct grub_net_network_level_interface struct grub_net_network_level_interface *next; char *name; struct grub_net_card *card; - union grub_net_network_level_address address; + grub_net_network_level_address_t address; void *data; }; From 0f37e4936515fb9d2c2204d3640d33a2a5ae4595 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Thu, 2 Sep 2010 20:00:56 +0200 Subject: [PATCH 041/869] Implement few variables --- grub-core/commands/net.c | 141 +++++++++++++++++++++++++++++++------ grub-core/fs/i386/pc/pxe.c | 35 +++------ include/grub/net.h | 35 ++++++++- 3 files changed, 161 insertions(+), 50 deletions(-) diff --git a/grub-core/commands/net.c b/grub-core/commands/net.c index 9d28c2ff7..5a21178e5 100644 --- a/grub-core/commands/net.c +++ b/grub-core/commands/net.c @@ -21,6 +21,7 @@ #include #include #include +#include struct grub_net_route { @@ -41,13 +42,6 @@ struct grub_net_network_level_interface *grub_net_network_level_interfaces = NUL struct grub_net_card *grub_net_cards = NULL; struct grub_net_network_level_protocol *grub_net_network_level_protocols = NULL; -static inline void -grub_net_network_level_interface_register (struct grub_net_network_level_interface *inter) -{ - grub_list_push (GRUB_AS_LIST_P (&grub_net_network_level_interfaces), - GRUB_AS_LIST (inter)); -} - static inline void grub_net_network_level_interface_unregister (struct grub_net_network_level_interface *inter) { @@ -212,6 +206,10 @@ grub_cmd_deladdr (struct grub_command *cmd __attribute__ ((unused)), if (inter == NULL) return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("address not found")); + if (inter->flags & GRUB_NET_INTERFACE_PERMANENT) + return grub_error (GRUB_ERR_IO, + N_("you can't delete this address")); + grub_net_network_level_interface_unregister (inter); grub_free (inter->name); grub_free (inter); @@ -219,9 +217,104 @@ grub_cmd_deladdr (struct grub_command *cmd __attribute__ ((unused)), return GRUB_ERR_NONE; } +/* + Currently suppoerted adresses: + IPv4: XXX.XXX.XXX.XXX + */ +#define MAX_STR_ADDR_LEN sizeof ("XXX.XXX.XXX.XXX") + +static void +addr_to_str (const grub_net_network_level_address_t *target, char *buf) +{ + switch (target->type) + { + case GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4: + { + grub_uint32_t n = grub_be_to_cpu32 (target->ipv4); + grub_snprintf (buf, MAX_STR_ADDR_LEN, "%d.%d.%d.%d", + ((n >> 24) & 0xff), ((n >> 16) & 0xff), + ((n >> 8) & 0xff), ((n >> 0) & 0xff)); + } + return; + } + grub_printf ("Unknown address type %d\n", target->type); +} + +/* + Currently suppoerted adresses: + ethernet: XX:XX:XX:XX:XX:XX + */ + +#define MAX_STR_HWADDR_LEN (sizeof ("XX:XX:XX:XX:XX:XX")) + +static void +hwaddr_to_str (const grub_net_link_level_address_t *addr, char *str) +{ + str[0] = 0; + switch (addr->type) + { + case GRUB_NET_LINK_LEVEL_PROTOCOL_ETHERNET: + { + char *ptr; + unsigned i; + for (ptr = str, i = 0; i < ARRAY_SIZE (addr->mac); i++) + { + grub_snprintf (ptr, MAX_STR_HWADDR_LEN - (ptr - str), + "%02x:", addr->mac[i] & 0xff); + ptr += (sizeof ("XX:") - 1); + } + return; + } + } + grub_printf ("Unsupported hw address type %d\n", addr->type); +} + +/* FIXME: implement this. */ +static char * +hwaddr_set_env (struct grub_env_var *var __attribute__ ((unused)), + const char *val __attribute__ ((unused))) +{ + return NULL; +} + +/* FIXME: implement this. */ +static char * +addr_set_env (struct grub_env_var *var __attribute__ ((unused)), + const char *val __attribute__ ((unused))) +{ + return NULL; +} + +static void +grub_net_network_level_interface_register (struct grub_net_network_level_interface *inter) +{ + { + char buf[MAX_STR_HWADDR_LEN]; + char name[grub_strlen (inter->name) + sizeof ("net__mac")]; + hwaddr_to_str (&inter->hwaddress, buf); + grub_snprintf (name, sizeof (name), "net_%s_mac", inter->name); + grub_env_set (name, buf); + grub_register_variable_hook (name, 0, hwaddr_set_env); + } + + { + char buf[MAX_STR_ADDR_LEN]; + char name[grub_strlen (inter->name) + sizeof ("net__ip")]; + addr_to_str (&inter->address, buf); + grub_snprintf (name, sizeof (name), "net_%s_ip", inter->name); + grub_env_set (name, buf); + grub_register_variable_hook (name, 0, addr_set_env); + } + + grub_list_push (GRUB_AS_LIST_P (&grub_net_network_level_interfaces), + GRUB_AS_LIST (inter)); +} + struct grub_net_network_level_interface * grub_net_add_addr (const char *name, struct grub_net_card *card, - grub_net_network_level_address_t addr) + grub_net_network_level_address_t addr, + grub_net_link_level_address_t hwaddress, + grub_net_interface_flags_t flags) { struct grub_net_network_level_interface *inter; @@ -231,6 +324,8 @@ grub_net_add_addr (const char *name, struct grub_net_card *card, inter->name = grub_strdup (name); grub_memcpy (&(inter->address), &addr, sizeof (inter->address)); + grub_memcpy (&(inter->hwaddress), &hwaddress, sizeof (inter->hwaddress)); + inter->flags = flags; inter->card = card; grub_net_network_level_interface_register (inter); @@ -238,6 +333,7 @@ grub_net_add_addr (const char *name, struct grub_net_card *card, return inter; } +/* FIXME: support MAC specifying. */ static grub_err_t grub_cmd_addaddr (struct grub_command *cmd __attribute__ ((unused)), int argc, char **args) @@ -245,6 +341,7 @@ grub_cmd_addaddr (struct grub_command *cmd __attribute__ ((unused)), struct grub_net_card *card; grub_net_network_level_address_t addr; grub_err_t err; + grub_net_interface_flags_t flags = 0; if (argc != 3) return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("three arguments expected")); @@ -259,7 +356,15 @@ grub_cmd_addaddr (struct grub_command *cmd __attribute__ ((unused)), if (err) return err; - grub_net_add_addr (args[0], card, addr); + if (card->flags & GRUB_NET_CARD_NO_MANUAL_INTERFACES) + return grub_error (GRUB_ERR_IO, + "this card doesn't support address addition"); + + if (card->flags & GRUB_NET_CARD_HWADDRESS_IMMUTABLE) + flags |= GRUB_NET_INTERFACE_HWADDRESS_IMMUTABLE; + + grub_net_add_addr (args[0], card, addr, card->default_address, + flags); return grub_errno; } @@ -397,19 +502,9 @@ print_net_address (const grub_net_network_level_netaddress_t *target) static void print_address (const grub_net_network_level_address_t *target) { - switch (target->type) - { - case GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4: - { - grub_uint32_t n = grub_be_to_cpu32 (target->ipv4); - grub_printf ("%d.%d.%d.%d ", ((n >> 24) & 0xff), - ((n >> 16) & 0xff), - ((n >> 8) & 0xff), - ((n >> 0) & 0xff)); - } - return; - } - grub_printf ("Unknown address type %d\n", target->type); + char buf[MAX_STR_ADDR_LEN]; + addr_to_str (target, buf); + grub_xputs (buf); } static grub_err_t @@ -487,7 +582,7 @@ static grub_command_t cmd_lsroutes, cmd_lscards; GRUB_MOD_INIT(net) { cmd_addaddr = grub_register_command ("net_add_addr", grub_cmd_addaddr, - "SHORTNAME CARD ADDRESS", + "SHORTNAME CARD ADDRESS [HWADDRESS]", N_("Add a network address.")); cmd_deladdr = grub_register_command ("net_del_addr", grub_cmd_deladdr, "SHORTNAME", diff --git a/grub-core/fs/i386/pc/pxe.c b/grub-core/fs/i386/pc/pxe.c index 85d138bb0..1d9ea8f89 100644 --- a/grub-core/fs/i386/pc/pxe.c +++ b/grub-core/fs/i386/pc/pxe.c @@ -41,6 +41,7 @@ static grub_uint32_t grub_pxe_default_gateway_ip; static unsigned grub_pxe_blksize = GRUB_PXE_MIN_BLKSIZE; static grub_file_t curr_file = 0; +static grub_net_link_level_address_t pxe_hwaddr; struct grub_pxe_data { @@ -322,29 +323,6 @@ grub_env_write_readonly (struct grub_env_var *var __attribute__ ((unused)), return NULL; } -static void -set_mac_env (grub_uint8_t *mac_addr, grub_size_t mac_len) -{ - char buf[(sizeof ("XX:") - 1) * mac_len + 1]; - char *ptr = buf; - unsigned i; - - for (i = 0; i < mac_len; i++) - { - grub_snprintf (ptr, sizeof (buf) - (ptr - buf), - "%02x:", mac_addr[i] & 0xff); - ptr += (sizeof ("XX:") - 1); - } - if (mac_len) - *(ptr - 1) = 0; - else - buf[0] = 0; - - grub_env_set ("net_pxe_mac", buf); - /* XXX: Is it possible to change MAC in PXE? */ - grub_register_variable_hook ("net_pxe_mac", 0, grub_env_write_readonly); -} - static void set_env_limn_ro (const char *varname, char *value, grub_size_t len) { @@ -432,8 +410,10 @@ grub_pxe_detect (void) grub_pxe_your_ip = bp->your_ip; grub_pxe_default_server_ip = bp->server_ip; grub_pxe_default_gateway_ip = bp->gateway_ip; - set_mac_env (bp->mac_addr, bp->hw_len < sizeof (bp->mac_addr) ? bp->hw_len - : sizeof (bp->mac_addr)); + grub_memcpy (pxe_hwaddr.mac, bp->mac_addr, + bp->hw_len < sizeof (pxe_hwaddr.mac) + ? bp->hw_len : sizeof (pxe_hwaddr.mac)); + pxe_hwaddr.type = GRUB_NET_LINK_LEVEL_PROTOCOL_ETHERNET; set_env_limn_ro ("net_pxe_boot_file", (char *) bp->boot_file, sizeof (bp->boot_file)); set_env_limn_ro ("net_pxe_dhcp_server_name", (char *) bp->server_name, @@ -589,7 +569,10 @@ GRUB_MOD_INIT(pxe) grub_net_card_register (&grub_pxe_card); addr.type = GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4; addr.ipv4 = grub_pxe_your_ip; - inter = grub_net_add_addr ("pxe", &grub_pxe_card, addr); + inter = grub_net_add_addr ("pxe", &grub_pxe_card, addr, pxe_hwaddr, + GRUB_NET_INTERFACE_PERMANENT + | GRUB_NET_INTERFACE_ADDRESS_IMMUTABLE + | GRUB_NET_INTERFACE_HWADDRESS_IMMUTABLE); if (grub_pxe_default_gateway_ip != grub_pxe_default_server_ip) { grub_net_network_level_netaddress_t target; diff --git a/include/grub/net.h b/include/grub/net.h index 4efd79f79..649bf4096 100644 --- a/include/grub/net.h +++ b/include/grub/net.h @@ -34,6 +34,33 @@ typedef struct grub_net extern grub_net_t (*EXPORT_VAR (grub_net_open)) (const char *name); +typedef enum grub_link_level_protocol_id +{ + GRUB_NET_LINK_LEVEL_PROTOCOL_ETHERNET +} grub_link_level_protocol_id_t; + +typedef struct grub_net_link_level_address +{ + grub_link_level_protocol_id_t type; + union + { + grub_uint8_t mac[6]; + }; +} grub_net_link_level_address_t; + +typedef enum grub_net_interface_flags + { + GRUB_NET_INTERFACE_HWADDRESS_IMMUTABLE = 1, + GRUB_NET_INTERFACE_ADDRESS_IMMUTABLE = 2, + GRUB_NET_INTERFACE_PERMANENT = 4 + } grub_net_interface_flags_t; + +typedef enum grub_net_card_flags + { + GRUB_NET_CARD_HWADDRESS_IMMUTABLE = 1, + GRUB_NET_CARD_NO_MANUAL_INTERFACES = 2 + } grub_net_card_flags_t; + struct grub_net_card; struct grub_net_card_driver @@ -49,6 +76,8 @@ struct grub_net_card struct grub_net_card *next; char *name; struct grub_net_card_driver *driver; + grub_net_link_level_address_t default_address; + grub_net_card_flags_t flags; void *data; }; @@ -88,6 +117,8 @@ struct grub_net_network_level_interface char *name; struct grub_net_card *card; grub_net_network_level_address_t address; + grub_net_link_level_address_t hwaddress; + grub_net_interface_flags_t flags; void *data; }; @@ -130,7 +161,9 @@ grub_net_session_recv (struct grub_net_session *session, void *buf, struct grub_net_network_level_interface * grub_net_add_addr (const char *name, struct grub_net_card *card, - grub_net_network_level_address_t addr); + grub_net_network_level_address_t addr, + grub_net_link_level_address_t hwaddress, + grub_net_interface_flags_t flags); extern struct grub_net_network_level_interface *grub_net_network_level_interfaces; From 308fad6dc87b752d32e383d8670a8a7fcf4bafa9 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Thu, 2 Sep 2010 22:10:55 +0200 Subject: [PATCH 042/869] Move DHCP parsing to net module and reintroduce most variables --- grub-core/commands/net.c | 161 +++++++++++++++++++++++-- grub-core/fs/i386/pc/pxe.c | 235 ++++++++++--------------------------- include/grub/i386/pc/pxe.h | 38 +----- include/grub/net.h | 43 +++++++ 4 files changed, 257 insertions(+), 220 deletions(-) diff --git a/grub-core/commands/net.c b/grub-core/commands/net.c index 5a21178e5..f1838569b 100644 --- a/grub-core/commands/net.c +++ b/grub-core/commands/net.c @@ -217,21 +217,15 @@ grub_cmd_deladdr (struct grub_command *cmd __attribute__ ((unused)), return GRUB_ERR_NONE; } -/* - Currently suppoerted adresses: - IPv4: XXX.XXX.XXX.XXX - */ -#define MAX_STR_ADDR_LEN sizeof ("XXX.XXX.XXX.XXX") - -static void -addr_to_str (const grub_net_network_level_address_t *target, char *buf) +void +grub_net_addr_to_str (const grub_net_network_level_address_t *target, char *buf) { switch (target->type) { case GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4: { grub_uint32_t n = grub_be_to_cpu32 (target->ipv4); - grub_snprintf (buf, MAX_STR_ADDR_LEN, "%d.%d.%d.%d", + grub_snprintf (buf, GRUB_NET_MAX_STR_ADDR_LEN, "%d.%d.%d.%d", ((n >> 24) & 0xff), ((n >> 16) & 0xff), ((n >> 8) & 0xff), ((n >> 0) & 0xff)); } @@ -298,9 +292,9 @@ grub_net_network_level_interface_register (struct grub_net_network_level_interfa } { - char buf[MAX_STR_ADDR_LEN]; + char buf[GRUB_NET_MAX_STR_ADDR_LEN]; char name[grub_strlen (inter->name) + sizeof ("net__ip")]; - addr_to_str (&inter->address, buf); + grub_net_addr_to_str (&inter->address, buf); grub_snprintf (name, sizeof (name), "net_%s_ip", inter->name); grub_env_set (name, buf); grub_register_variable_hook (name, 0, addr_set_env); @@ -327,6 +321,8 @@ grub_net_add_addr (const char *name, struct grub_net_card *card, grub_memcpy (&(inter->hwaddress), &hwaddress, sizeof (inter->hwaddress)); inter->flags = flags; inter->card = card; + inter->dhcp_ack = NULL; + inter->dhcp_acklen = 0; grub_net_network_level_interface_register (inter); @@ -502,8 +498,8 @@ print_net_address (const grub_net_network_level_netaddress_t *target) static void print_address (const grub_net_network_level_address_t *target) { - char buf[MAX_STR_ADDR_LEN]; - addr_to_str (target, buf); + char buf[GRUB_NET_MAX_STR_ADDR_LEN]; + grub_net_addr_to_str (target, buf); grub_xputs (buf); } @@ -576,6 +572,145 @@ grub_net_open_real (const char *name) return NULL; } +static char * +grub_env_write_readonly (struct grub_env_var *var __attribute__ ((unused)), + const char *val __attribute__ ((unused))) +{ + return NULL; +} + +static void +set_env_limn_ro (const char *intername, const char *suffix, + char *value, grub_size_t len) +{ + char c; + char varname[sizeof ("net_") + grub_strlen (intername) + sizeof ("_") + + grub_strlen (suffix)]; + grub_snprintf (varname, sizeof (varname), "net_%s_%s", intername, suffix); + c = value[len]; + value[len] = 0; + grub_env_set (varname, value); + value[len] = c; + grub_register_variable_hook (varname, 0, grub_env_write_readonly); +} + +static void +parse_dhcp_vendor (const char *name, void *vend, int limit) +{ + grub_uint8_t *ptr, *ptr0; + + ptr = ptr0 = vend; + + if (grub_be_to_cpu32 (*(grub_uint32_t *) ptr) != GRUB_NET_BOOTP_RFC1048_MAGIC) + return; + ptr = ptr + sizeof (grub_uint32_t); + while (ptr - ptr0 < limit) + { + grub_uint8_t tagtype; + grub_uint8_t taglength; + + tagtype = *ptr++; + + /* Pad tag. */ + if (tagtype == 0) + continue; + + /* End tag. */ + if (tagtype == 0xff) + return; + + taglength = *ptr++; + + switch (tagtype) + { + case 12: + set_env_limn_ro (name, "hostname", (char *) ptr, taglength); + break; + + case 15: + set_env_limn_ro (name, "domain", (char *) ptr, taglength); + break; + + case 17: + set_env_limn_ro (name, "rootpath", (char *) ptr, taglength); + break; + + case 18: + set_env_limn_ro (name, "extensionspath", (char *) ptr, taglength); + break; + + /* If you need any other options please contact GRUB + developpement team. */ + } + + ptr += taglength; + } +} + +#define OFFSET_OF(x, y) ((grub_uint8_t *)((y)->x) - (grub_uint8_t *)(y)) + +struct grub_net_network_level_interface * +grub_net_configure_by_dhcp_ack (const char *name, struct grub_net_card *card, + grub_net_interface_flags_t flags, + struct grub_net_bootp_ack *bp, + grub_size_t size) +{ + grub_net_network_level_address_t addr; + grub_net_link_level_address_t hwaddr; + struct grub_net_network_level_interface *inter; + + addr.type = GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4; + addr.ipv4 = bp->your_ip; + + grub_memcpy (hwaddr.mac, bp->mac_addr, + bp->hw_len < sizeof (hwaddr.mac) ? bp->hw_len + : sizeof (hwaddr.mac)); + hwaddr.type = GRUB_NET_LINK_LEVEL_PROTOCOL_ETHERNET; + + inter = grub_net_add_addr (name, card, addr, hwaddr, flags); + if (bp->gateway_ip != bp->server_ip) + { + grub_net_network_level_netaddress_t target; + grub_net_network_level_address_t gw; + char rname[grub_strlen (name) + sizeof ("_gw")]; + + target.type = GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4; + target.ipv4.base = bp->server_ip; + target.ipv4.masksize = 32; + gw.type = GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4; + gw.ipv4 = bp->gateway_ip; + grub_snprintf (rname, sizeof (rname), "%s_gw", name); + grub_net_add_route_gw (rname, target, gw); + } + { + grub_net_network_level_netaddress_t target; + target.type = GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4; + target.ipv4.base = bp->gateway_ip; + target.ipv4.masksize = 32; + grub_net_add_route (name, target, inter); + } + + if (size > OFFSET_OF (boot_file, bp)) + set_env_limn_ro (name, "boot_file", (char *) bp->boot_file, + sizeof (bp->boot_file)); + if (size > OFFSET_OF (server_name, bp)) + set_env_limn_ro (name, "dhcp_server_name", (char *) bp->server_name, + sizeof (bp->server_name)); + if (size > OFFSET_OF (vendor, bp)) + parse_dhcp_vendor (name, &bp->vendor, size - OFFSET_OF (vendor, bp)); + + inter->dhcp_ack = grub_malloc (size); + if (inter->dhcp_ack) + { + grub_memcpy (inter->dhcp_ack, bp, size); + inter->dhcp_acklen = size; + } + else + grub_errno = GRUB_ERR_NONE; + + return inter; +} + static grub_command_t cmd_addaddr, cmd_deladdr, cmd_addroute, cmd_delroute; static grub_command_t cmd_lsroutes, cmd_lscards; diff --git a/grub-core/fs/i386/pc/pxe.c b/grub-core/fs/i386/pc/pxe.c index 1d9ea8f89..513a8cb7d 100644 --- a/grub-core/fs/i386/pc/pxe.c +++ b/grub-core/fs/i386/pc/pxe.c @@ -35,13 +35,13 @@ #define LINEAR(x) (void *) (((x >> 16) << 4) + (x & 0xFFFF)) struct grub_pxe_bangpxe *grub_pxe_pxenv; -static grub_uint32_t grub_pxe_your_ip; static grub_uint32_t grub_pxe_default_server_ip; +#if 0 static grub_uint32_t grub_pxe_default_gateway_ip; +#endif static unsigned grub_pxe_blksize = GRUB_PXE_MIN_BLKSIZE; - +static grub_uint32_t pxe_rm_entry = 0; static grub_file_t curr_file = 0; -static grub_net_link_level_address_t pxe_hwaddr; struct grub_pxe_data { @@ -52,7 +52,6 @@ struct grub_pxe_data char filename[0]; }; -static grub_uint32_t pxe_rm_entry = 0; static struct grub_pxe_bangpxe * grub_pxe_scan (void) @@ -316,112 +315,6 @@ static struct grub_fs grub_pxefs_fs = .next = 0 }; -static char * -grub_env_write_readonly (struct grub_env_var *var __attribute__ ((unused)), - const char *val __attribute__ ((unused))) -{ - return NULL; -} - -static void -set_env_limn_ro (const char *varname, char *value, grub_size_t len) -{ - char c; - c = value[len]; - value[len] = 0; - grub_env_set (varname, value); - value[len] = c; - grub_register_variable_hook (varname, 0, grub_env_write_readonly); -} - -static void -parse_dhcp_vendor (void *vend, int limit) -{ - grub_uint8_t *ptr, *ptr0; - - ptr = ptr0 = vend; - - if (grub_be_to_cpu32 (*(grub_uint32_t *) ptr) != 0x63825363) - return; - ptr = ptr + sizeof (grub_uint32_t); - while (ptr - ptr0 < limit) - { - grub_uint8_t tagtype; - grub_uint8_t taglength; - - tagtype = *ptr++; - - /* Pad tag. */ - if (tagtype == 0) - continue; - - /* End tag. */ - if (tagtype == 0xff) - return; - - taglength = *ptr++; - - switch (tagtype) - { - case 12: - set_env_limn_ro ("net_pxe_hostname", (char *) ptr, taglength); - break; - - case 15: - set_env_limn_ro ("net_pxe_domain", (char *) ptr, taglength); - break; - - case 17: - set_env_limn_ro ("net_pxe_rootpath", (char *) ptr, taglength); - break; - - case 18: - set_env_limn_ro ("net_pxe_extensionspath", (char *) ptr, taglength); - break; - - /* If you need any other options please contact GRUB - developpement team. */ - } - - ptr += taglength; - } -} - -static void -grub_pxe_detect (void) -{ - struct grub_pxe_bangpxe *pxenv; - struct grub_pxenv_get_cached_info ci; - struct grub_pxenv_boot_player *bp; - - pxenv = grub_pxe_scan (); - if (! pxenv) - return; - - ci.packet_type = GRUB_PXENV_PACKET_TYPE_DHCP_ACK; - ci.buffer = 0; - ci.buffer_size = 0; - grub_pxe_call (GRUB_PXENV_GET_CACHED_INFO, &ci, pxe_rm_entry); - if (ci.status) - return; - - bp = LINEAR (ci.buffer); - - grub_pxe_your_ip = bp->your_ip; - grub_pxe_default_server_ip = bp->server_ip; - grub_pxe_default_gateway_ip = bp->gateway_ip; - grub_memcpy (pxe_hwaddr.mac, bp->mac_addr, - bp->hw_len < sizeof (pxe_hwaddr.mac) - ? bp->hw_len : sizeof (pxe_hwaddr.mac)); - pxe_hwaddr.type = GRUB_NET_LINK_LEVEL_PROTOCOL_ETHERNET; - set_env_limn_ro ("net_pxe_boot_file", (char *) bp->boot_file, - sizeof (bp->boot_file)); - set_env_limn_ro ("net_pxe_dhcp_server_name", (char *) bp->server_name, - sizeof (bp->server_name)); - parse_dhcp_vendor (&bp->vendor, sizeof (bp->vendor)); - grub_pxe_pxenv = pxenv; -} - static grub_size_t grub_pxe_recv (struct grub_net_card *dev __attribute__ ((unused)), void *buf __attribute__ ((unused)), @@ -461,14 +354,15 @@ grub_pxe_unload (void) } } -#if 0 static void set_ip_env (char *varname, grub_uint32_t ip) { - char buf[sizeof ("XXX.XXX.XXX.XXX")]; + char buf[GRUB_NET_MAX_STR_ADDR_LEN]; + grub_net_network_level_address_t addr; + addr.type = GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4; + addr.ipv4 = ip; - grub_snprintf (buf, sizeof (buf), "%d.%d.%d.%d", (ip & 0xff), - (ip >> 8) & 0xff, (ip >> 16) & 0xff, (ip >> 24) & 0xff); + grub_net_addr_to_str (&addr, buf); grub_env_set (varname, buf); } @@ -477,25 +371,25 @@ write_ip_env (grub_uint32_t *ip, const char *val) { char *buf; grub_err_t err; - grub_uint32_t newip; - - err = parse_ip (val, &newip, 0); + grub_net_network_level_address_t addr; + + err = grub_net_resolve_address (val, &addr); if (err) return 0; + if (addr.type != GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4) + return NULL; /* Normalize the IP. */ - buf = grub_xasprintf ("%d.%d.%d.%d", (newip & 0xff), (newip >> 8) & 0xff, - (newip >> 16) & 0xff, (newip >> 24) & 0xff); + buf = grub_malloc (GRUB_NET_MAX_STR_ADDR_LEN); if (!buf) return 0; + grub_net_addr_to_str (&addr, buf); - *ip = newip; + *ip = addr.ipv4; return buf; } -#endif -#if 0 static char * grub_env_write_pxe_default_server (struct grub_env_var *var __attribute__ ((unused)), @@ -504,6 +398,7 @@ grub_env_write_pxe_default_server (struct grub_env_var *var return write_ip_env (&grub_pxe_default_server_ip, val); } +#if 0 static char * grub_env_write_pxe_default_gateway (struct grub_env_var *var __attribute__ ((unused)), @@ -540,60 +435,58 @@ grub_env_write_pxe_blocksize (struct grub_env_var *var __attribute__ ((unused)), GRUB_MOD_INIT(pxe) { - grub_pxe_detect (); - if (grub_pxe_pxenv) - { - char *buf; - grub_net_network_level_address_t addr; - struct grub_net_network_level_interface *inter; - -#if 0 - grub_register_variable_hook ("pxe_default_server", 0, - grub_env_write_pxe_default_server); - grub_register_variable_hook ("pxe_default_gateway", 0, - grub_env_write_pxe_default_gateway); -#endif - grub_register_variable_hook ("pxe_blksize", 0, - grub_env_write_pxe_blocksize); + struct grub_pxe_bangpxe *pxenv; + struct grub_pxenv_get_cached_info ci; + struct grub_net_bootp_ack *bp; + char *buf; - buf = grub_xasprintf ("%d", grub_pxe_blksize); - if (buf) - grub_env_set ("pxe_blksize", buf); - grub_free (buf); + pxenv = grub_pxe_scan (); + if (! pxenv) + return; + + ci.packet_type = GRUB_PXENV_PACKET_TYPE_DHCP_ACK; + ci.buffer = 0; + ci.buffer_size = 0; + grub_pxe_call (GRUB_PXENV_GET_CACHED_INFO, &ci, pxe_rm_entry); + if (ci.status) + return; + + bp = LINEAR (ci.buffer); + + grub_pxe_default_server_ip = bp->server_ip; + grub_pxe_pxenv = pxenv; + + set_ip_env ("pxe_default_server", grub_pxe_default_server_ip); + grub_register_variable_hook ("pxe_default_server", 0, + grub_env_write_pxe_default_server); #if 0 - set_ip_env ("pxe_default_server", grub_pxe_default_server_ip); + grub_pxe_default_gateway_ip = bp->gateway_ip; + + grub_register_variable_hook ("pxe_default_gateway", 0, + grub_env_write_pxe_default_gateway); #endif - grub_net_app_level_register (&grub_pxefs_fs); - grub_net_card_register (&grub_pxe_card); - addr.type = GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4; - addr.ipv4 = grub_pxe_your_ip; - inter = grub_net_add_addr ("pxe", &grub_pxe_card, addr, pxe_hwaddr, - GRUB_NET_INTERFACE_PERMANENT - | GRUB_NET_INTERFACE_ADDRESS_IMMUTABLE - | GRUB_NET_INTERFACE_HWADDRESS_IMMUTABLE); - if (grub_pxe_default_gateway_ip != grub_pxe_default_server_ip) - { - grub_net_network_level_netaddress_t target; - grub_net_network_level_address_t gw; - - target.type = GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4; - target.ipv4.base = grub_pxe_default_server_ip; - target.ipv4.masksize = 32; - gw.type = GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4; - gw.ipv4 = grub_pxe_default_gateway_ip; - grub_net_add_route_gw ("pxe_gw", target, gw); - } - { - grub_net_network_level_netaddress_t target; - target.type = GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4; - target.ipv4.base = grub_pxe_default_gateway_ip ? - : grub_pxe_default_server_ip; - target.ipv4.masksize = 32; - grub_net_add_route ("pxe", target, inter); - } - } + buf = grub_xasprintf ("%d", grub_pxe_blksize); + if (buf) + grub_env_set ("pxe_blksize", buf); + grub_free (buf); + + grub_register_variable_hook ("pxe_blksize", 0, + grub_env_write_pxe_blocksize); + + grub_memcpy (grub_pxe_card.default_address.mac, bp->mac_addr, + bp->hw_len < sizeof (grub_pxe_card.default_address.mac) + ? bp->hw_len : sizeof (grub_pxe_card.default_address.mac)); + grub_pxe_card.default_address.type = GRUB_NET_LINK_LEVEL_PROTOCOL_ETHERNET; + + grub_net_app_level_register (&grub_pxefs_fs); + grub_net_card_register (&grub_pxe_card); + grub_net_configure_by_dhcp_ack ("pxe", &grub_pxe_card, + GRUB_NET_INTERFACE_PERMANENT + | GRUB_NET_INTERFACE_ADDRESS_IMMUTABLE + | GRUB_NET_INTERFACE_HWADDRESS_IMMUTABLE, + bp, GRUB_PXE_BOOTP_SIZE); } GRUB_MOD_FINI(pxe) diff --git a/include/grub/i386/pc/pxe.h b/include/grub/i386/pc/pxe.h index 62ece21b0..781b53df5 100644 --- a/include/grub/i386/pc/pxe.h +++ b/include/grub/i386/pc/pxe.h @@ -152,9 +152,9 @@ #define GRUB_PXE_BOOTP_BCAST 0x8000 #if 1 -#define GRUB_PXE_BOOTP_DHCPVEND 1024 /* DHCP extended vendor field size. */ +#define GRUB_PXE_BOOTP_SIZE (1024 + 236) /* DHCP extended vendor field size. */ #else -#define GRUB_PXE_BOOTP_DHCPVEND 312 /* DHCP standard vendor field size. */ +#define GRUB_PXE_BOOTP_SIZE (312 + 236) /* DHCP standard vendor field size. */ #endif #define GRUB_PXE_MIN_BLKSIZE 512 @@ -162,8 +162,6 @@ #define GRUB_PXE_TFTP_PORT 69 -#define GRUB_PXE_VM_RFC1048 0x63825363L - #define GRUB_PXE_ERR_LEN 0xFFFFFFFF #ifndef ASM_FILE @@ -214,38 +212,6 @@ struct grub_pxenv_get_cached_info grub_uint16_t buffer_limit; } __attribute__ ((packed)); -#define GRUB_PXE_MAC_ADDR_LEN 16 - -typedef grub_uint8_t grub_pxe_mac_addr_t[GRUB_PXE_MAC_ADDR_LEN]; - -struct grub_pxenv_boot_player -{ - grub_uint8_t opcode; - grub_uint8_t hw_type; /* hardware type. */ - grub_uint8_t hw_len; /* hardware addr len. */ - grub_uint8_t gate_hops; /* zero it. */ - grub_uint32_t ident; /* random number chosen by client. */ - grub_uint16_t seconds; /* seconds since did initial bootstrap. */ - grub_uint16_t flags; - grub_uint32_t client_ip; - grub_uint32_t your_ip; - grub_uint32_t server_ip; - grub_uint32_t gateway_ip; - grub_pxe_mac_addr_t mac_addr; - grub_uint8_t server_name[64]; - grub_uint8_t boot_file[128]; - union - { - grub_uint8_t d[GRUB_PXE_BOOTP_DHCPVEND]; /* raw array of vendor/dhcp options. */ - struct - { - grub_uint32_t magic; /* DHCP magic cookie. */ - grub_uint32_t flags; /* bootp flags/opcodes. */ - grub_uint8_t padding[56]; - } v; - } vendor; -} __attribute__ ((packed)); - struct grub_pxenv_tftp_open { grub_uint16_t status; diff --git a/include/grub/net.h b/include/grub/net.h index 649bf4096..ec334092d 100644 --- a/include/grub/net.h +++ b/include/grub/net.h @@ -119,6 +119,8 @@ struct grub_net_network_level_interface grub_net_network_level_address_t address; grub_net_link_level_address_t hwaddress; grub_net_interface_flags_t flags; + struct grub_net_bootp_ack *dhcp_ack; + grub_size_t dhcp_acklen; void *data; }; @@ -234,4 +236,45 @@ grub_net_add_route_gw (const char *name, grub_net_network_level_address_t gw); +#define GRUB_NET_BOOTP_MAC_ADDR_LEN 16 + +typedef grub_uint8_t grub_net_bootp_mac_addr_t[GRUB_NET_BOOTP_MAC_ADDR_LEN]; + +struct grub_net_bootp_ack +{ + grub_uint8_t opcode; + grub_uint8_t hw_type; /* hardware type. */ + grub_uint8_t hw_len; /* hardware addr len. */ + grub_uint8_t gate_hops; /* zero it. */ + grub_uint32_t ident; /* random number chosen by client. */ + grub_uint16_t seconds; /* seconds since did initial bootstrap. */ + grub_uint16_t flags; + grub_uint32_t client_ip; + grub_uint32_t your_ip; + grub_uint32_t server_ip; + grub_uint32_t gateway_ip; + grub_net_bootp_mac_addr_t mac_addr; + grub_uint8_t server_name[64]; + grub_uint8_t boot_file[128]; + grub_uint8_t vendor[0]; +} __attribute__ ((packed)); + +#define GRUB_NET_BOOTP_RFC1048_MAGIC 0x63825363L + +struct grub_net_network_level_interface * +grub_net_configure_by_dhcp_ack (const char *name, struct grub_net_card *card, + grub_net_interface_flags_t flags, + struct grub_net_bootp_ack *bp, + grub_size_t size); + +/* + Currently suppoerted adresses: + IPv4: XXX.XXX.XXX.XXX + */ +#define GRUB_NET_MAX_STR_ADDR_LEN sizeof ("XXX.XXX.XXX.XXX") + +void +grub_net_addr_to_str (const grub_net_network_level_address_t *target, + char *buf); + #endif /* ! GRUB_NET_HEADER */ From 9daa20394429830d83a26c4eda35ab1a085fadd9 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Thu, 2 Sep 2010 22:12:37 +0200 Subject: [PATCH 043/869] Reintroduce pxe: syntax --- grub-core/fs/i386/pc/pxe.c | 77 ++++++++++++++------------------------ 1 file changed, 29 insertions(+), 48 deletions(-) diff --git a/grub-core/fs/i386/pc/pxe.c b/grub-core/fs/i386/pc/pxe.c index 513a8cb7d..dc447d92c 100644 --- a/grub-core/fs/i386/pc/pxe.c +++ b/grub-core/fs/i386/pc/pxe.c @@ -121,54 +121,35 @@ grub_pxefs_open (struct grub_file *file, const char *name) if (!data) return grub_errno; -#if 0 - if (grub_strncmp (file->device->net->name, "pxe:", sizeof ("pxe:") - 1) == 0) - { - const char *ptr; - grub_err_t err; - - ptr = name + sizeof ("pxe:") - 1; - err = parse_ip (ptr, &(data->server_ip), &ptr); - if (err) - return err; - if (*ptr == ':') - { - err = parse_ip (ptr + 1, &(data->gateway_ip), 0); - if (err) - return err; - } - else - data->gateway_ip = grub_pxe_default_gateway_ip; - } - else -#endif - { - grub_net_network_level_address_t addr; - grub_net_network_level_address_t gateway; - struct grub_net_network_level_interface *interf; - grub_err_t err; - - if (grub_strncmp (file->device->net->name, - "pxe,", sizeof ("pxe,") - 1) == 0) - { - const char *ptr; - - ptr = name + sizeof ("pxe,") - 1; - err = grub_net_resolve_address (name + sizeof ("pxe,") - 1, &addr); - if (err) - return err; - } - else - { - addr.ipv4 = grub_pxe_default_server_ip; - addr.type = GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4; - } - err = grub_net_route_address (addr, &gateway, &interf); - if (err) - return err; - data->server_ip = addr.ipv4; - data->gateway_ip = gateway.ipv4; - } + { + grub_net_network_level_address_t addr; + grub_net_network_level_address_t gateway; + struct grub_net_network_level_interface *interf; + grub_err_t err; + + if (grub_strncmp (file->device->net->name, + "pxe,", sizeof ("pxe,") - 1) == 0 + || grub_strncmp (file->device->net->name, + "pxe:", sizeof ("pxe:") - 1) == 0) + { + const char *ptr; + + ptr = name + sizeof ("pxe,") - 1; + err = grub_net_resolve_address (name + sizeof ("pxe,") - 1, &addr); + if (err) + return err; + } + else + { + addr.ipv4 = grub_pxe_default_server_ip; + addr.type = GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4; + } + err = grub_net_route_address (addr, &gateway, &interf); + if (err) + return err; + data->server_ip = addr.ipv4; + data->gateway_ip = gateway.ipv4; + } if (curr_file != 0) { From c04256771534fc5dcd1ce71e335b37d5cacc7b42 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Thu, 2 Sep 2010 22:20:48 +0200 Subject: [PATCH 044/869] Create directory net and move all net files there --- Makefile.util.def | 2 +- grub-core/Makefile.core.def | 4 ++-- grub-core/{fs => net}/i386/pc/pxe.c | 0 grub-core/{commands => net}/net.c | 0 4 files changed, 3 insertions(+), 3 deletions(-) rename grub-core/{fs => net}/i386/pc/pxe.c (100%) rename grub-core/{commands => net}/net.c (100%) diff --git a/Makefile.util.def b/Makefile.util.def index 5fd53680d..68c105a9b 100644 --- a/Makefile.util.def +++ b/Makefile.util.def @@ -30,7 +30,7 @@ library = { common = grub-core/commands/blocklist.c; common = grub-core/commands/extcmd.c; common = grub-core/commands/ls.c; - common = grub-core/commands/net.c; + common = grub-core/net/net.c; common = grub-core/disk/dmraid_nvidia.c; common = grub-core/disk/host.c; common = grub-core/disk/loopback.c; diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def index fb68f344c..bd5d78160 100644 --- a/grub-core/Makefile.core.def +++ b/grub-core/Makefile.core.def @@ -930,7 +930,7 @@ module = { module = { name = pxe; - i386_pc = fs/i386/pc/pxe.c; + i386_pc = net/i386/pc/pxe.c; enable = i386_pc; }; @@ -1379,5 +1379,5 @@ module = { module = { name = net; - common = commands/net.c; + common = net/net.c; }; \ No newline at end of file diff --git a/grub-core/fs/i386/pc/pxe.c b/grub-core/net/i386/pc/pxe.c similarity index 100% rename from grub-core/fs/i386/pc/pxe.c rename to grub-core/net/i386/pc/pxe.c diff --git a/grub-core/commands/net.c b/grub-core/net/net.c similarity index 100% rename from grub-core/commands/net.c rename to grub-core/net/net.c From 30b4166fdea35a49e1712efe6997de210cd17ca3 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 4 Sep 2010 17:23:51 +0200 Subject: [PATCH 045/869] Reimport setjmp from Tristan's branch. --- ChangeLog.ia64-emu | 6 ++ grub-core/lib/ia64/longjmp.S | 162 +++++++++++++++++++++++++++++++++ grub-core/lib/ia64/setjmp.S | 171 +++++++++++++++++++++++++++++++++++ grub-core/lib/setjmp.S | 2 + 4 files changed, 341 insertions(+) create mode 100644 ChangeLog.ia64-emu create mode 100644 grub-core/lib/ia64/longjmp.S create mode 100644 grub-core/lib/ia64/setjmp.S diff --git a/ChangeLog.ia64-emu b/ChangeLog.ia64-emu new file mode 100644 index 000000000..61a3ca6de --- /dev/null +++ b/ChangeLog.ia64-emu @@ -0,0 +1,6 @@ +2008-01-28 Tristan Gingold +2010-01-18 Robert Millan + + * grub-core/lib/ia64/setjmp.S: New file (from glibc). + * grub-core/lib/ia64/longjmp.S: New file (from glibc). + * grub-core/lib/setjmp.S [__ia64__]: include ia64/setjmp.S. diff --git a/grub-core/lib/ia64/longjmp.S b/grub-core/lib/ia64/longjmp.S new file mode 100644 index 000000000..729bdc76e --- /dev/null +++ b/grub-core/lib/ia64/longjmp.S @@ -0,0 +1,162 @@ +/* Copyright (C) 1999, 2000, 2001, 2002, 2008 Free Software Foundation, Inc. + Contributed by David Mosberger-Tang . + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. + + Note that __sigsetjmp() did NOT flush the register stack. Instead, + we do it here since __longjmp() is usually much less frequently + invoked than __sigsetjmp(). The only difficulty is that __sigsetjmp() + didn't (and wouldn't be able to) save ar.rnat either. This is a problem + because if we're not careful, we could end up loading random NaT bits. + There are two cases: + + (i) ar.bsp < ia64_rse_rnat_addr(jmpbuf.ar_bsp) + ar.rnat contains the desired bits---preserve ar.rnat + across loadrs and write to ar.bspstore + + (ii) ar.bsp >= ia64_rse_rnat_addr(jmpbuf.ar_bsp) + The desired ar.rnat is stored in + ia64_rse_rnat_addr(jmpbuf.ar_bsp). Load those + bits into ar.rnat after setting ar.bspstore. */ + + + +# define pPos p6 /* is rotate count positive? */ +# define pNeg p7 /* is rotate count negative? */ + + + /* __longjmp(__jmp_buf buf, int val) */ + + .text + .global longjmp + .proc longjmp +longjmp: + alloc r8=ar.pfs,2,1,0,0 + mov r27=ar.rsc + add r2=0x98,in0 // r2 <- &jmpbuf.orig_jmp_buf_addr + ;; + ld8 r8=[r2],-16 // r8 <- orig_jmp_buf_addr + mov r10=ar.bsp + and r11=~0x3,r27 // clear ar.rsc.mode + ;; + flushrs // flush dirty regs to backing store (must be first in insn grp) + ld8 r23=[r2],8 // r23 <- jmpbuf.ar_bsp + sub r8=r8,in0 // r8 <- &orig_jmpbuf - &jmpbuf + ;; + ld8 r25=[r2] // r25 <- jmpbuf.ar_unat + extr.u r8=r8,3,6 // r8 <- (&orig_jmpbuf - &jmpbuf)/8 & 0x3f + ;; + cmp.lt pNeg,pPos=r8,r0 + mov r2=in0 + ;; +(pPos) mov r16=r8 +(pNeg) add r16=64,r8 +(pPos) sub r17=64,r8 +(pNeg) sub r17=r0,r8 + ;; + mov ar.rsc=r11 // put RSE in enforced lazy mode + shr.u r8=r25,r16 + add r3=8,in0 // r3 <- &jmpbuf.r1 + shl r9=r25,r17 + ;; + or r25=r8,r9 + ;; + mov r26=ar.rnat + mov ar.unat=r25 // setup ar.unat (NaT bits for r1, r4-r7, and r12) + ;; + ld8.fill.nta sp=[r2],16 // r12 (sp) + ld8.fill.nta gp=[r3],16 // r1 (gp) + dep r11=-1,r23,3,6 // r11 <- ia64_rse_rnat_addr(jmpbuf.ar_bsp) + ;; + ld8.nta r16=[r2],16 // caller's unat + ld8.nta r17=[r3],16 // fpsr + ;; + ld8.fill.nta r4=[r2],16 // r4 + ld8.fill.nta r5=[r3],16 // r5 (gp) + cmp.geu p8,p0=r10,r11 // p8 <- (ar.bsp >= jmpbuf.ar_bsp) + ;; + ld8.fill.nta r6=[r2],16 // r6 + ld8.fill.nta r7=[r3],16 // r7 + ;; + mov ar.unat=r16 // restore caller's unat + mov ar.fpsr=r17 // restore fpsr + ;; + ld8.nta r16=[r2],16 // b0 + ld8.nta r17=[r3],16 // b1 + ;; +(p8) ld8 r26=[r11] // r26 <- *ia64_rse_rnat_addr(jmpbuf.ar_bsp) + mov ar.bspstore=r23 // restore ar.bspstore + ;; + ld8.nta r18=[r2],16 // b2 + ld8.nta r19=[r3],16 // b3 + ;; + ld8.nta r20=[r2],16 // b4 + ld8.nta r21=[r3],16 // b5 + ;; + ld8.nta r11=[r2],16 // ar.pfs + ld8.nta r22=[r3],56 // ar.lc + ;; + ld8.nta r24=[r2],32 // pr + mov b0=r16 + ;; + ldf.fill.nta f2=[r2],32 + ldf.fill.nta f3=[r3],32 + mov b1=r17 + ;; + ldf.fill.nta f4=[r2],32 + ldf.fill.nta f5=[r3],32 + mov b2=r18 + ;; + ldf.fill.nta f16=[r2],32 + ldf.fill.nta f17=[r3],32 + mov b3=r19 + ;; + ldf.fill.nta f18=[r2],32 + ldf.fill.nta f19=[r3],32 + mov b4=r20 + ;; + ldf.fill.nta f20=[r2],32 + ldf.fill.nta f21=[r3],32 + mov b5=r21 + ;; + ldf.fill.nta f22=[r2],32 + ldf.fill.nta f23=[r3],32 + mov ar.lc=r22 + ;; + ldf.fill.nta f24=[r2],32 + ldf.fill.nta f25=[r3],32 + cmp.eq p8,p9=0,in1 + ;; + ldf.fill.nta f26=[r2],32 + ldf.fill.nta f27=[r3],32 + mov ar.pfs=r11 + ;; + ldf.fill.nta f28=[r2],32 + ldf.fill.nta f29=[r3],32 + ;; + ldf.fill.nta f30=[r2] + ldf.fill.nta f31=[r3] +(p8) mov r8=1 + + mov ar.rnat=r26 // restore ar.rnat + ;; + mov ar.rsc=r27 // restore ar.rsc +(p9) mov r8=in1 + + invala // virt. -> phys. regnum mapping may change + mov pr=r24,-1 + br.ret.dptk.few rp + .endp longjmp diff --git a/grub-core/lib/ia64/setjmp.S b/grub-core/lib/ia64/setjmp.S new file mode 100644 index 000000000..0851885c5 --- /dev/null +++ b/grub-core/lib/ia64/setjmp.S @@ -0,0 +1,171 @@ +/* Copyright (C) 1999, 2000, 2001, 2002, 2008 Free Software Foundation, Inc. + Contributed by David Mosberger-Tang . + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. + + The layout of the jmp_buf is as follows. This is subject to change + and user-code should never depend on the particular layout of + jmp_buf! + + + offset: description: + ------- ------------ + 0x000 stack pointer (r12) ; unchangeable (see _JMPBUF_UNWINDS) + 0x008 r1 (gp) + 0x010 caller's unat + 0x018 fpsr + 0x020 r4 + 0x028 r5 + 0x030 r6 + 0x038 r7 + 0x040 rp (b0) + 0x048 b1 + 0x050 b2 + 0x058 b3 + 0x060 b4 + 0x068 b5 + 0x070 ar.pfs + 0x078 ar.lc + 0x080 pr + 0x088 ar.bsp ; unchangeable (see __longjmp.S) + 0x090 ar.unat + 0x098 &__jmp_buf ; address of the jmpbuf (needed to locate NaT bits in unat) + 0x0a0 f2 + 0x0b0 f3 + 0x0c0 f4 + 0x0d0 f5 + 0x0e0 f16 + 0x0f0 f17 + 0x100 f18 + 0x110 f19 + 0x120 f20 + 0x130 f21 + 0x130 f22 + 0x140 f23 + 0x150 f24 + 0x160 f25 + 0x170 f26 + 0x180 f27 + 0x190 f28 + 0x1a0 f29 + 0x1b0 f30 + 0x1c0 f31 */ + + + /* The following two entry points are the traditional entry points: */ + + .text + .global setjmp + .proc setjmp +setjmp: + alloc r8=ar.pfs,2,0,0,0 + mov in1=1 + br.cond.sptk.many __sigsetjmp + .endp setjmp + + /* __sigsetjmp(__jmp_buf buf, int savemask) */ + + .proc __sigsetjmp +__sigsetjmp: + //.prologue ASM_UNW_PRLG_RP|ASM_UNW_PRLG_PFS, ASM_UNW_PRLG_GRSAVE(2) + alloc loc1=ar.pfs,2,2,2,0 + mov r16=ar.unat + ;; + mov r17=ar.fpsr + mov r2=in0 + add r3=8,in0 + ;; + st8.spill.nta [r2]=sp,16 // r12 (sp) + st8.spill.nta [r3]=gp,16 // r1 (gp) + ;; + st8.nta [r2]=r16,16 // save caller's unat + st8.nta [r3]=r17,16 // save fpsr + add r8=0xa0,in0 + ;; + st8.spill.nta [r2]=r4,16 // r4 + st8.spill.nta [r3]=r5,16 // r5 + add r9=0xb0,in0 + ;; + stf.spill.nta [r8]=f2,32 + stf.spill.nta [r9]=f3,32 + mov loc0=rp + .body + ;; + stf.spill.nta [r8]=f4,32 + stf.spill.nta [r9]=f5,32 + mov r17=b1 + ;; + stf.spill.nta [r8]=f16,32 + stf.spill.nta [r9]=f17,32 + mov r18=b2 + ;; + stf.spill.nta [r8]=f18,32 + stf.spill.nta [r9]=f19,32 + mov r19=b3 + ;; + stf.spill.nta [r8]=f20,32 + stf.spill.nta [r9]=f21,32 + mov r20=b4 + ;; + stf.spill.nta [r8]=f22,32 + stf.spill.nta [r9]=f23,32 + mov r21=b5 + ;; + stf.spill.nta [r8]=f24,32 + stf.spill.nta [r9]=f25,32 + mov r22=ar.lc + ;; + stf.spill.nta [r8]=f26,32 + stf.spill.nta [r9]=f27,32 + mov r24=pr + ;; + stf.spill.nta [r8]=f28,32 + stf.spill.nta [r9]=f29,32 + ;; + stf.spill.nta [r8]=f30 + stf.spill.nta [r9]=f31 + + st8.spill.nta [r2]=r6,16 // r6 + st8.spill.nta [r3]=r7,16 // r7 + ;; + mov r23=ar.bsp + mov r25=ar.unat + mov out0=in0 + + st8.nta [r2]=loc0,16 // b0 + st8.nta [r3]=r17,16 // b1 + mov out1=in1 + ;; + st8.nta [r2]=r18,16 // b2 + st8.nta [r3]=r19,16 // b3 + ;; + st8.nta [r2]=r20,16 // b4 + st8.nta [r3]=r21,16 // b5 + ;; + st8.nta [r2]=loc1,16 // ar.pfs + st8.nta [r3]=r22,16 // ar.lc + ;; + st8.nta [r2]=r24,16 // pr + st8.nta [r3]=r23,16 // ar.bsp + ;; + st8.nta [r2]=r25 // ar.unat + st8.nta [r3]=in0 // &__jmp_buf + mov r8=0 + mov rp=loc0 + mov ar.pfs=loc1 + br.ret.sptk.many rp + + .endp __sigsetjmp diff --git a/grub-core/lib/setjmp.S b/grub-core/lib/setjmp.S index c39c91b9c..7e669d4ff 100644 --- a/grub-core/lib/setjmp.S +++ b/grub-core/lib/setjmp.S @@ -8,6 +8,8 @@ #include "./mips/setjmp.S" #elif defined(__powerpc__) #include "./powerpc/setjmp.S" +#elif defined(__ia64__) +#include "./ia64/setjmp.S" #else #error "Unknwon target cpu type" #endif From 3b2bdd6f73c0e7bf082f8553503b27c3806eb224 Mon Sep 17 00:00:00 2001 From: Tristan Gingold Date: Wed, 8 Sep 2010 01:50:12 +0200 Subject: [PATCH 046/869] Add missing headers for ia64 --- include/grub/ia64/setjmp.h | 28 ++++++++++++++++++++++++++++ include/grub/ia64/time.h | 28 ++++++++++++++++++++++++++++ include/grub/ia64/types.h | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 88 insertions(+) create mode 100644 include/grub/ia64/setjmp.h create mode 100644 include/grub/ia64/time.h create mode 100644 include/grub/ia64/types.h diff --git a/include/grub/ia64/setjmp.h b/include/grub/ia64/setjmp.h new file mode 100644 index 000000000..a71c9c56d --- /dev/null +++ b/include/grub/ia64/setjmp.h @@ -0,0 +1,28 @@ +/* Define the machine-dependent type `jmp_buf'. Linux/IA-64 version. + Copyright (C) 1999, 2000, 2008 Free Software Foundation, Inc. + Contributed by David Mosberger-Tang . + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + The GNU C Library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with the GNU C Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + +/* User code must not depend on the internal representation of jmp_buf. */ + +#define _JBLEN 70 + +/* the __jmp_buf element type should be __float80 per ABI... */ +typedef long grub_jmp_buf[_JBLEN] __attribute__ ((aligned (16))); /* guarantees 128-bit alignment! */ + +int grub_setjmp (grub_jmp_buf env); +void grub_longjmp (grub_jmp_buf env, int val) __attribute__ ((noreturn)); diff --git a/include/grub/ia64/time.h b/include/grub/ia64/time.h new file mode 100644 index 000000000..03ee79fa4 --- /dev/null +++ b/include/grub/ia64/time.h @@ -0,0 +1,28 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2007, 2008 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 . + */ + +#ifndef KERNEL_CPU_TIME_HEADER +#define KERNEL_CPU_TIME_HEADER 1 + +static __inline void +grub_cpu_idle (void) +{ + /* FIXME: not implemented */ +} + +#endif /* ! KERNEL_CPU_TIME_HEADER */ diff --git a/include/grub/ia64/types.h b/include/grub/ia64/types.h new file mode 100644 index 000000000..91a546dd2 --- /dev/null +++ b/include/grub/ia64/types.h @@ -0,0 +1,32 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2008 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 . + */ + +#ifndef GRUB_TYPES_CPU_HEADER +#define GRUB_TYPES_CPU_HEADER 1 + +/* The size of void *. */ +#define GRUB_TARGET_SIZEOF_VOID_P 8 + +/* The size of long. */ +#define GRUB_TARGET_SIZEOF_LONG 8 + +/* ia64 is little-endian (usually). */ +#undef GRUB_TARGET_WORDS_BIGENDIAN + + +#endif /* ! GRUB_TYPES_CPU_HEADER */ From 22a85f6b0abc04e881b8e376cc0793992dc23e16 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 8 Sep 2010 01:51:31 +0200 Subject: [PATCH 047/869] Add ia64-specific libgcc symbols --- configure.ac | 2 +- include/grub/libgcc.h | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index d362f68a5..ca886b5dc 100644 --- a/configure.ac +++ b/configure.ac @@ -542,7 +542,7 @@ CFLAGS="$CFLAGS -Wl,--defsym,abort=main" fi # Check for libgcc symbols -AC_CHECK_FUNCS(__bswapsi2 __bswapdi2 __ashldi3 __ashrdi3 __lshrdi3 __trampoline_setup __ucmpdi2 _restgpr_14_x) +AC_CHECK_FUNCS(__bswapsi2 __bswapdi2 __ashldi3 __ashrdi3 __lshrdi3 __trampoline_setup __ucmpdi2 _restgpr_14_x __ia64_trampoline __udivsi3 __umoddi3 __udivdi3 __divsi3 __modsi3 __umodsi3) if test "x$TARGET_APPLE_CC" = x1 ; then CFLAGS="$TARGET_CFLAGS -nostdlib" diff --git a/include/grub/libgcc.h b/include/grub/libgcc.h index d0adae8c1..703182577 100644 --- a/include/grub/libgcc.h +++ b/include/grub/libgcc.h @@ -38,8 +38,30 @@ void EXPORT_FUNC (__bswapsi2) (void); # ifdef HAVE___BSWAPDI2 void EXPORT_FUNC (__bswapdi2) (void); # endif +# ifdef HAVE___UDIVSI3 +void EXPORT_FUNC (__udivsi3) (void); +# endif +# ifdef HAVE___UMODSI3 +void EXPORT_FUNC (__umodsi3) (void); +# endif +# ifdef HAVE___UMODDI3 +void EXPORT_FUNC (__umoddi3) (void); +# endif +# ifdef HAVE___UDIVDI3 +void EXPORT_FUNC (__udivdi3) (void); +# endif +# ifdef HAVE___DIVSI3 +void EXPORT_FUNC (__divsi3) (void); +# endif +# ifdef HAVE___UMODSI3 +void EXPORT_FUNC (__modsi3) (void); +# endif #endif +# ifdef HAVE___IA64_TRAMPOLINE +void EXPORT_FUNC (__ia64_trampoline) (void); +# endif + #ifdef HAVE___TRAMPOLINE_SETUP void EXPORT_FUNC (__trampoline_setup) (void); #endif From 779e9dc48071591aa3205bb6087459902820c746 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 15 Sep 2010 00:44:57 +0200 Subject: [PATCH 048/869] Support Solaris DHCP ACK parsing --- grub-core/loader/i386/multiboot_mbi.c | 29 ++++++++++++++++++++++++++- grub-core/net/net.c | 2 -- include/grub/net.h | 4 ++++ 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/grub-core/loader/i386/multiboot_mbi.c b/grub-core/loader/i386/multiboot_mbi.c index bf17863cf..9d6497442 100644 --- a/grub-core/loader/i386/multiboot_mbi.c +++ b/grub-core/loader/i386/multiboot_mbi.c @@ -32,6 +32,7 @@ #include #include #include +#include /* The bits in the required part of flags field we don't support. */ #define UNSUPPORTED_FLAGS 0x0000fff8 @@ -189,12 +190,24 @@ grub_multiboot_load (grub_file_t file) static grub_size_t grub_multiboot_get_mbi_size (void) { - return sizeof (struct multiboot_info) + ALIGN_UP (cmdline_size, 4) + grub_size_t ret; + struct grub_net_network_level_interface *net; + + ret = sizeof (struct multiboot_info) + ALIGN_UP (cmdline_size, 4) + modcnt * sizeof (struct multiboot_mod_list) + total_modcmd + ALIGN_UP (sizeof(PACKAGE_STRING), 4) + grub_get_multiboot_mmap_count () * sizeof (struct multiboot_mmap_entry) + elf_sec_entsize * elf_sec_num + 256 * sizeof (struct multiboot_color); + + FOR_NET_NETWORK_LEVEL_INTERFACES(net) + if (net->dhcp_ack) + { + ret += net->dhcp_acklen; + break; + } + + return ret; } /* Fill previously allocated Multiboot mmap. */ @@ -401,6 +414,20 @@ grub_multiboot_make_mbi (grub_uint32_t *target) mbi->flags |= MULTIBOOT_INFO_BOOTDEV; } + { + struct grub_net_network_level_interface *net; + FOR_NET_NETWORK_LEVEL_INTERFACES(net) + if (net->dhcp_ack) + { + grub_memcpy (ptrorig, net->dhcp_ack, net->dhcp_acklen); + mbi->drives_addr = ptrdest; + mbi->drives_length = net->dhcp_acklen; + ptrorig += net->dhcp_acklen; + ptrdest += net->dhcp_acklen; + break; + } + } + if (elf_sec_num) { mbi->u.elf_sec.addr = ptrdest; diff --git a/grub-core/net/net.c b/grub-core/net/net.c index f1838569b..7c8992f8d 100644 --- a/grub-core/net/net.c +++ b/grub-core/net/net.c @@ -49,8 +49,6 @@ grub_net_network_level_interface_unregister (struct grub_net_network_level_inter GRUB_AS_LIST (inter)); } -#define FOR_NET_NETWORK_LEVEL_INTERFACES(var) for (var = grub_net_network_level_interfaces; var; var = var->next) - static inline void grub_net_route_register (struct grub_net_route *route) { diff --git a/include/grub/net.h b/include/grub/net.h index ec334092d..a0737d574 100644 --- a/include/grub/net.h +++ b/include/grub/net.h @@ -277,4 +277,8 @@ void grub_net_addr_to_str (const grub_net_network_level_address_t *target, char *buf); +extern struct grub_net_network_level_interface *grub_net_network_level_interfaces; +#define FOR_NET_NETWORK_LEVEL_INTERFACES(var) for (var = grub_net_network_level_interfaces; var; var = var->next) + + #endif /* ! GRUB_NET_HEADER */ From 21e4963bcc9cd307c54762d1715a0d38d502dd9f Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 15 Sep 2010 01:12:47 +0200 Subject: [PATCH 049/869] Support net_get_dhcp_option --- grub-core/net/net.c | 128 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 127 insertions(+), 1 deletion(-) diff --git a/grub-core/net/net.c b/grub-core/net/net.c index 7c8992f8d..5205e1938 100644 --- a/grub-core/net/net.c +++ b/grub-core/net/net.c @@ -709,8 +709,130 @@ grub_net_configure_by_dhcp_ack (const char *name, struct grub_net_card *card, return inter; } +static char +hexdigit (grub_uint8_t val) +{ + if (val < 10) + return val + '0'; + return val + 'a' - 10; +} + +static grub_err_t +grub_cmd_dhcpopt (struct grub_command *cmd __attribute__ ((unused)), + int argc, char **args) +{ + struct grub_net_network_level_interface *inter; + int num; + grub_uint8_t *ptr; + grub_uint8_t taglength; + + if (argc < 4) + return grub_error (GRUB_ERR_BAD_ARGUMENT, "4 arguments expected"); + + FOR_NET_NETWORK_LEVEL_INTERFACES (inter) + if (grub_strcmp (inter->name, args[1])) + break; + + if (!inter) + return grub_error (GRUB_ERR_BAD_ARGUMENT, + N_("unrecognised interface %s"), args[1]); + + if (!inter->dhcp_ack) + return grub_error (GRUB_ERR_IO, N_("no DHCP info found")); + + if (inter->dhcp_acklen <= OFFSET_OF (vendor, inter->dhcp_ack)) + return grub_error (GRUB_ERR_IO, N_("no DHCP options found")); + + num = grub_strtoul (args[2], 0, 0); + if (grub_errno) + return grub_errno; + + ptr = inter->dhcp_ack->vendor; + + if (grub_be_to_cpu32 (*(grub_uint32_t *) ptr) + != GRUB_NET_BOOTP_RFC1048_MAGIC) + return grub_error (GRUB_ERR_IO, N_("no DHCP options found")); + ptr = ptr + sizeof (grub_uint32_t); + while (1) + { + grub_uint8_t tagtype; + + if (ptr >= ((grub_uint8_t *) inter->dhcp_ack) + inter->dhcp_acklen) + return grub_error (GRUB_ERR_IO, N_("no DHCP option %d found"), num); + + tagtype = *ptr++; + + /* Pad tag. */ + if (tagtype == 0) + continue; + + /* End tag. */ + if (tagtype == 0xff) + return grub_error (GRUB_ERR_IO, N_("no DHCP option %d found"), num); + + taglength = *ptr++; + + if (tagtype == num) + break; + ptr += taglength; + } + + if (grub_strcmp (args[3], "string") == 0) + { + char *val = grub_malloc (taglength + 1); + if (!val) + return grub_errno; + grub_memcpy (val, ptr, taglength); + val[taglength] = 0; + if (args[0][0] == '-' && args[0][1] == 0) + grub_printf ("%s\n", val); + else + return grub_env_set (args[0], val); + return GRUB_ERR_NONE; + } + + if (grub_strcmp (args[3], "number") == 0) + { + grub_uint64_t val = 0; + int i; + for (i = 0; i < taglength; i++) + val = (val << 8) | ptr[i]; + if (args[0][0] == '-' && args[0][1] == 0) + grub_printf ("%llu\n", (unsigned long long) val); + else + { + char valn[64]; + grub_printf (valn, sizeof (valn), "%lld\n", (unsigned long long) val); + return grub_env_set (args[0], valn); + } + return GRUB_ERR_NONE; + } + + if (grub_strcmp (args[3], "hex") == 0) + { + char *val = grub_malloc (2 * taglength + 1); + int i; + if (!val) + return grub_errno; + for (i = 0; i < taglength; i++) + { + val[2 * i] = hexdigit (ptr[i] >> 4); + val[2 * i + 1] = hexdigit (ptr[i] & 0xf); + } + val[2 * taglength] = 0; + if (args[0][0] == '-' && args[0][1] == 0) + grub_printf ("%s\n", val); + else + return grub_env_set (args[0], val); + return GRUB_ERR_NONE; + } + + return grub_error (GRUB_ERR_BAD_ARGUMENT, + "unrecognised format specification %s", args[3]); +} + static grub_command_t cmd_addaddr, cmd_deladdr, cmd_addroute, cmd_delroute; -static grub_command_t cmd_lsroutes, cmd_lscards; +static grub_command_t cmd_lsroutes, cmd_lscards, cmd_getdhcp; GRUB_MOD_INIT(net) { @@ -730,6 +852,9 @@ GRUB_MOD_INIT(net) "", N_("list network routes")); cmd_lscards = grub_register_command ("net_ls_cards", grub_cmd_listcards, "", N_("list network cards")); + cmd_getdhcp = grub_register_command ("net_get_dhcp_option", grub_cmd_dhcpopt, + N_("VAR INTERFACE NUMBER DESCRIPTION"), + N_("retrieve DHCP option and save it into VAR. If VAR is - then print the value.")); grub_net_open = grub_net_open_real; } @@ -742,5 +867,6 @@ GRUB_MOD_FINI(net) grub_unregister_command (cmd_delroute); grub_unregister_command (cmd_lsroutes); grub_unregister_command (cmd_lscards); + grub_unregister_command (cmd_getdhcp); grub_net_open = NULL; } From 9a9cee4e4347c0480fb9e19ce2732a2132c4e3f9 Mon Sep 17 00:00:00 2001 From: "Manoel R. Abranches" Date: Wed, 15 Sep 2010 13:00:51 -0300 Subject: [PATCH 050/869] Use the correct address types in net.c. implement ntoa ipv4 function. --- commands/net.c | 40 +++++++++++++++++++++++++++---------- include/grub/net.h | 29 +++++++++++++++++++++++---- include/grub/net/protocol.h | 5 +++-- include/grub/net/type_net.h | 8 ++++---- net/ip.c | 38 +++++++++++++++++++++++++++++++++-- 5 files changed, 97 insertions(+), 23 deletions(-) diff --git a/commands/net.c b/commands/net.c index b8ceb36f4..2558a309b 100644 --- a/commands/net.c +++ b/commands/net.c @@ -22,11 +22,8 @@ #include #include -struct grub_net_route *grub_net_routes = NULL; -struct grub_net_network_layer_interface *grub_net_network_layer_interfaces = NULL; -struct grub_net_card *grub_net_cards = NULL; -struct grub_net_network_layer_protocol *grub_net_network_layer_protocols = NULL; +/*Find which protocol understands the given address*/ grub_err_t grub_net_resolve_address (struct grub_net_network_layer_protocol **prot, char *name, @@ -102,7 +99,7 @@ grub_cmd_deladdr (struct grub_command *cmd __attribute__ ((unused)), return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("one argument expected")); FOR_NET_NETWORK_LEVEL_INTERFACES (inter) - if (grub_strcmp (inter->name, args[1])) + if ( !grub_strcmp (inter->name, args[1])) break; if (inter == NULL) return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("address not found")); @@ -124,21 +121,36 @@ grub_cmd_addaddr (struct grub_command *cmd __attribute__ ((unused)), grub_err_t err; grub_net_network_layer_address_t addr; struct grub_net_network_layer_interface *inter; + grub_printf("Enter add addr function.\n"); + + grub_printf("card list address in net.c = %x\n", (int) grub_net_cards); if (argc != 4) return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("four arguments expected")); FOR_NET_CARDS (card) - if (grub_strcmp (card->name, args[1])) + { + grub_printf("card address = %x\n", (int) card); + grub_printf("card->name = %s\n",card->name); + grub_printf("args[1] = %s\n",args[1]); + if ( !grub_strcmp (card->name, args[1])) break; + } + + grub_printf("Out of the loop.\n"); + grub_printf("card address = %x\n", (int) card); + if (card == NULL) return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("card not found")); + grub_printf("protocols loop.\n"); FOR_NET_NETWORK_LEVEL_PROTOCOLS (prot) - if (grub_strcmp (prot->name, args[2])) + if ( !grub_strcmp (prot->name, args[2])) break; - if (card == NULL) + grub_printf("end protocols loop.\n"); + + if (prot == NULL) return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("protocol not found")); err = grub_net_resolve_address_in_protocol (prot, args[3], &addr); @@ -163,6 +175,12 @@ grub_cmd_addaddr (struct grub_command *cmd __attribute__ ((unused)), } grub_net_network_layer_interface_register (inter); + FOR_NET_NETWORK_LEVEL_INTERFACES (inter) + { + grub_printf("inter->name = %s\n",inter->name); + grub_printf("inter->address = %x\n",(int) (inter->address.ipv4)); + + } return GRUB_ERR_NONE; } @@ -178,7 +196,7 @@ grub_cmd_delroute (struct grub_command *cmd __attribute__ ((unused)), for (prev = &grub_net_routes, route = *prev; route; prev = &((*prev)->next), route = *prev) - if (grub_strcmp (route->name, args[0]) == 0) + if ( !grub_strcmp (route->name, args[0]) == 0) { *prev = route->next; grub_free (route->name); @@ -232,7 +250,7 @@ grub_cmd_addroute (struct grub_command *cmd __attribute__ ((unused)), N_("Unrecognised address %s"), args[1]); } - if (grub_strcmp (args[2], "gw") == 0 && argc >= 4) + if ( !grub_strcmp (args[2], "gw") == 0 && argc >= 4) { grub_err_t err; route->is_gateway = 1; @@ -251,7 +269,7 @@ grub_cmd_addroute (struct grub_command *cmd __attribute__ ((unused)), route->is_gateway = 0; FOR_NET_NETWORK_LEVEL_INTERFACES (inter) - if (grub_strcmp (inter->name, args[2])) + if ( !grub_strcmp (inter->name, args[2])) break; if (!inter) diff --git a/include/grub/net.h b/include/grub/net.h index abb8a3167..18779dabe 100644 --- a/include/grub/net.h +++ b/include/grub/net.h @@ -31,6 +31,8 @@ struct grub_net_card; struct grub_net_card_driver { + struct grub_net_card_driver *next; + char *name; grub_err_t (*init) (struct grub_net_card *dev); grub_err_t (*fini) (struct grub_net_card *dev); grub_err_t (*send) (struct grub_net_card *dev,struct grub_net_buff *nb); @@ -66,7 +68,7 @@ struct grub_net_network_layer_interface /* Underlying protocol. */ struct grub_net_network_layer_protocol *protocol; struct grub_net_card *card; - union grub_net_network_layer_address address; + grub_net_network_layer_address_t address; void *data; }; @@ -121,7 +123,7 @@ grub_net_session_recv (struct grub_net_session *session, void *buf, return session->protocol->recv (session, buf, size); } -struct grub_net_network_layer_interface *grub_net_network_layer_interfaces; +extern struct grub_net_network_layer_interface *EXPORT_VAR(grub_net_network_layer_interfaces); static inline void grub_net_network_layer_interface_register (struct grub_net_network_layer_interface *inter) @@ -139,7 +141,7 @@ grub_net_network_layer_interface_unregister (struct grub_net_network_layer_inter #define FOR_NET_NETWORK_LEVEL_INTERFACES(var) for (var = grub_net_network_layer_interfaces; var; var = var->next) -extern struct grub_net_route *grub_net_routes; +extern struct grub_net_route *EXPORT_VAR(grub_net_routes); static inline void grub_net_route_register (struct grub_net_route *route) @@ -157,7 +159,7 @@ grub_net_route_unregister (struct grub_net_route *route) #define FOR_NET_ROUTES(var) for (var = grub_net_routes; var; var = var->next) -extern struct grub_net_card *grub_net_cards; +extern struct grub_net_card *EXPORT_VAR(grub_net_cards); static inline void grub_net_card_register (struct grub_net_card *card) @@ -174,7 +176,26 @@ grub_net_card_unregister (struct grub_net_card *card) } #define FOR_NET_CARDS(var) for (var = grub_net_cards; var; var = var->next) +struct grub_net_card_driver *grub_net_card_drivers; +static inline void +grub_net_card_driver_register (struct grub_net_card_driver *driver) +{ + grub_list_push (GRUB_AS_LIST_P (&grub_net_card_drivers), + GRUB_AS_LIST (driver)); +} + +static inline void +grub_net_card_driver_unregister (struct grub_net_card_driver *driver) +{ + grub_list_remove (GRUB_AS_LIST_P (&grub_net_card_drivers), + GRUB_AS_LIST (driver)); +} + +void ofdriver_ini(void); +void ofdriver_fini(void); + +#define FOR_NET_CARD_DRIVERS(var) for (var = grub_net_card_drivers; var; var = var->next) #define FOR_NET_NETWORK_LEVEL_PROTOCOLS(var) for ((var) = grub_net_network_layer_protocols; (var); (var) = (var)->next) diff --git a/include/grub/net/protocol.h b/include/grub/net/protocol.h index ffc3dd719..ce37404bc 100644 --- a/include/grub/net/protocol.h +++ b/include/grub/net/protocol.h @@ -1,6 +1,7 @@ #ifndef GRUB_PROTOCOL_HEADER #define GRUB_PROTOCOL_HEADER #include +#include #include #include #include @@ -60,7 +61,7 @@ struct grub_net_network_layer_protocol grub_uint16_t type; /* IANA Ethertype */ //grub_network_layer_protocol_id_t id; grub_err_t (*ntoa) (char *name, grub_net_network_layer_address_t *addr); - char * (*aton) (union grub_net_network_layer_address addr); + char * (*aton) (grub_net_network_layer_address_t addr); grub_err_t (*net_ntoa) (char *name, grub_net_network_layer_netaddress_t *addr); char * (*net_aton) (grub_net_network_layer_netaddress_t addr); @@ -87,7 +88,7 @@ struct grub_net_link_layer_protocol grub_uint16_t ethertype); }; -extern struct grub_net_network_layer_protocol *grub_net_network_layer_protocols; +extern struct grub_net_network_layer_protocol *EXPORT_VAR(grub_net_network_layer_protocols); typedef struct grub_net_protocol *grub_net_protocol_t; void grub_net_application_layer_protocol_register (struct grub_net_application_layer_protocol *prot); diff --git a/include/grub/net/type_net.h b/include/grub/net/type_net.h index a1717d6a7..f159b1de0 100644 --- a/include/grub/net/type_net.h +++ b/include/grub/net/type_net.h @@ -18,16 +18,16 @@ typedef enum }grub_net_protocol_id_t; -typedef union grub_net_network_layer_address +typedef union grub_net_network_layer_netaddress { grub_uint32_t ipv4; -} grub_net_network_layer_netaddress_t; +} grub_net_network_layer_address_t; -typedef union grub_net_network_layer_netaddress +typedef union grub_net_network_layer_address { struct { grub_uint32_t base; int masksize; } ipv4; -} grub_net_network_layer_address_t; +} grub_net_network_layer_netaddress_t; #endif diff --git a/net/ip.c b/net/ip.c index 142f33e70..8237603f2 100644 --- a/net/ip.c +++ b/net/ip.c @@ -68,8 +68,10 @@ send_ip_packet (struct grub_net_network_layer_interface *inf, grub_memcpy(nl_target_addr.addr, &(iph->dest), nl_target_addr.len); rc = arp_resolve(inf, trans_net_inf->inner_layer, &nl_target_addr, &ll_target_addr); grub_free(nl_target_addr.addr); - if (rc != GRUB_ERR_NONE) + if (rc != GRUB_ERR_NONE){ + grub_printf("Error in the ARP resolve.\n"); return rc; + } rc = trans_net_inf->inner_layer->link_prot->send(inf,trans_net_inf->inner_layer,nb,ll_target_addr, IP_ETHERTYPE); grub_free(ll_target_addr.addr); @@ -113,13 +115,45 @@ recv_ip_packet (struct grub_net_network_layer_interface *inf, return 0; } + +static grub_err_t +ipv4_ntoa (char *val, grub_net_network_layer_address_t *addr ) +{ + grub_uint8_t *p = (grub_uint8_t *) addr; + unsigned long t; + int i; + + for (i = 0; i < 4; i++) + { + t = grub_strtoul (val, (char **) &val, 0); + if (grub_errno) + return grub_errno; + + if (t & ~0xff) + return grub_error (GRUB_ERR_OUT_OF_RANGE, "Invalid IP."); + + p[i] = (grub_uint8_t) t; + if (i != 3 && *val != '.') + return grub_error (GRUB_ERR_OUT_OF_RANGE, "Invalid IP."); + + val++; + } + + val = val - 1; + if (*val != '\0') + return grub_error (GRUB_ERR_OUT_OF_RANGE, "Invalid IP."); + + return GRUB_ERR_NONE; +} + static struct grub_net_network_layer_protocol grub_ipv4_protocol = { .name = "ipv4", .id = GRUB_NET_IPV4_ID, .type = IP_ETHERTYPE, .send = send_ip_packet, - .recv = recv_ip_packet + .recv = recv_ip_packet, + .ntoa = ipv4_ntoa }; void ipv4_ini(void) From 87fdc7e8d28f20f355240219ea7e7a580e0f7303 Mon Sep 17 00:00:00 2001 From: "Manoel R. Abranches" Date: Wed, 15 Sep 2010 13:23:23 -0300 Subject: [PATCH 051/869] Create Open firmware pseudo driver. Change ofnet.c to disknet.c and remove almost all ieee1275 specific code. Create grub_net_malloc to handle iee1275 memory issues in a temporary solution. --- conf/powerpc-ieee1275.rmk | 6 +- fs/{ieee1275/ofnet.c => netdisk.c} | 142 ++++++++------------------ include/grub/ieee1275/ieee1275.h | 10 +- include/grub/ieee1275/ofnet.h | 29 +----- include/grub/net/disknet.h | 5 + include/grub/net/ethernet.h | 15 ++- include/grub/net/ieee1275/interface.h | 9 -- include/grub/net/mem.h | 9 ++ kern/ieee1275/openfw.c | 64 ++++++++++++ net/drivers/ieee1275/ofdriver.c | 74 ++++++++++++++ net/ethernet.c | 9 +- net/i386/mem.c | 10 ++ net/ieee1275/interface.c | 46 --------- net/ieee1275/mem.c | 32 ++++++ net/protocol.c | 2 + 15 files changed, 272 insertions(+), 190 deletions(-) rename fs/{ieee1275/ofnet.c => netdisk.c} (77%) create mode 100644 include/grub/net/disknet.h create mode 100644 include/grub/net/mem.h create mode 100644 net/drivers/ieee1275/ofdriver.c create mode 100644 net/i386/mem.c delete mode 100644 net/ieee1275/interface.c create mode 100644 net/ieee1275/mem.c diff --git a/conf/powerpc-ieee1275.rmk b/conf/powerpc-ieee1275.rmk index f0faef489..a70a1e962 100644 --- a/conf/powerpc-ieee1275.rmk +++ b/conf/powerpc-ieee1275.rmk @@ -5,7 +5,7 @@ kernel_img_HEADERS += ieee1275/ieee1275.h \ command.h i18n.h env_private.h net/ip.h net/udp.h net/ethernet.h net/arp.h net/tftp.h\ - net/ieee1275/interface.h net/type_net.h net.h net/interface.h net/protocol.h net/netbuff.h + net/ieee1275/interface.h net/type_net.h net.h net/interface.h net/protocol.h net/netbuff.h net/mem.h # Programs pkglib_PROGRAMS = kernel.img @@ -23,8 +23,8 @@ kernel_img_SOURCES = kern/powerpc/ieee1275/startup.S kern/ieee1275/cmain.c \ kern/parser.c kern/partition.c kern/env.c kern/$(target_cpu)/dl.c \ kern/generic/millisleep.c kern/time.c \ symlist.c kern/$(target_cpu)/cache.S net/ip.c net/tftp.c net/udp.c net/ethernet.c net/arp.c \ - net/ieee1275/interface.c net/interface.c net/protocol.c net/netbuff.c \ - fs/ieee1275/ofnet.c + net/drivers/ieee1275/ofdriver.c net/interface.c net/protocol.c net/netbuff.c \ + fs/netdisk.c net/ieee1275/mem.c kernel_img_CFLAGS = $(COMMON_CFLAGS) kernel_img_ASFLAGS = $(COMMON_ASFLAGS) kernel_img_LDFLAGS += $(COMMON_LDFLAGS) -Wl,-N,-S,-Ttext,0x200000,-Bstatic diff --git a/fs/ieee1275/ofnet.c b/fs/netdisk.c similarity index 77% rename from fs/ieee1275/ofnet.c rename to fs/netdisk.c index cf7eeb5b2..2f6e97d52 100644 --- a/fs/ieee1275/ofnet.c +++ b/fs/netdisk.c @@ -23,26 +23,25 @@ #include #include #include -#include -#include -#include #include #include #include #include #include -#include #include #include #include +#include +#include + +struct grub_net_card *grub_net_cards = NULL; +struct grub_net_network_layer_interface *grub_net_network_layer_interfaces = NULL; +struct grub_net_route *grub_net_routes = NULL; #define BUFFERADDR 0X00000000 #define BUFFERSIZE 0x02000000 #define U64MAXSIZE 18446744073709551615ULL - -//static grub_ieee1275_ihandle_t handle = 0; - static const char * find_sep (const char *name) { @@ -295,29 +294,45 @@ grub_ofnetfs_open (struct grub_file *file , const char *name ) return 1; } - // grub_printf("name = %s\n",name); +/*TESt*/ + // grub_printf("name = %s\n",name); + struct grub_net_card *card; + struct grub_ofnetcard_data *ofdata; + FOR_NET_CARDS(card) + { + grub_printf("card address = %x\n", (int) card); + grub_printf ("card name = %s\n", card->name); + ofdata = card->data; + grub_printf("card path = %s\n", (char *) ofdata->path); + grub_printf("card handle = %d\n", ofdata->handle); + } + grub_printf("card list address in disknet.c = %x\n",(int) grub_net_cards); + card = grub_net_cards; + grub_printf("card address = %x\n", (int) card); +/*TESt*/ + struct grub_net_protocol_stack *stack; struct grub_net_buff *pack; struct grub_net_application_transport_interface *app_interface; int file_size; char *datap; int amount = 0; - grub_addr_t found_addr; grub_netdisk_data_t netdisk_data = (grub_netdisk_data_t) file->device->disk->data; + // TODO: replace getting IP and MAC from bootp by routing functions struct grub_net_network_layer_interface net_interface; - struct grub_net_card net_card; struct grub_net_addr ila, lla; - ila.addr = (grub_uint8_t *) &(bootp_pckt->yiaddr); + ila.addr = (grub_uint8_t *) & (bootp_pckt->yiaddr); ila.len = 4; - lla.addr = (grub_uint8_t *) &(bootp_pckt->chaddr); + lla.addr = (grub_uint8_t *) & (bootp_pckt->chaddr); lla.len = 6; - net_card.ila = &ila; - net_card.lla = &lla; - net_interface.card = &net_card; // END TODO + card->ila = &ila; + card->lla = &lla; + net_interface.card = card; + if(! netdisk_data) return grub_error (GRUB_ERR_BAD_ARGUMENT, "arguments missing"); @@ -328,37 +343,35 @@ grub_ofnetfs_open (struct grub_file *file , const char *name ) app_interface = (struct grub_net_application_transport_interface *) stack->interface; app_interface->inner_layer->data = (void *) &(netdisk_data->server_ip); + pack = grub_netbuff_alloc (2048); grub_netbuff_reserve (pack,2048); + file_size = app_interface->app_prot->get_file_size(&net_interface,stack,pack,(char *) name); - for (found_addr = 0x800000; found_addr < + 2000 * 0x100000; found_addr += 0x100000) - { - if (grub_claimmap (found_addr , file_size) != -1) - break; - } - file->data = (void *) found_addr; + file->data = grub_net_malloc (file_size); grub_netbuff_clear(pack); grub_netbuff_reserve (pack,2048); + app_interface->app_prot->open (&net_interface,stack,pack,(char *) name); if (grub_errno != GRUB_ERR_NONE) goto error; do { - grub_netbuff_clear(pack); - grub_netbuff_reserve (pack,2048); app_interface->app_prot->recv (&net_interface,stack,pack); + if (grub_errno != GRUB_ERR_NONE) goto error; + if ((pack->tail - pack->data)) { - // file->data = grub_realloc(file->data,amount + pack->tail - pack->data); datap = (char *)file->data + amount; amount += (pack->tail - pack->data); - grub_memcpy(datap , pack->data, pack->tail - pack->data); + grub_memcpy (datap , pack->data, pack->tail - pack->data); } + grub_netbuff_clear(pack); grub_netbuff_reserve (pack,2048); app_interface->app_prot->send_ack (&net_interface,stack,pack); @@ -394,54 +407,6 @@ static struct grub_fs grub_ofnetfs_fs = .next = 0 }; -static char * -grub_ieee1275_get_devargs (const char *path) -{ - int len; - char *colon = grub_strchr (path, ':'); - len = colon - path; - if (! colon) - return 0; - - return grub_strndup (path,len); -} - -static int -grub_ofnet_detect (void) -{ - - char *devalias; - char bootpath[64]; /* XXX check length */ - grub_ieee1275_phandle_t root; - grub_uint32_t net_type; - - grub_ieee1275_finddevice ("/chosen", &grub_ieee1275_chosen); - if (grub_ieee1275_get_property (grub_ieee1275_chosen, "bootpath", &bootpath, - sizeof (bootpath), 0)) - { - /* Should never happen. */ - grub_printf ("/chosen/bootpath property missing!\n"); - return 0; - } - devalias = grub_ieee1275_get_aliasdevname (bootpath); - - if (grub_strncmp(devalias ,"net",3)) - return 0; - - grub_net = grub_malloc (sizeof *grub_net ); - grub_net->name = "net"; - grub_net->dev = grub_ieee1275_get_devargs (bootpath); - grub_ieee1275_finddevice ("/", &root); - grub_ieee1275_get_integer_property (root, "ibm,fw-net-compatibility", - &net_type, sizeof net_type, 0); - grub_printf("root = %d\n",root); - grub_printf("net_type= %d\n",net_type); - grub_net->type = net_type; - - return 1; -} - - #define IPMASK 0x000000FF #define IPSIZE 16 #define IPTEMPLATE "%d.%d.%d.%d" @@ -456,34 +421,17 @@ grub_ip2str (grub_uint32_t ip) return str_ip; } + void -grub_get_netinfo (grub_ofnet_t netinfo,grub_bootp_t packet) +grub_disknet_init(void) { - netinfo->sip = grub_ip2str(packet->siaddr); - netinfo->cip = grub_ip2str(packet->yiaddr); - netinfo->gat = grub_ip2str(packet->giaddr); - grub_printf("packet->siaddr = %x\n",packet->siaddr); - grub_printf("netinfo-> = %s\n",netinfo->sip); - grub_printf("packet->yiaddr = %x\n",packet->yiaddr); - grub_printf("netinfo-> = %s\n",netinfo->cip); - grub_printf("packet->giaddr = %x\n",packet->giaddr); - grub_printf("netinfo-> = %s\n",netinfo->gat); + + grub_disk_dev_register (&grub_ofnet_dev); + grub_fs_register (&grub_ofnetfs_fs); } + void -grub_ofnet_init(void) -{ - tftp_ini (); - bootp_pckt = grub_getbootp (); - if(grub_ofnet_detect ()) - { - grub_get_netinfo (grub_net, bootp_pckt ); - grub_disk_dev_register (&grub_ofnet_dev); - grub_fs_register (&grub_ofnetfs_fs); - card_open (); - } -} -void -grub_ofnet_fini(void) +grub_disknet_fini(void) { grub_fs_unregister (&grub_ofnetfs_fs); grub_disk_dev_unregister (&grub_ofnet_dev); diff --git a/include/grub/ieee1275/ieee1275.h b/include/grub/ieee1275/ieee1275.h index f4c8b4edf..8fb558fa7 100644 --- a/include/grub/ieee1275/ieee1275.h +++ b/include/grub/ieee1275/ieee1275.h @@ -24,7 +24,6 @@ #include #include -/* Maps a device alias to a pathname. */ struct grub_ieee1275_devalias { char *name; @@ -65,6 +64,13 @@ struct grub_ieee1275_common_hdr typedef grub_uint32_t grub_ieee1275_ihandle_t; typedef grub_uint32_t grub_ieee1275_phandle_t; +struct grub_ofnetcard_data +{ + char *path; + grub_ieee1275_ihandle_t handle; +}; + +/* Maps a device alias to a pathname. */ extern grub_ieee1275_phandle_t EXPORT_VAR(grub_ieee1275_chosen); extern grub_ieee1275_ihandle_t EXPORT_VAR(grub_ieee1275_mmu); extern int (* EXPORT_VAR(grub_ieee1275_entry_fn)) (void *); @@ -186,4 +192,6 @@ int EXPORT_FUNC(grub_ieee1275_devices_iterate) (int (*hook) (struct grub_ieee1275_devalias * alias)); char *EXPORT_FUNC(grub_ieee1275_get_aliasdevname) (const char *path); +void EXPORT_FUNC(grub_ofnet_findcards) (void); +void EXPORT_FUNC(grub_ofnet_probecards) (void); #endif /* ! GRUB_IEEE1275_HEADER */ diff --git a/include/grub/ieee1275/ofnet.h b/include/grub/ieee1275/ofnet.h index a26c22235..ba4c62630 100644 --- a/include/grub/ieee1275/ofnet.h +++ b/include/grub/ieee1275/ofnet.h @@ -23,32 +23,9 @@ #include #include -extern void grub_ofnet_init(void); -extern void grub_ofnet_fini(void); +void grub_ofnet_init(void); +void grub_ofnet_fini(void); -/* -struct grub_net; - -struct grub_net_dev -{ - / The device name. / - const char *name; - - / FIXME: Just a template. / - int (*probe) (struct grub_net *net, const void *addr); - void (*reset) (struct grub_net *net); - int (*poll) (struct grub_net *net); - void (*transmit) (struct grub_net *net, const void *destip, - unsigned srcsock, unsigned destsock, const void *packet); - void (*disable) (struct grub_net *net); - - / The next net device. / - struct grub_net_dev *next; -}; -typedef struct grub_net_dev *grub_net_dev_t; - -struct grub_fs; -*/ struct grub_ofnet { /* The net name. */ @@ -85,7 +62,7 @@ struct grub_bootp { char file [128]; /* Boot filename */ // grub_uint32_t filesize ; /*File size (testing)*/ unsigned char vend [64]; -}; +}; typedef struct grub_bootp* grub_bootp_t; diff --git a/include/grub/net/disknet.h b/include/grub/net/disknet.h new file mode 100644 index 000000000..59aa2a320 --- /dev/null +++ b/include/grub/net/disknet.h @@ -0,0 +1,5 @@ +#ifndef GRUB_DISKNET_HEADER +#define GRUB_DISKNET_HEADER 1 + void grub_disknet_init(void); + void grub_disknet_fini(void); +#endif /* ! GRUB_NET_HEADER */ diff --git a/include/grub/net/ethernet.h b/include/grub/net/ethernet.h index 9043a5f02..f4a6c22cf 100644 --- a/include/grub/net/ethernet.h +++ b/include/grub/net/ethernet.h @@ -10,9 +10,18 @@ struct etherhdr grub_uint16_t type; } __attribute__ ((packed)); -#define PCP (x) x & 0xe000 -#define CFI (x) x & 0x1000 -#define VID (x) x & 0x0fff +#define PCP(x) x & 0xe000 +#define CFI(x) x & 0x1000 +#define VID(x) x & 0x0fff +#define PRINT_ETH_ADDR(name,addr) grub_printf("%s %x:%x:%x:%x:%x:%x\n",\ + name,\ + addr[0],\ + addr[1],\ + addr[2],\ + addr[3],\ + addr[4],\ + addr[5]\ + ) struct llchdr { diff --git a/include/grub/net/ieee1275/interface.h b/include/grub/net/ieee1275/interface.h index 16f624c05..c369e35a6 100644 --- a/include/grub/net/ieee1275/interface.h +++ b/include/grub/net/ieee1275/interface.h @@ -6,14 +6,5 @@ #include #include - -grub_ofnet_t grub_net; - grub_bootp_t bootp_pckt; - -int send_card_buffer (struct grub_net_buff *pack); -int get_card_packet (struct grub_net_buff *pack); -int card_open (void); -int card_close (void); - #endif diff --git a/include/grub/net/mem.h b/include/grub/net/mem.h new file mode 100644 index 000000000..bbdac512b --- /dev/null +++ b/include/grub/net/mem.h @@ -0,0 +1,9 @@ +#ifndef GRUB_NETMM_H +#define GRUB_NETMM_H 1 + +#include +#include + +void *EXPORT_FUNC(grub_net_malloc) (grub_size_t size); + +#endif /* ! GRUB_MM_H */ diff --git a/kern/ieee1275/openfw.c b/kern/ieee1275/openfw.c index 337fc4b7e..2650ff3d4 100644 --- a/kern/ieee1275/openfw.c +++ b/kern/ieee1275/openfw.c @@ -23,6 +23,10 @@ #include #include #include +#include +#include +#include +#include enum grub_ieee1275_parse_type { @@ -490,3 +494,63 @@ grub_getbootp( void ) return packet; } +void grub_ofnet_findcards (void) +{ + struct grub_net_card *card; + int i = 0; + + auto int search_net_devices (struct grub_ieee1275_devalias *alias); + + int search_net_devices (struct grub_ieee1275_devalias *alias) + { + if ( !grub_strcmp (alias->type,"network") ) + { + + card = grub_malloc (sizeof (struct grub_net_card)); + struct grub_ofnetcard_data *ofdata = grub_malloc (sizeof (struct grub_ofnetcard_data)); + ofdata->path = grub_strdup (alias->path); + card->data = ofdata; + card->name = grub_xasprintf("eth%d",i++); // grub_strdup (alias->name); + grub_net_card_register (card); + } + return 0; + } + + /*Look at all nodes for devices of the type network*/ + grub_ieee1275_devices_iterate (search_net_devices); + +} + +void grub_ofnet_probecards (void) +{ + struct grub_net_card *card; + struct grub_net_card_driver *driver; + + /*Assign correspondent driver for each device. */ + FOR_NET_CARDS (card) + { + FOR_NET_CARD_DRIVERS (driver) + { + if (driver->init(card) == GRUB_ERR_NONE) + { + card->driver = driver; + continue; + } + } + } +} + +void +grub_ofnet_init(void) +{ + + ofdriver_ini(); + grub_ofnet_findcards(); + grub_ofnet_probecards(); + + /*init tftp stack - will be handled by module subsystem in the future*/ + tftp_ini (); + /*get bootp packet - won't be needed in the future*/ + bootp_pckt = grub_getbootp (); + grub_disknet_init(); +} diff --git a/net/drivers/ieee1275/ofdriver.c b/net/drivers/ieee1275/ofdriver.c new file mode 100644 index 000000000..5f6c3c2f6 --- /dev/null +++ b/net/drivers/ieee1275/ofdriver.c @@ -0,0 +1,74 @@ +#include +#include +#include +#include + +static +grub_err_t card_open (struct grub_net_card *dev) +{ + + struct grub_ofnetcard_data *data = dev->data; + return grub_ieee1275_open (data->path,&(data->handle)); +} + +static +grub_err_t card_close (struct grub_net_card *dev) +{ + + struct grub_ofnetcard_data *data = dev->data; + + if (data->handle) + grub_ieee1275_close (data->handle); + return GRUB_ERR_NONE; +} + +static +grub_err_t send_card_buffer (struct grub_net_card *dev, struct grub_net_buff *pack) +{ + + int actual; + struct grub_ofnetcard_data *data = dev->data; + + return grub_ieee1275_write (data->handle,pack->data,pack->tail - pack->data,&actual); +} + +static +grub_err_t get_card_packet (struct grub_net_card *dev, struct grub_net_buff *pack) +{ + + int actual, rc; + struct grub_ofnetcard_data *data = dev->data; + grub_netbuff_clear(pack); + + do + { + rc = grub_ieee1275_read (data->handle,pack->data,1500,&actual); + + }while (actual <= 0 || rc < 0); + grub_netbuff_put (pack, actual); + + return GRUB_ERR_NONE; +} + +static struct grub_net_card_driver ofdriver = +{ + .name = "ofnet", + .init = card_open, + .fini = card_close, + .send = send_card_buffer, + .recv = get_card_packet + +}; + +void ofdriver_ini(void) +{ + grub_net_card_driver_register (&ofdriver); +} + +void ofdriver_fini(void) +{ + grub_net_card_driver_unregister (&ofdriver); +} + + + diff --git a/net/ethernet.c b/net/ethernet.c index 14bc41c5b..7b578abab 100644 --- a/net/ethernet.c +++ b/net/ethernet.c @@ -22,10 +22,10 @@ struct grub_net_addr target_addr, grub_uint16_t ethertype) eth = (struct etherhdr *) nb->data; grub_memcpy(eth->dst, target_addr.addr, target_addr.len); grub_memcpy(eth->src, bootp_pckt->chaddr, 6); + eth->type = ethertype; - return send_card_buffer(nb); -// return inf->card->driver->send(inf->card,nb); + return inf->card->driver->send (inf->card,nb); } @@ -42,12 +42,11 @@ grub_uint16_t ethertype) start_time = grub_get_time_ms(); while (1) { - get_card_packet (nb); + inf->card->driver->recv (inf->card,nb); eth = (struct etherhdr *) nb->data; type = eth->type; grub_netbuff_pull(nb,sizeof (*eth)); - // grub_printf("ethernet type 58 %x\n",type); - // grub_printf("ethernet eth->type 58 %x\n",type); + if (eth->type <=1500) { llch = (struct llchdr *) nb->data; diff --git a/net/i386/mem.c b/net/i386/mem.c new file mode 100644 index 000000000..d6c98ea80 --- /dev/null +++ b/net/i386/mem.c @@ -0,0 +1,10 @@ +#include +#include +#include +#include + + +void *grub_net_malloc (grub_size_t size) +{ + return grub_malloc (size); +} diff --git a/net/ieee1275/interface.c b/net/ieee1275/interface.c deleted file mode 100644 index 342044041..000000000 --- a/net/ieee1275/interface.c +++ /dev/null @@ -1,46 +0,0 @@ -#include -#include -#include - -static grub_ieee1275_ihandle_t handle; -int card_open (void) -{ - - grub_ieee1275_open (grub_net->dev , &handle); - return 0; - -} - -int card_close (void) -{ - - if (handle) - grub_ieee1275_close (handle); - return 0; -} - - -int send_card_buffer (struct grub_net_buff *pack) -{ - - int actual; - grub_ieee1275_write (handle,pack->data,pack->tail - pack->data,&actual); - - return actual; -} - -int get_card_packet (struct grub_net_buff *pack __attribute__ ((unused))) -{ - - int actual, rc; - pack->data = pack->tail = pack->head; - do - { - rc = grub_ieee1275_read (handle,pack->data,1500,&actual); - - }while (actual <= 0 || rc < 0); - grub_netbuff_put (pack, actual); - -// grub_printf("packsize %d\n",pack->tail - pack->data); - return 0;// sizeof (eth) + iph.len; -} diff --git a/net/ieee1275/mem.c b/net/ieee1275/mem.c new file mode 100644 index 000000000..416a04253 --- /dev/null +++ b/net/ieee1275/mem.c @@ -0,0 +1,32 @@ +#include +#include +#include +#include +#include +#include +#define TRASHOLD_SIZE 5 * 1024 * 1024 + +void *grub_net_malloc (grub_size_t size) +{ + + int found = 0; + grub_addr_t found_addr; + + if (size <= TRASHOLD_SIZE) + return grub_malloc (size); + + for (found_addr = 0x800000; found_addr < + 2000 * 0x100000; found_addr += 0x100000) + { + if (grub_claimmap (found_addr , size) != -1) + { + found = 1; + break; + } + } + + if (!found) + grub_error (GRUB_ERR_OUT_OF_MEMORY, "out of memory"); + + return found?(void *) found_addr:NULL; + +} diff --git a/net/protocol.c b/net/protocol.c index 05d4471d2..bdd7f3671 100644 --- a/net/protocol.c +++ b/net/protocol.c @@ -2,6 +2,8 @@ #include #include +struct grub_net_network_layer_protocol *grub_net_network_layer_protocols = NULL; + #define PROTOCOL_REGISTER_FUNCTIONS(layername) \ struct grub_net_##layername##_layer_protocol *grub_net_##layername##_layer_protocols;\ \ From 6b1b3423dd0d5c38d561d5b7ab5ea082ca7ef620 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 22 Sep 2010 17:14:14 +0200 Subject: [PATCH 052/869] Fix error handling in ofnet --- grub-core/net/drivers/ieee1275/ofnet.c | 42 +++++++++++++++----------- 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/grub-core/net/drivers/ieee1275/ofnet.c b/grub-core/net/drivers/ieee1275/ofnet.c index 064f3d280..ce5276efe 100644 --- a/grub-core/net/drivers/ieee1275/ofnet.c +++ b/grub-core/net/drivers/ieee1275/ofnet.c @@ -3,18 +3,21 @@ #include #include -static -grub_err_t card_open (struct grub_net_card *dev) +static grub_err_t +card_open (struct grub_net_card *dev) { - + int status; struct grub_ofnetcard_data *data = dev->data; - return grub_ieee1275_open (data->path,&(data->handle)); + status = grub_ieee1275_open (data->path,&(data->handle)); + + if (status) + return grub_error (GRUB_ERR_IO, "couldn't open network card"); + return GRUB_ERR_NONE; } -static -grub_err_t card_close (struct grub_net_card *dev) +static grub_err_t +card_close (struct grub_net_card *dev) { - struct grub_ofnetcard_data *data = dev->data; if (data->handle) @@ -22,18 +25,23 @@ grub_err_t card_close (struct grub_net_card *dev) return GRUB_ERR_NONE; } -static -grub_err_t send_card_buffer (struct grub_net_card *dev, struct grub_net_buff *pack) -{ - +static grub_err_t +send_card_buffer (struct grub_net_card *dev, struct grub_net_buff *pack) +{ int actual; + int status; struct grub_ofnetcard_data *data = dev->data; - return grub_ieee1275_write (data->handle,pack->data,pack->tail - pack->data,&actual); + status = grub_ieee1275_write (data->handle, pack->data, + pack->tail - pack->data, &actual); + + if (status) + return grub_error (GRUB_ERR_IO, "couldn't send network packet"); + return GRUB_ERR_NONE; } -static -grub_err_t get_card_packet (struct grub_net_card *dev, struct grub_net_buff *pack) +static grub_err_t +get_card_packet (struct grub_net_card *dev, struct grub_net_buff *pack) { int actual, rc; @@ -41,10 +49,8 @@ grub_err_t get_card_packet (struct grub_net_card *dev, struct grub_net_buff *pac grub_netbuff_clear(pack); do - { - rc = grub_ieee1275_read (data->handle,pack->data,1500,&actual); - - }while (actual <= 0 || rc < 0); + rc = grub_ieee1275_read (data->handle, pack->data, 1500, &actual); + while (actual <= 0 || rc < 0); grub_netbuff_put (pack, actual); return GRUB_ERR_NONE; From 90451bb1c951bbc90f479084b28ddb1e09d8ac8d Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 22 Sep 2010 17:14:43 +0200 Subject: [PATCH 053/869] networking in grub-emu --- grub-core/Makefile.core.def | 6 +++ grub-core/net/drivers/emu/emunet.c | 69 ++++++++++++++++++++++++++++++ include/grub/net.h | 6 ++- 3 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 grub-core/net/drivers/emu/emunet.c diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def index 5cacb6851..2f55ba5ec 100644 --- a/grub-core/Makefile.core.def +++ b/grub-core/Makefile.core.def @@ -1398,3 +1398,9 @@ module = { ieee1275 = net/drivers/ieee1275/ofnet.c; enable = ieee1275; }; + +module = { + name = emunet; + emu = net/drivers/emu/emunet.c; + enable = ieee1275; +}; diff --git a/grub-core/net/drivers/emu/emunet.c b/grub-core/net/drivers/emu/emunet.c new file mode 100644 index 000000000..8914a1d95 --- /dev/null +++ b/grub-core/net/drivers/emu/emunet.c @@ -0,0 +1,69 @@ +#include +#include +#include +#include /* the L2 protocols */ +#include + +static grub_err_t +card_open (struct grub_net_card *dev) +{ + dev->data_num = socket (AF_PACKET, SOCK_RAW, htons(ETH_P_ALL)); + if (dev->data_num < 0) + return grub_error (GRUB_ERR_IO, "couldn't open packet interface"); + return GRUB_ERR_NONE; +} + +static grub_err_t +card_close (struct grub_net_card *dev) +{ + close (dev->data_num); + return GRUB_ERR_NONE; +} + +static grub_err_t +send_card_buffer (struct grub_net_card *dev, struct grub_net_buff *pack) +{ + ssize_t actual; + + actual = write (dev->data_num, pack->data, pack->tail - pack->data); + if (actual < 0) + return grub_error (GRUB_ERR_IO, "couldn't send packets"); + + return GRUB_ERR_NONE; +} + +static grub_err_t +get_card_packet (struct grub_net_card *dev, struct grub_net_buff *pack) +{ + ssize_t actual; + + grub_netbuff_clear(pack); + actual = read (dev->data_num, pack->data, 1500); + if (actual < 0) + return grub_error (GRUB_ERR_IO, "couldn't receive packets"); + grub_netbuff_put (pack, actual); + + return GRUB_ERR_NONE; +} + +static struct grub_net_card_driver emudriver = +{ + .name = "emu", + .init = card_open, + .fini = card_close, + .send = send_card_buffer, + .recv = get_card_packet +}; + +GRUB_MOD_INIT(emunet) +{ + grub_net_card_driver_register (&emudriver); +} + +GRUB_MODE_FINI(emunet) +{ + grub_net_card_driver_unregister (&emudriver); +} + + + diff --git a/include/grub/net.h b/include/grub/net.h index ad553a69a..de188f615 100644 --- a/include/grub/net.h +++ b/include/grub/net.h @@ -84,7 +84,11 @@ struct grub_net_card struct grub_net_card_driver *driver; grub_net_link_level_address_t default_address; grub_net_card_flags_t flags; - void *data; + union + { + void *data; + int data_num; + }; }; struct grub_net_network_level_interface; From ce3a2ec0256a6442cc9a3b47a6d218baf3412c39 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 22 Sep 2010 20:34:20 +0200 Subject: [PATCH 054/869] Remove some dead code --- grub-core/Makefile.core.def | 1 - grub-core/net/arp.c | 3 +- grub-core/net/ethernet.c | 1 - grub-core/net/interface.c | 37 ------------------- grub-core/net/ip.c | 2 -- grub-core/net/netbuff.c | 2 +- grub-core/net/tftp.c | 2 -- grub-core/net/udp.c | 3 -- include/grub/net.h | 3 +- include/grub/net/arp.h | 1 - include/grub/net/interface.h | 70 ------------------------------------ include/grub/net/protocol.h | 9 ----- include/grub/net/type_net.h | 33 ----------------- 13 files changed, 3 insertions(+), 164 deletions(-) delete mode 100644 grub-core/net/interface.c delete mode 100644 include/grub/net/interface.h delete mode 100644 include/grub/net/protocol.h delete mode 100644 include/grub/net/type_net.h diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def index d48c5d505..49dbd3f60 100644 --- a/grub-core/Makefile.core.def +++ b/grub-core/Makefile.core.def @@ -1438,7 +1438,6 @@ module = { common = net/udp.c; common = net/ethernet.c; common = net/arp.c; - common = net/interface.c; common = net/netbuff.c; }; diff --git a/grub-core/net/arp.c b/grub-core/net/arp.c index 5e10938ae..541b89411 100644 --- a/grub-core/net/arp.c +++ b/grub-core/net/arp.c @@ -1,6 +1,5 @@ #include #include -#include #include #include #include @@ -92,7 +91,7 @@ grub_net_arp_resolve(struct grub_net_network_level_interface *inf, return GRUB_ERR_NONE; } current_time = grub_get_time_ms(); - if (current_time - start_time > TIMEOUT_TIME_MS) + if (current_time - start_time > 3000) break; } while (! entry); grub_netbuff_clear(nb); diff --git a/grub-core/net/ethernet.c b/grub-core/net/ethernet.c index d3a34aec6..a40e1f795 100644 --- a/grub-core/net/ethernet.c +++ b/grub-core/net/ethernet.c @@ -4,7 +4,6 @@ #include #include #include -#include #include #include #include diff --git a/grub-core/net/interface.c b/grub-core/net/interface.c deleted file mode 100644 index f17b3e66b..000000000 --- a/grub-core/net/interface.c +++ /dev/null @@ -1,37 +0,0 @@ -/*#include - -#define INTERFACE_REGISTER_FUNCTIONS(layerprevious,layernext) \ -struct grub_net_##layername_layer_protocol *grub_net_##layername_layer_protocols;\ -\ -void grub_net_##layerprevious_##layernext_interface_register (struct grub_net_##layername_layer_protocol *prot)\ -{\ - grub_list_push (GRUB_AS_LIST_P (&grub_net_##layername_layer_protocols),\ - GRUB_AS_LIST (prot));\ -}\ -\ -void grub_net_##layerprevious_##layernext_interface_unregister (struct grub_net_##layername_layer_protocol *prot);\ -{\ - grub_list_remove (GRUB_AS_LIST_P (&grub_net_##layername_layer_protocols),\ - GRUB_AS_LIST (prot));\ -}\ - -INTERFACE_REGISTER_FUNCTIONS("application","transport"); -INTERFACE_REGISTER_FUNCTIONS("transport","network"); -INTERFACE_REGISTER_FUNCTIONS("network","link"); -INTERFACE_REGISTER_FUNCTIONS("link");*/ - -#include -#include -struct grub_net_protocol_stack - *grub_net_protocol_stack_get (char *name) -{ - struct grub_net_protocol_stack *p; - - for (p = grub_net_protocol_stacks; p; p = p->next) - { - if (!grub_strcmp(p->name,name)) - return p; - } - - return NULL; -} diff --git a/grub-core/net/ip.c b/grub-core/net/ip.c index 264195ad3..023564a5a 100644 --- a/grub-core/net/ip.c +++ b/grub-core/net/ip.c @@ -2,8 +2,6 @@ #include #include #include -#include -#include #include #include #include diff --git a/grub-core/net/netbuff.c b/grub-core/net/netbuff.c index 4f6a1da84..cc366ae09 100644 --- a/grub-core/net/netbuff.c +++ b/grub-core/net/netbuff.c @@ -73,7 +73,7 @@ struct grub_net_buff *grub_netbuff_alloc ( grub_size_t len ) len = ALIGN_UP (len,NETBUFF_ALIGN); data = grub_memalign (NETBUFF_ALIGN, len + sizeof (*nb)); - nb = (struct grub_net_buff *) ((int)data + len); + nb = (struct grub_net_buff *) ((grub_uint8_t *) data + len); nb->head = nb->data = nb->tail = data; nb->end = (char *) nb; diff --git a/grub-core/net/tftp.c b/grub-core/net/tftp.c index bb518b78f..b9e3f49c4 100644 --- a/grub-core/net/tftp.c +++ b/grub-core/net/tftp.c @@ -4,8 +4,6 @@ #include #include #include -#include -#include #include #include #include diff --git a/grub-core/net/udp.c b/grub-core/net/udp.c index 27e23e826..a73431f83 100644 --- a/grub-core/net/udp.c +++ b/grub-core/net/udp.c @@ -1,10 +1,7 @@ #include #include #include -#include #include -#include -#include #include grub_err_t diff --git a/include/grub/net.h b/include/grub/net.h index de188f615..20bf3c0e6 100644 --- a/include/grub/net.h +++ b/include/grub/net.h @@ -23,9 +23,8 @@ #include #include #include +#include #include -#include -#include typedef struct grub_fs *grub_net_app_level_t; diff --git a/include/grub/net/arp.h b/include/grub/net/arp.h index e547669a2..1475086e4 100644 --- a/include/grub/net/arp.h +++ b/include/grub/net/arp.h @@ -2,7 +2,6 @@ #define GRUB_NET_ARP_HEADER 1 #include #include -#include /* IANA ARP constant to define hardware type as ethernet */ #define ARPHRD_ETHERNET 1 diff --git a/include/grub/net/interface.h b/include/grub/net/interface.h deleted file mode 100644 index cf24dd22e..000000000 --- a/include/grub/net/interface.h +++ /dev/null @@ -1,70 +0,0 @@ -#ifndef GRUB_INTERFACE_HEADER -#define GRUB_INTERFACE_HEADER -//#include -#include -#include -#include - -struct grub_net_protocol_stack -{ - struct grub_net_protocol_stack *next; - char *name; - grub_net_protocol_id_t id; - void *interface; -}; - -struct grub_net_application_transport_interface -{ - struct grub_net_transport_network_interface *inner_layer; - void *data; - struct grub_net_application_layer_protocol *app_prot; - struct grub_net_transport_layer_protocol *trans_prot; -}; - -struct grub_net_transport_network_interface -{ - struct grub_net_network_link_interface *inner_layer; - void *data; - struct grub_net_transport_layer_protocol *trans_prot; - struct grub_net_network_layer_protocol *net_prot; -}; - -struct grub_net_network_link_interface -{ - void *data; - struct grub_net_network_layer_protocol *net_prot; - struct grub_net_link_layer_protocol *link_prot; -}; - - -struct grub_net_protocol_stack *grub_net_protocol_stacks; -static inline void -grub_net_stack_register (struct grub_net_protocol_stack *stack) -{ - - grub_list_push (GRUB_AS_LIST_P (&grub_net_protocol_stacks), - GRUB_AS_LIST (stack)); -} -/* -void grub_net_stack_unregister (struct grub_net_protocol_stack *stack) -{ - grub_list_remove (GRUB_AS_LIST_P (&grub_net_protocol_stacks), - GRUB_AS_LIST (stack)); -}*/ - -struct grub_net_protocol_stack *grub_net_protocol_stack_get (char *name); - -/* -static inline void -grub_net_interface_application_transport_register (struct grub_net_application_transport_interface); -static inline void -grub_net_interface_application_transport_unregister (struct grub_net_application_transport_interface); -static inline void -grub_net_interface_transport_network_register (struct grub_net_transport_network_interface); -static inline void -grub_net_interface_transport_network_unregister (struct grub_net_transport_network_interface); -static inline void -grub_net_interface_network_link_register (struct grub_net_network_link_interface); -static inline void -grub_net_interface_network_link_unregister (struct grub_net_network_link_interface);*/ -#endif diff --git a/include/grub/net/protocol.h b/include/grub/net/protocol.h deleted file mode 100644 index da54b073f..000000000 --- a/include/grub/net/protocol.h +++ /dev/null @@ -1,9 +0,0 @@ -#ifndef GRUB_PROTOCOL_HEADER -#define GRUB_PROTOCOL_HEADER -#include -#include -#include -#include -#include - -#endif diff --git a/include/grub/net/type_net.h b/include/grub/net/type_net.h deleted file mode 100644 index f159b1de0..000000000 --- a/include/grub/net/type_net.h +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef GRUB_TYPES_NET_HEADER -#define GRUB_TYPES_NET_HEADER 1 -#include - - -#define UDP_PCKT 0x11 -#define IP_PCKT 0x0800 -#define TIMEOUT_TIME_MS 3*1000 -typedef enum -{ - GRUB_NET_TFTP_ID, - GRUB_NET_UDP_ID, - GRUB_NET_IPV4_ID, - GRUB_NET_IPV6_ID, - GRUB_NET_ETHERNET_ID, - GRUB_NET_ARP_ID, - GRUB_NET_DHCP_ID -}grub_net_protocol_id_t; - - -typedef union grub_net_network_layer_netaddress -{ - grub_uint32_t ipv4; -} grub_net_network_layer_address_t; - -typedef union grub_net_network_layer_address -{ - struct { - grub_uint32_t base; - int masksize; - } ipv4; -} grub_net_network_layer_netaddress_t; -#endif From 04d22dddd985e49779fbdd570d1b4f0847dc4347 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Thu, 23 Sep 2010 00:45:39 +0200 Subject: [PATCH 055/869] Fix a bunch of net issues --- grub-core/net/arp.c | 85 ++++++++-------- grub-core/net/drivers/emu/emunet.c | 84 ++++++++++------ grub-core/net/ethernet.c | 14 +-- grub-core/net/ip.c | 11 +- grub-core/net/net.c | 6 +- grub-core/net/tftp.c | 155 +++++++++++------------------ include/grub/net/arp.h | 12 +-- include/grub/net/ethernet.h | 8 ++ include/grub/net/ip.h | 2 - 9 files changed, 181 insertions(+), 196 deletions(-) diff --git a/grub-core/net/arp.c b/grub-core/net/arp.c index 541b89411..c7b5d0573 100644 --- a/grub-core/net/arp.c +++ b/grub-core/net/arp.c @@ -6,7 +6,7 @@ #include #include -static struct arp_entry arp_table[SIZE_ARP_TABLE]; +static struct arp_entry arp_table[10]; static grub_int8_t new_table_entry = -1; static @@ -19,8 +19,8 @@ void arp_init_table(void) static struct arp_entry * arp_find_entry (const grub_net_network_level_address_t *proto) { - grub_uint8_t i; - for(i=0;i < SIZE_ARP_TABLE; i++) + unsigned i; + for(i = 0; i < ARRAY_SIZE (arp_table); i++) { if(arp_table[i].avail == 1 && arp_table[i].nl_address.ipv4 == proto->ipv4) @@ -48,24 +48,26 @@ grub_net_arp_resolve(struct grub_net_network_level_interface *inf, return GRUB_ERR_NONE; } /* Build a request packet */ - nb = grub_malloc (2048); + nb = grub_netbuff_alloc (2048); + if (!nb) + return grub_errno; grub_netbuff_reserve(nb, 2048); grub_netbuff_push(nb, sizeof(*arp_header) + 2 * (6 + 6)); arp_header = (struct arphdr *)nb->data; - arp_header->hrd = 0; - arp_header->pro = 0; + arp_header->hrd = grub_cpu_to_be16 (GRUB_NET_ARPHRD_ETHERNET); + arp_header->pro = grub_cpu_to_be16 (GRUB_NET_ETHERTYPE_IP); arp_header->hln = 6; - arp_header->pln = 6; - arp_header->op = ARP_REQUEST; + arp_header->pln = 4; + arp_header->op = grub_cpu_to_be16 (ARP_REQUEST); aux = (grub_uint8_t *)arp_header + sizeof(*arp_header); /* Sender hardware address */ grub_memcpy(aux, &inf->hwaddress.mac, 6); aux += 6; /* Sender protocol address */ grub_memcpy(aux, &inf->address.ipv4, 4); - aux += 6; + aux += 4; /* Target hardware address */ - for(i=0; i < 6; i++) + for(i = 0; i < 6; i++) aux[i] = 0x00; aux += 6; /* Target protocol address */ @@ -73,7 +75,7 @@ grub_net_arp_resolve(struct grub_net_network_level_interface *inf, grub_memset (&target_hw_addr.mac, 0xff, 6); - send_ethernet_packet (inf, nb, target_hw_addr, ARP_ETHERTYPE); + send_ethernet_packet (inf, nb, target_hw_addr, GRUB_NET_ETHERTYPE_ARP); grub_netbuff_clear(nb); grub_netbuff_reserve(nb, 2048); @@ -81,7 +83,7 @@ grub_net_arp_resolve(struct grub_net_network_level_interface *inf, start_time = grub_get_time_ms(); do { - grub_net_recv_ethernet_packet (inf, nb, ARP_ETHERTYPE); + grub_net_recv_ethernet_packet (inf, nb, GRUB_NET_ETHERTYPE_ARP); /* Now check cache table again */ entry = arp_find_entry(proto_addr); if (entry) @@ -90,7 +92,7 @@ grub_net_arp_resolve(struct grub_net_network_level_interface *inf, grub_netbuff_clear(nb); return GRUB_ERR_NONE; } - current_time = grub_get_time_ms(); + current_time = grub_get_time_ms(); if (current_time - start_time > 3000) break; } while (! entry); @@ -99,17 +101,16 @@ grub_net_arp_resolve(struct grub_net_network_level_interface *inf, } grub_err_t -grub_net_arp_receive(struct grub_net_network_level_interface *inf, - struct grub_net_buff *nb) +grub_net_arp_receive (struct grub_net_network_level_interface *inf, + struct grub_net_buff *nb) { struct arphdr *arp_header = (struct arphdr *)nb->data; struct arp_entry *entry; - grub_uint8_t merge = 0; grub_uint8_t *sender_hardware_address, *sender_protocol_address; grub_uint8_t *target_hardware_address, *target_protocol_address; grub_net_network_level_address_t hwaddress; - sender_hardware_address = (grub_uint8_t *)arp_header + sizeof(*arp_header); + sender_hardware_address = (grub_uint8_t *) arp_header + sizeof(*arp_header); sender_protocol_address = sender_hardware_address + arp_header->hln; target_hardware_address = sender_protocol_address + arp_header->pln; target_protocol_address = target_hardware_address + arp_header->hln; @@ -118,40 +119,36 @@ grub_net_arp_receive(struct grub_net_network_level_interface *inf, entry = arp_find_entry(&hwaddress); /* Update sender hardware address */ if (entry) + grub_memcpy(entry->ll_address.mac, sender_hardware_address, 6); + else { - grub_memcpy(entry->ll_address.mac, sender_hardware_address, 6); - merge = 1; - } - /* Am I the protocol address target? */ - if (! grub_memcmp(target_protocol_address, inf->hwaddress.mac, 6)) - { - /* Add sender to cache table */ - if (! merge) - { + /* Add sender to cache table */ if (new_table_entry == -1) - arp_init_table(); + arp_init_table(); entry = &(arp_table[new_table_entry]); entry->avail = 1; grub_memcpy(&entry->nl_address.ipv4, sender_protocol_address, 4); grub_memcpy(entry->ll_address.mac, sender_hardware_address, 6); new_table_entry++; - if (new_table_entry == SIZE_ARP_TABLE) - new_table_entry = 0; - } - if (arp_header->op == ARP_REQUEST) - { - grub_net_link_level_address_t aux; - /* Swap hardware fields */ - grub_memcpy(target_hardware_address, sender_hardware_address, arp_header->hln); - grub_memcpy(sender_hardware_address, inf->hwaddress.mac, 6); - grub_memcpy(aux.mac, sender_protocol_address, 6); - grub_memcpy(sender_protocol_address, target_protocol_address, arp_header->pln); - grub_memcpy(target_protocol_address, aux.mac, arp_header->pln); - /* Change operation to REPLY and send packet */ - arp_header->op = ARP_REPLY; - grub_memcpy (aux.mac, target_hardware_address, 6); - send_ethernet_packet (inf, nb, aux, ARP_ETHERTYPE); - } + if (new_table_entry == ARRAY_SIZE (arp_table)) + new_table_entry = 0; + } + + /* Am I the protocol address target? */ + if (grub_memcmp(target_protocol_address, inf->hwaddress.mac, 6) == 0 + && grub_be_to_cpu16 (arp_header->op) == ARP_REQUEST) + { + grub_net_link_level_address_t aux; + /* Swap hardware fields */ + grub_memcpy(target_hardware_address, sender_hardware_address, arp_header->hln); + grub_memcpy(sender_hardware_address, inf->hwaddress.mac, 6); + grub_memcpy(aux.mac, sender_protocol_address, 6); + grub_memcpy(sender_protocol_address, target_protocol_address, arp_header->pln); + grub_memcpy(target_protocol_address, aux.mac, arp_header->pln); + /* Change operation to REPLY and send packet */ + arp_header->op = grub_be_to_cpu16 (ARP_REPLY); + grub_memcpy (aux.mac, target_hardware_address, 6); + send_ethernet_packet (inf, nb, aux, GRUB_NET_ETHERTYPE_ARP); } return GRUB_ERR_NONE; } diff --git a/grub-core/net/drivers/emu/emunet.c b/grub-core/net/drivers/emu/emunet.c index 8914a1d95..9e4e66dce 100644 --- a/grub-core/net/drivers/emu/emunet.c +++ b/grub-core/net/drivers/emu/emunet.c @@ -1,68 +1,92 @@ + +#include #include #include -#include -#include /* the L2 protocols */ #include +#include +#include +#include +#include +#include +#include +#include + +static int fd; static grub_err_t -card_open (struct grub_net_card *dev) -{ - dev->data_num = socket (AF_PACKET, SOCK_RAW, htons(ETH_P_ALL)); - if (dev->data_num < 0) - return grub_error (GRUB_ERR_IO, "couldn't open packet interface"); - return GRUB_ERR_NONE; -} - -static grub_err_t -card_close (struct grub_net_card *dev) -{ - close (dev->data_num); - return GRUB_ERR_NONE; -} - -static grub_err_t -send_card_buffer (struct grub_net_card *dev, struct grub_net_buff *pack) +send_card_buffer (struct grub_net_card *dev __attribute__ ((unused)), + struct grub_net_buff *pack) { ssize_t actual; - actual = write (dev->data_num, pack->data, pack->tail - pack->data); + actual = write (fd, pack->data, pack->tail - pack->data); if (actual < 0) return grub_error (GRUB_ERR_IO, "couldn't send packets"); return GRUB_ERR_NONE; } -static grub_err_t -get_card_packet (struct grub_net_card *dev, struct grub_net_buff *pack) +static grub_size_t +get_card_packet (struct grub_net_card *dev __attribute__ ((unused)), + struct grub_net_buff *pack) { ssize_t actual; grub_netbuff_clear(pack); - actual = read (dev->data_num, pack->data, 1500); + actual = read (fd, pack->data, 1500); if (actual < 0) - return grub_error (GRUB_ERR_IO, "couldn't receive packets"); + { + grub_error (GRUB_ERR_IO, "couldn't receive packets"); + return -1; + } grub_netbuff_put (pack, actual); - return GRUB_ERR_NONE; + return actual; } static struct grub_net_card_driver emudriver = { .name = "emu", - .init = card_open, - .fini = card_close, .send = send_card_buffer, .recv = get_card_packet }; +static struct grub_net_card emucard = +{ + .name = "emu0", + .driver = &emudriver, + .default_address = { + .type = GRUB_NET_LINK_LEVEL_PROTOCOL_ETHERNET, + { .mac = { 0, 1, 2, 3, 4, 5} } + }, + .flags = 0 +}; + GRUB_MOD_INIT(emunet) { - grub_net_card_driver_register (&emudriver); + struct ifreq ifr; + // char fullname[64]; + fd = open ("/dev/net/tun", O_RDWR | O_NONBLOCK); + if (fd < 0) + return; + grub_memset (&ifr, 0, sizeof (ifr)); + ifr.ifr_flags = IFF_TAP | IFF_NO_PI; + if (ioctl (fd, TUNSETIFF, &ifr) < 0) + { + close (fd); + fd = -1; + return; + } + grub_net_card_register (&emucard); } -GRUB_MODE_FINI(emunet) +GRUB_MOD_FINI(emunet) { - grub_net_card_driver_unregister (&emudriver); + if (fd >= 0) + { + close (fd); + grub_net_card_unregister (&emucard); + } } diff --git a/grub-core/net/ethernet.c b/grub-core/net/ethernet.c index a40e1f795..cbda4c875 100644 --- a/grub-core/net/ethernet.c +++ b/grub-core/net/ethernet.c @@ -38,10 +38,10 @@ grub_net_recv_ethernet_packet (struct grub_net_network_level_interface *inf, inf->card->driver->recv (inf->card, nb); eth = (struct etherhdr *) nb->data; - type = eth->type; + type = grub_be_to_cpu16 (eth->type); grub_netbuff_pull(nb,sizeof (*eth)); - if (eth->type <=1500) + if (type <= 1500) { llch = (struct llchdr *) nb->data; type = llch->dsap & LLCADDRMASK; @@ -55,14 +55,10 @@ grub_net_recv_ethernet_packet (struct grub_net_network_level_interface *inf, } /* ARP packet */ - if (type == ARP_ETHERTYPE) - { - grub_net_arp_receive(inf, nb); - if (ethertype == ARP_ETHERTYPE) - return GRUB_ERR_NONE; - } + if (type == GRUB_NET_ETHERTYPE_ARP) + grub_net_arp_receive(inf, nb); /* IP packet */ - else if(type == IP_ETHERTYPE && ethertype == IP_ETHERTYPE) + if(type == GRUB_NET_ETHERTYPE_IP && ethertype == GRUB_NET_ETHERTYPE_IP) return GRUB_ERR_NONE; return GRUB_ERR_NONE; diff --git a/grub-core/net/ip.c b/grub-core/net/ip.c index 023564a5a..9a96ef532 100644 --- a/grub-core/net/ip.c +++ b/grub-core/net/ip.c @@ -54,7 +54,7 @@ grub_net_send_ip_packet (struct grub_net_network_level_interface *inf, if (err) return err; - return send_ethernet_packet (inf, nb, ll_target_addr, IP_ETHERTYPE); + return send_ethernet_packet (inf, nb, ll_target_addr, GRUB_NET_ETHERTYPE_IP); } static int @@ -84,8 +84,11 @@ ip_filter (struct grub_net_buff *nb, grub_err_t grub_net_recv_ip_packets (struct grub_net_network_level_interface *inf) { - struct grub_net_buff nb; - grub_net_recv_ethernet_packet (inf, &nb, IP_ETHERTYPE); - ip_filter (&nb, inf); + struct grub_net_buff *nb; + nb = grub_netbuff_alloc (2048); + if (!nb) + return grub_errno; + grub_net_recv_ethernet_packet (inf, nb, GRUB_NET_ETHERTYPE_IP); + ip_filter (nb, inf); return GRUB_ERR_NONE; } diff --git a/grub-core/net/net.c b/grub-core/net/net.c index 5205e1938..54663f4b0 100644 --- a/grub-core/net/net.c +++ b/grub-core/net/net.c @@ -92,7 +92,7 @@ parse_ip (const char *val, grub_uint32_t *ip, const char **rest) *ip = grub_cpu_to_le32 (newip); if (rest) *rest = ptr - 1; - return 0; + return 1; } static int @@ -341,7 +341,7 @@ grub_cmd_addaddr (struct grub_command *cmd __attribute__ ((unused)), return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("three arguments expected")); FOR_NET_CARDS (card) - if (grub_strcmp (card->name, args[1])) + if (grub_strcmp (card->name, args[1]) == 0) break; if (card == NULL) return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("card not found")); @@ -464,7 +464,7 @@ grub_cmd_addroute (struct grub_command *cmd __attribute__ ((unused)), struct grub_net_network_level_interface *inter; FOR_NET_NETWORK_LEVEL_INTERFACES (inter) - if (grub_strcmp (inter->name, args[2])) + if (grub_strcmp (inter->name, args[2]) == 0) break; if (!inter) diff --git a/grub-core/net/tftp.c b/grub-core/net/tftp.c index b9e3f49c4..16b60eeb6 100644 --- a/grub-core/net/tftp.c +++ b/grub-core/net/tftp.c @@ -9,60 +9,15 @@ #include #include -struct { - int block_size; - int size; -} tftp_file; -static int block; - - -static char *get_tok_val(char **tok, char **val, char **str_opt,char *end); -static void process_option(char *tok, char *val); - -static char * -get_tok_val(char **tok, char **val,char **str_opt,char *end) -{ - char *p = *str_opt; - *tok = p; - p += grub_strlen(p) + 1; - - if(p > end) - return NULL; - - *val = p; - p += grub_strlen(p) + 1; - *str_opt = p; - return *tok; -} - -static void -process_option(char *tok, char *val) -{ - if (!grub_strcmp(tok,"blksize")) - { - tftp_file.block_size = grub_strtoul (val,NULL,0); - return; - } - - if (!grub_strcmp(tok,"tsize")) - { - tftp_file.size = grub_strtoul (val,NULL,0); - return; - } - -} - -//void tftp_open (char *options); - -/*send read request*/ static grub_err_t tftp_open (struct grub_file *file, const char *filename) { struct tftphdr *tftph; char *rrq; + char *ptr; int rrqlen; int hdrlen; - struct grub_net_buff nb; + struct grub_net_buff *nb; grub_net_network_level_address_t addr; grub_err_t err; @@ -70,29 +25,28 @@ tftp_open (struct grub_file *file, const char *filename) + sizeof ("tftp,") - 1, &addr); if (err) return err; - - grub_memset (&nb, 0, sizeof (nb)); - grub_netbuff_push (&nb,sizeof (*tftph)); - tftph = (struct tftphdr *) nb.data; + nb = grub_netbuff_alloc (2048); + if (!nb) + return grub_errno; + + grub_netbuff_reserve (nb,2048); + grub_netbuff_push (nb,sizeof (*tftph)); + + tftph = (struct tftphdr *) nb->data; rrq = (char *) tftph->u.rrq; rrqlen = 0; - tftph->opcode = TFTP_RRQ; + tftph->opcode = grub_cpu_to_be16 (TFTP_RRQ); grub_strcpy (rrq, filename); rrqlen += grub_strlen (filename) + 1; rrq += grub_strlen (filename) + 1; - /*passar opcoes como parametro ou usar default?*/ grub_strcpy (rrq,"octet"); rrqlen += grub_strlen ("octet") + 1; rrq += grub_strlen ("octet") + 1; - //grub_strcpy (rrq,"netascii"); - //rrqlen += grub_strlen ("netascii") + 1; - //rrq += grub_strlen ("netascii") + 1; - grub_strcpy (rrq,"blksize"); rrqlen += grub_strlen("blksize") + 1; rrq += grub_strlen ("blksize") + 1; @@ -107,29 +61,53 @@ tftp_open (struct grub_file *file, const char *filename) grub_strcpy (rrq,"0"); rrqlen += grub_strlen ("0") + 1; - rrq += grub_strlen ("0") + 1; + rrq += grub_strlen ("0") + 1; hdrlen = sizeof (tftph->opcode) + rrqlen; - grub_netbuff_unput (&nb,nb.tail - (nb.data+hdrlen)); + grub_netbuff_unput (nb,nb->tail - (nb->data+hdrlen)); - grub_net_send_udp_packet (&addr, - &nb, TFTP_CLIENT_PORT, TFTP_SERVER_PORT); + err = grub_net_send_udp_packet (&addr, + nb, TFTP_CLIENT_PORT, TFTP_SERVER_PORT); + if (err) + return err; - grub_net_send_udp_packet (&addr, &nb, TFTP_CLIENT_PORT, TFTP_SERVER_PORT); - /*Receive OACK*/ - grub_netbuff_clear (&nb); - grub_netbuff_reserve (&nb,2048); - file->size = tftp_file.size; + /* Receive OACK. */ + grub_netbuff_clear (nb); + grub_netbuff_reserve (nb,2048); - return grub_net_recv_udp_packet (&addr, &nb, - TFTP_CLIENT_PORT, TFTP_SERVER_PORT); + do + { + err = grub_net_recv_udp_packet (&addr, nb, + TFTP_CLIENT_PORT, TFTP_SERVER_PORT); + if (err) + return err; + } + while (nb->tail == nb->data); + + file->size = 0; + + for (ptr = nb->data; ptr < nb->tail; ) + grub_printf ("%02x ", *ptr); + + for (ptr = nb->data; ptr < nb->tail; ) + { + if (grub_memcmp (ptr, "tsize\0=", sizeof ("tsize\0=") - 1) == 0) + { + file->size = grub_strtoul (ptr + sizeof ("tsize\0=") - 1, 0, 0); + grub_errno = GRUB_ERR_NONE; + } + while (ptr < nb->tail && *ptr) + ptr++; + ptr++; + } + return GRUB_ERR_NONE; } static grub_ssize_t tftp_receive (struct grub_file *file, char *buf, grub_size_t len) { struct tftphdr *tftph; - char *token,*value,*temp; + // char *token,*value,*temp; grub_err_t err; grub_net_network_level_address_t addr; struct grub_net_buff nb; @@ -143,38 +121,21 @@ tftp_receive (struct grub_file *file, char *buf, grub_size_t len) TFTP_CLIENT_PORT, TFTP_SERVER_PORT); tftph = (struct tftphdr *) nb.data; - switch (tftph->opcode) + switch (grub_be_to_cpu16 (tftph->opcode)) { - case TFTP_OACK: - /*process oack packet*/ - temp = (char *) tftph->u.oack.data; - while(get_tok_val(&token,&value,&temp,nb.tail)) - { - process_option(token,value); - } - - //buff_clean - grub_netbuff_clear(&nb); - // grub_printf("OACK---------------------------------------------------------\n"); - //grub_printf("block_size=%d\n",tftp_file.block_size); - // grub_printf("file_size=%d\n",tftp_file.size); - // grub_printf("OACK---------------------------------------------------------\n"); - block = 0; - break; case TFTP_DATA: grub_netbuff_pull (&nb,sizeof (tftph->opcode) + sizeof (tftph->u.data.block)); - if (tftph->u.data.block == block + 1) - { - block = tftph->u.data.block; + // if (tftph->u.data.block == block + 1) + //{ + // block = tftph->u.data.block; grub_memcpy (buf, nb.data, len); - } - else - grub_netbuff_clear(&nb); - break; + //} + //else + //grub_netbuff_clear(&nb); + break; case TFTP_ERROR: grub_netbuff_clear (&nb); - return grub_error (GRUB_ERR_ACCESS_DENIED, (char *)tftph->u.err.errmsg); - break; + return grub_error (GRUB_ERR_IO, (char *)tftph->u.err.errmsg); } nb.data = nb.tail = nb.end; @@ -182,8 +143,8 @@ tftp_receive (struct grub_file *file, char *buf, grub_size_t len) grub_netbuff_push (&nb,sizeof (tftph->opcode) + sizeof (tftph->u.ack.block)); tftph = (struct tftphdr *) nb.data; - tftph->opcode = TFTP_ACK; - tftph->u.ack.block = block; + tftph->opcode = grub_cpu_to_be16 (TFTP_ACK); + // tftph->u.ack.block = block; return grub_net_send_udp_packet (&addr, &nb, TFTP_CLIENT_PORT, TFTP_SERVER_PORT); } diff --git a/include/grub/net/arp.h b/include/grub/net/arp.h index 1475086e4..691fda307 100644 --- a/include/grub/net/arp.h +++ b/include/grub/net/arp.h @@ -3,13 +3,11 @@ #include #include -/* IANA ARP constant to define hardware type as ethernet */ -#define ARPHRD_ETHERNET 1 -/* IANA Ethertype */ -#define ARP_ETHERTYPE 0x806 - -/* Size for cache table */ -#define SIZE_ARP_TABLE 5 +enum +{ +/* IANA ARP constant to define hardware type as ethernet. */ + GRUB_NET_ARPHRD_ETHERNET = 1 +}; /* ARP header operation codes */ #define ARP_REQUEST 1 diff --git a/include/grub/net/ethernet.h b/include/grub/net/ethernet.h index b4f07992b..7a0235be6 100644 --- a/include/grub/net/ethernet.h +++ b/include/grub/net/ethernet.h @@ -38,6 +38,14 @@ struct snaphdr grub_uint16_t type; } __attribute__ ((packed)); +/* IANA Ethertype */ +enum +{ + GRUB_NET_ETHERTYPE_IP = 0x0800, + GRUB_NET_ETHERTYPE_ARP = 0x0806 +}; + + grub_err_t send_ethernet_packet (struct grub_net_network_level_interface *inf, struct grub_net_buff *nb, diff --git a/include/grub/net/ip.h b/include/grub/net/ip.h index 765d8005e..6f748bbf3 100644 --- a/include/grub/net/ip.h +++ b/include/grub/net/ip.h @@ -2,8 +2,6 @@ #define GRUB_NET_IP_HEADER 1 #include -#define IP_ETHERTYPE 0x800 /* IANA Ethertype */ - struct iphdr { grub_uint8_t verhdrlen; grub_uint8_t service; From c5dc16905aea5bce096c5a2061c236712b6e4686 Mon Sep 17 00:00:00 2001 From: Szymon Janc Date: Wed, 6 Oct 2010 19:57:01 +0200 Subject: [PATCH 056/869] Make enable of disk cache statistics code configurable. * configure.ac: --enable-cache-stats added. * config.h.in (DISK_CACHE_STATS): New define. * grub-core/Makefile.core.def (cacheinfo): New command. * include/grub/disk.h(grub_disk_cache_get_performance): New function. * grub-core/commands/cacheinfo.c: New file. * grub-core/commands/minicmd.c (grub_rescue_cmd_info): Updated and moved to cacheinfo.c. * grub-core/kern/disk.c: Use DISK_CACHE_STATS to disable disk cache debug code. * include/grub/disk.h: Likewise. --- ChangeLog | 15 +++++++++ config.h.in | 2 ++ configure.ac | 17 ++++++++++ grub-core/Makefile.core.def | 6 ++++ grub-core/commands/cacheinfo.c | 58 ++++++++++++++++++++++++++++++++++ grub-core/commands/minicmd.c | 20 ------------ grub-core/kern/disk.c | 6 ++-- include/grub/disk.h | 5 +++ 8 files changed, 106 insertions(+), 23 deletions(-) create mode 100644 grub-core/commands/cacheinfo.c diff --git a/ChangeLog b/ChangeLog index cc3c87445..6d54b6301 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +2010-10-05 Szymon Janc + + Make enable of disk cache statistics code configurable. + + * configure.ac: --enable-cache-stats added. + * config.h.in (DISK_CACHE_STATS): New define. + * grub-core/Makefile.core.def (cacheinfo): New command. + * include/grub/disk.h(grub_disk_cache_get_performance): New function. + * grub-core/commands/cacheinfo.c: New file. + * grub-core/commands/minicmd.c (grub_rescue_cmd_info): Updated and + moved to cacheinfo.c. + * grub-core/kern/disk.c: Use DISK_CACHE_STATS to disable disk cache + debug code. + * include/grub/disk.h: Likewise. + 2010-10-02 Aleš Nesrsta * include/grub/scsi.h: diff --git a/config.h.in b/config.h.in index 6d7d95dec..cfe6a94b2 100644 --- a/config.h.in +++ b/config.h.in @@ -32,6 +32,8 @@ #define NEED_ENABLE_EXECUTE_STACK @NEED_ENABLE_EXECUTE_STACK@ /* Define to 1 if GCC generates calls to __register_frame_info(). */ #define NEED_REGISTER_FRAME_INFO @NEED_REGISTER_FRAME_INFO@ +/* Define to 1 to enable disk cache statistics. */ +#define DISK_CACHE_STATS @DISK_CACHE_STATS@ #if defined(__i386__) #define NESTED_FUNC_ATTR __attribute__ ((__regparm__ (1))) diff --git a/configure.ac b/configure.ac index 66d4a6877..b3b5652d1 100644 --- a/configure.ac +++ b/configure.ac @@ -669,6 +669,17 @@ AC_ARG_ENABLE([mm-debug], [AC_DEFINE([MM_DEBUG], [1], [Define to 1 if you enable memory manager debugging.])]) +AC_ARG_ENABLE([cache-stats], + AS_HELP_STRING([--enable-cache-stats], + [enable disk cache statistics collection])]) + +if test x$enable_cache_stats = xyes; then + DISK_CACHE_STATS=1 +else + DISK_CACHE_STATS=0 +fi +AC_SUBST([DISK_CACHE_STATS]) + AC_ARG_ENABLE([grub-emu-usb], [AS_HELP_STRING([--enable-grub-emu-usb], [build and install the `grub-emu' debugging utility with USB support (default=guessed)])]) @@ -922,6 +933,7 @@ AM_CONDITIONAL([COND_HAVE_FONT_SOURCE], [test x$FONT_SOURCE != x]) AM_CONDITIONAL([COND_GRUB_PE2ELF], [test x$TARGET_OBJ2ELF != x]) AM_CONDITIONAL([COND_APPLE_CC], [test x$TARGET_APPLE_CC = x1]) AM_CONDITIONAL([COND_ENABLE_EFIEMU], [test x$enable_efiemu = xyes]) +AM_CONDITIONAL([COND_ENABLE_CACHE_STATS], [test x$DISK_CACHE_STATS = x1]) AM_CONDITIONAL([COND_HAVE_ASM_USCORE], [test x$HAVE_ASM_USCORE = x1]) @@ -983,6 +995,11 @@ echo With memory debugging: Yes else echo With memory debugging: No fi +if [ x"$enable_cache_stats" = xyes ]; then +echo With disk cache statistics: Yes +else +echo With disk cache statistics: No +fi if [ x"$efiemu_excuse" = x ]; then echo efiemu runtime: Yes else diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def index 8845c26ea..51ae522a6 100644 --- a/grub-core/Makefile.core.def +++ b/grub-core/Makefile.core.def @@ -1502,3 +1502,9 @@ module = { common = commands/keylayouts.c; enable = videomodules; }; + +module = { + name = cacheinfo; + common = commands/cacheinfo.c; + condition = COND_ENABLE_CACHE_STATS; +}; diff --git a/grub-core/commands/cacheinfo.c b/grub-core/commands/cacheinfo.c new file mode 100644 index 000000000..771763c9c --- /dev/null +++ b/grub-core/commands/cacheinfo.c @@ -0,0 +1,58 @@ +/* cacheinfo.c - disk cache statistics */ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2008,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 . + */ + +#include +#include +#include +#include +#include + +static grub_err_t +grub_rescue_cmd_info (struct grub_command *cmd __attribute__ ((unused)), + int argc __attribute__ ((unused)), + char *argv[] __attribute__ ((unused))) +{ + unsigned long hits, misses; + + grub_disk_cache_get_performance (&hits, &misses); + grub_printf ("Disk cache: hits = %lu, misses = %lu ", hits, misses); + if (hits + misses) + { + unsigned long ratio = hits * 10000 / (hits + misses); + grub_printf ("(%lu.%lu%%)\n", ratio / 100, ratio % 100); + } + else + grub_printf ("(N/A)\n"); + + return 0; +} + +static grub_command_t cmd_cacheinfo; + +GRUB_MOD_INIT(cacheinfo) +{ + cmd_cacheinfo = + grub_register_command ("cacheinfo", grub_rescue_cmd_info, + 0, N_("Get disk cache info.")); +} + +GRUB_MOD_FINI(cacheinfo) +{ + grub_unregister_command (cmd_cacheinfo); +} diff --git a/grub-core/commands/minicmd.c b/grub-core/commands/minicmd.c index 5cf109fde..5c90e8ac5 100644 --- a/grub-core/commands/minicmd.c +++ b/grub-core/commands/minicmd.c @@ -88,26 +88,6 @@ grub_mini_cmd_help (struct grub_command *cmd __attribute__ ((unused)), return 0; } -#if 0 -static void -grub_rescue_cmd_info (void) -{ - extern void grub_disk_cache_get_performance (unsigned long *, - unsigned long *); - unsigned long hits, misses; - - grub_disk_cache_get_performance (&hits, &misses); - grub_printf ("Disk cache: hits = %u, misses = %u ", hits, misses); - if (hits + misses) - { - unsigned long ratio = hits * 10000 / (hits + misses); - grub_printf ("(%u.%u%%)\n", ratio / 100, ratio % 100); - } - else - grub_printf ("(N/A)\n"); -} -#endif - /* dump ADDRESS [SIZE] */ static grub_err_t grub_mini_cmd_dump (struct grub_command *cmd __attribute__ ((unused)), diff --git a/grub-core/kern/disk.c b/grub-core/kern/disk.c index 807ee4277..2d50ea60c 100644 --- a/grub-core/kern/disk.c +++ b/grub-core/kern/disk.c @@ -50,7 +50,7 @@ grub_err_t (* grub_disk_ata_pass_through) (grub_disk_t, struct grub_disk_ata_pass_through_parms *); -#if 0 +#if DISK_CACHE_STATS static unsigned long grub_disk_cache_hits; static unsigned long grub_disk_cache_misses; @@ -123,13 +123,13 @@ grub_disk_cache_fetch (unsigned long dev_id, unsigned long disk_id, && cache->sector == sector) { cache->lock = 1; -#if 0 +#if DISK_CACHE_STATS grub_disk_cache_hits++; #endif return cache->data; } -#if 0 +#if DISK_CACHE_STATS grub_disk_cache_misses++; #endif diff --git a/include/grub/disk.h b/include/grub/disk.h index 9c5653e00..783640d19 100644 --- a/include/grub/disk.h +++ b/include/grub/disk.h @@ -160,6 +160,11 @@ grub_err_t EXPORT_FUNC(grub_disk_write) (grub_disk_t disk, grub_uint64_t EXPORT_FUNC(grub_disk_get_size) (grub_disk_t disk); +#if DISK_CACHE_STATS +void +EXPORT_FUNC(grub_disk_cache_get_performance) (unsigned long *hits, unsigned long *misses); +#endif + extern void (* EXPORT_VAR(grub_disk_firmware_fini)) (void); extern int EXPORT_VAR(grub_disk_firmware_is_tainted); From 5d49b1e69c82de6a07195dc39e7e601feeedd44d Mon Sep 17 00:00:00 2001 From: Szymon Janc Date: Wed, 6 Oct 2010 22:09:07 +0200 Subject: [PATCH 057/869] Move last changelog entry from ChangeLog to ChangeLog.cacheinfo. --- ChangeLog | 15 --------------- ChangeLog.cacheinfo | 14 ++++++++++++++ 2 files changed, 14 insertions(+), 15 deletions(-) create mode 100644 ChangeLog.cacheinfo diff --git a/ChangeLog b/ChangeLog index 6d54b6301..cc3c87445 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,18 +1,3 @@ -2010-10-05 Szymon Janc - - Make enable of disk cache statistics code configurable. - - * configure.ac: --enable-cache-stats added. - * config.h.in (DISK_CACHE_STATS): New define. - * grub-core/Makefile.core.def (cacheinfo): New command. - * include/grub/disk.h(grub_disk_cache_get_performance): New function. - * grub-core/commands/cacheinfo.c: New file. - * grub-core/commands/minicmd.c (grub_rescue_cmd_info): Updated and - moved to cacheinfo.c. - * grub-core/kern/disk.c: Use DISK_CACHE_STATS to disable disk cache - debug code. - * include/grub/disk.h: Likewise. - 2010-10-02 Aleš Nesrsta * include/grub/scsi.h: diff --git a/ChangeLog.cacheinfo b/ChangeLog.cacheinfo new file mode 100644 index 000000000..a26271cca --- /dev/null +++ b/ChangeLog.cacheinfo @@ -0,0 +1,14 @@ +2010-10-05 Szymon Janc + + Make enable of disk cache statistics code configurable. + + * configure.ac: --enable-cache-stats added. + * config.h.in (DISK_CACHE_STATS): New define. + * grub-core/Makefile.core.def (cacheinfo): New command. + * include/grub/disk.h(grub_disk_cache_get_performance): New function. + * grub-core/commands/cacheinfo.c: New file. + * grub-core/commands/minicmd.c (grub_rescue_cmd_info): Updated and + moved to cacheinfo.c. + * grub-core/kern/disk.c: Use DISK_CACHE_STATS to disable disk cache + debug code. + * include/grub/disk.h: Likewise. From c0e103e4dacffd9d9348cc753eaf89405564df98 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 8 Nov 2010 16:51:50 +0100 Subject: [PATCH 058/869] Support for partitioned loop devices. Improved devmapper support --- grub-core/kern/emu/getroot.c | 88 +++++++++++++++++++++++++---------- grub-core/kern/emu/hostdisk.c | 71 +++++++++++++++++++++++++++- 2 files changed, 133 insertions(+), 26 deletions(-) diff --git a/grub-core/kern/emu/getroot.c b/grub-core/kern/emu/getroot.c index 0433d49ed..a99bee9a4 100644 --- a/grub-core/kern/emu/getroot.c +++ b/grub-core/kern/emu/getroot.c @@ -32,6 +32,10 @@ #include #include +#ifdef HAVE_DEVICE_MAPPER +# include +#endif + #ifdef __GNU__ #include #include @@ -560,30 +564,66 @@ grub_guess_root_device (const char *dir) } static int -grub_util_is_dmraid (const char *os_dev) +grub_util_is_lvm (const char *os_dev) { - if (! strncmp (os_dev, "/dev/mapper/nvidia_", 19)) - return 1; - else if (! strncmp (os_dev, "/dev/mapper/isw_", 16)) - return 1; - else if (! strncmp (os_dev, "/dev/mapper/hpt37x_", 19)) - return 1; - else if (! strncmp (os_dev, "/dev/mapper/hpt45x_", 19)) - return 1; - else if (! strncmp (os_dev, "/dev/mapper/via_", 16)) - return 1; - else if (! strncmp (os_dev, "/dev/mapper/lsi_", 16)) - return 1; - else if (! strncmp (os_dev, "/dev/mapper/pdc_", 16)) - return 1; - else if (! strncmp (os_dev, "/dev/mapper/jmicron_", 20)) - return 1; - else if (! strncmp (os_dev, "/dev/mapper/asr_", 16)) - return 1; - else if (! strncmp (os_dev, "/dev/mapper/sil_", 16)) - return 1; + if ((strncmp ("/dev/mapper/", os_dev, 12) != 0)) + return 0; + +#ifdef HAVE_DEVICE_MAPPER + { + struct dm_tree *tree; + uint32_t maj, min; + struct dm_tree_node *node = NULL, *child; + void *handle; + const char *node_uuid, *mapper_name = NULL, *child_uuid, *child_name; + struct stat st; - return 0; + if (stat (os_dev, &st) < 0) + return 0; + + tree = dm_tree_create (); + if (! tree) + { + grub_printf ("Failed to create tree\n"); + grub_dprintf ("hostdisk", "dm_tree_create failed\n"); + return 0; + } + + maj = major (st.st_rdev); + min = minor (st.st_rdev); + + if (! dm_tree_add_dev (tree, maj, min)) + { + grub_dprintf ("hostdisk", "dm_tree_add_dev failed\n"); + dm_tree_free (tree); + return 0; + } + + node = dm_tree_find_node (tree, maj, min); + if (! node) + { + grub_dprintf ("hostdisk", "dm_tree_find_node failed\n"); + dm_tree_free (tree); + return 0; + } + node_uuid = dm_tree_node_get_uuid (node); + if (! node_uuid) + { + grub_dprintf ("hostdisk", "%s has no DM uuid\n", os_dev); + dm_tree_free (tree); + return 0; + } + if (strncmp (node_uuid, "LVM-", 4) != 0) + { + dm_tree_free (tree); + return 0; + } + dm_tree_free (tree); + return 1; + } +#else + return 1; +#endif /* HAVE_DEVICE_MAPPER */ } int @@ -595,9 +635,7 @@ grub_util_get_dev_abstraction (const char *os_dev __attribute__((unused))) return GRUB_DEV_ABSTRACTION_NONE; /* Check for LVM. */ - if (!strncmp (os_dev, "/dev/mapper/", 12) - && ! grub_util_is_dmraid (os_dev) - && strncmp (os_dev, "/dev/mapper/mpath", 17) != 0) + if (grub_util_is_lvm (os_dev)) return GRUB_DEV_ABSTRACTION_LVM; /* Check for RAID. */ diff --git a/grub-core/kern/emu/hostdisk.c b/grub-core/kern/emu/hostdisk.c index 12dbe7469..2a798a3cd 100644 --- a/grub-core/kern/emu/hostdisk.c +++ b/grub-core/kern/emu/hostdisk.c @@ -1035,6 +1035,55 @@ make_device_name (int drive, int dos_part, int bsd_part) return ret; } +#ifdef HAVE_DEVICE_MAPPER +static int +grub_util_get_dm_node_linear_info (const char *dev, + int *maj, int *min) +{ + struct dm_task *dmt; + void *next = NULL; + uint64_t length, start; + char *target, *params; + const char *node_name; + char *ptr; + int major, minor; + + dmt = dm_task_create(DM_DEVICE_TABLE); + if (!dmt) + return 0; + + if (!dm_task_set_name(dmt, dev)) + return 0; + dm_task_no_open_count(dmt); + if (!dm_task_run(dmt)) + return 0; + next = dm_get_next_target(dmt, next, &start, &length, + &target, ¶ms); + if (grub_strcmp (target, "linear") != 0) + return 0; + major = grub_strtoul (params, &ptr, 10); + if (grub_errno) + { + grub_errno = GRUB_ERR_NONE; + return 0; + } + if (*ptr != ':') + return 0; + ptr++; + minor = grub_strtoul (ptr, 0, 10); + if (grub_errno) + { + grub_errno = GRUB_ERR_NONE; + return 0; + } + if (maj) + *maj = major; + if (min) + *min = minor; + return 1; +} +#endif + static char * convert_system_partition_to_system_disk (const char *os_dev, struct stat *st) { @@ -1211,9 +1260,29 @@ convert_system_partition_to_system_disk (const char *os_dev, struct stat *st) node = NULL; goto devmapper_out; } - else if (strncmp (node_uuid, "DMRAID-", 7) != 0) + if (strncmp (node_uuid, "LVM-", 4) == 0) { + grub_dprintf ("hostdisk", "%s is an LVM\n", path); + node = NULL; + goto devmapper_out; + } + if (strncmp (node_uuid, "DMRAID-", 7) != 0) + { + int major, minor; + const char *node_name; grub_dprintf ("hostdisk", "%s is not DM-RAID\n", path); + + if ((node_name = dm_tree_node_get_name (node)) + && grub_util_get_dm_node_linear_info (node_name, + &major, &minor)) + { + if (tree) + dm_tree_free (tree); + free (path); + char *ret = grub_find_device (NULL, (major << 8) | minor); + return ret; + } + node = NULL; goto devmapper_out; } From a06eb03ad020dd530f635e2936ea29270e222c47 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 13 Nov 2010 21:27:08 +0100 Subject: [PATCH 059/869] Support long command lines as per 2.06 Linux boot protocol --- grub-core/loader/i386/linux.c | 19 ++++++++++++++----- grub-core/loader/i386/pc/linux.c | 25 +++++++++++++++++-------- include/grub/i386/linux.h | 5 ++++- 3 files changed, 35 insertions(+), 14 deletions(-) diff --git a/grub-core/loader/i386/linux.c b/grub-core/loader/i386/linux.c index de4bec106..bdf66c6f6 100644 --- a/grub-core/loader/i386/linux.c +++ b/grub-core/loader/i386/linux.c @@ -54,7 +54,6 @@ #endif #define GRUB_LINUX_CL_OFFSET 0x1000 -#define GRUB_LINUX_CL_END_OFFSET 0x2000 static grub_dl_t my_mod; @@ -71,6 +70,7 @@ static grub_uint32_t prot_mode_pages; static grub_uint32_t initrd_pages; static struct grub_relocator *relocator = NULL; static void *efi_mmap_buf; +static grub_size_t maximal_cmdline_size; #ifdef GRUB_MACHINE_EFI static grub_efi_uintn_t efi_mmap_size; #else @@ -185,7 +185,7 @@ allocate_pages (grub_size_t prot_size) grub_err_t err; /* Make sure that each size is aligned to a page boundary. */ - real_size = GRUB_LINUX_CL_END_OFFSET; + real_size = GRUB_LINUX_CL_OFFSET + maximal_cmdline_size; prot_size = page_align (prot_size); mmap_size = find_mmap_size (); @@ -630,6 +630,14 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), goto fail; } + if (grub_le_to_cpu16 (lh.version) >= 0x0206) + maximal_cmdline_size = grub_le_to_cpu32 (lh.cmdline_size) + 1; + else + maximal_cmdline_size = 256; + + if (maximal_cmdline_size < 128) + maximal_cmdline_size = 128; + setup_sects = lh.setup_sects; /* If SETUP_SECTS is not set, set it to the default (4). */ @@ -643,7 +651,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), goto fail; params = (struct linux_kernel_params *) real_mode_mem; - grub_memset (params, 0, GRUB_LINUX_CL_END_OFFSET); + grub_memset (params, 0, GRUB_LINUX_CL_OFFSET + maximal_cmdline_size); grub_memcpy (¶ms->setup_sects, &lh.setup_sects, sizeof (lh) - 0x1F1); params->ps_mouse = params->padding10 = 0; @@ -845,8 +853,9 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), /* Copy kernel parameters. */ for (i = 1; i < argc - && dest + grub_strlen (argv[i]) + 1 < ((char *) real_mode_mem - + GRUB_LINUX_CL_END_OFFSET); + && dest + grub_strlen (argv[i]) + 2 < ((char *) real_mode_mem + + GRUB_LINUX_CL_OFFSET + + maximal_cmdline_size); i++) { *dest++ = ' '; diff --git a/grub-core/loader/i386/pc/linux.c b/grub-core/loader/i386/pc/linux.c index 90de70f66..44da0ad90 100644 --- a/grub-core/loader/i386/pc/linux.c +++ b/grub-core/loader/i386/pc/linux.c @@ -36,7 +36,6 @@ #include #define GRUB_LINUX_CL_OFFSET 0x9000 -#define GRUB_LINUX_CL_END_OFFSET 0x90FF static grub_dl_t my_mod; @@ -46,6 +45,7 @@ static struct grub_relocator *relocator = NULL; static grub_addr_t grub_linux_real_target; static char *grub_linux_real_chunk; static grub_size_t grub_linux16_prot_size; +static grub_size_t maximal_cmdline_size; static grub_err_t grub_linux16_boot (void) @@ -126,15 +126,20 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), setup_sects = lh.setup_sects; linux_mem_size = 0; + maximal_cmdline_size = 256; + if (lh.header == grub_cpu_to_le32 (GRUB_LINUX_MAGIC_SIGNATURE) && grub_le_to_cpu16 (lh.version) >= 0x0200) { grub_linux_is_bzimage = (lh.loadflags & GRUB_LINUX_FLAG_BIG_KERNEL); lh.type_of_loader = GRUB_LINUX_BOOT_LOADER_TYPE; + if (grub_le_to_cpu16 (lh.version) >= 0x0206) + maximal_cmdline_size = grub_le_to_cpu32 (lh.cmdline_size) + 1; + /* Put the real mode part at as a high location as possible. */ grub_linux_real_target = grub_mmap_get_lower () - - GRUB_LINUX_SETUP_MOVE_SIZE; + - (GRUB_LINUX_CL_OFFSET + maximal_cmdline_size); /* But it must not exceed the traditional area. */ if (grub_linux_real_target > GRUB_LINUX_OLD_REAL_MODE_ADDR) grub_linux_real_target = GRUB_LINUX_OLD_REAL_MODE_ADDR; @@ -151,7 +156,8 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), { lh.cl_magic = grub_cpu_to_le16 (GRUB_LINUX_CL_MAGIC); lh.cl_offset = grub_cpu_to_le16 (GRUB_LINUX_CL_OFFSET); - lh.setup_move_size = grub_cpu_to_le16 (GRUB_LINUX_SETUP_MOVE_SIZE); + lh.setup_move_size = grub_cpu_to_le16 (GRUB_LINUX_CL_OFFSET + + maximal_cmdline_size); } } else @@ -183,12 +189,13 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), goto fail; } - if (grub_linux_real_target + GRUB_LINUX_SETUP_MOVE_SIZE + if (grub_linux_real_target + GRUB_LINUX_CL_OFFSET + maximal_cmdline_size > grub_mmap_get_lower ()) { grub_error (GRUB_ERR_OUT_OF_RANGE, "too small lower memory (0x%x > 0x%x)", - grub_linux_real_target + GRUB_LINUX_SETUP_MOVE_SIZE, + grub_linux_real_target + GRUB_LINUX_CL_OFFSET + + maximal_cmdline_size, (int) grub_mmap_get_lower ()); goto fail; } @@ -261,7 +268,8 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), grub_relocator_chunk_t ch; err = grub_relocator_alloc_chunk_addr (relocator, &ch, grub_linux_real_target, - GRUB_LINUX_SETUP_MOVE_SIZE); + GRUB_LINUX_CL_OFFSET + + maximal_cmdline_size); if (err) return err; grub_linux_real_chunk = get_virtual_current_address (ch); @@ -294,8 +302,9 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), /* Copy kernel parameters. */ for (i = 1; i < argc - && dest + grub_strlen (argv[i]) + 1 < (grub_linux_real_chunk - + GRUB_LINUX_CL_END_OFFSET); + && dest + grub_strlen (argv[i]) + 2 < (grub_linux_real_chunk + + GRUB_LINUX_CL_OFFSET + + maximal_cmdline_size); i++) { *dest++ = ' '; diff --git a/include/grub/i386/linux.h b/include/grub/i386/linux.h index 63f99db62..ad59b3452 100644 --- a/include/grub/i386/linux.h +++ b/include/grub/i386/linux.h @@ -41,7 +41,6 @@ #define GRUB_LINUX_VID_MODE_ASK 0xFFFD #define GRUB_LINUX_VID_MODE_VESA_START 0x0300 -#define GRUB_LINUX_SETUP_MOVE_SIZE 0x9100 #define GRUB_LINUX_CL_MAGIC 0xA33F #ifdef __x86_64__ @@ -126,6 +125,10 @@ struct linux_kernel_header grub_uint16_t pad1; /* Unused */ grub_uint32_t cmd_line_ptr; /* Points to the kernel command line */ grub_uint32_t initrd_addr_max; /* Highest address for initrd */ + grub_uint32_t kernel_alignment; + grub_uint8_t relocatable; + grub_uint8_t pad[3]; + grub_uint32_t cmdline_size; } __attribute__ ((packed)); /* Boot parameters for Linux based on 2.6.12. This is used by the setup From c53c723762cc4a544346b230eadddd15161b1e26 Mon Sep 17 00:00:00 2001 From: BVK Chaitanya Date: Fri, 3 Dec 2010 08:55:57 +0530 Subject: [PATCH 060/869] print line number on error --- util/grub-script-check.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/util/grub-script-check.c b/util/grub-script-check.c index a872a0400..2d1b31c9a 100644 --- a/util/grub-script-check.c +++ b/util/grub-script-check.c @@ -73,6 +73,7 @@ main (int argc, char *argv[]) { char *argument; char *input; + int lineno = 0; FILE *file = 0; int verbose = 0; int found_input = 0; @@ -111,6 +112,7 @@ main (int argc, char *argv[]) cmdline[i] = '\0'; } + lineno++; *line = grub_strdup (cmdline); free (cmdline); @@ -189,5 +191,11 @@ main (int argc, char *argv[]) if (file) fclose (file); - return (found_input && script == 0); + if (found_input && script == 0) + { + fprintf (stderr, "error: line no: %u\n", lineno); + return 1; + } + + return 0; } From 24b7938b32e755f25302962895cb81093550533c Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Sat, 4 Dec 2010 16:19:26 +0000 Subject: [PATCH 061/869] * grub-core/kern/i386/pc/startup.S (grub_console_getkey): Use `>> 1' rather than `/ 2', as the latter requires -Wa,--divide which would require bumping our minimum binutils version. --- ChangeLog | 6 ++++++ grub-core/kern/i386/pc/startup.S | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 995799775..0c6e842de 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2010-12-04 Colin Watson + + * grub-core/kern/i386/pc/startup.S (grub_console_getkey): Use `>> 1' + rather than `/ 2', as the latter requires -Wa,--divide which would + require bumping our minimum binutils version. + 2010-12-03 BVK Chaitanya * util/grub-script-check.c (main): Print script line number on diff --git a/grub-core/kern/i386/pc/startup.S b/grub-core/kern/i386/pc/startup.S index d089a3e15..7aebc8b38 100644 --- a/grub-core/kern/i386/pc/startup.S +++ b/grub-core/kern/i386/pc/startup.S @@ -650,7 +650,7 @@ FUNCTION(grub_console_getkey) jae 2f movl %edx, %eax leal LOCAL(bypass_table), %edi - movl $((LOCAL(bypass_table_end) - LOCAL(bypass_table)) / 2), %ecx + movl $((LOCAL(bypass_table_end) - LOCAL(bypass_table)) >> 1), %ecx repne scasw jz 3f From 79282228ec14e6509d1c6df5eb0ec9a7ee67a3f7 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 6 Dec 2010 20:26:49 +0100 Subject: [PATCH 062/869] use anopther RAID1(0) copy if main one fails --- grub-core/fs/btrfs.c | 86 +++++++++++++++++++++++++++++--------------- 1 file changed, 58 insertions(+), 28 deletions(-) diff --git a/grub-core/fs/btrfs.c b/grub-core/fs/btrfs.c index 7e31fa3f1..b7edb7e39 100644 --- a/grub-core/fs/btrfs.c +++ b/grub-core/fs/btrfs.c @@ -491,7 +491,8 @@ lower_bound (struct grub_btrfs_data *data, } static grub_device_t -find_device (struct grub_btrfs_data *data, grub_uint64_t id) +find_device (struct grub_btrfs_data *data, grub_uint64_t id, + int do_rescan) { grub_device_t dev_found = NULL; auto int hook (const char *name); @@ -537,7 +538,8 @@ find_device (struct grub_btrfs_data *data, grub_uint64_t id) for (i = 0; i < data->n_devices_attached; i++) if (id == data->devices_attached[i].id) return data->devices_attached[i].dev; - grub_device_iterate (hook); + if (do_rescan) + grub_device_iterate (hook); if (!dev_found) { grub_error (GRUB_ERR_BAD_FS, "couldn't find a member device"); @@ -574,7 +576,6 @@ grub_btrfs_read_logical (struct grub_btrfs_data *data, grub_uint8_t *ptr; struct grub_btrfs_key *key; struct grub_btrfs_chunk_item *chunk; - struct grub_btrfs_chunk_stripe *stripe; grub_ssize_t csize; grub_err_t err; struct grub_btrfs_key key_out; @@ -598,7 +599,8 @@ grub_btrfs_read_logical (struct grub_btrfs_data *data, + grub_le_to_cpu64 (chunk->size)) goto chunk_found; ptr += sizeof (*key) + sizeof (*chunk) - + sizeof (*stripe) * grub_le_to_cpu16 (chunk->nstripes); + + sizeof (struct grub_btrfs_chunk_stripe) + * grub_le_to_cpu16 (chunk->nstripes); } struct grub_btrfs_key key_in; grub_size_t chsize; @@ -634,9 +636,9 @@ grub_btrfs_read_logical (struct grub_btrfs_data *data, grub_uint32_t stripen; grub_uint32_t stripe_offset; grub_uint64_t off = addr - grub_le_to_cpu64 (key->offset); - grub_disk_addr_t paddr; + unsigned redundancy = 1; + unsigned i, j; - stripe = (struct grub_btrfs_chunk_stripe *) (chunk + 1); switch (grub_le_to_cpu64 (chunk->type) & ~GRUB_BTRFS_CHUNK_TYPE_BITS_DONTCARE) { @@ -661,6 +663,7 @@ grub_btrfs_read_logical (struct grub_btrfs_data *data, stripen = 0; stripe_offset = off; csize = stripe_length - off; + redundancy = 2; break; } case GRUB_BTRFS_CHUNK_TYPE_RAID0: @@ -692,6 +695,8 @@ grub_btrfs_read_logical (struct grub_btrfs_data *data, &stripen); stripen *= grub_le_to_cpu16 (chunk->nstripes) / grub_le_to_cpu16 (chunk->nsubstripes); + redundancy = grub_le_to_cpu16 (chunk->nstripes) + / grub_le_to_cpu16 (chunk->nsubstripes); stripe_offset = low + grub_le_to_cpu64 (chunk->stripe_length) * high; csize = grub_le_to_cpu64 (chunk->stripe_length) - low; @@ -702,35 +707,60 @@ grub_btrfs_read_logical (struct grub_btrfs_data *data, "unsupported RAID flags %" PRIxGRUB_UINT64_T, grub_le_to_cpu64 (chunk->type)); } - stripe += stripen; if (csize <= 0) return grub_error (GRUB_ERR_BAD_FS, "couldn't find the chunk descriptor"); if ((grub_size_t) csize > size) csize = size; - dev = find_device (data, stripe->device_id); - if (!dev) - return grub_errno; - grub_dprintf ("btrfs", "chunk 0x%" PRIxGRUB_UINT64_T - "+0x%" PRIxGRUB_UINT64_T " (%d stripes (%d substripes) of %" - PRIxGRUB_UINT64_T ") stripe %" PRIxGRUB_UINT32_T - " maps to 0x%" PRIxGRUB_UINT64_T "\n", - grub_le_to_cpu64 (key->offset), - grub_le_to_cpu64 (chunk->size), - grub_le_to_cpu16 (chunk->nstripes), - grub_le_to_cpu16 (chunk->nsubstripes), - grub_le_to_cpu64 (chunk->stripe_length), - stripen, - stripe->offset); - paddr = stripe->offset + stripe_offset; - grub_dprintf ("btrfs", "reading paddr 0x%" PRIxGRUB_UINT64_T - " for laddr 0x%" PRIxGRUB_UINT64_T"\n", paddr, - addr); - err = grub_disk_read (dev->disk, paddr >> GRUB_DISK_SECTOR_BITS, - paddr & (GRUB_DISK_SECTOR_SIZE - 1), csize, buf); + for (j = 0; j < 2; j++) + { + for (i = 0; i < redundancy; i++) + { + struct grub_btrfs_chunk_stripe *stripe; + grub_disk_addr_t paddr; + + stripe = (struct grub_btrfs_chunk_stripe *) (chunk + 1); + /* Right now the redundancy handlind is easy. + With RAID5-like it will be more difficult. */ + stripe += stripen + i; + + paddr = stripe->offset + stripe_offset; + + grub_dprintf ("btrfs", "chunk 0x%" PRIxGRUB_UINT64_T + "+0x%" PRIxGRUB_UINT64_T " (%d stripes (%d substripes) of %" + PRIxGRUB_UINT64_T ") stripe %" PRIxGRUB_UINT32_T + " maps to 0x%" PRIxGRUB_UINT64_T "\n", + grub_le_to_cpu64 (key->offset), + grub_le_to_cpu64 (chunk->size), + grub_le_to_cpu16 (chunk->nstripes), + grub_le_to_cpu16 (chunk->nsubstripes), + grub_le_to_cpu64 (chunk->stripe_length), + stripen, stripe->offset); + grub_dprintf ("btrfs", "reading paddr 0x%" PRIxGRUB_UINT64_T + " for laddr 0x%" PRIxGRUB_UINT64_T"\n", paddr, + addr); + + dev = find_device (data, stripe->device_id, j); + if (!dev) + { + err = grub_errno; + grub_errno = GRUB_ERR_NONE; + continue; + } + + err = grub_disk_read (dev->disk, paddr >> GRUB_DISK_SECTOR_BITS, + paddr & (GRUB_DISK_SECTOR_SIZE - 1), + csize, buf); + if (!err) + break; + grub_errno = GRUB_ERR_NONE; + } + if (i != redundancy) + break; + } if (err) - return err; + return grub_errno = err; } size -= csize; buf = (grub_uint8_t *) buf + csize; From 393324be7c27ee65c3f07de5b5e56f001b8a9ed3 Mon Sep 17 00:00:00 2001 From: BVK Chaitanya Date: Wed, 8 Dec 2010 16:43:11 +0530 Subject: [PATCH 063/869] execute menu editor commands with argument scope --- grub-core/normal/menu_entry.c | 59 +++++++++++++++++------------------ 1 file changed, 28 insertions(+), 31 deletions(-) diff --git a/grub-core/normal/menu_entry.c b/grub-core/normal/menu_entry.c index 0bb51ca28..4db4a45c1 100644 --- a/grub-core/normal/menu_entry.c +++ b/grub-core/normal/menu_entry.c @@ -1163,37 +1163,35 @@ clear_completions_all (struct screen *screen) static int run (struct screen *screen) { - int currline = 0; - char *nextline; + char *script; int errs_before; grub_menu_t menu; + char *dummy[1] = { NULL }; - auto grub_err_t editor_getline (char **line, int cont); - grub_err_t editor_getline (char **line, int cont __attribute__ ((unused))) - { - struct line *linep = screen->lines + currline; - char *p; + auto char * editor_getsource (void); + char * editor_getsource (void) + { + int i; + int size = 0; + char *source; - if (currline > screen->num_lines) - { - *line = 0; - return 0; - } + for (i = 0; i < screen->num_lines; i++) + size += screen->lines[i].len + 1; - /* Trim down space characters. */ - for (p = linep->buf + linep->len - 1; - p >= linep->buf && grub_isspace (*p); - p--) - ; - *++p = '\0'; + source = grub_malloc (size + 1); + if (! source) + return NULL; - linep->len = p - linep->buf; - for (p = linep->buf; grub_isspace (*p); p++) - ; - *line = grub_strdup (p); - currline++; - return 0; - } + size = 0; + for (i = 0; i < screen->num_lines; i++) + { + grub_strcpy (source + size, screen->lines[i].buf); + size += screen->lines[i].len; + source[size++] = '\n'; + } + source[size] = '\0'; + return source; + } grub_cls (); grub_printf (" "); @@ -1212,12 +1210,11 @@ run (struct screen *screen) } /* Execute the script, line for line. */ - while (currline < screen->num_lines) - { - editor_getline (&nextline, 0); - if (grub_normal_parse_line (nextline, editor_getline)) - break; - } + script = editor_getsource (); + if (! script) + return 0; + grub_script_execute_sourcecode (script, 0, dummy); + grub_free (script); if (errs_before != grub_err_printed_errors) grub_wait_after_message (); From 332fa368872a57f945a7387cc1b931e83f197cb0 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 8 Dec 2010 21:22:46 +0100 Subject: [PATCH 064/869] some squash4 code. Works only in very easy cases. --- Makefile.util.def | 1 + grub-core/Makefile.core.def | 5 + grub-core/fs/squash4.c | 384 ++++++++++++++++++++++++++++++++++++ 3 files changed, 390 insertions(+) create mode 100644 grub-core/fs/squash4.c diff --git a/Makefile.util.def b/Makefile.util.def index f3cd1d234..8eec8d0f7 100644 --- a/Makefile.util.def +++ b/Makefile.util.def @@ -65,6 +65,7 @@ library = { common = grub-core/fs/ntfscomp.c; common = grub-core/fs/reiserfs.c; common = grub-core/fs/sfs.c; + common = grub-core/fs/squash4.c; common = grub-core/fs/tar.c; common = grub-core/fs/udf.c; common = grub-core/fs/ufs2.c; diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def index c62d7d12f..583218372 100644 --- a/grub-core/Makefile.core.def +++ b/grub-core/Makefile.core.def @@ -983,6 +983,11 @@ module = { common = fs/sfs.c; }; +module = { + name = squash4; + common = fs/squash4.c; +}; + module = { name = tar; common = fs/tar.c; diff --git a/grub-core/fs/squash4.c b/grub-core/fs/squash4.c new file mode 100644 index 000000000..889f8b94c --- /dev/null +++ b/grub-core/fs/squash4.c @@ -0,0 +1,384 @@ +/* squash4.c - SquashFS */ +/* + * 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 . + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* + object format Pointed by + superblock RAW Fixed offset (0) + data RAW ? Fixed offset (60) + inode table Chunk superblock + dir table Chunk superblock + unk3 Chunk unk1 + unk1 RAW, Chunk superblock + unk2 RAW superblock + UID/GID Chunk exttblptr + exttblptr RAW superblock + + UID/GID table is the array ot uint32_t + unk1 contains pointer to unk3 followed by some chunk. + unk2 containts one uint64_t +*/ + +struct grub_squash_super +{ + grub_uint32_t magic; +#define SQUASH_MAGIC 0x73717368 + grub_uint32_t dummy1; + grub_uint32_t creation_time; + grub_uint32_t dummy2; + grub_uint32_t dummy3[4]; + grub_uint32_t dummy4[2]; + grub_uint64_t total_size; + grub_uint64_t exttbloffset; + grub_uint32_t dummy5[2]; + grub_uint64_t inodeoffset; + grub_uint64_t diroffset; + grub_uint64_t unk1offset; + grub_uint64_t unk2offset; +}; + + +/* Chunk-based */ +struct grub_squash_inode +{ + /* Same values as direlem types. */ + grub_uint16_t type; + grub_uint16_t dummy1[3]; + grub_uint32_t mtime; + grub_uint16_t dummy2[6]; + grub_uint32_t offset; + grub_uint16_t size; + grub_uint16_t dummy3; +} __attribute__ ((packed)); + +/* Chunk-based. */ +struct grub_squash_dirent_header +{ + /* Actually the value is the number of elements - 1. */ + grub_uint16_t nelems; + grub_uint16_t dummy[5]; +}; + +struct grub_squash_dirent +{ + grub_uint16_t ino; + grub_uint16_t dummy; + grub_uint16_t type; +#define SQUASH_TYPE_DIR 1 +#define SQUASH_TYPE_REGULAR 2 + /* Actually the value is the length of name - 1. */ + grub_uint16_t namelen; + char name[0]; +}; + +#define SQUASH_CHUNK_SIZE 0x2000 +#define SQUASH_CHUNK_FLAGS 0x8000 +#define SQUASH_CHUNK_UNCOMPRESSED 0x8000 + +static grub_err_t +read_chunk (grub_disk_t disk, void *buf, grub_size_t len, + grub_uint64_t chunk_start, grub_uint64_t offset) +{ + while (len > 0) + { + grub_uint64_t csize; + grub_uint16_t d; + grub_err_t err; + while (1) + { + err = grub_disk_read (disk, chunk_start >> GRUB_DISK_SECTOR_BITS, + chunk_start & (GRUB_DISK_SECTOR_SIZE - 1), + sizeof (d), &d); + if (err) + return err; + if (offset < SQUASH_CHUNK_SIZE) + break; + offset -= SQUASH_CHUNK_SIZE; + chunk_start += 2 + (grub_le_to_cpu16 (d) & ~SQUASH_CHUNK_FLAGS); + } + + csize = SQUASH_CHUNK_SIZE - offset; + if (csize > len) + csize = len; + + if (grub_le_to_cpu16 (d) & SQUASH_CHUNK_UNCOMPRESSED) + { + grub_disk_addr_t a = chunk_start + 2 + offset; + err = grub_disk_read (disk, (a >> GRUB_DISK_SECTOR_BITS), + a & (GRUB_DISK_SECTOR_SIZE - 1), + csize, buf); + if (err) + return err; + } + else + { + return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, + "compression not implemented yet"); + } + len -= csize; + offset += csize; + buf = (char *) buf + csize; + } + return GRUB_ERR_NONE; +} + +struct grub_squash_data +{ + grub_disk_t disk; + struct grub_squash_super sb; + struct grub_squash_inode ino; +}; + +struct grub_fshelp_node +{ + struct grub_squash_data *data; + struct grub_squash_inode ino; +}; + +static struct grub_squash_data * +squash_mount (grub_disk_t disk) +{ + struct grub_squash_super sb; + grub_err_t err; + struct grub_squash_data *data; + + err = grub_disk_read (disk, 0, 0, sizeof (sb), &sb); + if (grub_errno == GRUB_ERR_OUT_OF_RANGE) + grub_error (GRUB_ERR_BAD_FS, "not a squash4"); + if (err) + return NULL; + if (grub_le_to_cpu32 (sb.magic) != SQUASH_MAGIC) + { + grub_error (GRUB_ERR_BAD_FS, "not squash4"); + return NULL; + } + data = grub_malloc (sizeof (*data)); + if (!data) + return NULL; + data->sb = sb; + data->disk = disk; + + return data; +} + +static int +grub_squash_iterate_dir (grub_fshelp_node_t dir, + int NESTED_FUNC_ATTR + (*hook) (const char *filename, + enum grub_fshelp_filetype filetype, + grub_fshelp_node_t node)) +{ + grub_uint32_t off = grub_le_to_cpu32 (dir->ino.offset) >> 16; + /* FIXME: determine this. */ + unsigned numheaders = 1; + unsigned i, j; + for (j = 0; j < numheaders; j++) + { + struct grub_squash_dirent_header dh; + grub_err_t err; + + err = read_chunk (dir->data->disk, &dh, sizeof (dh), + grub_le_to_cpu64 (dir->data->sb.diroffset), off); + if (err) + return 0; + off += sizeof (dh); + for (i = 0; i < (unsigned) grub_le_to_cpu16 (dh.nelems) + 1; i++) + { + char *buf; + int r; + struct grub_fshelp_node *node; + enum grub_fshelp_filetype filetype = GRUB_FSHELP_REG; + struct grub_squash_dirent di; + struct grub_squash_inode ino; + + err = read_chunk (dir->data->disk, &di, sizeof (di), + grub_le_to_cpu64 (dir->data->sb.diroffset), off); + if (err) + return 0; + off += sizeof (di); + + err = read_chunk (dir->data->disk, &ino, sizeof (ino), + grub_le_to_cpu64 (dir->data->sb.inodeoffset), + grub_le_to_cpu16 (di.ino)); + if (err) + return 0; + + buf = grub_malloc (grub_le_to_cpu16 (di.namelen) + 2); + if (!buf) + return 0; + err = read_chunk (dir->data->disk, buf, + grub_le_to_cpu16 (di.namelen) + 1, + grub_le_to_cpu64 (dir->data->sb.diroffset), off); + if (err) + return 0; + + off += grub_le_to_cpu16 (di.namelen) + 1; + buf[grub_le_to_cpu16 (di.namelen) + 1] = 0; + if (grub_le_to_cpu16 (ino.type) == SQUASH_TYPE_DIR) + filetype = GRUB_FSHELP_DIR; + node = grub_malloc (sizeof (*node)); + if (! node) + return 0; + *node = *dir; + node->ino = ino; + r = hook (buf, filetype, node); + + grub_free (buf); + if (r) + return r; + } + } + return 0; +} + +static grub_err_t +make_root_node (struct grub_squash_data *data, struct grub_fshelp_node *root) +{ + /* FIXME */ + grub_memset (root, 0, sizeof (*root)); + root->data = data; + return GRUB_ERR_NONE; +} + +static grub_err_t +grub_squash_dir (grub_device_t device, const char *path, + int (*hook) (const char *filename, + const struct grub_dirhook_info *info)) +{ + auto int NESTED_FUNC_ATTR iterate (const char *filename, + enum grub_fshelp_filetype filetype, + grub_fshelp_node_t node); + + int NESTED_FUNC_ATTR iterate (const char *filename, + enum grub_fshelp_filetype filetype, + grub_fshelp_node_t node __attribute__ ((unused))) + { + struct grub_dirhook_info info; + grub_memset (&info, 0, sizeof (info)); + info.dir = ((filetype & GRUB_FSHELP_TYPE_MASK) == GRUB_FSHELP_DIR); + return hook (filename, &info); + } + + struct grub_squash_data *data = 0; + struct grub_fshelp_node *fdiro = 0; + struct grub_fshelp_node root; + grub_err_t err; + + data = squash_mount (device->disk); + if (! data) + return grub_errno; + + err = make_root_node (data, &root); + if (err) + return err; + + grub_fshelp_find_file (path, &root, &fdiro, grub_squash_iterate_dir, + NULL, GRUB_FSHELP_DIR); + if (!grub_errno) + grub_squash_iterate_dir (fdiro, iterate); + + grub_free (data); + + return grub_errno; +} + +static grub_err_t +grub_squash_open (struct grub_file *file, const char *name) +{ + struct grub_squash_data *data = 0; + struct grub_fshelp_node *fdiro = 0; + struct grub_fshelp_node root; + grub_err_t err; + + data = squash_mount (file->device->disk); + if (! data) + return grub_errno; + + err = make_root_node (data, &root); + if (err) + return err; + + grub_fshelp_find_file (name, &root, &fdiro, grub_squash_iterate_dir, + NULL, GRUB_FSHELP_REG); + if (grub_errno) + { + grub_free (data); + return grub_errno; + } + file->data = data; + data->ino = fdiro->ino; + file->size = grub_le_to_cpu16 (fdiro->ino.size); + return GRUB_ERR_NONE; +} + +static grub_ssize_t +grub_squash_read (grub_file_t file, char *buf, grub_size_t len) +{ + grub_err_t err; + grub_uint64_t a; + struct grub_squash_data *data = file->data; + + a = sizeof (struct grub_squash_super) + grub_le_to_cpu32 (data->ino.offset); + + err = grub_disk_read (file->device->disk, a >> GRUB_DISK_SECTOR_BITS, + a & (GRUB_DISK_SECTOR_SIZE - 1), len, buf); + if (err) + return -1; + return len; +} + +static grub_err_t +grub_squash_close (grub_file_t file) +{ + grub_free (file->data); + return GRUB_ERR_NONE; +} + +static struct grub_fs grub_squash_fs = + { + .name = "squash4", + .dir = grub_squash_dir, + .open = grub_squash_open, + .read = grub_squash_read, + .close = grub_squash_close, +#ifdef GRUB_UTIL + .reserved_first_sector = 0, +#endif + .next = 0 + }; + +GRUB_MOD_INIT(squash4) +{ + grub_fs_register (&grub_squash_fs); +} + +GRUB_MOD_FINI(squash4) +{ + grub_fs_unregister (&grub_squash_fs); +} + From 1deadc83f55187f1ba889d6533341850cb3a5f50 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 8 Dec 2010 23:03:59 +0100 Subject: [PATCH 065/869] extend size to 32-bit and handle file->offset --- grub-core/fs/squash4.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/grub-core/fs/squash4.c b/grub-core/fs/squash4.c index 889f8b94c..f3ac1f474 100644 --- a/grub-core/fs/squash4.c +++ b/grub-core/fs/squash4.c @@ -72,8 +72,7 @@ struct grub_squash_inode grub_uint32_t mtime; grub_uint16_t dummy2[6]; grub_uint32_t offset; - grub_uint16_t size; - grub_uint16_t dummy3; + grub_uint32_t size; } __attribute__ ((packed)); /* Chunk-based. */ @@ -330,9 +329,10 @@ grub_squash_open (struct grub_file *file, const char *name) grub_free (data); return grub_errno; } + file->data = data; data->ino = fdiro->ino; - file->size = grub_le_to_cpu16 (fdiro->ino.size); + file->size = grub_le_to_cpu32 (fdiro->ino.size); return GRUB_ERR_NONE; } @@ -343,7 +343,8 @@ grub_squash_read (grub_file_t file, char *buf, grub_size_t len) grub_uint64_t a; struct grub_squash_data *data = file->data; - a = sizeof (struct grub_squash_super) + grub_le_to_cpu32 (data->ino.offset); + a = sizeof (struct grub_squash_super) + grub_le_to_cpu32 (data->ino.offset) + + file->offset; err = grub_disk_read (file->device->disk, a >> GRUB_DISK_SECTOR_BITS, a & (GRUB_DISK_SECTOR_SIZE - 1), len, buf); From 0a040470e53c4620d93249d5aba40097c93740d8 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Thu, 9 Dec 2010 00:04:36 +0100 Subject: [PATCH 066/869] determine root inode on squash4fs --- grub-core/fs/squash4.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/grub-core/fs/squash4.c b/grub-core/fs/squash4.c index f3ac1f474..bd50265a8 100644 --- a/grub-core/fs/squash4.c +++ b/grub-core/fs/squash4.c @@ -52,7 +52,8 @@ struct grub_squash_super grub_uint32_t creation_time; grub_uint32_t dummy2; grub_uint32_t dummy3[4]; - grub_uint32_t dummy4[2]; + grub_uint32_t root_ino; + grub_uint32_t dummy4; grub_uint64_t total_size; grub_uint64_t exttbloffset; grub_uint32_t dummy5[2]; @@ -258,10 +259,12 @@ grub_squash_iterate_dir (grub_fshelp_node_t dir, static grub_err_t make_root_node (struct grub_squash_data *data, struct grub_fshelp_node *root) { - /* FIXME */ grub_memset (root, 0, sizeof (*root)); root->data = data; - return GRUB_ERR_NONE; + + return read_chunk (data->disk, &root->ino, sizeof (root->ino), + grub_le_to_cpu64 (data->sb.inodeoffset), + grub_le_to_cpu32 (data->sb.root_ino)); } static grub_err_t From 7ed6c3e85f51a59d0758de6363d7acd9804c2e21 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Thu, 9 Dec 2010 02:48:59 +0100 Subject: [PATCH 067/869] Honor chunk number for directories --- grub-core/fs/squash4.c | 48 ++++++++++++++++++++++++++++++------------ 1 file changed, 34 insertions(+), 14 deletions(-) diff --git a/grub-core/fs/squash4.c b/grub-core/fs/squash4.c index bd50265a8..1622d3736 100644 --- a/grub-core/fs/squash4.c +++ b/grub-core/fs/squash4.c @@ -52,7 +52,8 @@ struct grub_squash_super grub_uint32_t creation_time; grub_uint32_t dummy2; grub_uint32_t dummy3[4]; - grub_uint32_t root_ino; + grub_uint16_t root_ino_offset; + grub_uint16_t root_ino_chunk; grub_uint32_t dummy4; grub_uint64_t total_size; grub_uint64_t exttbloffset; @@ -71,11 +72,19 @@ struct grub_squash_inode grub_uint16_t type; grub_uint16_t dummy1[3]; grub_uint32_t mtime; - grub_uint16_t dummy2[6]; + grub_uint16_t dummy2[2]; + grub_uint16_t chunk; + grub_uint16_t dummy3[3]; grub_uint32_t offset; grub_uint32_t size; } __attribute__ ((packed)); +static inline unsigned +decode_chunk_number (grub_uint16_t in) +{ + return (grub_le_to_cpu16 (in) & 0xff) / 2; +} + /* Chunk-based. */ struct grub_squash_dirent_header { @@ -102,8 +111,10 @@ struct grub_squash_dirent static grub_err_t read_chunk (grub_disk_t disk, void *buf, grub_size_t len, - grub_uint64_t chunk_start, grub_uint64_t offset) + grub_uint64_t chunk, unsigned nchunk, grub_off_t offset) { + grub_uint64_t chunk_start; + chunk_start = grub_le_to_cpu64 (chunk); while (len > 0) { grub_uint64_t csize; @@ -116,9 +127,12 @@ read_chunk (grub_disk_t disk, void *buf, grub_size_t len, sizeof (d), &d); if (err) return err; - if (offset < SQUASH_CHUNK_SIZE) + if (!nchunk && offset < SQUASH_CHUNK_SIZE) break; - offset -= SQUASH_CHUNK_SIZE; + if (nchunk) + nchunk--; + else + offset -= SQUASH_CHUNK_SIZE; chunk_start += 2 + (grub_le_to_cpu16 (d) & ~SQUASH_CHUNK_FLAGS); } @@ -197,13 +211,15 @@ grub_squash_iterate_dir (grub_fshelp_node_t dir, /* FIXME: determine this. */ unsigned numheaders = 1; unsigned i, j; + for (j = 0; j < numheaders; j++) { struct grub_squash_dirent_header dh; grub_err_t err; err = read_chunk (dir->data->disk, &dh, sizeof (dh), - grub_le_to_cpu64 (dir->data->sb.diroffset), off); + dir->data->sb.diroffset, + decode_chunk_number (dir->ino.chunk), off); if (err) return 0; off += sizeof (dh); @@ -217,14 +233,16 @@ grub_squash_iterate_dir (grub_fshelp_node_t dir, struct grub_squash_inode ino; err = read_chunk (dir->data->disk, &di, sizeof (di), - grub_le_to_cpu64 (dir->data->sb.diroffset), off); + dir->data->sb.diroffset, + decode_chunk_number (dir->ino.chunk), off); if (err) return 0; off += sizeof (di); err = read_chunk (dir->data->disk, &ino, sizeof (ino), - grub_le_to_cpu64 (dir->data->sb.inodeoffset), - grub_le_to_cpu16 (di.ino)); + dir->data->sb.inodeoffset, + 0, + grub_cpu_to_le16 (di.ino)); if (err) return 0; @@ -233,7 +251,8 @@ grub_squash_iterate_dir (grub_fshelp_node_t dir, return 0; err = read_chunk (dir->data->disk, buf, grub_le_to_cpu16 (di.namelen) + 1, - grub_le_to_cpu64 (dir->data->sb.diroffset), off); + dir->data->sb.diroffset, + decode_chunk_number (dir->ino.chunk), off); if (err) return 0; @@ -261,10 +280,11 @@ make_root_node (struct grub_squash_data *data, struct grub_fshelp_node *root) { grub_memset (root, 0, sizeof (*root)); root->data = data; - - return read_chunk (data->disk, &root->ino, sizeof (root->ino), - grub_le_to_cpu64 (data->sb.inodeoffset), - grub_le_to_cpu32 (data->sb.root_ino)); + + return read_chunk (data->disk, &root->ino, sizeof (root->ino), + data->sb.inodeoffset, + decode_chunk_number (data->sb.root_ino_chunk), + grub_cpu_to_le16 (data->sb.root_ino_offset)); } static grub_err_t From a94a667185f093fd953b8775292652bc58b0d5fe Mon Sep 17 00:00:00 2001 From: Robert Millan Date: Thu, 9 Dec 2010 14:09:37 +0100 Subject: [PATCH 068/869] 2010-12-09 Robert Millan * NEWS: Document addition of ZFS support. --- ChangeLog | 4 ++++ NEWS | 4 +--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 0c6e842de..f215398cc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2010-12-09 Robert Millan + + * NEWS: Document addition of ZFS support. + 2010-12-04 Colin Watson * grub-core/kern/i386/pc/startup.S (grub_console_getkey): Use `>> 1' diff --git a/NEWS b/NEWS index 7fce921d6..36e3f25bf 100644 --- a/NEWS +++ b/NEWS @@ -51,9 +51,7 @@ New in 1.99: * Add `sendkey' command (i386-pc only). -* ZFS support in `grub-install' and `grub-mkconfig'. Note: complete - functionality requires external ZFS implementation (available from - grub-extras). +* ZFS support. * Support 1.x versions of mdadm metadata. From 948ebd7e91f29efea22bc4987582efb827940294 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Thu, 9 Dec 2010 17:06:49 +0100 Subject: [PATCH 069/869] Support fragments and chunks for data --- grub-core/fs/squash4.c | 91 +++++++++++++++++++++++++++++------------- 1 file changed, 64 insertions(+), 27 deletions(-) diff --git a/grub-core/fs/squash4.c b/grub-core/fs/squash4.c index 1622d3736..6fc2bc11b 100644 --- a/grub-core/fs/squash4.c +++ b/grub-core/fs/squash4.c @@ -28,16 +28,16 @@ #include /* - object format Pointed by - superblock RAW Fixed offset (0) - data RAW ? Fixed offset (60) - inode table Chunk superblock - dir table Chunk superblock - unk3 Chunk unk1 - unk1 RAW, Chunk superblock - unk2 RAW superblock - UID/GID Chunk exttblptr - exttblptr RAW superblock + object format Pointed by + superblock RAW Fixed offset (0) + data RAW ? Fixed offset (60) + inode table Chunk superblock + dir table Chunk superblock + fragment table Chunk unk1 + unk1 RAW, Chunk superblock + unk2 RAW superblock + UID/GID Chunk exttblptr + exttblptr RAW superblock UID/GID table is the array ot uint32_t unk1 contains pointer to unk3 followed by some chunk. @@ -73,8 +73,8 @@ struct grub_squash_inode grub_uint16_t dummy1[3]; grub_uint32_t mtime; grub_uint16_t dummy2[2]; - grub_uint16_t chunk; - grub_uint16_t dummy3[3]; + grub_uint32_t chunk; + grub_uint32_t fragment; grub_uint32_t offset; grub_uint32_t size; } __attribute__ ((packed)); @@ -105,10 +105,30 @@ struct grub_squash_dirent char name[0]; }; +struct grub_squash_frag_desc +{ + grub_uint64_t offset; + grub_uint64_t dummy; +}; + #define SQUASH_CHUNK_SIZE 0x2000 #define SQUASH_CHUNK_FLAGS 0x8000 #define SQUASH_CHUNK_UNCOMPRESSED 0x8000 +struct grub_squash_data +{ + grub_disk_t disk; + struct grub_squash_super sb; + struct grub_squash_inode ino; + grub_uint64_t fragments; +}; + +struct grub_fshelp_node +{ + struct grub_squash_data *data; + struct grub_squash_inode ino; +}; + static grub_err_t read_chunk (grub_disk_t disk, void *buf, grub_size_t len, grub_uint64_t chunk, unsigned nchunk, grub_off_t offset) @@ -161,25 +181,13 @@ read_chunk (grub_disk_t disk, void *buf, grub_size_t len, return GRUB_ERR_NONE; } -struct grub_squash_data -{ - grub_disk_t disk; - struct grub_squash_super sb; - struct grub_squash_inode ino; -}; - -struct grub_fshelp_node -{ - struct grub_squash_data *data; - struct grub_squash_inode ino; -}; - static struct grub_squash_data * squash_mount (grub_disk_t disk) { struct grub_squash_super sb; grub_err_t err; struct grub_squash_data *data; + grub_uint64_t frag; err = grub_disk_read (disk, 0, 0, sizeof (sb), &sb); if (grub_errno == GRUB_ERR_OUT_OF_RANGE) @@ -191,11 +199,22 @@ squash_mount (grub_disk_t disk) grub_error (GRUB_ERR_BAD_FS, "not squash4"); return NULL; } + + err = grub_disk_read (disk, grub_le_to_cpu32 (sb.unk1offset) + >> GRUB_DISK_SECTOR_BITS, + grub_le_to_cpu32 (sb.unk1offset) + & (GRUB_DISK_SECTOR_SIZE - 1), sizeof (frag), &frag); + if (grub_errno == GRUB_ERR_OUT_OF_RANGE) + grub_error (GRUB_ERR_BAD_FS, "not a squash4"); + if (err) + return NULL; + data = grub_malloc (sizeof (*data)); if (!data) return NULL; data->sb = sb; data->disk = disk; + data->fragments = frag; return data; } @@ -356,6 +375,7 @@ grub_squash_open (struct grub_file *file, const char *name) file->data = data; data->ino = fdiro->ino; file->size = grub_le_to_cpu32 (fdiro->ino.size); + return GRUB_ERR_NONE; } @@ -366,8 +386,25 @@ grub_squash_read (grub_file_t file, char *buf, grub_size_t len) grub_uint64_t a; struct grub_squash_data *data = file->data; - a = sizeof (struct grub_squash_super) + grub_le_to_cpu32 (data->ino.offset) - + file->offset; + a = grub_le_to_cpu32 (data->ino.offset) + file->offset; + if (grub_le_to_cpu16 (data->ino.fragment) == 0xffff) + { + if (grub_le_to_cpu32 (data->ino.chunk)) + a += grub_le_to_cpu32 (data->ino.chunk); + else + a += sizeof (struct grub_squash_super); + } + else + { + struct grub_squash_frag_desc frag; + err = read_chunk (file->device->disk, &frag, sizeof (frag), + data->fragments, 0, sizeof (frag) + * grub_le_to_cpu16 (data->ino.fragment)); + if (err) + return -1; + a += grub_le_to_cpu64 (frag.offset); + a += grub_le_to_cpu32 (data->ino.chunk); + } err = grub_disk_read (file->device->disk, a >> GRUB_DISK_SECTOR_BITS, a & (GRUB_DISK_SECTOR_SIZE - 1), len, buf); From 99f0735fb8f961f4281eae3c76366f2eb8afdad2 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Thu, 9 Dec 2010 18:22:38 +0100 Subject: [PATCH 070/869] Support multi-header directories --- grub-core/fs/squash4.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/grub-core/fs/squash4.c b/grub-core/fs/squash4.c index 6fc2bc11b..5bb128f58 100644 --- a/grub-core/fs/squash4.c +++ b/grub-core/fs/squash4.c @@ -227,11 +227,13 @@ grub_squash_iterate_dir (grub_fshelp_node_t dir, grub_fshelp_node_t node)) { grub_uint32_t off = grub_le_to_cpu32 (dir->ino.offset) >> 16; - /* FIXME: determine this. */ - unsigned numheaders = 1; - unsigned i, j; + grub_uint32_t endoff; + unsigned i; - for (j = 0; j < numheaders; j++) + /* FIXME: why - 3 ? */ + endoff = (grub_le_to_cpu32 (dir->ino.offset) & 0xffff) + off - 3; + + while (off < endoff) { struct grub_squash_dirent_header dh; grub_err_t err; From 76e39dc8711ce85d43fa06a0a4ee9e0683091d45 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Thu, 9 Dec 2010 19:23:35 +0100 Subject: [PATCH 071/869] Compressed metadata support --- grub-core/fs/squash4.c | 74 +++++++++++++++++++++++++----------------- 1 file changed, 44 insertions(+), 30 deletions(-) diff --git a/grub-core/fs/squash4.c b/grub-core/fs/squash4.c index 5bb128f58..8eca185f3 100644 --- a/grub-core/fs/squash4.c +++ b/grub-core/fs/squash4.c @@ -79,23 +79,19 @@ struct grub_squash_inode grub_uint32_t size; } __attribute__ ((packed)); -static inline unsigned -decode_chunk_number (grub_uint16_t in) -{ - return (grub_le_to_cpu16 (in) & 0xff) / 2; -} - /* Chunk-based. */ struct grub_squash_dirent_header { /* Actually the value is the number of elements - 1. */ grub_uint16_t nelems; - grub_uint16_t dummy[5]; + grub_uint16_t dummy1; + grub_uint32_t ino_chunk; + grub_uint16_t dummy2[2]; }; struct grub_squash_dirent { - grub_uint16_t ino; + grub_uint16_t ino_offset; grub_uint16_t dummy; grub_uint16_t type; #define SQUASH_TYPE_DIR 1 @@ -131,7 +127,7 @@ struct grub_fshelp_node static grub_err_t read_chunk (grub_disk_t disk, void *buf, grub_size_t len, - grub_uint64_t chunk, unsigned nchunk, grub_off_t offset) + grub_uint64_t chunk, grub_off_t offset) { grub_uint64_t chunk_start; chunk_start = grub_le_to_cpu64 (chunk); @@ -147,12 +143,9 @@ read_chunk (grub_disk_t disk, void *buf, grub_size_t len, sizeof (d), &d); if (err) return err; - if (!nchunk && offset < SQUASH_CHUNK_SIZE) + if (offset < SQUASH_CHUNK_SIZE) break; - if (nchunk) - nchunk--; - else - offset -= SQUASH_CHUNK_SIZE; + offset -= SQUASH_CHUNK_SIZE; chunk_start += 2 + (grub_le_to_cpu16 (d) & ~SQUASH_CHUNK_FLAGS); } @@ -171,8 +164,29 @@ read_chunk (grub_disk_t disk, void *buf, grub_size_t len, } else { - return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, - "compression not implemented yet"); + char *tmp; + grub_size_t bsize = grub_le_to_cpu16 (d) & ~SQUASH_CHUNK_FLAGS; + grub_disk_addr_t a = chunk_start + 2; + tmp = grub_malloc (bsize); + if (!tmp) + return grub_errno; + /* FIXME: buffer uncompressed data. */ + err = grub_disk_read (disk, (a >> GRUB_DISK_SECTOR_BITS), + a & (GRUB_DISK_SECTOR_SIZE - 1), + bsize, tmp); + if (err) + { + grub_free (tmp); + return err; + } + + if (grub_zlib_decompress (tmp, bsize, offset, + buf, csize) < 0) + { + grub_free (tmp); + return grub_errno; + } + grub_free (tmp); } len -= csize; offset += csize; @@ -239,8 +253,8 @@ grub_squash_iterate_dir (grub_fshelp_node_t dir, grub_err_t err; err = read_chunk (dir->data->disk, &dh, sizeof (dh), - dir->data->sb.diroffset, - decode_chunk_number (dir->ino.chunk), off); + grub_le_to_cpu64 (dir->data->sb.diroffset) + + grub_le_to_cpu32 (dir->ino.chunk), off); if (err) return 0; off += sizeof (dh); @@ -254,16 +268,16 @@ grub_squash_iterate_dir (grub_fshelp_node_t dir, struct grub_squash_inode ino; err = read_chunk (dir->data->disk, &di, sizeof (di), - dir->data->sb.diroffset, - decode_chunk_number (dir->ino.chunk), off); + grub_le_to_cpu64 (dir->data->sb.diroffset) + + grub_le_to_cpu32 (dir->ino.chunk), off); if (err) return 0; off += sizeof (di); err = read_chunk (dir->data->disk, &ino, sizeof (ino), - dir->data->sb.inodeoffset, - 0, - grub_cpu_to_le16 (di.ino)); + grub_le_to_cpu64 (dir->data->sb.inodeoffset) + + grub_le_to_cpu32 (dh.ino_chunk), + grub_cpu_to_le16 (di.ino_offset)); if (err) return 0; @@ -272,14 +286,14 @@ grub_squash_iterate_dir (grub_fshelp_node_t dir, return 0; err = read_chunk (dir->data->disk, buf, grub_le_to_cpu16 (di.namelen) + 1, - dir->data->sb.diroffset, - decode_chunk_number (dir->ino.chunk), off); + grub_le_to_cpu64 (dir->data->sb.diroffset) + + grub_le_to_cpu32 (dir->ino.chunk), off); if (err) return 0; off += grub_le_to_cpu16 (di.namelen) + 1; buf[grub_le_to_cpu16 (di.namelen) + 1] = 0; - if (grub_le_to_cpu16 (ino.type) == SQUASH_TYPE_DIR) + if (grub_le_to_cpu16 (di.type) == SQUASH_TYPE_DIR) filetype = GRUB_FSHELP_DIR; node = grub_malloc (sizeof (*node)); if (! node) @@ -303,9 +317,9 @@ make_root_node (struct grub_squash_data *data, struct grub_fshelp_node *root) root->data = data; return read_chunk (data->disk, &root->ino, sizeof (root->ino), - data->sb.inodeoffset, - decode_chunk_number (data->sb.root_ino_chunk), - grub_cpu_to_le16 (data->sb.root_ino_offset)); + grub_le_to_cpu64 (data->sb.inodeoffset) + + grub_le_to_cpu16 (data->sb.root_ino_chunk), + grub_cpu_to_le16 (data->sb.root_ino_offset)); } static grub_err_t @@ -400,7 +414,7 @@ grub_squash_read (grub_file_t file, char *buf, grub_size_t len) { struct grub_squash_frag_desc frag; err = read_chunk (file->device->disk, &frag, sizeof (frag), - data->fragments, 0, sizeof (frag) + data->fragments, sizeof (frag) * grub_le_to_cpu16 (data->ino.fragment)); if (err) return -1; From e4eaf625553ddf07f6cade56651fda7038542ea2 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Thu, 9 Dec 2010 19:40:11 +0100 Subject: [PATCH 072/869] Small restructuring of squash_read --- grub-core/fs/squash4.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/grub-core/fs/squash4.c b/grub-core/fs/squash4.c index 8eca185f3..1a121c2cf 100644 --- a/grub-core/fs/squash4.c +++ b/grub-core/fs/squash4.c @@ -402,13 +402,12 @@ grub_squash_read (grub_file_t file, char *buf, grub_size_t len) grub_uint64_t a; struct grub_squash_data *data = file->data; - a = grub_le_to_cpu32 (data->ino.offset) + file->offset; if (grub_le_to_cpu16 (data->ino.fragment) == 0xffff) { if (grub_le_to_cpu32 (data->ino.chunk)) - a += grub_le_to_cpu32 (data->ino.chunk); + a = grub_le_to_cpu32 (data->ino.chunk); else - a += sizeof (struct grub_squash_super); + a = sizeof (struct grub_squash_super); } else { @@ -418,10 +417,11 @@ grub_squash_read (grub_file_t file, char *buf, grub_size_t len) * grub_le_to_cpu16 (data->ino.fragment)); if (err) return -1; - a += grub_le_to_cpu64 (frag.offset); - a += grub_le_to_cpu32 (data->ino.chunk); + a = grub_le_to_cpu64 (frag.offset) + grub_le_to_cpu32 (data->ino.chunk); } + a += grub_le_to_cpu32 (data->ino.offset) + file->offset; + err = grub_disk_read (file->device->disk, a >> GRUB_DISK_SECTOR_BITS, a & (GRUB_DISK_SECTOR_SIZE - 1), len, buf); if (err) From 8eef1f8244a91a1beb18bc7a94fad7347382e65e Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Thu, 9 Dec 2010 20:41:41 +0100 Subject: [PATCH 073/869] Compressed fragments and compressed data support --- grub-core/fs/squash4.c | 26 +++++++++++++++------ grub-core/io/gzio.c | 53 +++++++++++++++++++++++++++++++++++++++--- include/grub/deflate.h | 4 ++++ 3 files changed, 73 insertions(+), 10 deletions(-) diff --git a/grub-core/fs/squash4.c b/grub-core/fs/squash4.c index 1a121c2cf..50e5c3090 100644 --- a/grub-core/fs/squash4.c +++ b/grub-core/fs/squash4.c @@ -51,13 +51,18 @@ struct grub_squash_super grub_uint32_t dummy1; grub_uint32_t creation_time; grub_uint32_t dummy2; - grub_uint32_t dummy3[4]; + grub_uint32_t dummy3[2]; + grub_uint8_t flags; +#define SQUASH_FLAG_UNCOMPRESSED_INODES 1 +#define SQUASH_FLAG_UNCOMPRESSED_DATA 2 +#define SQUASH_FLAG_UNCOMPRESSED_FRAGMENTS 8 + grub_uint8_t dummy4[7]; grub_uint16_t root_ino_offset; grub_uint16_t root_ino_chunk; - grub_uint32_t dummy4; + grub_uint32_t dummy5; grub_uint64_t total_size; grub_uint64_t exttbloffset; - grub_uint32_t dummy5[2]; + grub_uint32_t dummy6[2]; grub_uint64_t inodeoffset; grub_uint64_t diroffset; grub_uint64_t unk1offset; @@ -399,8 +404,9 @@ static grub_ssize_t grub_squash_read (grub_file_t file, char *buf, grub_size_t len) { grub_err_t err; - grub_uint64_t a; + grub_uint64_t a, b; struct grub_squash_data *data = file->data; + int compressed = 0; if (grub_le_to_cpu16 (data->ino.fragment) == 0xffff) { @@ -408,6 +414,7 @@ grub_squash_read (grub_file_t file, char *buf, grub_size_t len) a = grub_le_to_cpu32 (data->ino.chunk); else a = sizeof (struct grub_squash_super); + compressed = !(data->sb.flags & SQUASH_FLAG_UNCOMPRESSED_DATA); } else { @@ -418,12 +425,17 @@ grub_squash_read (grub_file_t file, char *buf, grub_size_t len) if (err) return -1; a = grub_le_to_cpu64 (frag.offset) + grub_le_to_cpu32 (data->ino.chunk); + compressed = !(data->sb.flags & SQUASH_FLAG_UNCOMPRESSED_FRAGMENTS); } - a += grub_le_to_cpu32 (data->ino.offset) + file->offset; + b = grub_le_to_cpu32 (data->ino.offset) + file->offset; - err = grub_disk_read (file->device->disk, a >> GRUB_DISK_SECTOR_BITS, - a & (GRUB_DISK_SECTOR_SIZE - 1), len, buf); + /* FIXME: cache uncompressed chunks. */ + if (compressed) + err = grub_zlib_disk_read (file->device->disk, a, b, buf, len); + else + err = grub_disk_read (file->device->disk, (a + b) >> GRUB_DISK_SECTOR_BITS, + (a + b) & (GRUB_DISK_SECTOR_SIZE - 1), len, buf); if (err) return -1; return len; diff --git a/grub-core/io/gzio.c b/grub-core/io/gzio.c index 248a1750e..61227b4fc 100644 --- a/grub-core/io/gzio.c +++ b/grub-core/io/gzio.c @@ -41,6 +41,7 @@ #include #include #include +#include #include /* @@ -62,6 +63,9 @@ struct grub_gzio /* If input is in memory following fields are used instead of file. */ grub_size_t mem_input_size, mem_input_off; grub_uint8_t *mem_input; + grub_disk_addr_t disk_input_off; + grub_disk_addr_t disk_input_start; + grub_disk_t disk_input; /* The offset at which the data starts in the underlying file. */ grub_off_t data_offset; /* The type of current block. */ @@ -383,8 +387,21 @@ get_byte (grub_gzio_t gzio) return 0; } - if (grub_file_tell (gzio->file) == (grub_off_t) gzio->data_offset - || gzio->inbuf_d == INBUFSIZ) + if (gzio->disk_input && (gzio->disk_input_off == gzio->data_offset + || gzio->inbuf_d == INBUFSIZ)) + { + grub_disk_addr_t d = gzio->disk_input_start + gzio->disk_input_off; + gzio->inbuf_d = 0; + grub_disk_read (gzio->disk_input, + d >> GRUB_DISK_SECTOR_BITS, + d & (GRUB_DISK_SECTOR_SIZE - 1), + INBUFSIZ, gzio->inbuf); + gzio->disk_input_off += INBUFSIZ; + } + + if (gzio->file && (grub_file_tell (gzio->file) + == (grub_off_t) gzio->data_offset + || gzio->inbuf_d == INBUFSIZ)) { gzio->inbuf_d = 0; grub_file_read (gzio->file, gzio->inbuf, INBUFSIZ); @@ -402,8 +419,10 @@ gzio_seek (grub_gzio_t gzio, grub_off_t off) grub_error (GRUB_ERR_OUT_OF_RANGE, "attempt to seek outside of the file"); else - gzio->mem_input_off = gzio->data_offset; + gzio->mem_input_off = off; } + else if (gzio->disk_input) + gzio->disk_input_off = off; else grub_file_seek (gzio->file, off); } @@ -1297,6 +1316,34 @@ grub_zlib_decompress (char *inbuf, grub_size_t insize, grub_off_t off, return ret; } +grub_err_t +grub_zlib_disk_read (grub_disk_t disk, grub_disk_addr_t zlibstart, + grub_off_t off, char *outbuf, grub_size_t outsize) +{ + grub_gzio_t gzio = 0; + grub_ssize_t ret; + + gzio = grub_zalloc (sizeof (*gzio)); + if (! gzio) + return -1; + + gzio->disk_input_off = 0; + gzio->disk_input_start = zlibstart; + gzio->disk_input = disk; + + if (!test_zlib_header (gzio)) + { + grub_free (gzio); + return -1; + } + + ret = grub_gzio_read_real (gzio, off, outbuf, outsize); + grub_free (gzio); + + /* FIXME: Check Adler. */ + return ret < 0 ? grub_errno : GRUB_ERR_NONE; +} + static struct grub_fs grub_gzio_fs = diff --git a/include/grub/deflate.h b/include/grub/deflate.h index 6ec4eaa99..ae4a1f244 100644 --- a/include/grub/deflate.h +++ b/include/grub/deflate.h @@ -23,4 +23,8 @@ grub_ssize_t grub_zlib_decompress (char *inbuf, grub_size_t insize, grub_off_t off, char *outbuf, grub_size_t outsize); +grub_err_t +grub_zlib_disk_read (grub_disk_t disk, grub_disk_addr_t zlibstart, + grub_off_t off, char *outbuf, grub_size_t outsize); + #endif From 1fc7203971e91efde3645b97fac776872ecf7e5a Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Thu, 9 Dec 2010 20:48:03 +0100 Subject: [PATCH 074/869] Split grub_squash_read_data --- grub-core/fs/squash4.c | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/grub-core/fs/squash4.c b/grub-core/fs/squash4.c index 50e5c3090..2fa429803 100644 --- a/grub-core/fs/squash4.c +++ b/grub-core/fs/squash4.c @@ -401,17 +401,18 @@ grub_squash_open (struct grub_file *file, const char *name) } static grub_ssize_t -grub_squash_read (grub_file_t file, char *buf, grub_size_t len) +grub_squash_read_data (struct grub_squash_data *data, + grub_disk_t disk, const struct grub_squash_inode *ino, + grub_off_t off, char *buf, grub_size_t len) { grub_err_t err; grub_uint64_t a, b; - struct grub_squash_data *data = file->data; int compressed = 0; - if (grub_le_to_cpu16 (data->ino.fragment) == 0xffff) + if (grub_le_to_cpu16 (ino->fragment) == 0xffff) { - if (grub_le_to_cpu32 (data->ino.chunk)) - a = grub_le_to_cpu32 (data->ino.chunk); + if (grub_le_to_cpu32 (ino->chunk)) + a = grub_le_to_cpu32 (ino->chunk); else a = sizeof (struct grub_squash_super); compressed = !(data->sb.flags & SQUASH_FLAG_UNCOMPRESSED_DATA); @@ -419,28 +420,37 @@ grub_squash_read (grub_file_t file, char *buf, grub_size_t len) else { struct grub_squash_frag_desc frag; - err = read_chunk (file->device->disk, &frag, sizeof (frag), + err = read_chunk (disk, &frag, sizeof (frag), data->fragments, sizeof (frag) - * grub_le_to_cpu16 (data->ino.fragment)); + * grub_le_to_cpu16 (ino->fragment)); if (err) return -1; - a = grub_le_to_cpu64 (frag.offset) + grub_le_to_cpu32 (data->ino.chunk); + a = grub_le_to_cpu64 (frag.offset) + grub_le_to_cpu32 (ino->chunk); compressed = !(data->sb.flags & SQUASH_FLAG_UNCOMPRESSED_FRAGMENTS); } - b = grub_le_to_cpu32 (data->ino.offset) + file->offset; + b = grub_le_to_cpu32 (data->ino.offset) + off; /* FIXME: cache uncompressed chunks. */ if (compressed) - err = grub_zlib_disk_read (file->device->disk, a, b, buf, len); + err = grub_zlib_disk_read (disk, a, b, buf, len); else - err = grub_disk_read (file->device->disk, (a + b) >> GRUB_DISK_SECTOR_BITS, + err = grub_disk_read (disk, (a + b) >> GRUB_DISK_SECTOR_BITS, (a + b) & (GRUB_DISK_SECTOR_SIZE - 1), len, buf); if (err) return -1; return len; } +static grub_ssize_t +grub_squash_read (grub_file_t file, char *buf, grub_size_t len) +{ + struct grub_squash_data *data = file->data; + + return grub_squash_read_data (data, file->device->disk, &data->ino, + file->offset, buf, len); +} + static grub_err_t grub_squash_close (grub_file_t file) { From 627a62fc70e75578ebcfbef71428afd1700f7e7d Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Thu, 9 Dec 2010 21:14:42 +0100 Subject: [PATCH 075/869] Make type-dependent portion of inode an union --- grub-core/fs/squash4.c | 49 ++++++++++++++++++++++++++---------------- 1 file changed, 31 insertions(+), 18 deletions(-) diff --git a/grub-core/fs/squash4.c b/grub-core/fs/squash4.c index 2fa429803..409d91e47 100644 --- a/grub-core/fs/squash4.c +++ b/grub-core/fs/squash4.c @@ -75,13 +75,26 @@ struct grub_squash_inode { /* Same values as direlem types. */ grub_uint16_t type; - grub_uint16_t dummy1[3]; + grub_uint16_t dummy[3]; grub_uint32_t mtime; - grub_uint16_t dummy2[2]; - grub_uint32_t chunk; - grub_uint32_t fragment; - grub_uint32_t offset; - grub_uint32_t size; + union + { + struct { + grub_uint16_t dummy[2]; + grub_uint32_t chunk; + grub_uint32_t fragment; + grub_uint32_t offset; + grub_uint32_t size; + } file; + struct { + grub_uint16_t dummy1[2]; + grub_uint32_t chunk; + grub_uint16_t dummy2[2]; + grub_uint16_t size; + grub_uint16_t offset; + grub_uint16_t dummy3[2]; + } dir; + }; } __attribute__ ((packed)); /* Chunk-based. */ @@ -245,12 +258,12 @@ grub_squash_iterate_dir (grub_fshelp_node_t dir, enum grub_fshelp_filetype filetype, grub_fshelp_node_t node)) { - grub_uint32_t off = grub_le_to_cpu32 (dir->ino.offset) >> 16; + grub_uint32_t off = grub_le_to_cpu16 (dir->ino.dir.offset); grub_uint32_t endoff; unsigned i; /* FIXME: why - 3 ? */ - endoff = (grub_le_to_cpu32 (dir->ino.offset) & 0xffff) + off - 3; + endoff = grub_le_to_cpu32 (dir->ino.dir.size) + off - 3; while (off < endoff) { @@ -259,7 +272,7 @@ grub_squash_iterate_dir (grub_fshelp_node_t dir, err = read_chunk (dir->data->disk, &dh, sizeof (dh), grub_le_to_cpu64 (dir->data->sb.diroffset) - + grub_le_to_cpu32 (dir->ino.chunk), off); + + grub_le_to_cpu32 (dir->ino.dir.chunk), off); if (err) return 0; off += sizeof (dh); @@ -274,7 +287,7 @@ grub_squash_iterate_dir (grub_fshelp_node_t dir, err = read_chunk (dir->data->disk, &di, sizeof (di), grub_le_to_cpu64 (dir->data->sb.diroffset) - + grub_le_to_cpu32 (dir->ino.chunk), off); + + grub_le_to_cpu32 (dir->ino.dir.chunk), off); if (err) return 0; off += sizeof (di); @@ -292,7 +305,7 @@ grub_squash_iterate_dir (grub_fshelp_node_t dir, err = read_chunk (dir->data->disk, buf, grub_le_to_cpu16 (di.namelen) + 1, grub_le_to_cpu64 (dir->data->sb.diroffset) - + grub_le_to_cpu32 (dir->ino.chunk), off); + + grub_le_to_cpu32 (dir->ino.dir.chunk), off); if (err) return 0; @@ -395,7 +408,7 @@ grub_squash_open (struct grub_file *file, const char *name) file->data = data; data->ino = fdiro->ino; - file->size = grub_le_to_cpu32 (fdiro->ino.size); + file->size = grub_le_to_cpu32 (fdiro->ino.file.size); return GRUB_ERR_NONE; } @@ -409,10 +422,10 @@ grub_squash_read_data (struct grub_squash_data *data, grub_uint64_t a, b; int compressed = 0; - if (grub_le_to_cpu16 (ino->fragment) == 0xffff) + if (grub_le_to_cpu16 (ino->file.fragment) == 0xffff) { - if (grub_le_to_cpu32 (ino->chunk)) - a = grub_le_to_cpu32 (ino->chunk); + if (grub_le_to_cpu32 (ino->file.chunk)) + a = grub_le_to_cpu32 (ino->file.chunk); else a = sizeof (struct grub_squash_super); compressed = !(data->sb.flags & SQUASH_FLAG_UNCOMPRESSED_DATA); @@ -422,14 +435,14 @@ grub_squash_read_data (struct grub_squash_data *data, struct grub_squash_frag_desc frag; err = read_chunk (disk, &frag, sizeof (frag), data->fragments, sizeof (frag) - * grub_le_to_cpu16 (ino->fragment)); + * grub_le_to_cpu16 (ino->file.fragment)); if (err) return -1; - a = grub_le_to_cpu64 (frag.offset) + grub_le_to_cpu32 (ino->chunk); + a = grub_le_to_cpu64 (frag.offset) + grub_le_to_cpu32 (ino->file.chunk); compressed = !(data->sb.flags & SQUASH_FLAG_UNCOMPRESSED_FRAGMENTS); } - b = grub_le_to_cpu32 (data->ino.offset) + off; + b = grub_le_to_cpu32 (data->ino.file.offset) + off; /* FIXME: cache uncompressed chunks. */ if (compressed) From e330e4f3830f0c0cab6dfc753c1c9b31c7b909bf Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Thu, 9 Dec 2010 21:17:27 +0100 Subject: [PATCH 076/869] support file mtime --- grub-core/fs/squash4.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/grub-core/fs/squash4.c b/grub-core/fs/squash4.c index 409d91e47..9637496d9 100644 --- a/grub-core/fs/squash4.c +++ b/grub-core/fs/squash4.c @@ -351,11 +351,13 @@ grub_squash_dir (grub_device_t device, const char *path, int NESTED_FUNC_ATTR iterate (const char *filename, enum grub_fshelp_filetype filetype, - grub_fshelp_node_t node __attribute__ ((unused))) + grub_fshelp_node_t node) { struct grub_dirhook_info info; grub_memset (&info, 0, sizeof (info)); info.dir = ((filetype & GRUB_FSHELP_TYPE_MASK) == GRUB_FSHELP_DIR); + info.mtimeset = 1; + info.mtime = grub_le_to_cpu32 (node->ino.mtime); return hook (filename, &info); } From 4a91cd82203200b8c636f4659905449e5ae1395a Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Thu, 9 Dec 2010 22:29:36 +0100 Subject: [PATCH 077/869] symlink support --- grub-core/fs/squash4.c | 40 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/grub-core/fs/squash4.c b/grub-core/fs/squash4.c index 9637496d9..95797998a 100644 --- a/grub-core/fs/squash4.c +++ b/grub-core/fs/squash4.c @@ -94,6 +94,11 @@ struct grub_squash_inode grub_uint16_t offset; grub_uint16_t dummy3[2]; } dir; + struct { + grub_uint16_t dummy[4]; + grub_uint32_t namelen; + char name[0]; + } symlink; }; } __attribute__ ((packed)); @@ -114,6 +119,7 @@ struct grub_squash_dirent grub_uint16_t type; #define SQUASH_TYPE_DIR 1 #define SQUASH_TYPE_REGULAR 2 +#define SQUASH_TYPE_SYMLINK 3 /* Actually the value is the length of name - 1. */ grub_uint16_t namelen; char name[0]; @@ -141,6 +147,8 @@ struct grub_fshelp_node { struct grub_squash_data *data; struct grub_squash_inode ino; + grub_uint32_t ino_chunk; + grub_uint16_t ino_offset; }; static grub_err_t @@ -251,6 +259,28 @@ squash_mount (grub_disk_t disk) return data; } +static char * +grub_squash_read_symlink (grub_fshelp_node_t node) +{ + char *ret; + grub_err_t err; + ret = grub_malloc (grub_le_to_cpu32 (node->ino.symlink.namelen) + 1); + + err = read_chunk (node->data->disk, ret, + grub_le_to_cpu32 (node->ino.symlink.namelen), + grub_le_to_cpu64 (node->data->sb.inodeoffset) + + node->ino_chunk, + node->ino_offset + (node->ino.symlink.name + - (char *) &node->ino)); + if (err) + { + grub_free (ret); + return NULL; + } + ret[grub_le_to_cpu32 (node->ino.symlink.namelen)] = 0; + return ret; +} + static int grub_squash_iterate_dir (grub_fshelp_node_t dir, int NESTED_FUNC_ATTR @@ -313,11 +343,17 @@ grub_squash_iterate_dir (grub_fshelp_node_t dir, buf[grub_le_to_cpu16 (di.namelen) + 1] = 0; if (grub_le_to_cpu16 (di.type) == SQUASH_TYPE_DIR) filetype = GRUB_FSHELP_DIR; + if (grub_le_to_cpu16 (di.type) == SQUASH_TYPE_SYMLINK) + filetype = GRUB_FSHELP_SYMLINK; + node = grub_malloc (sizeof (*node)); if (! node) return 0; *node = *dir; node->ino = ino; + node->ino_chunk = grub_le_to_cpu32 (dh.ino_chunk); + node->ino_offset = grub_le_to_cpu16 (di.ino_offset); + r = hook (buf, filetype, node); grub_free (buf); @@ -375,7 +411,7 @@ grub_squash_dir (grub_device_t device, const char *path, return err; grub_fshelp_find_file (path, &root, &fdiro, grub_squash_iterate_dir, - NULL, GRUB_FSHELP_DIR); + grub_squash_read_symlink, GRUB_FSHELP_DIR); if (!grub_errno) grub_squash_iterate_dir (fdiro, iterate); @@ -401,7 +437,7 @@ grub_squash_open (struct grub_file *file, const char *name) return err; grub_fshelp_find_file (name, &root, &fdiro, grub_squash_iterate_dir, - NULL, GRUB_FSHELP_REG); + grub_squash_read_symlink, GRUB_FSHELP_REG); if (grub_errno) { grub_free (data); From db64f5b16769168329c3269d5907acca7328de6c Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 10 Dec 2010 08:42:40 +0100 Subject: [PATCH 078/869] mtime support for cpio and tar --- grub-core/fs/cpio.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/grub-core/fs/cpio.c b/grub-core/fs/cpio.c index c087b4f90..486d8215c 100644 --- a/grub-core/fs/cpio.c +++ b/grub-core/fs/cpio.c @@ -78,7 +78,7 @@ static grub_dl_t my_mod; static grub_err_t grub_cpio_find_file (struct grub_cpio_data *data, char **name, - grub_uint32_t * ofs) + grub_int32_t *mtime, grub_uint32_t * ofs) { #ifndef MODE_USTAR struct head hd; @@ -91,6 +91,8 @@ grub_cpio_find_file (struct grub_cpio_data *data, char **name, return grub_error (GRUB_ERR_BAD_FS, "invalid cpio archive"); data->size = (((grub_uint32_t) hd.filesize_1) << 16) + hd.filesize_2; + if (mtime) + *mtime = (((grub_uint32_t) hd.mtime_1) << 16) + hd.mtime_2; if (hd.namesize & 1) hd.namesize++; @@ -139,6 +141,8 @@ grub_cpio_find_file (struct grub_cpio_data *data, char **name, data->dofs = data->hofs + GRUB_DISK_SECTOR_SIZE; *ofs = data->dofs + ((data->size + GRUB_DISK_SECTOR_SIZE - 1) & ~(GRUB_DISK_SECTOR_SIZE - 1)); + if (mtime) + *mtime = grub_strtoul (hd.mtime, NULL, 8); #endif return GRUB_ERR_NONE; } @@ -204,7 +208,9 @@ grub_cpio_dir (grub_device_t device, const char *path, data->hofs = 0; while (1) { - if (grub_cpio_find_file (data, &name, &ofs)) + grub_int32_t mtime; + + if (grub_cpio_find_file (data, &name, &mtime, &ofs)) goto fail; if (!ofs) @@ -227,6 +233,8 @@ grub_cpio_dir (grub_device_t device, const char *path, struct grub_dirhook_info info; grub_memset (&info, 0, sizeof (info)); info.dir = (p != NULL); + info.mtime = mtime; + info.mtimeset = 1; hook (name + len, &info); if (prev) @@ -269,7 +277,7 @@ grub_cpio_open (grub_file_t file, const char *name) data->hofs = 0; while (1) { - if (grub_cpio_find_file (data, &fn, &ofs)) + if (grub_cpio_find_file (data, &fn, NULL, &ofs)) goto fail; if (!ofs) From a2de6bf6ed9b2e3e4dcc9347f6d780608e11e95c Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 10 Dec 2010 10:32:50 +0100 Subject: [PATCH 079/869] filesystem mtime support for iso9660 --- grub-core/fs/iso9660.c | 130 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 130 insertions(+) diff --git a/grub-core/fs/iso9660.c b/grub-core/fs/iso9660.c index 6dc465f25..96753ac69 100644 --- a/grub-core/fs/iso9660.c +++ b/grub-core/fs/iso9660.c @@ -27,6 +27,7 @@ #include #include #include +#include #define GRUB_ISO9660_FSTYPE_DIR 0040000 #define GRUB_ISO9660_FSTYPE_REG 0100000 @@ -153,6 +154,108 @@ struct grub_fshelp_node static grub_dl_t my_mod; +#define SECPERMIN 60 +#define SECPERHOUR (60*SECPERMIN) +#define SECPERDAY (24*SECPERHOUR) +#define SECPERYEAR (365*SECPERDAY) +#define SECPER4YEARS (4*SECPERYEAR+SECPERDAY) + +static grub_err_t +grub_datetime2unixtime (const struct grub_datetime *datetime, grub_int32_t *nix) +{ + grub_int32_t ret; + int y4, ay; + grub_uint16_t monthssum[12] + = { 0, + 31, + 31 + 28, + 31 + 28 + 31, + 31 + 28 + 31 + 30, + 31 + 28 + 31 + 30 + 31, + 31 + 28 + 31 + 30 + 31 + 30, + 31 + 28 + 31 + 30 + 31 + 30 + 31, + 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31, + 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30, + 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31, + 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30}; + grub_uint8_t months[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; + + if (datetime->year > 2038 || datetime->year < 1902) + return grub_error (GRUB_ERR_OUT_OF_RANGE, "outside of UNIX epoch"); + if (datetime->month > 12 || datetime->month < 1) + return grub_error (GRUB_ERR_BAD_NUMBER, "not a valid month"); + + /* In the period of validity of unixtime all years divisible by 4 + are bissextile*/ + /* Convenience: let's have 3 consecutive non-bissextile years + at the beginning of the epoch. So count from 1973 instead of 1970 */ + ret = 3*SECPERYEAR + SECPERDAY; + + /* Transform C divisions and modulos to mathematical ones */ + y4 = (datetime->year - 1973) / 4; + if (datetime->year < 1973) + y4--; + ay = datetime->year - 1973 - 4 * y4; + ret += y4 * SECPER4YEARS; + ret += ay * SECPERYEAR; + + ret += monthssum[datetime->month - 1] * SECPERDAY; + if (ay == 0 && datetime->month >= 3) + ret += SECPERDAY; + + ret += (datetime->day - 1) * SECPERDAY; + if ((datetime->day > months[datetime->month - 1] + && (!ay || datetime->month != 2 || datetime->day != 29)) + || datetime->day < 1) + return grub_error (GRUB_ERR_BAD_NUMBER, "invalid day"); + + ret += datetime->hour * SECPERHOUR; + if (datetime->hour > 23) + return grub_error (GRUB_ERR_BAD_NUMBER, "invalid hour"); + ret += datetime->minute * 60; + if (datetime->minute > 59) + return grub_error (GRUB_ERR_BAD_NUMBER, "invalid minute"); + + ret += datetime->second; + /* Accept leap seconds. */ + if (datetime->second > 60) + return grub_error (GRUB_ERR_BAD_NUMBER, "invalid second"); + + if ((datetime->year > 1980 && ret < 0) + || (datetime->year < 1960 && ret > 0)) + return grub_error (GRUB_ERR_OUT_OF_RANGE, "outside of UNIX epoch"); + *nix = ret; + return GRUB_ERR_NONE; +} + +static grub_err_t +iso9660_to_unixtime (const struct grub_iso9660_date *i, grub_int32_t *nix) +{ + grub_err_t err; + struct grub_datetime datetime; + + if (! i->year[0] && ! i->year[1] + && ! i->year[2] && ! i->year[3] + && ! i->month[0] && ! i->month[1] + && ! i->day[0] && ! i->day[1] + && ! i->hour[0] && ! i->hour[1] + && ! i->minute[0] && ! i->minute[1] + && ! i->second[0] && ! i->second[1] + && ! i->hundredth[0] && ! i->hundredth[1]) + return grub_error (GRUB_ERR_BAD_NUMBER, "empty date"); + datetime.year = (i->year[0] - '0') * 1000 + (i->year[1] - '0') * 100 + + (i->year[2] - '0') * 10 + (i->year[3] - '0'); + datetime.month = (i->month[0] - '0') * 10 + (i->month[1] - '0'); + datetime.day = (i->day[0] - '0') * 10 + (i->day[1] - '0'); + datetime.hour = (i->hour[0] - '0') * 10 + (i->hour[1] - '0'); + datetime.minute = (i->minute[0] - '0') * 10 + (i->minute[1] - '0'); + datetime.second = (i->second[0] - '0') * 10 + (i->second[1] - '0'); + + err = grub_datetime2unixtime (&datetime, nix); + *nix -= i->offset * 60 * 15; + return err; +} + /* Iterate over the susp entries, starting with block SUA_BLOCK on the offset SUA_POS with a size of SUA_SIZE bytes. Hook is called for every entry. */ @@ -871,6 +974,32 @@ grub_iso9660_uuid (grub_device_t device, char **uuid) return grub_errno; } +/* Get writing time of filesystem. */ +static grub_err_t +grub_iso9660_mtime (grub_device_t device, grub_int32_t *timebuf) +{ + struct grub_iso9660_data *data; + grub_disk_t disk = device->disk; + grub_err_t err; + + grub_dl_ref (my_mod); + + data = grub_iso9660_mount (disk); + if (!data) + { + grub_dl_unref (my_mod); + return grub_errno; + } + err = iso9660_to_unixtime (&data->voldesc.modified, timebuf); + + grub_dl_unref (my_mod); + + grub_free (data); + + return err; +} + + static struct grub_fs grub_iso9660_fs = @@ -882,6 +1011,7 @@ static struct grub_fs grub_iso9660_fs = .close = grub_iso9660_close, .label = grub_iso9660_label, .uuid = grub_iso9660_uuid, + .mtime = grub_iso9660_mtime, .next = 0 }; From c50d99c5e531a6a7cedebd6de51d98fcfda5f694 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 10 Dec 2010 11:12:59 +0100 Subject: [PATCH 080/869] file mtime support for iso9660 --- grub-core/fs/iso9660.c | 60 +++++++++++++++++++++++++++++++++--------- 1 file changed, 47 insertions(+), 13 deletions(-) diff --git a/grub-core/fs/iso9660.c b/grub-core/fs/iso9660.c index 96753ac69..03bfd3e92 100644 --- a/grub-core/fs/iso9660.c +++ b/grub-core/fs/iso9660.c @@ -54,6 +54,17 @@ struct grub_iso9660_voldesc grub_uint8_t version; } __attribute__ ((packed)); +struct grub_iso9660_date2 +{ + grub_uint8_t year; + grub_uint8_t month; + grub_uint8_t day; + grub_uint8_t hour; + grub_uint8_t minute; + grub_uint8_t second; + grub_uint8_t offset; +} __attribute__ ((packed)); + /* A directory entry. */ struct grub_iso9660_dir { @@ -63,7 +74,7 @@ struct grub_iso9660_dir grub_uint32_t first_sector_be; grub_uint32_t size; grub_uint32_t size_be; - grub_uint8_t unused1[7]; + struct grub_iso9660_date2 mtime; grub_uint8_t flags; grub_uint8_t unused2[6]; grub_uint8_t namelen; @@ -145,6 +156,7 @@ struct grub_iso9660_data struct grub_fshelp_node { struct grub_iso9660_data *data; + struct grub_iso9660_dir dirent; unsigned int size; unsigned int blk; unsigned int dir_blk; @@ -188,14 +200,14 @@ grub_datetime2unixtime (const struct grub_datetime *datetime, grub_int32_t *nix) /* In the period of validity of unixtime all years divisible by 4 are bissextile*/ /* Convenience: let's have 3 consecutive non-bissextile years - at the beginning of the epoch. So count from 1973 instead of 1970 */ - ret = 3*SECPERYEAR + SECPERDAY; + at the beginning of the epoch. So count from 1971 instead of 1970 */ + ret = SECPERYEAR + SECPERDAY; /* Transform C divisions and modulos to mathematical ones */ - y4 = (datetime->year - 1973) / 4; - if (datetime->year < 1973) + y4 = (datetime->year - 1971) / 4; + if (datetime->year < 1971) y4--; - ay = datetime->year - 1973 - 4 * y4; + ay = datetime->year - 1971 - 4 * y4; ret += y4 * SECPER4YEARS; ret += ay * SECPERYEAR; @@ -256,6 +268,24 @@ iso9660_to_unixtime (const struct grub_iso9660_date *i, grub_int32_t *nix) return err; } +static grub_err_t +iso9660_to_unixtime2 (const struct grub_iso9660_date2 *i, grub_int32_t *nix) +{ + grub_err_t err; + struct grub_datetime datetime; + + datetime.year = i->year + 1900; + datetime.month = i->month; + datetime.day = i->day; + datetime.hour = i->hour; + datetime.minute = i->minute; + datetime.second = i->second; + + err = grub_datetime2unixtime (&datetime, nix); + *nix -= i->offset * 60 * 15; + return err; +} + /* Iterate over the susp entries, starting with block SUA_BLOCK on the offset SUA_POS with a size of SUA_SIZE bytes. Hook is called for every entry. */ @@ -467,7 +497,6 @@ grub_iso9660_mount (grub_disk_t disk) static char * grub_iso9660_read_symlink (grub_fshelp_node_t node) { - struct grub_iso9660_dir dirent; int sua_off; int sua_size; char *symlink = 0; @@ -545,13 +574,10 @@ grub_iso9660_read_symlink (grub_fshelp_node_t node) return 0; } - if (grub_disk_read (node->data->disk, node->dir_blk, node->dir_off, - sizeof (dirent), (char *) &dirent)) - return 0; - - sua_off = (sizeof (dirent) + dirent.namelen + 1 - (dirent.namelen % 2) + sua_off = (sizeof (node->dirent) + node->dirent.namelen + 1 + - (node->dirent.namelen % 2) + node->data->susp_skip); - sua_size = dirent.len - sua_off; + sua_size = node->dirent.len - sua_off; symlink = grub_malloc (1); if (!symlink) @@ -748,6 +774,7 @@ grub_iso9660_iterate_dir (grub_fshelp_node_t dir, filename_alloc = 1; } + node->dirent = dirent; if (hook (filename, type, node)) { if (filename_alloc) @@ -784,8 +811,15 @@ grub_iso9660_dir (grub_device_t device, const char *path, grub_fshelp_node_t node) { struct grub_dirhook_info info; + grub_err_t err; grub_memset (&info, 0, sizeof (info)); info.dir = ((filetype & GRUB_FSHELP_TYPE_MASK) == GRUB_FSHELP_DIR); + err = iso9660_to_unixtime2 (&node->dirent.mtime, &info.mtime); + if (err) + grub_errno = GRUB_ERR_NONE; + else + info.mtimeset = 1; + grub_free (node); return hook (filename, &info); } From 1fb430f865f2c4b367ddce5c45cc1b2f3eaecd34 Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Fri, 10 Dec 2010 11:45:08 +0000 Subject: [PATCH 081/869] * grub-core/gettext/gettext.c (grub_gettext_init_ext): Factor out .mo/.mo.gz opening sequence to ... (grub_mofile_open_lang): ... here. (grub_gettext_init_ext): If opening ll_CC fails, try ll. * util/grub.d/00_header.in (grub_lang): Include country part of locale. Reported by: Mario Limonciello. --- ChangeLog | 10 ++++++++ grub-core/gettext/gettext.c | 48 +++++++++++++++++++++++++++---------- util/grub.d/00_header.in | 2 +- 3 files changed, 47 insertions(+), 13 deletions(-) diff --git a/ChangeLog b/ChangeLog index f215398cc..e8ac26e83 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2010-12-10 Colin Watson + + * grub-core/gettext/gettext.c (grub_gettext_init_ext): Factor out + .mo/.mo.gz opening sequence to ... + (grub_mofile_open_lang): ... here. + (grub_gettext_init_ext): If opening ll_CC fails, try ll. + * util/grub.d/00_header.in (grub_lang): Include country part of + locale. + Reported by: Mario Limonciello. + 2010-12-09 Robert Millan * NEWS: Document addition of ZFS support. diff --git a/grub-core/gettext/gettext.c b/grub-core/gettext/gettext.c index 9ab4c3b8d..5c7db4408 100644 --- a/grub-core/gettext/gettext.c +++ b/grub-core/gettext/gettext.c @@ -261,24 +261,16 @@ grub_mofile_open (const char *filename) return fd_mo; } +/* Returning grub_file_t would be more natural, but grub_mofile_open assigns + to fd_mo anyway ... */ static void -grub_gettext_init_ext (const char *lang) +grub_mofile_open_lang (const char *locale_dir, const char *locale) { char *mo_file; - char *locale_dir; - - locale_dir = grub_env_get ("locale_dir"); - if (locale_dir == NULL) - { - grub_dprintf ("gettext", "locale_dir variable is not set up.\n"); - return; - } - - fd_mo = NULL; /* mo_file e.g.: /boot/grub/locale/ca.mo */ - mo_file = grub_xasprintf ("%s/%s.mo", locale_dir, lang); + mo_file = grub_xasprintf ("%s/%s.mo", locale_dir, locale); if (!mo_file) return; @@ -295,6 +287,38 @@ grub_gettext_init_ext (const char *lang) return; fd_mo = grub_mofile_open (mo_file); } +} + +static void +grub_gettext_init_ext (const char *locale) +{ + char *locale_dir; + + locale_dir = grub_env_get ("locale_dir"); + if (locale_dir == NULL) + { + grub_dprintf ("gettext", "locale_dir variable is not set up.\n"); + return; + } + + fd_mo = NULL; + + grub_mofile_open_lang (locale_dir, locale); + + /* ll_CC didn't work, so try ll. */ + if (fd_mo == NULL) + { + char *lang = grub_strdup (locale); + char *underscore = grub_strchr (lang, '_'); + + if (underscore) + { + *underscore = '\0'; + grub_mofile_open_lang (locale_dir, lang); + } + + grub_free (lang); + } if (fd_mo) { diff --git a/util/grub.d/00_header.in b/util/grub.d/00_header.in index 9ed3fc3a1..a596e9c4a 100644 --- a/util/grub.d/00_header.in +++ b/util/grub.d/00_header.in @@ -23,7 +23,7 @@ prefix=@prefix@ exec_prefix=@exec_prefix@ libdir=@libdir@ locale_dir=`echo ${GRUB_PREFIX}/locale | sed ${transform}` -grub_lang=`echo $LANG | cut -d _ -f 1` +grub_lang=`echo $LANG | cut -d . -f 1` . ${libdir}/grub/grub-mkconfig_lib From 5367ecd3050ebbc8e732b687303f5afc86ac3c62 Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Fri, 10 Dec 2010 12:56:45 +0000 Subject: [PATCH 082/869] * .bzrignore: Ignore grub-core/rs_decoder.S. --- .bzrignore | 1 + ChangeLog | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/.bzrignore b/.bzrignore index 7c5597bce..0cbb3f17f 100644 --- a/.bzrignore +++ b/.bzrignore @@ -131,5 +131,6 @@ grub-core/gnulib/unistd.h grub-core/gnulib/warn-on-use.h grub-core/gnulib/wchar.h grub-core/gnulib/wctype.h +grub-core/rs_decoder.S widthspec.bin widthspec.h diff --git a/ChangeLog b/ChangeLog index e8ac26e83..abd1d0400 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2010-12-10 Colin Watson + + * .bzrignore: Ignore grub-core/rs_decoder.S. + 2010-12-10 Colin Watson * grub-core/gettext/gettext.c (grub_gettext_init_ext): Factor out From d6f07b29fca3f555b22000fde18577a45bd42b39 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 10 Dec 2010 14:38:16 +0100 Subject: [PATCH 083/869] mtime btrfs support --- grub-core/fs/btrfs.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/grub-core/fs/btrfs.c b/grub-core/fs/btrfs.c index b7edb7e39..b7c59065c 100644 --- a/grub-core/fs/btrfs.c +++ b/grub-core/fs/btrfs.c @@ -172,10 +172,18 @@ struct grub_btrfs_root_item grub_uint64_t inode; }; +struct grub_btrfs_time +{ + grub_int64_t sec; + grub_uint32_t nanosec; +} __attribute__ ((aligned(4))); + struct grub_btrfs_inode { - grub_uint8_t dummy[0x10]; + grub_uint8_t dummy1[0x10]; grub_uint64_t size; + grub_uint8_t dummy2[0x70]; + struct grub_btrfs_time mtime; } __attribute__ ((packed)); struct grub_btrfs_extent_data @@ -1263,7 +1271,6 @@ grub_btrfs_dir (grub_device_t device, const char *path, } do { - struct grub_dirhook_info info; struct grub_btrfs_dir_item *cdirel; if (key_out.type != GRUB_BTRFS_ITEM_TYPE_DIR_ITEM || key_out.object_id != key_in.object_id) @@ -1295,9 +1302,20 @@ grub_btrfs_dir (grub_device_t device, const char *path, + grub_le_to_cpu16 (cdirel->m))) { char c; + struct grub_btrfs_inode inode; + struct grub_dirhook_info info; + err = grub_btrfs_read_inode (data, &inode, cdirel->key.object_id, + tree); + grub_memset (&info, 0, sizeof (info)); + if (err) + grub_errno = GRUB_ERR_NONE; + else + { + info.mtime = inode.mtime.sec; + info.mtimeset = 1; + } c = cdirel->name[grub_le_to_cpu16 (cdirel->n)]; cdirel->name[grub_le_to_cpu16 (cdirel->n)] = 0; - grub_memset (&info, 0, sizeof (info)); info.dir = (cdirel->type == GRUB_BTRFS_DIR_ITEM_TYPE_DIRECTORY); if (hook (cdirel->name, &info)) goto out; From 3b95531920bdd3bd96706ef6fb01ee6a0cfab8f1 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 10 Dec 2010 15:04:12 +0100 Subject: [PATCH 084/869] fix unix range --- grub-core/fs/iso9660.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/grub-core/fs/iso9660.c b/grub-core/fs/iso9660.c index 03bfd3e92..3b0da5e53 100644 --- a/grub-core/fs/iso9660.c +++ b/grub-core/fs/iso9660.c @@ -192,7 +192,7 @@ grub_datetime2unixtime (const struct grub_datetime *datetime, grub_int32_t *nix) 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30}; grub_uint8_t months[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; - if (datetime->year > 2038 || datetime->year < 1902) + if (datetime->year > 2038 || datetime->year < 1901) return grub_error (GRUB_ERR_OUT_OF_RANGE, "outside of UNIX epoch"); if (datetime->month > 12 || datetime->month < 1) return grub_error (GRUB_ERR_BAD_NUMBER, "not a valid month"); From 5706da04438db67180e6b08a3f62aa4ba0b58b75 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 10 Dec 2010 16:19:24 +0100 Subject: [PATCH 085/869] mtime support for xfs --- grub-core/fs/xfs.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/grub-core/fs/xfs.c b/grub-core/fs/xfs.c index 9dffe31d1..966bade1b 100644 --- a/grub-core/fs/xfs.c +++ b/grub-core/fs/xfs.c @@ -98,13 +98,22 @@ struct grub_xfs_btree_root grub_uint64_t keys[1]; } __attribute__ ((packed)); +struct grub_xfs_time +{ + grub_uint32_t sec; + grub_uint32_t nanosec; +} __attribute__ ((packed)); + struct grub_xfs_inode { grub_uint8_t magic[2]; grub_uint16_t mode; grub_uint8_t version; grub_uint8_t format; - grub_uint8_t unused2[50]; + grub_uint8_t unused2[26]; + struct grub_xfs_time atime; + struct grub_xfs_time mtime; + struct grub_xfs_time ctime; grub_uint64_t size; grub_uint64_t nblocks; grub_uint32_t extsize; @@ -643,6 +652,11 @@ grub_xfs_dir (grub_device_t device, const char *path, { struct grub_dirhook_info info; grub_memset (&info, 0, sizeof (info)); + if (node->inode_read) + { + info.mtimeset = 1; + info.mtime = grub_be_to_cpu32 (node->inode.mtime.sec); + } info.dir = ((filetype & GRUB_FSHELP_TYPE_MASK) == GRUB_FSHELP_DIR); grub_free (node); return hook (filename, &info); From f22c12e8524f69b3482f6965d8d9b3480b8a9588 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 10 Dec 2010 17:37:32 +0100 Subject: [PATCH 086/869] mtime for UDF support --- grub-core/fs/iso9660.c | 97 ++++------------------------------------- grub-core/fs/udf.c | 29 ++++++++++++ include/grub/datetime.h | 73 +++++++++++++++++++++++++++++++ 3 files changed, 111 insertions(+), 88 deletions(-) diff --git a/grub-core/fs/iso9660.c b/grub-core/fs/iso9660.c index 3b0da5e53..f2f4b5a97 100644 --- a/grub-core/fs/iso9660.c +++ b/grub-core/fs/iso9660.c @@ -166,84 +166,9 @@ struct grub_fshelp_node static grub_dl_t my_mod; -#define SECPERMIN 60 -#define SECPERHOUR (60*SECPERMIN) -#define SECPERDAY (24*SECPERHOUR) -#define SECPERYEAR (365*SECPERDAY) -#define SECPER4YEARS (4*SECPERYEAR+SECPERDAY) - -static grub_err_t -grub_datetime2unixtime (const struct grub_datetime *datetime, grub_int32_t *nix) -{ - grub_int32_t ret; - int y4, ay; - grub_uint16_t monthssum[12] - = { 0, - 31, - 31 + 28, - 31 + 28 + 31, - 31 + 28 + 31 + 30, - 31 + 28 + 31 + 30 + 31, - 31 + 28 + 31 + 30 + 31 + 30, - 31 + 28 + 31 + 30 + 31 + 30 + 31, - 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31, - 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30, - 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31, - 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30}; - grub_uint8_t months[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; - - if (datetime->year > 2038 || datetime->year < 1901) - return grub_error (GRUB_ERR_OUT_OF_RANGE, "outside of UNIX epoch"); - if (datetime->month > 12 || datetime->month < 1) - return grub_error (GRUB_ERR_BAD_NUMBER, "not a valid month"); - - /* In the period of validity of unixtime all years divisible by 4 - are bissextile*/ - /* Convenience: let's have 3 consecutive non-bissextile years - at the beginning of the epoch. So count from 1971 instead of 1970 */ - ret = SECPERYEAR + SECPERDAY; - - /* Transform C divisions and modulos to mathematical ones */ - y4 = (datetime->year - 1971) / 4; - if (datetime->year < 1971) - y4--; - ay = datetime->year - 1971 - 4 * y4; - ret += y4 * SECPER4YEARS; - ret += ay * SECPERYEAR; - - ret += monthssum[datetime->month - 1] * SECPERDAY; - if (ay == 0 && datetime->month >= 3) - ret += SECPERDAY; - - ret += (datetime->day - 1) * SECPERDAY; - if ((datetime->day > months[datetime->month - 1] - && (!ay || datetime->month != 2 || datetime->day != 29)) - || datetime->day < 1) - return grub_error (GRUB_ERR_BAD_NUMBER, "invalid day"); - - ret += datetime->hour * SECPERHOUR; - if (datetime->hour > 23) - return grub_error (GRUB_ERR_BAD_NUMBER, "invalid hour"); - ret += datetime->minute * 60; - if (datetime->minute > 59) - return grub_error (GRUB_ERR_BAD_NUMBER, "invalid minute"); - - ret += datetime->second; - /* Accept leap seconds. */ - if (datetime->second > 60) - return grub_error (GRUB_ERR_BAD_NUMBER, "invalid second"); - - if ((datetime->year > 1980 && ret < 0) - || (datetime->year < 1960 && ret > 0)) - return grub_error (GRUB_ERR_OUT_OF_RANGE, "outside of UNIX epoch"); - *nix = ret; - return GRUB_ERR_NONE; -} - static grub_err_t iso9660_to_unixtime (const struct grub_iso9660_date *i, grub_int32_t *nix) { - grub_err_t err; struct grub_datetime datetime; if (! i->year[0] && ! i->year[1] @@ -263,17 +188,17 @@ iso9660_to_unixtime (const struct grub_iso9660_date *i, grub_int32_t *nix) datetime.minute = (i->minute[0] - '0') * 10 + (i->minute[1] - '0'); datetime.second = (i->second[0] - '0') * 10 + (i->second[1] - '0'); - err = grub_datetime2unixtime (&datetime, nix); + if (!grub_datetime2unixtime (&datetime, nix)) + return grub_error (GRUB_ERR_BAD_NUMBER, "incorrect date"); *nix -= i->offset * 60 * 15; - return err; + return GRUB_ERR_NONE; } -static grub_err_t +static int iso9660_to_unixtime2 (const struct grub_iso9660_date2 *i, grub_int32_t *nix) { - grub_err_t err; struct grub_datetime datetime; - + datetime.year = i->year + 1900; datetime.month = i->month; datetime.day = i->day; @@ -281,9 +206,10 @@ iso9660_to_unixtime2 (const struct grub_iso9660_date2 *i, grub_int32_t *nix) datetime.minute = i->minute; datetime.second = i->second; - err = grub_datetime2unixtime (&datetime, nix); + if (!grub_datetime2unixtime (&datetime, nix)) + return 0; *nix -= i->offset * 60 * 15; - return err; + return 1; } /* Iterate over the susp entries, starting with block SUA_BLOCK on the @@ -811,14 +737,9 @@ grub_iso9660_dir (grub_device_t device, const char *path, grub_fshelp_node_t node) { struct grub_dirhook_info info; - grub_err_t err; grub_memset (&info, 0, sizeof (info)); info.dir = ((filetype & GRUB_FSHELP_TYPE_MASK) == GRUB_FSHELP_DIR); - err = iso9660_to_unixtime2 (&node->dirent.mtime, &info.mtime); - if (err) - grub_errno = GRUB_ERR_NONE; - else - info.mtimeset = 1; + info.mtimeset = !!iso9660_to_unixtime2 (&node->dirent.mtime, &info.mtime); grub_free (node); return hook (filename, &info); diff --git a/grub-core/fs/udf.c b/grub-core/fs/udf.c index 7041e619e..0c5da996e 100644 --- a/grub-core/fs/udf.c +++ b/grub-core/fs/udf.c @@ -26,6 +26,7 @@ #include #include #include +#include #define GRUB_UDF_MAX_PDS 2 #define GRUB_UDF_MAX_PMS 6 @@ -904,8 +905,36 @@ grub_udf_dir (grub_device_t device, const char *path, grub_fshelp_node_t node) { struct grub_dirhook_info info; + const struct grub_udf_timestamp *tstamp = NULL; grub_memset (&info, 0, sizeof (info)); info.dir = ((filetype & GRUB_FSHELP_TYPE_MASK) == GRUB_FSHELP_DIR); + if (U16 (node->fe.tag.tag_ident) == GRUB_UDF_TAG_IDENT_FE) + tstamp = &node->fe.modification_time; + else if (U16 (node->fe.tag.tag_ident) == GRUB_UDF_TAG_IDENT_EFE) + tstamp = &node->efe.modification_time; + + if (tstamp && (U16 (tstamp->type_and_timezone) & 0xf000) == 0x1000) + { + grub_int16_t tz; + struct grub_datetime datetime; + + datetime.year = U16 (tstamp->year); + datetime.month = tstamp->month; + datetime.day = tstamp->day; + datetime.hour = tstamp->hour; + datetime.minute = tstamp->minute; + datetime.second = tstamp->second; + + tz = U16 (tstamp->type_and_timezone) & 0xfff; + if (tz & 0x800) + tz |= 0xf000; + if (tz == -2047) + tz = 0; + + info.mtimeset = !!grub_datetime2unixtime (&datetime, &info.mtime); + + info.mtime -= 60 * tz; + } grub_free (node); return hook (filename, &info); } diff --git a/include/grub/datetime.h b/include/grub/datetime.h index e721e89af..c20fc8c36 100644 --- a/include/grub/datetime.h +++ b/include/grub/datetime.h @@ -51,5 +51,78 @@ char *grub_get_weekday_name (struct grub_datetime *datetime); void grub_unixtime2datetime (grub_int32_t nix, struct grub_datetime *datetime); +static inline int +grub_datetime2unixtime (const struct grub_datetime *datetime, grub_int32_t *nix) +{ + grub_int32_t ret; + int y4, ay; + const grub_uint16_t monthssum[12] + = { 0, + 31, + 31 + 28, + 31 + 28 + 31, + 31 + 28 + 31 + 30, + 31 + 28 + 31 + 30 + 31, + 31 + 28 + 31 + 30 + 31 + 30, + 31 + 28 + 31 + 30 + 31 + 30 + 31, + 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31, + 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30, + 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31, + 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30}; + const grub_uint8_t months[12] = {31, 28, 31, 30, 31, 30, + 31, 31, 30, 31, 30, 31}; + const int SECPERMIN = 60; + const int SECPERHOUR = 60 * SECPERMIN; + const int SECPERDAY = 24 * SECPERHOUR; + const int SECPERYEAR = 365 * SECPERDAY; + const int SECPER4YEARS = 4 * SECPERYEAR + SECPERDAY; + + if (datetime->year > 2038 || datetime->year < 1901) + return 0; + if (datetime->month > 12 || datetime->month < 1) + return 0; + + /* In the period of validity of unixtime all years divisible by 4 + are bissextile*/ + /* Convenience: let's have 3 consecutive non-bissextile years + at the beginning of the epoch. So count from 1971 instead of 1970 */ + ret = SECPERYEAR + SECPERDAY; + + /* Transform C divisions and modulos to mathematical ones */ + y4 = (datetime->year - 1971) / 4; + if (datetime->year < 1971) + y4--; + ay = datetime->year - 1971 - 4 * y4; + ret += y4 * SECPER4YEARS; + ret += ay * SECPERYEAR; + + ret += monthssum[datetime->month - 1] * SECPERDAY; + if (ay == 0 && datetime->month >= 3) + ret += SECPERDAY; + + ret += (datetime->day - 1) * SECPERDAY; + if ((datetime->day > months[datetime->month - 1] + && (!ay || datetime->month != 2 || datetime->day != 29)) + || datetime->day < 1) + return 0; + + ret += datetime->hour * SECPERHOUR; + if (datetime->hour > 23) + return 0; + ret += datetime->minute * 60; + if (datetime->minute > 59) + return 0; + + ret += datetime->second; + /* Accept leap seconds. */ + if (datetime->second > 60) + return 0; + + if ((datetime->year > 1980 && ret < 0) + || (datetime->year < 1960 && ret > 0)) + return 0; + *nix = ret; + return 1; +} #endif /* ! KERNEL_DATETIME_HEADER */ From 52832c554c3f4393819ad8fc67a92efc85fc8562 Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Fri, 10 Dec 2010 16:45:58 +0000 Subject: [PATCH 087/869] Move gfxmenu color handling to video, so that gfxterm can use it too. * grub-core/gfxmenu/named_colors.c: Move to ... * grub-core/video/colors.c: ... here. Rename grub_gui_get_named_color to grub_video_get_named_color. * grub-core/gfxmenu/gui_string_util.c (my_isxdigit): Move to ... * grub-core/video/colors.c (my_isxdigit): ... here. * grub-core/gfxmenu/gui_string_util.c (parse_hex_color_component): Move to ... * grub-core/video/colors.c (parse_hex_color_component): ... here. * grub-core/gfxmenu/gui_string_util.c (grub_gui_parse_color): Move to ... * grub-core/video/colors.c (grub_video_parse_color): ... here. * include/grub/gui.h (grub_gui_color_t): Move to ... * include/grub/video.h (grub_video_rgba_color_t): ... here. * include/grub/gui.h (grub_gui_color_rgb): Move to ... * include/grub/video.h (grub_video_rgba_color_rgb): ... here. * include/grub/gui.h (grub_gui_map_color): Move to ... * include/grub/video.h (grub_video_map_rgba_color): ... here. * include/grub/gui_string_util.h (grub_gui_get_named_color): Move to ... * include/grub/video.h (grub_video_get_named_color): ... here. * include/grub/gui_string_util.h (grub_gui_parse_color): Move to ... * include/grub/video.h (grub_video_parse_color): ... here. * grub-core/Makefile.core.def (kernel) [videoinkernel]: Add video/colors.c. (gfxmenu): Remove gfxmenu/named_colors.c. (video_colors) [videomodules]: New module, containing video/colors.c. --- ChangeLog.parse-color | 34 +++++ grub-core/Makefile.core.def | 8 +- grub-core/gfxmenu/gui_label.c | 6 +- grub-core/gfxmenu/gui_list.c | 16 +-- grub-core/gfxmenu/gui_progress_bar.c | 31 ++--- grub-core/gfxmenu/gui_string_util.c | 121 ----------------- grub-core/gfxmenu/theme_loader.c | 8 +- grub-core/gfxmenu/view.c | 16 +-- .../named_colors.c => video/colors.c} | 127 +++++++++++++++++- include/grub/gfxmenu_view.h | 8 +- include/grub/gui.h | 27 ---- include/grub/gui_string_util.h | 4 - include/grub/video.h | 32 +++++ 13 files changed, 240 insertions(+), 198 deletions(-) create mode 100644 ChangeLog.parse-color rename grub-core/{gfxmenu/named_colors.c => video/colors.c} (70%) diff --git a/ChangeLog.parse-color b/ChangeLog.parse-color new file mode 100644 index 000000000..93d696c6c --- /dev/null +++ b/ChangeLog.parse-color @@ -0,0 +1,34 @@ +2010-12-10 Colin Watson + + Move gfxmenu color handling to video, so that gfxterm can use it + too. + + * grub-core/gfxmenu/named_colors.c: Move to ... + * grub-core/video/colors.c: ... here. Rename + grub_gui_get_named_color to grub_video_get_named_color. + * grub-core/gfxmenu/gui_string_util.c (my_isxdigit): Move to ... + * grub-core/video/colors.c (my_isxdigit): ... here. + * grub-core/gfxmenu/gui_string_util.c (parse_hex_color_component): + Move to ... + * grub-core/video/colors.c (parse_hex_color_component): ... here. + * grub-core/gfxmenu/gui_string_util.c (grub_gui_parse_color): Move + to ... + * grub-core/video/colors.c (grub_video_parse_color): ... here. + + * include/grub/gui.h (grub_gui_color_t): Move to ... + * include/grub/video.h (grub_video_rgba_color_t): ... here. + * include/grub/gui.h (grub_gui_color_rgb): Move to ... + * include/grub/video.h (grub_video_rgba_color_rgb): ... here. + * include/grub/gui.h (grub_gui_map_color): Move to ... + * include/grub/video.h (grub_video_map_rgba_color): ... here. + * include/grub/gui_string_util.h (grub_gui_get_named_color): Move + to ... + * include/grub/video.h (grub_video_get_named_color): ... here. + * include/grub/gui_string_util.h (grub_gui_parse_color): Move to ... + * include/grub/video.h (grub_video_parse_color): ... here. + + * grub-core/Makefile.core.def (kernel) [videoinkernel]: Add + video/colors.c. + (gfxmenu): Remove gfxmenu/named_colors.c. + (video_colors) [videomodules]: New module, containing + video/colors.c. diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def index 37c0ce970..fdf7d0826 100644 --- a/grub-core/Makefile.core.def +++ b/grub-core/Makefile.core.def @@ -178,6 +178,7 @@ kernel = { videoinkernel = io/bufio.c; videoinkernel = video/bitmap.c; videoinkernel = video/bitmap_scale.c; + videoinkernel = video/colors.c; videoinkernel = video/fb/fbblit.c; videoinkernel = video/fb/fbfill.c; videoinkernel = video/fb/fbutil.c; @@ -1049,7 +1050,6 @@ module = { common = gfxmenu/gui_progress_bar.c; common = gfxmenu/gui_util.c; common = gfxmenu/gui_string_util.c; - common = gfxmenu/named_colors.c; }; module = { @@ -1442,6 +1442,12 @@ module = { enable = i386_pc; }; +module = { + name = video_colors; + common = video/colors.c; + enable = videomodules; +}; + module = { name = video_fb; common = video/fb/video_fb.c; diff --git a/grub-core/gfxmenu/gui_label.c b/grub-core/gfxmenu/gui_label.c index 15a352f84..a7dc95afc 100644 --- a/grub-core/gfxmenu/gui_label.c +++ b/grub-core/gfxmenu/gui_label.c @@ -48,7 +48,7 @@ struct grub_gui_label char *text; char *template; grub_font_t font; - grub_gui_color_t color; + grub_video_rgba_color_t color; int value; enum align_mode align; }; @@ -107,7 +107,7 @@ label_paint (void *vself, const grub_video_rect_t *region) grub_gui_set_viewport (&self->bounds, &vpsave); grub_font_draw_string (self->text, self->font, - grub_gui_map_color (self->color), + grub_video_map_rgba_color (self->color), left_x, grub_font_get_ascent (self->font)); grub_gui_restore_viewport (&vpsave); @@ -186,7 +186,7 @@ label_set_property (void *vself, const char *name, const char *value) } else if (grub_strcmp (name, "color") == 0) { - grub_gui_parse_color (value, &self->color); + grub_video_parse_color (value, &self->color); } else if (grub_strcmp (name, "align") == 0) { diff --git a/grub-core/gfxmenu/gui_list.c b/grub-core/gfxmenu/gui_list.c index b6b07dfd6..ca2061795 100644 --- a/grub-core/gfxmenu/gui_list.c +++ b/grub-core/gfxmenu/gui_list.c @@ -41,9 +41,9 @@ struct grub_gui_list_impl int item_spacing; grub_font_t item_font; grub_font_t selected_item_font; - grub_gui_color_t item_color; + grub_video_rgba_color_t item_color; int selected_item_color_set; - grub_gui_color_t selected_item_color; + grub_video_rgba_color_t selected_item_color; int draw_scrollbar; int need_to_recreate_scrollbar; @@ -267,13 +267,13 @@ draw_menu (list_impl_t self, int num_shown_items) (is_selected && self->selected_item_font ? self->selected_item_font : self->item_font); - grub_gui_color_t text_color = + grub_video_rgba_color_t text_color = ((is_selected && self->selected_item_color_set) ? self->selected_item_color : self->item_color); grub_font_draw_string (item_title, font, - grub_gui_map_color (text_color), + grub_video_map_rgba_color (text_color), sel_leftpad + self->icon_width + icon_text_space, (item_top + (item_height - (ascent + descent)) / 2 + ascent)); @@ -429,7 +429,7 @@ list_set_property (void *vself, const char *name, const char *value) } else if (grub_strcmp (name, "item_color") == 0) { - grub_gui_parse_color (value, &self->item_color); + grub_video_parse_color (value, &self->item_color); } else if (grub_strcmp (name, "selected_item_color") == 0) { @@ -439,7 +439,7 @@ list_set_property (void *vself, const char *name, const char *value) } else { - if (grub_gui_parse_color (value, &self->selected_item_color) + if (grub_video_parse_color (value, &self->selected_item_color) == GRUB_ERR_NONE) self->selected_item_color_set = 1; } @@ -562,7 +562,7 @@ grub_gui_list_new (void) { list_impl_t self; grub_font_t default_font; - grub_gui_color_t default_fg_color; + grub_video_rgba_color_t default_fg_color; self = grub_zalloc (sizeof (*self)); if (! self) @@ -574,7 +574,7 @@ grub_gui_list_new (void) self->visible = 1; default_font = grub_font_get ("Unknown Regular 16"); - default_fg_color = grub_gui_color_rgb (0, 0, 0); + default_fg_color = grub_video_rgba_color_rgb (0, 0, 0); self->icon_width = 32; self->icon_height = 32; diff --git a/grub-core/gfxmenu/gui_progress_bar.c b/grub-core/gfxmenu/gui_progress_bar.c index e1b31794f..db89ccbf7 100644 --- a/grub-core/gfxmenu/gui_progress_bar.c +++ b/grub-core/gfxmenu/gui_progress_bar.c @@ -40,10 +40,10 @@ struct grub_gui_progress_bar int show_text; char *template; grub_font_t font; - grub_gui_color_t text_color; - grub_gui_color_t border_color; - grub_gui_color_t bg_color; - grub_gui_color_t fg_color; + grub_video_rgba_color_t text_color; + grub_video_rgba_color_t border_color; + grub_video_rgba_color_t bg_color; + grub_video_rgba_color_t fg_color; char *theme_dir; int need_to_recreate_pixmaps; @@ -109,7 +109,7 @@ draw_filled_rect_bar (grub_gui_progress_bar_t self) f.height = self->bounds.height - 2; /* Border. */ - grub_video_fill_rect (grub_gui_map_color (self->border_color), + grub_video_fill_rect (grub_video_map_rgba_color (self->border_color), f.x - 1, f.y - 1, f.width + 2, f.height + 2); @@ -117,12 +117,12 @@ draw_filled_rect_bar (grub_gui_progress_bar_t self) int barwidth = (f.width * (self->value - self->start) / (self->end - self->start)); - grub_video_fill_rect (grub_gui_map_color (self->bg_color), + grub_video_fill_rect (grub_video_map_rgba_color (self->bg_color), f.x + barwidth, f.y, f.width - barwidth, f.height); /* Bar foreground. */ - grub_video_fill_rect (grub_gui_map_color (self->fg_color), + grub_video_fill_rect (grub_video_map_rgba_color (self->fg_color), f.x, f.y, barwidth, f.height); } @@ -161,7 +161,8 @@ draw_text (grub_gui_progress_bar_t self) if (self->template) { grub_font_t font = self->font; - grub_video_color_t text_color = grub_gui_map_color (self->text_color); + grub_video_color_t text_color = + grub_video_map_rgba_color (self->text_color); int width = self->bounds.width; int height = self->bounds.height; char *text; @@ -298,19 +299,19 @@ progress_bar_set_property (void *vself, const char *name, const char *value) } else if (grub_strcmp (name, "text_color") == 0) { - grub_gui_parse_color (value, &self->text_color); + grub_video_parse_color (value, &self->text_color); } else if (grub_strcmp (name, "border_color") == 0) { - grub_gui_parse_color (value, &self->border_color); + grub_video_parse_color (value, &self->border_color); } else if (grub_strcmp (name, "bg_color") == 0) { - grub_gui_parse_color (value, &self->bg_color); + grub_video_parse_color (value, &self->bg_color); } else if (grub_strcmp (name, "fg_color") == 0) { - grub_gui_parse_color (value, &self->fg_color); + grub_video_parse_color (value, &self->fg_color); } else if (grub_strcmp (name, "bar_style") == 0) { @@ -379,9 +380,9 @@ grub_gui_progress_bar_new (void) self->progress.component.ops = &progress_bar_ops; self->visible = 1; self->font = grub_font_get ("Unknown Regular 16"); - grub_gui_color_t black = { .red = 0, .green = 0, .blue = 0, .alpha = 255 }; - grub_gui_color_t gray = { .red = 128, .green = 128, .blue = 128, .alpha = 255 }; - grub_gui_color_t lightgray = { .red = 200, .green = 200, .blue = 200, .alpha = 255 }; + grub_video_rgba_color_t black = { .red = 0, .green = 0, .blue = 0, .alpha = 255 }; + grub_video_rgba_color_t gray = { .red = 128, .green = 128, .blue = 128, .alpha = 255 }; + grub_video_rgba_color_t lightgray = { .red = 200, .green = 200, .blue = 200, .alpha = 255 }; self->text_color = black; self->border_color = black; self->bg_color = gray; diff --git a/grub-core/gfxmenu/gui_string_util.c b/grub-core/gfxmenu/gui_string_util.c index 8c51e396a..a9a415e31 100644 --- a/grub-core/gfxmenu/gui_string_util.c +++ b/grub-core/gfxmenu/gui_string_util.c @@ -204,124 +204,3 @@ grub_get_dirname (const char *file_path) return grub_new_substring (file_path, 0, last_slash + 1); } - -static __inline int -my_isxdigit (char c) -{ - return ((c >= '0' && c <= '9') - || (c >= 'a' && c <= 'f') - || (c >= 'A' && c <= 'F')); -} - -static int -parse_hex_color_component (const char *s, unsigned start, unsigned end) -{ - unsigned len; - char buf[3]; - - len = end - start; - /* Check the limits so we don't overrun the buffer. */ - if (len < 1 || len > 2) - return 0; - - if (len == 1) - { - buf[0] = s[start]; /* Get the first and only hex digit. */ - buf[1] = buf[0]; /* Duplicate the hex digit. */ - } - else if (len == 2) - { - buf[0] = s[start]; - buf[1] = s[start + 1]; - } - - buf[2] = '\0'; - - return grub_strtoul (buf, 0, 16); -} - -/* Parse a color string of the form "r, g, b", "#RGB", "#RGBA", - "#RRGGBB", or "#RRGGBBAA". */ -grub_err_t -grub_gui_parse_color (const char *s, grub_gui_color_t *color) -{ - grub_gui_color_t c; - - /* Skip whitespace. */ - while (*s && grub_isspace (*s)) - s++; - - if (*s == '#') - { - /* HTML-style. Number if hex digits: - [6] #RRGGBB [3] #RGB - [8] #RRGGBBAA [4] #RGBA */ - - s++; /* Skip the '#'. */ - /* Count the hexits to determine the format. */ - int hexits = 0; - const char *end = s; - while (my_isxdigit (*end)) - { - end++; - hexits++; - } - - /* Parse the color components based on the format. */ - if (hexits == 3 || hexits == 4) - { - c.red = parse_hex_color_component (s, 0, 1); - c.green = parse_hex_color_component (s, 1, 2); - c.blue = parse_hex_color_component (s, 2, 3); - if (hexits == 4) - c.alpha = parse_hex_color_component (s, 3, 4); - else - c.alpha = 255; - } - else if (hexits == 6 || hexits == 8) - { - c.red = parse_hex_color_component (s, 0, 2); - c.green = parse_hex_color_component (s, 2, 4); - c.blue = parse_hex_color_component (s, 4, 6); - if (hexits == 8) - c.alpha = parse_hex_color_component (s, 6, 8); - else - c.alpha = 255; - } - else - return grub_error (GRUB_ERR_BAD_ARGUMENT, - "invalid HTML-type color string `%s'", s); - } - else if (grub_isdigit (*s)) - { - /* Comma separated decimal values. */ - c.red = grub_strtoul (s, 0, 0); - if ((s = grub_strchr (s, ',')) == 0) - return grub_error (GRUB_ERR_BAD_ARGUMENT, - "missing 1st comma separator in color `%s'", s); - s++; - c.green = grub_strtoul (s, 0, 0); - if ((s = grub_strchr (s, ',')) == 0) - return grub_error (GRUB_ERR_BAD_ARGUMENT, - "missing 2nd comma separator in color `%s'", s); - s++; - c.blue = grub_strtoul (s, 0, 0); - if ((s = grub_strchr (s, ',')) == 0) - c.alpha = 255; - else - { - s++; - c.alpha = grub_strtoul (s, 0, 0); - } - } - else - { - if (! grub_gui_get_named_color (s, &c)) - return grub_error (GRUB_ERR_BAD_ARGUMENT, - "invalid named color `%s'", s); - } - - if (grub_errno == GRUB_ERR_NONE) - *color = c; - return grub_errno; -} diff --git a/grub-core/gfxmenu/theme_loader.c b/grub-core/gfxmenu/theme_loader.c index 3854c6c53..f9c711d3e 100644 --- a/grub-core/gfxmenu/theme_loader.c +++ b/grub-core/gfxmenu/theme_loader.c @@ -135,11 +135,11 @@ theme_set_string (grub_gfxmenu_view_t view, return grub_errno; } else if (! grub_strcmp ("title-color", name)) - grub_gui_parse_color (value, &view->title_color); + grub_video_parse_color (value, &view->title_color); else if (! grub_strcmp ("message-color", name)) - grub_gui_parse_color (value, &view->message_color); + grub_video_parse_color (value, &view->message_color); else if (! grub_strcmp ("message-bg-color", name)) - grub_gui_parse_color (value, &view->message_bg_color); + grub_video_parse_color (value, &view->message_bg_color); else if (! grub_strcmp ("desktop-image", name)) { struct grub_video_bitmap *raw_bitmap; @@ -170,7 +170,7 @@ theme_set_string (grub_gfxmenu_view_t view, view->desktop_image = scaled_bitmap; } else if (! grub_strcmp ("desktop-color", name)) - grub_gui_parse_color (value, &view->desktop_color); + grub_video_parse_color (value, &view->desktop_color); else if (! grub_strcmp ("terminal-box", name)) { grub_err_t err; diff --git a/grub-core/gfxmenu/view.c b/grub-core/gfxmenu/view.c index 901cdc889..836a9884d 100644 --- a/grub-core/gfxmenu/view.c +++ b/grub-core/gfxmenu/view.c @@ -50,8 +50,8 @@ grub_gfxmenu_view_new (const char *theme_path, { grub_gfxmenu_view_t view; grub_font_t default_font; - grub_gui_color_t default_fg_color; - grub_gui_color_t default_bg_color; + grub_video_rgba_color_t default_fg_color; + grub_video_rgba_color_t default_bg_color; view = grub_malloc (sizeof (*view)); if (! view) @@ -63,8 +63,8 @@ grub_gfxmenu_view_new (const char *theme_path, view->screen.height = height; default_font = grub_font_get ("Unknown Regular 16"); - default_fg_color = grub_gui_color_rgb (0, 0, 0); - default_bg_color = grub_gui_color_rgb (255, 255, 255); + default_fg_color = grub_video_rgba_color_rgb (0, 0, 0); + default_bg_color = grub_video_rgba_color_rgb (255, 255, 255); view->canvas = 0; @@ -131,7 +131,7 @@ redraw_background (grub_gfxmenu_view_t view, } else { - grub_video_fill_rect (grub_gui_map_color (view->desktop_color), + grub_video_fill_rect (grub_video_map_rgba_color (view->desktop_color), bounds->x, bounds->y, bounds->width, bounds->height); } @@ -150,7 +150,7 @@ draw_title (grub_gfxmenu_view_t view) int y = 40 + grub_font_get_ascent (view->title_font); grub_font_draw_string (view->title_text, view->title_font, - grub_gui_map_color (view->title_color), + grub_video_map_rgba_color (view->title_color), x, y); } @@ -244,13 +244,13 @@ draw_message (grub_gfxmenu_view_t view) return; grub_font_t font = view->message_font; - grub_video_color_t color = grub_gui_map_color (view->message_color); + grub_video_color_t color = grub_video_map_rgba_color (view->message_color); /* Border. */ grub_video_fill_rect (color, f.x-1, f.y-1, f.width+2, f.height+2); /* Fill. */ - grub_video_fill_rect (grub_gui_map_color (view->message_bg_color), + grub_video_fill_rect (grub_video_map_rgba_color (view->message_bg_color), f.x, f.y, f.width, f.height); /* Center the text. */ diff --git a/grub-core/gfxmenu/named_colors.c b/grub-core/video/colors.c similarity index 70% rename from grub-core/gfxmenu/named_colors.c rename to grub-core/video/colors.c index eedbc47fb..0637c5508 100644 --- a/grub-core/gfxmenu/named_colors.c +++ b/grub-core/video/colors.c @@ -25,7 +25,7 @@ struct named_color { const char *name; - grub_gui_color_t color; + grub_video_rgba_color_t color; }; /* @@ -193,8 +193,8 @@ static struct named_color named_colors[] = stores the color into *COLOR. If the color was not found, returns 0 and does not modify *COLOR. */ int -grub_gui_get_named_color (const char *name, - grub_gui_color_t *color) +grub_video_get_named_color (const char *name, + grub_video_rgba_color_t *color) { int i; for (i = 0; named_colors[i].name; i++) @@ -207,3 +207,124 @@ grub_gui_get_named_color (const char *name, } return 0; } + +static __inline int +my_isxdigit (char c) +{ + return ((c >= '0' && c <= '9') + || (c >= 'a' && c <= 'f') + || (c >= 'A' && c <= 'F')); +} + +static int +parse_hex_color_component (const char *s, unsigned start, unsigned end) +{ + unsigned len; + char buf[3]; + + len = end - start; + /* Check the limits so we don't overrun the buffer. */ + if (len < 1 || len > 2) + return 0; + + if (len == 1) + { + buf[0] = s[start]; /* Get the first and only hex digit. */ + buf[1] = buf[0]; /* Duplicate the hex digit. */ + } + else if (len == 2) + { + buf[0] = s[start]; + buf[1] = s[start + 1]; + } + + buf[2] = '\0'; + + return grub_strtoul (buf, 0, 16); +} + +/* Parse a color string of the form "r, g, b", "#RGB", "#RGBA", + "#RRGGBB", or "#RRGGBBAA". */ +grub_err_t +grub_video_parse_color (const char *s, grub_video_rgba_color_t *color) +{ + grub_video_rgba_color_t c; + + /* Skip whitespace. */ + while (*s && grub_isspace (*s)) + s++; + + if (*s == '#') + { + /* HTML-style. Number if hex digits: + [6] #RRGGBB [3] #RGB + [8] #RRGGBBAA [4] #RGBA */ + + s++; /* Skip the '#'. */ + /* Count the hexits to determine the format. */ + int hexits = 0; + const char *end = s; + while (my_isxdigit (*end)) + { + end++; + hexits++; + } + + /* Parse the color components based on the format. */ + if (hexits == 3 || hexits == 4) + { + c.red = parse_hex_color_component (s, 0, 1); + c.green = parse_hex_color_component (s, 1, 2); + c.blue = parse_hex_color_component (s, 2, 3); + if (hexits == 4) + c.alpha = parse_hex_color_component (s, 3, 4); + else + c.alpha = 255; + } + else if (hexits == 6 || hexits == 8) + { + c.red = parse_hex_color_component (s, 0, 2); + c.green = parse_hex_color_component (s, 2, 4); + c.blue = parse_hex_color_component (s, 4, 6); + if (hexits == 8) + c.alpha = parse_hex_color_component (s, 6, 8); + else + c.alpha = 255; + } + else + return grub_error (GRUB_ERR_BAD_ARGUMENT, + "invalid HTML-type color string `%s'", s); + } + else if (grub_isdigit (*s)) + { + /* Comma separated decimal values. */ + c.red = grub_strtoul (s, 0, 0); + if ((s = grub_strchr (s, ',')) == 0) + return grub_error (GRUB_ERR_BAD_ARGUMENT, + "missing 1st comma separator in color `%s'", s); + s++; + c.green = grub_strtoul (s, 0, 0); + if ((s = grub_strchr (s, ',')) == 0) + return grub_error (GRUB_ERR_BAD_ARGUMENT, + "missing 2nd comma separator in color `%s'", s); + s++; + c.blue = grub_strtoul (s, 0, 0); + if ((s = grub_strchr (s, ',')) == 0) + c.alpha = 255; + else + { + s++; + c.alpha = grub_strtoul (s, 0, 0); + } + } + else + { + if (! grub_video_get_named_color (s, &c)) + return grub_error (GRUB_ERR_BAD_ARGUMENT, + "invalid named color `%s'", s); + } + + if (grub_errno == GRUB_ERR_NONE) + *color = c; + return grub_errno; +} diff --git a/include/grub/gfxmenu_view.h b/include/grub/gfxmenu_view.h index c52a3c71c..f858e9d49 100644 --- a/include/grub/gfxmenu_view.h +++ b/include/grub/gfxmenu_view.h @@ -87,11 +87,11 @@ struct grub_gfxmenu_view grub_font_t title_font; grub_font_t message_font; char *terminal_font_name; - grub_gui_color_t title_color; - grub_gui_color_t message_color; - grub_gui_color_t message_bg_color; + grub_video_rgba_color_t title_color; + grub_video_rgba_color_t message_color; + grub_video_rgba_color_t message_bg_color; struct grub_video_bitmap *desktop_image; - grub_gui_color_t desktop_color; + grub_video_rgba_color_t desktop_color; grub_gfxmenu_box_t terminal_box; char *title_text; char *progress_message_text; diff --git a/include/grub/gui.h b/include/grub/gui.h index 6e4a11cbe..ef0795cf7 100644 --- a/include/grub/gui.h +++ b/include/grub/gui.h @@ -31,16 +31,6 @@ status changes. */ #define GRUB_GFXMENU_TIMEOUT_COMPONENT_ID "__timeout__" -/* A representation of a color. Unlike grub_video_color_t, this - representation is independent of any video mode specifics. */ -typedef struct grub_gui_color -{ - grub_uint8_t red; - grub_uint8_t green; - grub_uint8_t blue; - grub_uint8_t alpha; -} grub_gui_color_t; - typedef struct grub_gui_component *grub_gui_component_t; typedef struct grub_gui_container *grub_gui_container_t; typedef struct grub_gui_list *grub_gui_list_t; @@ -242,23 +232,6 @@ grub_gui_set_viewport (const grub_video_rect_t *r, grub_video_rect_t *old) r->height); } -static __inline grub_gui_color_t -grub_gui_color_rgb (int r, int g, int b) -{ - grub_gui_color_t c; - c.red = r; - c.green = g; - c.blue = b; - c.alpha = 255; - return c; -} - -static __inline grub_video_color_t -grub_gui_map_color (grub_gui_color_t c) -{ - return grub_video_map_rgba (c.red, c.green, c.blue, c.alpha); -} - static inline int grub_video_have_common_points (const grub_video_rect_t *a, const grub_video_rect_t *b) diff --git a/include/grub/gui_string_util.h b/include/grub/gui_string_util.h index 1baa2eede..34f9a090d 100644 --- a/include/grub/gui_string_util.h +++ b/include/grub/gui_string_util.h @@ -30,8 +30,4 @@ char *grub_resolve_relative_path (const char *base, const char *path); char *grub_get_dirname (const char *file_path); -int grub_gui_get_named_color (const char *name, grub_gui_color_t *color); - -grub_err_t grub_gui_parse_color (const char *s, grub_gui_color_t *color); - #endif /* GRUB_GUI_STRING_UTIL_HEADER */ diff --git a/include/grub/video.h b/include/grub/video.h index 5350d87eb..97bd85bd1 100644 --- a/include/grub/video.h +++ b/include/grub/video.h @@ -27,6 +27,15 @@ specific coding format. */ typedef grub_uint32_t grub_video_color_t; +/* Video color in hardware independent format. */ +typedef struct grub_video_rgba_color +{ + grub_uint8_t red; + grub_uint8_t green; + grub_uint8_t blue; + grub_uint8_t alpha; +} grub_video_rgba_color_t; + /* This structure is driver specific and should not be accessed directly by outside code. */ struct grub_video_render_target; @@ -428,4 +437,27 @@ grub_video_check_mode_flag (grub_video_mode_type_t flags, grub_video_driver_id_t EXPORT_FUNC (grub_video_get_driver_id) (void); +static __inline grub_video_rgba_color_t +grub_video_rgba_color_rgb (int r, int g, int b) +{ + grub_video_rgba_color_t c; + c.red = r; + c.green = g; + c.blue = b; + c.alpha = 255; + return c; +} + +static __inline grub_video_color_t +grub_video_map_rgba_color (grub_video_rgba_color_t c) +{ + return grub_video_map_rgba (c.red, c.green, c.blue, c.alpha); +} + +int EXPORT_FUNC (grub_video_get_named_color) (const char *name, + grub_video_rgba_color_t *color); + +grub_err_t EXPORT_FUNC (grub_video_parse_color) (const char *s, + grub_video_rgba_color_t *color); + #endif /* ! GRUB_VIDEO_HEADER */ From f8e2e451e6e19fa94b9e7cc331104eae9b29135d Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 10 Dec 2010 18:34:46 +0100 Subject: [PATCH 088/869] handle UTF16 UDF label --- grub-core/fs/udf.c | 68 ++++++++++++++++++++++++++++++---------------- 1 file changed, 45 insertions(+), 23 deletions(-) diff --git a/grub-core/fs/udf.c b/grub-core/fs/udf.c index 0c5da996e..aaf1565f7 100644 --- a/grub-core/fs/udf.c +++ b/grub-core/fs/udf.c @@ -789,6 +789,43 @@ fail: return 0; } +static char * +read_string (grub_uint8_t *raw, grub_size_t sz) +{ + grub_uint16_t *utf16; + char *ret; + grub_size_t utf16len = 0; + + if (raw[0] != 8 && raw[0] != 16) + return NULL; + + if (raw[0] == 8) + { + unsigned i; + utf16len = sz - 1; + utf16 = grub_malloc (utf16len * sizeof (utf16[0])); + if (!utf16) + return NULL; + for (i = 0; i < utf16len; i++) + utf16[i] = raw[i + 1]; + } + if (raw[0] == 16) + { + unsigned i; + utf16len = (sz - 1) / 2; + utf16 = grub_malloc (utf16len * sizeof (utf16[0])); + if (!utf16) + return NULL; + for (i = 0; i < utf16len; i++) + utf16[i] = (raw[2 * i + 1] << 8) | raw[2*i + 2]; + } + ret = grub_malloc (utf16len * 3 + 1); + if (ret) + *grub_utf16_to_utf8 ((grub_uint8_t *) ret, utf16, utf16len) = '\0'; + grub_free (utf16); + return ret; +} + static int grub_udf_iterate_dir (grub_fshelp_node_t dir, int NESTED_FUNC_ATTR @@ -842,10 +879,8 @@ grub_udf_iterate_dir (grub_fshelp_node_t dir, else { enum grub_fshelp_filetype type; + char *filename; grub_uint8_t raw[dirent.file_ident_length]; - grub_uint16_t utf16[dirent.file_ident_length - 1]; - grub_uint8_t filename[dirent.file_ident_length * 2]; - grub_size_t utf16len = 0; type = ((dirent.characteristics & GRUB_UDF_FID_CHAR_DIRECTORY) ? (GRUB_FSHELP_DIR) : (GRUB_FSHELP_REG)); @@ -856,27 +891,14 @@ grub_udf_iterate_dir (grub_fshelp_node_t dir, != dirent.file_ident_length) return 0; - if (raw[0] == 8) - { - unsigned i; - utf16len = dirent.file_ident_length - 1; - for (i = 0; i < utf16len; i++) - utf16[i] = raw[i + 1]; - } - if (raw[0] == 16) - { - unsigned i; - utf16len = (dirent.file_ident_length - 1) / 2; - for (i = 0; i < utf16len; i++) - utf16[i] = (raw[2 * i + 1] << 8) | raw[2*i + 2]; - } - if (raw[0] == 8 || raw[0] == 16) - { - *grub_utf16_to_utf8 (filename, utf16, utf16len) = '\0'; + filename = read_string (raw, dirent.file_ident_length); - if (hook ((char *) filename, type, child)) - return 1; + if (filename && hook (filename, type, child)) + { + grub_free (filename); + return 1; } + grub_free (filename); } } @@ -1033,7 +1055,7 @@ grub_udf_label (grub_device_t device, char **label) if (data) { - *label = grub_strdup ((char *) &data->lvd.ident[1]); + *label = read_string (data->lvd.ident, sizeof (data->lvd.ident)); grub_free (data); } else From 9c55cbe8e70353e078b884b7c8d86f3e7ccf0ada Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Fri, 10 Dec 2010 17:47:38 +0000 Subject: [PATCH 089/869] Add a background_color command. * grub-core/term/gfxterm.c (grub_gfxterm_background_color_cmd): New function. (GRUB_MOD_INIT): Register background_color command. (GRUB_MOD_FINI): Unregister background_color command. --- ChangeLog.parse-color | 7 +++++ grub-core/term/gfxterm.c | 63 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+) diff --git a/ChangeLog.parse-color b/ChangeLog.parse-color index 93d696c6c..ccba06d3c 100644 --- a/ChangeLog.parse-color +++ b/ChangeLog.parse-color @@ -32,3 +32,10 @@ (gfxmenu): Remove gfxmenu/named_colors.c. (video_colors) [videomodules]: New module, containing video/colors.c. + + Add a background_color command. + + * grub-core/term/gfxterm.c (grub_gfxterm_background_color_cmd): New + function. + (GRUB_MOD_INIT): Register background_color command. + (GRUB_MOD_FINI): Unregister background_color command. diff --git a/grub-core/term/gfxterm.c b/grub-core/term/gfxterm.c index 9a10d47b0..93367f2bb 100644 --- a/grub-core/term/gfxterm.c +++ b/grub-core/term/gfxterm.c @@ -1180,6 +1180,62 @@ grub_gfxterm_background_image_cmd (grub_extcmd_context_t ctxt, return grub_errno; } +static grub_err_t +grub_gfxterm_background_color_cmd (grub_command_t cmd __attribute__ ((unused)), + int argc, char **args) +{ + grub_video_rgba_color_t color; + grub_uint8_t *data; + unsigned int i; + + if (argc != 1) + return grub_error (GRUB_ERR_BAD_ARGUMENT, "missing operand"); + + /* Check that we have video adapter active. */ + if (grub_video_get_info (NULL) != GRUB_ERR_NONE) + return grub_errno; + + if (grub_video_parse_color (args[0], &color) != GRUB_ERR_NONE) + return grub_errno; + + /* Destroy existing background bitmap if loaded. */ + if (bitmap) + { + grub_video_bitmap_destroy (bitmap); + bitmap = 0; + + /* Mark whole screen as dirty. */ + dirty_region_add (0, 0, window.width, window.height); + } + + /* Create a filled bitmap so that we get suitable text blending. */ + grub_video_bitmap_create (&bitmap, window.width, window.height, + GRUB_VIDEO_BLIT_FORMAT_RGB_888); + if (grub_errno != GRUB_ERR_NONE) + return grub_errno; + + data = bitmap->data; + for (i = 0; i < window.height * window.width; i++) + { + *data++ = color.red; + *data++ = color.green; + *data++ = color.blue; + } + + bitmap_width = window.width; + bitmap_height = window.height; + + /* Set the border color. */ + virtual_screen.bg_color_display = grub_video_map_rgba_color (color); + + /* Mark whole screen as dirty. */ + dirty_region_add (0, 0, window.width, window.height); + + /* All was ok. */ + grub_errno = GRUB_ERR_NONE; + return grub_errno; +} + static struct grub_term_output grub_video_term = { .name = "gfxterm", @@ -1201,6 +1257,7 @@ static struct grub_term_output grub_video_term = }; static grub_extcmd_t background_image_cmd_handle; +static grub_command_t background_color_cmd_handle; GRUB_MOD_INIT(gfxterm) { @@ -1211,10 +1268,16 @@ GRUB_MOD_INIT(gfxterm) N_("[-m (stretch|normal)] FILE"), N_("Load background image for active terminal."), background_image_cmd_options); + background_color_cmd_handle = + grub_register_command ("background_color", + grub_gfxterm_background_color_cmd, + N_("COLOR"), + N_("Set background color for active terminal.")); } GRUB_MOD_FINI(gfxterm) { + grub_unregister_command (background_color_cmd_handle); grub_unregister_extcmd (background_image_cmd_handle); grub_term_unregister_output (&grub_video_term); } From 591baceb34e93e0ebef73f24f581414472804548 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 11 Dec 2010 06:04:21 +0100 Subject: [PATCH 090/869] UDF symlink support --- grub-core/fs/udf.c | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/grub-core/fs/udf.c b/grub-core/fs/udf.c index aaf1565f7..48aeca3c8 100644 --- a/grub-core/fs/udf.c +++ b/grub-core/fs/udf.c @@ -884,6 +884,8 @@ grub_udf_iterate_dir (grub_fshelp_node_t dir, type = ((dirent.characteristics & GRUB_UDF_FID_CHAR_DIRECTORY) ? (GRUB_FSHELP_DIR) : (GRUB_FSHELP_REG)); + if (child->fe.icbtag.file_type == GRUB_UDF_ICBTAG_TYPE_SYMLINK) + type = GRUB_FSHELP_SYMLINK; if ((grub_udf_read_file (dir, 0, offset, dirent.file_ident_length, @@ -909,6 +911,25 @@ grub_udf_iterate_dir (grub_fshelp_node_t dir, return 0; } +static char * +grub_ufs_read_symlink (grub_fshelp_node_t node) +{ + grub_size_t sz = U64 (node->fe.file_size); + grub_uint8_t *raw; + char *ret; + + if (sz < 4) + return NULL; + raw = grub_malloc (sz - 4); + if (!raw) + return NULL; + if (grub_udf_read_file (node, NULL, 4, sz - 4, (char *) raw) < 0) + return NULL; + ret = read_string (raw, sz - 4); + grub_free (raw); + return ret; +} + static grub_err_t grub_udf_dir (grub_device_t device, const char *path, int (*hook) (const char *filename, @@ -972,7 +993,8 @@ grub_udf_dir (grub_device_t device, const char *path, if (grub_fshelp_find_file (path, &rootnode, &foundnode, - grub_udf_iterate_dir, 0, GRUB_FSHELP_DIR)) + grub_udf_iterate_dir, grub_ufs_read_symlink, + GRUB_FSHELP_DIR)) goto fail; grub_udf_iterate_dir (foundnode, iterate); @@ -1006,7 +1028,8 @@ grub_udf_open (struct grub_file *file, const char *name) if (grub_fshelp_find_file (name, &rootnode, &foundnode, - grub_udf_iterate_dir, 0, GRUB_FSHELP_REG)) + grub_udf_iterate_dir, grub_ufs_read_symlink, + GRUB_FSHELP_REG)) goto fail; file->data = foundnode; From 88db5b694a1fe9772fb21afe24d1dadbb6a1254f Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 11 Dec 2010 06:23:33 +0100 Subject: [PATCH 091/869] file mtime support for reiserfs --- grub-core/fs/reiserfs.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/grub-core/fs/reiserfs.c b/grub-core/fs/reiserfs.c index e92279554..443d71b6f 100644 --- a/grub-core/fs/reiserfs.c +++ b/grub-core/fs/reiserfs.c @@ -222,6 +222,7 @@ struct grub_fshelp_node grub_uint32_t block_number; /* 0 if node is not found. */ grub_uint16_t block_position; grub_uint64_t next_offset; + grub_int32_t mtime; enum grub_reiserfs_item_type type; /* To know how to read the header. */ struct grub_reiserfs_item_header header; }; @@ -868,6 +869,7 @@ grub_reiserfs_iterate_dir (grub_fshelp_node_t item, entry_v1_stat.rdev, entry_v1_stat.first_direct_byte); #endif + entry_item->mtime = grub_le_to_cpu32 (entry_v1_stat.mtime); if ((grub_le_to_cpu16 (entry_v1_stat.mode) & S_IFLNK) == S_IFLNK) entry_type = GRUB_FSHELP_SYMLINK; @@ -914,6 +916,7 @@ grub_reiserfs_iterate_dir (grub_fshelp_node_t item, entry_v2_stat.blocks, entry_v2_stat.first_direct_byte); #endif + entry_item->mtime = grub_le_to_cpu32 (entry_v2_stat.mtime); if ((grub_le_to_cpu16 (entry_v2_stat.mode) & S_IFLNK) == S_IFLNK) entry_type = GRUB_FSHELP_SYMLINK; @@ -1276,6 +1279,8 @@ grub_reiserfs_dir (grub_device_t device, const char *path, struct grub_dirhook_info info; grub_memset (&info, 0, sizeof (info)); info.dir = ((filetype & GRUB_FSHELP_TYPE_MASK) == GRUB_FSHELP_DIR); + info.mtimeset = 1; + info.mtime = node->mtime; grub_free (node); return hook (filename, &info); } From ebec6850b9a62caa24cc886bdaf647c5a731f4b2 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 11 Dec 2010 07:00:31 +0100 Subject: [PATCH 092/869] HFS filesystem mtime support --- grub-core/fs/hfs.c | 18 ++++++++++++++++++ include/grub/hfs.h | 4 +++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/grub-core/fs/hfs.c b/grub-core/fs/hfs.c index cef856326..a40171dbd 100644 --- a/grub-core/fs/hfs.c +++ b/grub-core/fs/hfs.c @@ -1072,6 +1072,23 @@ grub_hfs_label (grub_device_t device, char **label) return grub_errno; } +static grub_err_t +grub_hfs_mtime (grub_device_t device, grub_int32_t *tm) +{ + struct grub_hfs_data *data; + + data = grub_hfs_mount (device->disk); + + if (data) + *tm = grub_be_to_cpu32 (data->sblock.mtime) - 2082844800; + else + *tm = 0; + + grub_free (data); + return grub_errno; +} + + static grub_err_t grub_hfs_uuid (grub_device_t device, char **uuid) { @@ -1107,6 +1124,7 @@ static struct grub_fs grub_hfs_fs = .close = grub_hfs_close, .label = grub_hfs_label, .uuid = grub_hfs_uuid, + .mtime = grub_hfs_mtime, .next = 0 }; diff --git a/include/grub/hfs.h b/include/grub/hfs.h index d93b9a2c9..bf98610d9 100644 --- a/include/grub/hfs.h +++ b/include/grub/hfs.h @@ -39,7 +39,9 @@ typedef struct grub_hfs_extent grub_hfs_datarecord_t[3]; struct grub_hfs_sblock { grub_uint16_t magic; - grub_uint8_t unused[18]; + grub_uint32_t ctime; + grub_uint32_t mtime; + grub_uint8_t unused[10]; grub_uint32_t blksz; grub_uint8_t unused2[4]; grub_uint16_t first_block; From 58fa13fc7c03fdc605103e9a476267dcc3fe7190 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 11 Dec 2010 07:15:44 +0100 Subject: [PATCH 093/869] HFS mtime support --- grub-core/fs/hfs.c | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/grub-core/fs/hfs.c b/grub-core/fs/hfs.c index a40171dbd..e4cc23c17 100644 --- a/grub-core/fs/hfs.c +++ b/grub-core/fs/hfs.c @@ -131,6 +131,8 @@ struct grub_hfs_dirrec grub_uint8_t type; grub_uint8_t unused[5]; grub_uint32_t dirid; + grub_uint32_t ctime; + grub_uint32_t mtime; } __attribute__ ((packed)); /* Information about a file. */ @@ -142,7 +144,9 @@ struct grub_hfs_filerec grub_uint32_t fileid; grub_uint8_t unused2[2]; grub_uint32_t size; - grub_uint8_t unused3[44]; + grub_uint8_t unused3[18]; + grub_uint32_t mtime; + grub_uint8_t unused4[22]; /* The first 3 extents of the file. The other extents can be found in the extent overflow file. */ @@ -951,19 +955,29 @@ grub_hfs_dir (grub_device_t device, const char *path, int dir_hook (struct grub_hfs_record *rec) { char fname[32] = { 0 }; - char *filetype = rec->data; + struct grub_hfs_dirrec *drec = rec->data; + struct grub_hfs_filerec *frec = rec->data; struct grub_hfs_catalog_key *ckey = rec->key; struct grub_dirhook_info info; grub_memset (&info, 0, sizeof (info)); grub_strncpy (fname, (char *) (ckey->str), ckey->strlen); - if (*filetype == GRUB_HFS_FILETYPE_DIR - || *filetype == GRUB_HFS_FILETYPE_FILE) + if (drec->type == GRUB_HFS_FILETYPE_DIR) { - info.dir = (*filetype == GRUB_HFS_FILETYPE_DIR); + info.dir = 1; + info.mtimeset = 1; + info.mtime = grub_be_to_cpu32 (drec->mtime) - 2082844800; return hook (fname, &info); } + if (frec->type == GRUB_HFS_FILETYPE_FILE) + { + info.dir = 0; + info.mtimeset = 1; + info.mtime = grub_be_to_cpu32 (frec->mtime) - 2082844800; + return hook (fname, &info); + } + return 0; } @@ -1088,7 +1102,6 @@ grub_hfs_mtime (grub_device_t device, grub_int32_t *tm) return grub_errno; } - static grub_err_t grub_hfs_uuid (grub_device_t device, char **uuid) { From 7ac6c4842d57817bd35c74d49668422c9f43ba7a Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 11 Dec 2010 14:26:34 +0100 Subject: [PATCH 094/869] JFS mtime support --- grub-core/fs/jfs.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/grub-core/fs/jfs.c b/grub-core/fs/jfs.c index 76ef2e540..9e45f56d2 100644 --- a/grub-core/fs/jfs.c +++ b/grub-core/fs/jfs.c @@ -153,6 +153,12 @@ struct grub_jfs_leaf_next_dirent grub_uint16_t namepart[15]; } __attribute__ ((packed)); +struct grub_jfs_time +{ + grub_int32_t sec; + grub_int32_t nanosec; +} __attribute__ ((packed)); + struct grub_jfs_inode { grub_uint32_t stamp; @@ -162,7 +168,10 @@ struct grub_jfs_inode grub_uint64_t size; grub_uint8_t unused2[20]; grub_uint32_t mode; - grub_uint8_t unused3[72]; + struct grub_jfs_time atime; + struct grub_jfs_time ctime; + struct grub_jfs_time mtime; + grub_uint8_t unused3[48]; grub_uint8_t unused4[96]; union @@ -751,6 +760,8 @@ grub_jfs_dir (grub_device_t device, const char *path, info.dir = (grub_le_to_cpu32 (inode.mode) & GRUB_JFS_FILETYPE_MASK) == GRUB_JFS_FILETYPE_DIR; + info.mtimeset = 1; + info.mtime = grub_le_to_cpu32 (inode.mtime.sec); if (hook (diro->name, &info)) goto fail; } From f5ff296240e8575a35b14fc3ec8ca8263b6161c4 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 11 Dec 2010 17:46:16 +0100 Subject: [PATCH 095/869] minix mtime support --- grub-core/fs/minix.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/grub-core/fs/minix.c b/grub-core/fs/minix.c index 679e1ec51..e0ca09bd7 100644 --- a/grub-core/fs/minix.c +++ b/grub-core/fs/minix.c @@ -480,6 +480,13 @@ grub_minix_dir (grub_device_t device, const char *path, grub_minix_read_inode (data, grub_le_to_cpu16 (ino)); info.dir = ((GRUB_MINIX_INODE_MODE (data) & GRUB_MINIX_IFDIR) == GRUB_MINIX_IFDIR); + info.mtimeset = 1; +#ifndef MODE_MINIX2 + info.mtime = grub_le_to_cpu32 (data->inode.ctime); +#else + info.mtime = grub_le_to_cpu32 (data->inode.mtime); +#endif + if (hook (filename, &info) ? 1 : 0) break; From 4aab26313076d3fdb10264cd0b38d9d51741646f Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 11 Dec 2010 18:20:45 +0100 Subject: [PATCH 096/869] SquashFS mtime support --- grub-core/fs/squash4.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/grub-core/fs/squash4.c b/grub-core/fs/squash4.c index 95797998a..882f5c959 100644 --- a/grub-core/fs/squash4.c +++ b/grub-core/fs/squash4.c @@ -509,6 +509,19 @@ grub_squash_close (grub_file_t file) return GRUB_ERR_NONE; } +static grub_err_t +grub_squash_mtime (grub_device_t dev, grub_int32_t *tm) +{ + struct grub_squash_data *data = 0; + + data = squash_mount (dev->disk); + if (! data) + return grub_errno; + *tm = grub_le_to_cpu32 (data->sb.creation_time); + grub_free (data); + return GRUB_ERR_NONE; +} + static struct grub_fs grub_squash_fs = { .name = "squash4", @@ -516,6 +529,7 @@ static struct grub_fs grub_squash_fs = .open = grub_squash_open, .read = grub_squash_read, .close = grub_squash_close, + .mtime = grub_squash_mtime, #ifdef GRUB_UTIL .reserved_first_sector = 0, #endif From 80113a62583c1c1622a1ed2d7ea73dfe2b72e4ce Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 11 Dec 2010 18:21:39 +0100 Subject: [PATCH 097/869] declare AFFS, CPIO, TAR and XFS as non-installable explicitly --- grub-core/fs/affs.c | 3 +++ grub-core/fs/cpio.c | 3 +++ grub-core/fs/xfs.c | 3 +++ 3 files changed, 9 insertions(+) diff --git a/grub-core/fs/affs.c b/grub-core/fs/affs.c index 3dc80752d..27e03c0c4 100644 --- a/grub-core/fs/affs.c +++ b/grub-core/fs/affs.c @@ -535,6 +535,9 @@ static struct grub_fs grub_affs_fs = .read = grub_affs_read, .close = grub_affs_close, .label = grub_affs_label, +#ifdef GRUB_UTIL + .reserved_first_sector = 0, +#endif .next = 0 }; diff --git a/grub-core/fs/cpio.c b/grub-core/fs/cpio.c index 486d8215c..a6c7a1261 100644 --- a/grub-core/fs/cpio.c +++ b/grub-core/fs/cpio.c @@ -362,6 +362,9 @@ static struct grub_fs grub_cpio_fs = { .open = grub_cpio_open, .read = grub_cpio_read, .close = grub_cpio_close, +#ifdef GRUB_UTIL + .reserved_first_sector = 0, +#endif }; #ifdef MODE_USTAR diff --git a/grub-core/fs/xfs.c b/grub-core/fs/xfs.c index 966bade1b..dbe957470 100644 --- a/grub-core/fs/xfs.c +++ b/grub-core/fs/xfs.c @@ -822,6 +822,9 @@ static struct grub_fs grub_xfs_fs = .close = grub_xfs_close, .label = grub_xfs_label, .uuid = grub_xfs_uuid, +#ifdef GRUB_UTIL + .reserved_first_sector = 0, +#endif .next = 0 }; From ea17ec49ae1d5d20b93ad7f1c303aa4d1c0682ff Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 11 Dec 2010 18:32:08 +0100 Subject: [PATCH 098/869] Extend fields in dirent header --- grub-core/fs/squash4.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/grub-core/fs/squash4.c b/grub-core/fs/squash4.c index 882f5c959..1c522f893 100644 --- a/grub-core/fs/squash4.c +++ b/grub-core/fs/squash4.c @@ -106,11 +106,9 @@ struct grub_squash_inode struct grub_squash_dirent_header { /* Actually the value is the number of elements - 1. */ - grub_uint16_t nelems; - grub_uint16_t dummy1; - grub_uint32_t ino_chunk; - grub_uint16_t dummy2[2]; -}; + grub_uint32_t nelems; + grub_uint64_t ino_chunk; +} __attribute__ ((packed)); struct grub_squash_dirent { From 5e96cb4452735c9e2beb82dbfbb03b90ec6c2d1f Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 11 Dec 2010 18:41:42 +0100 Subject: [PATCH 099/869] Extend few other fields --- grub-core/fs/squash4.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/grub-core/fs/squash4.c b/grub-core/fs/squash4.c index 1c522f893..0f94ae0a2 100644 --- a/grub-core/fs/squash4.c +++ b/grub-core/fs/squash4.c @@ -51,23 +51,23 @@ struct grub_squash_super grub_uint32_t dummy1; grub_uint32_t creation_time; grub_uint32_t dummy2; - grub_uint32_t dummy3[2]; + grub_uint64_t dummy3; grub_uint8_t flags; #define SQUASH_FLAG_UNCOMPRESSED_INODES 1 #define SQUASH_FLAG_UNCOMPRESSED_DATA 2 #define SQUASH_FLAG_UNCOMPRESSED_FRAGMENTS 8 grub_uint8_t dummy4[7]; grub_uint16_t root_ino_offset; - grub_uint16_t root_ino_chunk; - grub_uint32_t dummy5; + grub_uint32_t root_ino_chunk; + grub_uint16_t dummy5; grub_uint64_t total_size; grub_uint64_t exttbloffset; - grub_uint32_t dummy6[2]; + grub_uint64_t dummy6; grub_uint64_t inodeoffset; grub_uint64_t diroffset; grub_uint64_t unk1offset; grub_uint64_t unk2offset; -}; +} __attribute__ ((packed)); /* Chunk-based */ @@ -80,25 +80,25 @@ struct grub_squash_inode union { struct { - grub_uint16_t dummy[2]; + grub_uint32_t dummy; grub_uint32_t chunk; grub_uint32_t fragment; grub_uint32_t offset; grub_uint32_t size; - } file; + } __attribute__ ((packed)) file; struct { - grub_uint16_t dummy1[2]; + grub_uint32_t dummy1; grub_uint32_t chunk; - grub_uint16_t dummy2[2]; + grub_uint32_t dummy2; grub_uint16_t size; - grub_uint16_t offset; - grub_uint16_t dummy3[2]; - } dir; + grub_uint32_t offset; + grub_uint16_t dummy3; + } __attribute__ ((packed)) dir; struct { - grub_uint16_t dummy[4]; + grub_uint64_t dummy; grub_uint32_t namelen; char name[0]; - } symlink; + } __attribute__ ((packed)) symlink; }; } __attribute__ ((packed)); From 81ecffbfc19293dd6b14050c775926d9b5478eb8 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 11 Dec 2010 18:42:44 +0100 Subject: [PATCH 100/869] Add missing packed attribute --- grub-core/fs/squash4.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/grub-core/fs/squash4.c b/grub-core/fs/squash4.c index 0f94ae0a2..8e8388628 100644 --- a/grub-core/fs/squash4.c +++ b/grub-core/fs/squash4.c @@ -99,7 +99,7 @@ struct grub_squash_inode grub_uint32_t namelen; char name[0]; } __attribute__ ((packed)) symlink; - }; + } __attribute__ ((packed)); } __attribute__ ((packed)); /* Chunk-based. */ @@ -121,13 +121,13 @@ struct grub_squash_dirent /* Actually the value is the length of name - 1. */ grub_uint16_t namelen; char name[0]; -}; +} __attribute__ ((packed)); struct grub_squash_frag_desc { grub_uint64_t offset; grub_uint64_t dummy; -}; +} __attribute__ ((packed)); #define SQUASH_CHUNK_SIZE 0x2000 #define SQUASH_CHUNK_FLAGS 0x8000 From 9959c6a70b7bd4d5cccad712a747f90f33f85fa9 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 11 Dec 2010 21:15:25 +0100 Subject: [PATCH 101/869] Fix AFFS rootblock detection --- grub-core/fs/affs.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/grub-core/fs/affs.c b/grub-core/fs/affs.c index 27e03c0c4..40be4b2f6 100644 --- a/grub-core/fs/affs.c +++ b/grub-core/fs/affs.c @@ -208,7 +208,7 @@ grub_affs_mount (grub_disk_t disk) rblock = (struct grub_affs_rblock *) rootblock; /* Read the rootblock. */ - grub_disk_read (disk, (disk->total_sectors >> 1) + blocksize, 0, + grub_disk_read (disk, grub_be_to_cpu32 (data->bblock.rootblock), 0, GRUB_DISK_SECTOR_SIZE * 16, rootblock); if (grub_errno) goto fail; @@ -240,7 +240,7 @@ grub_affs_mount (grub_disk_t disk) data->disk = disk; data->htsize = grub_be_to_cpu32 (rblock->htsize); data->diropen.data = data; - data->diropen.block = (disk->total_sectors >> 1); + data->diropen.block = grub_be_to_cpu32 (data->bblock.rootblock); grub_free (rootblock); @@ -507,7 +507,7 @@ grub_affs_label (grub_device_t device, char **label) { /* The rootblock maps quite well on a file header block, it's something we can use here. */ - grub_disk_read (data->disk, disk->total_sectors >> 1, + grub_disk_read (data->disk, grub_be_to_cpu32 (data->bblock.rootblock), data->blocksize * (GRUB_DISK_SECTOR_SIZE - GRUB_AFFS_FILE_LOCATION), sizeof (file), &file); From e21c35641397325aa9411b41239e4779212ebe0e Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 11 Dec 2010 21:59:22 +0100 Subject: [PATCH 102/869] restructure AFFS fshelp_node-related code --- grub-core/fs/affs.c | 84 ++++++++++++++++++++++++++++----------------- 1 file changed, 53 insertions(+), 31 deletions(-) diff --git a/grub-core/fs/affs.c b/grub-core/fs/affs.c index 40be4b2f6..343af6681 100644 --- a/grub-core/fs/affs.c +++ b/grub-core/fs/affs.c @@ -50,12 +50,20 @@ struct grub_affs_rblock grub_uint32_t hashtable[1]; } __attribute__ ((packed)); +struct grub_affs_time +{ + grub_int32_t day; + grub_uint32_t min; + grub_uint32_t fractions_of_sec; +} __attribute__ ((packed)); + /* The second part of a file header block. */ struct grub_affs_file { grub_uint8_t unused1[12]; grub_uint32_t size; - grub_uint8_t unused2[104]; + grub_uint8_t unused2[92]; + struct grub_affs_time mtime; grub_uint8_t namelen; grub_uint8_t name[30]; grub_uint8_t unused3[33]; @@ -85,9 +93,9 @@ struct grub_affs_file struct grub_fshelp_node { struct grub_affs_data *data; - int block; - int size; - int parent; + grub_disk_addr_t block; + struct grub_fshelp_node *parent; + struct grub_affs_file di; }; /* Information about a "mounted" affs filesystem. */ @@ -154,7 +162,7 @@ grub_affs_read_file (grub_fshelp_node_t node, { return grub_fshelp_read_file (node->data->disk, node, read_hook, pos, len, buf, grub_affs_read_block, - node->size, 0); + grub_be_to_cpu32 (node->di.size), 0); } @@ -241,6 +249,8 @@ grub_affs_mount (grub_disk_t disk) data->htsize = grub_be_to_cpu32 (rblock->htsize); data->diropen.data = data; data->diropen.block = grub_be_to_cpu32 (data->bblock.rootblock); + data->diropen.parent = NULL; + grub_memcpy (&data->diropen.di, rootblock, sizeof (data->diropen.di)); grub_free (rootblock); @@ -291,12 +301,15 @@ grub_affs_iterate_dir (grub_fshelp_node_t dir, struct grub_affs_data *data = dir->data; grub_uint32_t *hashtable; - auto int NESTED_FUNC_ATTR grub_affs_create_node (const char *name, int block, - int size, int type); + auto int NESTED_FUNC_ATTR grub_affs_create_node (const char *name, + grub_disk_addr_t block, + const struct grub_affs_file *fil); - int NESTED_FUNC_ATTR grub_affs_create_node (const char *name, int block, - int size, int type) + int NESTED_FUNC_ATTR grub_affs_create_node (const char *name, + grub_disk_addr_t block, + const struct grub_affs_file *fil) { + int type; node = grub_malloc (sizeof (*node)); if (!node) { @@ -304,10 +317,19 @@ grub_affs_iterate_dir (grub_fshelp_node_t dir, return 1; } + if ((int) grub_be_to_cpu32 (fil->type) == GRUB_AFFS_FILETYPE_DIR) + type = GRUB_FSHELP_REG; + else if (grub_be_to_cpu32 (fil->type) == GRUB_AFFS_FILETYPE_REG) + type = GRUB_FSHELP_DIR; + else if (grub_be_to_cpu32 (fil->type) == GRUB_AFFS_FILETYPE_SYMLINK) + type = GRUB_FSHELP_SYMLINK; + else + type = GRUB_FSHELP_UNKNOWN; + node->data = data; - node->size = size; node->block = block; - node->parent = grub_be_to_cpu32 (file.parent); + node->di = *fil; + node->parent = dir; if (hook (name, type, node)) { @@ -317,6 +339,24 @@ grub_affs_iterate_dir (grub_fshelp_node_t dir, return 0; } + /* Create the directory entries for `.' and `..'. */ + node = grub_malloc (sizeof (*node)); + if (!node) + return 1; + + *node = *dir; + if (hook (".", GRUB_FSHELP_DIR, node)) + return 1; + if (dir->parent) + { + node = grub_malloc (sizeof (*node)); + if (!node) + return 1; + *node = *dir->parent; + if (hook ("..", GRUB_FSHELP_DIR, node)) + return 1; + } + hashtable = grub_malloc (data->htsize * sizeof (*hashtable)); if (!hashtable) return 1; @@ -326,16 +366,8 @@ grub_affs_iterate_dir (grub_fshelp_node_t dir, if (grub_errno) goto fail; - /* Create the directory entries for `.' and `..'. */ - if (grub_affs_create_node (".", dir->block, dir->size, GRUB_FSHELP_DIR)) - return 1; - if (grub_affs_create_node ("..", dir->parent ? dir->parent : dir->block, - dir->size, GRUB_FSHELP_DIR)) - return 1; - for (i = 0; i < data->htsize; i++) { - enum grub_fshelp_filetype type; grub_uint64_t next; if (!hashtable[i]) @@ -356,17 +388,7 @@ grub_affs_iterate_dir (grub_fshelp_node_t dir, file.name[file.namelen] = '\0'; - if ((int) grub_be_to_cpu32 (file.type) == GRUB_AFFS_FILETYPE_DIR) - type = GRUB_FSHELP_REG; - else if (grub_be_to_cpu32 (file.type) == GRUB_AFFS_FILETYPE_REG) - type = GRUB_FSHELP_DIR; - else if (grub_be_to_cpu32 (file.type) == GRUB_AFFS_FILETYPE_SYMLINK) - type = GRUB_FSHELP_SYMLINK; - else - type = GRUB_FSHELP_UNKNOWN; - - if (grub_affs_create_node ((char *) (file.name), next, - grub_be_to_cpu32 (file.size), type)) + if (grub_affs_create_node ((char *) (file.name), next, &file)) return 1; next = grub_be_to_cpu32 (file.next); @@ -401,7 +423,7 @@ grub_affs_open (struct grub_file *file, const char *name) if (grub_errno) goto fail; - file->size = fdiro->size; + file->size = grub_be_to_cpu32 (fdiro->di.size); data->diropen = *fdiro; grub_free (fdiro); From 790aaa8c9f63a151c3cf45ea5d907c10174a2940 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 11 Dec 2010 22:02:22 +0100 Subject: [PATCH 103/869] AFFS mtime support --- grub-core/fs/affs.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/grub-core/fs/affs.c b/grub-core/fs/affs.c index 343af6681..e4b487a7e 100644 --- a/grub-core/fs/affs.c +++ b/grub-core/fs/affs.c @@ -54,7 +54,7 @@ struct grub_affs_time { grub_int32_t day; grub_uint32_t min; - grub_uint32_t fractions_of_sec; + grub_uint32_t hz; } __attribute__ ((packed)); /* The second part of a file header block. */ @@ -487,6 +487,11 @@ grub_affs_dir (grub_device_t device, const char *path, struct grub_dirhook_info info; grub_memset (&info, 0, sizeof (info)); info.dir = ((filetype & GRUB_FSHELP_TYPE_MASK) == GRUB_FSHELP_DIR); + info.mtimeset = 1; + info.mtime = grub_be_to_cpu32 (node->di.mtime.day) * 86400 + + grub_be_to_cpu32 (node->di.mtime.min) * 60 + + grub_be_to_cpu32 (node->di.mtime.hz) / 50 + + 8 * 365 * 86400 + 86400 * 2; grub_free (node); return hook (filename, &info); } From bd1de4341b4bc6cc1e616674a3fc1ff1c12120fc Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 11 Dec 2010 22:33:34 +0100 Subject: [PATCH 104/869] explicitly declare SFS as not installable --- grub-core/fs/sfs.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/grub-core/fs/sfs.c b/grub-core/fs/sfs.c index 4a5005908..b49420de1 100644 --- a/grub-core/fs/sfs.c +++ b/grub-core/fs/sfs.c @@ -579,6 +579,9 @@ static struct grub_fs grub_sfs_fs = .read = grub_sfs_read, .close = grub_sfs_close, .label = grub_sfs_label, +#ifdef GRUB_UTIL + .reserved_first_sector = 0, +#endif .next = 0 }; From 7b32d83d7834b4f36fbbbff7c526a07f1879c5b0 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 11 Dec 2010 22:48:29 +0100 Subject: [PATCH 105/869] SFS mtime support --- grub-core/fs/sfs.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/grub-core/fs/sfs.c b/grub-core/fs/sfs.c index b49420de1..dc4fbd45c 100644 --- a/grub-core/fs/sfs.c +++ b/grub-core/fs/sfs.c @@ -66,7 +66,7 @@ struct grub_sfs_obj grub_uint32_t dir_objc; } dir __attribute__ ((packed)); } file_dir; - grub_uint8_t unused3[4]; + grub_uint32_t mtime; grub_uint8_t type; grub_uint8_t filename[1]; grub_uint8_t comment[1]; @@ -119,6 +119,7 @@ struct grub_fshelp_node struct grub_sfs_data *data; int block; int size; + grub_uint32_t mtime; }; /* Information about a "mounted" sfs filesystem. */ @@ -355,10 +356,12 @@ grub_sfs_iterate_dir (grub_fshelp_node_t dir, int pos; auto int NESTED_FUNC_ATTR grub_sfs_create_node (const char *name, int block, - int size, int type); + int size, int type, + grub_uint32_t mtime); int NESTED_FUNC_ATTR grub_sfs_create_node (const char *name, int block, - int size, int type) + int size, int type, + grub_uint32_t mtime) { node = grub_malloc (sizeof (*node)); if (!node) @@ -367,6 +370,7 @@ grub_sfs_iterate_dir (grub_fshelp_node_t dir, node->data = data; node->size = size; node->block = block; + node->mtime = mtime; return hook (name, type, node); } @@ -426,7 +430,7 @@ grub_sfs_iterate_dir (grub_fshelp_node_t dir, if (grub_sfs_create_node (filename, block, grub_be_to_cpu32 (obj->file_dir.file.size), - type)) + type, grub_be_to_cpu32 (obj->mtime))) { grub_free (objc_data); return 1; @@ -525,6 +529,8 @@ grub_sfs_dir (grub_device_t device, const char *path, struct grub_dirhook_info info; grub_memset (&info, 0, sizeof (info)); info.dir = ((filetype & GRUB_FSHELP_TYPE_MASK) == GRUB_FSHELP_DIR); + info.mtime = node->mtime + 8 * 365 * 86400 + 86400 * 2; + info.mtimeset = 1; grub_free (node); return hook (filename, &info); } From 0e5507c411c63bdbddd2fcf1c6628a8ec29c87a4 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 12 Dec 2010 01:00:33 +0100 Subject: [PATCH 106/869] mtime support for ntfs --- grub-core/fs/ntfs.c | 8 ++++++++ include/grub/ntfs.h | 1 + 2 files changed, 9 insertions(+) diff --git a/grub-core/fs/ntfs.c b/grub-core/fs/ntfs.c index 414f6513d..7a5e2b158 100644 --- a/grub-core/fs/ntfs.c +++ b/grub-core/fs/ntfs.c @@ -610,6 +610,10 @@ list_file (struct grub_ntfs_file *diro, char *pos, fdiro->data = diro->data; fdiro->ino = u32at (pos, 0); + if (u64at (pos, 0x20) > u64at (pos, 0x28)) + fdiro->mtime = u64at (pos, 0x20); + else + fdiro->mtime = u64at (pos, 0x28); ustr = grub_malloc (ns * 4 + 1); if (ustr == NULL) @@ -880,6 +884,10 @@ grub_ntfs_dir (grub_device_t device, const char *path, struct grub_dirhook_info info; grub_memset (&info, 0, sizeof (info)); info.dir = ((filetype & GRUB_FSHELP_TYPE_MASK) == GRUB_FSHELP_DIR); + info.mtimeset = 1; + info.mtime = grub_divmod64 (node->mtime, 10000000, 0) + - 86400ULL * 365 * (1970 - 1601) + - 86400ULL * ((1970 - 1601) / 4) + 86400ULL * ((1970 - 1601) / 100); grub_free (node); return hook (filename, &info); } diff --git a/include/grub/ntfs.h b/include/grub/ntfs.h index 31b99398b..0a089b3c0 100644 --- a/include/grub/ntfs.h +++ b/include/grub/ntfs.h @@ -135,6 +135,7 @@ struct grub_fshelp_node struct grub_ntfs_data *data; char *buf; grub_uint64_t size; + grub_uint64_t mtime; grub_uint32_t ino; int inode_read; struct grub_ntfs_attr attr; From 198cae0c965abe97370b13d67e777f1136d4a1c2 Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Mon, 13 Dec 2010 13:58:53 +0000 Subject: [PATCH 107/869] Fix border repainting. * grub-core/term/gfxterm.c (dirty_region_add): When a repaint is already scheduled, merge the virtual screen with the requested region rather than repainting only the virtual screen. --- ChangeLog.parse-color | 6 ++++++ grub-core/term/gfxterm.c | 18 ++++++++++++++---- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/ChangeLog.parse-color b/ChangeLog.parse-color index ccba06d3c..941cd5aad 100644 --- a/ChangeLog.parse-color +++ b/ChangeLog.parse-color @@ -39,3 +39,9 @@ function. (GRUB_MOD_INIT): Register background_color command. (GRUB_MOD_FINI): Unregister background_color command. + + Fix border repainting. + + * grub-core/term/gfxterm.c (dirty_region_add): When a repaint is + already scheduled, merge the virtual screen with the requested + region rather than repainting only the virtual screen. diff --git a/grub-core/term/gfxterm.c b/grub-core/term/gfxterm.c index 93367f2bb..c914f8d2c 100644 --- a/grub-core/term/gfxterm.c +++ b/grub-core/term/gfxterm.c @@ -539,10 +539,20 @@ dirty_region_add (int x, int y, unsigned int width, unsigned int height) if (repaint_scheduled) { - x = virtual_screen.offset_x; - y = virtual_screen.offset_y; - width = virtual_screen.width; - height = virtual_screen.height; + if (x > (int)virtual_screen.offset_x) + { + width += virtual_screen.offset_x - x; + x = virtual_screen.offset_x; + } + if (y > (int)virtual_screen.offset_y) + { + height += virtual_screen.offset_y - y; + y = virtual_screen.offset_y; + } + if (width < virtual_screen.width) + width = virtual_screen.width; + if (height < virtual_screen.height) + height = virtual_screen.height; repaint_scheduled = 0; repaint_was_scheduled = 1; } From 159b4a8bb76f98d294fac139b4f3f4e21c03a03e Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Tue, 14 Dec 2010 12:28:36 +0000 Subject: [PATCH 108/869] (redraw_screen_rect): Allow blend/replace of text layer to be controlled independently from whether there is a background bitmap. (grub_gfxterm_fullscreen): Change blend_text_bg when changing bitmap. (destroy_window): Likewise. (grub_gfxterm_background_image_cmd): Likewise. --- ChangeLog.parse-color | 6 +++++ grub-core/term/gfxterm.c | 55 ++++++++++++++++------------------------ 2 files changed, 28 insertions(+), 33 deletions(-) diff --git a/ChangeLog.parse-color b/ChangeLog.parse-color index 941cd5aad..b241f3b73 100644 --- a/ChangeLog.parse-color +++ b/ChangeLog.parse-color @@ -39,6 +39,12 @@ function. (GRUB_MOD_INIT): Register background_color command. (GRUB_MOD_FINI): Unregister background_color command. + (redraw_screen_rect): Allow blend/replace of text layer to be + controlled independently from whether there is a background bitmap. + (grub_gfxterm_fullscreen): Change blend_text_bg when changing + bitmap. + (destroy_window): Likewise. + (grub_gfxterm_background_image_cmd): Likewise. Fix border repainting. diff --git a/grub-core/term/gfxterm.c b/grub-core/term/gfxterm.c index c914f8d2c..108ce941a 100644 --- a/grub-core/term/gfxterm.c +++ b/grub-core/term/gfxterm.c @@ -128,6 +128,7 @@ static struct grub_video_render_target *text_layer; static unsigned int bitmap_width; static unsigned int bitmap_height; static struct grub_video_bitmap *bitmap; +static int blend_text_bg; static struct grub_dirty_region dirty_region; @@ -344,6 +345,7 @@ grub_gfxterm_fullscreen (void) grub_video_fill_rect (color, 0, 0, mode_info.width, mode_info.height); } bitmap = 0; + blend_text_bg = 0; /* Select the font to use. */ font_name = grub_env_get ("gfxterm_font"); @@ -396,6 +398,7 @@ destroy_window (void) { grub_video_bitmap_destroy (bitmap); bitmap = 0; + blend_text_bg = 0; } repaint_callback = 0; @@ -481,26 +484,27 @@ redraw_screen_rect (unsigned int x, unsigned int y, /* Render background layer. */ grub_video_fill_rect (color, x, ty, width, h); } - - /* Render text layer as blended. */ - grub_video_blit_render_target (text_layer, GRUB_VIDEO_BLIT_BLEND, x, y, - x - virtual_screen.offset_x, - y - virtual_screen.offset_y, - width, height); } else { /* Render background layer. */ color = virtual_screen.bg_color_display; grub_video_fill_rect (color, x, y, width, height); - - /* Render text layer as replaced (to get texts background color). */ - grub_video_blit_render_target (text_layer, GRUB_VIDEO_BLIT_REPLACE, x, y, - x - virtual_screen.offset_x, - y - virtual_screen.offset_y, - width, height); } + if (blend_text_bg) + /* Render text layer as blended. */ + grub_video_blit_render_target (text_layer, GRUB_VIDEO_BLIT_BLEND, x, y, + x - virtual_screen.offset_x, + y - virtual_screen.offset_y, + width, height); + else + /* Render text layer as replaced (to get texts background color). */ + grub_video_blit_render_target (text_layer, GRUB_VIDEO_BLIT_REPLACE, x, y, + x - virtual_screen.offset_x, + y - virtual_screen.offset_y, + width, height); + /* Restore saved viewport. */ grub_video_set_viewport (saved_view.x, saved_view.y, saved_view.width, saved_view.height); @@ -1137,6 +1141,7 @@ grub_gfxterm_background_image_cmd (grub_extcmd_context_t ctxt, { grub_video_bitmap_destroy (bitmap); bitmap = 0; + blend_text_bg = 0; /* Mark whole screen as dirty. */ dirty_region_add (0, 0, window.width, window.height); @@ -1169,6 +1174,7 @@ grub_gfxterm_background_image_cmd (grub_extcmd_context_t ctxt, /* Replace the original bitmap with the scaled one. */ grub_video_bitmap_destroy (bitmap); bitmap = scaled_bitmap; + blend_text_bg = 1; } } } @@ -1195,8 +1201,6 @@ grub_gfxterm_background_color_cmd (grub_command_t cmd __attribute__ ((unused)), int argc, char **args) { grub_video_rgba_color_t color; - grub_uint8_t *data; - unsigned int i; if (argc != 1) return grub_error (GRUB_ERR_BAD_ARGUMENT, "missing operand"); @@ -1218,25 +1222,10 @@ grub_gfxterm_background_color_cmd (grub_command_t cmd __attribute__ ((unused)), dirty_region_add (0, 0, window.width, window.height); } - /* Create a filled bitmap so that we get suitable text blending. */ - grub_video_bitmap_create (&bitmap, window.width, window.height, - GRUB_VIDEO_BLIT_FORMAT_RGB_888); - if (grub_errno != GRUB_ERR_NONE) - return grub_errno; - - data = bitmap->data; - for (i = 0; i < window.height * window.width; i++) - { - *data++ = color.red; - *data++ = color.green; - *data++ = color.blue; - } - - bitmap_width = window.width; - bitmap_height = window.height; - - /* Set the border color. */ - virtual_screen.bg_color_display = grub_video_map_rgba_color (color); + /* Set the background and border colors. */ + virtual_screen.bg_color = grub_video_map_rgba_color (color); + virtual_screen.bg_color_display = virtual_screen.bg_color; + blend_text_bg = 1; /* Mark whole screen as dirty. */ dirty_region_add (0, 0, window.width, window.height); From e03f549b3e11018b0ec0f44465f6bf5ca98ca993 Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Tue, 14 Dec 2010 16:22:19 +0000 Subject: [PATCH 109/869] Preferred resolution detection for VBE. * grub-core/video/i386/pc/vbe.c (grub_vbe_bios_get_flat_panel_info): New function. (grub_vbe_bios_get_ddc_capabilities): Likewise. (grub_vbe_bios_read_edid): Likewise. (grub_vbe_edid_checksum): Likewise. (grub_vbe_get_preferred_mode): Likewise. Try EDID followed by the Flat Panel extension, in line with the X.org VESA driver. (grub_video_vbe_setup): When the mode is "auto", try to get the preferred mode from VBE, and use the largest mode that is no larger than the preferred mode (some BIOSes expose a preferred mode that is not in their mode list!). If this fails, fall back to 640x480 as a safe conservative choice. * include/grub/i386/pc/vbe.h (struct grub_vbe_flat_panel_info): New structure. (struct grub_vbe_edid_info): Likewise. (grub_vbe_bios_get_flat_panel_info): Add prototype. (grub_vbe_bios_get_ddc_capabilities): Likewise. (grub_vbe_bios_read_edid): Likewise. * util/grub.d/00_header.in (GRUB_GFXMODE): Default to "auto". This is more appropriate on a wider range of platforms than 640x480. --- ChangeLog.vbe-autodetect | 25 ++++++ grub-core/video/i386/pc/vbe.c | 150 +++++++++++++++++++++++++++++++++- include/grub/i386/pc/vbe.h | 84 +++++++++++++++++++ util/grub.d/00_header.in | 2 +- 4 files changed, 256 insertions(+), 5 deletions(-) create mode 100644 ChangeLog.vbe-autodetect diff --git a/ChangeLog.vbe-autodetect b/ChangeLog.vbe-autodetect new file mode 100644 index 000000000..7d16ebee2 --- /dev/null +++ b/ChangeLog.vbe-autodetect @@ -0,0 +1,25 @@ +2010-12-14 Colin Watson + + Preferred resolution detection for VBE. + + * grub-core/video/i386/pc/vbe.c (grub_vbe_bios_get_flat_panel_info): + New function. + (grub_vbe_bios_get_ddc_capabilities): Likewise. + (grub_vbe_bios_read_edid): Likewise. + (grub_vbe_edid_checksum): Likewise. + (grub_vbe_get_preferred_mode): Likewise. Try EDID followed by the + Flat Panel extension, in line with the X.org VESA driver. + (grub_video_vbe_setup): When the mode is "auto", try to get the + preferred mode from VBE, and use the largest mode that is no larger + than the preferred mode (some BIOSes expose a preferred mode that is + not in their mode list!). If this fails, fall back to 640x480 as a + safe conservative choice. + * include/grub/i386/pc/vbe.h (struct grub_vbe_flat_panel_info): New + structure. + (struct grub_vbe_edid_info): Likewise. + (grub_vbe_bios_get_flat_panel_info): Add prototype. + (grub_vbe_bios_get_ddc_capabilities): Likewise. + (grub_vbe_bios_read_edid): Likewise. + + * util/grub.d/00_header.in (GRUB_GFXMODE): Default to "auto". This + is more appropriate on a wider range of platforms than 640x480. diff --git a/grub-core/video/i386/pc/vbe.c b/grub-core/video/i386/pc/vbe.c index 2ddb4ca80..1794addae 100644 --- a/grub-core/video/i386/pc/vbe.c +++ b/grub-core/video/i386/pc/vbe.c @@ -273,6 +273,56 @@ grub_vbe_bios_get_pm_interface (grub_uint16_t *segment, grub_uint16_t *offset, return regs.eax & 0xffff; } +/* Call VESA BIOS 0x4f11 to get flat panel information, return status. */ +grub_vbe_status_t +grub_vbe_bios_get_flat_panel_info (struct grub_vbe_flat_panel_info *flat_panel_info) +{ + struct grub_bios_int_registers regs; + + regs.eax = 0x4f11; + regs.ebx = 0x0001; + regs.es = (((grub_addr_t) flat_panel_info) & 0xffff0000) >> 4; + regs.edi = ((grub_addr_t) flat_panel_info) & 0xffff; + regs.flags = GRUB_CPU_INT_FLAGS_DEFAULT; + grub_bios_interrupt (0x10, ®s); + return regs.eax & 0xffff; +} + +/* Call VESA BIOS 0x4f15 to get DDC availability, return status. */ +grub_vbe_status_t +grub_vbe_bios_get_ddc_capabilities (grub_uint8_t *level) +{ + struct grub_bios_int_registers regs; + + regs.eax = 0x4f15; + regs.ebx = 0x0000; + regs.ecx = 0x0000; + regs.es = 0x0000; + regs.edi = 0x0000; + regs.flags = GRUB_CPU_INT_FLAGS_DEFAULT; + grub_bios_interrupt (0x10, ®s); + + *level = regs.ebx & 0xff; + return regs.eax & 0xffff; +} + +/* Call VESA BIOS 0x4f15 to read EDID information, return status. */ +grub_vbe_status_t +grub_vbe_bios_read_edid (struct grub_vbe_edid_info *edid_info) +{ + struct grub_bios_int_registers regs; + + regs.eax = 0x4f15; + regs.ebx = 0x0001; + regs.ecx = 0x0000; + regs.edx = 0x0000; + regs.es = (((grub_addr_t) edid_info) & 0xffff0000) >> 4; + regs.edi = ((grub_addr_t) edid_info) & 0xffff; + regs.flags = GRUB_CPU_INT_FLAGS_DEFAULT; + grub_bios_interrupt (0x10, ®s); + return regs.eax & 0xffff; +} + grub_err_t grub_vbe_probe (struct grub_vbe_info_block *info_block) @@ -327,6 +377,70 @@ grub_vbe_probe (struct grub_vbe_info_block *info_block) return GRUB_ERR_NONE; } +static grub_err_t +grub_vbe_edid_checksum (struct grub_vbe_edid_info *edid_info) +{ + const char *edid_bytes = (const char *) edid_info; + int i; + char checksum = 0; + + /* Check EDID checksum. */ + for (i = 0; i < 128; ++i) + checksum += edid_bytes[i]; + + if (checksum != 0) + return grub_error (GRUB_ERR_BAD_DEVICE, + "invalid EDID checksum %d", checksum); + + grub_errno = GRUB_ERR_NONE; + return grub_errno; +} + +static grub_err_t +grub_vbe_get_preferred_mode (unsigned int *width, unsigned int *height) +{ + grub_vbe_status_t status; + grub_uint8_t ddc_level; + struct grub_vbe_edid_info edid_info; + struct grub_vbe_flat_panel_info flat_panel_info; + + if (controller_info.version >= 0x200 + && (grub_vbe_bios_get_ddc_capabilities (&ddc_level) & 0xff) + == GRUB_VBE_STATUS_OK) + { + status = grub_vbe_bios_read_edid (&edid_info); + /* Bit 1 in the Feature Support field indicates that the first + Detailed Timing Description is the preferred timing mode. */ + if (status == GRUB_VBE_STATUS_OK + && grub_vbe_edid_checksum (&edid_info) == GRUB_ERR_NONE + && edid_info.version == 1 /* we don't understand later versions */ + && (edid_info.feature_support + & GRUB_VBE_EDID_FEATURE_PREFERRED_TIMING_MODE) + && edid_info.detailed_timings[0].pixel_clock) + { + *width = edid_info.detailed_timings[0].horizontal_active_lo + | (((unsigned int) + (edid_info.detailed_timings[0].horizontal_hi & 0xf0)) + << 4); + *height = edid_info.detailed_timings[0].vertical_active_lo + | (((unsigned int) + (edid_info.detailed_timings[0].vertical_hi & 0xf0)) + << 4); + return GRUB_ERR_NONE; + } + } + + status = grub_vbe_bios_get_flat_panel_info (&flat_panel_info); + if (status == GRUB_VBE_STATUS_OK) + { + *width = flat_panel_info.horizontal_size; + *height = flat_panel_info.vertical_size; + return GRUB_ERR_NONE; + } + + return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "cannot get preferred mode"); +} + grub_err_t grub_vbe_set_video_mode (grub_uint32_t vbe_mode, struct grub_vbe_mode_info_block *vbe_mode_info) @@ -695,11 +809,28 @@ grub_video_vbe_setup (unsigned int width, unsigned int height, struct grub_vbe_mode_info_block best_vbe_mode_info; grub_uint32_t best_vbe_mode = 0; int depth; + int preferred_mode = 0; /* Decode depth from mode_type. If it is zero, then autodetect. */ depth = (mode_type & GRUB_VIDEO_MODE_TYPE_DEPTH_MASK) >> GRUB_VIDEO_MODE_TYPE_DEPTH_POS; + if (width == 0 && height == 0) + { + grub_vbe_get_preferred_mode (&width, &height); + if (grub_errno == GRUB_ERR_NONE) + preferred_mode = 1; + else + { + /* Fall back to 640x480. This is conservative, but the largest + mode supported by the graphics card may not be safe for the + display device. */ + grub_errno = GRUB_ERR_NONE; + width = 640; + height = 480; + } + } + /* Walk thru mode list and try to find matching mode. */ for (p = vbe_mode_list; *p != 0xFFFF; p++) { @@ -742,10 +873,21 @@ grub_video_vbe_setup (unsigned int width, unsigned int height, /* Unsupported bitdepth . */ continue; - if (((vbe_mode_info.x_resolution != width) - || (vbe_mode_info.y_resolution != height)) && width != 0 && height != 0) - /* Non matching resolution. */ - continue; + if (preferred_mode) + { + if (vbe_mode_info.x_resolution > width + || vbe_mode_info.y_resolution > height) + /* Resolution exceeds that of preferred mode. */ + continue; + } + else + { + if (((vbe_mode_info.x_resolution != width) + || (vbe_mode_info.y_resolution != height)) + && width != 0 && height != 0) + /* Non matching resolution. */ + continue; + } /* Check if user requested RGB or index color mode. */ if ((mode_mask & GRUB_VIDEO_MODE_TYPE_COLOR_MASK) != 0) diff --git a/include/grub/i386/pc/vbe.h b/include/grub/i386/pc/vbe.h index fba3ee642..5be34fdec 100644 --- a/include/grub/i386/pc/vbe.h +++ b/include/grub/i386/pc/vbe.h @@ -169,6 +169,81 @@ struct grub_vbe_palette_data grub_uint8_t alignment; } __attribute__ ((packed)); +struct grub_vbe_flat_panel_info +{ + grub_uint16_t horizontal_size; + grub_uint16_t vertical_size; + grub_uint16_t panel_type; + grub_uint8_t red_bpp; + grub_uint8_t green_bpp; + grub_uint8_t blue_bpp; + grub_uint8_t reserved_bpp; + grub_uint32_t reserved_offscreen_mem_size; + grub_vbe_farptr_t reserved_offscreen_mem_ptr; + + grub_uint8_t reserved[14]; +} __attribute__ ((packed)); + +struct grub_vbe_edid_info +{ + grub_uint8_t header[8]; + grub_uint16_t manufacturer_id; + grub_uint16_t product_id; + grub_uint32_t serial_number; + grub_uint8_t week_of_manufacture; + grub_uint8_t year_of_manufacture; + grub_uint8_t version; + grub_uint8_t revision; + + grub_uint8_t video_input_definition; + grub_uint8_t max_horizontal_image_size; + grub_uint8_t max_vertical_image_size; + grub_uint8_t display_gamma; + grub_uint8_t feature_support; +#define GRUB_VBE_EDID_FEATURE_PREFERRED_TIMING_MODE (1 << 1) + + grub_uint8_t red_green_lo; + grub_uint8_t blue_white_lo; + grub_uint8_t red_x_hi; + grub_uint8_t red_y_hi; + grub_uint8_t green_x_hi; + grub_uint8_t green_y_hi; + grub_uint8_t blue_x_hi; + grub_uint8_t blue_y_hi; + grub_uint8_t white_x_hi; + grub_uint8_t white_y_hi; + + grub_uint8_t established_timings_1; + grub_uint8_t established_timings_2; + grub_uint8_t manufacturer_reserved_timings; + + grub_uint16_t standard_timings[8]; + + struct { + grub_uint16_t pixel_clock; + /* Only valid if the pixel clock is non-null. */ + grub_uint8_t horizontal_active_lo; + grub_uint8_t horizontal_blanking_lo; + grub_uint8_t horizontal_hi; + grub_uint8_t vertical_active_lo; + grub_uint8_t vertical_blanking_lo; + grub_uint8_t vertical_hi; + grub_uint8_t horizontal_sync_offset_lo; + grub_uint8_t horizontal_sync_pulse_width_lo; + grub_uint8_t vertical_sync_lo; + grub_uint8_t sync_hi; + grub_uint8_t horizontal_image_size_lo; + grub_uint8_t vertical_image_size_lo; + grub_uint8_t image_size_hi; + grub_uint8_t horizontal_border; + grub_uint8_t vertical_border; + grub_uint8_t flags; + } detailed_timings[4]; + + grub_uint8_t extension_flag; + grub_uint8_t checksum; +} __attribute__ ((packed)); + /* Prototypes for helper functions. */ /* Call VESA BIOS 0x4f00 to get VBE Controller Information, return status. */ grub_vbe_status_t @@ -197,6 +272,15 @@ grub_vbe_bios_get_scanline_length (grub_uint32_t *length); grub_vbe_status_t grub_vbe_bios_get_display_start (grub_uint32_t *x, grub_uint32_t *y); +/* Call VESA BIOS 0x4f11 to get flat panel information, return status. */ +grub_vbe_status_t +grub_vbe_bios_get_flat_panel_info (struct grub_vbe_flat_panel_info *flat_panel_info); +/* Call VESA BIOS 0x4f15 to get DDC availability, return status. */ +grub_vbe_status_t +grub_vbe_bios_get_ddc_capabilities (grub_uint8_t *level); +/* Call VESA BIOS 0x4f15 to read EDID information, return status. */ +grub_vbe_status_t +grub_vbe_bios_read_edid (struct grub_vbe_edid_info *edid_data); grub_vbe_status_t grub_vbe_bios_getset_dac_palette_width (int set, int *width); diff --git a/util/grub.d/00_header.in b/util/grub.d/00_header.in index a596e9c4a..55c686296 100644 --- a/util/grub.d/00_header.in +++ b/util/grub.d/00_header.in @@ -36,7 +36,7 @@ done if [ "x${GRUB_DEFAULT}" = "x" ] ; then GRUB_DEFAULT=0 ; fi if [ "x${GRUB_DEFAULT}" = "xsaved" ] ; then GRUB_DEFAULT='${saved_entry}' ; fi if [ "x${GRUB_TIMEOUT}" = "x" ] ; then GRUB_TIMEOUT=5 ; fi -if [ "x${GRUB_GFXMODE}" = "x" ] ; then GRUB_GFXMODE=640x480 ; fi +if [ "x${GRUB_GFXMODE}" = "x" ] ; then GRUB_GFXMODE=auto ; fi if [ "x${GRUB_DEFAULT_BUTTON}" = "x" ] ; then GRUB_DEFAULT_BUTTON="$GRUB_DEFAULT" ; fi if [ "x${GRUB_DEFAULT_BUTTON}" = "xsaved" ] ; then GRUB_DEFAULT_BUTTON='${saved_entry}' ; fi From 25d884a52a1819792bc97cac9890d44a72446b7c Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Tue, 14 Dec 2010 17:06:32 +0000 Subject: [PATCH 110/869] move generic parts of EDID handling (structure, checksumming) to generic location --- ChangeLog.vbe-autodetect | 7 ++-- grub-core/video/i386/pc/vbe.c | 27 +++------------ grub-core/video/video.c | 19 +++++++++++ include/grub/i386/pc/vbe.h | 64 ++--------------------------------- include/grub/video.h | 62 +++++++++++++++++++++++++++++++++ 5 files changed, 92 insertions(+), 87 deletions(-) diff --git a/ChangeLog.vbe-autodetect b/ChangeLog.vbe-autodetect index 7d16ebee2..0d96fc0a2 100644 --- a/ChangeLog.vbe-autodetect +++ b/ChangeLog.vbe-autodetect @@ -2,11 +2,11 @@ Preferred resolution detection for VBE. + * grub-core/video/video.c (grub_video_edid_checksum): New function. * grub-core/video/i386/pc/vbe.c (grub_vbe_bios_get_flat_panel_info): - New function. + Likewise. (grub_vbe_bios_get_ddc_capabilities): Likewise. (grub_vbe_bios_read_edid): Likewise. - (grub_vbe_edid_checksum): Likewise. (grub_vbe_get_preferred_mode): Likewise. Try EDID followed by the Flat Panel extension, in line with the X.org VESA driver. (grub_video_vbe_setup): When the mode is "auto", try to get the @@ -14,9 +14,10 @@ than the preferred mode (some BIOSes expose a preferred mode that is not in their mode list!). If this fails, fall back to 640x480 as a safe conservative choice. + * include/grub/video.h (struct grub_vbe_edid_info): New structure. + (grub_video_edid_checksum): Add prototype. * include/grub/i386/pc/vbe.h (struct grub_vbe_flat_panel_info): New structure. - (struct grub_vbe_edid_info): Likewise. (grub_vbe_bios_get_flat_panel_info): Add prototype. (grub_vbe_bios_get_ddc_capabilities): Likewise. (grub_vbe_bios_read_edid): Likewise. diff --git a/grub-core/video/i386/pc/vbe.c b/grub-core/video/i386/pc/vbe.c index 1794addae..e2dcc151e 100644 --- a/grub-core/video/i386/pc/vbe.c +++ b/grub-core/video/i386/pc/vbe.c @@ -308,7 +308,7 @@ grub_vbe_bios_get_ddc_capabilities (grub_uint8_t *level) /* Call VESA BIOS 0x4f15 to read EDID information, return status. */ grub_vbe_status_t -grub_vbe_bios_read_edid (struct grub_vbe_edid_info *edid_info) +grub_vbe_bios_read_edid (struct grub_video_edid_info *edid_info) { struct grub_bios_int_registers regs; @@ -377,31 +377,12 @@ grub_vbe_probe (struct grub_vbe_info_block *info_block) return GRUB_ERR_NONE; } -static grub_err_t -grub_vbe_edid_checksum (struct grub_vbe_edid_info *edid_info) -{ - const char *edid_bytes = (const char *) edid_info; - int i; - char checksum = 0; - - /* Check EDID checksum. */ - for (i = 0; i < 128; ++i) - checksum += edid_bytes[i]; - - if (checksum != 0) - return grub_error (GRUB_ERR_BAD_DEVICE, - "invalid EDID checksum %d", checksum); - - grub_errno = GRUB_ERR_NONE; - return grub_errno; -} - static grub_err_t grub_vbe_get_preferred_mode (unsigned int *width, unsigned int *height) { grub_vbe_status_t status; grub_uint8_t ddc_level; - struct grub_vbe_edid_info edid_info; + struct grub_video_edid_info edid_info; struct grub_vbe_flat_panel_info flat_panel_info; if (controller_info.version >= 0x200 @@ -412,10 +393,10 @@ grub_vbe_get_preferred_mode (unsigned int *width, unsigned int *height) /* Bit 1 in the Feature Support field indicates that the first Detailed Timing Description is the preferred timing mode. */ if (status == GRUB_VBE_STATUS_OK - && grub_vbe_edid_checksum (&edid_info) == GRUB_ERR_NONE + && grub_video_edid_checksum (&edid_info) == GRUB_ERR_NONE && edid_info.version == 1 /* we don't understand later versions */ && (edid_info.feature_support - & GRUB_VBE_EDID_FEATURE_PREFERRED_TIMING_MODE) + & GRUB_VIDEO_EDID_FEATURE_PREFERRED_TIMING_MODE) && edid_info.detailed_timings[0].pixel_clock) { *width = edid_info.detailed_timings[0].horizontal_active_lo diff --git a/grub-core/video/video.c b/grub-core/video/video.c index 7a1a446e4..f3ecab94d 100644 --- a/grub-core/video/video.c +++ b/grub-core/video/video.c @@ -374,6 +374,25 @@ grub_video_get_active_render_target (struct grub_video_render_target **target) return grub_video_adapter_active->get_active_render_target (target); } +grub_err_t +grub_video_edid_checksum (struct grub_video_edid_info *edid_info) +{ + const char *edid_bytes = (const char *) edid_info; + int i; + char checksum = 0; + + /* Check EDID checksum. */ + for (i = 0; i < 128; ++i) + checksum += edid_bytes[i]; + + if (checksum != 0) + return grub_error (GRUB_ERR_BAD_DEVICE, + "invalid EDID checksum %d", checksum); + + grub_errno = GRUB_ERR_NONE; + return grub_errno; +} + /* Parse x[x]*/ static grub_err_t parse_modespec (const char *current_mode, int *width, int *height, int *depth) diff --git a/include/grub/i386/pc/vbe.h b/include/grub/i386/pc/vbe.h index 5be34fdec..0422558db 100644 --- a/include/grub/i386/pc/vbe.h +++ b/include/grub/i386/pc/vbe.h @@ -19,6 +19,8 @@ #ifndef GRUB_VBE_MACHINE_HEADER #define GRUB_VBE_MACHINE_HEADER 1 +#include + /* Default video mode to be used. */ #define GRUB_VBE_DEFAULT_VIDEO_MODE 0x101 @@ -184,66 +186,6 @@ struct grub_vbe_flat_panel_info grub_uint8_t reserved[14]; } __attribute__ ((packed)); -struct grub_vbe_edid_info -{ - grub_uint8_t header[8]; - grub_uint16_t manufacturer_id; - grub_uint16_t product_id; - grub_uint32_t serial_number; - grub_uint8_t week_of_manufacture; - grub_uint8_t year_of_manufacture; - grub_uint8_t version; - grub_uint8_t revision; - - grub_uint8_t video_input_definition; - grub_uint8_t max_horizontal_image_size; - grub_uint8_t max_vertical_image_size; - grub_uint8_t display_gamma; - grub_uint8_t feature_support; -#define GRUB_VBE_EDID_FEATURE_PREFERRED_TIMING_MODE (1 << 1) - - grub_uint8_t red_green_lo; - grub_uint8_t blue_white_lo; - grub_uint8_t red_x_hi; - grub_uint8_t red_y_hi; - grub_uint8_t green_x_hi; - grub_uint8_t green_y_hi; - grub_uint8_t blue_x_hi; - grub_uint8_t blue_y_hi; - grub_uint8_t white_x_hi; - grub_uint8_t white_y_hi; - - grub_uint8_t established_timings_1; - grub_uint8_t established_timings_2; - grub_uint8_t manufacturer_reserved_timings; - - grub_uint16_t standard_timings[8]; - - struct { - grub_uint16_t pixel_clock; - /* Only valid if the pixel clock is non-null. */ - grub_uint8_t horizontal_active_lo; - grub_uint8_t horizontal_blanking_lo; - grub_uint8_t horizontal_hi; - grub_uint8_t vertical_active_lo; - grub_uint8_t vertical_blanking_lo; - grub_uint8_t vertical_hi; - grub_uint8_t horizontal_sync_offset_lo; - grub_uint8_t horizontal_sync_pulse_width_lo; - grub_uint8_t vertical_sync_lo; - grub_uint8_t sync_hi; - grub_uint8_t horizontal_image_size_lo; - grub_uint8_t vertical_image_size_lo; - grub_uint8_t image_size_hi; - grub_uint8_t horizontal_border; - grub_uint8_t vertical_border; - grub_uint8_t flags; - } detailed_timings[4]; - - grub_uint8_t extension_flag; - grub_uint8_t checksum; -} __attribute__ ((packed)); - /* Prototypes for helper functions. */ /* Call VESA BIOS 0x4f00 to get VBE Controller Information, return status. */ grub_vbe_status_t @@ -280,7 +222,7 @@ grub_vbe_status_t grub_vbe_bios_get_ddc_capabilities (grub_uint8_t *level); /* Call VESA BIOS 0x4f15 to read EDID information, return status. */ grub_vbe_status_t -grub_vbe_bios_read_edid (struct grub_vbe_edid_info *edid_data); +grub_vbe_bios_read_edid (struct grub_video_edid_info *edid_data); grub_vbe_status_t grub_vbe_bios_getset_dac_palette_width (int set, int *width); diff --git a/include/grub/video.h b/include/grub/video.h index 97bd85bd1..2cf1424c4 100644 --- a/include/grub/video.h +++ b/include/grub/video.h @@ -210,6 +210,66 @@ struct grub_video_palette_data grub_uint8_t a; /* Reserved bits value (0-255). */ }; +struct grub_video_edid_info +{ + grub_uint8_t header[8]; + grub_uint16_t manufacturer_id; + grub_uint16_t product_id; + grub_uint32_t serial_number; + grub_uint8_t week_of_manufacture; + grub_uint8_t year_of_manufacture; + grub_uint8_t version; + grub_uint8_t revision; + + grub_uint8_t video_input_definition; + grub_uint8_t max_horizontal_image_size; + grub_uint8_t max_vertical_image_size; + grub_uint8_t display_gamma; + grub_uint8_t feature_support; +#define GRUB_VIDEO_EDID_FEATURE_PREFERRED_TIMING_MODE (1 << 1) + + grub_uint8_t red_green_lo; + grub_uint8_t blue_white_lo; + grub_uint8_t red_x_hi; + grub_uint8_t red_y_hi; + grub_uint8_t green_x_hi; + grub_uint8_t green_y_hi; + grub_uint8_t blue_x_hi; + grub_uint8_t blue_y_hi; + grub_uint8_t white_x_hi; + grub_uint8_t white_y_hi; + + grub_uint8_t established_timings_1; + grub_uint8_t established_timings_2; + grub_uint8_t manufacturer_reserved_timings; + + grub_uint16_t standard_timings[8]; + + struct { + grub_uint16_t pixel_clock; + /* Only valid if the pixel clock is non-null. */ + grub_uint8_t horizontal_active_lo; + grub_uint8_t horizontal_blanking_lo; + grub_uint8_t horizontal_hi; + grub_uint8_t vertical_active_lo; + grub_uint8_t vertical_blanking_lo; + grub_uint8_t vertical_hi; + grub_uint8_t horizontal_sync_offset_lo; + grub_uint8_t horizontal_sync_pulse_width_lo; + grub_uint8_t vertical_sync_lo; + grub_uint8_t sync_hi; + grub_uint8_t horizontal_image_size_lo; + grub_uint8_t vertical_image_size_lo; + grub_uint8_t image_size_hi; + grub_uint8_t horizontal_border; + grub_uint8_t vertical_border; + grub_uint8_t flags; + } detailed_timings[4]; + + grub_uint8_t extension_flag; + grub_uint8_t checksum; +} __attribute__ ((packed)); + typedef enum grub_video_driver_id { GRUB_VIDEO_DRIVER_NONE, @@ -423,6 +483,8 @@ grub_err_t EXPORT_FUNC (grub_video_set_active_render_target) (struct grub_video_ grub_err_t grub_video_get_active_render_target (struct grub_video_render_target **target); +grub_err_t grub_video_edid_checksum (struct grub_video_edid_info *edid_info); + grub_err_t EXPORT_FUNC (grub_video_set_mode) (const char *modestring, unsigned int modemask, unsigned int modevalue); From 129185cfaae5969be4e49f5d898ed553b18d8502 Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Tue, 14 Dec 2010 18:03:34 +0000 Subject: [PATCH 111/869] move more EDID-handling functions to generic code, and make videoinfo display EDID information --- ChangeLog.vbe-autodetect | 15 +++++++++--- grub-core/commands/videoinfo.c | 31 ++++++++++++++++++++++++ grub-core/video/i386/pc/vbe.c | 36 +++++++++++++--------------- grub-core/video/video.c | 43 ++++++++++++++++++++++++++++++++++ include/grub/video.h | 6 +++++ 5 files changed, 108 insertions(+), 23 deletions(-) diff --git a/ChangeLog.vbe-autodetect b/ChangeLog.vbe-autodetect index 0d96fc0a2..355ce00f6 100644 --- a/ChangeLog.vbe-autodetect +++ b/ChangeLog.vbe-autodetect @@ -3,24 +3,33 @@ Preferred resolution detection for VBE. * grub-core/video/video.c (grub_video_edid_checksum): New function. + (grub_video_get_edid): Likewise. + (grub_video_edid_preferred_mode): Likewise. Try EDID followed by + the Flat Panel extension, in line with the X.org VESA driver. * grub-core/video/i386/pc/vbe.c (grub_vbe_bios_get_flat_panel_info): - Likewise. + New function. (grub_vbe_bios_get_ddc_capabilities): Likewise. (grub_vbe_bios_read_edid): Likewise. - (grub_vbe_get_preferred_mode): Likewise. Try EDID followed by the - Flat Panel extension, in line with the X.org VESA driver. + (grub_vbe_get_preferred_mode): Likewise. (grub_video_vbe_setup): When the mode is "auto", try to get the preferred mode from VBE, and use the largest mode that is no larger than the preferred mode (some BIOSes expose a preferred mode that is not in their mode list!). If this fails, fall back to 640x480 as a safe conservative choice. + (grub_video_vbe_get_edid): New function. + (grub_video_vbe_adapter): Add get_edid. * include/grub/video.h (struct grub_vbe_edid_info): New structure. (grub_video_edid_checksum): Add prototype. + (grub_video_get_edid): Likewise. + (grub_video_edid_preferred_mode): Likewise. * include/grub/i386/pc/vbe.h (struct grub_vbe_flat_panel_info): New structure. (grub_vbe_bios_get_flat_panel_info): Add prototype. (grub_vbe_bios_get_ddc_capabilities): Likewise. (grub_vbe_bios_read_edid): Likewise. + * grub-core/commands/videoinfo.c (print_edid): New function. + (grub_cmd_videoinfo): Print EDID if available. + * util/grub.d/00_header.in (GRUB_GFXMODE): Default to "auto". This is more appropriate on a wider range of platforms than 640x480. diff --git a/grub-core/commands/videoinfo.c b/grub-core/commands/videoinfo.c index 10f77915b..56df943ec 100644 --- a/grub-core/commands/videoinfo.c +++ b/grub-core/commands/videoinfo.c @@ -77,6 +77,30 @@ hook (const struct grub_video_mode_info *info) return 0; } +static void +print_edid (struct grub_video_edid_info *edid_info) +{ + unsigned int edid_width, edid_height; + + if (grub_video_edid_checksum (edid_info)) + { + grub_printf (" EDID checksum invalid\n"); + grub_errno = GRUB_ERR_NONE; + return; + } + + grub_printf (" EDID version: %u.%u\n", + edid_info->version, edid_info->revision); + if (grub_video_edid_preferred_mode (edid_info, &edid_width, &edid_height) + == GRUB_ERR_NONE) + grub_printf (" Preferred mode: %ux%u\n", edid_width, edid_height); + else + { + grub_printf (" No preferred mode available\n"); + grub_errno = GRUB_ERR_NONE; + } +} + static grub_err_t grub_cmd_videoinfo (grub_command_t cmd __attribute__ ((unused)), int argc, char **args) @@ -120,6 +144,8 @@ grub_cmd_videoinfo (grub_command_t cmd __attribute__ ((unused)), FOR_VIDEO_ADAPTERS (adapter) { + struct grub_video_edid_info edid_info; + grub_printf ("Adapter '%s':\n", adapter->name); if (!adapter->iterate) @@ -143,6 +169,11 @@ grub_cmd_videoinfo (grub_command_t cmd __attribute__ ((unused)), adapter->iterate (hook); + if (adapter->get_edid (&edid_info) == GRUB_ERR_NONE) + print_edid (&edid_info); + else + grub_errno = GRUB_ERR_NONE; + if (adapter->id != id) { if (adapter->fini ()) diff --git a/grub-core/video/i386/pc/vbe.c b/grub-core/video/i386/pc/vbe.c index e2dcc151e..c6bb733a9 100644 --- a/grub-core/video/i386/pc/vbe.c +++ b/grub-core/video/i386/pc/vbe.c @@ -389,26 +389,12 @@ grub_vbe_get_preferred_mode (unsigned int *width, unsigned int *height) && (grub_vbe_bios_get_ddc_capabilities (&ddc_level) & 0xff) == GRUB_VBE_STATUS_OK) { - status = grub_vbe_bios_read_edid (&edid_info); - /* Bit 1 in the Feature Support field indicates that the first - Detailed Timing Description is the preferred timing mode. */ - if (status == GRUB_VBE_STATUS_OK - && grub_video_edid_checksum (&edid_info) == GRUB_ERR_NONE - && edid_info.version == 1 /* we don't understand later versions */ - && (edid_info.feature_support - & GRUB_VIDEO_EDID_FEATURE_PREFERRED_TIMING_MODE) - && edid_info.detailed_timings[0].pixel_clock) - { - *width = edid_info.detailed_timings[0].horizontal_active_lo - | (((unsigned int) - (edid_info.detailed_timings[0].horizontal_hi & 0xf0)) - << 4); - *height = edid_info.detailed_timings[0].vertical_active_lo - | (((unsigned int) - (edid_info.detailed_timings[0].vertical_hi & 0xf0)) - << 4); - return GRUB_ERR_NONE; - } + if (grub_video_get_edid (&edid_info) == GRUB_ERR_NONE + && grub_video_edid_preferred_mode (&edid_info, width, height) + == GRUB_ERR_NONE) + return GRUB_ERR_NONE; + + grub_errno = GRUB_ERR_NONE; } status = grub_vbe_bios_get_flat_panel_info (&flat_panel_info); @@ -978,6 +964,15 @@ grub_video_vbe_get_info_and_fini (struct grub_video_mode_info *mode_info, return grub_video_fb_get_info_and_fini (mode_info, framebuf); } +static grub_err_t +grub_video_vbe_get_edid (struct grub_video_edid_info *edid_info) +{ + if (grub_vbe_bios_read_edid (edid_info) != GRUB_VBE_STATUS_OK) + return grub_error (GRUB_ERR_BAD_DEVICE, "EDID information not available"); + + return GRUB_ERR_NONE; +} + static void grub_video_vbe_print_adapter_specific_info (void) { @@ -1022,6 +1017,7 @@ static struct grub_video_adapter grub_video_vbe_adapter = .set_active_render_target = grub_video_fb_set_active_render_target, .get_active_render_target = grub_video_fb_get_active_render_target, .iterate = grub_video_vbe_iterate, + .get_edid = grub_video_vbe_get_edid, .print_adapter_specific_info = grub_video_vbe_print_adapter_specific_info, .next = 0 diff --git a/grub-core/video/video.c b/grub-core/video/video.c index f3ecab94d..84e98bb67 100644 --- a/grub-core/video/video.c +++ b/grub-core/video/video.c @@ -393,6 +393,49 @@ grub_video_edid_checksum (struct grub_video_edid_info *edid_info) return grub_errno; } +grub_err_t +grub_video_get_edid (struct grub_video_edid_info *edid_info) +{ + if (! grub_video_adapter_active) + return grub_error (GRUB_ERR_BAD_DEVICE, "no video mode activated"); + + if (! grub_video_adapter_active->get_edid) + return grub_error (GRUB_ERR_BAD_DEVICE, + "EDID information unavailable for this video mode"); + + if (grub_video_adapter_active->get_edid (edid_info) != GRUB_ERR_NONE) + return grub_errno; + if (grub_video_edid_checksum (edid_info) != GRUB_ERR_NONE) + return grub_errno; + + return GRUB_ERR_NONE; +} + +grub_err_t +grub_video_edid_preferred_mode (struct grub_video_edid_info *edid_info, + unsigned int *width, unsigned int *height) +{ + /* Bit 1 in the Feature Support field indicates that the first + Detailed Timing Description is the preferred timing mode. */ + if (edid_info->version == 1 /* we don't understand later versions */ + && (edid_info->feature_support + & GRUB_VIDEO_EDID_FEATURE_PREFERRED_TIMING_MODE) + && edid_info->detailed_timings[0].pixel_clock) + { + *width = edid_info->detailed_timings[0].horizontal_active_lo + | (((unsigned int) + (edid_info->detailed_timings[0].horizontal_hi & 0xf0)) + << 4); + *height = edid_info->detailed_timings[0].vertical_active_lo + | (((unsigned int) + (edid_info->detailed_timings[0].vertical_hi & 0xf0)) + << 4); + return GRUB_ERR_NONE; + } + + return grub_error (GRUB_ERR_BAD_DEVICE, "no preferred mode available"); +} + /* Parse x[x]*/ static grub_err_t parse_modespec (const char *current_mode, int *width, int *height, int *depth) diff --git a/include/grub/video.h b/include/grub/video.h index 2cf1424c4..2251ed5f4 100644 --- a/include/grub/video.h +++ b/include/grub/video.h @@ -371,6 +371,8 @@ struct grub_video_adapter int (*iterate) (int (*hook) (const struct grub_video_mode_info *info)); + grub_err_t (*get_edid) (struct grub_video_edid_info *edid_info); + void (*print_adapter_specific_info) (void); }; typedef struct grub_video_adapter *grub_video_adapter_t; @@ -484,6 +486,10 @@ grub_err_t EXPORT_FUNC (grub_video_set_active_render_target) (struct grub_video_ grub_err_t grub_video_get_active_render_target (struct grub_video_render_target **target); grub_err_t grub_video_edid_checksum (struct grub_video_edid_info *edid_info); +grub_err_t grub_video_get_edid (struct grub_video_edid_info *edid_info); +grub_err_t grub_video_edid_preferred_mode (struct grub_video_edid_info *edid_info, + unsigned int *width, + unsigned int *height); grub_err_t EXPORT_FUNC (grub_video_set_mode) (const char *modestring, unsigned int modemask, From ef429417b2297c508685d9b1cc43e0bee74f0f44 Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Tue, 14 Dec 2010 18:08:27 +0000 Subject: [PATCH 112/869] mention struct grub_video_adapter change --- ChangeLog.vbe-autodetect | 1 + 1 file changed, 1 insertion(+) diff --git a/ChangeLog.vbe-autodetect b/ChangeLog.vbe-autodetect index 355ce00f6..d8034b885 100644 --- a/ChangeLog.vbe-autodetect +++ b/ChangeLog.vbe-autodetect @@ -19,6 +19,7 @@ (grub_video_vbe_get_edid): New function. (grub_video_vbe_adapter): Add get_edid. * include/grub/video.h (struct grub_vbe_edid_info): New structure. + (struct grub_video_adapter): Add get_edid. (grub_video_edid_checksum): Add prototype. (grub_video_get_edid): Likewise. (grub_video_edid_preferred_mode): Likewise. From 015e21571c2ecaacb7eb59c2cfde566d1290c445 Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Tue, 14 Dec 2010 19:03:28 +0000 Subject: [PATCH 113/869] check that adapter->get_edid is non-NULL --- grub-core/commands/videoinfo.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/grub-core/commands/videoinfo.c b/grub-core/commands/videoinfo.c index 56df943ec..9bd0a0e78 100644 --- a/grub-core/commands/videoinfo.c +++ b/grub-core/commands/videoinfo.c @@ -169,7 +169,7 @@ grub_cmd_videoinfo (grub_command_t cmd __attribute__ ((unused)), adapter->iterate (hook); - if (adapter->get_edid (&edid_info) == GRUB_ERR_NONE) + if (adapter->get_edid && adapter->get_edid (&edid_info) == GRUB_ERR_NONE) print_edid (&edid_info); else grub_errno = GRUB_ERR_NONE; From 477343c86e0b1e4279be40a1af488e7755f20339 Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Wed, 15 Dec 2010 01:31:07 +0000 Subject: [PATCH 114/869] make sure virtual_screen.bg_color is compatible with the text layer --- grub-core/term/gfxterm.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/grub-core/term/gfxterm.c b/grub-core/term/gfxterm.c index 108ce941a..09363918a 100644 --- a/grub-core/term/gfxterm.c +++ b/grub-core/term/gfxterm.c @@ -1201,6 +1201,7 @@ grub_gfxterm_background_color_cmd (grub_command_t cmd __attribute__ ((unused)), int argc, char **args) { grub_video_rgba_color_t color; + struct grub_video_render_target *old_target; if (argc != 1) return grub_error (GRUB_ERR_BAD_ARGUMENT, "missing operand"); @@ -1222,9 +1223,13 @@ grub_gfxterm_background_color_cmd (grub_command_t cmd __attribute__ ((unused)), dirty_region_add (0, 0, window.width, window.height); } - /* Set the background and border colors. */ + /* Set the background and border colors. The background color needs to be + compatible with the text layer. */ + grub_video_get_active_render_target (&old_target); + grub_video_set_active_render_target (text_layer); virtual_screen.bg_color = grub_video_map_rgba_color (color); - virtual_screen.bg_color_display = virtual_screen.bg_color; + grub_video_set_active_render_target (old_target); + virtual_screen.bg_color_display = grub_video_map_rgba_color (color); blend_text_bg = 1; /* Mark whole screen as dirty. */ From 29184e9312b4302932720e1bcdd478eaa2999b7e Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 15 Dec 2010 19:49:35 +0100 Subject: [PATCH 115/869] romfs support --- Makefile.util.def | 1 + grub-core/Makefile.core.def | 5 + grub-core/fs/romfs.c | 345 ++++++++++++++++++++++++++++++++++++ 3 files changed, 351 insertions(+) create mode 100644 grub-core/fs/romfs.c diff --git a/Makefile.util.def b/Makefile.util.def index 74984e2e9..6279f510a 100644 --- a/Makefile.util.def +++ b/Makefile.util.def @@ -64,6 +64,7 @@ library = { common = grub-core/fs/ntfs.c; common = grub-core/fs/ntfscomp.c; common = grub-core/fs/reiserfs.c; + common = grub-core/fs/romfs.c; common = grub-core/fs/sfs.c; common = grub-core/fs/tar.c; common = grub-core/fs/udf.c; diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def index 37c0ce970..f5bbb888d 100644 --- a/grub-core/Makefile.core.def +++ b/grub-core/Makefile.core.def @@ -977,6 +977,11 @@ module = { common = fs/reiserfs.c; }; +module = { + name = romfs; + common = fs/romfs.c; +}; + module = { name = sfs; common = fs/sfs.c; diff --git a/grub-core/fs/romfs.c b/grub-core/fs/romfs.c new file mode 100644 index 000000000..ad0b6a4c4 --- /dev/null +++ b/grub-core/fs/romfs.c @@ -0,0 +1,345 @@ +/* + * 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 . + */ + +#include +#include +#include +#include +#include +#include +#include + +struct grub_romfs_superblock +{ + char magic[8]; +#define GRUB_ROMFS_MAGIC "-rom1fs-" + grub_uint32_t total_size; + grub_uint32_t chksum; + char label[0]; +}; + +struct grub_romfs_file_header +{ + grub_uint32_t next_file; + grub_uint32_t spec; + grub_uint32_t size; + grub_uint32_t chksum; + char name[0]; +}; + +struct grub_romfs_data +{ + grub_disk_addr_t first_file; + grub_disk_t disk; +}; + +struct grub_fshelp_node +{ + grub_disk_addr_t addr; + struct grub_romfs_data *data; + /* Used only on regular files. */ + grub_disk_addr_t data_addr; + struct grub_romfs_file_header file; +}; + +#define GRUB_ROMFS_ALIGN 16 +#define GRUB_ROMFS_TYPE_MASK 7 +#define GRUB_ROMFS_TYPE_REGULAR 2 +#define GRUB_ROMFS_TYPE_DIRECTORY 1 + +static grub_err_t +do_checksum (void *in, grub_size_t insize) +{ + grub_uint32_t *a = in; + grub_size_t sz = insize / 4; + grub_uint32_t *b = a + sz; + grub_uint32_t csum = 0; + + while (a < b) + csum += grub_be_to_cpu32 (*a++); + if (csum) + return grub_error (GRUB_ERR_BAD_FS, "invalid checksum"); + return GRUB_ERR_NONE; +} + +static struct grub_romfs_data * +grub_romfs_mount (grub_device_t dev) +{ + union { + struct grub_romfs_superblock sb; + char d[512]; + } sb; + grub_err_t err; + char *ptr; + grub_disk_addr_t sec = 0; + struct grub_romfs_data *data; + if (!dev->disk) + { + grub_error (GRUB_ERR_BAD_FS, "not a disk"); + return NULL; + } + err = grub_disk_read (dev->disk, 0, 0, sizeof (sb), &sb); + if (err == GRUB_ERR_OUT_OF_RANGE) + err = grub_errno = GRUB_ERR_BAD_FS; + if (err) + return NULL; + if (grub_be_to_cpu32 (sb.sb.total_size) < sizeof (sb)) + { + grub_error (GRUB_ERR_BAD_FS, "too short filesystem"); + return NULL; + } + err = do_checksum (&sb, sizeof (sb) < grub_be_to_cpu32 (sb.sb.total_size) ? + sizeof (sb) : grub_be_to_cpu32 (sb.sb.total_size)); + if (err) + return NULL; + for (ptr = sb.sb.label; (void *) ptr < (void *) (&sb + 1) + && ptr < sb.d + grub_be_to_cpu32 (sb.sb.total_size); ptr++) + if (!*ptr) + break; + if ((void *) ptr == &sb + 1) + for (sec++; ; sec++) + { + err = grub_disk_read (dev->disk, sec, 0, sizeof (sb), &sb); + if (err == GRUB_ERR_OUT_OF_RANGE) + err = grub_errno = GRUB_ERR_BAD_FS; + if (err) + return NULL; + for (ptr = sb.d; (void *) ptr < (void *) (&sb + 1) + && ptr < sb.d + grub_be_to_cpu32 (sb.sb.total_size); ptr++) + if (!*ptr) + break; + } + data = grub_malloc (sizeof (*data)); + if (!data) + return NULL; + data->first_file = ALIGN_UP (ptr - sb.d, GRUB_ROMFS_ALIGN) + sec * 512; + data->disk = dev->disk; + return data; +} + +static int +grub_romfs_iterate_dir (grub_fshelp_node_t dir, + int NESTED_FUNC_ATTR + (*hook) (const char *filename, + enum grub_fshelp_filetype filetype, + grub_fshelp_node_t node)) +{ + grub_disk_addr_t caddr; + struct grub_romfs_file_header hdr; + grub_size_t a = 0; + char *name = NULL; + unsigned nptr; + unsigned i, j; + for (caddr = dir->addr; caddr; + caddr = grub_be_to_cpu32 (hdr.next_file) & ~(GRUB_ROMFS_ALIGN - 1)) + { + grub_disk_addr_t naddr = caddr + sizeof (hdr); + grub_uint32_t csum = 0; + enum grub_fshelp_filetype filetype = GRUB_FSHELP_UNKNOWN; + struct grub_fshelp_node *node; + grub_err_t err; + + err = grub_disk_read (dir->data->disk, caddr >> GRUB_DISK_SECTOR_BITS, + caddr & (GRUB_DISK_SECTOR_SIZE - 1), + sizeof (hdr), &hdr); + if (err) + { + grub_free (name); + return 1; + } + for (nptr = 0; ; nptr++, naddr += 16) + { + if (a >= nptr) + { + char *on; + a = 2 * (nptr + 1); + on = name; + name = grub_realloc (name, a * 16); + if (!name) + { + grub_free (on); + return 1; + } + } + err = grub_disk_read (dir->data->disk, naddr >> GRUB_DISK_SECTOR_BITS, + naddr & (GRUB_DISK_SECTOR_SIZE - 1), + 16, name + 16 * nptr); + if (err) + return err; + for (j = 0; j < 16; j++) + if (!name[16 * nptr + j]) + break; + if (j != 16) + break; + } + for (i = 0; i < sizeof (hdr) / sizeof (grub_uint32_t); i++) + csum += grub_be_to_cpu32 (((grub_uint32_t *) &hdr)[i]); + for (i = 0; i < (nptr + 1) * 4; i++) + csum += grub_be_to_cpu32 (((grub_uint32_t *) name)[i]); + if (csum != 0) + { + grub_error (GRUB_ERR_BAD_FS, "invalid checksum"); + grub_free (name); + return 1; + } + node = grub_malloc (sizeof (*node)); + if (!node) + return 1; + node->addr = caddr; + node->data_addr = caddr + (nptr + 1) * 16 + sizeof (hdr); + node->data = dir->data; + node->file = hdr; + switch (grub_be_to_cpu32 (hdr.next_file) & GRUB_ROMFS_TYPE_MASK) + { + case GRUB_ROMFS_TYPE_REGULAR: + filetype = GRUB_FSHELP_REG; + break; + case GRUB_ROMFS_TYPE_DIRECTORY: + filetype = GRUB_FSHELP_DIR; + break; + } + + if (hook (name, filetype, node)) + { + grub_free (name); + return 1; + } + } + grub_free (name); + return 0; +} + +static grub_err_t +grub_romfs_dir (grub_device_t device, const char *path, + int (*hook) (const char *filename, + const struct grub_dirhook_info *info)) +{ + struct grub_romfs_data *data = 0; + struct grub_fshelp_node *fdiro = 0, start; + + auto int NESTED_FUNC_ATTR iterate (const char *filename, + enum grub_fshelp_filetype filetype, + grub_fshelp_node_t node); + + int NESTED_FUNC_ATTR iterate (const char *filename, + enum grub_fshelp_filetype filetype, + grub_fshelp_node_t node) + { + struct grub_dirhook_info info; + grub_memset (&info, 0, sizeof (info)); + + info.dir = ((filetype & GRUB_FSHELP_TYPE_MASK) == GRUB_FSHELP_DIR); + grub_free (node); + return hook (filename, &info); + } + + data = grub_romfs_mount (device); + if (! data) + goto fail; + + start.addr = data->first_file; + start.data = data; + grub_fshelp_find_file (path, &start, &fdiro, grub_romfs_iterate_dir, + NULL, GRUB_FSHELP_DIR); + if (grub_errno) + goto fail; + + grub_romfs_iterate_dir (fdiro, iterate); + + fail: + grub_free (data); + + return grub_errno; +} + +static grub_err_t +grub_romfs_open (struct grub_file *file, const char *name) +{ + struct grub_romfs_data *data = 0; + struct grub_fshelp_node *fdiro = 0, start; + + data = grub_romfs_mount (file->device); + if (! data) + goto fail; + + start.addr = data->first_file; + start.data = data; + + grub_fshelp_find_file (name, &start, &fdiro, grub_romfs_iterate_dir, + NULL, GRUB_FSHELP_REG); + if (grub_errno) + goto fail; + + file->size = grub_be_to_cpu32 (fdiro->file.size); + file->data = fdiro; + + fail: + grub_free (data); + + return grub_errno; +} + +static grub_ssize_t +grub_romfs_read (grub_file_t file, char *buf, grub_size_t len) +{ + struct grub_fshelp_node *data = file->data; + + /* XXX: The file is stored in as a single extent. */ + data->data->disk->read_hook = file->read_hook; + grub_disk_read (data->data->disk, + (data->data_addr + file->offset) >> GRUB_DISK_SECTOR_BITS, + (data->data_addr + file->offset) & (GRUB_DISK_SECTOR_SIZE - 1), + len, buf); + data->data->disk->read_hook = NULL; + + if (grub_errno) + return -1; + + return len; +} + +static grub_err_t +grub_romfs_close (grub_file_t file) +{ + grub_free (file->data); + + return GRUB_ERR_NONE; +} + +static struct grub_fs grub_romfs_fs = + { + .name = "romfs", + .dir = grub_romfs_dir, + .open = grub_romfs_open, + .read = grub_romfs_read, + .close = grub_romfs_close, +#ifdef GRUB_UTIL + .reserved_first_sector = 0, +#endif + .next = 0 + }; + +GRUB_MOD_INIT(romfs) +{ + grub_fs_register (&grub_romfs_fs); +} + +GRUB_MOD_FINI(romfs) +{ + grub_fs_unregister (&grub_romfs_fs); +} From 921c7932d0ce8ff5bc36570a02fc220f9887139c Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 15 Dec 2010 20:24:16 +0100 Subject: [PATCH 116/869] directory and hardlink support on romfs --- grub-core/fs/romfs.c | 54 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 50 insertions(+), 4 deletions(-) diff --git a/grub-core/fs/romfs.c b/grub-core/fs/romfs.c index ad0b6a4c4..a642615c3 100644 --- a/grub-core/fs/romfs.c +++ b/grub-core/fs/romfs.c @@ -52,15 +52,16 @@ struct grub_fshelp_node { grub_disk_addr_t addr; struct grub_romfs_data *data; - /* Used only on regular files. */ grub_disk_addr_t data_addr; + /* Not filled for root. */ struct grub_romfs_file_header file; }; #define GRUB_ROMFS_ALIGN 16 #define GRUB_ROMFS_TYPE_MASK 7 -#define GRUB_ROMFS_TYPE_REGULAR 2 +#define GRUB_ROMFS_TYPE_HARDLINK 0 #define GRUB_ROMFS_TYPE_DIRECTORY 1 +#define GRUB_ROMFS_TYPE_REGULAR 2 static grub_err_t do_checksum (void *in, grub_size_t insize) @@ -145,7 +146,7 @@ grub_romfs_iterate_dir (grub_fshelp_node_t dir, char *name = NULL; unsigned nptr; unsigned i, j; - for (caddr = dir->addr; caddr; + for (caddr = dir->data_addr; caddr; caddr = grub_be_to_cpu32 (hdr.next_file) & ~(GRUB_ROMFS_ALIGN - 1)) { grub_disk_addr_t naddr = caddr + sizeof (hdr); @@ -180,7 +181,7 @@ grub_romfs_iterate_dir (grub_fshelp_node_t dir, naddr & (GRUB_DISK_SECTOR_SIZE - 1), 16, name + 16 * nptr); if (err) - return err; + return 1; for (j = 0; j < 16; j++) if (!name[16 * nptr + j]) break; @@ -210,8 +211,51 @@ grub_romfs_iterate_dir (grub_fshelp_node_t dir, filetype = GRUB_FSHELP_REG; break; case GRUB_ROMFS_TYPE_DIRECTORY: + node->data_addr = grub_be_to_cpu32 (hdr.spec); filetype = GRUB_FSHELP_DIR; break; + case GRUB_ROMFS_TYPE_HARDLINK: + { + grub_disk_addr_t laddr; + node->addr = laddr = grub_be_to_cpu32 (hdr.spec); + err = grub_disk_read (dir->data->disk, + laddr >> GRUB_DISK_SECTOR_BITS, + laddr & (GRUB_DISK_SECTOR_SIZE - 1), + sizeof (node->file), &node->file); + if (err) + return 1; + if ((grub_be_to_cpu32 (node->file.next_file) & GRUB_ROMFS_TYPE_MASK) + == GRUB_ROMFS_TYPE_REGULAR) + { + laddr += sizeof (hdr); + while (1) + { + char buf[16]; + err = grub_disk_read (dir->data->disk, + laddr >> GRUB_DISK_SECTOR_BITS, + laddr & (GRUB_DISK_SECTOR_SIZE - 1), + 16, buf); + if (err) + return 1; + for (i = 0; i < 16; i++) + if (!buf[i]) + break; + if (i != 16) + break; + laddr += 16; + } + node->data_addr = laddr + 16; + filetype = GRUB_FSHELP_REG; + } + if ((grub_be_to_cpu32 (node->file.next_file) & GRUB_ROMFS_TYPE_MASK) + == GRUB_ROMFS_TYPE_DIRECTORY) + { + node->data_addr = grub_be_to_cpu32 (node->file.spec); + filetype = GRUB_FSHELP_DIR; + } + + break; + } } if (hook (name, filetype, node)) @@ -253,6 +297,7 @@ grub_romfs_dir (grub_device_t device, const char *path, goto fail; start.addr = data->first_file; + start.data_addr = data->first_file; start.data = data; grub_fshelp_find_file (path, &start, &fdiro, grub_romfs_iterate_dir, NULL, GRUB_FSHELP_DIR); @@ -278,6 +323,7 @@ grub_romfs_open (struct grub_file *file, const char *name) goto fail; start.addr = data->first_file; + start.data_addr = data->first_file; start.data = data; grub_fshelp_find_file (name, &start, &fdiro, grub_romfs_iterate_dir, From 20af85758134eb05ecdb950ce113a3145530842d Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 15 Dec 2010 20:36:54 +0100 Subject: [PATCH 117/869] symlink support on romfs --- grub-core/fs/romfs.c | 56 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 44 insertions(+), 12 deletions(-) diff --git a/grub-core/fs/romfs.c b/grub-core/fs/romfs.c index a642615c3..342bdd733 100644 --- a/grub-core/fs/romfs.c +++ b/grub-core/fs/romfs.c @@ -62,6 +62,7 @@ struct grub_fshelp_node #define GRUB_ROMFS_TYPE_HARDLINK 0 #define GRUB_ROMFS_TYPE_DIRECTORY 1 #define GRUB_ROMFS_TYPE_REGULAR 2 +#define GRUB_ROMFS_TYPE_SYMLINK 3 static grub_err_t do_checksum (void *in, grub_size_t insize) @@ -133,6 +134,27 @@ grub_romfs_mount (grub_device_t dev) return data; } +static char * +grub_romfs_read_symlink (grub_fshelp_node_t node) +{ + char *ret; + grub_err_t err; + ret = grub_malloc (grub_be_to_cpu32 (node->file.size) + 1); + if (!ret) + return NULL; + err = grub_disk_read (node->data->disk, + (node->data_addr) >> GRUB_DISK_SECTOR_BITS, + (node->data_addr) & (GRUB_DISK_SECTOR_SIZE - 1), + grub_be_to_cpu32 (node->file.size), ret); + if (err) + { + grub_free (ret); + return NULL; + } + ret[grub_be_to_cpu32 (node->file.size)] = 0; + return ret; +} + static int grub_romfs_iterate_dir (grub_fshelp_node_t dir, int NESTED_FUNC_ATTR @@ -210,6 +232,9 @@ grub_romfs_iterate_dir (grub_fshelp_node_t dir, case GRUB_ROMFS_TYPE_REGULAR: filetype = GRUB_FSHELP_REG; break; + case GRUB_ROMFS_TYPE_SYMLINK: + filetype = GRUB_FSHELP_SYMLINK; + break; case GRUB_ROMFS_TYPE_DIRECTORY: node->data_addr = grub_be_to_cpu32 (hdr.spec); filetype = GRUB_FSHELP_DIR; @@ -225,7 +250,9 @@ grub_romfs_iterate_dir (grub_fshelp_node_t dir, if (err) return 1; if ((grub_be_to_cpu32 (node->file.next_file) & GRUB_ROMFS_TYPE_MASK) - == GRUB_ROMFS_TYPE_REGULAR) + == GRUB_ROMFS_TYPE_REGULAR + || (grub_be_to_cpu32 (node->file.next_file) + & GRUB_ROMFS_TYPE_MASK) == GRUB_ROMFS_TYPE_SYMLINK) { laddr += sizeof (hdr); while (1) @@ -245,16 +272,21 @@ grub_romfs_iterate_dir (grub_fshelp_node_t dir, laddr += 16; } node->data_addr = laddr + 16; - filetype = GRUB_FSHELP_REG; } - if ((grub_be_to_cpu32 (node->file.next_file) & GRUB_ROMFS_TYPE_MASK) - == GRUB_ROMFS_TYPE_DIRECTORY) - { - node->data_addr = grub_be_to_cpu32 (node->file.spec); - filetype = GRUB_FSHELP_DIR; - } - - break; + if ((grub_be_to_cpu32 (node->file.next_file) + & GRUB_ROMFS_TYPE_MASK) == GRUB_ROMFS_TYPE_REGULAR) + filetype = GRUB_FSHELP_REG; + if ((grub_be_to_cpu32 (node->file.next_file) + & GRUB_ROMFS_TYPE_MASK) == GRUB_ROMFS_TYPE_SYMLINK) + filetype = GRUB_FSHELP_SYMLINK; + if ((grub_be_to_cpu32 (node->file.next_file) & GRUB_ROMFS_TYPE_MASK) + == GRUB_ROMFS_TYPE_DIRECTORY) + { + node->data_addr = grub_be_to_cpu32 (node->file.spec); + filetype = GRUB_FSHELP_DIR; + } + + break; } } @@ -300,7 +332,7 @@ grub_romfs_dir (grub_device_t device, const char *path, start.data_addr = data->first_file; start.data = data; grub_fshelp_find_file (path, &start, &fdiro, grub_romfs_iterate_dir, - NULL, GRUB_FSHELP_DIR); + grub_romfs_read_symlink, GRUB_FSHELP_DIR); if (grub_errno) goto fail; @@ -327,7 +359,7 @@ grub_romfs_open (struct grub_file *file, const char *name) start.data = data; grub_fshelp_find_file (name, &start, &fdiro, grub_romfs_iterate_dir, - NULL, GRUB_FSHELP_REG); + grub_romfs_read_symlink, GRUB_FSHELP_REG); if (grub_errno) goto fail; From 44932541564c681250d819fe4e425bb9693f0c13 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 15 Dec 2010 22:00:18 +0100 Subject: [PATCH 118/869] Support RomFS label --- grub-core/fs/romfs.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/grub-core/fs/romfs.c b/grub-core/fs/romfs.c index 342bdd733..07632e635 100644 --- a/grub-core/fs/romfs.c +++ b/grub-core/fs/romfs.c @@ -399,6 +399,40 @@ grub_romfs_close (grub_file_t file) return GRUB_ERR_NONE; } +static grub_err_t +grub_romfs_label (grub_device_t device, char **label) +{ + struct grub_romfs_data *data; + grub_err_t err; + + *label = NULL; + + data = grub_romfs_mount (device); + if (!data) + return grub_errno; + *label = grub_malloc (data->first_file + 1 + - sizeof (struct grub_romfs_superblock)); + if (!*label) + { + grub_free (data); + return grub_errno; + } + err = grub_disk_read (device->disk, 0, sizeof (struct grub_romfs_superblock), + data->first_file + - sizeof (struct grub_romfs_superblock), + *label); + if (err) + { + grub_free (data); + grub_free (*label); + *label = NULL; + return err; + } + (*label)[data->first_file - sizeof (struct grub_romfs_superblock)] = 0; + return GRUB_ERR_NONE; +} + + static struct grub_fs grub_romfs_fs = { .name = "romfs", @@ -406,6 +440,7 @@ static struct grub_fs grub_romfs_fs = .open = grub_romfs_open, .read = grub_romfs_read, .close = grub_romfs_close, + .label = grub_romfs_label, #ifdef GRUB_UTIL .reserved_first_sector = 0, #endif From b04298cfa29418564bd86fd1053fb681000966bc Mon Sep 17 00:00:00 2001 From: kashyap garimella Date: Sat, 18 Dec 2010 15:22:11 +0100 Subject: [PATCH 119/869] * grub-core/loader/i386/multiboot_mbi.c (grub_multiboot_load): Use correct cat to grub_uint8_t * rather than grub_uint32_t *. --- ChangeLog | 5 +++++ grub-core/loader/i386/multiboot_mbi.c | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index abd1d0400..254c8303a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2010-12-18 kashyap garimella + + * grub-core/loader/i386/multiboot_mbi.c (grub_multiboot_load): Use + correct cat to grub_uint8_t * rather than grub_uint32_t *. + 2010-12-10 Colin Watson * .bzrignore: Ignore grub-core/rs_decoder.S. diff --git a/grub-core/loader/i386/multiboot_mbi.c b/grub-core/loader/i386/multiboot_mbi.c index 79f72ee0f..e3f328494 100644 --- a/grub-core/loader/i386/multiboot_mbi.c +++ b/grub-core/loader/i386/multiboot_mbi.c @@ -141,7 +141,7 @@ grub_multiboot_load (grub_file_t file) } if (header->bss_end_addr) - grub_memset ((grub_uint32_t *) source + load_size, 0, + grub_memset ((grub_uint8_t *) source + load_size, 0, header->bss_end_addr - header->load_addr - load_size); grub_multiboot_payload_eip = header->entry_addr; From e1dffcf2705db474dd3a59d8a514598af878da19 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 18 Dec 2010 14:31:05 +0100 Subject: [PATCH 120/869] * grub-core/loader/i386/multiboot_mbi.c (grub_multiboot_make_mbi): Set ptrdest to correct get_physical_target_address rather than incorrect get_virtual_current_address. --- ChangeLog | 6 ++++++ grub-core/loader/i386/multiboot_mbi.c | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 254c8303a..d7091f27c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2010-12-18 Vladimir Serbinenko + + * grub-core/loader/i386/multiboot_mbi.c (grub_multiboot_make_mbi): + Set ptrdest to correct get_physical_target_address rather than + incorrect get_virtual_current_address. + 2010-12-18 kashyap garimella * grub-core/loader/i386/multiboot_mbi.c (grub_multiboot_load): Use diff --git a/grub-core/loader/i386/multiboot_mbi.c b/grub-core/loader/i386/multiboot_mbi.c index e3f328494..7015666fc 100644 --- a/grub-core/loader/i386/multiboot_mbi.c +++ b/grub-core/loader/i386/multiboot_mbi.c @@ -441,7 +441,7 @@ grub_multiboot_make_mbi (grub_uint32_t *target) if (err) return err; ptrorig = get_virtual_current_address (ch); - ptrdest = (grub_addr_t) get_virtual_current_address (ch); + ptrdest = get_physical_target_address (ch); *target = ptrdest; From 32570200a8bb64856c3125fecfc79b9467dddb50 Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Sat, 18 Dec 2010 17:37:48 +0000 Subject: [PATCH 121/869] * grub-core/normal/term.c (print_more): Make \r or \n scroll one line, and other keys scroll an entire page (previous handling was for \r and \n to scroll a page and other keys to scroll two lines). --- ChangeLog | 6 ++++++ grub-core/normal/term.c | 8 ++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index d7091f27c..3f15bcc7b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2010-12-18 Colin Watson + + * grub-core/normal/term.c (print_more): Make \r or \n scroll one + line, and other keys scroll an entire page (previous handling was + for \r and \n to scroll a page and other keys to scroll two lines). + 2010-12-18 Vladimir Serbinenko * grub-core/loader/i386/multiboot_mbi.c (grub_multiboot_make_mbi): diff --git a/grub-core/normal/term.c b/grub-core/normal/term.c index 00721c447..a1aa3d783 100644 --- a/grub-core/normal/term.c +++ b/grub-core/normal/term.c @@ -91,16 +91,16 @@ print_more (void) grub_term_restore_pos (pos); grub_free (pos); - /* Scroll one lines or an entire page, depending on the key. */ + /* Scroll one line or an entire page, depending on the key. */ if (key == '\r' || key =='\n') - grub_normal_reset_more (); - else { static struct term_state *state; for (state = term_states; state; state = state->next) - state->num_lines -= 2; + state->num_lines--; } + else + grub_normal_reset_more (); } void From e872a2dd82c6bfc27a870aff9088dfccaaa4fc02 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 18 Dec 2010 22:47:50 +0100 Subject: [PATCH 122/869] * util/grub-mkfont.c (main): Handle errors from FT_Set_Pixel_Sizes. --- ChangeLog | 4 ++++ util/grub-mkfont.c | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 3f15bcc7b..de0a5690a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2010-12-18 Vladimir Serbinenko + + * util/grub-mkfont.c (main): Handle errors from FT_Set_Pixel_Sizes. + 2010-12-18 Colin Watson * grub-core/normal/term.c (print_more): Make \r or \n scroll one diff --git a/util/grub-mkfont.c b/util/grub-mkfont.c index 3e24380d1..fff6a619e 100644 --- a/util/grub-mkfont.c +++ b/util/grub-mkfont.c @@ -1170,7 +1170,8 @@ main (int argc, char *argv[]) font_info.style = ft_face->style_flags; font_info.size = size; - FT_Set_Pixel_Sizes (ft_face, size, size); + if (FT_Set_Pixel_Sizes (ft_face, size, size)) + grub_util_error ("can't set %dx%d font size", size, size); add_font (&font_info, ft_face, file_format != PF2); FT_Done_Face (ft_face); } From 5cf86f4b0fadf4fbe8780cf5d4592b81e86158b4 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 18 Dec 2010 22:47:50 +0100 Subject: [PATCH 123/869] * util/grub-mkfont.c (main): Handle errors from FT_Set_Pixel_Sizes. --- ChangeLog | 4 ++++ util/grub-mkfont.c | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index bc5e26582..1012833a0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -4,6 +4,10 @@ editor under argument scope. Reported by: Jordan Uggla +2010-12-18 Vladimir Serbinenko + + * util/grub-mkfont.c (main): Handle errors from FT_Set_Pixel_Sizes. + 2010-12-18 Colin Watson * grub-core/normal/term.c (print_more): Make \r or \n scroll one diff --git a/util/grub-mkfont.c b/util/grub-mkfont.c index 3e24380d1..fff6a619e 100644 --- a/util/grub-mkfont.c +++ b/util/grub-mkfont.c @@ -1170,7 +1170,8 @@ main (int argc, char *argv[]) font_info.style = ft_face->style_flags; font_info.size = size; - FT_Set_Pixel_Sizes (ft_face, size, size); + if (FT_Set_Pixel_Sizes (ft_face, size, size)) + grub_util_error ("can't set %dx%d font size", size, size); add_font (&font_info, ft_face, file_format != PF2); FT_Done_Face (ft_face); } From e6533ae1547169a4ef4dd2861bd6c56a8efdc5cc Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 19 Dec 2010 00:43:41 +0100 Subject: [PATCH 124/869] Fix handling of UTF-16 UDF labels. * grub-core/fs/udf.c (grub_udf_iterate_dir): Move string-parsing part (read_string): .. here. (grub_udf_label): Use read_string. --- ChangeLog | 8 ++++++ grub-core/fs/udf.c | 70 +++++++++++++++++++++++++++++++--------------- 2 files changed, 55 insertions(+), 23 deletions(-) diff --git a/ChangeLog b/ChangeLog index de0a5690a..effab30eb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2010-12-19 Vladimir Serbinenko + + Fix handling of UTF-16 UDF labels. + + * grub-core/fs/udf.c (grub_udf_iterate_dir): Move string-parsing part + (read_string): .. here. + (grub_udf_label): Use read_string. + 2010-12-18 Vladimir Serbinenko * util/grub-mkfont.c (main): Handle errors from FT_Set_Pixel_Sizes. diff --git a/grub-core/fs/udf.c b/grub-core/fs/udf.c index 7041e619e..51726edf3 100644 --- a/grub-core/fs/udf.c +++ b/grub-core/fs/udf.c @@ -788,6 +788,43 @@ fail: return 0; } +static char * +read_string (grub_uint8_t *raw, grub_size_t sz) +{ + grub_uint16_t *utf16; + char *ret; + grub_size_t utf16len = 0; + + if (raw[0] != 8 && raw[0] != 16) + return NULL; + + if (raw[0] == 8) + { + unsigned i; + utf16len = sz - 1; + utf16 = grub_malloc (utf16len * sizeof (utf16[0])); + if (!utf16) + return NULL; + for (i = 0; i < utf16len; i++) + utf16[i] = raw[i + 1]; + } + if (raw[0] == 16) + { + unsigned i; + utf16len = (sz - 1) / 2; + utf16 = grub_malloc (utf16len * sizeof (utf16[0])); + if (!utf16) + return NULL; + for (i = 0; i < utf16len; i++) + utf16[i] = (raw[2 * i + 1] << 8) | raw[2*i + 2]; + } + ret = grub_malloc (utf16len * 3 + 1); + if (ret) + *grub_utf16_to_utf8 ((grub_uint8_t *) ret, utf16, utf16len) = '\0'; + grub_free (utf16); + return ret; +} + static int grub_udf_iterate_dir (grub_fshelp_node_t dir, int NESTED_FUNC_ATTR @@ -841,10 +878,8 @@ grub_udf_iterate_dir (grub_fshelp_node_t dir, else { enum grub_fshelp_filetype type; + char *filename; grub_uint8_t raw[dirent.file_ident_length]; - grub_uint16_t utf16[dirent.file_ident_length - 1]; - grub_uint8_t filename[dirent.file_ident_length * 2]; - grub_size_t utf16len = 0; type = ((dirent.characteristics & GRUB_UDF_FID_CHAR_DIRECTORY) ? (GRUB_FSHELP_DIR) : (GRUB_FSHELP_REG)); @@ -855,27 +890,16 @@ grub_udf_iterate_dir (grub_fshelp_node_t dir, != dirent.file_ident_length) return 0; - if (raw[0] == 8) - { - unsigned i; - utf16len = dirent.file_ident_length - 1; - for (i = 0; i < utf16len; i++) - utf16[i] = raw[i + 1]; - } - if (raw[0] == 16) - { - unsigned i; - utf16len = (dirent.file_ident_length - 1) / 2; - for (i = 0; i < utf16len; i++) - utf16[i] = (raw[2 * i + 1] << 8) | raw[2*i + 2]; - } - if (raw[0] == 8 || raw[0] == 16) - { - *grub_utf16_to_utf8 (filename, utf16, utf16len) = '\0'; + filename = read_string (raw, dirent.file_ident_length); + if (!filename) + grub_print_error (); - if (hook ((char *) filename, type, child)) - return 1; + if (filename && hook (filename, type, child)) + { + grub_free (filename); + return 1; } + grub_free (filename); } } @@ -1004,7 +1028,7 @@ grub_udf_label (grub_device_t device, char **label) if (data) { - *label = grub_strdup ((char *) &data->lvd.ident[1]); + *label = read_string (data->lvd.ident, sizeof (data->lvd.ident)); grub_free (data); } else From 7059d1ec14f7c5c44623688a7960050be9c585e0 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 19 Dec 2010 00:43:41 +0100 Subject: [PATCH 125/869] Fix handling of UTF-16 UDF labels. * grub-core/fs/udf.c (grub_udf_iterate_dir): Move string-parsing part (read_string): .. here. (grub_udf_label): Use read_string. --- ChangeLog | 8 ++++++ grub-core/fs/udf.c | 70 +++++++++++++++++++++++++++++++--------------- 2 files changed, 55 insertions(+), 23 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1012833a0..333b24ab2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2010-12-19 Vladimir Serbinenko + + Fix handling of UTF-16 UDF labels. + + * grub-core/fs/udf.c (grub_udf_iterate_dir): Move string-parsing part + (read_string): .. here. + (grub_udf_label): Use read_string. + 2010-12-19 BVK Chaitanya * grub-core/normal/menu_entry.c (run): Execute commands from menu diff --git a/grub-core/fs/udf.c b/grub-core/fs/udf.c index 7041e619e..51726edf3 100644 --- a/grub-core/fs/udf.c +++ b/grub-core/fs/udf.c @@ -788,6 +788,43 @@ fail: return 0; } +static char * +read_string (grub_uint8_t *raw, grub_size_t sz) +{ + grub_uint16_t *utf16; + char *ret; + grub_size_t utf16len = 0; + + if (raw[0] != 8 && raw[0] != 16) + return NULL; + + if (raw[0] == 8) + { + unsigned i; + utf16len = sz - 1; + utf16 = grub_malloc (utf16len * sizeof (utf16[0])); + if (!utf16) + return NULL; + for (i = 0; i < utf16len; i++) + utf16[i] = raw[i + 1]; + } + if (raw[0] == 16) + { + unsigned i; + utf16len = (sz - 1) / 2; + utf16 = grub_malloc (utf16len * sizeof (utf16[0])); + if (!utf16) + return NULL; + for (i = 0; i < utf16len; i++) + utf16[i] = (raw[2 * i + 1] << 8) | raw[2*i + 2]; + } + ret = grub_malloc (utf16len * 3 + 1); + if (ret) + *grub_utf16_to_utf8 ((grub_uint8_t *) ret, utf16, utf16len) = '\0'; + grub_free (utf16); + return ret; +} + static int grub_udf_iterate_dir (grub_fshelp_node_t dir, int NESTED_FUNC_ATTR @@ -841,10 +878,8 @@ grub_udf_iterate_dir (grub_fshelp_node_t dir, else { enum grub_fshelp_filetype type; + char *filename; grub_uint8_t raw[dirent.file_ident_length]; - grub_uint16_t utf16[dirent.file_ident_length - 1]; - grub_uint8_t filename[dirent.file_ident_length * 2]; - grub_size_t utf16len = 0; type = ((dirent.characteristics & GRUB_UDF_FID_CHAR_DIRECTORY) ? (GRUB_FSHELP_DIR) : (GRUB_FSHELP_REG)); @@ -855,27 +890,16 @@ grub_udf_iterate_dir (grub_fshelp_node_t dir, != dirent.file_ident_length) return 0; - if (raw[0] == 8) - { - unsigned i; - utf16len = dirent.file_ident_length - 1; - for (i = 0; i < utf16len; i++) - utf16[i] = raw[i + 1]; - } - if (raw[0] == 16) - { - unsigned i; - utf16len = (dirent.file_ident_length - 1) / 2; - for (i = 0; i < utf16len; i++) - utf16[i] = (raw[2 * i + 1] << 8) | raw[2*i + 2]; - } - if (raw[0] == 8 || raw[0] == 16) - { - *grub_utf16_to_utf8 (filename, utf16, utf16len) = '\0'; + filename = read_string (raw, dirent.file_ident_length); + if (!filename) + grub_print_error (); - if (hook ((char *) filename, type, child)) - return 1; + if (filename && hook (filename, type, child)) + { + grub_free (filename); + return 1; } + grub_free (filename); } } @@ -1004,7 +1028,7 @@ grub_udf_label (grub_device_t device, char **label) if (data) { - *label = grub_strdup ((char *) &data->lvd.ident[1]); + *label = read_string (data->lvd.ident, sizeof (data->lvd.ident)); grub_free (data); } else From b85812b06f6806f988c9c57ca52f01c4eb110114 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 19 Dec 2010 00:49:52 +0100 Subject: [PATCH 126/869] * grub-core/fs/affs.c (grub_affs_fs) [GRUB_UTIL]: Explicitly set reserved_first_sector to 0. * grub-core/fs/cpio.c (grub_cpio_fs) [GRUB_UTIL]: Likewise. * grub-core/fs/sfs.c (grub_sfs_fs) [GRUB_UTIL]: Likewise. * grub-core/fs/xfs.c (grub_xfs_fs) [GRUB_UTIL]: Likewise. --- ChangeLog | 8 ++++++++ grub-core/fs/affs.c | 3 +++ grub-core/fs/cpio.c | 3 +++ grub-core/fs/sfs.c | 3 +++ grub-core/fs/xfs.c | 3 +++ 5 files changed, 20 insertions(+) diff --git a/ChangeLog b/ChangeLog index effab30eb..cc3f65c86 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2010-12-19 Vladimir Serbinenko + + * grub-core/fs/affs.c (grub_affs_fs) [GRUB_UTIL]: Explicitly set + reserved_first_sector to 0. + * grub-core/fs/cpio.c (grub_cpio_fs) [GRUB_UTIL]: Likewise. + * grub-core/fs/sfs.c (grub_sfs_fs) [GRUB_UTIL]: Likewise. + * grub-core/fs/xfs.c (grub_xfs_fs) [GRUB_UTIL]: Likewise. + 2010-12-19 Vladimir Serbinenko Fix handling of UTF-16 UDF labels. diff --git a/grub-core/fs/affs.c b/grub-core/fs/affs.c index 3dc80752d..27e03c0c4 100644 --- a/grub-core/fs/affs.c +++ b/grub-core/fs/affs.c @@ -535,6 +535,9 @@ static struct grub_fs grub_affs_fs = .read = grub_affs_read, .close = grub_affs_close, .label = grub_affs_label, +#ifdef GRUB_UTIL + .reserved_first_sector = 0, +#endif .next = 0 }; diff --git a/grub-core/fs/cpio.c b/grub-core/fs/cpio.c index c087b4f90..2c92404c3 100644 --- a/grub-core/fs/cpio.c +++ b/grub-core/fs/cpio.c @@ -354,6 +354,9 @@ static struct grub_fs grub_cpio_fs = { .open = grub_cpio_open, .read = grub_cpio_read, .close = grub_cpio_close, +#ifdef GRUB_UTIL + .reserved_first_sector = 0, +#endif }; #ifdef MODE_USTAR diff --git a/grub-core/fs/sfs.c b/grub-core/fs/sfs.c index 4a5005908..b49420de1 100644 --- a/grub-core/fs/sfs.c +++ b/grub-core/fs/sfs.c @@ -579,6 +579,9 @@ static struct grub_fs grub_sfs_fs = .read = grub_sfs_read, .close = grub_sfs_close, .label = grub_sfs_label, +#ifdef GRUB_UTIL + .reserved_first_sector = 0, +#endif .next = 0 }; diff --git a/grub-core/fs/xfs.c b/grub-core/fs/xfs.c index 9dffe31d1..3d773856e 100644 --- a/grub-core/fs/xfs.c +++ b/grub-core/fs/xfs.c @@ -808,6 +808,9 @@ static struct grub_fs grub_xfs_fs = .close = grub_xfs_close, .label = grub_xfs_label, .uuid = grub_xfs_uuid, +#ifdef GRUB_UTIL + .reserved_first_sector = 0, +#endif .next = 0 }; From a2a08a35bf2a6603b9c0ee5dc3e224f41373258c Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 19 Dec 2010 00:49:52 +0100 Subject: [PATCH 127/869] * grub-core/fs/affs.c (grub_affs_fs) [GRUB_UTIL]: Explicitly set reserved_first_sector to 0. * grub-core/fs/cpio.c (grub_cpio_fs) [GRUB_UTIL]: Likewise. * grub-core/fs/sfs.c (grub_sfs_fs) [GRUB_UTIL]: Likewise. * grub-core/fs/xfs.c (grub_xfs_fs) [GRUB_UTIL]: Likewise. --- ChangeLog | 8 ++++++++ grub-core/fs/affs.c | 3 +++ grub-core/fs/cpio.c | 3 +++ grub-core/fs/sfs.c | 3 +++ grub-core/fs/xfs.c | 3 +++ 5 files changed, 20 insertions(+) diff --git a/ChangeLog b/ChangeLog index 333b24ab2..99cf2cd7f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2010-12-19 Vladimir Serbinenko + + * grub-core/fs/affs.c (grub_affs_fs) [GRUB_UTIL]: Explicitly set + reserved_first_sector to 0. + * grub-core/fs/cpio.c (grub_cpio_fs) [GRUB_UTIL]: Likewise. + * grub-core/fs/sfs.c (grub_sfs_fs) [GRUB_UTIL]: Likewise. + * grub-core/fs/xfs.c (grub_xfs_fs) [GRUB_UTIL]: Likewise. + 2010-12-19 Vladimir Serbinenko Fix handling of UTF-16 UDF labels. diff --git a/grub-core/fs/affs.c b/grub-core/fs/affs.c index 3dc80752d..27e03c0c4 100644 --- a/grub-core/fs/affs.c +++ b/grub-core/fs/affs.c @@ -535,6 +535,9 @@ static struct grub_fs grub_affs_fs = .read = grub_affs_read, .close = grub_affs_close, .label = grub_affs_label, +#ifdef GRUB_UTIL + .reserved_first_sector = 0, +#endif .next = 0 }; diff --git a/grub-core/fs/cpio.c b/grub-core/fs/cpio.c index c087b4f90..2c92404c3 100644 --- a/grub-core/fs/cpio.c +++ b/grub-core/fs/cpio.c @@ -354,6 +354,9 @@ static struct grub_fs grub_cpio_fs = { .open = grub_cpio_open, .read = grub_cpio_read, .close = grub_cpio_close, +#ifdef GRUB_UTIL + .reserved_first_sector = 0, +#endif }; #ifdef MODE_USTAR diff --git a/grub-core/fs/sfs.c b/grub-core/fs/sfs.c index 4a5005908..b49420de1 100644 --- a/grub-core/fs/sfs.c +++ b/grub-core/fs/sfs.c @@ -579,6 +579,9 @@ static struct grub_fs grub_sfs_fs = .read = grub_sfs_read, .close = grub_sfs_close, .label = grub_sfs_label, +#ifdef GRUB_UTIL + .reserved_first_sector = 0, +#endif .next = 0 }; diff --git a/grub-core/fs/xfs.c b/grub-core/fs/xfs.c index 9dffe31d1..3d773856e 100644 --- a/grub-core/fs/xfs.c +++ b/grub-core/fs/xfs.c @@ -808,6 +808,9 @@ static struct grub_fs grub_xfs_fs = .close = grub_xfs_close, .label = grub_xfs_label, .uuid = grub_xfs_uuid, +#ifdef GRUB_UTIL + .reserved_first_sector = 0, +#endif .next = 0 }; From b070525d039783869b96e0223c8142a055fffc0f Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 19 Dec 2010 00:52:18 +0100 Subject: [PATCH 128/869] * grub-core/fs/affs.c (grub_affs_mount): Read data->bblock.rootblock rather than assuming than rootblock is exactly in the middle. (grub_affs_label): Likewise. --- ChangeLog | 6 ++++++ grub-core/fs/affs.c | 6 +++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index cc3f65c86..8f459f198 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2010-12-19 Vladimir Serbinenko + + * grub-core/fs/affs.c (grub_affs_mount): Read data->bblock.rootblock + rather than assuming than rootblock is exactly in the middle. + (grub_affs_label): Likewise. + 2010-12-19 Vladimir Serbinenko * grub-core/fs/affs.c (grub_affs_fs) [GRUB_UTIL]: Explicitly set diff --git a/grub-core/fs/affs.c b/grub-core/fs/affs.c index 27e03c0c4..40be4b2f6 100644 --- a/grub-core/fs/affs.c +++ b/grub-core/fs/affs.c @@ -208,7 +208,7 @@ grub_affs_mount (grub_disk_t disk) rblock = (struct grub_affs_rblock *) rootblock; /* Read the rootblock. */ - grub_disk_read (disk, (disk->total_sectors >> 1) + blocksize, 0, + grub_disk_read (disk, grub_be_to_cpu32 (data->bblock.rootblock), 0, GRUB_DISK_SECTOR_SIZE * 16, rootblock); if (grub_errno) goto fail; @@ -240,7 +240,7 @@ grub_affs_mount (grub_disk_t disk) data->disk = disk; data->htsize = grub_be_to_cpu32 (rblock->htsize); data->diropen.data = data; - data->diropen.block = (disk->total_sectors >> 1); + data->diropen.block = grub_be_to_cpu32 (data->bblock.rootblock); grub_free (rootblock); @@ -507,7 +507,7 @@ grub_affs_label (grub_device_t device, char **label) { /* The rootblock maps quite well on a file header block, it's something we can use here. */ - grub_disk_read (data->disk, disk->total_sectors >> 1, + grub_disk_read (data->disk, grub_be_to_cpu32 (data->bblock.rootblock), data->blocksize * (GRUB_DISK_SECTOR_SIZE - GRUB_AFFS_FILE_LOCATION), sizeof (file), &file); From 6c85b743f5c3a07c400ffd798e87cbcf2d3ab64d Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 19 Dec 2010 00:52:18 +0100 Subject: [PATCH 129/869] * grub-core/fs/affs.c (grub_affs_mount): Read data->bblock.rootblock rather than assuming than rootblock is exactly in the middle. (grub_affs_label): Likewise. --- ChangeLog | 6 ++++++ grub-core/fs/affs.c | 6 +++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 99cf2cd7f..12836d9af 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2010-12-19 Vladimir Serbinenko + + * grub-core/fs/affs.c (grub_affs_mount): Read data->bblock.rootblock + rather than assuming than rootblock is exactly in the middle. + (grub_affs_label): Likewise. + 2010-12-19 Vladimir Serbinenko * grub-core/fs/affs.c (grub_affs_fs) [GRUB_UTIL]: Explicitly set diff --git a/grub-core/fs/affs.c b/grub-core/fs/affs.c index 27e03c0c4..40be4b2f6 100644 --- a/grub-core/fs/affs.c +++ b/grub-core/fs/affs.c @@ -208,7 +208,7 @@ grub_affs_mount (grub_disk_t disk) rblock = (struct grub_affs_rblock *) rootblock; /* Read the rootblock. */ - grub_disk_read (disk, (disk->total_sectors >> 1) + blocksize, 0, + grub_disk_read (disk, grub_be_to_cpu32 (data->bblock.rootblock), 0, GRUB_DISK_SECTOR_SIZE * 16, rootblock); if (grub_errno) goto fail; @@ -240,7 +240,7 @@ grub_affs_mount (grub_disk_t disk) data->disk = disk; data->htsize = grub_be_to_cpu32 (rblock->htsize); data->diropen.data = data; - data->diropen.block = (disk->total_sectors >> 1); + data->diropen.block = grub_be_to_cpu32 (data->bblock.rootblock); grub_free (rootblock); @@ -507,7 +507,7 @@ grub_affs_label (grub_device_t device, char **label) { /* The rootblock maps quite well on a file header block, it's something we can use here. */ - grub_disk_read (data->disk, disk->total_sectors >> 1, + grub_disk_read (data->disk, grub_be_to_cpu32 (data->bblock.rootblock), data->blocksize * (GRUB_DISK_SECTOR_SIZE - GRUB_AFFS_FILE_LOCATION), sizeof (file), &file); From 5318fe9804f1e95e2d04186f4bf28562c8cfaf5e Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 20 Dec 2010 16:13:01 +0100 Subject: [PATCH 130/869] * grub-core/loader/i386/multiboot_mbi.c (grub_multiboot_add_module): Avoid next pointing to nowhere. --- ChangeLog | 5 +++++ grub-core/loader/i386/multiboot_mbi.c | 1 + 2 files changed, 6 insertions(+) diff --git a/ChangeLog b/ChangeLog index 12836d9af..6e564324b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2010-12-20 Vladimir Serbinenko + + * grub-core/loader/i386/multiboot_mbi.c (grub_multiboot_add_module): + Avoid next pointing to nowhere. + 2010-12-19 Vladimir Serbinenko * grub-core/fs/affs.c (grub_affs_mount): Read data->bblock.rootblock diff --git a/grub-core/loader/i386/multiboot_mbi.c b/grub-core/loader/i386/multiboot_mbi.c index 7015666fc..eade78e93 100644 --- a/grub-core/loader/i386/multiboot_mbi.c +++ b/grub-core/loader/i386/multiboot_mbi.c @@ -641,6 +641,7 @@ grub_multiboot_add_module (grub_addr_t start, grub_size_t size, return grub_errno; newmod->start = start; newmod->size = size; + newmod->next = 0; for (i = 0; i < argc; i++) len += grub_strlen (argv[i]) + 1; From 4e01b6c821b46c83b19a22b7ecd0207780c90ab0 Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Tue, 21 Dec 2010 12:49:29 +0000 Subject: [PATCH 131/869] * util/grub-mkconfig_lib.in (gettext_quoted): Add clarifying comment. Add an extra layer of quotation, requiring the output of this function to be used in a printf format string. (gettext_printf): New function. * util/grub.d/10_hurd.in: Use gettext_printf where appropriate. Extract translatable strings from here-documents and use a temporary variable instead, so that xgettext can find them. * util/grub.d/10_kfreebsd.in: Likewise. * util/grub.d/10_linux.in: Likewise. * util/grub.d/20_linux_xen.in: Likewise. * po/grub.d.sed: New file. * po/Makefile.in.in ($(DOMAIN).pot-update): Extract gettext_printf arguments. Set c-format flags on all strings extracted from util/grub.d/ (xgettext refuses to include these itself for strings it extracted from a shell file, but these really are c-format). --- ChangeLog | 19 +++++++++++++++++++ po/Makefile.in.in | 8 ++++++-- po/grub.d.sed | 2 ++ util/grub-mkconfig_lib.in | 14 +++++++++++++- util/grub.d/10_hurd.in | 12 ++++++++---- util/grub.d/10_kfreebsd.in | 3 ++- util/grub.d/10_linux.in | 6 ++++-- util/grub.d/20_linux_xen.in | 6 ++++-- 8 files changed, 58 insertions(+), 12 deletions(-) create mode 100644 po/grub.d.sed diff --git a/ChangeLog b/ChangeLog index 6e564324b..ca555a662 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,22 @@ +2010-12-21 Colin Watson + + * util/grub-mkconfig_lib.in (gettext_quoted): Add clarifying + comment. Add an extra layer of quotation, requiring the output of + this function to be used in a printf format string. + (gettext_printf): New function. + * util/grub.d/10_hurd.in: Use gettext_printf where appropriate. + Extract translatable strings from here-documents and use a temporary + variable instead, so that xgettext can find them. + * util/grub.d/10_kfreebsd.in: Likewise. + * util/grub.d/10_linux.in: Likewise. + * util/grub.d/20_linux_xen.in: Likewise. + + * po/grub.d.sed: New file. + * po/Makefile.in.in ($(DOMAIN).pot-update): Extract gettext_printf + arguments. Set c-format flags on all strings extracted from + util/grub.d/ (xgettext refuses to include these itself for strings + it extracted from a shell file, but these really are c-format). + 2010-12-20 Vladimir Serbinenko * grub-core/loader/i386/multiboot_mbi.c (grub_multiboot_add_module): diff --git a/po/Makefile.in.in b/po/Makefile.in.in index d0af6c962..b0e7b8fa2 100644 --- a/po/Makefile.in.in +++ b/po/Makefile.in.in @@ -173,7 +173,8 @@ $(DOMAIN).pot-update: $(POTFILES) $(srcdir)/POTFILES.in $(srcdir)/POTFILES-shell --files-from=$(srcdir)/POTFILES-shell.in \ --copyright-holder='$(COPYRIGHT_HOLDER)' \ --msgid-bugs-address="$$msgid_bugs_address" \ - --join-existing --language=Shell --keyword=gettext_quoted \ + --join-existing --language=Shell \ + --keyword=gettext_quoted --keyword=gettext_printf \ ;; \ *) \ $(XGETTEXT) --default-domain=$(DOMAIN) --directory=$(top_srcdir) \ @@ -183,10 +184,13 @@ $(DOMAIN).pot-update: $(POTFILES) $(srcdir)/POTFILES.in $(srcdir)/POTFILES-shell --package-name="$${package_gnu}@PACKAGE@" \ --package-version='@VERSION@' \ --msgid-bugs-address="$$msgid_bugs_address" \ - --join-existing --language=Shell --keyword=gettext_quoted \ + --join-existing --language=Shell \ + --keyword=gettext_quoted --keyword=gettext_printf \ ;; \ esac test ! -f $(DOMAIN).po || { \ + sed -f grub.d.sed < $(DOMAIN).po > $(DOMAIN).1po && \ + mv $(DOMAIN).1po $(DOMAIN).po; \ if test -f $(srcdir)/$(DOMAIN).pot; then \ sed -f remove-potcdate.sed < $(srcdir)/$(DOMAIN).pot > $(DOMAIN).1po && \ sed -f remove-potcdate.sed < $(DOMAIN).po > $(DOMAIN).2po && \ diff --git a/po/grub.d.sed b/po/grub.d.sed new file mode 100644 index 000000000..9fd729474 --- /dev/null +++ b/po/grub.d.sed @@ -0,0 +1,2 @@ +/^#: util\/grub\.d\//a\ +#, c-format diff --git a/util/grub-mkconfig_lib.in b/util/grub-mkconfig_lib.in index 41359975e..ec4084698 100644 --- a/util/grub-mkconfig_lib.in +++ b/util/grub-mkconfig_lib.in @@ -187,8 +187,20 @@ version_find_latest () echo "$a" } +# One layer of quotation is eaten by "", the second by sed, and the third by +# printf; so this turns ' into \'. Note that you must use the output of +# this function in a printf format string. gettext_quoted () { - $gettext "$@" | sed "s/'/'\\\\''/g" + $gettext "$@" | sed "s/'/'\\\\\\\\''/g" +} + +# Run the first argument through gettext_quoted, and then pass that and all +# remaining arguments to printf. This is a useful abbreviation and tends to +# be easier to type. +gettext_printf () { + local format="$1" + shift + printf "$(gettext_quoted "$format")" "$@" } uses_abstraction () { diff --git a/util/grub.d/10_hurd.in b/util/grub.d/10_hurd.in index 6490913ae..eeb441aa4 100644 --- a/util/grub.d/10_hurd.in +++ b/util/grub.d/10_hurd.in @@ -81,14 +81,16 @@ do menuentry "${OS} ${KERNEL}" ${CLASS} { EOF prepare_grub_to_access_device ${GRUB_DEVICE_BOOT} | sed -e "s/^/\t/" + message="$(gettext_printf "Loading GNU Mach ...")" cat << EOF - echo '$(gettext_quoted "Loading GNU Mach ...")' + echo '$message' multiboot ${kernel} root=device:${GRUB_DEVICE#/dev/} EOF save_default_entry | sed -e "s/^/\t/" prepare_grub_to_access_device ${GRUB_DEVICE} | sed -e "s/^/\t/" + message="$(gettext_printf "Loading the Hurd ...")" cat << EOF - echo '$(gettext_quoted "Loading the Hurd ...")' + echo '$message' module /hurd/${hurd_fs}.static ${hurd_fs} --readonly \\ --multiboot-command-line='\${kernel-command-line}' \\ --host-priv-port='\${host-port}' \\ @@ -103,13 +105,15 @@ EOF menuentry "${OS} ${KERNEL} (recovery mode)" ${CLASS} { EOF prepare_grub_to_access_device ${GRUB_DEVICE_BOOT} | sed -e "s/^/\t/" + message="$(gettext_printf "Loading GNU Mach ...")" cat << EOF - echo '$(gettext_quoted "Loading GNU Mach ...")' + echo '$message' multiboot ${kernel} root=device:${GRUB_DEVICE#/dev/} -s EOF prepare_grub_to_access_device ${GRUB_DEVICE} | sed -e "s/^/\t/" + message="$(gettext_printf "Loading the Hurd ...")" cat << EOF - echo '$(gettext_quoted "Loading the Hurd ...")' + echo '$message' module /hurd/${hurd_fs}.static ${hurd_fs} \\ --multiboot-command-line='\${kernel-command-line}' \\ --host-priv-port='\${host-port}' \\ diff --git a/util/grub.d/10_kfreebsd.in b/util/grub.d/10_kfreebsd.in index 9cb2788df..b026812a7 100644 --- a/util/grub.d/10_kfreebsd.in +++ b/util/grub.d/10_kfreebsd.in @@ -84,8 +84,9 @@ kfreebsd_entry () fi printf '%s\n' "${prepare_boot_cache}" + message="$(gettext_printf "Loading kernel of FreeBSD %s ..." ${version})" cat << EOF - echo '$(printf "$(gettext_quoted "Loading kernel of FreeBSD %s ...")" ${version})' + echo '$message' kfreebsd ${rel_dirname}/${basename} ${args} EOF diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in index 7650ac9fa..a09c3e687 100644 --- a/util/grub.d/10_linux.in +++ b/util/grub.d/10_linux.in @@ -94,13 +94,15 @@ EOF prepare_boot_cache="$(prepare_grub_to_access_device ${GRUB_DEVICE_BOOT} | sed -e "s/^/\t/")" fi printf '%s\n' "${prepare_boot_cache}" + message="$(gettext_printf "Loading Linux %s ..." ${version})" cat << EOF - echo '$(printf "$(gettext_quoted "Loading Linux %s ...")" ${version})' + echo '$message' linux ${rel_dirname}/${basename} root=${linux_root_device_thisversion} ro ${args} EOF if test -n "${initrd}" ; then + message="$(gettext_printf "Loading initial ramdisk ...")" cat << EOF - echo '$(gettext_quoted "Loading initial ramdisk ...")' + echo '$message' initrd ${rel_dirname}/${initrd} EOF fi diff --git a/util/grub.d/20_linux_xen.in b/util/grub.d/20_linux_xen.in index 649ae85dd..a90211f44 100644 --- a/util/grub.d/20_linux_xen.in +++ b/util/grub.d/20_linux_xen.in @@ -73,14 +73,16 @@ linux_entry () prepare_boot_cache="$(prepare_grub_to_access_device ${GRUB_DEVICE_BOOT} | sed -e "s/^/\t/")" fi printf '%s\n' "${prepare_boot_cache}" + message="$(gettext_printf "Loading Linux %s ..." ${version})" cat << EOF - echo '$(printf "$(gettext_quoted "Loading Linux %s ...")" ${version})' + echo '$message' multiboot ${rel_xen_dirname}/${xen_basename} placeholder ${xen_args} module ${rel_dirname}/${basename} placeholder root=${linux_root_device_thisversion} ro ${args} EOF if test -n "${initrd}" ; then + message="$(gettext_printf "Loading initial ramdisk ...")" cat << EOF - echo '$(gettext_quoted "Loading initial ramdisk ...")' + echo '$message' module ${rel_dirname}/${initrd} EOF fi From b889cfadf9e3cf85f538d5eb206028b583bff7ef Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Tue, 21 Dec 2010 13:00:10 +0000 Subject: [PATCH 132/869] * grub-core/fs/udf.c (read_string): Pacify GCC warning by initialising utf16. --- ChangeLog | 5 +++++ grub-core/fs/udf.c | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index ca555a662..42e059d46 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2010-12-21 Colin Watson + + * grub-core/fs/udf.c (read_string): Pacify GCC warning by + initialising utf16. + 2010-12-21 Colin Watson * util/grub-mkconfig_lib.in (gettext_quoted): Add clarifying diff --git a/grub-core/fs/udf.c b/grub-core/fs/udf.c index 51726edf3..1672aab1b 100644 --- a/grub-core/fs/udf.c +++ b/grub-core/fs/udf.c @@ -791,7 +791,7 @@ fail: static char * read_string (grub_uint8_t *raw, grub_size_t sz) { - grub_uint16_t *utf16; + grub_uint16_t *utf16 = NULL; char *ret; grub_size_t utf16len = 0; From d060ad60eee798a5c7c970ca2e777c7f1d0f8caa Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Tue, 21 Dec 2010 13:52:07 +0000 Subject: [PATCH 133/869] * grub-core/commands/echo.c (grub_cmd_echo): Make UTF-8-clean by constructing a new unescaped string and passing it to grub_xputs in one go, rather than passing characters to grub_printf one at a time. --- ChangeLog | 6 ++++++ grub-core/commands/echo.c | 26 ++++++++++++++++++-------- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index 42e059d46..e65dc231c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2010-12-21 Colin Watson + + * grub-core/commands/echo.c (grub_cmd_echo): Make UTF-8-clean by + constructing a new unescaped string and passing it to grub_xputs in + one go, rather than passing characters to grub_printf one at a time. + 2010-12-21 Colin Watson * grub-core/fs/udf.c (read_string): Pacify GCC warning by diff --git a/grub-core/commands/echo.c b/grub-core/commands/echo.c index 7ab9f92c6..93a452fc8 100644 --- a/grub-core/commands/echo.c +++ b/grub-core/commands/echo.c @@ -44,8 +44,14 @@ grub_cmd_echo (grub_extcmd_context_t ctxt, int argc, char **args) for (i = 0; i < argc; i++) { char *arg = *args; + /* Unescaping results in a string no longer than the original. */ + char *unescaped = grub_malloc (grub_strlen (arg) + 1); + char *p = unescaped; args++; + if (!unescaped) + return grub_errno; + while (*arg) { /* In case `-e' is used, parse backslashes. */ @@ -58,11 +64,11 @@ grub_cmd_echo (grub_extcmd_context_t ctxt, int argc, char **args) switch (*arg) { case '\\': - grub_printf ("\\"); + *p++ = '\\'; break; case 'a': - grub_printf ("\a"); + *p++ = '\a'; break; case 'c': @@ -70,23 +76,23 @@ grub_cmd_echo (grub_extcmd_context_t ctxt, int argc, char **args) break; case 'f': - grub_printf ("\f"); + *p++ = '\f'; break; case 'n': - grub_printf ("\n"); + *p++ = '\n'; break; case 'r': - grub_printf ("\r"); + *p++ = '\r'; break; case 't': - grub_printf ("\t"); + *p++ = '\t'; break; case 'v': - grub_printf ("\v"); + *p++ = '\v'; break; } arg++; @@ -95,10 +101,14 @@ grub_cmd_echo (grub_extcmd_context_t ctxt, int argc, char **args) /* This was not an escaped character, or escaping is not enabled. */ - grub_printf ("%c", *arg); + *p++ = *arg; arg++; } + *p = '\0'; + grub_xputs (unescaped); + grub_free (unescaped); + /* If another argument follows, insert a space. */ if (i != argc - 1) grub_printf (" " ); From 20641b6baad5d5a18ec5d5cd5305e01ff3c7f025 Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Tue, 21 Dec 2010 16:51:08 +0000 Subject: [PATCH 134/869] * grub-core/lib/reed_solomon.c (gauss_solve): Fix size of standalone scratch area. Make sure to initialise chosen in standalone mode as well as non-standalone. Reported by: Robert Hooker and Andy Whitcroft. Tested by: Andy Whitcroft. --- ChangeLog | 8 ++++++++ grub-core/lib/reed_solomon.c | 12 +++++++----- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index e65dc231c..4c7225bc5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2010-12-21 Colin Watson + + * grub-core/lib/reed_solomon.c (gauss_solve): Fix size of standalone + scratch area. Make sure to initialise chosen in standalone mode as + well as non-standalone. + Reported by: Robert Hooker and Andy Whitcroft. + Tested by: Andy Whitcroft. + 2010-12-21 Colin Watson * grub-core/commands/echo.c (grub_cmd_echo): Make UTF-8-clean by diff --git a/grub-core/lib/reed_solomon.c b/grub-core/lib/reed_solomon.c index 4c6e160e4..6f571550a 100644 --- a/grub-core/lib/reed_solomon.c +++ b/grub-core/lib/reed_solomon.c @@ -18,6 +18,8 @@ #ifdef TEST #include +#include +#include #define xmalloc malloc #define grub_memset memset #define grub_memcpy memcpy @@ -25,8 +27,6 @@ #ifndef STANDALONE #ifdef TEST -#include -#include typedef unsigned int grub_size_t; typedef unsigned char grub_uint8_t; typedef unsigned short grub_uint16_t; @@ -45,6 +45,7 @@ typedef unsigned char grub_uint8_t; typedef unsigned short grub_uint16_t; #else #include +#include #endif void grub_reed_solomon_recover (void *ptr_, grub_size_t s, grub_size_t rs); @@ -207,11 +208,12 @@ gauss_solve (gf_single_t *eq, int n, int m, gf_single_t *sol) #ifndef STANDALONE chosen = xmalloc (n * sizeof (int)); - grub_memset (chosen, -1, n * sizeof (int)); #else chosen = (void *) scratch; - scratch += n; + scratch += n * sizeof (int); #endif + for (i = 0; i < n; i++) + chosen[i] = -1; for (i = 0; i < m; i++) sol[i] = 0; gauss_eliminate (eq, n, m, chosen); @@ -228,7 +230,7 @@ gauss_solve (gf_single_t *eq, int n, int m, gf_single_t *sol) #ifndef STANDALONE free (chosen); #else - scratch -= n; + scratch -= n * sizeof (int); #endif } From 1426ef3560721b04db1d3e162957825a00753cd8 Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Tue, 21 Dec 2010 17:41:47 +0000 Subject: [PATCH 135/869] * include/grub/offsets.h (GRUB_KERNEL_I386_PC_RAW_SIZE): The previous patch increased the size of the RS code by 20 bytes (at least with gcc-4.4), so increase this by 20 bytes to match. (GRUB_KERNEL_I386_PC_NO_REED_SOLOMON_PART): Likewise. --- ChangeLog | 7 +++++++ include/grub/offsets.h | 4 ++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4c7225bc5..27e2aee97 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2010-12-21 Colin Watson + + * include/grub/offsets.h (GRUB_KERNEL_I386_PC_RAW_SIZE): The + previous patch increased the size of the RS code by 20 bytes (at + least with gcc-4.4), so increase this by 20 bytes to match. + (GRUB_KERNEL_I386_PC_NO_REED_SOLOMON_PART): Likewise. + 2010-12-21 Colin Watson * grub-core/lib/reed_solomon.c (gauss_solve): Fix size of standalone diff --git a/include/grub/offsets.h b/include/grub/offsets.h index b096abf37..817372b69 100644 --- a/include/grub/offsets.h +++ b/include/grub/offsets.h @@ -38,9 +38,9 @@ #define GRUB_KERNEL_I386_PC_REED_SOLOMON_REDUNDANCY 0x1c /* The size of the first region which won't be compressed. */ -#define GRUB_KERNEL_I386_PC_RAW_SIZE 0xc90 +#define GRUB_KERNEL_I386_PC_RAW_SIZE 0xca4 -#define GRUB_KERNEL_I386_PC_NO_REED_SOLOMON_PART 0x6f8 +#define GRUB_KERNEL_I386_PC_NO_REED_SOLOMON_PART 0x70c /* The offset of GRUB_PREFIX. */ #define GRUB_KERNEL_I386_PC_PREFIX GRUB_KERNEL_I386_PC_RAW_SIZE From ab66c69f1a91617b429d73c59987e2c0c7d898c3 Mon Sep 17 00:00:00 2001 From: Jordan Uggla Date: Thu, 23 Dec 2010 11:51:18 +0000 Subject: [PATCH 136/869] * tests/util/grub-shell.in: Suppress "ACPI shutdown failed" error to keep unit tests from failing when they shouldn't. --- ChangeLog | 5 +++++ tests/util/grub-shell.in | 2 ++ 2 files changed, 7 insertions(+) diff --git a/ChangeLog b/ChangeLog index 27e2aee97..79eeae387 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2010-12-23 Jordan Uggla + + * tests/util/grub-shell.in: Suppress "ACPI shutdown failed" error to + keep unit tests from failing when they shouldn't. + 2010-12-21 Colin Watson * include/grub/offsets.h (GRUB_KERNEL_I386_PC_RAW_SIZE): The diff --git a/tests/util/grub-shell.in b/tests/util/grub-shell.in index fc14ca7b0..e35d6bc65 100644 --- a/tests/util/grub-shell.in +++ b/tests/util/grub-shell.in @@ -132,6 +132,8 @@ done cat <>${cfgfile} source /boot/grub/testcase.cfg +# Stop serial output to suppress "ACPI shutdown failed" error. +terminal_output console halt EOF From 1c95b6d2bfb721df4859414a4f31ac8ed9c7bc8d Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Thu, 23 Dec 2010 12:11:44 +0000 Subject: [PATCH 137/869] Move video/colors.c into video.mod. --- ChangeLog.parse-color | 5 ++--- grub-core/Makefile.core.def | 7 +------ 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/ChangeLog.parse-color b/ChangeLog.parse-color index b241f3b73..81628e89f 100644 --- a/ChangeLog.parse-color +++ b/ChangeLog.parse-color @@ -1,4 +1,4 @@ -2010-12-10 Colin Watson +2010-12-23 Colin Watson Move gfxmenu color handling to video, so that gfxterm can use it too. @@ -30,8 +30,7 @@ * grub-core/Makefile.core.def (kernel) [videoinkernel]: Add video/colors.c. (gfxmenu): Remove gfxmenu/named_colors.c. - (video_colors) [videomodules]: New module, containing - video/colors.c. + (video) [videomodules]: Add video/colors.c. Add a background_color command. diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def index fdf7d0826..8566c79fb 100644 --- a/grub-core/Makefile.core.def +++ b/grub-core/Makefile.core.def @@ -1442,12 +1442,6 @@ module = { enable = i386_pc; }; -module = { - name = video_colors; - common = video/colors.c; - enable = videomodules; -}; - module = { name = video_fb; common = video/fb/video_fb.c; @@ -1460,6 +1454,7 @@ module = { module = { name = video; common = video/video.c; + common = video/colors.c; enable = videomodules; }; From af4e4a875acc4398a211b8e15ffa8ee40b1efdce Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Thu, 23 Dec 2010 12:19:55 +0000 Subject: [PATCH 138/869] return GRUB_ERR_NONE instead of setting grub_errno --- grub-core/term/gfxterm.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/grub-core/term/gfxterm.c b/grub-core/term/gfxterm.c index 09363918a..8a75df93c 100644 --- a/grub-core/term/gfxterm.c +++ b/grub-core/term/gfxterm.c @@ -1235,9 +1235,7 @@ grub_gfxterm_background_color_cmd (grub_command_t cmd __attribute__ ((unused)), /* Mark whole screen as dirty. */ dirty_region_add (0, 0, window.width, window.height); - /* All was ok. */ - grub_errno = GRUB_ERR_NONE; - return grub_errno; + return GRUB_ERR_NONE; } static struct grub_term_output grub_video_term = From c7336d912c656c4b7c7162e8dee6f5001e732be5 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 24 Dec 2010 16:07:53 +0100 Subject: [PATCH 139/869] splitting generic ata from pata. --- commands/hdparm.c | 95 +++-- disk/ahci.c | 289 ++++++++++----- disk/ata.c | 829 ++++++++++++++------------------------------ disk/ata_pthru.c | 520 ++++++++++++++++++++++++--- disk/scsi.c | 38 +- disk/usbms.c | 12 +- include/grub/ata.h | 122 ++++--- include/grub/disk.h | 13 +- include/grub/scsi.h | 16 +- kern/disk.c | 4 - 10 files changed, 1095 insertions(+), 843 deletions(-) diff --git a/commands/hdparm.c b/commands/hdparm.c index a3f8bbff0..02ae8f36b 100644 --- a/commands/hdparm.c +++ b/commands/hdparm.c @@ -18,6 +18,7 @@ */ #include +#include #include #include #include @@ -61,60 +62,60 @@ enum grub_ata_smart_commands static int quiet = 0; static grub_err_t -grub_hdparm_do_ata_cmd (grub_disk_t disk, grub_uint8_t cmd, +grub_hdparm_do_ata_cmd (grub_ata_t ata, grub_uint8_t cmd, grub_uint8_t features, grub_uint8_t sectors, void * buffer, int size) { struct grub_disk_ata_pass_through_parms apt; grub_memset (&apt, 0, sizeof (apt)); - apt.taskfile[GRUB_ATA_REG_CMD] = cmd; - apt.taskfile[GRUB_ATA_REG_FEATURES] = features; - apt.taskfile[GRUB_ATA_REG_SECTORS] = sectors; + apt.taskfile.cmd = cmd; + apt.taskfile.features = features; + apt.taskfile.sectors = sectors; apt.buffer = buffer; apt.size = size; - if (grub_disk_ata_pass_through (disk, &apt)) + if (ata->dev->readwrite (ata, &apt)) return grub_errno; return GRUB_ERR_NONE; } static int -grub_hdparm_do_check_powermode_cmd (grub_disk_t disk) +grub_hdparm_do_check_powermode_cmd (grub_ata_t ata) { struct grub_disk_ata_pass_through_parms apt; grub_memset (&apt, 0, sizeof (apt)); - apt.taskfile[GRUB_ATA_REG_CMD] = GRUB_ATA_CMD_CHECK_POWER_MODE; + apt.taskfile.cmd = GRUB_ATA_CMD_CHECK_POWER_MODE; - if (grub_disk_ata_pass_through (disk, &apt)) + if (ata->dev->readwrite (ata, &apt)) return -1; - return apt.taskfile[GRUB_ATA_REG_SECTORS]; + return apt.taskfile.sectors; } static int -grub_hdparm_do_smart_cmd (grub_disk_t disk, grub_uint8_t features) +grub_hdparm_do_smart_cmd (grub_ata_t ata, grub_uint8_t features) { struct grub_disk_ata_pass_through_parms apt; grub_memset (&apt, 0, sizeof (apt)); - apt.taskfile[GRUB_ATA_REG_CMD] = GRUB_ATA_CMD_SMART; - apt.taskfile[GRUB_ATA_REG_FEATURES] = features; - apt.taskfile[GRUB_ATA_REG_LBAMID] = 0x4f; - apt.taskfile[GRUB_ATA_REG_LBAHIGH] = 0xc2; + apt.taskfile.cmd = GRUB_ATA_CMD_SMART; + apt.taskfile.features = features; + apt.taskfile.lba_mid = 0x4f; + apt.taskfile.lba_high = 0xc2; - if (grub_disk_ata_pass_through (disk, &apt)) + if (ata->dev->readwrite (ata, &apt)) return -1; if (features == GRUB_ATA_FEAT_SMART_STATUS) { - if ( apt.taskfile[GRUB_ATA_REG_LBAMID] == 0x4f - && apt.taskfile[GRUB_ATA_REG_LBAHIGH] == 0xc2) + if ( apt.taskfile.lba_mid == 0x4f + && apt.taskfile.lba_high == 0xc2) return 0; /* Good SMART status. */ - else if ( apt.taskfile[GRUB_ATA_REG_LBAMID] == 0xf4 - && apt.taskfile[GRUB_ATA_REG_LBAHIGH] == 0x2c) + else if ( apt.taskfile.lba_mid == 0xf4 + && apt.taskfile.lba_high == 0x2c) return 1; /* Bad SMART status. */ else return -1; @@ -124,12 +125,12 @@ grub_hdparm_do_smart_cmd (grub_disk_t disk, grub_uint8_t features) static grub_err_t grub_hdparm_simple_cmd (const char * msg, - grub_disk_t disk, grub_uint8_t cmd) + grub_ata_t ata, grub_uint8_t cmd) { if (! quiet && msg) grub_printf ("%s", msg); - grub_err_t err = grub_hdparm_do_ata_cmd (disk, cmd, 0, 0, NULL, 0); + grub_err_t err = grub_hdparm_do_ata_cmd (ata, cmd, 0, 0, NULL, 0); if (! quiet && msg) grub_printf ("%s\n", ! err ? "" : ": not supported"); @@ -138,7 +139,7 @@ grub_hdparm_simple_cmd (const char * msg, static grub_err_t grub_hdparm_set_val_cmd (const char * msg, int val, - grub_disk_t disk, grub_uint8_t cmd, + grub_ata_t ata, grub_uint8_t cmd, grub_uint8_t features, grub_uint8_t sectors) { if (! quiet && msg && *msg) @@ -149,7 +150,7 @@ grub_hdparm_set_val_cmd (const char * msg, int val, grub_printf ("Disable %s", msg); } - grub_err_t err = grub_hdparm_do_ata_cmd (disk, cmd, features, sectors, + grub_err_t err = grub_hdparm_do_ata_cmd (ata, cmd, features, sectors, NULL, 0); if (! quiet && msg) @@ -273,6 +274,7 @@ static grub_err_t grub_cmd_hdparm (grub_extcmd_t cmd, int argc, char **args) // state???? { struct grub_arg_list *state = cmd->state; + struct grub_ata *ata; /* Check command line. */ if (argc != 1) @@ -283,9 +285,6 @@ grub_cmd_hdparm (grub_extcmd_t cmd, int argc, char **args) // state???? return grub_error (GRUB_ERR_BAD_ARGUMENT, "argument is not a device name"); args[0][len - 1] = 0; - if (! grub_disk_ata_pass_through) - return grub_error (GRUB_ERR_BAD_ARGUMENT, "ATA pass through not available"); - int i = 0; int apm = get_int_arg (&state[i++]); int power = state[i++].set; @@ -311,15 +310,37 @@ grub_cmd_hdparm (grub_extcmd_t cmd, int argc, char **args) // state???? return grub_error (GRUB_ERR_BAD_ARGUMENT, "partition not allowed"); } + switch (disk->dev->id) + { + case GRUB_DISK_DEVICE_ATA_ID: + ata = disk->data; + break; + case GRUB_DISK_DEVICE_SCSI_ID: + if (((disk->id >> GRUB_SCSI_ID_SUBSYSTEM_SHIFT) & 0xFF) + == GRUB_SCSI_SUBSYSTEM_PATA + || (((disk->id >> GRUB_SCSI_ID_SUBSYSTEM_SHIFT) & 0xFF) + == GRUB_SCSI_SUBSYSTEM_AHCI)) + { + ata = ((struct grub_scsi *) disk->data)->data; + break; + } + default: + return grub_error (GRUB_ERR_IO, "not an ATA device"); + } + + /* Change settings. */ if (aam >= 0) grub_hdparm_set_val_cmd ("Automatic Acoustic Management", (aam ? aam : -1), - disk, GRUB_ATA_CMD_SET_FEATURES, (aam ? 0x42 : 0xc2), aam); + ata, GRUB_ATA_CMD_SET_FEATURES, + (aam ? 0x42 : 0xc2), aam); if (apm >= 0) grub_hdparm_set_val_cmd ("Advanced Power Management", - (apm != 255 ? apm : -1), disk, GRUB_ATA_CMD_SET_FEATURES, - (apm != 255 ? 0x05 : 0x85), (apm != 255 ? apm : 0)); + (apm != 255 ? apm : -1), ata, + GRUB_ATA_CMD_SET_FEATURES, + (apm != 255 ? 0x05 : 0x85), + (apm != 255 ? apm : 0)); if (standby_tout >= 0) { @@ -330,28 +351,28 @@ grub_cmd_hdparm (grub_extcmd_t cmd, int argc, char **args) // state???? grub_printf (")"); } /* The IDLE cmd sets disk to idle mode and configures standby timer. */ - grub_hdparm_set_val_cmd ("", -1, disk, GRUB_ATA_CMD_IDLE, 0, standby_tout); + grub_hdparm_set_val_cmd ("", -1, ata, GRUB_ATA_CMD_IDLE, 0, standby_tout); } if (enable_smart >= 0) { if (! quiet) grub_printf ("%sable SMART operations", (enable_smart ? "En" : "Dis")); - int err = grub_hdparm_do_smart_cmd (disk, (enable_smart ? + int err = grub_hdparm_do_smart_cmd (ata, (enable_smart ? GRUB_ATA_FEAT_SMART_ENABLE : GRUB_ATA_FEAT_SMART_DISABLE)); if (! quiet) grub_printf ("%s\n", err ? ": not supported" : ""); } if (sec_freeze) - grub_hdparm_simple_cmd ("Freeze security settings", disk, + grub_hdparm_simple_cmd ("Freeze security settings", ata, GRUB_ATA_CMD_SECURITY_FREEZE_LOCK); /* Print/dump IDENTIFY. */ if (ident || dumpid) { char buf[GRUB_DISK_SECTOR_SIZE]; - if (grub_hdparm_do_ata_cmd (disk, GRUB_ATA_CMD_IDENTIFY_DEVICE, + if (grub_hdparm_do_ata_cmd (ata, GRUB_ATA_CMD_IDENTIFY_DEVICE, 0, 0, buf, sizeof (buf))) grub_printf ("Cannot read ATA IDENTIFY data\n"); else @@ -367,7 +388,7 @@ grub_cmd_hdparm (grub_extcmd_t cmd, int argc, char **args) // state???? if (power) { grub_printf ("Disk power mode is: "); - int mode = grub_hdparm_do_check_powermode_cmd (disk); + int mode = grub_hdparm_do_check_powermode_cmd (ata); if (mode < 0) grub_printf ("unknown\n"); else @@ -383,7 +404,7 @@ grub_cmd_hdparm (grub_extcmd_t cmd, int argc, char **args) // state???? { if (! quiet) grub_printf ("SMART status is: "); - int err = grub_hdparm_do_smart_cmd (disk, GRUB_ATA_FEAT_SMART_STATUS); + int err = grub_hdparm_do_smart_cmd (ata, GRUB_ATA_FEAT_SMART_STATUS); if (! quiet) grub_printf ("%s\n", (err < 0 ? "unknown" : err == 0 ? "OK" : "*BAD*")); @@ -392,11 +413,11 @@ grub_cmd_hdparm (grub_extcmd_t cmd, int argc, char **args) // state???? /* Change power mode. */ if (standby_now) - grub_hdparm_simple_cmd ("Set disk to standby mode", disk, + grub_hdparm_simple_cmd ("Set disk to standby mode", ata, GRUB_ATA_CMD_STANDBY_IMMEDIATE); if (sleep_now) - grub_hdparm_simple_cmd ("Set disk to sleep mode", disk, + grub_hdparm_simple_cmd ("Set disk to sleep mode", ata, GRUB_ATA_CMD_SLEEP); grub_disk_close (disk); diff --git a/disk/ahci.c b/disk/ahci.c index 1372fd651..946db82e1 100644 --- a/disk/ahci.c +++ b/disk/ahci.c @@ -21,39 +21,79 @@ #include #include #include +#include #include +#include +#include struct grub_ahci_cmd_head { - grub_uint32_t unused[8]; + grub_uint32_t config; + grub_uint32_t transfered; + grub_uint64_t command_table_base; + grub_uint32_t unused[4]; +}; + +struct grub_ahci_prdt_entry +{ + grub_uint64_t data_base; + grub_uint32_t unused; + grub_uint32_t size; +}; + +struct grub_ahci_cmd_table +{ + grub_uint8_t cfis[0x40]; + grub_uint8_t command[16]; + grub_uint32_t reserved[0xc]; + struct grub_ahci_prdt_entry prdt[1]; }; struct grub_ahci_hba_port { grub_uint64_t command_list_base; - grub_uint32_t unused[12]; + grub_uint64_t fis_base; + grub_uint32_t intstatus; + grub_uint32_t inten; + grub_uint32_t command; + grub_uint32_t unused1[6]; grub_uint32_t sata_active; grub_uint32_t command_issue; - grub_uint32_t unused[16]; + grub_uint32_t unused2[17]; }; struct grub_ahci_hba { grub_uint32_t cap; -#define GRUB_AHCI_HBA_CAP_MASK 0x1f grub_uint32_t global_control; -#define GRUB_AHCI_HBA_GLOBAL_CONTROL_AHCI_EN 0x80000000 + grub_uint32_t intr_status; grub_uint32_t ports_implemented; - grub_uint32_t unused1[7]; + grub_uint32_t unused1[6]; grub_uint32_t bios_handoff; -#define GRUB_AHCI_BIOS_HANDOFF_BIOS_OWNED 1 -#define GRUB_AHCI_BIOS_HANDOFF_OS_OWNED 2 -#define GRUB_AHCI_BIOS_HANDOFF_OS_OWNERSHIP_CHANGED 8 -#define GRUB_AHCI_BIOS_HANDOFF_RWC 8 grub_uint32_t unused2[53]; struct grub_ahci_hba_port ports[32]; }; +enum + { + GRUB_AHCI_HBA_CAP_NPORTS_MASK = 0x1f + }; + +enum + { + GRUB_AHCI_HBA_GLOBAL_CONTROL_INTR_EN = 0x00000002, + GRUB_AHCI_HBA_GLOBAL_CONTROL_AHCI_EN = 0x80000000, + }; + +enum + { + GRUB_AHCI_BIOS_HANDOFF_BIOS_OWNED = 1, + GRUB_AHCI_BIOS_HANDOFF_OS_OWNED = 2, + GRUB_AHCI_BIOS_HANDOFF_OS_OWNERSHIP_CHANGED = 8, + GRUB_AHCI_BIOS_HANDOFF_RWC = 8 + }; + + struct grub_ahci_device { struct grub_ahci_device *next; @@ -62,19 +102,41 @@ struct grub_ahci_device int num; struct grub_pci_dma_chunk *command_list_chunk; volatile struct grub_ahci_cmd_head *command_list; + struct grub_pci_dma_chunk *command_table_chunk; + volatile struct grub_ahci_cmd_table *command_table; }; +enum + { + GRUB_AHCI_CONFIG_READ = 0, + GRUB_AHCI_CONFIG_CFIS_LENGTH_MASK = 0x1f, + GRUB_AHCI_CONFIG_ATAPI = 0x20, + GRUB_AHCI_CONFIG_WRITE = 0x40, + GRUB_AHCI_CONFIG_PREFETCH = 0x80, + GRUB_AHCI_CONFIG_RESET = 0x100, + GRUB_AHCI_CONFIG_BIST = 0x200, + GRUB_AHCI_CONFIG_CLEAR_R_OK = 0x400, + GRUB_AHCI_CONFIG_PMP_MASK = 0xf000, + GRUB_AHCI_CONFIG_PRDT_LENGTH_MASK = 0xffff0000, + }; +#define GRUB_AHCI_CONFIG_CFIS_LENGTH_SHIFT 0 +#define GRUB_AHCI_CONFIG_PMP_SHIFT 12 +#define GRUB_AHCI_CONFIG_PRDT_LENGTH_SHIFT 16 +#define GRUB_AHCI_INTERRUPT_ON_COMPLETE 0x80000000 + +#define GRUB_AHCI_PRDT_MAX_CHUNK_LENGTH 0x200000 + static struct grub_ahci_device *grub_ahci_devices; static int numdevs; static int NESTED_FUNC_ATTR grub_ahci_pciinit (grub_pci_device_t dev, - grub_pci_id_t pciid __attribute__ ((unused))) + grub_pci_id_t pciid __attribute__ ((unused))) { grub_pci_address_t addr; grub_uint32_t class; grub_uint32_t bar; - int nports; + unsigned i, nports; volatile struct grub_ahci_hba *hba; /* Read class. */ @@ -88,8 +150,8 @@ grub_ahci_pciinit (grub_pci_device_t dev, addr = grub_pci_make_address (dev, GRUB_PCI_REG_ADDRESS_REG5); bar = grub_pci_read (addr); - if (bar & (GRUB_PCI_ADDR_SPACE_MASK | GRUB_PCI_ADDR_MEM_TYPE_MASK - | GRUB_PCI_ADDR_MEM_PREFETCH) + if ((bar & (GRUB_PCI_ADDR_SPACE_MASK | GRUB_PCI_ADDR_MEM_TYPE_MASK + | GRUB_PCI_ADDR_MEM_PREFETCH)) != (GRUB_PCI_ADDR_SPACE_MEMORY | GRUB_PCI_ADDR_MEM_TYPE_32)) return 0; @@ -98,7 +160,7 @@ grub_ahci_pciinit (grub_pci_device_t dev, hba->global_control |= GRUB_AHCI_HBA_GLOBAL_CONTROL_AHCI_EN; - nports = hba->cap & GRUB_AHCI_HBA_CAP_MASK; + nports = (hba->cap & GRUB_AHCI_HBA_CAP_NPORTS_MASK) + 1; if (! (hba->bios_handoff & GRUB_AHCI_BIOS_HANDOFF_OS_OWNED)) { @@ -122,11 +184,13 @@ grub_ahci_pciinit (grub_pci_device_t dev, } else grub_dprintf ("ahci", "AHCI is already in OS mode\n"); + grub_dprintf ("ahci", "%d AHCI ports\n", nports); for (i = 0; i < nports; i++) { struct grub_ahci_device *adev; struct grub_pci_dma_chunk *command_list; + struct grub_pci_dma_chunk *command_table; if (!(hba->ports_implemented & (1 << i))) continue; @@ -136,18 +200,34 @@ grub_ahci_pciinit (grub_pci_device_t dev, if (!command_list) return 1; - adev = grub_malloc (sizeof (*adev)); - if (!adev) + command_table = grub_memalign_dma32 (1024, + sizeof (struct grub_ahci_cmd_table)); + if (!command_table) { grub_dma_free (command_list); return 1; } + adev = grub_malloc (sizeof (*adev)); + if (!adev) + { + grub_dma_free (command_list); + grub_dma_free (command_table); + return 1; + } + + grub_dprintf ("ahci", "found device ahci%d (port %d)\n", numdevs, i); + adev->hba = hba; adev->port = i; adev->num = numdevs++; adev->command_list_chunk = command_list; adev->command_list = grub_dma_get_virt (command_list); + adev->command_table_chunk = command_table; + adev->command_table = grub_dma_get_virt (command_table); + adev->command_list->command_table_base + = grub_dma_get_phys (command_table); + adev->hba->ports[i].command_list_base = grub_dma_get_phys (command_list); grub_list_push (GRUB_AS_LIST_P (&grub_ahci_devices), GRUB_AS_LIST (adev)); @@ -167,12 +247,12 @@ grub_ahci_initialize (void) static int -grub_ahci_iterate (int (*hook) (int bus, int luns)) +grub_ahci_iterate (int (*hook) (int id, int bus)) { struct grub_ahci_device *dev; FOR_LIST_ELEMENTS(dev, grub_ahci_devices) - if (hook (dev->num, 1)) + if (hook (GRUB_SCSI_SUBSYSTEM_AHCI, dev->num)) return 1; return 0; @@ -195,95 +275,130 @@ find_free_cmd_slot (struct grub_ahci_device *dev) } #endif -static grub_err_t -grub_ahci_packet (struct grub_ahci_device *dev, char *packet, - grub_size_t size) +enum + { + GRUB_AHCI_FIS_REG_H2D = 0x27 + }; + +static const int register_map[11] = { 3 /* Features */, + 12 /* Sectors */, + 4 /* LBA low */, + 5 /* LBA mid */, + 6 /* LBA high */, + 7 /* Device */, + 2 /* CMD register */, + 13 /* Sectors 48 */, + 8 /* LBA48 low */, + 9 /* LBA48 mid */, + 10 /* LBA48 high */ }; + +static grub_err_t +grub_ahci_readwrite (grub_ata_t disk, + struct grub_disk_ata_pass_through_parms *parms) { + struct grub_ahci_device *dev = (struct grub_ahci_device *) disk->data; + struct grub_pci_dma_chunk *bufc; + grub_uint64_t endtime; + unsigned i; + + grub_dprintf("ahci", "grub_ahci_read (size=%llu, cmdsize = %llu)\n", + (unsigned long long) parms->size, + (unsigned long long) parms->cmdsize); + + if (parms->cmdsize != 0 && parms->cmdsize != 12 && parms->cmdsize != 16) + return grub_error (GRUB_ERR_BAD_ARGUMENT, "incorrect ATAPI command size"); + + if (parms->size > GRUB_AHCI_PRDT_MAX_CHUNK_LENGTH) + return grub_error (GRUB_ERR_BAD_ARGUMENT, "too big data buffer"); + + bufc = grub_memalign_dma32 (1024, parms->size + (parms->size & 1)); + + /* FIXME: support port multipliers. */ + dev->command_list[0].config + = (4 << GRUB_AHCI_CONFIG_CFIS_LENGTH_SHIFT) + | GRUB_AHCI_CONFIG_CLEAR_R_OK + | (0 << GRUB_AHCI_CONFIG_PMP_SHIFT) + | (1 << GRUB_AHCI_CONFIG_PRDT_LENGTH_SHIFT) + | (parms->cmdsize ? GRUB_AHCI_CONFIG_ATAPI : 0) + | (parms->write ? GRUB_AHCI_CONFIG_WRITE : GRUB_AHCI_CONFIG_READ); + dev->command_list[0].transfered = 0; + dev->command_list[0].command_table_base + = grub_dma_get_phys (dev->command_table_chunk); + grub_memset ((char *) dev->command_list[0].unused, 0, + sizeof (dev->command_list[0].unused)); + grub_memset ((char *) &dev->command_table[0], 0, + sizeof (dev->command_table[0])); + if (parms->cmdsize) + grub_memcpy ((char *) dev->command_table[0].command, parms->cmd, + parms->cmdsize); + + dev->command_table[0].cfis[0] = GRUB_AHCI_FIS_REG_H2D; + for (i = 0; i < sizeof (parms->taskfile.raw); i++) + dev->command_table[0].cfis[register_map[i]] = parms->taskfile.raw[i]; + + dev->command_table[0].prdt[0].data_base = grub_dma_get_phys (bufc); + dev->command_table[0].prdt[0].unused = 0; + dev->command_table[0].prdt[0].size = (parms->size + (parms->size & 1) - 1) + | GRUB_AHCI_INTERRUPT_ON_COMPLETE; + + if (parms->write) + grub_memcpy ((char *) grub_dma_get_virt (bufc), parms->buffer, parms->size); + + grub_dprintf ("ahci", "AHCI command schedulded\n"); + dev->hba->ports[dev->port].inten = (1 << 5); + dev->hba->ports[dev->port].intstatus = (1 << 5); + dev->hba->ports[dev->port].command_issue |= 1; + dev->hba->ports[dev->port].command |= 1; + + endtime = grub_get_time_ms () + 1000; + while (!(dev->hba->ports[dev->port].intstatus & (1 << 5))) + if (grub_get_time_ms () > endtime) + { + grub_dprintf ("ahci", "AHCI timeout\n"); + dev->hba->ports[dev->port].command &= ~1; + /* FIXME: free resources. */ + return grub_error (GRUB_ERR_IO, "AHCI transfer timeouted"); + } + + grub_dprintf ("ahci", "AHCI command completed succesfully\n"); + dev->hba->ports[dev->port].command &= ~1; + + if (!parms->write) + grub_memcpy (parms->buffer, (char *) grub_dma_get_virt (bufc), parms->size); + grub_dma_free (bufc); return GRUB_ERR_NONE; } static grub_err_t -grub_ahci_read (struct grub_scsi *scsi, - grub_size_t cmdsize __attribute__((unused)), - char *cmd, grub_size_t size, char *buf) -{ - struct grub_ahci_device *dev = (struct grub_ahci_device *) scsi->data; - - grub_dprintf("ahci", "grub_ahci_read (size=%llu)\n", (unsigned long long) size); - - if (grub_atapi_packet (dev, cmd, size)) - return grub_errno; - - grub_size_t nread = 0; - while (nread < size) - { - /* Wait for !BSY, DRQ, I/O, !C/D. */ - if (grub_atapi_wait_drq (dev, GRUB_ATAPI_IREASON_DATA_IN, GRUB_ATA_TOUT_DATA)) - return grub_errno; - - /* Get byte count for this DRQ assertion. */ - unsigned cnt = grub_ata_regget (dev, GRUB_ATAPI_REG_CNTHIGH) << 8 - | grub_ata_regget (dev, GRUB_ATAPI_REG_CNTLOW); - grub_dprintf("ata", "DRQ count=%u\n", cnt); - - /* Count of last transfer may be uneven. */ - if (! (0 < cnt && cnt <= size - nread && (! (cnt & 1) || cnt == size - nread))) - return grub_error (GRUB_ERR_READ_ERROR, "invalid ATAPI transfer count"); - - /* Read the data. */ - grub_ata_pio_read (dev, buf + nread, cnt); - - if (cnt & 1) - buf[nread + cnt - 1] = (char) grub_le_to_cpu16 (grub_inw (dev->ioaddress + GRUB_ATA_REG_DATA)); - - nread += cnt; - } - - return GRUB_ERR_NONE; -} - -static grub_err_t -grub_ahci_write (struct grub_scsi *scsi __attribute__((unused)), - grub_size_t cmdsize __attribute__((unused)), - char *cmd __attribute__((unused)), - grub_size_t size __attribute__((unused)), - char *buf __attribute__((unused))) -{ - // XXX: scsi.mod does not use write yet. - return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, "AHCI write not implemented"); -} - -static grub_err_t -grub_ahci_open (int devnum, struct grub_scsi *scsi) +grub_ahci_open (int id, int devnum, struct grub_ata *ata) { struct grub_ahci_device *dev; + if (id != GRUB_SCSI_SUBSYSTEM_AHCI) + return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "not an AHCI device"); + FOR_LIST_ELEMENTS(dev, grub_ahci_devices) { if (dev->num == devnum) break; } - grub_dprintf ("ata", "opening AHCI dev `ahci%d'\n", devnum); - if (! dev) return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "no such AHCI device"); - scsi->data = dev; + grub_dprintf ("ahci", "opening AHCI dev `ahci%d'\n", dev->num); + + ata->data = dev; return GRUB_ERR_NONE; } - -static struct grub_scsi_dev grub_ahci_dev = +static struct grub_ata_dev grub_ahci_dev = { - .name = "ahci", - .id = GRUB_SCSI_SUBSYSTEM_AHCI, .iterate = grub_ahci_iterate, .open = grub_ahci_open, - .read = grub_ahci_read, - .write = grub_ahci_write + .readwrite = grub_ahci_readwrite, }; @@ -291,8 +406,8 @@ static struct grub_scsi_dev grub_ahci_dev = GRUB_MOD_INIT(ahci) { /* To prevent two drivers operating on the same disks. */ - grub_disk_firmware_is_tainted = 1; - if (grub_disk_firmware_fini) + // grub_disk_firmware_is_tainted = 1; + if (0 && grub_disk_firmware_fini) { grub_disk_firmware_fini (); grub_disk_firmware_fini = NULL; @@ -302,10 +417,10 @@ GRUB_MOD_INIT(ahci) grub_ahci_initialize (); /* AHCI devices are handled by scsi.mod. */ - grub_scsi_dev_register (&grub_ahci_dev); + grub_ata_dev_register (&grub_ahci_dev); } GRUB_MOD_FINI(ahci) { - grub_scsi_dev_unregister (&grub_ahci_dev); + grub_ata_dev_unregister (&grub_ahci_dev); } diff --git a/disk/ata.c b/disk/ata.c index cfd58a6d5..3d9de23dd 100644 --- a/disk/ata.c +++ b/disk/ata.c @@ -21,76 +21,9 @@ #include #include #include -#include -#include #include -#include -/* At the moment, only two IDE ports are supported. */ -static const grub_port_t grub_ata_ioaddress[] = { GRUB_ATA_CH0_PORT1, - GRUB_ATA_CH1_PORT1 }; -static const grub_port_t grub_ata_ioaddress2[] = { GRUB_ATA_CH0_PORT2, - GRUB_ATA_CH1_PORT2 }; - -static struct grub_ata_device *grub_ata_devices; - -/* Wait for !BSY. */ -grub_err_t -grub_ata_wait_not_busy (struct grub_ata_device *dev, int milliseconds) -{ - /* ATA requires 400ns (after a write to CMD register) or - 1 PIO cycle (after a DRQ block transfer) before - first check of BSY. */ - grub_millisleep (1); - - int i = 1; - grub_uint8_t sts; - while ((sts = grub_ata_regget (dev, GRUB_ATA_REG_STATUS)) - & GRUB_ATA_STATUS_BUSY) - { - if (i >= milliseconds) - { - grub_dprintf ("ata", "timeout: %dms, status=0x%x\n", - milliseconds, sts); - return grub_error (GRUB_ERR_TIMEOUT, "ATA timeout"); - } - - grub_millisleep (1); - i++; - } - - return GRUB_ERR_NONE; -} - -static inline void -grub_ata_wait (void) -{ - grub_millisleep (50); -} - -/* Wait for !BSY, DRQ. */ -grub_err_t -grub_ata_wait_drq (struct grub_ata_device *dev, int rw, - int milliseconds) -{ - if (grub_ata_wait_not_busy (dev, milliseconds)) - return grub_errno; - - /* !DRQ implies error condition. */ - grub_uint8_t sts = grub_ata_regget (dev, GRUB_ATA_REG_STATUS); - if ((sts & (GRUB_ATA_STATUS_DRQ | GRUB_ATA_STATUS_ERR)) - != GRUB_ATA_STATUS_DRQ) - { - grub_dprintf ("ata", "ata error: status=0x%x, error=0x%x\n", - sts, grub_ata_regget (dev, GRUB_ATA_REG_ERROR)); - if (! rw) - return grub_error (GRUB_ERR_READ_ERROR, "ATA read error"); - else - return grub_error (GRUB_ERR_WRITE_ERROR, "ATA write error"); - } - - return GRUB_ERR_NONE; -} +static grub_ata_dev_t grub_ata_dev_list; /* Byteorder has to be changed before strings can be read. */ static void @@ -105,30 +38,8 @@ grub_ata_strncpy (char *dst, char *src, grub_size_t len) dst[len] = '\0'; } -void -grub_ata_pio_read (struct grub_ata_device *dev, char *buf, grub_size_t size) -{ - grub_uint16_t *buf16 = (grub_uint16_t *) buf; - unsigned int i; - - /* Read in the data, word by word. */ - for (i = 0; i < size / 2; i++) - buf16[i] = grub_le_to_cpu16 (grub_inw(dev->ioaddress + GRUB_ATA_REG_DATA)); -} - static void -grub_ata_pio_write (struct grub_ata_device *dev, char *buf, grub_size_t size) -{ - grub_uint16_t *buf16 = (grub_uint16_t *) buf; - unsigned int i; - - /* Write the data, word by word. */ - for (i = 0; i < size / 2; i++) - grub_outw(grub_cpu_to_le16 (buf16[i]), dev->ioaddress + GRUB_ATA_REG_DATA); -} - -static void -grub_ata_dumpinfo (struct grub_ata_device *dev, char *info) +grub_ata_dumpinfo (struct grub_ata *dev, char *info) { char text[41]; @@ -148,31 +59,27 @@ grub_ata_dumpinfo (struct grub_ata_device *dev, char *info) } static grub_err_t -grub_atapi_identify (struct grub_ata_device *dev) +grub_atapi_identify (struct grub_ata *dev) { + struct grub_disk_ata_pass_through_parms parms; char *info; + grub_err_t err; info = grub_malloc (GRUB_DISK_SECTOR_SIZE); if (! info) return grub_errno; - grub_ata_regset (dev, GRUB_ATA_REG_DISK, 0xE0 | dev->device << 4); - grub_ata_wait (); - if (grub_ata_check_ready (dev)) - { - grub_free (info); - return grub_errno; - } + grub_memset (&parms, 0, sizeof (parms)); + parms.taskfile.disk = 0; + parms.taskfile.cmd = GRUB_ATA_CMD_IDENTIFY_PACKET_DEVICE; - grub_ata_regset (dev, GRUB_ATA_REG_CMD, GRUB_ATA_CMD_IDENTIFY_PACKET_DEVICE); - grub_ata_wait (); + err = dev->dev->readwrite (dev, &parms); + if (err) + return err; - if (grub_ata_wait_drq (dev, 0, GRUB_ATA_TOUT_STD)) - { - grub_free (info); - return grub_errno; - } - grub_ata_pio_read (dev, info, GRUB_DISK_SECTOR_SIZE); + if (parms.size != GRUB_DISK_SECTOR_SIZE) + return grub_error (GRUB_ERR_UNKNOWN_DEVICE, + "device cannot be identified"); dev->atapi = 1; @@ -184,96 +91,35 @@ grub_atapi_identify (struct grub_ata_device *dev) } static grub_err_t -grub_atapi_wait_drq (struct grub_ata_device *dev, - grub_uint8_t ireason, - int milliseconds) -{ - /* Wait for !BSY, DRQ, ireason */ - if (grub_ata_wait_not_busy (dev, milliseconds)) - return grub_errno; - - grub_uint8_t sts = grub_ata_regget (dev, GRUB_ATA_REG_STATUS); - grub_uint8_t irs = grub_ata_regget (dev, GRUB_ATAPI_REG_IREASON); - - /* OK if DRQ is asserted and interrupt reason is as expected. */ - if ((sts & GRUB_ATA_STATUS_DRQ) - && (irs & GRUB_ATAPI_IREASON_MASK) == ireason) - return GRUB_ERR_NONE; - - /* !DRQ implies error condition. */ - grub_dprintf ("ata", "atapi error: status=0x%x, ireason=0x%x, error=0x%x\n", - sts, irs, grub_ata_regget (dev, GRUB_ATA_REG_ERROR)); - - if (! (sts & GRUB_ATA_STATUS_DRQ) - && (irs & GRUB_ATAPI_IREASON_MASK) == GRUB_ATAPI_IREASON_ERROR) - { - if (ireason == GRUB_ATAPI_IREASON_CMD_OUT) - return grub_error (GRUB_ERR_READ_ERROR, "ATA PACKET command error"); - else - return grub_error (GRUB_ERR_READ_ERROR, "ATAPI read error"); - } - - return grub_error (GRUB_ERR_READ_ERROR, "ATAPI protocol error"); -} - -static grub_err_t -grub_atapi_packet (struct grub_ata_device *dev, char *packet, - grub_size_t size) -{ - grub_ata_regset (dev, GRUB_ATA_REG_DISK, dev->device << 4); - if (grub_ata_check_ready (dev)) - return grub_errno; - - /* Send ATA PACKET command. */ - grub_ata_regset (dev, GRUB_ATA_REG_FEATURES, 0); - grub_ata_regset (dev, GRUB_ATAPI_REG_IREASON, 0); - grub_ata_regset (dev, GRUB_ATAPI_REG_CNTHIGH, size >> 8); - grub_ata_regset (dev, GRUB_ATAPI_REG_CNTLOW, size & 0xFF); - - grub_ata_regset (dev, GRUB_ATA_REG_CMD, GRUB_ATA_CMD_PACKET); - - /* Wait for !BSY, DRQ, !I/O, C/D. */ - if (grub_atapi_wait_drq (dev, GRUB_ATAPI_IREASON_CMD_OUT, GRUB_ATA_TOUT_STD)) - return grub_errno; - - /* Write the packet. */ - grub_ata_pio_write (dev, packet, 12); - - return GRUB_ERR_NONE; -} - -static grub_err_t -grub_ata_identify (struct grub_ata_device *dev) +grub_ata_identify (struct grub_ata *dev) { + struct grub_disk_ata_pass_through_parms parms; char *info; grub_uint16_t *info16; + grub_err_t err; info = grub_malloc (GRUB_DISK_SECTOR_SIZE); if (! info) return grub_errno; info16 = (grub_uint16_t *) info; + grub_memset (&parms, 0, sizeof (parms)); + parms.buffer = info; + parms.taskfile.disk = 0; - grub_ata_regset (dev, GRUB_ATA_REG_DISK, 0xE0 | dev->device << 4); - grub_ata_wait (); - if (grub_ata_check_ready (dev)) + parms.taskfile.cmd = GRUB_ATA_CMD_IDENTIFY_DEVICE; + + err = dev->dev->readwrite (dev, &parms); + if (err) + return err; + + if (parms.size != GRUB_DISK_SECTOR_SIZE) { + grub_uint8_t sts = parms.taskfile.status; grub_free (info); - return grub_errno; - } - - grub_ata_regset (dev, GRUB_ATA_REG_CMD, GRUB_ATA_CMD_IDENTIFY_DEVICE); - grub_ata_wait (); - - if (grub_ata_wait_drq (dev, 0, GRUB_ATA_TOUT_STD)) - { - grub_free (info); - grub_errno = GRUB_ERR_NONE; - grub_uint8_t sts = grub_ata_regget (dev, GRUB_ATA_REG_STATUS); - if ((sts & (GRUB_ATA_STATUS_BUSY | GRUB_ATA_STATUS_DRQ | GRUB_ATA_STATUS_ERR)) == GRUB_ATA_STATUS_ERR - && (grub_ata_regget (dev, GRUB_ATA_REG_ERROR) & 0x04 /* ABRT */)) + && (parms.taskfile.error & 0x04 /* ABRT */)) /* Device without ATA IDENTIFY, try ATAPI. */ return grub_atapi_identify (dev); @@ -287,19 +133,6 @@ grub_ata_identify (struct grub_ata_device *dev) "device cannot be identified"); } - grub_ata_pio_read (dev, info, GRUB_DISK_SECTOR_SIZE); - - /* Re-check status to avoid bogus identify data due to stuck DRQ. */ - grub_uint8_t sts = grub_ata_regget (dev, GRUB_ATA_REG_STATUS); - if (sts & (GRUB_ATA_STATUS_BUSY | GRUB_ATA_STATUS_DRQ | GRUB_ATA_STATUS_ERR)) - { - grub_dprintf ("ata", "bad status=0x%x\n", sts); - grub_free (info); - /* No device, return error but don't print message. */ - grub_errno = GRUB_ERR_NONE; - return GRUB_ERR_UNKNOWN_DEVICE; - } - /* Now it is certain that this is not an ATAPI device. */ dev->atapi = 0; @@ -335,196 +168,12 @@ grub_ata_identify (struct grub_ata_device *dev) } static grub_err_t -check_device (struct grub_ata_device *dev) -{ - grub_ata_regset (dev, GRUB_ATA_REG_DISK, dev->device << 4); - grub_ata_wait (); - - /* Try to detect if the port is in use by writing to it, - waiting for a while and reading it again. If the value - was preserved, there is a device connected. */ - grub_ata_regset (dev, GRUB_ATA_REG_SECTORS, 0x5A); - grub_ata_wait (); - grub_uint8_t sec = grub_ata_regget (dev, GRUB_ATA_REG_SECTORS); - grub_dprintf ("ata", "sectors=0x%x\n", sec); - if (sec != 0x5A) - return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "no device connected"); - - /* The above test may detect a second (slave) device - connected to a SATA controller which supports only one - (master) device. It is not safe to use the status register - READY bit to check for controller channel existence. Some - ATAPI commands (RESET, DIAGNOSTIC) may clear this bit. */ - - /* Use the IDENTIFY DEVICE command to query the device. */ - return grub_ata_identify (dev); -} - -static grub_err_t -grub_ata_device_initialize (int port, int device, int addr, int addr2) -{ - struct grub_ata_device *dev; - struct grub_ata_device **devp; - grub_err_t err; - - grub_dprintf ("ata", "detecting device %d,%d (0x%x, 0x%x)\n", - port, device, addr, addr2); - - dev = grub_malloc (sizeof(*dev)); - if (! dev) - return grub_errno; - - /* Setup the device information. */ - dev->port = port; - dev->device = device; - dev->ioaddress = addr + GRUB_MACHINE_PCI_IO_BASE; - dev->ioaddress2 = addr2 + GRUB_MACHINE_PCI_IO_BASE; - dev->next = NULL; - - /* Register the device. */ - for (devp = &grub_ata_devices; *devp; devp = &(*devp)->next); - *devp = dev; - - err = check_device (dev); - if (err) - grub_print_error (); - - return 0; -} - -static int NESTED_FUNC_ATTR -grub_ata_pciinit (grub_pci_device_t dev, - grub_pci_id_t pciid) -{ - static int compat_use[2] = { 0 }; - grub_pci_address_t addr; - grub_uint32_t class; - grub_uint32_t bar1; - grub_uint32_t bar2; - int rega; - int regb; - int i; - static int controller = 0; - int cs5536 = 0; - int nports = 2; - - /* Read class. */ - addr = grub_pci_make_address (dev, GRUB_PCI_REG_CLASS); - class = grub_pci_read (addr); - - /* AMD CS5536 Southbridge. */ - if (pciid == GRUB_CS5536_PCIID) - { - cs5536 = 1; - nports = 1; - } - - /* Check if this class ID matches that of a PCI IDE Controller. */ - if (!cs5536 && (class >> 16 != 0x0101)) - return 0; - - for (i = 0; i < nports; i++) - { - /* Set to 0 when the channel operated in compatibility mode. */ - int compat; - - /* We don't support non-compatibility mode for CS5536. */ - if (cs5536) - compat = 0; - else - compat = (class >> (8 + 2 * i)) & 1; - - rega = 0; - regb = 0; - - /* If the channel is in compatibility mode, just assign the - default registers. */ - if (compat == 0 && !compat_use[i]) - { - rega = grub_ata_ioaddress[i]; - regb = grub_ata_ioaddress2[i]; - compat_use[i] = 1; - } - else if (compat) - { - /* Read the BARs, which either contain a mmapped IO address - or the IO port address. */ - addr = grub_pci_make_address (dev, GRUB_PCI_REG_ADDRESSES - + sizeof (grub_uint64_t) * i); - bar1 = grub_pci_read (addr); - addr = grub_pci_make_address (dev, GRUB_PCI_REG_ADDRESSES - + sizeof (grub_uint64_t) * i - + sizeof (grub_uint32_t)); - bar2 = grub_pci_read (addr); - - /* Check if the BARs describe an IO region. */ - if ((bar1 & 1) && (bar2 & 1)) - { - rega = bar1 & ~3; - regb = bar2 & ~3; - } - } - - grub_dprintf ("ata", - "PCI dev (%d,%d,%d) compat=%d rega=0x%x regb=0x%x\n", - grub_pci_get_bus (dev), grub_pci_get_device (dev), - grub_pci_get_function (dev), compat, rega, regb); - - if (rega && regb) - { - grub_errno = GRUB_ERR_NONE; - grub_ata_device_initialize (controller * 2 + i, 0, rega, regb); - - /* Most errors raised by grub_ata_device_initialize() are harmless. - They just indicate this particular drive is not responding, most - likely because it doesn't exist. We might want to ignore specific - error types here, instead of printing them. */ - if (grub_errno) - { - grub_print_error (); - grub_errno = GRUB_ERR_NONE; - } - - grub_ata_device_initialize (controller * 2 + i, 1, rega, regb); - - /* Likewise. */ - if (grub_errno) - { - grub_print_error (); - grub_errno = GRUB_ERR_NONE; - } - } - } - - controller++; - - return 0; -} - -static grub_err_t -grub_ata_initialize (void) -{ - grub_pci_iterate (grub_ata_pciinit); - return 0; -} - -static void -grub_ata_setlba (struct grub_ata_device *dev, grub_disk_addr_t sector, - grub_size_t size) -{ - grub_ata_regset (dev, GRUB_ATA_REG_SECTORS, size); - grub_ata_regset (dev, GRUB_ATA_REG_LBALOW, sector & 0xFF); - grub_ata_regset (dev, GRUB_ATA_REG_LBAMID, (sector >> 8) & 0xFF); - grub_ata_regset (dev, GRUB_ATA_REG_LBAHIGH, (sector >> 16) & 0xFF); -} - -static grub_err_t -grub_ata_setaddress (struct grub_ata_device *dev, - grub_ata_addressing_t addressing, +grub_ata_setaddress (struct grub_ata *dev, + struct grub_disk_ata_pass_through_parms *parms, grub_disk_addr_t sector, grub_size_t size) { - switch (addressing) + switch (dev->addr) { case GRUB_ATA_CHS: { @@ -544,14 +193,11 @@ grub_ata_setaddress (struct grub_ata_device *dev, return grub_error (GRUB_ERR_OUT_OF_RANGE, "sector %d cannot be addressed " "using CHS addressing", sector); - - grub_ata_regset (dev, GRUB_ATA_REG_DISK, (dev->device << 4) | head); - if (grub_ata_check_ready (dev)) - return grub_errno; - - grub_ata_regset (dev, GRUB_ATA_REG_SECTNUM, sect); - grub_ata_regset (dev, GRUB_ATA_REG_CYLLSB, cylinder & 0xFF); - grub_ata_regset (dev, GRUB_ATA_REG_CYLMSB, cylinder >> 8); + + parms->taskfile.disk = head; + parms->taskfile.sectnum = sect; + parms->taskfile.cyllsb = cylinder & 0xFF; + parms->taskfile.cylmsb = cylinder >> 8; break; } @@ -559,26 +205,31 @@ grub_ata_setaddress (struct grub_ata_device *dev, case GRUB_ATA_LBA: if (size == 256) size = 0; - grub_ata_regset (dev, GRUB_ATA_REG_DISK, - 0xE0 | (dev->device << 4) | ((sector >> 24) & 0x0F)); - if (grub_ata_check_ready (dev)) - return grub_errno; + parms->taskfile.disk = ((sector >> 24) & 0x0F); - grub_ata_setlba (dev, sector, size); + parms->taskfile.sectors = size; + parms->taskfile.lba_low = sector & 0xFF; + parms->taskfile.lba_mid = (sector >> 8) & 0xFF; + parms->taskfile.lba_high = (sector >> 16) & 0xFF; break; case GRUB_ATA_LBA48: if (size == 65536) size = 0; - grub_ata_regset (dev, GRUB_ATA_REG_DISK, 0xE0 | (dev->device << 4)); - if (grub_ata_check_ready (dev)) - return grub_errno; + parms->taskfile.disk = 0; /* Set "Previous". */ - grub_ata_setlba (dev, sector >> 24, size >> 8); + parms->taskfile.sectors = size & 0xFF; + parms->taskfile.lba_low = sector & 0xFF; + parms->taskfile.lba_mid = (sector >> 8) & 0xFF; + parms->taskfile.lba_high = (sector >> 16) & 0xFF; + /* Set "Current". */ - grub_ata_setlba (dev, sector, size); + parms->taskfile.sectors48 = (size >> 8) & 0xFF; + parms->taskfile.lba48_low = (sector >> 24) & 0xFF; + parms->taskfile.lba48_mid = (sector >> 32) & 0xFF; + parms->taskfile.lba48_high = (sector >> 40) & 0xFF; break; } @@ -590,14 +241,15 @@ static grub_err_t grub_ata_readwrite (grub_disk_t disk, grub_disk_addr_t sector, grub_size_t size, char *buf, int rw) { - struct grub_ata_device *dev = (struct grub_ata_device *) disk->data; + struct grub_ata *ata = disk->data; - grub_dprintf("ata", "grub_ata_readwrite (size=%llu, rw=%d)\n", (unsigned long long) size, rw); - - grub_ata_addressing_t addressing = dev->addr; + grub_ata_addressing_t addressing = ata->addr; grub_size_t batch; int cmd, cmd_write; + grub_dprintf("ata", "grub_ata_readwrite (size=%llu, rw=%d)\n", + (unsigned long long) size, rw); + if (addressing == GRUB_ATA_LBA48 && ((sector + size) >> 28) != 0) { batch = 65536; @@ -608,7 +260,10 @@ grub_ata_readwrite (grub_disk_t disk, grub_disk_addr_t sector, { if (addressing == GRUB_ATA_LBA48) addressing = GRUB_ATA_LBA; - batch = 256; + if (addressing != GRUB_ATA_CHS) + batch = 256; + else + batch = 1; cmd = GRUB_ATA_CMD_READ_SECTORS; cmd_write = GRUB_ATA_CMD_WRITE_SECTORS; } @@ -616,44 +271,25 @@ grub_ata_readwrite (grub_disk_t disk, grub_disk_addr_t sector, grub_size_t nsectors = 0; while (nsectors < size) { + struct grub_disk_ata_pass_through_parms parms; + grub_err_t err; + if (size - nsectors < batch) batch = size - nsectors; grub_dprintf("ata", "rw=%d, sector=%llu, batch=%llu\n", rw, (unsigned long long) sector, (unsigned long long) batch); - - /* Send read/write command. */ - if (grub_ata_setaddress (dev, addressing, sector, batch)) - return grub_errno; - - grub_ata_regset (dev, GRUB_ATA_REG_CMD, (! rw ? cmd : cmd_write)); - - unsigned sect; - for (sect = 0; sect < batch; sect++) - { - /* Wait for !BSY, DRQ. */ - if (grub_ata_wait_drq (dev, rw, GRUB_ATA_TOUT_DATA)) - return grub_errno; - - /* Transfer data. */ - if (! rw) - grub_ata_pio_read (dev, buf, GRUB_DISK_SECTOR_SIZE); - else - grub_ata_pio_write (dev, buf, GRUB_DISK_SECTOR_SIZE); - - buf += GRUB_DISK_SECTOR_SIZE; - } - - if (rw) - { - /* Check for write error. */ - if (grub_ata_wait_not_busy (dev, GRUB_ATA_TOUT_DATA)) - return grub_errno; - - if (grub_ata_regget (dev, GRUB_ATA_REG_STATUS) - & (GRUB_ATA_STATUS_DRQ | GRUB_ATA_STATUS_ERR)) - return grub_error (GRUB_ERR_WRITE_ERROR, "ATA write error"); - } - + grub_memset (&parms, 0, sizeof (parms)); + grub_ata_setaddress (ata, &parms, sector, batch); + parms.taskfile.cmd = (! rw ? cmd : cmd_write); + parms.buffer = buf; + parms.size = batch * GRUB_DISK_SECTOR_SIZE; + + err = ata->dev->readwrite (ata, &parms); + if (err) + return err; + if (parms.size != batch * GRUB_DISK_SECTOR_SIZE) + return grub_error (GRUB_ERR_READ_ERROR, "incomplete read"); + buf += GRUB_DISK_SECTOR_SIZE * batch; sector += batch; nsectors += batch; } @@ -663,76 +299,118 @@ grub_ata_readwrite (grub_disk_t disk, grub_disk_addr_t sector, -static int -grub_ata_iterate (int (*hook) (const char *name)) +static inline void +grub_ata_real_close (struct grub_ata *ata) { - struct grub_ata_device *dev; + if (ata->dev->close) + ata->dev->close (ata); +} - for (dev = grub_ata_devices; dev; dev = dev->next) +static struct grub_ata * +grub_ata_real_open (int id, int bus) +{ + struct grub_ata *ata; + grub_ata_dev_t p; + + ata = grub_malloc (sizeof (*ata)); + if (!ata) + return NULL; + for (p = grub_ata_dev_list; p; p = p->next) { - char devname[10]; grub_err_t err; - - err = check_device (dev); - if (err) + if (p->open (id, bus, ata)) { grub_errno = GRUB_ERR_NONE; continue; } - - if (dev->atapi) - continue; - - grub_snprintf (devname, sizeof (devname), - "ata%d", dev->port * 2 + dev->device); - - if (hook (devname)) - return 1; + ata->dev = p; + /* Use the IDENTIFY DEVICE command to query the device. */ + err = grub_ata_identify (ata); + if (err) + { + grub_free (ata); + return NULL; + } + return ata; } + grub_free (ata); + grub_error (GRUB_ERR_UNKNOWN_DEVICE, "no such ATA device"); + return NULL; +} +static int +grub_ata_iterate (int (*hook_in) (const char *name)) +{ + auto int hook (int id, int bus); + int hook (int id, int bus) + { + struct grub_ata *ata; + int ret; + char devname[40]; + + ata = grub_ata_real_open (id, bus); + + if (!ata) + { + grub_errno = GRUB_ERR_NONE; + return 0; + } + if (ata->atapi) + { + grub_ata_real_close (ata); + return 0; + } + grub_snprintf (devname, sizeof (devname), + "%s%d", grub_scsi_names[id], bus); + ret = hook_in (devname); + grub_ata_real_close (ata); + return ret; + } + + grub_ata_dev_t p; + + for (p = grub_ata_dev_list; p; p = p->next) + if (p->iterate && p->iterate (hook)) + return 1; return 0; } static grub_err_t grub_ata_open (const char *name, grub_disk_t disk) { - struct grub_ata_device *dev; - grub_err_t err; + unsigned id, bus; + struct grub_ata *ata; - for (dev = grub_ata_devices; dev; dev = dev->next) - { - char devname[10]; - grub_snprintf (devname, sizeof (devname), - "ata%d", dev->port * 2 + dev->device); - if (grub_strcmp (name, devname) == 0) - break; - } + for (id = 0; id < GRUB_SCSI_NUM_SUBSYSTEMS; id++) + if (grub_strncmp (grub_scsi_names[id], name, + grub_strlen (grub_scsi_names[id])) == 0 + && grub_isdigit (name[grub_strlen (grub_scsi_names[id])])) + break; + if (id == GRUB_SCSI_NUM_SUBSYSTEMS) + return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "not an ATA harddisk"); + bus = grub_strtoul (name + grub_strlen (grub_scsi_names[id]), 0, 0); + ata = grub_ata_real_open (id, bus); + if (!ata) + return grub_errno; - if (! dev) - return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "can't open device"); - - if (dev->atapi) + if (ata->atapi) return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "not an ATA harddisk"); - err = check_device (dev); + disk->total_sectors = ata->size; - if (err) - return err; - - disk->total_sectors = dev->size; - - disk->id = (unsigned long) dev; + disk->id = grub_make_scsi_id (id, bus, 0); disk->has_partitions = 1; - disk->data = dev; + disk->data = ata; return 0; } static void -grub_ata_close (grub_disk_t disk __attribute__((unused))) +grub_ata_close (grub_disk_t disk) { - + struct grub_ata *ata = disk->data; + grub_ata_real_close (ata); } static grub_err_t @@ -767,70 +445,35 @@ static struct grub_disk_dev grub_atadisk_dev = /* ATAPI code. */ -static int -grub_atapi_iterate (int (*hook) (int bus, int luns)) -{ - struct grub_ata_device *dev; - - for (dev = grub_ata_devices; dev; dev = dev->next) - { - grub_err_t err; - - err = check_device (dev); - if (err) - { - grub_errno = GRUB_ERR_NONE; - continue; - } - - if (! dev->atapi) - continue; - - if (hook (dev->port * 2 + dev->device, 1)) - return 1; - } - - return 0; - -} - static grub_err_t -grub_atapi_read (struct grub_scsi *scsi, - grub_size_t cmdsize __attribute__((unused)), - char *cmd, grub_size_t size, char *buf) +grub_atapi_read (struct grub_scsi *scsi, grub_size_t cmdsize, char *cmd, + grub_size_t size, char *buf) { - struct grub_ata_device *dev = (struct grub_ata_device *) scsi->data; + struct grub_ata *dev = scsi->data; + struct grub_disk_ata_pass_through_parms parms; + grub_err_t err; grub_dprintf("ata", "grub_atapi_read (size=%llu)\n", (unsigned long long) size); + grub_memset (&parms, 0, sizeof (parms)); - if (grub_atapi_packet (dev, cmd, size)) - return grub_errno; + parms.taskfile.disk = 0; + parms.taskfile.features = 0; + parms.taskfile.atapi_ireason = 0; + parms.taskfile.atapi_cnthigh = size >> 8; + parms.taskfile.atapi_cntlow = size & 0xff; + parms.taskfile.cmd = GRUB_ATA_CMD_PACKET; + parms.cmd = cmd; + parms.cmdsize = cmdsize; - grub_size_t nread = 0; - while (nread < size) - { - /* Wait for !BSY, DRQ, I/O, !C/D. */ - if (grub_atapi_wait_drq (dev, GRUB_ATAPI_IREASON_DATA_IN, GRUB_ATA_TOUT_DATA)) - return grub_errno; - - /* Get byte count for this DRQ assertion. */ - unsigned cnt = grub_ata_regget (dev, GRUB_ATAPI_REG_CNTHIGH) << 8 - | grub_ata_regget (dev, GRUB_ATAPI_REG_CNTLOW); - grub_dprintf("ata", "DRQ count=%u\n", cnt); - - /* Count of last transfer may be uneven. */ - if (! (0 < cnt && cnt <= size - nread && (! (cnt & 1) || cnt == size - nread))) - return grub_error (GRUB_ERR_READ_ERROR, "invalid ATAPI transfer count"); - - /* Read the data. */ - grub_ata_pio_read (dev, buf + nread, cnt); - - if (cnt & 1) - buf[nread + cnt - 1] = (char) grub_le_to_cpu16 (grub_inw (dev->ioaddress + GRUB_ATA_REG_DATA)); - - nread += cnt; - } + parms.size = size; + parms.buffer = buf; + + err = dev->dev->readwrite (dev, &parms); + if (err) + return err; + if (parms.size != size) + return grub_error (GRUB_ERR_READ_ERROR, "incomplete ATAPI read"); return GRUB_ERR_NONE; } @@ -846,64 +489,98 @@ grub_atapi_write (struct grub_scsi *scsi __attribute__((unused)), } static grub_err_t -grub_atapi_open (int devnum, struct grub_scsi *scsi) +grub_atapi_open (int id, int bus, struct grub_scsi *scsi) { - struct grub_ata_device *dev; - struct grub_ata_device *devfnd = 0; - grub_err_t err; + struct grub_ata *ata; - for (dev = grub_ata_devices; dev; dev = dev->next) - { - if (dev->port * 2 + dev->device == devnum) - { - devfnd = dev; - break; - } - } - - grub_dprintf ("ata", "opening ATAPI dev `ata%d'\n", devnum); - - if (! devfnd) + ata = grub_ata_real_open (id, bus); + if (!ata) + return grub_errno; + + if (! ata->atapi) return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "no such ATAPI device"); - err = check_device (devfnd); - if (err) - return err; - - if (! devfnd->atapi) - return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "no such ATAPI device"); - - scsi->data = devfnd; + scsi->data = ata; return GRUB_ERR_NONE; } +static int +grub_atapi_iterate (int (*hook_in) (int id, int bus, int luns)) +{ + auto int hook (int id, int bus); + int hook (int id, int bus) + { + struct grub_ata *ata; + int ret; + + ata = grub_ata_real_open (id, bus); + + if (!ata) + { + grub_errno = GRUB_ERR_NONE; + return 0; + } + if (!ata->atapi) + { + grub_ata_real_close (ata); + return 0; + } + ret = hook_in (id, bus, 1); + grub_ata_real_close (ata); + return ret; + } + + grub_ata_dev_t p; + + for (p = grub_ata_dev_list; p; p = p->next) + if (p->iterate && p->iterate (hook)) + return 1; + return 0; +} + +static void +grub_atapi_close (grub_scsi_t disk) +{ + struct grub_ata *ata = disk->data; + grub_ata_real_close (ata); +} + + +void +grub_ata_dev_register (grub_ata_dev_t dev) +{ + dev->next = grub_ata_dev_list; + grub_ata_dev_list = dev; +} + +void +grub_ata_dev_unregister (grub_ata_dev_t dev) +{ + grub_ata_dev_t *p, q; + + for (p = &grub_ata_dev_list, q = *p; q; p = &(q->next), q = q->next) + if (q == dev) + { + *p = q->next; + break; + } +} static struct grub_scsi_dev grub_atapi_dev = { - .name = "ata", - .id = GRUB_SCSI_SUBSYSTEM_ATAPI, .iterate = grub_atapi_iterate, .open = grub_atapi_open, + .close = grub_atapi_close, .read = grub_atapi_read, - .write = grub_atapi_write + .write = grub_atapi_write, + .next = 0 }; GRUB_MOD_INIT(ata) { - /* To prevent two drivers operating on the same disks. */ - grub_disk_firmware_is_tainted = 1; - if (grub_disk_firmware_fini) - { - grub_disk_firmware_fini (); - grub_disk_firmware_fini = NULL; - } - - /* ATA initialization. */ - grub_ata_initialize (); - grub_disk_dev_register (&grub_atadisk_dev); /* ATAPI devices are handled by scsi.mod. */ diff --git a/disk/ata_pthru.c b/disk/ata_pthru.c index f52725a49..b6edf78d6 100644 --- a/disk/ata_pthru.c +++ b/disk/ata_pthru.c @@ -18,90 +18,496 @@ */ #include +#include #include #include #include +#include +#include +#include +/* At the moment, only two IDE ports are supported. */ +static const grub_port_t grub_pata_ioaddress[] = { GRUB_ATA_CH0_PORT1, + GRUB_ATA_CH1_PORT1 }; +static const grub_port_t grub_pata_ioaddress2[] = { GRUB_ATA_CH0_PORT2, + GRUB_ATA_CH1_PORT2 }; -/* ATA pass through support, used by hdparm.mod. */ -static grub_err_t -grub_ata_pass_through (grub_disk_t disk, - struct grub_disk_ata_pass_through_parms *parms) +struct grub_pata_device { - if (disk->dev->id != GRUB_DISK_DEVICE_ATA_ID) - return grub_error (GRUB_ERR_BAD_DEVICE, - "device not accessed via ata.mod"); + /* IDE port to use. */ + int port; - struct grub_ata_device *dev = (struct grub_ata_device *) disk->data; + /* IO addresses on which the registers for this device can be + found. */ + grub_port_t ioaddress; + grub_port_t ioaddress2; - if (! (parms->size == 0 || parms->size == GRUB_DISK_SECTOR_SIZE)) - return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, - "ATA multi-sector read and DATA OUT not implemented"); + /* Two devices can be connected to a single cable. Use this field + to select device 0 (commonly known as "master") or device 1 + (commonly known as "slave"). */ + int device; - grub_dprintf ("ata", "ata_pass_through: cmd=0x%x, features=0x%x, sectors=0x%x\n", - parms->taskfile[GRUB_ATA_REG_CMD], - parms->taskfile[GRUB_ATA_REG_FEATURES], - parms->taskfile[GRUB_ATA_REG_SECTORS]); - grub_dprintf ("ata", "lba_high=0x%x, lba_mid=0x%x, lba_low=0x%x, size=%d\n", - parms->taskfile[GRUB_ATA_REG_LBAHIGH], - parms->taskfile[GRUB_ATA_REG_LBAMID], - parms->taskfile[GRUB_ATA_REG_LBALOW], parms->size); + struct grub_pata_device *next; +}; - /* Set registers. */ - grub_ata_regset (dev, GRUB_ATA_REG_DISK, 0xE0 | dev->device << 4 - | (parms->taskfile[GRUB_ATA_REG_DISK] & 0xf)); - if (grub_ata_check_ready (dev)) - return grub_errno; +static struct grub_pata_device *grub_pata_devices; - int i; - for (i = GRUB_ATA_REG_FEATURES; i <= GRUB_ATA_REG_LBAHIGH; i++) - grub_ata_regset (dev, i, parms->taskfile[i]); +static inline void +grub_pata_regset (struct grub_pata_device *dev, int reg, int val) +{ + grub_outb (val, dev->ioaddress + reg); +} - /* Start command. */ - grub_ata_regset (dev, GRUB_ATA_REG_CMD, parms->taskfile[GRUB_ATA_REG_CMD]); +static inline grub_uint8_t +grub_pata_regget (struct grub_pata_device *dev, int reg) +{ + return grub_inb (dev->ioaddress + reg); +} - /* Wait for !BSY. */ - if (grub_ata_wait_not_busy (dev, GRUB_ATA_TOUT_DATA)) - return grub_errno; +static inline void +grub_pata_regset2 (struct grub_pata_device *dev, int reg, int val) +{ + grub_outb (val, dev->ioaddress2 + reg); +} - /* Check status. */ - grub_int8_t sts = grub_ata_regget (dev, GRUB_ATA_REG_STATUS); - grub_dprintf ("ata", "status=0x%x\n", sts); +static inline grub_uint8_t +grub_pata_regget2 (struct grub_pata_device *dev, int reg) +{ + return grub_inb (dev->ioaddress2 + reg); +} - /* Transfer data. */ - if ((sts & (GRUB_ATA_STATUS_DRQ | GRUB_ATA_STATUS_ERR)) == GRUB_ATA_STATUS_DRQ) +/* Wait for !BSY. */ +static grub_err_t +grub_pata_wait_not_busy (struct grub_pata_device *dev, int milliseconds) +{ + /* ATA requires 400ns (after a write to CMD register) or + 1 PIO cycle (after a DRQ block transfer) before + first check of BSY. */ + grub_millisleep (1); + + int i = 1; + grub_uint8_t sts; + while ((sts = grub_pata_regget (dev, GRUB_ATA_REG_STATUS)) + & GRUB_ATA_STATUS_BUSY) { - if (parms->size != GRUB_DISK_SECTOR_SIZE) - return grub_error (GRUB_ERR_READ_ERROR, "DRQ unexpected"); - grub_ata_pio_read (dev, parms->buffer, GRUB_DISK_SECTOR_SIZE); + if (i >= milliseconds) + { + grub_dprintf ("pata", "timeout: %dms, status=0x%x\n", + milliseconds, sts); + return grub_error (GRUB_ERR_TIMEOUT, "PATA timeout"); + } + + grub_millisleep (1); + i++; } - /* Return registers. */ - for (i = GRUB_ATA_REG_ERROR; i <= GRUB_ATA_REG_STATUS; i++) - parms->taskfile[i] = grub_ata_regget (dev, i); - - grub_dprintf ("ata", "status=0x%x, error=0x%x, sectors=0x%x\n", - parms->taskfile[GRUB_ATA_REG_STATUS], - parms->taskfile[GRUB_ATA_REG_ERROR], - parms->taskfile[GRUB_ATA_REG_SECTORS]); - - if (parms->taskfile[GRUB_ATA_REG_STATUS] - & (GRUB_ATA_STATUS_DRQ | GRUB_ATA_STATUS_ERR)) - return grub_error (GRUB_ERR_READ_ERROR, "ATA passthrough failed"); - return GRUB_ERR_NONE; } +static inline grub_err_t +grub_pata_check_ready (struct grub_pata_device *dev) +{ + if (grub_pata_regget (dev, GRUB_ATA_REG_STATUS) & GRUB_ATA_STATUS_BUSY) + return grub_pata_wait_not_busy (dev, GRUB_ATA_TOUT_STD); + + return GRUB_ERR_NONE; +} + +static inline void +grub_pata_wait (void) +{ + grub_millisleep (50); +} + +static void +grub_pata_pio_read (struct grub_pata_device *dev, char *buf, grub_size_t size) +{ + grub_uint16_t *buf16 = (grub_uint16_t *) buf; + unsigned int i; + + /* Read in the data, word by word. */ + for (i = 0; i < size / 2; i++) + buf16[i] = grub_le_to_cpu16 (grub_inw(dev->ioaddress + GRUB_ATA_REG_DATA)); + if (size & 1) + buf[size - 1] = (char) grub_le_to_cpu16 (grub_inw (dev->ioaddress + + GRUB_ATA_REG_DATA)); +} + +static void +grub_pata_pio_write (struct grub_pata_device *dev, char *buf, grub_size_t size) +{ + grub_uint16_t *buf16 = (grub_uint16_t *) buf; + unsigned int i; + + /* Write the data, word by word. */ + for (i = 0; i < size / 2; i++) + grub_outw(grub_cpu_to_le16 (buf16[i]), dev->ioaddress + GRUB_ATA_REG_DATA); +} + +/* ATA pass through support, used by hdparm.mod. */ +static grub_err_t +grub_pata_readwrite (struct grub_ata *disk, + struct grub_disk_ata_pass_through_parms *parms) +{ + struct grub_pata_device *dev = (struct grub_pata_device *) disk->data; + grub_size_t nread = 0; + + if (! (parms->cmdsize == 0 || parms->cmdsize == 12)) + return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, + "ATAPI non-12 byte commands not supported"); + + grub_dprintf ("pata", "pata_pass_through: cmd=0x%x, features=0x%x, sectors=0x%x\n", + parms->taskfile.cmd, + parms->taskfile.features, + parms->taskfile.sectors); + grub_dprintf ("pata", "lba_high=0x%x, lba_mid=0x%x, lba_low=0x%x, size=%d\n", + parms->taskfile.lba_high, + parms->taskfile.lba_mid, + parms->taskfile.lba_low, parms->size); + + /* Set registers. */ + grub_pata_regset (dev, GRUB_ATA_REG_DISK, (parms->cmdsize ? 0 : 0xE0) + | dev->device << 4 + | (parms->taskfile.disk & 0xf)); + if (grub_pata_check_ready (dev)) + return grub_errno; + + int i; + for (i = GRUB_ATA_REG_SECTORS; i <= GRUB_ATA_REG_LBAHIGH; i++) + grub_pata_regset (dev, i, + parms->taskfile.raw[7 + (i - GRUB_ATA_REG_SECTORS)]); + for (i = GRUB_ATA_REG_FEATURES; i <= GRUB_ATA_REG_LBAHIGH; i++) + grub_pata_regset (dev, i, parms->taskfile.raw[i - GRUB_ATA_REG_FEATURES]); + + /* Start command. */ + grub_pata_regset (dev, GRUB_ATA_REG_CMD, parms->taskfile.cmd); + + /* Wait for !BSY. */ + if (grub_pata_wait_not_busy (dev, GRUB_ATA_TOUT_DATA)) + return grub_errno; + + /* Check status. */ + grub_int8_t sts = grub_pata_regget (dev, GRUB_ATA_REG_STATUS); + grub_dprintf ("pata", "status=0x%x\n", sts); + + if (parms->cmdsize) + { + grub_uint8_t irs = grub_pata_regget (dev, GRUB_ATAPI_REG_IREASON); + /* OK if DRQ is asserted and interrupt reason is as expected. */ + if (!((sts & GRUB_ATA_STATUS_DRQ) + && (irs & GRUB_ATAPI_IREASON_MASK) == GRUB_ATAPI_IREASON_CMD_OUT)) + return grub_error (GRUB_ERR_READ_ERROR, "ATAPI protocol error"); + /* Write the packet. */ + grub_pata_pio_write (dev, parms->cmd, parms->cmdsize); + } + + /* Transfer data. */ + while (nread < parms->size + && ((sts & (GRUB_ATA_STATUS_DRQ | GRUB_ATA_STATUS_ERR)) + == GRUB_ATA_STATUS_DRQ) + && (!parms->cmdsize + || ((grub_pata_regget (dev, GRUB_ATAPI_REG_IREASON) + & GRUB_ATAPI_IREASON_MASK) == GRUB_ATAPI_IREASON_DATA_IN))) + { + unsigned cnt; + if (parms->cmdsize) + { + cnt = grub_pata_regget (dev, GRUB_ATAPI_REG_CNTHIGH) << 8 + | grub_pata_regget (dev, GRUB_ATAPI_REG_CNTLOW); + grub_dprintf("pata", "DRQ count=%u\n", cnt); + + /* Count of last transfer may be uneven. */ + if (! (0 < cnt && cnt <= parms->size - nread + && (! (cnt & 1) || cnt == parms->size - nread))) + return grub_error (GRUB_ERR_READ_ERROR, + "invalid ATAPI transfer count"); + } + else + cnt = GRUB_DISK_SECTOR_SIZE; + if (cnt > parms->size - nread) + cnt = parms->size - nread; + + if (parms->write) + grub_pata_pio_write (dev, (char *) parms->buffer + nread, cnt); + else + grub_pata_pio_read (dev, (char *) parms->buffer + nread, cnt); + + nread += cnt; + } + if (parms->write) + { + /* Check for write error. */ + if (grub_pata_wait_not_busy (dev, GRUB_ATA_TOUT_DATA)) + return grub_errno; + + if (grub_pata_regget (dev, GRUB_ATA_REG_STATUS) + & (GRUB_ATA_STATUS_DRQ | GRUB_ATA_STATUS_ERR)) + return grub_error (GRUB_ERR_WRITE_ERROR, "ATA write error"); + } + parms->size = nread; + + /* Return registers. */ + for (i = GRUB_ATA_REG_ERROR; i <= GRUB_ATA_REG_STATUS; i++) + parms->taskfile.raw[i - GRUB_ATA_REG_FEATURES] = grub_pata_regget (dev, i); + + grub_dprintf ("pata", "status=0x%x, error=0x%x, sectors=0x%x\n", + parms->taskfile.status, + parms->taskfile.error, + parms->taskfile.sectors); + + if (parms->taskfile.status + & (GRUB_ATA_STATUS_DRQ | GRUB_ATA_STATUS_ERR)) + return grub_error (GRUB_ERR_READ_ERROR, "PATA passthrough failed"); + + return GRUB_ERR_NONE; +} + +static grub_err_t +check_device (struct grub_pata_device *dev) +{ + grub_pata_regset (dev, GRUB_ATA_REG_DISK, dev->device << 4); + grub_pata_wait (); + + /* Try to detect if the port is in use by writing to it, + waiting for a while and reading it again. If the value + was preserved, there is a device connected. */ + grub_pata_regset (dev, GRUB_ATA_REG_SECTORS, 0x5A); + grub_pata_wait (); + grub_uint8_t sec = grub_pata_regget (dev, GRUB_ATA_REG_SECTORS); + grub_dprintf ("ata", "sectors=0x%x\n", sec); + if (sec != 0x5A) + return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "no device connected"); + + /* The above test may detect a second (slave) device + connected to a SATA controller which supports only one + (master) device. It is not safe to use the status register + READY bit to check for controller channel existence. Some + ATAPI commands (RESET, DIAGNOSTIC) may clear this bit. */ + + return GRUB_ERR_NONE; +} + +static grub_err_t +grub_pata_device_initialize (int port, int device, int addr, int addr2) +{ + struct grub_pata_device *dev; + struct grub_pata_device **devp; + grub_err_t err; + + grub_dprintf ("pata", "detecting device %d,%d (0x%x, 0x%x)\n", + port, device, addr, addr2); + + dev = grub_malloc (sizeof(*dev)); + if (! dev) + return grub_errno; + + /* Setup the device information. */ + dev->port = port; + dev->device = device; + dev->ioaddress = addr + GRUB_MACHINE_PCI_IO_BASE; + dev->ioaddress2 = addr2 + GRUB_MACHINE_PCI_IO_BASE; + dev->next = NULL; + + /* Register the device. */ + for (devp = &grub_pata_devices; *devp; devp = &(*devp)->next); + *devp = dev; + + err = check_device (dev); + if (err) + grub_print_error (); + + return 0; +} + +static int NESTED_FUNC_ATTR +grub_pata_pciinit (grub_pci_device_t dev, + grub_pci_id_t pciid) +{ + static int compat_use[2] = { 0 }; + grub_pci_address_t addr; + grub_uint32_t class; + grub_uint32_t bar1; + grub_uint32_t bar2; + int rega; + int regb; + int i; + static int controller = 0; + int cs5536 = 0; + int nports = 2; + + /* Read class. */ + addr = grub_pci_make_address (dev, GRUB_PCI_REG_CLASS); + class = grub_pci_read (addr); + + /* AMD CS5536 Southbridge. */ + if (pciid == GRUB_CS5536_PCIID) + { + cs5536 = 1; + nports = 1; + } + + /* Check if this class ID matches that of a PCI IDE Controller. */ + if (!cs5536 && (class >> 16 != 0x0101)) + return 0; + + for (i = 0; i < nports; i++) + { + /* Set to 0 when the channel operated in compatibility mode. */ + int compat; + + /* We don't support non-compatibility mode for CS5536. */ + if (cs5536) + compat = 0; + else + compat = (class >> (8 + 2 * i)) & 1; + + rega = 0; + regb = 0; + + /* If the channel is in compatibility mode, just assign the + default registers. */ + if (compat == 0 && !compat_use[i]) + { + rega = grub_pata_ioaddress[i]; + regb = grub_pata_ioaddress2[i]; + compat_use[i] = 1; + } + else if (compat) + { + /* Read the BARs, which either contain a mmapped IO address + or the IO port address. */ + addr = grub_pci_make_address (dev, GRUB_PCI_REG_ADDRESSES + + sizeof (grub_uint64_t) * i); + bar1 = grub_pci_read (addr); + addr = grub_pci_make_address (dev, GRUB_PCI_REG_ADDRESSES + + sizeof (grub_uint64_t) * i + + sizeof (grub_uint32_t)); + bar2 = grub_pci_read (addr); + + /* Check if the BARs describe an IO region. */ + if ((bar1 & 1) && (bar2 & 1)) + { + rega = bar1 & ~3; + regb = bar2 & ~3; + } + } + + grub_dprintf ("pata", + "PCI dev (%d,%d,%d) compat=%d rega=0x%x regb=0x%x\n", + grub_pci_get_bus (dev), grub_pci_get_device (dev), + grub_pci_get_function (dev), compat, rega, regb); + + if (rega && regb) + { + grub_errno = GRUB_ERR_NONE; + grub_pata_device_initialize (controller * 2 + i, 0, rega, regb); + + /* Most errors raised by grub_ata_device_initialize() are harmless. + They just indicate this particular drive is not responding, most + likely because it doesn't exist. We might want to ignore specific + error types here, instead of printing them. */ + if (grub_errno) + { + grub_print_error (); + grub_errno = GRUB_ERR_NONE; + } + + grub_pata_device_initialize (controller * 2 + i, 1, rega, regb); + + /* Likewise. */ + if (grub_errno) + { + grub_print_error (); + grub_errno = GRUB_ERR_NONE; + } + } + } + + controller++; + + return 0; +} + +static grub_err_t +grub_pata_initialize (void) +{ + grub_pci_iterate (grub_pata_pciinit); + return 0; +} + +static grub_err_t +grub_pata_open (int id, int devnum, struct grub_ata *ata) +{ + struct grub_pata_device *dev; + struct grub_pata_device *devfnd = 0; + grub_err_t err; + + if (id != GRUB_SCSI_SUBSYSTEM_PATA) + return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "not a PATA device"); + + for (dev = grub_pata_devices; dev; dev = dev->next) + { + if (dev->port * 2 + dev->device == devnum) + { + devfnd = dev; + break; + } + } + + grub_dprintf ("pata", "opening PATA dev `ata%d'\n", devnum); + + if (! devfnd) + return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "no such PATA device"); + + err = check_device (devfnd); + if (err) + return err; + + ata->data = devfnd; + + return GRUB_ERR_NONE; +} + +static int +grub_pata_iterate (int (*hook) (int id, int bus)) +{ + struct grub_pata_device *dev; + + for (dev = grub_pata_devices; dev; dev = dev->next) + if (hook (GRUB_SCSI_SUBSYSTEM_PATA, dev->port * 2 + dev->device)) + return 1; + + return 0; +} + + +static struct grub_ata_dev grub_pata_dev = + { + .iterate = grub_pata_iterate, + .open = grub_pata_open, + .readwrite = grub_pata_readwrite, + }; + + GRUB_MOD_INIT(ata_pthru) { - /* Register ATA pass through function. */ - grub_disk_ata_pass_through = grub_ata_pass_through; + /* To prevent two drivers operating on the same disks. */ + grub_disk_firmware_is_tainted = 1; + if (grub_disk_firmware_fini) + { + grub_disk_firmware_fini (); + grub_disk_firmware_fini = NULL; + } + + /* ATA initialization. */ + grub_pata_initialize (); + + grub_ata_dev_register (&grub_pata_dev); } GRUB_MOD_FINI(ata_pthru) { - if (grub_disk_ata_pass_through == grub_ata_pass_through) - grub_disk_ata_pass_through = NULL; + grub_ata_dev_unregister (&grub_pata_dev); } diff --git a/disk/scsi.c b/disk/scsi.c index 60192bef5..f0594e7c7 100644 --- a/disk/scsi.c +++ b/disk/scsi.c @@ -30,6 +30,12 @@ static grub_scsi_dev_t grub_scsi_dev_list; +char grub_scsi_names[GRUB_SCSI_NUM_SUBSYSTEMS][5] = { + [GRUB_SCSI_SUBSYSTEM_USBMS] = "usb", + [GRUB_SCSI_SUBSYSTEM_PATA] = "ata", + [GRUB_SCSI_SUBSYSTEM_AHCI] = "ahci" +}; + void grub_scsi_dev_register (grub_scsi_dev_t dev) { @@ -318,9 +324,9 @@ grub_scsi_iterate (int (*hook) (const char *name)) { grub_scsi_dev_t p; - auto int scsi_iterate (int bus, int luns); + auto int scsi_iterate (int id, int bus, int luns); - int scsi_iterate (int bus, int luns) + int scsi_iterate (int id, int bus, int luns) { int i; @@ -329,7 +335,7 @@ grub_scsi_iterate (int (*hook) (const char *name)) { char *sname; int ret; - sname = grub_xasprintf ("%s%d", p->name, bus); + sname = grub_xasprintf ("%s%d", grub_scsi_names[id], bus); if (!sname) return 1; ret = hook (sname); @@ -343,7 +349,7 @@ grub_scsi_iterate (int (*hook) (const char *name)) { char *sname; int ret; - sname = grub_xasprintf ("%s%d%c", p->name, bus, 'a' + i); + sname = grub_xasprintf ("%s%d%c", grub_scsi_names[id], bus, 'a' + i); if (!sname) return 1; ret = hook (sname); @@ -370,6 +376,7 @@ grub_scsi_open (const char *name, grub_disk_t disk) int lun, bus; grub_uint64_t maxtime; const char *nameend; + unsigned id; nameend = name + grub_strlen (name) - 1; /* Try to detect a LUN ('a'-'z'), otherwise just use the first @@ -394,15 +401,25 @@ grub_scsi_open (const char *name, grub_disk_t disk) if (! scsi) return grub_errno; + for (id = 0; id < ARRAY_SIZE (grub_scsi_names); id++) + if (grub_strncmp (grub_scsi_names[id], name, nameend - name) == 0) + break; + + if (id == ARRAY_SIZE (grub_scsi_names)) + { + grub_free (scsi); + return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "not a SCSI disk"); + } + for (p = grub_scsi_dev_list; p; p = p->next) { - if (grub_strncmp (p->name, name, nameend - name) != 0) - continue; + if (p->open (id, bus, scsi)) + { + grub_errno = GRUB_ERR_NONE; + continue; + } - if (p->open (bus, scsi)) - continue; - - disk->id = grub_make_scsi_id (p->id, bus, lun); + disk->id = grub_make_scsi_id (id, bus, lun); disk->data = scsi; scsi->dev = p; scsi->lun = lun; @@ -484,7 +501,6 @@ grub_scsi_open (const char *name, grub_disk_t disk) } grub_free (scsi); - return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "not a SCSI disk"); } diff --git a/disk/usbms.c b/disk/usbms.c index 225761e0f..0ff2e6235 100644 --- a/disk/usbms.c +++ b/disk/usbms.c @@ -205,7 +205,7 @@ grub_usbms_attach (grub_usb_device_t usbdev, int configno, int interfno) static int -grub_usbms_iterate (int (*hook) (int bus, int luns)) +grub_usbms_iterate (int (*hook) (int id, int bus, int luns)) { unsigned i; @@ -214,7 +214,7 @@ grub_usbms_iterate (int (*hook) (int bus, int luns)) for (i = 0; i < ARRAY_SIZE (grub_usbms_devices); i++) if (grub_usbms_devices[i]) { - if (hook (i, grub_usbms_devices[i]->luns)) + if (hook (GRUB_SCSI_SUBSYSTEM_USBMS, i, grub_usbms_devices[i]->luns)) return 1; } @@ -384,8 +384,12 @@ grub_usbms_write (struct grub_scsi *scsi, grub_size_t cmdsize, char *cmd, } static grub_err_t -grub_usbms_open (int devnum, struct grub_scsi *scsi) +grub_usbms_open (int id, int devnum, struct grub_scsi *scsi) { + if (id != GRUB_SCSI_SUBSYSTEM_USBMS) + return grub_error (GRUB_ERR_UNKNOWN_DEVICE, + "not USB Mass Storage device"); + grub_usb_poll_devices (); if (!grub_usbms_devices[devnum]) @@ -400,8 +404,6 @@ grub_usbms_open (int devnum, struct grub_scsi *scsi) static struct grub_scsi_dev grub_usbms_dev = { - .name = "usb", - .id = GRUB_SCSI_SUBSYSTEM_USBMS, .iterate = grub_usbms_iterate, .open = grub_usbms_open, .read = grub_usbms_read, diff --git a/include/grub/ata.h b/include/grub/ata.h index 9e3aaf0e6..b1c6ead26 100644 --- a/include/grub/ata.h +++ b/include/grub/ata.h @@ -97,21 +97,64 @@ enum grub_ata_timeout_milliseconds GRUB_ATA_TOUT_DATA = 10000 /* 10s DATA I/O timeout. */ }; -struct grub_ata_device +typedef union { - /* IDE port to use. */ - int port; + grub_uint8_t raw[11]; + struct + { + union + { + grub_uint8_t features; + grub_uint8_t error; + }; + union + { + grub_uint8_t sectors; + grub_uint8_t atapi_ireason; + }; + union + { + grub_uint8_t lba_low; + grub_uint8_t sectnum; + }; + union + { + grub_uint8_t lba_mid; + grub_uint8_t cyllsb; + grub_uint8_t atapi_cntlow; + }; + union + { + grub_uint8_t lba_high; + grub_uint8_t cylmsb; + grub_uint8_t atapi_cnthigh; + }; + grub_uint8_t disk; + union + { + grub_uint8_t cmd; + grub_uint8_t status; + }; + grub_uint8_t sectors48; + grub_uint8_t lba48_low; + grub_uint8_t lba48_mid; + grub_uint8_t lba48_high; + }; +} grub_ata_regs_t; - /* IO addresses on which the registers for this device can be - found. */ - grub_port_t ioaddress; - grub_port_t ioaddress2; - - /* Two devices can be connected to a single cable. Use this field - to select device 0 (commonly known as "master") or device 1 - (commonly known as "slave"). */ - int device; +/* ATA pass through parameters and function. */ +struct grub_disk_ata_pass_through_parms +{ + grub_ata_regs_t taskfile; + void * buffer; + grub_size_t size; + int write; + void *cmd; + int cmdsize; +}; +struct grub_ata +{ /* Addressing methods available for accessing this device. If CHS is only available, use that. Otherwise use LBA, except for the high sectors. In that case use LBA48. */ @@ -128,47 +171,36 @@ struct grub_ata_device /* Set to 0 for ATA, set to 1 for ATAPI. */ int atapi; - struct grub_ata_device *next; + void *data; + + struct grub_ata_dev *dev; }; -grub_err_t EXPORT_FUNC(grub_ata_wait_not_busy) (struct grub_ata_device *dev, - int milliseconds); -grub_err_t EXPORT_FUNC(grub_ata_wait_drq) (struct grub_ata_device *dev, - int rw, int milliseconds); -void EXPORT_FUNC(grub_ata_pio_read) (struct grub_ata_device *dev, - char *buf, grub_size_t size); +typedef struct grub_ata *grub_ata_t; -static inline void -grub_ata_regset (struct grub_ata_device *dev, int reg, int val) +struct grub_ata_dev { - grub_outb (val, dev->ioaddress + reg); -} + /* Call HOOK with each device name, until HOOK returns non-zero. */ + int (*iterate) (int (*hook) (int id, int bus)); -static inline grub_uint8_t -grub_ata_regget (struct grub_ata_device *dev, int reg) -{ - return grub_inb (dev->ioaddress + reg); -} + /* Open the device named NAME, and set up SCSI. */ + grub_err_t (*open) (int id, int bus, struct grub_ata *scsi); -static inline void -grub_ata_regset2 (struct grub_ata_device *dev, int reg, int val) -{ - grub_outb (val, dev->ioaddress2 + reg); -} + /* Close the scsi device SCSI. */ + void (*close) (struct grub_ata *ata); -static inline grub_uint8_t -grub_ata_regget2 (struct grub_ata_device *dev, int reg) -{ - return grub_inb (dev->ioaddress2 + reg); -} + /* Read SIZE bytes from the device SCSI into BUF after sending the + command CMD of size CMDSIZE. */ + grub_err_t (*readwrite) (struct grub_ata *ata, + struct grub_disk_ata_pass_through_parms *parms); -static inline grub_err_t -grub_ata_check_ready (struct grub_ata_device *dev) -{ - if (grub_ata_regget (dev, GRUB_ATA_REG_STATUS) & GRUB_ATA_STATUS_BUSY) - return grub_ata_wait_not_busy (dev, GRUB_ATA_TOUT_STD); + /* The next scsi device. */ + struct grub_ata_dev *next; +}; - return GRUB_ERR_NONE; -} +typedef struct grub_ata_dev *grub_ata_dev_t; + +void grub_ata_dev_register (grub_ata_dev_t dev); +void grub_ata_dev_unregister (grub_ata_dev_t dev); #endif /* ! GRUB_ATA_HEADER */ diff --git a/include/grub/disk.h b/include/grub/disk.h index e7f807e0e..ac3fb6497 100644 --- a/include/grub/disk.h +++ b/include/grub/disk.h @@ -165,16 +165,5 @@ grub_uint64_t EXPORT_FUNC(grub_disk_get_size) (grub_disk_t disk); extern void (* EXPORT_VAR(grub_disk_firmware_fini)) (void); extern int EXPORT_VAR(grub_disk_firmware_is_tainted); - -/* ATA pass through parameters and function. */ -struct grub_disk_ata_pass_through_parms -{ - grub_uint8_t taskfile[8]; - void * buffer; - int size; -}; - -extern grub_err_t (* EXPORT_VAR(grub_disk_ata_pass_through)) (grub_disk_t, - struct grub_disk_ata_pass_through_parms *); - + #endif /* ! GRUB_DISK_HEADER */ diff --git a/include/grub/scsi.h b/include/grub/scsi.h index 289cd8e4a..081189fb0 100644 --- a/include/grub/scsi.h +++ b/include/grub/scsi.h @@ -29,10 +29,13 @@ struct grub_scsi; enum { GRUB_SCSI_SUBSYSTEM_USBMS, - GRUB_SCSI_SUBSYSTEM_ATAPI, - GRUB_SCSI_SUBSYSTEM_AHCI + GRUB_SCSI_SUBSYSTEM_PATA, + GRUB_SCSI_SUBSYSTEM_AHCI, + GRUB_SCSI_NUM_SUBSYSTEMS }; +extern char grub_scsi_names[GRUB_SCSI_NUM_SUBSYSTEMS][5]; + #define GRUB_SCSI_ID_SUBSYSTEM_SHIFT 24 #define GRUB_SCSI_ID_BUS_SHIFT 8 #define GRUB_SCSI_ID_LUN_SHIFT 0 @@ -46,16 +49,11 @@ grub_make_scsi_id (int subsystem, int bus, int lun) struct grub_scsi_dev { - /* The device name. */ - const char *name; - - grub_uint8_t id; - /* Call HOOK with each device name, until HOOK returns non-zero. */ - int (*iterate) (int (*hook) (int bus, int luns)); + int (*iterate) (int (*hook) (int id, int bus, int luns)); /* Open the device named NAME, and set up SCSI. */ - grub_err_t (*open) (int bus, struct grub_scsi *scsi); + grub_err_t (*open) (int id, int bus, struct grub_scsi *scsi); /* Close the scsi device SCSI. */ void (*close) (struct grub_scsi *scsi); diff --git a/kern/disk.c b/kern/disk.c index ccd5f200f..84c48e65c 100644 --- a/kern/disk.c +++ b/kern/disk.c @@ -46,10 +46,6 @@ static struct grub_disk_cache grub_disk_cache_table[GRUB_DISK_CACHE_NUM]; void (*grub_disk_firmware_fini) (void); int grub_disk_firmware_is_tainted; -grub_err_t (* grub_disk_ata_pass_through) (grub_disk_t, - struct grub_disk_ata_pass_through_parms *); - - #if 0 static unsigned long grub_disk_cache_hits; static unsigned long grub_disk_cache_misses; From faec81d97dd6b3cb58b631f4fcf426786f1db54f Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 24 Dec 2010 16:54:33 +0100 Subject: [PATCH 140/869] Add missing buffer specifications --- grub-core/disk/ata.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/grub-core/disk/ata.c b/grub-core/disk/ata.c index 04b81cd27..9f62546e1 100644 --- a/grub-core/disk/ata.c +++ b/grub-core/disk/ata.c @@ -72,6 +72,8 @@ grub_atapi_identify (struct grub_ata *dev) grub_memset (&parms, 0, sizeof (parms)); parms.taskfile.disk = 0; parms.taskfile.cmd = GRUB_ATA_CMD_IDENTIFY_PACKET_DEVICE; + parms.size = GRUB_DISK_SECTOR_SIZE; + parms.buffer = info; err = dev->dev->readwrite (dev, &parms); if (err) @@ -105,6 +107,7 @@ grub_ata_identify (struct grub_ata *dev) info16 = (grub_uint16_t *) info; grub_memset (&parms, 0, sizeof (parms)); parms.buffer = info; + parms.size = GRUB_DISK_SECTOR_SIZE; parms.taskfile.disk = 0; parms.taskfile.cmd = GRUB_ATA_CMD_IDENTIFY_DEVICE; From 22a7cc9a6f5e61de79b34f09c97a71a12dd370a2 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 24 Dec 2010 17:09:56 +0100 Subject: [PATCH 141/869] fix 3rd argument to scsi_iterate --- grub-core/disk/ata.c | 2 +- grub-core/disk/scsi.c | 4 ++-- grub-core/disk/usbms.c | 2 +- include/grub/scsi.h | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/grub-core/disk/ata.c b/grub-core/disk/ata.c index 9f62546e1..6f7f44227 100644 --- a/grub-core/disk/ata.c +++ b/grub-core/disk/ata.c @@ -508,7 +508,7 @@ grub_atapi_open (int id, int bus, struct grub_scsi *scsi) } static int -grub_atapi_iterate (int (*hook_in) (int id, int bus, int luns)) +grub_atapi_iterate (int NESTED_FUNC_ATTR (*hook_in) (int id, int bus, int luns)) { auto int hook (int id, int bus); int hook (int id, int bus) diff --git a/grub-core/disk/scsi.c b/grub-core/disk/scsi.c index b989a98ad..015e5dce6 100644 --- a/grub-core/disk/scsi.c +++ b/grub-core/disk/scsi.c @@ -324,9 +324,9 @@ grub_scsi_iterate (int (*hook) (const char *name)) { grub_scsi_dev_t p; - auto int scsi_iterate (int id, int bus, int luns); + auto int NESTED_FUNC_ATTR scsi_iterate (int id, int bus, int luns); - int scsi_iterate (int id, int bus, int luns) + int NESTED_FUNC_ATTR scsi_iterate (int id, int bus, int luns) { int i; diff --git a/grub-core/disk/usbms.c b/grub-core/disk/usbms.c index 4e1af7be3..8041c6c95 100644 --- a/grub-core/disk/usbms.c +++ b/grub-core/disk/usbms.c @@ -205,7 +205,7 @@ grub_usbms_attach (grub_usb_device_t usbdev, int configno, int interfno) static int -grub_usbms_iterate (int (*hook) (int id, int bus, int luns)) +grub_usbms_iterate (int NESTED_FUNC_ATTR (*hook) (int id, int bus, int luns)) { unsigned i; diff --git a/include/grub/scsi.h b/include/grub/scsi.h index 3deb18f1b..5b6ccc9f4 100644 --- a/include/grub/scsi.h +++ b/include/grub/scsi.h @@ -50,7 +50,7 @@ grub_make_scsi_id (int subsystem, int bus, int lun) struct grub_scsi_dev { /* Call HOOK with each device name, until HOOK returns non-zero. */ - int (*iterate) (int (*hook) (int id, int bus, int luns)); + int (*iterate) (int NESTED_FUNC_ATTR (*hook) (int id, int bus, int luns)); /* Open the device named NAME, and set up SCSI. */ grub_err_t (*open) (int id, int bus, struct grub_scsi *scsi); From 8f5ac9e57050652378a9d54d9082ab331a775946 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 24 Dec 2010 17:10:41 +0100 Subject: [PATCH 142/869] fix ATAPI support --- grub-core/disk/ata.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/grub-core/disk/ata.c b/grub-core/disk/ata.c index 6f7f44227..5015f8507 100644 --- a/grub-core/disk/ata.c +++ b/grub-core/disk/ata.c @@ -113,13 +113,12 @@ grub_ata_identify (struct grub_ata *dev) parms.taskfile.cmd = GRUB_ATA_CMD_IDENTIFY_DEVICE; err = dev->dev->readwrite (dev, &parms); - if (err) - return err; - if (parms.size != GRUB_DISK_SECTOR_SIZE) + if (err || parms.size != GRUB_DISK_SECTOR_SIZE) { grub_uint8_t sts = parms.taskfile.status; grub_free (info); + grub_errno = GRUB_ERR_NONE; if ((sts & (GRUB_ATA_STATUS_BUSY | GRUB_ATA_STATUS_DRQ | GRUB_ATA_STATUS_ERR)) == GRUB_ATA_STATUS_ERR && (parms.taskfile.error & 0x04 /* ABRT */)) @@ -503,6 +502,7 @@ grub_atapi_open (int id, int bus, struct grub_scsi *scsi) return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "no such ATAPI device"); scsi->data = ata; + scsi->luns = 1; return GRUB_ERR_NONE; } From ee2b985ef68f5522796057ef6d3055ad7d6dc5a1 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 24 Dec 2010 17:11:21 +0100 Subject: [PATCH 143/869] rearrange wait_not_busy --- grub-core/disk/pata.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/grub-core/disk/pata.c b/grub-core/disk/pata.c index b6edf78d6..a24237a83 100644 --- a/grub-core/disk/pata.c +++ b/grub-core/disk/pata.c @@ -182,17 +182,18 @@ grub_pata_readwrite (struct grub_ata *disk, /* Start command. */ grub_pata_regset (dev, GRUB_ATA_REG_CMD, parms->taskfile.cmd); - /* Wait for !BSY. */ - if (grub_pata_wait_not_busy (dev, GRUB_ATA_TOUT_DATA)) - return grub_errno; - /* Check status. */ grub_int8_t sts = grub_pata_regget (dev, GRUB_ATA_REG_STATUS); grub_dprintf ("pata", "status=0x%x\n", sts); if (parms->cmdsize) { - grub_uint8_t irs = grub_pata_regget (dev, GRUB_ATAPI_REG_IREASON); + grub_uint8_t irs; + /* Wait for !BSY. */ + if (grub_pata_wait_not_busy (dev, GRUB_ATA_TOUT_DATA)) + return grub_errno; + + irs = grub_pata_regget (dev, GRUB_ATAPI_REG_IREASON); /* OK if DRQ is asserted and interrupt reason is as expected. */ if (!((sts & GRUB_ATA_STATUS_DRQ) && (irs & GRUB_ATAPI_IREASON_MASK) == GRUB_ATAPI_IREASON_CMD_OUT)) @@ -210,6 +211,11 @@ grub_pata_readwrite (struct grub_ata *disk, & GRUB_ATAPI_IREASON_MASK) == GRUB_ATAPI_IREASON_DATA_IN))) { unsigned cnt; + + /* Wait for !BSY. */ + if (grub_pata_wait_not_busy (dev, GRUB_ATA_TOUT_DATA)) + return grub_errno; + if (parms->cmdsize) { cnt = grub_pata_regget (dev, GRUB_ATAPI_REG_CNTHIGH) << 8 @@ -246,6 +252,10 @@ grub_pata_readwrite (struct grub_ata *disk, } parms->size = nread; + /* Wait for !BSY. */ + if (grub_pata_wait_not_busy (dev, GRUB_ATA_TOUT_DATA)) + return grub_errno; + /* Return registers. */ for (i = GRUB_ATA_REG_ERROR; i <= GRUB_ATA_REG_STATUS; i++) parms->taskfile.raw[i - GRUB_ATA_REG_FEATURES] = grub_pata_regget (dev, i); From 908a8fc37a51aea0dd22d53494772456a210b900 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 24 Dec 2010 19:48:55 +0100 Subject: [PATCH 144/869] Fix several AHCI problems --- grub-core/disk/ahci.c | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/grub-core/disk/ahci.c b/grub-core/disk/ahci.c index 946db82e1..1e28b3dc5 100644 --- a/grub-core/disk/ahci.c +++ b/grub-core/disk/ahci.c @@ -56,10 +56,12 @@ struct grub_ahci_hba_port grub_uint32_t intstatus; grub_uint32_t inten; grub_uint32_t command; - grub_uint32_t unused1[6]; + grub_uint32_t unused1[3]; + grub_uint32_t status; + grub_uint32_t unused2[2]; grub_uint32_t sata_active; grub_uint32_t command_issue; - grub_uint32_t unused2[17]; + grub_uint32_t unused3[17]; }; struct grub_ahci_hba @@ -195,6 +197,10 @@ grub_ahci_pciinit (grub_pci_device_t dev, if (!(hba->ports_implemented & (1 << i))) continue; + /* FIXME: support hotplugging. */ + if (!hba->ports[i].status) + continue; + command_list = grub_memalign_dma32 (1024, sizeof (struct grub_ahci_cmd_head)); if (!command_list) @@ -333,8 +339,11 @@ grub_ahci_readwrite (grub_ata_t disk, parms->cmdsize); dev->command_table[0].cfis[0] = GRUB_AHCI_FIS_REG_H2D; + dev->command_table[0].cfis[1] = 0x80; for (i = 0; i < sizeof (parms->taskfile.raw); i++) - dev->command_table[0].cfis[register_map[i]] = parms->taskfile.raw[i]; + dev->command_table[0].cfis[register_map[i]] = parms->taskfile.raw[i]; + + dev->command_table[0].cfis[7] |= (parms->cmdsize ? 0 : 0xE0); dev->command_table[0].prdt[0].data_base = grub_dma_get_phys (bufc); dev->command_table[0].prdt[0].unused = 0; @@ -345,12 +354,12 @@ grub_ahci_readwrite (grub_ata_t disk, grub_memcpy ((char *) grub_dma_get_virt (bufc), parms->buffer, parms->size); grub_dprintf ("ahci", "AHCI command schedulded\n"); - dev->hba->ports[dev->port].inten = (1 << 5); - dev->hba->ports[dev->port].intstatus = (1 << 5); + dev->hba->ports[dev->port].inten = (1 << 2) | (1 << 5); + dev->hba->ports[dev->port].intstatus = (1 << 2) | (1 << 5); dev->hba->ports[dev->port].command_issue |= 1; dev->hba->ports[dev->port].command |= 1; - endtime = grub_get_time_ms () + 1000; + endtime = grub_get_time_ms () + 1000; while (!(dev->hba->ports[dev->port].intstatus & (1 << 5))) if (grub_get_time_ms () > endtime) { @@ -362,6 +371,7 @@ grub_ahci_readwrite (grub_ata_t disk, grub_dprintf ("ahci", "AHCI command completed succesfully\n"); dev->hba->ports[dev->port].command &= ~1; + dev->hba->ports[dev->port].command_issue &= ~1; if (!parms->write) grub_memcpy (parms->buffer, (char *) grub_dma_get_virt (bufc), parms->size); @@ -379,10 +389,8 @@ grub_ahci_open (int id, int devnum, struct grub_ata *ata) return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "not an AHCI device"); FOR_LIST_ELEMENTS(dev, grub_ahci_devices) - { - if (dev->num == devnum) - break; - } + if (dev->num == devnum) + break; if (! dev) return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "no such AHCI device"); From 51f7e1acb7355d15d83ff3f916cc80cc1827b96b Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 25 Dec 2010 02:53:20 +0100 Subject: [PATCH 145/869] DMA ATA commands support --- grub-core/disk/ahci.c | 1 + grub-core/disk/ata.c | 28 +++++++++++++++++++++++----- grub-core/disk/pata.c | 1 + include/grub/ata.h | 8 ++++++++ 4 files changed, 33 insertions(+), 5 deletions(-) diff --git a/grub-core/disk/ahci.c b/grub-core/disk/ahci.c index 1e28b3dc5..4b5d195f2 100644 --- a/grub-core/disk/ahci.c +++ b/grub-core/disk/ahci.c @@ -398,6 +398,7 @@ grub_ahci_open (int id, int devnum, struct grub_ata *ata) grub_dprintf ("ahci", "opening AHCI dev `ahci%d'\n", dev->num); ata->data = dev; + ata->dma = 0; return GRUB_ERR_NONE; } diff --git a/grub-core/disk/ata.c b/grub-core/disk/ata.c index 5015f8507..b33abf90d 100644 --- a/grub-core/disk/ata.c +++ b/grub-core/disk/ata.c @@ -255,8 +255,16 @@ grub_ata_readwrite (grub_disk_t disk, grub_disk_addr_t sector, if (addressing == GRUB_ATA_LBA48 && ((sector + size) >> 28) != 0) { batch = 65536; - cmd = GRUB_ATA_CMD_READ_SECTORS_EXT; - cmd_write = GRUB_ATA_CMD_WRITE_SECTORS_EXT; + if (ata->dma) + { + cmd = GRUB_ATA_CMD_READ_SECTORS_DMA_EXT; + cmd_write = GRUB_ATA_CMD_WRITE_SECTORS_DMA_EXT; + } + else + { + cmd = GRUB_ATA_CMD_READ_SECTORS_EXT; + cmd_write = GRUB_ATA_CMD_WRITE_SECTORS_EXT; + } } else { @@ -266,9 +274,17 @@ grub_ata_readwrite (grub_disk_t disk, grub_disk_addr_t sector, batch = 256; else batch = 1; - cmd = GRUB_ATA_CMD_READ_SECTORS; - cmd_write = GRUB_ATA_CMD_WRITE_SECTORS; - } + if (ata->dma) + { + cmd = GRUB_ATA_CMD_READ_SECTORS_DMA; + cmd_write = GRUB_ATA_CMD_WRITE_SECTORS_DMA; + } + else + { + cmd = GRUB_ATA_CMD_READ_SECTORS; + cmd_write = GRUB_ATA_CMD_WRITE_SECTORS; + } + } grub_size_t nsectors = 0; while (nsectors < size) @@ -285,6 +301,8 @@ grub_ata_readwrite (grub_disk_t disk, grub_disk_addr_t sector, parms.taskfile.cmd = (! rw ? cmd : cmd_write); parms.buffer = buf; parms.size = batch * GRUB_DISK_SECTOR_SIZE; + if (ata->dma) + parms.dma = 1; err = ata->dev->readwrite (ata, &parms); if (err) diff --git a/grub-core/disk/pata.c b/grub-core/disk/pata.c index a24237a83..186caf6a2 100644 --- a/grub-core/disk/pata.c +++ b/grub-core/disk/pata.c @@ -474,6 +474,7 @@ grub_pata_open (int id, int devnum, struct grub_ata *ata) return err; ata->data = devfnd; + ata->dma = 0; return GRUB_ERR_NONE; } diff --git a/include/grub/ata.h b/include/grub/ata.h index b1c6ead26..bea74c180 100644 --- a/include/grub/ata.h +++ b/include/grub/ata.h @@ -82,6 +82,9 @@ enum grub_ata_commands GRUB_ATA_CMD_PACKET = 0xa0, GRUB_ATA_CMD_READ_SECTORS = 0x20, GRUB_ATA_CMD_READ_SECTORS_EXT = 0x24, + GRUB_ATA_CMD_READ_SECTORS_DMA = 0xc8, + GRUB_ATA_CMD_READ_SECTORS_DMA_EXT = 0x25, + GRUB_ATA_CMD_SECURITY_FREEZE_LOCK = 0xf5, GRUB_ATA_CMD_SET_FEATURES = 0xef, GRUB_ATA_CMD_SLEEP = 0xe6, @@ -89,6 +92,8 @@ enum grub_ata_commands GRUB_ATA_CMD_STANDBY_IMMEDIATE = 0xe0, GRUB_ATA_CMD_WRITE_SECTORS = 0x30, GRUB_ATA_CMD_WRITE_SECTORS_EXT = 0x34, + GRUB_ATA_CMD_WRITE_SECTORS_DMA_EXT = 0x35, + GRUB_ATA_CMD_WRITE_SECTORS_DMA = 0xca, }; enum grub_ata_timeout_milliseconds @@ -151,6 +156,7 @@ struct grub_disk_ata_pass_through_parms int write; void *cmd; int cmdsize; + int dma; }; struct grub_ata @@ -171,6 +177,8 @@ struct grub_ata /* Set to 0 for ATA, set to 1 for ATAPI. */ int atapi; + int dma; + void *data; struct grub_ata_dev *dev; From 060d0c7ac2fbf763cc07efcb498c04c03b4cf197 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 25 Dec 2010 03:06:07 +0100 Subject: [PATCH 146/869] working AHCI (at last) --- grub-core/disk/ahci.c | 182 +++++++++++++++++++++++++++++++++++------- 1 file changed, 152 insertions(+), 30 deletions(-) diff --git a/grub-core/disk/ahci.c b/grub-core/disk/ahci.c index 4b5d195f2..4d5ee692c 100644 --- a/grub-core/disk/ahci.c +++ b/grub-core/disk/ahci.c @@ -44,8 +44,8 @@ struct grub_ahci_prdt_entry struct grub_ahci_cmd_table { grub_uint8_t cfis[0x40]; - grub_uint8_t command[16]; - grub_uint32_t reserved[0xc]; + grub_uint8_t command[0x10]; + grub_uint8_t reserved[0x30]; struct grub_ahci_prdt_entry prdt[1]; }; @@ -56,14 +56,27 @@ struct grub_ahci_hba_port grub_uint32_t intstatus; grub_uint32_t inten; grub_uint32_t command; - grub_uint32_t unused1[3]; + grub_uint32_t unused1; + grub_uint32_t task_file_data; + grub_uint32_t sig; grub_uint32_t status; - grub_uint32_t unused2[2]; + grub_uint32_t unused2; + grub_uint32_t sata_error; grub_uint32_t sata_active; grub_uint32_t command_issue; - grub_uint32_t unused3[17]; + grub_uint32_t unused3; + grub_uint32_t fbs; + grub_uint32_t unused4[15]; }; +enum grub_ahci_hba_port_command + { + GRUB_AHCI_HBA_PORT_CMD_ST = 0x01, + GRUB_AHCI_HBA_PORT_CMD_FRE = 0x10, + GRUB_AHCI_HBA_PORT_CMD_CR = 0x8000, + GRUB_AHCI_HBA_PORT_CMD_FR = 0x4000, + }; + struct grub_ahci_hba { grub_uint32_t cap; @@ -76,6 +89,11 @@ struct grub_ahci_hba struct grub_ahci_hba_port ports[32]; }; +struct grub_ahci_received_fis +{ + char raw[4096]; +}; + enum { GRUB_AHCI_HBA_CAP_NPORTS_MASK = 0x1f @@ -83,6 +101,7 @@ enum enum { + GRUB_AHCI_HBA_GLOBAL_CONTROL_RESET = 0x00000001, GRUB_AHCI_HBA_GLOBAL_CONTROL_INTR_EN = 0x00000002, GRUB_AHCI_HBA_GLOBAL_CONTROL_AHCI_EN = 0x80000000, }; @@ -106,8 +125,14 @@ struct grub_ahci_device volatile struct grub_ahci_cmd_head *command_list; struct grub_pci_dma_chunk *command_table_chunk; volatile struct grub_ahci_cmd_table *command_table; + struct grub_pci_dma_chunk *rfis; }; +static grub_err_t +grub_ahci_readwrite_real (struct grub_ahci_device *dev, + struct grub_disk_ata_pass_through_parms *parms); + + enum { GRUB_AHCI_CONFIG_READ = 0, @@ -160,10 +185,6 @@ grub_ahci_pciinit (grub_pci_device_t dev, hba = grub_pci_device_map_range (dev, bar & GRUB_PCI_ADDR_MEM_MASK, sizeof (hba)); - hba->global_control |= GRUB_AHCI_HBA_GLOBAL_CONTROL_AHCI_EN; - - nports = (hba->cap & GRUB_AHCI_HBA_CAP_NPORTS_MASK) + 1; - if (! (hba->bios_handoff & GRUB_AHCI_BIOS_HANDOFF_OS_OWNED)) { grub_uint64_t endtime; @@ -186,6 +207,11 @@ grub_ahci_pciinit (grub_pci_device_t dev, } else grub_dprintf ("ahci", "AHCI is already in OS mode\n"); + + hba->global_control |= GRUB_AHCI_HBA_GLOBAL_CONTROL_AHCI_EN; + + nports = (hba->cap & GRUB_AHCI_HBA_CAP_NPORTS_MASK) + 1; + grub_dprintf ("ahci", "%d AHCI ports\n", nports); for (i = 0; i < nports; i++) @@ -197,8 +223,9 @@ grub_ahci_pciinit (grub_pci_device_t dev, if (!(hba->ports_implemented & (1 << i))) continue; + grub_dprintf ("ahci", "status %d:%x\n", i, hba->ports[i].status); /* FIXME: support hotplugging. */ - if (!hba->ports[i].status) + if ((hba->ports[i].status & 0xf) != 0x3) continue; command_list = grub_memalign_dma32 (1024, @@ -224,6 +251,26 @@ grub_ahci_pciinit (grub_pci_device_t dev, grub_dprintf ("ahci", "found device ahci%d (port %d)\n", numdevs, i); + hba->ports[i].command &= ~GRUB_AHCI_HBA_PORT_CMD_FRE; + while ((hba->ports[i].command & GRUB_AHCI_HBA_PORT_CMD_FR)); + hba->ports[i].command &= ~GRUB_AHCI_HBA_PORT_CMD_ST; + while ((hba->ports[i].command & GRUB_AHCI_HBA_PORT_CMD_CR)); + + hba->ports[i].fbs = 2; + + adev->rfis = grub_memalign_dma32 (4096, + sizeof (struct grub_ahci_received_fis)); + grub_memset ((char *) grub_dma_get_virt (adev->rfis), 0, + sizeof (struct grub_ahci_received_fis)); + hba->ports[i].fis_base = grub_dma_get_phys (adev->rfis); + hba->ports[i].command |= GRUB_AHCI_HBA_PORT_CMD_FRE; + while (!(hba->ports[i].command & GRUB_AHCI_HBA_PORT_CMD_FR)); + hba->ports[i].command |= GRUB_AHCI_HBA_PORT_CMD_ST; + while (!(hba->ports[i].command & GRUB_AHCI_HBA_PORT_CMD_CR)); + + hba->ports[i].command = (hba->ports[i].command & 0x0fffffff) + | (1 << 28) | 2 | 4; + adev->hba = hba; adev->port = i; adev->num = numdevs++; @@ -299,13 +346,26 @@ static const int register_map[11] = { 3 /* Features */, 10 /* LBA48 high */ }; static grub_err_t -grub_ahci_readwrite (grub_ata_t disk, - struct grub_disk_ata_pass_through_parms *parms) +grub_ahci_readwrite_real (struct grub_ahci_device *dev, + struct grub_disk_ata_pass_through_parms *parms) { - struct grub_ahci_device *dev = (struct grub_ahci_device *) disk->data; struct grub_pci_dma_chunk *bufc; grub_uint64_t endtime; unsigned i; + grub_err_t err = GRUB_ERR_NONE; + + grub_dprintf ("ahci", "AHCI tfd = %x\n", + dev->hba->ports[dev->port].task_file_data); + + if ((dev->hba->ports[dev->port].task_file_data & 0x80)) + { + dev->hba->ports[dev->port].command &= ~GRUB_AHCI_HBA_PORT_CMD_ST; + while ((dev->hba->ports[dev->port].command & GRUB_AHCI_HBA_PORT_CMD_CR)); + dev->hba->ports[dev->port].command |= GRUB_AHCI_HBA_PORT_CMD_ST; + while (!(dev->hba->ports[dev->port].command & GRUB_AHCI_HBA_PORT_CMD_CR)); + } + + dev->hba->ports[dev->port].sata_error = dev->hba->ports[dev->port].sata_error; grub_dprintf("ahci", "grub_ahci_read (size=%llu, cmdsize = %llu)\n", (unsigned long long) parms->size, @@ -319,14 +379,19 @@ grub_ahci_readwrite (grub_ata_t disk, bufc = grub_memalign_dma32 (1024, parms->size + (parms->size & 1)); + dev->hba->ports[dev->port].command |= 8; + + grub_dprintf ("ahci", "AHCI tfd = %x\n", + dev->hba->ports[dev->port].task_file_data); /* FIXME: support port multipliers. */ dev->command_list[0].config - = (4 << GRUB_AHCI_CONFIG_CFIS_LENGTH_SHIFT) - | GRUB_AHCI_CONFIG_CLEAR_R_OK + = (5 << GRUB_AHCI_CONFIG_CFIS_LENGTH_SHIFT) + // | GRUB_AHCI_CONFIG_CLEAR_R_OK | (0 << GRUB_AHCI_CONFIG_PMP_SHIFT) | (1 << GRUB_AHCI_CONFIG_PRDT_LENGTH_SHIFT) | (parms->cmdsize ? GRUB_AHCI_CONFIG_ATAPI : 0) - | (parms->write ? GRUB_AHCI_CONFIG_WRITE : GRUB_AHCI_CONFIG_READ); + | (parms->write ? GRUB_AHCI_CONFIG_WRITE : GRUB_AHCI_CONFIG_READ) + | (parms->taskfile.cmd == 8 ? (1 << 8) : 0); dev->command_list[0].transfered = 0; dev->command_list[0].command_table_base = grub_dma_get_phys (dev->command_table_chunk); @@ -344,40 +409,97 @@ grub_ahci_readwrite (grub_ata_t disk, dev->command_table[0].cfis[register_map[i]] = parms->taskfile.raw[i]; dev->command_table[0].cfis[7] |= (parms->cmdsize ? 0 : 0xE0); + grub_dprintf ("ahci", "cfis: %02x %02x %02x %02x %02x %02x %02x %02x\n", + dev->command_table[0].cfis[0], dev->command_table[0].cfis[1], + dev->command_table[0].cfis[2], dev->command_table[0].cfis[3], + dev->command_table[0].cfis[4], dev->command_table[0].cfis[5], + dev->command_table[0].cfis[6], dev->command_table[0].cfis[7]); + grub_dprintf ("ahci", "cfis: %02x %02x %02x %02x %02x %02x %02x %02x\n", + dev->command_table[0].cfis[8], dev->command_table[0].cfis[9], + dev->command_table[0].cfis[10], dev->command_table[0].cfis[11], + dev->command_table[0].cfis[12], dev->command_table[0].cfis[13], + dev->command_table[0].cfis[14], dev->command_table[0].cfis[15]); dev->command_table[0].prdt[0].data_base = grub_dma_get_phys (bufc); dev->command_table[0].prdt[0].unused = 0; dev->command_table[0].prdt[0].size = (parms->size + (parms->size & 1) - 1) | GRUB_AHCI_INTERRUPT_ON_COMPLETE; + grub_dprintf ("ahci", "PRDT = %" PRIxGRUB_UINT64_T ", %x, %x (%x)\n", + dev->command_table[0].prdt[0].data_base, + dev->command_table[0].prdt[0].unused, + dev->command_table[0].prdt[0].size, + (char *) &dev->command_table[0].prdt[0] + - (char *) &dev->command_table[0]); + if (parms->write) grub_memcpy ((char *) grub_dma_get_virt (bufc), parms->buffer, parms->size); grub_dprintf ("ahci", "AHCI command schedulded\n"); - dev->hba->ports[dev->port].inten = (1 << 2) | (1 << 5); - dev->hba->ports[dev->port].intstatus = (1 << 2) | (1 << 5); + grub_dprintf ("ahci", "AHCI tfd = %x\n", + dev->hba->ports[dev->port].task_file_data); + dev->hba->ports[dev->port].inten = 0xffffffff;//(1 << 2) | (1 << 5); + dev->hba->ports[dev->port].intstatus = 0xffffffff;//(1 << 2) | (1 << 5); + grub_dprintf ("ahci", "AHCI tfd = %x\n", + dev->hba->ports[dev->port].task_file_data); dev->hba->ports[dev->port].command_issue |= 1; - dev->hba->ports[dev->port].command |= 1; + grub_dprintf ("ahci", "AHCI sig = %x\n", dev->hba->ports[dev->port].sig); + grub_dprintf ("ahci", "AHCI tfd = %x\n", + dev->hba->ports[dev->port].task_file_data); endtime = grub_get_time_ms () + 1000; - while (!(dev->hba->ports[dev->port].intstatus & (1 << 5))) + while ((dev->hba->ports[dev->port].command_issue & 1)) if (grub_get_time_ms () > endtime) { - grub_dprintf ("ahci", "AHCI timeout\n"); - dev->hba->ports[dev->port].command &= ~1; - /* FIXME: free resources. */ - return grub_error (GRUB_ERR_IO, "AHCI transfer timeouted"); + grub_dprintf ("ahci", "AHCI status <%x %x %x>\n", + dev->hba->ports[dev->port].command_issue, + dev->hba->ports[dev->port].intstatus, + dev->hba->ports[dev->port].task_file_data); + err = grub_error (GRUB_ERR_IO, "AHCI transfer timeouted"); + break; } - grub_dprintf ("ahci", "AHCI command completed succesfully\n"); - dev->hba->ports[dev->port].command &= ~1; - dev->hba->ports[dev->port].command_issue &= ~1; + grub_dprintf ("ahci", "AHCI command completed <%x %x %x %x %x, %x %x>\n", + dev->hba->ports[dev->port].command_issue, + dev->hba->ports[dev->port].intstatus, + dev->hba->ports[dev->port].task_file_data, + dev->command_list[0].transfered, + dev->hba->ports[dev->port].sata_error, + ((grub_uint32_t *) grub_dma_get_virt (dev->rfis))[0x00], + ((grub_uint32_t *) grub_dma_get_virt (dev->rfis))[0x18]); + grub_dprintf ("ahci", + "last PIO FIS %08x %08x %08x %08x %08x %08x %08x %08x\n", + ((grub_uint32_t *) grub_dma_get_virt (dev->rfis))[0x08], + ((grub_uint32_t *) grub_dma_get_virt (dev->rfis))[0x09], + ((grub_uint32_t *) grub_dma_get_virt (dev->rfis))[0x0a], + ((grub_uint32_t *) grub_dma_get_virt (dev->rfis))[0x0b], + ((grub_uint32_t *) grub_dma_get_virt (dev->rfis))[0x0c], + ((grub_uint32_t *) grub_dma_get_virt (dev->rfis))[0x0d], + ((grub_uint32_t *) grub_dma_get_virt (dev->rfis))[0x0e], + ((grub_uint32_t *) grub_dma_get_virt (dev->rfis))[0x0f]); + grub_dprintf ("ahci", + "last REG FIS %08x %08x %08x %08x %08x %08x %08x %08x\n", + ((grub_uint32_t *) grub_dma_get_virt (dev->rfis))[0x10], + ((grub_uint32_t *) grub_dma_get_virt (dev->rfis))[0x11], + ((grub_uint32_t *) grub_dma_get_virt (dev->rfis))[0x12], + ((grub_uint32_t *) grub_dma_get_virt (dev->rfis))[0x13], + ((grub_uint32_t *) grub_dma_get_virt (dev->rfis))[0x14], + ((grub_uint32_t *) grub_dma_get_virt (dev->rfis))[0x15], + ((grub_uint32_t *) grub_dma_get_virt (dev->rfis))[0x16], + ((grub_uint32_t *) grub_dma_get_virt (dev->rfis))[0x17]); if (!parms->write) grub_memcpy (parms->buffer, (char *) grub_dma_get_virt (bufc), parms->size); grub_dma_free (bufc); - return GRUB_ERR_NONE; + return err; +} + +static grub_err_t +grub_ahci_readwrite (grub_ata_t disk, + struct grub_disk_ata_pass_through_parms *parms) +{ + return grub_ahci_readwrite_real (disk->data, parms); } static grub_err_t @@ -415,8 +537,8 @@ static struct grub_ata_dev grub_ahci_dev = GRUB_MOD_INIT(ahci) { /* To prevent two drivers operating on the same disks. */ - // grub_disk_firmware_is_tainted = 1; - if (0 && grub_disk_firmware_fini) + grub_disk_firmware_is_tainted = 1; + if (grub_disk_firmware_fini) { grub_disk_firmware_fini (); grub_disk_firmware_fini = NULL; From 188ac234bd37cd6c0fbf649d1f09cb1a0f114f5e Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 25 Dec 2010 03:12:49 +0100 Subject: [PATCH 147/869] use DMA for AHCI commands --- grub-core/disk/ahci.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/grub-core/disk/ahci.c b/grub-core/disk/ahci.c index 4d5ee692c..d9b95df37 100644 --- a/grub-core/disk/ahci.c +++ b/grub-core/disk/ahci.c @@ -520,7 +520,7 @@ grub_ahci_open (int id, int devnum, struct grub_ata *ata) grub_dprintf ("ahci", "opening AHCI dev `ahci%d'\n", dev->num); ata->data = dev; - ata->dma = 0; + ata->dma = 1; return GRUB_ERR_NONE; } From a934071d76d66b4b1a36ec73240249363392351f Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 25 Dec 2010 03:22:12 +0100 Subject: [PATCH 148/869] Remove unused pata ioaddress2 --- grub-core/disk/pata.c | 36 ++++++++---------------------------- 1 file changed, 8 insertions(+), 28 deletions(-) diff --git a/grub-core/disk/pata.c b/grub-core/disk/pata.c index 186caf6a2..940a9a5f0 100644 --- a/grub-core/disk/pata.c +++ b/grub-core/disk/pata.c @@ -29,8 +29,6 @@ /* At the moment, only two IDE ports are supported. */ static const grub_port_t grub_pata_ioaddress[] = { GRUB_ATA_CH0_PORT1, GRUB_ATA_CH1_PORT1 }; -static const grub_port_t grub_pata_ioaddress2[] = { GRUB_ATA_CH0_PORT2, - GRUB_ATA_CH1_PORT2 }; struct grub_pata_device { @@ -40,7 +38,6 @@ struct grub_pata_device /* IO addresses on which the registers for this device can be found. */ grub_port_t ioaddress; - grub_port_t ioaddress2; /* Two devices can be connected to a single cable. Use this field to select device 0 (commonly known as "master") or device 1 @@ -64,18 +61,6 @@ grub_pata_regget (struct grub_pata_device *dev, int reg) return grub_inb (dev->ioaddress + reg); } -static inline void -grub_pata_regset2 (struct grub_pata_device *dev, int reg, int val) -{ - grub_outb (val, dev->ioaddress2 + reg); -} - -static inline grub_uint8_t -grub_pata_regget2 (struct grub_pata_device *dev, int reg) -{ - return grub_inb (dev->ioaddress2 + reg); -} - /* Wait for !BSY. */ static grub_err_t grub_pata_wait_not_busy (struct grub_pata_device *dev, int milliseconds) @@ -298,14 +283,14 @@ check_device (struct grub_pata_device *dev) } static grub_err_t -grub_pata_device_initialize (int port, int device, int addr, int addr2) +grub_pata_device_initialize (int port, int device, int addr) { struct grub_pata_device *dev; struct grub_pata_device **devp; grub_err_t err; - grub_dprintf ("pata", "detecting device %d,%d (0x%x, 0x%x)\n", - port, device, addr, addr2); + grub_dprintf ("pata", "detecting device %d,%d (0x%x)\n", + port, device, addr); dev = grub_malloc (sizeof(*dev)); if (! dev) @@ -315,7 +300,6 @@ grub_pata_device_initialize (int port, int device, int addr, int addr2) dev->port = port; dev->device = device; dev->ioaddress = addr + GRUB_MACHINE_PCI_IO_BASE; - dev->ioaddress2 = addr2 + GRUB_MACHINE_PCI_IO_BASE; dev->next = NULL; /* Register the device. */ @@ -339,7 +323,6 @@ grub_pata_pciinit (grub_pci_device_t dev, grub_uint32_t bar1; grub_uint32_t bar2; int rega; - int regb; int i; static int controller = 0; int cs5536 = 0; @@ -372,14 +355,12 @@ grub_pata_pciinit (grub_pci_device_t dev, compat = (class >> (8 + 2 * i)) & 1; rega = 0; - regb = 0; /* If the channel is in compatibility mode, just assign the default registers. */ if (compat == 0 && !compat_use[i]) { rega = grub_pata_ioaddress[i]; - regb = grub_pata_ioaddress2[i]; compat_use[i] = 1; } else if (compat) @@ -398,19 +379,18 @@ grub_pata_pciinit (grub_pci_device_t dev, if ((bar1 & 1) && (bar2 & 1)) { rega = bar1 & ~3; - regb = bar2 & ~3; } } grub_dprintf ("pata", - "PCI dev (%d,%d,%d) compat=%d rega=0x%x regb=0x%x\n", + "PCI dev (%d,%d,%d) compat=%d rega=0x%x\n", grub_pci_get_bus (dev), grub_pci_get_device (dev), - grub_pci_get_function (dev), compat, rega, regb); + grub_pci_get_function (dev), compat, rega); - if (rega && regb) + if (rega) { grub_errno = GRUB_ERR_NONE; - grub_pata_device_initialize (controller * 2 + i, 0, rega, regb); + grub_pata_device_initialize (controller * 2 + i, 0, rega); /* Most errors raised by grub_ata_device_initialize() are harmless. They just indicate this particular drive is not responding, most @@ -422,7 +402,7 @@ grub_pata_pciinit (grub_pci_device_t dev, grub_errno = GRUB_ERR_NONE; } - grub_pata_device_initialize (controller * 2 + i, 1, rega, regb); + grub_pata_device_initialize (controller * 2 + i, 1, rega); /* Likewise. */ if (grub_errno) From d9675dbee3525def248571a7937e69fdec7afab0 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 25 Dec 2010 03:47:51 +0100 Subject: [PATCH 149/869] Move 0xE0 to callers rather than to have it in drivers --- grub-core/commands/hdparm.c | 4 ++++ grub-core/disk/ahci.c | 1 - grub-core/disk/ata.c | 10 +++++----- grub-core/disk/pata.c | 5 ++--- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/grub-core/commands/hdparm.c b/grub-core/commands/hdparm.c index 0154ece57..800bfa06d 100644 --- a/grub-core/commands/hdparm.c +++ b/grub-core/commands/hdparm.c @@ -72,6 +72,8 @@ grub_hdparm_do_ata_cmd (grub_ata_t ata, grub_uint8_t cmd, apt.taskfile.cmd = cmd; apt.taskfile.features = features; apt.taskfile.sectors = sectors; + apt.taskfile.disk = 0xE0; + apt.buffer = buffer; apt.size = size; @@ -88,6 +90,7 @@ grub_hdparm_do_check_powermode_cmd (grub_ata_t ata) grub_memset (&apt, 0, sizeof (apt)); apt.taskfile.cmd = GRUB_ATA_CMD_CHECK_POWER_MODE; + apt.taskfile.disk = 0xE0; if (ata->dev->readwrite (ata, &apt)) return -1; @@ -105,6 +108,7 @@ grub_hdparm_do_smart_cmd (grub_ata_t ata, grub_uint8_t features) apt.taskfile.features = features; apt.taskfile.lba_mid = 0x4f; apt.taskfile.lba_high = 0xc2; + apt.taskfile.disk = 0xE0; if (ata->dev->readwrite (ata, &apt)) return -1; diff --git a/grub-core/disk/ahci.c b/grub-core/disk/ahci.c index d9b95df37..3160523ce 100644 --- a/grub-core/disk/ahci.c +++ b/grub-core/disk/ahci.c @@ -408,7 +408,6 @@ grub_ahci_readwrite_real (struct grub_ahci_device *dev, for (i = 0; i < sizeof (parms->taskfile.raw); i++) dev->command_table[0].cfis[register_map[i]] = parms->taskfile.raw[i]; - dev->command_table[0].cfis[7] |= (parms->cmdsize ? 0 : 0xE0); grub_dprintf ("ahci", "cfis: %02x %02x %02x %02x %02x %02x %02x %02x\n", dev->command_table[0].cfis[0], dev->command_table[0].cfis[1], dev->command_table[0].cfis[2], dev->command_table[0].cfis[3], diff --git a/grub-core/disk/ata.c b/grub-core/disk/ata.c index b33abf90d..494325aa5 100644 --- a/grub-core/disk/ata.c +++ b/grub-core/disk/ata.c @@ -70,7 +70,7 @@ grub_atapi_identify (struct grub_ata *dev) return grub_errno; grub_memset (&parms, 0, sizeof (parms)); - parms.taskfile.disk = 0; + parms.taskfile.disk = 0xE0; parms.taskfile.cmd = GRUB_ATA_CMD_IDENTIFY_PACKET_DEVICE; parms.size = GRUB_DISK_SECTOR_SIZE; parms.buffer = info; @@ -108,7 +108,7 @@ grub_ata_identify (struct grub_ata *dev) grub_memset (&parms, 0, sizeof (parms)); parms.buffer = info; parms.size = GRUB_DISK_SECTOR_SIZE; - parms.taskfile.disk = 0; + parms.taskfile.disk = 0xE0; parms.taskfile.cmd = GRUB_ATA_CMD_IDENTIFY_DEVICE; @@ -196,7 +196,7 @@ grub_ata_setaddress (struct grub_ata *dev, "sector %d cannot be addressed " "using CHS addressing", sector); - parms->taskfile.disk = head; + parms->taskfile.disk = 0xE0 | head; parms->taskfile.sectnum = sect; parms->taskfile.cyllsb = cylinder & 0xFF; parms->taskfile.cylmsb = cylinder >> 8; @@ -207,7 +207,7 @@ grub_ata_setaddress (struct grub_ata *dev, case GRUB_ATA_LBA: if (size == 256) size = 0; - parms->taskfile.disk = ((sector >> 24) & 0x0F); + parms->taskfile.disk = 0xE0 | ((sector >> 24) & 0x0F); parms->taskfile.sectors = size; parms->taskfile.lba_low = sector & 0xFF; @@ -219,7 +219,7 @@ grub_ata_setaddress (struct grub_ata *dev, if (size == 65536) size = 0; - parms->taskfile.disk = 0; + parms->taskfile.disk = 0xE0; /* Set "Previous". */ parms->taskfile.sectors = size & 0xFF; diff --git a/grub-core/disk/pata.c b/grub-core/disk/pata.c index 940a9a5f0..f9111bc5f 100644 --- a/grub-core/disk/pata.c +++ b/grub-core/disk/pata.c @@ -151,9 +151,8 @@ grub_pata_readwrite (struct grub_ata *disk, parms->taskfile.lba_low, parms->size); /* Set registers. */ - grub_pata_regset (dev, GRUB_ATA_REG_DISK, (parms->cmdsize ? 0 : 0xE0) - | dev->device << 4 - | (parms->taskfile.disk & 0xf)); + grub_pata_regset (dev, GRUB_ATA_REG_DISK, (dev->device << 4) + | (parms->taskfile.disk & 0xef)); if (grub_pata_check_ready (dev)) return grub_errno; From d1e517eb20c2e5e14bdd8eea7168538f9f15a67c Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 25 Dec 2010 12:11:54 +0100 Subject: [PATCH 150/869] extend --disk-module to AHCI and USB --- grub-core/bus/usb/ohci.c | 8 ++++++-- grub-core/disk/ahci.c | 38 ++++++++++++++++++++++++++++++++++++++ util/grub-install.in | 14 +++++++++++--- 3 files changed, 55 insertions(+), 5 deletions(-) diff --git a/grub-core/bus/usb/ohci.c b/grub-core/bus/usb/ohci.c index 8adaee6e0..577f35259 100644 --- a/grub-core/bus/usb/ohci.c +++ b/grub-core/bus/usb/ohci.c @@ -1422,18 +1422,22 @@ static struct grub_usb_controller_dev usb_controller = .detect_dev = grub_ohci_detect_dev }; +static void *fini_hnd; + GRUB_MOD_INIT(ohci) { COMPILE_TIME_ASSERT (sizeof (struct grub_ohci_td) == 32); COMPILE_TIME_ASSERT (sizeof (struct grub_ohci_ed) == 16); grub_ohci_inithw (); grub_usb_controller_dev_register (&usb_controller); - grub_loader_register_preboot_hook (grub_ohci_fini_hw, grub_ohci_restore_hw, - GRUB_LOADER_PREBOOT_HOOK_PRIO_DISK); + fini_hnd = grub_loader_register_preboot_hook (grub_ohci_fini_hw, + grub_ohci_restore_hw, + GRUB_LOADER_PREBOOT_HOOK_PRIO_DISK); } GRUB_MOD_FINI(ohci) { grub_ohci_fini_hw (0); + grub_loader_unregister_preboot_hook (fini_hnd); grub_usb_controller_dev_unregister (&usb_controller); } diff --git a/grub-core/disk/ahci.c b/grub-core/disk/ahci.c index 3160523ce..61ca7e4d6 100644 --- a/grub-core/disk/ahci.c +++ b/grub-core/disk/ahci.c @@ -25,6 +25,7 @@ #include #include #include +#include struct grub_ahci_cmd_head { @@ -296,6 +297,34 @@ grub_ahci_initialize (void) return grub_errno; } +static grub_err_t +grub_ahci_fini_hw (int noreturn __attribute__ ((unused))) +{ + struct grub_ahci_device *dev, *next; + + for (dev = grub_ahci_devices; dev; dev = next) + { + next = dev->next; + dev->hba->ports[dev->num].command &= ~GRUB_AHCI_HBA_PORT_CMD_FRE; + while ((dev->hba->ports[dev->num].command & GRUB_AHCI_HBA_PORT_CMD_FR)); + dev->hba->ports[dev->num].command &= ~GRUB_AHCI_HBA_PORT_CMD_ST; + while ((dev->hba->ports[dev->num].command & GRUB_AHCI_HBA_PORT_CMD_CR)); + grub_dma_free (dev->command_list_chunk); + grub_dma_free (dev->command_table_chunk); + grub_dma_free (dev->rfis); + + grub_free (dev); + } + grub_ahci_devices = NULL; + return GRUB_ERR_NONE; +} + +static grub_err_t +grub_ahci_restore_hw (void) +{ + return grub_ahci_initialize (); +} + @@ -533,6 +562,8 @@ static struct grub_ata_dev grub_ahci_dev = +static void *fini_hnd; + GRUB_MOD_INIT(ahci) { /* To prevent two drivers operating on the same disks. */ @@ -548,9 +579,16 @@ GRUB_MOD_INIT(ahci) /* AHCI devices are handled by scsi.mod. */ grub_ata_dev_register (&grub_ahci_dev); + + fini_hnd = grub_loader_register_preboot_hook (grub_ahci_fini_hw, + grub_ahci_restore_hw, + GRUB_LOADER_PREBOOT_HOOK_PRIO_DISK); } GRUB_MOD_FINI(ahci) { + grub_ahci_fini_hw (0); + grub_loader_unregister_preboot_hook (fini_hnd); + grub_ata_dev_unregister (&grub_ahci_dev); } diff --git a/util/grub-install.in b/util/grub-install.in index b9e833360..6259b1c4a 100644 --- a/util/grub-install.in +++ b/util/grub-install.in @@ -77,7 +77,7 @@ if [ "${target_cpu}-${platform}" = "i386-pc" ] ; then elif [ "${platform}" = "ieee1275" ] || [ "${platform}" = "efi" ] ; then disk_module= else - disk_module=ata + disk_module=native fi # Usage: usage @@ -114,7 +114,7 @@ Install GRUB on your drive. EOF if [ "${target_cpu}-${platform}" = "i386-pc" ] ; then cat < Date: Sat, 25 Dec 2010 13:44:31 +0100 Subject: [PATCH 151/869] avoid throwing data away on pxefs_open. Reported by : Seth Goldberg --- grub-core/net/i386/pc/pxe.c | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/grub-core/net/i386/pc/pxe.c b/grub-core/net/i386/pc/pxe.c index fd1447b40..c07aa78f9 100644 --- a/grub-core/net/i386/pc/pxe.c +++ b/grub-core/net/i386/pc/pxe.c @@ -117,7 +117,7 @@ grub_pxefs_open (struct grub_file *file, const char *name) struct grub_pxe_data *data; grub_file_t file_int, bufio; - data = grub_malloc (sizeof (*data)); + data = grub_zalloc (sizeof (*data) + grub_strlen (name) + 1); if (!data) return grub_errno; @@ -135,7 +135,10 @@ grub_pxefs_open (struct grub_file *file, const char *name) err = grub_net_resolve_address (file->device->net->name + sizeof ("pxe,") - 1, &addr); if (err) - return err; + { + grub_free (data); + return err; + } } else { @@ -144,7 +147,10 @@ grub_pxefs_open (struct grub_file *file, const char *name) } err = grub_net_route_address (addr, &gateway, &interf); if (err) - return err; + { + grub_free (data); + return err; + } data->server_ip = addr.ipv4; data->gateway_ip = gateway.ipv4; } @@ -160,7 +166,10 @@ grub_pxefs_open (struct grub_file *file, const char *name) grub_strcpy ((char *)&c.c1.filename[0], name); grub_pxe_call (GRUB_PXENV_TFTP_GET_FSIZE, &c.c1, pxe_rm_entry); if (c.c1.status) - return grub_error (GRUB_ERR_FILE_NOT_FOUND, "file not found"); + { + grub_free (data); + return grub_error (GRUB_ERR_FILE_NOT_FOUND, "file not found"); + } file->size = c.c1.file_size; @@ -168,11 +177,10 @@ grub_pxefs_open (struct grub_file *file, const char *name) c.c2.packet_size = grub_pxe_blksize; grub_pxe_call (GRUB_PXENV_TFTP_OPEN, &c.c2, pxe_rm_entry); if (c.c2.status) - return grub_error (GRUB_ERR_BAD_FS, "open fails"); - - data = grub_zalloc (sizeof (struct grub_pxe_data) + grub_strlen (name) + 1); - if (! data) - return grub_errno; + { + grub_free (data); + return grub_error (GRUB_ERR_BAD_FS, "open fails"); + } data->block_size = c.c2.packet_size; grub_strcpy (data->filename, name); From 0354b8672cfceed56851c9bad14edfe6a33050b5 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 25 Dec 2010 14:09:36 +0100 Subject: [PATCH 152/869] * grub-core/commands/acpihalt.c (grub_acpi_halt): Sleep for 1.5 before writing an error message because of async power management. * grub-core/kern/mips/yeeloong/init.c (grub_halt): Likewise. (grub_reboot): Likewise. --- ChangeLog | 7 +++++++ grub-core/commands/acpihalt.c | 3 +++ grub-core/kern/mips/yeeloong/init.c | 4 ++++ 3 files changed, 14 insertions(+) diff --git a/ChangeLog b/ChangeLog index 79eeae387..452455966 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2010-12-25 Vladimir Serbinenko + + * grub-core/commands/acpihalt.c (grub_acpi_halt): Sleep for 1.5 before + writing an error message because of async power management. + * grub-core/kern/mips/yeeloong/init.c (grub_halt): Likewise. + (grub_reboot): Likewise. + 2010-12-23 Jordan Uggla * tests/util/grub-shell.in: Suppress "ACPI shutdown failed" error to diff --git a/grub-core/commands/acpihalt.c b/grub-core/commands/acpihalt.c index 2789e2eca..9a4cda521 100644 --- a/grub-core/commands/acpihalt.c +++ b/grub-core/commands/acpihalt.c @@ -36,6 +36,7 @@ typedef uint8_t grub_uint8_t; #ifndef GRUB_DSDT_TEST #include +#include #include #endif @@ -324,6 +325,8 @@ grub_acpi_halt (void) } } + grub_millisleep (1500); + grub_printf ("ACPI shutdown failed\n"); } #endif diff --git a/grub-core/kern/mips/yeeloong/init.c b/grub-core/kern/mips/yeeloong/init.c index cc7c16806..cadb10773 100644 --- a/grub-core/kern/mips/yeeloong/init.c +++ b/grub-core/kern/mips/yeeloong/init.c @@ -223,6 +223,8 @@ grub_halt (void) grub_outb (grub_inb (GRUB_CPU_LOONGSON_GPIOCFG) & ~GRUB_CPU_LOONGSON_SHUTDOWN_GPIO, GRUB_CPU_LOONGSON_GPIOCFG); + grub_millisleep (1500); + grub_printf ("Shutdown failed\n"); grub_refresh (); while (1); @@ -239,6 +241,8 @@ grub_reboot (void) { grub_write_ec (GRUB_MACHINE_EC_COMMAND_REBOOT); + grub_millisleep (1500); + grub_printf ("Reboot failed\n"); grub_refresh (); while (1); From 3c51ecb82b7ab1a94a296c530bd5f4ffdb7a2eab Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 25 Dec 2010 15:47:23 +0100 Subject: [PATCH 153/869] Fix adressing mode mismatch --- grub-core/disk/ata.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/grub-core/disk/ata.c b/grub-core/disk/ata.c index 494325aa5..3fecb98dd 100644 --- a/grub-core/disk/ata.c +++ b/grub-core/disk/ata.c @@ -173,9 +173,10 @@ static grub_err_t grub_ata_setaddress (struct grub_ata *dev, struct grub_disk_ata_pass_through_parms *parms, grub_disk_addr_t sector, - grub_size_t size) + grub_size_t size, + grub_ata_addressing_t addressing) { - switch (dev->addr) + switch (addressing) { case GRUB_ATA_CHS: { @@ -297,7 +298,7 @@ grub_ata_readwrite (grub_disk_t disk, grub_disk_addr_t sector, grub_dprintf("ata", "rw=%d, sector=%llu, batch=%llu\n", rw, (unsigned long long) sector, (unsigned long long) batch); grub_memset (&parms, 0, sizeof (parms)); - grub_ata_setaddress (ata, &parms, sector, batch); + grub_ata_setaddress (ata, &parms, sector, batch, addressing); parms.taskfile.cmd = (! rw ? cmd : cmd_write); parms.buffer = buf; parms.size = batch * GRUB_DISK_SECTOR_SIZE; From c76ae9b4da785c43dba8478768dd346f5c0b4d59 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 25 Dec 2010 17:40:00 +0100 Subject: [PATCH 154/869] set parms.write on disk write --- grub-core/disk/ata.c | 1 + 1 file changed, 1 insertion(+) diff --git a/grub-core/disk/ata.c b/grub-core/disk/ata.c index 3fecb98dd..c7cde3166 100644 --- a/grub-core/disk/ata.c +++ b/grub-core/disk/ata.c @@ -302,6 +302,7 @@ grub_ata_readwrite (grub_disk_t disk, grub_disk_addr_t sector, parms.taskfile.cmd = (! rw ? cmd : cmd_write); parms.buffer = buf; parms.size = batch * GRUB_DISK_SECTOR_SIZE; + parms.write = rw; if (ata->dma) parms.dma = 1; From 9797178671d1044cf9fc13648152ea2ea5e76e41 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 25 Dec 2010 18:02:43 +0100 Subject: [PATCH 155/869] Accept ports in state 1 --- grub-core/disk/ahci.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/grub-core/disk/ahci.c b/grub-core/disk/ahci.c index 61ca7e4d6..b348ce3d0 100644 --- a/grub-core/disk/ahci.c +++ b/grub-core/disk/ahci.c @@ -220,13 +220,15 @@ grub_ahci_pciinit (grub_pci_device_t dev, struct grub_ahci_device *adev; struct grub_pci_dma_chunk *command_list; struct grub_pci_dma_chunk *command_table; + grub_uint32_t st; if (!(hba->ports_implemented & (1 << i))) continue; grub_dprintf ("ahci", "status %d:%x\n", i, hba->ports[i].status); /* FIXME: support hotplugging. */ - if ((hba->ports[i].status & 0xf) != 0x3) + st = hba->ports[i].status; + if ((st & 0xf) != 0x3 && (st & 0xf) != 0x1) continue; command_list = grub_memalign_dma32 (1024, From c4855fdc79c3291e907a1080accbc1b4c60abd75 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 25 Dec 2010 18:16:01 +0100 Subject: [PATCH 156/869] * util/grub.d/30_os-prober.in: Don't emit drivemap directive for Windows Server 2008. Reported by: Devin Giddings. --- ChangeLog | 6 ++++++ util/grub.d/30_os-prober.in | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 452455966..43c4dbacb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2010-12-25 Vladimir Serbinenko + + * util/grub.d/30_os-prober.in: Don't emit drivemap directive for + Windows Server 2008. + Reported by: Devin Giddings. + 2010-12-25 Vladimir Serbinenko * grub-core/commands/acpihalt.c (grub_acpi_halt): Sleep for 1.5 before diff --git a/util/grub.d/30_os-prober.in b/util/grub.d/30_os-prober.in index 728ac2378..d9d4b0a96 100644 --- a/util/grub.d/30_os-prober.in +++ b/util/grub.d/30_os-prober.in @@ -111,7 +111,7 @@ EOF prepare_grub_to_access_device ${DEVICE} | sed -e "s/^/\t/" case ${LONGNAME} in - Windows\ Vista*|Windows\ 7*) + Windows\ Vista*|Windows\ 7*|Windows\ Server\ 2008*) ;; *) cat << EOF From 022d01b8078e3277a534f43eb58484ec2c4a3911 Mon Sep 17 00:00:00 2001 From: Shea Levy <> Date: Sat, 25 Dec 2010 18:21:46 +0100 Subject: [PATCH 157/869] * grub-core/genmod.sh.in: Use @OBJCOPY@ rather than objcopy. --- ChangeLog | 4 ++++ grub-core/genmod.sh.in | 6 +++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 43c4dbacb..3a20e6346 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2010-12-25 Shea Levy + + * grub-core/genmod.sh.in: Use @OBJCOPY@ rather than objcopy. + 2010-12-25 Vladimir Serbinenko * util/grub.d/30_os-prober.in: Don't emit drivemap directive for diff --git a/grub-core/genmod.sh.in b/grub-core/genmod.sh.in index 8dfd5d347..b97f3e1c7 100644 --- a/grub-core/genmod.sh.in +++ b/grub-core/genmod.sh.in @@ -35,7 +35,7 @@ deps=`grep ^$modname: $moddep | sed s@^.*:@@` rm -f $tmpfile $outfile # stripout .modname and .moddeps sections from input module -objcopy -R .modname -R .moddeps $infile $tmpfile +@OBJCOPY@ -R .modname -R .moddeps $infile $tmpfile # Attach .modname and .moddeps sections t1=`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` || exit 1 @@ -45,9 +45,9 @@ t2=`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` || exit 1 for dep in $deps; do printf "$dep\0" >> $t2; done if test -n "$deps"; then - objcopy --add-section .modname=$t1 --add-section .moddeps=$t2 $tmpfile + @OBJCOPY@ --add-section .modname=$t1 --add-section .moddeps=$t2 $tmpfile else - objcopy --add-section .modname=$t1 $tmpfile + @OBJCOPY@ --add-section .modname=$t1 $tmpfile fi rm -f $t1 $t2 From 190a011a8b15506f0403ba77a587fa63fe7c7e2a Mon Sep 17 00:00:00 2001 From: Jeroen Dekkers Date: Sat, 25 Dec 2010 22:32:54 +0100 Subject: [PATCH 158/869] * grub-core/disk/raid.c (insert_array): Don't add spurious members. --- ChangeLog | 4 ++++ grub-core/disk/raid.c | 10 ++++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3a20e6346..249ec6bc6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2010-12-25 Jeroen Dekkers + + * grub-core/disk/raid.c (insert_array): Don't add spurious members. + 2010-12-25 Shea Levy * grub-core/genmod.sh.in: Use @OBJCOPY@ rather than objcopy. diff --git a/grub-core/disk/raid.c b/grub-core/disk/raid.c index f1b67a859..edc2b195d 100644 --- a/grub-core/disk/raid.c +++ b/grub-core/disk/raid.c @@ -522,14 +522,16 @@ insert_array (grub_disk_t disk, struct grub_raid_array *new_array, /* We found more members of the array than the array actually has according to its superblock. This shouldn't happen normally. */ - grub_dprintf ("raid", "array->nr_devs > array->total_devs (%d)?!?", - array->total_devs); + return grub_error (GRUB_ERR_BAD_DEVICE, + "superfluous RAID member (%d found)", + array->total_devs); if (array->members[new_array->index].device != NULL) /* We found multiple devices with the same number. Again, this shouldn't happen. */ - grub_dprintf ("raid", "Found two disks with the number %d?!?", - new_array->number); + return grub_error (GRUB_ERR_BAD_DEVICE, + "found two disks with the number %d", + new_array->number); if (new_array->disk_size < array->disk_size) array->disk_size = new_array->disk_size; From b28fd807eb6e6ec74964715e0bfd3c32b0dbb449 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 26 Dec 2010 00:38:20 +0100 Subject: [PATCH 159/869] freedos support --- docs/grub.texi | 4 + grub-core/Makefile.core.def | 6 ++ grub-core/lib/i386/relocator.c | 2 + grub-core/lib/i386/relocator16.S | 7 +- grub-core/loader/i386/pc/freedos.c | 136 +++++++++++++++++++++++++++++ include/grub/i386/relocator.h | 1 + 6 files changed, 155 insertions(+), 1 deletion(-) create mode 100644 grub-core/loader/i386/pc/freedos.c diff --git a/docs/grub.texi b/docs/grub.texi index 54a2d8791..d9500fb52 100644 --- a/docs/grub.texi +++ b/docs/grub.texi @@ -3305,6 +3305,7 @@ X86 support is summarised in the following table. ``Yes'' means that the kernel @item @tab BIOS @tab Coreboot @item BIOS chainloading @tab yes @tab no (1) @item NTLDR @tab yes @tab no (1) +@item Freedos @tab yes @tab no (1) @item FreeBSD bootloader @tab yes @tab crashes (1) @item 32-bit kFreeBSD @tab yes @tab crashes (2,6) @item 64-bit kFreeBSD @tab yes @tab crashes (2,6) @@ -3329,6 +3330,7 @@ X86 support is summarised in the following table. ``Yes'' means that the kernel @item @tab Multiboot @tab Qemu @item BIOS chainloading @tab no (1) @tab no (1) @item NTLDR @tab no (1) @tab no (1) +@item FreeDOS @tab no (1) @tab no (1) @item FreeBSD bootloader @tab crashes (1) @tab crashes (1) @item 32-bit kFreeBSD @tab crashes (6) @tab crashes (6) @item 64-bit kFreeBSD @tab crashes (6) @tab crashes (6) @@ -3353,6 +3355,7 @@ X86 support is summarised in the following table. ``Yes'' means that the kernel @item @tab 32-bit EFI @tab 64-bit EFI @item BIOS chainloading @tab no (1) @tab no (1) @item NTLDR @tab no (1) @tab no (1) +@item FreeDOS @tab no (1) @tab no (1) @item FreeBSD bootloader @tab crashes (1) @tab crashes (1) @item 32-bit kFreeBSD @tab headless @tab headless @item 64-bit kFreeBSD @tab headless @tab headless @@ -3377,6 +3380,7 @@ X86 support is summarised in the following table. ``Yes'' means that the kernel @item @tab IEEE1275 @item BIOS chainloading @tab no (1) @item NTLDR @tab no (1) +@item FreeDOS @tab no (1) @item FreeBSD bootloader @tab crashes (1) @item 32-bit kFreeBSD @tab crashes (6) @item 64-bit kFreeBSD @tab crashes (6) diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def index 37c0ce970..da309d6d9 100644 --- a/grub-core/Makefile.core.def +++ b/grub-core/Makefile.core.def @@ -1158,6 +1158,12 @@ module = { enable = i386_pc; }; +module = { + name = freedos; + i386_pc = loader/i386/pc/freedos.c; + enable = i386_pc; +}; + module = { name = multiboot2; cppflags = "-DGRUB_USE_MULTIBOOT2"; diff --git a/grub-core/lib/i386/relocator.c b/grub-core/lib/i386/relocator.c index 1bc4240c3..2f10feb5e 100644 --- a/grub-core/lib/i386/relocator.c +++ b/grub-core/lib/i386/relocator.c @@ -50,6 +50,7 @@ extern grub_uint16_t grub_relocator16_gs; extern grub_uint16_t grub_relocator16_ss; extern grub_uint16_t grub_relocator16_sp; extern grub_uint32_t grub_relocator16_edx; +extern grub_uint32_t grub_relocator16_ebx; extern grub_uint8_t grub_relocator32_start; extern grub_uint8_t grub_relocator32_end; @@ -212,6 +213,7 @@ grub_relocator16_boot (struct grub_relocator *rel, grub_relocator16_ss = state.ss; grub_relocator16_sp = state.sp; + grub_relocator16_ebx = state.ebx; grub_relocator16_edx = state.edx; grub_memmove (get_virtual_current_address (ch), &grub_relocator16_start, diff --git a/grub-core/lib/i386/relocator16.S b/grub-core/lib/i386/relocator16.S index c3768f4eb..c6d38eba4 100644 --- a/grub-core/lib/i386/relocator16.S +++ b/grub-core/lib/i386/relocator16.S @@ -136,7 +136,12 @@ VARIABLE(grub_relocator16_sp) .byte 0x66, 0xba VARIABLE(grub_relocator16_edx) .long 0 - + + /* movw imm32, %ebx. */ + .byte 0x66, 0xbb +VARIABLE(grub_relocator16_ebx) + .long 0 + /* Cleared direction flag is of no problem with any current payload and makes this implementation easier. */ cld diff --git a/grub-core/loader/i386/pc/freedos.c b/grub-core/loader/i386/pc/freedos.c new file mode 100644 index 000000000..67d97e246 --- /dev/null +++ b/grub-core/loader/i386/pc/freedos.c @@ -0,0 +1,136 @@ +/* chainloader.c - boot another boot loader */ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2002,2004,2007,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 . + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static grub_dl_t my_mod; +static struct grub_relocator *rel; +static grub_uint32_t ebx = 0xffffffff; + +#define GRUB_FREEDOS_SEGMENT 0x60 +#define GRUB_FREEDOS_STACK_SEGMENT 0x1fe0 +#define GRUB_FREEDOS_STACK_POINTER 0x8000 + +static grub_err_t +grub_freedos_boot (void) +{ + struct grub_relocator16_state state = { + .cs = GRUB_FREEDOS_SEGMENT, + .ip = 0, + .ds = 0, + .es = 0, + .fs = 0, + .gs = 0, + .ss = GRUB_FREEDOS_STACK_SEGMENT, + .sp = GRUB_FREEDOS_STACK_POINTER, + .ebx = ebx, + .edx = 0 + }; + grub_video_set_mode ("text", 0, 0); + + return grub_relocator16_boot (rel, state); +} + +static grub_err_t +grub_freedos_unload (void) +{ + grub_relocator_unload (rel); + rel = NULL; + grub_dl_unref (my_mod); + return GRUB_ERR_NONE; +} + +static grub_err_t +grub_cmd_freedos (grub_command_t cmd __attribute__ ((unused)), + int argc, char *argv[]) +{ + grub_file_t file = 0; + grub_err_t err; + void *kernelsys; + grub_size_t kernelsyssize; + + if (argc == 0) + return grub_error (GRUB_ERR_BAD_ARGUMENT, "no file specified"); + + grub_dl_ref (my_mod); + + rel = grub_relocator_new (); + if (!rel) + goto fail; + + file = grub_file_open (argv[0]); + if (! file) + goto fail; + + ebx = grub_get_root_biosnumber (); + + kernelsyssize = grub_file_size (file); + { + grub_relocator_chunk_t ch; + err = grub_relocator_alloc_chunk_addr (rel, &ch, GRUB_NTLDR_SEGMENT << 4, + kernelsyssize); + if (err) + goto fail; + kernelsys = get_virtual_current_address (ch); + } + + if (grub_file_read (file, kernelsys, kernelsyssize) + != (grub_ssize_t) ntldrsize) + goto fail; + + grub_loader_set (grub_freedos_boot, grub_freedos_unload, 1); + return GRUB_ERR_NONE; + + fail: + + if (file) + grub_file_close (file); + + grub_ntldr_unload (); + + return grub_errno; +} + +static grub_command_t cmd; + +GRUB_MOD_INIT(freedos) +{ + cmd = grub_register_command ("freedos", grub_cmd_freedos, + 0, N_("Load FreeDOS kernel.sys.")); + my_mod = mod; +} + +GRUB_MOD_FINI(freedos) +{ + grub_unregister_command (cmd); +} diff --git a/include/grub/i386/relocator.h b/include/grub/i386/relocator.h index 6ff5c6631..778049eef 100644 --- a/include/grub/i386/relocator.h +++ b/include/grub/i386/relocator.h @@ -46,6 +46,7 @@ struct grub_relocator16_state grub_uint16_t ss; grub_uint16_t sp; grub_uint16_t ip; + grub_uint32_t ebx; grub_uint32_t edx; }; From af36812f5cf8d15cdb00a80681a2918bd07a9765 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 26 Dec 2010 00:57:03 +0100 Subject: [PATCH 160/869] fix a compilation error --- grub-core/loader/i386/pc/freedos.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/grub-core/loader/i386/pc/freedos.c b/grub-core/loader/i386/pc/freedos.c index 67d97e246..0ae815490 100644 --- a/grub-core/loader/i386/pc/freedos.c +++ b/grub-core/loader/i386/pc/freedos.c @@ -97,7 +97,7 @@ grub_cmd_freedos (grub_command_t cmd __attribute__ ((unused)), kernelsyssize = grub_file_size (file); { grub_relocator_chunk_t ch; - err = grub_relocator_alloc_chunk_addr (rel, &ch, GRUB_NTLDR_SEGMENT << 4, + err = grub_relocator_alloc_chunk_addr (rel, &ch, GRUB_FREEDOS_SEGMENT << 4, kernelsyssize); if (err) goto fail; @@ -105,7 +105,7 @@ grub_cmd_freedos (grub_command_t cmd __attribute__ ((unused)), } if (grub_file_read (file, kernelsys, kernelsyssize) - != (grub_ssize_t) ntldrsize) + != (grub_ssize_t) kernelsyssize) goto fail; grub_loader_set (grub_freedos_boot, grub_freedos_unload, 1); @@ -116,7 +116,7 @@ grub_cmd_freedos (grub_command_t cmd __attribute__ ((unused)), if (file) grub_file_close (file); - grub_ntldr_unload (); + grub_freedos_unload (); return grub_errno; } From 5c408d0f50396e832b386e6f7678a5b401dbde84 Mon Sep 17 00:00:00 2001 From: Mirko Parthey Date: Sun, 26 Dec 2010 20:49:08 +0100 Subject: [PATCH 161/869] * grub-core/boot/i386/pc/boot.S: Fix %es:%bx pointing to nowhere on floppy probe. --- ChangeLog | 5 +++++ grub-core/boot/i386/pc/boot.S | 2 ++ 2 files changed, 7 insertions(+) diff --git a/ChangeLog b/ChangeLog index 249ec6bc6..80f5ef568 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2010-12-25 Mirko Parthey + + * grub-core/boot/i386/pc/boot.S: Fix %es:%bx pointing to nowhere on + floppy probe. + 2010-12-25 Jeroen Dekkers * grub-core/disk/raid.c (insert_array): Don't add spurious members. diff --git a/grub-core/boot/i386/pc/boot.S b/grub-core/boot/i386/pc/boot.S index 320918566..635599a24 100644 --- a/grub-core/boot/i386/pc/boot.S +++ b/grub-core/boot/i386/pc/boot.S @@ -459,6 +459,8 @@ fd_probe_error_string: .asciz "Floppy" 1: /* perform read */ movw $GRUB_BOOT_MACHINE_BUFFER_SEG, %bx + movw %bx, %es + xorw %bx, %bx movw $0x201, %ax movb $0, %ch movb $0, %dh From 0b2db94300dca2b7597e3fbf6ade3a1cebd72c19 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 26 Dec 2010 21:15:31 +0100 Subject: [PATCH 162/869] Handling of files of unknown size is currently limited. They can't be used e.g. for initrd or modules. Moreover gzip handling of not easily seekable files is buggy. Disable unknown file size for now. May be inefficient but works. * grub-core/io/gzio.c (test_header): Always retrieve the file size. * grub-core/io/xzio.c (grub_xzio_open): Likewise. --- ChangeLog | 10 ++++++++++ grub-core/io/gzio.c | 25 ++++++++++++------------- grub-core/io/xzio.c | 3 ++- 3 files changed, 24 insertions(+), 14 deletions(-) diff --git a/ChangeLog b/ChangeLog index 80f5ef568..0c701a342 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2010-12-26 Vladimir Serbinenko + + Handling of files of unknown size is currently limited. They can't be + used e.g. for initrd or modules. Moreover gzip handling of not + easily seekable files is buggy. Disable unknown file size for now. May + be inefficient but works. + + * grub-core/io/gzio.c (test_header): Always retrieve the file size. + * grub-core/io/xzio.c (grub_xzio_open): Likewise. + 2010-12-25 Mirko Parthey * grub-core/boot/i386/pc/boot.S: Fix %es:%bx pointing to nowhere on diff --git a/grub-core/io/gzio.c b/grub-core/io/gzio.c index 43b67c373..f563d7b92 100644 --- a/grub-core/io/gzio.c +++ b/grub-core/io/gzio.c @@ -212,19 +212,18 @@ test_header (grub_file_t file) gzio->data_offset = grub_file_tell (gzio->file); - grub_file_seek (gzio->file, grub_file_size (gzio->file) - 4); - - if (grub_file_seekable (gzio->file)) - { - if (grub_file_read (gzio->file, &orig_len, 4) != 4) - { - grub_error (GRUB_ERR_BAD_FILE_TYPE, "unsupported gzip format"); - return 0; - } - } - /* FIXME: this does not handle files whose original size is over 4GB. - But how can we know the real original size? */ - file->size = grub_le_to_cpu32 (orig_len); + /* FIXME: don't do this on not easily seekable files. */ + { + grub_file_seek (gzio->file, grub_file_size (gzio->file) - 4); + if (grub_file_read (gzio->file, &orig_len, 4) != 4) + { + grub_error (GRUB_ERR_BAD_FILE_TYPE, "unsupported gzip format"); + return 0; + } + /* FIXME: this does not handle files whose original size is over 4GB. + But how can we know the real original size? */ + file->size = grub_le_to_cpu32 (orig_len); + } initialize_tables (file); diff --git a/grub-core/io/xzio.c b/grub-core/io/xzio.c index 1a22bdc70..37be1790f 100644 --- a/grub-core/io/xzio.c +++ b/grub-core/io/xzio.c @@ -222,7 +222,8 @@ grub_xzio_open (grub_file_t io) xzio->buf.out_pos = 0; xzio->buf.out_size = XZBUFSIZ; - if (!test_header (file) || !(grub_file_seekable (io) && test_footer (file))) + /* FIXME: don't test footer on not easily seekable files. */ + if (!test_header (file) || !test_footer (file)) { grub_errno = GRUB_ERR_NONE; grub_file_seek (io, 0); From 25dd47804dc8f314ad2061c0d0a50e5827f1de51 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 27 Dec 2010 07:06:41 +0100 Subject: [PATCH 163/869] Don't use disk subsystem in freebsd_boot. * grub-core/loader/i386/bsd.c (freebsd_bootdev): New variable. (freebsd_biosdev): Likewise. (grub_freebsd_boot): Use freebsd_bootdev and freebsd_biosdev. (grub_cmd_freebsd): Set freebsd_bootdev and freebsd_biosdev. --- ChangeLog | 9 +++++++++ grub-core/loader/i386/bsd.c | 17 ++++++++++------- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index 0c701a342..0e4a725a5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2010-12-27 Vladimir Serbinenko + + Don't use disk subsystem in freebsd_boot. + + * grub-core/loader/i386/bsd.c (freebsd_bootdev): New variable. + (freebsd_biosdev): Likewise. + (grub_freebsd_boot): Use freebsd_bootdev and freebsd_biosdev. + (grub_cmd_freebsd): Set freebsd_bootdev and freebsd_biosdev. + 2010-12-26 Vladimir Serbinenko Handling of files of unknown size is currently limited. They can't be diff --git a/grub-core/loader/i386/bsd.c b/grub-core/loader/i386/bsd.c index 91cae418c..84cf1a17f 100644 --- a/grub-core/loader/i386/bsd.c +++ b/grub-core/loader/i386/bsd.c @@ -521,6 +521,8 @@ grub_netbsd_list_modules (void) /* This function would be here but it's under different license. */ #include "bsd_pagetable.c" +static grub_uint32_t freebsd_bootdev, freebsd_biosdev; + static grub_err_t grub_freebsd_boot (void) { @@ -528,7 +530,6 @@ grub_freebsd_boot (void) grub_uint8_t *p, *p0; grub_addr_t p_target; grub_size_t p_size = 0; - grub_uint32_t bootdev, biosdev, unit, slice, part; grub_err_t err; grub_size_t tag_buf_len = 0; @@ -564,11 +565,7 @@ grub_freebsd_boot (void) bi.version = FREEBSD_BOOTINFO_VERSION; bi.length = sizeof (bi); - grub_bsd_get_device (&biosdev, &unit, &slice, &part); - bootdev = (FREEBSD_B_DEVMAGIC + ((slice + 1) << FREEBSD_B_SLICESHIFT) + - (unit << FREEBSD_B_UNITSHIFT) + (part << FREEBSD_B_PARTSHIFT)); - - bi.boot_device = biosdev; + bi.boot_device = freebsd_biosdev; p_size = 0; grub_env_iterate (iterate_env_count); @@ -741,7 +738,7 @@ grub_freebsd_boot (void) state.ebp = stack_target; stack[0] = entry; /* "Return" address. */ stack[1] = bootflags | FREEBSD_RB_BOOTINFO; - stack[2] = bootdev; + stack[2] = freebsd_bootdev; stack[3] = 0; stack[4] = 0; stack[5] = 0; @@ -1371,6 +1368,8 @@ grub_cmd_freebsd (grub_extcmd_context_t ctxt, int argc, char *argv[]) if (grub_bsd_load (argc, argv) == GRUB_ERR_NONE) { + grub_uint32_t unit, slice, part; + kern_end = ALIGN_PAGE (kern_end); if (is_elf_kernel) { @@ -1414,6 +1413,10 @@ grub_cmd_freebsd (grub_extcmd_context_t ctxt, int argc, char *argv[]) if (err) return err; } + grub_bsd_get_device (&freebsd_biosdev, &unit, &slice, &part); + freebsd_bootdev = (FREEBSD_B_DEVMAGIC + ((slice + 1) << FREEBSD_B_SLICESHIFT) + + (unit << FREEBSD_B_UNITSHIFT) + (part << FREEBSD_B_PARTSHIFT)); + grub_loader_set (grub_freebsd_boot, grub_bsd_unload, 0); } From c76386454e2e2214c3082b26ab99f1e733cac5eb Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 27 Dec 2010 07:09:43 +0100 Subject: [PATCH 164/869] Avoid using Reed-Solomon with 0 redundancy. * grub-core/kern/i386/pc/startup.S: Remove 0-data check. * grub-core/lib/reed_solomon.c (decode_block): Do not proceed on 0 data or 0 redundancy. (grub_reed_solomon_add_redundancy): Do not proceed with 0 redundancy. (grub_reed_solomon_recover): Likewise. --- ChangeLog | 10 ++++++++++ grub-core/kern/i386/pc/startup.S | 2 -- grub-core/lib/reed_solomon.c | 16 ++++++++++++++-- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 0e4a725a5..d7606da2a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2010-12-27 Vladimir Serbinenko + + Avoid using Reed-Solomon with 0 redundancy. + + * grub-core/kern/i386/pc/startup.S: Remove 0-data check. + * grub-core/lib/reed_solomon.c (decode_block): Do not proceed on 0 data + or 0 redundancy. + (grub_reed_solomon_add_redundancy): Do not proceed with 0 redundancy. + (grub_reed_solomon_recover): Likewise. + 2010-12-27 Vladimir Serbinenko Don't use disk subsystem in freebsd_boot. diff --git a/grub-core/kern/i386/pc/startup.S b/grub-core/kern/i386/pc/startup.S index 7aebc8b38..e78a0aa9a 100644 --- a/grub-core/kern/i386/pc/startup.S +++ b/grub-core/kern/i386/pc/startup.S @@ -151,8 +151,6 @@ LOCAL (codestart): addl $(GRUB_KERNEL_MACHINE_RAW_SIZE - GRUB_KERNEL_I386_PC_NO_REED_SOLOMON_PART), %edx movl reed_solomon_redundancy, %ecx leal _start + GRUB_KERNEL_I386_PC_NO_REED_SOLOMON_PART, %eax - testl %edx, %edx - jz post_reed_solomon call EXT_C (grub_reed_solomon_recover) jmp post_reed_solomon diff --git a/grub-core/lib/reed_solomon.c b/grub-core/lib/reed_solomon.c index 6f571550a..9a40e2f98 100644 --- a/grub-core/lib/reed_solomon.c +++ b/grub-core/lib/reed_solomon.c @@ -372,6 +372,10 @@ decode_block (gf_single_t *ptr, grub_size_t s, grub_size_t rr = (rs + SECTOR_SIZE - 1 - i) / SECTOR_SIZE; gf_single_t m[ds + rr]; + /* Nothing to do. */ + if (!ds || !rr) + continue; + for (j = 0; j < (int) ds; j++) m[j] = ptr[SECTOR_SIZE * j + i]; for (j = 0; j < (int) rr; j++) @@ -414,6 +418,10 @@ grub_reed_solomon_add_redundancy (void *buffer, grub_size_t data_size, gf_single_t *ptr = buffer; gf_single_t *rptr = ptr + s; + /* Nothing to do. */ + if (!rs) + return; + while (s > 0) { grub_size_t tt; @@ -441,6 +449,10 @@ grub_reed_solomon_recover (void *ptr_, grub_size_t s, grub_size_t rs) gf_single_t *ptr = ptr_; gf_single_t *rptr = ptr + s; + /* Nothing to do. */ + if (!rs) + return; + #if defined (STANDALONE) init_inverts (); #endif @@ -454,8 +466,8 @@ grub_reed_solomon_recover (void *ptr_, grub_size_t s, grub_size_t rs) tt = cs + crs; if (tt > MAX_BLOCK_SIZE) { - cs = cs * MAX_BLOCK_SIZE / tt; - crs = crs * MAX_BLOCK_SIZE / tt; + cs = (cs * MAX_BLOCK_SIZE) / tt; + crs = (crs * MAX_BLOCK_SIZE) / tt; } decode_block (ptr, cs, rptr, crs); ptr += cs; From 693db2df5615ce6297031e04361b7bcb4b0fd571 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 27 Dec 2010 07:18:24 +0100 Subject: [PATCH 165/869] * grub-core/loader/xnu.c (grub_cmd_xnu_kext): Abort if no kernel is loaded (grub_cmd_xnu_kextdir): Likewise. (grub_cmd_xnu_splash): Likewise. --- ChangeLog | 7 +++++++ grub-core/loader/xnu.c | 10 ++++++++++ 2 files changed, 17 insertions(+) diff --git a/ChangeLog b/ChangeLog index d7606da2a..31aa19bad 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2010-12-27 Vladimir Serbinenko + + * grub-core/loader/xnu.c (grub_cmd_xnu_kext): Abort if no kernel + is loaded + (grub_cmd_xnu_kextdir): Likewise. + (grub_cmd_xnu_splash): Likewise. + 2010-12-27 Vladimir Serbinenko Avoid using Reed-Solomon with 0 redundancy. diff --git a/grub-core/loader/xnu.c b/grub-core/loader/xnu.c index d0b32dc6f..02151dd9c 100644 --- a/grub-core/loader/xnu.c +++ b/grub-core/loader/xnu.c @@ -1198,6 +1198,10 @@ grub_cmd_xnu_kext (grub_command_t cmd __attribute__ ((unused)), int argc, char *args[]) { grub_file_t binfile = 0; + + if (! grub_xnu_heap_size) + return grub_error (GRUB_ERR_BAD_OS, "no xnu kernel loaded"); + if (argc == 2) { /* User explicitly specified plist and binary. */ @@ -1229,6 +1233,9 @@ grub_cmd_xnu_kextdir (grub_command_t cmd __attribute__ ((unused)), if (argc != 1 && argc != 2) return grub_error (GRUB_ERR_BAD_ARGUMENT, "directory name required"); + if (! grub_xnu_heap_size) + return grub_error (GRUB_ERR_BAD_OS, "no xnu kernel loaded"); + if (argc == 1) return grub_xnu_scan_dir_for_kexts (args[0], "console,root,local-root,network-root", @@ -1370,6 +1377,9 @@ grub_cmd_xnu_splash (grub_extcmd_context_t ctxt, if (argc != 1) return grub_error (GRUB_ERR_BAD_ARGUMENT, "file name required"); + if (! grub_xnu_heap_size) + return grub_error (GRUB_ERR_BAD_OS, "no xnu kernel loaded"); + if (ctxt->state[XNU_SPLASH_CMD_ARGINDEX_MODE].set && grub_strcmp (ctxt->state[XNU_SPLASH_CMD_ARGINDEX_MODE].arg, "stretch") == 0) From 14b48a19c21667755e3080b5aa4bf231693d7346 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 27 Dec 2010 07:19:51 +0100 Subject: [PATCH 166/869] * grub-core/loader/xnu.c (grub_cmd_xnu_kernel) [! GRUB_MACHINE_EFI]: Preload EFIemu. (grub_cmd_xnu_kernel64) [! GRUB_MACHINE_EFI]: Likewise. --- ChangeLog | 6 ++++++ grub-core/loader/xnu.c | 16 ++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/ChangeLog b/ChangeLog index 31aa19bad..9c1d85dcd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2010-12-27 Vladimir Serbinenko + + * grub-core/loader/xnu.c (grub_cmd_xnu_kernel) [! GRUB_MACHINE_EFI]: + Preload EFIemu. + (grub_cmd_xnu_kernel64) [! GRUB_MACHINE_EFI]: Likewise. + 2010-12-27 Vladimir Serbinenko * grub-core/loader/xnu.c (grub_cmd_xnu_kext): Abort if no kernel diff --git a/grub-core/loader/xnu.c b/grub-core/loader/xnu.c index 02151dd9c..95857951a 100644 --- a/grub-core/loader/xnu.c +++ b/grub-core/loader/xnu.c @@ -34,6 +34,10 @@ #include #include +#if defined (__i386) && !defined (GRUB_MACHINE_EFI) +#include +#endif + struct grub_xnu_devtree_key *grub_xnu_devtree_root = 0; static int driverspackagenum = 0; static int driversnum = 0; @@ -424,6 +428,12 @@ grub_cmd_xnu_kernel (grub_command_t cmd __attribute__ ((unused)), if (ptr != grub_xnu_cmdline) *(ptr - 1) = 0; +#if defined (__i386) && !defined (GRUB_MACHINE_EFI) + err = grub_efiemu_autocore (); + if (err) + return err; +#endif + grub_loader_set (grub_xnu_boot, grub_xnu_unload, 0); grub_xnu_lock (); @@ -529,6 +539,12 @@ grub_cmd_xnu_kernel64 (grub_command_t cmd __attribute__ ((unused)), if (ptr != grub_xnu_cmdline) *(ptr - 1) = 0; +#if defined (__i386) && !defined (GRUB_MACHINE_EFI) + err = grub_efiemu_autocore (); + if (err) + return err; +#endif + grub_loader_set (grub_xnu_boot, grub_xnu_unload, 0); grub_xnu_lock (); From b12b923e6335dd87944b49de08a021fac0c04b1b Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 31 Dec 2010 12:37:35 +0100 Subject: [PATCH 167/869] * grub-core/loader/i386/bsdXX.c (grub_openbsd_find_ramdisk): Silence spurious warning. Reported by: crocket --- ChangeLog | 6 ++++++ grub-core/loader/i386/bsdXX.c | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 9c1d85dcd..dae48b0e6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2010-12-31 Vladimir Serbinenko + + * grub-core/loader/i386/bsdXX.c (grub_openbsd_find_ramdisk): Silence + spurious warning. + Reported by: crocket + 2010-12-27 Vladimir Serbinenko * grub-core/loader/xnu.c (grub_cmd_xnu_kernel) [! GRUB_MACHINE_EFI]: diff --git a/grub-core/loader/i386/bsdXX.c b/grub-core/loader/i386/bsdXX.c index 29892e5fb..2dd180509 100644 --- a/grub-core/loader/i386/bsdXX.c +++ b/grub-core/loader/i386/bsdXX.c @@ -511,7 +511,7 @@ SUFFIX(grub_openbsd_find_ramdisk) (grub_file_t file, grub_err_t err; Elf_Ehdr e; Elf_Shdr *s; - char *shdr; + char *shdr = NULL; err = read_headers (file, &e, &shdr); if (err) From 307806cb53c3e5ef0dd15b8e8aba23b354b42416 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 31 Dec 2010 14:55:55 +0100 Subject: [PATCH 168/869] * grub-core/partmap/amiga.c (GRUB_AMIGA_RDSK_MAGIC): New define. (amiga_partition_map_iterate): Use grub_memcmp instead of grub_strcmp. Reported by:EHeM. --- ChangeLog | 6 ++++++ grub-core/partmap/amiga.c | 4 +++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index dae48b0e6..c9339e164 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2010-12-31 Vladimir Serbinenko + + * grub-core/partmap/amiga.c (GRUB_AMIGA_RDSK_MAGIC): New define. + (amiga_partition_map_iterate): Use grub_memcmp instead of grub_strcmp. + Reported by:EHeM. + 2010-12-31 Vladimir Serbinenko * grub-core/loader/i386/bsdXX.c (grub_openbsd_find_ramdisk): Silence diff --git a/grub-core/partmap/amiga.c b/grub-core/partmap/amiga.c index f21c5b243..a3ea3499c 100644 --- a/grub-core/partmap/amiga.c +++ b/grub-core/partmap/amiga.c @@ -27,6 +27,7 @@ struct grub_amiga_rdsk { /* "RDSK". */ grub_uint8_t magic[4]; +#define GRUB_AMIGA_RDSK_MAGIC "RDSK" grub_uint32_t size; grub_int32_t checksum; grub_uint32_t scsihost; @@ -87,7 +88,8 @@ amiga_partition_map_iterate (grub_disk_t disk, if (grub_disk_read (disk, pos, 0, sizeof (rdsk), &rdsk)) return grub_errno; - if (grub_strcmp ((char *) rdsk.magic, "RDSK") == 0) + if (grub_memcmp (rdsk.magic, GRUB_AMIGA_RDSK_MAGIC, + sizeof (rdsk.magic)) == 0) { /* Found the first PART block. */ next = grub_be_to_cpu32 (rdsk.partitionlst); From 275bff5f000f1d424dd86841f10ef79d4fc6c665 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 31 Dec 2010 15:00:45 +0100 Subject: [PATCH 169/869] * grub-core/partmap/amiga.c (GRUB_AMIGA_PART_MAGIC): New define. (amiga_partition_map_iterate): Check "PART" magic to avoid a very long loop in case of incorrect amiga partmap. --- ChangeLog | 6 ++++++ grub-core/partmap/amiga.c | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/ChangeLog b/ChangeLog index c9339e164..505c1cc0d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2010-12-31 Vladimir Serbinenko + + * grub-core/partmap/amiga.c (GRUB_AMIGA_PART_MAGIC): New define. + (amiga_partition_map_iterate): Check "PART" magic to avoid a very long + loop in case of incorrect amiga partmap. + 2010-12-31 Vladimir Serbinenko * grub-core/partmap/amiga.c (GRUB_AMIGA_RDSK_MAGIC): New define. diff --git a/grub-core/partmap/amiga.c b/grub-core/partmap/amiga.c index a3ea3499c..1e0f23402 100644 --- a/grub-core/partmap/amiga.c +++ b/grub-core/partmap/amiga.c @@ -44,6 +44,7 @@ struct grub_amiga_partition { /* "PART". */ grub_uint8_t magic[4]; +#define GRUB_AMIGA_PART_MAGIC "PART" grub_int32_t size; grub_int32_t checksum; grub_uint32_t scsihost; @@ -110,6 +111,9 @@ amiga_partition_map_iterate (grub_disk_t disk, if (grub_disk_read (disk, next, 0, sizeof (apart), &apart)) return grub_errno; + if (grub_memcmp (apart.magic, GRUB_AMIGA_PART_MAGIC, + sizeof (apart.magic)) == 0) + /* Calculate the first block and the size of the partition. */ part.start = (grub_be_to_cpu32 (apart.lowcyl) * grub_be_to_cpu32 (apart.heads) From b9cd13659cce5dd2414e962c02042c9ece90b918 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 31 Dec 2010 15:22:36 +0100 Subject: [PATCH 170/869] Simplify the AFFS checksum computation. --- grub-core/fs/affs.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/grub-core/fs/affs.c b/grub-core/fs/affs.c index e4b487a7e..e05c166a9 100644 --- a/grub-core/fs/affs.c +++ b/grub-core/fs/affs.c @@ -174,7 +174,6 @@ grub_affs_mount (grub_disk_t disk) struct grub_affs_rblock *rblock; int checksum = 0; - int checksumr = 0; int blocksize = 0; data = grub_malloc (sizeof (struct grub_affs_data)); @@ -224,8 +223,6 @@ grub_affs_mount (grub_disk_t disk) /* The filesystem blocksize is not stored anywhere in the filesystem itself. One way to determine it is reading blocks for the rootblock until the checksum is correct. */ - checksumr = grub_be_to_cpu32 (rblock->checksum); - rblock->checksum = 0; for (blocksize = 0; blocksize < 8; blocksize++) { grub_uint32_t *currblock = rootblock + GRUB_DISK_SECTOR_SIZE * blocksize; @@ -234,10 +231,10 @@ grub_affs_mount (grub_disk_t disk) for (i = 0; i < GRUB_DISK_SECTOR_SIZE / sizeof (*currblock); i++) checksum += grub_be_to_cpu32 (currblock[i]); - if (checksumr == -checksum) + if (checksum == 0) break; } - if (-checksum != checksumr) + if (checksum != 0) { grub_error (GRUB_ERR_BAD_FS, "AFFS blocksize couldn't be determined"); goto fail; From fb17547ca89991f33d269cc01af711e198ab1eb0 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 31 Dec 2010 15:23:06 +0100 Subject: [PATCH 171/869] Check amiga partmap checksum --- grub-core/partmap/amiga.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/grub-core/partmap/amiga.c b/grub-core/partmap/amiga.c index 1e0f23402..803e2e14f 100644 --- a/grub-core/partmap/amiga.c +++ b/grub-core/partmap/amiga.c @@ -37,7 +37,7 @@ struct grub_amiga_rdsk grub_uint32_t partitionlst; grub_uint32_t fslst; - /* The other information is not important for us. */ + grub_uint32_t unused[128 - 9]; } __attribute__ ((packed)); struct grub_amiga_partition @@ -65,12 +65,24 @@ struct grub_amiga_partition grub_uint32_t highcyl; grub_uint32_t firstcyl; + grub_uint32_t unused[128 - 44]; } __attribute__ ((packed)); static struct grub_partition_map grub_amiga_partition_map; +static grub_uint32_t +amiga_partition_map_checksum (void *buf, grub_size_t sz) +{ + grub_uint32_t *ptr = buf; + grub_uint32_t r = 0; + sz /= sizeof (grub_uint32_t); + for (; sz; sz--, ptr++) + r += grub_be_to_cpu32 (*ptr); + return r; +} + static grub_err_t amiga_partition_map_iterate (grub_disk_t disk, int (*hook) (grub_disk_t disk, @@ -90,7 +102,8 @@ amiga_partition_map_iterate (grub_disk_t disk, return grub_errno; if (grub_memcmp (rdsk.magic, GRUB_AMIGA_RDSK_MAGIC, - sizeof (rdsk.magic)) == 0) + sizeof (rdsk.magic)) == 0 + && amiga_partition_map_checksum (&rdsk, sizeof (rdsk)) == 0) { /* Found the first PART block. */ next = grub_be_to_cpu32 (rdsk.partitionlst); @@ -112,7 +125,8 @@ amiga_partition_map_iterate (grub_disk_t disk, return grub_errno; if (grub_memcmp (apart.magic, GRUB_AMIGA_PART_MAGIC, - sizeof (apart.magic)) == 0) + sizeof (apart.magic)) == 0 + && amiga_partition_map_checksum (&apart, sizeof (apart)) == 0) /* Calculate the first block and the size of the partition. */ part.start = (grub_be_to_cpu32 (apart.lowcyl) From 1b394975e927af0533d42fc516dfc36d57a6692b Mon Sep 17 00:00:00 2001 From: Ian Campbell Date: Fri, 31 Dec 2010 22:49:42 +0000 Subject: [PATCH 172/869] * util/grub.d/20_linux_xen.in (linux_entry): Correctly capitalize Xen and reorder menu item wording to make it clearer that this entry will launch Xen. Print separate messages when loading Xen and Linux. --- ChangeLog | 7 +++++++ util/grub.d/20_linux_xen.in | 12 +++++++----- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 505c1cc0d..9881baee9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2010-12-31 Ian Campbell + + * util/grub.d/20_linux_xen.in (linux_entry): Correctly capitalize + Xen and reorder menu item wording to make it clearer that this entry + will launch Xen. Print separate messages when loading Xen and + Linux. + 2010-12-31 Vladimir Serbinenko * grub-core/partmap/amiga.c (GRUB_AMIGA_PART_MAGIC): New define. diff --git a/util/grub.d/20_linux_xen.in b/util/grub.d/20_linux_xen.in index a90211f44..ee49cd903 100644 --- a/util/grub.d/20_linux_xen.in +++ b/util/grub.d/20_linux_xen.in @@ -60,11 +60,11 @@ linux_entry () args="$5" xen_args="$6" if ${recovery} ; then - title="$(gettext_quoted "%s, with Linux %s and XEN %s (recovery mode)")" + title="$(gettext_quoted "%s, with Xen %s and Linux %s (recovery mode)")" else - title="$(gettext_quoted "%s, with Linux %s and XEN %s")" + title="$(gettext_quoted "%s, with Xen %s and Linux %s")" fi - printf "menuentry '${title}' ${CLASS} {\n" "${os}" "${version}" "${xen_version}" + printf "menuentry '${title}' ${CLASS} {\n" "${os}" "${xen_version}" "${version}" if ! ${recovery} ; then save_default_entry | sed -e "s/^/\t/" fi @@ -73,10 +73,12 @@ linux_entry () prepare_boot_cache="$(prepare_grub_to_access_device ${GRUB_DEVICE_BOOT} | sed -e "s/^/\t/")" fi printf '%s\n' "${prepare_boot_cache}" - message="$(gettext_printf "Loading Linux %s ..." ${version})" + xmessage="$(gettext_printf "Loading Xen %s ..." ${xen_version})" + lmessage="$(gettext_printf "Loading Linux %s ..." ${version})" cat << EOF - echo '$message' + echo '$xmessage' multiboot ${rel_xen_dirname}/${xen_basename} placeholder ${xen_args} + echo '$lmessage' module ${rel_dirname}/${basename} placeholder root=${linux_root_device_thisversion} ro ${args} EOF if test -n "${initrd}" ; then From 3a04c65d008246c29d8a0b86fb66770ac6d6634f Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 1 Jan 2011 15:13:03 +0100 Subject: [PATCH 173/869] Always add libgcc.h --- grub-core/Makefile.am | 4 +--- include/grub/libgcc.h | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/grub-core/Makefile.am b/grub-core/Makefile.am index 5d13d0313..7fa00b744 100644 --- a/grub-core/Makefile.am +++ b/grub-core/Makefile.am @@ -74,6 +74,7 @@ KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/term.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/time.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/mm_private.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/boot.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/libgcc.h if COND_i386_pc KERNEL_HEADER_FILES += $(top_builddir)/include/grub/machine/memory.h @@ -132,7 +133,6 @@ KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/font.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/bitmap_scale.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/bufio.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/pci.h -KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/libgcc.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/cs5536.h KERNEL_HEADER_FILES += $(top_builddir)/include/grub/machine/pci.h KERNEL_HEADER_FILES += $(top_builddir)/include/grub/serial.h @@ -140,11 +140,9 @@ endif if COND_powerpc_ieee1275 KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/ieee1275/ieee1275.h -KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/libgcc.h endif if COND_sparc64_ieee1275 -KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/libgcc.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/ieee1275/ieee1275.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/sparc64/ieee1275/ieee1275.h endif diff --git a/include/grub/libgcc.h b/include/grub/libgcc.h index 703182577..100c8667b 100644 --- a/include/grub/libgcc.h +++ b/include/grub/libgcc.h @@ -53,7 +53,7 @@ void EXPORT_FUNC (__udivdi3) (void); # ifdef HAVE___DIVSI3 void EXPORT_FUNC (__divsi3) (void); # endif -# ifdef HAVE___UMODSI3 +# ifdef HAVE___MODSI3 void EXPORT_FUNC (__modsi3) (void); # endif #endif From 52f65ea0bc9c3d36a0691a330eb2131df7cacc6d Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 1 Jan 2011 15:28:39 +0100 Subject: [PATCH 174/869] add moddi3 and divdi3 --- configure.ac | 2 +- include/grub/libgcc.h | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index ca886b5dc..4c710748c 100644 --- a/configure.ac +++ b/configure.ac @@ -542,7 +542,7 @@ CFLAGS="$CFLAGS -Wl,--defsym,abort=main" fi # Check for libgcc symbols -AC_CHECK_FUNCS(__bswapsi2 __bswapdi2 __ashldi3 __ashrdi3 __lshrdi3 __trampoline_setup __ucmpdi2 _restgpr_14_x __ia64_trampoline __udivsi3 __umoddi3 __udivdi3 __divsi3 __modsi3 __umodsi3) +AC_CHECK_FUNCS(__bswapsi2 __bswapdi2 __ashldi3 __ashrdi3 __lshrdi3 __trampoline_setup __ucmpdi2 _restgpr_14_x __ia64_trampoline __udivsi3 __umoddi3 __udivdi3 __divsi3 __modsi3 __umodsi3 __moddi3 __divdi3) if test "x$TARGET_APPLE_CC" = x1 ; then CFLAGS="$TARGET_CFLAGS -nostdlib" diff --git a/include/grub/libgcc.h b/include/grub/libgcc.h index 100c8667b..be600220e 100644 --- a/include/grub/libgcc.h +++ b/include/grub/libgcc.h @@ -50,6 +50,12 @@ void EXPORT_FUNC (__umoddi3) (void); # ifdef HAVE___UDIVDI3 void EXPORT_FUNC (__udivdi3) (void); # endif +# ifdef HAVE___MODDI3 +void EXPORT_FUNC (__moddi3) (void); +# endif +# ifdef HAVE___DIVDI3 +void EXPORT_FUNC (__divdi3) (void); +# endif # ifdef HAVE___DIVSI3 void EXPORT_FUNC (__divsi3) (void); # endif From 6f49d0aacb1a26d756faa849ea5b18d1322091d5 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 1 Jan 2011 15:53:31 +0100 Subject: [PATCH 175/869] Add missing cache.c --- grub-core/Makefile.core.def | 1 + grub-core/kern/emu/cache.c | 10 ++++++++++ 2 files changed, 11 insertions(+) create mode 100644 grub-core/kern/emu/cache.c diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def index b953adfb9..801ad6d7c 100644 --- a/grub-core/Makefile.core.def +++ b/grub-core/Makefile.core.def @@ -158,6 +158,7 @@ kernel = { emu = kern/emu/misc.c; emu = kern/emu/mm.c; emu = kern/emu/time.c; + emu = kern/emu/cache.c; videoinkernel = lib/arg.c; videoinkernel = term/gfxterm.c; diff --git a/grub-core/kern/emu/cache.c b/grub-core/kern/emu/cache.c new file mode 100644 index 000000000..bdff146ef --- /dev/null +++ b/grub-core/kern/emu/cache.c @@ -0,0 +1,10 @@ + +#include + +void __clear_cache (char *beg, char *end); + +void +grub_arch_sync_caches (void *address, grub_size_t len) +{ + __clear_cache (address, (char *) address + len); +} From f9c30af6d08a6d2b0c3e831d116c37dc1d1d7c78 Mon Sep 17 00:00:00 2001 From: phcoder Date: Sun, 2 Jan 2011 14:09:58 +0100 Subject: [PATCH 176/869] Succesfully loaded return-only module on ia64-emu --- grub-core/kern/dl.c | 49 ++++++- grub-core/kern/emu/cache.S | 1 + grub-core/kern/emu/cache.c | 3 + grub-core/kern/emu/full.c | 9 ++ grub-core/kern/emu/lite.c | 2 + grub-core/kern/ia64/dl.c | 288 +++++++++++++++++++++++++++++++++++++ include/grub/dl.h | 20 ++- include/grub/types.h | 3 + 8 files changed, 368 insertions(+), 7 deletions(-) create mode 100644 grub-core/kern/ia64/dl.c diff --git a/grub-core/kern/dl.c b/grub-core/kern/dl.c index 02d785b9b..2f2493fca 100644 --- a/grub-core/kern/dl.c +++ b/grub-core/kern/dl.c @@ -37,6 +37,10 @@ #define GRUB_MODULES_MACHINE_READONLY #endif +#ifdef GRUB_MACHINE_EMU +#include +#endif + grub_dl_t grub_dl_head = 0; @@ -233,11 +237,24 @@ grub_dl_load_segments (grub_dl_t mod, const Elf_Ehdr *e) if (s->sh_flags & SHF_ALLOC) { grub_dl_segment_t seg; + grub_size_t tramp_size = 0; seg = (grub_dl_segment_t) grub_malloc (sizeof (*seg)); if (! seg) return grub_errno; + tramp_size = grub_arch_dl_get_tramp_size (e, i); + if (tramp_size && s->sh_addralign < GRUB_ARCH_DL_TRAMP_ALIGN) + { + s->sh_addralign = GRUB_ARCH_DL_TRAMP_ALIGN; + s->sh_size = ALIGN_UP (s->sh_size, GRUB_ARCH_DL_TRAMP_ALIGN) + tramp_size; + } +#ifdef GRUB_MACHINE_EMU + if (s->sh_addralign < 8192) + s->sh_addralign = 8192; + s->sh_size = ALIGN_UP (s->sh_size, 8192); +#endif + if (s->sh_size) { void *addr; @@ -260,6 +277,10 @@ grub_dl_load_segments (grub_dl_t mod, const Elf_Ehdr *e) } seg->addr = addr; +#ifdef GRUB_MACHINE_EMU + if (s->sh_flags & SHF_EXECINSTR) + mprotect (addr, s->sh_size, PROT_READ | PROT_WRITE | PROT_EXEC); +#endif } else seg->addr = 0; @@ -343,9 +364,9 @@ grub_dl_resolve_symbols (grub_dl_t mod, Elf_Ehdr *e) return grub_errno; if (grub_strcmp (name, "grub_mod_init") == 0) - mod->init = (void (*) (grub_dl_t)) sym->st_value; + mod->init = sym->st_value; else if (grub_strcmp (name, "grub_mod_fini") == 0) - mod->fini = (void (*) (void)) sym->st_value; + mod->fini = sym->st_value; break; case STT_SECTION: @@ -370,7 +391,16 @@ static void grub_dl_call_init (grub_dl_t mod) { if (mod->init) - (mod->init) (mod); + { +#ifndef __ia64__ + ((void (*) (grub_dl_t)) mod->init) (mod); +#else + char *jmp[2]; + jmp[0] = (char *) mod->init; + jmp[1] = mod->gp; + ((void (*) (grub_dl_t)) jmp) (mod); +#endif + } } static grub_err_t @@ -533,7 +563,7 @@ grub_dl_load_core (void *addr, grub_size_t size) grub_dl_flush_cache (mod); grub_dprintf ("modules", "module name: %s\n", mod->name); - grub_dprintf ("modules", "init function: %p\n", mod->init); + grub_dprintf ("modules", "init function: %" PRIxGRUB_ADDR "\n", mod->init); grub_dl_call_init (mod); if (grub_dl_add (mod)) @@ -633,7 +663,16 @@ grub_dl_unload (grub_dl_t mod) return 0; if (mod->fini) - (mod->fini) (); + { +#ifndef __ia64__ + ((void (*) (void)) mod->fini) (); +#else + char *jmp[2]; + jmp[0] = (char *) mod->fini; + jmp[1] = mod->gp; + ((void (*) (void)) jmp) (); +#endif + } grub_dl_remove (mod); grub_dl_unregister_symbols (mod); diff --git a/grub-core/kern/emu/cache.S b/grub-core/kern/emu/cache.S index 90a5b5396..99637762a 100644 --- a/grub-core/kern/emu/cache.S +++ b/grub-core/kern/emu/cache.S @@ -10,6 +10,7 @@ #include "../mips/cache.S" #elif defined(__powerpc__) #include "../powerpc/cache.S" +#elif defined(__ia64__) #else #error "No target cpu type is defined" #endif diff --git a/grub-core/kern/emu/cache.c b/grub-core/kern/emu/cache.c index bdff146ef..543e457e5 100644 --- a/grub-core/kern/emu/cache.c +++ b/grub-core/kern/emu/cache.c @@ -1,4 +1,5 @@ +#if defined(__ia64__) #include void __clear_cache (char *beg, char *end); @@ -8,3 +9,5 @@ grub_arch_sync_caches (void *address, grub_size_t len) { __clear_cache (address, (char *) address + len); } +#endif + diff --git a/grub-core/kern/emu/full.c b/grub-core/kern/emu/full.c index 0bd33337f..0396d0ab4 100644 --- a/grub-core/kern/emu/full.c +++ b/grub-core/kern/emu/full.c @@ -48,3 +48,12 @@ grub_emu_init (void) { grub_no_autoload = 1; } + +#ifdef __ia64__ +grub_size_t +grub_arch_dl_get_tramp_size (const void *ehdr __attribute__ ((unused)), + unsigned sec __attribute__ ((unused))) +{ + return ~(grub_size_t)0; +} +#endif diff --git a/grub-core/kern/emu/lite.c b/grub-core/kern/emu/lite.c index 9b3728717..5d3588bd0 100644 --- a/grub-core/kern/emu/lite.c +++ b/grub-core/kern/emu/lite.c @@ -15,6 +15,8 @@ #include "../mips/dl.c" #elif defined(__powerpc__) #include "../powerpc/dl.c" +#elif defined(__ia64__) +#include "../ia64/dl.c" #else #error "No target cpu type is defined" #endif diff --git a/grub-core/kern/ia64/dl.c b/grub-core/kern/ia64/dl.c new file mode 100644 index 000000000..2b87577a4 --- /dev/null +++ b/grub-core/kern/ia64/dl.c @@ -0,0 +1,288 @@ +/* dl.c - arch-dependent part of loadable module support */ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2002,2004,2005,2007,2009 Free Software Foundation, Inc. + * + * GRUB is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see . + */ + +#include +#include +#include +#include +#include + +/* Check if EHDR is a valid ELF header. */ +grub_err_t +grub_arch_dl_check_header (void *ehdr) +{ + Elf_Ehdr *e = ehdr; + + /* Check the magic numbers. */ + if (e->e_ident[EI_CLASS] != ELFCLASS64 + || e->e_ident[EI_DATA] != ELFDATA2LSB + || e->e_machine != EM_IA_64) + return grub_error (GRUB_ERR_BAD_OS, "invalid arch specific ELF magic"); + + return GRUB_ERR_NONE; +} + +#define MASK20 ((1 << 20) - 1) +#define MASK19 ((1 << 19) - 1) + +static void +add_value_to_slot13_20 (Elf_Word *addr, grub_uint32_t value, int slot) +{ + grub_uint32_t *p __attribute__ ((aligned (1))); + switch (slot) + { + case 0: + p = (grub_uint32_t *) (addr + 2); + *p = (((((*p >> 2) & MASK20) + value) & MASK20) << 2) | (*p & ~(MASK20 << 2)); + break; + case 1: + p = (grub_uint32_t *) ((grub_uint8_t *) addr + 7); + *p = (((((*p >> 3) & MASK20) + value) & MASK20) << 3) | (*p & ~(MASK20 << 3)); + break; + case 2: + p = (grub_uint32_t *) ((grub_uint8_t *) addr + 12); + *p = (((((*p >> 4) & MASK20) + value) & MASK20) << 4) | (*p & ~(MASK20 << 4)); + break; + } +} + +static grub_uint8_t nopm[5] = + { + /* [MLX] nop.m 0x0 */ + 0x05, 0x00, 0x00, 0x00, 0x01 + }; + +static grub_uint8_t jump[0x20] = + { + /* ld8 r16=[r15],8 */ + 0x02, 0x80, 0x20, 0x1e, 0x18, 0x14, + /* mov r14=r1;; */ + 0xe0, 0x00, 0x04, 0x00, 0x42, 0x00, + /* nop.i 0x0 */ + 0x00, 0x00, 0x04, 0x00, + /* ld8 r1=[r15] */ + 0x11, 0x08, 0x00, 0x1e, 0x18, 0x10, + /* mov b6=r16 */ + 0x60, 0x80, 0x04, 0x80, 0x03, 0x00, + /* br.few b6;; */ + 0x60, 0x00, 0x80, 0x00 + }; + +struct ia64_trampoline +{ + /* nop.m */ + grub_uint8_t nop[5]; + /* movl r15 = addr*/ + grub_uint8_t addr_hi[6]; + grub_uint8_t e0; + grub_uint8_t addr_lo[4]; + grub_uint8_t jump[0x20]; +}; + +static void +make_trampoline (struct ia64_trampoline *tr, grub_uint64_t addr) +{ + grub_memcpy (tr->nop, nopm, sizeof (tr->nop)); + tr->addr_hi[0] = ((addr & 0xc00000) >> 18); + tr->addr_hi[1] = (addr >> 24) & 0xff; + tr->addr_hi[2] = (addr >> 32) & 0xff; + tr->addr_hi[3] = (addr >> 40) & 0xff; + tr->addr_hi[4] = (addr >> 48) & 0xff; + tr->addr_hi[5] = (addr >> 56) & 0xff; + tr->e0 = 0xe0; + tr->addr_lo[0] = ((addr & 0x000f) << 4) | 0x01; + tr->addr_lo[1] = ((addr & 0x0070) >> 4) | ((addr & 0x070000) >> 11) | ((addr & 0x200000) >> 17); + tr->addr_lo[2] = ((addr & 0x1f80) >> 5) | ((addr & 0x180000) >> 19); + tr->addr_lo[3] = ((addr & 0xe000) >> 13) | 0x60; + grub_memcpy (tr->jump, jump, sizeof (tr->jump)); +} + +grub_size_t +grub_arch_dl_get_tramp_size (const void *ehdr, unsigned sec) +{ + const Elf_Ehdr *e = ehdr; + int cnt = 0; + const Elf_Shdr *s; + Elf_Word entsize; + unsigned i; + + /* Find a symbol table. */ + for (i = 0, s = (Elf_Shdr *) ((char *) e + e->e_shoff); + i < e->e_shnum; + i++, s = (Elf_Shdr *) ((char *) s + e->e_shentsize)) + if (s->sh_type == SHT_SYMTAB) + break; + + if (i == e->e_shnum) + return 0; + + entsize = s->sh_entsize; + + for (i = 0, s = (Elf_Shdr *) ((char *) e + e->e_shoff); + i < e->e_shnum; + i++, s = (Elf_Shdr *) ((char *) s + e->e_shentsize)) + if (s->sh_type == SHT_RELA) + { + Elf_Rela *rel, *max; + + if (s->sh_info != sec) + continue; + + for (rel = (Elf_Rela *) ((char *) e + s->sh_offset), + max = rel + s->sh_size / s->sh_entsize; + rel < max; rel++) + if (ELF_R_TYPE (rel->r_info) == R_IA64_PCREL21B) + cnt++; + } + + return cnt * sizeof (struct ia64_trampoline); +} + +/* Relocate symbols. */ +grub_err_t +grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr) +{ + Elf_Ehdr *e = ehdr; + Elf_Shdr *s; + Elf_Word entsize; + unsigned i; + grub_uint64_t *gp, *gpptr; + grub_size_t gp_size = 0; + + for (i = 0, s = (Elf_Shdr *) ((char *) e + e->e_shoff); + i < e->e_shnum; + i++, s = (Elf_Shdr *) ((char *) s + e->e_shentsize)) + if (s->sh_type == SHT_REL) + { + grub_dl_segment_t seg; + + /* Find the target segment. */ + for (seg = mod->segment; seg; seg = seg->next) + if (seg->section == s->sh_info) + break; + + if (seg) + { + Elf_Rel *rel, *max; + + for (rel = (Elf_Rel *) ((char *) e + s->sh_offset), + max = rel + s->sh_size / s->sh_entsize; + rel < max; + rel++) + switch (ELF_R_TYPE (rel->r_info)) + { + default: break; + } + } + } + + if (gp_size > MASK19) + return grub_error (GRUB_ERR_OUT_OF_RANGE, "gp too big"); + + gpptr = gp = grub_malloc (gp_size); + if (!gp) + return grub_errno; + mod->gp = (char *) gp; + + /* Find a symbol table. */ + for (i = 0, s = (Elf_Shdr *) ((char *) e + e->e_shoff); + i < e->e_shnum; + i++, s = (Elf_Shdr *) ((char *) s + e->e_shentsize)) + if (s->sh_type == SHT_SYMTAB) + break; + + if (i == e->e_shnum) + return grub_error (GRUB_ERR_BAD_MODULE, "no symtab found"); + + entsize = s->sh_entsize; + + for (i = 0, s = (Elf_Shdr *) ((char *) e + e->e_shoff); + i < e->e_shnum; + i++, s = (Elf_Shdr *) ((char *) s + e->e_shentsize)) + if (s->sh_type == SHT_RELA) + { + grub_dl_segment_t seg; + + /* Find the target segment. */ + for (seg = mod->segment; seg; seg = seg->next) + if (seg->section == s->sh_info) + break; + + if (seg) + { + Elf_Rela *rel, *max; + struct ia64_trampoline *tr; + + for (rel = (Elf_Rela *) ((char *) e + s->sh_offset), + max = rel + s->sh_size / s->sh_entsize; + rel < max; + rel++) + { + Elf_Word *addr; + Elf_Sym *sym; + grub_uint64_t value; + int slot = 0; + + if (seg->size < (rel->r_offset & ~3)) + return grub_error (GRUB_ERR_BAD_MODULE, + "reloc offset is out of the segment"); + + tr = (void *) ((char *) seg->addr + ALIGN_UP (seg->size, GRUB_ARCH_DL_TRAMP_ALIGN)); + + if (ELF_R_TYPE (rel->r_info) == R_IA64_PCREL21B) + { + addr = (Elf_Word *) ((char *) seg->addr + (rel->r_offset & ~3)); + slot = rel->r_offset & 3; + } + else + addr = (Elf_Word *) ((char *) seg->addr + rel->r_offset); + sym = (Elf_Sym *) ((char *) mod->symtab + + entsize * ELF_R_SYM (rel->r_info)); + + /* On the PPC the value does not have an explicit + addend, add it. */ + value = sym->st_value + rel->r_addend; + switch (ELF_R_TYPE (rel->r_info)) + { + case R_IA64_PCREL21B: + { + grub_uint64_t noff; + make_trampoline (tr, value); + noff = ((char *) tr - (char *) addr) >> 4; + tr++; + if (noff & ~MASK19) + return grub_error (GRUB_ERR_BAD_OS, + "trampoline offset too big"); + add_value_to_slot13_20 (addr, noff, slot); + } + break; + case R_IA64_SEGREL64LSB: + *(grub_uint64_t *) addr += value - rel->r_offset; + break; + default: + return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, + "this relocation (0x%x) is not implemented yet", + ELF_R_TYPE (rel->r_info)); + } + } + } + } + + return GRUB_ERR_NONE; +} diff --git a/include/grub/dl.h b/include/grub/dl.h index afc4af41a..e04285280 100644 --- a/include/grub/dl.h +++ b/include/grub/dl.h @@ -90,8 +90,11 @@ struct grub_dl grub_dl_dep_t dep; grub_dl_segment_t segment; Elf_Sym *symtab; - void (*init) (struct grub_dl *mod); - void (*fini) (void); + grub_addr_t init; + grub_addr_t fini; +#ifdef __ia64__ + char *gp; +#endif struct grub_dl *next; }; typedef struct grub_dl *grub_dl_t; @@ -119,4 +122,17 @@ grub_err_t grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr); void grub_arch_dl_init_linker (void); #endif +#ifdef __ia64__ +grub_size_t grub_arch_dl_get_tramp_size (const void *ehdr, unsigned sec); +#define GRUB_ARCH_DL_TRAMP_ALIGN 16 +#else +static inline grub_size_t +grub_arch_dl_get_tramp_size (const void *ehdr __attribute__ ((unused)), int sec __attribute__ ((unused))) +{ + return 0; +} +#define GRUB_ARCH_DL_TRAMP_ALIGN 1 +#endif + + #endif /* ! GRUB_DL_H */ diff --git a/include/grub/types.h b/include/grub/types.h index 4499e4538..b3aa69c1c 100644 --- a/include/grub/types.h +++ b/include/grub/types.h @@ -95,8 +95,10 @@ typedef grub_int64_t grub_ssize_t; # if GRUB_CPU_SIZEOF_LONG == 8 # define PRIxGRUB_SIZE "lx" +# define PRIxGRUB_ADDR "lx" # else # define PRIxGRUB_SIZE "llx" +# define PRIxGRUB_ADDR "llx" # endif #else typedef grub_uint32_t grub_addr_t; @@ -104,6 +106,7 @@ typedef grub_uint32_t grub_size_t; typedef grub_int32_t grub_ssize_t; # define PRIxGRUB_SIZE "x" +# define PRIxGRUB_ADDR "x" #endif #if GRUB_CPU_SIZEOF_LONG == 8 From daca6c5f45406137290e008ae0ef363624bc1887 Mon Sep 17 00:00:00 2001 From: phcoder Date: Sun, 2 Jan 2011 14:39:23 +0100 Subject: [PATCH 177/869] ltoff relocation support --- grub-core/kern/ia64/dl.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/grub-core/kern/ia64/dl.c b/grub-core/kern/ia64/dl.c index 2b87577a4..24fa01b90 100644 --- a/grub-core/kern/ia64/dl.c +++ b/grub-core/kern/ia64/dl.c @@ -187,6 +187,10 @@ grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr) rel++) switch (ELF_R_TYPE (rel->r_info)) { + case R_IA64_LTOFF22X: + case R_IA64_LTOFF22: + gp_size += 8; + break; default: break; } } @@ -275,6 +279,16 @@ grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr) case R_IA64_SEGREL64LSB: *(grub_uint64_t *) addr += value - rel->r_offset; break; + case R_IA64_LTOFF22X: + case R_IA64_LTOFF22: + *gpptr = value; + add_value_to_slot13_20 (addr, (gpptr - gp) * sizeof (grub_uint64_t), slot); + gpptr++; + break; + + /* We treat LTOFF22X as LTOFF22, so we can ignore LDXMOV. */ + case R_IA64_LDXMOV: + break; default: return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, "this relocation (0x%x) is not implemented yet", From 73911575dd67eaa09837fe0f691655553c3dea69 Mon Sep 17 00:00:00 2001 From: phcoder Date: Sun, 2 Jan 2011 14:58:57 +0100 Subject: [PATCH 178/869] support for registering functions from modules (not tested yet) --- grub-core/kern/dl.c | 20 +++++++++++++++++--- grub-core/kern/emu/full.c | 8 ++++++++ grub-core/kern/ia64/dl.c | 30 ++++++++++++++++++++---------- include/grub/dl.h | 9 +++++++++ 4 files changed, 54 insertions(+), 13 deletions(-) diff --git a/grub-core/kern/dl.c b/grub-core/kern/dl.c index 2f2493fca..9dfff5287 100644 --- a/grub-core/kern/dl.c +++ b/grub-core/kern/dl.c @@ -360,9 +360,22 @@ grub_dl_resolve_symbols (grub_dl_t mod, Elf_Ehdr *e) sym->st_value += (Elf_Addr) grub_dl_get_section_addr (mod, sym->st_shndx); if (bind != STB_LOCAL) - if (grub_dl_register_symbol (name, (void *) sym->st_value, mod)) - return grub_errno; - + { +#ifdef __ia64__ + /* FIXME: free descriptor once it's not used anymore. */ + char **desc; + desc = grub_malloc (2 * sizeof (char *)); + if (!desc) + return grub_errno; + desc[0] = (void *) sym->st_value; + desc[1] = mod->gp; + if (grub_dl_register_symbol (name, (void *) desc, mod)) + return grub_errno; +#else + if (grub_dl_register_symbol (name, (void *) sym->st_value, mod)) + return grub_errno; +#endif + } if (grub_strcmp (name, "grub_mod_init") == 0) mod->init = sym->st_value; else if (grub_strcmp (name, "grub_mod_fini") == 0) @@ -552,6 +565,7 @@ grub_dl_load_core (void *addr, grub_size_t size) if (grub_dl_resolve_name (mod, e) || grub_dl_resolve_dependencies (mod, e) || grub_dl_load_segments (mod, e) + || grub_arch_dl_allocate_gp (mod, e) || grub_dl_resolve_symbols (mod, e) || grub_arch_dl_relocate_symbols (mod, e)) { diff --git a/grub-core/kern/emu/full.c b/grub-core/kern/emu/full.c index 0396d0ab4..67a125301 100644 --- a/grub-core/kern/emu/full.c +++ b/grub-core/kern/emu/full.c @@ -56,4 +56,12 @@ grub_arch_dl_get_tramp_size (const void *ehdr __attribute__ ((unused)), { return ~(grub_size_t)0; } + +grub_err_t +grub_arch_dl_allocate_gp (grub_dl_t mod __attribute__ ((unused)), + const void *ehdr __attribute__ ((unused))) +{ + return GRUB_ERR_BAD_MODULE; +} + #endif diff --git a/grub-core/kern/ia64/dl.c b/grub-core/kern/ia64/dl.c index 24fa01b90..1fbe185b4 100644 --- a/grub-core/kern/ia64/dl.c +++ b/grub-core/kern/ia64/dl.c @@ -154,16 +154,13 @@ grub_arch_dl_get_tramp_size (const void *ehdr, unsigned sec) return cnt * sizeof (struct ia64_trampoline); } -/* Relocate symbols. */ grub_err_t -grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr) +grub_arch_dl_allocate_gp (grub_dl_t mod, const void *ehdr) { - Elf_Ehdr *e = ehdr; - Elf_Shdr *s; - Elf_Word entsize; - unsigned i; - grub_uint64_t *gp, *gpptr; grub_size_t gp_size = 0; + const Elf_Ehdr *e = ehdr; + const Elf_Shdr *s; + unsigned i; for (i = 0, s = (Elf_Shdr *) ((char *) e + e->e_shoff); i < e->e_shnum; @@ -199,10 +196,23 @@ grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr) if (gp_size > MASK19) return grub_error (GRUB_ERR_OUT_OF_RANGE, "gp too big"); - gpptr = gp = grub_malloc (gp_size); - if (!gp) + mod->gp = grub_malloc (gp_size); + if (!mod->gp) return grub_errno; - mod->gp = (char *) gp; + return GRUB_ERR_NONE; +} + +/* Relocate symbols. */ +grub_err_t +grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr) +{ + Elf_Ehdr *e = ehdr; + Elf_Shdr *s; + Elf_Word entsize; + unsigned i; + grub_uint64_t *gp, *gpptr; + + gp = gpptr = (grub_uint64_t *) mod->gp; /* Find a symbol table. */ for (i = 0, s = (Elf_Shdr *) ((char *) e + e->e_shoff); diff --git a/include/grub/dl.h b/include/grub/dl.h index e04285280..c43c30ca7 100644 --- a/include/grub/dl.h +++ b/include/grub/dl.h @@ -124,6 +124,8 @@ void grub_arch_dl_init_linker (void); #ifdef __ia64__ grub_size_t grub_arch_dl_get_tramp_size (const void *ehdr, unsigned sec); +grub_err_t grub_arch_dl_allocate_gp (grub_dl_t mod, const void *ehdr); + #define GRUB_ARCH_DL_TRAMP_ALIGN 16 #else static inline grub_size_t @@ -131,6 +133,13 @@ grub_arch_dl_get_tramp_size (const void *ehdr __attribute__ ((unused)), int sec { return 0; } +static inline grub_err_t +grub_arch_dl_allocate_gp (grub_dl_t mod __attribute__ ((unused)), + const void *ehdr __attribute__ ((unused))) +{ + return GRUB_ERR_NONE; +} + #define GRUB_ARCH_DL_TRAMP_ALIGN 1 #endif From bbbf84350e06a97de1254fa0866d317ab40c95a7 Mon Sep 17 00:00:00 2001 From: phcoder Date: Sun, 2 Jan 2011 19:20:28 +0100 Subject: [PATCH 179/869] Working hello.mod with extcmd.mod --- grub-core/kern/dl.c | 46 ++++++++----------- grub-core/kern/ia64/dl.c | 99 ++++++++++++++++++++++++++++------------ 2 files changed, 88 insertions(+), 57 deletions(-) diff --git a/grub-core/kern/dl.c b/grub-core/kern/dl.c index 9dfff5287..0ccdbe03b 100644 --- a/grub-core/kern/dl.c +++ b/grub-core/kern/dl.c @@ -238,28 +238,32 @@ grub_dl_load_segments (grub_dl_t mod, const Elf_Ehdr *e) { grub_dl_segment_t seg; grub_size_t tramp_size = 0; + grub_size_t alsize, align; seg = (grub_dl_segment_t) grub_malloc (sizeof (*seg)); if (! seg) return grub_errno; + alsize = s->sh_size; + align = s->sh_addralign; tramp_size = grub_arch_dl_get_tramp_size (e, i); - if (tramp_size && s->sh_addralign < GRUB_ARCH_DL_TRAMP_ALIGN) + if (tramp_size && align < GRUB_ARCH_DL_TRAMP_ALIGN) { - s->sh_addralign = GRUB_ARCH_DL_TRAMP_ALIGN; - s->sh_size = ALIGN_UP (s->sh_size, GRUB_ARCH_DL_TRAMP_ALIGN) + tramp_size; + align = GRUB_ARCH_DL_TRAMP_ALIGN; + alsize = ALIGN_UP (alsize, GRUB_ARCH_DL_TRAMP_ALIGN); } + alsize += tramp_size; #ifdef GRUB_MACHINE_EMU - if (s->sh_addralign < 8192) - s->sh_addralign = 8192; - s->sh_size = ALIGN_UP (s->sh_size, 8192); + if (align < 8192 * 16) + align = 8192 * 16; + alsize = ALIGN_UP (alsize, 8192 * 16); #endif - if (s->sh_size) + if (alsize) { void *addr; - addr = grub_memalign (s->sh_addralign, s->sh_size); + addr = grub_memalign (align, alsize); if (! addr) { grub_free (seg); @@ -279,7 +283,7 @@ grub_dl_load_segments (grub_dl_t mod, const Elf_Ehdr *e) seg->addr = addr; #ifdef GRUB_MACHINE_EMU if (s->sh_flags & SHF_EXECINSTR) - mprotect (addr, s->sh_size, PROT_READ | PROT_WRITE | PROT_EXEC); + mprotect (addr, alsize, PROT_READ | PROT_WRITE | PROT_EXEC); #endif } else @@ -359,9 +363,8 @@ grub_dl_resolve_symbols (grub_dl_t mod, Elf_Ehdr *e) case STT_FUNC: sym->st_value += (Elf_Addr) grub_dl_get_section_addr (mod, sym->st_shndx); - if (bind != STB_LOCAL) - { #ifdef __ia64__ + { /* FIXME: free descriptor once it's not used anymore. */ char **desc; desc = grub_malloc (2 * sizeof (char *)); @@ -371,10 +374,13 @@ grub_dl_resolve_symbols (grub_dl_t mod, Elf_Ehdr *e) desc[1] = mod->gp; if (grub_dl_register_symbol (name, (void *) desc, mod)) return grub_errno; -#else + sym->st_value = (grub_addr_t) desc; + } +#endif + if (bind != STB_LOCAL) + { if (grub_dl_register_symbol (name, (void *) sym->st_value, mod)) return grub_errno; -#endif } if (grub_strcmp (name, "grub_mod_init") == 0) mod->init = sym->st_value; @@ -405,14 +411,7 @@ grub_dl_call_init (grub_dl_t mod) { if (mod->init) { -#ifndef __ia64__ ((void (*) (grub_dl_t)) mod->init) (mod); -#else - char *jmp[2]; - jmp[0] = (char *) mod->init; - jmp[1] = mod->gp; - ((void (*) (grub_dl_t)) jmp) (mod); -#endif } } @@ -678,14 +677,7 @@ grub_dl_unload (grub_dl_t mod) if (mod->fini) { -#ifndef __ia64__ ((void (*) (void)) mod->fini) (); -#else - char *jmp[2]; - jmp[0] = (char *) mod->fini; - jmp[1] = mod->gp; - ((void (*) (void)) jmp) (); -#endif } grub_dl_remove (mod); diff --git a/grub-core/kern/ia64/dl.c b/grub-core/kern/ia64/dl.c index 1fbe185b4..55b50ff69 100644 --- a/grub-core/kern/ia64/dl.c +++ b/grub-core/kern/ia64/dl.c @@ -41,23 +41,62 @@ grub_arch_dl_check_header (void *ehdr) #define MASK20 ((1 << 20) - 1) #define MASK19 ((1 << 19) - 1) -static void -add_value_to_slot13_20 (Elf_Word *addr, grub_uint32_t value, int slot) +struct unaligned_uint32 { - grub_uint32_t *p __attribute__ ((aligned (1))); - switch (slot) + grub_uint32_t val; +} __attribute__ ((packed)); + +static void +add_value_to_slot_20b (grub_addr_t addr, grub_uint32_t value) +{ + struct unaligned_uint32 *p; + switch (addr & 3) { case 0: - p = (grub_uint32_t *) (addr + 2); - *p = (((((*p >> 2) & MASK20) + value) & MASK20) << 2) | (*p & ~(MASK20 << 2)); + p = (struct unaligned_uint32 *) ((addr & ~3ULL) + 2); + p->val = (((((p->val >> 2) & MASK20) + value) & MASK20) << 2) | (p->val & ~(MASK20 << 2)); break; case 1: - p = (grub_uint32_t *) ((grub_uint8_t *) addr + 7); - *p = (((((*p >> 3) & MASK20) + value) & MASK20) << 3) | (*p & ~(MASK20 << 3)); + p = (struct unaligned_uint32 *) ((grub_uint8_t *) (addr & ~3ULL) + 7); + p->val = (((((p->val >> 3) & MASK20) + value) & MASK20) << 3) | (p->val & ~(MASK20 << 3)); break; case 2: - p = (grub_uint32_t *) ((grub_uint8_t *) addr + 12); - *p = (((((*p >> 4) & MASK20) + value) & MASK20) << 4) | (*p & ~(MASK20 << 4)); + p = (struct unaligned_uint32 *) ((grub_uint8_t *) (addr & ~3ULL) + 12); + p->val = (((((p->val >> 4) & MASK20) + value) & MASK20) << 4) | (p->val & ~(MASK20 << 4)); + break; + } +} + +#define MASKF21 ( ((1 << 23) - 1) & ~((1 << 7) | (1 << 8)) ) + +static grub_uint32_t +add_value_to_slot_21_real (grub_uint32_t a, grub_uint32_t value) +{ + grub_uint32_t high, mid, low, c; + low = (a & 0x00007f); + mid = (a & 0x7fc000) >> 7; + high = (a & 0x003e00) << 5; + c = (low | mid | high) + value; + return (c & 0x7f) | ((c << 7) & 0x7fc000) | ((c >> 5) & 0x003e00); +} + +static void +add_value_to_slot_21 (grub_addr_t addr, grub_uint32_t value) +{ + struct unaligned_uint32 *p; + switch (addr & 3) + { + case 0: + p = (struct unaligned_uint32 *) ((addr & ~3ULL) + 2); + p->val = ((add_value_to_slot_21_real (((p->val >> 2) & MASKF21), value) & MASKF21) << 2) | (p->val & ~(MASKF21 << 2)); + break; + case 1: + p = (struct unaligned_uint32 *) ((grub_uint8_t *) (addr & ~3ULL) + 7); + p->val = ((add_value_to_slot_21_real (((p->val >> 3) & MASKF21), value) & MASKF21) << 3) | (p->val & ~(MASKF21 << 3)); + break; + case 2: + p = (struct unaligned_uint32 *) ((grub_uint8_t *) (addr & ~3ULL) + 12); + p->val = ((add_value_to_slot_21_real (((p->val >> 4) & MASKF21), value) & MASKF21) << 4) | (p->val & ~(MASKF21 << 4)); break; } } @@ -147,8 +186,8 @@ grub_arch_dl_get_tramp_size (const void *ehdr, unsigned sec) for (rel = (Elf_Rela *) ((char *) e + s->sh_offset), max = rel + s->sh_size / s->sh_entsize; rel < max; rel++) - if (ELF_R_TYPE (rel->r_info) == R_IA64_PCREL21B) - cnt++; + if (ELF_R_TYPE (rel->r_info) == R_IA64_PCREL21B) + cnt++; } return cnt * sizeof (struct ia64_trampoline); @@ -165,7 +204,7 @@ grub_arch_dl_allocate_gp (grub_dl_t mod, const void *ehdr) for (i = 0, s = (Elf_Shdr *) ((char *) e + e->e_shoff); i < e->e_shnum; i++, s = (Elf_Shdr *) ((char *) s + e->e_shentsize)) - if (s->sh_type == SHT_REL) + if (s->sh_type == SHT_RELA) { grub_dl_segment_t seg; @@ -176,16 +215,18 @@ grub_arch_dl_allocate_gp (grub_dl_t mod, const void *ehdr) if (seg) { - Elf_Rel *rel, *max; + Elf_Rela *rel, *max; - for (rel = (Elf_Rel *) ((char *) e + s->sh_offset), + for (rel = (Elf_Rela *) ((char *) e + s->sh_offset), max = rel + s->sh_size / s->sh_entsize; rel < max; rel++) switch (ELF_R_TYPE (rel->r_info)) { + case R_IA64_LTOFF_FPTR22: case R_IA64_LTOFF22X: case R_IA64_LTOFF22: + case R_IA64_GPREL22: gp_size += 8; break; default: break; @@ -243,29 +284,22 @@ grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr) Elf_Rela *rel, *max; struct ia64_trampoline *tr; + tr = (void *) ((char *) seg->addr + ALIGN_UP (seg->size, GRUB_ARCH_DL_TRAMP_ALIGN)); + for (rel = (Elf_Rela *) ((char *) e + s->sh_offset), max = rel + s->sh_size / s->sh_entsize; rel < max; rel++) { - Elf_Word *addr; + grub_addr_t addr; Elf_Sym *sym; grub_uint64_t value; - int slot = 0; if (seg->size < (rel->r_offset & ~3)) return grub_error (GRUB_ERR_BAD_MODULE, "reloc offset is out of the segment"); - tr = (void *) ((char *) seg->addr + ALIGN_UP (seg->size, GRUB_ARCH_DL_TRAMP_ALIGN)); - - if (ELF_R_TYPE (rel->r_info) == R_IA64_PCREL21B) - { - addr = (Elf_Word *) ((char *) seg->addr + (rel->r_offset & ~3)); - slot = rel->r_offset & 3; - } - else - addr = (Elf_Word *) ((char *) seg->addr + rel->r_offset); + addr = (grub_addr_t) seg->addr + rel->r_offset; sym = (Elf_Sym *) ((char *) mod->symtab + entsize * ELF_R_SYM (rel->r_info)); @@ -278,21 +312,26 @@ grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr) { grub_uint64_t noff; make_trampoline (tr, value); - noff = ((char *) tr - (char *) addr) >> 4; + noff = ((char *) tr - (char *) (addr & ~3)) >> 4; tr++; if (noff & ~MASK19) return grub_error (GRUB_ERR_BAD_OS, - "trampoline offset too big"); - add_value_to_slot13_20 (addr, noff, slot); + "trampoline offset too big (%lx)", noff); + add_value_to_slot_20b (addr, noff); } break; case R_IA64_SEGREL64LSB: *(grub_uint64_t *) addr += value - rel->r_offset; break; + case R_IA64_DIR64LSB: + *(grub_uint64_t *) addr += value; + break; + case R_IA64_LTOFF_FPTR22: case R_IA64_LTOFF22X: case R_IA64_LTOFF22: + case R_IA64_GPREL22: *gpptr = value; - add_value_to_slot13_20 (addr, (gpptr - gp) * sizeof (grub_uint64_t), slot); + add_value_to_slot_21 (addr, (gpptr - gp) * sizeof (grub_uint64_t)); gpptr++; break; From f49157dfe52bc95640645080f228cccd69ff72a5 Mon Sep 17 00:00:00 2001 From: phcoder Date: Sun, 2 Jan 2011 23:30:25 +0100 Subject: [PATCH 180/869] Restructure module loading and many fixes. Now normal.mod loads successfully --- grub-core/kern/dl.c | 83 +++++++++++++++++++----------- grub-core/kern/emu/full.c | 15 ++---- grub-core/kern/ia64/dl.c | 105 +++++++++++++------------------------- include/grub/dl.h | 22 +++----- 4 files changed, 99 insertions(+), 126 deletions(-) diff --git a/grub-core/kern/dl.c b/grub-core/kern/dl.c index 0ccdbe03b..787fcfad0 100644 --- a/grub-core/kern/dl.c +++ b/grub-core/kern/dl.c @@ -229,6 +229,46 @@ grub_dl_load_segments (grub_dl_t mod, const Elf_Ehdr *e) { unsigned i; Elf_Shdr *s; + grub_size_t tsize = 0, talign = 1; +#ifdef __ia64__ + grub_size_t tramp; + grub_size_t got; +#endif + char *ptr; + + for (i = 0, s = (Elf_Shdr *)((char *) e + e->e_shoff); + i < e->e_shnum; + i++, s = (Elf_Shdr *)((char *) s + e->e_shentsize)) + { + tsize += ALIGN_UP (s->sh_size, s->sh_addralign); + if (talign < s->sh_addralign) + talign = s->sh_addralign; + } + +#ifdef __ia64__ + grub_arch_dl_get_tramp_got_size (e, &tramp, &got); + tsize += ALIGN_UP (tramp, GRUB_ARCH_DL_TRAMP_ALIGN); + if (talign < GRUB_ARCH_DL_TRAMP_ALIGN) + talign = GRUB_ARCH_DL_TRAMP_ALIGN; + tsize += ALIGN_UP (got, GRUB_ARCH_DL_GOT_ALIGN); + if (talign < GRUB_ARCH_DL_GOT_ALIGN) + talign = GRUB_ARCH_DL_GOT_ALIGN; +#endif + +#ifdef GRUB_MACHINE_EMU + if (talign < 8192 * 16) + talign = 8192 * 16; + tsize = ALIGN_UP (tsize, 8192 * 16); +#endif + + mod->base = grub_memalign (talign, tsize); + if (!mod->base) + return grub_errno; + ptr = mod->base; + +#ifdef GRUB_MACHINE_EMU + mprotect (mod->base, tsize, PROT_READ | PROT_WRITE | PROT_EXEC); +#endif for (i = 0, s = (Elf_Shdr *)((char *) e + e->e_shoff); i < e->e_shnum; @@ -237,38 +277,18 @@ grub_dl_load_segments (grub_dl_t mod, const Elf_Ehdr *e) if (s->sh_flags & SHF_ALLOC) { grub_dl_segment_t seg; - grub_size_t tramp_size = 0; - grub_size_t alsize, align; seg = (grub_dl_segment_t) grub_malloc (sizeof (*seg)); if (! seg) return grub_errno; - alsize = s->sh_size; - align = s->sh_addralign; - tramp_size = grub_arch_dl_get_tramp_size (e, i); - if (tramp_size && align < GRUB_ARCH_DL_TRAMP_ALIGN) - { - align = GRUB_ARCH_DL_TRAMP_ALIGN; - alsize = ALIGN_UP (alsize, GRUB_ARCH_DL_TRAMP_ALIGN); - } - alsize += tramp_size; -#ifdef GRUB_MACHINE_EMU - if (align < 8192 * 16) - align = 8192 * 16; - alsize = ALIGN_UP (alsize, 8192 * 16); -#endif - - if (alsize) + if (s->sh_size) { void *addr; - addr = grub_memalign (align, alsize); - if (! addr) - { - grub_free (seg); - return grub_errno; - } + ptr = (char *) ALIGN_UP ((grub_addr_t) ptr, s->sh_addralign); + addr = ptr; + ptr += s->sh_size; switch (s->sh_type) { @@ -281,10 +301,6 @@ grub_dl_load_segments (grub_dl_t mod, const Elf_Ehdr *e) } seg->addr = addr; -#ifdef GRUB_MACHINE_EMU - if (s->sh_flags & SHF_EXECINSTR) - mprotect (addr, alsize, PROT_READ | PROT_WRITE | PROT_EXEC); -#endif } else seg->addr = 0; @@ -295,6 +311,14 @@ grub_dl_load_segments (grub_dl_t mod, const Elf_Ehdr *e) mod->segment = seg; } } +#ifdef __ia64__ + ptr = (char *) ALIGN_UP ((grub_addr_t) ptr, GRUB_ARCH_DL_TRAMP_ALIGN); + mod->tramp = ptr; + ptr += tramp; + ptr = (char *) ALIGN_UP ((grub_addr_t) ptr, GRUB_ARCH_DL_GOT_ALIGN); + mod->got = ptr; + ptr += got; +#endif return GRUB_ERR_NONE; } @@ -371,7 +395,7 @@ grub_dl_resolve_symbols (grub_dl_t mod, Elf_Ehdr *e) if (!desc) return grub_errno; desc[0] = (void *) sym->st_value; - desc[1] = mod->gp; + desc[1] = mod->base; if (grub_dl_register_symbol (name, (void *) desc, mod)) return grub_errno; sym->st_value = (grub_addr_t) desc; @@ -564,7 +588,6 @@ grub_dl_load_core (void *addr, grub_size_t size) if (grub_dl_resolve_name (mod, e) || grub_dl_resolve_dependencies (mod, e) || grub_dl_load_segments (mod, e) - || grub_arch_dl_allocate_gp (mod, e) || grub_dl_resolve_symbols (mod, e) || grub_arch_dl_relocate_symbols (mod, e)) { diff --git a/grub-core/kern/emu/full.c b/grub-core/kern/emu/full.c index 67a125301..80edb991e 100644 --- a/grub-core/kern/emu/full.c +++ b/grub-core/kern/emu/full.c @@ -50,18 +50,11 @@ grub_emu_init (void) } #ifdef __ia64__ -grub_size_t -grub_arch_dl_get_tramp_size (const void *ehdr __attribute__ ((unused)), - unsigned sec __attribute__ ((unused))) +void grub_arch_dl_get_tramp_got_size (const void *ehdr __attribute__ ((unused)), + grub_size_t *tramp, grub_size_t *got) { - return ~(grub_size_t)0; -} - -grub_err_t -grub_arch_dl_allocate_gp (grub_dl_t mod __attribute__ ((unused)), - const void *ehdr __attribute__ ((unused))) -{ - return GRUB_ERR_BAD_MODULE; + *tramp = 0; + *got = 0; } #endif diff --git a/grub-core/kern/ia64/dl.c b/grub-core/kern/ia64/dl.c index 55b50ff69..9bbebcd2f 100644 --- a/grub-core/kern/ia64/dl.c +++ b/grub-core/kern/ia64/dl.c @@ -75,9 +75,9 @@ add_value_to_slot_21_real (grub_uint32_t a, grub_uint32_t value) grub_uint32_t high, mid, low, c; low = (a & 0x00007f); mid = (a & 0x7fc000) >> 7; - high = (a & 0x003e00) << 5; + high = (a & 0x003e00) << 7; c = (low | mid | high) + value; - return (c & 0x7f) | ((c << 7) & 0x7fc000) | ((c >> 5) & 0x003e00); + return (c & 0x7f) | ((c << 7) & 0x7fc000) | ((c >> 7) & 0x0003e00); //0x003e00 } static void @@ -138,7 +138,7 @@ static void make_trampoline (struct ia64_trampoline *tr, grub_uint64_t addr) { grub_memcpy (tr->nop, nopm, sizeof (tr->nop)); - tr->addr_hi[0] = ((addr & 0xc00000) >> 18); + tr->addr_hi[0] = ((addr & 0xc00000) >> 16); tr->addr_hi[1] = (addr >> 24) & 0xff; tr->addr_hi[2] = (addr >> 32) & 0xff; tr->addr_hi[3] = (addr >> 40) & 0xff; @@ -152,11 +152,11 @@ make_trampoline (struct ia64_trampoline *tr, grub_uint64_t addr) grub_memcpy (tr->jump, jump, sizeof (tr->jump)); } -grub_size_t -grub_arch_dl_get_tramp_size (const void *ehdr, unsigned sec) +void +grub_arch_dl_get_tramp_got_size (const void *ehdr, grub_size_t *tramp, grub_size_t *got) { const Elf_Ehdr *e = ehdr; - int cnt = 0; + grub_size_t cntt = 0, cntg = 0;; const Elf_Shdr *s; Elf_Word entsize; unsigned i; @@ -169,7 +169,7 @@ grub_arch_dl_get_tramp_size (const void *ehdr, unsigned sec) break; if (i == e->e_shnum) - return 0; + return; entsize = s->sh_entsize; @@ -180,68 +180,25 @@ grub_arch_dl_get_tramp_size (const void *ehdr, unsigned sec) { Elf_Rela *rel, *max; - if (s->sh_info != sec) - continue; - for (rel = (Elf_Rela *) ((char *) e + s->sh_offset), max = rel + s->sh_size / s->sh_entsize; rel < max; rel++) - if (ELF_R_TYPE (rel->r_info) == R_IA64_PCREL21B) - cnt++; + switch (ELF_R_TYPE (rel->r_info)) + { + case R_IA64_PCREL21B: + cntt++; + break; + case R_IA64_LTOFF_FPTR22: + case R_IA64_LTOFF22X: + case R_IA64_LTOFF22: + cntg++; + break; + } } - - return cnt * sizeof (struct ia64_trampoline); + *tramp = cntt * sizeof (struct ia64_trampoline); + *got = cntg * sizeof (grub_uint64_t); } -grub_err_t -grub_arch_dl_allocate_gp (grub_dl_t mod, const void *ehdr) -{ - grub_size_t gp_size = 0; - const Elf_Ehdr *e = ehdr; - const Elf_Shdr *s; - unsigned i; - - for (i = 0, s = (Elf_Shdr *) ((char *) e + e->e_shoff); - i < e->e_shnum; - i++, s = (Elf_Shdr *) ((char *) s + e->e_shentsize)) - if (s->sh_type == SHT_RELA) - { - grub_dl_segment_t seg; - - /* Find the target segment. */ - for (seg = mod->segment; seg; seg = seg->next) - if (seg->section == s->sh_info) - break; - - if (seg) - { - Elf_Rela *rel, *max; - - for (rel = (Elf_Rela *) ((char *) e + s->sh_offset), - max = rel + s->sh_size / s->sh_entsize; - rel < max; - rel++) - switch (ELF_R_TYPE (rel->r_info)) - { - case R_IA64_LTOFF_FPTR22: - case R_IA64_LTOFF22X: - case R_IA64_LTOFF22: - case R_IA64_GPREL22: - gp_size += 8; - break; - default: break; - } - } - } - - if (gp_size > MASK19) - return grub_error (GRUB_ERR_OUT_OF_RANGE, "gp too big"); - - mod->gp = grub_malloc (gp_size); - if (!mod->gp) - return grub_errno; - return GRUB_ERR_NONE; -} /* Relocate symbols. */ grub_err_t @@ -252,8 +209,11 @@ grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr) Elf_Word entsize; unsigned i; grub_uint64_t *gp, *gpptr; + struct ia64_trampoline *tr; - gp = gpptr = (grub_uint64_t *) mod->gp; + gp = (grub_uint64_t *) mod->base; + gpptr = (grub_uint64_t *) mod->got; + tr = mod->tramp; /* Find a symbol table. */ for (i = 0, s = (Elf_Shdr *) ((char *) e + e->e_shoff); @@ -282,9 +242,6 @@ grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr) if (seg) { Elf_Rela *rel, *max; - struct ia64_trampoline *tr; - - tr = (void *) ((char *) seg->addr + ALIGN_UP (seg->size, GRUB_ARCH_DL_TRAMP_ALIGN)); for (rel = (Elf_Rela *) ((char *) e + s->sh_offset), max = rel + s->sh_size / s->sh_entsize; @@ -306,6 +263,7 @@ grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr) /* On the PPC the value does not have an explicit addend, add it. */ value = sym->st_value + rel->r_addend; + switch (ELF_R_TYPE (rel->r_info)) { case R_IA64_PCREL21B: @@ -323,15 +281,24 @@ grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr) case R_IA64_SEGREL64LSB: *(grub_uint64_t *) addr += value - rel->r_offset; break; + case R_IA64_FPTR64LSB: case R_IA64_DIR64LSB: *(grub_uint64_t *) addr += value; break; + case R_IA64_PCREL64LSB: + *(grub_uint64_t *) addr += value - addr; + break; + case R_IA64_GPREL22: + add_value_to_slot_21 (addr, value - (grub_addr_t) gp); + break; + case R_IA64_LTOFF_FPTR22: case R_IA64_LTOFF22X: case R_IA64_LTOFF22: - case R_IA64_GPREL22: *gpptr = value; - add_value_to_slot_21 (addr, (gpptr - gp) * sizeof (grub_uint64_t)); + if ((addr & 0xffff) == 0x4301) + grub_dprintf ("modules", "off = %lx\n", (grub_addr_t) gpptr - (grub_addr_t) gp); + add_value_to_slot_21 (addr, (grub_addr_t) gpptr - (grub_addr_t) gp); gpptr++; break; diff --git a/include/grub/dl.h b/include/grub/dl.h index c43c30ca7..b57c3ae87 100644 --- a/include/grub/dl.h +++ b/include/grub/dl.h @@ -93,8 +93,10 @@ struct grub_dl grub_addr_t init; grub_addr_t fini; #ifdef __ia64__ - char *gp; + void *got; + void *tramp; #endif + void *base; struct grub_dl *next; }; typedef struct grub_dl *grub_dl_t; @@ -123,24 +125,12 @@ void grub_arch_dl_init_linker (void); #endif #ifdef __ia64__ -grub_size_t grub_arch_dl_get_tramp_size (const void *ehdr, unsigned sec); -grub_err_t grub_arch_dl_allocate_gp (grub_dl_t mod, const void *ehdr); +void grub_arch_dl_get_tramp_got_size (const void *ehdr, grub_size_t *tramp, grub_size_t *got); #define GRUB_ARCH_DL_TRAMP_ALIGN 16 -#else -static inline grub_size_t -grub_arch_dl_get_tramp_size (const void *ehdr __attribute__ ((unused)), int sec __attribute__ ((unused))) -{ - return 0; -} -static inline grub_err_t -grub_arch_dl_allocate_gp (grub_dl_t mod __attribute__ ((unused)), - const void *ehdr __attribute__ ((unused))) -{ - return GRUB_ERR_NONE; -} +#define GRUB_ARCH_DL_GOT_ALIGN 16 -#define GRUB_ARCH_DL_TRAMP_ALIGN 1 +#else #endif From 0a2b2cdc95d1a8677fec66df81d48db88a2546f7 Mon Sep 17 00:00:00 2001 From: phcoder Date: Mon, 3 Jan 2011 00:30:26 +0100 Subject: [PATCH 181/869] Fix autogen --- grub-core/Makefile.core.def | 37 +---------------------- grub-core/kern/emu/{cache.S => cache_s.S} | 0 2 files changed, 1 insertion(+), 36 deletions(-) rename grub-core/kern/emu/{cache.S => cache_s.S} (100%) diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def index 8f988b0be..ff5bf7a30 100644 --- a/grub-core/Makefile.core.def +++ b/grub-core/Makefile.core.def @@ -173,7 +173,7 @@ kernel = { emu = disk/host.c; emu = gnulib/progname.c; emu = gnulib/error.c; - emu = kern/emu/cache.S; + emu = kern/emu/cache_s.S; emu = kern/emu/console.c; emu = kern/emu/getroot.c; emu = kern/emu/hostdisk.c; @@ -463,41 +463,6 @@ module = { enable = i386_multiboot; }; -module = { - name = lsacpi; - - common = commands/lsacpi.c; - - enable = efi; - enable = i386_pc; - enable = i386_coreboot; - enable = i386_multiboot; -}; - -module = { - name = lsefisystab; - - common = commands/efi/lsefisystab.c; - - enable = efi; -}; - -module = { - name = lssal; - - common = commands/efi/lssal.c; - - enable = efi; -}; - -module = { - name = lsefimmap; - - common = commands/efi/lsefimmap.c; - - enable = efi; -}; - module = { name = lsacpi; diff --git a/grub-core/kern/emu/cache.S b/grub-core/kern/emu/cache_s.S similarity index 100% rename from grub-core/kern/emu/cache.S rename to grub-core/kern/emu/cache_s.S From 5faa440cb00186819dd2af2fca42fe4f9eb4d608 Mon Sep 17 00:00:00 2001 From: phcoder Date: Mon, 3 Jan 2011 00:47:21 +0100 Subject: [PATCH 182/869] Discard several spurious differences from mainline --- grub-core/kern/dl.c | 25 ------------------------- grub-core/kern/main.c | 2 +- include/grub/dl.h | 4 ++-- 3 files changed, 3 insertions(+), 28 deletions(-) diff --git a/grub-core/kern/dl.c b/grub-core/kern/dl.c index 7727745e8..787fcfad0 100644 --- a/grub-core/kern/dl.c +++ b/grub-core/kern/dl.c @@ -611,31 +611,6 @@ grub_dl_load_core (void *addr, grub_size_t size) return mod; } -#ifdef __ia64__ -void -grub_init_module (const char *name, - void (*init)(grub_dl_t), void (*fini)(void)) -{ - grub_dl_t mod; - - mod = (grub_dl_t) grub_malloc (sizeof (*mod)); - if (! mod) - return; - - mod->name = (char *) name; - mod->ref_count = 1; - mod->dep = 0; - mod->segment = 0; - mod->init = init; - mod->fini = fini; - - grub_dl_call_init (mod); - - /* Can't fail. */ - grub_dl_add (mod); -} -#endif - /* Load a module from the file FILENAME. */ grub_dl_t grub_dl_load_file (const char *filename) diff --git a/grub-core/kern/main.c b/grub-core/kern/main.c index 24593e3c0..3474ed3bb 100644 --- a/grub-core/kern/main.c +++ b/grub-core/kern/main.c @@ -159,7 +159,7 @@ static void grub_load_normal_mode (void) { /* Load the module. */ -// grub_dl_load ("normal"); + grub_dl_load ("normal"); /* Something went wrong. Print errors here to let user know why we're entering rescue mode. */ grub_print_error (); diff --git a/include/grub/dl.h b/include/grub/dl.h index fcf5bb620..a5e5c3332 100644 --- a/include/grub/dl.h +++ b/include/grub/dl.h @@ -34,9 +34,9 @@ #ifndef GRUB_MOD_INIT #define GRUB_MOD_INIT(name) \ static void grub_mod_init (grub_dl_t mod __attribute__ ((unused))) __attribute__ ((used)); \ -void grub_##name##_init (grub_dl_t); \ +void grub_##name##_init (void); \ void \ -grub_##name##_init (grub_dl_t mod) { grub_mod_init (mod); } \ +grub_##name##_init (void) { grub_mod_init (0); } \ static void \ grub_mod_init (grub_dl_t mod __attribute__ ((unused))) #endif From 0718f66d12275a940f8cf882d24aec2a48f17f99 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 3 Jan 2011 00:56:28 +0100 Subject: [PATCH 183/869] Discard a bunch of junk code --- grub-core/kern/dl.c | 20 +- grub-core/kern/main.c | 2 - grub-core/kern/mm.c | 2 +- include/grub/dl.h | 4 +- include/grub/ia64/efi/misc.h | 27 -- util/ia64/efi/elf2pe.c | 812 ---------------------------------- util/ia64/efi/grub-install.in | 233 ---------- util/ia64/efi/pe32.h | 237 ---------- 8 files changed, 10 insertions(+), 1327 deletions(-) delete mode 100644 include/grub/ia64/efi/misc.h delete mode 100644 util/ia64/efi/elf2pe.c delete mode 100644 util/ia64/efi/grub-install.in delete mode 100644 util/ia64/efi/pe32.h diff --git a/grub-core/kern/dl.c b/grub-core/kern/dl.c index 787fcfad0..f871b81a1 100644 --- a/grub-core/kern/dl.c +++ b/grub-core/kern/dl.c @@ -402,14 +402,12 @@ grub_dl_resolve_symbols (grub_dl_t mod, Elf_Ehdr *e) } #endif if (bind != STB_LOCAL) - { - if (grub_dl_register_symbol (name, (void *) sym->st_value, mod)) - return grub_errno; - } + if (grub_dl_register_symbol (name, (void *) sym->st_value, mod)) + return grub_errno; if (grub_strcmp (name, "grub_mod_init") == 0) - mod->init = sym->st_value; + mod->init = (void (*) (grub_dl_t)) sym->st_value; else if (grub_strcmp (name, "grub_mod_fini") == 0) - mod->fini = sym->st_value; + mod->fini = (void (*) (void)) sym->st_value; break; case STT_SECTION: @@ -434,9 +432,7 @@ static void grub_dl_call_init (grub_dl_t mod) { if (mod->init) - { - ((void (*) (grub_dl_t)) mod->init) (mod); - } + (mod->init) (mod); } static grub_err_t @@ -599,7 +595,7 @@ grub_dl_load_core (void *addr, grub_size_t size) grub_dl_flush_cache (mod); grub_dprintf ("modules", "module name: %s\n", mod->name); - grub_dprintf ("modules", "init function: %" PRIxGRUB_ADDR "\n", mod->init); + grub_dprintf ("modules", "init function: %p\n", mod->init); grub_dl_call_init (mod); if (grub_dl_add (mod)) @@ -699,9 +695,7 @@ grub_dl_unload (grub_dl_t mod) return 0; if (mod->fini) - { - ((void (*) (void)) mod->fini) (); - } + (mod->fini) (); grub_dl_remove (mod); grub_dl_unregister_symbols (mod); diff --git a/grub-core/kern/main.c b/grub-core/kern/main.c index 3474ed3bb..8b6c8a180 100644 --- a/grub-core/kern/main.c +++ b/grub-core/kern/main.c @@ -76,7 +76,6 @@ grub_modules_get_end (void) static void grub_load_modules (void) { -#if 0 auto int hook (struct grub_module_header *); int hook (struct grub_module_header *header) { @@ -95,7 +94,6 @@ grub_load_modules (void) } grub_module_iterate (hook); -#endif } static void diff --git a/grub-core/kern/mm.c b/grub-core/kern/mm.c index bd489e22c..8d9b5db78 100644 --- a/grub-core/kern/mm.c +++ b/grub-core/kern/mm.c @@ -313,7 +313,7 @@ grub_memalign (grub_size_t align, grub_size_t size) case 1: /* Unload unneeded modules. */ -// grub_dl_unload_unneeded (); + grub_dl_unload_unneeded (); count++; goto again; diff --git a/include/grub/dl.h b/include/grub/dl.h index a5e5c3332..b45928a76 100644 --- a/include/grub/dl.h +++ b/include/grub/dl.h @@ -92,8 +92,8 @@ struct grub_dl grub_dl_dep_t dep; grub_dl_segment_t segment; Elf_Sym *symtab; - grub_addr_t init; - grub_addr_t fini; + void (*init) (struct grub_dl *mod); + void (*fini) (void); #ifdef __ia64__ void *got; void *tramp; diff --git a/include/grub/ia64/efi/misc.h b/include/grub/ia64/efi/misc.h deleted file mode 100644 index 4f9c69e32..000000000 --- a/include/grub/ia64/efi/misc.h +++ /dev/null @@ -1,27 +0,0 @@ -/* - * GRUB -- GRand Unified Bootloader - * Copyright (C) 2008 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 . - */ - -void EXPORT_FUNC (__ia64_trampoline) (void); -void EXPORT_FUNC (grub_init_modules) (void); - -void -grub_init_module (const char *name, - void (*init)(grub_dl_t), void (*fini)(void)); - -extern unsigned long EXPORT_VAR (__gp); - diff --git a/util/ia64/efi/elf2pe.c b/util/ia64/efi/elf2pe.c deleted file mode 100644 index 66d28bde8..000000000 --- a/util/ia64/efi/elf2pe.c +++ /dev/null @@ -1,812 +0,0 @@ -/* elf2pe.c - convert elf binary to PE/Coff. */ -/* - * GRUB -- GRand Unified Bootloader - * Copyright (C) 2008 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 . - */ -#include -#include -#include -#include -#include -#include - -#if defined(ELF2PE_I386) -#define USE_ELF32 -#define USE_PE32 -#define ELF_MACHINE EM_386 -#define EFI_MACHINE PE32_MACHINE_I386 -#elif defined(ELF2PE_IA64) -#define USE_ELF64 -#define USE_PE32PLUS -#define ELF_MACHINE EM_IA_64 -#define EFI_MACHINE PE32_MACHINE_IA64 -#else -#error "unknown architecture" -#endif - -#include "pe32.h" - -const char *filename; - -int -is_elf_header(uint8_t *buffer) -{ - return (buffer[EI_MAG0] == ELFMAG0 - && buffer[EI_MAG1] == ELFMAG1 - && buffer[EI_MAG2] == ELFMAG2 - && buffer[EI_MAG3] == ELFMAG3); -} - -#ifdef USE_ELF32 -typedef Elf32_Shdr Elf_Shdr; -typedef Elf32_Ehdr Elf_Ehdr; -typedef Elf32_Rel Elf_Rel; -typedef Elf32_Rela Elf_Rela; -typedef Elf32_Sym Elf_Sym; -#define ELFCLASS ELFCLASS32 -#define ELF_R_TYPE(r) ELF32_R_TYPE(r) -#define ELF_R_SYM(r) ELF32_R_SYM(r) -#else -typedef Elf64_Shdr Elf_Shdr; -typedef Elf64_Ehdr Elf_Ehdr; -typedef Elf64_Rel Elf_Rel; -typedef Elf64_Rela Elf_Rela; -typedef Elf64_Sym Elf_Sym; -#define ELFCLASS ELFCLASS64 -#define ELF_R_TYPE(r) ELF64_R_TYPE(r) -#define ELF_R_SYM(r) ELF64_R_SYM(r) -#endif - -#ifdef ELF2PE_IA64 -#define ELF_ETYPE ET_DYN -#else -#define ELF_ETYPE ET_EXEC -#endif - -/* Well known ELF structures. */ -Elf_Ehdr *ehdr; -Elf_Shdr *shdr_base; -Elf_Shdr *shdr_dynamic; -const uint8_t *shdr_str; - -/* PE section alignment. */ -const uint32_t coff_alignment = 0x20; -const uint32_t coff_nbr_sections = 4; - -/* Current offset in coff file. */ -uint32_t coff_offset; - -/* Result Coff file in memory. */ -uint8_t *coff_file; - -/* Offset in Coff file of headers and sections. */ -uint32_t nt_hdr_offset; -uint32_t table_offset; -uint32_t text_offset; -uint32_t data_offset; -uint32_t reloc_offset; - -#ifdef ELF2PE_IA64 -uint32_t coff_entry_descr_offset; -uint32_t coff_entry_descr_func; -uint64_t plt_base; -#endif - -/* ELF sections to offset in Coff file. */ -uint32_t *coff_sections_offset; - -struct pe32_fixup_block *coff_base_rel; -uint16_t *coff_entry_rel; - -uint32_t -coff_align(uint32_t offset) -{ - return (offset + coff_alignment - 1) & ~(coff_alignment - 1); -} - -Elf_Shdr * -get_shdr_by_index(uint32_t num) -{ - if (num >= ehdr->e_shnum) - return NULL; - return (Elf_Shdr*)((uint8_t*)shdr_base + num * ehdr->e_shentsize); -} - -int -check_elf_header (void) -{ - /* Note: Magic has already been tested. */ - if (ehdr->e_ident[EI_CLASS] != ELFCLASS) - return 0; - if (ehdr->e_ident[EI_DATA] != ELFDATA2LSB) - return 0; - if (ehdr->e_type != ELF_ETYPE) - return 0; - if (ehdr->e_machine != ELF_MACHINE) - return 0; - if (ehdr->e_version != EV_CURRENT) - return 0; - - shdr_base = (Elf_Shdr *)((uint8_t *)ehdr + ehdr->e_shoff); - - coff_sections_offset = - (uint32_t *)malloc (ehdr->e_shnum * sizeof (uint32_t)); - memset (coff_sections_offset, 0, ehdr->e_shnum * sizeof(uint32_t)); - - if (ehdr->e_shstrndx != SHN_UNDEF) - shdr_str = (uint8_t*)ehdr + shdr_base[ehdr->e_shstrndx].sh_offset; - else - shdr_str = NULL; - - return 1; -} - -int -is_text_shdr (Elf_Shdr *shdr) -{ - if (shdr->sh_type != SHT_PROGBITS) { - return 0; - } -#ifdef ELF2PE_IA64 - return (shdr->sh_flags & (SHF_EXECINSTR | SHF_ALLOC)) - == (SHF_ALLOC | SHF_EXECINSTR); -#else - return (shdr->sh_flags & (SHF_WRITE | SHF_ALLOC)) == SHF_ALLOC; -#endif -} - -int -is_data_shdr (Elf_Shdr *shdr) -{ - if (shdr->sh_type != SHT_PROGBITS && shdr->sh_type != SHT_NOBITS) { - return 0; - } - return (shdr->sh_flags & (SHF_WRITE | SHF_ALLOC)) == (SHF_ALLOC | SHF_WRITE); -} - -void -create_section_header (const char *name, uint32_t offset, uint32_t size, - uint32_t flags) -{ - struct pe32_section_header *hdr; - hdr = (struct pe32_section_header*)(coff_file + table_offset); - - strcpy (hdr->name, name); - hdr->virtual_size = size; - hdr->virtual_address = offset; - hdr->raw_data_size = size; - hdr->raw_data_offset = offset; - hdr->relocations_offset = 0; - hdr->line_numbers_offset = 0; - hdr->num_relocations = 0; - hdr->num_line_numbers = 0; - hdr->characteristics = flags; - - table_offset += sizeof (struct pe32_section_header); -} - -int -scan_sections (void) -{ - uint32_t i; - struct pe32_dos_header *doshdr; - struct pe32_nt_header *nt_hdr; - uint32_t coff_entry = 0; - int status = 0; - - coff_offset = 0; - - /* Coff file start with a DOS header. */ - coff_offset = sizeof(struct pe32_dos_header); - nt_hdr_offset = coff_offset; - coff_offset += sizeof(struct pe32_nt_header); - table_offset = coff_offset; - coff_offset += coff_nbr_sections * sizeof(struct pe32_section_header); - - /* First text sections. */ - coff_offset = coff_align(coff_offset); - text_offset = coff_offset; - for (i = 0; i < ehdr->e_shnum; i++) { - Elf_Shdr *shdr = get_shdr_by_index (i); - if (is_text_shdr (shdr)) { - /* Relocate entry. */ - if (ehdr->e_entry >= shdr->sh_addr - && ehdr->e_entry < shdr->sh_addr + shdr->sh_size) { - coff_entry = coff_offset + ehdr->e_entry - shdr->sh_addr; - } - coff_sections_offset[i] = coff_offset; - coff_offset += shdr->sh_size; -#ifdef ELF2PE_IA64 - if (coff_sections_offset[i] != shdr->sh_addr) { - fprintf (stderr, - "Section %s: Coff offset (%x) != Elf offset (%lx)", - shdr_str + shdr->sh_name, - coff_sections_offset[i], - shdr->sh_addr); - status = -1; - } -#endif - } - if (shdr->sh_type == SHT_DYNAMIC) { - shdr_dynamic = shdr; - } - } -#ifdef ELF2PE_IA64 - /* 16 bytes are reserved (by the ld script) for the entry point descriptor. - */ - coff_entry_descr_offset = coff_offset - 16; -#endif - - coff_offset = coff_align (coff_offset); - - /* Then data sections. */ - data_offset = coff_offset; - for (i = 0; i < ehdr->e_shnum; i++) { - Elf_Shdr *shdr = get_shdr_by_index (i); - if (is_data_shdr (shdr)) { - coff_sections_offset[i] = coff_offset; - coff_offset += shdr->sh_size; -#ifdef ELF2PE_IA64 - if (coff_sections_offset[i] != shdr->sh_addr) { - fprintf (stderr, - "Section %s: Coff offset (%x) != Elf offset (%lx)", - shdr_str + shdr->sh_name, - coff_sections_offset[i], - shdr->sh_addr); - status = -1; - } -#endif - } - } - coff_offset = coff_align (coff_offset); - - reloc_offset = coff_offset; - - /* Allocate base Coff file. Will be expanded later for relocations. */ - coff_file = (uint8_t *)malloc (coff_offset); - memset (coff_file, 0, coff_offset); - - /* Fill headers. */ - doshdr = (struct pe32_dos_header *)coff_file; - doshdr->magic = 0x5A4D; - doshdr->new_hdr_offset = nt_hdr_offset; - - nt_hdr = (struct pe32_nt_header*)(coff_file + nt_hdr_offset); - - memcpy (nt_hdr->signature, "PE\0", 4); - - nt_hdr->coff_header.machine = EFI_MACHINE; - nt_hdr->coff_header.num_sections = coff_nbr_sections; - nt_hdr->coff_header.time = time (NULL); - nt_hdr->coff_header.symtab_offset = 0; - nt_hdr->coff_header.num_symbols = 0; - nt_hdr->coff_header.optional_header_size = sizeof(nt_hdr->optional_header); - nt_hdr->coff_header.characteristics = PE32_EXECUTABLE_IMAGE - | PE32_LINE_NUMS_STRIPPED - | PE32_LOCAL_SYMS_STRIPPED - | PE32_32BIT_MACHINE; - -#ifdef USE_PE32 - nt_hdr->optional_header.magic = PE32_PE32_MAGIC; -#else - nt_hdr->optional_header.magic = PE32_PE64_MAGIC; -#endif - nt_hdr->optional_header.code_size = data_offset - text_offset; - nt_hdr->optional_header.data_size = reloc_offset - data_offset; - nt_hdr->optional_header.bss_size = 0; -#ifdef ELF2PE_IA64 - nt_hdr->optional_header.entry_addr = coff_entry_descr_offset; - coff_entry_descr_func = coff_entry; -#else - nt_hdr->optional_header.entry_addr = coff_entry; -#endif - nt_hdr->optional_header.code_base = text_offset; - -#ifdef USE_PE32 - nt_hdr->optional_header.data_base = data_offset; -#endif - nt_hdr->optional_header.image_base = 0; - nt_hdr->optional_header.section_alignment = coff_alignment; - nt_hdr->optional_header.file_alignment = coff_alignment; - nt_hdr->optional_header.image_size = 0; - - nt_hdr->optional_header.header_size = text_offset; - nt_hdr->optional_header.num_data_directories = PE32_NUM_DATA_DIRECTORIES; - - /* Section headers. */ - create_section_header (".text", text_offset, data_offset - text_offset, - PE32_SCN_CNT_CODE - | PE32_SCN_MEM_EXECUTE - | PE32_SCN_MEM_READ); - create_section_header (".data", data_offset, reloc_offset - data_offset, - PE32_SCN_CNT_INITIALIZED_DATA - | PE32_SCN_MEM_WRITE - | PE32_SCN_MEM_READ); -#ifdef ELF2PE_IA64 - if (shdr_dynamic != NULL) - { - Elf64_Dyn *dyn = (Elf64_Dyn*)((uint8_t*)ehdr + shdr_dynamic->sh_offset); - while (dyn->d_tag != DT_NULL) - { - if (dyn->d_tag == DT_PLTGOT) - plt_base = dyn->d_un.d_ptr; - dyn++; - } - } -#endif - return status; -} - -int -write_sections (int (*filter)(Elf_Shdr *)) -{ - uint32_t idx; - int status = 0; - - /* First: copy sections. */ - for (idx = 0; idx < ehdr->e_shnum; idx++) - { - Elf_Shdr *shdr = get_shdr_by_index (idx); - if ((*filter)(shdr)) - { - switch (shdr->sh_type) { - case SHT_PROGBITS: - /* Copy. */ - memcpy (coff_file + coff_sections_offset[idx], - (uint8_t*)ehdr + shdr->sh_offset, - shdr->sh_size); - break; - case SHT_NOBITS: - memset (coff_file + coff_sections_offset[idx], 0, shdr->sh_size); - break; - case SHT_DYNAMIC: - break; - default: - fprintf (stderr, "unhandled section type %x", - (unsigned int)shdr->sh_type); - status = -1; - } - } - } - - /* Second: apply relocations. */ - for (idx = 0; idx < ehdr->e_shnum; idx++) - { - Elf_Shdr *rel_shdr = get_shdr_by_index (idx); - if (rel_shdr->sh_type != SHT_REL && rel_shdr->sh_type != SHT_RELA) - continue; - Elf_Shdr *sec_shdr = get_shdr_by_index (rel_shdr->sh_info); - uint32_t sec_offset = coff_sections_offset[rel_shdr->sh_info]; - - if (rel_shdr->sh_info == 0 || (*filter)(sec_shdr)) - { - uint32_t rel_idx; - Elf_Shdr *symtab_shdr = get_shdr_by_index(rel_shdr->sh_link); - uint8_t *symtab = (uint8_t*)ehdr + symtab_shdr->sh_offset; - - if (rel_shdr->sh_type == SHT_REL) - { - for (rel_idx = 0; - rel_idx < rel_shdr->sh_size; - rel_idx += rel_shdr->sh_entsize) - { - Elf_Rel *rel = (Elf_Rel *) - ((uint8_t*)ehdr + rel_shdr->sh_offset + rel_idx); - Elf_Sym *sym = (Elf_Sym *) - (symtab - + ELF_R_SYM(rel->r_info) * symtab_shdr->sh_entsize); - Elf_Shdr *sym_shdr; - uint8_t *targ; - - if (sym->st_shndx == SHN_UNDEF - || sym->st_shndx == SHN_ABS - || sym->st_shndx > ehdr->e_shnum) - { - fprintf (stderr, "bad symbol definition"); - status = -1; - } - sym_shdr = get_shdr_by_index(sym->st_shndx); - - /* Note: r_offset in a memory address. - Convert it to a pointer in the coff file. */ - targ = coff_file + sec_offset - + (rel->r_offset - sec_shdr->sh_addr); - - switch (ELF_R_TYPE(rel->r_info)) { - case R_386_NONE: - break; - case R_386_32: - /* Absolute relocation. */ - *(uint32_t *)targ = *(uint32_t *)targ - sym_shdr->sh_addr - + coff_sections_offset[sym->st_shndx]; - break; - case R_386_PC32: - /* Relative relocation: Symbol - Ip + Addend */ - *(uint32_t *)targ = *(uint32_t *)targ - + (coff_sections_offset[sym->st_shndx] - - sym_shdr->sh_addr) - - (sec_offset - sec_shdr->sh_addr); - break; - default: - fprintf (stderr, "unhandled relocation type %lx", - ELF_R_TYPE(rel->r_info)); - status = -1; - } - } - } - else if (rel_shdr->sh_type == SHT_RELA) - { - for (rel_idx = 0; - rel_idx < rel_shdr->sh_size; - rel_idx += rel_shdr->sh_entsize) { - Elf_Rela *rela = (Elf_Rela *) - ((uint8_t*)ehdr + rel_shdr->sh_offset + rel_idx); - Elf_Sym *sym = (Elf_Sym *) - (symtab + ELF_R_SYM(rela->r_info) * symtab_shdr->sh_entsize); - Elf_Shdr *sym_shdr; - uint8_t *targ; - - if (ELF_R_TYPE(rela->r_info) == R_IA64_NONE) - continue; - -#if 0 - if (sym->st_shndx == SHN_UNDEF - || sym->st_shndx == SHN_ABS - || sym->st_shndx > ehdr->e_shnum) { - fprintf (stderr, "bad symbol definition %d", - ELF_R_SYM(rela->r_info)); - } -#endif - sym_shdr = get_shdr_by_index (sym->st_shndx); - - /* Note: r_offset in a memory address. - Convert it to a pointer in the coff file. */ - targ = coff_file + sec_offset - + (rela->r_offset - sec_shdr->sh_addr); - - switch (ELF_R_TYPE(rela->r_info)) { - case R_IA64_IPLTLSB: - /* If there is a descriptor with the same function - pointer as the ELF entry point, use that - descriptor for the PE/Coff entry. */ - if (*(uint64_t*)targ == ehdr->e_entry) { - struct pe32_nt_header *nt_hdr; - - nt_hdr = - (struct pe32_nt_header*)(coff_file + nt_hdr_offset); - nt_hdr->optional_header.entry_addr = targ - coff_file; - } - break; - case R_IA64_REL64LSB: - case R_IA64_NONE: - break; - default: - fprintf (stderr, - "unhandled relocation type %lx in section %d", - ELF_R_TYPE(rela->r_info), rel_shdr->sh_info); - status = -1; - } - } - } - } - } - return status; -} - -void -coff_add_fixup_entry (uint16_t val) -{ - *coff_entry_rel = val; - coff_entry_rel++; - coff_base_rel->block_size += 2; - coff_offset += 2; -} - -void -coff_add_fixup (uint32_t offset, uint8_t type) -{ - if (coff_base_rel == NULL - || coff_base_rel->page_rva != (offset & ~0xfff)) { - if (coff_base_rel != NULL) { - /* Add a null entry (is it required ?) */ - coff_add_fixup_entry (0); - /* Pad for alignment. */ - if (coff_offset % 4 != 0) - coff_add_fixup_entry (0); - } - - coff_file = realloc - (coff_file, - coff_offset + sizeof(struct pe32_fixup_block) + 2*0x1000); - memset(coff_file + coff_offset, 0, - sizeof(struct pe32_fixup_block) + 2*0x1000); - - coff_base_rel = (struct pe32_fixup_block*)(coff_file + coff_offset); - coff_base_rel->page_rva = offset & ~0xfff; - coff_base_rel->block_size = sizeof(struct pe32_fixup_block); - - coff_entry_rel = (uint16_t *)(coff_base_rel + 1); - coff_offset += sizeof(struct pe32_fixup_block); - } - - /* Fill the entry. */ - coff_add_fixup_entry ((type << 12) | (offset & 0xfff)); -} - -int -write_relocations(void) -{ - uint32_t idx; - struct pe32_nt_header *nt_hdr; - struct pe32_data_directory *dir; - int status = 0; - - for (idx = 0; idx < ehdr->e_shnum; idx++) - { - Elf_Shdr *rel_shdr = get_shdr_by_index (idx); - if (rel_shdr->sh_type == SHT_REL) - { - Elf_Shdr *sec_shdr = get_shdr_by_index (rel_shdr->sh_info); - if (is_text_shdr(sec_shdr) || is_data_shdr(sec_shdr)) - { - uint32_t rel_idx; - for (rel_idx = 0; - rel_idx < rel_shdr->sh_size; - rel_idx += rel_shdr->sh_entsize) - { - Elf_Rel *rel = (Elf_Rel *) - ((uint8_t*)ehdr + rel_shdr->sh_offset + rel_idx); - - switch (ELF_R_TYPE(rel->r_info)) - { - case R_386_NONE: - case R_386_PC32: - break; - case R_386_32: - coff_add_fixup(coff_sections_offset[rel_shdr->sh_info] - + (rel->r_offset - sec_shdr->sh_addr), - PE32_REL_BASED_HIGHLOW); - break; - default: - fprintf (stderr, "unhandled relocation type %lx", - ELF_R_TYPE(rel->r_info)); - status = -1; - } - } - } - } - else if (rel_shdr->sh_type == SHT_RELA) - { - Elf_Shdr *sec_shdr = get_shdr_by_index(rel_shdr->sh_info); - if (rel_shdr->sh_info == 0 - || is_text_shdr(sec_shdr) || is_data_shdr(sec_shdr)) - { - uint32_t rel_idx; - for (rel_idx = 0; - rel_idx < rel_shdr->sh_size; - rel_idx += rel_shdr->sh_entsize) { - Elf_Rela *rela = (Elf_Rela *) - ((uint8_t*)ehdr + rel_shdr->sh_offset + rel_idx); - uint32_t Loc = coff_sections_offset[rel_shdr->sh_info] - + (rela->r_offset - sec_shdr->sh_addr); - - switch (ELF_R_TYPE(rela->r_info)) - { - case R_IA64_IPLTLSB: - coff_add_fixup(Loc, PE32_REL_BASED_DIR64); - coff_add_fixup(Loc + 8, PE32_REL_BASED_DIR64); - break; - case R_IA64_REL64LSB: - coff_add_fixup(Loc, PE32_REL_BASED_DIR64); - break; - case R_IA64_DIR64LSB: - coff_add_fixup(Loc, PE32_REL_BASED_DIR64); - break; - case R_IA64_IMM64: - coff_add_fixup(Loc, PE32_REL_BASED_IA64_IMM64); - break; - case R_IA64_PCREL21B: - case R_IA64_PCREL64LSB: - case R_IA64_SECREL32LSB: - case R_IA64_SEGREL64LSB: - break; - case R_IA64_GPREL22: - case R_IA64_LTOFF22X: - case R_IA64_LDXMOV: - case R_IA64_LTOFF_FPTR22: - case R_IA64_NONE: - break; - default: - fprintf (stderr, "unhandled relocation type %lx", - ELF_R_TYPE(rela->r_info)); - status = -1; - } - } - } - } - } - -#ifdef ELF2PE_IA64 - coff_add_fixup (coff_entry_descr_offset, PE32_REL_BASED_DIR64); - coff_add_fixup (coff_entry_descr_offset + 8, PE32_REL_BASED_DIR64); -#endif - - /* Pad by adding empty entries. */ - while (coff_offset & (coff_alignment - 1)) - coff_add_fixup_entry (0); - - create_section_header (".reloc", reloc_offset, coff_offset - reloc_offset, - PE32_SCN_CNT_INITIALIZED_DATA - | PE32_SCN_MEM_DISCARDABLE - | PE32_SCN_MEM_READ); - - nt_hdr = (struct pe32_nt_header *)(coff_file + nt_hdr_offset); - dir = &nt_hdr->optional_header.base_relocation_table; - dir->rva = reloc_offset; - dir->size = coff_offset - reloc_offset; - - return status; -} - -void -write_debug(void) -{ - uint32_t len = strlen(filename) + 1; - uint32_t debug_offset = coff_offset; - struct pe32_nt_header *nt_hdr; - struct pe32_data_directory *data_dir; - struct pe32_debug_directory_entry *dir; - struct pe32_debug_codeview_nb10_entry *nb10; - - coff_offset += sizeof (struct pe32_debug_directory_entry) - + sizeof(struct pe32_debug_codeview_nb10_entry) - + len; - coff_offset = coff_align(coff_offset); - - coff_file = realloc - (coff_file, coff_offset); - memset(coff_file + debug_offset, 0, coff_offset - debug_offset); - - dir = (struct pe32_debug_directory_entry*)(coff_file + debug_offset); - dir->type = PE32_DEBUG_TYPE_CODEVIEW; - dir->data_size = sizeof(struct pe32_debug_directory_entry) + len; - dir->rva = debug_offset + sizeof(struct pe32_debug_directory_entry); - dir->file_offset = debug_offset + sizeof(struct pe32_debug_directory_entry); - - nb10 = (struct pe32_debug_codeview_nb10_entry*)(dir + 1); - nb10->signature = PE32_CODEVIEW_SIGNATURE_NB10; - strcpy (nb10->filename, filename); - - create_section_header (".debug", debug_offset, coff_offset - debug_offset, - PE32_SCN_CNT_INITIALIZED_DATA - | PE32_SCN_MEM_DISCARDABLE - | PE32_SCN_MEM_READ); - - nt_hdr = (struct pe32_nt_header *)(coff_file + nt_hdr_offset); - data_dir = &nt_hdr->optional_header.debug; - data_dir->rva = debug_offset; - data_dir->size = coff_offset - debug_offset; -} - -int -convert_elf (uint8_t **file_buffer, unsigned int *file_length) -{ - struct pe32_nt_header *nt_hdr; - - /* Check header, read section table. */ - ehdr = (Elf_Ehdr*)*file_buffer; - if (!check_elf_header ()) - return -1; - - /* Compute sections new address. */ - if (scan_sections () != 0) - return -2; - - /* Write and relocate sections. */ - if (write_sections (is_text_shdr) != 0) - return -3; - -#ifdef ELF2PE_IA64 - *(uint64_t*)(coff_file + coff_entry_descr_offset) = coff_entry_descr_func; - *(uint64_t*)(coff_file + coff_entry_descr_offset + 8) = plt_base; -#endif - - if (write_sections (is_data_shdr) != 0) - return -4; - - /* Translate and write relocations. */ - if (write_relocations () != 0) - return -5; - - /* Write debug info. */ - write_debug (); - - nt_hdr = (struct pe32_nt_header *)(coff_file + nt_hdr_offset); - nt_hdr->optional_header.image_size = coff_offset; - - nt_hdr->optional_header.subsystem = PE32_SUBSYSTEM_EFI_APPLICATION; - - /* Replace. */ - free (*file_buffer); - *file_buffer = coff_file; - *file_length = coff_offset; - - return 0; -} - -int -main (int argc, char **argv) -{ - FILE *f; - unsigned int size; - uint8_t *buffer; - const char *outfile; - int status; - - if (argc != 3) - { - fprintf (stderr, "usage: %s elf-file pe-file\n", argv[0]); - exit (1); - } - - filename = argv[1]; - outfile = argv[2]; - f = fopen (filename, "rb"); - fseek (f, 0, SEEK_END); - size = ftell (f); - fseek (f, 0, SEEK_SET); - - buffer = malloc (size); - if (buffer == NULL) - { - fprintf (stderr, "cannot allocate %u bytes of memory\n", size); - exit (2); - } - if (fread (buffer, size, 1, f) != 1) - { - fprintf (stderr, "cannot read %s\n", filename); - exit (2); - } - fclose (f); - - if (!is_elf_header (buffer)) - { - fprintf (stderr, "%s is not an elf file\n", filename); - exit (2); - } - - status = convert_elf (&buffer, &size); - if (status != 0) - { - fprintf (stderr, "cannot convert %s to pe (err=%d)\n", filename, status); - exit (2); - } - - f = fopen (outfile, "wb"); - if (f == NULL) - { - fprintf (stderr, "cannot open %s\n", outfile); - exit (2); - } - if (fwrite (buffer, size, 1, f) != 1) - { - fprintf (stderr, "cannot write to %s\n", outfile); - exit (2); - } - fclose (f); - - return 0; -} diff --git a/util/ia64/efi/grub-install.in b/util/ia64/efi/grub-install.in deleted file mode 100644 index 63b0c9f6c..000000000 --- a/util/ia64/efi/grub-install.in +++ /dev/null @@ -1,233 +0,0 @@ -#! /bin/sh - -# Install GRUB on your EFI partition. -# Copyright (C) 1999,2000,2001,2002,2003,2004,2005,2006,2007,2008 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 . - - -# Initialize some variables. -prefix=@prefix@ -exec_prefix=@exec_prefix@ -sbindir=@sbindir@ -bindir=@bindir@ -libdir=@libdir@ -datadir=@datadir@ -PACKAGE_NAME=@PACKAGE_NAME@ -PACKAGE_TARNAME=@PACKAGE_TARNAME@ -PACKAGE_VERSION=@PACKAGE_VERSION@ -target_cpu=@target_cpu@ -platform=@platform@ -pkglibdir=${libdir}/${PACKAGE_TARNAME}/${target_cpu}-${platform} -pkgdatadir=${datadir}/${PACKAGE_TARNAME} - - -TARGET_CC=@TARGET_CC@ -TARGET_CFLAGS="@TARGET_CFLAGS@" -TARGET_CPPFLAGS="@TARGET_CPPFLAGS@" -TARGET_LDFLAGS="@TARGET_LDFLAGS@" -OBJCOPY=@OBJCOPY@ - -grub_setup=${sbindir}/grub-setup -grub_mkimage=${bindir}/grub-mkimage -grub_mkdevicemap=${sbindir}/grub-mkdevicemap -grub_probefs=${sbindir}/grub-probefs -rootdir= -grub_prefix=/boot/grub -modules= - -install_device= -recheck=no -debug=no - -# Usage: usage -# Print the usage. -usage () { - cat <. -EOF -} - -# Check the arguments. -for option in "$@"; do - case "$option" in - -h | --help) - usage - exit 0 ;; - -v | --version) - echo "grub-install (GNU GRUB ${PACKAGE_VERSION})" - exit 0 ;; - --modules=*) - modules=`echo "$option" | sed 's/--modules=//'` ;; - --root-directory=*) - rootdir=`echo "$option" | sed 's/--root-directory=//'` ;; - --grub-setup=*) - grub_setup=`echo "$option" | sed 's/--grub-setup=//'` ;; - --grub-mkimage=*) - grub_mkimage=`echo "$option" | sed 's/--grub-mkimage=//'` ;; - --grub-mkdevicemap=*) - grub_mkdevicemap=`echo "$option" | sed 's/--grub-mkdevicemap=//'` ;; - --grub-probefs=*) - grub_probefs=`echo "$option" | sed 's/--grub-probefs=//'` ;; - --pkglibdir=*) - pkglibdir=`echo "$option" | sed 's/--pkglibdir=//'` ;; - --pkgdatadir=*) - pkgdatadir=`echo "$option" | sed 's/--pkgdatadir=//'` ;; - --recheck) - recheck=yes ;; - # This is an undocumented feature... - --debug) - debug=yes ;; - -*) - echo "Unrecognized option \`$option'" 1>&2 - usage - exit 1 - ;; - *) - if test "x$install_device" != x; then - echo "More than one install_devices?" 1>&2 - usage - exit 1 - fi - install_device="${option}" ;; - esac -done - -#if test "x$install_device" = x; then -# echo "install_device not specified." 1>&2 -# usage -# exit 1 -#fi - -# If the debugging feature is enabled, print commands. -if test $debug = yes; then - set -x -fi - -# Initialize these directories here, since ROOTDIR was initialized. -bootdir=${rootdir}/boot/efi - -grubdir=${bootdir}/grub -device_map=${grubdir}/device.map - -# Create the GRUB directory if it is not present. -test -d "$bootdir" || mkdir "$bootdir" || exit 1 -test -d "$grubdir" || mkdir "$grubdir" || exit 1 - -# Copy the GRUB images to the GRUB directory. -if false; then - for file in ${grubdir}/*.mod ${grubdir}/*.lst; do - if test -f $file; then - rm -f $file || exit 1 - fi - done - for file in ${pkglibdir}/*.mod ${pkglibdir}/*.lst; do - cp -f $file ${grubdir} || exit 1 - done -fi - -# Create the core image. First, auto-detect the filesystme module. -#fs_module=`$grub_probefs --device-map=${device_map} ${grubdir}` -#if test "x$fs_module" = x -a "x$modules" = x; then -# echo "Auto-detection of a filesystem module failed." 1>&2 -# echo "Please specify the module with the option \`--modules' explicitly." 1>&2 -# exit 1 -#fi - -# Typically, _chain and pc are required. -modules="$modules $fs_module _chain" - -modules="kernel gzio gpt fat normal ls cat fshelp help _linux linux $modules" -modules="$modules memmap systab boot" - -if [ $debug = yes ]; then - tmpdir=. -else - tmpdir=`mktemp -d /tmp/grub.XXXXXXXXXX` || exit 1 - trap "rm -rf $tmpdir" 1 2 13 15 -fi - -# Generate init/fini for modules. -modfile=$tmpdir/mod.c -echo "/* Dummy modules. */" > $modfile -list="" -init_list="" -fini_list="" -for m in $modules; do - file="$pkglibdir/${m}.mod" - name=`nm $file | sed -n "/ r grub_module_name/ s/.* r grub_module_name_\(.*\)/\1/p"` - init=`nm $file | sed -n "/ T grub_module_.*_init/ s/.* T //p"` - fini=`nm $file | sed -n "/ T grub_module_.*_fini/ s/.* T //p"` - init_list="$init_list $init" - fini_list="$fini_list $fini" - arg="\"$name\",${init:-0},${fini:-0}" - list="$list $arg" -done -echo "extern void grub_init_module (const char *, void (*init)(void *), void (*fini)(void));" >> $modfile -echo "extern void grub_init_modules (void);" >> $modfile -for m in $init_list; do - echo "extern void $m(void *);" >> $modfile -done -for m in $fini_list; do - echo "extern void $m(void);" >> $modfile -done -echo "void grub_init_modules (void)" >> $modfile -echo "{" >> $modfile -for m in $list; do - echo " grub_init_module($m);" >> $modfile -done -echo "}" >> $modfile - -$TARGET_CC -c $TARGET_CFLAGS -o $tmpdir/mod.o $modfile - -mod_objs= -for m in $modules; do mod_objs="$mod_objs $pkglibdir/${m}.mod"; done - -ld -pie -nostdlib -T $pkgdatadir/elf_ia64_efi.lds \ - $mod_objs $tmpdir/mod.o -o $tmpdir/grub.elf - - -if ! $bindir/grub-elf2pe $tmpdir/grub.elf $grubdir/grub.efi; then - echo "Failed to build efi binary" - [ $debug = no ] && rm -rf $tmpdir - exit 1 -fi - -echo "grub.efi generated" - -[ $debug = no ] && rm -rf $tmpdir - -# Bye. -exit 0 diff --git a/util/ia64/efi/pe32.h b/util/ia64/efi/pe32.h deleted file mode 100644 index 391e70c26..000000000 --- a/util/ia64/efi/pe32.h +++ /dev/null @@ -1,237 +0,0 @@ -/* pe32.h - PE/Coff definitions. */ -/* - * GRUB -- GRand Unified Bootloader - * Copyright (C) 2008 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 . - */ -#ifdef USE_PE32PLUS -typedef uint64_t pe32_uintptr_t; -#else -typedef uint32_t pe32_uintptr_t; -#endif - -struct pe32_coff_header -{ - uint16_t machine; - uint16_t num_sections; - uint32_t time; - uint32_t symtab_offset; - uint32_t num_symbols; - uint16_t optional_header_size; - uint16_t characteristics; -}; - -#define PE32_MACHINE_I386 0x014c -#define PE32_MACHINE_IA64 0x0200 -#define PE32_MACHINE_EBC 0x0EBC -#define PE32_MACHINE_X64 0x8664 - -#define PE32_RELOCS_STRIPPED 0x0001 -#define PE32_EXECUTABLE_IMAGE 0x0002 -#define PE32_LINE_NUMS_STRIPPED 0x0004 -#define PE32_LOCAL_SYMS_STRIPPED 0x0008 -#define PE32_AGGRESSIVE_WS_TRIM 0x0010 -#define PE32_LARGE_ADDRESS_AWARE 0x0020 -#define PE32_16BIT_MACHINE 0x0040 -#define PE32_BYTES_REVERSED_LO 0x0080 -#define PE32_32BIT_MACHINE 0x0100 -#define PE32_DEBUG_STRIPPED 0x0200 -#define PE32_REMOVABLE_RUN_FROM_SWAP 0x0400 -#define PE32_SYSTEM 0x1000 -#define PE32_DLL 0x2000 -#define PE32_UP_SYSTEM_ONLY 0x4000 -#define PE32_BYTES_REVERSED_HI 0x8000 - -struct pe32_data_directory -{ - uint32_t rva; - uint32_t size; -}; - -struct pe32_optional_header -{ - uint16_t magic; - uint8_t major_linker_version; - uint8_t minor_linker_version; - uint32_t code_size; - uint32_t data_size; - uint32_t bss_size; - uint32_t entry_addr; - uint32_t code_base; - -#ifndef USE_PE32PLUS - uint32_t data_base; -#endif - - pe32_uintptr_t image_base; - uint32_t section_alignment; - uint32_t file_alignment; - uint16_t major_os_version; - uint16_t minor_os_version; - uint16_t major_image_version; - uint16_t minor_image_version; - uint16_t major_subsystem_version; - uint16_t minor_subsystem_version; - uint32_t reserved; - uint32_t image_size; - uint32_t header_size; - uint32_t checksum; - uint16_t subsystem; - uint16_t dll_characteristics; - pe32_uintptr_t stack_reserve_size; - pe32_uintptr_t stack_commit_size; - pe32_uintptr_t heap_reserve_size; - pe32_uintptr_t heap_commit_size; - uint32_t loader_flags; - uint32_t num_data_directories; - - /* Data directories. */ - struct pe32_data_directory export_table; - struct pe32_data_directory import_table; - struct pe32_data_directory resource_table; - struct pe32_data_directory exception_table; - struct pe32_data_directory certificate_table; - struct pe32_data_directory base_relocation_table; - struct pe32_data_directory debug; - struct pe32_data_directory architecture; - struct pe32_data_directory global_ptr; - struct pe32_data_directory tls_table; - struct pe32_data_directory load_config_table; - struct pe32_data_directory bound_import; - struct pe32_data_directory iat; - struct pe32_data_directory delay_import_descriptor; - struct pe32_data_directory com_runtime_header; - struct pe32_data_directory reserved_entry; -}; - -#define PE32_PE32_MAGIC 0x10b -#define PE32_PE64_MAGIC 0x20b - -#define PE32_SUBSYSTEM_EFI_APPLICATION 10 -#define PE32_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER 11 -#define PE32_SUBSYSTEM_EFI_RUNTIME_DRIVER 12 -#define PE32_SUBSYSTEM_EFI_EFI_ROM 13 - -#define PE32_NUM_DATA_DIRECTORIES 16 - -struct pe32_section_header -{ - char name[8]; - uint32_t virtual_size; - uint32_t virtual_address; - uint32_t raw_data_size; - uint32_t raw_data_offset; - uint32_t relocations_offset; - uint32_t line_numbers_offset; - uint16_t num_relocations; - uint16_t num_line_numbers; - uint32_t characteristics; -}; - -#define PE32_SCN_CNT_CODE 0x00000020 -#define PE32_SCN_CNT_INITIALIZED_DATA 0x00000040 -#define PE32_SCN_MEM_DISCARDABLE 0x02000000 -#define PE32_SCN_MEM_EXECUTE 0x20000000 -#define PE32_SCN_MEM_READ 0x40000000 -#define PE32_SCN_MEM_WRITE 0x80000000 - -struct pe32_dos_header -{ - uint16_t magic; // Magic number - uint16_t cblp; // Bytes on last page of file - uint16_t cp; // Pages in file - uint16_t crlc; // Relocations - uint16_t cparhdr; // Size of header in paragraphs - uint16_t minalloc; // Minimum extra paragraphs needed - uint16_t maxalloc; // Maximum extra paragraphs needed - uint16_t ss; // Initial (relative) SS value - uint16_t sp; // Initial SP value - uint16_t csum; // Checksum - uint16_t ip; // Initial IP value - uint16_t cs; // Initial (relative) CS value - uint16_t lfa_rlc; // File address of relocation table - uint16_t ov_no; // Overlay number - uint16_t res[4]; // Reserved words - uint16_t oem_id; // OEM identifier (for e_oeminfo) - uint16_t oem_info; // OEM information; e_oemid specific - uint16_t res2[10]; // Reserved words - uint32_t new_hdr_offset; - - uint16_t stub[0x20]; -}; - -struct pe32_nt_header -{ - /* This is always PE\0\0. */ - char signature[4]; - - /* The COFF file header. */ - struct pe32_coff_header coff_header; - - /* The Optional header. */ - struct pe32_optional_header optional_header; -}; - -struct pe32_base_relocation -{ - uint32_t page_rva; - uint32_t block_size; -}; - -struct pe32_fixup_block -{ - uint32_t page_rva; - uint32_t block_size; - uint16_t entries[0]; -}; - -#define PE32_FIXUP_ENTRY(type, offset) (((type) << 12) | (offset)) - -#define PE32_REL_BASED_ABSOLUTE 0 -#define PE32_REL_BASED_HIGHLOW 3 -#define PE32_REL_BASED_IA64_IMM64 9 -#define PE32_REL_BASED_DIR64 10 - -#define PE32_DEBUG_TYPE_CODEVIEW 2 -struct pe32_debug_directory_entry { - uint32_t characteristics; - uint32_t time; - uint16_t major_version; - uint16_t minor_version; - uint32_t type; - uint32_t data_size; - uint32_t rva; - uint32_t file_offset; -}; - -#define PE32_CODEVIEW_SIGNATURE_NB10 0x3031424E // "NB10" -struct pe32_debug_codeview_nb10_entry { - uint32_t signature; // "NB10" - uint32_t unknown[3]; - char filename[0]; /* Filename of .PDB */ -}; - - -#if 1 -#define pe32_check(name, x) extern char pe32_check_##name [x ? 1 : -1] -#ifdef USE_PE32PLUS -#define PE32_HEADER_SIZE 112 -#else -#define PE32_HEADER_SIZE 96 -#endif - -pe32_check(optional_header, sizeof (struct pe32_optional_header) == PE32_HEADER_SIZE + PE32_NUM_DATA_DIRECTORIES * 8); -#endif - From c18271ed0042a870b84476b6b20241e884ed5792 Mon Sep 17 00:00:00 2001 From: phcoder Date: Mon, 3 Jan 2011 02:28:14 +0100 Subject: [PATCH 184/869] Fix compilation errors --- grub-core/Makefile.am | 1 - grub-core/Makefile.core.def | 9 ++++++--- grub-core/kern/ia64/efi/init.c | 2 -- grub-core/kern/ia64/efi/startup.S | 13 +++++++++++++ grub-core/lib/efi/halt.c | 2 ++ grub-core/loader/ia64/efi/linux.c | 7 +++---- include/grub/efi/api.h | 2 +- include/grub/offsets.h | 6 ++++++ 8 files changed, 31 insertions(+), 11 deletions(-) diff --git a/grub-core/Makefile.am b/grub-core/Makefile.am index 5481d9ebb..df691a586 100644 --- a/grub-core/Makefile.am +++ b/grub-core/Makefile.am @@ -130,7 +130,6 @@ if COND_ia64_efi KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/efi/efi.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/efi/time.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/efi/disk.h -KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/ia64/efi/misc.h endif if COND_mips_yeeloong diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def index ff5bf7a30..4581b79cf 100644 --- a/grub-core/Makefile.core.def +++ b/grub-core/Makefile.core.def @@ -126,8 +126,8 @@ kernel = { x86_64_efi = kern/i386/efi/init.c; ia64_efi = kern/ia64/efi/startup.S; - ia64_efi = kern/ia64/trampoline.S; ia64_efi = kern/ia64/efi/init.c; + ia64_efi = kern/ia64/dl.c; i386_pc = kern/i386/pc/init.c; i386_pc = kern/i386/pc/mmap.c; @@ -575,7 +575,8 @@ module = { i386_pc = commands/acpihalt.c; i386_coreboot = commands/acpihalt.c; i386_multiboot = commands/acpihalt.c; - x86_efi = commands/acpihalt.c; + i386_efi = commands/acpihalt.c; + x86_64_efi = commands/acpihalt.c; i386_multiboot = lib/i386/halt.c; i386_coreboot = lib/i386/halt.c; i386_qemu = lib/i386/halt.c; @@ -1244,6 +1245,7 @@ module = { mips_yeeloong = mmap/mips/yeeloong/uppermem.c; enable = x86; + enable = ia64_efi; enable = mips_yeeloong; }; @@ -1435,7 +1437,8 @@ module = { module = { name = efi_uga; efi = video/efi_uga.c; - enable = efi; + enable = i386_efi; + enable = x86_64_efi; }; module = { diff --git a/grub-core/kern/ia64/efi/init.c b/grub-core/kern/ia64/efi/init.c index 06d5f5095..13a81a66e 100644 --- a/grub-core/kern/ia64/efi/init.c +++ b/grub-core/kern/ia64/efi/init.c @@ -25,13 +25,11 @@ #include #include #include -#include void grub_machine_init (void) { grub_efi_init (); - grub_init_modules (); } void diff --git a/grub-core/kern/ia64/efi/startup.S b/grub-core/kern/ia64/efi/startup.S index 9ba6858d9..fcaf4e189 100644 --- a/grub-core/kern/ia64/efi/startup.S +++ b/grub-core/kern/ia64/efi/startup.S @@ -15,6 +15,10 @@ * You should have received a copy of the GNU General Public License * along with GRUB. If not, see . */ +#include +#include +#include + .text .psr abi64 .psr lsb @@ -38,3 +42,12 @@ _start: br.ret.sptk.few rp .endp _start + + . = _start + GRUB_KERNEL_MACHINE_PREFIX +VARIABLE(grub_prefix) + /* to be filled by grub-mkimage */ + + /* + * Leave some breathing room for the prefix. + */ + . = _start + GRUB_KERNEL_MACHINE_PREFIX_END diff --git a/grub-core/lib/efi/halt.c b/grub-core/lib/efi/halt.c index c19536897..5ebf2cd1d 100644 --- a/grub-core/lib/efi/halt.c +++ b/grub-core/lib/efi/halt.c @@ -28,7 +28,9 @@ void grub_halt (void) { grub_machine_fini (); +#ifndef __ia64__ grub_acpi_halt (); +#endif efi_call_4 (grub_efi_system_table->runtime_services->reset_system, GRUB_EFI_RESET_SHUTDOWN, GRUB_EFI_SUCCESS, 0, NULL); diff --git a/grub-core/loader/ia64/efi/linux.c b/grub-core/loader/ia64/efi/linux.c index d9b4c338b..b018e4549 100644 --- a/grub-core/loader/ia64/efi/linux.c +++ b/grub-core/loader/ia64/efi/linux.c @@ -30,7 +30,6 @@ #include #include #include -#include #define ALIGN_MIN (256*1024*1024) @@ -512,7 +511,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), goto fail; } - file = grub_gzfile_open (argv[0], 1); + file = grub_file_open (argv[0]); if (! file) { grub_error (GRUB_ERR_BAD_ARGUMENT, "Couldn't open file"); @@ -594,7 +593,7 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), goto fail; } - file = grub_gzfile_open (argv[0], 1); + file = grub_file_open (argv[0]); if (! file) goto fail; @@ -644,7 +643,7 @@ grub_cmd_payload (grub_command_t cmd __attribute__ ((unused)), goto fail; } - file = grub_gzfile_open (argv[0], 1); + file = grub_file_open (argv[0]); if (! file) goto fail; diff --git a/include/grub/efi/api.h b/include/grub/efi/api.h index cb6b1113b..ded03a1b3 100644 --- a/include/grub/efi/api.h +++ b/include/grub/efi/api.h @@ -1234,7 +1234,7 @@ struct grub_efi_block_io }; typedef struct grub_efi_block_io grub_efi_block_io_t; -#if GRUB_TARGET_SIZEOF_VOID_P == 4 +#if (GRUB_TARGET_SIZEOF_VOID_P == 4) || defined (__ia64__) #define efi_call_0(func) func() #define efi_call_1(func, a) func(a) diff --git a/include/grub/offsets.h b/include/grub/offsets.h index 817372b69..55b0f8fb8 100644 --- a/include/grub/offsets.h +++ b/include/grub/offsets.h @@ -117,6 +117,12 @@ /* End of the data section. */ #define GRUB_KERNEL_I386_EFI_PREFIX_END 0x50 +/* The offset of GRUB_PREFIX. */ +#define GRUB_KERNEL_IA64_EFI_PREFIX 0x50 + +/* End of the data section. */ +#define GRUB_KERNEL_IA64_EFI_PREFIX_END 0xa0 + /* The offset of GRUB_PREFIX. */ #define GRUB_KERNEL_X86_64_EFI_PREFIX 0x8 From bea33583891ad31f7673a377244defa4e393c8b7 Mon Sep 17 00:00:00 2001 From: phcoder Date: Mon, 3 Jan 2011 13:46:36 +0100 Subject: [PATCH 185/869] First handling of ia64-efi in grub-mkimage --- grub-core/Makefile.core.def | 4 ++-- include/grub/efi/pe32.h | 1 + util/grub-mkimage.c | 34 +++++++++++++++++++++++++++++---- util/grub-mkimagexx.c | 38 ++++++++++++++++++++++++++++--------- 4 files changed, 62 insertions(+), 15 deletions(-) diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def index 4581b79cf..c21c38763 100644 --- a/grub-core/Makefile.core.def +++ b/grub-core/Makefile.core.def @@ -24,8 +24,8 @@ kernel = { x86_64_efi_stripflags = '--strip-unneeded -K start -R .note -R .comment'; ia64_efi_cflags = '-fno-builtin -fpic -minline-int-divide-max-throughput'; - ia64_efi_ldflags = '-melf_64'; - ia64_efi_stripflags = '-R .note -R .comment -X'; + ia64_efi_ldflags = '-Wl,-r,-d'; + ia64_efi_stripflags = '--strip-unneeded -K start -R .note -R .comment'; i386_pc_ldflags = '$(TARGET_IMG_LDFLAGS)'; i386_pc_ldflags = '$(TARGET_IMG_BASE_LDOPT),0x8200'; diff --git a/include/grub/efi/pe32.h b/include/grub/efi/pe32.h index 81a1a5797..c3efa9b3d 100644 --- a/include/grub/efi/pe32.h +++ b/include/grub/efi/pe32.h @@ -64,6 +64,7 @@ struct grub_pe32_coff_header }; #define GRUB_PE32_MACHINE_I386 0x14c +#define GRUB_PE32_MACHINE_IA64 0x200 #define GRUB_PE32_MACHINE_X86_64 0x8664 #define GRUB_PE32_RELOCS_STRIPPED 0x0001 diff --git a/util/grub-mkimage.c b/util/grub-mkimage.c index 53e867602..507a7a80d 100644 --- a/util/grub-mkimage.c +++ b/util/grub-mkimage.c @@ -86,6 +86,7 @@ struct image_target_desc grub_uint64_t link_addr; unsigned mod_gap, mod_align; grub_compression_t default_compression; + grub_uint16_t pe_target; }; struct image_target_desc image_targets[] = @@ -191,6 +192,8 @@ struct image_target_desc image_targets[] = GRUB_PE32_SECTION_ALIGNMENT), .install_dos_part = TARGET_NO_FIELD, .install_bsd_part = TARGET_NO_FIELD, + .pe_target = GRUB_PE32_MACHINE_I386, + .elf_target = EM_386, }, { .name = "i386-ieee1275", @@ -253,6 +256,8 @@ struct image_target_desc image_targets[] = GRUB_PE32_SECTION_ALIGNMENT), .install_dos_part = TARGET_NO_FIELD, .install_bsd_part = TARGET_NO_FIELD, + .pe_target = GRUB_PE32_MACHINE_X86_64, + .elf_target = EM_X86_64, }, { .name = "mipsel-yeeloong-flash", @@ -354,6 +359,30 @@ struct image_target_desc image_targets[] = .install_bsd_part = TARGET_NO_FIELD, .link_addr = GRUB_KERNEL_SPARC64_IEEE1275_LINK_ADDR }, + { + .name = "ia64-efi", + .voidp_sizeof = 8, + .bigendian = 0, + .id = IMAGE_EFI, + .flags = PLATFORM_FLAGS_NONE, + .prefix = GRUB_KERNEL_IA64_EFI_PREFIX, + .prefix_end = GRUB_KERNEL_IA64_EFI_PREFIX_END, + .raw_size = 0, + .total_module_size = TARGET_NO_FIELD, + .kernel_image_size = TARGET_NO_FIELD, + .compressed_size = TARGET_NO_FIELD, + .section_align = GRUB_PE32_SECTION_ALIGNMENT, + .vaddr_offset = ALIGN_UP (GRUB_PE32_MSDOS_STUB_SIZE + + GRUB_PE32_SIGNATURE_SIZE + + sizeof (struct grub_pe32_coff_header) + + sizeof (struct grub_pe64_optional_header) + + 4 * sizeof (struct grub_pe32_section_table), + GRUB_PE32_SECTION_ALIGNMENT), + .install_dos_part = TARGET_NO_FIELD, + .install_bsd_part = TARGET_NO_FIELD, + .pe_target = GRUB_PE32_MACHINE_IA64, + .elf_target = EM_IA_64, + }, }; #define grub_target_to_host32(x) (grub_target_to_host32_real (image_target, (x))) @@ -927,10 +956,7 @@ generate_image (const char *dir, char *prefix, FILE *out, char *mods[], /* The COFF file header. */ c = (struct grub_pe32_coff_header *) (header + GRUB_PE32_MSDOS_STUB_SIZE + GRUB_PE32_SIGNATURE_SIZE); - if (image_target->voidp_sizeof == 4) - c->machine = grub_host_to_target16 (GRUB_PE32_MACHINE_I386); - else - c->machine = grub_host_to_target16 (GRUB_PE32_MACHINE_X86_64); + c->machine = grub_host_to_target16 (image_target->pe_target); c->num_sections = grub_host_to_target16 (4); c->time = grub_host_to_target32 (time (0)); diff --git a/util/grub-mkimagexx.c b/util/grub-mkimagexx.c index ce51f2fbc..20cbacf15 100644 --- a/util/grub-mkimagexx.c +++ b/util/grub-mkimagexx.c @@ -101,9 +101,9 @@ SUFFIX (relocate_symbols) (Elf_Ehdr *e, Elf_Shdr *sections, else if (index >= num_sections) grub_util_error ("section %d does not exist", index); - sym->st_value = (grub_target_to_host32 (sym->st_value) + sym->st_value = (grub_target_to_host (sym->st_value) + section_addresses[index]); - grub_util_info ("locating %s at 0x%x", name, sym->st_value); + grub_util_info ("locating %s at 0x%x", name, sym->st_value, section_addresses[index]); if (! start_address) if (strcmp (name, "_start") == 0 || strcmp (name, "start") == 0) @@ -200,7 +200,9 @@ SUFFIX (relocate_addresses) (Elf_Ehdr *e, Elf_Shdr *sections, addend = (s->sh_type == grub_target_to_host32 (SHT_RELA)) ? r->r_addend : 0; - if (image_target->voidp_sizeof == 4) + switch (image_target->elf_target) + { + case EM_386: switch (ELF_R_TYPE (info)) { case R_386_NONE: @@ -224,11 +226,12 @@ SUFFIX (relocate_addresses) (Elf_Ehdr *e, Elf_Shdr *sections, *target, offset); break; default: - grub_util_error ("unknown relocation type %d", + grub_util_error ("unknown relocation type 0x%x", ELF_R_TYPE (info)); break; } - else + break; + case EM_X86_64: switch (ELF_R_TYPE (info)) { @@ -270,6 +273,20 @@ SUFFIX (relocate_addresses) (Elf_Ehdr *e, Elf_Shdr *sections, ELF_R_TYPE (info)); break; } + break; + case EM_IA_64: + switch (ELF_R_TYPE (info)) + { + default: + grub_util_error ("unknown relocation type 0x%x", + ELF_R_TYPE (info)); + break; + } + break; + default: + grub_util_error ("unknown architecture type %d", + image_target->elf_target); + } } } } @@ -417,8 +434,9 @@ SUFFIX (make_reloc_section) (Elf_Ehdr *e, void **out, info = grub_le_to_cpu32 (r->r_info); /* Necessary to relocate only absolute addresses. */ - if (image_target->voidp_sizeof == 4) + switch (image_target->elf_target) { + case EM_386: if (ELF_R_TYPE (info) == R_386_32) { Elf_Addr addr; @@ -431,9 +449,8 @@ SUFFIX (make_reloc_section) (Elf_Ehdr *e, void **out, addr, 0, current_address, image_target); } - } - else - { + break; + case EM_X86_64: if ((ELF_R_TYPE (info) == R_X86_64_32) || (ELF_R_TYPE (info) == R_X86_64_32S)) { @@ -452,6 +469,9 @@ SUFFIX (make_reloc_section) (Elf_Ehdr *e, void **out, 0, current_address, image_target); } + break; + default: + grub_util_error ("unknown machine type 0x%x", image_target->elf_target); } } } From 7021cb3e16f4c5c32289ede7d0c53f4d4cc850c9 Mon Sep 17 00:00:00 2001 From: phcoder Date: Mon, 3 Jan 2011 13:48:33 +0100 Subject: [PATCH 186/869] Fix incorrect usage of variables in grub-install --- util/grub-install.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/grub-install.in b/util/grub-install.in index b9e833360..716582dfd 100644 --- a/util/grub-install.in +++ b/util/grub-install.in @@ -648,7 +648,7 @@ elif [ x"$platform" = xefi ]; then efidir_disk="$(echo "$clean_devmap" | grep "^$(echo "$efidir_drive" | sed 's/,[^)]*//')" | cut -f2)" efidir_part="$(echo "$efidir_drive" | sed 's/^([^,]*,[^0-9]*//; s/[^0-9].*//')" efibootmgr $efi_quiet -c -d "$efidir_disk" -p "$efidir_part" -w \ - -L "$GRUB_DISTRIBUTOR" -l "\\EFI\\$efi_distributor\\$efi_file" + -L "$bootloader_id" -l "\\EFI\\$efi_distributor\\$efi_file" fi fi fi From 323a8e9c6413ea90030c24d663f4c4f12a7a1ffd Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 3 Jan 2011 14:16:42 +0100 Subject: [PATCH 187/869] * util/grub-mkfont.c (main): Report errors in FT_New_Face. --- ChangeLog | 4 ++++ util/grub-mkfont.c | 13 ++++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9881baee9..7f5a316fc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2011-01-03 Vladimir Serbinenko + + * util/grub-mkfont.c (main): Report errors in FT_New_Face. + 2010-12-31 Ian Campbell * util/grub.d/20_linux_xen.in (linux_entry): Correctly capitalize diff --git a/util/grub-mkfont.c b/util/grub-mkfont.c index fff6a619e..983ac7065 100644 --- a/util/grub-mkfont.c +++ b/util/grub-mkfont.c @@ -1146,11 +1146,18 @@ main (int argc, char *argv[]) { FT_Face ft_face; int size; + FT_Error err; - if (FT_New_Face (ft_lib, argv[optind], font_index, &ft_face)) + err = FT_New_Face (ft_lib, argv[optind], font_index, &ft_face); + if (err) { - grub_util_info ("can't open file %s, index %d", argv[optind], - font_index); + grub_printf ("can't open file %s, index %d: error %d", argv[optind], + font_index, err); + if (err > 0 && err < (signed) ARRAY_SIZE (ft_errmsgs)) + printf (": %s\n", ft_errmsgs[err]); + else + printf ("\n"); + continue; } From 469ee10a7f8637ce676fd3c8f43094f4235c020a Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 3 Jan 2011 14:33:43 +0100 Subject: [PATCH 188/869] * util/grub-install.in: Correctly use bootloader_id and not GRUB_DISTRIBUTOR on efibootmgr line. --- ChangeLog | 5 +++++ util/grub-install.in | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 7f5a316fc..f7b08c1e6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-01-03 Vladimir Serbinenko + + * util/grub-install.in: Correctly use bootloader_id and not + GRUB_DISTRIBUTOR on efibootmgr line. + 2011-01-03 Vladimir Serbinenko * util/grub-mkfont.c (main): Report errors in FT_New_Face. diff --git a/util/grub-install.in b/util/grub-install.in index b9e833360..716582dfd 100644 --- a/util/grub-install.in +++ b/util/grub-install.in @@ -648,7 +648,7 @@ elif [ x"$platform" = xefi ]; then efidir_disk="$(echo "$clean_devmap" | grep "^$(echo "$efidir_drive" | sed 's/,[^)]*//')" | cut -f2)" efidir_part="$(echo "$efidir_drive" | sed 's/^([^,]*,[^0-9]*//; s/[^0-9].*//')" efibootmgr $efi_quiet -c -d "$efidir_disk" -p "$efidir_part" -w \ - -L "$GRUB_DISTRIBUTOR" -l "\\EFI\\$efi_distributor\\$efi_file" + -L "$bootloader_id" -l "\\EFI\\$efi_distributor\\$efi_file" fi fi fi From 4af0504b724b89d7e8057e64a6260a4d04781ffd Mon Sep 17 00:00:00 2001 From: Dave Vasilevsky Date: Mon, 3 Jan 2011 15:30:41 +0100 Subject: [PATCH 189/869] * grub-core/fs/hfsplus.c: Make parent unsigned. (grub_hfsplus_cmp_catkey): Don't compare using subtraction, it overflows. (grub_hfsplus_cmp_extkey): Likewise --- ChangeLog | 7 +++++++ grub-core/fs/hfsplus.c | 33 +++++++++++++++++++++------------ 2 files changed, 28 insertions(+), 12 deletions(-) diff --git a/ChangeLog b/ChangeLog index f7b08c1e6..d89cb8618 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2011-01-03 Dave Vasilevsky + + * grub-core/fs/hfsplus.c: Make parent unsigned. + (grub_hfsplus_cmp_catkey): Don't compare using subtraction, it + overflows. + (grub_hfsplus_cmp_extkey): Likewise + 2011-01-03 Vladimir Serbinenko * util/grub-install.in: Correctly use bootloader_id and not diff --git a/grub-core/fs/hfsplus.c b/grub-core/fs/hfsplus.c index bcb8e9584..7d7115ce3 100644 --- a/grub-core/fs/hfsplus.c +++ b/grub-core/fs/hfsplus.c @@ -178,7 +178,7 @@ enum grub_hfsplus_filetype /* Internal representation of a catalog key. */ struct grub_hfsplus_catkey_internal { - int parent; + grub_uint32_t parent; char *name; }; @@ -520,9 +520,12 @@ grub_hfsplus_cmp_catkey (struct grub_hfsplus_key *keya, int i; int diff; - diff = grub_be_to_cpu32 (catkey_a->parent) - catkey_b->parent; - if (diff) - return diff; + /* Safe unsigned comparison */ + grub_uint32_t aparent = grub_be_to_cpu32 (catkey_a->parent); + if (aparent > catkey_b->parent) + return 1; + if (aparent < catkey_b->parent) + return -1; /* Change the filename in keya so the endianness is correct. */ for (i = 0; i < grub_be_to_cpu16 (catkey_a->namelen); i++) @@ -555,15 +558,21 @@ grub_hfsplus_cmp_extkey (struct grub_hfsplus_key *keya, { struct grub_hfsplus_extkey *extkey_a = &keya->extkey; struct grub_hfsplus_extkey_internal *extkey_b = &keyb->extkey; - int diff; + grub_uint32_t akey; - diff = grub_be_to_cpu32 (extkey_a->fileid) - extkey_b->fileid; - - if (diff) - return diff; - - diff = grub_be_to_cpu32 (extkey_a->start) - extkey_b->start; - return diff; + /* Safe unsigned comparison */ + akey = grub_be_to_cpu32 (extkey_a->fileid); + if (akey > extkey_b->fileid) + return 1; + if (akey < extkey_b->fileid) + return -1; + + akey = grub_be_to_cpu32 (extkey_a->start); + if (akey > extkey_b->start) + return 1; + if (akey < extkey_b->start) + return -1; + return 0; } static char * From fb7ab4a99ba343167d3d0c5a8affa38c8dc057bf Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 3 Jan 2011 15:54:59 +0100 Subject: [PATCH 190/869] add missing == 0 --- grub-core/net/net.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/grub-core/net/net.c b/grub-core/net/net.c index 54663f4b0..d3b4c74db 100644 --- a/grub-core/net/net.c +++ b/grub-core/net/net.c @@ -199,7 +199,7 @@ grub_cmd_deladdr (struct grub_command *cmd __attribute__ ((unused)), return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("one argument expected")); FOR_NET_NETWORK_LEVEL_INTERFACES (inter) - if (grub_strcmp (inter->name, args[1])) + if (grub_strcmp (inter->name, args[1]) == 0) break; if (inter == NULL) return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("address not found")); @@ -730,7 +730,7 @@ grub_cmd_dhcpopt (struct grub_command *cmd __attribute__ ((unused)), return grub_error (GRUB_ERR_BAD_ARGUMENT, "4 arguments expected"); FOR_NET_NETWORK_LEVEL_INTERFACES (inter) - if (grub_strcmp (inter->name, args[1])) + if (grub_strcmp (inter->name, args[1]) == 0) break; if (!inter) From 7a1d4deec9267fc56ed50507b5a7fa9d96e3b610 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 3 Jan 2011 15:59:20 +0100 Subject: [PATCH 191/869] Fix finalisation/restore --- grub-core/disk/ahci.c | 255 +++++++++++++++++++++++++++++++----------- 1 file changed, 192 insertions(+), 63 deletions(-) diff --git a/grub-core/disk/ahci.c b/grub-core/disk/ahci.c index b348ce3d0..c67dbbe7e 100644 --- a/grub-core/disk/ahci.c +++ b/grub-core/disk/ahci.c @@ -157,6 +157,98 @@ enum static struct grub_ahci_device *grub_ahci_devices; static int numdevs; +static int +init_port (struct grub_ahci_device *dev) +{ + struct grub_pci_dma_chunk *command_list; + struct grub_pci_dma_chunk *command_table; + grub_uint64_t endtime; + + command_list = grub_memalign_dma32 (1024, sizeof (struct grub_ahci_cmd_head)); + if (!command_list) + return 1; + + command_table = grub_memalign_dma32 (1024, + sizeof (struct grub_ahci_cmd_table)); + if (!command_table) + { + grub_dma_free (command_list); + return 1; + } + + grub_dprintf ("ahci", "found device ahci%d (port %d)\n", dev->num, dev->port); + + dev->hba->ports[dev->port].command &= ~GRUB_AHCI_HBA_PORT_CMD_FRE; + endtime = grub_get_time_ms () + 1000; + while ((dev->hba->ports[dev->port].command & GRUB_AHCI_HBA_PORT_CMD_FR)) + if (grub_get_time_ms () > endtime) + { + grub_dprintf ("ahci", "couldn't stop FR\n"); + goto out; + } + + dev->hba->ports[dev->port].command &= ~GRUB_AHCI_HBA_PORT_CMD_ST; + endtime = grub_get_time_ms () + 1000; + while ((dev->hba->ports[dev->port].command & GRUB_AHCI_HBA_PORT_CMD_CR)) + if (grub_get_time_ms () > endtime) + { + grub_dprintf ("ahci", "couldn't stop CR\n"); + goto out; + } + + dev->hba->ports[dev->port].fbs = 2; + + dev->rfis = grub_memalign_dma32 (4096, + sizeof (struct grub_ahci_received_fis)); + grub_memset ((char *) grub_dma_get_virt (dev->rfis), 0, + sizeof (struct grub_ahci_received_fis)); + dev->hba->ports[dev->port].fis_base = grub_dma_get_phys (dev->rfis); + dev->hba->ports[dev->port].command_list_base + = grub_dma_get_phys (command_list); + dev->hba->ports[dev->port].command |= GRUB_AHCI_HBA_PORT_CMD_FRE; + while (!(dev->hba->ports[dev->port].command & GRUB_AHCI_HBA_PORT_CMD_FR)) + if (grub_get_time_ms () > endtime) + { + grub_dprintf ("ahci", "couldn't start FR\n"); + dev->hba->ports[dev->port].command &= ~GRUB_AHCI_HBA_PORT_CMD_FRE; + goto out; + } + dev->hba->ports[dev->port].command |= GRUB_AHCI_HBA_PORT_CMD_ST; + while (!(dev->hba->ports[dev->port].command & GRUB_AHCI_HBA_PORT_CMD_CR)) + if (grub_get_time_ms () > endtime) + { + grub_dprintf ("ahci", "couldn't start CR\n"); + dev->hba->ports[dev->port].command &= ~GRUB_AHCI_HBA_PORT_CMD_CR; + goto out_stop_fr; + } + + dev->hba->ports[dev->port].command + = (dev->hba->ports[dev->port].command & 0x0fffffff) | (1 << 28) | 2 | 4; + + dev->command_list_chunk = command_list; + dev->command_list = grub_dma_get_virt (command_list); + dev->command_table_chunk = command_table; + dev->command_table = grub_dma_get_virt (command_table); + dev->command_list->command_table_base + = grub_dma_get_phys (command_table); + + return 0; + out_stop_fr: + dev->hba->ports[dev->port].command &= ~GRUB_AHCI_HBA_PORT_CMD_FRE; + endtime = grub_get_time_ms () + 1000; + while ((dev->hba->ports[dev->port].command & GRUB_AHCI_HBA_PORT_CMD_FR)) + if (grub_get_time_ms () > endtime) + { + grub_dprintf ("ahci", "couldn't stop FR\n"); + break; + } + out: + grub_dma_free (command_list); + grub_dma_free (command_table); + grub_dma_free (dev->rfis); + return 1; +} + static int NESTED_FUNC_ATTR grub_ahci_pciinit (grub_pci_device_t dev, grub_pci_id_t pciid __attribute__ ((unused))) @@ -209,7 +301,50 @@ grub_ahci_pciinit (grub_pci_device_t dev, else grub_dprintf ("ahci", "AHCI is already in OS mode\n"); - hba->global_control |= GRUB_AHCI_HBA_GLOBAL_CONTROL_AHCI_EN; + if (~(hba->global_control & GRUB_AHCI_HBA_GLOBAL_CONTROL_AHCI_EN)) + grub_dprintf ("ahci", "AHCI is in compat mode. Switching\n"); + else + grub_dprintf ("ahci", "AHCI is in AHCI mode.\n"); + + for (i = 0; i < 5; i++) + { + hba->global_control |= GRUB_AHCI_HBA_GLOBAL_CONTROL_AHCI_EN; + grub_millisleep (1); + if (hba->global_control & GRUB_AHCI_HBA_GLOBAL_CONTROL_AHCI_EN) + break; + } + if (i == 5) + { + grub_dprintf ("ahci", "Couldn't put AHCI in AHCI mode\n"); + return 0; + } + + /* + { + grub_uint64_t endtime; + hba->global_control |= 1; + endtime = grub_get_time_ms () + 1000; + while (hba->global_control & 1) + if (grub_get_time_ms () > endtime) + { + grub_dprintf ("ahci", "couldn't reset AHCI\n"); + return 0; + } + } + + for (i = 0; i < 5; i++) + { + hba->global_control |= GRUB_AHCI_HBA_GLOBAL_CONTROL_AHCI_EN; + grub_millisleep (1); + if (hba->global_control & GRUB_AHCI_HBA_GLOBAL_CONTROL_AHCI_EN) + break; + } + if (i == 5) + { + grub_dprintf ("ahci", "Couldn't put AHCI in AHCI mode\n"); + return 0; + } + */ nports = (hba->cap & GRUB_AHCI_HBA_CAP_NPORTS_MASK) + 1; @@ -218,8 +353,6 @@ grub_ahci_pciinit (grub_pci_device_t dev, for (i = 0; i < nports; i++) { struct grub_ahci_device *adev; - struct grub_pci_dma_chunk *command_list; - struct grub_pci_dma_chunk *command_table; grub_uint32_t st; if (!(hba->ports_implemented & (1 << i))) @@ -231,60 +364,20 @@ grub_ahci_pciinit (grub_pci_device_t dev, if ((st & 0xf) != 0x3 && (st & 0xf) != 0x1) continue; - command_list = grub_memalign_dma32 (1024, - sizeof (struct grub_ahci_cmd_head)); - if (!command_list) - return 1; - - command_table = grub_memalign_dma32 (1024, - sizeof (struct grub_ahci_cmd_table)); - if (!command_table) - { - grub_dma_free (command_list); - return 1; - } - adev = grub_malloc (sizeof (*adev)); if (!adev) - { - grub_dma_free (command_list); - grub_dma_free (command_table); - return 1; - } - - grub_dprintf ("ahci", "found device ahci%d (port %d)\n", numdevs, i); - - hba->ports[i].command &= ~GRUB_AHCI_HBA_PORT_CMD_FRE; - while ((hba->ports[i].command & GRUB_AHCI_HBA_PORT_CMD_FR)); - hba->ports[i].command &= ~GRUB_AHCI_HBA_PORT_CMD_ST; - while ((hba->ports[i].command & GRUB_AHCI_HBA_PORT_CMD_CR)); - - hba->ports[i].fbs = 2; - - adev->rfis = grub_memalign_dma32 (4096, - sizeof (struct grub_ahci_received_fis)); - grub_memset ((char *) grub_dma_get_virt (adev->rfis), 0, - sizeof (struct grub_ahci_received_fis)); - hba->ports[i].fis_base = grub_dma_get_phys (adev->rfis); - hba->ports[i].command |= GRUB_AHCI_HBA_PORT_CMD_FRE; - while (!(hba->ports[i].command & GRUB_AHCI_HBA_PORT_CMD_FR)); - hba->ports[i].command |= GRUB_AHCI_HBA_PORT_CMD_ST; - while (!(hba->ports[i].command & GRUB_AHCI_HBA_PORT_CMD_CR)); - - hba->ports[i].command = (hba->ports[i].command & 0x0fffffff) - | (1 << 28) | 2 | 4; + return 1; adev->hba = hba; adev->port = i; adev->num = numdevs++; - adev->command_list_chunk = command_list; - adev->command_list = grub_dma_get_virt (command_list); - adev->command_table_chunk = command_table; - adev->command_table = grub_dma_get_virt (command_table); - adev->command_list->command_table_base - = grub_dma_get_phys (command_table); - adev->hba->ports[i].command_list_base = grub_dma_get_phys (command_list); + if (init_port (adev)) + { + grub_free (adev); + return 1; + } + grub_list_push (GRUB_AS_LIST_P (&grub_ahci_devices), GRUB_AS_LIST (adev)); } @@ -302,29 +395,53 @@ grub_ahci_initialize (void) static grub_err_t grub_ahci_fini_hw (int noreturn __attribute__ ((unused))) { - struct grub_ahci_device *dev, *next; + struct grub_ahci_device *dev; - for (dev = grub_ahci_devices; dev; dev = next) + for (dev = grub_ahci_devices; dev; dev = dev->next) { - next = dev->next; - dev->hba->ports[dev->num].command &= ~GRUB_AHCI_HBA_PORT_CMD_FRE; - while ((dev->hba->ports[dev->num].command & GRUB_AHCI_HBA_PORT_CMD_FR)); - dev->hba->ports[dev->num].command &= ~GRUB_AHCI_HBA_PORT_CMD_ST; - while ((dev->hba->ports[dev->num].command & GRUB_AHCI_HBA_PORT_CMD_CR)); + grub_uint64_t endtime; + + dev->hba->ports[dev->port].command &= ~GRUB_AHCI_HBA_PORT_CMD_FRE; + endtime = grub_get_time_ms () + 1000; + while ((dev->hba->ports[dev->port].command & GRUB_AHCI_HBA_PORT_CMD_FR)) + if (grub_get_time_ms () > endtime) + { + grub_dprintf ("ahci", "couldn't stop FR\n"); + break; + } + + dev->hba->ports[dev->port].command &= ~GRUB_AHCI_HBA_PORT_CMD_ST; + endtime = grub_get_time_ms () + 1000; + while ((dev->hba->ports[dev->port].command & GRUB_AHCI_HBA_PORT_CMD_CR)) + if (grub_get_time_ms () > endtime) + { + grub_dprintf ("ahci", "couldn't stop CR\n"); + break; + } grub_dma_free (dev->command_list_chunk); grub_dma_free (dev->command_table_chunk); grub_dma_free (dev->rfis); - - grub_free (dev); + dev->command_list_chunk = NULL; + dev->command_table_chunk = NULL; + dev->rfis = NULL; } - grub_ahci_devices = NULL; return GRUB_ERR_NONE; } static grub_err_t grub_ahci_restore_hw (void) { - return grub_ahci_initialize (); + struct grub_ahci_device **pdev; + + for (pdev = &grub_ahci_devices; *pdev; pdev = &((*pdev)->next)) + if (init_port (*pdev)) + { + struct grub_ahci_device *odev; + odev = *pdev; + *pdev = (*pdev)->next; + grub_free (odev); + } + return GRUB_ERR_NONE; } @@ -391,9 +508,21 @@ grub_ahci_readwrite_real (struct grub_ahci_device *dev, if ((dev->hba->ports[dev->port].task_file_data & 0x80)) { dev->hba->ports[dev->port].command &= ~GRUB_AHCI_HBA_PORT_CMD_ST; - while ((dev->hba->ports[dev->port].command & GRUB_AHCI_HBA_PORT_CMD_CR)); + endtime = grub_get_time_ms () + 1000; + while ((dev->hba->ports[dev->port].command & GRUB_AHCI_HBA_PORT_CMD_CR)) + if (grub_get_time_ms () > endtime) + { + grub_dprintf ("ahci", "couldn't stop CR\n"); + break; + } dev->hba->ports[dev->port].command |= GRUB_AHCI_HBA_PORT_CMD_ST; - while (!(dev->hba->ports[dev->port].command & GRUB_AHCI_HBA_PORT_CMD_CR)); + endtime = grub_get_time_ms () + 1000; + while (!(dev->hba->ports[dev->port].command & GRUB_AHCI_HBA_PORT_CMD_CR)) + if (grub_get_time_ms () > endtime) + { + grub_dprintf ("ahci", "couldn't start CR\n"); + break; + } } dev->hba->ports[dev->port].sata_error = dev->hba->ports[dev->port].sata_error; From 99d925aad45bb0f929a24957a43b83d50929cca4 Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Mon, 3 Jan 2011 23:56:45 +0000 Subject: [PATCH 192/869] * grub-core/bus/pci.c (grub_pci_iterate): Skip remaining functions on devices that do not implement function 0. --- ChangeLog | 5 +++++ grub-core/bus/pci.c | 9 ++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index d89cb8618..a4692b5a7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-01-03 Colin Watson + + * grub-core/bus/pci.c (grub_pci_iterate): Skip remaining functions + on devices that do not implement function 0. + 2011-01-03 Dave Vasilevsky * grub-core/fs/hfsplus.c: Make parent unsigned. diff --git a/grub-core/bus/pci.c b/grub-core/bus/pci.c index bf14a8653..11101d42b 100644 --- a/grub-core/bus/pci.c +++ b/grub-core/bus/pci.c @@ -90,7 +90,14 @@ grub_pci_iterate (grub_pci_iteratefunc_t hook) /* Check if there is a device present. */ if (id >> 16 == 0xFFFF) - continue; + { + if (dev.function == 0) + /* Devices are required to implement function 0, so if + it's missing then there is no device here. */ + break; + else + continue; + } #ifdef GRUB_MACHINE_MIPS_YEELOONG /* Skip ghosts. */ From 5b1bdf12314a2a76168c0d03f729d33af9e2b778 Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Tue, 4 Jan 2011 13:05:19 +0000 Subject: [PATCH 193/869] * grub-core/commands/legacycfg.c (GRUB_MOD_INIT): Fix typo in descriptions of extract_legacy_entries_source and extract_legacy_entries_configfile. Reported by: Seung Soo, Ha. --- ChangeLog | 7 +++++++ grub-core/commands/legacycfg.c | 4 ++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index a4692b5a7..b4a308e9a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2011-01-04 Colin Watson + + * grub-core/commands/legacycfg.c (GRUB_MOD_INIT): Fix typo in + descriptions of extract_legacy_entries_source and + extract_legacy_entries_configfile. + Reported by: Seung Soo, Ha. + 2011-01-03 Colin Watson * grub-core/bus/pci.c (grub_pci_iterate): Skip remaining functions diff --git a/grub-core/commands/legacycfg.c b/grub-core/commands/legacycfg.c index 80718196a..de392ac81 100644 --- a/grub-core/commands/legacycfg.c +++ b/grub-core/commands/legacycfg.c @@ -765,12 +765,12 @@ GRUB_MOD_INIT(legacycfg) = grub_register_command ("extract_legacy_entries_source", grub_cmd_legacy_source, N_("FILE"), - N_("Parse legacy config in same context taking onl entries")); + N_("Parse legacy config in same context taking only menu entries")); cmd_configfile_extract = grub_register_command ("extract_legacy_entries_configfile", grub_cmd_legacy_source, N_("FILE"), - N_("Parse legacy config in new context taking onl entries")); + N_("Parse legacy config in new context taking only menu entries")); cmd_kernel = grub_register_command ("legacy_kernel", grub_cmd_legacy_kernel, From 956384994b66a9c1a72876738d41b5e0e24b9022 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Tue, 4 Jan 2011 15:35:10 +0100 Subject: [PATCH 194/869] * grub-core/lib/reed_solomon.c (scratch) [! STANDALONE]: Remove leftover variable. --- ChangeLog | 5 +++++ grub-core/lib/reed_solomon.c | 2 ++ 2 files changed, 7 insertions(+) diff --git a/ChangeLog b/ChangeLog index b4a308e9a..d40ea54aa 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-01-03 Vladimir Serbinenko + + * grub-core/lib/reed_solomon.c (scratch) [! STANDALONE]: Remove leftover + variable. + 2011-01-04 Colin Watson * grub-core/commands/legacycfg.c (GRUB_MOD_INIT): Fix typo in diff --git a/grub-core/lib/reed_solomon.c b/grub-core/lib/reed_solomon.c index 9a40e2f98..740a069ee 100644 --- a/grub-core/lib/reed_solomon.c +++ b/grub-core/lib/reed_solomon.c @@ -60,7 +60,9 @@ typedef grub_uint16_t gf_double_t; static char *gf_invert __attribute__ ((section(".text"))) = (void *) 0x100000; static char *scratch __attribute__ ((section(".text"))) = (void *) 0x100100; #else +#if defined (STANDALONE) static char *scratch; +#endif static grub_uint8_t gf_invert[256]; #endif From e5146ca18b828a17e79a122b648fbd390e7bd122 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Tue, 4 Jan 2011 15:37:10 +0100 Subject: [PATCH 195/869] * grub-core/lib/reed_solomon.c (main) [TEST]: Reactivate normal test. --- ChangeLog | 6 +++++- grub-core/lib/reed_solomon.c | 9 +-------- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index d40ea54aa..505923fa9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,8 @@ -2011-01-03 Vladimir Serbinenko +2011-01-04 Vladimir Serbinenko + + * grub-core/lib/reed_solomon.c (main) [TEST]: Reactivate normal test. + +2011-01-04 Vladimir Serbinenko * grub-core/lib/reed_solomon.c (scratch) [! STANDALONE]: Remove leftover variable. diff --git a/grub-core/lib/reed_solomon.c b/grub-core/lib/reed_solomon.c index 740a069ee..62aad3111 100644 --- a/grub-core/lib/reed_solomon.c +++ b/grub-core/lib/reed_solomon.c @@ -501,14 +501,10 @@ main (int argc, char **argv) fseek (in, 0, SEEK_END); s = ftell (in); fseek (in, 0, SEEK_SET); - rs = 1024 * ((s + MAX_BLOCK_SIZE - 1) / (MAX_BLOCK_SIZE - 1024)); + rs = s / 3; buf = xmalloc (s + rs + SECTOR_SIZE); fread (buf, 1, s, in); - s = 0x5fbb; - rs = 0x6af9; - -#if 0 grub_reed_solomon_add_redundancy (buf, s, rs); out = fopen ("tst_rs.bin", "wb"); @@ -520,9 +516,6 @@ main (int argc, char **argv) out = fopen ("tst_dam.bin", "wb"); fwrite (buf, 1, s + rs, out); fclose (out); -#endif - s = 0x5fbb; - rs = 0x6af9; grub_reed_solomon_recover (buf, s, rs); out = fopen ("tst_rec.bin", "wb"); From a0159f370da21f7dd264e7b4185f15907cca19ef Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Tue, 4 Jan 2011 15:39:59 +0100 Subject: [PATCH 196/869] * grub-core/lib/reed_solomon.c (grub_reed_solomon_add_redundancy): Prevent overflow. (grub_reed_solomon_recover): Likewise. --- ChangeLog | 6 ++++++ grub-core/lib/reed_solomon.c | 8 ++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 505923fa9..3e20a118b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2011-01-04 Vladimir Serbinenko + + * grub-core/lib/reed_solomon.c (grub_reed_solomon_add_redundancy): + Prevent overflow. + (grub_reed_solomon_recover): Likewise. + 2011-01-04 Vladimir Serbinenko * grub-core/lib/reed_solomon.c (main) [TEST]: Reactivate normal test. diff --git a/grub-core/lib/reed_solomon.c b/grub-core/lib/reed_solomon.c index 62aad3111..e500ba32d 100644 --- a/grub-core/lib/reed_solomon.c +++ b/grub-core/lib/reed_solomon.c @@ -433,8 +433,8 @@ grub_reed_solomon_add_redundancy (void *buffer, grub_size_t data_size, tt = cs + crs; if (tt > MAX_BLOCK_SIZE) { - cs = (cs * MAX_BLOCK_SIZE) / tt; - crs = (crs * MAX_BLOCK_SIZE) / tt; + cs = ((cs * (MAX_BLOCK_SIZE / 512)) / tt) * 512; + crs = ((crs * (MAX_BLOCK_SIZE / 512)) / tt) * 512; } encode_block (ptr, cs, rptr, crs); ptr += cs; @@ -468,8 +468,8 @@ grub_reed_solomon_recover (void *ptr_, grub_size_t s, grub_size_t rs) tt = cs + crs; if (tt > MAX_BLOCK_SIZE) { - cs = (cs * MAX_BLOCK_SIZE) / tt; - crs = (crs * MAX_BLOCK_SIZE) / tt; + cs = ((cs * (MAX_BLOCK_SIZE / 512)) / tt) * 512; + crs = ((crs * (MAX_BLOCK_SIZE / 512)) / tt) * 512; } decode_block (ptr, cs, rptr, crs); ptr += cs; From 446fa40081ab2602dcad9ebdfc4564e63fed1c76 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Tue, 4 Jan 2011 15:42:47 +0100 Subject: [PATCH 197/869] * grub-core/disk/i386/pc/biosdisk.c (GRUB_MOD_INIT): Workaround buggy BIOSes. --- ChangeLog | 5 +++++ grub-core/disk/i386/pc/biosdisk.c | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/ChangeLog b/ChangeLog index 3e20a118b..f3fa4d4c0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-01-04 Vladimir Serbinenko + + * grub-core/disk/i386/pc/biosdisk.c (GRUB_MOD_INIT): Workaround buggy + BIOSes. + 2011-01-04 Vladimir Serbinenko * grub-core/lib/reed_solomon.c (grub_reed_solomon_add_redundancy): diff --git a/grub-core/disk/i386/pc/biosdisk.c b/grub-core/disk/i386/pc/biosdisk.c index 3f9015fb9..069bb0b59 100644 --- a/grub-core/disk/i386/pc/biosdisk.c +++ b/grub-core/disk/i386/pc/biosdisk.c @@ -624,6 +624,11 @@ GRUB_MOD_INIT(biosdisk) ((cdrp->media_type & GRUB_BIOSDISK_CDTYPE_MASK) == GRUB_BIOSDISK_CDTYPE_NO_EMUL)) cd_drive = cdrp->drive_no; + /* Since diskboot.S rejects devices over 0x90 it must be a CD booted with + cdboot.S + */ + if (grub_boot_drive >= 0x90) + cd_drive = grub_boot_drive; grub_disk_dev_register (&grub_biosdisk_dev); } From ebc71d284cae71f142486b7f6b98fbd978af3833 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Tue, 4 Jan 2011 18:15:27 +0100 Subject: [PATCH 198/869] * grub-core/kern/emu/getroot.c (grub_util_get_grub_dev): Check md/%s names. Reported by: David Pravec. --- ChangeLog | 6 ++++++ grub-core/kern/emu/getroot.c | 11 +++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index f3fa4d4c0..bba94dfd9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2011-01-04 Vladimir Serbinenko + + * grub-core/kern/emu/getroot.c (grub_util_get_grub_dev): Check md/%s + names. + Reported by: David Pravec. + 2011-01-04 Vladimir Serbinenko * grub-core/disk/i386/pc/biosdisk.c (GRUB_MOD_INIT): Workaround buggy diff --git a/grub-core/kern/emu/getroot.c b/grub-core/kern/emu/getroot.c index f51dcd770..5356685e9 100644 --- a/grub-core/kern/emu/getroot.c +++ b/grub-core/kern/emu/getroot.c @@ -794,11 +794,18 @@ grub_util_get_grub_dev (const char *os_dev) #ifdef __linux__ { char *mdadm_name = get_mdadm_name (os_dev); + struct stat st; if (mdadm_name) { - free (grub_dev); - grub_dev = xasprintf ("md/%s", mdadm_name); + char *newname; + newname = xasprintf ("/dev/md/%s", mdadm_name); + if (stat (newname, &st) == 0) + { + free (grub_dev); + grub_dev = xasprintf ("md/%s", mdadm_name); + } + free (newname); free (mdadm_name); } } From 9eae2084f405a7ae3ac25b87daf23c224956fd42 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Tue, 4 Jan 2011 19:08:03 +0100 Subject: [PATCH 199/869] * grub-core/lib/efi/relocator.c (grub_relocator_firmware_fill_events): Ignore the memory post-4G. (grub_relocator_firmware_alloc_region): Additional debug statement. --- ChangeLog | 6 ++++++ grub-core/lib/efi/relocator.c | 19 +++++++++++++++++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index bba94dfd9..cda79b44a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2011-01-04 Vladimir Serbinenko + + * grub-core/lib/efi/relocator.c (grub_relocator_firmware_fill_events): + Ignore the memory post-4G. + (grub_relocator_firmware_alloc_region): Additional debug statement. + 2011-01-04 Vladimir Serbinenko * grub-core/kern/emu/getroot.c (grub_util_get_grub_dev): Check md/%s diff --git a/grub-core/lib/efi/relocator.c b/grub-core/lib/efi/relocator.c index fc4de834b..0d346bea3 100644 --- a/grub-core/lib/efi/relocator.c +++ b/grub-core/lib/efi/relocator.c @@ -62,13 +62,25 @@ grub_relocator_firmware_fill_events (struct grub_relocator_mmap_event *events) (char *) desc < ((char *) descs + mmapsize); desc = NEXT_MEMORY_DESCRIPTOR (desc, desc_size)) { + grub_uint64_t start = desc->physical_start; + grub_uint64_t end = desc->physical_start + (desc->num_pages << 12); + + /* post-4G addresses are never supported on 32-bit EFI. + Moreover it has been reported that some 64-bit EFI contrary to the + spec don't map post-4G pages. So if you enable post-4G allocations, + map pages manually or check that they are mapped. + */ + if (end >= 0x100000000ULL) + end = 0x100000000ULL; + if (end <= start) + continue; if (desc->type != GRUB_EFI_CONVENTIONAL_MEMORY) continue; events[counter].type = REG_FIRMWARE_START; - events[counter].pos = desc->physical_start; + events[counter].pos = start; counter++; events[counter].type = REG_FIRMWARE_END; - events[counter].pos = desc->physical_start + (desc->num_pages << 12); + events[counter].pos = end; counter++; } @@ -85,6 +97,9 @@ grub_relocator_firmware_alloc_region (grub_addr_t start, grub_size_t size) if (grub_efi_is_finished) return 1; + grub_dprintf ("relocator", "EFI alloc: %llx, %llx\n", + (unsigned long long) start, (unsigned long long) size); + b = grub_efi_system_table->boot_services; status = efi_call_4 (b->allocate_pages, GRUB_EFI_ALLOCATE_ADDRESS, GRUB_EFI_LOADER_DATA, size >> 12, &address); From 18a38098ad53654bc304271464e01fe0e090249e Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 5 Jan 2011 01:14:32 +0100 Subject: [PATCH 200/869] The E820 type 5 is BADRAM, not EXEC_CODE. * grub-core/loader/i386/bsd.c (GRUB_E820_EXEC_CODE): Removed. (GRUB_E820_BADRAM): New define. * grub-core/loader/i386/linux.c (grub_linux_boot): Translate code into reserved. Propagate BADRAM. * grub-core/loader/i386/bsd.c (GRUB_E820_EXEC_CODE): Removed. (GRUB_E820_BADRAM): New define. --- ChangeLog | 11 +++++++++++ grub-core/loader/i386/bsd.c | 2 +- grub-core/loader/i386/linux.c | 4 ++-- include/grub/i386/linux.h | 2 +- 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index cda79b44a..41241e7a0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2011-01-05 Vladimir Serbinenko + + The E820 type 5 is BADRAM, not EXEC_CODE. + + * grub-core/loader/i386/bsd.c (GRUB_E820_EXEC_CODE): Removed. + (GRUB_E820_BADRAM): New define. + * grub-core/loader/i386/linux.c (grub_linux_boot): Translate code + into reserved. Propagate BADRAM. + * grub-core/loader/i386/bsd.c (GRUB_E820_EXEC_CODE): Removed. + (GRUB_E820_BADRAM): New define. + 2011-01-04 Vladimir Serbinenko * grub-core/lib/efi/relocator.c (grub_relocator_firmware_fill_events): diff --git a/grub-core/loader/i386/bsd.c b/grub-core/loader/i386/bsd.c index 84cf1a17f..08cdcda37 100644 --- a/grub-core/loader/i386/bsd.c +++ b/grub-core/loader/i386/bsd.c @@ -252,7 +252,7 @@ struct grub_e820_mmap #define GRUB_E820_RESERVED 2 #define GRUB_E820_ACPI 3 #define GRUB_E820_NVS 4 -#define GRUB_E820_EXEC_CODE 5 +#define GRUB_E820_BADRAM 5 static void generate_e820_mmap (grub_size_t *len, grub_size_t *cnt, void *buf) diff --git a/grub-core/loader/i386/linux.c b/grub-core/loader/i386/linux.c index 95aa6b456..ca88c7403 100644 --- a/grub-core/loader/i386/linux.c +++ b/grub-core/loader/i386/linux.c @@ -418,9 +418,9 @@ grub_linux_boot (void) addr, size, GRUB_E820_NVS); break; - case GRUB_MEMORY_CODE: + case GRUB_MEMORY_BADRAM: grub_e820_add_region (params->e820_map, &e820_num, - addr, size, GRUB_E820_EXEC_CODE); + addr, size, GRUB_E820_BADRAM); break; default: diff --git a/include/grub/i386/linux.h b/include/grub/i386/linux.h index 63f99db62..9ba83eee2 100644 --- a/include/grub/i386/linux.h +++ b/include/grub/i386/linux.h @@ -68,7 +68,7 @@ #define GRUB_E820_RESERVED 2 #define GRUB_E820_ACPI 3 #define GRUB_E820_NVS 4 -#define GRUB_E820_EXEC_CODE 5 +#define GRUB_E820_BADRAM 5 #define GRUB_E820_MAX_ENTRY 128 From 488f71f116916549766d4df50d364dc3400c50ba Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 5 Jan 2011 01:25:01 +0100 Subject: [PATCH 201/869] * grub-core/term/terminfo.c (grub_terminfo_readkey): Handle keys with CTRL. --- ChangeLog | 5 +++++ grub-core/term/terminfo.c | 2 ++ 2 files changed, 7 insertions(+) diff --git a/ChangeLog b/ChangeLog index 41241e7a0..0932ee7cb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-01-05 Vladimir Serbinenko + + * grub-core/term/terminfo.c (grub_terminfo_readkey): Handle keys with + CTRL. + 2011-01-05 Vladimir Serbinenko The E820 type 5 is BADRAM, not EXEC_CODE. diff --git a/grub-core/term/terminfo.c b/grub-core/term/terminfo.c index d01811959..8450ea231 100644 --- a/grub-core/term/terminfo.c +++ b/grub-core/term/terminfo.c @@ -403,6 +403,8 @@ grub_terminfo_readkey (struct grub_term_input *term, int *keys, int *len, /* Backspace: Ctrl-h. */ if (c == 0x7f) c = '\b'; + if (c < 0x20 && c != '\t' && c!= '\b' && c != '\n' && c != '\r') + c = GRUB_TERM_CTRL | (c - 1 + 'a'); *len = 1; keys[0] = c; return; From 4c3e4f37be31b5b1ed9e1928116f0d504faac937 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 5 Jan 2011 01:28:28 +0100 Subject: [PATCH 202/869] * util/grub-install.in: Determine ofpathname, nvsetenv and efibootmgr only when needed. --- ChangeLog | 5 +++++ util/grub-install.in | 6 +++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 0932ee7cb..50da0e678 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-01-05 Vladimir Serbinenko + + * util/grub-install.in: Determine ofpathname, nvsetenv and efibootmgr + only when needed. + 2011-01-05 Vladimir Serbinenko * grub-core/term/terminfo.c (grub_terminfo_readkey): Handle keys with diff --git a/util/grub-install.in b/util/grub-install.in index 716582dfd..90360c279 100644 --- a/util/grub-install.in +++ b/util/grub-install.in @@ -56,9 +56,6 @@ debug_image= update_nvram=yes -ofpathname="`which ofpathname`" -nvsetenv="`which nvsetenv`" -efibootmgr="`which efibootmgr 2>/dev/null || true`" removable=no efi_quiet= @@ -585,6 +582,8 @@ if [ "${target_cpu}-${platform}" = "i386-pc" ] || [ "${target_cpu}-${platform}" --device-map="${device_map}" "${install_device}" || exit 1 elif [ "${target_cpu}-${platform}" = "i386-ieee1275" ] || [ "${target_cpu}-${platform}" = "powerpc-ieee1275" ]; then if [ x"$update_nvram" = xyes ]; then + ofpathname="`which ofpathname`" + nvsetenv="`which nvsetenv`" set "$ofpathname" dummy if test -f "$1"; then : @@ -621,6 +620,7 @@ elif [ x"$platform" = xefi ]; then cp "${grubdir}/core.${imgext}" "${efidir}/${efi_file}" # Try to make this image bootable using the EFI Boot Manager, if available. + efibootmgr="`which efibootmgr`" if test "$removable" = no && test -n "$efi_distributor" && \ test -n "$efibootmgr"; then # On Linux, we need the efivars kernel modules. From b3f8d28ad0c629d7ae77318be9fe23f8a618d11f Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 5 Jan 2011 12:23:06 +0100 Subject: [PATCH 203/869] Run terminfo_cls on initing terminfo output to clear the screen and move the cursor to (0,0). * grub-core/term/ieee1275/ofconsole.c (grub_ofconsole_init_output): Call grub_terminfo_output_init. * grub-core/term/serial.c (grub_serial_term_output): Set .init. * grub-core/term/terminfo.c (grub_terminfo_output_init): New function. * include/grub/terminfo.h (grub_terminfo_output_init): New declaration. --- ChangeLog | 11 +++++++++++ grub-core/term/ieee1275/ofconsole.c | 2 ++ grub-core/term/serial.c | 1 + grub-core/term/terminfo.c | 7 +++++++ include/grub/terminfo.h | 1 + 5 files changed, 22 insertions(+) diff --git a/ChangeLog b/ChangeLog index 50da0e678..0159aab3d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2011-01-05 Vladimir Serbinenko + + Run terminfo_cls on initing terminfo output to clear the screen and + move the cursor to (0,0). + + * grub-core/term/ieee1275/ofconsole.c (grub_ofconsole_init_output): + Call grub_terminfo_output_init. + * grub-core/term/serial.c (grub_serial_term_output): Set .init. + * grub-core/term/terminfo.c (grub_terminfo_output_init): New function. + * include/grub/terminfo.h (grub_terminfo_output_init): New declaration. + 2011-01-05 Vladimir Serbinenko * util/grub-install.in: Determine ofpathname, nvsetenv and efibootmgr diff --git a/grub-core/term/ieee1275/ofconsole.c b/grub-core/term/ieee1275/ofconsole.c index 2b0bddbbb..ab74f21da 100644 --- a/grub-core/term/ieee1275/ofconsole.c +++ b/grub-core/term/ieee1275/ofconsole.c @@ -170,6 +170,8 @@ grub_ofconsole_init_output (struct grub_term_output *term) grub_ofconsole_dimensions (); + grub_terminfo_output_init (term); + return 0; } diff --git a/grub-core/term/serial.c b/grub-core/term/serial.c index d36388359..e672a89d6 100644 --- a/grub-core/term/serial.c +++ b/grub-core/term/serial.c @@ -104,6 +104,7 @@ static struct grub_term_input grub_serial_term_input = static struct grub_term_output grub_serial_term_output = { .name = "serial", + .init = grub_terminfo_output_init, .putchar = grub_terminfo_putchar, .getwh = grub_terminfo_getwh, .getxy = grub_terminfo_getxy, diff --git a/grub-core/term/terminfo.c b/grub-core/term/terminfo.c index 8450ea231..0a8c75c74 100644 --- a/grub-core/term/terminfo.c +++ b/grub-core/term/terminfo.c @@ -514,6 +514,13 @@ grub_terminfo_input_init (struct grub_term_input *termi) return GRUB_ERR_NONE; } +grub_err_t +grub_terminfo_output_init (struct grub_term_output *term) +{ + grub_terminfo_cls (term); + return GRUB_ERR_NONE; +} + /* GRUB Command. */ static grub_err_t diff --git a/include/grub/terminfo.h b/include/grub/terminfo.h index 8317995d8..5a552b327 100644 --- a/include/grub/terminfo.h +++ b/include/grub/terminfo.h @@ -56,6 +56,7 @@ struct grub_terminfo_output_state void (*put) (struct grub_term_output *term, const int c); }; +grub_err_t EXPORT_FUNC(grub_terminfo_output_init) (struct grub_term_output *term); void EXPORT_FUNC(grub_terminfo_gotoxy) (grub_term_output_t term, grub_uint8_t x, grub_uint8_t y); void EXPORT_FUNC(grub_terminfo_cls) (grub_term_output_t term); From 304e349b7fcfeaaa2a340c0adf30a281b82e62ff Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Wed, 5 Jan 2011 11:41:12 +0000 Subject: [PATCH 204/869] include for grub_find_device --- grub-core/kern/emu/hostdisk.c | 1 + 1 file changed, 1 insertion(+) diff --git a/grub-core/kern/emu/hostdisk.c b/grub-core/kern/emu/hostdisk.c index 2a798a3cd..b21ac3285 100644 --- a/grub-core/kern/emu/hostdisk.c +++ b/grub-core/kern/emu/hostdisk.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include From 71b6a2b7a2d9d71cff26b39a941b0f7191bcea42 Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Thu, 6 Jan 2011 11:09:17 +0000 Subject: [PATCH 205/869] * grub-core/kern/emu/getroot.c (find_root_device_from_mountinfo): Fix prefix check to handle the case where dir ends with a slash (most significantly, "/" itself). Reported by: Michael Vogt. --- ChangeLog | 7 +++++++ grub-core/kern/emu/getroot.c | 6 +++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 0159aab3d..a6d62da6c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2011-01-06 Colin Watson + + * grub-core/kern/emu/getroot.c (find_root_device_from_mountinfo): + Fix prefix check to handle the case where dir ends with a slash + (most significantly, "/" itself). + Reported by: Michael Vogt. + 2011-01-05 Vladimir Serbinenko Run terminfo_cls on initing terminfo output to clear the screen and diff --git a/grub-core/kern/emu/getroot.c b/grub-core/kern/emu/getroot.c index 5356685e9..aedef9e0e 100644 --- a/grub-core/kern/emu/getroot.c +++ b/grub-core/kern/emu/getroot.c @@ -135,8 +135,12 @@ find_root_device_from_mountinfo (const char *dir) continue; /* only a subtree is mounted */ enc_path_len = strlen (enc_path); + /* Check that enc_path is a prefix of dir. The prefix must either be + the entire string, or end with a slash, or be immediately followed + by a slash. */ if (strncmp (dir, enc_path, enc_path_len) != 0 || - (dir[enc_path_len] && dir[enc_path_len] != '/')) + (enc_path_len && dir[enc_path_len - 1] != '/' && + dir[enc_path_len] && dir[enc_path_len] != '/')) continue; /* This is a parent of the requested directory. /proc/self/mountinfo From 415502c26a4544292046fbb0b580b352cb346f5f Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Thu, 6 Jan 2011 13:24:38 +0000 Subject: [PATCH 206/869] * tests/util/grub-shell.in: Set serial terminfo type to `dumb', to avoid causing test failures by clearing the screen. --- ChangeLog | 5 +++++ tests/util/grub-shell.in | 1 + 2 files changed, 6 insertions(+) diff --git a/ChangeLog b/ChangeLog index a6d62da6c..a727bd4ec 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-01-06 Colin Watson + + * tests/util/grub-shell.in: Set serial terminfo type to `dumb', to + avoid causing test failures by clearing the screen. + 2011-01-06 Colin Watson * grub-core/kern/emu/getroot.c (find_root_device_from_mountinfo): diff --git a/tests/util/grub-shell.in b/tests/util/grub-shell.in index e35d6bc65..0213376d0 100644 --- a/tests/util/grub-shell.in +++ b/tests/util/grub-shell.in @@ -119,6 +119,7 @@ cat <${cfgfile} grubshell=yes insmod serial serial +terminfo serial dumb terminal_input serial terminal_output serial EOF From 6383772c926fb299953c8830b0d115b55c110f0d Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Thu, 6 Jan 2011 18:08:01 +0000 Subject: [PATCH 207/869] remove unused variable --- grub-core/kern/emu/hostdisk.c | 1 - 1 file changed, 1 deletion(-) diff --git a/grub-core/kern/emu/hostdisk.c b/grub-core/kern/emu/hostdisk.c index b21ac3285..ee3cc0a36 100644 --- a/grub-core/kern/emu/hostdisk.c +++ b/grub-core/kern/emu/hostdisk.c @@ -1045,7 +1045,6 @@ grub_util_get_dm_node_linear_info (const char *dev, void *next = NULL; uint64_t length, start; char *target, *params; - const char *node_name; char *ptr; int major, minor; From 014b68068d4136812f2e3dc16c986351e6fb2779 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 7 Jan 2011 13:27:34 +0100 Subject: [PATCH 208/869] =?UTF-8?q?=09*=20util/grub-setup.c=20(setup):=20H?= =?UTF-8?q?andle=20NetBSD=20and=20OpenBSD=20disklabels.=20=09Reported=20an?= =?UTF-8?q?d=20tested=20by:=20Gr=C3=A9goire=20Sutre.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ChangeLog | 5 +++++ util/grub-setup.c | 16 ++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/ChangeLog b/ChangeLog index a727bd4ec..d734d86b6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-01-07 Vladimir Serbinenko + + * util/grub-setup.c (setup): Handle NetBSD and OpenBSD disklabels. + Reported and tested by: GrĂ©goire Sutre. + 2011-01-06 Colin Watson * tests/util/grub-shell.in: Set serial terminfo type to `dumb', to diff --git a/util/grub-setup.c b/util/grub-setup.c index 5f9b29f25..b4749b433 100644 --- a/util/grub-setup.c +++ b/util/grub-setup.c @@ -49,6 +49,7 @@ #include #include "progname.h" #include +#include #define _GNU_SOURCE 1 #include @@ -339,6 +340,12 @@ setup (const char *dir, { if (p->parent != container) return 0; + /* NetBSD and OpenBSD subpartitions have metadata inside a partition, + so they are safe to ignore. + */ + if (grub_strcmp (p->partmap->name, "netbsd") == 0 + || grub_strcmp (p->partmap->name, "openbsd") == 0) + return 0; if (dest_partmap == NULL) { dest_partmap = p->partmap; @@ -352,6 +359,15 @@ setup (const char *dir, grub_partition_iterate (dest_dev->disk, identify_partmap); + if (container && grub_strcmp (container->partmap->name, "msdos") == 0 + && dest_partmap + && (container->msdostype == GRUB_PC_PARTITION_TYPE_NETBSD + || container->msdostype == GRUB_PC_PARTITION_TYPE_OPENBSD)) + { + grub_util_warn (_("Attempting to install GRUB to a disk with multiple partition labels or both partition label and filesystem. This is not supported yet.")); + goto unable_to_embed; + } + fs = grub_fs_probe (dest_dev); if (!fs) grub_errno = GRUB_ERR_NONE; From 0ca09e6c528885b5af9b2f614d62f50f79fc413a Mon Sep 17 00:00:00 2001 From: Doug Nazar Date: Fri, 7 Jan 2011 14:41:44 +0100 Subject: [PATCH 209/869] * grub-core/disk/raid5_recover.c (grub_raid5_recover): Add missing array->members[i].start_sector. * grub-core/disk/raid6_recover.c (grub_raid6_recover): Likewise. --- ChangeLog | 6 ++++++ grub-core/disk/raid5_recover.c | 4 +++- grub-core/disk/raid6_recover.c | 18 +++++++++++++----- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index d734d86b6..c5cc7afa6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2011-01-07 Doug Nazar + + * grub-core/disk/raid5_recover.c (grub_raid5_recover): Add missing + array->members[i].start_sector. + * grub-core/disk/raid6_recover.c (grub_raid6_recover): Likewise. + 2011-01-07 Vladimir Serbinenko * util/grub-setup.c (setup): Handle NetBSD and OpenBSD disklabels. diff --git a/grub-core/disk/raid5_recover.c b/grub-core/disk/raid5_recover.c index 2cda67533..349eb0291 100644 --- a/grub-core/disk/raid5_recover.c +++ b/grub-core/disk/raid5_recover.c @@ -45,7 +45,9 @@ grub_raid5_recover (struct grub_raid_array *array, int disknr, if (i == disknr) continue; - err = grub_disk_read (array->members[i].device, sector, 0, size, buf2); + err = grub_disk_read (array->members[i].device, + array->members[i].start_sector + sector, + 0, size, buf2); if (err) { diff --git a/grub-core/disk/raid6_recover.c b/grub-core/disk/raid6_recover.c index 01daa2c79..dfaa60ea4 100644 --- a/grub-core/disk/raid6_recover.c +++ b/grub-core/disk/raid6_recover.c @@ -119,7 +119,8 @@ grub_raid6_recover (struct grub_raid_array *array, int disknr, int p, else { if ((array->members[pos].device) && - (! grub_disk_read (array->members[pos].device, sector, + (! grub_disk_read (array->members[pos].device, + array->members[i].start_sector + sector, 0, size, buf))) { grub_raid_block_xor (pbuf, buf, size); @@ -150,7 +151,9 @@ grub_raid6_recover (struct grub_raid_array *array, int disknr, int p, { /* One bad device */ if ((array->members[p].device) && - (! grub_disk_read (array->members[p].device, sector, 0, size, buf))) + (! grub_disk_read (array->members[p].device, + array->members[i].start_sector + sector, + 0, size, buf))) { grub_raid_block_xor (buf, pbuf, size); goto quit; @@ -163,7 +166,8 @@ grub_raid6_recover (struct grub_raid_array *array, int disknr, int p, } grub_errno = GRUB_ERR_NONE; - if (grub_disk_read (array->members[q].device, sector, 0, size, buf)) + if (grub_disk_read (array->members[q].device, + array->members[i].start_sector + sector, 0, size, buf)) goto quit; grub_raid_block_xor (buf, qbuf, size); @@ -181,12 +185,16 @@ grub_raid6_recover (struct grub_raid_array *array, int disknr, int p, goto quit; } - if (grub_disk_read (array->members[p].device, sector, 0, size, buf)) + if (grub_disk_read (array->members[p].device, + array->members[i].start_sector + sector, + 0, size, buf)) goto quit; grub_raid_block_xor (pbuf, buf, size); - if (grub_disk_read (array->members[q].device, sector, 0, size, buf)) + if (grub_disk_read (array->members[q].device, + array->members[i].start_sector + sector, + 0, size, buf)) goto quit; grub_raid_block_xor (qbuf, buf, size); From c0cf26da6b7662fd309b509b4238aa3877003f15 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 7 Jan 2011 16:17:24 +0100 Subject: [PATCH 210/869] * grub-core/disk/mdraid1x_linux.c (grub_mdraid_detect): Add missing endian transformations. * grub-core/disk/mdraid_linux.c (grub_mdraid_detect): Likewise. Based on report by: Doug Nazar. --- ChangeLog | 7 +++++++ grub-core/disk/mdraid1x_linux.c | 19 ++++++++++------- grub-core/disk/mdraid_linux.c | 37 +++++++++++++++++++-------------- 3 files changed, 39 insertions(+), 24 deletions(-) diff --git a/ChangeLog b/ChangeLog index c5cc7afa6..0362abd51 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2011-01-07 Vladimir Serbinenko + + * grub-core/disk/mdraid1x_linux.c (grub_mdraid_detect): Add missing + endian transformations. + * grub-core/disk/mdraid_linux.c (grub_mdraid_detect): Likewise. + Based on report by: Doug Nazar. + 2011-01-07 Doug Nazar * grub-core/disk/raid5_recover.c (grub_raid5_recover): Add missing diff --git a/grub-core/disk/mdraid1x_linux.c b/grub-core/disk/mdraid1x_linux.c index b6a48b848..155210df3 100644 --- a/grub-core/disk/mdraid1x_linux.c +++ b/grub-core/disk/mdraid1x_linux.c @@ -143,24 +143,27 @@ grub_mdraid_detect (grub_disk_t disk, struct grub_raid_array *array, &sb)) return grub_errno; - if (sb.magic != SB_MAGIC) + if (grub_le_to_cpu32 (sb.magic) != SB_MAGIC) continue; { grub_uint64_t sb_size; struct grub_raid_super_1x *real_sb; + grub_uint32_t level; - if (sb.major_version != 1) + if (grub_le_to_cpu32 (sb.major_version) != 1) return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, "Unsupported RAID version: %d", - sb.major_version); + grub_le_to_cpu32 (sb.major_version)); + + level = grub_le_to_cpu32 (sb.level); /* Multipath. */ - if ((int) sb.level == -4) - sb.level = 1; + if ((int) level == -4) + level = 1; - if (sb.level != 0 && sb.level != 1 && sb.level != 4 && - sb.level != 5 && sb.level != 6 && sb.level != 10) + if (level != 0 && level != 1 && level != 4 && + level != 5 && level != 6 && level != 10) return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, "Unsupported RAID level: %d", sb.level); @@ -209,7 +212,7 @@ grub_mdraid_detect (grub_disk_t disk, struct grub_raid_array *array, grub_memcpy (array->uuid, real_sb->set_uuid, 16); - *start_sector = real_sb->data_offset; + *start_sector = grub_le_to_cpu64 (real_sb->data_offset); grub_free (real_sb); return 0; diff --git a/grub-core/disk/mdraid_linux.c b/grub-core/disk/mdraid_linux.c index dc0d80ffd..7aa48fd7a 100644 --- a/grub-core/disk/mdraid_linux.c +++ b/grub-core/disk/mdraid_linux.c @@ -167,6 +167,7 @@ grub_mdraid_detect (grub_disk_t disk, struct grub_raid_array *array, grub_uint64_t size; struct grub_raid_super_09 sb; grub_uint32_t *uuid; + grub_uint32_t level; /* The sector where the mdraid 0.90 superblock is stored, if available. */ size = grub_disk_get_size (disk); @@ -178,36 +179,40 @@ grub_mdraid_detect (grub_disk_t disk, struct grub_raid_array *array, return grub_errno; /* Look whether there is a mdraid 0.90 superblock. */ - if (sb.md_magic != SB_MAGIC) + if (grub_le_to_cpu32 (sb.md_magic) != SB_MAGIC) return grub_error (GRUB_ERR_OUT_OF_RANGE, "not 0.9x raid"); - if (sb.major_version != 0 || sb.minor_version != 90) + if (grub_le_to_cpu32 (sb.major_version) != 0 + || grub_le_to_cpu32 (sb.minor_version) != 90) return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, "unsupported RAID version: %d.%d", - sb.major_version, sb.minor_version); + grub_le_to_cpu32 (sb.major_version), + grub_le_to_cpu32 (sb.minor_version)); /* FIXME: Check the checksum. */ + level = grub_le_to_cpu32 (sb.level); /* Multipath. */ - if ((int) sb.level == -4) - sb.level = 1; + if ((int) level == -4) + level = 1; - if (sb.level != 0 && sb.level != 1 && sb.level != 4 && - sb.level != 5 && sb.level != 6 && sb.level != 10) + if (level != 0 && level != 1 && level != 4 && + level != 5 && level != 6 && level != 10) return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, - "unsupported RAID level: %d", sb.level); - if (sb.this_disk.number == 0xffff || sb.this_disk.number == 0xfffe) + "unsupported RAID level: %d", level); + if (grub_le_to_cpu32 (sb.this_disk.number) == 0xffff + || grub_le_to_cpu32 (sb.this_disk.number) == 0xfffe) return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, "spares aren't implemented"); array->name = NULL; - array->number = sb.md_minor; - array->level = sb.level; - array->layout = sb.layout; - array->total_devs = sb.raid_disks; - array->disk_size = (sb.size) ? sb.size * 2 : sector; - array->chunk_size = sb.chunk_size >> 9; - array->index = sb.this_disk.number; + array->number = grub_le_to_cpu32 (sb.md_minor); + array->level = level; + array->layout = grub_le_to_cpu32 (sb.layout); + array->total_devs = grub_le_to_cpu32 (sb.raid_disks); + array->disk_size = (sb.size) ? grub_le_to_cpu32 (sb.size) * 2 : sector; + array->chunk_size = grub_le_to_cpu32 (sb.chunk_size) >> 9; + array->index = grub_le_to_cpu32 (sb.this_disk.number); array->uuid_len = 16; array->uuid = grub_malloc (16); if (!array->uuid) From e72d259fe113e41722904bb25e7a51ba6bc3239c Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 7 Jan 2011 17:06:42 +0100 Subject: [PATCH 211/869] * grub-core/fs/xfs.c (grub_xfs_iterate_dir): Take into account that inopos might be unaligned. --- ChangeLog | 5 +++++ grub-core/fs/xfs.c | 21 +++++++++++++++------ 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index 0362abd51..ca63b0e85 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-01-07 Vladimir Serbinenko + + * grub-core/fs/xfs.c (grub_xfs_iterate_dir): Take into account that + inopos might be unaligned. + 2011-01-07 Vladimir Serbinenko * grub-core/disk/mdraid1x_linux.c (grub_mdraid_detect): Add missing diff --git a/grub-core/fs/xfs.c b/grub-core/fs/xfs.c index 3d773856e..9f8dc28de 100644 --- a/grub-core/fs/xfs.c +++ b/grub-core/fs/xfs.c @@ -451,18 +451,27 @@ grub_xfs_iterate_dir (grub_fshelp_node_t dir, for (i = 0; i < diro->inode.data.dir.dirhead.count; i++) { grub_uint64_t ino; - void *inopos = (((char *) de) + grub_uint8_t *inopos = (((grub_uint8_t *) de) + sizeof (struct grub_xfs_dir_entry) + de->len - 1); char name[de->len + 1]; + /* inopos might be unaligned. */ if (smallino) - { - ino = grub_be_to_cpu32 (*(grub_uint32_t *) inopos); - ino = grub_cpu_to_be64 (ino); - } + ino = (((grub_uint32_t) inopos[0]) << 24) + | (((grub_uint32_t) inopos[1]) << 16) + | (((grub_uint32_t) inopos[2]) << 8) + | (((grub_uint32_t) inopos[3]) << 0); else - ino = *(grub_uint64_t *) inopos; + ino = (((grub_uint64_t) inopos[0]) << 56) + | (((grub_uint64_t) inopos[1]) << 48) + | (((grub_uint64_t) inopos[2]) << 40) + | (((grub_uint64_t) inopos[3]) << 32) + | (((grub_uint64_t) inopos[4]) << 24) + | (((grub_uint64_t) inopos[5]) << 16) + | (((grub_uint64_t) inopos[6]) << 8) + | (((grub_uint64_t) inopos[7]) << 0); + ino = grub_cpu_to_be64 (ino); grub_memcpy (name, de->name, de->len); name[de->len] = '\0'; From 25953e10553dad2e378541a68686fc094603ec54 Mon Sep 17 00:00:00 2001 From: Szymon Janc Date: Fri, 7 Jan 2011 17:09:39 +0100 Subject: [PATCH 212/869] Improve loaders' kernel command line handling. * grub-core/lib/cmdline.c: New file. * include/grub/lib/cmdline.h: Likewise. * grub-core/loader/i386/linux.c (grub_cmd_linux): Use grub_create_loader_cmdline to create kernel command line. * grub-core/loader/i386/pc/linux.c (grub_cmd_linux): Likewise. * grub-core/loader/powerpc/ieee1275/linux.c (grub_cmd_linux): Likewise. * grub-core/loader/sparc64/ieee1275/linux.c (grub_cmd_linux): Likewise. * grub-core/Makefile.core.def (linux16): Add lib/cmdline.c on i386_pc. (linux): Add lib/cmdline.c on common. --- ChangeLog | 14 +++ grub-core/Makefile.core.def | 2 + grub-core/lib/cmdline.c | 105 ++++++++++++++++++++++ grub-core/loader/i386/linux.c | 26 ++---- grub-core/loader/i386/pc/linux.c | 25 ++---- grub-core/loader/powerpc/ieee1275/linux.c | 23 ++--- grub-core/loader/sparc64/ieee1275/linux.c | 22 ++--- include/grub/lib/cmdline.h | 31 +++++++ 8 files changed, 184 insertions(+), 64 deletions(-) create mode 100644 grub-core/lib/cmdline.c create mode 100644 include/grub/lib/cmdline.h diff --git a/ChangeLog b/ChangeLog index ca63b0e85..d1ddc8741 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +2011-01-07 Szymon Janc + + Improve loaders' kernel command line handling. + + * grub-core/lib/cmdline.c: New file. + * include/grub/lib/cmdline.h: Likewise. + * grub-core/loader/i386/linux.c (grub_cmd_linux): Use + grub_create_loader_cmdline to create kernel command line. + * grub-core/loader/i386/pc/linux.c (grub_cmd_linux): Likewise. + * grub-core/loader/powerpc/ieee1275/linux.c (grub_cmd_linux): Likewise. + * grub-core/loader/sparc64/ieee1275/linux.c (grub_cmd_linux): Likewise. + * grub-core/Makefile.core.def (linux16): Add lib/cmdline.c on i386_pc. + (linux): Add lib/cmdline.c on common. + 2011-01-07 Vladimir Serbinenko * grub-core/fs/xfs.c (grub_xfs_iterate_dir): Take into account that diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def index 37c0ce970..094bbc835 100644 --- a/grub-core/Makefile.core.def +++ b/grub-core/Makefile.core.def @@ -1149,6 +1149,7 @@ module = { module = { name = linux16; i386_pc = loader/i386/pc/linux.c; + i386_pc = lib/cmdline.c; enable = i386_pc; }; @@ -1183,6 +1184,7 @@ module = { mips = loader/mips/linux.c; powerpc_ieee1275 = loader/powerpc/ieee1275/linux.c; sparc64_ieee1275 = loader/sparc64/ieee1275/linux.c; + common = lib/cmdline.c; enable = noemu; }; diff --git a/grub-core/lib/cmdline.c b/grub-core/lib/cmdline.c new file mode 100644 index 000000000..a702e6487 --- /dev/null +++ b/grub-core/lib/cmdline.c @@ -0,0 +1,105 @@ +/* cmdline.c - linux command line handling */ +/* + * 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 . + */ + +#include +#include + +static unsigned int check_arg (char *c, int *has_space) +{ + int space = 0; + unsigned int size = 0; + + while (*c) + { + if (*c == '\\' || *c == '\'' || *c == '"') + size++; + else if (*c == ' ') + space = 1; + + size++; + c++; + } + + if (space) + size += 2; + + if (has_space) + *has_space = space; + + return size; +} + +unsigned int grub_loader_cmdline_size (int argc, char *argv[]) +{ + int i; + unsigned int size = 0; + + for (i = 0; i < argc; i++) + { + size += check_arg (argv[i], 0); + size++; /* Separator space or NULL. */ + } + + return size; +} + +int grub_create_loader_cmdline (int argc, char *argv[], char *buf, + grub_size_t size) +{ + int i, space; + unsigned int arg_size; + char *c; + + for (i = 0; i < argc; i++) + { + c = argv[i]; + arg_size = check_arg(argv[i], &space); + arg_size++; /* Separator space or NULL. */ + + if (size < arg_size) + break; + + size -= arg_size; + + if (space) + *buf++ = '"'; + + while (*c) + { + if (*c == '\\' || *c == '\'' || *c == '"') + *buf++ = '\\'; + + *buf++ = *c; + c++; + } + + if (space) + *buf++ = '"'; + + *buf++ = ' '; + } + + /* Replace last space with null. */ + if (i) + buf--; + + *buf = 0; + + return i; +} diff --git a/grub-core/loader/i386/linux.c b/grub-core/loader/i386/linux.c index ca88c7403..80f583cef 100644 --- a/grub-core/loader/i386/linux.c +++ b/grub-core/loader/i386/linux.c @@ -33,6 +33,7 @@ #include #include #include +#include #ifdef GRUB_MACHINE_PCBIOS #include @@ -575,7 +576,6 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), grub_size_t real_size, prot_size; grub_ssize_t len; int i; - char *dest; grub_dl_ref (my_mod); @@ -836,22 +836,14 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), params->loadflags |= GRUB_LINUX_FLAG_QUIET; } - - /* Specify the boot file. */ - dest = grub_stpcpy ((char *) real_mode_mem + GRUB_LINUX_CL_OFFSET, - "BOOT_IMAGE="); - dest = grub_stpcpy (dest, argv[0]); - - /* Copy kernel parameters. */ - for (i = 1; - i < argc - && dest + grub_strlen (argv[i]) + 1 < ((char *) real_mode_mem - + GRUB_LINUX_CL_END_OFFSET); - i++) - { - *dest++ = ' '; - dest = grub_stpcpy (dest, argv[i]); - } + /* Create kernel command line. */ + grub_memcpy ((char *)real_mode_mem + GRUB_LINUX_CL_OFFSET, LINUX_IMAGE, + sizeof (LINUX_IMAGE)); + grub_create_loader_cmdline (argc, argv, + (char *)real_mode_mem + GRUB_LINUX_CL_OFFSET + + sizeof (LINUX_IMAGE) - 1, + GRUB_LINUX_CL_END_OFFSET - GRUB_LINUX_CL_OFFSET + - (sizeof (LINUX_IMAGE) - 1)); len = prot_size; if (grub_file_read (file, prot_mode_mem, len) != len) diff --git a/grub-core/loader/i386/pc/linux.c b/grub-core/loader/i386/pc/linux.c index 90de70f66..96d00f927 100644 --- a/grub-core/loader/i386/pc/linux.c +++ b/grub-core/loader/i386/pc/linux.c @@ -34,6 +34,7 @@ #include #include #include +#include #define GRUB_LINUX_CL_OFFSET 0x9000 #define GRUB_LINUX_CL_END_OFFSET 0x90FF @@ -86,7 +87,6 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), grub_size_t real_size; grub_ssize_t len; int i; - char *dest; char *grub_linux_prot_chunk; int grub_linux_is_bzimage; grub_addr_t grub_linux_prot_target; @@ -286,21 +286,14 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), ((GRUB_LINUX_MAX_SETUP_SECTS - setup_sects - 1) << GRUB_DISK_SECTOR_BITS)); - /* Specify the boot file. */ - dest = grub_stpcpy (grub_linux_real_chunk + GRUB_LINUX_CL_OFFSET, - "BOOT_IMAGE="); - dest = grub_stpcpy (dest, argv[0]); - - /* Copy kernel parameters. */ - for (i = 1; - i < argc - && dest + grub_strlen (argv[i]) + 1 < (grub_linux_real_chunk - + GRUB_LINUX_CL_END_OFFSET); - i++) - { - *dest++ = ' '; - dest = grub_stpcpy (dest, argv[i]); - } + /* Create kernel command line. */ + grub_memcpy ((char *)grub_linux_real_chunk + GRUB_LINUX_CL_OFFSET, + LINUX_IMAGE, sizeof (LINUX_IMAGE)); + grub_create_loader_cmdline (argc, argv, + (char *)grub_linux_real_chunk + + GRUB_LINUX_CL_OFFSET + sizeof (LINUX_IMAGE) - 1, + GRUB_LINUX_CL_END_OFFSET - GRUB_LINUX_CL_OFFSET + - (sizeof (LINUX_IMAGE) - 1)); if (grub_linux_is_bzimage) grub_linux_prot_target = GRUB_LINUX_BZIMAGE_ADDR; diff --git a/grub-core/loader/powerpc/ieee1275/linux.c b/grub-core/loader/powerpc/ieee1275/linux.c index 231aec1d3..a99310cfd 100644 --- a/grub-core/loader/powerpc/ieee1275/linux.c +++ b/grub-core/loader/powerpc/ieee1275/linux.c @@ -27,6 +27,7 @@ #include #include #include +#include #define ELF32_LOADMASK (0xc0000000UL) #define ELF64_LOADMASK (0xc000000000000000ULL) @@ -238,9 +239,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), int argc, char *argv[]) { grub_elf_t elf = 0; - int i; int size; - char *dest; grub_dl_ref (my_mod); @@ -275,23 +274,15 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), goto out; } - size = sizeof ("BOOT_IMAGE=") + grub_strlen (argv[0]); - for (i = 0; i < argc; i++) - size += grub_strlen (argv[i]) + 1; - - linux_args = grub_malloc (size); + size = grub_loader_cmdline_size(argc, argv); + linux_args = grub_malloc (size + sizeof (LINUX_IMAGE)); if (! linux_args) goto out; - /* Specify the boot file. */ - dest = grub_stpcpy (linux_args, "BOOT_IMAGE="); - dest = grub_stpcpy (dest, argv[0]); - - for (i = 1; i < argc; i++) - { - *dest++ = ' '; - dest = grub_stpcpy (dest, argv[i]); - } + /* Create kernel command line. */ + grub_memcpy (linux_args, LINUX_IMAGE, sizeof (LINUX_IMAGE)); + grub_create_loader_cmdline (argc, argv, linux_args + sizeof (LINUX_IMAGE) - 1, + size); out: diff --git a/grub-core/loader/sparc64/ieee1275/linux.c b/grub-core/loader/sparc64/ieee1275/linux.c index 8ea96f1c9..a262049a7 100644 --- a/grub-core/loader/sparc64/ieee1275/linux.c +++ b/grub-core/loader/sparc64/ieee1275/linux.c @@ -27,6 +27,7 @@ #include #include #include +#include static grub_dl_t my_mod; @@ -295,9 +296,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), { grub_file_t file = 0; grub_elf_t elf = 0; - int i; int size; - char *dest; grub_dl_ref (my_mod); @@ -333,23 +332,16 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), goto out; } - size = sizeof ("BOOT_IMAGE=") + grub_strlen (argv[0]); - for (i = 0; i < argc; i++) - size += grub_strlen (argv[i]) + 1; + size = grub_loader_cmdline_size(argc, argv); - linux_args = grub_malloc (size); + linux_args = grub_malloc (size + sizeof (LINUX_IMAGE)); if (! linux_args) goto out; - /* Specify the boot file. */ - dest = grub_stpcpy (linux_args, "BOOT_IMAGE="); - dest = grub_stpcpy (dest, argv[0]); - - for (i = 1; i < argc; i++) - { - *dest++ = ' '; - dest = grub_stpcpy (dest, argv[i]); - } + /* Create kernel command line. */ + grub_memcpy (linux_args, LINUX_IMAGE, sizeof (LINUX_IMAGE)); + grub_create_loader_cmdline (argc, argv, linux_args + sizeof (LINUX_IMAGE) - 1, + size); out: if (elf) diff --git a/include/grub/lib/cmdline.h b/include/grub/lib/cmdline.h new file mode 100644 index 000000000..1fe8d0179 --- /dev/null +++ b/include/grub/lib/cmdline.h @@ -0,0 +1,31 @@ +/* cmdline.h - linux command line handling */ +/* + * 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 . + */ + +#ifndef GRUB_CMDLINE_HEADER +#define GRUB_CMDLINE_HEADER 1 + +#include + +#define LINUX_IMAGE "BOOT_IMAGE=" + +unsigned int grub_loader_cmdline_size (int argc, char *argv[]); +int grub_create_loader_cmdline (int argc, char *argv[], char *buf, + grub_size_t size); + +#endif /* ! GRUB_CMDLINE_HEADER */ From 11b970d7c9e820e4d7574d0cb63ddc55cd27176e Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Fri, 7 Jan 2011 17:24:25 +0000 Subject: [PATCH 213/869] Always initialise *relroot in grub_find_root_device_from_mountinfo, otherwise we free an uninitialised pointer if /proc is unmounted. Reported by: Scott Moser. --- grub-core/kern/emu/getroot.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/grub-core/kern/emu/getroot.c b/grub-core/kern/emu/getroot.c index 373834127..a4cfaffc9 100644 --- a/grub-core/kern/emu/getroot.c +++ b/grub-core/kern/emu/getroot.c @@ -111,13 +111,13 @@ grub_find_root_device_from_mountinfo (const char *dir, char **relroot) size_t len = 0; char *ret = NULL; + if (relroot) + *relroot = NULL; + fp = fopen ("/proc/self/mountinfo", "r"); if (! fp) return NULL; /* fall through to other methods */ - if (relroot) - *relroot = NULL; - while (getline (&buf, &len, fp) > 0) { int mnt_id, parent_mnt_id; From 64d1f0412bbbfafb0bef788ad6fe13b28329e65d Mon Sep 17 00:00:00 2001 From: Szymon Janc Date: Fri, 7 Jan 2011 22:42:02 +0100 Subject: [PATCH 214/869] * docs/grub.texi (Support automatic decompression): Update with xz decompression support. --- ChangeLog | 5 +++++ docs/grub.texi | 8 +++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index d1ddc8741..d65e97e09 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-01-07 Szymon Janc + + * docs/grub.texi (Support automatic decompression): Update with xz + decompression support. + 2011-01-07 Szymon Janc Improve loaders' kernel command line handling. diff --git a/docs/grub.texi b/docs/grub.texi index 54a2d8791..daf48da13 100644 --- a/docs/grub.texi +++ b/docs/grub.texi @@ -346,9 +346,11 @@ ext2/ext3/ext4}, @dfn{DOS FAT12/FAT16/FAT32}, @dfn{HFS}, @dfn{HFS+}, @dfn{BSD UFS/UFS2}, and @dfn{XFS}. @xref{Filesystem}, for more information. @item Support automatic decompression -Can decompress files which were compressed by @command{gzip}. This -function is both automatic and transparent to the user (i.e. all -functions operate upon the uncompressed contents of the specified +Can decompress files which were compressed by @command{gzip} or +@command{xz}@footnote{Only CRC32 data integrity check is supported (xz default +is CRC64 so one should use --check=crc32 option). LZMA BCJ filters are +supported.}. This function is both automatic and transparent to the user +(i.e. all functions operate upon the uncompressed contents of the specified files). This greatly reduces a file size and loading time, a particularly great benefit for floppies.@footnote{There are a few pathological cases where loading a very badly organized ELF kernel might From 43f1bc8369211247259581d458a0f3aaa9782bbb Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 8 Jan 2011 00:27:38 +0100 Subject: [PATCH 215/869] * grub-core/loader/i386/bsdXX.c (grub_netbsd_load_elf_meta): Silence spurious warning. Reported and tested by: Alain Greppin. --- ChangeLog | 6 ++++++ grub-core/loader/i386/bsdXX.c | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index d65e97e09..52f59019b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2011-01-08 Vladimir Serbinenko + + * grub-core/loader/i386/bsdXX.c (grub_netbsd_load_elf_meta): + Silence spurious warning. + Reported and tested by: Alain Greppin. + 2011-01-07 Szymon Janc * docs/grub.texi (Support automatic decompression): Update with xz diff --git a/grub-core/loader/i386/bsdXX.c b/grub-core/loader/i386/bsdXX.c index 2dd180509..5b9e7689e 100644 --- a/grub-core/loader/i386/bsdXX.c +++ b/grub-core/loader/i386/bsdXX.c @@ -394,7 +394,7 @@ SUFFIX (grub_netbsd_load_elf_meta) (struct grub_relocator *relocator, grub_err_t err; Elf_Ehdr e; Elf_Shdr *s, *symsh, *strsh; - char *shdr; + char *shdr = NULL; unsigned symsize, strsize; void *sym_chunk; grub_uint8_t *curload; From 0fd48e357f73864f7a334be23153e973f2f76f2a Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 8 Jan 2011 00:34:23 +0100 Subject: [PATCH 216/869] Satisfy some bison versions need for inttypes.h. * grub-core/lib/posix_wrap/inttypes.h: New file. * grub-core/lib/posix_wrap/sys/types.h (int8_t): New type. (int16_t): Likewise. (int32_t): Likewise. (int64_t): Likewise. Reported and tested by: Alain Greppin. --- ChangeLog | 11 +++++++++++ grub-core/lib/posix_wrap/inttypes.h | 1 + grub-core/lib/posix_wrap/sys/types.h | 5 +++++ 3 files changed, 17 insertions(+) create mode 100644 grub-core/lib/posix_wrap/inttypes.h diff --git a/ChangeLog b/ChangeLog index 52f59019b..1a297da01 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2011-01-08 Vladimir Serbinenko + + Satisfy some bison versions need for inttypes.h. + + * grub-core/lib/posix_wrap/inttypes.h: New file. + * grub-core/lib/posix_wrap/sys/types.h (int8_t): New type. + (int16_t): Likewise. + (int32_t): Likewise. + (int64_t): Likewise. + Reported and tested by: Alain Greppin. + 2011-01-08 Vladimir Serbinenko * grub-core/loader/i386/bsdXX.c (grub_netbsd_load_elf_meta): diff --git a/grub-core/lib/posix_wrap/inttypes.h b/grub-core/lib/posix_wrap/inttypes.h new file mode 100644 index 000000000..a12c43b15 --- /dev/null +++ b/grub-core/lib/posix_wrap/inttypes.h @@ -0,0 +1 @@ +#include diff --git a/grub-core/lib/posix_wrap/sys/types.h b/grub-core/lib/posix_wrap/sys/types.h index 4e8331fdd..69e49509e 100644 --- a/grub-core/lib/posix_wrap/sys/types.h +++ b/grub-core/lib/posix_wrap/sys/types.h @@ -32,6 +32,11 @@ typedef grub_uint16_t uint16_t; typedef grub_uint32_t uint32_t; typedef grub_uint64_t uint64_t; +typedef grub_int8_t int8_t; +typedef grub_int16_t int16_t; +typedef grub_int32_t int32_t; +typedef grub_int64_t int64_t; + #ifdef GRUB_CPU_WORDS_BIGENDIAN #define WORDS_BIGENDIAN #else From 9462775a2df7842cf4a4c21f19e5dd1d92ef5183 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 8 Jan 2011 00:39:12 +0100 Subject: [PATCH 217/869] * grub-core/Makefile.am (rs_decoder.S): Force compilation with -Os. Reported and tested by: Alain Greppin. --- ChangeLog | 5 +++++ grub-core/Makefile.am | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 1a297da01..984c3fc5a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-01-08 Vladimir Serbinenko + + * grub-core/Makefile.am (rs_decoder.S): Force compilation with -Os. + Reported and tested by: Alain Greppin. + 2011-01-08 Vladimir Serbinenko Satisfy some bison versions need for inttypes.h. diff --git a/grub-core/Makefile.am b/grub-core/Makefile.am index 073ce37f6..fcf3fc42d 100644 --- a/grub-core/Makefile.am +++ b/grub-core/Makefile.am @@ -50,7 +50,7 @@ grub_script.yy.h: script/yylex.l grub_script.yy.c: grub_script.yy.h rs_decoder.S: $(srcdir)/lib/reed_solomon.c - $(TARGET_CC) $(TARGET_CPPFLAGS) $(TARGET_CFLAGS) -I$(top_builddir) -S -DSTANDALONE -o $@ $< -g0 -mregparm=3 + $(TARGET_CC) $(TARGET_CPPFLAGS) $(TARGET_CFLAGS) -Os -I$(top_builddir) -S -DSTANDALONE -o $@ $< -g0 -mregparm=3 kern/i386/pc/startup.S: $(builddir)/rs_decoder.S From ec1dfd634e3c2f09d9e293239529c5ea784ac102 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 8 Jan 2011 00:44:38 +0100 Subject: [PATCH 218/869] * configure.ac: Do CPU substitution even if it's specified explicitly. Reported and tested by: Alain Greppin. --- ChangeLog | 5 +++++ configure.ac | 15 ++++++--------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index 984c3fc5a..5116604f5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-01-08 Vladimir Serbinenko + + * configure.ac: Do CPU substitution even if it's specified explicitly. + Reported and tested by: Alain Greppin. + 2011-01-08 Vladimir Serbinenko * grub-core/Makefile.am (rs_decoder.S): Force compilation with -Os. diff --git a/configure.ac b/configure.ac index c013c9022..8bb585a78 100644 --- a/configure.ac +++ b/configure.ac @@ -103,15 +103,12 @@ else platform="$with_platform" fi -# Adjust CPU unless target was explicitly specified. -if test -z "$target_alias"; then - case "$target_cpu"-"$platform" in - x86_64-efi) ;; - x86_64-emu) ;; - x86_64-*) target_cpu=i386 ;; - powerpc64-ieee1275) target_cpu=powerpc ;; - esac -fi +case "$target_cpu"-"$platform" in + x86_64-efi) ;; + x86_64-emu) ;; + x86_64-*) target_cpu=i386 ;; + powerpc64-ieee1275) target_cpu=powerpc ;; +esac # Check if the platform is supported, make final adjustments. case "$target_cpu"-"$platform" in From f9f376488bc602b6c8f370c6697e0765747ac1c6 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 8 Jan 2011 01:45:57 +0100 Subject: [PATCH 219/869] =?UTF-8?q?=09*=20grub-core/term/at=5Fkeyboard.c?= =?UTF-8?q?=20(grub=5Fkeyboard=5Fgetkey):=20Silence=20spurious=20=09warnin?= =?UTF-8?q?g.=20=09Reported=20and=20tested=20by:=20Gr=C3=A9goire=20Sutre.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ChangeLog | 6 ++++++ grub-core/term/at_keyboard.c | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 5116604f5..4c2fd2a62 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2011-01-08 Vladimir Serbinenko + + * grub-core/term/at_keyboard.c (grub_keyboard_getkey): Silence spurious + warning. + Reported and tested by: GrĂ©goire Sutre. + 2011-01-08 Vladimir Serbinenko * configure.ac: Do CPU substitution even if it's specified explicitly. diff --git a/grub-core/term/at_keyboard.c b/grub-core/term/at_keyboard.c index 5bc3f578c..55cb76483 100644 --- a/grub-core/term/at_keyboard.c +++ b/grub-core/term/at_keyboard.c @@ -494,7 +494,7 @@ static int grub_keyboard_getkey (void) { int key; - int is_break; + int is_break = 0; key = fetch_key (&is_break); if (key == -1) From fc836af9a520da52a84c74b99d06de8a3fd117b6 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 8 Jan 2011 01:50:06 +0100 Subject: [PATCH 220/869] =?UTF-8?q?=09*=20grub-core/commands/terminal.c=20?= =?UTF-8?q?(grub=5Fcmd=5Fterminal=5Finput):=20Silence=20=09aliasing=20warn?= =?UTF-8?q?ing.=20=09(grub=5Fcmd=5Fterminal=5Foutput):=20Likewise.=20=09Re?= =?UTF-8?q?ported=20and=20tested=20by:=20Gr=C3=A9goire=20Sutre.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ChangeLog | 7 +++++++ grub-core/commands/terminal.c | 21 +++++++++++---------- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4c2fd2a62..7545cbef9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2011-01-08 Vladimir Serbinenko + + * grub-core/commands/terminal.c (grub_cmd_terminal_input): Silence + aliasing warning. + (grub_cmd_terminal_output): Likewise. + Reported and tested by: GrĂ©goire Sutre. + 2011-01-08 Vladimir Serbinenko * grub-core/term/at_keyboard.c (grub_keyboard_getkey): Silence spurious diff --git a/grub-core/commands/terminal.c b/grub-core/commands/terminal.c index c8b1b6315..c2d9550f6 100644 --- a/grub-core/commands/terminal.c +++ b/grub-core/commands/terminal.c @@ -210,11 +210,11 @@ grub_cmd_terminal_input (grub_command_t cmd __attribute__ ((unused)), (void) GRUB_FIELD_MATCH (grub_term_inputs, struct abstract_terminal *, init); (void) GRUB_FIELD_MATCH (grub_term_inputs, struct abstract_terminal *, fini); return handle_command (argc, args, - (struct abstract_terminal **) &grub_term_inputs, - (struct abstract_terminal **) &grub_term_inputs_disabled, - grub_term_input_autoload, - N_ ("Active input terminals:"), - N_ ("Available input terminals:")); + (struct abstract_terminal **) (void *) &grub_term_inputs, + (struct abstract_terminal **) (void *) &grub_term_inputs_disabled, + grub_term_input_autoload, + N_ ("Active input terminals:"), + N_ ("Available input terminals:")); } static grub_err_t @@ -225,11 +225,12 @@ grub_cmd_terminal_output (grub_command_t cmd __attribute__ ((unused)), (void) GRUB_FIELD_MATCH (grub_term_outputs, struct abstract_terminal *, name); (void) GRUB_FIELD_MATCH (grub_term_outputs, struct abstract_terminal *, init); (void) GRUB_FIELD_MATCH (grub_term_outputs, struct abstract_terminal *, fini); - return handle_command (argc, args, (struct abstract_terminal **) &grub_term_outputs, - (struct abstract_terminal **) &grub_term_outputs_disabled, - grub_term_output_autoload, - N_ ("Active output terminals:"), - N_ ("Available output terminals:")); + return handle_command (argc, args, + (struct abstract_terminal **) (void *) &grub_term_outputs, + (struct abstract_terminal **) (void *) &grub_term_outputs_disabled, + grub_term_output_autoload, + N_ ("Active output terminals:"), + N_ ("Available output terminals:")); } static grub_command_t cmd_terminal_input, cmd_terminal_output; From e7121b69329ce5bff182ab85ccaf2f888a07a7b9 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 8 Jan 2011 01:56:09 +0100 Subject: [PATCH 221/869] * grub-core/fs/zfs/zfs.c (dmu_read): Use void * for some pointers to avoid aliasing. (fzap_lookup): Likewise. (dnode_get): Likewise. (make_mdn): Likewise. (zfs_mount): Likewise. (fzap_iterate): Use temporary pointer to avoid aliasing. (grub_zfs_read): Likewise. * grub-core/loader/i386/xnu.c (grub_xnu_boot): Likewise. * grub-core/loader/xnu.c (grub_cmd_xnu_kernel): Use void * for some pointers to avoid aliasing. (grub_cmd_xnu_kernel64): Likewise. (grub_xnu_load_driver): Likewise. --- ChangeLog | 16 ++++++++++++++ grub-core/fs/zfs/zfs.c | 43 +++++++++++++++++++++---------------- grub-core/loader/i386/xnu.c | 10 +++++---- grub-core/loader/xnu.c | 27 +++++++++++++---------- 4 files changed, 63 insertions(+), 33 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7545cbef9..0f132cb01 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,19 @@ +2011-01-08 Vladimir Serbinenko + + * grub-core/fs/zfs/zfs.c (dmu_read): Use void * for some pointers to + avoid aliasing. + (fzap_lookup): Likewise. + (dnode_get): Likewise. + (make_mdn): Likewise. + (zfs_mount): Likewise. + (fzap_iterate): Use temporary pointer to avoid aliasing. + (grub_zfs_read): Likewise. + * grub-core/loader/i386/xnu.c (grub_xnu_boot): Likewise. + * grub-core/loader/xnu.c (grub_cmd_xnu_kernel): Use void * for some + pointers to avoid aliasing. + (grub_cmd_xnu_kernel64): Likewise. + (grub_xnu_load_driver): Likewise. + 2011-01-08 Vladimir Serbinenko * grub-core/commands/terminal.c (grub_cmd_terminal_input): Silence diff --git a/grub-core/fs/zfs/zfs.c b/grub-core/fs/zfs/zfs.c index 8901af76f..5b575f369 100644 --- a/grub-core/fs/zfs/zfs.c +++ b/grub-core/fs/zfs/zfs.c @@ -603,7 +603,8 @@ dmu_read (dnode_end_t * dn, grub_uint64_t blkid, void **buf, int idx, level; blkptr_t *bp_array = dn->dn.dn_blkptr; int epbs = dn->dn.dn_indblkshift - SPA_BLKPTRSHIFT; - blkptr_t *bp, *tmpbuf = 0; + blkptr_t *bp; + void *tmpbuf = 0; grub_zfs_endian_t endian; grub_err_t err = GRUB_ERR_NONE; @@ -646,7 +647,7 @@ dmu_read (dnode_end_t * dn, grub_uint64_t blkid, void **buf, break; } grub_dprintf ("zfs", "endian = %d\n", endian); - err = zio_read (bp, endian, (void **) &tmpbuf, 0, data); + err = zio_read (bp, endian, &tmpbuf, 0, data); endian = (grub_zfs_to_cpu64 (bp->blk_prop, endian) >> 63) & 1; if (err) break; @@ -880,7 +881,7 @@ static grub_err_t fzap_lookup (dnode_end_t * zap_dnode, zap_phys_t * zap, char *name, grub_uint64_t * value, struct grub_zfs_data *data) { - zap_leaf_phys_t *l; + void *l; grub_uint64_t hash, idx, blkid; int blksft = zfs_log2 (grub_zfs_to_cpu16 (zap_dnode->dn.dn_datablkszsec, zap_dnode->endian) << DNODE_SHIFT); @@ -903,7 +904,7 @@ fzap_lookup (dnode_end_t * zap_dnode, zap_phys_t * zap, /* Get the leaf block */ if ((1U << blksft) < sizeof (zap_leaf_phys_t)) return grub_error (GRUB_ERR_BAD_FS, "ZAP leaf is too small"); - err = dmu_read (zap_dnode, blkid, (void **) &l, &leafendian, data); + err = dmu_read (zap_dnode, blkid, &l, &leafendian, data); if (err) return err; @@ -920,6 +921,7 @@ fzap_iterate (dnode_end_t * zap_dnode, zap_phys_t * zap, struct grub_zfs_data *data) { zap_leaf_phys_t *l; + void *l_in; grub_uint64_t idx, blkid; grub_uint16_t chunk; int blksft = zfs_log2 (grub_zfs_to_cpu16 (zap_dnode->dn.dn_datablkszsec, @@ -947,7 +949,8 @@ fzap_iterate (dnode_end_t * zap_dnode, zap_phys_t * zap, { blkid = ((grub_uint64_t *) zap)[idx + (1 << (blksft - 3 - 1))]; - err = dmu_read (zap_dnode, blkid, (void **) &l, &endian, data); + err = dmu_read (zap_dnode, blkid, &l_in, &endian, data); + l = l_in; if (err) { grub_errno = GRUB_ERR_NONE; @@ -1108,7 +1111,7 @@ dnode_get (dnode_end_t * mdn, grub_uint64_t objnum, grub_uint8_t type, grub_uint64_t blkid, blksz; /* the block id this object dnode is in */ int epbs; /* shift of number of dnodes in a block */ int idx; /* index within a block */ - dnode_phys_t *dnbuf; + void *dnbuf; grub_err_t err; grub_zfs_endian_t endian; @@ -1131,7 +1134,7 @@ dnode_get (dnode_end_t * mdn, grub_uint64_t objnum, grub_uint8_t type, grub_dprintf ("zfs", "endian = %d, blkid=%llx\n", mdn->endian, (unsigned long long) blkid); - err = dmu_read (mdn, blkid, (void **) &dnbuf, &endian, data); + err = dmu_read (mdn, blkid, &dnbuf, &endian, data); if (err) return err; grub_dprintf ("zfs", "alive\n"); @@ -1153,7 +1156,7 @@ dnode_get (dnode_end_t * mdn, grub_uint64_t objnum, grub_uint8_t type, data->dnode_endian = endian; } - grub_memmove (&(buf->dn), &dnbuf[idx], DNODE_SIZE); + grub_memmove (&(buf->dn), (dnode_phys_t *) dnbuf + idx, DNODE_SIZE); buf->endian = endian; if (type && buf->dn.dn_type != type) return grub_error(GRUB_ERR_BAD_FS, "incorrect dnode type"); @@ -1465,7 +1468,7 @@ get_filesystem_dnode (dnode_end_t * mosmdn, char *fsname, static grub_err_t make_mdn (dnode_end_t * mdn, struct grub_zfs_data *data) { - objset_phys_t *osp; + void *osp; blkptr_t *bp; grub_size_t ospsize; grub_err_t err; @@ -1473,7 +1476,7 @@ make_mdn (dnode_end_t * mdn, struct grub_zfs_data *data) grub_dprintf ("zfs", "endian = %d\n", mdn->endian); bp = &(((dsl_dataset_phys_t *) DN_BONUS (&mdn->dn))->ds_bp); - err = zio_read (bp, mdn->endian, (void **) &osp, &ospsize, data); + err = zio_read (bp, mdn->endian, &osp, &ospsize, data); if (err) return err; if (ospsize < OBJSET_PHYS_SIZE_V14) @@ -1483,7 +1486,8 @@ make_mdn (dnode_end_t * mdn, struct grub_zfs_data *data) } mdn->endian = (grub_zfs_to_cpu64 (bp->blk_prop, mdn->endian)>>63) & 1; - grub_memmove ((char *) &(mdn->dn), (char *) &osp->os_meta_dnode, DNODE_SIZE); + grub_memmove ((char *) &(mdn->dn), + (char *) &((objset_phys_t *) osp)->os_meta_dnode, DNODE_SIZE); grub_free (osp); return GRUB_ERR_NONE; } @@ -1960,7 +1964,7 @@ zfs_mount (grub_device_t dev) int label = 0; uberblock_phys_t *ub_array, *ubbest = NULL; vdev_boot_header_t *bh; - objset_phys_t *osp = 0; + void *osp = 0; grub_size_t ospsize; grub_err_t err; int vdevnum; @@ -2038,7 +2042,7 @@ zfs_mount (grub_device_t dev) ? LITTLE_ENDIAN : BIG_ENDIAN); err = zio_read (&ubbest->ubp_uberblock.ub_rootbp, ub_endian, - (void **) &osp, &ospsize, data); + &osp, &ospsize, data); if (err) { grub_dprintf ("zfs", "couldn't zio_read\n"); @@ -2067,7 +2071,8 @@ zfs_mount (grub_device_t dev) continue; #endif /* Got the MOS. Save it at the memory addr MOS. */ - grub_memmove (&(data->mos.dn), &osp->os_meta_dnode, DNODE_SIZE); + grub_memmove (&(data->mos.dn), &((objset_phys_t *) osp)->os_meta_dnode, + DNODE_SIZE); data->mos.endian = (grub_zfs_to_cpu64 (ubbest->ubp_uberblock.ub_rootbp.blk_prop, ub_endian) >> 63) & 1; grub_memmove (&(data->current_uberblock), &ubbest->ubp_uberblock, sizeof (uberblock_t)); @@ -2201,7 +2206,7 @@ grub_zfs_open (struct grub_file *file, const char *fsfilename) */ if (data->dnode.dn.dn_bonustype == DMU_OT_SA) { - sa_hdr_phys_t *sahdrp; + void *sahdrp; int hdrsize; if (data->dnode.dn.dn_bonuslen != 0) @@ -2212,7 +2217,7 @@ grub_zfs_open (struct grub_file *file, const char *fsfilename) { blkptr_t *bp = &data->dnode.dn.dn_spill; - err = zio_read (bp, data->dnode.endian, (void **) &sahdrp, NULL, data); + err = zio_read (bp, data->dnode.endian, &sahdrp, NULL, data); if (err) return err; } @@ -2221,7 +2226,7 @@ grub_zfs_open (struct grub_file *file, const char *fsfilename) return grub_error (GRUB_ERR_BAD_FS, "filesystem is corrupt"); } - hdrsize = SA_HDR_SIZE (sahdrp); + hdrsize = SA_HDR_SIZE (((sa_hdr_phys_t *) sahdrp)); file->size = *(grub_uint64_t *) ((char *) sahdrp + hdrsize + SA_SIZE_OFFSET); } else @@ -2280,6 +2285,7 @@ grub_zfs_read (grub_file_t file, char *buf, grub_size_t len) read = 0; while (length) { + void *t; /* * Find requested blkid and the offset within that block. */ @@ -2287,8 +2293,9 @@ grub_zfs_read (grub_file_t file, char *buf, grub_size_t len) grub_free (data->file_buf); data->file_buf = 0; - err = dmu_read (&(data->dnode), blkid, (void **) &(data->file_buf), + err = dmu_read (&(data->dnode), blkid, &t, 0, data); + data->file_buf = t; if (err) return -1; diff --git a/grub-core/loader/i386/xnu.c b/grub-core/loader/i386/xnu.c index a9435eff3..a0df6f4aa 100644 --- a/grub-core/loader/i386/xnu.c +++ b/grub-core/loader/i386/xnu.c @@ -951,10 +951,11 @@ grub_err_t grub_xnu_boot (void) { struct grub_xnu_boot_params *bootparams; + void *bp_in; grub_addr_t bootparams_target; grub_err_t err; grub_efi_uintn_t memory_map_size = 0; - grub_efi_memory_descriptor_t *memory_map; + void *memory_map; grub_addr_t memory_map_target; grub_efi_uintn_t map_key = 0; grub_efi_uintn_t descriptor_size = 0; @@ -1006,9 +1007,10 @@ grub_xnu_boot (void) /* Relocate the boot parameters to heap. */ err = grub_xnu_heap_malloc (sizeof (*bootparams), - (void **) &bootparams, &bootparams_target); + &bp_in, &bootparams_target); if (err) return err; + bootparams = bp_in; /* Set video. */ err = grub_xnu_set_video (bootparams); @@ -1035,7 +1037,7 @@ grub_xnu_boot (void) memory map growth. */ memory_map_size += 20 * descriptor_size; err = grub_xnu_heap_malloc (memory_map_size, - (void **) &memory_map, &memory_map_target); + &memory_map, &memory_map_target); if (err) return err; @@ -1109,7 +1111,7 @@ grub_xnu_boot (void) grub_xnu_arg1 = bootparams_target; grub_autoefi_set_virtual_address_map (memory_map_size, descriptor_size, - descriptor_version,memory_map); + descriptor_version, memory_map); state.eip = grub_xnu_entry_point; state.eax = grub_xnu_arg1; diff --git a/grub-core/loader/xnu.c b/grub-core/loader/xnu.c index 95857951a..5a84dea1c 100644 --- a/grub-core/loader/xnu.c +++ b/grub-core/loader/xnu.c @@ -342,7 +342,8 @@ grub_cmd_xnu_kernel (grub_command_t cmd __attribute__ ((unused)), grub_macho_t macho; grub_uint32_t startcode, endcode; int i; - char *ptr, *loadaddr; + char *ptr; + void *loadaddr; grub_addr_t loadaddr_target; if (argc < 1) @@ -375,7 +376,7 @@ grub_cmd_xnu_kernel (grub_command_t cmd __attribute__ ((unused)), if (!grub_xnu_relocator) return grub_errno; grub_xnu_heap_target_start = startcode; - err = grub_xnu_heap_malloc (endcode - startcode, (void **) &loadaddr, + err = grub_xnu_heap_malloc (endcode - startcode, &loadaddr, &loadaddr_target); if (err) @@ -386,7 +387,8 @@ grub_cmd_xnu_kernel (grub_command_t cmd __attribute__ ((unused)), } /* Load kernel. */ - err = grub_macho_load32 (macho, loadaddr - startcode, GRUB_MACHO_NOBSS); + err = grub_macho_load32 (macho, (char *) loadaddr - startcode, + GRUB_MACHO_NOBSS); if (err) { grub_macho_close (macho); @@ -450,7 +452,8 @@ grub_cmd_xnu_kernel64 (grub_command_t cmd __attribute__ ((unused)), grub_macho_t macho; grub_uint64_t startcode, endcode; int i; - char *ptr, *loadaddr; + char *ptr; + void *loadaddr; grub_addr_t loadaddr_target; if (argc < 1) @@ -486,7 +489,7 @@ grub_cmd_xnu_kernel64 (grub_command_t cmd __attribute__ ((unused)), if (!grub_xnu_relocator) return grub_errno; grub_xnu_heap_target_start = startcode; - err = grub_xnu_heap_malloc (endcode - startcode, (void **) &loadaddr, + err = grub_xnu_heap_malloc (endcode - startcode, &loadaddr, &loadaddr_target); if (err) @@ -497,7 +500,8 @@ grub_cmd_xnu_kernel64 (grub_command_t cmd __attribute__ ((unused)), } /* Load kernel. */ - err = grub_macho_load64 (macho, loadaddr - startcode, GRUB_MACHO_NOBSS); + err = grub_macho_load64 (macho, (char *) loadaddr - startcode, + GRUB_MACHO_NOBSS); if (err) { grub_macho_close (macho); @@ -636,7 +640,8 @@ grub_xnu_load_driver (char *infoplistname, grub_file_t binaryfile) grub_file_t infoplist; struct grub_xnu_extheader *exthead; int neededspace = sizeof (*exthead); - grub_uint8_t *buf, *buf0; + grub_uint8_t *buf; + void *buf0; grub_addr_t buf_target; grub_size_t infoplistsize = 0, machosize = 0; char *name, *nameend; @@ -692,7 +697,7 @@ grub_xnu_load_driver (char *infoplistname, grub_file_t binaryfile) err = grub_xnu_align_heap (GRUB_XNU_PAGESIZE); if (err) return err; - err = grub_xnu_heap_malloc (neededspace, (void **) &buf0, &buf_target); + err = grub_xnu_heap_malloc (neededspace, &buf0, &buf_target); if (err) return err; buf = buf0; @@ -704,7 +709,7 @@ grub_xnu_load_driver (char *infoplistname, grub_file_t binaryfile) /* Load the binary. */ if (macho) { - exthead->binaryaddr = buf_target + (buf - buf0); + exthead->binaryaddr = buf_target + (buf - (grub_uint8_t *) buf0); exthead->binarysize = machosize; if (grub_xnu_is_64bit) err = grub_macho_readfile64 (macho, buf); @@ -723,7 +728,7 @@ grub_xnu_load_driver (char *infoplistname, grub_file_t binaryfile) /* Load the plist. */ if (infoplist) { - exthead->infoplistaddr = buf_target + (buf - buf0); + exthead->infoplistaddr = buf_target + (buf - (grub_uint8_t *) buf0); exthead->infoplistsize = infoplistsize + 1; if (grub_file_read (infoplist, buf, infoplistsize) != (grub_ssize_t) (infoplistsize)) @@ -739,7 +744,7 @@ grub_xnu_load_driver (char *infoplistname, grub_file_t binaryfile) } grub_errno = GRUB_ERR_NONE; - exthead->nameaddr = (buf - buf0) + buf_target; + exthead->nameaddr = (buf - (grub_uint8_t *) buf0) + buf_target; exthead->namesize = namelen + 1; grub_memcpy (buf, name, namelen); buf[namelen] = 0; From 4b0782664739170dc3688a55e667a56146128e78 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 8 Jan 2011 16:33:49 +0100 Subject: [PATCH 222/869] partitioned mdraid support (untested) --- grub-core/kern/emu/getroot.c | 2 +- grub-core/kern/emu/hostdisk.c | 15 ++++++++++----- include/grub/emu/misc.h | 2 ++ 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/grub-core/kern/emu/getroot.c b/grub-core/kern/emu/getroot.c index a99bee9a4..0035c734a 100644 --- a/grub-core/kern/emu/getroot.c +++ b/grub-core/kern/emu/getroot.c @@ -639,7 +639,7 @@ grub_util_get_dev_abstraction (const char *os_dev __attribute__((unused))) return GRUB_DEV_ABSTRACTION_LVM; /* Check for RAID. */ - if (!strncmp (os_dev, "/dev/md", 7)) + if (!strncmp (os_dev, "/dev/md", 7) && ! grub_util_device_is_mapped (os_dev)) return GRUB_DEV_ABSTRACTION_RAID; #endif diff --git a/grub-core/kern/emu/hostdisk.c b/grub-core/kern/emu/hostdisk.c index ee3cc0a36..eb84d0220 100644 --- a/grub-core/kern/emu/hostdisk.c +++ b/grub-core/kern/emu/hostdisk.c @@ -325,18 +325,23 @@ grub_util_biosdisk_open (const char *name, grub_disk_t disk) return GRUB_ERR_NONE; } -#ifdef HAVE_DEVICE_MAPPER -static int -device_is_mapped (const char *dev) +int +grub_util_device_is_mapped (const char *dev) { +#ifdef HAVE_DEVICE_MAPPER struct stat st; + if (!grub_device_mapper_supported ()) + return 0; + if (stat (dev, &st) < 0) return 0; return dm_is_dm_major (major (st.st_rdev)); -} +#else + return 0; #endif /* HAVE_DEVICE_MAPPER */ +} #if defined(__linux__) || defined(__CYGWIN__) || defined(HAVE_DIOCGDINFO) static grub_disk_addr_t @@ -351,7 +356,7 @@ find_partition_start (const char *dev) # endif /* !defined(HAVE_DIOCGDINFO) */ # ifdef HAVE_DEVICE_MAPPER - if (grub_device_mapper_supported () && device_is_mapped (dev)) { + if (grub_util_device_is_mapped (dev)) { struct dm_task *task = NULL; grub_uint64_t start, length; char *target_type, *params, *space; diff --git a/include/grub/emu/misc.h b/include/grub/emu/misc.h index ef0d18300..03909e025 100644 --- a/include/grub/emu/misc.h +++ b/include/grub/emu/misc.h @@ -54,6 +54,8 @@ void grub_find_zpool_from_dir (const char *dir, char *grub_make_system_path_relative_to_its_root (const char *path) __attribute__ ((warn_unused_result)); +int +grub_util_device_is_mapped (const char *dev); 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)); From 53798c4bd1ae9c635740f72207c9db5509505f36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Sutre?= Date: Sat, 8 Jan 2011 17:01:38 +0100 Subject: [PATCH 223/869] Check for libdevmapper header --- ChangeLog | 4 ++++ configure.ac | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/ChangeLog b/ChangeLog index 0f132cb01..8a832d41d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2011-01-08 GrĂ©goire Sutre + + * configure.ac: Check for libdevmapper header. + 2011-01-08 Vladimir Serbinenko * grub-core/fs/zfs/zfs.c (dmu_read): Use void * for some pointers to diff --git a/configure.ac b/configure.ac index 8bb585a78..a9ca130b4 100644 --- a/configure.ac +++ b/configure.ac @@ -863,6 +863,12 @@ if test x"$enable_device_mapper" = xno ; then device_mapper_excuse="explicitly disabled" fi +if test x"$device_mapper_excuse" = x ; then + # Check for device-mapper header. + AC_CHECK_HEADER([libdevmapper.h], [], + [device_mapper_excuse="need libdevmapper header"]) +fi + if test x"$device_mapper_excuse" = x ; then # Check for device-mapper library. AC_CHECK_LIB([devmapper], [dm_task_create], [], From c88172fa92efe15950247491db154c01a58df074 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 8 Jan 2011 20:22:32 +0100 Subject: [PATCH 224/869] * config.h.in (_LARGEFILE_SOURCE): Add missing define. (_FILE_OFFSET_BITS): Likewise. Reported by: Seth Goldberg. --- ChangeLog | 6 ++++++ config.h.in | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/ChangeLog b/ChangeLog index 8a832d41d..30dd4798f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2011-01-08 Vladimir Serbinenko + + * config.h.in (_LARGEFILE_SOURCE): Add missing define. + (_FILE_OFFSET_BITS): Likewise. + Reported by: Seth Goldberg. + 2011-01-08 GrĂ©goire Sutre * configure.ac: Check for libdevmapper header. diff --git a/config.h.in b/config.h.in index 6d7d95dec..3974ad7d5 100644 --- a/config.h.in +++ b/config.h.in @@ -1,3 +1,7 @@ +#undef _LARGEFILE_SOURCE +#undef _FILE_OFFSET_BITS +#define _LARGEFILE_SOURCE +#define _FILE_OFFSET_BITS 64 #if defined (GRUB_UTIL) || !defined (GRUB_MACHINE) #include #define NESTED_FUNC_ATTR From a21e5672fd8edd1f7ab17204396fb436dba0c2ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Sutre?= Date: Sun, 9 Jan 2011 23:23:25 +0100 Subject: [PATCH 225/869] Handle openbsd and netbsd types being in part_bsd module. --- ChangeLog | 5 +++++ util/grub-mkconfig_lib.in | 7 ++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 30dd4798f..723df8522 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-01-09 GrĂ©goire Sutre + + * util/grub-mkconfig_lib.in (prepare_grub_to_access_device): Handle + openbsd and netbsd types being in part_bsd module. + 2011-01-08 Vladimir Serbinenko * config.h.in (_LARGEFILE_SOURCE): Add missing define. diff --git a/util/grub-mkconfig_lib.in b/util/grub-mkconfig_lib.in index ec4084698..2a48fb260 100644 --- a/util/grub-mkconfig_lib.in +++ b/util/grub-mkconfig_lib.in @@ -107,7 +107,12 @@ prepare_grub_to_access_device () partmap="`${grub_probe} --device ${device} --target=partmap`" for module in ${partmap} ; do - echo "insmod part_${module}" + case "${module}" in + netbsd | openbsd) + echo "insmod part_bsd";; + *) + echo "insmod part_${module}";; + esac done fs="`${grub_probe} --device ${device} --target=fs`" From 1f060f399a5eebbb50f0e3aa41e734de09380aad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Sutre?= Date: Mon, 10 Jan 2011 01:08:40 +0100 Subject: [PATCH 226/869] Teach grub-mkconfig to load fs modules for NetBSD. --- ChangeLog | 5 ++++ util/grub.d/10_netbsd.in | 62 ++++++++++++++++++++++++++++++++++++++-- 2 files changed, 64 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 723df8522..e215db3bd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-01-09 GrĂ©goire Sutre + + * util/grub.d/10_netbsd.in (netbsd_load_fs_module): New function. + (netbsd_entry): Use netbsd_load_fs_module() to load filesystem module. + 2011-01-09 GrĂ©goire Sutre * util/grub-mkconfig_lib.in (prepare_grub_to_access_device): Handle diff --git a/util/grub.d/10_netbsd.in b/util/grub.d/10_netbsd.in index 13f9d923a..ffd31ad93 100644 --- a/util/grub.d/10_netbsd.in +++ b/util/grub.d/10_netbsd.in @@ -27,11 +27,65 @@ export TEXTDOMAIN=@PACKAGE@ export TEXTDOMAINDIR=@localedir@ if [ "x${GRUB_DISTRIBUTOR}" = "x" ] ; then - OS=NetBSD + OS="NetBSD" else OS="${GRUB_DISTRIBUTOR} NetBSD" fi +netbsd_load_fs_module () +{ + loader="$1" # "knetbsd" or "multiboot" + kernel="$2" # absolute path to the kernel file + + case $(zcat -f "${kernel}" | file -bL - | cut -d , -f 2 | tr -d ' ') in + Intel80386) + karch="i386" + ;; + x86-64) + karch="amd64" + ;; + *) + return + ;; + esac + + case $(${grub_probe} --target=fs -d ${GRUB_DEVICE}) in + ext2) + kmod="ext2fs" + ;; + fat) + kmod="msdosfs" + ;; + ntfs) + kmod="ntfs" + ;; + ufs*) + kmod="ffs" + ;; + *) + return + ;; + esac + + kversion=$(zcat -f "${kernel}" | strings | sed -n -e '/^@(#)NetBSD/ { s/^@(#)NetBSD \([0-9\.]*\) .*$/\1/g ; p ; q ; }') + kmodule="/stand/${karch}/${kversion}/modules/${kmod}/${kmod}.kmod" + + if test -z "$karch" -o -z "$kversion" -o ! -f "${kmodule}"; then + return + fi + + kmodule_rel=$(make_system_path_relative_to_its_root "$kmodule") || return + prepare_grub_to_access_device $(${grub_probe} -t device "${kmodule}") | sed -e 's,^, ,' + case "${loader}" in + knetbsd) + printf "\tknetbsd_module_elf %s\n" "${kmodule_rel}" + ;; + multiboot) + printf "\tmodule %s\n" "${kmodule_rel}" + ;; + esac +} + netbsd_entry () { loader="$1" # "knetbsd" or "multiboot" @@ -59,6 +113,9 @@ netbsd_entry () "${kernel}" "${kernel}" "${kroot_device}" "${GRUB_CMDLINE_NETBSD} ${args}" ;; esac + + netbsd_load_fs_module "${loader}" "${kernel}" + printf "}\n" } @@ -72,8 +129,7 @@ for k in $(ls -t /netbsd*) ; do if ! grub_file_is_not_garbage "$k" ; then continue fi - if ! ((file -bL "$k" | grep -q "${pattern}") || - (zcat "$k" | file -bL - | grep -q "${pattern}")) 2>/dev/null ; then + if ! (zcat -f "$k" | file -bL - | grep -q "${pattern}") 2>/dev/null ; then continue fi From cf0eaf13a102d71b8f7d56af8b1d00a623903d0e Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 10 Jan 2011 17:28:29 +0100 Subject: [PATCH 227/869] * grub-core/disk/raid.c (insert_array): Display RAID name in duplicate members errors. --- ChangeLog | 5 +++++ grub-core/disk/raid.c | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index e215db3bd..85495e8ad 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-01-10 Vladimir Serbinenko + + * grub-core/disk/raid.c (insert_array): Display RAID name in duplicate + members errors. + 2011-01-09 GrĂ©goire Sutre * util/grub.d/10_netbsd.in (netbsd_load_fs_module): New function. diff --git a/grub-core/disk/raid.c b/grub-core/disk/raid.c index edc2b195d..c789fea50 100644 --- a/grub-core/disk/raid.c +++ b/grub-core/disk/raid.c @@ -530,8 +530,8 @@ insert_array (grub_disk_t disk, struct grub_raid_array *new_array, /* We found multiple devices with the same number. Again, this shouldn't happen. */ return grub_error (GRUB_ERR_BAD_DEVICE, - "found two disks with the number %d", - new_array->number); + "found two disks with the index %d for RAID %s", + new_array->index, array->name); if (new_array->disk_size < array->disk_size) array->disk_size = new_array->disk_size; From b1969b304927c0fcd7ad812d97e564ddf3216476 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 10 Jan 2011 17:35:32 +0100 Subject: [PATCH 228/869] * grub-core/fs/btrfs.c (grub_btrfs_mount): Transform out of range into badfs. Reported by: TiCPU. --- ChangeLog | 6 ++++++ grub-core/fs/btrfs.c | 3 +++ 2 files changed, 9 insertions(+) diff --git a/ChangeLog b/ChangeLog index 85495e8ad..12927d0f2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2011-01-10 Vladimir Serbinenko + + * grub-core/fs/btrfs.c (grub_btrfs_mount): Transform out of range into + badfs. + Reported by: TiCPU. + 2011-01-10 Vladimir Serbinenko * grub-core/disk/raid.c (insert_array): Display RAID name in duplicate diff --git a/grub-core/fs/btrfs.c b/grub-core/fs/btrfs.c index a2ee485b4..179891da8 100644 --- a/grub-core/fs/btrfs.c +++ b/grub-core/fs/btrfs.c @@ -60,6 +60,9 @@ grub_btrfs_mount (grub_disk_t disk) return data; fail: + if (grub_errno == GRUB_ERR_OUT_OF_RANGE) + grub_error (GRUB_ERR_BAD_FS, "not a Btrfs filesystem"); + grub_free (data); return NULL; } From c49849cc63560d02e042eda337135dbcf72a92fa Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 10 Jan 2011 17:51:06 +0100 Subject: [PATCH 229/869] * grub-core/kern/i386/pc/mmap.c (grub_get_conv_memsize): New function. (grub_machine_mmap_iterate): Take low memory into account --- ChangeLog | 5 +++++ grub-core/kern/i386/pc/mmap.c | 23 ++++++++++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 12927d0f2..34703b81d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-01-10 Vladimir Serbinenko + + * grub-core/kern/i386/pc/mmap.c (grub_get_conv_memsize): New function. + (grub_machine_mmap_iterate): Take low memory into account + 2011-01-10 Vladimir Serbinenko * grub-core/fs/btrfs.c (grub_btrfs_mount): Transform out of range into diff --git a/grub-core/kern/i386/pc/mmap.c b/grub-core/kern/i386/pc/mmap.c index a305d4511..480ffa949 100644 --- a/grub-core/kern/i386/pc/mmap.c +++ b/grub-core/kern/i386/pc/mmap.c @@ -36,6 +36,22 @@ struct grub_machine_mmap_entry } __attribute__((packed)); +/* + * + * grub_get_conv_memsize(i) : return the conventional memory size in KB. + * BIOS call "INT 12H" to get conventional memory size + * The return value in AX. + */ +static inline grub_uint16_t +grub_get_conv_memsize (void) +{ + struct grub_bios_int_registers regs; + + regs.flags = GRUB_CPU_INT_FLAGS_DEFAULT; + grub_bios_interrupt (0x12, ®s); + return regs.eax & 0xffff; +} + /* * grub_get_ext_memsize() : return the extended memory size in KB. * BIOS call "INT 15H, AH=88H" to get extended memory size @@ -155,6 +171,10 @@ grub_machine_mmap_iterate (grub_memory_hook_t hook) { grub_uint32_t eisa_mmap = grub_get_eisa_mmap (); + if (hook (0x0, ((grub_uint32_t) grub_get_conv_memsize ()) << 10, + GRUB_MEMORY_AVAILABLE)) + return 0; + if (eisa_mmap) { if (hook (0x100000, (eisa_mmap & 0xFFFF) << 10, @@ -162,7 +182,8 @@ grub_machine_mmap_iterate (grub_memory_hook_t hook) hook (0x1000000, eisa_mmap & ~0xFFFF, GRUB_MEMORY_AVAILABLE); } else - hook (0x100000, grub_get_ext_memsize () << 10, GRUB_MEMORY_AVAILABLE); + hook (0x100000, ((grub_uint32_t) grub_get_ext_memsize ()) << 10, + GRUB_MEMORY_AVAILABLE); } return 0; From db87be2aeab310b4740c0a6c556f667d43dd342e Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 10 Jan 2011 17:54:21 +0100 Subject: [PATCH 230/869] * grub-core/kern/i386/pc/init.c (grub_get_conv_memsize): Removed. (grub_machine_init): Don't check amount of low memory as reportedly INT 12h can be broken and if low memory is too low we wouldn't have gotten into grub_machine_init anyway. --- ChangeLog | 7 +++++++ grub-core/kern/i386/pc/init.c | 23 +++++++---------------- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/ChangeLog b/ChangeLog index 34703b81d..a1d948151 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2011-01-10 Vladimir Serbinenko + + * grub-core/kern/i386/pc/init.c (grub_get_conv_memsize): Removed. + (grub_machine_init): Don't check amount of low memory as reportedly + INT 12h can be broken and if low memory is too low we wouldn't have + gotten into grub_machine_init anyway. + 2011-01-10 Vladimir Serbinenko * grub-core/kern/i386/pc/mmap.c (grub_get_conv_memsize): New function. diff --git a/grub-core/kern/i386/pc/init.c b/grub-core/kern/i386/pc/init.c index 122c2c556..d8c337bde 100644 --- a/grub-core/kern/i386/pc/init.c +++ b/grub-core/kern/i386/pc/init.c @@ -140,36 +140,27 @@ compact_mem_regions (void) } } -/* - * - * grub_get_conv_memsize(i) : return the conventional memory size in KB. - * BIOS call "INT 12H" to get conventional memory size - * The return value in AX. - */ -static inline grub_uint16_t -grub_get_conv_memsize (void) -{ - struct grub_bios_int_registers regs; - - regs.flags = GRUB_CPU_INT_FLAGS_DEFAULT; - grub_bios_interrupt (0x12, ®s); - return regs.eax & 0xffff; -} - void grub_machine_init (void) { int i; +#if 0 int grub_lower_mem; +#endif /* Initialize the console as early as possible. */ grub_console_init (); + /* This sanity check is useless since top of GRUB_MEMORY_MACHINE_RESERVED_END + is used for stack and if it's unavailable we wouldn't have gotten so far. + */ +#if 0 grub_lower_mem = grub_get_conv_memsize () << 10; /* Sanity check. */ if (grub_lower_mem < GRUB_MEMORY_MACHINE_RESERVED_END) grub_fatal ("too small memory"); +#endif /* FIXME: This prevents loader/i386/linux.c from using low memory. When our heap implements support for requesting a chunk in low memory, this should From ce6bb3ee31b651a09cd513cf8af5fb3b142bb82c Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 10 Jan 2011 19:20:50 +0100 Subject: [PATCH 231/869] * util/grub-menulst2cfg.c (main): Trim the line. --- ChangeLog | 4 ++++ util/grub-menulst2cfg.c | 5 ++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index a1d948151..64f9a5be9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2011-01-10 Vladimir Serbinenko + + * util/grub-menulst2cfg.c (main): Trim the line. + 2011-01-10 Vladimir Serbinenko * grub-core/kern/i386/pc/init.c (grub_get_conv_memsize): Removed. diff --git a/util/grub-menulst2cfg.c b/util/grub-menulst2cfg.c index e29c6b17c..da1c289a8 100644 --- a/util/grub-menulst2cfg.c +++ b/util/grub-menulst2cfg.c @@ -78,9 +78,12 @@ main (int argc, char **argv) { char *oldname = NULL; char *newsuffix; + char *ptr; + + for (ptr = buf; *ptr && grub_isspace (*ptr); ptr++); oldname = entryname; - parsed = grub_legacy_parse (buf, &entryname, &newsuffix); + parsed = grub_legacy_parse (ptr, &entryname, &newsuffix); if (newsuffix) { suffixlen += strlen (newsuffix); From 47a77af5e8f03eed1edb60f81ab7764d54ab515a Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 10 Jan 2011 19:25:00 +0100 Subject: [PATCH 232/869] * grub-core/commands/legacycfg.c (legacy_file): Trim the line. --- ChangeLog | 4 ++++ grub-core/commands/legacycfg.c | 6 +++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 64f9a5be9..6461f79f4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2011-01-10 Vladimir Serbinenko + + * grub-core/commands/legacycfg.c (legacy_file): Trim the line. + 2011-01-10 Vladimir Serbinenko * util/grub-menulst2cfg.c (main): Trim the line. diff --git a/grub-core/commands/legacycfg.c b/grub-core/commands/legacycfg.c index de392ac81..71ac5c620 100644 --- a/grub-core/commands/legacycfg.c +++ b/grub-core/commands/legacycfg.c @@ -83,9 +83,13 @@ legacy_file (const char *filename) { char *oldname = NULL; char *newsuffix; + char *ptr; + + for (ptr = buf; *ptr && grub_isspace (*ptr); ptr++); oldname = entryname; - parsed = grub_legacy_parse (buf, &entryname, &newsuffix); + parsed = grub_legacy_parse (ptr, &entryname, &newsuffix); + grub_free (buf); buf = NULL; if (newsuffix) { From 6fef99b4e4121ccd3bf9208c13faa6433a51453f Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 10 Jan 2011 19:52:12 +0100 Subject: [PATCH 233/869] * util/grub-mklayout.c (usage): Update help text. --- ChangeLog | 4 ++++ util/grub-mklayout.c | 5 +++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 6461f79f4..d856bbff2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2011-01-10 Vladimir Serbinenko + + * util/grub-mklayout.c (usage): Update help text. + 2011-01-10 Vladimir Serbinenko * grub-core/commands/legacycfg.c (legacy_file): Trim the line. diff --git a/util/grub-mklayout.c b/util/grub-mklayout.c index e90d955ff..36f6e04fc 100644 --- a/util/grub-mklayout.c +++ b/util/grub-mklayout.c @@ -259,8 +259,9 @@ usage (int status) fprintf (stderr, "Try `%s --help' for more information.\n", program_name); else printf ("\ -Usage: %s [OPTIONS] LAYOUT\n\ - -o, --output set output base name file. Default is LAYOUT.gkb\n\ +Usage: %s [OPTIONS]\n\ + -i, --input set input filename. Default is STDIN\n\ + -o, --output set output filename. Default is STDOUT\n\ -h, --help display this message and exit.\n\ -V, --version print version information and exit.\n\ -v, --verbose print verbose messages.\n\ From dcb883b1623c730190357ad8803f88e592b6d364 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 10 Jan 2011 23:27:58 +0100 Subject: [PATCH 234/869] Submenu default support. * grub-core/normal/menu.c (grub_menu_execute_entry): New parameter auto_boot. All users updated. Declared static. Handle chosen and default with submenus. (grub_menu_execute_with_fallback): Declared static. Don't notify failure if autobooted. Upper level does it. (menuentry_eq): New function. (get_entry_number): Use menuentry_eq. (show_menu): New parameter "autobooted". All users updated. (grub_show_menu): Likewise. * include/grub/normal.h (grub_show_menu): Likewise. * include/grub/menu.h (grub_menu_execute_entry): Removed. (grub_menu_execute_with_fallback): Likewise. --- ChangeLog | 18 +++++ grub-core/commands/legacycfg.c | 2 +- grub-core/normal/main.c | 2 +- grub-core/normal/menu.c | 130 +++++++++++++++++++++++++++++---- grub-core/normal/menu_entry.c | 2 +- include/grub/menu.h | 5 -- include/grub/normal.h | 2 +- 7 files changed, 137 insertions(+), 24 deletions(-) diff --git a/ChangeLog b/ChangeLog index d856bbff2..976c2cf5b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,21 @@ +2011-01-10 Vladimir Serbinenko + + Submenu default support. + + * grub-core/normal/menu.c (grub_menu_execute_entry): New parameter + auto_boot. All users updated. + Declared static. + Handle chosen and default with submenus. + (grub_menu_execute_with_fallback): Declared static. + Don't notify failure if autobooted. Upper level does it. + (menuentry_eq): New function. + (get_entry_number): Use menuentry_eq. + (show_menu): New parameter "autobooted". All users updated. + (grub_show_menu): Likewise. + * include/grub/normal.h (grub_show_menu): Likewise. + * include/grub/menu.h (grub_menu_execute_entry): Removed. + (grub_menu_execute_with_fallback): Likewise. + 2011-01-10 Vladimir Serbinenko * util/grub-mklayout.c (usage): Update help text. diff --git a/grub-core/commands/legacycfg.c b/grub-core/commands/legacycfg.c index 71ac5c620..23c1c1908 100644 --- a/grub-core/commands/legacycfg.c +++ b/grub-core/commands/legacycfg.c @@ -213,7 +213,7 @@ grub_cmd_legacy_source (struct grub_command *cmd, grub_menu_t menu; menu = grub_env_get_menu (); if (menu && menu->size) - grub_show_menu (menu, 1); + grub_show_menu (menu, 1, 0); if (!extractor) grub_env_context_close (); } diff --git a/grub-core/normal/main.c b/grub-core/normal/main.c index 3bfbbeb72..69bf5e6b5 100644 --- a/grub-core/normal/main.c +++ b/grub-core/normal/main.c @@ -287,7 +287,7 @@ grub_normal_execute (const char *config, int nested, int batch) { if (menu && menu->size) { - grub_show_menu (menu, nested); + grub_show_menu (menu, nested, 0); if (nested) grub_normal_free_menu (menu); } diff --git a/grub-core/normal/menu.c b/grub-core/normal/menu.c index 807ad51e0..6a123a6de 100644 --- a/grub-core/normal/menu.c +++ b/grub-core/normal/menu.c @@ -154,12 +154,15 @@ get_and_remove_first_entry_number (const char *name) } /* Run a menu entry. */ -void -grub_menu_execute_entry(grub_menu_entry_t entry) +static void +grub_menu_execute_entry(grub_menu_entry_t entry, int auto_boot) { grub_err_t err = GRUB_ERR_NONE; int errs_before; grub_menu_t menu; + char *optr, *buf, *oldchosen = NULL, *olddefault = NULL; + const char *ptr, *chosen, *def; + grub_size_t sz = 0; if (entry->restricted) err = grub_auth_check_authentication (entry->users); @@ -173,6 +176,9 @@ grub_menu_execute_entry(grub_menu_entry_t entry) errs_before = grub_err_printed_errors; + chosen = grub_env_get ("chosen"); + def = grub_env_get ("default"); + if (entry->submenu) { grub_env_context_open (); @@ -180,9 +186,64 @@ grub_menu_execute_entry(grub_menu_entry_t entry) if (! menu) return; grub_env_set_menu (menu); + if (auto_boot) + grub_env_set ("timeout", "0"); } - grub_env_set ("chosen", entry->title); + for (ptr = entry->title; *ptr; ptr++) + sz += (*ptr == '>') ? 2 : 1; + if (chosen) + { + oldchosen = grub_strdup (chosen); + if (!oldchosen) + grub_print_error (); + } + if (def) + { + olddefault = grub_strdup (def); + if (!olddefault) + grub_print_error (); + } + sz++; + if (chosen) + sz += grub_strlen (chosen); + sz++; + buf = grub_malloc (sz); + if (!buf) + grub_print_error (); + else + { + optr = buf; + if (chosen) + { + optr = grub_stpcpy (optr, chosen); + *optr++ = '>'; + } + for (ptr = entry->title; *ptr; ptr++) + { + if (*ptr == '>') + *optr++ = '>'; + *optr++ = *ptr; + } + *optr = 0; + grub_env_set ("chosen", buf); + grub_env_export ("chosen"); + grub_free (buf); + } + for (ptr = def; *ptr; ptr++) + { + if (ptr[0] == '>' && ptr[1] == '>') + { + ptr++; + continue; + } + if (ptr[0] == '>') + break; + } + if (ptr[0] && ptr[1]) + grub_env_set ("default", ptr + 1); + else + grub_env_unset ("default"); grub_script_execute_sourcecode (entry->sourcecode, entry->argc, entry->args); if (errs_before != grub_err_printed_errors) @@ -196,20 +257,30 @@ grub_menu_execute_entry(grub_menu_entry_t entry) { if (menu && menu->size) { - grub_show_menu (menu, 1); + grub_show_menu (menu, 1, auto_boot); grub_normal_free_menu (menu); } grub_env_context_close (); } + if (oldchosen) + grub_env_set ("chosen", oldchosen); + else + grub_env_unset ("chosen"); + if (olddefault) + grub_env_set ("default", olddefault); + else + grub_env_unset ("default"); + grub_env_unset ("timeout"); } /* Execute ENTRY from the menu MENU, falling back to entries specified in the environment variable "fallback" if it fails. CALLBACK is a pointer to a struct of function pointers which are used to allow the caller provide feedback to the user. */ -void +static void grub_menu_execute_with_fallback (grub_menu_t menu, grub_menu_entry_t entry, + int autobooted, grub_menu_execute_callback_t callback, void *callback_data) { @@ -217,7 +288,7 @@ grub_menu_execute_with_fallback (grub_menu_t menu, callback->notify_booting (entry, callback_data); - grub_menu_execute_entry (entry); + grub_menu_execute_entry (entry, 1); /* Deal with fallback entries. */ while ((fallback_entry = get_and_remove_first_entry_number ("fallback")) @@ -228,14 +299,15 @@ grub_menu_execute_with_fallback (grub_menu_t menu, entry = grub_menu_get_entry (menu, fallback_entry); callback->notify_fallback (entry, callback_data); - grub_menu_execute_entry (entry); + grub_menu_execute_entry (entry, 1); /* If the function call to execute the entry returns at all, then this is taken to indicate a boot failure. For menu entries that do something other than actually boot an operating system, this could assume incorrectly that something failed. */ } - callback->notify_failure (callback_data); + if (!autobooted) + callback->notify_failure (callback_data); } static struct grub_menu_viewer *viewers; @@ -309,11 +381,35 @@ grub_menu_register_viewer (struct grub_menu_viewer *viewer) viewers = viewer; } +static int +menuentry_eq (const char *title, const char *spec) +{ + const char *ptr1, *ptr2; + ptr1 = title; + ptr2 = spec; + while (1) + { + if (*ptr2 == '>' && ptr2[1] != '>' && *ptr1 == 0) + return 1; + if (*ptr2 == '>' && ptr2[1] != '>') + return 0; + if (*ptr2 == '>') + ptr2++; + if (*ptr1 != *ptr2) + return 0; + if (*ptr1 == 0) + return 1; + ptr1++; + ptr2++; + } +} + + /* Get the entry number from the variable NAME. */ static int get_entry_number (grub_menu_t menu, const char *name) { - char *val; + const char *val; int entry; val = grub_env_get (name); @@ -334,7 +430,7 @@ get_entry_number (grub_menu_t menu, const char *name) for (i = 0; e; i++) { - if (grub_strcmp (e->title, val) == 0) + if (menuentry_eq (e->title, val)) { entry = i; break; @@ -590,7 +686,7 @@ static struct grub_menu_execute_callback execution_callback = }; static grub_err_t -show_menu (grub_menu_t menu, int nested) +show_menu (grub_menu_t menu, int nested, int autobooted) { while (1) { @@ -609,22 +705,26 @@ show_menu (grub_menu_t menu, int nested) grub_cls (); if (auto_boot) - grub_menu_execute_with_fallback (menu, e, &execution_callback, 0); + grub_menu_execute_with_fallback (menu, e, autobooted, + &execution_callback, 0); else - grub_menu_execute_entry (e); + grub_menu_execute_entry (e, 0); + if (autobooted) + break; } return GRUB_ERR_NONE; } grub_err_t -grub_show_menu (grub_menu_t menu, int nested) +grub_show_menu (grub_menu_t menu, int nested, int autoboot) { grub_err_t err1, err2; while (1) { - err1 = show_menu (menu, nested); + err1 = show_menu (menu, nested, autoboot); + autoboot = 0; grub_print_error (); if (grub_normal_exit_level) diff --git a/grub-core/normal/menu_entry.c b/grub-core/normal/menu_entry.c index 4db4a45c1..e744d8d69 100644 --- a/grub-core/normal/menu_entry.c +++ b/grub-core/normal/menu_entry.c @@ -1227,7 +1227,7 @@ run (struct screen *screen) { if (menu && menu->size) { - grub_show_menu (menu, 1); + grub_show_menu (menu, 1, 0); grub_normal_free_menu (menu); } grub_env_context_close (); diff --git a/include/grub/menu.h b/include/grub/menu.h index 5ff356beb..1f23a2363 100644 --- a/include/grub/menu.h +++ b/include/grub/menu.h @@ -94,11 +94,6 @@ typedef struct grub_menu_execute_callback grub_menu_entry_t grub_menu_get_entry (grub_menu_t menu, int no); int grub_menu_get_timeout (void); void grub_menu_set_timeout (int timeout); -void grub_menu_execute_entry (grub_menu_entry_t entry); -void grub_menu_execute_with_fallback (grub_menu_t menu, - grub_menu_entry_t entry, - grub_menu_execute_callback_t callback, - void *callback_data); void grub_menu_entry_run (grub_menu_entry_t entry); int grub_menu_get_default_entry_index (grub_menu_t menu); diff --git a/include/grub/normal.h b/include/grub/normal.h index 187567797..3b99e073a 100644 --- a/include/grub/normal.h +++ b/include/grub/normal.h @@ -89,7 +89,7 @@ void grub_print_message_indented (const char *msg, int margin_left, void grub_menu_text_register_instances (int entry, grub_menu_t menu, int nested); grub_err_t -grub_show_menu (grub_menu_t menu, int nested); +grub_show_menu (grub_menu_t menu, int nested, int autobooted); /* Defined in `handler.c'. */ void read_handler_list (void); From a508e7764271aa8abcb4c93a799eec64326806e4 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 10 Jan 2011 23:31:27 +0100 Subject: [PATCH 235/869] * util/grub-kbdcomp.in: Add missing transform and bindir variables. Reported by: nebuchadnezzar. --- ChangeLog | 5 +++++ util/grub-kbdcomp.in | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/ChangeLog b/ChangeLog index 976c2cf5b..eff9002cf 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-01-10 Vladimir Serbinenko + + * util/grub-kbdcomp.in: Add missing transform and bindir variables. + Reported by: nebuchadnezzar. + 2011-01-10 Vladimir Serbinenko Submenu default support. diff --git a/util/grub-kbdcomp.in b/util/grub-kbdcomp.in index 87b24bcdf..b7e706c24 100644 --- a/util/grub-kbdcomp.in +++ b/util/grub-kbdcomp.in @@ -1,5 +1,9 @@ #!/bin/sh +transform="@program_transform_name@" + +bindir="@bindir@" + grub_mklayout=${bindir}/`echo grub-mklayout | sed ${transform}` ckbcomp "$@" | $grub_mklayout -o "$1".gkb From d570097a04f3249274d1d588d51b1fffa8aa6513 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 10 Jan 2011 23:41:58 +0100 Subject: [PATCH 236/869] * util/grub-kbdcomp.in: Add missing prefix and exec_prefix variables. Reported by: nebuchadnezzar. --- ChangeLog | 5 +++++ util/grub-kbdcomp.in | 2 ++ 2 files changed, 7 insertions(+) diff --git a/ChangeLog b/ChangeLog index eff9002cf..5ef4b1c95 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-01-10 Vladimir Serbinenko + + * util/grub-kbdcomp.in: Add missing prefix and exec_prefix variables. + Reported by: nebuchadnezzar. + 2011-01-10 Vladimir Serbinenko * util/grub-kbdcomp.in: Add missing transform and bindir variables. diff --git a/util/grub-kbdcomp.in b/util/grub-kbdcomp.in index b7e706c24..05e516d23 100644 --- a/util/grub-kbdcomp.in +++ b/util/grub-kbdcomp.in @@ -2,6 +2,8 @@ transform="@program_transform_name@" +prefix="@prefix@" +exec_prefix="@exec_prefix@" bindir="@bindir@" grub_mklayout=${bindir}/`echo grub-mklayout | sed ${transform}` From ae67942e7819481499fbc9710781b5eacaf445b3 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 10 Jan 2011 23:51:10 +0100 Subject: [PATCH 237/869] Don't use post-4G memory on EFI even if 64-bit since some non-compliant implementations bug on them. * grub-core/kern/efi/mm.c (grub_efi_allocate_pages): Skip post-4G memory. (filter_memory_map): Likewise. --- ChangeLog | 9 +++++++++ grub-core/kern/efi/mm.c | 8 ++++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5ef4b1c95..0b9b9b6aa 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2011-01-10 Vladimir Serbinenko + + Don't use post-4G memory on EFI even if 64-bit since some non-compliant + implementations bug on them. + + * grub-core/kern/efi/mm.c (grub_efi_allocate_pages): Skip post-4G + memory. + (filter_memory_map): Likewise. + 2011-01-10 Vladimir Serbinenko * util/grub-kbdcomp.in: Add missing prefix and exec_prefix variables. diff --git a/grub-core/kern/efi/mm.c b/grub-core/kern/efi/mm.c index a715da076..8b9e6ec25 100644 --- a/grub-core/kern/efi/mm.c +++ b/grub-core/kern/efi/mm.c @@ -52,13 +52,13 @@ grub_efi_allocate_pages (grub_efi_physical_address_t address, grub_efi_status_t status; grub_efi_boot_services_t *b; -#if GRUB_TARGET_SIZEOF_VOID_P < 8 +#if 1 /* Limit the memory access to less than 4GB for 32-bit platforms. */ if (address > 0xffffffff) return 0; #endif -#if GRUB_TARGET_SIZEOF_VOID_P < 8 || defined (MCMODEL_SMALL) +#if 1 if (address == 0) { type = GRUB_EFI_ALLOCATE_MAX_ADDRESS; @@ -251,7 +251,7 @@ filter_memory_map (grub_efi_memory_descriptor_t *memory_map, desc = NEXT_MEMORY_DESCRIPTOR (desc, desc_size)) { if (desc->type == GRUB_EFI_CONVENTIONAL_MEMORY -#if GRUB_TARGET_SIZEOF_VOID_P < 8 || defined (MCMODEL_SMALL) +#if 1 && desc->physical_start <= 0xffffffff #endif && desc->physical_start + PAGES_TO_BYTES (desc->num_pages) > 0x100000 @@ -267,7 +267,7 @@ filter_memory_map (grub_efi_memory_descriptor_t *memory_map, desc->physical_start = 0x100000; } -#if GRUB_TARGET_SIZEOF_VOID_P < 8 || defined (MCMODEL_SMALL) +#if 1 if (BYTES_TO_PAGES (filtered_desc->physical_start) + filtered_desc->num_pages > BYTES_TO_PAGES (0x100000000LL)) From b3ff6ff0565a4f774763eb71f70979b126029dce Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 10 Jan 2011 23:56:11 +0100 Subject: [PATCH 238/869] * grub-core/fs/zfs/zfsinfo.c (grub_cmd_zfs_bootfs): Use comma as separator and pass bootpath/devid even if only one of them is available. Reported by: Seth Goldberg. --- ChangeLog | 6 ++++++ grub-core/fs/zfs/zfsinfo.c | 23 ++++++++--------------- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/ChangeLog b/ChangeLog index 0b9b9b6aa..4433ffa5e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2011-01-10 Vladimir Serbinenko + + * grub-core/fs/zfs/zfsinfo.c (grub_cmd_zfs_bootfs): Use comma as + separator and pass bootpath/devid even if only one of them is available. + Reported by: Seth Goldberg. + 2011-01-10 Vladimir Serbinenko Don't use post-4G memory on EFI even if 64-bit since some non-compliant diff --git a/grub-core/fs/zfs/zfsinfo.c b/grub-core/fs/zfs/zfsinfo.c index 33065892a..5a7b5ec44 100644 --- a/grub-core/fs/zfs/zfsinfo.c +++ b/grub-core/fs/zfs/zfsinfo.c @@ -364,21 +364,14 @@ grub_cmd_zfs_bootfs (grub_command_t cmd __attribute__ ((unused)), int argc, grub_free (nv); grub_free (nvlist); - if (bootpath && devid) - { - bootfs = grub_xasprintf ("zfs-bootfs=%s/%llu bootpath=%s diskdevid=%s", - poolname, (unsigned long long) mdnobj, - bootpath, devid); - if (!bootfs) - return grub_errno; - } - else - { - bootfs = grub_xasprintf ("zfs-bootfs=%s/%llu", - poolname, (unsigned long long) mdnobj); - if (!bootfs) - return grub_errno; - } + bootfs = grub_xasprintf ("zfs-bootfs=%s/%llu%s%s%s%s", + poolname, (unsigned long long) mdnobj, + bootpath ? ",bootpath=" : "", + bootpath ? : "", + devid ? ",diskdevid=" : "", + devid ? : ""); + if (!bootfs) + return grub_errno; if (argc >= 2) grub_env_set (args[1], bootfs); else From c2fa6cbb42dd3e2a17e7074a2eec421c31f4b4fa Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 10 Jan 2011 23:57:49 +0100 Subject: [PATCH 239/869] * util/grub-menulst2cfg.c: Add missing include of misc.h. --- ChangeLog | 4 ++++ util/grub-menulst2cfg.c | 1 + 2 files changed, 5 insertions(+) diff --git a/ChangeLog b/ChangeLog index 4433ffa5e..63a0ee46c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2011-01-10 Vladimir Serbinenko + + * util/grub-menulst2cfg.c: Add missing include of misc.h. + 2011-01-10 Vladimir Serbinenko * grub-core/fs/zfs/zfsinfo.c (grub_cmd_zfs_bootfs): Use comma as diff --git a/util/grub-menulst2cfg.c b/util/grub-menulst2cfg.c index da1c289a8..513af47c1 100644 --- a/util/grub-menulst2cfg.c +++ b/util/grub-menulst2cfg.c @@ -23,6 +23,7 @@ #include #include #include +#include int main (int argc, char **argv) From 3395fe5230ef31f838692b88dc0c7ebc62599151 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Tue, 11 Jan 2011 00:02:01 +0100 Subject: [PATCH 240/869] Pass more appropriate video id to Linux. * grub-core/loader/i386/linux.c (grub_linux_setup_video): Use grub_video_get_driver_id and variable gfxpayloadforcelfb to fill have_vga. (grub_linux_boot): Rely on grub_linux_setup_video to fill have_vga and shift params->lfb_size. * include/grub/i386/linux.h: Make an enume out of have_vga values. --- BUGS | 2 ++ ChangeLog | 11 ++++++++ grub-core/loader/i386/linux.c | 51 +++++++++++++++++++++++++---------- include/grub/i386/linux.h | 10 ++++--- 4 files changed, 57 insertions(+), 17 deletions(-) create mode 100644 BUGS diff --git a/BUGS b/BUGS new file mode 100644 index 000000000..0faebcdcc --- /dev/null +++ b/BUGS @@ -0,0 +1,2 @@ +Currently search and assembling multidevice abstractions scans all the devices which can be slow. +Cache isn't used correctly for video which results in slowness. diff --git a/ChangeLog b/ChangeLog index 63a0ee46c..1a6a71bc5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2011-01-10 Vladimir Serbinenko + + Pass more appropriate video id to Linux. + + * grub-core/loader/i386/linux.c (grub_linux_setup_video): Use + grub_video_get_driver_id and variable gfxpayloadforcelfb to + fill have_vga. + (grub_linux_boot): Rely on grub_linux_setup_video to fill have_vga and + shift params->lfb_size. + * include/grub/i386/linux.h: Make an enume out of have_vga values. + 2011-01-10 Vladimir Serbinenko * util/grub-menulst2cfg.c: Add missing include of misc.h. diff --git a/grub-core/loader/i386/linux.c b/grub-core/loader/i386/linux.c index 80f583cef..80960570b 100644 --- a/grub-core/loader/i386/linux.c +++ b/grub-core/loader/i386/linux.c @@ -313,6 +313,13 @@ grub_linux_setup_video (struct linux_kernel_params *params) struct grub_video_mode_info mode_info; void *framebuffer; grub_err_t err; + grub_video_driver_id_t driver_id; + char *gfxlfbvar = grub_env_get ("gfxpayloadforcelfb"); + + driver_id = grub_video_get_driver_id (); + + if (driver_id == GRUB_VIDEO_DRIVER_NONE) + return 1; err = grub_video_get_info_and_fini (&mode_info, &framebuffer); @@ -339,12 +346,40 @@ grub_linux_setup_video (struct linux_kernel_params *params) params->reserved_mask_size = mode_info.reserved_mask_size; params->reserved_field_pos = mode_info.reserved_field_pos; + if (gfxlfbvar && (gfxlfbvar[0] == '1' || gfxlfbvar[0] == 'y')) + params->have_vga = GRUB_VIDEO_LINUX_TYPE_SIMPLE; + else + { + switch (driver_id) + { + case GRUB_VIDEO_DRIVER_VBE: + params->lfb_size >>= 16; + params->have_vga = GRUB_VIDEO_LINUX_TYPE_VESA; + break; + + case GRUB_VIDEO_DRIVER_EFI_UGA: + case GRUB_VIDEO_DRIVER_EFI_GOP: + params->have_vga = GRUB_VIDEO_LINUX_TYPE_EFIFB; + break; + + /* FIXME: check if better id is available. */ + case GRUB_VIDEO_DRIVER_SM712: + case GRUB_VIDEO_DRIVER_VGA: + case GRUB_VIDEO_DRIVER_CIRRUS: + case GRUB_VIDEO_DRIVER_BOCHS: + /* Make gcc happy. */ + case GRUB_VIDEO_DRIVER_SDL: + case GRUB_VIDEO_DRIVER_NONE: + params->have_vga = GRUB_VIDEO_LINUX_TYPE_SIMPLE; + break; + } + } #ifdef GRUB_MACHINE_PCBIOS /* VESA packed modes may come with zeroed mask sizes, which need to be set here according to DAC Palette width. If we don't, this results in Linux displaying a black screen. */ - if (mode_info.bpp <= 8) + if (driver_id == GRUB_VIDEO_DRIVER_VBE && mode_info.bpp <= 8) { struct grub_vbe_info_block controller_info; int status; @@ -457,15 +492,7 @@ grub_linux_boot (void) grub_errno = GRUB_ERR_NONE; } - if (! grub_linux_setup_video (params)) - { - /* Use generic framebuffer unless VESA is known to be supported. */ - if (params->have_vga != GRUB_VIDEO_LINUX_TYPE_VESA) - params->have_vga = GRUB_VIDEO_LINUX_TYPE_SIMPLE; - else - params->lfb_size >>= 16; - } - else + if (grub_linux_setup_video (params)) { #if defined (GRUB_MACHINE_PCBIOS) || defined (GRUB_MACHINE_COREBOOT) || defined (GRUB_MACHINE_QEMU) params->have_vga = GRUB_VIDEO_LINUX_TYPE_TEXT; @@ -771,10 +798,6 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), break; } - /* We can't detect VESA, but user is implicitly telling us that it - is built-in because `vga=' parameter was used. */ - params->have_vga = GRUB_VIDEO_LINUX_TYPE_VESA; - linux_mode = &grub_vesa_mode_table[vid_mode - GRUB_VESA_MODE_TABLE_START]; diff --git a/include/grub/i386/linux.h b/include/grub/i386/linux.h index 9ba83eee2..fed58a630 100644 --- a/include/grub/i386/linux.h +++ b/include/grub/i386/linux.h @@ -79,9 +79,13 @@ struct grub_e820_mmap grub_uint32_t type; } __attribute__((packed)); -#define GRUB_VIDEO_LINUX_TYPE_TEXT 0x01 -#define GRUB_VIDEO_LINUX_TYPE_VESA 0x23 /* VESA VGA in graphic mode. */ -#define GRUB_VIDEO_LINUX_TYPE_SIMPLE 0x70 /* Linear framebuffer without any additional functions. */ +enum + { + GRUB_VIDEO_LINUX_TYPE_TEXT = 0x01, + GRUB_VIDEO_LINUX_TYPE_VESA = 0x23, /* VESA VGA in graphic mode. */ + GRUB_VIDEO_LINUX_TYPE_EFIFB = 0x70, /* EFI Framebuffer. */ + GRUB_VIDEO_LINUX_TYPE_SIMPLE = 0x70 /* Linear framebuffer without any additional functions. */ + }; /* For the Linux/i386 boot protocol version 2.03. */ struct linux_kernel_header From f093110b52d6d2b3b97fd1c07388f441863e0f5f Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Tue, 11 Jan 2011 00:06:01 +0100 Subject: [PATCH 241/869] * BUGS: New file. --- BUGS | 9 +++++++-- ChangeLog | 4 ++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/BUGS b/BUGS index 0faebcdcc..46faa6452 100644 --- a/BUGS +++ b/BUGS @@ -1,2 +1,7 @@ -Currently search and assembling multidevice abstractions scans all the devices which can be slow. -Cache isn't used correctly for video which results in slowness. +GRUB team is aware of following problems: + - Currently search and assembling multidevice abstractions scans + all the devices which can be slow. + - Cache isn't used correctly for video which results in slowness. + +While these are bugs their solution has a potential of breaking more and more +seriously. So it was decided for 1.99 that they aren't fixed. diff --git a/ChangeLog b/ChangeLog index 1a6a71bc5..894f886b4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2011-01-11 Vladimir Serbinenko + + * BUGS: New file. + 2011-01-10 Vladimir Serbinenko Pass more appropriate video id to Linux. From 45146057263bc0d47cefe2f46ee6157f92fd3af4 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Tue, 11 Jan 2011 00:44:56 +0100 Subject: [PATCH 242/869] =?UTF-8?q?=09*=20grub-core/loader/i386/multiboot?= =?UTF-8?q?=5Fmbi.c=20(grub=5Fmultiboot=5Fmake=5Fmbi):=20=09Take=20into=20?= =?UTF-8?q?account=20space=20used=20by=20ELF=20sections=20and=20multiboot?= =?UTF-8?q?=20palette.=20=09Reported=20by:=20Gr=C3=A9goire=20Sutre.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ChangeLog | 6 ++++++ grub-core/loader/i386/multiboot_mbi.c | 13 +++++++++++++ 2 files changed, 19 insertions(+) diff --git a/ChangeLog b/ChangeLog index 894f886b4..73571a549 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2011-01-11 Vladimir Serbinenko + + * grub-core/loader/i386/multiboot_mbi.c (grub_multiboot_make_mbi): + Take into account space used by ELF sections and multiboot palette. + Reported by: GrĂ©goire Sutre. + 2011-01-11 Vladimir Serbinenko * BUGS: New file. diff --git a/grub-core/loader/i386/multiboot_mbi.c b/grub-core/loader/i386/multiboot_mbi.c index eade78e93..b98bda223 100644 --- a/grub-core/loader/i386/multiboot_mbi.c +++ b/grub-core/loader/i386/multiboot_mbi.c @@ -539,6 +539,9 @@ grub_multiboot_make_mbi (grub_uint32_t *target) mbi->u.elf_sec.shndx = elf_sec_shstrndx; mbi->flags |= MULTIBOOT_INFO_ELF_SHDR; + + ptrorig += elf_sec_entsize * elf_sec_num; + ptrdest += elf_sec_entsize * elf_sec_num; } err = retrieve_video_parameters (mbi, ptrorig, ptrdest); @@ -547,6 +550,16 @@ grub_multiboot_make_mbi (grub_uint32_t *target) grub_print_error (); grub_errno = GRUB_ERR_NONE; } + + if ((mbi->flags & MULTIBOOT_INFO_FRAMEBUFFER_INFO) + && mbi->framebuffer_type == MULTIBOOT_FRAMEBUFFER_TYPE_INDEXED) + { + ptrorig += mbi->framebuffer_palette_num_colors + * sizeof (struct multiboot_color); + ptrdest += mbi->framebuffer_palette_num_colors + * sizeof (struct multiboot_color); + } + #if GRUB_MACHINE_HAS_VBE ptrorig += sizeof (struct grub_vbe_info_block); ptrdest += sizeof (struct grub_vbe_info_block); From 4531a206a1c112d405ef9ea00f2e06037ef0c01a Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Tue, 11 Jan 2011 11:51:05 +0100 Subject: [PATCH 243/869] * grub-core/fs/i386/pc/pxe.c (set_mac_env): Export variable. (set_env_limn_ro): Likewise. (GRUB_MOD_INIT): Likewise. * grub-core/hook/datehook.c (GRUB_MOD_INIT): Likewise. Change to ARRAY_SIZE while on it. (GRUB_MOD_FINI): Change to ARRAY_SIZE. * grub-core/normal/context.c (grub_env_export): Move from here ... * grub-core/kern/env.c (grub_env_export): ... here. * grub-core/normal/context.c (grub_cmd_export): Skip exporting root and prefix. * grub-core/kern/main.c (grub_main): Export root and prefix. * include/grub/env.h (grub_env_export): Export. Reported by: Seth Goldberg. --- ChangeLog | 16 ++++++++++++++++ grub-core/fs/i386/pc/pxe.c | 9 +++++++++ grub-core/hook/datehook.c | 15 +++++++++------ grub-core/kern/env.c | 20 ++++++++++++++++++++ grub-core/kern/main.c | 2 ++ grub-core/normal/context.c | 23 ----------------------- include/grub/env.h | 2 +- 7 files changed, 57 insertions(+), 30 deletions(-) diff --git a/ChangeLog b/ChangeLog index 73571a549..a4f7122fb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,19 @@ +2011-01-11 Vladimir Serbinenko + + * grub-core/fs/i386/pc/pxe.c (set_mac_env): Export variable. + (set_env_limn_ro): Likewise. + (GRUB_MOD_INIT): Likewise. + * grub-core/hook/datehook.c (GRUB_MOD_INIT): Likewise. Change to + ARRAY_SIZE while on it. + (GRUB_MOD_FINI): Change to ARRAY_SIZE. + * grub-core/normal/context.c (grub_env_export): Move from here ... + * grub-core/kern/env.c (grub_env_export): ... here. + * grub-core/normal/context.c (grub_cmd_export): Skip exporting root and + prefix. + * grub-core/kern/main.c (grub_main): Export root and prefix. + * include/grub/env.h (grub_env_export): Export. + Reported by: Seth Goldberg. + 2011-01-11 Vladimir Serbinenko * grub-core/loader/i386/multiboot_mbi.c (grub_multiboot_make_mbi): diff --git a/grub-core/fs/i386/pc/pxe.c b/grub-core/fs/i386/pc/pxe.c index cbb3c7d87..e2b53d637 100644 --- a/grub-core/fs/i386/pc/pxe.c +++ b/grub-core/fs/i386/pc/pxe.c @@ -420,6 +420,7 @@ set_mac_env (grub_uint8_t *mac_addr, grub_size_t mac_len) grub_env_set ("net_pxe_mac", buf); /* XXX: Is it possible to change MAC in PXE? */ grub_register_variable_hook ("net_pxe_mac", 0, grub_env_write_readonly); + grub_env_export ("net_pxe_mac"); } static void @@ -431,6 +432,7 @@ set_env_limn_ro (const char *varname, char *value, grub_size_t len) grub_env_set (varname, value); value[len] = c; grub_register_variable_hook (varname, 0, grub_env_write_readonly); + grub_env_export (varname); } static void @@ -624,12 +626,19 @@ GRUB_MOD_INIT(pxe) grub_env_write_pxe_default_server); grub_register_variable_hook ("pxe_default_gateway", 0, grub_env_write_pxe_default_gateway); + /* XXX: Is it possible to change IP in PXE? */ grub_register_variable_hook ("net_pxe_ip", 0, grub_env_write_readonly); grub_register_variable_hook ("pxe_blksize", 0, grub_env_write_pxe_blocksize); + + grub_env_export ("pxe_default_server"); + grub_env_export ("pxe_default_gateway"); + grub_env_export ("net_pxe_ip"); + grub_env_export ("pxe_blksize"); + grub_disk_dev_register (&grub_pxe_dev); grub_fs_register (&grub_pxefs_fs); } diff --git a/grub-core/hook/datehook.c b/grub-core/hook/datehook.c index 9b5b54bf3..d855311d3 100644 --- a/grub-core/hook/datehook.c +++ b/grub-core/hook/datehook.c @@ -86,18 +86,21 @@ grub_read_hook_datetime (struct grub_env_var *var, GRUB_MOD_INIT(datehook) { - int i; + unsigned i; - for (i = 0; i < 7; i++) - grub_register_variable_hook (grub_datetime_names[i], - grub_read_hook_datetime, 0); + for (i = 0; i < ARRAY_SIZE (grub_datetime_names); i++) + { + grub_register_variable_hook (grub_datetime_names[i], + grub_read_hook_datetime, 0); + grub_env_export (grub_datetime_names[i]); + } } GRUB_MOD_FINI(datehook) { - int i; + unsigned i; - for (i = 0; i < 7; i++) + for (i = 0; i < ARRAY_SIZE (grub_datetime_names); i++) { grub_register_variable_hook (grub_datetime_names[i], 0, 0); grub_env_unset (grub_datetime_names[i]); diff --git a/grub-core/kern/env.c b/grub-core/kern/env.c index 84b3a001d..8f843a872 100644 --- a/grub-core/kern/env.c +++ b/grub-core/kern/env.c @@ -240,3 +240,23 @@ grub_register_variable_hook (const char *name, return GRUB_ERR_NONE; } + +grub_err_t +grub_env_export (const char *name) +{ + struct grub_env_var *var; + + var = grub_env_find (name); + if (! var) + { + grub_err_t err; + + err = grub_env_set (name, ""); + if (err) + return err; + var = grub_env_find (name); + } + var->global = 1; + + return GRUB_ERR_NONE; +} diff --git a/grub-core/kern/main.c b/grub-core/kern/main.c index 8b6c8a180..da7123234 100644 --- a/grub-core/kern/main.c +++ b/grub-core/kern/main.c @@ -189,6 +189,8 @@ grub_main (void) for convenience. */ grub_machine_set_prefix (); grub_set_root_dev (); + grub_env_export ("root"); + grub_env_export ("prefix"); grub_register_core_commands (); diff --git a/grub-core/normal/context.c b/grub-core/normal/context.c index 75beeefda..b73161d0b 100644 --- a/grub-core/normal/context.c +++ b/grub-core/normal/context.c @@ -175,26 +175,6 @@ grub_env_extractor_close (int source) return err; } -grub_err_t -grub_env_export (const char *name) -{ - struct grub_env_var *var; - - var = grub_env_find (name); - if (! var) - { - grub_err_t err; - - err = grub_env_set (name, ""); - if (err) - return err; - var = grub_env_find (name); - } - var->global = 1; - - return GRUB_ERR_NONE; -} - static grub_command_t export_cmd; static grub_err_t @@ -216,9 +196,6 @@ grub_cmd_export (struct grub_command *cmd __attribute__ ((unused)), void grub_context_init (void) { - grub_env_export ("root"); - grub_env_export ("prefix"); - export_cmd = grub_register_command ("export", grub_cmd_export, N_("ENVVAR [ENVVAR] ..."), N_("Export variables.")); diff --git a/include/grub/env.h b/include/grub/env.h index 6d1f0de6e..c0107f16a 100644 --- a/include/grub/env.h +++ b/include/grub/env.h @@ -53,7 +53,7 @@ grub_err_t EXPORT_FUNC(grub_register_variable_hook) (const char *name, grub_err_t grub_env_context_open (void); grub_err_t grub_env_context_close (void); -grub_err_t grub_env_export (const char *name); +grub_err_t EXPORT_FUNC(grub_env_export) (const char *name); void grub_env_unset_menu (void); grub_menu_t grub_env_get_menu (void); From 86205c94c3f85579f56b005896c4ad3cf0c69d00 Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Tue, 11 Jan 2011 09:08:57 -0600 Subject: [PATCH 244/869] * util/grub-mklayout.c (console_grub_equivalences_shift): Terminate with NULL. (console_grub_equivalences_unshift): Likewise. Reported by: Daniel Dehennin. --- ChangeLog | 7 +++++++ util/grub-mklayout.c | 4 ++++ 2 files changed, 11 insertions(+) diff --git a/ChangeLog b/ChangeLog index a4f7122fb..56a8db213 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2011-01-11 Colin Watson + + * util/grub-mklayout.c (console_grub_equivalences_shift): Terminate + with NULL. + (console_grub_equivalences_unshift): Likewise. + Reported by: Daniel Dehennin. + 2011-01-11 Vladimir Serbinenko * grub-core/fs/i386/pc/pxe.c (set_mac_env): Export variable. diff --git a/util/grub-mklayout.c b/util/grub-mklayout.c index 36f6e04fc..04501cb40 100644 --- a/util/grub-mklayout.c +++ b/util/grub-mklayout.c @@ -60,6 +60,8 @@ static struct console_grub_equivalence console_grub_equivalences_shift[] = { {"KP_8", '8'}, {"KP_9", '9'}, {"KP_Period", '.'}, + + {NULL, '\0'} }; static struct console_grub_equivalence console_grub_equivalences_unshift[] = { @@ -74,6 +76,8 @@ static struct console_grub_equivalence console_grub_equivalences_unshift[] = { {"KP_8", GRUB_TERM_KEY_UP}, {"KP_9", GRUB_TERM_KEY_PPAGE}, {"KP_Period", GRUB_TERM_KEY_DC}, + + {NULL, '\0'} }; static struct console_grub_equivalence console_grub_equivalences_common[] = { From 9da068a5dc3b507276552980fc9c6459aef0a02d Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Tue, 11 Jan 2011 23:01:07 +0100 Subject: [PATCH 245/869] * grub-core/loader/powerpc/ieee1275/linux.c (grub_linux_load32): Apply loadmask before doing any calculations. Use correct type for offset. (grub_linux_load64): Likewise. --- ChangeLog | 6 ++++++ grub-core/loader/powerpc/ieee1275/linux.c | 16 +++++++++++----- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 56a8db213..05e2ec8c7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2011-01-11 Vladimir Serbinenko + + * grub-core/loader/powerpc/ieee1275/linux.c (grub_linux_load32): Apply + loadmask before doing any calculations. Use correct type for offset. + (grub_linux_load64): Likewise. + 2011-01-11 Colin Watson * util/grub-mklayout.c (console_grub_equivalences_shift): Terminate diff --git a/grub-core/loader/powerpc/ieee1275/linux.c b/grub-core/loader/powerpc/ieee1275/linux.c index a99310cfd..0cf0eb825 100644 --- a/grub-core/loader/powerpc/ieee1275/linux.c +++ b/grub-core/loader/powerpc/ieee1275/linux.c @@ -152,7 +152,8 @@ grub_linux_load32 (grub_elf_t elf) Elf32_Addr base_addr; grub_addr_t seg_addr; grub_uint32_t align; - int offset; + grub_uint32_t offset; + Elf32_Addr entry; linux_size = grub_elf32_size (elf, &base_addr, &align); if (linux_size == 0) @@ -160,9 +161,12 @@ grub_linux_load32 (grub_elf_t elf) /* Pad it; the kernel scribbles over memory beyond its load address. */ linux_size += 0x100000; - offset = elf->ehdr.ehdr32.e_entry - base_addr; + /* Linux's entry point incorrectly contains a virtual address. */ + entry = elf->ehdr.ehdr32.e_entry & ~ELF32_LOADMASK; + /* Linux's incorrectly contains a virtual address. */ base_addr &= ~ELF32_LOADMASK; + offset = entry - base_addr; /* On some systems, firmware occupies the memory we're trying to use. * Happily, Linux can be loaded anywhere (it relocates itself). Iterate @@ -196,7 +200,8 @@ grub_linux_load64 (grub_elf_t elf) Elf64_Addr base_addr; grub_addr_t seg_addr; grub_uint64_t align; - int offset; + grub_uint64_t offset; + Elf64_Addr entry; linux_size = grub_elf64_size (elf, &base_addr, &align); if (linux_size == 0) @@ -204,9 +209,10 @@ grub_linux_load64 (grub_elf_t elf) /* Pad it; the kernel scribbles over memory beyond its load address. */ linux_size += 0x100000; - offset = elf->ehdr.ehdr64.e_entry - base_addr; - /* Linux's incorrectly contains a virtual address. */ base_addr &= ~ELF64_LOADMASK; + entry = elf->ehdr.ehdr64.e_entry & ~ELF64_LOADMASK; + offset = entry - base_addr; + /* Linux's incorrectly contains a virtual address. */ /* On some systems, firmware occupies the memory we're trying to use. * Happily, Linux can be loaded anywhere (it relocates itself). Iterate From 51fa856c58720eeb6b018a2181716a5458e5fbae Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Tue, 11 Jan 2011 17:49:27 -0600 Subject: [PATCH 246/869] * configure.ac: Fall back to `true' if `makeinfo' does not exist. --- ChangeLog | 4 ++++ configure.ac | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 05e2ec8c7..e14a33968 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2011-01-11 Colin Watson + + * configure.ac: Fall back to `true' if `makeinfo' does not exist. + 2011-01-11 Vladimir Serbinenko * grub-core/loader/powerpc/ieee1275/linux.c (grub_linux_load32): Apply diff --git a/configure.ac b/configure.ac index a9ca130b4..055c65e67 100644 --- a/configure.ac +++ b/configure.ac @@ -246,7 +246,7 @@ else fi # These are not a "must". -AC_PATH_PROG(MAKEINFO, makeinfo) +AC_PATH_PROGS(MAKEINFO, makeinfo true) # # Checks for host programs. From b44a558c9a133f398364bc953ba540e1909c1f31 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 12 Jan 2011 11:26:28 +0100 Subject: [PATCH 247/869] Use alias->path rather than buggy "canon". * grub-core/disk/ieee1275/ofdisk.c (ofdisk_hash_add_real): New function. (ofdisk_hash_add): New argument curcan. All users updated. --- ChangeLog | 7 +++++++ grub-core/disk/ieee1275/ofdisk.c | 34 ++++++++++++++++++++++---------- 2 files changed, 31 insertions(+), 10 deletions(-) diff --git a/ChangeLog b/ChangeLog index e14a33968..958850421 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2011-01-12 Vladimir Serbinenko + + Use alias->path rather than buggy "canon". + + * grub-core/disk/ieee1275/ofdisk.c (ofdisk_hash_add_real): New function. + (ofdisk_hash_add): New argument curcan. All users updated. + 2011-01-11 Colin Watson * configure.ac: Fall back to `true' if `makeinfo' does not exist. diff --git a/grub-core/disk/ieee1275/ofdisk.c b/grub-core/disk/ieee1275/ofdisk.c index 85c34609e..0a935d5c2 100644 --- a/grub-core/disk/ieee1275/ofdisk.c +++ b/grub-core/disk/ieee1275/ofdisk.c @@ -62,11 +62,10 @@ ofdisk_hash_find (const char *devpath) } static struct ofdisk_hash_ent * -ofdisk_hash_add (char *devpath) +ofdisk_hash_add_real (char *devpath) { + struct ofdisk_hash_ent *p; struct ofdisk_hash_ent **head = &ofdisk_hash[ofdisk_hash_fn(devpath)]; - struct ofdisk_hash_ent *p, *pcan; - char *curcan; p = grub_malloc(sizeof (*p)); if (!p) @@ -76,17 +75,27 @@ ofdisk_hash_add (char *devpath) p->next = *head; p->shortest = 0; *head = p; + return p; +} + +static struct ofdisk_hash_ent * +ofdisk_hash_add (char *devpath, char *curcan) +{ + struct ofdisk_hash_ent *p, *pcan; + + p = ofdisk_hash_add_real (devpath); + + grub_dprintf ("disk", "devpath = %s, canonical = %s\n", devpath, curcan); - curcan = grub_ieee1275_canonicalise_devname (devpath); if (!curcan) { - grub_errno = GRUB_ERR_NONE; + p->shortest = devpath; return p; } pcan = ofdisk_hash_find (curcan); if (!pcan) - pcan = ofdisk_hash_add (curcan); + pcan = ofdisk_hash_add_real (curcan); else grub_free (curcan); @@ -118,17 +127,22 @@ scan (void) return 0; grub_dprintf ("disk", "disk name = %s\n", alias->name); + grub_dprintf ("disk", "disk name = %s, path = %s\n", alias->name, + alias->path); - op = ofdisk_hash_find (alias->path); + op = ofdisk_hash_find (alias->name); if (!op) { char *name = grub_strdup (alias->name); - if (!name) + char *can = grub_strdup (alias->path); + if (!name || !can) { grub_errno = GRUB_ERR_NONE; + grub_free (name); + grub_free (can); return 0; } - op = ofdisk_hash_add (name); + op = ofdisk_hash_add (name, can); } return 0; } @@ -247,7 +261,7 @@ grub_ofdisk_open (const char *name, grub_disk_t disk) struct ofdisk_hash_ent *op; op = ofdisk_hash_find (devpath); if (!op) - op = ofdisk_hash_add (devpath); + op = ofdisk_hash_add (devpath, NULL); else grub_free (devpath); if (!op) From b8494fbe5c6b816dc7386eb7dc60a3922b86fdb7 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 12 Jan 2011 11:52:51 +0100 Subject: [PATCH 248/869] * grub-core/normal/context.c (grub_env_context_close): Silence spurious warning. * grub-core/normal/menu.c (grub_menu_execute_entry): Likewise. * grub-core/partmap/msdos.c (pc_partition_map_embed): Use unsigned counter. --- ChangeLog | 8 ++++++++ grub-core/normal/context.c | 3 ++- grub-core/normal/menu.c | 2 +- grub-core/partmap/msdos.c | 2 +- 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 958850421..6efb466bb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2011-01-12 Vladimir Serbinenko + + * grub-core/normal/context.c (grub_env_context_close): Silence spurious + warning. + * grub-core/normal/menu.c (grub_menu_execute_entry): Likewise. + * grub-core/partmap/msdos.c (pc_partition_map_embed): Use unsigned + counter. + 2011-01-12 Vladimir Serbinenko Use alias->path rather than buggy "canon". diff --git a/grub-core/normal/context.c b/grub-core/normal/context.c index b73161d0b..108679913 100644 --- a/grub-core/normal/context.c +++ b/grub-core/normal/context.c @@ -148,7 +148,7 @@ grub_env_context_close (void) grub_err_t grub_env_extractor_close (int source) { - grub_menu_t menu, menu2; + grub_menu_t menu = NULL; grub_menu_entry_t *last; grub_err_t err; @@ -161,6 +161,7 @@ grub_env_extractor_close (int source) if (source) { + grub_menu_t menu2; menu2 = grub_env_get_menu (); last = &menu2->entry_list; diff --git a/grub-core/normal/menu.c b/grub-core/normal/menu.c index 6a123a6de..e62482122 100644 --- a/grub-core/normal/menu.c +++ b/grub-core/normal/menu.c @@ -159,7 +159,7 @@ grub_menu_execute_entry(grub_menu_entry_t entry, int auto_boot) { grub_err_t err = GRUB_ERR_NONE; int errs_before; - grub_menu_t menu; + grub_menu_t menu = NULL; char *optr, *buf, *oldchosen = NULL, *olddefault = NULL; const char *ptr, *chosen, *def; grub_size_t sz = 0; diff --git a/grub-core/partmap/msdos.c b/grub-core/partmap/msdos.c index f99e27a6e..d411c4405 100644 --- a/grub-core/partmap/msdos.c +++ b/grub-core/partmap/msdos.c @@ -234,7 +234,7 @@ pc_partition_map_embed (struct grub_disk *disk, unsigned int *nsectors, if (end >= *nsectors + 1) { - int i; + unsigned i; *nsectors = end - 1; *sectors = grub_malloc (*nsectors * sizeof (**sectors)); if (!*sectors) From 8fc0a24576669f28e98f9ccc1b40b8e742f95aad Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 12 Jan 2011 11:55:52 +0100 Subject: [PATCH 249/869] * grub-core/Makefile.core.def (ieee1275_fb): Disable on sparc. It doesn't work well there. --- ChangeLog | 5 +++++ grub-core/Makefile.core.def | 1 - 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 6efb466bb..915fd2619 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-01-12 Vladimir Serbinenko + + * grub-core/Makefile.core.def (ieee1275_fb): Disable on sparc. + It doesn't work well there. + 2011-01-12 Vladimir Serbinenko * grub-core/normal/context.c (grub_env_context_close): Silence spurious diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def index 094bbc835..2cca4fa95 100644 --- a/grub-core/Makefile.core.def +++ b/grub-core/Makefile.core.def @@ -1463,7 +1463,6 @@ module = { name = ieee1275_fb; ieee1275 = video/ieee1275.c; enable = powerpc; - enable = sparc64; }; module = { From f8f479dbbbd908551f2c691b3b7d35997f3a1a7b Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 12 Jan 2011 12:49:16 +0100 Subject: [PATCH 250/869] * util/grub-mkfont.c (write_font_pf2): Use appropriate type for data variable. Fixes problem on big endian platforms. --- ChangeLog | 5 +++++ util/grub-mkfont.c | 17 ++++++++++------- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index 915fd2619..254fc2c6f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-01-12 Vladimir Serbinenko + + * util/grub-mkfont.c (write_font_pf2): Use appropriate type for data + variable. Fixes problem on big endian platforms. + 2011-01-12 Vladimir Serbinenko * grub-core/Makefile.core.def (ieee1275_fb): Disable on sparc. diff --git a/util/grub-mkfont.c b/util/grub-mkfont.c index 983ac7065..3108d4694 100644 --- a/util/grub-mkfont.c +++ b/util/grub-mkfont.c @@ -859,7 +859,7 @@ void write_font_pf2 (struct grub_font_info *font_info, char *output_file) { FILE *file; - grub_uint32_t leng, data; + grub_uint32_t leng; char style_name[20], *font_name; int offset; struct grub_glyph_info *cur; @@ -959,12 +959,14 @@ write_font_pf2 (struct grub_font_info *font_info, char *output_file) for (cur = font_info->glyphs_sorted; cur < font_info->glyphs_sorted + font_info->num_glyphs; cur++) { - data = grub_cpu_to_be32 (cur->char_code); - grub_util_write_image ((char *) &data, 4, file); - data = 0; - grub_util_write_image ((char *) &data, 1, file); - data = grub_cpu_to_be32 (offset); - grub_util_write_image ((char *) &data, 4, file); + grub_uint32_t data32; + grub_uint8_t data8; + data32 = grub_cpu_to_be32 (cur->char_code); + grub_util_write_image ((char *) &data32, 4, file); + data8 = 0; + grub_util_write_image ((char *) &data8, 1, file); + data32 = grub_cpu_to_be32 (offset); + grub_util_write_image ((char *) &data32, 4, file); offset += 10 + cur->bitmap_size; } @@ -976,6 +978,7 @@ write_font_pf2 (struct grub_font_info *font_info, char *output_file) for (cur = font_info->glyphs_sorted; cur < font_info->glyphs_sorted + font_info->num_glyphs; cur++) { + grub_uint16_t data; data = grub_cpu_to_be16 (cur->width); grub_util_write_image ((char *) &data, 2, file); data = grub_cpu_to_be16 (cur->height); From 173b71e9fea74cb2edfab96418f92bc589a17dc4 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 12 Jan 2011 19:51:19 +0100 Subject: [PATCH 251/869] * util/grub.d/00_header.in (load_video): Handle the case when no video drivers available. Thanks to: Axel Beckert. --- ChangeLog | 6 ++++++ util/grub.d/00_header.in | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/ChangeLog b/ChangeLog index 254fc2c6f..74c6affff 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2011-01-12 Vladimir Serbinenko + + * util/grub.d/00_header.in (load_video): Handle the case when no video + drivers available. + Thanks to: Axel Beckert. + 2011-01-12 Vladimir Serbinenko * util/grub-mkfont.c (write_font_pf2): Use appropriate type for data diff --git a/util/grub.d/00_header.in b/util/grub.d/00_header.in index a596e9c4a..420b3f32c 100644 --- a/util/grub.d/00_header.in +++ b/util/grub.d/00_header.in @@ -84,11 +84,16 @@ if [ -n "${GRUB_VIDEO_BACKEND}" ]; then EOF else # Insert all available backends; GRUB will use the most appropriate. + have_video=0; for backend in $(cat "${GRUB_PREFIX}/video.lst"); do + have_video=1; cat < Date: Wed, 12 Jan 2011 19:58:32 +0100 Subject: [PATCH 252/869] * util/ieee1275/ofpath.c (grub_util_devname_to_ofpath): Use the realpath'ed device string. Handle floppy (somewhat). Issue error in unknown case rather than garbage. Reported by: Axel Beckert. --- ChangeLog | 8 ++++++++ util/ieee1275/ofpath.c | 11 +++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 74c6affff..7a3f3f63a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2011-01-12 Vladimir Serbinenko + + * util/ieee1275/ofpath.c (grub_util_devname_to_ofpath): Use the + realpath'ed device string. + Handle floppy (somewhat). + Issue error in unknown case rather than garbage. + Reported by: Axel Beckert. + 2011-01-12 Vladimir Serbinenko * util/grub.d/00_header.in (load_video): Handle the case when no video diff --git a/util/ieee1275/ofpath.c b/util/ieee1275/ofpath.c index fa0d48cf9..1a433345d 100644 --- a/util/ieee1275/ofpath.c +++ b/util/ieee1275/ofpath.c @@ -377,8 +377,8 @@ grub_util_devname_to_ofpath (const char *devname) if (! name_buf) grub_util_error ("cannot get the real path of `%s'", devname); - device = get_basename (devname); - devnode = strip_trailing_digits (devname); + device = get_basename (name_buf); + devnode = strip_trailing_digits (name_buf); devicenode = strip_trailing_digits (device); ofpath = xmalloc (OF_PATH_MAX); @@ -391,6 +391,13 @@ grub_util_devname_to_ofpath (const char *devname) else if (device[0] == 'v' && device[1] == 'd' && device[2] == 'i' && device[3] == 's' && device[4] == 'k') of_path_of_vdisk(ofpath, name_buf, device, devnode, devicenode); + else if (device[0] == 'f' && device[1] == 'd' + && device[2] == '0' && device[3] == '\0') + /* All the models I've seen have a devalias "floppy". + New models have no floppy at all. */ + strcpy (ofpath, "floppy"); + else + grub_util_error ("unknown device type %s\n", device); free (devnode); free (devicenode); From bd1a4147141708625214564959684257a6614935 Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Wed, 12 Jan 2011 17:27:52 -0600 Subject: [PATCH 253/869] Resolve the device returned by grub_find_root_device_from_mountinfo or find_root_device_from_libzfs using grub_find_device. Reported by: Roderich Schupp. --- grub-core/kern/emu/getroot.c | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/grub-core/kern/emu/getroot.c b/grub-core/kern/emu/getroot.c index df3a4d765..92ff971e5 100644 --- a/grub-core/kern/emu/getroot.c +++ b/grub-core/kern/emu/getroot.c @@ -467,7 +467,7 @@ grub_find_device (const char *path, dev_t dev) char * grub_guess_root_device (const char *dir) { - char *os_dev; + char *os_dev = NULL; #ifdef __GNU__ file_t file; mach_port_t *ports; @@ -526,30 +526,42 @@ grub_guess_root_device (const char *dir) mach_port_deallocate (mach_task_self (), file); #else /* !__GNU__ */ struct stat st; + dev_t dev; #ifdef __linux__ - os_dev = grub_find_root_device_from_mountinfo (dir, NULL); - if (os_dev) - return os_dev; + if (!os_dev) + os_dev = grub_find_root_device_from_mountinfo (dir, NULL); #endif /* __linux__ */ #if defined(HAVE_LIBZFS) && defined(HAVE_LIBNVPAIR) - os_dev = find_root_device_from_libzfs (dir); - if (os_dev) - return os_dev; + if (!os_dev) + os_dev = find_root_device_from_libzfs (dir); #endif - if (stat (dir, &st) < 0) - grub_util_error ("cannot stat `%s'", dir); + if (os_dev) + { + if (stat (os_dev, &st) >= 0) + dev = st.st_rdev; + else + grub_util_error ("cannot stat `%s'", os_dev); + free (os_dev); + } + else + { + if (stat (dir, &st) >= 0) + dev = st.st_dev; + else + grub_util_error ("cannot stat `%s'", dir); + } #ifdef __CYGWIN__ /* Cygwin specific function. */ - os_dev = grub_find_device (dir, st.st_dev); + os_dev = grub_find_device (dir, dev); #else /* This might be truly slow, but is there any better way? */ - os_dev = grub_find_device ("/dev", st.st_dev); + os_dev = grub_find_device ("/dev", dev); #endif #endif /* !__GNU__ */ From f1632d4dd050baee3d2a41730c45ab21f741c62f Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Thu, 13 Jan 2011 22:23:49 +0100 Subject: [PATCH 254/869] Fix compilation on cygwin. * conf/Makefile.common (STRIPFLAGS_KERNEL): Add -F elf32-i386 and -R .drectve on cygwin. * conf/i386-pc-cygwin-img-ld.sc: Merge rdata and pdata into data. * configure.ac: Use $(top_builddir) in TARGET_OBJ2ELF. (COND_CYGWIN): New condition. * grub-core/Makefile.am (%.mod): Set TARGET_OBJ2ELF. * grub-core/genmod.sh.in: Use ${TARGET_OBJ2ELF} and not @TARGET_OBJ2ELF@. * util/grub-pe2elf.c (write_symbol_table): Use pe_symtab->type and not type to determine whether aux is to be used. --- ChangeLog | 15 +++++++++++++++ conf/Makefile.common | 4 ++++ conf/i386-pc-cygwin-img-ld.sc | 6 ------ configure.ac | 3 ++- grub-core/Makefile.am | 2 +- grub-core/genmod.sh.in | 4 ++-- util/grub-pe2elf.c | 2 +- 7 files changed, 25 insertions(+), 11 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7a3f3f63a..696da1215 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +2011-01-13 Vladimir Serbinenko + + Fix compilation on cygwin. + + * conf/Makefile.common (STRIPFLAGS_KERNEL): Add -F elf32-i386 and + -R .drectve on cygwin. + * conf/i386-pc-cygwin-img-ld.sc: Merge rdata and pdata into data. + * configure.ac: Use $(top_builddir) in TARGET_OBJ2ELF. + (COND_CYGWIN): New condition. + * grub-core/Makefile.am (%.mod): Set TARGET_OBJ2ELF. + * grub-core/genmod.sh.in: Use ${TARGET_OBJ2ELF} and + not @TARGET_OBJ2ELF@. + * util/grub-pe2elf.c (write_symbol_table): Use pe_symtab->type and not + type to determine whether aux is to be used. + 2011-01-12 Vladimir Serbinenko * util/ieee1275/ofpath.c (grub_util_devname_to_ofpath): Use the diff --git a/conf/Makefile.common b/conf/Makefile.common index 2df8465c0..32ca76d08 100644 --- a/conf/Makefile.common +++ b/conf/Makefile.common @@ -67,7 +67,11 @@ CFLAGS_KERNEL = $(CFLAGS_CPU) $(CFLAGS_PLATFORM) -ffreestanding LDFLAGS_KERNEL = $(LDFLAGS_CPU) $(LDFLAGS_PLATFORM) -nostdlib -Wl,-N -static-libgcc CPPFLAGS_KERNEL = $(CPPFLAGS_CPU) $(CPPFLAGS_PLATFORM) CCASFLAGS_KERNEL = $(CCASFLAGS_CPU) $(CCASFLAGS_PLATFORM) +if COND_CYGWIN +STRIPFLAGS_KERNEL = -F elf32-i386 -R .rel.dyn -R .reginfo -R .note -R .comment -R .drectve +else STRIPFLAGS_KERNEL = -R .rel.dyn -R .reginfo -R .note -R .comment +endif CFLAGS_MODULE = $(CFLAGS_CPU) $(CFLAGS_PLATFORM) -ffreestanding LDFLAGS_MODULE = $(LDFLAGS_CPU) $(LDFLAGS_PLATFORM) -nostdlib -Wl,-N,-r,-d diff --git a/conf/i386-pc-cygwin-img-ld.sc b/conf/i386-pc-cygwin-img-ld.sc index a41cac75e..3b579d344 100644 --- a/conf/i386-pc-cygwin-img-ld.sc +++ b/conf/i386-pc-cygwin-img-ld.sc @@ -13,15 +13,9 @@ SECTIONS __data_start__ = . ; *(.data) __data_end__ = . ; - } - .rdata : - { __rdata_start__ = . ; *(.rdata) __rdata_end__ = . ; - } - .pdata : - { *(.pdata) edata = . ; } diff --git a/configure.ac b/configure.ac index 055c65e67..0b9207ea2 100644 --- a/configure.ac +++ b/configure.ac @@ -454,7 +454,7 @@ fi # For platforms where ELF is not the default link format. AC_MSG_CHECKING([for command to convert module to ELF format]) case "${host_os}" in - cygwin) TARGET_OBJ2ELF='$(grub_utildir)/grub-pe2elf'; + cygwin) TARGET_OBJ2ELF='$(top_builddir)/grub-pe2elf'; # FIXME: put proper test here NEED_REGISTER_FRAME_INFO=1 ;; @@ -964,6 +964,7 @@ AM_CONDITIONAL([COND_APPLE_CC], [test x$TARGET_APPLE_CC = x1]) AM_CONDITIONAL([COND_ENABLE_EFIEMU], [test x$enable_efiemu = xyes]) AM_CONDITIONAL([COND_HAVE_ASM_USCORE], [test x$HAVE_ASM_USCORE = x1]) +AM_CONDITIONAL([COND_CYGWIN], [test x$host_os = xcygwin]) # Output files. grub_CHECK_LINK_DIR diff --git a/grub-core/Makefile.am b/grub-core/Makefile.am index fcf3fc42d..94f7f3ffe 100644 --- a/grub-core/Makefile.am +++ b/grub-core/Makefile.am @@ -303,7 +303,7 @@ platform_DATA += moddep.lst CLEANFILES += config.log syminfo.lst moddep.lst $(MOD_FILES): %.mod : genmod.sh moddep.lst %.module$(EXEEXT) - sh $^ $@ + TARGET_OBJ2ELF=@TARGET_OBJ2ELF@ sh $^ $@ platform_DATA += $(MOD_FILES) CLEANFILES += $(MOD_FILES) diff --git a/grub-core/genmod.sh.in b/grub-core/genmod.sh.in index b97f3e1c7..023cd1062 100644 --- a/grub-core/genmod.sh.in +++ b/grub-core/genmod.sh.in @@ -52,8 +52,8 @@ fi rm -f $t1 $t2 if test x@TARGET_APPLE_CC@ != x1; then - if ! test -z "@TARGET_OBJ2ELF@"; then - ./@TARGET_OBJ2ELF@ $tmpfile || exit 1 + if ! test -z "${TARGET_OBJ2ELF}"; then + ./${TARGET_OBJ2ELF} $tmpfile || exit 1 fi if test x@platform@ != xemu; then @STRIP@ --strip-unneeded \ diff --git a/util/grub-pe2elf.c b/util/grub-pe2elf.c index f370bbfa8..cf690841f 100644 --- a/util/grub-pe2elf.c +++ b/util/grub-pe2elf.c @@ -337,7 +337,7 @@ write_symbol_table (FILE* fp, char *image, else bind = STB_LOCAL; - if ((type != STT_FUNC) && (pe_symtab->num_aux)) + if ((pe_symtab->type != GRUB_PE32_DT_FUNCTION) && (pe_symtab->num_aux)) { if (! pe_symtab->value) type = STT_SECTION; From 4fbf185232d53acc65599720b6d304acb012e968 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Thu, 13 Jan 2011 22:25:56 +0100 Subject: [PATCH 255/869] * grub-core/fs/zfs/zfsinfo.c (grub_cmd_zfs_bootfs): Quote bootpath and diskdevid. --- ChangeLog | 5 +++++ grub-core/fs/zfs/zfsinfo.c | 12 +++++++----- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 696da1215..b57c6f229 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-01-13 Vladimir Serbinenko + + * grub-core/fs/zfs/zfsinfo.c (grub_cmd_zfs_bootfs): Quote bootpath and + diskdevid. + 2011-01-13 Vladimir Serbinenko Fix compilation on cygwin. diff --git a/grub-core/fs/zfs/zfsinfo.c b/grub-core/fs/zfs/zfsinfo.c index 5a7b5ec44..224a97792 100644 --- a/grub-core/fs/zfs/zfsinfo.c +++ b/grub-core/fs/zfs/zfsinfo.c @@ -364,12 +364,14 @@ grub_cmd_zfs_bootfs (grub_command_t cmd __attribute__ ((unused)), int argc, grub_free (nv); grub_free (nvlist); - bootfs = grub_xasprintf ("zfs-bootfs=%s/%llu%s%s%s%s", + bootfs = grub_xasprintf ("zfs-bootfs=%s/%llu%s%s%s%s%s%s", poolname, (unsigned long long) mdnobj, - bootpath ? ",bootpath=" : "", - bootpath ? : "", - devid ? ",diskdevid=" : "", - devid ? : ""); + bootpath ? ",bootpath=\"" : "", + bootpath ? : "", + bootpath ? "\"" : "", + devid ? ",diskdevid=\"" : "", + devid ? : "", + devid ? "\"" : ""); if (!bootfs) return grub_errno; if (argc >= 2) From f440c33fd2669b06a0c84cbbe1912054d5d39314 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 14 Jan 2011 17:37:11 +0100 Subject: [PATCH 256/869] Make qemu-mips compile again. Still no grub-mkimage support --- configure.ac | 4 +-- gentpl.py | 8 ++--- grub-core/Makefile.am | 5 +++ grub-core/Makefile.core.def | 12 ++++--- grub-core/kern/mips/cache_flush.S | 4 +++ grub-core/kern/mips/qemu-mips/init.c | 3 +- grub-core/loader/mips/linux.c | 7 ++++- grub-core/loader/multiboot_mbi2.c | 2 ++ include/grub/mips/qemu_mips/cmos.h | 28 +++++++++++++++++ .../mips/{qemu-mips => qemu_mips}/kernel.h | 1 - .../mips/{qemu-mips => qemu_mips}/loader.h | 0 .../mips/{qemu-mips => qemu_mips}/memory.h | 31 +++++++++++++++++-- .../mips/{qemu-mips => qemu_mips}/serial.h | 0 .../grub/mips/{qemu-mips => qemu_mips}/time.h | 0 include/grub/offsets.h | 28 +++++++++++++---- 15 files changed, 110 insertions(+), 23 deletions(-) create mode 100644 include/grub/mips/qemu_mips/cmos.h rename include/grub/mips/{qemu-mips => qemu_mips}/kernel.h (97%) rename include/grub/mips/{qemu-mips => qemu_mips}/loader.h (100%) rename include/grub/mips/{qemu-mips => qemu_mips}/memory.h (69%) rename include/grub/mips/{qemu-mips => qemu_mips}/serial.h (100%) rename include/grub/mips/{qemu-mips => qemu_mips}/time.h (100%) diff --git a/configure.ac b/configure.ac index 0b9207ea2..aac93fba2 100644 --- a/configure.ac +++ b/configure.ac @@ -122,7 +122,7 @@ case "$target_cpu"-"$platform" in i386-qemu) ;; powerpc-ieee1275) ;; sparc64-ieee1275) ;; - mips-qemu-mips) ;; + mips-qemu_mips) ;; mips-yeeloong) ;; *-emu) ;; *) AC_MSG_ERROR([platform "$platform" is not supported for target CPU "$target_cpu"]) ;; @@ -157,7 +157,7 @@ case "$platform" in pc) machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_MACHINE_PCBIOS=1" ;; emu) machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_MACHINE_EMU=1" ;; yeeloong) machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_MACHINE_MIPS_YEELOONG=1 -DGRUB_MACHINE_MIPS_BONITO=1" ;; - qemu-mips) machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_MACHINE_MIPS_QEMU_MIPS=1 -DGRUB_MACHINE_MIPS_BONITO=1" ;; + qemu_mips) machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_MACHINE_MIPS_QEMU_MIPS=1" ;; esac case "$target_cpu" in mips) machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_MACHINE_MIPS=1" ;; diff --git a/gentpl.py b/gentpl.py index a42a60667..97eff9f57 100644 --- a/gentpl.py +++ b/gentpl.py @@ -6,7 +6,7 @@ GRUB_PLATFORMS = [ "emu", "i386_pc", "i386_efi", "i386_qemu", "i386_coreboot", "i386_multiboot", "i386_ieee1275", "x86_64_efi", - "mips_yeeloong", "sparc64_ieee1275", + "mips_yeeloong", "mips_qemu_mips", "sparc64_ieee1275", "powerpc_ieee1275" ] GROUPS = {} @@ -17,7 +17,7 @@ GROUPS["common"] = GRUB_PLATFORMS[:] GROUPS["i386"] = [ "i386_pc", "i386_efi", "i386_qemu", "i386_coreboot", "i386_multiboot", "i386_ieee1275" ] GROUPS["x86_64"] = [ "x86_64_efi" ] GROUPS["x86"] = GROUPS["i386"] + GROUPS["x86_64"] -GROUPS["mips"] = [ "mips_yeeloong" ] +GROUPS["mips"] = [ "mips_yeeloong", "mips_qemu_mips" ] GROUPS["sparc64"] = [ "sparc64_ieee1275" ] GROUPS["powerpc"] = [ "powerpc_ieee1275" ] @@ -29,8 +29,8 @@ GROUPS["ieee1275"] = [ "i386_ieee1275", "sparc64_ieee1275", "powerpc_ieee1275" GROUPS["noemu"] = GRUB_PLATFORMS[:]; GROUPS["noemu"].remove("emu") # Groups based on hardware features -GROUPS["cmos"] = GROUPS["x86"][:] + ["mips_yeeloong"]; GROUPS["cmos"].remove("i386_efi"); GROUPS["cmos"].remove("x86_64_efi") -GROUPS["pci"] = GROUPS["x86"] + GROUPS["mips"] +GROUPS["cmos"] = GROUPS["x86"][:] + ["mips_yeeloong", "mips_qemu_mips" ]; GROUPS["cmos"].remove("i386_efi"); GROUPS["cmos"].remove("x86_64_efi") +GROUPS["pci"] = GROUPS["x86"] + ["mips_yeeloong"] GROUPS["usb"] = GROUPS["pci"] # If gfxterm is main output console integrate it into kernel diff --git a/grub-core/Makefile.am b/grub-core/Makefile.am index 94f7f3ffe..65f638745 100644 --- a/grub-core/Makefile.am +++ b/grub-core/Makefile.am @@ -145,6 +145,11 @@ KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/extcmd.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/lib/arg.h endif +if COND_mips_qemu_mips +KERNEL_HEADER_FILES += $(top_builddir)/include/grub/machine/memory.h +KERNEL_HEADER_FILES += $(top_builddir)/include/grub/machine/kernel.h +endif + if COND_powerpc_ieee1275 KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/ieee1275/ieee1275.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/terminfo.h diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def index 2cca4fa95..1cc832892 100644 --- a/grub-core/Makefile.core.def +++ b/grub-core/Makefile.core.def @@ -48,7 +48,7 @@ kernel = { i386_ieee1275_startup = kern/i386/ieee1275/startup.S; i386_coreboot_startup = kern/i386/coreboot/startup.S; i386_multiboot_startup = kern/i386/coreboot/startup.S; - mips_yeeloong_startup = kern/mips/startup.S; + mips_startup = kern/mips/startup.S; sparc64_ieee1275_startup = kern/sparc64/ieee1275/crt0.S; powerpc_ieee1275_startup = kern/powerpc/ieee1275/startup.S; @@ -82,6 +82,7 @@ kernel = { i386_coreboot = kern/generic/rtc_get_time_ms.c; i386_multiboot = kern/generic/rtc_get_time_ms.c; mips_yeeloong = kern/generic/rtc_get_time_ms.c; + mips_qemu_mips = kern/generic/rtc_get_time_ms.c; ieee1275 = disk/ieee1275/ofdisk.c; ieee1275 = kern/ieee1275/cmain.c; @@ -140,10 +141,11 @@ kernel = { mips_yeeloong = bus/bonito.c; mips_yeeloong = bus/cs5536.c; mips_yeeloong = bus/pci.c; - mips_yeeloong = kern/mips/cache.S; - mips_yeeloong = kern/mips/dl.c; - mips_yeeloong = kern/mips/init.c; + mips = kern/mips/cache.S; + mips = kern/mips/dl.c; + mips = kern/mips/init.c; mips_yeeloong = kern/mips/yeeloong/init.c; + mips_qemu_mips = kern/mips/qemu-mips/init.c; mips_yeeloong = term/at_keyboard.c; mips_yeeloong = term/serial.c; mips_yeeloong = video/sm712.c; @@ -1229,7 +1231,7 @@ module = { mips_yeeloong = mmap/mips/yeeloong/uppermem.c; enable = x86; - enable = mips_yeeloong; + enable = mips; }; module = { diff --git a/grub-core/kern/mips/cache_flush.S b/grub-core/kern/mips/cache_flush.S index 11096c035..87a738caa 100644 --- a/grub-core/kern/mips/cache_flush.S +++ b/grub-core/kern/mips/cache_flush.S @@ -1,3 +1,6 @@ + + /* Qemu doesn't emulate caches. Oh boy. */ +#ifndef GRUB_MACHINE_MIPS_QEMU_MIPS move $t2, $a0 addu $t3, $a0, $a1 srl $t2, $t2, 5 @@ -21,3 +24,4 @@ bne $t1, $zero, 2b addiu $t0, $t0, 0x1 sync +#endif \ No newline at end of file diff --git a/grub-core/kern/mips/qemu-mips/init.c b/grub-core/kern/mips/qemu-mips/init.c index f2bb652a8..1690b5451 100644 --- a/grub-core/kern/mips/qemu-mips/init.c +++ b/grub-core/kern/mips/qemu-mips/init.c @@ -6,9 +6,8 @@ #include #include #include -#include #include -#include +#include #define RAMSIZE (*(grub_uint32_t *) ((16 << 20) - 264)) diff --git a/grub-core/loader/mips/linux.c b/grub-core/loader/mips/linux.c index 6ae2a9321..8520609ed 100644 --- a/grub-core/loader/mips/linux.c +++ b/grub-core/loader/mips/linux.c @@ -29,8 +29,10 @@ #include /* For frequencies. */ +#ifdef GRUB_MACHINE_MIPS_YEELOONG #include #include +#endif #ifdef GRUB_MACHINE_MIPS_YEELOONG /* This can be detected on runtime from PMON, but: @@ -314,6 +316,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), linux_envp = extra; envp_off = (grub_uint8_t *) linux_envp - (grub_uint8_t *) playground; linux_envs = (char *) (linux_envp + 5); +#ifdef GRUB_MACHINE_MIPS_YEELOONG grub_snprintf (linux_envs, sizeof ("memsize=XXXXXXXXXXXXXXXXXXXX"), "memsize=%lld", (unsigned long long) grub_mmap_get_lower () >> 20); @@ -338,8 +341,10 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), + target_addr; linux_envs += ALIGN_UP (grub_strlen (linux_envs) + 1, 4); - linux_envp[4] = 0; +#else + linux_envp[0] = 0; +#endif grub_loader_set (grub_linux_boot, grub_linux_unload, 1); initrd_loaded = 0; diff --git a/grub-core/loader/multiboot_mbi2.c b/grub-core/loader/multiboot_mbi2.c index 3141f0028..e4a630d03 100644 --- a/grub-core/loader/multiboot_mbi2.c +++ b/grub-core/loader/multiboot_mbi2.c @@ -671,6 +671,7 @@ grub_multiboot_make_mbi (grub_uint32_t *target) ptrorig += ALIGN_UP (tag->size, MULTIBOOT_TAG_ALIGN); } +#if defined (__i386) || defined (__x86_64__) || defined (GRUB_MACHINE_MIPS_YEELOONG) { struct multiboot_tag_basic_meminfo *tag = (struct multiboot_tag_basic_meminfo *) ptrorig; @@ -682,6 +683,7 @@ grub_multiboot_make_mbi (grub_uint32_t *target) tag->mem_upper = grub_mmap_get_upper () / 1024; ptrorig += ALIGN_UP (tag->size, MULTIBOOT_TAG_ALIGN); } +#endif if (bootdev_set) { diff --git a/include/grub/mips/qemu_mips/cmos.h b/include/grub/mips/qemu_mips/cmos.h new file mode 100644 index 000000000..4aef40e81 --- /dev/null +++ b/include/grub/mips/qemu_mips/cmos.h @@ -0,0 +1,28 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2008 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 . + */ + +#ifndef GRUB_CPU_CMOS_H +#define GRUB_CPU_CMOS_H 1 + +#include +#include + +#define GRUB_CMOS_ADDR_REG 0xb4000070 +#define GRUB_CMOS_DATA_REG 0xb4000071 + +#endif /* GRUB_CPU_CMOS_H */ diff --git a/include/grub/mips/qemu-mips/kernel.h b/include/grub/mips/qemu_mips/kernel.h similarity index 97% rename from include/grub/mips/qemu-mips/kernel.h rename to include/grub/mips/qemu_mips/kernel.h index 230455dbf..c08405e83 100644 --- a/include/grub/mips/qemu-mips/kernel.h +++ b/include/grub/mips/qemu_mips/kernel.h @@ -20,7 +20,6 @@ #define GRUB_KERNEL_MACHINE_HEADER 1 #include -#include #ifndef ASM_FILE diff --git a/include/grub/mips/qemu-mips/loader.h b/include/grub/mips/qemu_mips/loader.h similarity index 100% rename from include/grub/mips/qemu-mips/loader.h rename to include/grub/mips/qemu_mips/loader.h diff --git a/include/grub/mips/qemu-mips/memory.h b/include/grub/mips/qemu_mips/memory.h similarity index 69% rename from include/grub/mips/qemu-mips/memory.h rename to include/grub/mips/qemu_mips/memory.h index 99d9ef2be..57220a1e2 100644 --- a/include/grub/mips/qemu-mips/memory.h +++ b/include/grub/mips/qemu_mips/memory.h @@ -28,11 +28,37 @@ #define GRUB_MACHINE_MEMORY_STACK_HIGH 0x80f00000 #define GRUB_MACHINE_MEMORY_USABLE 0x81000000 +#define GRUB_MACHINE_MEMORY_AVAILABLE 1 +#define GRUB_MACHINE_MEMORY_MAX_TYPE 1 + /* This one is special: it's used internally but is never reported + by firmware. */ +#define GRUB_MACHINE_MEMORY_HOLE 2 +#define GRUB_MACHINE_MEMORY_RESERVED GRUB_MACHINE_MEMORY_HOLE + #ifndef ASM_FILE + +typedef grub_addr_t grub_phys_addr_t; + +static inline grub_phys_addr_t +grub_vtop (void *a) +{ + return ((grub_phys_addr_t) a) & 0x1fffffff; +} + +static inline void * +grub_map_memory (grub_phys_addr_t a, grub_size_t size __attribute__ ((unused))) +{ + return (void *) (a | 0x80000000); +} + +static inline void +grub_unmap_memory (void *a __attribute__ ((unused)), + grub_size_t size __attribute__ ((unused))) +{ +} + grub_err_t EXPORT_FUNC (grub_machine_mmap_iterate) (int NESTED_FUNC_ATTR (*hook) (grub_uint64_t, grub_uint64_t, grub_uint32_t)); -grub_err_t EXPORT_FUNC(grub_machine_mmap_iterate) - (int NESTED_FUNC_ATTR (*hook) (grub_uint64_t, grub_uint64_t, grub_uint32_t)); static inline grub_err_t grub_machine_mmap_register (grub_uint64_t start __attribute__ ((unused)), @@ -47,6 +73,7 @@ grub_machine_mmap_unregister (int handle __attribute__ ((unused))) { return GRUB_ERR_NONE; } + #endif #endif diff --git a/include/grub/mips/qemu-mips/serial.h b/include/grub/mips/qemu_mips/serial.h similarity index 100% rename from include/grub/mips/qemu-mips/serial.h rename to include/grub/mips/qemu_mips/serial.h diff --git a/include/grub/mips/qemu-mips/time.h b/include/grub/mips/qemu_mips/time.h similarity index 100% rename from include/grub/mips/qemu-mips/time.h rename to include/grub/mips/qemu_mips/time.h diff --git a/include/grub/offsets.h b/include/grub/offsets.h index 817372b69..fa609b16f 100644 --- a/include/grub/offsets.h +++ b/include/grub/offsets.h @@ -104,12 +104,26 @@ #define GRUB_KERNEL_MIPS_YEELOONG_LINK_ALIGN 32 -#define GRUB_KERNEL_MIPS_YEELOONG_COMPRESSED_SIZE 0x8 -#define GRUB_KERNEL_MIPS_YEELOONG_UNCOMPRESSED_SIZE 0xc +#define GRUB_KERNEL_MIPS_COMPRESSED_SIZE 0x8 +#define GRUB_KERNEL_MIPS_UNCOMPRESSED_SIZE 0xc -#define GRUB_KERNEL_MIPS_YEELOONG_TOTAL_MODULE_SIZE 0x08 -#define GRUB_KERNEL_MIPS_YEELOONG_PREFIX 0x0c -#define GRUB_KERNEL_MIPS_YEELOONG_PREFIX_END 0x54 +#define GRUB_KERNEL_MIPS_YEELOONG_COMPRESSED_SIZE GRUB_KERNEL_MIPS_COMPRESSED_SIZE +#define GRUB_KERNEL_MIPS_YEELOONG_UNCOMPRESSED_SIZE GRUB_KERNEL_MIPS_UNCOMPRESSED_SIZE + +#define GRUB_KERNEL_MIPS_QEMU_MIPS_COMPRESSED_SIZE GRUB_KERNEL_MIPS_COMPRESSED_SIZE +#define GRUB_KERNEL_MIPS_QEMU_MIPS_UNCOMPRESSED_SIZE GRUB_KERNEL_MIPS_UNCOMPRESSED_SIZE + +#define GRUB_KERNEL_MIPS_TOTAL_MODULE_SIZE 0x08 +#define GRUB_KERNEL_MIPS_PREFIX 0x0c +#define GRUB_KERNEL_MIPS_PREFIX_END 0x54 + +#define GRUB_KERNEL_MIPS_YEELOONG_TOTAL_MODULE_SIZE GRUB_KERNEL_MIPS_TOTAL_MODULE_SIZE +#define GRUB_KERNEL_MIPS_YEELOONG_PREFIX GRUB_KERNEL_MIPS_PREFIX +#define GRUB_KERNEL_MIPS_YEELOONG_PREFIX_END GRUB_KERNEL_MIPS_PREFIX_END + +#define GRUB_KERNEL_MIPS_QEMU_MIPS_TOTAL_MODULE_SIZE GRUB_KERNEL_MIPS_TOTAL_MODULE_SIZE +#define GRUB_KERNEL_MIPS_QEMU_MIPS_PREFIX GRUB_KERNEL_MIPS_PREFIX +#define GRUB_KERNEL_MIPS_QEMU_MIPS_PREFIX_END GRUB_KERNEL_MIPS_PREFIX_END /* The offset of GRUB_PREFIX. */ #define GRUB_KERNEL_I386_EFI_PREFIX 0x8 @@ -144,7 +158,9 @@ #define GRUB_KERNEL_POWERPC_IEEE1275_MOD_ALIGN 0x1000 -#define GRUB_KERNEL_MIPS_YEELOONG_MOD_ALIGN 0x1 +#define GRUB_KERNEL_MIPS_MOD_ALIGN 0x1 +#define GRUB_KERNEL_MIPS_YEELOONG_MOD_ALIGN GRUB_KERNEL_MIPS_MOD_ALIGN +#define GRUB_KERNEL_MIPS_QEMU_MIPS_MOD_ALIGN GRUB_KERNEL_MIPS_MOD_ALIGN /* Minimal gap between _end and the start of the modules. It's a hack for PowerMac to prevent "CLAIM failed" error. The real fix is to From 1d955d0098b02d77ccec93cd425568a7fa95c913 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 14 Jan 2011 19:21:06 +0100 Subject: [PATCH 257/869] * grub-core/Makefile.core.def (fwstart): Add lost LDFLAGS. --- ChangeLog | 4 ++++ grub-core/Makefile.core.def | 1 + 2 files changed, 5 insertions(+) diff --git a/ChangeLog b/ChangeLog index b57c6f229..4822910dd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2011-01-13 Vladimir Serbinenko + + * grub-core/Makefile.core.def (fwstart): Add lost LDFLAGS. + 2011-01-13 Vladimir Serbinenko * grub-core/fs/zfs/zfsinfo.c (grub_cmd_zfs_bootfs): Quote bootpath and diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def index 2cca4fa95..ce7d0b0c2 100644 --- a/grub-core/Makefile.core.def +++ b/grub-core/Makefile.core.def @@ -324,6 +324,7 @@ image = { name = fwstart; mips_yeeloong = boot/mips/yeeloong/fwstart.S; objcopyflags = '-O binary'; + ldflags = '-static-libgcc -lgcc -Wl,-N,-S,-Ttext,0xbfc00000,-Bstatic'; enable = mips_yeeloong; }; From 46c9db88cda310ec22344fcf4cfb055c1a317a28 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 14 Jan 2011 19:23:34 +0100 Subject: [PATCH 258/869] * grub-core/kern/mips/yeeloong/init.c (grub_machine_init): Init boot module. --- ChangeLog | 7 ++++++- grub-core/kern/mips/yeeloong/init.c | 3 +++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 4822910dd..69534abe2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,9 @@ -2011-01-13 Vladimir Serbinenko +2011-01-14 Vladimir Serbinenko + + * grub-core/kern/mips/yeeloong/init.c (grub_machine_init): Init boot + module. + +2011-01-14 Vladimir Serbinenko * grub-core/Makefile.core.def (fwstart): Add lost LDFLAGS. diff --git a/grub-core/kern/mips/yeeloong/init.c b/grub-core/kern/mips/yeeloong/init.c index cadb10773..7a48d69f5 100644 --- a/grub-core/kern/mips/yeeloong/init.c +++ b/grub-core/kern/mips/yeeloong/init.c @@ -41,6 +41,7 @@ extern void grub_at_keyboard_init (void); extern void grub_serial_init (void); extern void grub_terminfo_init (void); extern void grub_keylayouts_init (void); +extern void grub_boot_init (void); /* FIXME: use interrupt to count high. */ grub_uint64_t @@ -210,6 +211,8 @@ grub_machine_init (void) grub_terminfo_init (); grub_serial_init (); + + grub_boot_init (); } void From 13fc463f17281442f13c5ed3dc586f22efaaa2af Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Sat, 15 Jan 2011 14:18:16 -0600 Subject: [PATCH 259/869] Make new grub_vbe_bios_* functions static. --- ChangeLog.vbe-autodetect | 5 +---- grub-core/video/i386/pc/vbe.c | 6 +++--- include/grub/i386/pc/vbe.h | 9 --------- 3 files changed, 4 insertions(+), 16 deletions(-) diff --git a/ChangeLog.vbe-autodetect b/ChangeLog.vbe-autodetect index d8034b885..46aacef7b 100644 --- a/ChangeLog.vbe-autodetect +++ b/ChangeLog.vbe-autodetect @@ -1,4 +1,4 @@ -2010-12-14 Colin Watson +2011-01-15 Colin Watson Preferred resolution detection for VBE. @@ -25,9 +25,6 @@ (grub_video_edid_preferred_mode): Likewise. * include/grub/i386/pc/vbe.h (struct grub_vbe_flat_panel_info): New structure. - (grub_vbe_bios_get_flat_panel_info): Add prototype. - (grub_vbe_bios_get_ddc_capabilities): Likewise. - (grub_vbe_bios_read_edid): Likewise. * grub-core/commands/videoinfo.c (print_edid): New function. (grub_cmd_videoinfo): Print EDID if available. diff --git a/grub-core/video/i386/pc/vbe.c b/grub-core/video/i386/pc/vbe.c index c6bb733a9..29b67beeb 100644 --- a/grub-core/video/i386/pc/vbe.c +++ b/grub-core/video/i386/pc/vbe.c @@ -274,7 +274,7 @@ grub_vbe_bios_get_pm_interface (grub_uint16_t *segment, grub_uint16_t *offset, } /* Call VESA BIOS 0x4f11 to get flat panel information, return status. */ -grub_vbe_status_t +static grub_vbe_status_t grub_vbe_bios_get_flat_panel_info (struct grub_vbe_flat_panel_info *flat_panel_info) { struct grub_bios_int_registers regs; @@ -289,7 +289,7 @@ grub_vbe_bios_get_flat_panel_info (struct grub_vbe_flat_panel_info *flat_panel_i } /* Call VESA BIOS 0x4f15 to get DDC availability, return status. */ -grub_vbe_status_t +static grub_vbe_status_t grub_vbe_bios_get_ddc_capabilities (grub_uint8_t *level) { struct grub_bios_int_registers regs; @@ -307,7 +307,7 @@ grub_vbe_bios_get_ddc_capabilities (grub_uint8_t *level) } /* Call VESA BIOS 0x4f15 to read EDID information, return status. */ -grub_vbe_status_t +static grub_vbe_status_t grub_vbe_bios_read_edid (struct grub_video_edid_info *edid_info) { struct grub_bios_int_registers regs; diff --git a/include/grub/i386/pc/vbe.h b/include/grub/i386/pc/vbe.h index 0422558db..09ad7eb64 100644 --- a/include/grub/i386/pc/vbe.h +++ b/include/grub/i386/pc/vbe.h @@ -214,15 +214,6 @@ grub_vbe_bios_get_scanline_length (grub_uint32_t *length); grub_vbe_status_t grub_vbe_bios_get_display_start (grub_uint32_t *x, grub_uint32_t *y); -/* Call VESA BIOS 0x4f11 to get flat panel information, return status. */ -grub_vbe_status_t -grub_vbe_bios_get_flat_panel_info (struct grub_vbe_flat_panel_info *flat_panel_info); -/* Call VESA BIOS 0x4f15 to get DDC availability, return status. */ -grub_vbe_status_t -grub_vbe_bios_get_ddc_capabilities (grub_uint8_t *level); -/* Call VESA BIOS 0x4f15 to read EDID information, return status. */ -grub_vbe_status_t -grub_vbe_bios_read_edid (struct grub_video_edid_info *edid_data); grub_vbe_status_t grub_vbe_bios_getset_dac_palette_width (int set, int *width); From 043603376e933098adea34156b0898814221c734 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 15 Jan 2011 21:58:21 +0100 Subject: [PATCH 260/869] * util/grub-mkimage.c (generate_image): Check fwstart.img checksum for safety. --- ChangeLog | 5 +++++ util/grub-mkimage.c | 24 ++++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/ChangeLog b/ChangeLog index 69534abe2..d275fd9b6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-01-15 Vladimir Serbinenko + + * util/grub-mkimage.c (generate_image): Check fwstart.img checksum + for safety. + 2011-01-14 Vladimir Serbinenko * grub-core/kern/mips/yeeloong/init.c (grub_machine_init): Init boot diff --git a/util/grub-mkimage.c b/util/grub-mkimage.c index 53e867602..0375d3ed5 100644 --- a/util/grub-mkimage.c +++ b/util/grub-mkimage.c @@ -29,6 +29,7 @@ #include #include #include +#include #include #include @@ -1167,11 +1168,34 @@ generate_image (const char *dir, char *prefix, FILE *out, char *mods[], size_t rom_size; char *boot_path, *boot_img; size_t boot_size; + grub_uint8_t context[GRUB_MD_SHA512->contextsize]; + /* fwstart.img is the only part which can't be testes by using *-elf + target. Check it against the checksum. This checksum is obtained with + sha512sum utility after compiling on Gnewsense. + */ + const grub_uint8_t fwstart_good_hash[] = + { 0x75, 0xbf, 0xa3, 0x0e, 0x7c, 0xd1, 0x03, 0x82, + 0xe1, 0x34, 0x55, 0xd7, 0x09, 0x1e, 0x6c, 0xcc, + 0xef, 0x08, 0x61, 0xc1, 0x3c, 0xd8, 0xc7, 0x9f, + 0xe8, 0x2d, 0x3d, 0xb2, 0xda, 0x41, 0xd3, 0x83, + 0xd7, 0xb8, 0xe3, 0xd7, 0x13, 0xec, 0x9b, 0xf6, + 0xf6, 0xae, 0x6b, 0x32, 0x29, 0xc1, 0x69, 0x82, + 0xfa, 0x65, 0x2d, 0x97, 0x3e, 0x83, 0x6e, 0x6c, + 0xce, 0x34, 0x10, 0x59, 0x74, 0x0e, 0x96, 0x26 }; boot_path = grub_util_get_path (dir, "fwstart.img"); boot_size = grub_util_get_image_size (boot_path); boot_img = grub_util_read_image (boot_path); + grub_memset (context, 0, sizeof (context)); + GRUB_MD_SHA512->init (context); + GRUB_MD_SHA512->write (context, boot_img, boot_size); + GRUB_MD_SHA512->final (context); + if (grub_memcmp (GRUB_MD_SHA512->read (context), fwstart_good_hash, + GRUB_MD_SHA512->mdlen) != 0) + grub_util_warn ("fwstart.img doesn't match the known good version. " + "Proceed at your own risk"); + rom_size = ALIGN_UP (core_size + boot_size, 512 * 1024); rom_img = xmalloc (rom_size); From 646ada34d11f26484ffe33e0cc80bcd06219ec8c Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 16 Jan 2011 12:54:03 +0100 Subject: [PATCH 261/869] * configure.ac: Bump version to 1.99~rc1. --- ChangeLog | 4 ++++ configure.ac | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index d275fd9b6..8c39f7ba5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2011-01-16 Vladimir Serbinenko + + * configure.ac: Bump version to 1.99~rc1. + 2011-01-15 Vladimir Serbinenko * util/grub-mkimage.c (generate_image): Check fwstart.img checksum diff --git a/configure.ac b/configure.ac index 0b9207ea2..c660ac41e 100644 --- a/configure.ac +++ b/configure.ac @@ -32,7 +32,7 @@ dnl type, so there is no conflict. Variables with the prefix "TARGET_" dnl (such as TARGET_CC, TARGET_CFLAGS, etc.) are used for the target dnl type. -AC_INIT([GRUB],[1.99~beta0],[bug-grub@gnu.org]) +AC_INIT([GRUB],[1.99~rc1],[bug-grub@gnu.org]) AC_CONFIG_AUX_DIR([build-aux]) From 4f8ba1461b82f886557293c26da82fe590d556cd Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Mon, 17 Jan 2011 11:56:36 +0000 Subject: [PATCH 262/869] Use low memory scratch area for EDID and FP calls. --- grub-core/video/i386/pc/vbe.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/grub-core/video/i386/pc/vbe.c b/grub-core/video/i386/pc/vbe.c index 29b67beeb..ea60c6074 100644 --- a/grub-core/video/i386/pc/vbe.c +++ b/grub-core/video/i386/pc/vbe.c @@ -383,7 +383,12 @@ grub_vbe_get_preferred_mode (unsigned int *width, unsigned int *height) grub_vbe_status_t status; grub_uint8_t ddc_level; struct grub_video_edid_info edid_info; - struct grub_vbe_flat_panel_info flat_panel_info; + struct grub_vbe_flat_panel_info *flat_panel_info; + + /* Use low memory scratch area as temporary storage for VESA BIOS calls. */ + flat_panel_info = (struct grub_vbe_flat_panel_info *) + (GRUB_MEMORY_MACHINE_SCRATCH_ADDR + sizeof (struct grub_video_edid_info)); + grub_memset (flat_panel_info, 0, sizeof (*flat_panel_info)); if (controller_info.version >= 0x200 && (grub_vbe_bios_get_ddc_capabilities (&ddc_level) & 0xff) @@ -397,7 +402,7 @@ grub_vbe_get_preferred_mode (unsigned int *width, unsigned int *height) grub_errno = GRUB_ERR_NONE; } - status = grub_vbe_bios_get_flat_panel_info (&flat_panel_info); + status = grub_vbe_bios_get_flat_panel_info (flat_panel_info); if (status == GRUB_VBE_STATUS_OK) { *width = flat_panel_info.horizontal_size; @@ -967,9 +972,18 @@ grub_video_vbe_get_info_and_fini (struct grub_video_mode_info *mode_info, static grub_err_t grub_video_vbe_get_edid (struct grub_video_edid_info *edid_info) { - if (grub_vbe_bios_read_edid (edid_info) != GRUB_VBE_STATUS_OK) + struct grub_video_edid_info *edid_info_lowmem; + + /* Use low memory scratch area as temporary storage for VESA BIOS calls. */ + edid_info_lowmem = + (struct grub_video_edid_info *) GRUB_MEMORY_MACHINE_SCRATCH_ADDR; + grub_memset (edid_info_lowmem, 0, sizeof (*edid_info_lowmem)); + + if (grub_vbe_bios_read_edid (edid_info_lowmem) != GRUB_VBE_STATUS_OK) return grub_error (GRUB_ERR_BAD_DEVICE, "EDID information not available"); + grub_memcpy (edid_info, edid_info_lowmem, sizeof (*edid_info)); + return GRUB_ERR_NONE; } From cb918eddf4fd5c2d2d07ac5da6fa8074604b3e5f Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Mon, 17 Jan 2011 12:05:12 +0000 Subject: [PATCH 263/869] fix FP info handling --- grub-core/video/i386/pc/vbe.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/grub-core/video/i386/pc/vbe.c b/grub-core/video/i386/pc/vbe.c index ea60c6074..c2b35a851 100644 --- a/grub-core/video/i386/pc/vbe.c +++ b/grub-core/video/i386/pc/vbe.c @@ -405,8 +405,8 @@ grub_vbe_get_preferred_mode (unsigned int *width, unsigned int *height) status = grub_vbe_bios_get_flat_panel_info (flat_panel_info); if (status == GRUB_VBE_STATUS_OK) { - *width = flat_panel_info.horizontal_size; - *height = flat_panel_info.vertical_size; + *width = flat_panel_info->horizontal_size; + *height = flat_panel_info->vertical_size; return GRUB_ERR_NONE; } From 9b300caf8455dd0b8c3910330b063ff5777f0a36 Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Mon, 17 Jan 2011 12:07:47 +0000 Subject: [PATCH 264/869] grub_video_get_edid is not usable from grub_vbe_get_preferred_mode, as a video adapter has not necessarily yet been set. Use grub_video_vbe_get_edid and grub_video_edid_checksum directly instead. Remove grub_video_get_edid as it now has no users. Reported by: Marjo Mercado. --- ChangeLog.vbe-autodetect | 4 +--- grub-core/video/i386/pc/vbe.c | 39 ++++++++++++++++++----------------- grub-core/video/video.c | 18 ---------------- include/grub/video.h | 1 - 4 files changed, 21 insertions(+), 41 deletions(-) diff --git a/ChangeLog.vbe-autodetect b/ChangeLog.vbe-autodetect index 46aacef7b..3341e8cc3 100644 --- a/ChangeLog.vbe-autodetect +++ b/ChangeLog.vbe-autodetect @@ -1,9 +1,8 @@ -2011-01-15 Colin Watson +2011-01-17 Colin Watson Preferred resolution detection for VBE. * grub-core/video/video.c (grub_video_edid_checksum): New function. - (grub_video_get_edid): Likewise. (grub_video_edid_preferred_mode): Likewise. Try EDID followed by the Flat Panel extension, in line with the X.org VESA driver. * grub-core/video/i386/pc/vbe.c (grub_vbe_bios_get_flat_panel_info): @@ -21,7 +20,6 @@ * include/grub/video.h (struct grub_vbe_edid_info): New structure. (struct grub_video_adapter): Add get_edid. (grub_video_edid_checksum): Add prototype. - (grub_video_get_edid): Likewise. (grub_video_edid_preferred_mode): Likewise. * include/grub/i386/pc/vbe.h (struct grub_vbe_flat_panel_info): New structure. diff --git a/grub-core/video/i386/pc/vbe.c b/grub-core/video/i386/pc/vbe.c index c2b35a851..f94b06060 100644 --- a/grub-core/video/i386/pc/vbe.c +++ b/grub-core/video/i386/pc/vbe.c @@ -377,6 +377,24 @@ grub_vbe_probe (struct grub_vbe_info_block *info_block) return GRUB_ERR_NONE; } +static grub_err_t +grub_video_vbe_get_edid (struct grub_video_edid_info *edid_info) +{ + struct grub_video_edid_info *edid_info_lowmem; + + /* Use low memory scratch area as temporary storage for VESA BIOS calls. */ + edid_info_lowmem = + (struct grub_video_edid_info *) GRUB_MEMORY_MACHINE_SCRATCH_ADDR; + grub_memset (edid_info_lowmem, 0, sizeof (*edid_info_lowmem)); + + if (grub_vbe_bios_read_edid (edid_info_lowmem) != GRUB_VBE_STATUS_OK) + return grub_error (GRUB_ERR_BAD_DEVICE, "EDID information not available"); + + grub_memcpy (edid_info, edid_info_lowmem, sizeof (*edid_info)); + + return GRUB_ERR_NONE; +} + static grub_err_t grub_vbe_get_preferred_mode (unsigned int *width, unsigned int *height) { @@ -394,7 +412,8 @@ grub_vbe_get_preferred_mode (unsigned int *width, unsigned int *height) && (grub_vbe_bios_get_ddc_capabilities (&ddc_level) & 0xff) == GRUB_VBE_STATUS_OK) { - if (grub_video_get_edid (&edid_info) == GRUB_ERR_NONE + if (grub_video_vbe_get_edid (&edid_info) == GRUB_ERR_NONE + && grub_video_edid_checksum (&edid_info) == GRUB_ERR_NONE && grub_video_edid_preferred_mode (&edid_info, width, height) == GRUB_ERR_NONE) return GRUB_ERR_NONE; @@ -969,24 +988,6 @@ grub_video_vbe_get_info_and_fini (struct grub_video_mode_info *mode_info, return grub_video_fb_get_info_and_fini (mode_info, framebuf); } -static grub_err_t -grub_video_vbe_get_edid (struct grub_video_edid_info *edid_info) -{ - struct grub_video_edid_info *edid_info_lowmem; - - /* Use low memory scratch area as temporary storage for VESA BIOS calls. */ - edid_info_lowmem = - (struct grub_video_edid_info *) GRUB_MEMORY_MACHINE_SCRATCH_ADDR; - grub_memset (edid_info_lowmem, 0, sizeof (*edid_info_lowmem)); - - if (grub_vbe_bios_read_edid (edid_info_lowmem) != GRUB_VBE_STATUS_OK) - return grub_error (GRUB_ERR_BAD_DEVICE, "EDID information not available"); - - grub_memcpy (edid_info, edid_info_lowmem, sizeof (*edid_info)); - - return GRUB_ERR_NONE; -} - static void grub_video_vbe_print_adapter_specific_info (void) { diff --git a/grub-core/video/video.c b/grub-core/video/video.c index 84e98bb67..01bdd1ff3 100644 --- a/grub-core/video/video.c +++ b/grub-core/video/video.c @@ -393,24 +393,6 @@ grub_video_edid_checksum (struct grub_video_edid_info *edid_info) return grub_errno; } -grub_err_t -grub_video_get_edid (struct grub_video_edid_info *edid_info) -{ - if (! grub_video_adapter_active) - return grub_error (GRUB_ERR_BAD_DEVICE, "no video mode activated"); - - if (! grub_video_adapter_active->get_edid) - return grub_error (GRUB_ERR_BAD_DEVICE, - "EDID information unavailable for this video mode"); - - if (grub_video_adapter_active->get_edid (edid_info) != GRUB_ERR_NONE) - return grub_errno; - if (grub_video_edid_checksum (edid_info) != GRUB_ERR_NONE) - return grub_errno; - - return GRUB_ERR_NONE; -} - grub_err_t grub_video_edid_preferred_mode (struct grub_video_edid_info *edid_info, unsigned int *width, unsigned int *height) diff --git a/include/grub/video.h b/include/grub/video.h index 2251ed5f4..f42730a7d 100644 --- a/include/grub/video.h +++ b/include/grub/video.h @@ -486,7 +486,6 @@ grub_err_t EXPORT_FUNC (grub_video_set_active_render_target) (struct grub_video_ grub_err_t grub_video_get_active_render_target (struct grub_video_render_target **target); grub_err_t grub_video_edid_checksum (struct grub_video_edid_info *edid_info); -grub_err_t grub_video_get_edid (struct grub_video_edid_info *edid_info); grub_err_t grub_video_edid_preferred_mode (struct grub_video_edid_info *edid_info, unsigned int *width, unsigned int *height); From 5e79d66a547bd1e616defefef4cc5ab44d198a1e Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Mon, 17 Jan 2011 12:48:07 +0000 Subject: [PATCH 265/869] * .bzrignore: Remove nonexistent grub-pbkdf2. --- .bzrignore | 1 - ChangeLog | 4 ++++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/.bzrignore b/.bzrignore index 0cbb3f17f..a3e6f9dd2 100644 --- a/.bzrignore +++ b/.bzrignore @@ -44,7 +44,6 @@ grub-kbdcomp grub-macho2img grub-menulst2cfg grub-mk* -grub-pbkdf2 grub-pe2elf grub-probe grub_probe_init.c diff --git a/ChangeLog b/ChangeLog index 8c39f7ba5..a2d11d828 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2011-01-17 Colin Watson + + * .bzrignore: Remove nonexistent grub-pbkdf2. + 2011-01-16 Vladimir Serbinenko * configure.ac: Bump version to 1.99~rc1. From 01b08a0f15e12a1bcbea49b092a960645c9880fb Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Tue, 18 Jan 2011 13:44:16 +0100 Subject: [PATCH 266/869] initial SIS315PRO support --- grub-core/Makefile.core.def | 1 + grub-core/kern/mips/yeeloong/init.c | 2 + grub-core/video/sis315pro.c | 246 ++++++++++++++++++++++++++++ include/grub/video.h | 3 +- 4 files changed, 251 insertions(+), 1 deletion(-) create mode 100644 grub-core/video/sis315pro.c diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def index ce7d0b0c2..a67c805c9 100644 --- a/grub-core/Makefile.core.def +++ b/grub-core/Makefile.core.def @@ -147,6 +147,7 @@ kernel = { mips_yeeloong = term/at_keyboard.c; mips_yeeloong = term/serial.c; mips_yeeloong = video/sm712.c; + mips_yeeloong = video/sis315pro.c; extra_dist = video/sm712_init.c; mips_yeeloong = commands/keylayouts.c; diff --git a/grub-core/kern/mips/yeeloong/init.c b/grub-core/kern/mips/yeeloong/init.c index 7a48d69f5..f42c9696d 100644 --- a/grub-core/kern/mips/yeeloong/init.c +++ b/grub-core/kern/mips/yeeloong/init.c @@ -33,6 +33,7 @@ #include extern void grub_video_sm712_init (void); +extern void grub_video_sis315pro_init (void); extern void grub_video_init (void); extern void grub_bitmap_init (void); extern void grub_font_init (void); @@ -202,6 +203,7 @@ grub_machine_init (void) relies on a working heap. */ grub_video_init (); grub_video_sm712_init (); + grub_video_sis315pro_init (); grub_bitmap_init (); grub_font_init (); grub_gfxterm_init (); diff --git a/grub-core/video/sis315pro.c b/grub-core/video/sis315pro.c new file mode 100644 index 000000000..59ff6432d --- /dev/null +++ b/grub-core/video/sis315pro.c @@ -0,0 +1,246 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 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 . + */ + +#define grub_video_render_target grub_video_fbrender_target + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define GRUB_SIS315PRO_PCIID 0x03251039 +#define GRUB_SIS315PRO_TOTAL_MEMORY_SPACE 0x800000 + +static struct +{ + struct grub_video_mode_info mode_info; + struct grub_video_render_target *render_target; + + grub_uint8_t *ptr; + int mapped; + grub_uint32_t base; + grub_pci_device_t dev; +} framebuffer; + +#ifndef TEST +static grub_err_t +grub_video_sis315pro_video_init (void) +{ + /* Reset frame buffer. */ + grub_memset (&framebuffer, 0, sizeof(framebuffer)); + + return grub_video_fb_init (); +} + +static grub_err_t +grub_video_sis315pro_video_fini (void) +{ + if (framebuffer.mapped) + grub_pci_device_unmap_range (framebuffer.dev, framebuffer.ptr, + GRUB_SIS315PRO_TOTAL_MEMORY_SPACE); + + return grub_video_fb_fini (); +} +#endif + +static grub_err_t +grub_video_sis315pro_setup (unsigned int width, unsigned int height, + unsigned int mode_type, + unsigned int mode_mask __attribute__ ((unused))) +{ + int depth; + grub_err_t err; + int found = 0; + +#ifndef TEST + 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))) + { + grub_pci_address_t addr; + grub_uint32_t class; + + addr = grub_pci_make_address (dev, GRUB_PCI_REG_CLASS); + class = grub_pci_read (addr); + + if (((class >> 16) & 0xffff) != GRUB_PCI_CLASS_SUBCLASS_VGA + || pciid != GRUB_SIS315PRO_PCIID) + return 0; + + found = 1; + + addr = grub_pci_make_address (dev, GRUB_PCI_REG_ADDRESS_REG0); + framebuffer.base = grub_pci_read (addr); + framebuffer.dev = dev; + + return 1; + } + + /* Decode depth from mode_type. If it is zero, then autodetect. */ + depth = (mode_type & GRUB_VIDEO_MODE_TYPE_DEPTH_MASK) + >> GRUB_VIDEO_MODE_TYPE_DEPTH_POS; + + if ((width != 640 && width != 0) || (height != 400 && height != 0) + || (depth != 8 && depth != 0)) + return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, + "Only 640x400x8 is supported"); + + grub_pci_iterate (find_card); + if (!found) + return grub_error (GRUB_ERR_IO, "Couldn't find graphics card"); +#endif + /* Fill mode info details. */ + framebuffer.mode_info.width = 640; + framebuffer.mode_info.height = 400; + framebuffer.mode_info.mode_type = GRUB_VIDEO_MODE_TYPE_INDEX_COLOR; + framebuffer.mode_info.bpp = 8; + framebuffer.mode_info.bytes_per_pixel = 1; + framebuffer.mode_info.pitch = 640 * 1; + framebuffer.mode_info.number_of_colors = 256; + framebuffer.mode_info.red_mask_size = 0; + framebuffer.mode_info.red_field_pos = 0; + framebuffer.mode_info.green_mask_size = 0; + framebuffer.mode_info.green_field_pos = 0; + framebuffer.mode_info.blue_mask_size = 0; + framebuffer.mode_info.blue_field_pos = 0; + framebuffer.mode_info.reserved_mask_size = 0; + framebuffer.mode_info.reserved_field_pos = 0; +#ifndef TEST + framebuffer.mode_info.blit_format + = grub_video_get_blit_format (&framebuffer.mode_info); +#endif + + /* We can safely discard volatile attribute. */ +#ifndef TEST + framebuffer.ptr + = (void *) grub_pci_device_map_range (framebuffer.dev, + framebuffer.base, + GRUB_SIS315PRO_TOTAL_MEMORY_SPACE); +#endif + framebuffer.mapped = 1; + +#ifndef TEST + /* Prevent garbage from appearing on the screen. */ + grub_memset (framebuffer.ptr, 0, + framebuffer.mode_info.height * framebuffer.mode_info.pitch); +#endif + +#ifndef TEST + err = grub_video_fb_create_render_target_from_pointer (&framebuffer + .render_target, + &framebuffer.mode_info, + framebuffer.ptr); + + if (err) + return err; + + err = grub_video_fb_set_active_render_target (framebuffer.render_target); + + if (err) + return err; + + /* Copy default palette to initialize emulated palette. */ + err = grub_video_fb_set_palette (0, GRUB_VIDEO_FBSTD_NUMCOLORS, + grub_video_fbstd_colors); +#endif + return err; +} + +#ifndef TEST + +static grub_err_t +grub_video_sis315pro_swap_buffers (void) +{ + /* TODO: Implement buffer swapping. */ + return GRUB_ERR_NONE; +} + +static grub_err_t +grub_video_sis315pro_set_active_render_target (struct grub_video_render_target *target) +{ + if (target == GRUB_VIDEO_RENDER_TARGET_DISPLAY) + target = framebuffer.render_target; + + return grub_video_fb_set_active_render_target (target); +} + +static grub_err_t +grub_video_sis315pro_get_info_and_fini (struct grub_video_mode_info *mode_info, + void **framebuf) +{ + grub_memcpy (mode_info, &(framebuffer.mode_info), sizeof (*mode_info)); + *framebuf = (char *) framebuffer.ptr; + + grub_video_fb_fini (); + + return GRUB_ERR_NONE; +} + +static struct grub_video_adapter grub_video_sis315pro_adapter = + { + .name = "SIS315PRO Video Driver", + .id = GRUB_VIDEO_DRIVER_SIS315PRO, + + .prio = GRUB_VIDEO_ADAPTER_PRIO_NATIVE, + + .init = grub_video_sis315pro_video_init, + .fini = grub_video_sis315pro_video_fini, + .setup = grub_video_sis315pro_setup, + .get_info = grub_video_fb_get_info, + .get_info_and_fini = grub_video_sis315pro_get_info_and_fini, + .set_palette = grub_video_fb_set_palette, + .get_palette = grub_video_fb_get_palette, + .set_viewport = grub_video_fb_set_viewport, + .get_viewport = grub_video_fb_get_viewport, + .map_color = grub_video_fb_map_color, + .map_rgb = grub_video_fb_map_rgb, + .map_rgba = grub_video_fb_map_rgba, + .unmap_color = grub_video_fb_unmap_color, + .fill_rect = grub_video_fb_fill_rect, + .blit_bitmap = grub_video_fb_blit_bitmap, + .blit_render_target = grub_video_fb_blit_render_target, + .scroll = grub_video_fb_scroll, + .swap_buffers = grub_video_sis315pro_swap_buffers, + .create_render_target = grub_video_fb_create_render_target, + .delete_render_target = grub_video_fb_delete_render_target, + .set_active_render_target = grub_video_sis315pro_set_active_render_target, + .get_active_render_target = grub_video_fb_get_active_render_target, + + .next = 0 + }; + +GRUB_MOD_INIT(video_sis315pro) +{ + grub_video_register (&grub_video_sis315pro_adapter); +} + +GRUB_MOD_FINI(video_sis315pro) +{ + grub_video_unregister (&grub_video_sis315pro_adapter); +} +#else +int +main () +{ + grub_video_sis315pro_setup (640, 400, 0, 0); +} +#endif diff --git a/include/grub/video.h b/include/grub/video.h index 5350d87eb..8773199c2 100644 --- a/include/grub/video.h +++ b/include/grub/video.h @@ -211,7 +211,8 @@ typedef enum grub_video_driver_id GRUB_VIDEO_DRIVER_VGA, GRUB_VIDEO_DRIVER_CIRRUS, GRUB_VIDEO_DRIVER_BOCHS, - GRUB_VIDEO_DRIVER_SDL + GRUB_VIDEO_DRIVER_SDL, + GRUB_VIDEO_DRIVER_SIS315PRO, } grub_video_driver_id_t; typedef enum grub_video_adapter_prio From edf9d1f7ebb6c37e2de52c50268331384a6e66b5 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Tue, 18 Jan 2011 14:00:55 +0100 Subject: [PATCH 267/869] Don't double the divisor on Geode UART, it runs at normal speed --- grub-core/term/ns8250.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/grub-core/term/ns8250.c b/grub-core/term/ns8250.c index 4be528df8..5d403c845 100644 --- a/grub-core/term/ns8250.c +++ b/grub-core/term/ns8250.c @@ -37,7 +37,8 @@ static const grub_port_t serial_hw_io_addr[] = GRUB_MACHINE_SERIAL_PORTS; /* Convert speed to divisor. */ static unsigned short -serial_get_divisor (unsigned int speed) +serial_get_divisor (const struct grub_serial_port *port, + const struct grub_serial_config *config) { unsigned int i; @@ -63,13 +64,16 @@ serial_get_divisor (unsigned int speed) /* Set the baud rate. */ for (i = 0; i < ARRAY_SIZE (divisor_tab); i++) - if (divisor_tab[i].speed == speed) - /* UART in Yeeloong runs twice the usual rate. */ + if (divisor_tab[i].speed == config->speed) + { + /* internal UART in Yeeloong runs twice the usual rate. */ #ifdef GRUB_MACHINE_MIPS_YEELOONG - return 2 * divisor_tab[i].div; -#else - return divisor_tab[i].div; + if (port->port == 0xbff003f8) + return 2 * divisor_tab[i].div; + else #endif + return divisor_tab[i].div; + } return 0; } @@ -93,7 +97,7 @@ do_real_config (struct grub_serial_port *port) port->broken = 0; - divisor = serial_get_divisor (port->config.speed); + divisor = serial_get_divisor (port, &port->config); /* Turn off the interrupt. */ grub_outb (0, port->port + UART_IER); @@ -188,7 +192,7 @@ serial_hw_configure (struct grub_serial_port *port, { unsigned short divisor; - divisor = serial_get_divisor (config->speed); + divisor = serial_get_divisor (port, config); if (divisor == 0) return grub_error (GRUB_ERR_BAD_ARGUMENT, "bad speed"); From 74eea126f472abc82268d937a26d7367e75e9369 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Tue, 18 Jan 2011 15:28:44 +0100 Subject: [PATCH 268/869] fuloong support --- grub-core/boot/mips/yeeloong/fwstart.S | 3 ++ grub-core/kern/mips/startup.S | 3 ++ grub-core/kern/mips/yeeloong/init.c | 7 +++-- grub-core/loader/mips/linux.c | 40 +++++++++++++++----------- grub-core/term/serial.c | 16 ++++++++--- include/grub/mips/yeeloong/kernel.h | 5 ++++ include/grub/mips/yeeloong/serial.h | 9 ++++-- include/grub/term.h | 16 +++++++++++ 8 files changed, 74 insertions(+), 25 deletions(-) diff --git a/grub-core/boot/mips/yeeloong/fwstart.S b/grub-core/boot/mips/yeeloong/fwstart.S index 425458401..4c2fe5543 100644 --- a/grub-core/boot/mips/yeeloong/fwstart.S +++ b/grub-core/boot/mips/yeeloong/fwstart.S @@ -25,6 +25,9 @@ #include #include +#define GRUB_MACHINE_SERIAL_PORT GRUB_MACHINE_SERIAL_PORT0 +#define GRUB_MACHINE_SERIAL_DIVISOR_115200 GRUB_MACHINE_SERIAL_PORT0_DIVISOR_115200 + .set noreorder .set noat .set nomacro diff --git a/grub-core/kern/mips/startup.S b/grub-core/kern/mips/startup.S index ae0e0b187..4bf4c1762 100644 --- a/grub-core/kern/mips/startup.S +++ b/grub-core/kern/mips/startup.S @@ -20,6 +20,7 @@ #include #include #include +#include #include #define BASE_ADDR 8 @@ -59,6 +60,8 @@ VARIABLE (grub_arch_memsize) .long 0 VARIABLE (grub_arch_highmemsize) .long 0 +VARIABLE (grub_arch_machine) + .long GRUB_ARCH_MACHINE_FULOONG #endif cont: /* Save our base. */ diff --git a/grub-core/kern/mips/yeeloong/init.c b/grub-core/kern/mips/yeeloong/init.c index f42c9696d..6787a205d 100644 --- a/grub-core/kern/mips/yeeloong/init.c +++ b/grub-core/kern/mips/yeeloong/init.c @@ -208,8 +208,11 @@ grub_machine_init (void) grub_font_init (); grub_gfxterm_init (); - grub_keylayouts_init (); - grub_at_keyboard_init (); + if (grub_arch_machine == GRUB_ARCH_MACHINE_YEELOONG) + { + grub_keylayouts_init (); + grub_at_keyboard_init (); + } grub_terminfo_init (); grub_serial_init (); diff --git a/grub-core/loader/mips/linux.c b/grub-core/loader/mips/linux.c index 6ae2a9321..244d2b8a3 100644 --- a/grub-core/loader/mips/linux.c +++ b/grub-core/loader/mips/linux.c @@ -33,11 +33,13 @@ #include #ifdef GRUB_MACHINE_MIPS_YEELOONG -/* This can be detected on runtime from PMON, but: - a) it wouldn't work when GRUB is the firmware - and - b) for now we only support Yeeloong anyway. */ -#define LOONGSON_MACHTYPE "machtype=lemote-yeeloong-2f-8.9inches" +#include + +const char loongson_machtypes[][60] = + { + [GRUB_ARCH_MACHINE_YEELOONG] = "machtype=lemote-yeeloong-2f-8.9inches", + [GRUB_ARCH_MACHINE_FULOONG] = "machtype=lemote-fuloong-2f-unknown" + }; #endif static grub_dl_t my_mod; @@ -222,7 +224,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), /* For arguments. */ linux_argc = argc; -#ifdef LOONGSON_MACHTYPE +#ifdef GRUB_MACHINE_MIPS_YEELOONG linux_argc++; #endif /* Main arguments. */ @@ -237,8 +239,8 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), /* Normal arguments. */ for (i = 1; i < argc; i++) size += ALIGN_UP (grub_strlen (argv[i]) + 1, 4); -#ifdef LOONGSON_MACHTYPE - size += ALIGN_UP (sizeof (LOONGSON_MACHTYPE), 4); +#ifdef GRUB_MACHINE_MIPS_YEELOONG + size += ALIGN_UP (sizeof (loongson_machtypes[0]), 4); #endif /* rd arguments. */ @@ -277,14 +279,20 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), linux_argv++; linux_args += ALIGN_UP (sizeof ("a0"), 4); -#ifdef LOONGSON_MACHTYPE - /* In Loongson platform, it is the responsibility of the bootloader/firmware - to supply the OS kernel with machine type information. */ - grub_memcpy (linux_args, LOONGSON_MACHTYPE, sizeof (LOONGSON_MACHTYPE)); - *linux_argv = (grub_uint8_t *) linux_args - (grub_uint8_t *) playground - + target_addr; - linux_argv++; - linux_args += ALIGN_UP (sizeof (LOONGSON_MACHTYPE), 4); +#ifdef GRUB_MACHINE_MIPS_YEELOONG + { + unsigned mtype = grub_arch_machine; + if (mtype >= ARRAY_SIZE (loongson_machtypes)) + mtype = 0; + /* In Loongson platform, it is the responsibility of the bootloader/firmware + to supply the OS kernel with machine type information. */ + grub_memcpy (linux_args, loongson_machtypes[mtype], + sizeof (loongson_machtypes[mtype])); + *linux_argv = (grub_uint8_t *) linux_args - (grub_uint8_t *) playground + + target_addr; + linux_argv++; + linux_args += ALIGN_UP (sizeof (loongson_machtypes[mtype]), 4); + } #endif for (i = 1; i < argc; i++) diff --git a/grub-core/term/serial.c b/grub-core/term/serial.c index e672a89d6..aca5769fd 100644 --- a/grub-core/term/serial.c +++ b/grub-core/term/serial.c @@ -26,6 +26,9 @@ #include #include #include +#ifdef GRUB_MACHINE_MIPS_YEELOONG +#include +#endif #define FOR_SERIAL_PORTS(var) FOR_LIST_ELEMENTS((var), (grub_serial_ports)) @@ -296,17 +299,22 @@ grub_serial_register (struct grub_serial_port *port) port->term_out = out; grub_terminfo_output_register (out, "vt100"); #ifdef GRUB_MACHINE_MIPS_YEELOONG - if (grub_strcmp (port->name, "com0") == 0) + if (grub_strcmp (port->name, + (grub_arch_machine == GRUB_ARCH_MACHINE_YEELOONG) + ? "com0" : "com2") == 0) { grub_term_register_input_active ("serial_*", in); grub_term_register_output_active ("serial_*", out); } else -#endif { - grub_term_register_input ("serial_*", in); - grub_term_register_output ("serial_*", out); + grub_term_register_input_inactive ("serial_*", in); + grub_term_register_output_inactive ("serial_*", out); } +#else + grub_term_register_input ("serial_*", in); + grub_term_register_output ("serial_*", out); +#endif return GRUB_ERR_NONE; } diff --git a/include/grub/mips/yeeloong/kernel.h b/include/grub/mips/yeeloong/kernel.h index 15cf9f9fd..857b37a15 100644 --- a/include/grub/mips/yeeloong/kernel.h +++ b/include/grub/mips/yeeloong/kernel.h @@ -21,11 +21,16 @@ #include +#define GRUB_ARCH_MACHINE_YEELOONG 0 +#define GRUB_ARCH_MACHINE_FULOONG 1 + #ifndef ASM_FILE void EXPORT_FUNC (grub_reboot) (void) __attribute__ ((noreturn)); void EXPORT_FUNC (grub_halt) (void) __attribute__ ((noreturn)); +extern grub_uint32_t EXPORT_VAR (grub_arch_machine); + #endif #endif /* ! GRUB_KERNEL_MACHINE_HEADER */ diff --git a/include/grub/mips/yeeloong/serial.h b/include/grub/mips/yeeloong/serial.h index ebe3638a1..45e6d8457 100644 --- a/include/grub/mips/yeeloong/serial.h +++ b/include/grub/mips/yeeloong/serial.h @@ -19,11 +19,14 @@ #ifndef GRUB_MACHINE_SERIAL_HEADER #define GRUB_MACHINE_SERIAL_HEADER 1 -#define GRUB_MACHINE_SERIAL_DIVISOR_115200 2 -#define GRUB_MACHINE_SERIAL_PORT 0xbff003f8 +#define GRUB_MACHINE_SERIAL_PORT0_DIVISOR_115200 2 +#define GRUB_MACHINE_SERIAL_PORT2_DIVISOR_115200 1 +#define GRUB_MACHINE_SERIAL_PORT0 0xbff003f8 +#define GRUB_MACHINE_SERIAL_PORT1 0xbfd003f8 +#define GRUB_MACHINE_SERIAL_PORT2 0xbfd002f8 #ifndef ASM_FILE -#define GRUB_MACHINE_SERIAL_PORTS { GRUB_MACHINE_SERIAL_PORT } +#define GRUB_MACHINE_SERIAL_PORTS { GRUB_MACHINE_SERIAL_PORT0, GRUB_MACHINE_SERIAL_PORT1, GRUB_MACHINE_SERIAL_PORT2 } #else #endif diff --git a/include/grub/term.h b/include/grub/term.h index dbcb2f52c..e9efc3f84 100644 --- a/include/grub/term.h +++ b/include/grub/term.h @@ -251,6 +251,14 @@ grub_term_register_input (const char *name __attribute__ ((unused)), } } +static inline void +grub_term_register_input_inactive (const char *name __attribute__ ((unused)), + grub_term_input_t term) +{ + grub_list_push (GRUB_AS_LIST_P (&grub_term_inputs_disabled), + GRUB_AS_LIST (term)); +} + static inline void grub_term_register_input_active (const char *name __attribute__ ((unused)), grub_term_input_t term) @@ -275,6 +283,14 @@ grub_term_register_output (const char *name __attribute__ ((unused)), } } +static inline void +grub_term_register_output_inactive (const char *name __attribute__ ((unused)), + grub_term_output_t term) +{ + grub_list_push (GRUB_AS_LIST_P (&grub_term_outputs_disabled), + GRUB_AS_LIST (term)); +} + static inline void grub_term_register_output_active (const char *name __attribute__ ((unused)), grub_term_output_t term) From 8f49d04c98338c29bddeb1f407500f954a78494e Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Tue, 18 Jan 2011 19:04:27 +0100 Subject: [PATCH 269/869] machtype autodetection --- grub-core/boot/mips/startup_raw.S | 56 ++++++++++++++++++++++++-- grub-core/boot/mips/yeeloong/fwstart.S | 3 +- grub-core/kern/mips/startup.S | 1 + 3 files changed, 56 insertions(+), 4 deletions(-) diff --git a/grub-core/boot/mips/startup_raw.S b/grub-core/boot/mips/startup_raw.S index c41ce8257..d8789982f 100644 --- a/grub-core/boot/mips/startup_raw.S +++ b/grub-core/boot/mips/startup_raw.S @@ -20,6 +20,7 @@ #include #include #include +#include #include #define BASE_ADDR 8 @@ -54,10 +55,12 @@ codestart: move $s3, $zero move $s4, $zero move $s5, $zero + move $s7, $zero /* $a2 has the environment. */ - addiu $t0, $a2, 1 - beq $t0, $zero, argdone + addiu $t0, $zero, -0x10 + and $t1, $a2, $t0 + beq $t0, $t1, argfw nop move $t0, $a2 argcont: @@ -72,11 +75,19 @@ argcont: nop ;\ b 2f;\ move reg, $v0; \ -1: +1: +#define DO_CHECKT1(str, val) \ + move $t6, $t1 ;\ + addiu $t7, $s0, (str - base);\ + bal do_check ;\ + li $t2, val + DO_PARSE (busclockstr, $s2) DO_PARSE (cpuclockstr, $s3) DO_PARSE (memsizestr, $s4) DO_PARSE (highmemsizestr, $s5) + DO_CHECKT1 (pmon_yeeloong_verstr, GRUB_ARCH_MACHINE_YEELOONG) + DO_CHECKT1 (pmon_fuloong_verstr, GRUB_ARCH_MACHINE_FULOONG) 2: b argcont addiu $t0, $t0, 4 @@ -120,8 +131,47 @@ busclockstr: .asciiz "busclock=" cpuclockstr: .asciiz "cpuclock=" memsizestr: .asciiz "memsize=" highmemsizestr: .asciiz "highmemsize=" +machtype_yeeloong_str1: .asciiz "machtype=8.9" +machtype_yeeloong_str2: .asciiz "machtype=lemote-yeeloong-" +machtype_fuloong_str: .asciiz "machtype=lemote-fuloong-" +pmon_yeeloong_str: .asciiz "PMON_VER=LM8" +pmon_fuloong_str: .asciiz "PMON_VER=LM6" +pmon_yeeloong_verstr: .asciiz "Version=LM8" +pmon_fuloong_verstr: .asciiz "Version=LM6" .p2align 2 + argdone: + beq $a0, $zero, cmdlinedone + nop +#define DO_CHECKA1(str, val) \ + lw $t6, 0($a1) ;\ + addiu $t7, $s0, (str - base);\ + bal do_check ;\ + li $t2, val + DO_CHECKA1 (machtype_yeeloong_str1, GRUB_ARCH_MACHINE_YEELOONG) + DO_CHECKA1 (machtype_yeeloong_str2, GRUB_ARCH_MACHINE_YEELOONG) + DO_CHECKA1 (pmon_yeeloong_str, GRUB_ARCH_MACHINE_YEELOONG) + DO_CHECKA1 (machtype_fuloong_str, GRUB_ARCH_MACHINE_FULOONG) + DO_CHECKA1 (pmon_fuloong_str, GRUB_ARCH_MACHINE_FULOONG) + addiu $a0, $a0, -1 + b argdone + addiu $a1, $a1, 4 +do_check: + lb $t4, 0($t7) + beq $t4, $zero, 1f + lb $t3, 0($t6) + bne $t3, $t4, 2f + addiu $t6, $t6, 1 + b do_check + addiu $t7, $t7, 1 +1: + move $s7, $t2 +2: + jr $ra + nop +argfw: + not $s7, $a2 +cmdlinedone: #endif /* Copy the decompressor. */ lui $t1, %hi(base) diff --git a/grub-core/boot/mips/yeeloong/fwstart.S b/grub-core/boot/mips/yeeloong/fwstart.S index 4c2fe5543..bc59c1174 100644 --- a/grub-core/boot/mips/yeeloong/fwstart.S +++ b/grub-core/boot/mips/yeeloong/fwstart.S @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -629,6 +630,6 @@ continue: lui $t0, %hi(cached_continue - 0x20000000) addiu $t0, $t0, %lo(cached_continue - 0x20000000) jr $t0 - addiu $a2, $zero, -1 + addiu $a2, $zero, -(1 + GRUB_ARCH_MACHINE_YEELOONG) cached_continue: \ No newline at end of file diff --git a/grub-core/kern/mips/startup.S b/grub-core/kern/mips/startup.S index 4bf4c1762..999beee79 100644 --- a/grub-core/kern/mips/startup.S +++ b/grub-core/kern/mips/startup.S @@ -74,6 +74,7 @@ cont: sw $s3, 4($t1) sw $s4, 8($t1) sw $s5, 12($t1) + sw $s7, 16($t1) #endif /* Move the modules out of BSS. */ From cfe6539cfe8146ea27ec30fa1ecf55f95b331601 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Tue, 18 Jan 2011 19:05:12 +0100 Subject: [PATCH 270/869] initialise keylayout on fuloong too --- grub-core/kern/mips/yeeloong/init.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/grub-core/kern/mips/yeeloong/init.c b/grub-core/kern/mips/yeeloong/init.c index 6787a205d..b444caf06 100644 --- a/grub-core/kern/mips/yeeloong/init.c +++ b/grub-core/kern/mips/yeeloong/init.c @@ -208,11 +208,9 @@ grub_machine_init (void) grub_font_init (); grub_gfxterm_init (); + grub_keylayouts_init (); if (grub_arch_machine == GRUB_ARCH_MACHINE_YEELOONG) - { - grub_keylayouts_init (); - grub_at_keyboard_init (); - } + grub_at_keyboard_init (); grub_terminfo_init (); grub_serial_init (); From 99388e0cf8e7c3e8f3bdf3d828caddade7b68613 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Tue, 18 Jan 2011 19:39:12 +0100 Subject: [PATCH 271/869] Fuloong shutdown support --- grub-core/kern/mips/yeeloong/init.c | 26 ++++++++++++++++++++++---- include/grub/mips/loongson.h | 2 +- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/grub-core/kern/mips/yeeloong/init.c b/grub-core/kern/mips/yeeloong/init.c index b444caf06..7526111cc 100644 --- a/grub-core/kern/mips/yeeloong/init.c +++ b/grub-core/kern/mips/yeeloong/init.c @@ -226,10 +226,28 @@ grub_machine_fini (void) void grub_halt (void) { - grub_outb (grub_inb (GRUB_CPU_LOONGSON_GPIOCFG) - & ~GRUB_CPU_LOONGSON_SHUTDOWN_GPIO, GRUB_CPU_LOONGSON_GPIOCFG); - - grub_millisleep (1500); + switch (grub_arch_machine) + { + case GRUB_ARCH_MACHINE_FULOONG: + { + grub_pci_device_t dev; + grub_port_t p; + if (grub_cs5536_find (&dev)) + { + p = (grub_cs5536_read_msr (dev, GRUB_CS5536_MSR_GPIO_BAR) + & GRUB_CS5536_LBAR_ADDR_MASK) + GRUB_MACHINE_PCI_IO_BASE; + grub_outl ((1 << 13), p + 4); + grub_outl ((1 << 29), p); + grub_millisleep (5000); + } + } + break; + case GRUB_ARCH_MACHINE_YEELOONG: + grub_outb (grub_inb (GRUB_CPU_LOONGSON_GPIOCFG) + & ~GRUB_CPU_YEELOONG_SHUTDOWN_GPIO, GRUB_CPU_LOONGSON_GPIOCFG); + grub_millisleep (1500); + break; + } grub_printf ("Shutdown failed\n"); grub_refresh (); diff --git a/include/grub/mips/loongson.h b/include/grub/mips/loongson.h index 6cb1178d5..e9f1583ab 100644 --- a/include/grub/mips/loongson.h +++ b/include/grub/mips/loongson.h @@ -85,6 +85,6 @@ #define GRUB_CPU_LOONGSON_PCI_HIT1_SEL_HI 0xbfe00154 #define GRUB_CPU_LOONGSON_GPIOCFG 0xbfe00120 -#define GRUB_CPU_LOONGSON_SHUTDOWN_GPIO 1 +#define GRUB_CPU_YEELOONG_SHUTDOWN_GPIO 1 #endif From 81431e2b020371b57f747e2b3decdfbb00ed183e Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Sat, 22 Jan 2011 01:11:56 +0000 Subject: [PATCH 272/869] * docs/grub.texi (Simple configuration): Document GRUB_PRELOAD_MODULES. --- ChangeLog | 5 +++++ docs/grub.texi | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/ChangeLog b/ChangeLog index a2d11d828..75c713b9d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-01-22 Colin Watson + + * docs/grub.texi (Simple configuration): Document + GRUB_PRELOAD_MODULES. + 2011-01-17 Colin Watson * .bzrignore: Remove nonexistent grub-pbkdf2. diff --git a/docs/grub.texi b/docs/grub.texi index daf48da13..a47389f1e 100644 --- a/docs/grub.texi +++ b/docs/grub.texi @@ -1181,6 +1181,11 @@ directly to @ref{play}. If this option is set, GRUB will issue a @ref{badram} command to filter out specified regions of RAM. +@item GRUB_PRELOAD_MODULES +This option may be set to a list of GRUB module names separated by spaces. +Each module will be loaded as early as possible, at the start of +@file{grub.cfg}. + @end table For more detailed customisation of @command{grub-mkconfig}'s output, you may From 96e0a6ea9795fd2068d8f8e308d398fd3cb0e314 Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Sat, 22 Jan 2011 01:26:49 +0000 Subject: [PATCH 273/869] * util/grub-mkconfig_lib.in (is_path_readable_by_grub): Consider a path unreadable if `grub-probe -t abstraction' fails, for example if memberlist fails on an LVM volume group. Reported by: Darius Jahandarie. --- ChangeLog | 7 +++++++ util/grub-mkconfig_lib.in | 6 ++++++ 2 files changed, 13 insertions(+) diff --git a/ChangeLog b/ChangeLog index 75c713b9d..062f3c5a8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2011-01-22 Colin Watson + + * util/grub-mkconfig_lib.in (is_path_readable_by_grub): Consider a + path unreadable if `grub-probe -t abstraction' fails, for example if + memberlist fails on an LVM volume group. + Reported by: Darius Jahandarie. + 2011-01-22 Colin Watson * docs/grub.texi (Simple configuration): Document diff --git a/util/grub-mkconfig_lib.in b/util/grub-mkconfig_lib.in index 2a48fb260..628ea34d4 100644 --- a/util/grub-mkconfig_lib.in +++ b/util/grub-mkconfig_lib.in @@ -61,6 +61,12 @@ is_path_readable_by_grub () return 1 fi + # ... or if we can't figure out the abstraction module, for example if + # memberlist fails on an LVM volume group. + if ${grub_probe} -t abstraction $path > /dev/null 2>&1 ; then : ; else + return 1 + fi + return 0 } From e489601ad0594bde0dc17257802beb7076976849 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 22 Jan 2011 13:18:05 +0100 Subject: [PATCH 274/869] * grub-core/disk/raid.c (insert_array): Ensure uniqueness of p->number even if some elements have a name. Reported by: Alexander GQ Gerasiov. --- ChangeLog | 6 ++++++ grub-core/disk/raid.c | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 062f3c5a8..cb499bb01 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2011-01-22 Vladimir Serbinenko + + * grub-core/disk/raid.c (insert_array): Ensure uniqueness of p->number + even if some elements have a name. + Reported by: Alexander GQ Gerasiov. + 2011-01-22 Colin Watson * util/grub-mkconfig_lib.in (is_path_readable_by_grub): Consider a diff --git a/grub-core/disk/raid.c b/grub-core/disk/raid.c index c789fea50..3972e1632 100644 --- a/grub-core/disk/raid.c +++ b/grub-core/disk/raid.c @@ -570,7 +570,7 @@ insert_array (grub_disk_t disk, struct grub_raid_array *new_array, { for (p = array_list; p != NULL; p = p->next) { - if (! p->name && p->number == array->number) + if (p->number == array->number) break; } } From 5d4f4dd51b159de457a989c731c0012d0bbbac98 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 22 Jan 2011 13:22:46 +0100 Subject: [PATCH 275/869] * grub-core/disk/scsi.c (grub_scsi_read): Fix binary and check and make logical expression more readable. --- ChangeLog | 5 +++++ grub-core/disk/scsi.c | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index cb499bb01..16be610ea 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-01-22 Vladimir Serbinenko + + * grub-core/disk/scsi.c (grub_scsi_read): Fix binary and check and make + logical expression more readable. + 2011-01-22 Vladimir Serbinenko * grub-core/disk/raid.c (insert_array): Ensure uniqueness of p->number diff --git a/grub-core/disk/scsi.c b/grub-core/disk/scsi.c index 902ab12c3..a40de278f 100644 --- a/grub-core/disk/scsi.c +++ b/grub-core/disk/scsi.c @@ -506,7 +506,7 @@ grub_scsi_read (grub_disk_t disk, grub_disk_addr_t sector, if (scsi->blocksize != GRUB_DISK_SECTOR_SIZE) { unsigned spb = scsi->blocksize >> GRUB_DISK_SECTOR_BITS; - if (! (spb != 0 && (scsi->blocksize & GRUB_DISK_SECTOR_SIZE) == 0)) + if (spb == 0 || (scsi->blocksize & (GRUB_DISK_SECTOR_SIZE - 1)) != 0) return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, "unsupported SCSI block size"); From 80f23be71fa11304d11e3dc549f1a20d0a492673 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 22 Jan 2011 14:11:19 +0100 Subject: [PATCH 276/869] * grub-core/script/argv.c (round_up_exp): unsigned is 32-bit on all supported platforms. Put a compile time assert for this rather than generate a warning with 32-bit shift. --- ChangeLog | 6 ++++++ grub-core/script/argv.c | 5 ++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 16be610ea..9e4ea21dd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2011-01-22 Vladimir Serbinenko + + * grub-core/script/argv.c (round_up_exp): unsigned is 32-bit on all + supported platforms. Put a compile time assert for this rather than + generate a warning with 32-bit shift. + 2011-01-22 Vladimir Serbinenko * grub-core/disk/scsi.c (grub_scsi_read): Fix binary and check and make diff --git a/grub-core/script/argv.c b/grub-core/script/argv.c index 50f810fcf..856828d7b 100644 --- a/grub-core/script/argv.c +++ b/grub-core/script/argv.c @@ -25,6 +25,8 @@ static unsigned round_up_exp (unsigned v) { + COMPILE_TIME_ASSERT (sizeof (v) == 4); + v--; v |= v >> 1; v |= v >> 2; @@ -32,9 +34,6 @@ round_up_exp (unsigned v) v |= v >> 8; v |= v >> 16; - if (sizeof (v) > 4) - v |= v >> 32; - v++; v += (v == 0); From ffc8f4d8bce3586d4dcd714c84eea558c902c8a8 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 22 Jan 2011 14:15:17 +0100 Subject: [PATCH 277/869] * grub-core/partmap/bsdlabel.c: Include grub/emu/misc.h and not grub/util/misc.h. (iterate_real): Don't rely on partition being non-NULL. --- ChangeLog | 5 +++++ grub-core/partmap/bsdlabel.c | 5 +++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9e4ea21dd..6593c4891 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-01-22 Vladimir Serbinenko + + * grub-core/partmap/bsdlabel.c: Include grub/emu/misc.h and not grub/util/misc.h. + (iterate_real): Don't rely on partition being non-NULL. + 2011-01-22 Vladimir Serbinenko * grub-core/script/argv.c (round_up_exp): unsigned is 32-bit on all diff --git a/grub-core/partmap/bsdlabel.c b/grub-core/partmap/bsdlabel.c index 09ecd935a..4dec3851c 100644 --- a/grub-core/partmap/bsdlabel.c +++ b/grub-core/partmap/bsdlabel.c @@ -26,7 +26,7 @@ #include #ifdef GRUB_UTIL -#include +#include #endif static struct grub_partition_map grub_bsdlabel_partition_map; @@ -101,7 +101,8 @@ iterate_real (grub_disk_t disk, grub_disk_addr_t sector, int freebsd, #ifdef GRUB_UTIL char *partname; /* disk->partition != NULL as 0 < delta */ - partname = grub_partition_get_name (disk->partition); + partname = disk->partition ? 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); From 03a4ccb5134770375d5b8ed95e11ef6bfc296730 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 22 Jan 2011 14:26:18 +0100 Subject: [PATCH 278/869] * grub-core/bus/bonito.c (write_bases): Fix direction of the shift. --- ChangeLog | 4 ++++ grub-core/bus/bonito.c | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 6593c4891..f44a91c6b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2011-01-22 Vladimir Serbinenko + + * grub-core/bus/bonito.c (write_bases): Fix direction of the shift. + 2011-01-22 Vladimir Serbinenko * grub-core/partmap/bsdlabel.c: Include grub/emu/misc.h and not grub/util/misc.h. diff --git a/grub-core/bus/bonito.c b/grub-core/bus/bonito.c index 3f794c45a..c2e0cd6ff 100644 --- a/grub-core/bus/bonito.c +++ b/grub-core/bus/bonito.c @@ -38,7 +38,7 @@ write_bases (void) for (i = 0; i < GRUB_MACHINE_PCI_NUM_WIN; i++) reg |= (((base_win[i] >> GRUB_MACHINE_PCI_WIN_SHIFT) & GRUB_MACHINE_PCI_WIN_MASK) - >> (i * GRUB_MACHINE_PCI_WIN_MASK_SIZE)); + << (i * GRUB_MACHINE_PCI_WIN_MASK_SIZE)); GRUB_MACHINE_PCI_IO_CTRL_REG = reg; } From 37f4f60828307e35cac458e5b832d4a36aaa0471 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 22 Jan 2011 15:10:29 +0100 Subject: [PATCH 279/869] * util/grub-install.in: Ignore install device on platforms where it doesn't make sense. Always use UUIDs except on pc, efi and sparc64. Reported by: Daniel Kahn Gillmor. --- ChangeLog | 7 +++++++ util/grub-install.in | 26 ++++++++++++++------------ 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/ChangeLog b/ChangeLog index f44a91c6b..ce6b6f7cf 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2011-01-22 Vladimir Serbinenko + + * util/grub-install.in: Ignore install device on platforms + where it doesn't make sense. Always use UUIDs except on pc, efi and + sparc64. + Reported by: Daniel Kahn Gillmor. + 2011-01-22 Vladimir Serbinenko * grub-core/bus/bonito.c (write_bases): Fix direction of the shift. diff --git a/util/grub-install.in b/util/grub-install.in index 90360c279..1ae00b2fd 100644 --- a/util/grub-install.in +++ b/util/grub-install.in @@ -270,6 +270,11 @@ if test "x$install_device" = x && ([ "${target_cpu}-${platform}" = "i386-pc" ] \ exit 1 fi +if ! ([ "${target_cpu}-${platform}" = "i386-pc" ] \ + || [ "${target_cpu}-${platform}" = "sparc64-ieee1275" ]); then + install_device= +fi + # If the debugging feature is enabled, print commands. setup_verbose= if test x"$debug" = xyes; then @@ -516,27 +521,24 @@ if [ "x${devabstraction_module}" = "x" ] ; then # Strip partition number grub_partition="`echo "${grub_drive}" | sed -e 's/^[^,]*[,)]//; s/)$//'`" grub_drive="`echo "${grub_drive}" | sed -e s/,[a-z0-9,]*//g`" - if [ "$disk_module" = ata ] ; then + if [ "$disk_module" = ata ] || [ "x${grub_drive}" != "x${install_drive}" ] || ([ "x$platform" != xefi ] && [ "x$platform" != xpc ] && [ x"${target_cpu}-${platform}" != x"sparc64-ieee1275" ]) ; then # generic method (used on coreboot and ata mod) uuid="`"$grub_probe" --device-map="${device_map}" --target=fs_uuid --device "${grub_device}"`" if [ "x${uuid}" = "x" ] ; then - echo "UUID needed with ata mod, but the filesystem containing ${grubdir} does not support UUIDs." 1>&2 + if [ "x$platform" != xefi ] && [ "x$platform" != xpc ] && [ x"${target_cpu}-${platform}" != x"sparc64-ieee1275" ]; then + echo "UUID needed with $platform, but the filesystem containing ${grubdir} does not support UUIDs." 1>&2 + elif [ "$disk_module" = ata ]; then + echo "UUID needed with ata mod, but the filesystem containing ${grubdir} does not support UUIDs." 1>&2 + else + echo "UUID needed with cross-disk installs, but the filesystem containing ${grubdir} does not support UUIDs." 1>&2 + fi + exit 1 fi echo "search.fs_uuid ${uuid} root " >> "${grubdir}/load.cfg" echo 'set prefix=($root)'"${relative_grubdir}" >> "${grubdir}/load.cfg" config_opt="-c ${grubdir}/load.cfg " modules="$modules search_fs_uuid" - elif [ "x${grub_drive}" != "x${install_drive}" ] ; then - uuid="`"$grub_probe" --device-map="${device_map}" --target=fs_uuid --device "${grub_device}"`" - if [ "x${uuid}" = "x" ] ; then - echo "You attempted a cross-disk install, but the filesystem containing ${grubdir} does not support UUIDs." 1>&2 - exit 1 - fi - echo "search.fs_uuid ${uuid} root " >> ${grubdir}/load.cfg - echo 'set prefix=($root)'"${relative_grubdir}" >> ${grubdir}/load.cfg - config_opt="-c ${grubdir}/load.cfg " - modules="$modules search_fs_uuid" elif [ "x$platform" = xefi ] || [ "x$platform" = xpc ]; then # we need to hardcode the partition number in the core image's prefix. if [ x"$grub_partition" = x ]; then From 5d4c5f891446f913ced217af1712a8d903449fe0 Mon Sep 17 00:00:00 2001 From: Anthony DeRobertis Date: Sat, 22 Jan 2011 15:20:08 +0100 Subject: [PATCH 280/869] * grub-core/disk/mdraid1x_linux.c (grub_mdraid_detect): Check super_offset field. --- grub-core/disk/mdraid1x_linux.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/grub-core/disk/mdraid1x_linux.c b/grub-core/disk/mdraid1x_linux.c index 155210df3..f2e7555cb 100644 --- a/grub-core/disk/mdraid1x_linux.c +++ b/grub-core/disk/mdraid1x_linux.c @@ -143,7 +143,8 @@ grub_mdraid_detect (grub_disk_t disk, struct grub_raid_array *array, &sb)) return grub_errno; - if (grub_le_to_cpu32 (sb.magic) != SB_MAGIC) + if (grub_le_to_cpu32 (sb.magic) != SB_MAGIC + || grub_le_to_cpu64 (sb.super_offset) != sector) continue; { From 73ae4f4ff55b39739352daf133ac4e9562e7f98e Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 22 Jan 2011 15:30:48 +0100 Subject: [PATCH 281/869] Add missing ChangeLog entry --- ChangeLog | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/ChangeLog b/ChangeLog index ce6b6f7cf..ba611afad 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-01-22 Anthony DeRobertis + + * grub-core/disk/mdraid1x_linux.c (grub_mdraid_detect): Check + super_offset field. + 2011-01-22 Vladimir Serbinenko * util/grub-install.in: Ignore install device on platforms From 3533413cd5efc9630436511b57d77f24c6afd0a3 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 22 Jan 2011 15:37:05 +0100 Subject: [PATCH 282/869] * grub-core/kern/emu/getroot.c: Include config-util.h explicitly. --- ChangeLog | 4 ++++ grub-core/kern/emu/getroot.c | 2 ++ 2 files changed, 6 insertions(+) diff --git a/ChangeLog b/ChangeLog index ba611afad..edb7d46f7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2011-01-22 Vladimir Serbinenko + + * grub-core/kern/emu/getroot.c: Include config-util.h explicitly. + 2011-01-22 Anthony DeRobertis * grub-core/disk/mdraid1x_linux.c (grub_mdraid_detect): Check diff --git a/grub-core/kern/emu/getroot.c b/grub-core/kern/emu/getroot.c index aedef9e0e..110e58b14 100644 --- a/grub-core/kern/emu/getroot.c +++ b/grub-core/kern/emu/getroot.c @@ -17,7 +17,9 @@ * along with GRUB. If not, see . */ +#include #include + #include #include #include From ea9e017dc5064da8a8f8d336785bd1937d1b6737 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 23 Jan 2011 21:50:09 +0100 Subject: [PATCH 283/869] Correct address to unsupported memory type string --- grub-core/boot/mips/yeeloong/fwstart.S | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/grub-core/boot/mips/yeeloong/fwstart.S b/grub-core/boot/mips/yeeloong/fwstart.S index bc59c1174..560e0ed8c 100644 --- a/grub-core/boot/mips/yeeloong/fwstart.S +++ b/grub-core/boot/mips/yeeloong/fwstart.S @@ -124,7 +124,7 @@ __start: ori $t0, $zero, GRUB_SMBUS_SPD_MEMORY_TYPE_DDR2 lui $a0, %hi(unimplemented_memory_type) bne $t0, $v0, fatal - addiu $a0, $a0, %hi(unimplemented_memory_type) + addiu $a0, $a0, %lo(unimplemented_memory_type) /* And here is our goal: DDR2 controller initialisation. */ lui $t0, %hi(GRUB_CPU_LOONGSON_CORECFG) From 9b4ad415e649d02565d429d539c7800df967b2b6 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 23 Jan 2011 21:52:43 +0100 Subject: [PATCH 284/869] Retry the scan for CS5536 in case of failure --- grub-core/boot/mips/yeeloong/fwstart.S | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/grub-core/boot/mips/yeeloong/fwstart.S b/grub-core/boot/mips/yeeloong/fwstart.S index 560e0ed8c..144c76ac6 100644 --- a/grub-core/boot/mips/yeeloong/fwstart.S +++ b/grub-core/boot/mips/yeeloong/fwstart.S @@ -43,17 +43,18 @@ __start: /* $t4 chooses device in priority encoding. */ /* Resulting value is kept in GRUB_MACHINE_PCI_CONF_CTRL_REG. This way we don't need to sacrifice a register for it. */ +retry_cs5536: /* We have only one bus (0). Function is 0. */ lui $t0, %hi(GRUB_MACHINE_PCI_CONF_CTRL_REG_ADDR) lui $t1, %hi(GRUB_MACHINE_PCI_CONFSPACE) lui $t3, %hi(GRUB_CS5536_PCIID) addiu $t3, $t3, %lo(GRUB_CS5536_PCIID) ori $t4, $zero, 1 - lui $a0, %hi(no_cs5536) 1: andi $t4, $t4, ((1 << GRUB_PCI_NUM_DEVICES) - 1) - beql $t4, $zero, fatal - addiu $a0, $a0, %lo(no_cs5536) + /* In case of failure try again. CS5536 may be slow to come up. */ + beql $t4, $zero, retry_cs5536 + nop sw $t4, %lo(GRUB_MACHINE_PCI_CONF_CTRL_REG_ADDR) ($t0) lw $t2, (%lo(GRUB_MACHINE_PCI_CONFSPACE) + GRUB_PCI_REG_PCI_ID) ($t1) bnel $t2, $t3, 1b @@ -383,7 +384,6 @@ read_spd_fail: ori $v0, $v0, 0x100 notification_string: .asciz "GRUB " -no_cs5536: .asciz "No CS5536 found.\n\r" cs5536_found: .asciz "CS5536 at " sm_failed: .asciz "SM transaction failed.\n\r" unhandled_tlb_refill: .asciz "Unhandled TLB refill.\n\r" From 0889c3401c4b2c2c9359fdfe06a7169f8b9b4bc4 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 23 Jan 2011 21:56:00 +0100 Subject: [PATCH 285/869] Explicitly enable MSR mailbox --- grub-core/boot/mips/yeeloong/fwstart.S | 4 ++++ include/grub/cs5536.h | 8 +++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/grub-core/boot/mips/yeeloong/fwstart.S b/grub-core/boot/mips/yeeloong/fwstart.S index 144c76ac6..184aff5d2 100644 --- a/grub-core/boot/mips/yeeloong/fwstart.S +++ b/grub-core/boot/mips/yeeloong/fwstart.S @@ -66,6 +66,10 @@ retry_cs5536: move $a0, $t4 /* Initialise SMBus controller. */ + lui $t0, %hi(GRUB_MACHINE_PCI_CONFSPACE) + li $t1, GRUB_CS5536_MSR_MAILBOX_CONFIG_ENABLED + sw $t1, (%lo(GRUB_MACHINE_PCI_CONFSPACE) + GRUB_CS5536_MSR_MAILBOX_CONFIG) ($t0) + /* Set GPIO LBAR. */ lui $a0, %hi(GRUB_CS5536_MSR_GPIO_BAR) addiu $a0, $a0, %lo(GRUB_CS5536_MSR_GPIO_BAR) diff --git a/include/grub/cs5536.h b/include/grub/cs5536.h index cd17e11fc..de0d6df7e 100644 --- a/include/grub/cs5536.h +++ b/include/grub/cs5536.h @@ -26,9 +26,11 @@ #endif #define GRUB_CS5536_PCIID 0x208f1022 -#define GRUB_CS5536_MSR_MAILBOX_ADDR 0xf4 -#define GRUB_CS5536_MSR_MAILBOX_DATA0 0xf8 -#define GRUB_CS5536_MSR_MAILBOX_DATA1 0xfc +#define GRUB_CS5536_MSR_MAILBOX_CONFIG_ENABLED 0x1 +#define GRUB_CS5536_MSR_MAILBOX_CONFIG 0xf0 +#define GRUB_CS5536_MSR_MAILBOX_ADDR 0xf4 +#define GRUB_CS5536_MSR_MAILBOX_DATA0 0xf8 +#define GRUB_CS5536_MSR_MAILBOX_DATA1 0xfc #define GRUB_CS5536_MSR_IRQ_MAP_BAR 0x80000008 #define GRUB_CS5536_MSR_SMB_BAR 0x8000000b From 1ccfc5d20139637a65ab81bb3c606e122eb341f4 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 24 Jan 2011 00:38:30 +0100 Subject: [PATCH 286/869] Move GPIO init to fwstart.S for convenience --- grub-core/boot/mips/yeeloong/fwstart.S | 70 ++++++++++++++++++++++---- grub-core/bus/cs5536.c | 31 ------------ 2 files changed, 61 insertions(+), 40 deletions(-) diff --git a/grub-core/boot/mips/yeeloong/fwstart.S b/grub-core/boot/mips/yeeloong/fwstart.S index 184aff5d2..41559ffa4 100644 --- a/grub-core/boot/mips/yeeloong/fwstart.S +++ b/grub-core/boot/mips/yeeloong/fwstart.S @@ -65,7 +65,6 @@ retry_cs5536: bal printhex move $a0, $t4 - /* Initialise SMBus controller. */ lui $t0, %hi(GRUB_MACHINE_PCI_CONFSPACE) li $t1, GRUB_CS5536_MSR_MAILBOX_CONFIG_ENABLED sw $t1, (%lo(GRUB_MACHINE_PCI_CONFSPACE) + GRUB_CS5536_MSR_MAILBOX_CONFIG) ($t0) @@ -79,6 +78,10 @@ retry_cs5536: ori $a2, $zero, ((GRUB_CS5536_LBAR_MASK_MASK \ | GRUB_CS5536_LBAR_ENABLE) >> 32) + bal gpio_init + nop + + /* Initialise SMBus controller. */ /* Set SMBUS LBAR. */ lui $a0, %hi(GRUB_CS5536_MSR_SMB_BAR) addiu $a0, $a0, %lo(GRUB_CS5536_MSR_SMB_BAR) @@ -92,14 +95,6 @@ retry_cs5536: bal message addiu $a0, $a0, %lo(smbus_enabled) - /* Enable SMBus controller pins. */ - lui $t0, %hi(GRUB_MACHINE_PCI_IO_BASE + GRUB_CS5536_LBAR_GPIO) - ori $t1, $zero, GRUB_GPIO_SMBUS_PINS - sw $t1, %lo(GRUB_MACHINE_PCI_IO_BASE + GRUB_CS5536_LBAR_GPIO + GRUB_GPIO_REG_OUT_EN) ($t0) - sw $t1, %lo(GRUB_MACHINE_PCI_IO_BASE + GRUB_CS5536_LBAR_GPIO + GRUB_GPIO_REG_OUT_AUX1) ($t0) - sw $t1, %lo(GRUB_MACHINE_PCI_IO_BASE + GRUB_CS5536_LBAR_GPIO + GRUB_GPIO_REG_IN_EN) ($t0) - sw $t1, %lo(GRUB_MACHINE_PCI_IO_BASE + GRUB_CS5536_LBAR_GPIO + GRUB_GPIO_REG_IN_AUX1) ($t0) - lui $t0, %hi(GRUB_MACHINE_PCI_IO_BASE + GRUB_CS5536_LBAR_SMBUS) /* Disable SMB. */ @@ -215,6 +210,24 @@ other_exception: b fatal addiu $a0, $a0, %lo(unhandled_exception) +gpio_init: + lui $t0, %hi(GRUB_MACHINE_PCI_IO_BASE + GRUB_CS5536_LBAR_GPIO) + addiu $t0, $t0, %lo(GRUB_MACHINE_PCI_IO_BASE + GRUB_CS5536_LBAR_GPIO) + lui $t1, %hi (gpio_dump) + addiu $t1, $t1, %lo (gpio_dump) + +1: + lw $t2, 0($t1) + sw $t2, 0($t0) + addiu $t0, $t0, 4 + addiu $t1, $t1, 4 + lui $t2, %hi (gpio_dump_end) + addiu $t2, $t2, %lo (gpio_dump_end) + bne $t1, $t2, 1b + nop + jr $ra + nop + /* Same as similarly named C function but in asm since we need it early. */ /* In: none. Out: none. Clobbered: $t0, $t1, $a0. */ @@ -434,6 +447,45 @@ regdump: .quad 0 /* 1b */ .quad 0 /* 1c */ +/* Dump of GPIO connections. FIXME: Remove useless and macroify. */ +gpio_dump: +#ifdef FULOONG + .long 0xffff0000, 0x2eefd110, 0xffff0000, 0xffff0000 + .long 0x2eefd110, 0xffff0000, 0x1000efff, 0xefff1000 + .long 0x3df3c20c, 0xffff0000, 0xffff0000, 0xffff0000 + .long 0x7df3820c, 0x3df3c20c, 0xffff0000, 0x00000000 + .long 0xffff0000, 0xffff0000, 0x3de3c21c, 0x3d83c27c + .long 0x00000000, 0x00000000, 0x00000000, 0x00000000 + .long 0x00000000, 0x00000000, 0x00000000, 0x00000000 + .long 0x00000000, 0x00000000, 0x00000000, 0x00000000 + .long 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000 + .long 0xffff0000, 0xffff0000, 0x0000ffff, 0xffff0000 + .long 0xefff1000, 0xffff0000, 0xffff0000, 0xffff0000 + .long 0xefff1000, 0xefff1000, 0xffff0000, 0x00000000 + .long 0xffff0000, 0xffff0000, 0xefff1000, 0xefff1000 + .long 0x00000000, 0x00000000, 0x00000000, 0x00000000 + .long 0x00000000, 0x00000000, 0x00000000, 0x00000000 + .long 0x00000000, 0x00000000, 0x00000000, 0x00000000 +#else + .long 0xffff0000, 0x2ffdd002, 0xffff0000, 0xffff0000 + .long 0x2fffd000, 0xffff0000, 0x1000efff, 0xefff1000 + .long 0x3ffbc004, 0xffff0000, 0xffff0000, 0xffff0000 + .long 0x3ffbc004, 0x3ffbc004, 0xffff0000, 0x00000000 + .long 0xffff0000, 0xffff0000, 0x3ffbc004, 0x3f9bc064 + .long 0x00000000, 0x00000000, 0x00000000, 0x00000000 + .long 0x00000000, 0x00000000, 0x00000000, 0x00000000 + .long 0x00000000, 0x00000000, 0x00000000, 0x00000000 + .long 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000 + .long 0xffff0000, 0xffff0000, 0x0000ffff, 0xffff0000 + .long 0xefff1000, 0xffff0000, 0xffff0000, 0xffff0000 + .long 0xefff1000, 0xefff1000, 0xffff0000, 0x00000000 + .long 0xffff0000, 0xffff0000, 0xefff1000, 0xffff0000 + .long 0x00000000, 0x00000000, 0x00000000, 0x00000000 + .long 0x00000000, 0x00000000, 0x00000000, 0x00000000 + .long 0x00000000, 0x50000000, 0x00000000, 0x00000000 +#endif +gpio_dump_end: + .p2align write_dumpreg: diff --git a/grub-core/bus/cs5536.c b/grub-core/bus/cs5536.c index 088f4dfc1..690b8f29a 100644 --- a/grub-core/bus/cs5536.c +++ b/grub-core/bus/cs5536.c @@ -213,26 +213,6 @@ grub_cs5536_read_spd (grub_port_t smbbase, grub_uint8_t dev, return GRUB_ERR_NONE; } -/* Dump of GPIO connections. FIXME: Remove useless and macroify. */ -static grub_uint32_t gpiodump[] = { - 0xffff0000, 0x2ffdd002, 0xffff0000, 0xffff0000, - 0x2fffd000, 0xffff0000, 0x1000efff, 0xefff1000, - 0x3ffbc004, 0xffff0000, 0xffff0000, 0xffff0000, - 0x3ffbc004, 0x3ffbc004, 0xffff0000, 0x00000000, - 0xffff0000, 0xffff0000, 0x3ffbc004, 0x3f9bc064, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000, - 0xffff0000, 0xffff0000, 0x0000ffff, 0xffff0000, - 0xefff1000, 0xffff0000, 0xffff0000, 0xffff0000, - 0xefff1000, 0xefff1000, 0xffff0000, 0x00000000, - 0xffff0000, 0xffff0000, 0xefff1000, 0xffff0000, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0x00000000, 0x50000000, 0x00000000, 0x00000000, -}; - static inline void set_io_space (grub_pci_device_t dev, int num, grub_uint16_t start, grub_uint16_t len) @@ -273,17 +253,6 @@ set_p2d (grub_pci_device_t dev, int num, int dest, grub_uint32_t start) void grub_cs5536_init_geode (grub_pci_device_t dev) { - int i; - - /* Make sure GPIO is where we expect it to be. */ - grub_cs5536_write_msr (dev, GRUB_CS5536_MSR_GPIO_BAR, - GRUB_CS5536_LBAR_TURN_ON | GRUB_CS5536_LBAR_GPIO); - - /* Setup GPIO. */ - for (i = 0; i < (int) ARRAY_SIZE (gpiodump); i++) - ((volatile grub_uint32_t *) (GRUB_MACHINE_PCI_IO_BASE - + GRUB_CS5536_LBAR_GPIO)) [i] = gpiodump[i]; - /* Enable more BARs. */ grub_cs5536_write_msr (dev, GRUB_CS5536_MSR_IRQ_MAP_BAR, GRUB_CS5536_LBAR_TURN_ON | GRUB_CS5536_LBAR_IRQ_MAP); From 5ea788ada075c32a171390c26d06e596eefd2412 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 24 Jan 2011 00:40:03 +0100 Subject: [PATCH 287/869] Geode UART2 (for Fuloong) fwstart.img support --- grub-core/boot/mips/yeeloong/fwstart.S | 42 +++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/grub-core/boot/mips/yeeloong/fwstart.S b/grub-core/boot/mips/yeeloong/fwstart.S index 41559ffa4..1a1a44c85 100644 --- a/grub-core/boot/mips/yeeloong/fwstart.S +++ b/grub-core/boot/mips/yeeloong/fwstart.S @@ -26,8 +26,13 @@ #include #include +#ifdef FULOONG +#define GRUB_MACHINE_SERIAL_PORT GRUB_MACHINE_SERIAL_PORT2 +#define GRUB_MACHINE_SERIAL_DIVISOR_115200 GRUB_MACHINE_SERIAL_PORT2_DIVISOR_115200 +#else #define GRUB_MACHINE_SERIAL_PORT GRUB_MACHINE_SERIAL_PORT0 #define GRUB_MACHINE_SERIAL_DIVISOR_115200 GRUB_MACHINE_SERIAL_PORT0_DIVISOR_115200 +#endif .set noreorder .set noat @@ -37,8 +42,14 @@ start: _start: __start: + /* Put serial init as soon as possible. But on Fuloong serial is past + Geode, so on Fuloong we need Geode first. + */ +#ifndef FULOONG bal serial_hw_init nop +#endif + /* Find CS5536 controller. */ /* $t4 chooses device in priority encoding. */ /* Resulting value is kept in GRUB_MACHINE_PCI_CONF_CTRL_REG. @@ -60,10 +71,12 @@ retry_cs5536: bnel $t2, $t3, 1b sll $t4, $t4, 1 +#ifndef FULOONG bal message addiu $a0, $a0, %lo(cs5536_found) bal printhex move $a0, $t4 +#endif lui $t0, %hi(GRUB_MACHINE_PCI_CONFSPACE) li $t1, GRUB_CS5536_MSR_MAILBOX_CONFIG_ENABLED @@ -81,6 +94,11 @@ retry_cs5536: bal gpio_init nop +#ifdef FULOONG + bal serial_hw_init + nop +#endif + /* Initialise SMBus controller. */ /* Set SMBUS LBAR. */ lui $a0, %hi(GRUB_CS5536_MSR_SMB_BAR) @@ -230,8 +248,29 @@ gpio_init: /* Same as similarly named C function but in asm since we need it early. */ - /* In: none. Out: none. Clobbered: $t0, $t1, $a0. */ + /* In: none. Out: none. Clobbered: $t0, $t1, $t2, $a0, $a1, $a2. */ serial_hw_init: + move $t2, $ra +#ifdef FULOONG + lui $a0, %hi(GRUB_CS5536_MSR_DIVIL_LEG_IO) + addiu $a0, $a0, %lo(GRUB_CS5536_MSR_DIVIL_LEG_IO) + li $a1, 0x04570003 + bal wrmsr + move $a2, $zero + + lui $a0, %hi(GRUB_CS5536_MSR_DIVIL_UART1_CONF) + addiu $a0, $a0, %lo(GRUB_CS5536_MSR_DIVIL_UART1_CONF) + li $a1, 2 + bal wrmsr + move $a2, $zero + + lui $a0, %hi(GRUB_CS5536_MSR_DIVIL_UART2_CONF) + addiu $a0, $a0, %lo(GRUB_CS5536_MSR_DIVIL_UART2_CONF) + li $a1, 2 + bal wrmsr + move $a2, $zero +#endif + lui $t0, %hi (GRUB_MACHINE_SERIAL_PORT) /* Turn off the interrupt. */ @@ -261,6 +300,7 @@ serial_hw_init: /* Let message return to original caller. */ lui $a0, %hi(notification_string) addiu $a0, $a0, %lo(notification_string) + move $ra, $t2 /* Print message on serial console. */ /* In: $a0 = asciiz message. Out: none. Clobbered: $t0, $t1, $a0. */ From c69ef8a0ab622769bc7ede5c45b36a38e2203035 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 24 Jan 2011 00:40:59 +0100 Subject: [PATCH 288/869] pass machine type from fwstart.S. Minor cleanup --- grub-core/boot/mips/yeeloong/fwstart.S | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/grub-core/boot/mips/yeeloong/fwstart.S b/grub-core/boot/mips/yeeloong/fwstart.S index 1a1a44c85..8c0963ba3 100644 --- a/grub-core/boot/mips/yeeloong/fwstart.S +++ b/grub-core/boot/mips/yeeloong/fwstart.S @@ -726,6 +726,10 @@ continue: lui $t0, %hi(cached_continue - 0x20000000) addiu $t0, $t0, %lo(cached_continue - 0x20000000) jr $t0 +#ifdef FULOONG + addiu $a2, $zero, -(1 + GRUB_ARCH_MACHINE_FULOONG) +#else addiu $a2, $zero, -(1 + GRUB_ARCH_MACHINE_YEELOONG) +#endif -cached_continue: \ No newline at end of file +cached_continue: From 9f7322f50e80df1cd67ffda5bbd148b6bcefcd80 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 24 Jan 2011 00:47:36 +0100 Subject: [PATCH 289/869] Add missing UART2 definitions --- include/grub/cs5536.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/grub/cs5536.h b/include/grub/cs5536.h index de0d6df7e..90a39df44 100644 --- a/include/grub/cs5536.h +++ b/include/grub/cs5536.h @@ -80,6 +80,8 @@ #define GRUB_CS5536_DIVIL_LPC_INTERRUPTS 0x1002 #define GRUB_CS5536_MSR_DIVIL_LPC_SERIAL_IRQ_CONTROL 0x8000004e #define GRUB_CS5536_MSR_DIVIL_LPC_SERIAL_IRQ_CONTROL_ENABLE 0x80 +#define GRUB_CS5536_MSR_DIVIL_UART1_CONF 0x8000003a +#define GRUB_CS5536_MSR_DIVIL_UART2_CONF 0x8000003e #define GRUB_CS5536_MSR_USB_OHCI_BASE 0x40000008 #define GRUB_CS5536_MSR_USB_EHCI_BASE 0x40000009 From 44626c910ec2a8a4ebea96b590a549610301735b Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 24 Jan 2011 01:45:11 +0100 Subject: [PATCH 290/869] Add fuloong registers for RAM controller --- grub-core/boot/mips/yeeloong/fwstart.S | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/grub-core/boot/mips/yeeloong/fwstart.S b/grub-core/boot/mips/yeeloong/fwstart.S index 8c0963ba3..995aa5071 100644 --- a/grub-core/boot/mips/yeeloong/fwstart.S +++ b/grub-core/boot/mips/yeeloong/fwstart.S @@ -465,14 +465,22 @@ regdump: .quad 0x0100020200010101 /* 4 */ .quad 0x0a04030603050203 /* 6 */ .quad 0x0f0e040000010a0b /* 7 */ +#ifdef FULOONG + .quad 0x0000000100000001 /* 8 */ +#else .quad 0x0000010200000102 /* 8 */ +#endif .quad 0x0000060c00000000 /* 9 */ .quad 0x2323233f3f1f0200 /* a */ .quad 0x5f7f232323232323 /* b */ .quad 0x002a3c0615000000 /* c */ .quad 0x002a002a002a002a /* d */ .quad 0x002a002a002a002a /* e */ +#ifdef FULOONG + .quad 0x00b40020005b0004 /* f */ +#else .quad 0x00b40020006d0004 /* f */ +#endif .quad 0x070007ff00000087 /* 10 */ .quad 0x000000000016101f /* 11 */ .quad 0x001c000000000000 /* 12 */ From 88906eaa69c3f117ef7416b225c33f6bdaf7a2c4 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 24 Jan 2011 01:46:00 +0100 Subject: [PATCH 291/869] Fix accidental disable of Geode UARTs --- grub-core/boot/mips/yeeloong/fwstart.S | 7 ++++++- grub-core/bus/cs5536.c | 25 ++++++++++++++++++++----- include/grub/cs5536.h | 2 ++ 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/grub-core/boot/mips/yeeloong/fwstart.S b/grub-core/boot/mips/yeeloong/fwstart.S index 995aa5071..d25ff1a5b 100644 --- a/grub-core/boot/mips/yeeloong/fwstart.S +++ b/grub-core/boot/mips/yeeloong/fwstart.S @@ -254,7 +254,12 @@ serial_hw_init: #ifdef FULOONG lui $a0, %hi(GRUB_CS5536_MSR_DIVIL_LEG_IO) addiu $a0, $a0, %lo(GRUB_CS5536_MSR_DIVIL_LEG_IO) - li $a1, 0x04570003 + li $a1, (GRUB_CS5536_MSR_DIVIL_LEG_IO_UART2_COM3 \ + | GRUB_CS5536_MSR_DIVIL_LEG_IO_F_REMAP \ + | GRUB_CS5536_MSR_DIVIL_LEG_IO_MODE_X86 \ + | GRUB_CS5536_MSR_DIVIL_LEG_IO_UART1_COM1 \ + | GRUB_CS5536_MSR_DIVIL_LEG_IO_RTC_ENABLE0 \ + | GRUB_CS5536_MSR_DIVIL_LEG_IO_RTC_ENABLE1) bal wrmsr move $a2, $zero diff --git a/grub-core/bus/cs5536.c b/grub-core/bus/cs5536.c index 690b8f29a..f5b2089e3 100644 --- a/grub-core/bus/cs5536.c +++ b/grub-core/bus/cs5536.c @@ -21,6 +21,7 @@ #include #include #include +#include int grub_cs5536_find (grub_pci_device_t *devp) @@ -264,11 +265,25 @@ grub_cs5536_init_geode (grub_pci_device_t dev) GRUB_CS5536_LBAR_TURN_ON | GRUB_CS5536_LBAR_PM); /* Setup DIVIL. */ - grub_cs5536_write_msr (dev, GRUB_CS5536_MSR_DIVIL_LEG_IO, - GRUB_CS5536_MSR_DIVIL_LEG_IO_MODE_X86 - | GRUB_CS5536_MSR_DIVIL_LEG_IO_F_REMAP - | GRUB_CS5536_MSR_DIVIL_LEG_IO_RTC_ENABLE0 - | GRUB_CS5536_MSR_DIVIL_LEG_IO_RTC_ENABLE1); + switch (grub_arch_machine) + { + case GRUB_ARCH_MACHINE_YEELOONG: + grub_cs5536_write_msr (dev, GRUB_CS5536_MSR_DIVIL_LEG_IO, + GRUB_CS5536_MSR_DIVIL_LEG_IO_MODE_X86 + | GRUB_CS5536_MSR_DIVIL_LEG_IO_F_REMAP + | GRUB_CS5536_MSR_DIVIL_LEG_IO_RTC_ENABLE0 + | GRUB_CS5536_MSR_DIVIL_LEG_IO_RTC_ENABLE1); + break; + case GRUB_ARCH_MACHINE_FULOONG: + grub_cs5536_write_msr (dev, GRUB_CS5536_MSR_DIVIL_LEG_IO, + GRUB_CS5536_MSR_DIVIL_LEG_IO_UART2_COM3 + | GRUB_CS5536_MSR_DIVIL_LEG_IO_UART1_COM1 + | GRUB_CS5536_MSR_DIVIL_LEG_IO_MODE_X86 + | GRUB_CS5536_MSR_DIVIL_LEG_IO_F_REMAP + | GRUB_CS5536_MSR_DIVIL_LEG_IO_RTC_ENABLE0 + | GRUB_CS5536_MSR_DIVIL_LEG_IO_RTC_ENABLE1); + break; + } grub_cs5536_write_msr (dev, GRUB_CS5536_MSR_DIVIL_IRQ_MAPPER_PRIMARY_MASK, (~GRUB_CS5536_DIVIL_LPC_INTERRUPTS) & 0xffff); grub_cs5536_write_msr (dev, GRUB_CS5536_MSR_DIVIL_IRQ_MAPPER_LPC_MASK, diff --git a/include/grub/cs5536.h b/include/grub/cs5536.h index 90a39df44..103b30633 100644 --- a/include/grub/cs5536.h +++ b/include/grub/cs5536.h @@ -75,6 +75,8 @@ #define GRUB_CS5536_MSR_DIVIL_LEG_IO_RTC_ENABLE1 0x00000002 #define GRUB_CS5536_MSR_DIVIL_LEG_IO_MODE_X86 0x10000000 #define GRUB_CS5536_MSR_DIVIL_LEG_IO_F_REMAP 0x04000000 +#define GRUB_CS5536_MSR_DIVIL_LEG_IO_UART1_COM1 0x00070000 +#define GRUB_CS5536_MSR_DIVIL_LEG_IO_UART2_COM3 0x00500000 #define GRUB_CS5536_MSR_DIVIL_IRQ_MAPPER_PRIMARY_MASK 0x80000024 #define GRUB_CS5536_MSR_DIVIL_IRQ_MAPPER_LPC_MASK 0x80000025 #define GRUB_CS5536_DIVIL_LPC_INTERRUPTS 0x1002 From dc1c21edb7be8bd892204981c31cd496f65e9a35 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 24 Jan 2011 01:49:25 +0100 Subject: [PATCH 292/869] Add informative #define --- grub-core/boot/mips/yeeloong/fwstart.S | 2 ++ 1 file changed, 2 insertions(+) diff --git a/grub-core/boot/mips/yeeloong/fwstart.S b/grub-core/boot/mips/yeeloong/fwstart.S index d25ff1a5b..41ed0063b 100644 --- a/grub-core/boot/mips/yeeloong/fwstart.S +++ b/grub-core/boot/mips/yeeloong/fwstart.S @@ -26,6 +26,8 @@ #include #include +/* #define FULOONG 1 */ + #ifdef FULOONG #define GRUB_MACHINE_SERIAL_PORT GRUB_MACHINE_SERIAL_PORT2 #define GRUB_MACHINE_SERIAL_DIVISOR_115200 GRUB_MACHINE_SERIAL_PORT2_DIVISOR_115200 From a9fa2a22d7f7e8f696c6cbca6103f3a62528c3a8 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 24 Jan 2011 02:20:04 +0100 Subject: [PATCH 293/869] Integrate Fuloong firmware port into build system and grub-mkimage --- grub-core/Makefile.core.def | 8 ++ grub-core/boot/mips/yeeloong/fuloong.S | 2 + grub-core/boot/mips/yeeloong/fwstart.S | 2 - util/grub-mkimage.c | 144 +++++++++++++++++-------- 4 files changed, 108 insertions(+), 48 deletions(-) create mode 100644 grub-core/boot/mips/yeeloong/fuloong.S diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def index a67c805c9..e651e1596 100644 --- a/grub-core/Makefile.core.def +++ b/grub-core/Makefile.core.def @@ -329,6 +329,14 @@ image = { enable = mips_yeeloong; }; +image = { + name = fwstart_fuloong; + mips_yeeloong = boot/mips/yeeloong/fuloong.S; + objcopyflags = '-O binary'; + ldflags = '-static-libgcc -lgcc -Wl,-N,-S,-Ttext,0xbfc00000,-Bstatic'; + enable = mips_yeeloong; +}; + module = { name = trig; common_nodist = trigtables.c; diff --git a/grub-core/boot/mips/yeeloong/fuloong.S b/grub-core/boot/mips/yeeloong/fuloong.S new file mode 100644 index 000000000..5df0d54c1 --- /dev/null +++ b/grub-core/boot/mips/yeeloong/fuloong.S @@ -0,0 +1,2 @@ +#define FULOONG 1 +#include "fwstart.S" diff --git a/grub-core/boot/mips/yeeloong/fwstart.S b/grub-core/boot/mips/yeeloong/fwstart.S index 41ed0063b..d25ff1a5b 100644 --- a/grub-core/boot/mips/yeeloong/fwstart.S +++ b/grub-core/boot/mips/yeeloong/fwstart.S @@ -26,8 +26,6 @@ #include #include -/* #define FULOONG 1 */ - #ifdef FULOONG #define GRUB_MACHINE_SERIAL_PORT GRUB_MACHINE_SERIAL_PORT2 #define GRUB_MACHINE_SERIAL_DIVISOR_115200 GRUB_MACHINE_SERIAL_PORT2_DIVISOR_115200 diff --git a/util/grub-mkimage.c b/util/grub-mkimage.c index 0375d3ed5..663e60f08 100644 --- a/util/grub-mkimage.c +++ b/util/grub-mkimage.c @@ -58,14 +58,15 @@ typedef enum { struct image_target_desc { - const char *name; + const char *dirname; + const char *names[6]; grub_size_t voidp_sizeof; int bigendian; enum { IMAGE_I386_PC, IMAGE_EFI, IMAGE_COREBOOT, IMAGE_SPARC64_AOUT, IMAGE_SPARC64_RAW, IMAGE_I386_IEEE1275, IMAGE_YEELOONG_ELF, IMAGE_QEMU, IMAGE_PPC, IMAGE_YEELOONG_FLASH, - IMAGE_I386_PC_PXE + IMAGE_FULOONG_FLASH, IMAGE_I386_PC_PXE } id; enum { @@ -92,7 +93,8 @@ struct image_target_desc struct image_target_desc image_targets[] = { { - .name = "i386-coreboot", + .dirname = "i386-coreboot", + .names = { "i386-coreboot", NULL }, .voidp_sizeof = 4, .bigendian = 0, .id = IMAGE_COREBOOT, @@ -114,7 +116,8 @@ struct image_target_desc image_targets[] = .mod_align = GRUB_KERNEL_I386_COREBOOT_MOD_ALIGN }, { - .name = "i386-multiboot", + .dirname = "i386-multiboot", + .names = { "i386-multiboot", NULL}, .voidp_sizeof = 4, .bigendian = 0, .id = IMAGE_COREBOOT, @@ -136,7 +139,8 @@ struct image_target_desc image_targets[] = .mod_align = GRUB_KERNEL_I386_COREBOOT_MOD_ALIGN }, { - .name = "i386-pc", + .dirname = "i386-pc", + .names = { "i386-pc", NULL }, .voidp_sizeof = 4, .bigendian = 0, .id = IMAGE_I386_PC, @@ -154,7 +158,8 @@ struct image_target_desc image_targets[] = .link_addr = GRUB_KERNEL_I386_PC_LINK_ADDR }, { - .name = "i386-pc-pxe", + .dirname = "i386-pc", + .names = { "i386-pc-pxe", NULL }, .voidp_sizeof = 4, .bigendian = 0, .id = IMAGE_I386_PC_PXE, @@ -172,7 +177,8 @@ struct image_target_desc image_targets[] = .link_addr = GRUB_KERNEL_I386_PC_LINK_ADDR }, { - .name = "i386-efi", + .dirname = "i386-efi", + .names = { "i386-efi", NULL }, .voidp_sizeof = 4, .bigendian = 0, .id = IMAGE_EFI, @@ -194,7 +200,8 @@ struct image_target_desc image_targets[] = .install_bsd_part = TARGET_NO_FIELD, }, { - .name = "i386-ieee1275", + .dirname = "i386-ieee1275", + .names = { "i386-ieee1275", NULL }, .voidp_sizeof = 4, .bigendian = 0, .id = IMAGE_I386_IEEE1275, @@ -216,7 +223,8 @@ struct image_target_desc image_targets[] = .link_align = 4, }, { - .name = "i386-qemu", + .dirname = "i386-qemu", + .names = { "i386-qemu", NULL }, .voidp_sizeof = 4, .bigendian = 0, .id = IMAGE_QEMU, @@ -234,7 +242,8 @@ struct image_target_desc image_targets[] = .link_addr = GRUB_KERNEL_I386_QEMU_LINK_ADDR }, { - .name = "x86_64-efi", + .dirname = "x86_64-efi", + .names = { "x86_64-efi", NULL }, .voidp_sizeof = 8, .bigendian = 0, .id = IMAGE_EFI, @@ -256,7 +265,8 @@ struct image_target_desc image_targets[] = .install_bsd_part = TARGET_NO_FIELD, }, { - .name = "mipsel-yeeloong-flash", + .dirname = "mipsel-yeeloong", + .names = { "mipsel-yeeloong-flash", NULL }, .voidp_sizeof = 4, .bigendian = 0, .id = IMAGE_YEELOONG_FLASH, @@ -277,7 +287,31 @@ struct image_target_desc image_targets[] = .default_compression = COMPRESSION_NONE }, { - .name = "mipsel-yeeloong-elf", + .dirname = "mipsel-yeeloong", + .names = { "mipsel-fuloong-flash", NULL }, + .voidp_sizeof = 4, + .bigendian = 0, + .id = IMAGE_FULOONG_FLASH, + .flags = PLATFORM_FLAGS_DECOMPRESSORS, + .prefix = GRUB_KERNEL_MIPS_YEELOONG_PREFIX, + .prefix_end = GRUB_KERNEL_MIPS_YEELOONG_PREFIX_END, + .raw_size = 0, + .total_module_size = GRUB_KERNEL_MIPS_YEELOONG_TOTAL_MODULE_SIZE, + .compressed_size = TARGET_NO_FIELD, + .kernel_image_size = TARGET_NO_FIELD, + .section_align = 1, + .vaddr_offset = 0, + .install_dos_part = TARGET_NO_FIELD, + .install_bsd_part = TARGET_NO_FIELD, + .link_addr = GRUB_KERNEL_MIPS_YEELOONG_LINK_ADDR, + .elf_target = EM_MIPS, + .link_align = GRUB_KERNEL_MIPS_YEELOONG_LINK_ALIGN, + .default_compression = COMPRESSION_NONE + }, + { + .dirname = "mipsel-yeeloong", + .names = { "mipsel-loongson-elf", "mipsel-yeeloong-elf", + "mipsel-fuloong-elf", NULL }, .voidp_sizeof = 4, .bigendian = 0, .id = IMAGE_YEELOONG_ELF, @@ -298,7 +332,8 @@ struct image_target_desc image_targets[] = .default_compression = COMPRESSION_NONE }, { - .name = "powerpc-ieee1275", + .dirname = "powerpc-ieee1275", + .names = { "powerpc-ieee1275", NULL }, .voidp_sizeof = 4, .bigendian = 1, .id = IMAGE_PPC, @@ -320,7 +355,8 @@ struct image_target_desc image_targets[] = .link_align = 4 }, { - .name = "sparc64-ieee1275-raw", + .dirname = "sparc64-ieee1275", + .names = { "sparc64-ieee1275-raw", NULL }, .voidp_sizeof = 8, .bigendian = 1, .id = IMAGE_SPARC64_RAW, @@ -338,7 +374,8 @@ struct image_target_desc image_targets[] = .link_addr = GRUB_KERNEL_SPARC64_IEEE1275_LINK_ADDR }, { - .name = "sparc64-ieee1275-aout", + .dirname = "sparc64-ieee1275", + .names = { "sparc64-ieee1275-aout", NULL }, .voidp_sizeof = 8, .bigendian = 1, .id = IMAGE_SPARC64_AOUT, @@ -1163,6 +1200,7 @@ generate_image (const char *dir, char *prefix, FILE *out, char *mods[], } break; case IMAGE_YEELOONG_FLASH: + case IMAGE_FULOONG_FLASH: { char *rom_img; size_t rom_size; @@ -1170,20 +1208,40 @@ generate_image (const char *dir, char *prefix, FILE *out, char *mods[], size_t boot_size; grub_uint8_t context[GRUB_MD_SHA512->contextsize]; /* fwstart.img is the only part which can't be testes by using *-elf - target. Check it against the checksum. This checksum is obtained with - sha512sum utility after compiling on Gnewsense. - */ - const grub_uint8_t fwstart_good_hash[] = - { 0x75, 0xbf, 0xa3, 0x0e, 0x7c, 0xd1, 0x03, 0x82, - 0xe1, 0x34, 0x55, 0xd7, 0x09, 0x1e, 0x6c, 0xcc, - 0xef, 0x08, 0x61, 0xc1, 0x3c, 0xd8, 0xc7, 0x9f, - 0xe8, 0x2d, 0x3d, 0xb2, 0xda, 0x41, 0xd3, 0x83, - 0xd7, 0xb8, 0xe3, 0xd7, 0x13, 0xec, 0x9b, 0xf6, - 0xf6, 0xae, 0x6b, 0x32, 0x29, 0xc1, 0x69, 0x82, - 0xfa, 0x65, 0x2d, 0x97, 0x3e, 0x83, 0x6e, 0x6c, - 0xce, 0x34, 0x10, 0x59, 0x74, 0x0e, 0x96, 0x26 }; - - boot_path = grub_util_get_path (dir, "fwstart.img"); + target. Check it against the checksum. */ + /* Wasn't retested after important changes. */ + const grub_uint8_t yeeloong_fwstart_good_hash[512 / 8] = + { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; + /* None yet. */ + const grub_uint8_t fuloong_fwstart_good_hash[512 / 8] = + { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + }; + const grub_uint8_t *fwstart_good_hash; + + if (image_target->id == IMAGE_FULOONG_FLASH) + { + fwstart_good_hash = fuloong_fwstart_good_hash; + boot_path = grub_util_get_path (dir, "fwstart_fuloong.img"); + } + else + { + fwstart_good_hash = yeeloong_fwstart_good_hash; + boot_path = grub_util_get_path (dir, "fwstart.img"); + } boot_size = grub_util_get_image_size (boot_path); boot_img = grub_util_read_image (boot_path); @@ -1403,12 +1461,12 @@ usage (int status) char *ptr; unsigned i; for (i = 0; i < ARRAY_SIZE (image_targets); i++) - format_len += strlen (image_targets[i].name) + 2; + format_len += strlen (image_targets[i].names[0]) + 2; ptr = formats = xmalloc (format_len); for (i = 0; i < ARRAY_SIZE (image_targets); i++) { - strcpy (ptr, image_targets[i].name); - ptr += strlen (image_targets[i].name); + strcpy (ptr, image_targets[i].names[0]); + ptr += strlen (image_targets[i].names[0]); *ptr++ = ','; *ptr++ = ' '; } @@ -1478,10 +1536,12 @@ main (int argc, char *argv[]) case 'O': { - unsigned i; + unsigned i, j; for (i = 0; i < ARRAY_SIZE (image_targets); i++) - if (strcmp (optarg, image_targets[i].name) == 0) - image_target = &image_targets[i]; + for (j = 0; image_targets[i].names[j] + && j < ARRAY_SIZE (image_targets[i].names); j++) + if (strcmp (optarg, image_targets[i].names[j]) == 0) + image_target = &image_targets[i]; if (!image_target) { printf ("unknown target format %s\n", optarg); @@ -1576,19 +1636,11 @@ main (int argc, char *argv[]) if (!dir) { - const char *last; - last = strchr (image_target->name, '-'); - if (last) - last = strchr (last + 1, '-'); - if (!last) - last = image_target->name + strlen (image_target->name); - dir = xmalloc (sizeof (GRUB_PKGLIBROOTDIR) + (last - image_target->name) - + 1); + dir = xmalloc (sizeof (GRUB_PKGLIBROOTDIR) + + grub_strlen (image_target->dirname) + 1); memcpy (dir, GRUB_PKGLIBROOTDIR, sizeof (GRUB_PKGLIBROOTDIR) - 1); *(dir + sizeof (GRUB_PKGLIBROOTDIR) - 1) = '/'; - memcpy (dir + sizeof (GRUB_PKGLIBROOTDIR), image_target->name, - last - image_target->name); - *(dir + sizeof (GRUB_PKGLIBROOTDIR) + (last - image_target->name)) = 0; + strcpy (dir + sizeof (GRUB_PKGLIBROOTDIR), image_target->dirname); } generate_image (dir, prefix ? : DEFAULT_DIRECTORY, fp, From 3281d3d6d43ac50dab55cbed9b337ac4d8e17dac Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 24 Jan 2011 02:44:27 +0100 Subject: [PATCH 294/869] * util/grub-mkimage.c (generate_image): Refuse to create the images bigger than the actual flash (512K) in Loongson machines. 512K is also the biggest chip supported by them. --- ChangeLog | 6 ++++++ util/grub-mkimage.c | 4 +++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index edb7d46f7..514ce4ef8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2011-01-24 Vladimir Serbinenko + + * util/grub-mkimage.c (generate_image): Refuse to create the images + bigger than the actual flash (512K) in Loongson machines. 512K is also + the biggest chip supported by them. + 2011-01-22 Vladimir Serbinenko * grub-core/kern/emu/getroot.c: Include config-util.h explicitly. diff --git a/util/grub-mkimage.c b/util/grub-mkimage.c index 0375d3ed5..876e9c9b2 100644 --- a/util/grub-mkimage.c +++ b/util/grub-mkimage.c @@ -1196,7 +1196,9 @@ generate_image (const char *dir, char *prefix, FILE *out, char *mods[], grub_util_warn ("fwstart.img doesn't match the known good version. " "Proceed at your own risk"); - rom_size = ALIGN_UP (core_size + boot_size, 512 * 1024); + if (core_size + boot_size > 512 * 1024) + grub_util_error ("firmware image is too big"); + rom_size = 512 * 1024; rom_img = xmalloc (rom_size); memset (rom_img, 0, rom_size); From 307ed0b484330ed600cb01e33f45f6a974aae7c1 Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Tue, 25 Jan 2011 12:28:11 +0000 Subject: [PATCH 295/869] remove unused variables --- grub-core/kern/emu/getroot.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/grub-core/kern/emu/getroot.c b/grub-core/kern/emu/getroot.c index 0035c734a..4f8a0e8a7 100644 --- a/grub-core/kern/emu/getroot.c +++ b/grub-core/kern/emu/getroot.c @@ -573,9 +573,8 @@ grub_util_is_lvm (const char *os_dev) { struct dm_tree *tree; uint32_t maj, min; - struct dm_tree_node *node = NULL, *child; - void *handle; - const char *node_uuid, *mapper_name = NULL, *child_uuid, *child_name; + struct dm_tree_node *node = NULL; + const char *node_uuid; struct stat st; if (stat (os_dev, &st) < 0) From 118fb264ee5e92e43a57a82a7a262a08a850b8b3 Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Tue, 25 Jan 2011 16:51:23 +0000 Subject: [PATCH 296/869] Support probing multipath disks. --- grub-core/kern/emu/hostdisk.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/grub-core/kern/emu/hostdisk.c b/grub-core/kern/emu/hostdisk.c index eb84d0220..ea42d945e 100644 --- a/grub-core/kern/emu/hostdisk.c +++ b/grub-core/kern/emu/hostdisk.c @@ -1271,6 +1271,16 @@ convert_system_partition_to_system_disk (const char *os_dev, struct stat *st) node = NULL; goto devmapper_out; } + if (strncmp (node_uuid, "mpath-", 6) == 0) + { + /* Multipath partitions have partN-mpath-* UUIDs, and are + linear mappings so are handled by + grub_util_get_dm_node_linear_info. Multipath disks are not + linear mappings and must be handled specially. */ + grub_dprintf ("hostdisk", "%s is a multipath disk\n", path); + mapper_name = dm_tree_node_get_name (node); + goto devmapper_out; + } if (strncmp (node_uuid, "DMRAID-", 7) != 0) { int major, minor; From 800f188183cf4d45bbd13eb94e1c2419888b76b2 Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Fri, 28 Jan 2011 17:01:28 +0000 Subject: [PATCH 297/869] * docs/grub.texi (Making a GRUB bootable CD-ROM): Update to describe grub-mkrescue. --- ChangeLog | 5 +++++ docs/grub.texi | 48 +++++++++++++++++++++++------------------------- 2 files changed, 28 insertions(+), 25 deletions(-) diff --git a/ChangeLog b/ChangeLog index 514ce4ef8..019a6746c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-01-28 Colin Watson + + * docs/grub.texi (Making a GRUB bootable CD-ROM): Update to describe + grub-mkrescue. + 2011-01-24 Vladimir Serbinenko * util/grub-mkimage.c (generate_image): Refuse to create the images diff --git a/docs/grub.texi b/docs/grub.texi index a47389f1e..c815bcbbe 100644 --- a/docs/grub.texi +++ b/docs/grub.texi @@ -651,15 +651,22 @@ using BIOS functions.}. This means that you can use the whole CD-ROM from GRUB and you don't have to make a floppy or hard disk image file, which can cause compatibility problems. -For booting from a CD-ROM, GRUB uses a special Stage 2 called -@file{stage2_eltorito}. The only GRUB files you need to have in your -bootable CD-ROM are this @file{stage2_eltorito} and optionally a config file -@file{grub.cfg}. You don't need to use @file{stage1} or @file{stage2}, -because El Torito is quite different from the standard boot process. +For booting from a CD-ROM, GRUB uses a special image called +@file{cdboot.img}, which is concatenated with @file{core.img}. The +@file{core.img} used for this should be built with at least the +@samp{iso9660} and @samp{biosdisk} modules. Your bootable CD-ROM will +usually also need to include a configuration file @file{grub.cfg} and some +other GRUB modules. -Here is an example of procedures to make a bootable CD-ROM -image. First, make a top directory for the bootable image, say, -@samp{iso}: +To make a simple generic GRUB rescue CD, you can use the +@command{grub-mkrescue} program: + +@example +$ @kbd{grub-mkrescue -o grub.iso} +@end example + +You will often need to include other files in your image. To do this, first +make a top directory for the bootable image, say, @samp{iso}: @example $ @kbd{mkdir iso} @@ -671,33 +678,24 @@ Make a directory for GRUB: $ @kbd{mkdir -p iso/boot/grub} @end example -Copy the file @file{stage2_eltorito}: - -@example -$ @kbd{cp /usr/lib/grub/i386-pc/stage2_eltorito iso/boot/grub} -@end example - If desired, make the config file @file{grub.cfg} under @file{iso/boot/grub} (@pxref{Configuration}), and copy any files and directories for the disc to the directory @file{iso/}. -Finally, make a ISO9660 image file like this: +Finally, make the image: @example -$ @kbd{mkisofs -R -b boot/grub/stage2_eltorito -no-emul-boot \ - -boot-load-size 4 -boot-info-table -o grub.iso iso} +$ @kbd{grub-mkrescue -o grub.iso iso} @end example This produces a file named @file{grub.iso}, which then can be burned -into a CD (or a DVD). @kbd{mkisofs} has already set up the disc to boot -from the @kbd{boot/grub/stage2_eltorito} file, so there is no need to -setup GRUB on the disc. (Note that the @kbd{-boot-load-size 4} bit is -required for compatibility with the BIOS on many older machines.) +into a CD (or a DVD), or written to a USB mass storage device. -You can use the device @samp{(cd)} to access a CD-ROM in your -config file. This is not required; GRUB automatically sets the root device -to @samp{(cd)} when booted from a CD-ROM. It is only necessary to refer to -@samp{(cd)} if you want to access other drives as well. +The root device will be set up appropriately on entering your +@file{grub.cfg} configuration file, so you can refer to file names on the CD +without needing to use an explicit device name. This makes it easier to +produce rescue images that will work on both optical drives and USB mass +storage devices. @node Device map From 8c2c4ff2f533cf37c2025655497f3dfc8cfd5eef Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Fri, 4 Feb 2011 13:33:16 +0000 Subject: [PATCH 298/869] Handle empty dir passed to grub_find_root_device_from_mountinfo; fixes grub-mkrelpath on btrfs subvolumes. --- grub-core/kern/emu/getroot.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/grub-core/kern/emu/getroot.c b/grub-core/kern/emu/getroot.c index 92ff971e5..c1ed35b2d 100644 --- a/grub-core/kern/emu/getroot.c +++ b/grub-core/kern/emu/getroot.c @@ -111,6 +111,8 @@ grub_find_root_device_from_mountinfo (const char *dir, char **relroot) size_t len = 0; char *ret = NULL; + if (! *dir) + dir = "/"; if (relroot) *relroot = NULL; From 5870a4a06f11059defad9ff546b7b2811a838873 Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Fri, 4 Feb 2011 16:35:07 +0000 Subject: [PATCH 299/869] typo --- grub-core/fs/btrfs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/grub-core/fs/btrfs.c b/grub-core/fs/btrfs.c index b7c59065c..ac90c055a 100644 --- a/grub-core/fs/btrfs.c +++ b/grub-core/fs/btrfs.c @@ -729,7 +729,7 @@ grub_btrfs_read_logical (struct grub_btrfs_data *data, grub_disk_addr_t paddr; stripe = (struct grub_btrfs_chunk_stripe *) (chunk + 1); - /* Right now the redundancy handlind is easy. + /* Right now the redundancy handling is easy. With RAID5-like it will be more difficult. */ stripe += stripen + i; From 7e735e4349c2c408dd5420882ed206d8d34d78ce Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Tue, 8 Feb 2011 13:21:13 +0000 Subject: [PATCH 300/869] * include/grub/file.h (not_easly_seekable): Rename to ... (not_easily_seekable): ... this. Update all users. --- ChangeLog | 5 +++++ grub-core/fs/i386/pc/pxe.c | 2 +- grub-core/io/bufio.c | 2 +- grub-core/io/gzio.c | 2 +- grub-core/io/xzio.c | 2 +- include/grub/file.h | 6 +++--- 6 files changed, 12 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index 019a6746c..d3325ac6b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-02-08 Colin Watson + + * include/grub/file.h (not_easly_seekable): Rename to ... + (not_easily_seekable): ... this. Update all users. + 2011-01-28 Colin Watson * docs/grub.texi (Making a GRUB bootable CD-ROM): Update to describe diff --git a/grub-core/fs/i386/pc/pxe.c b/grub-core/fs/i386/pc/pxe.c index e2b53d637..a3b055f3d 100644 --- a/grub-core/fs/i386/pc/pxe.c +++ b/grub-core/fs/i386/pc/pxe.c @@ -281,7 +281,7 @@ grub_pxefs_open (struct grub_file *file, const char *name) } file->data = data; - file->not_easly_seekable = 1; + file->not_easily_seekable = 1; grub_memcpy (file_int, file, sizeof (struct grub_file)); curr_file = file_int; diff --git a/grub-core/io/bufio.c b/grub-core/io/bufio.c index 8a72ecd79..891fb78e9 100644 --- a/grub-core/io/bufio.c +++ b/grub-core/io/bufio.c @@ -74,7 +74,7 @@ grub_bufio_open (grub_file_t io, int size) file->data = bufio; file->read_hook = 0; file->fs = &grub_bufio_fs; - file->not_easly_seekable = io->not_easly_seekable; + file->not_easily_seekable = io->not_easily_seekable; return file; } diff --git a/grub-core/io/gzio.c b/grub-core/io/gzio.c index f563d7b92..47df23833 100644 --- a/grub-core/io/gzio.c +++ b/grub-core/io/gzio.c @@ -1136,7 +1136,7 @@ grub_gzio_open (grub_file_t io) file->data = gzio; file->read_hook = 0; file->fs = &grub_gzio_fs; - file->not_easly_seekable = 1; + file->not_easily_seekable = 1; if (! test_header (file)) { diff --git a/grub-core/io/xzio.c b/grub-core/io/xzio.c index 37be1790f..3daf6a3fe 100644 --- a/grub-core/io/xzio.c +++ b/grub-core/io/xzio.c @@ -200,7 +200,7 @@ grub_xzio_open (grub_file_t io) file->read_hook = 0; file->fs = &grub_xzio_fs; file->size = GRUB_FILE_SIZE_UNKNOWN; - file->not_easly_seekable = 1; + file->not_easily_seekable = 1; if (grub_file_tell (xzio->file) != 0) grub_file_seek (xzio->file, 0); diff --git a/include/grub/file.h b/include/grub/file.h index 72cd45468..3adb1706f 100644 --- a/include/grub/file.h +++ b/include/grub/file.h @@ -39,8 +39,8 @@ struct grub_file /* The file size. */ grub_off_t size; - /* If file is not easly seekable. Should be set by underlying layer. */ - int not_easly_seekable; + /* If file is not easily seekable. Should be set by underlying layer. */ + int not_easily_seekable; /* Filesystem-specific data. */ void *data; @@ -123,7 +123,7 @@ grub_file_tell (const grub_file_t file) static inline int grub_file_seekable (const grub_file_t file) { - return !file->not_easly_seekable; + return !file->not_easily_seekable; } #endif /* ! GRUB_FILE_HEADER */ From 22b28eb3fe78a38e1be478d70bd8da1a75f784de Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Wed, 9 Feb 2011 11:23:11 +0000 Subject: [PATCH 301/869] * util/grub-install.in: Remove unnecessary brackets from tr arguments. * util/grub.d/10_hurd.in: Likewise. * util/grub.d/10_kfreebsd.in: Likewise. * util/grub.d/10_linux.in: Likewise. * util/grub.d/20_linux_xen.in: Likewise. Reported by: Jamie Heilman. Fixes Debian bug #612564. --- ChangeLog | 10 ++++++++++ util/grub-install.in | 2 +- util/grub.d/10_hurd.in | 2 +- util/grub.d/10_kfreebsd.in | 2 +- util/grub.d/10_linux.in | 2 +- util/grub.d/20_linux_xen.in | 2 +- 6 files changed, 15 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index d3325ac6b..6517450ce 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2011-02-09 Colin Watson + + * util/grub-install.in: Remove unnecessary brackets from tr + arguments. + * util/grub.d/10_hurd.in: Likewise. + * util/grub.d/10_kfreebsd.in: Likewise. + * util/grub.d/10_linux.in: Likewise. + * util/grub.d/20_linux_xen.in: Likewise. + Reported by: Jamie Heilman. Fixes Debian bug #612564. + 2011-02-08 Colin Watson * include/grub/file.h (not_easly_seekable): Rename to ... diff --git a/util/grub-install.in b/util/grub-install.in index 1ae00b2fd..af3034e03 100644 --- a/util/grub-install.in +++ b/util/grub-install.in @@ -64,7 +64,7 @@ if test -f "${sysconfdir}/default/grub" ; then . "${sysconfdir}/default/grub" fi -bootloader_id="$(echo "$GRUB_DISTRIBUTOR" | tr '[A-Z]' '[a-z]' | cut -d' ' -f1)" +bootloader_id="$(echo "$GRUB_DISTRIBUTOR" | tr 'A-Z' 'a-z' | cut -d' ' -f1)" if test -z "$bootloader_id"; then bootloader_id=grub fi diff --git a/util/grub.d/10_hurd.in b/util/grub.d/10_hurd.in index eeb441aa4..8c54eab97 100644 --- a/util/grub.d/10_hurd.in +++ b/util/grub.d/10_hurd.in @@ -28,7 +28,7 @@ if [ "x${GRUB_DISTRIBUTOR}" = "x" ] ; then OS=GNU else OS="${GRUB_DISTRIBUTOR} GNU/Hurd" - CLASS="--class $(echo ${GRUB_DISTRIBUTOR} | tr '[A-Z]' '[a-z]' | cut -d' ' -f1) ${CLASS}" + CLASS="--class $(echo ${GRUB_DISTRIBUTOR} | tr 'A-Z' 'a-z' | cut -d' ' -f1) ${CLASS}" fi at_least_one=false diff --git a/util/grub.d/10_kfreebsd.in b/util/grub.d/10_kfreebsd.in index b026812a7..dce5e945c 100644 --- a/util/grub.d/10_kfreebsd.in +++ b/util/grub.d/10_kfreebsd.in @@ -31,7 +31,7 @@ CLASS="--class os" case "${GRUB_DISTRIBUTOR}" in Debian) OS="${GRUB_DISTRIBUTOR} GNU/kFreeBSD" - CLASS="--class $(echo ${GRUB_DISTRIBUTOR} | tr '[A-Z]' '[a-z]' | cut -d' ' -f1) --class gnu-kfreebsd --class gnu ${CLASS}" + CLASS="--class $(echo ${GRUB_DISTRIBUTOR} | tr 'A-Z' 'a-z' | cut -d' ' -f1) --class gnu-kfreebsd --class gnu ${CLASS}" ;; *) OS="FreeBSD" diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in index a09c3e687..491d2b5ce 100644 --- a/util/grub.d/10_linux.in +++ b/util/grub.d/10_linux.in @@ -32,7 +32,7 @@ if [ "x${GRUB_DISTRIBUTOR}" = "x" ] ; then OS=GNU/Linux else OS="${GRUB_DISTRIBUTOR} GNU/Linux" - CLASS="--class $(echo ${GRUB_DISTRIBUTOR} | tr '[A-Z]' '[a-z]' | cut -d' ' -f1) ${CLASS}" + CLASS="--class $(echo ${GRUB_DISTRIBUTOR} | tr 'A-Z' 'a-z' | cut -d' ' -f1) ${CLASS}" fi # loop-AES arranges things so that /dev/loop/X can be our root device, but diff --git a/util/grub.d/20_linux_xen.in b/util/grub.d/20_linux_xen.in index ee49cd903..356219e1d 100644 --- a/util/grub.d/20_linux_xen.in +++ b/util/grub.d/20_linux_xen.in @@ -32,7 +32,7 @@ if [ "x${GRUB_DISTRIBUTOR}" = "x" ] ; then OS=GNU/Linux else OS="${GRUB_DISTRIBUTOR} GNU/Linux" - CLASS="--class $(echo ${GRUB_DISTRIBUTOR} | tr '[A-Z]' '[a-z]' | cut -d' ' -f1) ${CLASS}" + CLASS="--class $(echo ${GRUB_DISTRIBUTOR} | tr 'A-Z' 'a-z' | cut -d' ' -f1) ${CLASS}" fi # loop-AES arranges things so that /dev/loop/X can be our root device, but From 97286eb54770ce840063ee0740c4a4923aaa28de Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Wed, 9 Feb 2011 12:14:10 +0000 Subject: [PATCH 302/869] * docs/grub.texi (Kernel): Add reference to grub-mkrescue. (Making a GRUB bootable CD-ROM): Likewise. (Invoking grub-mkrescue): New section. Reported by: Yann Dirson. Fixes Debian bug #612585. --- ChangeLog | 7 ++++++ docs/grub.texi | 62 +++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 68 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 6517450ce..56498af1b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2011-02-09 Colin Watson + + * docs/grub.texi (Kernel): Add reference to grub-mkrescue. + (Making a GRUB bootable CD-ROM): Likewise. + (Invoking grub-mkrescue): New section. + Reported by: Yann Dirson. Fixes Debian bug #612585. + 2011-02-09 Colin Watson * util/grub-install.in: Remove unnecessary brackets from tr diff --git a/docs/grub.texi b/docs/grub.texi index c815bcbbe..590e6afb7 100644 --- a/docs/grub.texi +++ b/docs/grub.texi @@ -36,6 +36,7 @@ Invariant Sections. * grub-install: (grub)Invoking grub-install. Install GRUB on your drive * grub-mkconfig: (grub)Invoking grub-mkconfig. Generate GRUB configuration * grub-mkpasswd-pbkdf2: (grub)Invoking grub-mkpasswd-pbkdf2. +* grub-mkrescue: (grub)Invoking grub-mkrescue. Make a GRUB rescue image @end direntry @setchapternewpage odd @@ -94,6 +95,7 @@ This edition documents version @value{VERSION}. * Invoking grub-mkconfig:: Generate a GRUB configuration file * Invoking grub-mkpasswd-pbkdf2:: Generate GRUB password hashes +* Invoking grub-mkrescue:: Make a GRUB rescue image * Obtaining and Building GRUB:: How to obtain and build GRUB * Reporting bugs:: Where you should send a bug report * Future:: Some future plans on GRUB @@ -659,7 +661,7 @@ usually also need to include a configuration file @file{grub.cfg} and some other GRUB modules. To make a simple generic GRUB rescue CD, you can use the -@command{grub-mkrescue} program: +@command{grub-mkrescue} program (@pxref{Invoking grub-mkrescue}): @example $ @kbd{grub-mkrescue -o grub.iso} @@ -3609,6 +3611,64 @@ Length of the salt. Defaults to 64. @end table +@node Invoking grub-mkrescue +@chapter Invoking grub-mkrescue + +The program @command{grub-mkrescue} generates a bootable GRUB rescue image +(@pxref{Making a GRUB bootable CD-ROM}). + +@example +grub-mkrescue -o grub.iso +@end example + +All arguments not explicitly listed as @command{grub-mkrescue} options are +passed on directly to @command{xorriso} in @command{mkisofs} emulation mode. +Options passed to @command{xorriso} will normally be interpreted as +@command{mkisofs} options; if the option @samp{--} is used, then anything +after that will be interpreted as native @command{xorriso} options. + +Non-option arguments specify additional source directories. This is +commonly used to add extra files to the image: + +@example +mkdir -p disk/boot/grub +@r{(add extra files to @file{disk/boot/grub})} +grub-mkrescue -o grub.iso disk +@end example + +@command{grub-mkrescue} accepts the following options: + +@table @option +@item --help +Print a summary of the command-line options and exit. + +@item --version +Print the version number of GRUB and exit. + +@item -o @var{file} +@itemx --output=@var{file} +Save output in @var{file}. This "option" is required. + +@item --modules=@var{modules} +Pre-load the named GRUB modules in the image. Multiple entries in +@var{modules} should be separated by whitespace (so you will probably need +to quote this for your shell). + +@item --rom-directory=@var{dir} +If generating images for the QEMU or Coreboot platforms, copy the resulting +@file{qemu.img} or @file{coreboot.elf} files respectively to the @var{dir} +directory as well as including them in the image. + +@item --xorriso=@var{file} +Use @var{file} as the @command{xorriso} program, rather than the built-in +default. + +@item --grub-mkimage=@var{file} +Use @var{file} as the @command{grub-mkimage} program, rather than the +built-in default. +@end table + + @node Obtaining and Building GRUB @appendix How to obtain and build GRUB From fee7cdd4e1bdc0618e01307477e5c115ee76a6dc Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Fri, 11 Feb 2011 13:00:54 +0000 Subject: [PATCH 303/869] * util/grub.d/20_linux_xen.in: Bail out early if linux_list is empty, since in that case we can only generate either nothing or a syntactically invalid configuration file. Reported by: Michal Suchanek. Fixes Debian bug #612898. --- ChangeLog | 7 +++++++ util/grub.d/20_linux_xen.in | 3 +++ 2 files changed, 10 insertions(+) diff --git a/ChangeLog b/ChangeLog index 56498af1b..6e9ab5758 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2011-02-11 Colin Watson + + * util/grub.d/20_linux_xen.in: Bail out early if linux_list is + empty, since in that case we can only generate either nothing or a + syntactically invalid configuration file. + Reported by: Michal Suchanek. Fixes Debian bug #612898. + 2011-02-09 Colin Watson * docs/grub.texi (Kernel): Add reference to grub-mkrescue. diff --git a/util/grub.d/20_linux_xen.in b/util/grub.d/20_linux_xen.in index 356219e1d..e71fc1458 100644 --- a/util/grub.d/20_linux_xen.in +++ b/util/grub.d/20_linux_xen.in @@ -98,6 +98,9 @@ linux_list=`for i in /boot/vmlinu[xz]-* /vmlinu[xz]-* ; do version=$(echo $basename | sed -e "s,^[^0-9]*-,,g") if grub_file_is_not_garbage "$i" && grep -qx "CONFIG_XEN_DOM0=y" /boot/config-${version} 2> /dev/null ; then echo -n "$i " ; fi done` +if [ "x${linux_list}" = "x" ] ; then + exit 0 +fi xen_list=`for i in /boot/xen*; do if grub_file_is_not_garbage "$i" ; then echo -n "$i " ; fi done` From d998657dcf8be2a6d4e93f004519e63b66af22cd Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 12 Feb 2011 09:59:04 +0300 Subject: [PATCH 304/869] * grub-core/partmap/msdos.c (pc_partition_map_embed): Fix off by one error. --- ChangeLog | 5 +++++ grub-core/partmap/msdos.c | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 6e9ab5758..3a695b25a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-02-12 Vladimir Serbinenko + + * grub-core/partmap/msdos.c (pc_partition_map_embed): Fix off by one + error. + 2011-02-11 Colin Watson * util/grub.d/20_linux_xen.in: Bail out early if linux_list is diff --git a/grub-core/partmap/msdos.c b/grub-core/partmap/msdos.c index d411c4405..31a0a0707 100644 --- a/grub-core/partmap/msdos.c +++ b/grub-core/partmap/msdos.c @@ -232,10 +232,10 @@ pc_partition_map_embed (struct grub_disk *disk, unsigned int *nsectors, break; } - if (end >= *nsectors + 1) + if (end >= *nsectors + 2) { unsigned i; - *nsectors = end - 1; + *nsectors = end - 2; *sectors = grub_malloc (*nsectors * sizeof (**sectors)); if (!*sectors) return grub_errno; From 028501a0e06877f14e2445f73a8969bced63c10f Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 12 Feb 2011 10:22:55 +0300 Subject: [PATCH 305/869] Workaround yet another IEEE1275 bug. * include/grub/ieee1275/ieee1275.h (grub_ieee1275_flag): New enum value GRUB_IEEE1275_FLAG_BROKEN_ADDRESS_CELLS. * grub-core/kern/ieee1275/mmap.c (grub_machine_mmap_iterate): Ignore adress_cells and size:cells if GRUB_IEEE1275_FLAG_BROKEN_ADDRESS_CELLS is set. * grub-core/kern/ieee1275/cmain.c (grub_ieee1275_find_options): Set GRUB_IEEE1275_FLAG_BROKEN_ADDRESS_CELLS on powermacs. --- ChangeLog | 12 ++++++++++++ grub-core/kern/ieee1275/cmain.c | 3 +++ grub-core/kern/ieee1275/mmap.c | 6 ++++++ include/grub/ieee1275/ieee1275.h | 6 ++++++ 4 files changed, 27 insertions(+) diff --git a/ChangeLog b/ChangeLog index 3a695b25a..72d718b08 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2011-02-12 Vladimir Serbinenko + + Workaround yet another IEEE1275 bug. + + * include/grub/ieee1275/ieee1275.h (grub_ieee1275_flag): New enum value + GRUB_IEEE1275_FLAG_BROKEN_ADDRESS_CELLS. + * grub-core/kern/ieee1275/mmap.c (grub_machine_mmap_iterate): Ignore + adress_cells and size:cells if GRUB_IEEE1275_FLAG_BROKEN_ADDRESS_CELLS + is set. + * grub-core/kern/ieee1275/cmain.c (grub_ieee1275_find_options): Set + GRUB_IEEE1275_FLAG_BROKEN_ADDRESS_CELLS on powermacs. + 2011-02-12 Vladimir Serbinenko * grub-core/partmap/msdos.c (pc_partition_map_embed): Fix off by one diff --git a/grub-core/kern/ieee1275/cmain.c b/grub-core/kern/ieee1275/cmain.c index 30eacbbdd..2fbe809b2 100644 --- a/grub-core/kern/ieee1275/cmain.c +++ b/grub-core/kern/ieee1275/cmain.c @@ -84,6 +84,9 @@ grub_ieee1275_find_options (void) if (rc >= 0 && !grub_strcmp (tmp, "Emulated PC")) is_qemu = 1; + if (grub_strncmp (tmp, "PowerMac", sizeof ("PowerMac") - 1) == 0) + grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_BROKEN_ADDRESS_CELLS); + if (is_smartfirmware) { /* Broken in all versions */ diff --git a/grub-core/kern/ieee1275/mmap.c b/grub-core/kern/ieee1275/mmap.c index 942e5a354..2e4e085bb 100644 --- a/grub-core/kern/ieee1275/mmap.c +++ b/grub-core/kern/ieee1275/mmap.c @@ -50,6 +50,12 @@ grub_machine_mmap_iterate (grub_memory_hook_t hook) return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "couldn't examine /memory/available property"); + if (grub_ieee1275_test_flag (GRUB_IEEE1275_FLAG_BROKEN_ADDRESS_CELLS)) + { + address_cells = 1; + size_cells = 1; + } + /* Decode each entry and call `hook'. */ i = 0; available_size /= sizeof (grub_uint32_t); diff --git a/include/grub/ieee1275/ieee1275.h b/include/grub/ieee1275/ieee1275.h index 2592dd348..4c56cc20f 100644 --- a/include/grub/ieee1275/ieee1275.h +++ b/include/grub/ieee1275/ieee1275.h @@ -106,6 +106,12 @@ enum grub_ieee1275_flag /* OLPC / XO firmware has the cursor ON/OFF routines. */ GRUB_IEEE1275_FLAG_HAS_CURSORONOFF, + + /* Some PowerMacs claim to use 2 address cells but in fact use only 1. + Other PowerMacs claim to use only 1 and really do so. Always assume + 1 address cell is used on PowerMacs. + */ + GRUB_IEEE1275_FLAG_BROKEN_ADDRESS_CELLS, }; extern int EXPORT_FUNC(grub_ieee1275_test_flag) (enum grub_ieee1275_flag flag); From 54da1febceee8e07edf6b58f31952648897ba689 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 19 Feb 2011 13:18:05 +0100 Subject: [PATCH 306/869] Rename mipsel-yeeloong to mipsel-loongson --- conf/Makefile.common | 2 +- configure.ac | 16 +++--- gentpl.py | 12 ++-- grub-core/Makefile.am | 2 +- grub-core/Makefile.core.def | 50 ++++++++--------- .../mips/{yeeloong => loongson}/fuloong.S | 0 .../mips/{yeeloong => loongson}/fwstart.S | 6 +- grub-core/boot/mips/startup_raw.S | 2 +- grub-core/bus/pci.c | 12 ++-- .../mips/{yeeloong => loongson}/lsspd.c | 0 grub-core/kern/main.c | 4 +- .../kern/mips/{yeeloong => loongson}/init.c | 6 +- grub-core/kern/mips/startup.S | 6 +- grub-core/loader/mips/linux.c | 8 +-- .../mips/{yeeloong => loongson}/uppermem.c | 0 grub-core/term/at_keyboard.c | 4 +- grub-core/term/ns8250.c | 8 +-- grub-core/term/serial.c | 4 +- .../mips/{yeeloong => loongson}/at_keyboard.h | 0 .../grub/mips/{yeeloong => loongson}/cmos.h | 0 include/grub/mips/{yeeloong => loongson}/ec.h | 0 .../grub/mips/{yeeloong => loongson}/kernel.h | 0 .../grub/mips/{yeeloong => loongson}/memory.h | 0 .../grub/mips/{yeeloong => loongson}/pci.h | 8 +-- .../grub/mips/{yeeloong => loongson}/serial.h | 0 .../grub/mips/{yeeloong => loongson}/time.h | 0 include/grub/offsets.h | 16 +++--- include/grub/serial.h | 2 +- util/grub-install.in | 6 +- util/grub-mkimage.c | 56 +++++++++---------- 30 files changed, 116 insertions(+), 114 deletions(-) rename grub-core/boot/mips/{yeeloong => loongson}/fuloong.S (100%) rename grub-core/boot/mips/{yeeloong => loongson}/fwstart.S (99%) rename grub-core/commands/mips/{yeeloong => loongson}/lsspd.c (100%) rename grub-core/kern/mips/{yeeloong => loongson}/init.c (98%) rename grub-core/mmap/mips/{yeeloong => loongson}/uppermem.c (100%) rename include/grub/mips/{yeeloong => loongson}/at_keyboard.h (100%) rename include/grub/mips/{yeeloong => loongson}/cmos.h (100%) rename include/grub/mips/{yeeloong => loongson}/ec.h (100%) rename include/grub/mips/{yeeloong => loongson}/kernel.h (100%) rename include/grub/mips/{yeeloong => loongson}/memory.h (100%) rename include/grub/mips/{yeeloong => loongson}/pci.h (95%) rename include/grub/mips/{yeeloong => loongson}/serial.h (100%) rename include/grub/mips/{yeeloong => loongson}/time.h (100%) diff --git a/conf/Makefile.common b/conf/Makefile.common index 32ca76d08..2c08d4df9 100644 --- a/conf/Makefile.common +++ b/conf/Makefile.common @@ -21,7 +21,7 @@ endif if COND_i386_ieee1275 CFLAGS_PLATFORM += -mrtd -mregparm=3 endif -if COND_mips_yeeloong +if COND_mips_loongson CFLAGS_PLATFORM += -mexplicit-relocs CPPFLAGS_PLATFORM = -DUSE_ASCII_FAILBACK CCASFLAGS_PLATFORM = -march=mips3 diff --git a/configure.ac b/configure.ac index c660ac41e..64d6daf2b 100644 --- a/configure.ac +++ b/configure.ac @@ -96,7 +96,7 @@ if test "x$with_platform" = x; then powerpc-*) platform=ieee1275 ;; powerpc64-*) platform=ieee1275 ;; sparc64-*) platform=ieee1275 ;; - mips-*) platform=yeeloong ;; + mips-*) platform=loongson ;; *) AC_MSG_ERROR([unsupported CPU: "$target_cpu"]) ;; esac else @@ -123,7 +123,9 @@ case "$target_cpu"-"$platform" in powerpc-ieee1275) ;; sparc64-ieee1275) ;; mips-qemu-mips) ;; - mips-yeeloong) ;; + mips-yeeloong) platform=loongson ;; + mips-fuloong) platform=loongson ;; + mips-loongson) ;; *-emu) ;; *) AC_MSG_ERROR([platform "$platform" is not supported for target CPU "$target_cpu"]) ;; esac @@ -156,7 +158,7 @@ case "$platform" in qemu) machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_MACHINE_QEMU=1" ;; pc) machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_MACHINE_PCBIOS=1" ;; emu) machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_MACHINE_EMU=1" ;; - yeeloong) machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_MACHINE_MIPS_YEELOONG=1 -DGRUB_MACHINE_MIPS_BONITO=1" ;; + loongson) machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_MACHINE_MIPS_LOONGSON=1 -DGRUB_MACHINE_MIPS_BONITO=1" ;; qemu-mips) machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_MACHINE_MIPS_QEMU_MIPS=1 -DGRUB_MACHINE_MIPS_BONITO=1" ;; esac case "$target_cpu" in @@ -219,8 +221,8 @@ for ext in pcf pcf.gz bdf bdf.gz ttf ttf.gz; do done done -if test "x$FONT_SOURCE" = x && ( test "x$platform" = xqemu || test "x$platform" = xyeeloong ); then - AC_MSG_ERROR([qemu and yeeloong ports need unifont]) +if test "x$FONT_SOURCE" = x && ( test "x$platform" = xqemu || test "x$platform" = xloongson ); then + AC_MSG_ERROR([qemu and loongson ports need unifont]) fi AC_SUBST([FONT_SOURCE]) @@ -398,7 +400,7 @@ if test "x$grub_cv_cc_fno_dwarf2_cfi_asm" = xyes; then TARGET_CFLAGS="$TARGET_CFLAGS -fno-dwarf2-cfi-asm" fi -if test "${target_cpu}-${platform}" = mips-yeeloong; then +if test "${target_cpu}-${platform}" = mips-loongson; then AC_CACHE_CHECK([whether -march=loongson2f works], [grub_cv_cc_march_loongson2f], [ SAVE_CFLAGS="$CFLAGS" CFLAGS="$CFLAGS -march=loongson2f" @@ -941,7 +943,7 @@ AM_CONDITIONAL([COND_i386_ieee1275], [test x$target_cpu = xi386 -a x$platform = AM_CONDITIONAL([COND_i386_coreboot], [test x$target_cpu = xi386 -a x$platform = xcoreboot]) AM_CONDITIONAL([COND_i386_multiboot], [test x$target_cpu = xi386 -a x$platform = xmultiboot]) AM_CONDITIONAL([COND_x86_64_efi], [test x$target_cpu = xx86_64 -a x$platform = xefi]) -AM_CONDITIONAL([COND_mips_yeeloong], [test x$target_cpu = xmips -a x$platform = xyeeloong]) +AM_CONDITIONAL([COND_mips_loongson], [test x$target_cpu = xmips -a x$platform = xloongson]) AM_CONDITIONAL([COND_mips_qemu_mips], [test x$target_cpu = xmips -a x$platform = xqemu_mips]) AM_CONDITIONAL([COND_sparc64_ieee1275], [test x$target_cpu = xsparc64 -a x$platform = xieee1275]) AM_CONDITIONAL([COND_powerpc_ieee1275], [test x$target_cpu = xpowerpc -a x$platform = xieee1275]) diff --git a/gentpl.py b/gentpl.py index a42a60667..17c6abfd8 100644 --- a/gentpl.py +++ b/gentpl.py @@ -6,7 +6,7 @@ GRUB_PLATFORMS = [ "emu", "i386_pc", "i386_efi", "i386_qemu", "i386_coreboot", "i386_multiboot", "i386_ieee1275", "x86_64_efi", - "mips_yeeloong", "sparc64_ieee1275", + "mips_loongson", "sparc64_ieee1275", "powerpc_ieee1275" ] GROUPS = {} @@ -17,7 +17,7 @@ GROUPS["common"] = GRUB_PLATFORMS[:] GROUPS["i386"] = [ "i386_pc", "i386_efi", "i386_qemu", "i386_coreboot", "i386_multiboot", "i386_ieee1275" ] GROUPS["x86_64"] = [ "x86_64_efi" ] GROUPS["x86"] = GROUPS["i386"] + GROUPS["x86_64"] -GROUPS["mips"] = [ "mips_yeeloong" ] +GROUPS["mips"] = [ "mips_loongson" ] GROUPS["sparc64"] = [ "sparc64_ieee1275" ] GROUPS["powerpc"] = [ "powerpc_ieee1275" ] @@ -29,17 +29,17 @@ GROUPS["ieee1275"] = [ "i386_ieee1275", "sparc64_ieee1275", "powerpc_ieee1275" GROUPS["noemu"] = GRUB_PLATFORMS[:]; GROUPS["noemu"].remove("emu") # Groups based on hardware features -GROUPS["cmos"] = GROUPS["x86"][:] + ["mips_yeeloong"]; GROUPS["cmos"].remove("i386_efi"); GROUPS["cmos"].remove("x86_64_efi") +GROUPS["cmos"] = GROUPS["x86"][:] + ["mips_loongson"]; GROUPS["cmos"].remove("i386_efi"); GROUPS["cmos"].remove("x86_64_efi") GROUPS["pci"] = GROUPS["x86"] + GROUPS["mips"] GROUPS["usb"] = GROUPS["pci"] # If gfxterm is main output console integrate it into kernel -GROUPS["videoinkernel"] = ["mips_yeeloong"] +GROUPS["videoinkernel"] = ["mips_loongson"] GROUPS["videomodules"] = GRUB_PLATFORMS[:]; for i in GROUPS["videoinkernel"]: GROUPS["videomodules"].remove(i) # Similar for terminfo -GROUPS["terminfoinkernel"] = ["mips_yeeloong"] + GROUPS["ieee1275"]; +GROUPS["terminfoinkernel"] = ["mips_loongson"] + GROUPS["ieee1275"]; GROUPS["terminfomodule"] = GRUB_PLATFORMS[:]; for i in GROUPS["terminfoinkernel"]: GROUPS["terminfomodule"].remove(i) @@ -238,7 +238,7 @@ def foreach_enabled_platform(closure): # noemu = bus/usb/usbhub.c; # enable = emu; # enable = i386; -# enable = mips_yeeloong; +# enable = mips_loongson; # emu_condition = COND_GRUB_EMU_USB; # }; # diff --git a/grub-core/Makefile.am b/grub-core/Makefile.am index 94f7f3ffe..3b1611db2 100644 --- a/grub-core/Makefile.am +++ b/grub-core/Makefile.am @@ -125,7 +125,7 @@ KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/efi/disk.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/i386/pit.h endif -if COND_mips_yeeloong +if COND_mips_loongson KERNEL_HEADER_FILES += $(top_builddir)/include/grub/keyboard_layouts.h KERNEL_HEADER_FILES += $(top_builddir)/include/grub/machine/kernel.h KERNEL_HEADER_FILES += $(top_builddir)/include/grub/cpu/cache.h diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def index e651e1596..a87eb1598 100644 --- a/grub-core/Makefile.core.def +++ b/grub-core/Makefile.core.def @@ -32,11 +32,11 @@ kernel = { i386_coreboot_ldflags = '-Wl,-Ttext=0x8200'; i386_multiboot_ldflags = '-Wl,-Ttext=0x8200'; i386_ieee1275_ldflags = '-Wl,-Ttext=0x10000'; - mips_yeeloong_ldflags = '-Wl,-Ttext,0x80200000'; + mips_loongson_ldflags = '-Wl,-Ttext,0x80200000'; powerpc_ieee1275_ldflags = '-Wl,-Ttext,0x200000'; sparc64_ieee1275_ldflags = '-Wl,-Ttext,0x4400'; - mips_yeeloong_cppflags = '-DUSE_ASCII_FAILBACK'; + mips_loongson_cppflags = '-DUSE_ASCII_FAILBACK'; i386_qemu_cppflags = '-DGRUB_BOOT_MACHINE_LINK_ADDR=$(GRUB_BOOT_MACHINE_LINK_ADDR)'; emu_cflags = '$(CFLAGS_GNULIB)'; emu_cppflags = '$(CPPFLAGS_GNULIB)'; @@ -48,7 +48,7 @@ kernel = { i386_ieee1275_startup = kern/i386/ieee1275/startup.S; i386_coreboot_startup = kern/i386/coreboot/startup.S; i386_multiboot_startup = kern/i386/coreboot/startup.S; - mips_yeeloong_startup = kern/mips/startup.S; + mips_loongson_startup = kern/mips/startup.S; sparc64_ieee1275_startup = kern/sparc64/ieee1275/crt0.S; powerpc_ieee1275_startup = kern/powerpc/ieee1275/startup.S; @@ -81,7 +81,7 @@ kernel = { i386_qemu = kern/generic/rtc_get_time_ms.c; i386_coreboot = kern/generic/rtc_get_time_ms.c; i386_multiboot = kern/generic/rtc_get_time_ms.c; - mips_yeeloong = kern/generic/rtc_get_time_ms.c; + mips_loongson = kern/generic/rtc_get_time_ms.c; ieee1275 = disk/ieee1275/ofdisk.c; ieee1275 = kern/ieee1275/cmain.c; @@ -136,20 +136,20 @@ kernel = { i386_ieee1275 = kern/ieee1275/init.c; - mips_yeeloong = term/ns8250.c; - mips_yeeloong = bus/bonito.c; - mips_yeeloong = bus/cs5536.c; - mips_yeeloong = bus/pci.c; - mips_yeeloong = kern/mips/cache.S; - mips_yeeloong = kern/mips/dl.c; - mips_yeeloong = kern/mips/init.c; - mips_yeeloong = kern/mips/yeeloong/init.c; - mips_yeeloong = term/at_keyboard.c; - mips_yeeloong = term/serial.c; - mips_yeeloong = video/sm712.c; - mips_yeeloong = video/sis315pro.c; + mips_loongson = term/ns8250.c; + mips_loongson = bus/bonito.c; + mips_loongson = bus/cs5536.c; + mips_loongson = bus/pci.c; + mips_loongson = kern/mips/cache.S; + mips_loongson = kern/mips/dl.c; + mips_loongson = kern/mips/init.c; + mips_loongson = kern/mips/loongson/init.c; + mips_loongson = term/at_keyboard.c; + mips_loongson = term/serial.c; + mips_loongson = video/sm712.c; + mips_loongson = video/sis315pro.c; extra_dist = video/sm712_init.c; - mips_yeeloong = commands/keylayouts.c; + mips_loongson = commands/keylayouts.c; powerpc_ieee1275 = kern/ieee1275/init.c; powerpc_ieee1275 = kern/powerpc/cache.S; @@ -323,18 +323,18 @@ image = { image = { name = fwstart; - mips_yeeloong = boot/mips/yeeloong/fwstart.S; + mips_loongson = boot/mips/loongson/fwstart.S; objcopyflags = '-O binary'; ldflags = '-static-libgcc -lgcc -Wl,-N,-S,-Ttext,0xbfc00000,-Bstatic'; - enable = mips_yeeloong; + enable = mips_loongson; }; image = { name = fwstart_fuloong; - mips_yeeloong = boot/mips/yeeloong/fuloong.S; + mips_loongson = boot/mips/loongson/fuloong.S; objcopyflags = '-O binary'; ldflags = '-static-libgcc -lgcc -Wl,-N,-S,-Ttext,0xbfc00000,-Bstatic'; - enable = mips_yeeloong; + enable = mips_loongson; }; module = { @@ -358,8 +358,8 @@ module = { module = { name = lsspd; - mips_yeeloong = commands/mips/yeeloong/lsspd.c; - enable = mips_yeeloong; + mips_loongson = commands/mips/loongson/lsspd.c; + enable = mips_loongson; }; module = { @@ -1236,10 +1236,10 @@ module = { x86_efi = mmap/efi/mmap.c; - mips_yeeloong = mmap/mips/yeeloong/uppermem.c; + mips_loongson = mmap/mips/loongson/uppermem.c; enable = x86; - enable = mips_yeeloong; + enable = mips_loongson; }; module = { diff --git a/grub-core/boot/mips/yeeloong/fuloong.S b/grub-core/boot/mips/loongson/fuloong.S similarity index 100% rename from grub-core/boot/mips/yeeloong/fuloong.S rename to grub-core/boot/mips/loongson/fuloong.S diff --git a/grub-core/boot/mips/yeeloong/fwstart.S b/grub-core/boot/mips/loongson/fwstart.S similarity index 99% rename from grub-core/boot/mips/yeeloong/fwstart.S rename to grub-core/boot/mips/loongson/fwstart.S index d25ff1a5b..6deb17f2b 100644 --- a/grub-core/boot/mips/yeeloong/fwstart.S +++ b/grub-core/boot/mips/loongson/fwstart.S @@ -16,8 +16,8 @@ * along with GRUB. If not, see . */ -#include -#include +#include +#include #include #include #include @@ -129,7 +129,7 @@ retry_cs5536: sb $t1, %lo(GRUB_MACHINE_PCI_IO_BASE + GRUB_CS5536_LBAR_SMBUS + GRUB_CS5536_SMB_REG_CTRL3) ($t0) sb $t1, %lo(GRUB_MACHINE_PCI_IO_BASE + GRUB_CS5536_LBAR_SMBUS + GRUB_CS5536_SMB_REG_CTRL2) ($t0) - /* Yeeloong has only one memory slot. */ + /* Yeeloong and Fuloong have only one memory slot. */ /* Output first byte on serial for debugging. */ ori $a1, $zero, GRUB_SMB_RAM_START_ADDR bal read_spd diff --git a/grub-core/boot/mips/startup_raw.S b/grub-core/boot/mips/startup_raw.S index d8789982f..0bb3ea11f 100644 --- a/grub-core/boot/mips/startup_raw.S +++ b/grub-core/boot/mips/startup_raw.S @@ -50,7 +50,7 @@ codestart: /* Parse arguments. Has to be done before relocation. So need to do it in asm. */ -#ifdef GRUB_MACHINE_MIPS_YEELOONG +#ifdef GRUB_MACHINE_MIPS_LOONGSON move $s2, $zero move $s3, $zero move $s4, $zero diff --git a/grub-core/bus/pci.c b/grub-core/bus/pci.c index 11101d42b..bf9e605ae 100644 --- a/grub-core/bus/pci.c +++ b/grub-core/bus/pci.c @@ -36,7 +36,7 @@ grub_dma_free (struct grub_pci_dma_chunk *ch) } /* #endif */ -#ifdef GRUB_MACHINE_MIPS_YEELOONG +#ifdef GRUB_MACHINE_MIPS_LOONGSON volatile void * grub_dma_get_virt (struct grub_pci_dma_chunk *ch) { @@ -99,13 +99,13 @@ grub_pci_iterate (grub_pci_iteratefunc_t hook) continue; } -#ifdef GRUB_MACHINE_MIPS_YEELOONG +#ifdef GRUB_MACHINE_MIPS_LOONGSON /* Skip ghosts. */ - if (id == GRUB_YEELOONG_OHCI_PCIID - && dev.function == GRUB_YEELOONG_OHCI_GHOST_FUNCTION) + if (id == GRUB_LOONGSON_OHCI_PCIID + && dev.function == GRUB_LOONGSON_OHCI_GHOST_FUNCTION) continue; - if (id == GRUB_YEELOONG_EHCI_PCIID - && dev.function == GRUB_YEELOONG_EHCI_GHOST_FUNCTION) + if (id == GRUB_LOONGSON_EHCI_PCIID + && dev.function == GRUB_LOONGSON_EHCI_GHOST_FUNCTION) continue; #endif diff --git a/grub-core/commands/mips/yeeloong/lsspd.c b/grub-core/commands/mips/loongson/lsspd.c similarity index 100% rename from grub-core/commands/mips/yeeloong/lsspd.c rename to grub-core/commands/mips/loongson/lsspd.c diff --git a/grub-core/kern/main.c b/grub-core/kern/main.c index da7123234..6376c2516 100644 --- a/grub-core/kern/main.c +++ b/grub-core/kern/main.c @@ -53,8 +53,8 @@ grub_module_iterate (int (*hook) (struct grub_module_header *header)) } } -/* This is actualy platform-independant but used only on yeeloong and sparc. */ -#if defined (GRUB_MACHINE_MIPS_YEELOONG) || defined (GRUB_MACHINE_SPARC64) +/* This is actualy platform-independant but used only on loongson and sparc. */ +#if defined (GRUB_MACHINE_MIPS_LOONGSON) || defined (GRUB_MACHINE_SPARC64) grub_addr_t grub_modules_get_end (void) { diff --git a/grub-core/kern/mips/yeeloong/init.c b/grub-core/kern/mips/loongson/init.c similarity index 98% rename from grub-core/kern/mips/yeeloong/init.c rename to grub-core/kern/mips/loongson/init.c index 7526111cc..acc3a17c7 100644 --- a/grub-core/kern/mips/yeeloong/init.c +++ b/grub-core/kern/mips/loongson/init.c @@ -80,7 +80,7 @@ init_pci (void) /* FIXME: autoscan for BARs and devices. */ switch (pciid) { - case GRUB_YEELOONG_OHCI_PCIID: + case GRUB_LOONGSON_OHCI_PCIID: addr = grub_pci_make_address (dev, GRUB_PCI_REG_ADDRESS_REG0); grub_pci_write (addr, 0x5025000); addr = grub_pci_make_address (dev, GRUB_PCI_REG_COMMAND); @@ -92,7 +92,7 @@ init_pci (void) addr = grub_pci_make_address (dev, GRUB_PCI_REG_STATUS); grub_pci_write_word (addr, 0x0200 | GRUB_PCI_STATUS_CAPABILITIES); break; - case GRUB_YEELOONG_EHCI_PCIID: + case GRUB_LOONGSON_EHCI_PCIID: addr = grub_pci_make_address (dev, GRUB_PCI_REG_ADDRESS_REG0); grub_pci_write (addr, 0x5026000); addr = grub_pci_make_address (dev, GRUB_PCI_REG_COMMAND); @@ -164,7 +164,7 @@ grub_machine_init (void) if (err) grub_fatal ("Couldn't init SMBus: %s\n", grub_errmsg); - /* Yeeloong has only one memory slot. */ + /* Yeeloong and Fuloong have only one memory slot. */ err = grub_cs5536_read_spd (smbbase, GRUB_SMB_RAM_START_ADDR, &spd); if (err) grub_fatal ("Couldn't read SPD: %s\n", grub_errmsg); diff --git a/grub-core/kern/mips/startup.S b/grub-core/kern/mips/startup.S index 999beee79..624ceb6d0 100644 --- a/grub-core/kern/mips/startup.S +++ b/grub-core/kern/mips/startup.S @@ -36,7 +36,7 @@ start: bal cont nop - . = _start + GRUB_KERNEL_MIPS_YEELOONG_TOTAL_MODULE_SIZE + . = _start + GRUB_KERNEL_MIPS_LOONGSON_TOTAL_MODULE_SIZE total_module_size: .long 0 @@ -51,7 +51,7 @@ VARIABLE(grub_prefix) */ . = _start + GRUB_KERNEL_MACHINE_PREFIX_END -#ifdef GRUB_MACHINE_MIPS_YEELOONG +#ifdef GRUB_MACHINE_MIPS_LOONGSON VARIABLE (grub_arch_busclock) .long 0 VARIABLE (grub_arch_cpuclock) @@ -67,7 +67,7 @@ cont: /* Save our base. */ move $s0, $ra -#ifdef GRUB_MACHINE_MIPS_YEELOONG +#ifdef GRUB_MACHINE_MIPS_LOONGSON lui $t1, %hi(grub_arch_busclock) addiu $t1, %lo(grub_arch_busclock) sw $s2, 0($t1) diff --git a/grub-core/loader/mips/linux.c b/grub-core/loader/mips/linux.c index 244d2b8a3..9cc1bd778 100644 --- a/grub-core/loader/mips/linux.c +++ b/grub-core/loader/mips/linux.c @@ -32,7 +32,7 @@ #include #include -#ifdef GRUB_MACHINE_MIPS_YEELOONG +#ifdef GRUB_MACHINE_MIPS_LOONGSON #include const char loongson_machtypes[][60] = @@ -224,7 +224,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), /* For arguments. */ linux_argc = argc; -#ifdef GRUB_MACHINE_MIPS_YEELOONG +#ifdef GRUB_MACHINE_MIPS_LOONGSON linux_argc++; #endif /* Main arguments. */ @@ -239,7 +239,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), /* Normal arguments. */ for (i = 1; i < argc; i++) size += ALIGN_UP (grub_strlen (argv[i]) + 1, 4); -#ifdef GRUB_MACHINE_MIPS_YEELOONG +#ifdef GRUB_MACHINE_MIPS_LOONGSON size += ALIGN_UP (sizeof (loongson_machtypes[0]), 4); #endif @@ -279,7 +279,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), linux_argv++; linux_args += ALIGN_UP (sizeof ("a0"), 4); -#ifdef GRUB_MACHINE_MIPS_YEELOONG +#ifdef GRUB_MACHINE_MIPS_LOONGSON { unsigned mtype = grub_arch_machine; if (mtype >= ARRAY_SIZE (loongson_machtypes)) diff --git a/grub-core/mmap/mips/yeeloong/uppermem.c b/grub-core/mmap/mips/loongson/uppermem.c similarity index 100% rename from grub-core/mmap/mips/yeeloong/uppermem.c rename to grub-core/mmap/mips/loongson/uppermem.c diff --git a/grub-core/term/at_keyboard.c b/grub-core/term/at_keyboard.c index 55cb76483..828217497 100644 --- a/grub-core/term/at_keyboard.c +++ b/grub-core/term/at_keyboard.c @@ -257,7 +257,7 @@ grub_keyboard_controller_write (grub_uint8_t c) grub_outb (c, KEYBOARD_REG_DATA); } -#if !defined (GRUB_MACHINE_MIPS_YEELOONG) && !defined (GRUB_MACHINE_QEMU) +#if !defined (GRUB_MACHINE_MIPS_LOONGSON) && !defined (GRUB_MACHINE_QEMU) static grub_uint8_t grub_keyboard_controller_read (void) @@ -562,7 +562,7 @@ grub_keyboard_controller_init (struct grub_term_input *term __attribute__ ((unus keyboard_controller_wait_until_ready (); grub_inb (KEYBOARD_REG_DATA); } -#if defined (GRUB_MACHINE_MIPS_YEELOONG) || defined (GRUB_MACHINE_QEMU) +#if defined (GRUB_MACHINE_MIPS_LOONGSON) || defined (GRUB_MACHINE_QEMU) grub_keyboard_controller_orig = 0; grub_keyboard_orig_set = 2; #else diff --git a/grub-core/term/ns8250.c b/grub-core/term/ns8250.c index 5d403c845..b63ee14d9 100644 --- a/grub-core/term/ns8250.c +++ b/grub-core/term/ns8250.c @@ -66,8 +66,8 @@ serial_get_divisor (const struct grub_serial_port *port, for (i = 0; i < ARRAY_SIZE (divisor_tab); i++) if (divisor_tab[i].speed == config->speed) { - /* internal UART in Yeeloong runs twice the usual rate. */ -#ifdef GRUB_MACHINE_MIPS_YEELOONG + /* internal Loongson UART runs twice the usual rate. */ +#ifdef GRUB_MACHINE_MIPS_LOONGSON if (port->port == 0xbff003f8) return 2 * divisor_tab[i].div; else @@ -115,8 +115,8 @@ do_real_config (struct grub_serial_port *port) | stop_bits[port->config.stop_bits]); grub_outb (status, port->port + UART_LCR); - /* In Yeeloong serial port has only 3 wires. */ -#ifndef GRUB_MACHINE_MIPS_YEELOONG + /* On Loongson machines serial port has only 3 wires. */ +#ifndef GRUB_MACHINE_MIPS_LOONGSON /* Enable the FIFO. */ grub_outb (UART_ENABLE_FIFO_TRIGGER1, port->port + UART_FCR); diff --git a/grub-core/term/serial.c b/grub-core/term/serial.c index aca5769fd..74c493da1 100644 --- a/grub-core/term/serial.c +++ b/grub-core/term/serial.c @@ -26,7 +26,7 @@ #include #include #include -#ifdef GRUB_MACHINE_MIPS_YEELOONG +#ifdef GRUB_MACHINE_MIPS_LOONGSON #include #endif @@ -298,7 +298,7 @@ grub_serial_register (struct grub_serial_port *port) port->term_in = in; port->term_out = out; grub_terminfo_output_register (out, "vt100"); -#ifdef GRUB_MACHINE_MIPS_YEELOONG +#ifdef GRUB_MACHINE_MIPS_LOONGSON if (grub_strcmp (port->name, (grub_arch_machine == GRUB_ARCH_MACHINE_YEELOONG) ? "com0" : "com2") == 0) diff --git a/include/grub/mips/yeeloong/at_keyboard.h b/include/grub/mips/loongson/at_keyboard.h similarity index 100% rename from include/grub/mips/yeeloong/at_keyboard.h rename to include/grub/mips/loongson/at_keyboard.h diff --git a/include/grub/mips/yeeloong/cmos.h b/include/grub/mips/loongson/cmos.h similarity index 100% rename from include/grub/mips/yeeloong/cmos.h rename to include/grub/mips/loongson/cmos.h diff --git a/include/grub/mips/yeeloong/ec.h b/include/grub/mips/loongson/ec.h similarity index 100% rename from include/grub/mips/yeeloong/ec.h rename to include/grub/mips/loongson/ec.h diff --git a/include/grub/mips/yeeloong/kernel.h b/include/grub/mips/loongson/kernel.h similarity index 100% rename from include/grub/mips/yeeloong/kernel.h rename to include/grub/mips/loongson/kernel.h diff --git a/include/grub/mips/yeeloong/memory.h b/include/grub/mips/loongson/memory.h similarity index 100% rename from include/grub/mips/yeeloong/memory.h rename to include/grub/mips/loongson/memory.h diff --git a/include/grub/mips/yeeloong/pci.h b/include/grub/mips/loongson/pci.h similarity index 95% rename from include/grub/mips/yeeloong/pci.h rename to include/grub/mips/loongson/pci.h index 199bac048..3f828c2f8 100644 --- a/include/grub/mips/yeeloong/pci.h +++ b/include/grub/mips/loongson/pci.h @@ -24,10 +24,10 @@ #include #endif -#define GRUB_YEELOONG_OHCI_PCIID 0x00351033 -#define GRUB_YEELOONG_EHCI_PCIID 0x00e01033 -#define GRUB_YEELOONG_OHCI_GHOST_FUNCTION 4 -#define GRUB_YEELOONG_EHCI_GHOST_FUNCTION 5 +#define GRUB_LOONGSON_OHCI_PCIID 0x00351033 +#define GRUB_LOONGSON_EHCI_PCIID 0x00e01033 +#define GRUB_LOONGSON_OHCI_GHOST_FUNCTION 4 +#define GRUB_LOONGSON_EHCI_GHOST_FUNCTION 5 #define GRUB_PCI_NUM_BUS 1 #define GRUB_PCI_NUM_DEVICES 16 diff --git a/include/grub/mips/yeeloong/serial.h b/include/grub/mips/loongson/serial.h similarity index 100% rename from include/grub/mips/yeeloong/serial.h rename to include/grub/mips/loongson/serial.h diff --git a/include/grub/mips/yeeloong/time.h b/include/grub/mips/loongson/time.h similarity index 100% rename from include/grub/mips/yeeloong/time.h rename to include/grub/mips/loongson/time.h diff --git a/include/grub/offsets.h b/include/grub/offsets.h index 817372b69..7d88f344d 100644 --- a/include/grub/offsets.h +++ b/include/grub/offsets.h @@ -100,16 +100,16 @@ #define GRUB_KERNEL_POWERPC_IEEE1275_LINK_ALIGN 4 #define GRUB_KERNEL_POWERPC_IEEE1275_LINK_ADDR 0x200000 -#define GRUB_KERNEL_MIPS_YEELOONG_LINK_ADDR 0x80200000 +#define GRUB_KERNEL_MIPS_LOONGSON_LINK_ADDR 0x80200000 -#define GRUB_KERNEL_MIPS_YEELOONG_LINK_ALIGN 32 +#define GRUB_KERNEL_MIPS_LOONGSON_LINK_ALIGN 32 -#define GRUB_KERNEL_MIPS_YEELOONG_COMPRESSED_SIZE 0x8 -#define GRUB_KERNEL_MIPS_YEELOONG_UNCOMPRESSED_SIZE 0xc +#define GRUB_KERNEL_MIPS_LOONGSON_COMPRESSED_SIZE 0x8 +#define GRUB_KERNEL_MIPS_LOONGSON_UNCOMPRESSED_SIZE 0xc -#define GRUB_KERNEL_MIPS_YEELOONG_TOTAL_MODULE_SIZE 0x08 -#define GRUB_KERNEL_MIPS_YEELOONG_PREFIX 0x0c -#define GRUB_KERNEL_MIPS_YEELOONG_PREFIX_END 0x54 +#define GRUB_KERNEL_MIPS_LOONGSON_TOTAL_MODULE_SIZE 0x08 +#define GRUB_KERNEL_MIPS_LOONGSON_PREFIX 0x0c +#define GRUB_KERNEL_MIPS_LOONGSON_PREFIX_END 0x54 /* The offset of GRUB_PREFIX. */ #define GRUB_KERNEL_I386_EFI_PREFIX 0x8 @@ -144,7 +144,7 @@ #define GRUB_KERNEL_POWERPC_IEEE1275_MOD_ALIGN 0x1000 -#define GRUB_KERNEL_MIPS_YEELOONG_MOD_ALIGN 0x1 +#define GRUB_KERNEL_MIPS_LOONGSON_MOD_ALIGN 0x1 /* Minimal gap between _end and the start of the modules. It's a hack for PowerMac to prevent "CLAIM failed" error. The real fix is to diff --git a/include/grub/serial.h b/include/grub/serial.h index 9540bee64..41b720891 100644 --- a/include/grub/serial.h +++ b/include/grub/serial.h @@ -102,7 +102,7 @@ grub_serial_config_defaults (struct grub_serial_port *port) { struct grub_serial_config config = { -#ifdef GRUB_MACHINE_MIPS_YEELOONG +#ifdef GRUB_MACHINE_MIPS_LOONGSON .speed = 115200, #else .speed = 9600, diff --git a/util/grub-install.in b/util/grub-install.in index 90360c279..b20cadaf6 100644 --- a/util/grub-install.in +++ b/util/grub-install.in @@ -551,13 +551,13 @@ fi case "${target_cpu}-${platform}" in sparc64-ieee1275) mkimage_target=sparc64-ieee1275-raw ;; - mips-yeeloong) mkimage_target=mipsel-yeeloong-elf ;; + mips-loongson) mkimage_target=mipsel-loongson-elf ;; *) mkimage_target="${target_cpu}-${platform}" ;; esac case "${target_cpu}-${platform}" in i386-efi | x86_64-efi) imgext=efi ;; - mips-yeeloong | i386-coreboot | i386-multiboot | i386-ieee1275 \ + mips-loongson | i386-coreboot | i386-multiboot | i386-ieee1275 \ | powerpc-ieee1275) imgext=elf ;; *) imgext=img ;; esac @@ -566,7 +566,7 @@ esac "$grub_mkimage" ${config_opt} -d "${pkglibdir}" -O ${mkimage_target} --output="${grubdir}/core.${imgext}" --prefix="${prefix_drive}${relative_grubdir}" $modules || exit 1 # Backward-compatibility kludges -if [ "${target_cpu}-${platform}" = "mips-yeeloong" ]; then +if [ "${target_cpu}-${platform}" = "mips-loongson" ]; then cp "${grubdir}/core.${imgext}" "${bootdir}"/grub.elf elif [ "${target_cpu}-${platform}" = "i386-ieee1275" ] || [ "${target_cpu}-${platform}" = "powerpc-ieee1275" ]; then cp "${grubdir}/core.${imgext}" "${grubdir}/grub" diff --git a/util/grub-mkimage.c b/util/grub-mkimage.c index 663e60f08..739b8c16e 100644 --- a/util/grub-mkimage.c +++ b/util/grub-mkimage.c @@ -65,7 +65,7 @@ struct image_target_desc enum { IMAGE_I386_PC, IMAGE_EFI, IMAGE_COREBOOT, IMAGE_SPARC64_AOUT, IMAGE_SPARC64_RAW, IMAGE_I386_IEEE1275, - IMAGE_YEELOONG_ELF, IMAGE_QEMU, IMAGE_PPC, IMAGE_YEELOONG_FLASH, + IMAGE_LOONGSON_ELF, IMAGE_QEMU, IMAGE_PPC, IMAGE_YEELOONG_FLASH, IMAGE_FULOONG_FLASH, IMAGE_I386_PC_PXE } id; enum @@ -265,70 +265,70 @@ struct image_target_desc image_targets[] = .install_bsd_part = TARGET_NO_FIELD, }, { - .dirname = "mipsel-yeeloong", + .dirname = "mipsel-loongson", .names = { "mipsel-yeeloong-flash", NULL }, .voidp_sizeof = 4, .bigendian = 0, .id = IMAGE_YEELOONG_FLASH, .flags = PLATFORM_FLAGS_DECOMPRESSORS, - .prefix = GRUB_KERNEL_MIPS_YEELOONG_PREFIX, - .prefix_end = GRUB_KERNEL_MIPS_YEELOONG_PREFIX_END, + .prefix = GRUB_KERNEL_MIPS_LOONGSON_PREFIX, + .prefix_end = GRUB_KERNEL_MIPS_LOONGSON_PREFIX_END, .raw_size = 0, - .total_module_size = GRUB_KERNEL_MIPS_YEELOONG_TOTAL_MODULE_SIZE, + .total_module_size = GRUB_KERNEL_MIPS_LOONGSON_TOTAL_MODULE_SIZE, .compressed_size = TARGET_NO_FIELD, .kernel_image_size = TARGET_NO_FIELD, .section_align = 1, .vaddr_offset = 0, .install_dos_part = TARGET_NO_FIELD, .install_bsd_part = TARGET_NO_FIELD, - .link_addr = GRUB_KERNEL_MIPS_YEELOONG_LINK_ADDR, + .link_addr = GRUB_KERNEL_MIPS_LOONGSON_LINK_ADDR, .elf_target = EM_MIPS, - .link_align = GRUB_KERNEL_MIPS_YEELOONG_LINK_ALIGN, + .link_align = GRUB_KERNEL_MIPS_LOONGSON_LINK_ALIGN, .default_compression = COMPRESSION_NONE }, { - .dirname = "mipsel-yeeloong", + .dirname = "mipsel-loongson", .names = { "mipsel-fuloong-flash", NULL }, .voidp_sizeof = 4, .bigendian = 0, .id = IMAGE_FULOONG_FLASH, .flags = PLATFORM_FLAGS_DECOMPRESSORS, - .prefix = GRUB_KERNEL_MIPS_YEELOONG_PREFIX, - .prefix_end = GRUB_KERNEL_MIPS_YEELOONG_PREFIX_END, + .prefix = GRUB_KERNEL_MIPS_LOONGSON_PREFIX, + .prefix_end = GRUB_KERNEL_MIPS_LOONGSON_PREFIX_END, .raw_size = 0, - .total_module_size = GRUB_KERNEL_MIPS_YEELOONG_TOTAL_MODULE_SIZE, + .total_module_size = GRUB_KERNEL_MIPS_LOONGSON_TOTAL_MODULE_SIZE, .compressed_size = TARGET_NO_FIELD, .kernel_image_size = TARGET_NO_FIELD, .section_align = 1, .vaddr_offset = 0, .install_dos_part = TARGET_NO_FIELD, .install_bsd_part = TARGET_NO_FIELD, - .link_addr = GRUB_KERNEL_MIPS_YEELOONG_LINK_ADDR, + .link_addr = GRUB_KERNEL_MIPS_LOONGSON_LINK_ADDR, .elf_target = EM_MIPS, - .link_align = GRUB_KERNEL_MIPS_YEELOONG_LINK_ALIGN, + .link_align = GRUB_KERNEL_MIPS_LOONGSON_LINK_ALIGN, .default_compression = COMPRESSION_NONE }, { - .dirname = "mipsel-yeeloong", + .dirname = "mipsel-loongson", .names = { "mipsel-loongson-elf", "mipsel-yeeloong-elf", "mipsel-fuloong-elf", NULL }, .voidp_sizeof = 4, .bigendian = 0, - .id = IMAGE_YEELOONG_ELF, + .id = IMAGE_LOONGSON_ELF, .flags = PLATFORM_FLAGS_DECOMPRESSORS, - .prefix = GRUB_KERNEL_MIPS_YEELOONG_PREFIX, - .prefix_end = GRUB_KERNEL_MIPS_YEELOONG_PREFIX_END, + .prefix = GRUB_KERNEL_MIPS_LOONGSON_PREFIX, + .prefix_end = GRUB_KERNEL_MIPS_LOONGSON_PREFIX_END, .raw_size = 0, - .total_module_size = GRUB_KERNEL_MIPS_YEELOONG_TOTAL_MODULE_SIZE, + .total_module_size = GRUB_KERNEL_MIPS_LOONGSON_TOTAL_MODULE_SIZE, .compressed_size = TARGET_NO_FIELD, .kernel_image_size = TARGET_NO_FIELD, .section_align = 1, .vaddr_offset = 0, .install_dos_part = TARGET_NO_FIELD, .install_bsd_part = TARGET_NO_FIELD, - .link_addr = GRUB_KERNEL_MIPS_YEELOONG_LINK_ADDR, + .link_addr = GRUB_KERNEL_MIPS_LOONGSON_LINK_ADDR, .elf_target = EM_MIPS, - .link_align = GRUB_KERNEL_MIPS_YEELOONG_LINK_ALIGN, + .link_align = GRUB_KERNEL_MIPS_LOONGSON_LINK_ALIGN, .default_compression = COMPRESSION_NONE }, { @@ -837,10 +837,10 @@ generate_image (const char *dir, char *prefix, FILE *out, char *mods[], decompress_size = grub_util_get_image_size (decompress_path); decompress_img = grub_util_read_image (decompress_path); - *((grub_uint32_t *) (decompress_img + GRUB_KERNEL_MIPS_YEELOONG_COMPRESSED_SIZE)) + *((grub_uint32_t *) (decompress_img + GRUB_KERNEL_MIPS_LOONGSON_COMPRESSED_SIZE)) = grub_host_to_target32 (core_size); - *((grub_uint32_t *) (decompress_img + GRUB_KERNEL_MIPS_YEELOONG_UNCOMPRESSED_SIZE)) + *((grub_uint32_t *) (decompress_img + GRUB_KERNEL_MIPS_LOONGSON_UNCOMPRESSED_SIZE)) = grub_host_to_target32 (kernel_size + total_module_size); full_size = core_size + decompress_size; @@ -1271,7 +1271,7 @@ generate_image (const char *dir, char *prefix, FILE *out, char *mods[], core_size = rom_size; } break; - case IMAGE_YEELOONG_ELF: + case IMAGE_LOONGSON_ELF: case IMAGE_PPC: case IMAGE_COREBOOT: case IMAGE_I386_IEEE1275: @@ -1284,7 +1284,7 @@ generate_image (const char *dir, char *prefix, FILE *out, char *mods[], int header_size, footer_size = 0; int phnum = 1; - if (image_target->id != IMAGE_YEELOONG_ELF) + if (image_target->id != IMAGE_LOONGSON_ELF) phnum += 2; if (note) @@ -1319,7 +1319,7 @@ generate_image (const char *dir, char *prefix, FILE *out, char *mods[], /* No section headers. */ ehdr->e_shoff = grub_host_to_target32 (0); - if (image_target->id == IMAGE_YEELOONG_ELF) + if (image_target->id == IMAGE_LOONGSON_ELF) ehdr->e_shentsize = grub_host_to_target16 (0); else ehdr->e_shentsize = grub_host_to_target16 (sizeof (Elf32_Shdr)); @@ -1332,7 +1332,7 @@ generate_image (const char *dir, char *prefix, FILE *out, char *mods[], phdr->p_offset = grub_host_to_target32 (header_size); phdr->p_flags = grub_host_to_target32 (PF_R | PF_W | PF_X); - if (image_target->id == IMAGE_YEELOONG_ELF) + if (image_target->id == IMAGE_LOONGSON_ELF) target_addr = ALIGN_UP (image_target->link_addr + kernel_size + total_module_size, 32); else @@ -1341,12 +1341,12 @@ generate_image (const char *dir, char *prefix, FILE *out, char *mods[], phdr->p_vaddr = grub_host_to_target32 (target_addr); phdr->p_paddr = grub_host_to_target32 (target_addr); phdr->p_align = grub_host_to_target32 (align > image_target->link_align ? align : image_target->link_align); - if (image_target->id == IMAGE_YEELOONG_ELF) + if (image_target->id == IMAGE_LOONGSON_ELF) ehdr->e_flags = grub_host_to_target32 (0x1000 | EF_MIPS_NOREORDER | EF_MIPS_PIC | EF_MIPS_CPIC); else ehdr->e_flags = 0; - if (image_target->id == IMAGE_YEELOONG_ELF) + if (image_target->id == IMAGE_LOONGSON_ELF) { phdr->p_filesz = grub_host_to_target32 (core_size); phdr->p_memsz = grub_host_to_target32 (core_size); From 57d75699d6eff414d65bd0cc704c2b86be518c94 Mon Sep 17 00:00:00 2001 From: Szymon Janc Date: Mon, 7 Mar 2011 22:23:06 +0100 Subject: [PATCH 307/869] 2011-03-07 Szymon Janc * grub-core/fs/zfs/zfs.c (zap_leaf_lookup): Set-but-not-used variable removed. --- ChangeLog | 5 +++++ grub-core/fs/zfs/zfs.c | 2 -- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 72d718b08..d8a8d1fc2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-03-07 Szymon Janc + + * grub-core/fs/zfs/zfs.c (zap_leaf_lookup): + Set-but-not-used variable removed. + 2011-02-12 Vladimir Serbinenko Workaround yet another IEEE1275 bug. diff --git a/grub-core/fs/zfs/zfs.c b/grub-core/fs/zfs/zfs.c index 5b575f369..3a94d8874 100644 --- a/grub-core/fs/zfs/zfs.c +++ b/grub-core/fs/zfs/zfs.c @@ -837,14 +837,12 @@ zap_leaf_lookup (zap_leaf_phys_t * l, grub_zfs_endian_t endian, name)) { struct zap_leaf_array *la; - grub_uint8_t *ip; if (le->le_int_size != 8 || le->le_value_length != 1) return grub_error (GRUB_ERR_BAD_FS, "invalid leaf chunk entry"); /* get the uint64_t property value */ la = &ZAP_LEAF_CHUNK (l, blksft, le->le_value_chunk).l_array; - ip = la->la_array; *value = grub_be_to_cpu64 (la->la_array64); From 83a3c48d3749b64eda1708f2d76efd18f2d6e487 Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Wed, 9 Mar 2011 17:35:16 +0000 Subject: [PATCH 308/869] * docs/grub.texi (Simple configuration): Tidy up formatting. --- ChangeLog | 4 ++++ docs/grub.texi | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index d8a8d1fc2..103706af0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2011-03-09 Colin Watson + + * docs/grub.texi (Simple configuration): Tidy up formatting. + 2011-03-07 Szymon Janc * grub-core/fs/zfs/zfs.c (zap_leaf_lookup): diff --git a/docs/grub.texi b/docs/grub.texi index 590e6afb7..83bd80023 100644 --- a/docs/grub.texi +++ b/docs/grub.texi @@ -1036,8 +1036,8 @@ it as a new default entry for use by future runs of GRUB. This is only useful if @samp{GRUB_DEFAULT=saved}; it is a separate option because @samp{GRUB_DEFAULT=saved} is useful without this option, in conjunction with @command{grub-set-default} or @command{grub-reboot}. Unset by default. -The remarks of @pxref{Changes from GRUB Legacy} on the availability -of @samp{save_env} apply. +@samp{save_env} may not be available in all situations +(@pxref{Changes from GRUB Legacy}). @item GRUB_TIMEOUT Boot the default entry this many seconds after the menu is displayed, unless From be1a7ce0cfdd3ada7298abae16168a16bc551e96 Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Wed, 9 Mar 2011 17:38:31 +0000 Subject: [PATCH 309/869] * grub-core/loader/i386/linux.c (find_efi_mmap_size): Page-align cached mmap_size, so that this works correctly when called multiple times. Reported by: Daniel Kahn Gillmor. Should fix Debian bug #616638. --- ChangeLog | 7 +++++++ grub-core/loader/i386/linux.c | 3 ++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 103706af0..0406cf91f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2011-03-09 Colin Watson + + * grub-core/loader/i386/linux.c (find_efi_mmap_size): Page-align + cached mmap_size, so that this works correctly when called multiple + times. + Reported by: Daniel Kahn Gillmor. Should fix Debian bug #616638. + 2011-03-09 Colin Watson * docs/grub.texi (Simple configuration): Tidy up formatting. diff --git a/grub-core/loader/i386/linux.c b/grub-core/loader/i386/linux.c index 80960570b..0178e2fd4 100644 --- a/grub-core/loader/i386/linux.c +++ b/grub-core/loader/i386/linux.c @@ -136,7 +136,8 @@ find_efi_mmap_size (void) later, and EFI itself may allocate more. */ mmap_size += (1 << 12); - return page_align (mmap_size); + mmap_size = page_align (mmap_size); + return mmap_size; } #endif From 9b43bf396a61b60a0ee4b8a1591634b1120b8906 Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Fri, 11 Mar 2011 11:51:10 +0000 Subject: [PATCH 310/869] * grub-core/boot/i386/pc/lnxboot.S (real_code_2): Ensure that the initial chunk read from the kernel always includes GRUB's multiboot header, which is now outside the first sector. --- ChangeLog | 6 ++++++ grub-core/boot/i386/pc/lnxboot.S | 9 +++++++++ 2 files changed, 15 insertions(+) diff --git a/ChangeLog b/ChangeLog index 0406cf91f..08b937dcb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2011-03-11 Colin Watson + + * grub-core/boot/i386/pc/lnxboot.S (real_code_2): Ensure that the + initial chunk read from the kernel always includes GRUB's multiboot + header, which is now outside the first sector. + 2011-03-09 Colin Watson * grub-core/loader/i386/linux.c (find_efi_mmap_size): Page-align diff --git a/grub-core/boot/i386/pc/lnxboot.S b/grub-core/boot/i386/pc/lnxboot.S index 9a599c261..2c7596026 100644 --- a/grub-core/boot/i386/pc/lnxboot.S +++ b/grub-core/boot/i386/pc/lnxboot.S @@ -178,8 +178,13 @@ real_code_2: pushw %es popw %ds +#if GRUB_KERNEL_I386_PC_NO_REED_SOLOMON_PART + 4 < 0x200 movl $0x200, %ecx addl %ecx, %esi +#else + movl $(GRUB_KERNEL_I386_PC_NO_REED_SOLOMON_PART + 4), %ecx + addl $0x200, %esi +#endif movl $DATA_ADDR, %edi call LOCAL(move_memory) @@ -196,7 +201,11 @@ real_code_2: 1: movl %ss:(DATA_ADDR + GRUB_KERNEL_MACHINE_COMPRESSED_SIZE), %ecx +#if GRUB_KERNEL_I386_PC_NO_REED_SOLOMON_PART + 4 < 0x200 addl $(GRUB_KERNEL_MACHINE_RAW_SIZE - 0x200), %ecx +#else + addl $(GRUB_KERNEL_MACHINE_RAW_SIZE - (GRUB_KERNEL_I386_PC_NO_REED_SOLOMON_PART + 4)), %ecx +#endif 2: call LOCAL(move_memory) From 2da48d28d998f8d85868fae5debd238d2b3994d4 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 23 Mar 2011 11:52:04 +0100 Subject: [PATCH 311/869] * util/grub-install.in: Correct the x86-64 name as x86_64. --- ChangeLog | 4 ++++ util/grub-install.in | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 08b937dcb..6218e9f12 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2011-03-23 Vladimir Serbinenko + + * util/grub-install.in: Correct the x86-64 name as x86_64. + 2011-03-11 Colin Watson * grub-core/boot/i386/pc/lnxboot.S (real_code_2): Ensure that the diff --git a/util/grub-install.in b/util/grub-install.in index af3034e03..b4a4b3f26 100644 --- a/util/grub-install.in +++ b/util/grub-install.in @@ -367,7 +367,7 @@ if [ x"$platform" = xefi ]; then case "$target_cpu" in i386) efi_file=BOOTIA32.EFI ;; - x86-64) + x86_64) efi_file=BOOTX64.EFI ;; # GRUB does not yet support these architectures, but they're defined # by the specification so we include them here to ease future @@ -381,7 +381,7 @@ if [ x"$platform" = xefi ]; then case "$target_cpu" in i386) efi_file=grubia32.efi ;; - x86-64) + x86_64) efi_file=grubx64.efi ;; # GRUB does not yet support these architectures, but they're defined # by the specification so we include them here to ease future From 40fc46599d1421ed892d9eb2cd0277850791ef35 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 23 Mar 2011 11:54:58 +0100 Subject: [PATCH 312/869] * grub-core/video/bochs.c (grub_video_bochs_setup): Use grub_video_mode_type_t. * grub-core/video/cirrus.c (grub_video_cirrus_setup): Likewise. * grub-core/video/i386/pc/vbe.c (grub_video_vbe_setup): Likewise. * grub-core/video/i386/pc/vga.c (grub_video_vga_setup): Likewise. --- ChangeLog | 8 ++++++++ grub-core/video/bochs.c | 3 ++- grub-core/video/cirrus.c | 3 ++- grub-core/video/i386/pc/vbe.c | 3 ++- grub-core/video/i386/pc/vga.c | 3 ++- 5 files changed, 16 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 6218e9f12..20fdfc86c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2011-03-23 Vladimir Serbinenko + + * grub-core/video/bochs.c (grub_video_bochs_setup): Use + grub_video_mode_type_t. + * grub-core/video/cirrus.c (grub_video_cirrus_setup): Likewise. + * grub-core/video/i386/pc/vbe.c (grub_video_vbe_setup): Likewise. + * grub-core/video/i386/pc/vga.c (grub_video_vga_setup): Likewise. + 2011-03-23 Vladimir Serbinenko * util/grub-install.in: Correct the x86-64 name as x86_64. diff --git a/grub-core/video/bochs.c b/grub-core/video/bochs.c index 5def0985b..832cd9903 100644 --- a/grub-core/video/bochs.c +++ b/grub-core/video/bochs.c @@ -199,7 +199,8 @@ grub_video_bochs_set_palette (unsigned int start, unsigned int count, static grub_err_t grub_video_bochs_setup (unsigned int width, unsigned int height, - unsigned int mode_type, unsigned int mode_mask) + grub_video_mode_type_t mode_type, + grub_video_mode_type_t mode_mask) { int depth; grub_err_t err; diff --git a/grub-core/video/cirrus.c b/grub-core/video/cirrus.c index b8b0142ad..a964c85cd 100644 --- a/grub-core/video/cirrus.c +++ b/grub-core/video/cirrus.c @@ -235,7 +235,8 @@ grub_video_cirrus_set_palette (unsigned int start, unsigned int count, static grub_err_t grub_video_cirrus_setup (unsigned int width, unsigned int height, - unsigned int mode_type, unsigned int mode_mask) + grub_video_mode_type_t mode_type, + grub_video_mode_type_t mode_mask) { int depth; grub_err_t err; diff --git a/grub-core/video/i386/pc/vbe.c b/grub-core/video/i386/pc/vbe.c index 2ddb4ca80..08bf124b6 100644 --- a/grub-core/video/i386/pc/vbe.c +++ b/grub-core/video/i386/pc/vbe.c @@ -688,7 +688,8 @@ grub_video_vbe_iterate (int (*hook) (const struct grub_video_mode_info *info)) static grub_err_t grub_video_vbe_setup (unsigned int width, unsigned int height, - unsigned int mode_type, unsigned int mode_mask) + grub_video_mode_type_t mode_type, + grub_video_mode_type_t mode_mask) { grub_uint16_t *p; struct grub_vbe_mode_info_block vbe_mode_info; diff --git a/grub-core/video/i386/pc/vga.c b/grub-core/video/i386/pc/vga.c index 41b8d3eb1..19770ce0a 100644 --- a/grub-core/video/i386/pc/vga.c +++ b/grub-core/video/i386/pc/vga.c @@ -116,7 +116,8 @@ grub_video_vga_init (void) static grub_err_t grub_video_vga_setup (unsigned int width, unsigned int height, - unsigned int mode_type, unsigned int mode_mask) + grub_video_mode_type_t mode_type, + grub_video_mode_type_t mode_mask) { grub_err_t err; From 7d4e39d65a7102579e219ba52dccbb3830617ede Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 23 Mar 2011 12:05:13 +0100 Subject: [PATCH 313/869] * grub-core/bus/usb/usb.c (attach_hooks): Make static. * grub-core/bus/usb/usbhub.c (hubs): Likewise. * grub-core/commands/hashsum.c (aliases): Likewise. * grub-core/commands/setpci.c (pci_registers): Likewise. * grub-core/disk/usbms.c (attach_hook): Likewise. * grub-core/fs/zfs/zfs.c (decomp_table): Likewise. (zio_checksum_table): Likewise. * grub-core/gettext/gettext.c (grub_gettext_msg_list): Likewise. * grub-core/gfxmenu/gfxmenu.c (cached_view): Likewise. * grub-core/lib/legacy_parse.c (legacy_commands): Likewise. * grub-core/lib/relocator.c (leftovers): Likewise. (extra_blocks): Likewise. * grub-core/loader/i386/bsd.c (relocator): Likewise. * grub-core/loader/i386/multiboot_mbi.c (modules): Likewise. (modules_last): Likewise. * grub-core/loader/i386/xnu.c (table_aliases): Likewise. (devices): Likewise. * grub-core/loader/multiboot_mbi2.c (modules): Likewise. (modules_last): Likewise. * grub-core/normal/auth.c (users): Likewise. * grub-core/normal/context.c (initial_menu): Likewise. (current_menu): Likewise. * grub-core/normal/crypto.c (crypto_specs): Likewise. * grub-core/term/serial.c (grub_serial_ports): Likewise. (grub_serial_terminfo_input_template): Likewise. (grub_serial_terminfo_output_template): Likewise. (grub_serial_terminfo_input): Likewise. (grub_serial_terminfo_output): Likewise. (registered): Likewise. * grub-core/term/usb_keyboard.c (attach_hook): Likewise. --- ChangeLog | 33 +++++++++++++++++++++++++++ grub-core/bus/usb/usb.c | 2 +- grub-core/bus/usb/usbhub.c | 2 +- grub-core/commands/hashsum.c | 2 +- grub-core/commands/setpci.c | 2 +- grub-core/disk/usbms.c | 2 +- grub-core/fs/zfs/zfs.c | 4 ++-- grub-core/gettext/gettext.c | 2 +- grub-core/gfxmenu/gfxmenu.c | 2 +- grub-core/lib/legacy_parse.c | 2 +- grub-core/lib/relocator.c | 4 ++-- grub-core/loader/i386/bsd.c | 2 +- grub-core/loader/i386/multiboot_mbi.c | 2 +- grub-core/loader/i386/xnu.c | 4 ++-- grub-core/loader/multiboot_mbi2.c | 2 +- grub-core/normal/auth.c | 2 +- grub-core/normal/context.c | 4 ++-- grub-core/normal/crypto.c | 2 +- grub-core/term/serial.c | 12 +++++----- grub-core/term/usb_keyboard.c | 2 +- 20 files changed, 61 insertions(+), 28 deletions(-) diff --git a/ChangeLog b/ChangeLog index 20fdfc86c..9527a6e8e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,36 @@ +2011-03-23 Vladimir Serbinenko + + * grub-core/bus/usb/usb.c (attach_hooks): Make static. + * grub-core/bus/usb/usbhub.c (hubs): Likewise. + * grub-core/commands/hashsum.c (aliases): Likewise. + * grub-core/commands/setpci.c (pci_registers): Likewise. + * grub-core/disk/usbms.c (attach_hook): Likewise. + * grub-core/fs/zfs/zfs.c (decomp_table): Likewise. + (zio_checksum_table): Likewise. + * grub-core/gettext/gettext.c (grub_gettext_msg_list): Likewise. + * grub-core/gfxmenu/gfxmenu.c (cached_view): Likewise. + * grub-core/lib/legacy_parse.c (legacy_commands): Likewise. + * grub-core/lib/relocator.c (leftovers): Likewise. + (extra_blocks): Likewise. + * grub-core/loader/i386/bsd.c (relocator): Likewise. + * grub-core/loader/i386/multiboot_mbi.c (modules): Likewise. + (modules_last): Likewise. + * grub-core/loader/i386/xnu.c (table_aliases): Likewise. + (devices): Likewise. + * grub-core/loader/multiboot_mbi2.c (modules): Likewise. + (modules_last): Likewise. + * grub-core/normal/auth.c (users): Likewise. + * grub-core/normal/context.c (initial_menu): Likewise. + (current_menu): Likewise. + * grub-core/normal/crypto.c (crypto_specs): Likewise. + * grub-core/term/serial.c (grub_serial_ports): Likewise. + (grub_serial_terminfo_input_template): Likewise. + (grub_serial_terminfo_output_template): Likewise. + (grub_serial_terminfo_input): Likewise. + (grub_serial_terminfo_output): Likewise. + (registered): Likewise. + * grub-core/term/usb_keyboard.c (attach_hook): Likewise. + 2011-03-23 Vladimir Serbinenko * grub-core/video/bochs.c (grub_video_bochs_setup): Use diff --git a/grub-core/bus/usb/usb.c b/grub-core/bus/usb/usb.c index 2bd805ef2..70173b7ea 100644 --- a/grub-core/bus/usb/usb.c +++ b/grub-core/bus/usb/usb.c @@ -25,7 +25,7 @@ #include static grub_usb_controller_dev_t grub_usb_list; -struct grub_usb_attach_desc *attach_hooks; +static struct grub_usb_attach_desc *attach_hooks; void grub_usb_controller_dev_register (grub_usb_controller_dev_t usb) diff --git a/grub-core/bus/usb/usbhub.c b/grub-core/bus/usb/usbhub.c index f08910d2b..492be914c 100644 --- a/grub-core/bus/usb/usbhub.c +++ b/grub-core/bus/usb/usbhub.c @@ -39,7 +39,7 @@ struct grub_usb_hub grub_usb_device_t dev; }; -struct grub_usb_hub *hubs; +static struct grub_usb_hub *hubs; /* Add a device that currently has device number 0 and resides on CONTROLLER, the Hub reported that the device speed is SPEED. */ diff --git a/grub-core/commands/hashsum.c b/grub-core/commands/hashsum.c index 8b6806e45..664fe9c24 100644 --- a/grub-core/commands/hashsum.c +++ b/grub-core/commands/hashsum.c @@ -36,7 +36,7 @@ static const struct grub_arg_option options[] = { {0, 0, 0, 0, 0, 0} }; -struct { const char *name; const char *hashname; } aliases[] = +static struct { const char *name; const char *hashname; } aliases[] = { {"sha256sum", "sha256"}, {"sha512sum", "sha512"}, diff --git a/grub-core/commands/setpci.c b/grub-core/commands/setpci.c index 7b194ed17..88dfa4c08 100644 --- a/grub-core/commands/setpci.c +++ b/grub-core/commands/setpci.c @@ -32,7 +32,7 @@ struct pci_register unsigned size; }; -struct pci_register pci_registers[] = +static struct pci_register pci_registers[] = { {"VENDOR_ID", GRUB_PCI_REG_VENDOR , 2}, {"DEVICE_ID", GRUB_PCI_REG_DEVICE , 2}, diff --git a/grub-core/disk/usbms.c b/grub-core/disk/usbms.c index e63105ccc..2e5d2459a 100644 --- a/grub-core/disk/usbms.c +++ b/grub-core/disk/usbms.c @@ -408,7 +408,7 @@ static struct grub_scsi_dev grub_usbms_dev = .write = grub_usbms_write }; -struct grub_usb_attach_desc attach_hook = +static struct grub_usb_attach_desc attach_hook = { .class = GRUB_USB_CLASS_MASS_STORAGE, .hook = grub_usbms_attach diff --git a/grub-core/fs/zfs/zfs.c b/grub-core/fs/zfs/zfs.c index 3a94d8874..8e83ea0b5 100644 --- a/grub-core/fs/zfs/zfs.c +++ b/grub-core/fs/zfs/zfs.c @@ -161,7 +161,7 @@ struct grub_zfs_data grub_disk_addr_t vdev_phys_sector; }; -decomp_entry_t decomp_table[ZIO_COMPRESS_FUNCTIONS] = { +static decomp_entry_t decomp_table[ZIO_COMPRESS_FUNCTIONS] = { {"inherit", NULL}, /* ZIO_COMPRESS_INHERIT */ {"on", lzjb_decompress}, /* ZIO_COMPRESS_ON */ {"off", NULL}, /* ZIO_COMPRESS_OFF */ @@ -201,7 +201,7 @@ zio_checksum_off (const void *buf __attribute__ ((unused)), } /* Checksum Table and Values */ -zio_checksum_info_t zio_checksum_table[ZIO_CHECKSUM_FUNCTIONS] = { +static zio_checksum_info_t zio_checksum_table[ZIO_CHECKSUM_FUNCTIONS] = { {NULL, 0, 0, "inherit"}, {NULL, 0, 0, "on"}, {zio_checksum_off, 0, 0, "off"}, diff --git a/grub-core/gettext/gettext.c b/grub-core/gettext/gettext.c index 5c7db4408..84937f19b 100644 --- a/grub-core/gettext/gettext.c +++ b/grub-core/gettext/gettext.c @@ -49,7 +49,7 @@ struct grub_gettext_msg const char *translated; }; -struct grub_gettext_msg *grub_gettext_msg_list = NULL; +static struct grub_gettext_msg *grub_gettext_msg_list = NULL; #define GETTEXT_MAGIC_NUMBER 0 #define GETTEXT_FILE_FORMAT 4 diff --git a/grub-core/gfxmenu/gfxmenu.c b/grub-core/gfxmenu/gfxmenu.c index 1acab9ca7..76d83c44b 100644 --- a/grub-core/gfxmenu/gfxmenu.c +++ b/grub-core/gfxmenu/gfxmenu.c @@ -37,7 +37,7 @@ #include #include -grub_gfxmenu_view_t cached_view; +static grub_gfxmenu_view_t cached_view; static void grub_gfxmenu_viewer_fini (void *data __attribute__ ((unused))) diff --git a/grub-core/lib/legacy_parse.c b/grub-core/lib/legacy_parse.c index fe421af35..fb1a52bf8 100644 --- a/grub-core/lib/legacy_parse.c +++ b/grub-core/lib/legacy_parse.c @@ -58,7 +58,7 @@ struct legacy_command const char *longdesc; }; -struct legacy_command legacy_commands[] = +static struct legacy_command legacy_commands[] = { {"blocklist", "blocklist '%s'\n", NULL, 0, 1, {TYPE_FILE}, 0, "FILE", "Print the blocklist notation of the file FILE."}, diff --git a/grub-core/lib/relocator.c b/grub-core/lib/relocator.c index dbd5fe4d0..e1bb7b7ea 100644 --- a/grub-core/lib/relocator.c +++ b/grub-core/lib/relocator.c @@ -77,10 +77,10 @@ struct grub_relocator_fw_leftover grub_uint8_t freebytes[GRUB_RELOCATOR_FIRMWARE_REQUESTS_QUANT / 8]; }; -struct grub_relocator_fw_leftover *leftovers; +static struct grub_relocator_fw_leftover *leftovers; #endif -struct grub_relocator_extra_block *extra_blocks; +static struct grub_relocator_extra_block *extra_blocks; void * get_virtual_current_address (grub_relocator_chunk_t in) diff --git a/grub-core/loader/i386/bsd.c b/grub-core/loader/i386/bsd.c index 08cdcda37..ecd5bd5cd 100644 --- a/grub-core/loader/i386/bsd.c +++ b/grub-core/loader/i386/bsd.c @@ -65,7 +65,7 @@ static void *kern_chunk_src; static grub_uint32_t bootflags; static int is_elf_kernel, is_64bit; static grub_uint32_t openbsd_root; -struct grub_relocator *relocator = NULL; +static struct grub_relocator *relocator = NULL; static struct grub_openbsd_ramdisk_descriptor openbsd_ramdisk; struct bsd_tag diff --git a/grub-core/loader/i386/multiboot_mbi.c b/grub-core/loader/i386/multiboot_mbi.c index b98bda223..14db50bcd 100644 --- a/grub-core/loader/i386/multiboot_mbi.c +++ b/grub-core/loader/i386/multiboot_mbi.c @@ -46,7 +46,7 @@ struct module int cmdline_size; }; -struct module *modules, *modules_last; +static struct module *modules, *modules_last; static grub_size_t cmdline_size; static grub_size_t total_modcmd; static unsigned modcnt; diff --git a/grub-core/loader/i386/xnu.c b/grub-core/loader/i386/xnu.c index a0df6f4aa..b877b0ea5 100644 --- a/grub-core/loader/i386/xnu.c +++ b/grub-core/loader/i386/xnu.c @@ -49,7 +49,7 @@ struct tbl_alias char *name; }; -struct tbl_alias table_aliases[] = +static struct tbl_alias table_aliases[] = { {GRUB_EFI_ACPI_20_TABLE_GUID, "ACPI_20"}, {GRUB_EFI_ACPI_TABLE_GUID, "ACPI"}, @@ -219,7 +219,7 @@ struct property_descriptor void *data; }; -struct grub_xnu_devprop_device_descriptor *devices = 0; +static struct grub_xnu_devprop_device_descriptor *devices = 0; grub_err_t grub_xnu_devprop_remove_property (struct grub_xnu_devprop_device_descriptor *dev, diff --git a/grub-core/loader/multiboot_mbi2.c b/grub-core/loader/multiboot_mbi2.c index 3141f0028..05f581bb6 100644 --- a/grub-core/loader/multiboot_mbi2.c +++ b/grub-core/loader/multiboot_mbi2.c @@ -54,7 +54,7 @@ struct module int cmdline_size; }; -struct module *modules, *modules_last; +static struct module *modules, *modules_last; static grub_size_t cmdline_size; static grub_size_t total_modcmd; static unsigned modcnt; diff --git a/grub-core/normal/auth.c b/grub-core/normal/auth.c index e5d187f0e..8e19568e2 100644 --- a/grub-core/normal/auth.c +++ b/grub-core/normal/auth.c @@ -34,7 +34,7 @@ struct grub_auth_user int authenticated; }; -struct grub_auth_user *users = NULL; +static struct grub_auth_user *users = NULL; grub_err_t grub_auth_register_authentication (const char *user, diff --git a/grub-core/normal/context.c b/grub-core/normal/context.c index 108679913..581316603 100644 --- a/grub-core/normal/context.c +++ b/grub-core/normal/context.c @@ -31,8 +31,8 @@ struct menu_pointer struct menu_pointer *prev; }; -struct menu_pointer initial_menu; -struct menu_pointer *current_menu = &initial_menu; +static struct menu_pointer initial_menu; +static struct menu_pointer *current_menu = &initial_menu; void grub_env_unset_menu (void) diff --git a/grub-core/normal/crypto.c b/grub-core/normal/crypto.c index 465c9f81d..19dafd8a7 100644 --- a/grub-core/normal/crypto.c +++ b/grub-core/normal/crypto.c @@ -31,7 +31,7 @@ struct load_spec char *modname; }; -struct load_spec *crypto_specs = NULL; +static struct load_spec *crypto_specs = NULL; static void grub_crypto_autoload (const char *name) diff --git a/grub-core/term/serial.c b/grub-core/term/serial.c index e672a89d6..32628dbae 100644 --- a/grub-core/term/serial.c +++ b/grub-core/term/serial.c @@ -41,7 +41,7 @@ static const struct grub_arg_option options[] = {0, 0, 0, 0, 0, 0} }; -struct grub_serial_port *grub_serial_ports; +static struct grub_serial_port *grub_serial_ports; struct grub_serial_output_state { @@ -69,7 +69,7 @@ serial_fetch (grub_term_input_t term) return data->port->driver->fetch (data->port); } -const struct grub_serial_input_state grub_serial_terminfo_input_template = +static const struct grub_serial_input_state grub_serial_terminfo_input_template = { .tinfo = { @@ -77,7 +77,7 @@ const struct grub_serial_input_state grub_serial_terminfo_input_template = } }; -const struct grub_serial_output_state grub_serial_terminfo_output_template = +static const struct grub_serial_output_state grub_serial_terminfo_output_template = { .tinfo = { @@ -87,11 +87,11 @@ const struct grub_serial_output_state grub_serial_terminfo_output_template = } }; -struct grub_serial_input_state grub_serial_terminfo_input; +static struct grub_serial_input_state grub_serial_terminfo_input; -struct grub_serial_output_state grub_serial_terminfo_output; +static struct grub_serial_output_state grub_serial_terminfo_output; -int registered = 0; +static int registered = 0; static struct grub_term_input grub_serial_term_input = { diff --git a/grub-core/term/usb_keyboard.c b/grub-core/term/usb_keyboard.c index 30ed8f9c2..23c0c10ca 100644 --- a/grub-core/term/usb_keyboard.c +++ b/grub-core/term/usb_keyboard.c @@ -435,7 +435,7 @@ grub_usb_keyboard_getkeystatus (struct grub_term_input *term) return interpret_status (termdata->status) | termdata->mods; } -struct grub_usb_attach_desc attach_hook = +static struct grub_usb_attach_desc attach_hook = { .class = GRUB_USB_CLASS_HID, .hook = grub_usb_keyboard_attach From d1611f0163f1915b1de994c2cc1bd5f315b16dae Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 23 Mar 2011 12:08:33 +0100 Subject: [PATCH 314/869] * grub-core/efiemu/i386/pc/cfgtables.c (grub_machine_efiemu_init_tables): Make declaration a prototype. * grub-core/loader/xnu.c (grub_xnu_lock): Likewise. (grub_xnu_unlock): Likewise. * grub-core/normal/cmdline.c (grub_cmdline_get/cl_set_pos_all): Likewise. --- ChangeLog | 8 ++++++++ grub-core/efiemu/i386/pc/cfgtables.c | 2 +- grub-core/loader/xnu.c | 4 ++-- grub-core/normal/cmdline.c | 2 +- 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9527a6e8e..1f7de420e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2011-03-23 Vladimir Serbinenko + + * grub-core/efiemu/i386/pc/cfgtables.c + (grub_machine_efiemu_init_tables): Make declaration a prototype. + * grub-core/loader/xnu.c (grub_xnu_lock): Likewise. + (grub_xnu_unlock): Likewise. + * grub-core/normal/cmdline.c (grub_cmdline_get/cl_set_pos_all): Likewise. + 2011-03-23 Vladimir Serbinenko * grub-core/bus/usb/usb.c (attach_hooks): Make static. diff --git a/grub-core/efiemu/i386/pc/cfgtables.c b/grub-core/efiemu/i386/pc/cfgtables.c index 9287d3a94..7b6a40c87 100644 --- a/grub-core/efiemu/i386/pc/cfgtables.c +++ b/grub-core/efiemu/i386/pc/cfgtables.c @@ -24,7 +24,7 @@ #include grub_err_t -grub_machine_efiemu_init_tables () +grub_machine_efiemu_init_tables (void) { grub_uint8_t *ptr; void *table; diff --git a/grub-core/loader/xnu.c b/grub-core/loader/xnu.c index 5a84dea1c..73158fd10 100644 --- a/grub-core/loader/xnu.c +++ b/grub-core/loader/xnu.c @@ -1429,7 +1429,7 @@ grub_cmd_xnu_resume (grub_command_t cmd __attribute__ ((unused)), #endif void -grub_xnu_lock () +grub_xnu_lock (void) { if (!locked) grub_dl_ref (my_mod); @@ -1437,7 +1437,7 @@ grub_xnu_lock () } void -grub_xnu_unlock () +grub_xnu_unlock (void) { if (locked) grub_dl_unref (my_mod); diff --git a/grub-core/normal/cmdline.c b/grub-core/normal/cmdline.c index b8c20d91c..09f2271ea 100644 --- a/grub-core/normal/cmdline.c +++ b/grub-core/normal/cmdline.c @@ -240,7 +240,7 @@ grub_cmdline_get (const char *prompt) grub_term_gotoxy (cl_term->term, cl_term->xpos, cl_term->ypos); } - void cl_set_pos_all () + void cl_set_pos_all (void) { unsigned i; for (i = 0; i < nterms; i++) From ed57e55702eac9ce24a8db0b4b7e5d40794a36a5 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 23 Mar 2011 12:13:39 +0100 Subject: [PATCH 315/869] * grub-core/bus/usb/uhci.c (grub_uhci_detect_dev): Return GRUB_USB_SPEED_NONE in case of failure and not the error code. --- ChangeLog | 5 +++++ grub-core/bus/usb/uhci.c | 3 +-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1f7de420e..d1d946075 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-03-23 Vladimir Serbinenko + + * grub-core/bus/usb/uhci.c (grub_uhci_detect_dev): Return + GRUB_USB_SPEED_NONE in case of failure and not the error code. + 2011-03-23 Vladimir Serbinenko * grub-core/efiemu/i386/pc/cfgtables.c diff --git a/grub-core/bus/usb/uhci.c b/grub-core/bus/usb/uhci.c index d082beac4..71142846b 100644 --- a/grub-core/bus/usb/uhci.c +++ b/grub-core/bus/usb/uhci.c @@ -749,8 +749,7 @@ grub_uhci_detect_dev (grub_usb_controller_t dev, int port, int *changed) else if (port == 1) reg = GRUB_UHCI_REG_PORTSC2; else - return grub_error (GRUB_ERR_OUT_OF_RANGE, - "UHCI Root Hub port does not exist"); + return GRUB_USB_SPEED_NONE; status = grub_uhci_readreg16 (u, reg); From 2e3e2e09081afd7b50391182401c7c90f8a9e9c7 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 23 Mar 2011 12:17:05 +0100 Subject: [PATCH 316/869] * grub-core/bus/usb/usbtrans.c (grub_usb_control_msg): Return usb-style error and not grub_errno. * grub-core/bus/usb/usbhub.c (grub_usb_add_hub): Likewise. --- ChangeLog | 6 ++++++ grub-core/bus/usb/usbtrans.c | 6 +++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index d1d946075..87f78e0bd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2011-03-23 Vladimir Serbinenko + + * grub-core/bus/usb/usbtrans.c (grub_usb_control_msg): Return usb-style + error and not grub_errno. + * grub-core/bus/usb/usbhub.c (grub_usb_add_hub): Likewise. + 2011-03-23 Vladimir Serbinenko * grub-core/bus/usb/uhci.c (grub_uhci_detect_dev): Return diff --git a/grub-core/bus/usb/usbtrans.c b/grub-core/bus/usb/usbtrans.c index ebb8a2eb6..167fae5a2 100644 --- a/grub-core/bus/usb/usbtrans.c +++ b/grub-core/bus/usb/usbtrans.c @@ -97,7 +97,7 @@ grub_usb_control_msg (grub_usb_device_t dev, if (! transfer) { grub_dma_free (data_chunk); - return grub_errno; + return GRUB_USB_ERR_INTERNAL; } setupdata_chunk = grub_memalign_dma32 (32, sizeof (*setupdata)); @@ -105,7 +105,7 @@ grub_usb_control_msg (grub_usb_device_t dev, { grub_free (transfer); grub_dma_free (data_chunk); - return grub_errno; + return GRUB_USB_ERR_INTERNAL; } setupdata = grub_dma_get_virt (setupdata_chunk); @@ -139,7 +139,7 @@ grub_usb_control_msg (grub_usb_device_t dev, grub_free (transfer); grub_dma_free (setupdata_chunk); grub_dma_free (data_chunk); - return grub_errno; + return GRUB_USB_ERR_INTERNAL; } /* Build a Setup packet. XXX: Endianness. */ From e804e7b099ca8cf2feddd92682ba617423159afa Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 23 Mar 2011 12:18:21 +0100 Subject: [PATCH 317/869] missing file in last change --- grub-core/bus/usb/usbhub.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/grub-core/bus/usb/usbhub.c b/grub-core/bus/usb/usbhub.c index 492be914c..82bb2da1c 100644 --- a/grub-core/bus/usb/usbhub.c +++ b/grub-core/bus/usb/usbhub.c @@ -110,7 +110,7 @@ static grub_usb_err_t grub_usb_add_hub (grub_usb_device_t dev) { struct grub_usb_usb_hubdesc hubdesc; - grub_err_t err; + grub_usb_err_t err; int i; err = grub_usb_control_msg (dev, (GRUB_USB_REQTYPE_IN From b1d2840445c6b471e600f7d6177b6fc56bffc666 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 23 Mar 2011 12:21:15 +0100 Subject: [PATCH 318/869] * grub-core/disk/usbms.c (grub_usbms_reset): Transform USB-style error into GRUB-style one. --- ChangeLog | 5 +++++ grub-core/disk/usbms.c | 6 +++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 87f78e0bd..20a83dd84 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-03-23 Vladimir Serbinenko + + * grub-core/disk/usbms.c (grub_usbms_reset): Transform USB-style error + into GRUB-style one. + 2011-03-23 Vladimir Serbinenko * grub-core/bus/usb/usbtrans.c (grub_usb_control_msg): Return usb-style diff --git a/grub-core/disk/usbms.c b/grub-core/disk/usbms.c index 2e5d2459a..fcfe9e5d4 100644 --- a/grub-core/disk/usbms.c +++ b/grub-core/disk/usbms.c @@ -70,7 +70,11 @@ static int first_available_slot = 0; static grub_err_t grub_usbms_reset (grub_usb_device_t dev, int interface) { - return grub_usb_control_msg (dev, 0x21, 255, 0, interface, 0, 0); + grub_usb_err_t u; + u = grub_usb_control_msg (dev, 0x21, 255, 0, interface, 0, 0); + if (u) + return grub_error (GRUB_ERR_IO, "USB error %d", u); + return GRUB_ERR_NONE; } static void From fa3e01bfb5710c13daf92e0d107ae9ac39991209 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 23 Mar 2011 12:23:42 +0100 Subject: [PATCH 319/869] * grub-core/lib/i386/pc/biosnum.c: Add missing include. --- ChangeLog | 4 ++++ grub-core/lib/i386/pc/biosnum.c | 1 + 2 files changed, 5 insertions(+) diff --git a/ChangeLog b/ChangeLog index 20a83dd84..ac149aeaa 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2011-03-23 Vladimir Serbinenko + + * grub-core/lib/i386/pc/biosnum.c: Add missing include. + 2011-03-23 Vladimir Serbinenko * grub-core/disk/usbms.c (grub_usbms_reset): Transform USB-style error diff --git a/grub-core/lib/i386/pc/biosnum.c b/grub-core/lib/i386/pc/biosnum.c index 058c9d331..12771085a 100644 --- a/grub-core/lib/i386/pc/biosnum.c +++ b/grub-core/lib/i386/pc/biosnum.c @@ -19,6 +19,7 @@ #include #include #include +#include static int grub_get_root_biosnumber_default (void) From 537dc9bec6da41353c0df219a58cb378f0484091 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 23 Mar 2011 12:40:15 +0100 Subject: [PATCH 320/869] * grub-core/normal/main.c (GRUB_MOD_INIT): Export pager variable. --- ChangeLog | 4 ++++ grub-core/normal/main.c | 1 + 2 files changed, 5 insertions(+) diff --git a/ChangeLog b/ChangeLog index ac149aeaa..a6afeac29 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2011-03-23 Vladimir Serbinenko + + * grub-core/normal/main.c (GRUB_MOD_INIT): Export pager variable. + 2011-03-23 Vladimir Serbinenko * grub-core/lib/i386/pc/biosnum.c: Add missing include. diff --git a/grub-core/normal/main.c b/grub-core/normal/main.c index 69bf5e6b5..cefb1cb9b 100644 --- a/grub-core/normal/main.c +++ b/grub-core/normal/main.c @@ -496,6 +496,7 @@ GRUB_MOD_INIT(normal) grub_set_history (GRUB_DEFAULT_HISTORY_SIZE); grub_register_variable_hook ("pager", 0, grub_env_write_pager); + grub_env_export ("pager"); /* Register a command "normal" for the rescue mode. */ grub_register_command ("normal", grub_cmd_normal, From bae7fcc1ed5ac86f54f99f8033fa1980ad8a54dd Mon Sep 17 00:00:00 2001 From: Peter Jones Date: Wed, 23 Mar 2011 13:01:42 +0100 Subject: [PATCH 321/869] Fix incorrect assert failure reporting. * grub-core/tests/example_functional_test.c (example_test): Add a failure comment. * grub-core/tests/lib/test.c (add_failure): Renamed to ... (failure_start): ...this. Check that malloc succeeded. Don't call xvasprintf. Return failure struct. (failure_append_vtext): New function. (failure_append_text): Likewise. (add_failure): Likewise. (grub_test_assert_helper): Likewise. * include/grub/test.h (grub_test_assert_helper): New declaration. (grub_test_assert): Macro rewritten. --- ChangeLog | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/ChangeLog b/ChangeLog index a6afeac29..99cae9ba5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,19 @@ +2011-03-23 Peter Jones + + Fix incorrect assert failure reporting. + + * grub-core/tests/example_functional_test.c (example_test): Add + a failure comment. + * grub-core/tests/lib/test.c (add_failure): Renamed to ... + (failure_start): ...this. Check that malloc succeeded. + Don't call xvasprintf. Return failure struct. + (failure_append_vtext): New function. + (failure_append_text): Likewise. + (add_failure): Likewise. + (grub_test_assert_helper): Likewise. + * include/grub/test.h (grub_test_assert_helper): New declaration. + (grub_test_assert): Macro rewritten. + 2011-03-23 Vladimir Serbinenko * grub-core/normal/main.c (GRUB_MOD_INIT): Export pager variable. From bd4d051a9517992ddcc291110ba52dd9efe743e8 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 23 Mar 2011 13:23:50 +0100 Subject: [PATCH 322/869] * grub-core/script/parser.y: Declare "time" as valid argument. --- ChangeLog | 4 ++++ grub-core/script/parser.y | 1 + 2 files changed, 5 insertions(+) diff --git a/ChangeLog b/ChangeLog index 99cae9ba5..3330a357b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2011-03-23 Vladimir Serbinenko + + * grub-core/script/parser.y: Declare "time" as valid argument. + 2011-03-23 Peter Jones Fix incorrect assert failure reporting. diff --git a/grub-core/script/parser.y b/grub-core/script/parser.y index 88c7fe9e3..683b3ac4b 100644 --- a/grub-core/script/parser.y +++ b/grub-core/script/parser.y @@ -147,6 +147,7 @@ argument : "case" { $$ = grub_script_add_arglist (state, 0, $1); } | "until" { $$ = grub_script_add_arglist (state, 0, $1); } | "while" { $$ = grub_script_add_arglist (state, 0, $1); } | "function" { $$ = grub_script_add_arglist (state, 0, $1); } + | "time" { $$ = grub_script_add_arglist (state, 0, $1); } | word { $$ = $1; } ; From 59e1e5f17ba434d6fbf66de4014471f01c1c00e2 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 23 Mar 2011 14:18:56 +0100 Subject: [PATCH 323/869] * grub-core/normal/menu_entry.c (init_line): Fix off-by-one error. --- ChangeLog | 4 ++++ grub-core/normal/menu_entry.c | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 3330a357b..c7bc69f58 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2011-03-23 Vladimir Serbinenko + + * grub-core/normal/menu_entry.c (init_line): Fix off-by-one error. + 2011-03-23 Vladimir Serbinenko * grub-core/script/parser.y: Declare "time" as valid argument. diff --git a/grub-core/normal/menu_entry.c b/grub-core/normal/menu_entry.c index e744d8d69..94f6e7f32 100644 --- a/grub-core/normal/menu_entry.c +++ b/grub-core/normal/menu_entry.c @@ -87,7 +87,7 @@ init_line (struct line *linep) { linep->len = 0; linep->max_len = 80; /* XXX */ - linep->buf = grub_malloc (linep->max_len); + linep->buf = grub_malloc (linep->max_len + 1); if (! linep->buf) return 0; From ebad0b81be1e6cd148688bcb0c4192b1923a51d0 Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Wed, 23 Mar 2011 14:45:04 +0000 Subject: [PATCH 324/869] remove unused variable --- grub-core/kern/emu/getroot.c | 1 - 1 file changed, 1 deletion(-) diff --git a/grub-core/kern/emu/getroot.c b/grub-core/kern/emu/getroot.c index 601ac8b04..71b9a3c50 100644 --- a/grub-core/kern/emu/getroot.c +++ b/grub-core/kern/emu/getroot.c @@ -131,7 +131,6 @@ grub_find_root_device_from_mountinfo (const char *dir, char **relroot) size_t enc_path_len; const char *sep; char fstype[PATH_MAX], device[PATH_MAX]; - struct stat st; if (sscanf (buf, "%d %d %u:%u %s %s%n", &mnt_id, &parent_mnt_id, &major, &minor, enc_root, enc_path, From 41a85f5508774c85e569917a0e9f6d5371b055a3 Mon Sep 17 00:00:00 2001 From: Alexander Kurtz Date: Wed, 23 Mar 2011 17:08:56 +0100 Subject: [PATCH 325/869] * grub-core/video/bitmap.c (match_extension): Ignore case. --- ChangeLog | 4 ++++ grub-core/video/bitmap.c | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index c7bc69f58..e462dddc0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2011-03-23 Alexander Kurtz + + * grub-core/video/bitmap.c (match_extension): Ignore case. + 2011-03-23 Vladimir Serbinenko * grub-core/normal/menu_entry.c (init_line): Fix off-by-one error. diff --git a/grub-core/video/bitmap.c b/grub-core/video/bitmap.c index e06a5b696..659ab9a57 100644 --- a/grub-core/video/bitmap.c +++ b/grub-core/video/bitmap.c @@ -177,7 +177,7 @@ match_extension (const char *filename, const char *ext) pos -= ext_len; - return grub_strcmp (filename + pos, ext) == 0; + return grub_strcasecmp (filename + pos, ext) == 0; } /* Loads bitmap using registered bitmap readers. */ From 5657722c3c59ad45f3bebf9dae1f881a0e5e0186 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 23 Mar 2011 20:29:17 +0100 Subject: [PATCH 326/869] * grub-core/term/gfxterm.c (calculate_normal_character_width): Return 8 if no ASCII character is found to prevent crash. --- ChangeLog | 5 +++++ grub-core/term/gfxterm.c | 2 ++ 2 files changed, 7 insertions(+) diff --git a/ChangeLog b/ChangeLog index e462dddc0..6e59b97ae 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-03-23 Vladimir Serbinenko + + * grub-core/term/gfxterm.c (calculate_normal_character_width): Return 8 + if no ASCII character is found to prevent crash. + 2011-03-23 Alexander Kurtz * grub-core/video/bitmap.c (match_extension): Ignore case. diff --git a/grub-core/term/gfxterm.c b/grub-core/term/gfxterm.c index 9a10d47b0..321479e0a 100644 --- a/grub-core/term/gfxterm.c +++ b/grub-core/term/gfxterm.c @@ -945,6 +945,8 @@ calculate_normal_character_width (grub_font_t font) if (glyph->device_width > width) width = glyph->device_width; } + if (!width) + return 8; return width; } From 8bc66a2ce617da1b721f7beebe8b0b164e733ae6 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Thu, 24 Mar 2011 12:28:22 +0100 Subject: [PATCH 327/869] * grub-core/loader/i386/bsdXX.c (grub_freebsd_load_elfmodule): Account for modules headers when counting the needed allocation size. --- ChangeLog | 5 +++++ grub-core/loader/i386/bsdXX.c | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/ChangeLog b/ChangeLog index 6e59b97ae..61adf1e26 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-03-24 Vladimir Serbinenko + + * grub-core/loader/i386/bsdXX.c (grub_freebsd_load_elfmodule): Account + for modules headers when counting the needed allocation size. + 2011-03-23 Vladimir Serbinenko * grub-core/term/gfxterm.c (calculate_normal_character_width): Return 8 diff --git a/grub-core/loader/i386/bsdXX.c b/grub-core/loader/i386/bsdXX.c index 5b9e7689e..92d267534 100644 --- a/grub-core/loader/i386/bsdXX.c +++ b/grub-core/loader/i386/bsdXX.c @@ -195,6 +195,11 @@ SUFFIX (grub_freebsd_load_elfmodule) (struct grub_relocator *relocator, chunk_size = s->sh_addr + s->sh_size; } + if (chunk_size < sizeof (e)) + chunk_size = sizeof (e); + chunk_size += e.e_phnum * e.e_phentsize; + chunk_size += e.e_shnum * e.e_shentsize; + { grub_relocator_chunk_t ch; From ef6de21af47aba0485951dac352ea6cadcb18535 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Thu, 24 Mar 2011 12:39:48 +0100 Subject: [PATCH 328/869] * grub-core/lib/relocator.c (allocate_inreg): Avoid dprintf unless DEBUG_RELOCATOR is defined since gfxterm can't cope with output when malloc is disabled. --- ChangeLog | 6 ++++++ grub-core/lib/relocator.c | 2 ++ 2 files changed, 8 insertions(+) diff --git a/ChangeLog b/ChangeLog index 61adf1e26..2cdeb6dc4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2011-03-24 Vladimir Serbinenko + + * grub-core/lib/relocator.c (allocate_inreg): Avoid dprintf unless + DEBUG_RELOCATOR is defined since gfxterm can't cope with output when + malloc is disabled. + 2011-03-24 Vladimir Serbinenko * grub-core/loader/i386/bsdXX.c (grub_freebsd_load_elfmodule): Account diff --git a/grub-core/lib/relocator.c b/grub-core/lib/relocator.c index e1bb7b7ea..421054176 100644 --- a/grub-core/lib/relocator.c +++ b/grub-core/lib/relocator.c @@ -200,10 +200,12 @@ allocate_inreg (grub_phys_addr_t paddr, grub_size_t size, struct grub_mm_header *foll = NULL; grub_addr_t vaddr = (grub_addr_t) hb + (paddr - grub_vtop (hb)); +#ifdef DEBUG_RELOCATOR grub_dprintf ("relocator", "inreg paddr = 0x%lx, size = %lu," " hb = %p, hbp = %p, rb = %p, vaddr = 0x%lx\n", (unsigned long) paddr, (unsigned long) size, hb, hbp, rb, (unsigned long) vaddr); +#endif if (ALIGN_UP (vaddr + size, GRUB_MM_ALIGN) + GRUB_MM_ALIGN <= (grub_addr_t) (hb + hb->size)) From 3f71cded814d7938bbb4e0d5bfa3b51440e3ffe4 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Thu, 24 Mar 2011 12:43:28 +0100 Subject: [PATCH 329/869] * include/grub/mm.h (GRUB_MM_CHECK): Rename to ... (grub_mm_check): ... this. MAke a function-like macro and use GRUB_FILE. --- ChangeLog | 5 +++++ include/grub/mm.h | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 2cdeb6dc4..cfce9988b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-03-24 Vladimir Serbinenko + + * include/grub/mm.h (GRUB_MM_CHECK): Rename to ... + (grub_mm_check): ... this. MAke a function-like macro and use GRUB_FILE. + 2011-03-24 Vladimir Serbinenko * grub-core/lib/relocator.c (allocate_inreg): Avoid dprintf unless diff --git a/include/grub/mm.h b/include/grub/mm.h index cc115907a..047006944 100644 --- a/include/grub/mm.h +++ b/include/grub/mm.h @@ -36,7 +36,7 @@ void *EXPORT_FUNC(grub_realloc) (void *ptr, grub_size_t size); void *EXPORT_FUNC(grub_memalign) (grub_size_t align, grub_size_t size); void grub_mm_check_real (char *file, int line); -#define GRUB_MM_CHECK grub_mm_check_real (__FILE__, __LINE__); +#define grub_mm_check() grub_mm_check_real (GRUB_FILE, __LINE__); /* For debugging. */ #if defined(MM_DEBUG) && !defined(GRUB_UTIL) && !defined (GRUB_MACHINE_EMU) From c7064d94250a9f9b78e5a08a44837626293fe596 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Thu, 24 Mar 2011 12:45:51 +0100 Subject: [PATCH 330/869] * grub-core/lib/relocator.c (grub_relocator_alloc_chunk_addr) [DEBUG_RELOCATOR]: Reuse grub_mm_check. (grub_relocator_alloc_chunk_align) [DEBUG_RELOCATOR]: Likewise. --- ChangeLog | 6 ++++++ grub-core/lib/relocator.c | 39 ++++----------------------------------- 2 files changed, 10 insertions(+), 35 deletions(-) diff --git a/ChangeLog b/ChangeLog index cfce9988b..8744dbff3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2011-03-24 Vladimir Serbinenko + + * grub-core/lib/relocator.c (grub_relocator_alloc_chunk_addr) + [DEBUG_RELOCATOR]: Reuse grub_mm_check. + (grub_relocator_alloc_chunk_align) [DEBUG_RELOCATOR]: Likewise. + 2011-03-24 Vladimir Serbinenko * include/grub/mm.h (GRUB_MM_CHECK): Rename to ... diff --git a/grub-core/lib/relocator.c b/grub-core/lib/relocator.c index 421054176..7d29ab5cc 100644 --- a/grub-core/lib/relocator.c +++ b/grub-core/lib/relocator.c @@ -1284,23 +1284,8 @@ grub_relocator_alloc_chunk_addr (struct grub_relocator *rel, chunk->srcv = grub_map_memory (chunk->src, chunk->size); *out = chunk; #ifdef DEBUG_RELOCATOR - { - grub_mm_region_t r; - grub_mm_header_t p; - grub_memset (chunk->srcv, 0xfa, chunk->size); - for (r = grub_mm_base; r; r = r->next) - { - p = r->first; - do - { - if ((grub_addr_t) p < (grub_addr_t) (r + 1) - || (grub_addr_t) p >= (grub_addr_t) (r + 1) + r->size) - grub_fatal (__FILE__ ":%d: out of range pointer: %p\n", __LINE__, p); - p = p->next; - } - while (p != r->first); - } - } + grub_memset (chunk->srcv, 0xfa, chunk->size); + grub_mm_check (); #endif return GRUB_ERR_NONE; } @@ -1438,24 +1423,8 @@ grub_relocator_alloc_chunk_align (struct grub_relocator *rel, chunk->srcv = grub_map_memory (chunk->src, chunk->size); *out = chunk; #ifdef DEBUG_RELOCATOR - { - grub_mm_region_t r; - grub_mm_header_t p; - - grub_memset (chunk->srcv, 0xfa, chunk->size); - for (r = grub_mm_base; r; r = r->next) - { - p = r->first; - do - { - if ((grub_addr_t) p < (grub_addr_t) (r + 1) - || (grub_addr_t) p >= (grub_addr_t) (r + 1) + r->size) - grub_fatal (__FILE__ "%d: out of range pointer: %p\n", __LINE__, p); - p = p->next; - } - while (p != r->first); - } - } + grub_memset (chunk->srcv, 0xfa, chunk->size); + grub_mm_check (); #endif return GRUB_ERR_NONE; } From 4c6c9431d2f72d6b7397a39e81e0112a01e3ec97 Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Fri, 25 Mar 2011 00:03:54 +0000 Subject: [PATCH 331/869] * grub-core/video/fb/video_fb.c (grub_video_fb_get_info_and_fini): Switch back to page zero before loading a kernel, since some kernel drivers expect that. Thanks to: Felix Kuehling. --- ChangeLog | 7 +++++++ grub-core/video/fb/video_fb.c | 14 ++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/ChangeLog b/ChangeLog index 8744dbff3..b556c77e8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2011-03-24 Colin Watson + + * grub-core/video/fb/video_fb.c (grub_video_fb_get_info_and_fini): + Switch back to page zero before loading a kernel, since some kernel + drivers expect that. + Thanks to: Felix Kuehling. + 2011-03-24 Vladimir Serbinenko * grub-core/lib/relocator.c (grub_relocator_alloc_chunk_addr) diff --git a/grub-core/video/fb/video_fb.c b/grub-core/video/fb/video_fb.c index 69626be5c..768b63328 100644 --- a/grub-core/video/fb/video_fb.c +++ b/grub-core/video/fb/video_fb.c @@ -1505,6 +1505,20 @@ grub_video_fb_get_info_and_fini (struct grub_video_mode_info *mode_info, { grub_memcpy (mode_info, &(framebuffer.front_target->mode_info), sizeof (*mode_info)); + + /* We are about to load a kernel. Switch back to page zero, since some + kernel drivers expect that. */ + if ((mode_info->mode_type & GRUB_VIDEO_MODE_TYPE_DOUBLE_BUFFERED) + && framebuffer.set_page && framebuffer.displayed_page != 0) + { + /* Ensure both pages are exactly in sync. */ + grub_memcpy (framebuffer.back_target->data, + framebuffer.front_target->data, + framebuffer.back_target->mode_info.pitch + * framebuffer.back_target->mode_info.height); + grub_video_swap_buffers (); + } + *framebuf = framebuffer.front_target->data; grub_video_fb_fini (); From 82fe6c751bb32337045a57a18f2bb1f05c91d47b Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 26 Mar 2011 12:49:34 +0100 Subject: [PATCH 332/869] Fix FreeBSD compilation problem. * grub-core/kern/emu/hostdisk.c (MAJOR) [FreeBSD]: New definition. (FLOPPY_MAJOR) [FreeBSD]: Likewise. --- ChangeLog | 7 +++++++ grub-core/kern/emu/hostdisk.c | 2 ++ 2 files changed, 9 insertions(+) diff --git a/ChangeLog b/ChangeLog index b556c77e8..bf69511a5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2011-03-26 Vladimir Serbinenko + + Fix FreeBSD compilation problem. + + * grub-core/kern/emu/hostdisk.c (MAJOR) [FreeBSD]: New definition. + (FLOPPY_MAJOR) [FreeBSD]: Likewise. + 2011-03-24 Colin Watson * grub-core/video/fb/video_fb.c (grub_video_fb_get_info_and_fini): diff --git a/grub-core/kern/emu/hostdisk.c b/grub-core/kern/emu/hostdisk.c index 12dbe7469..b4f51da0f 100644 --- a/grub-core/kern/emu/hostdisk.c +++ b/grub-core/kern/emu/hostdisk.c @@ -92,6 +92,8 @@ struct hd_geometry # include /* DIOCGMEDIASIZE */ # include # include +# define MAJOR(dev) major(dev) +# define FLOPPY_MAJOR 2 #endif #if defined(__APPLE__) From f4727da93f55ba7a959848117b4c9db9afaba3ff Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 26 Mar 2011 12:59:02 +0100 Subject: [PATCH 333/869] Use libgeom on FreeBSD to detect partitions. * Makefile.util.def (grub-mkimage): Add LIBGEOM to ldadd. (grub-mkrelpath): Likewise. (grub-script-check): Likewise. (grub-editenv): Likewise. (grub-mkpasswd-pbkdf2): Likewise. (grub-fstest): Likewise. (grub-mkfont): Likewise. (grub-mkdevicemap): Likewise. (grub-probe): Likewise. (grub-setup): Likewise. (grub-ofpathname): Likewise. (grub-mklayout): Likewise. (example_unit_test): Likewise. (grub-menulst2cfg): Likewise. * grub-core/Makefile.core.def (grub-emu): Likewise. (grub-emu-lite): Likewise. * configure.ac: Check for -lgeom on FreeBSD and set LIBGEOM. * grub-core/kern/emu/hostdisk.c [FreeBSD]: Include libgeom.h. Don't define HAVE_DIOCGDINFO. (follow_geom_up) [FreeBSD]: New function. (find_partition_start) [FreeBSD]: Rewritten using follow_geom_up. (convert_system_partition_to_system_disk) [FreeBSD]: Likewise. (grub_util_biosdisk_get_grub_dev) [FreeBSD]: Use FreeBSD path unconditionally of HAVE_DIOCGDINFO. --- ChangeLog | 29 +++++++++++++ Makefile.util.def | 28 ++++++------ configure.ac | 9 ++++ grub-core/Makefile.core.def | 4 +- grub-core/kern/emu/hostdisk.c | 82 +++++++++++++++++++++++++++++++++-- 5 files changed, 132 insertions(+), 20 deletions(-) diff --git a/ChangeLog b/ChangeLog index bf69511a5..0d902ecd6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,32 @@ +2011-03-26 Vladimir Serbinenko + + Use libgeom on FreeBSD to detect partitions. + + * Makefile.util.def (grub-mkimage): Add LIBGEOM to ldadd. + (grub-mkrelpath): Likewise. + (grub-script-check): Likewise. + (grub-editenv): Likewise. + (grub-mkpasswd-pbkdf2): Likewise. + (grub-fstest): Likewise. + (grub-mkfont): Likewise. + (grub-mkdevicemap): Likewise. + (grub-probe): Likewise. + (grub-setup): Likewise. + (grub-ofpathname): Likewise. + (grub-mklayout): Likewise. + (example_unit_test): Likewise. + (grub-menulst2cfg): Likewise. + * grub-core/Makefile.core.def (grub-emu): Likewise. + (grub-emu-lite): Likewise. + * configure.ac: Check for -lgeom on FreeBSD and set LIBGEOM. + * grub-core/kern/emu/hostdisk.c [FreeBSD]: Include libgeom.h. Don't + define HAVE_DIOCGDINFO. + (follow_geom_up) [FreeBSD]: New function. + (find_partition_start) [FreeBSD]: Rewritten using follow_geom_up. + (convert_system_partition_to_system_disk) [FreeBSD]: Likewise. + (grub_util_biosdisk_get_grub_dev) [FreeBSD]: Use FreeBSD path + unconditionally of HAVE_DIOCGDINFO. + 2011-03-26 Vladimir Serbinenko Fix FreeBSD compilation problem. diff --git a/Makefile.util.def b/Makefile.util.def index 74984e2e9..303baea3f 100644 --- a/Makefile.util.def +++ b/Makefile.util.def @@ -122,7 +122,7 @@ program = { ldadd = libgrubkern.a; ldadd = grub-core/gnulib/libgnu.a; ldadd = '$(LIBLZMA)'; - ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBZFS) $(LIBNVPAIR)'; + ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM)'; cppflags = '-DGRUB_PKGLIBROOTDIR=\"$(pkglibrootdir)\"'; }; @@ -135,7 +135,7 @@ program = { ldadd = libgrubmods.a; ldadd = libgrubkern.a; ldadd = grub-core/gnulib/libgnu.a; - ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBZFS) $(LIBNVPAIR)'; + ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM)'; }; program = { @@ -147,7 +147,7 @@ program = { ldadd = libgrubmods.a; ldadd = libgrubkern.a; ldadd = grub-core/gnulib/libgnu.a; - ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBZFS) $(LIBNVPAIR)'; + ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM)'; }; program = { @@ -159,7 +159,7 @@ program = { ldadd = libgrubmods.a; ldadd = libgrubkern.a; ldadd = grub-core/gnulib/libgnu.a; - ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBZFS) $(LIBNVPAIR)'; + ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM)'; }; program = { @@ -171,7 +171,7 @@ program = { ldadd = libgrubmods.a; ldadd = libgrubkern.a; ldadd = grub-core/gnulib/libgnu.a; - ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBZFS) $(LIBNVPAIR)'; + ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM)'; cflags = '$(CFLAGS_GCRY)'; cppflags = '$(CPPFLAGS_GCRY)'; }; @@ -209,7 +209,7 @@ program = { ldadd = libgrubmods.a; ldadd = libgrubkern.a; ldadd = grub-core/gnulib/libgnu.a; - ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBZFS) $(LIBNVPAIR)'; + ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM)'; }; program = { @@ -224,7 +224,7 @@ program = { ldadd = libgrubkern.a; ldadd = grub-core/gnulib/libgnu.a; ldadd = '$(freetype_libs)'; - ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBZFS) $(LIBNVPAIR)'; + ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM)'; condition = COND_GRUB_MKFONT; }; @@ -243,7 +243,7 @@ program = { ldadd = libgrubmods.a; ldadd = libgrubkern.a; ldadd = grub-core/gnulib/libgnu.a; - ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBUTIL) $(LIBZFS) $(LIBNVPAIR)'; + ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBUTIL) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM)'; }; program = { @@ -255,7 +255,7 @@ program = { ldadd = libgrubmods.a; ldadd = libgrubkern.a; ldadd = grub-core/gnulib/libgnu.a; - ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBUTIL) $(LIBZFS) $(LIBNVPAIR)'; + ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBUTIL) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM)'; }; program = { @@ -272,7 +272,7 @@ program = { ldadd = libgrubmods.a; ldadd = libgrubkern.a; ldadd = grub-core/gnulib/libgnu.a; - ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBUTIL) $(LIBZFS) $(LIBNVPAIR)'; + ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBUTIL) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM)'; enable = i386_pc; enable = sparc64_ieee1275; @@ -287,7 +287,7 @@ program = { ldadd = libgrubmods.a; ldadd = libgrubkern.a; ldadd = grub-core/gnulib/libgnu.a; - ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBUTIL)'; + ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBUTIL) $(LIBGEOM)'; enable = sparc64_ieee1275; }; @@ -301,7 +301,7 @@ program = { ldadd = libgrubmods.a; ldadd = libgrubkern.a; ldadd = grub-core/gnulib/libgnu.a; - ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBZFS) $(LIBNVPAIR)'; + ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM)'; }; data = { @@ -611,7 +611,7 @@ program = { ldadd = libgrubmods.a; ldadd = libgrubkern.a; ldadd = grub-core/gnulib/libgnu.a; - ldadd = '$(LIBDEVMAPPER) $(LIBZFS) $(LIBNVPAIR)'; + ldadd = '$(LIBDEVMAPPER) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM)'; }; program = { @@ -624,5 +624,5 @@ program = { ldadd = libgrubmods.a; ldadd = libgrubkern.a; ldadd = grub-core/gnulib/libgnu.a; - ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBZFS) $(LIBNVPAIR)'; + ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM)'; }; diff --git a/configure.ac b/configure.ac index c660ac41e..f9e974bca 100644 --- a/configure.ac +++ b/configure.ac @@ -890,6 +890,15 @@ fi AC_SUBST([LIBDEVMAPPER]) +LIBGEOM= +if test x$host_kernel = xkfreebsd; then + AC_CHECK_LIB([geom], [geom_gettree], [], + [AC_MSG_ERROR([Your platform requires libgeom])]) + LIBGEOM="-lgeom" +fi + +AC_SUBST([LIBGEOM]) + AC_CHECK_LIB([lzma], [lzma_code], [LIBLZMA="-llzma" AC_DEFINE([HAVE_LIBLZMA], [1], diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def index ce7d0b0c2..7c26b37e9 100644 --- a/grub-core/Makefile.core.def +++ b/grub-core/Makefile.core.def @@ -200,7 +200,7 @@ program = { ldadd = 'kernel.img$(EXEEXT)'; ldadd = '$(MODULE_FILES)'; - ldadd = '$(LIBUTIL) $(LIBCURSES) $(LIBSDL) $(LIBUSB) $(LIBPCIACCESS) $(LIBDEVMAPPER) $(LIBZFS) $(LIBNVPAIR)'; + ldadd = '$(LIBUTIL) $(LIBCURSES) $(LIBSDL) $(LIBUSB) $(LIBPCIACCESS) $(LIBDEVMAPPER) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM)'; enable = emu; }; @@ -212,7 +212,7 @@ program = { emu_nodist = symlist.c; ldadd = 'kernel.img$(EXEEXT)'; - ldadd = '$(LIBUTIL) $(LIBCURSES) $(LIBSDL) $(LIBUSB) $(LIBPCIACCESS) $(LIBDEVMAPPER) $(LIBZFS) $(LIBNVPAIR)'; + ldadd = '$(LIBUTIL) $(LIBCURSES) $(LIBSDL) $(LIBUSB) $(LIBPCIACCESS) $(LIBDEVMAPPER) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM)'; enable = emu; }; diff --git a/grub-core/kern/emu/hostdisk.c b/grub-core/kern/emu/hostdisk.c index b4f51da0f..73d023ce9 100644 --- a/grub-core/kern/emu/hostdisk.c +++ b/grub-core/kern/emu/hostdisk.c @@ -104,7 +104,9 @@ struct hd_geometry # include #endif -#if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__) +#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) +#include +#elif defined(__NetBSD__) # define HAVE_DIOCGDINFO # include # include /* struct disklabel */ @@ -339,7 +341,68 @@ device_is_mapped (const char *dev) } #endif /* HAVE_DEVICE_MAPPER */ -#if defined(__linux__) || defined(__CYGWIN__) || defined(HAVE_DIOCGDINFO) +#if defined (__FreeBSD__) || defined(__FreeBSD_kernel__) +/* FIXME: geom actually gives us the whole container hierarchy. + It can be used more efficiently than this. */ +static void +follow_geom_up (const char *name, grub_disk_addr_t *off_out, char **name_out) +{ + struct gmesh mesh; + struct gclass *class; + int error; + struct ggeom *geom; + + grub_util_info ("following geom '%s'", name); + + error = geom_gettree (&mesh); + if (error != 0) + grub_util_error ("couldn't open geom"); + + LIST_FOREACH (class, &mesh.lg_class, lg_class) + if (strcasecmp (class->lg_name, "part") == 0) + break; + if (!class) + grub_util_error ("couldn't open geom part"); + + LIST_FOREACH (geom, &class->lg_geom, lg_geom) + { + struct gprovider *provider; + LIST_FOREACH (provider, &geom->lg_provider, lg_provider) + if (strcmp (provider->lg_name, name) == 0) + { + char *name_tmp = xstrdup (geom->lg_name); + grub_disk_addr_t off = 0; + struct gconfig *config; + grub_util_info ("geom '%s' has parent '%s'", name, geom->lg_name); + + follow_geom_up (name_tmp, &off, name_out); + free (name_tmp); + LIST_FOREACH (config, &provider->lg_config, lg_config) + if (strcasecmp (config->lg_name, "start") == 0) + off += strtoull (config->lg_val, 0, 10); + if (off_out) + *off_out = off; + return; + } + } + grub_util_info ("geom '%s' has no parent", name); + if (name_out) + *name_out = xstrdup (name); + if (off_out) + *off_out = 0; +} + +static grub_disk_addr_t +find_partition_start (const char *dev) +{ + grub_disk_addr_t out; + if (strncmp (dev, "/dev/", sizeof ("/dev/") - 1) != 0) + return 0; + follow_geom_up (dev + sizeof ("/dev/") - 1, &out, NULL); + + return out; +} +#elif defined(__linux__) || defined(__CYGWIN__) || defined(HAVE_DIOCGDINFO) static grub_disk_addr_t find_partition_start (const char *dev) { @@ -1286,7 +1349,17 @@ devmapper_out: path[8] = 0; return path; -#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__APPLE__) +#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) + char *out, *out2; + if (strncmp (os_dev, "/dev/", sizeof ("/dev/") - 1) != 0) + return xstrdup (os_dev); + follow_geom_up (os_dev + sizeof ("/dev/") - 1, NULL, &out); + + out2 = xasprintf ("/dev/%s", out); + free (out); + + return out2; +#elif defined(__APPLE__) char *path = xstrdup (os_dev); if (strncmp ("/dev/", path, 5) == 0) { @@ -1464,7 +1537,8 @@ grub_util_biosdisk_get_grub_dev (const char *os_dev) #endif return make_device_name (drive, -1, -1); -#if defined(__linux__) || defined(__CYGWIN__) || defined(HAVE_DIOCGDINFO) +#if defined(__linux__) || defined(__CYGWIN__) || defined(HAVE_DIOCGDINFO) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__) + /* Linux counts partitions uniformly, whether a BSD partition or a DOS partition, so mapping them to GRUB devices is not trivial. Here, get the start sector of a partition by HDIO_GETGEO, and From 5ee04984d113205aa413eb9b36164d4d2543aa88 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 26 Mar 2011 14:14:59 +0100 Subject: [PATCH 334/869] * grub-core/fs/iso9660.c (grub_iso9660_label): Rtrim the label. --- ChangeLog | 4 ++++ grub-core/fs/iso9660.c | 9 +++++++++ 2 files changed, 13 insertions(+) diff --git a/ChangeLog b/ChangeLog index 0d902ecd6..741f0f013 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2011-03-26 Vladimir Serbinenko + + * grub-core/fs/iso9660.c (grub_iso9660_label): Rtrim the label. + 2011-03-26 Vladimir Serbinenko Use libgeom on FreeBSD to detect partitions. diff --git a/grub-core/fs/iso9660.c b/grub-core/fs/iso9660.c index 6dc465f25..f72249d20 100644 --- a/grub-core/fs/iso9660.c +++ b/grub-core/fs/iso9660.c @@ -808,6 +808,15 @@ grub_iso9660_label (grub_device_t device, char **label) ((grub_uint16_t *) &data->voldesc.volname, 16); else *label = grub_strndup ((char *) data->voldesc.volname, 32); + if (*label) + { + char *ptr; + for (ptr = *label; *ptr;ptr++); + ptr--; + while (ptr >= *label && *ptr == ' ') + *ptr-- = 0; + } + grub_free (data); } else From c482ad98b370a53f2eac04eec824903ba1a557e6 Mon Sep 17 00:00:00 2001 From: Seth Goldberg Date: Sat, 26 Mar 2011 23:22:59 +0100 Subject: [PATCH 335/869] * grub-core/kern/emu/getroot.c (find_root_device_from_libzfs): Don't return freed string. --- ChangeLog | 5 +++++ grub-core/kern/emu/getroot.c | 7 +++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 741f0f013..39ec5742e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-03-26 Seth Goldberg + + * grub-core/kern/emu/getroot.c (find_root_device_from_libzfs): Don't + return freed string. + 2011-03-26 Vladimir Serbinenko * grub-core/fs/iso9660.c (grub_iso9660_label): Rtrim the label. diff --git a/grub-core/kern/emu/getroot.c b/grub-core/kern/emu/getroot.c index 110e58b14..1d87442d9 100644 --- a/grub-core/kern/emu/getroot.c +++ b/grub-core/kern/emu/getroot.c @@ -184,7 +184,7 @@ find_root_device_from_mountinfo (const char *dir) static char * find_root_device_from_libzfs (const char *dir) { - char *device; + char *device = NULL; char *poolname; char *poolfs; @@ -225,7 +225,10 @@ find_root_device_from_libzfs (const char *dir) struct stat st; if (stat (device, &st) == 0) - break; + { + device = xstrdup (device); + break; + } device = NULL; } From f329eda79eb0340e148f6c827c910c317e083822 Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Mon, 28 Mar 2011 13:23:54 +0100 Subject: [PATCH 336/869] * grub-core/disk/raid.c (grub_raid_register): Adjust debug message to be specific about what kind of RAID device we're scanning for. --- ChangeLog | 5 +++++ grub-core/disk/raid.c | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 39ec5742e..24b608417 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-03-28 Colin Watson + + * grub-core/disk/raid.c (grub_raid_register): Adjust debug message + to be specific about what kind of RAID device we're scanning for. + 2011-03-26 Seth Goldberg * grub-core/kern/emu/getroot.c (find_root_device_from_libzfs): Don't diff --git a/grub-core/disk/raid.c b/grub-core/disk/raid.c index 3972e1632..9d2468b88 100644 --- a/grub-core/disk/raid.c +++ b/grub-core/disk/raid.c @@ -696,7 +696,8 @@ grub_raid_register (grub_raid_t raid) 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 %s RAID devices on disk %s\n", + grub_raid_list->name, name); disk = grub_disk_open (name); if (!disk) From 24148725381450cc2dd2b4a19a0b496d22a304ba Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Mon, 28 Mar 2011 15:17:22 +0100 Subject: [PATCH 337/869] * grub-core/disk/mdraid1x_linux.c (grub_mdraid_detect): Remove stale comment. --- ChangeLog | 5 +++++ grub-core/disk/mdraid1x_linux.c | 1 - 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 24b608417..d6afea1d2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-03-28 Colin Watson + + * grub-core/disk/mdraid1x_linux.c (grub_mdraid_detect): Remove stale + comment. + 2011-03-28 Colin Watson * grub-core/disk/raid.c (grub_raid_register): Adjust debug message diff --git a/grub-core/disk/mdraid1x_linux.c b/grub-core/disk/mdraid1x_linux.c index f2e7555cb..296d1375b 100644 --- a/grub-core/disk/mdraid1x_linux.c +++ b/grub-core/disk/mdraid1x_linux.c @@ -110,7 +110,6 @@ grub_mdraid_detect (grub_disk_t disk, struct grub_raid_array *array, struct grub_raid_super_1x sb; grub_uint8_t minor_version; - /* The sector where the mdraid 0.90 superblock is stored, if available. */ size = grub_disk_get_size (disk); /* Check for an 1.x superblock. From 09573499ff62ebbeabfedc45dd8106ba715cbdf3 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Tue, 29 Mar 2011 02:02:55 +0200 Subject: [PATCH 338/869] Initial variable sector size support --- grub-core/disk/efi/efidisk.c | 17 ++++--- grub-core/disk/i386/pc/biosdisk.c | 52 +++++++++++---------- grub-core/disk/scsi.c | 36 +++++---------- grub-core/kern/disk.c | 77 +++++++++++++++++++++++-------- grub-core/kern/emu/hostdisk.c | 37 ++++++++++----- grub-core/partmap/msdos.c | 22 ++++++--- include/grub/disk.h | 10 ++-- 7 files changed, 155 insertions(+), 96 deletions(-) diff --git a/grub-core/disk/efi/efidisk.c b/grub-core/disk/efi/efidisk.c index 08094fa5c..20fea956f 100644 --- a/grub-core/disk/efi/efidisk.c +++ b/grub-core/disk/efi/efidisk.c @@ -536,8 +536,13 @@ grub_efidisk_open (const char *name, struct grub_disk *disk) and total sectors should be replaced with total blocks. */ grub_dprintf ("efidisk", "m = %p, last block = %llx, block size = %x\n", m, (unsigned long long) m->last_block, m->block_size); - disk->total_sectors = (m->last_block - * (m->block_size >> GRUB_DISK_SECTOR_BITS)); + disk->total_sectors = m->last_block; + if (m->blocksize & (m->blocksize - 1) || !m->blocksize) + return grub_error (GRUB_ERR_IO, "invalid sector size %d", + m->blocksize); + for (disk->log_sector_size = 0; + (1 << disk->log_sector_size) < m->blocksize; + disk->log_sector_size++); disk->data = d; grub_dprintf ("efidisk", "opening %s succeeded\n", name); @@ -571,8 +576,8 @@ grub_efidisk_read (struct grub_disk *disk, grub_disk_addr_t sector, (unsigned long) size, (unsigned long long) sector, disk->name); status = efi_call_5 (dio->read, dio, bio->media->media_id, - (grub_efi_uint64_t) sector << GRUB_DISK_SECTOR_BITS, - (grub_efi_uintn_t) size << GRUB_DISK_SECTOR_BITS, + (grub_efi_uint64_t) sector << disk->log_sector_size, + (grub_efi_uintn_t) size << disk->log_sector_size, buf); if (status != GRUB_EFI_SUCCESS) return grub_error (GRUB_ERR_READ_ERROR, "efidisk read error"); @@ -599,8 +604,8 @@ grub_efidisk_write (struct grub_disk *disk, grub_disk_addr_t sector, (unsigned long) size, (unsigned long long) sector, disk->name); status = efi_call_5 (dio->write, dio, bio->media->media_id, - (grub_efi_uint64_t) sector << GRUB_DISK_SECTOR_BITS, - (grub_efi_uintn_t) size << GRUB_DISK_SECTOR_BITS, + (grub_efi_uint64_t) sector << disk->log_sector_size, + (grub_efi_uintn_t) size << disk->log_sector_size, (void *) buf); if (status != GRUB_EFI_SUCCESS) return grub_error (GRUB_ERR_WRITE_ERROR, "efidisk write error"); diff --git a/grub-core/disk/i386/pc/biosdisk.c b/grub-core/disk/i386/pc/biosdisk.c index 069bb0b59..6e48fff43 100644 --- a/grub-core/disk/i386/pc/biosdisk.c +++ b/grub-core/disk/i386/pc/biosdisk.c @@ -338,7 +338,8 @@ grub_biosdisk_open (const char *name, grub_disk_t disk) if ((cd_drive) && (drive == cd_drive)) { data->flags = GRUB_BIOSDISK_FLAG_LBA | GRUB_BIOSDISK_FLAG_CDROM; - data->sectors = 32; + data->sectors = 8; + disk->log_sector_size = 11; /* TODO: get the correct size. */ total_sectors = GRUB_DISK_SIZE_UNKNOWN; } @@ -347,6 +348,8 @@ grub_biosdisk_open (const char *name, grub_disk_t disk) /* HDD */ int version; + disk->log_sector_size = 9; + version = grub_biosdisk_check_int13_extensions (drive); if (version) { @@ -367,6 +370,15 @@ grub_biosdisk_open (const char *name, grub_disk_t disk) correctly but returns zero. So if it is zero, compute it by C/H/S returned by the LBA BIOS call. */ total_sectors = drp->cylinders * drp->heads * drp->sectors; + if (drp->bytes_per_sector + && !(drp->bytes_per_sector & (drp->bytes_per_sector - 1)) + && drp->bytes_per_sector >= 512 + && drp->bytes_per_sector <= 16384) + { + for (disk->log_sector_size = 0; + (1 << disk->log_sector_size) < drp->bytes_per_sector; + disk->log_sector_size++); + } } } } @@ -429,7 +441,7 @@ grub_biosdisk_rw (int cmd, grub_disk_t disk, dap = (struct grub_biosdisk_dap *) (GRUB_MEMORY_MACHINE_SCRATCH_ADDR + (data->sectors - << GRUB_DISK_SECTOR_BITS)); + << disk->log_sector_size)); dap->length = sizeof (*dap); dap->reserved = 0; dap->blocks = size; @@ -443,9 +455,6 @@ grub_biosdisk_rw (int cmd, grub_disk_t disk, if (cmd) return grub_error (GRUB_ERR_WRITE_ERROR, "can\'t write to cdrom"); - dap->blocks = ALIGN_UP (dap->blocks, 4) >> 2; - dap->block >>= 2; - for (i = 0; i < GRUB_BIOSDISK_CDROM_RETRY_COUNT; i++) if (! grub_biosdisk_rw_int13_extensions (0x42, data->drive, dap)) break; @@ -501,10 +510,12 @@ grub_biosdisk_rw (int cmd, grub_disk_t disk, /* Return the number of sectors which can be read safely at a time. */ static grub_size_t -get_safe_sectors (grub_disk_addr_t sector, grub_uint32_t sectors) +get_safe_sectors (grub_disk_t disk, grub_disk_addr_t sector) { grub_size_t size; grub_uint32_t offset; + struct grub_biosdisk_data *data = disk->data; + grub_uint32_t sectors = data->sectors; /* OFFSET = SECTOR % SECTORS */ grub_divmod64 (sector, sectors, &offset); @@ -512,8 +523,8 @@ get_safe_sectors (grub_disk_addr_t sector, grub_uint32_t sectors) size = sectors - offset; /* Limit the max to 0x7f because of Phoenix EDD. */ - if (size > 0x7f) - size = 0x7f; + if (size > ((0x7fU << GRUB_DISK_SECTOR_BITS) >> disk->log_sector_size)) + size = ((0x7fU << GRUB_DISK_SECTOR_BITS) >> disk->log_sector_size); return size; } @@ -522,21 +533,11 @@ static grub_err_t grub_biosdisk_read (grub_disk_t disk, grub_disk_addr_t sector, grub_size_t size, char *buf) { - struct grub_biosdisk_data *data = disk->data; - while (size) { grub_size_t len; - grub_size_t cdoff = 0; - len = get_safe_sectors (sector, data->sectors); - - if (data->flags & GRUB_BIOSDISK_FLAG_CDROM) - { - cdoff = (sector & 3) << GRUB_DISK_SECTOR_BITS; - len = ALIGN_UP (sector + len, 4) - (sector & ~3); - sector &= ~3; - } + len = get_safe_sectors (disk, sector); if (len > size) len = size; @@ -545,9 +546,10 @@ grub_biosdisk_read (grub_disk_t disk, grub_disk_addr_t sector, GRUB_MEMORY_MACHINE_SCRATCH_SEG)) return grub_errno; - grub_memcpy (buf, (void *) (GRUB_MEMORY_MACHINE_SCRATCH_ADDR + cdoff), - len << GRUB_DISK_SECTOR_BITS); - buf += len << GRUB_DISK_SECTOR_BITS; + grub_memcpy (buf, (void *) GRUB_MEMORY_MACHINE_SCRATCH_ADDR, + len << disk->log_sector_size); + + buf += len << disk->log_sector_size; sector += len; size -= len; } @@ -568,18 +570,18 @@ grub_biosdisk_write (grub_disk_t disk, grub_disk_addr_t sector, { grub_size_t len; - len = get_safe_sectors (sector, data->sectors); + len = get_safe_sectors (disk, sector); if (len > size) len = size; grub_memcpy ((void *) GRUB_MEMORY_MACHINE_SCRATCH_ADDR, buf, - len << GRUB_DISK_SECTOR_BITS); + len << disk->log_sector_size); if (grub_biosdisk_rw (GRUB_BIOSDISK_WRITE, disk, sector, len, GRUB_MEMORY_MACHINE_SCRATCH_SEG)) return grub_errno; - buf += len << GRUB_DISK_SECTOR_BITS; + buf += len << disk->log_sector_size; sector += len; size -= len; } diff --git a/grub-core/disk/scsi.c b/grub-core/disk/scsi.c index a40de278f..0d4734dc0 100644 --- a/grub-core/disk/scsi.c +++ b/grub-core/disk/scsi.c @@ -463,15 +463,20 @@ grub_scsi_open (const char *name, grub_disk_t disk) return err; } - /* SCSI blocks can be something else than 512, although GRUB - wants 512 byte blocks. */ - disk->total_sectors = ((grub_uint64_t)scsi->size - * (grub_uint64_t)scsi->blocksize) - >> GRUB_DISK_SECTOR_BITS; + disk->total_sectors = scsi->size; + if (scsi->blocksize & (scsi->blocksize - 1) || !scsi->blocksize) + { + grub_free (scsi); + return grub_error (GRUB_ERR_IO, "invalid sector size %d", + scsi->blocksize); + } + for (disk->log_sector_size = 0; + (1 << disk->log_sector_size) < scsi->blocksize; + disk->log_sector_size++); grub_dprintf ("scsi", "blocks=%u, blocksize=%u\n", scsi->size, scsi->blocksize); - grub_dprintf ("scsi", "Disk total 512 sectors = %llu\n", + grub_dprintf ("scsi", "Disk total sectors = %llu\n", (unsigned long long) disk->total_sectors); return GRUB_ERR_NONE; @@ -501,25 +506,6 @@ grub_scsi_read (grub_disk_t disk, grub_disk_addr_t sector, scsi = disk->data; - /* SCSI sectors are variable in size. GRUB uses 512 byte - sectors. */ - if (scsi->blocksize != GRUB_DISK_SECTOR_SIZE) - { - unsigned spb = scsi->blocksize >> GRUB_DISK_SECTOR_BITS; - if (spb == 0 || (scsi->blocksize & (GRUB_DISK_SECTOR_SIZE - 1)) != 0) - return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, - "unsupported SCSI block size"); - - grub_uint32_t sector_mod = 0; - sector = grub_divmod64 (sector, spb, §or_mod); - - if (! (sector_mod == 0 && size % spb == 0)) - return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, - "unaligned SCSI read not supported"); - - size /= spb; - } - /* Depending on the type, select a read function. */ switch (scsi->devtype) { diff --git a/grub-core/kern/disk.c b/grub-core/kern/disk.c index 807ee4277..af56527ad 100644 --- a/grub-core/kern/disk.c +++ b/grub-core/kern/disk.c @@ -247,6 +247,7 @@ grub_disk_open (const char *name) disk = (grub_disk_t) grub_zalloc (sizeof (*disk)); if (! disk) return 0; + disk->log_sector_size = GRUB_DISK_SECTOR_BITS; p = find_part_sep (name); if (p) @@ -266,7 +267,6 @@ grub_disk_open (const char *name) if (! disk->name) goto fail; - for (dev = grub_disk_dev_list; dev; dev = dev->next) { if ((dev->open) (raw, disk) == GRUB_ERR_NONE) @@ -282,6 +282,14 @@ grub_disk_open (const char *name) grub_error (GRUB_ERR_UNKNOWN_DEVICE, "no such disk"); goto fail; } + if (disk->log_sector_size > GRUB_DISK_CACHE_BITS + GRUB_DISK_SECTOR_BITS + || disk->log_sector_size < GRUB_DISK_SECTOR_BITS) + { + grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, + "sector sizes of %d bytes aren't supported yet", + (1 << disk->log_sector_size)); + goto fail; + } disk->dev = dev; @@ -373,14 +381,23 @@ grub_disk_adjust_range (grub_disk_t disk, grub_disk_addr_t *sector, *sector += start; } - if (disk->total_sectors <= *sector - || ((*offset + size + GRUB_DISK_SECTOR_SIZE - 1) - >> GRUB_DISK_SECTOR_BITS) > disk->total_sectors - *sector) + if (disk->total_sectors != GRUB_DISK_SIZE_UNKNOWN + && ((disk->total_sectors << (disk->log_sector_size - GRUB_DISK_SECTOR_BITS)) <= *sector + || ((*offset + size + GRUB_DISK_SECTOR_SIZE - 1) + >> GRUB_DISK_SECTOR_BITS) > (disk->total_sectors + << (disk->log_sector_size + - GRUB_DISK_SECTOR_BITS)) - *sector)) return grub_error (GRUB_ERR_OUT_OF_RANGE, "out of disk"); return GRUB_ERR_NONE; } +static inline grub_disk_addr_t +transform_sector (grub_disk_t disk, grub_disk_addr_t sector) +{ + return sector >> (disk->log_sector_size - GRUB_DISK_SECTOR_BITS); +} + /* Read data from the disk. */ grub_err_t grub_disk_read (grub_disk_t disk, grub_disk_addr_t sector, @@ -433,27 +450,39 @@ grub_disk_read (grub_disk_t disk, grub_disk_addr_t sector, else { /* Otherwise read data from the disk actually. */ - if (start_sector + GRUB_DISK_CACHE_SIZE > disk->total_sectors - || (disk->dev->read) (disk, start_sector, - GRUB_DISK_CACHE_SIZE, tmp_buf) + if ((disk->total_sectors != GRUB_DISK_SIZE_UNKNOWN + && start_sector + GRUB_DISK_CACHE_SIZE + > (disk->total_sectors << (disk->log_sector_size - GRUB_DISK_SECTOR_BITS))) + || (disk->dev->read) (disk, transform_sector (disk, start_sector), + 1 << (GRUB_DISK_CACHE_BITS + + GRUB_DISK_SECTOR_BITS + - disk->log_sector_size), tmp_buf) != GRUB_ERR_NONE) { /* Uggh... Failed. Instead, just read necessary data. */ unsigned num; char *p; + grub_disk_addr_t aligned_sector; grub_errno = GRUB_ERR_NONE; - num = ((size + real_offset + GRUB_DISK_SECTOR_SIZE - 1) - >> GRUB_DISK_SECTOR_BITS); + aligned_sector = (sector & ~((1 << (disk->log_sector_size + - GRUB_DISK_SECTOR_BITS)) + - 1)); + real_offset += ((sector - aligned_sector) + << GRUB_DISK_SECTOR_BITS); + num = ((size + real_offset + (1 << (disk->log_sector_size)) + - 1) >> (disk->log_sector_size)); - p = grub_realloc (tmp_buf, num << GRUB_DISK_SECTOR_BITS); + p = grub_realloc (tmp_buf, num << disk->log_sector_size); if (!p) goto finish; tmp_buf = p; - if ((disk->dev->read) (disk, sector, num, tmp_buf)) + if ((disk->dev->read) (disk, transform_sector (disk, + aligned_sector), + num, tmp_buf)) { grub_error_push (); grub_dprintf ("disk", "%s read failed\n", disk->name); @@ -528,25 +557,31 @@ grub_disk_write (grub_disk_t disk, grub_disk_addr_t sector, grub_off_t offset, grub_size_t size, const void *buf) { unsigned real_offset; + grub_disk_addr_t aligned_sector; grub_dprintf ("disk", "Writing `%s'...\n", disk->name); if (grub_disk_adjust_range (disk, §or, &offset, size) != GRUB_ERR_NONE) return -1; - real_offset = offset; + aligned_sector = (sector & ~((1 << (disk->log_sector_size + - GRUB_DISK_SECTOR_BITS)) - 1)); + real_offset = offset + ((sector - aligned_sector) << GRUB_DISK_SECTOR_BITS); + sector = aligned_sector; while (size) { - if (real_offset != 0 || (size < GRUB_DISK_SECTOR_SIZE && size != 0)) + if (real_offset != 0 || (size < (1U << disk->log_sector_size) + && size != 0)) { - char tmp_buf[GRUB_DISK_SECTOR_SIZE]; + char tmp_buf[1 << disk->log_sector_size]; grub_size_t len; grub_partition_t part; part = disk->partition; disk->partition = 0; - if (grub_disk_read (disk, sector, 0, GRUB_DISK_SECTOR_SIZE, tmp_buf) + if (grub_disk_read (disk, sector, + 0, (1 << disk->log_sector_size), tmp_buf) != GRUB_ERR_NONE) { disk->partition = part; @@ -554,7 +589,7 @@ grub_disk_write (grub_disk_t disk, grub_disk_addr_t sector, } disk->partition = part; - len = GRUB_DISK_SECTOR_SIZE - real_offset; + len = (1 << disk->log_sector_size) - real_offset; if (len > size) len = size; @@ -565,7 +600,7 @@ grub_disk_write (grub_disk_t disk, grub_disk_addr_t sector, if ((disk->dev->write) (disk, sector, 1, tmp_buf) != GRUB_ERR_NONE) goto finish; - sector++; + sector += (1 << (disk->log_sector_size - GRUB_DISK_SECTOR_BITS)); buf = (char *) buf + len; size -= len; real_offset = 0; @@ -575,8 +610,8 @@ grub_disk_write (grub_disk_t disk, grub_disk_addr_t sector, grub_size_t len; grub_size_t n; - len = size & ~(GRUB_DISK_SECTOR_SIZE - 1); - n = size >> GRUB_DISK_SECTOR_BITS; + len = size & ~((1 << disk->log_sector_size) - 1); + n = size >> disk->log_sector_size; if ((disk->dev->write) (disk, sector, n, buf) != GRUB_ERR_NONE) goto finish; @@ -599,6 +634,8 @@ grub_disk_get_size (grub_disk_t disk) { if (disk->partition) return grub_partition_get_len (disk->partition); + else if (disk->total_sectors != GRUB_DISK_SIZE_UNKNOWN) + return disk->total_sectors << (disk->log_sector_size - GRUB_DISK_SECTOR_BITS); else - return disk->total_sectors; + return GRUB_DISK_SIZE_UNKNOWN; } diff --git a/grub-core/kern/emu/hostdisk.c b/grub-core/kern/emu/hostdisk.c index 73d023ce9..f082ada89 100644 --- a/grub-core/kern/emu/hostdisk.c +++ b/grub-core/kern/emu/hostdisk.c @@ -42,6 +42,7 @@ #ifdef __linux__ # include /* ioctl */ +# include # if !defined(__GLIBC__) || \ ((__GLIBC__ < 2) || ((__GLIBC__ == 2) && (__GLIBC_MINOR__ < 1))) /* Maybe libc doesn't have large file support. */ @@ -264,6 +265,7 @@ grub_util_biosdisk_open (const char *name, grub_disk_t disk) # else unsigned long long nr; # endif + int sector_size; int fd; fd = open (map[drive].device, O_RDONLY); @@ -295,16 +297,28 @@ grub_util_biosdisk_open (const char *name, grub_disk_t disk) goto fail; } + if (ioctl (fd, BLKSSZGET, §or_size)) + { + close (fd); + goto fail; + } + close (fd); + if (sector_size & (sector_size - 1) || !sector_size) + goto fail; + for (disk->log_sector_size = 0; + (1 << disk->log_sector_size) < sector_size; + disk->log_sector_size++); + # if defined (__APPLE__) disk->total_sectors = nr; # elif defined(__NetBSD__) disk->total_sectors = label.d_secperunit; # else - disk->total_sectors = nr / 512; + disk->total_sectors = nr >> disk->log_sector_size; - if (nr % 512) + if (nr & ((1 << disk->log_sector_size) - 1)) grub_util_error ("unaligned device size"); # endif @@ -321,7 +335,7 @@ grub_util_biosdisk_open (const char *name, grub_disk_t disk) if (stat (map[drive].device, &st) < 0) return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "cannot stat `%s'", map[drive].device); - disk->total_sectors = st.st_size >> GRUB_DISK_SECTOR_BITS; + disk->total_sectors = st.st_size >> disk->log_sector_size; grub_util_info ("the size of %s is %lu", name, disk->total_sectors); @@ -760,7 +774,7 @@ open_device (const grub_disk_t disk, grub_disk_addr_t sector, int flags) _syscall5 (int, _llseek, uint, filedes, ulong, hi, ulong, lo, loff_t *, res, uint, wh); - offset = (loff_t) sector << GRUB_DISK_SECTOR_BITS; + offset = (loff_t) sector << disk->log_sector_size; if (_llseek (fd, offset >> 32, offset & 0xffffffff, &result, SEEK_SET)) { grub_error (GRUB_ERR_BAD_DEVICE, "cannot seek `%s'", map[disk->id].device); @@ -770,7 +784,7 @@ open_device (const grub_disk_t disk, grub_disk_addr_t sector, int flags) } #else { - off_t offset = (off_t) sector << GRUB_DISK_SECTOR_BITS; + off_t offset = (off_t) sector << disk->log_sector_size; if (lseek (fd, offset, SEEK_SET) != offset) { @@ -870,20 +884,21 @@ grub_util_biosdisk_read (grub_disk_t disk, grub_disk_addr_t sector, sectors that are read together with the MBR in one read. It should only remap the MBR, so we split the read in two parts. -jochen */ - if (nread (fd, buf, GRUB_DISK_SECTOR_SIZE) != GRUB_DISK_SECTOR_SIZE) + if (nread (fd, buf, (1 << disk->log_sector_size)) + != (1 << disk->log_sector_size)) { grub_error (GRUB_ERR_READ_ERROR, "cannot read `%s'", map[disk->id].device); close (fd); return grub_errno; } - buf += GRUB_DISK_SECTOR_SIZE; + buf += (1 << disk->log_sector_size); size--; } #endif /* __linux__ */ - if (nread (fd, buf, size << GRUB_DISK_SECTOR_BITS) - != (ssize_t) (size << GRUB_DISK_SECTOR_BITS)) + if (nread (fd, buf, size << disk->log_sector_size) + != (ssize_t) (size << disk->log_sector_size)) grub_error (GRUB_ERR_READ_ERROR, "cannot read from `%s'", map[disk->id].device); return grub_errno; @@ -916,8 +931,8 @@ grub_util_biosdisk_write (grub_disk_t disk, grub_disk_addr_t sector, if (fd < 0) return grub_errno; - if (nwrite (fd, buf, size << GRUB_DISK_SECTOR_BITS) - != (ssize_t) (size << GRUB_DISK_SECTOR_BITS)) + if (nwrite (fd, buf, size << disk->log_sector_size) + != (ssize_t) (size << disk->log_sector_size)) grub_error (GRUB_ERR_WRITE_ERROR, "cannot write to `%s'", map[disk->id].device); return grub_errno; diff --git a/grub-core/partmap/msdos.c b/grub-core/partmap/msdos.c index 31a0a0707..c2e726bd7 100644 --- a/grub-core/partmap/msdos.c +++ b/grub-core/partmap/msdos.c @@ -90,8 +90,11 @@ grub_partition_msdos_iterate (grub_disk_t disk, { e = mbr.entries + p.index; - p.start = p.offset + grub_le_to_cpu32 (e->start) - delta; - p.len = grub_le_to_cpu32 (e->length); + p.start = p.offset + + (grub_le_to_cpu32 (e->start) + << (disk->log_sector_size - GRUB_DISK_SECTOR_BITS)) - delta; + p.len = grub_le_to_cpu32 (e->length) + << (disk->log_sector_size - GRUB_DISK_SECTOR_BITS); p.msdostype = e->type; grub_dprintf ("partition", @@ -126,7 +129,9 @@ grub_partition_msdos_iterate (grub_disk_t disk, if (grub_msdos_partition_is_extended (e->type)) { - p.offset = ext_offset + grub_le_to_cpu32 (e->start); + p.offset = ext_offset + + (grub_le_to_cpu32 (e->start) + << (disk->log_sector_size - GRUB_DISK_SECTOR_BITS)); if (! ext_offset) ext_offset = p.offset; @@ -204,8 +209,11 @@ pc_partition_map_embed (struct grub_disk *disk, unsigned int *nsectors, e = mbr.entries + i; if (!grub_msdos_partition_is_empty (e->type) - && end > offset + grub_le_to_cpu32 (e->start)) - end = offset + grub_le_to_cpu32 (e->start); + && end > offset + + (grub_le_to_cpu32 (e->start) + << (disk->log_sector_size - GRUB_DISK_SECTOR_BITS))) + end = offset + (grub_le_to_cpu32 (e->start) + << (disk->log_sector_size - GRUB_DISK_SECTOR_BITS)); /* If this is a GPT partition, this MBR is just a dummy. */ if (e->type == GRUB_PC_PARTITION_TYPE_GPT_DISK && i == 0) @@ -219,7 +227,9 @@ pc_partition_map_embed (struct grub_disk *disk, unsigned int *nsectors, if (grub_msdos_partition_is_extended (e->type)) { - offset = ext_offset + grub_le_to_cpu32 (e->start); + offset = ext_offset + + (grub_le_to_cpu32 (e->start) + << (disk->log_sector_size - GRUB_DISK_SECTOR_BITS)); if (! ext_offset) ext_offset = offset; diff --git a/include/grub/disk.h b/include/grub/disk.h index 66db1149a..b46d6670a 100644 --- a/include/grub/disk.h +++ b/include/grub/disk.h @@ -100,6 +100,9 @@ struct grub_disk /* The total number of sectors. */ grub_uint64_t total_sectors; + /* Logarithm of sector size. */ + unsigned int log_sector_size; + /* The id used by the disk cache manager. */ unsigned long id; @@ -132,9 +135,10 @@ typedef struct grub_disk_memberlist *grub_disk_memberlist_t; /* The maximum number of disk caches. */ #define GRUB_DISK_CACHE_NUM 1021 -/* The size of a disk cache in sector units. */ -#define GRUB_DISK_CACHE_SIZE 8 -#define GRUB_DISK_CACHE_BITS 3 +/* The size of a disk cache in 512B units. Must be at least as big as the + largest supported sector size, currently 16K. */ +#define GRUB_DISK_CACHE_BITS 6 +#define GRUB_DISK_CACHE_SIZE (1 << GRUB_DISK_CACHE_BITS) /* Return value of grub_disk_get_size() in case disk size is unknown. */ #define GRUB_DISK_SIZE_UNKNOWN 0xffffffffffffffffULL From 9f3677d3c1dc361c570d6b20acff9e98563355aa Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Tue, 29 Mar 2011 02:20:52 +0200 Subject: [PATCH 339/869] * util/grub-setup.c: Copy the partition table zone if floppy support is disabled, even if no partition table is found. Otherwise, the BIOS on Dell Latitude E series laptops will freeze during POST if an invalid partition table is contained in the PBR of the active partition when GRUB is installed to a partition. --- ChangeLog | 9 +++++++++ util/grub-setup.c | 17 +++++++++-------- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index d6afea1d2..1ea9ca076 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2011-03-29 Mario Limonciello + + * util/grub-setup.c: Copy the partition table zone if floppy support + is disabled, even if no partition table is found. + + Otherwise, the BIOS on Dell Latitude E series laptops will freeze + during POST if an invalid partition table is contained in the PBR + of the active partition when GRUB is installed to a partition. + 2011-03-28 Colin Watson * grub-core/disk/mdraid1x_linux.c (grub_mdraid_detect): Remove stale diff --git a/util/grub-setup.c b/util/grub-setup.c index b4749b433..c1f2a1f5e 100644 --- a/util/grub-setup.c +++ b/util/grub-setup.c @@ -399,6 +399,15 @@ setup (const char *dir, } #endif + /* Copy the partition table. */ + if (dest_partmap || + (!allow_floppy && !grub_util_biosdisk_is_floppy (dest_dev->disk))) + memcpy (boot_img + GRUB_BOOT_MACHINE_WINDOWS_NT_MAGIC, + tmp_img + GRUB_BOOT_MACHINE_WINDOWS_NT_MAGIC, + GRUB_BOOT_MACHINE_PART_END - GRUB_BOOT_MACHINE_WINDOWS_NT_MAGIC); + + free (tmp_img); + if (! dest_partmap) { grub_util_warn (_("Attempting to install GRUB to a partitionless disk or to a partition. This is a BAD idea.")); @@ -410,14 +419,6 @@ setup (const char *dir, goto unable_to_embed; } - /* Copy the partition table. */ - if (dest_partmap) - memcpy (boot_img + GRUB_BOOT_MACHINE_WINDOWS_NT_MAGIC, - tmp_img + GRUB_BOOT_MACHINE_WINDOWS_NT_MAGIC, - GRUB_BOOT_MACHINE_PART_END - GRUB_BOOT_MACHINE_WINDOWS_NT_MAGIC); - - free (tmp_img); - if (!dest_partmap->embed) { grub_util_warn ("Partition style '%s' doesn't support embeding", From a1dc717c5869064fda3553fd4055e00af6623d7e Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Tue, 29 Mar 2011 08:20:19 +0200 Subject: [PATCH 340/869] * grub-core/lib/relocator.c (allocate_regstart) [!DEBUG_RELOCATOR_NOMEM_DPRINTF]: Avoid grub_dprintf since not all terminals are capabple of malloc-free operation. (allocate_inreg) [!DEBUG_RELOCATOR_NOMEM_DPRINTF]: Likewise. (malloc_in_range) [!DEBUG_RELOCATOR_NOMEM_DPRINTF]: Likewise. --- ChangeLog | 8 ++++++++ grub-core/lib/relocator.c | 14 ++++++++++---- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1ea9ca076..a07eff722 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2011-03-29 Vladimir Serbinenko + + * grub-core/lib/relocator.c (allocate_regstart) + [!DEBUG_RELOCATOR_NOMEM_DPRINTF]: Avoid grub_dprintf since not all + terminals are capabple of malloc-free operation. + (allocate_inreg) [!DEBUG_RELOCATOR_NOMEM_DPRINTF]: Likewise. + (malloc_in_range) [!DEBUG_RELOCATOR_NOMEM_DPRINTF]: Likewise. + 2011-03-29 Mario Limonciello * util/grub-setup.c: Copy the partition table zone if floppy support diff --git a/grub-core/lib/relocator.c b/grub-core/lib/relocator.c index 7d29ab5cc..940b9133b 100644 --- a/grub-core/lib/relocator.c +++ b/grub-core/lib/relocator.c @@ -134,9 +134,10 @@ allocate_regstart (grub_phys_addr_t addr, grub_size_t size, grub_mm_region_t rb, grub_addr_t newreg_size, newreg_presize; grub_mm_header_t new_header; grub_mm_header_t hb = (grub_mm_header_t) (rb + 1); - - grub_dprintf ("relocator", "ra = %p, rb = %p\n", regancestor, rb); +#ifdef DEBUG_RELOCATOR_NOMEM_DPRINTF + grub_dprintf ("relocator", "ra = %p, rb = %p\n", regancestor, rb); +#endif newreg_start = ALIGN_UP (newreg_raw_start, GRUB_MM_ALIGN); newreg_presize = newreg_start - newreg_raw_start; newreg_size = rb->size - (newreg_start - (grub_addr_t) rb); @@ -179,11 +180,12 @@ allocate_regstart (grub_phys_addr_t addr, grub_size_t size, grub_mm_region_t rb, if ((void *) h < (void *) (newreg + 1)) grub_fatal ("Failed to adjust memory region: %p, %p, %p, %p, %p", newreg, newreg->first, h, hp, hb); +#ifdef DEBUG_RELOCATOR_NOMEM_DPRINTF if ((void *) h == (void *) (newreg + 1)) grub_dprintf ("relocator", "Free start memory region: %p, %p, %p, %p, %p", newreg, newreg->first, h, hp, hb); - +#endif hp = h; h = h->next; } @@ -200,7 +202,7 @@ allocate_inreg (grub_phys_addr_t paddr, grub_size_t size, struct grub_mm_header *foll = NULL; grub_addr_t vaddr = (grub_addr_t) hb + (paddr - grub_vtop (hb)); -#ifdef DEBUG_RELOCATOR +#ifdef DEBUG_RELOCATOR_NOMEM_DPRINTF grub_dprintf ("relocator", "inreg paddr = 0x%lx, size = %lu," " hb = %p, hbp = %p, rb = %p, vaddr = 0x%lx\n", (unsigned long) paddr, (unsigned long) size, hb, hbp, @@ -213,8 +215,10 @@ allocate_inreg (grub_phys_addr_t paddr, grub_size_t size, foll = (void *) ALIGN_UP (vaddr + size, GRUB_MM_ALIGN); foll->magic = GRUB_MM_FREE_MAGIC; foll->size = hb + hb->size - foll; +#ifdef DEBUG_RELOCATOR_NOMEM_DPRINTF grub_dprintf ("relocator", "foll = %p, foll->size = %lu\n", foll, (unsigned long) foll->size); +#endif } if (vaddr - (grub_addr_t) hb >= sizeof (*hb)) @@ -821,9 +825,11 @@ malloc_in_range (struct grub_relocator *rel, fend = ALIGN_UP (alloc_end, GRUB_RELOCATOR_FIRMWARE_REQUESTS_QUANT); +#ifdef DEBUG_RELOCATOR_NOMEM_DPRINTF grub_dprintf ("relocator", "requesting %lx-%lx\n", (unsigned long) fstart, (unsigned long) fend); +#endif /* The failure here can be very expensive. */ if (!grub_relocator_firmware_alloc_region (fstart, fend - fstart)) From ed5587afea4da065b2857906cacde451818c0e82 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Tue, 29 Mar 2011 08:33:28 +0200 Subject: [PATCH 341/869] * grub-core/term/gfxterm.c (dirty_region_add): Move core part to ... (dirty_region_add_real): ... this. (dirty_region_add): Don't discard margin refresh when performing scheduled repaint. --- ChangeLog | 7 +++++++ grub-core/term/gfxterm.c | 31 +++++++++++++++++-------------- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/ChangeLog b/ChangeLog index a07eff722..c353b8fea 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2011-03-29 Vladimir Serbinenko + + * grub-core/term/gfxterm.c (dirty_region_add): Move core part to ... + (dirty_region_add_real): ... this. + (dirty_region_add): Don't discard margin refresh when performing + scheduled repaint. + 2011-03-29 Vladimir Serbinenko * grub-core/lib/relocator.c (allocate_regstart) diff --git a/grub-core/term/gfxterm.c b/grub-core/term/gfxterm.c index 321479e0a..44d1a9be8 100644 --- a/grub-core/term/gfxterm.c +++ b/grub-core/term/gfxterm.c @@ -532,21 +532,8 @@ dirty_region_is_empty (void) } static void -dirty_region_add (int x, int y, unsigned int width, unsigned int height) +dirty_region_add_real (int x, int y, unsigned int width, unsigned int height) { - if ((width == 0) || (height == 0)) - return; - - if (repaint_scheduled) - { - x = virtual_screen.offset_x; - y = virtual_screen.offset_y; - width = virtual_screen.width; - height = virtual_screen.height; - repaint_scheduled = 0; - repaint_was_scheduled = 1; - } - if (dirty_region_is_empty ()) { dirty_region.top_left_x = x; @@ -567,6 +554,22 @@ dirty_region_add (int x, int y, unsigned int width, unsigned int height) } } +static void +dirty_region_add (int x, int y, unsigned int width, unsigned int height) +{ + if ((width == 0) || (height == 0)) + return; + + if (repaint_scheduled) + { + dirty_region_add_real (virtual_screen.offset_x, virtual_screen.offset_y, + virtual_screen.width, virtual_screen.height); + repaint_scheduled = 0; + repaint_was_scheduled = 1; + } + dirty_region_add_real (x, y, width, height); +} + static void dirty_region_add_virtualscreen (void) { From d2e29d81a9fb4f07485a6948c5bb04ff8c0a9c69 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Tue, 29 Mar 2011 10:56:14 +0200 Subject: [PATCH 342/869] * grub-core/fs/ext2.c (grub_ext2_read_inode): Fix an overflow. Reported and tested by: Timothy Nikkel. --- ChangeLog | 5 +++++ grub-core/fs/ext2.c | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index c353b8fea..9e90df11e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-03-29 Vladimir Serbinenko + + * grub-core/fs/ext2.c (grub_ext2_read_inode): Fix an overflow. + Reported and tested by: Timothy Nikkel. + 2011-03-29 Vladimir Serbinenko * grub-core/term/gfxterm.c (dirty_region_add): Move core part to ... diff --git a/grub-core/fs/ext2.c b/grub-core/fs/ext2.c index ed5fafd4c..9d7bbfd36 100644 --- a/grub-core/fs/ext2.c +++ b/grub-core/fs/ext2.c @@ -555,7 +555,7 @@ grub_ext2_read_inode (struct grub_ext2_data *data, /* Read the inode. */ if (grub_disk_read (data->disk, - ((grub_le_to_cpu32 (blkgrp.inode_table_id) + blkno) + (((grub_disk_addr_t) grub_le_to_cpu32 (blkgrp.inode_table_id) + blkno) << LOG2_EXT2_BLOCK_SIZE (data)), EXT2_INODE_SIZE (data) * blkoff, sizeof (struct grub_ext2_inode), inode)) From 35e5f84c18dde153c0671f3cf1f56371cde95631 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Tue, 29 Mar 2011 11:25:04 +0200 Subject: [PATCH 343/869] * grub-core/normal/misc.c (grub_normal_print_device_info): Use correct printf clauses for printing size and start. --- ChangeLog | 5 +++++ grub-core/normal/misc.c | 11 +++++------ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9e90df11e..8d976d770 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-03-29 Vladimir Serbinenko + + * grub-core/normal/misc.c (grub_normal_print_device_info): Use correct + printf clauses for printing size and start. + 2011-03-29 Vladimir Serbinenko * grub-core/fs/ext2.c (grub_ext2_read_inode): Fix an overflow. diff --git a/grub-core/normal/misc.c b/grub-core/normal/misc.c index d81b6d26f..4a7e6a3ea 100644 --- a/grub-core/normal/misc.c +++ b/grub-core/normal/misc.c @@ -112,14 +112,13 @@ grub_normal_print_device_info (const char *name) grub_printf ("%s", _("Not a known filesystem")); if (dev->disk->partition) - grub_printf (_(" - Partition start at %u"), - grub_partition_get_start (dev->disk->partition)); + grub_printf (_(" - Partition start at %llu"), + (unsigned long long) grub_partition_get_start (dev->disk->partition)); if (grub_disk_get_size (dev->disk) == GRUB_DISK_SIZE_UNKNOWN) - grub_printf (_(" - Total size unknown"), - grub_disk_get_size (dev->disk)); + grub_puts_ (" - Total size unknown"); else - grub_printf (_(" - Total size %u sectors"), - grub_disk_get_size (dev->disk)); + grub_printf (_(" - Total size %llu sectors"), + (unsigned long long) grub_disk_get_size (dev->disk)); grub_device_close (dev); } From b4db4f39f017cc7cf97890523bd6e6b219a9a326 Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Tue, 29 Mar 2011 10:51:58 +0100 Subject: [PATCH 344/869] * grub-core/disk/mdraid1x_linux.c (grub_mdraid_detect): If real_sb->size is zero (e.g. RAID-0), get the disk size from real_sb->data_size instead. Fixes Ubuntu bug #743136. --- ChangeLog | 7 +++++++ grub-core/disk/mdraid1x_linux.c | 5 ++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 8d976d770..ab5182b8c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2011-03-29 Colin Watson + + * grub-core/disk/mdraid1x_linux.c (grub_mdraid_detect): If + real_sb->size is zero (e.g. RAID-0), get the disk size from + real_sb->data_size instead. + Fixes Ubuntu bug #743136. + 2011-03-29 Vladimir Serbinenko * grub-core/normal/misc.c (grub_normal_print_device_info): Use correct diff --git a/grub-core/disk/mdraid1x_linux.c b/grub-core/disk/mdraid1x_linux.c index 296d1375b..1d08abf5b 100644 --- a/grub-core/disk/mdraid1x_linux.c +++ b/grub-core/disk/mdraid1x_linux.c @@ -192,7 +192,10 @@ grub_mdraid_detect (grub_disk_t disk, struct grub_raid_array *array, 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); + if (real_sb->size) + array->disk_size = grub_le_to_cpu64 (real_sb->size); + else + array->disk_size = grub_le_to_cpu64 (real_sb->data_size); array->chunk_size = grub_le_to_cpu32 (real_sb->chunksize); if (grub_le_to_cpu32 (real_sb->dev_number) >= From a307c0b206aebb15110a5c192ad0e5f2ddcd123f Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Tue, 29 Mar 2011 12:01:48 +0200 Subject: [PATCH 345/869] * util/grub.d/10_kfreebsd.in: Allow ufs.ko to be missing as it's per default compiled in kernel and prior to 8.0 isn't shipped at all. --- ChangeLog | 5 +++++ util/grub.d/10_kfreebsd.in | 6 +++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index ab5182b8c..8b593f634 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-03-29 Vladimir Serbinenko + + * util/grub.d/10_kfreebsd.in: Allow ufs.ko to be missing as it's + per default compiled in kernel and prior to 8.0 isn't shipped at all. + 2011-03-29 Colin Watson * grub-core/disk/mdraid1x_linux.c (grub_mdraid_detect): If diff --git a/util/grub.d/10_kfreebsd.in b/util/grub.d/10_kfreebsd.in index dce5e945c..3600c74f9 100644 --- a/util/grub.d/10_kfreebsd.in +++ b/util/grub.d/10_kfreebsd.in @@ -110,7 +110,11 @@ EOF ;; esac - load_kfreebsd_module ${kfreebsd_fs} false + if [ x${kfreebsd_fs} = xufs ]; then + load_kfreebsd_module ${kfreebsd_fs} true + else + load_kfreebsd_module ${kfreebsd_fs} false + fi cat << EOF set kFreeBSD.vfs.root.mountfrom=${kfreebsd_fs}:${kfreebsd_device} From 9e4d19e0d362613b566d824cc609b875c630e2b1 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Tue, 29 Mar 2011 15:00:23 +0200 Subject: [PATCH 346/869] * grub-core/kern/emu/hostdisk.c (find_partition_start) [HAVE_DIOCGDINFO]: Add safety checks. --- ChangeLog | 5 +++++ grub-core/kern/emu/hostdisk.c | 9 ++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 8b593f634..a7ed9fc94 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-03-29 Vladimir Serbinenko + + * grub-core/kern/emu/hostdisk.c (find_partition_start) + [HAVE_DIOCGDINFO]: Add safety checks. + 2011-03-29 Vladimir Serbinenko * util/grub.d/10_kfreebsd.in: Allow ufs.ko to be missing as it's diff --git a/grub-core/kern/emu/hostdisk.c b/grub-core/kern/emu/hostdisk.c index 73d023ce9..9900a79bd 100644 --- a/grub-core/kern/emu/hostdisk.c +++ b/grub-core/kern/emu/hostdisk.c @@ -518,9 +518,12 @@ devmapper_fail: # if !defined(HAVE_DIOCGDINFO) return hdg.start; # else /* defined(HAVE_DIOCGDINFO) */ - p_index = dev[strlen(dev) - 1] - 'a'; - - if (p_index >= label.d_npartitions) + if (dev[0]) + p_index = dev[strlen(dev) - 1] - 'a'; + else + p_index = -1; + + if (p_index >= label.d_npartitions || p_index < 0) { grub_error (GRUB_ERR_BAD_DEVICE, "no disk label entry for `%s'", dev); From 994b82643247f936e07aa9652451a9d724bda615 Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Tue, 29 Mar 2011 14:32:38 +0100 Subject: [PATCH 347/869] * docs/grub.texi (BIOS installation): New section, partly based on previous text in other sections. (Installing GRUB using grub-install): Replace BIOS discussion with a cross-reference. (Images): Likewise. --- ChangeLog | 8 ++++ docs/grub.texi | 100 +++++++++++++++++++++++++++++++++++-------------- 2 files changed, 79 insertions(+), 29 deletions(-) diff --git a/ChangeLog b/ChangeLog index a7ed9fc94..552d5dc7c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2011-03-29 Colin Watson + + * docs/grub.texi (BIOS installation): New section, partly based on + previous text in other sections. + (Installing GRUB using grub-install): Replace BIOS discussion with a + cross-reference. + (Images): Likewise. + 2011-03-29 Vladimir Serbinenko * grub-core/kern/emu/hostdisk.c (find_partition_start) diff --git a/docs/grub.texi b/docs/grub.texi index 83bd80023..cac4ffbf3 100644 --- a/docs/grub.texi +++ b/docs/grub.texi @@ -550,6 +550,7 @@ the @dfn{boot directory}. * Installing GRUB using grub-install:: * Making a GRUB bootable CD-ROM:: * Device map:: +* BIOS installation:: @end menu @@ -565,13 +566,8 @@ always. Therefore, GRUB provides you with a map file called the @dfn{device map}, which you must fix if it is wrong. @xref{Device map}, for more details. -On BIOS platforms GRUB has to use a so-called embedding zone. On msdos -partition tables, this is the space between the MBR and the first partition -(called the MBR gap or the boot track), while on GPT partition tables it -uses a BIOS Boot Partition (a partition with GUID -21686148-6449-6e6f-744e656564454649). If you use GRUB on a BIOS system, make -sure that the embedding zone is at least 31 KiB (512KiB or more -recommended). +For information on where GRUB should be installed on PC BIOS platforms, +@pxref{BIOS installation}. If you still do want to install GRUB under a UNIX-like OS (such as @sc{gnu}), invoke the program @command{grub-install} (@pxref{Invoking @@ -744,6 +740,72 @@ comments in the file if needed, as the GRUB utilities assume that a line is just a comment if the first character is @samp{#}. +@node BIOS installation +@section BIOS installation + +@heading MBR + +The partition table format traditionally used on PC BIOS platforms is called +the Master Boot Record (MBR) format; this is the format that allows up to +four primary partitions and additional logical partitions. With this +partition table format, there are two ways to install GRUB: it can be +embedded in the area between the MBR and the first partition (called by +various names, such as the "boot track", "MBR gap", or "embedding area", and +which is usually at least 31 KiB), or the core image can be installed in a +file system and a list of the blocks that make it up can be stored in the +first sector of that partition. + +Each of these has different problems. There is no way to reserve space in +the embedding area with complete safety, and some proprietary software is +known to use it to make it difficult for users to work around licensing +restrictions; and systems are sometimes partitioned without leaving enough +space before the first partition. On the other hand, installing to a +filesystem means that GRUB is vulnerable to its blocks being moved around by +filesystem features such as tail packing, or even by aggressive fsck +implementations, so this approach is quite fragile; and this approach can +only be used if the @file{/boot} filesystem is on the same disk that the +BIOS boots from, so that GRUB does not have to rely on guessing BIOS drive +numbers. + +The GRUB development team generally recommends embedding GRUB before the +first partition, unless you have special requirements. You must ensure that +the first partition starts at least 31 KiB (63 sectors) from the start of +the disk; on modern disks, it is often a performance advantage to align +partitions on larger boundaries anyway, so the first partition might start 1 +MiB from the start of the disk. + +@heading GPT + +Some newer systems use the GUID Partition Table (GPT) format. This was +specified as part of the Extensible Firmware Interface (EFI), but it can +also be used on BIOS platforms if system software supports it; for example, +GRUB and GNU/Linux can be used in this configuration. With this format, it +is possible to reserve a whole partition for GRUB, called the BIOS Boot +Partition. GRUB can then be embedded into that partition without the risk +of being overwritten by other software and without being contained in a +filesystem which might move its blocks around. + +When creating a BIOS Boot Partition on a GPT system, you should make sure +that it is at least 31 KiB in size. (GPT-formatted disks are not usually +particularly small, so we recommend that you make it larger than the bare +minimum, such as 1 MiB, to allow plenty of room for growth.) You must also +make sure that it has the proper partition type. Using GNU Parted, you can +set this using a command such as the following: + +@example +# @kbd{parted /dev/@var{disk} set @var{partition-number} bios_grub on} +@end example + +If you are using gdisk, set the partition type to @samp{0xEF02}. With +partitioning programs that require setting the GUID directly, it should be +@samp{21686148-6449-6e6f-744e656564454649}. + +@strong{Caution:} Be very careful which partition you select! When GRUB +finds a BIOS Boot Partition during installation, it will automatically +overwrite part of it. Make sure that the partition does not contain any +other data. + + @node Booting @chapter Booting @@ -2021,28 +2083,8 @@ target operating systems, and so on) from the file system at run-time. The modular design allows the core image to be kept small, since the areas of disk where it must be installed are often as small as 32KB. -On PC systems using the traditional MBR partition table format, the core -image is usually installed in the "MBR gap" between the master boot record -and the first partition, or sometimes it is installed in a file system and -read directly from that. The latter is not recommended because GRUB needs -to encode the location of all the core image sectors in @file{diskboot.img}, -and if the file system ever moves the core image around (as it is entitled -to do) then GRUB must be reinstalled; it also means that GRUB will not be -able to reliably find the core image if it resides on a different disk than -the one to which @file{boot.img} was installed. - -On PC systems using the more recent GUID Partition Table (GPT) format, the -core image should be installed to a BIOS Boot Partition. This may be -created by GNU Parted using a command such as the following: - -@example -# @kbd{parted /dev/@var{disk} set @var{partition-number} bios_grub on} -@end example - -@strong{Caution:} Be very careful which partition you select! When GRUB -finds a BIOS Boot Partition during installation, it will automatically -overwrite part of it. Make sure that the partition does not contain any -other data. +@xref{BIOS installation}, for details on where the core image can be +installed on PC systems. @item *.mod Everything else in GRUB resides in dynamically loadable modules. These are From cf4d3fa6407417a6ecdc82ed886484400789cde5 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Tue, 29 Mar 2011 18:34:05 +0200 Subject: [PATCH 348/869] Send blend_text_bg when any backgorund is set as opposed to only when streteched background is set --- grub-core/term/gfxterm.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/grub-core/term/gfxterm.c b/grub-core/term/gfxterm.c index 8a75df93c..1d850abd4 100644 --- a/grub-core/term/gfxterm.c +++ b/grub-core/term/gfxterm.c @@ -1174,7 +1174,6 @@ grub_gfxterm_background_image_cmd (grub_extcmd_context_t ctxt, /* Replace the original bitmap with the scaled one. */ grub_video_bitmap_destroy (bitmap); bitmap = scaled_bitmap; - blend_text_bg = 1; } } } @@ -1182,6 +1181,8 @@ grub_gfxterm_background_image_cmd (grub_extcmd_context_t ctxt, /* If bitmap was loaded correctly, display it. */ if (bitmap) { + blend_text_bg = 1; + /* Determine bitmap dimensions. */ bitmap_width = grub_video_bitmap_get_width (bitmap); bitmap_height = grub_video_bitmap_get_height (bitmap); From 61d7156b947cbb19cad2565b82fb599695a41bb1 Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Tue, 29 Mar 2011 18:00:23 +0100 Subject: [PATCH 349/869] * grub-core/disk/loopback.c (GRUB_MOD_INIT): Stop documenting removed -p option. --- ChangeLog | 5 +++++ grub-core/disk/loopback.c | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 552d5dc7c..36ca453f1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-03-29 Colin Watson + + * grub-core/disk/loopback.c (GRUB_MOD_INIT): Stop documenting + removed -p option. + 2011-03-29 Colin Watson * docs/grub.texi (BIOS installation): New section, partly based on diff --git a/grub-core/disk/loopback.c b/grub-core/disk/loopback.c index ae4cb9a9c..b05940a4a 100644 --- a/grub-core/disk/loopback.c +++ b/grub-core/disk/loopback.c @@ -222,7 +222,7 @@ static grub_extcmd_t cmd; GRUB_MOD_INIT(loopback) { cmd = grub_register_extcmd ("loopback", grub_cmd_loopback, 0, - N_("[-d|-p] DEVICENAME FILE."), + N_("[-d] DEVICENAME FILE."), N_("Make a device of a file."), options); grub_disk_dev_register (&grub_loopback_dev); } From 5c650f4c8ea62ea776807b9e1444a496c652608d Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Tue, 29 Mar 2011 18:08:23 +0100 Subject: [PATCH 350/869] * docs/grub.texi (loopback): New section. --- ChangeLog | 4 ++++ docs/grub.texi | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/ChangeLog b/ChangeLog index 36ca453f1..cf7b1b0d6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2011-03-29 Colin Watson + + * docs/grub.texi (loopback): New section. + 2011-03-29 Colin Watson * grub-core/disk/loopback.c (GRUB_MOD_INIT): Stop documenting diff --git a/docs/grub.texi b/docs/grub.texi index cac4ffbf3..368d21f1d 100644 --- a/docs/grub.texi +++ b/docs/grub.texi @@ -2589,6 +2589,7 @@ you forget a command, you can run the command @command{help} * keystatus:: Check key modifier status * linux:: Load a Linux kernel * linux16:: Load a Linux kernel (16-bit mode) +* loopback:: Make a device from a filesystem image * ls:: List devices or files * parttool:: Modify partition table entries * password:: Set a clear-text password @@ -2978,6 +2979,23 @@ This command is only available on x86 systems. @end deffn +@node loopback +@subsection loopback + +@deffn Command loopback [@option{-d}] device file +Make the device named @var{device} correspond to the contents of the +filesystem image in @var{file}. For example: + +@example +loopback loop0 /path/to/image +ls (loop0)/ +@end example + +With the @option{-d} option, delete a device previously created using this +command. +@end deffn + + @node ls @subsection ls From fc18f6a3cb15db980e65dda9e305a1d176b14b3a Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Tue, 29 Mar 2011 19:47:34 +0200 Subject: [PATCH 351/869] * util/grub.d/10_linux.in: Skip vmlinux-* on x86 platforms. --- ChangeLog | 4 + grub-core/disk/lvm.c | 354 ++++++++++++++++++++++++++-------------- include/grub/lvm.h | 13 ++ util/grub.d/10_linux.in | 14 +- 4 files changed, 260 insertions(+), 125 deletions(-) diff --git a/ChangeLog b/ChangeLog index cf7b1b0d6..dcacc600c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2011-03-29 Vladimir Serbinenko + + * util/grub.d/10_linux.in: Skip vmlinux-* on x86 platforms. + 2011-03-29 Colin Watson * docs/grub.texi (loopback): New section. diff --git a/grub-core/disk/lvm.c b/grub-core/disk/lvm.c index 39fa84d91..b1a7a50a9 100644 --- a/grub-core/disk/lvm.c +++ b/grub-core/disk/lvm.c @@ -45,6 +45,7 @@ grub_lvm_getvalue (char **p, char *str) return grub_strtoul (*p, NULL, 10); } +#if 0 static int grub_lvm_checkvalue (char **p, char *str, char *tmpl) { @@ -57,6 +58,7 @@ grub_lvm_checkvalue (char **p, char *str, char *tmpl) return 0; return (grub_memcmp (*p + 1, tmpl, tmpllen) == 0 && (*p)[tmpllen + 1] == '"'); } +#endif static int grub_lvm_check_flag (char *p, char *str, char *flag) @@ -100,7 +102,7 @@ grub_lvm_iterate (int (*hook) (const char *name)) struct grub_lvm_lv *lv; if (vg->lvs) for (lv = vg->lvs; lv; lv = lv->next) - if (hook (lv->name)) + if (lv->visible && hook (lv->name)) return 1; } @@ -164,11 +166,10 @@ grub_lvm_close (grub_disk_t disk __attribute ((unused))) } static grub_err_t -grub_lvm_read (grub_disk_t disk, grub_disk_addr_t sector, - grub_size_t size, char *buf) +read_lv (struct grub_lvm_lv *lv, grub_disk_addr_t sector, + grub_size_t size, char *buf) { grub_err_t err = 0; - struct grub_lvm_lv *lv = disk->data; struct grub_lvm_vg *vg = lv->vg; struct grub_lvm_segment *seg = lv->segments; struct grub_lvm_pv *pv; @@ -176,6 +177,9 @@ grub_lvm_read (grub_disk_t disk, grub_disk_addr_t sector, grub_uint64_t extent; unsigned int i; + if (!lv) + return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "unknown volume"); + extent = grub_divmod64 (sector, vg->extent_size, NULL); /* Find the right segment. */ @@ -190,59 +194,88 @@ grub_lvm_read (grub_disk_t disk, grub_disk_addr_t sector, seg++; } - if (seg->stripe_count == 1) + if (i == lv->segment_count) + return grub_error (GRUB_ERR_READ_ERROR, "incorrect segment"); + + switch (seg->type) { - /* This segment is linear, so that's easy. We just need to find - out the offset in the physical volume and read SIZE bytes - from that. */ - struct grub_lvm_stripe *stripe = seg->stripes; - grub_uint64_t seg_offset; /* Offset of the segment in PV device. */ + case GRUB_LVM_STRIPED: + if (seg->stripe_count == 1) + { + /* This segment is linear, so that's easy. We just need to find + out the offset in the physical volume and read SIZE bytes + from that. */ + struct grub_lvm_stripe *stripe = seg->stripes; + grub_uint64_t seg_offset; /* Offset of the segment in PV device. */ - pv = stripe->pv; - seg_offset = ((grub_uint64_t) stripe->start - * (grub_uint64_t) vg->extent_size) + pv->start; + pv = stripe->pv; + seg_offset = ((grub_uint64_t) stripe->start + * (grub_uint64_t) vg->extent_size) + pv->start; - offset = sector - ((grub_uint64_t) seg->start_extent - * (grub_uint64_t) vg->extent_size) + seg_offset; + offset = sector - ((grub_uint64_t) seg->start_extent + * (grub_uint64_t) vg->extent_size) + seg_offset; + } + else + { + /* This is a striped segment. We have to find the right PV + similar to RAID0. */ + struct grub_lvm_stripe *stripe = seg->stripes; + grub_uint32_t a, b; + grub_uint64_t seg_offset; /* Offset of the segment in PV device. */ + unsigned int stripenr; + + offset = sector - ((grub_uint64_t) seg->start_extent + * (grub_uint64_t) vg->extent_size); + + a = grub_divmod64 (offset, seg->stripe_size, NULL); + grub_divmod64 (a, seg->stripe_count, &stripenr); + + a = grub_divmod64 (offset, seg->stripe_size * seg->stripe_count, NULL); + grub_divmod64 (offset, seg->stripe_size, &b); + offset = a * seg->stripe_size + b; + + stripe += stripenr; + pv = stripe->pv; + + seg_offset = ((grub_uint64_t) stripe->start + * (grub_uint64_t) vg->extent_size) + pv->start; + + offset += seg_offset; + } + /* Check whether we actually know the physical volume we want to + read from. */ + if (pv->disk) + err = grub_disk_read (pv->disk, offset, 0, + size << GRUB_DISK_SECTOR_BITS, buf); + else + err = grub_error (GRUB_ERR_UNKNOWN_DEVICE, + "physical volume %s not found", pv->name); + + return err; + case GRUB_LVM_MIRROR: + i = 0; + while (1) + { + if (!seg->mirrors[i].lv) + err = grub_error (GRUB_ERR_UNKNOWN_DEVICE, "unknown volume '%s'", + seg->mirrors[i].lvname); + else + err = read_lv (seg->mirrors[i].lv, sector, size, buf); + if (!err) + return err; + if (++i >= seg->mirror_count) + return err; + grub_errno = GRUB_ERR_NONE; + } } - else - { - /* This is a striped segment. We have to find the right PV - similar to RAID0. */ - struct grub_lvm_stripe *stripe = seg->stripes; - grub_uint32_t a, b; - grub_uint64_t seg_offset; /* Offset of the segment in PV device. */ - unsigned int stripenr; + return grub_error (GRUB_ERR_IO, "unknown LVM segment"); +} - offset = sector - ((grub_uint64_t) seg->start_extent - * (grub_uint64_t) vg->extent_size); - - a = grub_divmod64 (offset, seg->stripe_size, NULL); - grub_divmod64 (a, seg->stripe_count, &stripenr); - - a = grub_divmod64 (offset, seg->stripe_size * seg->stripe_count, NULL); - grub_divmod64 (offset, seg->stripe_size, &b); - offset = a * seg->stripe_size + b; - - stripe += stripenr; - pv = stripe->pv; - - seg_offset = ((grub_uint64_t) stripe->start - * (grub_uint64_t) vg->extent_size) + pv->start; - - offset += seg_offset; - } - - /* Check whether we actually know the physical volume we want to - read from. */ - if (pv->disk) - err = grub_disk_read (pv->disk, offset, 0, - size << GRUB_DISK_SECTOR_BITS, buf); - else - err = grub_error (GRUB_ERR_UNKNOWN_DEVICE, - "physical volume %s not found", pv->name); - - return err; +static grub_err_t +grub_lvm_read (grub_disk_t disk, grub_disk_addr_t sector, + grub_size_t size, char *buf) +{ + return read_lv (disk->data, sector, size, buf); } static grub_err_t @@ -533,11 +566,7 @@ grub_lvm_scan_device (const char *name) lv->size = 0; - if (!grub_lvm_check_flag (p, "status", "VISIBLE")) - { - skip_lv = 1; - goto lv_parsed; - } + lv->visible = grub_lvm_check_flag (p, "status", "VISIBLE"); lv->segment_count = grub_lvm_getvalue (&p, "segment_count = "); if (p == NULL) @@ -552,7 +581,6 @@ grub_lvm_scan_device (const char *name) for (i = 0; i < lv->segment_count; i++) { - struct grub_lvm_stripe *stripe; p = grub_strstr (p, "segment"); if (p == NULL) @@ -580,78 +608,147 @@ grub_lvm_scan_device (const char *name) goto lvs_segment_fail; } - if (grub_lvm_checkvalue (&p, "type = ", "snapshot")) - { - /* Found a snapshot, give up and move on. */ - skip_lv = 1; - break; - } - - seg->stripe_count = grub_lvm_getvalue (&p, "stripe_count = "); + p = grub_strstr (p, "type = \""); if (p == NULL) - { -#ifdef GRUB_UTIL - grub_util_info ("unknown stripe_count\n"); -#endif - goto lvs_segment_fail; - } + goto lvs_segment_fail; + p += sizeof("type = \"") - 1; lv->size += seg->extent_count * vg->extent_size; - if (seg->stripe_count != 1) - seg->stripe_size = grub_lvm_getvalue (&p, "stripe_size = "); + if (grub_memcmp (p, "striped\"", + sizeof ("striped\"") - 1) == 0) + { + struct grub_lvm_stripe *stripe; - seg->stripes = grub_malloc (sizeof (*stripe) - * seg->stripe_count); - stripe = seg->stripes; + seg->type = GRUB_LVM_STRIPED; + seg->stripe_count = grub_lvm_getvalue (&p, "stripe_count = "); + if (p == NULL) + { +#ifdef GRUB_UTIL + grub_util_info ("unknown stripe_count\n"); +#endif + goto lvs_segment_fail; + } - p = grub_strstr (p, "stripes = ["); - if (p == NULL) + if (seg->stripe_count != 1) + seg->stripe_size = grub_lvm_getvalue (&p, "stripe_size = "); + + seg->stripes = grub_malloc (sizeof (*stripe) + * seg->stripe_count); + stripe = seg->stripes; + + p = grub_strstr (p, "stripes = ["); + if (p == NULL) + { +#ifdef GRUB_UTIL + grub_util_info ("unknown stripes\n"); +#endif + goto lvs_segment_fail2; + } + p += sizeof("stripes = [") - 1; + + for (j = 0; j < seg->stripe_count; j++) + { + char *pvname; + + p = grub_strchr (p, '"'); + if (p == NULL) + continue; + q = ++p; + while (*q != '"') + q++; + + s = q - p; + + pvname = grub_malloc (s + 1); + if (pvname == NULL) + goto lvs_segment_fail2; + + grub_memcpy (pvname, p, s); + pvname[s] = '\0'; + + if (vg->pvs) + for (pv = vg->pvs; pv; pv = pv->next) + { + if (! grub_strcmp (pvname, pv->name)) + { + stripe->pv = pv; + break; + } + } + + grub_free(pvname); + + stripe->start = grub_lvm_getvalue (&p, ","); + if (p == NULL) + continue; + + stripe++; + } + } + else if (grub_memcmp (p, "mirror\"", sizeof ("mirror\"") - 1) + == 0) + { + seg->type = GRUB_LVM_MIRROR; + seg->mirror_count = grub_lvm_getvalue (&p, "mirror_count = "); + if (p == NULL) + { +#ifdef GRUB_UTIL + grub_util_info ("unknown mirror_count\n"); +#endif + goto lvs_segment_fail; + } + + seg->mirrors = grub_zalloc (sizeof (seg->mirrors[0]) + * seg->mirror_count); + + p = grub_strstr (p, "mirrors = ["); + if (p == NULL) + { +#ifdef GRUB_UTIL + grub_util_info ("unknown mirrors\n"); +#endif + goto lvs_segment_fail2; + } + p += sizeof("mirrors = [") - 1; + + for (j = 0; j < seg->mirror_count; j++) + { + char *lvname; + + p = grub_strchr (p, '"'); + if (p == NULL) + continue; + q = ++p; + while (*q != '"') + q++; + + s = q - p; + + lvname = grub_malloc (s + 1); + if (lvname == NULL) + goto lvs_segment_fail2; + + grub_memcpy (lvname, p, s); + lvname[s] = '\0'; + seg->mirrors[j].lvname = lvname; + p = q + 1; + } + } + else { #ifdef GRUB_UTIL - grub_util_info ("unknown stripes\n"); + char *p2; + p2 = grub_strchr (p, '"'); + if (p2) + *p2 = 0; + grub_util_info ("unknown LVM type %s\n", p); + if (p2) + *p2 ='"'; #endif - goto lvs_segment_fail2; - } - p += sizeof("stripes = [") - 1; - - for (j = 0; j < seg->stripe_count; j++) - { - char *pvname; - - p = grub_strchr (p, '"'); - if (p == NULL) - continue; - q = ++p; - while (*q != '"') - q++; - - s = q - p; - - pvname = grub_malloc (s + 1); - if (pvname == NULL) - goto lvs_segment_fail2; - - grub_memcpy (pvname, p, s); - pvname[s] = '\0'; - - if (vg->pvs) - for (pv = vg->pvs; pv; pv = pv->next) - { - if (! grub_strcmp (pvname, pv->name)) - { - stripe->pv = pv; - break; - } - } - - grub_free(pvname); - - stripe->start = grub_lvm_getvalue (&p, ","); - if (p == NULL) - continue; - - stripe++; + /* Found a non-supported type, give up and move on. */ + skip_lv = 1; + break; } seg++; @@ -663,7 +760,6 @@ grub_lvm_scan_device (const char *name) goto fail4; } - lv_parsed: if (p != NULL) p = grub_strchr (p, '}'); if (p == NULL) @@ -690,6 +786,20 @@ grub_lvm_scan_device (const char *name) } } + /* Match mirrors */ + { + struct grub_lvm_lv *lv1; + struct grub_lvm_lv *lv2; + for (lv1 = vg->lvs; lv1; lv1 = lv1->next) + for (i = 0; i < lv1->segment_count; i++) + if (lv1->segments[i].type == GRUB_LVM_MIRROR) + for (j = 0; j < lv1->segments[i].mirror_count; j++) + for (lv2 = vg->lvs; lv2; lv2 = lv2->next) + if (grub_strcmp (lv2->name + grub_strlen (vg->name) + 1, + lv1->segments[i].mirrors[j].lvname) == 0) + lv1->segments[i].mirrors[j].lv = lv2; + } + vg->next = vg_list; vg_list = vg; } diff --git a/include/grub/lvm.h b/include/grub/lvm.h index a4bf3b288..220517183 100644 --- a/include/grub/lvm.h +++ b/include/grub/lvm.h @@ -47,6 +47,9 @@ struct grub_lvm_lv { unsigned int number; unsigned int segment_count; grub_uint64_t size; + + int visible; + struct grub_lvm_segment *segments; /* Pointer to segment_count segments. */ struct grub_lvm_vg *vg; struct grub_lvm_lv *next; @@ -55,6 +58,11 @@ struct grub_lvm_lv { struct grub_lvm_segment { unsigned int start_extent; unsigned int extent_count; + enum { GRUB_LVM_STRIPED, GRUB_LVM_MIRROR } type; + + unsigned int mirror_count; + struct grub_lvm_mirror *mirrors; + unsigned int stripe_count; unsigned int stripe_size; struct grub_lvm_stripe *stripes; /* Pointer to stripe_count stripes. */ @@ -65,6 +73,11 @@ struct grub_lvm_stripe { struct grub_lvm_pv *pv; }; +struct grub_lvm_mirror { + char *lvname; + struct grub_lvm_lv *lv; +}; + #define GRUB_LVM_LABEL_SIZE GRUB_DISK_SECTOR_SIZE #define GRUB_LVM_LABEL_SCAN_SECTORS 4L diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in index 491d2b5ce..d12902e33 100644 --- a/util/grub.d/10_linux.in +++ b/util/grub.d/10_linux.in @@ -111,9 +111,17 @@ EOF EOF } -list=`for i in /boot/vmlinuz-* /boot/vmlinux-* /vmlinuz-* /vmlinux-* ; do - if grub_file_is_not_garbage "$i" ; then echo -n "$i " ; fi - done` +case x`uname -m` in + xi?86 | xx86_64) + list=`for i in /boot/vmlinuz-* /vmlinuz-* ; do + if grub_file_is_not_garbage "$i" ; then echo -n "$i " ; fi + done` ;; + *) + list=`for i in /boot/vmlinuz-* /boot/vmlinux-* /vmlinuz-* /vmlinux-* ; do + if grub_file_is_not_garbage "$i" ; then echo -n "$i " ; fi + done` ;; +esac + prepare_boot_cache= while [ "x$list" != "x" ] ; do From 70e75364fa8627e24bb5ed9eead391c778c4504e Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Tue, 29 Mar 2011 20:33:32 +0200 Subject: [PATCH 352/869] * include/grub/lvm.h (grub_lvm_lv): New field 'visible'. (grub_lvm_segment): New fields 'type', 'mirror_count' and 'mirrors'. (grub_lvm_mirror): New struct. * grub-core/disk/lvm.c (grub_lvm_checkvalue): Commented out. (grub_lvm_iterate): Iterate only visible volumes. (grub_lvm_read): Factor out to .. (read_lv): ... this. Support mirrors. (grub_lvm_read): New wrapper function. (grub_lvm_scan_device): Parse mirrors. Skip everything that isn't stripped or mirrored. --- ChangeLog | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/ChangeLog b/ChangeLog index dcacc600c..e93ffe4c4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2011-03-29 Vladimir Serbinenko + + * include/grub/lvm.h (grub_lvm_lv): New field 'visible'. + (grub_lvm_segment): New fields 'type', 'mirror_count' and 'mirrors'. + (grub_lvm_mirror): New struct. + * grub-core/disk/lvm.c (grub_lvm_checkvalue): Commented out. + (grub_lvm_iterate): Iterate only visible volumes. + (grub_lvm_read): Factor out to .. + (read_lv): ... this. Support mirrors. + (grub_lvm_read): New wrapper function. + (grub_lvm_scan_device): Parse mirrors. Skip everything that isn't + stripped or mirrored. + 2011-03-29 Vladimir Serbinenko * util/grub.d/10_linux.in: Skip vmlinux-* on x86 platforms. From e1eb511d9a069dd09472889322ff53844e56e432 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Tue, 29 Mar 2011 21:12:13 +0200 Subject: [PATCH 353/869] * util/grub.d/20_linux_xen.in: Accept old-style xen kernels. --- ChangeLog | 4 ++++ util/grub.d/20_linux_xen.in | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index e93ffe4c4..073543c16 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2011-03-29 Vladimir Serbinenko + + * util/grub.d/20_linux_xen.in: Accept old-style xen kernels. + 2011-03-29 Vladimir Serbinenko * include/grub/lvm.h (grub_lvm_lv): New field 'visible'. diff --git a/util/grub.d/20_linux_xen.in b/util/grub.d/20_linux_xen.in index e71fc1458..bacd8ffea 100644 --- a/util/grub.d/20_linux_xen.in +++ b/util/grub.d/20_linux_xen.in @@ -96,7 +96,7 @@ EOF linux_list=`for i in /boot/vmlinu[xz]-* /vmlinu[xz]-* ; do basename=$(basename $i) version=$(echo $basename | sed -e "s,^[^0-9]*-,,g") - if grub_file_is_not_garbage "$i" && grep -qx "CONFIG_XEN_DOM0=y" /boot/config-${version} 2> /dev/null ; then echo -n "$i " ; fi + if grub_file_is_not_garbage "$i" && (grep -qx "CONFIG_XEN_DOM0=y" /boot/config-${version} 2> /dev/null || grep -qx "CONFIG_XEN_PRIVILEGED_GUEST=y" /boot/config-${version} 2> /dev/null); then echo -n "$i " ; fi done` if [ "x${linux_list}" = "x" ] ; then exit 0 From fc8584825cb513ffaca12585657b1682ef79a3e5 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 30 Mar 2011 00:05:25 +0200 Subject: [PATCH 354/869] Old macs search for boot.efi rather than for bootia32.efi. * util/grub-install.in: Copy bootia32.efi to boot.efi. * util/grub-mkrescue.in: Likewise. Suggested by: Peter Jones. --- ChangeLog | 8 ++++++++ util/grub-install.in | 4 ++++ util/grub-mkrescue.in | 4 ++++ 3 files changed, 16 insertions(+) diff --git a/ChangeLog b/ChangeLog index 073543c16..661f08502 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2011-03-29 Vladimir Serbinenko + + Old macs search for boot.efi rather than for bootia32.efi. + + * util/grub-install.in: Copy bootia32.efi to boot.efi. + * util/grub-mkrescue.in: Likewise. + Suggested by: Peter Jones. + 2011-03-29 Vladimir Serbinenko * util/grub.d/20_linux_xen.in: Accept old-style xen kernels. diff --git a/util/grub-install.in b/util/grub-install.in index b4a4b3f26..4e78dfadb 100644 --- a/util/grub-install.in +++ b/util/grub-install.in @@ -620,6 +620,10 @@ elif [ "${target_cpu}-${platform}" = "i386-ieee1275" ] || [ "${target_cpu}-${pla fi elif [ x"$platform" = xefi ]; then cp "${grubdir}/core.${imgext}" "${efidir}/${efi_file}" + # For old macs. Suggested by Peter Jones. + if [ x$target_cpu = xi386 ]; then + cp "${grubdir}/core.${imgext}" "${efidir}/boot.efi" + fi # Try to make this image bootable using the EFI Boot Manager, if available. efibootmgr="`which efibootmgr`" diff --git a/util/grub-mkrescue.in b/util/grub-mkrescue.in index 690bddb30..455534009 100644 --- a/util/grub-mkrescue.in +++ b/util/grub-mkrescue.in @@ -286,6 +286,10 @@ if test -e "${efi64_dir}" || test -e "${efi32_dir}"; then make_image "${efi64_dir}" x86_64-efi "${efi_dir}"/efi/boot/bootx64.efi "" # build bootia32.efi make_image "${efi32_dir}" i386-efi "${efi_dir}"/efi/boot/bootia32.efi "" + if [ -e "${efi_dir}"/efi/boot/bootia32.efi ]; then + # For old macs. Suggested by Peter Jones. + cp "${efi_dir}"/efi/boot/bootia32.efi "${efi_dir}"/efi/boot/boot.efi + fi mformat -C -f 2880 -L 16 -i "${iso9660_dir}"/efi.img :: mcopy -s -i "${iso9660_dir}"/efi.img ${efi_dir}/efi ::/ From e30af0297db09528ca5a9e08aaf31154859e0fe4 Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Wed, 30 Mar 2011 03:20:09 +0100 Subject: [PATCH 355/869] * docs/grub.texi (Simple configuration): Explain some of the current limitations of grub-mkconfig. --- ChangeLog | 5 +++++ docs/grub.texi | 10 ++++++++++ 2 files changed, 15 insertions(+) diff --git a/ChangeLog b/ChangeLog index 661f08502..35fd04154 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-03-30 Colin Watson + + * docs/grub.texi (Simple configuration): Explain some of the + current limitations of grub-mkconfig. + 2011-03-29 Vladimir Serbinenko Old macs search for boot.efi rather than for bootia32.efi. diff --git a/docs/grub.texi b/docs/grub.texi index 368d21f1d..9ff72798b 100644 --- a/docs/grub.texi +++ b/docs/grub.texi @@ -1066,6 +1066,16 @@ generates @file{grub.cfg} files suitable for most cases. It is suitable for use when upgrading a distribution, and will discover available kernels and attempt to generate menu entries for them. +@command{grub-mkconfig} does have some limitations. While adding extra +custom menu entries to the end of the list can be done by editing +@file{/etc/grub.d/40_custom} or creating @file{/boot/grub/custom.cfg}, +changing the order of menu entries or changing their titles may require +making complex changes to shell scripts stored in @file{/etc/grub.d/}. This +may be improved in the future. In the meantime, those who feel that it +would be easier to write @file{grub.cfg} directly are encouraged to do so +(@pxref{Booting}, and @ref{Shell-like scripting}), and to disable any system +provided by their distribution to automatically run @command{grub-mkconfig}. + The file @file{/etc/default/grub} controls the operation of @command{grub-mkconfig}. It is sourced by a shell script, and so must be valid POSIX shell input; normally, it will just be a sequence of From 8a748df2fdcabe3bbb4f0ca8654654ae55aac422 Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Wed, 30 Mar 2011 03:22:37 +0100 Subject: [PATCH 356/869] credit --- ChangeLog | 1 + 1 file changed, 1 insertion(+) diff --git a/ChangeLog b/ChangeLog index 35fd04154..3939f1d81 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,6 +2,7 @@ * docs/grub.texi (Simple configuration): Explain some of the current limitations of grub-mkconfig. + Reported by: Leslie Rhorer. 2011-03-29 Vladimir Serbinenko From a7527639063a314a11af11bc11acb681bbc9e724 Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Wed, 30 Mar 2011 03:26:11 +0100 Subject: [PATCH 357/869] * docs/grub.texi (Changes from GRUB Legacy): Minor proofreading. --- ChangeLog | 6 +++++- docs/grub.texi | 7 ++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3939f1d81..b34443efc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,8 @@ -2011-03-30 Colin Watson +2011-03-30 Colin Watson + + * docs/grub.texi (Changes from GRUB Legacy): Minor proofreading. + +2011-03-30 Colin Watson * docs/grub.texi (Simple configuration): Explain some of the current limitations of grub-mkconfig. diff --git a/docs/grub.texi b/docs/grub.texi index 9ff72798b..a07377348 100644 --- a/docs/grub.texi +++ b/docs/grub.texi @@ -229,9 +229,10 @@ scripting language: variables, conditionals, and loops are available. @item A small amount of persistent storage is available across reboots, using the @command{save_env} and @command{load_env} commands in GRUB and the -@command{grub-editenv} utility. For safety reasons this storage is only -available when installed on plain disk (no LVM or RAID), using non-checksumming -filesystem (no ZFS) and using BIOS or EFI functions (no ATA, USB or IEEE1275) +@command{grub-editenv} utility. For safety reasons, this storage is only +available when installed on a plain disk (no LVM or RAID), using a +non-checksumming filesystem (no ZFS), and using BIOS or EFI functions (no +ATA, USB or IEEE1275). @item GRUB 2 has more reliable ways to find its own files and those of target From 2a2da1d030c71912cf11a07dffa8a155673fd4c6 Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Wed, 30 Mar 2011 03:49:22 +0100 Subject: [PATCH 358/869] * docs/grub.texi (Menu-specific commands): Remove some semantics that were true in GRUB Legacy but not in GRUB 2. (submenu): New section. (false): New section. (read): New section. (true): New section. --- ChangeLog | 9 ++++++++ docs/grub.texi | 59 ++++++++++++++++++++++++++++++++++++++++---------- 2 files changed, 57 insertions(+), 11 deletions(-) diff --git a/ChangeLog b/ChangeLog index b34443efc..9fc7fdcf0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2011-03-30 Colin Watson + + * docs/grub.texi (Menu-specific commands): Remove some semantics + that were true in GRUB Legacy but not in GRUB 2. + (submenu): New section. + (false): New section. + (read): New section. + (true): New section. + 2011-03-30 Colin Watson * docs/grub.texi (Changes from GRUB Legacy): Minor proofreading. diff --git a/docs/grub.texi b/docs/grub.texi index a07377348..9abf1b174 100644 --- a/docs/grub.texi +++ b/docs/grub.texi @@ -2411,9 +2411,6 @@ In rescue mode, only the @command{insmod} (@pxref{insmod}), @command{ls} The semantics used in parsing the configuration file are the following: @itemize @bullet -@item -The menu-specific commands have to be used before any others. - @item The files @emph{must} be in plain-text format. @@ -2427,20 +2424,13 @@ Options are separated by spaces. @item All numbers can be either decimal or hexadecimal. A hexadecimal number must be preceded by @samp{0x}, and is case-insensitive. - -@item -Extra options or text at the end of the line are ignored unless otherwise -specified. - -@item -Unrecognized commands are added to the current entry, except before entries -start, where they are ignored. @end itemize These commands can only be used in the menu: @menu * menuentry:: Start a menu entry +* submenu:: Group menu entries @end menu @@ -2470,6 +2460,22 @@ The @option{--hotkey} option associates a hotkey with a menu entry. @end deffn +@node submenu +@subsection submenu + +@deffn Command submenu @var{title} @ + [@option{--class=class} @dots{}] [@option{--users=users}] @ + [@option{--hotkey=key}] @ + @{ @var{menu entries} @dots{} @} +This defines a submenu. An entry called @var{title} will be added to the +menu; when that entry is selected, a new menu will be displayed showing all +the entries within this submenu. + +All options are the same as in the @command{menuentry} command +(@pxref{menuentry}). +@end deffn + + @node General commands @section The list of general commands @@ -2590,6 +2596,7 @@ you forget a command, you can run the command @command{help} * drivemap:: Map a drive to another * echo:: Display a line of text * export:: Export an environment variable +* false:: Do nothing, unsuccessfully * gettext:: Translate a string * gptsync:: Fill an MBR based on GPT entries * halt:: Shut down your computer @@ -2607,10 +2614,12 @@ you forget a command, you can run the command @command{help} * password_pbkdf2:: Set a hashed password * play:: Play a tune * pxe_unload:: Unload the PXE environment +* read:: Read user input * reboot:: Reboot your computer * search:: Search devices by file, label, or UUID * sendkey:: Emulate keystrokes * set:: Set an environment variable +* true:: Do nothing, successfully * unset:: Unset an environment variable * uppermem:: Set the upper memory size @end menu @@ -2853,6 +2862,15 @@ to subsidiary configuration files loaded using @command{configfile}. @end deffn +@node false +@subsection false + +@deffn Command false +Do nothing, unsuccessfully. This is mainly useful in control constructs +such as @code{if} and @code{while} (@pxref{Shell-like scripting}). +@end deffn + + @node gettext @subsection gettext @@ -3106,6 +3124,16 @@ This command is only available on PC BIOS systems. @end deffn +@node read +@subsection read + +@deffn Command read [var] +Read a line of input from the user. If an environment variable @var{var} is +given, set that environment variable to the line of input that was read, +with no terminating newline. +@end deffn + + @node reboot @subsection reboot @@ -3294,6 +3322,15 @@ arguments, print all environment variables with their values. @end deffn +@node true +@subsection true + +@deffn Command true +Do nothing, successfully. This is mainly useful in control constructs such +as @code{if} and @code{while} (@pxref{Shell-like scripting}). +@end deffn + + @node unset @subsection unset From 5d8031749e8b8642d31f6f9da510bca3872ffea2 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 30 Mar 2011 09:26:23 +0200 Subject: [PATCH 359/869] * grub-core/term/at_keyboard.c (set_scancodes) [!GRUB_MACHINE_MIPS_YEELOONG && !GRUB_MACHINE_QEMU]: Use scancode set 1. --- ChangeLog | 5 +++++ grub-core/term/at_keyboard.c | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/ChangeLog b/ChangeLog index 9fc7fdcf0..778d86145 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-03-30 Vladimir Serbinenko + + * grub-core/term/at_keyboard.c (set_scancodes) + [!GRUB_MACHINE_MIPS_YEELOONG && !GRUB_MACHINE_QEMU]: Use scancode set 1. + 2011-03-30 Colin Watson * docs/grub.texi (Menu-specific commands): Remove some semantics diff --git a/grub-core/term/at_keyboard.c b/grub-core/term/at_keyboard.c index 55cb76483..7ce287ecc 100644 --- a/grub-core/term/at_keyboard.c +++ b/grub-core/term/at_keyboard.c @@ -330,6 +330,11 @@ set_scancodes (void) return; } +#if !(defined (GRUB_MACHINE_MIPS_YEELOONG) || defined (GRUB_MACHINE_QEMU)) + current_set = 1; + return; +#endif + grub_keyboard_controller_write (grub_keyboard_controller_orig & ~KEYBOARD_AT_TRANSLATE); From e1ad0edd11ea71bdb059fd2768a5e2dbe6589315 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 30 Mar 2011 09:35:35 +0200 Subject: [PATCH 360/869] * docs/grub.texi: Correctly use "terminal_input" and not "terminal" in the example. --- ChangeLog | 5 +++++ docs/grub.texi | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 778d86145..c28b07653 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-03-30 Vladimir Serbinenko + + * docs/grub.texi: Correctly use "terminal_input" and not "terminal" in + the example. + 2011-03-30 Vladimir Serbinenko * grub-core/term/at_keyboard.c (set_scancodes) diff --git a/docs/grub.texi b/docs/grub.texi index 9abf1b174..a347579b3 100644 --- a/docs/grub.texi +++ b/docs/grub.texi @@ -1998,7 +1998,7 @@ The commands @command{terminal_input} (@pxref{terminal_input}) and @command{terminal_output} (@pxref{terminal_output}) choose which type of 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, -as @samp{terminal serial console}. In this case, a terminal in which +as @samp{terminal_input serial console}. In this case, a terminal in which 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 From 421284f2998aa3e9134372379a2bd03de08a2740 Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Wed, 30 Mar 2011 10:19:08 +0100 Subject: [PATCH 361/869] * docs/grub.texi (Simple configuration): Update GRUB_GFXMODE documentation. --- ChangeLog.vbe-autodetect | 2 ++ docs/grub.texi | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/ChangeLog.vbe-autodetect b/ChangeLog.vbe-autodetect index 3341e8cc3..6308e5793 100644 --- a/ChangeLog.vbe-autodetect +++ b/ChangeLog.vbe-autodetect @@ -29,3 +29,5 @@ * util/grub.d/00_header.in (GRUB_GFXMODE): Default to "auto". This is more appropriate on a wider range of platforms than 640x480. + * docs/grub.texi (Simple configuration): Update GRUB_GFXMODE + documentation. diff --git a/docs/grub.texi b/docs/grub.texi index 54a2d8791..885bb4731 100644 --- a/docs/grub.texi +++ b/docs/grub.texi @@ -1140,7 +1140,8 @@ listed in @file{/boot/grub/video.lst}. Set the resolution used on the @samp{gfxterm} graphical terminal. Note that you can only use modes which your graphics card supports via VESA BIOS Extensions (VBE), so for example native LCD panel resolutions may not be -available. The default is @samp{640x480}. +available. The default is @samp{auto}, which tries to select a preferred +resolution. @item GRUB_BACKGROUND Set a background image for use with the @samp{gfxterm} graphical terminal. From abf042006ef39370254e3758970d9bcab37218cb Mon Sep 17 00:00:00 2001 From: <> Date: Wed, 30 Mar 2011 11:31:33 +0100 Subject: [PATCH 362/869] * docs/grub.texi (Environment): New chapter. (Changes from GRUB Legacy): Link to "Environment block" section for details of limitations. (Simple configuration): Likewise. Link to documentation of gfxmode and gfxpayload variables from GRUB_GFXMODE and GRUB_GFXPAYLOAD respectively. (Shell-like scripting): Note that normal variables are stored in the environment. (gettext): Link to documentation of lang and locale_dir. (list_env): New section. (load_env): New section. (save_env): New section. (Reporting bugs): Fix typo. --- ChangeLog | 17 ++ docs/grub.texi | 493 +++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 498 insertions(+), 12 deletions(-) diff --git a/ChangeLog b/ChangeLog index c28b07653..61727a1dd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,20 @@ +2011-03-30 Colin Watson + + * docs/grub.texi (Environment): New chapter. + (Changes from GRUB Legacy): Link to "Environment block" section for + details of limitations. + (Simple configuration): Likewise. Link to documentation of gfxmode + and gfxpayload variables from GRUB_GFXMODE and GRUB_GFXPAYLOAD + respectively. + (Shell-like scripting): Note that normal variables are stored in the + environment. + (gettext): Link to documentation of lang and locale_dir. + (list_env): New section. + (load_env): New section. + (save_env): New section. + + (Reporting bugs): Fix typo. + 2011-03-30 Vladimir Serbinenko * docs/grub.texi: Correctly use "terminal_input" and not "terminal" in diff --git a/docs/grub.texi b/docs/grub.texi index a347579b3..8441dd267 100644 --- a/docs/grub.texi +++ b/docs/grub.texi @@ -87,6 +87,7 @@ This edition documents version @value{VERSION}. * Images:: GRUB image files * Filesystem:: Filesystem syntax and semantics * Interface:: The menu and the command-line +* Environment:: GRUB environment variables * Commands:: The list of available builtin commands * Security:: Authentication and authorisation * Supported kernels:: The list of supported kernels @@ -229,10 +230,8 @@ scripting language: variables, conditionals, and loops are available. @item A small amount of persistent storage is available across reboots, using the @command{save_env} and @command{load_env} commands in GRUB and the -@command{grub-editenv} utility. For safety reasons, this storage is only -available when installed on a plain disk (no LVM or RAID), using a -non-checksumming filesystem (no ZFS), and using BIOS or EFI functions (no -ATA, USB or IEEE1275). +@command{grub-editenv} utility. This is not available in all configurations +(@pxref{Environment block}). @item GRUB 2 has more reliable ways to find its own files and those of target @@ -1109,8 +1108,8 @@ it as a new default entry for use by future runs of GRUB. This is only useful if @samp{GRUB_DEFAULT=saved}; it is a separate option because @samp{GRUB_DEFAULT=saved} is useful without this option, in conjunction with @command{grub-set-default} or @command{grub-reboot}. Unset by default. -@samp{save_env} may not be available in all situations -(@pxref{Changes from GRUB Legacy}). +This option relies on the environment block, which may not be available in +all situations (@pxref{Environment block}). @item GRUB_TIMEOUT Boot the default entry this many seconds after the menu is displayed, unless @@ -1215,7 +1214,7 @@ listed in @file{/boot/grub/video.lst}. Set the resolution used on the @samp{gfxterm} graphical terminal. Note that you can only use modes which your graphics card supports via VESA BIOS Extensions (VBE), so for example native LCD panel resolutions may not be -available. The default is @samp{640x480}. +available. The default is @samp{640x480}. @xref{gfxmode}. @item GRUB_BACKGROUND Set a background image for use with the @samp{gfxterm} graphical terminal. @@ -1231,7 +1230,7 @@ Set to @samp{text} to force the Linux kernel to boot in normal text mode, @samp{keep} to preserve the graphics mode set using @samp{GRUB_GFXMODE}, @samp{@var{width}x@var{height}}[@samp{x@var{depth}}] to set a particular graphics mode, or a sequence of these separated by commas or semicolons to -try several modes in sequence. +try several modes in sequence. @xref{gfxpayload}. 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 @@ -1342,7 +1341,8 @@ 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. +or more alphanumeric characters. These names refer to entries in the GRUB +environment (@pxref{Environment}). Positional variable names consist of one or more digits. They represent parameters passed to function calls, with @samp{$1} representing the first @@ -2384,6 +2384,437 @@ Although GRUB unfortunately does not support @dfn{undo}, you can do almost the same thing by just returning to the main menu using @key{ESC}. +@node Environment +@chapter GRUB environment variables + +GRUB supports environment variables which are rather like those offered by +all Unix-like systems. Environment variables have a name, which is unique +and is usually a short identifier, and a value, which is an arbitrary string +of characters. They may be set (@pxref{set}), unset (@pxref{unset}), or +looked up (@pxref{Shell-like scripting}) by name. + +A number of environment variables have special meanings to various parts of +GRUB. Others may be used freely in GRUB configuration files. + + +@menu +* Special environment variables:: +* Environment block:: +@end menu + + +@node Special environment variables +@section Special environment variables + +These variables have special meaning to GRUB. + +@menu +* biosnum:: +* chosen:: +* color_highlight:: +* color_normal:: +* debug:: +* default:: +* fallback:: +* gfxmode:: +* gfxpayload:: +* gfxterm_font:: +* icondir:: +* lang:: +* locale_dir:: +* menu_color_highlight:: +* menu_color_normal:: +* net_pxe_boot_file:: +* net_pxe_dhcp_server_name:: +* net_pxe_domain:: +* net_pxe_extensionspath:: +* net_pxe_hostname:: +* net_pxe_ip:: +* net_pxe_mac:: +* net_pxe_rootpath:: +* pager:: +* prefix:: +* pxe_blksize:: +* pxe_default_gateway:: +* pxe_default_server:: +* root:: +* superusers:: +* theme:: +* timeout:: +@end menu + + +@node biosnum +@subsection biosnum + +When chain-loading another boot loader (@pxref{Chain-loading}), GRUB may +need to know what BIOS drive number corresponds to the root device +(@pxref{root}) so that it can set up registers properly. If the +@var{biosnum} variable is set, it overrides GRUB's own means of guessing +this. + +For an alternative approach which also changes BIOS drive mappings for the +chain-loaded system, @pxref{drivemap}. + + +@node chosen +@subsection chosen + +When executing a menu entry, GRUB sets the @var{chosen} variable to the +title of the entry being executed. + +If the menu entry is in one or more submenus, then @var{chosen} is set to +the titles of each of the submenus starting from the top level followed by +the title of the menu entry itself, separated by @samp{>}. + + +@node color_highlight +@subsection color_highlight + +This variable contains the ``highlight'' foreground and background terminal +colors, separated by a slash (@samp{/}). Setting this variable changes +those colors. For the available color names, @pxref{color_normal}. + +The default is @samp{black/white}. + + +@node color_normal +@subsection color_normal + +This variable contains the ``normal'' foreground and background terminal +colors, separated by a slash (@samp{/}). Setting this variable changes +those colors. Each color must be a name from the following list: + +@itemize @bullet +@item black +@item blue +@item green +@item cyan +@item red +@item magenta +@item brown +@item light-gray +@item dark-gray +@item light-blue +@item light-green +@item light-cyan +@item light-red +@item light-magenta +@item yellow +@item white +@end itemize + +The default is @samp{white/black}. + + +@node debug +@subsection debug + +This variable may be set to enable debugging output from various components +of GRUB. The value is a list of debug facility names separated by +whitespace or @samp{,}, or @samp{all} to enable all available debugging +output. + + +@node default +@subsection default + +If this variable is set, it identifies a menu entry that should be selected +by default, possibly after a timeout (@pxref{timeout}). The entry may be +identified by number or by title. + +If the entry is in a submenu, then it must be identified using the titles of +each of the submenus starting from the top level followed by the number or +title of the menu entry itself, separated by @samp{>}. For example, take +the following menu structure: + +@itemize @w +@item Submenu 1 +@itemize @w +@item Menu Entry 1 +@item Menu Entry 2 +@end itemize +@item Submenu 2 +@itemize @w +@item Submenu 3 +@itemize @w +@item Menu Entry 3 +@item Menu Entry 4 +@end itemize +@item Menu Entry 5 +@end itemize +@end itemize + +``Menu Entry 3'' would then be identified as +@samp{Submenu 2>Submenu 3>Menu Entry 3}. + +This variable is often set by @samp{GRUB_DEFAULT} (@pxref{Simple +configuration}), @command{grub-set-default}, or @command{grub-reboot}. + + +@node fallback +@subsection fallback + +If this variable is set, it identifies a menu entry that should be selected +if the default menu entry fails to boot. Entries are identified in the same +way as for @samp{default} (@pxref{default}). + + +@node gfxmode +@subsection gfxmode + +If this variable is set, it sets the resolution used on the @samp{gfxterm} +graphical terminal. Note that you can only use modes which your graphics +card supports via VESA BIOS Extensions (VBE), so for example native LCD +panel resolutions may not be available. The default is @samp{auto}, which +selects a platform-specific default that should look reasonable. + +The resolution may be specified as a sequence of one or more modes, +separated by commas (@samp{,}) or semicolons (@samp{;}); each will be tried +in turn until one is found. Each mode should be either @samp{auto}, +@samp{@var{width}x@var{height}}, or +@samp{@var{width}x@var{height}x@var{depth}}. + + +@node gfxpayload +@subsection gfxpayload + +If this variable is set, it controls the video mode in which the Linux +kernel starts up, replacing the @samp{vga=} boot option (@pxref{linux}). It +may be set to @samp{text} to force the Linux kernel to boot in normal text +mode, @samp{keep} to preserve the graphics mode set using @samp{gfxmode}, or +any of the permitted values for @samp{gfxmode} to set a particular graphics +mode (@pxref{gfxmode}). + +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 +from various display problems, particularly during the early part of the +boot sequence. If you have problems, set this variable to @samp{text} and +GRUB will tell Linux to boot in normal text mode. + +The default is platform-specific. On platforms with a native text mode +(such as PC BIOS platforms), the default is @samp{text}. Otherwise the +default may be @samp{auto} or a specific video mode. + +This variable is often set by @samp{GRUB_GFXPAYLOAD_LINUX} (@pxref{Simple +configuration}). + + +@node gfxterm_font +@subsection gfxterm_font + +If this variable is set, it names a font to use for text on the +@samp{gfxterm} graphical terminal. Otherwise, @samp{gfxterm} may use any +available font. + + +@node icondir +@subsection icondir + +If this variable is set, it names a directory in which the GRUB graphical +menu should look for icons after looking in the theme's @samp{icons} +directory. @xref{Theme file format}. + + +@node lang +@subsection lang + +If this variable is set, it names the language code that the +@command{gettext} command (@pxref{gettext}) uses to translate strings. For +example, French would be named as @samp{fr}, and Simplified Chinese as +@samp{zh_CN}. + +@command{grub-mkconfig} (@pxref{Simple configuration}) will try to set a +reasonable default for this variable based on the system locale. + + +@node locale_dir +@subsection locale_dir + +If this variable is set, it names the directory where translation files may +be found (@pxref{gettext}), usually @file{/boot/grub/locale}. Otherwise, +internationalization is disabled. + +@command{grub-mkconfig} (@pxref{Simple configuration}) will set a reasonable +default for this variable if internationalization is needed and any +translation files are available. + + +@node menu_color_highlight +@subsection menu_color_highlight + +This variable contains the foreground and background colors to be used for +the highlighted menu entry, separated by a slash (@samp{/}). Setting this +variable changes those colors. For the available color names, +@pxref{color_normal}. + +The default is the value of @samp{color_highlight} +(@pxref{color_highlight}). + + +@node menu_color_normal +@subsection menu_color_normal + +This variable contains the foreground and background colors to be used for +non-highlighted menu entries, separated by a slash (@samp{/}). Setting this +variable changes those colors. For the available color names, +@pxref{color_normal}. + +The default is the value of @samp{color_normal} (@pxref{color_normal}). + + +@node net_pxe_boot_file +@subsection net_pxe_boot_file + +@xref{Network}. + + +@node net_pxe_dhcp_server_name +@subsection net_pxe_dhcp_server_name + +@xref{Network}. + + +@node net_pxe_domain +@subsection net_pxe_domain + +@xref{Network}. + + +@node net_pxe_extensionspath +@subsection net_pxe_extensionspath + +@xref{Network}. + + +@node net_pxe_hostname +@subsection net_pxe_hostname + +@xref{Network}. + + +@node net_pxe_ip +@subsection net_pxe_ip + +@xref{Network}. + + +@node net_pxe_mac +@subsection net_pxe_mac + +@xref{Network}. + + +@node net_pxe_rootpath +@subsection net_pxe_rootpath + +@xref{Network}. + + +@node pager +@subsection pager + +If set to @samp{1}, pause output after each screenful and wait for keyboard +input. The default is not to pause output. + + +@node prefix +@subsection prefix + +The location of the @samp{/boot/grub} directory as an absolute file name +(@pxref{File name syntax}). This is normally set by GRUB at startup based +on information provided by @command{grub-install}. GRUB modules are +dynamically loaded from this directory, so it must be set correctly in order +for many parts of GRUB to work. + + +@node pxe_blksize +@subsection pxe_blksize + +@xref{Network}. + + +@node pxe_default_gateway +@subsection pxe_default_gateway + +@xref{Network}. + + +@node pxe_default_server +@subsection pxe_default_server + +@xref{Network}. + + +@node root +@subsection root + +The root device name (@pxref{Device syntax}). Any file names that do not +specify an explicit device name are read from this device. The default is +normally set by GRUB at startup based on the value of @samp{prefix} +(@pxref{prefix}). + +For example, if GRUB was installed to the first partition of the first hard +disk, then @samp{prefix} might be set to @samp{(hd0,msdos1)/boot/grub} and +@samp{root} to @samp{hd0,msdos1}. + + +@node superusers +@subsection superusers + +This variable may be set to a list of superuser names to enable +authentication support. @xref{Security}. + + +@node theme +@subsection theme + +This variable may be set to a directory containing a GRUB graphical menu +theme. @xref{Theme file format}. + +This variable is often set by @samp{GRUB_THEME} (@pxref{Simple +configuration}). + + +@node timeout +@subsection timeout + +If this variable is set, it specifies the time in seconds to wait for +keyboard input before booting the default menu entry. A timeout of @samp{0} +means to boot the default entry immediately without displaying the menu; a +timeout of @samp{-1} (or unset) means to wait indefinitely. + +This variable is often set by @samp{GRUB_TIMEOUT} or +@samp{GRUB_HIDDEN_TIMEOUT} (@pxref{Simple configuration}). + + +@node Environment block +@section The GRUB environment block + +It is often useful to be able to remember a small amount of information from +one boot to the next. For example, you might want to set the default menu +entry based on what was selected the last time. GRUB deliberately does not +implement support for writing files in order to minimise the possibility of +the boot loader being responsible for file system corruption, so a GRUB +configuration file cannot just create a file in the ordinary way. However, +GRUB provides an ``environment block'' which can be used to save a small +amount of state. + +The environment block is a preallocated 1024-byte file, which normally lives +in @file{/boot/grub/grubenv} (although you should not assume this). At boot +time, the @command{load_env} command (@pxref{load_env}) loads environment +variables from it, and the @command{save_env} (@pxref{save_env}) command +saves environment variables to it. From a running system, the +@command{grub-editenv} utility can be used to edit the environment block. + +For safety reasons, this storage is only available when installed on a plain +disk (no LVM or RAID), using a non-checksumming filesystem (no ZFS), and +using BIOS or EFI functions (no ATA, USB or IEEE1275). + +@command{grub-mkconfig} uses this facility to implement +@samp{GRUB_SAVEDEFAULT} (@pxref{Simple configuration}). + + @node Commands @chapter The list of available commands @@ -2607,6 +3038,8 @@ you forget a command, you can run the command @command{help} * keystatus:: Check key modifier status * linux:: Load a Linux kernel * linux16:: Load a Linux kernel (16-bit mode) +* list_env:: List variables in environment block +* load_env:: Load variables from environment block * loopback:: Make a device from a filesystem image * ls:: List devices or files * parttool:: Modify partition table entries @@ -2616,6 +3049,7 @@ you forget a command, you can run the command @command{help} * pxe_unload:: Unload the PXE environment * read:: Read user input * reboot:: Reboot your computer +* save_env:: Save variables to environment block * search:: Search devices by file, label, or UUID * sendkey:: Emulate keystrokes * set:: Set an environment variable @@ -2878,8 +3312,8 @@ such as @code{if} and @code{while} (@pxref{Shell-like scripting}). Translate @var{string} into the current language. The current language code is stored in the @samp{lang} variable in GRUB's -environment. Translation files in MO format are read from -@samp{locale_dir}, usually @file{/boot/grub/locale}. +environment (@pxref{lang}). Translation files in MO format are read from +@samp{locale_dir} (@pxref{locale_dir}), usually @file{/boot/grub/locale}. @end deffn @@ -3008,6 +3442,29 @@ This command is only available on x86 systems. @end deffn +@node list_env +@subsection list_env + +@deffn Command list_env [@option{-f} file] +List all variables in the environment block file. @xref{Environment block}. + +The @option{-f} option overrides the default location of the environment +block. +@end deffn + + +@node load_env +@subsection load_env + +@deffn Command load_env [@option{-f} file] +Load all variables from the environment block file into the environment. +@xref{Environment block}. + +The @option{-f} option overrides the default location of the environment +block. +@end deffn + + @node loopback @subsection loopback @@ -3142,6 +3599,18 @@ Reboot the computer. @end deffn +@node save_env +@subsection save_env + +@deffn Command save_env [@option{-f} file] var @dots{} +Save the named variables from the environment to the environment block file. +@xref{Environment block}. + +The @option{-f} option overrides the default location of the environment +block. +@end deffn + + @node search @subsection search @@ -3868,7 +4337,7 @@ for. @item Write down anything that you think might be related. Please understand -that we often need to reproduce the same problem you encounterred in our +that we often need to reproduce the same problem you encountered in our environment. So your information should be sufficient for us to do the same thing---Don't forget that we cannot see your computer directly. If you are not sure whether to state a fact or leave it out, state it! From 3d7ed04e92786d287be33a31aa62daff823e4435 Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Wed, 30 Mar 2011 11:34:52 +0100 Subject: [PATCH 363/869] * docs/grub.texi (Future): Update. --- ChangeLog | 4 ++++ docs/grub.texi | 11 +++++------ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index 61727a1dd..10bb289cc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2011-03-30 Colin Watson + + * docs/grub.texi (Future): Update. + 2011-03-30 Colin Watson * docs/grub.texi (Environment): New chapter. diff --git a/docs/grub.texi b/docs/grub.texi index 8441dd267..1c21cb67d 100644 --- a/docs/grub.texi +++ b/docs/grub.texi @@ -4357,12 +4357,11 @@ Once we get your report, we will try to fix the bugs. @node Future @appendix Where GRUB will go -We started the next generation of GRUB, GRUB 2. GRUB 2 includes -internationalization, dynamic module loading, real memory management, -multiple architecture support, a scripting language, and many other -nice features. If you are interested in the development of GRUB 2, take -a look at @uref{http://www.gnu.org/software/grub/grub.html, the -homepage}. +GRUB 2 is now quite stable and used in many production systems. We are +currently working towards a 2.0 release. + +If you are interested in the development of GRUB 2, take a look at +@uref{http://www.gnu.org/software/grub/grub.html, the homepage}. @node Internals From 2d5d0333d6982e175edc5982b487cf11514e1fb3 Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Wed, 30 Mar 2011 11:46:36 +0100 Subject: [PATCH 364/869] * docs/grub.texi (default): Use @example rather than nested itemized lists to avoid breaking gendocs. --- ChangeLog | 5 +++++ docs/grub.texi | 26 ++++++++++---------------- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/ChangeLog b/ChangeLog index 10bb289cc..1e20b132e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-03-30 Colin Watson + + * docs/grub.texi (default): Use @example rather than nested + itemized lists to avoid breaking gendocs. + 2011-03-30 Colin Watson * docs/grub.texi (Future): Update. diff --git a/docs/grub.texi b/docs/grub.texi index 1c21cb67d..dd3afcf48 100644 --- a/docs/grub.texi +++ b/docs/grub.texi @@ -2528,22 +2528,16 @@ each of the submenus starting from the top level followed by the number or title of the menu entry itself, separated by @samp{>}. For example, take the following menu structure: -@itemize @w -@item Submenu 1 -@itemize @w -@item Menu Entry 1 -@item Menu Entry 2 -@end itemize -@item Submenu 2 -@itemize @w -@item Submenu 3 -@itemize @w -@item Menu Entry 3 -@item Menu Entry 4 -@end itemize -@item Menu Entry 5 -@end itemize -@end itemize +@example +Submenu 1 + Menu Entry 1 + Menu Entry 2 +Submenu 2 + Submenu 3 + Menu Entry 3 + Menu Entry 4 + Menu Entry 5 +@end example ``Menu Entry 3'' would then be identified as @samp{Submenu 2>Submenu 3>Menu Entry 3}. From 87d1aa1927c2e91dcd37341e6e363011a8a48c05 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 30 Mar 2011 13:02:39 +0200 Subject: [PATCH 365/869] * grub-core/disk/lvm.c (grub_lvm_scan_device): Remove spurious \n. --- ChangeLog | 4 ++++ grub-core/disk/lvm.c | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 1e20b132e..103d12189 100644 --- a/ChangeLog +++ b/ChangeLog @@ -24,6 +24,10 @@ (Reporting bugs): Fix typo. +2011-03-30 Vladimir Serbinenko + + * grub-core/disk/lvm.c (grub_lvm_scan_device): Remove spurious \n. + 2011-03-30 Vladimir Serbinenko * docs/grub.texi: Correctly use "terminal_input" and not "terminal" in diff --git a/grub-core/disk/lvm.c b/grub-core/disk/lvm.c index b1a7a50a9..5a79063da 100644 --- a/grub-core/disk/lvm.c +++ b/grub-core/disk/lvm.c @@ -336,7 +336,7 @@ grub_lvm_scan_device (const char *name) if (i == GRUB_LVM_LABEL_SCAN_SECTORS) { #ifdef GRUB_UTIL - grub_util_info ("no LVM signature found\n"); + grub_util_info ("no LVM signature found"); #endif goto fail; } From 5e631b4fcb6cf6a5b47834a55a32c65c1121c905 Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Wed, 30 Mar 2011 12:07:43 +0100 Subject: [PATCH 366/869] fix ChangeLog ordering --- ChangeLog | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 103d12189..b251826af 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2011-03-30 Vladimir Serbinenko + + * grub-core/disk/lvm.c (grub_lvm_scan_device): Remove spurious \n. + 2011-03-30 Colin Watson * docs/grub.texi (default): Use @example rather than nested @@ -24,10 +28,6 @@ (Reporting bugs): Fix typo. -2011-03-30 Vladimir Serbinenko - - * grub-core/disk/lvm.c (grub_lvm_scan_device): Remove spurious \n. - 2011-03-30 Vladimir Serbinenko * docs/grub.texi: Correctly use "terminal_input" and not "terminal" in From c871b1c6d0ff9dcb79f7b4b9503eacfa8b405509 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 30 Mar 2011 13:13:25 +0200 Subject: [PATCH 367/869] * grub-core/kern/emu/hostdisk.c (grub_util_biosdisk_get_grub_dev): Add few potentially useful grub_util_info. --- ChangeLog | 5 +++++ grub-core/kern/emu/hostdisk.c | 2 ++ 2 files changed, 7 insertions(+) diff --git a/ChangeLog b/ChangeLog index b251826af..b93141df6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-03-30 Vladimir Serbinenko + + * grub-core/kern/emu/hostdisk.c (grub_util_biosdisk_get_grub_dev): Add + few potentially useful grub_util_info. + 2011-03-30 Vladimir Serbinenko * grub-core/disk/lvm.c (grub_lvm_scan_device): Remove spurious \n. diff --git a/grub-core/kern/emu/hostdisk.c b/grub-core/kern/emu/hostdisk.c index 9900a79bd..d5b0439fb 100644 --- a/grub-core/kern/emu/hostdisk.c +++ b/grub-core/kern/emu/hostdisk.c @@ -1518,6 +1518,7 @@ grub_util_biosdisk_get_grub_dev (const char *os_dev) if (stat (os_dev, &st) < 0) { grub_error (GRUB_ERR_BAD_DEVICE, "cannot stat `%s'", os_dev); + grub_util_info ("cannot stat `%s'", os_dev); return 0; } @@ -1526,6 +1527,7 @@ grub_util_biosdisk_get_grub_dev (const char *os_dev) { grub_error (GRUB_ERR_UNKNOWN_DEVICE, "no mapping exists for `%s'", os_dev); + grub_util_info ("no mapping exists for `%s'", os_dev); return 0; } From 56445fb2b459f3dce2b7dc8b70cf9db90aae9d88 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 30 Mar 2011 16:37:10 +0200 Subject: [PATCH 368/869] * grub-core/kern/emu/getroot.c (grub_util_get_grub_dev) [__linux__]: Preserve partition number in mdadm code path. --- ChangeLog | 5 +++++ grub-core/kern/emu/getroot.c | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/ChangeLog b/ChangeLog index b93141df6..0afcadf68 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-03-30 Vladimir Serbinenko + + * grub-core/kern/emu/getroot.c (grub_util_get_grub_dev) [__linux__]: + Preserve partition number in mdadm code path. + 2011-03-30 Vladimir Serbinenko * grub-core/kern/emu/hostdisk.c (grub_util_biosdisk_get_grub_dev): Add diff --git a/grub-core/kern/emu/getroot.c b/grub-core/kern/emu/getroot.c index 1d87442d9..ae066d2f8 100644 --- a/grub-core/kern/emu/getroot.c +++ b/grub-core/kern/emu/getroot.c @@ -808,12 +808,30 @@ grub_util_get_grub_dev (const char *os_dev) if (mdadm_name) { char *newname; + char *q; + + for (q = os_dev + strlen (os_dev) - 1; q >= os_dev && isdigit (*q); + q--); + + if (q >= os_dev && *q == 'p') + { + newname = xasprintf ("/dev/md/%sp%s", mdadm_name, q + 1); + if (stat (newname, &st) == 0) + { + free (grub_dev); + grub_dev = xasprintf ("md/%s,%s", mdadm_name, q + 1); + goto done; + } + free (newname); + } newname = xasprintf ("/dev/md/%s", mdadm_name); if (stat (newname, &st) == 0) { free (grub_dev); grub_dev = xasprintf ("md/%s", mdadm_name); } + + done: free (newname); free (mdadm_name); } From 241e41f55c5cb9b05f7f596a8ea039bcb6ebb031 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 30 Mar 2011 16:54:11 +0200 Subject: [PATCH 369/869] * grub-core/disk/raid.c (insert_array): Add few potentially useful grub_util_info. (grub_raid_register): Likewise. --- ChangeLog | 6 ++++++ grub-core/disk/raid.c | 8 ++++++++ 2 files changed, 14 insertions(+) diff --git a/ChangeLog b/ChangeLog index 0afcadf68..35a2de3e3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2011-03-30 Vladimir Serbinenko + + * grub-core/disk/raid.c (insert_array): Add few potentially + useful grub_util_info. + (grub_raid_register): Likewise. + 2011-03-30 Vladimir Serbinenko * grub-core/kern/emu/getroot.c (grub_util_get_grub_dev) [__linux__]: diff --git a/grub-core/disk/raid.c b/grub-core/disk/raid.c index 9d2468b88..c89ca62a1 100644 --- a/grub-core/disk/raid.c +++ b/grub-core/disk/raid.c @@ -638,6 +638,10 @@ insert_array (grub_disk_t disk, struct grub_raid_array *new_array, grub_dprintf ("raid", "Found array %s (%s)\n", array->name, scanner_name); +#ifdef GRUB_UTIL + grub_util_info ("Found array %s (%s)", array->name, + scanner_name); +#endif /* Add our new array to the list. */ array->next = array_list; @@ -698,6 +702,10 @@ grub_raid_register (grub_raid_t raid) grub_dprintf ("raid", "Scanning for %s RAID devices on disk %s\n", grub_raid_list->name, name); +#ifdef GRUB_UTIL + grub_util_info ("Scanning for %s RAID devices on disk %s", + grub_raid_list->name, name); +#endif disk = grub_disk_open (name); if (!disk) From baad885c14a5e982e19ad8d8c00177dd8ffda8e4 Mon Sep 17 00:00:00 2001 From: Alexey Shvetsov Date: Wed, 30 Mar 2011 19:22:28 +0200 Subject: [PATCH 370/869] * util/grub.d/10_linux.in: Add gentoo-specific Linux and initrd names. * util/grub.d/20_linux_xen.in: Likewise. --- ChangeLog | 5 +++++ util/grub.d/10_linux.in | 8 +++++--- util/grub.d/20_linux_xen.in | 6 ++++-- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 35a2de3e3..462b15810 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-03-30 Alexey Shvetsov + + * util/grub.d/10_linux.in: Add gentoo-specific Linux and initrd names. + * util/grub.d/20_linux_xen.in: Likewise. + 2011-03-30 Vladimir Serbinenko * grub-core/disk/raid.c (insert_array): Add few potentially diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in index d12902e33..9d13529d6 100644 --- a/util/grub.d/10_linux.in +++ b/util/grub.d/10_linux.in @@ -113,11 +113,11 @@ EOF case x`uname -m` in xi?86 | xx86_64) - list=`for i in /boot/vmlinuz-* /vmlinuz-* ; do + list=`for i in /boot/vmlinuz-* /vmlinuz-* /boot/kernel-* ; do if grub_file_is_not_garbage "$i" ; then echo -n "$i " ; fi done` ;; *) - list=`for i in /boot/vmlinuz-* /boot/vmlinux-* /vmlinuz-* /vmlinux-* ; do + list=`for i in /boot/vmlinuz-* /boot/vmlinux-* /vmlinuz-* /vmlinux-* /boot/kernel-* ; do if grub_file_is_not_garbage "$i" ; then echo -n "$i " ; fi done` ;; esac @@ -138,7 +138,9 @@ while [ "x$list" != "x" ] ; do for i in "initrd.img-${version}" "initrd-${version}.img" \ "initrd-${version}" "initramfs-${version}.img" \ "initrd.img-${alt_version}" "initrd-${alt_version}.img" \ - "initrd-${alt_version}" "initramfs-${alt_version}.img"; do + "initrd-${alt_version}" "initramfs-${alt_version}.img" \ + "initramfs-genkernel-${version}" \ + "initramfs-genkernel-${alt_version}"; do if test -e "${dirname}/${i}" ; then initrd="$i" break diff --git a/util/grub.d/20_linux_xen.in b/util/grub.d/20_linux_xen.in index bacd8ffea..50938d1c7 100644 --- a/util/grub.d/20_linux_xen.in +++ b/util/grub.d/20_linux_xen.in @@ -93,7 +93,7 @@ EOF EOF } -linux_list=`for i in /boot/vmlinu[xz]-* /vmlinu[xz]-* ; do +linux_list=`for i in /boot/vmlinu[xz]-* /vmlinu[xz]-* /boot/kernel-*; do basename=$(basename $i) version=$(echo $basename | sed -e "s,^[^0-9]*-,,g") if grub_file_is_not_garbage "$i" && (grep -qx "CONFIG_XEN_DOM0=y" /boot/config-${version} 2> /dev/null || grep -qx "CONFIG_XEN_PRIVILEGED_GUEST=y" /boot/config-${version} 2> /dev/null); then echo -n "$i " ; fi @@ -127,7 +127,9 @@ while [ "x${xen_list}" != "x" ] ; do initrd= for i in "initrd.img-${version}" "initrd-${version}.img" \ "initrd-${version}" "initrd.img-${alt_version}" \ - "initrd-${alt_version}.img" "initrd-${alt_version}"; do + "initrd-${alt_version}.img" "initrd-${alt_version}" \ + "initramfs-genkernel-${version}" \ + "initramfs-genkernel-${alt_version}" ; do if test -e "${dirname}/${i}" ; then initrd="$i" break From 090b1b6ac665f656a5f3ba0e3e59d9d138994238 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 30 Mar 2011 20:42:42 +0200 Subject: [PATCH 371/869] * util/grub.d/10_linux.in: Try alternative config filenames where we parse config file. * util/grub.d/20_linux_xen.in: Likewise. --- ChangeLog | 6 ++++++ util/grub.d/10_linux.in | 13 +++++++++---- util/grub.d/20_linux_xen.in | 14 ++++++++++++-- 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index 462b15810..95e7363a2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2011-03-30 Vladimir Serbinenko + + * util/grub.d/10_linux.in: Try alternative config filenames where + we parse config file. + * util/grub.d/20_linux_xen.in: Likewise. + 2011-03-30 Alexey Shvetsov * util/grub.d/10_linux.in: Add gentoo-specific Linux and initrd names. diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in index 9d13529d6..4f8a7927c 100644 --- a/util/grub.d/10_linux.in +++ b/util/grub.d/10_linux.in @@ -73,8 +73,8 @@ linux_entry () cat << EOF load_video EOF - if grep -qx "CONFIG_FB_EFI=y" /boot/config-${version} 2> /dev/null \ - && grep -qx "CONFIG_VT_HW_CONSOLE_BINDING=y" /boot/config-${version} 2> /dev/null; then + if grep -qx "CONFIG_FB_EFI=y" "${config}" 2> /dev/null \ + && grep -qx "CONFIG_VT_HW_CONSOLE_BINDING=y" "${config}" 2> /dev/null; then cat << EOF set gfxpayload=keep EOF @@ -147,14 +147,19 @@ while [ "x$list" != "x" ] ; do fi done - initramfs= + config= for i in "config-${version}" "config-${alt_version}"; do if test -e "${dirname}/${i}" ; then - initramfs=`grep CONFIG_INITRAMFS_SOURCE= "${dirname}/${i}" | cut -f2 -d= | tr -d \"` + config="${dirname}/${i}" break fi done + initramfs= + if test -n "${config}" ; then + initramfs=`grep CONFIG_INITRAMFS_SOURCE= "${config}" | cut -f2 -d= | tr -d \"` + fi + if test -n "${initrd}" ; then echo "Found initrd image: ${dirname}/${initrd}" >&2 elif test -z "${initramfs}" ; then diff --git a/util/grub.d/20_linux_xen.in b/util/grub.d/20_linux_xen.in index 50938d1c7..59a953ebb 100644 --- a/util/grub.d/20_linux_xen.in +++ b/util/grub.d/20_linux_xen.in @@ -94,10 +94,20 @@ EOF } linux_list=`for i in /boot/vmlinu[xz]-* /vmlinu[xz]-* /boot/kernel-*; do + if grub_file_is_not_garbage "$i"; then basename=$(basename $i) version=$(echo $basename | sed -e "s,^[^0-9]*-,,g") - if grub_file_is_not_garbage "$i" && (grep -qx "CONFIG_XEN_DOM0=y" /boot/config-${version} 2> /dev/null || grep -qx "CONFIG_XEN_PRIVILEGED_GUEST=y" /boot/config-${version} 2> /dev/null); then echo -n "$i " ; fi - done` + dirname=$(dirname $i) + config= + for j in "config-${version}" "config-${alt_version}"; do + if test -e "${dirname}/${j}" ; then + config="${dirname}/${j}" + break + fi + done + if (grep -qx "CONFIG_XEN_DOM0=y" "${config}" 2> /dev/null || grep -qx "CONFIG_XEN_PRIVILEGED_GUEST=y" "${config}" 2> /dev/null); then echo -n "$i " ; fi + fi + done` if [ "x${linux_list}" = "x" ] ; then exit 0 fi From fd7cd914c6763c4aa2810974c69dc0edb3000946 Mon Sep 17 00:00:00 2001 From: Alexey Shvetsov Date: Wed, 30 Mar 2011 20:53:23 +0200 Subject: [PATCH 372/869] * util/grub.d/10_linux.in: Add gentoo-specific config filename. * util/grub.d/20_linux_xen.in: Likewise. --- ChangeLog | 5 +++++ util/grub.d/10_linux.in | 6 +++--- util/grub.d/20_linux_xen.in | 6 +++--- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index 95e7363a2..d0f2acacc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-03-30 Alexey Shvetsov + + * util/grub.d/10_linux.in: Add gentoo-specific config filename. + * util/grub.d/20_linux_xen.in: Likewise. + 2011-03-30 Vladimir Serbinenko * util/grub.d/10_linux.in: Try alternative config filenames where diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in index 4f8a7927c..930ce06ef 100644 --- a/util/grub.d/10_linux.in +++ b/util/grub.d/10_linux.in @@ -148,9 +148,9 @@ while [ "x$list" != "x" ] ; do done config= - for i in "config-${version}" "config-${alt_version}"; do - if test -e "${dirname}/${i}" ; then - config="${dirname}/${i}" + for i in "${dirname}/config-${version}" "${dirname}/config-${alt_version}" "/etc/kernels/kernel-config-${version}" ; do + if test -e "${i}" ; then + config="${i}" break fi done diff --git a/util/grub.d/20_linux_xen.in b/util/grub.d/20_linux_xen.in index 59a953ebb..858627aa3 100644 --- a/util/grub.d/20_linux_xen.in +++ b/util/grub.d/20_linux_xen.in @@ -99,9 +99,9 @@ linux_list=`for i in /boot/vmlinu[xz]-* /vmlinu[xz]-* /boot/kernel-*; do version=$(echo $basename | sed -e "s,^[^0-9]*-,,g") dirname=$(dirname $i) config= - for j in "config-${version}" "config-${alt_version}"; do - if test -e "${dirname}/${j}" ; then - config="${dirname}/${j}" + for j in "${dirname}/config-${version}" "${dirname}/config-${alt_version}" "/etc/kernels/kernel-config-${version}" ; do + if test -e "${j}" ; then + config="${j}" break fi done From 875b67ba09992be7f75534513d84e505789c48b5 Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Wed, 30 Mar 2011 20:52:26 +0100 Subject: [PATCH 373/869] * docs/grub.texi (Commands): Link to "GRUB only offers a rescue shell". --- ChangeLog | 5 +++++ docs/grub.texi | 4 +++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index d0f2acacc..1a533ae17 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-03-30 Colin Watson + + * docs/grub.texi (Commands): Link to "GRUB only offers a rescue + shell". + 2011-03-30 Alexey Shvetsov * util/grub.d/10_linux.in: Add gentoo-specific config filename. diff --git a/docs/grub.texi b/docs/grub.texi index dd3afcf48..fa38b96ff 100644 --- a/docs/grub.texi +++ b/docs/grub.texi @@ -2821,7 +2821,9 @@ anywhere in the menu or specifically in the menu entries. In rescue mode, only the @command{insmod} (@pxref{insmod}), @command{ls} (@pxref{ls}), @command{set} (@pxref{set}), and @command{unset} -(@pxref{unset}) commands are normally available. +(@pxref{unset}) commands are normally available. If you end up in rescue +mode and do not know what to do, then @pxref{GRUB only offers a rescue +shell}. @menu * Menu-specific commands:: From a826cc7d7e09da20b514f3e2b973f89888d3d994 Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Thu, 31 Mar 2011 08:46:41 +0100 Subject: [PATCH 374/869] * docs/grub.texi (Simple configuration): Be more explicit about GRUB_DEFAULT, and add an example. Reported by: Leslie Rhorer. --- ChangeLog | 6 ++++++ docs/grub.texi | 18 ++++++++++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1a533ae17..ff9582918 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2011-03-31 Colin Watson + + * docs/grub.texi (Simple configuration): Be more explicit about + GRUB_DEFAULT, and add an example. + Reported by: Leslie Rhorer. + 2011-03-30 Colin Watson * docs/grub.texi (Commands): Link to "GRUB only offers a rescue diff --git a/docs/grub.texi b/docs/grub.texi index fa38b96ff..0808ded6b 100644 --- a/docs/grub.texi +++ b/docs/grub.texi @@ -1091,11 +1091,25 @@ Valid keys in @file{/etc/default/grub} are as follows: @table @samp @item GRUB_DEFAULT The default menu entry. This may be a number, in which case it identifies -the Nth entry in the generated menu counted from zero, or the full name of a -menu entry, or the special string @samp{saved}. Using the full name may be +the Nth entry in the generated menu counted from zero, or the title of a +menu entry, or the special string @samp{saved}. Using the title may be useful if you want to set a menu entry as the default even though there may be a variable number of entries before it. +For example, if you have: + +@verbatim +menuentry 'Example GNU/Linux distribution' --class gnu-linux { + ... +} +@end verbatim + +then you can make this the default using: + +@example +GRUB_DEFAULT='Example GNU/Linux distribution' +@end example + If you set this to @samp{saved}, then the default menu entry will be that saved by @samp{GRUB_SAVEDEFAULT}, @command{grub-set-default}, or @command{grub-reboot}. From a8afc1d12c9f4a10dc107b8a6ab819f879b10883 Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Thu, 31 Mar 2011 12:25:10 +0100 Subject: [PATCH 375/869] * grub-core/mmap/efi/mmap.c (grub_mmap_unregister): Remove set-but-not-used variable. --- ChangeLog | 5 +++++ grub-core/mmap/efi/mmap.c | 3 +-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index ff9582918..25aa0a496 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-03-31 Colin Watson + + * grub-core/mmap/efi/mmap.c (grub_mmap_unregister): Remove + set-but-not-used variable. + 2011-03-31 Colin Watson * docs/grub.texi (Simple configuration): Be more explicit about diff --git a/grub-core/mmap/efi/mmap.c b/grub-core/mmap/efi/mmap.c index 5b82a8717..8e5cce0d0 100644 --- a/grub-core/mmap/efi/mmap.c +++ b/grub-core/mmap/efi/mmap.c @@ -194,7 +194,6 @@ grub_mmap_unregister (int handle) { struct overlay *curover, *prevover; grub_efi_boot_services_t *b; - grub_efi_status_t status; b = grub_efi_system_table->boot_services; @@ -204,7 +203,7 @@ grub_mmap_unregister (int handle) { if (curover->handle == handle) { - status = efi_call_2 (b->free_pages, curover->address, curover->pages); + efi_call_2 (b->free_pages, curover->address, curover->pages); if (prevover != 0) prevover->next = curover->next; else From 91dc6073309e5582d3293c6c0a037d7f3457dc32 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Thu, 31 Mar 2011 16:48:36 +0200 Subject: [PATCH 376/869] * grub-core/kern/x86_64/efi/callwrap.S (efi_wrap_0): Preserve 16-byte stack alignment. (efi_wrap_1): Likewise. (efi_wrap_2): Likewise. (efi_wrap_3): Likewise. (efi_wrap_4): Likewise. (efi_wrap_5): Likewise. (efi_wrap_6): Likewise. (efi_wrap_10): Likewise. Based on information by: Red Hat/Peter Jones. --- ChangeLog | 13 ++++++++ grub-core/kern/x86_64/efi/callwrap.S | 44 ++++++++++++++-------------- 2 files changed, 35 insertions(+), 22 deletions(-) diff --git a/ChangeLog b/ChangeLog index 25aa0a496..847d04b03 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2011-03-31 Vladimir Serbinenko + + * grub-core/kern/x86_64/efi/callwrap.S (efi_wrap_0): Preserve 16-byte + stack alignment. + (efi_wrap_1): Likewise. + (efi_wrap_2): Likewise. + (efi_wrap_3): Likewise. + (efi_wrap_4): Likewise. + (efi_wrap_5): Likewise. + (efi_wrap_6): Likewise. + (efi_wrap_10): Likewise. + Based on information by: Red Hat/Peter Jones. + 2011-03-31 Colin Watson * grub-core/mmap/efi/mmap.c (grub_mmap_unregister): Remove diff --git a/grub-core/kern/x86_64/efi/callwrap.S b/grub-core/kern/x86_64/efi/callwrap.S index 1946732ae..aae267872 100644 --- a/grub-core/kern/x86_64/efi/callwrap.S +++ b/grub-core/kern/x86_64/efi/callwrap.S @@ -37,80 +37,80 @@ .text FUNCTION(efi_wrap_0) - subq $40, %rsp + subq $48, %rsp call *%rdi - addq $40, %rsp + addq $48, %rsp ret FUNCTION(efi_wrap_1) - subq $40, %rsp + subq $48, %rsp mov %rsi, %rcx call *%rdi - addq $40, %rsp + addq $48, %rsp ret FUNCTION(efi_wrap_2) - subq $40, %rsp + subq $48, %rsp mov %rsi, %rcx call *%rdi - addq $40, %rsp + addq $48, %rsp ret FUNCTION(efi_wrap_3) - subq $40, %rsp + subq $48, %rsp mov %rcx, %r8 mov %rsi, %rcx call *%rdi - addq $40, %rsp + addq $48, %rsp ret FUNCTION(efi_wrap_4) - subq $40, %rsp + subq $48, %rsp mov %r8, %r9 mov %rcx, %r8 mov %rsi, %rcx call *%rdi - addq $40, %rsp + addq $48, %rsp ret FUNCTION(efi_wrap_5) - subq $40, %rsp + subq $48, %rsp mov %r9, 32(%rsp) mov %r8, %r9 mov %rcx, %r8 mov %rsi, %rcx call *%rdi - addq $40, %rsp + addq $48, %rsp ret FUNCTION(efi_wrap_6) - subq $56, %rsp - mov 56+8(%rsp), %rax + subq $64, %rsp + mov 64+8(%rsp), %rax mov %rax, 40(%rsp) mov %r9, 32(%rsp) mov %r8, %r9 mov %rcx, %r8 mov %rsi, %rcx call *%rdi - addq $56, %rsp + addq $64, %rsp ret FUNCTION(efi_wrap_10) - subq $88, %rsp - mov 88+40(%rsp), %rax + subq $96, %rsp + mov 96+40(%rsp), %rax mov %rax, 72(%rsp) - mov 88+32(%rsp), %rax + mov 96+32(%rsp), %rax mov %rax, 64(%rsp) - mov 88+24(%rsp), %rax + mov 96+24(%rsp), %rax mov %rax, 56(%rsp) - mov 88+16(%rsp), %rax + mov 96+16(%rsp), %rax mov %rax, 48(%rsp) - mov 88+8(%rsp), %rax + mov 96+8(%rsp), %rax mov %rax, 40(%rsp) mov %r9, 32(%rsp) mov %r8, %r9 mov %rcx, %r8 mov %rsi, %rcx call *%rdi - addq $88, %rsp + addq $96, %rsp ret From 6dc14451f4769d68d96c40f66644fe52e5a29d39 Mon Sep 17 00:00:00 2001 From: Manoel Rebelo Abranches Date: Fri, 1 Apr 2011 05:12:44 -0300 Subject: [PATCH 377/869] Iterate sockets to see if we expect this packet. Let the App layer to remove its own header. Add packet to socket list if it contains data. Undesired packets are freed. --- grub-core/net/udp.c | 62 ++++++++++++++++++--------------------------- 1 file changed, 25 insertions(+), 37 deletions(-) diff --git a/grub-core/net/udp.c b/grub-core/net/udp.c index a73431f83..16b2011ff 100644 --- a/grub-core/net/udp.c +++ b/grub-core/net/udp.c @@ -5,63 +5,51 @@ #include grub_err_t -grub_net_send_udp_packet (const grub_net_network_level_address_t *target, - struct grub_net_buff *nb, grub_uint16_t srcport, - grub_uint16_t destport) +grub_net_send_udp_packet (const grub_net_socket_t socket , struct grub_net_buff *nb) { struct udphdr *udph; - struct grub_net_network_level_interface *inf; - grub_err_t err; - grub_net_network_level_address_t gateway; - - err = grub_net_route_address (*target, &gateway, &inf); - if (err) - return err; grub_netbuff_push (nb,sizeof(*udph)); udph = (struct udphdr *) nb->data; - udph->src = grub_cpu_to_be16 (srcport); - udph->dst = grub_cpu_to_be16 (destport); + udph->src = grub_cpu_to_be16 (socket->in_port); + udph->dst = grub_cpu_to_be16 (socket->out_port); /* No chechksum. */ udph->chksum = 0; udph->len = grub_cpu_to_be16 (nb->tail - nb->data); - return grub_net_send_ip_packet (inf, target, nb); + return grub_net_send_ip_packet (socket->inf, &(socket->out_nla), nb); } grub_err_t -grub_net_recv_udp_packet (const grub_net_network_level_address_t *target, - struct grub_net_buff *buf, - grub_uint16_t srcport, grub_uint16_t destport) +grub_net_recv_udp_packet (struct grub_net_buff *nb) { - grub_err_t err; - struct grub_net_packet *pkt; - struct grub_net_network_level_interface *inf; - grub_net_network_level_address_t gateway; + //grub_err_t err; + struct udphdr *udph; + grub_net_socket_t sock; + udph = (struct udphdr *) nb->data; + grub_netbuff_pull (nb, sizeof (*udph)); - err = grub_net_route_address (*target, &gateway, &inf); - if (err) - return err; - - (void) srcport; - - err = grub_net_recv_ip_packets (inf); - - FOR_NET_NL_PACKETS(inf, pkt) + FOR_NET_SOCKETS(sock) { - struct udphdr *udph; - struct grub_net_buff *nb = pkt->nb; - udph = (struct udphdr *) nb->data; - if (grub_be_to_cpu16 (udph->dst) == destport) + if (grub_be_to_cpu16 (udph->dst) == sock->in_port) { - grub_net_remove_packet (pkt); - grub_netbuff_pull (nb, sizeof(*udph)); - grub_memcpy (buf, nb, sizeof (buf)); - + if (sock->status == 0) + sock->out_port = udph->src; + + + /* App protocol remove its own reader. */ + sock->app->read (sock,nb); + + /* If there is data, puts packet in socket list */ + if ((nb->tail - nb->data) > 0) + grub_net_put_packet (sock->packs, nb); + else + grub_netbuff_free (nb); return GRUB_ERR_NONE; } } + grub_netbuff_free (nb); return GRUB_ERR_NONE; } From d5e0a358f1252bb4af4002a9589e89ec70f0944c Mon Sep 17 00:00:00 2001 From: Manoel Rebelo Abranches Date: Fri, 1 Apr 2011 05:14:16 -0300 Subject: [PATCH 378/869] Correctly match network. --- grub-core/net/net.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/grub-core/net/net.c b/grub-core/net/net.c index 54663f4b0..ab6b39261 100644 --- a/grub-core/net/net.c +++ b/grub-core/net/net.c @@ -105,7 +105,7 @@ match_net (const grub_net_network_level_netaddress_t *net, { case GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4: { - grub_int32_t mask = (1 << net->ipv4.masksize) - 1; + grub_int32_t mask = ((1 << net->ipv4.masksize) - 1) << (32 - net->ipv4.masksize); return ((grub_be_to_cpu32 (net->ipv4.base) & mask) == (grub_be_to_cpu32 (addr->ipv4) & mask)); } From fbdee79b1729f432e4673a5088b20509be5e032b Mon Sep 17 00:00:00 2001 From: Manoel Rebelo Abranches Date: Fri, 1 Apr 2011 05:22:41 -0300 Subject: [PATCH 379/869] Add generic functions to read and seek in network file. Allocate socket with network and adress information. --- grub-core/net/net.c | 164 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 164 insertions(+) diff --git a/grub-core/net/net.c b/grub-core/net/net.c index ab6b39261..8c9229915 100644 --- a/grub-core/net/net.c +++ b/grub-core/net/net.c @@ -17,8 +17,12 @@ */ #include +#include +#include +#include #include #include +#include #include #include #include @@ -40,6 +44,7 @@ struct grub_net_route struct grub_net_route *grub_net_routes = NULL; struct grub_net_network_level_interface *grub_net_network_level_interfaces = NULL; struct grub_net_card *grub_net_cards = NULL; +struct grub_net_card_driver *grub_net_card_drivers = NULL; struct grub_net_network_level_protocol *grub_net_network_level_protocols = NULL; static inline void @@ -538,6 +543,7 @@ grub_cmd_listcards (struct grub_command *cmd __attribute__ ((unused)), } grub_net_app_level_t grub_net_app_level_list; +struct grub_net_socket *grub_net_sockets; static grub_net_t grub_net_open_real (const char *name) @@ -570,6 +576,159 @@ grub_net_open_real (const char *name) return NULL; } +static grub_err_t +grub_net_file_open_real (struct grub_file *file, const char *name) +{ + grub_err_t err; + grub_net_network_level_address_t addr; + struct grub_net_network_level_interface *inf; + grub_net_network_level_address_t gateway; + grub_net_socket_t socket; + static int port = 25300; + + err = grub_net_resolve_address (file->device->net->name + + sizeof (file->device->net->protocol->name) + 1, &addr); + if (err) + return err; + + err = grub_net_route_address (addr, &gateway, &inf); + if (err) + return err; + + if ((socket = (grub_net_socket_t) grub_malloc (sizeof (*socket))) == NULL) + return GRUB_ERR_OUT_OF_MEMORY; + + socket->inf = inf; + socket->out_nla = addr; + socket->in_port = port++; + socket->status = 0; + socket->app = file->device->net->protocol; + socket->packs = NULL; + file->device->net->socket = socket; + grub_net_socket_register (socket); + + if ((err = file->device->net->protocol->open (file,name))) + goto fail; + + return GRUB_ERR_NONE; +fail: + grub_net_socket_unregister (socket); + grub_free (socket); + return err; + +} + +static grub_err_t +receive_packets (struct grub_net_card *card) +{ + /* Maybe should be better have a fixed number of packets for each card + and just mark them as used and not used. */ + struct grub_net_buff *nb; + nb = grub_netbuff_alloc (1500); + if (!nb) + return grub_errno; + + card->driver->recv (card, nb); + return GRUB_ERR_NONE; +} + +void +grub_net_pool_cards (unsigned time) +{ + struct grub_net_card *card; + grub_uint64_t start_time; + FOR_NET_CARDS (card) + { + start_time = grub_get_time_ms (); + while( (grub_get_time_ms () - start_time) < time) + receive_packets (card); + } +} + +static grub_ssize_t +process_packets (grub_file_t file, void *buf, grub_size_t len, + void *NESTED_FUNC_ATTR (hook) (void *dest, const void *src, grub_size_t n)) +{ + grub_net_socket_t sock = file->device->net->socket; + struct grub_net_buff *nb; + char *ptr = (char *) buf; + grub_size_t amount, total = 0; + int try = 0; + while (try <= 3) + { + while (sock->packs->first) + { + try = 0; + nb = sock->packs->first->nb; + amount = (grub_size_t)(len <= (grub_size_t) (nb->tail - nb->data))? len :(grub_size_t)(nb->tail - nb->data); + len -= amount; + total += amount; + hook (ptr, nb->data, amount); + ptr += amount; + if (amount == (grub_size_t) (nb->tail - nb->data)) + { + grub_netbuff_free (nb); + grub_net_remove_packet (sock->packs->first); + } + else + nb->data += amount; + + if (!len) + return total; + } + if (sock->status == 1) + { + try++; + grub_net_pool_cards (200); + } + else + return total; + } + return total; +} + + +/* Read from the packets list*/ +static grub_ssize_t +grub_net_read_real (grub_file_t file, void *buf, grub_size_t len ) +{ + auto void *NESTED_FUNC_ATTR memcpy_hook (void *dest, const void *src, grub_size_t n); + void *NESTED_FUNC_ATTR memcpy_hook (void *dest __attribute__ ((unused)), const void *src __attribute__ ((unused)), + grub_size_t n __attribute__ ((unused))) + { + return grub_memcpy (dest, src, n); + } + return process_packets (file, buf, len, memcpy_hook); +} + +/* Read from the packets list*/ +static grub_err_t +grub_net_seek_real (struct grub_file *file, grub_off_t offset) +{ + grub_net_socket_t sock = file->device->net->socket; + struct grub_net_buff *nb; + grub_size_t len = offset - file->offset; + + if (!len) + return GRUB_ERR_NONE; + + /* We cant seek backwards past the current packet. */ + if (file->offset > offset) + { + nb = sock->packs->first->nb; + return grub_netbuff_push (nb, file->offset - offset); + } + + auto void *NESTED_FUNC_ATTR dummy (void *dest, const void *src, grub_size_t n); + void *NESTED_FUNC_ATTR dummy (void *dest __attribute__ ((unused)), const void *src __attribute__ ((unused)), + grub_size_t n __attribute__ ((unused))) + { + return NULL; + } + process_packets (file, NULL, len, dummy); + return GRUB_ERR_NONE; +} + static char * grub_env_write_readonly (struct grub_env_var *var __attribute__ ((unused)), const char *val __attribute__ ((unused))) @@ -857,6 +1016,9 @@ GRUB_MOD_INIT(net) N_("retrieve DHCP option and save it into VAR. If VAR is - then print the value.")); grub_net_open = grub_net_open_real; + grub_file_net_open = grub_net_file_open_real; + grub_file_net_read = grub_net_read_real; + grub_file_net_seek = grub_net_seek_real; } GRUB_MOD_FINI(net) @@ -869,4 +1031,6 @@ GRUB_MOD_FINI(net) grub_unregister_command (cmd_lscards); grub_unregister_command (cmd_getdhcp); grub_net_open = NULL; + grub_file_net_read = NULL; + grub_file_net_open = NULL; } From 6ccb7a35e61a2853549dc90fe00981aebc09571b Mon Sep 17 00:00:00 2001 From: Manoel Rebelo Abranches Date: Fri, 1 Apr 2011 05:26:27 -0300 Subject: [PATCH 380/869] Remove unused file. --- grub-core/net/device.c | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 grub-core/net/device.c diff --git a/grub-core/net/device.c b/grub-core/net/device.c deleted file mode 100644 index e69de29bb..000000000 From 6d5c2ed68a8b5f126c2eec349e39496af86d63ab Mon Sep 17 00:00:00 2001 From: Manoel Rebelo Abranches Date: Fri, 1 Apr 2011 05:27:06 -0300 Subject: [PATCH 381/869] Use nb in all function declarations for consistency. --- grub-core/net/netbuff.c | 45 +++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/grub-core/net/netbuff.c b/grub-core/net/netbuff.c index cc366ae09..be9fc9de2 100644 --- a/grub-core/net/netbuff.c +++ b/grub-core/net/netbuff.c @@ -22,43 +22,43 @@ #include -grub_err_t grub_netbuff_put (struct grub_net_buff *net_buff ,grub_size_t len) +grub_err_t grub_netbuff_put (struct grub_net_buff *nb ,grub_size_t len) { - net_buff->tail += len; - if (net_buff->tail > net_buff->end) + nb->tail += len; + if (nb->tail > nb->end) return grub_error (GRUB_ERR_OUT_OF_RANGE, "put out of the packet range."); return GRUB_ERR_NONE; } -grub_err_t grub_netbuff_unput (struct grub_net_buff *net_buff ,grub_size_t len) +grub_err_t grub_netbuff_unput (struct grub_net_buff *nb ,grub_size_t len) { - net_buff->tail -= len; - if (net_buff->tail < net_buff->head) + nb->tail -= len; + if (nb->tail < nb->head) return grub_error (GRUB_ERR_OUT_OF_RANGE, "unput out of the packet range."); return GRUB_ERR_NONE; } -grub_err_t grub_netbuff_push (struct grub_net_buff *net_buff ,grub_size_t len) +grub_err_t grub_netbuff_push (struct grub_net_buff *nb ,grub_size_t len) { - net_buff->data -= len; - if (net_buff->data < net_buff->head) + nb->data -= len; + if (nb->data < nb->head) return grub_error (GRUB_ERR_OUT_OF_RANGE, "push out of the packet range."); return GRUB_ERR_NONE; } -grub_err_t grub_netbuff_pull (struct grub_net_buff *net_buff ,grub_size_t len) +grub_err_t grub_netbuff_pull (struct grub_net_buff *nb ,grub_size_t len) { - net_buff->data += len; - if (net_buff->data > net_buff->end) + nb->data += len; + if (nb->data > nb->end) return grub_error (GRUB_ERR_OUT_OF_RANGE, "pull out of the packet range."); return GRUB_ERR_NONE; } -grub_err_t grub_netbuff_reserve (struct grub_net_buff *net_buff ,grub_size_t len) +grub_err_t grub_netbuff_reserve (struct grub_net_buff *nb ,grub_size_t len) { - net_buff->data += len; - net_buff->tail += len; - if ((net_buff->tail > net_buff->end) || (net_buff->data > net_buff->end)) + nb->data += len; + nb->tail += len; + if ((nb->tail > nb->end) || (nb->data > nb->end)) return grub_error (GRUB_ERR_OUT_OF_RANGE, "reserve out of the packet range."); return GRUB_ERR_NONE; } @@ -73,22 +73,23 @@ struct grub_net_buff *grub_netbuff_alloc ( grub_size_t len ) len = ALIGN_UP (len,NETBUFF_ALIGN); data = grub_memalign (NETBUFF_ALIGN, len + sizeof (*nb)); + if (!data) + return NULL; nb = (struct grub_net_buff *) ((grub_uint8_t *) data + len); nb->head = nb->data = nb->tail = data; - nb->end = (char *) nb; - + nb->end = (char *) nb; return nb; } -grub_err_t grub_netbuff_free (struct grub_net_buff *net_buff) +grub_err_t grub_netbuff_free (struct grub_net_buff *nb) { - grub_free (net_buff->head); + grub_free (nb->head); return 0; } -grub_err_t grub_netbuff_clear (struct grub_net_buff *net_buff) +grub_err_t grub_netbuff_clear (struct grub_net_buff *nb) { - net_buff->data = net_buff->tail = net_buff->head; + nb->data = nb->tail = nb->head; return 0; } From 59b361a2df22426b6d34870bdbcc312641414369 Mon Sep 17 00:00:00 2001 From: Manoel Rebelo Abranches Date: Fri, 1 Apr 2011 05:39:06 -0300 Subject: [PATCH 382/869] Use bootp packet to set prefix and card address. --- grub-core/kern/ieee1275/init.c | 19 +++++- grub-core/kern/ieee1275/openfw.c | 1 + grub-core/net/drivers/ieee1275/ofnet.c | 89 +++++++++++++++++--------- include/grub/ieee1275/ofnet.h | 6 +- 4 files changed, 77 insertions(+), 38 deletions(-) diff --git a/grub-core/kern/ieee1275/init.c b/grub-core/kern/ieee1275/init.c index 682a8b5a4..ad34ea188 100644 --- a/grub-core/kern/ieee1275/init.c +++ b/grub-core/kern/ieee1275/init.c @@ -31,6 +31,8 @@ #include #include #include +#include +#include #include #include @@ -74,7 +76,22 @@ grub_machine_set_prefix (void) char bootpath[64]; /* XXX check length */ char *filename; char *prefix; - + grub_bootp_t bootp_pckt; + char addr[GRUB_NET_MAX_STR_ADDR_LEN]; + + /* Set the net prefix when possible. */ + if (grub_getbootp && (bootp_pckt = grub_getbootp())) + { + grub_uint32_t n = bootp_pckt->siaddr; + grub_snprintf (addr, GRUB_NET_MAX_STR_ADDR_LEN, "%d.%d.%d.%d", + ((n >> 24) & 0xff), ((n >> 16) & 0xff), + ((n >> 8) & 0xff), ((n >> 0) & 0xff)); + prefix = grub_xasprintf ("(tftp,%s)%s", addr,grub_prefix); + grub_env_set ("prefix", prefix); + grub_free (prefix); + return; + } + if (grub_prefix[0]) { grub_env_set ("prefix", grub_prefix); diff --git a/grub-core/kern/ieee1275/openfw.c b/grub-core/kern/ieee1275/openfw.c index 3c228f574..fed4f7e76 100644 --- a/grub-core/kern/ieee1275/openfw.c +++ b/grub-core/kern/ieee1275/openfw.c @@ -28,6 +28,7 @@ #include #include +grub_bootp_t (*grub_getbootp) (void); enum grub_ieee1275_parse_type { GRUB_PARSE_FILENAME, diff --git a/grub-core/net/drivers/ieee1275/ofnet.c b/grub-core/net/drivers/ieee1275/ofnet.c index ce5276efe..10de81bc7 100644 --- a/grub-core/net/drivers/ieee1275/ofnet.c +++ b/grub-core/net/drivers/ieee1275/ofnet.c @@ -78,12 +78,11 @@ bootp_response_properties[] = { .name = "bootpreply-packet", .offset = 0x2a }, }; - -grub_bootp_t -grub_getbootp( void ) +static grub_bootp_t +grub_getbootp_real ( void ) { - grub_bootp_t packet = grub_malloc(sizeof *packet); - void *bootp_response = NULL; + grub_bootp_t packet = grub_malloc (sizeof *packet); + char *bootp_response; grub_ssize_t size; unsigned int i; @@ -94,30 +93,27 @@ grub_getbootp( void ) break; if (size < 0) - { - grub_printf("Error to get bootp\n"); return NULL; - } + bootp_response = grub_malloc (size); if (grub_ieee1275_get_property (grub_ieee1275_chosen, bootp_response_properties[i].name, bootp_response , size, 0) < 0) - { - grub_printf("Error to get bootp\n"); return NULL; - } - packet = (void *) ((int)bootp_response - + bootp_response_properties[i].offset); + grub_memcpy (packet, bootp_response + bootp_response_properties[i].offset, sizeof (*packet)); + grub_free (bootp_response); return packet; } +static void grub_ofnet_findcards (void) { struct grub_net_card *card; + grub_ieee1275_phandle_t devhandle; + grub_net_link_level_address_t lla; int i = 0; - auto int search_net_devices (struct grub_ieee1275_devalias *alias); int search_net_devices (struct grub_ieee1275_devalias *alias) @@ -128,53 +124,82 @@ void grub_ofnet_findcards (void) card = grub_malloc (sizeof (struct grub_net_card)); struct grub_ofnetcard_data *ofdata = grub_malloc (sizeof (struct grub_ofnetcard_data)); ofdata->path = grub_strdup (alias->path); - card->data = ofdata; + + grub_ieee1275_finddevice (ofdata->path, &devhandle); + + if (grub_ieee1275_get_integer_property + (devhandle, "max-frame-size", &(ofdata->mtu), sizeof (ofdata->mtu), 0)) + return grub_error (GRUB_ERR_IO, "Couldn't retrieve mtu size."); + + if (grub_ieee1275_get_property (devhandle, "mac-address", &(lla.mac), 6, 0)) + return grub_error (GRUB_ERR_IO, "Couldn't retrieve mac address."); + + lla.type = GRUB_NET_LINK_LEVEL_PROTOCOL_ETHERNET; + card->default_address = lla; + + card->data = ofdata; + card->flags = 0; card->name = grub_xasprintf("eth%d",i++); // grub_strdup (alias->name); grub_net_card_register (card); } return 0; } - /*Look at all nodes for devices of the type network*/ + /* Look at all nodes for devices of the type network. */ grub_ieee1275_devices_iterate (search_net_devices); - } +static void grub_ofnet_probecards (void) { struct grub_net_card *card; struct grub_net_card_driver *driver; + struct grub_net_network_level_interface *inter; + grub_bootp_t bootp_pckt; + grub_net_network_level_address_t addr; + grub_net_network_level_netaddress_t net; - /*Assign correspondent driver for each device. */ + /* Assign correspondent driver for each device. */ FOR_NET_CARDS (card) { FOR_NET_CARD_DRIVERS (driver) { if (driver->init(card) == GRUB_ERR_NONE) - { - card->driver = driver; - continue; - } + { + card->driver = driver; + bootp_pckt = grub_getbootp (); + if (bootp_pckt) + { + addr.type = GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4; + addr.ipv4 = bootp_pckt->yiaddr; + grub_net_add_addr ("bootp_cli_addr", card, addr, card->default_address, 0); + FOR_NET_NETWORK_LEVEL_INTERFACES (inter) + if (grub_strcmp (inter->name, "bootp_cli_addr") == 0) + break; + net.type = addr.type; + net.ipv4.base = addr.ipv4; + net.ipv4.masksize = 24; + grub_net_add_route ("bootp-router", net, inter); + } + grub_free (bootp_pckt); + break; + } } } } -GRUB_MOD_INIT(ofnet) +GRUB_MOD_INIT (ofnet) { + grub_getbootp = grub_getbootp_real; grub_net_card_driver_register (&ofdriver); - grub_ofnet_findcards(); - grub_ofnet_probecards(); - - /*init tftp stack - will be handled by module subsystem in the future*/ - tftp_ini (); - /*get bootp packet - won't be needed in the future*/ - bootp_pckt = grub_getbootp (); - grub_disknet_init(); + grub_ofnet_findcards (); + grub_ofnet_probecards (); } -GRUB_MODE_FINI(ofnet) +GRUB_MOD_FINI (ofnet) { grub_net_card_driver_unregister (&ofdriver); + grub_getbootp = NULL; } diff --git a/include/grub/ieee1275/ofnet.h b/include/grub/ieee1275/ofnet.h index ba4c62630..9a0ae29e3 100644 --- a/include/grub/ieee1275/ofnet.h +++ b/include/grub/ieee1275/ofnet.h @@ -60,14 +60,10 @@ struct grub_bootp { unsigned char chaddr [16]; /* Client hardware address */ char sname [64]; /* Server name */ char file [128]; /* Boot filename */ -// grub_uint32_t filesize ; /*File size (testing)*/ unsigned char vend [64]; }; typedef struct grub_bootp* grub_bootp_t; -char * grub_get_filestr(const char * ); -char * grub_ip2str (grub_uint32_t ip); -void grub_get_netinfo (grub_ofnet_t netinfo,grub_bootp_t packet); -grub_bootp_t grub_getbootp (void); +extern grub_bootp_t (*EXPORT_VAR (grub_getbootp)) (void); #endif /* ! GRUB_NET_HEADER */ From 457d1104f6137887a04c479ee43b5168b7733987 Mon Sep 17 00:00:00 2001 From: Manoel Rebelo Abranches Date: Fri, 1 Apr 2011 05:40:44 -0300 Subject: [PATCH 383/869] Add ofnet.h to Makefile.am --- grub-core/Makefile.am | 3 +++ 1 file changed, 3 insertions(+) diff --git a/grub-core/Makefile.am b/grub-core/Makefile.am index 050075ef8..0fdb4b1db 100644 --- a/grub-core/Makefile.am +++ b/grub-core/Makefile.am @@ -113,6 +113,7 @@ endif if COND_i386_ieee1275 KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/ieee1275/ieee1275.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/ieee1275/ofnet.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/terminfo.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/extcmd.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/lib/arg.h @@ -148,6 +149,7 @@ endif if COND_powerpc_ieee1275 KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/ieee1275/ieee1275.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/ieee1275/ofnet.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/terminfo.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/extcmd.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/lib/arg.h @@ -155,6 +157,7 @@ endif if COND_sparc64_ieee1275 KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/ieee1275/ieee1275.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/ieee1275/ofnet.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/sparc64/ieee1275/ieee1275.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/terminfo.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/extcmd.h From 09375846b9ea73269302e97affc85dbb3a43f1b8 Mon Sep 17 00:00:00 2001 From: Manoel Rebelo Abranches Date: Fri, 1 Apr 2011 05:41:37 -0300 Subject: [PATCH 384/869] Add mtu to ieee1275 driver data. --- include/grub/ieee1275/ieee1275.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/include/grub/ieee1275/ieee1275.h b/include/grub/ieee1275/ieee1275.h index 94a69d73d..87294610d 100644 --- a/include/grub/ieee1275/ieee1275.h +++ b/include/grub/ieee1275/ieee1275.h @@ -68,6 +68,7 @@ struct grub_ofnetcard_data { char *path; grub_ieee1275_ihandle_t handle; + grub_uint32_t mtu; }; /* Maps a device alias to a pathname. */ @@ -201,8 +202,6 @@ int EXPORT_FUNC(grub_ieee1275_devices_iterate) (int (*hook) (struct grub_ieee1275_devalias * alias)); char *EXPORT_FUNC(grub_ieee1275_get_aliasdevname) (const char *path); -void EXPORT_FUNC(grub_ofnet_findcards) (void); -void EXPORT_FUNC(grub_ofnet_probecards) (void); char *EXPORT_FUNC(grub_ieee1275_canonicalise_devname) (const char *path); #endif /* ! GRUB_IEEE1275_HEADER */ From 25f1579b4348935084a7f349b1ee6c345fe83d39 Mon Sep 17 00:00:00 2001 From: Manoel Rebelo Abranches Date: Fri, 1 Apr 2011 05:42:34 -0300 Subject: [PATCH 385/869] Adapt protocols to new network struct. --- Makefile.util.def | 1 + grub-core/kern/file.c | 29 ++++++- grub-core/kern/fs.c | 2 +- grub-core/net/arp.c | 100 ++++++++++++------------ grub-core/net/ethernet.c | 18 ++--- grub-core/net/i386/pc/pxe.c | 2 +- grub-core/net/ip.c | 36 +++++---- grub-core/net/tftp.c | 151 ++++++++++++++++++------------------ include/grub/net.h | 125 ++++++++++++++++++++++------- include/grub/net/arp.h | 3 +- include/grub/net/device.h | 7 -- include/grub/net/ethernet.h | 4 +- include/grub/net/ip.h | 2 +- include/grub/net/tftp.h | 12 ++- include/grub/net/udp.h | 12 +-- 15 files changed, 296 insertions(+), 208 deletions(-) diff --git a/Makefile.util.def b/Makefile.util.def index 579fd0714..0f7643b58 100644 --- a/Makefile.util.def +++ b/Makefile.util.def @@ -37,6 +37,7 @@ library = { common = grub-core/commands/extcmd.c; common = grub-core/commands/ls.c; common = grub-core/net/net.c; + common = grub-core/net/netbuff.c; common = grub-core/disk/dmraid_nvidia.c; common = grub-core/disk/loopback.c; common = grub-core/disk/lvm.c; diff --git a/grub-core/kern/file.c b/grub-core/kern/file.c index c93fbf737..85ba8536c 100644 --- a/grub-core/kern/file.c +++ b/grub-core/kern/file.c @@ -20,10 +20,15 @@ #include #include #include +#include #include #include #include +grub_ssize_t (*grub_file_net_read) (grub_file_t file, void *buf, grub_size_t len) = NULL; +grub_err_t (*grub_file_net_open) (struct grub_file *file, const char *name) = NULL; +grub_err_t (*grub_file_net_seek) (struct grub_file *file, grub_off_t offset) = NULL; + grub_file_filter_t grub_file_filters_all[GRUB_FILE_FILTER_MAX]; grub_file_filter_t grub_file_filters_enabled[GRUB_FILE_FILTER_MAX]; @@ -85,6 +90,13 @@ grub_file_open (const char *name) file->device = device; + if (device->net && grub_file_net_open) + { + if (grub_file_net_open (file, file_name)) + goto fail; + return file; + } + if (device->disk && file_name[0] != '/') /* This is a block list. */ file->fs = &grub_fs_blocklist; @@ -130,7 +142,7 @@ grub_file_open (const char *name) grub_ssize_t grub_file_read (grub_file_t file, void *buf, grub_size_t len) { - grub_ssize_t res; + grub_ssize_t res = 0; if (file->offset > file->size) { @@ -148,8 +160,12 @@ grub_file_read (grub_file_t file, void *buf, grub_size_t len) if (len == 0) return 0; - - res = (file->fs->read) (file, buf, len); + if (file->device->disk) + res = (file->fs->read) (file, buf, len); + else + if (grub_file_net_read && file->device->net) + res = grub_file_net_read (file, buf, len); + if (res > 0) file->offset += res; @@ -159,6 +175,9 @@ grub_file_read (grub_file_t file, void *buf, grub_size_t len) grub_err_t grub_file_close (grub_file_t file) { + if (file->device->net) + return grub_errno; + if (file->fs->close) (file->fs->close) (file); @@ -179,8 +198,12 @@ grub_file_seek (grub_file_t file, grub_off_t offset) "attempt to seek outside of the file"); return -1; } + + if (file->device->net && grub_file_net_seek) + grub_file_net_seek (file, offset); old = file->offset; file->offset = offset; + return old; } diff --git a/grub-core/kern/fs.c b/grub-core/kern/fs.c index c4d6efa96..7166648be 100644 --- a/grub-core/kern/fs.c +++ b/grub-core/kern/fs.c @@ -95,7 +95,7 @@ grub_fs_probe (grub_device_t device) } } else if (device->net) - return device->net->protocol; + return NULL; grub_error (GRUB_ERR_UNKNOWN_FS, "unknown filesystem"); return 0; diff --git a/grub-core/net/arp.c b/grub-core/net/arp.c index c7b5d0573..8778a6e51 100644 --- a/grub-core/net/arp.c +++ b/grub-core/net/arp.c @@ -35,36 +35,40 @@ grub_net_arp_resolve(struct grub_net_network_level_interface *inf, grub_net_link_level_address_t *hw_addr) { struct arp_entry *entry; - struct grub_net_buff *nb; + struct grub_net_buff nb; struct arphdr *arp_header; grub_net_link_level_address_t target_hw_addr; - grub_uint8_t *aux, i; + char *aux, arp_data[128]; + int i; - /* Check cache table */ + /* Check cache table. */ entry = arp_find_entry (proto_addr); if (entry) { *hw_addr = entry->ll_address; return GRUB_ERR_NONE; } - /* Build a request packet */ - nb = grub_netbuff_alloc (2048); - if (!nb) - return grub_errno; - grub_netbuff_reserve(nb, 2048); - grub_netbuff_push(nb, sizeof(*arp_header) + 2 * (6 + 6)); - arp_header = (struct arphdr *)nb->data; + /* Build a request packet. */ + nb.head = arp_data; + nb.end = arp_data + sizeof (arp_data); + grub_netbuff_clear (&nb); + + grub_netbuff_reserve (&nb,128); + grub_netbuff_push (&nb, sizeof(*arp_header) + 2 * (6 + 4)); + arp_header = (struct arphdr *) nb.data; arp_header->hrd = grub_cpu_to_be16 (GRUB_NET_ARPHRD_ETHERNET); arp_header->pro = grub_cpu_to_be16 (GRUB_NET_ETHERTYPE_IP); + /* FIXME Add support to ipv6 address. */ arp_header->hln = 6; arp_header->pln = 4; arp_header->op = grub_cpu_to_be16 (ARP_REQUEST); - aux = (grub_uint8_t *)arp_header + sizeof(*arp_header); - /* Sender hardware address */ - grub_memcpy(aux, &inf->hwaddress.mac, 6); + aux = (char *) arp_header + sizeof (*arp_header); + /* Sender hardware address. */ + grub_memcpy (aux, &inf->hwaddress.mac, 6); + aux += 6; /* Sender protocol address */ - grub_memcpy(aux, &inf->address.ipv4, 4); + grub_memcpy (aux, &inf->address.ipv4, 4); aux += 4; /* Target hardware address */ for(i = 0; i < 6; i++) @@ -72,49 +76,40 @@ grub_net_arp_resolve(struct grub_net_network_level_interface *inf, aux += 6; /* Target protocol address */ grub_memcpy(aux, &proto_addr->ipv4, 4); - grub_memset (&target_hw_addr.mac, 0xff, 6); - send_ethernet_packet (inf, nb, target_hw_addr, GRUB_NET_ETHERTYPE_ARP); - grub_netbuff_clear(nb); - grub_netbuff_reserve(nb, 2048); - - grub_uint64_t start_time, current_time; - start_time = grub_get_time_ms(); - do + send_ethernet_packet (inf, &nb, target_hw_addr, GRUB_NET_ETHERTYPE_ARP); + for (i = 0; i < 3; i++) { - grub_net_recv_ethernet_packet (inf, nb, GRUB_NET_ETHERTYPE_ARP); - /* Now check cache table again */ - entry = arp_find_entry(proto_addr); + entry = arp_find_entry (proto_addr); if (entry) - { - grub_memcpy(hw_addr, &entry->ll_address, sizeof (*hw_addr)); - grub_netbuff_clear(nb); - return GRUB_ERR_NONE; - } - current_time = grub_get_time_ms(); - if (current_time - start_time > 3000) - break; - } while (! entry); - grub_netbuff_clear(nb); + { + grub_memcpy (hw_addr, &entry->ll_address, sizeof (*hw_addr)); + return GRUB_ERR_NONE; + } + grub_net_pool_cards (200); + + } + return grub_error (GRUB_ERR_TIMEOUT, "Timeout: could not resolve hardware address."); } grub_err_t -grub_net_arp_receive (struct grub_net_network_level_interface *inf, - struct grub_net_buff *nb) +grub_net_arp_receive (struct grub_net_buff *nb) { struct arphdr *arp_header = (struct arphdr *)nb->data; struct arp_entry *entry; grub_uint8_t *sender_hardware_address, *sender_protocol_address; grub_uint8_t *target_hardware_address, *target_protocol_address; grub_net_network_level_address_t hwaddress; + struct grub_net_network_level_interface *inf; sender_hardware_address = (grub_uint8_t *) arp_header + sizeof(*arp_header); sender_protocol_address = sender_hardware_address + arp_header->hln; target_hardware_address = sender_protocol_address + arp_header->pln; target_protocol_address = target_hardware_address + arp_header->hln; grub_memcpy (&hwaddress.ipv4, sender_protocol_address, 4); + /* Check if the sender is in the cache table */ entry = arp_find_entry(&hwaddress); /* Update sender hardware address */ @@ -134,21 +129,24 @@ grub_net_arp_receive (struct grub_net_network_level_interface *inf, new_table_entry = 0; } - /* Am I the protocol address target? */ - if (grub_memcmp(target_protocol_address, inf->hwaddress.mac, 6) == 0 - && grub_be_to_cpu16 (arp_header->op) == ARP_REQUEST) + FOR_NET_NETWORK_LEVEL_INTERFACES(inf) { - grub_net_link_level_address_t aux; - /* Swap hardware fields */ - grub_memcpy(target_hardware_address, sender_hardware_address, arp_header->hln); - grub_memcpy(sender_hardware_address, inf->hwaddress.mac, 6); - grub_memcpy(aux.mac, sender_protocol_address, 6); - grub_memcpy(sender_protocol_address, target_protocol_address, arp_header->pln); - grub_memcpy(target_protocol_address, aux.mac, arp_header->pln); - /* Change operation to REPLY and send packet */ - arp_header->op = grub_be_to_cpu16 (ARP_REPLY); - grub_memcpy (aux.mac, target_hardware_address, 6); - send_ethernet_packet (inf, nb, aux, GRUB_NET_ETHERTYPE_ARP); + /* Am I the protocol address target? */ + if (grub_memcmp (target_protocol_address, &inf->address.ipv4, 6) == 0 + && grub_be_to_cpu16 (arp_header->op) == ARP_REQUEST) + { + grub_net_link_level_address_t aux; + /* Swap hardware fields */ + grub_memcpy (target_hardware_address, sender_hardware_address, arp_header->hln); + grub_memcpy (sender_hardware_address, inf->hwaddress.mac, 6); + grub_memcpy (aux.mac, sender_protocol_address, 6); + grub_memcpy (sender_protocol_address, target_protocol_address, arp_header->pln); + grub_memcpy (target_protocol_address, aux.mac, arp_header->pln); + /* Change operation to REPLY and send packet */ + arp_header->op = grub_be_to_cpu16 (ARP_REPLY); + grub_memcpy (aux.mac, target_hardware_address, 6); + send_ethernet_packet (inf, nb, aux, GRUB_NET_ETHERTYPE_ARP); + } } return GRUB_ERR_NONE; } diff --git a/grub-core/net/ethernet.c b/grub-core/net/ethernet.c index cbda4c875..c96a65602 100644 --- a/grub-core/net/ethernet.c +++ b/grub-core/net/ethernet.c @@ -23,23 +23,20 @@ send_ethernet_packet (struct grub_net_network_level_interface *inf, eth->type = grub_cpu_to_be16 (ethertype); - return inf->card->driver->send (inf->card,nb); + return inf->card->driver->send (inf->card, nb); } grub_err_t -grub_net_recv_ethernet_packet (struct grub_net_network_level_interface *inf, - struct grub_net_buff *nb, - grub_uint16_t ethertype) +grub_net_recv_ethernet_packet (struct grub_net_buff *nb) { struct etherhdr *eth; struct llchdr *llch; struct snaphdr *snaph; grub_uint16_t type; - inf->card->driver->recv (inf->card, nb); eth = (struct etherhdr *) nb->data; type = grub_be_to_cpu16 (eth->type); - grub_netbuff_pull(nb,sizeof (*eth)); + grub_netbuff_pull (nb, sizeof (*eth)); if (type <= 1500) { @@ -56,10 +53,13 @@ grub_net_recv_ethernet_packet (struct grub_net_network_level_interface *inf, /* ARP packet */ if (type == GRUB_NET_ETHERTYPE_ARP) - grub_net_arp_receive(inf, nb); + { + grub_net_arp_receive (nb); + grub_netbuff_free (nb); + } /* IP packet */ - if(type == GRUB_NET_ETHERTYPE_IP && ethertype == GRUB_NET_ETHERTYPE_IP) - return GRUB_ERR_NONE; + if (type == GRUB_NET_ETHERTYPE_IP) + grub_net_recv_ip_packets (nb); return GRUB_ERR_NONE; } diff --git a/grub-core/net/i386/pc/pxe.c b/grub-core/net/i386/pc/pxe.c index c07aa78f9..8e7f75ed8 100644 --- a/grub-core/net/i386/pc/pxe.c +++ b/grub-core/net/i386/pc/pxe.c @@ -292,7 +292,7 @@ grub_pxefs_label (grub_device_t device __attribute ((unused)), return GRUB_ERR_NONE; } -static struct grub_fs grub_pxefs_fs = +static struct grub_net_app_protocol grub_pxefs_fs = { .name = "pxe", .dir = grub_pxefs_dir, diff --git a/grub-core/net/ip.c b/grub-core/net/ip.c index 9a96ef532..d6684c29e 100644 --- a/grub-core/net/ip.c +++ b/grub-core/net/ip.c @@ -1,6 +1,7 @@ #include #include #include +#include #include #include #include @@ -33,7 +34,7 @@ grub_net_send_ip_packet (struct grub_net_network_level_interface *inf, grub_net_link_level_address_t ll_target_addr; grub_err_t err; - grub_netbuff_push(nb,sizeof(*iph)); + grub_netbuff_push (nb, sizeof(*iph)); iph = (struct iphdr *) nb->data; iph->verhdrlen = ((4 << 4) | 5); @@ -49,17 +50,15 @@ grub_net_send_ip_packet (struct grub_net_network_level_interface *inf, iph->chksum = 0 ; iph->chksum = ipchksum((void *)nb->data, sizeof(*iph)); - /* Determine link layer target address via ARP */ - err = grub_net_arp_resolve(inf, target, &ll_target_addr); + /* Determine link layer target address via ARP. */ + err = grub_net_arp_resolve (inf, target, &ll_target_addr); if (err) return err; - return send_ethernet_packet (inf, nb, ll_target_addr, GRUB_NET_ETHERTYPE_IP); } - +/* static int -ip_filter (struct grub_net_buff *nb, - struct grub_net_network_level_interface *inf) +ip_filter (struct grub_net_buff *nb) { struct iphdr *iph = (struct iphdr *) nb->data; grub_err_t err; @@ -80,15 +79,22 @@ ip_filter (struct grub_net_buff *nb, } return 1; } - +*/ grub_err_t -grub_net_recv_ip_packets (struct grub_net_network_level_interface *inf) +grub_net_recv_ip_packets (struct grub_net_buff *nb) { - struct grub_net_buff *nb; - nb = grub_netbuff_alloc (2048); - if (!nb) - return grub_errno; - grub_net_recv_ethernet_packet (inf, nb, GRUB_NET_ETHERTYPE_IP); - ip_filter (nb, inf); + struct iphdr *iph = (struct iphdr *) nb->data; + grub_netbuff_pull (nb, sizeof (*iph)); + + switch (iph->protocol) + { + case IP_UDP: + return grub_net_recv_udp_packet (nb); + break; + default: + grub_netbuff_free (nb); + break; + } + return GRUB_ERR_NONE; } diff --git a/grub-core/net/tftp.c b/grub-core/net/tftp.c index 16b60eeb6..cafb30585 100644 --- a/grub-core/net/tftp.c +++ b/grub-core/net/tftp.c @@ -14,26 +14,23 @@ tftp_open (struct grub_file *file, const char *filename) { struct tftphdr *tftph; char *rrq; - char *ptr; + int i; int rrqlen; - int hdrlen; - struct grub_net_buff *nb; - grub_net_network_level_address_t addr; + int hdrlen; + char open_data[1500]; + struct grub_net_buff nb; + tftp_data_t data = grub_malloc (sizeof *data); grub_err_t err; + + file->device->net->socket->data = (void *) data; + nb.head = open_data; + nb.end = open_data + sizeof (open_data); + grub_netbuff_clear (&nb); - err = grub_net_resolve_address (file->device->net->name - + sizeof ("tftp,") - 1, &addr); - if (err) - return err; + grub_netbuff_reserve (&nb,1500); + grub_netbuff_push (&nb,sizeof (*tftph)); - nb = grub_netbuff_alloc (2048); - if (!nb) - return grub_errno; - - grub_netbuff_reserve (nb,2048); - grub_netbuff_push (nb,sizeof (*tftph)); - - tftph = (struct tftphdr *) nb->data; + tftph = (struct tftphdr *) nb.data; rrq = (char *) tftph->u.rrq; rrqlen = 0; @@ -64,89 +61,93 @@ tftp_open (struct grub_file *file, const char *filename) rrq += grub_strlen ("0") + 1; hdrlen = sizeof (tftph->opcode) + rrqlen; - grub_netbuff_unput (nb,nb->tail - (nb->data+hdrlen)); + grub_netbuff_unput (&nb, nb.tail - (nb.data + hdrlen)); - err = grub_net_send_udp_packet (&addr, - nb, TFTP_CLIENT_PORT, TFTP_SERVER_PORT); + file->device->net->socket->out_port = TFTP_SERVER_PORT; + + err = grub_net_send_udp_packet (file->device->net->socket, &nb); if (err) return err; - /* Receive OACK. */ - grub_netbuff_clear (nb); - grub_netbuff_reserve (nb,2048); - - do + /* Receive OACK packet. */ + for ( i = 0; i < 3; i++) { - err = grub_net_recv_udp_packet (&addr, nb, - TFTP_CLIENT_PORT, TFTP_SERVER_PORT); - if (err) - return err; + grub_net_pool_cards (100); + if (grub_errno) + return grub_errno; + if (file->device->net->socket->status != 0) + break; + /* Retry. */ + //err = grub_net_send_udp_packet (file->device->net->socket, &nb); + // if (err) + // return err; } - while (nb->tail == nb->data); - file->size = 0; + if (file->device->net->socket->status == 0) + return grub_error (GRUB_ERR_TIMEOUT,"Time out opening tftp."); + file->size = data->file_size; - for (ptr = nb->data; ptr < nb->tail; ) - grub_printf ("%02x ", *ptr); - - for (ptr = nb->data; ptr < nb->tail; ) - { - if (grub_memcmp (ptr, "tsize\0=", sizeof ("tsize\0=") - 1) == 0) - { - file->size = grub_strtoul (ptr + sizeof ("tsize\0=") - 1, 0, 0); - grub_errno = GRUB_ERR_NONE; - } - while (ptr < nb->tail && *ptr) - ptr++; - ptr++; - } return GRUB_ERR_NONE; } -static grub_ssize_t -tftp_receive (struct grub_file *file, char *buf, grub_size_t len) +static grub_err_t +tftp_receive (grub_net_socket_t sock, struct grub_net_buff *nb) { struct tftphdr *tftph; - // char *token,*value,*temp; + char nbdata[128]; + tftp_data_t data = sock->data; grub_err_t err; - grub_net_network_level_address_t addr; - struct grub_net_buff nb; + char *ptr; + struct grub_net_buff nb_ack; - err = grub_net_resolve_address (file->device->net->name - + sizeof ("tftp,") - 1, &addr); - if (err) - return err; + nb_ack.head = nbdata; + nb_ack.end = nbdata + sizeof (nbdata); - grub_net_recv_udp_packet (&addr, &nb, - TFTP_CLIENT_PORT, TFTP_SERVER_PORT); - - tftph = (struct tftphdr *) nb.data; + + tftph = (struct tftphdr *) nb->data; switch (grub_be_to_cpu16 (tftph->opcode)) { + case TFTP_OACK: + for (ptr = nb->data; ptr < nb->tail; ) + { + if (grub_memcmp (ptr, "tsize\0", sizeof ("tsize\0") - 1) == 0) + data->file_size = grub_strtoul (ptr + sizeof ("tsize\0") - 1, 0, 0); + while (ptr < nb->tail && *ptr) + ptr++; + ptr++; + } + sock->status = 1; + data->block = 0; + grub_netbuff_clear(nb); + break; case TFTP_DATA: - grub_netbuff_pull (&nb,sizeof (tftph->opcode) + sizeof (tftph->u.data.block)); - // if (tftph->u.data.block == block + 1) - //{ - // block = tftph->u.data.block; - grub_memcpy (buf, nb.data, len); - //} - //else - //grub_netbuff_clear(&nb); - break; + grub_netbuff_pull (nb,sizeof (tftph->opcode) + sizeof (tftph->u.data.block)); + + if (grub_be_to_cpu16 (tftph->u.data.block) == data->block + 1) + { + data->block++; + if (nb->tail - nb->data < 1024) + sock->status = 2; + } + else + grub_netbuff_clear(nb); + + break; case TFTP_ERROR: - grub_netbuff_clear (&nb); + grub_netbuff_clear (nb); return grub_error (GRUB_ERR_IO, (char *)tftph->u.err.errmsg); + break; } + grub_netbuff_clear (&nb_ack); + grub_netbuff_reserve (&nb_ack,128); + grub_netbuff_push (&nb_ack,sizeof (tftph->opcode) + sizeof (tftph->u.ack.block)); - nb.data = nb.tail = nb.end; - - grub_netbuff_push (&nb,sizeof (tftph->opcode) + sizeof (tftph->u.ack.block)); - - tftph = (struct tftphdr *) nb.data; + tftph = (struct tftphdr *) nb_ack.data; tftph->opcode = grub_cpu_to_be16 (TFTP_ACK); - // tftph->u.ack.block = block; + tftph->u.ack.block = data->block; - return grub_net_send_udp_packet (&addr, &nb, TFTP_CLIENT_PORT, TFTP_SERVER_PORT); + err = grub_net_send_udp_packet (sock, &nb_ack); + return err; } static grub_err_t @@ -155,7 +156,7 @@ tftp_close (struct grub_file *file __attribute__ ((unused))) return 0; } -static struct grub_fs grub_tftp_protocol = +static struct grub_net_app_protocol grub_tftp_protocol = { .name = "tftp", .open = tftp_open, diff --git a/include/grub/net.h b/include/grub/net.h index 20bf3c0e6..37b258f36 100644 --- a/include/grub/net.h +++ b/include/grub/net.h @@ -23,19 +23,10 @@ #include #include #include +#include #include #include -typedef struct grub_fs *grub_net_app_level_t; - -typedef struct grub_net -{ - char *name; - grub_net_app_level_t protocol; -} *grub_net_t; - -extern grub_net_t (*EXPORT_VAR (grub_net_open)) (const char *name); - typedef enum grub_link_level_protocol_id { GRUB_NET_LINK_LEVEL_PROTOCOL_ETHERNET @@ -75,6 +66,37 @@ struct grub_net_card_driver grub_size_t (*recv) (struct grub_net_card *dev, struct grub_net_buff *buf); }; +extern struct grub_net_card_driver *grub_net_card_drivers; + +static inline void +grub_net_card_driver_register (struct grub_net_card_driver *driver) +{ + grub_list_push (GRUB_AS_LIST_P (&grub_net_card_drivers), + GRUB_AS_LIST (driver)); +} + +static inline void +grub_net_card_driver_unregister (struct grub_net_card_driver *driver) +{ + grub_list_remove (GRUB_AS_LIST_P (&grub_net_card_drivers), + GRUB_AS_LIST (driver)); +} + +#define FOR_NET_CARD_DRIVERS(var) for (var = grub_net_card_drivers; var; var = var->next) + +typedef struct grub_net_packet +{ + struct grub_net_packet *next; + struct grub_net_packet *prev; + struct grub_net_packets *up; + struct grub_net_buff *nb; +} grub_net_packet_t; + +typedef struct grub_net_packets +{ + grub_net_packet_t *first; + grub_net_packet_t *last; +} grub_net_packets_t; struct grub_net_card { @@ -118,20 +140,6 @@ typedef struct grub_net_network_level_netaddress }; } grub_net_network_level_netaddress_t; -typedef struct grub_net_packet -{ - struct grub_net_packet *next; - struct grub_net_packet *prev; - struct grub_net_packets *up; - struct grub_net_buff *nb; -} grub_net_packet_t; - -typedef struct grub_net_packets -{ - struct grub_net_packet *first; - struct grub_net_packet *last; -} grub_net_packets_t; - #define FOR_PACKETS(cont,var) for (var = (cont).first; var; var = var->next) static inline grub_err_t @@ -172,6 +180,66 @@ grub_net_remove_packet (grub_net_packet_t *pkt) pkt->up->last = pkt->prev; } +typedef struct grub_net_app_protocol *grub_net_app_level_t; + +typedef struct grub_net_socket *grub_net_socket_t; + +struct grub_net_app_protocol +{ + struct grub_net_app_protocol *next; + char *name; + grub_err_t (*dir) (grub_device_t device, const char *path, + int (*hook) (const char *filename, + const struct grub_dirhook_info *info)); + grub_err_t (*open) (struct grub_file *file, const char *filename); + grub_err_t (*read) (grub_net_socket_t sock, struct grub_net_buff *nb); + grub_err_t (*close) (struct grub_file *file); + grub_err_t (*label) (grub_device_t device, char **label); +}; + +struct grub_net_socket +{ + struct grub_net_socket *next; + int status; + int in_port; + int out_port; + grub_net_app_level_t app; + grub_net_network_level_address_t out_nla; + struct grub_net_network_level_interface *inf; + grub_net_packets_t *packs; + void *data; +}; + +extern struct grub_net_socket *grub_net_sockets; + +static inline void +grub_net_socket_register (grub_net_socket_t socket) +{ + grub_list_push (GRUB_AS_LIST_P (&grub_net_sockets), + GRUB_AS_LIST (socket)); +} + +static inline void +grub_net_socket_unregister (grub_net_socket_t socket) +{ + grub_list_remove (GRUB_AS_LIST_P (&grub_net_sockets), + GRUB_AS_LIST (socket)); +} + +#define FOR_NET_SOCKETS(var) for (var = grub_net_sockets; var; var = var->next) + +typedef struct grub_net +{ + char *name; + grub_net_app_level_t protocol; + grub_net_socket_t socket; +} *grub_net_t; + +extern grub_net_t (*EXPORT_VAR (grub_net_open)) (const char *name); +extern grub_ssize_t (*EXPORT_VAR (grub_file_net_read)) (grub_file_t file, void *buf, grub_size_t len); +extern grub_err_t (*EXPORT_VAR (grub_file_net_open)) (struct grub_file *file, const char *name); +extern grub_err_t (*EXPORT_VAR (grub_file_net_seek)) (struct grub_file *file, grub_off_t offset); + struct grub_net_network_level_interface { struct grub_net_network_level_interface *next; @@ -182,7 +250,6 @@ struct grub_net_network_level_interface grub_net_interface_flags_t flags; struct grub_net_bootp_ack *dhcp_ack; grub_size_t dhcp_acklen; - grub_net_packets_t nl_pending; void *data; }; @@ -354,7 +421,7 @@ grub_err_t grub_net_recv_link_layer (struct grub_net_network_level_interface *in grub_net_packet_handler_t handler); grub_err_t -grub_net_recv_ip_packets (struct grub_net_network_level_interface *inf); +grub_net_recv_ip_packets (struct grub_net_buff *nb); grub_err_t grub_net_send_ip_packet (struct grub_net_network_level_interface *inf, @@ -363,4 +430,10 @@ grub_net_send_ip_packet (struct grub_net_network_level_interface *inf, #define FOR_NET_NL_PACKETS(inf, var) FOR_PACKETS(inf->nl_pending, var) +void +grub_net_pool_cards (unsigned time); + +void +hwaddr_to_str (const grub_net_link_level_address_t *addr, char *str); + #endif /* ! GRUB_NET_HEADER */ diff --git a/include/grub/net/arp.h b/include/grub/net/arp.h index 691fda307..c60ea333f 100644 --- a/include/grub/net/arp.h +++ b/include/grub/net/arp.h @@ -27,8 +27,7 @@ struct arphdr { grub_uint16_t op; } __attribute__ ((packed)); -extern grub_err_t grub_net_arp_receive(struct grub_net_network_level_interface *inf, - struct grub_net_buff *nb); +extern grub_err_t grub_net_arp_receive(struct grub_net_buff *nb); extern grub_err_t grub_net_arp_resolve(struct grub_net_network_level_interface *inf, const grub_net_network_level_address_t *addr, diff --git a/include/grub/net/device.h b/include/grub/net/device.h index 9f1b9bf1d..e69de29bb 100644 --- a/include/grub/net/device.h +++ b/include/grub/net/device.h @@ -1,7 +0,0 @@ -struct grub_net_card -{ - struct grub_net_card *next; - char *name; - struct grub_net_card_driver *driver; - void *data; -}; diff --git a/include/grub/net/ethernet.h b/include/grub/net/ethernet.h index 7a0235be6..7ff7a4562 100644 --- a/include/grub/net/ethernet.h +++ b/include/grub/net/ethernet.h @@ -52,8 +52,6 @@ send_ethernet_packet (struct grub_net_network_level_interface *inf, grub_net_link_level_address_t target_addr, grub_uint16_t ethertype); grub_err_t -grub_net_recv_ethernet_packet (struct grub_net_network_level_interface *inf, - struct grub_net_buff *nb, - grub_uint16_t ethertype); +grub_net_recv_ethernet_packet (struct grub_net_buff *nb); #endif diff --git a/include/grub/net/ip.h b/include/grub/net/ip.h index 6f748bbf3..cb8481a7d 100644 --- a/include/grub/net/ip.h +++ b/include/grub/net/ip.h @@ -26,7 +26,7 @@ struct ip6hdr grub_uint8_t daddr[16]; } __attribute__ ((packed)); -#define IP_UDP 17 /* UDP protocol */ +#define IP_UDP 0x11 /* UDP protocol */ #define IP_BROADCAST 0xFFFFFFFF grub_uint16_t ipchksum(void *ipv, int len); diff --git a/include/grub/net/tftp.h b/include/grub/net/tftp.h index 1f1c48616..c67380817 100644 --- a/include/grub/net/tftp.h +++ b/include/grub/net/tftp.h @@ -14,7 +14,6 @@ /* IP port for the TFTP server */ #define TFTP_SERVER_PORT 69 -#define TFTP_CLIENT_PORT 26300 /* We define these based on what's in arpa/tftp.h. We just like our @@ -40,10 +39,17 @@ #define TFTP_EBADID 5 /* unknown transfer ID */ #define TFTP_EEXISTS 6 /* file already exists */ #define TFTP_ENOUSER 7 /* no such user */ -#define TFTP_DEFAULT_FILENAME "kernel" /* * own here because this is cleaner, and maps to the same data layout. * */ + +typedef struct tftp_data + { + int file_size; + int block; + } *tftp_data_t; + + struct tftphdr { grub_uint16_t opcode; union { @@ -65,6 +71,4 @@ struct tftphdr { } u; } __attribute__ ((packed)) ; -void tftp_ini(void); -void tftp_fini(void); #endif diff --git a/include/grub/net/udp.h b/include/grub/net/udp.h index f1992467d..86311ccf1 100644 --- a/include/grub/net/udp.h +++ b/include/grub/net/udp.h @@ -12,20 +12,12 @@ struct udphdr } __attribute__ ((packed)); grub_err_t -grub_net_send_udp_packet (const grub_net_network_level_address_t *target, - struct grub_net_buff *nb, grub_uint16_t srcport, - grub_uint16_t destport); - +grub_net_send_udp_packet (const grub_net_socket_t socket , struct grub_net_buff *nb); grub_err_t -grub_net_recv_udp_packets (struct grub_net_network_level_interface *inf); +grub_net_recv_udp_packet (struct grub_net_buff *nb); -grub_err_t -grub_net_recv_udp_packet (const grub_net_network_level_address_t *target, - struct grub_net_buff *buf, - grub_uint16_t srcport, grub_uint16_t destport); #define FOR_NET_UDP_PACKETS(inf, var) FOR_PACKETS(inf->udp_pending, var) - #endif From 05d2ed3277a7c7057b77b2e62bda9d0ed8c6ef13 Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Fri, 1 Apr 2011 11:43:51 +0100 Subject: [PATCH 386/869] * grub-core/normal/menu_entry.c (run): Quieten uninitialised warning. (This was in fact always initialised before use, but GCC wasn't smart enough to prove that.) * grub-core/script/lexer.c (grub_script_lexer_yywrap): Likewise. --- ChangeLog | 7 +++++++ grub-core/normal/menu_entry.c | 2 +- grub-core/script/lexer.c | 2 +- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 847d04b03..21fd6b68b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2011-04-01 Colin Watson + + * grub-core/normal/menu_entry.c (run): Quieten uninitialised + warning. (This was in fact always initialised before use, but GCC + wasn't smart enough to prove that.) + * grub-core/script/lexer.c (grub_script_lexer_yywrap): Likewise. + 2011-03-31 Vladimir Serbinenko * grub-core/kern/x86_64/efi/callwrap.S (efi_wrap_0): Preserve 16-byte diff --git a/grub-core/normal/menu_entry.c b/grub-core/normal/menu_entry.c index 94f6e7f32..a675ff005 100644 --- a/grub-core/normal/menu_entry.c +++ b/grub-core/normal/menu_entry.c @@ -1165,7 +1165,7 @@ run (struct screen *screen) { char *script; int errs_before; - grub_menu_t menu; + grub_menu_t menu = NULL; char *dummy[1] = { NULL }; auto char * editor_getsource (void); diff --git a/grub-core/script/lexer.c b/grub-core/script/lexer.c index 909b515fa..98279079f 100644 --- a/grub-core/script/lexer.c +++ b/grub-core/script/lexer.c @@ -126,7 +126,7 @@ int grub_script_lexer_yywrap (struct grub_parser_param *parserstate, const char *input) { - int len; + int len = 0; char *p = 0; char *line = 0; YY_BUFFER_STATE buffer; From cfed2ad09766fb9243afe4c6ec4c4d782c75ecef Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 1 Apr 2011 15:53:06 +0200 Subject: [PATCH 387/869] Fix incorrect types in jfs.c. This enables >2TiB disks and fixes some memory corruptions. * grub-core/fs/jfs.c (struct grub_jfs_diropen): Interpret bytes as unsigned. (grub_jfs_lookup_symlink): Make ino a grub_uint32_t rather than int. (grub_jfs_blkno): Use 64-bit quantities for block sectors. (grub_jfs_read_inode): Likewise. (grub_jfs_opendir): Likewise. Remove now useless casts. (grub_jfs_getent): Likewise. Make ino a grub_uint32_t rather than int. (grub_jfs_mount): Ensure that blksize and log2_blksize are consistent. (grub_jfs_read_file): Use 64-bit quantities when necessary. Replace division and module with bit operations. (grub_jfs_find_file): Make ino a grub_uint32_t. (grub_jfs_lookup_symlink): Likewise. Use 64-bit quantities --- ChangeLog | 19 +++++++++++++ grub-core/fs/jfs.c | 69 +++++++++++++++++++++++++--------------------- 2 files changed, 57 insertions(+), 31 deletions(-) diff --git a/ChangeLog b/ChangeLog index 21fd6b68b..044be9d5c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,22 @@ +2011-04-01 Vladimir Serbinenko + + Fix incorrect types in jfs.c. This enables >2TiB disks and fixes some + memory corruptions. + + * grub-core/fs/jfs.c (struct grub_jfs_diropen): Interpret bytes as + unsigned. + (grub_jfs_lookup_symlink): Make ino a grub_uint32_t rather than int. + (grub_jfs_blkno): Use 64-bit quantities for block sectors. + (grub_jfs_read_inode): Likewise. + (grub_jfs_opendir): Likewise. Remove now useless casts. + (grub_jfs_getent): Likewise. + Make ino a grub_uint32_t rather than int. + (grub_jfs_mount): Ensure that blksize and log2_blksize are consistent. + (grub_jfs_read_file): Use 64-bit quantities when necessary. Replace + division and module with bit operations. + (grub_jfs_find_file): Make ino a grub_uint32_t. + (grub_jfs_lookup_symlink): Likewise. Use 64-bit quantities + 2011-04-01 Colin Watson * grub-core/normal/menu_entry.c (run): Quieten uninitialised diff --git a/grub-core/fs/jfs.c b/grub-core/fs/jfs.c index 76ef2e540..6857c4a2c 100644 --- a/grub-core/fs/jfs.c +++ b/grub-core/fs/jfs.c @@ -217,12 +217,12 @@ struct grub_jfs_diropen struct grub_jfs_tree_dir header; struct grub_jfs_leaf_dirent dirent[0]; struct grub_jfs_leaf_next_dirent next_dirent[0]; - char sorted[0]; + grub_uint8_t sorted[0]; } *dirpage __attribute__ ((packed)); struct grub_jfs_data *data; struct grub_jfs_inode *inode; int count; - char *sorted; + grub_uint8_t *sorted; struct grub_jfs_leaf_dirent *leaf; struct grub_jfs_leaf_next_dirent *next_leaf; @@ -234,13 +234,13 @@ struct grub_jfs_diropen static grub_dl_t my_mod; -static grub_err_t grub_jfs_lookup_symlink (struct grub_jfs_data *data, int ino); +static grub_err_t grub_jfs_lookup_symlink (struct grub_jfs_data *data, grub_uint32_t ino); /* Get the block number for the block BLK in the node INODE in the mounted filesystem DATA. */ -static int +static grub_int64_t grub_jfs_blkno (struct grub_jfs_data *data, struct grub_jfs_inode *inode, - unsigned int blk) + grub_uint64_t blk) { auto int getblk (struct grub_jfs_treehead *treehead, struct grub_jfs_tree_extent *extents); @@ -294,15 +294,15 @@ grub_jfs_blkno (struct grub_jfs_data *data, struct grub_jfs_inode *inode, static grub_err_t -grub_jfs_read_inode (struct grub_jfs_data *data, int ino, +grub_jfs_read_inode (struct grub_jfs_data *data, grub_uint32_t ino, struct grub_jfs_inode *inode) { struct grub_jfs_iag iag; - int iagnum = ino / 4096; - int inoext = (ino % 4096) / 32; - int inonum = (ino % 4096) % 32; - grub_uint32_t iagblk; - grub_uint32_t inoblk; + grub_uint32_t iagnum = ino / 4096; + unsigned inoext = (ino % 4096) / 32; + unsigned inonum = (ino % 4096) % 32; + grub_uint64_t iagblk; + grub_uint64_t inoblk; iagblk = grub_jfs_blkno (data, &data->fileset, iagnum + 1); if (grub_errno) @@ -348,6 +348,13 @@ grub_jfs_mount (grub_disk_t disk) goto fail; } + if (grub_le_to_cpu32 (data->sblock.blksz) + != (1U << grub_le_to_cpu16 (data->sblock.log2_blksz))) + { + grub_error (GRUB_ERR_BAD_FS, "not a JFS filesystem"); + goto fail; + } + data->disk = disk; data->pos = 0; data->linknest = 0; @@ -374,7 +381,7 @@ grub_jfs_opendir (struct grub_jfs_data *data, struct grub_jfs_inode *inode) { struct grub_jfs_internal_dirent *de; struct grub_jfs_diropen *diro; - int blk; + grub_disk_addr_t blk; de = (struct grub_jfs_internal_dirent *) inode->dir.dirents; @@ -397,7 +404,7 @@ grub_jfs_opendir (struct grub_jfs_data *data, struct grub_jfs_inode *inode) { diro->leaf = inode->dir.dirents; diro->next_leaf = (struct grub_jfs_leaf_next_dirent *) de; - diro->sorted = (char *) (inode->dir.header.sorted); + diro->sorted = inode->dir.header.sorted; diro->count = inode->dir.header.count; return diro; @@ -475,7 +482,7 @@ grub_jfs_getent (struct grub_jfs_diropen *diro) /* The last node, read in more. */ if (diro->index == diro->count) { - unsigned int next; + grub_disk_addr_t next; /* If the inode contains the entry tree or if this was the last node, there is nothing to read. */ @@ -499,7 +506,7 @@ grub_jfs_getent (struct grub_jfs_diropen *diro) diro->index = 0; } - leaf = &diro->leaf[(int) diro->sorted[diro->index]]; + leaf = &diro->leaf[diro->sorted[diro->index]]; next_leaf = &diro->next_leaf[diro->index]; len = leaf->len; @@ -540,21 +547,21 @@ static grub_ssize_t grub_jfs_read_file (struct grub_jfs_data *data, void NESTED_FUNC_ATTR (*read_hook) (grub_disk_addr_t sector, unsigned offset, unsigned length), - int pos, grub_size_t len, char *buf) + grub_uint64_t pos, grub_size_t len, char *buf) { - int i; - int blockcnt; + grub_uint64_t i; + grub_uint64_t blockcnt; - blockcnt = ((len + pos + grub_le_to_cpu32 (data->sblock.blksz) - 1) - / grub_le_to_cpu32 (data->sblock.blksz)); + blockcnt = (len + pos + grub_le_to_cpu32 (data->sblock.blksz) - 1) + >> grub_le_to_cpu16 (data->sblock.log2_blksz); - for (i = pos / grub_le_to_cpu32 (data->sblock.blksz); i < blockcnt; i++) + for (i = pos >> grub_le_to_cpu16 (data->sblock.log2_blksz); i < blockcnt; i++) { - int blknr; - int blockoff = pos % grub_le_to_cpu32 (data->sblock.blksz); - int blockend = grub_le_to_cpu32 (data->sblock.blksz); + grub_disk_addr_t blknr; + grub_uint32_t blockoff = pos & (grub_le_to_cpu32 (data->sblock.blksz) - 1); + grub_uint32_t blockend = grub_le_to_cpu32 (data->sblock.blksz); - int skipfirst = 0; + grub_uint64_t skipfirst = 0; blknr = grub_jfs_blkno (data, &data->currinode, i); if (grub_errno) @@ -563,14 +570,14 @@ grub_jfs_read_file (struct grub_jfs_data *data, /* Last block. */ if (i == blockcnt - 1) { - blockend = (len + pos) % grub_le_to_cpu32 (data->sblock.blksz); + blockend = (len + pos) & (grub_le_to_cpu32 (data->sblock.blksz) - 1); if (!blockend) blockend = grub_le_to_cpu32 (data->sblock.blksz); } /* First block. */ - if (i == (pos / (int) grub_le_to_cpu32 (data->sblock.blksz))) + if (i == (pos >> grub_le_to_cpu16 (data->sblock.log2_blksz))) { skipfirst = blockoff; blockend -= skipfirst; @@ -642,8 +649,8 @@ grub_jfs_find_file (struct grub_jfs_data *data, const char *path) pathname. */ if (!grub_strcmp (name, diro->name)) { - int ino = diro->ino; - int dirino = grub_le_to_cpu32 (data->currinode.inode); + grub_uint32_t ino = diro->ino; + grub_uint32_t dirino = grub_le_to_cpu32 (data->currinode.inode); grub_jfs_closedir (diro); diro = 0; @@ -687,9 +694,9 @@ grub_jfs_find_file (struct grub_jfs_data *data, const char *path) static grub_err_t -grub_jfs_lookup_symlink (struct grub_jfs_data *data, int ino) +grub_jfs_lookup_symlink (struct grub_jfs_data *data, grub_uint32_t ino) { - int size = grub_le_to_cpu64 (data->currinode.size); + grub_uint64_t size = grub_le_to_cpu64 (data->currinode.size); char symlink[size + 1]; if (++data->linknest > GRUB_JFS_MAX_SYMLNK_CNT) From 186ae367af232e0c8faa43abad07085d5787071c Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Fri, 1 Apr 2011 15:35:09 +0100 Subject: [PATCH 388/869] * grub-core/disk/loopback.c (grub_cmd_loopback): Fix a memory leak when replacing an existing device. --- ChangeLog | 5 +++++ grub-core/disk/loopback.c | 4 ---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 044be9d5c..512b61cac 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-04-01 Colin Watson + + * grub-core/disk/loopback.c (grub_cmd_loopback): Fix a memory leak + when replacing an existing device. + 2011-04-01 Vladimir Serbinenko Fix incorrect types in jfs.c. This enables >2TiB disks and fixes some diff --git a/grub-core/disk/loopback.c b/grub-core/disk/loopback.c index b05940a4a..02e6c164f 100644 --- a/grub-core/disk/loopback.c +++ b/grub-core/disk/loopback.c @@ -97,10 +97,6 @@ grub_cmd_loopback (grub_extcmd_context_t ctxt, int argc, char **args) if (newdev) { - char *newname = grub_strdup (args[1]); - if (! newname) - goto fail; - grub_file_close (newdev->file); newdev->file = file; From 2cccc747acc482e710e3dd23c672ce6151fd59e9 Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Fri, 1 Apr 2011 17:04:10 +0100 Subject: [PATCH 389/869] Store the loopback device as data on loopback grub_disk structures, rather than the file it points to. This fixes use of freed memory if an existing loopback device is replaced. * grub-core/disk/loopback.c (grub_loopback_open): Store dev in disk->data, not dev->file. (grub_loopback_read): Adjust file assignment to match. Fixes Ubuntu bug #742967. --- ChangeLog | 11 +++++++++++ grub-core/disk/loopback.c | 4 ++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 512b61cac..fb6875c69 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2011-04-01 Colin Watson + + Store the loopback device as data on loopback grub_disk structures, + rather than the file it points to. This fixes use of freed memory + if an existing loopback device is replaced. + + * grub-core/disk/loopback.c (grub_loopback_open): Store dev in + disk->data, not dev->file. + (grub_loopback_read): Adjust file assignment to match. + Fixes Ubuntu bug #742967. + 2011-04-01 Colin Watson * grub-core/disk/loopback.c (grub_cmd_loopback): Fix a memory leak diff --git a/grub-core/disk/loopback.c b/grub-core/disk/loopback.c index 02e6c164f..939043f01 100644 --- a/grub-core/disk/loopback.c +++ b/grub-core/disk/loopback.c @@ -162,7 +162,7 @@ grub_loopback_open (const char *name, grub_disk_t disk) disk->total_sectors = GRUB_DISK_SIZE_UNKNOWN; disk->id = (unsigned long) dev; - disk->data = dev->file; + disk->data = dev; return 0; } @@ -171,7 +171,7 @@ static grub_err_t grub_loopback_read (grub_disk_t disk, grub_disk_addr_t sector, grub_size_t size, char *buf) { - grub_file_t file = (grub_file_t) disk->data; + grub_file_t file = ((struct grub_loopback *) disk->data)->file; grub_off_t pos; grub_file_seek (file, sector << GRUB_DISK_SECTOR_BITS); From caee5efd313a3f95babb176cc710ff193fcdb81f Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 3 Apr 2011 15:30:28 +0200 Subject: [PATCH 390/869] GRUB developper manual based on existing Internals section and contributions by the various authors with active copyright assignment. * docs/Makefile.am (info_TEXINFOS): Add grub-dev.texi. * docs/font_char_metrics.png: New file. * docs/font_char_metrics.txt: Likewise. * docs/grub-dev.texi: Likewise. * docs/grub.texi (Internals): Move from here ... * docs/grub-dev.texi: ... here. --- ChangeLog | 12 + docs/Makefile.am | 2 +- docs/font_char_metrics.png | Bin 0 -> 16443 bytes docs/font_char_metrics.txt | 1 + docs/grub-dev.texi | 1515 ++++++++++++++++++++++++++++++++++++ docs/grub.texi | 106 --- 6 files changed, 1529 insertions(+), 107 deletions(-) create mode 100644 docs/font_char_metrics.png create mode 100644 docs/font_char_metrics.txt create mode 100644 docs/grub-dev.texi diff --git a/ChangeLog b/ChangeLog index fb6875c69..47bb01e7e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2011-04-02 Vladimir Serbinenko + + GRUB developper manual based on existing Internals section and + contributions by the various authors with active copyright assignment. + + * docs/Makefile.am (info_TEXINFOS): Add grub-dev.texi. + * docs/font_char_metrics.png: New file. + * docs/font_char_metrics.txt: Likewise. + * docs/grub-dev.texi: Likewise. + * docs/grub.texi (Internals): Move from here ... + * docs/grub-dev.texi: ... here. + 2011-04-01 Colin Watson Store the loopback device as data on loopback grub_disk structures, diff --git a/docs/Makefile.am b/docs/Makefile.am index 8d9fb8445..6e1500601 100644 --- a/docs/Makefile.am +++ b/docs/Makefile.am @@ -1,7 +1,7 @@ AUTOMAKE_OPTIONS = subdir-objects # AM_MAKEINFOFLAGS = --no-split --no-validate -info_TEXINFOS = grub.texi +info_TEXINFOS = grub.texi grub-dev.texi grub_TEXINFOS = fdl.texi diff --git a/docs/font_char_metrics.png b/docs/font_char_metrics.png new file mode 100644 index 0000000000000000000000000000000000000000..8d10d1f645e3a22b1535716256adc73f262e56cb GIT binary patch literal 16443 zcmc(`_dlE8|37Z;RcfyyMr~pXswk;dt-VJDwfEjsZGw`TMQQCVC}JxyO6?%1Rl5i^ zKc27mpYZ+Ro7*kPb_{?|aar;wve%qo zs^45(oJB+*o=})5Kf-(bxF3rjhoqQDgX+;E8;z(4Q2_0$AF>W<63{-x-Q9e-!@EC* zzH_@v%QN0bfwL99?gsh#%QGE12aVClBvsCIjWhP?UkVZb9X-y#^ZBpiDfk&Lb-ZdJ z^#4=yjOy7G3-n{UL@^rm)x!-#fsxKG1p=xUzexpaUuun~HF+d@k!qMW7;U^0Pq_uK z<}Fx>C53m%4Q1^JgP&27W3Uc!=>%n317upg39oaB=kbk8qg`KcI4OXQG(J_2@oe?g z+N98Jrr^6dHKyt`VAnZ8!j(gA8fSrdsv-=c8!rL;$AWeI$BxN%IqdUzIW>b~zkX<6 z`X2|3ZD{zU1B&9rpoZ9nI4jt0l8r-N+e#$gNl}zlI3bVW1OWs&WB66Crp9O% z{J4b(stB|wQBIK7?W-Fi(N@?k*H^k(oI65uSBU$2aZ;?&Sbk^CAjzBXd>E`$@AC>Z zA{ep!FHA1EbT@J)k~@+&GM8y%EEC3fDRZ}V!hg&T3@$D0oQd3w42}$^f6N#kPB{Jc zPZjxhsw*p2V*>aD^3GCx#rK$SSqS3SUFsWAj@*y`psDLa1Jqp7@4}A5A`mq7aD#aq zI>YRyu^rxTq~c8A9^n#h{kfxoKV~2dAp+sM5GE1(wvud0k-ENZrB{KKh#!Ok&rWfU zHDtmGL@mmYCkXG)Rj~~OC|o4nNC?ODUB;#0Ur%d&nR{_jY&Z@5AweFYR>rQwtw+cv zUEx6+qEcw2DyywvsCQL8!T@N`M43q63tz$K!BPLc$V8k+9zs>~4~!N^d!ZM#+O$=a zG#yeDDD!ZV2v-O!N$pd{&g=O+jASkXF5M`}3m4XWS0|iCLyUYWpSZGKQuC7T;6{jS zwz!MEddALxhmeBVsmFTl*{9qBZvrL=K9UWUaq|{w4*HNBzfjS@-V=Xi?asQWB;&n* z>9J2@-R9xa`0Anq=Cu@OcS?8GDJ$xF84jp>!zVBGri=@RDMyxQa5VBuZ~d1(2Y+c% zPL^C6WBE7kJm|PJQ=?IqRo)QkT>BJO))9+bSwo&8C9JOGi5dqy9TMN{ADPT?mEWW& zuLW@C;xH7o*I_zlTXz+~SWbJ0Y#Ebh-EZnT&7Kq$VhwICG7y8vZ)ClzIEuDMvt0R$ zBBP^==Ec4DQ!mLvRBQIt5J1@N#t#L)-V?&eMDgn{IPGt>TCum^V&u7tF31l;1pU8@ zbxG#_$|o+|WXqKGllB1DpnNXPdYWN&_BdCJ&tP`!x0hXjN|BtHd_7G(OoT_7=$z7TnPcMMU4(|c}N!_ zcE;qFq#hiK9i4;$_%f{F2S*Z(>p_RtB;(6T6Ccu>G#UCl5tPRR-O`>kUFn~1n%3?w zNEU;#-*wMDWqS_6L@G)1g!(0`4ctUe^?uypf<~}Gaux)jmNtL2_(!KMIgKQsbVD<= zM%dT%j|0Dg3u|Eu0_he~c$ZCW8)oahF1kQxWB(^kdgf_cZrSoLvWJ>jkN+uf6Pj ztL(pZ@kILHPX<#Lx;n7)5dvTFSz?9gOaXjTN~7#qb}V|x(njOzncMmPe*2DhA&F(>RKP^Luj05$m=N)#uMVF0IabO3m7t^L&L zxHXnMvh5gl{S9FhnagdFtVHH8NDpab!4Kijytd?G}eN3JfiZ#8sScm1;rYK!+PL2@5ZbPtz-4Hr4H1O~0eRL18lU-EF%dZ#Os2ky*ypALItE!x0 zEa^?W#{$;0z>dbl6F{Csv<{g7z?C3LtkG&l;bS{dMUIN+n-1xS`@U$W{DK(o@N_z2 zn!e;O9uvK5NEP@Z!$T3+VKRkhomA@Ex7+famnPor zL95#uTSIg;+9hPdK`DgeN<{vFI)E$aTf%$>DUC(K%cqASKpaYjrX(1x>?MG@`M)dX zsb1SG$LB5*2TUSA*7)nktI9g1i;B63HeN*R<*)=bGXFeyuK;}kUKD^=ZBMv99v{n) z7X}9t@G=2z<-V4fo;Meka$aDH8|E~x^k(*U2%!-=WYQ^by>1fd_gIEsaf65`@w?u5 zT;ZX>Hwz$;((my*E}-rz zc#mzE3IZw!4W&gZt<7Hr_;k}m^m%R04V?xX)f8~n-FzZi{ic*4 zLxPYkozmJ2oQ(IVTe>k$e3Pzs`8IoKc_npJO@E*Hzh&7MZPYwTE1P>*Y7XS(v9$af zOLj`_V4*sXJ}}>JuNyp%P@cl|?MMq|+CHrt>Z0_QuEL<`2__guoth=B_n(+euHqYr z7DJyyWMCv$gmVM%HjHzuh^8;A@569w&WAoE+s899;mlOhxVa&_6eYlJTirc_Vn#j< zJ<8sN(1pOo7Gl&}8Z+!q_1E;%0x1+T5PSUt;-{l5&%C)f&nQEqTjOEhF}Eai_4nI@ zbr;d7`P!RXZYUs%&2;Jpeis-bGb-mHPy)x=Xsb5w zxs8>md&$N!sa=R4*CBpTQt35dncxQRQd{|i>qKpU7|Nru=;)FCiv6kaYg>&+>*7^d zsMuWHd^^a5{WyE7Lye`9(UBjT1Sk*ib_qfQ;VVHZXbRwUca2p))$^$;L?CY3we^WU6o1#RhAneNd6M66&9ggeWNwSi7-L@gJ53dNB;+8Y0sx*tSjrTIX#4r z<$)cNdG6oV(WtQRFUn| z-i1@bS!I~uUnz#l{sUIVsMf`HL}A1#cDBR5n}8j}9eW#VJBG+be!Vw{6g>T)pjlZk zzlLuv%|;n`n3)(3wf=^I^S{NqJ8xM%$24(;S8=uuTl z8;KvGE;n=c>jO-IA_P2D0}nkN4>P9s#Ys5=^6@|kO6UpkM)f@w-G>o4qG1X@ zH!%YChYZ4aW?RmY&fKB+#_%l;-zb_fm%`bBAeD!+RBb2mnkR96Q|;=S8io!ff9QRg zAXXk39Z!ZzaNg9`!DnQoRWiJ$TlL%qDO$6Iq%Bn2oCK0Y%-lYiQ>zdMy<;7LsM%$>PFd2wx(E9c$-OBh_*7aq!^?SlqA-1v^*j**QaYBkzOutD&Me}2%%$^4>0E1 z<$_>5_Mj@v;7a?>C)}*qA+>5}ohfNPlec5^!0>J>kGo%}yZdA0u$m5?{dXQGd|+@z z^2s?%8~LFO&%{}!_|wdX)4;d;u9cKnI7C|BhE-{K7u z$sUiQ&jiFS(W7Gp{S>Ag2vYrmF`2y8!S%7jebjyzwK#rn%QCS)`ilWL=MxR1X zCsW|{vnf1aZgoAo-u*LldHS-YD@jH3) zURE%zDH?YB`Ox!>34Fa_(sNIlYJb}WJDC4I`{Y^+r@h;WXh-Ugc624~Y(iCgHY}fI z$x1r?j2Lv>!C9dYS1D!bY9jt9wzO?*f1rKnrvMXw3bJ%J%=!)bTMqb*Jb-pcKdJO~ zWIT4*%&OM_AjU$2yuOO6dlx3>*~@5s0mvhaE6q<#q2yg7%P?RGv_ZM9k%6D-&PcfB z@ocl>Q6#(g@t`HZ^*HrrH+ZQ~x<1A+mx4r}N+?}MllDIPy^PwdFgR{i<-zd3x?zDo zZ5SsA_`YgNTwq(j5%8X_{T=Yyq^Ew!t1O_efJYBIdvEvIyBAYI)tbI>fTD6+K=Wfu z<(YbclZuo=4b!UXNM9^4aKov>*5Pl5uQ+PQqs*lYL`MJGS@U@s-q|m0ZbBMhFp=)Y zyR*LU4Vke-!?+W~Pp$H~TDt+b5uD%~!T3keClV4uNjga0Xj`lGN8rJ7ekjKYHs{l);UG!V+w^Zib{ zF!mGr@k7o1e9Cg8uOQ`QZjh#fnqK z{B$-LItgHdGlbbej0}VXoe-Sac?GfQc}yAwF*;JVZ)^X1sIoE9&%8KuYP0|F>fD(_ z)i`$Fzz_V$bg>9u%s!oR6~S?Nv@o7lHoSX9&fziMJ2aLB#oTzK7svbA2K3A<>dlODLxt-O;%>o1@R1}M5F0+)Cy z?3^wi3Y6|KCJr?xuf=g}>Z_+o&==tI5a4#XKwM?19xKd0L|bfjB7SD_P$>0{D9Qy= zQ{V!s1)QQvi37xEtRykOA*-S3-J5T=xzP>kl8t_l&(qT;21DQg@o5GfiN+JwKT3Mf z)0;^%m((e3-kk!p5@QrN1(64j{QUdrcMr#DgSl8bzNV)&EO34?Gb`AJVvU50``(r}HWEgv&6JVnV}i3>;;R=`|K={xPk_2!hECcm6*gZp z3W>O}^K(=a8P6i}Vxo5(bk}`*?(t@wc!g_9N#k`HeZIpE*q4mRpo$bXqQxUe*9zHO z5vBGYuET028;=ZJuAiabxRO_e|Fi2;R-0NeamcbH*?F{l_(V^O=t~<{9bV1c*x%2v zYKzaXlmQ~q#tiOII^7Q@S(1^s$2ntJ>1X)sv8U09R<6Cw^X@#@a;`j2i1wBh;;(+; zf(YlX{@y)oyxH=)xr!?dC zn4j_E8IZ~IV@Xg0>V@)?Gkgfc=`)6eT?-Xyr6P~mkJiJ`b;EMeoB^hTL?~U&Pqk(nyI8?5GH)ZOv_%7{ z<$Q@9G;rF5-JYyexnfy-_w>W%k3B?s#FTE1>bx{1O4X0u8A|+F zutNeTarbbPZ=2jyvqs1Eza5AFpV;rMF(WFVm_I`>qsvG`^03vS&wu#dUm1|$jyI1zg(wP`#E&G5vBFK*VNe z-2w#`^6&4loY7G&tkQqkVGEzrefeoNzVKQp908&{&6F#jWPL)o5V{keg zL+96!=NaB#&gDSkqsJzpNDM1z&Bdj&BSOzNTpH$VCE|6nS`&=4L5;phx$bQrLVcOA z@dYiY?uWwN%aS|2T~{cRey}dl!pnZh9Af#Uu!c`5&&8DHd&EVQN9+NIbklqcod%xn z8nmn_e3SCj)-axx~7HC%_1-Bxs@OO`AylVg%8mQS3> zJj8Gne9b(C3z#SvzVq4~zqW{wDqcVDOP1JAYZCI{@c`mxz%9vK1f29M{i;q2V(f20 zxFHG+iy9zOO)~X|Xb9(CQy&ig5FLS(&{OtPTvnB_#8_8B3PqjBgAVP1f*20DHG9PO zbOZO^IVJwxFz!&3skxJ*5F4=7ge&3NBj##`7XUlM)s$e@KxO#Kh%i_Q~8?nDH1kdC$0>v|__?d>{!nH9E_bYu1@Z&h3K zuh(!AdtG$>M$f?oOtHZ-9`xS+SO;&DC6-LKFp11=%Ayc9dP{K=EN7z8D9 zA0ymkrV-D(X3G!$&HUk95G5I8&00i0(UUk&y&t8T8`RzC<4~EN<_I{D3PWRc_u= zGl9(og2{ndOqPxxz~5Ey`wG!f1bNmeXTZFyf~a3EVqb;D0)s9;Fmfb8p6F~i5m9+eg0*+1e(I*pFd%ZF@DG%68qa8fu95DE~)q6=N-A)sy zodT)wdltJZK_q3FUFVj?coy`@G|TTDSpKnPy!?rW%v9MKYLECogUDOMv|epS2^-fZ zQ~N_a=Nz%E0%5qF&6mm;PUq|{uCM08y&FCK9%ZoRJWn%x-RIy+tPPLKbYNsBX-kfD z9XP+dI#v2=IHAPag?_qgX0RIZ;nSdkN>4p3a)AHWty8~bS1NDu!Hlm3yI6~VWZTmI zc0~J8C(?MUe-&hR)b0G$Q8KgJiqB79mZkL!R-G}I4VjdD;$#Yr)eQ!7aT|C&OK&oC zP&drCF7GtXomm~ImU^e>YOMUi0~oxFG!;g!_uS-;$u*t{k~uLaM$?<-dgfOTUJje| zy6-$+_g%lhUNSz%|8Bvb2_r&5Agtt7nRq@5c@e9|Y7)QLZpR-XNL*)c*#y6hASg%s3T9e5!H9fN!J5l@oV~zRd^BW{B!q1=6+D%Ul-0ES4%>Eoil| zgNV6V>|K>BbNdmhw+_Qa6N6WEgze(HU;H`&+P42IB=X4L`P3?ylLd+sPX#H zIj4x%;@a5#T=zLhUj@lf9L@bD;6d4n)=>}qkT!~Xm%>-JjdX4n9J+S`TA6lI!UL>HRAl!Fnhc$9L?@zEMYrr>^=6!^n{p)7+`w z(irXaD#+ck&bHIuEgAY6&W71&+aQeMZ{}w8QMjR! zCU4i9I)Dy>+leV>#ou4z7uL|6Wtw>gW1IjA zIR3=%j#InQ}e(dAH0V<_dI z#~Bj}F*H%&c9I2FDr{zz?w(8pCJ$Hmp_!3>h6daU97eEFsKaKYb&_0tzHe z|J+~@RT{LIw+o=T%!DZ{$75?$Km*nZKzD;b5g`za7|@K-%IHeKqZTHF=RzK0I)%xS ztGycqF2}`kxHS;xAuMR!SQwX>gY@U z&~io}g(`|0?#6ERyO$Co9t<9iIc+V)mDq{0G8jBeN8S@{u_~OGBm-BvrY`pNvp})Ssj;0K|dYm_XIEo}72v9rG0t<`1 z>OU?3#GO7bm^y&f5pN@iHetp97QW{+N?J@PT|^gD#|SdzinUp45+kREutfhw_>?@8CTovTo7}K6d%-V ztWU-*+nvgJ=}iqu8H)*??}{CoS9~l((u({SNY3-SsLSkikLp0%e##v z9G0QPVkebGvDkFOD1y3$lie-WtEJe!sD>vkkq+IV`FD4&?77Bo176u^oZx?}2<=>` zdG-ad_+_+kEeT#?xZmj|pb%0-PrTz1Vredv;ae6+BE!JII-(W5V=giDxTf;2%sJsF}zHGb=fN|9#TXMd%qrZT8MLPr<2ZlC;BLLEx39nFGFjp_Ly-= z+$P-VMrH47xgo2DDJvzUTX+5l#%p7o*YOel-7R%3{lavSO0ymBQvY{d7zDEX*Lt6i z<9sSw|Nf@RMUAB{BpmGgV%F&;Sf^K3#j>qMtTE0r z%fP@^ds9)}ca6+7XLggX!Ecuj+EUs%j}E?gE`w{_)^V)`S2RIgwWeUu!}PPf((spZGKFTkQ%q3djI)^1Z52SP`{oEzcoz?RPrNCd zbrwE0$n9hU-iQt=^4!mchEZL8SDktTbrWoOli8G3I?cVzy{iY_2AgtjHGWGd-2|{k zUvH-NS)~j2D6J%q?Q2yspww7LzznwghpZ+CVvEBSwh)I`EQB45qw7ywP6Tw3vSfdg7g1EnBfi8Av%CA4r1HMBEuter=)`ECj>H~BW zXagP|{u4XhvF&zlTu=_Ce)%aLW5Dd*vT(rGKlJCataN5^-}BEh%Behw+YLpPDB@p|2v48s~`vo9)%%mn0PCM5wfIBmgd3CIJD$&X4cdS5KFGTw3+3;Kx?~pS3!e{Q3$iY* zNO?+^eUB6ASAo;GbMax8gS&Lile=ND13YT5{`FpB!qacR;V~qK4CnS)fFzeEspLI$1hcbTmAkOI4vnMg*(HG zlaKCftZUpXjrt`s7nIpq2j#E>$mfMw3Pn(q&ixpJ%^#t31@G?gZn8q`(M2IKykKwe zqTZA;GzH<%IE|Am*m{rPdUvZobw66Egp<2wh*!cb#Ief-{fKi%AYtI0d7J}V{{XI19DtsV^VfuZ?ztwm-KGCkJK~DRqY5AtPU@?)-LIRLoGuFEFxHQ zXxTm{G4r{J%q437P#2JW*o&Ox4dFC)wC*SWmo0-X-~W&WnfLfAyf}W{hr7wF=q&Q* zsEtA?5Z?tWk5#dj@H)9m2=CPiSpd(wgZ(do{~*8pT>~fvbbsB3Zq<|w&s=xl(TvuG18oRcF%x~- zFG{Z7@fuHAd9F41Zq0)O*g6BpTyTL)`8W!BFbi8qCGO}(Z(zqH8w3*uZws@5lxVih zEi$+RnRI{SzP#FdyKjkX8$|l`T18(BT3PwyKc?eth3fxc86s#k_9i>|mZ&4%coMzi z{b2lpZ`7Ilh|p&}-xVJ38gdKq?@k}Iz=lvO=XVJMn)IYg#w<6T&D~OI+sNW*8!bJ& z?gaK$vG?^5zfk7$pfN|ZJ?RuYLN;Dn%vJMQZS0<-6>gdYDciSQsCnDe90Rap4%wA@ zFO&W8muOix?WMi}wxlsqMNN^&WjgWhZ)onq4@e8o9YT&E9G@w!y!#K+UzUjaM4i;N zT95oKX*h|%`z*%(mtjAn$2cFb@%P*#dw&rV!To>h*0=%_VE8jFd7H?4|9&A=ToxNh z^R@X`Q=MM<2uW@s%U9uI)~={$Pf~cMFW)EF5u%(Sny8BPM>kn62U-gP5layU9*wa2 z%ibjbE#aZEAJ*}skij}Y&2?z*k93qFg=;FVVQ=9}()Gr3cZaLJ4+&iR()v>6F=EMs z4j-*b`)UJdE%RSs74py=BvDk#c$^N;JKC@sxIRvDBJ1K~29{lTP!1M^D!H1^xdhY| zSIjjz)r9S@qm|@9cUkh2gSPNLK*Q#r(!>PA|3Y3>tuw?E1_cpV@wO4l;DsX;lPf_4 zF@BB<{u#=w1=k40{$(u@-d2*7+=b4xrx)(#Pqy*T!h!aJL-NQnx z@FKRY-74t@)b(qvzE*nps_{{FV|~4aCSjFtdqC|+6Hf`3j?+2sr?7cty-;6|$&zCY zGjEBfTp>1&1~)%UuT*=gpBeTzH2%~rkgByQnB0DjXCJ<7#)~g;$Mg8wE-;fqNUoV7 zx0e#=7xGhYZKs&mM!Dmj-c#s}ARTq9%q719iC}E)LK8obTAJa*t>O_bTG)%>Wc z?Y68S27c1B1)sG!Q9if07%;kt=)w^+xR80*j!F3q=$|7lNVuu@F=*Bk9UO>%L(I@M z(jBtA`X+I&U3NW)g4EZxFX68Ea1Uv5y6Z}`eNSOn0qgIz+OCGoC#Ugj#3u{JL{#=;axLMrWho-)Ro`RaGEx9@_DpKEO$y?3y2 zO^haAJO^a@FtB-ZzklF*qEcI?9i;22AEF09O;c{$#CrR}U;p&$*Z#y=ob0o>ql0!E zPd)@&X!g9hctNPoqGd^xybx5p$j4CW!TWjsgzfRqp&nXV)Bo=k3J?=~Awm<@R`eXx3o#p+m2h1Frc{BllsOH?G?s z|9F_f>y2Z%gik}!Y))=UD^+(cm&MLWPMO%u#*_{dCIF%MTp@!WE-PqOROFY615e%b zGayJuo7QrWUZ}F65!TE+!Oa8)8b=Zrl=>crgw(rpK6n|ra^i5|Cr(PEIgoc=pq&d( z-QR+RJ#+IEB94FFJ1*#7On+6;Z8GrGEigMNKk0<)-N>CeM%E|J&1w-YPmxjiOMS>s z_FH~e(hI+Ew?l=OYsRa{dnjm9D>YU%bZR}gim_rwQb6*#i`UE>N^OTnWyup?^a;sB zC@*!(ul@wH`p_cxrGWBNNX7R{+U#*64d%q(pX>^P3rTe(RS1C26-$|fDyy;$3+lTm zDlY|HCM4ZokZw`V03W z*$@UsVp^0pE!FcK%iFf7>8dy84i>-K=uJAXau#ORzI%AL=NNOKKa;i8jStQ4(oM|H zoapmrE)L|GjqP`A#Y@olM1!gmt*levVUJR7bQHEh2TKDT0 ztHRwk^LsrNu`l-LnNF{vafs->p^to(&yUTlP{Q zMTbi_r(MkLQ3L+rFR_9jh8()HGA*wKQlNjm(T2>YYCdl&XI=;Zgc65>;_E2_Xi{gy z5H&5sSKOe??H!E2kP|jY`0|6Y)H(H`;>`+LomRcCLb-tMaBcWc>IR+M?YPY8nTy7! z8BiUQO}EWJy^M!W&5G7#=#`gp?n5#=P%N5ZUt1hNBsWJINg7>YM{aI>grCQ^t7C3# zmE=&llUV+#^xVbz_#aI?&G@84MKTEDXQhGTsju417aO}p><+bhcwjN4j!#1Fw# zl_o~G5-$8=^d)lO3-_)Z&Z#?>Um%=th~#w0B8HDN@r%4jEq2Su3R^wSb+Q7fuLmPe z1F-U{cZ#_P3lz5>hwucDc=#y8X1uP=Xxz8XG^A@wq6>$b;EeYB=Lc^lXCwGrKi{U< zQ@DEyF*kX#E*z*>|6ogMbV8Ez@P21VSQ68&k#7sSAcbJyuzYI>Gq(3yZ_wjA)lhK3 zmk<$fz1y#9ILkbFYG)@iKCEtR-zxb&S~EoJ#^#v$WOSC$khxlPZuKxh31D|wPr!38 z^qO&uvTAj3vRJIqIf9VjXTRhYB-mnrq{;#dkbK~`O3X{VL-Y{723}{t4w8aJ+>-W! zy9q$tyGqb5UZ-Yp0UWTIVG^^aLQO5#4QrYKXSTs_RTQh@dn;4ru&%HH-q@rjeGjjh4(2VY)^oq5Bc9R_e zgoe@JdCl4fzCb?$YiFQ8b!$pCfb&=}r~3p?b{hk#Nk?9C@kzm*xPa2s?lf*_VPC)-mur z2{89rF!1Mewc1Su6ps@q_kcG8>$Jm7US?BE0Go=`;GF-wx}+AI*b7PW;* zK4w~#>r#+je^PF%2dJK z+A|u9RW)515r^Ussh`Li$wv2_1t@~vL;i=}<#xA(M|x@QbFFC5mv=;9hc%vOVp`P? zf~XF)q<5*J&TRQ$q6Okrh?Kx zQb9F26QC3VB?_K~R>kH}LC1w0|7@=v&3QP-xDcFiMIJ=hd-)y`2qTuuR>{nw?T*h> ztwv`8Cy;&=e8K0Lm>_* zO3~kathJ`5T&UCQ?Kqw*uPByuI~`C|Eog+j{pP!jKY%UQwiR_k3~9+OJ)pht7w zwA=l{Us^Ay{b$S--cuc-!}rzOcqe=abwWSpVg+6maXjJ#)lIjNH7zU1Bn7J9+_`G; zTlOj~DKI$3h0}P*4@9Qx3?9v$dky6_`?H4W(l=jdTE|9V3WipTFg?}ve-D-^_hGUa zIyd_Jn0GGj1M9L=g<%1|@1)z`)GD9FASfo#JYEQpjBwxIUws6-bpmMHu?c?F zP+G3TVoWBa{`6RD7&)kEniyGMSV*+pRq!p>)qOFli^<)ngk)T@N_}K-PA8b($^8=) z^C0jJ0EMwiOA#4qa^WhbA?6c_JLbds>SM6_M?%lI6cM_lqmPqw6>S@1i@`wd*X2z!%!L6c`uAx2*OM+VeWcj8CePG@ul@%#zkjXb<+yyc5->@E7)oXYae{q4= zI@#|t9Hah6RYKm~BFZ3`fYxgrxgACI*OupL_Rl8>#AEoTs$ViavTZm^`2Mn#k^Qx; z-cRj6P4@@94ZUr14-~K=jZd^PhOh5@$#dS0rF|&Zpqfw*nMbw|VOQJI`PYgz7KrF) z?YHlSkA7Zqoc|U4Vq+*jUM9%3MqIz0ClfK3k#N<*r zbe`-{@l{Yjd2PlXo~}CtTlzMThB8zC>y}3U8wsvIpLy3JAK9;dNt7it``MpS=YWc5Sc!#t07Ho>Af0`Bl8Yuw?O&fd8vj5ZPIp z4T%d)gbkFP|6woy5z`Mww|{>h3``#M#&GQNpeH|{sb-ylJfdK?b)>GfDZy+CE)VJB z_FGl^1fNQG-1`H=IH*)_G{j(&4%pFbw(;%x!clwr12tyjTVjY#uO)TKy3861N!eXTr}njee4ADt!0R}5r)-?K5;F0dLQhAzmz(kpm%v+Ugg3%fAP`S9vyxl zd>2Rz|Anj>YvFPVw5GRy1j_nZ5HZBkB&af96mTnN~)>BzpQ7*RF0|PWLzz{9Sj*blLiXTdLQ~L{W!39@t z8ZdIa81b=4NDrmP#g&uXkOILCs>xbmUW{+5d2MpySt8ZrK1t+eG|763FXf~9Ja#~Y?R>0F`soSZup>;!9_p2qTTVZ!}f;W4qLBE+W10g_jcsM zLrQJ(&$XtR0&_uIN50_i`>No5+8S5mW&hs|xzl}BEBTYnT~v2c&&}PU95fWi%YL2T zGRa7w;FK}0ZfF{4jTmJuxNIDXSPTgH{glq#<*&2jOc#^6HALhsrncYvpHPfhStjQ$ zC%PnH-)OCIO}*ETv_>(IApoGXVlFQq>xZ#B-c9u5P!v!vCXdP*`paFej&?UaMXw%Q zktNleXSuhU)NW*clX1BWq^5&NAK~XyO_IiSlVi8KTm}bCZjcx;OZCB?Jmf)Yk?hC&J{&z`A8)8Ik*ld!Ga{|9$QKEw#NWt1*H&V@l z7*{<&06>VO%4Kt$pBe3LzWiI_fh9H?+W#sb9BjG(4XWn#dHzf~Y2k=6TnW*~752#L za`coX0@jJ+!h(9yI_NtQ{Bm&=sRQvE+}I^qbbR%#mW(FX>ZR;#WGv3O~^mb@>P`z%8w=owt`GA$lXgFNw4Gs$w{p42gb4n2WpGbH4At5rpY% zz@Os3PP46ob2f?tS)$aX#Riz)?| zsd-63n_kVYzMcw!opO1Eda2Og3KpCmQi0hgGIKeM{q+w8puCa3fU%Vq%Q{{ZH9;_n zxg*M)9^N$+8+Q+MOW51>5IZhs!9enSIqC8E#~=k_JG?Vu_~M!Y3Un9%vY!w)>4d?w z`)RVfuu;6bY~cIB3|-5?-++u@TwQRxNB}?wQO(j&8+eU-kL8wjX6?A$jmYM@PFUkZ zd2MooX#fW^70;zbQ+tlH>#o1TZaY&v$@Kn%zI8g~&aF5IW`pUA-WPZT3Wj6(J}qSgD_?L1o;Rz zPXrK3HUR*Uw2m;i!>E#IuRdWLvsx7e%f4}!GG|!*6o~8iR@?-qut)JNWJ2OLtv#l6 z0*f9;NxV^obllw$VssJqwl5VewDd!*Hy)7=!Q6i2rfDu_@}@2;tq)BC*^M|O)W`O_ zqE4M8JINPM0Q+?jU99snNVlU`!4@3Vo{y(BvGaSAF=95fq2-)wEaU%8u);%H-UhyW zJBxUCE1bs>NR7c=CLzh(p@Lwx8@!7p>cOT7Ei*Uz(c({pOVcjpeB@}|7lmPyYHZY8WR4SYIntk6DZBJH|FvR6mS>#Y zr$XprHMv50T!;4$b12>Dt+^=AK9|lOr)17!15www60Ca;4px7hw03js|BUC9=U~|t zvYp-J@5bQW)fo@L;DVPn)>z9NDevC@TQjcvVomrk7byC21qhFL`tB&xJeb^V$l;~g`r*MpjHUb3N`>~~ z5{duG#9ux)4*g#%@!SW?IC*+gE1~eKnySvwNHy=FqpUNgI&xeE&D`b-pt;QU#4=W% z#ncKb{EMDRurs{&z=opcfFiE?*vplI>$^Rw$$JeBvJz)nJ~|h49@oQ^Ih^t)&h)IJi;Y(On8vWFx^=VZ&uT zp!Lsz?_$9*@u46AK&_`?>MkQ&DFGtxGdq|LKma}NQ)?=Mr#RR2wbJ|4IDbAJVex;T z;Xwhyvo2Ua8u8e-KWCGatGsi?~Qu#w5l-7SNTWo(}n#L|Bh{L_S6=BihP-bgXPxm9h8g5LOe;5!N(;R<8jJ( +@c Date: 8 January 2009 + +@menu +* Introduction:: +* File Structure:: +* Font Metrics:: +@end menu + + +@node Introduction +@section Introduction + +The goal of this format is to provide a bitmap font format that is simple to +use, compact, and cleanly supports Unicode. + + +@subsection Goals of the GRUB Font Format + +@itemize +@item Simple to read and use. + Since GRUB will only be reading the font files, + we are more concerned with making the code to read the font simple than we + are with writing the font. + +@item Compact storage. + The fonts will generally be stored in a small boot + partition where GRUB is located, and this may be on a removable storage + device such as a CD or USB flash drive where space is more limited than it + is on most hard drives. + +@item Unicode. + GRUB should not have to deal with multiple character + encodings. The font should always use Unicode character codes for simple + internationalization. +@end itemize + +@subsection Why Another Font Format? + +There are many existing bitmap font formats that GRUB could use. However, +there are aspects of these formats that may make them less than suitable for +use in GRUB at this time: + +@table @samp +@item BDF + Inefficient storage; uses ASCII to describe properties and + hexadecimal numbers in ASCII for the bitmap rows. +@item PCF + Many format variations such as byte order and bitmap padding (rows + padded to byte, word, etc.) would result in more complex code to + handle the font format. +@end table + +@node File Structure +@section File Structure + +A file *section* consists of a 4-byte name, a 32-bit big-endian length (not +including the name or length), and then *length* more section-type-specific +bytes. + +The standard file extension for PFF2 font files is ``.pf2``. + + +@subsection Section Types + +@table @samp +@item FILE + *File type ID* (ASCII string). This must be the first section in the file. It has length 4 + and the contents are the four bytes of the ASCII string ``PFF2``. + +@item NAME + *Font name* (ASCII string). This is the full font name including family, + weight, style, and point size. For instance, "Helvetica Bold Italic 14". + +@item FAMI + *Font family name* (ASCII string). For instance, "Helvetica". This should + be included so that intelligent font substitution can take place. + +@item WEIG + *Font weight* (ASCII string). Valid values are ``bold`` and ``normal``. + This should be included so that intelligent font substitution can take + place. + +@item SLAN + *Font slant* (ASCII string). Valid values are ``italic`` and ``normal``. + This should be included so that intelligent font substitution can take + place. + +@item PTSZ + *Font point size* (uint16be). + +@item MAXW + *Maximum character width in pixels* (uint16be). + +@item MAXH + *Maximum character height in pixels* (uint16be). + +@item ASCE + *Ascent in pixels* (uint16be). See `Font Metrics`_ for details. + +@item DESC + *Descent in pixels* (uint16be). See `Font Metrics`_ for details. + +@item CHIX + *Character index.* + The character index begins with a 32-bit big-endian unsigned integer + indicating the total size of the section, not including this size value. + For each character, there is an instance of the following entry structure: + + @itemize + @item **Unicode code point.** (32-bit big-endian integer.) + + @item **Storage flags.** (byte.) + + @itemize + @item Bits 2..0: + + - If equal to 000 binary, then the character data is stored + uncompressed beginning at the offset indicated by the character's + *offset* value. + + - If equal to 001 binary, then the character data is stored within a + compressed character definition block that begins at the offset + within the file indicated by the character's *offset* value. + @end itemize + @item **Offset.** (32-bit big-endian integer.) + + A marker that indicates the remainder of the file is data accessed via + the character index (CHIX) section. When reading this font file, the rest + of the file can be ignored when scanning the sections. The length should + be set to -1 (0xFFFFFFFF). + + Supported data structures: + + Character definition + Each character definition consists of: + + @itemize + @item **Width.** Width of the bitmap in pixels. The bitmap's extents + represent the glyph's bounding box. *uint16be*. + + @item **Height.** Height of the bitmap in pixels. The bitmap's extents + represent the glyph's bounding box. *uint16be*. + + @item **X offset.** The number of pixels to shift the bitmap by + horizontally before drawing the character. *int16be*. + + @item **Y offset.** The number of pixels to shift the bitmap by + vertically before drawing the character. *int16be*. + + @item **Device width.** The number of pixels to advance horizontally from + this character's origin to the origin of the next character. + *int16be*. + + @item **Bitmap data.** This is encoded as a string of bits. It is + organized as a row-major, top-down, left-to-right bitmap. The most + significant bit of each byte is taken to be the leftmost or uppermost + bit in the byte. For the sake of compact storage, rows are not padded + to byte boundaries (i.e., a single byte may contain bits belonging to + multiple rows). The last byte of the bitmap *is* padded with zero + bits in the bits positions to the right of the last used bit if the + bitmap data does not fill the last byte. + + The length of the *bitmap data* field is (*width* * *height* + 7) / 8 + using integer arithmetic, which is equivalent to ceil(*width* * + *height* / 8) using real number arithmetic. + + It remains to be determined whether bitmap fonts usually make all + glyph bitmaps the same height, or if smaller glyphs are stored with + bitmaps having a lesser height. In the latter case, the baseline + would have to be used to calculate the location the bitmap should be + anchored at on screen. + @end itemize + + @end itemize +@end table + +@node Font Metrics +@section Font Metrics + +@itemize +@item Ascent. + The distance from the baseline to the top of most characters. + Note that in some cases characters may extend above the ascent. + +@item Descent. + The distance from the baseline to the bottom of most characters. Note that + in some cases characters may extend below the descent. + +@item Leading. + The amount of space, in pixels, to leave between the descent of one line of + text and the ascent of the next line. This metrics is not specified in the + current file format; instead, the font rendering engine calculates a + reasonable leading value based on the other font metrics. + +@item Horizonal leading. + The amount of space, in pixels, to leave horizontally between the left and + right edges of two adjacent glyphs. The *device width* field determines + the effective leading value that is used to render the font. + +@end itemize +@image{font_char_metrics,,,,.png} + + An illustration of how the various font metrics apply to characters. + + + +@node Graphical Menu Software Design +@chapter Graphical Menu Software Design + +@c By Colin D. Bennett +@c Date: 17 August 2008 + +@menu +* Introduction_2:: +* Startup Sequence:: +* GUI Components:: +* Command Line Window:: +@end menu + +@node Introduction_2 +@section Introduction + +The ``gfxmenu`` module provides a graphical menu interface for GRUB 2. It +functions as an alternative to the menu interface provided by the ``normal`` +module, which uses the grub terminal interface to display a menu on a +character-oriented terminal. + +The graphical menu uses the GRUB video API, which is currently for the VESA +BIOS extensions (VBE) 2.0+. This is supported on the i386-pc platform. +However, the graphical menu itself does not depend on using VBE, so if another +GRUB video driver were implemented, the ``gfxmenu`` graphical menu would work +on the new video driver as well. + + +@node Startup Sequence +@section Startup Sequence + +@itemize +@item grub_enter_normal_mode [normal/main.c] +@item grub_normal_execute [normal/main.c] +@item read_config_file [normal/main.c] +@item (When ``gfxmenu.mod`` is loaded with ``insmod``, it will call ``grub_menu_viewer_register()`` to register itself.) +@item GRUB_MOD_INIT (gfxmenu) [gfxmenu/gfxmenu.c] +@item grub_menu_viewer_register [kern/menu_viewer.c] +@item grub_menu_viewer_show_menu [kern/menu_viewer.c] +@item get_current_menu_viewer() [kern/menu_viewer.c] +@item show_menu() [gfxmenu/gfxmenu.c] +@item grub_gfxmenu_model_new [gfxmenu/model.c] +@item grub_gfxmenu_view_new [gfxmenu/view.c] +@item set_graphics_mode [gfxmenu/view.c] +@item grub_gfxmenu_view_load_theme [gfxmenu/theme_loader.c] +@end itemize + + +@node GUI Components +@section GUI Components + +The graphical menu implements a GUI component system that supports a +container-based layout system. Components can be added to containers, and +containers (which are a type of component) can then be added to other +containers, to form a tree of components. Currently, the root component of +this tree is a *canvas* component, which allows manual layout of its child +components. + +Components (non-container): + +@itemize +@item label +@item image +@item progress_bar +@item circular_progress +@item list (currently hard coded to be a boot menu list) +@end itemize + +Containers: + +@itemize +@item canvas +@item hbox +@item vbox +@end itemize + +The GUI component instances are created by the theme loader in +``gfxmenu/theme_loader.c`` when a theme is loaded. Theme files specify +statements such as ``+vbox@{ +label @{ text="Hello" @} +label@{ text="World" @} @}`` +to add components to the component tree root. By nesting the component +creation statements in the theme file, the instantiated components are nested +the same way. + +When a component is added to a container, that new child is considered *owned* +by the container. Great care should be taken if the caller retains a +reference to the child component, since it will be destroyed if its parent +container is destroyed. A better choice instead of storing a pointer to the +child component is to use the component ID to find the desired component. +Component IDs do not have to be unique (it is often useful to have multiple +components with an ID of "__timeout__", for instance). + +In order to access and use components in the component tree, there are two +functions (defined in ``gfxmenu/gui_util.c``) that are particularly useful: + +@itemize + +@item ``grub_gui_find_by_id (root, id, callback, userdata)``: + + This function ecursively traverses the component tree rooted at *root*, and + for every component that has an ID equal to *id*, calls the function pointed + to by *callback* with the matching component and the void pointer *userdata* + as arguments. The callback function can do whatever is desired to use the + component passed in. + +@item ``grub_gui_iterate_recursively (root, callback, userdata)``: + + This function calls the function pointed to by *callback* for every + component that is a descendant of *root* in the component tree. When the + callback function is called, the component and the void pointer *userdata* + as arguments. The callback function can do whatever is desired to use the + component passed in. +@end itemize + +@node Command Line Window +@section Command Line Window + +The terminal window used to provide command line access within the graphical +menu is managed by ``gfxmenu/view.c``. The ``gfxterm`` terminal is used, and +it has been modified to allow rendering to an offscreen render target to allow +it to be composed into the double buffering system that the graphical menu +view uses. This is bad for performance, however, so it would probably be a +good idea to make it possible to temporarily disable double buffering as long +as the terminal window is visible. There are still unresolved problems that +occur when commands are executed from the terminal window that change the +graphics mode. It's possible that making ``grub_video_restore()`` return to +the graphics mode that was in use before ``grub_video_setup()`` was called +might fix some of the problems. + + +@node Copying This Manual +@appendix Copying This Manual + +@menu +* GNU Free Documentation License:: License for copying this manual. +@end menu + +@include fdl.texi + + +@node Index +@unnumbered Index + +@c Currently, we use only the Concept Index. +@printindex cp + +@bye diff --git a/docs/grub.texi b/docs/grub.texi index 0808ded6b..45baeafe6 100644 --- a/docs/grub.texi +++ b/docs/grub.texi @@ -100,7 +100,6 @@ This edition documents version @value{VERSION}. * Obtaining and Building GRUB:: How to obtain and build GRUB * Reporting bugs:: Where you should send a bug report * Future:: Some future plans on GRUB -* Internals:: Hacking GRUB * Copying This Manual:: Copying This Manual * Index:: @end menu @@ -4374,111 +4373,6 @@ If you are interested in the development of GRUB 2, take a look at @uref{http://www.gnu.org/software/grub/grub.html, the homepage}. -@node Internals -@appendix Hacking GRUB - -@menu -* Getting the source code:: -* Finding your way around:: -@end menu - - -@node Getting the source code -@section Getting the source code - -GRUB is maintained using the @uref{http://bazaar-vcs.org/, Bazaar revision -control system}. To fetch the primary development branch: - -@example -bzr get http://bzr.savannah.gnu.org/r/grub/trunk/grub -@end example - -The GRUB developers maintain several other branches with work in progress. -Of these, the most interesting is the experimental branch, which is a -staging area for new code which we expect to eventually merge into trunk but -which is not yet ready: - -@example -bzr get http://bzr.savannah.gnu.org/r/grub/branches/experimental -@end example - -Once you have used @kbd{bzr get} to fetch an initial copy of a branch, you -can use @kbd{bzr pull} to keep it up to date. If you have modified your -local version, you may need to resolve conflicts when pulling. - - -@node Finding your way around -@section Finding your way around - -Here is a brief map of the GRUB code base. - -GRUB uses Autoconf, but not (yet) Automake. The top-level build rules are -in @file{configure.ac}, @file{Makefile.in}, and @file{conf/*.rmk}. Each -@file{conf/*.rmk} file represents a particular target configuration, and is -processed into GNU Make rules by @file{genmk.rb} (which you only need to -look at if you are extending the build system). If you are adding a new -module which follows an existing pattern, such as a new command or a new -filesystem implementation, it is usually easiest to grep @file{conf/*.rmk} -for an existing example of that pattern to find out where it should be -added. - -Low-level boot code, such as the MBR implementation on PC BIOS systems, is -in the @file{boot/} directory. - -The GRUB kernel is in @file{kern/}. This contains core facilities such as -the device, disk, and file frameworks, environment variable handling, list -processing, and so on. The kernel should contain enough to get up to a -rescue prompt. Header files for kernel facilities, among others, are in -@file{include/}. - -Terminal implementations are in @file{term/}. - -Disk access code is spread across @file{disk/} (for accessing the disk -devices themselves), @file{partmap/} (for interpreting partition table -data), and @file{fs/} (for accessing filesystems). Note that, with the odd -specialised exception, GRUB only contains code to @emph{read} from -filesystems and tries to avoid containing any code to @emph{write} to -filesystems; this lets us confidently assure users that GRUB cannot be -responsible for filesystem corruption. - -PCI and USB bus handling is in @file{bus/}. - -Video handling code is in @file{video/}. The graphical menu system uses -this heavily, but is in a separate directory, @file{gfxmenu/}. - -Most commands are implemented by files in @file{commands/}, with the -following exceptions: - -@itemize -@item -A few core commands live in @file{kern/corecmd.c}. - -@item -Commands related to normal mode live under @file{normal/}. - -@item -Commands that load and boot kernels live under @file{loader/}. - -@item -The @samp{loopback} command is really a disk device, and so lives in -@file{disk/loopback.c}. - -@item -The @samp{gettext} command lives under @file{gettext/}. - -@item -The @samp{loadfont} and @samp{lsfonts} commands live under @file{font/}. - -@item -The @samp{serial}, @samp{terminfo}, and @samp{background_image} commands -live under @file{term/}. - -@item -The @samp{efiemu_*} commands live under @file{efiemu/}. -@end itemize - -There are a few other special-purpose exceptions; grep for them if they -matter to you. From 67e11623a8a14414342a396c3d0dce7f774018cf Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 3 Apr 2011 15:34:50 +0200 Subject: [PATCH 391/869] * docs/grub.texi (Vendor power-on buttons): Explain how the numbers are obtained. --- ChangeLog | 5 +++++ docs/grub.texi | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/ChangeLog b/ChangeLog index 47bb01e7e..129703971 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-04-02 Vladimir Serbinenko + + * docs/grub.texi (Vendor power-on buttons): Explain how the numbers + are obtained. + 2011-04-02 Vladimir Serbinenko GRUB developper manual based on existing Internals section and diff --git a/docs/grub.texi b/docs/grub.texi index 45baeafe6..0c59975cd 100644 --- a/docs/grub.texi +++ b/docs/grub.texi @@ -2049,6 +2049,44 @@ model-specific. Values known to the GRUB team are: To take full advantage of this function, install GRUB into the MBR (@pxref{Installing GRUB using grub-install}). +If you have a laptop which has a similar feature and not in the above list +could you figure your address and contribute? +To discover the address do the following: +@itemize +@item boot normally +@item +@example +sudo modprobe nvram +sudo cat /dev/nvram | xxd > normal_button.txt +@end example +@item boot using vendor button +@item +@example +sudo modprobe nvram +sudo cat /dev/nvram | xxd > normal_vendor.txt +@end example +@end itemize + +Then compare these text files and find where a bit was toggled. E.g. in +case of Dell XPS it was: +@example +byte 0x47: 20 --> 28 +@end example +It's a bit number 3 as seen from following table: +@multitable @columnfractions .2 .2 +@item 0 @tab 01 +@item 1 @tab 02 +@item 2 @tab 04 +@item 3 @tab 08 +@item 4 @tab 10 +@item 5 @tab 20 +@item 6 @tab 40 +@item 7 @tab 80 +@end multitable + +0x47 is decimal 71. Linux nvram implementation cuts first 14 bytes of +CMOS. So the real byte address in CMOS is 71+14=85 +So complete address is 85:3 @node Images @chapter GRUB image files From 09ceb9a5923c65b1fc6d9f39a5b64f0e2c2373e3 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 3 Apr 2011 15:37:24 +0200 Subject: [PATCH 392/869] * util/grub-install.in: Add a recommendation to use --recheck before reporting bugs. --- ChangeLog | 5 +++++ util/grub-install.in | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 129703971..54a6d6333 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-04-02 Vladimir Serbinenko + + * util/grub-install.in: Add a recommendation to use --recheck before + reporting bugs. + 2011-04-02 Vladimir Serbinenko * docs/grub.texi (Vendor power-on buttons): Explain how the numbers diff --git a/util/grub-install.in b/util/grub-install.in index 4e78dfadb..ff8bea87c 100644 --- a/util/grub-install.in +++ b/util/grub-install.in @@ -467,7 +467,8 @@ fi fs_module="`"$grub_probe" --device-map="${device_map}" --target=fs --device "${grub_device}"`" if test "x$fs_module" = x ; then echo "Auto-detection of a filesystem of ${grub_device} failed." 1>&2 - echo "Please report this together with the output of \"$grub_probe --device-map=\"${device_map}\" --target=fs -v ${grubdir}\" to " 1>&2 + echo "Try with --recheck." 1>&2 + echo "If the problem persists please report this together with the output of \"$grub_probe --device-map=\"${device_map}\" --target=fs -v ${grubdir}\" to " 1>&2 exit 1 fi From 829ea451a4b26418d1f413eab57a39620cecd95b Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 3 Apr 2011 15:45:20 +0200 Subject: [PATCH 393/869] * grub-core/kern/emu/hostdisk.c (grub_util_biosdisk_read): Don't close on failed seek as it breaks open fd reusage. --- ChangeLog | 5 +++++ grub-core/kern/emu/hostdisk.c | 1 - 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 54a6d6333..88a8a7f69 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-04-02 Vladimir Serbinenko + + * grub-core/kern/emu/hostdisk.c (grub_util_biosdisk_read): Don't close + on failed seek as it breaks open fd reusage. + 2011-04-02 Vladimir Serbinenko * util/grub-install.in: Add a recommendation to use --recheck before diff --git a/grub-core/kern/emu/hostdisk.c b/grub-core/kern/emu/hostdisk.c index d5b0439fb..50e5a34ad 100644 --- a/grub-core/kern/emu/hostdisk.c +++ b/grub-core/kern/emu/hostdisk.c @@ -876,7 +876,6 @@ grub_util_biosdisk_read (grub_disk_t disk, grub_disk_addr_t sector, if (nread (fd, buf, GRUB_DISK_SECTOR_SIZE) != GRUB_DISK_SECTOR_SIZE) { grub_error (GRUB_ERR_READ_ERROR, "cannot read `%s'", map[disk->id].device); - close (fd); return grub_errno; } From 6f332153941293db9cb28ecb4cbe323f94134d82 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 3 Apr 2011 15:57:44 +0200 Subject: [PATCH 394/869] * grub-core/disk/lvm.c (grub_lvm_scan_device): Print errors on the end of function to allow further scanning for LVMs. --- ChangeLog | 5 +++++ grub-core/disk/lvm.c | 1 + 2 files changed, 6 insertions(+) diff --git a/ChangeLog b/ChangeLog index 88a8a7f69..fc6dee2ce 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-04-02 Vladimir Serbinenko + + * grub-core/disk/lvm.c (grub_lvm_scan_device): Print errors on the end + of function to allow further scanning for LVMs. + 2011-04-02 Vladimir Serbinenko * grub-core/kern/emu/hostdisk.c (grub_util_biosdisk_read): Don't close diff --git a/grub-core/disk/lvm.c b/grub-core/disk/lvm.c index 5a79063da..6b6417f38 100644 --- a/grub-core/disk/lvm.c +++ b/grub-core/disk/lvm.c @@ -838,6 +838,7 @@ grub_lvm_scan_device (const char *name) grub_disk_close (disk); if (grub_errno == GRUB_ERR_OUT_OF_RANGE) grub_errno = GRUB_ERR_NONE; + grub_print_error (); return 0; } From 850e937329ab9da72cca06efeb1c10ec2e996a42 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 3 Apr 2011 16:28:14 +0200 Subject: [PATCH 395/869] Increase LVM implementation robustness in order not to crash on configurations like pvmove. Previously code assumed that in some places only lvs or only pvs are used whereas it seems that they are used interchangeably. * grub-core/disk/lvm.c (read_node): New function. (read_lv): Use read_node. (grub_lvm_scan_device): Use only first mirror on pvmove'd lvs. Match volumes only at the end when all lvs are found. Take both pvs (first) and lvs (second) into account. * include/grub/lvm.h (grub_lvm_segment): Merge fields stripe_* and mirror_* into node_*. All users updated. (grub_lvm_stripe): Merge this ... (grub_lvm_mirror): ... and this ... (grub_lvm_node): ... into this. All users updated. --- ChangeLog | 18 ++++++ grub-core/disk/lvm.c | 144 ++++++++++++++++++++++++------------------- include/grub/lvm.h | 15 ++--- 3 files changed, 103 insertions(+), 74 deletions(-) diff --git a/ChangeLog b/ChangeLog index fc6dee2ce..667daad65 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,21 @@ +2011-04-02 Vladimir Serbinenko + + Increase LVM implementation robustness in order not to crash on + configurations like pvmove. Previously code assumed that in some places + only lvs or only pvs are used whereas it seems that they are used + interchangeably. + + * grub-core/disk/lvm.c (read_node): New function. + (read_lv): Use read_node. + (grub_lvm_scan_device): Use only first mirror on pvmove'd lvs. + Match volumes only at the end when all lvs are found. Take both + pvs (first) and lvs (second) into account. + * include/grub/lvm.h (grub_lvm_segment): Merge fields stripe_* and + mirror_* into node_*. All users updated. + (grub_lvm_stripe): Merge this ... + (grub_lvm_mirror): ... and this ... + (grub_lvm_node): ... into this. All users updated. + 2011-04-02 Vladimir Serbinenko * grub-core/disk/lvm.c (grub_lvm_scan_device): Print errors on the end diff --git a/grub-core/disk/lvm.c b/grub-core/disk/lvm.c index 6b6417f38..00c6d8f9b 100644 --- a/grub-core/disk/lvm.c +++ b/grub-core/disk/lvm.c @@ -165,6 +165,31 @@ grub_lvm_close (grub_disk_t disk __attribute ((unused))) return; } +static grub_err_t +read_lv (struct grub_lvm_lv *lv, grub_disk_addr_t sector, + grub_size_t size, char *buf); + +static grub_err_t +read_node (const struct grub_lvm_node *node, grub_disk_addr_t sector, + grub_size_t size, char *buf) +{ + /* Check whether we actually know the physical volume we want to + read from. */ + if (node->pv) + { + if (node->pv->disk) + return grub_disk_read (node->pv->disk, sector + node->pv->start, 0, + size << GRUB_DISK_SECTOR_BITS, buf); + else + return grub_error (GRUB_ERR_UNKNOWN_DEVICE, + "physical volume %s not found", node->pv->name); + + } + if (node->lv) + return read_lv (node->lv, sector, size, buf); + return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "unknown node '%s'", node->name); +} + static grub_err_t read_lv (struct grub_lvm_lv *lv, grub_disk_addr_t sector, grub_size_t size, char *buf) @@ -172,7 +197,7 @@ read_lv (struct grub_lvm_lv *lv, grub_disk_addr_t sector, grub_err_t err = 0; struct grub_lvm_vg *vg = lv->vg; struct grub_lvm_segment *seg = lv->segments; - struct grub_lvm_pv *pv; + struct grub_lvm_node *node; grub_uint64_t offset; grub_uint64_t extent; unsigned int i; @@ -200,17 +225,17 @@ read_lv (struct grub_lvm_lv *lv, grub_disk_addr_t sector, switch (seg->type) { case GRUB_LVM_STRIPED: - if (seg->stripe_count == 1) + if (seg->node_count == 1) { /* This segment is linear, so that's easy. We just need to find out the offset in the physical volume and read SIZE bytes from that. */ - struct grub_lvm_stripe *stripe = seg->stripes; + struct grub_lvm_node *stripe = seg->nodes; grub_uint64_t seg_offset; /* Offset of the segment in PV device. */ - pv = stripe->pv; + node = stripe; seg_offset = ((grub_uint64_t) stripe->start - * (grub_uint64_t) vg->extent_size) + pv->start; + * (grub_uint64_t) vg->extent_size); offset = sector - ((grub_uint64_t) seg->start_extent * (grub_uint64_t) vg->extent_size) + seg_offset; @@ -219,7 +244,7 @@ read_lv (struct grub_lvm_lv *lv, grub_disk_addr_t sector, { /* This is a striped segment. We have to find the right PV similar to RAID0. */ - struct grub_lvm_stripe *stripe = seg->stripes; + struct grub_lvm_node *stripe = seg->nodes; grub_uint32_t a, b; grub_uint64_t seg_offset; /* Offset of the segment in PV device. */ unsigned int stripenr; @@ -228,42 +253,29 @@ read_lv (struct grub_lvm_lv *lv, grub_disk_addr_t sector, * (grub_uint64_t) vg->extent_size); a = grub_divmod64 (offset, seg->stripe_size, NULL); - grub_divmod64 (a, seg->stripe_count, &stripenr); + grub_divmod64 (a, seg->node_count, &stripenr); - a = grub_divmod64 (offset, seg->stripe_size * seg->stripe_count, NULL); + a = grub_divmod64 (offset, seg->stripe_size * seg->node_count, NULL); grub_divmod64 (offset, seg->stripe_size, &b); offset = a * seg->stripe_size + b; stripe += stripenr; - pv = stripe->pv; + node = stripe; seg_offset = ((grub_uint64_t) stripe->start - * (grub_uint64_t) vg->extent_size) + pv->start; + * (grub_uint64_t) vg->extent_size); offset += seg_offset; } - /* Check whether we actually know the physical volume we want to - read from. */ - if (pv->disk) - err = grub_disk_read (pv->disk, offset, 0, - size << GRUB_DISK_SECTOR_BITS, buf); - else - err = grub_error (GRUB_ERR_UNKNOWN_DEVICE, - "physical volume %s not found", pv->name); - - return err; + return read_node (node, offset, size, buf); case GRUB_LVM_MIRROR: i = 0; while (1) { - if (!seg->mirrors[i].lv) - err = grub_error (GRUB_ERR_UNKNOWN_DEVICE, "unknown volume '%s'", - seg->mirrors[i].lvname); - else - err = read_lv (seg->mirrors[i].lv, sector, size, buf); + err = read_node (&seg->nodes[i], sector, size, buf); if (!err) return err; - if (++i >= seg->mirror_count) + if (++i >= seg->node_count) return err; grub_errno = GRUB_ERR_NONE; } @@ -544,6 +556,7 @@ grub_lvm_scan_device (const char *name) int skip_lv = 0; struct grub_lvm_lv *lv; struct grub_lvm_segment *seg; + int is_pvmove; while (grub_isspace (*p)) p++; @@ -567,6 +580,7 @@ grub_lvm_scan_device (const char *name) lv->size = 0; lv->visible = grub_lvm_check_flag (p, "status", "VISIBLE"); + is_pvmove = grub_lvm_check_flag (p, "status", "PVMOVE"); lv->segment_count = grub_lvm_getvalue (&p, "segment_count = "); if (p == NULL) @@ -618,10 +632,10 @@ grub_lvm_scan_device (const char *name) if (grub_memcmp (p, "striped\"", sizeof ("striped\"") - 1) == 0) { - struct grub_lvm_stripe *stripe; + struct grub_lvm_node *stripe; seg->type = GRUB_LVM_STRIPED; - seg->stripe_count = grub_lvm_getvalue (&p, "stripe_count = "); + seg->node_count = grub_lvm_getvalue (&p, "stripe_count = "); if (p == NULL) { #ifdef GRUB_UTIL @@ -630,12 +644,12 @@ grub_lvm_scan_device (const char *name) goto lvs_segment_fail; } - if (seg->stripe_count != 1) + if (seg->node_count != 1) seg->stripe_size = grub_lvm_getvalue (&p, "stripe_size = "); - seg->stripes = grub_malloc (sizeof (*stripe) - * seg->stripe_count); - stripe = seg->stripes; + seg->nodes = grub_zalloc (sizeof (*stripe) + * seg->node_count); + stripe = seg->nodes; p = grub_strstr (p, "stripes = ["); if (p == NULL) @@ -647,10 +661,8 @@ grub_lvm_scan_device (const char *name) } p += sizeof("stripes = [") - 1; - for (j = 0; j < seg->stripe_count; j++) + for (j = 0; j < seg->node_count; j++) { - char *pvname; - p = grub_strchr (p, '"'); if (p == NULL) continue; @@ -660,24 +672,12 @@ grub_lvm_scan_device (const char *name) s = q - p; - pvname = grub_malloc (s + 1); - if (pvname == NULL) + stripe->name = grub_malloc (s + 1); + if (stripe->name == NULL) goto lvs_segment_fail2; - grub_memcpy (pvname, p, s); - pvname[s] = '\0'; - - if (vg->pvs) - for (pv = vg->pvs; pv; pv = pv->next) - { - if (! grub_strcmp (pvname, pv->name)) - { - stripe->pv = pv; - break; - } - } - - grub_free(pvname); + grub_memcpy (stripe->name, p, s); + stripe->name[s] = '\0'; stripe->start = grub_lvm_getvalue (&p, ","); if (p == NULL) @@ -690,7 +690,7 @@ grub_lvm_scan_device (const char *name) == 0) { seg->type = GRUB_LVM_MIRROR; - seg->mirror_count = grub_lvm_getvalue (&p, "mirror_count = "); + seg->node_count = grub_lvm_getvalue (&p, "mirror_count = "); if (p == NULL) { #ifdef GRUB_UTIL @@ -699,8 +699,8 @@ grub_lvm_scan_device (const char *name) goto lvs_segment_fail; } - seg->mirrors = grub_zalloc (sizeof (seg->mirrors[0]) - * seg->mirror_count); + seg->nodes = grub_zalloc (sizeof (seg->nodes[0]) + * seg->node_count); p = grub_strstr (p, "mirrors = ["); if (p == NULL) @@ -712,7 +712,7 @@ grub_lvm_scan_device (const char *name) } p += sizeof("mirrors = [") - 1; - for (j = 0; j < seg->mirror_count; j++) + for (j = 0; j < seg->node_count; j++) { char *lvname; @@ -731,9 +731,12 @@ grub_lvm_scan_device (const char *name) grub_memcpy (lvname, p, s); lvname[s] = '\0'; - seg->mirrors[j].lvname = lvname; + seg->nodes[j].name = lvname; p = q + 1; } + /* Only first (original) is ok with in progress pvmove. */ + if (is_pvmove) + seg->node_count = 1; } else { @@ -755,7 +758,7 @@ grub_lvm_scan_device (const char *name) continue; lvs_segment_fail2: - grub_free (seg->stripes); + grub_free (seg->nodes); lvs_segment_fail: goto fail4; } @@ -786,18 +789,31 @@ grub_lvm_scan_device (const char *name) } } - /* Match mirrors */ + /* Match lvs. */ { struct grub_lvm_lv *lv1; struct grub_lvm_lv *lv2; for (lv1 = vg->lvs; lv1; lv1 = lv1->next) for (i = 0; i < lv1->segment_count; i++) - if (lv1->segments[i].type == GRUB_LVM_MIRROR) - for (j = 0; j < lv1->segments[i].mirror_count; j++) - for (lv2 = vg->lvs; lv2; lv2 = lv2->next) - if (grub_strcmp (lv2->name + grub_strlen (vg->name) + 1, - lv1->segments[i].mirrors[j].lvname) == 0) - lv1->segments[i].mirrors[j].lv = lv2; + for (j = 0; j < lv1->segments[i].node_count; j++) + { + if (vg->pvs) + for (pv = vg->pvs; pv; pv = pv->next) + { + if (! grub_strcmp (pv->name, + lv1->segments[i].nodes[j].name)) + { + lv1->segments[i].nodes[j].pv = pv; + break; + } + } + if (lv1->segments[i].nodes[j].pv == NULL) + for (lv2 = vg->lvs; lv2; lv2 = lv2->next) + if (grub_strcmp (lv2->name + grub_strlen (vg->name) + 1, + lv1->segments[i].nodes[j].name) == 0) + lv1->segments[i].nodes[j].lv = lv2; + } + } vg->next = vg_list; diff --git a/include/grub/lvm.h b/include/grub/lvm.h index 220517183..b962dfd6c 100644 --- a/include/grub/lvm.h +++ b/include/grub/lvm.h @@ -60,21 +60,16 @@ struct grub_lvm_segment { unsigned int extent_count; enum { GRUB_LVM_STRIPED, GRUB_LVM_MIRROR } type; - unsigned int mirror_count; - struct grub_lvm_mirror *mirrors; + unsigned int node_count; + struct grub_lvm_node *nodes; - unsigned int stripe_count; unsigned int stripe_size; - struct grub_lvm_stripe *stripes; /* Pointer to stripe_count stripes. */ }; -struct grub_lvm_stripe { - int start; +struct grub_lvm_node { + grub_disk_addr_t start; + char *name; struct grub_lvm_pv *pv; -}; - -struct grub_lvm_mirror { - char *lvname; struct grub_lvm_lv *lv; }; From 6ac14e6cef8b3dc675fc09239b2101dcc4393a18 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Tue, 5 Apr 2011 09:34:58 +0200 Subject: [PATCH 396/869] Fix EFI compilation --- grub-core/disk/efi/efidisk.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/grub-core/disk/efi/efidisk.c b/grub-core/disk/efi/efidisk.c index 20fea956f..1bf764f10 100644 --- a/grub-core/disk/efi/efidisk.c +++ b/grub-core/disk/efi/efidisk.c @@ -537,11 +537,11 @@ grub_efidisk_open (const char *name, struct grub_disk *disk) grub_dprintf ("efidisk", "m = %p, last block = %llx, block size = %x\n", m, (unsigned long long) m->last_block, m->block_size); disk->total_sectors = m->last_block; - if (m->blocksize & (m->blocksize - 1) || !m->blocksize) + if (m->block_size & (m->block_size - 1) || !m->block_size) return grub_error (GRUB_ERR_IO, "invalid sector size %d", - m->blocksize); + m->block_size); for (disk->log_sector_size = 0; - (1 << disk->log_sector_size) < m->blocksize; + (1U << disk->log_sector_size) < m->block_size; disk->log_sector_size++); disk->data = d; From b38a4983949bbf66a7ecdae3423b2401ce2e635f Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Tue, 5 Apr 2011 14:40:15 +0200 Subject: [PATCH 397/869] BPB patching support (untested) --- grub-core/fs/fat.c | 47 +------------ grub-core/loader/i386/pc/chainloader.c | 91 ++++++++++++++++++++++++-- grub-core/loader/i386/pc/ntldr.c | 2 + grub-core/normal/main.c | 3 + include/grub/i386/pc/chainloader.h | 7 +- include/grub/ntfs.h | 8 ++- 6 files changed, 99 insertions(+), 59 deletions(-) diff --git a/grub-core/fs/fat.c b/grub-core/fs/fat.c index 89050943c..7906cf1b2 100644 --- a/grub-core/fs/fat.c +++ b/grub-core/fs/fat.c @@ -26,6 +26,7 @@ #include #include #include +#include #define GRUB_FAT_DIR_ENTRY_SIZE 32 @@ -49,52 +50,6 @@ | GRUB_FAT_ATTR_ARCHIVE \ | GRUB_FAT_ATTR_VOLUME_ID) -struct grub_fat_bpb -{ - grub_uint8_t jmp_boot[3]; - grub_uint8_t oem_name[8]; - grub_uint16_t bytes_per_sector; - grub_uint8_t sectors_per_cluster; - grub_uint16_t num_reserved_sectors; - grub_uint8_t num_fats; - grub_uint16_t num_root_entries; - grub_uint16_t num_total_sectors_16; - grub_uint8_t media; - grub_uint16_t sectors_per_fat_16; - grub_uint16_t sectors_per_track; - grub_uint16_t num_heads; - grub_uint32_t num_hidden_sectors; - grub_uint32_t num_total_sectors_32; - union - { - struct - { - grub_uint8_t num_ph_drive; - grub_uint8_t reserved; - grub_uint8_t boot_sig; - grub_uint32_t num_serial; - grub_uint8_t label[11]; - grub_uint8_t fstype[8]; - } __attribute__ ((packed)) fat12_or_fat16; - struct - { - grub_uint32_t sectors_per_fat_32; - grub_uint16_t extended_flags; - grub_uint16_t fs_version; - grub_uint32_t root_cluster; - grub_uint16_t fs_info; - grub_uint16_t backup_boot_sector; - grub_uint8_t reserved[12]; - grub_uint8_t num_ph_drive; - grub_uint8_t reserved1; - grub_uint8_t boot_sig; - grub_uint32_t num_serial; - grub_uint8_t label[11]; - grub_uint8_t fstype[8]; - } __attribute__ ((packed)) fat32; - } __attribute__ ((packed)) version_specific; -} __attribute__ ((packed)); - struct grub_fat_dir_entry { grub_uint8_t name[11]; diff --git a/grub-core/loader/i386/pc/chainloader.c b/grub-core/loader/i386/pc/chainloader.c index fd99c81d5..174e5b7a5 100644 --- a/grub-core/loader/i386/pc/chainloader.c +++ b/grub-core/loader/i386/pc/chainloader.c @@ -37,11 +37,19 @@ #include #include #include +#include +#include static grub_dl_t my_mod; static int boot_drive; static void *boot_part_addr; +typedef enum + { + GRUB_CHAINLOADER_FORCE = 0x1, + GRUB_CHAINLOADER_BPB = 0x2, + } grub_chainloader_flags_t; + static grub_err_t grub_chainloader_boot (void) { @@ -59,6 +67,63 @@ grub_chainloader_unload (void) return GRUB_ERR_NONE; } +void +grub_chainloader_patch_bpb (void *bs, grub_device_t dev, grub_uint8_t dl) +{ + grub_uint32_t part_start = 0; + if (dev && dev->disk) + part_start = grub_partition_get_start (dev->disk->partition); + if (grub_memcmp ((char *) &((struct grub_ntfs_bpb *) bs)->oem_name, + "NTFS", 4) == 0) + { + struct grub_ntfs_bpb *bpb = (struct grub_ntfs_bpb *) bs; + bpb->num_hidden_sectors = grub_cpu_to_le32 (part_start); + bpb->bios_drive = dl; + return; + } + + do + { + struct grub_fat_bpb *bpb = (struct grub_fat_bpb *) bs; + if (grub_strncmp((const char *) bpb->version_specific.fat12_or_fat16.fstype, "FAT12", 5) + && grub_strncmp((const char *) bpb->version_specific.fat12_or_fat16.fstype, "FAT16", 5) + && grub_strncmp((const char *) bpb->version_specific.fat32.fstype, "FAT32", 5)) + break; + + if (grub_le_to_cpu16 (bpb->bytes_per_sector) < 512 + || (grub_le_to_cpu16 (bpb->bytes_per_sector) + & (grub_le_to_cpu16 (bpb->bytes_per_sector) - 1))) + break; + + if (bpb->sectors_per_cluster == 0 + || (bpb->sectors_per_cluster & (bpb->sectors_per_cluster - 1))) + break; + + if (bpb->num_reserved_sectors == 0) + break; + if (bpb->num_total_sectors_16 == 0 || bpb->num_total_sectors_32 == 0) + break; + + if (bpb->num_fats == 0) + break; + + if (bpb->sectors_per_fat_16) + { + bpb->num_hidden_sectors = grub_cpu_to_le32 (part_start); + bpb->version_specific.fat12_or_fat16.num_ph_drive = dl; + return; + } + if (bpb->version_specific.fat32.sectors_per_fat_32) + { + bpb->num_hidden_sectors = grub_cpu_to_le32 (part_start); + bpb->version_specific.fat32.num_ph_drive = dl; + return; + } + break; + } + while (0); +} + static void grub_chainloader_cmd (const char *filename, grub_chainloader_flags_t flags) { @@ -119,6 +184,9 @@ grub_chainloader_cmd (const char *filename, grub_chainloader_flags_t flags) } } + if (flags & GRUB_CHAINLOADER_BPB) + grub_chainloader_patch_bpb ((void *) 0x7C00, dev, drive); + if (dev) grub_device_close (dev); @@ -145,11 +213,23 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)), { grub_chainloader_flags_t flags = 0; - if (argc > 0 && grub_strcmp (argv[0], "--force") == 0) + while (argc > 0) { - flags |= GRUB_CHAINLOADER_FORCE; - argc--; - argv++; + if (grub_strcmp (argv[0], "--force") == 0) + { + flags |= GRUB_CHAINLOADER_FORCE; + argc--; + argv++; + continue; + } + if (grub_strcmp (argv[0], "--bpb") == 0) + { + flags |= GRUB_CHAINLOADER_BPB; + argc--; + argv++; + continue; + } + break; } if (argc == 0) @@ -165,7 +245,8 @@ static grub_command_t cmd; GRUB_MOD_INIT(chainloader) { cmd = grub_register_command ("chainloader", grub_cmd_chainloader, - 0, N_("Load another boot loader.")); + "[--force|--bpb] FILE", + N_("Load another boot loader.")); my_mod = mod; } diff --git a/grub-core/loader/i386/pc/ntldr.c b/grub-core/loader/i386/pc/ntldr.c index 0c33a0680..9649cdfbe 100644 --- a/grub-core/loader/i386/pc/ntldr.c +++ b/grub-core/loader/i386/pc/ntldr.c @@ -32,6 +32,7 @@ #include #include #include +#include static grub_dl_t my_mod; static struct grub_relocator *rel; @@ -110,6 +111,7 @@ grub_cmd_ntldr (grub_command_t cmd __attribute__ ((unused)), grub_device_close (dev); goto fail; } + grub_chainloader_patch_bpb (bs, dev, edx); } if (dev) diff --git a/grub-core/normal/main.c b/grub-core/normal/main.c index cefb1cb9b..c04accb6d 100644 --- a/grub-core/normal/main.c +++ b/grub-core/normal/main.c @@ -515,6 +515,9 @@ GRUB_MOD_INIT(normal) /* Set default color names. */ grub_env_set ("color_normal", "white/black"); grub_env_set ("color_highlight", "black/white"); + + grub_env_set ("grub_feature_chainloader_bpb", "--bpb"); + grub_env_export ("grub_feature_chainloader_bpb"); } GRUB_MOD_FINI(normal) diff --git a/include/grub/i386/pc/chainloader.h b/include/grub/i386/pc/chainloader.h index ca1da23a7..4776b181b 100644 --- a/include/grub/i386/pc/chainloader.h +++ b/include/grub/i386/pc/chainloader.h @@ -21,10 +21,7 @@ #include -/* Common function for normal and rescue mode commands. */ -typedef enum - { - GRUB_CHAINLOADER_FORCE = 0x1 - } grub_chainloader_flags_t; +void +grub_chainloader_patch_bpb (void *bs, grub_device_t dev, grub_uint8_t dl); #endif /* GRUB_CHAINLOADER_MACHINE_HEADER */ diff --git a/include/grub/ntfs.h b/include/grub/ntfs.h index 31b99398b..9e2e34707 100644 --- a/include/grub/ntfs.h +++ b/include/grub/ntfs.h @@ -106,14 +106,16 @@ struct grub_ntfs_bpb grub_uint16_t sectors_per_track; grub_uint16_t num_heads; grub_uint32_t num_hidden_sectors; - grub_uint32_t reserved_3[2]; + grub_uint32_t reserved_3; + grub_uint8_t bios_drive; + grub_uint8_t reserved_4[3]; grub_uint64_t num_total_sectors; grub_uint64_t mft_lcn; grub_uint64_t mft_mirr_lcn; grub_int8_t clusters_per_mft; - grub_int8_t reserved_4[3]; - grub_int8_t clusters_per_index; grub_int8_t reserved_5[3]; + grub_int8_t clusters_per_index; + grub_int8_t reserved_6[3]; grub_uint64_t num_serial; grub_uint32_t checksum; } __attribute__ ((packed)); From 5bfb6e71e8c3d189cc55542239a01794096344bb Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Tue, 5 Apr 2011 15:05:53 +0200 Subject: [PATCH 398/869] features support --- grub-core/normal/main.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/grub-core/normal/main.c b/grub-core/normal/main.c index c04accb6d..fa20d0d78 100644 --- a/grub-core/normal/main.c +++ b/grub-core/normal/main.c @@ -471,9 +471,14 @@ grub_mini_cmd_clear (struct grub_command *cmd __attribute__ ((unused)), static grub_command_t cmd_clear; static void (*grub_xputs_saved) (const char *str); +static const char *features[] = { + "feature_chainloader_bpb", "feature_ntldr" +}; GRUB_MOD_INIT(normal) { + unsigned i; + /* Previously many modules depended on gzio. Be nice to user and load it. */ grub_dl_load ("gzio"); @@ -516,8 +521,11 @@ GRUB_MOD_INIT(normal) grub_env_set ("color_normal", "white/black"); grub_env_set ("color_highlight", "black/white"); - grub_env_set ("grub_feature_chainloader_bpb", "--bpb"); - grub_env_export ("grub_feature_chainloader_bpb"); + for (i = 0; i < ARRAY_SIZE (features); i++) + { + grub_env_set (features[i], "y"); + grub_env_export (features[i]); + } } GRUB_MOD_FINI(normal) From 246c23696a24dd3e971a9b29b7ee25c905d6ba63 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 6 Apr 2011 12:25:33 +0200 Subject: [PATCH 399/869] Ignore docs/stamp-1 and docs/version-dev.texi --- .bzrignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.bzrignore b/.bzrignore index a3e6f9dd2..55cbdaeeb 100644 --- a/.bzrignore +++ b/.bzrignore @@ -133,3 +133,5 @@ grub-core/gnulib/wctype.h grub-core/rs_decoder.S widthspec.bin widthspec.h +docs/stamp-1 +docs/version-dev.texi From a562b47916eef29b39ed23115b7bf9af6e3bd179 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 6 Apr 2011 12:29:49 +0200 Subject: [PATCH 400/869] * grub-core/disk/mdraid1x_linux.c (grub_mdraid_detect): Detect spares and report them as not RAID members since they are useless for GRUB. * grub-core/disk/mdraid_linux.c (grub_mdraid_detect): Likewise. --- ChangeLog | 6 ++++++ grub-core/disk/mdraid1x_linux.c | 5 ++++- grub-core/disk/mdraid_linux.c | 2 +- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 667daad65..81ba177d5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2011-04-06 Vladimir Serbinenko + + * grub-core/disk/mdraid1x_linux.c (grub_mdraid_detect): Detect spares + and report them as not RAID members since they are useless for GRUB. + * grub-core/disk/mdraid_linux.c (grub_mdraid_detect): Likewise. + 2011-04-02 Vladimir Serbinenko Increase LVM implementation robustness in order not to crash on diff --git a/grub-core/disk/mdraid1x_linux.c b/grub-core/disk/mdraid1x_linux.c index 1d08abf5b..e30878365 100644 --- a/grub-core/disk/mdraid1x_linux.c +++ b/grub-core/disk/mdraid1x_linux.c @@ -200,11 +200,14 @@ grub_mdraid_detect (grub_disk_t disk, struct grub_raid_array *array, if (grub_le_to_cpu32 (real_sb->dev_number) >= grub_le_to_cpu32 (real_sb->max_dev)) - return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, + return grub_error (GRUB_ERR_OUT_OF_RANGE, "spares aren't implemented"); array->index = grub_le_to_cpu16 (real_sb->dev_roles[grub_le_to_cpu32 (real_sb->dev_number)]); + if (array->index >= array->total_devs) + return grub_error (GRUB_ERR_OUT_OF_RANGE, + "spares aren't implemented"); array->uuid_len = 16; array->uuid = grub_malloc (16); if (!array->uuid) diff --git a/grub-core/disk/mdraid_linux.c b/grub-core/disk/mdraid_linux.c index 7aa48fd7a..06d3498a8 100644 --- a/grub-core/disk/mdraid_linux.c +++ b/grub-core/disk/mdraid_linux.c @@ -202,7 +202,7 @@ grub_mdraid_detect (grub_disk_t disk, struct grub_raid_array *array, "unsupported RAID level: %d", level); if (grub_le_to_cpu32 (sb.this_disk.number) == 0xffff || grub_le_to_cpu32 (sb.this_disk.number) == 0xfffe) - return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, + return grub_error (GRUB_ERR_OUT_OF_RANGE, "spares aren't implemented"); array->name = NULL; From 665900a3892d554c7bcafdfefcff027da35ad709 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 6 Apr 2011 12:33:46 +0200 Subject: [PATCH 401/869] * include/grub/offsets.h (GRUB_KERNEL_I386_PC_RAW_SIZE): Let a bit more space for older compilers. (GRUB_KERNEL_I386_PC_NO_REED_SOLOMON_PART): Likewise. --- ChangeLog | 6 ++++++ include/grub/offsets.h | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 81ba177d5..a657807bd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2011-04-06 Vladimir Serbinenko + + * include/grub/offsets.h (GRUB_KERNEL_I386_PC_RAW_SIZE): Let a bit more + space for older compilers. + (GRUB_KERNEL_I386_PC_NO_REED_SOLOMON_PART): Likewise. + 2011-04-06 Vladimir Serbinenko * grub-core/disk/mdraid1x_linux.c (grub_mdraid_detect): Detect spares diff --git a/include/grub/offsets.h b/include/grub/offsets.h index 817372b69..31deb5031 100644 --- a/include/grub/offsets.h +++ b/include/grub/offsets.h @@ -38,9 +38,9 @@ #define GRUB_KERNEL_I386_PC_REED_SOLOMON_REDUNDANCY 0x1c /* The size of the first region which won't be compressed. */ -#define GRUB_KERNEL_I386_PC_RAW_SIZE 0xca4 +#define GRUB_KERNEL_I386_PC_RAW_SIZE 0xcd0 -#define GRUB_KERNEL_I386_PC_NO_REED_SOLOMON_PART 0x70c +#define GRUB_KERNEL_I386_PC_NO_REED_SOLOMON_PART 0x730 /* The offset of GRUB_PREFIX. */ #define GRUB_KERNEL_I386_PC_PREFIX GRUB_KERNEL_I386_PC_RAW_SIZE From adf594cc44418f7d3e7801b677c73ed93b848129 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 6 Apr 2011 13:00:18 +0200 Subject: [PATCH 402/869] Output errors if theme loading failed. * grub-core/gfxmenu/gfxmenu.c (grub_gfxmenu_try): Move the call to grub_gfxterm_fullscreen on error paths to ... * grub-core/normal/menu.c (menu_init): ...here. Wait after showing theme loading error. --- ChangeLog | 9 ++++++++ grub-core/gfxmenu/gfxmenu.c | 24 +++------------------- grub-core/normal/menu.c | 41 ++++++++++++++++++++++++++++++------- 3 files changed, 46 insertions(+), 28 deletions(-) diff --git a/ChangeLog b/ChangeLog index a657807bd..891853f71 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2011-04-06 Vladimir Serbinenko + + Output errors if theme loading failed. + + * grub-core/gfxmenu/gfxmenu.c (grub_gfxmenu_try): Move the call to + grub_gfxterm_fullscreen on error paths to ... + * grub-core/normal/menu.c (menu_init): ...here. Wait after showing + theme loading error. + 2011-04-06 Vladimir Serbinenko * include/grub/offsets.h (GRUB_KERNEL_I386_PC_RAW_SIZE): Let a bit more diff --git a/grub-core/gfxmenu/gfxmenu.c b/grub-core/gfxmenu/gfxmenu.c index 76d83c44b..564a87634 100644 --- a/grub-core/gfxmenu/gfxmenu.c +++ b/grub-core/gfxmenu/gfxmenu.c @@ -56,30 +56,15 @@ grub_gfxmenu_try (int entry, grub_menu_t menu, int nested) theme_path = grub_env_get ("theme"); if (! theme_path) - { - grub_error_push (); - grub_gfxterm_fullscreen (); - grub_error_pop (); - return grub_error (GRUB_ERR_FILE_NOT_FOUND, "no theme specified"); - } + return grub_error (GRUB_ERR_FILE_NOT_FOUND, "no theme specified"); instance = grub_zalloc (sizeof (*instance)); if (!instance) - { - grub_error_push (); - grub_gfxterm_fullscreen (); - grub_error_pop (); - return grub_errno; - } + return grub_errno; err = grub_video_get_info (&mode_info); if (err) - { - grub_error_push (); - grub_gfxterm_fullscreen (); - grub_error_pop (); - return err; - } + return err; if (!cached_view || grub_strcmp (cached_view->theme_path, theme_path) != 0 || cached_view->screen.width != mode_info.width @@ -94,9 +79,6 @@ grub_gfxmenu_try (int entry, grub_menu_t menu, int nested) if (! cached_view) { grub_free (instance); - grub_error_push (); - grub_gfxterm_fullscreen (); - grub_error_pop (); return grub_errno; } diff --git a/grub-core/normal/menu.c b/grub-core/normal/menu.c index e62482122..bfcdd0ac5 100644 --- a/grub-core/normal/menu.c +++ b/grub-core/normal/menu.c @@ -30,6 +30,7 @@ #include #include #include +#include /* Time to delay after displaying an error message about a default/fallback entry failing to boot. */ @@ -345,18 +346,44 @@ static void menu_init (int entry, grub_menu_t menu, int nested) { struct grub_term_output *term; + int gfxmenu = 0; + + FOR_ACTIVE_TERM_OUTPUTS(term) + if (grub_strcmp (term->name, "gfxterm") == 0) + { + if (grub_env_get ("theme")) + { + if (!grub_gfxmenu_try_hook) + { + grub_dl_load ("gfxmenu"); + grub_print_error (); + } + if (grub_gfxmenu_try_hook) + { + grub_err_t err; + err = grub_gfxmenu_try_hook (entry, menu, nested); + if(!err) + { + gfxmenu = 1; + break; + } + } + else + grub_error (GRUB_ERR_BAD_MODULE, "no gfxmenu found"); + grub_print_error (); + grub_wait_after_message (); + } + grub_errno = GRUB_ERR_NONE; + grub_gfxterm_fullscreen (); + break; + } FOR_ACTIVE_TERM_OUTPUTS(term) { grub_err_t err; - if (grub_gfxmenu_try_hook && grub_strcmp (term->name, "gfxterm") == 0) - { - err = grub_gfxmenu_try_hook (entry, menu, nested); - if(!err) - continue; - grub_errno = GRUB_ERR_NONE; - } + if (grub_strcmp (term->name, "gfxterm") == 0 && gfxmenu) + break; err = grub_menu_try_text (term, entry, menu, nested); if(!err) From 2a961775e6ef522a47eaf898806d2f5de785e46e Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 6 Apr 2011 13:18:11 +0200 Subject: [PATCH 403/869] * util/grub.d/00_header.in: Don't use LANG unless unifont is available. --- ChangeLog | 4 ++++ util/grub.d/00_header.in | 23 +++++++++++++---------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/ChangeLog b/ChangeLog index 891853f71..bc9318701 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2011-04-06 Vladimir Serbinenko + + * util/grub.d/00_header.in: Don't use LANG unless unifont is available. + 2011-04-06 Vladimir Serbinenko Output errors if theme loading failed. diff --git a/util/grub.d/00_header.in b/util/grub.d/00_header.in index 420b3f32c..9da1511f5 100644 --- a/util/grub.d/00_header.in +++ b/util/grub.d/00_header.in @@ -132,6 +132,19 @@ if loadfont `make_system_path_relative_to_its_root "${GRUB_FONT_PATH}"` ; then set gfxmode=${GRUB_GFXMODE} load_video insmod gfxterm +EOF + +# Gettext variables and module +if [ "x${LANG}" != "xC" ] && [ -d "${locale_dir}" ] ; then + prepare_grub_to_access_device $(${grub_probe} --target=device ${locale_dir}) | sed -e "s/^/ /" + cat << EOF + set locale_dir=(\$root)$(make_system_path_relative_to_its_root ${locale_dir}) + set lang=${grub_lang} + insmod gettext +EOF +fi + +cat < Date: Wed, 6 Apr 2011 14:01:12 +0200 Subject: [PATCH 404/869] * include/grub/fs.h (grub_dirhook_info): Use unsigned for 1-bit fields. --- ChangeLog | 4 ++++ include/grub/fs.h | 6 +++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index bc9318701..84fcc5627 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2011-04-06 Vladimir Serbinenko + + * include/grub/fs.h (grub_dirhook_info): Use unsigned for 1-bit fields. + 2011-04-06 Vladimir Serbinenko * util/grub.d/00_header.in: Don't use LANG unless unifont is available. diff --git a/include/grub/fs.h b/include/grub/fs.h index 994eb8080..2c39332a9 100644 --- a/include/grub/fs.h +++ b/include/grub/fs.h @@ -31,9 +31,9 @@ struct grub_file; struct grub_dirhook_info { - int dir:1; - int mtimeset:1; - int case_insensitive:1; + unsigned dir:1; + unsigned mtimeset:1; + unsigned case_insensitive:1; grub_int32_t mtime; }; From 7755f66e64f52e4c551c477dcdfd4f4a9fdd8f74 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 6 Apr 2011 14:04:52 +0200 Subject: [PATCH 405/869] * grub-core/lib/relocator.c (grub_relocator_alloc_chunk_align): Add few useful grub_dprintf's. --- ChangeLog | 5 +++++ grub-core/lib/relocator.c | 6 ++++++ 2 files changed, 11 insertions(+) diff --git a/ChangeLog b/ChangeLog index 84fcc5627..b110a9803 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-04-06 Vladimir Serbinenko + + * grub-core/lib/relocator.c (grub_relocator_alloc_chunk_align): Add few + useful grub_dprintf's. + 2011-04-06 Vladimir Serbinenko * include/grub/fs.h (grub_dirhook_info): Use unsigned for 1-bit fields. diff --git a/grub-core/lib/relocator.c b/grub-core/lib/relocator.c index 940b9133b..3642de9dc 100644 --- a/grub-core/lib/relocator.c +++ b/grub-core/lib/relocator.c @@ -1416,11 +1416,17 @@ grub_relocator_alloc_chunk_align (struct grub_relocator *rel, break; } + grub_dprintf ("relocator", "relocators_size=%ld\n", + (unsigned long) rel->relocators_size); + if (chunk->src < chunk->target) rel->relocators_size += grub_relocator_backward_size; if (chunk->src > chunk->target) rel->relocators_size += grub_relocator_forward_size; + grub_dprintf ("relocator", "relocators_size=%ld\n", + (unsigned long) rel->relocators_size); + chunk->size = size; chunk->next = rel->chunks; rel->chunks = chunk; From b5ebecfabc1037532c18b42372218d45b237f192 Mon Sep 17 00:00:00 2001 From: Andrey Date: Wed, 6 Apr 2011 14:21:34 +0200 Subject: [PATCH 406/869] * grub-core/video/fb/video_fb.c (grub_video_fb_setup): Silence older gcc warning. --- ChangeLog | 5 +++++ grub-core/video/fb/video_fb.c | 5 ++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index b110a9803..e495fbf9a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-04-06 Andrey + + * grub-core/video/fb/video_fb.c (grub_video_fb_setup): Silence older + gcc warning. + 2011-04-06 Vladimir Serbinenko * grub-core/lib/relocator.c (grub_relocator_alloc_chunk_align): Add few diff --git a/grub-core/video/fb/video_fb.c b/grub-core/video/fb/video_fb.c index 768b63328..2226d6583 100644 --- a/grub-core/video/fb/video_fb.c +++ b/grub-core/video/fb/video_fb.c @@ -1445,13 +1445,16 @@ grub_video_fb_setup (unsigned int mode_type, unsigned int mode_mask, GRUB_VIDEO_MODE_TYPE_DOUBLE_BUFFERED, 0)) { + /* It was much nicer with the cast directly at function call but + some older gcc versions don't accept it properly.*/ + void *tmp = (void *) page0_ptr; mode_info->mode_type |= (GRUB_VIDEO_MODE_TYPE_DOUBLE_BUFFERED | GRUB_VIDEO_MODE_TYPE_UPDATING_SWAP); err = grub_video_fb_doublebuf_blit_init (&framebuffer.front_target, &framebuffer.back_target, *mode_info, - (void *) page0_ptr); + tmp); if (!err) { From 72a89a54e170ccccf0dd6bd83aaba16692a19ebc Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 8 Apr 2011 11:44:44 +0200 Subject: [PATCH 407/869] * grub-core/kern/emu/getroot.c (grub_util_get_grub_dev): Add missing const attribute and use grub_isdigit. --- ChangeLog | 5 +++++ grub-core/kern/emu/getroot.c | 6 +++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index e495fbf9a..1c4bbb5ab 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-04-08 Vladimir Serbinenko + + * grub-core/kern/emu/getroot.c (grub_util_get_grub_dev): Add missing + const attribute and use grub_isdigit. + 2011-04-06 Andrey * grub-core/video/fb/video_fb.c (grub_video_fb_setup): Silence older diff --git a/grub-core/kern/emu/getroot.c b/grub-core/kern/emu/getroot.c index ae066d2f8..8f65d92c5 100644 --- a/grub-core/kern/emu/getroot.c +++ b/grub-core/kern/emu/getroot.c @@ -808,10 +808,10 @@ grub_util_get_grub_dev (const char *os_dev) if (mdadm_name) { char *newname; - char *q; + const char *q; - for (q = os_dev + strlen (os_dev) - 1; q >= os_dev && isdigit (*q); - q--); + for (q = os_dev + strlen (os_dev) - 1; q >= os_dev + && grub_isdigit (*q); q--); if (q >= os_dev && *q == 'p') { From 478182a83841c912996558900469d34832f8bd2e Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 8 Apr 2011 11:49:38 +0200 Subject: [PATCH 408/869] * grub-core/kern/emu/hostdisk.c (open_device): Sync on close and not on open. (grub_util_biosdisk_close): Likewise. --- ChangeLog | 6 ++++++ grub-core/kern/emu/hostdisk.c | 38 ++++++++++++++++++++++++++++------- 2 files changed, 37 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1c4bbb5ab..a9aaa81c1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2011-04-08 Vladimir Serbinenko + + * grub-core/kern/emu/hostdisk.c (open_device): Sync on close and not + on open. + (grub_util_biosdisk_close): Likewise. + 2011-04-08 Vladimir Serbinenko * grub-core/kern/emu/getroot.c (grub_util_get_grub_dev): Add missing diff --git a/grub-core/kern/emu/hostdisk.c b/grub-core/kern/emu/hostdisk.c index 50e5a34ad..7b034e06b 100644 --- a/grub-core/kern/emu/hostdisk.c +++ b/grub-core/kern/emu/hostdisk.c @@ -664,7 +664,17 @@ open_device (const grub_disk_t disk, grub_disk_addr_t sector, int flags) { free (data->dev); if (data->fd != -1) - close (data->fd); + { + if (data->access_mode == O_RDWR || data->access_mode == O_WRONLY) + { + fsync (data->fd); +#ifdef __linux__ + ioctl (data->fd, BLKFLSBUF, 0); +#endif + } + + close (data->fd); + } /* Open the partition. */ grub_dprintf ("hostdisk", "opening the device `%s' in open_device()\n", dev); @@ -675,10 +685,6 @@ open_device (const grub_disk_t disk, grub_disk_addr_t sector, int flags) return -1; } - /* Flush the buffer cache to the physical disk. - XXX: This also empties the buffer cache. */ - ioctl (fd, BLKFLSBUF, 0); - data->dev = xstrdup (dev); data->access_mode = (flags & O_ACCMODE); data->fd = fd; @@ -716,7 +722,16 @@ open_device (const grub_disk_t disk, grub_disk_addr_t sector, int flags) { free (data->dev); if (data->fd != -1) - close (data->fd); + { + if (data->access_mode == O_RDWR || data->access_mode == O_WRONLY) + { + fsync (data->fd); +#ifdef __linux__ + ioctl (data->fd, BLKFLSBUF, 0); +#endif + } + close (data->fd); + } fd = open (map[disk->id].device, flags); if (fd >= 0) @@ -932,7 +947,16 @@ grub_util_biosdisk_close (struct grub_disk *disk) free (data->dev); if (data->fd != -1) - close (data->fd); + { + if (data->access_mode == O_RDWR || data->access_mode == O_WRONLY) + { + fsync (data->fd); +#ifdef __linux__ + ioctl (data->fd, BLKFLSBUF, 0); +#endif + } + close (data->fd); + } free (data); } From 6d1fa41fb413050d4c7fe6c9b224c655e53b4917 Mon Sep 17 00:00:00 2001 From: Martin Zuther Date: Fri, 8 Apr 2011 11:53:17 +0200 Subject: [PATCH 409/869] * util/grub-mkconfig.in: Ignore emacsen backup. --- ChangeLog | 4 ++++ util/grub-mkconfig.in | 2 ++ 2 files changed, 6 insertions(+) diff --git a/ChangeLog b/ChangeLog index a9aaa81c1..cce7aa483 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2011-04-08 Martin Zuther + + * util/grub-mkconfig.in: Ignore emacsen backup. + 2011-04-08 Vladimir Serbinenko * grub-core/kern/emu/hostdisk.c (open_device): Sync on close and not diff --git a/util/grub-mkconfig.in b/util/grub-mkconfig.in index b041a38d7..afc66f886 100644 --- a/util/grub-mkconfig.in +++ b/util/grub-mkconfig.in @@ -280,6 +280,8 @@ for i in ${grub_mkconfig_dir}/* ; do case "$i" in # emacsen backup files. FIXME: support other editors *~) ;; + # emacsen autosave files. FIXME: support other editors + \#*\#) ;; *) if grub_file_is_not_garbage "$i" && test -x "$i" ; then echo From 3c0e3f142abf1f336eccc8fbe27e44062b7bcdfc Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 8 Apr 2011 12:06:55 +0200 Subject: [PATCH 410/869] * grub-core/disk/raid.c [GRUB_UTIL]: Add missing include. --- ChangeLog | 4 ++++ grub-core/disk/raid.c | 3 +++ 2 files changed, 7 insertions(+) diff --git a/ChangeLog b/ChangeLog index cce7aa483..9c2b6a959 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2011-04-08 Vladimir Serbinenko + + * grub-core/disk/raid.c [GRUB_UTIL]: Addmissing include. + 2011-04-08 Martin Zuther * util/grub-mkconfig.in: Ignore emacsen backup. diff --git a/grub-core/disk/raid.c b/grub-core/disk/raid.c index c89ca62a1..ac2b9fefe 100644 --- a/grub-core/disk/raid.c +++ b/grub-core/disk/raid.c @@ -23,6 +23,9 @@ #include #include #include +#ifdef GRUB_UTIL +#include +#endif /* Linked list of RAID arrays. */ static struct grub_raid_array *array_list; From f7148863eb5ae162281d8ff79500dfad77974d08 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 8 Apr 2011 12:12:02 +0200 Subject: [PATCH 411/869] * grub-core/normal/menu.c: Add missing include. --- ChangeLog | 6 +++++- grub-core/normal/menu.c | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 9c2b6a959..7b247ca81 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,10 @@ 2011-04-08 Vladimir Serbinenko - * grub-core/disk/raid.c [GRUB_UTIL]: Addmissing include. + * grub-core/normal/menu.c: Add missing include. + +2011-04-08 Vladimir Serbinenko + + * grub-core/disk/raid.c [GRUB_UTIL]: Add missing include. 2011-04-08 Martin Zuther diff --git a/grub-core/normal/menu.c b/grub-core/normal/menu.c index bfcdd0ac5..5844cb2f0 100644 --- a/grub-core/normal/menu.c +++ b/grub-core/normal/menu.c @@ -31,6 +31,7 @@ #include #include #include +#include /* Time to delay after displaying an error message about a default/fallback entry failing to boot. */ From 947aa4f886767d0da7a00418672ded6cc4fb52e2 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 8 Apr 2011 12:13:44 +0200 Subject: [PATCH 412/869] * grub-core/Makefile.am: Properly escape parenthesis in sed expressions. Fixes Estonian locale. Reported by: Leho Kraav. --- ChangeLog | 6 ++++++ grub-core/Makefile.am | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7b247ca81..fd5cadae5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2011-04-08 Vladimir Serbinenko + + * grub-core/Makefile.am: Properly escape parenthesis in sed expressions. + Fixes Estonian locale. + Reported by: Leho Kraav. + 2011-04-08 Vladimir Serbinenko * grub-core/normal/menu.c: Add missing include. diff --git a/grub-core/Makefile.am b/grub-core/Makefile.am index 94f7f3ffe..9e0ca7cc3 100644 --- a/grub-core/Makefile.am +++ b/grub-core/Makefile.am @@ -200,8 +200,8 @@ noinst_DATA += kernel_syms.lst kernel_syms.lst: $(KERNEL_HEADER_FILES) $(top_builddir)/config.h $(TARGET_CPP) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS_KERNEL) $(CPPFLAGS) $(CFLAGS) -DGRUB_SYMBOL_GENERATOR=1 $^ >kernel_syms.input cat kernel_syms.input | grep -v '^#' | sed -n \ - -e '/EXPORT_FUNC *([a-zA-Z0-9_]*)/{s/.*EXPORT_FUNC *(\([a-zA-Z0-9_]*\)).*/defined kernel '"$(ASM_PREFIX)"'\1/;p;}' \ - -e '/EXPORT_VAR *([a-zA-Z0-9_]*)/{s/.*EXPORT_VAR *(\([a-zA-Z0-9_]*\)).*/defined kernel '"$(ASM_PREFIX)"'\1/;p;}' \ + -e '/EXPORT_FUNC *\([a-zA-Z0-9_]*\)/{s/.*EXPORT_FUNC *(\([a-zA-Z0-9_]*\)).*/defined kernel '"$(ASM_PREFIX)"'\1/;p;}' \ + -e '/EXPORT_VAR *\([a-zA-Z0-9_]*\)/{s/.*EXPORT_VAR *(\([a-zA-Z0-9_]*\)).*/defined kernel '"$(ASM_PREFIX)"'\1/;p;}' \ | sort -u >$@ rm -f kernel_syms.input CLEANFILES += kernel_syms.lst From cb180fdf06a03ad159b83915572ea60f32073053 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 8 Apr 2011 13:18:27 +0200 Subject: [PATCH 413/869] revert last revision. It's ineffective --- ChangeLog | 6 ------ grub-core/Makefile.am | 4 ++-- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index fd5cadae5..7b247ca81 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,9 +1,3 @@ -2011-04-08 Vladimir Serbinenko - - * grub-core/Makefile.am: Properly escape parenthesis in sed expressions. - Fixes Estonian locale. - Reported by: Leho Kraav. - 2011-04-08 Vladimir Serbinenko * grub-core/normal/menu.c: Add missing include. diff --git a/grub-core/Makefile.am b/grub-core/Makefile.am index 9e0ca7cc3..94f7f3ffe 100644 --- a/grub-core/Makefile.am +++ b/grub-core/Makefile.am @@ -200,8 +200,8 @@ noinst_DATA += kernel_syms.lst kernel_syms.lst: $(KERNEL_HEADER_FILES) $(top_builddir)/config.h $(TARGET_CPP) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS_KERNEL) $(CPPFLAGS) $(CFLAGS) -DGRUB_SYMBOL_GENERATOR=1 $^ >kernel_syms.input cat kernel_syms.input | grep -v '^#' | sed -n \ - -e '/EXPORT_FUNC *\([a-zA-Z0-9_]*\)/{s/.*EXPORT_FUNC *(\([a-zA-Z0-9_]*\)).*/defined kernel '"$(ASM_PREFIX)"'\1/;p;}' \ - -e '/EXPORT_VAR *\([a-zA-Z0-9_]*\)/{s/.*EXPORT_VAR *(\([a-zA-Z0-9_]*\)).*/defined kernel '"$(ASM_PREFIX)"'\1/;p;}' \ + -e '/EXPORT_FUNC *([a-zA-Z0-9_]*)/{s/.*EXPORT_FUNC *(\([a-zA-Z0-9_]*\)).*/defined kernel '"$(ASM_PREFIX)"'\1/;p;}' \ + -e '/EXPORT_VAR *([a-zA-Z0-9_]*)/{s/.*EXPORT_VAR *(\([a-zA-Z0-9_]*\)).*/defined kernel '"$(ASM_PREFIX)"'\1/;p;}' \ | sort -u >$@ rm -f kernel_syms.input CLEANFILES += kernel_syms.lst From 18dd6b472d1ef7799d83c0bd7df823dc8f45133d Mon Sep 17 00:00:00 2001 From: Vladimir Serbinenko Date: Fri, 8 Apr 2011 13:57:56 +0200 Subject: [PATCH 414/869] * autogen.sh: Ensure that collate and ctype locale is C. * conf/Makefile.common: Likeiwise. Also-By: Colin Watson --- ChangeLog | 6 ++++++ autogen.sh | 4 ++++ conf/Makefile.common | 4 ++++ 3 files changed, 14 insertions(+) diff --git a/ChangeLog b/ChangeLog index 7b247ca81..1820e3306 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2011-04-08 Vladimir Serbinenko +2011-04-08 Colin Watson + + * autogen.sh: Ensure that collate and ctype locale is C. + * conf/Makefile.common: Likeiwise. + 2011-04-08 Vladimir Serbinenko * grub-core/normal/menu.c: Add missing include. diff --git a/autogen.sh b/autogen.sh index 96b1e33e2..d14707aad 100755 --- a/autogen.sh +++ b/autogen.sh @@ -2,6 +2,10 @@ set -e +export LC_CTYPE=C +export LC_COLLATE=C +unset LC_ALL + autogen --version >/dev/null || exit 1 echo "Importing unicode..." diff --git a/conf/Makefile.common b/conf/Makefile.common index 32ca76d08..5aa13cdd6 100644 --- a/conf/Makefile.common +++ b/conf/Makefile.common @@ -2,6 +2,10 @@ CFLAGS_PLATFORM= +export LC_COLLATE := C +export LC_CTYPE := C +unexport LC_ALL + # Platform specific options if COND_i386_pc CFLAGS_PLATFORM += -mrtd -mregparm=3 From 4ed4ce5820f74eb1f908ba8cef90aba743ce3bd9 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 8 Apr 2011 13:59:07 +0200 Subject: [PATCH 415/869] correct Changelog spelling --- ChangeLog | 2 +- grub-core/loader/i386/multiboot_mbi.c | 2 +- include/grub/efiemu/efiemu.h | 5 ++--- include/grub/util/raid.h | 2 +- util/grub-setup.c | 10 +++++++++- util/raid.c | 13 +++---------- 6 files changed, 17 insertions(+), 17 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1820e3306..e8b2bf0e7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,7 +2,7 @@ 2011-04-08 Colin Watson * autogen.sh: Ensure that collate and ctype locale is C. - * conf/Makefile.common: Likeiwise. + * conf/Makefile.common: Likewise. 2011-04-08 Vladimir Serbinenko diff --git a/grub-core/loader/i386/multiboot_mbi.c b/grub-core/loader/i386/multiboot_mbi.c index 14db50bcd..bef534296 100644 --- a/grub-core/loader/i386/multiboot_mbi.c +++ b/grub-core/loader/i386/multiboot_mbi.c @@ -435,7 +435,7 @@ grub_multiboot_make_mbi (grub_uint32_t *target) bufsize = grub_multiboot_get_mbi_size (); err = grub_relocator_alloc_chunk_align (grub_multiboot_relocator, &ch, - 0, 0xffffffff - bufsize, + 0x10000, 0x100000 - bufsize, bufsize, 4, GRUB_RELOCATOR_PREFERENCE_NONE); if (err) diff --git a/include/grub/efiemu/efiemu.h b/include/grub/efiemu/efiemu.h index 8eee98b61..9cedc3226 100644 --- a/include/grub/efiemu/efiemu.h +++ b/include/grub/efiemu/efiemu.h @@ -21,6 +21,7 @@ #include #include +#include #define GRUB_EFIEMU_PAGESIZE 4096 @@ -227,9 +228,7 @@ grub_efiemu_finish_boot_services (grub_efi_uintn_t *memory_map_size, grub_efi_uint32_t *descriptor_version); grub_err_t -grub_efiemu_mmap_iterate (int NESTED_FUNC_ATTR (*hook) (grub_uint64_t, - grub_uint64_t, - grub_uint32_t)); +grub_efiemu_mmap_iterate (grub_memory_hook_t hook); int grub_efiemu_sizeof_uintn_t (void); grub_err_t grub_efiemu_get_lower_upper_memory (grub_uint64_t *lower, grub_uint64_t *upper); diff --git a/include/grub/util/raid.h b/include/grub/util/raid.h index 67020bb86..4da5eaaa8 100644 --- a/include/grub/util/raid.h +++ b/include/grub/util/raid.h @@ -21,7 +21,7 @@ #define GRUB_RAID_UTIL_HEADER 1 #ifdef __linux__ -char** grub_util_raid_getmembers (char *name); +char** grub_util_raid_getmembers (const char *name); #endif #endif /* ! GRUB_RAID_UTIL_HEADER */ diff --git a/util/grub-setup.c b/util/grub-setup.c index c1f2a1f5e..ed2d63fdd 100644 --- a/util/grub-setup.c +++ b/util/grub-setup.c @@ -973,7 +973,15 @@ main (int argc, char *argv[]) char **devicelist; int i; - devicelist = grub_util_raid_getmembers (dest_dev); + if (arguments.device[0] == '/') + devicelist = grub_util_raid_getmembers (arguments.device); + else + { + char *devname; + devname = xasprintf ("/dev/%s", dest_dev); + devicelist = grub_util_raid_getmembers (dest_dev); + free (devname); + } for (i = 0; devicelist[i]; i++) { diff --git a/util/raid.c b/util/raid.c index dac19a935..a6aa5f95e 100644 --- a/util/raid.c +++ b/util/raid.c @@ -36,25 +36,18 @@ #include char ** -grub_util_raid_getmembers (char *name) +grub_util_raid_getmembers (const char *name) { int fd, ret, i, j; - char *devname; char **devicelist; mdu_version_t version; mdu_array_info_t info; mdu_disk_info_t disk; - devname = xmalloc (strlen (name) + 6); - strcpy (devname, "/dev/"); - strcpy (devname+5, name); - - fd = open (devname, O_RDONLY); + fd = open (name, O_RDONLY); if (fd == -1) - grub_util_error ("can't open %s: %s", devname, strerror (errno)); - - free (devname); + grub_util_error ("can't open %s: %s", name, strerror (errno)); ret = ioctl (fd, RAID_VERSION, &version); if (ret != 0) From 7a3d6cd97bd2f047ce93a6dab1c3094cd0d2eaf8 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 8 Apr 2011 14:02:27 +0200 Subject: [PATCH 416/869] * include/grub/efiemu/efiemu.h: Use grub_memory_hook_t type. --- ChangeLog | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ChangeLog b/ChangeLog index e8b2bf0e7..df08adb93 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2011-04-08 Vladimir Serbinenko + + * include/grub/efiemu/efiemu.h: Use grub_memory_hook_t type. + 2011-04-08 Vladimir Serbinenko 2011-04-08 Colin Watson From 10a7a86703946b5f09cff96206a793a6beb449ec Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 8 Apr 2011 14:04:24 +0200 Subject: [PATCH 417/869] * grub-core/loader/i386/multiboot_mbi.c (grub_multiboot_make_mbi): Place mbi on low memory for better compatibility. --- ChangeLog | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/ChangeLog b/ChangeLog index df08adb93..a0ed27b06 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-04-08 Vladimir Serbinenko + + * grub-core/loader/i386/multiboot_mbi.c (grub_multiboot_make_mbi): + Place mbi on low memory for better compatibility. + 2011-04-08 Vladimir Serbinenko * include/grub/efiemu/efiemu.h: Use grub_memory_hook_t type. From 2e335e901cd0f45e9610c6441154f9d7a415b1d4 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 8 Apr 2011 14:08:55 +0200 Subject: [PATCH 418/869] * include/grub/util/raid.h (grub_util_raid_getmembers): Make argument const. * util/grub-setup.c (main): Reuse md device name if available. * util/raid.c (grub_util_raid_getmembers): Receive device name and not GRUB name as argument. Based on patch by: Florian Wagner . --- ChangeLog | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/ChangeLog b/ChangeLog index a0ed27b06..fdce6dfe0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2011-04-08 Vladimir Serbinenko + + * include/grub/util/raid.h (grub_util_raid_getmembers): Make argument + const. + * util/grub-setup.c (main): Reuse md device name if available. + * util/raid.c (grub_util_raid_getmembers): Receive device name and + not GRUB name as argument. + Based on patch by: Florian Wagner . + 2011-04-08 Vladimir Serbinenko * grub-core/loader/i386/multiboot_mbi.c (grub_multiboot_make_mbi): From 6a6f80587b06170180b899877c54299f5a1c5af5 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 8 Apr 2011 14:25:44 +0200 Subject: [PATCH 419/869] * grub-core/normal/term.c (print_ucs4_terminal): Don't try to put the word on new line if it's too long anyway. Fixes a hang. --- ChangeLog | 5 +++++ grub-core/normal/term.c | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index fdce6dfe0..1b9d768ce 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-04-08 Vladimir Serbinenko + + * grub-core/normal/term.c (print_ucs4_terminal): Don't try to put the + word on new line if it's too long anyway. Fixes a hang. + 2011-04-08 Vladimir Serbinenko * include/grub/util/raid.h (grub_util_raid_getmembers): Make argument diff --git a/grub-core/normal/term.c b/grub-core/normal/term.c index a1aa3d783..9c4b491f5 100644 --- a/grub-core/normal/term.c +++ b/grub-core/normal/term.c @@ -552,7 +552,7 @@ print_ucs4_terminal (const grub_uint32_t * str, if (line_width > max_width && last_space > line_start) ptr = last_space; else if (line_width > max_width - && line_start == str && startwidth != 0) + && line_start == str && line_width - lastspacewidth < max_width - 5) { ptr = str; lastspacewidth = startwidth; From 34c09785b674cab9df9be9bd2a6e992fafb67c4b Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 8 Apr 2011 14:28:19 +0200 Subject: [PATCH 420/869] * grub-core/commands/probe.c (options): Argument to set isn't optional. (GRUB_MOD_INIT): DEVICE isn't optional. --- ChangeLog | 5 +++++ grub-core/commands/probe.c | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1b9d768ce..2bcc1b66b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-04-08 Vladimir Serbinenko + + * grub-core/commands/probe.c (options): Argument to set isn't optional. + (GRUB_MOD_INIT): DEVICE isn't optional. + 2011-04-08 Vladimir Serbinenko * grub-core/normal/term.c (print_ucs4_terminal): Don't try to put the diff --git a/grub-core/commands/probe.c b/grub-core/commands/probe.c index abe84895d..3ace596d8 100644 --- a/grub-core/commands/probe.c +++ b/grub-core/commands/probe.c @@ -34,7 +34,7 @@ static const struct grub_arg_option options[] = { - {"set", 's', GRUB_ARG_OPTION_OPTIONAL, + {"set", 's', 0, N_("Set a variable to return value."), "VAR", ARG_TYPE_STRING}, {"driver", 'd', 0, N_("Determine driver."), 0, 0}, {"partmap", 'p', 0, N_("Determine partition map type."), 0, 0}, @@ -150,7 +150,7 @@ static grub_extcmd_t cmd; GRUB_MOD_INIT (probe) { - cmd = grub_register_extcmd ("probe", grub_cmd_probe, 0, N_("[DEVICE]"), + cmd = grub_register_extcmd ("probe", grub_cmd_probe, 0, N_("DEVICE"), N_("Retrieve device info."), options); } From 7c2e4909c3cf1a2b23ac096e48269e1e7f694fab Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 8 Apr 2011 14:32:41 +0200 Subject: [PATCH 421/869] * grub-core/lib/legacy_parse.c (legacy_commands): Find doesn't set root on legacy. --- ChangeLog | 5 +++++ grub-core/lib/legacy_parse.c | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 2bcc1b66b..70101ef17 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-04-08 Vladimir Serbinenko + + * grub-core/lib/legacy_parse.c (legacy_commands): Find doesn't set + root on legacy. + 2011-04-08 Vladimir Serbinenko * grub-core/commands/probe.c (options): Argument to set isn't optional. diff --git a/grub-core/lib/legacy_parse.c b/grub-core/lib/legacy_parse.c index fb1a52bf8..024849055 100644 --- a/grub-core/lib/legacy_parse.c +++ b/grub-core/lib/legacy_parse.c @@ -116,7 +116,7 @@ static struct legacy_command legacy_commands[] = " immediately starts over using the NUM entry (same numbering as the" " `default' command). This obviously won't help if the machine" " was rebooted by a kernel that GRUB loaded."}, - {"find", "search -sf '%s'\n", NULL, 0, 1, {TYPE_FILE}, 0, "FILENAME", + {"find", "search -f '%s'\n", NULL, 0, 1, {TYPE_FILE}, 0, "FILENAME", "Search for the filename FILENAME in all of partitions and print the list of" " the devices which contain the file."}, /* FIXME: fstest unsupported. */ From d7a565e962b541b8a5ccb2719253a884b2c2b422 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 8 Apr 2011 14:37:13 +0200 Subject: [PATCH 422/869] * grub-core/normal/menu_entry.c (run): Use grub_memcpy rather than grub_strcpy since the lines aren't necessarily 0-terminated. --- ChangeLog | 5 +++++ grub-core/normal/menu_entry.c | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 70101ef17..7621dc3fb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-04-08 Vladimir Serbinenko + + * grub-core/normal/menu_entry.c (run): Use grub_memcpy rather than + grub_strcpy since the lines aren't necessarily 0-terminated. + 2011-04-08 Vladimir Serbinenko * grub-core/lib/legacy_parse.c (legacy_commands): Find doesn't set diff --git a/grub-core/normal/menu_entry.c b/grub-core/normal/menu_entry.c index a675ff005..30af2c1dc 100644 --- a/grub-core/normal/menu_entry.c +++ b/grub-core/normal/menu_entry.c @@ -1185,7 +1185,7 @@ run (struct screen *screen) size = 0; for (i = 0; i < screen->num_lines; i++) { - grub_strcpy (source + size, screen->lines[i].buf); + grub_memcpy (source + size, screen->lines[i].buf, screen->lines[i].len); size += screen->lines[i].len; source[size++] = '\n'; } From 2c58372857c7482217006ff9a056915d47bd14a1 Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Fri, 8 Apr 2011 14:01:51 +0100 Subject: [PATCH 423/869] * docs/grub-dev.texi: Fix spelling of "developer" throughout. * grub-core/fs/i386/pc/pxe.c (parse_dhcp_vendor): Fix spelling of "development". --- ChangeLog | 6 ++++++ docs/grub-dev.texi | 10 +++++----- grub-core/fs/i386/pc/pxe.c | 2 +- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7621dc3fb..bc44fb078 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2011-04-08 Colin Watson + + * docs/grub-dev.texi: Fix spelling of "developer" throughout. + * grub-core/fs/i386/pc/pxe.c (parse_dhcp_vendor): Fix spelling of + "development". + 2011-04-08 Vladimir Serbinenko * grub-core/normal/menu_entry.c (run): Use grub_memcpy rather than diff --git a/docs/grub-dev.texi b/docs/grub-dev.texi index f1bfd294b..7c4e3d258 100644 --- a/docs/grub-dev.texi +++ b/docs/grub-dev.texi @@ -3,7 +3,7 @@ @c %**start of header @setfilename grub-dev.info @include version-dev.texi -@settitle GNU GRUB Developpers Manual @value{VERSION} +@settitle GNU GRUB Developers Manual @value{VERSION} @c Unify all our little indices for now. @syncodeindex fn cp @syncodeindex vr cp @@ -17,7 +17,7 @@ @finalout @copying -This developper manual is for GNU GRUB (version @value{VERSION}, +This developer manual is for GNU GRUB (version @value{VERSION}, @value{UPDATED}). Copyright @copyright{} 1999,2000,2001,2002,2004,2005,2006,2008,2009,2010,2011 Free Software Foundation, Inc. @@ -39,7 +39,7 @@ Invariant Sections. @titlepage @sp 10 -@title the GNU GRUB developper manual +@title the GNU GRUB developer manual @subtitle The GRand Unified Bootloader, version @value{VERSION}, @value{UPDATED}. @author Yoshinori K. Okuji @author Colin D Bennett @@ -61,9 +61,9 @@ Invariant Sections. @ifnottex @node Top -@top GNU GRUB developper manual +@top GNU GRUB developer manual -This is the developper documentation of GNU GRUB, the GRand Unified Bootloader, +This is the developer documentation of GNU GRUB, the GRand Unified Bootloader, a flexible and powerful boot loader program for a wide range of architectures. diff --git a/grub-core/fs/i386/pc/pxe.c b/grub-core/fs/i386/pc/pxe.c index a3b055f3d..c800ea2ad 100644 --- a/grub-core/fs/i386/pc/pxe.c +++ b/grub-core/fs/i386/pc/pxe.c @@ -481,7 +481,7 @@ parse_dhcp_vendor (void *vend, int limit) break; /* If you need any other options please contact GRUB - developpement team. */ + development team. */ } ptr += taglength; From 1ec652f4c46b34e833e4c5068176531e54db7ac3 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 8 Apr 2011 16:00:23 +0200 Subject: [PATCH 424/869] * util/grub-mkimage.c (main): Handle special naming of yeeloong directory. --- ChangeLog | 5 +++++ util/grub-mkimage.c | 16 +++++++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index bc44fb078..569060ec8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-04-08 Vladimir Serbinenko + + * util/grub-mkimage.c (main): Handle special naming of yeeloong + directory. + 2011-04-08 Colin Watson * docs/grub-dev.texi: Fix spelling of "developer" throughout. diff --git a/util/grub-mkimage.c b/util/grub-mkimage.c index 876e9c9b2..70c5ef6a9 100644 --- a/util/grub-mkimage.c +++ b/util/grub-mkimage.c @@ -1588,9 +1588,19 @@ main (int argc, char *argv[]) + 1); memcpy (dir, GRUB_PKGLIBROOTDIR, sizeof (GRUB_PKGLIBROOTDIR) - 1); *(dir + sizeof (GRUB_PKGLIBROOTDIR) - 1) = '/'; - memcpy (dir + sizeof (GRUB_PKGLIBROOTDIR), image_target->name, - last - image_target->name); - *(dir + sizeof (GRUB_PKGLIBROOTDIR) + (last - image_target->name)) = 0; + if (strncmp (image_target->name, "mipsel-yeeloong", + last - image_target->name) == 0) + { + memcpy (dir + sizeof (GRUB_PKGLIBROOTDIR), "mips-yeeloong", + sizeof ("mips-yeeloong")); + } + else + { + memcpy (dir + sizeof (GRUB_PKGLIBROOTDIR), image_target->name, + last - image_target->name); + *(dir + sizeof (GRUB_PKGLIBROOTDIR) + (last - image_target->name)) + = 0; + } } generate_image (dir, prefix ? : DEFAULT_DIRECTORY, fp, From 2cf09e3258991b0b1a4d5645d6deaff5ca27ed09 Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Sat, 9 Apr 2011 03:10:59 +0100 Subject: [PATCH 425/869] * docs/grub-dev.texi: Replace MoinMoin syntax with Texinfo syntax throughout. --- ChangeLog | 5 + docs/grub-dev.texi | 339 +++++++++++++++++++++++---------------------- 2 files changed, 178 insertions(+), 166 deletions(-) diff --git a/ChangeLog b/ChangeLog index 569060ec8..0494fa2c3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-04-09 Colin Watson + + * docs/grub-dev.texi: Replace MoinMoin syntax with Texinfo syntax + throughout. + 2011-04-08 Vladimir Serbinenko * util/grub-mkimage.c (main): Handle special naming of yeeloong diff --git a/docs/grub-dev.texi b/docs/grub-dev.texi index 7c4e3d258..a7ab6f71a 100644 --- a/docs/grub-dev.texi +++ b/docs/grub-dev.texi @@ -115,7 +115,7 @@ local version, you may need to resolve conflicts when pulling. @chapter Coding style @c By YoshinoriOkuji, VesaJääskeläinen and ColinBennett -Basically we follow the [http://www.gnu.org/prep/standards_toc.html GNU Coding Standards]. We define additional conventions for GRUB here. +Basically we follow the @uref{http://www.gnu.org/prep/standards_toc.html, GNU Coding Standards}. We define additional conventions for GRUB here. @menu * Naming Conventions:: @@ -167,7 +167,7 @@ If a macro is global, its name must be prefixed with GRUB_ and must consist of o @node Comments @section Comments -All comments shall be C-style comments, of the form `/*` … `*/`. +All comments shall be C-style comments, of the form @samp{/* @dots{} */}. Comments shall be placed only on a line be themselves. They shall not be placed together with code, variable declarations, or other non-comment entities. A comment should be placed immediately preceding the entity it describes. @@ -207,7 +207,7 @@ Unacceptable: * It is long. */ @end example -The opening `/*` and closing `*/` should be placed together on a line with text. +The opening @samp{/*} and closing @samp{*/} should be placed together on a line with text. @node Finding your way around @chapter Finding your way around @@ -320,7 +320,7 @@ anymore. For developers it is recommended always to use the newest development version of GRUB 2. If development takes a long period of time, please remember to keep in sync with newest developments regularly so it is much easier to integrate your change in the future. GRUB 2 is being developed on SVN repository. Please check Savannah's GRUB project page for details how to get newest BZR: -[http://savannah.gnu.org/bzr/?group=grub GRUB 2 BZR Repository] +@uref{http://savannah.gnu.org/bzr/?group=grub, GRUB 2 BZR Repository} @item Compile it and try it out. @@ -368,7 +368,7 @@ what it changes and so on. Please be prepared to receive even discouraging comments about your patch. There is usually at least something that needs to be improved in every patch. -Please use unified diff to make your patch (good match of arguments for diff is ''-pruN''). +Please use unified diff to make your patch (good match of arguments for diff is @samp{-pruN}). @item Respond to received feedback. @@ -419,7 +419,7 @@ project: @enumerate @item You need to create your own account on Savannah. -@item You can submit ''Request for Inclusion'' from ''My Groups'' on Savannah. +@item You can submit ``Request for Inclusion'' from ``My Groups'' on Savannah. @end enumerate Then, one of the admins can approve your request, and you will be a member. @@ -427,7 +427,7 @@ If you don't want to use the Savannah interface to submit a request, you can simply notify the admins by email or something else, alternatively. But you still need to create an account beforehand. -NOTE: we sometimes receive a ''Request for Inclusion'' from an unknown person. +NOTE: we sometimes receive a ``Request for Inclusion'' from an unknown person. In this case, the request would be just discarded, since it is too dangerous to allow a stranger to be a member, which automatically gives him a commit right to the repository, both for a legal reason and for a technical reason. @@ -448,13 +448,13 @@ function does not provide handling of the exception it must return back to it's calling function and so on, until exception is handled. If exception is not handled before prompt is displayed, error message will be shown to user. -Exception information is stored on ''grub_errno'' global variable. If -''grub_errno'' variable contains value ''GRUB_ERR_NONE'', there is no active -exception and application can continue normal processing. When grub_errno has +Exception information is stored on @code{grub_errno} global variable. If +@code{grub_errno} variable contains value @code{GRUB_ERR_NONE}, there is no active +exception and application can continue normal processing. When @code{grub_errno} has other value, it is required that application code either handles this error or -returns instantly to caller. If function is with return type ''grub_err_t'' is -about to return ''GRUB_ERR_NONE'', it should not set ''grub_errno'' to that -value. Only set ''grub_errno'' in cases where there is error situation. +returns instantly to caller. If function is with return type @code{grub_err_t} is +about to return @code{GRUB_ERR_NONE}, it should not set @code{grub_errno} to that +value. Only set @code{grub_errno} in cases where there is error situation. Simple exception forwarder. @example @@ -478,11 +478,11 @@ forwarding_example (void) @end example Error reporting has two components, the actual error code (of type -''grub_err_t'') and textual message that will be displayed to user. List of -valid error codes is listed in header file ''include/grub/err.h''. Textual +@code{grub_err_t}) and textual message that will be displayed to user. List of +valid error codes is listed in header file @file{include/grub/err.h}. Textual error message can contain any textual data. At time of writing, error message can contain up to 256 characters (including terminating NUL). To ease error -reporting there is a helper function ''grub_error'' that allows easier +reporting there is a helper function @code{grub_error} that allows easier formatting of error messages and should be used instead of writing directly to global variables. @@ -499,11 +499,11 @@ failing_example () @end example If there is a special reason that error code does not need to be taken account, -''grub_errno'' can be zeroed back to ''GRUB_ERR_NONE''. In cases like this all +@code{grub_errno} can be zeroed back to @code{GRUB_ERR_NONE}. In cases like this all previous error codes should have been handled correctly. This makes sure that there are no unhandled exceptions. -Example of zeroing ''grub_errno''. +Example of zeroing @code{grub_errno}. @example grub_err_t probe_example () @@ -539,8 +539,8 @@ Some times there is a need to continue processing even if there is a error state in application. In situations like this, there is a needed to save old error state and then call other functions that might fail. To aid in this, there is a error stack implemented. Error state can be pushed to error stack -by calling function ''grub_error_push ()''. When processing has been completed, -''grub_error_pop ()'' can be used to pop error state from stack. Error stack +by calling function @code{grub_error_push ()}. When processing has been completed, +@code{grub_error_pop ()} can be used to pop error state from stack. Error stack contains predefined amount of error stack items. Error stack is proteced for overflow and marks these situations so overflow error does not get unseen. If there is no space available to store error message, it is simply discarded @@ -644,7 +644,7 @@ grub_video_setup (unsigned int width, unsigned int height, unsigned int mode_typ @end example @item Description: -Driver will use information provided to it to select best possible video mode and switch to it. Supported values for ''mode_type'' are ''GRUB_VIDEO_MODE_TYPE_INDEX_COLOR'' for index color modes, ''GRUB_VIDEO_MODE_TYPE_RGB'' for direct RGB color modes and ''GRUB_VIDEO_MODE_TYPE_DOUBLE_BUFFERED'' for double buffering. When requesting RGB mode, highest bits per pixel mode will be selected. When requesting Index color mode, mode with highest number of colors will be selected. If all parameters are specified as zero, video adapter will try to figure out best possible mode and initialize it, platform specific differences are allowed here. If there is no mode matching request, error X will be returned. If there are no problems, function returns ''GRUB_ERR_NONE''. +Driver will use information provided to it to select best possible video mode and switch to it. Supported values for @code{mode_type} are @code{GRUB_VIDEO_MODE_TYPE_INDEX_COLOR} for index color modes, @code{GRUB_VIDEO_MODE_TYPE_RGB} for direct RGB color modes and @code{GRUB_VIDEO_MODE_TYPE_DOUBLE_BUFFERED} for double buffering. When requesting RGB mode, highest bits per pixel mode will be selected. When requesting Index color mode, mode with highest number of colors will be selected. If all parameters are specified as zero, video adapter will try to figure out best possible mode and initialize it, platform specific differences are allowed here. If there is no mode matching request, error X will be returned. If there are no problems, function returns @code{GRUB_ERR_NONE}. This function also performs following task upon succesful mode switch. Active rendering target is changed to screen and viewport is maximized to allow whole screen to be used when performing graphics operations. In RGB modes, emulated palette get's 16 entries containing default values for VGA palette, other colors are defined as black. When switching to Indexed Color mode, driver may set default VGA palette to screen if the video card allows the operation. @@ -712,7 +712,7 @@ struct grub_video_mode_info @end example @item Description: -Software developer can use this function to query properties of active rendering taget. Information provided here can be used by other parts of GRUB, like image loaders to convert loaded images to correct screen format to allow more optimized blitters to be used. If there there is no configured video driver with active screen, error ''GRUB_ERR_BAD_DEVICE'' is returned, otherwise ''mode_info'' is filled with valid information and ''GRUB_ERR_NONE'' is returned. +Software developer can use this function to query properties of active rendering taget. Information provided here can be used by other parts of GRUB, like image loaders to convert loaded images to correct screen format to allow more optimized blitters to be used. If there there is no configured video driver with active screen, error @code{GRUB_ERR_BAD_DEVICE} is returned, otherwise @code{mode_info} is filled with valid information and @code{GRUB_ERR_NONE} is returned. @end itemize @subsection grub_video_get_blit_format @@ -740,7 +740,7 @@ enum grub_video_blit_format @end example @item Description: -Used to query how data could be optimized to suit specified video mode. Returns exact video format type, or a generic one if there is no definition for the type. For generic formats, use ''grub_video_get_info'' to query video color coding settings. +Used to query how data could be optimized to suit specified video mode. Returns exact video format type, or a generic one if there is no definition for the type. For generic formats, use @code{grub_video_get_info} to query video color coding settings. @end itemize @subsection grub_video_set_palette @@ -762,7 +762,7 @@ struct grub_video_palette_data @end example @item Description: -Used to setup indexed color palettes. If mode is RGB mode, colors will be set to emulated palette data. In Indexed Color modes, palettes will be set to hardware. Color values will be converted to suit requirements of the video mode. ''start'' will tell what hardware color index (or emulated color index) will be set to according information in first indice of ''palette_data'', after that both hardware color index and ''palette_data'' index will be incremented until ''count'' number of colors have been set. +Used to setup indexed color palettes. If mode is RGB mode, colors will be set to emulated palette data. In Indexed Color modes, palettes will be set to hardware. Color values will be converted to suit requirements of the video mode. @code{start} will tell what hardware color index (or emulated color index) will be set to according information in first indice of @code{palette_data}, after that both hardware color index and @code{palette_data} index will be incremented until @code{count} number of colors have been set. @end itemize @subsection grub_video_get_palette @@ -784,7 +784,7 @@ struct grub_video_palette_data @end example @item Description: -Used to query indexed color palettes. If mode is RGB mode, colors will be copied from emulated palette data. In Indexed Color modes, palettes will be read from hardware. Color values will be converted to suit structure format. ''start'' will tell what hardware color index (or emulated color index) will be used as a source for first indice of ''palette_data'', after that both hardware color index and ''palette_data'' index will be incremented until ''count'' number of colors have been read. +Used to query indexed color palettes. If mode is RGB mode, colors will be copied from emulated palette data. In Indexed Color modes, palettes will be read from hardware. Color values will be converted to suit structure format. @code{start} will tell what hardware color index (or emulated color index) will be used as a source for first indice of @code{palette_data}, after that both hardware color index and @code{palette_data} index will be incremented until @code{count} number of colors have been read. @end itemize @subsection grub_video_set_viewport @@ -797,7 +797,7 @@ grub_video_set_viewport (unsigned int x, unsigned int y, unsigned int width, uns @end example @item Description: -Used to specify viewport where draw commands are performed. When viewport is set, all draw commands coordinates relate to those specified by ''x'' and ''y''. If draw commands try to draw over viewport, they are clipped. If developer requests larger than possible viewport, width and height will be clamped to fit screen. If ''x'' and ''y'' are out of bounds, all functions drawing to screen will not be displayed. In order to maximize viewport, use grub_video_get_info to query actual screen dimensions and provide that information to this function. +Used to specify viewport where draw commands are performed. When viewport is set, all draw commands coordinates relate to those specified by @code{x} and @code{y}. If draw commands try to draw over viewport, they are clipped. If developer requests larger than possible viewport, width and height will be clamped to fit screen. If @code{x} and @code{y} are out of bounds, all functions drawing to screen will not be displayed. In order to maximize viewport, use @code{grub_video_get_info} to query actual screen dimensions and provide that information to this function. @end itemize @subsection grub_video_get_viewport @@ -823,7 +823,7 @@ grub_video_map_color (grub_uint32_t color_name); @end example @item Description: -Map color can be used to support color themes in GRUB. There will be collection of color names that can be used to query actual screen mapped color data. Examples could be ''GRUB_COLOR_CONSOLE_BACKGROUND'', ''GRUB_COLOR_CONSOLE_TEXT''. The actual color defines are not specified at this point. +Map color can be used to support color themes in GRUB. There will be collection of color names that can be used to query actual screen mapped color data. Examples could be @code{GRUB_COLOR_CONSOLE_BACKGROUND}, @code{GRUB_COLOR_CONSOLE_TEXT}. The actual color defines are not specified at this point. @end itemize @subsection grub_video_map_rgb @@ -862,7 +862,7 @@ grub_video_unmap_color (grub_video_color_t color, grub_uint8_t *red, grub_uint8_ @end example @item Description: -Unmap color value from ''color'' to color channels in ''red'', ''green'', ''blue'' and ''alpha''. Values will be in range 0-255. Active rendering target will be used for color domain. In case alpha information is not available in rendering target, it is assumed to be opaque (having value 255). +Unmap color value from @code{color} to color channels in @code{red}, @code{green}, @code{blue} and @code{alpha}. Values will be in range 0-255. Active rendering target will be used for color domain. In case alpha information is not available in rendering target, it is assumed to be opaque (having value 255). @end itemize @subsection grub_video_fill_rect @@ -877,7 +877,7 @@ grub_video_fill_rect (grub_video_color_t color, int x, int y, unsigned int width Fill specified area limited by given coordinates within specified viewport. Negative coordinates are accepted in order to allow easy moving of rectangle within viewport. If coordinates are negative, area of the rectangle will be shrinken to follow size limits of the viewport. -Software developer should use either ''grub_video_map_color'', ''grub_video_map_rgb'' or ''grub_video_map_rgba'' to map requested color to ''color'' parameter. +Software developer should use either @code{grub_video_map_color}, @code{grub_video_map_rgb} or @code{grub_video_map_rgba} to map requested color to @code{color} parameter. @end itemize @subsection grub_video_blit_glyph @@ -895,7 +895,7 @@ struct grub_font_glyph @{ @end example @item Description: -Used to blit glyph to viewport in specified coodinates. If glyph is at edge of viewport, pixels outside of viewport will be clipped out. Software developer should use either ''grub_video_map_rgb'' or ''grub_video_map_rgba'' to map requested color to ''color'' parameter. +Used to blit glyph to viewport in specified coodinates. If glyph is at edge of viewport, pixels outside of viewport will be clipped out. Software developer should use either @code{grub_video_map_rgb} or @code{grub_video_map_rgba} to map requested color to @code{color} parameter. @end itemize @subsection grub_video_blit_bitmap @@ -920,9 +920,9 @@ enum grub_video_blit_operators @end example @item Description: -Used to blit bitmap to viewport in specified coordinates. If part of bitmap is outside of viewport region, it will be clipped out. Offsets affect bitmap position where data will be copied from. Negative values for both viewport coordinates and bitmap offset coordinates are allowed. If data is looked out of bounds of bitmap, color value will be assumed to be transparent. If viewport coordinates are negative, area of the blitted rectangle will be shrinken to follow size limits of the viewport and bitmap. Blitting operator ''oper'' specifies should source pixel replace data in screen or blend with pixel alpha value. +Used to blit bitmap to viewport in specified coordinates. If part of bitmap is outside of viewport region, it will be clipped out. Offsets affect bitmap position where data will be copied from. Negative values for both viewport coordinates and bitmap offset coordinates are allowed. If data is looked out of bounds of bitmap, color value will be assumed to be transparent. If viewport coordinates are negative, area of the blitted rectangle will be shrinken to follow size limits of the viewport and bitmap. Blitting operator @code{oper} specifies should source pixel replace data in screen or blend with pixel alpha value. -Software developer should use ''grub_video_bitmap_create'' or ''grub_video_bitmap_load'' to create or load bitmap data. +Software developer should use @code{grub_video_bitmap_create} or @code{grub_video_bitmap_load} to create or load bitmap data. @end itemize @subsection grub_video_blit_render_target @@ -946,7 +946,7 @@ enum grub_video_blit_operators @end example @item Description: -Used to blit source render target to viewport in specified coordinates. If part of source render target is outside of viewport region, it will be clipped out. If blitting operator is specified and source contains alpha values, resulting pixel color components will be calculated using formula ((src_color * src_alpha) + (dst_color * (255 - src_alpha)) / 255, if target buffer has alpha, it will be set to src_alpha. Offsets affect render target position where data will be copied from. If data is looked out of bounds of render target, color value will be assumed to be transparent. Blitting operator ''oper'' specifies should source pixel replace data in screen or blend with pixel alpha value. +Used to blit source render target to viewport in specified coordinates. If part of source render target is outside of viewport region, it will be clipped out. If blitting operator is specified and source contains alpha values, resulting pixel color components will be calculated using formula ((src_color * src_alpha) + (dst_color * (255 - src_alpha)) / 255, if target buffer has alpha, it will be set to src_alpha. Offsets affect render target position where data will be copied from. If data is looked out of bounds of render target, color value will be assumed to be transparent. Blitting operator @code{oper} specifies should source pixel replace data in screen or blend with pixel alpha value. @end itemize @subsection grub_video_scroll @@ -990,7 +990,7 @@ struct grub_video_render_target @{ @end example @item Description: -Driver will use information provided to it to create best fitting render target. ''mode_type'' will be used to guide on selecting what features are wanted for render target. Supported values for ''mode_type'' are ''GRUB_VIDEO_MODE_TYPE_INDEX_COLOR'' for index color modes, ''GRUB_VIDEO_MODE_TYPE_RGB'' for direct RGB color modes and ''GRUB_VIDEO_MODE_TYPE_ALPHA'' for alpha component. +Driver will use information provided to it to create best fitting render target. @code{mode_type} will be used to guide on selecting what features are wanted for render target. Supported values for @code{mode_type} are @code{GRUB_VIDEO_MODE_TYPE_INDEX_COLOR} for index color modes, @code{GRUB_VIDEO_MODE_TYPE_RGB} for direct RGB color modes and @code{GRUB_VIDEO_MODE_TYPE_ALPHA} for alpha component. @end itemize @subsection grub_video_delete_render_target @@ -1003,7 +1003,7 @@ grub_video_delete_render_target (struct grub_video_render_target *target); @end example @item Description: -Used to delete previously created render target. If ''target'' contains ''NULL'' pointer, nothing will be done. If render target is correctly destroyed, GRUB_ERR_NONE is returned. +Used to delete previously created render target. If @code{target} contains @code{NULL} pointer, nothing will be done. If render target is correctly destroyed, GRUB_ERR_NONE is returned. @end itemize @subsection grub_video_set_active_render_target @@ -1016,7 +1016,7 @@ grub_video_set_active_render_target (struct grub_video_render_target *target); @end example @item Description: -Set's active render target. If this comand is successful all drawing commands will be done to specified ''target''. There is also special values for target, ''GRUB_VIDEO_RENDER_TARGET_DISPLAY'' used to reference screen's front buffer, ''GRUB_VIDEO_RENDER_TARGET_FRONT_BUFFER'' used to reference screen's front buffer (alias for ''GRUB_VIDEO_RENDER_TARGET_DISPLAY'') and ''GRUB_VIDEO_RENDER_TARGET_BACK_BUFFER'' used to reference back buffer (if double buffering is enabled). If render target is correclty switched GRUB_ERR_NONE is returned. In no any event shall there be non drawable active render target. +Set's active render target. If this comand is successful all drawing commands will be done to specified @code{target}. There is also special values for target, @code{GRUB_VIDEO_RENDER_TARGET_DISPLAY} used to reference screen's front buffer, @code{GRUB_VIDEO_RENDER_TARGET_FRONT_BUFFER} used to reference screen's front buffer (alias for @code{GRUB_VIDEO_RENDER_TARGET_DISPLAY}) and @code{GRUB_VIDEO_RENDER_TARGET_BACK_BUFFER} used to reference back buffer (if double buffering is enabled). If render target is correclty switched GRUB_ERR_NONE is returned. In no any event shall there be non drawable active render target. @end itemize @subsection grub_video_get_active_render_target @@ -1029,7 +1029,7 @@ grub_video_get_active_render_target (struct grub_video_render_target **target); @end example @item Description: -Returns currently active render target. It returns value in ''target'' that can be subsequently issued back to ''grub_video_set_active_render_target''. +Returns currently active render target. It returns value in @code{target} that can be subsequently issued back to @code{grub_video_set_active_render_target}. @end itemize @node Example usage of Video API @@ -1082,7 +1082,7 @@ grub_err_t grub_video_bitmap_create (struct grub_video_bitmap **bitmap, unsigned @item Description: -Creates a new bitmap with given dimensions and blitting format. Allocated bitmap data can then be modified freely and finally blitted with ''grub_video_blit_bitmap'' to rendering target. +Creates a new bitmap with given dimensions and blitting format. Allocated bitmap data can then be modified freely and finally blitted with @code{grub_video_blit_bitmap} to rendering target. @end itemize @subsection grub_video_bitmap_destroy @@ -1094,7 +1094,7 @@ grub_err_t grub_video_bitmap_destroy (struct grub_video_bitmap *bitmap); @item Description: -When bitmap is no longer needed, it can be freed from memory using this command. ''bitmap'' is previously allocated bitmap with ''grub_video_bitmap_create'' or loaded with ''grub_video_bitmap_load''. +When bitmap is no longer needed, it can be freed from memory using this command. @code{bitmap} is previously allocated bitmap with @code{grub_video_bitmap_create} or loaded with @code{grub_video_bitmap_load}. @end itemize @subsection grub_video_bitmap_load @@ -1106,7 +1106,7 @@ grub_err_t grub_video_bitmap_load (struct grub_video_bitmap **bitmap, const char @item Description: -Tries to load given bitmap (''filename'') using registered bitmap loaders. In case bitmap format is not recognized or supported error ''GRUB_ERR_BAD_FILE_TYPE'' is returned. +Tries to load given bitmap (@code{filename}) using registered bitmap loaders. In case bitmap format is not recognized or supported error @code{GRUB_ERR_BAD_FILE_TYPE} is returned. @end itemize @subsection grub_video_bitmap_get_width @@ -1142,7 +1142,7 @@ void grub_video_bitmap_get_mode_info (struct grub_video_bitmap *bitmap, struct g @item Description: -Returns bitmap format details in form of ''grub_video_mode_info''. +Returns bitmap format details in form of @code{grub_video_mode_info}. @end itemize @subsection grub_video_bitmap_get_data @@ -1181,20 +1181,20 @@ use, compact, and cleanly supports Unicode. @itemize @item Simple to read and use. - Since GRUB will only be reading the font files, - we are more concerned with making the code to read the font simple than we - are with writing the font. +Since GRUB will only be reading the font files, +we are more concerned with making the code to read the font simple than we +are with writing the font. @item Compact storage. - The fonts will generally be stored in a small boot - partition where GRUB is located, and this may be on a removable storage - device such as a CD or USB flash drive where space is more limited than it - is on most hard drives. +The fonts will generally be stored in a small boot +partition where GRUB is located, and this may be on a removable storage +device such as a CD or USB flash drive where space is more limited than it +is on most hard drives. @item Unicode. - GRUB should not have to deal with multiple character - encodings. The font should always use Unicode character codes for simple - internationalization. +GRUB should not have to deal with multiple character +encodings. The font should always use Unicode character codes for simple +internationalization. @end itemize @subsection Why Another Font Format? @@ -1205,136 +1205,143 @@ use in GRUB at this time: @table @samp @item BDF - Inefficient storage; uses ASCII to describe properties and - hexadecimal numbers in ASCII for the bitmap rows. +Inefficient storage; uses ASCII to describe properties and +hexadecimal numbers in ASCII for the bitmap rows. @item PCF - Many format variations such as byte order and bitmap padding (rows - padded to byte, word, etc.) would result in more complex code to - handle the font format. +Many format variations such as byte order and bitmap padding (rows +padded to byte, word, etc.) would result in more complex code to +handle the font format. @end table @node File Structure @section File Structure -A file *section* consists of a 4-byte name, a 32-bit big-endian length (not -including the name or length), and then *length* more section-type-specific +A file @strong{section} consists of a 4-byte name, a 32-bit big-endian length (not +including the name or length), and then @var{length} more section-type-specific bytes. -The standard file extension for PFF2 font files is ``.pf2``. +The standard file extension for PFF2 font files is @file{.pf2}. @subsection Section Types @table @samp @item FILE - *File type ID* (ASCII string). This must be the first section in the file. It has length 4 - and the contents are the four bytes of the ASCII string ``PFF2``. +@strong{File type ID} (ASCII string). This must be the first section in the file. It has length 4 +and the contents are the four bytes of the ASCII string @samp{PFF2}. @item NAME - *Font name* (ASCII string). This is the full font name including family, - weight, style, and point size. For instance, "Helvetica Bold Italic 14". +@strong{Font name} (ASCII string). This is the full font name including family, +weight, style, and point size. For instance, "Helvetica Bold Italic 14". @item FAMI - *Font family name* (ASCII string). For instance, "Helvetica". This should - be included so that intelligent font substitution can take place. +@strong{Font family name} (ASCII string). For instance, "Helvetica". This should +be included so that intelligent font substitution can take place. @item WEIG - *Font weight* (ASCII string). Valid values are ``bold`` and ``normal``. - This should be included so that intelligent font substitution can take - place. +@strong{Font weight} (ASCII string). Valid values are @samp{bold} and @samp{normal}. +This should be included so that intelligent font substitution can take +place. @item SLAN - *Font slant* (ASCII string). Valid values are ``italic`` and ``normal``. - This should be included so that intelligent font substitution can take - place. +@strong{Font slant} (ASCII string). Valid values are @samp{italic} and @samp{normal}. +This should be included so that intelligent font substitution can take +place. @item PTSZ - *Font point size* (uint16be). +@strong{Font point size} (uint16be). @item MAXW - *Maximum character width in pixels* (uint16be). +@strong{Maximum character width in pixels} (uint16be). @item MAXH - *Maximum character height in pixels* (uint16be). +@strong{Maximum character height in pixels} (uint16be). @item ASCE - *Ascent in pixels* (uint16be). See `Font Metrics`_ for details. +@strong{Ascent in pixels} (uint16be). @xref{Font Metrics}, for details. @item DESC - *Descent in pixels* (uint16be). See `Font Metrics`_ for details. +@strong{Descent in pixels} (uint16be). @xref{Font Metrics}, for details. @item CHIX - *Character index.* - The character index begins with a 32-bit big-endian unsigned integer - indicating the total size of the section, not including this size value. - For each character, there is an instance of the following entry structure: +@strong{Character index.} +The character index begins with a 32-bit big-endian unsigned integer +indicating the total size of the section, not including this size value. +For each character, there is an instance of the following entry structure: - @itemize - @item **Unicode code point.** (32-bit big-endian integer.) +@itemize +@item @strong{Unicode code point.} (32-bit big-endian integer.) - @item **Storage flags.** (byte.) +@item @strong{Storage flags.} (byte.) - @itemize - @item Bits 2..0: +@itemize +@item Bits 2..0: - - If equal to 000 binary, then the character data is stored - uncompressed beginning at the offset indicated by the character's - *offset* value. +If equal to 000 binary, then the character data is stored +uncompressed beginning at the offset indicated by the character's +@strong{offset} value. - - If equal to 001 binary, then the character data is stored within a - compressed character definition block that begins at the offset - within the file indicated by the character's *offset* value. - @end itemize - @item **Offset.** (32-bit big-endian integer.) +If equal to 001 binary, then the character data is stored within a +compressed character definition block that begins at the offset +within the file indicated by the character's @strong{offset} value. +@end itemize - A marker that indicates the remainder of the file is data accessed via - the character index (CHIX) section. When reading this font file, the rest - of the file can be ignored when scanning the sections. The length should - be set to -1 (0xFFFFFFFF). +@item @strong{Offset.} (32-bit big-endian integer.) - Supported data structures: +A marker that indicates the remainder of the file is data accessed via +the character index (CHIX) section. When reading this font file, the rest +of the file can be ignored when scanning the sections. The length should +be set to -1 (0xFFFFFFFF). - Character definition - Each character definition consists of: +Supported data structures: - @itemize - @item **Width.** Width of the bitmap in pixels. The bitmap's extents - represent the glyph's bounding box. *uint16be*. +Character definition +Each character definition consists of: - @item **Height.** Height of the bitmap in pixels. The bitmap's extents - represent the glyph's bounding box. *uint16be*. +@itemize +@item @strong{Width.} +Width of the bitmap in pixels. The bitmap's extents +represent the glyph's bounding box. @code{uint16be}. - @item **X offset.** The number of pixels to shift the bitmap by - horizontally before drawing the character. *int16be*. +@item @strong{Height.} +Height of the bitmap in pixels. The bitmap's extents +represent the glyph's bounding box. @code{uint16be}. - @item **Y offset.** The number of pixels to shift the bitmap by - vertically before drawing the character. *int16be*. +@item @strong{X offset.} +The number of pixels to shift the bitmap by +horizontally before drawing the character. @code{int16be}. - @item **Device width.** The number of pixels to advance horizontally from - this character's origin to the origin of the next character. - *int16be*. +@item @strong{Y offset.} +The number of pixels to shift the bitmap by +vertically before drawing the character. @code{int16be}. - @item **Bitmap data.** This is encoded as a string of bits. It is - organized as a row-major, top-down, left-to-right bitmap. The most - significant bit of each byte is taken to be the leftmost or uppermost - bit in the byte. For the sake of compact storage, rows are not padded - to byte boundaries (i.e., a single byte may contain bits belonging to - multiple rows). The last byte of the bitmap *is* padded with zero - bits in the bits positions to the right of the last used bit if the - bitmap data does not fill the last byte. +@item @strong{Device width.} +The number of pixels to advance horizontally from +this character's origin to the origin of the next character. +@code{int16be}. + +@item @strong{Bitmap data.} +This is encoded as a string of bits. It is +organized as a row-major, top-down, left-to-right bitmap. The most +significant bit of each byte is taken to be the leftmost or uppermost +bit in the byte. For the sake of compact storage, rows are not padded +to byte boundaries (i.e., a single byte may contain bits belonging to +multiple rows). The last byte of the bitmap @strong{is} padded with zero +bits in the bits positions to the right of the last used bit if the +bitmap data does not fill the last byte. - The length of the *bitmap data* field is (*width* * *height* + 7) / 8 - using integer arithmetic, which is equivalent to ceil(*width* * - *height* / 8) using real number arithmetic. +The length of the @strong{bitmap data} field is (@var{width} * @var{height} + 7) / 8 +using integer arithmetic, which is equivalent to ceil(@var{width} * +@var{height} / 8) using real number arithmetic. - It remains to be determined whether bitmap fonts usually make all - glyph bitmaps the same height, or if smaller glyphs are stored with - bitmaps having a lesser height. In the latter case, the baseline - would have to be used to calculate the location the bitmap should be - anchored at on screen. - @end itemize +It remains to be determined whether bitmap fonts usually make all +glyph bitmaps the same height, or if smaller glyphs are stored with +bitmaps having a lesser height. In the latter case, the baseline +would have to be used to calculate the location the bitmap should be +anchored at on screen. +@end itemize - @end itemize +@end itemize @end table @node Font Metrics @@ -1342,28 +1349,28 @@ The standard file extension for PFF2 font files is ``.pf2``. @itemize @item Ascent. - The distance from the baseline to the top of most characters. - Note that in some cases characters may extend above the ascent. +The distance from the baseline to the top of most characters. +Note that in some cases characters may extend above the ascent. @item Descent. - The distance from the baseline to the bottom of most characters. Note that - in some cases characters may extend below the descent. +The distance from the baseline to the bottom of most characters. Note that +in some cases characters may extend below the descent. @item Leading. - The amount of space, in pixels, to leave between the descent of one line of - text and the ascent of the next line. This metrics is not specified in the - current file format; instead, the font rendering engine calculates a - reasonable leading value based on the other font metrics. +The amount of space, in pixels, to leave between the descent of one line of +text and the ascent of the next line. This metrics is not specified in the +current file format; instead, the font rendering engine calculates a +reasonable leading value based on the other font metrics. @item Horizonal leading. - The amount of space, in pixels, to leave horizontally between the left and - right edges of two adjacent glyphs. The *device width* field determines - the effective leading value that is used to render the font. +The amount of space, in pixels, to leave horizontally between the left and +right edges of two adjacent glyphs. The @strong{device width} field determines +the effective leading value that is used to render the font. @end itemize @image{font_char_metrics,,,,.png} - An illustration of how the various font metrics apply to characters. +An illustration of how the various font metrics apply to characters. @@ -1383,15 +1390,15 @@ The standard file extension for PFF2 font files is ``.pf2``. @node Introduction_2 @section Introduction -The ``gfxmenu`` module provides a graphical menu interface for GRUB 2. It -functions as an alternative to the menu interface provided by the ``normal`` +The @samp{gfxmenu} module provides a graphical menu interface for GRUB 2. It +functions as an alternative to the menu interface provided by the @samp{normal} module, which uses the grub terminal interface to display a menu on a character-oriented terminal. The graphical menu uses the GRUB video API, which is currently for the VESA BIOS extensions (VBE) 2.0+. This is supported on the i386-pc platform. However, the graphical menu itself does not depend on using VBE, so if another -GRUB video driver were implemented, the ``gfxmenu`` graphical menu would work +GRUB video driver were implemented, the @samp{gfxmenu} graphical menu would work on the new video driver as well. @@ -1402,7 +1409,7 @@ on the new video driver as well. @item grub_enter_normal_mode [normal/main.c] @item grub_normal_execute [normal/main.c] @item read_config_file [normal/main.c] -@item (When ``gfxmenu.mod`` is loaded with ``insmod``, it will call ``grub_menu_viewer_register()`` to register itself.) +@item (When @file{gfxmenu.mod} is loaded with @command{insmod}, it will call @code{grub_menu_viewer_register()} to register itself.) @item GRUB_MOD_INIT (gfxmenu) [gfxmenu/gfxmenu.c] @item grub_menu_viewer_register [kern/menu_viewer.c] @item grub_menu_viewer_show_menu [kern/menu_viewer.c] @@ -1422,7 +1429,7 @@ The graphical menu implements a GUI component system that supports a container-based layout system. Components can be added to containers, and containers (which are a type of component) can then be added to other containers, to form a tree of components. Currently, the root component of -this tree is a *canvas* component, which allows manual layout of its child +this tree is a @samp{canvas} component, which allows manual layout of its child components. Components (non-container): @@ -1444,13 +1451,13 @@ Containers: @end itemize The GUI component instances are created by the theme loader in -``gfxmenu/theme_loader.c`` when a theme is loaded. Theme files specify -statements such as ``+vbox@{ +label @{ text="Hello" @} +label@{ text="World" @} @}`` +@file{gfxmenu/theme_loader.c} when a theme is loaded. Theme files specify +statements such as @samp{+vbox@{ +label @{ text="Hello" @} +label@{ text="World" @} @}} to add components to the component tree root. By nesting the component creation statements in the theme file, the instantiated components are nested the same way. -When a component is added to a container, that new child is considered *owned* +When a component is added to a container, that new child is considered @strong{owned} by the container. Great care should be taken if the caller retains a reference to the child component, since it will be destroyed if its parent container is destroyed. A better choice instead of storing a pointer to the @@ -1459,40 +1466,40 @@ Component IDs do not have to be unique (it is often useful to have multiple components with an ID of "__timeout__", for instance). In order to access and use components in the component tree, there are two -functions (defined in ``gfxmenu/gui_util.c``) that are particularly useful: +functions (defined in @file{gfxmenu/gui_util.c}) that are particularly useful: @itemize -@item ``grub_gui_find_by_id (root, id, callback, userdata)``: +@item @code{grub_gui_find_by_id (root, id, callback, userdata)}: - This function ecursively traverses the component tree rooted at *root*, and - for every component that has an ID equal to *id*, calls the function pointed - to by *callback* with the matching component and the void pointer *userdata* - as arguments. The callback function can do whatever is desired to use the - component passed in. +This function ecursively traverses the component tree rooted at @var{root}, and +for every component that has an ID equal to @var{id}, calls the function pointed +to by @var{callback} with the matching component and the void pointer @var{userdata} +as arguments. The callback function can do whatever is desired to use the +component passed in. -@item ``grub_gui_iterate_recursively (root, callback, userdata)``: +@item @code{grub_gui_iterate_recursively (root, callback, userdata)}: - This function calls the function pointed to by *callback* for every - component that is a descendant of *root* in the component tree. When the - callback function is called, the component and the void pointer *userdata* - as arguments. The callback function can do whatever is desired to use the - component passed in. +This function calls the function pointed to by @var{callback} for every +component that is a descendant of @var{root} in the component tree. When the +callback function is called, the component and the void pointer @var{userdata} +as arguments. The callback function can do whatever is desired to use the +component passed in. @end itemize @node Command Line Window @section Command Line Window The terminal window used to provide command line access within the graphical -menu is managed by ``gfxmenu/view.c``. The ``gfxterm`` terminal is used, and +menu is managed by @file{gfxmenu/view.c}. The @samp{gfxterm} terminal is used, and it has been modified to allow rendering to an offscreen render target to allow it to be composed into the double buffering system that the graphical menu view uses. This is bad for performance, however, so it would probably be a good idea to make it possible to temporarily disable double buffering as long as the terminal window is visible. There are still unresolved problems that occur when commands are executed from the terminal window that change the -graphics mode. It's possible that making ``grub_video_restore()`` return to -the graphics mode that was in use before ``grub_video_setup()`` was called +graphics mode. It's possible that making @code{grub_video_restore()} return to +the graphics mode that was in use before @code{grub_video_setup()} was called might fix some of the problems. From 536ce85a8dc2fafbe6694b8664eb9c77b7d1d08e Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Sat, 9 Apr 2011 03:39:47 +0100 Subject: [PATCH 426/869] * docs/grub-dev.texi (Finding your way around): Update for 1.99 build system. (Getting started): GRUB is developed in Bazaar now, not Subversion. (Comment): Fix typo. (Getting started): General copy-editing. (Typical Development Experience): Likewise. (Error Handling): Likewise. (Video API): Likewise. --- ChangeLog | 12 +++++ docs/grub-dev.texi | 117 +++++++++++++++++++++++++-------------------- 2 files changed, 76 insertions(+), 53 deletions(-) diff --git a/ChangeLog b/ChangeLog index 0494fa2c3..4c46f8996 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2011-04-09 Colin Watson + + * docs/grub-dev.texi (Finding your way around): Update for 1.99 + build system. + (Getting started): GRUB is developed in Bazaar now, not Subversion. + + (Comment): Fix typo. + (Getting started): General copy-editing. + (Typical Development Experience): Likewise. + (Error Handling): Likewise. + (Video API): Likewise. + 2011-04-09 Colin Watson * docs/grub-dev.texi: Replace MoinMoin syntax with Texinfo syntax diff --git a/docs/grub-dev.texi b/docs/grub-dev.texi index a7ab6f71a..a45b8b198 100644 --- a/docs/grub-dev.texi +++ b/docs/grub-dev.texi @@ -169,7 +169,7 @@ If a macro is global, its name must be prefixed with GRUB_ and must consist of o All comments shall be C-style comments, of the form @samp{/* @dots{} */}. -Comments shall be placed only on a line be themselves. They shall not be placed together with code, variable declarations, or other non-comment entities. A comment should be placed immediately preceding the entity it describes. +Comments shall be placed only on a line by themselves. They shall not be placed together with code, variable declarations, or other non-comment entities. A comment should be placed immediately preceding the entity it describes. Acceptable: @example @@ -214,74 +214,85 @@ The opening @samp{/*} and closing @samp{*/} should be placed together on a line Here is a brief map of the GRUB code base. -GRUB uses Autoconf, but not (yet) Automake. The top-level build rules are -in @file{configure.ac}, @file{Makefile.in}, and @file{conf/*.rmk}. Each -@file{conf/*.rmk} file represents a particular target configuration, and is -processed into GNU Make rules by @file{genmk.rb} (which you only need to +GRUB uses Autoconf and Automake, with most of the Automake input generated +by AutoGen. The top-level build rules are in @file{configure.ac}, +@file{grub-core/Makefile.core.def}, and @file{Makefile.util.def}. Each +block in a @file{*.def} file represents a build target, and specifies the +source files used to build it on various platforms. The @file{*.def} files +are processed into AutoGen input by @file{gentpl.py} (which you only need to look at if you are extending the build system). If you are adding a new module which follows an existing pattern, such as a new command or a new -filesystem implementation, it is usually easiest to grep @file{conf/*.rmk} -for an existing example of that pattern to find out where it should be -added. +filesystem implementation, it is usually easiest to grep +@file{grub-core/Makefile.core.def} and @file{Makefile.util.def} for an +existing example of that pattern to find out where it should be added. + +In general, code that may be run at boot time is in a subdirectory of +@file{grub-core}, while code that is only run from within a full operating +system is in a subdirectory of the top level. Low-level boot code, such as the MBR implementation on PC BIOS systems, is -in the @file{boot/} directory. +in the @file{grub-core/boot/} directory. -The GRUB kernel is in @file{kern/}. This contains core facilities such as -the device, disk, and file frameworks, environment variable handling, list -processing, and so on. The kernel should contain enough to get up to a -rescue prompt. Header files for kernel facilities, among others, are in -@file{include/}. +The GRUB kernel is in @file{grub-core/kern/}. This contains core facilities +such as the device, disk, and file frameworks, environment variable +handling, list processing, and so on. The kernel should contain enough to +get up to a rescue prompt. Header files for kernel facilities, among +others, are in @file{include/}. -Terminal implementations are in @file{term/}. +Terminal implementations are in @file{grub-core/term/}. -Disk access code is spread across @file{disk/} (for accessing the disk -devices themselves), @file{partmap/} (for interpreting partition table -data), and @file{fs/} (for accessing filesystems). Note that, with the odd -specialised exception, GRUB only contains code to @emph{read} from -filesystems and tries to avoid containing any code to @emph{write} to -filesystems; this lets us confidently assure users that GRUB cannot be -responsible for filesystem corruption. +Disk access code is spread across @file{grub-core/disk/} (for accessing the +disk devices themselves), @file{grub-core/partmap/} (for interpreting +partition table data), and @file{grub-core/fs/} (for accessing filesystems). +Note that, with the odd specialised exception, GRUB only contains code to +@emph{read} from filesystems and tries to avoid containing any code to +@emph{write} to filesystems; this lets us confidently assure users that GRUB +cannot be responsible for filesystem corruption. -PCI and USB bus handling is in @file{bus/}. +PCI and USB bus handling is in @file{grub-core/bus/}. -Video handling code is in @file{video/}. The graphical menu system uses -this heavily, but is in a separate directory, @file{gfxmenu/}. +Video handling code is in @file{grub-core/video/}. The graphical menu +system uses this heavily, but is in a separate directory, +@file{grub-core/gfxmenu/}. -Most commands are implemented by files in @file{commands/}, with the -following exceptions: +Most commands are implemented by files in @file{grub-core/commands/}, with +the following exceptions: @itemize @item -A few core commands live in @file{kern/corecmd.c}. +A few core commands live in @file{grub-core/kern/corecmd.c}. @item -Commands related to normal mode live under @file{normal/}. +Commands related to normal mode live under @file{grub-core/normal/}. @item -Commands that load and boot kernels live under @file{loader/}. +Commands that load and boot kernels live under @file{grub-core/loader/}. @item The @samp{loopback} command is really a disk device, and so lives in -@file{disk/loopback.c}. +@file{grub-core/disk/loopback.c}. @item -The @samp{gettext} command lives under @file{gettext/}. +The @samp{gettext} command lives under @file{grub-core/gettext/}. @item -The @samp{loadfont} and @samp{lsfonts} commands live under @file{font/}. +The @samp{loadfont} and @samp{lsfonts} commands live under +@file{grub-core/font/}. @item The @samp{serial}, @samp{terminfo}, and @samp{background_image} commands -live under @file{term/}. +live under @file{grub-core/term/}. @item -The @samp{efiemu_*} commands live under @file{efiemu/}. +The @samp{efiemu_*} commands live under @file{grub-core/efiemu/}. @end itemize There are a few other special-purpose exceptions; grep for them if they matter to you. +Utility programs meant to be run from a full operating system are in +@file{util/}. + @node Contributing Changes @chapter Contributing changes @c By YoshinoriOkuji, VesaJääskeläinen, ColinWatson @@ -317,10 +328,10 @@ anymore. @itemize @item Always use latest GRUB 2 source code. So get that first. -For developers it is recommended always to use the newest development version of GRUB 2. If development takes a long period of time, please remember to keep in sync with newest developments regularly so it is much easier to integrate your change in the future. GRUB 2 is being developed on SVN repository. +For developers it is recommended always to use the newest development version of GRUB 2. If development takes a long period of time, please remember to keep in sync with newest developments regularly so it is much easier to integrate your change in the future. GRUB 2 is being developed in a Bazaar (bzr) repository. -Please check Savannah's GRUB project page for details how to get newest BZR: -@uref{http://savannah.gnu.org/bzr/?group=grub, GRUB 2 BZR Repository} +Please check Savannah's GRUB project page for details how to get newest bzr: +@uref{http://savannah.gnu.org/bzr/?group=grub, GRUB 2 bzr Repository} @item Compile it and try it out. @@ -342,7 +353,7 @@ be free to develop it. If you have not so far announced your idea on grub-devel mailing list, please do it now. This is to make sure you are not wasting your time working on the solution that will not be integrated to GRUB 2 code base. -You might want to study our coding style before starting to development so you +You might want to study our coding style before starting development so you do not need to change much of the code when your patch is being reviewed. (see @ref{Coding style}) @@ -357,11 +368,11 @@ discuss it beforehand on grub-devel mailing list. @item Test your change. -Test that your change works properly. Try it out couple of times. Preferably on different systems. And try to find problems from it. +Test that your change works properly. Try it out a couple of times, preferably on different systems, and try to find problems with it. @item Publish your change. -When you are happy with your change. First make sure it is compilable with +When you are happy with your change, first make sure it is compilable with latest development version of GRUB 2. After that please send a patch to grub-devel for review. Please describe in your email why you made the change, what it changes and so on. Please be prepared to receive even discouraging @@ -379,15 +390,15 @@ for copyright agreement, process can take some time and is mandatory in order to get your changes integrated. If you are not on grub-devel to respond to questions, most likely your patch -will not be accepted. Also if there comes problems from your changes later on, -it would be preferably that you also fix the problem. So stay around +will not be accepted. Also if problems arise from your changes later on, +it would be preferable that you also fix the problem. So stay around for a while. @item Your patch is accepted. -Good job! Your patch will no be integrated to GRUB 2 main line and if it didn't break a thing it will be publically available when next release will be done. +Good job! Your patch will now be integrated into GRUB 2 mainline, and if it didn't break anything it will be publicly available in the next release. -Now you are welcomed to do further improvements :) +Now you are welcome to do further improvements :) @end itemize @node Typical Developer Experience @@ -400,7 +411,7 @@ The typical experience for a developer in this project is the following: @item You show some result in the mailing list or the IRC. @item You are getting to be known to other developers. @item You accumulate significant amount of contribution, so copyright assignment is processed. -@item You are free to check in your changes by your own, legally speaking. +@item You are free to check in your changes on your own, legally speaking. @end enumerate At this point, it is rather annoying that you ought to ask somebody else every @@ -444,7 +455,7 @@ doesn't direcly support exceptions, exception handling behavior is emulated in software. When exception is raised, function must return to calling function. If calling -function does not provide handling of the exception it must return back to it's +function does not provide handling of the exception it must return back to its calling function and so on, until exception is handled. If exception is not handled before prompt is displayed, error message will be shown to user. @@ -541,11 +552,11 @@ error state and then call other functions that might fail. To aid in this, there is a error stack implemented. Error state can be pushed to error stack by calling function @code{grub_error_push ()}. When processing has been completed, @code{grub_error_pop ()} can be used to pop error state from stack. Error stack -contains predefined amount of error stack items. Error stack is proteced for +contains predefined amount of error stack items. Error stack is protected for overflow and marks these situations so overflow error does not get unseen. If there is no space available to store error message, it is simply discarded and overflow will be marked as happened. When overflow happens, it most likely -will corrupt error stack consistency as for pushed error there is no matching +will corrupt error stack consistency as for pushed error there is no matching pop, but overflow message will be shown to inform user about the situation. Overflow message will be shown at time when prompt is about to be drawn. @@ -646,7 +657,7 @@ grub_video_setup (unsigned int width, unsigned int height, unsigned int mode_typ Driver will use information provided to it to select best possible video mode and switch to it. Supported values for @code{mode_type} are @code{GRUB_VIDEO_MODE_TYPE_INDEX_COLOR} for index color modes, @code{GRUB_VIDEO_MODE_TYPE_RGB} for direct RGB color modes and @code{GRUB_VIDEO_MODE_TYPE_DOUBLE_BUFFERED} for double buffering. When requesting RGB mode, highest bits per pixel mode will be selected. When requesting Index color mode, mode with highest number of colors will be selected. If all parameters are specified as zero, video adapter will try to figure out best possible mode and initialize it, platform specific differences are allowed here. If there is no mode matching request, error X will be returned. If there are no problems, function returns @code{GRUB_ERR_NONE}. -This function also performs following task upon succesful mode switch. Active rendering target is changed to screen and viewport is maximized to allow whole screen to be used when performing graphics operations. In RGB modes, emulated palette get's 16 entries containing default values for VGA palette, other colors are defined as black. When switching to Indexed Color mode, driver may set default VGA palette to screen if the video card allows the operation. +This function also performs following task upon succesful mode switch. Active rendering target is changed to screen and viewport is maximized to allow whole screen to be used when performing graphics operations. In RGB modes, emulated palette gets 16 entries containing default values for VGA palette, other colors are defined as black. When switching to Indexed Color mode, driver may set default VGA palette to screen if the video card allows the operation. @end itemize @@ -836,7 +847,7 @@ grub_video_map_rgb (grub_uint8_t red, grub_uint8_t green, grub_uint8_t blue); @end example @item Description: -Map RGB values to compatible screen color data. Values are excepted to be in range 0-255 and in RGB modes they will be converted to screen color data. In index color modes, index color palette will be searched for specified color and then index is returned. +Map RGB values to compatible screen color data. Values are expected to be in range 0-255 and in RGB modes they will be converted to screen color data. In index color modes, index color palette will be searched for specified color and then index is returned. @end itemize @subsection grub_video_map_rgba @@ -849,7 +860,7 @@ grub_video_map_rgba (grub_uint8_t red, grub_uint8_t green, grub_uint8_t blue, gr @end example @item Description: -Map RGBA values to compatible screen color data. Values are excepted to be in range 0-255. In RGBA modes they will be converted to screen color data. In index color modes, index color palette will be searched for best matching color and it's index is returned. +Map RGBA values to compatible screen color data. Values are expected to be in range 0-255. In RGBA modes they will be converted to screen color data. In index color modes, index color palette will be searched for best matching color and its index is returned. @end itemize @subsection grub_video_unmap_color @@ -1016,7 +1027,7 @@ grub_video_set_active_render_target (struct grub_video_render_target *target); @end example @item Description: -Set's active render target. If this comand is successful all drawing commands will be done to specified @code{target}. There is also special values for target, @code{GRUB_VIDEO_RENDER_TARGET_DISPLAY} used to reference screen's front buffer, @code{GRUB_VIDEO_RENDER_TARGET_FRONT_BUFFER} used to reference screen's front buffer (alias for @code{GRUB_VIDEO_RENDER_TARGET_DISPLAY}) and @code{GRUB_VIDEO_RENDER_TARGET_BACK_BUFFER} used to reference back buffer (if double buffering is enabled). If render target is correclty switched GRUB_ERR_NONE is returned. In no any event shall there be non drawable active render target. +Sets active render target. If this comand is successful all drawing commands will be done to specified @code{target}. There is also special values for target, @code{GRUB_VIDEO_RENDER_TARGET_DISPLAY} used to reference screen's front buffer, @code{GRUB_VIDEO_RENDER_TARGET_FRONT_BUFFER} used to reference screen's front buffer (alias for @code{GRUB_VIDEO_RENDER_TARGET_DISPLAY}) and @code{GRUB_VIDEO_RENDER_TARGET_BACK_BUFFER} used to reference back buffer (if double buffering is enabled). If render target is correclty switched GRUB_ERR_NONE is returned. In no any event shall there be non drawable active render target. @end itemize @subsection grub_video_get_active_render_target From 099821e9e4d55abe11054380068decda0cec4a17 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 9 Apr 2011 21:55:50 +0200 Subject: [PATCH 427/869] Fix RAID1/duplicated chunk size calculation --- grub-core/fs/btrfs.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/grub-core/fs/btrfs.c b/grub-core/fs/btrfs.c index ac90c055a..7632d535c 100644 --- a/grub-core/fs/btrfs.c +++ b/grub-core/fs/btrfs.c @@ -664,13 +664,9 @@ grub_btrfs_read_logical (struct grub_btrfs_data *data, case GRUB_BTRFS_CHUNK_TYPE_RAID1: /* FIXME: Use redundancy. */ { - grub_uint32_t stripe_length; - stripe_length = grub_divmod64 (grub_le_to_cpu64 (chunk->size), - grub_le_to_cpu16 (chunk->nstripes), - NULL); stripen = 0; stripe_offset = off; - csize = stripe_length - off; + csize = grub_le_to_cpu64 (chunk->size) - off; redundancy = 2; break; } From 277f955bf115a516fa464fec3e92f919c48f05bf Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 10 Apr 2011 11:57:19 +0200 Subject: [PATCH 428/869] * grub-core/boot/mips/yeeloong/fwstart.S: Fix address to error message. Remove now unused string. --- ChangeLog | 5 +++++ grub-core/boot/mips/yeeloong/fwstart.S | 3 +-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4c46f8996..1bb8cf278 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-04-10 Vladimir Serbinenko + + * grub-core/boot/mips/yeeloong/fwstart.S: Fix address to error message. + Remove now unused string. + 2011-04-09 Colin Watson * docs/grub-dev.texi (Finding your way around): Update for 1.99 diff --git a/grub-core/boot/mips/yeeloong/fwstart.S b/grub-core/boot/mips/yeeloong/fwstart.S index 425458401..e2aa79759 100644 --- a/grub-core/boot/mips/yeeloong/fwstart.S +++ b/grub-core/boot/mips/yeeloong/fwstart.S @@ -120,7 +120,7 @@ __start: ori $t0, $zero, GRUB_SMBUS_SPD_MEMORY_TYPE_DDR2 lui $a0, %hi(unimplemented_memory_type) bne $t0, $v0, fatal - addiu $a0, $a0, %hi(unimplemented_memory_type) + addiu $a0, $a0, %lo(unimplemented_memory_type) /* And here is our goal: DDR2 controller initialisation. */ lui $t0, %hi(GRUB_CPU_LOONGSON_CORECFG) @@ -379,7 +379,6 @@ read_spd_fail: ori $v0, $v0, 0x100 notification_string: .asciz "GRUB " -no_cs5536: .asciz "No CS5536 found.\n\r" cs5536_found: .asciz "CS5536 at " sm_failed: .asciz "SM transaction failed.\n\r" unhandled_tlb_refill: .asciz "Unhandled TLB refill.\n\r" From 8b8a81fa6a600c743ef0a34122f127671a5a5bfc Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 10 Apr 2011 13:56:23 +0200 Subject: [PATCH 429/869] Dynamically count the number of lines for the lower banner. * grub-core/normal/menu_entry.c (per_term_screen): New member num_entries. (print_down): Use num_entries. (update_screen): Likewise. (grub_menu_entry_run): Set num_entries. * grub-core/normal/menu_text.c (menu_viewer_data): New member num_entries. (grub_print_message_indented): Move real part to ... (grub_print_message_indented_real): ... here. Additional argument dry_run. (draw_border): Additional argument num_entries. (print_message): Additional argument dry_run. (print_entries): Receive menu viewer data. (grub_menu_init_page): New argment num_entries. (menu_text_set_chosen_entry): Use num_entries. (grub_menu_try_text): Likewise. * grub-core/normal/term.c (print_ucs4_terminal): New argument dry_run. All users updated. (grub_ucs4_count_lines): New function. * include/grub/term.h (grub_term_cursor_x): Moved from here .. * grub-core/normal/menu_text.c (grub_term_cursor_x): ... to here. * include/grub/term.h (GRUB_TERM_MESSAGE_HEIGHT): Removed. (grub_term_border_height): Likewise. (grub_term_num_entries): Likewise. --- ChangeLog | 29 +++++++ grub-core/normal/menu_entry.c | 20 ++--- grub-core/normal/menu_text.c | 145 +++++++++++++++++++++------------- grub-core/normal/term.c | 136 +++++++++++++++++++------------ include/grub/normal.h | 7 +- include/grub/term.h | 26 ------ 6 files changed, 225 insertions(+), 138 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1bb8cf278..3f4913ec1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,32 @@ +2011-04-10 Vladimir Serbinenko + + Dynamically count the number of lines for the lower banner. + + * grub-core/normal/menu_entry.c (per_term_screen): New member + num_entries. + (print_down): Use num_entries. + (update_screen): Likewise. + (grub_menu_entry_run): Set num_entries. + * grub-core/normal/menu_text.c (menu_viewer_data): New member + num_entries. + (grub_print_message_indented): Move real part to ... + (grub_print_message_indented_real): ... here. Additional argument + dry_run. + (draw_border): Additional argument num_entries. + (print_message): Additional argument dry_run. + (print_entries): Receive menu viewer data. + (grub_menu_init_page): New argment num_entries. + (menu_text_set_chosen_entry): Use num_entries. + (grub_menu_try_text): Likewise. + * grub-core/normal/term.c (print_ucs4_terminal): New argument dry_run. + All users updated. + (grub_ucs4_count_lines): New function. + * include/grub/term.h (grub_term_cursor_x): Moved from here .. + * grub-core/normal/menu_text.c (grub_term_cursor_x): ... to here. + * include/grub/term.h (GRUB_TERM_MESSAGE_HEIGHT): Removed. + (grub_term_border_height): Likewise. + (grub_term_num_entries): Likewise. + 2011-04-10 Vladimir Serbinenko * grub-core/boot/mips/yeeloong/fwstart.S: Fix address to error message. diff --git a/grub-core/normal/menu_entry.c b/grub-core/normal/menu_entry.c index 30af2c1dc..dc5ab528f 100644 --- a/grub-core/normal/menu_entry.c +++ b/grub-core/normal/menu_entry.c @@ -52,6 +52,8 @@ struct per_term_screen int x; /* The Y coordinate. */ int y; + /* Number of entries. */ + int num_entries; }; struct screen @@ -188,7 +190,7 @@ print_down (int flag, struct per_term_screen *term_screen) grub_term_gotoxy (term_screen->term, GRUB_TERM_LEFT_BORDER_X + grub_term_border_width (term_screen->term), GRUB_TERM_TOP_BORDER_Y - + grub_term_num_entries (term_screen->term)); + + term_screen->num_entries); if (flag) grub_putcode (GRUB_UNICODE_DOWNARROW, term_screen->term); @@ -209,13 +211,12 @@ update_screen (struct screen *screen, struct per_term_screen *term_screen, struct line *linep; /* Check if scrolling is necessary. */ - if (term_screen->y < 0 || term_screen->y - >= grub_term_num_entries (term_screen->term)) + if (term_screen->y < 0 || term_screen->y >= term_screen->num_entries) { if (term_screen->y < 0) term_screen->y = 0; else - term_screen->y = grub_term_num_entries (term_screen->term) - 1; + term_screen->y = term_screen->num_entries - 1; region_start = 0; region_column = 0; @@ -251,7 +252,7 @@ update_screen (struct screen *screen, struct per_term_screen *term_screen, for (column = 0; column <= linep->len - && y < grub_term_num_entries (term_screen->term); + && y < term_screen->num_entries; column += grub_term_entry_width (term_screen->term), y++) { if (y < 0) @@ -272,7 +273,7 @@ update_screen (struct screen *screen, struct per_term_screen *term_screen, print_line (linep, column, 0, y, term_screen); } - if (y == grub_term_num_entries (term_screen->term)) + if (y == term_screen->num_entries) { if (column <= linep->len || i + 1 < screen->num_lines) down_flag = 1; @@ -282,11 +283,11 @@ update_screen (struct screen *screen, struct per_term_screen *term_screen, i++; if (mode == ALL_LINES && i == screen->num_lines) - for (; y < grub_term_num_entries (term_screen->term); y++) + for (; y < term_screen->num_entries; y++) print_empty_line (y, term_screen); } - while (y < grub_term_num_entries (term_screen->term)); + while (y < term_screen->num_entries); /* Draw up and down arrows. */ if (up) @@ -1290,7 +1291,8 @@ grub_menu_entry_run (grub_menu_entry_t entry) } /* Draw the screen. */ for (i = 0; i < screen->nterms; i++) - grub_menu_init_page (0, 1, screen->terms[i].term); + grub_menu_init_page (0, 1, &screen->terms[i].num_entries, + screen->terms[i].term); update_screen_all (screen, 0, 0, 1, 1, ALL_LINES); for (i = 0; i < screen->nterms; i++) grub_term_setcursor (screen->terms[i].term, 1); diff --git a/grub-core/normal/menu_text.c b/grub-core/normal/menu_text.c index fc4a89196..93f0492bc 100644 --- a/grub-core/normal/menu_text.c +++ b/grub-core/normal/menu_text.c @@ -34,10 +34,19 @@ static grub_uint8_t grub_color_menu_highlight; struct menu_viewer_data { int first, offset; + /* The number of entries shown at a time. */ + int num_entries; grub_menu_t menu; struct grub_term_output *term; }; +static inline int +grub_term_cursor_x (struct grub_term_output *term) +{ + return (GRUB_TERM_LEFT_BORDER_X + grub_term_border_width (term) + - GRUB_TERM_MARGIN - 1); +} + grub_ssize_t grub_getstringwidth (grub_uint32_t * str, const grub_uint32_t * last_position, struct grub_term_output *term) @@ -53,30 +62,45 @@ grub_getstringwidth (grub_uint32_t * str, const grub_uint32_t * last_position, return width; } -void -grub_print_message_indented (const char *msg, int margin_left, int margin_right, - struct grub_term_output *term) +static int +grub_print_message_indented_real (const char *msg, int margin_left, + int margin_right, + struct grub_term_output *term, int dry_run) { grub_uint32_t *unicode_msg; grub_uint32_t *last_position; int msg_len; + int ret = 0; msg_len = grub_utf8_to_ucs4_alloc (msg, &unicode_msg, &last_position); if (msg_len < 0) { - return; + return 0; } - grub_print_ucs4 (unicode_msg, last_position, margin_left, margin_right, term); + if (dry_run) + ret = grub_ucs4_count_lines (unicode_msg, last_position, margin_left, + margin_right, term); + else + grub_print_ucs4 (unicode_msg, last_position, margin_left, + margin_right, term); grub_free (unicode_msg); + + return ret; } +void +grub_print_message_indented (const char *msg, int margin_left, int margin_right, + struct grub_term_output *term) +{ + grub_print_message_indented_real (msg, margin_left, margin_right, term, 0); +} static void -draw_border (struct grub_term_output *term) +draw_border (struct grub_term_output *term, int num_entries) { unsigned i; @@ -88,7 +112,7 @@ draw_border (struct grub_term_output *term) grub_putcode (GRUB_UNICODE_HLINE, term); grub_putcode (GRUB_UNICODE_CORNER_UR, term); - for (i = 0; i < (unsigned) grub_term_num_entries (term); i++) + for (i = 0; i < (unsigned) num_entries; i++) { grub_term_gotoxy (term, GRUB_TERM_MARGIN, GRUB_TERM_TOP_BORDER_Y + i + 1); grub_putcode (GRUB_UNICODE_VLINE, term); @@ -99,7 +123,7 @@ draw_border (struct grub_term_output *term) } grub_term_gotoxy (term, GRUB_TERM_MARGIN, - GRUB_TERM_TOP_BORDER_Y + grub_term_num_entries (term) + 1); + GRUB_TERM_TOP_BORDER_Y + num_entries + 1); grub_putcode (GRUB_UNICODE_CORNER_LL, term); for (i = 0; i < (unsigned) grub_term_border_width (term) - 2; i++) grub_putcode (GRUB_UNICODE_HLINE, term); @@ -108,22 +132,27 @@ draw_border (struct grub_term_output *term) grub_term_setcolorstate (term, GRUB_TERM_COLOR_NORMAL); grub_term_gotoxy (term, GRUB_TERM_MARGIN, - (GRUB_TERM_TOP_BORDER_Y + grub_term_num_entries (term) + (GRUB_TERM_TOP_BORDER_Y + num_entries + GRUB_TERM_MARGIN + 1)); } -static void -print_message (int nested, int edit, struct grub_term_output *term) +static int +print_message (int nested, int edit, struct grub_term_output *term, int dry_run) { + int ret = 0; grub_term_setcolorstate (term, GRUB_TERM_COLOR_NORMAL); if (edit) { - grub_putcode ('\n', term); - grub_print_message_indented (_("Minimum Emacs-like screen editing is \ + if(dry_run) + ret++; + else + grub_putcode ('\n', term); + ret += grub_print_message_indented_real (_("Minimum Emacs-like screen editing is \ supported. TAB lists completions. Press Ctrl-x or F10 to boot, Ctrl-c or F2 for a \ command-line or ESC to discard edits and return to the GRUB menu."), - STANDARD_MARGIN, STANDARD_MARGIN, term); + STANDARD_MARGIN, STANDARD_MARGIN, + term, dry_run); } else { @@ -134,30 +163,34 @@ command-line or ESC to discard edits and return to the GRUB menu."), msg_translated = grub_xasprintf (msg, GRUB_UNICODE_UPARROW, GRUB_UNICODE_DOWNARROW); if (!msg_translated) - return; - grub_putcode ('\n', term); - grub_print_message_indented (msg_translated, STANDARD_MARGIN, - STANDARD_MARGIN, term); + return 0; + if(dry_run) + ret++; + else + grub_putcode ('\n', term); + ret += grub_print_message_indented_real (msg_translated, STANDARD_MARGIN, + STANDARD_MARGIN, term, dry_run); grub_free (msg_translated); if (nested) { - grub_print_message_indented + ret += grub_print_message_indented_real (_("Press enter to boot the selected OS, " "\'e\' to edit the commands before booting " "or \'c\' for a command-line. ESC to return previous menu.\n"), - STANDARD_MARGIN, STANDARD_MARGIN, term); + STANDARD_MARGIN, STANDARD_MARGIN, term, dry_run); } else { - grub_print_message_indented + ret += grub_print_message_indented_real (_("Press enter to boot the selected OS, " "\'e\' to edit the commands before booting " "or \'c\' for a command-line.\n"), - STANDARD_MARGIN, STANDARD_MARGIN, term); + STANDARD_MARGIN, STANDARD_MARGIN, term, dry_run); } } + return ret; } static void @@ -256,52 +289,56 @@ print_entry (int y, int highlight, grub_menu_entry_t entry, } static void -print_entries (grub_menu_t menu, int first, int offset, - struct grub_term_output *term) +print_entries (grub_menu_t menu, const struct menu_viewer_data *data) { grub_menu_entry_t e; int i; - grub_term_gotoxy (term, - GRUB_TERM_LEFT_BORDER_X + grub_term_border_width (term), + grub_term_gotoxy (data->term, + GRUB_TERM_LEFT_BORDER_X + grub_term_border_width (data->term), GRUB_TERM_FIRST_ENTRY_Y); - if (first) - grub_putcode (GRUB_UNICODE_UPARROW, term); + if (data->first) + grub_putcode (GRUB_UNICODE_UPARROW, data->term); else - grub_putcode (' ', term); + grub_putcode (' ', data->term); - e = grub_menu_get_entry (menu, first); + e = grub_menu_get_entry (menu, data->first); - for (i = 0; i < grub_term_num_entries (term); i++) + for (i = 0; i < data->num_entries; i++) { - print_entry (GRUB_TERM_FIRST_ENTRY_Y + i, offset == i, e, term); + print_entry (GRUB_TERM_FIRST_ENTRY_Y + i, data->offset == i, + e, data->term); if (e) e = e->next; } - grub_term_gotoxy (term, GRUB_TERM_LEFT_BORDER_X - + grub_term_border_width (term), - GRUB_TERM_TOP_BORDER_Y + grub_term_num_entries (term)); + grub_term_gotoxy (data->term, GRUB_TERM_LEFT_BORDER_X + + grub_term_border_width (data->term), + GRUB_TERM_TOP_BORDER_Y + data->num_entries); if (e) - grub_putcode (GRUB_UNICODE_DOWNARROW, term); + grub_putcode (GRUB_UNICODE_DOWNARROW, data->term); else - grub_putcode (' ', term); + grub_putcode (' ', data->term); - grub_term_gotoxy (term, grub_term_cursor_x (term), - GRUB_TERM_FIRST_ENTRY_Y + offset); + grub_term_gotoxy (data->term, grub_term_cursor_x (data->term), + GRUB_TERM_FIRST_ENTRY_Y + data->offset); } /* Initialize the screen. If NESTED is non-zero, assume that this menu is run from another menu or a command-line. If EDIT is non-zero, show a message for the menu entry editor. */ void -grub_menu_init_page (int nested, int edit, +grub_menu_init_page (int nested, int edit, int *num_entries, struct grub_term_output *term) { grub_uint8_t old_color_normal, old_color_highlight; + /* 3 lines for timeout message and bottom margin. 2 lines for the border. */ + *num_entries = grub_term_height (term) - GRUB_TERM_TOP_BORDER_Y + - (print_message (nested, edit, term, 1) + 3) - 2; + grub_term_getcolor (term, &old_color_normal, &old_color_highlight); /* By default, use the same colors for the menu. */ @@ -316,9 +353,9 @@ grub_menu_init_page (int nested, int edit, grub_normal_init_page (term); grub_term_setcolor (term, grub_color_menu_normal, grub_color_menu_highlight); - draw_border (term); + draw_border (term, *num_entries); grub_term_setcolor (term, old_color_normal, old_color_highlight); - print_message (nested, edit, term); + print_message (nested, edit, term, 0); } static void @@ -359,10 +396,10 @@ menu_text_set_chosen_entry (int entry, void *dataptr) int complete_redraw = 0; data->offset = entry - data->first; - if (data->offset > grub_term_num_entries (data->term) - 1) + if (data->offset > data->num_entries - 1) { - data->first = entry - (grub_term_num_entries (data->term) - 1); - data->offset = grub_term_num_entries (data->term) - 1; + data->first = entry - (data->num_entries - 1); + data->offset = data->num_entries - 1; complete_redraw = 1; } if (data->offset < 0) @@ -372,7 +409,7 @@ menu_text_set_chosen_entry (int entry, void *dataptr) complete_redraw = 1; } if (complete_redraw) - print_entries (data->menu, data->first, data->offset, data->term); + print_entries (data->menu, data); else { print_entry (GRUB_TERM_FIRST_ENTRY_Y + oldoffset, 0, @@ -436,15 +473,17 @@ grub_menu_try_text (struct grub_term_output *term, data->offset = entry; data->first = 0; - if (data->offset > grub_term_num_entries (data->term) - 1) - { - data->first = data->offset - (grub_term_num_entries (data->term) - 1); - data->offset = grub_term_num_entries (data->term) - 1; - } grub_term_setcursor (data->term, 0); - grub_menu_init_page (nested, 0, data->term); - print_entries (menu, data->first, data->offset, data->term); + grub_menu_init_page (nested, 0, &data->num_entries, data->term); + + if (data->offset > data->num_entries - 1) + { + data->first = data->offset - (data->num_entries - 1); + data->offset = data->num_entries - 1; + } + + print_entries (menu, data); grub_term_refresh (data->term); grub_menu_register_viewer (instance); diff --git a/grub-core/normal/term.c b/grub-core/normal/term.c index 9c4b491f5..a8b9e6683 100644 --- a/grub-core/normal/term.c +++ b/grub-core/normal/term.c @@ -515,14 +515,16 @@ print_ucs4_terminal (const grub_uint32_t * str, const grub_uint32_t * last_position, int margin_left, int margin_right, struct grub_term_output *term, - struct term_state *state) + struct term_state *state, + int dry_run) { const grub_uint32_t *ptr; - grub_ssize_t startwidth = get_startwidth (term, margin_left); + grub_ssize_t startwidth = dry_run ? 0 : get_startwidth (term, margin_left); grub_ssize_t line_width = startwidth; grub_ssize_t lastspacewidth = 0; grub_ssize_t max_width = get_maxwidth (term, margin_left, margin_right); const grub_uint32_t *line_start = str, *last_space = str - 1; + int lines = 0; for (ptr = str; ptr < last_position; ptr++) { @@ -560,50 +562,59 @@ print_ucs4_terminal (const grub_uint32_t * str, else lastspacewidth = line_width - last_width; - for (ptr2 = line_start; ptr2 < ptr; ptr2++) - { - /* Skip combining characters on non-UTF8 terminals. */ - if ((term->flags & GRUB_TERM_CODE_TYPE_MASK) - != GRUB_TERM_CODE_TYPE_UTF8_LOGICAL - && grub_unicode_get_comb_type (*ptr2) - != GRUB_UNICODE_COMB_NONE) - continue; - putcode_real (*ptr2, term); - } + lines++; - grub_print_spaces (term, margin_right); - grub_putcode ('\n', term); - if (state && ++state->num_lines - >= (grub_ssize_t) grub_term_height (term) - 2) + if (!dry_run) { - state->backlog_ucs4 = (ptr == last_space || *ptr == '\n') - ? ptr + 1 : ptr; - state->backlog_len = last_position - state->backlog_ucs4; - return 1; + for (ptr2 = line_start; ptr2 < ptr; ptr2++) + { + /* Skip combining characters on non-UTF8 terminals. */ + if ((term->flags & GRUB_TERM_CODE_TYPE_MASK) + != GRUB_TERM_CODE_TYPE_UTF8_LOGICAL + && grub_unicode_get_comb_type (*ptr2) + != GRUB_UNICODE_COMB_NONE) + continue; + putcode_real (*ptr2, term); + } + + grub_print_spaces (term, margin_right); + grub_putcode ('\n', term); + if (state && ++state->num_lines + >= (grub_ssize_t) grub_term_height (term) - 2) + { + state->backlog_ucs4 = (ptr == last_space || *ptr == '\n') + ? ptr + 1 : ptr; + state->backlog_len = last_position - state->backlog_ucs4; + return 1; + } } line_width -= lastspacewidth; - grub_print_spaces (term, margin_left); + if (!dry_run) + grub_print_spaces (term, margin_left); if (ptr == last_space || *ptr == '\n') ptr++; line_start = ptr; } } - { - const grub_uint32_t *ptr2; - for (ptr2 = line_start; ptr2 < last_position; ptr2++) - { - /* Skip combining characters on non-UTF8 terminals. */ - if ((term->flags & GRUB_TERM_CODE_TYPE_MASK) - != GRUB_TERM_CODE_TYPE_UTF8_LOGICAL - && grub_unicode_get_comb_type (*ptr2) - != GRUB_UNICODE_COMB_NONE) - continue; - putcode_real (*ptr2, term); - } - } - return 0; + if (line_start < last_position) + lines++; + if (!dry_run) + { + const grub_uint32_t *ptr2; + for (ptr2 = line_start; ptr2 < last_position; ptr2++) + { + /* Skip combining characters on non-UTF8 terminals. */ + if ((term->flags & GRUB_TERM_CODE_TYPE_MASK) + != GRUB_TERM_CODE_TYPE_UTF8_LOGICAL + && grub_unicode_get_comb_type (*ptr2) + != GRUB_UNICODE_COMB_NONE) + continue; + putcode_real (*ptr2, term); + } + } + return dry_run ? lines : 0; } static struct term_state * @@ -672,7 +683,7 @@ print_backlog (struct grub_term_output *term, int ret; ret = print_ucs4_terminal (state->backlog_ucs4, state->backlog_ucs4 + state->backlog_len, - margin_left, margin_right, term, state); + margin_left, margin_right, term, state, 0); if (!ret) { grub_free (state->free); @@ -706,15 +717,19 @@ static int print_ucs4_real (const grub_uint32_t * str, const grub_uint32_t * last_position, int margin_left, int margin_right, - struct grub_term_output *term, int backlog) + struct grub_term_output *term, int backlog, + int dry_run) { struct term_state *state = NULL; - if (backlog) - state = find_term_state (term); + if (!dry_run) + { + if (backlog) + state = find_term_state (term); - if (((term->getxy (term) >> 8) & 0xff) < margin_left) - grub_print_spaces (term, margin_left - ((term->getxy (term) >> 8) & 0xff)); + if (((term->getxy (term) >> 8) & 0xff) < margin_left) + grub_print_spaces (term, margin_left - ((term->getxy (term) >> 8) & 0xff)); + } if ((term->flags & GRUB_TERM_CODE_TYPE_MASK) == GRUB_TERM_CODE_TYPE_VISUAL_GLYPHS @@ -743,16 +758,30 @@ print_ucs4_real (const grub_uint32_t * str, grub_print_error (); return 0; } - ret = put_glyphs_terminal (visual, visual_len, margin_left, margin_right, - term, state); - if (!ret) - grub_free (visual); + if (dry_run) + { + struct grub_unicode_glyph *vptr; + ret = 0; + for (vptr = visual; vptr < visual + visual_len; vptr++) + if (vptr->base == '\n') + ret++; + if (visual_len && visual[visual_len - 1].base != '\n') + ret++; + grub_free (visual); + } else - state->free = visual; + { + ret = put_glyphs_terminal (visual, visual_len, margin_left, + margin_right, term, state); + if (!ret) + grub_free (visual); + else + state->free = visual; + } return ret; } return print_ucs4_terminal (str, last_position, margin_left, margin_right, - term, state); + term, state, dry_run); } void @@ -762,9 +791,18 @@ grub_print_ucs4 (const grub_uint32_t * str, struct grub_term_output *term) { print_ucs4_real (str, last_position, margin_left, margin_right, - term, 0); + term, 0, 0); } +int +grub_ucs4_count_lines (const grub_uint32_t * str, + const grub_uint32_t * last_position, + int margin_left, int margin_right, + struct grub_term_output *term) +{ + return print_ucs4_real (str, last_position, margin_left, margin_right, + term, 0, 1); +} void grub_xputs_normal (const char *str) @@ -813,7 +851,7 @@ grub_xputs_normal (const char *str) { int cur; cur = print_ucs4_real (unicode_str, unicode_last_position, 0, 0, - term, grub_more); + term, grub_more, 0); if (cur) backlog = 1; } diff --git a/include/grub/normal.h b/include/grub/normal.h index 3b99e073a..08c14d209 100644 --- a/include/grub/normal.h +++ b/include/grub/normal.h @@ -51,7 +51,7 @@ extern int grub_normal_exit_level; /* Defined in `main.c'. */ void grub_enter_normal_mode (const char *config); void grub_normal_execute (const char *config, int nested, int batch); -void grub_menu_init_page (int nested, int edit, +void grub_menu_init_page (int nested, int edit, int *num_entries, struct grub_term_output *term); void grub_normal_init_page (struct grub_term_output *term); char *grub_file_getline (grub_file_t file); @@ -80,6 +80,11 @@ grub_print_ucs4 (const grub_uint32_t * str, const grub_uint32_t * last_position, int margin_left, int margin_right, struct grub_term_output *term); +int +grub_ucs4_count_lines (const grub_uint32_t * str, + const grub_uint32_t * last_position, + int margin_left, int margin_right, + struct grub_term_output *term); grub_ssize_t grub_getstringwidth (grub_uint32_t * str, const grub_uint32_t * last_position, struct grub_term_output *term); diff --git a/include/grub/term.h b/include/grub/term.h index dbcb2f52c..726c84dbf 100644 --- a/include/grub/term.h +++ b/include/grub/term.h @@ -140,9 +140,6 @@ grub_term_color_state; /* The X position of the left border. */ #define GRUB_TERM_LEFT_BORDER_X GRUB_TERM_MARGIN -/* The number of lines of messages at the bottom. */ -#define GRUB_TERM_MESSAGE_HEIGHT 8 - /* The Y position of the first entry. */ #define GRUB_TERM_FIRST_ENTRY_Y (GRUB_TERM_TOP_BORDER_Y + 1) @@ -339,29 +336,6 @@ grub_term_entry_width (struct grub_term_output *term) return grub_term_border_width (term) - 2 - GRUB_TERM_MARGIN * 2 - 1; } -/* The height of the border. */ - -static inline unsigned -grub_term_border_height (struct grub_term_output *term) -{ - return grub_term_height (term) - GRUB_TERM_TOP_BORDER_Y - - GRUB_TERM_MESSAGE_HEIGHT; -} - -/* The number of entries shown at a time. */ -static inline int -grub_term_num_entries (struct grub_term_output *term) -{ - return grub_term_border_height (term) - 2; -} - -static inline int -grub_term_cursor_x (struct grub_term_output *term) -{ - return (GRUB_TERM_LEFT_BORDER_X + grub_term_border_width (term) - - GRUB_TERM_MARGIN - 1); -} - static inline grub_uint16_t grub_term_getxy (struct grub_term_output *term) { From 088cdb65eb49582b71fa3ef2065406a37e5f1672 Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Sun, 10 Apr 2011 15:25:52 +0200 Subject: [PATCH 430/869] * grub-core/gnulib/argp-parse.c (__argp_input): Don't crash if pstate is NULL. --- ChangeLog | 5 +++++ grub-core/gnulib/argp-parse.c | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 3f4913ec1..b5ca76ac6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-04-10 Colin Watson + + * grub-core/gnulib/argp-parse.c (__argp_input): Don't crash if pstate + is NULL. + 2011-04-10 Vladimir Serbinenko Dynamically count the number of lines for the lower banner. diff --git a/grub-core/gnulib/argp-parse.c b/grub-core/gnulib/argp-parse.c index a1cbf884e..9c054653c 100644 --- a/grub-core/gnulib/argp-parse.c +++ b/grub-core/gnulib/argp-parse.c @@ -935,7 +935,7 @@ weak_alias (__argp_parse, argp_parse) void * __argp_input (const struct argp *argp, const struct argp_state *state) { - if (state) + if (state && state->pstate) { struct group *group; struct parser *parser = state->pstate; From cbac5b1eceb008ec6a97f22a88318c1afd17a343 Mon Sep 17 00:00:00 2001 From: Alexander Kurtz Date: Sun, 10 Apr 2011 15:30:45 +0200 Subject: [PATCH 431/869] * util/grub-mkconfig_lib.in: Add missing quotes. --- ChangeLog | 4 ++ util/grub-mkconfig_lib.in | 86 +++++++++++++++++++-------------------- 2 files changed, 47 insertions(+), 43 deletions(-) diff --git a/ChangeLog b/ChangeLog index b5ca76ac6..c86adedb0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2011-04-10 Alexander Kurtz + + * util/grub-mkconfig_lib.in: Add missing quotes. + 2011-04-10 Colin Watson * grub-core/gnulib/argp-parse.c (__argp_input): Don't crash if pstate diff --git a/util/grub-mkconfig_lib.in b/util/grub-mkconfig_lib.in index 628ea34d4..2c5fd8c6f 100644 --- a/util/grub-mkconfig_lib.in +++ b/util/grub-mkconfig_lib.in @@ -16,19 +16,19 @@ transform="@program_transform_name@" -prefix=@prefix@ -exec_prefix=@exec_prefix@ -datarootdir=@datarootdir@ -datadir=@datadir@ -bindir=@bindir@ -sbindir=@sbindir@ -pkgdatadir=${datadir}/`echo @PACKAGE_TARNAME@ | sed "${transform}"` +prefix="@prefix@" +exec_prefix="@exec_prefix@" +datarootdir="@datarootdir@" +datadir="@datadir@" +bindir="@bindir@" +sbindir="@sbindir@" +pkgdatadir="${datadir}/`echo "@PACKAGE_TARNAME@" | sed "${transform}"`" if test "x$grub_probe" = x; then - grub_probe=${sbindir}/`echo grub-probe | sed ${transform}` + grub_probe="${sbindir}/`echo grub-probe | sed "${transform}"`" fi if test "x$grub_mkrelpath" = x; then - grub_mkrelpath=${bindir}/`echo grub-mkrelpath | sed ${transform}` + grub_mkrelpath="${bindir}/`echo grub-mkrelpath | sed "${transform}"`" fi if $(which gettext >/dev/null 2>/dev/null) ; then @@ -44,20 +44,20 @@ grub_warn () make_system_path_relative_to_its_root () { - ${grub_mkrelpath} $1 + "${grub_mkrelpath}" "$1" } is_path_readable_by_grub () { - path=$1 + path="$1" # abort if path doesn't exist - if test -e $path ; then : ;else + if test -e "$path" ; then : ;else return 1 fi # abort if file is in a filesystem we can't read - if ${grub_probe} -t fs $path > /dev/null 2>&1 ; then : ; else + if "${grub_probe}" -t fs "$path" > /dev/null 2>&1 ; then : ; else return 1 fi @@ -72,24 +72,24 @@ is_path_readable_by_grub () convert_system_path_to_grub_path () { - path=$1 + path="$1" grub_warn "convert_system_path_to_grub_path() is deprecated. Use prepare_grub_to_access_device() instead." # abort if GRUB can't access the path - if is_path_readable_by_grub ${path} ; then : ; else + if is_path_readable_by_grub "${path}" ; then : ; else return 1 fi - if drive=`${grub_probe} -t drive $path` ; then : ; else + if drive="`"${grub_probe}" -t drive "$path"`" ; then : ; else return 1 fi - if relative_path=`make_system_path_relative_to_its_root $path` ; then : ; else + if relative_path="`make_system_path_relative_to_its_root "$path"`" ; then : ; else return 1 fi - echo ${drive}${relative_path} + echo "${drive}${relative_path}" } save_default_entry () @@ -103,15 +103,15 @@ EOF prepare_grub_to_access_device () { - device=$1 + device="$1" # Abstraction modules aren't auto-loaded. - abstraction="`${grub_probe} --device ${device} --target=abstraction`" + abstraction="`"${grub_probe}" --device "${device}" --target=abstraction`" for module in ${abstraction} ; do echo "insmod ${module}" done - partmap="`${grub_probe} --device ${device} --target=partmap`" + partmap="`"${grub_probe}" --device "${device}" --target=partmap`" for module in ${partmap} ; do case "${module}" in netbsd | openbsd) @@ -121,15 +121,15 @@ prepare_grub_to_access_device () esac done - fs="`${grub_probe} --device ${device} --target=fs`" + fs="`"${grub_probe}" --device "${device}" --target=fs`" for module in ${fs} ; do echo "insmod ${module}" done # If there's a filesystem UUID that GRUB is capable of identifying, use it; # otherwise set root as per value in device.map. - echo "set root='`${grub_probe} --device ${device} --target=drive`'" - if fs_uuid="`${grub_probe} --device ${device} --target=fs_uuid 2> /dev/null`" ; then + echo "set root='`"${grub_probe}" --device "${device}" --target=drive`'" + if fs_uuid="`"${grub_probe}" --device "${device}" --target=fs_uuid 2> /dev/null`" ; then echo "search --no-floppy --fs-uuid --set=root ${fs_uuid}" fi } @@ -149,21 +149,21 @@ grub_file_is_not_garbage () version_test_numeric () { - local a=$1 - local cmp=$2 - local b=$3 + local a="$1" + local cmp="$2" + local b="$3" if [ "$a" = "$b" ] ; then - case $cmp in + case "$cmp" in ge|eq|le) return 0 ;; gt|lt) return 1 ;; esac fi if [ "$cmp" = "lt" ] ; then - c=$a - a=$b - b=$c + c="$a" + a="$b" + b="$c" fi - if (echo $a ; echo $b) | sort -n | head -n 1 | grep -qx $b ; then + if (echo "$a" ; echo "$b") | sort -n | head -n 1 | grep -qx "$b" ; then return 0 else return 1 @@ -172,25 +172,25 @@ version_test_numeric () version_test_gt () { - local a=`echo $1 | sed -e "s/[^-]*-//"` - local b=`echo $2 | sed -e "s/[^-]*-//"` + local a="`echo "$1" | sed -e "s/[^-]*-//"`" + local b="`echo "$2" | sed -e "s/[^-]*-//"`" local cmp=gt if [ "x$b" = "x" ] ; then return 0 fi - case $a:$b in + case "$a:$b" in *.old:*.old) ;; - *.old:*) a=`echo -n $a | sed -e s/\.old$//` ; cmp=gt ;; - *:*.old) b=`echo -n $b | sed -e s/\.old$//` ; cmp=ge ;; + *.old:*) a="`echo -n "$a" | sed -e 's/\.old$//'`" ; cmp=gt ;; + *:*.old) b="`echo -n "$b" | sed -e 's/\.old$//'`" ; cmp=ge ;; esac - version_test_numeric $a $cmp $b - return $? + version_test_numeric "$a" "$cmp" "$b" + return "$?" } version_find_latest () { local a="" - for i in $@ ; do + for i in "$@" ; do if version_test_gt "$i" "$a" ; then a="$i" fi @@ -202,7 +202,7 @@ version_find_latest () # printf; so this turns ' into \'. Note that you must use the output of # this function in a printf format string. gettext_quoted () { - $gettext "$@" | sed "s/'/'\\\\\\\\''/g" + "$gettext" "$@" | sed "s/'/'\\\\\\\\''/g" } # Run the first argument through gettext_quoted, and then pass that and all @@ -215,9 +215,9 @@ gettext_printf () { } uses_abstraction () { - device=$1 + device="$1" - abstraction="`${grub_probe} --device ${device} --target=abstraction`" + abstraction="`"${grub_probe}" --device "${device}" --target=abstraction`" for module in ${abstraction}; do if test "x${module}" = "x$2"; then return 0 From 5ca1a64de674ccc1f03f91ed7a2115140c1f2826 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 10 Apr 2011 16:08:58 +0200 Subject: [PATCH 432/869] * grub-core/kern/emu/hostdisk.c (grub_util_biosdisk_data): New member is_disk. (grub_util_biosdisk_open): Don't apply ioctl on non-disk devices. (open_device) Likewise. (grub_util_biosdisk_close): Likewise. Reported by: Mark Korenberger. --- ChangeLog | 9 +++++++++ grub-core/kern/emu/hostdisk.c | 12 +++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index c86adedb0..a7e73f461 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2011-04-10 Vladimir Serbinenko + + * grub-core/kern/emu/hostdisk.c (grub_util_biosdisk_data): New member + is_disk. + (grub_util_biosdisk_open): Don't apply ioctl on non-disk devices. + (open_device) Likewise. + (grub_util_biosdisk_close): Likewise. + Reported by: Mark Korenberger. + 2011-04-10 Alexander Kurtz * util/grub-mkconfig_lib.in: Add missing quotes. diff --git a/grub-core/kern/emu/hostdisk.c b/grub-core/kern/emu/hostdisk.c index 7b034e06b..f01e21aa0 100644 --- a/grub-core/kern/emu/hostdisk.c +++ b/grub-core/kern/emu/hostdisk.c @@ -138,6 +138,7 @@ struct grub_util_biosdisk_data char *dev; int access_mode; int fd; + int is_disk; }; #ifdef __linux__ @@ -239,6 +240,7 @@ grub_util_biosdisk_open (const char *name, grub_disk_t disk) data->dev = NULL; data->access_mode = 0; data->fd = -1; + data->is_disk = 0; /* Get the size. */ #if defined(__MINGW32__) @@ -279,6 +281,7 @@ grub_util_biosdisk_open (const char *name, grub_disk_t disk) close (fd); goto fail; } + data->is_disk = 1; # if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) if (ioctl (fd, DIOCGMEDIASIZE, &nr)) @@ -669,7 +672,8 @@ open_device (const grub_disk_t disk, grub_disk_addr_t sector, int flags) { fsync (data->fd); #ifdef __linux__ - ioctl (data->fd, BLKFLSBUF, 0); + if (data->is_disk) + ioctl (data->fd, BLKFLSBUF, 0); #endif } @@ -727,7 +731,8 @@ open_device (const grub_disk_t disk, grub_disk_addr_t sector, int flags) { fsync (data->fd); #ifdef __linux__ - ioctl (data->fd, BLKFLSBUF, 0); + if (data->is_disk) + ioctl (data->fd, BLKFLSBUF, 0); #endif } close (data->fd); @@ -952,7 +957,8 @@ grub_util_biosdisk_close (struct grub_disk *disk) { fsync (data->fd); #ifdef __linux__ - ioctl (data->fd, BLKFLSBUF, 0); + if (data->is_disk) + ioctl (data->fd, BLKFLSBUF, 0); #endif } close (data->fd); From 335bda1e57c9c5a7325d00817f990e658152161c Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 10 Apr 2011 16:12:31 +0200 Subject: [PATCH 433/869] * grub-core/boot/mips/yeeloong/fwstart.S (no_cs5536): Put back improperly removed string. --- ChangeLog | 5 +++++ grub-core/boot/mips/yeeloong/fwstart.S | 1 + 2 files changed, 6 insertions(+) diff --git a/ChangeLog b/ChangeLog index a7e73f461..65f42dd6a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-04-10 Vladimir Serbinenko + + * grub-core/boot/mips/yeeloong/fwstart.S (no_cs5536): Put back + improperly removed string. + 2011-04-10 Vladimir Serbinenko * grub-core/kern/emu/hostdisk.c (grub_util_biosdisk_data): New member diff --git a/grub-core/boot/mips/yeeloong/fwstart.S b/grub-core/boot/mips/yeeloong/fwstart.S index e2aa79759..9e81df192 100644 --- a/grub-core/boot/mips/yeeloong/fwstart.S +++ b/grub-core/boot/mips/yeeloong/fwstart.S @@ -379,6 +379,7 @@ read_spd_fail: ori $v0, $v0, 0x100 notification_string: .asciz "GRUB " +no_cs5536: .asciz "No CS5536 found.\n\r" cs5536_found: .asciz "CS5536 at " sm_failed: .asciz "SM transaction failed.\n\r" unhandled_tlb_refill: .asciz "Unhandled TLB refill.\n\r" From b01abe3e1679ed31a03a3203e3b9127c847e8d1a Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 10 Apr 2011 16:44:11 +0200 Subject: [PATCH 434/869] * grub-core/loader/mips/linux.c (grub_cmd_initrd): Use correct limits rather than trying to put initrd way too high. Reported by: Ryan Lortie --- ChangeLog | 6 ++++++ grub-core/loader/mips/linux.c | 5 +++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 65f42dd6a..f3050ef73 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2011-04-10 Vladimir Serbinenko + + * grub-core/loader/mips/linux.c (grub_cmd_initrd): Use correct limits + rather than trying to put initrd way too high. + Reported by: Ryan Lortie + 2011-04-10 Vladimir Serbinenko * grub-core/boot/mips/yeeloong/fwstart.S (no_cs5536): Put back diff --git a/grub-core/loader/mips/linux.c b/grub-core/loader/mips/linux.c index 6ae2a9321..9accfc270 100644 --- a/grub-core/loader/mips/linux.c +++ b/grub-core/loader/mips/linux.c @@ -379,8 +379,9 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), grub_relocator_chunk_t ch; err = grub_relocator_alloc_chunk_align (relocator, &ch, - target_addr + linux_size + 0x10000, - (0xffffffff - size) + 1, + (target_addr & 0x1fffffff) + + linux_size + 0x10000, + (0x10000000 - size), size, 0x10000, GRUB_RELOCATOR_PREFERENCE_NONE); From 9ee8d94faa182cb25eac7b5a15e29e122fe7fbc2 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 11 Apr 2011 07:38:42 +0200 Subject: [PATCH 435/869] * grub-core/kern/file.c (grub_file_open): Don't take into account the parenthesis in the middle of the filename. --- ChangeLog | 5 +++++ grub-core/kern/file.c | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index f3050ef73..46f683cb6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-04-11 Vladimir Serbinenko + + * grub-core/kern/file.c (grub_file_open): Don't take into account the + parenthesis in the middle of the filename. + 2011-04-10 Vladimir Serbinenko * grub-core/loader/mips/linux.c (grub_cmd_initrd): Use correct limits diff --git a/grub-core/kern/file.c b/grub-core/kern/file.c index c93fbf737..9d5a51c48 100644 --- a/grub-core/kern/file.c +++ b/grub-core/kern/file.c @@ -68,7 +68,7 @@ grub_file_open (const char *name) goto fail; /* Get the file part of NAME. */ - file_name = grub_strchr (name, ')'); + file_name = (name[0] == '(') ? grub_strchr (name, ')') : NULL; if (file_name) file_name++; else From af869a4ab9755cdc3fbbcaf639b88b386bbe395d Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 11 Apr 2011 07:40:53 +0200 Subject: [PATCH 436/869] * util/grub-fstest.c (read_file): Report GRUB error if file opening failed. --- ChangeLog | 5 +++++ util/grub-fstest.c | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 46f683cb6..cbb77c14c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-04-11 Vladimir Serbinenko + + * util/grub-fstest.c (read_file): Report GRUB error if file opening + failed. + 2011-04-11 Vladimir Serbinenko * grub-core/kern/file.c (grub_file_open): Don't take into account the diff --git a/util/grub-fstest.c b/util/grub-fstest.c index 2fcde4ab0..51c1a3a52 100644 --- a/util/grub-fstest.c +++ b/util/grub-fstest.c @@ -111,7 +111,8 @@ read_file (char *pathname, int (*hook) (grub_off_t ofs, char *buf, int len)) file = grub_file_open (pathname); if (!file) { - grub_util_error (_("cannot open file %s"), pathname); + grub_util_error (_("cannot open file %s:%s"), pathname, + grub_errmsg); return; } From 8a3bc88ea740221ae56afdd1545327f45280f112 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 11 Apr 2011 07:41:59 +0200 Subject: [PATCH 437/869] * util/grub-fstest.c (cmd_cmp): Check that sizes match. --- ChangeLog | 4 ++++ util/grub-fstest.c | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/ChangeLog b/ChangeLog index cbb77c14c..dbcbb9651 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2011-04-11 Vladimir Serbinenko + + * util/grub-fstest.c (cmd_cmp): Check that sizes match. + 2011-04-11 Vladimir Serbinenko * util/grub-fstest.c (read_file): Report GRUB error if file opening diff --git a/util/grub-fstest.c b/util/grub-fstest.c index 51c1a3a52..293bdf74a 100644 --- a/util/grub-fstest.c +++ b/util/grub-fstest.c @@ -222,6 +222,14 @@ cmd_cmp (char *src, char *dest) grub_util_error (_("seek error")); read_file (src, cmp_hook); + + { + grub_uint64_t pre; + pre = ftell (ff); + fseek (ff, 0, SEEK_END); + if (pre != ftell (ff)) + grub_util_error (_("unexpected end of file")); + } fclose (ff); } From e8980227e8e3df225dfecd9bb98d5ea515d7b041 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 11 Apr 2011 07:49:26 +0200 Subject: [PATCH 438/869] Remove stale comment about redundancy --- grub-core/fs/btrfs.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/grub-core/fs/btrfs.c b/grub-core/fs/btrfs.c index 7632d535c..16aa0742a 100644 --- a/grub-core/fs/btrfs.c +++ b/grub-core/fs/btrfs.c @@ -662,7 +662,6 @@ grub_btrfs_read_logical (struct grub_btrfs_data *data, } case GRUB_BTRFS_CHUNK_TYPE_DUPLICATED: case GRUB_BTRFS_CHUNK_TYPE_RAID1: - /* FIXME: Use redundancy. */ { stripen = 0; stripe_offset = off; @@ -686,7 +685,6 @@ grub_btrfs_read_logical (struct grub_btrfs_data *data, break; } case GRUB_BTRFS_CHUNK_TYPE_RAID10: - /* FIXME: Use redundancy. */ { grub_uint64_t middle, high; grub_uint32_t low; From ec25b87d2904ef8ea1417bb0e61397c008e1b7f1 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 11 Apr 2011 07:50:22 +0200 Subject: [PATCH 439/869] Add dprintfs to report chunk lookups --- grub-core/fs/btrfs.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/grub-core/fs/btrfs.c b/grub-core/fs/btrfs.c index 16aa0742a..fb7469b67 100644 --- a/grub-core/fs/btrfs.c +++ b/grub-core/fs/btrfs.c @@ -589,6 +589,8 @@ grub_btrfs_read_logical (struct grub_btrfs_data *data, struct grub_btrfs_key key_out; int challoc = 0; grub_device_t dev; + grub_dprintf ("btrfs", "searching for laddr %" PRIxGRUB_UINT64_T "\n", + addr); for (ptr = data->sblock.bootstrap_mapping; ptr < data->sblock.bootstrap_mapping + sizeof (data->sblock.bootstrap_mapping) @@ -647,6 +649,16 @@ grub_btrfs_read_logical (struct grub_btrfs_data *data, unsigned redundancy = 1; unsigned i, j; + grub_dprintf ("btrfs", "chunk 0x%" PRIxGRUB_UINT64_T + "+0x%" PRIxGRUB_UINT64_T + " (%d stripes (%d substripes) of %" + PRIxGRUB_UINT64_T ")\n", + grub_le_to_cpu64 (key->offset), + grub_le_to_cpu64 (chunk->size), + grub_le_to_cpu16 (chunk->nstripes), + grub_le_to_cpu16 (chunk->nsubstripes), + grub_le_to_cpu64 (chunk->stripe_length)); + switch (grub_le_to_cpu64 (chunk->type) & ~GRUB_BTRFS_CHUNK_TYPE_BITS_DONTCARE) { From 228f95a2502a35a5a2e9a8a8eab0e66fa2c515ad Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 11 Apr 2011 07:51:15 +0200 Subject: [PATCH 440/869] Fix filename comparison --- grub-core/fs/btrfs.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/grub-core/fs/btrfs.c b/grub-core/fs/btrfs.c index fb7469b67..add590dfb 100644 --- a/grub-core/fs/btrfs.c +++ b/grub-core/fs/btrfs.c @@ -1103,12 +1103,9 @@ find_path (struct grub_btrfs_data *data, + grub_le_to_cpu16 (cdirel->n) + grub_le_to_cpu16 (cdirel->m))) { - char c; - c = cdirel->name[grub_le_to_cpu16 (cdirel->n)]; - cdirel->name[grub_le_to_cpu16 (cdirel->n)] = 0; - if (grub_strncmp (cdirel->name, ctoken, ctokenlen) == 0) + if (ctokenlen == grub_le_to_cpu16 (cdirel->n) + && grub_memcmp (cdirel->name, ctoken, ctokenlen) == 0) break; - cdirel->name[grub_le_to_cpu16 (cdirel->n)] = c; } if ((grub_uint8_t *) cdirel - (grub_uint8_t *) direl >= (grub_ssize_t) elemsize) From 565f0763118ac5d7789f4a85075e8f013f13ac69 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 11 Apr 2011 07:52:39 +0200 Subject: [PATCH 441/869] Take extent offset in account on uncompressed extents --- grub-core/fs/btrfs.c | 1 + 1 file changed, 1 insertion(+) diff --git a/grub-core/fs/btrfs.c b/grub-core/fs/btrfs.c index add590dfb..7b1888502 100644 --- a/grub-core/fs/btrfs.c +++ b/grub-core/fs/btrfs.c @@ -989,6 +989,7 @@ grub_btrfs_extent_read (struct grub_btrfs_data *data, } err = grub_btrfs_read_logical (data, grub_le_to_cpu64 (data->extent->laddr) + + grub_le_to_cpu64 (data->extent->offset) + extoff, buf, csize); if (err) From 6a01f54affc70b25a0a0507775ba159423402387 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 11 Apr 2011 07:53:21 +0200 Subject: [PATCH 442/869] use actually filled extent size if available --- grub-core/fs/btrfs.c | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/grub-core/fs/btrfs.c b/grub-core/fs/btrfs.c index 7b1888502..0b0e5259c 100644 --- a/grub-core/fs/btrfs.c +++ b/grub-core/fs/btrfs.c @@ -83,6 +83,7 @@ struct grub_btrfs_data /* Cached extent data. */ grub_uint64_t extstart; + grub_uint64_t extend; grub_uint64_t extino; grub_uint64_t exttree; grub_size_t extsize; @@ -202,6 +203,7 @@ struct grub_btrfs_extent_data grub_uint64_t laddr; grub_uint64_t compressed_size; grub_uint64_t offset; + grub_uint64_t filled; }; }; } __attribute__ ((packed)); @@ -872,12 +874,12 @@ grub_btrfs_extent_read (struct grub_btrfs_data *data, grub_err_t err; grub_off_t extoff; if (!data->extent || data->extstart > pos || data->extino != ino - || data->exttree != tree - || grub_le_to_cpu64 (data->extent->size) + data->extstart <= pos) + || data->exttree != tree || data->extend <= pos) { struct grub_btrfs_key key_in, key_out; grub_disk_addr_t elemaddr; grub_size_t elemsize; + grub_free (data->extent); key_in.object_id = ino; key_in.type = GRUB_BTRFS_ITEM_TYPE_EXTENT_ITEM; @@ -904,15 +906,29 @@ grub_btrfs_extent_read (struct grub_btrfs_data *data, data->extent, elemsize); if (err) return err; - if (grub_le_to_cpu64 (data->extent->size) + data->extstart <= pos) - return grub_error (GRUB_ERR_BAD_FS, "extent not found"); + + data->extend = data->extstart + + grub_le_to_cpu64 (data->extent->size); + if (data->extent->type == GRUB_BTRFS_EXTENT_REGULAR + && (char *) &data->extent + elemsize + >= (char *) &data->extent->filled + + sizeof (data->extent->filled)) + data->extend = data->extstart + + grub_le_to_cpu64 (data->extent->filled); + grub_dprintf ("btrfs", "extent 0x%" PRIxGRUB_UINT64_T "+0x%" - PRIxGRUB_UINT64_T "\n", + PRIxGRUB_UINT64_T " (0x%" + PRIxGRUB_UINT64_T ")\n", grub_le_to_cpu64 (key_out.offset), - grub_le_to_cpu64 (data->extent->size)); + grub_le_to_cpu64 (data->extent->size), + grub_le_to_cpu64 (data->extent->filled)); + if (data->extend <= pos) + { + grub_error (GRUB_ERR_BAD_FS, "extent not found"); + return -1; + } } - csize = grub_le_to_cpu64 (data->extent->size) - + grub_le_to_cpu64 (data->extstart) - pos; + csize = data->extend - pos; extoff = pos - data->extstart; if (csize > len) csize = len; From 3dd3dd335fe8efb23d54bfbc322701d54c28a65d Mon Sep 17 00:00:00 2001 From: Feiran Zheng Date: Mon, 11 Apr 2011 08:16:13 +0200 Subject: [PATCH 443/869] minix3fs support --- grub-core/Makefile.core.def | 5 ++ grub-core/fs/minix.c | 164 +++++++++++++++++++++++++++--------- grub-core/fs/minix3.c | 2 + 3 files changed, 132 insertions(+), 39 deletions(-) create mode 100644 grub-core/fs/minix3.c diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def index 7c26b37e9..9f418a0b7 100644 --- a/grub-core/Makefile.core.def +++ b/grub-core/Makefile.core.def @@ -958,6 +958,11 @@ module = { common = fs/minix2.c; }; +module = { + name = minix3; + common = fs/minix3.c; +}; + module = { name = nilfs2; common = fs/nilfs2.c; diff --git a/grub-core/fs/minix.c b/grub-core/fs/minix.c index 679e1ec51..c93dfe085 100644 --- a/grub-core/fs/minix.c +++ b/grub-core/fs/minix.c @@ -25,14 +25,17 @@ #include #include -#ifdef MODE_MINIX2 +#ifdef MODE_MINIX3 +#define GRUB_MINIX_MAGIC 0x4D5A +#elif defined(MODE_MINIX2) #define GRUB_MINIX_MAGIC 0x2468 #define GRUB_MINIX_MAGIC_30 0x2478 #else #define GRUB_MINIX_MAGIC 0x137F #define GRUB_MINIX_MAGIC_30 0x138F #endif -#define GRUB_MINIX_BSIZE 1024U + +#define GRUB_MINIX_INODE_DIR_BLOCKS 7 #define GRUB_MINIX_LOG2_BSIZE 1 #define GRUB_MINIX_ROOT_INODE 1 #define GRUB_MINIX_MAX_SYMLNK_CNT 8 @@ -41,7 +44,7 @@ #define GRUB_MINIX_IFDIR 0040000U #define GRUB_MINIX_IFLNK 0120000U -#ifdef MODE_MINIX2 +#if defined(MODE_MINIX2) || defined(MODE_MINIX3) typedef grub_uint32_t grub_minix_uintn_t; #define grub_minix_le_to_cpu_n grub_le_to_cpu32 #else @@ -50,6 +53,13 @@ typedef grub_uint16_t grub_minix_uintn_t; #endif #define GRUB_MINIX_INODE_BLKSZ(data) sizeof (grub_minix_uintn_t) +#ifdef MODE_MINIX3 +typedef grub_uint32_t grub_minix_ino_t; +#define grub_minix_le_to_cpu_ino grub_le_to_cpu32 +#else +typedef grub_uint16_t grub_minix_ino_t; +#define grub_minix_le_to_cpu_ino grub_le_to_cpu16 +#endif #define GRUB_MINIX_INODE_SIZE(data) (grub_minix_le_to_cpu_n (data->inode.size)) #define GRUB_MINIX_INODE_MODE(data) (grub_le_to_cpu16 (data->inode.mode)) @@ -62,9 +72,28 @@ typedef grub_uint16_t grub_minix_uintn_t; #define GRUB_MINIX_LOG2_ZONESZ (GRUB_MINIX_LOG2_BSIZE \ + grub_le_to_cpu16 (sblock->log2_zone_size)) -#define GRUB_MINIX_ZONESZ (GRUB_MINIX_BSIZE \ +#define GRUB_MINIX_ZONESZ (data->block_size \ << grub_le_to_cpu16 (sblock->log2_zone_size)) +#ifdef MODE_MINIX3 +struct grub_minix_sblock +{ + grub_uint32_t inode_cnt; + grub_uint16_t zone_cnt; + grub_uint16_t inode_bmap_size; + grub_uint16_t zone_bmap_size; + grub_uint16_t first_data_zone; + grub_uint16_t log2_zone_size; + grub_uint16_t pad; + grub_uint32_t max_file_size; + grub_uint32_t zones; + grub_uint16_t magic; + + grub_uint16_t pad2; + grub_uint16_t block_size; + grub_uint8_t disk_version; +}; +#else struct grub_minix_sblock { grub_uint16_t inode_cnt; @@ -76,8 +105,28 @@ struct grub_minix_sblock grub_uint32_t max_file_size; grub_uint16_t magic; }; +#endif -#ifndef MODE_MINIX2 +#if defined(MODE_MINIX3) + +struct grub_minix_inode +{ + grub_uint16_t mode; + grub_uint16_t nlinks; + grub_uint16_t uid; + grub_uint8_t gid; + grub_uint8_t pad; + grub_uint32_t size; + grub_uint32_t atime; + grub_uint32_t mtime; + grub_uint32_t ctime; + grub_uint32_t dir_zones[7]; + grub_uint32_t indir_zone; + grub_uint32_t double_indir_zone; + grub_uint32_t unused; +}; + +#elif defined(MODE_MINIX2) struct grub_minix_inode { grub_uint16_t mode; @@ -121,6 +170,7 @@ struct grub_minix_data int linknest; grub_disk_t disk; int filename_size; + grub_size_t block_size; }; static grub_dl_t my_mod; @@ -141,18 +191,22 @@ grub_minix_get_file_block (struct grub_minix_data *data, unsigned int blk) { grub_minix_uintn_t indirn; grub_disk_read (data->disk, +#ifdef MODE_MINIX3 + zone * (data->block_size / GRUB_DISK_SECTOR_SIZE), +#else zone << GRUB_MINIX_LOG2_ZONESZ, +#endif sizeof (grub_minix_uintn_t) * num, sizeof (grub_minix_uintn_t), (char *) &indirn); return grub_minix_le_to_cpu_n (indirn); } /* Direct block. */ - if (blk < 7) + if (blk < GRUB_MINIX_INODE_DIR_BLOCKS) return GRUB_MINIX_INODE_DIR_ZONES (data, blk); /* Indirect block. */ - blk -= 7; + blk -= GRUB_MINIX_INODE_DIR_BLOCKS; if (blk < GRUB_MINIX_ZONESZ / GRUB_MINIX_INODE_BLKSZ (data)) { indir = grub_get_indir (GRUB_MINIX_INODE_INDIR_ZONE (data), blk); @@ -185,25 +239,27 @@ static grub_ssize_t grub_minix_read_file (struct grub_minix_data *data, void NESTED_FUNC_ATTR (*read_hook) (grub_disk_addr_t sector, unsigned offset, unsigned length), - int pos, grub_disk_addr_t len, char *buf) + grub_off_t pos, grub_disk_addr_t len, char *buf) { struct grub_minix_sblock *sblock = &data->sblock; - int i; - int blockcnt; + grub_disk_addr_t i; + grub_disk_addr_t blockcnt; + grub_uint64_t posblock; + grub_uint32_t blockoff; /* Adjust len so it we can't read past the end of the file. */ if (len + pos > GRUB_MINIX_INODE_SIZE (data)) len = GRUB_MINIX_INODE_SIZE (data) - pos; - blockcnt = (len + pos + GRUB_MINIX_BSIZE - 1) / GRUB_MINIX_BSIZE; + blockcnt = grub_divmod64 ((len + pos + data->block_size - 1), + data->block_size, 0); + posblock = grub_divmod64 (pos, data->block_size, &blockoff); - for (i = pos / GRUB_MINIX_BSIZE; i < blockcnt; i++) + for (i = posblock; i < blockcnt; i++) { - int blknr; - int blockoff = pos % GRUB_MINIX_BSIZE; - int blockend = GRUB_MINIX_BSIZE; - - int skipfirst = 0; + grub_disk_addr_t blknr; + grub_uint32_t blockend = data->block_size; + grub_off_t skipfirst = 0; blknr = grub_minix_get_file_block (data, i); if (grub_errno) @@ -212,28 +268,32 @@ grub_minix_read_file (struct grub_minix_data *data, /* Last block. */ if (i == blockcnt - 1) { - blockend = (len + pos) % GRUB_MINIX_BSIZE; + grub_divmod64 (len + pos, data->block_size, &blockend); if (!blockend) - blockend = GRUB_MINIX_BSIZE; + blockend = data->block_size; } /* First block. */ - if (i == (pos / (int) GRUB_MINIX_BSIZE)) + if (i == posblock) { skipfirst = blockoff; blockend -= skipfirst; } data->disk->read_hook = read_hook; - grub_disk_read (data->disk, blknr << GRUB_MINIX_LOG2_ZONESZ, + grub_disk_read (data->disk, +#ifdef MODE_MINIX3 + blknr * (sblock->block_size / GRUB_DISK_SECTOR_SIZE), +#else + blknr << GRUB_MINIX_LOG2_ZONESZ, +#endif skipfirst, blockend, buf); - data->disk->read_hook = 0; if (grub_errno) return -1; - buf += GRUB_MINIX_BSIZE - skipfirst; + buf += data->block_size - skipfirst; } return len; @@ -248,16 +308,18 @@ grub_minix_read_inode (struct grub_minix_data *data, int ino) struct grub_minix_sblock *sblock = &data->sblock; /* Block in which the inode is stored. */ - int block; + grub_disk_addr_t block; data->ino = ino; /* The first inode in minix is inode 1. */ ino--; - - block = ((2 + grub_le_to_cpu16 (sblock->inode_bmap_size) - + grub_le_to_cpu16 (sblock->zone_bmap_size)) - << GRUB_MINIX_LOG2_BSIZE); - + block = (2 + grub_le_to_cpu16 (sblock->inode_bmap_size) + + grub_le_to_cpu16 (sblock->zone_bmap_size)); +#ifndef MODE_MINIX3 + block <<= GRUB_MINIX_LOG2_BSIZE; +#else + block *= sblock->block_size / GRUB_DISK_SECTOR_SIZE; +#endif block += ino / (GRUB_DISK_SECTOR_SIZE / sizeof (struct grub_minix_inode)); int offs = (ino % (GRUB_DISK_SECTOR_SIZE / sizeof (struct grub_minix_inode)) @@ -333,7 +395,7 @@ grub_minix_find_file (struct grub_minix_data *data, const char *path) do { - grub_uint16_t ino; + grub_minix_ino_t ino; char filename[data->filename_size + 1]; if (grub_strlen (name) == 0) @@ -353,7 +415,7 @@ grub_minix_find_file (struct grub_minix_data *data, const char *path) if (!grub_strcmp (name, filename)) { dirino = data->ino; - grub_minix_read_inode (data, grub_le_to_cpu16 (ino)); + grub_minix_read_inode (data, grub_minix_le_to_cpu_ino (ino)); /* Follow the symlink. */ if ((GRUB_MINIX_INODE_MODE (data) @@ -409,20 +471,35 @@ grub_minix_mount (grub_disk_t disk) goto fail; if (grub_le_to_cpu16 (data->sblock.magic) == GRUB_MINIX_MAGIC) + { +#if !defined(MODE_MINIX3) data->filename_size = 14; +#else + data->filename_size = 60; +#endif + } +#if !defined(MODE_MINIX3) else if (grub_le_to_cpu16 (data->sblock.magic) == GRUB_MINIX_MAGIC_30) data->filename_size = 30; +#endif else goto fail; data->disk = disk; data->linknest = 0; +#ifdef MODE_MINIX3 + data->block_size = grub_le_to_cpu16 (data->sblock.block_size); +#else + data->block_size = 1024U; +#endif return data; fail: grub_free (data); -#ifdef MODE_MINIX2 +#if defined(MODE_MINIX3) + grub_error (GRUB_ERR_BAD_FS, "not a minix3 filesystem"); +#elif defined(MODE_MINIX2) grub_error (GRUB_ERR_BAD_FS, "not a minix2 filesystem"); #else grub_error (GRUB_ERR_BAD_FS, "not a minix filesystem"); @@ -458,7 +535,7 @@ grub_minix_dir (grub_device_t device, const char *path, while (pos < GRUB_MINIX_INODE_SIZE (data)) { - grub_uint16_t ino; + grub_minix_ino_t ino; char filename[data->filename_size + 1]; int dirino = data->ino; struct grub_dirhook_info info; @@ -474,10 +551,13 @@ grub_minix_dir (grub_device_t device, const char *path, (char *) filename) < 0) return grub_errno; filename[data->filename_size] = '\0'; + if (!ino) + { + pos += sizeof (ino) + data->filename_size; + continue; + } - /* The filetype is not stored in the dirent. Read the inode to - find out the filetype. This *REALLY* sucks. */ - grub_minix_read_inode (data, grub_le_to_cpu16 (ino)); + grub_minix_read_inode (data, grub_minix_le_to_cpu_ino (ino)); info.dir = ((GRUB_MINIX_INODE_MODE (data) & GRUB_MINIX_IFDIR) == GRUB_MINIX_IFDIR); if (hook (filename, &info) ? 1 : 0) @@ -556,7 +636,9 @@ grub_minix_close (grub_file_t file) static struct grub_fs grub_minix_fs = { -#ifdef MODE_MINIX2 +#if defined(MODE_MINIX3) + .name = "minix3", +#elif defined(MODE_MINIX2) .name = "minix2", #else .name = "minix", @@ -568,7 +650,9 @@ static struct grub_fs grub_minix_fs = .next = 0 }; -#ifdef MODE_MINIX2 +#if defined(MODE_MINIX3) +GRUB_MOD_INIT(minix3) +#elif defined(MODE_MINIX2) GRUB_MOD_INIT(minix2) #else GRUB_MOD_INIT(minix) @@ -578,7 +662,9 @@ GRUB_MOD_INIT(minix) my_mod = mod; } -#ifdef MODE_MINIX2 +#if defined(MODE_MINIX3) +GRUB_MOD_FINI(minix3) +#elif defined(MODE_MINIX2) GRUB_MOD_FINI(minix2) #else GRUB_MOD_FINI(minix) diff --git a/grub-core/fs/minix3.c b/grub-core/fs/minix3.c new file mode 100644 index 000000000..58a21d2b5 --- /dev/null +++ b/grub-core/fs/minix3.c @@ -0,0 +1,2 @@ +#define MODE_MINIX3 1 +#include "minix.c" From 58ee1408a8be7d386027882cb07e14f76a2b6cfb Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 11 Apr 2011 08:53:28 +0200 Subject: [PATCH 444/869] Fix an error in minix inode declaration --- grub-core/fs/minix.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/grub-core/fs/minix.c b/grub-core/fs/minix.c index c93dfe085..877f71921 100644 --- a/grub-core/fs/minix.c +++ b/grub-core/fs/minix.c @@ -126,7 +126,7 @@ struct grub_minix_inode grub_uint32_t unused; }; -#elif defined(MODE_MINIX2) +#elif !defined(MODE_MINIX2) struct grub_minix_inode { grub_uint16_t mode; From 65f01628e19d04be6cad0242d3056dbb656a54b2 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 11 Apr 2011 08:56:42 +0200 Subject: [PATCH 445/869] unify minix3 and minix2 inode declarations --- grub-core/fs/minix.c | 49 +++++++++++++------------------------------- 1 file changed, 14 insertions(+), 35 deletions(-) diff --git a/grub-core/fs/minix.c b/grub-core/fs/minix.c index 877f71921..a01ee77ca 100644 --- a/grub-core/fs/minix.c +++ b/grub-core/fs/minix.c @@ -107,41 +107,7 @@ struct grub_minix_sblock }; #endif -#if defined(MODE_MINIX3) - -struct grub_minix_inode -{ - grub_uint16_t mode; - grub_uint16_t nlinks; - grub_uint16_t uid; - grub_uint8_t gid; - grub_uint8_t pad; - grub_uint32_t size; - grub_uint32_t atime; - grub_uint32_t mtime; - grub_uint32_t ctime; - grub_uint32_t dir_zones[7]; - grub_uint32_t indir_zone; - grub_uint32_t double_indir_zone; - grub_uint32_t unused; -}; - -#elif !defined(MODE_MINIX2) -struct grub_minix_inode -{ - grub_uint16_t mode; - grub_uint16_t uid; - grub_uint16_t size; - grub_uint32_t ctime; - grub_uint8_t gid; - grub_uint8_t nlinks; - grub_uint16_t dir_zones[7]; - grub_uint16_t indir_zone; - grub_uint16_t double_indir_zone; -}; - -#else - +#if defined(MODE_MINIX3) || defined(MODE_MINIX2) struct grub_minix_inode { grub_uint16_t mode; @@ -158,6 +124,19 @@ struct grub_minix_inode grub_uint32_t unused; }; +#else +struct grub_minix_inode +{ + grub_uint16_t mode; + grub_uint16_t uid; + grub_uint16_t size; + grub_uint32_t ctime; + grub_uint8_t gid; + grub_uint8_t nlinks; + grub_uint16_t dir_zones[7]; + grub_uint16_t indir_zone; + grub_uint16_t double_indir_zone; +}; #endif From 8fc88523dd88ed4e7852bbab28faa8225cde7f21 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 11 Apr 2011 14:09:02 +0200 Subject: [PATCH 446/869] Add minix3 to util filesystems --- Makefile.util.def | 1 + grub-core/fs/minix.c | 36 +++++++++++++++--------------------- 2 files changed, 16 insertions(+), 21 deletions(-) diff --git a/Makefile.util.def b/Makefile.util.def index 303baea3f..678e581e6 100644 --- a/Makefile.util.def +++ b/Makefile.util.def @@ -60,6 +60,7 @@ library = { common = grub-core/fs/jfs.c; common = grub-core/fs/minix.c; common = grub-core/fs/minix2.c; + common = grub-core/fs/minix3.c; common = grub-core/fs/nilfs2.c; common = grub-core/fs/ntfs.c; common = grub-core/fs/ntfscomp.c; diff --git a/grub-core/fs/minix.c b/grub-core/fs/minix.c index a01ee77ca..298eef394 100644 --- a/grub-core/fs/minix.c +++ b/grub-core/fs/minix.c @@ -70,10 +70,19 @@ typedef grub_uint16_t grub_minix_ino_t; #define GRUB_MINIX_INODE_DINDIR_ZONE(data) (grub_minix_le_to_cpu_n \ (data->inode.double_indir_zone)) +#ifndef MODE_MINIX3 #define GRUB_MINIX_LOG2_ZONESZ (GRUB_MINIX_LOG2_BSIZE \ - + grub_le_to_cpu16 (sblock->log2_zone_size)) + + grub_le_to_cpu16 (data->sblock.log2_zone_size)) +#endif #define GRUB_MINIX_ZONESZ (data->block_size \ - << grub_le_to_cpu16 (sblock->log2_zone_size)) + << grub_le_to_cpu16 (data->sblock.log2_zone_size)) + +#ifdef MODE_MINIX3 +#define GRUB_MINIX_ZONE2SECT(zone) ((zone) * (data->block_size / GRUB_DISK_SECTOR_SIZE)) +#else +#define GRUB_MINIX_ZONE2SECT(zone) ((zone) << GRUB_MINIX_LOG2_ZONESZ) +#endif + #ifdef MODE_MINIX3 struct grub_minix_sblock @@ -160,7 +169,6 @@ static grub_err_t grub_minix_find_file (struct grub_minix_data *data, static int grub_minix_get_file_block (struct grub_minix_data *data, unsigned int blk) { - struct grub_minix_sblock *sblock = &data->sblock; int indir; auto int grub_get_indir (int, int); @@ -170,11 +178,7 @@ grub_minix_get_file_block (struct grub_minix_data *data, unsigned int blk) { grub_minix_uintn_t indirn; grub_disk_read (data->disk, -#ifdef MODE_MINIX3 - zone * (data->block_size / GRUB_DISK_SECTOR_SIZE), -#else - zone << GRUB_MINIX_LOG2_ZONESZ, -#endif + GRUB_MINIX_ZONE2SECT(zone), sizeof (grub_minix_uintn_t) * num, sizeof (grub_minix_uintn_t), (char *) &indirn); return grub_minix_le_to_cpu_n (indirn); @@ -220,7 +224,6 @@ grub_minix_read_file (struct grub_minix_data *data, unsigned offset, unsigned length), grub_off_t pos, grub_disk_addr_t len, char *buf) { - struct grub_minix_sblock *sblock = &data->sblock; grub_disk_addr_t i; grub_disk_addr_t blockcnt; grub_uint64_t posblock; @@ -262,11 +265,7 @@ grub_minix_read_file (struct grub_minix_data *data, data->disk->read_hook = read_hook; grub_disk_read (data->disk, -#ifdef MODE_MINIX3 - blknr * (sblock->block_size / GRUB_DISK_SECTOR_SIZE), -#else - blknr << GRUB_MINIX_LOG2_ZONESZ, -#endif + GRUB_MINIX_ZONE2SECT(blknr), skipfirst, blockend, buf); data->disk->read_hook = 0; if (grub_errno) @@ -292,13 +291,8 @@ grub_minix_read_inode (struct grub_minix_data *data, int ino) /* The first inode in minix is inode 1. */ ino--; - block = (2 + grub_le_to_cpu16 (sblock->inode_bmap_size) - + grub_le_to_cpu16 (sblock->zone_bmap_size)); -#ifndef MODE_MINIX3 - block <<= GRUB_MINIX_LOG2_BSIZE; -#else - block *= sblock->block_size / GRUB_DISK_SECTOR_SIZE; -#endif + block = GRUB_MINIX_ZONE2SECT (2 + grub_le_to_cpu16 (sblock->inode_bmap_size) + + grub_le_to_cpu16 (sblock->zone_bmap_size)); block += ino / (GRUB_DISK_SECTOR_SIZE / sizeof (struct grub_minix_inode)); int offs = (ino % (GRUB_DISK_SECTOR_SIZE / sizeof (struct grub_minix_inode)) From 2a9bc0169eced59e03dde36de0958c4d3bf06ee0 Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Mon, 11 Apr 2011 16:06:37 +0100 Subject: [PATCH 447/869] * grub-core/fs/btrfs.c (grub_btrfs_fs) [GRUB_UTIL]: Set reserved_first_sector to 1. btrfs reserves plenty of space for boot loaders. Reported by: Gene Cumm. Fixes Ubuntu bug #757446. --- ChangeLog | 7 +++++++ grub-core/fs/btrfs.c | 3 +++ 2 files changed, 10 insertions(+) diff --git a/ChangeLog b/ChangeLog index dbcbb9651..295a23d1a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2011-04-11 Colin Watson + + * grub-core/fs/btrfs.c (grub_btrfs_fs) [GRUB_UTIL]: Set + reserved_first_sector to 1. btrfs reserves plenty of space for boot + loaders. + Reported by: Gene Cumm. Fixes Ubuntu bug #757446. + 2011-04-11 Vladimir Serbinenko * util/grub-fstest.c (cmd_cmp): Check that sizes match. diff --git a/grub-core/fs/btrfs.c b/grub-core/fs/btrfs.c index 179891da8..11b8dba33 100644 --- a/grub-core/fs/btrfs.c +++ b/grub-core/fs/btrfs.c @@ -122,6 +122,9 @@ static struct grub_fs grub_btrfs_fs = .dir = grub_btrfs_dir, .open = grub_btrfs_open, .uuid = grub_btrfs_uuid, +#ifdef GRUB_UTIL + .reserved_first_sector = 1, +#endif }; GRUB_MOD_INIT(btrfs) From 48fe18dcf2d2003846046a808d984a4db0a336ba Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 11 Apr 2011 18:13:00 +0200 Subject: [PATCH 448/869] exfat reader --- Makefile.util.def | 1 + grub-core/Makefile.core.def | 5 + grub-core/fs/exfat.c | 2 + grub-core/fs/fat.c | 369 ++++++++++++++++++++++++++++++++++-- 4 files changed, 359 insertions(+), 18 deletions(-) create mode 100644 grub-core/fs/exfat.c diff --git a/Makefile.util.def b/Makefile.util.def index 303baea3f..a1d00a683 100644 --- a/Makefile.util.def +++ b/Makefile.util.def @@ -53,6 +53,7 @@ library = { common = grub-core/fs/cpio.c; common = grub-core/fs/ext2.c; common = grub-core/fs/fat.c; + common = grub-core/fs/exfat.c; common = grub-core/fs/fshelp.c; common = grub-core/fs/hfs.c; common = grub-core/fs/hfsplus.c; diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def index 7c26b37e9..3ec41ac7f 100644 --- a/grub-core/Makefile.core.def +++ b/grub-core/Makefile.core.def @@ -923,6 +923,11 @@ module = { common = fs/fat.c; }; +module = { + name = exfat; + common = fs/exfat.c; +}; + module = { name = fshelp; common = fs/fshelp.c; diff --git a/grub-core/fs/exfat.c b/grub-core/fs/exfat.c new file mode 100644 index 000000000..fe149ddd3 --- /dev/null +++ b/grub-core/fs/exfat.c @@ -0,0 +1,2 @@ +#define MODE_EXFAT 1 +#include "fat.c" diff --git a/grub-core/fs/fat.c b/grub-core/fs/fat.c index 89050943c..5f7a58571 100644 --- a/grub-core/fs/fat.c +++ b/grub-core/fs/fat.c @@ -32,23 +32,54 @@ #define GRUB_FAT_ATTR_READ_ONLY 0x01 #define GRUB_FAT_ATTR_HIDDEN 0x02 #define GRUB_FAT_ATTR_SYSTEM 0x04 +#ifndef MODE_EXFAT #define GRUB_FAT_ATTR_VOLUME_ID 0x08 +#endif #define GRUB_FAT_ATTR_DIRECTORY 0x10 #define GRUB_FAT_ATTR_ARCHIVE 0x20 #define GRUB_FAT_MAXFILE 256 +#ifndef MODE_EXFAT #define GRUB_FAT_ATTR_LONG_NAME (GRUB_FAT_ATTR_READ_ONLY \ | GRUB_FAT_ATTR_HIDDEN \ | GRUB_FAT_ATTR_SYSTEM \ | GRUB_FAT_ATTR_VOLUME_ID) -#define GRUB_FAT_ATTR_VALID (GRUB_FAT_ATTR_READ_ONLY \ - | GRUB_FAT_ATTR_HIDDEN \ - | GRUB_FAT_ATTR_SYSTEM \ - | GRUB_FAT_ATTR_DIRECTORY \ - | GRUB_FAT_ATTR_ARCHIVE \ - | GRUB_FAT_ATTR_VOLUME_ID) +#endif +static const grub_uint8_t GRUB_FAT_ATTR_VALID = (GRUB_FAT_ATTR_READ_ONLY + | GRUB_FAT_ATTR_HIDDEN + | GRUB_FAT_ATTR_SYSTEM + | GRUB_FAT_ATTR_DIRECTORY + | GRUB_FAT_ATTR_ARCHIVE +#ifndef MODE_EXFAT + | GRUB_FAT_ATTR_VOLUME_ID +#endif + ); +#ifdef MODE_EXFAT +struct grub_fat_bpb +{ + grub_uint8_t jmp_boot[3]; + grub_uint8_t oem_name[8]; + grub_uint8_t mbz[53]; + grub_uint64_t num_hidden_sectors; + grub_uint64_t num_total_sectors; + grub_uint32_t num_reserved_sectors; + grub_uint32_t sectors_per_fat; + grub_uint32_t cluster_offset; + grub_uint32_t cluster_count; + grub_uint32_t root_cluster; + grub_uint32_t num_serial; + grub_uint16_t fs_revision; + grub_uint16_t volume_flags; + grub_uint8_t bytes_per_sector_shift; + grub_uint8_t sectors_per_cluster_shift; + grub_uint8_t num_fats; + grub_uint8_t num_ph_drive; + grub_uint8_t reserved[8]; +} __attribute__ ((packed)); + +#else struct grub_fat_bpb { grub_uint8_t jmp_boot[3]; @@ -94,7 +125,64 @@ struct grub_fat_bpb } __attribute__ ((packed)) fat32; } __attribute__ ((packed)) version_specific; } __attribute__ ((packed)); +#endif +#ifdef MODE_EXFAT +struct grub_fat_dir_entry +{ + grub_uint8_t entry_type; + union + { + grub_uint8_t placeholder[31]; + struct { + grub_uint8_t secondary_count; + grub_uint16_t checksum; + grub_uint16_t attr; + grub_uint16_t reserved1; + grub_uint32_t c_time; + grub_uint32_t m_time; + grub_uint32_t a_time; + grub_uint8_t c_time_tenth; + grub_uint8_t m_time_tenth; + grub_uint8_t a_time_tenth; + grub_uint8_t reserved2[9]; + } __attribute__ ((packed)) file; + struct { + grub_uint8_t flags; + grub_uint8_t reserved1; + grub_uint8_t name_length; + grub_uint16_t name_hash; + grub_uint16_t reserved2; + grub_uint64_t valid_size; + grub_uint32_t reserved3; + grub_uint32_t first_cluster; + grub_uint64_t file_size; + } __attribute__ ((packed)) stream_extension; + struct { + grub_uint8_t flags; + grub_uint16_t str[15]; + } __attribute__ ((packed)) file_name; + struct { + grub_uint8_t character_count; + grub_uint16_t str[11]; + grub_uint8_t reserved[8]; + } __attribute__ ((packed)) volume_label; + } __attribute__ ((packed)) type_specific; +} __attribute__ ((packed)); + +struct grub_fat_dir_node +{ + grub_uint32_t attr; + grub_uint32_t first_cluster; + grub_uint64_t file_size; + grub_uint64_t valid_size; + int have_stream; + int is_label; +}; + +typedef struct grub_fat_dir_node grub_fat_dir_node_t; + +#else struct grub_fat_dir_entry { grub_uint8_t name[11]; @@ -123,6 +211,10 @@ struct grub_fat_long_name_entry grub_uint16_t name3[2]; } __attribute__ ((packed)); +typedef struct grub_fat_dir_entry grub_fat_dir_node_t; + +#endif + struct grub_fat_data { int logical_sector_bits; @@ -133,8 +225,10 @@ struct grub_fat_data int fat_size; grub_uint32_t root_cluster; +#ifndef MODE_EXFAT grub_uint32_t root_sector; grub_uint32_t num_root_sectors; +#endif int cluster_bits; grub_uint32_t cluster_eof_mark; @@ -152,6 +246,7 @@ struct grub_fat_data static grub_dl_t my_mod; +#ifndef MODE_EXFAT static int fat_log2 (unsigned x) { @@ -168,6 +263,7 @@ fat_log2 (unsigned x) return i; } +#endif static struct grub_fat_data * grub_fat_mount (grub_disk_t disk) @@ -187,20 +283,37 @@ grub_fat_mount (grub_disk_t disk) if (grub_disk_read (disk, 0, 0, sizeof (bpb), &bpb)) goto fail; +#ifdef MODE_EXFAT + if (grub_memcmp ((const char *) bpb.oem_name, "EXFAT ", + sizeof (bpb.oem_name)) != 0) + goto fail; +#else if (grub_strncmp((const char *) bpb.version_specific.fat12_or_fat16.fstype, "FAT12", 5) && grub_strncmp((const char *) bpb.version_specific.fat12_or_fat16.fstype, "FAT16", 5) && grub_strncmp((const char *) bpb.version_specific.fat32.fstype, "FAT32", 5)) goto fail; +#endif + + grub_dprintf ("exfat", "alive\n"); /* Get the sizes of logical sectors and clusters. */ +#ifdef MODE_EXFAT + data->logical_sector_bits = bpb.bytes_per_sector_shift; +#else data->logical_sector_bits = fat_log2 (grub_le_to_cpu16 (bpb.bytes_per_sector)); - if (data->logical_sector_bits < GRUB_DISK_SECTOR_BITS) +#endif + if (data->logical_sector_bits < GRUB_DISK_SECTOR_BITS + || data->logical_sector_bits >= 16) goto fail; data->logical_sector_bits -= GRUB_DISK_SECTOR_BITS; +#ifdef MODE_EXFAT + data->cluster_bits = bpb.sectors_per_cluster_shift; +#else data->cluster_bits = fat_log2 (bpb.sectors_per_cluster); - if (data->cluster_bits < 0) +#endif + if (data->cluster_bits < 0 || data->cluster_bits > 25) goto fail; data->cluster_bits += data->logical_sector_bits; @@ -210,18 +323,28 @@ grub_fat_mount (grub_disk_t disk) if (data->fat_sector == 0) goto fail; +#ifdef MODE_EXFAT + data->sectors_per_fat = (grub_le_to_cpu32 (bpb.sectors_per_fat) + << data->logical_sector_bits); +#else data->sectors_per_fat = ((bpb.sectors_per_fat_16 ? grub_le_to_cpu16 (bpb.sectors_per_fat_16) : grub_le_to_cpu32 (bpb.version_specific.fat32.sectors_per_fat_32)) << data->logical_sector_bits); +#endif if (data->sectors_per_fat == 0) goto fail; /* Get the number of sectors in this volume. */ +#ifdef MODE_EXFAT + data->num_sectors = ((grub_le_to_cpu64 (bpb.num_total_sectors)) + << data->logical_sector_bits); +#else data->num_sectors = ((bpb.num_total_sectors_16 ? grub_le_to_cpu16 (bpb.num_total_sectors_16) : grub_le_to_cpu32 (bpb.num_total_sectors_32)) << data->logical_sector_bits); +#endif if (data->num_sectors == 0) goto fail; @@ -229,6 +352,9 @@ grub_fat_mount (grub_disk_t disk) if (bpb.num_fats == 0) goto fail; + grub_dprintf ("exfat", "alive\n"); + +#ifndef MODE_EXFAT data->root_sector = data->fat_sector + bpb.num_fats * data->sectors_per_fat; data->num_root_sectors = ((((grub_uint32_t) grub_le_to_cpu16 (bpb.num_root_entries) @@ -236,15 +362,36 @@ grub_fat_mount (grub_disk_t disk) + grub_le_to_cpu16 (bpb.bytes_per_sector) - 1) >> (data->logical_sector_bits + GRUB_DISK_SECTOR_BITS)) << (data->logical_sector_bits)); +#endif +#ifdef MODE_EXFAT + data->cluster_sector = (grub_le_to_cpu32 (bpb.cluster_offset) + << data->logical_sector_bits); + data->num_clusters = (grub_le_to_cpu32 (bpb.cluster_count) + << data->logical_sector_bits); +#else data->cluster_sector = data->root_sector + data->num_root_sectors; data->num_clusters = (((data->num_sectors - data->cluster_sector) >> (data->cluster_bits + data->logical_sector_bits)) + 2); +#endif if (data->num_clusters <= 2) goto fail; +#ifdef MODE_EXFAT + { + /* exFAT. */ + grub_uint16_t flags = grub_le_to_cpu16 (bpb.volume_flags); + + data->root_cluster = grub_le_to_cpu32 (bpb.root_cluster); + data->fat_size = 32; + data->cluster_eof_mark = 0xffffffff; + + if ((flags & 0x1) && bpb.num_fats > 1) + data->fat_sector += data->sectors_per_fat; + } +#else if (! bpb.sectors_per_fat_16) { /* FAT32. */ @@ -286,6 +433,7 @@ grub_fat_mount (grub_disk_t disk) data->cluster_eof_mark = 0xfff8; } } +#endif /* More sanity checks. */ if (data->num_sectors <= data->fat_sector) @@ -317,17 +465,23 @@ grub_fat_mount (grub_disk_t disk) } /* Serial number. */ +#ifdef MODE_EXFAT + data->uuid = grub_le_to_cpu32 (bpb.num_serial); +#else if (bpb.sectors_per_fat_16) data->uuid = grub_le_to_cpu32 (bpb.version_specific.fat12_or_fat16.num_serial); else data->uuid = grub_le_to_cpu32 (bpb.version_specific.fat32.num_serial); +#endif +#ifndef MODE_EXFAT /* Ignore the 3rd bit, because some BIOSes assigns 0xF0 to the media descriptor, even if it is a so-called superfloppy (e.g. an USB key). The check may be too strict for this kind of stupid BIOSes, as they overwrite the media descriptor. */ if ((first_fat | 0x8) != (magic | bpb.media | 0x8)) goto fail; +#endif /* Start from the root directory. */ data->file_cluster = data->root_cluster; @@ -354,6 +508,7 @@ grub_fat_read_data (grub_disk_t disk, struct grub_fat_data *data, grub_ssize_t ret = 0; unsigned long sector; +#ifndef MODE_EXFAT /* This is a special case. FAT12 and FAT16 doesn't have the root directory in clusters. */ if (data->file_cluster == ~0U) @@ -367,6 +522,7 @@ grub_fat_read_data (grub_disk_t disk, struct grub_fat_data *data, return size; } +#endif /* Calculate the logical cluster number and offset. */ logical_cluster_bits = (data->cluster_bits @@ -465,13 +621,115 @@ grub_fat_read_data (grub_disk_t disk, struct grub_fat_data *data, return ret; } +#ifdef MODE_EXFAT +static grub_err_t +grub_fat_iterate_dir (grub_disk_t disk, struct grub_fat_data *data, + int (*hook) (const char *filename, + grub_fat_dir_node_t *node)) +{ + struct grub_fat_dir_entry dir; + grub_ssize_t offset = -sizeof(dir); + grub_uint16_t *unibuf; + char *filename; + + unibuf = grub_malloc (15 * 256 * 2); + filename = grub_malloc (15 * 256 * 4 + 1); + + while (1) + { + offset += sizeof (dir); + + if (grub_fat_read_data (disk, data, 0, + offset, sizeof (dir), (char *) &dir) + != sizeof (dir)) + break; + + if (dir.entry_type == 0) + break; + if (!(dir.entry_type & 0x80)) + continue; + + if (dir.entry_type == 0x85) + { + unsigned i, nsec, slots = 0; + grub_fat_dir_node_t node; + + nsec = dir.type_specific.file.secondary_count; + + node.attr = grub_cpu_to_le32 (dir.type_specific.file.attr); + node.have_stream = 0; + for (i = 0; i < nsec; i++) + { + struct grub_fat_dir_entry sec; + offset += sizeof (sec); + if (grub_fat_read_data (disk, data, 0, + offset, sizeof (sec), (char *) &sec) + != sizeof (sec)) + break; + if (!(sec.entry_type & 0x80)) + continue; + if (!(sec.entry_type & 0x40)) + break; + switch (sec.entry_type) + { + case 0xc0: + node.first_cluster = grub_cpu_to_le32 (sec.type_specific.stream_extension.first_cluster); + node.valid_size + = grub_cpu_to_le32 (sec.type_specific.stream_extension.valid_size); + node.file_size + = grub_cpu_to_le32 (sec.type_specific.stream_extension.file_size); + node.have_stream = 1; + break; + case 0xc1: + grub_memcpy (unibuf + slots * 15, + sec.type_specific.file_name.str, 30); + slots++; + break; + default: + grub_printf ("unknown secondary type 0x%02x\n", sec.entry_type); + } + } + + if (i != nsec) + { + offset -= sizeof (dir); + continue; + } + + *grub_utf16_to_utf8 ((grub_uint8_t *) filename, unibuf, + slots * 15) = '\0'; + + if (hook (filename, &node)) + break; + continue; + } + /* Allocation bitmap. */ + if (dir.entry_type == 0x81) + continue; + /* Upcase table. */ + if (dir.entry_type == 0x82) + continue; + /* Volume label. */ + if (dir.entry_type == 0x83) + continue; + grub_printf ("unknown primary type 0x%02x\n", dir.entry_type); + } + grub_free (filename); + grub_free (unibuf); + + return grub_errno; +} + +#else + static grub_err_t grub_fat_iterate_dir (grub_disk_t disk, struct grub_fat_data *data, int (*hook) (const char *filename, struct grub_fat_dir_entry *dir)) { struct grub_fat_dir_entry dir; - char *filename, *filep = 0; + char *filename; + char *filep = 0; grub_uint16_t *unibuf; int slot = -1, slots = -1; int checksum = -1; @@ -498,10 +756,11 @@ grub_fat_iterate_dir (grub_disk_t disk, struct grub_fat_data *data, offset += sizeof (dir); /* Read a directory entry. */ - if ((grub_fat_read_data (disk, data, 0, + if (grub_fat_read_data (disk, data, 0, offset, sizeof (dir), (char *) &dir) - != sizeof (dir) || dir.name[0] == 0)) + != sizeof (dir) || dir.name[0] == 0) break; + /* Handle long name entries. */ if (dir.attr == GRUB_FAT_ATTR_LONG_NAME) { @@ -586,7 +845,6 @@ grub_fat_iterate_dir (grub_disk_t disk, struct grub_fat_data *data, filep++; } *filep = '\0'; - if (hook (filename, &dir)) break; } @@ -596,7 +854,7 @@ grub_fat_iterate_dir (grub_disk_t disk, struct grub_fat_data *data, return grub_errno; } - +#endif /* Find the underlying directory or file in PATH and return the next path. If there is no next path or an error occurs, return NULL. @@ -611,8 +869,8 @@ grub_fat_find_dir (grub_disk_t disk, struct grub_fat_data *data, int call_hook; int found = 0; - auto int iter_hook (const char *filename, struct grub_fat_dir_entry *dir); - int iter_hook (const char *filename, struct grub_fat_dir_entry *dir) + auto int iter_hook (const char *filename, grub_fat_dir_node_t *dir); + int iter_hook (const char *filename, grub_fat_dir_node_t *dir) { struct grub_dirhook_info info; grub_memset (&info, 0, sizeof (info)); @@ -620,8 +878,13 @@ grub_fat_find_dir (grub_disk_t disk, struct grub_fat_data *data, info.dir = !! (dir->attr & GRUB_FAT_ATTR_DIRECTORY); info.case_insensitive = 1; +#ifdef MODE_EXFAT + if (!dir->have_stream) + return 0; +#else if (dir->attr & GRUB_FAT_ATTR_VOLUME_ID) return 0; +#endif if (*dirname == '\0' && call_hook) return hook (filename, &info); @@ -629,9 +892,14 @@ grub_fat_find_dir (grub_disk_t disk, struct grub_fat_data *data, { found = 1; data->attr = dir->attr; +#ifdef MODE_EXFAT + data->file_size = dir->file_size; + data->file_cluster = dir->first_cluster; +#else data->file_size = grub_le_to_cpu32 (dir->file_size); data->file_cluster = ((grub_le_to_cpu16 (dir->first_cluster_high) << 16) | grub_le_to_cpu16 (dir->first_cluster_low)); +#endif data->cur_cluster_num = ~0U; if (call_hook) @@ -781,14 +1049,61 @@ grub_fat_close (grub_file_t file) return grub_errno; } +#ifdef MODE_EXFAT +static grub_err_t +grub_fat_label (grub_device_t device, char **label) +{ + struct grub_fat_dir_entry dir; + grub_ssize_t offset = -sizeof(dir); + struct grub_fat_data *data; + grub_disk_t disk = device->disk; + + data = grub_fat_mount (disk); + if (! data) + return grub_errno; + + while (1) + { + offset += sizeof (dir); + + if (grub_fat_read_data (disk, data, 0, + offset, sizeof (dir), (char *) &dir) + != sizeof (dir)) + break; + + if (dir.entry_type == 0) + break; + if (!(dir.entry_type & 0x80)) + continue; + + /* Volume label. */ + if (dir.entry_type == 0x83) + { + grub_size_t chc; + *label = grub_malloc (11 * 4 + 1); + if (!*label) + return grub_errno; + chc = dir.type_specific.volume_label.character_count; + if (chc > ARRAY_SIZE (dir.type_specific.volume_label.str)) + chc = ARRAY_SIZE (dir.type_specific.volume_label.str); + *grub_utf16_to_utf8 ((grub_uint8_t *) *label, + dir.type_specific.volume_label.str, chc) = '\0'; + } + } + + return grub_errno; +} + +#else + static grub_err_t grub_fat_label (grub_device_t device, char **label) { struct grub_fat_data *data; grub_disk_t disk = device->disk; - auto int iter_hook (const char *filename, struct grub_fat_dir_entry *dir); - int iter_hook (const char *filename, struct grub_fat_dir_entry *dir) + auto int iter_hook (const char *filename, grub_fat_dir_node_t *dir); + int iter_hook (const char *filename, grub_fat_dir_node_t *dir) { if (dir->attr == GRUB_FAT_ATTR_VOLUME_ID) { @@ -823,6 +1138,8 @@ grub_fat_label (grub_device_t device, char **label) return grub_errno; } +#endif + static grub_err_t grub_fat_uuid (grub_device_t device, char **uuid) { @@ -850,7 +1167,11 @@ grub_fat_uuid (grub_device_t device, char **uuid) static struct grub_fs grub_fat_fs = { +#ifdef MODE_EXFAT + .name = "exfat", +#else .name = "fat", +#endif .dir = grub_fat_dir, .open = grub_fat_open, .read = grub_fat_read, @@ -858,18 +1179,30 @@ static struct grub_fs grub_fat_fs = .label = grub_fat_label, .uuid = grub_fat_uuid, #ifdef GRUB_UTIL +#ifdef MODE_EXFAT + /* ExFAT BPB is 30 larger than FAT32 one. */ + .reserved_first_sector = 0, +#else .reserved_first_sector = 1, +#endif #endif .next = 0 }; +#ifdef MODE_EXFAT +GRUB_MOD_INIT(exfat) +#else GRUB_MOD_INIT(fat) +#endif { grub_fs_register (&grub_fat_fs); my_mod = mod; } - +#ifdef MODE_EXFAT +GRUB_MOD_FINI(exfat) +#else GRUB_MOD_FINI(fat) +#endif { grub_fs_unregister (&grub_fat_fs); } From b6929f5ef598a6d76129fc1915a87bdcf7c62fb8 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 11 Apr 2011 20:38:08 +0200 Subject: [PATCH 449/869] Transform exfat printfs into dprintfs --- grub-core/fs/fat.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/grub-core/fs/fat.c b/grub-core/fs/fat.c index 5f7a58571..49bb3a599 100644 --- a/grub-core/fs/fat.c +++ b/grub-core/fs/fat.c @@ -686,7 +686,8 @@ grub_fat_iterate_dir (grub_disk_t disk, struct grub_fat_data *data, slots++; break; default: - grub_printf ("unknown secondary type 0x%02x\n", sec.entry_type); + grub_dprintf ("exfat", "unknown secondary type 0x%02x\n", + sec.entry_type); } } @@ -712,7 +713,7 @@ grub_fat_iterate_dir (grub_disk_t disk, struct grub_fat_data *data, /* Volume label. */ if (dir.entry_type == 0x83) continue; - grub_printf ("unknown primary type 0x%02x\n", dir.entry_type); + grub_dprintf ("exfat", "unknown primary type 0x%02x\n", dir.entry_type); } grub_free (filename); grub_free (unibuf); From e745cf0ca64f94fa072d777cde8186aca2b78c1f Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 11 Apr 2011 23:01:51 +0200 Subject: [PATCH 450/869] Implement automatic module license checking according to new GNU guidelines. * grub-core/kern/dl.c (grub_dl_check_license): New function. (grub_dl_load_core): Use grub_dl_check_license. * include/grub/dl.h (GRUB_MOD_SECTION): New macro. (GRUB_MOD_LICENSE): Likewise. (GRUB_MOD_DUAL_LICENSE): Likewise. All modules updated. --- ChangeLog | 12 +++++++ grub-core/bus/cs5536.c | 4 +++ grub-core/bus/pci.c | 2 ++ grub-core/bus/usb/emu/usb.c | 2 ++ grub-core/bus/usb/ohci.c | 2 ++ grub-core/bus/usb/serial/common.c | 3 ++ grub-core/bus/usb/serial/ftdi.c | 2 ++ grub-core/bus/usb/serial/pl2303.c | 2 ++ grub-core/bus/usb/uhci.c | 2 ++ grub-core/bus/usb/usb.c | 2 ++ grub-core/commands/acpi.c | 2 ++ grub-core/commands/blocklist.c | 2 ++ grub-core/commands/boot.c | 2 ++ grub-core/commands/cat.c | 2 ++ grub-core/commands/cmp.c | 2 ++ grub-core/commands/configfile.c | 2 ++ grub-core/commands/date.c | 2 ++ grub-core/commands/echo.c | 2 ++ grub-core/commands/efi/fixvideo.c | 2 ++ grub-core/commands/efi/loadbios.c | 2 ++ grub-core/commands/efi/lsefimmap.c | 2 ++ grub-core/commands/efi/lsefisystab.c | 3 ++ grub-core/commands/efi/lssal.c | 3 ++ grub-core/commands/extcmd.c | 3 ++ grub-core/commands/gptsync.c | 2 ++ grub-core/commands/halt.c | 2 ++ grub-core/commands/hashsum.c | 2 ++ grub-core/commands/hdparm.c | 2 ++ grub-core/commands/help.c | 2 ++ grub-core/commands/hexdump.c | 2 ++ grub-core/commands/i386/cmostest.c | 2 ++ grub-core/commands/i386/cpuid.c | 2 ++ grub-core/commands/i386/pc/drivemap.c | 1 + grub-core/commands/i386/pc/halt.c | 2 ++ grub-core/commands/i386/pc/lsapm.c | 2 ++ grub-core/commands/i386/pc/play.c | 2 ++ grub-core/commands/i386/pc/pxecmd.c | 2 ++ grub-core/commands/i386/pc/sendkey.c | 2 ++ grub-core/commands/ieee1275/suspend.c | 2 ++ grub-core/commands/iorw.c | 2 ++ grub-core/commands/keylayouts.c | 2 ++ grub-core/commands/keystatus.c | 2 ++ grub-core/commands/legacycfg.c | 2 ++ grub-core/commands/loadenv.c | 2 ++ grub-core/commands/ls.c | 2 ++ grub-core/commands/lsacpi.c | 2 ++ grub-core/commands/lsmmap.c | 2 ++ grub-core/commands/lspci.c | 2 ++ grub-core/commands/memrw.c | 2 ++ grub-core/commands/minicmd.c | 2 ++ grub-core/commands/mips/yeeloong/lsspd.c | 2 ++ grub-core/commands/parttool.c | 2 ++ grub-core/commands/password.c | 2 ++ grub-core/commands/password_pbkdf2.c | 2 ++ grub-core/commands/probe.c | 2 ++ grub-core/commands/read.c | 2 ++ grub-core/commands/reboot.c | 2 ++ grub-core/commands/regexp.c | 2 ++ grub-core/commands/search.c | 2 ++ grub-core/commands/search_wrap.c | 2 ++ grub-core/commands/setpci.c | 2 ++ grub-core/commands/sleep.c | 2 ++ grub-core/commands/terminal.c | 2 ++ grub-core/commands/test.c | 2 ++ grub-core/commands/testload.c | 2 ++ grub-core/commands/true.c | 2 ++ grub-core/commands/usbtest.c | 2 ++ grub-core/commands/videoinfo.c | 2 ++ grub-core/commands/videotest.c | 2 ++ grub-core/commands/xnu_uuid.c | 2 ++ grub-core/disk/ata.c | 2 ++ grub-core/disk/ata_pthru.c | 1 + grub-core/disk/dmraid_nvidia.c | 2 ++ grub-core/disk/i386/pc/biosdisk.c | 2 ++ grub-core/disk/ieee1275/nand.c | 2 ++ grub-core/disk/loopback.c | 2 ++ grub-core/disk/lvm.c | 2 ++ grub-core/disk/mdraid1x_linux.c | 2 ++ grub-core/disk/mdraid_linux.c | 2 ++ grub-core/disk/memdisk.c | 2 ++ grub-core/disk/raid.c | 2 ++ grub-core/disk/raid5_recover.c | 2 ++ grub-core/disk/raid6_recover.c | 2 ++ grub-core/disk/scsi.c | 2 ++ grub-core/disk/usbms.c | 2 ++ grub-core/efiemu/main.c | 2 ++ grub-core/font/font.c | 2 ++ grub-core/fs/affs.c | 2 ++ grub-core/fs/afs.c | 2 ++ grub-core/fs/btrfs.c | 2 ++ grub-core/fs/cpio.c | 2 ++ grub-core/fs/ext2.c | 2 ++ grub-core/fs/fat.c | 2 ++ grub-core/fs/fshelp.c | 2 ++ grub-core/fs/hfs.c | 2 ++ grub-core/fs/hfsplus.c | 2 ++ grub-core/fs/i386/pc/pxe.c | 2 ++ grub-core/fs/iso9660.c | 2 ++ grub-core/fs/jfs.c | 2 ++ grub-core/fs/minix.c | 2 ++ grub-core/fs/nilfs2.c | 2 ++ grub-core/fs/ntfs.c | 2 ++ grub-core/fs/ntfscomp.c | 2 ++ grub-core/fs/reiserfs.c | 2 ++ grub-core/fs/sfs.c | 2 ++ grub-core/fs/udf.c | 2 ++ grub-core/fs/ufs.c | 2 ++ grub-core/fs/xfs.c | 2 ++ grub-core/fs/zfs/zfs.c | 2 ++ grub-core/fs/zfs/zfsinfo.c | 2 ++ grub-core/gentrigtables.c | 8 +++++ grub-core/gettext/gettext.c | 2 ++ grub-core/gfxmenu/gfxmenu.c | 2 ++ grub-core/gnulib/regex.c | 3 ++ grub-core/hello/hello.c | 2 ++ grub-core/hook/datehook.c | 2 ++ grub-core/io/bufio.c | 3 ++ grub-core/io/gzio.c | 2 ++ grub-core/io/xzio.c | 2 ++ grub-core/kern/dl.c | 43 ++++++++++++++++++++++- grub-core/kern/elf.c | 3 ++ grub-core/lib/cmos_datetime.c | 3 ++ grub-core/lib/crypto.c | 3 ++ grub-core/lib/pbkdf2.c | 3 ++ grub-core/lib/relocator.c | 3 ++ grub-core/loader/aout.c | 2 ++ grub-core/loader/efi/appleloader.c | 2 ++ grub-core/loader/efi/chainloader.c | 2 ++ grub-core/loader/i386/bsd.c | 2 ++ grub-core/loader/i386/linux.c | 2 ++ grub-core/loader/i386/pc/chainloader.c | 2 ++ grub-core/loader/i386/pc/linux.c | 2 ++ grub-core/loader/i386/pc/ntldr.c | 2 ++ grub-core/loader/mips/linux.c | 2 ++ grub-core/loader/multiboot.c | 2 ++ grub-core/loader/powerpc/ieee1275/linux.c | 2 ++ grub-core/loader/sparc64/ieee1275/linux.c | 2 ++ grub-core/loader/xnu.c | 2 ++ grub-core/mmap/mmap.c | 2 ++ grub-core/normal/main.c | 2 ++ grub-core/partmap/acorn.c | 2 ++ grub-core/partmap/amiga.c | 2 ++ grub-core/partmap/apple.c | 2 ++ grub-core/partmap/bsdlabel.c | 2 ++ grub-core/partmap/gpt.c | 2 ++ grub-core/partmap/msdos.c | 2 ++ grub-core/partmap/sun.c | 2 ++ grub-core/partmap/sunpc.c | 2 ++ grub-core/parttool/msdospart.c | 2 ++ grub-core/term/at_keyboard.c | 2 ++ grub-core/term/gfxterm.c | 2 ++ grub-core/term/i386/pc/vga_text.c | 2 ++ grub-core/term/serial.c | 2 ++ grub-core/term/terminfo.c | 2 ++ grub-core/term/usb_keyboard.c | 2 ++ grub-core/tests/example_functional_test.c | 3 ++ grub-core/tests/lib/functional_test.c | 3 ++ grub-core/tests/test_blockarg.c | 2 ++ grub-core/video/bitmap.c | 2 ++ grub-core/video/bitmap_scale.c | 3 ++ grub-core/video/bochs.c | 2 ++ grub-core/video/cirrus.c | 2 ++ grub-core/video/efi_gop.c | 2 ++ grub-core/video/efi_uga.c | 2 ++ grub-core/video/emu/sdl.c | 2 ++ grub-core/video/fb/video_fb.c | 3 ++ grub-core/video/i386/pc/vbe.c | 2 ++ grub-core/video/i386/pc/vga.c | 2 ++ grub-core/video/ieee1275.c | 2 ++ grub-core/video/readers/jpeg.c | 2 ++ grub-core/video/readers/png.c | 2 ++ grub-core/video/readers/tga.c | 2 ++ grub-core/video/video.c | 2 ++ include/grub/dl.h | 24 +++++++++++++ util/import_gcry.py | 7 +++- 175 files changed, 447 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 295a23d1a..a3d1e7f92 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2011-04-11 Vladimir Serbinenko + + Implement automatic module license checking according to new GNU + guidelines. + + * grub-core/kern/dl.c (grub_dl_check_license): New function. + (grub_dl_load_core): Use grub_dl_check_license. + * include/grub/dl.h (GRUB_MOD_SECTION): New macro. + (GRUB_MOD_LICENSE): Likewise. + (GRUB_MOD_DUAL_LICENSE): Likewise. + All modules updated. + 2011-04-11 Colin Watson * grub-core/fs/btrfs.c (grub_btrfs_fs) [GRUB_UTIL]: Set diff --git a/grub-core/bus/cs5536.c b/grub-core/bus/cs5536.c index 088f4dfc1..fbcb83cfe 100644 --- a/grub-core/bus/cs5536.c +++ b/grub-core/bus/cs5536.c @@ -22,6 +22,10 @@ #include #include +#include + +GRUB_MOD_LICENSE ("GPLv3+"); + int grub_cs5536_find (grub_pci_device_t *devp) { diff --git a/grub-core/bus/pci.c b/grub-core/bus/pci.c index 11101d42b..07d20e3f5 100644 --- a/grub-core/bus/pci.c +++ b/grub-core/bus/pci.c @@ -21,6 +21,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + /* FIXME: correctly support 64-bit architectures. */ /* #if GRUB_TARGET_SIZEOF_VOID_P == 4 */ struct grub_pci_dma_chunk * diff --git a/grub-core/bus/usb/emu/usb.c b/grub-core/bus/usb/emu/usb.c index 7d52decb2..38c5f01f1 100644 --- a/grub-core/bus/usb/emu/usb.c +++ b/grub-core/bus/usb/emu/usb.c @@ -24,6 +24,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + static struct grub_usb_controller_dev usb_controller = { diff --git a/grub-core/bus/usb/ohci.c b/grub-core/bus/usb/ohci.c index 8adaee6e0..df0d0f4af 100644 --- a/grub-core/bus/usb/ohci.c +++ b/grub-core/bus/usb/ohci.c @@ -29,6 +29,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + struct grub_ohci_hcca { /* Pointers to Interrupt Endpoint Descriptors. Not used by diff --git a/grub-core/bus/usb/serial/common.c b/grub-core/bus/usb/serial/common.c index ee8794de0..55d1884cc 100644 --- a/grub-core/bus/usb/serial/common.c +++ b/grub-core/bus/usb/serial/common.c @@ -18,6 +18,9 @@ #include #include +#include + +GRUB_MOD_LICENSE ("GPLv3+"); void grub_usbserial_fini (struct grub_serial_port *port) diff --git a/grub-core/bus/usb/serial/ftdi.c b/grub-core/bus/usb/serial/ftdi.c index bd1713b27..07ac7ac52 100644 --- a/grub-core/bus/usb/serial/ftdi.c +++ b/grub-core/bus/usb/serial/ftdi.c @@ -24,6 +24,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + enum { GRUB_FTDI_MODEM_CTRL = 0x01, diff --git a/grub-core/bus/usb/serial/pl2303.c b/grub-core/bus/usb/serial/pl2303.c index 9e3b9ae7e..b9954116b 100644 --- a/grub-core/bus/usb/serial/pl2303.c +++ b/grub-core/bus/usb/serial/pl2303.c @@ -24,6 +24,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + /* Convert speed to divisor. */ static grub_uint32_t is_speed_supported (unsigned int speed) diff --git a/grub-core/bus/usb/uhci.c b/grub-core/bus/usb/uhci.c index 71142846b..99e597f6d 100644 --- a/grub-core/bus/usb/uhci.c +++ b/grub-core/bus/usb/uhci.c @@ -26,6 +26,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + #define GRUB_UHCI_IOMASK (0x7FF << 5) #define N_QH 256 diff --git a/grub-core/bus/usb/usb.c b/grub-core/bus/usb/usb.c index 70173b7ea..005d3bcf0 100644 --- a/grub-core/bus/usb/usb.c +++ b/grub-core/bus/usb/usb.c @@ -24,6 +24,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + static grub_usb_controller_dev_t grub_usb_list; static struct grub_usb_attach_desc *attach_hooks; diff --git a/grub-core/commands/acpi.c b/grub-core/commands/acpi.c index 4f03997e0..8f4429627 100644 --- a/grub-core/commands/acpi.c +++ b/grub-core/commands/acpi.c @@ -33,6 +33,8 @@ #include #endif +GRUB_MOD_LICENSE ("GPLv3+"); + static const struct grub_arg_option options[] = { {"exclude", 'x', 0, N_("Don't load host tables specified by comma-separated list."), diff --git a/grub-core/commands/blocklist.c b/grub-core/commands/blocklist.c index 4651fb32a..5eb12e434 100644 --- a/grub-core/commands/blocklist.c +++ b/grub-core/commands/blocklist.c @@ -26,6 +26,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + static grub_err_t grub_cmd_blocklist (grub_command_t cmd __attribute__ ((unused)), int argc, char **args) diff --git a/grub-core/commands/boot.c b/grub-core/commands/boot.c index 1ec1e6f77..7714011bf 100644 --- a/grub-core/commands/boot.c +++ b/grub-core/commands/boot.c @@ -25,6 +25,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + static grub_err_t (*grub_loader_boot_func) (void); static grub_err_t (*grub_loader_unload_func) (void); static int grub_loader_noreturn; diff --git a/grub-core/commands/cat.c b/grub-core/commands/cat.c index 79ecf75c7..9be6cbc8f 100644 --- a/grub-core/commands/cat.c +++ b/grub-core/commands/cat.c @@ -25,6 +25,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + static const struct grub_arg_option options[] = { {"dos", -1, 0, N_("Accept DOS-style CR/NL line endings."), 0, 0}, diff --git a/grub-core/commands/cmp.c b/grub-core/commands/cmp.c index d9e76a4d7..0222927b6 100644 --- a/grub-core/commands/cmp.c +++ b/grub-core/commands/cmp.c @@ -24,6 +24,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + #define BUFFER_SIZE 512 static grub_err_t diff --git a/grub-core/commands/configfile.c b/grub-core/commands/configfile.c index 2568b7ee6..124a09a9e 100644 --- a/grub-core/commands/configfile.c +++ b/grub-core/commands/configfile.c @@ -24,6 +24,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + static grub_err_t grub_cmd_source (grub_command_t cmd, int argc, char **args) { diff --git a/grub-core/commands/date.c b/grub-core/commands/date.c index 623db4943..d27162077 100644 --- a/grub-core/commands/date.c +++ b/grub-core/commands/date.c @@ -24,6 +24,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + #define GRUB_DATETIME_SET_YEAR 1 #define GRUB_DATETIME_SET_MONTH 2 #define GRUB_DATETIME_SET_DAY 4 diff --git a/grub-core/commands/echo.c b/grub-core/commands/echo.c index 93a452fc8..81ba50d68 100644 --- a/grub-core/commands/echo.c +++ b/grub-core/commands/echo.c @@ -23,6 +23,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + static const struct grub_arg_option options[] = { {0, 'n', 0, N_("Do not output the trailing newline."), 0, 0}, diff --git a/grub-core/commands/efi/fixvideo.c b/grub-core/commands/efi/fixvideo.c index 6430be5e3..c53e47d8a 100644 --- a/grub-core/commands/efi/fixvideo.c +++ b/grub-core/commands/efi/fixvideo.c @@ -24,6 +24,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + static struct grub_video_patch { const char *name; diff --git a/grub-core/commands/efi/loadbios.c b/grub-core/commands/efi/loadbios.c index 8c7c25abd..138311222 100644 --- a/grub-core/commands/efi/loadbios.c +++ b/grub-core/commands/efi/loadbios.c @@ -25,6 +25,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + static grub_efi_guid_t acpi_guid = GRUB_EFI_ACPI_TABLE_GUID; static grub_efi_guid_t acpi2_guid = GRUB_EFI_ACPI_20_TABLE_GUID; static grub_efi_guid_t smbios_guid = GRUB_EFI_SMBIOS_TABLE_GUID; diff --git a/grub-core/commands/efi/lsefimmap.c b/grub-core/commands/efi/lsefimmap.c index 2bb5dcb5d..215b45bff 100644 --- a/grub-core/commands/efi/lsefimmap.c +++ b/grub-core/commands/efi/lsefimmap.c @@ -23,6 +23,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + #define ADD_MEMORY_DESCRIPTOR(desc, size) \ ((grub_efi_memory_descriptor_t *) ((char *) (desc) + (size))) diff --git a/grub-core/commands/efi/lsefisystab.c b/grub-core/commands/efi/lsefisystab.c index aa3e05aee..b2359253a 100644 --- a/grub-core/commands/efi/lsefisystab.c +++ b/grub-core/commands/efi/lsefisystab.c @@ -18,12 +18,15 @@ */ #include #include +#include #include #include #include #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + struct guid_mapping { grub_efi_guid_t guid; diff --git a/grub-core/commands/efi/lssal.c b/grub-core/commands/efi/lssal.c index 2ee993033..fa8005b88 100644 --- a/grub-core/commands/efi/lssal.c +++ b/grub-core/commands/efi/lssal.c @@ -23,6 +23,9 @@ #include #include #include +#include + +GRUB_MOD_LICENSE ("GPLv3+"); static void disp_sal (void *table) diff --git a/grub-core/commands/extcmd.c b/grub-core/commands/extcmd.c index e9274fbab..69574e2b0 100644 --- a/grub-core/commands/extcmd.c +++ b/grub-core/commands/extcmd.c @@ -22,6 +22,9 @@ #include #include #include +#include + +GRUB_MOD_LICENSE ("GPLv3+"); grub_err_t grub_extcmd_dispatcher (struct grub_command *cmd, int argc, char **args, diff --git a/grub-core/commands/gptsync.c b/grub-core/commands/gptsync.c index 6364c13f7..e92dc20ec 100644 --- a/grub-core/commands/gptsync.c +++ b/grub-core/commands/gptsync.c @@ -29,6 +29,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + /* Convert a LBA address to a CHS address in the INT 13 format. */ /* Taken from grub1. */ /* XXX: use hardcoded geometry of C = 1024, H = 255, S = 63. diff --git a/grub-core/commands/halt.c b/grub-core/commands/halt.c index 3400115a0..317f7753f 100644 --- a/grub-core/commands/halt.c +++ b/grub-core/commands/halt.c @@ -22,6 +22,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + static grub_err_t grub_cmd_halt (grub_command_t cmd __attribute__ ((unused)), int argc __attribute__ ((unused)), diff --git a/grub-core/commands/hashsum.c b/grub-core/commands/hashsum.c index 664fe9c24..6825d4811 100644 --- a/grub-core/commands/hashsum.c +++ b/grub-core/commands/hashsum.c @@ -26,6 +26,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + static const struct grub_arg_option options[] = { {"hash", 'h', 0, N_("Specify hash to use."), N_("HASH"), ARG_TYPE_STRING}, {"check", 'c', 0, N_("Check hash list file."), N_("FILE"), ARG_TYPE_STRING}, diff --git a/grub-core/commands/hdparm.c b/grub-core/commands/hdparm.c index b6ab78755..0c12b8814 100644 --- a/grub-core/commands/hdparm.c +++ b/grub-core/commands/hdparm.c @@ -26,6 +26,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + static const struct grub_arg_option options[] = { {"apm", 'B', 0, N_("Set Advanced Power Management\n" "(1=low, ..., 254=high, 255=off)."), diff --git a/grub-core/commands/help.c b/grub-core/commands/help.c index ff6d7ed2e..82f3200c7 100644 --- a/grub-core/commands/help.c +++ b/grub-core/commands/help.c @@ -26,6 +26,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + static grub_err_t grub_cmd_help (grub_extcmd_context_t ctxt __attribute__ ((unused)), int argc, char **args) diff --git a/grub-core/commands/hexdump.c b/grub-core/commands/hexdump.c index 629f2a069..9ba83598a 100644 --- a/grub-core/commands/hexdump.c +++ b/grub-core/commands/hexdump.c @@ -25,6 +25,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + static const struct grub_arg_option options[] = { {"skip", 's', 0, N_("Skip offset bytes from the beginning of file."), 0, ARG_TYPE_INT}, diff --git a/grub-core/commands/i386/cmostest.c b/grub-core/commands/i386/cmostest.c index 994da11b0..c79bd0387 100644 --- a/grub-core/commands/i386/cmostest.c +++ b/grub-core/commands/i386/cmostest.c @@ -21,6 +21,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + static grub_err_t parse_args (int argc, char *argv[], int *byte, int *bit) { diff --git a/grub-core/commands/i386/cpuid.c b/grub-core/commands/i386/cpuid.c index f5f0f15a8..6a771ba74 100644 --- a/grub-core/commands/i386/cpuid.c +++ b/grub-core/commands/i386/cpuid.c @@ -27,6 +27,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + #define cpuid(num,a,b,c,d) \ asm volatile ("xchgl %%ebx, %1; cpuid; xchgl %%ebx, %1" \ : "=a" (a), "=r" (b), "=c" (c), "=d" (d) \ diff --git a/grub-core/commands/i386/pc/drivemap.c b/grub-core/commands/i386/pc/drivemap.c index ed4211cca..c9c8881b4 100644 --- a/grub-core/commands/i386/pc/drivemap.c +++ b/grub-core/commands/i386/pc/drivemap.c @@ -29,6 +29,7 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); /* Real mode IVT slot (seg:off far pointer) for interrupt 0x13. */ static grub_uint32_t *const int13slot = UINT_TO_PTR (4 * 0x13); diff --git a/grub-core/commands/i386/pc/halt.c b/grub-core/commands/i386/pc/halt.c index 81eb6a1bb..e7c191de3 100644 --- a/grub-core/commands/i386/pc/halt.c +++ b/grub-core/commands/i386/pc/halt.c @@ -24,6 +24,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + static const struct grub_arg_option options[] = { {"no-apm", 'n', 0, N_("Do not use APM to halt the computer."), 0, 0}, diff --git a/grub-core/commands/i386/pc/lsapm.c b/grub-core/commands/i386/pc/lsapm.c index 30475d2ec..17bcfd6eb 100644 --- a/grub-core/commands/i386/pc/lsapm.c +++ b/grub-core/commands/i386/pc/lsapm.c @@ -22,6 +22,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + int grub_apm_get_info (struct grub_apm_info *info) { diff --git a/grub-core/commands/i386/pc/play.c b/grub-core/commands/i386/pc/play.c index 4ed937d4a..57980eb92 100644 --- a/grub-core/commands/i386/pc/play.c +++ b/grub-core/commands/i386/pc/play.c @@ -29,6 +29,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + #define BASE_TEMPO (60 * GRUB_TICKS_PER_SECOND) /* The speaker port. */ diff --git a/grub-core/commands/i386/pc/pxecmd.c b/grub-core/commands/i386/pc/pxecmd.c index b576a8ea4..dffa15a3a 100644 --- a/grub-core/commands/i386/pc/pxecmd.c +++ b/grub-core/commands/i386/pc/pxecmd.c @@ -24,6 +24,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + static grub_err_t grub_cmd_pxe_unload (grub_command_t cmd __attribute__ ((unused)), int argc __attribute__ ((unused)), diff --git a/grub-core/commands/i386/pc/sendkey.c b/grub-core/commands/i386/pc/sendkey.c index c777ea60a..a55d17bd0 100644 --- a/grub-core/commands/i386/pc/sendkey.c +++ b/grub-core/commands/i386/pc/sendkey.c @@ -27,6 +27,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv2+"); + static char sendkey[0x20]; /* Length of sendkey. */ static int keylen = 0; diff --git a/grub-core/commands/ieee1275/suspend.c b/grub-core/commands/ieee1275/suspend.c index f096cc9ba..de068951d 100644 --- a/grub-core/commands/ieee1275/suspend.c +++ b/grub-core/commands/ieee1275/suspend.c @@ -24,6 +24,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + static grub_err_t grub_cmd_suspend (grub_command_t cmd __attribute__ ((unused)), int argc __attribute__ ((unused)), diff --git a/grub-core/commands/iorw.c b/grub-core/commands/iorw.c index 20d203e92..e7035b528 100644 --- a/grub-core/commands/iorw.c +++ b/grub-core/commands/iorw.c @@ -24,6 +24,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + static grub_extcmd_t cmd_read_byte, cmd_read_word, cmd_read_dword; static grub_command_t cmd_write_byte, cmd_write_word, cmd_write_dword; diff --git a/grub-core/commands/keylayouts.c b/grub-core/commands/keylayouts.c index deb482a85..6c5913a54 100644 --- a/grub-core/commands/keylayouts.c +++ b/grub-core/commands/keylayouts.c @@ -28,6 +28,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + static struct grub_keyboard_layout layout_us = { .keyboard_map = { /* Keyboard errors. Handled by driver. */ diff --git a/grub-core/commands/keystatus.c b/grub-core/commands/keystatus.c index 9e1486c9d..f3a669942 100644 --- a/grub-core/commands/keystatus.c +++ b/grub-core/commands/keystatus.c @@ -23,6 +23,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + static const struct grub_arg_option options[] = { {"shift", 's', 0, N_("Check Shift key."), 0, 0}, diff --git a/grub-core/commands/legacycfg.c b/grub-core/commands/legacycfg.c index 23c1c1908..e68b3315a 100644 --- a/grub-core/commands/legacycfg.c +++ b/grub-core/commands/legacycfg.c @@ -33,6 +33,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + static grub_err_t legacy_file (const char *filename) { diff --git a/grub-core/commands/loadenv.c b/grub-core/commands/loadenv.c index 38b3a84c6..5d53a8e66 100644 --- a/grub-core/commands/loadenv.c +++ b/grub-core/commands/loadenv.c @@ -28,6 +28,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + static const struct grub_arg_option options[] = { {"file", 'f', 0, N_("Specify filename."), 0, ARG_TYPE_PATHNAME}, diff --git a/grub-core/commands/ls.c b/grub-core/commands/ls.c index 481d17db0..5fc648a9b 100644 --- a/grub-core/commands/ls.c +++ b/grub-core/commands/ls.c @@ -32,6 +32,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + static const struct grub_arg_option options[] = { {"long", 'l', 0, N_("Show a long list with more detailed information."), 0, 0}, diff --git a/grub-core/commands/lsacpi.c b/grub-core/commands/lsacpi.c index 64b559665..fd19e380a 100644 --- a/grub-core/commands/lsacpi.c +++ b/grub-core/commands/lsacpi.c @@ -25,6 +25,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + static void print_strn (grub_uint8_t *str, grub_size_t len) { diff --git a/grub-core/commands/lsmmap.c b/grub-core/commands/lsmmap.c index 657f81387..44598f0df 100644 --- a/grub-core/commands/lsmmap.c +++ b/grub-core/commands/lsmmap.c @@ -22,6 +22,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + static const char *names[] = { [GRUB_MEMORY_AVAILABLE] = "available", diff --git a/grub-core/commands/lspci.c b/grub-core/commands/lspci.c index fd2d4eaf2..03541df6c 100644 --- a/grub-core/commands/lspci.c +++ b/grub-core/commands/lspci.c @@ -23,6 +23,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + struct grub_pci_classname { int class; diff --git a/grub-core/commands/memrw.c b/grub-core/commands/memrw.c index 28aac7d81..3b51189d6 100644 --- a/grub-core/commands/memrw.c +++ b/grub-core/commands/memrw.c @@ -23,6 +23,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + static grub_extcmd_t cmd_read_byte, cmd_read_word, cmd_read_dword; static grub_command_t cmd_write_byte, cmd_write_word, cmd_write_dword; diff --git a/grub-core/commands/minicmd.c b/grub-core/commands/minicmd.c index 5cf109fde..c7d1ec4f5 100644 --- a/grub-core/commands/minicmd.c +++ b/grub-core/commands/minicmd.c @@ -29,6 +29,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + /* cat FILE */ static grub_err_t grub_mini_cmd_cat (struct grub_command *cmd __attribute__ ((unused)), diff --git a/grub-core/commands/mips/yeeloong/lsspd.c b/grub-core/commands/mips/yeeloong/lsspd.c index 539cda34c..c1c5e2ef7 100644 --- a/grub-core/commands/mips/yeeloong/lsspd.c +++ b/grub-core/commands/mips/yeeloong/lsspd.c @@ -24,6 +24,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + static grub_err_t grub_cmd_lsspd (grub_command_t cmd __attribute__ ((unused)), int argc __attribute__ ((unused)), diff --git a/grub-core/commands/parttool.c b/grub-core/commands/parttool.c index 31e768553..a54286161 100644 --- a/grub-core/commands/parttool.c +++ b/grub-core/commands/parttool.c @@ -31,6 +31,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv2+"); + static struct grub_parttool *parts = 0; static int curhandle = 0; static grub_dl_t mymod; diff --git a/grub-core/commands/password.c b/grub-core/commands/password.c index db5951cbb..8821607b8 100644 --- a/grub-core/commands/password.c +++ b/grub-core/commands/password.c @@ -26,6 +26,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + static grub_dl_t my_mod; static grub_err_t diff --git a/grub-core/commands/password_pbkdf2.c b/grub-core/commands/password_pbkdf2.c index 6886987da..05a627219 100644 --- a/grub-core/commands/password_pbkdf2.c +++ b/grub-core/commands/password_pbkdf2.c @@ -26,6 +26,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + static grub_dl_t my_mod; struct pbkdf2_password diff --git a/grub-core/commands/probe.c b/grub-core/commands/probe.c index 3ace596d8..c5f946340 100644 --- a/grub-core/commands/probe.c +++ b/grub-core/commands/probe.c @@ -32,6 +32,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + static const struct grub_arg_option options[] = { {"set", 's', 0, diff --git a/grub-core/commands/read.c b/grub-core/commands/read.c index 6a187fc3e..fe3e88b15 100644 --- a/grub-core/commands/read.c +++ b/grub-core/commands/read.c @@ -26,6 +26,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + static char * grub_getline (void) { diff --git a/grub-core/commands/reboot.c b/grub-core/commands/reboot.c index eedd53c91..8e18083c0 100644 --- a/grub-core/commands/reboot.c +++ b/grub-core/commands/reboot.c @@ -22,6 +22,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + static grub_err_t grub_cmd_reboot (grub_command_t cmd __attribute__ ((unused)), int argc __attribute__ ((unused)), diff --git a/grub-core/commands/regexp.c b/grub-core/commands/regexp.c index 83c0d8d43..1e8a6f309 100644 --- a/grub-core/commands/regexp.c +++ b/grub-core/commands/regexp.c @@ -27,6 +27,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + static const struct grub_arg_option options[] = { { "set", 's', GRUB_ARG_OPTION_REPEATABLE, diff --git a/grub-core/commands/search.c b/grub-core/commands/search.c index f265f86d6..ba80d80ef 100644 --- a/grub-core/commands/search.c +++ b/grub-core/commands/search.c @@ -31,6 +31,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + void FUNC_NAME (const char *key, const char *var, int no_floppy, char **hints, unsigned nhints) diff --git a/grub-core/commands/search_wrap.c b/grub-core/commands/search_wrap.c index 80741d7ab..7b0a99565 100644 --- a/grub-core/commands/search_wrap.c +++ b/grub-core/commands/search_wrap.c @@ -27,6 +27,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + static const struct grub_arg_option options[] = { {"file", 'f', 0, N_("Search devices by a file."), 0, 0}, diff --git a/grub-core/commands/setpci.c b/grub-core/commands/setpci.c index 88dfa4c08..70f5bcdad 100644 --- a/grub-core/commands/setpci.c +++ b/grub-core/commands/setpci.c @@ -25,6 +25,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + struct pci_register { const char *name; diff --git a/grub-core/commands/sleep.c b/grub-core/commands/sleep.c index da642fcd9..97e7a40a6 100644 --- a/grub-core/commands/sleep.c +++ b/grub-core/commands/sleep.c @@ -25,6 +25,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + static const struct grub_arg_option options[] = { {"verbose", 'v', 0, N_("Verbose countdown."), 0, 0}, diff --git a/grub-core/commands/terminal.c b/grub-core/commands/terminal.c index c2d9550f6..0adfd3d2e 100644 --- a/grub-core/commands/terminal.c +++ b/grub-core/commands/terminal.c @@ -23,6 +23,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + struct grub_term_autoload *grub_term_input_autoload = NULL; struct grub_term_autoload *grub_term_output_autoload = NULL; diff --git a/grub-core/commands/test.c b/grub-core/commands/test.c index e981c945a..50d5aba5e 100644 --- a/grub-core/commands/test.c +++ b/grub-core/commands/test.c @@ -27,6 +27,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + /* A simple implementation for signed numbers. */ static int grub_strtosl (char *arg, char **end, int base) diff --git a/grub-core/commands/testload.c b/grub-core/commands/testload.c index 86b8a9253..fe06f3d1e 100644 --- a/grub-core/commands/testload.c +++ b/grub-core/commands/testload.c @@ -29,6 +29,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + static grub_err_t grub_cmd_testload (struct grub_command *cmd __attribute__ ((unused)), int argc, char *argv[]) diff --git a/grub-core/commands/true.c b/grub-core/commands/true.c index aa8125853..82775e7ef 100644 --- a/grub-core/commands/true.c +++ b/grub-core/commands/true.c @@ -21,6 +21,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + static grub_err_t grub_cmd_true (struct grub_command *cmd __attribute__ ((unused)), int argc __attribute__ ((unused)), diff --git a/grub-core/commands/usbtest.c b/grub-core/commands/usbtest.c index 7f00c8856..4a051ad1f 100644 --- a/grub-core/commands/usbtest.c +++ b/grub-core/commands/usbtest.c @@ -27,6 +27,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + static const char *usb_classes[] = { "Unknown", diff --git a/grub-core/commands/videoinfo.c b/grub-core/commands/videoinfo.c index 10f77915b..3e0c1a12e 100644 --- a/grub-core/commands/videoinfo.c +++ b/grub-core/commands/videoinfo.c @@ -25,6 +25,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + static unsigned height, width, depth; static int diff --git a/grub-core/commands/videotest.c b/grub-core/commands/videotest.c index 435ac2937..dc7a6485f 100644 --- a/grub-core/commands/videotest.c +++ b/grub-core/commands/videotest.c @@ -28,6 +28,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + static grub_err_t grub_cmd_videotest (grub_command_t cmd __attribute__ ((unused)), int argc, char **args) diff --git a/grub-core/commands/xnu_uuid.c b/grub-core/commands/xnu_uuid.c index 382d3196b..f618b4ec0 100644 --- a/grub-core/commands/xnu_uuid.c +++ b/grub-core/commands/xnu_uuid.c @@ -34,6 +34,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + /* This prefix is used by xnu and boot-132 to hash together with volume serial. */ static grub_uint8_t hash_prefix[16] diff --git a/grub-core/disk/ata.c b/grub-core/disk/ata.c index fe677e2a0..7f261560d 100644 --- a/grub-core/disk/ata.c +++ b/grub-core/disk/ata.c @@ -26,6 +26,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + /* At the moment, only two IDE ports are supported. */ static const grub_port_t grub_ata_ioaddress[] = { GRUB_ATA_CH0_PORT1, GRUB_ATA_CH1_PORT1 }; diff --git a/grub-core/disk/ata_pthru.c b/grub-core/disk/ata_pthru.c index f52725a49..eb9cb5f85 100644 --- a/grub-core/disk/ata_pthru.c +++ b/grub-core/disk/ata_pthru.c @@ -22,6 +22,7 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); /* ATA pass through support, used by hdparm.mod. */ static grub_err_t diff --git a/grub-core/disk/dmraid_nvidia.c b/grub-core/disk/dmraid_nvidia.c index d3f45935c..154193eb0 100644 --- a/grub-core/disk/dmraid_nvidia.c +++ b/grub-core/disk/dmraid_nvidia.c @@ -24,6 +24,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + #define NV_SIGNATURES 4 #define NV_IDLE 0 diff --git a/grub-core/disk/i386/pc/biosdisk.c b/grub-core/disk/i386/pc/biosdisk.c index 069bb0b59..1d47dc727 100644 --- a/grub-core/disk/i386/pc/biosdisk.c +++ b/grub-core/disk/i386/pc/biosdisk.c @@ -28,6 +28,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + static int cd_drive = 0; static int grub_biosdisk_rw_int13_extensions (int ah, int drive, void *dap); diff --git a/grub-core/disk/ieee1275/nand.c b/grub-core/disk/ieee1275/nand.c index a2c717cdb..e9450167e 100644 --- a/grub-core/disk/ieee1275/nand.c +++ b/grub-core/disk/ieee1275/nand.c @@ -23,6 +23,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + struct grub_nand_data { grub_ieee1275_ihandle_t handle; diff --git a/grub-core/disk/loopback.c b/grub-core/disk/loopback.c index 939043f01..d50f353b1 100644 --- a/grub-core/disk/loopback.c +++ b/grub-core/disk/loopback.c @@ -25,6 +25,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + struct grub_loopback { char *devname; diff --git a/grub-core/disk/lvm.c b/grub-core/disk/lvm.c index 00c6d8f9b..206e3e220 100644 --- a/grub-core/disk/lvm.c +++ b/grub-core/disk/lvm.c @@ -28,6 +28,8 @@ #include #endif +GRUB_MOD_LICENSE ("GPLv3+"); + static struct grub_lvm_vg *vg_list; static int lv_count; diff --git a/grub-core/disk/mdraid1x_linux.c b/grub-core/disk/mdraid1x_linux.c index e30878365..19c43f455 100644 --- a/grub-core/disk/mdraid1x_linux.c +++ b/grub-core/disk/mdraid1x_linux.c @@ -24,6 +24,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + /* Linux RAID on disk structures and constants, copied from include/linux/raid/md_p.h. */ diff --git a/grub-core/disk/mdraid_linux.c b/grub-core/disk/mdraid_linux.c index 06d3498a8..691d100b8 100644 --- a/grub-core/disk/mdraid_linux.c +++ b/grub-core/disk/mdraid_linux.c @@ -27,6 +27,8 @@ /* Linux RAID on disk structures and constants, copied from include/linux/raid/md_p.h. */ +GRUB_MOD_LICENSE ("GPLv3+"); + #define RESERVED_BYTES (64 * 1024) #define RESERVED_SECTORS (RESERVED_BYTES / 512) diff --git a/grub-core/disk/memdisk.c b/grub-core/disk/memdisk.c index e00280dd7..114ac0d9e 100644 --- a/grub-core/disk/memdisk.c +++ b/grub-core/disk/memdisk.c @@ -24,6 +24,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + static char *memdisk_addr; static grub_off_t memdisk_size = 0; diff --git a/grub-core/disk/raid.c b/grub-core/disk/raid.c index ac2b9fefe..3c74bba99 100644 --- a/grub-core/disk/raid.c +++ b/grub-core/disk/raid.c @@ -27,6 +27,8 @@ #include #endif +GRUB_MOD_LICENSE ("GPLv3+"); + /* Linked list of RAID arrays. */ static struct grub_raid_array *array_list; grub_raid5_recover_func_t grub_raid5_recover_func; diff --git a/grub-core/disk/raid5_recover.c b/grub-core/disk/raid5_recover.c index 349eb0291..c26d05e94 100644 --- a/grub-core/disk/raid5_recover.c +++ b/grub-core/disk/raid5_recover.c @@ -24,6 +24,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + static grub_err_t grub_raid5_recover (struct grub_raid_array *array, int disknr, char *buf, grub_disk_addr_t sector, int size) diff --git a/grub-core/disk/raid6_recover.c b/grub-core/disk/raid6_recover.c index dfaa60ea4..25b50eb6b 100644 --- a/grub-core/disk/raid6_recover.c +++ b/grub-core/disk/raid6_recover.c @@ -24,6 +24,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + static grub_uint8_t raid6_table1[256][256]; static grub_uint8_t raid6_table2[256][256]; diff --git a/grub-core/disk/scsi.c b/grub-core/disk/scsi.c index a40de278f..25f0e3aea 100644 --- a/grub-core/disk/scsi.c +++ b/grub-core/disk/scsi.c @@ -27,6 +27,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + static grub_scsi_dev_t grub_scsi_dev_list; diff --git a/grub-core/disk/usbms.c b/grub-core/disk/usbms.c index fcfe9e5d4..2f1dbd487 100644 --- a/grub-core/disk/usbms.c +++ b/grub-core/disk/usbms.c @@ -24,6 +24,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + #define GRUB_USBMS_DIRECTION_BIT 7 /* The USB Mass Storage Command Block Wrapper. */ diff --git a/grub-core/efiemu/main.c b/grub-core/efiemu/main.c index da813b00d..772db2956 100644 --- a/grub-core/efiemu/main.c +++ b/grub-core/efiemu/main.c @@ -32,6 +32,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + /* System table. Two version depending on mode */ grub_efi_system_table32_t *grub_efiemu_system_table32 = 0; grub_efi_system_table64_t *grub_efiemu_system_table64 = 0; diff --git a/grub-core/font/font.c b/grub-core/font/font.c index b5ec43bb2..ef6caf77b 100644 --- a/grub-core/font/font.c +++ b/grub-core/font/font.c @@ -30,6 +30,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + #ifdef USE_ASCII_FAILBACK #include "ascii.h" #endif diff --git a/grub-core/fs/affs.c b/grub-core/fs/affs.c index 40be4b2f6..1c4f80ec0 100644 --- a/grub-core/fs/affs.c +++ b/grub-core/fs/affs.c @@ -26,6 +26,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + /* The affs bootblock. */ struct grub_affs_bblock { diff --git a/grub-core/fs/afs.c b/grub-core/fs/afs.c index cd61f4db9..35ef49937 100644 --- a/grub-core/fs/afs.c +++ b/grub-core/fs/afs.c @@ -26,6 +26,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + #ifdef MODE_BIGENDIAN #define GRUB_AFS_FSNAME_SUFFIX "_be" #else diff --git a/grub-core/fs/btrfs.c b/grub-core/fs/btrfs.c index 11b8dba33..3e73837d9 100644 --- a/grub-core/fs/btrfs.c +++ b/grub-core/fs/btrfs.c @@ -25,6 +25,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + #define BTRFS_SIGNATURE "_BHRfS_M" struct btrfs_superblock diff --git a/grub-core/fs/cpio.c b/grub-core/fs/cpio.c index 2c92404c3..a7ccfbded 100644 --- a/grub-core/fs/cpio.c +++ b/grub-core/fs/cpio.c @@ -23,6 +23,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + #ifndef MODE_USTAR /* cpio support */ #define MAGIC_BCPIO 070707 diff --git a/grub-core/fs/ext2.c b/grub-core/fs/ext2.c index 9d7bbfd36..0fdf151a2 100644 --- a/grub-core/fs/ext2.c +++ b/grub-core/fs/ext2.c @@ -51,6 +51,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + /* Log2 size of ext2 block in 512 blocks. */ #define LOG2_EXT2_BLOCK_SIZE(data) \ (grub_le_to_cpu32 (data->sblock.log2_block_size) + 1) diff --git a/grub-core/fs/fat.c b/grub-core/fs/fat.c index 89050943c..76b9c52d7 100644 --- a/grub-core/fs/fat.c +++ b/grub-core/fs/fat.c @@ -27,6 +27,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + #define GRUB_FAT_DIR_ENTRY_SIZE 32 #define GRUB_FAT_ATTR_READ_ONLY 0x01 diff --git a/grub-core/fs/fshelp.c b/grub-core/fs/fshelp.c index d0b1e493e..f879885ac 100644 --- a/grub-core/fs/fshelp.c +++ b/grub-core/fs/fshelp.c @@ -22,7 +22,9 @@ #include #include #include +#include +GRUB_MOD_LICENSE ("GPLv3+"); /* Lookup the node PATH. The node ROOTNODE describes the root of the directory tree. The node found is returned in FOUNDNODE, which is diff --git a/grub-core/fs/hfs.c b/grub-core/fs/hfs.c index cef856326..1f67ea155 100644 --- a/grub-core/fs/hfs.c +++ b/grub-core/fs/hfs.c @@ -29,6 +29,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + #define GRUB_HFS_SBLOCK 2 #define GRUB_HFS_EMBED_HFSPLUS_SIG 0x482B diff --git a/grub-core/fs/hfsplus.c b/grub-core/fs/hfsplus.c index 7d7115ce3..304b32126 100644 --- a/grub-core/fs/hfsplus.c +++ b/grub-core/fs/hfsplus.c @@ -30,6 +30,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + #define GRUB_HFSPLUS_MAGIC 0x482B #define GRUB_HFSPLUSX_MAGIC 0x4858 #define GRUB_HFSPLUS_SBLOCK 2 diff --git a/grub-core/fs/i386/pc/pxe.c b/grub-core/fs/i386/pc/pxe.c index c800ea2ad..d6dc2c22d 100644 --- a/grub-core/fs/i386/pc/pxe.c +++ b/grub-core/fs/i386/pc/pxe.c @@ -30,6 +30,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + #define SEGMENT(x) ((x) >> 4) #define OFFSET(x) ((x) & 0xF) #define SEGOFS(x) ((SEGMENT(x) << 16) + OFFSET(x)) diff --git a/grub-core/fs/iso9660.c b/grub-core/fs/iso9660.c index f72249d20..a9a17fef8 100644 --- a/grub-core/fs/iso9660.c +++ b/grub-core/fs/iso9660.c @@ -28,6 +28,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + #define GRUB_ISO9660_FSTYPE_DIR 0040000 #define GRUB_ISO9660_FSTYPE_REG 0100000 #define GRUB_ISO9660_FSTYPE_SYMLINK 0120000 diff --git a/grub-core/fs/jfs.c b/grub-core/fs/jfs.c index 6857c4a2c..72e6adc74 100644 --- a/grub-core/fs/jfs.c +++ b/grub-core/fs/jfs.c @@ -26,6 +26,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + #define GRUB_JFS_MAX_SYMLNK_CNT 8 #define GRUB_JFS_FILETYPE_MASK 0170000 #define GRUB_JFS_FILETYPE_REG 0100000 diff --git a/grub-core/fs/minix.c b/grub-core/fs/minix.c index 679e1ec51..523e6e616 100644 --- a/grub-core/fs/minix.c +++ b/grub-core/fs/minix.c @@ -25,6 +25,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + #ifdef MODE_MINIX2 #define GRUB_MINIX_MAGIC 0x2468 #define GRUB_MINIX_MAGIC_30 0x2478 diff --git a/grub-core/fs/nilfs2.c b/grub-core/fs/nilfs2.c index e529775f4..4c8d7633c 100644 --- a/grub-core/fs/nilfs2.c +++ b/grub-core/fs/nilfs2.c @@ -35,6 +35,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + #define NILFS_INODE_BMAP_SIZE 7 #define NILFS_SUPORT_REV 2 diff --git a/grub-core/fs/ntfs.c b/grub-core/fs/ntfs.c index 414f6513d..e01ce34c2 100644 --- a/grub-core/fs/ntfs.c +++ b/grub-core/fs/ntfs.c @@ -26,6 +26,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + static grub_dl_t my_mod; ntfscomp_func_t grub_ntfscomp_func; diff --git a/grub-core/fs/ntfscomp.c b/grub-core/fs/ntfscomp.c index c29979edc..d2893cb99 100644 --- a/grub-core/fs/ntfscomp.c +++ b/grub-core/fs/ntfscomp.c @@ -24,6 +24,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + static grub_err_t decomp_nextvcn (struct grub_ntfs_comp *cc) { diff --git a/grub-core/fs/reiserfs.c b/grub-core/fs/reiserfs.c index e92279554..f2984f845 100644 --- a/grub-core/fs/reiserfs.c +++ b/grub-core/fs/reiserfs.c @@ -39,6 +39,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + #define MIN(a, b) \ ({ typeof (a) _a = (a); \ typeof (b) _b = (b); \ diff --git a/grub-core/fs/sfs.c b/grub-core/fs/sfs.c index b49420de1..455743117 100644 --- a/grub-core/fs/sfs.c +++ b/grub-core/fs/sfs.c @@ -26,6 +26,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + /* The common header for a block. */ struct grub_sfs_bheader { diff --git a/grub-core/fs/udf.c b/grub-core/fs/udf.c index 1672aab1b..5842d5d12 100644 --- a/grub-core/fs/udf.c +++ b/grub-core/fs/udf.c @@ -27,6 +27,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + #define GRUB_UDF_MAX_PDS 2 #define GRUB_UDF_MAX_PMS 6 diff --git a/grub-core/fs/ufs.c b/grub-core/fs/ufs.c index 2b1021db6..86fe8af65 100644 --- a/grub-core/fs/ufs.c +++ b/grub-core/fs/ufs.c @@ -25,6 +25,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + #ifdef MODE_UFS2 #define GRUB_UFS_MAGIC 0x19540119 #else diff --git a/grub-core/fs/xfs.c b/grub-core/fs/xfs.c index 9f8dc28de..2eadc3768 100644 --- a/grub-core/fs/xfs.c +++ b/grub-core/fs/xfs.c @@ -26,6 +26,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + #define XFS_INODE_EXTENTS 9 #define XFS_INODE_FORMAT_INO 1 diff --git a/grub-core/fs/zfs/zfs.c b/grub-core/fs/zfs/zfs.c index 8e83ea0b5..8d86cf9e5 100644 --- a/grub-core/fs/zfs/zfs.c +++ b/grub-core/fs/zfs/zfs.c @@ -52,6 +52,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + #define ZPOOL_PROP_BOOTFS "bootfs" #define MIN(a,b) (((a) < (b)) ? (a) : (b)) diff --git a/grub-core/fs/zfs/zfsinfo.c b/grub-core/fs/zfs/zfsinfo.c index 224a97792..1968ed554 100644 --- a/grub-core/fs/zfs/zfsinfo.c +++ b/grub-core/fs/zfs/zfsinfo.c @@ -26,6 +26,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + static inline void print_tabs (int n) { diff --git a/grub-core/gentrigtables.c b/grub-core/gentrigtables.c index bef2b083c..8c039570d 100644 --- a/grub-core/gentrigtables.c +++ b/grub-core/gentrigtables.c @@ -30,6 +30,14 @@ main (int argc __attribute__ ((unused)), int i; printf ("#include \n"); + printf ("#include \n"); + printf ("\n"); + + printf ("/* Under copyright legislature such automated output isn't\n"); + printf ("covered by any copyright. Hence it's public domain. Public\n"); + printf ("domain works can be dual-licenced with any license. */\n"); + printf ("GRUB_MOD_LICENSE (\"GPLv3+\");"); + printf ("GRUB_MOD_DUAL_LICENSE (\"Public Domain\");"); #define TAB(op) \ printf ("grub_int16_t grub_trig_" #op "tab[] =\n{"); \ diff --git a/grub-core/gettext/gettext.c b/grub-core/gettext/gettext.c index 84937f19b..cca8b901f 100644 --- a/grub-core/gettext/gettext.c +++ b/grub-core/gettext/gettext.c @@ -28,6 +28,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + /* .mo file information from: http://www.gnu.org/software/autoconf/manual/gettext/MO-Files.html . diff --git a/grub-core/gfxmenu/gfxmenu.c b/grub-core/gfxmenu/gfxmenu.c index 564a87634..2f210e02b 100644 --- a/grub-core/gfxmenu/gfxmenu.c +++ b/grub-core/gfxmenu/gfxmenu.c @@ -37,6 +37,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + static grub_gfxmenu_view_t cached_view; static void diff --git a/grub-core/gnulib/regex.c b/grub-core/gnulib/regex.c index ba0eebee7..4c2243f64 100644 --- a/grub-core/gnulib/regex.c +++ b/grub-core/gnulib/regex.c @@ -19,6 +19,9 @@ Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include +#include + +GRUB_MOD_LICENSE ("GPLv3+"); /* Make sure noone compiles this code with a C++ compiler. */ #if defined __cplusplus && defined _LIBC diff --git a/grub-core/hello/hello.c b/grub-core/hello/hello.c index 77c4c96b1..2c9e90f72 100644 --- a/grub-core/hello/hello.c +++ b/grub-core/hello/hello.c @@ -26,6 +26,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + static grub_err_t grub_cmd_hello (grub_extcmd_context_t ctxt __attribute__ ((unused)), int argc __attribute__ ((unused)), diff --git a/grub-core/hook/datehook.c b/grub-core/hook/datehook.c index d855311d3..f64fac074 100644 --- a/grub-core/hook/datehook.c +++ b/grub-core/hook/datehook.c @@ -24,6 +24,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + static char *grub_datetime_names[] = { "YEAR", diff --git a/grub-core/io/bufio.c b/grub-core/io/bufio.c index 891fb78e9..3b456c1d2 100644 --- a/grub-core/io/bufio.c +++ b/grub-core/io/bufio.c @@ -23,6 +23,9 @@ #include #include #include +#include + +GRUB_MOD_LICENSE ("GPLv3+"); #define GRUB_BUFIO_DEF_SIZE 8192 #define GRUB_BUFIO_MAX_SIZE 1048576 diff --git a/grub-core/io/gzio.c b/grub-core/io/gzio.c index 47df23833..ad185dcab 100644 --- a/grub-core/io/gzio.c +++ b/grub-core/io/gzio.c @@ -42,6 +42,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + /* * Window Size * diff --git a/grub-core/io/xzio.c b/grub-core/io/xzio.c index 3daf6a3fe..1f42cd242 100644 --- a/grub-core/io/xzio.c +++ b/grub-core/io/xzio.c @@ -24,6 +24,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + #include "xz.h" #include "xz_stream.h" diff --git a/grub-core/kern/dl.c b/grub-core/kern/dl.c index 02d785b9b..c5e2888cd 100644 --- a/grub-core/kern/dl.c +++ b/grub-core/kern/dl.c @@ -373,6 +373,38 @@ grub_dl_call_init (grub_dl_t mod) (mod->init) (mod); } +/* Me, Vladimir Serbinenko, hereby I add this module check as per new + GNU module policy. Note that this license check is informative only. + Modules have to be licensed under GPLv3 or GPLv3+ (optionally + multi-licensed under other licences as well) independently of the + presence of this check and solely by linking (module loading in GRUB + constitutes linking) and GRUB core being licensed under GPLv3+. + Be sure to understand your license obligations. +*/ +static grub_err_t +grub_dl_check_license (Elf_Ehdr *e) +{ + Elf_Shdr *s; + const char *str; + unsigned i; + + s = (Elf_Shdr *) ((char *) e + e->e_shoff + e->e_shstrndx * e->e_shentsize); + str = (char *) e + s->sh_offset; + + for (i = 0, s = (Elf_Shdr *) ((char *) e + e->e_shoff); + i < e->e_shnum; + i++, s = (Elf_Shdr *) ((char *) s + e->e_shentsize)) + if (grub_strcmp (str + s->sh_name, ".module_license") == 0) + { + if (grub_strcmp ((char *) e + s->sh_offset, "LICENSE=GPLv3") == 0 + || grub_strcmp ((char *) e + s->sh_offset, "LICENSE=GPLv3+") == 0 + || grub_strcmp ((char *) e + s->sh_offset, "LICENSE=GPLv2+") == 0) + return GRUB_ERR_NONE; + } + + return grub_error (GRUB_ERR_BAD_MODULE, "incompatible license"); +} + static grub_err_t grub_dl_resolve_name (grub_dl_t mod, Elf_Ehdr *e) { @@ -519,7 +551,16 @@ grub_dl_load_core (void *addr, grub_size_t size) mod->ref_count = 1; grub_dprintf ("modules", "relocating to %p\n", mod); - if (grub_dl_resolve_name (mod, e) + /* Me, Vladimir Serbinenko, hereby I add this module check as per new + GNU module policy. Note that this license check is informative only. + Modules have to be licensed under GPLv3 or GPLv3+ (optionally + multi-licensed under other licences as well) independently of the + presence of this check and solely by linking (module loading in GRUB + constitutes linking) and GRUB core being licensed under GPLv3+. + Be sure to understand your license obligations. + */ + if (grub_dl_check_license (e) + || grub_dl_resolve_name (mod, e) || grub_dl_resolve_dependencies (mod, e) || grub_dl_load_segments (mod, e) || grub_dl_resolve_symbols (mod, e) diff --git a/grub-core/kern/elf.c b/grub-core/kern/elf.c index 56218b4e4..9c7b8cec2 100644 --- a/grub-core/kern/elf.c +++ b/grub-core/kern/elf.c @@ -23,6 +23,9 @@ #include #include #include +#include + +GRUB_MOD_LICENSE ("GPLv3+"); /* Check if EHDR is a valid ELF header. */ static grub_err_t diff --git a/grub-core/lib/cmos_datetime.c b/grub-core/lib/cmos_datetime.c index 8db60b48c..73c5a03c0 100644 --- a/grub-core/lib/cmos_datetime.c +++ b/grub-core/lib/cmos_datetime.c @@ -19,6 +19,9 @@ #include #include +#include + +GRUB_MOD_LICENSE ("GPLv3+"); grub_err_t grub_get_datetime (struct grub_datetime *datetime) diff --git a/grub-core/lib/crypto.c b/grub-core/lib/crypto.c index f5768b8b5..ad1bfc4d3 100644 --- a/grub-core/lib/crypto.c +++ b/grub-core/lib/crypto.c @@ -21,6 +21,9 @@ #include #include #include +#include + +GRUB_MOD_LICENSE ("GPLv3+"); struct grub_crypto_hmac_handle { diff --git a/grub-core/lib/pbkdf2.c b/grub-core/lib/pbkdf2.c index 083446ab9..09b8c7360 100644 --- a/grub-core/lib/pbkdf2.c +++ b/grub-core/lib/pbkdf2.c @@ -21,6 +21,9 @@ #include #include #include +#include + +GRUB_MOD_LICENSE ("GPLv2+"); /* Implement PKCS#5 PBKDF2 as per RFC 2898. The PRF to use is HMAC variant of digest supplied by MD. Inputs are the password P of length PLEN, diff --git a/grub-core/lib/relocator.c b/grub-core/lib/relocator.c index 3642de9dc..6eb20b865 100644 --- a/grub-core/lib/relocator.c +++ b/grub-core/lib/relocator.c @@ -22,6 +22,9 @@ #include #include #include +#include + +GRUB_MOD_LICENSE ("GPLv3+"); struct grub_relocator { diff --git a/grub-core/loader/aout.c b/grub-core/loader/aout.c index 611960f92..69bf6e6ad 100644 --- a/grub-core/loader/aout.c +++ b/grub-core/loader/aout.c @@ -21,6 +21,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + int grub_aout_get_type (union grub_aout_header *header) { diff --git a/grub-core/loader/efi/appleloader.c b/grub-core/loader/efi/appleloader.c index dc42683a6..847750dc0 100644 --- a/grub-core/loader/efi/appleloader.c +++ b/grub-core/loader/efi/appleloader.c @@ -27,6 +27,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + static grub_dl_t my_mod; static grub_efi_handle_t image_handle; diff --git a/grub-core/loader/efi/chainloader.c b/grub-core/loader/efi/chainloader.c index a095ad931..869b64ced 100644 --- a/grub-core/loader/efi/chainloader.c +++ b/grub-core/loader/efi/chainloader.c @@ -35,6 +35,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + static grub_dl_t my_mod; static grub_efi_physical_address_t address; diff --git a/grub-core/loader/i386/bsd.c b/grub-core/loader/i386/bsd.c index ecd5bd5cd..6487dc3df 100644 --- a/grub-core/loader/i386/bsd.c +++ b/grub-core/loader/i386/bsd.c @@ -34,6 +34,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + #include #ifdef GRUB_MACHINE_PCBIOS #include diff --git a/grub-core/loader/i386/linux.c b/grub-core/loader/i386/linux.c index 0178e2fd4..241eaa5e7 100644 --- a/grub-core/loader/i386/linux.c +++ b/grub-core/loader/i386/linux.c @@ -35,6 +35,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + #ifdef GRUB_MACHINE_PCBIOS #include #endif diff --git a/grub-core/loader/i386/pc/chainloader.c b/grub-core/loader/i386/pc/chainloader.c index fd99c81d5..794316b34 100644 --- a/grub-core/loader/i386/pc/chainloader.c +++ b/grub-core/loader/i386/pc/chainloader.c @@ -38,6 +38,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + static grub_dl_t my_mod; static int boot_drive; static void *boot_part_addr; diff --git a/grub-core/loader/i386/pc/linux.c b/grub-core/loader/i386/pc/linux.c index 96d00f927..c6e6b67d1 100644 --- a/grub-core/loader/i386/pc/linux.c +++ b/grub-core/loader/i386/pc/linux.c @@ -36,6 +36,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + #define GRUB_LINUX_CL_OFFSET 0x9000 #define GRUB_LINUX_CL_END_OFFSET 0x90FF diff --git a/grub-core/loader/i386/pc/ntldr.c b/grub-core/loader/i386/pc/ntldr.c index 0c33a0680..4a08b54f2 100644 --- a/grub-core/loader/i386/pc/ntldr.c +++ b/grub-core/loader/i386/pc/ntldr.c @@ -33,6 +33,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + static grub_dl_t my_mod; static struct grub_relocator *rel; static grub_uint32_t edx = 0xffffffff; diff --git a/grub-core/loader/mips/linux.c b/grub-core/loader/mips/linux.c index 9accfc270..0bf7b1f8e 100644 --- a/grub-core/loader/mips/linux.c +++ b/grub-core/loader/mips/linux.c @@ -28,6 +28,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + /* For frequencies. */ #include #include diff --git a/grub-core/loader/multiboot.c b/grub-core/loader/multiboot.c index 4bfc2c191..d9e74b3c7 100644 --- a/grub-core/loader/multiboot.c +++ b/grub-core/loader/multiboot.c @@ -43,6 +43,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + #ifdef GRUB_MACHINE_EFI #include #endif diff --git a/grub-core/loader/powerpc/ieee1275/linux.c b/grub-core/loader/powerpc/ieee1275/linux.c index 0cf0eb825..12a3fa9f6 100644 --- a/grub-core/loader/powerpc/ieee1275/linux.c +++ b/grub-core/loader/powerpc/ieee1275/linux.c @@ -29,6 +29,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + #define ELF32_LOADMASK (0xc0000000UL) #define ELF64_LOADMASK (0xc000000000000000ULL) diff --git a/grub-core/loader/sparc64/ieee1275/linux.c b/grub-core/loader/sparc64/ieee1275/linux.c index a262049a7..8ed61f8bf 100644 --- a/grub-core/loader/sparc64/ieee1275/linux.c +++ b/grub-core/loader/sparc64/ieee1275/linux.c @@ -29,6 +29,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + static grub_dl_t my_mod; static int loaded; diff --git a/grub-core/loader/xnu.c b/grub-core/loader/xnu.c index 73158fd10..a98d60c20 100644 --- a/grub-core/loader/xnu.c +++ b/grub-core/loader/xnu.c @@ -34,6 +34,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + #if defined (__i386) && !defined (GRUB_MACHINE_EFI) #include #endif diff --git a/grub-core/mmap/mmap.c b/grub-core/mmap/mmap.c index 1c1825490..07a71336b 100644 --- a/grub-core/mmap/mmap.c +++ b/grub-core/mmap/mmap.c @@ -26,6 +26,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + #ifndef GRUB_MMAP_REGISTER_BY_FIRMWARE struct grub_mmap_region *grub_mmap_overlays = 0; diff --git a/grub-core/normal/main.c b/grub-core/normal/main.c index cefb1cb9b..837fcb960 100644 --- a/grub-core/normal/main.c +++ b/grub-core/normal/main.c @@ -33,6 +33,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + #define GRUB_DEFAULT_HISTORY_SIZE 50 static int nested_level = 0; diff --git a/grub-core/partmap/acorn.c b/grub-core/partmap/acorn.c index 677ec61d5..9a68ddd92 100644 --- a/grub-core/partmap/acorn.c +++ b/grub-core/partmap/acorn.c @@ -23,6 +23,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + #define LINUX_NATIVE_MAGIC grub_cpu_to_le32 (0xdeafa1de) #define LINUX_SWAP_MAGIC grub_cpu_to_le32 (0xdeafab1e) #define LINUX_MAP_ENTRIES (512 / 12) diff --git a/grub-core/partmap/amiga.c b/grub-core/partmap/amiga.c index 1e0f23402..f3ba950aa 100644 --- a/grub-core/partmap/amiga.c +++ b/grub-core/partmap/amiga.c @@ -23,6 +23,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + struct grub_amiga_rdsk { /* "RDSK". */ diff --git a/grub-core/partmap/apple.c b/grub-core/partmap/apple.c index e162d18d7..c08cae589 100644 --- a/grub-core/partmap/apple.c +++ b/grub-core/partmap/apple.c @@ -22,6 +22,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + #define GRUB_APPLE_HEADER_MAGIC 0x4552 #define GRUB_APPLE_PART_MAGIC 0x504D diff --git a/grub-core/partmap/bsdlabel.c b/grub-core/partmap/bsdlabel.c index 4dec3851c..888100aa2 100644 --- a/grub-core/partmap/bsdlabel.c +++ b/grub-core/partmap/bsdlabel.c @@ -25,6 +25,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + #ifdef GRUB_UTIL #include #endif diff --git a/grub-core/partmap/gpt.c b/grub-core/partmap/gpt.c index 7f2c36143..73a1c3b19 100644 --- a/grub-core/partmap/gpt.c +++ b/grub-core/partmap/gpt.c @@ -25,6 +25,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + static grub_uint8_t grub_gpt_magic[8] = { 0x45, 0x46, 0x49, 0x20, 0x50, 0x41, 0x52, 0x54 diff --git a/grub-core/partmap/msdos.c b/grub-core/partmap/msdos.c index 31a0a0707..1b71c69ab 100644 --- a/grub-core/partmap/msdos.c +++ b/grub-core/partmap/msdos.c @@ -24,6 +24,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + static struct grub_partition_map grub_msdos_partition_map; diff --git a/grub-core/partmap/sun.c b/grub-core/partmap/sun.c index 7af95c939..c7ef681c4 100644 --- a/grub-core/partmap/sun.c +++ b/grub-core/partmap/sun.c @@ -26,6 +26,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + #define GRUB_PARTMAP_SUN_MAGIC 0xDABE #define GRUB_PARTMAP_SUN_MAX_PARTS 8 #define GRUB_PARTMAP_SUN_WHOLE_DISK_ID 0x05 diff --git a/grub-core/partmap/sunpc.c b/grub-core/partmap/sunpc.c index ea69c28b9..28dc4f5be 100644 --- a/grub-core/partmap/sunpc.c +++ b/grub-core/partmap/sunpc.c @@ -26,6 +26,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + #define GRUB_PARTMAP_SUN_PC_MAGIC 0xDABE #define GRUB_PARTMAP_SUN_PC_MAX_PARTS 16 #define GRUB_PARTMAP_SUN_PC_WHOLE_DISK_ID 0x05 diff --git a/grub-core/parttool/msdospart.c b/grub-core/parttool/msdospart.c index 006a87def..ecaca140a 100644 --- a/grub-core/parttool/msdospart.c +++ b/grub-core/parttool/msdospart.c @@ -28,6 +28,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv2+"); + static int activate_table_handle = -1; static int type_table_handle = -1; diff --git a/grub-core/term/at_keyboard.c b/grub-core/term/at_keyboard.c index 7ce287ecc..210ac21cc 100644 --- a/grub-core/term/at_keyboard.c +++ b/grub-core/term/at_keyboard.c @@ -26,6 +26,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + static short at_keyboard_status = 0; static int e0_received = 0; static int f0_received = 0; diff --git a/grub-core/term/gfxterm.c b/grub-core/term/gfxterm.c index 44d1a9be8..0ade65f27 100644 --- a/grub-core/term/gfxterm.c +++ b/grub-core/term/gfxterm.c @@ -31,6 +31,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + #define DEFAULT_VIDEO_MODE "auto" #define DEFAULT_BORDER_WIDTH 10 diff --git a/grub-core/term/i386/pc/vga_text.c b/grub-core/term/i386/pc/vga_text.c index fbb65ae0c..1816bfae2 100644 --- a/grub-core/term/i386/pc/vga_text.c +++ b/grub-core/term/i386/pc/vga_text.c @@ -22,6 +22,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + #define COLS 80 #define ROWS 25 diff --git a/grub-core/term/serial.c b/grub-core/term/serial.c index 32628dbae..073c27aed 100644 --- a/grub-core/term/serial.c +++ b/grub-core/term/serial.c @@ -27,6 +27,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + #define FOR_SERIAL_PORTS(var) FOR_LIST_ELEMENTS((var), (grub_serial_ports)) /* Argument options. */ diff --git a/grub-core/term/terminfo.c b/grub-core/term/terminfo.c index 0a8c75c74..16158139d 100644 --- a/grub-core/term/terminfo.c +++ b/grub-core/term/terminfo.c @@ -34,6 +34,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + static struct grub_term_output *terminfo_outputs; /* Get current terminfo name. */ diff --git a/grub-core/term/usb_keyboard.c b/grub-core/term/usb_keyboard.c index 23c0c10ca..ae00936b8 100644 --- a/grub-core/term/usb_keyboard.c +++ b/grub-core/term/usb_keyboard.c @@ -27,6 +27,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + enum diff --git a/grub-core/tests/example_functional_test.c b/grub-core/tests/example_functional_test.c index 525988145..802088791 100644 --- a/grub-core/tests/example_functional_test.c +++ b/grub-core/tests/example_functional_test.c @@ -18,6 +18,9 @@ /* All tests need to include test.h for GRUB testing framework. */ #include +#include + +GRUB_MOD_LICENSE ("GPLv3+"); /* Functional test main method. */ static void diff --git a/grub-core/tests/lib/functional_test.c b/grub-core/tests/lib/functional_test.c index 521f4ad22..fd199bd63 100644 --- a/grub-core/tests/lib/functional_test.c +++ b/grub-core/tests/lib/functional_test.c @@ -20,6 +20,9 @@ #include #include #include +#include + +GRUB_MOD_LICENSE ("GPLv3+"); static grub_err_t grub_functional_test (grub_extcmd_context_t ctxt __attribute__ ((unused)), diff --git a/grub-core/tests/test_blockarg.c b/grub-core/tests/test_blockarg.c index 41460fb7e..ddd46e1f6 100644 --- a/grub-core/tests/test_blockarg.c +++ b/grub-core/tests/test_blockarg.c @@ -24,6 +24,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + static grub_err_t test_blockarg (grub_extcmd_context_t ctxt, int argc, char **args) { diff --git a/grub-core/video/bitmap.c b/grub-core/video/bitmap.c index 659ab9a57..32e9358a3 100644 --- a/grub-core/video/bitmap.c +++ b/grub-core/video/bitmap.c @@ -23,6 +23,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + /* List of bitmap readers registered to system. */ static grub_video_bitmap_reader_t bitmap_readers_list; diff --git a/grub-core/video/bitmap_scale.c b/grub-core/video/bitmap_scale.c index 6f8ff247e..8da5697f8 100644 --- a/grub-core/video/bitmap_scale.c +++ b/grub-core/video/bitmap_scale.c @@ -23,6 +23,9 @@ #include #include #include +#include + +GRUB_MOD_LICENSE ("GPLv3+"); /* Prototypes for module-local functions. */ static grub_err_t scale_nn (struct grub_video_bitmap *dst, diff --git a/grub-core/video/bochs.c b/grub-core/video/bochs.c index 832cd9903..79cae6547 100644 --- a/grub-core/video/bochs.c +++ b/grub-core/video/bochs.c @@ -28,6 +28,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + static struct { struct grub_video_mode_info mode_info; diff --git a/grub-core/video/cirrus.c b/grub-core/video/cirrus.c index a964c85cd..7fad50e5b 100644 --- a/grub-core/video/cirrus.c +++ b/grub-core/video/cirrus.c @@ -28,6 +28,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + static struct { struct grub_video_mode_info mode_info; diff --git a/grub-core/video/efi_gop.c b/grub-core/video/efi_gop.c index f02dc9cb6..d14ae98d2 100644 --- a/grub-core/video/efi_gop.c +++ b/grub-core/video/efi_gop.c @@ -29,6 +29,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + static grub_efi_guid_t graphics_output_guid = GRUB_EFI_GOP_GUID; static struct grub_efi_gop *gop; static unsigned old_mode; diff --git a/grub-core/video/efi_uga.c b/grub-core/video/efi_uga.c index a8f70edea..1e709a52d 100644 --- a/grub-core/video/efi_uga.c +++ b/grub-core/video/efi_uga.c @@ -30,6 +30,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + static grub_efi_guid_t uga_draw_guid = GRUB_EFI_UGA_DRAW_GUID; static struct grub_efi_uga_draw_protocol *uga; static grub_uint32_t uga_fb; diff --git a/grub-core/video/emu/sdl.c b/grub-core/video/emu/sdl.c index d66b8b0c0..f4c1a6ab6 100644 --- a/grub-core/video/emu/sdl.c +++ b/grub-core/video/emu/sdl.c @@ -27,6 +27,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + static SDL_Surface *window = 0; static struct grub_video_render_target *sdl_render_target; static struct grub_video_mode_info mode_info; diff --git a/grub-core/video/fb/video_fb.c b/grub-core/video/fb/video_fb.c index 2226d6583..2cffcb3d9 100644 --- a/grub-core/video/fb/video_fb.c +++ b/grub-core/video/fb/video_fb.c @@ -24,6 +24,9 @@ #include #include #include +#include + +GRUB_MOD_LICENSE ("GPLv3+"); static struct { diff --git a/grub-core/video/i386/pc/vbe.c b/grub-core/video/i386/pc/vbe.c index 08bf124b6..a109bcf43 100644 --- a/grub-core/video/i386/pc/vbe.c +++ b/grub-core/video/i386/pc/vbe.c @@ -30,6 +30,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + static int vbe_detected = -1; static struct grub_vbe_info_block controller_info; diff --git a/grub-core/video/i386/pc/vga.c b/grub-core/video/i386/pc/vga.c index 19770ce0a..fe387a26b 100644 --- a/grub-core/video/i386/pc/vga.c +++ b/grub-core/video/i386/pc/vga.c @@ -30,6 +30,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + #define VGA_WIDTH 640 #define VGA_HEIGHT 350 #define VGA_MEM ((grub_uint8_t *) GRUB_MEMORY_MACHINE_VGA_ADDR) diff --git a/grub-core/video/ieee1275.c b/grub-core/video/ieee1275.c index 501ba7c2f..913ea8376 100644 --- a/grub-core/video/ieee1275.c +++ b/grub-core/video/ieee1275.c @@ -27,6 +27,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + /* Only 8-bit indexed color is supported for now. */ static unsigned old_width, old_height; diff --git a/grub-core/video/readers/jpeg.c b/grub-core/video/readers/jpeg.c index 9d88163bd..8cdb2f61d 100644 --- a/grub-core/video/readers/jpeg.c +++ b/grub-core/video/readers/jpeg.c @@ -24,6 +24,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + /* Uncomment following define to enable JPEG debug. */ //#define JPEG_DEBUG diff --git a/grub-core/video/readers/png.c b/grub-core/video/readers/png.c index 2cec49e2f..5728651e0 100644 --- a/grub-core/video/readers/png.c +++ b/grub-core/video/readers/png.c @@ -24,6 +24,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + /* Uncomment following define to enable PNG debug. */ //#define PNG_DEBUG diff --git a/grub-core/video/readers/tga.c b/grub-core/video/readers/tga.c index 6c9e9d691..84be68a0a 100644 --- a/grub-core/video/readers/tga.c +++ b/grub-core/video/readers/tga.c @@ -24,6 +24,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + /* Uncomment following define to enable TGA debug. */ //#define TGA_DEBUG diff --git a/grub-core/video/video.c b/grub-core/video/video.c index 7a1a446e4..6a1d47304 100644 --- a/grub-core/video/video.c +++ b/grub-core/video/video.c @@ -22,6 +22,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + /* The list of video adapters registered to system. */ grub_video_adapter_t grub_video_adapter_list = NULL; diff --git a/include/grub/dl.h b/include/grub/dl.h index afc4af41a..71db90c8b 100644 --- a/include/grub/dl.h +++ b/include/grub/dl.h @@ -63,8 +63,32 @@ __asm__ (".section .modname\n.asciz \"" #name "\"\n") #define GRUB_MOD_DEP(name) \ __asm__ (".section .moddeps\n.asciz \"" #name "\"\n") + #endif +#ifdef APPLE_CC +#define GRUB_MOD_SECTION(x) "_" x ", _" x "" +#else +#define GRUB_MOD_SECTION(x) "." x +#endif + +/* Me, Vladimir Serbinenko, hereby I add this module check as per new + GNU module policy. Note that this license check is informative only. + Modules have to be licensed under GPLv3 or GPLv3+ (optionally + multi-licensed under other licences as well) independently of the + presence of this check and solely by linking (module loading in GRUB + constitutes linking) and GRUB core being licensed under GPLv3+. + Be sure to understand your license obligations. +*/ +#define GRUB_MOD_LICENSE(license) \ + static char grub_module_license[] __attribute__ ((section (GRUB_MOD_SECTION ("module_license")), used)) = "LICENSE=" license; + +/* Under GPL license obligations you have to distribute your module + under GPLv3(+). However, you can also distribute the same code under + another license as long as GPLv3(+) version is provided. +*/ +#define GRUB_MOD_DUAL_LICENSE(x) + struct grub_dl_segment { struct grub_dl_segment *next; diff --git a/util/import_gcry.py b/util/import_gcry.py index 494a4ae7b..54c178dbf 100644 --- a/util/import_gcry.py +++ b/util/import_gcry.py @@ -91,7 +91,12 @@ for cipher_file in cipher_files: f = open (infile, "r") fw = open (outfile, "w") fw.write ("/* This file was automatically imported with \n") - fw.write (" import_gcry.py. Please don't modify it */\n"); + fw.write (" import_gcry.py. Please don't modify it */\n") + fw.write ("#include \n") + # Whole libgcrypt is distributedunder GPLv3+ or compatible + if isc: + fw.write ("GRUB_MOD_LICENSE (\"GPLv3+\");\n") + ciphernames = [] mdnames = [] hold = False From ec9f5e0d7387817ca986a33de79c9323d35beabb Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 11 Apr 2011 23:30:15 +0200 Subject: [PATCH 451/869] * NEWS: Add btrfs support. --- ChangeLog | 4 ++++ NEWS | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 29dbceec0..6112407bc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2011-04-11 Vladimir Serbinenko + + * NEWS: Add btrfs support. + 2011-04-11 Vladimir Serbinenko 2011-04-11 Colin Watson diff --git a/NEWS b/NEWS index 36e3f25bf..81b6ecb2d 100644 --- a/NEWS +++ b/NEWS @@ -29,7 +29,7 @@ New in 1.99: * New `lsacpi' command. -* Basic btrfs support (detection and UUID). +* Btrfs support. * New `--boot-directory' option to `grub-install', `grub-reboot', and `grub-set-default', with clearer semantics than the previous From 0c6769339490388a44e3b782a16443c0219029fe Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Tue, 12 Apr 2011 11:39:17 +0100 Subject: [PATCH 452/869] * util/import_gcry.py: Fix typo. --- ChangeLog | 4 ++++ util/import_gcry.py | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 6112407bc..63c6ec58d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2011-04-12 Colin Watson + + * util/import_gcry.py: Fix typo. + 2011-04-11 Vladimir Serbinenko * NEWS: Add btrfs support. diff --git a/util/import_gcry.py b/util/import_gcry.py index 54c178dbf..b2a0a5451 100644 --- a/util/import_gcry.py +++ b/util/import_gcry.py @@ -93,7 +93,7 @@ for cipher_file in cipher_files: fw.write ("/* This file was automatically imported with \n") fw.write (" import_gcry.py. Please don't modify it */\n") fw.write ("#include \n") - # Whole libgcrypt is distributedunder GPLv3+ or compatible + # Whole libgcrypt is distributed under GPLv3+ or compatible if isc: fw.write ("GRUB_MOD_LICENSE (\"GPLv3+\");\n") From 09a9d66f1d670be91aab7915284c18e67e8602e3 Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Tue, 12 Apr 2011 11:44:35 +0100 Subject: [PATCH 453/869] * NEWS: Drop obsolete entry about probe-only btrfs support. --- ChangeLog | 4 ++++ NEWS | 4 ---- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 63c6ec58d..cf6fa18c9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2011-04-12 Colin Watson + + * NEWS: Drop obsolete entry about probe-only btrfs support. + 2011-04-12 Colin Watson * util/import_gcry.py: Fix typo. diff --git a/NEWS b/NEWS index 81b6ecb2d..2a93c2526 100644 --- a/NEWS +++ b/NEWS @@ -83,10 +83,6 @@ New in 1.99: * Extensive updates to the Texinfo documentation. -* Add `grub-probe' support for the btrfs filesystem, permitting / to - reside on btrfs as long as /boot is on a filesystem natively supported - by GRUB. - * Handle symbolic links under /dev/mapper on GNU/Linux. * Handle installation across multiple partition table types. From 9d5f81622cd2bc422d6165b6d7a1b022495ecfc4 Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Tue, 12 Apr 2011 13:23:19 +0100 Subject: [PATCH 454/869] * docs/grub.texi (normal): New section. (normal_exit): New section. (Embedded configuration): Add reference to normal. (GRUB only offers a rescue shell): Likewise. * docs/grub-dev.texi (Error Handling): Fix typo. --- ChangeLog | 8 ++++++++ docs/grub-dev.texi | 2 +- docs/grub.texi | 48 +++++++++++++++++++++++++++++++++++++--------- 3 files changed, 48 insertions(+), 10 deletions(-) diff --git a/ChangeLog b/ChangeLog index cf6fa18c9..c1ee7cf9d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2011-04-12 Colin Watson + + * docs/grub.texi (normal): New section. + (normal_exit): New section. + (Embedded configuration): Add reference to normal. + (GRUB only offers a rescue shell): Likewise. + * docs/grub-dev.texi (Error Handling): Fix typo. + 2011-04-12 Colin Watson * NEWS: Drop obsolete entry about probe-only btrfs support. diff --git a/docs/grub-dev.texi b/docs/grub-dev.texi index a45b8b198..93d2bdb4d 100644 --- a/docs/grub-dev.texi +++ b/docs/grub-dev.texi @@ -451,7 +451,7 @@ request. Instead, please subscribe to the mailing list, and communicate first @chapter Error Handling Error handling in GRUB 2 is based on exception handling model. As C language -doesn't direcly support exceptions, exception handling behavior is emulated +doesn't directly support exceptions, exception handling behavior is emulated in software. When exception is raised, function must return to calling function. If calling diff --git a/docs/grub.texi b/docs/grub.texi index 0c59975cd..8d2223fb4 100644 --- a/docs/grub.texi +++ b/docs/grub.texi @@ -1486,14 +1486,14 @@ reside anywhere on the file system, and may be removed after running @command{grub-mkimage}. After the embedded configuration file (if any) is executed, GRUB will load -the @samp{normal} module, which will then read the real configuration file -from @file{$prefix/grub.cfg}. By this point, the @code{root} variable will -also have been set to the root device name. For example, @code{prefix} -might be set to @samp{(hd0,1)/boot/grub}, and @code{root} might be set to -@samp{hd0,1}. Thus, in most cases, the embedded configuration file only -needs to set the @code{prefix} and @code{root} variables, and then drop -through to GRUB's normal processing. A typical example of this might look -like this: +the @samp{normal} module (@pxref{normal}), which will then read the real +configuration file from @file{$prefix/grub.cfg}. By this point, the +@code{root} variable will also have been set to the root device name. For +example, @code{prefix} might be set to @samp{(hd0,1)/boot/grub}, and +@code{root} might be set to @samp{hd0,1}. Thus, in most cases, the embedded +configuration file only needs to set the @code{prefix} and @code{root} +variables, and then drop through to GRUB's normal processing. A typical +example of this might look like this: @example @group @@ -3089,6 +3089,8 @@ you forget a command, you can run the command @command{help} * load_env:: Load variables from environment block * loopback:: Make a device from a filesystem image * ls:: List devices or files +* normal:: Enter normal mode +* normal_exit:: Exit from normal mode * parttool:: Modify partition table entries * password:: Set a clear-text password * password_pbkdf2:: Set a hashed password @@ -3545,6 +3547,34 @@ name syntax}), then list the contents of that directory. @end deffn +@node normal +@subsection normal + +@deffn Command normal [file] +Enter normal mode and display the GRUB menu. + +In normal mode, commands, filesystem modules, and cryptography modules are +automatically loaded, and the full GRUB script parser is available. Other +modules may be explicitly loaded using @command{insmod} (@pxref{insmod}). + +If a @var{file} is given, then commands will be read from that file. +Otherwise, they will be read from @file{$prefix/grub.cfg} if it exists. + +@command{normal} may be called from within normal mode, creating a nested +environment. It is more usual to use @command{configfile} +(@pxref{configfile}) for this. +@end deffn + + +@node normal_exit +@subsection normal_exit + +@deffn Command normal_exit +Exit normal mode (@pxref{normal}). If this instance of normal mode was not +nested within another one, then return to rescue mode. +@end deffn + + @node parttool @subsection parttool @@ -4082,7 +4112,7 @@ GRUB's normal start-up procedure involves setting the @samp{prefix} environment variable to a value set in the core image by @command{grub-install}, setting the @samp{root} variable to match, loading the @samp{normal} module from the prefix, and running the @samp{normal} -command. This command is responsible for reading +command (@pxref{normal}). This command is responsible for reading @file{/boot/grub/grub.cfg}, running the menu, and doing all the useful things GRUB is supposed to do. From 78fa584f67811a331de065dc1cca39e65a40b21e Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Wed, 13 Apr 2011 12:36:04 +0100 Subject: [PATCH 455/869] Rewrite /proc/self/mountinfo handling to cope with bind-mounts and move-mounts appearing out of order. Fixes Ubuntu bug #738345. * grub-core/kern/emu/getroot.c (find_root_device_from_mountinfo): Build a list of relevant visible mounts using the mnt_id and parent_mnt_id fields, and then scan that list at the end. --- ChangeLog | 9 ++++ grub-core/kern/emu/getroot.c | 100 ++++++++++++++++++++++++++++------- 2 files changed, 90 insertions(+), 19 deletions(-) diff --git a/ChangeLog b/ChangeLog index c1ee7cf9d..d0269c905 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2011-04-13 Colin Watson + + Rewrite /proc/self/mountinfo handling to cope with bind-mounts and + move-mounts appearing out of order. Fixes Ubuntu bug #738345. + + * grub-core/kern/emu/getroot.c (find_root_device_from_mountinfo): + Build a list of relevant visible mounts using the mnt_id and + parent_mnt_id fields, and then scan that list at the end. + 2011-04-12 Colin Watson * docs/grub.texi (normal): New section. diff --git a/grub-core/kern/emu/getroot.c b/grub-core/kern/emu/getroot.c index c4cbb9c18..17da9070f 100644 --- a/grub-core/kern/emu/getroot.c +++ b/grub-core/kern/emu/getroot.c @@ -98,6 +98,14 @@ xgetcwd (void) #ifdef __linux__ +struct mountinfo_entry +{ + int id; + int major, minor; + char enc_root[PATH_MAX], enc_path[PATH_MAX]; + char fstype[PATH_MAX], device[PATH_MAX]; +}; + /* Statting something on a btrfs filesystem always returns a virtual device major/minor pair rather than the real underlying device, because btrfs can span multiple underlying devices (and even if it's currently only @@ -112,6 +120,10 @@ grub_find_root_device_from_mountinfo (const char *dir, char **relroot) char *buf = NULL; size_t len = 0; char *ret = NULL; + int entry_len = 0, entry_max = 4; + struct mountinfo_entry *entries; + struct mountinfo_entry parent_entry = { 0, 0, 0, "", "", "", "" }; + int i; if (! *dir) dir = "/"; @@ -122,52 +134,102 @@ grub_find_root_device_from_mountinfo (const char *dir, char **relroot) if (! fp) return NULL; /* fall through to other methods */ + entries = xmalloc (entry_max * sizeof (*entries)); + + /* First, build a list of relevant visible mounts. */ while (getline (&buf, &len, fp) > 0) { - int mnt_id, parent_mnt_id; - unsigned int major, minor; - char enc_root[PATH_MAX], enc_path[PATH_MAX]; + struct mountinfo_entry entry; int count; size_t enc_path_len; const char *sep; - char fstype[PATH_MAX], device[PATH_MAX]; if (sscanf (buf, "%d %d %u:%u %s %s%n", - &mnt_id, &parent_mnt_id, &major, &minor, enc_root, enc_path, - &count) < 6) + &entry.id, &parent_entry.id, &entry.major, &entry.minor, + entry.enc_root, entry.enc_path, &count) < 6) continue; - enc_path_len = strlen (enc_path); + enc_path_len = strlen (entry.enc_path); /* Check that enc_path is a prefix of dir. The prefix must either be the entire string, or end with a slash, or be immediately followed by a slash. */ - if (strncmp (dir, enc_path, enc_path_len) != 0 || + if (strncmp (dir, entry.enc_path, enc_path_len) != 0 || (enc_path_len && dir[enc_path_len - 1] != '/' && dir[enc_path_len] && dir[enc_path_len] != '/')) continue; - /* This is a parent of the requested directory. /proc/self/mountinfo - is in mount order, so it must be the closest parent we've - encountered so far. If it's virtual, return its device node; - otherwise, carry on to try to find something closer. */ - - free (ret); - ret = NULL; - sep = strstr (buf + count, " - "); if (!sep) continue; sep += sizeof (" - ") - 1; - if (sscanf (sep, "%s %s", fstype, device) != 2) + if (sscanf (sep, "%s %s", entry.fstype, entry.device) != 2) continue; - ret = strdup (device); + /* Using the mount IDs, find out where this fits in the list of + visible mount entries we've seen so far. There are three + interesting cases. Firstly, it may be inserted at the end: this is + the usual case of /foo/bar being mounted after /foo. Secondly, it + may be inserted at the start: for example, this can happen for + filesystems that are mounted before / and later moved under it. + Thirdly, it may occlude part or all of the existing filesystem + tree, in which case the end of the list needs to be pruned and this + new entry will be inserted at the end. */ + if (entry_len >= entry_max) + { + entry_max <<= 1; + entries = xrealloc (entries, entry_max * sizeof (*entries)); + } + + if (!entry_len) + { + /* Initialise list. */ + entry_len = 2; + entries[0] = parent_entry; + entries[1] = entry; + } + else + { + for (i = entry_len - 1; i >= 0; i--) + { + if (entries[i].id == parent_entry.id) + { + /* Insert at end, pruning anything previously above this. */ + entry_len = i + 2; + entries[i + 1] = entry; + break; + } + else if (i == 0 && entries[i].id == entry.id) + { + /* Insert at start. */ + entry_len++; + memmove (entries + 1, entries, + (entry_len - 1) * sizeof (*entries)); + entries[0] = parent_entry; + entries[1] = entry; + break; + } + } + } + } + + /* Now scan visible mounts for the ones we're interested in. */ + for (i = entry_len - 1; i >= 0; i--) + { + if (entries[i].major != 0) + continue; /* not a virtual device */ + + if (!*entries[i].device) + continue; + + ret = strdup (entries[i].device); if (relroot) - *relroot = strdup (enc_root); + *relroot = strdup (entries[i].enc_root); + break; } free (buf); + free (entries); fclose (fp); return ret; } From e74c31125d2466db7d5a190f924b1abee6094947 Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Wed, 13 Apr 2011 12:57:26 +0100 Subject: [PATCH 456/869] * util/grub.d/10_linux.in: Add rootflags=subvol= if / is on a btrfs subvolume. * util/grub.d/20_linux_xen.in: Likewise. --- ChangeLog | 6 ++++++ util/grub.d/10_linux.in | 8 ++++++++ util/grub.d/20_linux_xen.in | 8 ++++++++ 3 files changed, 22 insertions(+) diff --git a/ChangeLog b/ChangeLog index d0269c905..47935890d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2011-04-13 Colin Watson + + * util/grub.d/10_linux.in: Add rootflags=subvol= if / is on a + btrfs subvolume. + * util/grub.d/20_linux_xen.in: Likewise. + 2011-04-13 Colin Watson Rewrite /proc/self/mountinfo handling to cope with bind-mounts and diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in index 930ce06ef..1dbcad90c 100644 --- a/util/grub.d/10_linux.in +++ b/util/grub.d/10_linux.in @@ -51,6 +51,14 @@ else LINUX_ROOT_DEVICE=UUID=${GRUB_DEVICE_UUID} fi +if [ "x`${grub_probe} --device ${GRUB_DEVICE} --target=fs 2>/dev/null || true`" = xbtrfs ]; then + rootsubvol="`make_system_path_relative_to_its_root /`" + rootsubvol="${rootsubvol#/}" + if [ "x${rootsubvol}" != x ]; then + GRUB_CMDLINE_LINUX="rootflags=subvol=${rootsubvol} ${GRUB_CMDLINE_LINUX}" + fi +fi + linux_entry () { os="$1" diff --git a/util/grub.d/20_linux_xen.in b/util/grub.d/20_linux_xen.in index 858627aa3..a9007603d 100644 --- a/util/grub.d/20_linux_xen.in +++ b/util/grub.d/20_linux_xen.in @@ -51,6 +51,14 @@ else LINUX_ROOT_DEVICE=UUID=${GRUB_DEVICE_UUID} fi +if [ "x`${grub_probe} --device ${GRUB_DEVICE} --target=fs 2>/dev/null || true`" = xbtrfs ]; then + rootsubvol="`make_system_path_relative_to_its_root /`" + rootsubvol="${rootsubvol#/}" + if [ "x${rootsubvol}" != x ]; then + GRUB_CMDLINE_LINUX="rootflags=subvol=${rootsubvol} ${GRUB_CMDLINE_LINUX}" + fi +fi + linux_entry () { os="$1" From bd671cc4fe27784df6bacb57d83f691a84e3f5f0 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 15 Apr 2011 18:15:06 +0200 Subject: [PATCH 457/869] Use Block IO on EFI --- grub-core/disk/efi/efidisk.c | 28 +++++++++------------------- 1 file changed, 9 insertions(+), 19 deletions(-) diff --git a/grub-core/disk/efi/efidisk.c b/grub-core/disk/efi/efidisk.c index 1bf764f10..35602513e 100644 --- a/grub-core/disk/efi/efidisk.c +++ b/grub-core/disk/efi/efidisk.c @@ -33,12 +33,10 @@ struct grub_efidisk_data grub_efi_device_path_t *device_path; grub_efi_device_path_t *last_device_path; grub_efi_block_io_t *block_io; - grub_efi_disk_io_t *disk_io; struct grub_efidisk_data *next; }; -/* GUIDs. */ -static grub_efi_guid_t disk_io_guid = GRUB_EFI_DISK_IO_GUID; +/* GUID. */ static grub_efi_guid_t block_io_guid = GRUB_EFI_BLOCK_IO_GUID; static struct grub_efidisk_data *fd_devices; @@ -143,7 +141,7 @@ make_devices (void) struct grub_efidisk_data *devices = 0; /* Find handles which support the disk io interface. */ - handles = grub_efi_locate_handle (GRUB_EFI_BY_PROTOCOL, &disk_io_guid, + handles = grub_efi_locate_handle (GRUB_EFI_BY_PROTOCOL, &block_io_guid, 0, &num_handles); if (! handles) return 0; @@ -155,7 +153,6 @@ make_devices (void) grub_efi_device_path_t *ldp; struct grub_efidisk_data *d; grub_efi_block_io_t *bio; - grub_efi_disk_io_t *dio; dp = grub_efi_get_device_path (*handle); if (! dp) @@ -168,9 +165,7 @@ make_devices (void) bio = grub_efi_open_protocol (*handle, &block_io_guid, GRUB_EFI_OPEN_PROTOCOL_GET_PROTOCOL); - dio = grub_efi_open_protocol (*handle, &disk_io_guid, - GRUB_EFI_OPEN_PROTOCOL_GET_PROTOCOL); - if (! bio || ! dio) + if (! bio) /* This should not happen... Why? */ continue; @@ -186,7 +181,6 @@ make_devices (void) d->device_path = dp; d->last_device_path = ldp; d->block_io = bio; - d->disk_io = dio; d->next = devices; devices = d; } @@ -563,22 +557,20 @@ grub_efidisk_read (struct grub_disk *disk, grub_disk_addr_t sector, { /* For now, use the disk io interface rather than the block io's. */ struct grub_efidisk_data *d; - grub_efi_disk_io_t *dio; grub_efi_block_io_t *bio; grub_efi_status_t status; d = disk->data; - dio = d->disk_io; bio = d->block_io; grub_dprintf ("efidisk", "reading 0x%lx sectors at the sector 0x%llx from %s\n", (unsigned long) size, (unsigned long long) sector, disk->name); - status = efi_call_5 (dio->read, dio, bio->media->media_id, - (grub_efi_uint64_t) sector << disk->log_sector_size, - (grub_efi_uintn_t) size << disk->log_sector_size, - buf); + status = efi_call_5 (bio->read_blocks, bio, bio->media->media_id, + (grub_efi_uint64_t) sector, + (grub_efi_uintn_t) size << disk->log_sector_size, + buf); if (status != GRUB_EFI_SUCCESS) return grub_error (GRUB_ERR_READ_ERROR, "efidisk read error"); @@ -591,20 +583,18 @@ grub_efidisk_write (struct grub_disk *disk, grub_disk_addr_t sector, { /* For now, use the disk io interface rather than the block io's. */ struct grub_efidisk_data *d; - grub_efi_disk_io_t *dio; grub_efi_block_io_t *bio; grub_efi_status_t status; d = disk->data; - dio = d->disk_io; bio = d->block_io; grub_dprintf ("efidisk", "writing 0x%lx sectors at the sector 0x%llx to %s\n", (unsigned long) size, (unsigned long long) sector, disk->name); - status = efi_call_5 (dio->write, dio, bio->media->media_id, - (grub_efi_uint64_t) sector << disk->log_sector_size, + status = efi_call_5 (bio->write_blocks, bio, bio->media->media_id, + (grub_efi_uint64_t) sector, (grub_efi_uintn_t) size << disk->log_sector_size, (void *) buf); if (status != GRUB_EFI_SUCCESS) From d8a2bcf564728cc38b138fed18cd89b097493e75 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 15 Apr 2011 21:42:29 +0200 Subject: [PATCH 458/869] contiguous read --- grub-core/kern/disk.c | 296 +++++++++++++++++++++++++----------------- 1 file changed, 178 insertions(+), 118 deletions(-) diff --git a/grub-core/kern/disk.c b/grub-core/kern/disk.c index af56527ad..5439a02f6 100644 --- a/grub-core/kern/disk.c +++ b/grub-core/kern/disk.c @@ -398,13 +398,93 @@ transform_sector (grub_disk_t disk, grub_disk_addr_t sector) return sector >> (disk->log_sector_size - GRUB_DISK_SECTOR_BITS); } +/* Small read (less than cache size and not pass across cache unit boundaries). + sector is already adjusted and is divisible by cache unit size. + */ +static grub_err_t +grub_disk_read_small (grub_disk_t disk, grub_disk_addr_t sector, + grub_off_t offset, grub_size_t size, void *buf) +{ + char *data; + char *tmp_buf; + + /* Fetch the cache. */ + data = grub_disk_cache_fetch (disk->dev->id, disk->id, sector); + if (data) + { + /* Just copy it! */ + grub_memcpy (buf, data + offset, size); + grub_disk_cache_unlock (disk->dev->id, disk->id, sector); + return GRUB_ERR_NONE; + } + + /* Allocate a temporary buffer. */ + tmp_buf = grub_malloc (GRUB_DISK_SECTOR_SIZE << GRUB_DISK_CACHE_BITS); + if (! tmp_buf) + return grub_errno; + + /* Otherwise read data from the disk actually. */ + if (disk->total_sectors == GRUB_DISK_SIZE_UNKNOWN + || sector + GRUB_DISK_CACHE_SIZE + < (disk->total_sectors << (disk->log_sector_size - GRUB_DISK_SECTOR_BITS))) + { + grub_err_t err; + err = (disk->dev->read) (disk, transform_sector (disk, sector), + 1 << (GRUB_DISK_CACHE_BITS + + GRUB_DISK_SECTOR_BITS + - disk->log_sector_size), tmp_buf); + if (!err) + { + /* Copy it and store it in the disk cache. */ + grub_memcpy (buf, tmp_buf + offset, size); + grub_disk_cache_store (disk->dev->id, disk->id, + sector, tmp_buf); + grub_free (tmp_buf); + return GRUB_ERR_NONE; + } + } + + grub_errno = GRUB_ERR_NONE; + + { + /* Uggh... Failed. Instead, just read necessary data. */ + unsigned num; + grub_disk_addr_t aligned_sector; + + sector += (offset >> GRUB_DISK_SECTOR_BITS); + offset &= ((1 << GRUB_DISK_SECTOR_BITS) - 1); + aligned_sector = (sector & ~((1 << (disk->log_sector_size + - GRUB_DISK_SECTOR_BITS)) + - 1)); + offset += ((sector - aligned_sector) << GRUB_DISK_SECTOR_BITS); + num = ((size + offset + (1 << (disk->log_sector_size)) + - 1) >> (disk->log_sector_size)); + + tmp_buf = grub_malloc (num << disk->log_sector_size); + if (!tmp_buf) + return grub_errno; + + if ((disk->dev->read) (disk, transform_sector (disk, aligned_sector), + num, tmp_buf)) + { + grub_error_push (); + grub_dprintf ("disk", "%s read failed\n", disk->name); + grub_error_pop (); + return grub_errno; + } + grub_memcpy (buf, tmp_buf + offset, size); + return GRUB_ERR_NONE; + } +} + /* Read data from the disk. */ grub_err_t grub_disk_read (grub_disk_t disk, grub_disk_addr_t sector, grub_off_t offset, grub_size_t size, void *buf) { - char *tmp_buf; - unsigned real_offset; + grub_off_t real_offset; + grub_disk_addr_t real_sector; + grub_size_t real_size; /* First of all, check if the region is within the disk. */ if (grub_disk_adjust_range (disk, §or, &offset, size) != GRUB_ERR_NONE) @@ -416,138 +496,118 @@ grub_disk_read (grub_disk_t disk, grub_disk_addr_t sector, return grub_errno; } + real_sector = sector; real_offset = offset; + real_size = size; - /* Allocate a temporary buffer. */ - tmp_buf = grub_malloc (GRUB_DISK_SECTOR_SIZE << GRUB_DISK_CACHE_BITS); - if (! tmp_buf) - return grub_errno; - - /* Until SIZE is zero... */ - while (size) + /* First read until first cache boundary. */ + if (offset || (sector & (GRUB_DISK_CACHE_SIZE - 1))) { - char *data; grub_disk_addr_t start_sector; - grub_size_t len; grub_size_t pos; + grub_err_t err; + grub_size_t len; - /* For reading bulk data. */ start_sector = sector & ~(GRUB_DISK_CACHE_SIZE - 1); pos = (sector - start_sector) << GRUB_DISK_SECTOR_BITS; len = ((GRUB_DISK_SECTOR_SIZE << GRUB_DISK_CACHE_BITS) - - pos - real_offset); + - pos - offset); if (len > size) len = size; - - /* Fetch the cache. */ - data = grub_disk_cache_fetch (disk->dev->id, disk->id, start_sector); - if (data) - { - /* Just copy it! */ - grub_memcpy (buf, data + pos + real_offset, len); - grub_disk_cache_unlock (disk->dev->id, disk->id, start_sector); - } - else - { - /* Otherwise read data from the disk actually. */ - if ((disk->total_sectors != GRUB_DISK_SIZE_UNKNOWN - && start_sector + GRUB_DISK_CACHE_SIZE - > (disk->total_sectors << (disk->log_sector_size - GRUB_DISK_SECTOR_BITS))) - || (disk->dev->read) (disk, transform_sector (disk, start_sector), - 1 << (GRUB_DISK_CACHE_BITS - + GRUB_DISK_SECTOR_BITS - - disk->log_sector_size), tmp_buf) - != GRUB_ERR_NONE) - { - /* Uggh... Failed. Instead, just read necessary data. */ - unsigned num; - char *p; - grub_disk_addr_t aligned_sector; - - grub_errno = GRUB_ERR_NONE; - - aligned_sector = (sector & ~((1 << (disk->log_sector_size - - GRUB_DISK_SECTOR_BITS)) - - 1)); - real_offset += ((sector - aligned_sector) - << GRUB_DISK_SECTOR_BITS); - num = ((size + real_offset + (1 << (disk->log_sector_size)) - - 1) >> (disk->log_sector_size)); - - p = grub_realloc (tmp_buf, num << disk->log_sector_size); - if (!p) - goto finish; - - tmp_buf = p; - - if ((disk->dev->read) (disk, transform_sector (disk, - aligned_sector), - num, tmp_buf)) - { - grub_error_push (); - grub_dprintf ("disk", "%s read failed\n", disk->name); - grub_error_pop (); - goto finish; - } - - grub_memcpy (buf, tmp_buf + real_offset, size); - - /* Call the read hook, if any. */ - if (disk->read_hook) - while (size) - { - grub_size_t to_read = (size > GRUB_DISK_SECTOR_SIZE) ? GRUB_DISK_SECTOR_SIZE : size; - (disk->read_hook) (sector, real_offset, - to_read); - if (grub_errno != GRUB_ERR_NONE) - goto finish; - - sector++; - size -= to_read - real_offset; - real_offset = 0; - } - - /* This must be the end. */ - goto finish; - } - - /* Copy it and store it in the disk cache. */ - grub_memcpy (buf, tmp_buf + pos + real_offset, len); - grub_disk_cache_store (disk->dev->id, disk->id, - start_sector, tmp_buf); - } - - /* Call the read hook, if any. */ - if (disk->read_hook) - { - grub_disk_addr_t s = sector; - grub_size_t l = len; - - while (l) - { - (disk->read_hook) (s, real_offset, - ((l > GRUB_DISK_SECTOR_SIZE) - ? GRUB_DISK_SECTOR_SIZE - : l)); - - if (l < GRUB_DISK_SECTOR_SIZE - real_offset) - break; - - s++; - l -= GRUB_DISK_SECTOR_SIZE - real_offset; - real_offset = 0; - } - } - - sector = start_sector + GRUB_DISK_CACHE_SIZE; + err = grub_disk_read_small (disk, start_sector, + offset + pos, len, buf); + if (err) + return err; buf = (char *) buf + len; size -= len; - real_offset = 0; + offset += len; + sector += (offset >> GRUB_DISK_SECTOR_BITS); + offset &= ((1 << GRUB_DISK_SECTOR_BITS) - 1); } - finish: + /* Until SIZE is zero... */ + while (size >= (GRUB_DISK_CACHE_SIZE << GRUB_DISK_SECTOR_BITS)) + { + char *data = NULL; + grub_disk_addr_t agglomerate; + grub_err_t err; - grub_free (tmp_buf); + /* agglomerate read until we find a first cached entry. */ + for (agglomerate = 0; agglomerate + < (size >> (GRUB_DISK_SECTOR_BITS + GRUB_DISK_CACHE_BITS)); + agglomerate++) + { + data = grub_disk_cache_fetch (disk->dev->id, disk->id, + sector + (agglomerate + << GRUB_DISK_CACHE_BITS)); + if (data) + break; + } + + if (agglomerate) + { + grub_disk_addr_t i; + + err = (disk->dev->read) (disk, transform_sector (disk, sector), + agglomerate << (GRUB_DISK_CACHE_BITS + + GRUB_DISK_SECTOR_BITS + - disk->log_sector_size), + buf); + if (err) + return err; + + for (i = 0; i < agglomerate; i ++) + grub_disk_cache_store (disk->dev->id, disk->id, + sector + (i << GRUB_DISK_CACHE_BITS), + (char *) buf + + (i << (GRUB_DISK_CACHE_BITS + + GRUB_DISK_SECTOR_BITS))); + + sector += agglomerate << GRUB_DISK_CACHE_BITS; + size -= agglomerate << (GRUB_DISK_CACHE_BITS + GRUB_DISK_SECTOR_BITS); + buf = (char *) buf + + (agglomerate << (GRUB_DISK_CACHE_BITS + GRUB_DISK_SECTOR_BITS)); + } + + if (data) + { + grub_memcpy (buf, data, GRUB_DISK_CACHE_SIZE); + sector += GRUB_DISK_CACHE_SIZE; + buf = (char *) buf + (GRUB_DISK_CACHE_SIZE << GRUB_DISK_SECTOR_BITS); + size -= (GRUB_DISK_CACHE_SIZE << GRUB_DISK_SECTOR_BITS); + grub_disk_cache_unlock (disk->dev->id, disk->id, + sector + (agglomerate + << GRUB_DISK_CACHE_BITS)); + } + } + + /* And now read the last part. */ + if (size) + { + grub_err_t err; + err = grub_disk_read_small (disk, sector, 0, size, buf); + if (err) + return err; + } + + /* Call the read hook, if any. */ + if (disk->read_hook) + { + grub_disk_addr_t s = real_sector; + grub_size_t l = real_size; + grub_off_t o = real_offset; + + while (l) + { + (disk->read_hook) (s, o, + ((l > GRUB_DISK_SECTOR_SIZE) + ? GRUB_DISK_SECTOR_SIZE + : l)); + s++; + l -= GRUB_DISK_SECTOR_SIZE - o; + o = 0; + } + } return grub_errno; } From e03f7bea4526068566c7c305e90b4614132129dc Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 16 Apr 2011 09:16:44 +0200 Subject: [PATCH 459/869] * grub-core/gfxmenu/gui_image.c (rescale_image): Don't attempt to scale to negative size. --- ChangeLog | 5 +++++ grub-core/gfxmenu/gui_image.c | 17 ++++++++++------- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index 47935890d..572d49a13 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-04-16 Vladimir Serbinenko + + * grub-core/gfxmenu/gui_image.c (rescale_image): Don't attempt to scale + to negative size. + 2011-04-13 Colin Watson * util/grub.d/10_linux.in: Add rootflags=subvol= if / is on a diff --git a/grub-core/gfxmenu/gui_image.c b/grub-core/gfxmenu/gui_image.c index 3988f4ba8..60e4a46de 100644 --- a/grub-core/gfxmenu/gui_image.c +++ b/grub-core/gfxmenu/gui_image.c @@ -101,6 +101,9 @@ image_get_parent (void *vself) static grub_err_t rescale_image (grub_gui_image_t self) { + signed width; + signed height; + if (! self->raw_bitmap) { if (self->bitmap) @@ -111,12 +114,12 @@ rescale_image (grub_gui_image_t self) return grub_errno; } - unsigned width = self->bounds.width; - unsigned height = self->bounds.height; + width = self->bounds.width; + height = self->bounds.height; if (self->bitmap - && (grub_video_bitmap_get_width (self->bitmap) == width) - && (grub_video_bitmap_get_height (self->bitmap) == height)) + && ((signed) grub_video_bitmap_get_width (self->bitmap) == width) + && ((signed) grub_video_bitmap_get_height (self->bitmap) == height)) { /* Nothing to do; already the right size. */ return grub_errno; @@ -131,15 +134,15 @@ rescale_image (grub_gui_image_t self) /* Create a scaled bitmap, unless the requested size is the same as the raw size -- in that case a reference is made. */ - if (grub_video_bitmap_get_width (self->raw_bitmap) == width - && grub_video_bitmap_get_height (self->raw_bitmap) == height) + if ((signed) grub_video_bitmap_get_width (self->raw_bitmap) == width + && (signed) grub_video_bitmap_get_height (self->raw_bitmap) == height) { self->bitmap = self->raw_bitmap; return grub_errno; } /* Don't scale to an invalid size. */ - if (width == 0 || height == 0) + if (width <= 0 || height <= 0) return grub_errno; /* Create the scaled bitmap. */ From 50d2cc5ae5712101b2307d5b8df2d1e05a63ea41 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 16 Apr 2011 15:27:35 +0200 Subject: [PATCH 460/869] Identify RAID by its UUID rather than (guessed) name. * grub-core/disk/raid.c (ascii2hex): New function. (grub_raid_open): Accept mduuid/%s specification. * grub-core/kern/emu/getroot.c (get_mdadm_name): Revamped into ... (get_mdadm_uuid): ... this. (grub_util_get_grub_dev): Use mduuid/%s if UUID is available. --- ChangeLog | 10 +++++++++ grub-core/disk/raid.c | 39 ++++++++++++++++++++++++++++---- grub-core/kern/emu/getroot.c | 43 ++++++++++++++---------------------- 3 files changed, 62 insertions(+), 30 deletions(-) diff --git a/ChangeLog b/ChangeLog index 572d49a13..84840a9a7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2011-04-17 Vladimir Serbinenko + + Identify RAID by its UUID rather than (guessed) name. + + * grub-core/disk/raid.c (ascii2hex): New function. + (grub_raid_open): Accept mduuid/%s specification. + * grub-core/kern/emu/getroot.c (get_mdadm_name): Revamped into ... + (get_mdadm_uuid): ... this. + (grub_util_get_grub_dev): Use mduuid/%s if UUID is available. + 2011-04-16 Vladimir Serbinenko * grub-core/gfxmenu/gui_image.c (rescale_image): Don't attempt to scale diff --git a/grub-core/disk/raid.c b/grub-core/disk/raid.c index 3c74bba99..946e6d2c2 100644 --- a/grub-core/disk/raid.c +++ b/grub-core/disk/raid.c @@ -122,18 +122,49 @@ grub_raid_getname (struct grub_disk *disk) } #endif +static inline int +ascii2hex (char c) +{ + if (c >= '0' && c <= '9') + return c - '0'; + if (c >= 'a' && c <= 'f') + return c - 'a' + 10; + if (c >= 'A' && c <= 'F') + return c - 'A' + 10; + return 0; +} + static grub_err_t grub_raid_open (const char *name, grub_disk_t disk) { struct grub_raid_array *array; unsigned n; - for (array = array_list; array != NULL; array = array->next) + if (grub_memcmp (name, "mduuid/", sizeof ("mduuid/") - 1) == 0) { - if (!grub_strcmp (array->name, name)) - if (grub_is_array_readable (array)) - break; + const char *uuidstr = name + sizeof ("mduuid/") - 1; + grub_size_t uuid_len = grub_strlen (uuidstr) / 2; + grub_uint8_t uuidbin[uuid_len]; + unsigned i; + for (i = 0; i < uuid_len; i++) + uuidbin[i] = ascii2hex (uuidstr[2 * i + 1]) + | (ascii2hex (uuidstr[2 * i]) << 4); + + for (array = array_list; array != NULL; array = array->next) + { + if (uuid_len == (unsigned) array->uuid_len + && grub_memcmp (uuidbin, array->uuid, uuid_len) == 0) + if (grub_is_array_readable (array)) + break; + } } + else + for (array = array_list; array != NULL; array = array->next) + { + if (!grub_strcmp (array->name, name)) + if (grub_is_array_readable (array)) + break; + } if (!array) return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "unknown RAID device %s", diff --git a/grub-core/kern/emu/getroot.c b/grub-core/kern/emu/getroot.c index 17da9070f..f836a6625 100644 --- a/grub-core/kern/emu/getroot.c +++ b/grub-core/kern/emu/getroot.c @@ -690,7 +690,7 @@ grub_util_get_dev_abstraction (const char *os_dev __attribute__((unused))) #ifdef __linux__ static char * -get_mdadm_name (const char *os_dev) +get_mdadm_uuid (const char *os_dev) { int mdadm_pipe[2]; pid_t mdadm_pid; @@ -742,19 +742,21 @@ get_mdadm_name (const char *os_dev) while (getline (&buf, &len, mdadm) > 0) { - if (strncmp (buf, "MD_NAME=", sizeof ("MD_NAME=") - 1) == 0) + if (strncmp (buf, "MD_UUID=", sizeof ("MD_UUID=") - 1) == 0) { - char *name_start, *colon; + char *name_start, *ptri, *ptro; 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'; + name_start = buf + sizeof ("MD_UUID=") - 1; + ptro = name = xmalloc (strlen (name_start) + 1); + for (ptri = name_start; *ptri && *ptri != '\n' && *ptri != '\r'; + ptri++) + if ((*ptri >= '0' && *ptri <= '9') + || (*ptri >= 'a' && *ptri <= 'f') + || (*ptri >= 'A' && *ptri <= 'F')) + *ptro++ = *ptri; + *ptro = 0; } } @@ -870,37 +872,26 @@ grub_util_get_grub_dev (const char *os_dev) #ifdef __linux__ { - char *mdadm_name = get_mdadm_name (os_dev); + char *mdadm_name = get_mdadm_uuid (os_dev); struct stat st; if (mdadm_name) { - char *newname; const char *q; for (q = os_dev + strlen (os_dev) - 1; q >= os_dev && grub_isdigit (*q); q--); if (q >= os_dev && *q == 'p') - { - newname = xasprintf ("/dev/md/%sp%s", mdadm_name, q + 1); - if (stat (newname, &st) == 0) - { - free (grub_dev); - grub_dev = xasprintf ("md/%s,%s", mdadm_name, q + 1); - goto done; - } - free (newname); - } - newname = xasprintf ("/dev/md/%s", mdadm_name); - if (stat (newname, &st) == 0) { free (grub_dev); - grub_dev = xasprintf ("md/%s", mdadm_name); + grub_dev = xasprintf ("mduuid/%s,%s", mdadm_name, q + 1); + goto done; } + free (grub_dev); + grub_dev = xasprintf ("mduuid/%s", mdadm_name); done: - free (newname); free (mdadm_name); } } From 9ac718b06128f3d55ebdd704cec668347e06af2b Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 16 Apr 2011 17:24:47 +0200 Subject: [PATCH 461/869] * Makefile.am (multiboot.elf): Add -Wl,--build-id=none. (kfreebsd.elf): Likewise. (pc-chainloader.elf): Likewise. (ntldr.elf): Likewise. --- ChangeLog | 7 +++++++ Makefile.am | 10 +++++----- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 84840a9a7..859f337ac 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2011-04-17 Vladimir Serbinenko + + * Makefile.am (multiboot.elf): Add -Wl,--build-id=none. + (kfreebsd.elf): Likewise. + (pc-chainloader.elf): Likewise. + (ntldr.elf): Likewise. + 2011-04-17 Vladimir Serbinenko Identify RAID by its UUID rather than (guessed) name. diff --git a/Makefile.am b/Makefile.am index 60e041a8d..9301c91a5 100644 --- a/Makefile.am +++ b/Makefile.am @@ -147,28 +147,28 @@ linux.init.i386: $(srcdir)/grub-core/tests/boot/linux.init-i386.S $(TARGET_CC) -o $@ $< -m32 -nostdlib -nostdinc -DSUCCESSFUL_BOOT_STRING=\"$(SUCCESSFUL_BOOT_STRING)\" multiboot.elf: $(srcdir)/grub-core/tests/boot/kernel-i386.S - $(TARGET_CC) -o $@ $< -DSUCCESSFUL_BOOT_STRING=\"$(SUCCESSFUL_BOOT_STRING)\" -ffreestanding -nostdlib -nostdinc -DTARGET_MULTIBOOT=1 -Wl,-N -Wl,-Ttext,0x100000 -m32 -I$(srcdir)/include + $(TARGET_CC) -o $@ $< -DSUCCESSFUL_BOOT_STRING=\"$(SUCCESSFUL_BOOT_STRING)\" -ffreestanding -nostdlib -nostdinc -DTARGET_MULTIBOOT=1 -Wl,--build-id=none -Wl,-N -Wl,-Ttext,0x100000 -m32 -I$(srcdir)/include kfreebsd.elf: $(srcdir)/grub-core/tests/boot/kernel-i386.S - $(TARGET_CC) -o $@ $< -DSUCCESSFUL_BOOT_STRING=\"$(SUCCESSFUL_BOOT_STRING)\" -ffreestanding -nostdlib -nostdinc -Wl,-N -Wl,-Ttext,0x100000 -m32 -I$(srcdir)/include + $(TARGET_CC) -o $@ $< -DSUCCESSFUL_BOOT_STRING=\"$(SUCCESSFUL_BOOT_STRING)\" -ffreestanding -nostdlib -nostdinc -Wl,--build-id=none -Wl,-N -Wl,-Ttext,0x100000 -m32 -I$(srcdir)/include kfreebsd.aout: kfreebsd.elf $(OBJCOPY) -O a.out-i386-linux $< $@ -R .note.gnu.build-id pc-chainloader.elf: $(srcdir)/grub-core/tests/boot/kernel-8086.S - $(TARGET_CC) -o $@ $< -DTARGET_CHAINLOADER=1 -DSUCCESSFUL_BOOT_STRING=\"$(SUCCESSFUL_BOOT_STRING)\" -ffreestanding -nostdlib -nostdinc -Wl,-N -Wl,-Ttext,0x7c00 -m32 + $(TARGET_CC) -o $@ $< -DTARGET_CHAINLOADER=1 -DSUCCESSFUL_BOOT_STRING=\"$(SUCCESSFUL_BOOT_STRING)\" -ffreestanding -nostdlib -nostdinc -Wl,--build-id=none -Wl,-N -Wl,-Ttext,0x7c00 -m32 pc-chainloader.bin: pc-chainloader.elf $(OBJCOPY) -O binary --strip-unneeded -R .note -R .comment -R .note.gnu.build-id -R .reginfo -R .rel.dyn $< $@; ntldr.elf: $(srcdir)/grub-core/tests/boot/kernel-8086.S - $(TARGET_CC) -o $@ $< -DTARGET_NTLDR=1 -DSUCCESSFUL_BOOT_STRING=\"$(SUCCESSFUL_BOOT_STRING)\" -ffreestanding -nostdlib -nostdinc -Wl,-N -Wl,-Ttext,0 -m32 + $(TARGET_CC) -o $@ $< -DTARGET_NTLDR=1 -DSUCCESSFUL_BOOT_STRING=\"$(SUCCESSFUL_BOOT_STRING)\" -ffreestanding -nostdlib -nostdinc -Wl,--build-id=none -Wl,-N -Wl,-Ttext,0 -m32 ntldr.bin: ntldr.elf $(OBJCOPY) -O binary --strip-unneeded -R .note -R .comment -R .note.gnu.build-id -R .reginfo -R .rel.dyn $< $@; multiboot2.elf: $(srcdir)/grub-core/tests/boot/kernel-i386.S - $(TARGET_CC) -o $@ $< -DSUCCESSFUL_BOOT_STRING=\"$(SUCCESSFUL_BOOT_STRING)\" -ffreestanding -nostdlib -nostdinc -Wl,-N -Wl,-Ttext,0x100000 -m32 -I$(srcdir)/include -DTARGET_MULTIBOOT2=1 + $(TARGET_CC) -o $@ $< -DSUCCESSFUL_BOOT_STRING=\"$(SUCCESSFUL_BOOT_STRING)\" -ffreestanding -nostdlib -nostdinc -Wl,--build-id=none -Wl,-N -Wl,-Ttext,0x100000 -m32 -I$(srcdir)/include -DTARGET_MULTIBOOT2=1 kfreebsd.init.x86_64: $(srcdir)/grub-core/tests/boot/kfreebsd.init-x86_64.S $(TARGET_CC) -o $@ $< -m64 -nostdlib -nostdinc -DSUCCESSFUL_BOOT_STRING=\"$(SUCCESSFUL_BOOT_STRING)\" && freebsd-brandelf -t FreeBSD $@ From f3fb7b36df4c729f001bc245a64304a5a34e30d6 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 18 Apr 2011 09:31:13 +0200 Subject: [PATCH 462/869] * util/grub-mkimage.c (generate_image): Update fwstart.img hash after performing the necessary test. --- ChangeLog | 5 +++++ util/grub-mkimage.c | 18 ++++++++++-------- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index 859f337ac..a29a5b694 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-04-18 Vladimir Serbinenko + + * util/grub-mkimage.c (generate_image): Update fwstart.img hash after + performing the necessary test. + 2011-04-17 Vladimir Serbinenko * Makefile.am (multiboot.elf): Add -Wl,--build-id=none. diff --git a/util/grub-mkimage.c b/util/grub-mkimage.c index 70c5ef6a9..c07f43af2 100644 --- a/util/grub-mkimage.c +++ b/util/grub-mkimage.c @@ -1174,14 +1174,16 @@ generate_image (const char *dir, char *prefix, FILE *out, char *mods[], sha512sum utility after compiling on Gnewsense. */ const grub_uint8_t fwstart_good_hash[] = - { 0x75, 0xbf, 0xa3, 0x0e, 0x7c, 0xd1, 0x03, 0x82, - 0xe1, 0x34, 0x55, 0xd7, 0x09, 0x1e, 0x6c, 0xcc, - 0xef, 0x08, 0x61, 0xc1, 0x3c, 0xd8, 0xc7, 0x9f, - 0xe8, 0x2d, 0x3d, 0xb2, 0xda, 0x41, 0xd3, 0x83, - 0xd7, 0xb8, 0xe3, 0xd7, 0x13, 0xec, 0x9b, 0xf6, - 0xf6, 0xae, 0x6b, 0x32, 0x29, 0xc1, 0x69, 0x82, - 0xfa, 0x65, 0x2d, 0x97, 0x3e, 0x83, 0x6e, 0x6c, - 0xce, 0x34, 0x10, 0x59, 0x74, 0x0e, 0x96, 0x26 }; + { + 0x9f, 0x7f, 0x79, 0x47, 0x68, 0x91, 0x61, 0xb3 + 0x16, 0x7b, 0xf0, 0x27, 0x1c, 0xf7, 0xaf, 0x05, + 0x6c, 0xc1, 0x6f, 0xd2, 0xe7, 0xd1, 0xe9, 0xec, + 0x08, 0x87, 0xe5, 0xc8, 0x29, 0xa2, 0x5b, 0x84, + 0xf8, 0xa6, 0xec, 0x08, 0xf7, 0xcb, 0x7b, 0x6c, + 0xfe, 0x01, 0xfd, 0x5d, 0xba, 0xbf, 0x0d, 0x0f, + 0x2e, 0xef, 0xed, 0x7b, 0xfe, 0xc9, 0x4a, 0x85, + 0xcf, 0xac, 0x20, 0xd7, 0x01, 0xc5, 0xc5, 0x9c + }; boot_path = grub_util_get_path (dir, "fwstart.img"); boot_size = grub_util_get_image_size (boot_path); From a5102d9433ca39c8f73615b757b2b35225c2d165 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 18 Apr 2011 17:47:21 +0200 Subject: [PATCH 463/869] * util/grub-mkimage.c (generate_image): Add forgotten comma. --- ChangeLog | 4 ++++ util/grub-mkimage.c | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index a29a5b694..f9cfcdb46 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2011-04-18 Vladimir Serbinenko + + * util/grub-mkimage.c (generate_image): Add forgotten comma. + 2011-04-18 Vladimir Serbinenko * util/grub-mkimage.c (generate_image): Update fwstart.img hash after diff --git a/util/grub-mkimage.c b/util/grub-mkimage.c index c07f43af2..2ba351596 100644 --- a/util/grub-mkimage.c +++ b/util/grub-mkimage.c @@ -1175,7 +1175,7 @@ generate_image (const char *dir, char *prefix, FILE *out, char *mods[], */ const grub_uint8_t fwstart_good_hash[] = { - 0x9f, 0x7f, 0x79, 0x47, 0x68, 0x91, 0x61, 0xb3 + 0x9f, 0x7f, 0x79, 0x47, 0x68, 0x91, 0x61, 0xb3, 0x16, 0x7b, 0xf0, 0x27, 0x1c, 0xf7, 0xaf, 0x05, 0x6c, 0xc1, 0x6f, 0xd2, 0xe7, 0xd1, 0xe9, 0xec, 0x08, 0x87, 0xe5, 0xc8, 0x29, 0xa2, 0x5b, 0x84, From 93a777e38840ad59105cd6552c9a787e61b6f338 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 18 Apr 2011 23:03:52 +0200 Subject: [PATCH 464/869] Complete 64-bit division support. * grub-core/kern/misc.c (grub_divmod64): Rename to ... (grub_divmod64_full): ... this. Support 64-bit divisor and reminder. * include/grub/misc.h (grub_divmod64): Rename to ... (grub_divmod64_full): ... this. (grub_divmod64): New inline function. --- ChangeLog | 10 ++++++++++ grub-core/kern/misc.c | 14 +++++++------- include/grub/misc.h | 16 ++++++++++++++-- 3 files changed, 31 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index f9cfcdb46..f46277405 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2011-04-18 Vladimir Serbinenko + + Complete 64-bit division support. + + * grub-core/kern/misc.c (grub_divmod64): Rename to ... + (grub_divmod64_full): ... this. Support 64-bit divisor and reminder. + * include/grub/misc.h (grub_divmod64): Rename to ... + (grub_divmod64_full): ... this. + (grub_divmod64): New inline function. + 2011-04-18 Vladimir Serbinenko * util/grub-mkimage.c (generate_image): Add forgotten comma. diff --git a/grub-core/kern/misc.c b/grub-core/kern/misc.c index 37ce8decd..1b4cdec66 100644 --- a/grub-core/kern/misc.c +++ b/grub-core/kern/misc.c @@ -597,23 +597,23 @@ grub_reverse (char *str) /* Divide N by D, return the quotient, and store the remainder in *R. */ grub_uint64_t -grub_divmod64 (grub_uint64_t n, grub_uint32_t d, grub_uint32_t *r) +grub_divmod64_full (grub_uint64_t n, grub_uint64_t d, grub_uint64_t *r) { /* This algorithm is typically implemented by hardware. The idea is to get the highest bit in N, 64 times, by keeping - upper(N * 2^i) = upper((Q * 10 + M) * 2^i), where upper + upper(N * 2^i) = (Q * D + M), where upper represents the high 64 bits in 128-bits space. */ unsigned bits = 64; - unsigned long long q = 0; - unsigned m = 0; + grub_uint64_t q = 0; + grub_uint64_t m = 0; /* Skip the slow computation if 32-bit arithmetic is possible. */ - if (n < 0xffffffff) + if (n < 0xffffffff && d < 0xffffffff) { if (r) - *r = ((grub_uint32_t) n) % d; + *r = ((grub_uint32_t) n) % (grub_uint32_t) d; - return ((grub_uint32_t) n) / d; + return ((grub_uint32_t) n) / (grub_uint32_t) d; } while (bits--) diff --git a/include/grub/misc.h b/include/grub/misc.h index 6fcaa148b..80588be33 100644 --- a/include/grub/misc.h +++ b/include/grub/misc.h @@ -287,8 +287,20 @@ char *EXPORT_FUNC(grub_xasprintf) (const char *fmt, ...) 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_abort) (void) __attribute__ ((noreturn)); -grub_uint64_t EXPORT_FUNC(grub_divmod64) (grub_uint64_t n, - grub_uint32_t d, grub_uint32_t *r); +grub_uint64_t EXPORT_FUNC(grub_divmod64_full) (grub_uint64_t n, + grub_uint64_t d, + grub_uint64_t *r); +static inline grub_uint64_t grub_divmod64 (grub_uint64_t n, + grub_uint32_t d, + grub_uint32_t *r) +{ + grub_uint64_t ret, rr; + + ret = grub_divmod64_full (n, d, &rr); + if (r) + *r = rr; + return ret; +} #if NEED_ENABLE_EXECUTE_STACK && !defined(GRUB_UTIL) void EXPORT_FUNC(__enable_execute_stack) (void *addr); From 34faa5955af9527d6d12cca5bf22b613b98586a0 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 18 Apr 2011 23:10:19 +0200 Subject: [PATCH 465/869] * grub-core/fs/btrfs.c (grub_btrfs_read_logical): Support huge chunks. * include/grub/err.h (grub_err_t): New enum value GRUB_ERR_BUG. --- ChangeLog | 6 ++++++ grub-core/fs/btrfs.c | 29 ++++++++++++++++++++--------- include/grub/err.h | 3 ++- 3 files changed, 28 insertions(+), 10 deletions(-) diff --git a/ChangeLog b/ChangeLog index f46277405..676c374aa 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2011-04-18 Vladimir Serbinenko + + * grub-core/fs/btrfs.c (grub_btrfs_read_logical): Support huge + chunks. + * include/grub/err.h (grub_err_t): New enum value GRUB_ERR_BUG. + 2011-04-18 Vladimir Serbinenko Complete 64-bit division support. diff --git a/grub-core/fs/btrfs.c b/grub-core/fs/btrfs.c index bbb326b98..42aa257d9 100644 --- a/grub-core/fs/btrfs.c +++ b/grub-core/fs/btrfs.c @@ -588,7 +588,7 @@ grub_btrfs_read_logical (struct grub_btrfs_data *data, grub_uint8_t *ptr; struct grub_btrfs_key *key; struct grub_btrfs_chunk_item *chunk; - grub_ssize_t csize; + grub_uint64_t csize; grub_err_t err; struct grub_btrfs_key key_out; int challoc = 0; @@ -648,11 +648,18 @@ grub_btrfs_read_logical (struct grub_btrfs_data *data, chunk_found: { grub_uint32_t stripen; - grub_uint32_t stripe_offset; + grub_uint64_t stripe_offset; grub_uint64_t off = addr - grub_le_to_cpu64 (key->offset); unsigned redundancy = 1; unsigned i, j; + if (grub_le_to_cpu64 (chunk->size) <= off) + { + grub_dprintf ("btrfs", "no chunk\n"); + return grub_error (GRUB_ERR_BAD_FS, + "couldn't find the chunk descriptor"); + } + grub_dprintf ("btrfs", "chunk 0x%" PRIxGRUB_UINT64_T "+0x%" PRIxGRUB_UINT64_T " (%d stripes (%d substripes) of %" @@ -668,17 +675,19 @@ grub_btrfs_read_logical (struct grub_btrfs_data *data, { case GRUB_BTRFS_CHUNK_TYPE_SINGLE: { - grub_uint32_t stripe_length; - stripe_length = grub_divmod64 (grub_le_to_cpu64 (chunk->size), - grub_le_to_cpu16 (chunk->nstripes), - NULL); - stripen = grub_divmod64 (off, stripe_length, &stripe_offset); + grub_uint64_t stripe_length; + grub_dprintf ("btrfs", "single\n"); + stripe_length = grub_divmod64_full (grub_le_to_cpu64 (chunk->size), + grub_le_to_cpu16 (chunk->nstripes), + NULL); + stripen = grub_divmod64_full (off, stripe_length, &stripe_offset); csize = (stripen + 1) * stripe_length - off; break; } case GRUB_BTRFS_CHUNK_TYPE_DUPLICATED: case GRUB_BTRFS_CHUNK_TYPE_RAID1: { + grub_dprintf ("btrfs", "RAID1\n"); stripen = 0; stripe_offset = off; csize = grub_le_to_cpu64 (chunk->size) - off; @@ -689,6 +698,7 @@ grub_btrfs_read_logical (struct grub_btrfs_data *data, { grub_uint64_t middle, high; grub_uint32_t low; + grub_dprintf ("btrfs", "RAID0\n"); middle = grub_divmod64 (off, grub_le_to_cpu64 (chunk->stripe_length), &low); @@ -721,12 +731,13 @@ grub_btrfs_read_logical (struct grub_btrfs_data *data, break; } default: + grub_dprintf ("btrfs", "unsupported RAID\n"); return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, "unsupported RAID flags %" PRIxGRUB_UINT64_T, grub_le_to_cpu64 (chunk->type)); } - if (csize <= 0) - return grub_error (GRUB_ERR_BAD_FS, + if (csize == 0) + return grub_error (GRUB_ERR_BUG, "couldn't find the chunk descriptor"); if ((grub_size_t) csize > size) csize = size; diff --git a/include/grub/err.h b/include/grub/err.h index 22334038d..69bc6ec79 100644 --- a/include/grub/err.h +++ b/include/grub/err.h @@ -55,7 +55,8 @@ typedef enum GRUB_ERR_TIMEOUT, GRUB_ERR_IO, GRUB_ERR_ACCESS_DENIED, - GRUB_ERR_EXTRACTOR + GRUB_ERR_EXTRACTOR, + GRUB_ERR_BUG } grub_err_t; From e74b3947af1d11b8279706e07302ed0debe82779 Mon Sep 17 00:00:00 2001 From: Endres Puschner Date: Mon, 18 Apr 2011 23:24:41 +0200 Subject: [PATCH 466/869] * grub-core/gfxmenu/icon_manager.c (grub_gfxmenu_icon_manager_get_icon): Don't skip first class. --- ChangeLog | 5 +++++ grub-core/gfxmenu/icon_manager.c | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 676c374aa..8c00f7849 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-04-18 Endres Puschner + + * grub-core/gfxmenu/icon_manager.c (grub_gfxmenu_icon_manager_get_icon): + Don't skip first class. + 2011-04-18 Vladimir Serbinenko * grub-core/fs/btrfs.c (grub_btrfs_read_logical): Support huge diff --git a/grub-core/gfxmenu/icon_manager.c b/grub-core/gfxmenu/icon_manager.c index 0c304ede0..6990d05d4 100644 --- a/grub-core/gfxmenu/icon_manager.c +++ b/grub-core/gfxmenu/icon_manager.c @@ -257,7 +257,7 @@ grub_gfxmenu_icon_manager_get_icon (grub_gfxmenu_icon_manager_t mgr, /* Try each class in succession. */ icon = 0; - for (c = entry->classes->next; c && ! icon; c = c->next) + for (c = entry->classes; c && ! icon; c = c->next) icon = get_icon_by_class (mgr, c->name); return icon; } From abc474ef4bb79cd21e5510c302309ab87008ef65 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Tue, 19 Apr 2011 00:44:53 +0200 Subject: [PATCH 467/869] Take into account the decorations the computing menu entry width. * grub-core/gfxmenu/widget-box.c (get_border_width): New function. (grub_gfxmenu_create_box): Register get_border_width. * grub-core/gfxmenu/gui_list.c (draw_menu): Use get_border_width if available. * include/grub/gfxwidgets.h (grub_gfxmenu_box): New member get_border_width. --- ChangeLog | 11 +++++++++++ grub-core/gfxmenu/gui_list.c | 6 ++++-- grub-core/gfxmenu/widget-box.c | 9 +++++++++ include/grub/gfxwidgets.h | 1 + 4 files changed, 25 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 8c00f7849..79d868f86 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2011-04-19 Vladimir Serbinenko + + Take into account the decorations the computing menu entry width. + + * grub-core/gfxmenu/widget-box.c (get_border_width): New function. + (grub_gfxmenu_create_box): Register get_border_width. + * grub-core/gfxmenu/gui_list.c (draw_menu): Use get_border_width + if available. + * include/grub/gfxwidgets.h (grub_gfxmenu_box): New member + get_border_width. + 2011-04-18 Endres Puschner * grub-core/gfxmenu/icon_manager.c (grub_gfxmenu_icon_manager_get_icon): diff --git a/grub-core/gfxmenu/gui_list.c b/grub-core/gfxmenu/gui_list.c index b6b07dfd6..e5d6fc2a1 100644 --- a/grub-core/gfxmenu/gui_list.c +++ b/grub-core/gfxmenu/gui_list.c @@ -248,8 +248,10 @@ draw_menu (list_impl_t self, int num_shown_items) if (is_selected) { - selbox->set_content_size (selbox, oviewport.width - 2 * boxpad - 2, - item_height - 1); + int cwidth = oviewport.width - 2 * boxpad - 2; + if (selbox->get_border_width) + cwidth -= selbox->get_border_width (selbox); + selbox->set_content_size (selbox, cwidth, item_height - 1); selbox->draw (selbox, 0, item_top - sel_toppad); } diff --git a/grub-core/gfxmenu/widget-box.c b/grub-core/gfxmenu/widget-box.c index 244fe1e6c..41ca7f536 100644 --- a/grub-core/gfxmenu/widget-box.c +++ b/grub-core/gfxmenu/widget-box.c @@ -178,6 +178,13 @@ set_content_size (grub_gfxmenu_box_t self, return; } +static int +get_border_width (grub_gfxmenu_box_t self) +{ + return (get_width (self->raw_pixmaps[BOX_PIXMAP_E]) + + get_width (self->raw_pixmaps[BOX_PIXMAP_W])); +} + static int get_left_pad (grub_gfxmenu_box_t self) { @@ -288,6 +295,8 @@ grub_gfxmenu_create_box (const char *pixmaps_prefix, box->draw = draw; box->set_content_size = set_content_size; + box->get_border_width = get_border_width; + box->get_left_pad = get_left_pad; box->get_top_pad = get_top_pad; box->get_right_pad = get_right_pad; diff --git a/include/grub/gfxwidgets.h b/include/grub/gfxwidgets.h index f9678bf9e..8ce666c5c 100644 --- a/include/grub/gfxwidgets.h +++ b/include/grub/gfxwidgets.h @@ -36,6 +36,7 @@ struct grub_gfxmenu_box void (*draw) (grub_gfxmenu_box_t self, int x, int y); void (*set_content_size) (grub_gfxmenu_box_t self, int width, int height); + int (*get_border_width) (grub_gfxmenu_box_t self); int (*get_left_pad) (grub_gfxmenu_box_t self); int (*get_top_pad) (grub_gfxmenu_box_t self); int (*get_right_pad) (grub_gfxmenu_box_t self); From bba79a1502b433c013ac034ed931da93f30802d4 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Tue, 19 Apr 2011 22:31:50 +0200 Subject: [PATCH 468/869] * grub-core/term/gfxterm.c (grub_gfxterm_fullscreen): Preserve previous bitmap. (grub_gfxterm_term_init): Likewise. --- ChangeLog | 6 ++++++ grub-core/term/gfxterm.c | 7 ------- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index 79d868f86..2eade534d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2011-04-19 Vladimir Serbinenko + + * grub-core/term/gfxterm.c (grub_gfxterm_fullscreen): Preserve previous + bitmap. + (grub_gfxterm_term_init): Likewise. + 2011-04-19 Vladimir Serbinenko Take into account the decorations the computing menu entry width. diff --git a/grub-core/term/gfxterm.c b/grub-core/term/gfxterm.c index 0ade65f27..e58d6722d 100644 --- a/grub-core/term/gfxterm.c +++ b/grub-core/term/gfxterm.c @@ -345,7 +345,6 @@ grub_gfxterm_fullscreen (void) grub_video_swap_buffers (); grub_video_fill_rect (color, 0, 0, mode_info.width, mode_info.height); } - bitmap = 0; /* Select the font to use. */ font_name = grub_env_get ("gfxterm_font"); @@ -394,12 +393,6 @@ grub_gfxterm_term_init (struct grub_term_output *term __attribute__ ((unused))) static void destroy_window (void) { - if (bitmap) - { - grub_video_bitmap_destroy (bitmap); - bitmap = 0; - } - repaint_callback = 0; grub_virtual_screen_free (); } From e8f28d4c0e8af4103e50776a0614cd2c73a98136 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Tue, 19 Apr 2011 22:39:14 +0200 Subject: [PATCH 469/869] * grub-core/kern/emu/hostdisk.c (grub_util_biosdisk_flush): New function. (grub_util_biosdisk_close): Use grub_util_biosdisk_flush. * include/grub/emu/hostdisk.h (grub_util_biosdisk_flush): New proto. * util/grub-setup.c (setup): Use grub_util_biosdisk_flush. --- ChangeLog | 8 ++++++++ grub-core/kern/emu/hostdisk.c | 29 ++++++++++++++++++++++------- include/grub/emu/hostdisk.h | 1 + util/grub-setup.c | 10 ++++------ 4 files changed, 35 insertions(+), 13 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2eade534d..1eff73ca3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2011-04-19 Vladimir Serbinenko + + * grub-core/kern/emu/hostdisk.c (grub_util_biosdisk_flush): + New function. + (grub_util_biosdisk_close): Use grub_util_biosdisk_flush. + * include/grub/emu/hostdisk.h (grub_util_biosdisk_flush): New proto. + * util/grub-setup.c (setup): Use grub_util_biosdisk_flush. + 2011-04-19 Vladimir Serbinenko * grub-core/term/gfxterm.c (grub_gfxterm_fullscreen): Preserve previous diff --git a/grub-core/kern/emu/hostdisk.c b/grub-core/kern/emu/hostdisk.c index f01e21aa0..63bca37ee 100644 --- a/grub-core/kern/emu/hostdisk.c +++ b/grub-core/kern/emu/hostdisk.c @@ -945,6 +945,27 @@ grub_util_biosdisk_write (grub_disk_t disk, grub_disk_addr_t sector, return grub_errno; } +grub_err_t +grub_util_biosdisk_flush (struct grub_disk *disk) +{ + struct grub_util_biosdisk_data *data = disk->data; + + if (disk->dev->id != GRUB_DISK_DEVICE_BIOSDISK_ID) + return GRUB_ERR_NONE; + if (data->fd == -1) + { + data->fd = open_device (disk, 0, O_RDONLY); + if (data->fd < 0) + return grub_errno; + } + fsync (data->fd); +#ifdef __linux__ + if (data->is_disk) + ioctl (data->fd, BLKFLSBUF, 0); +#endif + return GRUB_ERR_NONE; +} + static void grub_util_biosdisk_close (struct grub_disk *disk) { @@ -954,13 +975,7 @@ grub_util_biosdisk_close (struct grub_disk *disk) if (data->fd != -1) { if (data->access_mode == O_RDWR || data->access_mode == O_WRONLY) - { - fsync (data->fd); -#ifdef __linux__ - if (data->is_disk) - ioctl (data->fd, BLKFLSBUF, 0); -#endif - } + grub_util_biosdisk_flush (disk); close (data->fd); } free (data); diff --git a/include/grub/emu/hostdisk.h b/include/grub/emu/hostdisk.h index d8cc02e14..842dff496 100644 --- a/include/grub/emu/hostdisk.h +++ b/include/grub/emu/hostdisk.h @@ -28,5 +28,6 @@ char *grub_util_biosdisk_get_grub_dev (const char *os_dev); const char *grub_util_biosdisk_get_osdev (grub_disk_t disk); int grub_util_biosdisk_is_present (const char *name); int grub_util_biosdisk_is_floppy (grub_disk_t disk); +grub_err_t grub_util_biosdisk_flush (struct grub_disk *disk); #endif /* ! GRUB_BIOSDISK_MACHINE_UTIL_HEADER */ diff --git a/util/grub-setup.c b/util/grub-setup.c index ed2d63fdd..7d47fa654 100644 --- a/util/grub-setup.c +++ b/util/grub-setup.c @@ -520,9 +520,7 @@ unable_to_embed: core_path_dev = grub_make_system_path_relative_to_its_root (core_path_dev_full); free (core_path_dev_full); - /* It is a Good Thing to sync two times. */ - sync (); - sync (); + grub_util_biosdisk_flush (root_dev->disk); #define MAX_TRIES 5 @@ -583,7 +581,7 @@ unable_to_embed: grub_util_info ("error message = %s", grub_errmsg); grub_errno = GRUB_ERR_NONE; - sync (); + grub_util_biosdisk_flush (root_dev->disk); sleep (1); } @@ -674,8 +672,8 @@ unable_to_embed: grub_util_error ("%s", grub_errmsg); - /* Sync is a Good Thing. */ - sync (); + grub_util_biosdisk_flush (root_dev->disk); + grub_util_biosdisk_flush (dest_dev->disk); free (core_path); free (core_img); From 0624551c2286f9ce94f6c9a24a66da6f60dbe08b Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 20 Apr 2011 01:32:21 +0200 Subject: [PATCH 470/869] * grub-core/lib/efi/datetime.c: Add missing GRUB_MOD_LICENSE. * grub-core/lib/efi/datetime.c: Likewise. --- ChangeLog | 5 +++++ grub-core/lib/efi/datetime.c | 3 +++ grub-core/lib/ieee1275/datetime.c | 3 +++ 3 files changed, 11 insertions(+) diff --git a/ChangeLog b/ChangeLog index 1eff73ca3..877186e23 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-04-20 Vladimir Serbinenko + + * grub-core/lib/efi/datetime.c: Add missing GRUB_MOD_LICENSE. + * grub-core/lib/efi/datetime.c: Likewise. + 2011-04-19 Vladimir Serbinenko * grub-core/kern/emu/hostdisk.c (grub_util_biosdisk_flush): diff --git a/grub-core/lib/efi/datetime.c b/grub-core/lib/efi/datetime.c index 0a91c345a..0fd1b5fbd 100644 --- a/grub-core/lib/efi/datetime.c +++ b/grub-core/lib/efi/datetime.c @@ -22,6 +22,9 @@ #include #include #include +#include + +GRUB_MOD_LICENSE ("GPLv3+"); grub_err_t grub_get_datetime (struct grub_datetime *datetime) diff --git a/grub-core/lib/ieee1275/datetime.c b/grub-core/lib/ieee1275/datetime.c index 7e6f8d1f1..4105c639b 100644 --- a/grub-core/lib/ieee1275/datetime.c +++ b/grub-core/lib/ieee1275/datetime.c @@ -20,6 +20,9 @@ #include #include #include +#include + +GRUB_MOD_LICENSE ("GPLv3+"); static char *rtc = 0; From d97e7b5935896a7c5bfe0592385bf19a77f97560 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 20 Apr 2011 01:37:48 +0200 Subject: [PATCH 471/869] * include/grub/dl.h [ASM_FILE]: Adapt for assembly. * grub-core/lib/i386/setjmp.S: Add missing GRUB_MOD_LICENSE. * grub-core/lib/x86_64/setjmp.S: Likewise. * grub-core/lib/mips/setjmp.S: Likewise. * grub-core/lib/powerpc/setjmp.S: Likewise. * grub-core/lib/sparc64/setjmp.S: Likewise. --- ChangeLog | 9 +++++++++ grub-core/lib/i386/setjmp.S | 3 +++ grub-core/lib/mips/setjmp.S | 3 +++ grub-core/lib/powerpc/setjmp.S | 3 +++ grub-core/lib/sparc64/setjmp.S | 3 +++ grub-core/lib/x86_64/setjmp.S | 3 +++ include/grub/dl.h | 31 ++++++++++++++++++++++++++++--- 7 files changed, 52 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 877186e23..c78ae8cab 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2011-04-20 Vladimir Serbinenko + + * include/grub/dl.h [ASM_FILE]: Adapt for assembly. + * grub-core/lib/i386/setjmp.S: Add missing GRUB_MOD_LICENSE. + * grub-core/lib/x86_64/setjmp.S: Likewise. + * grub-core/lib/mips/setjmp.S: Likewise. + * grub-core/lib/powerpc/setjmp.S: Likewise. + * grub-core/lib/sparc64/setjmp.S: Likewise. + 2011-04-20 Vladimir Serbinenko * grub-core/lib/efi/datetime.c: Add missing GRUB_MOD_LICENSE. diff --git a/grub-core/lib/i386/setjmp.S b/grub-core/lib/i386/setjmp.S index a2002ae3d..5b7aa158b 100644 --- a/grub-core/lib/i386/setjmp.S +++ b/grub-core/lib/i386/setjmp.S @@ -17,9 +17,12 @@ */ #include +#include .file "setjmp.S" +GRUB_MOD_LICENSE ("GPLv3+") + .text /* diff --git a/grub-core/lib/mips/setjmp.S b/grub-core/lib/mips/setjmp.S index 8ab6222c4..8259c9d22 100644 --- a/grub-core/lib/mips/setjmp.S +++ b/grub-core/lib/mips/setjmp.S @@ -17,9 +17,12 @@ */ #include +#include .file "setjmp.S" +GRUB_MOD_LICENSE ("GPLv3+") + .text /* diff --git a/grub-core/lib/powerpc/setjmp.S b/grub-core/lib/powerpc/setjmp.S index 25cbaa3e9..8c7540e3c 100644 --- a/grub-core/lib/powerpc/setjmp.S +++ b/grub-core/lib/powerpc/setjmp.S @@ -17,9 +17,12 @@ */ #include +#include .file "setjmp.S" +GRUB_MOD_LICENSE ("GPLv3+") + .text /* diff --git a/grub-core/lib/sparc64/setjmp.S b/grub-core/lib/sparc64/setjmp.S index 0e23ecfa1..5c2ec2cf3 100644 --- a/grub-core/lib/sparc64/setjmp.S +++ b/grub-core/lib/sparc64/setjmp.S @@ -17,9 +17,12 @@ */ #include +#include .file "setjmp.S" +GRUB_MOD_LICENSE ("GPLv3+") + .text /* diff --git a/grub-core/lib/x86_64/setjmp.S b/grub-core/lib/x86_64/setjmp.S index 621b09b93..b1f1b22cb 100644 --- a/grub-core/lib/x86_64/setjmp.S +++ b/grub-core/lib/x86_64/setjmp.S @@ -17,9 +17,12 @@ */ #include +#include .file "setjmp.S" +GRUB_MOD_LICENSE ("GPLv3+") + .text /* diff --git a/include/grub/dl.h b/include/grub/dl.h index 71db90c8b..6f23f7d63 100644 --- a/include/grub/dl.h +++ b/include/grub/dl.h @@ -21,15 +21,18 @@ #define GRUB_DL_H 1 #include +#ifndef ASM_FILE #include #include #include +#endif /* * Macros GRUB_MOD_INIT and GRUB_MOD_FINI are also used by build rules * to collect module names, so we define them only when they are not * defined already. */ +#ifndef ASM_FILE #ifndef GRUB_MOD_INIT #define GRUB_MOD_INIT(name) \ @@ -66,10 +69,20 @@ __asm__ (".section .moddeps\n.asciz \"" #name "\"\n") #endif +#endif + +#ifndef ASM_FILE #ifdef APPLE_CC -#define GRUB_MOD_SECTION(x) "_" x ", _" x "" +#define GRUB_MOD_SECTION(x) "_" #x ", _" #x "" #else -#define GRUB_MOD_SECTION(x) "." x +#define GRUB_MOD_SECTION(x) "." #x +#endif +#else +#ifdef APPLE_CC +#define GRUB_MOD_SECTION(x) _ ## x , _ ##x +#else +#define GRUB_MOD_SECTION(x) . ## x +#endif #endif /* Me, Vladimir Serbinenko, hereby I add this module check as per new @@ -80,8 +93,16 @@ __asm__ (".section .moddeps\n.asciz \"" #name "\"\n") constitutes linking) and GRUB core being licensed under GPLv3+. Be sure to understand your license obligations. */ +#ifndef ASM_FILE #define GRUB_MOD_LICENSE(license) \ - static char grub_module_license[] __attribute__ ((section (GRUB_MOD_SECTION ("module_license")), used)) = "LICENSE=" license; + static char grub_module_license[] __attribute__ ((section (GRUB_MOD_SECTION (module_license)), used)) = "LICENSE=" license; +#else +#define GRUB_MOD_LICENSE(license) \ + .section GRUB_MOD_SECTION(module_license), "a"; \ + .ascii "LICENSE="; \ + .ascii license; \ + .byte 0 +#endif /* Under GPL license obligations you have to distribute your module under GPLv3(+). However, you can also distribute the same code under @@ -89,6 +110,8 @@ __asm__ (".section .moddeps\n.asciz \"" #name "\"\n") */ #define GRUB_MOD_DUAL_LICENSE(x) +#ifndef ASM_FILE + struct grub_dl_segment { struct grub_dl_segment *next; @@ -143,4 +166,6 @@ grub_err_t grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr); void grub_arch_dl_init_linker (void); #endif +#endif + #endif /* ! GRUB_DL_H */ From 9b710a888e80862a18449bc9b5a31e2148da56c6 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 20 Apr 2011 09:23:55 +0200 Subject: [PATCH 472/869] * configure.ac: Bump version to 1.99~rc2. --- ChangeLog | 4 ++++ configure.ac | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index c78ae8cab..083d22ec5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2011-04-20 Vladimir Serbinenko + + * configure.ac: Bump version to 1.99~rc2. + 2011-04-20 Vladimir Serbinenko * include/grub/dl.h [ASM_FILE]: Adapt for assembly. diff --git a/configure.ac b/configure.ac index f9e974bca..811bd992d 100644 --- a/configure.ac +++ b/configure.ac @@ -32,7 +32,7 @@ dnl type, so there is no conflict. Variables with the prefix "TARGET_" dnl (such as TARGET_CC, TARGET_CFLAGS, etc.) are used for the target dnl type. -AC_INIT([GRUB],[1.99~rc1],[bug-grub@gnu.org]) +AC_INIT([GRUB],[1.99~rc2],[bug-grub@gnu.org]) AC_CONFIG_AUX_DIR([build-aux]) From b13f79a427b6ae6c1405c48b8cf57a1e99de16f9 Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Thu, 21 Apr 2011 00:07:22 +0100 Subject: [PATCH 473/869] Fix stack pointer handling in 16-bit relocator. * grub-core/lib/i386/relocator16.S (grub_relocator16_start): Move grub_relocator16_sp to %esp rather than %ss, and zero-extend it. Fixes Ubuntu bug #683904. --- ChangeLog | 8 ++++++++ grub-core/lib/i386/relocator16.S | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 083d22ec5..98d3b0ea8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2011-04-21 Colin Watson + + Fix stack pointer handling in 16-bit relocator. + + * grub-core/lib/i386/relocator16.S (grub_relocator16_start): Move + grub_relocator16_sp to %esp rather than %ss, and zero-extend it. + Fixes Ubuntu bug #683904. + 2011-04-20 Vladimir Serbinenko * configure.ac: Bump version to 1.99~rc2. diff --git a/grub-core/lib/i386/relocator16.S b/grub-core/lib/i386/relocator16.S index c3768f4eb..982415de4 100644 --- a/grub-core/lib/i386/relocator16.S +++ b/grub-core/lib/i386/relocator16.S @@ -130,7 +130,7 @@ VARIABLE(grub_relocator16_ss) .byte 0xb8 VARIABLE(grub_relocator16_sp) .word 0 - movw %ax, %ss + movzwl %ax, %esp /* movw imm32, %edx. */ .byte 0x66, 0xba From 7217f315d375c678d4f00a4601923769b9b5a6ad Mon Sep 17 00:00:00 2001 From: Michael Gorven Date: Thu, 21 Apr 2011 11:14:29 +0200 Subject: [PATCH 474/869] LUKS support based on work of Michael Gorven with some code from Clemens Fruhwirth and heavily cleaned up by me (phcoder) Also-By: Clemens Fruhwirth Also-By: Vladimir Serbinenko --- grub-core/Makefile.core.def | 6 + grub-core/disk/AFSplitter.c | 104 ++++++ grub-core/disk/luks.c | 700 ++++++++++++++++++++++++++++++++++++ 3 files changed, 810 insertions(+) create mode 100644 grub-core/disk/AFSplitter.c create mode 100644 grub-core/disk/luks.c diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def index f4d38149d..b8c996ba7 100644 --- a/grub-core/Makefile.core.def +++ b/grub-core/Makefile.core.def @@ -767,6 +767,12 @@ module = { common = disk/loopback.c; }; +module = { + name = luks; + common = disk/luks.c; + common = disk/AFSplitter.c; +}; + module = { name = lvm; common = disk/lvm.c; diff --git a/grub-core/disk/AFSplitter.c b/grub-core/disk/AFSplitter.c new file mode 100644 index 000000000..6c3dc488e --- /dev/null +++ b/grub-core/disk/AFSplitter.c @@ -0,0 +1,104 @@ +/* + * AFsplitter - Anti forensic information splitter + * Copyright 2004, Clemens Fruhwirth + * + * AFsplitter diffuses information over a large stripe of data, + * therefor supporting secure data destruction. + * + * This program is grub_free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the grub_free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 Library General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the grub_free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +gcry_err_code_t AF_merge (const gcry_md_spec_t * hash, grub_uint8_t * src, + grub_uint8_t * dst, grub_size_t blocksize, + grub_size_t blocknumbers); +static void diffuse (const gcry_md_spec_t * hash, grub_uint8_t * src, + grub_uint8_t * dst, grub_size_t size); +gcry_err_code_t AF_split (const gcry_md_spec_t * hash, grub_uint8_t * src, + grub_uint8_t * dst, grub_size_t blocksize, + grub_size_t blocknumbers); + + +static void +diffuse (const gcry_md_spec_t * hash, grub_uint8_t * src, + grub_uint8_t * dst, grub_size_t size) +{ + grub_size_t i; + grub_uint32_t IV; /* host byte order independend hash IV */ + + grub_size_t fullblocks = size / hash->mdlen; + int padding = size % hash->mdlen; + grub_uint8_t final[hash->mdlen]; + grub_uint8_t temp[sizeof (IV) + hash->mdlen]; + + /* hash block the whole data set with different IVs to produce + * more than just a single data block + */ + for (i = 0; i < fullblocks; i++) + { + IV = grub_cpu_to_be32 (i); + grub_memcpy (temp, &IV, sizeof (IV)); + grub_memcpy (temp + sizeof (IV), src + hash->mdlen * i, hash->mdlen); + grub_crypto_hash (hash, dst + hash->mdlen * i, temp, + sizeof (IV) + hash->mdlen); + } + + if (padding) + { + IV = grub_cpu_to_be32 (i); + grub_memcpy (temp, &IV, sizeof (IV)); + grub_memcpy (temp + sizeof (IV), src + hash->mdlen * i, padding); + grub_crypto_hash (hash, final, temp, sizeof (IV) + padding); + grub_memcpy (dst + hash->mdlen * i, final, padding); + } +} + +/** + * Merges the splitted master key stored on disk into the original key + */ +gcry_err_code_t +AF_merge (const gcry_md_spec_t * hash, grub_uint8_t * src, grub_uint8_t * dst, + grub_size_t blocksize, grub_size_t blocknumbers) +{ + grub_size_t i; + grub_uint8_t *bufblock; + + bufblock = grub_zalloc (blocksize); + if (bufblock == NULL) + return GPG_ERR_OUT_OF_MEMORY; + + grub_memset (bufblock, 0, blocksize); + for (i = 0; i < blocknumbers - 1; i++) + { + grub_crypto_xor (bufblock, src + (blocksize * i), bufblock, blocksize); + diffuse (hash, bufblock, bufblock, blocksize); + } + grub_crypto_xor (dst, src + (i * blocksize), bufblock, blocksize); + + grub_free (bufblock); + return GPG_ERR_NO_ERROR; +} diff --git a/grub-core/disk/luks.c b/grub-core/disk/luks.c new file mode 100644 index 000000000..47d10d63c --- /dev/null +++ b/grub-core/disk/luks.c @@ -0,0 +1,700 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2003,2007,2010,2011 Free Software Foundation, Inc. + * + * GRUB is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see . + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +GRUB_MOD_LICENSE ("GPLv3+"); + +#define MAX_PASSPHRASE 256 + +#define LUKS_KEY_ENABLED 0x00AC71F3 +#define LUKS_STRIPES 4000 + +/* On disk LUKS header */ +struct grub_luks_phdr +{ + grub_uint8_t magic[6]; +#define LUKS_MAGIC "LUKS\xBA\xBE" + grub_uint16_t version; + char cipherName[32]; + char cipherMode[32]; + char hashSpec[32]; + grub_uint32_t payloadOffset; + grub_uint32_t keyBytes; + grub_uint8_t mkDigest[20]; + grub_uint8_t mkDigestSalt[32]; + grub_uint32_t mkDigestIterations; + grub_uint8_t uuid[40]; + struct + { + grub_uint32_t active; + grub_uint32_t passwordIterations; + grub_uint8_t passwordSalt[32]; + grub_uint32_t keyMaterialOffset; + grub_uint32_t stripes; + } keyblock[8]; +} __attribute__ ((packed)); + +typedef struct grub_luks_phdr *grub_luks_phdr_t; + +typedef enum +{ + GRUB_LUKS_MODE_ECB, + GRUB_LUKS_MODE_CBC_PLAIN, + GRUB_LUKS_MODE_CBC_ESSIV +} +luks_mode_t; + +struct grub_luks +{ + char *devname, *source; + grub_uint32_t offset; + grub_disk_t source_disk; + int ref; + grub_crypto_cipher_handle_t cipher; + grub_crypto_cipher_handle_t essiv_cipher; + luks_mode_t mode; + int id; + struct grub_luks *next; +}; +typedef struct grub_luks *grub_luks_t; + +static grub_luks_t luks_list = NULL; +static grub_uint8_t n = 0; + +gcry_err_code_t AF_merge (const gcry_md_spec_t * hash, grub_uint8_t * src, + grub_uint8_t * dst, grub_size_t blocksize, + grub_size_t blocknumbers); + +static const struct grub_arg_option options[] = + { + {"uuid", 'u', 0, N_("Mount by UUID."), 0, 0}, + {0, 0, 0, 0, 0, 0} + }; + +static gcry_err_code_t +luks_decrypt (grub_crypto_cipher_handle_t cipher, luks_mode_t mode, + grub_uint8_t * data, grub_size_t len, + grub_size_t sector, grub_crypto_cipher_handle_t essiv_cipher) +{ + grub_size_t i; + gcry_err_code_t err; + + switch (mode) + { + case GRUB_LUKS_MODE_ECB: + return grub_crypto_ecb_decrypt (cipher, data, data, len); + + case GRUB_LUKS_MODE_CBC_PLAIN: + for (i = 0; i < len; i += GRUB_DISK_SECTOR_SIZE) + { + grub_uint32_t iv[(cipher->cipher->blocksize + + sizeof (grub_uint32_t) - 1) + / sizeof (grub_uint32_t)]; + grub_memset (iv, 0, cipher->cipher->blocksize); + iv[0] = grub_cpu_to_le32 (sector & 0xFFFFFFFF); + err = grub_crypto_cbc_decrypt (cipher, data + i, data + i, + GRUB_DISK_SECTOR_SIZE, iv); + if (err) + return err; + sector++; + } + return GPG_ERR_NO_ERROR; + + case GRUB_LUKS_MODE_CBC_ESSIV: + for (i = 0; i < len; i += GRUB_DISK_SECTOR_SIZE) + { + grub_uint32_t iv[(cipher->cipher->blocksize + + sizeof (grub_uint32_t) - 1) + / sizeof (grub_uint32_t)]; + grub_memset (iv, 0, cipher->cipher->blocksize); + iv[0] = grub_cpu_to_le32 (sector & 0xFFFFFFFF); + err = + grub_crypto_ecb_encrypt (essiv_cipher, iv, iv, + cipher->cipher->blocksize); + if (err) + return err; + err = grub_crypto_cbc_decrypt (cipher, data + i, data + i, + GRUB_DISK_SECTOR_SIZE, iv); + if (err) + return err; + sector++; + } + return GPG_ERR_NO_ERROR; + + default: + return GPG_ERR_NOT_IMPLEMENTED; + } +} + +static int check_uuid, have_it; +static char *uuid; + +static grub_err_t +grub_luks_scan_device_real (const char *name) +{ + grub_disk_t source; + grub_err_t err; + grub_luks_t newdev; + struct grub_luks_phdr header; + grub_crypto_cipher_handle_t cipher = NULL, essiv_cipher = NULL; + const gcry_md_spec_t *hash = NULL, *essiv_hash = NULL; + grub_size_t keysize; + /* GCC thinks we may use this variable uninitialised. Silence the warning. */ + grub_size_t essiv_keysize = 0; + grub_uint8_t *hashed_key = NULL; + luks_mode_t mode; + grub_uint8_t *split_key = NULL; + unsigned i; + grub_size_t length; + const struct gcry_cipher_spec *ciph; + char passphrase[MAX_PASSPHRASE] = ""; + grub_uint8_t candidate_digest[sizeof (header.mkDigest)]; + + /* Try to open disk. */ + source = grub_disk_open (name); + if (!source) + return grub_errno; + + /* Read the LUKS header. */ + err = grub_disk_read (source, 0, 0, sizeof (header), &header); + if (err) + { + grub_disk_close (source); + return err; + } + + /* Look for LUKS magic sequence. */ + if (grub_memcmp (header.magic, LUKS_MAGIC, sizeof (header.magic)) + || grub_be_to_cpu16 (header.version) != 1) + { + grub_disk_close (source); + return GRUB_ERR_NONE; + } + + if (check_uuid && grub_memcmp (header.uuid, uuid, + sizeof (header.uuid)) != 0) + return 0; + + newdev = grub_zalloc (sizeof (struct grub_luks)); + if (!newdev) + { + grub_disk_close (source); + return grub_errno; + } + + newdev->id = n; + newdev->devname = grub_xasprintf ("luks%d", n); + newdev->source = grub_strdup (name); + n++; + + /* Make sure that strings are null terminated. */ + header.cipherName[sizeof (header.cipherName) - 1] = 0; + header.cipherMode[sizeof (header.cipherMode) - 1] = 0; + header.hashSpec[sizeof (header.hashSpec) - 1] = 0; + + ciph = grub_crypto_lookup_cipher_by_name (header.cipherName); + if (!ciph) + { + grub_disk_close (source); + return grub_error (GRUB_ERR_FILE_NOT_FOUND, "Cipher %s isn't available", + header.cipherName); + } + + /* Configure the cipher used for the bulk data. */ + cipher = grub_crypto_cipher_open (ciph); + if (!cipher) + { + grub_disk_close (source); + grub_free (newdev); + return grub_errno; + } + + keysize = grub_be_to_cpu32 (header.keyBytes); + if (keysize > 1024) + { + grub_disk_close (source); + grub_free (newdev); + return grub_error (GRUB_ERR_BAD_ARGUMENT, "invalid keysize %d", + keysize); + } + + /* Configure the cipher mode. */ + if (grub_strncmp (header.cipherMode, "ecb", 3) == 0) + mode = GRUB_LUKS_MODE_ECB; + else if (grub_strncmp (header.cipherMode, "cbc-plain", 9) == 0 + || grub_strncmp (header.cipherMode, "plain", 5) == 0) + mode = GRUB_LUKS_MODE_CBC_PLAIN; + else if (grub_strncmp (header.cipherMode, "cbc-essiv", 9) == 0) + { + mode = GRUB_LUKS_MODE_CBC_ESSIV; + char *hash_str = header.cipherMode + 10; + + /* Configure the hash and cipher used for ESSIV. */ + essiv_hash = grub_crypto_lookup_md_by_name (hash_str); + if (!essiv_hash) + { + grub_crypto_cipher_close (cipher); + grub_disk_close (source); + grub_free (newdev); + return grub_error (GRUB_ERR_FILE_NOT_FOUND, + "Couldn't load %s hash", hash_str); + } + essiv_cipher = grub_crypto_cipher_open (ciph); + if (!cipher) + { + grub_crypto_cipher_close (cipher); + grub_disk_close (source); + grub_free (newdev); + return grub_errno; + } + + essiv_keysize = essiv_hash->mdlen; + hashed_key = grub_malloc (essiv_hash->mdlen); + if (!hashed_key) + { + grub_crypto_cipher_close (cipher); + grub_crypto_cipher_close (essiv_cipher); + grub_disk_close (source); + grub_free (newdev); + return grub_errno; + } + } + else + { + grub_crypto_cipher_close (cipher); + grub_disk_close (source); + grub_free (newdev); + return grub_error (GRUB_ERR_BAD_ARGUMENT, "Unknown cipher mode: %s", + header.cipherMode); + } + + /* Configure the hash used for the AF splitter and HMAC. */ + hash = grub_crypto_lookup_md_by_name (header.hashSpec); + if (!hash) + { + grub_crypto_cipher_close (cipher); + grub_crypto_cipher_close (essiv_cipher); + grub_free (hashed_key); + grub_disk_close (source); + grub_free (newdev); + return grub_error (GRUB_ERR_FILE_NOT_FOUND, "Couldn't load %s hash", + header.hashSpec); + } + + grub_printf ("Attempting to decrypt master key...\n"); + + grub_uint8_t candidate_key[keysize]; + grub_uint8_t digest[keysize]; + + split_key = grub_malloc (keysize * LUKS_STRIPES); + if (!split_key) + { + grub_crypto_cipher_close (cipher); + grub_crypto_cipher_close (essiv_cipher); + grub_free (hashed_key); + grub_disk_close (source); + grub_free (newdev); + return grub_errno; + } + + /* Get the passphrase from the user. */ + grub_printf ("Enter passphrase: "); + if (!grub_password_get (passphrase, MAX_PASSPHRASE)) + { + grub_crypto_cipher_close (cipher); + grub_crypto_cipher_close (essiv_cipher); + grub_free (hashed_key); + grub_free (split_key); + grub_disk_close (source); + grub_free (newdev); + return grub_error (GRUB_ERR_BAD_ARGUMENT, "Passphrase not supplied"); + } + + /* Try to recover master key from each active keyslot. */ + for (i = 0; i < ARRAY_SIZE (header.keyblock); i++) + { + gcry_err_code_t gcry_err; + + /* Check if keyslot is enabled. */ + if (grub_be_to_cpu32 (header.keyblock[i].active) != LUKS_KEY_ENABLED) + continue; + + grub_dprintf ("luks", "Trying keyslot %d\n", i); + + /* Calculate the PBKDF2 of the user supplied passphrase. */ + gcry_err = grub_crypto_pbkdf2 (hash, (grub_uint8_t *) passphrase, + grub_strlen (passphrase), + header.keyblock[i].passwordSalt, + sizeof (header. + keyblock[i].passwordSalt), + grub_be_to_cpu32 (header.keyblock[i]. + passwordIterations), + digest, keysize); + + if (gcry_err) + { + grub_crypto_cipher_close (cipher); + grub_crypto_cipher_close (essiv_cipher); + grub_free (hashed_key); + grub_free (split_key); + grub_disk_close (source); + grub_free (newdev); + return grub_crypto_gcry_error (gcry_err); + } + + grub_dprintf ("luks", "PBKDF2 done\n"); + + /* Set the PBKDF2 output as the cipher key. */ + gcry_err = grub_crypto_cipher_set_key (cipher, digest, keysize); + if (gcry_err) + { + grub_crypto_cipher_close (cipher); + grub_crypto_cipher_close (essiv_cipher); + grub_free (hashed_key); + grub_free (split_key); + grub_disk_close (source); + grub_free (newdev); + return grub_crypto_gcry_error (gcry_err); + } + + /* Configure ESSIV if necessary. */ + if (mode == GRUB_LUKS_MODE_CBC_ESSIV) + { + grub_crypto_hash (essiv_hash, hashed_key, digest, keysize); + grub_crypto_cipher_set_key (essiv_cipher, hashed_key, + essiv_keysize); + } + + length = + grub_be_to_cpu32 (header.keyBytes) * + grub_be_to_cpu32 (header.keyblock[i].stripes); + + /* Read and decrypt the key material from the disk. */ + err = grub_disk_read (source, + grub_be_to_cpu32 (header.keyblock + [i].keyMaterialOffset), 0, + length, split_key); + if (err) + { + grub_crypto_cipher_close (cipher); + grub_crypto_cipher_close (essiv_cipher); + grub_free (hashed_key); + grub_free (split_key); + grub_disk_close (source); + grub_free (newdev); + return err; + } + + gcry_err = luks_decrypt (cipher, mode, split_key, + length, 0, essiv_cipher); + if (gcry_err) + { + grub_crypto_cipher_close (cipher); + grub_crypto_cipher_close (essiv_cipher); + grub_free (hashed_key); + grub_free (split_key); + grub_disk_close (source); + grub_free (newdev); + return grub_crypto_gcry_error (gcry_err); + } + + /* Merge the decrypted key material to get the candidate master key. */ + gcry_err = AF_merge (hash, split_key, candidate_key, keysize, + grub_be_to_cpu32 (header.keyblock[i].stripes)); + if (gcry_err) + { + grub_crypto_cipher_close (cipher); + grub_crypto_cipher_close (essiv_cipher); + grub_free (hashed_key); + grub_free (split_key); + grub_disk_close (source); + grub_free (newdev); + return grub_crypto_gcry_error (gcry_err); + } + + grub_dprintf ("luks", "candidate key recovered\n"); + + /* Calculate the PBKDF2 of the candidate master key. */ + gcry_err = grub_crypto_pbkdf2 (hash, candidate_key, + grub_be_to_cpu32 (header.keyBytes), + header.mkDigestSalt, + sizeof (header.mkDigestSalt), + grub_be_to_cpu32 + (header.mkDigestIterations), + candidate_digest, + sizeof (candidate_digest)); + if (gcry_err) + { + grub_crypto_cipher_close (cipher); + grub_crypto_cipher_close (essiv_cipher); + grub_free (hashed_key); + grub_free (split_key); + grub_disk_close (source); + grub_free (newdev); + return grub_crypto_gcry_error (gcry_err); + } + + /* Compare the calculated PBKDF2 to the digest stored + in the header to see if it's correct. */ + if (grub_memcmp (candidate_digest, header.mkDigest, + sizeof (header.mkDigest)) != 0) + continue; + + grub_disk_close (source); + + grub_printf ("Slot %d opened\n", i); + + /* Set the master key. */ + gcry_err = grub_crypto_cipher_set_key (cipher, candidate_key, keysize); + if (gcry_err) + { + grub_crypto_cipher_close (cipher); + grub_crypto_cipher_close (essiv_cipher); + grub_free (hashed_key); + grub_free (split_key); + grub_free (newdev); + return grub_crypto_gcry_error (gcry_err); + } + + newdev->cipher = cipher; + + /* Configure ESSIV if necessary. */ + if (mode == GRUB_LUKS_MODE_CBC_ESSIV) + { + grub_crypto_hash (essiv_hash, hashed_key, candidate_key, keysize); + gcry_err = + grub_crypto_cipher_set_key (essiv_cipher, hashed_key, + essiv_keysize); + if (gcry_err) + { + grub_crypto_cipher_close (cipher); + grub_crypto_cipher_close (essiv_cipher); + grub_free (hashed_key); + grub_free (split_key); + grub_free (newdev); + return grub_crypto_gcry_error (gcry_err); + } + newdev->essiv_cipher = essiv_cipher; + } + else + { + newdev->essiv_cipher = NULL; + } + + newdev->offset = grub_be_to_cpu32 (header.payloadOffset); + newdev->source_disk = NULL; + newdev->mode = mode; + + grub_free (split_key); + grub_free (hashed_key); + newdev->next = luks_list; + luks_list = newdev; + + have_it = 1; + + return GRUB_ERR_NONE; + } + + return GRUB_ACCESS_DENIED; +} + +static int +grub_luks_scan_device (const char *name) +{ + grub_err_t err; + err = grub_luks_scan_device_real (name); + if (err) + grub_print_error (); + return have_it && check_uuid ? 0 : 1; +} + +static int +grub_luks_iterate (int (*hook) (const char *name)) +{ + grub_luks_t i; + + for (i = luks_list; i != NULL; i = i->next) + if (hook (i->devname)) + return 1; + + return GRUB_ERR_NONE; +} + +static grub_err_t +grub_luks_open (const char *name, grub_disk_t disk) +{ + grub_luks_t dev; + + /* Search for requested device in the list of LUKS devices. */ + for (dev = luks_list; dev != NULL; dev = dev->next) + if (grub_strcmp (dev->devname, name) == 0) + break; + + if (!dev) + return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "No such device"); + + if (!dev->source_disk) + { + grub_dprintf ("luks", "Opening device %s\n", name); + /* Try to open the source disk and populate the requested disk. */ + dev->source_disk = grub_disk_open (dev->source); + if (!dev->source_disk) + return grub_errno; + } + + disk->data = dev; + disk->total_sectors = grub_disk_get_size (dev->source_disk) - dev->offset; + disk->id = dev->id; + dev->ref++; + return GRUB_ERR_NONE; +} + +static void +grub_luks_close (grub_disk_t disk) +{ + grub_luks_t dev = (grub_luks_t) disk->data; + grub_dprintf ("luks", "Closing disk\n"); + + dev->ref--; + + if (dev->ref == 0) + { + grub_disk_close (dev->source_disk); + dev->source_disk = NULL; + } +} + +static grub_err_t +grub_luks_read (grub_disk_t disk, grub_disk_addr_t sector, + grub_size_t size, char *buf) +{ + grub_luks_t dev = (grub_luks_t) disk->data; + grub_err_t err; + grub_dprintf ("luks", + "Reading %" PRIuGRUB_SIZE " sectors from sector 0x%" + PRIxGRUB_UINT64_T " with offset of %" PRIuGRUB_UINT32_T "\n", + size, sector, dev->offset); + + err = grub_disk_read (dev->source_disk, sector + dev->offset, 0, + size << GRUB_DISK_SECTOR_BITS, buf); + if (err) + { + grub_dprintf ("luks", "grub_disk_read failed with error %d\n", err); + return err; + } + return grub_crypto_gcry_error (luks_decrypt (dev->cipher, + dev->mode, + (grub_uint8_t *) buf, + size << GRUB_DISK_SECTOR_BITS, + sector, dev->essiv_cipher)); +} + +static grub_err_t +grub_luks_write (grub_disk_t disk __attribute ((unused)), + grub_disk_addr_t sector __attribute ((unused)), + grub_size_t size __attribute ((unused)), + const char *buf __attribute ((unused))) +{ + return GRUB_ERR_NOT_IMPLEMENTED_YET; +} + +static void +luks_cleanup (void) +{ + grub_luks_t dev = luks_list; + grub_luks_t tmp; + + while (dev != NULL) + { + grub_free (dev->devname); + grub_free (dev->source); + grub_free (dev->cipher); + grub_free (dev->essiv_cipher); + tmp = dev->next; + grub_free (dev); + dev = tmp; + } +} + +static grub_err_t +grub_cmd_luksmount (grub_extcmd_context_t ctxt, int argc, char **args) +{ + struct grub_arg_list *state = ctxt->state; + + if (argc < 1) + return grub_error (GRUB_ERR_BAD_ARGUMENT, "device name required"); + + have_it = 0; + if (state[0].set) + { + check_uuid = 1; + uuid = args[0]; + grub_device_iterate (&grub_luks_scan_device); + uuid = NULL; + } + else + { + grub_err_t err; + check_uuid = 0; + uuid = NULL; + err = grub_luks_scan_device_real (args[0]); + return err; + } + if (!have_it) + return grub_error (GRUB_ERR_BAD_ARGUMENT, "no such luks found"); + return 0; +} + +static struct grub_disk_dev grub_luks_dev = { + .name = "luks", + .id = GRUB_DISK_DEVICE_LUKS_ID, + .iterate = grub_luks_iterate, + .open = grub_luks_open, + .close = grub_luks_close, + .read = grub_luks_read, + .write = grub_luks_write, + .next = 0 +}; + +static grub_extcmd_t cmd; + +GRUB_MOD_INIT (luks) +{ + cmd = grub_register_extcmd ("luksmount", grub_cmd_luksmount, 0, + N_("SOURCE|-u UUID"), + N_("Mount a LUKS device."), options); + grub_disk_dev_register (&grub_luks_dev); +} + +GRUB_MOD_FINI (luks) +{ + grub_unregister_extcmd (cmd); + grub_disk_dev_unregister (&grub_luks_dev); + luks_cleanup (); +} From 5709ed126d9155ae06c284f9c8fceb11227cc73d Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Thu, 21 Apr 2011 11:17:01 +0200 Subject: [PATCH 475/869] small cleanup --- grub-core/disk/AFSplitter.c | 19 ++----------------- grub-core/disk/luks.c | 2 -- 2 files changed, 2 insertions(+), 19 deletions(-) diff --git a/grub-core/disk/AFSplitter.c b/grub-core/disk/AFSplitter.c index 6c3dc488e..ebcc35221 100644 --- a/grub-core/disk/AFSplitter.c +++ b/grub-core/disk/AFSplitter.c @@ -20,28 +20,13 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#include -#include -#include -#include -#include -#include -#include -#include #include -#include -#include -#include +#include +#include gcry_err_code_t AF_merge (const gcry_md_spec_t * hash, grub_uint8_t * src, grub_uint8_t * dst, grub_size_t blocksize, grub_size_t blocknumbers); -static void diffuse (const gcry_md_spec_t * hash, grub_uint8_t * src, - grub_uint8_t * dst, grub_size_t size); -gcry_err_code_t AF_split (const gcry_md_spec_t * hash, grub_uint8_t * src, - grub_uint8_t * dst, grub_size_t blocksize, - grub_size_t blocknumbers); - static void diffuse (const gcry_md_spec_t * hash, grub_uint8_t * src, diff --git a/grub-core/disk/luks.c b/grub-core/disk/luks.c index 47d10d63c..78fcabb03 100644 --- a/grub-core/disk/luks.c +++ b/grub-core/disk/luks.c @@ -20,11 +20,9 @@ #include #include #include -#include #include #include #include -#include #include #include From 92051871b736cde73d8755b3e29781a677ee362c Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Thu, 21 Apr 2011 10:26:29 +0100 Subject: [PATCH 476/869] * grub-core/kern/emu/getroot.c (grub_find_root_device_from_mountinfo): Remove non-virtual-device test that was incorrectly reintroduced in r3214. Reported by: Ian Dall. Fixes Savannah bug #33133. --- ChangeLog | 7 +++++++ grub-core/kern/emu/getroot.c | 3 --- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 98d3b0ea8..1142cf81d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2011-04-21 Colin Watson + + * grub-core/kern/emu/getroot.c + (grub_find_root_device_from_mountinfo): Remove non-virtual-device + test that was incorrectly reintroduced in r3214. + Reported by: Ian Dall. Fixes Savannah bug #33133. + 2011-04-21 Colin Watson Fix stack pointer handling in 16-bit relocator. diff --git a/grub-core/kern/emu/getroot.c b/grub-core/kern/emu/getroot.c index f836a6625..a274f3c06 100644 --- a/grub-core/kern/emu/getroot.c +++ b/grub-core/kern/emu/getroot.c @@ -216,9 +216,6 @@ grub_find_root_device_from_mountinfo (const char *dir, char **relroot) /* Now scan visible mounts for the ones we're interested in. */ for (i = entry_len - 1; i >= 0; i--) { - if (entries[i].major != 0) - continue; /* not a virtual device */ - if (!*entries[i].device) continue; From cff5e5e58d93bdd028aba1a220bb59a7962bba52 Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Thu, 21 Apr 2011 10:37:45 +0100 Subject: [PATCH 477/869] grub-core/fs/squash4.c: Add missing GRUB_MOD_LICENSE. --- grub-core/fs/squash4.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/grub-core/fs/squash4.c b/grub-core/fs/squash4.c index 8e8388628..4f1265582 100644 --- a/grub-core/fs/squash4.c +++ b/grub-core/fs/squash4.c @@ -27,6 +27,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + /* object format Pointed by superblock RAW Fixed offset (0) From a89c3dd3f7f587447b61cdfb4de587951217fca2 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Thu, 21 Apr 2011 11:38:51 +0200 Subject: [PATCH 478/869] Don't mount the same LUKS volume twice --- grub-core/disk/luks.c | 171 ++++++++++++++++++------------------------ 1 file changed, 75 insertions(+), 96 deletions(-) diff --git a/grub-core/disk/luks.c b/grub-core/disk/luks.c index 78fcabb03..160d1102c 100644 --- a/grub-core/disk/luks.c +++ b/grub-core/disk/luks.c @@ -47,7 +47,7 @@ struct grub_luks_phdr grub_uint8_t mkDigest[20]; grub_uint8_t mkDigestSalt[32]; grub_uint32_t mkDigestIterations; - grub_uint8_t uuid[40]; + char uuid[40]; struct { grub_uint32_t active; @@ -65,8 +65,7 @@ typedef enum GRUB_LUKS_MODE_ECB, GRUB_LUKS_MODE_CBC_PLAIN, GRUB_LUKS_MODE_CBC_ESSIV -} -luks_mode_t; +} luks_mode_t; struct grub_luks { @@ -77,7 +76,9 @@ struct grub_luks grub_crypto_cipher_handle_t cipher; grub_crypto_cipher_handle_t essiv_cipher; luks_mode_t mode; - int id; + unsigned long id, source_id; + enum grub_disk_dev_id source_dev_id; + char uuid[sizeof (((struct grub_luks_phdr *) 0)->uuid)]; struct grub_luks *next; }; typedef struct grub_luks *grub_luks_t; @@ -154,11 +155,9 @@ static int check_uuid, have_it; static char *uuid; static grub_err_t -grub_luks_scan_device_real (const char *name) +grub_luks_scan_device_real (const char *name, grub_disk_t source) { - grub_disk_t source; grub_err_t err; - grub_luks_t newdev; struct grub_luks_phdr header; grub_crypto_cipher_handle_t cipher = NULL, essiv_cipher = NULL; const gcry_md_spec_t *hash = NULL, *essiv_hash = NULL; @@ -174,73 +173,38 @@ grub_luks_scan_device_real (const char *name) char passphrase[MAX_PASSPHRASE] = ""; grub_uint8_t candidate_digest[sizeof (header.mkDigest)]; - /* Try to open disk. */ - source = grub_disk_open (name); - if (!source) - return grub_errno; - /* Read the LUKS header. */ err = grub_disk_read (source, 0, 0, sizeof (header), &header); if (err) - { - grub_disk_close (source); - return err; - } + return err; /* Look for LUKS magic sequence. */ if (grub_memcmp (header.magic, LUKS_MAGIC, sizeof (header.magic)) || grub_be_to_cpu16 (header.version) != 1) - { - grub_disk_close (source); - return GRUB_ERR_NONE; - } - - if (check_uuid && grub_memcmp (header.uuid, uuid, - sizeof (header.uuid)) != 0) - return 0; - - newdev = grub_zalloc (sizeof (struct grub_luks)); - if (!newdev) - { - grub_disk_close (source); - return grub_errno; - } - - newdev->id = n; - newdev->devname = grub_xasprintf ("luks%d", n); - newdev->source = grub_strdup (name); - n++; + return GRUB_ERR_NONE; /* Make sure that strings are null terminated. */ header.cipherName[sizeof (header.cipherName) - 1] = 0; header.cipherMode[sizeof (header.cipherMode) - 1] = 0; header.hashSpec[sizeof (header.hashSpec) - 1] = 0; + header.uuid[sizeof (header.uuid) - 1] = 0; + + if (check_uuid && grub_strcmp (header.uuid, uuid) != 0) + return 0; ciph = grub_crypto_lookup_cipher_by_name (header.cipherName); if (!ciph) - { - grub_disk_close (source); - return grub_error (GRUB_ERR_FILE_NOT_FOUND, "Cipher %s isn't available", - header.cipherName); - } + return grub_error (GRUB_ERR_FILE_NOT_FOUND, "Cipher %s isn't available", + header.cipherName); /* Configure the cipher used for the bulk data. */ cipher = grub_crypto_cipher_open (ciph); if (!cipher) - { - grub_disk_close (source); - grub_free (newdev); - return grub_errno; - } + return grub_errno; keysize = grub_be_to_cpu32 (header.keyBytes); if (keysize > 1024) - { - grub_disk_close (source); - grub_free (newdev); - return grub_error (GRUB_ERR_BAD_ARGUMENT, "invalid keysize %d", - keysize); - } + return grub_error (GRUB_ERR_BAD_ARGUMENT, "invalid keysize %d", keysize); /* Configure the cipher mode. */ if (grub_strncmp (header.cipherMode, "ecb", 3) == 0) @@ -258,8 +222,6 @@ grub_luks_scan_device_real (const char *name) if (!essiv_hash) { grub_crypto_cipher_close (cipher); - grub_disk_close (source); - grub_free (newdev); return grub_error (GRUB_ERR_FILE_NOT_FOUND, "Couldn't load %s hash", hash_str); } @@ -267,8 +229,6 @@ grub_luks_scan_device_real (const char *name) if (!cipher) { grub_crypto_cipher_close (cipher); - grub_disk_close (source); - grub_free (newdev); return grub_errno; } @@ -278,16 +238,12 @@ grub_luks_scan_device_real (const char *name) { grub_crypto_cipher_close (cipher); grub_crypto_cipher_close (essiv_cipher); - grub_disk_close (source); - grub_free (newdev); return grub_errno; } } else { grub_crypto_cipher_close (cipher); - grub_disk_close (source); - grub_free (newdev); return grub_error (GRUB_ERR_BAD_ARGUMENT, "Unknown cipher mode: %s", header.cipherMode); } @@ -299,8 +255,6 @@ grub_luks_scan_device_real (const char *name) grub_crypto_cipher_close (cipher); grub_crypto_cipher_close (essiv_cipher); grub_free (hashed_key); - grub_disk_close (source); - grub_free (newdev); return grub_error (GRUB_ERR_FILE_NOT_FOUND, "Couldn't load %s hash", header.hashSpec); } @@ -316,8 +270,6 @@ grub_luks_scan_device_real (const char *name) grub_crypto_cipher_close (cipher); grub_crypto_cipher_close (essiv_cipher); grub_free (hashed_key); - grub_disk_close (source); - grub_free (newdev); return grub_errno; } @@ -329,8 +281,6 @@ grub_luks_scan_device_real (const char *name) grub_crypto_cipher_close (essiv_cipher); grub_free (hashed_key); grub_free (split_key); - grub_disk_close (source); - grub_free (newdev); return grub_error (GRUB_ERR_BAD_ARGUMENT, "Passphrase not supplied"); } @@ -361,8 +311,6 @@ grub_luks_scan_device_real (const char *name) grub_crypto_cipher_close (essiv_cipher); grub_free (hashed_key); grub_free (split_key); - grub_disk_close (source); - grub_free (newdev); return grub_crypto_gcry_error (gcry_err); } @@ -376,8 +324,6 @@ grub_luks_scan_device_real (const char *name) grub_crypto_cipher_close (essiv_cipher); grub_free (hashed_key); grub_free (split_key); - grub_disk_close (source); - grub_free (newdev); return grub_crypto_gcry_error (gcry_err); } @@ -404,8 +350,6 @@ grub_luks_scan_device_real (const char *name) grub_crypto_cipher_close (essiv_cipher); grub_free (hashed_key); grub_free (split_key); - grub_disk_close (source); - grub_free (newdev); return err; } @@ -417,8 +361,6 @@ grub_luks_scan_device_real (const char *name) grub_crypto_cipher_close (essiv_cipher); grub_free (hashed_key); grub_free (split_key); - grub_disk_close (source); - grub_free (newdev); return grub_crypto_gcry_error (gcry_err); } @@ -431,8 +373,6 @@ grub_luks_scan_device_real (const char *name) grub_crypto_cipher_close (essiv_cipher); grub_free (hashed_key); grub_free (split_key); - grub_disk_close (source); - grub_free (newdev); return grub_crypto_gcry_error (gcry_err); } @@ -453,8 +393,6 @@ grub_luks_scan_device_real (const char *name) grub_crypto_cipher_close (essiv_cipher); grub_free (hashed_key); grub_free (split_key); - grub_disk_close (source); - grub_free (newdev); return grub_crypto_gcry_error (gcry_err); } @@ -464,8 +402,6 @@ grub_luks_scan_device_real (const char *name) sizeof (header.mkDigest)) != 0) continue; - grub_disk_close (source); - grub_printf ("Slot %d opened\n", i); /* Set the master key. */ @@ -476,12 +412,9 @@ grub_luks_scan_device_real (const char *name) grub_crypto_cipher_close (essiv_cipher); grub_free (hashed_key); grub_free (split_key); - grub_free (newdev); return grub_crypto_gcry_error (gcry_err); } - newdev->cipher = cipher; - /* Configure ESSIV if necessary. */ if (mode == GRUB_LUKS_MODE_CBC_ESSIV) { @@ -495,24 +428,33 @@ grub_luks_scan_device_real (const char *name) grub_crypto_cipher_close (essiv_cipher); grub_free (hashed_key); grub_free (split_key); - grub_free (newdev); return grub_crypto_gcry_error (gcry_err); } - newdev->essiv_cipher = essiv_cipher; - } - else - { - newdev->essiv_cipher = NULL; } - newdev->offset = grub_be_to_cpu32 (header.payloadOffset); - newdev->source_disk = NULL; - newdev->mode = mode; + { + grub_luks_t newdev; + newdev = grub_zalloc (sizeof (struct grub_luks)); + if (!newdev) + return grub_errno; + newdev->id = n; + newdev->devname = grub_xasprintf ("luks%d", n); + newdev->source = grub_strdup (name); + newdev->source_id = source->id; + newdev->source_dev_id = source->dev->id; + newdev->cipher = cipher; + newdev->offset = grub_be_to_cpu32 (header.payloadOffset); + newdev->source_disk = NULL; + newdev->mode = mode; + newdev->essiv_cipher = essiv_cipher; + grub_memcpy (newdev->uuid, header.uuid, sizeof (newdev->uuid)); + newdev->next = luks_list; + luks_list = newdev; + n++; + } grub_free (split_key); grub_free (hashed_key); - newdev->next = luks_list; - luks_list = newdev; have_it = 1; @@ -526,7 +468,17 @@ static int grub_luks_scan_device (const char *name) { grub_err_t err; - err = grub_luks_scan_device_real (name); + grub_disk_t source; + + /* Try to open disk. */ + source = grub_disk_open (name); + if (!source) + return grub_errno; + + err = grub_luks_scan_device_real (name, source); + + grub_disk_close (source); + if (err) grub_print_error (); return have_it && check_uuid ? 0 : 1; @@ -651,6 +603,15 @@ grub_cmd_luksmount (grub_extcmd_context_t ctxt, int argc, char **args) have_it = 0; if (state[0].set) { + grub_luks_t dev; + + for (dev = luks_list; dev != NULL; dev = dev->next) + if (grub_strcmp (dev->uuid, args[0]) == 0) + { + grub_dprintf ("luks", "already mounted as %s\n", dev->devname); + return GRUB_ERR_NONE; + } + check_uuid = 1; uuid = args[0]; grub_device_iterate (&grub_luks_scan_device); @@ -659,9 +620,27 @@ grub_cmd_luksmount (grub_extcmd_context_t ctxt, int argc, char **args) else { grub_err_t err; + grub_disk_t disk; + grub_luks_t dev; + check_uuid = 0; uuid = NULL; - err = grub_luks_scan_device_real (args[0]); + disk = grub_disk_open (args[0]); + if (!disk) + return grub_errno; + + for (dev = luks_list; dev != NULL; dev = dev->next) + if (dev->source_id == disk->id && dev->source_dev_id == disk->dev->id) + { + grub_dprintf ("luks", "already mounted as %s\n", dev->devname); + grub_disk_close (disk); + return GRUB_ERR_NONE; + } + + err = grub_luks_scan_device_real (args[0], disk); + + grub_disk_close (disk); + return err; } if (!have_it) From 79cde98f5d1c77697e8e3713987136cbf35a13c8 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Thu, 21 Apr 2011 11:58:06 +0200 Subject: [PATCH 479/869] Support luksuuid specification --- grub-core/disk/luks.c | 38 +++++++++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/grub-core/disk/luks.c b/grub-core/disk/luks.c index 160d1102c..3ab6b844d 100644 --- a/grub-core/disk/luks.c +++ b/grub-core/disk/luks.c @@ -69,7 +69,7 @@ typedef enum struct grub_luks { - char *devname, *source; + char *source; grub_uint32_t offset; grub_disk_t source_disk; int ref; @@ -438,7 +438,6 @@ grub_luks_scan_device_real (const char *name, grub_disk_t source) if (!newdev) return grub_errno; newdev->id = n; - newdev->devname = grub_xasprintf ("luks%d", n); newdev->source = grub_strdup (name); newdev->source_id = source->id; newdev->source_dev_id = source->dev->id; @@ -490,8 +489,12 @@ grub_luks_iterate (int (*hook) (const char *name)) grub_luks_t i; for (i = luks_list; i != NULL; i = i->next) - if (hook (i->devname)) - return 1; + { + char buf[30]; + grub_snprintf (buf, sizeof (buf), "luks%lu", i->id); + if (hook (buf)) + return 1; + } return GRUB_ERR_NONE; } @@ -501,11 +504,25 @@ grub_luks_open (const char *name, grub_disk_t disk) { grub_luks_t dev; - /* Search for requested device in the list of LUKS devices. */ - for (dev = luks_list; dev != NULL; dev = dev->next) - if (grub_strcmp (dev->devname, name) == 0) - break; + if (grub_memcmp (name, "luks", sizeof ("luks") - 1) != 0) + return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "No such device"); + if (grub_memcmp (name, "luksuuid/", sizeof ("luksuuid/") - 1) == 0) + { + for (dev = luks_list; dev != NULL; dev = dev->next) + if (grub_strcmp (name + sizeof ("luksuuid/") - 1, dev->uuid) == 0) + break; + } + else + { + unsigned long id = grub_strtoul (name + sizeof ("luks") - 1, 0, 0); + if (grub_errno) + return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "No such device"); + /* Search for requested device in the list of LUKS devices. */ + for (dev = luks_list; dev != NULL; dev = dev->next) + if (dev->id == id) + break; + } if (!dev) return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "No such device"); @@ -582,7 +599,6 @@ luks_cleanup (void) while (dev != NULL) { - grub_free (dev->devname); grub_free (dev->source); grub_free (dev->cipher); grub_free (dev->essiv_cipher); @@ -608,7 +624,7 @@ grub_cmd_luksmount (grub_extcmd_context_t ctxt, int argc, char **args) for (dev = luks_list; dev != NULL; dev = dev->next) if (grub_strcmp (dev->uuid, args[0]) == 0) { - grub_dprintf ("luks", "already mounted as %s\n", dev->devname); + grub_dprintf ("luks", "already mounted as luks%lu\n", dev->id); return GRUB_ERR_NONE; } @@ -632,7 +648,7 @@ grub_cmd_luksmount (grub_extcmd_context_t ctxt, int argc, char **args) for (dev = luks_list; dev != NULL; dev = dev->next) if (dev->source_id == disk->id && dev->source_dev_id == disk->dev->id) { - grub_dprintf ("luks", "already mounted as %s\n", dev->devname); + grub_dprintf ("luks", "already mounted as luks%lu\n", dev->id); grub_disk_close (disk); return GRUB_ERR_NONE; } From 64516e9df6de88b84e53e7b84a25bff2130c00ae Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Thu, 21 Apr 2011 12:39:14 +0200 Subject: [PATCH 480/869] Fix couple of UUID problems --- grub-core/disk/luks.c | 43 +++++++++++++++++++++++++++++-------------- 1 file changed, 29 insertions(+), 14 deletions(-) diff --git a/grub-core/disk/luks.c b/grub-core/disk/luks.c index 3ab6b844d..bc53e0a2b 100644 --- a/grub-core/disk/luks.c +++ b/grub-core/disk/luks.c @@ -78,7 +78,7 @@ struct grub_luks luks_mode_t mode; unsigned long id, source_id; enum grub_disk_dev_id source_dev_id; - char uuid[sizeof (((struct grub_luks_phdr *) 0)->uuid)]; + char uuid[sizeof (((struct grub_luks_phdr *) 0)->uuid) + 1]; struct grub_luks *next; }; typedef struct grub_luks *grub_luks_t; @@ -152,7 +152,7 @@ luks_decrypt (grub_crypto_cipher_handle_t cipher, luks_mode_t mode, } static int check_uuid, have_it; -static char *uuid; +static char *search_uuid; static grub_err_t grub_luks_scan_device_real (const char *name, grub_disk_t source) @@ -172,6 +172,8 @@ grub_luks_scan_device_real (const char *name, grub_disk_t source) const struct gcry_cipher_spec *ciph; char passphrase[MAX_PASSPHRASE] = ""; grub_uint8_t candidate_digest[sizeof (header.mkDigest)]; + char uuid[sizeof (header.uuid) + 1]; + char *iptr, *optr; /* Read the LUKS header. */ err = grub_disk_read (source, 0, 0, sizeof (header), &header); @@ -189,8 +191,20 @@ grub_luks_scan_device_real (const char *name, grub_disk_t source) header.hashSpec[sizeof (header.hashSpec) - 1] = 0; header.uuid[sizeof (header.uuid) - 1] = 0; - if (check_uuid && grub_strcmp (header.uuid, uuid) != 0) - return 0; + optr = uuid; + for (iptr = header.uuid; iptr < &header.uuid[ARRAY_SIZE (header.uuid)]; + iptr++) + { + if (*iptr != '-') + *optr++ = *iptr; + } + *optr = 0; + + if (check_uuid && grub_strcasecmp (search_uuid, uuid) != 0) + { + grub_dprintf ("luks", "%s != %s", uuid, search_uuid); + return 0; + } ciph = grub_crypto_lookup_cipher_by_name (header.cipherName); if (!ciph) @@ -274,7 +288,7 @@ grub_luks_scan_device_real (const char *name, grub_disk_t source) } /* Get the passphrase from the user. */ - grub_printf ("Enter passphrase: "); + grub_printf ("Enter passphrase for %s (%s): ", name, uuid); if (!grub_password_get (passphrase, MAX_PASSPHRASE)) { grub_crypto_cipher_close (cipher); @@ -446,7 +460,7 @@ grub_luks_scan_device_real (const char *name, grub_disk_t source) newdev->source_disk = NULL; newdev->mode = mode; newdev->essiv_cipher = essiv_cipher; - grub_memcpy (newdev->uuid, header.uuid, sizeof (newdev->uuid)); + grub_memcpy (newdev->uuid, uuid, sizeof (newdev->uuid)); newdev->next = luks_list; luks_list = newdev; n++; @@ -510,7 +524,7 @@ grub_luks_open (const char *name, grub_disk_t disk) if (grub_memcmp (name, "luksuuid/", sizeof ("luksuuid/") - 1) == 0) { for (dev = luks_list; dev != NULL; dev = dev->next) - if (grub_strcmp (name + sizeof ("luksuuid/") - 1, dev->uuid) == 0) + if (grub_strcasecmp (name + sizeof ("luksuuid/") - 1, dev->uuid) == 0) break; } else @@ -622,16 +636,20 @@ grub_cmd_luksmount (grub_extcmd_context_t ctxt, int argc, char **args) grub_luks_t dev; for (dev = luks_list; dev != NULL; dev = dev->next) - if (grub_strcmp (dev->uuid, args[0]) == 0) + if (grub_strcasecmp (dev->uuid, args[0]) == 0) { grub_dprintf ("luks", "already mounted as luks%lu\n", dev->id); return GRUB_ERR_NONE; } check_uuid = 1; - uuid = args[0]; + search_uuid = args[0]; grub_device_iterate (&grub_luks_scan_device); - uuid = NULL; + search_uuid = NULL; + + if (!have_it) + return grub_error (GRUB_ERR_BAD_ARGUMENT, "no such luks found"); + return GRUB_ERR_NONE; } else { @@ -640,7 +658,7 @@ grub_cmd_luksmount (grub_extcmd_context_t ctxt, int argc, char **args) grub_luks_t dev; check_uuid = 0; - uuid = NULL; + search_uuid = NULL; disk = grub_disk_open (args[0]); if (!disk) return grub_errno; @@ -659,9 +677,6 @@ grub_cmd_luksmount (grub_extcmd_context_t ctxt, int argc, char **args) return err; } - if (!have_it) - return grub_error (GRUB_ERR_BAD_ARGUMENT, "no such luks found"); - return 0; } static struct grub_disk_dev grub_luks_dev = { From a10e7a5a8918bea6e2632055129fa9b516fe965a Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Thu, 21 Apr 2011 12:39:31 +0200 Subject: [PATCH 481/869] Support grub-probe -t drive --- grub-core/kern/emu/getroot.c | 75 +++++++++++++++++++++++++++--------- include/grub/emu/getroot.h | 1 + 2 files changed, 58 insertions(+), 18 deletions(-) diff --git a/grub-core/kern/emu/getroot.c b/grub-core/kern/emu/getroot.c index f47203cfc..40cbc4998 100644 --- a/grub-core/kern/emu/getroot.c +++ b/grub-core/kern/emu/getroot.c @@ -640,11 +640,11 @@ grub_guess_root_device (const char *dir) return os_dev; } -static int -grub_util_is_lvm (const char *os_dev) +static char * +get_dm_uuid (const char *os_dev) { if ((strncmp ("/dev/mapper/", os_dev, 12) != 0)) - return 0; + return NULL; #ifdef HAVE_DEVICE_MAPPER { @@ -652,17 +652,18 @@ grub_util_is_lvm (const char *os_dev) uint32_t maj, min; struct dm_tree_node *node = NULL; const char *node_uuid; + char *ret; struct stat st; if (stat (os_dev, &st) < 0) - return 0; + return NULL; tree = dm_tree_create (); if (! tree) { grub_printf ("Failed to create tree\n"); grub_dprintf ("hostdisk", "dm_tree_create failed\n"); - return 0; + return NULL; } maj = major (st.st_rdev); @@ -672,7 +673,7 @@ grub_util_is_lvm (const char *os_dev) { grub_dprintf ("hostdisk", "dm_tree_add_dev failed\n"); dm_tree_free (tree); - return 0; + return NULL; } node = dm_tree_find_node (tree, maj, min); @@ -680,39 +681,64 @@ grub_util_is_lvm (const char *os_dev) { grub_dprintf ("hostdisk", "dm_tree_find_node failed\n"); dm_tree_free (tree); - return 0; + return NULL; } node_uuid = dm_tree_node_get_uuid (node); if (! node_uuid) { grub_dprintf ("hostdisk", "%s has no DM uuid\n", os_dev); dm_tree_free (tree); - return 0; - } - if (strncmp (node_uuid, "LVM-", 4) != 0) - { - dm_tree_free (tree); - return 0; + return NULL; } + + ret = grub_strdup (node_uuid); dm_tree_free (tree); - return 1; + return ret; } #else - return 1; + return NULL; #endif /* HAVE_DEVICE_MAPPER */ } +static enum grub_dev_abstraction_types +grub_util_get_dm_abstraction (const char *os_dev) +{ + char *uuid; + uuid = get_dm_uuid (os_dev); + + if (uuid == NULL) + return GRUB_DEV_ABSTRACTION_NONE; + + if (strncmp (uuid, "LVM-", 4) == 0) + { + grub_free (uuid); + return GRUB_DEV_ABSTRACTION_LVM; + } + if (strncmp (uuid, "CRYPT-LUKS1-", 4) == 0) + { + grub_free (uuid); + return GRUB_DEV_ABSTRACTION_LUKS; + } + + grub_free (uuid); + return GRUB_DEV_ABSTRACTION_NONE; +} + int grub_util_get_dev_abstraction (const char *os_dev __attribute__((unused))) { #ifdef __linux__ + enum grub_dev_abstraction_types ret; + /* User explicitly claims that this drive is visible by BIOS. */ if (grub_util_biosdisk_is_present (os_dev)) return GRUB_DEV_ABSTRACTION_NONE; - /* Check for LVM. */ - if (grub_util_is_lvm (os_dev)) - return GRUB_DEV_ABSTRACTION_LVM; + /* Check for LVM and LUKS. */ + ret = grub_util_get_dm_abstraction (os_dev); + + if (ret != GRUB_DEV_ABSTRACTION_NONE) + return ret; /* Check for RAID. */ if (!strncmp (os_dev, "/dev/md", 7) && ! grub_util_device_is_mapped (os_dev)) @@ -830,6 +856,19 @@ grub_util_get_grub_dev (const char *os_dev) break; + case GRUB_DEV_ABSTRACTION_LUKS: + { + char *uuid, *dash; + uuid = get_dm_uuid (os_dev); + dash = grub_strchr (uuid + sizeof ("CRYPT-LUKS1-") - 1, '-'); + if (dash) + *dash = 0; + grub_dev = grub_xasprintf ("luksuuid/%s", + uuid + sizeof ("CRYPT-LUKS1-") - 1); + grub_free (uuid); + } + break; + case GRUB_DEV_ABSTRACTION_RAID: if (os_dev[7] == '_' && os_dev[8] == 'd') diff --git a/include/grub/emu/getroot.h b/include/grub/emu/getroot.h index 581ea8056..14df583b3 100644 --- a/include/grub/emu/getroot.h +++ b/include/grub/emu/getroot.h @@ -25,6 +25,7 @@ enum grub_dev_abstraction_types { GRUB_DEV_ABSTRACTION_NONE, GRUB_DEV_ABSTRACTION_LVM, GRUB_DEV_ABSTRACTION_RAID, + GRUB_DEV_ABSTRACTION_LUKS, }; char *grub_find_device (const char *dir, dev_t dev); From c85140b3b79fb91fb7d174042139adc9b5028a23 Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Thu, 21 Apr 2011 15:17:48 +0100 Subject: [PATCH 482/869] Add "SEE ALSO" sections to most man pages. Fixes Debian bug #551428. * docs/man/grub-editenv.h2m (SEE ALSO): New section. * docs/man/grub-emu.h2m (SEE ALSO): Likewise. * docs/man/grub-fstest.h2m (SEE ALSO): Likewise. * docs/man/grub-install.h2m (SEE ALSO): Likewise. * docs/man/grub-macho2img.h2m (SEE ALSO): Likewise. * docs/man/grub-menulst2cfg.h2m (SEE ALSO): Likewise. * docs/man/grub-mkconfig.h2m (SEE ALSO): Likewise. * docs/man/grub-mkdevicemap.h2m (SEE ALSO): Likewise. * docs/man/grub-mkfont.h2m (SEE ALSO): Likewise. * docs/man/grub-mkimage.h2m (SEE ALSO): Likewise. * docs/man/grub-mklayout.h2m (SEE ALSO): Likewise. * docs/man/grub-mknetdir.h2m (SEE ALSO): Likewise. * docs/man/grub-mkpasswd-pbkdf2.h2m (SEE ALSO): Likewise. * docs/man/grub-mkrelpath.h2m (SEE ALSO): Likewise. * docs/man/grub-mkrescue.h2m (SEE ALSO): Likewise. * docs/man/grub-ofpathname.h2m (SEE ALSO): Likewise. * docs/man/grub-pe2elf.h2m (SEE ALSO): Likewise. * docs/man/grub-probe.h2m (SEE ALSO): Likewise. * docs/man/grub-reboot.h2m (SEE ALSO): Likewise. * docs/man/grub-script-check.h2m (SEE ALSO): Likewise. * docs/man/grub-set-default.h2m (SEE ALSO): Likewise. * docs/man/grub-setup.h2m (SEE ALSO): Likewise. --- ChangeLog | 28 ++++++++++++++++++++++++++++ docs/man/grub-editenv.h2m | 3 +++ docs/man/grub-emu.h2m | 4 ++++ docs/man/grub-fstest.h2m | 2 ++ docs/man/grub-install.h2m | 5 +++++ docs/man/grub-macho2img.h2m | 2 ++ docs/man/grub-menulst2cfg.h2m | 3 ++- docs/man/grub-mkconfig.h2m | 2 ++ docs/man/grub-mkdevicemap.h2m | 2 ++ docs/man/grub-mkfont.h2m | 2 ++ docs/man/grub-mkimage.h2m | 5 +++++ docs/man/grub-mklayout.h2m | 2 ++ docs/man/grub-mknetdir.h2m | 2 ++ docs/man/grub-mkpasswd-pbkdf2.h2m | 2 ++ docs/man/grub-mkrelpath.h2m | 2 ++ docs/man/grub-mkrescue.h2m | 2 ++ docs/man/grub-ofpathname.h2m | 2 ++ docs/man/grub-pe2elf.h2m | 2 ++ docs/man/grub-probe.h2m | 2 ++ docs/man/grub-reboot.h2m | 3 +++ docs/man/grub-script-check.h2m | 2 ++ docs/man/grub-set-default.h2m | 3 +++ docs/man/grub-setup.h2m | 4 ++++ 23 files changed, 85 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 1142cf81d..3b98caba3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,31 @@ +2011-04-21 Colin Watson + + Add "SEE ALSO" sections to most man pages. Fixes Debian bug + #551428. + + * docs/man/grub-editenv.h2m (SEE ALSO): New section. + * docs/man/grub-emu.h2m (SEE ALSO): Likewise. + * docs/man/grub-fstest.h2m (SEE ALSO): Likewise. + * docs/man/grub-install.h2m (SEE ALSO): Likewise. + * docs/man/grub-macho2img.h2m (SEE ALSO): Likewise. + * docs/man/grub-menulst2cfg.h2m (SEE ALSO): Likewise. + * docs/man/grub-mkconfig.h2m (SEE ALSO): Likewise. + * docs/man/grub-mkdevicemap.h2m (SEE ALSO): Likewise. + * docs/man/grub-mkfont.h2m (SEE ALSO): Likewise. + * docs/man/grub-mkimage.h2m (SEE ALSO): Likewise. + * docs/man/grub-mklayout.h2m (SEE ALSO): Likewise. + * docs/man/grub-mknetdir.h2m (SEE ALSO): Likewise. + * docs/man/grub-mkpasswd-pbkdf2.h2m (SEE ALSO): Likewise. + * docs/man/grub-mkrelpath.h2m (SEE ALSO): Likewise. + * docs/man/grub-mkrescue.h2m (SEE ALSO): Likewise. + * docs/man/grub-ofpathname.h2m (SEE ALSO): Likewise. + * docs/man/grub-pe2elf.h2m (SEE ALSO): Likewise. + * docs/man/grub-probe.h2m (SEE ALSO): Likewise. + * docs/man/grub-reboot.h2m (SEE ALSO): Likewise. + * docs/man/grub-script-check.h2m (SEE ALSO): Likewise. + * docs/man/grub-set-default.h2m (SEE ALSO): Likewise. + * docs/man/grub-setup.h2m (SEE ALSO): Likewise. + 2011-04-21 Colin Watson * grub-core/kern/emu/getroot.c diff --git a/docs/man/grub-editenv.h2m b/docs/man/grub-editenv.h2m index efbd79070..3859d3d4c 100644 --- a/docs/man/grub-editenv.h2m +++ b/docs/man/grub-editenv.h2m @@ -1,2 +1,5 @@ [NAME] grub-editenv \- edit GRUB environment block +[SEE ALSO] +.BR grub-reboot (8), +.BR grub-set-default (8) diff --git a/docs/man/grub-emu.h2m b/docs/man/grub-emu.h2m index 09a1f88c1..ef1c00065 100644 --- a/docs/man/grub-emu.h2m +++ b/docs/man/grub-emu.h2m @@ -1,2 +1,6 @@ [NAME] grub-emu \- GRUB emulator +[SEE ALSO] +If you are trying to install GRUB, then you should use +.BR grub-install (8) +rather than this program. diff --git a/docs/man/grub-fstest.h2m b/docs/man/grub-fstest.h2m index be39429b5..9676b159a 100644 --- a/docs/man/grub-fstest.h2m +++ b/docs/man/grub-fstest.h2m @@ -1,2 +1,4 @@ [NAME] grub-fstest \- debug tool for GRUB filesystem drivers +[SEE ALSO] +.BR grub-probe (8) diff --git a/docs/man/grub-install.h2m b/docs/man/grub-install.h2m index 65252155c..2de371a3f 100644 --- a/docs/man/grub-install.h2m +++ b/docs/man/grub-install.h2m @@ -1,2 +1,7 @@ [NAME] grub-install \- install GRUB to a device +[SEE ALSO] +.BR grub-mkconfig (8), +.BR grub-mkimage (1), +.BR grub-setup (8), +.BR grub-mkrescue (1) diff --git a/docs/man/grub-macho2img.h2m b/docs/man/grub-macho2img.h2m index 412bf926a..d79aaeed8 100644 --- a/docs/man/grub-macho2img.h2m +++ b/docs/man/grub-macho2img.h2m @@ -1,2 +1,4 @@ [NAME] grub-macho2img \- convert Mach-O to raw image +[SEE ALSO] +.BR grub-mkimage (1) diff --git a/docs/man/grub-menulst2cfg.h2m b/docs/man/grub-menulst2cfg.h2m index 0c0570f27..c2e0055ed 100644 --- a/docs/man/grub-menulst2cfg.h2m +++ b/docs/man/grub-menulst2cfg.h2m @@ -1,3 +1,4 @@ [NAME] grub-menulst2cfg \- transform legacy menu.lst into grub.cfg - +[SEE ALSO] +.BR grub-mkconfig (8) diff --git a/docs/man/grub-mkconfig.h2m b/docs/man/grub-mkconfig.h2m index b0d33ec61..9b42f8130 100644 --- a/docs/man/grub-mkconfig.h2m +++ b/docs/man/grub-mkconfig.h2m @@ -1,2 +1,4 @@ [NAME] grub-mkconfig \- generate a GRUB configuration file +[SEE ALSO] +.BR grub-install (8) diff --git a/docs/man/grub-mkdevicemap.h2m b/docs/man/grub-mkdevicemap.h2m index 8ab34ac86..3ef8e9712 100644 --- a/docs/man/grub-mkdevicemap.h2m +++ b/docs/man/grub-mkdevicemap.h2m @@ -1,2 +1,4 @@ [NAME] grub-mkdevicemap \- generate a GRUB device map file automatically +[SEE ALSO] +.BR grub-install (8) diff --git a/docs/man/grub-mkfont.h2m b/docs/man/grub-mkfont.h2m index d8580186f..d46fe600e 100644 --- a/docs/man/grub-mkfont.h2m +++ b/docs/man/grub-mkfont.h2m @@ -1,2 +1,4 @@ [NAME] grub-mkfont \- make GRUB font files +[SEE ALSO] +.BR grub-mkconfig (8) diff --git a/docs/man/grub-mkimage.h2m b/docs/man/grub-mkimage.h2m index 71f270940..ca08b0c5c 100644 --- a/docs/man/grub-mkimage.h2m +++ b/docs/man/grub-mkimage.h2m @@ -1,2 +1,7 @@ [NAME] grub-mkimage \- make a bootable image of GRUB +[SEE ALSO] +.BR grub-install (8), +.BR grub-setup (8), +.BR grub-mkrescue (1), +.BR grub-mknetdir (8) diff --git a/docs/man/grub-mklayout.h2m b/docs/man/grub-mklayout.h2m index e0ae9dedb..cda6f3676 100644 --- a/docs/man/grub-mklayout.h2m +++ b/docs/man/grub-mklayout.h2m @@ -1,2 +1,4 @@ [NAME] grub-mklayout \- generate a GRUB keyboard layout file +[SEE ALSO] +.BR grub-mkconfig (8) diff --git a/docs/man/grub-mknetdir.h2m b/docs/man/grub-mknetdir.h2m index 26defe876..a2ef13ec1 100644 --- a/docs/man/grub-mknetdir.h2m +++ b/docs/man/grub-mknetdir.h2m @@ -1,2 +1,4 @@ [NAME] grub-mknetdir \- prepare a GRUB netboot directory. +[SEE ALSO] +.BR grub-mkimage (1) diff --git a/docs/man/grub-mkpasswd-pbkdf2.h2m b/docs/man/grub-mkpasswd-pbkdf2.h2m index 5b2b2ef7f..4d202f3da 100644 --- a/docs/man/grub-mkpasswd-pbkdf2.h2m +++ b/docs/man/grub-mkpasswd-pbkdf2.h2m @@ -1,2 +1,4 @@ [NAME] grub-mkpasswd-pbkdf2 \- generate hashed password for GRUB +[SEE ALSO] +.BR grub-mkconfig (8) diff --git a/docs/man/grub-mkrelpath.h2m b/docs/man/grub-mkrelpath.h2m index ccc0880fa..d01f3961e 100644 --- a/docs/man/grub-mkrelpath.h2m +++ b/docs/man/grub-mkrelpath.h2m @@ -1,2 +1,4 @@ [NAME] grub-mkrelpath \- make a system path relative to its root +[SEE ALSO] +.BR grub-probe (8) diff --git a/docs/man/grub-mkrescue.h2m b/docs/man/grub-mkrescue.h2m index 5e92e0d99..a427f02e3 100644 --- a/docs/man/grub-mkrescue.h2m +++ b/docs/man/grub-mkrescue.h2m @@ -1,2 +1,4 @@ [NAME] grub-mkrescue \- make a GRUB rescue image +[SEE ALSO] +.BR grub-mkimage (1) diff --git a/docs/man/grub-ofpathname.h2m b/docs/man/grub-ofpathname.h2m index f07158cb3..74b43eea0 100644 --- a/docs/man/grub-ofpathname.h2m +++ b/docs/man/grub-ofpathname.h2m @@ -1,2 +1,4 @@ [NAME] grub-ofpathname \- find OpenBOOT path for a device +[SEE ALSO] +.BR grub-probe (8) diff --git a/docs/man/grub-pe2elf.h2m b/docs/man/grub-pe2elf.h2m index 3fdb88b43..7ca29bd70 100644 --- a/docs/man/grub-pe2elf.h2m +++ b/docs/man/grub-pe2elf.h2m @@ -1,2 +1,4 @@ [NAME] grub-pe2elf \- convert PE image to ELF +[SEE ALSO] +.BR grub-mkimage (1) diff --git a/docs/man/grub-probe.h2m b/docs/man/grub-probe.h2m index 817ba8ef6..6e1ffdcf9 100644 --- a/docs/man/grub-probe.h2m +++ b/docs/man/grub-probe.h2m @@ -1,2 +1,4 @@ [NAME] grub-probe \- probe device information for GRUB +[SEE ALSO] +.BR grub-fstest (1) diff --git a/docs/man/grub-reboot.h2m b/docs/man/grub-reboot.h2m index 957e4b797..e4acace65 100644 --- a/docs/man/grub-reboot.h2m +++ b/docs/man/grub-reboot.h2m @@ -1,2 +1,5 @@ [NAME] grub-reboot \- set the default boot entry for GRUB, for the next boot only +[SEE ALSO] +.BR grub-set-default (8), +.BR grub-editenv (1) diff --git a/docs/man/grub-script-check.h2m b/docs/man/grub-script-check.h2m index 39c0a3ef6..365368267 100644 --- a/docs/man/grub-script-check.h2m +++ b/docs/man/grub-script-check.h2m @@ -1,2 +1,4 @@ [NAME] grub-script-check \- check grub.cfg for syntax errors +[SEE ALSO] +.BR grub-mkconfig (8) diff --git a/docs/man/grub-set-default.h2m b/docs/man/grub-set-default.h2m index dd0793cfd..7945001c1 100644 --- a/docs/man/grub-set-default.h2m +++ b/docs/man/grub-set-default.h2m @@ -1,2 +1,5 @@ [NAME] grub-set-default \- set the saved default boot entry for GRUB +[SEE ALSO] +.BR grub-reboot (8), +.BR grub-editenv (1) diff --git a/docs/man/grub-setup.h2m b/docs/man/grub-setup.h2m index e70e465a4..eebe3ef38 100644 --- a/docs/man/grub-setup.h2m +++ b/docs/man/grub-setup.h2m @@ -1,2 +1,6 @@ [NAME] grub-setup \- set up a device to boot using GRUB +[SEE ALSO] +.BR grub-install (8), +.BR grub-mkimage (1), +.BR grub-mkrescue (1) From e91dba5b13c564a5fbfc2b9d070ad9e87cb1bae5 Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Thu, 21 Apr 2011 15:47:58 +0100 Subject: [PATCH 483/869] * po/README: Add instructions for creating po/LINGUAS. --- ChangeLog | 4 ++++ po/README | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/ChangeLog b/ChangeLog index 3b98caba3..cd791308c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2011-04-21 Colin Watson + + * po/README: Add instructions for creating po/LINGUAS. + 2011-04-21 Colin Watson Add "SEE ALSO" sections to most man pages. Fixes Debian bug diff --git a/po/README b/po/README index 801599583..5541f4229 100644 --- a/po/README +++ b/po/README @@ -8,6 +8,10 @@ that will hopefully clarify the situation. rsync -Lrtvz translationproject.org::tp/latest/grub/ po + Then create a po/LINGUAS file listing all the language codes: + + (cd po && ls *.po | cut -d. -f1 | xargs) >po/LINGUAS + GRUB's build system will automatically detect those and include them in your install. From 24b905a11c90e47cb271397bd507e0496fe130e7 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 22 Apr 2011 00:09:07 +0200 Subject: [PATCH 484/869] Lazy LVM and RAID assembly --- grub-core/disk/ata.c | 9 +- grub-core/disk/host.c | 9 +- grub-core/disk/i386/pc/biosdisk.c | 56 ++++++---- grub-core/disk/loopback.c | 8 +- grub-core/disk/lvm.c | 139 ++++++++++++++++++++--- grub-core/disk/memdisk.c | 9 +- grub-core/disk/raid.c | 178 ++++++++++++++++++++++-------- grub-core/disk/scsi.c | 9 +- grub-core/fs/i386/pc/pxe.c | 9 +- grub-core/kern/disk.c | 31 ++++-- grub-core/kern/emu/hostdisk.c | 6 +- include/grub/disk.h | 15 ++- include/grub/raid.h | 1 + 13 files changed, 365 insertions(+), 114 deletions(-) diff --git a/grub-core/disk/ata.c b/grub-core/disk/ata.c index 7f261560d..3a43a8cae 100644 --- a/grub-core/disk/ata.c +++ b/grub-core/disk/ata.c @@ -666,10 +666,14 @@ grub_ata_readwrite (grub_disk_t disk, grub_disk_addr_t sector, static int -grub_ata_iterate (int (*hook) (const char *name)) +grub_ata_iterate (int (*hook) (const char *name), + grub_disk_pull_t pull) { struct grub_ata_device *dev; + if (pull != GRUB_DISK_PULL_NONE) + return 0; + for (dev = grub_ata_devices; dev; dev = dev->next) { char devname[10]; @@ -696,7 +700,8 @@ grub_ata_iterate (int (*hook) (const char *name)) } static grub_err_t -grub_ata_open (const char *name, grub_disk_t disk) +grub_ata_open (const char *name, grub_disk_t disk, + grub_disk_pull_t pull __attribute__ ((unused))) { struct grub_ata_device *dev; grub_err_t err; diff --git a/grub-core/disk/host.c b/grub-core/disk/host.c index c51966293..5376cc6ce 100644 --- a/grub-core/disk/host.c +++ b/grub-core/disk/host.c @@ -27,15 +27,20 @@ int grub_disk_host_i_want_a_reference; static int -grub_host_iterate (int (*hook) (const char *name)) +grub_host_iterate (int (*hook) (const char *name), + grub_disk_pull_t pull) { + if (pull != GRUB_DISK_PULL_NONE) + return 0; + if (hook ("host")) return 1; return 0; } static grub_err_t -grub_host_open (const char *name, grub_disk_t disk) +grub_host_open (const char *name, grub_disk_t disk, + grub_disk_pull_t pull __attribute__ ((unused))) { if (grub_strcmp (name, "host")) return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "not a host disk"); diff --git a/grub-core/disk/i386/pc/biosdisk.c b/grub-core/disk/i386/pc/biosdisk.c index 1d47dc727..e75ab184b 100644 --- a/grub-core/disk/i386/pc/biosdisk.c +++ b/grub-core/disk/i386/pc/biosdisk.c @@ -284,42 +284,52 @@ grub_biosdisk_call_hook (int (*hook) (const char *name), int drive) } static int -grub_biosdisk_iterate (int (*hook) (const char *name)) +grub_biosdisk_iterate (int (*hook) (const char *name), + grub_disk_pull_t pull __attribute__ ((unused))) { - int drive; int num_floppies; + int drive; /* For hard disks, attempt to read the MBR. */ - for (drive = 0x80; drive < 0x90; drive++) + switch (pull) { - if (grub_biosdisk_rw_standard (0x02, drive, 0, 0, 1, 1, - GRUB_MEMORY_MACHINE_SCRATCH_SEG) != 0) + case GRUB_DISK_PULL_NONE: + for (drive = 0x80; drive < 0x90; drive++) { - grub_dprintf ("disk", "Read error when probing drive 0x%2x\n", drive); - break; + if (grub_biosdisk_rw_standard (0x02, drive, 0, 0, 1, 1, + GRUB_MEMORY_MACHINE_SCRATCH_SEG) != 0) + { + grub_dprintf ("disk", "Read error when probing drive 0x%2x\n", drive); + break; + } + + if (grub_biosdisk_call_hook (hook, drive)) + return 1; + } + return 0; + + case GRUB_DISK_PULL_REMOVABLE: + if (cd_drive) + { + if (grub_biosdisk_call_hook (hook, cd_drive)) + return 1; } - if (grub_biosdisk_call_hook (hook, drive)) - return 1; + /* For floppy disks, we can get the number safely. */ + num_floppies = grub_biosdisk_get_num_floppies (); + for (drive = 0; drive < num_floppies; drive++) + if (grub_biosdisk_call_hook (hook, drive)) + return 1; + return 0; + default: + return 0; } - - if (cd_drive) - { - if (grub_biosdisk_call_hook (hook, cd_drive)) - return 1; - } - - /* For floppy disks, we can get the number safely. */ - num_floppies = grub_biosdisk_get_num_floppies (); - for (drive = 0; drive < num_floppies; drive++) - if (grub_biosdisk_call_hook (hook, drive)) - return 1; - return 0; } static grub_err_t -grub_biosdisk_open (const char *name, grub_disk_t disk) +grub_biosdisk_open (const char *name, grub_disk_t disk, + grub_disk_pull_t pull __attribute__ ((unused))) { grub_uint64_t total_sectors = 0; int drive; diff --git a/grub-core/disk/loopback.c b/grub-core/disk/loopback.c index d50f353b1..21345af57 100644 --- a/grub-core/disk/loopback.c +++ b/grub-core/disk/loopback.c @@ -133,9 +133,12 @@ fail: static int -grub_loopback_iterate (int (*hook) (const char *name)) +grub_loopback_iterate (int (*hook) (const char *name), + grub_disk_pull_t pull) { struct grub_loopback *d; + if (pull != GRUB_DISK_PULL_NONE) + return 0; for (d = loopback_list; d; d = d->next) { if (hook (d->devname)) @@ -145,7 +148,8 @@ grub_loopback_iterate (int (*hook) (const char *name)) } 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_disk_pull_t pull __attribute__ ((unused))) { struct grub_loopback *dev; diff --git a/grub-core/disk/lvm.c b/grub-core/disk/lvm.c index 206e3e220..72f493540 100644 --- a/grub-core/disk/lvm.c +++ b/grub-core/disk/lvm.c @@ -32,7 +32,12 @@ GRUB_MOD_LICENSE ("GPLv3+"); static struct grub_lvm_vg *vg_list; static int lv_count; +static int scan_depth = 0; +static int is_lv_readable (struct grub_lvm_lv *lv); + +static int +grub_lvm_scan_device (const char *name); /* Go the string STR and return the number after STR. *P will point at the number. In case STR is not found, *P will be NULL and the @@ -96,16 +101,39 @@ grub_lvm_check_flag (char *p, char *str, char *flag) } static int -grub_lvm_iterate (int (*hook) (const char *name)) +grub_lvm_iterate (int (*hook) (const char *name), + grub_disk_pull_t pull) { struct grub_lvm_vg *vg; + unsigned old_count = 0; + if (pull == GRUB_DISK_PULL_RESCAN && scan_depth) + return 0; + + if (pull == GRUB_DISK_PULL_RESCAN) + { + old_count = lv_count; + if (!scan_depth) + { + scan_depth++; + grub_device_iterate (&grub_lvm_scan_device); + scan_depth--; + } + } + if (pull != GRUB_DISK_PULL_RESCAN && pull != GRUB_DISK_PULL_NONE) + return GRUB_ERR_NONE; for (vg = vg_list; vg; vg = vg->next) { struct grub_lvm_lv *lv; if (vg->lvs) for (lv = vg->lvs; lv; lv = lv->next) - if (lv->visible && hook (lv->name)) - return 1; + if (lv->visible && lv->number >= old_count) + { + char lvname[sizeof ("lvm/") + grub_strlen (lv->name)]; + grub_memcpy (lvname, "lvm/", sizeof ("lvm/") - 1); + grub_strcpy (lvname + sizeof ("lvm/") - 1, lv->name); + if (hook (lvname)) + return 1; + } } return 0; @@ -135,8 +163,8 @@ grub_lvm_memberlist (grub_disk_t disk) } #endif -static grub_err_t -grub_lvm_open (const char *name, grub_disk_t disk) +static struct grub_lvm_lv * +find_lv (const char *name) { struct grub_lvm_vg *vg; struct grub_lvm_lv *lv = NULL; @@ -144,11 +172,43 @@ grub_lvm_open (const char *name, grub_disk_t disk) { if (vg->lvs) for (lv = vg->lvs; lv; lv = lv->next) - if (! grub_strcmp (lv->name, name)) - break; + if (! grub_strcmp (lv->name, name) && is_lv_readable (lv)) + return lv; + } + return NULL; +} - if (lv) - break; +static const char *scan_for = NULL; + +static grub_err_t +grub_lvm_open (const char *name, grub_disk_t disk, + grub_disk_pull_t pull) +{ + struct grub_lvm_lv *lv = NULL; + int explicit = 0; + + if (grub_memcmp (name, "lvm/", sizeof ("lvm/") - 1) == 0) + { + name += sizeof ("lvm/") - 1; + explicit = 1; + } + + lv = find_lv (name); + + if (! lv && !scan_depth && + pull == (explicit ? GRUB_DISK_PULL_RESCAN : GRUB_DISK_PULL_RESCAN_UNTYPED)) + { + scan_for = name; + scan_depth++; + grub_device_iterate (&grub_lvm_scan_device); + scan_depth--; + scan_for = NULL; + if (grub_errno) + { + grub_print_error (); + grub_errno = GRUB_ERR_NONE; + } + lv = find_lv (name); } if (! lv) @@ -285,6 +345,49 @@ read_lv (struct grub_lvm_lv *lv, grub_disk_addr_t sector, return grub_error (GRUB_ERR_IO, "unknown LVM segment"); } +static grub_err_t +is_node_readable (const struct grub_lvm_node *node) +{ + /* Check whether we actually know the physical volume we want to + read from. */ + if (node->pv) + return !!(node->pv->disk); + if (node->lv) + return is_lv_readable (node->lv); + return 0; +} + +static int +is_lv_readable (struct grub_lvm_lv *lv) +{ + unsigned int i, j; + + if (!lv) + return 0; + + /* Find the right segment. */ + for (i = 0; i < lv->segment_count; i++) + switch (lv->segments[i].type) + { + case GRUB_LVM_STRIPED: + for (j = 0; j < lv->segments[i].node_count; j++) + if (!is_node_readable (lv->segments[i].nodes + j)) + return 0; + break; + case GRUB_LVM_MIRROR: + for (j = 0; j < lv->segments[i].node_count; j++) + if (is_node_readable (lv->segments[i].nodes + j)) + break; + if (j == lv->segments[i].node_count) + return 0; + default: + return 0; + } + + return 1; +} + + static grub_err_t grub_lvm_read (grub_disk_t disk, grub_disk_addr_t sector, grub_size_t size, char *buf) @@ -332,6 +435,15 @@ grub_lvm_scan_device (const char *name) return 0; } + for (vg = vg_list; vg; vg = vg->next) + for (pv = vg->pvs; pv; pv = pv->next) + if (pv->disk && pv->disk->id == disk->id + && pv->disk->dev->id == disk->dev->id) + { + grub_disk_close (disk); + return 0; + } + /* Search for label. */ for (i = 0; i < GRUB_LVM_LABEL_SCAN_SECTORS; i++) { @@ -857,6 +969,8 @@ grub_lvm_scan_device (const char *name) if (grub_errno == GRUB_ERR_OUT_OF_RANGE) grub_errno = GRUB_ERR_NONE; grub_print_error (); + if (scan_for && find_lv (scan_for)) + return 1; return 0; } @@ -878,13 +992,6 @@ static struct grub_disk_dev grub_lvm_dev = GRUB_MOD_INIT(lvm) { - grub_device_iterate (&grub_lvm_scan_device); - if (grub_errno) - { - grub_print_error (); - grub_errno = GRUB_ERR_NONE; - } - grub_disk_dev_register (&grub_lvm_dev); } diff --git a/grub-core/disk/memdisk.c b/grub-core/disk/memdisk.c index 114ac0d9e..775234055 100644 --- a/grub-core/disk/memdisk.c +++ b/grub-core/disk/memdisk.c @@ -30,13 +30,18 @@ static char *memdisk_addr; static grub_off_t memdisk_size = 0; static int -grub_memdisk_iterate (int (*hook) (const char *name)) +grub_memdisk_iterate (int (*hook) (const char *name), + grub_disk_pull_t pull) { + if (pull != GRUB_DISK_PULL_NONE) + return 0; + return hook ("memdisk"); } static grub_err_t -grub_memdisk_open (const char *name, grub_disk_t disk) +grub_memdisk_open (const char *name, grub_disk_t disk, + grub_disk_pull_t pull __attribute__ ((unused))) { if (grub_strcmp (name, "memdisk")) return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "not a memdisk"); diff --git a/grub-core/disk/raid.c b/grub-core/disk/raid.c index 946e6d2c2..78453ac88 100644 --- a/grub-core/disk/raid.c +++ b/grub-core/disk/raid.c @@ -33,6 +33,11 @@ GRUB_MOD_LICENSE ("GPLv3+"); static struct grub_raid_array *array_list; grub_raid5_recover_func_t grub_raid5_recover_func; grub_raid6_recover_func_t grub_raid6_recover_func; +static grub_raid_t grub_raid_list; +static int inscnt = 0; + +static struct grub_raid_array * +find_array (const char *name); static char @@ -78,14 +83,98 @@ grub_is_array_readable (struct grub_raid_array *array) return 0; } +static grub_err_t +insert_array (grub_disk_t disk, struct grub_raid_array *new_array, + grub_disk_addr_t start_sector, const char *scanner_name, + grub_raid_t raid __attribute__ ((unused))); + +static int scan_depth = 0; + +static void +scan_devices (const char *arname) +{ + grub_raid_t raid; + + auto int hook (const char *name); + int hook (const char *name) + { + grub_disk_t disk; + struct grub_raid_array array; + struct grub_raid_array *arr; + grub_disk_addr_t start_sector; + + grub_dprintf ("raid", "Scanning for %s RAID devices on disk %s\n", + raid->name, name); +#ifdef GRUB_UTIL + grub_util_info ("Scanning for %s RAID devices on disk %s", + raid->name, name); +#endif + + disk = grub_disk_open (name); + if (!disk) + return 0; + + for (arr = array_list; arr != NULL; arr = arr->next) + { + struct grub_raid_member *m; + for (m = arr->members; m < arr->members + arr->nr_devs; m++) + if (m->device && m->device->id == disk->id + && m->device->dev->id == m->device->dev->id) + { + grub_disk_close (disk); + return 0; + } + } + + if ((disk->total_sectors != GRUB_ULONG_MAX) && + (! raid->detect (disk, &array, &start_sector)) && + (! insert_array (disk, &array, start_sector, raid->name, + raid))) + return 0; + + /* This error usually means it's not raid, no need to display + it. */ + if (grub_errno != GRUB_ERR_OUT_OF_RANGE) + grub_print_error (); + + grub_errno = GRUB_ERR_NONE; + + grub_disk_close (disk); + + if (arname && find_array (arname)) + return 1; + + return 0; + } + + if (scan_depth) + return; + + scan_depth++; + for (raid = grub_raid_list; raid; raid = raid->next) + grub_device_iterate (&hook); + scan_depth--; +} + static int -grub_raid_iterate (int (*hook) (const char *name)) +grub_raid_iterate (int (*hook) (const char *name), + grub_disk_pull_t pull) { struct grub_raid_array *array; + int islcnt = 0; + + if (pull == GRUB_DISK_PULL_RESCAN) + { + islcnt = inscnt; + scan_devices (NULL); + } + + if (pull != GRUB_DISK_PULL_NONE && pull != GRUB_DISK_PULL_RESCAN) + return 0; for (array = array_list; array != NULL; array = array->next) { - if (grub_is_array_readable (array)) + if (grub_is_array_readable (array) && array->became_readable_at >= islcnt) if (hook (array->name)) return 1; } @@ -134,11 +223,10 @@ ascii2hex (char c) return 0; } -static grub_err_t -grub_raid_open (const char *name, grub_disk_t disk) +static struct grub_raid_array * +find_array (const char *name) { struct grub_raid_array *array; - unsigned n; if (grub_memcmp (name, "mduuid/", sizeof ("mduuid/") - 1) == 0) { @@ -155,7 +243,7 @@ grub_raid_open (const char *name, grub_disk_t disk) if (uuid_len == (unsigned) array->uuid_len && grub_memcmp (uuidbin, array->uuid, uuid_len) == 0) if (grub_is_array_readable (array)) - break; + return array; } } else @@ -163,8 +251,33 @@ grub_raid_open (const char *name, grub_disk_t disk) { if (!grub_strcmp (array->name, name)) if (grub_is_array_readable (array)) - break; + return array; } + return NULL; +} + +static grub_err_t +grub_raid_open (const char *name, grub_disk_t disk, grub_disk_pull_t pull) +{ + struct grub_raid_array *array; + unsigned n; + + if (grub_memcmp (name, "md", sizeof ("md") - 1) != 0) + return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "unknown RAID device %s", + name); + + array = find_array (name); + + if (! array && pull == GRUB_DISK_PULL_RESCAN) + { + scan_devices (name); + if (grub_errno) + { + grub_print_error (); + grub_errno = GRUB_ERR_NONE; + } + array = find_array (name); + } if (!array) return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "unknown RAID device %s", @@ -690,15 +803,19 @@ insert_array (grub_disk_t disk, struct grub_raid_array *new_array, } /* Add the device to the array. */ - array->members[new_array->index].device = disk; - array->members[new_array->index].start_sector = start_sector; - array->nr_devs++; + { + int was_readable = grub_is_array_readable (array); + + array->members[new_array->index].device = disk; + array->members[new_array->index].start_sector = start_sector; + array->nr_devs++; + if (!was_readable && grub_is_array_readable (array)) + array->became_readable_at = inscnt++; + } return 0; } -static grub_raid_t grub_raid_list; - static void free_array (void) { @@ -729,45 +846,8 @@ free_array (void) void grub_raid_register (grub_raid_t raid) { - auto int hook (const char *name); - int hook (const char *name) - { - grub_disk_t disk; - struct grub_raid_array array; - grub_disk_addr_t start_sector; - - grub_dprintf ("raid", "Scanning for %s RAID devices on disk %s\n", - grub_raid_list->name, name); -#ifdef GRUB_UTIL - grub_util_info ("Scanning for %s RAID devices on disk %s", - grub_raid_list->name, name); -#endif - - disk = grub_disk_open (name); - if (!disk) - return 0; - - if ((disk->total_sectors != GRUB_ULONG_MAX) && - (! grub_raid_list->detect (disk, &array, &start_sector)) && - (! insert_array (disk, &array, start_sector, grub_raid_list->name, - grub_raid_list))) - return 0; - - /* This error usually means it's not raid, no need to display - it. */ - if (grub_errno != GRUB_ERR_OUT_OF_RANGE) - grub_print_error (); - - grub_errno = GRUB_ERR_NONE; - - grub_disk_close (disk); - - return 0; - } - raid->next = grub_raid_list; grub_raid_list = raid; - grub_device_iterate (&hook); } void diff --git a/grub-core/disk/scsi.c b/grub-core/disk/scsi.c index 25f0e3aea..e85036860 100644 --- a/grub-core/disk/scsi.c +++ b/grub-core/disk/scsi.c @@ -316,7 +316,8 @@ grub_scsi_write12 (grub_disk_t disk, grub_disk_addr_t sector, static int -grub_scsi_iterate (int (*hook) (const char *name)) +grub_scsi_iterate (int (*hook) (const char *name), + grub_disk_pull_t pull) { grub_scsi_dev_t p; @@ -356,6 +357,9 @@ grub_scsi_iterate (int (*hook) (const char *name)) return 0; } + if (pull != GRUB_DISK_PULL_NONE) + return 0; + for (p = grub_scsi_dev_list; p; p = p->next) if (p->iterate && (p->iterate) (scsi_iterate)) return 1; @@ -364,7 +368,8 @@ grub_scsi_iterate (int (*hook) (const char *name)) } static grub_err_t -grub_scsi_open (const char *name, grub_disk_t disk) +grub_scsi_open (const char *name, grub_disk_t disk, + grub_disk_pull_t pull __attribute__ ((unused))) { grub_scsi_dev_t p; grub_scsi_t scsi; diff --git a/grub-core/fs/i386/pc/pxe.c b/grub-core/fs/i386/pc/pxe.c index d6dc2c22d..929f44587 100644 --- a/grub-core/fs/i386/pc/pxe.c +++ b/grub-core/fs/i386/pc/pxe.c @@ -104,8 +104,12 @@ grub_pxe_scan (void) } static int -grub_pxe_iterate (int (*hook) (const char *name)) +grub_pxe_iterate (int (*hook) (const char *name), + grub_disk_pull_t pull) { + if (pull != GRUB_DISK_PULL_NONE) + return 0; + if (hook ("pxe")) return 1; return 0; @@ -139,7 +143,8 @@ parse_ip (const char *val, grub_uint32_t *ip, const char **rest) } static grub_err_t -grub_pxe_open (const char *name, grub_disk_t disk) +grub_pxe_open (const char *name, grub_disk_t disk, + grub_disk_pull_t pull __attribute__ ((unused))) { struct grub_pxe_disk_data *data; diff --git a/grub-core/kern/disk.c b/grub-core/kern/disk.c index 807ee4277..9c2c70b80 100644 --- a/grub-core/kern/disk.c +++ b/grub-core/kern/disk.c @@ -207,10 +207,16 @@ int grub_disk_dev_iterate (int (*hook) (const char *name)) { grub_disk_dev_t p; + grub_disk_pull_t pull; - for (p = grub_disk_dev_list; p; p = p->next) - if (p->iterate && (p->iterate) (hook)) - return 1; + for (pull = 0; pull < GRUB_DISK_PULL_MAX; pull++) + { + if (pull == GRUB_DISK_PULL_RESCAN_UNTYPED) + continue; + for (p = grub_disk_dev_list; p; p = p->next) + if (p->iterate && (p->iterate) (hook, pull)) + return 1; + } return 0; } @@ -241,6 +247,7 @@ grub_disk_open (const char *name) grub_disk_dev_t dev; char *raw = (char *) name; grub_uint64_t current_time; + grub_disk_pull_t pull; grub_dprintf ("disk", "Opening `%s'...\n", name); @@ -266,15 +273,19 @@ grub_disk_open (const char *name) if (! disk->name) goto fail; - - for (dev = grub_disk_dev_list; dev; dev = dev->next) + for (pull = 0; pull < GRUB_DISK_PULL_MAX; pull++) { - if ((dev->open) (raw, disk) == GRUB_ERR_NONE) + for (dev = grub_disk_dev_list; dev; dev = dev->next) + { + if ((dev->open) (raw, disk, pull) == GRUB_ERR_NONE) + break; + else if (grub_errno == GRUB_ERR_UNKNOWN_DEVICE) + grub_errno = GRUB_ERR_NONE; + else + goto fail; + } + if (dev) break; - else if (grub_errno == GRUB_ERR_UNKNOWN_DEVICE) - grub_errno = GRUB_ERR_NONE; - else - goto fail; } if (! dev) diff --git a/grub-core/kern/emu/hostdisk.c b/grub-core/kern/emu/hostdisk.c index 63bca37ee..3ee6174d0 100644 --- a/grub-core/kern/emu/hostdisk.c +++ b/grub-core/kern/emu/hostdisk.c @@ -212,7 +212,8 @@ find_free_slot (void) } static int -grub_util_biosdisk_iterate (int (*hook) (const char *name)) +grub_util_biosdisk_iterate (int (*hook) (const char *name), + grub_disk_pull_t pull) { unsigned i; @@ -224,7 +225,8 @@ grub_util_biosdisk_iterate (int (*hook) (const char *name)) } static grub_err_t -grub_util_biosdisk_open (const char *name, grub_disk_t disk) +grub_util_biosdisk_open (const char *name, grub_disk_t disk, + grub_disk_pull_t pull __attribute__ ((unused))) { int drive; struct stat st; diff --git a/include/grub/disk.h b/include/grub/disk.h index 66db1149a..2678ad5eb 100644 --- a/include/grub/disk.h +++ b/include/grub/disk.h @@ -50,6 +50,15 @@ struct grub_disk; struct grub_disk_memberlist; #endif +typedef enum + { + GRUB_DISK_PULL_NONE, + GRUB_DISK_PULL_REMOVABLE, + GRUB_DISK_PULL_RESCAN, + GRUB_DISK_PULL_RESCAN_UNTYPED, + GRUB_DISK_PULL_MAX + } grub_disk_pull_t; + /* Disk device. */ struct grub_disk_dev { @@ -60,10 +69,12 @@ struct grub_disk_dev enum grub_disk_dev_id id; /* Call HOOK with each device name, until HOOK returns non-zero. */ - int (*iterate) (int (*hook) (const char *name)); + int (*iterate) (int (*hook) (const char *name), + grub_disk_pull_t pull); /* Open the device named NAME, and set up DISK. */ - grub_err_t (*open) (const char *name, struct grub_disk *disk); + grub_err_t (*open) (const char *name, struct grub_disk *disk, + grub_disk_pull_t pull); /* Close the disk DISK. */ void (*close) (struct grub_disk *disk); diff --git a/include/grub/raid.h b/include/grub/raid.h index d5853639d..1eb43721a 100644 --- a/include/grub/raid.h +++ b/include/grub/raid.h @@ -42,6 +42,7 @@ struct grub_raid_array int number; /* The device number, taken from md_minor so we are consistent with the device name in Linux. */ + int became_readable_at; int level; /* RAID levels, only 0, 1 or 5 at the moment. */ int layout; /* Layout for RAID 5/6. */ unsigned int total_devs; /* Total number of devices in the array. */ From 5dad99b7304b4b2bb0daaa0c379420b4dd1955d5 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 22 Apr 2011 01:10:24 +0200 Subject: [PATCH 485/869] more linux-like name for LVM volumes --- grub-core/disk/lvm.c | 42 +++++++++++++++++++++++++++--------- grub-core/kern/emu/getroot.c | 10 +++------ include/grub/lvm.h | 2 ++ 3 files changed, 37 insertions(+), 17 deletions(-) diff --git a/grub-core/disk/lvm.c b/grub-core/disk/lvm.c index 72f493540..c430f596d 100644 --- a/grub-core/disk/lvm.c +++ b/grub-core/disk/lvm.c @@ -172,7 +172,9 @@ find_lv (const char *name) { if (vg->lvs) for (lv = vg->lvs; lv; lv = lv->next) - if (! grub_strcmp (lv->name, name) && is_lv_readable (lv)) + if ((grub_strcmp (lv->fullname, name) == 0 + || grub_strcmp (lv->compatname, name) == 0) + && is_lv_readable (lv)) return lv; } return NULL; @@ -188,10 +190,7 @@ grub_lvm_open (const char *name, grub_disk_t disk, int explicit = 0; if (grub_memcmp (name, "lvm/", sizeof ("lvm/") - 1) == 0) - { - name += sizeof ("lvm/") - 1; - explicit = 1; - } + explicit = 1; lv = find_lv (name); @@ -685,11 +684,34 @@ grub_lvm_scan_device (const char *name) q++; s = q - p; - lv->name = grub_malloc (vgname_len + 1 + s + 1); - grub_memcpy (lv->name, vgname, vgname_len); - lv->name[vgname_len] = '-'; - grub_memcpy (lv->name + vgname_len + 1, p, s); - lv->name[vgname_len + 1 + s] = '\0'; + lv->name = grub_strndup (p, s); + lv->compatname = grub_malloc (vgname_len + 1 + s + 1); + grub_memcpy (lv->compatname, vgname, vgname_len); + lv->compatname[vgname_len] = '-'; + grub_memcpy (lv->compatname + vgname_len + 1, p, s); + lv->compatname[vgname_len + 1 + s] = '\0'; + + { + const char *iptr; + char *optr; + lv->fullname = grub_malloc (sizeof("lvm/") + 2 * vgname_len + + 1 + 2 * s + 1); + optr = lv->fullname; + for (iptr = vgname; iptr < vgname + vgname_len; iptr++) + { + *optr++ = *iptr; + if (*iptr == '-') + *optr++ = '-'; + } + *optr++ = '-'; + for (iptr = p; iptr < p + s; iptr++) + { + *optr++ = *iptr; + if (*iptr == '-') + *optr++ = '-'; + } + *optr++ = 0; + } lv->size = 0; diff --git a/grub-core/kern/emu/getroot.c b/grub-core/kern/emu/getroot.c index f836a6625..c780fd94d 100644 --- a/grub-core/kern/emu/getroot.c +++ b/grub-core/kern/emu/getroot.c @@ -783,14 +783,10 @@ grub_util_get_grub_dev (const char *os_dev) grub_size_t offset = sizeof ("/dev/mapper/") - 1; len = strlen (os_dev) - offset + 1; - grub_dev = xmalloc (len); + grub_dev = xmalloc (len + sizeof ("lvm/")); - for (i = 0; i < len; i++, offset++) - { - grub_dev[i] = os_dev[offset]; - if (os_dev[offset] == '-' && os_dev[offset + 1] == '-') - offset++; - } + grub_memcpy (grub_dev, "lvm/", sizeof ("lvm/") - 1); + grub_memcpy (grub_dev + sizeof ("lvm/") - 1, os_dev + offset, len); } break; diff --git a/include/grub/lvm.h b/include/grub/lvm.h index b962dfd6c..b5352c75c 100644 --- a/include/grub/lvm.h +++ b/include/grub/lvm.h @@ -44,6 +44,8 @@ struct grub_lvm_pv { struct grub_lvm_lv { char *name; + char *fullname; + char *compatname; unsigned int number; unsigned int segment_count; grub_uint64_t size; From 65b4742cd70d15d41483582b454f21144b9ba60e Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 22 Apr 2011 02:46:36 +0200 Subject: [PATCH 486/869] Add lost lvm/ prefix. Autoadd lvm subdevices. --- grub-core/disk/lvm.c | 20 ++++++ grub-core/kern/emu/getroot.c | 120 ++++++++++++++++++++++++++--------- include/grub/emu/hostdisk.h | 1 + 3 files changed, 111 insertions(+), 30 deletions(-) diff --git a/grub-core/disk/lvm.c b/grub-core/disk/lvm.c index c430f596d..d104be750 100644 --- a/grub-core/disk/lvm.c +++ b/grub-core/disk/lvm.c @@ -26,6 +26,7 @@ #ifdef GRUB_UTIL #include +#include #endif GRUB_MOD_LICENSE ("GPLv3+"); @@ -197,6 +198,16 @@ grub_lvm_open (const char *name, grub_disk_t disk, if (! lv && !scan_depth && pull == (explicit ? GRUB_DISK_PULL_RESCAN : GRUB_DISK_PULL_RESCAN_UNTYPED)) { +#ifdef GRUB_UTIL + if (explicit) + { + char buf[grub_strlen (name) + sizeof ("/dev/mapper/")]; + grub_memcpy (buf, "/dev/mapper/", sizeof ("/dev/mapper/")); + grub_strcpy (buf + sizeof ("/dev/mapper/") - 1, + name + sizeof ("lvm/") - 1); + grub_util_pull_device (buf); + } +#endif scan_for = name; scan_depth++; grub_device_iterate (&grub_lvm_scan_device); @@ -685,7 +696,11 @@ grub_lvm_scan_device (const char *name) s = q - p; lv->name = grub_strndup (p, s); + if (!lv->name) + goto lvs_fail; lv->compatname = grub_malloc (vgname_len + 1 + s + 1); + if (!lv->compatname) + goto lvs_fail; grub_memcpy (lv->compatname, vgname, vgname_len); lv->compatname[vgname_len] = '-'; grub_memcpy (lv->compatname + vgname_len + 1, p, s); @@ -696,7 +711,12 @@ grub_lvm_scan_device (const char *name) char *optr; lv->fullname = grub_malloc (sizeof("lvm/") + 2 * vgname_len + 1 + 2 * s + 1); + if (!lv->fullname) + goto lvs_fail; + optr = lv->fullname; + grub_memcpy (optr, "lvm/", sizeof ("lvm/") - 1); + optr += sizeof ("lvm/") - 1; for (iptr = vgname; iptr < vgname + vgname_len; iptr++) { *optr++ = *iptr; diff --git a/grub-core/kern/emu/getroot.c b/grub-core/kern/emu/getroot.c index dd277d705..474bb42bc 100644 --- a/grub-core/kern/emu/getroot.c +++ b/grub-core/kern/emu/getroot.c @@ -640,6 +640,56 @@ grub_guess_root_device (const char *dir) return os_dev; } +#ifdef HAVE_DEVICE_MAPPER + +static int +grub_util_open_dm (const char *os_dev, struct dm_tree **tree, + struct dm_tree_node **node) +{ + uint32_t maj, min; + struct stat st; + + *node = NULL; + *tree = NULL; + + if ((strncmp ("/dev/mapper/", os_dev, 12) != 0)) + return 0; + + if (stat (os_dev, &st) < 0) + return 0; + + *tree = dm_tree_create (); + if (! *tree) + { + grub_printf ("Failed to create tree\n"); + grub_dprintf ("hostdisk", "dm_tree_create failed\n"); + return 0; + } + + maj = major (st.st_rdev); + min = minor (st.st_rdev); + + if (! dm_tree_add_dev (*tree, maj, min)) + { + grub_dprintf ("hostdisk", "dm_tree_add_dev failed\n"); + dm_tree_free (*tree); + *tree = NULL; + return 0; + } + + *node = dm_tree_find_node (*tree, maj, min); + if (! *node) + { + grub_dprintf ("hostdisk", "dm_tree_find_node failed\n"); + dm_tree_free (*tree); + *tree = NULL; + return 0; + } + return 1; +} + +#endif + static int grub_util_is_lvm (const char *os_dev) { @@ -648,40 +698,13 @@ grub_util_is_lvm (const char *os_dev) #ifdef HAVE_DEVICE_MAPPER { - struct dm_tree *tree; - uint32_t maj, min; - struct dm_tree_node *node = NULL; const char *node_uuid; - struct stat st; + struct dm_tree *tree; + struct dm_tree_node *node; - if (stat (os_dev, &st) < 0) + if (!grub_util_open_dm (os_dev, &tree, &node)) return 0; - tree = dm_tree_create (); - if (! tree) - { - grub_printf ("Failed to create tree\n"); - grub_dprintf ("hostdisk", "dm_tree_create failed\n"); - return 0; - } - - maj = major (st.st_rdev); - min = minor (st.st_rdev); - - if (! dm_tree_add_dev (tree, maj, min)) - { - grub_dprintf ("hostdisk", "dm_tree_add_dev failed\n"); - dm_tree_free (tree); - return 0; - } - - node = dm_tree_find_node (tree, maj, min); - if (! node) - { - grub_dprintf ("hostdisk", "dm_tree_find_node failed\n"); - dm_tree_free (tree); - return 0; - } node_uuid = dm_tree_node_get_uuid (node); if (! node_uuid) { @@ -804,6 +827,43 @@ out: } #endif /* __linux__ */ +void +grub_util_pull_device (const char *os_dev) +{ + switch (grub_util_get_dev_abstraction (os_dev)) + { + case GRUB_DEV_ABSTRACTION_LVM: +#ifdef HAVE_DEVICE_MAPPER + { + struct dm_tree *tree; + struct dm_tree_node *node; + struct dm_tree_node *child; + void *handle = NULL; + + if (!grub_util_open_dm (os_dev, &tree, &node)) + return; + + while ((child = dm_tree_next_child (&handle, node, 0))) + { + const struct dm_info *dm = dm_tree_node_get_info (child); + char *subdev; + if (!dm) + continue; + subdev = grub_find_device ("/dev", makedev (dm->major, dm->minor)); + if (subdev) + grub_util_pull_device (subdev); + } + dm_tree_free (tree); + return; + } +#endif + + default: /* GRUB_DEV_ABSTRACTION_NONE */ + grub_util_biosdisk_get_grub_dev (os_dev); + return; + } +} + char * grub_util_get_grub_dev (const char *os_dev) { diff --git a/include/grub/emu/hostdisk.h b/include/grub/emu/hostdisk.h index 842dff496..803c0f755 100644 --- a/include/grub/emu/hostdisk.h +++ b/include/grub/emu/hostdisk.h @@ -29,5 +29,6 @@ const char *grub_util_biosdisk_get_osdev (grub_disk_t disk); int grub_util_biosdisk_is_present (const char *name); int grub_util_biosdisk_is_floppy (grub_disk_t disk); grub_err_t grub_util_biosdisk_flush (struct grub_disk *disk); +void grub_util_pull_device (const char *osname); #endif /* ! GRUB_BIOSDISK_MACHINE_UTIL_HEADER */ From 4defebbec8eeae0909c6912d757e2a2f510dae78 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 22 Apr 2011 13:55:30 +0200 Subject: [PATCH 487/869] automatic raid members addition --- Makefile.util.def | 2 +- grub-core/Makefile.core.def | 1 + grub-core/disk/lvm.c | 10 ---------- grub-core/kern/emu/getroot.c | 15 ++++++++++++++- {util => grub-core/kern/emu}/raid.c | 12 +++++++++--- include/grub/emu/getroot.h | 3 +++ include/grub/util/raid.h | 27 --------------------------- util/grub-setup.c | 5 ++--- 8 files changed, 30 insertions(+), 45 deletions(-) rename {util => grub-core/kern/emu}/raid.c (84%) delete mode 100644 include/grub/util/raid.h diff --git a/Makefile.util.def b/Makefile.util.def index 058572f06..40c67c233 100644 --- a/Makefile.util.def +++ b/Makefile.util.def @@ -10,6 +10,7 @@ library = { common = grub-core/kern/device.c; common = grub-core/kern/disk.c; common = grub-core/kern/emu/getroot.c; + common = grub-core/kern/emu/raid.c; common = grub-core/kern/emu/hostdisk.c; common = grub-core/kern/emu/misc.c; common = grub-core/kern/emu/mm.c; @@ -265,7 +266,6 @@ program = { installdir = sbin; mansection = 8; common = util/grub-setup.c; - common = util/raid.c; common = util/lvm.c; common = grub-core/lib/reed_solomon.c; diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def index f4d38149d..4146e3841 100644 --- a/grub-core/Makefile.core.def +++ b/grub-core/Makefile.core.def @@ -165,6 +165,7 @@ kernel = { emu = kern/emu/cache.S; emu = kern/emu/console.c; emu = kern/emu/getroot.c; + emu = kern/emu/raid.c; emu = kern/emu/hostdisk.c; emu = kern/emu/hostfs.c; emu = kern/emu/main.c; diff --git a/grub-core/disk/lvm.c b/grub-core/disk/lvm.c index d104be750..b86cd8023 100644 --- a/grub-core/disk/lvm.c +++ b/grub-core/disk/lvm.c @@ -198,16 +198,6 @@ grub_lvm_open (const char *name, grub_disk_t disk, if (! lv && !scan_depth && pull == (explicit ? GRUB_DISK_PULL_RESCAN : GRUB_DISK_PULL_RESCAN_UNTYPED)) { -#ifdef GRUB_UTIL - if (explicit) - { - char buf[grub_strlen (name) + sizeof ("/dev/mapper/")]; - grub_memcpy (buf, "/dev/mapper/", sizeof ("/dev/mapper/")); - grub_strcpy (buf + sizeof ("/dev/mapper/") - 1, - name + sizeof ("lvm/") - 1); - grub_util_pull_device (buf); - } -#endif scan_for = name; scan_depth++; grub_device_iterate (&grub_lvm_scan_device); diff --git a/grub-core/kern/emu/getroot.c b/grub-core/kern/emu/getroot.c index 474bb42bc..d9c1c9e08 100644 --- a/grub-core/kern/emu/getroot.c +++ b/grub-core/kern/emu/getroot.c @@ -854,9 +854,20 @@ grub_util_pull_device (const char *os_dev) grub_util_pull_device (subdev); } dm_tree_free (tree); - return; } #endif + return; + case GRUB_DEV_ABSTRACTION_RAID: +#ifdef __linux__ + { + char **devicelist = grub_util_raid_getmembers (os_dev, 0); + int i; + for (i = 0; devicelist[i];i++) + grub_util_pull_device (devicelist[i]); + free (devicelist); + } +#endif + return; default: /* GRUB_DEV_ABSTRACTION_NONE */ grub_util_biosdisk_get_grub_dev (os_dev); @@ -869,6 +880,8 @@ grub_util_get_grub_dev (const char *os_dev) { char *grub_dev = NULL; + grub_util_pull_device (os_dev); + switch (grub_util_get_dev_abstraction (os_dev)) { case GRUB_DEV_ABSTRACTION_LVM: diff --git a/util/raid.c b/grub-core/kern/emu/raid.c similarity index 84% rename from util/raid.c rename to grub-core/kern/emu/raid.c index a6aa5f95e..1371117da 100644 --- a/util/raid.c +++ b/grub-core/kern/emu/raid.c @@ -21,7 +21,6 @@ #ifdef __linux__ #include #include -#include #include #include @@ -36,7 +35,7 @@ #include char ** -grub_util_raid_getmembers (const char *name) +grub_util_raid_getmembers (const char *name, int bootable) { int fd, ret, i, j; char **devicelist; @@ -53,7 +52,14 @@ grub_util_raid_getmembers (const char *name) if (ret != 0) grub_util_error ("ioctl RAID_VERSION error: %s", strerror (errno)); - if (version.major != 0 || version.minor != 90) + if ((version.major != 0 || version.minor != 90) + && (version.major != 1 || version.minor != 0) + && (version.major != 1 || version.minor != 1) + && (version.major != 1 || version.minor != 2)) + grub_util_error ("unsupported RAID version: %d.%d", + version.major, version.minor); + + if (bootable && (version.major != 0 || version.minor != 90)) grub_util_error ("unsupported RAID version: %d.%d", version.major, version.minor); diff --git a/include/grub/emu/getroot.h b/include/grub/emu/getroot.h index 581ea8056..702903ee6 100644 --- a/include/grub/emu/getroot.h +++ b/include/grub/emu/getroot.h @@ -34,5 +34,8 @@ char *grub_util_get_grub_dev (const char *os_dev); char *grub_make_system_path_relative_to_its_root (const char *path); const char *grub_util_check_block_device (const char *blk_dev); const char *grub_util_check_char_device (const char *blk_dev); +#ifdef __linux__ +char **grub_util_raid_getmembers (const char *name, int bootable); +#endif #endif /* ! GRUB_UTIL_GETROOT_HEADER */ diff --git a/include/grub/util/raid.h b/include/grub/util/raid.h deleted file mode 100644 index 4da5eaaa8..000000000 --- a/include/grub/util/raid.h +++ /dev/null @@ -1,27 +0,0 @@ -/* raid.h - RAID support for GRUB utils. */ -/* - * GRUB -- GRand Unified Bootloader - * Copyright (C) 2006,2007 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 . - */ - -#ifndef GRUB_RAID_UTIL_HEADER -#define GRUB_RAID_UTIL_HEADER 1 - -#ifdef __linux__ -char** grub_util_raid_getmembers (const char *name); -#endif - -#endif /* ! GRUB_RAID_UTIL_HEADER */ diff --git a/util/grub-setup.c b/util/grub-setup.c index 7d47fa654..8482e11c9 100644 --- a/util/grub-setup.c +++ b/util/grub-setup.c @@ -32,7 +32,6 @@ #include #include #include -#include #include #ifdef GRUB_MACHINE_IEEE1275 #include @@ -972,12 +971,12 @@ main (int argc, char *argv[]) int i; if (arguments.device[0] == '/') - devicelist = grub_util_raid_getmembers (arguments.device); + devicelist = grub_util_raid_getmembers (arguments.device, 1); else { char *devname; devname = xasprintf ("/dev/%s", dest_dev); - devicelist = grub_util_raid_getmembers (dest_dev); + devicelist = grub_util_raid_getmembers (dest_dev, 1); free (devname); } From 716aa45e40c96ddbe01403faa42355b22a4d4b96 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 22 Apr 2011 14:58:12 +0200 Subject: [PATCH 488/869] Fix LVM listing --- grub-core/disk/lvm.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/grub-core/disk/lvm.c b/grub-core/disk/lvm.c index b86cd8023..ec1780e32 100644 --- a/grub-core/disk/lvm.c +++ b/grub-core/disk/lvm.c @@ -129,10 +129,7 @@ grub_lvm_iterate (int (*hook) (const char *name), for (lv = vg->lvs; lv; lv = lv->next) if (lv->visible && lv->number >= old_count) { - char lvname[sizeof ("lvm/") + grub_strlen (lv->name)]; - grub_memcpy (lvname, "lvm/", sizeof ("lvm/") - 1); - grub_strcpy (lvname + sizeof ("lvm/") - 1, lv->name); - if (hook (lvname)) + if (hook (lv->fullname)) return 1; } } From f3470f4eb51026e410c687f10065a1fc797ba384 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 22 Apr 2011 16:32:27 +0200 Subject: [PATCH 489/869] restructure prior to adding cheatmounts --- grub-core/disk/luks.c | 302 +++++++++++++++++++++++------------------- 1 file changed, 166 insertions(+), 136 deletions(-) diff --git a/grub-core/disk/luks.c b/grub-core/disk/luks.c index 12a37b98b..4d907b4c6 100644 --- a/grub-core/disk/luks.c +++ b/grub-core/disk/luks.c @@ -75,6 +75,7 @@ struct grub_luks int ref; grub_crypto_cipher_handle_t cipher; grub_crypto_cipher_handle_t essiv_cipher; + const gcry_md_spec_t *essiv_hash, *hash; luks_mode_t mode; unsigned long id, source_id; enum grub_disk_dev_id source_dev_id; @@ -154,45 +155,28 @@ luks_decrypt (grub_crypto_cipher_handle_t cipher, luks_mode_t mode, static int check_uuid, have_it; static char *search_uuid; -static grub_err_t -grub_luks_scan_device_real (const char *name, grub_disk_t source) +static grub_luks_t +configure_ciphers (const struct grub_luks_phdr *header) { - grub_err_t err; - struct grub_luks_phdr header; + grub_luks_t newdev; + const char *iptr; + char *optr; + char uuid[sizeof (header->uuid) + 1]; + char ciphername[sizeof (header->cipherName) + 1]; + char ciphermode[sizeof (header->cipherMode) + 1]; + char hashspec[sizeof (header->hashSpec) + 1]; grub_crypto_cipher_handle_t cipher = NULL, essiv_cipher = NULL; const gcry_md_spec_t *hash = NULL, *essiv_hash = NULL; - grub_size_t keysize; - /* GCC thinks we may use this variable uninitialised. Silence the warning. */ - grub_size_t essiv_keysize = 0; - grub_uint8_t *hashed_key = NULL; - luks_mode_t mode; - grub_uint8_t *split_key = NULL; - unsigned i; - grub_size_t length; const struct gcry_cipher_spec *ciph; - char passphrase[MAX_PASSPHRASE] = ""; - grub_uint8_t candidate_digest[sizeof (header.mkDigest)]; - char uuid[sizeof (header.uuid) + 1]; - char *iptr, *optr; - - /* Read the LUKS header. */ - err = grub_disk_read (source, 0, 0, sizeof (header), &header); - if (err) - return err; - + luks_mode_t mode; + /* Look for LUKS magic sequence. */ - if (grub_memcmp (header.magic, LUKS_MAGIC, sizeof (header.magic)) - || grub_be_to_cpu16 (header.version) != 1) - return GRUB_ERR_NONE; - - /* Make sure that strings are null terminated. */ - header.cipherName[sizeof (header.cipherName) - 1] = 0; - header.cipherMode[sizeof (header.cipherMode) - 1] = 0; - header.hashSpec[sizeof (header.hashSpec) - 1] = 0; - header.uuid[sizeof (header.uuid) - 1] = 0; + if (grub_memcmp (header->magic, LUKS_MAGIC, sizeof (header->magic)) + || grub_be_to_cpu16 (header->version) != 1) + return NULL; optr = uuid; - for (iptr = header.uuid; iptr < &header.uuid[ARRAY_SIZE (header.uuid)]; + for (iptr = header->uuid; iptr < &header->uuid[ARRAY_SIZE (header->uuid)]; iptr++) { if (*iptr != '-') @@ -203,126 +187,163 @@ grub_luks_scan_device_real (const char *name, grub_disk_t source) if (check_uuid && grub_strcasecmp (search_uuid, uuid) != 0) { grub_dprintf ("luks", "%s != %s", uuid, search_uuid); - return 0; + return NULL; } - ciph = grub_crypto_lookup_cipher_by_name (header.cipherName); + /* Make sure that strings are null terminated. */ + grub_memcpy (ciphername, header->cipherName, sizeof (header->cipherName)); + ciphername[sizeof (header->cipherName)] = 0; + grub_memcpy (ciphermode, header->cipherMode, sizeof (header->cipherMode)); + ciphermode[sizeof (header->cipherMode)] = 0; + grub_memcpy (hashspec, header->hashSpec, sizeof (header->hashSpec)); + hashspec[sizeof (header->hashSpec)] = 0; + + ciph = grub_crypto_lookup_cipher_by_name (ciphername); if (!ciph) - return grub_error (GRUB_ERR_FILE_NOT_FOUND, "Cipher %s isn't available", - header.cipherName); + { + grub_error (GRUB_ERR_FILE_NOT_FOUND, "Cipher %s isn't available", + ciphername); + return NULL; + } /* Configure the cipher used for the bulk data. */ cipher = grub_crypto_cipher_open (ciph); if (!cipher) - return grub_errno; + return NULL; - keysize = grub_be_to_cpu32 (header.keyBytes); - if (keysize > 1024) - return grub_error (GRUB_ERR_BAD_ARGUMENT, "invalid keysize %d", keysize); + if (grub_be_to_cpu32 (header->keyBytes) > 1024) + { + grub_error (GRUB_ERR_BAD_ARGUMENT, "invalid keysize %d", + grub_be_to_cpu32 (header->keyBytes)); + return NULL; + } /* Configure the cipher mode. */ - if (grub_strncmp (header.cipherMode, "ecb", 3) == 0) + if (grub_strncmp (ciphermode, "ecb", 3) == 0) mode = GRUB_LUKS_MODE_ECB; - else if (grub_strncmp (header.cipherMode, "cbc-plain", 9) == 0 - || grub_strncmp (header.cipherMode, "plain", 5) == 0) + else if (grub_strncmp (ciphermode, "cbc-plain", 9) == 0 + || grub_strncmp (ciphermode, "plain", 5) == 0) mode = GRUB_LUKS_MODE_CBC_PLAIN; - else if (grub_strncmp (header.cipherMode, "cbc-essiv", 9) == 0) + else if (grub_strncmp (ciphermode, "cbc-essiv", 9) == 0) { mode = GRUB_LUKS_MODE_CBC_ESSIV; - char *hash_str = header.cipherMode + 10; + char *hash_str = ciphermode + 10; /* Configure the hash and cipher used for ESSIV. */ essiv_hash = grub_crypto_lookup_md_by_name (hash_str); if (!essiv_hash) { grub_crypto_cipher_close (cipher); - return grub_error (GRUB_ERR_FILE_NOT_FOUND, - "Couldn't load %s hash", hash_str); + grub_error (GRUB_ERR_FILE_NOT_FOUND, + "Couldn't load %s hash", hash_str); + return NULL; } essiv_cipher = grub_crypto_cipher_open (ciph); if (!cipher) { grub_crypto_cipher_close (cipher); - return grub_errno; - } - - essiv_keysize = essiv_hash->mdlen; - hashed_key = grub_malloc (essiv_hash->mdlen); - if (!hashed_key) - { - grub_crypto_cipher_close (cipher); - grub_crypto_cipher_close (essiv_cipher); - return grub_errno; + return NULL; } } else { grub_crypto_cipher_close (cipher); - return grub_error (GRUB_ERR_BAD_ARGUMENT, "Unknown cipher mode: %s", - header.cipherMode); + grub_error (GRUB_ERR_BAD_ARGUMENT, "Unknown cipher mode: %s", + ciphermode); + return NULL; } /* Configure the hash used for the AF splitter and HMAC. */ - hash = grub_crypto_lookup_md_by_name (header.hashSpec); + hash = grub_crypto_lookup_md_by_name (hashspec); if (!hash) { grub_crypto_cipher_close (cipher); grub_crypto_cipher_close (essiv_cipher); - grub_free (hashed_key); - return grub_error (GRUB_ERR_FILE_NOT_FOUND, "Couldn't load %s hash", - header.hashSpec); + grub_error (GRUB_ERR_FILE_NOT_FOUND, "Couldn't load %s hash", + hashspec); + return NULL; + } + + newdev = grub_zalloc (sizeof (struct grub_luks)); + if (!newdev) + return NULL; + newdev->cipher = cipher; + newdev->offset = grub_be_to_cpu32 (header->payloadOffset); + newdev->source_disk = NULL; + newdev->mode = mode; + newdev->essiv_cipher = essiv_cipher; + newdev->essiv_hash = essiv_hash; + newdev->hash = hash; + newdev->id = n++; + grub_memcpy (newdev->uuid, uuid, sizeof (newdev->uuid)); + return newdev; +} + +static grub_err_t +luks_recover_key (grub_luks_t dev, const struct grub_luks_phdr *header, + const char *name, grub_disk_t source) +{ + grub_size_t keysize = grub_be_to_cpu32 (header->keyBytes); + grub_uint8_t candidate_key[keysize]; + grub_uint8_t digest[keysize]; + grub_uint8_t *hashed_key = NULL; + grub_uint8_t *split_key = NULL; + char passphrase[MAX_PASSPHRASE] = ""; + grub_uint8_t candidate_digest[sizeof (header->mkDigest)]; + unsigned i; + grub_size_t essiv_keysize = 0; + grub_size_t length; + grub_err_t err; + + if (dev->mode == GRUB_LUKS_MODE_CBC_ESSIV) + essiv_keysize = dev->essiv_hash->mdlen; + hashed_key = grub_malloc (dev->essiv_hash->mdlen); + if (!hashed_key) + { + return grub_errno; } grub_printf ("Attempting to decrypt master key...\n"); - grub_uint8_t candidate_key[keysize]; - grub_uint8_t digest[keysize]; - split_key = grub_malloc (keysize * LUKS_STRIPES); if (!split_key) { - grub_crypto_cipher_close (cipher); - grub_crypto_cipher_close (essiv_cipher); grub_free (hashed_key); return grub_errno; } /* Get the passphrase from the user. */ - grub_printf ("Enter passphrase for %s (%s): ", name, uuid); + grub_printf ("Enter passphrase for %s (%s): ", name, dev->uuid); if (!grub_password_get (passphrase, MAX_PASSPHRASE)) { - grub_crypto_cipher_close (cipher); - grub_crypto_cipher_close (essiv_cipher); grub_free (hashed_key); grub_free (split_key); return grub_error (GRUB_ERR_BAD_ARGUMENT, "Passphrase not supplied"); } /* Try to recover master key from each active keyslot. */ - for (i = 0; i < ARRAY_SIZE (header.keyblock); i++) + for (i = 0; i < ARRAY_SIZE (header->keyblock); i++) { gcry_err_code_t gcry_err; /* Check if keyslot is enabled. */ - if (grub_be_to_cpu32 (header.keyblock[i].active) != LUKS_KEY_ENABLED) + if (grub_be_to_cpu32 (header->keyblock[i].active) != LUKS_KEY_ENABLED) continue; grub_dprintf ("luks", "Trying keyslot %d\n", i); /* Calculate the PBKDF2 of the user supplied passphrase. */ - gcry_err = grub_crypto_pbkdf2 (hash, (grub_uint8_t *) passphrase, + gcry_err = grub_crypto_pbkdf2 (dev->hash, (grub_uint8_t *) passphrase, grub_strlen (passphrase), - header.keyblock[i].passwordSalt, - sizeof (header. + header->keyblock[i].passwordSalt, + sizeof (header-> keyblock[i].passwordSalt), - grub_be_to_cpu32 (header.keyblock[i]. + grub_be_to_cpu32 (header->keyblock[i]. passwordIterations), digest, keysize); if (gcry_err) { - grub_crypto_cipher_close (cipher); - grub_crypto_cipher_close (essiv_cipher); grub_free (hashed_key); grub_free (split_key); return grub_crypto_gcry_error (gcry_err); @@ -331,60 +352,52 @@ grub_luks_scan_device_real (const char *name, grub_disk_t source) grub_dprintf ("luks", "PBKDF2 done\n"); /* Set the PBKDF2 output as the cipher key. */ - gcry_err = grub_crypto_cipher_set_key (cipher, digest, keysize); + gcry_err = grub_crypto_cipher_set_key (dev->cipher, digest, keysize); if (gcry_err) { - grub_crypto_cipher_close (cipher); - grub_crypto_cipher_close (essiv_cipher); grub_free (hashed_key); grub_free (split_key); return grub_crypto_gcry_error (gcry_err); } /* Configure ESSIV if necessary. */ - if (mode == GRUB_LUKS_MODE_CBC_ESSIV) + if (dev->mode == GRUB_LUKS_MODE_CBC_ESSIV) { - grub_crypto_hash (essiv_hash, hashed_key, digest, keysize); - grub_crypto_cipher_set_key (essiv_cipher, hashed_key, + grub_crypto_hash (dev->essiv_hash, hashed_key, digest, keysize); + grub_crypto_cipher_set_key (dev->essiv_cipher, hashed_key, essiv_keysize); } length = - grub_be_to_cpu32 (header.keyBytes) * - grub_be_to_cpu32 (header.keyblock[i].stripes); + grub_be_to_cpu32 (header->keyBytes) * + grub_be_to_cpu32 (header->keyblock[i].stripes); /* Read and decrypt the key material from the disk. */ err = grub_disk_read (source, - grub_be_to_cpu32 (header.keyblock + grub_be_to_cpu32 (header->keyblock [i].keyMaterialOffset), 0, length, split_key); if (err) { - grub_crypto_cipher_close (cipher); - grub_crypto_cipher_close (essiv_cipher); grub_free (hashed_key); grub_free (split_key); return err; } - gcry_err = luks_decrypt (cipher, mode, split_key, - length, 0, essiv_cipher); + gcry_err = luks_decrypt (dev->cipher, dev->mode, split_key, + length, 0, dev->essiv_cipher); if (gcry_err) { - grub_crypto_cipher_close (cipher); - grub_crypto_cipher_close (essiv_cipher); grub_free (hashed_key); grub_free (split_key); return grub_crypto_gcry_error (gcry_err); } /* Merge the decrypted key material to get the candidate master key. */ - gcry_err = AF_merge (hash, split_key, candidate_key, keysize, - grub_be_to_cpu32 (header.keyblock[i].stripes)); + gcry_err = AF_merge (dev->hash, split_key, candidate_key, keysize, + grub_be_to_cpu32 (header->keyblock[i].stripes)); if (gcry_err) { - grub_crypto_cipher_close (cipher); - grub_crypto_cipher_close (essiv_cipher); grub_free (hashed_key); grub_free (split_key); return grub_crypto_gcry_error (gcry_err); @@ -393,18 +406,16 @@ grub_luks_scan_device_real (const char *name, grub_disk_t source) grub_dprintf ("luks", "candidate key recovered\n"); /* Calculate the PBKDF2 of the candidate master key. */ - gcry_err = grub_crypto_pbkdf2 (hash, candidate_key, - grub_be_to_cpu32 (header.keyBytes), - header.mkDigestSalt, - sizeof (header.mkDigestSalt), + gcry_err = grub_crypto_pbkdf2 (dev->hash, candidate_key, + grub_be_to_cpu32 (header->keyBytes), + header->mkDigestSalt, + sizeof (header->mkDigestSalt), grub_be_to_cpu32 - (header.mkDigestIterations), + (header->mkDigestIterations), candidate_digest, sizeof (candidate_digest)); if (gcry_err) { - grub_crypto_cipher_close (cipher); - grub_crypto_cipher_close (essiv_cipher); grub_free (hashed_key); grub_free (split_key); return grub_crypto_gcry_error (gcry_err); @@ -412,71 +423,90 @@ grub_luks_scan_device_real (const char *name, grub_disk_t source) /* Compare the calculated PBKDF2 to the digest stored in the header to see if it's correct. */ - if (grub_memcmp (candidate_digest, header.mkDigest, - sizeof (header.mkDigest)) != 0) + if (grub_memcmp (candidate_digest, header->mkDigest, + sizeof (header->mkDigest)) != 0) continue; grub_printf ("Slot %d opened\n", i); /* Set the master key. */ - gcry_err = grub_crypto_cipher_set_key (cipher, candidate_key, keysize); + gcry_err = grub_crypto_cipher_set_key (dev->cipher, + candidate_key, keysize); if (gcry_err) { - grub_crypto_cipher_close (cipher); - grub_crypto_cipher_close (essiv_cipher); grub_free (hashed_key); grub_free (split_key); return grub_crypto_gcry_error (gcry_err); } /* Configure ESSIV if necessary. */ - if (mode == GRUB_LUKS_MODE_CBC_ESSIV) + if (dev->mode == GRUB_LUKS_MODE_CBC_ESSIV) { - grub_crypto_hash (essiv_hash, hashed_key, candidate_key, keysize); + grub_crypto_hash (dev->essiv_hash, hashed_key, + candidate_key, keysize); gcry_err = - grub_crypto_cipher_set_key (essiv_cipher, hashed_key, + grub_crypto_cipher_set_key (dev->essiv_cipher, hashed_key, essiv_keysize); if (gcry_err) { - grub_crypto_cipher_close (cipher); - grub_crypto_cipher_close (essiv_cipher); grub_free (hashed_key); grub_free (split_key); return grub_crypto_gcry_error (gcry_err); } } - { - grub_luks_t newdev; - newdev = grub_zalloc (sizeof (struct grub_luks)); - if (!newdev) - return grub_errno; - newdev->id = n; - newdev->source = grub_strdup (name); - newdev->source_id = source->id; - newdev->source_dev_id = source->dev->id; - newdev->cipher = cipher; - newdev->offset = grub_be_to_cpu32 (header.payloadOffset); - newdev->source_disk = NULL; - newdev->mode = mode; - newdev->essiv_cipher = essiv_cipher; - grub_memcpy (newdev->uuid, uuid, sizeof (newdev->uuid)); - newdev->next = luks_list; - luks_list = newdev; - n++; - } grub_free (split_key); grub_free (hashed_key); - have_it = 1; - return GRUB_ERR_NONE; } return GRUB_ACCESS_DENIED; } +static void +luks_close (grub_luks_t luks) +{ + grub_crypto_cipher_close (luks->cipher); + grub_crypto_cipher_close (luks->essiv_cipher); + grub_free (luks); +} + +static grub_err_t +grub_luks_scan_device_real (const char *name, grub_disk_t source) +{ + grub_err_t err; + struct grub_luks_phdr header; + grub_luks_t newdev; + + /* Read the LUKS header. */ + err = grub_disk_read (source, 0, 0, sizeof (header), &header); + if (err) + return err; + + newdev = configure_ciphers (&header); + if (!newdev) + return grub_errno; + + err = luks_recover_key (newdev, &header, name, source); + if (err) + { + luks_close (newdev); + return err; + } + + newdev->source = grub_strdup (name); + newdev->source_id = source->id; + newdev->source_dev_id = source->dev->id; + newdev->next = luks_list; + luks_list = newdev; + + have_it = 1; + + return GRUB_ERR_NONE; +} + static int grub_luks_scan_device (const char *name) { From dcd73ec05ef7a98f403860fcf7c9d80ef3c6440b Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 22 Apr 2011 19:04:21 +0200 Subject: [PATCH 490/869] add gcry to utils --- .bzrignore | 1 + Makefile.util.def | 18 ++++++++++-------- autogen.sh | 2 +- include/grub/crypto.h | 6 ++++++ util/grub-probe.c | 2 ++ util/import_gcry.py | 36 ++++++++++++++++++++++++++++++++++++ 6 files changed, 56 insertions(+), 9 deletions(-) diff --git a/.bzrignore b/.bzrignore index 55cbdaeeb..204fc182f 100644 --- a/.bzrignore +++ b/.bzrignore @@ -135,3 +135,4 @@ widthspec.bin widthspec.h docs/stamp-1 docs/version-dev.texi +Makefile.utilgcry.def diff --git a/Makefile.util.def b/Makefile.util.def index 40c67c233..693a7d127 100644 --- a/Makefile.util.def +++ b/Makefile.util.def @@ -21,12 +21,16 @@ library = { common = grub-core/kern/list.c; common = grub-core/kern/misc.c; common = grub-core/kern/partition.c; + common = grub-core/lib/crypto.c; + common = grub-core/disk/luks.c; + common = grub-core/disk/AFSplitter.c; + common = grub-core/lib/pbkdf2.c; + common = grub-core/commands/extcmd.c; + common = grub-core/lib/arg.c; }; library = { name = libgrubmods.a; - cflags = '$(CFLAGS_GCRY)'; - cppflags = '$(CPPFLAGS_GCRY)'; common_nodist = grub_script.tab.c; common_nodist = grub_script.yy.c; @@ -35,7 +39,6 @@ library = { common_nodist = grub_script.tab.h; common = grub-core/commands/blocklist.c; - common = grub-core/commands/extcmd.c; common = grub-core/commands/ls.c; common = grub-core/disk/dmraid_nvidia.c; common = grub-core/disk/loopback.c; @@ -75,15 +78,10 @@ library = { common = grub-core/fs/zfs/zfs_lzjb.c; common = grub-core/fs/zfs/zfs_sha256.c; common = grub-core/fs/zfs/zfs_fletcher.c; - common = grub-core/lib/arg.c; - common = grub-core/lib/crypto.c; common = grub-core/lib/envblk.c; common = grub-core/lib/hexdump.c; - common = grub-core/lib/libgcrypt-grub/cipher/sha512.c; - common = grub-core/lib/libgcrypt-grub/cipher/crc.c; common = grub-core/lib/LzFind.c; common = grub-core/lib/LzmaEnc.c; - common = grub-core/lib/pbkdf2.c; common = grub-core/lib/crc.c; common = grub-core/normal/datetime.c; common = grub-core/normal/misc.c; @@ -123,6 +121,7 @@ program = { ldadd = libgrubmods.a; ldadd = libgrubkern.a; + ldadd = libgrubgcry.a; ldadd = grub-core/gnulib/libgnu.a; ldadd = '$(LIBLZMA)'; ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM)'; @@ -173,6 +172,7 @@ program = { ldadd = libgrubmods.a; ldadd = libgrubkern.a; + ldadd = libgrubgcry.a; ldadd = grub-core/gnulib/libgnu.a; ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM)'; cflags = '$(CFLAGS_GCRY)'; @@ -211,6 +211,7 @@ program = { ldadd = libgrubmods.a; ldadd = libgrubkern.a; + ldadd = libgrubgcry.a; ldadd = grub-core/gnulib/libgnu.a; ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM)'; }; @@ -257,6 +258,7 @@ program = { ldadd = libgrubmods.a; ldadd = libgrubkern.a; + ldadd = libgrubgcry.a; ldadd = grub-core/gnulib/libgnu.a; ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBUTIL) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM)'; }; diff --git a/autogen.sh b/autogen.sh index d14707aad..db719cd1d 100755 --- a/autogen.sh +++ b/autogen.sh @@ -26,7 +26,7 @@ if [ "x${GRUB_CONTRIB}" != x ]; then [ "${GRUB_CONTRIB}" = grub-core/contrib ] || ln -s ../contrib grub-core/contrib fi -UTIL_DEFS=Makefile.util.def +UTIL_DEFS='Makefile.util.def Makefile.utilgcry.def' CORE_DEFS='grub-core/Makefile.core.def grub-core/Makefile.gcry.def' for extra in contrib/*/Makefile.util.def; do diff --git a/include/grub/crypto.h b/include/grub/crypto.h index ebe78e7a1..a8ca2106d 100644 --- a/include/grub/crypto.h +++ b/include/grub/crypto.h @@ -274,4 +274,10 @@ grub_password_get (char buf[], unsigned buf_size); extern void (*grub_crypto_autoload_hook) (const char *name); +#ifdef GRUB_UTIL +void grub_gcry_init_all (void); +void grub_gcry_fini_all (void); +#endif + + #endif diff --git a/util/grub-probe.c b/util/grub-probe.c index 0d5dac902..6c6220b8b 100644 --- a/util/grub-probe.c +++ b/util/grub-probe.c @@ -393,6 +393,7 @@ main (int argc, char *argv[]) /* Initialize all modules. */ grub_init_all (); + grub_gcry_init_all (); grub_lvm_fini (); grub_mdraid09_fini (); @@ -410,6 +411,7 @@ main (int argc, char *argv[]) probe (argument, NULL); /* Free resources. */ + grub_gcry_fini_all (); grub_fini_all (); grub_util_biosdisk_fini (); diff --git a/util/import_gcry.py b/util/import_gcry.py index b2a0a5451..3a110f028 100644 --- a/util/import_gcry.py +++ b/util/import_gcry.py @@ -42,7 +42,15 @@ except: cipher_files = os.listdir (cipher_dir_in) conf = open (os.path.join ("grub-core", "Makefile.gcry.def"), "w") conf.write ("AutoGen definitions Makefile.tpl;\n\n") +confutil = open ("Makefile.utilgcry.def", "w") +confutil.write ("AutoGen definitions Makefile.tpl;\n\n") +confutil.write ("library = {\n"); +confutil.write (" name = libgrubgcry.a;\n"); +confutil.write (" cflags = '$(CFLAGS_GCRY)';\n"); +confutil.write (" cppflags = '$(CPPFLAGS_GCRY)';\n"); +confutil.write ("\n"); chlog = "" +modules = [] # Strictly speaking CRC32/CRC24 work on bytes so this value should be 1 # But libgcrypt uses 64. Let's keep the value for compatibility. Since @@ -249,6 +257,7 @@ for cipher_file in cipher_files: % (cipher_file, cipher_file.replace ("-glue.c", ".c")) else: modfiles = "lib/libgcrypt-grub/cipher/%s" % cipher_file + modules.append (modname) chmsg = "(GRUB_MOD_INIT(%s)): New function\n" % modname if nch: chlognew = "%s\n %s" % (chlognew, chmsg) @@ -283,6 +292,7 @@ for cipher_file in cipher_files: conf.write (" name = %s;\n" % modname) for src in modfiles.split(): conf.write (" common = %s;\n" % src) + confutil.write (" common = grub-core/%s;\n" % src) conf.write (" cflags = '$(CFLAGS_GCRY)';\n"); conf.write (" cppflags = '$(CPPFLAGS_GCRY)';\n"); conf.write ("};\n\n") @@ -329,6 +339,32 @@ fw.close () infile = os.path.join (cipher_dir_in, "ChangeLog") outfile = os.path.join (cipher_dir_out, "ChangeLog") +conf.close (); + +initfile = open (os.path.join (cipher_dir_out, "init.c"), "w") +for module in modules: + initfile.write ("extern void grub_%s_init (void);\n" % module) + initfile.write ("extern void grub_%s_fini (void);\n" % module) +initfile.write ("\n") +initfile.write ("void\n") +initfile.write ("grub_gcry_init_all (void)\n") +initfile.write ("{\n") +for module in modules: + initfile.write (" grub_%s_init ();\n" % module) +initfile.write ("}\n") +initfile.write ("\n") +initfile.write ("void\n") +initfile.write ("grub_gcry_fini_all (void)\n") +initfile.write ("{\n") +for module in modules: + initfile.write (" grub_%s_fini ();\n" % module) +initfile.write ("}\n") +initfile.close () + +confutil.write (" common = grub-core/lib/libgcrypt-grub/cipher/init.c;\n") +confutil.write ("};\n"); +confutil.close (); + f=open (infile, "r") fw=open (outfile, "w") From 24089d19e2dde4e72d8c783a3f1a607f5a8e7729 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 22 Apr 2011 19:20:46 +0200 Subject: [PATCH 491/869] Add cheatmounting --- grub-core/disk/luks.c | 99 +++++++++++++++++++++++++++++++++-- grub-core/kern/emu/getroot.c | 26 +++++++-- grub-core/kern/emu/hostdisk.c | 75 ++++++++++++++------------ include/grub/emu/hostdisk.h | 6 +++ 4 files changed, 166 insertions(+), 40 deletions(-) diff --git a/grub-core/disk/luks.c b/grub-core/disk/luks.c index 4d907b4c6..99dd3a8e6 100644 --- a/grub-core/disk/luks.c +++ b/grub-core/disk/luks.c @@ -25,6 +25,15 @@ #include #include #include +#ifdef GRUB_UTIL +#include +#include +#include +#include +#include +#include +#include +#endif GRUB_MOD_LICENSE ("GPLv3+"); @@ -80,6 +89,10 @@ struct grub_luks unsigned long id, source_id; enum grub_disk_dev_id source_dev_id; char uuid[sizeof (((struct grub_luks_phdr *) 0)->uuid) + 1]; +#ifdef GRUB_UTIL + char *cheat; + int cheat_fd; +#endif struct grub_luks *next; }; typedef struct grub_luks *grub_luks_t; @@ -497,6 +510,12 @@ grub_luks_scan_device_real (const char *name, grub_disk_t source) } newdev->source = grub_strdup (name); + if (!newdev->source) + { + grub_free (newdev); + return grub_errno; + } + newdev->source_id = source->id; newdev->source_dev_id = source->dev->id; newdev->next = luks_list; @@ -507,6 +526,48 @@ grub_luks_scan_device_real (const char *name, grub_disk_t source) return GRUB_ERR_NONE; } +#ifdef GRUB_UTIL +grub_err_t +grub_luks_cheat_mount (const char *sourcedev, const char *cheat) +{ + grub_err_t err; + struct grub_luks_phdr header; + grub_luks_t newdev; + grub_disk_t source; + + /* Try to open disk. */ + source = grub_disk_open (sourcedev); + if (!source) + return grub_errno; + + /* Read the LUKS header. */ + err = grub_disk_read (source, 0, 0, sizeof (header), &header); + if (err) + return err; + + newdev = configure_ciphers (&header); + grub_disk_close (source); + if (!newdev) + return grub_errno; + + newdev->cheat = grub_strdup (cheat); + newdev->source = grub_strdup (sourcedev); + if (!newdev->source || !newdev->cheat) + { + grub_free (newdev->source); + grub_free (newdev->cheat); + grub_free (newdev); + return grub_errno; + } + newdev->cheat_fd = -1; + newdev->source_id = source->id; + newdev->source_dev_id = source->dev->id; + newdev->next = luks_list; + luks_list = newdev; + return GRUB_ERR_NONE; +} +#endif + static int grub_luks_scan_device (const char *name) { @@ -575,6 +636,17 @@ grub_luks_open (const char *name, grub_disk_t disk, if (!dev) return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "No such device"); +#ifdef GRUB_UTIL + if (dev->cheat) + { + if (dev->cheat_fd == -1) + dev->cheat_fd = open (dev->cheat, O_RDONLY); + if (dev->cheat_fd == -1) + return grub_error (GRUB_ERR_IO, "couldn't open %s: %s", + dev->cheat, strerror (errno)); + } +#endif + if (!dev->source_disk) { grub_dprintf ("luks", "Opening device %s\n", name); @@ -599,11 +671,17 @@ grub_luks_close (grub_disk_t disk) dev->ref--; - if (dev->ref == 0) + if (dev->ref != 0) + return; +#ifdef GRUB_UTIL + if (dev->cheat) { - grub_disk_close (dev->source_disk); - dev->source_disk = NULL; + close (dev->cheat_fd); + dev->cheat_fd = -1; } +#endif + grub_disk_close (dev->source_disk); + dev->source_disk = NULL; } static grub_err_t @@ -612,6 +690,21 @@ grub_luks_read (grub_disk_t disk, grub_disk_addr_t sector, { grub_luks_t dev = (grub_luks_t) disk->data; grub_err_t err; + +#ifdef GRUB_UTIL + if (dev->cheat) + { + err = grub_util_fd_sector_seek (dev->cheat_fd, dev->cheat, sector); + if (err) + return err; + if (grub_util_fd_read (dev->cheat_fd, buf, size << GRUB_DISK_SECTOR_BITS) + != (ssize_t) (size << GRUB_DISK_SECTOR_BITS)) + return grub_error (GRUB_ERR_READ_ERROR, "cannot read from `%s'", + dev->cheat); + return GRUB_ERR_NONE; + } +#endif + grub_dprintf ("luks", "Reading %" PRIuGRUB_SIZE " sectors from sector 0x%" PRIxGRUB_UINT64_T " with offset of %" PRIuGRUB_UINT32_T "\n", diff --git a/grub-core/kern/emu/getroot.c b/grub-core/kern/emu/getroot.c index 6cc745833..c3a971689 100644 --- a/grub-core/kern/emu/getroot.c +++ b/grub-core/kern/emu/getroot.c @@ -865,7 +865,9 @@ out: void grub_util_pull_device (const char *os_dev) { - switch (grub_util_get_dev_abstraction (os_dev)) + int ab; + ab = grub_util_get_dev_abstraction (os_dev); + switch (ab) { case GRUB_DEV_ABSTRACTION_LVM: case GRUB_DEV_ABSTRACTION_LUKS: @@ -875,6 +877,7 @@ grub_util_pull_device (const char *os_dev) struct dm_tree_node *node; struct dm_tree_node *child; void *handle = NULL; + char *lastsubdev = NULL; if (!grub_util_open_dm (os_dev, &tree, &node)) return; @@ -887,9 +890,26 @@ grub_util_pull_device (const char *os_dev) continue; subdev = grub_find_device ("/dev", makedev (dm->major, dm->minor)); if (subdev) - grub_util_pull_device (subdev); + { + lastsubdev = subdev; + grub_util_pull_device (subdev); + } } - dm_tree_free (tree); + if (ab == GRUB_DEV_ABSTRACTION_LUKS && lastsubdev) + { + char *grdev = grub_util_get_grub_dev (lastsubdev); + dm_tree_free (tree); + if (grdev) + { + grub_err_t err; + err = grub_luks_cheat_mount (grdev, os_dev); + if (err) + grub_util_error ("Can't mount LUKS: %s", grub_errmsg); + } + grub_free (grdev); + } + else + dm_tree_free (tree); } #endif return; diff --git a/grub-core/kern/emu/hostdisk.c b/grub-core/kern/emu/hostdisk.c index 9b65d417e..110d3e291 100644 --- a/grub-core/kern/emu/hostdisk.c +++ b/grub-core/kern/emu/hostdisk.c @@ -631,6 +631,37 @@ linux_find_partition (char *dev, unsigned long sector) } #endif /* __linux__ */ +#if defined(__linux__) && (!defined(__GLIBC__) || \ + ((__GLIBC__ < 2) || ((__GLIBC__ == 2) && (__GLIBC_MINOR__ < 1)))) + /* Maybe libc doesn't have large file support. */ +grub_err_t +grub_util_fd_sector_seek (int fd, const char *name, grub_disk_addr_t sector) +{ + loff_t offset, result; + static int _llseek (uint filedes, ulong hi, ulong lo, + loff_t *res, uint wh); + _syscall5 (int, _llseek, uint, filedes, ulong, hi, ulong, lo, + loff_t *, res, uint, wh); + + offset = (loff_t) sector << GRUB_DISK_SECTOR_BITS; + if (_llseek (fd, offset >> 32, offset & 0xffffffff, &result, SEEK_SET)) + { + return grub_error (GRUB_ERR_BAD_DEVICE, "cannot seek `%s'", name); + } + return GRUB_ERR_NONE; +} +#else +grub_err_t +grub_util_fd_sector_seek (int fd, const char *name, grub_disk_addr_t sector) +{ + off_t offset = (off_t) sector << GRUB_DISK_SECTOR_BITS; + + if (lseek (fd, offset, SEEK_SET) != offset) + return grub_error (GRUB_ERR_BAD_DEVICE, "cannot seek `%s'", name); + return 0; +} +#endif + static int open_device (const grub_disk_t disk, grub_disk_addr_t sector, int flags) { @@ -781,44 +812,19 @@ open_device (const grub_disk_t disk, grub_disk_addr_t sector, int flags) configure_device_driver (fd); #endif /* defined(__NetBSD__) */ -#if defined(__linux__) && (!defined(__GLIBC__) || \ - ((__GLIBC__ < 2) || ((__GLIBC__ == 2) && (__GLIBC_MINOR__ < 1)))) - /* Maybe libc doesn't have large file support. */ - { - loff_t offset, result; - static int _llseek (uint filedes, ulong hi, ulong lo, - loff_t *res, uint wh); - _syscall5 (int, _llseek, uint, filedes, ulong, hi, ulong, lo, - loff_t *, res, uint, wh); - - offset = (loff_t) sector << GRUB_DISK_SECTOR_BITS; - if (_llseek (fd, offset >> 32, offset & 0xffffffff, &result, SEEK_SET)) - { - grub_error (GRUB_ERR_BAD_DEVICE, "cannot seek `%s'", map[disk->id].device); - close (fd); - return -1; - } - } -#else - { - off_t offset = (off_t) sector << GRUB_DISK_SECTOR_BITS; - - if (lseek (fd, offset, SEEK_SET) != offset) - { - grub_error (GRUB_ERR_BAD_DEVICE, "cannot seek `%s'", map[disk->id].device); - close (fd); - return -1; - } - } -#endif + if (grub_util_fd_sector_seek (fd, map[disk->id].device, sector)) + { + close (fd); + return -1; + } return fd; } /* Read LEN bytes from FD in BUF. Return less than or equal to zero if an error occurs, otherwise return LEN. */ -static ssize_t -nread (int fd, char *buf, size_t len) +ssize_t +grub_util_fd_read (int fd, char *buf, size_t len) { ssize_t size = len; @@ -901,7 +907,8 @@ grub_util_biosdisk_read (grub_disk_t disk, grub_disk_addr_t sector, sectors that are read together with the MBR in one read. It should only remap the MBR, so we split the read in two parts. -jochen */ - if (nread (fd, buf, GRUB_DISK_SECTOR_SIZE) != GRUB_DISK_SECTOR_SIZE) + if (grub_util_fd_read (fd, buf, GRUB_DISK_SECTOR_SIZE) + != GRUB_DISK_SECTOR_SIZE) { grub_error (GRUB_ERR_READ_ERROR, "cannot read `%s'", map[disk->id].device); return grub_errno; @@ -912,7 +919,7 @@ grub_util_biosdisk_read (grub_disk_t disk, grub_disk_addr_t sector, } #endif /* __linux__ */ - if (nread (fd, buf, size << GRUB_DISK_SECTOR_BITS) + if (grub_util_fd_read (fd, buf, size << GRUB_DISK_SECTOR_BITS) != (ssize_t) (size << GRUB_DISK_SECTOR_BITS)) grub_error (GRUB_ERR_READ_ERROR, "cannot read from `%s'", map[disk->id].device); diff --git a/include/grub/emu/hostdisk.h b/include/grub/emu/hostdisk.h index 803c0f755..c7a794d68 100644 --- a/include/grub/emu/hostdisk.h +++ b/include/grub/emu/hostdisk.h @@ -21,6 +21,7 @@ #define GRUB_BIOSDISK_MACHINE_UTIL_HEADER 1 #include +#include void grub_util_biosdisk_init (const char *dev_map); void grub_util_biosdisk_fini (void); @@ -30,5 +31,10 @@ int grub_util_biosdisk_is_present (const char *name); int grub_util_biosdisk_is_floppy (grub_disk_t disk); grub_err_t grub_util_biosdisk_flush (struct grub_disk *disk); void grub_util_pull_device (const char *osname); +grub_err_t +grub_util_fd_sector_seek (int fd, const char *name, grub_disk_addr_t sector); +ssize_t grub_util_fd_read (int fd, char *buf, size_t len); +grub_err_t +grub_luks_cheat_mount (const char *sourcedev, const char *cheat); #endif /* ! GRUB_BIOSDISK_MACHINE_UTIL_HEADER */ From 4169260830d30fca23af54441bfd3ea749b7c006 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 22 Apr 2011 19:44:41 +0200 Subject: [PATCH 492/869] grub-fstest luks support --- grub-core/disk/luks.c | 28 ++++++++++++++++++++++++---- util/grub-fstest.c | 15 +++++++++++++++ 2 files changed, 39 insertions(+), 4 deletions(-) diff --git a/grub-core/disk/luks.c b/grub-core/disk/luks.c index 99dd3a8e6..eb9dd050e 100644 --- a/grub-core/disk/luks.c +++ b/grub-core/disk/luks.c @@ -107,6 +107,7 @@ gcry_err_code_t AF_merge (const gcry_md_spec_t * hash, grub_uint8_t * src, static const struct grub_arg_option options[] = { {"uuid", 'u', 0, N_("Mount by UUID."), 0, 0}, + {"all", 'a', 0, N_("Mount all."), 0, 0}, {0, 0, 0, 0, 0, 0} }; @@ -491,7 +492,11 @@ grub_luks_scan_device_real (const char *name, grub_disk_t source) { grub_err_t err; struct grub_luks_phdr header; - grub_luks_t newdev; + grub_luks_t newdev, dev; + + for (dev = luks_list; dev != NULL; dev = dev->next) + if (dev->source_id == source->id && dev->source_dev_id == source->dev->id) + return GRUB_ERR_NONE; /* Read the LUKS header. */ err = grub_disk_read (source, 0, 0, sizeof (header), &header); @@ -532,7 +537,7 @@ grub_luks_cheat_mount (const char *sourcedev, const char *cheat) { grub_err_t err; struct grub_luks_phdr header; - grub_luks_t newdev; + grub_luks_t newdev, dev; grub_disk_t source; /* Try to open disk. */ @@ -540,6 +545,13 @@ grub_luks_cheat_mount (const char *sourcedev, const char *cheat) if (!source) return grub_errno; + for (dev = luks_list; dev != NULL; dev = dev->next) + if (dev->source_id == source->id && dev->source_dev_id == source->dev->id) + { + grub_disk_close (source); + return GRUB_ERR_NONE; + } + /* Read the LUKS header. */ err = grub_disk_read (source, 0, 0, sizeof (header), &header); if (err) @@ -755,7 +767,7 @@ grub_cmd_luksmount (grub_extcmd_context_t ctxt, int argc, char **args) { struct grub_arg_list *state = ctxt->state; - if (argc < 1) + if (argc < 1 && !state[1].set) return grub_error (GRUB_ERR_BAD_ARGUMENT, "device name required"); have_it = 0; @@ -779,6 +791,14 @@ grub_cmd_luksmount (grub_extcmd_context_t ctxt, int argc, char **args) return grub_error (GRUB_ERR_BAD_ARGUMENT, "no such luks found"); return GRUB_ERR_NONE; } + else if (state[1].set) + { + check_uuid = 0; + search_uuid = NULL; + grub_device_iterate (&grub_luks_scan_device); + search_uuid = NULL; + return GRUB_ERR_NONE; + } else { grub_err_t err; @@ -823,7 +843,7 @@ static grub_extcmd_t cmd; GRUB_MOD_INIT (luks) { cmd = grub_register_extcmd ("luksmount", grub_cmd_luksmount, 0, - N_("SOURCE|-u UUID"), + N_("SOURCE|-u UUID|-a"), N_("Mount a LUKS device."), options); grub_disk_dev_register (&grub_luks_dev); } diff --git a/util/grub-fstest.c b/util/grub-fstest.c index 293bdf74a..2adb2331d 100644 --- a/util/grub-fstest.c +++ b/util/grub-fstest.c @@ -275,6 +275,7 @@ static char **images = NULL; static int cmd = 0; static char *debug_str = NULL; static char **args = NULL; +static int mount_crypt = 0; static void fstest (int n, char **args) @@ -304,6 +305,13 @@ fstest (int n, char **args) grub_free (host_file); } + { + char *argv[2] = { "-a", NULL}; + if (mount_crypt) + if (execute_command ("luksmount", 1, argv)) + grub_util_error (_("luksmount command fails: %s"), grub_errmsg); + } + grub_lvm_fini (); grub_mdraid09_fini (); grub_mdraid1x_fini (); @@ -366,6 +374,7 @@ static struct argp_option options[] = { {"length", 'n', "N", 0, N_("Handle N bytes in output file."), 2}, {"diskcount", 'c', "N", 0, N_("N input files."), 2}, {"debug", 'd', "S", 0, N_("Set debug environment variable."), 2}, + {"crypto", 'C', NULL, OPTION_ARG_OPTIONAL, N_("Mount crypto devices."), 2}, {"verbose", 'v', NULL, OPTION_ARG_OPTIONAL, N_("Print verbose messages."), 2}, {0, 0, 0, 0, 0, 0} }; @@ -389,6 +398,10 @@ argp_parser (int key, char *arg, struct argp_state *state) root = arg; return 0; + case 'C': + mount_crypt = 1; + return 0; + case 's': skip = grub_strtoul (arg, &p, 0); if (*p == 's') @@ -523,6 +536,7 @@ main (int argc, char *argv[]) /* Initialize all modules. */ grub_init_all (); + grub_gcry_init_all (); if (debug_str) grub_env_set ("debug", debug_str); @@ -551,6 +565,7 @@ main (int argc, char *argv[]) fstest (args_count - 1 - num_disks, args); /* Free resources. */ + grub_gcry_fini_all (); grub_fini_all (); return 0; From 84a411c0c3b17ba1a67ef30a94134bb8c8a9266a Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 22 Apr 2011 19:51:06 +0200 Subject: [PATCH 493/869] small argument revamp --- grub-core/disk/luks.c | 34 +++++++++++++++------------------- 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/grub-core/disk/luks.c b/grub-core/disk/luks.c index eb9dd050e..8bf07903c 100644 --- a/grub-core/disk/luks.c +++ b/grub-core/disk/luks.c @@ -112,27 +112,26 @@ static const struct grub_arg_option options[] = }; static gcry_err_code_t -luks_decrypt (grub_crypto_cipher_handle_t cipher, luks_mode_t mode, - grub_uint8_t * data, grub_size_t len, - grub_size_t sector, grub_crypto_cipher_handle_t essiv_cipher) +luks_decrypt (const struct grub_luks *dev, + grub_uint8_t * data, grub_size_t len, grub_size_t sector) { grub_size_t i; gcry_err_code_t err; - switch (mode) + switch (dev->mode) { case GRUB_LUKS_MODE_ECB: - return grub_crypto_ecb_decrypt (cipher, data, data, len); + return grub_crypto_ecb_decrypt (dev->cipher, data, data, len); case GRUB_LUKS_MODE_CBC_PLAIN: for (i = 0; i < len; i += GRUB_DISK_SECTOR_SIZE) { - grub_uint32_t iv[(cipher->cipher->blocksize + grub_uint32_t iv[(dev->cipher->cipher->blocksize + sizeof (grub_uint32_t) - 1) / sizeof (grub_uint32_t)]; - grub_memset (iv, 0, cipher->cipher->blocksize); + grub_memset (iv, 0, dev->cipher->cipher->blocksize); iv[0] = grub_cpu_to_le32 (sector & 0xFFFFFFFF); - err = grub_crypto_cbc_decrypt (cipher, data + i, data + i, + err = grub_crypto_cbc_decrypt (dev->cipher, data + i, data + i, GRUB_DISK_SECTOR_SIZE, iv); if (err) return err; @@ -143,17 +142,17 @@ luks_decrypt (grub_crypto_cipher_handle_t cipher, luks_mode_t mode, case GRUB_LUKS_MODE_CBC_ESSIV: for (i = 0; i < len; i += GRUB_DISK_SECTOR_SIZE) { - grub_uint32_t iv[(cipher->cipher->blocksize + grub_uint32_t iv[(dev->cipher->cipher->blocksize + sizeof (grub_uint32_t) - 1) / sizeof (grub_uint32_t)]; - grub_memset (iv, 0, cipher->cipher->blocksize); + grub_memset (iv, 0, dev->cipher->cipher->blocksize); iv[0] = grub_cpu_to_le32 (sector & 0xFFFFFFFF); err = - grub_crypto_ecb_encrypt (essiv_cipher, iv, iv, - cipher->cipher->blocksize); + grub_crypto_ecb_encrypt (dev->essiv_cipher, iv, iv, + dev->cipher->cipher->blocksize); if (err) return err; - err = grub_crypto_cbc_decrypt (cipher, data + i, data + i, + err = grub_crypto_cbc_decrypt (dev->cipher, data + i, data + i, GRUB_DISK_SECTOR_SIZE, iv); if (err) return err; @@ -398,8 +397,7 @@ luks_recover_key (grub_luks_t dev, const struct grub_luks_phdr *header, return err; } - gcry_err = luks_decrypt (dev->cipher, dev->mode, split_key, - length, 0, dev->essiv_cipher); + gcry_err = luks_decrypt (dev, split_key, length, 0); if (gcry_err) { grub_free (hashed_key); @@ -729,11 +727,9 @@ grub_luks_read (grub_disk_t disk, grub_disk_addr_t sector, grub_dprintf ("luks", "grub_disk_read failed with error %d\n", err); return err; } - return grub_crypto_gcry_error (luks_decrypt (dev->cipher, - dev->mode, - (grub_uint8_t *) buf, + return grub_crypto_gcry_error (luks_decrypt (dev, (grub_uint8_t *) buf, size << GRUB_DISK_SECTOR_BITS, - sector, dev->essiv_cipher)); + sector)); } static grub_err_t From 2cb55e6f7356d82f826e65577373167a46b73f8d Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 22 Apr 2011 21:46:00 +0200 Subject: [PATCH 494/869] make grub_password_get work in userland --- grub-core/lib/crypto.c | 44 ++++++++++++++++++++- util/grub-mkpasswd-pbkdf2.c | 76 ++++++------------------------------- 2 files changed, 53 insertions(+), 67 deletions(-) diff --git a/grub-core/lib/crypto.c b/grub-core/lib/crypto.c index ad1bfc4d3..2f172ebf8 100644 --- a/grub-core/lib/crypto.c +++ b/grub-core/lib/crypto.c @@ -23,6 +23,13 @@ #include #include +#ifdef GRUB_UTIL +#include +#include +#include +#include +#endif + GRUB_MOD_LICENSE ("GPLv3+"); struct grub_crypto_hmac_handle @@ -414,10 +421,43 @@ grub_crypto_memcmp (const void *a, const void *b, grub_size_t n) return !!counter; } -#ifndef GRUB_MKPASSWD int grub_password_get (char buf[], unsigned buf_size) { +#ifdef GRUB_UTIL + FILE *in; + struct termios s, t; + int tty_changed = 0; + char *ptr; + + /* Disable echoing. Based on glibc. */ + in = fopen ("/dev/tty", "w+c"); + if (in == NULL) + in = stdin; + + if (tcgetattr (fileno (in), &t) == 0) + { + /* Save the old one. */ + s = t; + /* Tricky, tricky. */ + t.c_lflag &= ~(ECHO|ISIG); + tty_changed = (tcsetattr (fileno (in), TCSAFLUSH, &t) == 0); + } + else + tty_changed = 0; + fgets (buf, buf_size, stdin); + ptr = buf + strlen (buf) - 1; + while (buf <= ptr && (*ptr == '\n' || *ptr == '\r')) + *ptr-- = 0; + /* Restore the original setting. */ + if (tty_changed) + (void) tcsetattr (fileno (in), TCSAFLUSH, &s); + + grub_xputs ("\n"); + grub_refresh (); + + return 1; +#else unsigned cur_len = 0; int key; @@ -452,5 +492,5 @@ grub_password_get (char buf[], unsigned buf_size) grub_refresh (); return (key != '\e'); -} #endif +} diff --git a/util/grub-mkpasswd-pbkdf2.c b/util/grub-mkpasswd-pbkdf2.c index fe1887f8f..032a8b586 100644 --- a/util/grub-mkpasswd-pbkdf2.c +++ b/util/grub-mkpasswd-pbkdf2.c @@ -20,6 +20,7 @@ #include #include +#include #include #include #include @@ -29,7 +30,6 @@ #include #include #include -#include #include "progname.h" @@ -85,14 +85,12 @@ int main (int argc, char *argv[]) { unsigned int count = 10000, buflen = 64, saltlen = 64; - char *pass1, *pass2; char *bufhex, *salthex; gcry_err_code_t gcry_err; grub_uint8_t *buf, *salt; ssize_t nr; - FILE *in, *out; - struct termios s, t; - int tty_changed; + char pass1[GRUB_AUTH_MAX_PASSLEN]; + char pass2[GRUB_AUTH_MAX_PASSLEN]; set_program_name (argv[0]); @@ -160,86 +158,37 @@ main (int argc, char *argv[]) free (buf); grub_util_error ("out of memory"); } - - /* Disable echoing. Based on glibc. */ - in = fopen ("/dev/tty", "w+c"); - if (in == NULL) - { - in = stdin; - out = stderr; - } - else - out = in; - - if (tcgetattr (fileno (in), &t) == 0) - { - /* Save the old one. */ - s = t; - /* Tricky, tricky. */ - t.c_lflag &= ~(ECHO|ISIG); - tty_changed = (tcsetattr (fileno (in), TCSAFLUSH, &t) == 0); - } - else - tty_changed = 0; printf ("Enter password: "); - pass1 = NULL; - { - grub_size_t n; - nr = getline (&pass1, &n, stdin); - } - if (nr < 0 || !pass1) + if (!grub_password_get (pass1, GRUB_AUTH_MAX_PASSLEN)) { free (buf); free (bufhex); free (salthex); free (salt); - /* Restore the original setting. */ - if (tty_changed) - (void) tcsetattr (fileno (in), TCSAFLUSH, &s); grub_util_error ("failure to read password"); } - if (nr >= 1 && pass1[nr-1] == '\n') - pass1[nr-1] = 0; - printf ("\nReenter password: "); - pass2 = NULL; - { - grub_size_t n; - nr = getline (&pass2, &n, stdin); - } - /* Restore the original setting. */ - if (tty_changed) - (void) tcsetattr (fileno (in), TCSAFLUSH, &s); - printf ("\n"); - - if (nr < 0 || !pass2) + if (!grub_password_get (pass2, GRUB_AUTH_MAX_PASSLEN)) { - memset (pass1, 0, strlen (pass1)); - free (pass1); free (buf); free (bufhex); free (salthex); free (salt); grub_util_error ("failure to read password"); } - if (nr >= 1 && pass2[nr-1] == '\n') - pass2[nr-1] = 0; if (strcmp (pass1, pass2) != 0) { - memset (pass1, 0, strlen (pass1)); - memset (pass2, 0, strlen (pass2)); - free (pass1); - free (pass2); + memset (pass1, 0, sizeof (pass1)); + memset (pass2, 0, sizeof (pass2)); free (buf); free (bufhex); free (salthex); free (salt); grub_util_error ("passwords don't match"); } - memset (pass2, 0, strlen (pass2)); - free (pass2); + memset (pass2, 0, sizeof (pass2)); #if ! defined (__linux__) && ! defined (__FreeBSD__) printf ("WARNING: your random generator isn't known to be secure\n"); @@ -251,8 +200,7 @@ main (int argc, char *argv[]) f = fopen ("/dev/random", "rb"); if (!f) { - memset (pass1, 0, strlen (pass1)); - free (pass1); + memset (pass1, 0, sizeof (pass1)); free (buf); free (bufhex); free (salthex); @@ -264,8 +212,7 @@ main (int argc, char *argv[]) if (rd != saltlen) { fclose (f); - memset (pass1, 0, strlen (pass1)); - free (pass1); + memset (pass1, 0, sizeof (pass1)); free (buf); free (bufhex); free (salthex); @@ -280,8 +227,7 @@ main (int argc, char *argv[]) (grub_uint8_t *) pass1, strlen (pass1), salt, saltlen, count, buf, buflen); - memset (pass1, 0, strlen (pass1)); - free (pass1); + memset (pass1, 0, sizeof (pass1)); if (gcry_err) { From fe32915a5ebc39f21524547c6a7ec6d123534828 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 22 Apr 2011 21:48:32 +0200 Subject: [PATCH 495/869] XTS support --- grub-core/disk/luks.c | 192 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 157 insertions(+), 35 deletions(-) diff --git a/grub-core/disk/luks.c b/grub-core/disk/luks.c index 8bf07903c..0098c9d49 100644 --- a/grub-core/disk/luks.c +++ b/grub-core/disk/luks.c @@ -73,7 +73,8 @@ typedef enum { GRUB_LUKS_MODE_ECB, GRUB_LUKS_MODE_CBC_PLAIN, - GRUB_LUKS_MODE_CBC_ESSIV + GRUB_LUKS_MODE_CBC_ESSIV, + GRUB_LUKS_MODE_XTS } luks_mode_t; struct grub_luks @@ -83,7 +84,7 @@ struct grub_luks grub_disk_t source_disk; int ref; grub_crypto_cipher_handle_t cipher; - grub_crypto_cipher_handle_t essiv_cipher; + grub_crypto_cipher_handle_t secondary_cipher; const gcry_md_spec_t *essiv_hash, *hash; luks_mode_t mode; unsigned long id, source_id; @@ -111,6 +112,33 @@ static const struct grub_arg_option options[] = {0, 0, 0, 0, 0, 0} }; +static inline void +make_iv (grub_uint32_t *iv, grub_size_t sz, grub_disk_addr_t sector) +{ + grub_memset (iv, 0, sz * sizeof (iv[0])); + iv[0] = grub_cpu_to_le32 (sector & 0xFFFFFFFF); +} + +/* Our irreducible polynom is x^128+x^7+x^2+x+1. Lowest byte of it is: */ +#define POLYNOM 0x87 + +static void +gf_mul_x (grub_uint8_t *g) +{ + int over = 0, over2 = 0; + int j; + + for (j = 0; j < 16; j++) + { + over2 = !!(g[j] & 0x80); + g[j] <<= 1; + g[j] |= over; + over = over2; + } + if (over) + g[0] ^= POLYNOM; +} + static gcry_err_code_t luks_decrypt (const struct grub_luks *dev, grub_uint8_t * data, grub_size_t len, grub_size_t sector) @@ -126,11 +154,11 @@ luks_decrypt (const struct grub_luks *dev, case GRUB_LUKS_MODE_CBC_PLAIN: for (i = 0; i < len; i += GRUB_DISK_SECTOR_SIZE) { - grub_uint32_t iv[(dev->cipher->cipher->blocksize + grub_size_t sz = ((dev->cipher->cipher->blocksize + sizeof (grub_uint32_t) - 1) - / sizeof (grub_uint32_t)]; - grub_memset (iv, 0, dev->cipher->cipher->blocksize); - iv[0] = grub_cpu_to_le32 (sector & 0xFFFFFFFF); + / sizeof (grub_uint32_t)); + grub_uint32_t iv[sz]; + make_iv (iv, sz, sector); err = grub_crypto_cbc_decrypt (dev->cipher, data + i, data + i, GRUB_DISK_SECTOR_SIZE, iv); if (err) @@ -142,14 +170,14 @@ luks_decrypt (const struct grub_luks *dev, case GRUB_LUKS_MODE_CBC_ESSIV: for (i = 0; i < len; i += GRUB_DISK_SECTOR_SIZE) { - grub_uint32_t iv[(dev->cipher->cipher->blocksize + grub_size_t sz = ((dev->cipher->cipher->blocksize + sizeof (grub_uint32_t) - 1) - / sizeof (grub_uint32_t)]; - grub_memset (iv, 0, dev->cipher->cipher->blocksize); - iv[0] = grub_cpu_to_le32 (sector & 0xFFFFFFFF); - err = - grub_crypto_ecb_encrypt (dev->essiv_cipher, iv, iv, - dev->cipher->cipher->blocksize); + / sizeof (grub_uint32_t)); + grub_uint32_t iv[sz]; + make_iv (iv, sz, sector); + + err = grub_crypto_ecb_encrypt (dev->secondary_cipher, iv, iv, + dev->cipher->cipher->blocksize); if (err) return err; err = grub_crypto_cbc_decrypt (dev->cipher, data + i, data + i, @@ -160,6 +188,39 @@ luks_decrypt (const struct grub_luks *dev, } return GPG_ERR_NO_ERROR; + case GRUB_LUKS_MODE_XTS: + for (i = 0; i < len; i += GRUB_DISK_SECTOR_SIZE) + { + grub_size_t sz = ((dev->cipher->cipher->blocksize + + sizeof (grub_uint32_t) - 1) + / sizeof (grub_uint32_t)); + grub_uint32_t iv[sz]; + int j; + make_iv (iv, sz, sector); + + err = grub_crypto_ecb_encrypt (dev->secondary_cipher, iv, iv, + dev->cipher->cipher->blocksize); + if (err) + return err; + + for (j = 0; j < GRUB_DISK_SECTOR_SIZE; + j += dev->cipher->cipher->blocksize) + { + grub_crypto_xor (data + i + j, data + i + j, iv, + dev->cipher->cipher->blocksize); + err = grub_crypto_ecb_decrypt (dev->cipher, data + i + j, + data + i + j, + dev->cipher->cipher->blocksize); + if (err) + return err; + grub_crypto_xor (data + i + j, data + i + j, iv, + dev->cipher->cipher->blocksize); + gf_mul_x ((grub_uint8_t *) iv); + } + sector++; + } + return GPG_ERR_NO_ERROR; + default: return GPG_ERR_NOT_IMPLEMENTED; } @@ -178,7 +239,7 @@ configure_ciphers (const struct grub_luks_phdr *header) char ciphername[sizeof (header->cipherName) + 1]; char ciphermode[sizeof (header->cipherMode) + 1]; char hashspec[sizeof (header->hashSpec) + 1]; - grub_crypto_cipher_handle_t cipher = NULL, essiv_cipher = NULL; + grub_crypto_cipher_handle_t cipher = NULL, secondary_cipher = NULL; const gcry_md_spec_t *hash = NULL, *essiv_hash = NULL; const struct gcry_cipher_spec *ciph; luks_mode_t mode; @@ -232,12 +293,13 @@ configure_ciphers (const struct grub_luks_phdr *header) } /* Configure the cipher mode. */ - if (grub_strncmp (ciphermode, "ecb", 3) == 0) + if (grub_strcmp (ciphermode, "ecb") == 0) mode = GRUB_LUKS_MODE_ECB; - else if (grub_strncmp (ciphermode, "cbc-plain", 9) == 0 - || grub_strncmp (ciphermode, "plain", 5) == 0) + else if (grub_strcmp (ciphermode, "cbc-plain") == 0 + || grub_strcmp (ciphermode, "plain") == 0) mode = GRUB_LUKS_MODE_CBC_PLAIN; - else if (grub_strncmp (ciphermode, "cbc-essiv", 9) == 0) + else if (grub_memcmp (ciphermode, "cbc-essiv:", sizeof ("cbc-essiv:") - 1) + == 0) { mode = GRUB_LUKS_MODE_CBC_ESSIV; char *hash_str = ciphermode + 10; @@ -251,13 +313,35 @@ configure_ciphers (const struct grub_luks_phdr *header) "Couldn't load %s hash", hash_str); return NULL; } - essiv_cipher = grub_crypto_cipher_open (ciph); - if (!cipher) + secondary_cipher = grub_crypto_cipher_open (ciph); + if (!secondary_cipher) { grub_crypto_cipher_close (cipher); return NULL; } } + else if (grub_strcmp (ciphermode, "xts-plain") == 0) + { + mode = GRUB_LUKS_MODE_XTS; + secondary_cipher = grub_crypto_cipher_open (ciph); + if (!secondary_cipher) + { + grub_crypto_cipher_close (cipher); + return NULL; + } + if (cipher->cipher->blocksize != 16) + { + grub_error (GRUB_ERR_BAD_ARGUMENT, "Unsupported XTS block size: %d", + cipher->cipher->blocksize); + return NULL; + } + if (secondary_cipher->cipher->blocksize != 16) + { + grub_error (GRUB_ERR_BAD_ARGUMENT, "Unsupported XTS block size: %d", + secondary_cipher->cipher->blocksize); + return NULL; + } + } else { grub_crypto_cipher_close (cipher); @@ -271,7 +355,7 @@ configure_ciphers (const struct grub_luks_phdr *header) if (!hash) { grub_crypto_cipher_close (cipher); - grub_crypto_cipher_close (essiv_cipher); + grub_crypto_cipher_close (secondary_cipher); grub_error (GRUB_ERR_FILE_NOT_FOUND, "Couldn't load %s hash", hashspec); return NULL; @@ -284,7 +368,7 @@ configure_ciphers (const struct grub_luks_phdr *header) newdev->offset = grub_be_to_cpu32 (header->payloadOffset); newdev->source_disk = NULL; newdev->mode = mode; - newdev->essiv_cipher = essiv_cipher; + newdev->secondary_cipher = secondary_cipher; newdev->essiv_hash = essiv_hash; newdev->hash = hash; newdev->id = n++; @@ -309,11 +393,11 @@ luks_recover_key (grub_luks_t dev, const struct grub_luks_phdr *header, grub_err_t err; if (dev->mode == GRUB_LUKS_MODE_CBC_ESSIV) - essiv_keysize = dev->essiv_hash->mdlen; - hashed_key = grub_malloc (dev->essiv_hash->mdlen); - if (!hashed_key) { - return grub_errno; + essiv_keysize = dev->essiv_hash->mdlen; + hashed_key = grub_malloc (dev->essiv_hash->mdlen); + if (!hashed_key) + return grub_errno; } grub_printf ("Attempting to decrypt master key...\n"); @@ -365,7 +449,9 @@ luks_recover_key (grub_luks_t dev, const struct grub_luks_phdr *header, grub_dprintf ("luks", "PBKDF2 done\n"); /* Set the PBKDF2 output as the cipher key. */ - gcry_err = grub_crypto_cipher_set_key (dev->cipher, digest, keysize); + gcry_err = grub_crypto_cipher_set_key (dev->cipher, digest, + (dev->mode == GRUB_LUKS_MODE_XTS) + ? (keysize / 2) : keysize); if (gcry_err) { grub_free (hashed_key); @@ -377,8 +463,28 @@ luks_recover_key (grub_luks_t dev, const struct grub_luks_phdr *header, if (dev->mode == GRUB_LUKS_MODE_CBC_ESSIV) { grub_crypto_hash (dev->essiv_hash, hashed_key, digest, keysize); - grub_crypto_cipher_set_key (dev->essiv_cipher, hashed_key, - essiv_keysize); + gcry_err = grub_crypto_cipher_set_key (dev->secondary_cipher, + hashed_key, + essiv_keysize); + if (gcry_err) + { + grub_free (hashed_key); + grub_free (split_key); + return grub_crypto_gcry_error (gcry_err); + } + } + + if (dev->mode == GRUB_LUKS_MODE_XTS) + { + gcry_err = grub_crypto_cipher_set_key (dev->secondary_cipher, + digest + (keysize / 2), + keysize / 2); + if (gcry_err) + { + grub_free (hashed_key); + grub_free (split_key); + return grub_crypto_gcry_error (gcry_err); + } } length = @@ -437,13 +543,17 @@ luks_recover_key (grub_luks_t dev, const struct grub_luks_phdr *header, in the header to see if it's correct. */ if (grub_memcmp (candidate_digest, header->mkDigest, sizeof (header->mkDigest)) != 0) - continue; + { + grub_dprintf ("luks", "bad digest\n"); + continue; + } grub_printf ("Slot %d opened\n", i); /* Set the master key. */ - gcry_err = grub_crypto_cipher_set_key (dev->cipher, - candidate_key, keysize); + gcry_err = grub_crypto_cipher_set_key (dev->cipher, candidate_key, + (dev->mode == GRUB_LUKS_MODE_XTS) + ? (keysize / 2) : keysize); if (gcry_err) { grub_free (hashed_key); @@ -457,7 +567,7 @@ luks_recover_key (grub_luks_t dev, const struct grub_luks_phdr *header, grub_crypto_hash (dev->essiv_hash, hashed_key, candidate_key, keysize); gcry_err = - grub_crypto_cipher_set_key (dev->essiv_cipher, hashed_key, + grub_crypto_cipher_set_key (dev->secondary_cipher, hashed_key, essiv_keysize); if (gcry_err) { @@ -467,6 +577,18 @@ luks_recover_key (grub_luks_t dev, const struct grub_luks_phdr *header, } } + if (dev->mode == GRUB_LUKS_MODE_XTS) + { + gcry_err = grub_crypto_cipher_set_key (dev->secondary_cipher, + candidate_key + (keysize / 2), + keysize / 2); + if (gcry_err) + { + grub_free (hashed_key); + grub_free (split_key); + return grub_crypto_gcry_error (gcry_err); + } + } grub_free (split_key); grub_free (hashed_key); @@ -481,7 +603,7 @@ static void luks_close (grub_luks_t luks) { grub_crypto_cipher_close (luks->cipher); - grub_crypto_cipher_close (luks->essiv_cipher); + grub_crypto_cipher_close (luks->secondary_cipher); grub_free (luks); } @@ -751,7 +873,7 @@ luks_cleanup (void) { grub_free (dev->source); grub_free (dev->cipher); - grub_free (dev->essiv_cipher); + grub_free (dev->secondary_cipher); tmp = dev->next; grub_free (dev); dev = tmp; From 50ad7d9cae1c31bbcd2ec776083f5ca59f01c06a Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 22 Apr 2011 23:39:36 +0200 Subject: [PATCH 496/869] luks grub-probe support --- grub-core/disk/luks.c | 35 ++++++++++ include/grub/crypto.h | 6 ++ include/grub/emu/hostdisk.h | 1 + util/grub-probe.c | 136 +++++++++++++++--------------------- util/import_gcry.py | 22 ++++-- 5 files changed, 116 insertions(+), 84 deletions(-) diff --git a/grub-core/disk/luks.c b/grub-core/disk/luks.c index 0098c9d49..ce1f1bfc6 100644 --- a/grub-core/disk/luks.c +++ b/grub-core/disk/luks.c @@ -863,6 +863,38 @@ grub_luks_write (grub_disk_t disk __attribute ((unused)), return GRUB_ERR_NOT_IMPLEMENTED_YET; } +#ifdef GRUB_UTIL +static grub_disk_memberlist_t +grub_luks_memberlist (grub_disk_t disk) +{ + grub_luks_t dev = (grub_luks_t) disk->data; + grub_disk_memberlist_t list = NULL; + + list = grub_malloc (sizeof (*list)); + if (list) + { + list->disk = dev->source_disk; + list->next = NULL; + } + + return list; +} + +void +grub_util_luks_print_ciphers (grub_disk_t disk) +{ + grub_luks_t dev = (grub_luks_t) disk->data; + if (dev->cipher) + grub_printf ("%s ", dev->cipher->cipher->modname); + if (dev->secondary_cipher) + grub_printf ("%s ", dev->secondary_cipher->cipher->modname); + if (dev->hash) + grub_printf ("%s ", dev->hash->modname); + if (dev->essiv_hash) + grub_printf ("%s ", dev->essiv_hash->modname); +} +#endif + static void luks_cleanup (void) { @@ -953,6 +985,9 @@ static struct grub_disk_dev grub_luks_dev = { .close = grub_luks_close, .read = grub_luks_read, .write = grub_luks_write, +#ifdef GRUB_UTIL + .memberlist = grub_luks_memberlist, +#endif .next = 0 }; diff --git a/include/grub/crypto.h b/include/grub/crypto.h index a8ca2106d..62ed2015c 100644 --- a/include/grub/crypto.h +++ b/include/grub/crypto.h @@ -126,6 +126,9 @@ typedef struct gcry_cipher_spec gcry_cipher_decrypt_t decrypt; gcry_cipher_stencrypt_t stencrypt; gcry_cipher_stdecrypt_t stdecrypt; +#ifdef GRUB_UTIL + const char *modname; +#endif struct gcry_cipher_spec *next; } gcry_cipher_spec_t; @@ -161,6 +164,9 @@ typedef struct gcry_md_spec grub_size_t contextsize; /* allocate this amount of context */ /* Block size, needed for HMAC. */ grub_size_t blocksize; +#ifdef GRUB_UTIL + const char *modname; +#endif struct gcry_md_spec *next; } gcry_md_spec_t; diff --git a/include/grub/emu/hostdisk.h b/include/grub/emu/hostdisk.h index c7a794d68..2be24cc3f 100644 --- a/include/grub/emu/hostdisk.h +++ b/include/grub/emu/hostdisk.h @@ -36,5 +36,6 @@ grub_util_fd_sector_seek (int fd, const char *name, grub_disk_addr_t sector); ssize_t grub_util_fd_read (int fd, char *buf, size_t len); grub_err_t grub_luks_cheat_mount (const char *sourcedev, const char *cheat); +void grub_util_luks_print_ciphers (grub_disk_t disk); #endif /* ! GRUB_BIOSDISK_MACHINE_UTIL_HEADER */ diff --git a/util/grub-probe.c b/util/grub-probe.c index 6c6220b8b..68d9b06f1 100644 --- a/util/grub-probe.c +++ b/util/grub-probe.c @@ -34,6 +34,7 @@ #include #include #include +#include #include #include @@ -63,15 +64,28 @@ static void probe_partmap (grub_disk_t disk) { grub_partition_t part; + grub_disk_memberlist_t list = NULL, tmp; if (disk->partition == NULL) { grub_util_info ("no partition map found for %s", disk->name); - return; } for (part = disk->partition; part; part = part->parent) - printf ("%s\n", part->partmap->name); + printf ("%s ", part->partmap->name); + + /* In case of LVM/RAID, check the member devices as well. */ + if (disk->dev->memberlist) + { + list = disk->dev->memberlist (disk); + } + while (list) + { + probe_partmap (list->disk); + tmp = list->next; + free (list); + list = tmp; + } } static int @@ -88,6 +102,45 @@ probe_raid_level (grub_disk_t disk) return ((struct grub_raid_array *) disk->data)->level; } +static void +probe_abstraction (grub_disk_t disk) +{ + grub_disk_memberlist_t list = NULL, tmp; + int raid_level; + + if (disk->dev->memberlist) + list = disk->dev->memberlist (disk); + while (list) + { + probe_abstraction (list->disk); + + tmp = list->next; + free (list); + list = tmp; + } + + if (disk->dev->id == GRUB_DISK_DEVICE_LVM_ID) + printf ("lvm "); + + if (disk->dev->id == GRUB_DISK_DEVICE_LUKS_ID) + { + printf ("luks "); + grub_util_luks_print_ciphers (disk); + } + + raid_level = probe_raid_level (disk); + if (raid_level >= 0) + { + printf ("raid "); + if (disk->dev->raidname) + printf ("%s ", disk->dev->raidname (disk)); + } + if (raid_level == 5) + printf ("raid5rec "); + if (raid_level == 6) + printf ("raid6rec "); +} + static void probe (const char *path, char *device_name) { @@ -136,91 +189,16 @@ probe (const char *path, char *device_name) if (print == PRINT_ABSTRACTION) { - grub_disk_memberlist_t list = NULL, tmp; - const int is_lvm = (dev->disk->dev->id == GRUB_DISK_DEVICE_LVM_ID); - int is_raid = 0; - int is_raid5 = 0; - int is_raid6 = 0; - int raid_level; - grub_disk_t raid_disk; - - raid_level = probe_raid_level (dev->disk); - if (raid_level >= 0) - { - is_raid = 1; - is_raid5 |= (raid_level == 5); - is_raid6 |= (raid_level == 6); - raid_disk = dev->disk; - } - - if ((is_lvm) && (dev->disk->dev->memberlist)) - list = dev->disk->dev->memberlist (dev->disk); - while (list) - { - raid_level = probe_raid_level (list->disk); - if (raid_level >= 0) - { - is_raid = 1; - is_raid5 |= (raid_level == 5); - is_raid6 |= (raid_level == 6); - raid_disk = list->disk; - } - - tmp = list->next; - free (list); - list = tmp; - } - - if (is_raid) - { - printf ("raid "); - if (is_raid5) - printf ("raid5rec "); - if (is_raid6) - printf ("raid6rec "); - if (raid_disk->dev->raidname) - printf ("%s ", raid_disk->dev->raidname (raid_disk)); - } - - if (is_lvm) - printf ("lvm "); - + probe_abstraction (dev->disk); printf ("\n"); - goto end; } if (print == PRINT_PARTMAP) { - grub_disk_memberlist_t list = NULL, tmp; - /* Check if dev->disk itself is contained in a partmap. */ probe_partmap (dev->disk); - - /* In case of LVM/RAID, check the member devices as well. */ - if (dev->disk->dev->memberlist) - list = dev->disk->dev->memberlist (dev->disk); - while (list) - { - probe_partmap (list->disk); - /* LVM on RAID */ - if (list->disk->dev->memberlist) - { - grub_disk_memberlist_t sub_list; - - sub_list = list->disk->dev->memberlist (list->disk); - while (sub_list) - { - probe_partmap (sub_list->disk); - tmp = sub_list->next; - free (sub_list); - sub_list = tmp; - } - } - tmp = list->next; - free (list); - list = tmp; - } + printf ("\n"); goto end; } diff --git a/util/import_gcry.py b/util/import_gcry.py index 3a110f028..0ebfd1f56 100644 --- a/util/import_gcry.py +++ b/util/import_gcry.py @@ -111,6 +111,7 @@ for cipher_file in cipher_files: skip = False skip2 = False ismd = False + iscipher = False iscryptostart = False iscomma = False isglue = False @@ -140,15 +141,22 @@ for cipher_file in cipher_files: sg = s.groups()[0] cryptolist.write (("%s: %s\n") % (sg, modname)) iscryptostart = False - if ismd: + if ismd or iscipher: if not re.search (" *};", line) is None: - if not mdblocksizes.has_key (mdname): - print ("ERROR: Unknown digest blocksize: %s\n" % mdname) - exit (1) if not iscomma: fw.write (" ,\n") - fw.write (" .blocksize = %s\n" % mdblocksizes [mdname]) + fw.write ("#ifdef GRUB_UTIL\n"); + fw.write (" .modname = \"%s\",\n" % modname); + fw.write ("#endif\n"); + if ismd: + if not mdblocksizes.has_key (mdname): + print ("ERROR: Unknown digest blocksize: %s\n" + % mdname) + exit (1) + fw.write (" .blocksize = %s\n" + % mdblocksizes [mdname]) ismd = False + iscipher = False iscomma = not re.search (",$", line) is None # Used only for selftests. m = re.match ("(static byte|static unsigned char) (weak_keys_chksum)\[[0-9]*\] =", line) @@ -189,14 +197,18 @@ for cipher_file in cipher_files: continue m = re.match ("gcry_cipher_spec_t", line) if isc and not m is None: + assert (not iscryptostart) + assert (not iscipher) assert (not iscryptostart) ciphername = line [len ("gcry_cipher_spec_t"):].strip () ciphername = re.match("[a-zA-Z0-9_]*",ciphername).group () ciphernames.append (ciphername) + iscipher = True iscryptostart = True m = re.match ("gcry_md_spec_t", line) if isc and not m is None: assert (not ismd) + assert (not iscipher) assert (not iscryptostart) mdname = line [len ("gcry_md_spec_t"):].strip () mdname = re.match("[a-zA-Z0-9_]*",mdname).group () From 9d647e4e181b0f88b5107b3f00e4f7d3bb9a1686 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 22 Apr 2011 23:51:16 +0200 Subject: [PATCH 497/869] New -t luks_uuid --- grub-core/disk/luks.c | 7 +++++++ include/grub/emu/hostdisk.h | 1 + util/grub-probe.c | 35 +++++++++++++++++++++++++++++++++-- 3 files changed, 41 insertions(+), 2 deletions(-) diff --git a/grub-core/disk/luks.c b/grub-core/disk/luks.c index ce1f1bfc6..997e2eb30 100644 --- a/grub-core/disk/luks.c +++ b/grub-core/disk/luks.c @@ -893,6 +893,13 @@ grub_util_luks_print_ciphers (grub_disk_t disk) if (dev->essiv_hash) grub_printf ("%s ", dev->essiv_hash->modname); } + +void +grub_util_luks_print_uuid (grub_disk_t disk) +{ + grub_luks_t dev = (grub_luks_t) disk->data; + grub_printf ("%s ", dev->uuid); +} #endif static void diff --git a/include/grub/emu/hostdisk.h b/include/grub/emu/hostdisk.h index 2be24cc3f..7541308e6 100644 --- a/include/grub/emu/hostdisk.h +++ b/include/grub/emu/hostdisk.h @@ -37,5 +37,6 @@ ssize_t grub_util_fd_read (int fd, char *buf, size_t len); grub_err_t grub_luks_cheat_mount (const char *sourcedev, const char *cheat); void grub_util_luks_print_ciphers (grub_disk_t disk); +void grub_util_luks_print_uuid (grub_disk_t disk); #endif /* ! GRUB_BIOSDISK_MACHINE_UTIL_HEADER */ diff --git a/util/grub-probe.c b/util/grub-probe.c index 68d9b06f1..21fc21b02 100644 --- a/util/grub-probe.c +++ b/util/grub-probe.c @@ -55,6 +55,7 @@ enum { PRINT_DEVICE, PRINT_PARTMAP, PRINT_ABSTRACTION, + PRINT_LUKS_UUID }; int print = PRINT_FS; @@ -88,6 +89,27 @@ probe_partmap (grub_disk_t disk) } } +static void +probe_luks_uuid (grub_disk_t disk) +{ + grub_disk_memberlist_t list = NULL, tmp; + + /* In case of LVM/RAID, check the member devices as well. */ + if (disk->dev->memberlist) + { + list = disk->dev->memberlist (disk); + } + while (list) + { + probe_luks_uuid (list->disk); + tmp = list->next; + free (list); + list = tmp; + } + if (disk->dev->id == GRUB_DISK_DEVICE_LUKS_ID) + grub_util_luks_print_uuid (disk); +} + static int probe_raid_level (grub_disk_t disk) { @@ -194,6 +216,13 @@ probe (const char *path, char *device_name) goto end; } + if (print == PRINT_LUKS_UUID) + { + probe_luks_uuid (dev->disk); + printf ("\n"); + goto end; + } + if (print == PRINT_PARTMAP) { /* Check if dev->disk itself is contained in a partmap. */ @@ -267,8 +296,8 @@ Probe device information for a given path (or device, if the -d option is given) \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\ - -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\ + -t, --target=(fs|fs_uuid|fs_label|drive|device|partmap|abstraction|luks_uuid)\n\ + print filesystem module, GRUB drive, system device, partition map module, abstraction module or LUKS UUID [default=fs]\n\ -h, --help display this message and exit\n\ -V, --version print version information and exit\n\ -v, --verbose print verbose messages\n\ @@ -326,6 +355,8 @@ main (int argc, char *argv[]) print = PRINT_PARTMAP; else if (!strcmp (optarg, "abstraction")) print = PRINT_ABSTRACTION; + else if (!strcmp (optarg, "luks_uuid")) + print = PRINT_LUKS_UUID; else usage (1); break; From 8306591ff30a94c5f9dfcaa4ee02a06a8c0021a5 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 23 Apr 2011 00:13:56 +0200 Subject: [PATCH 498/869] support LUKS in shell libraries --- util/grub-install.in | 8 ++++++++ util/grub-mkconfig.in | 1 + util/grub-mkconfig_lib.in | 20 +++++++++++++++++++- 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/util/grub-install.in b/util/grub-install.in index ff8bea87c..3b3383ab4 100644 --- a/util/grub-install.in +++ b/util/grub-install.in @@ -456,6 +456,8 @@ for dir in "${localedir}"/*; do fi done +is_path_readable_by_grub "${grubdir}" || (echo "${grubdir}" not readable 1>&2 ; exit 1) + # Write device to a variable so we don't have to traverse /dev every time. grub_device="`"$grub_probe" --device-map="${device_map}" --target=device "${grubdir}"`" || exit 1 @@ -536,6 +538,12 @@ if [ "x${devabstraction_module}" = "x" ] ; then exit 1 fi + if [ x$GRUB_LUKS_ENABLE = xy ]; then + for uuid in "`"${grub_probe}" --device "${device}" --target=luks_uuid`"; do + echo "luksmount -u $uuid" + done + fi + echo "search.fs_uuid ${uuid} root " >> "${grubdir}/load.cfg" echo 'set prefix=($root)'"${relative_grubdir}" >> "${grubdir}/load.cfg" config_opt="-c ${grubdir}/load.cfg " diff --git a/util/grub-mkconfig.in b/util/grub-mkconfig.in index afc66f886..41e68bc1b 100644 --- a/util/grub-mkconfig.in +++ b/util/grub-mkconfig.in @@ -254,6 +254,7 @@ export GRUB_DEFAULT \ GRUB_DISABLE_OS_PROBER \ GRUB_INIT_TUNE \ GRUB_SAVEDEFAULT \ + GRUB_ENABLE_LUKS \ GRUB_BADRAM if test "x${grub_cfg}" != "x"; then diff --git a/util/grub-mkconfig_lib.in b/util/grub-mkconfig_lib.in index 2c5fd8c6f..1664b6bbe 100644 --- a/util/grub-mkconfig_lib.in +++ b/util/grub-mkconfig_lib.in @@ -63,10 +63,22 @@ is_path_readable_by_grub () # ... or if we can't figure out the abstraction module, for example if # memberlist fails on an LVM volume group. - if ${grub_probe} -t abstraction $path > /dev/null 2>&1 ; then : ; else + if abstractions="`"${grub_probe}" -t abstraction "$path"`" 2>&1 ; then + : + else return 1 fi + if [ x$GRUB_LUKS_ENABLE = xy ]; then + return 0 + fi + + for abstraction in $abstractions; do + if [ "x$abstraction" = xluks ]; then + return 1 + fi + done + return 0 } @@ -126,6 +138,12 @@ prepare_grub_to_access_device () echo "insmod ${module}" done + if [ x$GRUB_LUKS_ENABLE = xy ]; then + for uuid in "`"${grub_probe}" --device "${device}" --target=luks_uuid`"; do + echo "luksmount -u $uuid" + done + fi + # If there's a filesystem UUID that GRUB is capable of identifying, use it; # otherwise set root as per value in device.map. echo "set root='`"${grub_probe}" --device "${device}" --target=drive`'" From 4879d87871dceba99558c7911cc15b9ddee4b4bf Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 23 Apr 2011 02:01:39 +0200 Subject: [PATCH 499/869] fix bug caused by import_gcry modifications --- util/import_gcry.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/util/import_gcry.py b/util/import_gcry.py index 0ebfd1f56..727492f10 100644 --- a/util/import_gcry.py +++ b/util/import_gcry.py @@ -153,8 +153,8 @@ for cipher_file in cipher_files: print ("ERROR: Unknown digest blocksize: %s\n" % mdname) exit (1) - fw.write (" .blocksize = %s\n" - % mdblocksizes [mdname]) + fw.write (" .blocksize = %s\n" + % mdblocksizes [mdname]) ismd = False iscipher = False iscomma = not re.search (",$", line) is None From 95172af9fa30d41b6f37e32ee9e0e79a2e10930d Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 23 Apr 2011 02:04:40 +0200 Subject: [PATCH 500/869] Better IV modes support --- grub-core/disk/luks.c | 266 ++++++++++++++++++++++++------------------ 1 file changed, 151 insertions(+), 115 deletions(-) diff --git a/grub-core/disk/luks.c b/grub-core/disk/luks.c index 997e2eb30..8f8b8dbe4 100644 --- a/grub-core/disk/luks.c +++ b/grub-core/disk/luks.c @@ -70,12 +70,20 @@ struct grub_luks_phdr typedef struct grub_luks_phdr *grub_luks_phdr_t; typedef enum -{ - GRUB_LUKS_MODE_ECB, - GRUB_LUKS_MODE_CBC_PLAIN, - GRUB_LUKS_MODE_CBC_ESSIV, - GRUB_LUKS_MODE_XTS -} luks_mode_t; + { + GRUB_LUKS_MODE_ECB, + GRUB_LUKS_MODE_CBC, + GRUB_LUKS_MODE_XTS + } luks_mode_t; + +typedef enum + { + GRUB_LUKS_MODE_IV_NULL, + GRUB_LUKS_MODE_IV_PLAIN, + GRUB_LUKS_MODE_IV_PLAIN64, + GRUB_LUKS_MODE_IV_ESSIV, + GRUB_LUKS_MODE_IV_BENBI, + } luks_mode_iv_t; struct grub_luks { @@ -85,8 +93,10 @@ struct grub_luks int ref; grub_crypto_cipher_handle_t cipher; grub_crypto_cipher_handle_t secondary_cipher; + grub_crypto_cipher_handle_t essiv_cipher; const gcry_md_spec_t *essiv_hash, *hash; luks_mode_t mode; + luks_mode_iv_t mode_iv; unsigned long id, source_id; enum grub_disk_dev_id source_dev_id; char uuid[sizeof (((struct grub_luks_phdr *) 0)->uuid) + 1]; @@ -112,13 +122,6 @@ static const struct grub_arg_option options[] = {0, 0, 0, 0, 0, 0} }; -static inline void -make_iv (grub_uint32_t *iv, grub_size_t sz, grub_disk_addr_t sector) -{ - grub_memset (iv, 0, sz * sizeof (iv[0])); - iv[0] = grub_cpu_to_le32 (sector & 0xFFFFFFFF); -} - /* Our irreducible polynom is x^128+x^7+x^2+x+1. Lowest byte of it is: */ #define POLYNOM 0x87 @@ -141,89 +144,83 @@ gf_mul_x (grub_uint8_t *g) static gcry_err_code_t luks_decrypt (const struct grub_luks *dev, - grub_uint8_t * data, grub_size_t len, grub_size_t sector) + grub_uint8_t * data, grub_size_t len, grub_disk_addr_t sector) { grub_size_t i; gcry_err_code_t err; - switch (dev->mode) + /* The only mode without IV. */ + if (dev->mode == GRUB_LUKS_MODE_ECB) + return grub_crypto_ecb_decrypt (dev->cipher, data, data, len); + + for (i = 0; i < len; i += GRUB_DISK_SECTOR_SIZE) { - case GRUB_LUKS_MODE_ECB: - return grub_crypto_ecb_decrypt (dev->cipher, data, data, len); + grub_size_t sz = ((dev->cipher->cipher->blocksize + + sizeof (grub_uint32_t) - 1) + / sizeof (grub_uint32_t)); + grub_uint32_t iv[sz]; - case GRUB_LUKS_MODE_CBC_PLAIN: - for (i = 0; i < len; i += GRUB_DISK_SECTOR_SIZE) + grub_memset (iv, 0, sz * sizeof (iv[0])); + switch (dev->mode_iv) { - grub_size_t sz = ((dev->cipher->cipher->blocksize - + sizeof (grub_uint32_t) - 1) - / sizeof (grub_uint32_t)); - grub_uint32_t iv[sz]; - make_iv (iv, sz, sector); + case GRUB_LUKS_MODE_IV_NULL: + break; + case GRUB_LUKS_MODE_IV_PLAIN64: + iv[1] = grub_cpu_to_le32 (sector >> 32); + case GRUB_LUKS_MODE_IV_PLAIN: + iv[0] = grub_cpu_to_le32 (sector & 0xFFFFFFFF); + break; + case GRUB_LUKS_MODE_IV_BENBI: + iv[sz - 2] = grub_cpu_to_be32 (sector >> 32); + iv[sz - 1] = grub_cpu_to_be32 (sector & 0xFFFFFFFF); + break; + case GRUB_LUKS_MODE_IV_ESSIV: + iv[0] = grub_cpu_to_le32 (sector & 0xFFFFFFFF); + err = grub_crypto_ecb_encrypt (dev->essiv_cipher, iv, iv, + dev->cipher->cipher->blocksize); + if (err) + return err; + } + + switch (dev->mode) + { + case GRUB_LUKS_MODE_CBC: err = grub_crypto_cbc_decrypt (dev->cipher, data + i, data + i, GRUB_DISK_SECTOR_SIZE, iv); if (err) return err; - sector++; + break; + + case GRUB_LUKS_MODE_XTS: + { + int j; + err = grub_crypto_ecb_encrypt (dev->secondary_cipher, iv, iv, + dev->cipher->cipher->blocksize); + if (err) + return err; + + for (j = 0; j < GRUB_DISK_SECTOR_SIZE; + j += dev->cipher->cipher->blocksize) + { + grub_crypto_xor (data + i + j, data + i + j, iv, + dev->cipher->cipher->blocksize); + err = grub_crypto_ecb_decrypt (dev->cipher, data + i + j, + data + i + j, + dev->cipher->cipher->blocksize); + if (err) + return err; + grub_crypto_xor (data + i + j, data + i + j, iv, + dev->cipher->cipher->blocksize); + gf_mul_x ((grub_uint8_t *) iv); + } + } + break; + default: + return GPG_ERR_NOT_IMPLEMENTED; } - return GPG_ERR_NO_ERROR; - - case GRUB_LUKS_MODE_CBC_ESSIV: - for (i = 0; i < len; i += GRUB_DISK_SECTOR_SIZE) - { - grub_size_t sz = ((dev->cipher->cipher->blocksize - + sizeof (grub_uint32_t) - 1) - / sizeof (grub_uint32_t)); - grub_uint32_t iv[sz]; - make_iv (iv, sz, sector); - - err = grub_crypto_ecb_encrypt (dev->secondary_cipher, iv, iv, - dev->cipher->cipher->blocksize); - if (err) - return err; - err = grub_crypto_cbc_decrypt (dev->cipher, data + i, data + i, - GRUB_DISK_SECTOR_SIZE, iv); - if (err) - return err; - sector++; - } - return GPG_ERR_NO_ERROR; - - case GRUB_LUKS_MODE_XTS: - for (i = 0; i < len; i += GRUB_DISK_SECTOR_SIZE) - { - grub_size_t sz = ((dev->cipher->cipher->blocksize - + sizeof (grub_uint32_t) - 1) - / sizeof (grub_uint32_t)); - grub_uint32_t iv[sz]; - int j; - make_iv (iv, sz, sector); - - err = grub_crypto_ecb_encrypt (dev->secondary_cipher, iv, iv, - dev->cipher->cipher->blocksize); - if (err) - return err; - - for (j = 0; j < GRUB_DISK_SECTOR_SIZE; - j += dev->cipher->cipher->blocksize) - { - grub_crypto_xor (data + i + j, data + i + j, iv, - dev->cipher->cipher->blocksize); - err = grub_crypto_ecb_decrypt (dev->cipher, data + i + j, - data + i + j, - dev->cipher->cipher->blocksize); - if (err) - return err; - grub_crypto_xor (data + i + j, data + i + j, iv, - dev->cipher->cipher->blocksize); - gf_mul_x ((grub_uint8_t *) iv); - } - sector++; - } - return GPG_ERR_NO_ERROR; - - default: - return GPG_ERR_NOT_IMPLEMENTED; + sector++; } + return GPG_ERR_NO_ERROR; } static int check_uuid, have_it; @@ -238,11 +235,14 @@ configure_ciphers (const struct grub_luks_phdr *header) char uuid[sizeof (header->uuid) + 1]; char ciphername[sizeof (header->cipherName) + 1]; char ciphermode[sizeof (header->cipherMode) + 1]; + char *cipheriv = NULL; char hashspec[sizeof (header->hashSpec) + 1]; grub_crypto_cipher_handle_t cipher = NULL, secondary_cipher = NULL; + grub_crypto_cipher_handle_t essiv_cipher = NULL; const gcry_md_spec_t *hash = NULL, *essiv_hash = NULL; const struct gcry_cipher_spec *ciph; luks_mode_t mode; + luks_mode_iv_t mode_iv; /* Look for LUKS magic sequence. */ if (grub_memcmp (header->magic, LUKS_MAGIC, sizeof (header->magic)) @@ -294,35 +294,26 @@ configure_ciphers (const struct grub_luks_phdr *header) /* Configure the cipher mode. */ if (grub_strcmp (ciphermode, "ecb") == 0) - mode = GRUB_LUKS_MODE_ECB; - else if (grub_strcmp (ciphermode, "cbc-plain") == 0 - || grub_strcmp (ciphermode, "plain") == 0) - mode = GRUB_LUKS_MODE_CBC_PLAIN; - else if (grub_memcmp (ciphermode, "cbc-essiv:", sizeof ("cbc-essiv:") - 1) - == 0) { - mode = GRUB_LUKS_MODE_CBC_ESSIV; - char *hash_str = ciphermode + 10; - - /* Configure the hash and cipher used for ESSIV. */ - essiv_hash = grub_crypto_lookup_md_by_name (hash_str); - if (!essiv_hash) - { - grub_crypto_cipher_close (cipher); - grub_error (GRUB_ERR_FILE_NOT_FOUND, - "Couldn't load %s hash", hash_str); - return NULL; - } - secondary_cipher = grub_crypto_cipher_open (ciph); - if (!secondary_cipher) - { - grub_crypto_cipher_close (cipher); - return NULL; - } + mode = GRUB_LUKS_MODE_ECB; + mode_iv = GRUB_LUKS_MODE_IV_PLAIN; + cipheriv = NULL; } - else if (grub_strcmp (ciphermode, "xts-plain") == 0) + else if (grub_strcmp (ciphermode, "plain") == 0) + { + mode = GRUB_LUKS_MODE_CBC; + mode_iv = GRUB_LUKS_MODE_IV_PLAIN; + cipheriv = NULL; + } + else if (grub_memcmp (ciphermode, "cbc-", sizeof ("cbc-") - 1) == 0) + { + mode = GRUB_LUKS_MODE_CBC; + cipheriv = ciphermode + sizeof ("cbc-") - 1; + } + else if (grub_memcmp (ciphermode, "xts-", sizeof ("xts-") - 1) == 0) { mode = GRUB_LUKS_MODE_XTS; + cipheriv = ciphermode + sizeof ("xts-") - 1; secondary_cipher = grub_crypto_cipher_open (ciph); if (!secondary_cipher) { @@ -350,11 +341,51 @@ configure_ciphers (const struct grub_luks_phdr *header) return NULL; } + if (cipheriv == NULL); + else if (grub_memcmp (cipheriv, "plain", sizeof ("plain") - 1) == 0) + mode_iv = GRUB_LUKS_MODE_IV_PLAIN; + else if (grub_memcmp (cipheriv, "plain64", sizeof ("plain64") - 1) == 0) + mode_iv = GRUB_LUKS_MODE_IV_PLAIN64; + else if (grub_memcmp (cipheriv, "benbi", sizeof ("benbi") - 1) == 0) + mode_iv = GRUB_LUKS_MODE_IV_BENBI; + else if (grub_memcmp (cipheriv, "null", sizeof ("null") - 1) == 0) + mode_iv = GRUB_LUKS_MODE_IV_NULL; + else if (grub_memcmp (cipheriv, "essiv:", sizeof ("essiv:") - 1) == 0) + { + char *hash_str = cipheriv + 6; + + mode_iv = GRUB_LUKS_MODE_IV_ESSIV; + + /* Configure the hash and cipher used for ESSIV. */ + essiv_hash = grub_crypto_lookup_md_by_name (hash_str); + if (!essiv_hash) + { + grub_crypto_cipher_close (cipher); + grub_error (GRUB_ERR_FILE_NOT_FOUND, + "Couldn't load %s hash", hash_str); + return NULL; + } + essiv_cipher = grub_crypto_cipher_open (ciph); + if (!essiv_cipher) + { + grub_crypto_cipher_close (cipher); + return NULL; + } + } + else + { + grub_crypto_cipher_close (cipher); + grub_error (GRUB_ERR_BAD_ARGUMENT, "Unknown IV mode: %s", + cipheriv); + return NULL; + } + /* Configure the hash used for the AF splitter and HMAC. */ hash = grub_crypto_lookup_md_by_name (hashspec); if (!hash) { grub_crypto_cipher_close (cipher); + grub_crypto_cipher_close (essiv_cipher); grub_crypto_cipher_close (secondary_cipher); grub_error (GRUB_ERR_FILE_NOT_FOUND, "Couldn't load %s hash", hashspec); @@ -368,7 +399,9 @@ configure_ciphers (const struct grub_luks_phdr *header) newdev->offset = grub_be_to_cpu32 (header->payloadOffset); newdev->source_disk = NULL; newdev->mode = mode; + newdev->mode_iv = mode_iv; newdev->secondary_cipher = secondary_cipher; + newdev->essiv_cipher = essiv_cipher; newdev->essiv_hash = essiv_hash; newdev->hash = hash; newdev->id = n++; @@ -392,7 +425,7 @@ luks_recover_key (grub_luks_t dev, const struct grub_luks_phdr *header, grub_size_t length; grub_err_t err; - if (dev->mode == GRUB_LUKS_MODE_CBC_ESSIV) + if (dev->mode_iv == GRUB_LUKS_MODE_IV_ESSIV) { essiv_keysize = dev->essiv_hash->mdlen; hashed_key = grub_malloc (dev->essiv_hash->mdlen); @@ -433,8 +466,7 @@ luks_recover_key (grub_luks_t dev, const struct grub_luks_phdr *header, gcry_err = grub_crypto_pbkdf2 (dev->hash, (grub_uint8_t *) passphrase, grub_strlen (passphrase), header->keyblock[i].passwordSalt, - sizeof (header-> - keyblock[i].passwordSalt), + sizeof (header->keyblock[i].passwordSalt), grub_be_to_cpu32 (header->keyblock[i]. passwordIterations), digest, keysize); @@ -460,10 +492,10 @@ luks_recover_key (grub_luks_t dev, const struct grub_luks_phdr *header, } /* Configure ESSIV if necessary. */ - if (dev->mode == GRUB_LUKS_MODE_CBC_ESSIV) + if (dev->mode_iv == GRUB_LUKS_MODE_IV_ESSIV) { grub_crypto_hash (dev->essiv_hash, hashed_key, digest, keysize); - gcry_err = grub_crypto_cipher_set_key (dev->secondary_cipher, + gcry_err = grub_crypto_cipher_set_key (dev->essiv_cipher, hashed_key, essiv_keysize); if (gcry_err) @@ -562,12 +594,12 @@ luks_recover_key (grub_luks_t dev, const struct grub_luks_phdr *header, } /* Configure ESSIV if necessary. */ - if (dev->mode == GRUB_LUKS_MODE_CBC_ESSIV) + if (dev->mode_iv == GRUB_LUKS_MODE_IV_ESSIV) { grub_crypto_hash (dev->essiv_hash, hashed_key, candidate_key, keysize); gcry_err = - grub_crypto_cipher_set_key (dev->secondary_cipher, hashed_key, + grub_crypto_cipher_set_key (dev->essiv_cipher, hashed_key, essiv_keysize); if (gcry_err) { @@ -604,6 +636,7 @@ luks_close (grub_luks_t luks) { grub_crypto_cipher_close (luks->cipher); grub_crypto_cipher_close (luks->secondary_cipher); + grub_crypto_cipher_close (luks->essiv_cipher); grub_free (luks); } @@ -888,6 +921,8 @@ grub_util_luks_print_ciphers (grub_disk_t disk) grub_printf ("%s ", dev->cipher->cipher->modname); if (dev->secondary_cipher) grub_printf ("%s ", dev->secondary_cipher->cipher->modname); + if (dev->essiv_cipher) + grub_printf ("%s ", dev->essiv_cipher->cipher->modname); if (dev->hash) grub_printf ("%s ", dev->hash->modname); if (dev->essiv_hash) @@ -913,6 +948,7 @@ luks_cleanup (void) grub_free (dev->source); grub_free (dev->cipher); grub_free (dev->secondary_cipher); + grub_free (dev->essiv_cipher); tmp = dev->next; grub_free (dev); dev = tmp; From ed38c849f4bc6b193431360dd21424c013b594fd Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 23 Apr 2011 02:27:45 +0200 Subject: [PATCH 501/869] pcbc support --- grub-core/disk/luks.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/grub-core/disk/luks.c b/grub-core/disk/luks.c index 8f8b8dbe4..ac3b81e99 100644 --- a/grub-core/disk/luks.c +++ b/grub-core/disk/luks.c @@ -73,6 +73,7 @@ typedef enum { GRUB_LUKS_MODE_ECB, GRUB_LUKS_MODE_CBC, + GRUB_LUKS_MODE_PCBC, GRUB_LUKS_MODE_XTS } luks_mode_t; @@ -142,6 +143,29 @@ gf_mul_x (grub_uint8_t *g) g[0] ^= POLYNOM; } +static gcry_err_code_t +grub_crypto_pcbc_decrypt (grub_crypto_cipher_handle_t cipher, + void *out, void *in, grub_size_t size, + void *iv) +{ + grub_uint8_t *inptr, *outptr, *end; + grub_uint8_t ivt[cipher->cipher->blocksize]; + if (!cipher->cipher->decrypt) + return GPG_ERR_NOT_SUPPORTED; + if (size % cipher->cipher->blocksize != 0) + return GPG_ERR_INV_ARG; + end = (grub_uint8_t *) in + size; + for (inptr = in, outptr = out; inptr < end; + inptr += cipher->cipher->blocksize, outptr += cipher->cipher->blocksize) + { + grub_memcpy (ivt, inptr, cipher->cipher->blocksize); + cipher->cipher->decrypt (cipher->ctx, outptr, inptr); + grub_crypto_xor (outptr, outptr, iv, cipher->cipher->blocksize); + grub_crypto_xor (iv, ivt, outptr, cipher->cipher->blocksize); + } + return GPG_ERR_NO_ERROR; +} + static gcry_err_code_t luks_decrypt (const struct grub_luks *dev, grub_uint8_t * data, grub_size_t len, grub_disk_addr_t sector) @@ -191,6 +215,12 @@ luks_decrypt (const struct grub_luks *dev, return err; break; + case GRUB_LUKS_MODE_PCBC: + err = grub_crypto_pcbc_decrypt (dev->cipher, data + i, data + i, + GRUB_DISK_SECTOR_SIZE, iv); + if (err) + return err; + break; case GRUB_LUKS_MODE_XTS: { int j; @@ -310,6 +340,11 @@ configure_ciphers (const struct grub_luks_phdr *header) mode = GRUB_LUKS_MODE_CBC; cipheriv = ciphermode + sizeof ("cbc-") - 1; } + else if (grub_memcmp (ciphermode, "pcbc-", sizeof ("pcbc-") - 1) == 0) + { + mode = GRUB_LUKS_MODE_PCBC; + cipheriv = ciphermode + sizeof ("pcbc-") - 1; + } else if (grub_memcmp (ciphermode, "xts-", sizeof ("xts-") - 1) == 0) { mode = GRUB_LUKS_MODE_XTS; From 4b35060f6fd84a6fc5fb19974098d66e16a44964 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 23 Apr 2011 03:18:07 +0200 Subject: [PATCH 502/869] Fix benbi --- grub-core/disk/luks.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/grub-core/disk/luks.c b/grub-core/disk/luks.c index ac3b81e99..8af087eea 100644 --- a/grub-core/disk/luks.c +++ b/grub-core/disk/luks.c @@ -98,6 +98,7 @@ struct grub_luks const gcry_md_spec_t *essiv_hash, *hash; luks_mode_t mode; luks_mode_iv_t mode_iv; + int benbi_log; unsigned long id, source_id; enum grub_disk_dev_id source_dev_id; char uuid[sizeof (((struct grub_luks_phdr *) 0)->uuid) + 1]; @@ -195,8 +196,11 @@ luks_decrypt (const struct grub_luks *dev, iv[0] = grub_cpu_to_le32 (sector & 0xFFFFFFFF); break; case GRUB_LUKS_MODE_IV_BENBI: - iv[sz - 2] = grub_cpu_to_be32 (sector >> 32); - iv[sz - 1] = grub_cpu_to_be32 (sector & 0xFFFFFFFF); + { + grub_uint64_t num = (sector << dev->benbi_log) + 1; + iv[sz - 2] = grub_cpu_to_be32 (num >> 32); + iv[sz - 1] = grub_cpu_to_be32 (num & 0xFFFFFFFF); + } break; case GRUB_LUKS_MODE_IV_ESSIV: iv[0] = grub_cpu_to_le32 (sector & 0xFFFFFFFF); @@ -273,7 +277,8 @@ configure_ciphers (const struct grub_luks_phdr *header) const struct gcry_cipher_spec *ciph; luks_mode_t mode; luks_mode_iv_t mode_iv; - + int benbi_log = 0; + /* Look for LUKS magic sequence. */ if (grub_memcmp (header->magic, LUKS_MAGIC, sizeof (header->magic)) || grub_be_to_cpu16 (header->version) != 1) @@ -382,7 +387,16 @@ configure_ciphers (const struct grub_luks_phdr *header) else if (grub_memcmp (cipheriv, "plain64", sizeof ("plain64") - 1) == 0) mode_iv = GRUB_LUKS_MODE_IV_PLAIN64; else if (grub_memcmp (cipheriv, "benbi", sizeof ("benbi") - 1) == 0) + { + if (cipher->cipher->blocksize & (cipher->cipher->blocksize - 1) + || cipher->cipher->blocksize == 0) + grub_error (GRUB_ERR_BAD_ARGUMENT, "Unsupported benbi blocksize: %d", + cipher->cipher->blocksize); + for (benbi_log = 0; + (cipher->cipher->blocksize << benbi_log) < GRUB_DISK_SECTOR_SIZE; + benbi_log++); mode_iv = GRUB_LUKS_MODE_IV_BENBI; + } else if (grub_memcmp (cipheriv, "null", sizeof ("null") - 1) == 0) mode_iv = GRUB_LUKS_MODE_IV_NULL; else if (grub_memcmp (cipheriv, "essiv:", sizeof ("essiv:") - 1) == 0) @@ -433,6 +447,7 @@ configure_ciphers (const struct grub_luks_phdr *header) newdev->cipher = cipher; newdev->offset = grub_be_to_cpu32 (header->payloadOffset); newdev->source_disk = NULL; + newdev->benbi_log = benbi_log; newdev->mode = mode; newdev->mode_iv = mode_iv; newdev->secondary_cipher = secondary_cipher; From 2f179c3236573a4aca5816aac4b3bb5ed16f8268 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 23 Apr 2011 04:51:53 +0200 Subject: [PATCH 503/869] LRW support --- grub-core/disk/luks.c | 120 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 105 insertions(+), 15 deletions(-) diff --git a/grub-core/disk/luks.c b/grub-core/disk/luks.c index 8af087eea..775a10f20 100644 --- a/grub-core/disk/luks.c +++ b/grub-core/disk/luks.c @@ -74,7 +74,8 @@ typedef enum GRUB_LUKS_MODE_ECB, GRUB_LUKS_MODE_CBC, GRUB_LUKS_MODE_PCBC, - GRUB_LUKS_MODE_XTS + GRUB_LUKS_MODE_XTS, + GRUB_LUKS_MODE_LRW } luks_mode_t; typedef enum @@ -86,6 +87,10 @@ typedef enum GRUB_LUKS_MODE_IV_BENBI, } luks_mode_iv_t; +/* Our irreducible polynom is x^128+x^7+x^2+x+1. Lowest byte of it is: */ +#define GF_POLYNOM 0x87 +#define GF_SIZE 128 + struct grub_luks { char *source; @@ -102,6 +107,7 @@ struct grub_luks unsigned long id, source_id; enum grub_disk_dev_id source_dev_id; char uuid[sizeof (((struct grub_luks_phdr *) 0)->uuid) + 1]; + grub_uint8_t lrw_key[GF_SIZE / 8]; #ifdef GRUB_UTIL char *cheat; int cheat_fd; @@ -124,16 +130,13 @@ static const struct grub_arg_option options[] = {0, 0, 0, 0, 0, 0} }; -/* Our irreducible polynom is x^128+x^7+x^2+x+1. Lowest byte of it is: */ -#define POLYNOM 0x87 - static void gf_mul_x (grub_uint8_t *g) { int over = 0, over2 = 0; int j; - for (j = 0; j < 16; j++) + for (j = 0; j < GF_SIZE / 8; j++) { over2 = !!(g[j] & 0x80); g[j] <<= 1; @@ -141,7 +144,40 @@ gf_mul_x (grub_uint8_t *g) over = over2; } if (over) - g[0] ^= POLYNOM; + g[0] ^= GF_POLYNOM; +} + + +static void +gf_mul_x_be (grub_uint8_t *g) +{ + int over = 0, over2 = 0; + int j; + + for (j = GF_SIZE / 8 - 1; j >= 0; j--) + { + over2 = !!(g[j] & 0x80); + g[j] <<= 1; + g[j] |= over; + over = over2; + } + if (over) + g[GF_SIZE / 8 - 1] ^= GF_POLYNOM; +} + +static void +gf_mul_be (grub_uint8_t *o, const grub_uint8_t *a, const grub_uint8_t *b) +{ + int i; + grub_uint8_t t[GF_SIZE / 8]; + grub_memset (o, 0, GF_SIZE / 8); + grub_memcpy (t, b, GF_SIZE / 8); + for (i = 0; i < GF_SIZE; i++) + { + if (((a[GF_SIZE / 8 - i / 8 - 1] >> (i % 8))) & 1) + grub_crypto_xor (o, o, t, GF_SIZE / 8); + gf_mul_x_be (t); + } } static gcry_err_code_t @@ -249,6 +285,34 @@ luks_decrypt (const struct grub_luks *dev, } } break; + case GRUB_LUKS_MODE_LRW: + { + int j, k; + for (j = 0; + j < GRUB_DISK_SECTOR_SIZE; + j += dev->cipher->cipher->blocksize) + { + grub_uint8_t x[sz * sizeof (grub_uint32_t)]; + + gf_mul_be (x, dev->lrw_key, (grub_uint8_t *) iv); + grub_crypto_xor (data + i + j, data + i + j, x, + dev->cipher->cipher->blocksize); + err = grub_crypto_ecb_decrypt (dev->cipher, data + i + j, + data + i + j, + dev->cipher->cipher->blocksize); + if (err) + return err; + grub_crypto_xor (data + i + j, data + i + j, x, + dev->cipher->cipher->blocksize); + for (k = sz - 1; k >= 0; k++) + { + iv[k] = grub_cpu_to_be32 (grub_be_to_cpu32 (iv[k]) + 1); + if (iv[k] != 0) + break; + } + } + } + break; default: return GPG_ERR_NOT_IMPLEMENTED; } @@ -360,19 +424,33 @@ configure_ciphers (const struct grub_luks_phdr *header) grub_crypto_cipher_close (cipher); return NULL; } - if (cipher->cipher->blocksize != 16) + if (cipher->cipher->blocksize != GF_SIZE / 8) { + grub_crypto_cipher_close (cipher); grub_error (GRUB_ERR_BAD_ARGUMENT, "Unsupported XTS block size: %d", cipher->cipher->blocksize); return NULL; } - if (secondary_cipher->cipher->blocksize != 16) + if (secondary_cipher->cipher->blocksize != GF_SIZE / 8) { + grub_crypto_cipher_close (cipher); grub_error (GRUB_ERR_BAD_ARGUMENT, "Unsupported XTS block size: %d", secondary_cipher->cipher->blocksize); return NULL; } } + else if (grub_memcmp (ciphermode, "lrw-", sizeof ("lrw-") - 1) == 0) + { + mode = GRUB_LUKS_MODE_LRW; + cipheriv = ciphermode + sizeof ("lrw-") - 1; + if (cipher->cipher->blocksize != GF_SIZE / 8) + { + grub_crypto_cipher_close (cipher); + grub_error (GRUB_ERR_BAD_ARGUMENT, "Unsupported LRW block size: %d", + cipher->cipher->blocksize); + return NULL; + } + } else { grub_crypto_cipher_close (cipher); @@ -505,6 +583,7 @@ luks_recover_key (grub_luks_t dev, const struct grub_luks_phdr *header, for (i = 0; i < ARRAY_SIZE (header->keyblock); i++) { gcry_err_code_t gcry_err; + int real_keysize; /* Check if keyslot is enabled. */ if (grub_be_to_cpu32 (header->keyblock[i].active) != LUKS_KEY_ENABLED) @@ -530,10 +609,14 @@ luks_recover_key (grub_luks_t dev, const struct grub_luks_phdr *header, grub_dprintf ("luks", "PBKDF2 done\n"); + real_keysize = keysize; + if (dev->mode == GRUB_LUKS_MODE_XTS) + real_keysize /= 2; + if (dev->mode == GRUB_LUKS_MODE_LRW) + real_keysize -= dev->cipher->cipher->blocksize; + /* Set the PBKDF2 output as the cipher key. */ - gcry_err = grub_crypto_cipher_set_key (dev->cipher, digest, - (dev->mode == GRUB_LUKS_MODE_XTS) - ? (keysize / 2) : keysize); + gcry_err = grub_crypto_cipher_set_key (dev->cipher, digest, real_keysize); if (gcry_err) { grub_free (hashed_key); @@ -559,7 +642,7 @@ luks_recover_key (grub_luks_t dev, const struct grub_luks_phdr *header, if (dev->mode == GRUB_LUKS_MODE_XTS) { gcry_err = grub_crypto_cipher_set_key (dev->secondary_cipher, - digest + (keysize / 2), + digest + real_keysize, keysize / 2); if (gcry_err) { @@ -569,6 +652,10 @@ luks_recover_key (grub_luks_t dev, const struct grub_luks_phdr *header, } } + if (dev->mode == GRUB_LUKS_MODE_LRW) + grub_memcpy (dev->lrw_key, digest + real_keysize, + dev->cipher->cipher->blocksize); + length = grub_be_to_cpu32 (header->keyBytes) * grub_be_to_cpu32 (header->keyblock[i].stripes); @@ -634,8 +721,7 @@ luks_recover_key (grub_luks_t dev, const struct grub_luks_phdr *header, /* Set the master key. */ gcry_err = grub_crypto_cipher_set_key (dev->cipher, candidate_key, - (dev->mode == GRUB_LUKS_MODE_XTS) - ? (keysize / 2) : keysize); + real_keysize); if (gcry_err) { grub_free (hashed_key); @@ -662,7 +748,7 @@ luks_recover_key (grub_luks_t dev, const struct grub_luks_phdr *header, if (dev->mode == GRUB_LUKS_MODE_XTS) { gcry_err = grub_crypto_cipher_set_key (dev->secondary_cipher, - candidate_key + (keysize / 2), + candidate_key + real_keysize, keysize / 2); if (gcry_err) { @@ -672,6 +758,10 @@ luks_recover_key (grub_luks_t dev, const struct grub_luks_phdr *header, } } + if (dev->mode == GRUB_LUKS_MODE_LRW) + grub_memcpy (dev->lrw_key, candidate_key + real_keysize, + dev->cipher->cipher->blocksize); + grub_free (split_key); grub_free (hashed_key); From 6fd80b9ac45df8a5b417f1a215e8cd428ebe8b82 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 23 Apr 2011 12:40:43 +0200 Subject: [PATCH 504/869] factor luks_set_key out --- grub-core/disk/luks.c | 151 ++++++++++++++---------------------------- 1 file changed, 49 insertions(+), 102 deletions(-) diff --git a/grub-core/disk/luks.c b/grub-core/disk/luks.c index 775a10f20..b1c738f2a 100644 --- a/grub-core/disk/luks.c +++ b/grub-core/disk/luks.c @@ -537,6 +537,50 @@ configure_ciphers (const struct grub_luks_phdr *header) return newdev; } +static gcry_err_code_t +luks_setkey (grub_luks_t dev, grub_uint8_t *key, grub_size_t keysize) +{ + gcry_err_code_t err; + int real_keysize; + + real_keysize = keysize; + if (dev->mode == GRUB_LUKS_MODE_XTS) + real_keysize /= 2; + if (dev->mode == GRUB_LUKS_MODE_LRW) + real_keysize -= dev->cipher->cipher->blocksize; + + /* Set the PBKDF2 output as the cipher key. */ + err = grub_crypto_cipher_set_key (dev->cipher, key, real_keysize); + if (err) + return err; + + /* Configure ESSIV if necessary. */ + if (dev->mode_iv == GRUB_LUKS_MODE_IV_ESSIV) + { + grub_size_t essiv_keysize = dev->essiv_hash->mdlen; + grub_uint8_t hashed_key[essiv_keysize]; + + grub_crypto_hash (dev->essiv_hash, hashed_key, key, keysize); + err = grub_crypto_cipher_set_key (dev->essiv_cipher, + hashed_key, essiv_keysize); + if (err) + return err; + } + if (dev->mode == GRUB_LUKS_MODE_XTS) + { + err = grub_crypto_cipher_set_key (dev->secondary_cipher, + key + real_keysize, + keysize / 2); + if (err) + return err; + } + + if (dev->mode == GRUB_LUKS_MODE_LRW) + grub_memcpy (dev->lrw_key, key + real_keysize, + dev->cipher->cipher->blocksize); + return GPG_ERR_NO_ERROR; +} + static grub_err_t luks_recover_key (grub_luks_t dev, const struct grub_luks_phdr *header, const char *name, grub_disk_t source) @@ -544,37 +588,23 @@ luks_recover_key (grub_luks_t dev, const struct grub_luks_phdr *header, grub_size_t keysize = grub_be_to_cpu32 (header->keyBytes); grub_uint8_t candidate_key[keysize]; grub_uint8_t digest[keysize]; - grub_uint8_t *hashed_key = NULL; grub_uint8_t *split_key = NULL; char passphrase[MAX_PASSPHRASE] = ""; grub_uint8_t candidate_digest[sizeof (header->mkDigest)]; unsigned i; - grub_size_t essiv_keysize = 0; grub_size_t length; grub_err_t err; - if (dev->mode_iv == GRUB_LUKS_MODE_IV_ESSIV) - { - essiv_keysize = dev->essiv_hash->mdlen; - hashed_key = grub_malloc (dev->essiv_hash->mdlen); - if (!hashed_key) - return grub_errno; - } - grub_printf ("Attempting to decrypt master key...\n"); split_key = grub_malloc (keysize * LUKS_STRIPES); if (!split_key) - { - grub_free (hashed_key); - return grub_errno; - } + return grub_errno; /* Get the passphrase from the user. */ grub_printf ("Enter passphrase for %s (%s): ", name, dev->uuid); if (!grub_password_get (passphrase, MAX_PASSPHRASE)) { - grub_free (hashed_key); grub_free (split_key); return grub_error (GRUB_ERR_BAD_ARGUMENT, "Passphrase not supplied"); } @@ -583,7 +613,6 @@ luks_recover_key (grub_luks_t dev, const struct grub_luks_phdr *header, for (i = 0; i < ARRAY_SIZE (header->keyblock); i++) { gcry_err_code_t gcry_err; - int real_keysize; /* Check if keyslot is enabled. */ if (grub_be_to_cpu32 (header->keyblock[i].active) != LUKS_KEY_ENABLED) @@ -602,63 +631,21 @@ luks_recover_key (grub_luks_t dev, const struct grub_luks_phdr *header, if (gcry_err) { - grub_free (hashed_key); grub_free (split_key); return grub_crypto_gcry_error (gcry_err); } grub_dprintf ("luks", "PBKDF2 done\n"); - real_keysize = keysize; - if (dev->mode == GRUB_LUKS_MODE_XTS) - real_keysize /= 2; - if (dev->mode == GRUB_LUKS_MODE_LRW) - real_keysize -= dev->cipher->cipher->blocksize; - - /* Set the PBKDF2 output as the cipher key. */ - gcry_err = grub_crypto_cipher_set_key (dev->cipher, digest, real_keysize); + gcry_err = luks_setkey (dev, digest, keysize); if (gcry_err) { - grub_free (hashed_key); grub_free (split_key); return grub_crypto_gcry_error (gcry_err); } - /* Configure ESSIV if necessary. */ - if (dev->mode_iv == GRUB_LUKS_MODE_IV_ESSIV) - { - grub_crypto_hash (dev->essiv_hash, hashed_key, digest, keysize); - gcry_err = grub_crypto_cipher_set_key (dev->essiv_cipher, - hashed_key, - essiv_keysize); - if (gcry_err) - { - grub_free (hashed_key); - grub_free (split_key); - return grub_crypto_gcry_error (gcry_err); - } - } - - if (dev->mode == GRUB_LUKS_MODE_XTS) - { - gcry_err = grub_crypto_cipher_set_key (dev->secondary_cipher, - digest + real_keysize, - keysize / 2); - if (gcry_err) - { - grub_free (hashed_key); - grub_free (split_key); - return grub_crypto_gcry_error (gcry_err); - } - } - - if (dev->mode == GRUB_LUKS_MODE_LRW) - grub_memcpy (dev->lrw_key, digest + real_keysize, - dev->cipher->cipher->blocksize); - - length = - grub_be_to_cpu32 (header->keyBytes) * - grub_be_to_cpu32 (header->keyblock[i].stripes); + length = (grub_be_to_cpu32 (header->keyBytes) + * grub_be_to_cpu32 (header->keyblock[i].stripes)); /* Read and decrypt the key material from the disk. */ err = grub_disk_read (source, @@ -667,7 +654,6 @@ luks_recover_key (grub_luks_t dev, const struct grub_luks_phdr *header, length, split_key); if (err) { - grub_free (hashed_key); grub_free (split_key); return err; } @@ -675,7 +661,6 @@ luks_recover_key (grub_luks_t dev, const struct grub_luks_phdr *header, gcry_err = luks_decrypt (dev, split_key, length, 0); if (gcry_err) { - grub_free (hashed_key); grub_free (split_key); return grub_crypto_gcry_error (gcry_err); } @@ -685,7 +670,6 @@ luks_recover_key (grub_luks_t dev, const struct grub_luks_phdr *header, grub_be_to_cpu32 (header->keyblock[i].stripes)); if (gcry_err) { - grub_free (hashed_key); grub_free (split_key); return grub_crypto_gcry_error (gcry_err); } @@ -703,7 +687,6 @@ luks_recover_key (grub_luks_t dev, const struct grub_luks_phdr *header, sizeof (candidate_digest)); if (gcry_err) { - grub_free (hashed_key); grub_free (split_key); return grub_crypto_gcry_error (gcry_err); } @@ -720,50 +703,14 @@ luks_recover_key (grub_luks_t dev, const struct grub_luks_phdr *header, grub_printf ("Slot %d opened\n", i); /* Set the master key. */ - gcry_err = grub_crypto_cipher_set_key (dev->cipher, candidate_key, - real_keysize); + gcry_err = luks_setkey (dev, candidate_key, keysize); if (gcry_err) { - grub_free (hashed_key); grub_free (split_key); return grub_crypto_gcry_error (gcry_err); } - /* Configure ESSIV if necessary. */ - if (dev->mode_iv == GRUB_LUKS_MODE_IV_ESSIV) - { - grub_crypto_hash (dev->essiv_hash, hashed_key, - candidate_key, keysize); - gcry_err = - grub_crypto_cipher_set_key (dev->essiv_cipher, hashed_key, - essiv_keysize); - if (gcry_err) - { - grub_free (hashed_key); - grub_free (split_key); - return grub_crypto_gcry_error (gcry_err); - } - } - - if (dev->mode == GRUB_LUKS_MODE_XTS) - { - gcry_err = grub_crypto_cipher_set_key (dev->secondary_cipher, - candidate_key + real_keysize, - keysize / 2); - if (gcry_err) - { - grub_free (hashed_key); - grub_free (split_key); - return grub_crypto_gcry_error (gcry_err); - } - } - - if (dev->mode == GRUB_LUKS_MODE_LRW) - grub_memcpy (dev->lrw_key, candidate_key + real_keysize, - dev->cipher->cipher->blocksize); - grub_free (split_key); - grub_free (hashed_key); return GRUB_ERR_NONE; } From 6f33a8eebc99d6b3cb22f17a94779f6171aca17b Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 23 Apr 2011 16:41:43 +0200 Subject: [PATCH 505/869] optimize LRW --- grub-core/disk/luks.c | 114 +++++++++++++++++++++++++++++++++--------- 1 file changed, 89 insertions(+), 25 deletions(-) diff --git a/grub-core/disk/luks.c b/grub-core/disk/luks.c index b1c738f2a..542ad4c9c 100644 --- a/grub-core/disk/luks.c +++ b/grub-core/disk/luks.c @@ -108,6 +108,7 @@ struct grub_luks enum grub_disk_dev_id source_dev_id; char uuid[sizeof (((struct grub_luks_phdr *) 0)->uuid) + 1]; grub_uint8_t lrw_key[GF_SIZE / 8]; + grub_uint8_t *lrw_precalc; #ifdef GRUB_UTIL char *cheat; int cheat_fd; @@ -203,6 +204,68 @@ grub_crypto_pcbc_decrypt (grub_crypto_cipher_handle_t cipher, return GPG_ERR_NO_ERROR; } +#define GF_BYTES (GF_SIZE / 8) +#define GF_PER_SECTOR (GRUB_DISK_SECTOR_SIZE / GF_BYTES) + +struct lrw_sector +{ + grub_uint8_t low[GF_BYTES]; + grub_uint8_t high[GF_BYTES]; + grub_uint8_t low_byte, low_byte_c; +}; + +static void +generate_lrw_sector (struct lrw_sector *sec, + const struct grub_luks *dev, + const grub_uint8_t *iv) +{ + grub_uint8_t idx[GF_BYTES]; + grub_uint16_t c; + int j; + grub_memcpy (idx, iv, GF_BYTES); + sec->low_byte = (idx[GF_BYTES - 1] & (GF_PER_SECTOR - 1)); + sec->low_byte_c = (((GF_PER_SECTOR - 1) & ~sec->low_byte) + 1); + idx[GF_BYTES - 1] &= ~(GF_PER_SECTOR - 1); + gf_mul_be (sec->low, dev->lrw_key, idx); + if (!sec->low_byte) + return; + + c = idx[GF_BYTES - 1] + GF_PER_SECTOR; + if (c & 0x100) + { + for (j = GF_BYTES - 2; j >= 0; j--) + { + idx[j]++; + if (idx[j] != 0) + break; + } + } + idx[GF_BYTES - 1] = c; + gf_mul_be (sec->high, dev->lrw_key, idx); +} + +static void __attribute__ ((unused)) +lrw_xor (const struct lrw_sector *sec, + const struct grub_luks *dev, + grub_uint8_t *b) +{ + int i; + + for (i = 0; i < sec->low_byte_c * GF_BYTES; i += GF_BYTES) + grub_crypto_xor (b + i, b + i, sec->low, GF_BYTES); + grub_crypto_xor (b, b, dev->lrw_precalc + GF_BYTES * sec->low_byte, + sec->low_byte_c * GF_BYTES); + if (!sec->low_byte) + return; + + for (i = sec->low_byte_c * GF_BYTES; + i < GRUB_DISK_SECTOR_SIZE; i += GF_BYTES) + grub_crypto_xor (b + i, b + i, sec->high, GF_BYTES); + grub_crypto_xor (b + sec->low_byte_c * GF_BYTES, + b + sec->low_byte_c * GF_BYTES, + dev->lrw_precalc, sec->low_byte * GF_BYTES); +} + static gcry_err_code_t luks_decrypt (const struct grub_luks *dev, grub_uint8_t * data, grub_size_t len, grub_disk_addr_t sector) @@ -287,30 +350,16 @@ luks_decrypt (const struct grub_luks *dev, break; case GRUB_LUKS_MODE_LRW: { - int j, k; - for (j = 0; - j < GRUB_DISK_SECTOR_SIZE; - j += dev->cipher->cipher->blocksize) - { - grub_uint8_t x[sz * sizeof (grub_uint32_t)]; + struct lrw_sector sec; - gf_mul_be (x, dev->lrw_key, (grub_uint8_t *) iv); - grub_crypto_xor (data + i + j, data + i + j, x, - dev->cipher->cipher->blocksize); - err = grub_crypto_ecb_decrypt (dev->cipher, data + i + j, - data + i + j, - dev->cipher->cipher->blocksize); - if (err) - return err; - grub_crypto_xor (data + i + j, data + i + j, x, - dev->cipher->cipher->blocksize); - for (k = sz - 1; k >= 0; k++) - { - iv[k] = grub_cpu_to_be32 (grub_be_to_cpu32 (iv[k]) + 1); - if (iv[k] != 0) - break; - } - } + generate_lrw_sector (&sec, dev, (grub_uint8_t *) iv); + lrw_xor (&sec, dev, data + i); + + err = grub_crypto_ecb_decrypt (dev->cipher, data + i, + data + i, GRUB_DISK_SECTOR_SIZE); + if (err) + return err; + lrw_xor (&sec, dev, data + i); } break; default: @@ -576,8 +625,23 @@ luks_setkey (grub_luks_t dev, grub_uint8_t *key, grub_size_t keysize) } if (dev->mode == GRUB_LUKS_MODE_LRW) - grub_memcpy (dev->lrw_key, key + real_keysize, - dev->cipher->cipher->blocksize); + { + int i; + grub_uint8_t idx[GF_SIZE / 8]; + + grub_free (dev->lrw_precalc); + grub_memcpy (dev->lrw_key, key + real_keysize, + dev->cipher->cipher->blocksize); + dev->lrw_precalc = grub_malloc (GRUB_DISK_SECTOR_SIZE); + if (!dev->lrw_precalc) + return GPG_ERR_OUT_OF_MEMORY; + grub_memset (idx, 0, GF_SIZE / 8); + for (i = 0; i < GRUB_DISK_SECTOR_SIZE; i += GF_SIZE / 8) + { + idx[15] = i / (GF_SIZE / 8); + gf_mul_be (dev->lrw_precalc + i, idx, dev->lrw_key); + } + } return GPG_ERR_NO_ERROR; } From b896ae82db4584b29ebbfabac99c02a6abd070d7 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 23 Apr 2011 16:43:55 +0200 Subject: [PATCH 506/869] small readability improvement --- grub-core/disk/luks.c | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/grub-core/disk/luks.c b/grub-core/disk/luks.c index 542ad4c9c..4a35ef011 100644 --- a/grub-core/disk/luks.c +++ b/grub-core/disk/luks.c @@ -90,6 +90,8 @@ typedef enum /* Our irreducible polynom is x^128+x^7+x^2+x+1. Lowest byte of it is: */ #define GF_POLYNOM 0x87 #define GF_SIZE 128 +#define GF_BYTES (GF_SIZE / 8) +#define GF_PER_SECTOR (GRUB_DISK_SECTOR_SIZE / GF_BYTES) struct grub_luks { @@ -107,7 +109,7 @@ struct grub_luks unsigned long id, source_id; enum grub_disk_dev_id source_dev_id; char uuid[sizeof (((struct grub_luks_phdr *) 0)->uuid) + 1]; - grub_uint8_t lrw_key[GF_SIZE / 8]; + grub_uint8_t lrw_key[GF_BYTES]; grub_uint8_t *lrw_precalc; #ifdef GRUB_UTIL char *cheat; @@ -137,7 +139,7 @@ gf_mul_x (grub_uint8_t *g) int over = 0, over2 = 0; int j; - for (j = 0; j < GF_SIZE / 8; j++) + for (j = 0; j < GF_BYTES; j++) { over2 = !!(g[j] & 0x80); g[j] <<= 1; @@ -155,7 +157,7 @@ gf_mul_x_be (grub_uint8_t *g) int over = 0, over2 = 0; int j; - for (j = GF_SIZE / 8 - 1; j >= 0; j--) + for (j = GF_BYTES - 1; j >= 0; j--) { over2 = !!(g[j] & 0x80); g[j] <<= 1; @@ -163,20 +165,20 @@ gf_mul_x_be (grub_uint8_t *g) over = over2; } if (over) - g[GF_SIZE / 8 - 1] ^= GF_POLYNOM; + g[GF_BYTES - 1] ^= GF_POLYNOM; } static void gf_mul_be (grub_uint8_t *o, const grub_uint8_t *a, const grub_uint8_t *b) { int i; - grub_uint8_t t[GF_SIZE / 8]; - grub_memset (o, 0, GF_SIZE / 8); - grub_memcpy (t, b, GF_SIZE / 8); + grub_uint8_t t[GF_BYTES]; + grub_memset (o, 0, GF_BYTES); + grub_memcpy (t, b, GF_BYTES); for (i = 0; i < GF_SIZE; i++) { - if (((a[GF_SIZE / 8 - i / 8 - 1] >> (i % 8))) & 1) - grub_crypto_xor (o, o, t, GF_SIZE / 8); + if (((a[GF_BYTES - i / 8 - 1] >> (i % 8))) & 1) + grub_crypto_xor (o, o, t, GF_BYTES); gf_mul_x_be (t); } } @@ -204,9 +206,6 @@ grub_crypto_pcbc_decrypt (grub_crypto_cipher_handle_t cipher, return GPG_ERR_NO_ERROR; } -#define GF_BYTES (GF_SIZE / 8) -#define GF_PER_SECTOR (GRUB_DISK_SECTOR_SIZE / GF_BYTES) - struct lrw_sector { grub_uint8_t low[GF_BYTES]; @@ -473,14 +472,14 @@ configure_ciphers (const struct grub_luks_phdr *header) grub_crypto_cipher_close (cipher); return NULL; } - if (cipher->cipher->blocksize != GF_SIZE / 8) + if (cipher->cipher->blocksize != GF_BYTES) { grub_crypto_cipher_close (cipher); grub_error (GRUB_ERR_BAD_ARGUMENT, "Unsupported XTS block size: %d", cipher->cipher->blocksize); return NULL; } - if (secondary_cipher->cipher->blocksize != GF_SIZE / 8) + if (secondary_cipher->cipher->blocksize != GF_BYTES) { grub_crypto_cipher_close (cipher); grub_error (GRUB_ERR_BAD_ARGUMENT, "Unsupported XTS block size: %d", @@ -492,7 +491,7 @@ configure_ciphers (const struct grub_luks_phdr *header) { mode = GRUB_LUKS_MODE_LRW; cipheriv = ciphermode + sizeof ("lrw-") - 1; - if (cipher->cipher->blocksize != GF_SIZE / 8) + if (cipher->cipher->blocksize != GF_BYTES) { grub_crypto_cipher_close (cipher); grub_error (GRUB_ERR_BAD_ARGUMENT, "Unsupported LRW block size: %d", @@ -627,7 +626,7 @@ luks_setkey (grub_luks_t dev, grub_uint8_t *key, grub_size_t keysize) if (dev->mode == GRUB_LUKS_MODE_LRW) { int i; - grub_uint8_t idx[GF_SIZE / 8]; + grub_uint8_t idx[GF_BYTES]; grub_free (dev->lrw_precalc); grub_memcpy (dev->lrw_key, key + real_keysize, @@ -635,10 +634,10 @@ luks_setkey (grub_luks_t dev, grub_uint8_t *key, grub_size_t keysize) dev->lrw_precalc = grub_malloc (GRUB_DISK_SECTOR_SIZE); if (!dev->lrw_precalc) return GPG_ERR_OUT_OF_MEMORY; - grub_memset (idx, 0, GF_SIZE / 8); - for (i = 0; i < GRUB_DISK_SECTOR_SIZE; i += GF_SIZE / 8) + grub_memset (idx, 0, GF_BYTES); + for (i = 0; i < GRUB_DISK_SECTOR_SIZE; i += GF_BYTES) { - idx[15] = i / (GF_SIZE / 8); + idx[15] = i / GF_BYTES; gf_mul_be (dev->lrw_precalc + i, idx, dev->lrw_key); } } From fcf3bfb6ffcd03e2b134f6b1c09571351793d50b Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 23 Apr 2011 16:45:00 +0200 Subject: [PATCH 507/869] small readability improvement --- grub-core/disk/luks.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/grub-core/disk/luks.c b/grub-core/disk/luks.c index 4a35ef011..a9590cab5 100644 --- a/grub-core/disk/luks.c +++ b/grub-core/disk/luks.c @@ -637,7 +637,7 @@ luks_setkey (grub_luks_t dev, grub_uint8_t *key, grub_size_t keysize) grub_memset (idx, 0, GF_BYTES); for (i = 0; i < GRUB_DISK_SECTOR_SIZE; i += GF_BYTES) { - idx[15] = i / GF_BYTES; + idx[GF_BYTES - 1] = i / GF_BYTES; gf_mul_be (dev->lrw_precalc + i, idx, dev->lrw_key); } } From 8585e54becc32be8cb8e45b85fd14f5235a5c2dd Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 23 Apr 2011 18:00:42 +0200 Subject: [PATCH 508/869] factor cryptodisk part out --- Makefile.util.def | 1 + grub-core/Makefile.core.def | 5 + grub-core/disk/luks.c | 713 ++++------------------------------- grub-core/kern/emu/getroot.c | 2 +- include/grub/disk.h | 2 +- include/grub/emu/hostdisk.h | 1 - util/grub-probe.c | 11 +- 7 files changed, 80 insertions(+), 655 deletions(-) diff --git a/Makefile.util.def b/Makefile.util.def index 693a7d127..ffa7a794f 100644 --- a/Makefile.util.def +++ b/Makefile.util.def @@ -23,6 +23,7 @@ library = { common = grub-core/kern/partition.c; common = grub-core/lib/crypto.c; common = grub-core/disk/luks.c; + common = grub-core/disk/cryptodisk.c; common = grub-core/disk/AFSplitter.c; common = grub-core/lib/pbkdf2.c; common = grub-core/commands/extcmd.c; diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def index 8dc810200..c55fff13a 100644 --- a/grub-core/Makefile.core.def +++ b/grub-core/Makefile.core.def @@ -768,6 +768,11 @@ module = { common = disk/loopback.c; }; +module = { + name = cryptodisk; + common = disk/cryptodisk.c; +}; + module = { name = luks; common = disk/luks.c; diff --git a/grub-core/disk/luks.c b/grub-core/disk/luks.c index a9590cab5..361beb756 100644 --- a/grub-core/disk/luks.c +++ b/grub-core/disk/luks.c @@ -16,6 +16,7 @@ * along with GRUB. If not, see . */ +#include #include #include #include @@ -25,15 +26,6 @@ #include #include #include -#ifdef GRUB_UTIL -#include -#include -#include -#include -#include -#include -#include -#endif GRUB_MOD_LICENSE ("GPLv3+"); @@ -69,59 +61,6 @@ struct grub_luks_phdr typedef struct grub_luks_phdr *grub_luks_phdr_t; -typedef enum - { - GRUB_LUKS_MODE_ECB, - GRUB_LUKS_MODE_CBC, - GRUB_LUKS_MODE_PCBC, - GRUB_LUKS_MODE_XTS, - GRUB_LUKS_MODE_LRW - } luks_mode_t; - -typedef enum - { - GRUB_LUKS_MODE_IV_NULL, - GRUB_LUKS_MODE_IV_PLAIN, - GRUB_LUKS_MODE_IV_PLAIN64, - GRUB_LUKS_MODE_IV_ESSIV, - GRUB_LUKS_MODE_IV_BENBI, - } luks_mode_iv_t; - -/* Our irreducible polynom is x^128+x^7+x^2+x+1. Lowest byte of it is: */ -#define GF_POLYNOM 0x87 -#define GF_SIZE 128 -#define GF_BYTES (GF_SIZE / 8) -#define GF_PER_SECTOR (GRUB_DISK_SECTOR_SIZE / GF_BYTES) - -struct grub_luks -{ - char *source; - grub_uint32_t offset; - grub_disk_t source_disk; - int ref; - grub_crypto_cipher_handle_t cipher; - grub_crypto_cipher_handle_t secondary_cipher; - grub_crypto_cipher_handle_t essiv_cipher; - const gcry_md_spec_t *essiv_hash, *hash; - luks_mode_t mode; - luks_mode_iv_t mode_iv; - int benbi_log; - unsigned long id, source_id; - enum grub_disk_dev_id source_dev_id; - char uuid[sizeof (((struct grub_luks_phdr *) 0)->uuid) + 1]; - grub_uint8_t lrw_key[GF_BYTES]; - grub_uint8_t *lrw_precalc; -#ifdef GRUB_UTIL - char *cheat; - int cheat_fd; -#endif - struct grub_luks *next; -}; -typedef struct grub_luks *grub_luks_t; - -static grub_luks_t luks_list = NULL; -static grub_uint8_t n = 0; - gcry_err_code_t AF_merge (const gcry_md_spec_t * hash, grub_uint8_t * src, grub_uint8_t * dst, grub_size_t blocksize, grub_size_t blocknumbers); @@ -133,249 +72,13 @@ static const struct grub_arg_option options[] = {0, 0, 0, 0, 0, 0} }; -static void -gf_mul_x (grub_uint8_t *g) -{ - int over = 0, over2 = 0; - int j; - - for (j = 0; j < GF_BYTES; j++) - { - over2 = !!(g[j] & 0x80); - g[j] <<= 1; - g[j] |= over; - over = over2; - } - if (over) - g[0] ^= GF_POLYNOM; -} - - -static void -gf_mul_x_be (grub_uint8_t *g) -{ - int over = 0, over2 = 0; - int j; - - for (j = GF_BYTES - 1; j >= 0; j--) - { - over2 = !!(g[j] & 0x80); - g[j] <<= 1; - g[j] |= over; - over = over2; - } - if (over) - g[GF_BYTES - 1] ^= GF_POLYNOM; -} - -static void -gf_mul_be (grub_uint8_t *o, const grub_uint8_t *a, const grub_uint8_t *b) -{ - int i; - grub_uint8_t t[GF_BYTES]; - grub_memset (o, 0, GF_BYTES); - grub_memcpy (t, b, GF_BYTES); - for (i = 0; i < GF_SIZE; i++) - { - if (((a[GF_BYTES - i / 8 - 1] >> (i % 8))) & 1) - grub_crypto_xor (o, o, t, GF_BYTES); - gf_mul_x_be (t); - } -} - -static gcry_err_code_t -grub_crypto_pcbc_decrypt (grub_crypto_cipher_handle_t cipher, - void *out, void *in, grub_size_t size, - void *iv) -{ - grub_uint8_t *inptr, *outptr, *end; - grub_uint8_t ivt[cipher->cipher->blocksize]; - if (!cipher->cipher->decrypt) - return GPG_ERR_NOT_SUPPORTED; - if (size % cipher->cipher->blocksize != 0) - return GPG_ERR_INV_ARG; - end = (grub_uint8_t *) in + size; - for (inptr = in, outptr = out; inptr < end; - inptr += cipher->cipher->blocksize, outptr += cipher->cipher->blocksize) - { - grub_memcpy (ivt, inptr, cipher->cipher->blocksize); - cipher->cipher->decrypt (cipher->ctx, outptr, inptr); - grub_crypto_xor (outptr, outptr, iv, cipher->cipher->blocksize); - grub_crypto_xor (iv, ivt, outptr, cipher->cipher->blocksize); - } - return GPG_ERR_NO_ERROR; -} - -struct lrw_sector -{ - grub_uint8_t low[GF_BYTES]; - grub_uint8_t high[GF_BYTES]; - grub_uint8_t low_byte, low_byte_c; -}; - -static void -generate_lrw_sector (struct lrw_sector *sec, - const struct grub_luks *dev, - const grub_uint8_t *iv) -{ - grub_uint8_t idx[GF_BYTES]; - grub_uint16_t c; - int j; - grub_memcpy (idx, iv, GF_BYTES); - sec->low_byte = (idx[GF_BYTES - 1] & (GF_PER_SECTOR - 1)); - sec->low_byte_c = (((GF_PER_SECTOR - 1) & ~sec->low_byte) + 1); - idx[GF_BYTES - 1] &= ~(GF_PER_SECTOR - 1); - gf_mul_be (sec->low, dev->lrw_key, idx); - if (!sec->low_byte) - return; - - c = idx[GF_BYTES - 1] + GF_PER_SECTOR; - if (c & 0x100) - { - for (j = GF_BYTES - 2; j >= 0; j--) - { - idx[j]++; - if (idx[j] != 0) - break; - } - } - idx[GF_BYTES - 1] = c; - gf_mul_be (sec->high, dev->lrw_key, idx); -} - -static void __attribute__ ((unused)) -lrw_xor (const struct lrw_sector *sec, - const struct grub_luks *dev, - grub_uint8_t *b) -{ - int i; - - for (i = 0; i < sec->low_byte_c * GF_BYTES; i += GF_BYTES) - grub_crypto_xor (b + i, b + i, sec->low, GF_BYTES); - grub_crypto_xor (b, b, dev->lrw_precalc + GF_BYTES * sec->low_byte, - sec->low_byte_c * GF_BYTES); - if (!sec->low_byte) - return; - - for (i = sec->low_byte_c * GF_BYTES; - i < GRUB_DISK_SECTOR_SIZE; i += GF_BYTES) - grub_crypto_xor (b + i, b + i, sec->high, GF_BYTES); - grub_crypto_xor (b + sec->low_byte_c * GF_BYTES, - b + sec->low_byte_c * GF_BYTES, - dev->lrw_precalc, sec->low_byte * GF_BYTES); -} - -static gcry_err_code_t -luks_decrypt (const struct grub_luks *dev, - grub_uint8_t * data, grub_size_t len, grub_disk_addr_t sector) -{ - grub_size_t i; - gcry_err_code_t err; - - /* The only mode without IV. */ - if (dev->mode == GRUB_LUKS_MODE_ECB) - return grub_crypto_ecb_decrypt (dev->cipher, data, data, len); - - for (i = 0; i < len; i += GRUB_DISK_SECTOR_SIZE) - { - grub_size_t sz = ((dev->cipher->cipher->blocksize - + sizeof (grub_uint32_t) - 1) - / sizeof (grub_uint32_t)); - grub_uint32_t iv[sz]; - - grub_memset (iv, 0, sz * sizeof (iv[0])); - switch (dev->mode_iv) - { - case GRUB_LUKS_MODE_IV_NULL: - break; - case GRUB_LUKS_MODE_IV_PLAIN64: - iv[1] = grub_cpu_to_le32 (sector >> 32); - case GRUB_LUKS_MODE_IV_PLAIN: - iv[0] = grub_cpu_to_le32 (sector & 0xFFFFFFFF); - break; - case GRUB_LUKS_MODE_IV_BENBI: - { - grub_uint64_t num = (sector << dev->benbi_log) + 1; - iv[sz - 2] = grub_cpu_to_be32 (num >> 32); - iv[sz - 1] = grub_cpu_to_be32 (num & 0xFFFFFFFF); - } - break; - case GRUB_LUKS_MODE_IV_ESSIV: - iv[0] = grub_cpu_to_le32 (sector & 0xFFFFFFFF); - err = grub_crypto_ecb_encrypt (dev->essiv_cipher, iv, iv, - dev->cipher->cipher->blocksize); - if (err) - return err; - } - - switch (dev->mode) - { - case GRUB_LUKS_MODE_CBC: - err = grub_crypto_cbc_decrypt (dev->cipher, data + i, data + i, - GRUB_DISK_SECTOR_SIZE, iv); - if (err) - return err; - break; - - case GRUB_LUKS_MODE_PCBC: - err = grub_crypto_pcbc_decrypt (dev->cipher, data + i, data + i, - GRUB_DISK_SECTOR_SIZE, iv); - if (err) - return err; - break; - case GRUB_LUKS_MODE_XTS: - { - int j; - err = grub_crypto_ecb_encrypt (dev->secondary_cipher, iv, iv, - dev->cipher->cipher->blocksize); - if (err) - return err; - - for (j = 0; j < GRUB_DISK_SECTOR_SIZE; - j += dev->cipher->cipher->blocksize) - { - grub_crypto_xor (data + i + j, data + i + j, iv, - dev->cipher->cipher->blocksize); - err = grub_crypto_ecb_decrypt (dev->cipher, data + i + j, - data + i + j, - dev->cipher->cipher->blocksize); - if (err) - return err; - grub_crypto_xor (data + i + j, data + i + j, iv, - dev->cipher->cipher->blocksize); - gf_mul_x ((grub_uint8_t *) iv); - } - } - break; - case GRUB_LUKS_MODE_LRW: - { - struct lrw_sector sec; - - generate_lrw_sector (&sec, dev, (grub_uint8_t *) iv); - lrw_xor (&sec, dev, data + i); - - err = grub_crypto_ecb_decrypt (dev->cipher, data + i, - data + i, GRUB_DISK_SECTOR_SIZE); - if (err) - return err; - lrw_xor (&sec, dev, data + i); - } - break; - default: - return GPG_ERR_NOT_IMPLEMENTED; - } - sector++; - } - return GPG_ERR_NO_ERROR; -} - static int check_uuid, have_it; static char *search_uuid; -static grub_luks_t +static grub_cryptodisk_t configure_ciphers (const struct grub_luks_phdr *header) { - grub_luks_t newdev; + grub_cryptodisk_t newdev; const char *iptr; char *optr; char uuid[sizeof (header->uuid) + 1]; @@ -387,8 +90,8 @@ configure_ciphers (const struct grub_luks_phdr *header) grub_crypto_cipher_handle_t essiv_cipher = NULL; const gcry_md_spec_t *hash = NULL, *essiv_hash = NULL; const struct gcry_cipher_spec *ciph; - luks_mode_t mode; - luks_mode_iv_t mode_iv; + grub_cryptodisk_mode_t mode; + grub_cryptodisk_mode_iv_t mode_iv; int benbi_log = 0; /* Look for LUKS magic sequence. */ @@ -442,29 +145,29 @@ configure_ciphers (const struct grub_luks_phdr *header) /* Configure the cipher mode. */ if (grub_strcmp (ciphermode, "ecb") == 0) { - mode = GRUB_LUKS_MODE_ECB; - mode_iv = GRUB_LUKS_MODE_IV_PLAIN; + mode = GRUB_CRYPTODISK_MODE_ECB; + mode_iv = GRUB_CRYPTODISK_MODE_IV_PLAIN; cipheriv = NULL; } else if (grub_strcmp (ciphermode, "plain") == 0) { - mode = GRUB_LUKS_MODE_CBC; - mode_iv = GRUB_LUKS_MODE_IV_PLAIN; + mode = GRUB_CRYPTODISK_MODE_CBC; + mode_iv = GRUB_CRYPTODISK_MODE_IV_PLAIN; cipheriv = NULL; } else if (grub_memcmp (ciphermode, "cbc-", sizeof ("cbc-") - 1) == 0) { - mode = GRUB_LUKS_MODE_CBC; + mode = GRUB_CRYPTODISK_MODE_CBC; cipheriv = ciphermode + sizeof ("cbc-") - 1; } else if (grub_memcmp (ciphermode, "pcbc-", sizeof ("pcbc-") - 1) == 0) { - mode = GRUB_LUKS_MODE_PCBC; + mode = GRUB_CRYPTODISK_MODE_PCBC; cipheriv = ciphermode + sizeof ("pcbc-") - 1; } else if (grub_memcmp (ciphermode, "xts-", sizeof ("xts-") - 1) == 0) { - mode = GRUB_LUKS_MODE_XTS; + mode = GRUB_CRYPTODISK_MODE_XTS; cipheriv = ciphermode + sizeof ("xts-") - 1; secondary_cipher = grub_crypto_cipher_open (ciph); if (!secondary_cipher) @@ -472,14 +175,14 @@ configure_ciphers (const struct grub_luks_phdr *header) grub_crypto_cipher_close (cipher); return NULL; } - if (cipher->cipher->blocksize != GF_BYTES) + if (cipher->cipher->blocksize != GRUB_CRYPTODISK_GF_BYTES) { grub_crypto_cipher_close (cipher); grub_error (GRUB_ERR_BAD_ARGUMENT, "Unsupported XTS block size: %d", cipher->cipher->blocksize); return NULL; } - if (secondary_cipher->cipher->blocksize != GF_BYTES) + if (secondary_cipher->cipher->blocksize != GRUB_CRYPTODISK_GF_BYTES) { grub_crypto_cipher_close (cipher); grub_error (GRUB_ERR_BAD_ARGUMENT, "Unsupported XTS block size: %d", @@ -489,9 +192,9 @@ configure_ciphers (const struct grub_luks_phdr *header) } else if (grub_memcmp (ciphermode, "lrw-", sizeof ("lrw-") - 1) == 0) { - mode = GRUB_LUKS_MODE_LRW; + mode = GRUB_CRYPTODISK_MODE_LRW; cipheriv = ciphermode + sizeof ("lrw-") - 1; - if (cipher->cipher->blocksize != GF_BYTES) + if (cipher->cipher->blocksize != GRUB_CRYPTODISK_GF_BYTES) { grub_crypto_cipher_close (cipher); grub_error (GRUB_ERR_BAD_ARGUMENT, "Unsupported LRW block size: %d", @@ -509,9 +212,9 @@ configure_ciphers (const struct grub_luks_phdr *header) if (cipheriv == NULL); else if (grub_memcmp (cipheriv, "plain", sizeof ("plain") - 1) == 0) - mode_iv = GRUB_LUKS_MODE_IV_PLAIN; + mode_iv = GRUB_CRYPTODISK_MODE_IV_PLAIN; else if (grub_memcmp (cipheriv, "plain64", sizeof ("plain64") - 1) == 0) - mode_iv = GRUB_LUKS_MODE_IV_PLAIN64; + mode_iv = GRUB_CRYPTODISK_MODE_IV_PLAIN64; else if (grub_memcmp (cipheriv, "benbi", sizeof ("benbi") - 1) == 0) { if (cipher->cipher->blocksize & (cipher->cipher->blocksize - 1) @@ -521,15 +224,15 @@ configure_ciphers (const struct grub_luks_phdr *header) for (benbi_log = 0; (cipher->cipher->blocksize << benbi_log) < GRUB_DISK_SECTOR_SIZE; benbi_log++); - mode_iv = GRUB_LUKS_MODE_IV_BENBI; + mode_iv = GRUB_CRYPTODISK_MODE_IV_BENBI; } else if (grub_memcmp (cipheriv, "null", sizeof ("null") - 1) == 0) - mode_iv = GRUB_LUKS_MODE_IV_NULL; + mode_iv = GRUB_CRYPTODISK_MODE_IV_NULL; else if (grub_memcmp (cipheriv, "essiv:", sizeof ("essiv:") - 1) == 0) { char *hash_str = cipheriv + 6; - mode_iv = GRUB_LUKS_MODE_IV_ESSIV; + mode_iv = GRUB_CRYPTODISK_MODE_IV_ESSIV; /* Configure the hash and cipher used for ESSIV. */ essiv_hash = grub_crypto_lookup_md_by_name (hash_str); @@ -567,7 +270,7 @@ configure_ciphers (const struct grub_luks_phdr *header) return NULL; } - newdev = grub_zalloc (sizeof (struct grub_luks)); + newdev = grub_zalloc (sizeof (struct grub_cryptodisk)); if (!newdev) return NULL; newdev->cipher = cipher; @@ -580,72 +283,12 @@ configure_ciphers (const struct grub_luks_phdr *header) newdev->essiv_cipher = essiv_cipher; newdev->essiv_hash = essiv_hash; newdev->hash = hash; - newdev->id = n++; grub_memcpy (newdev->uuid, uuid, sizeof (newdev->uuid)); return newdev; } -static gcry_err_code_t -luks_setkey (grub_luks_t dev, grub_uint8_t *key, grub_size_t keysize) -{ - gcry_err_code_t err; - int real_keysize; - - real_keysize = keysize; - if (dev->mode == GRUB_LUKS_MODE_XTS) - real_keysize /= 2; - if (dev->mode == GRUB_LUKS_MODE_LRW) - real_keysize -= dev->cipher->cipher->blocksize; - - /* Set the PBKDF2 output as the cipher key. */ - err = grub_crypto_cipher_set_key (dev->cipher, key, real_keysize); - if (err) - return err; - - /* Configure ESSIV if necessary. */ - if (dev->mode_iv == GRUB_LUKS_MODE_IV_ESSIV) - { - grub_size_t essiv_keysize = dev->essiv_hash->mdlen; - grub_uint8_t hashed_key[essiv_keysize]; - - grub_crypto_hash (dev->essiv_hash, hashed_key, key, keysize); - err = grub_crypto_cipher_set_key (dev->essiv_cipher, - hashed_key, essiv_keysize); - if (err) - return err; - } - if (dev->mode == GRUB_LUKS_MODE_XTS) - { - err = grub_crypto_cipher_set_key (dev->secondary_cipher, - key + real_keysize, - keysize / 2); - if (err) - return err; - } - - if (dev->mode == GRUB_LUKS_MODE_LRW) - { - int i; - grub_uint8_t idx[GF_BYTES]; - - grub_free (dev->lrw_precalc); - grub_memcpy (dev->lrw_key, key + real_keysize, - dev->cipher->cipher->blocksize); - dev->lrw_precalc = grub_malloc (GRUB_DISK_SECTOR_SIZE); - if (!dev->lrw_precalc) - return GPG_ERR_OUT_OF_MEMORY; - grub_memset (idx, 0, GF_BYTES); - for (i = 0; i < GRUB_DISK_SECTOR_SIZE; i += GF_BYTES) - { - idx[GF_BYTES - 1] = i / GF_BYTES; - gf_mul_be (dev->lrw_precalc + i, idx, dev->lrw_key); - } - } - return GPG_ERR_NO_ERROR; -} - static grub_err_t -luks_recover_key (grub_luks_t dev, const struct grub_luks_phdr *header, +luks_recover_key (grub_cryptodisk_t dev, const struct grub_luks_phdr *header, const char *name, grub_disk_t source) { grub_size_t keysize = grub_be_to_cpu32 (header->keyBytes); @@ -700,7 +343,7 @@ luks_recover_key (grub_luks_t dev, const struct grub_luks_phdr *header, grub_dprintf ("luks", "PBKDF2 done\n"); - gcry_err = luks_setkey (dev, digest, keysize); + gcry_err = grub_cryptodisk_setkey (dev, digest, keysize); if (gcry_err) { grub_free (split_key); @@ -721,7 +364,7 @@ luks_recover_key (grub_luks_t dev, const struct grub_luks_phdr *header, return err; } - gcry_err = luks_decrypt (dev, split_key, length, 0); + gcry_err = grub_cryptodisk_decrypt (dev, split_key, length, 0); if (gcry_err) { grub_free (split_key); @@ -766,7 +409,7 @@ luks_recover_key (grub_luks_t dev, const struct grub_luks_phdr *header, grub_printf ("Slot %d opened\n", i); /* Set the master key. */ - gcry_err = luks_setkey (dev, candidate_key, keysize); + gcry_err = grub_cryptodisk_setkey (dev, candidate_key, keysize); if (gcry_err) { grub_free (split_key); @@ -782,7 +425,7 @@ luks_recover_key (grub_luks_t dev, const struct grub_luks_phdr *header, } static void -luks_close (grub_luks_t luks) +luks_close (grub_cryptodisk_t luks) { grub_crypto_cipher_close (luks->cipher); grub_crypto_cipher_close (luks->secondary_cipher); @@ -795,11 +438,12 @@ grub_luks_scan_device_real (const char *name, grub_disk_t source) { grub_err_t err; struct grub_luks_phdr header; - grub_luks_t newdev, dev; + grub_cryptodisk_t newdev, dev; - for (dev = luks_list; dev != NULL; dev = dev->next) - if (dev->source_id == source->id && dev->source_dev_id == source->dev->id) - return GRUB_ERR_NONE; + dev = grub_cryptodisk_get_by_source_disk (source); + + if (dev) + return GRUB_ERR_NONE; /* Read the LUKS header. */ err = grub_disk_read (source, 0, 0, sizeof (header), &header); @@ -817,17 +461,7 @@ grub_luks_scan_device_real (const char *name, grub_disk_t source) return err; } - newdev->source = grub_strdup (name); - if (!newdev->source) - { - grub_free (newdev); - return grub_errno; - } - - newdev->source_id = source->id; - newdev->source_dev_id = source->dev->id; - newdev->next = luks_list; - luks_list = newdev; + grub_cryptodisk_insert (newdev, name, source); have_it = 1; @@ -840,7 +474,7 @@ grub_luks_cheat_mount (const char *sourcedev, const char *cheat) { grub_err_t err; struct grub_luks_phdr header; - grub_luks_t newdev, dev; + grub_cryptodisk_t newdev, dev; grub_disk_t source; /* Try to open disk. */ @@ -848,12 +482,13 @@ grub_luks_cheat_mount (const char *sourcedev, const char *cheat) if (!source) return grub_errno; - for (dev = luks_list; dev != NULL; dev = dev->next) - if (dev->source_id == source->id && dev->source_dev_id == source->dev->id) - { - grub_disk_close (source); - return GRUB_ERR_NONE; - } + dev = grub_cryptodisk_get_by_source_disk (source); + + if (dev) + { + grub_disk_close (source); + return GRUB_ERR_NONE; + } /* Read the LUKS header. */ err = grub_disk_read (source, 0, 0, sizeof (header), &header); @@ -861,25 +496,18 @@ grub_luks_cheat_mount (const char *sourcedev, const char *cheat) return err; newdev = configure_ciphers (&header); - grub_disk_close (source); if (!newdev) - return grub_errno; - - newdev->cheat = grub_strdup (cheat); - newdev->source = grub_strdup (sourcedev); - if (!newdev->source || !newdev->cheat) { - grub_free (newdev->source); - grub_free (newdev->cheat); - grub_free (newdev); + grub_disk_close (source); return grub_errno; } - newdev->cheat_fd = -1; - newdev->source_id = source->id; - newdev->source_dev_id = source->dev->id; - newdev->next = luks_list; - luks_list = newdev; - return GRUB_ERR_NONE; + + err = grub_cryptodisk_cheat_insert (newdev, sourcedev, source, cheat); + grub_disk_close (source); + if (err) + grub_free (newdev); + + return err; } #endif @@ -903,208 +531,16 @@ grub_luks_scan_device (const char *name) return have_it && check_uuid ? 0 : 1; } -static int -grub_luks_iterate (int (*hook) (const char *name), - grub_disk_pull_t pull) -{ - grub_luks_t i; - - if (pull != GRUB_DISK_PULL_NONE) - return 0; - - for (i = luks_list; i != NULL; i = i->next) - { - char buf[30]; - grub_snprintf (buf, sizeof (buf), "luks%lu", i->id); - if (hook (buf)) - return 1; - } - - return GRUB_ERR_NONE; -} - -static grub_err_t -grub_luks_open (const char *name, grub_disk_t disk, - grub_disk_pull_t pull __attribute__ ((unused))) -{ - grub_luks_t dev; - - if (grub_memcmp (name, "luks", sizeof ("luks") - 1) != 0) - return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "No such device"); - - if (grub_memcmp (name, "luksuuid/", sizeof ("luksuuid/") - 1) == 0) - { - for (dev = luks_list; dev != NULL; dev = dev->next) - if (grub_strcasecmp (name + sizeof ("luksuuid/") - 1, dev->uuid) == 0) - break; - } - else - { - unsigned long id = grub_strtoul (name + sizeof ("luks") - 1, 0, 0); - if (grub_errno) - return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "No such device"); - /* Search for requested device in the list of LUKS devices. */ - for (dev = luks_list; dev != NULL; dev = dev->next) - if (dev->id == id) - break; - } - if (!dev) - return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "No such device"); - #ifdef GRUB_UTIL - if (dev->cheat) - { - if (dev->cheat_fd == -1) - dev->cheat_fd = open (dev->cheat, O_RDONLY); - if (dev->cheat_fd == -1) - return grub_error (GRUB_ERR_IO, "couldn't open %s: %s", - dev->cheat, strerror (errno)); - } -#endif - - if (!dev->source_disk) - { - grub_dprintf ("luks", "Opening device %s\n", name); - /* Try to open the source disk and populate the requested disk. */ - dev->source_disk = grub_disk_open (dev->source); - if (!dev->source_disk) - return grub_errno; - } - - disk->data = dev; - disk->total_sectors = grub_disk_get_size (dev->source_disk) - dev->offset; - disk->id = dev->id; - dev->ref++; - return GRUB_ERR_NONE; -} - -static void -grub_luks_close (grub_disk_t disk) -{ - grub_luks_t dev = (grub_luks_t) disk->data; - grub_dprintf ("luks", "Closing disk\n"); - - dev->ref--; - - if (dev->ref != 0) - return; -#ifdef GRUB_UTIL - if (dev->cheat) - { - close (dev->cheat_fd); - dev->cheat_fd = -1; - } -#endif - grub_disk_close (dev->source_disk); - dev->source_disk = NULL; -} - -static grub_err_t -grub_luks_read (grub_disk_t disk, grub_disk_addr_t sector, - grub_size_t size, char *buf) -{ - grub_luks_t dev = (grub_luks_t) disk->data; - grub_err_t err; - -#ifdef GRUB_UTIL - if (dev->cheat) - { - err = grub_util_fd_sector_seek (dev->cheat_fd, dev->cheat, sector); - if (err) - return err; - if (grub_util_fd_read (dev->cheat_fd, buf, size << GRUB_DISK_SECTOR_BITS) - != (ssize_t) (size << GRUB_DISK_SECTOR_BITS)) - return grub_error (GRUB_ERR_READ_ERROR, "cannot read from `%s'", - dev->cheat); - return GRUB_ERR_NONE; - } -#endif - - grub_dprintf ("luks", - "Reading %" PRIuGRUB_SIZE " sectors from sector 0x%" - PRIxGRUB_UINT64_T " with offset of %" PRIuGRUB_UINT32_T "\n", - size, sector, dev->offset); - - err = grub_disk_read (dev->source_disk, sector + dev->offset, 0, - size << GRUB_DISK_SECTOR_BITS, buf); - if (err) - { - grub_dprintf ("luks", "grub_disk_read failed with error %d\n", err); - return err; - } - return grub_crypto_gcry_error (luks_decrypt (dev, (grub_uint8_t *) buf, - size << GRUB_DISK_SECTOR_BITS, - sector)); -} - -static grub_err_t -grub_luks_write (grub_disk_t disk __attribute ((unused)), - grub_disk_addr_t sector __attribute ((unused)), - grub_size_t size __attribute ((unused)), - const char *buf __attribute ((unused))) -{ - return GRUB_ERR_NOT_IMPLEMENTED_YET; -} - -#ifdef GRUB_UTIL -static grub_disk_memberlist_t -grub_luks_memberlist (grub_disk_t disk) -{ - grub_luks_t dev = (grub_luks_t) disk->data; - grub_disk_memberlist_t list = NULL; - - list = grub_malloc (sizeof (*list)); - if (list) - { - list->disk = dev->source_disk; - list->next = NULL; - } - - return list; -} - -void -grub_util_luks_print_ciphers (grub_disk_t disk) -{ - grub_luks_t dev = (grub_luks_t) disk->data; - if (dev->cipher) - grub_printf ("%s ", dev->cipher->cipher->modname); - if (dev->secondary_cipher) - grub_printf ("%s ", dev->secondary_cipher->cipher->modname); - if (dev->essiv_cipher) - grub_printf ("%s ", dev->essiv_cipher->cipher->modname); - if (dev->hash) - grub_printf ("%s ", dev->hash->modname); - if (dev->essiv_hash) - grub_printf ("%s ", dev->essiv_hash->modname); -} void grub_util_luks_print_uuid (grub_disk_t disk) { - grub_luks_t dev = (grub_luks_t) disk->data; + grub_cryptodisk_t dev = (grub_cryptodisk_t) disk->data; grub_printf ("%s ", dev->uuid); } #endif -static void -luks_cleanup (void) -{ - grub_luks_t dev = luks_list; - grub_luks_t tmp; - - while (dev != NULL) - { - grub_free (dev->source); - grub_free (dev->cipher); - grub_free (dev->secondary_cipher); - grub_free (dev->essiv_cipher); - tmp = dev->next; - grub_free (dev); - dev = tmp; - } -} - static grub_err_t grub_cmd_luksmount (grub_extcmd_context_t ctxt, int argc, char **args) { @@ -1116,14 +552,14 @@ grub_cmd_luksmount (grub_extcmd_context_t ctxt, int argc, char **args) have_it = 0; if (state[0].set) { - grub_luks_t dev; + grub_cryptodisk_t dev; - for (dev = luks_list; dev != NULL; dev = dev->next) - if (grub_strcasecmp (dev->uuid, args[0]) == 0) - { - grub_dprintf ("luks", "already mounted as luks%lu\n", dev->id); - return GRUB_ERR_NONE; - } + dev = grub_cryptodisk_get_by_uuid (args[0]); + if (dev) + { + grub_dprintf ("luks", "already mounted as crypto%lu\n", dev->id); + return GRUB_ERR_NONE; + } check_uuid = 1; search_uuid = args[0]; @@ -1146,7 +582,7 @@ grub_cmd_luksmount (grub_extcmd_context_t ctxt, int argc, char **args) { grub_err_t err; grub_disk_t disk; - grub_luks_t dev; + grub_cryptodisk_t dev; check_uuid = 0; search_uuid = NULL; @@ -1154,13 +590,13 @@ grub_cmd_luksmount (grub_extcmd_context_t ctxt, int argc, char **args) if (!disk) return grub_errno; - for (dev = luks_list; dev != NULL; dev = dev->next) - if (dev->source_id == disk->id && dev->source_dev_id == disk->dev->id) - { - grub_dprintf ("luks", "already mounted as luks%lu\n", dev->id); - grub_disk_close (disk); - return GRUB_ERR_NONE; - } + dev = grub_cryptodisk_get_by_source_disk (disk); + if (dev) + { + grub_dprintf ("luks", "already mounted as luks%lu\n", dev->id); + grub_disk_close (disk); + return GRUB_ERR_NONE; + } err = grub_luks_scan_device_real (args[0], disk); @@ -1170,33 +606,18 @@ grub_cmd_luksmount (grub_extcmd_context_t ctxt, int argc, char **args) } } -static struct grub_disk_dev grub_luks_dev = { - .name = "luks", - .id = GRUB_DISK_DEVICE_LUKS_ID, - .iterate = grub_luks_iterate, - .open = grub_luks_open, - .close = grub_luks_close, - .read = grub_luks_read, - .write = grub_luks_write, -#ifdef GRUB_UTIL - .memberlist = grub_luks_memberlist, -#endif - .next = 0 -}; - static grub_extcmd_t cmd; GRUB_MOD_INIT (luks) { + COMPILE_TIME_ASSERT (sizeof (((struct grub_luks_phdr *) 0)->uuid) + < GRUB_CRYPTODISK_MAX_UUID_LENGTH); cmd = grub_register_extcmd ("luksmount", grub_cmd_luksmount, 0, N_("SOURCE|-u UUID|-a"), N_("Mount a LUKS device."), options); - grub_disk_dev_register (&grub_luks_dev); } GRUB_MOD_FINI (luks) { grub_unregister_extcmd (cmd); - grub_disk_dev_unregister (&grub_luks_dev); - luks_cleanup (); } diff --git a/grub-core/kern/emu/getroot.c b/grub-core/kern/emu/getroot.c index c3a971689..642d77cf0 100644 --- a/grub-core/kern/emu/getroot.c +++ b/grub-core/kern/emu/getroot.c @@ -962,7 +962,7 @@ grub_util_get_grub_dev (const char *os_dev) dash = grub_strchr (uuid + sizeof ("CRYPT-LUKS1-") - 1, '-'); if (dash) *dash = 0; - grub_dev = grub_xasprintf ("luksuuid/%s", + grub_dev = grub_xasprintf ("cryptouuid/%s", uuid + sizeof ("CRYPT-LUKS1-") - 1); grub_free (uuid); } diff --git a/include/grub/disk.h b/include/grub/disk.h index 2678ad5eb..52f3e61b0 100644 --- a/include/grub/disk.h +++ b/include/grub/disk.h @@ -42,7 +42,7 @@ enum grub_disk_dev_id GRUB_DISK_DEVICE_PXE_ID, GRUB_DISK_DEVICE_SCSI_ID, GRUB_DISK_DEVICE_FILE_ID, - GRUB_DISK_DEVICE_LUKS_ID + GRUB_DISK_DEVICE_CRYPTODISK_ID }; struct grub_disk; diff --git a/include/grub/emu/hostdisk.h b/include/grub/emu/hostdisk.h index 7541308e6..c1350a370 100644 --- a/include/grub/emu/hostdisk.h +++ b/include/grub/emu/hostdisk.h @@ -36,7 +36,6 @@ grub_util_fd_sector_seek (int fd, const char *name, grub_disk_addr_t sector); ssize_t grub_util_fd_read (int fd, char *buf, size_t len); grub_err_t grub_luks_cheat_mount (const char *sourcedev, const char *cheat); -void grub_util_luks_print_ciphers (grub_disk_t disk); void grub_util_luks_print_uuid (grub_disk_t disk); #endif /* ! GRUB_BIOSDISK_MACHINE_UTIL_HEADER */ diff --git a/util/grub-probe.c b/util/grub-probe.c index 21fc21b02..f5d93ac4e 100644 --- a/util/grub-probe.c +++ b/util/grub-probe.c @@ -35,6 +35,7 @@ #include #include #include +#include #include #include @@ -106,7 +107,8 @@ probe_luks_uuid (grub_disk_t disk) free (list); list = tmp; } - if (disk->dev->id == GRUB_DISK_DEVICE_LUKS_ID) + /* FIXME: support non-LUKS. */ + if (disk->dev->id == GRUB_DISK_DEVICE_CRYPTODISK_ID) grub_util_luks_print_uuid (disk); } @@ -144,11 +146,8 @@ probe_abstraction (grub_disk_t disk) if (disk->dev->id == GRUB_DISK_DEVICE_LVM_ID) printf ("lvm "); - if (disk->dev->id == GRUB_DISK_DEVICE_LUKS_ID) - { - printf ("luks "); - grub_util_luks_print_ciphers (disk); - } + if (disk->dev->id == GRUB_DISK_DEVICE_CRYPTODISK_ID) + grub_util_cryptodisk_print_abstraction (disk); raid_level = probe_raid_level (disk); if (raid_level >= 0) From 1a1f408f206f2e29b40b172b0e9857f0137d91a6 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 24 Apr 2011 00:00:29 +0200 Subject: [PATCH 509/869] geli support --- Makefile.util.def | 1 + grub-core/Makefile.core.def | 5 + grub-core/disk/cryptodisk.c | 643 ++++++++++++++++++++++++++++++++++++ grub-core/disk/geli.c | 515 +++++++++++++++++++++++++++++ grub-core/disk/luks.c | 4 + grub-core/lib/crypto.c | 10 +- include/grub/crypto.h | 4 +- include/grub/cryptodisk.h | 99 ++++++ util/grub-fstest.c | 8 +- 9 files changed, 1281 insertions(+), 8 deletions(-) create mode 100644 grub-core/disk/cryptodisk.c create mode 100644 grub-core/disk/geli.c create mode 100644 include/grub/cryptodisk.h diff --git a/Makefile.util.def b/Makefile.util.def index ffa7a794f..fe9e8c036 100644 --- a/Makefile.util.def +++ b/Makefile.util.def @@ -23,6 +23,7 @@ library = { common = grub-core/kern/partition.c; common = grub-core/lib/crypto.c; common = grub-core/disk/luks.c; + common = grub-core/disk/geli.c; common = grub-core/disk/cryptodisk.c; common = grub-core/disk/AFSplitter.c; common = grub-core/lib/pbkdf2.c; diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def index c55fff13a..52add9f1b 100644 --- a/grub-core/Makefile.core.def +++ b/grub-core/Makefile.core.def @@ -779,6 +779,11 @@ module = { common = disk/AFSplitter.c; }; +module = { + name = geli; + common = disk/geli.c; +}; + module = { name = lvm; common = disk/lvm.c; diff --git a/grub-core/disk/cryptodisk.c b/grub-core/disk/cryptodisk.c new file mode 100644 index 000000000..7f3b60bf5 --- /dev/null +++ b/grub-core/disk/cryptodisk.c @@ -0,0 +1,643 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2003,2007,2010,2011 Free Software Foundation, Inc. + * + * GRUB is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see . + */ + +#include +#include +#include +#include + +#ifdef GRUB_UTIL +#include +#include +#include +#include +#include +#include +#include +#endif + +GRUB_MOD_LICENSE ("GPLv3+"); + +/* Our irreducible polynom is x^128+x^7+x^2+x+1. Lowest byte of it is: */ +#define GF_POLYNOM 0x87 +#define GF_PER_SECTOR (GRUB_DISK_SECTOR_SIZE / GRUB_CRYPTODISK_GF_BYTES) + +static grub_cryptodisk_t cryptodisk_list = NULL; +static grub_uint8_t n = 0; + +static void +gf_mul_x (grub_uint8_t *g) +{ + int over = 0, over2 = 0; + int j; + + for (j = 0; j < GRUB_CRYPTODISK_GF_BYTES; j++) + { + over2 = !!(g[j] & 0x80); + g[j] <<= 1; + g[j] |= over; + over = over2; + } + if (over) + g[0] ^= GF_POLYNOM; +} + + +static void +gf_mul_x_be (grub_uint8_t *g) +{ + int over = 0, over2 = 0; + int j; + + for (j = GRUB_CRYPTODISK_GF_BYTES - 1; j >= 0; j--) + { + over2 = !!(g[j] & 0x80); + g[j] <<= 1; + g[j] |= over; + over = over2; + } + if (over) + g[GRUB_CRYPTODISK_GF_BYTES - 1] ^= GF_POLYNOM; +} + +static void +gf_mul_be (grub_uint8_t *o, const grub_uint8_t *a, const grub_uint8_t *b) +{ + int i; + grub_uint8_t t[GRUB_CRYPTODISK_GF_BYTES]; + grub_memset (o, 0, GRUB_CRYPTODISK_GF_BYTES); + grub_memcpy (t, b, GRUB_CRYPTODISK_GF_BYTES); + for (i = 0; i < GRUB_CRYPTODISK_GF_SIZE; i++) + { + if (((a[GRUB_CRYPTODISK_GF_BYTES - i / 8 - 1] >> (i % 8))) & 1) + grub_crypto_xor (o, o, t, GRUB_CRYPTODISK_GF_BYTES); + gf_mul_x_be (t); + } +} + +static gcry_err_code_t +grub_crypto_pcbc_decrypt (grub_crypto_cipher_handle_t cipher, + void *out, void *in, grub_size_t size, + void *iv) +{ + grub_uint8_t *inptr, *outptr, *end; + grub_uint8_t ivt[cipher->cipher->blocksize]; + if (!cipher->cipher->decrypt) + return GPG_ERR_NOT_SUPPORTED; + if (size % cipher->cipher->blocksize != 0) + return GPG_ERR_INV_ARG; + end = (grub_uint8_t *) in + size; + for (inptr = in, outptr = out; inptr < end; + inptr += cipher->cipher->blocksize, outptr += cipher->cipher->blocksize) + { + grub_memcpy (ivt, inptr, cipher->cipher->blocksize); + cipher->cipher->decrypt (cipher->ctx, outptr, inptr); + grub_crypto_xor (outptr, outptr, iv, cipher->cipher->blocksize); + grub_crypto_xor (iv, ivt, outptr, cipher->cipher->blocksize); + } + return GPG_ERR_NO_ERROR; +} + +struct lrw_sector +{ + grub_uint8_t low[GRUB_CRYPTODISK_GF_BYTES]; + grub_uint8_t high[GRUB_CRYPTODISK_GF_BYTES]; + grub_uint8_t low_byte, low_byte_c; +}; + +static void +generate_lrw_sector (struct lrw_sector *sec, + const struct grub_cryptodisk *dev, + const grub_uint8_t *iv) +{ + grub_uint8_t idx[GRUB_CRYPTODISK_GF_BYTES]; + grub_uint16_t c; + int j; + grub_memcpy (idx, iv, GRUB_CRYPTODISK_GF_BYTES); + sec->low_byte = (idx[GRUB_CRYPTODISK_GF_BYTES - 1] & (GF_PER_SECTOR - 1)); + sec->low_byte_c = (((GF_PER_SECTOR - 1) & ~sec->low_byte) + 1); + idx[GRUB_CRYPTODISK_GF_BYTES - 1] &= ~(GF_PER_SECTOR - 1); + gf_mul_be (sec->low, dev->lrw_key, idx); + if (!sec->low_byte) + return; + + c = idx[GRUB_CRYPTODISK_GF_BYTES - 1] + GF_PER_SECTOR; + if (c & 0x100) + { + for (j = GRUB_CRYPTODISK_GF_BYTES - 2; j >= 0; j--) + { + idx[j]++; + if (idx[j] != 0) + break; + } + } + idx[GRUB_CRYPTODISK_GF_BYTES - 1] = c; + gf_mul_be (sec->high, dev->lrw_key, idx); +} + +static void __attribute__ ((unused)) +lrw_xor (const struct lrw_sector *sec, + const struct grub_cryptodisk *dev, + grub_uint8_t *b) +{ + int i; + + for (i = 0; i < sec->low_byte_c * GRUB_CRYPTODISK_GF_BYTES; i += GRUB_CRYPTODISK_GF_BYTES) + grub_crypto_xor (b + i, b + i, sec->low, GRUB_CRYPTODISK_GF_BYTES); + grub_crypto_xor (b, b, dev->lrw_precalc + GRUB_CRYPTODISK_GF_BYTES * sec->low_byte, + sec->low_byte_c * GRUB_CRYPTODISK_GF_BYTES); + if (!sec->low_byte) + return; + + for (i = sec->low_byte_c * GRUB_CRYPTODISK_GF_BYTES; + i < GRUB_DISK_SECTOR_SIZE; i += GRUB_CRYPTODISK_GF_BYTES) + grub_crypto_xor (b + i, b + i, sec->high, GRUB_CRYPTODISK_GF_BYTES); + grub_crypto_xor (b + sec->low_byte_c * GRUB_CRYPTODISK_GF_BYTES, + b + sec->low_byte_c * GRUB_CRYPTODISK_GF_BYTES, + dev->lrw_precalc, sec->low_byte * GRUB_CRYPTODISK_GF_BYTES); +} + +gcry_err_code_t +grub_cryptodisk_decrypt (const struct grub_cryptodisk *dev, + grub_uint8_t * data, grub_size_t len, + grub_disk_addr_t sector) +{ + grub_size_t i; + gcry_err_code_t err; + + /* The only mode without IV. */ + if (dev->mode == GRUB_CRYPTODISK_MODE_ECB) + return grub_crypto_ecb_decrypt (dev->cipher, data, data, len); + + for (i = 0; i < len; i += GRUB_DISK_SECTOR_SIZE) + { + grub_size_t sz = ((dev->cipher->cipher->blocksize + + sizeof (grub_uint32_t) - 1) + / sizeof (grub_uint32_t)); + grub_uint32_t iv[sz]; + + grub_memset (iv, 0, sz * sizeof (iv[0])); + switch (dev->mode_iv) + { + case GRUB_CRYPTODISK_MODE_IV_NULL: + break; + case GRUB_CRYPTODISK_MODE_IV_BYTECOUNT64_HASH: + { + grub_uint64_t tmp; + grub_uint64_t ctx[(dev->iv_hash->contextsize + 7) / 8]; + tmp = grub_cpu_to_le64 (sector << GRUB_DISK_SECTOR_BITS); + dev->iv_hash->init (ctx); + dev->iv_hash->write (ctx, dev->iv_prefix, dev->iv_prefix_len); + dev->iv_hash->write (ctx, &tmp, sizeof (tmp)); + dev->iv_hash->final (ctx); + + grub_memcpy (iv, dev->iv_hash->read (ctx), sizeof (iv)); + } + break; + case GRUB_CRYPTODISK_MODE_IV_PLAIN64: + iv[1] = grub_cpu_to_le32 (sector >> 32); + case GRUB_CRYPTODISK_MODE_IV_PLAIN: + iv[0] = grub_cpu_to_le32 (sector & 0xFFFFFFFF); + break; + case GRUB_CRYPTODISK_MODE_IV_BENBI: + { + grub_uint64_t num = (sector << dev->benbi_log) + 1; + iv[sz - 2] = grub_cpu_to_be32 (num >> 32); + iv[sz - 1] = grub_cpu_to_be32 (num & 0xFFFFFFFF); + } + break; + case GRUB_CRYPTODISK_MODE_IV_ESSIV: + iv[0] = grub_cpu_to_le32 (sector & 0xFFFFFFFF); + err = grub_crypto_ecb_encrypt (dev->essiv_cipher, iv, iv, + dev->cipher->cipher->blocksize); + if (err) + return err; + } + + switch (dev->mode) + { + case GRUB_CRYPTODISK_MODE_CBC: + err = grub_crypto_cbc_decrypt (dev->cipher, data + i, data + i, + GRUB_DISK_SECTOR_SIZE, iv); + if (err) + return err; + break; + + case GRUB_CRYPTODISK_MODE_PCBC: + err = grub_crypto_pcbc_decrypt (dev->cipher, data + i, data + i, + GRUB_DISK_SECTOR_SIZE, iv); + if (err) + return err; + break; + case GRUB_CRYPTODISK_MODE_XTS: + { + int j; + err = grub_crypto_ecb_encrypt (dev->secondary_cipher, iv, iv, + dev->cipher->cipher->blocksize); + if (err) + return err; + + for (j = 0; j < GRUB_DISK_SECTOR_SIZE; + j += dev->cipher->cipher->blocksize) + { + grub_crypto_xor (data + i + j, data + i + j, iv, + dev->cipher->cipher->blocksize); + err = grub_crypto_ecb_decrypt (dev->cipher, data + i + j, + data + i + j, + dev->cipher->cipher->blocksize); + if (err) + return err; + grub_crypto_xor (data + i + j, data + i + j, iv, + dev->cipher->cipher->blocksize); + gf_mul_x ((grub_uint8_t *) iv); + } + } + break; + case GRUB_CRYPTODISK_MODE_LRW: + { + struct lrw_sector sec; + + generate_lrw_sector (&sec, dev, (grub_uint8_t *) iv); + lrw_xor (&sec, dev, data + i); + + err = grub_crypto_ecb_decrypt (dev->cipher, data + i, + data + i, GRUB_DISK_SECTOR_SIZE); + if (err) + return err; + lrw_xor (&sec, dev, data + i); + } + break; + default: + return GPG_ERR_NOT_IMPLEMENTED; + } + sector++; + } + return GPG_ERR_NO_ERROR; +} + +gcry_err_code_t +grub_cryptodisk_setkey (grub_cryptodisk_t dev, grub_uint8_t *key, grub_size_t keysize) +{ + gcry_err_code_t err; + int real_keysize; + + real_keysize = keysize; + if (dev->mode == GRUB_CRYPTODISK_MODE_XTS) + real_keysize /= 2; + if (dev->mode == GRUB_CRYPTODISK_MODE_LRW) + real_keysize -= dev->cipher->cipher->blocksize; + + /* Set the PBKDF2 output as the cipher key. */ + err = grub_crypto_cipher_set_key (dev->cipher, key, real_keysize); + if (err) + return err; + + /* Configure ESSIV if necessary. */ + if (dev->mode_iv == GRUB_CRYPTODISK_MODE_IV_ESSIV) + { + grub_size_t essiv_keysize = dev->essiv_hash->mdlen; + grub_uint8_t hashed_key[essiv_keysize]; + + grub_crypto_hash (dev->essiv_hash, hashed_key, key, keysize); + err = grub_crypto_cipher_set_key (dev->essiv_cipher, + hashed_key, essiv_keysize); + if (err) + return err; + } + if (dev->mode == GRUB_CRYPTODISK_MODE_XTS) + { + err = grub_crypto_cipher_set_key (dev->secondary_cipher, + key + real_keysize, + keysize / 2); + if (err) + return err; + } + + if (dev->mode == GRUB_CRYPTODISK_MODE_LRW) + { + int i; + grub_uint8_t idx[GRUB_CRYPTODISK_GF_BYTES]; + + grub_free (dev->lrw_precalc); + grub_memcpy (dev->lrw_key, key + real_keysize, + dev->cipher->cipher->blocksize); + dev->lrw_precalc = grub_malloc (GRUB_DISK_SECTOR_SIZE); + if (!dev->lrw_precalc) + return GPG_ERR_OUT_OF_MEMORY; + grub_memset (idx, 0, GRUB_CRYPTODISK_GF_BYTES); + for (i = 0; i < GRUB_DISK_SECTOR_SIZE; + i += GRUB_CRYPTODISK_GF_BYTES) + { + idx[GRUB_CRYPTODISK_GF_BYTES - 1] = i / GRUB_CRYPTODISK_GF_BYTES; + gf_mul_be (dev->lrw_precalc + i, idx, dev->lrw_key); + } + } + return GPG_ERR_NO_ERROR; +} + +static int +grub_cryptodisk_iterate (int (*hook) (const char *name), + grub_disk_pull_t pull) +{ + grub_cryptodisk_t i; + + if (pull != GRUB_DISK_PULL_NONE) + return 0; + + for (i = cryptodisk_list; i != NULL; i = i->next) + { + char buf[30]; + grub_snprintf (buf, sizeof (buf), "crypto%lu", i->id); + if (hook (buf)) + return 1; + } + + return GRUB_ERR_NONE; +} + +static grub_err_t +grub_cryptodisk_open (const char *name, grub_disk_t disk, + grub_disk_pull_t pull __attribute__ ((unused))) +{ + grub_cryptodisk_t dev; + + if (grub_memcmp (name, "crypto", sizeof ("crypto") - 1) != 0) + return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "No such device"); + + if (grub_memcmp (name, "cryptouuid/", sizeof ("cryptouuid/") - 1) == 0) + { + for (dev = cryptodisk_list; dev != NULL; dev = dev->next) + if (grub_strcasecmp (name + sizeof ("cryptouuid/") - 1, dev->uuid) == 0) + break; + } + else + { + unsigned long id = grub_strtoul (name + sizeof ("crypto") - 1, 0, 0); + if (grub_errno) + return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "No such device"); + /* Search for requested device in the list of CRYPTODISK devices. */ + for (dev = cryptodisk_list; dev != NULL; dev = dev->next) + if (dev->id == id) + break; + } + if (!dev) + return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "No such device"); + +#ifdef GRUB_UTIL + if (dev->cheat) + { + if (dev->cheat_fd == -1) + dev->cheat_fd = open (dev->cheat, O_RDONLY); + if (dev->cheat_fd == -1) + return grub_error (GRUB_ERR_IO, "couldn't open %s: %s", + dev->cheat, strerror (errno)); + } +#endif + + if (!dev->source_disk) + { + grub_dprintf ("cryptodisk", "Opening device %s\n", name); + /* Try to open the source disk and populate the requested disk. */ + dev->source_disk = grub_disk_open (dev->source); + if (!dev->source_disk) + return grub_errno; + } + + disk->data = dev; + disk->total_sectors = dev->total_length; + disk->id = dev->id; + dev->ref++; + return GRUB_ERR_NONE; +} + +static void +grub_cryptodisk_close (grub_disk_t disk) +{ + grub_cryptodisk_t dev = (grub_cryptodisk_t) disk->data; + grub_dprintf ("cryptodisk", "Closing disk\n"); + + dev->ref--; + + if (dev->ref != 0) + return; +#ifdef GRUB_UTIL + if (dev->cheat) + { + close (dev->cheat_fd); + dev->cheat_fd = -1; + } +#endif + grub_disk_close (dev->source_disk); + dev->source_disk = NULL; +} + +static grub_err_t +grub_cryptodisk_read (grub_disk_t disk, grub_disk_addr_t sector, + grub_size_t size, char *buf) +{ + grub_cryptodisk_t dev = (grub_cryptodisk_t) disk->data; + grub_err_t err; + gcry_err_code_t gcry_err; + +#ifdef GRUB_UTIL + if (dev->cheat) + { + err = grub_util_fd_sector_seek (dev->cheat_fd, dev->cheat, sector); + if (err) + return err; + if (grub_util_fd_read (dev->cheat_fd, buf, size << GRUB_DISK_SECTOR_BITS) + != (ssize_t) (size << GRUB_DISK_SECTOR_BITS)) + return grub_error (GRUB_ERR_READ_ERROR, "cannot read from `%s'", + dev->cheat); + return GRUB_ERR_NONE; + } +#endif + + grub_dprintf ("cryptodisk", + "Reading %" PRIuGRUB_SIZE " sectors from sector 0x%" + PRIxGRUB_UINT64_T " with offset of %" PRIuGRUB_UINT64_T "\n", + size, sector, dev->offset); + + err = grub_disk_read (dev->source_disk, sector + dev->offset, 0, + size << GRUB_DISK_SECTOR_BITS, buf); + if (err) + { + grub_dprintf ("cryptodisk", "grub_disk_read failed with error %d\n", err); + return err; + } + gcry_err = grub_cryptodisk_decrypt (dev, (grub_uint8_t *) buf, + size << GRUB_DISK_SECTOR_BITS, + sector); + return grub_crypto_gcry_error (gcry_err); +} + +static grub_err_t +grub_cryptodisk_write (grub_disk_t disk __attribute ((unused)), + grub_disk_addr_t sector __attribute ((unused)), + grub_size_t size __attribute ((unused)), + const char *buf __attribute ((unused))) +{ + return GRUB_ERR_NOT_IMPLEMENTED_YET; +} + +#ifdef GRUB_UTIL +static grub_disk_memberlist_t +grub_cryptodisk_memberlist (grub_disk_t disk) +{ + grub_cryptodisk_t dev = (grub_cryptodisk_t) disk->data; + grub_disk_memberlist_t list = NULL; + + list = grub_malloc (sizeof (*list)); + if (list) + { + list->disk = dev->source_disk; + list->next = NULL; + } + + return list; +} +#endif + +static void +cryptodisk_cleanup (void) +{ + grub_cryptodisk_t dev = cryptodisk_list; + grub_cryptodisk_t tmp; + + while (dev != NULL) + { + grub_free (dev->source); + grub_free (dev->cipher); + grub_free (dev->secondary_cipher); + grub_free (dev->essiv_cipher); + tmp = dev->next; + grub_free (dev); + dev = tmp; + } +} + +grub_err_t +grub_cryptodisk_insert (grub_cryptodisk_t newdev, const char *name, + grub_disk_t source) +{ + newdev->source = grub_strdup (name); + if (!newdev->source) + { + grub_free (newdev); + return grub_errno; + } + + newdev->id = n++; + newdev->source_id = source->id; + newdev->source_dev_id = source->dev->id; + newdev->next = cryptodisk_list; + cryptodisk_list = newdev; + + return GRUB_ERR_NONE; +} + +grub_cryptodisk_t +grub_cryptodisk_get_by_uuid (const char *uuid) +{ + grub_cryptodisk_t dev; + for (dev = cryptodisk_list; dev != NULL; dev = dev->next) + if (grub_strcasecmp (dev->uuid, uuid) == 0) + return dev; + return NULL; +} + +grub_cryptodisk_t +grub_cryptodisk_get_by_source_disk (grub_disk_t disk) +{ + grub_cryptodisk_t dev; + for (dev = cryptodisk_list; dev != NULL; dev = dev->next) + if (dev->source_id == disk->id && dev->source_dev_id == disk->dev->id) + return dev; + return NULL; +} + +#ifdef GRUB_UTIL +grub_err_t +grub_cryptodisk_cheat_insert (grub_cryptodisk_t newdev, const char *name, + grub_disk_t source, const char *cheat) +{ + newdev->cheat = grub_strdup (cheat); + newdev->source = grub_strdup (name); + if (!newdev->source || !newdev->cheat) + { + grub_free (newdev->source); + grub_free (newdev->cheat); + return grub_errno; + } + + newdev->cheat_fd = -1; + newdev->source_id = source->id; + newdev->source_dev_id = source->dev->id; + newdev->id = n++; + newdev->next = cryptodisk_list; + cryptodisk_list = newdev; + + return GRUB_ERR_NONE; +} + +void +grub_util_cryptodisk_print_abstraction (grub_disk_t disk) +{ + grub_cryptodisk_t dev = (grub_cryptodisk_t) disk->data; + + grub_printf ("luks "); + + if (dev->cipher) + grub_printf ("%s ", dev->cipher->cipher->modname); + if (dev->secondary_cipher) + grub_printf ("%s ", dev->secondary_cipher->cipher->modname); + if (dev->essiv_cipher) + grub_printf ("%s ", dev->essiv_cipher->cipher->modname); + if (dev->hash) + grub_printf ("%s ", dev->hash->modname); + if (dev->essiv_hash) + grub_printf ("%s ", dev->essiv_hash->modname); + if (dev->iv_hash) + grub_printf ("%s ", dev->iv_hash->modname); +} +#endif + +static struct grub_disk_dev grub_cryptodisk_dev = { + .name = "cryptodisk", + .id = GRUB_DISK_DEVICE_CRYPTODISK_ID, + .iterate = grub_cryptodisk_iterate, + .open = grub_cryptodisk_open, + .close = grub_cryptodisk_close, + .read = grub_cryptodisk_read, + .write = grub_cryptodisk_write, +#ifdef GRUB_UTIL + .memberlist = grub_cryptodisk_memberlist, +#endif + .next = 0 +}; + +GRUB_MOD_INIT (cryptodisk) +{ + grub_disk_dev_register (&grub_cryptodisk_dev); +} + +GRUB_MOD_FINI (cryptodisk) +{ + grub_disk_dev_unregister (&grub_cryptodisk_dev); + cryptodisk_cleanup (); +} diff --git a/grub-core/disk/geli.c b/grub-core/disk/geli.c new file mode 100644 index 000000000..6af1de766 --- /dev/null +++ b/grub-core/disk/geli.c @@ -0,0 +1,515 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2003,2007,2010,2011 Free Software Foundation, Inc. + * + * GRUB is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see . + */ + +/* This file is loosely based on FreeBSD geli implementation + (but no code was directly copied). FreeBSD geli is distributed under + following terms: */ +/*- + * Copyright (c) 2005-2006 Pawel Jakub Dawidek + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +GRUB_MOD_LICENSE ("GPLv3+"); + +struct grub_geli_key +{ + grub_uint8_t iv_key[64]; + grub_uint8_t cipher_key[64]; + grub_uint8_t hmac[64]; +} __attribute__ ((packed)); + +struct grub_geli_phdr +{ + grub_uint8_t magic[16]; +#define GELI_MAGIC "GEOM::ELI" + grub_uint32_t version; + grub_uint32_t unused1; + grub_uint16_t alg; + grub_uint16_t keylen; + grub_uint16_t unused3[7]; + grub_uint8_t keys_used; + grub_uint32_t niter; + grub_uint8_t salt[64]; + struct grub_geli_key keys[2]; +} __attribute__ ((packed)); + +const char *algorithms[] = { + [0x0b] = "aes", +}; + +#define MAX_PASSPHRASE 256 + +static const struct grub_arg_option options[] = + { + {"uuid", 'u', 0, N_("Mount by UUID."), 0, 0}, + {"all", 'a', 0, N_("Mount all."), 0, 0}, + {0, 0, 0, 0, 0, 0} + }; + +static int check_uuid, have_it; +static char *search_uuid; + +static grub_cryptodisk_t +configure_ciphers (const struct grub_geli_phdr *header) +{ + grub_cryptodisk_t newdev; + grub_crypto_cipher_handle_t cipher = NULL; + const struct gcry_cipher_spec *ciph; + const char *ciphername = NULL; + const gcry_md_spec_t *hash = NULL, *iv_hash = NULL; + + /* Look for GELI magic sequence. */ + if (grub_memcmp (header->magic, GELI_MAGIC, sizeof (GELI_MAGIC)) + || grub_le_to_cpu32 (header->version) != 3) + { + grub_dprintf ("geli", "wrong magic %02x\n", header->magic[0]); + return NULL; + } + +#if 0 + optr = uuid; + for (iptr = header->uuid; iptr < &header->uuid[ARRAY_SIZE (header->uuid)]; + iptr++) + { + if (*iptr != '-') + *optr++ = *iptr; + } + *optr = 0; + + if (check_uuid && grub_strcasecmp (search_uuid, uuid) != 0) + { + grub_dprintf ("luks", "%s != %s", uuid, search_uuid); + return NULL; + } +#endif + + if (grub_le_to_cpu16 (header->alg) >= ARRAY_SIZE (algorithms) + || algorithms[grub_le_to_cpu16 (header->alg)] == NULL) + { + grub_error (GRUB_ERR_FILE_NOT_FOUND, "Cipher 0x%x unknown", + grub_le_to_cpu16 (header->alg)); + return NULL; + } + + ciphername = algorithms[grub_le_to_cpu16 (header->alg)]; + ciph = grub_crypto_lookup_cipher_by_name (ciphername); + if (!ciph) + { + grub_error (GRUB_ERR_FILE_NOT_FOUND, "Cipher %s isn't available", + ciphername); + return NULL; + } + + /* Configure the cipher used for the bulk data. */ + cipher = grub_crypto_cipher_open (ciph); + if (!cipher) + return NULL; + + if (grub_le_to_cpu16 (header->keylen) > 1024) + { + grub_error (GRUB_ERR_BAD_ARGUMENT, "invalid keysize %d", + grub_le_to_cpu16 (header->keylen)); + return NULL; + } + + hash = grub_crypto_lookup_md_by_name ("sha512"); + if (!hash) + { + grub_crypto_cipher_close (cipher); + grub_error (GRUB_ERR_FILE_NOT_FOUND, "Couldn't load %s hash", + "sha512"); + return NULL; + } + + iv_hash = grub_crypto_lookup_md_by_name ("sha256"); + if (!hash) + { + grub_crypto_cipher_close (cipher); + grub_error (GRUB_ERR_FILE_NOT_FOUND, "Couldn't load %s hash", + "sha512"); + return NULL; + } + + newdev = grub_zalloc (sizeof (struct grub_cryptodisk)); + if (!newdev) + return NULL; + newdev->cipher = cipher; + newdev->offset = 0; + newdev->source_disk = NULL; + newdev->benbi_log = 0; + newdev->mode = GRUB_CRYPTODISK_MODE_CBC; + newdev->mode_iv = GRUB_CRYPTODISK_MODE_IV_BYTECOUNT64_HASH; + newdev->secondary_cipher = NULL; + newdev->essiv_cipher = NULL; + newdev->essiv_hash = NULL; + newdev->hash = hash; + newdev->iv_hash = iv_hash; +#if 0 + grub_memcpy (newdev->uuid, uuid, sizeof (newdev->uuid)); +#endif + return newdev; +} + +static grub_err_t +recover_key (grub_cryptodisk_t dev, const struct grub_geli_phdr *header, + const char *name, grub_disk_t source __attribute__ ((unused))) +{ + grub_size_t keysize = grub_le_to_cpu16 (header->keylen) / 8; + grub_uint8_t digest[dev->hash->mdlen]; + grub_uint8_t geomkey[dev->hash->mdlen]; + grub_uint8_t verify_key[dev->hash->mdlen]; + grub_uint8_t pbkdf_key[64]; + grub_uint8_t zero[dev->cipher->cipher->blocksize]; + char passphrase[MAX_PASSPHRASE] = ""; + unsigned i; + gcry_err_code_t gcry_err; + + grub_memset (zero, 0, sizeof (zero)); + + grub_printf ("Attempting to decrypt master key...\n"); + + /* Get the passphrase from the user. */ + grub_printf ("Enter passphrase for %s (%s): ", name, dev->uuid); + if (!grub_password_get (passphrase, MAX_PASSPHRASE)) + return grub_error (GRUB_ERR_BAD_ARGUMENT, "Passphrase not supplied"); + + /* Calculate the PBKDF2 of the user supplied passphrase. */ + gcry_err = grub_crypto_pbkdf2 (dev->hash, (grub_uint8_t *) passphrase, + grub_strlen (passphrase), + header->salt, + sizeof (header->salt), + grub_le_to_cpu32 (header->niter), + pbkdf_key, sizeof (pbkdf_key)); + + if (gcry_err) + return grub_crypto_gcry_error (gcry_err); + + gcry_err = grub_crypto_hmac_buffer (dev->hash, NULL, 0, pbkdf_key, + sizeof (pbkdf_key), geomkey); + if (gcry_err) + return grub_crypto_gcry_error (gcry_err); + + gcry_err = grub_crypto_hmac_buffer (dev->hash, geomkey, + sizeof (geomkey), "\1", 1, digest); + if (gcry_err) + return grub_crypto_gcry_error (gcry_err); + + gcry_err = grub_crypto_hmac_buffer (dev->hash, geomkey, + sizeof (geomkey), "\0", 1, verify_key); + if (gcry_err) + return grub_crypto_gcry_error (gcry_err); + + grub_dprintf ("geli", "keylen = %" PRIuGRUB_SIZE "\n", keysize); + + /* Try to recover master key from each active keyslot. */ + for (i = 0; i < ARRAY_SIZE (header->keys); i++) + { + struct grub_geli_key candidate_key; + grub_uint8_t key_hmac[dev->hash->mdlen]; + + /* Check if keyslot is enabled. */ + if (! (header->keys_used & (1 << i))) + continue; + + grub_dprintf ("geli", "Trying keyslot %d\n", i); + + gcry_err = grub_crypto_cipher_set_key (dev->cipher, + digest, keysize); + if (gcry_err) + return grub_crypto_gcry_error (gcry_err); + + gcry_err = grub_crypto_cbc_decrypt (dev->cipher, &candidate_key, + &header->keys[i], + sizeof (candidate_key), + zero); + if (gcry_err) + return grub_crypto_gcry_error (gcry_err); + + gcry_err = grub_crypto_hmac_buffer (dev->hash, verify_key, + sizeof (verify_key), + &candidate_key, + (sizeof (candidate_key) + - sizeof (candidate_key.hmac)), + key_hmac); + if (gcry_err) + return grub_crypto_gcry_error (gcry_err); + + if (grub_memcmp (candidate_key.hmac, key_hmac, dev->hash->mdlen) != 0) + continue; + grub_printf ("Slot %d opened\n", i); + + /* Set the master key. */ + gcry_err = grub_cryptodisk_setkey (dev, candidate_key.cipher_key, + keysize); + if (gcry_err) + return grub_crypto_gcry_error (gcry_err); + + dev->iv_prefix_len = sizeof (candidate_key.iv_key); + grub_memcpy (dev->iv_prefix, candidate_key.iv_key, + sizeof (candidate_key.iv_key)); + + COMPILE_TIME_ASSERT (sizeof (dev->iv_prefix) >= sizeof (candidate_key.iv_key)); + + return GRUB_ERR_NONE; + } + + return GRUB_ACCESS_DENIED; +} + +static void +close (grub_cryptodisk_t luks) +{ + grub_crypto_cipher_close (luks->cipher); + grub_crypto_cipher_close (luks->secondary_cipher); + grub_crypto_cipher_close (luks->essiv_cipher); + grub_free (luks); +} + +static grub_err_t +grub_geli_scan_device_real (const char *name, grub_disk_t source) +{ + grub_err_t err; + struct grub_geli_phdr header; + grub_cryptodisk_t newdev, dev; + grub_disk_addr_t sector; + + grub_dprintf ("geli", "scanning %s\n", source->name); + dev = grub_cryptodisk_get_by_source_disk (source); + + if (dev) + return GRUB_ERR_NONE; + + sector = grub_disk_get_size (source); + if (sector == GRUB_DISK_SIZE_UNKNOWN) + return grub_error (GRUB_ERR_OUT_OF_RANGE, "not a geli"); + + /* Read the LUKS header. */ + err = grub_disk_read (source, sector - 1, 0, sizeof (header), &header); + if (err) + return err; + + newdev = configure_ciphers (&header); + if (!newdev) + return grub_errno; + + newdev->total_length = grub_disk_get_size (source) - 1; + + err = recover_key (newdev, &header, name, source); + if (err) + { + close (newdev); + return err; + } + + grub_cryptodisk_insert (newdev, name, source); + + have_it = 1; + + return GRUB_ERR_NONE; +} + +#ifdef GRUB_UTIL +grub_err_t +grub_geli_cheat_mount (const char *sourcedev, const char *cheat) +{ + grub_err_t err; + struct grub_geli_phdr header; + grub_cryptodisk_t newdev, dev; + grub_disk_t source; + grub_disk_addr_t sector; + + /* Try to open disk. */ + source = grub_disk_open (sourcedev); + if (!source) + return grub_errno; + + dev = grub_cryptodisk_get_by_source_disk (source); + + if (dev) + { + grub_disk_close (source); + return GRUB_ERR_NONE; + } + + sector = grub_disk_get_size (source); + if (sector == GRUB_DISK_SIZE_UNKNOWN) + return grub_error (GRUB_ERR_OUT_OF_RANGE, "not a geli"); + + /* Read the LUKS header. */ + err = grub_disk_read (source, sector - 1, 0, sizeof (header), &header); + if (err) + return err; + + newdev = configure_ciphers (&header); + if (!newdev) + { + grub_disk_close (source); + return grub_errno; + } + + newdev->total_length = grub_disk_get_size (source) - 1; + + err = grub_cryptodisk_cheat_insert (newdev, sourcedev, source, cheat); + grub_disk_close (source); + if (err) + grub_free (newdev); + + return err; +} +#endif + +static int +grub_geli_scan_device (const char *name) +{ + grub_err_t err; + grub_disk_t source; + + /* Try to open disk. */ + source = grub_disk_open (name); + if (!source) + return grub_errno; + + err = grub_geli_scan_device_real (name, source); + + grub_disk_close (source); + + if (err) + grub_print_error (); + return have_it && check_uuid ? 0 : 1; +} + +#ifdef GRUB_UTIL + +void +grub_util_geli_print_uuid (grub_disk_t disk) +{ + grub_cryptodisk_t dev = (grub_cryptodisk_t) disk->data; + grub_printf ("%s ", dev->uuid); +} +#endif + +static grub_err_t +grub_cmd_gelimount (grub_extcmd_context_t ctxt, int argc, char **args) +{ + struct grub_arg_list *state = ctxt->state; + + if (argc < 1 && !state[1].set) + return grub_error (GRUB_ERR_BAD_ARGUMENT, "device name required"); + + have_it = 0; + if (state[0].set) + { + grub_cryptodisk_t dev; + + dev = grub_cryptodisk_get_by_uuid (args[0]); + if (dev) + { + grub_dprintf ("luks", "already mounted as crypto%lu\n", dev->id); + return GRUB_ERR_NONE; + } + + check_uuid = 1; + search_uuid = args[0]; + grub_device_iterate (&grub_geli_scan_device); + search_uuid = NULL; + + if (!have_it) + return grub_error (GRUB_ERR_BAD_ARGUMENT, "no such luks found"); + return GRUB_ERR_NONE; + } + else if (state[1].set) + { + check_uuid = 0; + search_uuid = NULL; + grub_device_iterate (&grub_geli_scan_device); + search_uuid = NULL; + return GRUB_ERR_NONE; + } + else + { + grub_err_t err; + grub_disk_t disk; + grub_cryptodisk_t dev; + + check_uuid = 0; + search_uuid = NULL; + disk = grub_disk_open (args[0]); + if (!disk) + return grub_errno; + + dev = grub_cryptodisk_get_by_source_disk (disk); + if (dev) + { + grub_dprintf ("luks", "already mounted as luks%lu\n", dev->id); + grub_disk_close (disk); + return GRUB_ERR_NONE; + } + + err = grub_geli_scan_device_real (args[0], disk); + + grub_disk_close (disk); + + return err; + } +} + +static grub_extcmd_t cmd; + +GRUB_MOD_INIT (geli) +{ + cmd = grub_register_extcmd ("gelimount", grub_cmd_gelimount, 0, + N_("SOURCE|-u UUID|-a"), + N_("Mount a GELI device."), options); +} + +GRUB_MOD_FINI (geli) +{ + grub_unregister_extcmd (cmd); +} diff --git a/grub-core/disk/luks.c b/grub-core/disk/luks.c index 361beb756..0763da011 100644 --- a/grub-core/disk/luks.c +++ b/grub-core/disk/luks.c @@ -454,6 +454,8 @@ grub_luks_scan_device_real (const char *name, grub_disk_t source) if (!newdev) return grub_errno; + newdev->total_length = grub_disk_get_size (source) - newdev->offset; + err = luks_recover_key (newdev, &header, name, source); if (err) { @@ -502,6 +504,8 @@ grub_luks_cheat_mount (const char *sourcedev, const char *cheat) return grub_errno; } + newdev->total_length = grub_disk_get_size (source) - newdev->offset; + err = grub_cryptodisk_cheat_insert (newdev, sourcedev, source, cheat); grub_disk_close (source); if (err) diff --git a/grub-core/lib/crypto.c b/grub-core/lib/crypto.c index 2f172ebf8..e6f55062b 100644 --- a/grub-core/lib/crypto.c +++ b/grub-core/lib/crypto.c @@ -193,9 +193,10 @@ grub_crypto_xor (void *out, const void *in1, const void *in2, grub_size_t size) gcry_err_code_t grub_crypto_ecb_decrypt (grub_crypto_cipher_handle_t cipher, - void *out, void *in, grub_size_t size) + void *out, const void *in, grub_size_t size) { - grub_uint8_t *inptr, *outptr, *end; + const grub_uint8_t *inptr; + grub_uint8_t *outptr, *end; if (!cipher->cipher->decrypt) return GPG_ERR_NOT_SUPPORTED; if (size % cipher->cipher->blocksize != 0) @@ -249,10 +250,11 @@ grub_crypto_cbc_encrypt (grub_crypto_cipher_handle_t cipher, gcry_err_code_t grub_crypto_cbc_decrypt (grub_crypto_cipher_handle_t cipher, - void *out, void *in, grub_size_t size, + void *out, const void *in, grub_size_t size, void *iv) { - grub_uint8_t *inptr, *outptr, *end; + const grub_uint8_t *inptr; + grub_uint8_t *outptr, *end; grub_uint8_t ivt[cipher->cipher->blocksize]; if (!cipher->cipher->decrypt) return GPG_ERR_NOT_SUPPORTED; diff --git a/include/grub/crypto.h b/include/grub/crypto.h index 62ed2015c..ab82da862 100644 --- a/include/grub/crypto.h +++ b/include/grub/crypto.h @@ -199,7 +199,7 @@ grub_crypto_xor (void *out, const void *in1, const void *in2, grub_size_t size); gcry_err_code_t grub_crypto_ecb_decrypt (grub_crypto_cipher_handle_t cipher, - void *out, void *in, grub_size_t size); + void *out, const void *in, grub_size_t size); gcry_err_code_t grub_crypto_ecb_encrypt (grub_crypto_cipher_handle_t cipher, @@ -210,7 +210,7 @@ grub_crypto_cbc_encrypt (grub_crypto_cipher_handle_t cipher, void *iv_in); gcry_err_code_t grub_crypto_cbc_decrypt (grub_crypto_cipher_handle_t cipher, - void *out, void *in, grub_size_t size, + void *out, const void *in, grub_size_t size, void *iv); void grub_cipher_register (gcry_cipher_spec_t *cipher); diff --git a/include/grub/cryptodisk.h b/include/grub/cryptodisk.h new file mode 100644 index 000000000..284e599f2 --- /dev/null +++ b/include/grub/cryptodisk.h @@ -0,0 +1,99 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2002,2003,2004,2005,2006,2007,2008,2009 Free Software Foundation, Inc. + * + * GRUB is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see . + */ + +#ifndef GRUB_CRYPTODISK_HEADER +#define GRUB_CRYPTODISK_HEADER 1 + +#include +#include + +typedef enum + { + GRUB_CRYPTODISK_MODE_ECB, + GRUB_CRYPTODISK_MODE_CBC, + GRUB_CRYPTODISK_MODE_PCBC, + GRUB_CRYPTODISK_MODE_XTS, + GRUB_CRYPTODISK_MODE_LRW + } grub_cryptodisk_mode_t; + +typedef enum + { + GRUB_CRYPTODISK_MODE_IV_NULL, + GRUB_CRYPTODISK_MODE_IV_PLAIN, + GRUB_CRYPTODISK_MODE_IV_PLAIN64, + GRUB_CRYPTODISK_MODE_IV_ESSIV, + GRUB_CRYPTODISK_MODE_IV_BENBI, + GRUB_CRYPTODISK_MODE_IV_BYTECOUNT64_HASH + } grub_cryptodisk_mode_iv_t; + +#define GRUB_CRYPTODISK_MAX_UUID_LENGTH 63 + +#define GRUB_CRYPTODISK_GF_SIZE 128 +#define GRUB_CRYPTODISK_GF_BYTES (GRUB_CRYPTODISK_GF_SIZE / 8) + +struct grub_cryptodisk +{ + char *source; + grub_disk_addr_t offset; + grub_disk_addr_t total_length; + grub_disk_t source_disk; + int ref; + grub_crypto_cipher_handle_t cipher; + grub_crypto_cipher_handle_t secondary_cipher; + grub_crypto_cipher_handle_t essiv_cipher; + const gcry_md_spec_t *essiv_hash, *hash, *iv_hash; + grub_cryptodisk_mode_t mode; + grub_cryptodisk_mode_iv_t mode_iv; + int benbi_log; + unsigned long id, source_id; + enum grub_disk_dev_id source_dev_id; + char uuid[GRUB_CRYPTODISK_MAX_UUID_LENGTH + 1]; + grub_uint8_t lrw_key[GRUB_CRYPTODISK_GF_BYTES]; + grub_uint8_t *lrw_precalc; + grub_uint8_t iv_prefix[64]; + grub_size_t iv_prefix_len; +#ifdef GRUB_UTIL + char *cheat; + int cheat_fd; +#endif + struct grub_cryptodisk *next; +}; +typedef struct grub_cryptodisk *grub_cryptodisk_t; + +gcry_err_code_t +grub_cryptodisk_setkey (grub_cryptodisk_t dev, + grub_uint8_t *key, grub_size_t keysize); +gcry_err_code_t +grub_cryptodisk_decrypt (const struct grub_cryptodisk *dev, + grub_uint8_t * data, grub_size_t len, + grub_disk_addr_t sector); +grub_err_t +grub_cryptodisk_insert (grub_cryptodisk_t newdev, const char *name, + grub_disk_t source); +#ifdef GRUB_UTIL +grub_err_t +grub_cryptodisk_cheat_insert (grub_cryptodisk_t newdev, const char *name, + grub_disk_t source, const char *cheat); +void +grub_util_cryptodisk_print_abstraction (grub_disk_t disk); +#endif + +grub_cryptodisk_t grub_cryptodisk_get_by_uuid (const char *uuid); +grub_cryptodisk_t grub_cryptodisk_get_by_source_disk (grub_disk_t disk); + +#endif diff --git a/util/grub-fstest.c b/util/grub-fstest.c index 2adb2331d..48a5be1ca 100644 --- a/util/grub-fstest.c +++ b/util/grub-fstest.c @@ -308,8 +308,12 @@ fstest (int n, char **args) { char *argv[2] = { "-a", NULL}; if (mount_crypt) - if (execute_command ("luksmount", 1, argv)) - grub_util_error (_("luksmount command fails: %s"), grub_errmsg); + { + if (execute_command ("luksmount", 1, argv)) + grub_util_error (_("luksmount command fails: %s"), grub_errmsg); + if (execute_command ("gelimount", 1, argv)) + grub_util_error (_("gelimount command fails: %s"), grub_errmsg); + } } grub_lvm_fini (); From b44cd9e710c0bf0c1d1dfceef5ba883a4eebe98f Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 24 Apr 2011 02:34:32 +0200 Subject: [PATCH 510/869] zero-fill hash context for safety --- grub-core/disk/cryptodisk.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/grub-core/disk/cryptodisk.c b/grub-core/disk/cryptodisk.c index 7f3b60bf5..dc6ca486e 100644 --- a/grub-core/disk/cryptodisk.c +++ b/grub-core/disk/cryptodisk.c @@ -200,6 +200,9 @@ grub_cryptodisk_decrypt (const struct grub_cryptodisk *dev, { grub_uint64_t tmp; grub_uint64_t ctx[(dev->iv_hash->contextsize + 7) / 8]; + + grub_memset (ctx, 0, sizeof (ctx)); + tmp = grub_cpu_to_le64 (sector << GRUB_DISK_SECTOR_BITS); dev->iv_hash->init (ctx); dev->iv_hash->write (ctx, dev->iv_prefix, dev->iv_prefix_len); From 7ede8f8b5b62f7244f3cc9e9e6927cac43df006b Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 24 Apr 2011 02:36:04 +0200 Subject: [PATCH 511/869] support niter == 0 --- grub-core/disk/geli.c | 46 ++++++++++++++++++++++++++++++------------- 1 file changed, 32 insertions(+), 14 deletions(-) diff --git a/grub-core/disk/geli.c b/grub-core/disk/geli.c index 6af1de766..565498ece 100644 --- a/grub-core/disk/geli.c +++ b/grub-core/disk/geli.c @@ -205,7 +205,6 @@ recover_key (grub_cryptodisk_t dev, const struct grub_geli_phdr *header, grub_uint8_t digest[dev->hash->mdlen]; grub_uint8_t geomkey[dev->hash->mdlen]; grub_uint8_t verify_key[dev->hash->mdlen]; - grub_uint8_t pbkdf_key[64]; grub_uint8_t zero[dev->cipher->cipher->blocksize]; char passphrase[MAX_PASSPHRASE] = ""; unsigned i; @@ -220,21 +219,40 @@ recover_key (grub_cryptodisk_t dev, const struct grub_geli_phdr *header, if (!grub_password_get (passphrase, MAX_PASSPHRASE)) return grub_error (GRUB_ERR_BAD_ARGUMENT, "Passphrase not supplied"); - /* Calculate the PBKDF2 of the user supplied passphrase. */ - gcry_err = grub_crypto_pbkdf2 (dev->hash, (grub_uint8_t *) passphrase, - grub_strlen (passphrase), - header->salt, - sizeof (header->salt), - grub_le_to_cpu32 (header->niter), - pbkdf_key, sizeof (pbkdf_key)); + /* Calculate the PBKDF2 of the user supplied passphrase. */ + if (grub_le_to_cpu32 (header->niter) != 0) + { + grub_uint8_t pbkdf_key[64]; + gcry_err = grub_crypto_pbkdf2 (dev->hash, (grub_uint8_t *) passphrase, + grub_strlen (passphrase), + header->salt, + sizeof (header->salt), + grub_le_to_cpu32 (header->niter), + pbkdf_key, sizeof (pbkdf_key)); - if (gcry_err) - return grub_crypto_gcry_error (gcry_err); + if (gcry_err) + return grub_crypto_gcry_error (gcry_err); - gcry_err = grub_crypto_hmac_buffer (dev->hash, NULL, 0, pbkdf_key, - sizeof (pbkdf_key), geomkey); - if (gcry_err) - return grub_crypto_gcry_error (gcry_err); + gcry_err = grub_crypto_hmac_buffer (dev->hash, NULL, 0, pbkdf_key, + sizeof (pbkdf_key), geomkey); + if (gcry_err) + return grub_crypto_gcry_error (gcry_err); + } + else + { + struct grub_crypto_hmac_handle *hnd; + + hnd = grub_crypto_hmac_init (dev->hash, NULL, 0); + if (!hnd) + return grub_crypto_gcry_error (GPG_ERR_OUT_OF_MEMORY); + + grub_crypto_hmac_write (hnd, header->salt, sizeof (header->salt)); + grub_crypto_hmac_write (hnd, passphrase, grub_strlen (passphrase)); + + gcry_err = grub_crypto_hmac_fini (hnd, geomkey); + if (gcry_err) + return grub_crypto_gcry_error (gcry_err); + } gcry_err = grub_crypto_hmac_buffer (dev->hash, geomkey, sizeof (geomkey), "\1", 1, digest); From 972d86df5f68efecb9952fa994aa851bae44aa28 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 24 Apr 2011 02:36:50 +0200 Subject: [PATCH 512/869] accept version 2 geli --- grub-core/disk/geli.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/grub-core/disk/geli.c b/grub-core/disk/geli.c index 565498ece..7d0c8621f 100644 --- a/grub-core/disk/geli.c +++ b/grub-core/disk/geli.c @@ -107,7 +107,8 @@ configure_ciphers (const struct grub_geli_phdr *header) /* Look for GELI magic sequence. */ if (grub_memcmp (header->magic, GELI_MAGIC, sizeof (GELI_MAGIC)) - || grub_le_to_cpu32 (header->version) != 3) + || grub_le_to_cpu32 (header->version) > 3 + || grub_le_to_cpu32 (header->version) < 2) { grub_dprintf ("geli", "wrong magic %02x\n", header->magic[0]); return NULL; From b6b4ea5fd1ee71062c05b89bd606d869ebc33517 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 24 Apr 2011 02:37:23 +0200 Subject: [PATCH 513/869] Add IDs for more ciphers --- grub-core/disk/geli.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/grub-core/disk/geli.c b/grub-core/disk/geli.c index 7d0c8621f..843eb7d90 100644 --- a/grub-core/disk/geli.c +++ b/grub-core/disk/geli.c @@ -81,7 +81,14 @@ struct grub_geli_phdr } __attribute__ ((packed)); const char *algorithms[] = { + [0x01] = "des", + [0x02] = "3des", + [0x03] = "blowfish", + [0x04] = "cast5", + /* 0x05 is skipjack, but we don't have it. */ [0x0b] = "aes", + /* 0x10 is null. */ + [0x15] = "camellia128", }; #define MAX_PASSPHRASE 256 From 848c83e75c059b8463788ec1095b84158458c200 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 24 Apr 2011 02:38:42 +0200 Subject: [PATCH 514/869] add few necessarry const qualifiers for pointers --- grub-core/lib/crypto.c | 3 ++- include/grub/crypto.h | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/grub-core/lib/crypto.c b/grub-core/lib/crypto.c index e6f55062b..5098f0a66 100644 --- a/grub-core/lib/crypto.c +++ b/grub-core/lib/crypto.c @@ -345,7 +345,8 @@ grub_crypto_hmac_init (const struct gcry_md_spec *md, } void -grub_crypto_hmac_write (struct grub_crypto_hmac_handle *hnd, void *data, +grub_crypto_hmac_write (struct grub_crypto_hmac_handle *hnd, + const void *data, grub_size_t datalen) { hnd->md->write (hnd->ctx, data, datalen); diff --git a/include/grub/crypto.h b/include/grub/crypto.h index ab82da862..baccbcd06 100644 --- a/include/grub/crypto.h +++ b/include/grub/crypto.h @@ -235,7 +235,8 @@ struct grub_crypto_hmac_handle * grub_crypto_hmac_init (const struct gcry_md_spec *md, const void *key, grub_size_t keylen); void -grub_crypto_hmac_write (struct grub_crypto_hmac_handle *hnd, void *data, +grub_crypto_hmac_write (struct grub_crypto_hmac_handle *hnd, + const void *data, grub_size_t datalen); gcry_err_code_t grub_crypto_hmac_fini (struct grub_crypto_hmac_handle *hnd, void *out); From b094f07c2364b616452639db9184d9411f376f38 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 24 Apr 2011 02:39:21 +0200 Subject: [PATCH 515/869] Don't set was_readable for new array --- grub-core/disk/raid.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/grub-core/disk/raid.c b/grub-core/disk/raid.c index 78453ac88..27a57d7fc 100644 --- a/grub-core/disk/raid.c +++ b/grub-core/disk/raid.c @@ -637,6 +637,7 @@ insert_array (grub_disk_t disk, struct grub_raid_array *new_array, grub_raid_t raid __attribute__ ((unused))) { struct grub_raid_array *array = 0, *p; + int was_readable = 0; /* See whether the device is part of an array we have already seen a device from. */ @@ -647,6 +648,8 @@ insert_array (grub_disk_t disk, struct grub_raid_array *new_array, grub_free (new_array->uuid); array = p; + was_readable = grub_is_array_readable (array); + /* Do some checks before adding the device to the array. */ if (new_array->index >= array->allocated_devs) @@ -803,15 +806,11 @@ insert_array (grub_disk_t disk, struct grub_raid_array *new_array, } /* Add the device to the array. */ - { - int was_readable = grub_is_array_readable (array); - - array->members[new_array->index].device = disk; - array->members[new_array->index].start_sector = start_sector; - array->nr_devs++; - if (!was_readable && grub_is_array_readable (array)) - array->became_readable_at = inscnt++; - } + array->members[new_array->index].device = disk; + array->members[new_array->index].start_sector = start_sector; + array->nr_devs++; + if (!was_readable && grub_is_array_readable (array)) + array->became_readable_at = inscnt++; return 0; } From 0c512b092c885733eb31aa1a12c6e7289c5e5ea1 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 24 Apr 2011 14:52:00 +0200 Subject: [PATCH 516/869] Fix a cache retrieving bug --- grub-core/kern/disk.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/grub-core/kern/disk.c b/grub-core/kern/disk.c index 5439a02f6..30bc604f0 100644 --- a/grub-core/kern/disk.c +++ b/grub-core/kern/disk.c @@ -571,7 +571,8 @@ grub_disk_read (grub_disk_t disk, grub_disk_addr_t sector, if (data) { - grub_memcpy (buf, data, GRUB_DISK_CACHE_SIZE); + grub_memcpy (buf, data, + GRUB_DISK_CACHE_SIZE << GRUB_DISK_SECTOR_BITS); sector += GRUB_DISK_CACHE_SIZE; buf = (char *) buf + (GRUB_DISK_CACHE_SIZE << GRUB_DISK_SECTOR_BITS); size -= (GRUB_DISK_CACHE_SIZE << GRUB_DISK_SECTOR_BITS); From 3e90811d884cab7a333ad9a4458732409be9f88f Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 24 Apr 2011 14:59:38 +0200 Subject: [PATCH 517/869] support non-512B sectors for geli --- grub-core/disk/cryptodisk.c | 50 +++++++++++++++++++++---------------- grub-core/disk/geli.c | 15 ++++++++++- grub-core/disk/luks.c | 1 + include/grub/cryptodisk.h | 7 ++++-- 4 files changed, 49 insertions(+), 24 deletions(-) diff --git a/grub-core/disk/cryptodisk.c b/grub-core/disk/cryptodisk.c index 6dbd6bac6..4a716602e 100644 --- a/grub-core/disk/cryptodisk.c +++ b/grub-core/disk/cryptodisk.c @@ -35,7 +35,10 @@ GRUB_MOD_LICENSE ("GPLv3+"); /* Our irreducible polynom is x^128+x^7+x^2+x+1. Lowest byte of it is: */ #define GF_POLYNOM 0x87 -#define GF_PER_SECTOR (GRUB_DISK_SECTOR_SIZE / GRUB_CRYPTODISK_GF_BYTES) +static inline int GF_PER_SECTOR (const struct grub_cryptodisk *dev) +{ + return 1U << (dev->log_sector_size - GRUB_CRYPTODISK_GF_LOG_BYTES); +} static grub_cryptodisk_t cryptodisk_list = NULL; static grub_uint8_t n = 0; @@ -44,7 +47,7 @@ static void gf_mul_x (grub_uint8_t *g) { int over = 0, over2 = 0; - int j; + unsigned j; for (j = 0; j < GRUB_CRYPTODISK_GF_BYTES; j++) { @@ -64,7 +67,7 @@ gf_mul_x_be (grub_uint8_t *g) int over = 0, over2 = 0; int j; - for (j = GRUB_CRYPTODISK_GF_BYTES - 1; j >= 0; j--) + for (j = (int) GRUB_CRYPTODISK_GF_BYTES - 1; j >= 0; j--) { over2 = !!(g[j] & 0x80); g[j] <<= 1; @@ -78,7 +81,7 @@ gf_mul_x_be (grub_uint8_t *g) static void gf_mul_be (grub_uint8_t *o, const grub_uint8_t *a, const grub_uint8_t *b) { - int i; + unsigned i; grub_uint8_t t[GRUB_CRYPTODISK_GF_BYTES]; grub_memset (o, 0, GRUB_CRYPTODISK_GF_BYTES); grub_memcpy (t, b, GRUB_CRYPTODISK_GF_BYTES); @@ -129,14 +132,15 @@ generate_lrw_sector (struct lrw_sector *sec, grub_uint16_t c; int j; grub_memcpy (idx, iv, GRUB_CRYPTODISK_GF_BYTES); - sec->low_byte = (idx[GRUB_CRYPTODISK_GF_BYTES - 1] & (GF_PER_SECTOR - 1)); - sec->low_byte_c = (((GF_PER_SECTOR - 1) & ~sec->low_byte) + 1); - idx[GRUB_CRYPTODISK_GF_BYTES - 1] &= ~(GF_PER_SECTOR - 1); + sec->low_byte = (idx[GRUB_CRYPTODISK_GF_BYTES - 1] + & (GF_PER_SECTOR (dev) - 1)); + sec->low_byte_c = (((GF_PER_SECTOR (dev) - 1) & ~sec->low_byte) + 1); + idx[GRUB_CRYPTODISK_GF_BYTES - 1] &= ~(GF_PER_SECTOR (dev) - 1); gf_mul_be (sec->low, dev->lrw_key, idx); if (!sec->low_byte) return; - c = idx[GRUB_CRYPTODISK_GF_BYTES - 1] + GF_PER_SECTOR; + c = idx[GRUB_CRYPTODISK_GF_BYTES - 1] + GF_PER_SECTOR (dev); if (c & 0x100) { for (j = GRUB_CRYPTODISK_GF_BYTES - 2; j >= 0; j--) @@ -155,9 +159,10 @@ lrw_xor (const struct lrw_sector *sec, const struct grub_cryptodisk *dev, grub_uint8_t *b) { - int i; + unsigned i; - for (i = 0; i < sec->low_byte_c * GRUB_CRYPTODISK_GF_BYTES; i += GRUB_CRYPTODISK_GF_BYTES) + for (i = 0; i < sec->low_byte_c * GRUB_CRYPTODISK_GF_BYTES; + i += GRUB_CRYPTODISK_GF_BYTES) grub_crypto_xor (b + i, b + i, sec->low, GRUB_CRYPTODISK_GF_BYTES); grub_crypto_xor (b, b, dev->lrw_precalc + GRUB_CRYPTODISK_GF_BYTES * sec->low_byte, sec->low_byte_c * GRUB_CRYPTODISK_GF_BYTES); @@ -165,7 +170,7 @@ lrw_xor (const struct lrw_sector *sec, return; for (i = sec->low_byte_c * GRUB_CRYPTODISK_GF_BYTES; - i < GRUB_DISK_SECTOR_SIZE; i += GRUB_CRYPTODISK_GF_BYTES) + i < (1U << dev->log_sector_size); i += GRUB_CRYPTODISK_GF_BYTES) grub_crypto_xor (b + i, b + i, sec->high, GRUB_CRYPTODISK_GF_BYTES); grub_crypto_xor (b + sec->low_byte_c * GRUB_CRYPTODISK_GF_BYTES, b + sec->low_byte_c * GRUB_CRYPTODISK_GF_BYTES, @@ -184,7 +189,7 @@ grub_cryptodisk_decrypt (const struct grub_cryptodisk *dev, if (dev->mode == GRUB_CRYPTODISK_MODE_ECB) return grub_crypto_ecb_decrypt (dev->cipher, data, data, len); - for (i = 0; i < len; i += GRUB_DISK_SECTOR_SIZE) + for (i = 0; i < len; i += (1U << dev->log_sector_size)) { grub_size_t sz = ((dev->cipher->cipher->blocksize + sizeof (grub_uint32_t) - 1) @@ -203,7 +208,7 @@ grub_cryptodisk_decrypt (const struct grub_cryptodisk *dev, grub_memset (ctx, 0, sizeof (ctx)); - tmp = grub_cpu_to_le64 (sector << GRUB_DISK_SECTOR_BITS); + tmp = grub_cpu_to_le64 (sector << dev->log_sector_size); dev->iv_hash->init (ctx); dev->iv_hash->write (ctx, dev->iv_prefix, dev->iv_prefix_len); dev->iv_hash->write (ctx, &tmp, sizeof (tmp)); @@ -236,26 +241,26 @@ grub_cryptodisk_decrypt (const struct grub_cryptodisk *dev, { case GRUB_CRYPTODISK_MODE_CBC: err = grub_crypto_cbc_decrypt (dev->cipher, data + i, data + i, - GRUB_DISK_SECTOR_SIZE, iv); + (1U << dev->log_sector_size), iv); if (err) return err; break; case GRUB_CRYPTODISK_MODE_PCBC: err = grub_crypto_pcbc_decrypt (dev->cipher, data + i, data + i, - GRUB_DISK_SECTOR_SIZE, iv); + (1U << dev->log_sector_size), iv); if (err) return err; break; case GRUB_CRYPTODISK_MODE_XTS: { - int j; + unsigned j; err = grub_crypto_ecb_encrypt (dev->secondary_cipher, iv, iv, dev->cipher->cipher->blocksize); if (err) return err; - for (j = 0; j < GRUB_DISK_SECTOR_SIZE; + for (j = 0; j < (1U << dev->log_sector_size); j += dev->cipher->cipher->blocksize) { grub_crypto_xor (data + i + j, data + i + j, iv, @@ -279,7 +284,8 @@ grub_cryptodisk_decrypt (const struct grub_cryptodisk *dev, lrw_xor (&sec, dev, data + i); err = grub_crypto_ecb_decrypt (dev->cipher, data + i, - data + i, GRUB_DISK_SECTOR_SIZE); + data + i, + (1U << dev->log_sector_size)); if (err) return err; lrw_xor (&sec, dev, data + i); @@ -333,17 +339,17 @@ grub_cryptodisk_setkey (grub_cryptodisk_t dev, grub_uint8_t *key, grub_size_t ke if (dev->mode == GRUB_CRYPTODISK_MODE_LRW) { - int i; + unsigned i; grub_uint8_t idx[GRUB_CRYPTODISK_GF_BYTES]; grub_free (dev->lrw_precalc); grub_memcpy (dev->lrw_key, key + real_keysize, dev->cipher->cipher->blocksize); - dev->lrw_precalc = grub_malloc (GRUB_DISK_SECTOR_SIZE); + dev->lrw_precalc = grub_malloc ((1U << dev->log_sector_size)); if (!dev->lrw_precalc) return GPG_ERR_OUT_OF_MEMORY; grub_memset (idx, 0, GRUB_CRYPTODISK_GF_BYTES); - for (i = 0; i < GRUB_DISK_SECTOR_SIZE; + for (i = 0; i < (1U << dev->log_sector_size); i += GRUB_CRYPTODISK_GF_BYTES) { idx[GRUB_CRYPTODISK_GF_BYTES - 1] = i / GRUB_CRYPTODISK_GF_BYTES; @@ -401,6 +407,8 @@ grub_cryptodisk_open (const char *name, grub_disk_t disk, if (!dev) return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "No such device"); + disk->log_sector_size = dev->log_sector_size; + #ifdef GRUB_UTIL if (dev->cheat) { diff --git a/grub-core/disk/geli.c b/grub-core/disk/geli.c index 843eb7d90..3c2cbb9ce 100644 --- a/grub-core/disk/geli.c +++ b/grub-core/disk/geli.c @@ -73,7 +73,8 @@ struct grub_geli_phdr grub_uint32_t unused1; grub_uint16_t alg; grub_uint16_t keylen; - grub_uint16_t unused3[7]; + grub_uint16_t unused3[5]; + grub_uint32_t sector_size; grub_uint8_t keys_used; grub_uint32_t niter; grub_uint8_t salt[64]; @@ -120,6 +121,14 @@ configure_ciphers (const struct grub_geli_phdr *header) grub_dprintf ("geli", "wrong magic %02x\n", header->magic[0]); return NULL; } + if ((grub_le_to_cpu32 (header->sector_size) + & (grub_le_to_cpu32 (header->sector_size) - 1)) + || grub_le_to_cpu32 (header->sector_size) == 0) + { + grub_dprintf ("geli", "incorrect sector size %d\n", + grub_le_to_cpu32 (header->sector_size)); + return NULL; + } #if 0 optr = uuid; @@ -199,6 +208,10 @@ configure_ciphers (const struct grub_geli_phdr *header) newdev->essiv_hash = NULL; newdev->hash = hash; newdev->iv_hash = iv_hash; + + for (newdev->log_sector_size = 0; + (1U << newdev->log_sector_size) < grub_le_to_cpu32 (header->sector_size); + newdev->log_sector_size++); #if 0 grub_memcpy (newdev->uuid, uuid, sizeof (newdev->uuid)); #endif diff --git a/grub-core/disk/luks.c b/grub-core/disk/luks.c index 0763da011..7c39002b8 100644 --- a/grub-core/disk/luks.c +++ b/grub-core/disk/luks.c @@ -283,6 +283,7 @@ configure_ciphers (const struct grub_luks_phdr *header) newdev->essiv_cipher = essiv_cipher; newdev->essiv_hash = essiv_hash; newdev->hash = hash; + newdev->log_sector_size = 9; grub_memcpy (newdev->uuid, uuid, sizeof (newdev->uuid)); return newdev; } diff --git a/include/grub/cryptodisk.h b/include/grub/cryptodisk.h index 284e599f2..11181f42d 100644 --- a/include/grub/cryptodisk.h +++ b/include/grub/cryptodisk.h @@ -43,8 +43,10 @@ typedef enum #define GRUB_CRYPTODISK_MAX_UUID_LENGTH 63 -#define GRUB_CRYPTODISK_GF_SIZE 128 -#define GRUB_CRYPTODISK_GF_BYTES (GRUB_CRYPTODISK_GF_SIZE / 8) +#define GRUB_CRYPTODISK_GF_LOG_SIZE 7 +#define GRUB_CRYPTODISK_GF_SIZE (1U << GRUB_CRYPTODISK_GF_LOG_SIZE) +#define GRUB_CRYPTODISK_GF_LOG_BYTES (GRUB_CRYPTODISK_GF_LOG_SIZE - 3) +#define GRUB_CRYPTODISK_GF_BYTES (1U << GRUB_CRYPTODISK_GF_LOG_BYTES) struct grub_cryptodisk { @@ -71,6 +73,7 @@ struct grub_cryptodisk char *cheat; int cheat_fd; #endif + int log_sector_size; struct grub_cryptodisk *next; }; typedef struct grub_cryptodisk *grub_cryptodisk_t; From 88ac3146d6ad5d17788821fa4aa296271a2c0550 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 24 Apr 2011 17:15:55 +0200 Subject: [PATCH 518/869] geli v5 (including rekeying support) --- grub-core/disk/cryptodisk.c | 20 ++++++++++++-- grub-core/disk/geli.c | 53 ++++++++++++++++++++++++++++++++----- grub-core/lib/crypto.c | 2 +- include/grub/crypto.h | 2 +- include/grub/cryptodisk.h | 13 ++++++++- 5 files changed, 79 insertions(+), 11 deletions(-) diff --git a/grub-core/disk/cryptodisk.c b/grub-core/disk/cryptodisk.c index 4a716602e..5ab607146 100644 --- a/grub-core/disk/cryptodisk.c +++ b/grub-core/disk/cryptodisk.c @@ -178,7 +178,7 @@ lrw_xor (const struct lrw_sector *sec, } gcry_err_code_t -grub_cryptodisk_decrypt (const struct grub_cryptodisk *dev, +grub_cryptodisk_decrypt (struct grub_cryptodisk *dev, grub_uint8_t * data, grub_size_t len, grub_disk_addr_t sector) { @@ -186,7 +186,7 @@ grub_cryptodisk_decrypt (const struct grub_cryptodisk *dev, gcry_err_code_t err; /* The only mode without IV. */ - if (dev->mode == GRUB_CRYPTODISK_MODE_ECB) + if (dev->mode == GRUB_CRYPTODISK_MODE_ECB && !dev->rekey) return grub_crypto_ecb_decrypt (dev->cipher, data, data, len); for (i = 0; i < len; i += (1U << dev->log_sector_size)) @@ -196,6 +196,18 @@ grub_cryptodisk_decrypt (const struct grub_cryptodisk *dev, / sizeof (grub_uint32_t)); grub_uint32_t iv[sz]; + if (dev->rekey) + { + grub_uint64_t zone = sector >> dev->rekey_shift; + if (zone != dev->last_rekey) + { + err = dev->rekey (dev, zone); + if (err) + return err; + dev->last_rekey = zone; + } + } + grub_memset (iv, 0, sz * sizeof (iv[0])); switch (dev->mode_iv) { @@ -291,6 +303,10 @@ grub_cryptodisk_decrypt (const struct grub_cryptodisk *dev, lrw_xor (&sec, dev, data + i); } break; + case GRUB_CRYPTODISK_MODE_ECB: + grub_crypto_ecb_decrypt (dev->cipher, data + i, data + i, + (1U << dev->log_sector_size)); + break; default: return GPG_ERR_NOT_IMPLEMENTED; } diff --git a/grub-core/disk/geli.c b/grub-core/disk/geli.c index 3c2cbb9ce..b3fa10cc5 100644 --- a/grub-core/disk/geli.c +++ b/grub-core/disk/geli.c @@ -104,6 +104,28 @@ static const struct grub_arg_option options[] = static int check_uuid, have_it; static char *search_uuid; +static gcry_err_code_t +geli_rekey (struct grub_cryptodisk *dev, grub_uint64_t zoneno) +{ + gcry_err_code_t gcry_err; + const struct { + char magic[4]; + grub_uint64_t zone; + } __attribute__ ((packed)) tohash + = { {'e', 'k', 'e', 'y'}, grub_cpu_to_le64 (zoneno) }; + grub_uint64_t key[(dev->hash->mdlen + 7) / 8]; + + grub_dprintf ("geli", "rekeying %" PRIuGRUB_UINT64_T " keysize=%d\n", + zoneno, dev->rekey_derived_size); + gcry_err = grub_crypto_hmac_buffer (dev->hash, dev->rekey_key, 64, + &tohash, sizeof (tohash), key); + if (gcry_err) + return grub_crypto_gcry_error (gcry_err); + + return grub_cryptodisk_setkey (dev, (grub_uint8_t *) key, + dev->rekey_derived_size); +} + static grub_cryptodisk_t configure_ciphers (const struct grub_geli_phdr *header) { @@ -115,8 +137,8 @@ configure_ciphers (const struct grub_geli_phdr *header) /* Look for GELI magic sequence. */ if (grub_memcmp (header->magic, GELI_MAGIC, sizeof (GELI_MAGIC)) - || grub_le_to_cpu32 (header->version) > 3 - || grub_le_to_cpu32 (header->version) < 2) + || grub_le_to_cpu32 (header->version) > 5 + || grub_le_to_cpu32 (header->version) < 1) { grub_dprintf ("geli", "wrong magic %02x\n", header->magic[0]); return NULL; @@ -212,6 +234,12 @@ configure_ciphers (const struct grub_geli_phdr *header) for (newdev->log_sector_size = 0; (1U << newdev->log_sector_size) < grub_le_to_cpu32 (header->sector_size); newdev->log_sector_size++); + + if (grub_le_to_cpu32 (header->version) >= 5) + { + newdev->rekey = geli_rekey; + newdev->rekey_shift = 20; + } #if 0 grub_memcpy (newdev->uuid, uuid, sizeof (newdev->uuid)); #endif @@ -325,10 +353,23 @@ recover_key (grub_cryptodisk_t dev, const struct grub_geli_phdr *header, grub_printf ("Slot %d opened\n", i); /* Set the master key. */ - gcry_err = grub_cryptodisk_setkey (dev, candidate_key.cipher_key, - keysize); - if (gcry_err) - return grub_crypto_gcry_error (gcry_err); + if (!dev->rekey) + { + gcry_err = grub_cryptodisk_setkey (dev, candidate_key.cipher_key, + keysize); + if (gcry_err) + return grub_crypto_gcry_error (gcry_err); + } + else + { + /* For a reason I don't know, the IV key is used in rekeying. */ + grub_memcpy (dev->rekey_key, candidate_key.iv_key, + sizeof (candidate_key.iv_key)); + dev->rekey_derived_size = keysize; + dev->last_rekey = -1; + COMPILE_TIME_ASSERT (sizeof (dev->rekey_key) + >= sizeof (candidate_key.iv_key)); + } dev->iv_prefix_len = sizeof (candidate_key.iv_key); grub_memcpy (dev->iv_prefix, candidate_key.iv_key, diff --git a/grub-core/lib/crypto.c b/grub-core/lib/crypto.c index 5098f0a66..8876cc326 100644 --- a/grub-core/lib/crypto.c +++ b/grub-core/lib/crypto.c @@ -388,7 +388,7 @@ grub_crypto_hmac_fini (struct grub_crypto_hmac_handle *hnd, void *out) gcry_err_code_t grub_crypto_hmac_buffer (const struct gcry_md_spec *md, const void *key, grub_size_t keylen, - void *data, grub_size_t datalen, void *out) + const void *data, grub_size_t datalen, void *out) { struct grub_crypto_hmac_handle *hnd; diff --git a/include/grub/crypto.h b/include/grub/crypto.h index baccbcd06..10368d99f 100644 --- a/include/grub/crypto.h +++ b/include/grub/crypto.h @@ -244,7 +244,7 @@ grub_crypto_hmac_fini (struct grub_crypto_hmac_handle *hnd, void *out); gcry_err_code_t grub_crypto_hmac_buffer (const struct gcry_md_spec *md, const void *key, grub_size_t keylen, - void *data, grub_size_t datalen, void *out); + const void *data, grub_size_t datalen, void *out); extern gcry_md_spec_t _gcry_digest_spec_md5; extern gcry_md_spec_t _gcry_digest_spec_sha1; diff --git a/include/grub/cryptodisk.h b/include/grub/cryptodisk.h index 11181f42d..2da3f76d2 100644 --- a/include/grub/cryptodisk.h +++ b/include/grub/cryptodisk.h @@ -48,6 +48,12 @@ typedef enum #define GRUB_CRYPTODISK_GF_LOG_BYTES (GRUB_CRYPTODISK_GF_LOG_SIZE - 3) #define GRUB_CRYPTODISK_GF_BYTES (1U << GRUB_CRYPTODISK_GF_LOG_BYTES) +struct grub_cryptodisk; + +typedef gcry_err_code_t +(*grub_cryptodisk_rekey_func_t) (struct grub_cryptodisk *dev, + grub_uint64_t zoneno); + struct grub_cryptodisk { char *source; @@ -74,6 +80,11 @@ struct grub_cryptodisk int cheat_fd; #endif int log_sector_size; + grub_cryptodisk_rekey_func_t rekey; + int rekey_shift; + grub_uint8_t rekey_key[64]; + grub_uint64_t last_rekey; + int rekey_derived_size; struct grub_cryptodisk *next; }; typedef struct grub_cryptodisk *grub_cryptodisk_t; @@ -82,7 +93,7 @@ gcry_err_code_t grub_cryptodisk_setkey (grub_cryptodisk_t dev, grub_uint8_t *key, grub_size_t keysize); gcry_err_code_t -grub_cryptodisk_decrypt (const struct grub_cryptodisk *dev, +grub_cryptodisk_decrypt (struct grub_cryptodisk *dev, grub_uint8_t * data, grub_size_t len, grub_disk_addr_t sector); grub_err_t From 574d268020510d7996c1e263f1fac79aefeaf854 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 24 Apr 2011 17:18:18 +0200 Subject: [PATCH 519/869] Add few FIXME comments --- grub-core/disk/geli.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/grub-core/disk/geli.c b/grub-core/disk/geli.c index b3fa10cc5..6ffc7c26e 100644 --- a/grub-core/disk/geli.c +++ b/grub-core/disk/geli.c @@ -81,14 +81,19 @@ struct grub_geli_phdr struct grub_geli_key keys[2]; } __attribute__ ((packed)); +/* FIXME: support big-endian pre-version-4 volumes. */ +/* FIXME: support for keyfiles. */ +/* FIXME: support for HMAC. */ +/* FIXME: support for UUID. */ +/* FIXME: support for mounting all boot volumes. */ const char *algorithms[] = { [0x01] = "des", [0x02] = "3des", [0x03] = "blowfish", [0x04] = "cast5", - /* 0x05 is skipjack, but we don't have it. */ + /* FIXME: 0x05 is skipjack, but we don't have it. */ [0x0b] = "aes", - /* 0x10 is null. */ + /* FIXME: 0x10 is null. */ [0x15] = "camellia128", }; From 171e2be183b086b1560630f02231ee15771176a7 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 24 Apr 2011 17:41:50 +0200 Subject: [PATCH 520/869] geli xts support --- grub-core/disk/cryptodisk.c | 5 +++++ grub-core/disk/geli.c | 34 ++++++++++++++++++++++++++++------ include/grub/cryptodisk.h | 1 + 3 files changed, 34 insertions(+), 6 deletions(-) diff --git a/grub-core/disk/cryptodisk.c b/grub-core/disk/cryptodisk.c index 5ab607146..bf0b1cde2 100644 --- a/grub-core/disk/cryptodisk.c +++ b/grub-core/disk/cryptodisk.c @@ -234,6 +234,11 @@ grub_cryptodisk_decrypt (struct grub_cryptodisk *dev, case GRUB_CRYPTODISK_MODE_IV_PLAIN: iv[0] = grub_cpu_to_le32 (sector & 0xFFFFFFFF); break; + case GRUB_CRYPTODISK_MODE_IV_BYTECOUNT64: + iv[1] = grub_cpu_to_le32 (sector >> (32 - dev->log_sector_size)); + iv[0] = grub_cpu_to_le32 ((sector << dev->log_sector_size) + & 0xFFFFFFFF); + break; case GRUB_CRYPTODISK_MODE_IV_BENBI: { grub_uint64_t num = (sector << dev->benbi_log) + 1; diff --git a/grub-core/disk/geli.c b/grub-core/disk/geli.c index 6ffc7c26e..334a06340 100644 --- a/grub-core/disk/geli.c +++ b/grub-core/disk/geli.c @@ -95,6 +95,7 @@ const char *algorithms[] = { [0x0b] = "aes", /* FIXME: 0x10 is null. */ [0x15] = "camellia128", + [0x16] = "aes" }; #define MAX_PASSPHRASE 256 @@ -135,7 +136,7 @@ static grub_cryptodisk_t configure_ciphers (const struct grub_geli_phdr *header) { grub_cryptodisk_t newdev; - grub_crypto_cipher_handle_t cipher = NULL; + grub_crypto_cipher_handle_t cipher = NULL, secondary_cipher = NULL; const struct gcry_cipher_spec *ciph; const char *ciphername = NULL; const gcry_md_spec_t *hash = NULL, *iv_hash = NULL; @@ -196,6 +197,13 @@ configure_ciphers (const struct grub_geli_phdr *header) if (!cipher) return NULL; + if (grub_le_to_cpu16 (header->alg) == 0x16) + { + secondary_cipher = grub_crypto_cipher_open (ciph); + if (!secondary_cipher) + return NULL; + } + if (grub_le_to_cpu16 (header->keylen) > 1024) { grub_error (GRUB_ERR_BAD_ARGUMENT, "invalid keysize %d", @@ -225,12 +233,20 @@ configure_ciphers (const struct grub_geli_phdr *header) if (!newdev) return NULL; newdev->cipher = cipher; + newdev->secondary_cipher = secondary_cipher; newdev->offset = 0; newdev->source_disk = NULL; newdev->benbi_log = 0; - newdev->mode = GRUB_CRYPTODISK_MODE_CBC; - newdev->mode_iv = GRUB_CRYPTODISK_MODE_IV_BYTECOUNT64_HASH; - newdev->secondary_cipher = NULL; + if (grub_le_to_cpu16 (header->alg) == 0x16) + { + newdev->mode = GRUB_CRYPTODISK_MODE_XTS; + newdev->mode_iv = GRUB_CRYPTODISK_MODE_IV_BYTECOUNT64; + } + else + { + newdev->mode = GRUB_CRYPTODISK_MODE_CBC; + newdev->mode_iv = GRUB_CRYPTODISK_MODE_IV_BYTECOUNT64_HASH; + } newdev->essiv_cipher = NULL; newdev->essiv_hash = NULL; newdev->hash = hash; @@ -360,17 +376,23 @@ recover_key (grub_cryptodisk_t dev, const struct grub_geli_phdr *header, /* Set the master key. */ if (!dev->rekey) { + grub_size_t real_keysize = keysize; + if (grub_le_to_cpu16 (header->alg) == 0x16) + real_keysize *= 2; gcry_err = grub_cryptodisk_setkey (dev, candidate_key.cipher_key, - keysize); + real_keysize); if (gcry_err) return grub_crypto_gcry_error (gcry_err); } else { + grub_size_t real_keysize = keysize; + if (grub_le_to_cpu16 (header->alg) == 0x16) + real_keysize *= 2; /* For a reason I don't know, the IV key is used in rekeying. */ grub_memcpy (dev->rekey_key, candidate_key.iv_key, sizeof (candidate_key.iv_key)); - dev->rekey_derived_size = keysize; + dev->rekey_derived_size = real_keysize; dev->last_rekey = -1; COMPILE_TIME_ASSERT (sizeof (dev->rekey_key) >= sizeof (candidate_key.iv_key)); diff --git a/include/grub/cryptodisk.h b/include/grub/cryptodisk.h index 2da3f76d2..1911c04be 100644 --- a/include/grub/cryptodisk.h +++ b/include/grub/cryptodisk.h @@ -38,6 +38,7 @@ typedef enum GRUB_CRYPTODISK_MODE_IV_PLAIN64, GRUB_CRYPTODISK_MODE_IV_ESSIV, GRUB_CRYPTODISK_MODE_IV_BENBI, + GRUB_CRYPTODISK_MODE_IV_BYTECOUNT64, GRUB_CRYPTODISK_MODE_IV_BYTECOUNT64_HASH } grub_cryptodisk_mode_iv_t; From 371a8f1183f2696b1a58e410d89ff131cfc830a7 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 24 Apr 2011 17:50:22 +0200 Subject: [PATCH 521/869] Fix a potential buffer overflow --- grub-core/disk/luks.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/grub-core/disk/luks.c b/grub-core/disk/luks.c index 7c39002b8..3f98dfc87 100644 --- a/grub-core/disk/luks.c +++ b/grub-core/disk/luks.c @@ -32,7 +32,6 @@ GRUB_MOD_LICENSE ("GPLv3+"); #define MAX_PASSPHRASE 256 #define LUKS_KEY_ENABLED 0x00AC71F3 -#define LUKS_STRIPES 4000 /* On disk LUKS header */ struct grub_luks_phdr @@ -301,10 +300,16 @@ luks_recover_key (grub_cryptodisk_t dev, const struct grub_luks_phdr *header, unsigned i; grub_size_t length; grub_err_t err; + grub_size_t max_stripes = 1; grub_printf ("Attempting to decrypt master key...\n"); - split_key = grub_malloc (keysize * LUKS_STRIPES); + for (i = 0; i < ARRAY_SIZE (header->keyblock); i++) + if (grub_be_to_cpu32 (header->keyblock[i].active) == LUKS_KEY_ENABLED + && grub_be_to_cpu32 (header->keyblock[i].stripes) > max_stripes) + max_stripes = grub_be_to_cpu32 (header->keyblock[i].stripes); + + split_key = grub_malloc (keysize * max_stripes); if (!split_key) return grub_errno; @@ -351,8 +356,7 @@ luks_recover_key (grub_cryptodisk_t dev, const struct grub_luks_phdr *header, return grub_crypto_gcry_error (gcry_err); } - length = (grub_be_to_cpu32 (header->keyBytes) - * grub_be_to_cpu32 (header->keyblock[i].stripes)); + length = (keysize * grub_be_to_cpu32 (header->keyblock[i].stripes)); /* Read and decrypt the key material from the disk. */ err = grub_disk_read (source, From 7efb5c9eeaad83e8eb2fdcde0fd182828d157610 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 24 Apr 2011 20:37:56 +0200 Subject: [PATCH 522/869] Use hardcoded reference to sha512 and sha256 in geli rather than runtime lookup since they are always used --- Makefile.util.def | 12 ++++++++++++ grub-core/disk/geli.c | 23 ++--------------------- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/Makefile.util.def b/Makefile.util.def index fe9e8c036..51771b9fa 100644 --- a/Makefile.util.def +++ b/Makefile.util.def @@ -108,6 +108,7 @@ program = { common = util/bin2h.c; ldadd = libgrubmods.a; ldadd = libgrubkern.a; + ldadd = libgrubgcry.a; ldadd = grub-core/gnulib/libgnu.a; ldadd = '$(LIBINTL) $(LIBDEVMAPPER)'; mansection = 1; @@ -138,6 +139,7 @@ program = { ldadd = libgrubmods.a; ldadd = libgrubkern.a; + ldadd = libgrubgcry.a; ldadd = grub-core/gnulib/libgnu.a; ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM)'; }; @@ -150,6 +152,7 @@ program = { ldadd = libgrubmods.a; ldadd = libgrubkern.a; + ldadd = libgrubgcry.a; ldadd = grub-core/gnulib/libgnu.a; ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM)'; }; @@ -162,6 +165,7 @@ program = { ldadd = libgrubmods.a; ldadd = libgrubkern.a; + ldadd = libgrubgcry.a; ldadd = grub-core/gnulib/libgnu.a; ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM)'; }; @@ -195,6 +199,7 @@ program = { ldadd = libgrubmods.a; ldadd = libgrubkern.a; + ldadd = libgrubgcry.a; ldadd = grub-core/gnulib/libgnu.a; ldadd = '$(LIBINTL)'; condition = COND_GRUB_PE2ELF; @@ -228,6 +233,7 @@ program = { ldadd = libgrubmods.a; ldadd = libgrubkern.a; + ldadd = libgrubgcry.a; ldadd = grub-core/gnulib/libgnu.a; ldadd = '$(freetype_libs)'; ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM)'; @@ -248,6 +254,7 @@ program = { ldadd = libgrubmods.a; ldadd = libgrubkern.a; + ldadd = libgrubgcry.a; ldadd = grub-core/gnulib/libgnu.a; ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBUTIL) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM)'; }; @@ -277,6 +284,7 @@ program = { ldadd = libgrubmods.a; ldadd = libgrubkern.a; + ldadd = libgrubgcry.a; ldadd = grub-core/gnulib/libgnu.a; ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBUTIL) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM)'; @@ -292,6 +300,7 @@ program = { ldadd = libgrubmods.a; ldadd = libgrubkern.a; + ldadd = libgrubgcry.a; ldadd = grub-core/gnulib/libgnu.a; ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBUTIL) $(LIBGEOM)'; @@ -306,6 +315,7 @@ program = { ldadd = libgrubmods.a; ldadd = libgrubkern.a; + ldadd = libgrubgcry.a; ldadd = grub-core/gnulib/libgnu.a; ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM)'; }; @@ -616,6 +626,7 @@ program = { cflags = -Wno-format; ldadd = libgrubmods.a; ldadd = libgrubkern.a; + ldadd = libgrubgcry.a; ldadd = grub-core/gnulib/libgnu.a; ldadd = '$(LIBDEVMAPPER) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM)'; }; @@ -629,6 +640,7 @@ program = { ldadd = libgrubmods.a; ldadd = libgrubkern.a; + ldadd = libgrubgcry.a; ldadd = grub-core/gnulib/libgnu.a; ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM)'; }; diff --git a/grub-core/disk/geli.c b/grub-core/disk/geli.c index 334a06340..b86e363c7 100644 --- a/grub-core/disk/geli.c +++ b/grub-core/disk/geli.c @@ -139,7 +139,6 @@ configure_ciphers (const struct grub_geli_phdr *header) grub_crypto_cipher_handle_t cipher = NULL, secondary_cipher = NULL; const struct gcry_cipher_spec *ciph; const char *ciphername = NULL; - const gcry_md_spec_t *hash = NULL, *iv_hash = NULL; /* Look for GELI magic sequence. */ if (grub_memcmp (header->magic, GELI_MAGIC, sizeof (GELI_MAGIC)) @@ -211,24 +210,6 @@ configure_ciphers (const struct grub_geli_phdr *header) return NULL; } - hash = grub_crypto_lookup_md_by_name ("sha512"); - if (!hash) - { - grub_crypto_cipher_close (cipher); - grub_error (GRUB_ERR_FILE_NOT_FOUND, "Couldn't load %s hash", - "sha512"); - return NULL; - } - - iv_hash = grub_crypto_lookup_md_by_name ("sha256"); - if (!hash) - { - grub_crypto_cipher_close (cipher); - grub_error (GRUB_ERR_FILE_NOT_FOUND, "Couldn't load %s hash", - "sha512"); - return NULL; - } - newdev = grub_zalloc (sizeof (struct grub_cryptodisk)); if (!newdev) return NULL; @@ -249,8 +230,8 @@ configure_ciphers (const struct grub_geli_phdr *header) } newdev->essiv_cipher = NULL; newdev->essiv_hash = NULL; - newdev->hash = hash; - newdev->iv_hash = iv_hash; + newdev->hash = GRUB_MD_SHA512; + newdev->iv_hash = GRUB_MD_SHA256; for (newdev->log_sector_size = 0; (1U << newdev->log_sector_size) < grub_le_to_cpu32 (header->sector_size); From 23432f6542506794cbcf1d3b75b1e9d3fe284ad4 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 24 Apr 2011 21:11:14 +0200 Subject: [PATCH 523/869] support UUID for geli --- grub-core/disk/geli.c | 41 +++++++++++++++++++++++++++++---------- grub-core/disk/luks.c | 1 + include/grub/cryptodisk.h | 2 +- 3 files changed, 33 insertions(+), 11 deletions(-) diff --git a/grub-core/disk/geli.c b/grub-core/disk/geli.c index b86e363c7..104200546 100644 --- a/grub-core/disk/geli.c +++ b/grub-core/disk/geli.c @@ -84,7 +84,6 @@ struct grub_geli_phdr /* FIXME: support big-endian pre-version-4 volumes. */ /* FIXME: support for keyfiles. */ /* FIXME: support for HMAC. */ -/* FIXME: support for UUID. */ /* FIXME: support for mounting all boot volumes. */ const char *algorithms[] = { [0x01] = "des", @@ -132,6 +131,18 @@ geli_rekey (struct grub_cryptodisk *dev, grub_uint64_t zoneno) dev->rekey_derived_size); } +static inline int +ascii2hex (char c) +{ + if (c >= '0' && c <= '9') + return c - '0'; + if (c >= 'a' && c <= 'f') + return c - 'a' + 10; + if (c >= 'A' && c <= 'F') + return c - 'A' + 10; + return 0; +} + static grub_cryptodisk_t configure_ciphers (const struct grub_geli_phdr *header) { @@ -139,6 +150,11 @@ configure_ciphers (const struct grub_geli_phdr *header) grub_crypto_cipher_handle_t cipher = NULL, secondary_cipher = NULL; const struct gcry_cipher_spec *ciph; const char *ciphername = NULL; + char uuid[GRUB_MD_SHA256->mdlen * 2 + 1]; + grub_uint8_t uuidbin[GRUB_MD_SHA256->mdlen]; + grub_uint8_t *iptr; + char *optr; + gcry_err_code_t gcry_err; /* Look for GELI magic sequence. */ if (grub_memcmp (header->magic, GELI_MAGIC, sizeof (GELI_MAGIC)) @@ -157,13 +173,19 @@ configure_ciphers (const struct grub_geli_phdr *header) return NULL; } -#if 0 - optr = uuid; - for (iptr = header->uuid; iptr < &header->uuid[ARRAY_SIZE (header->uuid)]; - iptr++) + gcry_err = grub_crypto_hmac_buffer (GRUB_MD_SHA256, + header->salt, sizeof (header->salt), + "uuid", sizeof ("uuid") - 1, uuidbin); + if (gcry_err) { - if (*iptr != '-') - *optr++ = *iptr; + grub_crypto_gcry_error (gcry_err); + return NULL; + } + optr = uuid; + for (iptr = uuidbin; iptr < &uuidbin[ARRAY_SIZE (uuidbin)]; iptr++) + { + grub_snprintf (optr, 3, "%02x", *iptr); + optr += 2; } *optr = 0; @@ -172,7 +194,6 @@ configure_ciphers (const struct grub_geli_phdr *header) grub_dprintf ("luks", "%s != %s", uuid, search_uuid); return NULL; } -#endif if (grub_le_to_cpu16 (header->alg) >= ARRAY_SIZE (algorithms) || algorithms[grub_le_to_cpu16 (header->alg)] == NULL) @@ -242,9 +263,9 @@ configure_ciphers (const struct grub_geli_phdr *header) newdev->rekey = geli_rekey; newdev->rekey_shift = 20; } -#if 0 + grub_memcpy (newdev->uuid, uuid, sizeof (newdev->uuid)); -#endif + COMPILE_TIME_ASSERT (sizeof (newdev->uuid) >= 32 * 2 + 1); return newdev; } diff --git a/grub-core/disk/luks.c b/grub-core/disk/luks.c index 3f98dfc87..a94b3cc52 100644 --- a/grub-core/disk/luks.c +++ b/grub-core/disk/luks.c @@ -284,6 +284,7 @@ configure_ciphers (const struct grub_luks_phdr *header) newdev->hash = hash; newdev->log_sector_size = 9; grub_memcpy (newdev->uuid, uuid, sizeof (newdev->uuid)); + COMPILE_TIME_ASSERT (sizeof (newdev->uuid) >= sizeof (uuid)); return newdev; } diff --git a/include/grub/cryptodisk.h b/include/grub/cryptodisk.h index 1911c04be..169fb119d 100644 --- a/include/grub/cryptodisk.h +++ b/include/grub/cryptodisk.h @@ -42,7 +42,7 @@ typedef enum GRUB_CRYPTODISK_MODE_IV_BYTECOUNT64_HASH } grub_cryptodisk_mode_iv_t; -#define GRUB_CRYPTODISK_MAX_UUID_LENGTH 63 +#define GRUB_CRYPTODISK_MAX_UUID_LENGTH 71 #define GRUB_CRYPTODISK_GF_LOG_SIZE 7 #define GRUB_CRYPTODISK_GF_SIZE (1U << GRUB_CRYPTODISK_GF_LOG_SIZE) From 8358d7f22154b26c94d440e5c76e6287dfdf1372 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 24 Apr 2011 21:40:13 +0200 Subject: [PATCH 524/869] Skip one-time volumes and add option for skipping non-boot volumes --- grub-core/disk/geli.c | 36 +++++++++++++++++++++++++++++------- grub-core/disk/luks.c | 2 +- 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/grub-core/disk/geli.c b/grub-core/disk/geli.c index 104200546..8731d3065 100644 --- a/grub-core/disk/geli.c +++ b/grub-core/disk/geli.c @@ -70,7 +70,7 @@ struct grub_geli_phdr grub_uint8_t magic[16]; #define GELI_MAGIC "GEOM::ELI" grub_uint32_t version; - grub_uint32_t unused1; + grub_uint32_t flags; grub_uint16_t alg; grub_uint16_t keylen; grub_uint16_t unused3[5]; @@ -81,6 +81,12 @@ struct grub_geli_phdr struct grub_geli_key keys[2]; } __attribute__ ((packed)); +enum + { + GRUB_GELI_FLAGS_ONETIME = 1, + GRUB_GELI_FLAGS_BOOT = 2, + }; + /* FIXME: support big-endian pre-version-4 volumes. */ /* FIXME: support for keyfiles. */ /* FIXME: support for HMAC. */ @@ -103,10 +109,11 @@ static const struct grub_arg_option options[] = { {"uuid", 'u', 0, N_("Mount by UUID."), 0, 0}, {"all", 'a', 0, N_("Mount all."), 0, 0}, + {"boot", 'b', 0, N_("Mount all volumes marked as boot."), 0, 0}, {0, 0, 0, 0, 0, 0} }; -static int check_uuid, have_it; +static int check_uuid, check_boot, have_it; static char *search_uuid; static gcry_err_code_t @@ -171,7 +178,19 @@ configure_ciphers (const struct grub_geli_phdr *header) grub_dprintf ("geli", "incorrect sector size %d\n", grub_le_to_cpu32 (header->sector_size)); return NULL; - } + } + + if (grub_le_to_cpu32 (header->flags) & GRUB_GELI_FLAGS_ONETIME) + { + grub_dprintf ("geli", "skipping one-time volume\n"); + return NULL; + } + + if (check_boot && !(grub_le_to_cpu32 (header->flags) & GRUB_GELI_FLAGS_BOOT)) + { + grub_dprintf ("geli", "not a boot volume\n"); + return NULL; + } gcry_err = grub_crypto_hmac_buffer (GRUB_MD_SHA256, header->salt, sizeof (header->salt), @@ -191,7 +210,7 @@ configure_ciphers (const struct grub_geli_phdr *header) if (check_uuid && grub_strcasecmp (search_uuid, uuid) != 0) { - grub_dprintf ("luks", "%s != %s", uuid, search_uuid); + grub_dprintf ("geli", "%s != %s\n", uuid, search_uuid); return NULL; } @@ -549,7 +568,7 @@ grub_cmd_gelimount (grub_extcmd_context_t ctxt, int argc, char **args) { struct grub_arg_list *state = ctxt->state; - if (argc < 1 && !state[1].set) + if (argc < 1 && !state[1].set && !state[2].set) return grub_error (GRUB_ERR_BAD_ARGUMENT, "device name required"); have_it = 0; @@ -565,6 +584,7 @@ grub_cmd_gelimount (grub_extcmd_context_t ctxt, int argc, char **args) } check_uuid = 1; + check_boot = state[2].set; search_uuid = args[0]; grub_device_iterate (&grub_geli_scan_device); search_uuid = NULL; @@ -573,10 +593,11 @@ grub_cmd_gelimount (grub_extcmd_context_t ctxt, int argc, char **args) return grub_error (GRUB_ERR_BAD_ARGUMENT, "no such luks found"); return GRUB_ERR_NONE; } - else if (state[1].set) + else if (state[1].set || (argc == 0 && state[2].set)) { check_uuid = 0; search_uuid = NULL; + check_boot = state[2].set; grub_device_iterate (&grub_geli_scan_device); search_uuid = NULL; return GRUB_ERR_NONE; @@ -589,6 +610,7 @@ grub_cmd_gelimount (grub_extcmd_context_t ctxt, int argc, char **args) check_uuid = 0; search_uuid = NULL; + check_boot = state[2].set; disk = grub_disk_open (args[0]); if (!disk) return grub_errno; @@ -614,7 +636,7 @@ static grub_extcmd_t cmd; GRUB_MOD_INIT (geli) { cmd = grub_register_extcmd ("gelimount", grub_cmd_gelimount, 0, - N_("SOURCE|-u UUID|-a"), + N_("SOURCE|-u UUID|-a|-b"), N_("Mount a GELI device."), options); } diff --git a/grub-core/disk/luks.c b/grub-core/disk/luks.c index a94b3cc52..aa23e2e35 100644 --- a/grub-core/disk/luks.c +++ b/grub-core/disk/luks.c @@ -109,7 +109,7 @@ configure_ciphers (const struct grub_luks_phdr *header) if (check_uuid && grub_strcasecmp (search_uuid, uuid) != 0) { - grub_dprintf ("luks", "%s != %s", uuid, search_uuid); + grub_dprintf ("luks", "%s != %s\n", uuid, search_uuid); return NULL; } From f718594e32da770ac412d1a02a2002c81d2302c2 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 24 Apr 2011 21:41:49 +0200 Subject: [PATCH 525/869] update fixme --- grub-core/disk/geli.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/grub-core/disk/geli.c b/grub-core/disk/geli.c index 8731d3065..1353be172 100644 --- a/grub-core/disk/geli.c +++ b/grub-core/disk/geli.c @@ -87,10 +87,10 @@ enum GRUB_GELI_FLAGS_BOOT = 2, }; +/* FIXME: support version 0. */ /* FIXME: support big-endian pre-version-4 volumes. */ /* FIXME: support for keyfiles. */ /* FIXME: support for HMAC. */ -/* FIXME: support for mounting all boot volumes. */ const char *algorithms[] = { [0x01] = "des", [0x02] = "3des", From d7bdab32b8e9e17c0111536b357189f72e6f330d Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 25 Apr 2011 14:46:47 +0200 Subject: [PATCH 526/869] fix linking trouble on FreeBSD --- Makefile.util.def | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/Makefile.util.def b/Makefile.util.def index 51771b9fa..3125b8b30 100644 --- a/Makefile.util.def +++ b/Makefile.util.def @@ -107,8 +107,8 @@ program = { name = grub-bin2h; common = util/bin2h.c; ldadd = libgrubmods.a; - ldadd = libgrubkern.a; ldadd = libgrubgcry.a; + ldadd = libgrubkern.a; ldadd = grub-core/gnulib/libgnu.a; ldadd = '$(LIBINTL) $(LIBDEVMAPPER)'; mansection = 1; @@ -123,8 +123,8 @@ program = { extra_dist = util/grub-mkimagexx.c; ldadd = libgrubmods.a; - ldadd = libgrubkern.a; ldadd = libgrubgcry.a; + ldadd = libgrubkern.a; ldadd = grub-core/gnulib/libgnu.a; ldadd = '$(LIBLZMA)'; ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM)'; @@ -138,8 +138,8 @@ program = { common = util/grub-mkrelpath.c; ldadd = libgrubmods.a; - ldadd = libgrubkern.a; ldadd = libgrubgcry.a; + ldadd = libgrubkern.a; ldadd = grub-core/gnulib/libgnu.a; ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM)'; }; @@ -151,8 +151,8 @@ program = { common = util/grub-script-check.c; ldadd = libgrubmods.a; - ldadd = libgrubkern.a; ldadd = libgrubgcry.a; + ldadd = libgrubkern.a; ldadd = grub-core/gnulib/libgnu.a; ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM)'; }; @@ -164,8 +164,8 @@ program = { common = util/grub-editenv.c; ldadd = libgrubmods.a; - ldadd = libgrubkern.a; ldadd = libgrubgcry.a; + ldadd = libgrubkern.a; ldadd = grub-core/gnulib/libgnu.a; ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM)'; }; @@ -177,8 +177,8 @@ program = { common = util/grub-mkpasswd-pbkdf2.c; ldadd = libgrubmods.a; - ldadd = libgrubkern.a; ldadd = libgrubgcry.a; + ldadd = libgrubkern.a; ldadd = grub-core/gnulib/libgnu.a; ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM)'; cflags = '$(CFLAGS_GCRY)'; @@ -198,8 +198,8 @@ program = { common = util/grub-pe2elf.c; ldadd = libgrubmods.a; - ldadd = libgrubkern.a; ldadd = libgrubgcry.a; + ldadd = libgrubkern.a; ldadd = grub-core/gnulib/libgnu.a; ldadd = '$(LIBINTL)'; condition = COND_GRUB_PE2ELF; @@ -217,8 +217,8 @@ program = { cppflags = '$(CPPFLAGS_GCRY)'; ldadd = libgrubmods.a; - ldadd = libgrubkern.a; ldadd = libgrubgcry.a; + ldadd = libgrubkern.a; ldadd = grub-core/gnulib/libgnu.a; ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM)'; }; @@ -232,8 +232,8 @@ program = { cflags = '$(freetype_cflags)'; ldadd = libgrubmods.a; - ldadd = libgrubkern.a; ldadd = libgrubgcry.a; + ldadd = libgrubkern.a; ldadd = grub-core/gnulib/libgnu.a; ldadd = '$(freetype_libs)'; ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM)'; @@ -253,8 +253,8 @@ program = { sparc64_ieee1275 = util/ieee1275/devicemap.c; ldadd = libgrubmods.a; - ldadd = libgrubkern.a; ldadd = libgrubgcry.a; + ldadd = libgrubkern.a; ldadd = grub-core/gnulib/libgnu.a; ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBUTIL) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM)'; }; @@ -266,8 +266,8 @@ program = { common = util/grub-probe.c; ldadd = libgrubmods.a; - ldadd = libgrubkern.a; ldadd = libgrubgcry.a; + ldadd = libgrubkern.a; ldadd = grub-core/gnulib/libgnu.a; ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBUTIL) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM)'; }; @@ -299,8 +299,8 @@ program = { ieee1275 = util/ieee1275/ofpath.c; ldadd = libgrubmods.a; - ldadd = libgrubkern.a; ldadd = libgrubgcry.a; + ldadd = libgrubkern.a; ldadd = grub-core/gnulib/libgnu.a; ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBUTIL) $(LIBGEOM)'; @@ -314,8 +314,8 @@ program = { common = util/grub-mklayout.c; ldadd = libgrubmods.a; - ldadd = libgrubkern.a; ldadd = libgrubgcry.a; + ldadd = libgrubkern.a; ldadd = grub-core/gnulib/libgnu.a; ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM)'; }; @@ -625,8 +625,8 @@ program = { common = grub-core/tests/lib/test.c; cflags = -Wno-format; ldadd = libgrubmods.a; - ldadd = libgrubkern.a; ldadd = libgrubgcry.a; + ldadd = libgrubkern.a; ldadd = grub-core/gnulib/libgnu.a; ldadd = '$(LIBDEVMAPPER) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM)'; }; @@ -639,8 +639,8 @@ program = { common = grub-core/lib/i386/pc/vesa_modes_table.c; ldadd = libgrubmods.a; - ldadd = libgrubkern.a; ldadd = libgrubgcry.a; + ldadd = libgrubkern.a; ldadd = grub-core/gnulib/libgnu.a; ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM)'; }; From 20a409405b6caf9f51bb391caaac24124c0de3f9 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 25 Apr 2011 14:52:07 +0200 Subject: [PATCH 527/869] Integrate geli into autoconfiguration system --- grub-core/disk/cryptodisk.c | 210 ++++++++++++++- grub-core/disk/geli.c | 464 +++++++++++++--------------------- grub-core/disk/luks.c | 329 ++++++------------------ grub-core/kern/emu/getroot.c | 217 +++++++++++++++- grub-core/kern/emu/hostdisk.c | 204 +++++++-------- include/grub/cryptodisk.h | 35 ++- include/grub/emu/getroot.h | 5 + include/grub/emu/hostdisk.h | 8 +- util/grub-fstest.c | 6 +- util/grub-install.in | 6 +- util/grub-mkconfig.in | 2 +- util/grub-mkconfig_lib.in | 10 +- util/grub-probe.c | 21 +- 13 files changed, 835 insertions(+), 682 deletions(-) diff --git a/grub-core/disk/cryptodisk.c b/grub-core/disk/cryptodisk.c index bf0b1cde2..1a5e8164b 100644 --- a/grub-core/disk/cryptodisk.c +++ b/grub-core/disk/cryptodisk.c @@ -20,6 +20,8 @@ #include #include #include +#include +#include #ifdef GRUB_UTIL #include @@ -33,6 +35,16 @@ GRUB_MOD_LICENSE ("GPLv3+"); +grub_cryptodisk_dev_t grub_cryptodisk_list; + +static const struct grub_arg_option options[] = + { + {"uuid", 'u', 0, N_("Mount by UUID."), 0, 0}, + {"all", 'a', 0, N_("Mount all."), 0, 0}, + {"boot", 'b', 0, N_("Mount all volumes marked as boot."), 0, 0}, + {0, 0, 0, 0, 0, 0} + }; + /* Our irreducible polynom is x^128+x^7+x^2+x+1. Lowest byte of it is: */ #define GF_POLYNOM 0x87 static inline int GF_PER_SECTOR (const struct grub_cryptodisk *dev) @@ -480,7 +492,7 @@ grub_cryptodisk_close (grub_disk_t disk) static grub_err_t grub_cryptodisk_read (grub_disk_t disk, grub_disk_addr_t sector, - grub_size_t size, char *buf) + grub_size_t size, char *buf) { grub_cryptodisk_t dev = (grub_cryptodisk_t) disk->data; grub_err_t err; @@ -635,7 +647,7 @@ grub_util_cryptodisk_print_abstraction (grub_disk_t disk) { grub_cryptodisk_t dev = (grub_cryptodisk_t) disk->data; - grub_printf ("luks "); + grub_printf ("cryptodisk %s ", dev->modname); if (dev->cipher) grub_printf ("%s ", dev->cipher->cipher->modname); @@ -650,8 +662,197 @@ grub_util_cryptodisk_print_abstraction (grub_disk_t disk) if (dev->iv_hash) grub_printf ("%s ", dev->iv_hash->modname); } + +void +grub_util_cryptodisk_print_uuid (grub_disk_t disk) +{ + grub_cryptodisk_t dev = (grub_cryptodisk_t) disk->data; + grub_printf ("%s ", dev->uuid); +} + #endif +static int check_boot, have_it; +static char *search_uuid; + +static void +cryptodisk_close (grub_cryptodisk_t dev) +{ + grub_crypto_cipher_close (dev->cipher); + grub_crypto_cipher_close (dev->secondary_cipher); + grub_crypto_cipher_close (dev->essiv_cipher); + grub_free (dev); +} + +static grub_err_t +grub_cryptodisk_scan_device_real (const char *name, grub_disk_t source) +{ + grub_err_t err; + grub_cryptodisk_t dev; + grub_cryptodisk_dev_t cr; + + dev = grub_cryptodisk_get_by_source_disk (source); + + if (dev) + return GRUB_ERR_NONE; + + FOR_CRYPTODISK_DEVS (cr) + { + dev = cr->scan (source, search_uuid, check_boot); + if (grub_errno) + return grub_errno; + if (!dev) + continue; + + err = cr->recover_key (source, dev); + if (err) + { + cryptodisk_close (dev); + return err; + } + + grub_cryptodisk_insert (dev, name, source); + + have_it = 1; + + return GRUB_ERR_NONE; + } + return GRUB_ERR_NONE; +} + +#ifdef GRUB_UTIL +#include +grub_err_t +grub_cryptodisk_cheat_mount (const char *sourcedev, const char *cheat) +{ + grub_err_t err; + grub_cryptodisk_t dev; + grub_cryptodisk_dev_t cr; + grub_disk_t source; + + /* Try to open disk. */ + source = grub_disk_open (sourcedev); + if (!source) + return grub_errno; + + dev = grub_cryptodisk_get_by_source_disk (source); + + if (dev) + { + grub_disk_close (source); + return GRUB_ERR_NONE; + } + + FOR_CRYPTODISK_DEVS (cr) + { + dev = cr->scan (source, search_uuid, check_boot); + if (grub_errno) + return grub_errno; + if (!dev) + continue; + + grub_util_info ("cheatmounted %s (%s) at %s", sourcedev, dev->modname, + cheat); + err = grub_cryptodisk_cheat_insert (dev, sourcedev, source, cheat); + grub_disk_close (source); + if (err) + grub_free (dev); + + return GRUB_ERR_NONE; + } + + grub_disk_close (source); + + return GRUB_ERR_NONE; +} +#endif + +static int +grub_cryptodisk_scan_device (const char *name) +{ + grub_err_t err; + grub_disk_t source; + + /* Try to open disk. */ + source = grub_disk_open (name); + if (!source) + return grub_errno; + + err = grub_cryptodisk_scan_device_real (name, source); + + grub_disk_close (source); + + if (err) + grub_print_error (); + return have_it && search_uuid ? 1 : 0; +} + +static grub_err_t +grub_cmd_cryptomount (grub_extcmd_context_t ctxt, int argc, char **args) +{ + struct grub_arg_list *state = ctxt->state; + + if (argc < 1 && !state[1].set && !state[2].set) + return grub_error (GRUB_ERR_BAD_ARGUMENT, "device name required"); + + have_it = 0; + if (state[0].set) + { + grub_cryptodisk_t dev; + + dev = grub_cryptodisk_get_by_uuid (args[0]); + if (dev) + { + grub_dprintf ("cryptodisk", + "already mounted as crypto%lu\n", dev->id); + return GRUB_ERR_NONE; + } + + check_boot = state[2].set; + search_uuid = args[0]; + grub_device_iterate (&grub_cryptodisk_scan_device); + search_uuid = NULL; + + if (!have_it) + return grub_error (GRUB_ERR_BAD_ARGUMENT, "no such cryptodisk found"); + return GRUB_ERR_NONE; + } + else if (state[1].set || (argc == 0 && state[2].set)) + { + search_uuid = NULL; + check_boot = state[2].set; + grub_device_iterate (&grub_cryptodisk_scan_device); + search_uuid = NULL; + return GRUB_ERR_NONE; + } + else + { + grub_err_t err; + grub_disk_t disk; + grub_cryptodisk_t dev; + + search_uuid = NULL; + check_boot = state[2].set; + disk = grub_disk_open (args[0]); + if (!disk) + return grub_errno; + + dev = grub_cryptodisk_get_by_source_disk (disk); + if (dev) + { + grub_dprintf ("cryptodisk", "already mounted as crypto%lu\n", dev->id); + grub_disk_close (disk); + return GRUB_ERR_NONE; + } + + err = grub_cryptodisk_scan_device_real (args[0], disk); + + grub_disk_close (disk); + + return err; + } +} + static struct grub_disk_dev grub_cryptodisk_dev = { .name = "cryptodisk", .id = GRUB_DISK_DEVICE_CRYPTODISK_ID, @@ -666,9 +867,14 @@ static struct grub_disk_dev grub_cryptodisk_dev = { .next = 0 }; +static grub_extcmd_t cmd; + GRUB_MOD_INIT (cryptodisk) { grub_disk_dev_register (&grub_cryptodisk_dev); + cmd = grub_register_extcmd ("cryptomount", grub_cmd_cryptomount, 0, + N_("SOURCE|-u UUID|-a|-b"), + N_("Mount a crypto device."), options); } GRUB_MOD_FINI (cryptodisk) diff --git a/grub-core/disk/geli.c b/grub-core/disk/geli.c index 1353be172..d2ae5da56 100644 --- a/grub-core/disk/geli.c +++ b/grub-core/disk/geli.c @@ -53,7 +53,7 @@ #include #include #include -#include +#include #include GRUB_MOD_LICENSE ("GPLv3+"); @@ -105,17 +105,6 @@ const char *algorithms[] = { #define MAX_PASSPHRASE 256 -static const struct grub_arg_option options[] = - { - {"uuid", 'u', 0, N_("Mount by UUID."), 0, 0}, - {"all", 'a', 0, N_("Mount all."), 0, 0}, - {"boot", 'b', 0, N_("Mount all volumes marked as boot."), 0, 0}, - {0, 0, 0, 0, 0, 0} - }; - -static int check_uuid, check_boot, have_it; -static char *search_uuid; - static gcry_err_code_t geli_rekey (struct grub_cryptodisk *dev, grub_uint64_t zoneno) { @@ -150,56 +139,21 @@ ascii2hex (char c) return 0; } -static grub_cryptodisk_t -configure_ciphers (const struct grub_geli_phdr *header) +static inline gcry_err_code_t +make_uuid (const struct grub_geli_phdr *header, + char *uuid) { - grub_cryptodisk_t newdev; - grub_crypto_cipher_handle_t cipher = NULL, secondary_cipher = NULL; - const struct gcry_cipher_spec *ciph; - const char *ciphername = NULL; - char uuid[GRUB_MD_SHA256->mdlen * 2 + 1]; grub_uint8_t uuidbin[GRUB_MD_SHA256->mdlen]; + gcry_err_code_t err; grub_uint8_t *iptr; char *optr; - gcry_err_code_t gcry_err; - /* Look for GELI magic sequence. */ - if (grub_memcmp (header->magic, GELI_MAGIC, sizeof (GELI_MAGIC)) - || grub_le_to_cpu32 (header->version) > 5 - || grub_le_to_cpu32 (header->version) < 1) - { - grub_dprintf ("geli", "wrong magic %02x\n", header->magic[0]); - return NULL; - } - if ((grub_le_to_cpu32 (header->sector_size) - & (grub_le_to_cpu32 (header->sector_size) - 1)) - || grub_le_to_cpu32 (header->sector_size) == 0) - { - grub_dprintf ("geli", "incorrect sector size %d\n", - grub_le_to_cpu32 (header->sector_size)); - return NULL; - } + err = grub_crypto_hmac_buffer (GRUB_MD_SHA256, + header->salt, sizeof (header->salt), + "uuid", sizeof ("uuid") - 1, uuidbin); + if (err) + return err; - if (grub_le_to_cpu32 (header->flags) & GRUB_GELI_FLAGS_ONETIME) - { - grub_dprintf ("geli", "skipping one-time volume\n"); - return NULL; - } - - if (check_boot && !(grub_le_to_cpu32 (header->flags) & GRUB_GELI_FLAGS_BOOT)) - { - grub_dprintf ("geli", "not a boot volume\n"); - return NULL; - } - - gcry_err = grub_crypto_hmac_buffer (GRUB_MD_SHA256, - header->salt, sizeof (header->salt), - "uuid", sizeof ("uuid") - 1, uuidbin); - if (gcry_err) - { - grub_crypto_gcry_error (gcry_err); - return NULL; - } optr = uuid; for (iptr = uuidbin; iptr < &uuidbin[ARRAY_SIZE (uuidbin)]; iptr++) { @@ -207,22 +161,133 @@ configure_ciphers (const struct grub_geli_phdr *header) optr += 2; } *optr = 0; + return GPG_ERR_NO_ERROR; +} - if (check_uuid && grub_strcasecmp (search_uuid, uuid) != 0) +#ifdef GRUB_UTIL + +#include +#include +#include +#include +#include +#include +#include +#include + +char * +grub_util_get_geli_uuid (const char *dev) +{ + int fd = open (dev, O_RDONLY); + grub_uint64_t s; + unsigned log_secsize; + grub_uint8_t hdr[512]; + struct grub_geli_phdr *header; + char *uuid; + gcry_err_code_t err; + + if (fd < 0) + return NULL; + + s = grub_util_get_fd_sectors (fd, &log_secsize); + grub_util_fd_seek (fd, dev, (s << log_secsize) - 512); + + uuid = xmalloc (GRUB_MD_SHA256->mdlen * 2 + 1); + if (grub_util_fd_read (fd, (void *) &hdr, 512) < 0) + grub_util_error ("couldn't read ELI metadata"); + + COMPILE_TIME_ASSERT (sizeof (header) <= 512); + header = (void *) &hdr; + + /* Look for GELI magic sequence. */ + if (grub_memcmp (header->magic, GELI_MAGIC, sizeof (GELI_MAGIC)) + || grub_le_to_cpu32 (header->version) > 5 + || grub_le_to_cpu32 (header->version) < 1) + grub_util_error ("wrong ELI magic or version"); + + err = make_uuid ((void *) &hdr, uuid); + if (err) + return NULL; + + return uuid; +} +#endif + +static grub_cryptodisk_t +configure_ciphers (grub_disk_t disk, const char *check_uuid, + int boot_only) +{ + grub_cryptodisk_t newdev; + struct grub_geli_phdr header; + grub_crypto_cipher_handle_t cipher = NULL, secondary_cipher = NULL; + const struct gcry_cipher_spec *ciph; + const char *ciphername = NULL; + gcry_err_code_t gcry_err; + char uuid[GRUB_MD_SHA256->mdlen * 2 + 1]; + grub_disk_addr_t sector; + grub_err_t err; + + sector = grub_disk_get_size (disk); + if (sector == GRUB_DISK_SIZE_UNKNOWN || sector == 0) + return NULL; + + /* Read the GELI header. */ + err = grub_disk_read (disk, sector - 1, 0, sizeof (header), &header); + if (err) + return NULL; + + /* Look for GELI magic sequence. */ + if (grub_memcmp (header.magic, GELI_MAGIC, sizeof (GELI_MAGIC)) + || grub_le_to_cpu32 (header.version) > 5 + || grub_le_to_cpu32 (header.version) < 1) { - grub_dprintf ("geli", "%s != %s\n", uuid, search_uuid); + grub_dprintf ("geli", "wrong magic %02x\n", header.magic[0]); return NULL; } - if (grub_le_to_cpu16 (header->alg) >= ARRAY_SIZE (algorithms) - || algorithms[grub_le_to_cpu16 (header->alg)] == NULL) + if ((grub_le_to_cpu32 (header.sector_size) + & (grub_le_to_cpu32 (header.sector_size) - 1)) + || grub_le_to_cpu32 (header.sector_size) == 0) + { + grub_dprintf ("geli", "incorrect sector size %d\n", + grub_le_to_cpu32 (header.sector_size)); + return NULL; + } + + if (grub_le_to_cpu32 (header.flags) & GRUB_GELI_FLAGS_ONETIME) + { + grub_dprintf ("geli", "skipping one-time volume\n"); + return NULL; + } + + if (boot_only && !(grub_le_to_cpu32 (header.flags) & GRUB_GELI_FLAGS_BOOT)) + { + grub_dprintf ("geli", "not a boot volume\n"); + return NULL; + } + + gcry_err = make_uuid (&header, uuid); + if (gcry_err) + { + grub_crypto_gcry_error (gcry_err); + return NULL; + } + + if (check_uuid && grub_strcasecmp (check_uuid, uuid) != 0) + { + grub_dprintf ("geli", "%s != %s\n", uuid, check_uuid); + return NULL; + } + + if (grub_le_to_cpu16 (header.alg) >= ARRAY_SIZE (algorithms) + || algorithms[grub_le_to_cpu16 (header.alg)] == NULL) { grub_error (GRUB_ERR_FILE_NOT_FOUND, "Cipher 0x%x unknown", - grub_le_to_cpu16 (header->alg)); + grub_le_to_cpu16 (header.alg)); return NULL; } - ciphername = algorithms[grub_le_to_cpu16 (header->alg)]; + ciphername = algorithms[grub_le_to_cpu16 (header.alg)]; ciph = grub_crypto_lookup_cipher_by_name (ciphername); if (!ciph) { @@ -236,17 +301,17 @@ configure_ciphers (const struct grub_geli_phdr *header) if (!cipher) return NULL; - if (grub_le_to_cpu16 (header->alg) == 0x16) + if (grub_le_to_cpu16 (header.alg) == 0x16) { secondary_cipher = grub_crypto_cipher_open (ciph); if (!secondary_cipher) return NULL; } - if (grub_le_to_cpu16 (header->keylen) > 1024) + if (grub_le_to_cpu16 (header.keylen) > 1024) { grub_error (GRUB_ERR_BAD_ARGUMENT, "invalid keysize %d", - grub_le_to_cpu16 (header->keylen)); + grub_le_to_cpu16 (header.keylen)); return NULL; } @@ -258,7 +323,7 @@ configure_ciphers (const struct grub_geli_phdr *header) newdev->offset = 0; newdev->source_disk = NULL; newdev->benbi_log = 0; - if (grub_le_to_cpu16 (header->alg) == 0x16) + if (grub_le_to_cpu16 (header.alg) == 0x16) { newdev->mode = GRUB_CRYPTODISK_MODE_XTS; newdev->mode_iv = GRUB_CRYPTODISK_MODE_IV_BYTECOUNT64; @@ -274,25 +339,29 @@ configure_ciphers (const struct grub_geli_phdr *header) newdev->iv_hash = GRUB_MD_SHA256; for (newdev->log_sector_size = 0; - (1U << newdev->log_sector_size) < grub_le_to_cpu32 (header->sector_size); + (1U << newdev->log_sector_size) < grub_le_to_cpu32 (header.sector_size); newdev->log_sector_size++); - if (grub_le_to_cpu32 (header->version) >= 5) + if (grub_le_to_cpu32 (header.version) >= 5) { newdev->rekey = geli_rekey; newdev->rekey_shift = 20; } +#ifdef GRUB_UTIL + newdev->modname = "geli"; +#endif + + newdev->total_length = grub_disk_get_size (disk) - 1; grub_memcpy (newdev->uuid, uuid, sizeof (newdev->uuid)); COMPILE_TIME_ASSERT (sizeof (newdev->uuid) >= 32 * 2 + 1); return newdev; } static grub_err_t -recover_key (grub_cryptodisk_t dev, const struct grub_geli_phdr *header, - const char *name, grub_disk_t source __attribute__ ((unused))) +recover_key (grub_disk_t source, grub_cryptodisk_t dev) { - grub_size_t keysize = grub_le_to_cpu16 (header->keylen) / 8; + grub_size_t keysize; grub_uint8_t digest[dev->hash->mdlen]; grub_uint8_t geomkey[dev->hash->mdlen]; grub_uint8_t verify_key[dev->hash->mdlen]; @@ -300,25 +369,45 @@ recover_key (grub_cryptodisk_t dev, const struct grub_geli_phdr *header, char passphrase[MAX_PASSPHRASE] = ""; unsigned i; gcry_err_code_t gcry_err; + struct grub_geli_phdr header; + char *tmp; + grub_disk_addr_t sector; + grub_err_t err; + sector = grub_disk_get_size (source); + if (sector == GRUB_DISK_SIZE_UNKNOWN || sector == 0) + return grub_error (GRUB_ERR_OUT_OF_RANGE, "not a geli"); + + /* Read the GELI header. */ + err = grub_disk_read (source, sector - 1, 0, sizeof (header), &header); + if (err) + return err; + + keysize = grub_le_to_cpu16 (header.keylen) / 8; grub_memset (zero, 0, sizeof (zero)); grub_printf ("Attempting to decrypt master key...\n"); /* Get the passphrase from the user. */ - grub_printf ("Enter passphrase for %s (%s): ", name, dev->uuid); + tmp = NULL; + if (source->partition) + tmp = grub_partition_get_name (source->partition); + grub_printf ("Enter passphrase for %s%s%s (%s): ", source->name, + source->partition ? "," : "", tmp ? : "", + dev->uuid); + grub_free (tmp); if (!grub_password_get (passphrase, MAX_PASSPHRASE)) return grub_error (GRUB_ERR_BAD_ARGUMENT, "Passphrase not supplied"); /* Calculate the PBKDF2 of the user supplied passphrase. */ - if (grub_le_to_cpu32 (header->niter) != 0) + if (grub_le_to_cpu32 (header.niter) != 0) { grub_uint8_t pbkdf_key[64]; gcry_err = grub_crypto_pbkdf2 (dev->hash, (grub_uint8_t *) passphrase, grub_strlen (passphrase), - header->salt, - sizeof (header->salt), - grub_le_to_cpu32 (header->niter), + header.salt, + sizeof (header.salt), + grub_le_to_cpu32 (header.niter), pbkdf_key, sizeof (pbkdf_key)); if (gcry_err) @@ -337,7 +426,7 @@ recover_key (grub_cryptodisk_t dev, const struct grub_geli_phdr *header, if (!hnd) return grub_crypto_gcry_error (GPG_ERR_OUT_OF_MEMORY); - grub_crypto_hmac_write (hnd, header->salt, sizeof (header->salt)); + grub_crypto_hmac_write (hnd, header.salt, sizeof (header.salt)); grub_crypto_hmac_write (hnd, passphrase, grub_strlen (passphrase)); gcry_err = grub_crypto_hmac_fini (hnd, geomkey); @@ -358,13 +447,13 @@ recover_key (grub_cryptodisk_t dev, const struct grub_geli_phdr *header, grub_dprintf ("geli", "keylen = %" PRIuGRUB_SIZE "\n", keysize); /* Try to recover master key from each active keyslot. */ - for (i = 0; i < ARRAY_SIZE (header->keys); i++) + for (i = 0; i < ARRAY_SIZE (header.keys); i++) { struct grub_geli_key candidate_key; grub_uint8_t key_hmac[dev->hash->mdlen]; /* Check if keyslot is enabled. */ - if (! (header->keys_used & (1 << i))) + if (! (header.keys_used & (1 << i))) continue; grub_dprintf ("geli", "Trying keyslot %d\n", i); @@ -375,7 +464,7 @@ recover_key (grub_cryptodisk_t dev, const struct grub_geli_phdr *header, return grub_crypto_gcry_error (gcry_err); gcry_err = grub_crypto_cbc_decrypt (dev->cipher, &candidate_key, - &header->keys[i], + &header.keys[i], sizeof (candidate_key), zero); if (gcry_err) @@ -398,7 +487,7 @@ recover_key (grub_cryptodisk_t dev, const struct grub_geli_phdr *header, if (!dev->rekey) { grub_size_t real_keysize = keysize; - if (grub_le_to_cpu16 (header->alg) == 0x16) + if (grub_le_to_cpu16 (header.alg) == 0x16) real_keysize *= 2; gcry_err = grub_cryptodisk_setkey (dev, candidate_key.cipher_key, real_keysize); @@ -408,7 +497,7 @@ recover_key (grub_cryptodisk_t dev, const struct grub_geli_phdr *header, else { grub_size_t real_keysize = keysize; - if (grub_le_to_cpu16 (header->alg) == 0x16) + if (grub_le_to_cpu16 (header.alg) == 0x16) real_keysize *= 2; /* For a reason I don't know, the IV key is used in rekeying. */ grub_memcpy (dev->rekey_key, candidate_key.iv_key, @@ -431,216 +520,17 @@ recover_key (grub_cryptodisk_t dev, const struct grub_geli_phdr *header, return GRUB_ACCESS_DENIED; } -static void -close (grub_cryptodisk_t luks) -{ - grub_crypto_cipher_close (luks->cipher); - grub_crypto_cipher_close (luks->secondary_cipher); - grub_crypto_cipher_close (luks->essiv_cipher); - grub_free (luks); -} - -static grub_err_t -grub_geli_scan_device_real (const char *name, grub_disk_t source) -{ - grub_err_t err; - struct grub_geli_phdr header; - grub_cryptodisk_t newdev, dev; - grub_disk_addr_t sector; - - grub_dprintf ("geli", "scanning %s\n", source->name); - dev = grub_cryptodisk_get_by_source_disk (source); - - if (dev) - return GRUB_ERR_NONE; - - sector = grub_disk_get_size (source); - if (sector == GRUB_DISK_SIZE_UNKNOWN) - return grub_error (GRUB_ERR_OUT_OF_RANGE, "not a geli"); - - /* Read the LUKS header. */ - err = grub_disk_read (source, sector - 1, 0, sizeof (header), &header); - if (err) - return err; - - newdev = configure_ciphers (&header); - if (!newdev) - return grub_errno; - - newdev->total_length = grub_disk_get_size (source) - 1; - - err = recover_key (newdev, &header, name, source); - if (err) - { - close (newdev); - return err; - } - - grub_cryptodisk_insert (newdev, name, source); - - have_it = 1; - - return GRUB_ERR_NONE; -} - -#ifdef GRUB_UTIL -grub_err_t -grub_geli_cheat_mount (const char *sourcedev, const char *cheat) -{ - grub_err_t err; - struct grub_geli_phdr header; - grub_cryptodisk_t newdev, dev; - grub_disk_t source; - grub_disk_addr_t sector; - - /* Try to open disk. */ - source = grub_disk_open (sourcedev); - if (!source) - return grub_errno; - - dev = grub_cryptodisk_get_by_source_disk (source); - - if (dev) - { - grub_disk_close (source); - return GRUB_ERR_NONE; - } - - sector = grub_disk_get_size (source); - if (sector == GRUB_DISK_SIZE_UNKNOWN) - return grub_error (GRUB_ERR_OUT_OF_RANGE, "not a geli"); - - /* Read the LUKS header. */ - err = grub_disk_read (source, sector - 1, 0, sizeof (header), &header); - if (err) - return err; - - newdev = configure_ciphers (&header); - if (!newdev) - { - grub_disk_close (source); - return grub_errno; - } - - newdev->total_length = grub_disk_get_size (source) - 1; - - err = grub_cryptodisk_cheat_insert (newdev, sourcedev, source, cheat); - grub_disk_close (source); - if (err) - grub_free (newdev); - - return err; -} -#endif - -static int -grub_geli_scan_device (const char *name) -{ - grub_err_t err; - grub_disk_t source; - - /* Try to open disk. */ - source = grub_disk_open (name); - if (!source) - return grub_errno; - - err = grub_geli_scan_device_real (name, source); - - grub_disk_close (source); - - if (err) - grub_print_error (); - return have_it && check_uuid ? 0 : 1; -} - -#ifdef GRUB_UTIL - -void -grub_util_geli_print_uuid (grub_disk_t disk) -{ - grub_cryptodisk_t dev = (grub_cryptodisk_t) disk->data; - grub_printf ("%s ", dev->uuid); -} -#endif - -static grub_err_t -grub_cmd_gelimount (grub_extcmd_context_t ctxt, int argc, char **args) -{ - struct grub_arg_list *state = ctxt->state; - - if (argc < 1 && !state[1].set && !state[2].set) - return grub_error (GRUB_ERR_BAD_ARGUMENT, "device name required"); - - have_it = 0; - if (state[0].set) - { - grub_cryptodisk_t dev; - - dev = grub_cryptodisk_get_by_uuid (args[0]); - if (dev) - { - grub_dprintf ("luks", "already mounted as crypto%lu\n", dev->id); - return GRUB_ERR_NONE; - } - - check_uuid = 1; - check_boot = state[2].set; - search_uuid = args[0]; - grub_device_iterate (&grub_geli_scan_device); - search_uuid = NULL; - - if (!have_it) - return grub_error (GRUB_ERR_BAD_ARGUMENT, "no such luks found"); - return GRUB_ERR_NONE; - } - else if (state[1].set || (argc == 0 && state[2].set)) - { - check_uuid = 0; - search_uuid = NULL; - check_boot = state[2].set; - grub_device_iterate (&grub_geli_scan_device); - search_uuid = NULL; - return GRUB_ERR_NONE; - } - else - { - grub_err_t err; - grub_disk_t disk; - grub_cryptodisk_t dev; - - check_uuid = 0; - search_uuid = NULL; - check_boot = state[2].set; - disk = grub_disk_open (args[0]); - if (!disk) - return grub_errno; - - dev = grub_cryptodisk_get_by_source_disk (disk); - if (dev) - { - grub_dprintf ("luks", "already mounted as luks%lu\n", dev->id); - grub_disk_close (disk); - return GRUB_ERR_NONE; - } - - err = grub_geli_scan_device_real (args[0], disk); - - grub_disk_close (disk); - - return err; - } -} - -static grub_extcmd_t cmd; +struct grub_cryptodisk_dev geli_crypto = { + .scan = configure_ciphers, + .recover_key = recover_key +}; GRUB_MOD_INIT (geli) { - cmd = grub_register_extcmd ("gelimount", grub_cmd_gelimount, 0, - N_("SOURCE|-u UUID|-a|-b"), - N_("Mount a GELI device."), options); + grub_cryptodisk_dev_register (&geli_crypto); } GRUB_MOD_FINI (geli) { - grub_unregister_extcmd (cmd); + grub_cryptodisk_dev_unregister (&geli_crypto); } diff --git a/grub-core/disk/luks.c b/grub-core/disk/luks.c index aa23e2e35..0ec95fccd 100644 --- a/grub-core/disk/luks.c +++ b/grub-core/disk/luks.c @@ -24,7 +24,7 @@ #include #include #include -#include +#include #include GRUB_MOD_LICENSE ("GPLv3+"); @@ -64,27 +64,19 @@ gcry_err_code_t AF_merge (const gcry_md_spec_t * hash, grub_uint8_t * src, grub_uint8_t * dst, grub_size_t blocksize, grub_size_t blocknumbers); -static const struct grub_arg_option options[] = - { - {"uuid", 'u', 0, N_("Mount by UUID."), 0, 0}, - {"all", 'a', 0, N_("Mount all."), 0, 0}, - {0, 0, 0, 0, 0, 0} - }; - -static int check_uuid, have_it; -static char *search_uuid; - static grub_cryptodisk_t -configure_ciphers (const struct grub_luks_phdr *header) +configure_ciphers (grub_disk_t disk, const char *check_uuid, + int check_boot) { grub_cryptodisk_t newdev; const char *iptr; + struct grub_luks_phdr header; char *optr; - char uuid[sizeof (header->uuid) + 1]; - char ciphername[sizeof (header->cipherName) + 1]; - char ciphermode[sizeof (header->cipherMode) + 1]; + char uuid[sizeof (header.uuid) + 1]; + char ciphername[sizeof (header.cipherName) + 1]; + char ciphermode[sizeof (header.cipherMode) + 1]; char *cipheriv = NULL; - char hashspec[sizeof (header->hashSpec) + 1]; + char hashspec[sizeof (header.hashSpec) + 1]; grub_crypto_cipher_handle_t cipher = NULL, secondary_cipher = NULL; grub_crypto_cipher_handle_t essiv_cipher = NULL; const gcry_md_spec_t *hash = NULL, *essiv_hash = NULL; @@ -92,14 +84,27 @@ configure_ciphers (const struct grub_luks_phdr *header) grub_cryptodisk_mode_t mode; grub_cryptodisk_mode_iv_t mode_iv; int benbi_log = 0; + grub_err_t err; + + if (check_boot) + return NULL; + + /* Read the LUKS header. */ + err = grub_disk_read (disk, 0, 0, sizeof (header), &header); + if (err) + { + if (err == GRUB_ERR_OUT_OF_RANGE) + grub_errno = GRUB_ERR_NONE; + return NULL; + } /* Look for LUKS magic sequence. */ - if (grub_memcmp (header->magic, LUKS_MAGIC, sizeof (header->magic)) - || grub_be_to_cpu16 (header->version) != 1) + if (grub_memcmp (header.magic, LUKS_MAGIC, sizeof (header.magic)) + || grub_be_to_cpu16 (header.version) != 1) return NULL; optr = uuid; - for (iptr = header->uuid; iptr < &header->uuid[ARRAY_SIZE (header->uuid)]; + for (iptr = header.uuid; iptr < &header.uuid[ARRAY_SIZE (header.uuid)]; iptr++) { if (*iptr != '-') @@ -107,19 +112,19 @@ configure_ciphers (const struct grub_luks_phdr *header) } *optr = 0; - if (check_uuid && grub_strcasecmp (search_uuid, uuid) != 0) + if (check_uuid && grub_strcasecmp (check_uuid, uuid) != 0) { - grub_dprintf ("luks", "%s != %s\n", uuid, search_uuid); + grub_dprintf ("luks", "%s != %s\n", uuid, check_uuid); return NULL; } /* Make sure that strings are null terminated. */ - grub_memcpy (ciphername, header->cipherName, sizeof (header->cipherName)); - ciphername[sizeof (header->cipherName)] = 0; - grub_memcpy (ciphermode, header->cipherMode, sizeof (header->cipherMode)); - ciphermode[sizeof (header->cipherMode)] = 0; - grub_memcpy (hashspec, header->hashSpec, sizeof (header->hashSpec)); - hashspec[sizeof (header->hashSpec)] = 0; + grub_memcpy (ciphername, header.cipherName, sizeof (header.cipherName)); + ciphername[sizeof (header.cipherName)] = 0; + grub_memcpy (ciphermode, header.cipherMode, sizeof (header.cipherMode)); + ciphermode[sizeof (header.cipherMode)] = 0; + grub_memcpy (hashspec, header.hashSpec, sizeof (header.hashSpec)); + hashspec[sizeof (header.hashSpec)] = 0; ciph = grub_crypto_lookup_cipher_by_name (ciphername); if (!ciph) @@ -134,10 +139,10 @@ configure_ciphers (const struct grub_luks_phdr *header) if (!cipher) return NULL; - if (grub_be_to_cpu32 (header->keyBytes) > 1024) + if (grub_be_to_cpu32 (header.keyBytes) > 1024) { grub_error (GRUB_ERR_BAD_ARGUMENT, "invalid keysize %d", - grub_be_to_cpu32 (header->keyBytes)); + grub_be_to_cpu32 (header.keyBytes)); return NULL; } @@ -273,7 +278,7 @@ configure_ciphers (const struct grub_luks_phdr *header) if (!newdev) return NULL; newdev->cipher = cipher; - newdev->offset = grub_be_to_cpu32 (header->payloadOffset); + newdev->offset = grub_be_to_cpu32 (header.payloadOffset); newdev->source_disk = NULL; newdev->benbi_log = benbi_log; newdev->mode = mode; @@ -283,39 +288,54 @@ configure_ciphers (const struct grub_luks_phdr *header) newdev->essiv_hash = essiv_hash; newdev->hash = hash; newdev->log_sector_size = 9; + newdev->total_length = grub_disk_get_size (disk) - newdev->offset; grub_memcpy (newdev->uuid, uuid, sizeof (newdev->uuid)); +#ifdef GRUB_UTIL + newdev->modname = "luks"; +#endif COMPILE_TIME_ASSERT (sizeof (newdev->uuid) >= sizeof (uuid)); return newdev; } static grub_err_t -luks_recover_key (grub_cryptodisk_t dev, const struct grub_luks_phdr *header, - const char *name, grub_disk_t source) +luks_recover_key (grub_disk_t source, + grub_cryptodisk_t dev) { - grub_size_t keysize = grub_be_to_cpu32 (header->keyBytes); - grub_uint8_t candidate_key[keysize]; - grub_uint8_t digest[keysize]; + struct grub_luks_phdr header; + grub_size_t keysize; grub_uint8_t *split_key = NULL; char passphrase[MAX_PASSPHRASE] = ""; - grub_uint8_t candidate_digest[sizeof (header->mkDigest)]; + grub_uint8_t candidate_digest[sizeof (header.mkDigest)]; unsigned i; grub_size_t length; grub_err_t err; grub_size_t max_stripes = 1; + char *tmp; + + err = grub_disk_read (source, 0, 0, sizeof (header), &header); + if (err) + return err; grub_printf ("Attempting to decrypt master key...\n"); + keysize = grub_be_to_cpu32 (header.keyBytes); - for (i = 0; i < ARRAY_SIZE (header->keyblock); i++) - if (grub_be_to_cpu32 (header->keyblock[i].active) == LUKS_KEY_ENABLED - && grub_be_to_cpu32 (header->keyblock[i].stripes) > max_stripes) - max_stripes = grub_be_to_cpu32 (header->keyblock[i].stripes); + for (i = 0; i < ARRAY_SIZE (header.keyblock); i++) + if (grub_be_to_cpu32 (header.keyblock[i].active) == LUKS_KEY_ENABLED + && grub_be_to_cpu32 (header.keyblock[i].stripes) > max_stripes) + max_stripes = grub_be_to_cpu32 (header.keyblock[i].stripes); split_key = grub_malloc (keysize * max_stripes); if (!split_key) return grub_errno; /* Get the passphrase from the user. */ - grub_printf ("Enter passphrase for %s (%s): ", name, dev->uuid); + tmp = NULL; + if (source->partition) + tmp = grub_partition_get_name (source->partition); + grub_printf ("Enter passphrase for %s%s%s (%s): ", source->name, + source->partition ? "," : "", tmp ? : "", + dev->uuid); + grub_free (tmp); if (!grub_password_get (passphrase, MAX_PASSPHRASE)) { grub_free (split_key); @@ -323,12 +343,14 @@ luks_recover_key (grub_cryptodisk_t dev, const struct grub_luks_phdr *header, } /* Try to recover master key from each active keyslot. */ - for (i = 0; i < ARRAY_SIZE (header->keyblock); i++) + for (i = 0; i < ARRAY_SIZE (header.keyblock); i++) { gcry_err_code_t gcry_err; + grub_uint8_t candidate_key[keysize]; + grub_uint8_t digest[keysize]; /* Check if keyslot is enabled. */ - if (grub_be_to_cpu32 (header->keyblock[i].active) != LUKS_KEY_ENABLED) + if (grub_be_to_cpu32 (header.keyblock[i].active) != LUKS_KEY_ENABLED) continue; grub_dprintf ("luks", "Trying keyslot %d\n", i); @@ -336,9 +358,9 @@ luks_recover_key (grub_cryptodisk_t dev, const struct grub_luks_phdr *header, /* Calculate the PBKDF2 of the user supplied passphrase. */ gcry_err = grub_crypto_pbkdf2 (dev->hash, (grub_uint8_t *) passphrase, grub_strlen (passphrase), - header->keyblock[i].passwordSalt, - sizeof (header->keyblock[i].passwordSalt), - grub_be_to_cpu32 (header->keyblock[i]. + header.keyblock[i].passwordSalt, + sizeof (header.keyblock[i].passwordSalt), + grub_be_to_cpu32 (header.keyblock[i]. passwordIterations), digest, keysize); @@ -357,11 +379,11 @@ luks_recover_key (grub_cryptodisk_t dev, const struct grub_luks_phdr *header, return grub_crypto_gcry_error (gcry_err); } - length = (keysize * grub_be_to_cpu32 (header->keyblock[i].stripes)); + length = (keysize * grub_be_to_cpu32 (header.keyblock[i].stripes)); /* Read and decrypt the key material from the disk. */ err = grub_disk_read (source, - grub_be_to_cpu32 (header->keyblock + grub_be_to_cpu32 (header.keyblock [i].keyMaterialOffset), 0, length, split_key); if (err) @@ -379,7 +401,7 @@ luks_recover_key (grub_cryptodisk_t dev, const struct grub_luks_phdr *header, /* Merge the decrypted key material to get the candidate master key. */ gcry_err = AF_merge (dev->hash, split_key, candidate_key, keysize, - grub_be_to_cpu32 (header->keyblock[i].stripes)); + grub_be_to_cpu32 (header.keyblock[i].stripes)); if (gcry_err) { grub_free (split_key); @@ -390,11 +412,11 @@ luks_recover_key (grub_cryptodisk_t dev, const struct grub_luks_phdr *header, /* Calculate the PBKDF2 of the candidate master key. */ gcry_err = grub_crypto_pbkdf2 (dev->hash, candidate_key, - grub_be_to_cpu32 (header->keyBytes), - header->mkDigestSalt, - sizeof (header->mkDigestSalt), + grub_be_to_cpu32 (header.keyBytes), + header.mkDigestSalt, + sizeof (header.mkDigestSalt), grub_be_to_cpu32 - (header->mkDigestIterations), + (header.mkDigestIterations), candidate_digest, sizeof (candidate_digest)); if (gcry_err) @@ -405,8 +427,8 @@ luks_recover_key (grub_cryptodisk_t dev, const struct grub_luks_phdr *header, /* Compare the calculated PBKDF2 to the digest stored in the header to see if it's correct. */ - if (grub_memcmp (candidate_digest, header->mkDigest, - sizeof (header->mkDigest)) != 0) + if (grub_memcmp (candidate_digest, header.mkDigest, + sizeof (header.mkDigest)) != 0) { grub_dprintf ("luks", "bad digest\n"); continue; @@ -430,204 +452,19 @@ luks_recover_key (grub_cryptodisk_t dev, const struct grub_luks_phdr *header, return GRUB_ACCESS_DENIED; } -static void -luks_close (grub_cryptodisk_t luks) -{ - grub_crypto_cipher_close (luks->cipher); - grub_crypto_cipher_close (luks->secondary_cipher); - grub_crypto_cipher_close (luks->essiv_cipher); - grub_free (luks); -} - -static grub_err_t -grub_luks_scan_device_real (const char *name, grub_disk_t source) -{ - grub_err_t err; - struct grub_luks_phdr header; - grub_cryptodisk_t newdev, dev; - - dev = grub_cryptodisk_get_by_source_disk (source); - - if (dev) - return GRUB_ERR_NONE; - - /* Read the LUKS header. */ - err = grub_disk_read (source, 0, 0, sizeof (header), &header); - if (err) - return err; - - newdev = configure_ciphers (&header); - if (!newdev) - return grub_errno; - - newdev->total_length = grub_disk_get_size (source) - newdev->offset; - - err = luks_recover_key (newdev, &header, name, source); - if (err) - { - luks_close (newdev); - return err; - } - - grub_cryptodisk_insert (newdev, name, source); - - have_it = 1; - - return GRUB_ERR_NONE; -} - -#ifdef GRUB_UTIL -grub_err_t -grub_luks_cheat_mount (const char *sourcedev, const char *cheat) -{ - grub_err_t err; - struct grub_luks_phdr header; - grub_cryptodisk_t newdev, dev; - grub_disk_t source; - - /* Try to open disk. */ - source = grub_disk_open (sourcedev); - if (!source) - return grub_errno; - - dev = grub_cryptodisk_get_by_source_disk (source); - - if (dev) - { - grub_disk_close (source); - return GRUB_ERR_NONE; - } - - /* Read the LUKS header. */ - err = grub_disk_read (source, 0, 0, sizeof (header), &header); - if (err) - return err; - - newdev = configure_ciphers (&header); - if (!newdev) - { - grub_disk_close (source); - return grub_errno; - } - - newdev->total_length = grub_disk_get_size (source) - newdev->offset; - - err = grub_cryptodisk_cheat_insert (newdev, sourcedev, source, cheat); - grub_disk_close (source); - if (err) - grub_free (newdev); - - return err; -} -#endif - -static int -grub_luks_scan_device (const char *name) -{ - grub_err_t err; - grub_disk_t source; - - /* Try to open disk. */ - source = grub_disk_open (name); - if (!source) - return grub_errno; - - err = grub_luks_scan_device_real (name, source); - - grub_disk_close (source); - - if (err) - grub_print_error (); - return have_it && check_uuid ? 0 : 1; -} - -#ifdef GRUB_UTIL - -void -grub_util_luks_print_uuid (grub_disk_t disk) -{ - grub_cryptodisk_t dev = (grub_cryptodisk_t) disk->data; - grub_printf ("%s ", dev->uuid); -} -#endif - -static grub_err_t -grub_cmd_luksmount (grub_extcmd_context_t ctxt, int argc, char **args) -{ - struct grub_arg_list *state = ctxt->state; - - if (argc < 1 && !state[1].set) - return grub_error (GRUB_ERR_BAD_ARGUMENT, "device name required"); - - have_it = 0; - if (state[0].set) - { - grub_cryptodisk_t dev; - - dev = grub_cryptodisk_get_by_uuid (args[0]); - if (dev) - { - grub_dprintf ("luks", "already mounted as crypto%lu\n", dev->id); - return GRUB_ERR_NONE; - } - - check_uuid = 1; - search_uuid = args[0]; - grub_device_iterate (&grub_luks_scan_device); - search_uuid = NULL; - - if (!have_it) - return grub_error (GRUB_ERR_BAD_ARGUMENT, "no such luks found"); - return GRUB_ERR_NONE; - } - else if (state[1].set) - { - check_uuid = 0; - search_uuid = NULL; - grub_device_iterate (&grub_luks_scan_device); - search_uuid = NULL; - return GRUB_ERR_NONE; - } - else - { - grub_err_t err; - grub_disk_t disk; - grub_cryptodisk_t dev; - - check_uuid = 0; - search_uuid = NULL; - disk = grub_disk_open (args[0]); - if (!disk) - return grub_errno; - - dev = grub_cryptodisk_get_by_source_disk (disk); - if (dev) - { - grub_dprintf ("luks", "already mounted as luks%lu\n", dev->id); - grub_disk_close (disk); - return GRUB_ERR_NONE; - } - - err = grub_luks_scan_device_real (args[0], disk); - - grub_disk_close (disk); - - return err; - } -} - -static grub_extcmd_t cmd; +struct grub_cryptodisk_dev luks_crypto = { + .scan = configure_ciphers, + .recover_key = luks_recover_key +}; GRUB_MOD_INIT (luks) { COMPILE_TIME_ASSERT (sizeof (((struct grub_luks_phdr *) 0)->uuid) < GRUB_CRYPTODISK_MAX_UUID_LENGTH); - cmd = grub_register_extcmd ("luksmount", grub_cmd_luksmount, 0, - N_("SOURCE|-u UUID|-a"), - N_("Mount a LUKS device."), options); + grub_cryptodisk_dev_register (&luks_crypto); } GRUB_MOD_FINI (luks) { - grub_unregister_extcmd (cmd); + grub_cryptodisk_dev_unregister (&luks_crypto); } diff --git a/grub-core/kern/emu/getroot.c b/grub-core/kern/emu/getroot.c index 642d77cf0..b6e8a673f 100644 --- a/grub-core/kern/emu/getroot.c +++ b/grub-core/kern/emu/getroot.c @@ -33,6 +33,7 @@ #include #include #include +#include #ifdef HAVE_DEVICE_MAPPER # include @@ -756,6 +757,94 @@ grub_util_get_dm_abstraction (const char *os_dev) #endif } +#if defined (__FreeBSD__) || defined(__FreeBSD_kernel__) +#include + +/* FIXME: geom actually gives us the whole container hierarchy. + It can be used more efficiently than this. */ +void +grub_util_follow_gpart_up (const char *name, grub_disk_addr_t *off_out, char **name_out) +{ + struct gmesh mesh; + struct gclass *class; + int error; + struct ggeom *geom; + + grub_util_info ("following geom '%s'", name); + + error = geom_gettree (&mesh); + if (error != 0) + grub_util_error ("couldn't open geom"); + + LIST_FOREACH (class, &mesh.lg_class, lg_class) + if (strcasecmp (class->lg_name, "part") == 0) + break; + if (!class) + grub_util_error ("couldn't open geom part"); + + LIST_FOREACH (geom, &class->lg_geom, lg_geom) + { + struct gprovider *provider; + LIST_FOREACH (provider, &geom->lg_provider, lg_provider) + if (strcmp (provider->lg_name, name) == 0) + { + char *name_tmp = xstrdup (geom->lg_name); + grub_disk_addr_t off = 0; + struct gconfig *config; + grub_util_info ("geom '%s' has parent '%s'", name, geom->lg_name); + + grub_util_follow_gpart_up (name_tmp, &off, name_out); + free (name_tmp); + LIST_FOREACH (config, &provider->lg_config, lg_config) + if (strcasecmp (config->lg_name, "start") == 0) + off += strtoull (config->lg_val, 0, 10); + if (off_out) + *off_out = off; + return; + } + } + grub_util_info ("geom '%s' has no parent", name); + if (name_out) + *name_out = xstrdup (name); + if (off_out) + *off_out = 0; +} + +static const char * +grub_util_get_geom_abstraction (const char *dev) +{ + char *whole; + struct gmesh mesh; + struct gclass *class; + const char *name; + int error; + + if (strncmp (dev, "/dev/", sizeof ("/dev/") - 1) != 0) + return 0; + name = dev + sizeof ("/dev/") - 1; + grub_util_follow_gpart_up (name, NULL, &whole); + + grub_util_info ("following geom '%s'", name); + + error = geom_gettree (&mesh); + if (error != 0) + grub_util_error ("couldn't open geom"); + + LIST_FOREACH (class, &mesh.lg_class, lg_class) + { + struct ggeom *geom; + LIST_FOREACH (geom, &class->lg_geom, lg_geom) + { + struct gprovider *provider; + LIST_FOREACH (provider, &geom->lg_provider, lg_provider) + if (strcmp (provider->lg_name, name) == 0) + return class->lg_name; + } + } + return NULL; +} +#endif + int grub_util_get_dev_abstraction (const char *os_dev __attribute__((unused))) { @@ -777,6 +866,14 @@ grub_util_get_dev_abstraction (const char *os_dev __attribute__((unused))) return GRUB_DEV_ABSTRACTION_RAID; #endif +#if defined (__FreeBSD__) || defined(__FreeBSD_kernel__) + const char *abs; + abs = grub_util_get_geom_abstraction (os_dev); + grub_util_info ("abstraction of %s is %s", os_dev, abs); + if (abs && grub_strcasecmp (abs, "eli") == 0) + return GRUB_DEV_ABSTRACTION_GELI; +#endif + /* No abstraction found. */ return GRUB_DEV_ABSTRACTION_NONE; } @@ -869,6 +966,71 @@ grub_util_pull_device (const char *os_dev) ab = grub_util_get_dev_abstraction (os_dev); switch (ab) { + case GRUB_DEV_ABSTRACTION_GELI: + { + char *whole; + struct gmesh mesh; + struct gclass *class; + const char *name; + int error; + char *lastsubdev = NULL; + + if (strncmp (os_dev, "/dev/", sizeof ("/dev/") - 1) != 0) + return; + name = os_dev + sizeof ("/dev/") - 1; + grub_util_follow_gpart_up (name, NULL, &whole); + + grub_util_info ("following geom '%s'", name); + + error = geom_gettree (&mesh); + if (error != 0) + grub_util_error ("couldn't open geom"); + + LIST_FOREACH (class, &mesh.lg_class, lg_class) + { + struct ggeom *geom; + LIST_FOREACH (geom, &class->lg_geom, lg_geom) + { + struct gprovider *provider; + LIST_FOREACH (provider, &geom->lg_provider, lg_provider) + if (strcmp (provider->lg_name, name) == 0) + { + struct gconsumer *consumer; + char *fname; + char *uuid; + + LIST_FOREACH (consumer, &geom->lg_consumer, lg_consumer) + break; + if (!consumer) + grub_util_error ("couldn't find geli consumer"); + fname = xasprintf ("/dev/%s", consumer->lg_provider->lg_name); + grub_util_info ("consumer %s", consumer->lg_provider->lg_name); + lastsubdev = consumer->lg_provider->lg_name; + grub_util_pull_device (fname); + free (fname); + } + } + } + if (ab == GRUB_DEV_ABSTRACTION_GELI && lastsubdev) + { + char *fname = xasprintf ("/dev/%s", lastsubdev); + char *grdev = grub_util_get_grub_dev (fname); + free (fname); + + if (grdev) + { + grub_err_t err; + err = grub_cryptodisk_cheat_mount (grdev, os_dev); + if (err) + grub_util_error ("Can't mount crypto: %s", grub_errmsg); + } + + grub_free (grdev); + } + + } + break; + case GRUB_DEV_ABSTRACTION_LVM: case GRUB_DEV_ABSTRACTION_LUKS: #ifdef HAVE_DEVICE_MAPPER @@ -895,7 +1057,7 @@ grub_util_pull_device (const char *os_dev) grub_util_pull_device (subdev); } } - if (ab == GRUB_DEV_ABSTRACTION_LUKS && lastsubdev) + if (ab == GRUB_DEV_ABSTRACTION_CRYPTO && lastsubdev) { char *grdev = grub_util_get_grub_dev (lastsubdev); dm_tree_free (tree); @@ -904,7 +1066,7 @@ grub_util_pull_device (const char *os_dev) grub_err_t err; err = grub_luks_cheat_mount (grdev, os_dev); if (err) - grub_util_error ("Can't mount LUKS: %s", grub_errmsg); + grub_util_error ("Can't mount crypto: %s", grub_errmsg); } grub_free (grdev); } @@ -959,6 +1121,8 @@ grub_util_get_grub_dev (const char *os_dev) { char *uuid, *dash; uuid = get_dm_uuid (os_dev); + if (!uuid) + break; dash = grub_strchr (uuid + sizeof ("CRYPT-LUKS1-") - 1, '-'); if (dash) *dash = 0; @@ -968,6 +1132,55 @@ grub_util_get_grub_dev (const char *os_dev) } break; + case GRUB_DEV_ABSTRACTION_GELI: + { + char *whole; + struct gmesh mesh; + struct gclass *class; + const char *name; + int error; + + if (strncmp (os_dev, "/dev/", sizeof ("/dev/") - 1) != 0) + return 0; + name = os_dev + sizeof ("/dev/") - 1; + grub_util_follow_gpart_up (name, NULL, &whole); + + grub_util_info ("following geom '%s'", name); + + error = geom_gettree (&mesh); + if (error != 0) + grub_util_error ("couldn't open geom"); + + LIST_FOREACH (class, &mesh.lg_class, lg_class) + { + struct ggeom *geom; + LIST_FOREACH (geom, &class->lg_geom, lg_geom) + { + struct gprovider *provider; + LIST_FOREACH (provider, &geom->lg_provider, lg_provider) + if (strcmp (provider->lg_name, name) == 0) + { + struct gconsumer *consumer; + char *fname; + char *uuid; + + LIST_FOREACH (consumer, &geom->lg_consumer, lg_consumer) + break; + if (!consumer) + grub_util_error ("couldn't find geli consumer"); + fname = xasprintf ("/dev/%s", consumer->lg_provider->lg_name); + uuid = grub_util_get_geli_uuid (fname); + if (!uuid) + grub_util_error ("couldn't retrieve geli UUID"); + grub_dev = xasprintf ("cryptouuid/%s", uuid); + free (fname); + free (uuid); + } + } + } + } + break; + case GRUB_DEV_ABSTRACTION_RAID: if (os_dev[7] == '_' && os_dev[8] == 'd') diff --git a/grub-core/kern/emu/hostdisk.c b/grub-core/kern/emu/hostdisk.c index 97e090222..6cace3746 100644 --- a/grub-core/kern/emu/hostdisk.c +++ b/grub-core/kern/emu/hostdisk.c @@ -106,9 +106,7 @@ struct hd_geometry # include #endif -#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) -#include -#elif defined(__NetBSD__) +#if defined(__NetBSD__) # define HAVE_DIOCGDINFO # include # include /* struct disklabel */ @@ -226,6 +224,82 @@ grub_util_biosdisk_iterate (int (*hook) (const char *name), return 0; } +#if !defined(__MINGW32__) +grub_uint64_t +grub_util_get_fd_sectors (int fd, unsigned *log_secsize) +{ +#if defined(__linux__) || defined(__CYGWIN__) || defined(__FreeBSD__) || \ + defined(__FreeBSD_kernel__) || defined(__APPLE__) || defined(__NetBSD__) +# if defined(__NetBSD__) + struct disklabel label; +# else + unsigned long long nr; +# endif + unsigned sector_size, log_sector_size; + struct stat st; + + if (fstat (fd, &st) < 0) + grub_util_error ("fstat failed"); + +# if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__APPLE__) || defined(__NetBSD__) + if (! S_ISCHR (st.st_mode)) +# else + if (! S_ISBLK (st.st_mode)) +# endif + goto fail; + +# if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) + if (ioctl (fd, DIOCGMEDIASIZE, &nr)) +# elif defined(__APPLE__) + if (ioctl (fd, DKIOCGETBLOCKCOUNT, &nr)) +# elif defined(__NetBSD__) + configure_device_driver (fd); + if (ioctl (fd, DIOCGDINFO, &label) == -1) +# else + if (ioctl (fd, BLKGETSIZE64, &nr)) +# endif + goto fail; + +# if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) + if (ioctl (fd, DIOCGSECTORSIZE, §or_size)) +# else + if (ioctl (fd, BLKSSZGET, §or_size)) +# endif + goto fail; + + if (sector_size & (sector_size - 1) || !sector_size) + goto fail; + for (log_sector_size = 0; + (1 << log_sector_size) < sector_size; + log_sector_size++); + + if (log_secsize) + *log_secsize = log_sector_size; + +# if defined (__APPLE__) + return nr; +# elif defined(__NetBSD__) + return label.d_secperunit; +# else + if (nr & ((1 << log_sector_size) - 1)) + grub_util_error ("unaligned device size"); + + return (nr >> log_sector_size); +# endif + + fail: + /* In GNU/Hurd, stat() will return the right size. */ +#elif !defined (__GNU__) +# warning "No special routine to get the size of a block device is implemented for your OS. This is not possibly fatal." +#endif + + if (log_secsize) + *log_secsize = 9; + + return st.st_size >> 9; +} +#endif + static grub_err_t grub_util_biosdisk_open (const char *name, grub_disk_t disk, grub_disk_pull_t pull __attribute__ ((unused))) @@ -262,90 +336,30 @@ grub_util_biosdisk_open (const char *name, grub_disk_t disk, return GRUB_ERR_NONE; } -#elif defined(__linux__) || defined(__CYGWIN__) || defined(__FreeBSD__) || \ - defined(__FreeBSD_kernel__) || defined(__APPLE__) || defined(__NetBSD__) +#else { -# if defined(__NetBSD__) - struct disklabel label; -# else - unsigned long long nr; -# endif - int sector_size; int fd; fd = open (map[drive].device, O_RDONLY); if (fd == -1) return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "cannot open `%s' while attempting to get disk size", map[drive].device); + disk->total_sectors = grub_util_get_fd_sectors (fd, &disk->log_sector_size); + # if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__APPLE__) || defined(__NetBSD__) if (fstat (fd, &st) < 0 || ! S_ISCHR (st.st_mode)) # else if (fstat (fd, &st) < 0 || ! S_ISBLK (st.st_mode)) # endif - { - close (fd); - goto fail; - } - data->is_disk = 1; - -# if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) - if (ioctl (fd, DIOCGMEDIASIZE, &nr)) -# elif defined(__APPLE__) - if (ioctl (fd, DKIOCGETBLOCKCOUNT, &nr)) -# elif defined(__NetBSD__) - configure_device_driver (fd); - if (ioctl (fd, DIOCGDINFO, &label) == -1) -# else - if (ioctl (fd, BLKGETSIZE64, &nr)) -# endif - { - close (fd); - goto fail; - } - - if (ioctl (fd, BLKSSZGET, §or_size)) - { - close (fd); - goto fail; - } + data->is_disk = 1; close (fd); - if (sector_size & (sector_size - 1) || !sector_size) - goto fail; - for (disk->log_sector_size = 0; - (1 << disk->log_sector_size) < sector_size; - disk->log_sector_size++); - -# if defined (__APPLE__) - disk->total_sectors = nr; -# elif defined(__NetBSD__) - disk->total_sectors = label.d_secperunit; -# else - disk->total_sectors = nr >> disk->log_sector_size; - - if (nr & ((1 << disk->log_sector_size) - 1)) - grub_util_error ("unaligned device size"); -# endif - grub_util_info ("the size of %s is %llu", name, disk->total_sectors); return GRUB_ERR_NONE; } - - fail: - /* In GNU/Hurd, stat() will return the right size. */ -#elif !defined (__GNU__) -# warning "No special routine to get the size of a block device is implemented for your OS. This is not possibly fatal." #endif - if (stat (map[drive].device, &st) < 0) - return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "cannot stat `%s'", map[drive].device); - - disk->total_sectors = st.st_size >> disk->log_sector_size; - - grub_util_info ("the size of %s is %lu", name, disk->total_sectors); - - return GRUB_ERR_NONE; } int @@ -367,55 +381,6 @@ grub_util_device_is_mapped (const char *dev) } #if defined (__FreeBSD__) || defined(__FreeBSD_kernel__) -/* FIXME: geom actually gives us the whole container hierarchy. - It can be used more efficiently than this. */ -static void -follow_geom_up (const char *name, grub_disk_addr_t *off_out, char **name_out) -{ - struct gmesh mesh; - struct gclass *class; - int error; - struct ggeom *geom; - - grub_util_info ("following geom '%s'", name); - - error = geom_gettree (&mesh); - if (error != 0) - grub_util_error ("couldn't open geom"); - - LIST_FOREACH (class, &mesh.lg_class, lg_class) - if (strcasecmp (class->lg_name, "part") == 0) - break; - if (!class) - grub_util_error ("couldn't open geom part"); - - LIST_FOREACH (geom, &class->lg_geom, lg_geom) - { - struct gprovider *provider; - LIST_FOREACH (provider, &geom->lg_provider, lg_provider) - if (strcmp (provider->lg_name, name) == 0) - { - char *name_tmp = xstrdup (geom->lg_name); - grub_disk_addr_t off = 0; - struct gconfig *config; - grub_util_info ("geom '%s' has parent '%s'", name, geom->lg_name); - - follow_geom_up (name_tmp, &off, name_out); - free (name_tmp); - LIST_FOREACH (config, &provider->lg_config, lg_config) - if (strcasecmp (config->lg_name, "start") == 0) - off += strtoull (config->lg_val, 0, 10); - if (off_out) - *off_out = off; - return; - } - } - grub_util_info ("geom '%s' has no parent", name); - if (name_out) - *name_out = xstrdup (name); - if (off_out) - *off_out = 0; -} static grub_disk_addr_t find_partition_start (const char *dev) @@ -423,10 +388,11 @@ find_partition_start (const char *dev) grub_disk_addr_t out; if (strncmp (dev, "/dev/", sizeof ("/dev/") - 1) != 0) return 0; - follow_geom_up (dev + sizeof ("/dev/") - 1, &out, NULL); + grub_util_follow_gpart_up (dev + sizeof ("/dev/") - 1, &out, NULL); return out; } + #elif defined(__linux__) || defined(__CYGWIN__) || defined(HAVE_DIOCGDINFO) static grub_disk_addr_t find_partition_start (const char *dev) @@ -1508,7 +1474,7 @@ devmapper_out: char *out, *out2; if (strncmp (os_dev, "/dev/", sizeof ("/dev/") - 1) != 0) return xstrdup (os_dev); - follow_geom_up (os_dev + sizeof ("/dev/") - 1, NULL, &out); + grub_util_follow_gpart_up (os_dev + sizeof ("/dev/") - 1, NULL, &out); out2 = xasprintf ("/dev/%s", out); free (out); @@ -1667,6 +1633,8 @@ grub_util_biosdisk_get_grub_dev (const char *os_dev) struct stat st; int drive; + grub_util_info ("Looking for %s", os_dev); + if (stat (os_dev, &st) < 0) { grub_error (GRUB_ERR_BAD_DEVICE, "cannot stat `%s'", os_dev); diff --git a/include/grub/cryptodisk.h b/include/grub/cryptodisk.h index 169fb119d..c6d1ce8de 100644 --- a/include/grub/cryptodisk.h +++ b/include/grub/cryptodisk.h @@ -21,6 +21,7 @@ #include #include +#include typedef enum { @@ -57,6 +58,8 @@ typedef gcry_err_code_t struct grub_cryptodisk { + struct grub_cryptodisk *next; + char *source; grub_disk_addr_t offset; grub_disk_addr_t total_length; @@ -78,6 +81,7 @@ struct grub_cryptodisk grub_size_t iv_prefix_len; #ifdef GRUB_UTIL char *cheat; + const char *modname; int cheat_fd; #endif int log_sector_size; @@ -86,10 +90,37 @@ struct grub_cryptodisk grub_uint8_t rekey_key[64]; grub_uint64_t last_rekey; int rekey_derived_size; - struct grub_cryptodisk *next; }; typedef struct grub_cryptodisk *grub_cryptodisk_t; +struct grub_cryptodisk_dev +{ + struct grub_cryptodisk_dev *next; + + grub_cryptodisk_t (*scan) (grub_disk_t disk, const char *check_uuid, + int boot_only); + grub_err_t (*recover_key) (grub_disk_t disk, grub_cryptodisk_t dev); +}; +typedef struct grub_cryptodisk_dev *grub_cryptodisk_dev_t; + +extern grub_cryptodisk_dev_t EXPORT_VAR (grub_cryptodisk_list); + +#ifndef GRUB_LST_GENERATOR +static inline void +grub_cryptodisk_dev_register (grub_cryptodisk_dev_t cr) +{ + grub_list_push (GRUB_AS_LIST_P (&grub_cryptodisk_list), GRUB_AS_LIST (cr)); +} +#endif + +static inline void +grub_cryptodisk_dev_unregister (grub_cryptodisk_dev_t cr) +{ + grub_list_remove (GRUB_AS_LIST_P (&grub_cryptodisk_list), GRUB_AS_LIST (cr)); +} + +#define FOR_CRYPTODISK_DEVS(var) FOR_LIST_ELEMENTS((var), (grub_cryptodisk_list)) + gcry_err_code_t grub_cryptodisk_setkey (grub_cryptodisk_t dev, grub_uint8_t *key, grub_size_t keysize); @@ -106,6 +137,8 @@ grub_cryptodisk_cheat_insert (grub_cryptodisk_t newdev, const char *name, grub_disk_t source, const char *cheat); void grub_util_cryptodisk_print_abstraction (grub_disk_t disk); +char * +grub_util_get_geli_uuid (const char *dev); #endif grub_cryptodisk_t grub_cryptodisk_get_by_uuid (const char *uuid); diff --git a/include/grub/emu/getroot.h b/include/grub/emu/getroot.h index 57cd911ef..6921e567c 100644 --- a/include/grub/emu/getroot.h +++ b/include/grub/emu/getroot.h @@ -26,6 +26,7 @@ enum grub_dev_abstraction_types { GRUB_DEV_ABSTRACTION_LVM, GRUB_DEV_ABSTRACTION_RAID, GRUB_DEV_ABSTRACTION_LUKS, + GRUB_DEV_ABSTRACTION_GELI, }; char *grub_find_device (const char *dir, dev_t dev); @@ -38,5 +39,9 @@ const char *grub_util_check_char_device (const char *blk_dev); #ifdef __linux__ char **grub_util_raid_getmembers (const char *name, int bootable); #endif +#if defined (__FreeBSD__) || defined(__FreeBSD_kernel__) +void grub_util_follow_gpart_up (const char *name, grub_disk_addr_t *off_out, + char **name_out); +#endif #endif /* ! GRUB_UTIL_GETROOT_HEADER */ diff --git a/include/grub/emu/hostdisk.h b/include/grub/emu/hostdisk.h index 18191c4eb..719faa29b 100644 --- a/include/grub/emu/hostdisk.h +++ b/include/grub/emu/hostdisk.h @@ -35,7 +35,11 @@ grub_err_t grub_util_fd_seek (int fd, const char *name, grub_uint64_t sector); ssize_t grub_util_fd_read (int fd, char *buf, size_t len); grub_err_t -grub_luks_cheat_mount (const char *sourcedev, const char *cheat); -void grub_util_luks_print_uuid (grub_disk_t disk); +grub_cryptodisk_cheat_mount (const char *sourcedev, const char *cheat); +void grub_util_cryptodisk_print_uuid (grub_disk_t disk); +#if !defined(__MINGW32__) +grub_uint64_t +grub_util_get_fd_sectors (int fd, unsigned *log_secsize); +#endif #endif /* ! GRUB_BIOSDISK_MACHINE_UTIL_HEADER */ diff --git a/util/grub-fstest.c b/util/grub-fstest.c index 48a5be1ca..f5880626c 100644 --- a/util/grub-fstest.c +++ b/util/grub-fstest.c @@ -309,10 +309,8 @@ fstest (int n, char **args) char *argv[2] = { "-a", NULL}; if (mount_crypt) { - if (execute_command ("luksmount", 1, argv)) - grub_util_error (_("luksmount command fails: %s"), grub_errmsg); - if (execute_command ("gelimount", 1, argv)) - grub_util_error (_("gelimount command fails: %s"), grub_errmsg); + if (execute_command ("cryptomount", 1, argv)) + grub_util_error (_("cryptomount command fails: %s"), grub_errmsg); } } diff --git a/util/grub-install.in b/util/grub-install.in index 3b3383ab4..049444e93 100644 --- a/util/grub-install.in +++ b/util/grub-install.in @@ -538,9 +538,9 @@ if [ "x${devabstraction_module}" = "x" ] ; then exit 1 fi - if [ x$GRUB_LUKS_ENABLE = xy ]; then - for uuid in "`"${grub_probe}" --device "${device}" --target=luks_uuid`"; do - echo "luksmount -u $uuid" + if [ x$GRUB_CRYPTODISK_ENABLE = xy ]; then + for uuid in "`"${grub_probe}" --device "${device}" --target=cryptodisk_uuid`"; do + echo "cryptomount -u $uuid" done fi diff --git a/util/grub-mkconfig.in b/util/grub-mkconfig.in index 41e68bc1b..ade7a558d 100644 --- a/util/grub-mkconfig.in +++ b/util/grub-mkconfig.in @@ -254,7 +254,7 @@ export GRUB_DEFAULT \ GRUB_DISABLE_OS_PROBER \ GRUB_INIT_TUNE \ GRUB_SAVEDEFAULT \ - GRUB_ENABLE_LUKS \ + GRUB_ENABLE_CRYPTODISK \ GRUB_BADRAM if test "x${grub_cfg}" != "x"; then diff --git a/util/grub-mkconfig_lib.in b/util/grub-mkconfig_lib.in index 1664b6bbe..33ee7e432 100644 --- a/util/grub-mkconfig_lib.in +++ b/util/grub-mkconfig_lib.in @@ -69,12 +69,12 @@ is_path_readable_by_grub () return 1 fi - if [ x$GRUB_LUKS_ENABLE = xy ]; then + if [ x$GRUB_CRYPTODISK_ENABLE = xy ]; then return 0 fi for abstraction in $abstractions; do - if [ "x$abstraction" = xluks ]; then + if [ "x$abstraction" = xcryptodisk ]; then return 1 fi done @@ -138,9 +138,9 @@ prepare_grub_to_access_device () echo "insmod ${module}" done - if [ x$GRUB_LUKS_ENABLE = xy ]; then - for uuid in "`"${grub_probe}" --device "${device}" --target=luks_uuid`"; do - echo "luksmount -u $uuid" + if [ x$GRUB_CRYPTODISK_ENABLE = xy ]; then + for uuid in "`"${grub_probe}" --device "${device}" --target=cryptodisk_uuid`"; do + echo "cryptomount -u $uuid" done fi diff --git a/util/grub-probe.c b/util/grub-probe.c index f5d93ac4e..7c0a75123 100644 --- a/util/grub-probe.c +++ b/util/grub-probe.c @@ -56,7 +56,7 @@ enum { PRINT_DEVICE, PRINT_PARTMAP, PRINT_ABSTRACTION, - PRINT_LUKS_UUID + PRINT_CRYPTODISK_UUID }; int print = PRINT_FS; @@ -91,7 +91,7 @@ probe_partmap (grub_disk_t disk) } static void -probe_luks_uuid (grub_disk_t disk) +probe_cryptodisk_uuid (grub_disk_t disk) { grub_disk_memberlist_t list = NULL, tmp; @@ -102,14 +102,13 @@ probe_luks_uuid (grub_disk_t disk) } while (list) { - probe_luks_uuid (list->disk); + probe_cryptodisk_uuid (list->disk); tmp = list->next; free (list); list = tmp; } - /* FIXME: support non-LUKS. */ if (disk->dev->id == GRUB_DISK_DEVICE_CRYPTODISK_ID) - grub_util_luks_print_uuid (disk); + grub_util_cryptodisk_print_uuid (disk); } static int @@ -215,9 +214,9 @@ probe (const char *path, char *device_name) goto end; } - if (print == PRINT_LUKS_UUID) + if (print == PRINT_CRYPTODISK_UUID) { - probe_luks_uuid (dev->disk); + probe_cryptodisk_uuid (dev->disk); printf ("\n"); goto end; } @@ -295,8 +294,8 @@ Probe device information for a given path (or device, if the -d option is given) \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\ - -t, --target=(fs|fs_uuid|fs_label|drive|device|partmap|abstraction|luks_uuid)\n\ - print filesystem module, GRUB drive, system device, partition map module, abstraction module or LUKS UUID [default=fs]\n\ + -t, --target=(fs|fs_uuid|fs_label|drive|device|partmap|abstraction|cryptodisk_uuid)\n\ + print filesystem module, GRUB drive, system device, partition map module, abstraction module or CRYPTO UUID [default=fs]\n\ -h, --help display this message and exit\n\ -V, --version print version information and exit\n\ -v, --verbose print verbose messages\n\ @@ -354,8 +353,8 @@ main (int argc, char *argv[]) print = PRINT_PARTMAP; else if (!strcmp (optarg, "abstraction")) print = PRINT_ABSTRACTION; - else if (!strcmp (optarg, "luks_uuid")) - print = PRINT_LUKS_UUID; + else if (!strcmp (optarg, "cryptodisk_uuid")) + print = PRINT_CRYPTODISK_UUID; else usage (1); break; From 6be8715dfce00f852b8f31ae3d89f34c5b2f60b0 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 25 Apr 2011 15:23:37 +0200 Subject: [PATCH 528/869] * grub-core/disk/mdraid_linux.c (grub_mdraid_detect): Make mdraid UUID match the one used by mdadm. --- ChangeLog | 5 +++++ grub-core/disk/mdraid_linux.c | 8 ++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index cd791308c..2de8578ff 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-04-25 Vladimir Serbinenko + + * grub-core/disk/mdraid_linux.c (grub_mdraid_detect): Make mdraid UUID + match the one used by mdadm. + 2011-04-21 Colin Watson * po/README: Add instructions for creating po/LINGUAS. diff --git a/grub-core/disk/mdraid_linux.c b/grub-core/disk/mdraid_linux.c index 691d100b8..0e2d85009 100644 --- a/grub-core/disk/mdraid_linux.c +++ b/grub-core/disk/mdraid_linux.c @@ -221,10 +221,10 @@ grub_mdraid_detect (grub_disk_t disk, struct grub_raid_array *array, return grub_errno; uuid = (grub_uint32_t *) array->uuid; - uuid[0] = sb.set_uuid0; - uuid[1] = sb.set_uuid1; - uuid[2] = sb.set_uuid2; - uuid[3] = sb.set_uuid3; + uuid[0] = grub_swap_bytes32 (sb.set_uuid0); + uuid[1] = grub_swap_bytes32 (sb.set_uuid1); + uuid[2] = grub_swap_bytes32 (sb.set_uuid2); + uuid[3] = grub_swap_bytes32 (sb.set_uuid3); *start_sector = 0; From 68797f9230de4768b472f2807d1c947dba96dff0 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 25 Apr 2011 15:29:41 +0200 Subject: [PATCH 529/869] * grub-core/gnulib/regex.c: Remove GRUB_MOD_LICENSE since it's already supplied by another part of the module (fixes compilation on FreeBSD). --- ChangeLog | 6 ++++++ grub-core/gnulib/regex.c | 3 --- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2de8578ff..b464d83a8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2011-04-25 Vladimir Serbinenko + + * grub-core/gnulib/regex.c: Remove GRUB_MOD_LICENSE since it's + already supplied by another part of the module (fixes compilation on + FreeBSD). + 2011-04-25 Vladimir Serbinenko * grub-core/disk/mdraid_linux.c (grub_mdraid_detect): Make mdraid UUID diff --git a/grub-core/gnulib/regex.c b/grub-core/gnulib/regex.c index 4c2243f64..ba0eebee7 100644 --- a/grub-core/gnulib/regex.c +++ b/grub-core/gnulib/regex.c @@ -19,9 +19,6 @@ Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include -#include - -GRUB_MOD_LICENSE ("GPLv3+"); /* Make sure noone compiles this code with a C++ compiler. */ #if defined __cplusplus && defined _LIBC From 723f63f2f88c91407ec0ee8c6b545f76a79e75dc Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 25 Apr 2011 15:36:08 +0200 Subject: [PATCH 530/869] * grub-core/partmap/amiga.c (amiga_partition_map_iterate): Fix a wrong action on non-detecting the magic. --- ChangeLog | 5 +++++ grub-core/partmap/amiga.c | 5 +++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index b464d83a8..3da7693db 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-04-25 Vladimir Serbinenko + + * grub-core/partmap/amiga.c (amiga_partition_map_iterate): Fix a + wrong action on non-detecting the magic. + 2011-04-25 Vladimir Serbinenko * grub-core/gnulib/regex.c: Remove GRUB_MOD_LICENSE since it's diff --git a/grub-core/partmap/amiga.c b/grub-core/partmap/amiga.c index f3ba950aa..36e318beb 100644 --- a/grub-core/partmap/amiga.c +++ b/grub-core/partmap/amiga.c @@ -114,8 +114,9 @@ amiga_partition_map_iterate (grub_disk_t disk, return grub_errno; if (grub_memcmp (apart.magic, GRUB_AMIGA_PART_MAGIC, - sizeof (apart.magic)) == 0) - + sizeof (apart.magic)) != 0) + return grub_error (GRUB_ERR_BAD_PART_TABLE, + "invalid Amiga partition map"); /* Calculate the first block and the size of the partition. */ part.start = (grub_be_to_cpu32 (apart.lowcyl) * grub_be_to_cpu32 (apart.heads) From 3c62402d08da39973b299c1c153c119567bb08f3 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 25 Apr 2011 16:58:25 +0200 Subject: [PATCH 531/869] * grub-core/loader/i386/linux.c (grub_linux_boot): Supply target rather than source address for efi mmap buffer. --- ChangeLog | 5 +++++ grub-core/loader/i386/linux.c | 10 ++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3da7693db..0a7e4d64c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-04-25 Vladimir Serbinenko + + * grub-core/loader/i386/linux.c (grub_linux_boot): Supply target rather + than source address for efi mmap buffer. + 2011-04-25 Vladimir Serbinenko * grub-core/partmap/amiga.c (amiga_partition_map_iterate): Fix a diff --git a/grub-core/loader/i386/linux.c b/grub-core/loader/i386/linux.c index 241eaa5e7..f19f471ab 100644 --- a/grub-core/loader/i386/linux.c +++ b/grub-core/loader/i386/linux.c @@ -549,6 +549,7 @@ grub_linux_boot (void) #ifdef GRUB_MACHINE_EFI { grub_efi_uintn_t efi_desc_size; + grub_size_t efi_mmap_target; grub_efi_uint32_t efi_desc_version; err = grub_efi_finish_boot_services (&efi_mmap_size, efi_mmap_buf, NULL, &efi_desc_size, &efi_desc_version); @@ -556,23 +557,24 @@ grub_linux_boot (void) return err; /* Note that no boot services are available from here. */ - + efi_mmap_target = real_mode_target + + ((grub_uint8_t *) efi_mmap_buf - (grub_uint8_t *) real_mode_mem); /* Pass EFI parameters. */ if (grub_le_to_cpu16 (params->version) >= 0x0206) { params->v0206.efi_mem_desc_size = efi_desc_size; params->v0206.efi_mem_desc_version = efi_desc_version; - params->v0206.efi_mmap = (grub_uint32_t) (unsigned long) efi_mmap_buf; + params->v0206.efi_mmap = efi_mmap_target; params->v0206.efi_mmap_size = efi_mmap_size; #ifdef __x86_64__ - params->v0206.efi_mmap_hi = (grub_uint32_t) ((grub_uint64_t) efi_mmap_buf >> 32); + params->v0206.efi_mmap_hi = (efi_mmap_target >> 32); #endif } else if (grub_le_to_cpu16 (params->version) >= 0x0204) { params->v0204.efi_mem_desc_size = efi_desc_size; params->v0204.efi_mem_desc_version = efi_desc_version; - params->v0204.efi_mmap = (grub_uint32_t) (unsigned long) efi_mmap_buf; + params->v0204.efi_mmap = efi_mmap_target; params->v0204.efi_mmap_size = efi_mmap_size; } } From 8f9425534015c78ec04976aa04ce28811cf42405 Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Sun, 1 May 2011 20:04:02 +0100 Subject: [PATCH 532/869] * docs/grub.texi (GRUB only offers a rescue shell): Suggest the use of `ls' to find out which devices are available. --- ChangeLog | 5 +++++ docs/grub.texi | 2 ++ 2 files changed, 7 insertions(+) diff --git a/ChangeLog b/ChangeLog index 0a7e4d64c..58b3cc56c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-05-01 Colin Watson + + * docs/grub.texi (GRUB only offers a rescue shell): Suggest the use + of `ls' to find out which devices are available. + 2011-04-25 Vladimir Serbinenko * grub-core/loader/i386/linux.c (grub_linux_boot): Supply target rather diff --git a/docs/grub.texi b/docs/grub.texi index 8d2223fb4..95707e4cc 100644 --- a/docs/grub.texi +++ b/docs/grub.texi @@ -4127,6 +4127,8 @@ device), then you can correct this and enter normal mode manually: @group # Inspect the current prefix (and other preset variables): set +# Find out which devices are available: +ls # Set to the correct value, which might be something like this: set prefix=(hd0,1)/grub set root=(hd0,1) From 4ebff75340fa311ed4c76644b6f3b798f0ae9723 Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Tue, 3 May 2011 17:57:39 +0100 Subject: [PATCH 533/869] * tests/partmap_test.in: Don't hardcode path to parted. Reported by: Peter Hjalmarsson. Fixes Savannah bug #33150. --- ChangeLog | 5 +++++ tests/partmap_test.in | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 58b3cc56c..2aaeb862a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-05-03 Colin Watson + + * tests/partmap_test.in: Don't hardcode path to parted. + Reported by: Peter Hjalmarsson. Fixes Savannah bug #33150. + 2011-05-01 Colin Watson * docs/grub.texi (GRUB only offers a rescue shell): Suggest the use diff --git a/tests/partmap_test.in b/tests/partmap_test.in index 5a9c1a93d..7e9cef7c6 100644 --- a/tests/partmap_test.in +++ b/tests/partmap_test.in @@ -15,7 +15,7 @@ # You should have received a copy of the GNU General Public License # along with GRUB. If not, see . -parted=/sbin/parted +parted=parted grubshell=@builddir@/grub-shell create_disk_image () { From bd405bbc55f88971a5e669d3c1f6c2570296093f Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Tue, 3 May 2011 18:03:05 +0100 Subject: [PATCH 534/869] * grub-core/fs/i386/pc/pxe.c (grub_pxefs_dir): Return GRUB_ERR_BAD_FS rather than GRUB_ERR_IO if the disk is not a pxe disk; otherwise grub_fs_probe will not fall back to the next filesystem. (grub_pxefs_open): Likewise, for consistency. Reported and tested by: Ezekiel Grave. --- ChangeLog | 9 +++++++++ grub-core/fs/i386/pc/pxe.c | 4 ++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2aaeb862a..29cdc3e01 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2011-05-03 Colin Watson + + * grub-core/fs/i386/pc/pxe.c (grub_pxefs_dir): Return + GRUB_ERR_BAD_FS rather than GRUB_ERR_IO if the disk is not a pxe + disk; otherwise grub_fs_probe will not fall back to the next + filesystem. + (grub_pxefs_open): Likewise, for consistency. + Reported and tested by: Ezekiel Grave. + 2011-05-03 Colin Watson * tests/partmap_test.in: Don't hardcode path to parted. diff --git a/grub-core/fs/i386/pc/pxe.c b/grub-core/fs/i386/pc/pxe.c index d6dc2c22d..4304881fa 100644 --- a/grub-core/fs/i386/pc/pxe.c +++ b/grub-core/fs/i386/pc/pxe.c @@ -227,7 +227,7 @@ grub_pxefs_dir (grub_device_t device, __attribute__ ((unused))) { if (device->disk->dev->id != GRUB_DISK_DEVICE_PXE_ID) - return grub_error (GRUB_ERR_IO, "not a pxe disk"); + return grub_error (GRUB_ERR_BAD_FS, "not a pxe disk"); return GRUB_ERR_NONE; } @@ -245,7 +245,7 @@ grub_pxefs_open (struct grub_file *file, const char *name) grub_file_t file_int, bufio; if (file->device->disk->dev->id != GRUB_DISK_DEVICE_PXE_ID) - return grub_error (GRUB_ERR_IO, "not a pxe disk"); + return grub_error (GRUB_ERR_BAD_FS, "not a pxe disk"); if (curr_file != 0) { From 664889a69ccae30908c13e2293d8400b570bee44 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Thu, 5 May 2011 01:26:16 +0200 Subject: [PATCH 535/869] * grub-core/efiemu/main.c (grub_efiemu_load_file): Return grub_errno and not 0 on failure. --- ChangeLog | 5 +++++ grub-core/efiemu/main.c | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 29cdc3e01..cdfc82688 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-05-05 Vladimir Serbinenko + + * grub-core/efiemu/main.c (grub_efiemu_load_file): Return grub_errno + and not 0 on failure. + 2011-05-03 Colin Watson * grub-core/fs/i386/pc/pxe.c (grub_pxefs_dir): Return diff --git a/grub-core/efiemu/main.c b/grub-core/efiemu/main.c index 772db2956..7ad3abb0d 100644 --- a/grub-core/efiemu/main.c +++ b/grub-core/efiemu/main.c @@ -193,7 +193,7 @@ grub_efiemu_load_file (const char *filename) file = grub_file_open (filename); if (! file) - return 0; + return grub_errno; err = grub_efiemu_mm_init (); if (err) From ee5614b7f8ff69ca55541a72bef0755488a4171d Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Thu, 5 May 2011 01:27:54 +0200 Subject: [PATCH 536/869] * grub-core/lib/legacy_parse.c (grub_legacy_parse): Correctly handle hexadecimal. --- ChangeLog | 5 +++++ grub-core/lib/legacy_parse.c | 5 ++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index cdfc82688..7785ac9f7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-05-05 Vladimir Serbinenko + + * grub-core/lib/legacy_parse.c (grub_legacy_parse): Correctly handle + hexadecimal. + 2011-05-05 Vladimir Serbinenko * grub-core/efiemu/main.c (grub_efiemu_load_file): Return grub_errno diff --git a/grub-core/lib/legacy_parse.c b/grub-core/lib/legacy_parse.c index 024849055..659fa7061 100644 --- a/grub-core/lib/legacy_parse.c +++ b/grub-core/lib/legacy_parse.c @@ -680,7 +680,10 @@ grub_legacy_parse (const char *buf, char **entryname, char **suffix) int base = 10; brk = curarg; if (brk[0] == '0' && brk[1] == 'x') - base = 16; + { + base = 16; + brk += 2; + } else if (brk[0] == '0') base = 8; for (; *brk && brk < curarg + curarglen; brk++) From ed660bd8ed99a29a5eb4b0bebf77a5c50a7fef44 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Thu, 5 May 2011 01:29:21 +0200 Subject: [PATCH 537/869] * util/grub-mkrescue.in (process_input_dir): Include efiemu??.o. --- ChangeLog | 4 ++++ util/grub-mkrescue.in | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 7785ac9f7..794fdf719 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2011-05-05 Vladimir Serbinenko + + * util/grub-mkrescue.in (process_input_dir): Include efiemu??.o. + 2011-05-05 Vladimir Serbinenko * grub-core/lib/legacy_parse.c (grub_legacy_parse): Correctly handle diff --git a/util/grub-mkrescue.in b/util/grub-mkrescue.in index 455534009..f7f751708 100644 --- a/util/grub-mkrescue.in +++ b/util/grub-mkrescue.in @@ -160,7 +160,7 @@ process_input_dir () input_dir="$1" platform="$2" mkdir -p ${iso9660_dir}/boot/grub/${platform} - for file in ${input_dir}/*.mod; do + for file in "${input_dir}/"*.mod "${input_dir}/"efiemu32.o "${input_dir}/"efiemu64.o; do if test -f "$file"; then cp -f "$file" ${iso9660_dir}/boot/grub/${platform}/ fi From 7c515bee148b85f907bdd41db613064b6e2f445c Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Thu, 5 May 2011 01:32:04 +0200 Subject: [PATCH 538/869] * util/grub-mkpasswd-pbkdf2.c (main): Use /dev/urandom and not /dev/random. /dev/urandom is good enough for our purposes (salting). --- ChangeLog | 5 +++++ util/grub-mkpasswd-pbkdf2.c | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 794fdf719..5dd39905e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-05-05 Vladimir Serbinenko + + * util/grub-mkpasswd-pbkdf2.c (main): Use /dev/urandom and not + /dev/random. /dev/urandom is good enough for our purposes (salting). + 2011-05-05 Vladimir Serbinenko * util/grub-mkrescue.in (process_input_dir): Include efiemu??.o. diff --git a/util/grub-mkpasswd-pbkdf2.c b/util/grub-mkpasswd-pbkdf2.c index fe1887f8f..dc2afdb6e 100644 --- a/util/grub-mkpasswd-pbkdf2.c +++ b/util/grub-mkpasswd-pbkdf2.c @@ -248,7 +248,7 @@ main (int argc, char *argv[]) { FILE *f; size_t rd; - f = fopen ("/dev/random", "rb"); + f = fopen ("/dev/urandom", "rb"); if (!f) { memset (pass1, 0, strlen (pass1)); From 7fae005102ffab0148219a26df8aa80d2110627e Mon Sep 17 00:00:00 2001 From: Zach Date: Thu, 5 May 2011 12:18:00 +0200 Subject: [PATCH 539/869] Support 2010 Macbooks. * grub-core/loader/efi/appleloader.c (devpath_6): New variable. (devs): Add devpath_6. --- ChangeLog | 7 +++++++ grub-core/loader/efi/appleloader.c | 33 ++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/ChangeLog b/ChangeLog index 5dd39905e..81deaf96d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2011-05-05 Zach + + Support 2010 Macbooks. + + * grub-core/loader/efi/appleloader.c (devpath_6): New variable. + (devs): Add devpath_6. + 2011-05-05 Vladimir Serbinenko * util/grub-mkpasswd-pbkdf2.c (main): Use /dev/urandom and not diff --git a/grub-core/loader/efi/appleloader.c b/grub-core/loader/efi/appleloader.c index 847750dc0..d8ca4a7f3 100644 --- a/grub-core/loader/efi/appleloader.c +++ b/grub-core/loader/efi/appleloader.c @@ -229,6 +229,38 @@ static struct piwg_full_device_path devpath_5 = } }; +/* mid-2010 MB/MBP (NVidia chipset) */ +static struct piwg_full_device_path devpath_6 = +{ + .comp1 = + { + .header = { + .type = GRUB_EFI_HARDWARE_DEVICE_PATH_TYPE, + .subtype = GRUB_EFI_MEMORY_MAPPED_DEVICE_PATH_SUBTYPE, + .length = {sizeof (struct grub_efi_memory_mapped_device_path), 0} + }, + .memory_type = GRUB_EFI_MEMORY_MAPPED_IO, + .start_address = 0xffcc4000, + .end_address = 0xffffbfff + }, + .comp2 = + { + .header = { + .type = GRUB_EFI_MEDIA_DEVICE_PATH_TYPE, + .subtype = GRUB_EFI_PIWG_DEVICE_PATH_SUBTYPE, + .length = {sizeof (struct grub_efi_piwg_device_path), 0} + }, + .guid = {0x2B0585EB, 0xD8B8, 0x49A9, {0x8B, 0x8C, 0xE2, 0x1B, + 0x01, 0xAE, 0xF2, 0xB7}} + }, + .end = + { + .type = GRUB_EFI_END_DEVICE_PATH_TYPE, + .subtype = GRUB_EFI_END_ENTIRE_DEVICE_PATH_SUBTYPE, + .length = {sizeof (struct grub_efi_device_path), 0} + } +}; + struct devdata { char *model; @@ -242,6 +274,7 @@ struct devdata devs[] = {"MBP", (grub_efi_device_path_t *) &devpath_3}, {"MBA", (grub_efi_device_path_t *) &devpath_4}, {"MB NV", (grub_efi_device_path_t *) &devpath_5}, + {"MB NV2", (grub_efi_device_path_t *) &devpath_6}, {NULL, NULL}, }; From 072b5d315af49fc0ff4c6e31bc4f3a8f9e8a58ef Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Thu, 5 May 2011 13:34:03 +0200 Subject: [PATCH 540/869] * grub-core/loader/efi/appleloader.c (MAKE_PIWG_PATH): New macro. (devpath_1): Use MAKE_PIWG_PATH. (devpath_2): Likewise. (devpath_3): Likewise. (devpath_4): Likewise. (devpath_5): Likewise. (devpath_6): Likewise. The appleldr.mod was checked that to be binary identical to previous version. --- ChangeLog | 13 ++ grub-core/loader/efi/appleloader.c | 223 ++++++----------------------- 2 files changed, 56 insertions(+), 180 deletions(-) diff --git a/ChangeLog b/ChangeLog index 81deaf96d..540e171cc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2011-05-05 Vladimir Serbinenko + + * grub-core/loader/efi/appleloader.c (MAKE_PIWG_PATH): New macro. + (devpath_1): Use MAKE_PIWG_PATH. + (devpath_2): Likewise. + (devpath_3): Likewise. + (devpath_4): Likewise. + (devpath_5): Likewise. + (devpath_6): Likewise. + + The appleldr.mod was checked that to be binary identical to previous + version. + 2011-05-05 Zach Support 2010 Macbooks. diff --git a/grub-core/loader/efi/appleloader.c b/grub-core/loader/efi/appleloader.c index d8ca4a7f3..db57a573c 100644 --- a/grub-core/loader/efi/appleloader.c +++ b/grub-core/loader/efi/appleloader.c @@ -69,197 +69,60 @@ struct piwg_full_device_path struct grub_efi_device_path end; }; -/* early 2006 Core Duo / Core Solo models */ -static struct piwg_full_device_path devpath_1 = -{ - .comp1 = - { - .header = { - .type = GRUB_EFI_HARDWARE_DEVICE_PATH_TYPE, - .subtype = GRUB_EFI_MEMORY_MAPPED_DEVICE_PATH_SUBTYPE, - .length = {sizeof (struct grub_efi_memory_mapped_device_path), 0} - }, - .memory_type = GRUB_EFI_MEMORY_MAPPED_IO, - .start_address = 0xffe00000, - .end_address = 0xfff9ffff - }, - .comp2 = - { - .header = { - .type = GRUB_EFI_MEDIA_DEVICE_PATH_TYPE, - .subtype = GRUB_EFI_PIWG_DEVICE_PATH_SUBTYPE, - .length = {sizeof (struct grub_efi_piwg_device_path), 0} - }, - .guid = {0x2B0585EB, 0xD8B8, 0x49A9, {0x8B, 0x8C, 0xE2, 0x1B, - 0x01, 0xAE, 0xF2, 0xB7}} - }, - .end = - { - .type = GRUB_EFI_END_DEVICE_PATH_TYPE, - .subtype = GRUB_EFI_END_ENTIRE_DEVICE_PATH_SUBTYPE, - .length = {sizeof (struct grub_efi_device_path), 0} +#define MAKE_PIWG_PATH(st, en) \ + { \ + .comp1 = \ + { \ + .header = { \ + .type = GRUB_EFI_HARDWARE_DEVICE_PATH_TYPE, \ + .subtype = GRUB_EFI_MEMORY_MAPPED_DEVICE_PATH_SUBTYPE, \ + .length = {sizeof (struct grub_efi_memory_mapped_device_path), 0} \ + }, \ + .memory_type = GRUB_EFI_MEMORY_MAPPED_IO, \ + .start_address = st, \ + .end_address = en \ + }, \ + .comp2 = \ + { \ + .header = { \ + .type = GRUB_EFI_MEDIA_DEVICE_PATH_TYPE, \ + .subtype = GRUB_EFI_PIWG_DEVICE_PATH_SUBTYPE, \ + .length = {sizeof (struct grub_efi_piwg_device_path), 0} \ + }, \ + .guid = {0x2B0585EB, 0xD8B8, 0x49A9, {0x8B, 0x8C, 0xE2, 0x1B, \ + 0x01, 0xAE, 0xF2, 0xB7}} \ + }, \ + .end = \ + { \ + .type = GRUB_EFI_END_DEVICE_PATH_TYPE, \ + .subtype = GRUB_EFI_END_ENTIRE_DEVICE_PATH_SUBTYPE, \ + .length = {sizeof (struct grub_efi_device_path), 0} \ + } \ } -}; + +/* early 2006 Core Duo / Core Solo models */ +static struct piwg_full_device_path devpath_1 = MAKE_PIWG_PATH (0xffe00000, + 0xfff9ffff); /* mid-2006 Mac Pro (and probably other Core 2 models) */ -static struct piwg_full_device_path devpath_2 = -{ - .comp1 = - { - .header = { - .type = GRUB_EFI_HARDWARE_DEVICE_PATH_TYPE, - .subtype = GRUB_EFI_MEMORY_MAPPED_DEVICE_PATH_SUBTYPE, - .length = {sizeof (struct grub_efi_memory_mapped_device_path), 0} - }, - .memory_type = GRUB_EFI_MEMORY_MAPPED_IO, - .start_address = 0xffe00000, - .end_address = 0xfff7ffff - }, - .comp2 = - { - .header = { - .type = GRUB_EFI_MEDIA_DEVICE_PATH_TYPE, - .subtype = GRUB_EFI_PIWG_DEVICE_PATH_SUBTYPE, - .length = {sizeof (struct grub_efi_piwg_device_path), 0} - }, - .guid = {0x2B0585EB, 0xD8B8, 0x49A9, {0x8B, 0x8C, 0xE2, 0x1B, - 0x01, 0xAE, 0xF2, 0xB7}} - }, - .end = - { - .type = GRUB_EFI_END_DEVICE_PATH_TYPE, - .subtype = GRUB_EFI_END_ENTIRE_DEVICE_PATH_SUBTYPE, - .length = {sizeof (struct grub_efi_device_path), 0} - } -}; +static struct piwg_full_device_path devpath_2 = MAKE_PIWG_PATH (0xffe00000, + 0xfff7ffff); /* mid-2007 MBP ("Santa Rosa" based models) */ -static struct piwg_full_device_path devpath_3 = -{ - .comp1 = - { - .header = { - .type = GRUB_EFI_HARDWARE_DEVICE_PATH_TYPE, - .subtype = GRUB_EFI_MEMORY_MAPPED_DEVICE_PATH_SUBTYPE, - .length = {sizeof (struct grub_efi_memory_mapped_device_path), 0} - }, - .memory_type = GRUB_EFI_MEMORY_MAPPED_IO, - .start_address = 0xffe00000, - .end_address = 0xfff8ffff - }, - .comp2 = - { - .header = { - .type = GRUB_EFI_MEDIA_DEVICE_PATH_TYPE, - .subtype = GRUB_EFI_PIWG_DEVICE_PATH_SUBTYPE, - .length = {sizeof (struct grub_efi_piwg_device_path), 0} - }, - .guid = {0x2B0585EB, 0xD8B8, 0x49A9, {0x8B, 0x8C, 0xE2, 0x1B, - 0x01, 0xAE, 0xF2, 0xB7}} - }, - .end = - { - .type = GRUB_EFI_END_DEVICE_PATH_TYPE, - .subtype = GRUB_EFI_END_ENTIRE_DEVICE_PATH_SUBTYPE, - .length = {sizeof (struct grub_efi_device_path), 0} - } -}; +static struct piwg_full_device_path devpath_3 = MAKE_PIWG_PATH (0xffe00000, + 0xfff8ffff); /* early-2008 MBA */ -static struct piwg_full_device_path devpath_4 = -{ - .comp1 = - { - .header = { - .type = GRUB_EFI_HARDWARE_DEVICE_PATH_TYPE, - .subtype = GRUB_EFI_MEMORY_MAPPED_DEVICE_PATH_SUBTYPE, - .length = {sizeof (struct grub_efi_memory_mapped_device_path), 0} - }, - .memory_type = GRUB_EFI_MEMORY_MAPPED_IO, - .start_address = 0xffc00000, - .end_address = 0xfff8ffff - }, - .comp2 = - { - .header = { - .type = GRUB_EFI_MEDIA_DEVICE_PATH_TYPE, - .subtype = GRUB_EFI_PIWG_DEVICE_PATH_SUBTYPE, - .length = {sizeof (struct grub_efi_piwg_device_path), 0} - }, - .guid = {0x2B0585EB, 0xD8B8, 0x49A9, {0x8B, 0x8C, 0xE2, 0x1B, - 0x01, 0xAE, 0xF2, 0xB7}} - }, - .end = - { - .type = GRUB_EFI_END_DEVICE_PATH_TYPE, - .subtype = GRUB_EFI_END_ENTIRE_DEVICE_PATH_SUBTYPE, - .length = {sizeof (struct grub_efi_device_path), 0} - } -}; +static struct piwg_full_device_path devpath_4 = MAKE_PIWG_PATH (0xffc00000, + 0xfff8ffff); /* late-2008 MB/MBP (NVidia chipset) */ -static struct piwg_full_device_path devpath_5 = -{ - .comp1 = - { - .header = { - .type = GRUB_EFI_HARDWARE_DEVICE_PATH_TYPE, - .subtype = GRUB_EFI_MEMORY_MAPPED_DEVICE_PATH_SUBTYPE, - .length = {sizeof (struct grub_efi_memory_mapped_device_path), 0} - }, - .memory_type = GRUB_EFI_MEMORY_MAPPED_IO, - .start_address = 0xffcb4000, - .end_address = 0xffffbfff - }, - .comp2 = - { - .header = { - .type = GRUB_EFI_MEDIA_DEVICE_PATH_TYPE, - .subtype = GRUB_EFI_PIWG_DEVICE_PATH_SUBTYPE, - .length = {sizeof (struct grub_efi_piwg_device_path), 0} - }, - .guid = {0x2B0585EB, 0xD8B8, 0x49A9, {0x8B, 0x8C, 0xE2, 0x1B, - 0x01, 0xAE, 0xF2, 0xB7}} - }, - .end = - { - .type = GRUB_EFI_END_DEVICE_PATH_TYPE, - .subtype = GRUB_EFI_END_ENTIRE_DEVICE_PATH_SUBTYPE, - .length = {sizeof (struct grub_efi_device_path), 0} - } -}; +static struct piwg_full_device_path devpath_5 = MAKE_PIWG_PATH (0xffcb4000, + 0xffffbfff); /* mid-2010 MB/MBP (NVidia chipset) */ -static struct piwg_full_device_path devpath_6 = -{ - .comp1 = - { - .header = { - .type = GRUB_EFI_HARDWARE_DEVICE_PATH_TYPE, - .subtype = GRUB_EFI_MEMORY_MAPPED_DEVICE_PATH_SUBTYPE, - .length = {sizeof (struct grub_efi_memory_mapped_device_path), 0} - }, - .memory_type = GRUB_EFI_MEMORY_MAPPED_IO, - .start_address = 0xffcc4000, - .end_address = 0xffffbfff - }, - .comp2 = - { - .header = { - .type = GRUB_EFI_MEDIA_DEVICE_PATH_TYPE, - .subtype = GRUB_EFI_PIWG_DEVICE_PATH_SUBTYPE, - .length = {sizeof (struct grub_efi_piwg_device_path), 0} - }, - .guid = {0x2B0585EB, 0xD8B8, 0x49A9, {0x8B, 0x8C, 0xE2, 0x1B, - 0x01, 0xAE, 0xF2, 0xB7}} - }, - .end = - { - .type = GRUB_EFI_END_DEVICE_PATH_TYPE, - .subtype = GRUB_EFI_END_ENTIRE_DEVICE_PATH_SUBTYPE, - .length = {sizeof (struct grub_efi_device_path), 0} - } -}; +static struct piwg_full_device_path devpath_6 = MAKE_PIWG_PATH (0xffcc4000, + 0xffffbfff); struct devdata { From c5934345bea4070e56813c4064645240ff902f4a Mon Sep 17 00:00:00 2001 From: Manoel Rebelo Abranches Date: Fri, 6 May 2011 14:03:51 -0300 Subject: [PATCH 541/869] Free memory when removing packet. --- include/grub/net.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/grub/net.h b/include/grub/net.h index 37b258f36..59974b94f 100644 --- a/include/grub/net.h +++ b/include/grub/net.h @@ -178,6 +178,7 @@ grub_net_remove_packet (grub_net_packet_t *pkt) pkt->next->prev = pkt->prev; else pkt->up->last = pkt->prev; + grub_free (pkt); } typedef struct grub_net_app_protocol *grub_net_app_level_t; From 5452733f3505fcd1135c3705a9565365be60bfd5 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 8 May 2011 12:39:08 +0200 Subject: [PATCH 542/869] more or less functional ia64 grub-mkimage --- Makefile.util.def | 1 + grub-core/Makefile.core.def | 1 + grub-core/kern/dl.c | 2 + grub-core/kern/ia64/dl.c | 66 ++----- include/grub/dl.h | 12 +- util/grub-mkimage.c | 29 ++- util/grub-mkimagexx.c | 345 +++++++++++++++++++++++++++++++++--- 7 files changed, 358 insertions(+), 98 deletions(-) diff --git a/Makefile.util.def b/Makefile.util.def index c37cac965..df3b14138 100644 --- a/Makefile.util.def +++ b/Makefile.util.def @@ -98,6 +98,7 @@ library = { common = grub-core/script/main.c; common = grub-core/script/script.c; common = grub-core/script/argv.c; + common = grub-core/kern/ia64/dl_helper.c; }; program = { diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def index c21c38763..7bb51adfe 100644 --- a/grub-core/Makefile.core.def +++ b/grub-core/Makefile.core.def @@ -128,6 +128,7 @@ kernel = { ia64_efi = kern/ia64/efi/startup.S; ia64_efi = kern/ia64/efi/init.c; ia64_efi = kern/ia64/dl.c; + ia64_efi = kern/ia64/dl_helper.c; i386_pc = kern/i386/pc/init.c; i386_pc = kern/i386/pc/mmap.c; diff --git a/grub-core/kern/dl.c b/grub-core/kern/dl.c index f871b81a1..aa15cfa24 100644 --- a/grub-core/kern/dl.c +++ b/grub-core/kern/dl.c @@ -247,6 +247,8 @@ grub_dl_load_segments (grub_dl_t mod, const Elf_Ehdr *e) #ifdef __ia64__ grub_arch_dl_get_tramp_got_size (e, &tramp, &got); + tramp *= GRUB_IA64_DL_TRAMP_SIZE; + got *= sizeof (grub_uint64_t); tsize += ALIGN_UP (tramp, GRUB_ARCH_DL_TRAMP_ALIGN); if (talign < GRUB_ARCH_DL_TRAMP_ALIGN) talign = GRUB_ARCH_DL_TRAMP_ALIGN; diff --git a/grub-core/kern/ia64/dl.c b/grub-core/kern/ia64/dl.c index 9bbebcd2f..0d1e0d2e6 100644 --- a/grub-core/kern/ia64/dl.c +++ b/grub-core/kern/ia64/dl.c @@ -54,15 +54,18 @@ add_value_to_slot_20b (grub_addr_t addr, grub_uint32_t value) { case 0: p = (struct unaligned_uint32 *) ((addr & ~3ULL) + 2); - p->val = (((((p->val >> 2) & MASK20) + value) & MASK20) << 2) | (p->val & ~(MASK20 << 2)); + p->val = ((((((p->val >> 2) & MASK20) + value) & MASK20) << 2) + | (p->val & ~(MASK20 << 2))); break; case 1: p = (struct unaligned_uint32 *) ((grub_uint8_t *) (addr & ~3ULL) + 7); - p->val = (((((p->val >> 3) & MASK20) + value) & MASK20) << 3) | (p->val & ~(MASK20 << 3)); + p->val = ((((((p->val >> 3) & MASK20) + value) & MASK20) << 3) + | (p->val & ~(MASK20 << 3))); break; case 2: p = (struct unaligned_uint32 *) ((grub_uint8_t *) (addr & ~3ULL) + 12); - p->val = (((((p->val >> 4) & MASK20) + value) & MASK20) << 4) | (p->val & ~(MASK20 << 4)); + p->val = ((((((p->val >> 4) & MASK20) + value) & MASK20) << 4) + | (p->val & ~(MASK20 << 4))); break; } } @@ -137,6 +140,8 @@ struct ia64_trampoline static void make_trampoline (struct ia64_trampoline *tr, grub_uint64_t addr) { + COMPILE_TIME_ASSERT (sizeof (struct ia64_trampoline) + == GRUB_IA64_DL_TRAMP_SIZE); grub_memcpy (tr->nop, nopm, sizeof (tr->nop)); tr->addr_hi[0] = ((addr & 0xc00000) >> 16); tr->addr_hi[1] = (addr >> 24) & 0xff; @@ -146,60 +151,13 @@ make_trampoline (struct ia64_trampoline *tr, grub_uint64_t addr) tr->addr_hi[5] = (addr >> 56) & 0xff; tr->e0 = 0xe0; tr->addr_lo[0] = ((addr & 0x000f) << 4) | 0x01; - tr->addr_lo[1] = ((addr & 0x0070) >> 4) | ((addr & 0x070000) >> 11) | ((addr & 0x200000) >> 17); + tr->addr_lo[1] = (((addr & 0x0070) >> 4) | ((addr & 0x070000) >> 11) + | ((addr & 0x200000) >> 17)); tr->addr_lo[2] = ((addr & 0x1f80) >> 5) | ((addr & 0x180000) >> 19); tr->addr_lo[3] = ((addr & 0xe000) >> 13) | 0x60; grub_memcpy (tr->jump, jump, sizeof (tr->jump)); } -void -grub_arch_dl_get_tramp_got_size (const void *ehdr, grub_size_t *tramp, grub_size_t *got) -{ - const Elf_Ehdr *e = ehdr; - grub_size_t cntt = 0, cntg = 0;; - const Elf_Shdr *s; - Elf_Word entsize; - unsigned i; - - /* Find a symbol table. */ - for (i = 0, s = (Elf_Shdr *) ((char *) e + e->e_shoff); - i < e->e_shnum; - i++, s = (Elf_Shdr *) ((char *) s + e->e_shentsize)) - if (s->sh_type == SHT_SYMTAB) - break; - - if (i == e->e_shnum) - return; - - entsize = s->sh_entsize; - - for (i = 0, s = (Elf_Shdr *) ((char *) e + e->e_shoff); - i < e->e_shnum; - i++, s = (Elf_Shdr *) ((char *) s + e->e_shentsize)) - if (s->sh_type == SHT_RELA) - { - Elf_Rela *rel, *max; - - for (rel = (Elf_Rela *) ((char *) e + s->sh_offset), - max = rel + s->sh_size / s->sh_entsize; - rel < max; rel++) - switch (ELF_R_TYPE (rel->r_info)) - { - case R_IA64_PCREL21B: - cntt++; - break; - case R_IA64_LTOFF_FPTR22: - case R_IA64_LTOFF22X: - case R_IA64_LTOFF22: - cntg++; - break; - } - } - *tramp = cntt * sizeof (struct ia64_trampoline); - *got = cntg * sizeof (grub_uint64_t); -} - - /* Relocate symbols. */ grub_err_t grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr) @@ -279,7 +237,7 @@ grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr) } break; case R_IA64_SEGREL64LSB: - *(grub_uint64_t *) addr += value - rel->r_offset; + *(grub_uint64_t *) addr += value - (grub_addr_t) seg->addr; break; case R_IA64_FPTR64LSB: case R_IA64_DIR64LSB: @@ -296,8 +254,6 @@ grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr) case R_IA64_LTOFF22X: case R_IA64_LTOFF22: *gpptr = value; - if ((addr & 0xffff) == 0x4301) - grub_dprintf ("modules", "off = %lx\n", (grub_addr_t) gpptr - (grub_addr_t) gp); add_value_to_slot_21 (addr, (grub_addr_t) gpptr - (grub_addr_t) gp); gpptr++; break; diff --git a/include/grub/dl.h b/include/grub/dl.h index b45928a76..6646902d4 100644 --- a/include/grub/dl.h +++ b/include/grub/dl.h @@ -126,12 +126,18 @@ grub_err_t grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr); void grub_arch_dl_init_linker (void); #endif -#ifdef __ia64__ -void grub_arch_dl_get_tramp_got_size (const void *ehdr, grub_size_t *tramp, grub_size_t *got); +#define GRUB_IA64_DL_TRAMP_ALIGN 16 +#define GRUB_IA64_DL_TRAMP_SIZE 48 +#define GRUB_IA64_DL_GOT_ALIGN 16 +void +grub_ia64_dl_get_tramp_got_size (const void *ehdr, grub_size_t *tramp, + grub_size_t *got); + +#ifdef __ia64__ #define GRUB_ARCH_DL_TRAMP_ALIGN 16 #define GRUB_ARCH_DL_GOT_ALIGN 16 - +#define grub_arch_dl_get_tramp_got_size grub_ia64_dl_get_tramp_got_size #else #endif diff --git a/util/grub-mkimage.c b/util/grub-mkimage.c index 507a7a80d..9f4e2a61f 100644 --- a/util/grub-mkimage.c +++ b/util/grub-mkimage.c @@ -29,6 +29,7 @@ #include #include #include +#include #include #include @@ -89,6 +90,13 @@ struct image_target_desc grub_uint16_t pe_target; }; +#define EFI64_HEADER_SIZE ALIGN_UP (GRUB_PE32_MSDOS_STUB_SIZE \ + + GRUB_PE32_SIGNATURE_SIZE \ + + sizeof (struct grub_pe32_coff_header) \ + + sizeof (struct grub_pe64_optional_header) \ + + 4 * sizeof (struct grub_pe32_section_table), \ + GRUB_PE32_SECTION_ALIGNMENT) + struct image_target_desc image_targets[] = { { @@ -248,12 +256,7 @@ struct image_target_desc image_targets[] = .kernel_image_size = TARGET_NO_FIELD, .compressed_size = TARGET_NO_FIELD, .section_align = GRUB_PE32_SECTION_ALIGNMENT, - .vaddr_offset = ALIGN_UP (GRUB_PE32_MSDOS_STUB_SIZE - + GRUB_PE32_SIGNATURE_SIZE - + sizeof (struct grub_pe32_coff_header) - + sizeof (struct grub_pe64_optional_header) - + 4 * sizeof (struct grub_pe32_section_table), - GRUB_PE32_SECTION_ALIGNMENT), + .vaddr_offset = EFI64_HEADER_SIZE, .install_dos_part = TARGET_NO_FIELD, .install_bsd_part = TARGET_NO_FIELD, .pe_target = GRUB_PE32_MACHINE_X86_64, @@ -372,12 +375,7 @@ struct image_target_desc image_targets[] = .kernel_image_size = TARGET_NO_FIELD, .compressed_size = TARGET_NO_FIELD, .section_align = GRUB_PE32_SECTION_ALIGNMENT, - .vaddr_offset = ALIGN_UP (GRUB_PE32_MSDOS_STUB_SIZE - + GRUB_PE32_SIGNATURE_SIZE - + sizeof (struct grub_pe32_coff_header) - + sizeof (struct grub_pe64_optional_header) - + 4 * sizeof (struct grub_pe32_section_table), - GRUB_PE32_SECTION_ALIGNMENT), + .vaddr_offset = EFI64_HEADER_SIZE, .install_dos_part = TARGET_NO_FIELD, .install_bsd_part = TARGET_NO_FIELD, .pe_target = GRUB_PE32_MACHINE_IA64, @@ -930,12 +928,7 @@ generate_image (const char *dir, char *prefix, FILE *out, char *mods[], + 4 * sizeof (struct grub_pe32_section_table), GRUB_PE32_SECTION_ALIGNMENT); else - header_size = ALIGN_UP (GRUB_PE32_MSDOS_STUB_SIZE - + GRUB_PE32_SIGNATURE_SIZE - + sizeof (struct grub_pe32_coff_header) - + sizeof (struct grub_pe64_optional_header) - + 4 * sizeof (struct grub_pe32_section_table), - GRUB_PE32_SECTION_ALIGNMENT); + header_size = EFI64_HEADER_SIZE; reloc_addr = ALIGN_UP (header_size + core_size, image_target->section_align); diff --git a/util/grub-mkimagexx.c b/util/grub-mkimagexx.c index 20cbacf15..6f68bf1af 100644 --- a/util/grub-mkimagexx.c +++ b/util/grub-mkimagexx.c @@ -56,6 +56,7 @@ static Elf_Addr SUFFIX (relocate_symbols) (Elf_Ehdr *e, Elf_Shdr *sections, Elf_Shdr *symtab_section, Elf_Addr *section_addresses, Elf_Half section_entsize, Elf_Half num_sections, + void *jumpers, Elf_Addr jumpers_addr, struct image_target_desc *image_target) { Elf_Word symtab_size, sym_size, num_syms; @@ -65,6 +66,7 @@ SUFFIX (relocate_symbols) (Elf_Ehdr *e, Elf_Shdr *sections, Elf_Word i; Elf_Shdr *strtab_section; const char *strtab; + grub_uint64_t *jptr = jumpers; strtab_section = (Elf_Shdr *) ((char *) sections @@ -103,6 +105,16 @@ SUFFIX (relocate_symbols) (Elf_Ehdr *e, Elf_Shdr *sections, sym->st_value = (grub_target_to_host (sym->st_value) + section_addresses[index]); + + if (image_target->elf_target == EM_IA_64 && ELF_ST_TYPE (sym->st_info) + == STT_FUNC) + { + *jptr = sym->st_value; + sym->st_value = (char *) jptr - (char *) jumpers + jumpers_addr; + jptr++; + *jptr = 0; + jptr++; + } grub_util_info ("locating %s at 0x%x", name, sym->st_value, section_addresses[index]); if (! start_address) @@ -134,6 +146,152 @@ SUFFIX (get_target_address) (Elf_Ehdr *e, Elf_Shdr *s, Elf_Addr offset, return (Elf_Addr *) ((char *) e + grub_target_to_host32 (s->sh_offset) + offset); } +static Elf_Addr +SUFFIX (count_funcs) (Elf_Ehdr *e, Elf_Shdr *symtab_section, + struct image_target_desc *image_target) +{ + Elf_Word symtab_size, sym_size, num_syms; + Elf_Off symtab_offset; + Elf_Addr start_address = 0; + Elf_Sym *sym; + Elf_Word i; + int ret = 0; + + symtab_size = grub_target_to_host (symtab_section->sh_size); + sym_size = grub_target_to_host (symtab_section->sh_entsize); + symtab_offset = grub_target_to_host (symtab_section->sh_offset); + num_syms = symtab_size / sym_size; + + for (i = 0, sym = (Elf_Sym *) ((char *) e + symtab_offset); + i < num_syms; + i++, sym = (Elf_Sym *) ((char *) sym + sym_size)) + if (ELF_ST_TYPE (sym->st_info) == STT_FUNC) + ret++; + + return ret; +} + +#ifdef MKIMAGE_ELF64 +struct unaligned_uint32 +{ + grub_uint32_t val; +} __attribute__ ((packed)); + +#define MASK20 ((1 << 20) - 1) +#define MASK19 ((1 << 19) - 1) + +static void +add_value_to_slot_20b (grub_addr_t addr, grub_uint32_t value) +{ + struct unaligned_uint32 *p; + switch (addr & 3) + { + case 0: + p = (struct unaligned_uint32 *) ((addr & ~3ULL) + 2); + p->val = ((((((p->val >> 2) & MASK20) + value) & MASK20) << 2) + | (p->val & ~(MASK20 << 2))); + break; + case 1: + p = (struct unaligned_uint32 *) ((grub_uint8_t *) (addr & ~3ULL) + 7); + p->val = ((((((p->val >> 3) & MASK20) + value) & MASK20) << 3) + | (p->val & ~(MASK20 << 3))); + break; + case 2: + p = (struct unaligned_uint32 *) ((grub_uint8_t *) (addr & ~3ULL) + 12); + p->val = ((((((p->val >> 4) & MASK20) + value) & MASK20) << 4) + | (p->val & ~(MASK20 << 4))); + break; + } +} + +#define MASKF21 ( ((1 << 23) - 1) & ~((1 << 7) | (1 << 8)) ) + +static grub_uint32_t +add_value_to_slot_21_real (grub_uint32_t a, grub_uint32_t value) +{ + grub_uint32_t high, mid, low, c; + low = (a & 0x00007f); + mid = (a & 0x7fc000) >> 7; + high = (a & 0x003e00) << 7; + c = (low | mid | high) + value; + return (c & 0x7f) | ((c << 7) & 0x7fc000) | ((c >> 7) & 0x0003e00); //0x003e00 +} + +static void +add_value_to_slot_21 (grub_addr_t addr, grub_uint32_t value) +{ + struct unaligned_uint32 *p; + switch (addr & 3) + { + case 0: + p = (struct unaligned_uint32 *) ((addr & ~3ULL) + 2); + p->val = ((add_value_to_slot_21_real (((p->val >> 2) & MASKF21), value) & MASKF21) << 2) | (p->val & ~(MASKF21 << 2)); + break; + case 1: + p = (struct unaligned_uint32 *) ((grub_uint8_t *) (addr & ~3ULL) + 7); + p->val = ((add_value_to_slot_21_real (((p->val >> 3) & MASKF21), value) & MASKF21) << 3) | (p->val & ~(MASKF21 << 3)); + break; + case 2: + p = (struct unaligned_uint32 *) ((grub_uint8_t *) (addr & ~3ULL) + 12); + p->val = ((add_value_to_slot_21_real (((p->val >> 4) & MASKF21), value) & MASKF21) << 4) | (p->val & ~(MASKF21 << 4)); + break; + } +} + + +struct ia64_kernel_trampoline +{ + /* nop.m */ + grub_uint8_t nop[5]; + /* movl r15 = addr*/ + grub_uint8_t addr_hi[6]; + grub_uint8_t e0; + grub_uint8_t addr_lo[4]; + grub_uint8_t jump[0x20]; +}; + +static grub_uint8_t nopm[5] = + { + /* [MLX] nop.m 0x0 */ + 0x05, 0x00, 0x00, 0x00, 0x01 + }; + +static grub_uint8_t jump[0x20] = + { + /* [MMI] add r15=r15,r1;; */ + 0x0b, 0x78, 0x3c, 0x02, 0x00, 0x20, + /* ld8 r16=[r15],8 */ + 0x00, 0x41, 0x3c, 0x30, 0x28, 0xc0, + /* mov r14=r1;; */ + 0x01, 0x08, 0x00, 0x84, + /* [MIB] ld8 r1=[r15] */ + 0x11, 0x08, 0x00, 0x1e, 0x18, 0x10, + /* mov b6=r16 */ + 0x60, 0x80, 0x04, 0x80, 0x03, 0x00, + /* br.few b6;; */ + 0x60, 0x00, 0x80, 0x00 + }; + +static void +make_trampoline (struct ia64_kernel_trampoline *tr, grub_uint64_t addr) +{ + grub_memcpy (tr->nop, nopm, sizeof (tr->nop)); + tr->addr_hi[0] = ((addr & 0xc00000) >> 16); + tr->addr_hi[1] = (addr >> 24) & 0xff; + tr->addr_hi[2] = (addr >> 32) & 0xff; + tr->addr_hi[3] = (addr >> 40) & 0xff; + tr->addr_hi[4] = (addr >> 48) & 0xff; + tr->addr_hi[5] = (addr >> 56) & 0xff; + tr->e0 = 0xe0; + tr->addr_lo[0] = ((addr & 0x000f) << 4) | 0x01; + tr->addr_lo[1] = (((addr & 0x0070) >> 4) | ((addr & 0x070000) >> 11) + | ((addr & 0x200000) >> 17)); + tr->addr_lo[2] = ((addr & 0x1f80) >> 5) | ((addr & 0x180000) >> 19); + tr->addr_lo[3] = ((addr & 0xe000) >> 13) | 0x60; + grub_memcpy (tr->jump, jump, sizeof (tr->jump)); +} +#endif + /* Deal with relocation information. This function relocates addresses within the virtual address space starting from 0. So only relative addresses can be fully resolved. Absolute addresses must be relocated @@ -142,10 +300,15 @@ static void SUFFIX (relocate_addresses) (Elf_Ehdr *e, Elf_Shdr *sections, Elf_Addr *section_addresses, Elf_Half section_entsize, Elf_Half num_sections, - const char *strtab, struct image_target_desc *image_target) + const char *strtab, + char *pe_target, Elf_Addr tramp_off, + Elf_Addr got_off, + struct image_target_desc *image_target) { Elf_Half i; Elf_Shdr *s; + struct ia64_kernel_trampoline *tr = (void *) (pe_target + tramp_off); + grub_uint64_t *gpptr = (void *) (pe_target + got_off); for (i = 0, s = sections; i < num_sections; @@ -274,15 +437,69 @@ SUFFIX (relocate_addresses) (Elf_Ehdr *e, Elf_Shdr *sections, break; } break; +#ifdef MKIMAGE_ELF64 case EM_IA_64: switch (ELF_R_TYPE (info)) { + case R_IA64_PCREL21B: + { + grub_uint64_t noff; + make_trampoline (tr, addend + sym_addr); + noff = ((char *) tr - (char *) pe_target + - target_section_addr - (offset & ~3) + - image_target->vaddr_offset) >> 4; + tr++; + if (noff & ~MASK19) + grub_util_error ("trampoline offset too big (%lx)", + noff); + add_value_to_slot_20b ((grub_addr_t) target, noff); + } + break; + + case R_IA64_LTOFF_FPTR22: + case R_IA64_LTOFF22X: + case R_IA64_LTOFF22: + *gpptr = grub_host_to_target64 (addend + sym_addr); + add_value_to_slot_21 ((grub_addr_t) target, + (char *) gpptr - (char *) pe_target); + gpptr++; + break; + + case R_IA64_GPREL22: + add_value_to_slot_21 ((grub_addr_t) target, + addend + sym_addr); + break; + case R_IA64_PCREL64LSB: + *target = grub_host_to_target64 (grub_target_to_host64 (*target) + + addend + sym_addr + - target_section_addr - offset + - image_target->vaddr_offset); + break; + + case R_IA64_SEGREL64LSB: + *target = grub_host_to_target64 (grub_target_to_host64 (*target) + + addend + sym_addr - target_section_addr); + break; + case R_IA64_DIR64LSB: + case R_IA64_FPTR64LSB: + *target = grub_host_to_target64 (grub_target_to_host64 (*target) + + addend + sym_addr); + grub_util_info ("relocating a direct entry to 0x%" + PRIxGRUB_UINT64_T " at the offset 0x%x", + *target, offset); + break; + + /* We treat LTOFF22X as LTOFF22, so we can ignore LDXMOV. */ + case R_IA64_LDXMOV: + break; + default: grub_util_error ("unknown relocation type 0x%x", - ELF_R_TYPE (info)); + ELF_R_TYPE (info)); break; } break; +#endif default: grub_util_error ("unknown architecture type %d", image_target->elf_target); @@ -329,7 +546,7 @@ SUFFIX (add_fixup_entry) (struct fixup_block_list **cblock, grub_uint16_t type, b->block_size += 2; } } - else if (b->block_size & (8 - 1)) + else while (b->block_size & (8 - 1)) { /* If not aligned with a 32-bit boundary, add a padding entry. */ @@ -391,9 +608,11 @@ static Elf_Addr SUFFIX (make_reloc_section) (Elf_Ehdr *e, void **out, Elf_Addr *section_addresses, Elf_Shdr *sections, Elf_Half section_entsize, Elf_Half num_sections, - const char *strtab, struct image_target_desc *image_target) + const char *strtab, + Elf_Addr jumpers, grub_size_t njumpers, + struct image_target_desc *image_target) { - Elf_Half i; + unsigned i; Elf_Shdr *s; struct fixup_block_list *lst, *lst0; Elf_Addr current_address = 0; @@ -401,8 +620,7 @@ SUFFIX (make_reloc_section) (Elf_Ehdr *e, void **out, lst = lst0 = xmalloc (sizeof (*lst) + 2 * 0x1000); memset (lst, 0, sizeof (*lst) + 2 * 0x1000); - for (i = 0, s = sections; - i < num_sections; + for (i = 0, s = sections; i < num_sections; i++, s = (Elf_Shdr *) ((char *) s + section_entsize)) if ((s->sh_type == grub_cpu_to_le32 (SHT_REL)) || (s->sh_type == grub_cpu_to_le32 (SHT_RELA))) @@ -470,12 +688,56 @@ SUFFIX (make_reloc_section) (Elf_Ehdr *e, void **out, image_target); } break; + case EM_IA_64: + switch (ELF_R_TYPE (info)) + { + case R_IA64_PCREL64LSB: + case R_IA64_LDXMOV: + case R_IA64_PCREL21B: + case R_IA64_LTOFF_FPTR22: + case R_IA64_LTOFF22X: + case R_IA64_LTOFF22: + case R_IA64_GPREL22: + case R_IA64_SEGREL64LSB: + break; + + case R_IA64_FPTR64LSB: + case R_IA64_DIR64LSB: +#if 1 + { + Elf_Addr addr; + + addr = section_address + offset; + grub_util_info ("adding a relocation entry for 0x%llx", addr); + current_address + = SUFFIX (add_fixup_entry) (&lst, + GRUB_PE32_REL_BASED_DIR64, + addr, + 0, current_address, + image_target); + } +#endif + break; + default: + grub_util_error ("unknown relocation type 0x%x", + ELF_R_TYPE (info)); + break; + } + break; default: grub_util_error ("unknown machine type 0x%x", image_target->elf_target); } } } + if (image_target->elf_target == EM_IA_64) + for (i = 0; i < njumpers; i++) + current_address = SUFFIX (add_fixup_entry) (&lst, + GRUB_PE32_REL_BASED_DIR64, + jumpers + 8 * i, + 0, current_address, + image_target); + current_address = SUFFIX (add_fixup_entry) (&lst, 0, 0, 1, current_address, image_target); { @@ -637,7 +899,10 @@ SUFFIX (load_image) (const char *kernel_path, grub_size_t *exec_size, Elf_Off section_offset; Elf_Half section_entsize; grub_size_t kernel_size; + grub_size_t ia64jmp_off = 0, ia64_toff = 0, ia64_got_off = 0; + unsigned ia64jmpnum = 0; Elf_Shdr *symtab_section; + grub_size_t got = 0; *start = 0; @@ -716,23 +981,31 @@ SUFFIX (load_image) (const char *kernel_path, grub_size_t *exec_size, break; } +#ifdef MKIMAGE_ELF64 + if (image_target->elf_target == EM_IA_64) + { + grub_size_t tramp; + + *kernel_sz = ALIGN_UP (*kernel_sz, 16); + + grub_ia64_dl_get_tramp_got_size (e, &tramp, &got); + tramp *= sizeof (struct ia64_kernel_trampoline); + + ia64_toff = *kernel_sz; + *kernel_sz += ALIGN_UP (tramp, 16); + + ia64jmp_off = *kernel_sz; + ia64jmpnum = SUFFIX (count_funcs) (e, symtab_section, + image_target); + *kernel_sz += 16 * ia64jmpnum; + + ia64_got_off = *kernel_sz; + *kernel_sz += ALIGN_UP (got * sizeof (grub_uint64_t), 16); + } +#endif + if (! symtab_section) grub_util_error ("no symbol table"); - - *start = SUFFIX (relocate_symbols) (e, sections, symtab_section, - section_vaddresses, section_entsize, - num_sections, image_target); - if (*start == 0) - grub_util_error ("start symbol is not defined"); - - /* Resolve addresses in the virtual address space. */ - SUFFIX (relocate_addresses) (e, sections, section_addresses, section_entsize, - num_sections, strtab, image_target); - - *reloc_size = SUFFIX (make_reloc_section) (e, reloc_section, - section_vaddresses, sections, - section_entsize, num_sections, - strtab, image_target); } else { @@ -742,6 +1015,34 @@ SUFFIX (load_image) (const char *kernel_path, grub_size_t *exec_size, out_img = xmalloc (*kernel_sz + total_module_size); + if (image_target->id == IMAGE_EFI) + { + *start = SUFFIX (relocate_symbols) (e, sections, symtab_section, + section_vaddresses, section_entsize, + num_sections, + (char *) out_img + ia64jmp_off, + ia64jmp_off + + image_target->vaddr_offset, + image_target); + if (*start == 0) + grub_util_error ("start symbol is not defined"); + + /* Resolve addresses in the virtual address space. */ + SUFFIX (relocate_addresses) (e, sections, section_addresses, + section_entsize, + num_sections, strtab, + out_img, ia64_toff, ia64_got_off, + image_target); + + *reloc_size = SUFFIX (make_reloc_section) (e, reloc_section, + section_vaddresses, sections, + section_entsize, num_sections, + strtab, ia64jmp_off + + image_target->vaddr_offset, + 2 * ia64jmpnum + got, + image_target); + } + for (i = 0, s = sections; i < num_sections; i++, s = (Elf_Shdr *) ((char *) s + section_entsize)) From ad6e5cf25fb3cc4a42dcf1eeb2e555ac9300cf91 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 8 May 2011 12:42:08 +0200 Subject: [PATCH 543/869] add missing file --- grub-core/kern/ia64/dl_helper.c | 73 +++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 grub-core/kern/ia64/dl_helper.c diff --git a/grub-core/kern/ia64/dl_helper.c b/grub-core/kern/ia64/dl_helper.c new file mode 100644 index 000000000..9503c49ea --- /dev/null +++ b/grub-core/kern/ia64/dl_helper.c @@ -0,0 +1,73 @@ +/* dl.c - arch-dependent part of loadable module support */ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2002,2004,2005,2007,2009 Free Software Foundation, Inc. + * + * GRUB is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see . + */ + +#include +#include +#include +#include +#include + +void +grub_ia64_dl_get_tramp_got_size (const void *ehdr, grub_size_t *tramp, + grub_size_t *got) +{ + const Elf_Ehdr *e = ehdr; + grub_size_t cntt = 0, cntg = 0;; + const Elf_Shdr *s; + Elf_Word entsize; + unsigned i; + + /* Find a symbol table. */ + for (i = 0, s = (Elf_Shdr *) ((char *) e + e->e_shoff); + i < e->e_shnum; + i++, s = (Elf_Shdr *) ((char *) s + e->e_shentsize)) + if (s->sh_type == SHT_SYMTAB) + break; + + if (i == e->e_shnum) + return; + + entsize = s->sh_entsize; + + for (i = 0, s = (Elf_Shdr *) ((char *) e + e->e_shoff); + i < e->e_shnum; + i++, s = (Elf_Shdr *) ((char *) s + e->e_shentsize)) + if (s->sh_type == SHT_RELA) + { + Elf_Rela *rel, *max; + + for (rel = (Elf_Rela *) ((char *) e + s->sh_offset), + max = rel + s->sh_size / s->sh_entsize; + rel < max; rel++) + switch (ELF_R_TYPE (rel->r_info)) + { + case R_IA64_PCREL21B: + cntt++; + break; + case R_IA64_LTOFF_FPTR22: + case R_IA64_LTOFF22X: + case R_IA64_LTOFF22: + cntg++; + break; + } + } + *tramp = cntt; + *got = cntg; +} + From a988e7aa63948b2e624c1aff8cb63f32d0cee406 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 8 May 2011 14:33:30 +0200 Subject: [PATCH 544/869] Fix 2 incorrect vaddr_offsets --- util/grub-mkimagexx.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/util/grub-mkimagexx.c b/util/grub-mkimagexx.c index 6f68bf1af..9bfb5de75 100644 --- a/util/grub-mkimagexx.c +++ b/util/grub-mkimagexx.c @@ -446,8 +446,7 @@ SUFFIX (relocate_addresses) (Elf_Ehdr *e, Elf_Shdr *sections, grub_uint64_t noff; make_trampoline (tr, addend + sym_addr); noff = ((char *) tr - (char *) pe_target - - target_section_addr - (offset & ~3) - - image_target->vaddr_offset) >> 4; + - target_section_addr - (offset & ~3)) >> 4; tr++; if (noff & ~MASK19) grub_util_error ("trampoline offset too big (%lx)", @@ -461,7 +460,8 @@ SUFFIX (relocate_addresses) (Elf_Ehdr *e, Elf_Shdr *sections, case R_IA64_LTOFF22: *gpptr = grub_host_to_target64 (addend + sym_addr); add_value_to_slot_21 ((grub_addr_t) target, - (char *) gpptr - (char *) pe_target); + (char *) gpptr - (char *) pe_target + + image_target->vaddr_offset); gpptr++; break; From 7216a1bff3a513549525787b67bd365e8f788569 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 8 May 2011 17:05:47 +0200 Subject: [PATCH 545/869] Set EFI ticks to 1000Hz simplifying much of the code and avoiding cotsly division --- grub-core/Makefile.core.def | 1 - grub-core/kern/efi/efi.c | 16 +++++++++++----- include/grub/efi/time.h | 3 +-- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def index 7bb51adfe..bc7ce5fbe 100644 --- a/grub-core/Makefile.core.def +++ b/grub-core/Makefile.core.def @@ -83,7 +83,6 @@ kernel = { noemu_nodist = symlist.c; i386_pc = kern/generic/rtc_get_time_ms.c; - efi = kern/generic/rtc_get_time_ms.c; i386_qemu = kern/generic/rtc_get_time_ms.c; i386_coreboot = kern/generic/rtc_get_time_ms.c; i386_multiboot = kern/generic/rtc_get_time_ms.c; diff --git a/grub-core/kern/efi/efi.c b/grub-core/kern/efi/efi.c index fa1d0c730..c95058733 100644 --- a/grub-core/kern/efi/efi.c +++ b/grub-core/kern/efi/efi.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -193,8 +194,8 @@ grub_efi_set_virtual_address_map (grub_efi_uintn_t memory_map_size, return grub_error (GRUB_ERR_IO, "set_virtual_address_map failed"); } -grub_uint32_t -grub_get_rtc (void) +grub_uint64_t +grub_rtc_get_time_ms (void) { grub_efi_time_t time; grub_efi_runtime_services_t *r; @@ -204,9 +205,14 @@ grub_get_rtc (void) /* What is possible in this case? */ return 0; - return (((time.minute * 60 + time.second) * 1000 - + time.nanosecond / 1000000) - * GRUB_TICKS_PER_SECOND / 1000); + return ((time.minute * 60 + time.second) * 1000 + + time.nanosecond / 1000000); +} + +grub_uint32_t +grub_get_rtc (void) +{ + return grub_rtc_get_time_ms (); } /* Search the mods section from the PE32/PE32+ image. This code uses diff --git a/include/grub/efi/time.h b/include/grub/efi/time.h index 540f6fc04..51b337309 100644 --- a/include/grub/efi/time.h +++ b/include/grub/efi/time.h @@ -21,8 +21,7 @@ #include -/* This is destined to overflow when one hour passes by. */ -#define GRUB_TICKS_PER_SECOND ((1UL << 31) / 60 / 60 * 2) +#define GRUB_TICKS_PER_SECOND 1000 /* Return the real time in ticks. */ grub_uint32_t EXPORT_FUNC (grub_get_rtc) (void); From fa610088bafb704ae3a0bfdc5d2040542687ae14 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 8 May 2011 17:06:28 +0200 Subject: [PATCH 546/869] Add missing time installation --- grub-core/kern/ia64/efi/init.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/grub-core/kern/ia64/efi/init.c b/grub-core/kern/ia64/efi/init.c index 13a81a66e..6bb4219ac 100644 --- a/grub-core/kern/ia64/efi/init.c +++ b/grub-core/kern/ia64/efi/init.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -30,6 +31,7 @@ void grub_machine_init (void) { grub_efi_init (); + grub_install_get_time_ms (grub_rtc_get_time_ms); } void From 44748f71c043e069dbbd7c3d960102df94c8a505 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 8 May 2011 17:06:56 +0200 Subject: [PATCH 547/869] Add explicit byt 0 to workaround a problem with assembler --- grub-core/kern/ia64/efi/startup.S | 1 + 1 file changed, 1 insertion(+) diff --git a/grub-core/kern/ia64/efi/startup.S b/grub-core/kern/ia64/efi/startup.S index fcaf4e189..b5e26a204 100644 --- a/grub-core/kern/ia64/efi/startup.S +++ b/grub-core/kern/ia64/efi/startup.S @@ -45,6 +45,7 @@ _start: . = _start + GRUB_KERNEL_MACHINE_PREFIX VARIABLE(grub_prefix) + .byte 0 /* to be filled by grub-mkimage */ /* From 2679b7249be860ad19d8d9fa4e0c882e2eed207a Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 8 May 2011 17:07:40 +0200 Subject: [PATCH 548/869] Fix LTOFF relocation to functions (needed for trampolines) --- grub-core/kern/ia64/dl.c | 4 +++- util/grub-mkimagexx.c | 13 ++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/grub-core/kern/ia64/dl.c b/grub-core/kern/ia64/dl.c index 0d1e0d2e6..3904f73b7 100644 --- a/grub-core/kern/ia64/dl.c +++ b/grub-core/kern/ia64/dl.c @@ -250,9 +250,11 @@ grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr) add_value_to_slot_21 (addr, value - (grub_addr_t) gp); break; - case R_IA64_LTOFF_FPTR22: case R_IA64_LTOFF22X: case R_IA64_LTOFF22: + if (ELF_ST_TYPE (sym->st_info) == STT_FUNC) + value = *(grub_uint64_t *) sym->st_value + rel->r_addend; + case R_IA64_LTOFF_FPTR22: *gpptr = value; add_value_to_slot_21 (addr, (grub_addr_t) gpptr - (grub_addr_t) gp); gpptr++; diff --git a/util/grub-mkimagexx.c b/util/grub-mkimagexx.c index 9bfb5de75..352291070 100644 --- a/util/grub-mkimagexx.c +++ b/util/grub-mkimagexx.c @@ -455,9 +455,20 @@ SUFFIX (relocate_addresses) (Elf_Ehdr *e, Elf_Shdr *sections, } break; - case R_IA64_LTOFF_FPTR22: case R_IA64_LTOFF22X: case R_IA64_LTOFF22: + { + Elf_Sym *sym; + + sym = (Elf_Sym *) ((char *) e + + grub_target_to_host32 (symtab_section->sh_offset) + + ELF_R_SYM (info) * grub_target_to_host32 (symtab_section->sh_entsize)); + if (ELF_ST_TYPE (sym->st_info) == STT_FUNC) + sym_addr = grub_target_to_host64 (*(grub_uint64_t *) (pe_target + + sym->st_value + - image_target->vaddr_offset)); + } + case R_IA64_LTOFF_FPTR22: *gpptr = grub_host_to_target64 (addend + sym_addr); add_value_to_slot_21 ((grub_addr_t) target, (char *) gpptr - (char *) pe_target From 5a0baa09f29fc1ccd5227e00aea8d409024fddfa Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 8 May 2011 18:28:25 +0200 Subject: [PATCH 549/869] Remove now useless LD script --- grub-core/kern/ia64/efi/elf_ia64_efi.lds | 84 ------------------------ 1 file changed, 84 deletions(-) delete mode 100644 grub-core/kern/ia64/efi/elf_ia64_efi.lds diff --git a/grub-core/kern/ia64/efi/elf_ia64_efi.lds b/grub-core/kern/ia64/efi/elf_ia64_efi.lds deleted file mode 100644 index b6889d4af..000000000 --- a/grub-core/kern/ia64/efi/elf_ia64_efi.lds +++ /dev/null @@ -1,84 +0,0 @@ -/* - * GRUB -- GRand Unified Bootloader - * Copyright (C) 2008 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 . - */ -OUTPUT_FORMAT("elf64-ia64-little") -OUTPUT_ARCH(ia64) -ENTRY(_start) -SECTIONS -{ - . = 0x240; - .text : - { - *(.text) - *(.text.*) - *(.rodata) - *(.rodata.*) - /* Reserve space for the entry point descriptor. */ - . = ALIGN(16); - QUAD(0) - QUAD(0) - } - . = ALIGN(0x20); - .got : - { - *(.got.plt) - *(.got) - . = ALIGN(0x10); - } - .opd : - { - *(.opd) - } - .sdata : - { - *(.srodata) - *(.sdata) - *(.sbss) - *(.scommon) - . = ALIGN(0x10); - } - .data : - { - *(.data*) - *(.dynbss) - *(.bss) - *(COMMON) - . = ALIGN(0x10); - } - .dynamic : { *(.dynamic) } - - . = ALIGN(4096); - .interp : { *(.interp) } - .plt : { *(.plt) } - .rela : - { - *(.rela.text*) - *(.rela.data*) - *(.rela.sdata) - *(.rela.got) - } - .hash : { *(.hash) } - .dynsym : { *(.dynsym) } - .dynstr : { *(.dynstr) } - /DISCARD/ : - { - *(.IA_64.unwind*) - *(.IA64.unwind*) - *(.moddeps) - *(.modname) - } -} From 7b58e65f2423311b2224cf54d347a0c33eac09bc Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 8 May 2011 18:29:37 +0200 Subject: [PATCH 550/869] track function symbols --- grub-core/gensymlist.sh | 10 +++++----- grub-core/kern/dl.c | 22 +++++++++++++--------- include/grub/dl.h | 2 +- include/grub/elf.h | 3 +++ 4 files changed, 22 insertions(+), 15 deletions(-) diff --git a/grub-core/gensymlist.sh b/grub-core/gensymlist.sh index 0ab56e9cb..5f402ea87 100644 --- a/grub-core/gensymlist.sh +++ b/grub-core/gensymlist.sh @@ -47,7 +47,7 @@ grub_register_exported_symbols (void) EOF cat < sizeof (tab[0])); for (p = tab; p->name; p++) - grub_dl_register_symbol (p->name, p->addr, 0); + grub_dl_register_symbol (p->name, p->addr, p->isfunc, 0); } EOF diff --git a/grub-core/kern/dl.c b/grub-core/kern/dl.c index aa15cfa24..6353b0d59 100644 --- a/grub-core/kern/dl.c +++ b/grub-core/kern/dl.c @@ -90,6 +90,7 @@ struct grub_symbol struct grub_symbol *next; const char *name; void *addr; + int isfunc; grub_dl_t mod; /* The module to which this symbol belongs. */ }; typedef struct grub_symbol *grub_symbol_t; @@ -114,21 +115,22 @@ grub_symbol_hash (const char *s) /* Resolve the symbol name NAME and return the address. Return NULL, if not found. */ -static void * +static grub_symbol_t grub_dl_resolve_symbol (const char *name) { grub_symbol_t sym; for (sym = grub_symtab[grub_symbol_hash (name)]; sym; sym = sym->next) if (grub_strcmp (sym->name, name) == 0) - return sym->addr; + return sym; return 0; } /* Register a symbol with the name NAME and the address ADDR. */ grub_err_t -grub_dl_register_symbol (const char *name, void *addr, grub_dl_t mod) +grub_dl_register_symbol (const char *name, void *addr, int isfunc, + grub_dl_t mod) { grub_symbol_t sym; unsigned k; @@ -151,6 +153,7 @@ grub_dl_register_symbol (const char *name, void *addr, grub_dl_t mod) sym->addr = addr; sym->mod = mod; + sym->isfunc = isfunc; k = grub_symbol_hash (name); sym->next = grub_symtab[k]; @@ -371,17 +374,20 @@ grub_dl_resolve_symbols (grub_dl_t mod, Elf_Ehdr *e) /* Resolve a global symbol. */ if (sym->st_name != 0 && sym->st_shndx == 0) { - sym->st_value = (Elf_Addr) grub_dl_resolve_symbol (name); - if (! sym->st_value) + grub_symbol_t nsym = grub_dl_resolve_symbol (name); + if (! nsym) return grub_error (GRUB_ERR_BAD_MODULE, "symbol not found: `%s'", name); + sym->st_value = (Elf_Addr) nsym->addr; + if (nsym->isfunc) + sym->st_info = ELF_ST_INFO (bind, STT_FUNC); } else { sym->st_value += (Elf_Addr) grub_dl_get_section_addr (mod, sym->st_shndx); if (bind != STB_LOCAL) - if (grub_dl_register_symbol (name, (void *) sym->st_value, mod)) + if (grub_dl_register_symbol (name, (void *) sym->st_value, 0, mod)) return grub_errno; } break; @@ -398,13 +404,11 @@ grub_dl_resolve_symbols (grub_dl_t mod, Elf_Ehdr *e) return grub_errno; desc[0] = (void *) sym->st_value; desc[1] = mod->base; - if (grub_dl_register_symbol (name, (void *) desc, mod)) - return grub_errno; sym->st_value = (grub_addr_t) desc; } #endif if (bind != STB_LOCAL) - if (grub_dl_register_symbol (name, (void *) sym->st_value, mod)) + if (grub_dl_register_symbol (name, (void *) sym->st_value, 1, mod)) return grub_errno; if (grub_strcmp (name, "grub_mod_init") == 0) mod->init = (void (*) (grub_dl_t)) sym->st_value; diff --git a/include/grub/dl.h b/include/grub/dl.h index 6646902d4..319ed5745 100644 --- a/include/grub/dl.h +++ b/include/grub/dl.h @@ -116,7 +116,7 @@ extern grub_dl_t EXPORT_VAR(grub_dl_head); grub_dl_t EXPORT_FUNC(grub_dl_get) (const char *name); grub_err_t grub_dl_register_symbol (const char *name, void *addr, - grub_dl_t mod); + int isfunc, grub_dl_t mod); grub_err_t grub_arch_dl_check_header (void *ehdr); grub_err_t grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr); diff --git a/include/grub/elf.h b/include/grub/elf.h index b9401f241..a02b90238 100644 --- a/include/grub/elf.h +++ b/include/grub/elf.h @@ -2348,6 +2348,8 @@ typedef Elf32_Xword Elf_Xword; #define ELF_ST_BIND(val) ELF32_ST_BIND(val) #define ELF_ST_TYPE(val) ELF32_ST_TYPE(val) +#define ELF_ST_INFO(a,b) ELF32_ST_INFO(a,b) + #define ELF_R_SYM(val) ELF32_R_SYM(val) #define ELF_R_TYPE(val) ELF32_R_TYPE(val) #define ELF_R_INFO(sym, type) ELF32_R_INFO(sym, type) @@ -2369,6 +2371,7 @@ typedef Elf64_Xword Elf_Xword; #define ELF_ST_BIND(val) ELF64_ST_BIND (val) #define ELF_ST_TYPE(val) ELF64_ST_TYPE (val) +#define ELF_ST_INFO(a,b) ELF64_ST_INFO(a,b) #define ELF_R_SYM(val) ELF64_R_SYM(val) #define ELF_R_TYPE(val) ELF64_R_TYPE(val) #define ELF_R_INFO(sym, type) ELF64_R_INFO(sym, type) From b868b5105219f202cf158e01198d1b7504f050c8 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 8 May 2011 20:06:03 +0200 Subject: [PATCH 551/869] remove ia64.moved From 485e1572467c5b0cf29086572e7a40da53292146 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 8 May 2011 20:16:25 +0200 Subject: [PATCH 552/869] Remove 2 useless directories From ea75312f31fb83300d1f00b9630b05fd79bb7650 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 9 May 2011 16:27:09 +0200 Subject: [PATCH 553/869] * util/grub-mkimage.c (main): Explicitely flush and sync the output before closing to ensure that it will be readable by grub-setup. --- ChangeLog | 5 +++++ util/grub-mkimage.c | 2 ++ 2 files changed, 7 insertions(+) diff --git a/ChangeLog b/ChangeLog index 540e171cc..bec788b3c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-05-09 Vladimir Serbinenko + + * util/grub-mkimage.c (main): Explicitely flush and sync the output + before closing to ensure that it will be readable by grub-setup. + 2011-05-05 Vladimir Serbinenko * grub-core/loader/efi/appleloader.c (MAKE_PIWG_PATH): New macro. diff --git a/util/grub-mkimage.c b/util/grub-mkimage.c index 2ba351596..b71fb0420 100644 --- a/util/grub-mkimage.c +++ b/util/grub-mkimage.c @@ -1609,6 +1609,8 @@ main (int argc, char *argv[]) argv + optind, memdisk, config, image_target, note, comp); + fflush (fp); + fsync (fileno (fp)); fclose (fp); if (dir) From 157effb745b4e520327bde2ac3de131f766da095 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 9 May 2011 18:46:51 +0200 Subject: [PATCH 554/869] * grub-core/kern/emu/hostdisk.c (linux_find_partition): Prevent possible overflow. --- ChangeLog | 5 +++++ grub-core/kern/emu/hostdisk.c | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index bec788b3c..532a3a3b8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-05-09 Vladimir Serbinenko + + * grub-core/kern/emu/hostdisk.c (linux_find_partition): Prevent possible + overflow. + 2011-05-09 Vladimir Serbinenko * util/grub-mkimage.c (main): Explicitely flush and sync the output diff --git a/grub-core/kern/emu/hostdisk.c b/grub-core/kern/emu/hostdisk.c index 63bca37ee..085048e86 100644 --- a/grub-core/kern/emu/hostdisk.c +++ b/grub-core/kern/emu/hostdisk.c @@ -550,7 +550,7 @@ struct linux_partition_cache struct linux_partition_cache *linux_partition_cache_list; static int -linux_find_partition (char *dev, unsigned long sector) +linux_find_partition (char *dev, grub_disk_addr_t sector) { size_t len = strlen (dev); const char *format; From fa68d99c4552d02be40c56b787141e340021a4ca Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 9 May 2011 18:48:50 +0200 Subject: [PATCH 555/869] * grub-core/kern/emu/hostdisk.c (open_device): Set data->fd to -1 if openning fails. Reported by: Mark Korenberg. --- ChangeLog | 6 ++++++ grub-core/kern/emu/hostdisk.c | 2 ++ 2 files changed, 8 insertions(+) diff --git a/ChangeLog b/ChangeLog index 532a3a3b8..7c924a505 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2011-05-09 Vladimir Serbinenko + + * grub-core/kern/emu/hostdisk.c (open_device): Set data->fd to -1 if + openning fails. + Reported by: Mark Korenberg. + 2011-05-09 Vladimir Serbinenko * grub-core/kern/emu/hostdisk.c (linux_find_partition): Prevent possible diff --git a/grub-core/kern/emu/hostdisk.c b/grub-core/kern/emu/hostdisk.c index 085048e86..92882838f 100644 --- a/grub-core/kern/emu/hostdisk.c +++ b/grub-core/kern/emu/hostdisk.c @@ -678,6 +678,7 @@ open_device (const grub_disk_t disk, grub_disk_addr_t sector, int flags) } close (data->fd); + data->fd = -1; } /* Open the partition. */ @@ -736,6 +737,7 @@ open_device (const grub_disk_t disk, grub_disk_addr_t sector, int flags) #endif } close (data->fd); + data->fd = -1; } fd = open (map[disk->id].device, flags); From d8ce9995012629e60c91ed24df01720871558c4f Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 9 May 2011 18:50:25 +0200 Subject: [PATCH 556/869] Fix surname spelling in Changelog --- ChangeLog | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 7c924a505..6da178a9f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -348,7 +348,7 @@ (grub_util_biosdisk_open): Don't apply ioctl on non-disk devices. (open_device) Likewise. (grub_util_biosdisk_close): Likewise. - Reported by: Mark Korenberger. + Reported by: Mark Korenberg. 2011-04-10 Alexander Kurtz From dd94a3df9deb3d8fad0950bd3ce180b5a1c262e6 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 9 May 2011 18:59:35 +0200 Subject: [PATCH 557/869] * grub-core/kern/emu/hostdisk.c (linux_find_partition): Don't abort on first non-existant partition. --- ChangeLog | 5 +++++ grub-core/kern/emu/hostdisk.c | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 6da178a9f..5136a915e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-05-09 Vladimir Serbinenko + + * grub-core/kern/emu/hostdisk.c (linux_find_partition): Don't abort + on first non-existant partition. + 2011-05-09 Vladimir Serbinenko * grub-core/kern/emu/hostdisk.c (open_device): Set data->fd to -1 if diff --git a/grub-core/kern/emu/hostdisk.c b/grub-core/kern/emu/hostdisk.c index 92882838f..feb2a8ff5 100644 --- a/grub-core/kern/emu/hostdisk.c +++ b/grub-core/kern/emu/hostdisk.c @@ -596,7 +596,7 @@ linux_find_partition (char *dev, grub_disk_addr_t sector) fd = open (real_dev, O_RDONLY); if (fd == -1) - return 0; + continue; close (fd); start = find_partition_start (real_dev); From 9c9bfc6de9c1c397e857506ed6410e1f1c379b8d Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 9 May 2011 19:33:03 +0200 Subject: [PATCH 558/869] * grub-core/term/at_keyboard.c (fetch_key): Make a printf on unknown key into a dprintf. --- ChangeLog | 5 +++++ grub-core/term/at_keyboard.c | 8 ++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5136a915e..9baad1f9c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-05-09 Vladimir Serbinenko + + * grub-core/term/at_keyboard.c (fetch_key): Make a printf on + unknown key into a dprintf. + 2011-05-09 Vladimir Serbinenko * grub-core/kern/emu/hostdisk.c (linux_find_partition): Don't abort diff --git a/grub-core/term/at_keyboard.c b/grub-core/term/at_keyboard.c index 210ac21cc..56aa7275e 100644 --- a/grub-core/term/at_keyboard.c +++ b/grub-core/term/at_keyboard.c @@ -431,11 +431,11 @@ fetch_key (int *is_break) if (!ret) { if (was_ext) - grub_printf ("Unknown key 0xe0+0x%02x from set %d\n", - at_key, current_set); + grub_dprintf ("atkeyb", "Unknown key 0xe0+0x%02x from set %d\n", + at_key, current_set); else - grub_printf ("Unknown key 0x%02x from set %d\n", - at_key, current_set); + grub_dprintf ("atkeyb", "Unknown key 0x%02x from set %d\n", + at_key, current_set); return -1; } return ret; From 52856af26237d211bc413f36b1573d267badad37 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Tue, 10 May 2011 09:14:41 +0200 Subject: [PATCH 559/869] * grub-core/loader/efi/chainloader.c (grub_chainloader_unload): Set file_path to 0 for surety. (grub_chainloader_boot): Set exit_data to NULL. Unset the loader once done. (grub_cmd_chainloader): Fix confusing error message if file is empty. --- ChangeLog | 8 ++++++++ grub-core/loader/efi/chainloader.c | 10 ++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9baad1f9c..ed0bc71d6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2011-05-09 Vladimir Serbinenko + + * grub-core/loader/efi/chainloader.c (grub_chainloader_unload): Set + file_path to 0 for surety. + (grub_chainloader_boot): Set exit_data to NULL. + Unset the loader once done. + (grub_cmd_chainloader): Fix confusing error message if file is empty. + 2011-05-09 Vladimir Serbinenko * grub-core/term/at_keyboard.c (fetch_key): Make a printf on diff --git a/grub-core/loader/efi/chainloader.c b/grub-core/loader/efi/chainloader.c index 869b64ced..5dd5adab2 100644 --- a/grub-core/loader/efi/chainloader.c +++ b/grub-core/loader/efi/chainloader.c @@ -57,6 +57,7 @@ grub_chainloader_unload (void) grub_free (file_path); grub_free (cmdline); cmdline = 0; + file_path = 0; grub_dl_unref (my_mod); return GRUB_ERR_NONE; @@ -68,7 +69,7 @@ grub_chainloader_boot (void) grub_efi_boot_services_t *b; grub_efi_status_t status; grub_efi_uintn_t exit_data_size; - grub_efi_char16_t *exit_data; + grub_efi_char16_t *exit_data = NULL; b = grub_efi_system_table->boot_services; status = efi_call_3 (b->start_image, image_handle, &exit_data_size, &exit_data); @@ -95,7 +96,7 @@ grub_chainloader_boot (void) if (exit_data) efi_call_1 (b->free_pool, exit_data); - grub_chainloader_unload (); + grub_loader_unset (); return grub_errno; } @@ -238,6 +239,11 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)), grub_efi_print_device_path (file_path); size = grub_file_size (file); + if (!size) + { + grub_error (GRUB_ERR_BAD_OS, "file is empty"); + goto fail; + } pages = (((grub_efi_uintn_t) size + ((1 << 12) - 1)) >> 12); status = efi_call_4 (b->allocate_pages, GRUB_EFI_ALLOCATE_ANY_PAGES, From 56dbe7b4855d9aa6dc45d0cf5a8a03c28696f864 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Tue, 10 May 2011 10:40:22 +0200 Subject: [PATCH 560/869] * util/grub.d/10_linux.in: Correctly handle the Linux in root. --- ChangeLog | 4 ++++ util/grub.d/10_linux.in | 14 +++++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index ed0bc71d6..d36d3441f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2011-05-10 Vladimir Serbinenko + + * util/grub.d/10_linux.in: Correctly handle the Linux in root. + 2011-05-09 Vladimir Serbinenko * grub-core/loader/efi/chainloader.c (grub_chainloader_unload): Set diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in index 1dbcad90c..3c3a2a5d5 100644 --- a/util/grub.d/10_linux.in +++ b/util/grub.d/10_linux.in @@ -98,10 +98,17 @@ EOF EOF fi - if [ -z "${prepare_boot_cache}" ]; then - prepare_boot_cache="$(prepare_grub_to_access_device ${GRUB_DEVICE_BOOT} | sed -e "s/^/\t/")" + if [ x$dirname = x/ ]; then + if [ -z "${prepare_root_cache}" ]; then + prepare_root_cache="$(prepare_grub_to_access_device ${GRUB_DEVICE} | sed -e "s/^/\t/")" + fi + printf '%s\n' "${prepare_root_cache}" + else + if [ -z "${prepare_boot_cache}" ]; then + prepare_boot_cache="$(prepare_grub_to_access_device ${GRUB_DEVICE_BOOT} | sed -e "s/^/\t/")" + fi + printf '%s\n' "${prepare_boot_cache}" fi - printf '%s\n' "${prepare_boot_cache}" message="$(gettext_printf "Loading Linux %s ..." ${version})" cat << EOF echo '$message' @@ -131,6 +138,7 @@ case x`uname -m` in esac prepare_boot_cache= +prepare_root_cache= while [ "x$list" != "x" ] ; do linux=`version_find_latest $list` From 4f7386025b3bc0e5da39e79062aaef02a924a86a Mon Sep 17 00:00:00 2001 From: Manoel Rebelo Abranches Date: Tue, 10 May 2011 09:28:45 -0300 Subject: [PATCH 561/869] Correct expected argument numbers in del addr command. --- grub-core/net/net.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/grub-core/net/net.c b/grub-core/net/net.c index 636aaefaf..48fb350d2 100644 --- a/grub-core/net/net.c +++ b/grub-core/net/net.c @@ -200,7 +200,7 @@ grub_cmd_deladdr (struct grub_command *cmd __attribute__ ((unused)), { struct grub_net_network_level_interface *inter; - if (argc != 4) + if (argc != 1) return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("one argument expected")); FOR_NET_NETWORK_LEVEL_INTERFACES (inter) From 1893017d440b967cb977888ad1fbc4f4cf2df9a4 Mon Sep 17 00:00:00 2001 From: Manoel Rebelo Abranches Date: Tue, 10 May 2011 09:30:26 -0300 Subject: [PATCH 562/869] Mark file as not easily seekable on net open. --- grub-core/net/net.c | 1 + 1 file changed, 1 insertion(+) diff --git a/grub-core/net/net.c b/grub-core/net/net.c index 48fb350d2..cdeaa5a32 100644 --- a/grub-core/net/net.c +++ b/grub-core/net/net.c @@ -609,6 +609,7 @@ grub_net_file_open_real (struct grub_file *file, const char *name) if ((err = file->device->net->protocol->open (file,name))) goto fail; + file->not_easily_seekable = 1; return GRUB_ERR_NONE; fail: From 4d6374ba7855abc9726d838258ec8093bc1238f1 Mon Sep 17 00:00:00 2001 From: Manoel Rebelo Abranches Date: Tue, 10 May 2011 09:32:38 -0300 Subject: [PATCH 563/869] Implement file close in network tranference. Stop receiving packets from card on error. --- grub-core/kern/file.c | 8 ++++++-- grub-core/net/net.c | 26 +++++++++++++++++++++++--- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/grub-core/kern/file.c b/grub-core/kern/file.c index 6e7ed0e57..2b3e9d689 100644 --- a/grub-core/kern/file.c +++ b/grub-core/kern/file.c @@ -27,6 +27,7 @@ grub_ssize_t (*grub_file_net_read) (grub_file_t file, void *buf, grub_size_t len) = NULL; grub_err_t (*grub_file_net_open) (struct grub_file *file, const char *name) = NULL; +grub_err_t (*grub_file_net_close) (grub_file_t file) = NULL; grub_err_t (*grub_file_net_seek) (struct grub_file *file, grub_off_t offset) = NULL; grub_file_filter_t grub_file_filters_all[GRUB_FILE_FILTER_MAX]; @@ -176,8 +177,11 @@ grub_err_t grub_file_close (grub_file_t file) { if (file->device->net) - return grub_errno; - + { + grub_file_net_close (file); + return grub_errno; + } + if (file->fs->close) (file->fs->close) (file); diff --git a/grub-core/net/net.c b/grub-core/net/net.c index cdeaa5a32..6ccf20725 100644 --- a/grub-core/net/net.c +++ b/grub-core/net/net.c @@ -619,18 +619,35 @@ fail: } +static grub_err_t +grub_net_file_close_real (grub_file_t file) +{ + grub_net_socket_t sock = file->device->net->socket; + while (sock->packs->first) + { + grub_netbuff_free (sock->packs->first->nb); + grub_net_remove_packet (sock->packs->first); + } + grub_net_socket_unregister (sock); + grub_free (sock); + return GRUB_ERR_NONE; + +} + static grub_err_t receive_packets (struct grub_net_card *card) { /* Maybe should be better have a fixed number of packets for each card and just mark them as used and not used. */ struct grub_net_buff *nb; + grub_err_t err; nb = grub_netbuff_alloc (1500); if (!nb) return grub_errno; - card->driver->recv (card, nb); - return GRUB_ERR_NONE; + if ((err = card->driver->recv (card, nb)) != GRUB_ERR_NONE) + grub_netbuff_free (nb); + return err; } void @@ -642,7 +659,8 @@ grub_net_pool_cards (unsigned time) { start_time = grub_get_time_ms (); while( (grub_get_time_ms () - start_time) < time) - receive_packets (card); + if( receive_packets (card) != GRUB_ERR_NONE) + break; } } @@ -1018,6 +1036,7 @@ GRUB_MOD_INIT(net) grub_net_open = grub_net_open_real; grub_file_net_open = grub_net_file_open_real; + grub_file_net_close = grub_net_file_close_real; grub_file_net_read = grub_net_read_real; grub_file_net_seek = grub_net_seek_real; } @@ -1034,4 +1053,5 @@ GRUB_MOD_FINI(net) grub_net_open = NULL; grub_file_net_read = NULL; grub_file_net_open = NULL; + grub_file_net_close = NULL; } From a5184d629a4411f8c74eeb1b244523ddddf1512e Mon Sep 17 00:00:00 2001 From: Manoel Rebelo Abranches Date: Tue, 10 May 2011 09:45:57 -0300 Subject: [PATCH 564/869] Prevente a bootp packet to be sent on open. --- grub-core/net/drivers/ieee1275/ofnet.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/grub-core/net/drivers/ieee1275/ofnet.c b/grub-core/net/drivers/ieee1275/ofnet.c index 10de81bc7..ce7ab32a8 100644 --- a/grub-core/net/drivers/ieee1275/ofnet.c +++ b/grub-core/net/drivers/ieee1275/ofnet.c @@ -1,17 +1,23 @@ #include #include #include +#include #include +#include static grub_err_t card_open (struct grub_net_card *dev) { int status; struct grub_ofnetcard_data *data = dev->data; - status = grub_ieee1275_open (data->path,&(data->handle)); + char path[grub_strlen(data->path) + grub_strlen(":speed=auto,duplex=auto,1.1.1.1,dummy,1.1.1.1,1.1.1.1,5,5,1.1.1.1,512") + 1]; + /* The full string will prevent a bootp packet to be sent. Just put some valid ip in there. */ + grub_snprintf(path,sizeof(path),"%s%s",data->path,":speed=auto,duplex=auto,1.1.1.1,dummy,1.1.1.1,1.1.1.1,5,5,1.1.1.1,512"); + status = grub_ieee1275_open (path,&(data->handle)); if (status) - return grub_error (GRUB_ERR_IO, "couldn't open network card"); + return grub_error (GRUB_ERR_IO, "Couldn't open network card."); + return GRUB_ERR_NONE; } From 0f231af8ae44b6e4efe6b25794db21fbfd270718 Mon Sep 17 00:00:00 2001 From: Manoel Rebelo Abranches Date: Tue, 10 May 2011 09:50:18 -0300 Subject: [PATCH 565/869] Implement timeout when receiving packets. --- grub-core/net/drivers/ieee1275/ofnet.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/grub-core/net/drivers/ieee1275/ofnet.c b/grub-core/net/drivers/ieee1275/ofnet.c index ce7ab32a8..a7b66261c 100644 --- a/grub-core/net/drivers/ieee1275/ofnet.c +++ b/grub-core/net/drivers/ieee1275/ofnet.c @@ -42,24 +42,29 @@ send_card_buffer (struct grub_net_card *dev, struct grub_net_buff *pack) pack->tail - pack->data, &actual); if (status) - return grub_error (GRUB_ERR_IO, "couldn't send network packet"); + return grub_error (GRUB_ERR_IO, "Couldn't send network packet."); return GRUB_ERR_NONE; } static grub_err_t -get_card_packet (struct grub_net_card *dev, struct grub_net_buff *pack) +get_card_packet (struct grub_net_card *dev, struct grub_net_buff *nb) { int actual, rc; struct grub_ofnetcard_data *data = dev->data; - grub_netbuff_clear(pack); + grub_uint64_t start_time; + grub_netbuff_clear (nb); + start_time = grub_get_time_ms (); do - rc = grub_ieee1275_read (data->handle, pack->data, 1500, &actual); - while (actual <= 0 || rc < 0); - grub_netbuff_put (pack, actual); - - return GRUB_ERR_NONE; + rc = grub_ieee1275_read (data->handle, nb->data, data->mtu, &actual); + while ((actual <= 0 || rc < 0) && (grub_get_time_ms () - start_time < 200)); + if (actual) + { + grub_netbuff_put (nb, actual); + return grub_net_recv_ethernet_packet (nb); + } + return GRUB_ERR_TIMEOUT; } static struct grub_net_card_driver ofdriver = From 70c52f3e248a67ad809c1309095b59cfff9d6628 Mon Sep 17 00:00:00 2001 From: Manoel Rebelo Abranches Date: Tue, 10 May 2011 09:54:32 -0300 Subject: [PATCH 566/869] Remove cards with no associated driver. --- grub-core/net/drivers/ieee1275/ofnet.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/grub-core/net/drivers/ieee1275/ofnet.c b/grub-core/net/drivers/ieee1275/ofnet.c index a7b66261c..e33622fe2 100644 --- a/grub-core/net/drivers/ieee1275/ofnet.c +++ b/grub-core/net/drivers/ieee1275/ofnet.c @@ -148,10 +148,12 @@ void grub_ofnet_findcards (void) lla.type = GRUB_NET_LINK_LEVEL_PROTOCOL_ETHERNET; card->default_address = lla; + card->driver = NULL; card->data = ofdata; card->flags = 0; card->name = grub_xasprintf("eth%d",i++); // grub_strdup (alias->name); - grub_net_card_register (card); + grub_net_card_register (card); + return 0; } return 0; } @@ -192,19 +194,24 @@ void grub_ofnet_probecards (void) net.ipv4.masksize = 24; grub_net_add_route ("bootp-router", net, inter); } - grub_free (bootp_pckt); break; - } + } } } + grub_free (bootp_pckt); + } GRUB_MOD_INIT (ofnet) { + struct grub_net_card *card; grub_getbootp = grub_getbootp_real; grub_net_card_driver_register (&ofdriver); grub_ofnet_findcards (); grub_ofnet_probecards (); + FOR_NET_CARDS (card) + if (card->driver == NULL) + grub_net_card_unregister (card); } GRUB_MOD_FINI (ofnet) From 36e2782dba154140c30ba77dabf67cea2df02719 Mon Sep 17 00:00:00 2001 From: Manoel Rebelo Abranches Date: Tue, 10 May 2011 09:55:20 -0300 Subject: [PATCH 567/869] Only setup network in the card we booted from. --- grub-core/net/drivers/ieee1275/ofnet.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/grub-core/net/drivers/ieee1275/ofnet.c b/grub-core/net/drivers/ieee1275/ofnet.c index e33622fe2..4067e36cf 100644 --- a/grub-core/net/drivers/ieee1275/ofnet.c +++ b/grub-core/net/drivers/ieee1275/ofnet.c @@ -171,6 +171,7 @@ void grub_ofnet_probecards (void) grub_bootp_t bootp_pckt; grub_net_network_level_address_t addr; grub_net_network_level_netaddress_t net; + bootp_pckt = grub_getbootp (); /* Assign correspondent driver for each device. */ FOR_NET_CARDS (card) @@ -180,8 +181,7 @@ void grub_ofnet_probecards (void) if (driver->init(card) == GRUB_ERR_NONE) { card->driver = driver; - bootp_pckt = grub_getbootp (); - if (bootp_pckt) + if (bootp_pckt && grub_memcmp(bootp_pckt->chaddr,card->default_address.mac,6) == 0) { addr.type = GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4; addr.ipv4 = bootp_pckt->yiaddr; From 0696f08f9238087edf5c1f1b91779f7515e7aeb5 Mon Sep 17 00:00:00 2001 From: Manoel Rebelo Abranches Date: Tue, 10 May 2011 14:07:20 -0300 Subject: [PATCH 568/869] Prevente error in broken cards by limiting data size. --- grub-core/net/tftp.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/grub-core/net/tftp.c b/grub-core/net/tftp.c index cafb30585..6cc281085 100644 --- a/grub-core/net/tftp.c +++ b/grub-core/net/tftp.c @@ -126,8 +126,12 @@ tftp_receive (grub_net_socket_t sock, struct grub_net_buff *nb) if (grub_be_to_cpu16 (tftph->u.data.block) == data->block + 1) { data->block++; - if (nb->tail - nb->data < 1024) + unsigned size = nb->tail - nb->data; + if (size < 1024) sock->status = 2; + /* Prevent garbage in broken cards. */ + if (size > 1024) + grub_netbuff_unput (nb, size - 1024); } else grub_netbuff_clear(nb); From 31b5172bbd3cfa83f0cd9d83fce18a21e2796048 Mon Sep 17 00:00:00 2001 From: Manoel Rebelo Abranches Date: Tue, 10 May 2011 14:07:54 -0300 Subject: [PATCH 569/869] Implement close in TFTP --- grub-core/net/tftp.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/grub-core/net/tftp.c b/grub-core/net/tftp.c index 6cc281085..13bd87d15 100644 --- a/grub-core/net/tftp.c +++ b/grub-core/net/tftp.c @@ -157,7 +157,8 @@ tftp_receive (grub_net_socket_t sock, struct grub_net_buff *nb) static grub_err_t tftp_close (struct grub_file *file __attribute__ ((unused))) { - return 0; + grub_free (file->device->net->socket->data); + return GRUB_ERR_NONE; } static struct grub_net_app_protocol grub_tftp_protocol = From 8db3b0eca9704c93fde8e1b0d41741f2299cb2b3 Mon Sep 17 00:00:00 2001 From: Manoel Rebelo Abranches Date: Tue, 10 May 2011 14:08:18 -0300 Subject: [PATCH 570/869] Remove unused file --- include/grub/net/disknet.h | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 include/grub/net/disknet.h diff --git a/include/grub/net/disknet.h b/include/grub/net/disknet.h deleted file mode 100644 index 59aa2a320..000000000 --- a/include/grub/net/disknet.h +++ /dev/null @@ -1,5 +0,0 @@ -#ifndef GRUB_DISKNET_HEADER -#define GRUB_DISKNET_HEADER 1 - void grub_disknet_init(void); - void grub_disknet_fini(void); -#endif /* ! GRUB_NET_HEADER */ From d8123bfb54e92aff473edaac87b535cb81e1f778 Mon Sep 17 00:00:00 2001 From: "Manoel R. Abranches" Date: Thu, 12 May 2011 13:20:43 -0300 Subject: [PATCH 571/869] Correct some compile erros. --- grub-core/Makefile.core.def | 2 +- grub-core/kern/ieee1275/openfw.c | 1 - grub-core/net/drivers/ieee1275/ofnet.c | 1 + include/grub/net.h | 4 +--- 4 files changed, 3 insertions(+), 5 deletions(-) diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def index e242d8ece..e1e1623e6 100644 --- a/grub-core/Makefile.core.def +++ b/grub-core/Makefile.core.def @@ -1503,7 +1503,7 @@ module = { module = { name = emunet; emu = net/drivers/emu/emunet.c; - enable = ieee1275; + enable = emu; }; module = { diff --git a/grub-core/kern/ieee1275/openfw.c b/grub-core/kern/ieee1275/openfw.c index fed4f7e76..3473fe362 100644 --- a/grub-core/kern/ieee1275/openfw.c +++ b/grub-core/kern/ieee1275/openfw.c @@ -25,7 +25,6 @@ #include #include #include -#include #include grub_bootp_t (*grub_getbootp) (void); diff --git a/grub-core/net/drivers/ieee1275/ofnet.c b/grub-core/net/drivers/ieee1275/ofnet.c index 4067e36cf..44738c67a 100644 --- a/grub-core/net/drivers/ieee1275/ofnet.c +++ b/grub-core/net/drivers/ieee1275/ofnet.c @@ -1,4 +1,5 @@ #include +#include #include #include #include diff --git a/include/grub/net.h b/include/grub/net.h index 59974b94f..cb6db06d8 100644 --- a/include/grub/net.h +++ b/include/grub/net.h @@ -434,7 +434,5 @@ grub_net_send_ip_packet (struct grub_net_network_level_interface *inf, void grub_net_pool_cards (unsigned time); -void -hwaddr_to_str (const grub_net_link_level_address_t *addr, char *str); - +extern grub_err_t (*EXPORT_VAR (grub_file_net_close)) (grub_file_t file); #endif /* ! GRUB_NET_HEADER */ From 48ac061ab6f4d685a1c93af59a0c366d3721a84d Mon Sep 17 00:00:00 2001 From: "Manoel R. Abranches" Date: Thu, 12 May 2011 15:40:54 -0300 Subject: [PATCH 572/869] Prevent "incompatible license" error. --- grub-core/net/drivers/ieee1275/ofnet.c | 2 ++ grub-core/net/net.c | 2 ++ grub-core/net/tftp.c | 2 ++ 3 files changed, 6 insertions(+) diff --git a/grub-core/net/drivers/ieee1275/ofnet.c b/grub-core/net/drivers/ieee1275/ofnet.c index 44738c67a..cb3882ceb 100644 --- a/grub-core/net/drivers/ieee1275/ofnet.c +++ b/grub-core/net/drivers/ieee1275/ofnet.c @@ -6,6 +6,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + static grub_err_t card_open (struct grub_net_card *dev) { diff --git a/grub-core/net/net.c b/grub-core/net/net.c index 6ccf20725..be5279c99 100644 --- a/grub-core/net/net.c +++ b/grub-core/net/net.c @@ -27,6 +27,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + struct grub_net_route { struct grub_net_route *next; diff --git a/grub-core/net/tftp.c b/grub-core/net/tftp.c index 13bd87d15..278f6ed14 100644 --- a/grub-core/net/tftp.c +++ b/grub-core/net/tftp.c @@ -9,6 +9,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + static grub_err_t tftp_open (struct grub_file *file, const char *filename) { From 9b44fecaa65643896bfd95fc76a5a782b802e416 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 13 May 2011 15:17:02 +0200 Subject: [PATCH 573/869] * grub-core/kern/mips/dl.c (grub_arch_dl_relocate_symbols): Handle R_MIPS_JALR since it's used by newer compiler. --- ChangeLog | 5 +++++ grub-core/kern/mips/dl.c | 2 ++ 2 files changed, 7 insertions(+) diff --git a/ChangeLog b/ChangeLog index d36d3441f..944fcb4ab 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-05-13 Vladimir Serbinenko + + * grub-core/kern/mips/dl.c (grub_arch_dl_relocate_symbols): Handle + R_MIPS_JALR since it's used by newer compiler. + 2011-05-10 Vladimir Serbinenko * util/grub.d/10_linux.in: Correctly handle the Linux in root. diff --git a/grub-core/kern/mips/dl.c b/grub-core/kern/mips/dl.c index 485955e7f..e17e9f30b 100644 --- a/grub-core/kern/mips/dl.c +++ b/grub-core/kern/mips/dl.c @@ -213,6 +213,8 @@ grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr) = sizeof (grub_uint32_t) * (gpptr - gp); gpptr++; break; + case R_MIPS_JALR: + break; default: { grub_free (gp); From a298aa046c528b8c4a5a73fb5dd92d24bdd453f6 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 13 May 2011 15:20:16 +0200 Subject: [PATCH 574/869] * grub-core/boot/mips/startup_raw.S: Use jalr rather than bal to call grub_decompress_core since later would fail if grub_decompress_core is too far. --- ChangeLog | 6 ++++++ grub-core/boot/mips/startup_raw.S | 6 ++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 944fcb4ab..d1a1d6f05 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2011-05-13 Vladimir Serbinenko + + * grub-core/boot/mips/startup_raw.S: Use jalr rather than bal to call + grub_decompress_core since later would fail if grub_decompress_core + is too far. + 2011-05-13 Vladimir Serbinenko * grub-core/kern/mips/dl.c (grub_arch_dl_relocate_symbols): Handle diff --git a/grub-core/boot/mips/startup_raw.S b/grub-core/boot/mips/startup_raw.S index c41ce8257..2e874e251 100644 --- a/grub-core/boot/mips/startup_raw.S +++ b/grub-core/boot/mips/startup_raw.S @@ -170,9 +170,11 @@ argdone: */ move $s6, $a3 - lui $sp, %hi(_start - 256) + lui $t0, %hi(EXT_C(grub_decompress_core)) + addiu $t0, $t0, %lo(EXT_C(grub_decompress_core)) - bal EXT_C(grub_decompress_core) + lui $sp, %hi(_start - 256) + jalr $t0 addiu $sp, $sp, %lo(_start - 256) move $a0, $s1 From 60ddfad3dab5c5eb479227d287f83ee66f67ebe4 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 13 May 2011 15:35:06 +0200 Subject: [PATCH 575/869] * grub-core/boot/mips/startup_raw.S: Flush cache after loading decompressor. --- ChangeLog | 5 +++++ grub-core/boot/mips/startup_raw.S | 7 +++++++ 2 files changed, 12 insertions(+) diff --git a/ChangeLog b/ChangeLog index d1a1d6f05..ede161faf 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-05-13 Vladimir Serbinenko + + * grub-core/boot/mips/startup_raw.S: Flush cache after loading + decompressor. + 2011-05-13 Vladimir Serbinenko * grub-core/boot/mips/startup_raw.S: Use jalr rather than bal to call diff --git a/grub-core/boot/mips/startup_raw.S b/grub-core/boot/mips/startup_raw.S index 2e874e251..6ba04c12f 100644 --- a/grub-core/boot/mips/startup_raw.S +++ b/grub-core/boot/mips/startup_raw.S @@ -150,6 +150,13 @@ argdone: b 1b addiu $t1, $t1, 1 2: + lui $a0, %hi(base) + addiu $a0, $a0, %lo(base) + lui $a1, %hi(_end) + addiu $a1, %lo(_end) + subu $a1,$a1,$a0 + +#include "../../kern/mips/cache_flush.S" /* Decompress the payload. */ lui $a0, %hi(__bss_start) From 11d86592b7bec1c7ffa746bb1bf384b3cfa7953b Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 13 May 2011 15:38:42 +0200 Subject: [PATCH 576/869] Adjust mips/dl.c for bigendian --- grub-core/kern/mips/dl.c | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/grub-core/kern/mips/dl.c b/grub-core/kern/mips/dl.c index e17e9f30b..e4ce12157 100644 --- a/grub-core/kern/mips/dl.c +++ b/grub-core/kern/mips/dl.c @@ -34,7 +34,7 @@ grub_arch_dl_check_header (void *ehdr) Elf_Ehdr *e = ehdr; /* Check the magic numbers. */ -#ifdef WORDS_BIGENDIAN +#ifdef GRUB_CPU_WORDS_BIGENDIAN if (e->e_ident[EI_CLASS] != ELFCLASS32 || e->e_ident[EI_DATA] != ELFDATA2MSB || e->e_machine != EM_MIPS) @@ -144,14 +144,14 @@ grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr) rel < max; rel++) { - Elf_Word *addr; + grub_uint8_t *addr; Elf_Sym *sym; if (seg->size < rel->r_offset) return grub_error (GRUB_ERR_BAD_MODULE, "reloc offset is out of the segment"); - addr = (Elf_Word *) ((char *) seg->addr + rel->r_offset); + addr = (grub_uint8_t *) ((char *) seg->addr + rel->r_offset); sym = (Elf_Sym *) ((char *) mod->symtab + entsize * ELF_R_SYM (rel->r_info)); if (sym->st_value == (grub_addr_t) &__gnu_local_gp_dummy) @@ -163,7 +163,11 @@ grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr) { grub_uint32_t value; Elf_Rel *rel2; - + +#ifdef GRUB_CPU_WORDS_BIGENDIAN + addr += 2; +#endif + /* Handle partner lo16 relocation. Lower part is treated as signed. Hence add 0x8000 to compensate. */ @@ -175,13 +179,20 @@ grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr) && ELF_R_TYPE (rel2->r_info) == R_MIPS_LO16) { value += *(grub_int16_t *) - ((char *) seg->addr + rel2->r_offset); + ((char *) seg->addr + rel2->r_offset +#ifdef GRUB_CPU_WORDS_BIGENDIAN + + 2 +#endif + ); break; } *(grub_uint16_t *) addr = (value >> 16) & 0xffff; } break; case R_MIPS_LO16: +#ifdef GRUB_CPU_WORDS_BIGENDIAN + addr += 2; +#endif *(grub_uint16_t *) addr += (sym->st_value) & 0xffff; break; case R_MIPS_32: @@ -208,6 +219,9 @@ grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr) case R_MIPS_GOT16: case R_MIPS_CALL16: /* FIXME: reuse*/ +#ifdef GRUB_CPU_WORDS_BIGENDIAN + addr += 2; +#endif *gpptr = sym->st_value + *(grub_uint16_t *) addr; *(grub_uint16_t *) addr = sizeof (grub_uint32_t) * (gpptr - gp); From 8906c3dd40f9a0fa64bc91f32b42f3078a57323b Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 13 May 2011 16:36:05 +0200 Subject: [PATCH 577/869] sgi support --- conf/Makefile.common | 2 +- configure.ac | 3 + gentpl.py | 8 +- grub-core/Makefile.am | 10 +- grub-core/Makefile.core.def | 45 +++- grub-core/commands/arc/lsdev.c | 53 ++++ grub-core/disk/arc/arcdisk.c | 232 +++++++++++++++++ grub-core/kern/mips/arc/init.c | 203 +++++++++++++++ grub-core/kern/mips/init.c | 18 ++ grub-core/kern/mips/yeeloong/init.c | 17 +- grub-core/lib/arc/datetime.c | 48 ++++ grub-core/mmap/mips/{yeeloong => }/uppermem.c | 2 +- grub-core/partmap/dvh.c | 124 +++++++++ grub-core/term/arc/console.c | 123 +++++++++ grub-core/term/terminfo.c | 19 +- include/grub/arc/arc.h | 244 ++++++++++++++++++ include/grub/arc/console.h | 31 +++ include/grub/disk.h | 3 +- include/grub/mips/arc/kernel.h | 2 + include/grub/mips/arc/memory.h | 42 +++ include/grub/mips/arc/time.h | 0 include/grub/mips/kernel.h | 30 +++ include/grub/mips/loongson.h | 7 +- include/grub/mips/memory.h | 61 ++++- include/grub/mips/mips.h | 30 +++ include/grub/mips/time.h | 33 ++- include/grub/mips/yeeloong/kernel.h | 32 +-- include/grub/mips/yeeloong/memory.h | 34 +-- include/grub/mips/yeeloong/time.h | 12 +- include/grub/offsets.h | 12 + util/grub-mkimage.c | 93 ++++++- 31 files changed, 1453 insertions(+), 120 deletions(-) create mode 100644 grub-core/commands/arc/lsdev.c create mode 100644 grub-core/disk/arc/arcdisk.c create mode 100644 grub-core/kern/mips/arc/init.c create mode 100644 grub-core/lib/arc/datetime.c rename grub-core/mmap/mips/{yeeloong => }/uppermem.c (98%) create mode 100644 grub-core/partmap/dvh.c create mode 100644 grub-core/term/arc/console.c create mode 100644 include/grub/arc/arc.h create mode 100644 include/grub/arc/console.h create mode 100644 include/grub/mips/arc/kernel.h create mode 100644 include/grub/mips/arc/memory.h create mode 100644 include/grub/mips/arc/time.h create mode 100644 include/grub/mips/kernel.h create mode 100644 include/grub/mips/mips.h diff --git a/conf/Makefile.common b/conf/Makefile.common index 5aa13cdd6..13963d5f3 100644 --- a/conf/Makefile.common +++ b/conf/Makefile.common @@ -28,10 +28,10 @@ endif if COND_mips_yeeloong CFLAGS_PLATFORM += -mexplicit-relocs CPPFLAGS_PLATFORM = -DUSE_ASCII_FAILBACK - CCASFLAGS_PLATFORM = -march=mips3 endif if COND_mips CFLAGS_PLATFORM += -mflush-func=grub_cpu_flush_cache + CCASFLAGS_PLATFORM = -march=mips3 endif if COND_sparc64_ieee1275 CFLAGS_PLATFORM += -mno-app-regs diff --git a/configure.ac b/configure.ac index 811bd992d..28c13b511 100644 --- a/configure.ac +++ b/configure.ac @@ -124,6 +124,7 @@ case "$target_cpu"-"$platform" in sparc64-ieee1275) ;; mips-qemu-mips) ;; mips-yeeloong) ;; + mips-arc) ;; *-emu) ;; *) AC_MSG_ERROR([platform "$platform" is not supported for target CPU "$target_cpu"]) ;; esac @@ -158,6 +159,7 @@ case "$platform" in emu) machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_MACHINE_EMU=1" ;; yeeloong) machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_MACHINE_MIPS_YEELOONG=1 -DGRUB_MACHINE_MIPS_BONITO=1" ;; qemu-mips) machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_MACHINE_MIPS_QEMU_MIPS=1 -DGRUB_MACHINE_MIPS_BONITO=1" ;; + mips-arc) machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_MACHINE_MIPS_ARC=1 -DGRUB_MACHINE_ARC=1" ;; esac case "$target_cpu" in mips) machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_MACHINE_MIPS=1" ;; @@ -952,6 +954,7 @@ AM_CONDITIONAL([COND_i386_multiboot], [test x$target_cpu = xi386 -a x$platform = AM_CONDITIONAL([COND_x86_64_efi], [test x$target_cpu = xx86_64 -a x$platform = xefi]) AM_CONDITIONAL([COND_mips_yeeloong], [test x$target_cpu = xmips -a x$platform = xyeeloong]) AM_CONDITIONAL([COND_mips_qemu_mips], [test x$target_cpu = xmips -a x$platform = xqemu_mips]) +AM_CONDITIONAL([COND_mips_arc], [test x$target_cpu = xmips -a x$platform = xarc]) AM_CONDITIONAL([COND_sparc64_ieee1275], [test x$target_cpu = xsparc64 -a x$platform = xieee1275]) AM_CONDITIONAL([COND_powerpc_ieee1275], [test x$target_cpu = xpowerpc -a x$platform = xieee1275]) AM_CONDITIONAL([COND_mips], [test x$target_cpu = xmips]) diff --git a/gentpl.py b/gentpl.py index a42a60667..c8d81cfba 100644 --- a/gentpl.py +++ b/gentpl.py @@ -7,7 +7,7 @@ GRUB_PLATFORMS = [ "emu", "i386_pc", "i386_efi", "i386_qemu", "i386_coreboot", "i386_multiboot", "i386_ieee1275", "x86_64_efi", "mips_yeeloong", "sparc64_ieee1275", - "powerpc_ieee1275" ] + "powerpc_ieee1275", "mips_arc" ] GROUPS = {} @@ -17,7 +17,7 @@ GROUPS["common"] = GRUB_PLATFORMS[:] GROUPS["i386"] = [ "i386_pc", "i386_efi", "i386_qemu", "i386_coreboot", "i386_multiboot", "i386_ieee1275" ] GROUPS["x86_64"] = [ "x86_64_efi" ] GROUPS["x86"] = GROUPS["i386"] + GROUPS["x86_64"] -GROUPS["mips"] = [ "mips_yeeloong" ] +GROUPS["mips"] = [ "mips_yeeloong", "mips_arc" ] GROUPS["sparc64"] = [ "sparc64_ieee1275" ] GROUPS["powerpc"] = [ "powerpc_ieee1275" ] @@ -30,7 +30,7 @@ GROUPS["noemu"] = GRUB_PLATFORMS[:]; GROUPS["noemu"].remove("emu") # Groups based on hardware features GROUPS["cmos"] = GROUPS["x86"][:] + ["mips_yeeloong"]; GROUPS["cmos"].remove("i386_efi"); GROUPS["cmos"].remove("x86_64_efi") -GROUPS["pci"] = GROUPS["x86"] + GROUPS["mips"] +GROUPS["pci"] = GROUPS["x86"] + ["mips_yeeloong"] GROUPS["usb"] = GROUPS["pci"] # If gfxterm is main output console integrate it into kernel @@ -39,7 +39,7 @@ GROUPS["videomodules"] = GRUB_PLATFORMS[:]; for i in GROUPS["videoinkernel"]: GROUPS["videomodules"].remove(i) # Similar for terminfo -GROUPS["terminfoinkernel"] = ["mips_yeeloong"] + GROUPS["ieee1275"]; +GROUPS["terminfoinkernel"] = ["mips_yeeloong", "mips_arc"] + GROUPS["ieee1275"]; GROUPS["terminfomodule"] = GRUB_PLATFORMS[:]; for i in GROUPS["terminfoinkernel"]: GROUPS["terminfomodule"].remove(i) diff --git a/grub-core/Makefile.am b/grub-core/Makefile.am index 94f7f3ffe..234bd3ee8 100644 --- a/grub-core/Makefile.am +++ b/grub-core/Makefile.am @@ -125,9 +125,17 @@ KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/efi/disk.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/i386/pit.h endif +if COND_mips +KERNEL_HEADER_FILES += $(top_builddir)/include/grub/cpu/kernel.h +endif + +if COND_mips_arc +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/extcmd.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/arc/arc.h +endif + if COND_mips_yeeloong KERNEL_HEADER_FILES += $(top_builddir)/include/grub/keyboard_layouts.h -KERNEL_HEADER_FILES += $(top_builddir)/include/grub/machine/kernel.h KERNEL_HEADER_FILES += $(top_builddir)/include/grub/cpu/cache.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/bitmap.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/video.h diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def index f4d38149d..e27d375c4 100644 --- a/grub-core/Makefile.core.def +++ b/grub-core/Makefile.core.def @@ -35,6 +35,7 @@ kernel = { mips_yeeloong_ldflags = '-Wl,-Ttext,0x80200000'; powerpc_ieee1275_ldflags = '-Wl,-Ttext,0x200000'; sparc64_ieee1275_ldflags = '-Wl,-Ttext,0x4400'; + mips_arc_ldflags = '-Wl,-Ttext,0x8a000000'; mips_yeeloong_cppflags = '-DUSE_ASCII_FAILBACK'; i386_qemu_cppflags = '-DGRUB_BOOT_MACHINE_LINK_ADDR=$(GRUB_BOOT_MACHINE_LINK_ADDR)'; @@ -48,7 +49,7 @@ kernel = { i386_ieee1275_startup = kern/i386/ieee1275/startup.S; i386_coreboot_startup = kern/i386/coreboot/startup.S; i386_multiboot_startup = kern/i386/coreboot/startup.S; - mips_yeeloong_startup = kern/mips/startup.S; + mips_startup = kern/mips/startup.S; sparc64_ieee1275_startup = kern/sparc64/ieee1275/crt0.S; powerpc_ieee1275_startup = kern/powerpc/ieee1275/startup.S; @@ -81,7 +82,7 @@ kernel = { i386_qemu = kern/generic/rtc_get_time_ms.c; i386_coreboot = kern/generic/rtc_get_time_ms.c; i386_multiboot = kern/generic/rtc_get_time_ms.c; - mips_yeeloong = kern/generic/rtc_get_time_ms.c; + mips = kern/generic/rtc_get_time_ms.c; ieee1275 = disk/ieee1275/ofdisk.c; ieee1275 = kern/ieee1275/cmain.c; @@ -136,13 +137,18 @@ kernel = { i386_ieee1275 = kern/ieee1275/init.c; + mips = kern/mips/cache.S; + mips = kern/mips/dl.c; + mips = kern/mips/init.c; + + mips_arc = kern/mips/arc/init.c; + mips_arc = term/arc/console.c; + mips_arc = disk/arc/arcdisk.c; + mips_yeeloong = term/ns8250.c; mips_yeeloong = bus/bonito.c; mips_yeeloong = bus/cs5536.c; mips_yeeloong = bus/pci.c; - mips_yeeloong = kern/mips/cache.S; - mips_yeeloong = kern/mips/dl.c; - mips_yeeloong = kern/mips/init.c; mips_yeeloong = kern/mips/yeeloong/init.c; mips_yeeloong = term/at_keyboard.c; mips_yeeloong = term/serial.c; @@ -297,10 +303,12 @@ image = { cppflags = '-I$(srcdir)/lib/posix_wrap -I$(srcdir)/lib/xzembed'; - mips_cppflags = '-I$(srcdir)/lib/posix_wrap -I$(srcdir)/lib/xzembed -DGRUB_EMBED_DECOMPRESSOR=1 -DGRUB_MACHINE_LINK_ADDR=0x80200000'; + mips_arc_cppflags = '-I$(srcdir)/lib/posix_wrap -I$(srcdir)/lib/xzembed -DGRUB_EMBED_DECOMPRESSOR=1 -DGRUB_MACHINE_LINK_ADDR=0x8a000000'; + mips_yeeloong_cppflags = '-I$(srcdir)/lib/posix_wrap -I$(srcdir)/lib/xzembed -DGRUB_EMBED_DECOMPRESSOR=1 -DGRUB_MACHINE_LINK_ADDR=0x80200000'; objcopyflags = '-O binary'; - ldflags = '-static-libgcc -Wl,-Ttext,0x80100000'; + mips_yeeloong_ldflags = '-static-libgcc -Wl,-Ttext,0x80100000'; + mips_arc_ldflags = '-static-libgcc -Wl,-Ttext,0x89f00000'; ldadd = '-lgcc'; cflags = '-static-libgcc'; enable = mips; @@ -311,10 +319,12 @@ image = { mips = boot/mips/startup_raw.S; common = boot/decompressor/none.c; - mips_cppflags = '-DGRUB_EMBED_DECOMPRESSOR=1 -DGRUB_MACHINE_LINK_ADDR=0x80200000'; + mips_arc_cppflags = '-DGRUB_EMBED_DECOMPRESSOR=1 -DGRUB_MACHINE_LINK_ADDR=0x8a000000'; + mips_yeeloong_cppflags = '-DGRUB_EMBED_DECOMPRESSOR=1 -DGRUB_MACHINE_LINK_ADDR=0x80200000'; objcopyflags = '-O binary'; - ldflags = '-static-libgcc -Wl,-Ttext,0x80100000'; + mips_yeeloong_ldflags = '-static-libgcc -Wl,-Ttext,0x80100000'; + mips_arc_ldflags = '-static-libgcc -Wl,-Ttext,0x89f00000'; ldadd = '-lgcc'; cflags = '-static-libgcc'; enable = mips; @@ -408,6 +418,13 @@ module = { emu_condition = COND_GRUB_EMU_PCI; }; +module = { + name = lsdev; + common = commands/arc/lsdev.c; + + enable = mips_arc; +}; + library = { name = libgnulib.a; common = gnulib/regex.c; @@ -1117,6 +1134,7 @@ module = { x86_efi = lib/efi/datetime.c; sparc64_ieee1275 = lib/ieee1275/datetime.c; powerpc_ieee1275 = lib/ieee1275/datetime.c; + mips_arc = lib/arc/datetime.c; enable = noemu; }; @@ -1228,10 +1246,10 @@ module = { x86_efi = mmap/efi/mmap.c; - mips_yeeloong = mmap/mips/yeeloong/uppermem.c; + mips = mmap/mips/uppermem.c; enable = x86; - enable = mips_yeeloong; + enable = mips; }; module = { @@ -1305,6 +1323,11 @@ module = { common = partmap/sun.c; }; +module = { + name = part_dvh; + common = partmap/dvh.c; +}; + module = { name = part_bsd; common = partmap/bsdlabel.c; diff --git a/grub-core/commands/arc/lsdev.c b/grub-core/commands/arc/lsdev.c new file mode 100644 index 000000000..5d4b0cd09 --- /dev/null +++ b/grub-core/commands/arc/lsdev.c @@ -0,0 +1,53 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2011 Free Software Foundation, Inc. + * + * GRUB is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see . + */ + +#include +#include +#include +#include +#include + +GRUB_MOD_LICENSE ("GPLv3+"); + +static grub_err_t +grub_cmd_lsdev (grub_command_t cmd __attribute__ ((unused)), + int argc __attribute__ ((unused)), + char **args __attribute__ ((unused))) +{ + auto int hook (const char *name, const struct grub_arc_component *comp); + int hook (const char *name, const struct grub_arc_component *comp __attribute__ ((unused))) + { + grub_printf ("%s\n", name); + return 0; + } + grub_arc_iterate_devs (hook, 0); + return 0; +} + +static grub_command_t cmd; + +GRUB_MOD_INIT(lsdev) +{ + cmd = grub_register_command ("lsdev", grub_cmd_lsdev, "", + N_("List devices.")); +} + +GRUB_MOD_FINI(lsdev) +{ + grub_unregister_command (cmd); +} diff --git a/grub-core/disk/arc/arcdisk.c b/grub-core/disk/arc/arcdisk.c new file mode 100644 index 000000000..c3b98a52e --- /dev/null +++ b/grub-core/disk/arc/arcdisk.c @@ -0,0 +1,232 @@ +/* ofdisk.c - Open Firmware disk access. */ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2004,2006,2007,2008,2009 Free Software Foundation, Inc. + * + * GRUB is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see . + */ + +#include +#include +#include +#include + +static unsigned last_handle = 0; +static char *last_path = NULL; + +static int +grub_arcdisk_iterate (int (*hook_in) (const char *name)) +{ + auto int hook (const char *name, const struct grub_arc_component *comp); + int hook (const char *name, const struct grub_arc_component *comp) + { + if (!(comp->type == GRUB_ARC_COMPONENT_TYPE_DISK + || comp->type == GRUB_ARC_COMPONENT_TYPE_DISK + || comp->type == GRUB_ARC_COMPONENT_TYPE_TAPE)) + return 0; + return hook_in (name); + } + return grub_arc_iterate_devs (hook, 1); +} + +#define RAW_SUFFIX "partition(10)" + +static grub_err_t +reopen (const char *name) +{ + unsigned handle; + + if (last_path && grub_strcmp (last_path, name) == 0) + { + grub_dprintf ("arcdisk", "using already opened %s\n", name); + return GRUB_ERR_NONE; + } + if (GRUB_ARC_FIRMWARE_VECTOR->open (name, 0, &handle)) + { + grub_dprintf ("arcdisk", "couldn't open %s\n", name); + return grub_error (GRUB_ERR_IO, "couldn't open %s", name); + } + if (last_path) + { + GRUB_ARC_FIRMWARE_VECTOR->close (last_handle); + grub_free (last_path); + last_path = NULL; + last_handle = 0; + } + last_path = grub_strdup (name); + if (!last_path) + return grub_errno; + last_handle = handle; + grub_dprintf ("arcdisk", "opened %s\n", name); + return GRUB_ERR_NONE; +} + +static grub_err_t +grub_arcdisk_open (const char *name, grub_disk_t disk) +{ + char *fullname, *optr; + const char *iptr; + int state = 0; + grub_err_t err; + int r; + struct grub_arc_fileinfo info; + if (grub_memcmp (name, "arc/", 4) != 0) + return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "not arc device"); + fullname = grub_malloc (2 * grub_strlen (name) + sizeof (RAW_SUFFIX)); + if (!fullname) + return grub_errno; + optr = fullname; + for (iptr = name + 4; *iptr; iptr++) + if (state == 0) + { + if (!grub_isdigit (*iptr)) + *optr++ = *iptr; + else + { + *optr++ = '('; + *optr++ = *iptr; + state = 1; + } + } + else + { + if (grub_isdigit (*iptr)) + *optr++ = *iptr; + else + { + *optr++ = ')'; + state = 0; + } + } + if (state) + *optr++ = ')'; + grub_memcpy (optr, RAW_SUFFIX, sizeof (RAW_SUFFIX)); + disk->data = fullname; + grub_dprintf ("arcdisk", "opening %s\n", fullname); + err = reopen (fullname); + if (err) + return err; + + r = GRUB_ARC_FIRMWARE_VECTOR->getfileinformation (last_handle, &info); + if (r) + { + grub_uint64_t res = 0; + int i; + + grub_dprintf ("arcdisk", "couldn't retrieve size: %d\n", r); + for (i = 40; i >= 9; i--) + { + grub_uint64_t pos = res | (1ULL << i); + char buf[512]; + long unsigned count = 0; + grub_dprintf ("arcdisk", + "seek to 0x%" PRIxGRUB_UINT64_T "\n", pos); + if (GRUB_ARC_FIRMWARE_VECTOR->seek (last_handle, &pos, 0)) + continue; + if (GRUB_ARC_FIRMWARE_VECTOR->read (last_handle, buf, + 0x200, &count)) + continue; + if (count == 0) + continue; + res |= (1ULL << i); + } + grub_dprintf ("arcdisk", + "determined disk size 0x%" PRIxGRUB_UINT64_T "\n", res); + disk->total_sectors = (res + 0x200) >> 9; + } + else + disk->total_sectors = (info.end >> 9); + disk->id = 0; /* XXX */ + return GRUB_ERR_NONE; +} + +static void +grub_arcdisk_close (grub_disk_t disk) +{ + grub_free (disk->data); +} + +static grub_err_t +grub_arcdisk_read (grub_disk_t disk, grub_disk_addr_t sector, + grub_size_t size, char *buf) +{ + grub_err_t err; + grub_uint64_t pos = sector << 9; + unsigned long count; + grub_uint64_t totl = size << 9; + int r; + + err = reopen (disk->data); + if (err) + return err; + r = GRUB_ARC_FIRMWARE_VECTOR->seek (last_handle, &pos, 0); + if (r) + { + grub_dprintf ("arcdisk", "seek to 0x%" PRIxGRUB_UINT64_T " failed: %d\n", + pos, r); + return grub_error (GRUB_ERR_IO, "couldn't seek"); + } + + while (totl) + { + if (GRUB_ARC_FIRMWARE_VECTOR->read (last_handle, buf, + totl, &count)) + return grub_error (GRUB_ERR_READ_ERROR, "read failed"); + totl -= count; + buf += count; + } + + return GRUB_ERR_NONE; +} + +static grub_err_t +grub_arcdisk_write (grub_disk_t disk __attribute ((unused)), + grub_disk_addr_t sector __attribute ((unused)), + grub_size_t size __attribute ((unused)), + const char *buf __attribute ((unused))) +{ + return GRUB_ERR_NOT_IMPLEMENTED_YET; +} + +static struct grub_disk_dev grub_arcdisk_dev = + { + .name = "arcdisk", + .id = GRUB_DISK_DEVICE_ARCDISK_ID, + .iterate = grub_arcdisk_iterate, + .open = grub_arcdisk_open, + .close = grub_arcdisk_close, + .read = grub_arcdisk_read, + .write = grub_arcdisk_write, + .next = 0 + }; + +void +grub_arcdisk_init (void) +{ + grub_disk_dev_register (&grub_arcdisk_dev); +} + +void +grub_arcdisk_fini (void) +{ + if (last_path) + { + GRUB_ARC_FIRMWARE_VECTOR->close (last_handle); + grub_free (last_path); + last_path = NULL; + last_handle = 0; + } + + grub_disk_dev_unregister (&grub_arcdisk_dev); +} diff --git a/grub-core/kern/mips/arc/init.c b/grub-core/kern/mips/arc/init.c new file mode 100644 index 000000000..85d8b26f5 --- /dev/null +++ b/grub-core/kern/mips/arc/init.c @@ -0,0 +1,203 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 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 . + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +const char *type_names[] = { +#ifdef GRUB_CPU_WORDS_BIGENDIAN + NULL, +#endif + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, + "eisa", "tc", "scsi", "dti", "multi", "disk", "tape", "cdrom", "worm", + "serial", "net", "video", "par", "point", "key", "audio", "other", + "rdisk", "fdisk", "tape", "modem", "monitor", "print", "pointer", + "keyboard", "term", "other", "line", "network", NULL +}; + +static int +iterate_rec (const char *prefix, const struct grub_arc_component *parent, + int (*hook) (const char *name, + const struct grub_arc_component *comp), + int alt_names) +{ + const struct grub_arc_component *comp; + FOR_ARC_CHILDREN(comp, parent) + { + char *name; + const char *cname = NULL; + if (comp->type < ARRAY_SIZE (type_names)) + cname = type_names[comp->type]; + if (!cname) + cname = "unknown"; + if (alt_names) + name = grub_xasprintf ("%s/%s%d", prefix, cname, comp->key); + else + name = grub_xasprintf ("%s%s(%d)", prefix, cname, comp->key); + if (!name) + return 1; + if (hook (name, comp)) + { + grub_free (name); + return 1; + } + if (iterate_rec ((parent ? name : prefix), comp, hook, alt_names)) + { + grub_free (name); + return 1; + } + grub_free (name); + } + return 0; +} + +int +grub_arc_iterate_devs (int (*hook) (const char *name, + const struct grub_arc_component *comp), + int alt_names) +{ + return iterate_rec ((alt_names ? "arc" : ""), NULL, hook, alt_names); +} + +grub_err_t +grub_machine_mmap_iterate (grub_memory_hook_t hook) +{ + struct grub_arc_memory_descriptor *cur = NULL; + while (1) + { + grub_memory_type_t type; + cur = GRUB_ARC_FIRMWARE_VECTOR->getmemorydescriptor (cur); + if (!cur) + return GRUB_ERR_NONE; + switch (cur->type) + { + case GRUB_ARC_MEMORY_EXCEPTION_BLOCK: + case GRUB_ARC_MEMORY_SYSTEM_PARAMETER_BLOCK: + case GRUB_ARC_MEMORY_FW_PERMANENT: + default: + type = GRUB_MEMORY_RESERVED; + break; + + case GRUB_ARC_MEMORY_FW_TEMPORARY: + case GRUB_ARC_MEMORY_FREE: + case GRUB_ARC_MEMORY_LOADED: + case GRUB_ARC_MEMORY_FREE_CONTIGUOUS: + type = GRUB_MEMORY_AVAILABLE; + break; + case GRUB_ARC_MEMORY_BADRAM: + type = GRUB_MEMORY_BADRAM; + break; + } + if (hook (((grub_uint64_t) cur->start_page) << 12, + ((grub_uint64_t) cur->num_pages) << 12, type)) + return GRUB_ERR_NONE; + } +} + +void +grub_machine_init (void) +{ + struct grub_arc_memory_descriptor *cur = NULL; + + grub_console_init_early (); + + /* FIXME: measure this. */ + grub_arch_cpuclock = 64000000; + grub_install_get_time_ms (grub_rtc_get_time_ms); + + while (1) + { + grub_uint64_t start, end; + cur = GRUB_ARC_FIRMWARE_VECTOR->getmemorydescriptor (cur); + if (!cur) + break; + if (cur->type != GRUB_ARC_MEMORY_FREE + && cur->type != GRUB_ARC_MEMORY_LOADED + && cur->type != GRUB_ARC_MEMORY_FREE_CONTIGUOUS) + continue; + start = ((grub_uint64_t) cur->start_page) << 12; + end = ((grub_uint64_t) cur->num_pages) << 12; + end += start; + if ((grub_uint64_t) end > (GRUB_KERNEL_MIPS_ARC_LINK_ADDR & 0x1fffffff)) + end = (GRUB_KERNEL_MIPS_ARC_LINK_ADDR & 0x1fffffff); + if (end > start) + grub_mm_init_region ((void *) (grub_addr_t) (start | 0x80000000), + end - start); + } + + grub_console_init_lately (); + + grub_arcdisk_init (); +} + +void +grub_machine_fini (void) +{ +} + +void +grub_halt (void) +{ + GRUB_ARC_FIRMWARE_VECTOR->powerdown (); + + grub_millisleep (1500); + + grub_printf ("Shutdown failed\n"); + grub_refresh (); + while (1); +} + +void +grub_exit (void) +{ + GRUB_ARC_FIRMWARE_VECTOR->exit (); + + grub_millisleep (1500); + + grub_printf ("Exit failed\n"); + grub_refresh (); + while (1); +} + +void +grub_reboot (void) +{ + GRUB_ARC_FIRMWARE_VECTOR->restart (); + + grub_millisleep (1500); + + grub_printf ("Reboot failed\n"); + grub_refresh (); + while (1); +} + diff --git a/grub-core/kern/mips/init.c b/grub-core/kern/mips/init.c index f220108d4..3b08d5606 100644 --- a/grub-core/kern/mips/init.c +++ b/grub-core/kern/mips/init.c @@ -18,6 +18,24 @@ #include #include +#include +#include + +/* FIXME: use interrupt to count high. */ +grub_uint64_t +grub_get_rtc (void) +{ + static grub_uint32_t high = 0; + static grub_uint32_t last = 0; + grub_uint32_t low; + + asm volatile ("mfc0 %0, " GRUB_CPU_MIPS_COP0_TIMER_COUNT : "=r" (low)); + if (low < last) + high++; + last = low; + + return (((grub_uint64_t) high) << 32) | low; +} void grub_machine_set_prefix (void) diff --git a/grub-core/kern/mips/yeeloong/init.c b/grub-core/kern/mips/yeeloong/init.c index 7a48d69f5..426e7eabb 100644 --- a/grub-core/kern/mips/yeeloong/init.c +++ b/grub-core/kern/mips/yeeloong/init.c @@ -31,6 +31,7 @@ #include #include #include +#include extern void grub_video_sm712_init (void); extern void grub_video_init (void); @@ -43,22 +44,6 @@ extern void grub_terminfo_init (void); extern void grub_keylayouts_init (void); extern void grub_boot_init (void); -/* FIXME: use interrupt to count high. */ -grub_uint64_t -grub_get_rtc (void) -{ - static grub_uint32_t high = 0; - static grub_uint32_t last = 0; - grub_uint32_t low; - - asm volatile ("mfc0 %0, " GRUB_CPU_LOONGSON_COP0_TIMER_COUNT : "=r" (low)); - if (low < last) - high++; - last = low; - - return (((grub_uint64_t) high) << 32) | low; -} - grub_err_t grub_machine_mmap_iterate (grub_memory_hook_t hook) { diff --git a/grub-core/lib/arc/datetime.c b/grub-core/lib/arc/datetime.c new file mode 100644 index 000000000..b8d910e5f --- /dev/null +++ b/grub-core/lib/arc/datetime.c @@ -0,0 +1,48 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2011 Free Software Foundation, Inc. + * + * GRUB is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see . + */ + +#include +#include +#include +#include + +GRUB_MOD_LICENSE ("GPLv3+"); + +grub_err_t +grub_get_datetime (struct grub_datetime *datetime) +{ + struct grub_arc_timeinfo *dt; + grub_memset (datetime, 0, sizeof (*datetime)); + + dt = GRUB_ARC_FIRMWARE_VECTOR->gettime (); + + datetime->year = dt->y; + datetime->month = dt->m; + datetime->day = dt->d; + datetime->hour = dt->h; + datetime->minute = dt->min; + datetime->second = dt->s; + + return 0; +} + +grub_err_t +grub_set_datetime (struct grub_datetime *datetime __attribute__ ((unused))) +{ + return grub_error (GRUB_ERR_IO, "setting time isn't supported"); +} diff --git a/grub-core/mmap/mips/yeeloong/uppermem.c b/grub-core/mmap/mips/uppermem.c similarity index 98% rename from grub-core/mmap/mips/yeeloong/uppermem.c rename to grub-core/mmap/mips/uppermem.c index 723b6a888..832618540 100644 --- a/grub-core/mmap/mips/yeeloong/uppermem.c +++ b/grub-core/mmap/mips/uppermem.c @@ -20,7 +20,7 @@ #include #include #include -#include +#include grub_uint64_t grub_mmap_get_lower (void) diff --git a/grub-core/partmap/dvh.c b/grub-core/partmap/dvh.c new file mode 100644 index 000000000..118401612 --- /dev/null +++ b/grub-core/partmap/dvh.c @@ -0,0 +1,124 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2002,2005,2006,2007,2011 Free Software Foundation, Inc. + * + * GRUB is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see . + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +GRUB_MOD_LICENSE ("GPLv3+"); + +#define DVH_MAGIC 0x0be5a941 + +struct grub_dvh_partition_descriptor +{ + grub_uint32_t length; + grub_uint32_t start; + grub_uint32_t type; +} __attribute__ ((packed)); + +struct grub_dvh_block +{ + grub_uint32_t magic; + grub_uint8_t unused[308]; + struct grub_dvh_partition_descriptor parts[16]; + grub_uint32_t checksum; + grub_uint32_t unused2; +} __attribute__ ((packed)); + +static struct grub_partition_map grub_dvh_partition_map; + +/* Verify checksum (true=ok). */ +static int +grub_dvh_is_valid (struct grub_dvh_block *label) +{ + grub_uint32_t *pos; + grub_uint32_t sum = 0; + + for (pos = (grub_uint32_t *) label; + pos < (grub_uint32_t *) (label + 1); + pos++) + sum += *pos; + + return ! sum; +} + +static grub_err_t +dvh_partition_map_iterate (grub_disk_t disk, + int (*hook) (grub_disk_t disk, + const grub_partition_t partition)) +{ + struct grub_partition p; + struct grub_dvh_block block; + unsigned partnum; + grub_err_t err; + + p.partmap = &grub_dvh_partition_map; + err = grub_disk_read (disk, 0, 0, sizeof (struct grub_dvh_block), + &block); + if (err) + return err; + + if (DVH_MAGIC != grub_be_to_cpu32 (block.magic)) + return grub_error (GRUB_ERR_BAD_PART_TABLE, "not a dvh partition table"); + + if (! grub_dvh_is_valid (&block)) + return grub_error (GRUB_ERR_BAD_PART_TABLE, "invalid checksum"); + + /* Maybe another error value would be better, because partition + table _is_ recognized but invalid. */ + for (partnum = 0; partnum < ARRAY_SIZE (block.parts); partnum++) + { + if (block.parts[partnum].length == 0) + continue; + + if (partnum == 10) + continue; + + p.start = grub_be_to_cpu32 (block.parts[partnum].start); + p.len = grub_be_to_cpu32 (block.parts[partnum].length); + p.number = p.index = partnum; + if (hook (disk, &p)) + break; + } + + return grub_errno; +} + + +/* Partition map type. */ +static struct grub_partition_map grub_dvh_partition_map = + { + .name = "dvh", + .iterate = dvh_partition_map_iterate, + }; + +GRUB_MOD_INIT(part_dvh) +{ + grub_partition_map_register (&grub_dvh_partition_map); +} + +GRUB_MOD_FINI(part_dvh) +{ + grub_partition_map_unregister (&grub_dvh_partition_map); +} + diff --git a/grub-core/term/arc/console.c b/grub-core/term/arc/console.c new file mode 100644 index 000000000..b7e428795 --- /dev/null +++ b/grub-core/term/arc/console.c @@ -0,0 +1,123 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2011 Free Software Foundation, Inc. + * + * GRUB is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see . + */ + +#include +#include +#include +#include + +/* FIXME: use unicode. */ + +static int +readkey (struct grub_term_input *term __attribute__ ((unused))) +{ + unsigned long count; + char chr; + + if (GRUB_ARC_FIRMWARE_VECTOR->get_read_status (GRUB_ARC_STDIN)) + return -1; + + if (GRUB_ARC_FIRMWARE_VECTOR->read (GRUB_ARC_STDIN, &chr, 1, &count)) + return -1; + if (!count) + return -1; + return chr; +} + +static void +put (struct grub_term_output *term __attribute__ ((unused)), const int c) +{ + unsigned long count; + char chr = c; + + GRUB_ARC_FIRMWARE_VECTOR->write (GRUB_ARC_STDOUT, &chr, 1, &count); +} + +static struct grub_terminfo_output_state grub_console_terminfo_output; + +static grub_err_t +grub_console_init_output (struct grub_term_output *term) +{ + struct grub_arc_display_status *info = NULL; + if (GRUB_ARC_SYSTEM_PARAMETER_BLOCK->firmware_vector_length + >= ((char *) (&GRUB_ARC_FIRMWARE_VECTOR->getdisplaystatus + 1) + - (char *) GRUB_ARC_FIRMWARE_VECTOR) + && GRUB_ARC_FIRMWARE_VECTOR->getdisplaystatus) + info = GRUB_ARC_FIRMWARE_VECTOR->getdisplaystatus (GRUB_ARC_STDOUT); + if (info) + { + grub_console_terminfo_output.width = info->w; + grub_console_terminfo_output.height = info->h; + } + grub_terminfo_output_init (term); + + return 0; +} + +static struct grub_terminfo_input_state grub_console_terminfo_input = + { + .readkey = readkey + }; + +static struct grub_terminfo_output_state grub_console_terminfo_output = + { + .put = put, + .width = 80, + .height = 36 + }; + +static struct grub_term_input grub_console_term_input = + { + .name = "console", + .init = grub_terminfo_input_init, + .getkey = grub_terminfo_getkey, + .data = &grub_console_terminfo_input + }; + +static struct grub_term_output grub_console_term_output = + { + .name = "console", + .init = grub_console_init_output, + .putchar = grub_terminfo_putchar, + .getxy = grub_terminfo_getxy, + .getwh = grub_terminfo_getwh, + .gotoxy = grub_terminfo_gotoxy, + .cls = grub_terminfo_cls, + .setcolorstate = grub_terminfo_setcolorstate, + .setcursor = grub_terminfo_setcursor, + .flags = GRUB_TERM_CODE_TYPE_ASCII, + .data = &grub_console_terminfo_output, + .normal_color = GRUB_TERM_DEFAULT_NORMAL_COLOR, + .highlight_color = GRUB_TERM_DEFAULT_HIGHLIGHT_COLOR, + }; + +void +grub_console_init_early (void) +{ + grub_term_register_input ("console", &grub_console_term_input); + grub_term_register_output ("console", &grub_console_term_output); +} + +void grub_terminfo_init (void); + +void +grub_console_init_lately (void) +{ + grub_terminfo_init (); + grub_terminfo_output_register (&grub_console_term_output, "arc"); +} diff --git a/grub-core/term/terminfo.c b/grub-core/term/terminfo.c index 16158139d..3ba630b33 100644 --- a/grub-core/term/terminfo.c +++ b/grub-core/term/terminfo.c @@ -36,6 +36,9 @@ GRUB_MOD_LICENSE ("GPLv3+"); +#define ANSI_C0 0x9b +#define ANSI_C0_STR "\x9b" + static struct grub_term_output *terminfo_outputs; /* Get current terminfo name. */ @@ -123,6 +126,20 @@ grub_terminfo_set_current (struct grub_term_output *term, return grub_errno; } + if (grub_strcmp ("arc", str) == 0) + { + data->name = grub_strdup ("arc"); + data->gotoxy = grub_strdup (ANSI_C0_STR "%i%p1%d;%p2%dH"); + data->cls = grub_strdup (ANSI_C0_STR "2J"); + data->reverse_video_on = grub_strdup (ANSI_C0_STR "7m"); + data->reverse_video_off = grub_strdup (ANSI_C0_STR "0m"); + data->cursor_on = 0; + data->cursor_off = 0; + data->setcolor = grub_strdup (ANSI_C0_STR "3%p1%dm" + ANSI_C0_STR "4%p2%dm"); + return grub_errno; + } + if (grub_strcmp ("ieee1275", str) == 0) { data->name = grub_strdup ("ieee1275"); @@ -369,8 +386,6 @@ grub_terminfo_getwh (struct grub_term_output *term) return (data->width << 8) | data->height; } -#define ANSI_C0 0x9b - static void grub_terminfo_readkey (struct grub_term_input *term, int *keys, int *len, int (*readkey) (struct grub_term_input *term)) diff --git a/include/grub/arc/arc.h b/include/grub/arc/arc.h new file mode 100644 index 000000000..5ff0a41f1 --- /dev/null +++ b/include/grub/arc/arc.h @@ -0,0 +1,244 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2011 Free Software Foundation, Inc. + * + * GRUB is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see . + */ + +#ifndef GRUB_ARC_HEADER +#define GRUB_ARC_HEADER 1 + +#include +#include + +struct grub_arc_memory_descriptor +{ + grub_uint32_t type; + grub_uint32_t start_page; + grub_uint32_t num_pages; +}; + +enum grub_arc_memory_type + { + GRUB_ARC_MEMORY_EXCEPTION_BLOCK, + GRUB_ARC_MEMORY_SYSTEM_PARAMETER_BLOCK, +#ifdef GRUB_CPU_WORDS_BIGENDIAN + GRUB_ARC_MEMORY_FREE_CONTIGUOUS, +#endif + GRUB_ARC_MEMORY_FREE, + GRUB_ARC_MEMORY_BADRAM, + GRUB_ARC_MEMORY_LOADED, GRUB_ARC_MEMORY_FW_TEMPORARY, + GRUB_ARC_MEMORY_FW_PERMANENT, +#ifndef GRUB_CPU_WORDS_BIGENDIAN + GRUB_ARC_MEMORY_FREE_CONTIGUOUS, +#endif + } grub_arc_memory_type_t; + +struct grub_arc_timeinfo +{ + grub_uint16_t y; + grub_uint16_t m; + grub_uint16_t d; + grub_uint16_t h; + grub_uint16_t min; + grub_uint16_t s; + grub_uint16_t ms; +}; + +struct grub_arc_display_status +{ + grub_uint16_t x; + grub_uint16_t y; + grub_uint16_t w; + grub_uint16_t h; + grub_uint8_t fgcolor; + grub_uint8_t bgcolor; + grub_uint8_t high_intensity; + grub_uint8_t underscored; + grub_uint8_t reverse_video; +}; + +struct grub_arc_component +{ + unsigned class; + unsigned type; + unsigned flags; + grub_uint16_t version; + grub_uint16_t rev; + grub_uint32_t key; + grub_uint32_t affinity; + grub_uint32_t configdatasize; + grub_uint32_t idlen; + const char *idstr; +}; + +enum + { +#ifdef GRUB_CPU_WORDS_BIGENDIAN + GRUB_ARC_COMPONENT_TYPE_ARC = 1, +#else + GRUB_ARC_COMPONENT_TYPE_ARC, +#endif + GRUB_ARC_COMPONENT_TYPE_CPU, + GRUB_ARC_COMPONENT_TYPE_FPU, + GRUB_ARC_COMPONENT_TYPE_PRI_I_CACHE, + GRUB_ARC_COMPONENT_TYPE_PRI_D_CACHE, + GRUB_ARC_COMPONENT_TYPE_SEC_I_CACHE, + GRUB_ARC_COMPONENT_TYPE_SEC_D_CACHE, + GRUB_ARC_COMPONENT_TYPE_SEC_CACHE, + GRUB_ARC_COMPONENT_TYPE_EISA, + GRUB_ARC_COMPONENT_TYPE_TCA, + GRUB_ARC_COMPONENT_TYPE_SCSI, + GRUB_ARC_COMPONENT_TYPE_DTIA, + GRUB_ARC_COMPONENT_TYPE_MULTIFUNC, + GRUB_ARC_COMPONENT_TYPE_DISK_CONTROLLER, + GRUB_ARC_COMPONENT_TYPE_TAPE_CONTROLLER, + GRUB_ARC_COMPONENT_TYPE_CDROM_CONTROLLER, + GRUB_ARC_COMPONENT_TYPE_WORM_CONTROLLER, + GRUB_ARC_COMPONENT_TYPE_SERIAL_CONTROLLER, + GRUB_ARC_COMPONENT_TYPE_NET_CONTROLLER, + GRUB_ARC_COMPONENT_TYPE_DISPLAY_CONTROLLER, + GRUB_ARC_COMPONENT_TYPE_PARALLEL_CONTROLLER, + GRUB_ARC_COMPONENT_TYPE_POINTER_CONTROLLER, + GRUB_ARC_COMPONENT_TYPE_KBD_CONTROLLER, + GRUB_ARC_COMPONENT_TYPE_AUDIO_CONTROLLER, + GRUB_ARC_COMPONENT_TYPE_OTHER_CONTROLLER, + GRUB_ARC_COMPONENT_TYPE_DISK, + GRUB_ARC_COMPONENT_TYPE_FLOPPY, + GRUB_ARC_COMPONENT_TYPE_TAPE, + GRUB_ARC_COMPONENT_TYPE_MODEM, + GRUB_ARC_COMPONENT_TYPE_MONITOR, + GRUB_ARC_COMPONENT_TYPE_PRINTER, + GRUB_ARC_COMPONENT_TYPE_POINTER, + GRUB_ARC_COMPONENT_TYPE_KBD, + GRUB_ARC_COMPONENT_TYPE_TERMINAL, + GRUB_ARC_COMPONENT_TYPE_OTHER_PERIPHERAL, + GRUB_ARC_COMPONENT_TYPE_LINE, + GRUB_ARC_COMPONENT_TYPE_NET, + GRUB_ARC_COMPONENT_TYPE_MEMORY_UNIT, + }; + +struct grub_arc_fileinfo +{ + grub_uint64_t start; + grub_uint64_t end; + grub_uint64_t current; + grub_uint32_t type; + grub_uint32_t fnamelength; + grub_uint8_t attr; + char filename[32]; +}; + +struct grub_arc_firmware_vector +{ + /* 0x00. */ + void *load; + void *invoke; + void *execute; + void *halt; + + /* 0x10. */ + void (*powerdown) (void); + void (*restart) (void); + void (*reboot) (void); + void (*exit) (void); + + /* 0x20. */ + void *reserved1; + const struct grub_arc_component * (*getpeer) (const struct grub_arc_component *comp); + const struct grub_arc_component * (*getchild) (const struct grub_arc_component *comp); + void *getparent; + + /* 0x30. */ + void *getconfigurationdata; + void *addchild; + void *deletecomponent; + void *getcomponent; + + /* 0x40. */ + void *saveconfiguration; + void *getsystemid; + struct grub_arc_memory_descriptor *(*getmemorydescriptor) (struct grub_arc_memory_descriptor *current); + void *reserved2; + + /* 0x50. */ + struct grub_arc_timeinfo *(*gettime) (void); + void *getrelativetime; + void *getdirectoryentry; + int (*open) (const char *path, int mode, unsigned *fileno); + + /* 0x60. */ + int (*close) (unsigned fileno); + int (*read) (unsigned fileno, void *buf, unsigned long n, + unsigned long *count); + int (*get_read_status) (unsigned fileno); + int (*write) (unsigned fileno, void *buf, unsigned long n, + unsigned long *count); + + /* 0x70. */ + int (*seek) (unsigned fileno, grub_uint64_t *pos, int mode); + void *mount; + void *getenvironmentvariable; + void *setenvironmentvariable; + + /* 0x80. */ + int (*getfileinformation) (unsigned fileno, struct grub_arc_fileinfo *info); + void *setfileinformation; + void *flushallcaches; + void *testunicodecharacter; + + /* 0x90. */ + struct grub_arc_display_status * (*getdisplaystatus) (unsigned fileno); +}; + +struct grub_arc_adapter +{ + grub_uint32_t adapter_type; + grub_uint32_t adapter_vector_length; + void *adapter_vector; +}; + +struct grub_arc_system_parameter_block +{ + grub_uint32_t signature; + grub_uint32_t length; + grub_uint16_t version; + grub_uint16_t revision; + void *restartblock; + void *debugblock; + void *gevector; + void *utlbmissvector; + grub_uint32_t firmware_vector_length; + struct grub_arc_firmware_vector *firmwarevector; + grub_uint32_t private_vector_length; + void *private_vector; + grub_uint32_t adapter_count; + struct grub_arc_adapter adapters[0]; +}; + + +#define GRUB_ARC_SYSTEM_PARAMETER_BLOCK ((struct grub_arc_system_parameter_block *) 0xa0001000) +#define GRUB_ARC_FIRMWARE_VECTOR (GRUB_ARC_SYSTEM_PARAMETER_BLOCK->firmwarevector) +#define GRUB_ARC_STDIN 0 +#define GRUB_ARC_STDOUT 1 + +int EXPORT_FUNC (grub_arc_iterate_devs) (int (*hook) (const char *name, const struct grub_arc_component *comp), int alt_names); + +#define FOR_ARC_CHILDREN(comp, parent) for (comp = GRUB_ARC_FIRMWARE_VECTOR->getchild (parent); comp; comp = GRUB_ARC_FIRMWARE_VECTOR->getpeer (comp)) + +extern void grub_arcdisk_init (void); +extern void grub_arcdisk_fini (void); + + +#endif diff --git a/include/grub/arc/console.h b/include/grub/arc/console.h new file mode 100644 index 000000000..e054f54f5 --- /dev/null +++ b/include/grub/arc/console.h @@ -0,0 +1,31 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2008 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 . + */ + +#ifndef GRUB_CONSOLE_MACHINE_HEADER +#define GRUB_CONSOLE_MACHINE_HEADER 1 + +#include + +/* Initialize the console system. */ +void grub_console_init_early (void); +void grub_console_init_lately (void); + +/* Finish the console system. */ +void grub_console_fini (void); + +#endif /* ! GRUB_CONSOLE_MACHINE_HEADER */ diff --git a/include/grub/disk.h b/include/grub/disk.h index 66db1149a..867283494 100644 --- a/include/grub/disk.h +++ b/include/grub/disk.h @@ -42,7 +42,8 @@ enum grub_disk_dev_id GRUB_DISK_DEVICE_PXE_ID, GRUB_DISK_DEVICE_SCSI_ID, GRUB_DISK_DEVICE_FILE_ID, - GRUB_DISK_DEVICE_LUKS_ID + GRUB_DISK_DEVICE_LUKS_ID, + GRUB_DISK_DEVICE_ARCDISK_ID, }; struct grub_disk; diff --git a/include/grub/mips/arc/kernel.h b/include/grub/mips/arc/kernel.h new file mode 100644 index 000000000..50694866b --- /dev/null +++ b/include/grub/mips/arc/kernel.h @@ -0,0 +1,2 @@ +#include + diff --git a/include/grub/mips/arc/memory.h b/include/grub/mips/arc/memory.h new file mode 100644 index 000000000..b960d2a37 --- /dev/null +++ b/include/grub/mips/arc/memory.h @@ -0,0 +1,42 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2009 Free Software Foundation, Inc. + * + * GRUB is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see . + */ + +#ifndef GRUB_MEMORY_MACHINE_HEADER +#define GRUB_MEMORY_MACHINE_HEADER 1 + +#define GRUB_MACHINE_MEMORY_STACK_HIGH 0x8bfffff0 + +#ifndef ASM_FILE + +static inline grub_err_t +grub_machine_mmap_register (grub_uint64_t start __attribute__ ((unused)), + grub_uint64_t size __attribute__ ((unused)), + int type __attribute__ ((unused)), + int handle __attribute__ ((unused))) +{ + return GRUB_ERR_NONE; +} +static inline grub_err_t +grub_machine_mmap_unregister (int handle __attribute__ ((unused))) +{ + return GRUB_ERR_NONE; +} + +#endif + +#endif diff --git a/include/grub/mips/arc/time.h b/include/grub/mips/arc/time.h new file mode 100644 index 000000000..e69de29bb diff --git a/include/grub/mips/kernel.h b/include/grub/mips/kernel.h new file mode 100644 index 000000000..d82d0a97d --- /dev/null +++ b/include/grub/mips/kernel.h @@ -0,0 +1,30 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2005,2006,2007,2008,2009 Free Software Foundation, Inc. + * + * GRUB is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see . + */ + +#ifndef GRUB_KERNEL_MACHINE_HEADER +#define GRUB_KERNEL_MACHINE_HEADER 1 + +#include + +#ifndef ASM_FILE + +void EXPORT_FUNC (grub_halt) (void) __attribute__ ((noreturn)); + +#endif + +#endif /* ! GRUB_KERNEL_MACHINE_HEADER */ diff --git a/include/grub/mips/loongson.h b/include/grub/mips/loongson.h index 6cb1178d5..810b73ef2 100644 --- a/include/grub/mips/loongson.h +++ b/include/grub/mips/loongson.h @@ -19,11 +19,7 @@ #ifndef GRUB_LOONGSON_CPU_HEADER #define GRUB_LOONGSON_CPU_HEADER 1 -#ifdef ASM_FILE -#define GRUB_CPU_REGISTER_WRAP(x) x -#else -#define GRUB_CPU_REGISTER_WRAP(x) #x -#endif +#include #define GRUB_CPU_LOONGSON_FLASH_START 0xbfc00000 #define GRUB_CPU_LOONGSON_FLASH_TLB_REFILL 0xbfc00200 @@ -68,7 +64,6 @@ #define GRUB_CPU_LOONGSON_SECONDARY_CACHE_LOG_SIZE 19 #define GRUB_CPU_LOONGSON_COP0_BADVADDR GRUB_CPU_REGISTER_WRAP($8) -#define GRUB_CPU_LOONGSON_COP0_TIMER_COUNT GRUB_CPU_REGISTER_WRAP($9) #define GRUB_CPU_LOONGSON_COP0_CAUSE GRUB_CPU_REGISTER_WRAP($13) #define GRUB_CPU_LOONGSON_COP0_EPC GRUB_CPU_REGISTER_WRAP($14) #define GRUB_CPU_LOONGSON_COP0_CACHE_TAGLO GRUB_CPU_REGISTER_WRAP($28) diff --git a/include/grub/mips/memory.h b/include/grub/mips/memory.h index e51bcc1f2..2ef2ed31c 100644 --- a/include/grub/mips/memory.h +++ b/include/grub/mips/memory.h @@ -1 +1,60 @@ -#include +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2009 Free Software Foundation, Inc. + * + * GRUB is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see . + */ + +#ifndef GRUB_MEMORY_MACHINE_HEADER +#define GRUB_MEMORY_MACHINE_HEADER 1 + +#ifndef ASM_FILE +#include +#include +#include +#endif + +#define GRUB_ARCH_LOWMEMVSTART 0x80000000 +#define GRUB_ARCH_LOWMEMPSTART 0x00000000 +#define GRUB_ARCH_LOWMEMMAXSIZE 0x10000000 +#define GRUB_ARCH_HIGHMEMPSTART 0x10000000 + +#ifndef ASM_FILE + +typedef grub_addr_t grub_phys_addr_t; + +static inline grub_phys_addr_t +grub_vtop (void *a) +{ + return ((grub_phys_addr_t) a) & 0x1fffffff; +} + +static inline void * +grub_map_memory (grub_phys_addr_t a, grub_size_t size __attribute__ ((unused))) +{ + return (void *) (a | 0x80000000); +} + +static inline void +grub_unmap_memory (void *a __attribute__ ((unused)), + grub_size_t size __attribute__ ((unused))) +{ +} + +grub_uint64_t grub_mmap_get_lower (void); +grub_uint64_t grub_mmap_get_upper (void); + +#endif + +#endif diff --git a/include/grub/mips/mips.h b/include/grub/mips/mips.h new file mode 100644 index 000000000..8c161aa15 --- /dev/null +++ b/include/grub/mips/mips.h @@ -0,0 +1,30 @@ +/* + * 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 . + */ + +#ifndef GRUB_REGISTORS_CPU_HEADER +#define GRUB_REGISTORS_CPU_HEADER 1 + +#ifdef ASM_FILE +#define GRUB_CPU_REGISTER_WRAP(x) x +#else +#define GRUB_CPU_REGISTER_WRAP(x) #x +#endif + +#define GRUB_CPU_MIPS_COP0_TIMER_COUNT GRUB_CPU_REGISTER_WRAP($9) + +#endif diff --git a/include/grub/mips/time.h b/include/grub/mips/time.h index b143a48e0..1139b24bb 100644 --- a/include/grub/mips/time.h +++ b/include/grub/mips/time.h @@ -1,6 +1,37 @@ -#ifdef GRUB_MACHINE_EMU +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2003,2004,2005,2007 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 . + */ + +#ifndef KERNEL_CPU_TIME_HEADER +#define KERNEL_CPU_TIME_HEADER 1 + +#ifndef GRUB_UTIL + +#define GRUB_TICKS_PER_SECOND (grub_arch_cpuclock / 2) + +/* Return the real time in ticks. */ +grub_uint64_t EXPORT_FUNC (grub_get_rtc) (void); + +extern grub_uint32_t EXPORT_VAR (grub_arch_cpuclock); +#endif + static inline void grub_cpu_idle(void) { } + #endif diff --git a/include/grub/mips/yeeloong/kernel.h b/include/grub/mips/yeeloong/kernel.h index 15cf9f9fd..7752a3ef5 100644 --- a/include/grub/mips/yeeloong/kernel.h +++ b/include/grub/mips/yeeloong/kernel.h @@ -1,31 +1 @@ -/* - * GRUB -- GRand Unified Bootloader - * Copyright (C) 2005,2006,2007,2008,2009 Free Software Foundation, Inc. - * - * GRUB is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * GRUB is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GRUB. If not, see . - */ - -#ifndef GRUB_KERNEL_MACHINE_HEADER -#define GRUB_KERNEL_MACHINE_HEADER 1 - -#include - -#ifndef ASM_FILE - -void EXPORT_FUNC (grub_reboot) (void) __attribute__ ((noreturn)); -void EXPORT_FUNC (grub_halt) (void) __attribute__ ((noreturn)); - -#endif - -#endif /* ! GRUB_KERNEL_MACHINE_HEADER */ +#include diff --git a/include/grub/mips/yeeloong/memory.h b/include/grub/mips/yeeloong/memory.h index 9d53b5e0e..4a1065ea5 100644 --- a/include/grub/mips/yeeloong/memory.h +++ b/include/grub/mips/yeeloong/memory.h @@ -19,43 +19,16 @@ #ifndef GRUB_MEMORY_MACHINE_HEADER #define GRUB_MEMORY_MACHINE_HEADER 1 +#define GRUB_MACHINE_MEMORY_STACK_HIGH 0x801ffff0 + #ifndef ASM_FILE #include #include #include #endif -#define GRUB_MACHINE_MEMORY_STACK_HIGH 0x801ffff0 -#define GRUB_ARCH_LOWMEMVSTART 0x80000000 -#define GRUB_ARCH_LOWMEMPSTART 0x00000000 -#define GRUB_ARCH_LOWMEMMAXSIZE 0x10000000 -#define GRUB_ARCH_HIGHMEMPSTART 0x10000000 - #ifndef ASM_FILE -typedef grub_addr_t grub_phys_addr_t; - -static inline grub_phys_addr_t -grub_vtop (void *a) -{ - return ((grub_phys_addr_t) a) & 0x1fffffff; -} - -static inline void * -grub_map_memory (grub_phys_addr_t a, grub_size_t size __attribute__ ((unused))) -{ - return (void *) (a | 0x80000000); -} - -static inline void -grub_unmap_memory (void *a __attribute__ ((unused)), - grub_size_t size __attribute__ ((unused))) -{ -} - -grub_err_t EXPORT_FUNC (grub_machine_mmap_iterate) -(int NESTED_FUNC_ATTR (*hook) (grub_uint64_t, grub_uint64_t, grub_uint32_t)); - static inline grub_err_t grub_machine_mmap_register (grub_uint64_t start __attribute__ ((unused)), grub_uint64_t size __attribute__ ((unused)), @@ -70,9 +43,6 @@ grub_machine_mmap_unregister (int handle __attribute__ ((unused))) return GRUB_ERR_NONE; } -grub_uint64_t grub_mmap_get_lower (void); -grub_uint64_t grub_mmap_get_upper (void); - extern grub_uint32_t EXPORT_VAR (grub_arch_memsize); extern grub_uint32_t EXPORT_VAR (grub_arch_highmemsize); diff --git a/include/grub/mips/yeeloong/time.h b/include/grub/mips/yeeloong/time.h index 7f468bf12..8b8ee42c4 100644 --- a/include/grub/mips/yeeloong/time.h +++ b/include/grub/mips/yeeloong/time.h @@ -20,18 +20,8 @@ #define KERNEL_MACHINE_TIME_HEADER 1 #include - -#define GRUB_TICKS_PER_SECOND (grub_arch_cpuclock / 2) - -/* Return the real time in ticks. */ -grub_uint64_t EXPORT_FUNC (grub_get_rtc) (void); +#include extern grub_uint32_t EXPORT_VAR (grub_arch_busclock); -extern grub_uint32_t EXPORT_VAR (grub_arch_cpuclock); - -static inline void -grub_cpu_idle(void) -{ -} #endif /* ! KERNEL_MACHINE_TIME_HEADER */ diff --git a/include/grub/offsets.h b/include/grub/offsets.h index 31deb5031..d71e7deae 100644 --- a/include/grub/offsets.h +++ b/include/grub/offsets.h @@ -111,6 +111,17 @@ #define GRUB_KERNEL_MIPS_YEELOONG_PREFIX 0x0c #define GRUB_KERNEL_MIPS_YEELOONG_PREFIX_END 0x54 +#define GRUB_KERNEL_MIPS_ARC_LINK_ADDR 0x8a000000 + +#define GRUB_KERNEL_MIPS_ARC_LINK_ALIGN 32 + +#define GRUB_KERNEL_MIPS_ARC_COMPRESSED_SIZE 0x8 +#define GRUB_KERNEL_MIPS_ARC_UNCOMPRESSED_SIZE 0xc + +#define GRUB_KERNEL_MIPS_ARC_TOTAL_MODULE_SIZE 0x08 +#define GRUB_KERNEL_MIPS_ARC_PREFIX 0x0c +#define GRUB_KERNEL_MIPS_ARC_PREFIX_END 0x54 + /* The offset of GRUB_PREFIX. */ #define GRUB_KERNEL_I386_EFI_PREFIX 0x8 @@ -145,6 +156,7 @@ #define GRUB_KERNEL_POWERPC_IEEE1275_MOD_ALIGN 0x1000 #define GRUB_KERNEL_MIPS_YEELOONG_MOD_ALIGN 0x1 +#define GRUB_KERNEL_MIPS_ARC_MOD_ALIGN 0x1 /* Minimal gap between _end and the start of the modules. It's a hack for PowerMac to prevent "CLAIM failed" error. The real fix is to diff --git a/util/grub-mkimage.c b/util/grub-mkimage.c index b71fb0420..259d78beb 100644 --- a/util/grub-mkimage.c +++ b/util/grub-mkimage.c @@ -65,7 +65,7 @@ struct image_target_desc IMAGE_I386_PC, IMAGE_EFI, IMAGE_COREBOOT, IMAGE_SPARC64_AOUT, IMAGE_SPARC64_RAW, IMAGE_I386_IEEE1275, IMAGE_YEELOONG_ELF, IMAGE_QEMU, IMAGE_PPC, IMAGE_YEELOONG_FLASH, - IMAGE_I386_PC_PXE + IMAGE_I386_PC_PXE, IMAGE_MIPS_ARC } id; enum { @@ -355,6 +355,27 @@ struct image_target_desc image_targets[] = .install_bsd_part = TARGET_NO_FIELD, .link_addr = GRUB_KERNEL_SPARC64_IEEE1275_LINK_ADDR }, + { + .name = "mips-arc", + .voidp_sizeof = 4, + .bigendian = 1, + .id = IMAGE_MIPS_ARC, + .flags = PLATFORM_FLAGS_DECOMPRESSORS, + .prefix = GRUB_KERNEL_MIPS_ARC_PREFIX, + .prefix_end = GRUB_KERNEL_MIPS_ARC_PREFIX_END, + .raw_size = 0, + .total_module_size = GRUB_KERNEL_MIPS_ARC_TOTAL_MODULE_SIZE, + .compressed_size = TARGET_NO_FIELD, + .kernel_image_size = TARGET_NO_FIELD, + .section_align = 1, + .vaddr_offset = 0, + .install_dos_part = TARGET_NO_FIELD, + .install_bsd_part = TARGET_NO_FIELD, + .link_addr = GRUB_KERNEL_MIPS_ARC_LINK_ADDR, + .elf_target = EM_MIPS, + .link_align = GRUB_KERNEL_MIPS_ARC_LINK_ALIGN, + .default_compression = COMPRESSION_NONE + }, }; #define grub_target_to_host32(x) (grub_target_to_host32_real (image_target, (x))) @@ -1217,6 +1238,76 @@ generate_image (const char *dir, char *prefix, FILE *out, char *mods[], core_size = rom_size; } break; + case IMAGE_MIPS_ARC: + { + char *ecoff_img; + struct ecoff_header { + grub_uint16_t magic; + grub_uint16_t nsec; + grub_uint32_t time; + grub_uint32_t syms; + grub_uint32_t nsyms; + grub_uint16_t opt; + grub_uint16_t flags; + grub_uint16_t magic2; + grub_uint16_t version; + grub_uint32_t textsize; + grub_uint32_t datasize; + grub_uint32_t bsssize; + grub_uint32_t entry; + grub_uint32_t text_start; + grub_uint32_t data_start; + grub_uint32_t bss_start; + grub_uint32_t gprmask; + grub_uint32_t cprmask[4]; + grub_uint32_t gp_value; + }; + struct ecoff_section + { + char name[8]; + grub_uint32_t paddr; + grub_uint32_t vaddr; + grub_uint32_t size; + grub_uint32_t file_offset; + grub_uint32_t reloc; + grub_uint32_t gp; + grub_uint16_t nreloc; + grub_uint16_t ngp; + grub_uint32_t flags; + }; + struct ecoff_header *head; + struct ecoff_section *section; + grub_uint32_t target_addr; + size_t program_size; + + program_size = ALIGN_ADDR (core_size); + target_addr = image_target->link_addr - ALIGN_UP(program_size, 1048576) + - (1 << 20); + + ecoff_img = xmalloc (program_size + sizeof (*head) + sizeof (*section)); + grub_memset (ecoff_img, 0, program_size + sizeof (*head) + sizeof (*section)); + head = (void *) ecoff_img; + section = (void *) (head + 1); + head->magic = grub_host_to_target16 (0x160); + head->nsec = grub_host_to_target16 (1); + head->time = grub_host_to_target32 (0); + head->opt = grub_host_to_target16 (0x38); + head->flags = grub_host_to_target16 (0x207); + head->magic2 = grub_host_to_target16 (0x107); + head->textsize = grub_host_to_target32 (program_size); + head->entry = grub_host_to_target32 (target_addr); + head->text_start = grub_host_to_target32 (target_addr); + head->data_start = grub_host_to_target32 (target_addr + program_size); + grub_memcpy (section->name, ".text", sizeof (".text") - 1); + section->vaddr = grub_host_to_target32 (target_addr); + section->size = grub_host_to_target32 (program_size); + section->file_offset = grub_host_to_target32 (sizeof (*head) + sizeof (*section)); + memcpy (section + 1, core_img, core_size); + free (core_img); + core_img = ecoff_img; + core_size = program_size + sizeof (*head) + sizeof (*section); + } + break; case IMAGE_YEELOONG_ELF: case IMAGE_PPC: case IMAGE_COREBOOT: From 12ce749d86fe53bfaee6bce2b552bedcda72bf50 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 13 May 2011 16:36:41 +0200 Subject: [PATCH 578/869] sgimips linux loader --- grub-core/loader/mips/linux.c | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/grub-core/loader/mips/linux.c b/grub-core/loader/mips/linux.c index 0bf7b1f8e..0b95bd3c2 100644 --- a/grub-core/loader/mips/linux.c +++ b/grub-core/loader/mips/linux.c @@ -31,10 +31,12 @@ GRUB_MOD_LICENSE ("GPLv3+"); /* For frequencies. */ -#include #include #ifdef GRUB_MACHINE_MIPS_YEELOONG + +#include + /* This can be detected on runtime from PMON, but: a) it wouldn't work when GRUB is the firmware and @@ -52,7 +54,10 @@ static struct grub_relocator *relocator; static grub_uint8_t *playground; static grub_addr_t target_addr, entry_addr; static int linux_argc; -static grub_off_t argv_off, envp_off; +static grub_off_t argv_off; +#ifdef GRUB_MACHINE_MIPS_YEELOONG +static grub_off_t envp_off; +#endif static grub_off_t rd_addr_arg_off, rd_size_arg_off; static int initrd_loaded = 0; @@ -65,7 +70,12 @@ grub_linux_boot (void) state.gpr[1] = entry_addr; state.gpr[4] = linux_argc; state.gpr[5] = target_addr + argv_off; +#ifdef GRUB_MACHINE_MIPS_YEELOONG state.gpr[6] = target_addr + envp_off; +#else + state.gpr[6] = 0; +#endif + state.gpr[7] = 0; state.jumpreg = 1; grub_relocator32_boot (relocator, state); @@ -200,9 +210,13 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), int i; int size; void *extra = NULL; - grub_uint32_t *linux_argv, *linux_envp; - char *linux_args, *linux_envs; + grub_uint32_t *linux_argv; + char *linux_args; grub_err_t err; +#ifdef GRUB_MACHINE_MIPS_YEELOONG + char *linux_envs; + grub_uint32_t *linux_envp; +#endif if (argc == 0) return grub_error (GRUB_ERR_BAD_ARGUMENT, "no kernel specified"); @@ -313,6 +327,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), extra = linux_args; +#ifdef GRUB_MACHINE_MIPS_YEELOONG linux_envp = extra; envp_off = (grub_uint8_t *) linux_envp - (grub_uint8_t *) playground; linux_envs = (char *) (linux_envp + 5); @@ -340,8 +355,8 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), + target_addr; linux_envs += ALIGN_UP (grub_strlen (linux_envs) + 1, 4); - linux_envp[4] = 0; +#endif grub_loader_set (grub_linux_boot, grub_linux_unload, 1); initrd_loaded = 0; From ae6a81f0bb996aa107810246d4b3148953c95919 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 13 May 2011 16:38:23 +0200 Subject: [PATCH 579/869] some additional key sequences for arc --- grub-core/term/terminfo.c | 59 ++++++++++++++++++++++++++++++++++----- include/grub/terminfo.h | 2 +- 2 files changed, 53 insertions(+), 8 deletions(-) diff --git a/grub-core/term/terminfo.c b/grub-core/term/terminfo.c index 3ba630b33..3419a5117 100644 --- a/grub-core/term/terminfo.c +++ b/grub-core/term/terminfo.c @@ -445,7 +445,8 @@ grub_terminfo_readkey (struct grub_term_input *term, int *keys, int *len, {'K', GRUB_TERM_KEY_END}, {'P', GRUB_TERM_KEY_DC}, {'?', GRUB_TERM_KEY_PPAGE}, - {'/', GRUB_TERM_KEY_NPAGE} + {'/', GRUB_TERM_KEY_NPAGE}, + {'@', GRUB_TERM_KEY_INSERT}, }; static struct @@ -460,6 +461,14 @@ grub_terminfo_readkey (struct grub_term_input *term, int *keys, int *len, {'5', GRUB_TERM_KEY_PPAGE}, {'6', GRUB_TERM_KEY_NPAGE} }; + char fx_key[] = + { 'P', 'Q', 'w', 'x', 't', 'u', + 'q', 'r', 'p', 'M', 'A', 'B' }; + unsigned fx_code[] = + { GRUB_TERM_KEY_F1, GRUB_TERM_KEY_F2, GRUB_TERM_KEY_F3, + GRUB_TERM_KEY_F4, GRUB_TERM_KEY_F5, GRUB_TERM_KEY_F6, + GRUB_TERM_KEY_F7, GRUB_TERM_KEY_F8, GRUB_TERM_KEY_F9, + GRUB_TERM_KEY_F10, GRUB_TERM_KEY_F11, GRUB_TERM_KEY_F12 }; unsigned i; if (c == '\e') @@ -480,17 +489,53 @@ grub_terminfo_readkey (struct grub_term_input *term, int *keys, int *len, return; } - for (i = 0; i < ARRAY_SIZE (four_code_table); i++) - if (four_code_table[i].key == c) + switch (c) + { + case 'O': + CONTINUE_READ; + for (i = 0; i < ARRAY_SIZE (fx_key); i++) + if (fx_key[i] == c) + { + keys[0] = fx_code[i]; + *len = 1; + return; + } + return; + + case '0': { + int num = 0; CONTINUE_READ; - if (c != '~') + if (c != '0' && c != '1') return; - keys[0] = three_code_table[i].ascii; + num = (c - '0') * 10; + CONTINUE_READ; + if (c < '0' || c > '9') + return; + num += (c - '0'); + if (num == 0 || num > 12) + return; + CONTINUE_READ; + if (c != 'q') + return; + keys[0] = fx_code[num - 1]; *len = 1; return; - } - return; + } + + default: + for (i = 0; i < ARRAY_SIZE (four_code_table); i++) + if (four_code_table[i].key == c) + { + CONTINUE_READ; + if (c != '~') + return; + keys[0] = three_code_table[i].ascii; + *len = 1; + return; + } + return; + } } #undef CONTINUE_READ } diff --git a/include/grub/terminfo.h b/include/grub/terminfo.h index 5a552b327..e3b28ce88 100644 --- a/include/grub/terminfo.h +++ b/include/grub/terminfo.h @@ -27,7 +27,7 @@ char *EXPORT_FUNC(grub_terminfo_get_current) (struct grub_term_output *term); grub_err_t EXPORT_FUNC(grub_terminfo_set_current) (struct grub_term_output *term, const char *); -#define GRUB_TERMINFO_READKEY_MAX_LEN 4 +#define GRUB_TERMINFO_READKEY_MAX_LEN 6 struct grub_terminfo_input_state { int input_buf[GRUB_TERMINFO_READKEY_MAX_LEN]; From fb25a861086e57e3ab8dbff1f16a5387e5a93d9d Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 13 May 2011 16:39:02 +0200 Subject: [PATCH 580/869] add dvh to userspace tools --- Makefile.util.def | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile.util.def b/Makefile.util.def index 058572f06..50e60f476 100644 --- a/Makefile.util.def +++ b/Makefile.util.def @@ -92,6 +92,7 @@ library = { common = grub-core/partmap/gpt.c; common = grub-core/partmap/msdos.c; common = grub-core/partmap/sun.c; + common = grub-core/partmap/dvh.c; common = grub-core/partmap/sunpc.c; common = grub-core/partmap/bsdlabel.c; common = grub-core/script/function.c; From 214af04cf585007d3b36488b289033c55d4e4719 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 13 May 2011 16:41:26 +0200 Subject: [PATCH 581/869] avoid executing cache opcode on non-4 byte aligned boundaries --- grub-core/kern/mips/cache_flush.S | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/grub-core/kern/mips/cache_flush.S b/grub-core/kern/mips/cache_flush.S index 11096c035..a352fd8ba 100644 --- a/grub-core/kern/mips/cache_flush.S +++ b/grub-core/kern/mips/cache_flush.S @@ -9,15 +9,15 @@ subu $t1, $t3, $t2 1: cache 1, 0($t0) - addiu $t1, $t1, 0xffff + addiu $t1, $t1, -0x4 bne $t1, $zero, 1b - addiu $t0, $t0, 0x1 + addiu $t0, $t0, 0x4 sync move $t0, $t2 subu $t1, $t3, $t2 2: cache 0, 0($t0) - addiu $t1, $t1, 0xffff + addiu $t1, $t1, -0x4 bne $t1, $zero, 2b - addiu $t0, $t0, 0x1 + addiu $t0, $t0, 0x4 sync From dd10ec9e60a5e9bc3829e79dc4c7f9b7d8c16593 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 13 May 2011 18:02:36 +0200 Subject: [PATCH 582/869] sgimips grub-install partial support (untested) --- util/grub-install.in | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/util/grub-install.in b/util/grub-install.in index ff8bea87c..537830ecb 100644 --- a/util/grub-install.in +++ b/util/grub-install.in @@ -619,6 +619,10 @@ elif [ "${target_cpu}-${platform}" = "i386-ieee1275" ] || [ "${target_cpu}-${pla exit 1 } fi +elif [ x"${target_cpu}-${platform}" = xmips-arc ]; then + dvhtool -d "${install_device}" --unix-to-vh "{grubdir}/core.${imgext}" grub + echo "You will have to set boot-device manually. At the Open Firmware prompt, type:" + elif [ x"$platform" = xefi ]; then cp "${grubdir}/core.${imgext}" "${efidir}/${efi_file}" # For old macs. Suggested by Peter Jones. From cdcfe2a95fb3a7e4828febab37be2f6ec744e436 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 13 May 2011 18:02:58 +0200 Subject: [PATCH 583/869] missing part of previous commits --- grub-core/kern/mips/startup.S | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/grub-core/kern/mips/startup.S b/grub-core/kern/mips/startup.S index ae0e0b187..48bf253de 100644 --- a/grub-core/kern/mips/startup.S +++ b/grub-core/kern/mips/startup.S @@ -50,11 +50,11 @@ VARIABLE(grub_prefix) */ . = _start + GRUB_KERNEL_MACHINE_PREFIX_END +VARIABLE (grub_arch_cpuclock) + .long 0 #ifdef GRUB_MACHINE_MIPS_YEELOONG VARIABLE (grub_arch_busclock) .long 0 -VARIABLE (grub_arch_cpuclock) - .long 0 VARIABLE (grub_arch_memsize) .long 0 VARIABLE (grub_arch_highmemsize) From 96a29d188b261ada3cf3085f0edda3a9a5622bfa Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 13 May 2011 18:03:20 +0200 Subject: [PATCH 584/869] Arc type cleanup --- grub-core/disk/arc/arcdisk.c | 12 ++-- grub-core/kern/mips/arc/init.c | 4 +- include/grub/arc/arc.h | 121 ++++++++++++++++++--------------- 3 files changed, 76 insertions(+), 61 deletions(-) diff --git a/grub-core/disk/arc/arcdisk.c b/grub-core/disk/arc/arcdisk.c index c3b98a52e..62732c7ad 100644 --- a/grub-core/disk/arc/arcdisk.c +++ b/grub-core/disk/arc/arcdisk.c @@ -22,7 +22,7 @@ #include #include -static unsigned last_handle = 0; +static grub_arc_fileno_t last_handle = 0; static char *last_path = NULL; static int @@ -45,7 +45,7 @@ grub_arcdisk_iterate (int (*hook_in) (const char *name)) static grub_err_t reopen (const char *name) { - unsigned handle; + grub_arc_fileno_t handle; if (last_path && grub_strcmp (last_path, name) == 0) { @@ -79,7 +79,7 @@ grub_arcdisk_open (const char *name, grub_disk_t disk) const char *iptr; int state = 0; grub_err_t err; - int r; + grub_arc_err_t r; struct grub_arc_fileinfo info; if (grub_memcmp (name, "arc/", 4) != 0) return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "not arc device"); @@ -124,7 +124,7 @@ grub_arcdisk_open (const char *name, grub_disk_t disk) grub_uint64_t res = 0; int i; - grub_dprintf ("arcdisk", "couldn't retrieve size: %d\n", r); + grub_dprintf ("arcdisk", "couldn't retrieve size: %ld\n", r); for (i = 40; i >= 9; i--) { grub_uint64_t pos = res | (1ULL << i); @@ -165,7 +165,7 @@ grub_arcdisk_read (grub_disk_t disk, grub_disk_addr_t sector, grub_uint64_t pos = sector << 9; unsigned long count; grub_uint64_t totl = size << 9; - int r; + grub_arc_err_t r; err = reopen (disk->data); if (err) @@ -173,7 +173,7 @@ grub_arcdisk_read (grub_disk_t disk, grub_disk_addr_t sector, r = GRUB_ARC_FIRMWARE_VECTOR->seek (last_handle, &pos, 0); if (r) { - grub_dprintf ("arcdisk", "seek to 0x%" PRIxGRUB_UINT64_T " failed: %d\n", + grub_dprintf ("arcdisk", "seek to 0x%" PRIxGRUB_UINT64_T " failed: %ld\n", pos, r); return grub_error (GRUB_ERR_IO, "couldn't seek"); } diff --git a/grub-core/kern/mips/arc/init.c b/grub-core/kern/mips/arc/init.c index 85d8b26f5..8ee965d74 100644 --- a/grub-core/kern/mips/arc/init.c +++ b/grub-core/kern/mips/arc/init.c @@ -61,9 +61,9 @@ iterate_rec (const char *prefix, const struct grub_arc_component *parent, if (!cname) cname = "unknown"; if (alt_names) - name = grub_xasprintf ("%s/%s%d", prefix, cname, comp->key); + name = grub_xasprintf ("%s/%s%lu", prefix, cname, comp->key); else - name = grub_xasprintf ("%s%s(%d)", prefix, cname, comp->key); + name = grub_xasprintf ("%s%s(%lu)", prefix, cname, comp->key); if (!name) return 1; if (hook (name, comp)) diff --git a/include/grub/arc/arc.h b/include/grub/arc/arc.h index 5ff0a41f1..aae73052b 100644 --- a/include/grub/arc/arc.h +++ b/include/grub/arc/arc.h @@ -22,11 +22,21 @@ #include #include +typedef unsigned grub_arc_enum_t; +typedef grub_uint64_t grub_arc_ularge_t; +typedef unsigned long grub_arc_ulong_t; +typedef long grub_arc_long_t; +typedef unsigned short grub_arc_ushort_t; +typedef unsigned char grub_arc_uchar_t; + +typedef grub_arc_long_t grub_arc_err_t; +typedef grub_arc_ulong_t grub_arc_fileno_t; + struct grub_arc_memory_descriptor { - grub_uint32_t type; - grub_uint32_t start_page; - grub_uint32_t num_pages; + grub_arc_enum_t type; + grub_arc_ulong_t start_page; + grub_arc_ulong_t num_pages; }; enum grub_arc_memory_type @@ -47,39 +57,39 @@ enum grub_arc_memory_type struct grub_arc_timeinfo { - grub_uint16_t y; - grub_uint16_t m; - grub_uint16_t d; - grub_uint16_t h; - grub_uint16_t min; - grub_uint16_t s; - grub_uint16_t ms; + grub_arc_ushort_t y; + grub_arc_ushort_t m; + grub_arc_ushort_t d; + grub_arc_ushort_t h; + grub_arc_ushort_t min; + grub_arc_ushort_t s; + grub_arc_ushort_t ms; }; struct grub_arc_display_status { - grub_uint16_t x; - grub_uint16_t y; - grub_uint16_t w; - grub_uint16_t h; - grub_uint8_t fgcolor; - grub_uint8_t bgcolor; - grub_uint8_t high_intensity; - grub_uint8_t underscored; - grub_uint8_t reverse_video; + grub_arc_ushort_t x; + grub_arc_ushort_t y; + grub_arc_ushort_t w; + grub_arc_ushort_t h; + grub_arc_uchar_t fgcolor; + grub_arc_uchar_t bgcolor; + grub_arc_uchar_t high_intensity; + grub_arc_uchar_t underscored; + grub_arc_uchar_t reverse_video; }; struct grub_arc_component { - unsigned class; - unsigned type; - unsigned flags; - grub_uint16_t version; - grub_uint16_t rev; - grub_uint32_t key; - grub_uint32_t affinity; - grub_uint32_t configdatasize; - grub_uint32_t idlen; + grub_arc_enum_t class; + grub_arc_enum_t type; + grub_arc_enum_t flags; + grub_arc_ushort_t version; + grub_arc_ushort_t rev; + grub_arc_ulong_t key; + grub_arc_ulong_t affinity; + grub_arc_ulong_t configdatasize; + grub_arc_ulong_t idlen; const char *idstr; }; @@ -131,12 +141,12 @@ enum struct grub_arc_fileinfo { - grub_uint64_t start; - grub_uint64_t end; - grub_uint64_t current; - grub_uint32_t type; - grub_uint32_t fnamelength; - grub_uint8_t attr; + grub_arc_ularge_t start; + grub_arc_ularge_t end; + grub_arc_ularge_t current; + grub_arc_enum_t type; + grub_arc_ulong_t fnamelength; + grub_arc_uchar_t attr; char filename[32]; }; @@ -176,54 +186,59 @@ struct grub_arc_firmware_vector struct grub_arc_timeinfo *(*gettime) (void); void *getrelativetime; void *getdirectoryentry; - int (*open) (const char *path, int mode, unsigned *fileno); + grub_arc_err_t (*open) (const char *path, grub_arc_enum_t mode, + grub_arc_fileno_t *fileno); /* 0x60. */ - int (*close) (unsigned fileno); - int (*read) (unsigned fileno, void *buf, unsigned long n, - unsigned long *count); - int (*get_read_status) (unsigned fileno); - int (*write) (unsigned fileno, void *buf, unsigned long n, - unsigned long *count); + grub_arc_err_t (*close) (grub_arc_fileno_t fileno); + grub_arc_err_t (*read) (grub_arc_fileno_t fileno, void *buf, + grub_arc_ulong_t n, + grub_arc_ulong_t *count); + grub_arc_err_t (*get_read_status) (grub_arc_fileno_t fileno); + grub_arc_err_t (*write) (grub_arc_fileno_t fileno, void *buf, + grub_arc_ulong_t n, + grub_arc_ulong_t *count); /* 0x70. */ - int (*seek) (unsigned fileno, grub_uint64_t *pos, int mode); + grub_arc_err_t (*seek) (grub_arc_fileno_t fileno, + grub_arc_ularge_t *pos, grub_arc_enum_t mode); void *mount; void *getenvironmentvariable; void *setenvironmentvariable; /* 0x80. */ - int (*getfileinformation) (unsigned fileno, struct grub_arc_fileinfo *info); + grub_arc_err_t (*getfileinformation) (grub_arc_fileno_t fileno, + struct grub_arc_fileinfo *info); void *setfileinformation; void *flushallcaches; void *testunicodecharacter; /* 0x90. */ - struct grub_arc_display_status * (*getdisplaystatus) (unsigned fileno); + struct grub_arc_display_status * (*getdisplaystatus) (grub_arc_fileno_t fileno); }; struct grub_arc_adapter { - grub_uint32_t adapter_type; - grub_uint32_t adapter_vector_length; + grub_arc_ulong_t adapter_type; + grub_arc_ulong_t adapter_vector_length; void *adapter_vector; }; struct grub_arc_system_parameter_block { - grub_uint32_t signature; - grub_uint32_t length; - grub_uint16_t version; - grub_uint16_t revision; + grub_arc_ulong_t signature; + grub_arc_ulong_t length; + grub_arc_ushort_t version; + grub_arc_ushort_t revision; void *restartblock; void *debugblock; void *gevector; void *utlbmissvector; - grub_uint32_t firmware_vector_length; + grub_arc_ulong_t firmware_vector_length; struct grub_arc_firmware_vector *firmwarevector; - grub_uint32_t private_vector_length; + grub_arc_ulong_t private_vector_length; void *private_vector; - grub_uint32_t adapter_count; + grub_arc_ulong_t adapter_count; struct grub_arc_adapter adapters[0]; }; From 91bbcc0cb666d9f1cc9965e1c692fd0730ab77fd Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 13 May 2011 20:23:29 +0200 Subject: [PATCH 585/869] * grub-core/boot/mips/yeeloong/fwstart.S: Add explicit set mips3 to avoid asm treating ld and sd as macros. --- ChangeLog | 5 +++++ grub-core/boot/mips/yeeloong/fwstart.S | 1 + 2 files changed, 6 insertions(+) diff --git a/ChangeLog b/ChangeLog index ede161faf..5b73d8884 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-05-13 Vladimir Serbinenko + + * grub-core/boot/mips/yeeloong/fwstart.S: Add explicit set mips3 + to avoid asm treating ld and sd as macros. + 2011-05-13 Vladimir Serbinenko * grub-core/boot/mips/startup_raw.S: Flush cache after loading diff --git a/grub-core/boot/mips/yeeloong/fwstart.S b/grub-core/boot/mips/yeeloong/fwstart.S index 9e81df192..2eec876c2 100644 --- a/grub-core/boot/mips/yeeloong/fwstart.S +++ b/grub-core/boot/mips/yeeloong/fwstart.S @@ -28,6 +28,7 @@ .set noreorder .set noat .set nomacro + .set mips3 .global start,_start,__start start: From 19e1c41bbf0638f0504f8cb6faf25c852c49db21 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 13 May 2011 20:56:50 +0200 Subject: [PATCH 586/869] Flush caches on DMA memory. * grub-core/kern/mips/cache.S (grub_arch_sync_dma_caches): New function. * grub-core/bus/pci.c (grub_memalign_dma32): Flush caches. (grub_dma_free): Likewise. * include/grub/cache.h (grub_arch_sync_dma_caches): New declaration. --- ChangeLog | 9 +++++++++ grub-core/bus/pci.c | 11 ++++++++++- grub-core/kern/mips/cache.S | 35 +++++++++++++++++++++++++++++++++++ include/grub/cache.h | 10 ++++++++++ 4 files changed, 64 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 5b73d8884..49873303c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2011-05-13 Vladimir Serbinenko + + Flush caches on DMA memory. + + * grub-core/kern/mips/cache.S (grub_arch_sync_dma_caches): New function. + * grub-core/bus/pci.c (grub_memalign_dma32): Flush caches. + (grub_dma_free): Likewise. + * include/grub/cache.h (grub_arch_sync_dma_caches): New declaration. + 2011-05-13 Vladimir Serbinenko * grub-core/boot/mips/yeeloong/fwstart.S: Add explicit set mips3 diff --git a/grub-core/bus/pci.c b/grub-core/bus/pci.c index 07d20e3f5..766b6d7f1 100644 --- a/grub-core/bus/pci.c +++ b/grub-core/bus/pci.c @@ -20,6 +20,8 @@ #include #include #include +#include +#include GRUB_MOD_LICENSE ("GPLv3+"); @@ -28,12 +30,19 @@ GRUB_MOD_LICENSE ("GPLv3+"); struct grub_pci_dma_chunk * grub_memalign_dma32 (grub_size_t align, grub_size_t size) { - return grub_memalign (align, size); + void *ret = grub_memalign (align, size); + if (!ret) + return 0; + grub_arch_sync_dma_caches (ret, size); + return ret; } +/* FIXME: evil. */ void grub_dma_free (struct grub_pci_dma_chunk *ch) { + grub_size_t size = (((struct grub_mm_header *) ch) - 1)->size * GRUB_MM_ALIGN; + grub_arch_sync_dma_caches (ch, size); grub_free (ch); } /* #endif */ diff --git a/grub-core/kern/mips/cache.S b/grub-core/kern/mips/cache.S index 999872f6b..a4aa06fb0 100644 --- a/grub-core/kern/mips/cache.S +++ b/grub-core/kern/mips/cache.S @@ -8,3 +8,38 @@ FUNCTION (grub_cpu_flush_cache) FUNCTION (grub_arch_sync_caches) #include "cache_flush.S" j $ra + +FUNCTION (grub_arch_sync_dma_caches) + move $t2, $a0 + addu $t3, $a0, $a1 + srl $t2, $t2, 5 + sll $t2, $t2, 5 + addu $t3, $t3, 0x1f + srl $t3, $t3, 5 + sll $t3, $t3, 5 + move $t0, $t2 + subu $t1, $t3, $t2 +1: + cache 1, 0($t0) + addiu $t1, $t1, 0xffff + bne $t1, $zero, 1b + addiu $t0, $t0, 0x1 + sync + move $t0, $t2 + subu $t1, $t3, $t2 +2: + cache 0, 0($t0) + addiu $t1, $t1, 0xffff + bne $t1, $zero, 2b + addiu $t0, $t0, 0x1 + sync + move $t0, $t2 + subu $t1, $t3, $t2 +2: + cache 23, 0($t0) + addiu $t1, $t1, 0xffff + bne $t1, $zero, 2b + addiu $t0, $t0, 0x1 + sync + + jr $ra \ No newline at end of file diff --git a/include/grub/cache.h b/include/grub/cache.h index 4f913f5c8..292830566 100644 --- a/include/grub/cache.h +++ b/include/grub/cache.h @@ -37,4 +37,14 @@ grub_arch_sync_caches (void *address __attribute__ ((unused)), void EXPORT_FUNC(grub_arch_sync_caches) (void *address, grub_size_t len); #endif +#ifdef _mips +void EXPORT_FUNC(grub_arch_sync_dma_caches) (void *address, grub_size_t len); +#else +static inline void +grub_arch_sync_dma_caches (void *address __attribute__ ((unused)), + grub_size_t len __attribute__ ((unused))) +{ +} +#endif + #endif /* ! GRUB_CACHE_HEADER */ From bda0e21993092a324ecee96e5d61c53ef5ebf6a1 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 13 May 2011 21:31:00 +0200 Subject: [PATCH 587/869] * util/grub-mkimage.c (generate_image): Update hash. --- ChangeLog | 4 ++++ util/grub-mkimage.c | 18 +++++++++--------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index 49873303c..905b0e919 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2011-05-13 Vladimir Serbinenko + + * util/grub-mkimage.c (generate_image): Update hash. + 2011-05-13 Vladimir Serbinenko Flush caches on DMA memory. diff --git a/util/grub-mkimage.c b/util/grub-mkimage.c index b71fb0420..5e964a3e7 100644 --- a/util/grub-mkimage.c +++ b/util/grub-mkimage.c @@ -1169,20 +1169,20 @@ generate_image (const char *dir, char *prefix, FILE *out, char *mods[], char *boot_path, *boot_img; size_t boot_size; grub_uint8_t context[GRUB_MD_SHA512->contextsize]; - /* fwstart.img is the only part which can't be testes by using *-elf + /* fwstart.img is the only part which can't be tested by using *-elf target. Check it against the checksum. This checksum is obtained with sha512sum utility after compiling on Gnewsense. */ const grub_uint8_t fwstart_good_hash[] = { - 0x9f, 0x7f, 0x79, 0x47, 0x68, 0x91, 0x61, 0xb3, - 0x16, 0x7b, 0xf0, 0x27, 0x1c, 0xf7, 0xaf, 0x05, - 0x6c, 0xc1, 0x6f, 0xd2, 0xe7, 0xd1, 0xe9, 0xec, - 0x08, 0x87, 0xe5, 0xc8, 0x29, 0xa2, 0x5b, 0x84, - 0xf8, 0xa6, 0xec, 0x08, 0xf7, 0xcb, 0x7b, 0x6c, - 0xfe, 0x01, 0xfd, 0x5d, 0xba, 0xbf, 0x0d, 0x0f, - 0x2e, 0xef, 0xed, 0x7b, 0xfe, 0xc9, 0x4a, 0x85, - 0xcf, 0xac, 0x20, 0xd7, 0x01, 0xc5, 0xc5, 0x9c + 0x44, 0xce, 0xbc, 0xe7, 0xc2, 0x5e, 0xff, 0x65, + 0xc5, 0xda, 0x29, 0x5a, 0xb9, 0x08, 0x89, 0x42, + 0x83, 0x3f, 0x2b, 0x2e, 0x06, 0xe1, 0x6f, 0x79, + 0x9b, 0x78, 0x6d, 0xe5, 0xd3, 0x64, 0x98, 0x35, + 0xc8, 0x58, 0xac, 0xb8, 0x08, 0x6d, 0x21, 0x51, + 0xcf, 0xe0, 0x76, 0x48, 0x81, 0x6c, 0xed, 0x65, + 0x4a, 0x50, 0xb4, 0x06, 0x38, 0x0b, 0x26, 0x74, + 0x43, 0xbf, 0xc5, 0x2e, 0x07, 0xa6, 0xb8, 0x0e, }; boot_path = grub_util_get_path (dir, "fwstart.img"); From 36084912c0310c7cb42e80b42d0b187bc3775809 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 13 May 2011 21:41:18 +0200 Subject: [PATCH 588/869] Give ATA device a bit more time on first try in order to allow disks to spin up. * grub-core/disk/ata.c (grub_atapi_identify): Use GRUB_ATA_TOUT_DEV_INIT if dev->present is 1. Reset dev->present on failure. (grub_ata_device_initialize): Set dev->present to 1. * include/grub/ata.h (GRUB_ATA_TOUT_DEV_INIT): New value. (grub_ata_device): New member 'present'. --- ChangeLog | 11 +++++++++++ grub-core/disk/ata.c | 35 +++++++++++++++++++++++++---------- include/grub/ata.h | 5 ++++- 3 files changed, 40 insertions(+), 11 deletions(-) diff --git a/ChangeLog b/ChangeLog index 905b0e919..e20f2d3cf 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2011-05-13 Vladimir Serbinenko + + Give ATA device a bit more time on first try in order to allow disks + to spin up. + + * grub-core/disk/ata.c (grub_atapi_identify): Use GRUB_ATA_TOUT_DEV_INIT + if dev->present is 1. Reset dev->present on failure. + (grub_ata_device_initialize): Set dev->present to 1. + * include/grub/ata.h (GRUB_ATA_TOUT_DEV_INIT): New value. + (grub_ata_device): New member 'present'. + 2011-05-13 Vladimir Serbinenko * util/grub-mkimage.c (generate_image): Update hash. diff --git a/grub-core/disk/ata.c b/grub-core/disk/ata.c index 7f261560d..391ccb9a2 100644 --- a/grub-core/disk/ata.c +++ b/grub-core/disk/ata.c @@ -160,18 +160,23 @@ grub_atapi_identify (struct grub_ata_device *dev) grub_ata_regset (dev, GRUB_ATA_REG_DISK, 0xE0 | dev->device << 4); grub_ata_wait (); - if (grub_ata_check_ready (dev)) + if ((grub_ata_regget (dev, GRUB_ATA_REG_STATUS) & GRUB_ATA_STATUS_BUSY) + && grub_ata_wait_not_busy (dev, dev->present ? GRUB_ATA_TOUT_DEV_INIT + : GRUB_ATA_TOUT_STD)) { grub_free (info); + dev->present = 0; return grub_errno; } grub_ata_regset (dev, GRUB_ATA_REG_CMD, GRUB_ATA_CMD_IDENTIFY_PACKET_DEVICE); grub_ata_wait (); - if (grub_ata_wait_drq (dev, 0, GRUB_ATA_TOUT_STD)) + if (grub_ata_wait_drq (dev, 0, dev->present ? GRUB_ATA_TOUT_DEV_INIT + : GRUB_ATA_TOUT_STD)) { grub_free (info); + dev->present = 0; return grub_errno; } grub_ata_pio_read (dev, info, GRUB_DISK_SECTOR_SIZE); @@ -258,8 +263,11 @@ grub_ata_identify (struct grub_ata_device *dev) grub_ata_regset (dev, GRUB_ATA_REG_DISK, 0xE0 | dev->device << 4); grub_ata_wait (); - if (grub_ata_check_ready (dev)) + if ((grub_ata_regget (dev, GRUB_ATA_REG_STATUS) & GRUB_ATA_STATUS_BUSY) + && grub_ata_wait_not_busy (dev, dev->present ? GRUB_ATA_TOUT_DEV_INIT + : GRUB_ATA_TOUT_STD)) { + dev->present = 0; grub_free (info); return grub_errno; } @@ -267,7 +275,8 @@ grub_ata_identify (struct grub_ata_device *dev) grub_ata_regset (dev, GRUB_ATA_REG_CMD, GRUB_ATA_CMD_IDENTIFY_DEVICE); grub_ata_wait (); - if (grub_ata_wait_drq (dev, 0, GRUB_ATA_TOUT_STD)) + if (grub_ata_wait_drq (dev, 0, dev->present ? GRUB_ATA_TOUT_DEV_INIT + : GRUB_ATA_TOUT_STD)) { grub_free (info); grub_errno = GRUB_ERR_NONE; @@ -280,13 +289,18 @@ grub_ata_identify (struct grub_ata_device *dev) return grub_atapi_identify (dev); else if (sts == 0x00) - /* No device, return error but don't print message. */ - return GRUB_ERR_UNKNOWN_DEVICE; - + { + dev->present = 0; + /* No device, return error but don't print message. */ + return GRUB_ERR_UNKNOWN_DEVICE; + } else - /* Other Error. */ - return grub_error (GRUB_ERR_UNKNOWN_DEVICE, - "device cannot be identified"); + { + dev->present = 0; + /* Other Error. */ + return grub_error (GRUB_ERR_UNKNOWN_DEVICE, + "device cannot be identified"); + } } grub_ata_pio_read (dev, info, GRUB_DISK_SECTOR_SIZE); @@ -381,6 +395,7 @@ grub_ata_device_initialize (int port, int device, int addr, int addr2) dev->device = device; dev->ioaddress = addr + GRUB_MACHINE_PCI_IO_BASE; dev->ioaddress2 = addr2 + GRUB_MACHINE_PCI_IO_BASE; + dev->present = 1; dev->next = NULL; /* Register the device. */ diff --git a/include/grub/ata.h b/include/grub/ata.h index 9e3aaf0e6..c8f4e5e1b 100644 --- a/include/grub/ata.h +++ b/include/grub/ata.h @@ -94,7 +94,8 @@ enum grub_ata_commands enum grub_ata_timeout_milliseconds { GRUB_ATA_TOUT_STD = 1000, /* 1s standard timeout. */ - GRUB_ATA_TOUT_DATA = 10000 /* 10s DATA I/O timeout. */ + GRUB_ATA_TOUT_DATA = 10000, /* 10s DATA I/O timeout. */ + GRUB_ATA_TOUT_DEV_INIT = 10000, /* Give the device 10s on first try to spinon. */ }; struct grub_ata_device @@ -128,6 +129,8 @@ struct grub_ata_device /* Set to 0 for ATA, set to 1 for ATAPI. */ int atapi; + int present; + struct grub_ata_device *next; }; From 85c6210f6abbb3146d547c33b7e3bd97cdc5751c Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 13 May 2011 21:50:18 +0200 Subject: [PATCH 589/869] * configure.ac: Bump version to 1.99. --- ChangeLog | 4 ++++ configure.ac | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index e20f2d3cf..143fc60f5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2011-05-13 Vladimir Serbinenko + + * configure.ac: Bump version to 1.99. + 2011-05-13 Vladimir Serbinenko Give ATA device a bit more time on first try in order to allow disks diff --git a/configure.ac b/configure.ac index 811bd992d..4a05007fd 100644 --- a/configure.ac +++ b/configure.ac @@ -32,7 +32,7 @@ dnl type, so there is no conflict. Variables with the prefix "TARGET_" dnl (such as TARGET_CC, TARGET_CFLAGS, etc.) are used for the target dnl type. -AC_INIT([GRUB],[1.99~rc2],[bug-grub@gnu.org]) +AC_INIT([GRUB],[1.99],[bug-grub@gnu.org]) AC_CONFIG_AUX_DIR([build-aux]) From 4c2a3b438eadb277a23f9aba650a683cb11d0fb8 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 14 May 2011 12:09:16 +0200 Subject: [PATCH 590/869] * grub-core/term/at_keyboard.c (set1_e0_mapping): Fix swap between PgUp and PgDown. --- ChangeLog | 5 +++++ grub-core/term/at_keyboard.c | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 143fc60f5..398495dea 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-05-14 Vladimir Serbinenko + + * grub-core/term/at_keyboard.c (set1_e0_mapping): Fix swap between + PgUp and PgDown. + 2011-05-13 Vladimir Serbinenko * configure.ac: Bump version to 1.99. diff --git a/grub-core/term/at_keyboard.c b/grub-core/term/at_keyboard.c index 56aa7275e..f0f346b1b 100644 --- a/grub-core/term/at_keyboard.c +++ b/grub-core/term/at_keyboard.c @@ -111,12 +111,12 @@ static const struct {0x38, GRUB_KEYBOARD_KEY_RIGHT_ALT}, {0x47, GRUB_KEYBOARD_KEY_HOME}, {0x48, GRUB_KEYBOARD_KEY_UP}, - {0x49, GRUB_KEYBOARD_KEY_NPAGE}, + {0x49, GRUB_KEYBOARD_KEY_PPAGE}, {0x4b, GRUB_KEYBOARD_KEY_LEFT}, {0x4d, GRUB_KEYBOARD_KEY_RIGHT}, {0x4f, GRUB_KEYBOARD_KEY_END}, {0x50, GRUB_KEYBOARD_KEY_DOWN}, - {0x51, GRUB_KEYBOARD_KEY_PPAGE}, + {0x51, GRUB_KEYBOARD_KEY_NPAGE}, {0x52, GRUB_KEYBOARD_KEY_INSERT}, {0x53, GRUB_KEYBOARD_KEY_DELETE}, }; From d4de6b01e8953039b84205d5ac181cb3615d726e Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 14 May 2011 12:14:00 +0200 Subject: [PATCH 591/869] * grub-core/commands/menuentry.c (grub_cmd_menuentry): Correctly handle class-free menuentries. (grub_normal_add_menu_entry): Add a check to be sure. --- ChangeLog | 6 ++++++ grub-core/commands/menuentry.c | 5 +++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 398495dea..466713bfe 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2011-05-14 Vladimir Serbinenko + + * grub-core/commands/menuentry.c (grub_cmd_menuentry): Correctly + handle class-free menuentries. + (grub_normal_add_menu_entry): Add a check to be sure. + 2011-05-14 Vladimir Serbinenko * grub-core/term/at_keyboard.c (set1_e0_mapping): Fix swap between diff --git a/grub-core/commands/menuentry.c b/grub-core/commands/menuentry.c index 4dab1783a..4849f8bb8 100644 --- a/grub-core/commands/menuentry.c +++ b/grub-core/commands/menuentry.c @@ -91,7 +91,7 @@ grub_normal_add_menu_entry (int argc, const char **args, char **classes, if (! menu_sourcecode) return grub_errno; - if (classes) + if (classes && classes[0]) { int i; for (i = 0; classes[i]; i++); /* count # of menuentry classes */ @@ -255,7 +255,8 @@ grub_cmd_menuentry (grub_extcmd_context_t ctxt, int argc, char **args) if (! ctxt->script) return grub_normal_add_menu_entry (argc, (const char **) args, - ctxt->state[0].args, ctxt->state[1].arg, + (ctxt->state[0].set ? ctxt->state[0].args + : NULL), ctxt->state[1].arg, ctxt->state[2].arg, 0, ctxt->state[3].arg, ctxt->extcmd->cmd->name[0] == 's'); From 2217a1430e285bc78cf595319c128acc8026369d Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 14 May 2011 17:47:59 +0200 Subject: [PATCH 592/869] Handle module_license on windows. * util/grub-pe2elf.c (MODLICENSE_SECTION): New definition. All following sections shifted. (insert_string): Make argument const char * instead of char *. (write_section_data): Handle long section names. Handle module_license. --- ChangeLog | 10 ++++++++++ util/grub-pe2elf.c | 44 +++++++++++++++++++++++++++++--------------- 2 files changed, 39 insertions(+), 15 deletions(-) diff --git a/ChangeLog b/ChangeLog index 466713bfe..80f21841f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2011-05-14 Vladimir Serbinenko + + Handle module_license on windows. + + * util/grub-pe2elf.c (MODLICENSE_SECTION): New definition. All following + sections shifted. + (insert_string): Make argument const char * instead of char *. + (write_section_data): Handle long section names. + Handle module_license. + 2011-05-14 Vladimir Serbinenko * grub-core/commands/menuentry.c (grub_cmd_menuentry): Correctly diff --git a/util/grub-pe2elf.c b/util/grub-pe2elf.c index cf690841f..4b93faa05 100644 --- a/util/grub-pe2elf.c +++ b/util/grub-pe2elf.c @@ -79,11 +79,12 @@ Report bugs to <%s>.\n", program_name, PACKAGE_BUGREPORT); #define BSS_SECTION 4 #define MODNAME_SECTION 5 #define MODDEPS_SECTION 6 -#define SYMTAB_SECTION 7 -#define STRTAB_SECTION 8 +#define MODLICENSE_SECTION 7 +#define SYMTAB_SECTION 8 +#define STRTAB_SECTION 9 -#define REL_SECTION 9 -#define MAX_SECTIONS 12 +#define REL_SECTION 10 +#define MAX_SECTIONS 16 #define STRTAB_BLOCK 256 @@ -96,7 +97,7 @@ int num_sections; grub_uint32_t offset; static int -insert_string (char *name) +insert_string (const char *name) { int len, result; @@ -124,6 +125,8 @@ write_section_data (FILE* fp, char *image, { int *section_map; int i; + char *pe_strtab = (image + pe_chdr->symtab_offset + + pe_chdr->num_symbols * sizeof (struct grub_pe32_symbol)); section_map = xmalloc ((pe_chdr->num_sections + 1) * sizeof (int)); section_map[0] = 0; @@ -131,31 +134,42 @@ write_section_data (FILE* fp, char *image, for (i = 0; i < pe_chdr->num_sections; i++, pe_shdr++) { grub_uint32_t idx; + const char *name = pe_shdr->name; - if (! strcmp (pe_shdr->name, ".text")) + if (name[0] == '/' && isdigit (name[1])) + { + char t[sizeof (pe_shdr->name) + 1]; + memcpy (t, name, sizeof (pe_shdr->name)); + t[sizeof (pe_shdr->name)] = 0; + name = pe_strtab + atoi (t + 1); + } + + if (! strcmp (name, ".text")) { idx = TEXT_SECTION; shdr[idx].sh_flags = SHF_ALLOC | SHF_EXECINSTR; } - else if (! strcmp (pe_shdr->name, ".rdata")) + else if (! strcmp (name, ".rdata")) { idx = RDATA_SECTION; shdr[idx].sh_flags = SHF_ALLOC; } - else if (! strcmp (pe_shdr->name, ".data")) + else if (! strcmp (name, ".data")) { idx = DATA_SECTION; shdr[idx].sh_flags = SHF_ALLOC | SHF_WRITE; } - else if (! strcmp (pe_shdr->name, ".bss")) + else if (! strcmp (name, ".bss")) { idx = BSS_SECTION; shdr[idx].sh_flags = SHF_ALLOC | SHF_WRITE; } - else if (! strcmp (pe_shdr->name, ".modname")) + else if (! strcmp (name, ".modname")) idx = MODNAME_SECTION; - else if (! strcmp (pe_shdr->name, ".moddeps")) + else if (! strcmp (name, ".moddeps")) idx = MODDEPS_SECTION; + else if (strcmp (name, ".module_license") == 0) + idx = MODLICENSE_SECTION; else { section_map[i + 1] = -1; @@ -181,14 +195,14 @@ write_section_data (FILE* fp, char *image, if (pe_shdr->relocations_offset) { - char name[5 + strlen (pe_shdr->name)]; + char relname[5 + strlen (name)]; if (num_sections >= MAX_SECTIONS) grub_util_error ("too many sections"); - sprintf (name, ".rel%s", pe_shdr->name); + sprintf (relname, ".rel%s", name); - shdr[num_sections].sh_name = insert_string (name); + shdr[num_sections].sh_name = insert_string (relname); shdr[num_sections].sh_link = i; shdr[num_sections].sh_info = idx; @@ -197,7 +211,7 @@ write_section_data (FILE* fp, char *image, num_sections++; } else - shdr[idx].sh_name = insert_string (pe_shdr->name); + shdr[idx].sh_name = insert_string (name); } return section_map; From 0cac83df852a8a58d36c0197fb2d3a67fef3488f Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 14 May 2011 17:50:48 +0200 Subject: [PATCH 593/869] * docs/grub.texi (Installation): Fix several outdated claims. --- ChangeLog | 4 ++++ docs/grub.texi | 62 +++++++++++++------------------------------------- 2 files changed, 20 insertions(+), 46 deletions(-) diff --git a/ChangeLog b/ChangeLog index 80f21841f..01f216bfb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2011-05-14 Vladimir Serbinenko + + * docs/grub.texi (Installation): Fix several outdated claims. + 2011-05-14 Vladimir Serbinenko Handle module_license on windows. diff --git a/docs/grub.texi b/docs/grub.texi index 95707e4cc..0b7e1098c 100644 --- a/docs/grub.texi +++ b/docs/grub.texi @@ -528,21 +528,15 @@ system (@pxref{Obtaining and Building GRUB}). You can do this either from the source tarball, or as a package for your OS. After you have done that, you need to install the boot loader on a -drive (floppy or hard disk). There are two ways of doing that - either -using the utility @command{grub-install} (@pxref{Invoking -grub-install}) on a UNIX-like OS, or by running GRUB itself from a -floppy. These are quite similar, however the utility might probe a -wrong BIOS drive, so you should be careful. - -Also, if you install GRUB on a UNIX-like OS, please make sure that you -have an emergency boot disk ready, so that you can rescue your computer -if, by any chance, your hard drive becomes unusable (unbootable). +drive (floppy or hard disk) by using the utility +@command{grub-install} (@pxref{Invoking grub-install}) on a UNIX-like OS. GRUB comes with boot images, which are normally put in the directory -@file{/usr/lib/grub/i386-pc}. Hereafter, the directory where GRUB images are -initially placed (normally @file{/usr/lib/grub/i386-pc}) will be +@file{/usr/lib/grub/-} (for BIOS-based machines +@file{/usr/lib/grub/i386-pc}). Hereafter, the directory where GRUB images are +initially placed (normally @file{/usr/lib/grub/-}) will be called the @dfn{image directory}, and the directory where the boot -loader needs to find them (usually @file{/boot/grub}) will be called +loader needs to find them (usually @file{/boot}) will be called the @dfn{boot directory}. @menu @@ -556,27 +550,18 @@ the @dfn{boot directory}. @node Installing GRUB using grub-install @section Installing GRUB using grub-install -@strong{Caution:} This procedure is definitely less safe, because -there are several ways in which your computer can become -unbootable. For example, most operating systems don't tell GRUB how to -map BIOS drives to OS devices correctly---GRUB merely @dfn{guesses} -the mapping. This will succeed in most cases, but not -always. Therefore, GRUB provides you with a map file called the -@dfn{device map}, which you must fix if it is wrong. @xref{Device -map}, for more details. - For information on where GRUB should be installed on PC BIOS platforms, @pxref{BIOS installation}. -If you still do want to install GRUB under a UNIX-like OS (such +In order to install GRUB under a UNIX-like OS (such as @sc{gnu}), invoke the program @command{grub-install} (@pxref{Invoking grub-install}) as the superuser (@dfn{root}). The usage is basically very simple. You only need to specify one argument to the program, namely, where to install the boot loader. The -argument can be either a device file (like @samp{/dev/hda}) or a -partition specified in GRUB's notation. For example, under Linux the -following will install GRUB into the MBR of the first IDE disk: +argument has to be either a device file (like @samp{/dev/hda}). +For example, under Linux the following will install GRUB into the MBR +of the first IDE disk: @example # @kbd{grub-install /dev/hda} @@ -588,37 +573,22 @@ Likewise, under GNU/Hurd, this has the same effect: # @kbd{grub-install /dev/hd0} @end example -But all the above examples assume that GRUB should use images under -the root directory. If you want GRUB to use images under a directory -other than the root directory, you need to specify the option -@option{--root-directory}. The typical usage is that you create a GRUB +But all the above examples assume that GRUB should put images under +the @file{/boot} directory. If you want GRUB to put images under a directory +other than @file{/boot}, you need to specify the option +@option{--boot-directory}. The typical usage is that you create a GRUB boot floppy with a filesystem. Here is an example: @example @group # @kbd{mke2fs /dev/fd0} # @kbd{mount -t ext2 /dev/fd0 /mnt} -# @kbd{grub-install --root-directory=/mnt fd0} +# @kbd{mkdir /mnt/boot} +# @kbd{grub-install --boot-directory=/mnt/boot /dev/fd0} # @kbd{umount /mnt} @end group @end example -Another example is when you have a separate boot partition -which is mounted at @file{/boot}. Since GRUB is a boot loader, it -doesn't know anything about mountpoints at all. Thus, you need to run -@command{grub-install} like this: - -@example -# @kbd{grub-install --root-directory=/boot /dev/hda} -@end example - -By the way, as noted above, it is quite difficult to guess BIOS drives -correctly under a UNIX-like OS. Thus, @command{grub-install} will prompt -you to check if it could really guess the correct mappings, after the -installation. The format is defined in @ref{Device map}. Please be -quite careful. If the output is wrong, it is unlikely that your -computer will be able to boot with no problem. - Some BIOSes have a bug of exposing the first partition of a USB drive as a floppy instead of exposing the USB drive as a hard disk (they call it ``USB-FDD'' boot). In such cases, you need to install like this: From 25a45338751d8ed2f8bed7231380a4e8183e585c Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 14 May 2011 22:26:52 +0200 Subject: [PATCH 594/869] Fix few potential memory misusage. * grub-core/font/font.c (load_font_index): Don't free char_index to avoid double free. --- ChangeLog | 7 +++++++ grub-core/font/font.c | 13 ++++++++----- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 01f216bfb..f316af0b1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2011-05-14 Vladimir Serbinenko + + Fix few potential memory misusage. + + * grub-core/font/font.c (load_font_index): Don't free char_index to + avoid double free. + 2011-05-14 Vladimir Serbinenko * docs/grub.texi (Installation): Fix several outdated claims. diff --git a/grub-core/font/font.c b/grub-core/font/font.c index ef6caf77b..26eac4c05 100644 --- a/grub-core/font/font.c +++ b/grub-core/font/font.c @@ -316,10 +316,7 @@ load_font_index (grub_file_t file, grub_uint32_t sect_length, struct return 1; font->bmp_idx = grub_malloc (0x10000 * sizeof (grub_uint16_t)); if (!font->bmp_idx) - { - grub_free (font->char_index); - return 1; - } + return 1; grub_memset (font->bmp_idx, 0xff, 0x10000 * sizeof (grub_uint16_t)); @@ -494,7 +491,7 @@ grub_font_load (const char *filename) #endif /* Allocate the font object. */ - font = (grub_font_t) grub_malloc (sizeof (struct grub_font)); + font = (grub_font_t) grub_zalloc (sizeof (struct grub_font)); if (!font) goto fail; @@ -640,6 +637,11 @@ grub_font_load (const char *filename) return 0; fail: + if (file) + grub_file_close (file); + if (font) + font->file = 0; + free_font (font); return 1; } @@ -799,6 +801,7 @@ free_font (grub_font_t font) grub_free (font->name); grub_free (font->family); grub_free (font->char_index); + grub_free (font->bmp_idx); grub_free (font); } } From b25db2188538c628f79ded0a3e17f77ccb8ebfa3 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 14 May 2011 22:29:27 +0200 Subject: [PATCH 595/869] * grub-core/font/font_cmd.c (loadfont_command): Set grub_errno on error if not already done. --- ChangeLog | 8 ++++++++ grub-core/font/font_cmd.c | 6 +++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index f316af0b1..bb4d0aade 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,9 +1,17 @@ +2011-05-14 Vladimir Serbinenko + + * grub-core/font/font_cmd.c (loadfont_command): Set grub_errno + on error if not already done. + 2011-05-14 Vladimir Serbinenko Fix few potential memory misusage. * grub-core/font/font.c (load_font_index): Don't free char_index to avoid double free. + (grub_font_load): Zero-fill font at alloc for safety. + Close file on error. + (free_font): Free bmp_idx. 2011-05-14 Vladimir Serbinenko diff --git a/grub-core/font/font_cmd.c b/grub-core/font/font_cmd.c index 8b00dd8b9..98f0b88d6 100644 --- a/grub-core/font/font_cmd.c +++ b/grub-core/font/font_cmd.c @@ -33,7 +33,11 @@ loadfont_command (grub_command_t cmd __attribute__ ((unused)), while (argc--) if (grub_font_load (*args++) != 0) - return GRUB_ERR_BAD_FONT; + { + if (!grub_errno) + return grub_error (GRUB_ERR_BAD_FONT, "invalid font"); + return grub_errno; + } return GRUB_ERR_NONE; } From 3d2c7e3591e3f0d4949e5822bfafb67f2b0dc476 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 14 May 2011 22:35:56 +0200 Subject: [PATCH 596/869] * grub-core/kern/dl.c (grub_dl_unload): Don't decrease reference counter on dependencies since grub_dl_unref already handles this. --- ChangeLog | 5 +++++ grub-core/kern/dl.c | 3 +-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index bb4d0aade..6777eb0f4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-05-14 Vladimir Serbinenko + + * grub-core/kern/dl.c (grub_dl_unload): Don't decrease reference + counter on dependencies since grub_dl_unref already handles this. + 2011-05-14 Vladimir Serbinenko * grub-core/font/font_cmd.c (loadfont_command): Set grub_errno diff --git a/grub-core/kern/dl.c b/grub-core/kern/dl.c index c5e2888cd..6104f229e 100644 --- a/grub-core/kern/dl.c +++ b/grub-core/kern/dl.c @@ -683,8 +683,7 @@ grub_dl_unload (grub_dl_t mod) { depn = dep->next; - if (! grub_dl_unref (dep->mod)) - grub_dl_unload (dep->mod); + grub_dl_unload (dep->mod); grub_free (dep); } From 576881217f04b6938f3dd8e15ce93ad6fa3170cd Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 14 May 2011 22:42:28 +0200 Subject: [PATCH 597/869] * grub-core/kern/dl.c (grub_dl_load_file): Decrease ref counter rather than resetting it to allow modules to reference themselves in init. --- ChangeLog | 6 ++++++ grub-core/kern/dl.c | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 6777eb0f4..429467d02 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2011-05-14 Vladimir Serbinenko + + * grub-core/kern/dl.c (grub_dl_load_file): Decrease ref counter + rather than resetting it to allow modules to reference themselves + in init. + 2011-05-14 Vladimir Serbinenko * grub-core/kern/dl.c (grub_dl_unload): Don't decrease reference diff --git a/grub-core/kern/dl.c b/grub-core/kern/dl.c index 6104f229e..623e0cbcb 100644 --- a/grub-core/kern/dl.c +++ b/grub-core/kern/dl.c @@ -626,7 +626,7 @@ grub_dl_load_file (const char *filename) return 0; } - mod->ref_count = 0; + mod->ref_count--; return mod; } From de04eecfa9df533f69f59a4be23e1ebbe8fe898a Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 14 May 2011 22:44:53 +0200 Subject: [PATCH 598/869] * grub-core/kern/mm.c (grub_memalign): Disable auto-unloadding of unused modules since currently referrence counter isn't reliable and there isn't much memory to recover there anyway. --- ChangeLog | 6 ++++++ grub-core/kern/mm.c | 2 ++ 2 files changed, 8 insertions(+) diff --git a/ChangeLog b/ChangeLog index 429467d02..a0efb24e8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2011-05-14 Vladimir Serbinenko + + * grub-core/kern/mm.c (grub_memalign): Disable auto-unloadding of + unused modules since currently referrence counter isn't reliable and + there isn't much memory to recover there anyway. + 2011-05-14 Vladimir Serbinenko * grub-core/kern/dl.c (grub_dl_load_file): Decrease ref counter diff --git a/grub-core/kern/mm.c b/grub-core/kern/mm.c index 8d9b5db78..d54f3f240 100644 --- a/grub-core/kern/mm.c +++ b/grub-core/kern/mm.c @@ -311,11 +311,13 @@ grub_memalign (grub_size_t align, grub_size_t size) count++; goto again; +#if 0 case 1: /* Unload unneeded modules. */ grub_dl_unload_unneeded (); count++; goto again; +#endif default: break; From 90c571a47fb9a100938707fdeba81e6d6fea4c33 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 14 May 2011 22:47:28 +0200 Subject: [PATCH 599/869] * util/grub.d/10_linux.in: Autoload gzio since it's needed on some platforms if kernel is compressed. --- ChangeLog | 5 +++++ util/grub.d/10_linux.in | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/ChangeLog b/ChangeLog index a0efb24e8..68a13a72e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-05-14 Vladimir Serbinenko + + * util/grub.d/10_linux.in: Autoload gzio since it's needed on some + platforms if kernel is compressed. + 2011-05-14 Vladimir Serbinenko * grub-core/kern/mm.c (grub_memalign): Disable auto-unloadding of diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in index 3c3a2a5d5..1d1eb403f 100644 --- a/util/grub.d/10_linux.in +++ b/util/grub.d/10_linux.in @@ -98,6 +98,10 @@ EOF EOF fi + cat << EOF + insmod gzio +EOF + if [ x$dirname = x/ ]; then if [ -z "${prepare_root_cache}" ]; then prepare_root_cache="$(prepare_grub_to_access_device ${GRUB_DEVICE} | sed -e "s/^/\t/")" From 6ada82d14df6c66cbb433d383e5f2d86e865d7c2 Mon Sep 17 00:00:00 2001 From: Jordan Uggla Date: Sat, 14 May 2011 22:49:53 +0200 Subject: [PATCH 600/869] * docs/grub.texi (Invoking grub-install): Fix additional outdated claims and add some clarification. --- ChangeLog | 5 +++++ docs/grub.texi | 27 ++++++++++++++++++++------- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index 68a13a72e..9575204c2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-05-14 Jordan Uggla + + * docs/grub.texi (Invoking grub-install): Fix additional outdated claims + and add some clarification. + 2011-05-14 Vladimir Serbinenko * util/grub.d/10_linux.in: Autoload gzio since it's needed on some diff --git a/docs/grub.texi b/docs/grub.texi index 0b7e1098c..b11e3836f 100644 --- a/docs/grub.texi +++ b/docs/grub.texi @@ -4165,15 +4165,28 @@ Print a summary of the command-line options and exit. @item --version Print the version number of GRUB and exit. -@item --root-directory=@var{dir} -Install GRUB images under the directory @var{dir} instead of the root -directory. This option is useful when you want to install GRUB into a -separate partition or a removable disk. Here is an example in which -you have a separate @dfn{boot} partition which is mounted on -@file{/boot}: +@item --boot-directory=@var{dir} +Install GRUB images under the directory @file{@var{dir}/grub/} +This option is useful when you want to install GRUB into a +separate partition or a removable disk. +If this option is not specified then it defaults to @file{/boot}, so @example -@kbd{grub-install --root-directory=/boot hd0} +@kbd{grub-install /dev/sda} +@end example + +is equivalent to + +@example +@kbd{grub-install --boot-directory=/boot/ /dev/sda} +@end example + +Here is an example in which you have a separate @dfn{boot} partition which is +mounted on +@file{/mnt/boot}: + +@example +@kbd{grub-install --boot-directory=/mnt/boot /dev/sdb} @end example @item --recheck From 983b414d776f638e9cb80988fcce7255cf162dd2 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 15 May 2011 10:23:02 +0200 Subject: [PATCH 601/869] * grub-core/fs/btrfs.c (grub_btrfs_read_logical): Silence spurious warning. Move variables before code while on it. --- ChangeLog | 5 +++++ grub-core/fs/btrfs.c | 10 ++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 505be20c2..ab247969e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-05-15 Vladimir Serbinenko + + * grub-core/fs/btrfs.c (grub_btrfs_read_logical): Silence spurious + warning. Move variables before code while on it. + 2011-05-15 Vladimir Serbinenko Fuloong support. diff --git a/grub-core/fs/btrfs.c b/grub-core/fs/btrfs.c index 42aa257d9..59e91b552 100644 --- a/grub-core/fs/btrfs.c +++ b/grub-core/fs/btrfs.c @@ -589,10 +589,14 @@ grub_btrfs_read_logical (struct grub_btrfs_data *data, struct grub_btrfs_key *key; struct grub_btrfs_chunk_item *chunk; grub_uint64_t csize; - grub_err_t err; + grub_err_t err = 0; struct grub_btrfs_key key_out; int challoc = 0; grub_device_t dev; + struct grub_btrfs_key key_in; + grub_size_t chsize; + grub_disk_addr_t chaddr; + grub_dprintf ("btrfs", "searching for laddr %" PRIxGRUB_UINT64_T "\n", addr); for (ptr = data->sblock.bootstrap_mapping; @@ -616,9 +620,7 @@ grub_btrfs_read_logical (struct grub_btrfs_data *data, + sizeof (struct grub_btrfs_chunk_stripe) * grub_le_to_cpu16 (chunk->nstripes); } - struct grub_btrfs_key key_in; - grub_size_t chsize; - grub_disk_addr_t chaddr; + key_in.object_id = GRUB_BTRFS_OBJECT_ID_CHUNK; key_in.type = GRUB_BTRFS_ITEM_TYPE_CHUNK; key_in.offset = addr; From 67b1e5c9079ae6fb734e69aa07a78e6a52d5eb56 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 15 May 2011 12:32:37 +0200 Subject: [PATCH 602/869] Fix compilation errors. * grub-core/term/ns8250.c (serial_get_divisor): Declare 'port' as potentially unused. * grub-core/loader/i386/linux.c (grub_linux_setup_video): Handle GRUB_VIDEO_DRIVER_SIS315PRO. * grub-core/bus/cs5536.c (grub_cs5536_init_geode): Restrict DIVIL init to loongson machines. --- ChangeLog | 11 +++++++++++ grub-core/bus/cs5536.c | 2 ++ grub-core/loader/i386/linux.c | 1 + grub-core/term/ns8250.c | 2 +- 4 files changed, 15 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index a2927df11..98418f4a0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2011-05-15 Vladimir Serbinenko + + Fix compilation errors. + + * grub-core/term/ns8250.c (serial_get_divisor): Declare 'port' as + potentially unused. + * grub-core/loader/i386/linux.c (grub_linux_setup_video): + Handle GRUB_VIDEO_DRIVER_SIS315PRO. + * grub-core/bus/cs5536.c (grub_cs5536_init_geode): Restrict DIVIL init + to loongson machines. + 2011-05-15 Vladimir Serbinenko Several FS mtime support. diff --git a/grub-core/bus/cs5536.c b/grub-core/bus/cs5536.c index f1a564251..ae3c5c878 100644 --- a/grub-core/bus/cs5536.c +++ b/grub-core/bus/cs5536.c @@ -269,6 +269,7 @@ grub_cs5536_init_geode (grub_pci_device_t dev) GRUB_CS5536_LBAR_TURN_ON | GRUB_CS5536_LBAR_PM); /* Setup DIVIL. */ +#ifdef GRUB_MACHINE_MIPS_LOONGSON switch (grub_arch_machine) { case GRUB_ARCH_MACHINE_YEELOONG: @@ -288,6 +289,7 @@ grub_cs5536_init_geode (grub_pci_device_t dev) | GRUB_CS5536_MSR_DIVIL_LEG_IO_RTC_ENABLE1); break; } +#endif grub_cs5536_write_msr (dev, GRUB_CS5536_MSR_DIVIL_IRQ_MAPPER_PRIMARY_MASK, (~GRUB_CS5536_DIVIL_LPC_INTERRUPTS) & 0xffff); grub_cs5536_write_msr (dev, GRUB_CS5536_MSR_DIVIL_IRQ_MAPPER_LPC_MASK, diff --git a/grub-core/loader/i386/linux.c b/grub-core/loader/i386/linux.c index f19f471ab..dc2af4093 100644 --- a/grub-core/loader/i386/linux.c +++ b/grub-core/loader/i386/linux.c @@ -367,6 +367,7 @@ grub_linux_setup_video (struct linux_kernel_params *params) /* FIXME: check if better id is available. */ case GRUB_VIDEO_DRIVER_SM712: + case GRUB_VIDEO_DRIVER_SIS315PRO: case GRUB_VIDEO_DRIVER_VGA: case GRUB_VIDEO_DRIVER_CIRRUS: case GRUB_VIDEO_DRIVER_BOCHS: diff --git a/grub-core/term/ns8250.c b/grub-core/term/ns8250.c index b63ee14d9..996fc81f3 100644 --- a/grub-core/term/ns8250.c +++ b/grub-core/term/ns8250.c @@ -37,7 +37,7 @@ static const grub_port_t serial_hw_io_addr[] = GRUB_MACHINE_SERIAL_PORTS; /* Convert speed to divisor. */ static unsigned short -serial_get_divisor (const struct grub_serial_port *port, +serial_get_divisor (const struct grub_serial_port *port __attribute__ ((unused)), const struct grub_serial_config *config) { unsigned int i; From c3fc520c0d5b05cc3f75b20a42f51f8fd5ca8519 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 15 May 2011 15:41:23 +0200 Subject: [PATCH 603/869] * grub-core/bus/cs5536.c: Don't include grub/machine/kernel.h on non-loongson. * grub-core/kern/mips/dl.c (grub_arch_dl_init_linker): Fix argument to grub_dl_register_symbol. --- ChangeLog | 7 +++++++ grub-core/bus/cs5536.c | 2 ++ grub-core/kern/mips/dl.c | 2 +- 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 98418f4a0..cdf602203 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2011-05-15 Vladimir Serbinenko + + * grub-core/bus/cs5536.c: Don't include grub/machine/kernel.h on + non-loongson. + * grub-core/kern/mips/dl.c (grub_arch_dl_init_linker): Fix argument + to grub_dl_register_symbol. + 2011-05-15 Vladimir Serbinenko Fix compilation errors. diff --git a/grub-core/bus/cs5536.c b/grub-core/bus/cs5536.c index ae3c5c878..58ffeb60a 100644 --- a/grub-core/bus/cs5536.c +++ b/grub-core/bus/cs5536.c @@ -21,7 +21,9 @@ #include #include #include +#ifdef GRUB_MACHINE_MIPS_LOONGSON #include +#endif #include diff --git a/grub-core/kern/mips/dl.c b/grub-core/kern/mips/dl.c index e17e9f30b..2ddbed3e6 100644 --- a/grub-core/kern/mips/dl.c +++ b/grub-core/kern/mips/dl.c @@ -234,6 +234,6 @@ grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr) void grub_arch_dl_init_linker (void) { - grub_dl_register_symbol ("__gnu_local_gp", &__gnu_local_gp_dummy, 0); + grub_dl_register_symbol ("__gnu_local_gp", &__gnu_local_gp_dummy, 0, 0); } From 736e0ade54b07ab10e8d98b54ecb6c43e779b04d Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 16 May 2011 02:34:58 +0200 Subject: [PATCH 604/869] Fuloong video init support. * include/grub/vga.h (grub_vga_write_arx): inb monochrome address as well. (grub_vga_read_arx): New function. * grub-core/video/sis315pro.c (GRUB_SIS315PRO_MMIO_SPACE): New definition. (framebuffer): New members io, mmioptr and mmiobase. (read_sis_cmd): New function. (write_sis_cmd): Likewise. (grub_video_sis315pro_setup): Do the initialisation. Use 640x480 rather than 640x400. * grub-core/video/sis315_init.c: New file. --- grub-core/video/sis315_init.c | 158 ++++++++++++++++++++++++++ grub-core/video/sis315pro.c | 208 +++++++++++++++++++++++++++++++++- include/grub/vga.h | 15 ++- 3 files changed, 377 insertions(+), 4 deletions(-) create mode 100644 grub-core/video/sis315_init.c diff --git a/grub-core/video/sis315_init.c b/grub-core/video/sis315_init.c new file mode 100644 index 000000000..ae5c1419c --- /dev/null +++ b/grub-core/video/sis315_init.c @@ -0,0 +1,158 @@ +static const struct { grub_uint8_t reg; grub_uint8_t val; } sr_dump [] = +{ + { 0x28, 0x81 }, + { 0x2a, 0x00 }, + { 0x29, 0xe1 }, + { 0x2b, 0x81 }, + { 0x2d, 0x00 }, + { 0x2c, 0xe1 }, + { 0x2e, 0x81 }, + { 0x30, 0x00 }, + { 0x2f, 0xe1 }, + { 0x28, 0x01 }, + { 0x29, 0x22 }, + { 0x28, 0x3b }, + { 0x29, 0x22 }, + { 0x2a, 0x01 }, + { 0x2e, 0x01 }, + { 0x2f, 0x22 }, + { 0x2e, 0x3b }, + { 0x2f, 0x22 }, + { 0x30, 0x01 }, + { 0x15, 0x00 }, + { 0x1b, 0x30 }, + + { 0x16, 0x0f }, + { 0x16, 0x8f }, + { 0x17, 0xba }, + { 0x16, 0x0f }, + { 0x16, 0x8f }, + { 0x1f, 0x00 }, + { 0x20, 0x20 }, + { 0x23, 0xf6 }, + { 0x24, 0x0d }, + { 0x25, 0x33 }, + { 0x21, 0x84 }, + { 0x22, 0x00 }, + { 0x27, 0x1f }, + { 0x31, 0x00 }, + { 0x33, 0x00 }, + { 0x32, 0x11 }, + + { 0x25, 0x33 }, + + { 0x05, 0x86 }, + { 0x01, 0x20 }, + { 0x32, 0x11 }, + { 0x1e, 0x00 }, + { 0x1d, 0x00 }, + { 0x00, 0x03 }, + { 0x01, 0x21 }, + { 0x02, 0x0f }, + { 0x03, 0x00 }, + { 0x04, 0x0e }, + + { 0x0a, 0x00 }, + { 0x0b, 0x00 }, + { 0x0c, 0x00 }, + { 0x0d, 0x00 }, + { 0x0e, 0x00 }, + { 0x37, 0x00 }, + + { 0x0a, 0x00 }, + { 0x0b, 0x00 }, + { 0x0c, 0x05 }, + { 0x0e, 0x00 }, + + { 0x0e, 0x00 }, + + { 0x10, 0x0b }, + { 0x31, 0x00 }, + { 0x2b, 0x01 }, + { 0x2c, 0xe1 }, + { 0x2b, 0x1b }, + { 0x2c, 0xe1 }, + { 0x2d, 0x01 }, + { 0x3d, 0x00 }, + { 0x08, 0x84 }, + { 0x09, 0x00 }, + { 0x3d, 0x01 }, + { 0x1f, 0x00 }, + { 0x06, 0x02 }, + + { 0x0f, 0x00 }, + { 0x17, 0xba }, + { 0x21, 0xa4 }, + { 0x32, 0x11 }, + { 0x07, 0x18 }, + + { 0x1d, 0x00 }, + { 0x1d, 0x00 }, + { 0x1d, 0x00 }, + { 0x1d, 0x00 }, + { 0x1d, 0x00 }, + { 0x1d, 0x00 }, + { 0x1d, 0x00 }, + { 0x1d, 0x00 }, + { 0x1d, 0x00 }, + { 0x1d, 0x00 }, + { 0x1d, 0x00 }, + { 0x1d, 0x00 }, + { 0x1d, 0x00 }, + { 0x1d, 0x00 }, + { 0x1d, 0x00 }, + { 0x1d, 0x00 }, + { 0x1d, 0x00 }, + + { 0x01, 0x01 }, + { 0x21, 0x84 }, + { 0x01, 0x21 }, + { 0x16, 0x8f }, + { 0x18, 0xa9 }, + { 0x19, 0xa0 }, + { 0x1b, 0x30 }, + { 0x17, 0xb8 }, + { 0x19, 0xa3 }, + { 0x13, 0x00 }, + { 0x14, 0x00 }, + { 0x14, 0x02 }, + { 0x15, 0x00 }, + { 0x16, 0x0f }, + { 0x16, 0x8f }, + { 0x1d, 0x00 }, + { 0x14, 0x00 }, + { 0x14, 0x01 }, + { 0x15, 0x00 }, + { 0x16, 0x0f }, + { 0x16, 0x8f }, + { 0x1d, 0x00 }, + { 0x14, 0x01 }, + { 0x14, 0x01 }, + { 0x15, 0x10 }, + { 0x13, 0x35 }, + { 0x14, 0x51 }, + { 0x16, 0x0f }, + { 0x16, 0x8f }, + { 0x1d, 0x00 }, + { 0x1d, 0x00 }, + { 0x1d, 0x11 }, + { 0x1d, 0x11 }, + { 0x1d, 0x00 }, + { 0x1d, 0x00 }, + { 0x1d, 0x00 }, + { 0x17, 0xba }, + { 0x19, 0xa0 }, + { 0x19, 0xa0 }, + { 0x01, 0x01 }, + { 0x16, 0x0f }, + { 0x18, 0xa9 }, + { 0x19, 0xa0 }, + { 0x1b, 0x30 }, + { 0x21, 0xa4 }, + { 0x05, 0x86 }, +}; + +static const grub_uint8_t gr[] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x05, 0x0f, + 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +}; diff --git a/grub-core/video/sis315pro.c b/grub-core/video/sis315pro.c index 59ff6432d..22064c91e 100644 --- a/grub-core/video/sis315pro.c +++ b/grub-core/video/sis315pro.c @@ -30,6 +30,7 @@ #define GRUB_SIS315PRO_PCIID 0x03251039 #define GRUB_SIS315PRO_TOTAL_MEMORY_SPACE 0x800000 +#define GRUB_SIS315PRO_MMIO_SPACE 0x1000 static struct { @@ -39,9 +40,26 @@ static struct grub_uint8_t *ptr; int mapped; grub_uint32_t base; + grub_uint32_t mmiobase; + volatile grub_uint32_t *mmioptr; grub_pci_device_t dev; + grub_port_t io; } framebuffer; +static grub_uint8_t +read_sis_cmd (grub_uint8_t addr) +{ + grub_outb (addr, framebuffer.io + 0x44); + return grub_inb (framebuffer.io + 0x45); +} + +static void +write_sis_cmd (grub_uint8_t val, grub_uint8_t addr) +{ + grub_outb (addr, framebuffer.io + 0x44); + grub_outb (val, framebuffer.io + 0x45); +} + #ifndef TEST static grub_err_t grub_video_sis315pro_video_init (void) @@ -63,6 +81,8 @@ grub_video_sis315pro_video_fini (void) } #endif +#include "sis315_init.c" + static grub_err_t grub_video_sis315pro_setup (unsigned int width, unsigned int height, unsigned int mode_type, @@ -71,6 +91,7 @@ grub_video_sis315pro_setup (unsigned int width, unsigned int height, int depth; grub_err_t err; int found = 0; + unsigned i; #ifndef TEST auto int NESTED_FUNC_ATTR find_card (grub_pci_device_t dev, grub_pci_id_t pciid __attribute__ ((unused))); @@ -89,7 +110,12 @@ grub_video_sis315pro_setup (unsigned int width, unsigned int height, found = 1; addr = grub_pci_make_address (dev, GRUB_PCI_REG_ADDRESS_REG0); - framebuffer.base = grub_pci_read (addr); + framebuffer.base = grub_pci_read (addr) & GRUB_PCI_ADDR_MEM_MASK; + addr = grub_pci_make_address (dev, GRUB_PCI_REG_ADDRESS_REG1); + framebuffer.mmiobase = grub_pci_read (addr) & GRUB_PCI_ADDR_MEM_MASK; + addr = grub_pci_make_address (dev, GRUB_PCI_REG_ADDRESS_REG2); + framebuffer.io = (grub_pci_read (addr) & GRUB_PCI_ADDR_IO_MASK) + + GRUB_MACHINE_PCI_IO_BASE; framebuffer.dev = dev; return 1; @@ -99,7 +125,7 @@ grub_video_sis315pro_setup (unsigned int width, unsigned int height, depth = (mode_type & GRUB_VIDEO_MODE_TYPE_DEPTH_MASK) >> GRUB_VIDEO_MODE_TYPE_DEPTH_POS; - if ((width != 640 && width != 0) || (height != 400 && height != 0) + if ((width != 640 && width != 0) || (height != 480 && height != 0) || (depth != 8 && depth != 0)) return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, "Only 640x400x8 is supported"); @@ -110,7 +136,7 @@ grub_video_sis315pro_setup (unsigned int width, unsigned int height, #endif /* Fill mode info details. */ framebuffer.mode_info.width = 640; - framebuffer.mode_info.height = 400; + framebuffer.mode_info.height = 480; framebuffer.mode_info.mode_type = GRUB_VIDEO_MODE_TYPE_INDEX_COLOR; framebuffer.mode_info.bpp = 8; framebuffer.mode_info.bytes_per_pixel = 1; @@ -129,12 +155,49 @@ grub_video_sis315pro_setup (unsigned int width, unsigned int height, = grub_video_get_blit_format (&framebuffer.mode_info); #endif +#ifndef TEST + if (found && (framebuffer.base == 0 || framebuffer.mmiobase == 0)) + { + grub_pci_address_t addr; + /* FIXME: choose address dynamically if needed. */ + framebuffer.base = 0x40000000; + framebuffer.mmiobase = 0x04000000; + framebuffer.io = 0xb300; + + addr = grub_pci_make_address (framebuffer.dev, GRUB_PCI_REG_ADDRESS_REG0); + grub_pci_write (addr, framebuffer.base | GRUB_PCI_ADDR_MEM_PREFETCH); + + addr = grub_pci_make_address (framebuffer.dev, GRUB_PCI_REG_ADDRESS_REG1); + grub_pci_write (addr, framebuffer.mmiobase); + + addr = grub_pci_make_address (framebuffer.dev, GRUB_PCI_REG_ADDRESS_REG2); + grub_pci_write (addr, framebuffer.io | GRUB_PCI_ADDR_SPACE_IO); + + /* Set latency. */ + addr = grub_pci_make_address (framebuffer.dev, GRUB_PCI_REG_CACHELINE); + grub_pci_write (addr, 0x80004700); + + /* Enable address spaces. */ + addr = grub_pci_make_address (framebuffer.dev, GRUB_PCI_REG_COMMAND); + grub_pci_write (addr, 0x7); + + addr = grub_pci_make_address (framebuffer.dev, 0x30); + grub_pci_write (addr, 0x04060001); + + framebuffer.io += GRUB_MACHINE_PCI_IO_BASE; + } +#endif + + /* We can safely discard volatile attribute. */ #ifndef TEST framebuffer.ptr = (void *) grub_pci_device_map_range (framebuffer.dev, framebuffer.base, GRUB_SIS315PRO_TOTAL_MEMORY_SPACE); + framebuffer.mmioptr = grub_pci_device_map_range (framebuffer.dev, + framebuffer.mmiobase, + GRUB_SIS315PRO_MMIO_SPACE); #endif framebuffer.mapped = 1; @@ -144,6 +207,145 @@ grub_video_sis315pro_setup (unsigned int width, unsigned int height, framebuffer.mode_info.height * framebuffer.mode_info.pitch); #endif + grub_outb (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_28MHZ + | GRUB_VGA_IO_MISC_ENABLE_VRAM_ACCESS + | GRUB_VGA_IO_MISC_COLOR, + GRUB_VGA_IO_MISC_WRITE + GRUB_MACHINE_PCI_IO_BASE); + + grub_vga_sr_write (0x86, 5); + for (i = 6; i <= 0x27; i++) + grub_vga_sr_write (0, i); + + for (i = 0x31; i <= 0x3d; i++) + grub_vga_sr_write (0, i); + + for (i = 0; i < ARRAY_SIZE (sr_dump); i++) + grub_vga_sr_write (sr_dump[i].val, sr_dump[i].reg); + + for (i = 0x30; i < 0x40; i++) + grub_vga_cr_write (0, i); + + grub_vga_cr_write (0x77, 0x40); + grub_vga_cr_write (0x77, 0x41); + grub_vga_cr_write (0x00, 0x42); + grub_vga_cr_write (0x5b, 0x43); + grub_vga_cr_write (0x00, 0x44); + grub_vga_cr_write (0x23, 0x48); + grub_vga_cr_write (0xaa, 0x49); + grub_vga_cr_write (0x02, 0x37); + grub_vga_cr_write (0x20, 0x5b); + grub_vga_cr_write (0x00, 0x83); + grub_vga_cr_write (0x80, 0x63); + + grub_vga_cr_write (0x0c, GRUB_VGA_CR_VSYNC_END); + grub_vga_cr_write (0x5f, GRUB_VGA_CR_HTOTAL); + grub_vga_cr_write (0x4f, GRUB_VGA_CR_HORIZ_END); + grub_vga_cr_write (0x50, GRUB_VGA_CR_HBLANK_START); + grub_vga_cr_write (0x82, GRUB_VGA_CR_HBLANK_END); + grub_vga_cr_write (0x54, GRUB_VGA_CR_HORIZ_SYNC_PULSE_START); + grub_vga_cr_write (0x80, GRUB_VGA_CR_HORIZ_SYNC_PULSE_END); + grub_vga_cr_write (0x0b, GRUB_VGA_CR_VERT_TOTAL); + grub_vga_cr_write (0x3e, GRUB_VGA_CR_OVERFLOW); + grub_vga_cr_write (0x00, GRUB_VGA_CR_BYTE_PANNING); + grub_vga_cr_write (0x40, GRUB_VGA_CR_CELL_HEIGHT); + grub_vga_cr_write (0x00, GRUB_VGA_CR_CURSOR_START); + grub_vga_cr_write (0x00, GRUB_VGA_CR_CURSOR_END); + grub_vga_cr_write (0x00, GRUB_VGA_CR_START_ADDR_HIGH_REGISTER); + grub_vga_cr_write (0x00, GRUB_VGA_CR_START_ADDR_LOW_REGISTER); + grub_vga_cr_write (0x00, GRUB_VGA_CR_CURSOR_ADDR_HIGH); + grub_vga_cr_write (0x00, GRUB_VGA_CR_CURSOR_ADDR_LOW); + grub_vga_cr_write (0xea, GRUB_VGA_CR_VSYNC_START); + grub_vga_cr_write (0x8c, GRUB_VGA_CR_VSYNC_END); + grub_vga_cr_write (0xdf, GRUB_VGA_CR_VDISPLAY_END); + grub_vga_cr_write (0x28, GRUB_VGA_CR_PITCH); + grub_vga_cr_write (0x40, GRUB_VGA_CR_UNDERLINE_LOCATION); + grub_vga_cr_write (0xe7, GRUB_VGA_CR_VERTICAL_BLANK_START); + grub_vga_cr_write (0x04, GRUB_VGA_CR_VERTICAL_BLANK_END); + grub_vga_cr_write (0xa3, GRUB_VGA_CR_MODE); + grub_vga_cr_write (0xff, GRUB_VGA_CR_LINE_COMPARE); + + grub_vga_cr_write (0x0c, GRUB_VGA_CR_VSYNC_END); + grub_vga_cr_write (0x5f, GRUB_VGA_CR_HTOTAL); + grub_vga_cr_write (0x4f, GRUB_VGA_CR_HORIZ_END); + grub_vga_cr_write (0x50, GRUB_VGA_CR_HBLANK_START); + grub_vga_cr_write (0x82, GRUB_VGA_CR_HBLANK_END); + grub_vga_cr_write (0x55, GRUB_VGA_CR_HORIZ_SYNC_PULSE_START); + grub_vga_cr_write (0x81, GRUB_VGA_CR_HORIZ_SYNC_PULSE_END); + grub_vga_cr_write (0x0b, GRUB_VGA_CR_VERT_TOTAL); + grub_vga_cr_write (0x3e, GRUB_VGA_CR_OVERFLOW); + grub_vga_cr_write (0xe9, GRUB_VGA_CR_VSYNC_START); + grub_vga_cr_write (0x8b, GRUB_VGA_CR_VSYNC_END); + grub_vga_cr_write (0xdf, GRUB_VGA_CR_VDISPLAY_END); + grub_vga_cr_write (0xe7, GRUB_VGA_CR_VERTICAL_BLANK_START); + grub_vga_cr_write (0x04, GRUB_VGA_CR_VERTICAL_BLANK_END); + grub_vga_cr_write (0x40, GRUB_VGA_CR_CELL_HEIGHT); + grub_vga_cr_write (0x50, GRUB_VGA_CR_PITCH); + + grub_vga_cr_write (0x00, 0x19); + grub_vga_cr_write (0x00, 0x1a); + grub_vga_cr_write (0x6c, 0x52); + grub_vga_cr_write (0x2e, 0x34); + grub_vga_cr_write (0x00, 0x31); + + + grub_vga_cr_write (0, GRUB_VGA_CR_START_ADDR_HIGH_REGISTER); + grub_vga_cr_write (0, GRUB_VGA_CR_START_ADDR_LOW_REGISTER); + + for (i = 0; i < 16; i++) + grub_vga_write_arx (i, i); + grub_vga_write_arx (1, GRUB_VGA_ARX_MODE); + grub_vga_write_arx (0, GRUB_VGA_ARX_OVERSCAN); + grub_vga_write_arx (0, GRUB_VGA_ARX_COLOR_PLANE_ENABLE); + grub_vga_write_arx (0, GRUB_VGA_ARX_HORIZONTAL_PANNING); + grub_vga_write_arx (0, GRUB_VGA_ARX_COLOR_SELECT); + + grub_outb (0xff, GRUB_VGA_IO_PIXEL_MASK + GRUB_MACHINE_PCI_IO_BASE); + + for (i = 0; i < ARRAY_SIZE (gr); i++) + grub_vga_gr_write (gr[i], i); + + for (i = 0; i < GRUB_VIDEO_FBSTD_NUMCOLORS; i++) + grub_vga_palette_write (i, grub_video_fbstd_colors[i].r, + grub_video_fbstd_colors[i].g, + grub_video_fbstd_colors[i].b); + +#if 1 + { + if (read_sis_cmd (0x5) != 0xa1) + write_sis_cmd (0x86, 0x5); + + write_sis_cmd (read_sis_cmd (0x20) | 0xa1, 0x20); + write_sis_cmd (read_sis_cmd (0x1e) | 0xda, 0x1e); + +#define IND_SIS_CMDQUEUE_SET 0x26 +#define IND_SIS_CMDQUEUE_THRESHOLD 0x27 + +#define COMMAND_QUEUE_THRESHOLD 0x1F +#define SIS_CMD_QUEUE_RESET 0x01 + +#define SIS_AGP_CMDQUEUE_ENABLE 0x80 /* 315/330/340 series SR26 */ +#define SIS_VRAM_CMDQUEUE_ENABLE 0x40 +#define SIS_MMIO_CMD_ENABLE 0x20 +#define SIS_CMD_QUEUE_SIZE_512k 0x00 +#define SIS_CMD_QUEUE_SIZE_1M 0x04 +#define SIS_CMD_QUEUE_SIZE_2M 0x08 +#define SIS_CMD_QUEUE_SIZE_4M 0x0C +#define SIS_CMD_QUEUE_RESET 0x01 +#define SIS_CMD_AUTO_CORR 0x02 + + + write_sis_cmd (COMMAND_QUEUE_THRESHOLD, IND_SIS_CMDQUEUE_THRESHOLD); + write_sis_cmd (SIS_CMD_QUEUE_RESET, IND_SIS_CMDQUEUE_SET); + framebuffer.mmioptr[0x85C4 / 4] = framebuffer.mmioptr[0x85C8 / 4]; + write_sis_cmd (SIS_MMIO_CMD_ENABLE | SIS_CMD_AUTO_CORR, IND_SIS_CMDQUEUE_SET); + framebuffer.mmioptr[0x85C0 / 4] = (0x1000000 - (512 * 1024)); + } +#endif + #ifndef TEST err = grub_video_fb_create_render_target_from_pointer (&framebuffer .render_target, diff --git a/include/grub/vga.h b/include/grub/vga.h index 7f112d83a..bf4439599 100644 --- a/include/grub/vga.h +++ b/include/grub/vga.h @@ -84,8 +84,8 @@ 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_EXTERNAL_CLOCK_0 = 0x08, GRUB_VGA_IO_MISC_UPPER_64K = 0x20, GRUB_VGA_IO_MISC_NEGATIVE_HORIZ_POLARITY = 0x40, GRUB_VGA_IO_MISC_NEGATIVE_VERT_POLARITY = 0x80, @@ -290,11 +290,24 @@ 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_inb (GRUB_MACHINE_PCI_IO_BASE + 0x3ba); + 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); } +static inline grub_uint8_t +grub_vga_read_arx (grub_uint8_t addr) +{ + grub_uint8_t val; + 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); + val = grub_inb (GRUB_MACHINE_PCI_IO_BASE + GRUB_VGA_IO_ARX_READ); + grub_outb (val, GRUB_MACHINE_PCI_IO_BASE + GRUB_VGA_IO_ARX); + return val; +} + struct grub_video_hw_config { unsigned vertical_total; From 638dbe4f27f481d57de39f2847e4c2b8992dbfcf Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 16 May 2011 02:35:47 +0200 Subject: [PATCH 605/869] add changelog entry --- ChangeLog | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/ChangeLog b/ChangeLog index cdf602203..d0b3b1a11 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,19 @@ +2011-05-16 Vladimir Serbinenko + + Fuloong video init support. + + * include/grub/vga.h (grub_vga_write_arx): inb monochrome address as + well. + (grub_vga_read_arx): New function. + * grub-core/video/sis315pro.c (GRUB_SIS315PRO_MMIO_SPACE): New + definition. + (framebuffer): New members io, mmioptr and mmiobase. + (read_sis_cmd): New function. + (write_sis_cmd): Likewise. + (grub_video_sis315pro_setup): Do the initialisation. Use 640x480 + rather than 640x400. + * grub-core/video/sis315_init.c: New file. + 2011-05-15 Vladimir Serbinenko * grub-core/bus/cs5536.c: Don't include grub/machine/kernel.h on From ff44d107adc5e85155b212211d4e0893d15da30c Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 16 May 2011 02:39:25 +0200 Subject: [PATCH 606/869] Skip incorrect USB devices. * grub-core/bus/usb/usb.c (grub_usb_device_initialize): Fail if configcnt == 0. * include/grub/usb.h (grub_usb_err_t): New enum value GRUB_USB_ERR_BADDEVICE. --- ChangeLog | 9 +++++++++ grub-core/bus/usb/usb.c | 6 ++++++ include/grub/usb.h | 3 ++- 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index d0b3b1a11..18a95a58e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2011-05-16 Vladimir Serbinenko + + Skip incorrect USB devices. + + * grub-core/bus/usb/usb.c (grub_usb_device_initialize): Fail if + configcnt == 0. + * include/grub/usb.h (grub_usb_err_t): New enum value + GRUB_USB_ERR_BADDEVICE. + 2011-05-16 Vladimir Serbinenko Fuloong video init support. diff --git a/grub-core/bus/usb/usb.c b/grub-core/bus/usb/usb.c index 005d3bcf0..cde57ced8 100644 --- a/grub-core/bus/usb/usb.c +++ b/grub-core/bus/usb/usb.c @@ -185,6 +185,12 @@ grub_usb_device_initialize (grub_usb_device_t dev) for (i = 0; i < 8; i++) dev->config[i].descconf = NULL; + if (descdev->configcnt == 0) + { + err = GRUB_USB_ERR_BADDEVICE; + goto fail; + } + for (i = 0; i < descdev->configcnt; i++) { int pos; diff --git a/include/grub/usb.h b/include/grub/usb.h index 6f838e4f9..ee133dbf5 100644 --- a/include/grub/usb.h +++ b/include/grub/usb.h @@ -38,7 +38,8 @@ typedef enum GRUB_USB_ERR_BABBLE, GRUB_USB_ERR_TIMEOUT, GRUB_USB_ERR_BITSTUFF, - GRUB_USB_ERR_UNRECOVERABLE + GRUB_USB_ERR_UNRECOVERABLE, + GRUB_USB_ERR_BADDEVICE } grub_usb_err_t; typedef enum From 153a4b552de2dce36071cb3edd532330e67cd477 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 16 May 2011 08:50:21 +0200 Subject: [PATCH 607/869] * grub-core/bus/usb/usbhub.c (attach_root_port): Wait 10ms after enabling port. --- ChangeLog | 5 +++++ grub-core/bus/usb/usbhub.c | 2 ++ 2 files changed, 7 insertions(+) diff --git a/ChangeLog b/ChangeLog index 18a95a58e..fc4d68013 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-05-16 Vladimir Serbinenko + + * grub-core/bus/usb/usbhub.c (attach_root_port): Wait 10ms + after enabling port. + 2011-05-16 Vladimir Serbinenko Skip incorrect USB devices. diff --git a/grub-core/bus/usb/usbhub.c b/grub-core/bus/usb/usbhub.c index 82bb2da1c..fff94a3fc 100644 --- a/grub-core/bus/usb/usbhub.c +++ b/grub-core/bus/usb/usbhub.c @@ -215,6 +215,8 @@ attach_root_port (struct grub_usb_hub *hub, int portno, return; hub->controller->dev->pending_reset = grub_get_time_ms () + 5000; + grub_millisleep (10); + /* Enable the port and create a device. */ dev = grub_usb_hub_add_dev (hub->controller, speed); hub->controller->dev->pending_reset = 0; From c8ecc840d7fa7111577ec3882623bb4b4f496e55 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 16 May 2011 08:51:55 +0200 Subject: [PATCH 608/869] * grub-core/bus/pci.c (grub_memalign_dma32): Always allocate in 64-byte blocks. --- ChangeLog | 5 +++++ grub-core/bus/pci.c | 7 ++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index fc4d68013..868391294 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-05-16 Vladimir Serbinenko + + * grub-core/bus/pci.c (grub_memalign_dma32): Always allocate in 64-byte + blocks. + 2011-05-16 Vladimir Serbinenko * grub-core/bus/usb/usbhub.c (attach_root_port): Wait 10ms diff --git a/grub-core/bus/pci.c b/grub-core/bus/pci.c index 4212905f0..51006a20e 100644 --- a/grub-core/bus/pci.c +++ b/grub-core/bus/pci.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include @@ -30,7 +31,11 @@ GRUB_MOD_LICENSE ("GPLv3+"); struct grub_pci_dma_chunk * grub_memalign_dma32 (grub_size_t align, grub_size_t size) { - void *ret = grub_memalign (align, size); + void *ret; + if (align < 64) + align = 64; + size = ALIGN_UP (size, align); + ret = grub_memalign (align, size); if (!ret) return 0; grub_arch_sync_dma_caches (ret, size); From 8e29b2ffe3c328d3b73fd7fc14ac4d6521154a08 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 16 May 2011 21:50:14 +0200 Subject: [PATCH 609/869] set id on arc disks --- grub-core/disk/arc/arcdisk.c | 65 +++++++++++++++++++++++++++++++++++- 1 file changed, 64 insertions(+), 1 deletion(-) diff --git a/grub-core/disk/arc/arcdisk.c b/grub-core/disk/arc/arcdisk.c index 62732c7ad..e8416634a 100644 --- a/grub-core/disk/arc/arcdisk.c +++ b/grub-core/disk/arc/arcdisk.c @@ -25,6 +25,59 @@ static grub_arc_fileno_t last_handle = 0; static char *last_path = NULL; +static int lnum = 0; + +struct arcdisk_hash_ent +{ + char *devpath; + int num; + struct arcdisk_hash_ent *next; +}; + +#define ARCDISK_HASH_SZ 8 +static struct arcdisk_hash_ent *arcdisk_hash[ARCDISK_HASH_SZ]; + +static int +arcdisk_hash_fn (const char *devpath) +{ + int hash = 0; + while (*devpath) + hash ^= *devpath++; + return (hash & (ARCDISK_HASH_SZ - 1)); +} + +static struct arcdisk_hash_ent * +arcdisk_hash_find (const char *devpath) +{ + struct arcdisk_hash_ent *p = arcdisk_hash[arcdisk_hash_fn (devpath)]; + + while (p) + { + if (!grub_strcmp (p->devpath, devpath)) + break; + p = p->next; + } + return p; +} + +static struct arcdisk_hash_ent * +arcdisk_hash_add (char *devpath) +{ + struct arcdisk_hash_ent *p; + struct arcdisk_hash_ent **head = &arcdisk_hash[arcdisk_hash_fn(devpath)]; + + p = grub_malloc (sizeof (*p)); + if (!p) + return NULL; + + p->devpath = devpath; + p->next = *head; + p->num = lnum++; + *head = p; + return p; +} + + static int grub_arcdisk_iterate (int (*hook_in) (const char *name)) { @@ -81,6 +134,8 @@ grub_arcdisk_open (const char *name, grub_disk_t disk) grub_err_t err; grub_arc_err_t r; struct grub_arc_fileinfo info; + struct arcdisk_hash_ent *hash; + if (grub_memcmp (name, "arc/", 4) != 0) return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "not arc device"); fullname = grub_malloc (2 * grub_strlen (name) + sizeof (RAW_SUFFIX)); @@ -114,6 +169,13 @@ grub_arcdisk_open (const char *name, grub_disk_t disk) grub_memcpy (optr, RAW_SUFFIX, sizeof (RAW_SUFFIX)); disk->data = fullname; grub_dprintf ("arcdisk", "opening %s\n", fullname); + + hash = arcdisk_hash_find (fullname); + if (!hash) + hash = arcdisk_hash_add (fullname); + if (!hash) + return grub_errno; + err = reopen (fullname); if (err) return err; @@ -147,7 +209,8 @@ grub_arcdisk_open (const char *name, grub_disk_t disk) } else disk->total_sectors = (info.end >> 9); - disk->id = 0; /* XXX */ + + disk->id = hash->num; return GRUB_ERR_NONE; } From 276ef9be21c60e2f0ff18daf7278de4a9f2ced9c Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 16 May 2011 21:50:24 +0200 Subject: [PATCH 610/869] Fix install message --- util/grub-install.in | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/util/grub-install.in b/util/grub-install.in index 0e0dfe920..ad6ea1037 100644 --- a/util/grub-install.in +++ b/util/grub-install.in @@ -621,8 +621,7 @@ elif [ "${target_cpu}-${platform}" = "i386-ieee1275" ] || [ "${target_cpu}-${pla fi elif [ x"${target_cpu}-${platform}" = xmips-arc ]; then dvhtool -d "${install_device}" --unix-to-vh "{grubdir}/core.${imgext}" grub - echo "You will have to set boot-device manually. At the Open Firmware prompt, type:" - + echo "You will have to set SystemPartition and OSLoader manually." elif [ x"$platform" = xefi ]; then cp "${grubdir}/core.${imgext}" "${efidir}/${efi_file}" # For old macs. Suggested by Peter Jones. From b6296b3f9e4dcf24dddc6e1dc3a4f1a06b50d850 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Tue, 17 May 2011 09:18:53 +0200 Subject: [PATCH 611/869] Add missing ChngeLog line --- ChangeLog | 1 + 1 file changed, 1 insertion(+) diff --git a/ChangeLog b/ChangeLog index 088de8937..815df4dd8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -104,6 +104,7 @@ to 6. * util/grub-install.in: Run dvhtool on ARC. * util/grub-mkimage.c (image_targets): Add mips-arc. + (generate_image): Handle ECOFF output for mips-arc. 2011-05-16 Vladimir Serbinenko From 1b6656d360d0bb6814b68ade969e04e82ad121d6 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Tue, 17 May 2011 14:04:49 +0200 Subject: [PATCH 612/869] Revert changes to cache_flush.S --- grub-core/kern/mips/cache_flush.S | 4 ---- 1 file changed, 4 deletions(-) diff --git a/grub-core/kern/mips/cache_flush.S b/grub-core/kern/mips/cache_flush.S index 305a8b401..a352fd8ba 100644 --- a/grub-core/kern/mips/cache_flush.S +++ b/grub-core/kern/mips/cache_flush.S @@ -1,6 +1,3 @@ - - /* Qemu doesn't emulate caches. Oh boy. */ -#ifndef GRUB_MACHINE_MIPS_QEMU_MIPS move $t2, $a0 addu $t3, $a0, $a1 srl $t2, $t2, 5 @@ -24,4 +21,3 @@ bne $t1, $zero, 2b addiu $t0, $t0, 0x4 sync -#endif \ No newline at end of file From b38c1d1442aec530c9faf80579ebf0cb8122adb4 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Tue, 17 May 2011 14:05:52 +0200 Subject: [PATCH 613/869] Fix -O for qemu --- util/grub-mkimage.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/grub-mkimage.c b/util/grub-mkimage.c index 480521cd6..5f35c1da0 100644 --- a/util/grub-mkimage.c +++ b/util/grub-mkimage.c @@ -444,7 +444,7 @@ struct image_target_desc image_targets[] = }, { .dirname = "mips-qemu_mips", - .names = { "mips-qemu_mips-elf", NULL }, + .names = { "mipsel-qemu_mips-elf", NULL }, .voidp_sizeof = 4, .bigendian = 0, .id = IMAGE_LOONGSON_ELF, From a228ec103a07815c4e08021f946d10b6fb15ac5b Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Tue, 17 May 2011 14:35:55 +0200 Subject: [PATCH 614/869] enable ATA on qemu-mips --- grub-core/Makefile.core.def | 2 ++ grub-core/disk/ata.c | 22 +++++++++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def index 48809a65d..1c0b530a1 100644 --- a/grub-core/Makefile.core.def +++ b/grub-core/Makefile.core.def @@ -856,12 +856,14 @@ module = { name = ata; common = disk/ata.c; enable = pci; + enable = mips_qemu_mips; }; module = { name = ata_pthru; common = disk/ata_pthru.c; enable = pci; + enable = mips_qemu_mips; }; module = { diff --git a/grub-core/disk/ata.c b/grub-core/disk/ata.c index 391ccb9a2..12e70d91b 100644 --- a/grub-core/disk/ata.c +++ b/grub-core/disk/ata.c @@ -22,9 +22,13 @@ #include #include #include +#ifndef GRUB_MACHINE_MIPS_QEMU_MIPS #include -#include #include +#else +#define GRUB_MACHINE_PCI_IO_BASE 0xb4000000 +#endif +#include GRUB_MOD_LICENSE ("GPLv3+"); @@ -409,6 +413,7 @@ grub_ata_device_initialize (int port, int device, int addr, int addr2) return 0; } +#ifndef GRUB_MACHINE_MIPS_QEMU_MIPS static int NESTED_FUNC_ATTR grub_ata_pciinit (grub_pci_device_t dev, grub_pci_id_t pciid) @@ -524,6 +529,21 @@ grub_ata_initialize (void) grub_pci_iterate (grub_ata_pciinit); return 0; } +#else +static grub_err_t +grub_ata_initialize (void) +{ + int i; + for (i = 0; i < 2; i++) + { + grub_ata_device_initialize (i, 0, grub_ata_ioaddress[i], + grub_ata_ioaddress2[i]); + grub_ata_device_initialize (i, 1, grub_ata_ioaddress[i], + grub_ata_ioaddress2[i]); + } + return 0; +} +#endif static void grub_ata_setlba (struct grub_ata_device *dev, grub_disk_addr_t sector, From dc16af0369c45d8987c7a65fecea962a0b2e6786 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Tue, 17 May 2011 15:34:40 +0200 Subject: [PATCH 615/869] make linux loader work on qemu-mips --- grub-core/loader/mips/linux.c | 68 ++++++++++++++++++++++++++++++++++- 1 file changed, 67 insertions(+), 1 deletion(-) diff --git a/grub-core/loader/mips/linux.c b/grub-core/loader/mips/linux.c index e0a0e7c98..722be36a9 100644 --- a/grub-core/loader/mips/linux.c +++ b/grub-core/loader/mips/linux.c @@ -27,6 +27,7 @@ #include #include #include +#include GRUB_MOD_LICENSE ("GPLv3+"); @@ -53,12 +54,16 @@ static grub_size_t linux_size; static struct grub_relocator *relocator; static grub_uint8_t *playground; static grub_addr_t target_addr, entry_addr; +#ifdef GRUB_MACHINE_MIPS_QEMU_MIPS +static char *params; +#else static int linux_argc; static grub_off_t argv_off; #ifdef GRUB_MACHINE_MIPS_LOONGSON static grub_off_t envp_off; #endif static grub_off_t rd_addr_arg_off, rd_size_arg_off; +#endif static int initrd_loaded = 0; static grub_err_t @@ -66,8 +71,26 @@ grub_linux_boot (void) { struct grub_relocator32_state state; + grub_memset (&state, 0, sizeof (state)); + /* Boot the kernel. */ state.gpr[1] = entry_addr; + +#ifdef GRUB_MACHINE_MIPS_QEMU_MIPS + { + grub_err_t err; + grub_relocator_chunk_t ch; + + err = grub_relocator_alloc_chunk_addr (relocator, &ch, + ((16 << 20) - 256), + grub_strlen (params) + 1); + if (err) + return err; + grub_strcpy (get_virtual_current_address (ch), params); + } +#endif + +#ifndef GRUB_MACHINE_MIPS_QEMU_MIPS state.gpr[4] = linux_argc; state.gpr[5] = target_addr + argv_off; #ifdef GRUB_MACHINE_MIPS_LOONGSON @@ -76,6 +99,7 @@ grub_linux_boot (void) state.gpr[6] = 0; #endif state.gpr[7] = 0; +#endif state.jumpreg = 1; grub_relocator32_boot (relocator, state); @@ -88,6 +112,11 @@ grub_linux_unload (void) grub_relocator_unload (relocator); grub_dl_unref (my_mod); +#ifdef GRUB_MACHINE_MIPS_QEMU_MIPS + grub_free (params); + params = 0; +#endif + loaded = 0; return GRUB_ERR_NONE; @@ -207,11 +236,13 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), int argc, char *argv[]) { grub_elf_t elf = 0; - int i; int size; void *extra = NULL; +#ifndef GRUB_MACHINE_MIPS_QEMU_MIPS + int i; grub_uint32_t *linux_argv; char *linux_args; +#endif grub_err_t err; #ifdef GRUB_MACHINE_MIPS_LOONGSON char *linux_envs; @@ -236,6 +267,9 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), grub_loader_unset (); loaded = 0; +#ifdef GRUB_MACHINE_MIPS_QEMU_MIPS + size = 0; +#else /* For arguments. */ linux_argc = argc; #ifdef GRUB_MACHINE_MIPS_LOONGSON @@ -268,6 +302,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), + ALIGN_UP (sizeof ("highmemsize=XXXXXXXXXXXXXXXXXXXX"), 4) + ALIGN_UP (sizeof ("busclock=XXXXXXXXXX"), 4) + ALIGN_UP (sizeof ("cpuclock=XXXXXXXXXX"), 4); +#endif if (grub_elf_is_elf32 (elf)) err = grub_linux_load32 (elf, &extra, size); @@ -282,6 +317,20 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), if (err) return err; +#ifdef GRUB_MACHINE_MIPS_QEMU_MIPS + /* Create kernel command line. */ + size = grub_loader_cmdline_size(argc, argv); + params = grub_malloc (size + sizeof (LINUX_IMAGE)); + if (! params) + { + grub_linux_unload (); + return grub_errno; + } + + grub_memcpy (params, LINUX_IMAGE, sizeof (LINUX_IMAGE)); + grub_create_loader_cmdline (argc, argv, params + sizeof (LINUX_IMAGE) - 1, + size); +#else linux_argv = extra; argv_off = (grub_uint8_t *) linux_argv - (grub_uint8_t *) playground; extra = linux_argv + (linux_argc + 1 + 2); @@ -362,6 +411,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), linux_envs += ALIGN_UP (grub_strlen (linux_envs) + 1, 4); linux_envp[4] = 0; +#endif #endif grub_loader_set (grub_linux_boot, grub_linux_unload, 1); @@ -425,6 +475,21 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), return grub_errno; } +#ifdef GRUB_MACHINE_MIPS_QEMU_MIPS + { + char *tmp; + tmp = grub_xasprintf ("%s rd_start=0x%" PRIxGRUB_ADDR + " rd_size=0x%" PRIxGRUB_ADDR, params, + initrd_dest, size); + if (!tmp) + { + grub_file_close (file); + return grub_errno; + } + grub_free (params); + params = tmp; + } +#else grub_snprintf ((char *) playground + rd_addr_arg_off, sizeof ("rd_start=0xXXXXXXXXXXXXXXXX"), "rd_start=0x%llx", (unsigned long long) initrd_dest); @@ -438,6 +503,7 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), ((grub_uint32_t *) (playground + argv_off))[linux_argc] = target_addr + rd_size_arg_off; linux_argc++; +#endif initrd_loaded = 1; From 90f7ac192fad8a204c1456dd90c239043ce70d91 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Tue, 17 May 2011 18:39:32 +0200 Subject: [PATCH 616/869] * grub-core/kern/mips/startup.S (grub_arch_cpuclock): Move to the right place. --- ChangeLog | 5 +++++ grub-core/kern/mips/startup.S | 6 ++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index c0b2e0ce3..5cd5d0b8e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-05-17 Vladimir Serbinenko + + * grub-core/kern/mips/startup.S (grub_arch_cpuclock): Move to the right + place. + 2011-05-17 Vladimir Serbinenko Reenable qemu-mips port. diff --git a/grub-core/kern/mips/startup.S b/grub-core/kern/mips/startup.S index 58acb00f3..1472aaf8c 100644 --- a/grub-core/kern/mips/startup.S +++ b/grub-core/kern/mips/startup.S @@ -51,18 +51,16 @@ VARIABLE(grub_prefix) */ . = _start + GRUB_KERNEL_MACHINE_PREFIX_END -VARIABLE (grub_arch_cpuclock) - .long 0 -#ifdef GRUB_MACHINE_MIPS_LOONGSON VARIABLE (grub_arch_busclock) .long 0 +VARIABLE (grub_arch_cpuclock) + .long 0 VARIABLE (grub_arch_memsize) .long 0 VARIABLE (grub_arch_highmemsize) .long 0 VARIABLE (grub_arch_machine) .long GRUB_ARCH_MACHINE_FULOONG -#endif cont: /* Save our base. */ move $s0, $ra From 24c9143ae3b22a54b9d26e5ef823b394f135dd72 Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Tue, 17 May 2011 18:00:31 +0100 Subject: [PATCH 617/869] * Makefile.util.def (grub-bin2h): Don't install. * docs/man/grub-bin2h.h2m: Remove. --- ChangeLog | 5 +++++ Makefile.util.def | 2 +- docs/man/grub-bin2h.h2m | 2 -- 3 files changed, 6 insertions(+), 3 deletions(-) delete mode 100644 docs/man/grub-bin2h.h2m diff --git a/ChangeLog b/ChangeLog index 5cd5d0b8e..47d23d811 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-05-17 Colin Watson + + * Makefile.util.def (grub-bin2h): Don't install. + * docs/man/grub-bin2h.h2m: Remove. + 2011-05-17 Vladimir Serbinenko * grub-core/kern/mips/startup.S (grub_arch_cpuclock): Move to the right diff --git a/Makefile.util.def b/Makefile.util.def index 60ad78217..380c939b9 100644 --- a/Makefile.util.def +++ b/Makefile.util.def @@ -114,7 +114,7 @@ program = { ldadd = libgrubkern.a; ldadd = grub-core/gnulib/libgnu.a; ldadd = '$(LIBINTL) $(LIBDEVMAPPER)'; - mansection = 1; + installdir = noinst; }; program = { diff --git a/docs/man/grub-bin2h.h2m b/docs/man/grub-bin2h.h2m deleted file mode 100644 index ef463f3d1..000000000 --- a/docs/man/grub-bin2h.h2m +++ /dev/null @@ -1,2 +0,0 @@ -[NAME] -grub-bin2h \- convert a binary file to a C header From 3ca2b466459ffe724e8f8e1c450a619710de44a4 Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Tue, 17 May 2011 18:03:59 +0100 Subject: [PATCH 618/869] * util/grub-fstest.c (cmd_cat): New function. (fstest): Handle CMD_CAT. (options): Add cat. (argp_parser): Handle cat. --- ChangeLog | 7 +++++++ util/grub-fstest.c | 44 ++++++++++++++++++++++++++++++++++++++------ 2 files changed, 45 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index 47d23d811..4f17525b6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2011-05-17 Colin Watson + + * util/grub-fstest.c (cmd_cat): New function. + (fstest): Handle CMD_CAT. + (options): Add cat. + (argp_parser): Handle cat. + 2011-05-17 Colin Watson * Makefile.util.def (grub-bin2h): Don't install. diff --git a/util/grub-fstest.c b/util/grub-fstest.c index 293bdf74a..f253a96f6 100644 --- a/util/grub-fstest.c +++ b/util/grub-fstest.c @@ -54,12 +54,15 @@ execute_command (char *name, int n, char **args) return (cmd->func) (cmd, n, args); } -#define CMD_LS 1 -#define CMD_CP 2 -#define CMD_CMP 3 -#define CMD_HEX 4 -#define CMD_CRC 6 -#define CMD_BLOCKLIST 7 +enum { + CMD_LS = 1, + CMD_CP, + CMD_CAT, + CMD_CMP, + CMD_HEX, + CMD_CRC, + CMD_BLOCKLIST +}; #define BUF_SIZE 32256 @@ -182,6 +185,26 @@ cmd_cp (char *src, char *dest) fclose (ff); } +static void +cmd_cat (char *src) +{ + auto int cat_hook (grub_off_t ofs, char *buf, int len); + int cat_hook (grub_off_t ofs, char *buf, int len) + { + (void) ofs; + + if ((int) fwrite (buf, 1, len, stdout) != len) + { + grub_util_error (_("write error")); + return 1; + } + + return 0; + } + + read_file (src, cat_hook); +} + static void cmd_cmp (char *src, char *dest) { @@ -321,6 +344,9 @@ fstest (int n, char **args) case CMD_CP: cmd_cp (args[0], args[1]); break; + case CMD_CAT: + cmd_cat (args[0]); + break; case CMD_CMP: cmd_cmp (args[0], args[1]); break; @@ -356,6 +382,7 @@ static struct argp_option options[] = { {0, 0, 0 , OPTION_DOC, N_("Commands:"), 1}, {N_("ls PATH"), 0, 0 , OPTION_DOC, N_("List files in PATH."), 1}, {N_("cp FILE LOCAL"), 0, 0, OPTION_DOC, N_("Copy FILE to local file LOCAL."), 1}, + {N_("cat FILE"), 0, 0 , OPTION_DOC, N_("Copy FILE to standard output."), 1}, {N_("cmp FILE LOCAL"), 0, 0, OPTION_DOC, N_("Compare FILE with local file LOCAL."), 1}, {N_("hex FILE"), 0, 0 , OPTION_DOC, N_("Hex dump FILE."), 1}, {N_("crc FILE"), 0, 0 , OPTION_DOC, N_("Get crc32 checksum of FILE."), 1}, @@ -468,6 +495,11 @@ argp_parser (int key, char *arg, struct argp_state *state) cmd = CMD_CP; nparm = 2; } + else if (!grub_strcmp (arg, "cat")) + { + cmd = CMD_CAT; + nparm = 1; + } else if (!grub_strcmp (arg, "cmp")) { cmd = CMD_CMP; From d064b83056698964cd6b59c6334d107a55379f46 Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Tue, 17 May 2011 18:10:29 +0100 Subject: [PATCH 619/869] * util/grub.d/20_linux_xen.in: Honour GRUB_CMDLINE_LINUX_XEN_REPLACE and GRUB_CMDLINE_LINUX_XEN_REPLACE_DEFAULT, which replace GRUB_CMDLINE_LINUX and GRUB_CMDLINE_LINUX_DEFAULT (complementing the existing options which append). * docs/grub.texi (Simple configuration): Document new options. Reported by: Ian Jackson. Fixes Debian bug #617538. --- ChangeLog | 9 +++++++++ docs/grub.texi | 10 ++++++++-- util/grub.d/20_linux_xen.in | 8 ++++++++ 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4f17525b6..ab710f5fb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2011-05-17 Colin Watson + + * util/grub.d/20_linux_xen.in: Honour GRUB_CMDLINE_LINUX_XEN_REPLACE + and GRUB_CMDLINE_LINUX_XEN_REPLACE_DEFAULT, which replace + GRUB_CMDLINE_LINUX and GRUB_CMDLINE_LINUX_DEFAULT (complementing the + existing options which append). + * docs/grub.texi (Simple configuration): Document new options. + Reported by: Ian Jackson. Fixes Debian bug #617538. + 2011-05-17 Colin Watson * util/grub-fstest.c (cmd_cat): New function. diff --git a/docs/grub.texi b/docs/grub.texi index b11e3836f..7e28d457a 100644 --- a/docs/grub.texi +++ b/docs/grub.texi @@ -1169,8 +1169,14 @@ 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. +The values of these options are appended to the values of +@samp{GRUB_CMDLINE_LINUX} and @samp{GRUB_CMDLINE_LINUX_DEFAULT} for Linux +and Xen menu entries. + +@item GRUB_CMDLINE_LINUX_XEN_REPLACE +@item GRUB_CMDLINE_LINUX_XEN_REPLACE_DEFAULT +The values of these options replace the values of @samp{GRUB_CMDLINE_LINUX} +and @samp{GRUB_CMDLINE_LINUX_DEFAULT} for Linux and Xen menu entries. @item GRUB_DISABLE_LINUX_UUID Normally, @command{grub-mkconfig} will generate menu entries that use diff --git a/util/grub.d/20_linux_xen.in b/util/grub.d/20_linux_xen.in index a9007603d..083391c40 100644 --- a/util/grub.d/20_linux_xen.in +++ b/util/grub.d/20_linux_xen.in @@ -51,6 +51,14 @@ else LINUX_ROOT_DEVICE=UUID=${GRUB_DEVICE_UUID} fi +# Allow overriding GRUB_CMDLINE_LINUX and GRUB_CMDLINE_LINUX_DEFAULT. +if [ "${GRUB_CMDLINE_LINUX_XEN_REPLACE}" ]; then + GRUB_CMDLINE_LINUX="${GRUB_CMDLINE_LINUX_XEN_REPLACE}" +fi +if [ "${GRUB_CMDLINE_LINUX_XEN_REPLACE_DEFAULT}" ]; then + GRUB_CMDLINE_LINUX_DEFAULT="${GRUB_CMDLINE_LINUX_XEN_REPLACE_DEFAULT}" +fi + if [ "x`${grub_probe} --device ${GRUB_DEVICE} --target=fs 2>/dev/null || true`" = xbtrfs ]; then rootsubvol="`make_system_path_relative_to_its_root /`" rootsubvol="${rootsubvol#/}" From 5d420cd9833ce99500222ceefa1addbffb6a45b7 Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Tue, 17 May 2011 18:13:12 +0100 Subject: [PATCH 620/869] * .bzrignore: Remove grub-dumpbios. --- .bzrignore | 1 - ChangeLog | 4 ++++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/.bzrignore b/.bzrignore index 55cbdaeeb..668d060ca 100644 --- a/.bzrignore +++ b/.bzrignore @@ -31,7 +31,6 @@ genkernsyms.sh gensymlist.sh gentrigtables grub-bin2h -grub-dumpbios grub-editenv grub-emu grub_emu_init.c diff --git a/ChangeLog b/ChangeLog index ab710f5fb..ded0469a3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2011-05-17 Colin Watson + + * .bzrignore: Remove grub-dumpbios. + 2011-05-17 Colin Watson * util/grub.d/20_linux_xen.in: Honour GRUB_CMDLINE_LINUX_XEN_REPLACE From 566a191715b3a91a7f5efd7e44e203620c513310 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Tue, 17 May 2011 19:32:51 +0200 Subject: [PATCH 621/869] Prevent potential loss of memory map by overwrite on qemu-mips. * grub-core/boot/mips/startup_raw.S [GRUB_MACHINE_MIPS_QEMU_MIPS]: Save ram size in $s4. * grub-core/kern/mips/qemu_mips/init.c (RAMSIZE): Removed. All users changed to grub_arch_memsize. * grub-core/kern/mips/startup.S (grub_arch_machine): Restrict to Loongson. [GRUB_MACHINE_MIPS_QEMU_MIPS]: Save grub_arch_memsize. * grub-core/loader/mips/linux.c (grub_linux_boot): Pass memory size. * include/grub/mips/qemu_mips/memory.h (grub_arch_memsize): New external variable. --- ChangeLog | 15 +++++++++++++++ grub-core/boot/mips/startup_raw.S | 5 +++++ grub-core/kern/mips/qemu_mips/init.c | 6 ++---- grub-core/kern/mips/startup.S | 8 ++++++++ grub-core/loader/mips/linux.c | 14 +++++++++++--- include/grub/mips/qemu_mips/memory.h | 3 +++ 6 files changed, 44 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index ded0469a3..d1f01e727 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +2011-05-17 Vladimir Serbinenko + + Prevent potential loss of memory map by overwrite on qemu-mips. + + * grub-core/boot/mips/startup_raw.S [GRUB_MACHINE_MIPS_QEMU_MIPS]: + Save ram size in $s4. + * grub-core/kern/mips/qemu_mips/init.c (RAMSIZE): Removed. + All users changed to grub_arch_memsize. + * grub-core/kern/mips/startup.S (grub_arch_machine): Restrict to + Loongson. + [GRUB_MACHINE_MIPS_QEMU_MIPS]: Save grub_arch_memsize. + * grub-core/loader/mips/linux.c (grub_linux_boot): Pass memory size. + * include/grub/mips/qemu_mips/memory.h (grub_arch_memsize): New + external variable. + 2011-05-17 Colin Watson * .bzrignore: Remove grub-dumpbios. diff --git a/grub-core/boot/mips/startup_raw.S b/grub-core/boot/mips/startup_raw.S index e69de26c2..65a2dd59e 100644 --- a/grub-core/boot/mips/startup_raw.S +++ b/grub-core/boot/mips/startup_raw.S @@ -50,6 +50,11 @@ codestart: /* Parse arguments. Has to be done before relocation. So need to do it in asm. */ +#ifdef GRUB_MACHINE_MIPS_QEMU_MIPS + lui $t0, %hi (((16 << 20) - 264) | 0x80000000) + lw $s4, %lo (((16 << 20) - 264) | 0x80000000) ($t0) +#endif + #ifdef GRUB_MACHINE_MIPS_LOONGSON move $s2, $zero move $s3, $zero diff --git a/grub-core/kern/mips/qemu_mips/init.c b/grub-core/kern/mips/qemu_mips/init.c index b3155eab5..e426b833d 100644 --- a/grub-core/kern/mips/qemu_mips/init.c +++ b/grub-core/kern/mips/qemu_mips/init.c @@ -10,8 +10,6 @@ #include #include -#define RAMSIZE (*(grub_uint32_t *) ((16 << 20) - 264)) - extern void grub_serial_init (void); extern void grub_terminfo_init (void); @@ -24,7 +22,7 @@ grub_machine_init (void) grub_arch_cpuclock = 64000000; modend = grub_modules_get_end (); - grub_mm_init_region ((void *) modend, RAMSIZE + grub_mm_init_region ((void *) modend, grub_arch_memsize - (modend - GRUB_ARCH_LOWMEMVSTART)); grub_install_get_time_ms (grub_rtc_get_time_ms); @@ -59,6 +57,6 @@ grub_reboot (void) grub_err_t grub_machine_mmap_iterate (grub_memory_hook_t hook) { - hook (0, RAMSIZE, GRUB_MEMORY_AVAILABLE); + hook (0, grub_arch_memsize, GRUB_MEMORY_AVAILABLE); return GRUB_ERR_NONE; } diff --git a/grub-core/kern/mips/startup.S b/grub-core/kern/mips/startup.S index 1472aaf8c..2654d744e 100644 --- a/grub-core/kern/mips/startup.S +++ b/grub-core/kern/mips/startup.S @@ -59,12 +59,20 @@ VARIABLE (grub_arch_memsize) .long 0 VARIABLE (grub_arch_highmemsize) .long 0 +#ifdef GRUB_MACHINE_MIPS_LOONGSON VARIABLE (grub_arch_machine) .long GRUB_ARCH_MACHINE_FULOONG +#endif cont: /* Save our base. */ move $s0, $ra +#ifdef GRUB_MACHINE_MIPS_QEMU_MIPS + lui $t1, %hi(grub_arch_busclock) + addiu $t1, %lo(grub_arch_busclock) + sw $s4, 8($t1) +#endif + #ifdef GRUB_MACHINE_MIPS_LOONGSON lui $t1, %hi(grub_arch_busclock) addiu $t1, %lo(grub_arch_busclock) diff --git a/grub-core/loader/mips/linux.c b/grub-core/loader/mips/linux.c index 722be36a9..64c4a0531 100644 --- a/grub-core/loader/mips/linux.c +++ b/grub-core/loader/mips/linux.c @@ -80,13 +80,21 @@ grub_linux_boot (void) { grub_err_t err; grub_relocator_chunk_t ch; + grub_uint32_t *memsize; + grub_uint32_t *magic; + char *str; err = grub_relocator_alloc_chunk_addr (relocator, &ch, - ((16 << 20) - 256), - grub_strlen (params) + 1); + ((16 << 20) - 264), + grub_strlen (params) + 1 + 8); if (err) return err; - grub_strcpy (get_virtual_current_address (ch), params); + memsize = get_virtual_current_address (ch); + magic = memsize + 1; + *memsize = grub_mmap_get_lower (); + *magic = 0x12345678; + str = (char *) (magic + 1); + grub_strcpy (str, params); } #endif diff --git a/include/grub/mips/qemu_mips/memory.h b/include/grub/mips/qemu_mips/memory.h index 7a7ff143e..48a9b69f0 100644 --- a/include/grub/mips/qemu_mips/memory.h +++ b/include/grub/mips/qemu_mips/memory.h @@ -29,6 +29,9 @@ #define GRUB_MACHINE_MEMORY_USABLE 0x81000000 #ifndef ASM_FILE + +extern grub_uint32_t grub_arch_memsize; + static inline grub_err_t grub_machine_mmap_register (grub_uint64_t start __attribute__ ((unused)), grub_uint64_t size __attribute__ ((unused)), From b772baedcd8ef2a995f4bb0fc8ebc9157c21e9b7 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Tue, 17 May 2011 21:15:54 +0200 Subject: [PATCH 622/869] Reduce memory footprint on SGI by putting modules before the kernel as opposed to after. * grub-core/Makefile.core.def (kernel): Increase linking address. (none_decompress): Likewise. (xz_decompress): Likewise. * grub-core/boot/mips/startup_raw.S: Use prewritten uncompression address. * grub-core/kern/mips/arc/init.c (grub_machine_init): Handle memory layout change. (grub_arch_modules_addr): New function. * grub-core/kern/mips/init.c (grub_arch_modules_addr): Moved from here... * grub-core/kern/mips/loongson/init.c (grub_arch_modules_addr): .. here * grub-core/kern/mips/qemu_mips/init.c (grub_arch_modules_addr): ... and here. * grub-core/kern/mips/startup.S (total_size): Rename to ... (grub_total_modules_size): ... this. Make global. [GRUB_MACHINE_ARC]: Don't attempt to move modules out of the bss. * include/grub/offsets.h (GRUB_KERNEL_MIPS_LOONGSON_UNCOMPRESSED_ADDR): New definition. (GRUB_KERNEL_MIPS_QEMU_MIPS_UNCOMPRESSED_ADDR): Likewise. (GRUB_KERNEL_MIPS_ARC_UNCOMPRESSED_ADDR): Likewise. (GRUB_KERNEL_MACHINE_UNCOMPRESSED_ADDR): Likewise. (GRUB_KERNEL_MIPS_ARC_LINK_ADDR): Increased. * util/grub-mkimage.c (image_target_desc): New flag PLATFORM_FLAGS_MODULES_BEFORE_KERNEL. (image_targets): Set PLATFORM_FLAGS_MODULES_BEFORE_KERNEL on mips-arc. (generate_image): Handle images with modules before kernel. --- ChangeLog | 31 ++++++++++++ grub-core/Makefile.core.def | 6 +-- grub-core/boot/mips/startup_raw.S | 6 ++- grub-core/kern/mips/arc/init.c | 14 +++++- grub-core/kern/mips/init.c | 8 ---- grub-core/kern/mips/loongson/init.c | 7 +++ grub-core/kern/mips/qemu_mips/init.c | 8 ++++ grub-core/kern/mips/startup.S | 4 +- include/grub/offsets.h | 6 ++- util/grub-mkimage.c | 70 ++++++++++++++++++++-------- 10 files changed, 123 insertions(+), 37 deletions(-) diff --git a/ChangeLog b/ChangeLog index d1f01e727..bf7d7d110 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,34 @@ +2011-05-17 Vladimir Serbinenko + + Reduce memory footprint on SGI by putting modules before the kernel + as opposed to after. + + * grub-core/Makefile.core.def (kernel): Increase linking address. + (none_decompress): Likewise. + (xz_decompress): Likewise. + * grub-core/boot/mips/startup_raw.S: Use prewritten uncompression + address. + * grub-core/kern/mips/arc/init.c (grub_machine_init): Handle memory + layout change. + (grub_arch_modules_addr): New function. + * grub-core/kern/mips/init.c (grub_arch_modules_addr): Moved from here... + * grub-core/kern/mips/loongson/init.c (grub_arch_modules_addr): .. here + * grub-core/kern/mips/qemu_mips/init.c (grub_arch_modules_addr): ... and + here. + * grub-core/kern/mips/startup.S (total_size): Rename to ... + (grub_total_modules_size): ... this. Make global. + [GRUB_MACHINE_ARC]: Don't attempt to move modules out of the bss. + * include/grub/offsets.h (GRUB_KERNEL_MIPS_LOONGSON_UNCOMPRESSED_ADDR): + New definition. + (GRUB_KERNEL_MIPS_QEMU_MIPS_UNCOMPRESSED_ADDR): Likewise. + (GRUB_KERNEL_MIPS_ARC_UNCOMPRESSED_ADDR): Likewise. + (GRUB_KERNEL_MACHINE_UNCOMPRESSED_ADDR): Likewise. + (GRUB_KERNEL_MIPS_ARC_LINK_ADDR): Increased. + * util/grub-mkimage.c (image_target_desc): New flag + PLATFORM_FLAGS_MODULES_BEFORE_KERNEL. + (image_targets): Set PLATFORM_FLAGS_MODULES_BEFORE_KERNEL on mips-arc. + (generate_image): Handle images with modules before kernel. + 2011-05-17 Vladimir Serbinenko Prevent potential loss of memory map by overwrite on qemu-mips. diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def index 1c0b530a1..c717167cb 100644 --- a/grub-core/Makefile.core.def +++ b/grub-core/Makefile.core.def @@ -41,7 +41,7 @@ kernel = { mips_loongson_ldflags = '-Wl,-Ttext,0x80200000'; powerpc_ieee1275_ldflags = '-Wl,-Ttext,0x200000'; sparc64_ieee1275_ldflags = '-Wl,-Ttext,0x4400'; - mips_arc_ldflags = '-Wl,-Ttext,0x8a000000'; + mips_arc_ldflags = '-Wl,-Ttext,0x8bd00000'; mips_qemu_mips_ldflags = '-Wl,-Ttext,0x80200000'; mips_loongson_cppflags = '-DUSE_ASCII_FAILBACK'; @@ -324,7 +324,7 @@ image = { objcopyflags = '-O binary'; mips_loongson_ldflags = '-static-libgcc -Wl,-Ttext,0x80100000'; mips_qemu_mips_ldflags = '-static-libgcc -Wl,-Ttext,0x80100000'; - mips_arc_ldflags = '-static-libgcc -Wl,-Ttext,0x89f00000'; + mips_arc_ldflags = '-static-libgcc -Wl,-Ttext,0x8bc00000'; ldadd = '-lgcc'; cflags = '-static-libgcc'; enable = mips; @@ -340,7 +340,7 @@ image = { objcopyflags = '-O binary'; mips_loongson_ldflags = '-static-libgcc -Wl,-Ttext,0x80100000'; mips_qemu_mips_ldflags = '-static-libgcc -Wl,-Ttext,0x80100000'; - mips_arc_ldflags = '-static-libgcc -Wl,-Ttext,0x89f00000'; + mips_arc_ldflags = '-static-libgcc -Wl,-Ttext,0x8bc00000'; ldadd = '-lgcc'; cflags = '-static-libgcc'; enable = mips; diff --git a/grub-core/boot/mips/startup_raw.S b/grub-core/boot/mips/startup_raw.S index 65a2dd59e..e6dfadaf9 100644 --- a/grub-core/boot/mips/startup_raw.S +++ b/grub-core/boot/mips/startup_raw.S @@ -44,6 +44,9 @@ compressed_size: . = _start + GRUB_KERNEL_MACHINE_UNCOMPRESSED_SIZE uncompressed_size: .long 0 + . = _start + GRUB_KERNEL_MACHINE_UNCOMPRESSED_ADDR +uncompressed_addr: + .long 0 codestart: /* Save our base. */ move $s0, $ra @@ -221,8 +224,7 @@ cmdlinedone: subu $a0, $a0, $t0 addu $a0, $a0, $s0 - lui $a1, %hi(GRUB_MACHINE_LINK_ADDR) - addiu $a1, %lo(GRUB_MACHINE_LINK_ADDR) + lw $a1, (GRUB_KERNEL_MACHINE_UNCOMPRESSED_ADDR - BASE_ADDR)($s0) lw $a2, (GRUB_KERNEL_MACHINE_COMPRESSED_SIZE - BASE_ADDR)($s0) lw $a3, (GRUB_KERNEL_MACHINE_UNCOMPRESSED_SIZE - BASE_ADDR)($s0) move $s1, $a1 diff --git a/grub-core/kern/mips/arc/init.c b/grub-core/kern/mips/arc/init.c index 8ee965d74..514b481f6 100644 --- a/grub-core/kern/mips/arc/init.c +++ b/grub-core/kern/mips/arc/init.c @@ -124,6 +124,8 @@ grub_machine_mmap_iterate (grub_memory_hook_t hook) } } +extern grub_uint32_t grub_total_modules_size; + void grub_machine_init (void) { @@ -148,8 +150,10 @@ grub_machine_init (void) start = ((grub_uint64_t) cur->start_page) << 12; end = ((grub_uint64_t) cur->num_pages) << 12; end += start; - if ((grub_uint64_t) end > (GRUB_KERNEL_MIPS_ARC_LINK_ADDR & 0x1fffffff)) - end = (GRUB_KERNEL_MIPS_ARC_LINK_ADDR & 0x1fffffff); + if ((grub_uint64_t) end > ((GRUB_KERNEL_MIPS_ARC_LINK_ADDR + - grub_total_modules_size) & 0x1fffffff)) + end = ((GRUB_KERNEL_MIPS_ARC_LINK_ADDR - grub_total_modules_size) + & 0x1fffffff); if (end > start) grub_mm_init_region ((void *) (grub_addr_t) (start | 0x80000000), end - start); @@ -160,6 +164,12 @@ grub_machine_init (void) grub_arcdisk_init (); } +grub_addr_t +grub_arch_modules_addr (void) +{ + return GRUB_KERNEL_MIPS_ARC_LINK_ADDR - grub_total_modules_size; +} + void grub_machine_fini (void) { diff --git a/grub-core/kern/mips/init.c b/grub-core/kern/mips/init.c index 3b08d5606..bfa08f56a 100644 --- a/grub-core/kern/mips/init.c +++ b/grub-core/kern/mips/init.c @@ -42,11 +42,3 @@ grub_machine_set_prefix (void) { grub_env_set ("prefix", grub_prefix); } - -extern char _end[]; - -grub_addr_t -grub_arch_modules_addr (void) -{ - return (grub_addr_t) _end; -} diff --git a/grub-core/kern/mips/loongson/init.c b/grub-core/kern/mips/loongson/init.c index f0f5c5874..bcef391b9 100644 --- a/grub-core/kern/mips/loongson/init.c +++ b/grub-core/kern/mips/loongson/init.c @@ -257,3 +257,10 @@ grub_reboot (void) while (1); } +extern char _end[]; + +grub_addr_t +grub_arch_modules_addr (void) +{ + return (grub_addr_t) _end; +} diff --git a/grub-core/kern/mips/qemu_mips/init.c b/grub-core/kern/mips/qemu_mips/init.c index e426b833d..2180b347a 100644 --- a/grub-core/kern/mips/qemu_mips/init.c +++ b/grub-core/kern/mips/qemu_mips/init.c @@ -60,3 +60,11 @@ grub_machine_mmap_iterate (grub_memory_hook_t hook) hook (0, grub_arch_memsize, GRUB_MEMORY_AVAILABLE); return GRUB_ERR_NONE; } + +extern char _end[]; + +grub_addr_t +grub_arch_modules_addr (void) +{ + return (grub_addr_t) _end; +} diff --git a/grub-core/kern/mips/startup.S b/grub-core/kern/mips/startup.S index 2654d744e..6220a8c33 100644 --- a/grub-core/kern/mips/startup.S +++ b/grub-core/kern/mips/startup.S @@ -37,7 +37,7 @@ start: nop . = _start + GRUB_KERNEL_MACHINE_TOTAL_MODULE_SIZE -total_module_size: +VARIABLE(grub_total_modules_size) .long 0 . = _start + GRUB_KERNEL_MACHINE_PREFIX @@ -84,6 +84,7 @@ cont: #endif /* Move the modules out of BSS. */ +#ifndef GRUB_MACHINE_ARC lui $t2, %hi(__bss_start) addiu $t2, %lo(__bss_start) @@ -113,6 +114,7 @@ modulesmovcont: b modulesmovcont addiu $t3, $t3, -1 modulesmovdone: +#endif /* Clean BSS. */ diff --git a/include/grub/offsets.h b/include/grub/offsets.h index 40c8a016b..af724096d 100644 --- a/include/grub/offsets.h +++ b/include/grub/offsets.h @@ -106,6 +106,7 @@ #define GRUB_KERNEL_MIPS_LOONGSON_COMPRESSED_SIZE 0x8 #define GRUB_KERNEL_MIPS_LOONGSON_UNCOMPRESSED_SIZE 0xc +#define GRUB_KERNEL_MIPS_LOONGSON_UNCOMPRESSED_ADDR 0x10 #define GRUB_KERNEL_MIPS_LOONGSON_TOTAL_MODULE_SIZE 0x08 #define GRUB_KERNEL_MIPS_LOONGSON_PREFIX 0x0c @@ -115,16 +116,18 @@ #define GRUB_KERNEL_MIPS_QEMU_MIPS_LINK_ALIGN 32 #define GRUB_KERNEL_MIPS_QEMU_MIPS_COMPRESSED_SIZE 0x8 #define GRUB_KERNEL_MIPS_QEMU_MIPS_UNCOMPRESSED_SIZE 0xc +#define GRUB_KERNEL_MIPS_QEMU_MIPS_UNCOMPRESSED_ADDR 0x10 #define GRUB_KERNEL_MIPS_QEMU_MIPS_TOTAL_MODULE_SIZE 0x08 #define GRUB_KERNEL_MIPS_QEMU_MIPS_PREFIX 0x0c #define GRUB_KERNEL_MIPS_QEMU_MIPS_PREFIX_END 0x54 -#define GRUB_KERNEL_MIPS_ARC_LINK_ADDR 0x8a000000 +#define GRUB_KERNEL_MIPS_ARC_LINK_ADDR 0x8bd00000 #define GRUB_KERNEL_MIPS_ARC_LINK_ALIGN 32 #define GRUB_KERNEL_MIPS_ARC_COMPRESSED_SIZE 0x8 #define GRUB_KERNEL_MIPS_ARC_UNCOMPRESSED_SIZE 0xc +#define GRUB_KERNEL_MIPS_ARC_UNCOMPRESSED_ADDR 0x10 #define GRUB_KERNEL_MIPS_ARC_TOTAL_MODULE_SIZE 0x08 #define GRUB_KERNEL_MIPS_ARC_PREFIX 0x0c @@ -187,6 +190,7 @@ #define GRUB_KERNEL_MACHINE_KERNEL_IMAGE_SIZE GRUB_OFFSETS_CONCAT (GRUB_KERNEL_, GRUB_MACHINE, _KERNEL_IMAGE_SIZE) #define GRUB_KERNEL_MACHINE_COMPRESSED_SIZE GRUB_OFFSETS_CONCAT (GRUB_KERNEL_, GRUB_MACHINE, _COMPRESSED_SIZE) #define GRUB_KERNEL_MACHINE_UNCOMPRESSED_SIZE GRUB_OFFSETS_CONCAT (GRUB_KERNEL_, GRUB_MACHINE, _UNCOMPRESSED_SIZE) +#define GRUB_KERNEL_MACHINE_UNCOMPRESSED_ADDR GRUB_OFFSETS_CONCAT (GRUB_KERNEL_, GRUB_MACHINE, _UNCOMPRESSED_ADDR) #define GRUB_KERNEL_MACHINE_PREFIX GRUB_OFFSETS_CONCAT (GRUB_KERNEL_, GRUB_MACHINE, _PREFIX) #define GRUB_KERNEL_MACHINE_PREFIX_END GRUB_OFFSETS_CONCAT (GRUB_KERNEL_, GRUB_MACHINE, _PREFIX_END) diff --git a/util/grub-mkimage.c b/util/grub-mkimage.c index 5f35c1da0..5ae744a8e 100644 --- a/util/grub-mkimage.c +++ b/util/grub-mkimage.c @@ -73,7 +73,8 @@ struct image_target_desc { PLATFORM_FLAGS_NONE = 0, PLATFORM_FLAGS_LZMA = 1, - PLATFORM_FLAGS_DECOMPRESSORS = 2 + PLATFORM_FLAGS_DECOMPRESSORS = 2, + PLATFORM_FLAGS_MODULES_BEFORE_KERNEL = 4, } flags; unsigned prefix; unsigned prefix_end; @@ -426,7 +427,8 @@ struct image_target_desc image_targets[] = .voidp_sizeof = 4, .bigendian = 1, .id = IMAGE_MIPS_ARC, - .flags = PLATFORM_FLAGS_DECOMPRESSORS, + .flags = (PLATFORM_FLAGS_DECOMPRESSORS + | PLATFORM_FLAGS_MODULES_BEFORE_KERNEL), .prefix = GRUB_KERNEL_MIPS_ARC_PREFIX, .prefix_end = GRUB_KERNEL_MIPS_ARC_PREFIX_END, .raw_size = 0, @@ -781,27 +783,47 @@ generate_image (const char *dir, char *prefix, FILE *out, char *mods[], grub_util_error (_("prefix is too long")); strcpy (kernel_img + image_target->prefix, prefix); + if ((image_target->flags & PLATFORM_FLAGS_DECOMPRESSORS) + && (image_target->total_module_size != TARGET_NO_FIELD)) + *((grub_uint32_t *) (kernel_img + image_target->total_module_size)) + = grub_host_to_target32 (total_module_size); + + if (image_target->flags & PLATFORM_FLAGS_MODULES_BEFORE_KERNEL) + memmove (kernel_img + total_module_size, kernel_img, kernel_size); + if (image_target->voidp_sizeof == 8) { /* Fill in the grub_module_info structure. */ struct grub_module_info64 *modinfo; - modinfo = (struct grub_module_info64 *) (kernel_img + kernel_size); + if (image_target->flags & PLATFORM_FLAGS_MODULES_BEFORE_KERNEL) + modinfo = (struct grub_module_info64 *) kernel_img; + else + modinfo = (struct grub_module_info64 *) (kernel_img + kernel_size); memset (modinfo, 0, sizeof (struct grub_module_info64)); modinfo->magic = grub_host_to_target32 (GRUB_MODULE_MAGIC); modinfo->offset = grub_host_to_target_addr (sizeof (struct grub_module_info64)); modinfo->size = grub_host_to_target_addr (total_module_size); - offset = kernel_size + sizeof (struct grub_module_info64); + if (image_target->flags & PLATFORM_FLAGS_MODULES_BEFORE_KERNEL) + offset = sizeof (struct grub_module_info64); + else + offset = kernel_size + sizeof (struct grub_module_info64); } else { /* Fill in the grub_module_info structure. */ struct grub_module_info32 *modinfo; - modinfo = (struct grub_module_info32 *) (kernel_img + kernel_size); + if (image_target->flags & PLATFORM_FLAGS_MODULES_BEFORE_KERNEL) + modinfo = (struct grub_module_info32 *) kernel_img; + else + modinfo = (struct grub_module_info32 *) (kernel_img + kernel_size); memset (modinfo, 0, sizeof (struct grub_module_info32)); modinfo->magic = grub_host_to_target32 (GRUB_MODULE_MAGIC); modinfo->offset = grub_host_to_target_addr (sizeof (struct grub_module_info32)); modinfo->size = grub_host_to_target_addr (total_module_size); - offset = kernel_size + sizeof (struct grub_module_info32); + if (image_target->flags & PLATFORM_FLAGS_MODULES_BEFORE_KERNEL) + offset = sizeof (struct grub_module_info32); + else + offset = kernel_size + sizeof (struct grub_module_info32); } for (p = path_list; p; p = p->next) @@ -852,26 +874,27 @@ generate_image (const char *dir, char *prefix, FILE *out, char *mods[], offset += config_size; } - if ((image_target->flags & PLATFORM_FLAGS_DECOMPRESSORS) - && (image_target->total_module_size != TARGET_NO_FIELD)) - *((grub_uint32_t *) (kernel_img + image_target->total_module_size)) - = grub_host_to_target32 (total_module_size); - grub_util_info ("kernel_img=%p, kernel_size=0x%x", kernel_img, kernel_size); compress_kernel (image_target, kernel_img, kernel_size + total_module_size, &core_img, &core_size, comp); + free (kernel_img); + + if (image_target->flags & PLATFORM_FLAGS_DECOMPRESSORS) + kernel_img = core_img + total_module_size; + else + kernel_img = core_img; grub_util_info ("the core size is 0x%x", core_size); if (!(image_target->flags & PLATFORM_FLAGS_DECOMPRESSORS) && image_target->total_module_size != TARGET_NO_FIELD) - *((grub_uint32_t *) (core_img + image_target->total_module_size)) + *((grub_uint32_t *) (kernel_img + image_target->total_module_size)) = grub_host_to_target32 (total_module_size); if (image_target->kernel_image_size != TARGET_NO_FIELD) - *((grub_uint32_t *) (core_img + image_target->kernel_image_size)) + *((grub_uint32_t *) (kernel_img + image_target->kernel_image_size)) = grub_host_to_target32 (kernel_size); if (image_target->compressed_size != TARGET_NO_FIELD) - *((grub_uint32_t *) (core_img + image_target->compressed_size)) + *((grub_uint32_t *) (kernel_img + image_target->compressed_size)) = grub_host_to_target32 (core_size - image_target->raw_size); /* If we included a drive in our prefix, let GRUB know it doesn't have to @@ -879,9 +902,9 @@ generate_image (const char *dir, char *prefix, FILE *out, char *mods[], if (image_target->install_dos_part != TARGET_NO_FIELD && image_target->install_bsd_part != TARGET_NO_FIELD && prefix[0] == '(') { - *((grub_int32_t *) (core_img + image_target->install_dos_part)) + *((grub_int32_t *) (kernel_img + image_target->install_dos_part)) = grub_host_to_target32 (-2); - *((grub_int32_t *) (core_img + image_target->install_bsd_part)) + *((grub_int32_t *) (kernel_img + image_target->install_bsd_part)) = grub_host_to_target32 (-2); } @@ -915,6 +938,13 @@ generate_image (const char *dir, char *prefix, FILE *out, char *mods[], *((grub_uint32_t *) (decompress_img + GRUB_KERNEL_MIPS_LOONGSON_UNCOMPRESSED_SIZE)) = grub_host_to_target32 (kernel_size + total_module_size); + if (image_target->flags & PLATFORM_FLAGS_MODULES_BEFORE_KERNEL) + *((grub_uint32_t *) (decompress_img + GRUB_KERNEL_MIPS_LOONGSON_UNCOMPRESSED_ADDR)) + = grub_host_to_target_addr (image_target->link_addr - total_module_size); + else + *((grub_uint32_t *) (decompress_img + GRUB_KERNEL_MIPS_LOONGSON_UNCOMPRESSED_ADDR)) + = grub_host_to_target_addr (image_target->link_addr); + full_size = core_size + decompress_size; full_img = xmalloc (full_size); @@ -1199,7 +1229,7 @@ generate_image (const char *dir, char *prefix, FILE *out, char *mods[], rom_img = xmalloc (rom_size); memset (rom_img, 0, rom_size); - *((grub_int32_t *) (core_img + GRUB_KERNEL_I386_QEMU_CORE_ENTRY_ADDR)) + *((grub_int32_t *) (kernel_img + GRUB_KERNEL_I386_QEMU_CORE_ENTRY_ADDR)) = grub_host_to_target32 ((grub_uint32_t) -rom_size); memcpy (rom_img, core_img, core_size); @@ -1380,8 +1410,9 @@ generate_image (const char *dir, char *prefix, FILE *out, char *mods[], size_t program_size; program_size = ALIGN_ADDR (core_size); - target_addr = image_target->link_addr - ALIGN_UP(program_size, 1048576) - - (1 << 20); + target_addr = (image_target->link_addr + - ALIGN_UP(total_module_size + core_size, 1048576) + - (1 << 20)); ecoff_img = xmalloc (program_size + sizeof (*head) + sizeof (*section)); grub_memset (ecoff_img, 0, program_size + sizeof (*head) + sizeof (*section)); @@ -1553,7 +1584,6 @@ generate_image (const char *dir, char *prefix, FILE *out, char *mods[], } grub_util_write_image (core_img, core_size, out); - free (kernel_img); free (core_img); free (kernel_path); From 35341bbc9644eb17ae08e5ccbc52c691cc8357fb Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Tue, 17 May 2011 21:40:35 +0200 Subject: [PATCH 623/869] Avoid unnecessary copying on MIPS. * grub-core/boot/decompressor/none.c (grub_decompress_core): Exit early if src == dest. * util/grub-mkimage.c (generate_image): Arange for src == dest if compression is none. --- ChangeLog | 9 +++++++++ grub-core/boot/decompressor/none.c | 3 +++ util/grub-mkimage.c | 21 +++++++++++++++------ 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index bf7d7d110..2d6a02d08 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2011-05-17 Vladimir Serbinenko + + Avoid unnecessary copying on MIPS. + + * grub-core/boot/decompressor/none.c (grub_decompress_core): Exit + early if src == dest. + * util/grub-mkimage.c (generate_image): Arange for src == dest if + compression is none. + 2011-05-17 Vladimir Serbinenko Reduce memory footprint on SGI by putting modules before the kernel diff --git a/grub-core/boot/decompressor/none.c b/grub-core/boot/decompressor/none.c index 44f56ce90..911e861e3 100644 --- a/grub-core/boot/decompressor/none.c +++ b/grub-core/boot/decompressor/none.c @@ -25,6 +25,9 @@ grub_decompress_core (void *src, void *dest, unsigned long n, char *d = (char *) dest; const char *s = (const char *) src; + if (d == s) + return; + if (d < s) while (n--) *d++ = *s++; diff --git a/util/grub-mkimage.c b/util/grub-mkimage.c index 5ae744a8e..2003a86d2 100644 --- a/util/grub-mkimage.c +++ b/util/grub-mkimage.c @@ -736,6 +736,7 @@ generate_image (const char *dir, char *prefix, FILE *out, char *mods[], grub_uint64_t start_address; void *rel_section; grub_size_t reloc_size, align; + size_t decompress_size; if (comp == COMPRESSION_AUTO) comp = image_target->default_compression; @@ -913,7 +914,6 @@ generate_image (const char *dir, char *prefix, FILE *out, char *mods[], char *full_img; size_t full_size; char *decompress_path, *decompress_img; - size_t decompress_size; const char *name; switch (comp) @@ -1410,9 +1410,13 @@ generate_image (const char *dir, char *prefix, FILE *out, char *mods[], size_t program_size; program_size = ALIGN_ADDR (core_size); - target_addr = (image_target->link_addr - - ALIGN_UP(total_module_size + core_size, 1048576) - - (1 << 20)); + if (comp == COMPRESSION_NONE) + target_addr = (image_target->link_addr + - total_module_size - decompress_size); + else + target_addr = (image_target->link_addr + - ALIGN_UP(total_module_size + core_size, 1048576) + - (1 << 20)); ecoff_img = xmalloc (program_size + sizeof (*head) + sizeof (*section)); grub_memset (ecoff_img, 0, program_size + sizeof (*head) + sizeof (*section)); @@ -1500,8 +1504,13 @@ generate_image (const char *dir, char *prefix, FILE *out, char *mods[], phdr->p_flags = grub_host_to_target32 (PF_R | PF_W | PF_X); if (image_target->id == IMAGE_LOONGSON_ELF) - target_addr = ALIGN_UP (image_target->link_addr - + kernel_size + total_module_size, 32); + { + if (comp == COMPRESSION_NONE) + target_addr = (image_target->link_addr - decompress_size); + else + target_addr = ALIGN_UP (image_target->link_addr + + kernel_size + total_module_size, 32); + } else target_addr = image_target->link_addr; ehdr->e_entry = grub_host_to_target32 (target_addr); From 4959e11109d8305a7a1aefa37cfd6bea60679038 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Tue, 17 May 2011 22:48:20 +0200 Subject: [PATCH 624/869] Use mipsel- rather than mips- in directories involving mipsel ports to allow both endiannesses coexist. * configure.ac: proparate target_cpu=mipsel rather than resetting to mips. All conditions adjusted. * tests/util/grub-shell-tester.in: Remove gratuitious target_cpu variable. * util/grub-install.in: Adjust conditions to take renaming into account. * util/grub-mkimage.c (image_targets): Likewise. New target mips-qemu_mips-elf for bigendian mips. --- ChangeLog | 13 +++++++++++ configure.ac | 41 +++++++++++++++++++++------------ tests/util/grub-shell-tester.in | 1 - util/grub-install.in | 6 ++--- util/grub-mkimage.c | 30 ++++++++++++++++++++---- 5 files changed, 68 insertions(+), 23 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2d6a02d08..1d4076a5b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2011-05-17 Vladimir Serbinenko + + Use mipsel- rather than mips- in directories involving mipsel ports to + allow both endiannesses coexist. + + * configure.ac: proparate target_cpu=mipsel rather than resetting to + mips. All conditions adjusted. + * tests/util/grub-shell-tester.in: Remove gratuitious target_cpu + variable. + * util/grub-install.in: Adjust conditions to take renaming into account. + * util/grub-mkimage.c (image_targets): Likewise. New target + mips-qemu_mips-elf for bigendian mips. + 2011-05-17 Vladimir Serbinenko Avoid unnecessary copying on MIPS. diff --git a/configure.ac b/configure.ac index 8f854155e..f674a90aa 100644 --- a/configure.ac +++ b/configure.ac @@ -72,7 +72,7 @@ case "$target_cpu" in amd64) target_cpu=x86_64 ;; sparc) target_cpu=sparc64 ;; mipsel|mips64el) - target_cpu=mips; + target_cpu=mipsel; machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_CPU_MIPSEL=1"; ;; mips|mips64) @@ -96,7 +96,8 @@ if test "x$with_platform" = x; then powerpc-*) platform=ieee1275 ;; powerpc64-*) platform=ieee1275 ;; sparc64-*) platform=ieee1275 ;; - mips-*) platform=loongson ;; + mipsel-*) platform=loongson ;; + mips-*) platform=arc ;; ia64-*) platform=efi ;; *) AC_MSG_ERROR([unsupported CPU: "$target_cpu"]) ;; esac @@ -126,10 +127,12 @@ case "$target_cpu"-"$platform" in ia64-efi) ;; mips-qemu_mips) ;; mips-qemu-mips) platform=qemu_mips;; - mips-yeeloong) platform=loongson ;; - mips-fuloong) platform=loongson ;; - mips-loongson) ;; mips-arc) ;; + mipsel-qemu_mips) ;; + mipsel-qemu-mips) platform=qemu_mips;; + mipsel-yeeloong) platform=loongson ;; + mipsel-fuloong) platform=loongson ;; + mipsel-loongson) ;; *-emu) ;; *) AC_MSG_ERROR([platform "$platform" is not supported for target CPU "$target_cpu"]) ;; esac @@ -167,10 +170,14 @@ case "$platform" in arc) machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_MACHINE_ARC=1" ;; esac case "$target_cpu" in - mips) machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_MACHINE_MIPS=1" ;; + mips |mipsel) machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_MACHINE_MIPS=1" ;; sparc64) machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_MACHINE_SPARC64=1" ;; esac -machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_MACHINE=`echo ${target_cpu}_$platform | sed y,abcdefghijklmnopqrstuvwxyz,ABCDEFGHIJKLMNOPQRSTUVWXYZ,`" +if test x${target_cpu} = xmipsel ; then + machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_MACHINE=`echo mips_$platform | sed y,abcdefghijklmnopqrstuvwxyz,ABCDEFGHIJKLMNOPQRSTUVWXYZ,`" +else + machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_MACHINE=`echo ${target_cpu}_$platform | sed y,abcdefghijklmnopqrstuvwxyz,ABCDEFGHIJKLMNOPQRSTUVWXYZ,`" +fi HOST_CPPFLAGS="$HOST_CPPFLAGS $machine_CPPFLAGS" TARGET_CPPFLAGS="$TARGET_CPPFLAGS $machine_CPPFLAGS" @@ -405,7 +412,7 @@ if test "x$grub_cv_cc_fno_dwarf2_cfi_asm" = xyes; then TARGET_CFLAGS="$TARGET_CFLAGS -fno-dwarf2-cfi-asm" fi -if test "${target_cpu}-${platform}" = mips-loongson; then +if test "${target_cpu}-${platform}" = mipsel-loongson; then AC_CACHE_CHECK([whether -march=loongson2f works], [grub_cv_cc_march_loongson2f], [ SAVE_CFLAGS="$CFLAGS" CFLAGS="$CFLAGS -march=loongson2f" @@ -958,12 +965,12 @@ AM_CONDITIONAL([COND_i386_ieee1275], [test x$target_cpu = xi386 -a x$platform = AM_CONDITIONAL([COND_i386_coreboot], [test x$target_cpu = xi386 -a x$platform = xcoreboot]) AM_CONDITIONAL([COND_i386_multiboot], [test x$target_cpu = xi386 -a x$platform = xmultiboot]) AM_CONDITIONAL([COND_x86_64_efi], [test x$target_cpu = xx86_64 -a x$platform = xefi]) -AM_CONDITIONAL([COND_mips_loongson], [test x$target_cpu = xmips -a x$platform = xloongson]) -AM_CONDITIONAL([COND_mips_qemu_mips], [test x$target_cpu = xmips -a x$platform = xqemu_mips]) +AM_CONDITIONAL([COND_mips_loongson], [test x$target_cpu = xmipsel -a x$platform = xloongson]) +AM_CONDITIONAL([COND_mips_qemu_mips], [test "(" x$target_cpu = xmips -o x$target_cpu = xmipsel ")" -a x$platform = xqemu_mips]) AM_CONDITIONAL([COND_mips_arc], [test x$target_cpu = xmips -a x$platform = xarc]) AM_CONDITIONAL([COND_sparc64_ieee1275], [test x$target_cpu = xsparc64 -a x$platform = xieee1275]) AM_CONDITIONAL([COND_powerpc_ieee1275], [test x$target_cpu = xpowerpc -a x$platform = xieee1275]) -AM_CONDITIONAL([COND_mips], [test x$target_cpu = xmips]) +AM_CONDITIONAL([COND_mips], [test x$target_cpu = xmips -o x$target_cpu = xmipsel]) AM_CONDITIONAL([COND_HOST_HURD], [test x$host_kernel = xhurd]) AM_CONDITIONAL([COND_HOST_LINUX], [test x$host_kernel = xlinux]) @@ -985,19 +992,23 @@ AM_CONDITIONAL([COND_HAVE_ASM_USCORE], [test x$HAVE_ASM_USCORE = x1]) AM_CONDITIONAL([COND_CYGWIN], [test x$host_os = xcygwin]) # Output files. +cpudir="${target_cpu}" +if test x${cpudir} = xmipsel; then + cpudir=mips; +fi grub_CHECK_LINK_DIR if test x"$link_dir" = xyes ; then - AC_CONFIG_LINKS([include/grub/cpu:include/grub/$target_cpu]) + AC_CONFIG_LINKS([include/grub/cpu:include/grub/$cpudir]) if test "$platform" != emu ; then - AC_CONFIG_LINKS([include/grub/machine:include/grub/$target_cpu/$platform]) + AC_CONFIG_LINKS([include/grub/machine:include/grub/$cpudir/$platform]) fi else mkdir -p include/grub 2>/dev/null rm -rf include/grub/cpu - cp -rp $srcdir/include/grub/$target_cpu include/grub/cpu 2>/dev/null + cp -rp $srcdir/include/grub/$cpudir include/grub/cpu 2>/dev/null if test "$platform" != emu ; then rm -rf include/grub/machine - cp -rp $srcdir/include/grub/$target_cpu/$platform include/grub/machine 2>/dev/null + cp -rp $srcdir/include/grub/$cpudir/$platform include/grub/machine 2>/dev/null fi fi diff --git a/tests/util/grub-shell-tester.in b/tests/util/grub-shell-tester.in index 02e49d3a4..b839825f1 100644 --- a/tests/util/grub-shell-tester.in +++ b/tests/util/grub-shell-tester.in @@ -27,7 +27,6 @@ builddir=@builddir@ PACKAGE_NAME=@PACKAGE_NAME@ PACKAGE_TARNAME=@PACKAGE_TARNAME@ PACKAGE_VERSION=@PACKAGE_VERSION@ -target_cpu=@target_cpu@ # Force build directory components PATH=${builddir}:$PATH diff --git a/util/grub-install.in b/util/grub-install.in index ad6ea1037..db3a4db98 100644 --- a/util/grub-install.in +++ b/util/grub-install.in @@ -554,13 +554,13 @@ fi case "${target_cpu}-${platform}" in sparc64-ieee1275) mkimage_target=sparc64-ieee1275-raw ;; - mips-loongson) mkimage_target=mipsel-loongson-elf ;; + mipsel-loongson) mkimage_target=mipsel-loongson-elf ;; *) mkimage_target="${target_cpu}-${platform}" ;; esac case "${target_cpu}-${platform}" in i386-efi | x86_64-efi) imgext=efi ;; - mips-loongson | i386-coreboot | i386-multiboot | i386-ieee1275 \ + mipsel-loongson | i386-coreboot | i386-multiboot | i386-ieee1275 \ | powerpc-ieee1275) imgext=elf ;; *) imgext=img ;; esac @@ -569,7 +569,7 @@ esac "$grub_mkimage" ${config_opt} -d "${pkglibdir}" -O ${mkimage_target} --output="${grubdir}/core.${imgext}" --prefix="${prefix_drive}${relative_grubdir}" $modules || exit 1 # Backward-compatibility kludges -if [ "${target_cpu}-${platform}" = "mips-loongson" ]; then +if [ "${target_cpu}-${platform}" = "mipsel-loongson" ]; then cp "${grubdir}/core.${imgext}" "${bootdir}"/grub.elf elif [ "${target_cpu}-${platform}" = "i386-ieee1275" ] || [ "${target_cpu}-${platform}" = "powerpc-ieee1275" ]; then cp "${grubdir}/core.${imgext}" "${grubdir}/grub" diff --git a/util/grub-mkimage.c b/util/grub-mkimage.c index 2003a86d2..9fc37df2b 100644 --- a/util/grub-mkimage.c +++ b/util/grub-mkimage.c @@ -274,7 +274,7 @@ struct image_target_desc image_targets[] = .elf_target = EM_X86_64, }, { - .dirname = "mips-loongson", + .dirname = "mipsel-loongson", .names = { "mipsel-yeeloong-flash", NULL }, .voidp_sizeof = 4, .bigendian = 0, @@ -296,7 +296,7 @@ struct image_target_desc image_targets[] = .default_compression = COMPRESSION_NONE }, { - .dirname = "mips-loongson", + .dirname = "mipsel-loongson", .names = { "mipsel-fuloong-flash", NULL }, .voidp_sizeof = 4, .bigendian = 0, @@ -318,7 +318,7 @@ struct image_target_desc image_targets[] = .default_compression = COMPRESSION_NONE }, { - .dirname = "mips-loongson", + .dirname = "mipsel-loongson", .names = { "mipsel-loongson-elf", "mipsel-yeeloong-elf", "mipsel-fuloong-elf", NULL }, .voidp_sizeof = 4, @@ -445,7 +445,7 @@ struct image_target_desc image_targets[] = .default_compression = COMPRESSION_NONE }, { - .dirname = "mips-qemu_mips", + .dirname = "mipsel-qemu_mips", .names = { "mipsel-qemu_mips-elf", NULL }, .voidp_sizeof = 4, .bigendian = 0, @@ -466,6 +466,28 @@ struct image_target_desc image_targets[] = .link_align = GRUB_KERNEL_MIPS_QEMU_MIPS_LINK_ALIGN, .default_compression = COMPRESSION_NONE }, + { + .dirname = "mips-qemu_mips", + .names = { "mips-qemu_mips-elf", NULL }, + .voidp_sizeof = 4, + .bigendian = 1, + .id = IMAGE_LOONGSON_ELF, + .flags = PLATFORM_FLAGS_DECOMPRESSORS, + .prefix = GRUB_KERNEL_MIPS_QEMU_MIPS_PREFIX, + .prefix_end = GRUB_KERNEL_MIPS_QEMU_MIPS_PREFIX_END, + .raw_size = 0, + .total_module_size = GRUB_KERNEL_MIPS_QEMU_MIPS_TOTAL_MODULE_SIZE, + .compressed_size = TARGET_NO_FIELD, + .kernel_image_size = TARGET_NO_FIELD, + .section_align = 1, + .vaddr_offset = 0, + .install_dos_part = TARGET_NO_FIELD, + .install_bsd_part = TARGET_NO_FIELD, + .link_addr = GRUB_KERNEL_MIPS_QEMU_MIPS_LINK_ADDR, + .elf_target = EM_MIPS, + .link_align = GRUB_KERNEL_MIPS_QEMU_MIPS_LINK_ALIGN, + .default_compression = COMPRESSION_NONE + }, }; #define grub_target_to_host32(x) (grub_target_to_host32_real (image_target, (x))) From 543a8f6ef929e94a45e293c4aeb3c6fbb9c6963e Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 18 May 2011 00:21:49 +0200 Subject: [PATCH 625/869] * grub-core/kern/ia64/dl_helper.c (grub_ia64_dl_get_tramp_got_size): Fix potential usage of Elf32 instead of Elf64 when compiling on 32-bit architecture. Add endianness macros while on it. --- ChangeLog | 6 ++++++ grub-core/kern/ia64/dl_helper.c | 32 ++++++++++++++++---------------- 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1d4076a5b..59574202a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2011-05-17 Vladimir Serbinenko + + * grub-core/kern/ia64/dl_helper.c (grub_ia64_dl_get_tramp_got_size): + Fix potential usage of Elf32 instead of Elf64 when compiling on + 32-bit architecture. Add endianness macros while on it. + 2011-05-17 Vladimir Serbinenko Use mipsel- rather than mips- in directories involving mipsel ports to diff --git a/grub-core/kern/ia64/dl_helper.c b/grub-core/kern/ia64/dl_helper.c index 9503c49ea..91f28026e 100644 --- a/grub-core/kern/ia64/dl_helper.c +++ b/grub-core/kern/ia64/dl_helper.c @@ -27,35 +27,35 @@ void grub_ia64_dl_get_tramp_got_size (const void *ehdr, grub_size_t *tramp, grub_size_t *got) { - const Elf_Ehdr *e = ehdr; + const Elf64_Ehdr *e = ehdr; grub_size_t cntt = 0, cntg = 0;; - const Elf_Shdr *s; - Elf_Word entsize; + const Elf64_Shdr *s; + Elf64_Word entsize; unsigned i; /* Find a symbol table. */ - for (i = 0, s = (Elf_Shdr *) ((char *) e + e->e_shoff); - i < e->e_shnum; - i++, s = (Elf_Shdr *) ((char *) s + e->e_shentsize)) - if (s->sh_type == SHT_SYMTAB) + for (i = 0, s = (Elf64_Shdr *) ((char *) e + grub_le_to_cpu32 (e->e_shoff)); + i < grub_le_to_cpu16 (e->e_shnum); + i++, s = (Elf64_Shdr *) ((char *) s + grub_le_to_cpu16 (e->e_shentsize))) + if (grub_le_to_cpu32 (s->sh_type) == SHT_SYMTAB) break; - if (i == e->e_shnum) + if (i == grub_le_to_cpu16 (e->e_shnum)) return; entsize = s->sh_entsize; - for (i = 0, s = (Elf_Shdr *) ((char *) e + e->e_shoff); - i < e->e_shnum; - i++, s = (Elf_Shdr *) ((char *) s + e->e_shentsize)) - if (s->sh_type == SHT_RELA) + for (i = 0, s = (Elf64_Shdr *) ((char *) e + grub_le_to_cpu32 (e->e_shoff)); + i < grub_le_to_cpu16 (e->e_shnum); + i++, s = (Elf64_Shdr *) ((char *) s + grub_le_to_cpu16 (e->e_shentsize))) + if (grub_le_to_cpu32 (s->sh_type) == SHT_RELA) { - Elf_Rela *rel, *max; + Elf64_Rela *rel, *max; - for (rel = (Elf_Rela *) ((char *) e + s->sh_offset), - max = rel + s->sh_size / s->sh_entsize; + for (rel = (Elf64_Rela *) ((char *) e + grub_le_to_cpu32 (s->sh_offset)), + max = rel + grub_le_to_cpu32 (s->sh_size) / grub_le_to_cpu16 (s->sh_entsize); rel < max; rel++) - switch (ELF_R_TYPE (rel->r_info)) + switch (ELF64_R_TYPE (grub_le_to_cpu32 (rel->r_info))) { case R_IA64_PCREL21B: cntt++; From 6ad6223e925efc5e0fa1d0d46c8620c09a06ea0b Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 18 May 2011 01:38:01 +0200 Subject: [PATCH 626/869] Unify grub-mkrescue (except powerpc) and grrub-mknetdir across platforms * grub-core/Makefile.am (platform_DATA): Add modinfo.sh. * grub-core/modinfo.sh.in: New file. * grub-core/Makefile.core.def (modinfo.sh): New script. * util/grub-mknetdir.in: Use modinfo.sh. * util/grub-mkrescue.in: Likewise. --- ChangeLog | 10 ++++++++++ grub-core/Makefile.am | 1 + grub-core/Makefile.core.def | 6 ++++++ grub-core/modinfo.sh.in | 4 ++++ util/grub-mknetdir.in | 9 +++------ util/grub-mkrescue.in | 7 +++---- 6 files changed, 27 insertions(+), 10 deletions(-) create mode 100644 grub-core/modinfo.sh.in diff --git a/ChangeLog b/ChangeLog index 59574202a..0c3503288 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2011-05-18 Vladimir Serbinenko + + Unify grub-mkrescue (except powerpc) and grrub-mknetdir across platforms + + * grub-core/Makefile.am (platform_DATA): Add modinfo.sh. + * grub-core/modinfo.sh.in: New file. + * grub-core/Makefile.core.def (modinfo.sh): New script. + * util/grub-mknetdir.in: Use modinfo.sh. + * util/grub-mkrescue.in: Likewise. + 2011-05-17 Vladimir Serbinenko * grub-core/kern/ia64/dl_helper.c (grub_ia64_dl_get_tramp_got_size): diff --git a/grub-core/Makefile.am b/grub-core/Makefile.am index 88858c8ab..98e275f7e 100644 --- a/grub-core/Makefile.am +++ b/grub-core/Makefile.am @@ -329,6 +329,7 @@ CLEANFILES += config.log syminfo.lst moddep.lst $(MOD_FILES): %.mod : genmod.sh moddep.lst %.module$(EXEEXT) TARGET_OBJ2ELF=@TARGET_OBJ2ELF@ sh $^ $@ platform_DATA += $(MOD_FILES) +platform_DATA += modinfo.sh CLEANFILES += $(MOD_FILES) if COND_ENABLE_EFIEMU diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def index c717167cb..8afb98b73 100644 --- a/grub-core/Makefile.core.def +++ b/grub-core/Makefile.core.def @@ -12,6 +12,12 @@ script = { common = genmod.sh.in; }; +script = { + installdir = noinst; + name = modinfo.sh; + common = modinfo.sh.in; +}; + kernel = { name = kernel; diff --git a/grub-core/modinfo.sh.in b/grub-core/modinfo.sh.in new file mode 100644 index 000000000..ff31ca816 --- /dev/null +++ b/grub-core/modinfo.sh.in @@ -0,0 +1,4 @@ +#!/bin/sh + +grub_modinfo_target_cpu=@target_cpu@ +grub_modinfo_platform=@platform@ diff --git a/util/grub-mknetdir.in b/util/grub-mknetdir.in index b353e98b9..61a7ec3ad 100644 --- a/util/grub-mknetdir.in +++ b/util/grub-mknetdir.in @@ -27,12 +27,8 @@ libdir=@libdir@ PACKAGE_NAME=@PACKAGE_NAME@ PACKAGE_TARNAME=@PACKAGE_TARNAME@ PACKAGE_VERSION=@PACKAGE_VERSION@ -target_cpu=@target_cpu@ -platform=@platform@ host_os=@host_os@ -pkglibdir=${libdir}/`echo ${PACKAGE_TARNAME}/${target_cpu}-${platform} | sed ${transform}` localedir=@datadir@/locale -native_platform=@platform@ pkglib_DATA="moddep.lst command.lst fs.lst partmap.lst parttool.lst handler.lst video.lst crypto.lst terminal.lst" self=`basename $0` @@ -64,7 +60,7 @@ Install GRUB on your drive. --subdir=DIR relative subdirectory on network server --grub-mkimage=FILE use FILE as grub-mkimage -$self copies GRUB images into net_directory/subdir/${target_cpu}-${platform} +$self copies GRUB images into net_directory/subdir/target_cpu-platform Report bugs to . EOF @@ -222,7 +218,8 @@ if [ "${override_dir}" = "" ] ; then process_input_dir ${pc_dir} i386-pc fi else - process_input_dir ${override_dir} ${target_cpu}-${native_platform} + source "${override_dir}"/modinfo.sh + process_input_dir "${override_dir}" ${grub_modinfo_target_cpu}-${grub_modinfo_platform} fi diff --git a/util/grub-mkrescue.in b/util/grub-mkrescue.in index f7f751708..2b6c9d391 100644 --- a/util/grub-mkrescue.in +++ b/util/grub-mkrescue.in @@ -27,8 +27,6 @@ libdir=@libdir@ PACKAGE_NAME=@PACKAGE_NAME@ PACKAGE_TARNAME=@PACKAGE_TARNAME@ PACKAGE_VERSION=@PACKAGE_VERSION@ -target_cpu=@target_cpu@ -native_platform=@platform@ pkglib_DATA="moddep.lst command.lst fs.lst partmap.lst parttool.lst handler.lst video.lst crypto.lst terminal.lst" self=`basename $0` @@ -231,14 +229,15 @@ if [ "${override_dir}" = "" ] ; then process_input_dir ${efi64_dir} x86_64-efi fi else - process_input_dir ${override_dir} ${target_cpu}-${native_platform} + source "${override_dir}"/modinfo.sh + process_input_dir "${override_dir}" ${grub_modinfo_target_cpu}-${grub_modinfo_platform} multiboot_dir= pc_dir= efi32_dir= efi64_dir= coreboot_dir= qemu_dir= - case "${target_cpu}-${native_platform}" in + case "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" in i386-multiboot) multiboot_dir=${override_dir} ;; i386-coreboot) coreboot_dir=${override_dir} ;; i386-qemu) qemu_dir=${override_dir} ;; From cf02731e4837930b21bcb30346ae696d4c9a90d2 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 18 May 2011 12:39:22 +0200 Subject: [PATCH 627/869] * grub-core/Makefile.core.def (ieee1275_fb): Use enable=powerpc_ieee1275 for cleanness. --- ChangeLog | 5 +++++ grub-core/Makefile.core.def | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 48b7bc171..eb86c47ab 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-05-18 Vladimir Serbinenko + + * grub-core/Makefile.core.def (ieee1275_fb): Use enable=powerpc_ieee1275 + for cleanness. + 2011-05-18 Vladimir Serbinenko FreeDOS direct loading support. diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def index 76539e8d2..f10b63238 100644 --- a/grub-core/Makefile.core.def +++ b/grub-core/Makefile.core.def @@ -1548,7 +1548,7 @@ module = { module = { name = ieee1275_fb; ieee1275 = video/ieee1275.c; - enable = powerpc; + enable = powerpc_ieee1275; }; module = { From 69b11a560c9b3f9f8f42cb3e6290a0db82b3df30 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 18 May 2011 12:41:22 +0200 Subject: [PATCH 628/869] add missing file --- include/grub/fat.h | 70 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 include/grub/fat.h diff --git a/include/grub/fat.h b/include/grub/fat.h new file mode 100644 index 000000000..7d8e51ad5 --- /dev/null +++ b/include/grub/fat.h @@ -0,0 +1,70 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2000,2001,2002,2003,2004,2005,2007,2008,2009 Free Software Foundation, Inc. + * + * GRUB is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see . + */ + +#ifndef GRUB_FAT_H +#define GRUB_FAT_H 1 + +#include + +struct grub_fat_bpb +{ + grub_uint8_t jmp_boot[3]; + grub_uint8_t oem_name[8]; + grub_uint16_t bytes_per_sector; + grub_uint8_t sectors_per_cluster; + grub_uint16_t num_reserved_sectors; + grub_uint8_t num_fats; + grub_uint16_t num_root_entries; + grub_uint16_t num_total_sectors_16; + grub_uint8_t media; + grub_uint16_t sectors_per_fat_16; + grub_uint16_t sectors_per_track; + grub_uint16_t num_heads; + grub_uint32_t num_hidden_sectors; + grub_uint32_t num_total_sectors_32; + union + { + struct + { + grub_uint8_t num_ph_drive; + grub_uint8_t reserved; + grub_uint8_t boot_sig; + grub_uint32_t num_serial; + grub_uint8_t label[11]; + grub_uint8_t fstype[8]; + } __attribute__ ((packed)) fat12_or_fat16; + struct + { + grub_uint32_t sectors_per_fat_32; + grub_uint16_t extended_flags; + grub_uint16_t fs_version; + grub_uint32_t root_cluster; + grub_uint16_t fs_info; + grub_uint16_t backup_boot_sector; + grub_uint8_t reserved[12]; + grub_uint8_t num_ph_drive; + grub_uint8_t reserved1; + grub_uint8_t boot_sig; + grub_uint32_t num_serial; + grub_uint8_t label[11]; + grub_uint8_t fstype[8]; + } __attribute__ ((packed)) fat32; + } __attribute__ ((packed)) version_specific; +} __attribute__ ((packed)); + +#endif From 26618ff0db4b9454685ebd93414aef4eae868fa4 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 18 May 2011 12:51:05 +0200 Subject: [PATCH 629/869] Patch BPB in ntldr and chainloader --bpb. * grub-core/fs/fat.c: Include grub/fat.h. (grub_fat_bpb): Moved to ... * include/grub/fat.h (grub_fat_bpb): ... here. New file. * grub-core/loader/i386/pc/chainloader.c: Include grub/fat.h and grub/ntfs.h. * include/grub/i386/pc/chainloader.h (grub_chainloader_flags_t): Moved from here... * grub-core/loader/i386/pc/chainloader.c (grub_chainloader_flags_t): ... here. * grub-core/loader/i386/pc/chainloader.c (grub_chainloader_patch_bpb): New function. (grub_chainloader_cmd): Patch BPB if --bpb is given. (GRUB_MOD_INIT): Show --bpb. * grub-core/loader/i386/pc/ntldr.c (grub_cmd_ntldr): Patch BPB. * grub-core/normal/main.c (features): New variable. (GRUB_MOD_INIT): Set feature_* variables. * include/grub/i386/pc/chainloader.h (grub_chainloader_patch_bpb): New proto. * include/grub/ntfs.h (grub_ntfs_bpb): New field bios_drive. --- ChangeLog | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ChangeLog b/ChangeLog index 9ea22d970..e80ff7870 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,7 @@ 2011-05-18 Vladimir Serbinenko + Patch BPB in ntldr and chainloader --bpb. + * grub-core/fs/fat.c: Include grub/fat.h. (grub_fat_bpb): Moved to ... * include/grub/fat.h (grub_fat_bpb): ... here. New file. From 5626056ffb35ed0320fed4bceac9768ebc8c31d2 Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Wed, 18 May 2011 12:53:07 +0100 Subject: [PATCH 630/869] * grub-core/genmod.sh.in: Use 'set -e' rather than '#! /bin/sh -e', to avoid accidents when debugging with 'sh -x'. * grub-core/gensyminfo.sh.in: Likewise. * tests/example_scripted_test.in: Likewise. * tests/grub_cmd_regexp.in: Likewise. * tests/grub_script_blanklines.in: Likewise. * tests/grub_script_dollar.in: Likewise. * tests/grub_script_expansion.in: Likewise. * tests/grub_script_final_semicolon.in: Likewise. * tests/partmap_test.in: Likewise. * tests/util/grub-shell-tester.in: Likewise. * tests/util/grub-shell.in: Likewise. --- ChangeLog | 15 +++++++++++++++ grub-core/genmod.sh.in | 5 +++-- grub-core/gensyminfo.sh.in | 5 +++-- tests/example_scripted_test.in | 3 ++- tests/grub_cmd_regexp.in | 3 ++- tests/grub_script_blanklines.in | 3 ++- tests/grub_script_dollar.in | 3 ++- tests/grub_script_expansion.in | 3 ++- tests/grub_script_final_semicolon.in | 3 ++- tests/partmap_test.in | 5 +++-- tests/util/grub-shell-tester.in | 3 ++- tests/util/grub-shell.in | 3 ++- 12 files changed, 40 insertions(+), 14 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9ed12abbe..bac09e101 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +2011-05-18 Colin Watson + + * grub-core/genmod.sh.in: Use 'set -e' rather than '#! /bin/sh -e', + to avoid accidents when debugging with 'sh -x'. + * grub-core/gensyminfo.sh.in: Likewise. + * tests/example_scripted_test.in: Likewise. + * tests/grub_cmd_regexp.in: Likewise. + * tests/grub_script_blanklines.in: Likewise. + * tests/grub_script_dollar.in: Likewise. + * tests/grub_script_expansion.in: Likewise. + * tests/grub_script_final_semicolon.in: Likewise. + * tests/partmap_test.in: Likewise. + * tests/util/grub-shell-tester.in: Likewise. + * tests/util/grub-shell.in: Likewise. + 2011-05-18 Colin Watson Move gfxmenu color handling to video, so that gfxterm can use it diff --git a/grub-core/genmod.sh.in b/grub-core/genmod.sh.in index 023cd1062..4cab8e50e 100644 --- a/grub-core/genmod.sh.in +++ b/grub-core/genmod.sh.in @@ -1,5 +1,6 @@ -#! /bin/sh -e -# +#! /bin/sh +set -e + # Copyright (C) 2010 Free Software Foundation, Inc. # # This gensymlist.sh is free software; the author diff --git a/grub-core/gensyminfo.sh.in b/grub-core/gensyminfo.sh.in index 4f5184913..d383f2640 100644 --- a/grub-core/gensyminfo.sh.in +++ b/grub-core/gensyminfo.sh.in @@ -1,5 +1,6 @@ -#! /bin/sh -e -# +#! /bin/sh +set -e + # Copyright (C) 2010 Free Software Foundation, Inc. # # This gensymlist.sh is free software; the author diff --git a/tests/example_scripted_test.in b/tests/example_scripted_test.in index 9ac0424c0..09633e893 100644 --- a/tests/example_scripted_test.in +++ b/tests/example_scripted_test.in @@ -1,3 +1,4 @@ -#!/bin/sh -e +#!/bin/sh +set -e true diff --git a/tests/grub_cmd_regexp.in b/tests/grub_cmd_regexp.in index 43b479fec..e7e625701 100644 --- a/tests/grub_cmd_regexp.in +++ b/tests/grub_cmd_regexp.in @@ -1,4 +1,5 @@ -#! /bin/bash -e +#! /bin/bash +set -e # Run GRUB script in a Qemu instance # Copyright (C) 2010 Free Software Foundation, Inc. diff --git a/tests/grub_script_blanklines.in b/tests/grub_script_blanklines.in index 71b869bd3..89ed763d3 100644 --- a/tests/grub_script_blanklines.in +++ b/tests/grub_script_blanklines.in @@ -1,4 +1,5 @@ -#! /bin/sh -e +#! /bin/sh +set -e @builddir@/grub-script-check < Date: Wed, 18 May 2011 12:57:59 +0100 Subject: [PATCH 631/869] * util/grub-mkrescue.in: Use portable `.' rather than non-portable `source'. --- ChangeLog | 5 +++++ util/grub-mkrescue.in | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index bac09e101..7b44c32fc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-05-18 Colin Watson + + * util/grub-mkrescue.in: Use portable `.' rather than non-portable + `source'. + 2011-05-18 Colin Watson * grub-core/genmod.sh.in: Use 'set -e' rather than '#! /bin/sh -e', diff --git a/util/grub-mkrescue.in b/util/grub-mkrescue.in index 2b6c9d391..8367c4dd4 100644 --- a/util/grub-mkrescue.in +++ b/util/grub-mkrescue.in @@ -229,7 +229,7 @@ if [ "${override_dir}" = "" ] ; then process_input_dir ${efi64_dir} x86_64-efi fi else - source "${override_dir}"/modinfo.sh + . "${override_dir}"/modinfo.sh process_input_dir "${override_dir}" ${grub_modinfo_target_cpu}-${grub_modinfo_platform} multiboot_dir= pc_dir= From bf947d36e3408fd4f5c74b7751663924500a53ff Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 18 May 2011 15:35:19 +0200 Subject: [PATCH 632/869] Use full 64-bit division. * grub-core/kern/misc.c (grub_divmod64_full): Renamed to ... (grub_divmod64): ... this. * include/grub/misc.h (grub_divmod64): Removed. All users switch to full version. --- ChangeLog | 9 +++++++++ grub-core/commands/ls.c | 5 +++-- grub-core/disk/i386/pc/biosdisk.c | 2 +- grub-core/disk/lvm.c | 4 ++-- grub-core/disk/raid.c | 4 ++-- grub-core/disk/scsi.c | 2 +- grub-core/fs/affs.c | 2 +- grub-core/fs/btrfs.c | 16 ++++++++-------- grub-core/fs/i386/pc/pxe.c | 3 ++- grub-core/fs/minix.c | 4 ++-- grub-core/fs/nilfs2.c | 14 ++++++++------ grub-core/fs/ntfs.c | 2 +- grub-core/io/bufio.c | 2 +- grub-core/kern/misc.c | 4 ++-- include/grub/misc.h | 17 +++-------------- 15 files changed, 46 insertions(+), 44 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7b44c32fc..cd49e296e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2011-05-18 Vladimir Serbinenko + + Use full 64-bit division. + + * grub-core/kern/misc.c (grub_divmod64_full): Renamed to ... + (grub_divmod64): ... this. + * include/grub/misc.h (grub_divmod64): Removed. All users switch to full + version. + 2011-05-18 Colin Watson * util/grub-mkrescue.in: Use portable `.' rather than non-portable diff --git a/grub-core/commands/ls.c b/grub-core/commands/ls.c index 5fc648a9b..4c4051a22 100644 --- a/grub-core/commands/ls.c +++ b/grub-core/commands/ls.c @@ -134,11 +134,12 @@ grub_ls_list_files (char *dirname, int longlist, int all, int human) if (units) { - grub_uint32_t whole, fraction; + grub_uint64_t whole, fraction; whole = grub_divmod64 (fsize, 100, &fraction); grub_snprintf (buf, sizeof (buf), - "%u.%02u%c", whole, fraction, + "%" PRIuGRUB_UINT64_T + ".%02" PRIuGRUB_UINT64_T "%c", whole, fraction, grub_human_sizes[units]); grub_printf ("%-12s", buf); } diff --git a/grub-core/disk/i386/pc/biosdisk.c b/grub-core/disk/i386/pc/biosdisk.c index 1d47dc727..3baf20717 100644 --- a/grub-core/disk/i386/pc/biosdisk.c +++ b/grub-core/disk/i386/pc/biosdisk.c @@ -506,7 +506,7 @@ static grub_size_t get_safe_sectors (grub_disk_addr_t sector, grub_uint32_t sectors) { grub_size_t size; - grub_uint32_t offset; + grub_uint64_t offset; /* OFFSET = SECTOR % SECTORS */ grub_divmod64 (sector, sectors, &offset); diff --git a/grub-core/disk/lvm.c b/grub-core/disk/lvm.c index 206e3e220..563b49b49 100644 --- a/grub-core/disk/lvm.c +++ b/grub-core/disk/lvm.c @@ -247,9 +247,9 @@ read_lv (struct grub_lvm_lv *lv, grub_disk_addr_t sector, /* This is a striped segment. We have to find the right PV similar to RAID0. */ struct grub_lvm_node *stripe = seg->nodes; - grub_uint32_t a, b; + grub_uint64_t a, b; grub_uint64_t seg_offset; /* Offset of the segment in PV device. */ - unsigned int stripenr; + grub_uint64_t stripenr; offset = sector - ((grub_uint64_t) seg->start_extent * (grub_uint64_t) vg->extent_size); diff --git a/grub-core/disk/raid.c b/grub-core/disk/raid.c index 946e6d2c2..c6be3efde 100644 --- a/grub-core/disk/raid.c +++ b/grub-core/disk/raid.c @@ -245,7 +245,7 @@ grub_raid_read (grub_disk_t disk, grub_disk_addr_t sector, case 10: { grub_disk_addr_t read_sector, far_ofs; - grub_uint32_t disknr, b, near, far, ofs; + grub_uint64_t disknr, b, near, far, ofs; read_sector = grub_divmod64 (sector, array->chunk_size, &b); far = ofs = near = 1; @@ -351,7 +351,7 @@ grub_raid_read (grub_disk_t disk, grub_disk_addr_t sector, case 6: { grub_disk_addr_t read_sector; - grub_uint32_t b, p, n, disknr, e; + grub_uint64_t b, p, n, disknr, e; /* n = 1 for level 4 and 5, 2 for level 6. */ n = array->level / 3; diff --git a/grub-core/disk/scsi.c b/grub-core/disk/scsi.c index 25f0e3aea..d683cbfe7 100644 --- a/grub-core/disk/scsi.c +++ b/grub-core/disk/scsi.c @@ -512,7 +512,7 @@ grub_scsi_read (grub_disk_t disk, grub_disk_addr_t sector, return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, "unsupported SCSI block size"); - grub_uint32_t sector_mod = 0; + grub_uint64_t sector_mod = 0; sector = grub_divmod64 (sector, spb, §or_mod); if (! (sector_mod == 0 && size % spb == 0)) diff --git a/grub-core/fs/affs.c b/grub-core/fs/affs.c index 7c2099410..e17540e2f 100644 --- a/grub-core/fs/affs.c +++ b/grub-core/fs/affs.c @@ -125,7 +125,7 @@ grub_affs_read_block (grub_fshelp_node_t node, grub_disk_addr_t fileblock) int block = node->block; struct grub_affs_file file; struct grub_affs_data *data = node->data; - grub_uint32_t mod; + grub_uint64_t mod; /* Find the block that points to the fileblock we are looking up by following the chain until the right table is reached. */ diff --git a/grub-core/fs/btrfs.c b/grub-core/fs/btrfs.c index 59e91b552..533529e3f 100644 --- a/grub-core/fs/btrfs.c +++ b/grub-core/fs/btrfs.c @@ -649,7 +649,7 @@ grub_btrfs_read_logical (struct grub_btrfs_data *data, chunk_found: { - grub_uint32_t stripen; + grub_uint64_t stripen; grub_uint64_t stripe_offset; grub_uint64_t off = addr - grub_le_to_cpu64 (key->offset); unsigned redundancy = 1; @@ -679,10 +679,10 @@ grub_btrfs_read_logical (struct grub_btrfs_data *data, { grub_uint64_t stripe_length; grub_dprintf ("btrfs", "single\n"); - stripe_length = grub_divmod64_full (grub_le_to_cpu64 (chunk->size), - grub_le_to_cpu16 (chunk->nstripes), - NULL); - stripen = grub_divmod64_full (off, stripe_length, &stripe_offset); + stripe_length = grub_divmod64 (grub_le_to_cpu64 (chunk->size), + grub_le_to_cpu16 (chunk->nstripes), + NULL); + stripen = grub_divmod64 (off, stripe_length, &stripe_offset); csize = (stripen + 1) * stripe_length - off; break; } @@ -699,7 +699,7 @@ grub_btrfs_read_logical (struct grub_btrfs_data *data, case GRUB_BTRFS_CHUNK_TYPE_RAID0: { grub_uint64_t middle, high; - grub_uint32_t low; + grub_uint64_t low; grub_dprintf ("btrfs", "RAID0\n"); middle = grub_divmod64 (off, grub_le_to_cpu64 (chunk->stripe_length), @@ -715,7 +715,7 @@ grub_btrfs_read_logical (struct grub_btrfs_data *data, case GRUB_BTRFS_CHUNK_TYPE_RAID10: { grub_uint64_t middle, high; - grub_uint32_t low; + grub_uint64_t low; middle = grub_divmod64 (off, grub_le_to_cpu64 (chunk->stripe_length), &low); @@ -760,7 +760,7 @@ grub_btrfs_read_logical (struct grub_btrfs_data *data, grub_dprintf ("btrfs", "chunk 0x%" PRIxGRUB_UINT64_T "+0x%" PRIxGRUB_UINT64_T " (%d stripes (%d substripes) of %" - PRIxGRUB_UINT64_T ") stripe %" PRIxGRUB_UINT32_T + PRIxGRUB_UINT64_T ") stripe %" PRIxGRUB_UINT64_T " maps to 0x%" PRIxGRUB_UINT64_T "\n", grub_le_to_cpu64 (key->offset), grub_le_to_cpu64 (chunk->size), diff --git a/grub-core/fs/i386/pc/pxe.c b/grub-core/fs/i386/pc/pxe.c index 4304881fa..7d86b78bf 100644 --- a/grub-core/fs/i386/pc/pxe.c +++ b/grub-core/fs/i386/pc/pxe.c @@ -306,7 +306,8 @@ grub_pxefs_read (grub_file_t file, char *buf, grub_size_t len) struct grub_pxenv_tftp_read c; struct grub_pxe_data *data; struct grub_pxe_disk_data *disk_data = file->device->disk->data; - grub_uint32_t pn, r; + grub_uint32_t pn; + grub_uint64_t r; data = file->data; diff --git a/grub-core/fs/minix.c b/grub-core/fs/minix.c index 91659b0f6..64a64cca0 100644 --- a/grub-core/fs/minix.c +++ b/grub-core/fs/minix.c @@ -229,7 +229,7 @@ grub_minix_read_file (struct grub_minix_data *data, grub_disk_addr_t i; grub_disk_addr_t blockcnt; grub_uint64_t posblock; - grub_uint32_t blockoff; + grub_uint64_t blockoff; /* Adjust len so it we can't read past the end of the file. */ if (len + pos > GRUB_MINIX_INODE_SIZE (data)) @@ -242,7 +242,7 @@ grub_minix_read_file (struct grub_minix_data *data, for (i = posblock; i < blockcnt; i++) { grub_disk_addr_t blknr; - grub_uint32_t blockend = data->block_size; + grub_uint64_t blockend = data->block_size; grub_off_t skipfirst = 0; blknr = grub_minix_get_file_block (data, i); diff --git a/grub-core/fs/nilfs2.c b/grub-core/fs/nilfs2.c index 4c8d7633c..44fb213bd 100644 --- a/grub-core/fs/nilfs2.c +++ b/grub-core/fs/nilfs2.c @@ -303,7 +303,7 @@ grub_nilfs2_palloc_entries_per_group (struct grub_nilfs2_data *data) static inline grub_uint64_t grub_nilfs2_palloc_group (struct grub_nilfs2_data *data, - grub_uint64_t nr, grub_uint32_t * offset) + grub_uint64_t nr, grub_uint64_t * offset) { return grub_divmod64 (nr, grub_nilfs2_palloc_entries_per_group (data), offset); @@ -368,13 +368,15 @@ grub_nilfs2_palloc_entry_offset (struct grub_nilfs2_data *data, grub_uint64_t nr, unsigned long entry_size) { unsigned long group; - grub_uint32_t group_offset; + grub_uint64_t group_offset; group = grub_nilfs2_palloc_group (data, nr, &group_offset); return grub_nilfs2_palloc_bitmap_block_offset (data, group, entry_size) + 1 + - group_offset / grub_nilfs2_entries_per_block (data, entry_size); + grub_divmod64 (group_offset, grub_nilfs2_entries_per_block (data, + entry_size), + NULL); } @@ -577,7 +579,7 @@ grub_nilfs2_dat_translate (struct grub_nilfs2_data *data, grub_uint64_t key) struct grub_nilfs2_dat_entry entry; grub_disk_t disk = data->disk; grub_uint64_t pptr; - grub_uint32_t blockno, offset; + grub_uint64_t blockno, offset; unsigned int nilfs2_block_count = (1 << LOG2_NILFS2_BLOCK_SIZE (data)); blockno = grub_nilfs2_palloc_entry_offset (data, key, @@ -641,7 +643,7 @@ grub_nilfs2_read_checkpoint (struct grub_nilfs2_data *data, struct grub_nilfs2_checkpoint *cpp) { grub_uint64_t blockno; - grub_uint32_t offset; + grub_uint64_t offset; grub_uint64_t pptr; grub_disk_t disk = data->disk; unsigned int nilfs2_block_count = (1 << LOG2_NILFS2_BLOCK_SIZE (data)); @@ -679,7 +681,7 @@ grub_nilfs2_read_inode (struct grub_nilfs2_data *data, grub_uint64_t ino, struct grub_nilfs2_inode *inodep) { grub_uint64_t blockno; - unsigned int offset; + grub_uint64_t offset; grub_uint64_t pptr; grub_disk_t disk = data->disk; unsigned int nilfs2_block_count = (1 << LOG2_NILFS2_BLOCK_SIZE (data)); diff --git a/grub-core/fs/ntfs.c b/grub-core/fs/ntfs.c index 1a8d3f17f..5d128bcc0 100644 --- a/grub-core/fs/ntfs.c +++ b/grub-core/fs/ntfs.c @@ -431,7 +431,7 @@ read_data (struct grub_ntfs_attr *at, char *pa, char *dest, if (at->flags & AF_GPOS) { grub_disk_addr_t st0, st1; - grub_uint32_t m; + grub_uint64_t m; grub_divmod64 (ofs >> BLK_SHR, ctx->comp.spc, &m); diff --git a/grub-core/io/bufio.c b/grub-core/io/bufio.c index 3b456c1d2..adb38af56 100644 --- a/grub-core/io/bufio.c +++ b/grub-core/io/bufio.c @@ -106,7 +106,7 @@ grub_bufio_read (grub_file_t file, char *buf, grub_size_t len) { grub_size_t res = len; grub_bufio_t bufio = file->data; - grub_uint32_t pos; + grub_uint64_t pos; if ((file->offset >= bufio->file->offset) && (file->offset < bufio->file->offset + bufio->buffer_len)) diff --git a/grub-core/kern/misc.c b/grub-core/kern/misc.c index 1b4cdec66..a3dfabf82 100644 --- a/grub-core/kern/misc.c +++ b/grub-core/kern/misc.c @@ -597,7 +597,7 @@ grub_reverse (char *str) /* Divide N by D, return the quotient, and store the remainder in *R. */ grub_uint64_t -grub_divmod64_full (grub_uint64_t n, grub_uint64_t d, grub_uint64_t *r) +grub_divmod64 (grub_uint64_t n, grub_uint64_t d, grub_uint64_t *r) { /* This algorithm is typically implemented by hardware. The idea is to get the highest bit in N, 64 times, by keeping @@ -666,7 +666,7 @@ grub_lltoa (char *str, int c, unsigned long long n) /* BASE == 10 */ do { - unsigned m; + grub_uint64_t m; n = grub_divmod64 (n, 10, &m); *p++ = m + '0'; diff --git a/include/grub/misc.h b/include/grub/misc.h index 80588be33..da4bd4a7e 100644 --- a/include/grub/misc.h +++ b/include/grub/misc.h @@ -287,20 +287,9 @@ char *EXPORT_FUNC(grub_xasprintf) (const char *fmt, ...) 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_abort) (void) __attribute__ ((noreturn)); -grub_uint64_t EXPORT_FUNC(grub_divmod64_full) (grub_uint64_t n, - grub_uint64_t d, - grub_uint64_t *r); -static inline grub_uint64_t grub_divmod64 (grub_uint64_t n, - grub_uint32_t d, - grub_uint32_t *r) -{ - grub_uint64_t ret, rr; - - ret = grub_divmod64_full (n, d, &rr); - if (r) - *r = rr; - return ret; -} +grub_uint64_t EXPORT_FUNC(grub_divmod64) (grub_uint64_t n, + grub_uint64_t d, + grub_uint64_t *r); #if NEED_ENABLE_EXECUTE_STACK && !defined(GRUB_UTIL) void EXPORT_FUNC(__enable_execute_stack) (void *addr); From e775d8edfe32cadb0294241a89cabbb00e338e39 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 18 May 2011 15:37:18 +0200 Subject: [PATCH 633/869] * grub-core/bus/usb/usbhub.c (poll_nonroot_hub): Downgrade a printf into dprintf. --- ChangeLog | 5 +++++ grub-core/bus/usb/usbhub.c | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index cd49e296e..1a3731242 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-05-18 Vladimir Serbinenko + + * grub-core/bus/usb/usbhub.c (poll_nonroot_hub): Downgrade a printf + into dprintf. + 2011-05-18 Vladimir Serbinenko Use full 64-bit division. diff --git a/grub-core/bus/usb/usbhub.c b/grub-core/bus/usb/usbhub.c index fff94a3fc..b59f2f51d 100644 --- a/grub-core/bus/usb/usbhub.c +++ b/grub-core/bus/usb/usbhub.c @@ -352,8 +352,8 @@ poll_nonroot_hub (grub_usb_device_t dev) GRUB_USB_REQ_GET_STATUS, 0, i, sizeof (status), (char *) &status); - grub_printf ("dev = %p, i = %d, status = %08x\n", - dev, i, status); + grub_dprintf ("usb", "dev = %p, i = %d, status = %08x\n", + dev, i, status); if (err) continue; From 8b63a142977cf48d33fd5486a8afeac9de78aca4 Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Wed, 18 May 2011 16:10:52 +0100 Subject: [PATCH 634/869] * .bzrignore: Add grub-core/modinfo.sh and a number of test files. --- .bzrignore | 26 ++++++++++++++++++++++++++ ChangeLog | 4 ++++ 2 files changed, 30 insertions(+) diff --git a/.bzrignore b/.bzrignore index 668d060ca..69aedc290 100644 --- a/.bzrignore +++ b/.bzrignore @@ -26,11 +26,16 @@ docs/*.info docs/stamp-vti docs/version.texi *.elf +example_grub_script_test +example_scripted_test +example_unit_test *.exec genkernsyms.sh gensymlist.sh gentrigtables grub-bin2h +grub_cmd_echo +grub_cmd_regexp grub-editenv grub-emu grub_emu_init.c @@ -48,9 +53,28 @@ grub-probe grub_probe_init.c grub_probe_init.h grub-reboot +grub_script_blanklines +grub_script_blockarg +grub_script_break grub-script-check grub_script_check_init.c grub_script_check_init.h +grub_script_comments +grub_script_continue +grub_script_dollar +grub_script_echo1 +grub_script_echo_keywords +grub_script_expansion +grub_script_final_semicolon +grub_script_for1 +grub_script_functions +grub_script_if +grub_script_not +grub_script_return +grub_script_setparams +grub_script_shift +grub_script_vars1 +grub_script_while1 grub_script.tab.c grub_script.tab.h grub_script.yy.c @@ -74,6 +98,7 @@ Makefile *.mod mod-*.c missing +partmap_test *.pf2 *.pp po/*.mo @@ -108,6 +133,7 @@ grub-core/Makefile.gcry.def grub-core/contrib grub-core/genmod.sh grub-core/gensyminfo.sh +grub-core/modinfo.sh grub-core/*.module grub-core/*.pp util/bash-completion.d/grub diff --git a/ChangeLog b/ChangeLog index 1a3731242..3980ef7b4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2011-05-18 Colin Watson + + * .bzrignore: Add grub-core/modinfo.sh and a number of test files. + 2011-05-18 Vladimir Serbinenko * grub-core/bus/usb/usbhub.c (poll_nonroot_hub): Downgrade a printf From 63e3eea967a3b7148adbf97195023fb6460a9989 Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Wed, 18 May 2011 17:31:50 +0100 Subject: [PATCH 635/869] * Makefile.util.def (grub-ofpathname): Install manual page. --- ChangeLog | 4 ++++ Makefile.util.def | 1 + 2 files changed, 5 insertions(+) diff --git a/ChangeLog b/ChangeLog index 2708949d1..c8e754685 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2011-05-18 Colin Watson + + * Makefile.util.def (grub-ofpathname): Install manual page. + 2011-05-18 Colin Watson * grub-core/fs/squash4.c: Add missing GRUB_MOD_LICENSE. diff --git a/Makefile.util.def b/Makefile.util.def index 380c939b9..829b16fac 100644 --- a/Makefile.util.def +++ b/Makefile.util.def @@ -288,6 +288,7 @@ program = { program = { name = grub-ofpathname; installdir = sbin; + mansection = 8; ieee1275 = util/ieee1275/grub-ofpathname.c; ieee1275 = util/ieee1275/ofpath.c; From 9a79fcf2c9b56bc85f9d104f947125aa73099c31 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Thu, 19 May 2011 12:13:18 +0200 Subject: [PATCH 636/869] * grub-core/Makefile.core.def (lsacpi): Fix ia64 mismerge. (lsefisystab): Likewise. (lssal): Likewise. (lsefimmap): Likewise. (hdparm): Enable on qemu-mips. (setjmp): Add ia64 nodist. (serial): Simplify tags. --- ChangeLog | 10 ++++++++++ grub-core/Makefile.core.def | 13 +++++++------ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index c8e754685..1a68f911c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2011-05-19 Vladimir Serbinenko + + * grub-core/Makefile.core.def (lsacpi): Fix ia64 mismerge. + (lsefisystab): Likewise. + (lssal): Likewise. + (lsefimmap): Likewise. + (hdparm): Enable on qemu-mips. + (setjmp): Add ia64 nodist. + (serial): Simplify tags. + 2011-05-18 Colin Watson * Makefile.util.def (grub-ofpathname): Install manual page. diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def index 6f0dce6ff..3fdf395b4 100644 --- a/grub-core/Makefile.core.def +++ b/grub-core/Makefile.core.def @@ -505,7 +505,7 @@ module = { common = commands/lsacpi.c; - enable = x86_efi; + enable = efi; enable = i386_pc; enable = i386_coreboot; enable = i386_multiboot; @@ -516,7 +516,7 @@ module = { common = commands/efi/lsefisystab.c; - enable = x86_efi; + enable = efi; }; module = { @@ -524,7 +524,7 @@ module = { common = commands/efi/lssal.c; - enable = x86_efi; + enable = efi; }; module = { @@ -532,7 +532,7 @@ module = { common = commands/efi/lsefimmap.c; - enable = x86_efi; + enable = efi; }; module = { @@ -632,6 +632,7 @@ module = { common = commands/hdparm.c; common = lib/hexdump.c; enable = pci; + enable = mips_qemu_mips; }; module = { @@ -1197,6 +1198,7 @@ module = { extra_dist = lib/x86_64/setjmp.S; extra_dist = lib/sparc64/setjmp.S; extra_dist = lib/powerpc/setjmp.S; + extra_dist = lib/ia64/setjmp.S; }; module = { @@ -1421,8 +1423,7 @@ module = { x86 = term/ns8250.c; enable = emu; - enable = i386; - enable = x86_64_efi; + enable = x86; emu_condition = COND_GRUB_EMU_USB; }; From eea841440d27babefa8dbc1e1e7810875a06eef7 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Thu, 19 May 2011 15:39:34 +0200 Subject: [PATCH 637/869] fix several bugs --- Makefile.util.def | 2 - grub-core/Makefile.am | 1 + grub-core/commands/ls.c | 22 +++--- grub-core/net/arp.c | 7 +- grub-core/net/drivers/emu/emunet.c | 8 +-- grub-core/net/drivers/ieee1275/ofnet.c | 7 +- grub-core/net/net.c | 96 +++++++++++++------------- grub-core/net/tftp.c | 17 +++-- grub-core/net/udp.c | 5 +- include/grub/net.h | 14 ++-- 10 files changed, 89 insertions(+), 90 deletions(-) diff --git a/Makefile.util.def b/Makefile.util.def index 79ab040dd..058572f06 100644 --- a/Makefile.util.def +++ b/Makefile.util.def @@ -36,8 +36,6 @@ library = { common = grub-core/commands/blocklist.c; common = grub-core/commands/extcmd.c; common = grub-core/commands/ls.c; - common = grub-core/net/net.c; - common = grub-core/net/netbuff.c; common = grub-core/disk/dmraid_nvidia.c; common = grub-core/disk/loopback.c; common = grub-core/disk/lvm.c; diff --git a/grub-core/Makefile.am b/grub-core/Makefile.am index 0fdb4b1db..d5cd25a70 100644 --- a/grub-core/Makefile.am +++ b/grub-core/Makefile.am @@ -167,6 +167,7 @@ endif if COND_emu KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/datetime.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/emu/misc.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/emu/export.h if COND_GRUB_EMU_SDL KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/sdl.h endif diff --git a/grub-core/commands/ls.c b/grub-core/commands/ls.c index 20a75733c..9df830612 100644 --- a/grub-core/commands/ls.c +++ b/grub-core/commands/ls.c @@ -48,9 +48,6 @@ static const char grub_human_sizes[] = {' ', 'K', 'M', 'G', 'T'}; static grub_err_t grub_ls_list_devices (int longlist) { - grub_net_app_level_t proto; - int first = 1; - auto int grub_ls_print_devices (const char *name); int grub_ls_print_devices (const char *name) { @@ -65,15 +62,20 @@ grub_ls_list_devices (int longlist) grub_device_iterate (grub_ls_print_devices); grub_xputs ("\n"); - FOR_NET_APP_LEVEL (proto) +#ifndef GRUB_UTIL { - if (first) - grub_puts_ (N_ ("Network protocols:")); - first = 0; - grub_printf ("%s ", proto->name); + grub_net_app_level_t proto; + int first = 1; + FOR_NET_APP_LEVEL (proto) + { + if (first) + grub_puts_ (N_ ("Network protocols:")); + first = 0; + grub_printf ("%s ", proto->name); + } + grub_xputs ("\n"); } - - grub_xputs ("\n"); +#endif grub_refresh (); diff --git a/grub-core/net/arp.c b/grub-core/net/arp.c index 8778a6e51..1300def25 100644 --- a/grub-core/net/arp.c +++ b/grub-core/net/arp.c @@ -87,11 +87,10 @@ grub_net_arp_resolve(struct grub_net_network_level_interface *inf, grub_memcpy (hw_addr, &entry->ll_address, sizeof (*hw_addr)); return GRUB_ERR_NONE; } - grub_net_pool_cards (200); + grub_net_poll_cards (200); + } - } - - return grub_error (GRUB_ERR_TIMEOUT, "Timeout: could not resolve hardware address."); + return grub_error (GRUB_ERR_TIMEOUT, "timeout: could not resolve hardware address"); } grub_err_t diff --git a/grub-core/net/drivers/emu/emunet.c b/grub-core/net/drivers/emu/emunet.c index 9e4e66dce..d707d8015 100644 --- a/grub-core/net/drivers/emu/emunet.c +++ b/grub-core/net/drivers/emu/emunet.c @@ -26,7 +26,7 @@ send_card_buffer (struct grub_net_card *dev __attribute__ ((unused)), return GRUB_ERR_NONE; } -static grub_size_t +static grub_ssize_t get_card_packet (struct grub_net_card *dev __attribute__ ((unused)), struct grub_net_buff *pack) { @@ -35,10 +35,7 @@ get_card_packet (struct grub_net_card *dev __attribute__ ((unused)), grub_netbuff_clear(pack); actual = read (fd, pack->data, 1500); if (actual < 0) - { - grub_error (GRUB_ERR_IO, "couldn't receive packets"); - return -1; - } + return -1; grub_netbuff_put (pack, actual); return actual; @@ -65,7 +62,6 @@ static struct grub_net_card emucard = GRUB_MOD_INIT(emunet) { struct ifreq ifr; - // char fullname[64]; fd = open ("/dev/net/tun", O_RDWR | O_NONBLOCK); if (fd < 0) return; diff --git a/grub-core/net/drivers/ieee1275/ofnet.c b/grub-core/net/drivers/ieee1275/ofnet.c index cb3882ceb..10d0b979e 100644 --- a/grub-core/net/drivers/ieee1275/ofnet.c +++ b/grub-core/net/drivers/ieee1275/ofnet.c @@ -1,5 +1,4 @@ #include -#include #include #include #include @@ -49,7 +48,7 @@ send_card_buffer (struct grub_net_card *dev, struct grub_net_buff *pack) return GRUB_ERR_NONE; } -static grub_err_t +static grub_ssize_t get_card_packet (struct grub_net_card *dev, struct grub_net_buff *nb) { @@ -65,9 +64,9 @@ get_card_packet (struct grub_net_card *dev, struct grub_net_buff *nb) if (actual) { grub_netbuff_put (nb, actual); - return grub_net_recv_ethernet_packet (nb); + return actual; } - return GRUB_ERR_TIMEOUT; + return -1; } static struct grub_net_card_driver ofdriver = diff --git a/grub-core/net/net.c b/grub-core/net/net.c index be5279c99..a82e73ab0 100644 --- a/grub-core/net/net.c +++ b/grub-core/net/net.c @@ -26,6 +26,7 @@ #include #include #include +#include GRUB_MOD_LICENSE ("GPLv3+"); @@ -587,9 +588,13 @@ grub_net_file_open_real (struct grub_file *file, const char *name) grub_net_network_level_address_t gateway; grub_net_socket_t socket; static int port = 25300; + const char *comma; - err = grub_net_resolve_address (file->device->net->name - + sizeof (file->device->net->protocol->name) + 1, &addr); + comma = grub_strchr (file->device->net->name, ','); + if (!comma) + return grub_error (GRUB_ERR_NET_BAD_ADDRESS, "no separator"); + + err = grub_net_resolve_address (comma + 1, &addr); if (err) return err; @@ -597,19 +602,22 @@ grub_net_file_open_real (struct grub_file *file, const char *name) if (err) return err; - if ((socket = (grub_net_socket_t) grub_malloc (sizeof (*socket))) == NULL) - return GRUB_ERR_OUT_OF_MEMORY; + socket = (grub_net_socket_t) grub_malloc (sizeof (*socket)); + if (socket == NULL) + return grub_errno; socket->inf = inf; socket->out_nla = addr; socket->in_port = port++; socket->status = 0; socket->app = file->device->net->protocol; - socket->packs = NULL; + socket->packs.first = NULL; + socket->packs.last = NULL; file->device->net->socket = socket; grub_net_socket_register (socket); - if ((err = file->device->net->protocol->open (file,name))) + err = file->device->net->protocol->open (file,name); + if (err) goto fail; file->not_easily_seekable = 1; @@ -625,10 +633,10 @@ static grub_err_t grub_net_file_close_real (grub_file_t file) { grub_net_socket_t sock = file->device->net->socket; - while (sock->packs->first) + while (sock->packs.first) { - grub_netbuff_free (sock->packs->first->nb); - grub_net_remove_packet (sock->packs->first); + grub_netbuff_free (sock->packs.first->nb); + grub_net_remove_packet (sock->packs.first); } grub_net_socket_unregister (sock); grub_free (sock); @@ -636,39 +644,44 @@ grub_net_file_close_real (grub_file_t file) } -static grub_err_t +static void receive_packets (struct grub_net_card *card) { /* Maybe should be better have a fixed number of packets for each card and just mark them as used and not used. */ struct grub_net_buff *nb; - grub_err_t err; + grub_ssize_t actual; nb = grub_netbuff_alloc (1500); if (!nb) - return grub_errno; + { + grub_print_error (); + return; + } - if ((err = card->driver->recv (card, nb)) != GRUB_ERR_NONE) + actual = card->driver->recv (card, nb); + if (actual < 0) grub_netbuff_free (nb); - return err; + else + grub_net_recv_ethernet_packet (nb); + grub_print_error (); } void -grub_net_pool_cards (unsigned time) +grub_net_poll_cards (unsigned time) { struct grub_net_card *card; grub_uint64_t start_time; FOR_NET_CARDS (card) { start_time = grub_get_time_ms (); - while( (grub_get_time_ms () - start_time) < time) - if( receive_packets (card) != GRUB_ERR_NONE) - break; + while ((grub_get_time_ms () - start_time) < time) + receive_packets (card); } } +/* Read from the packets list*/ static grub_ssize_t -process_packets (grub_file_t file, void *buf, grub_size_t len, - void *NESTED_FUNC_ATTR (hook) (void *dest, const void *src, grub_size_t n)) +grub_net_read_real (grub_file_t file, void *buf, grub_size_t len) { grub_net_socket_t sock = file->device->net->socket; struct grub_net_buff *nb; @@ -677,19 +690,24 @@ process_packets (grub_file_t file, void *buf, grub_size_t len, int try = 0; while (try <= 3) { - while (sock->packs->first) + while (sock->packs.first) { try = 0; - nb = sock->packs->first->nb; - amount = (grub_size_t)(len <= (grub_size_t) (nb->tail - nb->data))? len :(grub_size_t)(nb->tail - nb->data); + nb = sock->packs.first->nb; + amount = nb->tail - nb->data; + if (amount > len) + amount = len; len -= amount; total += amount; - hook (ptr, nb->data, amount); - ptr += amount; + if (buf) + { + grub_memcpy (ptr, nb->data, amount); + ptr += amount; + } if (amount == (grub_size_t) (nb->tail - nb->data)) { grub_netbuff_free (nb); - grub_net_remove_packet (sock->packs->first); + grub_net_remove_packet (sock->packs.first); } else nb->data += amount; @@ -700,7 +718,7 @@ process_packets (grub_file_t file, void *buf, grub_size_t len, if (sock->status == 1) { try++; - grub_net_pool_cards (200); + grub_net_poll_cards (200); } else return total; @@ -708,20 +726,6 @@ process_packets (grub_file_t file, void *buf, grub_size_t len, return total; } - -/* Read from the packets list*/ -static grub_ssize_t -grub_net_read_real (grub_file_t file, void *buf, grub_size_t len ) -{ - auto void *NESTED_FUNC_ATTR memcpy_hook (void *dest, const void *src, grub_size_t n); - void *NESTED_FUNC_ATTR memcpy_hook (void *dest __attribute__ ((unused)), const void *src __attribute__ ((unused)), - grub_size_t n __attribute__ ((unused))) - { - return grub_memcpy (dest, src, n); - } - return process_packets (file, buf, len, memcpy_hook); -} - /* Read from the packets list*/ static grub_err_t grub_net_seek_real (struct grub_file *file, grub_off_t offset) @@ -736,17 +740,11 @@ grub_net_seek_real (struct grub_file *file, grub_off_t offset) /* We cant seek backwards past the current packet. */ if (file->offset > offset) { - nb = sock->packs->first->nb; + nb = sock->packs.first->nb; return grub_netbuff_push (nb, file->offset - offset); } - auto void *NESTED_FUNC_ATTR dummy (void *dest, const void *src, grub_size_t n); - void *NESTED_FUNC_ATTR dummy (void *dest __attribute__ ((unused)), const void *src __attribute__ ((unused)), - grub_size_t n __attribute__ ((unused))) - { - return NULL; - } - process_packets (file, NULL, len, dummy); + grub_net_read_real (file, NULL, len); return GRUB_ERR_NONE; } diff --git a/grub-core/net/tftp.c b/grub-core/net/tftp.c index 278f6ed14..1daf11bc7 100644 --- a/grub-core/net/tftp.c +++ b/grub-core/net/tftp.c @@ -21,8 +21,12 @@ tftp_open (struct grub_file *file, const char *filename) int hdrlen; char open_data[1500]; struct grub_net_buff nb; - tftp_data_t data = grub_malloc (sizeof *data); + tftp_data_t data; grub_err_t err; + + data = grub_malloc (sizeof *data); + if (!data) + return grub_errno; file->device->net->socket->data = (void *) data; nb.head = open_data; @@ -74,7 +78,7 @@ tftp_open (struct grub_file *file, const char *filename) /* Receive OACK packet. */ for ( i = 0; i < 3; i++) { - grub_net_pool_cards (100); + grub_net_poll_cards (100); if (grub_errno) return grub_errno; if (file->device->net->socket->status != 0) @@ -110,10 +114,13 @@ tftp_receive (grub_net_socket_t sock, struct grub_net_buff *nb) switch (grub_be_to_cpu16 (tftph->opcode)) { case TFTP_OACK: - for (ptr = nb->data; ptr < nb->tail; ) + for (ptr = nb->data + sizeof (tftph->opcode); ptr < nb->tail; ) { if (grub_memcmp (ptr, "tsize\0", sizeof ("tsize\0") - 1) == 0) - data->file_size = grub_strtoul (ptr + sizeof ("tsize\0") - 1, 0, 0); + { + data->file_size = grub_strtoul (ptr + sizeof ("tsize\0") - 1, + 0, 0); + } while (ptr < nb->tail && *ptr) ptr++; ptr++; @@ -150,7 +157,7 @@ tftp_receive (grub_net_socket_t sock, struct grub_net_buff *nb) tftph = (struct tftphdr *) nb_ack.data; tftph->opcode = grub_cpu_to_be16 (TFTP_ACK); - tftph->u.ack.block = data->block; + tftph->u.ack.block = grub_cpu_to_be16 (data->block); err = grub_net_send_udp_packet (sock, &nb_ack); return err; diff --git a/grub-core/net/udp.c b/grub-core/net/udp.c index 16b2011ff..4477b3c2b 100644 --- a/grub-core/net/udp.c +++ b/grub-core/net/udp.c @@ -36,15 +36,14 @@ grub_net_recv_udp_packet (struct grub_net_buff *nb) if (grub_be_to_cpu16 (udph->dst) == sock->in_port) { if (sock->status == 0) - sock->out_port = udph->src; + sock->out_port = grub_be_to_cpu16 (udph->src); - /* App protocol remove its own reader. */ sock->app->read (sock,nb); /* If there is data, puts packet in socket list */ if ((nb->tail - nb->data) > 0) - grub_net_put_packet (sock->packs, nb); + grub_net_put_packet (&sock->packs, nb); else grub_netbuff_free (nb); return GRUB_ERR_NONE; diff --git a/include/grub/net.h b/include/grub/net.h index cb6db06d8..1b113972b 100644 --- a/include/grub/net.h +++ b/include/grub/net.h @@ -63,7 +63,7 @@ struct grub_net_card_driver grub_err_t (*init) (struct grub_net_card *dev); grub_err_t (*fini) (struct grub_net_card *dev); grub_err_t (*send) (struct grub_net_card *dev, struct grub_net_buff *buf); - grub_size_t (*recv) (struct grub_net_card *dev, struct grub_net_buff *buf); + grub_ssize_t (*recv) (struct grub_net_card *dev, struct grub_net_buff *buf); }; extern struct grub_net_card_driver *grub_net_card_drivers; @@ -207,24 +207,24 @@ struct grub_net_socket grub_net_app_level_t app; grub_net_network_level_address_t out_nla; struct grub_net_network_level_interface *inf; - grub_net_packets_t *packs; + grub_net_packets_t packs; void *data; }; extern struct grub_net_socket *grub_net_sockets; static inline void -grub_net_socket_register (grub_net_socket_t socket) +grub_net_socket_register (grub_net_socket_t sock) { grub_list_push (GRUB_AS_LIST_P (&grub_net_sockets), - GRUB_AS_LIST (socket)); + GRUB_AS_LIST (sock)); } static inline void -grub_net_socket_unregister (grub_net_socket_t socket) +grub_net_socket_unregister (grub_net_socket_t sock) { grub_list_remove (GRUB_AS_LIST_P (&grub_net_sockets), - GRUB_AS_LIST (socket)); + GRUB_AS_LIST (sock)); } #define FOR_NET_SOCKETS(var) for (var = grub_net_sockets; var; var = var->next) @@ -432,7 +432,7 @@ grub_net_send_ip_packet (struct grub_net_network_level_interface *inf, #define FOR_NET_NL_PACKETS(inf, var) FOR_PACKETS(inf->nl_pending, var) void -grub_net_pool_cards (unsigned time); +grub_net_poll_cards (unsigned time); extern grub_err_t (*EXPORT_VAR (grub_file_net_close)) (grub_file_t file); #endif /* ! GRUB_NET_HEADER */ From f35fa3a664474529be91252380eab589838add6d Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Fri, 20 May 2011 11:21:36 +0100 Subject: [PATCH 638/869] * util/grub-mkconfig.in: Export GRUB_CMDLINE_LINUX_XEN_REPLACE and GRUB_CMDLINE_LINUX_XEN_REPLACE_DEFAULT. Reported by: Pawel Tecza. --- ChangeLog | 6 ++++++ util/grub-mkconfig.in | 2 ++ 2 files changed, 8 insertions(+) diff --git a/ChangeLog b/ChangeLog index 1a68f911c..c94b7482d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2011-05-20 Colin Watson + + * util/grub-mkconfig.in: Export GRUB_CMDLINE_LINUX_XEN_REPLACE and + GRUB_CMDLINE_LINUX_XEN_REPLACE_DEFAULT. + Reported by: Pawel Tecza. + 2011-05-19 Vladimir Serbinenko * grub-core/Makefile.core.def (lsacpi): Fix ia64 mismerge. diff --git a/util/grub-mkconfig.in b/util/grub-mkconfig.in index afc66f886..4d627c057 100644 --- a/util/grub-mkconfig.in +++ b/util/grub-mkconfig.in @@ -239,6 +239,8 @@ export GRUB_DEFAULT \ GRUB_CMDLINE_LINUX_DEFAULT \ GRUB_CMDLINE_XEN \ GRUB_CMDLINE_XEN_DEFAULT \ + GRUB_CMDLINE_LINUX_XEN_REPLACE \ + GRUB_CMDLINE_LINUX_XEN_REPLACE_DEFAULT \ GRUB_CMDLINE_NETBSD \ GRUB_CMDLINE_NETBSD_DEFAULT \ GRUB_TERMINAL_INPUT \ From f767c929f2c430bb574a358e0ba8375d49c6ee64 Mon Sep 17 00:00:00 2001 From: Vladimir Serbinenko Date: Sat, 21 May 2011 07:03:55 +0200 Subject: [PATCH 639/869] Don't stat devices unless we have to. * grub-core/kern/emu/getroot.c (grub_find_device): Recognize dir == /dev/mapper. (grub_guess_root_device): Use already known os_dev if possible. * grub-core/kern/emu/hostdisk.c (convert_system_partition_to_system_disk): Scan only in /dev/mapper if device is known to be a dm one. Also-By: Colin Watson --- ChangeLog | 12 ++++++++++++ grub-core/kern/emu/getroot.c | 33 ++++++++++++++++++++------------- grub-core/kern/emu/hostdisk.c | 3 ++- 3 files changed, 34 insertions(+), 14 deletions(-) diff --git a/ChangeLog b/ChangeLog index c94b7482d..a01d57576 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2011-05-21 Colin Watson +2011-05-21 Vladimir Serbinenko + + Don't stat devices unless we have to. + + * grub-core/kern/emu/getroot.c (grub_find_device): Recognize + dir == /dev/mapper. + (grub_guess_root_device): Use already known os_dev if possible. + * grub-core/kern/emu/hostdisk.c + (convert_system_partition_to_system_disk): Scan only in /dev/mapper + if device is known to be a dm one. + 2011-05-20 Colin Watson * util/grub-mkconfig.in: Export GRUB_CMDLINE_LINUX_XEN_REPLACE and diff --git a/grub-core/kern/emu/getroot.c b/grub-core/kern/emu/getroot.c index b1b4f188c..6e49cc31b 100644 --- a/grub-core/kern/emu/getroot.c +++ b/grub-core/kern/emu/getroot.c @@ -358,7 +358,7 @@ grub_find_device (const char *dir, dev_t dev) if (S_ISLNK (st.st_mode)) { #ifdef __linux__ - if (strcmp (dir, "mapper") == 0) { + if (strcmp (dir, "mapper") == 0 || strcmp (dir, "/dev/mapper") == 0) { /* Follow symbolic links under /dev/mapper/; the canonical name may be something like /dev/dm-0, but the names under /dev/mapper/ are more human-readable and so we prefer them if @@ -609,20 +609,27 @@ grub_guess_root_device (const char *dir) if (os_dev) { - if (stat (os_dev, &st) >= 0) - dev = st.st_rdev; - else - grub_util_error ("cannot stat `%s'", os_dev); - free (os_dev); - } - else - { - if (stat (dir, &st) >= 0) - dev = st.st_dev; - else - grub_util_error ("cannot stat `%s'", dir); + char *tmp = os_dev; + os_dev = canonicalize_file_name (os_dev); + free (tmp); } + if (os_dev) + { + if (strncmp (os_dev, "/dev/dm-", sizeof ("/dev/dm-") - 1) != 0) + return os_dev; + if (stat (os_dev, &st) < 0) + grub_util_error ("cannot stat `%s'", os_dev); + free (os_dev); + dev = st.st_rdev; + return grub_find_device ("/dev/mapper", dev); + } + + if (stat (dir, &st) < 0) + grub_util_error ("cannot stat `%s'", dir); + + dev = st.st_dev; + #ifdef __CYGWIN__ /* Cygwin specific function. */ os_dev = grub_find_device (dir, dev); diff --git a/grub-core/kern/emu/hostdisk.c b/grub-core/kern/emu/hostdisk.c index d3db7e6be..d633059c3 100644 --- a/grub-core/kern/emu/hostdisk.c +++ b/grub-core/kern/emu/hostdisk.c @@ -1408,7 +1408,8 @@ convert_system_partition_to_system_disk (const char *os_dev, struct stat *st) if (tree) dm_tree_free (tree); free (path); - char *ret = grub_find_device (NULL, (major << 8) | minor); + char *ret = grub_find_device ("/dev/mapper", + (major << 8) | minor); return ret; } From 245f4aba489e3a21129253c28dc138571738a5e4 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 21 May 2011 07:05:46 +0200 Subject: [PATCH 640/869] * grub-core/disk/arc/arcdisk.c (reopen): Close old handle before opening new one. --- ChangeLog | 5 +++++ grub-core/disk/arc/arcdisk.c | 12 ++++++------ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index a01d57576..198750f6a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-05-21 Vladimir Serbinenko + + * grub-core/disk/arc/arcdisk.c (reopen): Close old handle before + opening new one. + 2011-05-21 Colin Watson 2011-05-21 Vladimir Serbinenko diff --git a/grub-core/disk/arc/arcdisk.c b/grub-core/disk/arc/arcdisk.c index e8416634a..7dff30931 100644 --- a/grub-core/disk/arc/arcdisk.c +++ b/grub-core/disk/arc/arcdisk.c @@ -1,7 +1,7 @@ /* ofdisk.c - Open Firmware disk access. */ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2004,2006,2007,2008,2009 Free Software Foundation, Inc. + * Copyright (C) 2004,2006,2007,2008,2009,2011 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -105,11 +105,6 @@ reopen (const char *name) grub_dprintf ("arcdisk", "using already opened %s\n", name); return GRUB_ERR_NONE; } - if (GRUB_ARC_FIRMWARE_VECTOR->open (name, 0, &handle)) - { - grub_dprintf ("arcdisk", "couldn't open %s\n", name); - return grub_error (GRUB_ERR_IO, "couldn't open %s", name); - } if (last_path) { GRUB_ARC_FIRMWARE_VECTOR->close (last_handle); @@ -117,6 +112,11 @@ reopen (const char *name) last_path = NULL; last_handle = 0; } + if (GRUB_ARC_FIRMWARE_VECTOR->open (name, 0, &handle)) + { + grub_dprintf ("arcdisk", "couldn't open %s\n", name); + return grub_error (GRUB_ERR_IO, "couldn't open %s", name); + } last_path = grub_strdup (name); if (!last_path) return grub_errno; From f42313bdb07e5a9bb5f6ca92a37f342aae5a1bfa Mon Sep 17 00:00:00 2001 From: Manoel Rebelo Abranches Date: Wed, 25 May 2011 11:10:48 -0300 Subject: [PATCH 641/869] Remove unused structs and functions. --- include/grub/disk.h | 20 +------------------- include/grub/ieee1275/ofnet.h | 3 --- include/grub/net/ieee1275/interface.h | 10 ---------- include/grub/net/mem.h | 9 --------- 4 files changed, 1 insertion(+), 41 deletions(-) delete mode 100644 include/grub/net/ieee1275/interface.h delete mode 100644 include/grub/net/mem.h diff --git a/include/grub/disk.h b/include/grub/disk.h index 101303205..66db1149a 100644 --- a/include/grub/disk.h +++ b/include/grub/disk.h @@ -42,8 +42,7 @@ enum grub_disk_dev_id GRUB_DISK_DEVICE_PXE_ID, GRUB_DISK_DEVICE_SCSI_ID, GRUB_DISK_DEVICE_FILE_ID, - GRUB_DISK_DEVICE_LUKS_ID, - GRUB_DISK_DEVICE_OFNET_ID + GRUB_DISK_DEVICE_LUKS_ID }; struct grub_disk; @@ -117,23 +116,6 @@ struct grub_disk }; typedef struct grub_disk *grub_disk_t; -/* Net Disk */ -enum grub_netdisk_protocol -{ - GRUB_NETDISK_PROTOCOL_TFTP -}; -typedef enum grub_netdisk_protocol grub_netdisk_protocol_t; - -struct grub_netdisk_data -{ - grub_netdisk_protocol_t protocol; - grub_uint32_t server_ip; - grub_uint32_t port; - char *username; - char *password; -}; -typedef struct grub_netdisk_data *grub_netdisk_data_t; - #ifdef GRUB_UTIL struct grub_disk_memberlist { diff --git a/include/grub/ieee1275/ofnet.h b/include/grub/ieee1275/ofnet.h index 9a0ae29e3..c7284df38 100644 --- a/include/grub/ieee1275/ofnet.h +++ b/include/grub/ieee1275/ofnet.h @@ -23,9 +23,6 @@ #include #include -void grub_ofnet_init(void); -void grub_ofnet_fini(void); - struct grub_ofnet { /* The net name. */ diff --git a/include/grub/net/ieee1275/interface.h b/include/grub/net/ieee1275/interface.h deleted file mode 100644 index c369e35a6..000000000 --- a/include/grub/net/ieee1275/interface.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef GRUB_IEEE1275_INTERFACE_HEADER -#define GRUB_IEEE1275_INTERFACE_HEADER 1 - -#include -#include -#include -#include - -grub_bootp_t bootp_pckt; -#endif diff --git a/include/grub/net/mem.h b/include/grub/net/mem.h deleted file mode 100644 index bbdac512b..000000000 --- a/include/grub/net/mem.h +++ /dev/null @@ -1,9 +0,0 @@ -#ifndef GRUB_NETMM_H -#define GRUB_NETMM_H 1 - -#include -#include - -void *EXPORT_FUNC(grub_net_malloc) (grub_size_t size); - -#endif /* ! GRUB_MM_H */ From 7dd64f12368b8ee35eb32b52b0f6e69068053ab2 Mon Sep 17 00:00:00 2001 From: "Manoel R. Abranches" Date: Fri, 27 May 2011 00:22:35 -0300 Subject: [PATCH 642/869] Use a net fs struct to handle open, reand and close in file. --- grub-core/kern/file.c | 25 ++--------------------- grub-core/kern/fs.c | 4 ++-- grub-core/kern/ieee1275/openfw.c | 1 - grub-core/net/net.c | 34 +++++++++++++++++++++----------- include/grub/net.h | 4 +--- 5 files changed, 27 insertions(+), 41 deletions(-) diff --git a/grub-core/kern/file.c b/grub-core/kern/file.c index 2b3e9d689..749e72dfc 100644 --- a/grub-core/kern/file.c +++ b/grub-core/kern/file.c @@ -25,9 +25,6 @@ #include #include -grub_ssize_t (*grub_file_net_read) (grub_file_t file, void *buf, grub_size_t len) = NULL; -grub_err_t (*grub_file_net_open) (struct grub_file *file, const char *name) = NULL; -grub_err_t (*grub_file_net_close) (grub_file_t file) = NULL; grub_err_t (*grub_file_net_seek) (struct grub_file *file, grub_off_t offset) = NULL; grub_file_filter_t grub_file_filters_all[GRUB_FILE_FILTER_MAX]; @@ -91,13 +88,6 @@ grub_file_open (const char *name) file->device = device; - if (device->net && grub_file_net_open) - { - if (grub_file_net_open (file, file_name)) - goto fail; - return file; - } - if (device->disk && file_name[0] != '/') /* This is a block list. */ file->fs = &grub_fs_blocklist; @@ -143,7 +133,7 @@ grub_file_open (const char *name) grub_ssize_t grub_file_read (grub_file_t file, void *buf, grub_size_t len) { - grub_ssize_t res = 0; + grub_ssize_t res; if (file->offset > file->size) { @@ -161,12 +151,7 @@ grub_file_read (grub_file_t file, void *buf, grub_size_t len) if (len == 0) return 0; - if (file->device->disk) - res = (file->fs->read) (file, buf, len); - else - if (grub_file_net_read && file->device->net) - res = grub_file_net_read (file, buf, len); - + res = (file->fs->read) (file, buf, len); if (res > 0) file->offset += res; @@ -176,12 +161,6 @@ grub_file_read (grub_file_t file, void *buf, grub_size_t len) grub_err_t grub_file_close (grub_file_t file) { - if (file->device->net) - { - grub_file_net_close (file); - return grub_errno; - } - if (file->fs->close) (file->fs->close) (file); diff --git a/grub-core/kern/fs.c b/grub-core/kern/fs.c index 7166648be..14d389e07 100644 --- a/grub-core/kern/fs.c +++ b/grub-core/kern/fs.c @@ -94,8 +94,8 @@ grub_fs_probe (grub_device_t device) count--; } } - else if (device->net) - return NULL; + else if (device->net && device->net->fs) + return device->net->fs; grub_error (GRUB_ERR_UNKNOWN_FS, "unknown filesystem"); return 0; diff --git a/grub-core/kern/ieee1275/openfw.c b/grub-core/kern/ieee1275/openfw.c index 3473fe362..db4bec90a 100644 --- a/grub-core/kern/ieee1275/openfw.c +++ b/grub-core/kern/ieee1275/openfw.c @@ -23,7 +23,6 @@ #include #include #include -#include #include #include diff --git a/grub-core/net/net.c b/grub-core/net/net.c index a82e73ab0..1232b3c74 100644 --- a/grub-core/net/net.c +++ b/grub-core/net/net.c @@ -49,6 +49,7 @@ struct grub_net_network_level_interface *grub_net_network_level_interfaces = NUL struct grub_net_card *grub_net_cards = NULL; struct grub_net_card_driver *grub_net_card_drivers = NULL; struct grub_net_network_level_protocol *grub_net_network_level_protocols = NULL; +static struct grub_fs grub_net_fs; static inline void grub_net_network_level_interface_unregister (struct grub_net_network_level_interface *inter) @@ -571,6 +572,7 @@ grub_net_open_real (const char *name) grub_free (ret); return NULL; } + ret->fs = &grub_net_fs; return ret; } } @@ -580,7 +582,7 @@ grub_net_open_real (const char *name) } static grub_err_t -grub_net_file_open_real (struct grub_file *file, const char *name) +grub_net_fs_open (struct grub_file *file, const char *name) { grub_err_t err; grub_net_network_level_address_t addr; @@ -620,7 +622,7 @@ grub_net_file_open_real (struct grub_file *file, const char *name) if (err) goto fail; file->not_easily_seekable = 1; - + return GRUB_ERR_NONE; fail: grub_net_socket_unregister (socket); @@ -630,7 +632,7 @@ fail: } static grub_err_t -grub_net_file_close_real (grub_file_t file) +grub_net_fs_close (grub_file_t file) { grub_net_socket_t sock = file->device->net->socket; while (sock->packs.first) @@ -681,11 +683,11 @@ grub_net_poll_cards (unsigned time) /* Read from the packets list*/ static grub_ssize_t -grub_net_read_real (grub_file_t file, void *buf, grub_size_t len) +grub_net_fs_read (grub_file_t file, char *buf, grub_size_t len) { grub_net_socket_t sock = file->device->net->socket; struct grub_net_buff *nb; - char *ptr = (char *) buf; + char *ptr = buf; grub_size_t amount, total = 0; int try = 0; while (try <= 3) @@ -744,7 +746,7 @@ grub_net_seek_real (struct grub_file *file, grub_off_t offset) return grub_netbuff_push (nb, file->offset - offset); } - grub_net_read_real (file, NULL, len); + grub_net_fs_read (file, NULL, len); return GRUB_ERR_NONE; } @@ -1009,6 +1011,17 @@ grub_cmd_dhcpopt (struct grub_command *cmd __attribute__ ((unused)), "unrecognised format specification %s", args[3]); } +static struct grub_fs grub_net_fs = + { + .name = "netfs", + .dir = NULL, + .open = grub_net_fs_open, + .read = grub_net_fs_read, + .close = grub_net_fs_close, + .label = NULL, + .uuid = NULL, + .mtime = NULL, + }; static grub_command_t cmd_addaddr, cmd_deladdr, cmd_addroute, cmd_delroute; static grub_command_t cmd_lsroutes, cmd_lscards, cmd_getdhcp; @@ -1034,10 +1047,8 @@ GRUB_MOD_INIT(net) N_("VAR INTERFACE NUMBER DESCRIPTION"), N_("retrieve DHCP option and save it into VAR. If VAR is - then print the value.")); + grub_fs_register (&grub_net_fs); grub_net_open = grub_net_open_real; - grub_file_net_open = grub_net_file_open_real; - grub_file_net_close = grub_net_file_close_real; - grub_file_net_read = grub_net_read_real; grub_file_net_seek = grub_net_seek_real; } @@ -1050,8 +1061,7 @@ GRUB_MOD_FINI(net) grub_unregister_command (cmd_lsroutes); grub_unregister_command (cmd_lscards); grub_unregister_command (cmd_getdhcp); + grub_fs_unregister (&grub_net_fs); grub_net_open = NULL; - grub_file_net_read = NULL; - grub_file_net_open = NULL; - grub_file_net_close = NULL; + grub_file_net_seek = NULL; } diff --git a/include/grub/net.h b/include/grub/net.h index 1b113972b..f9745acec 100644 --- a/include/grub/net.h +++ b/include/grub/net.h @@ -234,11 +234,10 @@ typedef struct grub_net char *name; grub_net_app_level_t protocol; grub_net_socket_t socket; + grub_fs_t fs; } *grub_net_t; extern grub_net_t (*EXPORT_VAR (grub_net_open)) (const char *name); -extern grub_ssize_t (*EXPORT_VAR (grub_file_net_read)) (grub_file_t file, void *buf, grub_size_t len); -extern grub_err_t (*EXPORT_VAR (grub_file_net_open)) (struct grub_file *file, const char *name); extern grub_err_t (*EXPORT_VAR (grub_file_net_seek)) (struct grub_file *file, grub_off_t offset); struct grub_net_network_level_interface @@ -434,5 +433,4 @@ grub_net_send_ip_packet (struct grub_net_network_level_interface *inf, void grub_net_poll_cards (unsigned time); -extern grub_err_t (*EXPORT_VAR (grub_file_net_close)) (grub_file_t file); #endif /* ! GRUB_NET_HEADER */ From c64db050f7f8669fa0b7e27811c869febbeaa848 Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Fri, 27 May 2011 13:52:21 +0100 Subject: [PATCH 643/869] * grub-core/kern/emu/hostdisk.c (linux_find_partition): Give up after ten consecutive open failures. Scanning all the way up to 10000 is excessive and can cause serious performance problems in some configurations. Fixes Ubuntu bug #787461. --- ChangeLog | 8 ++++++++ grub-core/kern/emu/hostdisk.c | 9 ++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 198750f6a..351700803 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2011-05-27 Colin Watson + + * grub-core/kern/emu/hostdisk.c (linux_find_partition): Give up + after ten consecutive open failures. Scanning all the way up to + 10000 is excessive and can cause serious performance problems in + some configurations. + Fixes Ubuntu bug #787461. + 2011-05-21 Vladimir Serbinenko * grub-core/disk/arc/arcdisk.c (reopen): Close old handle before diff --git a/grub-core/kern/emu/hostdisk.c b/grub-core/kern/emu/hostdisk.c index d633059c3..e404c4fea 100644 --- a/grub-core/kern/emu/hostdisk.c +++ b/grub-core/kern/emu/hostdisk.c @@ -564,6 +564,7 @@ linux_find_partition (char *dev, grub_disk_addr_t sector) int i; char real_dev[PATH_MAX]; struct linux_partition_cache *cache; + int missing = 0; strcpy(real_dev, dev); @@ -602,7 +603,13 @@ linux_find_partition (char *dev, grub_disk_addr_t sector) fd = open (real_dev, O_RDONLY); if (fd == -1) - continue; + { + if (missing++ < 10) + continue; + else + return 0; + } + missing = 0; close (fd); start = find_partition_start (real_dev); From 6b4e643081999c9fe388ad5bd8ad96812777fc76 Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Fri, 27 May 2011 13:57:22 +0100 Subject: [PATCH 644/869] * grub-core/kern/emu/hostdisk.c (linux_find_partition): Handle partitions under /dev/disk/by-id/. --- ChangeLog | 5 +++++ grub-core/kern/emu/hostdisk.c | 6 ++++++ 2 files changed, 11 insertions(+) diff --git a/ChangeLog b/ChangeLog index 351700803..b9abcd07f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-05-27 Colin Watson + + * grub-core/kern/emu/hostdisk.c (linux_find_partition): Handle + partitions under /dev/disk/by-id/. + 2011-05-27 Colin Watson * grub-core/kern/emu/hostdisk.c (linux_find_partition): Give up diff --git a/grub-core/kern/emu/hostdisk.c b/grub-core/kern/emu/hostdisk.c index e404c4fea..bb528d9bc 100644 --- a/grub-core/kern/emu/hostdisk.c +++ b/grub-core/kern/emu/hostdisk.c @@ -573,6 +573,12 @@ linux_find_partition (char *dev, grub_disk_addr_t sector) p = real_dev + len - 4; format = "part%d"; } + else if (strncmp (real_dev, "/dev/disk/by-id/", + sizeof ("/dev/disk/by-id/") - 1) == 0) + { + p = real_dev + len; + format = "-part%d"; + } else if (real_dev[len - 1] >= '0' && real_dev[len - 1] <= '9') { p = real_dev + len; From 351c7c8a155d1c3ace2cbefb9682c5b862082d98 Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Sun, 29 May 2011 22:15:08 +0100 Subject: [PATCH 645/869] * docs/grub.texi (Obtaining and Building GRUB): Substitute `ftp.gnu.org' for `alpha.gnu.org'. --- ChangeLog | 5 +++++ docs/grub.texi | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index b9abcd07f..fca980c1b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-05-29 Colin Watson + + * docs/grub.texi (Obtaining and Building GRUB): Substitute + `ftp.gnu.org' for `alpha.gnu.org'. + 2011-05-27 Colin Watson * grub-core/kern/emu/hostdisk.c (linux_find_partition): Handle diff --git a/docs/grub.texi b/docs/grub.texi index 818417d41..45c93d69c 100644 --- a/docs/grub.texi +++ b/docs/grub.texi @@ -4330,11 +4330,11 @@ how to get the latest version. @end quotation GRUB is available from the GNU alpha archive site -@uref{ftp://alpha.gnu.org/gnu/grub} or any of its mirrors. The file +@uref{ftp://ftp.gnu.org/gnu/grub} or any of its mirrors. The file will be named grub-version.tar.gz. The current version is @value{VERSION}, so the file you should grab is: -@uref{ftp://alpha.gnu.org/gnu/grub/grub-@value{VERSION}.tar.gz} +@uref{ftp://ftp.gnu.org/gnu/grub/grub-@value{VERSION}.tar.gz} To unbundle GRUB use the instruction: From 4f24b12e1fb7ad56b59dee6f545701a2864512a2 Mon Sep 17 00:00:00 2001 From: "Manoel R. Abranches" Date: Thu, 2 Jun 2011 15:13:33 -0300 Subject: [PATCH 646/869] Fix compilation in x86 --- grub-core/net/i386/pc/pxe.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/grub-core/net/i386/pc/pxe.c b/grub-core/net/i386/pc/pxe.c index 8e7f75ed8..27c4af17f 100644 --- a/grub-core/net/i386/pc/pxe.c +++ b/grub-core/net/i386/pc/pxe.c @@ -193,7 +193,7 @@ grub_pxefs_open (struct grub_file *file, const char *name) } file->data = data; - file->not_easly_seekable = 1; + file->not_easily_seekable = 1; grub_memcpy (file_int, file, sizeof (struct grub_file)); curr_file = file_int; @@ -215,7 +215,8 @@ grub_pxefs_read (grub_file_t file, char *buf, grub_size_t len) { struct grub_pxenv_tftp_read c; struct grub_pxe_data *data; - grub_uint32_t pn, r; + grub_uint32_t pn; + grub_uint64_t r; data = file->data; @@ -292,7 +293,7 @@ grub_pxefs_label (grub_device_t device __attribute ((unused)), return GRUB_ERR_NONE; } -static struct grub_net_app_protocol grub_pxefs_fs = +static struct grub_fs grub_pxefs_fs = { .name = "pxe", .dir = grub_pxefs_dir, @@ -303,7 +304,7 @@ static struct grub_net_app_protocol grub_pxefs_fs = .next = 0 }; -static grub_size_t +static grub_ssize_t grub_pxe_recv (struct grub_net_card *dev __attribute__ ((unused)), struct grub_net_buff *buf __attribute__ ((unused))) { @@ -334,7 +335,7 @@ grub_pxe_unload (void) { if (grub_pxe_pxenv) { - grub_net_app_level_unregister (&grub_pxefs_fs); + grub_fs_unregister (&grub_pxefs_fs); grub_net_card_unregister (&grub_pxe_card); grub_pxe_pxenv = 0; } @@ -466,7 +467,7 @@ GRUB_MOD_INIT(pxe) ? bp->hw_len : sizeof (grub_pxe_card.default_address.mac)); grub_pxe_card.default_address.type = GRUB_NET_LINK_LEVEL_PROTOCOL_ETHERNET; - grub_net_app_level_register (&grub_pxefs_fs); + grub_fs_register (&grub_pxefs_fs); grub_net_card_register (&grub_pxe_card); grub_net_configure_by_dhcp_ack ("pxe", &grub_pxe_card, GRUB_NET_INTERFACE_PERMANENT From 423a1849ef2d4791e03ef6cd6cd94d5bf75144af Mon Sep 17 00:00:00 2001 From: Manoel Rebelo Abranches Date: Tue, 7 Jun 2011 11:47:31 -0300 Subject: [PATCH 647/869] Write ChangeLog. --- ChangeLog | 26 ++++++++++++++++++++++++++ grub-core/net/tftp.c | 6 +++--- grub-core/net/udp.c | 3 +-- 3 files changed, 30 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 198750f6a..122ea029d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,29 @@ +2011-06-07 Vladimir Serbinenko +2011-06-07 Manoel Rebelo Abranches + + Network infrastructure. + The ARP protocol was made by Paulo Pinatti + + * include/grub/net/arp.h: New file. + * include/grub/net/ethernet.h: New file. + * include/grub/net/ip.h: New file. + * include/grub/net/netbuff.h: New file. + * include/grub/net/tftp.h: New file. + * include/grub/net/udp.h: New file. + * include/grub/net.h: New file. + * grub-core/net/arp.c: New file. + * grub-core/net/ethernet.c: New file. + * grub-core/net/ip.c: New file. + * grub-core/net/netbuff.c: New file. + * grub-core/net/net.c: New file. + * grub-core/net/drivers/emu/emunet.c: New file. + * grub-core/net/drivers/ieee1275/ofnet.c: New file. + * grub-core/kern/device.c (grub_net_open) : New function. + (grub_device_open) : Handle Network device. + * grub-core/kern/file.c (grub_file_net_seek) : New function. + (grub_file_net_seek): Seek in network device. + + 2011-05-21 Vladimir Serbinenko * grub-core/disk/arc/arcdisk.c (reopen): Close old handle before diff --git a/grub-core/net/tftp.c b/grub-core/net/tftp.c index 1daf11bc7..010a4a4bd 100644 --- a/grub-core/net/tftp.c +++ b/grub-core/net/tftp.c @@ -84,9 +84,9 @@ tftp_open (struct grub_file *file, const char *filename) if (file->device->net->socket->status != 0) break; /* Retry. */ - //err = grub_net_send_udp_packet (file->device->net->socket, &nb); - // if (err) - // return err; + /*err = grub_net_send_udp_packet (file->device->net->socket, &nb); + if (err) + return err;*/ } if (file->device->net->socket->status == 0) diff --git a/grub-core/net/udp.c b/grub-core/net/udp.c index 4477b3c2b..0b19c3098 100644 --- a/grub-core/net/udp.c +++ b/grub-core/net/udp.c @@ -25,7 +25,6 @@ grub_net_send_udp_packet (const grub_net_socket_t socket , struct grub_net_buff grub_err_t grub_net_recv_udp_packet (struct grub_net_buff *nb) { - //grub_err_t err; struct udphdr *udph; grub_net_socket_t sock; udph = (struct udphdr *) nb->data; @@ -41,7 +40,7 @@ grub_net_recv_udp_packet (struct grub_net_buff *nb) /* App protocol remove its own reader. */ sock->app->read (sock,nb); - /* If there is data, puts packet in socket list */ + /* If there is data, puts packet in socket list. */ if ((nb->tail - nb->data) > 0) grub_net_put_packet (&sock->packs, nb); else From 4700d08bb4ed597a9aa122340b06fba137327bb7 Mon Sep 17 00:00:00 2001 From: Manoel Rebelo Abranches Date: Tue, 7 Jun 2011 21:59:53 -0300 Subject: [PATCH 648/869] Run indent on files. --- grub-core/net/arp.c | 91 ++++++++------- grub-core/net/drivers/emu/emunet.c | 39 +++---- grub-core/net/drivers/ieee1275/ofnet.c | 154 +++++++++++++------------ grub-core/net/ethernet.c | 28 ++--- grub-core/net/ip.c | 53 ++++----- grub-core/net/netbuff.c | 59 ++++++---- grub-core/net/tftp.c | 118 +++++++++---------- grub-core/net/udp.c | 53 ++++----- 8 files changed, 307 insertions(+), 288 deletions(-) diff --git a/grub-core/net/arp.c b/grub-core/net/arp.c index 1300def25..0644d3d2e 100644 --- a/grub-core/net/arp.c +++ b/grub-core/net/arp.c @@ -9,10 +9,10 @@ static struct arp_entry arp_table[10]; static grub_int8_t new_table_entry = -1; -static -void arp_init_table(void) +static void +arp_init_table (void) { - grub_memset (arp_table, 0, sizeof (arp_table)); + grub_memset (arp_table, 0, sizeof (arp_table)); new_table_entry = 0; } @@ -20,19 +20,19 @@ static struct arp_entry * arp_find_entry (const grub_net_network_level_address_t *proto) { unsigned i; - for(i = 0; i < ARRAY_SIZE (arp_table); i++) + for (i = 0; i < ARRAY_SIZE (arp_table); i++) { - if(arp_table[i].avail == 1 && - arp_table[i].nl_address.ipv4 == proto->ipv4) - return &(arp_table[i]); + if (arp_table[i].avail == 1 && + arp_table[i].nl_address.ipv4 == proto->ipv4) + return &(arp_table[i]); } return NULL; } grub_err_t -grub_net_arp_resolve(struct grub_net_network_level_interface *inf, - const grub_net_network_level_address_t *proto_addr, - grub_net_link_level_address_t *hw_addr) +grub_net_arp_resolve (struct grub_net_network_level_interface *inf, + const grub_net_network_level_address_t *proto_addr, + grub_net_link_level_address_t *hw_addr) { struct arp_entry *entry; struct grub_net_buff nb; @@ -51,10 +51,10 @@ grub_net_arp_resolve(struct grub_net_network_level_interface *inf, /* Build a request packet. */ nb.head = arp_data; nb.end = arp_data + sizeof (arp_data); - grub_netbuff_clear (&nb); + grub_netbuff_clear (&nb); - grub_netbuff_reserve (&nb,128); - grub_netbuff_push (&nb, sizeof(*arp_header) + 2 * (6 + 4)); + grub_netbuff_reserve (&nb, 128); + grub_netbuff_push (&nb, sizeof (*arp_header) + 2 * (6 + 4)); arp_header = (struct arphdr *) nb.data; arp_header->hrd = grub_cpu_to_be16 (GRUB_NET_ARPHRD_ETHERNET); arp_header->pro = grub_cpu_to_be16 (GRUB_NET_ETHERTYPE_IP); @@ -71,11 +71,11 @@ grub_net_arp_resolve(struct grub_net_network_level_interface *inf, grub_memcpy (aux, &inf->address.ipv4, 4); aux += 4; /* Target hardware address */ - for(i = 0; i < 6; i++) + for (i = 0; i < 6; i++) aux[i] = 0x00; aux += 6; /* Target protocol address */ - grub_memcpy(aux, &proto_addr->ipv4, 4); + grub_memcpy (aux, &proto_addr->ipv4, 4); grub_memset (&target_hw_addr.mac, 0xff, 6); send_ethernet_packet (inf, &nb, target_hw_addr, GRUB_NET_ETHERTYPE_ARP); @@ -96,56 +96,59 @@ grub_net_arp_resolve(struct grub_net_network_level_interface *inf, grub_err_t grub_net_arp_receive (struct grub_net_buff *nb) { - struct arphdr *arp_header = (struct arphdr *)nb->data; + struct arphdr *arp_header = (struct arphdr *) nb->data; struct arp_entry *entry; grub_uint8_t *sender_hardware_address, *sender_protocol_address; grub_uint8_t *target_hardware_address, *target_protocol_address; grub_net_network_level_address_t hwaddress; struct grub_net_network_level_interface *inf; - sender_hardware_address = (grub_uint8_t *) arp_header + sizeof(*arp_header); + sender_hardware_address = + (grub_uint8_t *) arp_header + sizeof (*arp_header); sender_protocol_address = sender_hardware_address + arp_header->hln; target_hardware_address = sender_protocol_address + arp_header->pln; target_protocol_address = target_hardware_address + arp_header->hln; grub_memcpy (&hwaddress.ipv4, sender_protocol_address, 4); - /* Check if the sender is in the cache table */ - entry = arp_find_entry(&hwaddress); - /* Update sender hardware address */ + /* Check if the sender is in the cache table. */ + entry = arp_find_entry (&hwaddress); + /* Update sender hardware address. */ if (entry) - grub_memcpy(entry->ll_address.mac, sender_hardware_address, 6); + grub_memcpy (entry->ll_address.mac, sender_hardware_address, 6); else { - /* Add sender to cache table */ + /* Add sender to cache table. */ if (new_table_entry == -1) - arp_init_table(); + arp_init_table (); entry = &(arp_table[new_table_entry]); entry->avail = 1; - grub_memcpy(&entry->nl_address.ipv4, sender_protocol_address, 4); - grub_memcpy(entry->ll_address.mac, sender_hardware_address, 6); + grub_memcpy (&entry->nl_address.ipv4, sender_protocol_address, 4); + grub_memcpy (entry->ll_address.mac, sender_hardware_address, 6); new_table_entry++; if (new_table_entry == ARRAY_SIZE (arp_table)) new_table_entry = 0; } - FOR_NET_NETWORK_LEVEL_INTERFACES(inf) - { - /* Am I the protocol address target? */ - if (grub_memcmp (target_protocol_address, &inf->address.ipv4, 6) == 0 - && grub_be_to_cpu16 (arp_header->op) == ARP_REQUEST) - { - grub_net_link_level_address_t aux; - /* Swap hardware fields */ - grub_memcpy (target_hardware_address, sender_hardware_address, arp_header->hln); - grub_memcpy (sender_hardware_address, inf->hwaddress.mac, 6); - grub_memcpy (aux.mac, sender_protocol_address, 6); - grub_memcpy (sender_protocol_address, target_protocol_address, arp_header->pln); - grub_memcpy (target_protocol_address, aux.mac, arp_header->pln); - /* Change operation to REPLY and send packet */ - arp_header->op = grub_be_to_cpu16 (ARP_REPLY); - grub_memcpy (aux.mac, target_hardware_address, 6); - send_ethernet_packet (inf, nb, aux, GRUB_NET_ETHERTYPE_ARP); - } - } + FOR_NET_NETWORK_LEVEL_INTERFACES (inf) + { + /* Am I the protocol address target? */ + if (grub_memcmp (target_protocol_address, &inf->address.ipv4, 6) == 0 + && grub_be_to_cpu16 (arp_header->op) == ARP_REQUEST) + { + grub_net_link_level_address_t aux; + /* Swap hardware fields */ + grub_memcpy (target_hardware_address, sender_hardware_address, + arp_header->hln); + grub_memcpy (sender_hardware_address, inf->hwaddress.mac, 6); + grub_memcpy (aux.mac, sender_protocol_address, 6); + grub_memcpy (sender_protocol_address, target_protocol_address, + arp_header->pln); + grub_memcpy (target_protocol_address, aux.mac, arp_header->pln); + /* Change operation to REPLY and send packet */ + arp_header->op = grub_be_to_cpu16 (ARP_REPLY); + grub_memcpy (aux.mac, target_hardware_address, 6); + send_ethernet_packet (inf, nb, aux, GRUB_NET_ETHERTYPE_ARP); + } + } return GRUB_ERR_NONE; } diff --git a/grub-core/net/drivers/emu/emunet.c b/grub-core/net/drivers/emu/emunet.c index d707d8015..ee4ba4773 100644 --- a/grub-core/net/drivers/emu/emunet.c +++ b/grub-core/net/drivers/emu/emunet.c @@ -13,7 +13,7 @@ static int fd; -static grub_err_t +static grub_err_t send_card_buffer (struct grub_net_card *dev __attribute__ ((unused)), struct grub_net_buff *pack) { @@ -22,7 +22,7 @@ send_card_buffer (struct grub_net_card *dev __attribute__ ((unused)), actual = write (fd, pack->data, pack->tail - pack->data); if (actual < 0) return grub_error (GRUB_ERR_IO, "couldn't send packets"); - + return GRUB_ERR_NONE; } @@ -32,32 +32,32 @@ get_card_packet (struct grub_net_card *dev __attribute__ ((unused)), { ssize_t actual; - grub_netbuff_clear(pack); + grub_netbuff_clear (pack); actual = read (fd, pack->data, 1500); if (actual < 0) return -1; grub_netbuff_put (pack, actual); - return actual; + return actual; } static struct grub_net_card_driver emudriver = -{ - .name = "emu", - .send = send_card_buffer, - .recv = get_card_packet -}; + { + .name = "emu", + .send = send_card_buffer, + .recv = get_card_packet + }; static struct grub_net_card emucard = -{ - .name = "emu0", - .driver = &emudriver, - .default_address = { - .type = GRUB_NET_LINK_LEVEL_PROTOCOL_ETHERNET, - { .mac = { 0, 1, 2, 3, 4, 5} } - }, - .flags = 0 -}; + { + .name = "emu0", + .driver = &emudriver, + .default_address = { + .type = GRUB_NET_LINK_LEVEL_PROTOCOL_ETHERNET, + {.mac = {0, 1, 2, 3, 4, 5}} + }, + .flags = 0 + }; GRUB_MOD_INIT(emunet) { @@ -84,6 +84,3 @@ GRUB_MOD_FINI(emunet) grub_net_card_unregister (&emucard); } } - - - diff --git a/grub-core/net/drivers/ieee1275/ofnet.c b/grub-core/net/drivers/ieee1275/ofnet.c index 10d0b979e..751583e9d 100644 --- a/grub-core/net/drivers/ieee1275/ofnet.c +++ b/grub-core/net/drivers/ieee1275/ofnet.c @@ -7,15 +7,18 @@ GRUB_MOD_LICENSE ("GPLv3+"); -static grub_err_t +static grub_err_t card_open (struct grub_net_card *dev) { int status; struct grub_ofnetcard_data *data = dev->data; - char path[grub_strlen(data->path) + grub_strlen(":speed=auto,duplex=auto,1.1.1.1,dummy,1.1.1.1,1.1.1.1,5,5,1.1.1.1,512") + 1]; + char path[grub_strlen (data->path) + + grub_strlen (":speed=auto,duplex=auto,1.1.1.1,dummy,1.1.1.1,1.1.1.1,5,5,1.1.1.1,512") + 1]; + /* The full string will prevent a bootp packet to be sent. Just put some valid ip in there. */ - grub_snprintf(path,sizeof(path),"%s%s",data->path,":speed=auto,duplex=auto,1.1.1.1,dummy,1.1.1.1,1.1.1.1,5,5,1.1.1.1,512"); - status = grub_ieee1275_open (path,&(data->handle)); + grub_snprintf (path, sizeof (path), "%s%s", data->path, + ":speed=auto,duplex=auto,1.1.1.1,dummy,1.1.1.1,1.1.1.1,5,5,1.1.1.1,512"); + status = grub_ieee1275_open (path, &(data->handle)); if (status) return grub_error (GRUB_ERR_IO, "Couldn't open network card."); @@ -23,23 +26,23 @@ card_open (struct grub_net_card *dev) return GRUB_ERR_NONE; } -static grub_err_t +static grub_err_t card_close (struct grub_net_card *dev) { struct grub_ofnetcard_data *data = dev->data; - + if (data->handle) grub_ieee1275_close (data->handle); return GRUB_ERR_NONE; } -static grub_err_t +static grub_err_t send_card_buffer (struct grub_net_card *dev, struct grub_net_buff *pack) -{ +{ int actual; int status; struct grub_ofnetcard_data *data = dev->data; - + status = grub_ieee1275_write (data->handle, pack->data, pack->tail - pack->data, &actual); @@ -56,27 +59,27 @@ get_card_packet (struct grub_net_card *dev, struct grub_net_buff *nb) struct grub_ofnetcard_data *data = dev->data; grub_uint64_t start_time; - grub_netbuff_clear (nb); + grub_netbuff_clear (nb); start_time = grub_get_time_ms (); do rc = grub_ieee1275_read (data->handle, nb->data, data->mtu, &actual); while ((actual <= 0 || rc < 0) && (grub_get_time_ms () - start_time < 200)); if (actual) { - grub_netbuff_put (nb, actual); + grub_netbuff_put (nb, actual); return actual; } return -1; } -static struct grub_net_card_driver ofdriver = -{ - .name = "ofnet", - .init = card_open, - .fini = card_close, - .send = send_card_buffer, - .recv = get_card_packet -}; +static struct grub_net_card_driver ofdriver = + { + .name = "ofnet", + .init = card_open, + .fini = card_close, + .send = send_card_buffer, + .recv = get_card_packet + }; static const struct { @@ -84,23 +87,23 @@ static const struct int offset; } -bootp_response_properties[] = -{ - { .name = "bootp-response", .offset = 0 }, - { .name = "dhcp-response", .offset = 0 }, - { .name = "bootpreply-packet", .offset = 0x2a }, -}; +bootp_response_properties[] = + { + { .name = "bootp-response", .offset = 0}, + { .name = "dhcp-response", .offset = 0}, + { .name = "bootpreply-packet", .offset = 0x2a}, + }; -static grub_bootp_t -grub_getbootp_real ( void ) +static grub_bootp_t +grub_getbootp_real (void) { grub_bootp_t packet = grub_malloc (sizeof *packet); - char *bootp_response; + char *bootp_response; grub_ssize_t size; unsigned int i; - for ( i = 0; i < ARRAY_SIZE (bootp_response_properties); i++) - if (grub_ieee1275_get_property_length (grub_ieee1275_chosen, + for (i = 0; i < ARRAY_SIZE (bootp_response_properties); i++) + if (grub_ieee1275_get_property_length (grub_ieee1275_chosen, bootp_response_properties[i].name, &size) >= 0) break; @@ -111,8 +114,7 @@ grub_getbootp_real ( void ) bootp_response = grub_malloc (size); if (grub_ieee1275_get_property (grub_ieee1275_chosen, bootp_response_properties[i].name, - bootp_response , - size, 0) < 0) + bootp_response, size, 0) < 0) return NULL; grub_memcpy (packet, bootp_response + bootp_response_properties[i].offset, sizeof (*packet)); @@ -120,52 +122,55 @@ grub_getbootp_real ( void ) return packet; } -static -void grub_ofnet_findcards (void) +static void +grub_ofnet_findcards (void) { struct grub_net_card *card; grub_ieee1275_phandle_t devhandle; - grub_net_link_level_address_t lla; + grub_net_link_level_address_t lla; int i = 0; auto int search_net_devices (struct grub_ieee1275_devalias *alias); int search_net_devices (struct grub_ieee1275_devalias *alias) - { - if ( !grub_strcmp (alias->type,"network") ) - { - - card = grub_malloc (sizeof (struct grub_net_card)); - struct grub_ofnetcard_data *ofdata = grub_malloc (sizeof (struct grub_ofnetcard_data)); - ofdata->path = grub_strdup (alias->path); - - grub_ieee1275_finddevice (ofdata->path, &devhandle); - - if (grub_ieee1275_get_integer_property - (devhandle, "max-frame-size", &(ofdata->mtu), sizeof (ofdata->mtu), 0)) - return grub_error (GRUB_ERR_IO, "Couldn't retrieve mtu size."); + { + if (!grub_strcmp (alias->type, "network")) + { - if (grub_ieee1275_get_property (devhandle, "mac-address", &(lla.mac), 6, 0)) - return grub_error (GRUB_ERR_IO, "Couldn't retrieve mac address."); - - lla.type = GRUB_NET_LINK_LEVEL_PROTOCOL_ETHERNET; - card->default_address = lla; + card = grub_malloc (sizeof (struct grub_net_card)); + struct grub_ofnetcard_data *ofdata = + grub_malloc (sizeof (struct grub_ofnetcard_data)); + ofdata->path = grub_strdup (alias->path); - card->driver = NULL; - card->data = ofdata; + grub_ieee1275_finddevice (ofdata->path, &devhandle); + + if (grub_ieee1275_get_integer_property + (devhandle, "max-frame-size", &(ofdata->mtu), + sizeof (ofdata->mtu), 0)) + return grub_error (GRUB_ERR_IO, "Couldn't retrieve mtu size."); + + if (grub_ieee1275_get_property + (devhandle, "mac-address", &(lla.mac), 6, 0)) + return grub_error (GRUB_ERR_IO, "Couldn't retrieve mac address."); + + lla.type = GRUB_NET_LINK_LEVEL_PROTOCOL_ETHERNET; + card->default_address = lla; + + card->driver = NULL; + card->data = ofdata; card->flags = 0; - card->name = grub_xasprintf("eth%d",i++); // grub_strdup (alias->name); - grub_net_card_register (card); + card->name = grub_xasprintf ("eth%d", i++); + grub_net_card_register (card); return 0; - } - return 0; + } + return 0; } /* Look at all nodes for devices of the type network. */ grub_ieee1275_devices_iterate (search_net_devices); } -static -void grub_ofnet_probecards (void) +static void +grub_ofnet_probecards (void) { struct grub_net_card *card; struct grub_net_card_driver *driver; @@ -175,19 +180,21 @@ void grub_ofnet_probecards (void) grub_net_network_level_netaddress_t net; bootp_pckt = grub_getbootp (); - /* Assign correspondent driver for each device. */ + /* Assign correspondent driver for each device. */ FOR_NET_CARDS (card) { FOR_NET_CARD_DRIVERS (driver) { - if (driver->init(card) == GRUB_ERR_NONE) + if (driver->init (card) == GRUB_ERR_NONE) { card->driver = driver; - if (bootp_pckt && grub_memcmp(bootp_pckt->chaddr,card->default_address.mac,6) == 0) + if (bootp_pckt + && grub_memcmp (bootp_pckt->chaddr, card->default_address.mac, 6) == 0) { addr.type = GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4; addr.ipv4 = bootp_pckt->yiaddr; - grub_net_add_addr ("bootp_cli_addr", card, addr, card->default_address, 0); + grub_net_add_addr ("bootp_cli_addr", card, addr, + card->default_address, 0); FOR_NET_NETWORK_LEVEL_INTERFACES (inter) if (grub_strcmp (inter->name, "bootp_cli_addr") == 0) break; @@ -197,30 +204,27 @@ void grub_ofnet_probecards (void) grub_net_add_route ("bootp-router", net, inter); } break; - } + } } } grub_free (bootp_pckt); - + } -GRUB_MOD_INIT (ofnet) +GRUB_MOD_INIT(ofnet) { struct grub_net_card *card; grub_getbootp = grub_getbootp_real; grub_net_card_driver_register (&ofdriver); - grub_ofnet_findcards (); - grub_ofnet_probecards (); - FOR_NET_CARDS (card) + grub_ofnet_findcards (); + grub_ofnet_probecards (); + FOR_NET_CARDS (card) if (card->driver == NULL) grub_net_card_unregister (card); } -GRUB_MOD_FINI (ofnet) +GRUB_MOD_FINI(ofnet) { grub_net_card_driver_unregister (&ofdriver); grub_getbootp = NULL; } - - - diff --git a/grub-core/net/ethernet.c b/grub-core/net/ethernet.c index c96a65602..d29193afe 100644 --- a/grub-core/net/ethernet.c +++ b/grub-core/net/ethernet.c @@ -8,25 +8,25 @@ #include #include -grub_err_t +grub_err_t send_ethernet_packet (struct grub_net_network_level_interface *inf, struct grub_net_buff *nb, grub_net_link_level_address_t target_addr, grub_uint16_t ethertype) { - struct etherhdr *eth; + struct etherhdr *eth; - grub_netbuff_push (nb,sizeof(*eth)); - eth = (struct etherhdr *) nb->data; - grub_memcpy(eth->dst, target_addr.mac, 6); - grub_memcpy(eth->src, inf->hwaddress.mac, 6); + grub_netbuff_push (nb, sizeof (*eth)); + eth = (struct etherhdr *) nb->data; + grub_memcpy (eth->dst, target_addr.mac, 6); + grub_memcpy (eth->src, inf->hwaddress.mac, 6); eth->type = grub_cpu_to_be16 (ethertype); return inf->card->driver->send (inf->card, nb); } -grub_err_t +grub_err_t grub_net_recv_ethernet_packet (struct grub_net_buff *nb) { struct etherhdr *eth; @@ -34,32 +34,32 @@ grub_net_recv_ethernet_packet (struct grub_net_buff *nb) struct snaphdr *snaph; grub_uint16_t type; - eth = (struct etherhdr *) nb->data; + eth = (struct etherhdr *) nb->data; type = grub_be_to_cpu16 (eth->type); grub_netbuff_pull (nb, sizeof (*eth)); - + if (type <= 1500) { llch = (struct llchdr *) nb->data; type = llch->dsap & LLCADDRMASK; if (llch->dsap == 0xaa && llch->ssap == 0xaa && llch->ctrl == 0x3) - { - grub_netbuff_pull (nb,sizeof(*llch)); + { + grub_netbuff_pull (nb, sizeof (*llch)); snaph = (struct snaphdr *) nb->data; type = snaph->type; } } - /* ARP packet */ + /* ARP packet. */ if (type == GRUB_NET_ETHERTYPE_ARP) { grub_net_arp_receive (nb); grub_netbuff_free (nb); } - /* IP packet */ + /* IP packet. */ if (type == GRUB_NET_ETHERTYPE_IP) grub_net_recv_ip_packets (nb); - return GRUB_ERR_NONE; + return GRUB_ERR_NONE; } diff --git a/grub-core/net/ip.c b/grub-core/net/ip.c index d6684c29e..4adc2b028 100644 --- a/grub-core/net/ip.c +++ b/grub-core/net/ip.c @@ -8,54 +8,55 @@ #include grub_uint16_t -ipchksum(void *ipv, int len) +ipchksum (void *ipv, int len) { - grub_uint16_t *ip = (grub_uint16_t *)ipv; - grub_uint32_t sum = 0; + grub_uint16_t *ip = (grub_uint16_t *) ipv; + grub_uint32_t sum = 0; - len >>= 1; - while (len--) - { - sum += grub_be_to_cpu16 (*(ip++)); - if (sum > 0xFFFF) - sum -= 0xFFFF; - } + len >>= 1; + while (len--) + { + sum += grub_be_to_cpu16 (*(ip++)); + if (sum > 0xFFFF) + sum -= 0xFFFF; + } - return grub_cpu_to_be16 ((~sum) & 0x0000FFFF); + return grub_cpu_to_be16 ((~sum) & 0x0000FFFF); } grub_err_t grub_net_send_ip_packet (struct grub_net_network_level_interface *inf, const grub_net_network_level_address_t *target, struct grub_net_buff *nb) -{ +{ struct iphdr *iph; - static int id = 0x2400; + static int id = 0x2400; grub_net_link_level_address_t ll_target_addr; grub_err_t err; - - grub_netbuff_push (nb, sizeof(*iph)); - iph = (struct iphdr *) nb->data; + + grub_netbuff_push (nb, sizeof (*iph)); + iph = (struct iphdr *) nb->data; iph->verhdrlen = ((4 << 4) | 5); iph->service = 0; - iph->len = grub_cpu_to_be16 (nb->tail - nb-> data); + iph->len = grub_cpu_to_be16 (nb->tail - nb->data); iph->ident = grub_cpu_to_be16 (++id); iph->frags = 0; iph->ttl = 0xff; iph->protocol = 0x11; iph->src = inf->address.ipv4; iph->dest = target->ipv4; - - iph->chksum = 0 ; - iph->chksum = ipchksum((void *)nb->data, sizeof(*iph)); - + + iph->chksum = 0; + iph->chksum = ipchksum ((void *) nb->data, sizeof (*iph)); + /* Determine link layer target address via ARP. */ err = grub_net_arp_resolve (inf, target, &ll_target_addr); if (err) return err; return send_ethernet_packet (inf, nb, ll_target_addr, GRUB_NET_ETHERTYPE_IP); } + /* static int ip_filter (struct grub_net_buff *nb) @@ -80,7 +81,7 @@ ip_filter (struct grub_net_buff *nb) return 1; } */ -grub_err_t +grub_err_t grub_net_recv_ip_packets (struct grub_net_buff *nb) { struct iphdr *iph = (struct iphdr *) nb->data; @@ -88,11 +89,11 @@ grub_net_recv_ip_packets (struct grub_net_buff *nb) switch (iph->protocol) { - case IP_UDP: - return grub_net_recv_udp_packet (nb); + case IP_UDP: + return grub_net_recv_udp_packet (nb); break; - default: - grub_netbuff_free (nb); + default: + grub_netbuff_free (nb); break; } diff --git a/grub-core/net/netbuff.c b/grub-core/net/netbuff.c index be9fc9de2..aae2f4d8f 100644 --- a/grub-core/net/netbuff.c +++ b/grub-core/net/netbuff.c @@ -22,73 +22,84 @@ #include -grub_err_t grub_netbuff_put (struct grub_net_buff *nb ,grub_size_t len) +grub_err_t +grub_netbuff_put (struct grub_net_buff *nb, grub_size_t len) { nb->tail += len; if (nb->tail > nb->end) return grub_error (GRUB_ERR_OUT_OF_RANGE, "put out of the packet range."); - return GRUB_ERR_NONE; + return GRUB_ERR_NONE; } -grub_err_t grub_netbuff_unput (struct grub_net_buff *nb ,grub_size_t len) +grub_err_t +grub_netbuff_unput (struct grub_net_buff *nb, grub_size_t len) { nb->tail -= len; if (nb->tail < nb->head) - return grub_error (GRUB_ERR_OUT_OF_RANGE, "unput out of the packet range."); - return GRUB_ERR_NONE; + return grub_error (GRUB_ERR_OUT_OF_RANGE, + "unput out of the packet range."); + return GRUB_ERR_NONE; } -grub_err_t grub_netbuff_push (struct grub_net_buff *nb ,grub_size_t len) +grub_err_t +grub_netbuff_push (struct grub_net_buff *nb, grub_size_t len) { nb->data -= len; if (nb->data < nb->head) - return grub_error (GRUB_ERR_OUT_OF_RANGE, "push out of the packet range."); - return GRUB_ERR_NONE; + return grub_error (GRUB_ERR_OUT_OF_RANGE, + "push out of the packet range."); + return GRUB_ERR_NONE; } -grub_err_t grub_netbuff_pull (struct grub_net_buff *nb ,grub_size_t len) +grub_err_t +grub_netbuff_pull (struct grub_net_buff *nb, grub_size_t len) { nb->data += len; if (nb->data > nb->end) - return grub_error (GRUB_ERR_OUT_OF_RANGE, "pull out of the packet range."); - return GRUB_ERR_NONE; + return grub_error (GRUB_ERR_OUT_OF_RANGE, + "pull out of the packet range."); + return GRUB_ERR_NONE; } -grub_err_t grub_netbuff_reserve (struct grub_net_buff *nb ,grub_size_t len) +grub_err_t +grub_netbuff_reserve (struct grub_net_buff *nb, grub_size_t len) { nb->data += len; nb->tail += len; if ((nb->tail > nb->end) || (nb->data > nb->end)) - return grub_error (GRUB_ERR_OUT_OF_RANGE, "reserve out of the packet range."); - return GRUB_ERR_NONE; + return grub_error (GRUB_ERR_OUT_OF_RANGE, + "reserve out of the packet range."); + return GRUB_ERR_NONE; } -struct grub_net_buff *grub_netbuff_alloc ( grub_size_t len ) +struct grub_net_buff * +grub_netbuff_alloc (grub_size_t len) { struct grub_net_buff *nb; void *data; - if (len < NETBUFFMINLEN) + if (len < NETBUFFMINLEN) len = NETBUFFMINLEN; - - len = ALIGN_UP (len,NETBUFF_ALIGN); + + len = ALIGN_UP (len, NETBUFF_ALIGN); data = grub_memalign (NETBUFF_ALIGN, len + sizeof (*nb)); if (!data) return NULL; - nb = (struct grub_net_buff *) ((grub_uint8_t *) data + len); + nb = (struct grub_net_buff *) ((grub_uint8_t *) data + len); nb->head = nb->data = nb->tail = data; - nb->end = (char *) nb; - return nb; + nb->end = (char *) nb; + return nb; } -grub_err_t grub_netbuff_free (struct grub_net_buff *nb) +grub_err_t +grub_netbuff_free (struct grub_net_buff *nb) { grub_free (nb->head); return 0; - } -grub_err_t grub_netbuff_clear (struct grub_net_buff *nb) +grub_err_t +grub_netbuff_clear (struct grub_net_buff *nb) { nb->data = nb->tail = nb->head; return 0; diff --git a/grub-core/net/tftp.c b/grub-core/net/tftp.c index 010a4a4bd..ac3b3e9db 100644 --- a/grub-core/net/tftp.c +++ b/grub-core/net/tftp.c @@ -11,15 +11,15 @@ GRUB_MOD_LICENSE ("GPLv3+"); -static grub_err_t +static grub_err_t tftp_open (struct grub_file *file, const char *filename) { - struct tftphdr *tftph; + struct tftphdr *tftph; char *rrq; int i; int rrqlen; int hdrlen; - char open_data[1500]; + char open_data[1500]; struct grub_net_buff nb; tftp_data_t data; grub_err_t err; @@ -27,47 +27,47 @@ tftp_open (struct grub_file *file, const char *filename) data = grub_malloc (sizeof *data); if (!data) return grub_errno; - + file->device->net->socket->data = (void *) data; nb.head = open_data; nb.end = open_data + sizeof (open_data); - grub_netbuff_clear (&nb); + grub_netbuff_clear (&nb); - grub_netbuff_reserve (&nb,1500); - grub_netbuff_push (&nb,sizeof (*tftph)); + grub_netbuff_reserve (&nb, 1500); + grub_netbuff_push (&nb, sizeof (*tftph)); + + tftph = (struct tftphdr *) nb.data; - tftph = (struct tftphdr *) nb.data; - rrq = (char *) tftph->u.rrq; rrqlen = 0; - + tftph->opcode = grub_cpu_to_be16 (TFTP_RRQ); grub_strcpy (rrq, filename); rrqlen += grub_strlen (filename) + 1; - rrq += grub_strlen (filename) + 1; - - grub_strcpy (rrq,"octet"); + rrq += grub_strlen (filename) + 1; + + grub_strcpy (rrq, "octet"); rrqlen += grub_strlen ("octet") + 1; - rrq += grub_strlen ("octet") + 1; + rrq += grub_strlen ("octet") + 1; - grub_strcpy (rrq,"blksize"); - rrqlen += grub_strlen("blksize") + 1; - rrq += grub_strlen ("blksize") + 1; + grub_strcpy (rrq, "blksize"); + rrqlen += grub_strlen ("blksize") + 1; + rrq += grub_strlen ("blksize") + 1; - grub_strcpy (rrq,"1024"); + grub_strcpy (rrq, "1024"); rrqlen += grub_strlen ("1024") + 1; - rrq += grub_strlen ("1024") + 1; - - grub_strcpy (rrq,"tsize"); - rrqlen += grub_strlen ("tsize") + 1; - rrq += grub_strlen ("tsize") + 1; + rrq += grub_strlen ("1024") + 1; - grub_strcpy (rrq,"0"); + grub_strcpy (rrq, "tsize"); + rrqlen += grub_strlen ("tsize") + 1; + rrq += grub_strlen ("tsize") + 1; + + grub_strcpy (rrq, "0"); rrqlen += grub_strlen ("0") + 1; rrq += grub_strlen ("0") + 1; hdrlen = sizeof (tftph->opcode) + rrqlen; - - grub_netbuff_unput (&nb, nb.tail - (nb.data + hdrlen)); + + grub_netbuff_unput (&nb, nb.tail - (nb.data + hdrlen)); file->device->net->socket->out_port = TFTP_SERVER_PORT; @@ -76,7 +76,7 @@ tftp_open (struct grub_file *file, const char *filename) return err; /* Receive OACK packet. */ - for ( i = 0; i < 3; i++) + for (i = 0; i < 3; i++) { grub_net_poll_cards (100); if (grub_errno) @@ -85,22 +85,22 @@ tftp_open (struct grub_file *file, const char *filename) break; /* Retry. */ /*err = grub_net_send_udp_packet (file->device->net->socket, &nb); - if (err) - return err;*/ + if (err) + return err; */ } if (file->device->net->socket->status == 0) - return grub_error (GRUB_ERR_TIMEOUT,"Time out opening tftp."); + return grub_error (GRUB_ERR_TIMEOUT, "Time out opening tftp."); file->size = data->file_size; return GRUB_ERR_NONE; } -static grub_err_t +static grub_err_t tftp_receive (grub_net_socket_t sock, struct grub_net_buff *nb) { struct tftphdr *tftph; - char nbdata[128]; + char nbdata[128]; tftp_data_t data = sock->data; grub_err_t err; char *ptr; @@ -112,9 +112,9 @@ tftp_receive (grub_net_socket_t sock, struct grub_net_buff *nb) tftph = (struct tftphdr *) nb->data; switch (grub_be_to_cpu16 (tftph->opcode)) - { + { case TFTP_OACK: - for (ptr = nb->data + sizeof (tftph->opcode); ptr < nb->tail; ) + for (ptr = nb->data + sizeof (tftph->opcode); ptr < nb->tail;) { if (grub_memcmp (ptr, "tsize\0", sizeof ("tsize\0") - 1) == 0) { @@ -125,13 +125,14 @@ tftp_receive (grub_net_socket_t sock, struct grub_net_buff *nb) ptr++; ptr++; } - sock->status = 1; + sock->status = 1; data->block = 0; - grub_netbuff_clear(nb); - break; + grub_netbuff_clear (nb); + break; case TFTP_DATA: - grub_netbuff_pull (nb,sizeof (tftph->opcode) + sizeof (tftph->u.data.block)); - + grub_netbuff_pull (nb, sizeof (tftph->opcode) + + sizeof (tftph->u.data.block)); + if (grub_be_to_cpu16 (tftph->u.data.block) == data->block + 1) { data->block++; @@ -140,22 +141,23 @@ tftp_receive (grub_net_socket_t sock, struct grub_net_buff *nb) sock->status = 2; /* Prevent garbage in broken cards. */ if (size > 1024) - grub_netbuff_unput (nb, size - 1024); + grub_netbuff_unput (nb, size - 1024); } else - grub_netbuff_clear(nb); - - break; + grub_netbuff_clear (nb); + + break; case TFTP_ERROR: grub_netbuff_clear (nb); - return grub_error (GRUB_ERR_IO, (char *)tftph->u.err.errmsg); - break; - } + return grub_error (GRUB_ERR_IO, (char *) tftph->u.err.errmsg); + break; + } grub_netbuff_clear (&nb_ack); - grub_netbuff_reserve (&nb_ack,128); - grub_netbuff_push (&nb_ack,sizeof (tftph->opcode) + sizeof (tftph->u.ack.block)); + grub_netbuff_reserve (&nb_ack, 128); + grub_netbuff_push (&nb_ack, sizeof (tftph->opcode) + + sizeof (tftph->u.ack.block)); - tftph = (struct tftphdr *) nb_ack.data; + tftph = (struct tftphdr *) nb_ack.data; tftph->opcode = grub_cpu_to_be16 (TFTP_ACK); tftph->u.ack.block = grub_cpu_to_be16 (data->block); @@ -163,7 +165,7 @@ tftp_receive (grub_net_socket_t sock, struct grub_net_buff *nb) return err; } -static grub_err_t +static grub_err_t tftp_close (struct grub_file *file __attribute__ ((unused))) { grub_free (file->device->net->socket->data); @@ -171,19 +173,19 @@ tftp_close (struct grub_file *file __attribute__ ((unused))) } static struct grub_net_app_protocol grub_tftp_protocol = -{ - .name = "tftp", - .open = tftp_open, - .read = tftp_receive, - .close = tftp_close -}; + { + .name = "tftp", + .open = tftp_open, + .read = tftp_receive, + .close = tftp_close + }; -GRUB_MOD_INIT (tftp) +GRUB_MOD_INIT(tftp) { grub_net_app_level_register (&grub_tftp_protocol); } -GRUB_MOD_FINI (tftp) +GRUB_MOD_FINI(tftp) { grub_net_app_level_unregister (&grub_tftp_protocol); } diff --git a/grub-core/net/udp.c b/grub-core/net/udp.c index 0b19c3098..86220bf0f 100644 --- a/grub-core/net/udp.c +++ b/grub-core/net/udp.c @@ -5,24 +5,25 @@ #include grub_err_t -grub_net_send_udp_packet (const grub_net_socket_t socket , struct grub_net_buff *nb) +grub_net_send_udp_packet (const grub_net_socket_t socket, + struct grub_net_buff *nb) { struct udphdr *udph; - grub_netbuff_push (nb,sizeof(*udph)); - - udph = (struct udphdr *) nb->data; + grub_netbuff_push (nb, sizeof (*udph)); + + udph = (struct udphdr *) nb->data; udph->src = grub_cpu_to_be16 (socket->in_port); udph->dst = grub_cpu_to_be16 (socket->out_port); /* No chechksum. */ - udph->chksum = 0; + udph->chksum = 0; udph->len = grub_cpu_to_be16 (nb->tail - nb->data); - + return grub_net_send_ip_packet (socket->inf, &(socket->out_nla), nb); } -grub_err_t +grub_err_t grub_net_recv_udp_packet (struct grub_net_buff *nb) { struct udphdr *udph; @@ -30,24 +31,24 @@ grub_net_recv_udp_packet (struct grub_net_buff *nb) udph = (struct udphdr *) nb->data; grub_netbuff_pull (nb, sizeof (*udph)); - FOR_NET_SOCKETS(sock) - { - if (grub_be_to_cpu16 (udph->dst) == sock->in_port) - { - if (sock->status == 0) - sock->out_port = grub_be_to_cpu16 (udph->src); - - /* App protocol remove its own reader. */ - sock->app->read (sock,nb); - - /* If there is data, puts packet in socket list. */ - if ((nb->tail - nb->data) > 0) - grub_net_put_packet (&sock->packs, nb); - else - grub_netbuff_free (nb); - return GRUB_ERR_NONE; - } - } - grub_netbuff_free (nb); + FOR_NET_SOCKETS (sock) + { + if (grub_be_to_cpu16 (udph->dst) == sock->in_port) + { + if (sock->status == 0) + sock->out_port = grub_be_to_cpu16 (udph->src); + + /* App protocol remove its own reader. */ + sock->app->read (sock, nb); + + /* If there is data, puts packet in socket list. */ + if ((nb->tail - nb->data) > 0) + grub_net_put_packet (&sock->packs, nb); + else + grub_netbuff_free (nb); + return GRUB_ERR_NONE; + } + } + grub_netbuff_free (nb); return GRUB_ERR_NONE; } From 1e9aef7d963e86016cbb0568c5f9d01eee31fd99 Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Mon, 13 Jun 2011 17:35:50 +0100 Subject: [PATCH 649/869] * docs/man/grub-mklayout.h2m (DESCRIPTION): Add a reference to the input format. --- ChangeLog | 5 +++++ docs/man/grub-mklayout.h2m | 6 ++++++ 2 files changed, 11 insertions(+) diff --git a/ChangeLog b/ChangeLog index fca980c1b..5ac0ffb5c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-06-13 Colin Watson + + * docs/man/grub-mklayout.h2m (DESCRIPTION): Add a reference to the + input format. + 2011-05-29 Colin Watson * docs/grub.texi (Obtaining and Building GRUB): Substitute diff --git a/docs/man/grub-mklayout.h2m b/docs/man/grub-mklayout.h2m index cda6f3676..1e43409c0 100644 --- a/docs/man/grub-mklayout.h2m +++ b/docs/man/grub-mklayout.h2m @@ -1,4 +1,10 @@ [NAME] grub-mklayout \- generate a GRUB keyboard layout file +[DESCRIPTION] +grub-mklayout processes a keyboard layout description in +.BR keymaps (5) +format into a format that can be used by GRUB's +.B keymap +command. [SEE ALSO] .BR grub-mkconfig (8) From e23bc603f8e799dd85839ffe928b9e41d9a09d83 Mon Sep 17 00:00:00 2001 From: "Manoel R. Abranches" Date: Wed, 15 Jun 2011 15:11:26 -0300 Subject: [PATCH 650/869] Prevent crash when detecting fs. --- grub-core/net/net.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/grub-core/net/net.c b/grub-core/net/net.c index 1232b3c74..380eec3b5 100644 --- a/grub-core/net/net.c +++ b/grub-core/net/net.c @@ -581,6 +581,16 @@ grub_net_open_real (const char *name) return NULL; } +static grub_err_t +grub_net_fs_dir (grub_device_t device, const char *path __attribute__ ((unused)), + int (*hook) (const char *filename, + const struct grub_dirhook_info *info) __attribute__ ((unused))) +{ + if (!device->net) + return grub_error (GRUB_ERR_BAD_FS, "invalid extent"); + return GRUB_ERR_NONE; +} + static grub_err_t grub_net_fs_open (struct grub_file *file, const char *name) { @@ -1014,7 +1024,7 @@ grub_cmd_dhcpopt (struct grub_command *cmd __attribute__ ((unused)), static struct grub_fs grub_net_fs = { .name = "netfs", - .dir = NULL, + .dir = grub_net_fs_dir, .open = grub_net_fs_open, .read = grub_net_fs_read, .close = grub_net_fs_close, From 881ac815d00ecf1aa9093b015edf8c2da334d191 Mon Sep 17 00:00:00 2001 From: Robert Millan Date: Thu, 16 Jun 2011 14:33:11 +0200 Subject: [PATCH 651/869] 2011-06-16 Robert Millan Detect `ataraid' devices on GNU/kFreeBSD. Fix for ATA devices using `ata' driver on kernel of FreeBSD 9. * util/deviceiter.c [__FreeBSD_kernel__] (get_ada_disk_name) (get_ataraid_disk_name): New functions. [__FreeBSD_kernel__] (grub_util_iterate_devices): Scan for ataraid (/dev/ar[0-9]+) and ada (/dev/ada[0-9]+) devices using get_ataraid_disk_name() and get_ada_disk_name(). --- ChangeLog | 11 +++++++++++ util/deviceiter.c | 45 ++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 55 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 5ac0ffb5c..043b858a5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2011-06-16 Robert Millan + + Detect `ataraid' devices on GNU/kFreeBSD. Fix for ATA devices using + `ata' driver on kernel of FreeBSD 9. + + * util/deviceiter.c [__FreeBSD_kernel__] (get_ada_disk_name) + (get_ataraid_disk_name): New functions. + [__FreeBSD_kernel__] (grub_util_iterate_devices): Scan for ataraid + (/dev/ar[0-9]+) and ada (/dev/ada[0-9]+) devices using + get_ataraid_disk_name() and get_ada_disk_name(). + 2011-06-13 Colin Watson * docs/man/grub-mklayout.h2m (DESCRIPTION): Add a reference to the diff --git a/util/deviceiter.c b/util/deviceiter.c index 30c18beea..2a8acec0e 100644 --- a/util/deviceiter.c +++ b/util/deviceiter.c @@ -1,7 +1,7 @@ /* deviceiter.c - iterate over system devices */ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 1999,2000,2001,2002,2003,2004,2005,2007,2008 Free Software Foundation, Inc. + * Copyright (C) 1999,2000,2001,2002,2003,2004,2005,2007,2008,2011 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -286,6 +286,20 @@ get_scsi_disk_name (char *name, int unit) #endif } +#ifdef __FreeBSD_kernel__ +static void +get_ada_disk_name (char *name, int unit) +{ + sprintf (name, "/dev/ada%d", unit); +} + +static void +get_ataraid_disk_name (char *name, int unit) +{ + sprintf (name, "/dev/ar%d", unit); +} +#endif + #ifdef __linux__ static void get_virtio_disk_name (char *name, int unit) @@ -620,6 +634,35 @@ grub_util_iterate_devices (int NESTED_FUNC_ATTR (*hook) (const char *, int), } } +#ifdef __FreeBSD_kernel__ + /* IDE disks using ATA Direct Access driver. */ + if (get_kfreebsd_version () >= 800000) + for (i = 0; i < 96; i++) + { + char name[16]; + + get_ada_disk_name (name, i); + if (check_device_readable_unique (name)) + { + if (hook (name, 0)) + goto out; + } + } + + /* ATARAID disks. */ + for (i = 0; i < 8; i++) + { + char name[20]; + + get_ataraid_disk_name (name, i); + if (check_device_readable_unique (name)) + { + if (hook (name, 0)) + goto out; + } + } +#endif + #ifdef __linux__ /* Virtio disks. */ for (i = 0; i < 26; i++) From d6d205568f4ea7e6a49cd2ca745a8584d3bbca5d Mon Sep 17 00:00:00 2001 From: "Manoel R. Abranches" Date: Sat, 18 Jun 2011 20:18:25 -0300 Subject: [PATCH 652/869] Close cards before boot. --- grub-core/kern/ieee1275/init.c | 2 ++ grub-core/net/drivers/ieee1275/ofnet.c | 4 ++++ grub-core/net/net.c | 11 +++++++++++ include/grub/net.h | 1 + 4 files changed, 18 insertions(+) diff --git a/grub-core/kern/ieee1275/init.c b/grub-core/kern/ieee1275/init.c index ad34ea188..3c55096a4 100644 --- a/grub-core/kern/ieee1275/init.c +++ b/grub-core/kern/ieee1275/init.c @@ -264,6 +264,8 @@ grub_machine_init (void) void grub_machine_fini (void) { + if (grub_grubnet_fini) + grub_grubnet_fini (); grub_ofdisk_fini (); grub_console_fini (); } diff --git a/grub-core/net/drivers/ieee1275/ofnet.c b/grub-core/net/drivers/ieee1275/ofnet.c index 751583e9d..9789f2261 100644 --- a/grub-core/net/drivers/ieee1275/ofnet.c +++ b/grub-core/net/drivers/ieee1275/ofnet.c @@ -225,6 +225,10 @@ GRUB_MOD_INIT(ofnet) GRUB_MOD_FINI(ofnet) { + struct grub_net_card *card; + FOR_NET_CARDS (card) + if (card->driver && !grub_strcmp (card->driver->name, "ofnet")) + card->driver->fini (card); grub_net_card_driver_unregister (&ofdriver); grub_getbootp = NULL; } diff --git a/grub-core/net/net.c b/grub-core/net/net.c index 380eec3b5..c7732ecbf 100644 --- a/grub-core/net/net.c +++ b/grub-core/net/net.c @@ -1021,6 +1021,15 @@ grub_cmd_dhcpopt (struct grub_command *cmd __attribute__ ((unused)), "unrecognised format specification %s", args[3]); } +static void +grub_grubnet_fini_real (void) +{ + struct grub_net_card *card; + FOR_NET_CARDS (card) + if (card->driver) + card->driver->fini (card); +} + static struct grub_fs grub_net_fs = { .name = "netfs", @@ -1060,6 +1069,7 @@ GRUB_MOD_INIT(net) grub_fs_register (&grub_net_fs); grub_net_open = grub_net_open_real; grub_file_net_seek = grub_net_seek_real; + grub_grubnet_fini = grub_grubnet_fini_real; } GRUB_MOD_FINI(net) @@ -1074,4 +1084,5 @@ GRUB_MOD_FINI(net) grub_fs_unregister (&grub_net_fs); grub_net_open = NULL; grub_file_net_seek = NULL; + grub_grubnet_fini = NULL; } diff --git a/include/grub/net.h b/include/grub/net.h index f9745acec..006ec0686 100644 --- a/include/grub/net.h +++ b/include/grub/net.h @@ -239,6 +239,7 @@ typedef struct grub_net extern grub_net_t (*EXPORT_VAR (grub_net_open)) (const char *name); extern grub_err_t (*EXPORT_VAR (grub_file_net_seek)) (struct grub_file *file, grub_off_t offset); +void (*EXPORT_VAR (grub_grubnet_fini)) (void); struct grub_net_network_level_interface { From d855fbcf37fa97de08952aae80fc5bf704fdf149 Mon Sep 17 00:00:00 2001 From: "Manoel R. Abranches" Date: Sat, 18 Jun 2011 20:20:53 -0300 Subject: [PATCH 653/869] Add error verification in netbuff operations. --- grub-core/net/arp.c | 7 +++++-- grub-core/net/drivers/ieee1275/ofnet.c | 5 ++++- grub-core/net/ethernet.c | 11 ++++++++--- grub-core/net/ip.c | 5 ++++- grub-core/net/netbuff.c | 4 ++-- grub-core/net/tftp.c | 21 ++++++++++++--------- grub-core/net/udp.c | 4 +++- 7 files changed, 38 insertions(+), 19 deletions(-) diff --git a/grub-core/net/arp.c b/grub-core/net/arp.c index 0644d3d2e..6fc7554cd 100644 --- a/grub-core/net/arp.c +++ b/grub-core/net/arp.c @@ -39,6 +39,7 @@ grub_net_arp_resolve (struct grub_net_network_level_interface *inf, struct arphdr *arp_header; grub_net_link_level_address_t target_hw_addr; char *aux, arp_data[128]; + grub_err_t err; int i; /* Check cache table. */ @@ -52,9 +53,11 @@ grub_net_arp_resolve (struct grub_net_network_level_interface *inf, nb.head = arp_data; nb.end = arp_data + sizeof (arp_data); grub_netbuff_clear (&nb); - grub_netbuff_reserve (&nb, 128); - grub_netbuff_push (&nb, sizeof (*arp_header) + 2 * (6 + 4)); + + if ((err = grub_netbuff_push (&nb, sizeof (*arp_header) + 2 * (6 + 4))) != GRUB_ERR_NONE) + return err; + arp_header = (struct arphdr *) nb.data; arp_header->hrd = grub_cpu_to_be16 (GRUB_NET_ARPHRD_ETHERNET); arp_header->pro = grub_cpu_to_be16 (GRUB_NET_ETHERTYPE_IP); diff --git a/grub-core/net/drivers/ieee1275/ofnet.c b/grub-core/net/drivers/ieee1275/ofnet.c index 9789f2261..2c264edb1 100644 --- a/grub-core/net/drivers/ieee1275/ofnet.c +++ b/grub-core/net/drivers/ieee1275/ofnet.c @@ -228,7 +228,10 @@ GRUB_MOD_FINI(ofnet) struct grub_net_card *card; FOR_NET_CARDS (card) if (card->driver && !grub_strcmp (card->driver->name, "ofnet")) - card->driver->fini (card); + { + card->driver->fini (card); + card->driver = NULL; + } grub_net_card_driver_unregister (&ofdriver); grub_getbootp = NULL; } diff --git a/grub-core/net/ethernet.c b/grub-core/net/ethernet.c index d29193afe..d33a07010 100644 --- a/grub-core/net/ethernet.c +++ b/grub-core/net/ethernet.c @@ -15,8 +15,10 @@ send_ethernet_packet (struct grub_net_network_level_interface *inf, grub_uint16_t ethertype) { struct etherhdr *eth; + grub_err_t err; - grub_netbuff_push (nb, sizeof (*eth)); + if ((err = grub_netbuff_push (nb, sizeof (*eth))) != GRUB_ERR_NONE) + return err; eth = (struct etherhdr *) nb->data; grub_memcpy (eth->dst, target_addr.mac, 6); grub_memcpy (eth->src, inf->hwaddress.mac, 6); @@ -33,10 +35,12 @@ grub_net_recv_ethernet_packet (struct grub_net_buff *nb) struct llchdr *llch; struct snaphdr *snaph; grub_uint16_t type; + grub_err_t err; eth = (struct etherhdr *) nb->data; type = grub_be_to_cpu16 (eth->type); - grub_netbuff_pull (nb, sizeof (*eth)); + if ((err = grub_netbuff_pull (nb, sizeof (*eth))) != GRUB_ERR_NONE) + return err; if (type <= 1500) { @@ -45,7 +49,8 @@ grub_net_recv_ethernet_packet (struct grub_net_buff *nb) if (llch->dsap == 0xaa && llch->ssap == 0xaa && llch->ctrl == 0x3) { - grub_netbuff_pull (nb, sizeof (*llch)); + if ((err = grub_netbuff_pull (nb, sizeof (*llch))) != GRUB_ERR_NONE) + return err; snaph = (struct snaphdr *) nb->data; type = snaph->type; } diff --git a/grub-core/net/ip.c b/grub-core/net/ip.c index 4adc2b028..749b41d02 100644 --- a/grub-core/net/ip.c +++ b/grub-core/net/ip.c @@ -85,7 +85,10 @@ grub_err_t grub_net_recv_ip_packets (struct grub_net_buff *nb) { struct iphdr *iph = (struct iphdr *) nb->data; - grub_netbuff_pull (nb, sizeof (*iph)); + grub_err_t err; + + if ((err = grub_netbuff_pull (nb, sizeof (*iph))) != GRUB_ERR_NONE) + return err; switch (iph->protocol) { diff --git a/grub-core/net/netbuff.c b/grub-core/net/netbuff.c index aae2f4d8f..d20104ab0 100644 --- a/grub-core/net/netbuff.c +++ b/grub-core/net/netbuff.c @@ -95,12 +95,12 @@ grub_err_t grub_netbuff_free (struct grub_net_buff *nb) { grub_free (nb->head); - return 0; + return GRUB_ERR_NONE; } grub_err_t grub_netbuff_clear (struct grub_net_buff *nb) { nb->data = nb->tail = nb->head; - return 0; + return GRUB_ERR_NONE; } diff --git a/grub-core/net/tftp.c b/grub-core/net/tftp.c index ac3b3e9db..138020b08 100644 --- a/grub-core/net/tftp.c +++ b/grub-core/net/tftp.c @@ -34,7 +34,8 @@ tftp_open (struct grub_file *file, const char *filename) grub_netbuff_clear (&nb); grub_netbuff_reserve (&nb, 1500); - grub_netbuff_push (&nb, sizeof (*tftph)); + if ((err = grub_netbuff_push (&nb, sizeof (*tftph))) != GRUB_ERR_NONE) + return err; tftph = (struct tftphdr *) nb.data; @@ -67,8 +68,8 @@ tftp_open (struct grub_file *file, const char *filename) rrq += grub_strlen ("0") + 1; hdrlen = sizeof (tftph->opcode) + rrqlen; - grub_netbuff_unput (&nb, nb.tail - (nb.data + hdrlen)); - + if ((err = grub_netbuff_unput (&nb, nb.tail - (nb.data + hdrlen))) != GRUB_ERR_NONE) + return err; file->device->net->socket->out_port = TFTP_SERVER_PORT; err = grub_net_send_udp_packet (file->device->net->socket, &nb); @@ -130,9 +131,9 @@ tftp_receive (grub_net_socket_t sock, struct grub_net_buff *nb) grub_netbuff_clear (nb); break; case TFTP_DATA: - grub_netbuff_pull (nb, sizeof (tftph->opcode) + - sizeof (tftph->u.data.block)); - + if ((err = grub_netbuff_pull (nb, sizeof (tftph->opcode) + + sizeof (tftph->u.data.block))) != GRUB_ERR_NONE) + return err; if (grub_be_to_cpu16 (tftph->u.data.block) == data->block + 1) { data->block++; @@ -141,7 +142,8 @@ tftp_receive (grub_net_socket_t sock, struct grub_net_buff *nb) sock->status = 2; /* Prevent garbage in broken cards. */ if (size > 1024) - grub_netbuff_unput (nb, size - 1024); + if ((err = grub_netbuff_unput (nb, size - 1024)) != GRUB_ERR_NONE) + return err; } else grub_netbuff_clear (nb); @@ -154,8 +156,9 @@ tftp_receive (grub_net_socket_t sock, struct grub_net_buff *nb) } grub_netbuff_clear (&nb_ack); grub_netbuff_reserve (&nb_ack, 128); - grub_netbuff_push (&nb_ack, sizeof (tftph->opcode) - + sizeof (tftph->u.ack.block)); + if ((err = grub_netbuff_push (&nb_ack, sizeof (tftph->opcode) + + sizeof (tftph->u.ack.block))) != GRUB_ERR_NONE) + return err; tftph = (struct tftphdr *) nb_ack.data; tftph->opcode = grub_cpu_to_be16 (TFTP_ACK); diff --git a/grub-core/net/udp.c b/grub-core/net/udp.c index 86220bf0f..b070cbb64 100644 --- a/grub-core/net/udp.c +++ b/grub-core/net/udp.c @@ -9,8 +9,10 @@ grub_net_send_udp_packet (const grub_net_socket_t socket, struct grub_net_buff *nb) { struct udphdr *udph; + grub_err_t err; - grub_netbuff_push (nb, sizeof (*udph)); + if ((err = grub_netbuff_push (nb, sizeof (*udph))) != GRUB_ERR_NONE) + return err; udph = (struct udphdr *) nb->data; udph->src = grub_cpu_to_be16 (socket->in_port); From 77ba5392d0e482de3618c00129c7bc2a35691cce Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Thu, 23 Jun 2011 08:45:12 +0200 Subject: [PATCH 654/869] New testload grub-fstest command --- Makefile.util.def | 1 + util/grub-fstest.c | 11 ++++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/Makefile.util.def b/Makefile.util.def index 829b16fac..1fcd9465e 100644 --- a/Makefile.util.def +++ b/Makefile.util.def @@ -34,6 +34,7 @@ library = { common_nodist = grub_script.tab.h; common = grub-core/commands/blocklist.c; + common = grub-core/commands/testload.c; common = grub-core/commands/extcmd.c; common = grub-core/commands/ls.c; common = grub-core/disk/dmraid_nvidia.c; diff --git a/util/grub-fstest.c b/util/grub-fstest.c index f253a96f6..c2c8b1148 100644 --- a/util/grub-fstest.c +++ b/util/grub-fstest.c @@ -61,7 +61,8 @@ enum { CMD_CMP, CMD_HEX, CMD_CRC, - CMD_BLOCKLIST + CMD_BLOCKLIST, + CMD_TESTLOAD }; #define BUF_SIZE 32256 @@ -359,6 +360,9 @@ fstest (int n, char **args) case CMD_BLOCKLIST: execute_command ("blocklist", n, args); grub_printf ("\n"); + case CMD_TESTLOAD: + execute_command ("testload", n, args); + grub_printf ("\n"); } for (i = 0; i < num_disks; i++) @@ -520,6 +524,11 @@ argp_parser (int key, char *arg, struct argp_state *state) cmd = CMD_BLOCKLIST; nparm = 1; } + else if (!grub_strcmp (arg, "testload")) + { + cmd = CMD_TESTLOAD; + nparm = 1; + } else { fprintf (stderr, _("Invalid command %s.\n"), arg); From 2df2e89fee627a098b0192a526a2b6999699211c Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Thu, 23 Jun 2011 09:39:12 +0200 Subject: [PATCH 655/869] Fixed a cache collision bug. Thanks guufy1 for bugreport and test --- grub-core/kern/disk.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/grub-core/kern/disk.c b/grub-core/kern/disk.c index 30bc604f0..f1456defd 100644 --- a/grub-core/kern/disk.c +++ b/grub-core/kern/disk.c @@ -544,6 +544,17 @@ grub_disk_read (grub_disk_t disk, grub_disk_addr_t sector, break; } + if (data) + { + grub_memcpy ((char *) buf + + (agglomerate << (GRUB_DISK_CACHE_BITS + + GRUB_DISK_SECTOR_BITS)), + data, GRUB_DISK_CACHE_SIZE << GRUB_DISK_SECTOR_BITS); + grub_disk_cache_unlock (disk->dev->id, disk->id, + sector + (agglomerate + << GRUB_DISK_CACHE_BITS)); + } + if (agglomerate) { grub_disk_addr_t i; @@ -568,17 +579,12 @@ grub_disk_read (grub_disk_t disk, grub_disk_addr_t sector, buf = (char *) buf + (agglomerate << (GRUB_DISK_CACHE_BITS + GRUB_DISK_SECTOR_BITS)); } - + if (data) { - grub_memcpy (buf, data, - GRUB_DISK_CACHE_SIZE << GRUB_DISK_SECTOR_BITS); sector += GRUB_DISK_CACHE_SIZE; buf = (char *) buf + (GRUB_DISK_CACHE_SIZE << GRUB_DISK_SECTOR_BITS); size -= (GRUB_DISK_CACHE_SIZE << GRUB_DISK_SECTOR_BITS); - grub_disk_cache_unlock (disk->dev->id, disk->id, - sector + (agglomerate - << GRUB_DISK_CACHE_BITS)); } } From 8a5d6919e169d5839c474a5c0e8d8ed6b492fef1 Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Thu, 23 Jun 2011 18:08:53 +0200 Subject: [PATCH 656/869] Avoid NULL deref in grub_device_open. * grub-core/kern/device.c (grub_device_open): Don't dereference a NULL pointer upon failed grub_env_get. --- ChangeLog | 6 ++++++ grub-core/kern/device.c | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index e3ed5d13a..a7f6ce738 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2011-06-23 Jim Meyering + + avoid NULL deref in grub_device_open + * grub-core/kern/device.c (grub_device_open): Don't dereference + a NULL pointer upon failed grub_env_get. + 2011-06-23 Vladimir Serbinenko Support non-512B sectors and agglomerate reads. diff --git a/grub-core/kern/device.c b/grub-core/kern/device.c index 3db14f50e..50f49ae6b 100644 --- a/grub-core/kern/device.c +++ b/grub-core/kern/device.c @@ -35,7 +35,7 @@ grub_device_open (const char *name) if (! name) { name = grub_env_get ("root"); - if (*name == '\0') + if (name == NULL || *name == '\0') { grub_error (GRUB_ERR_BAD_DEVICE, "no device is set"); goto fail; From e2d1dba0ae8d87c9f9fc8ecbb4b10243507b2615 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Thu, 23 Jun 2011 19:50:41 +0200 Subject: [PATCH 657/869] * grub-core/kern/emu/getroot.c (grub_guess_root_device): Don't accept /dev/root as a valid device. --- ChangeLog | 8 +++++++- grub-core/kern/emu/getroot.c | 6 ++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index a7f6ce738..0ea09a0ab 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,12 @@ +2011-06-23 Vladimir Serbinenko + + * grub-core/kern/emu/getroot.c (grub_guess_root_device): Don't accept + /dev/root as a valid device. + 2011-06-23 Jim Meyering - avoid NULL deref in grub_device_open + Avoid NULL deref in grub_device_open. + * grub-core/kern/device.c (grub_device_open): Don't dereference a NULL pointer upon failed grub_env_get. diff --git a/grub-core/kern/emu/getroot.c b/grub-core/kern/emu/getroot.c index 6e49cc31b..db27abf74 100644 --- a/grub-core/kern/emu/getroot.c +++ b/grub-core/kern/emu/getroot.c @@ -616,13 +616,15 @@ grub_guess_root_device (const char *dir) if (os_dev) { - if (strncmp (os_dev, "/dev/dm-", sizeof ("/dev/dm-") - 1) != 0) + int dm = (strncmp (os_dev, "/dev/dm-", sizeof ("/dev/dm-") - 1) == 0); + int root = (strcmp (os_dev, "/dev/root") == 0); + if (!dm && !root) return os_dev; if (stat (os_dev, &st) < 0) grub_util_error ("cannot stat `%s'", os_dev); free (os_dev); dev = st.st_rdev; - return grub_find_device ("/dev/mapper", dev); + return grub_find_device (dm ? "/dev/mapper" : "/dev", dev); } if (stat (dir, &st) < 0) From a199a8cd1a5d01847e21bb40f21e044f4d728244 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Thu, 23 Jun 2011 20:05:39 +0200 Subject: [PATCH 658/869] Fix spurious warning. * grub-core/partmap/acorn.c (grub_acorn_boot_block): Make a union. (acorn_partition_map_find): Use .bin member. --- ChangeLog | 7 +++++++ grub-core/partmap/acorn.c | 19 +++++++++++++------ 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index 0ea09a0ab..a455d9b6b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2011-06-23 Vladimir Serbinenko + + Fix spurious warning. + + * grub-core/partmap/acorn.c (grub_acorn_boot_block): Make a union. + (acorn_partition_map_find): Use .bin member. + 2011-06-23 Vladimir Serbinenko * grub-core/kern/emu/getroot.c (grub_guess_root_device): Don't accept diff --git a/grub-core/partmap/acorn.c b/grub-core/partmap/acorn.c index 9a68ddd92..341b8ac5f 100644 --- a/grub-core/partmap/acorn.c +++ b/grub-core/partmap/acorn.c @@ -34,11 +34,18 @@ GRUB_MOD_LICENSE ("GPLv3+"); struct grub_acorn_boot_block { - grub_uint8_t misc[0x1C0]; - struct grub_filecore_disc_record disc_record; - grub_uint8_t flags; - grub_uint16_t start_cylinder; - grub_uint8_t checksum; + union + { + struct + { + grub_uint8_t misc[0x1C0]; + struct grub_filecore_disc_record disc_record; + grub_uint8_t flags; + grub_uint16_t start_cylinder; + grub_uint8_t checksum; + } __attribute__ ((packed, aligned)); + grub_uint8_t bin[0x200]; + }; } __attribute__ ((packed, aligned)); struct linux_part @@ -71,7 +78,7 @@ acorn_partition_map_find (grub_disk_t disk, struct linux_part *m, goto fail; for (i = 0; i != 0x1ff; ++i) - checksum = (checksum & 0xff) + (checksum >> 8) + boot.misc[i]; + checksum = ((checksum & 0xff) + (checksum >> 8) + boot.bin[i]); if ((grub_uint8_t) checksum != boot.checksum) goto fail; From e98c83e910e7fd3e39dd021213d111526e80775c Mon Sep 17 00:00:00 2001 From: David Volgyes Date: Thu, 23 Jun 2011 20:28:04 +0200 Subject: [PATCH 659/869] * grub-core/bus/usb/ohci.c (grub_ohci_pci_iter): Avoid NULL-pointer dereference. --- ChangeLog | 5 +++++ grub-core/bus/usb/ohci.c | 10 ++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index a455d9b6b..ad72c8da2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-06-23 David Volgyes + + * grub-core/bus/usb/ohci.c (grub_ohci_pci_iter): Avoid NULL-pointer + dereference. + 2011-06-23 Vladimir Serbinenko Fix spurious warning. diff --git a/grub-core/bus/usb/ohci.c b/grub-core/bus/usb/ohci.c index df0d0f4af..7e8eaaac2 100644 --- a/grub-core/bus/usb/ohci.c +++ b/grub-core/bus/usb/ohci.c @@ -454,10 +454,12 @@ grub_ohci_pci_iter (grub_pci_device_t dev, fail: if (o) - grub_dma_free (o->td_chunk); - grub_dma_free (o->ed_bulk_chunk); - grub_dma_free (o->ed_ctrl_chunk); - grub_dma_free (o->hcca_chunk); + { + grub_dma_free (o->td_chunk); + grub_dma_free (o->ed_bulk_chunk); + grub_dma_free (o->ed_ctrl_chunk); + grub_dma_free (o->hcca_chunk); + } grub_free (o); return 0; From fbc626665f458d60cc3d19e1e8eedb68638cb4dc Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Thu, 23 Jun 2011 20:38:19 +0200 Subject: [PATCH 660/869] * grub-core/loader/i386/xnu.c (grub_cpu_xnu_fill_devprop): Don't attempt to continue if allocation is failed. Reported by: David Volgyes . --- ChangeLog | 7 +++++++ grub-core/loader/i386/xnu.c | 10 +++++----- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index ad72c8da2..66c55d101 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2011-06-23 Vladimir Serbinenko + + * grub-core/loader/i386/xnu.c (grub_cpu_xnu_fill_devprop): Don't attempt + to continue if allocation is failed. + + Reported by: David Volgyes . + 2011-06-23 David Volgyes * grub-core/bus/usb/ohci.c (grub_ohci_pci_iter): Avoid NULL-pointer diff --git a/grub-core/loader/i386/xnu.c b/grub-core/loader/i386/xnu.c index b877b0ea5..6128ec384 100644 --- a/grub-core/loader/i386/xnu.c +++ b/grub-core/loader/i386/xnu.c @@ -452,11 +452,11 @@ grub_cpu_xnu_fill_devprop (void) } devprop = grub_xnu_create_value (&(efikey->first_child), "device-properties"); - if (devprop) - { - devprop->data = grub_malloc (total_length); - devprop->datasize = total_length; - } + if (!devprop) + return grub_errno; + + devprop->data = grub_malloc (total_length); + devprop->datasize = total_length; ptr = devprop->data; head = ptr; From 1abe47dc9935106c0079d0e50388d2c6168864a5 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Thu, 23 Jun 2011 20:55:36 +0200 Subject: [PATCH 661/869] * grub-core/lib/reed_solomon.c (rs_recover): Prevent memory leak. (main): Close file. --- ChangeLog | 5 +++++ grub-core/lib/reed_solomon.c | 25 +++++++++++++++++-------- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index 66c55d101..c267a8a0f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-06-23 Vladimir Serbinenko + + * grub-core/lib/reed_solomon.c (rs_recover): Prevent memory leak. + (main): Close file. + 2011-06-23 Vladimir Serbinenko * grub-core/loader/i386/xnu.c (grub_cpu_xnu_fill_devprop): Don't attempt diff --git a/grub-core/lib/reed_solomon.c b/grub-core/lib/reed_solomon.c index e500ba32d..8b5e8235a 100644 --- a/grub-core/lib/reed_solomon.c +++ b/grub-core/lib/reed_solomon.c @@ -265,6 +265,22 @@ rs_recover (gf_single_t *m, grub_size_t s, grub_size_t rs) syndroms (m, s, rs, sy); + for (i = 0; i < (int) rs; i++) + if (sy[i] != 0) + break; + + /* No error detected. */ + if (i == (int) rs) + { +#ifndef STANDALONE + free (sigma); + free (errpot); + free (errpos); + free (sy); +#endif + return; + } + { gf_single_t *eq; @@ -275,14 +291,6 @@ rs_recover (gf_single_t *m, grub_size_t s, grub_size_t rs) scratch += rs2 * (rs2 + 1) * sizeof (gf_single_t); #endif - for (i = 0; i < (int) rs; i++) - if (sy[i] != 0) - break; - - /* No error detected. */ - if (i == (int) rs) - return; - for (i = 0; i < (int) rs2; i++) for (j = 0; j < (int) rs2 + 1; j++) eq[i * (rs2 + 1) + j] = sy[i+j]; @@ -504,6 +512,7 @@ main (int argc, char **argv) rs = s / 3; buf = xmalloc (s + rs + SECTOR_SIZE); fread (buf, 1, s, in); + fclose (in); grub_reed_solomon_add_redundancy (buf, s, rs); From e061a1b537b1f8b719bfa69c49bdf39877fdf4d7 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Thu, 23 Jun 2011 20:58:35 +0200 Subject: [PATCH 662/869] * grub-core/lib/reed_solomon.c (rs_recover) [STANDALONE]: Prevent memory leak. --- ChangeLog | 6 ++++++ grub-core/lib/reed_solomon.c | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/ChangeLog b/ChangeLog index c267a8a0f..327b52afc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,7 +1,13 @@ +2011-06-23 Vladimir Serbinenko + + * grub-core/lib/reed_solomon.c (rs_recover) [STANDALONE]: + Prevent memory leak. + 2011-06-23 Vladimir Serbinenko * grub-core/lib/reed_solomon.c (rs_recover): Prevent memory leak. (main): Close file. + Reported by: David Volgyes . 2011-06-23 Vladimir Serbinenko diff --git a/grub-core/lib/reed_solomon.c b/grub-core/lib/reed_solomon.c index 8b5e8235a..365b76003 100644 --- a/grub-core/lib/reed_solomon.c +++ b/grub-core/lib/reed_solomon.c @@ -277,6 +277,11 @@ rs_recover (gf_single_t *m, grub_size_t s, grub_size_t rs) free (errpot); free (errpos); free (sy); +#else + scratch -= rs2 * sizeof (gf_single_t); + scratch -= rs2 * sizeof (gf_single_t); + scratch -= rs2 * sizeof (int); + scratch -= rs * sizeof (gf_single_t); #endif return; } From 13548d26e9492450da911aa5b7c5d9e6850cb327 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Thu, 23 Jun 2011 21:06:50 +0200 Subject: [PATCH 663/869] * util/raid.c (grub_util_raid_getmembers): Close fd before returning. Reported by: David Volgyes . --- ChangeLog | 6 ++++++ util/raid.c | 2 ++ 2 files changed, 8 insertions(+) diff --git a/ChangeLog b/ChangeLog index 327b52afc..058116fbb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2011-06-23 Vladimir Serbinenko + + * util/raid.c (grub_util_raid_getmembers): Close fd before returning. + + Reported by: David Volgyes . + 2011-06-23 Vladimir Serbinenko * grub-core/lib/reed_solomon.c (rs_recover) [STANDALONE]: diff --git a/util/raid.c b/util/raid.c index a6aa5f95e..c1c32b959 100644 --- a/util/raid.c +++ b/util/raid.c @@ -80,6 +80,8 @@ grub_util_raid_getmembers (const char *name) devicelist[j] = NULL; + close (fd); + return devicelist; } From cad3237fb5ecf1a21f9e1bad957942a0cac8d6cc Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Thu, 23 Jun 2011 22:02:05 +0200 Subject: [PATCH 664/869] * grub-core/kern/emu/hostdisk.c (grub_util_biosdisk_is_floppy): Close file after stat. Reported by: David Volgyes . --- ChangeLog | 6 ++++++ grub-core/kern/emu/hostdisk.c | 7 ++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 058116fbb..abe285ee9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2011-06-23 Vladimir Serbinenko + + * grub-core/kern/emu/hostdisk.c (grub_util_biosdisk_is_floppy): Close + file after stat. + Reported by: David Volgyes . + 2011-06-23 Vladimir Serbinenko * util/raid.c (grub_util_raid_getmembers): Close fd before returning. diff --git a/grub-core/kern/emu/hostdisk.c b/grub-core/kern/emu/hostdisk.c index e53a39c39..f4af73858 100644 --- a/grub-core/kern/emu/hostdisk.c +++ b/grub-core/kern/emu/hostdisk.c @@ -1866,7 +1866,12 @@ grub_util_biosdisk_is_floppy (grub_disk_t disk) /* Shouldn't happen either. */ if (fstat (fd, &st) < 0) - return 0; + { + close (fd); + return 0; + } + + close (fd); #if defined(__NetBSD__) if (major(st.st_rdev) == RAW_FLOPPY_MAJOR) From 03147f46671e2270ef4849a710b20572462844ac Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Thu, 23 Jun 2011 22:11:42 +0200 Subject: [PATCH 665/869] * util/grub-mkpasswd-pbkdf2.c (main): Don't double-close. Reported by: David Volgyes . --- ChangeLog | 5 +++++ util/grub-mkpasswd-pbkdf2.c | 1 - 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index abe285ee9..59cb3ec57 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-06-23 Vladimir Serbinenko + + * util/grub-mkpasswd-pbkdf2.c (main): Don't double-close. + Reported by: David Volgyes . + 2011-06-23 Vladimir Serbinenko * grub-core/kern/emu/hostdisk.c (grub_util_biosdisk_is_floppy): Close diff --git a/util/grub-mkpasswd-pbkdf2.c b/util/grub-mkpasswd-pbkdf2.c index dc2afdb6e..709ba7da7 100644 --- a/util/grub-mkpasswd-pbkdf2.c +++ b/util/grub-mkpasswd-pbkdf2.c @@ -270,7 +270,6 @@ main (int argc, char *argv[]) free (bufhex); free (salthex); free (salt); - fclose (f); grub_util_error ("couldn't retrieve random data for salt"); } fclose (f); From fe12fd5b439956ab5354dde8699870cb0fd7c8bd Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Thu, 23 Jun 2011 22:18:31 +0200 Subject: [PATCH 666/869] * util/ieee1275/ofpath.c (check_sas): Close fd. (main): Free of_path. Reported by: David Volgyes . --- ChangeLog | 6 ++++++ util/ieee1275/ofpath.c | 2 ++ 2 files changed, 8 insertions(+) diff --git a/ChangeLog b/ChangeLog index 59cb3ec57..062f66c00 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2011-06-23 Vladimir Serbinenko + + * util/ieee1275/ofpath.c (check_sas): Close fd. + (main): Free of_path. + Reported by: David Volgyes . + 2011-06-23 Vladimir Serbinenko * util/grub-mkpasswd-pbkdf2.c (main): Don't double-close. diff --git a/util/ieee1275/ofpath.c b/util/ieee1275/ofpath.c index 1a433345d..f72bea8a5 100644 --- a/util/ieee1275/ofpath.c +++ b/util/ieee1275/ofpath.c @@ -297,6 +297,7 @@ check_sas (char *sysfs_path, int *tgt) free (path); free (p); + close (fd); } static void @@ -419,6 +420,7 @@ int main(int argc, char **argv) of_path = grub_util_devname_to_ofpath (argv[1]); printf("%s\n", of_path); + free (of_path); return 0; } From c31dc5f5e4291e2aa7fb9fbf5ed88640fb05cc83 Mon Sep 17 00:00:00 2001 From: Szymon Janc Date: Thu, 23 Jun 2011 23:13:20 +0200 Subject: [PATCH 667/869] Add support for DRI and RSTn markers in JPEG files. * grub-core/video/readers/jpeg.c (JPEG_MARKER_DRI): New define. (JPEG_MARKER_RST0): Likewise. (JPEG_MARKER_RST1): Likewise. (JPEG_MARKER_RST2): Likewise. (JPEG_MARKER_RST3): Likewise. (JPEG_MARKER_RST4): Likewise. (JPEG_MARKER_RST5): Likewise. (JPEG_MARKER_RST6): Likewise. (JPEG_MARKER_RST7): Likewise. (grub_jpeg_data): New fields dri, r1, bitmap_ptr. (grub_jpeg_decode_dri): New function. (grub_jpeg_decode_sos): Move image data related part into grub_jpeg_decode_data function. (grub_jpeg_decode_data): New function. (grub_jpeg_reset): New function. (grub_jpeg_decode_jpeg): Handle new markers. --- ChangeLog | 21 +++++++++ grub-core/video/readers/jpeg.c | 78 ++++++++++++++++++++++++++++------ 2 files changed, 87 insertions(+), 12 deletions(-) diff --git a/ChangeLog b/ChangeLog index 062f66c00..655cbe25e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,24 @@ +2011-06-23 Szymon Janc + + Add support for DRI and RSTn markers in JPEG files. + + * grub-core/video/readers/jpeg.c (JPEG_MARKER_DRI): New define. + (JPEG_MARKER_RST0): Likewise. + (JPEG_MARKER_RST1): Likewise. + (JPEG_MARKER_RST2): Likewise. + (JPEG_MARKER_RST3): Likewise. + (JPEG_MARKER_RST4): Likewise. + (JPEG_MARKER_RST5): Likewise. + (JPEG_MARKER_RST6): Likewise. + (JPEG_MARKER_RST7): Likewise. + (grub_jpeg_data): New fields dri, r1, bitmap_ptr. + (grub_jpeg_decode_dri): New function. + (grub_jpeg_decode_sos): Move image data related part into + grub_jpeg_decode_data function. + (grub_jpeg_decode_data): New function. + (grub_jpeg_reset): New function. + (grub_jpeg_decode_jpeg): Handle new markers. + 2011-06-23 Vladimir Serbinenko * util/ieee1275/ofpath.c (check_sas): Close fd. diff --git a/grub-core/video/readers/jpeg.c b/grub-core/video/readers/jpeg.c index 8cdb2f61d..d61c90ec9 100644 --- a/grub-core/video/readers/jpeg.c +++ b/grub-core/video/readers/jpeg.c @@ -39,6 +39,15 @@ GRUB_MOD_LICENSE ("GPLv3+"); #define JPEG_MARKER_DQT 0xdb #define JPEG_MARKER_SOF0 0xc0 #define JPEG_MARKER_SOS 0xda +#define JPEG_MARKER_DRI 0xdd +#define JPEG_MARKER_RST0 0xd0 +#define JPEG_MARKER_RST1 0xd1 +#define JPEG_MARKER_RST2 0xd2 +#define JPEG_MARKER_RST3 0xd3 +#define JPEG_MARKER_RST4 0xd4 +#define JPEG_MARKER_RST5 0xd5 +#define JPEG_MARKER_RST6 0xd6 +#define JPEG_MARKER_RST7 0xd7 #define SHIFT_BITS 8 #define CONST(x) ((int) ((x) * (1L << SHIFT_BITS) + 0.5)) @@ -66,6 +75,7 @@ struct grub_jpeg_data { grub_file_t file; struct grub_video_bitmap **bitmap; + grub_uint8_t *bitmap_ptr; int image_width; int image_height; @@ -82,6 +92,8 @@ struct grub_jpeg_data jpeg_data_unit_t cbdu; int vs, hs; + int dri; + int r1; int dc_value[3]; @@ -315,6 +327,18 @@ grub_jpeg_decode_sof (struct grub_jpeg_data *data) return grub_errno; } +static grub_err_t +grub_jpeg_decode_dri (struct grub_jpeg_data *data) +{ + if (grub_jpeg_get_word (data) != 4) + return grub_error (GRUB_ERR_BAD_FILE_TYPE, + "jpeg: DRI marker length must be 4"); + + data->dri = grub_jpeg_get_word (data); + + return grub_errno; +} + static void grub_jpeg_idct_transform (jpeg_data_unit_t du) { @@ -526,8 +550,7 @@ grub_jpeg_ycrcb_to_rgb (int yy, int cr, int cb, grub_uint8_t * rgb) static grub_err_t grub_jpeg_decode_sos (struct grub_jpeg_data *data) { - int i, cc, r1, c1, nr1, nc1, vb, hb; - grub_uint8_t *ptr1; + int i, cc; grub_uint32_t data_offset; data_offset = data->file->offset; @@ -563,17 +586,25 @@ grub_jpeg_decode_sos (struct grub_jpeg_data *data) GRUB_VIDEO_BLIT_FORMAT_RGB_888)) return grub_errno; - data->bit_mask = 0x0; + data->bitmap_ptr = (*data->bitmap)->data; + return GRUB_ERR_NONE; +} + +static grub_err_t +grub_jpeg_decode_data (struct grub_jpeg_data *data) +{ + int c1, vb, hb, nr1, nc1; + int rst = data->dri; vb = data->vs * 8; hb = data->hs * 8; nr1 = (data->image_height + vb - 1) / vb; nc1 = (data->image_width + hb - 1) / hb; - ptr1 = (*data->bitmap)->data; - for (r1 = 0; r1 < nr1; - r1++, ptr1 += (vb * data->image_width - hb * nc1) * 3) - for (c1 = 0; c1 < nc1; c1++, ptr1 += hb * 3) + for (; data->r1 < nr1 && (!data->dri || rst); + data->r1++, data->bitmap_ptr += (vb * data->image_width - hb * nc1) * 3) + for (c1 = 0; c1 < nc1 && (!data->dri || rst); + c1++, rst--, data->bitmap_ptr += hb * 3) { int r2, c2, nr2, nc2; grub_uint8_t *ptr2; @@ -588,10 +619,10 @@ grub_jpeg_decode_sos (struct grub_jpeg_data *data) if (grub_errno) return grub_errno; - nr2 = (r1 == nr1 - 1) ? (data->image_height - r1 * vb) : vb; + nr2 = (data->r1 == nr1 - 1) ? (data->image_height - data->r1 * vb) : vb; nc2 = (c1 == nc1 - 1) ? (data->image_width - c1 * hb) : hb; - ptr2 = ptr1; + ptr2 = data->bitmap_ptr; for (r2 = 0; r2 < nr2; r2++, ptr2 += (data->image_width - nc2) * 3) for (c2 = 0; c2 < nc2; c2++, ptr2 += 3) { @@ -600,8 +631,7 @@ grub_jpeg_decode_sos (struct grub_jpeg_data *data) i0 = (r2 / data->vs) * 8 + (c2 / data->hs); cr = data->crdu[i0]; cb = data->cbdu[i0]; - yy = - data->ydu[(r2 / 8) * 2 + (c2 / 8)][(r2 % 8) * 8 + (c2 % 8)]; + yy = data->ydu[(r2 / 8) * 2 + (c2 / 8)][(r2 % 8) * 8 + (c2 % 8)]; grub_jpeg_ycrcb_to_rgb (yy, cr, cb, ptr2); } @@ -610,6 +640,16 @@ grub_jpeg_decode_sos (struct grub_jpeg_data *data) return grub_errno; } +static void +grub_jpeg_reset (struct grub_jpeg_data *data) +{ + data->bit_mask = 0x0; + + data->dc_value[0] = 0; + data->dc_value[1] = 0; + data->dc_value[2] = 0; +} + static grub_uint8_t grub_jpeg_get_marker (struct grub_jpeg_data *data) { @@ -655,8 +695,22 @@ grub_jpeg_decode_jpeg (struct grub_jpeg_data *data) case JPEG_MARKER_SOF0: /* Start Of Frame 0. */ grub_jpeg_decode_sof (data); break; + case JPEG_MARKER_DRI: /* Define Restart Interval. */ + grub_jpeg_decode_dri (data); + break; case JPEG_MARKER_SOS: /* Start Of Scan. */ - grub_jpeg_decode_sos (data); + if (grub_jpeg_decode_sos (data)) + break; + case JPEG_MARKER_RST0: /* Restart. */ + case JPEG_MARKER_RST1: + case JPEG_MARKER_RST2: + case JPEG_MARKER_RST3: + case JPEG_MARKER_RST4: + case JPEG_MARKER_RST5: + case JPEG_MARKER_RST6: + case JPEG_MARKER_RST7: + grub_jpeg_decode_data (data); + grub_jpeg_reset (data); break; case JPEG_MARKER_EOI: /* End Of Image. */ return grub_errno; From 005dd67cb68ece8ea1af43c5c11096d0d32614ea Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 24 Jun 2011 00:29:21 +0200 Subject: [PATCH 668/869] * grub-core/disk/ahci.c: Add missing license statements. * grub-core/fs/romfs.c: Likewise. * grub-core/lib/ia64/setjmp.S: Likewise. * grub-core/loader/i386/pc/freedos.c: Likewise. * grub-core/loader/ia64/efi/linux.c: Likewise. * grub-core/video/colors.c: Likewise. * include/grub/dl.h (GRUB_MOD_DEP): New macro. --- grub-core/disk/ahci.c | 2 ++ grub-core/fs/romfs.c | 2 ++ grub-core/lib/ia64/setjmp.S | 6 ++++++ grub-core/loader/i386/pc/freedos.c | 2 ++ grub-core/loader/ia64/efi/linux.c | 2 ++ grub-core/video/colors.c | 3 +++ include/grub/dl.h | 3 +++ 7 files changed, 20 insertions(+) diff --git a/grub-core/disk/ahci.c b/grub-core/disk/ahci.c index 699df767c..0f355aa53 100644 --- a/grub-core/disk/ahci.c +++ b/grub-core/disk/ahci.c @@ -27,6 +27,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + struct grub_ahci_cmd_head { grub_uint32_t config; diff --git a/grub-core/fs/romfs.c b/grub-core/fs/romfs.c index 07632e635..58dc98f34 100644 --- a/grub-core/fs/romfs.c +++ b/grub-core/fs/romfs.c @@ -24,6 +24,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + struct grub_romfs_superblock { char magic[8]; diff --git a/grub-core/lib/ia64/setjmp.S b/grub-core/lib/ia64/setjmp.S index 0851885c5..190623d35 100644 --- a/grub-core/lib/ia64/setjmp.S +++ b/grub-core/lib/ia64/setjmp.S @@ -64,6 +64,12 @@ 0x1b0 f30 0x1c0 f31 */ +#include +#include + + .file "setjmp.S" + +GRUB_MOD_LICENSE ("GPLv2+") /* The following two entry points are the traditional entry points: */ diff --git a/grub-core/loader/i386/pc/freedos.c b/grub-core/loader/i386/pc/freedos.c index 0ae815490..f796e08f4 100644 --- a/grub-core/loader/i386/pc/freedos.c +++ b/grub-core/loader/i386/pc/freedos.c @@ -33,6 +33,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + static grub_dl_t my_mod; static struct grub_relocator *rel; static grub_uint32_t ebx = 0xffffffff; diff --git a/grub-core/loader/ia64/efi/linux.c b/grub-core/loader/ia64/efi/linux.c index b018e4549..247eebae5 100644 --- a/grub-core/loader/ia64/efi/linux.c +++ b/grub-core/loader/ia64/efi/linux.c @@ -31,6 +31,8 @@ #include #include +GRUB_MOD_LICENSE ("GPLv3+"); + #define ALIGN_MIN (256*1024*1024) #define GRUB_ELF_SEARCH 1024 diff --git a/grub-core/video/colors.c b/grub-core/video/colors.c index 0637c5508..3119c0249 100644 --- a/grub-core/video/colors.c +++ b/grub-core/video/colors.c @@ -21,6 +21,9 @@ #include #include #include +#include + +GRUB_MOD_LICENSE ("GPLv3+"); struct named_color { diff --git a/include/grub/dl.h b/include/grub/dl.h index 5ce01199c..75cd71758 100644 --- a/include/grub/dl.h +++ b/include/grub/dl.h @@ -90,6 +90,9 @@ static const char grub_module_name_##name[] \ #ifndef ASM_FILE #define GRUB_MOD_LICENSE(license) \ static char grub_module_license[] __attribute__ ((section (GRUB_MOD_SECTION (module_license)), used)) = "LICENSE=" license; +#define GRUB_MOD_DEP(name) \ +static const char grub_module_depend_##name[] \ + __attribute__((section(GRUB_MOD_SECTION(moddeps)), __used__)) = #name #else #define GRUB_MOD_LICENSE(license) \ .section GRUB_MOD_SECTION(module_license), "a"; \ From 290766fb770aa9d3ebd3ada989ae3b24d21a093a Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 24 Jun 2011 00:31:29 +0200 Subject: [PATCH 669/869] ZFS zlib support * grub-core/fs/zfs/zfs.c (zlib_decompress): New function. (decomp_table): Add zlib entries. (zio_read): USe 8 bits for compression function rather than 3. * include/grub/zfs/zio.h (zio_compress): Add zlib values. --- ChangeLog | 19 +++++++++++++++++++ grub-core/fs/zfs/zfs.c | 22 ++++++++++++++++++++-- include/grub/zfs/zio.h | 10 +++++++++- 3 files changed, 48 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 6535b6e17..954166148 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,22 @@ +2011-06-24 Vladimir Serbinenko + + ZFS zlib support + + * grub-core/fs/zfs/zfs.c (zlib_decompress): New function. + (decomp_table): Add zlib entries. + (zio_read): USe 8 bits for compression function rather than 3. + * include/grub/zfs/zio.h (zio_compress): Add zlib values. + +2011-06-24 Vladimir Serbinenko + + * grub-core/disk/ahci.c: Add missing license statements. + * grub-core/fs/romfs.c: Likewise. + * grub-core/lib/ia64/setjmp.S: Likewise. + * grub-core/loader/i386/pc/freedos.c: Likewise. + * grub-core/loader/ia64/efi/linux.c: Likewise. + * grub-core/video/colors.c: Likewise. + * include/grub/dl.h (GRUB_MOD_DEP): New macro. + 2011-06-23 Vladimir Serbinenko AHCI support. diff --git a/grub-core/fs/zfs/zfs.c b/grub-core/fs/zfs/zfs.c index 8d86cf9e5..1eea13b26 100644 --- a/grub-core/fs/zfs/zfs.c +++ b/grub-core/fs/zfs/zfs.c @@ -51,6 +51,7 @@ #include #include #include +#include GRUB_MOD_LICENSE ("GPLv3+"); @@ -163,13 +164,30 @@ struct grub_zfs_data grub_disk_addr_t vdev_phys_sector; }; +static grub_err_t +zlib_decompress (void *s, void *d, + grub_size_t slen, grub_size_t dlen) +{ + if (grub_zlib_decompress (s, slen, 0, d, dlen) < 0) + return grub_errno; + return GRUB_ERR_NONE; +} + static decomp_entry_t decomp_table[ZIO_COMPRESS_FUNCTIONS] = { {"inherit", NULL}, /* ZIO_COMPRESS_INHERIT */ {"on", lzjb_decompress}, /* ZIO_COMPRESS_ON */ {"off", NULL}, /* ZIO_COMPRESS_OFF */ {"lzjb", lzjb_decompress}, /* ZIO_COMPRESS_LZJB */ {"empty", NULL}, /* ZIO_COMPRESS_EMPTY */ - {"gzip", NULL}, /* ZIO_COMPRESS_GZIP */ + {"gzip-1", zlib_decompress}, /* ZIO_COMPRESS_GZIP1 */ + {"gzip-2", zlib_decompress}, /* ZIO_COMPRESS_GZIP2 */ + {"gzip-3", zlib_decompress}, /* ZIO_COMPRESS_GZIP3 */ + {"gzip-4", zlib_decompress}, /* ZIO_COMPRESS_GZIP4 */ + {"gzip-5", zlib_decompress}, /* ZIO_COMPRESS_GZIP5 */ + {"gzip-6", zlib_decompress}, /* ZIO_COMPRESS_GZIP6 */ + {"gzip-7", zlib_decompress}, /* ZIO_COMPRESS_GZIP7 */ + {"gzip-8", zlib_decompress}, /* ZIO_COMPRESS_GZIP8 */ + {"gzip-9", zlib_decompress}, /* ZIO_COMPRESS_GZIP9 */ }; static grub_err_t zio_read_data (blkptr_t * bp, grub_zfs_endian_t endian, @@ -527,7 +545,7 @@ zio_read (blkptr_t * bp, grub_zfs_endian_t endian, void **buf, *buf = NULL; checksum = (grub_zfs_to_cpu64((bp)->blk_prop, endian) >> 40) & 0xff; - comp = (grub_zfs_to_cpu64((bp)->blk_prop, endian)>>32) & 0x7; + comp = (grub_zfs_to_cpu64((bp)->blk_prop, endian)>>32) & 0xff; lsize = (BP_IS_HOLE(bp) ? 0 : (((grub_zfs_to_cpu64 ((bp)->blk_prop, endian) & 0xffff) + 1) << SPA_MINBLOCKSHIFT)); diff --git a/include/grub/zfs/zio.h b/include/grub/zfs/zio.h index 797d4f9b3..3dafb4028 100644 --- a/include/grub/zfs/zio.h +++ b/include/grub/zfs/zio.h @@ -77,7 +77,15 @@ enum zio_compress { ZIO_COMPRESS_OFF, ZIO_COMPRESS_LZJB, ZIO_COMPRESS_EMPTY, - ZIO_COMPRESS_GZIP, + ZIO_COMPRESS_GZIP1, + ZIO_COMPRESS_GZIP2, + ZIO_COMPRESS_GZIP3, + ZIO_COMPRESS_GZIP4, + ZIO_COMPRESS_GZIP5, + ZIO_COMPRESS_GZIP6, + ZIO_COMPRESS_GZIP7, + ZIO_COMPRESS_GZIP8, + ZIO_COMPRESS_GZIP9, ZIO_COMPRESS_FUNCTIONS }; From bc09e1a23804bd4132a51bca01851135d7307bff Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 24 Jun 2011 04:32:54 +0200 Subject: [PATCH 670/869] * grub-core/kern/emu/getroot.c (grub_guess_root_device): Revert to old method if mountinfo would return /dev/root and /dev/root doesn't exist. --- ChangeLog | 6 ++++++ grub-core/kern/emu/getroot.c | 10 ++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 954166148..1b63af871 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2011-06-24 Vladimir Serbinenko + + * grub-core/kern/emu/getroot.c (grub_guess_root_device): Revert to + old method if mountinfo would return /dev/root and /dev/root doesn't + exist. + 2011-06-24 Vladimir Serbinenko ZFS zlib support diff --git a/grub-core/kern/emu/getroot.c b/grub-core/kern/emu/getroot.c index db27abf74..6d6c8ef8b 100644 --- a/grub-core/kern/emu/getroot.c +++ b/grub-core/kern/emu/getroot.c @@ -620,11 +620,13 @@ grub_guess_root_device (const char *dir) int root = (strcmp (os_dev, "/dev/root") == 0); if (!dm && !root) return os_dev; - if (stat (os_dev, &st) < 0) - grub_util_error ("cannot stat `%s'", os_dev); + if (stat (os_dev, &st) >= 0) + { + free (os_dev); + dev = st.st_rdev; + return grub_find_device (dm ? "/dev/mapper" : "/dev", dev); + } free (os_dev); - dev = st.st_rdev; - return grub_find_device (dm ? "/dev/mapper" : "/dev", dev); } if (stat (dir, &st) < 0) From 535c191059459b9212991f59aea494db1c1da767 Mon Sep 17 00:00:00 2001 From: Alexander Kurtz Date: Fri, 24 Jun 2011 12:38:24 +0200 Subject: [PATCH 671/869] * util/grub-mkconfig_lib.in: Add missing quotes. --- ChangeLog | 4 ++++ util/grub-mkconfig_lib.in | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 1b63af871..d5c97b6e0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2011-06-24 Alexander Kurtz + + * util/grub-mkconfig_lib.in: Add missing quotes. + 2011-06-24 Vladimir Serbinenko * grub-core/kern/emu/getroot.c (grub_guess_root_device): Revert to diff --git a/util/grub-mkconfig_lib.in b/util/grub-mkconfig_lib.in index 2c5fd8c6f..759bcba1b 100644 --- a/util/grub-mkconfig_lib.in +++ b/util/grub-mkconfig_lib.in @@ -63,7 +63,7 @@ is_path_readable_by_grub () # ... or if we can't figure out the abstraction module, for example if # memberlist fails on an LVM volume group. - if ${grub_probe} -t abstraction $path > /dev/null 2>&1 ; then : ; else + if "${grub_probe}" -t abstraction "$path" > /dev/null 2>&1 ; then : ; else return 1 fi From 2a5e94d84abd9efad39e7eafe68fb766cea87314 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 24 Jun 2011 12:41:05 +0200 Subject: [PATCH 672/869] * util/grub-mkconfig_lib.in (prepare_grub_to_access_device): Load partmap before abstraction. --- ChangeLog | 5 +++++ util/grub-mkconfig_lib.in | 12 ++++++------ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index d5c97b6e0..1e7a468ec 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-06-24 Vladimir Serbinenko + + * util/grub-mkconfig_lib.in (prepare_grub_to_access_device): Load + partmap before abstraction. + 2011-06-24 Alexander Kurtz * util/grub-mkconfig_lib.in: Add missing quotes. diff --git a/util/grub-mkconfig_lib.in b/util/grub-mkconfig_lib.in index 759bcba1b..090fcf314 100644 --- a/util/grub-mkconfig_lib.in +++ b/util/grub-mkconfig_lib.in @@ -105,12 +105,6 @@ prepare_grub_to_access_device () { device="$1" - # Abstraction modules aren't auto-loaded. - abstraction="`"${grub_probe}" --device "${device}" --target=abstraction`" - for module in ${abstraction} ; do - echo "insmod ${module}" - done - partmap="`"${grub_probe}" --device "${device}" --target=partmap`" for module in ${partmap} ; do case "${module}" in @@ -121,6 +115,12 @@ prepare_grub_to_access_device () esac done + # Abstraction modules aren't auto-loaded. + abstraction="`"${grub_probe}" --device "${device}" --target=abstraction`" + for module in ${abstraction} ; do + echo "insmod ${module}" + done + fs="`"${grub_probe}" --device "${device}" --target=fs`" for module in ${fs} ; do echo "insmod ${module}" From 98e2f50661b63494a7d94d3ad04d31669468f9b4 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 24 Jun 2011 13:02:49 +0200 Subject: [PATCH 673/869] * grub-core/fs/iso9660.c (grub_iso9660_iterate_dir): Skip . and .. --- ChangeLog | 4 ++++ grub-core/fs/iso9660.c | 11 ++++------- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1e7a468ec..d21fa1026 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2011-06-24 Vladimir Serbinenko + + * grub-core/fs/iso9660.c (grub_iso9660_iterate_dir): Skip . and .. + 2011-06-24 Vladimir Serbinenko * util/grub-mkconfig_lib.in (prepare_grub_to_access_device): Load diff --git a/grub-core/fs/iso9660.c b/grub-core/fs/iso9660.c index 508cc5b71..5b53ca597 100644 --- a/grub-core/fs/iso9660.c +++ b/grub-core/fs/iso9660.c @@ -598,7 +598,7 @@ grub_iso9660_iterate_dir (grub_fshelp_node_t dir, return 0; } - while (offset < dir->size) + for (; offset < dir->size; offset += dirent.len) { if (grub_disk_read (dir->data->disk, (dir->blk << GRUB_ISO9660_LOG2_BLKSZ) @@ -676,10 +676,9 @@ grub_iso9660_iterate_dir (grub_fshelp_node_t dir, if (filename) *filename = '\0'; - if (dirent.namelen == 1 && name[0] == 0) - filename = "."; - else if (dirent.namelen == 1 && name[0] == 1) - filename = ".."; + /* . and .. */ + if (dirent.namelen == 1 && (name[0] == 0 || name[0] == 1)) + continue; else filename = name; } @@ -712,8 +711,6 @@ grub_iso9660_iterate_dir (grub_fshelp_node_t dir, if (filename_alloc) grub_free (filename); } - - offset += dirent.len; } return 0; From 4388ca7224904dd35cafb7aa4a48fe60af1cdd4d Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 24 Jun 2011 13:43:10 +0200 Subject: [PATCH 674/869] * grub-core/commands/wildcard.c (match_files): Add a useful dprintf. (wildcard_expand): Don't stop on nonregexp parts after regexp ones since it truncates the output. Reported by: Ximin Luo. --- ChangeLog | 7 +++++++ grub-core/commands/wildcard.c | 4 ++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index d21fa1026..eaee6266a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2011-06-24 Vladimir Serbinenko + + * grub-core/commands/wildcard.c (match_files): Add a useful dprintf. + (wildcard_expand): Don't stop on nonregexp parts after regexp ones since + it truncates the output. + Reported by: Ximin Luo. + 2011-06-24 Vladimir Serbinenko * grub-core/fs/iso9660.c (grub_iso9660_iterate_dir): Skip . and .. diff --git a/grub-core/commands/wildcard.c b/grub-core/commands/wildcard.c index 32561abe6..45d819a3e 100644 --- a/grub-core/commands/wildcard.c +++ b/grub-core/commands/wildcard.c @@ -288,6 +288,8 @@ match_files (const char *prefix, const char *suffix, const char *end, if (regexec (regexp, name, 0, 0, 0)) return 0; + grub_dprintf ("expand", "matched\n"); + buffer = grub_xasprintf ("%s%s", dir, name); if (! buffer) return 1; @@ -423,8 +425,6 @@ wildcard_expand (const char *s, char ***strs) while (*start) { split_path (start, &noregexop, ®exop); - if (noregexop >= regexop) /* no more wildcards */ - break; if (make_regex (noregexop, regexop, ®exp)) goto fail; From 031f22a01f81f3b65bdc8bc8fde473a5f847752e Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 24 Jun 2011 18:26:20 +0200 Subject: [PATCH 675/869] * grub-core/disk/raid.c (insert_array): Ensure uniqueness of readable names. --- ChangeLog | 5 +++++ grub-core/disk/raid.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/ChangeLog b/ChangeLog index eaee6266a..d70c7c6c0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-06-24 Vladimir Serbinenko + + * grub-core/disk/raid.c (insert_array): Ensure uniqueness of readable + names. + 2011-06-24 Vladimir Serbinenko * grub-core/commands/wildcard.c (match_files): Add a useful dprintf. diff --git a/grub-core/disk/raid.c b/grub-core/disk/raid.c index c6be3efde..7c7dbc3dc 100644 --- a/grub-core/disk/raid.c +++ b/grub-core/disk/raid.c @@ -679,6 +679,49 @@ insert_array (grub_disk_t disk, struct grub_raid_array *new_array, scanner_name); #endif + { + int max_used_number = 0, len, need_new_name = 0; + int add_us = 0; + len = grub_strlen (array->name); + if (len && grub_isdigit (array->name[len-1])) + add_us = 1; + for (p = array_list; p != NULL; p = p->next) + { + int cur_num; + char *num, *end; + if (grub_strncmp (p->name, array->name, len) != 0) + continue; + if (p->name[len] == 0) + { + need_new_name = 1; + continue; + } + if (add_us && p->name[len] != '_') + continue; + if (add_us) + num = p->name + len + 1; + else + num = p->name + len; + if (!grub_isdigit (num[0])) + continue; + cur_num = grub_strtoull (num, &end, 10); + if (end[0]) + continue; + if (cur_num > max_used_number) + max_used_number = cur_num; + } + if (need_new_name) + { + char *tmp; + tmp = grub_xasprintf ("%s%s%d", array->name, add_us ? "_" : "", + max_used_number + 1); + if (!tmp) + return grub_errno; + grub_free (array->name); + array->name = tmp; + } + } + /* Add our new array to the list. */ array->next = array_list; array_list = array; From 8b51fd98b90531c9a3407ee0d00c935171f58e92 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 24 Jun 2011 20:35:25 +0200 Subject: [PATCH 676/869] bootp support --- grub-core/net/arp.c | 8 + grub-core/net/drivers/emu/emunet.c | 6 +- grub-core/net/ethernet.c | 11 +- grub-core/net/ip.c | 69 +++++--- grub-core/net/net.c | 268 ++++++++++++++++++++++++++--- grub-core/net/tftp.c | 12 +- grub-core/net/udp.c | 10 +- include/grub/emu/export.h | 6 + include/grub/net.h | 38 ++-- include/grub/net/ethernet.h | 16 +- include/grub/net/netbuff.h | 2 +- include/grub/net/udp.h | 5 +- 12 files changed, 360 insertions(+), 91 deletions(-) create mode 100644 include/grub/emu/export.h diff --git a/grub-core/net/arp.c b/grub-core/net/arp.c index 0644d3d2e..1dbd8a58f 100644 --- a/grub-core/net/arp.c +++ b/grub-core/net/arp.c @@ -41,6 +41,14 @@ grub_net_arp_resolve (struct grub_net_network_level_interface *inf, char *aux, arp_data[128]; int i; + if (proto_addr->type == GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4 + && proto_addr->ipv4 == 0xffffffff) + { + hw_addr->type = GRUB_NET_LINK_LEVEL_PROTOCOL_ETHERNET; + grub_memset (hw_addr->mac, -1, 6); + return GRUB_ERR_NONE; + } + /* Check cache table. */ entry = arp_find_entry (proto_addr); if (entry) diff --git a/grub-core/net/drivers/emu/emunet.c b/grub-core/net/drivers/emu/emunet.c index ee4ba4773..d1e49a2f4 100644 --- a/grub-core/net/drivers/emu/emunet.c +++ b/grub-core/net/drivers/emu/emunet.c @@ -13,8 +13,8 @@ static int fd; -static grub_err_t -send_card_buffer (struct grub_net_card *dev __attribute__ ((unused)), +static grub_err_t +send_card_buffer (const struct grub_net_card *dev __attribute__ ((unused)), struct grub_net_buff *pack) { ssize_t actual; @@ -27,7 +27,7 @@ send_card_buffer (struct grub_net_card *dev __attribute__ ((unused)), } static grub_ssize_t -get_card_packet (struct grub_net_card *dev __attribute__ ((unused)), +get_card_packet (const struct grub_net_card *dev __attribute__ ((unused)), struct grub_net_buff *pack) { ssize_t actual; diff --git a/grub-core/net/ethernet.c b/grub-core/net/ethernet.c index d29193afe..f1bc8c1d0 100644 --- a/grub-core/net/ethernet.c +++ b/grub-core/net/ethernet.c @@ -27,12 +27,14 @@ send_ethernet_packet (struct grub_net_network_level_interface *inf, } grub_err_t -grub_net_recv_ethernet_packet (struct grub_net_buff *nb) +grub_net_recv_ethernet_packet (struct grub_net_buff * nb, + const struct grub_net_card * card) { struct etherhdr *eth; struct llchdr *llch; struct snaphdr *snaph; grub_uint16_t type; + grub_net_link_level_address_t hwaddress; eth = (struct etherhdr *) nb->data; type = grub_be_to_cpu16 (eth->type); @@ -51,7 +53,10 @@ grub_net_recv_ethernet_packet (struct grub_net_buff *nb) } } - /* ARP packet. */ + hwaddress.type = GRUB_NET_LINK_LEVEL_PROTOCOL_ETHERNET; + grub_memcpy (hwaddress.mac, eth->dst, sizeof (hwaddress.mac)); + + /* ARP packet. */ if (type == GRUB_NET_ETHERTYPE_ARP) { grub_net_arp_receive (nb); @@ -59,7 +64,7 @@ grub_net_recv_ethernet_packet (struct grub_net_buff *nb) } /* IP packet. */ if (type == GRUB_NET_ETHERTYPE_IP) - grub_net_recv_ip_packets (nb); + grub_net_recv_ip_packets (nb, card, &hwaddress); return GRUB_ERR_NONE; } diff --git a/grub-core/net/ip.c b/grub-core/net/ip.c index 4adc2b028..808532a4a 100644 --- a/grub-core/net/ip.c +++ b/grub-core/net/ip.c @@ -25,9 +25,9 @@ ipchksum (void *ipv, int len) } grub_err_t -grub_net_send_ip_packet (struct grub_net_network_level_interface *inf, - const grub_net_network_level_address_t *target, - struct grub_net_buff *nb) +grub_net_send_ip_packet (struct grub_net_network_level_interface * inf, + const grub_net_network_level_address_t * target, + struct grub_net_buff * nb) { struct iphdr *iph; static int id = 0x2400; @@ -54,43 +54,58 @@ grub_net_send_ip_packet (struct grub_net_network_level_interface *inf, err = grub_net_arp_resolve (inf, target, &ll_target_addr); if (err) return err; - return send_ethernet_packet (inf, nb, ll_target_addr, GRUB_NET_ETHERTYPE_IP); + return send_ethernet_packet (inf, nb, ll_target_addr, + GRUB_NET_ETHERTYPE_IP); } -/* -static int -ip_filter (struct grub_net_buff *nb) +grub_err_t +grub_net_recv_ip_packets (struct grub_net_buff * nb, + const struct grub_net_card * card, + const grub_net_link_level_address_t * hwaddress) { struct iphdr *iph = (struct iphdr *) nb->data; grub_err_t err; + struct grub_net_network_level_interface *inf; - if (nb->end - nb->data < (signed) sizeof (*iph)) - return 0; - - if (iph->protocol != 0x11 || - iph->dest != inf->address.ipv4) - return 0; - - grub_netbuff_pull (nb, sizeof (iph)); - err = grub_net_put_packet (&inf->nl_pending, nb); + err = grub_netbuff_pull (nb, sizeof (*iph)); if (err) + return err; + + FOR_NET_NETWORK_LEVEL_INTERFACES (inf) + { + if (inf->card == card + && inf->address.type == GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4 + && inf->address.ipv4 == iph->dest + && grub_net_hwaddr_cmp (&inf->hwaddress, hwaddress) == 0) + break; + } + if (!inf) { - grub_print_error (); - return 0; + FOR_NET_NETWORK_LEVEL_INTERFACES (inf) + if (inf->card == card + && inf->address.type == GRUB_NET_NETWORK_LEVEL_PROTOCOL_PROMISC + && grub_net_hwaddr_cmp (&inf->hwaddress, hwaddress) == 0) + break; + } + if (!inf) + { + if (iph->protocol == IP_UDP + && grub_net_hwaddr_cmp (&card->default_address, hwaddress) == 0) + { + struct udphdr *udph; + udph = (struct udphdr *) nb->data; + grub_netbuff_pull (nb, sizeof (*udph)); + if (grub_be_to_cpu16 (udph->dst) == 68) + grub_net_process_dhcp (nb, card); + } + grub_netbuff_free (nb); + return GRUB_ERR_NONE; } - return 1; -} -*/ -grub_err_t -grub_net_recv_ip_packets (struct grub_net_buff *nb) -{ - struct iphdr *iph = (struct iphdr *) nb->data; - grub_netbuff_pull (nb, sizeof (*iph)); switch (iph->protocol) { case IP_UDP: - return grub_net_recv_udp_packet (nb); + return grub_net_recv_udp_packet (nb, inf); break; default: grub_netbuff_free (nb); diff --git a/grub-core/net/net.c b/grub-core/net/net.c index 1232b3c74..2da60256c 100644 --- a/grub-core/net/net.c +++ b/grub-core/net/net.c @@ -16,6 +16,7 @@ * along with GRUB. If not, see . */ +#include #include #include #include @@ -27,6 +28,7 @@ #include #include #include +#include GRUB_MOD_LICENSE ("GPLv3+"); @@ -54,8 +56,11 @@ static struct grub_fs grub_net_fs; static inline void grub_net_network_level_interface_unregister (struct grub_net_network_level_interface *inter) { - grub_list_remove (GRUB_AS_LIST_P (&grub_net_network_level_interfaces), - GRUB_AS_LIST (inter)); + *inter->prev = inter->next; + if (inter->next) + inter->next->prev = inter->prev; + inter->next = 0; + inter->prev = 0; } static inline void @@ -112,6 +117,8 @@ match_net (const grub_net_network_level_netaddress_t *net, return 0; switch (net->type) { + case GRUB_NET_NETWORK_LEVEL_PROTOCOL_PROMISC: + return 0; case GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4: { grub_int32_t mask = ((1 << net->ipv4.masksize) - 1) << (32 - net->ipv4.masksize); @@ -229,6 +236,9 @@ grub_net_addr_to_str (const grub_net_network_level_address_t *target, char *buf) { switch (target->type) { + case GRUB_NET_NETWORK_LEVEL_PROTOCOL_PROMISC: + grub_strcpy (buf, "promisc"); + return; case GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4: { grub_uint32_t n = grub_be_to_cpu32 (target->ipv4); @@ -270,6 +280,23 @@ hwaddr_to_str (const grub_net_link_level_address_t *addr, char *str) grub_printf ("Unsupported hw address type %d\n", addr->type); } +int +grub_net_hwaddr_cmp (const grub_net_link_level_address_t *a, + const grub_net_link_level_address_t *b) +{ + if (a->type < b->type) + return -1; + if (a->type > b->type) + return +1; + switch (a->type) + { + case GRUB_NET_LINK_LEVEL_PROTOCOL_ETHERNET: + return grub_memcmp (a->mac, b->mac, sizeof (a->mac)); + } + grub_printf ("Unsupported hw address type %d\n", a->type); + return 1; +} + /* FIXME: implement this. */ static char * hwaddr_set_env (struct grub_env_var *var __attribute__ ((unused)), @@ -307,12 +334,16 @@ grub_net_network_level_interface_register (struct grub_net_network_level_interfa grub_register_variable_hook (name, 0, addr_set_env); } - grub_list_push (GRUB_AS_LIST_P (&grub_net_network_level_interfaces), - GRUB_AS_LIST (inter)); + inter->prev = &grub_net_network_level_interfaces; + inter->next = grub_net_network_level_interfaces; + if (inter->next) + inter->next->prev = &inter->next; + grub_net_network_level_interfaces = inter; } struct grub_net_network_level_interface * -grub_net_add_addr (const char *name, struct grub_net_card *card, +grub_net_add_addr (const char *name, + const struct grub_net_card *card, grub_net_network_level_address_t addr, grub_net_link_level_address_t hwaddress, grub_net_interface_flags_t flags) @@ -488,6 +519,9 @@ print_net_address (const grub_net_network_level_netaddress_t *target) { switch (target->type) { + case GRUB_NET_NETWORK_LEVEL_PROTOCOL_PROMISC: + grub_printf ("promisc\n"); + break; case GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4: { grub_uint32_t n = grub_be_to_cpu32 (target->ipv4.base); @@ -546,6 +580,23 @@ grub_cmd_listcards (struct grub_command *cmd __attribute__ ((unused)), return GRUB_ERR_NONE; } +static grub_err_t +grub_cmd_listaddrs (struct grub_command *cmd __attribute__ ((unused)), + int argc __attribute__ ((unused)), + char **args __attribute__ ((unused))) +{ + struct grub_net_network_level_interface *inf; + FOR_NET_NETWORK_LEVEL_INTERFACES (inf) + { + char bufh[MAX_STR_HWADDR_LEN]; + char bufn[GRUB_NET_MAX_STR_ADDR_LEN]; + hwaddr_to_str (&inf->hwaddress, bufh); + grub_net_addr_to_str (&inf->address, bufn); + grub_printf ("%s %s %s\n", inf->name, bufh, bufn); + } + return GRUB_ERR_NONE; +} + grub_net_app_level_t grub_net_app_level_list; struct grub_net_socket *grub_net_sockets; @@ -649,22 +700,27 @@ grub_net_fs_close (grub_file_t file) static void receive_packets (struct grub_net_card *card) { - /* Maybe should be better have a fixed number of packets for each card - and just mark them as used and not used. */ - struct grub_net_buff *nb; - grub_ssize_t actual; - nb = grub_netbuff_alloc (1500); - if (!nb) + while (1) { - grub_print_error (); - return; - } + /* Maybe should be better have a fixed number of packets for each card + and just mark them as used and not used. */ + struct grub_net_buff *nb; + grub_ssize_t actual; + nb = grub_netbuff_alloc (1500); + if (!nb) + { + grub_print_error (); + return; + } - actual = card->driver->recv (card, nb); - if (actual < 0) - grub_netbuff_free (nb); - else - grub_net_recv_ethernet_packet (nb); + actual = card->driver->recv (card, nb); + if (actual < 0) + { + grub_netbuff_free (nb); + break; + } + grub_net_recv_ethernet_packet (nb, card); + } grub_print_error (); } @@ -828,9 +884,10 @@ parse_dhcp_vendor (const char *name, void *vend, int limit) #define OFFSET_OF(x, y) ((grub_uint8_t *)((y)->x) - (grub_uint8_t *)(y)) struct grub_net_network_level_interface * -grub_net_configure_by_dhcp_ack (const char *name, struct grub_net_card *card, +grub_net_configure_by_dhcp_ack (const char *name, + const struct grub_net_card *card, grub_net_interface_flags_t flags, - struct grub_net_bootp_ack *bp, + const struct grub_net_bootp_packet *bp, grub_size_t size) { grub_net_network_level_address_t addr; @@ -889,6 +946,38 @@ grub_net_configure_by_dhcp_ack (const char *name, struct grub_net_card *card, return inter; } +void +grub_net_process_dhcp (struct grub_net_buff *nb, + const struct grub_net_card *card) +{ + char *name; + struct grub_net_network_level_interface *inf; + + name = grub_xasprintf ("%s:dhcp", card->name); + if (!name) + { + grub_print_error (); + return; + } + grub_net_configure_by_dhcp_ack (name, card, + 0, (const struct grub_net_bootp_packet *) nb->data, + (nb->tail - nb->data)); + grub_free (name); + if (grub_errno) + grub_print_error (); + else + { + FOR_NET_NETWORK_LEVEL_INTERFACES(inf) + if (grub_memcmp (inf->name, card->name, grub_strlen (card->name)) == 0 + && grub_memcmp (inf->name + grub_strlen (card->name), + ":dhcp_tmp", sizeof (":dhcp_tmp") - 1) == 0) + { + grub_net_network_level_interface_unregister (inf); + break; + } + } +} + static char hexdigit (grub_uint8_t val) { @@ -1011,6 +1100,131 @@ grub_cmd_dhcpopt (struct grub_command *cmd __attribute__ ((unused)), "unrecognised format specification %s", args[3]); } +static grub_err_t +grub_cmd_bootp (struct grub_command *cmd __attribute__ ((unused)), + int argc, char **args) +{ + struct grub_net_card *card; + struct grub_net_network_level_interface *ifaces; + grub_size_t ncards = 0; + unsigned j = 0; + int interval; + grub_err_t err; + + FOR_NET_CARDS (card) + { + if (argc > 0 && grub_strcmp (card->name, args[0]) != 0) + continue; + ncards++; + } + + ifaces = grub_zalloc (ncards * sizeof (ifaces[0])); + if (!ifaces) + return grub_errno; + + j = 0; + FOR_NET_CARDS (card) + { + if (argc > 0 && grub_strcmp (card->name, args[0]) != 0) + continue; + ifaces[j].card = card; + ifaces[j].next = &ifaces[j+1]; + if (j) + ifaces[j].prev = &ifaces[j-1].next; + ifaces[j].name = grub_xasprintf ("%s:dhcp_tmp", card->name); + if (!ifaces[j].name) + { + unsigned i; + for (i = 0; i < j; i++) + grub_free (ifaces[i].name); + grub_free (ifaces); + return grub_errno; + } + ifaces[j].address.type = GRUB_NET_NETWORK_LEVEL_PROTOCOL_PROMISC; + grub_memcpy (&ifaces[j].hwaddress, &card->default_address, + sizeof (ifaces[j].hwaddress)); + j++; + } + ifaces[ncards - 1].next = grub_net_network_level_interfaces; + if (grub_net_network_level_interfaces) + grub_net_network_level_interfaces->prev = & ifaces[ncards - 1].next; + grub_net_network_level_interfaces = &ifaces[0]; + ifaces[0].prev = &grub_net_network_level_interfaces; + for (interval = 200; interval < 10000; interval *= 2) + { + int done = 0; + for (j = 0; j < ncards; j++) + { + struct grub_net_bootp_packet *pack; + struct grub_datetime date; + grub_int32_t t; + struct grub_net_buff *nb; + struct udphdr *udph; + grub_net_network_level_address_t target; + + if (!ifaces[j].prev) + continue; + nb = grub_netbuff_alloc (sizeof (*pack)); + if (!nb) + return grub_errno; + err = grub_netbuff_reserve (nb, sizeof (*pack) + 64 + 128); + if (err) + return err; + err = grub_netbuff_push (nb, sizeof (*pack) + 64); + if (err) + return err; + pack = (void *) nb->data; + done = 1; + grub_memset (pack, 0, sizeof (*pack) + 64); + pack->opcode = 1; + pack->hw_type = 1; + pack->hw_len = 6; + err = grub_get_datetime (&date); + if (err || !grub_datetime2unixtime (&date, &t)) + { + grub_errno = GRUB_ERR_NONE; + t = 0; + } + pack->ident = grub_cpu_to_be32 (t); + pack->seconds = 0;//grub_cpu_to_be16 (t); + + grub_memcpy (&pack->mac_addr, &ifaces[j].hwaddress.mac, 6); + + grub_netbuff_push (nb, sizeof (*udph)); + + udph = (struct udphdr *) nb->data; + udph->src = grub_cpu_to_be16 (68); + udph->dst = grub_cpu_to_be16 (67); + udph->chksum = 0; + udph->len = grub_cpu_to_be16 (nb->tail - nb->data); + + target.type = GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4; + target.ipv4 = 0xffffffff; + + err = grub_net_send_ip_packet (&ifaces[j], &target, nb); + if (err) + return err; + } + if (!done) + break; + grub_net_poll_cards (interval); + } + + err = GRUB_ERR_NONE; + for (j = 0; j < ncards; j++) + { + if (!ifaces[j].prev) + continue; + grub_error_push (); + grub_net_network_level_interface_unregister (&ifaces[j]); + err = grub_error (GRUB_ERR_FILE_NOT_FOUND, "couldn't configure %s", + ifaces[j].card->name); + } + + return err; +} + + static struct grub_fs grub_net_fs = { .name = "netfs", @@ -1023,7 +1237,8 @@ static struct grub_fs grub_net_fs = .mtime = NULL, }; static grub_command_t cmd_addaddr, cmd_deladdr, cmd_addroute, cmd_delroute; -static grub_command_t cmd_lsroutes, cmd_lscards, cmd_getdhcp; +static grub_command_t cmd_lsroutes, cmd_lscards, cmd_getdhcp, cmd_bootp; +static grub_command_t cmd_dhcp, cmd_lsaddr; GRUB_MOD_INIT(net) { @@ -1043,6 +1258,14 @@ GRUB_MOD_INIT(net) "", N_("list network routes")); cmd_lscards = grub_register_command ("net_ls_cards", grub_cmd_listcards, "", N_("list network cards")); + cmd_lsaddr = grub_register_command ("net_ls_addr", grub_cmd_listaddrs, + "", N_("list network addresses")); + cmd_bootp = grub_register_command ("net_bootp", grub_cmd_bootp, + "[CARD]", + N_("perform a bootp autoconfiguration")); + cmd_dhcp = grub_register_command ("net_dhcp", grub_cmd_bootp, + "[CARD]", + N_("perform a bootp autoconfiguration")); cmd_getdhcp = grub_register_command ("net_get_dhcp_option", grub_cmd_dhcpopt, N_("VAR INTERFACE NUMBER DESCRIPTION"), N_("retrieve DHCP option and save it into VAR. If VAR is - then print the value.")); @@ -1060,6 +1283,7 @@ GRUB_MOD_FINI(net) grub_unregister_command (cmd_delroute); grub_unregister_command (cmd_lsroutes); grub_unregister_command (cmd_lscards); + grub_unregister_command (cmd_lsaddr); grub_unregister_command (cmd_getdhcp); grub_fs_unregister (&grub_net_fs); grub_net_open = NULL; diff --git a/grub-core/net/tftp.c b/grub-core/net/tftp.c index ac3b3e9db..545862092 100644 --- a/grub-core/net/tftp.c +++ b/grub-core/net/tftp.c @@ -24,7 +24,7 @@ tftp_open (struct grub_file *file, const char *filename) tftp_data_t data; grub_err_t err; - data = grub_malloc (sizeof *data); + data = grub_malloc (sizeof (*data)); if (!data) return grub_errno; @@ -86,7 +86,7 @@ tftp_open (struct grub_file *file, const char *filename) /* Retry. */ /*err = grub_net_send_udp_packet (file->device->net->socket, &nb); if (err) - return err; */ + return err; */ } if (file->device->net->socket->status == 0) @@ -154,8 +154,8 @@ tftp_receive (grub_net_socket_t sock, struct grub_net_buff *nb) } grub_netbuff_clear (&nb_ack); grub_netbuff_reserve (&nb_ack, 128); - grub_netbuff_push (&nb_ack, sizeof (tftph->opcode) - + sizeof (tftph->u.ack.block)); + grub_netbuff_push (&nb_ack, sizeof (tftph->opcode) + + sizeof (tftph->u.ack.block)); tftph = (struct tftphdr *) nb_ack.data; tftph->opcode = grub_cpu_to_be16 (TFTP_ACK); @@ -180,12 +180,12 @@ static struct grub_net_app_protocol grub_tftp_protocol = .close = tftp_close }; -GRUB_MOD_INIT(tftp) +GRUB_MOD_INIT (tftp) { grub_net_app_level_register (&grub_tftp_protocol); } -GRUB_MOD_FINI(tftp) +GRUB_MOD_FINI (tftp) { grub_net_app_level_unregister (&grub_tftp_protocol); } diff --git a/grub-core/net/udp.c b/grub-core/net/udp.c index 86220bf0f..cc7534ea1 100644 --- a/grub-core/net/udp.c +++ b/grub-core/net/udp.c @@ -24,7 +24,8 @@ grub_net_send_udp_packet (const grub_net_socket_t socket, } grub_err_t -grub_net_recv_udp_packet (struct grub_net_buff *nb) +grub_net_recv_udp_packet (struct grub_net_buff * nb, + struct grub_net_network_level_interface * inf) { struct udphdr *udph; grub_net_socket_t sock; @@ -33,7 +34,8 @@ grub_net_recv_udp_packet (struct grub_net_buff *nb) FOR_NET_SOCKETS (sock) { - if (grub_be_to_cpu16 (udph->dst) == sock->in_port) + if (grub_be_to_cpu16 (udph->dst) == sock->in_port + && inf == sock->inf && sock->app) { if (sock->status == 0) sock->out_port = grub_be_to_cpu16 (udph->src); @@ -41,7 +43,7 @@ grub_net_recv_udp_packet (struct grub_net_buff *nb) /* App protocol remove its own reader. */ sock->app->read (sock, nb); - /* If there is data, puts packet in socket list. */ + /* If there is data, puts packet in socket list. */ if ((nb->tail - nb->data) > 0) grub_net_put_packet (&sock->packs, nb); else @@ -49,6 +51,8 @@ grub_net_recv_udp_packet (struct grub_net_buff *nb) return GRUB_ERR_NONE; } } + if (grub_be_to_cpu16 (udph->dst) == 68) + grub_net_process_dhcp (nb, inf->card); grub_netbuff_free (nb); return GRUB_ERR_NONE; } diff --git a/include/grub/emu/export.h b/include/grub/emu/export.h new file mode 100644 index 000000000..1e2f0432b --- /dev/null +++ b/include/grub/emu/export.h @@ -0,0 +1,6 @@ +void EXPORT_FUNC (open64) (void); +void EXPORT_FUNC (close) (void); +void EXPORT_FUNC (read) (void); +void EXPORT_FUNC (write) (void); +void EXPORT_FUNC (ioctl) (void); + diff --git a/include/grub/net.h b/include/grub/net.h index f9745acec..5d99cace3 100644 --- a/include/grub/net.h +++ b/include/grub/net.h @@ -62,8 +62,10 @@ struct grub_net_card_driver char *name; grub_err_t (*init) (struct grub_net_card *dev); grub_err_t (*fini) (struct grub_net_card *dev); - grub_err_t (*send) (struct grub_net_card *dev, struct grub_net_buff *buf); - grub_ssize_t (*recv) (struct grub_net_card *dev, struct grub_net_buff *buf); + grub_err_t (*send) (const struct grub_net_card *dev, + struct grub_net_buff *buf); + grub_ssize_t (*recv) (const struct grub_net_card *dev, + struct grub_net_buff *buf); }; extern struct grub_net_card_driver *grub_net_card_drivers; @@ -116,6 +118,7 @@ struct grub_net_network_level_interface; typedef enum grub_network_level_protocol_id { + GRUB_NET_NETWORK_LEVEL_PROTOCOL_PROMISC, GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4 } grub_network_level_protocol_id_t; @@ -243,12 +246,13 @@ extern grub_err_t (*EXPORT_VAR (grub_file_net_seek)) (struct grub_file *file, gr struct grub_net_network_level_interface { struct grub_net_network_level_interface *next; + struct grub_net_network_level_interface **prev; char *name; - struct grub_net_card *card; + const struct grub_net_card *card; grub_net_network_level_address_t address; grub_net_link_level_address_t hwaddress; grub_net_interface_flags_t flags; - struct grub_net_bootp_ack *dhcp_ack; + struct grub_net_bootp_packet *dhcp_ack; grub_size_t dhcp_acklen; void *data; }; @@ -291,7 +295,8 @@ grub_net_session_recv (struct grub_net_session *session, void *buf, } struct grub_net_network_level_interface * -grub_net_add_addr (const char *name, struct grub_net_card *card, +grub_net_add_addr (const char *name, + const struct grub_net_card *card, grub_net_network_level_address_t addr, grub_net_link_level_address_t hwaddress, grub_net_interface_flags_t flags); @@ -369,7 +374,7 @@ grub_net_add_route_gw (const char *name, typedef grub_uint8_t grub_net_bootp_mac_addr_t[GRUB_NET_BOOTP_MAC_ADDR_LEN]; -struct grub_net_bootp_ack +struct grub_net_bootp_packet { grub_uint8_t opcode; grub_uint8_t hw_type; /* hardware type. */ @@ -391,11 +396,21 @@ struct grub_net_bootp_ack #define GRUB_NET_BOOTP_RFC1048_MAGIC 0x63825363L struct grub_net_network_level_interface * -grub_net_configure_by_dhcp_ack (const char *name, struct grub_net_card *card, +grub_net_configure_by_dhcp_ack (const char *name, + const struct grub_net_card *card, grub_net_interface_flags_t flags, - struct grub_net_bootp_ack *bp, + const struct grub_net_bootp_packet *bp, grub_size_t size); +void +grub_net_process_dhcp (struct grub_net_buff *nb, + const struct grub_net_card *card); + +int +grub_net_hwaddr_cmp (const grub_net_link_level_address_t *a, + const grub_net_link_level_address_t *b); + + /* Currently suppoerted adresses: IPv4: XXX.XXX.XXX.XXX @@ -420,8 +435,11 @@ typedef int grub_err_t grub_net_recv_link_layer (struct grub_net_network_level_interface *inf, grub_net_packet_handler_t handler); -grub_err_t -grub_net_recv_ip_packets (struct grub_net_buff *nb); + +grub_err_t +grub_net_recv_ip_packets (struct grub_net_buff *nb, + const struct grub_net_card *card, + const grub_net_link_level_address_t *hwaddress); grub_err_t grub_net_send_ip_packet (struct grub_net_network_level_interface *inf, diff --git a/include/grub/net/ethernet.h b/include/grub/net/ethernet.h index 7ff7a4562..a841dc12c 100644 --- a/include/grub/net/ethernet.h +++ b/include/grub/net/ethernet.h @@ -12,19 +12,6 @@ struct etherhdr grub_uint16_t type; } __attribute__ ((packed)); -#define PCP(x) x & 0xe000 -#define CFI(x) x & 0x1000 -#define VID(x) x & 0x0fff -#define PRINT_ETH_ADDR(name,addr) grub_printf("%s %x:%x:%x:%x:%x:%x\n",\ - name,\ - addr[0],\ - addr[1],\ - addr[2],\ - addr[3],\ - addr[4],\ - addr[5]\ - ) - struct llchdr { grub_uint8_t dsap; @@ -52,6 +39,7 @@ send_ethernet_packet (struct grub_net_network_level_interface *inf, grub_net_link_level_address_t target_addr, grub_uint16_t ethertype); grub_err_t -grub_net_recv_ethernet_packet (struct grub_net_buff *nb); +grub_net_recv_ethernet_packet (struct grub_net_buff *nb, + const struct grub_net_card *card); #endif diff --git a/include/grub/net/netbuff.h b/include/grub/net/netbuff.h index 8ce508ead..245e813c3 100644 --- a/include/grub/net/netbuff.h +++ b/include/grub/net/netbuff.h @@ -26,5 +26,5 @@ grub_err_t grub_netbuff_reserve (struct grub_net_buff *net_buff ,grub_size_t len grub_err_t grub_netbuff_clear (struct grub_net_buff *net_buff); struct grub_net_buff * grub_netbuff_alloc ( grub_size_t len ); grub_err_t grub_netbuff_free (struct grub_net_buff *net_buff); -grub_err_t grub_netbuff_clear (struct grub_net_buff *net_buff); + #endif diff --git a/include/grub/net/udp.h b/include/grub/net/udp.h index 86311ccf1..eacf3325c 100644 --- a/include/grub/net/udp.h +++ b/include/grub/net/udp.h @@ -14,8 +14,9 @@ struct udphdr grub_err_t grub_net_send_udp_packet (const grub_net_socket_t socket , struct grub_net_buff *nb); -grub_err_t -grub_net_recv_udp_packet (struct grub_net_buff *nb); +grub_err_t +grub_net_recv_udp_packet (struct grub_net_buff *nb, + struct grub_net_network_level_interface *inf); #define FOR_NET_UDP_PACKETS(inf, var) FOR_PACKETS(inf->udp_pending, var) From 40ea05dee4d26693cb03e3d3157626b64f671da4 Mon Sep 17 00:00:00 2001 From: Szymon Janc Date: Fri, 24 Jun 2011 22:37:17 +0200 Subject: [PATCH 677/869] * grub-core/io/xzio.c: Fix code style issues --- ChangeLog | 4 ++++ grub-core/io/xzio.c | 16 +++++++++------- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4f42719bc..286648a46 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2011-06-24 Szymon Janc + + * grub-core/io/xzio.c: Fix code style issues + 2011-06-24 Vladimir Serbinenko 2011-06-24 Manoel Rebelo Abranches diff --git a/grub-core/io/xzio.c b/grub-core/io/xzio.c index 1f42cd242..1575ca236 100644 --- a/grub-core/io/xzio.c +++ b/grub-core/io/xzio.c @@ -48,7 +48,7 @@ static struct grub_fs grub_xzio_fs; static grub_size_t decode_vli (const grub_uint8_t buf[], grub_size_t size_max, - grub_uint64_t * num) + grub_uint64_t *num) { if (size_max == 0) return 0; @@ -71,7 +71,7 @@ decode_vli (const grub_uint8_t buf[], grub_size_t size_max, } static grub_ssize_t -read_vli (grub_file_t file, grub_uint64_t * num) +read_vli (grub_file_t file, grub_uint64_t *num) { grub_uint8_t buf[VLI_MAX_DIGITS]; grub_ssize_t read; @@ -92,6 +92,8 @@ static int test_header (grub_file_t file) { grub_xzio_t xzio = file->data; + enum xz_ret ret; + xzio->buf.in_size = grub_file_read (xzio->file, xzio->inbuf, STREAM_HEADER_SIZE); @@ -101,7 +103,7 @@ test_header (grub_file_t file) return 0; } - enum xz_ret ret = xz_dec_run (xzio->dec, &xzio->buf); + ret = xz_dec_run (xzio->dec, &xzio->buf); if (ret == XZ_FORMAT_ERROR) { @@ -132,8 +134,8 @@ test_footer (grub_file_t file) grub_uint64_t records; grub_file_seek (xzio->file, xzio->file->size - FOOTER_MAGIC_SIZE); - if (grub_file_read (xzio->file, footer, FOOTER_MAGIC_SIZE) != - FOOTER_MAGIC_SIZE + if (grub_file_read (xzio->file, footer, FOOTER_MAGIC_SIZE) + != FOOTER_MAGIC_SIZE || grub_memcmp (footer, FOOTER_MAGIC, FOOTER_MAGIC_SIZE) != 0) goto ERROR; @@ -150,8 +152,8 @@ test_footer (grub_file_t file) xzio->file->size - XZ_STREAM_FOOTER_SIZE - backsize); /* Test index marker. */ - if (grub_file_read (xzio->file, &imarker, sizeof (imarker)) != - sizeof (imarker) && imarker != 0x00) + if (grub_file_read (xzio->file, &imarker, sizeof (imarker)) + != sizeof (imarker) && imarker != 0x00) goto ERROR; if (read_vli (xzio->file, &records) <= 0) From 77c0840ba67302031363479dfbf8bf44ef1ab6d0 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 25 Jun 2011 00:18:36 +0200 Subject: [PATCH 678/869] * grub-core/net/i386/pc/pxe.c (grub_pxe_recv): Fix declaration. (grub_pxe_send): Likewise. (GRUB_MOD_INIT): Fix types. --- ChangeLog | 6 ++++++ grub-core/net/i386/pc/pxe.c | 6 +++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 286648a46..4cac3cd65 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2011-06-25 Vladimir Serbinenko + + * grub-core/net/i386/pc/pxe.c (grub_pxe_recv): Fix declaration. + (grub_pxe_send): Likewise. + (GRUB_MOD_INIT): Fix types. + 2011-06-24 Szymon Janc * grub-core/io/xzio.c: Fix code style issues diff --git a/grub-core/net/i386/pc/pxe.c b/grub-core/net/i386/pc/pxe.c index 27c4af17f..a23104bad 100644 --- a/grub-core/net/i386/pc/pxe.c +++ b/grub-core/net/i386/pc/pxe.c @@ -305,14 +305,14 @@ static struct grub_fs grub_pxefs_fs = }; static grub_ssize_t -grub_pxe_recv (struct grub_net_card *dev __attribute__ ((unused)), +grub_pxe_recv (const struct grub_net_card *dev __attribute__ ((unused)), struct grub_net_buff *buf __attribute__ ((unused))) { return 0; } static grub_err_t -grub_pxe_send (struct grub_net_card *dev __attribute__ ((unused)), +grub_pxe_send (const struct grub_net_card *dev __attribute__ ((unused)), struct grub_net_buff *buf __attribute__ ((unused))) { return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, "not implemented"); @@ -424,7 +424,7 @@ GRUB_MOD_INIT(pxe) { struct grub_pxe_bangpxe *pxenv; struct grub_pxenv_get_cached_info ci; - struct grub_net_bootp_ack *bp; + struct grub_net_bootp_packet *bp; char *buf; pxenv = grub_pxe_scan (); From 6295b32f79acb93df2208321eec491aa6b214fa0 Mon Sep 17 00:00:00 2001 From: Patrick Date: Sat, 25 Jun 2011 01:09:32 +0200 Subject: [PATCH 679/869] * grub-core/kern/main.c (grub_load_normal_mode): Correct the comment. --- ChangeLog | 4 ++++ grub-core/kern/main.c | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 4cac3cd65..c639cb9de 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2011-06-25 Patrick + + * grub-core/kern/main.c (grub_load_normal_mode): Correct the comment. + 2011-06-25 Vladimir Serbinenko * grub-core/net/i386/pc/pxe.c (grub_pxe_recv): Fix declaration. diff --git a/grub-core/kern/main.c b/grub-core/kern/main.c index cc9758988..447f0ae33 100644 --- a/grub-core/kern/main.c +++ b/grub-core/kern/main.c @@ -159,7 +159,7 @@ grub_load_normal_mode (void) /* Load the module. */ grub_dl_load ("normal"); - /* Something went wrong. Print errors here to let user know why we're entering rescue mode. */ + /* Print errors if any. */ grub_print_error (); grub_errno = 0; From cc4bfec8fac9a6fdea9ce38f5c7a92bc5579f22e Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 26 Jun 2011 04:18:45 +0200 Subject: [PATCH 680/869] Fix a memory leak --- grub-core/net/ethernet.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/grub-core/net/ethernet.c b/grub-core/net/ethernet.c index 863e659a8..175d0b65f 100644 --- a/grub-core/net/ethernet.c +++ b/grub-core/net/ethernet.c @@ -69,10 +69,14 @@ grub_net_recv_ethernet_packet (struct grub_net_buff * nb, { grub_net_arp_receive (nb); grub_netbuff_free (nb); + return GRUB_ERR_NONE; } /* IP packet. */ if (type == GRUB_NET_ETHERTYPE_IP) - grub_net_recv_ip_packets (nb, card, &hwaddress); - + { + grub_net_recv_ip_packets (nb, card, &hwaddress); + return GRUB_ERR_NONE; + } + grub_netbuff_free (nb); return GRUB_ERR_NONE; } From 8e60fc8f85b27fb513ef0b83efa07c531ec8e9a7 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 26 Jun 2011 04:19:12 +0200 Subject: [PATCH 681/869] Send network packets on PXE --- grub-core/Makefile.core.def | 2 +- grub-core/net/drivers/i386/pc/pxe.c | 304 ++++++++++++++++++ grub-core/net/i386/pc/pxe.c | 482 ---------------------------- 3 files changed, 305 insertions(+), 483 deletions(-) create mode 100644 grub-core/net/drivers/i386/pc/pxe.c delete mode 100644 grub-core/net/i386/pc/pxe.c diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def index 927718359..5c3ce99be 100644 --- a/grub-core/Makefile.core.def +++ b/grub-core/Makefile.core.def @@ -1100,7 +1100,7 @@ module = { module = { name = pxe; - i386_pc = net/i386/pc/pxe.c; + i386_pc = net/drivers/i386/pc/pxe.c; enable = i386_pc; }; diff --git a/grub-core/net/drivers/i386/pc/pxe.c b/grub-core/net/drivers/i386/pc/pxe.c new file mode 100644 index 000000000..7d6e3adca --- /dev/null +++ b/grub-core/net/drivers/i386/pc/pxe.c @@ -0,0 +1,304 @@ +/* pxe.c - Driver to provide access to the pxe filesystem */ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2008,2009,2011 Free Software Foundation, Inc. + * + * GRUB is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see . + */ + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +GRUB_MOD_LICENSE ("GPLv3+"); + +#define SEGMENT(x) ((x) >> 4) +#define OFFSET(x) ((x) & 0xF) +#define SEGOFS(x) ((SEGMENT(x) << 16) + OFFSET(x)) +#define LINEAR(x) (void *) ((((x) >> 16) << 4) + ((x) & 0xFFFF)) + +struct grub_pxe_undi_open +{ + grub_uint16_t status; + grub_uint16_t open_flag; + grub_uint16_t pkt_filter; + grub_uint16_t mcast_count; + grub_uint8_t mcast[8][6]; +} __attribute__ ((packed)); + +struct grub_pxe_undi_isr +{ + grub_uint16_t status; + grub_uint16_t func_flag; + grub_uint16_t buffer_len; + grub_uint16_t frame_len; + grub_uint16_t frame_hdr_len; + grub_uint32_t buffer; + grub_uint8_t prot_type; + grub_uint8_t pkt_type; +} __attribute__ ((packed)); + +enum + { + GRUB_PXE_ISR_IN_START = 1, + GRUB_PXE_ISR_IN_PROCESS, + GRUB_PXE_ISR_IN_GET_NEXT + }; + +enum + { + GRUB_PXE_ISR_OUT_OURS = 0, + GRUB_PXE_ISR_OUT_NOT_OURS = 1 + }; + +enum + { + GRUB_PXE_ISR_OUT_DONE = 0, + GRUB_PXE_ISR_OUT_TRANSMIT = 2, + GRUB_PXE_ISR_OUT_RECEIVE = 3, + GRUB_PXE_ISR_OUT_BUSY = 4, + }; + +struct grub_pxe_undi_transmit +{ + grub_uint16_t status; + grub_uint8_t protocol; + grub_uint8_t xmitflag; + grub_uint32_t dest; + grub_uint32_t tbd; + grub_uint32_t reserved[2]; +} __attribute__ ((packed)); + +struct grub_pxe_undi_tbd +{ + grub_uint16_t len; + grub_uint32_t buf; + grub_uint16_t blk_count; + struct + { + grub_uint8_t ptr_type; + grub_uint8_t reserved; + grub_uint16_t len; + grub_uint32_t ptr; + } blocks[8]; +} __attribute__ ((packed)); + +struct grub_pxe_bangpxe *grub_pxe_pxenv; +static grub_uint32_t pxe_rm_entry = 0; + +static struct grub_pxe_bangpxe * +grub_pxe_scan (void) +{ + struct grub_bios_int_registers regs; + struct grub_pxenv *pxenv; + struct grub_pxe_bangpxe *bangpxe; + + regs.flags = GRUB_CPU_INT_FLAGS_DEFAULT; + + regs.ebx = 0; + regs.ecx = 0; + regs.eax = 0x5650; + regs.es = 0; + + grub_bios_interrupt (0x1a, ®s); + + if ((regs.eax & 0xffff) != 0x564e) + return NULL; + + pxenv = (struct grub_pxenv *) ((regs.es << 4) + (regs.ebx & 0xffff)); + if (grub_memcmp (pxenv->signature, GRUB_PXE_SIGNATURE, + sizeof (pxenv->signature)) + != 0) + return NULL; + + if (pxenv->version < 0x201) + return NULL; + + bangpxe = (void *) ((((pxenv->pxe_ptr & 0xffff0000) >> 16) << 4) + + (pxenv->pxe_ptr & 0xffff)); + + if (!bangpxe) + return NULL; + + if (grub_memcmp (bangpxe->signature, GRUB_PXE_BANGPXE_SIGNATURE, + sizeof (bangpxe->signature)) != 0) + return NULL; + + pxe_rm_entry = bangpxe->rm_entry; + + return bangpxe; +} + +static grub_ssize_t +grub_pxe_recv (const struct grub_net_card *dev __attribute__ ((unused)), + struct grub_net_buff *buf) +{ + struct grub_pxe_undi_isr *isr; + static int in_progress = 0; + char *ptr, *end; + int len; + + isr = (void *) GRUB_MEMORY_MACHINE_SCRATCH_ADDR; + + if (!in_progress) + { + grub_memset (isr, 0, sizeof (*isr)); + isr->func_flag = GRUB_PXE_ISR_IN_START; + grub_pxe_call (GRUB_PXENV_UNDI_ISR, isr, pxe_rm_entry); + if (isr->status || isr->func_flag != GRUB_PXE_ISR_OUT_OURS) + return -1; + grub_memset (isr, 0, sizeof (*isr)); + isr->func_flag = GRUB_PXE_ISR_IN_PROCESS; + grub_pxe_call (GRUB_PXENV_UNDI_ISR, isr, pxe_rm_entry); + } + else + { + grub_memset (isr, 0, sizeof (*isr)); + isr->func_flag = GRUB_PXE_ISR_IN_GET_NEXT; + grub_pxe_call (GRUB_PXENV_UNDI_ISR, isr, pxe_rm_entry); + } + + while (isr->func_flag != GRUB_PXE_ISR_OUT_RECEIVE) + { + if (isr->status || isr->func_flag == GRUB_PXE_ISR_OUT_DONE) + return -1; + grub_memset (isr, 0, sizeof (*isr)); + isr->func_flag = GRUB_PXE_ISR_IN_GET_NEXT; + grub_pxe_call (GRUB_PXENV_UNDI_ISR, isr, pxe_rm_entry); + } + + grub_netbuff_put (buf, isr->frame_len); + ptr = buf->data; + end = ptr + isr->frame_len; + len = isr->frame_len; + grub_memcpy (ptr, LINEAR (isr->buffer), isr->buffer_len); + ptr += isr->buffer_len; + while (ptr < end) + { + grub_memset (isr, 0, sizeof (*isr)); + isr->func_flag = GRUB_PXE_ISR_IN_GET_NEXT; + grub_pxe_call (GRUB_PXENV_UNDI_ISR, isr, pxe_rm_entry); + if (isr->status || isr->func_flag != GRUB_PXE_ISR_OUT_RECEIVE) + return -1; + + grub_memcpy (ptr, LINEAR (isr->buffer), isr->buffer_len); + ptr += isr->buffer_len; + } + + grub_printf ("<%d>\n", len); + return len; +} + +static grub_err_t +grub_pxe_send (const struct grub_net_card *dev __attribute__ ((unused)), + struct grub_net_buff *pack) +{ + struct grub_pxe_undi_transmit *trans; + struct grub_pxe_undi_tbd *tbd; + char *buf; + + trans = (void *) GRUB_MEMORY_MACHINE_SCRATCH_ADDR; + grub_memset (trans, 0, sizeof (*trans)); + tbd = (void *) (GRUB_MEMORY_MACHINE_SCRATCH_ADDR + 128); + grub_memset (tbd, 0, sizeof (*tbd)); + buf = (void *) (GRUB_MEMORY_MACHINE_SCRATCH_ADDR + 256); + grub_memcpy (buf, pack->data, pack->tail - pack->data); + + trans->tbd = SEGOFS ((grub_addr_t) tbd); + trans->protocol = 0; + tbd->len = pack->tail - pack->data; + tbd->buf = SEGOFS ((grub_addr_t) buf); + + grub_pxe_call (GRUB_PXENV_UNDI_TRANSMIT, trans, pxe_rm_entry); + if (trans->status) + return grub_error (GRUB_ERR_IO, "PXE send failed (status 0x%x)", + trans->status); + return 0; +} + +struct grub_net_card_driver grub_pxe_card_driver = +{ + .send = grub_pxe_send, + .recv = grub_pxe_recv +}; + +struct grub_net_card grub_pxe_card = +{ + .driver = &grub_pxe_card_driver, + .name = "pxe" +}; + +void +grub_pxe_unload (void) +{ + if (grub_pxe_pxenv) + { + grub_pxe_call (GRUB_PXENV_UNDI_CLOSE, + (void *) GRUB_MEMORY_MACHINE_SCRATCH_ADDR, + pxe_rm_entry); + grub_net_card_unregister (&grub_pxe_card); + grub_pxe_pxenv = 0; + } +} + +GRUB_MOD_INIT(pxe) +{ + struct grub_pxe_bangpxe *pxenv; + struct grub_pxenv_get_cached_info ci; + struct grub_net_bootp_packet *bp; + struct grub_pxe_undi_open *ou; + + pxenv = grub_pxe_scan (); + if (! pxenv) + return; + + ci.packet_type = GRUB_PXENV_PACKET_TYPE_DHCP_ACK; + ci.buffer = 0; + ci.buffer_size = 0; + grub_pxe_call (GRUB_PXENV_GET_CACHED_INFO, &ci, pxe_rm_entry); + if (ci.status) + return; + + bp = LINEAR (ci.buffer); + + grub_memcpy (grub_pxe_card.default_address.mac, bp->mac_addr, + bp->hw_len < sizeof (grub_pxe_card.default_address.mac) + ? bp->hw_len : sizeof (grub_pxe_card.default_address.mac)); + grub_pxe_card.default_address.type = GRUB_NET_LINK_LEVEL_PROTOCOL_ETHERNET; + + ou = (void *) GRUB_MEMORY_MACHINE_SCRATCH_ADDR; + grub_memset (ou, 0, sizeof (ou)); + ou->pkt_filter = 4; + grub_pxe_call (GRUB_PXENV_UNDI_OPEN, ou, pxe_rm_entry); + + if (ou->status) + return; + + grub_net_card_register (&grub_pxe_card); + grub_net_configure_by_dhcp_ack ("pxe", &grub_pxe_card, 0, + bp, GRUB_PXE_BOOTP_SIZE); +} + +GRUB_MOD_FINI(pxe) +{ + grub_pxe_unload (); +} diff --git a/grub-core/net/i386/pc/pxe.c b/grub-core/net/i386/pc/pxe.c deleted file mode 100644 index 27c4af17f..000000000 --- a/grub-core/net/i386/pc/pxe.c +++ /dev/null @@ -1,482 +0,0 @@ -/* pxe.c - Driver to provide access to the pxe filesystem */ -/* - * GRUB -- GRand Unified Bootloader - * Copyright (C) 2008,2009 Free Software Foundation, Inc. - * - * GRUB is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * GRUB is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GRUB. If not, see . - */ - -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -#define SEGMENT(x) ((x) >> 4) -#define OFFSET(x) ((x) & 0xF) -#define SEGOFS(x) ((SEGMENT(x) << 16) + OFFSET(x)) -#define LINEAR(x) (void *) (((x >> 16) << 4) + (x & 0xFFFF)) - -struct grub_pxe_bangpxe *grub_pxe_pxenv; -static grub_uint32_t grub_pxe_default_server_ip; -#if 0 -static grub_uint32_t grub_pxe_default_gateway_ip; -#endif -static unsigned grub_pxe_blksize = GRUB_PXE_MIN_BLKSIZE; -static grub_uint32_t pxe_rm_entry = 0; -static grub_file_t curr_file = 0; - -struct grub_pxe_data -{ - grub_uint32_t packet_number; - grub_uint32_t block_size; - grub_uint32_t server_ip; - grub_uint32_t gateway_ip; - char filename[0]; -}; - - -static struct grub_pxe_bangpxe * -grub_pxe_scan (void) -{ - struct grub_bios_int_registers regs; - struct grub_pxenv *pxenv; - struct grub_pxe_bangpxe *bangpxe; - - regs.flags = GRUB_CPU_INT_FLAGS_DEFAULT; - - regs.ebx = 0; - regs.ecx = 0; - regs.eax = 0x5650; - regs.es = 0; - - grub_bios_interrupt (0x1a, ®s); - - if ((regs.eax & 0xffff) != 0x564e) - return NULL; - - pxenv = (struct grub_pxenv *) ((regs.es << 4) + (regs.ebx & 0xffff)); - if (grub_memcmp (pxenv->signature, GRUB_PXE_SIGNATURE, - sizeof (pxenv->signature)) - != 0) - return NULL; - - if (pxenv->version < 0x201) - return NULL; - - bangpxe = (void *) ((((pxenv->pxe_ptr & 0xffff0000) >> 16) << 4) - + (pxenv->pxe_ptr & 0xffff)); - - if (!bangpxe) - return NULL; - - if (grub_memcmp (bangpxe->signature, GRUB_PXE_BANGPXE_SIGNATURE, - sizeof (bangpxe->signature)) != 0) - return NULL; - - pxe_rm_entry = bangpxe->rm_entry; - - return bangpxe; -} - -static grub_err_t -grub_pxefs_dir (grub_device_t device __attribute__ ((unused)), - const char *path __attribute__ ((unused)), - int (*hook) (const char *filename, - const struct grub_dirhook_info *info) - __attribute__ ((unused))) -{ - return GRUB_ERR_NONE; -} - -static grub_err_t -grub_pxefs_open (struct grub_file *file, const char *name) -{ - union - { - struct grub_pxenv_tftp_get_fsize c1; - struct grub_pxenv_tftp_open c2; - } c; - struct grub_pxe_data *data; - grub_file_t file_int, bufio; - - data = grub_zalloc (sizeof (*data) + grub_strlen (name) + 1); - if (!data) - return grub_errno; - - { - grub_net_network_level_address_t addr; - grub_net_network_level_address_t gateway; - struct grub_net_network_level_interface *interf; - grub_err_t err; - - if (grub_strncmp (file->device->net->name, - "pxe,", sizeof ("pxe,") - 1) == 0 - || grub_strncmp (file->device->net->name, - "pxe:", sizeof ("pxe:") - 1) == 0) - { - err = grub_net_resolve_address (file->device->net->name - + sizeof ("pxe,") - 1, &addr); - if (err) - { - grub_free (data); - return err; - } - } - else - { - addr.ipv4 = grub_pxe_default_server_ip; - addr.type = GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4; - } - err = grub_net_route_address (addr, &gateway, &interf); - if (err) - { - grub_free (data); - return err; - } - data->server_ip = addr.ipv4; - data->gateway_ip = gateway.ipv4; - } - - if (curr_file != 0) - { - grub_pxe_call (GRUB_PXENV_TFTP_CLOSE, &c.c2, pxe_rm_entry); - curr_file = 0; - } - - c.c1.server_ip = data->server_ip; - c.c1.gateway_ip = data->gateway_ip; - grub_strcpy ((char *)&c.c1.filename[0], name); - grub_pxe_call (GRUB_PXENV_TFTP_GET_FSIZE, &c.c1, pxe_rm_entry); - if (c.c1.status) - { - grub_free (data); - return grub_error (GRUB_ERR_FILE_NOT_FOUND, "file not found"); - } - - file->size = c.c1.file_size; - - c.c2.tftp_port = grub_cpu_to_be16 (GRUB_PXE_TFTP_PORT); - c.c2.packet_size = grub_pxe_blksize; - grub_pxe_call (GRUB_PXENV_TFTP_OPEN, &c.c2, pxe_rm_entry); - if (c.c2.status) - { - grub_free (data); - return grub_error (GRUB_ERR_BAD_FS, "open fails"); - } - - data->block_size = c.c2.packet_size; - grub_strcpy (data->filename, name); - - file_int = grub_malloc (sizeof (*file_int)); - if (! file_int) - { - grub_free (data); - return grub_errno; - } - - file->data = data; - file->not_easily_seekable = 1; - grub_memcpy (file_int, file, sizeof (struct grub_file)); - curr_file = file_int; - - bufio = grub_bufio_open (file_int, data->block_size); - if (! bufio) - { - grub_free (file_int); - grub_free (data); - return grub_errno; - } - - grub_memcpy (file, bufio, sizeof (struct grub_file)); - - return GRUB_ERR_NONE; -} - -static grub_ssize_t -grub_pxefs_read (grub_file_t file, char *buf, grub_size_t len) -{ - struct grub_pxenv_tftp_read c; - struct grub_pxe_data *data; - grub_uint32_t pn; - grub_uint64_t r; - - data = file->data; - - pn = grub_divmod64 (file->offset, data->block_size, &r); - if (r) - { - grub_error (GRUB_ERR_BAD_FS, - "read access must be aligned to packet size"); - return -1; - } - - if ((curr_file != file) || (data->packet_number > pn)) - { - struct grub_pxenv_tftp_open o; - - if (curr_file != 0) - grub_pxe_call (GRUB_PXENV_TFTP_CLOSE, &o, pxe_rm_entry); - - o.server_ip = data->server_ip; - o.gateway_ip = data->gateway_ip; - grub_strcpy ((char *)&o.filename[0], data->filename); - o.tftp_port = grub_cpu_to_be16 (GRUB_PXE_TFTP_PORT); - o.packet_size = data->block_size; - grub_pxe_call (GRUB_PXENV_TFTP_OPEN, &o, pxe_rm_entry); - if (o.status) - { - grub_error (GRUB_ERR_BAD_FS, "open fails"); - return -1; - } - data->block_size = o.packet_size; - data->packet_number = 0; - curr_file = file; - } - - c.buffer = SEGOFS (GRUB_MEMORY_MACHINE_SCRATCH_ADDR); - while (pn >= data->packet_number) - { - c.buffer_size = data->block_size; - grub_pxe_call (GRUB_PXENV_TFTP_READ, &c, pxe_rm_entry); - if (c.status) - { - grub_error (GRUB_ERR_BAD_FS, "read fails"); - return -1; - } - data->packet_number++; - } - - grub_memcpy (buf, (char *) GRUB_MEMORY_MACHINE_SCRATCH_ADDR, len); - - return len; -} - -static grub_err_t -grub_pxefs_close (grub_file_t file) -{ - struct grub_pxenv_tftp_close c; - - if (curr_file == file) - { - grub_pxe_call (GRUB_PXENV_TFTP_CLOSE, &c, pxe_rm_entry); - curr_file = 0; - } - - grub_free (file->data); - - return GRUB_ERR_NONE; -} - -static grub_err_t -grub_pxefs_label (grub_device_t device __attribute ((unused)), - char **label __attribute ((unused))) -{ - *label = 0; - return GRUB_ERR_NONE; -} - -static struct grub_fs grub_pxefs_fs = - { - .name = "pxe", - .dir = grub_pxefs_dir, - .open = grub_pxefs_open, - .read = grub_pxefs_read, - .close = grub_pxefs_close, - .label = grub_pxefs_label, - .next = 0 - }; - -static grub_ssize_t -grub_pxe_recv (struct grub_net_card *dev __attribute__ ((unused)), - struct grub_net_buff *buf __attribute__ ((unused))) -{ - return 0; -} - -static grub_err_t -grub_pxe_send (struct grub_net_card *dev __attribute__ ((unused)), - struct grub_net_buff *buf __attribute__ ((unused))) -{ - return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, "not implemented"); -} - -struct grub_net_card_driver grub_pxe_card_driver = -{ - .send = grub_pxe_send, - .recv = grub_pxe_recv -}; - -struct grub_net_card grub_pxe_card = -{ - .driver = &grub_pxe_card_driver, - .name = "pxe" -}; - -void -grub_pxe_unload (void) -{ - if (grub_pxe_pxenv) - { - grub_fs_unregister (&grub_pxefs_fs); - grub_net_card_unregister (&grub_pxe_card); - grub_pxe_pxenv = 0; - } -} - -static void -set_ip_env (char *varname, grub_uint32_t ip) -{ - char buf[GRUB_NET_MAX_STR_ADDR_LEN]; - grub_net_network_level_address_t addr; - addr.type = GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4; - addr.ipv4 = ip; - - grub_net_addr_to_str (&addr, buf); - grub_env_set (varname, buf); -} - -static char * -write_ip_env (grub_uint32_t *ip, const char *val) -{ - char *buf; - grub_err_t err; - grub_net_network_level_address_t addr; - - err = grub_net_resolve_address (val, &addr); - if (err) - return 0; - if (addr.type != GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4) - return NULL; - - /* Normalize the IP. */ - buf = grub_malloc (GRUB_NET_MAX_STR_ADDR_LEN); - if (!buf) - return 0; - grub_net_addr_to_str (&addr, buf); - - *ip = addr.ipv4; - - return buf; -} - -static char * -grub_env_write_pxe_default_server (struct grub_env_var *var - __attribute__ ((unused)), - const char *val) -{ - return write_ip_env (&grub_pxe_default_server_ip, val); -} - -#if 0 -static char * -grub_env_write_pxe_default_gateway (struct grub_env_var *var - __attribute__ ((unused)), - const char *val) -{ - return write_ip_env (&grub_pxe_default_gateway_ip, val); -} -#endif - -static char * -grub_env_write_pxe_blocksize (struct grub_env_var *var __attribute__ ((unused)), - const char *val) -{ - unsigned size; - char *buf; - - size = grub_strtoul (val, 0, 0); - if (grub_errno) - return 0; - - if (size < GRUB_PXE_MIN_BLKSIZE) - size = GRUB_PXE_MIN_BLKSIZE; - else if (size > GRUB_PXE_MAX_BLKSIZE) - size = GRUB_PXE_MAX_BLKSIZE; - - buf = grub_xasprintf ("%d", size); - if (!buf) - return 0; - - grub_pxe_blksize = size; - - return buf; -} - -GRUB_MOD_INIT(pxe) -{ - struct grub_pxe_bangpxe *pxenv; - struct grub_pxenv_get_cached_info ci; - struct grub_net_bootp_ack *bp; - char *buf; - - pxenv = grub_pxe_scan (); - if (! pxenv) - return; - - ci.packet_type = GRUB_PXENV_PACKET_TYPE_DHCP_ACK; - ci.buffer = 0; - ci.buffer_size = 0; - grub_pxe_call (GRUB_PXENV_GET_CACHED_INFO, &ci, pxe_rm_entry); - if (ci.status) - return; - - bp = LINEAR (ci.buffer); - - grub_pxe_default_server_ip = bp->server_ip; - grub_pxe_pxenv = pxenv; - - set_ip_env ("pxe_default_server", grub_pxe_default_server_ip); - grub_register_variable_hook ("pxe_default_server", 0, - grub_env_write_pxe_default_server); - -#if 0 - grub_pxe_default_gateway_ip = bp->gateway_ip; - - grub_register_variable_hook ("pxe_default_gateway", 0, - grub_env_write_pxe_default_gateway); -#endif - - buf = grub_xasprintf ("%d", grub_pxe_blksize); - if (buf) - grub_env_set ("pxe_blksize", buf); - grub_free (buf); - - grub_register_variable_hook ("pxe_blksize", 0, - grub_env_write_pxe_blocksize); - - grub_memcpy (grub_pxe_card.default_address.mac, bp->mac_addr, - bp->hw_len < sizeof (grub_pxe_card.default_address.mac) - ? bp->hw_len : sizeof (grub_pxe_card.default_address.mac)); - grub_pxe_card.default_address.type = GRUB_NET_LINK_LEVEL_PROTOCOL_ETHERNET; - - grub_fs_register (&grub_pxefs_fs); - grub_net_card_register (&grub_pxe_card); - grub_net_configure_by_dhcp_ack ("pxe", &grub_pxe_card, - GRUB_NET_INTERFACE_PERMANENT - | GRUB_NET_INTERFACE_ADDRESS_IMMUTABLE - | GRUB_NET_INTERFACE_HWADDRESS_IMMUTABLE, - bp, GRUB_PXE_BOOTP_SIZE); -} - -GRUB_MOD_FINI(pxe) -{ - grub_pxe_unload (); -} From bf651f790717fd5b73c80e6bedd9df66069c847e Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 26 Jun 2011 14:47:38 +0200 Subject: [PATCH 682/869] Fix incorrect memset --- grub-core/net/drivers/i386/pc/pxe.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/grub-core/net/drivers/i386/pc/pxe.c b/grub-core/net/drivers/i386/pc/pxe.c index 7d6e3adca..e667d42ef 100644 --- a/grub-core/net/drivers/i386/pc/pxe.c +++ b/grub-core/net/drivers/i386/pc/pxe.c @@ -286,7 +286,7 @@ GRUB_MOD_INIT(pxe) grub_pxe_card.default_address.type = GRUB_NET_LINK_LEVEL_PROTOCOL_ETHERNET; ou = (void *) GRUB_MEMORY_MACHINE_SCRATCH_ADDR; - grub_memset (ou, 0, sizeof (ou)); + grub_memset (ou, 0, sizeof (*ou)); ou->pkt_filter = 4; grub_pxe_call (GRUB_PXENV_UNDI_OPEN, ou, pxe_rm_entry); From 80ca250565745aa1f587216ed8af6dc70e036e92 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 26 Jun 2011 17:06:18 +0200 Subject: [PATCH 683/869] Add backward compatibiulity with old (pxe) syntax. Several cleanups --- grub-core/commands/probe.c | 2 +- grub-core/kern/device.c | 2 +- grub-core/net/drivers/i386/pc/pxe.c | 1 - grub-core/net/net.c | 114 ++++++++++++++++++++-------- include/grub/net.h | 6 +- 5 files changed, 87 insertions(+), 38 deletions(-) diff --git a/grub-core/commands/probe.c b/grub-core/commands/probe.c index 7ed2a4e51..ce1e9aac0 100644 --- a/grub-core/commands/probe.c +++ b/grub-core/commands/probe.c @@ -74,7 +74,7 @@ grub_cmd_probe (grub_extcmd_context_t ctxt, int argc, char **args) { const char *val = "none"; if (dev->net) - val = dev->net->name; + val = dev->net->protocol->name; if (dev->disk) val = dev->disk->dev->name; if (state[0].set) diff --git a/grub-core/kern/device.c b/grub-core/kern/device.c index 45bcd8210..c998d4d4b 100644 --- a/grub-core/kern/device.c +++ b/grub-core/kern/device.c @@ -79,7 +79,7 @@ grub_device_close (grub_device_t device) if (device->net) { - grub_free (device->net->name); + grub_free (device->net->server); grub_free (device->net); } diff --git a/grub-core/net/drivers/i386/pc/pxe.c b/grub-core/net/drivers/i386/pc/pxe.c index e667d42ef..084cdb876 100644 --- a/grub-core/net/drivers/i386/pc/pxe.c +++ b/grub-core/net/drivers/i386/pc/pxe.c @@ -204,7 +204,6 @@ grub_pxe_recv (const struct grub_net_card *dev __attribute__ ((unused)), ptr += isr->buffer_len; } - grub_printf ("<%d>\n", len); return len; } diff --git a/grub-core/net/net.c b/grub-core/net/net.c index 5c7d00991..2932986b2 100644 --- a/grub-core/net/net.c +++ b/grub-core/net/net.c @@ -1,6 +1,6 @@ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2010 Free Software Foundation, Inc. + * Copyright (C) 2010,2011 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -32,6 +32,8 @@ GRUB_MOD_LICENSE ("GPLv3+"); +static char *default_server; + struct grub_net_route { struct grub_net_route *next; @@ -603,26 +605,63 @@ struct grub_net_socket *grub_net_sockets; static grub_net_t grub_net_open_real (const char *name) { - const char *comma = grub_strchr (name, ','); grub_net_app_level_t proto; + const char *protname, *server; + grub_size_t protnamelen; + + if (grub_strncmp (name, "pxe:", sizeof ("pxe:") - 1) == 0) + { + protname = "tftp"; + protnamelen = sizeof ("tftp") - 1; + server = name + sizeof ("pxe:") - 1; + } + else if (grub_strcmp (name, "pxe") == 0) + { + protname = "tftp"; + protnamelen = sizeof ("tftp") - 1; + server = default_server; + } + else + { + const char *comma; + comma = grub_strchr (name, ','); + if (comma) + { + protnamelen = comma - name; + server = comma + 1; + } + else + { + protnamelen = grub_strlen (name); + server = default_server; + } + } + if (!server) + { + grub_error (GRUB_ERR_NET_BAD_ADDRESS, "no server"); + return NULL; + } - if (!comma) - comma = name + grub_strlen (name); FOR_NET_APP_LEVEL (proto) { - if (comma - name == (grub_ssize_t) grub_strlen (proto->name) - && grub_memcmp (proto->name, name, comma - name) == 0) + if (grub_memcmp (proto->name, protname, protnamelen) == 0 + && proto->name[protnamelen] == 0) { grub_net_t ret = grub_malloc (sizeof (*ret)); if (!ret) return NULL; ret->protocol = proto; - ret->name = grub_strdup (name); - if (!ret->name) + if (server) { - grub_free (ret); - return NULL; + ret->server = grub_strdup (server); + if (!ret->server) + { + grub_free (ret); + return NULL; + } } + else + ret->server = NULL; ret->fs = &grub_net_fs; return ret; } @@ -651,13 +690,8 @@ grub_net_fs_open (struct grub_file *file, const char *name) grub_net_network_level_address_t gateway; grub_net_socket_t socket; static int port = 25300; - const char *comma; - comma = grub_strchr (file->device->net->name, ','); - if (!comma) - return grub_error (GRUB_ERR_NET_BAD_ADDRESS, "no separator"); - - err = grub_net_resolve_address (comma + 1, &addr); + err = grub_net_resolve_address (file->device->net->server, &addr); if (err) return err; @@ -913,20 +947,19 @@ grub_net_configure_by_dhcp_ack (const char *name, hwaddr.type = GRUB_NET_LINK_LEVEL_PROTOCOL_ETHERNET; inter = grub_net_add_addr (name, card, addr, hwaddr, flags); - if (bp->gateway_ip != bp->server_ip) - { - grub_net_network_level_netaddress_t target; - grub_net_network_level_address_t gw; - char rname[grub_strlen (name) + sizeof ("_gw")]; + { + grub_net_network_level_netaddress_t target; + grub_net_network_level_address_t gw; + char rname[grub_strlen (name) + sizeof ("_gw")]; - target.type = GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4; - target.ipv4.base = bp->server_ip; - target.ipv4.masksize = 32; - gw.type = GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4; - gw.ipv4 = bp->gateway_ip; - grub_snprintf (rname, sizeof (rname), "%s_gw", name); - grub_net_add_route_gw (rname, target, gw); - } + target.type = GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4; + target.ipv4.base = bp->server_ip; + target.ipv4.masksize = 32; + gw.type = GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4; + gw.ipv4 = bp->gateway_ip; + grub_snprintf (rname, sizeof (rname), "%s_gw", name); + grub_net_add_route_gw (rname, target, gw); + } { grub_net_network_level_netaddress_t target; target.type = GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4; @@ -938,9 +971,26 @@ grub_net_configure_by_dhcp_ack (const char *name, if (size > OFFSET_OF (boot_file, bp)) set_env_limn_ro (name, "boot_file", (char *) bp->boot_file, sizeof (bp->boot_file)); - if (size > OFFSET_OF (server_name, bp)) - set_env_limn_ro (name, "dhcp_server_name", (char *) bp->server_name, - sizeof (bp->server_name)); + if (size > OFFSET_OF (server_name, bp) + && bp->server_name[0]) + { + set_env_limn_ro (name, "dhcp_server_name", (char *) bp->server_name, + sizeof (bp->server_name)); + if (!default_server) + { + default_server = grub_strdup (bp->server_name); + grub_errno = GRUB_ERR_NONE; + } + } + if (!default_server) + { + default_server = grub_xasprintf ("%d.%d.%d.%d", + ((grub_uint8_t *) &bp->server_ip)[0], + ((grub_uint8_t *) &bp->server_ip)[1], + ((grub_uint8_t *) &bp->server_ip)[2], + ((grub_uint8_t *) &bp->server_ip)[3]); + grub_errno = GRUB_ERR_NONE; + } if (size > OFFSET_OF (vendor, bp)) parse_dhcp_vendor (name, &bp->vendor, size - OFFSET_OF (vendor, bp)); diff --git a/include/grub/net.h b/include/grub/net.h index 068ccec41..6595a8276 100644 --- a/include/grub/net.h +++ b/include/grub/net.h @@ -234,7 +234,7 @@ grub_net_socket_unregister (grub_net_socket_t sock) typedef struct grub_net { - char *name; + char *server; grub_net_app_level_t protocol; grub_net_socket_t socket; grub_fs_t fs; @@ -389,8 +389,8 @@ struct grub_net_bootp_packet grub_uint32_t server_ip; grub_uint32_t gateway_ip; grub_net_bootp_mac_addr_t mac_addr; - grub_uint8_t server_name[64]; - grub_uint8_t boot_file[128]; + char server_name[64]; + char boot_file[128]; grub_uint8_t vendor[0]; } __attribute__ ((packed)); From cbf597afb158a54ff1d35d4e21f0f6df3c1a01b9 Mon Sep 17 00:00:00 2001 From: Szymon Janc Date: Sun, 26 Jun 2011 17:17:41 +0200 Subject: [PATCH 684/869] * grub-core/commands/cmp.c (grub_cmd_cmp): Remove unnecessary NULL pointer checks before calling grub_free(). * grub-core/commands/wildcard.c (match_devices): Likewise. * grub-core/commands/wildcard.c (match_files): Likewise. * grub-core/fs/cpio.c (grub_cpio_dir): Likewise. * grub-core/fs/cpio.c (grub_cpio_open): Likewise. * grub-core/fs/udf.c (grub_udf_read_block): Likewise. * grub-core/fs/xfs.c (grub_xfs_read_block): Likewise. * grub-core/loader/efi/chainloader.c (grub_cmd_chainloader): Likewise. * grub-core/normal/cmdline.c (grub_cmdline_get): Likewise. * grub-core/script/yylex.l (grub_lexer_unput): Likewise. * grub-core/video/readers/jpeg.c (grub_video_reader_jpeg): Likewise. * grub-core/video/readers/png.c (grub_png_output_byte): Likewise. --- ChangeLog | 16 ++++++++++++++++ grub-core/commands/cmp.c | 6 ++---- grub-core/commands/wildcard.c | 12 ++++-------- grub-core/fs/cpio.c | 13 ++++--------- grub-core/fs/udf.c | 3 +-- grub-core/fs/xfs.c | 3 +-- grub-core/loader/efi/chainloader.c | 3 +-- grub-core/normal/cmdline.c | 6 ++---- grub-core/script/yylex.l | 3 +-- grub-core/video/readers/jpeg.c | 3 +-- grub-core/video/readers/png.c | 3 +-- 11 files changed, 34 insertions(+), 37 deletions(-) diff --git a/ChangeLog b/ChangeLog index c639cb9de..17be445af 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,19 @@ +2011-06-26 Szymon Janc + + * grub-core/commands/cmp.c (grub_cmd_cmp): Remove unnecessary NULL + pointer checks before calling grub_free(). + * grub-core/commands/wildcard.c (match_devices): Likewise. + * grub-core/commands/wildcard.c (match_files): Likewise. + * grub-core/fs/cpio.c (grub_cpio_dir): Likewise. + * grub-core/fs/cpio.c (grub_cpio_open): Likewise. + * grub-core/fs/udf.c (grub_udf_read_block): Likewise. + * grub-core/fs/xfs.c (grub_xfs_read_block): Likewise. + * grub-core/loader/efi/chainloader.c (grub_cmd_chainloader): Likewise. + * grub-core/normal/cmdline.c (grub_cmdline_get): Likewise. + * grub-core/script/yylex.l (grub_lexer_unput): Likewise. + * grub-core/video/readers/jpeg.c (grub_video_reader_jpeg): Likewise. + * grub-core/video/readers/png.c (grub_png_output_byte): Likewise. + 2011-06-25 Patrick * grub-core/kern/main.c (grub_load_normal_mode): Correct the comment. diff --git a/grub-core/commands/cmp.c b/grub-core/commands/cmp.c index 0222927b6..526459311 100644 --- a/grub-core/commands/cmp.c +++ b/grub-core/commands/cmp.c @@ -94,10 +94,8 @@ grub_cmd_cmp (grub_command_t cmd __attribute__ ((unused)), cleanup: - if (buf1) - grub_free (buf1); - if (buf2) - grub_free (buf2); + grub_free (buf1); + grub_free (buf2); if (file1) grub_file_close (file1); if (file2) diff --git a/grub-core/commands/wildcard.c b/grub-core/commands/wildcard.c index 45d819a3e..d2f4347d5 100644 --- a/grub-core/commands/wildcard.c +++ b/grub-core/commands/wildcard.c @@ -255,8 +255,7 @@ match_devices (const regex_t *regexp, int noparts) for (i = 0; devs && devs[i]; i++) grub_free (devs[i]); - if (devs) - grub_free (devs); + grub_free (devs); return 0; } @@ -342,20 +341,17 @@ match_files (const char *prefix, const char *suffix, const char *end, fail: - if (dir) - grub_free (dir); + grub_free (dir); for (i = 0; files && files[i]; i++) grub_free (files[i]); - if (files) - grub_free (files); + grub_free (files); if (dev) grub_device_close (dev); - if (device_name) - grub_free (device_name); + grub_free (device_name); grub_error_pop (); return 0; diff --git a/grub-core/fs/cpio.c b/grub-core/fs/cpio.c index 3a07873ec..0d84382ac 100644 --- a/grub-core/fs/cpio.c +++ b/grub-core/fs/cpio.c @@ -239,8 +239,7 @@ grub_cpio_dir (grub_device_t device, const char *path, info.mtimeset = 1; hook (name + len, &info); - if (prev) - grub_free (prev); + grub_free (prev); prev = name; } else @@ -251,11 +250,8 @@ grub_cpio_dir (grub_device_t device, const char *path, fail: - if (prev) - grub_free (prev); - - if (data) - grub_free (data); + grub_free (prev); + grub_free (data); grub_dl_unref (my_mod); @@ -326,8 +322,7 @@ grub_cpio_open (grub_file_t file, const char *name) fail: - if (data) - grub_free (data); + grub_free (data); grub_dl_unref (my_mod); diff --git a/grub-core/fs/udf.c b/grub-core/fs/udf.c index 48906f84f..e1f115015 100644 --- a/grub-core/fs/udf.c +++ b/grub-core/fs/udf.c @@ -546,8 +546,7 @@ grub_udf_read_block (grub_fshelp_node_t node, grub_disk_addr_t fileblock) } fail: - if (buf) - grub_free (buf); + grub_free (buf); return 0; } diff --git a/grub-core/fs/xfs.c b/grub-core/fs/xfs.c index 1e466465b..eb0783407 100644 --- a/grub-core/fs/xfs.c +++ b/grub-core/fs/xfs.c @@ -324,8 +324,7 @@ grub_xfs_read_block (grub_fshelp_node_t node, grub_disk_addr_t fileblock) } } - if (leaf) - grub_free (leaf); + grub_free (leaf); return GRUB_XFS_FSB_TO_BLOCK(node->data, ret); } diff --git a/grub-core/loader/efi/chainloader.c b/grub-core/loader/efi/chainloader.c index 5dd5adab2..3ecdca534 100644 --- a/grub-core/loader/efi/chainloader.c +++ b/grub-core/loader/efi/chainloader.c @@ -329,8 +329,7 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)), if (file) grub_file_close (file); - if (file_path) - grub_free (file_path); + grub_free (file_path); if (address) efi_call_2 (b->free_pages, address, pages); diff --git a/grub-core/normal/cmdline.c b/grub-core/normal/cmdline.c index 09f2271ea..ea06b4cc7 100644 --- a/grub-core/normal/cmdline.c +++ b/grub-core/normal/cmdline.c @@ -500,8 +500,7 @@ grub_cmdline_get (const char *prompt) case GRUB_TERM_CTRL | 'k': if (lpos < llen) { - if (kill_buf) - grub_free (kill_buf); + grub_free (kill_buf); kill_buf = grub_malloc ((llen - lpos + 1) * sizeof (grub_uint32_t)); @@ -566,8 +565,7 @@ grub_cmdline_get (const char *prompt) { grub_size_t n = lpos; - if (kill_buf) - grub_free (kill_buf); + grub_free (kill_buf); kill_buf = grub_malloc (n + 1); if (grub_errno) diff --git a/grub-core/script/yylex.l b/grub-core/script/yylex.l index 53ae4c54f..96f57dbe6 100644 --- a/grub-core/script/yylex.l +++ b/grub-core/script/yylex.l @@ -355,8 +355,7 @@ grub_lexer_unput (const char *text, yyscan_t yyscanner) { struct grub_lexer_param *lexerstate = yyget_extra (yyscanner)->lexerstate; - if (lexerstate->prefix) - grub_free (lexerstate->prefix); + grub_free (lexerstate->prefix); lexerstate->prefix = grub_strdup (text); if (! lexerstate->prefix) diff --git a/grub-core/video/readers/jpeg.c b/grub-core/video/readers/jpeg.c index d61c90ec9..f2351dee9 100644 --- a/grub-core/video/readers/jpeg.c +++ b/grub-core/video/readers/jpeg.c @@ -750,8 +750,7 @@ grub_video_reader_jpeg (struct grub_video_bitmap **bitmap, grub_jpeg_decode_jpeg (data); for (i = 0; i < 4; i++) - if (data->huff_value[i]) - grub_free (data->huff_value[i]); + grub_free (data->huff_value[i]); grub_free (data); } diff --git a/grub-core/video/readers/png.c b/grub-core/video/readers/png.c index 5728651e0..ae9879b16 100644 --- a/grub-core/video/readers/png.c +++ b/grub-core/video/readers/png.c @@ -625,8 +625,7 @@ grub_png_output_byte (struct grub_png_data *data, grub_uint8_t n) } } - if (blank_line) - grub_free (blank_line); + grub_free (blank_line); data->cur_column = 0; data->first_line = 0; From a8fae12c5be48b4dafeec7c47d99132630be51cb Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 26 Jun 2011 17:18:53 +0200 Subject: [PATCH 685/869] minor cleanups --- grub-core/net/tftp.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/grub-core/net/tftp.c b/grub-core/net/tftp.c index d0ed7c43a..24f30eb7a 100644 --- a/grub-core/net/tftp.c +++ b/grub-core/net/tftp.c @@ -131,8 +131,9 @@ tftp_receive (grub_net_socket_t sock, struct grub_net_buff *nb) grub_netbuff_clear (nb); break; case TFTP_DATA: - if ((err = grub_netbuff_pull (nb, sizeof (tftph->opcode) + - sizeof (tftph->u.data.block))) != GRUB_ERR_NONE) + err = grub_netbuff_pull (nb, sizeof (tftph->opcode) + + sizeof (tftph->u.data.block)); + if (err) return err; if (grub_be_to_cpu16 (tftph->u.data.block) == data->block + 1) { @@ -142,8 +143,11 @@ tftp_receive (grub_net_socket_t sock, struct grub_net_buff *nb) sock->status = 2; /* Prevent garbage in broken cards. */ if (size > 1024) - if ((err = grub_netbuff_unput (nb, size - 1024)) != GRUB_ERR_NONE) - return err; + { + err = grub_netbuff_unput (nb, size - 1024); + if (err) + return err; + } } else grub_netbuff_clear (nb); From b1f9b7249afa234d64454b3db3c5a77a64db1e87 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 26 Jun 2011 17:28:19 +0200 Subject: [PATCH 686/869] mknetdir support for ieee1275 --- util/grub-mknetdir.in | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/util/grub-mknetdir.in b/util/grub-mknetdir.in index 61a7ec3ad..3b4f051c5 100644 --- a/util/grub-mknetdir.in +++ b/util/grub-mknetdir.in @@ -196,11 +196,17 @@ process_input_dir () config_opt="-c ${grubdir}/load.cfg " fi + prefix="/${subdir}/${platform}"; case "${platform}" in i386-pc) mkimage_target=i386-pc-pxe; netmodules="pxe"; - prefix="(pxe)/${subdir}/${platform}"; ext=0 ;; + sparc64-ieee1275) mkimage_target=sparc64-ieee1275-aout; + netmodules=""; + ext=img ;; + *-ieee1275) mkimage_target="${platform}"; + netmodules=""; + ext=elf ;; *) echo Unsupported platform ${platform}; exit 1;; esac From 2f804a7ff6cf37ac69584b88c63e6e5cc209da73 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 26 Jun 2011 17:28:57 +0200 Subject: [PATCH 687/869] remove leftover directory From a27fe54f96b3dc19f3222b2872cd0e365059e1a6 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 26 Jun 2011 17:51:46 +0200 Subject: [PATCH 688/869] missing part of previous commit --- util/grub-mknetdir.in | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/util/grub-mknetdir.in b/util/grub-mknetdir.in index 3b4f051c5..a561004e6 100644 --- a/util/grub-mknetdir.in +++ b/util/grub-mknetdir.in @@ -45,6 +45,9 @@ debug=no debug_image= subdir=`echo /boot/grub | sed ${transform}` pc_dir=${libdir}/$(echo ${PACKAGE_TARNAME} | sed ${transform})/i386-pc +ppc_dir=${libdir}/$(echo ${PACKAGE_TARNAME} | sed ${transform})/powerpc-ieee1275 +sparc_dir=${libdir}/$(echo ${PACKAGE_TARNAME} | sed ${transform})/sparc64-ieee1275 +i386_ieee1275_dir=${libdir}/$(echo ${PACKAGE_TARNAME} | sed ${transform})/i386-ieee1275 # Usage: usage # Print the usage. @@ -223,6 +226,15 @@ if [ "${override_dir}" = "" ] ; then if test -e "${pc_dir}" ; then process_input_dir ${pc_dir} i386-pc fi + if test -e "${ppc_dir}" ; then + process_input_dir ${ppc_dir} powerpc-ieee1275 + fi + if test -e "${sparc_dir}" ; then + process_input_dir ${sparc_dir} sparc64-ieee1275 + fi + if test -e "${i386_ieee1275_dir}" ; then + process_input_dir ${sparc_dir} i386-ieee1275 + fi else source "${override_dir}"/modinfo.sh process_input_dir "${override_dir}" ${grub_modinfo_target_cpu}-${grub_modinfo_platform} From cf2bba0ef43bd2708d705ab3bf40fb841310b398 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 26 Jun 2011 18:23:12 +0200 Subject: [PATCH 689/869] add missing quotes and fix variable name --- util/grub-mknetdir.in | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/util/grub-mknetdir.in b/util/grub-mknetdir.in index a561004e6..fa0cafe54 100644 --- a/util/grub-mknetdir.in +++ b/util/grub-mknetdir.in @@ -224,16 +224,16 @@ EOF if [ "${override_dir}" = "" ] ; then if test -e "${pc_dir}" ; then - process_input_dir ${pc_dir} i386-pc + process_input_dir "${pc_dir}" i386-pc fi if test -e "${ppc_dir}" ; then - process_input_dir ${ppc_dir} powerpc-ieee1275 + process_input_dir "${ppc_dir}" powerpc-ieee1275 fi if test -e "${sparc_dir}" ; then process_input_dir ${sparc_dir} sparc64-ieee1275 fi if test -e "${i386_ieee1275_dir}" ; then - process_input_dir ${sparc_dir} i386-ieee1275 + process_input_dir "${i386_ieee1275_dir}" i386-ieee1275 fi else source "${override_dir}"/modinfo.sh From e552d93a8b28cac6fd1a1b4116980f80794a80ca Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 26 Jun 2011 19:52:50 +0200 Subject: [PATCH 690/869] Add ofnet and tftp modules --- util/grub-mknetdir.in | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/util/grub-mknetdir.in b/util/grub-mknetdir.in index fa0cafe54..a36e33cab 100644 --- a/util/grub-mknetdir.in +++ b/util/grub-mknetdir.in @@ -205,10 +205,10 @@ process_input_dir () netmodules="pxe"; ext=0 ;; sparc64-ieee1275) mkimage_target=sparc64-ieee1275-aout; - netmodules=""; + netmodules="ofnet"; ext=img ;; *-ieee1275) mkimage_target="${platform}"; - netmodules=""; + netmodules="ofnet"; ext=elf ;; *) echo Unsupported platform ${platform}; exit 1;; @@ -218,7 +218,7 @@ process_input_dir () source ${subdir}/grub.cfg EOF - $grub_mkimage ${config_opt} -d "${input_dir}" -O ${mkimage_target} --output=${grubdir}/core.$ext --prefix=$prefix $modules $netmodules || exit 1 + $grub_mkimage ${config_opt} -d "${input_dir}" -O ${mkimage_target} --output=${grubdir}/core.$ext --prefix=$prefix $modules $netmodules tftp || exit 1 echo "Netboot directory for ${platform} created. Configure your DHCP server to point to ${subdir}/${platform}/core.$ext" } From 9e322ce8de8526c2c752362749663e6c186f60e3 Mon Sep 17 00:00:00 2001 From: Yves Blusseau Date: Sun, 26 Jun 2011 21:48:52 +0200 Subject: [PATCH 691/869] Display the path of the file when file is not found * grub-core/fs/fat.c: Display the filename when file is not found. * grub-core/fs/fshelp.c: Likewise. * grub-core/fs/hfs.c: Likewise. * grub-core/fs/jfs.c: Likewise. * grub-core/fs/minix.c: Likewise. * grub-core/fs/ufs.c: Likewise. * grub-core/fs/btrfs.c: Likewise. * grub-core/commands/i386/pc/play.c: Likewise. --- ChangeLog | 13 +++++++++++++ grub-core/commands/i386/pc/play.c | 4 ++-- grub-core/fs/btrfs.c | 32 +++++++++++++++++++++++++++---- grub-core/fs/fat.c | 11 +++++++++-- grub-core/fs/fshelp.c | 2 +- grub-core/fs/hfs.c | 2 +- grub-core/fs/jfs.c | 2 +- grub-core/fs/minix.c | 2 +- grub-core/fs/ufs.c | 2 +- 9 files changed, 57 insertions(+), 13 deletions(-) diff --git a/ChangeLog b/ChangeLog index 17be445af..bd6e311bd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2011-06-26 Yves Blusseau + + Display the path of the file when file is not found + + * grub-core/fs/fat.c: Display the filename when file is not found. + * grub-core/fs/fshelp.c: Likewise. + * grub-core/fs/hfs.c: Likewise. + * grub-core/fs/jfs.c: Likewise. + * grub-core/fs/minix.c: Likewise. + * grub-core/fs/ufs.c: Likewise. + * grub-core/fs/btrfs.c: Likewise. + * grub-core/commands/i386/pc/play.c: Likewise. + 2011-06-26 Szymon Janc * grub-core/commands/cmp.c (grub_cmd_cmp): Remove unnecessary NULL diff --git a/grub-core/commands/i386/pc/play.c b/grub-core/commands/i386/pc/play.c index 57980eb92..1adf296ec 100644 --- a/grub-core/commands/i386/pc/play.c +++ b/grub-core/commands/i386/pc/play.c @@ -192,7 +192,7 @@ grub_cmd_play (grub_command_t cmd __attribute__ ((unused)), file = grub_file_open (args[0]); if (! file) - return grub_error (GRUB_ERR_FILE_NOT_FOUND, "file not found"); + return grub_error (GRUB_ERR_FILE_NOT_FOUND, "file `%s' not found", args[0]); if (grub_file_read (file, &tempo, sizeof (tempo)) != sizeof (tempo)) { @@ -227,7 +227,7 @@ grub_cmd_play (grub_command_t cmd __attribute__ ((unused)), if (*end) /* Was not a number either, assume it was supposed to be a file name. */ - return grub_error (GRUB_ERR_FILE_NOT_FOUND, "file not found"); + return grub_error (GRUB_ERR_FILE_NOT_FOUND, "file `%s' not found", args[0]); grub_dprintf ("play","tempo = %d\n", tempo); diff --git a/grub-core/fs/btrfs.c b/grub-core/fs/btrfs.c index 533529e3f..6470c9819 100644 --- a/grub-core/fs/btrfs.c +++ b/grub-core/fs/btrfs.c @@ -1054,6 +1054,7 @@ find_path (struct grub_btrfs_data *data, const char *ctoken; grub_size_t ctokenlen; char *path_alloc = NULL; + char *origpath = NULL; unsigned symlinks_max = 32; *type = GRUB_BTRFS_DIR_ITEM_TYPE_DIRECTORY; @@ -1062,6 +1063,9 @@ find_path (struct grub_btrfs_data *data, key->type = GRUB_BTRFS_ITEM_TYPE_DIR_ITEM; key->offset = 0; skip_default = 1; + origpath = grub_strdup (path); + if (!origpath) + return grub_errno; while (1) { @@ -1086,6 +1090,7 @@ find_path (struct grub_btrfs_data *data, if (*type != GRUB_BTRFS_DIR_ITEM_TYPE_DIRECTORY) { grub_free (path_alloc); + grub_free (origpath); return grub_error (GRUB_ERR_BAD_FILE_TYPE, "not a directory"); } @@ -1098,13 +1103,16 @@ find_path (struct grub_btrfs_data *data, { grub_free (direl); grub_free (path_alloc); + grub_free (origpath); return err; } if (key_cmp (key, &key_out) != 0) { grub_free (direl); grub_free (path_alloc); - return grub_error (GRUB_ERR_FILE_NOT_FOUND, "file not found"); + err = grub_error (GRUB_ERR_FILE_NOT_FOUND, "file `%s' not found", origpath); + grub_free (origpath); + return err; } struct grub_btrfs_dir_item *cdirel; @@ -1116,6 +1124,7 @@ find_path (struct grub_btrfs_data *data, if (!direl) { grub_free (path_alloc); + grub_free (origpath); return grub_errno; } } @@ -1125,6 +1134,7 @@ find_path (struct grub_btrfs_data *data, { grub_free (direl); grub_free (path_alloc); + grub_free (origpath); return err; } @@ -1144,7 +1154,9 @@ find_path (struct grub_btrfs_data *data, { grub_free (direl); grub_free (path_alloc); - return grub_error (GRUB_ERR_FILE_NOT_FOUND, "file not found"); + err = grub_error (GRUB_ERR_FILE_NOT_FOUND, "file `%s' not found", origpath); + grub_free (origpath); + return err; } if (!skip_default) @@ -1158,6 +1170,7 @@ find_path (struct grub_btrfs_data *data, { grub_free (direl); grub_free (path_alloc); + grub_free (origpath); return grub_error (GRUB_ERR_SYMLINK_LOOP, "too deep nesting of symlinks"); } @@ -1168,6 +1181,7 @@ find_path (struct grub_btrfs_data *data, { grub_free (direl); grub_free (path_alloc); + grub_free (origpath); return err; } tmp = grub_malloc (grub_le_to_cpu64 (inode.size) @@ -1176,6 +1190,7 @@ find_path (struct grub_btrfs_data *data, { grub_free (direl); grub_free (path_alloc); + grub_free (origpath); return grub_errno; } @@ -1186,12 +1201,14 @@ find_path (struct grub_btrfs_data *data, { grub_free (direl); grub_free (path_alloc); + grub_free (origpath); grub_free (tmp); return grub_errno; } grub_memcpy (tmp + grub_le_to_cpu64 (inode.size), path, grub_strlen (path) + 1); grub_free (path_alloc); + grub_free (origpath); path = path_alloc = tmp; if (path[0] == '/') { @@ -1218,6 +1235,7 @@ find_path (struct grub_btrfs_data *data, { grub_free (direl); grub_free (path_alloc); + grub_free (origpath); return err; } if (cdirel->key.object_id != key_out.object_id @@ -1225,7 +1243,9 @@ find_path (struct grub_btrfs_data *data, { grub_free (direl); grub_free (path_alloc); - return grub_error (GRUB_ERR_FILE_NOT_FOUND, "file not found"); + err = grub_error (GRUB_ERR_FILE_NOT_FOUND, "file `%s' not found", origpath); + grub_free (origpath); + return err; } err = grub_btrfs_read_logical (data, elemaddr, &ri, sizeof (ri)); @@ -1233,6 +1253,7 @@ find_path (struct grub_btrfs_data *data, { grub_free (direl); grub_free (path_alloc); + grub_free (origpath); return err; } key->type = GRUB_BTRFS_ITEM_TYPE_DIR_ITEM; @@ -1246,7 +1267,9 @@ find_path (struct grub_btrfs_data *data, { grub_free (direl); grub_free (path_alloc); - return grub_error (GRUB_ERR_FILE_NOT_FOUND, "file not found"); + err = grub_error (GRUB_ERR_FILE_NOT_FOUND, "file `%s' not found", origpath); + grub_free (origpath); + return err; } *key = cdirel->key; if (*type == GRUB_BTRFS_DIR_ITEM_TYPE_DIRECTORY) @@ -1254,6 +1277,7 @@ find_path (struct grub_btrfs_data *data, break; default: grub_free (path_alloc); + grub_free (origpath); grub_free (direl); return grub_error (GRUB_ERR_BAD_FS, "unrecognised object type 0x%x", cdirel->key.type); diff --git a/grub-core/fs/fat.c b/grub-core/fs/fat.c index f617bb0f4..c78d3fbe6 100644 --- a/grub-core/fs/fat.c +++ b/grub-core/fs/fat.c @@ -565,6 +565,7 @@ grub_fat_find_dir (grub_disk_t disk, struct grub_fat_data *data, const struct grub_dirhook_info *info)) { char *dirname, *dirp; + char *origpath = NULL; int call_hook; int found = 0; @@ -605,6 +606,10 @@ grub_fat_find_dir (grub_disk_t disk, struct grub_fat_data *data, return 0; } + origpath = grub_strdup (path); + if (!origpath) + return 0; + /* Extract a directory name. */ while (*path == '/') path++; @@ -616,7 +621,7 @@ grub_fat_find_dir (grub_disk_t disk, struct grub_fat_data *data, dirname = grub_malloc (len + 1); if (! dirname) - return 0; + goto fail; grub_memcpy (dirname, path, len); dirname[len] = '\0'; @@ -629,9 +634,11 @@ grub_fat_find_dir (grub_disk_t disk, struct grub_fat_data *data, grub_fat_iterate_dir (disk, data, iter_hook); if (grub_errno == GRUB_ERR_NONE && ! found && !call_hook) - grub_error (GRUB_ERR_FILE_NOT_FOUND, "file not found"); + grub_error (GRUB_ERR_FILE_NOT_FOUND, "file `%s' not found", origpath); + fail: grub_free (dirname); + grub_free (origpath); return found ? dirp : 0; } diff --git a/grub-core/fs/fshelp.c b/grub-core/fs/fshelp.c index f879885ac..2ff78c423 100644 --- a/grub-core/fs/fshelp.c +++ b/grub-core/fs/fshelp.c @@ -197,7 +197,7 @@ grub_fshelp_find_file (const char *path, grub_fshelp_node_t rootnode, name = next; } - return grub_error (GRUB_ERR_FILE_NOT_FOUND, "file not found"); + return grub_error (GRUB_ERR_FILE_NOT_FOUND, "file `%s' not found", path); } if (!path || path[0] != '/') diff --git a/grub-core/fs/hfs.c b/grub-core/fs/hfs.c index cb7679ecb..6f27c69c4 100644 --- a/grub-core/fs/hfs.c +++ b/grub-core/fs/hfs.c @@ -921,7 +921,7 @@ grub_hfs_find_dir (struct grub_hfs_data *data, const char *path, if (! grub_hfs_find_node (data, (char *) &key, data->cat_root, 0, (char *) &fdrec.frec, sizeof (fdrec.frec))) { - grub_error (GRUB_ERR_FILE_NOT_FOUND, "file not found"); + grub_error (GRUB_ERR_FILE_NOT_FOUND, "file `%s' not found", origpath); goto fail; } diff --git a/grub-core/fs/jfs.c b/grub-core/fs/jfs.c index c131169d8..36ec5fd25 100644 --- a/grub-core/fs/jfs.c +++ b/grub-core/fs/jfs.c @@ -699,7 +699,7 @@ grub_jfs_find_file (struct grub_jfs_data *data, const char *path) } grub_jfs_closedir (diro); - grub_error (GRUB_ERR_FILE_NOT_FOUND, "file not found"); + grub_error (GRUB_ERR_FILE_NOT_FOUND, "file `%s' not found", path); return grub_errno; } diff --git a/grub-core/fs/minix.c b/grub-core/fs/minix.c index 64a64cca0..055f89095 100644 --- a/grub-core/fs/minix.c +++ b/grub-core/fs/minix.c @@ -424,7 +424,7 @@ grub_minix_find_file (struct grub_minix_data *data, const char *path) pos += sizeof (ino) + data->filename_size; } while (pos < GRUB_MINIX_INODE_SIZE (data)); - grub_error (GRUB_ERR_FILE_NOT_FOUND, "file not found"); + grub_error (GRUB_ERR_FILE_NOT_FOUND, "file `%s' not found", path); return grub_errno; } diff --git a/grub-core/fs/ufs.c b/grub-core/fs/ufs.c index 86fe8af65..0f4ea0019 100644 --- a/grub-core/fs/ufs.c +++ b/grub-core/fs/ufs.c @@ -514,7 +514,7 @@ grub_ufs_find_file (struct grub_ufs_data *data, const char *path) pos += grub_le_to_cpu16 (dirent.direntlen); } while (pos < INODE_SIZE (data)); - grub_error (GRUB_ERR_FILE_NOT_FOUND, "file not found"); + grub_error (GRUB_ERR_FILE_NOT_FOUND, "file `%s' not found", path); return grub_errno; } From d36f20db4608fa7a8e66bdc86993fcd813e22c08 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 26 Jun 2011 22:37:19 +0200 Subject: [PATCH 692/869] Don't do unaligned access when parsing DHCP packet --- grub-core/net/net.c | 11 ++++++++--- include/grub/net.h | 5 ++++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/grub-core/net/net.c b/grub-core/net/net.c index 2932986b2..560fa7a31 100644 --- a/grub-core/net/net.c +++ b/grub-core/net/net.c @@ -879,7 +879,10 @@ parse_dhcp_vendor (const char *name, void *vend, int limit) ptr = ptr0 = vend; - if (grub_be_to_cpu32 (*(grub_uint32_t *) ptr) != GRUB_NET_BOOTP_RFC1048_MAGIC) + if (ptr[0] != GRUB_NET_BOOTP_RFC1048_MAGIC_0 + || ptr[1] != GRUB_NET_BOOTP_RFC1048_MAGIC_1 + || ptr[2] != GRUB_NET_BOOTP_RFC1048_MAGIC_2 + || ptr[3] != GRUB_NET_BOOTP_RFC1048_MAGIC_3) return; ptr = ptr + sizeof (grub_uint32_t); while (ptr - ptr0 < limit) @@ -1078,8 +1081,10 @@ grub_cmd_dhcpopt (struct grub_command *cmd __attribute__ ((unused)), ptr = inter->dhcp_ack->vendor; - if (grub_be_to_cpu32 (*(grub_uint32_t *) ptr) - != GRUB_NET_BOOTP_RFC1048_MAGIC) + if (ptr[0] != GRUB_NET_BOOTP_RFC1048_MAGIC_0 + || ptr[1] != GRUB_NET_BOOTP_RFC1048_MAGIC_1 + || ptr[2] != GRUB_NET_BOOTP_RFC1048_MAGIC_2 + || ptr[3] != GRUB_NET_BOOTP_RFC1048_MAGIC_3) return grub_error (GRUB_ERR_IO, N_("no DHCP options found")); ptr = ptr + sizeof (grub_uint32_t); while (1) diff --git a/include/grub/net.h b/include/grub/net.h index 6595a8276..ee94ebcc6 100644 --- a/include/grub/net.h +++ b/include/grub/net.h @@ -394,7 +394,10 @@ struct grub_net_bootp_packet grub_uint8_t vendor[0]; } __attribute__ ((packed)); -#define GRUB_NET_BOOTP_RFC1048_MAGIC 0x63825363L +#define GRUB_NET_BOOTP_RFC1048_MAGIC_0 0x63 +#define GRUB_NET_BOOTP_RFC1048_MAGIC_1 0x82 +#define GRUB_NET_BOOTP_RFC1048_MAGIC_2 0x53 +#define GRUB_NET_BOOTP_RFC1048_MAGIC_3 0x63 struct grub_net_network_level_interface * grub_net_configure_by_dhcp_ack (const char *name, From 14f0752dcf5f55f9b50f0b6dce3362d53b180cce Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 26 Jun 2011 22:37:49 +0200 Subject: [PATCH 693/869] Print MAC address when listing cards --- grub-core/net/net.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/grub-core/net/net.c b/grub-core/net/net.c index 560fa7a31..34148f52c 100644 --- a/grub-core/net/net.c +++ b/grub-core/net/net.c @@ -576,9 +576,10 @@ grub_cmd_listcards (struct grub_command *cmd __attribute__ ((unused)), struct grub_net_card *card; FOR_NET_CARDS(card) { - grub_printf ("%s ", card->name); + char buf[MAX_STR_HWADDR_LEN]; + hwaddr_to_str (&card->default_address, buf); + grub_printf ("%s %s\n", card->name, buf); } - grub_printf ("\n"); return GRUB_ERR_NONE; } From f8614119a02110e8ccd69499b5a03147e9535372 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 26 Jun 2011 22:38:43 +0200 Subject: [PATCH 694/869] Few ofnet cleanups --- grub-core/net/drivers/ieee1275/ofnet.c | 47 ++++++++++++++++++++++---- 1 file changed, 40 insertions(+), 7 deletions(-) diff --git a/grub-core/net/drivers/ieee1275/ofnet.c b/grub-core/net/drivers/ieee1275/ofnet.c index 2c264edb1..48c3cd635 100644 --- a/grub-core/net/drivers/ieee1275/ofnet.c +++ b/grub-core/net/drivers/ieee1275/ofnet.c @@ -1,3 +1,21 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2010,2011 Free Software Foundation, Inc. + * + * GRUB is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see . + */ + #include #include #include @@ -37,7 +55,8 @@ card_close (struct grub_net_card *dev) } static grub_err_t -send_card_buffer (struct grub_net_card *dev, struct grub_net_buff *pack) +send_card_buffer (const struct grub_net_card *dev, + struct grub_net_buff *pack) { int actual; int status; @@ -52,7 +71,8 @@ send_card_buffer (struct grub_net_card *dev, struct grub_net_buff *pack) } static grub_ssize_t -get_card_packet (struct grub_net_card *dev, struct grub_net_buff *nb) +get_card_packet (const struct grub_net_card *dev, + struct grub_net_buff *nb) { int actual, rc; @@ -125,20 +145,33 @@ grub_getbootp_real (void) static void grub_ofnet_findcards (void) { - struct grub_net_card *card; - grub_ieee1275_phandle_t devhandle; - grub_net_link_level_address_t lla; int i = 0; + auto int search_net_devices (struct grub_ieee1275_devalias *alias); int search_net_devices (struct grub_ieee1275_devalias *alias) { if (!grub_strcmp (alias->type, "network")) { + struct grub_ofnetcard_data *ofdata; + struct grub_net_card *card; + grub_ieee1275_phandle_t devhandle; + grub_net_link_level_address_t lla; + ofdata = grub_malloc (sizeof (struct grub_ofnetcard_data)); + if (!ofdata) + { + grub_print_error (); + return 1; + } card = grub_malloc (sizeof (struct grub_net_card)); - struct grub_ofnetcard_data *ofdata = - grub_malloc (sizeof (struct grub_ofnetcard_data)); + if (!card) + { + grub_free (ofdata); + grub_print_error (); + return 1; + } + ofdata->path = grub_strdup (alias->path); grub_ieee1275_finddevice (ofdata->path, &devhandle); From 9d22909b8561f72a6503a1f26eab9652670db43f Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 26 Jun 2011 22:42:04 +0200 Subject: [PATCH 695/869] efinet support --- grub-core/Makefile.core.def | 8 +- grub-core/kern/x86_64/efi/callwrap.S | 14 +++ grub-core/net/drivers/efi/efinet.c | 165 +++++++++++++++++++++++++++ include/grub/efi/api.h | 81 +++++++++++++ 4 files changed, 267 insertions(+), 1 deletion(-) create mode 100644 grub-core/net/drivers/efi/efinet.c diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def index 5c3ce99be..ac969e09c 100644 --- a/grub-core/Makefile.core.def +++ b/grub-core/Makefile.core.def @@ -1588,10 +1588,16 @@ module = { module = { name = ofnet; - ieee1275 = net/drivers/ieee1275/ofnet.c; + common = net/drivers/ieee1275/ofnet.c; enable = ieee1275; }; +module = { + name = efinet; + common = net/drivers/efi/efinet.c; + enable = efi; +}; + module = { name = emunet; emu = net/drivers/emu/emunet.c; diff --git a/grub-core/kern/x86_64/efi/callwrap.S b/grub-core/kern/x86_64/efi/callwrap.S index aae267872..cc2c8aa05 100644 --- a/grub-core/kern/x86_64/efi/callwrap.S +++ b/grub-core/kern/x86_64/efi/callwrap.S @@ -95,6 +95,20 @@ FUNCTION(efi_wrap_6) addq $64, %rsp ret +FUNCTION(efi_wrap_7) + subq $96, %rsp + mov 96+16(%rsp), %rax + mov %rax, 48(%rsp) + mov 96+8(%rsp), %rax + mov %rax, 40(%rsp) + mov %r9, 32(%rsp) + mov %r8, %r9 + mov %rcx, %r8 + mov %rsi, %rcx + call *%rdi + addq $96, %rsp + ret + FUNCTION(efi_wrap_10) subq $96, %rsp mov 96+40(%rsp), %rax diff --git a/grub-core/net/drivers/efi/efinet.c b/grub-core/net/drivers/efi/efinet.c new file mode 100644 index 000000000..a6e005601 --- /dev/null +++ b/grub-core/net/drivers/efi/efinet.c @@ -0,0 +1,165 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2010,2011 Free Software Foundation, Inc. + * + * GRUB is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see . + */ + +#include +#include +#include +#include +#include +#include + +GRUB_MOD_LICENSE ("GPLv3+"); + +/* GUID. */ +static grub_efi_guid_t net_io_guid = GRUB_EFI_SIMPLE_NETWORK_GUID; + + +static grub_err_t +send_card_buffer (const struct grub_net_card *dev, + struct grub_net_buff *pack) +{ + grub_efi_status_t st; + grub_efi_simple_network_t *net = dev->data; + st = efi_call_7 (net->transmit, net, 0, pack->tail - pack->data, + pack->data, NULL, NULL, NULL); + if (st != GRUB_EFI_SUCCESS) + return grub_error (GRUB_ERR_IO, "Couldn't send network packet."); + return GRUB_ERR_NONE; +} + +static grub_ssize_t +get_card_packet (const struct grub_net_card *dev, + struct grub_net_buff *nb) +{ + grub_efi_simple_network_t *net = dev->data; + grub_err_t err; + grub_efi_status_t st; + grub_efi_uintn_t bufsize = 1500; + + err = grub_netbuff_clear (nb); + if (err) + return -1; + + err = grub_netbuff_put (nb, 1500); + if (err) + return -1; + + st = efi_call_7 (net->receive, net, NULL, &bufsize, + nb->data, NULL, NULL, NULL); + if (st == GRUB_EFI_BUFFER_TOO_SMALL) + { + err = grub_netbuff_put (nb, bufsize - 1500); + if (err) + return -1; + st = efi_call_7 (net->receive, net, NULL, &bufsize, + nb->data, NULL, NULL, NULL); + } + if (st != GRUB_EFI_SUCCESS) + { + grub_netbuff_clear (nb); + return -1; + } + err = grub_netbuff_unput (nb, (nb->tail - nb->data) - bufsize); + if (err) + return -1; + + return bufsize; +} + +static struct grub_net_card_driver efidriver = + { + .name = "efinet", + .send = send_card_buffer, + .recv = get_card_packet + }; + + +static void +grub_efinet_findcards (void) +{ + grub_efi_uintn_t num_handles; + grub_efi_handle_t *handles; + grub_efi_handle_t *handle; + int i = 0; + + /* Find handles which support the disk io interface. */ + handles = grub_efi_locate_handle (GRUB_EFI_BY_PROTOCOL, &net_io_guid, + 0, &num_handles); + if (! handles) + return; + for (handle = handles; num_handles--; handle++) + { + grub_efi_simple_network_t *net; + struct grub_net_card *card; + + net = grub_efi_open_protocol (*handle, &net_io_guid, + GRUB_EFI_OPEN_PROTOCOL_GET_PROTOCOL); + if (! net) + /* This should not happen... Why? */ + continue; + + if (net->mode->state == GRUB_EFI_NETWORK_STOPPED + && efi_call_1 (net->start, net) != GRUB_EFI_SUCCESS) + continue; + + if (net->mode->state == GRUB_EFI_NETWORK_STOPPED) + continue; + + if (net->mode->state == GRUB_EFI_NETWORK_STARTED + && efi_call_3 (net->initialize, net, 0, 0) != GRUB_EFI_SUCCESS) + continue; + + card = grub_zalloc (sizeof (struct grub_net_card)); + if (!card) + { + grub_print_error (); + grub_free (handles); + return; + } + + card->name = grub_xasprintf ("efinet%d", i++); + card->driver = &efidriver; + card->flags = 0; + card->default_address.type = GRUB_NET_LINK_LEVEL_PROTOCOL_ETHERNET; + grub_memcpy (card->default_address.mac, + net->mode->current_address, + sizeof (card->default_address.mac)); + card->data = net; + + grub_net_card_register (card); + } + grub_free (handles); +} + +GRUB_MOD_INIT(efinet) +{ + grub_efinet_findcards (); +} + +GRUB_MOD_FINI(ofnet) +{ + struct grub_net_card *card; + FOR_NET_CARDS (card) + if (card->driver && !grub_strcmp (card->driver->name, "efinet")) + { + card->driver->fini (card); + card->driver = NULL; + } + grub_net_card_driver_unregister (&efidriver); +} + diff --git a/include/grub/efi/api.h b/include/grub/efi/api.h index ded03a1b3..a3dde0eff 100644 --- a/include/grub/efi/api.h +++ b/include/grub/efi/api.h @@ -84,6 +84,11 @@ { 0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b } \ } +#define GRUB_EFI_SIMPLE_NETWORK_GUID \ + { 0xa19832b9, 0xac25, 0x11d3, \ + { 0x9a, 0x2d, 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d } \ + } + #define GRUB_EFI_DEVICE_PATH_GUID \ { 0x09576e91, 0x6d3f, 0x11d2, \ { 0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b } \ @@ -1214,6 +1219,74 @@ struct grub_efi_block_io_media }; typedef struct grub_efi_block_io_media grub_efi_block_io_media_t; +typedef grub_uint8_t grub_efi_mac_t[32]; + +struct grub_efi_simple_network_mode +{ + grub_uint32_t state; + grub_uint32_t hwaddr_size; + grub_uint32_t media_header_size; + grub_uint32_t max_packet_size; + grub_uint32_t nvram_size; + grub_uint32_t nvram_access_size; + grub_uint32_t receive_filter_mask; + grub_uint32_t receive_filter_setting; + grub_uint32_t max_mcast_filter_count; + grub_uint32_t mcast_filter_count; + grub_efi_mac_t mcast_filter[16]; + grub_efi_mac_t current_address; + grub_efi_mac_t broadcast_address; + grub_efi_mac_t permanent_address; + grub_uint8_t if_type; + grub_uint8_t mac_changeable; + grub_uint8_t multitx_supported; + grub_uint8_t media_present_supported; + grub_uint8_t media_present; +}; + +enum + { + GRUB_EFI_NETWORK_STOPPED, + GRUB_EFI_NETWORK_STARTED, + GRUB_EFI_NETWORK_INITIALIZED, + }; + +struct grub_efi_simple_network +{ + grub_uint64_t revision; + grub_efi_status_t (*start) (struct grub_efi_simple_network *this); + void (*stop) (void); + grub_efi_status_t (*initialize) (struct grub_efi_simple_network *this, + grub_efi_uintn_t extra_rx, + grub_efi_uintn_t extra_tx); + void (*reset) (void); + void (*shutdown) (void); + void (*receive_filters) (void); + void (*station_address) (void); + void (*statistics) (void); + void (*mcastiptomac) (void); + void (*nvdata) (void); + void (*getstatus) (void); + grub_efi_status_t (*transmit) (struct grub_efi_simple_network *this, + grub_efi_uintn_t header_size, + grub_efi_uintn_t buffer_size, + void *buffer, + grub_efi_mac_t *src_addr, + grub_efi_mac_t *dest_addr, + grub_efi_uint16_t *protocol); + grub_efi_status_t (*receive) (struct grub_efi_simple_network *this, + grub_efi_uintn_t *header_size, + grub_efi_uintn_t *buffer_size, + void *buffer, + grub_efi_mac_t *src_addr, + grub_efi_mac_t *dest_addr, + grub_uint16_t *protocol); + void (*waitforpacket) (void); + struct grub_efi_simple_network_mode *mode; +}; +typedef struct grub_efi_simple_network grub_efi_simple_network_t; + + struct grub_efi_block_io { grub_efi_uint64_t revision; @@ -1243,6 +1316,7 @@ typedef struct grub_efi_block_io grub_efi_block_io_t; #define efi_call_4(func, a, b, c, d) func(a, b, c, d) #define efi_call_5(func, a, b, c, d, e) func(a, b, c, d, e) #define efi_call_6(func, a, b, c, d, e, f) func(a, b, c, d, e, f) +#define efi_call_7(func, a, b, c, d, e, f, g) func(a, b, c, d, e, f, g) #define efi_call_10(func, a, b, c, d, e, f, g, h, i, j) func(a, b, c, d, e, f, g, h, i, j) #else @@ -1264,6 +1338,9 @@ typedef struct grub_efi_block_io grub_efi_block_io_t; #define efi_call_6(func, a, b, c, d, e, f) \ efi_wrap_6(func, (grub_uint64_t) a, (grub_uint64_t) b, (grub_uint64_t) c, \ (grub_uint64_t) d, (grub_uint64_t) e, (grub_uint64_t) f) +#define efi_call_7(func, a, b, c, d, e, f, g) \ + efi_wrap_7(func, (grub_uint64_t) a, (grub_uint64_t) b, (grub_uint64_t) c, \ + (grub_uint64_t) d, (grub_uint64_t) e, (grub_uint64_t) f, (grub_uint64_t) g) #define efi_call_10(func, a, b, c, d, e, f, g, h, i, j) \ efi_wrap_10(func, (grub_uint64_t) a, (grub_uint64_t) b, (grub_uint64_t) c, \ (grub_uint64_t) d, (grub_uint64_t) e, (grub_uint64_t) f, (grub_uint64_t) g, \ @@ -1285,6 +1362,10 @@ grub_uint64_t EXPORT_FUNC(efi_wrap_6) (void *func, grub_uint64_t arg1, grub_uint64_t arg2, grub_uint64_t arg3, grub_uint64_t arg4, grub_uint64_t arg5, grub_uint64_t arg6); +grub_uint64_t EXPORT_FUNC(efi_wrap_7) (void *func, grub_uint64_t arg1, + grub_uint64_t arg2, grub_uint64_t arg3, + grub_uint64_t arg4, grub_uint64_t arg5, + grub_uint64_t arg6, grub_uint64_t arg7); grub_uint64_t EXPORT_FUNC(efi_wrap_10) (void *func, grub_uint64_t arg1, grub_uint64_t arg2, grub_uint64_t arg3, grub_uint64_t arg4, grub_uint64_t arg5, From 0ff2c51b82c629e93fff4cc53c129b4d05a73667 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 26 Jun 2011 22:47:05 +0200 Subject: [PATCH 696/869] mknetdir support for EFI --- util/grub-mknetdir.in | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/util/grub-mknetdir.in b/util/grub-mknetdir.in index a36e33cab..52598a8c9 100644 --- a/util/grub-mknetdir.in +++ b/util/grub-mknetdir.in @@ -48,6 +48,9 @@ pc_dir=${libdir}/$(echo ${PACKAGE_TARNAME} | sed ${transform})/i386-pc ppc_dir=${libdir}/$(echo ${PACKAGE_TARNAME} | sed ${transform})/powerpc-ieee1275 sparc_dir=${libdir}/$(echo ${PACKAGE_TARNAME} | sed ${transform})/sparc64-ieee1275 i386_ieee1275_dir=${libdir}/$(echo ${PACKAGE_TARNAME} | sed ${transform})/i386-ieee1275 +efi32_dir=${libdir}/$(echo ${PACKAGE_TARNAME} | sed ${transform})/i386-efi +efi64_dir=${libdir}/$(echo ${PACKAGE_TARNAME} | sed ${transform})/x86_64-efi +itanium_dir=${libdir}/$(echo ${PACKAGE_TARNAME} | sed ${transform})/ia64-efi # Usage: usage # Print the usage. @@ -210,6 +213,9 @@ process_input_dir () *-ieee1275) mkimage_target="${platform}"; netmodules="ofnet"; ext=elf ;; + *-efi) mkimage_target="${platform}"; + netmodules="efinet"; + ext=efi ;; *) echo Unsupported platform ${platform}; exit 1;; esac @@ -235,6 +241,15 @@ if [ "${override_dir}" = "" ] ; then if test -e "${i386_ieee1275_dir}" ; then process_input_dir "${i386_ieee1275_dir}" i386-ieee1275 fi + if test -e "${efi32_dir}" ; then + process_input_dir "${efi32_dir}" i386-efi + fi + if test -e "${efi64_dir}" ; then + process_input_dir "${efi64_dir}" x86_64-efi + fi + if test -e "${itanium_dir}" ; then + process_input_dir "${itanium_dir}" ia64-efi + fi else source "${override_dir}"/modinfo.sh process_input_dir "${override_dir}" ${grub_modinfo_target_cpu}-${grub_modinfo_platform} From 59b455fceaee233e7221831e520c2dd76d42a466 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 27 Jun 2011 06:31:25 +0200 Subject: [PATCH 697/869] Fix incorrect ISR PXE calls --- grub-core/net/drivers/i386/pc/pxe.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/grub-core/net/drivers/i386/pc/pxe.c b/grub-core/net/drivers/i386/pc/pxe.c index 084cdb876..144df964c 100644 --- a/grub-core/net/drivers/i386/pc/pxe.c +++ b/grub-core/net/drivers/i386/pc/pxe.c @@ -165,7 +165,10 @@ grub_pxe_recv (const struct grub_net_card *dev __attribute__ ((unused)), isr->func_flag = GRUB_PXE_ISR_IN_START; grub_pxe_call (GRUB_PXENV_UNDI_ISR, isr, pxe_rm_entry); if (isr->status || isr->func_flag != GRUB_PXE_ISR_OUT_OURS) - return -1; + { + in_progress = 0; + return -1; + } grub_memset (isr, 0, sizeof (*isr)); isr->func_flag = GRUB_PXE_ISR_IN_PROCESS; grub_pxe_call (GRUB_PXENV_UNDI_ISR, isr, pxe_rm_entry); @@ -180,7 +183,10 @@ grub_pxe_recv (const struct grub_net_card *dev __attribute__ ((unused)), while (isr->func_flag != GRUB_PXE_ISR_OUT_RECEIVE) { if (isr->status || isr->func_flag == GRUB_PXE_ISR_OUT_DONE) - return -1; + { + in_progress = 0; + return -1; + } grub_memset (isr, 0, sizeof (*isr)); isr->func_flag = GRUB_PXE_ISR_IN_GET_NEXT; grub_pxe_call (GRUB_PXENV_UNDI_ISR, isr, pxe_rm_entry); @@ -198,11 +204,15 @@ grub_pxe_recv (const struct grub_net_card *dev __attribute__ ((unused)), isr->func_flag = GRUB_PXE_ISR_IN_GET_NEXT; grub_pxe_call (GRUB_PXENV_UNDI_ISR, isr, pxe_rm_entry); if (isr->status || isr->func_flag != GRUB_PXE_ISR_OUT_RECEIVE) - return -1; + { + in_progress = 1; + return -1; + } grub_memcpy (ptr, LINEAR (isr->buffer), isr->buffer_len); ptr += isr->buffer_len; } + in_progress = 1; return len; } From ca80309d32c9d8890d5a16888eac80043a9a16ec Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 27 Jun 2011 08:40:17 +0200 Subject: [PATCH 698/869] * grub-core/net/drivers/ieee1275/ofnet.c (send_card_buffer): Fix prototype. (get_card_packet): Likewise. --- ChangeLog | 6 ++++++ grub-core/net/drivers/ieee1275/ofnet.c | 5 ++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index bd6e311bd..62976120f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2011-06-27 Vladimir Serbinenko + + * grub-core/net/drivers/ieee1275/ofnet.c (send_card_buffer): Fix + prototype. + (get_card_packet): Likewise. + 2011-06-26 Yves Blusseau Display the path of the file when file is not found diff --git a/grub-core/net/drivers/ieee1275/ofnet.c b/grub-core/net/drivers/ieee1275/ofnet.c index 2c264edb1..0394e0dc0 100644 --- a/grub-core/net/drivers/ieee1275/ofnet.c +++ b/grub-core/net/drivers/ieee1275/ofnet.c @@ -37,7 +37,7 @@ card_close (struct grub_net_card *dev) } static grub_err_t -send_card_buffer (struct grub_net_card *dev, struct grub_net_buff *pack) +send_card_buffer (const struct grub_net_card *dev, struct grub_net_buff *pack) { int actual; int status; @@ -52,9 +52,8 @@ send_card_buffer (struct grub_net_card *dev, struct grub_net_buff *pack) } static grub_ssize_t -get_card_packet (struct grub_net_card *dev, struct grub_net_buff *nb) +get_card_packet (const struct grub_net_card *dev, struct grub_net_buff *nb) { - int actual, rc; struct grub_ofnetcard_data *data = dev->data; grub_uint64_t start_time; From 41bec7fec9b8a56172ab99997d5c86de9cffd405 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 27 Jun 2011 08:43:13 +0200 Subject: [PATCH 699/869] * grub-core/disk/ahci.c (grub_ahci_readwrite_real): Use proper definitions for dprintf. * grub-core/disk/pata.c (grub_pata_readwrite): Likewise. --- ChangeLog | 6 ++++++ grub-core/disk/ahci.c | 3 ++- grub-core/disk/pata.c | 3 ++- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 62976120f..df640a0ef 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2011-06-27 Vladimir Serbinenko + + * grub-core/disk/ahci.c (grub_ahci_readwrite_real): Use proper + definitions for dprintf. + * grub-core/disk/pata.c (grub_pata_readwrite): Likewise. + 2011-06-27 Vladimir Serbinenko * grub-core/net/drivers/ieee1275/ofnet.c (send_card_buffer): Fix diff --git a/grub-core/disk/ahci.c b/grub-core/disk/ahci.c index 0f355aa53..415004fcf 100644 --- a/grub-core/disk/ahci.c +++ b/grub-core/disk/ahci.c @@ -590,7 +590,8 @@ grub_ahci_readwrite_real (struct grub_ahci_device *dev, dev->command_table[0].prdt[0].size = (parms->size + (parms->size & 1) - 1) | GRUB_AHCI_INTERRUPT_ON_COMPLETE; - grub_dprintf ("ahci", "PRDT = %" PRIxGRUB_UINT64_T ", %x, %x (%x)\n", + grub_dprintf ("ahci", "PRDT = %" PRIxGRUB_UINT64_T ", %x, %x (%" + PRIuGRUB_SIZE ")\n", dev->command_table[0].prdt[0].data_base, dev->command_table[0].prdt[0].unused, dev->command_table[0].prdt[0].size, diff --git a/grub-core/disk/pata.c b/grub-core/disk/pata.c index 1cb42d04b..ac3b91a41 100644 --- a/grub-core/disk/pata.c +++ b/grub-core/disk/pata.c @@ -156,7 +156,8 @@ grub_pata_readwrite (struct grub_ata *disk, parms->taskfile.cmd, parms->taskfile.features, parms->taskfile.sectors); - grub_dprintf ("pata", "lba_high=0x%x, lba_mid=0x%x, lba_low=0x%x, size=%d\n", + grub_dprintf ("pata", "lba_high=0x%x, lba_mid=0x%x, lba_low=0x%x, size=%" + PRIuGRUB_SIZE "\n", parms->taskfile.lba_high, parms->taskfile.lba_mid, parms->taskfile.lba_low, parms->size); From 9fc9ce3795196effead800fecffff70c0b3415bd Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 27 Jun 2011 08:54:55 +0200 Subject: [PATCH 700/869] Coreboot video support. * grub-core/Makefile.core.def (vga): Extend to coreboot and multiboot. (vbe): Likewise. * grub-core/kern/i386/coreboot/startup.S: Include int.S. * grub-core/kern/i386/pc/startup.S (grub_bios_interrupt): Moved from here ... * grub-core/kern/i386/int.S: ... here. * grub-core/video/i386/pc/vbe.c: Updated includes. * grub-core/video/i386/pc/vga.c: Likewise. * include/grub/i386/coreboot/memory.h (GRUB_MEMORY_MACHINE_SCRATCH_ADDR): New definition. (GRUB_MEMORY_MACHINE_SCRATCH_SEG): Likewise. (GRUB_MEMORY_MACHINE_SCRATCH_SIZE): Likewise. * include/grub/i386/pc/int.h (GRUB_CPU_INT_FLAGS_DEFAULT) [!PCBIOS]: Disable interrupts. * include/grub/i386/pc/vga.h: Removed. All users updated. --- ChangeLog | 20 ++++ grub-core/Makefile.am | 2 + grub-core/Makefile.core.def | 8 +- grub-core/kern/i386/coreboot/startup.S | 1 + grub-core/kern/i386/int.S | 140 +++++++++++++++++++++++++ grub-core/kern/i386/pc/startup.S | 100 +----------------- grub-core/video/i386/pc/vbe.c | 7 +- grub-core/video/i386/pc/vga.c | 5 +- include/grub/i386/coreboot/memory.h | 4 + include/grub/i386/pc/int.h | 5 + include/grub/i386/pc/vga.h | 28 ----- 11 files changed, 184 insertions(+), 136 deletions(-) create mode 100644 grub-core/kern/i386/int.S delete mode 100644 include/grub/i386/pc/vga.h diff --git a/ChangeLog b/ChangeLog index df640a0ef..311e65b05 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,23 @@ +2011-06-27 Vladimir Serbinenko + + Coreboot video support. + + * grub-core/Makefile.core.def (vga): Extend to coreboot and multiboot. + (vbe): Likewise. + * grub-core/kern/i386/coreboot/startup.S: Include int.S. + * grub-core/kern/i386/pc/startup.S (grub_bios_interrupt): Moved from + here ... + * grub-core/kern/i386/int.S: ... here. + * grub-core/video/i386/pc/vbe.c: Updated includes. + * grub-core/video/i386/pc/vga.c: Likewise. + * include/grub/i386/coreboot/memory.h + (GRUB_MEMORY_MACHINE_SCRATCH_ADDR): New definition. + (GRUB_MEMORY_MACHINE_SCRATCH_SEG): Likewise. + (GRUB_MEMORY_MACHINE_SCRATCH_SIZE): Likewise. + * include/grub/i386/pc/int.h (GRUB_CPU_INT_FLAGS_DEFAULT) [!PCBIOS]: + Disable interrupts. + * include/grub/i386/pc/vga.h: Removed. All users updated. + 2011-06-27 Vladimir Serbinenko * grub-core/disk/ahci.c (grub_ahci_readwrite_real): Use proper diff --git a/grub-core/Makefile.am b/grub-core/Makefile.am index a8862b309..c3ecba9cf 100644 --- a/grub-core/Makefile.am +++ b/grub-core/Makefile.am @@ -100,10 +100,12 @@ endif if COND_i386_coreboot KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/i386/pit.h +KERNEL_HEADER_FILES += $(top_builddir)/include/grub/i386/pc/int.h endif if COND_i386_multiboot KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/i386/pit.h +KERNEL_HEADER_FILES += $(top_builddir)/include/grub/i386/pc/int.h endif if COND_i386_qemu diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def index 927718359..7a0536b97 100644 --- a/grub-core/Makefile.core.def +++ b/grub-core/Makefile.core.def @@ -1454,8 +1454,10 @@ module = { module = { name = vga; - i386_pc = video/i386/pc/vga.c; + common = video/i386/pc/vga.c; enable = i386_pc; + enable = i386_coreboot; + enable = i386_multiboot; }; module = { @@ -1533,8 +1535,10 @@ module = { module = { name = vbe; - i386_pc = video/i386/pc/vbe.c; + common = video/i386/pc/vbe.c; enable = i386_pc; + enable = i386_coreboot; + enable = i386_multiboot; }; module = { diff --git a/grub-core/kern/i386/coreboot/startup.S b/grub-core/kern/i386/coreboot/startup.S index cac023ddf..07c5437c0 100644 --- a/grub-core/kern/i386/coreboot/startup.S +++ b/grub-core/kern/i386/coreboot/startup.S @@ -87,3 +87,4 @@ codestart: */ #include "../realmode.S" +#include "../int.S" diff --git a/grub-core/kern/i386/int.S b/grub-core/kern/i386/int.S new file mode 100644 index 000000000..58ccfdaab --- /dev/null +++ b/grub-core/kern/i386/int.S @@ -0,0 +1,140 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2010,2011 Free Software Foundation, Inc. + * + * GRUB is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see . + */ + +FUNCTION(grub_bios_interrupt) + pushf + cli +#ifndef GRUB_MACHINE_PCBIOS + sidt protidt +#endif + popf + pushl %ebp + pushl %ecx + pushl %eax + pushl %ebx + pushl %esi + pushl %edi + pushl %edx + + movb %al, intno + movl (%edx), %eax + movl %eax, LOCAL(bios_register_eax) + movw 4(%edx), %ax + movw %ax, LOCAL(bios_register_es) + movw 6(%edx), %ax + movw %ax, LOCAL(bios_register_ds) + movw 8(%edx), %ax + movw %ax, LOCAL(bios_register_flags) + + movl 12(%edx), %ebx + movl 16(%edx), %ecx + movl 20(%edx), %edi + movl 24(%edx), %esi + movl 28(%edx), %edx + + call prot_to_real + .code16 + pushf + cli +#ifndef GRUB_MACHINE_PCBIOS + lidt realidt +#endif + + mov %ds, %ax + push %ax + + /* movw imm16, %ax*/ + .byte 0xb8 +LOCAL(bios_register_es): + .short 0 + movw %ax, %es + /* movw imm16, %ax*/ + .byte 0xb8 +LOCAL(bios_register_ds): + .short 0 + movw %ax, %ds + + /* movw imm16, %ax*/ + .byte 0xb8 +LOCAL(bios_register_flags): + .short 0 + push %ax + popf + + /* movl imm32, %eax*/ + .byte 0x66, 0xb8 +LOCAL(bios_register_eax): + .long 0 + + /* int imm8. */ + .byte 0xcd +intno: + .byte 0 + + movl %eax, %cs:LOCAL(bios_register_eax) + movw %ds, %ax + movw %ax, %cs:LOCAL(bios_register_ds) + pop %ax + mov %ax, %ds + pushf + pop %ax + movw %ax, LOCAL(bios_register_flags) + mov %es, %ax + movw %ax, LOCAL(bios_register_es) + + popf + DATA32 call real_to_prot + .code32 + + popl %eax + + movl %ebx, 12(%eax) + movl %ecx, 16(%eax) + movl %edi, 20(%eax) + movl %esi, 24(%eax) + movl %edx, 28(%eax) + + movl %eax, %edx + + movl LOCAL(bios_register_eax), %eax + movl %eax, (%edx) + movw LOCAL(bios_register_es), %ax + movw %ax, 4(%edx) + movw LOCAL(bios_register_ds), %ax + movw %ax, 6(%edx) + movw LOCAL(bios_register_flags), %ax + movw %ax, 8(%edx) + + popl %edi + popl %esi + popl %ebx + popl %eax + popl %ecx + popl %ebp +#ifndef GRUB_MACHINE_PCBIOS + lidt protidt +#endif + ret +#ifndef GRUB_MACHINE_PCBIOS +realidt: + .word 0x100 + .long 0 +protidt: + .word 0 + .long 0 +#endif diff --git a/grub-core/kern/i386/pc/startup.S b/grub-core/kern/i386/pc/startup.S index e78a0aa9a..0fe114add 100644 --- a/grub-core/kern/i386/pc/startup.S +++ b/grub-core/kern/i386/pc/startup.S @@ -910,102 +910,4 @@ FUNCTION(grub_pxe_call) popl %ebp ret -FUNCTION(grub_bios_interrupt) - pushl %ebp - pushl %ecx - pushl %eax - pushl %ebx - pushl %esi - pushl %edi - pushl %edx - - movb %al, intno - movl (%edx), %eax - movl %eax, LOCAL(bios_register_eax) - movw 4(%edx), %ax - movw %ax, LOCAL(bios_register_es) - movw 6(%edx), %ax - movw %ax, LOCAL(bios_register_ds) - movw 8(%edx), %ax - movw %ax, LOCAL(bios_register_flags) - - movl 12(%edx), %ebx - movl 16(%edx), %ecx - movl 20(%edx), %edi - movl 24(%edx), %esi - movl 28(%edx), %edx - - call prot_to_real - .code16 - - mov %ds, %ax - push %ax - - /* movw imm16, %ax*/ - .byte 0xb8 -LOCAL(bios_register_es): - .short 0 - movw %ax, %es - /* movw imm16, %ax*/ - .byte 0xb8 -LOCAL(bios_register_ds): - .short 0 - movw %ax, %ds - - /* movw imm16, %ax*/ - .byte 0xb8 -LOCAL(bios_register_flags): - .short 0 - push %ax - popf - - /* movl imm32, %eax*/ - .byte 0x66, 0xb8 -LOCAL(bios_register_eax): - .long 0 - - /* int imm8. */ - .byte 0xcd -intno: - .byte 0 - - movl %eax, %cs:LOCAL(bios_register_eax) - movw %ds, %ax - movw %ax, %cs:LOCAL(bios_register_ds) - pop %ax - mov %ax, %ds - pushf - pop %ax - movw %ax, LOCAL(bios_register_flags) - mov %es, %ax - movw %ax, LOCAL(bios_register_es) - - DATA32 call real_to_prot - .code32 - - popl %eax - - movl %ebx, 12(%eax) - movl %ecx, 16(%eax) - movl %edi, 20(%eax) - movl %esi, 24(%eax) - movl %edx, 28(%eax) - - movl %eax, %edx - - movl LOCAL(bios_register_eax), %eax - movl %eax, (%edx) - movw LOCAL(bios_register_es), %ax - movw %ax, 4(%edx) - movw LOCAL(bios_register_ds), %ax - movw %ax, 6(%edx) - movw LOCAL(bios_register_flags), %ax - movw %ax, 8(%edx) - - popl %edi - popl %esi - popl %ebx - popl %eax - popl %ecx - popl %ebp - ret +#include "../int.S" diff --git a/grub-core/video/i386/pc/vbe.c b/grub-core/video/i386/pc/vbe.c index a109bcf43..c11b9a627 100644 --- a/grub-core/video/i386/pc/vbe.c +++ b/grub-core/video/i386/pc/vbe.c @@ -20,15 +20,14 @@ #include #include -#include -#include +#include #include #include #include #include #include #include -#include +#include GRUB_MOD_LICENSE ("GPLv3+"); @@ -377,7 +376,7 @@ grub_vbe_set_video_mode (grub_uint32_t vbe_mode, if (vbe_mode < 0x100) { /* If this is not a VESA mode, guess address. */ - framebuffer.ptr = (grub_uint8_t *) GRUB_MEMORY_MACHINE_VGA_ADDR; + framebuffer.ptr = (grub_uint8_t *) 0xa0000; } else { diff --git a/grub-core/video/i386/pc/vga.c b/grub-core/video/i386/pc/vga.c index fe387a26b..08c9ca37d 100644 --- a/grub-core/video/i386/pc/vga.c +++ b/grub-core/video/i386/pc/vga.c @@ -18,8 +18,7 @@ #define grub_video_render_target grub_video_fbrender_target -#include -#include +#include #include #include #include @@ -34,7 +33,7 @@ GRUB_MOD_LICENSE ("GPLv3+"); #define VGA_WIDTH 640 #define VGA_HEIGHT 350 -#define VGA_MEM ((grub_uint8_t *) GRUB_MEMORY_MACHINE_VGA_ADDR) +#define VGA_MEM ((grub_uint8_t *) 0xa0000) #define PAGE_OFFSET(x) ((x) * (VGA_WIDTH * VGA_HEIGHT / 8)) static unsigned char text_mode; diff --git a/include/grub/i386/coreboot/memory.h b/include/grub/i386/coreboot/memory.h index 0642280b9..2859b1d7c 100644 --- a/include/grub/i386/coreboot/memory.h +++ b/include/grub/i386/coreboot/memory.h @@ -28,6 +28,10 @@ #include #endif +#define GRUB_MEMORY_MACHINE_SCRATCH_ADDR 0x68000 +#define GRUB_MEMORY_MACHINE_SCRATCH_SEG (GRUB_MEMORY_MACHINE_SCRATCH_ADDR >> 4) +#define GRUB_MEMORY_MACHINE_SCRATCH_SIZE 0x10000 + #define GRUB_MEMORY_MACHINE_LOWER_USABLE 0x9fc00 /* 640 kiB - 1 kiB */ #define GRUB_MEMORY_MACHINE_UPPER_START 0x100000 /* 1 MiB */ diff --git a/include/grub/i386/pc/int.h b/include/grub/i386/pc/int.h index de23775d0..337752587 100644 --- a/include/grub/i386/pc/int.h +++ b/include/grub/i386/pc/int.h @@ -45,7 +45,12 @@ struct grub_bios_int_registers #define GRUB_CPU_INT_FLAGS_INTERRUPT 0x200 #define GRUB_CPU_INT_FLAGS_DIRECTION 0x400 #define GRUB_CPU_INT_FLAGS_OVERFLOW 0x800 +#ifdef GRUB_MACHINE_PCBIOS #define GRUB_CPU_INT_FLAGS_DEFAULT GRUB_CPU_INT_FLAGS_INTERRUPT +#else +#define GRUB_CPU_INT_FLAGS_DEFAULT 0 +#endif + void EXPORT_FUNC (grub_bios_interrupt) (grub_uint8_t intno, struct grub_bios_int_registers *regs); diff --git a/include/grub/i386/pc/vga.h b/include/grub/i386/pc/vga.h deleted file mode 100644 index ecc169022..000000000 --- a/include/grub/i386/pc/vga.h +++ /dev/null @@ -1,28 +0,0 @@ -/* - * GRUB -- GRand Unified Bootloader - * Copyright (C) 2003,2007,2008 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 . - */ - -#ifndef GRUB_VGA_MACHINE_HEADER -#define GRUB_VGA_MACHINE_HEADER 1 - -#include -#include - -/* The VGA (at the beginning of upper memory). */ -#define GRUB_MEMORY_MACHINE_VGA_ADDR GRUB_MEMORY_MACHINE_UPPER - -#endif /* ! GRUB_VGA_MACHINE_HEADER */ From efff4b1cc3e390533a7333420cf980d304bd10bc Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 27 Jun 2011 09:06:15 +0200 Subject: [PATCH 701/869] * util/grub-mkrescue.in: Rename "ata" to "pata" and add ahci when necessary. --- ChangeLog | 5 +++++ util/grub-mkrescue.in | 6 +++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 311e65b05..ca4145e33 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-06-27 Vladimir Serbinenko + + * util/grub-mkrescue.in: Rename "ata" to "pata" and add ahci when + necessary. + 2011-06-27 Vladimir Serbinenko Coreboot video support. diff --git a/util/grub-mkrescue.in b/util/grub-mkrescue.in index 8367c4dd4..f054c43a9 100644 --- a/util/grub-mkrescue.in +++ b/util/grub-mkrescue.in @@ -275,7 +275,7 @@ if test -e "${pc_dir}" ; then fi # build multiboot core.img -make_image "${multiboot_dir}" i386-multiboot "${iso9660_dir}/boot/multiboot.img" "ata at_keyboard" +make_image "${multiboot_dir}" i386-multiboot "${iso9660_dir}/boot/multiboot.img" "pata ahci at_keyboard" if test -e "${efi64_dir}" || test -e "${efi32_dir}"; then efi_dir=`mktemp -d "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` || exit 1 @@ -296,11 +296,11 @@ if test -e "${efi64_dir}" || test -e "${efi32_dir}"; then grub_mkisofs_arguments="${grub_mkisofs_arguments} --efi-boot efi.img" fi -make_image "${qemu_dir}" i386-qemu "${iso9660_dir}/boot/qemu.img" "ata at_keyboard" +make_image "${qemu_dir}" i386-qemu "${iso9660_dir}/boot/qemu.img" "pata at_keyboard" if [ -e "${iso9660_dir}/boot/qemu.img" ] && [ -d "${rom_directory}" ]; then cp "${iso9660_dir}/boot/qemu.img" "${rom_directory}/qemu.img" fi -make_image "${coreboot_dir}" i386-coreboot "${iso9660_dir}/boot/coreboot.elf" "ata at_keyboard" +make_image "${coreboot_dir}" i386-coreboot "${iso9660_dir}/boot/coreboot.elf" "pata ahci at_keyboard" if [ -e "${iso9660_dir}/boot/coreboot.elf" ] && [ -d "${rom_directory}" ]; then cp "${iso9660_dir}/boot/coreboot.elf" "${rom_directory}/coreboot.elf" fi From 1e3d9b8612a3f2a4c907b98d6465fcf4e7a53c4e Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 27 Jun 2011 10:12:35 +0200 Subject: [PATCH 702/869] * grub-core/disk/scsi.c (grub_scsi_read): Limit SCSI reads to 32K because of underlying system restrictions. --- ChangeLog | 5 +++++ grub-core/disk/scsi.c | 33 ++++++++++++++++++++++++++------- 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index ca4145e33..360842279 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-06-27 Vladimir Serbinenko + + * grub-core/disk/scsi.c (grub_scsi_read): Limit SCSI reads to 32K + because of underlying system restrictions. + 2011-06-27 Vladimir Serbinenko * util/grub-mkrescue.in: Rename "ata" to "pata" and add ahci when diff --git a/grub-core/disk/scsi.c b/grub-core/disk/scsi.c index 35b8525c2..902564164 100644 --- a/grub-core/disk/scsi.c +++ b/grub-core/disk/scsi.c @@ -524,17 +524,36 @@ grub_scsi_read (grub_disk_t disk, grub_disk_addr_t sector, scsi = disk->data; - /* Depending on the type, select a read function. */ - switch (scsi->devtype) + while (size) { - case grub_scsi_devtype_direct: - return grub_scsi_read10 (disk, sector, size, buf); + /* PATA doesn't support more than 32K reads. + Not sure about AHCI and USB. If it's confirmed that either of + them can do bigger reads reliably this value can be moved to 'scsi' + structure. */ + grub_size_t len = 32768 >> disk->log_sector_size; + grub_err_t err; + if (len > size) + len = size; + /* Depending on the type, select a read function. */ + switch (scsi->devtype) + { + case grub_scsi_devtype_direct: + err = grub_scsi_read10 (disk, sector, len, buf); + if (err) + return err; + break; - case grub_scsi_devtype_cdrom: - return grub_scsi_read12 (disk, sector, size, buf); + case grub_scsi_devtype_cdrom: + err = grub_scsi_read12 (disk, sector, len, buf); + if (err) + return err; + break; + } + size -= len; + sector += len; + buf += len << disk->log_sector_size; } - /* XXX: Never reached. */ return GRUB_ERR_NONE; #if 0 /* Workaround - it works - but very slowly, from some reason From f9b75e8a67f54b425b64c62ea68d7ced88c566bd Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Mon, 27 Jun 2011 10:47:02 +0100 Subject: [PATCH 703/869] * grub-core/commands/videoinfo.c (hook): Indicate current video mode with `*'. (grub_cmd_videoinfo): Fetch current video mode. --- ChangeLog | 6 ++++++ grub-core/commands/videoinfo.c | 25 +++++++++++++++++++++++-- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 360842279..1aabd6b18 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2011-06-27 Colin Watson + + * grub-core/commands/videoinfo.c (hook): Indicate current video mode + with `*'. + (grub_cmd_videoinfo): Fetch current video mode. + 2011-06-27 Vladimir Serbinenko * grub-core/disk/scsi.c (grub_scsi_read): Limit SCSI reads to 32K diff --git a/grub-core/commands/videoinfo.c b/grub-core/commands/videoinfo.c index 3e0c1a12e..91a87fecc 100644 --- a/grub-core/commands/videoinfo.c +++ b/grub-core/commands/videoinfo.c @@ -28,6 +28,7 @@ GRUB_MOD_LICENSE ("GPLv3+"); static unsigned height, width, depth; +static struct grub_video_mode_info *current_mode; static int hook (const struct grub_video_mode_info *info) @@ -41,7 +42,13 @@ hook (const struct grub_video_mode_info *info) if (info->mode_number == GRUB_VIDEO_MODE_NUMBER_INVALID) grub_printf (" "); else - grub_printf (" 0x%03x ", info->mode_number); + { + if (current_mode && info->mode_number == current_mode->mode_number) + grub_printf ("*"); + else + grub_printf (" "); + grub_printf (" 0x%03x ", info->mode_number); + } grub_printf ("%4d x %4d x %2d ", info->width, info->height, info->bpp); if (info->mode_type & GRUB_VIDEO_MODE_TYPE_PURE_TEXT) @@ -122,6 +129,8 @@ grub_cmd_videoinfo (grub_command_t cmd __attribute__ ((unused)), FOR_VIDEO_ADAPTERS (adapter) { + struct grub_video_mode_info info; + grub_printf ("Adapter '%s':\n", adapter->name); if (!adapter->iterate) @@ -130,7 +139,17 @@ grub_cmd_videoinfo (grub_command_t cmd __attribute__ ((unused)), continue; } - if (adapter->id != id) + current_mode = NULL; + + if (adapter->id == id) + { + if (grub_video_get_info (&info) == GRUB_ERR_NONE) + current_mode = &info; + else + /* Don't worry about errors. */ + grub_errno = GRUB_ERR_NONE; + } + else { if (adapter->init ()) { @@ -145,6 +164,8 @@ grub_cmd_videoinfo (grub_command_t cmd __attribute__ ((unused)), adapter->iterate (hook); + current_mode = NULL; + if (adapter->id != id) { if (adapter->fini ()) From b6f945dccbf99c7126cca5b01f4cea807ccffc9e Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 27 Jun 2011 12:13:21 +0200 Subject: [PATCH 704/869] * grub-core/net/drivers/ieee1275/ofnet.c (send_card_buffer) Use right type in pointers on sparc64. (get_card_packet): Likewise. --- ChangeLog | 6 ++++++ grub-core/net/drivers/ieee1275/ofnet.c | 5 +++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1aabd6b18..1a3237f88 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2011-06-27 Vladimir Serbinenko + + * grub-core/net/drivers/ieee1275/ofnet.c (send_card_buffer) Use right + type in pointers on sparc64. + (get_card_packet): Likewise. + 2011-06-27 Colin Watson * grub-core/commands/videoinfo.c (hook): Indicate current video mode diff --git a/grub-core/net/drivers/ieee1275/ofnet.c b/grub-core/net/drivers/ieee1275/ofnet.c index 0394e0dc0..b5bb03dc8 100644 --- a/grub-core/net/drivers/ieee1275/ofnet.c +++ b/grub-core/net/drivers/ieee1275/ofnet.c @@ -39,7 +39,7 @@ card_close (struct grub_net_card *dev) static grub_err_t send_card_buffer (const struct grub_net_card *dev, struct grub_net_buff *pack) { - int actual; + grub_ssize_t actual; int status; struct grub_ofnetcard_data *data = dev->data; @@ -54,7 +54,8 @@ send_card_buffer (const struct grub_net_card *dev, struct grub_net_buff *pack) static grub_ssize_t get_card_packet (const struct grub_net_card *dev, struct grub_net_buff *nb) { - int actual, rc; + grub_ssize_t actual; + int rc; struct grub_ofnetcard_data *data = dev->data; grub_uint64_t start_time; From b28c56559b446bdc824fe650a641aa9e11923448 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 27 Jun 2011 12:16:00 +0200 Subject: [PATCH 705/869] * util/ieee1275/grub-ofpathname.c (main): Handle --help and --version so that help2man doesn't fail. --- ChangeLog | 5 +++++ util/ieee1275/grub-ofpathname.c | 7 ++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 1a3237f88..37446af70 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-06-27 Vladimir Serbinenko + + * util/ieee1275/grub-ofpathname.c (main): Handle --help and --version + so that help2man doesn't fail. + 2011-06-27 Vladimir Serbinenko * grub-core/net/drivers/ieee1275/ofnet.c (send_card_buffer) Use right diff --git a/util/ieee1275/grub-ofpathname.c b/util/ieee1275/grub-ofpathname.c index 3ac6fce8b..a9bc2cfda 100644 --- a/util/ieee1275/grub-ofpathname.c +++ b/util/ieee1275/grub-ofpathname.c @@ -32,11 +32,16 @@ int main(int argc, char **argv) grub_util_init_nls (); - if (argc != 2) + if (argc != 2 || strcmp (argv[1], "--help") == 0) { printf("Usage: %s DEVICE\n", program_name); return 1; } + if (strcmp (argv[1], "--version") == 0) + { + printf ("%s\n", PACKAGE_STRING); + return 1; + } of_path = grub_util_devname_to_ofpath (argv[1]); printf("%s\n", of_path); From bdea37983323f19d0cf8d2ef529d4d0f88ba2d81 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 27 Jun 2011 12:18:44 +0200 Subject: [PATCH 706/869] * grub-core/lib/relocator.c (malloc_in_range): Fix a memory corruption when handling leftovers. --- ChangeLog | 5 +++++ grub-core/lib/relocator.c | 13 +++++++------ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index 37446af70..e35b7c7ff 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-06-27 Vladimir Serbinenko + + * grub-core/lib/relocator.c (malloc_in_range): Fix a memory corruption + when handling leftovers. + 2011-06-27 Vladimir Serbinenko * util/ieee1275/grub-ofpathname.c (main): Handle --help and --version diff --git a/grub-core/lib/relocator.c b/grub-core/lib/relocator.c index 6eb20b865..aa404731f 100644 --- a/grub-core/lib/relocator.c +++ b/grub-core/lib/relocator.c @@ -764,6 +764,9 @@ malloc_in_range (struct grub_relocator *rel, int inreg = 0, regbeg = 0, ncol = 0; #if GRUB_RELOCATOR_HAVE_FIRMWARE_REQUESTS int fwin = 0, fwb = 0, fwlefto = 0; +#endif +#if GRUB_RELOCATOR_HAVE_LEFTOVERS + int last_lo = 0; #endif int last_start = 0; for (j = 0; j < N; j++) @@ -855,7 +858,7 @@ malloc_in_range (struct grub_relocator *rel, unsigned offend = alloc_end % GRUB_RELOCATOR_FIRMWARE_REQUESTS_QUANT; struct grub_relocator_fw_leftover *lo - = events[last_start].leftover; + = events[last_lo].leftover; lo->freebytes[offstart / 8] &= ((1 << (8 - (start % 8))) - 1); grub_memset (lo->freebytes + (offstart + 7) / 8, 0, @@ -910,6 +913,7 @@ malloc_in_range (struct grub_relocator *rel, #if GRUB_RELOCATOR_HAVE_LEFTOVERS case REG_LEFTOVER_START: fwlefto++; + last_lo = j; break; case REG_LEFTOVER_END: @@ -1009,7 +1013,8 @@ malloc_in_range (struct grub_relocator *rel, curschu->extra = ne; } } -#if GRUB_RELOCATOR_HAVE_FIRMWARE_REQUESTS + +#if GRUB_RELOCATOR_HAVE_LEFTOVERS if (!oom && typepre == CHUNK_TYPE_FIRMWARE) { grub_addr_t fstart, fend; @@ -1021,7 +1026,6 @@ malloc_in_range (struct grub_relocator *rel, = ALIGN_UP (alloc_end, GRUB_RELOCATOR_FIRMWARE_REQUESTS_QUANT); -#if GRUB_RELOCATOR_HAVE_LEFTOVERS { struct grub_relocator_fw_leftover *lo1 = NULL; struct grub_relocator_fw_leftover *lo2 = NULL; @@ -1081,10 +1085,8 @@ malloc_in_range (struct grub_relocator *rel, curschu->pre = lo1; curschu->post = lo2; } -#endif } -#if GRUB_RELOCATOR_HAVE_LEFTOVERS if (typepre == CHUNK_TYPE_LEFTOVER) { curschu->pre = events[last_start].leftover; @@ -1092,7 +1094,6 @@ malloc_in_range (struct grub_relocator *rel, } #endif -#endif if (!oom) cural++; else From 5ebaad7eec21a1d209d781b8c0b17f993a238380 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 27 Jun 2011 12:28:47 +0200 Subject: [PATCH 707/869] * include/grub/loader.h (grub_loader_unregister_preboot_hook): Export. --- ChangeLog | 4 ++++ include/grub/loader.h | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index e35b7c7ff..866e2ccaf 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2011-06-27 Vladimir Serbinenko + + * include/grub/loader.h (grub_loader_unregister_preboot_hook): Export. + 2011-06-27 Vladimir Serbinenko * grub-core/lib/relocator.c (malloc_in_range): Fix a memory corruption diff --git a/include/grub/loader.h b/include/grub/loader.h index c71e8dd10..f38deb96a 100644 --- a/include/grub/loader.h +++ b/include/grub/loader.h @@ -61,6 +61,6 @@ void *EXPORT_FUNC(grub_loader_register_preboot_hook) (grub_err_t (*preboot_func) grub_loader_preboot_hook_prio_t prio); /* Unregister given preboot hook. */ -void grub_loader_unregister_preboot_hook (void *hnd); +void EXPORT_FUNC (grub_loader_unregister_preboot_hook) (void *hnd); #endif /* ! GRUB_LOADER_HEADER */ From 5ff1d945ed89aa6203fdc005a55dbb83b3380ea1 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 27 Jun 2011 12:31:37 +0200 Subject: [PATCH 708/869] Implement time command. * grub-core/Makefile.core.def (time): New module. * grub-core/commands/time.c: New file. * grub-core/script/parser.y: Remove "time" keyword. * grub-core/script/yylex.l: Likewise. --- ChangeLog | 9 +++++ grub-core/Makefile.core.def | 5 +++ grub-core/commands/time.c | 68 +++++++++++++++++++++++++++++++++++++ grub-core/script/parser.y | 2 -- grub-core/script/yylex.l | 1 - 5 files changed, 82 insertions(+), 3 deletions(-) create mode 100644 grub-core/commands/time.c diff --git a/ChangeLog b/ChangeLog index 866e2ccaf..4cdbc2b15 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2011-06-27 Vladimir Serbinenko + + Implement time command. + + * grub-core/Makefile.core.def (time): New module. + * grub-core/commands/time.c: New file. + * grub-core/script/parser.y: Remove "time" keyword. + * grub-core/script/yylex.l: Likewise. + 2011-06-27 Vladimir Serbinenko * include/grub/loader.h (grub_loader_unregister_preboot_hook): Export. diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def index 7a0536b97..b10c16d55 100644 --- a/grub-core/Makefile.core.def +++ b/grub-core/Makefile.core.def @@ -1641,3 +1641,8 @@ module = { common = commands/keylayouts.c; enable = videomodules; }; + +module = { + name = time; + common = commands/time.c; +}; diff --git a/grub-core/commands/time.c b/grub-core/commands/time.c new file mode 100644 index 000000000..687495964 --- /dev/null +++ b/grub-core/commands/time.c @@ -0,0 +1,68 @@ +/* echo.c - Command to display a line of text */ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2011 Free Software Foundation, Inc. + * + * GRUB is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see . + */ + +#include +#include +#include +#include +#include + +GRUB_MOD_LICENSE ("GPLv3+"); + + +static grub_err_t +grub_cmd_time (grub_command_t ctxt __attribute__ ((unused)), + int argc, char **args) +{ + grub_command_t cmd; + grub_uint32_t start; + grub_uint32_t end; + + if (argc == 0) + return grub_error (GRUB_ERR_BAD_ARGUMENT, "command expected"); + + cmd = grub_command_find (args[0]); + + if (!cmd) + return grub_error (GRUB_ERR_UNKNOWN_COMMAND, "Unknown command `%s'\n", + args[0]); + + start = grub_get_time_ms (); + (cmd->func) (cmd, argc - 1, &args[1]); + end = grub_get_time_ms (); + + grub_printf ("Elapsed time: %d.%03d seconds \n", (end - start) / 1000, + (end - start) % 1000); + + return grub_errno; +} + +static grub_command_t cmd; + +GRUB_MOD_INIT(time) +{ + cmd = grub_register_command ("time", grub_cmd_time, + N_("COMMAND [ARGS]"), + N_("Measure time used by COMMAND")); +} + +GRUB_MOD_FINI(time) +{ + grub_unregister_command (cmd); +} diff --git a/grub-core/script/parser.y b/grub-core/script/parser.y index 683b3ac4b..cc20b5479 100644 --- a/grub-core/script/parser.y +++ b/grub-core/script/parser.y @@ -74,7 +74,6 @@ %token GRUB_PARSER_TOKEN_THEN "then" %token GRUB_PARSER_TOKEN_UNTIL "until" %token GRUB_PARSER_TOKEN_WHILE "while" -%token GRUB_PARSER_TOKEN_TIME "time" %token GRUB_PARSER_TOKEN_FUNCTION "function" %token GRUB_PARSER_TOKEN_NAME "name" %token GRUB_PARSER_TOKEN_WORD "word" @@ -147,7 +146,6 @@ argument : "case" { $$ = grub_script_add_arglist (state, 0, $1); } | "until" { $$ = grub_script_add_arglist (state, 0, $1); } | "while" { $$ = grub_script_add_arglist (state, 0, $1); } | "function" { $$ = grub_script_add_arglist (state, 0, $1); } - | "time" { $$ = grub_script_add_arglist (state, 0, $1); } | word { $$ = $1; } ; diff --git a/grub-core/script/yylex.l b/grub-core/script/yylex.l index 96f57dbe6..7195a880d 100644 --- a/grub-core/script/yylex.l +++ b/grub-core/script/yylex.l @@ -161,7 +161,6 @@ MULTILINE {WORD}?((\"{DQCHR}*)|(\'{SQCHR}*)|(\\\n)) "}" { RECORD; return GRUB_PARSER_TOKEN_RBR; } "[[" { RECORD; return GRUB_PARSER_TOKEN_RSQBR2; } "]]" { RECORD; return GRUB_PARSER_TOKEN_LSQBR2; } -"time" { RECORD; return GRUB_PARSER_TOKEN_TIME; } "case" { RECORD; return GRUB_PARSER_TOKEN_CASE; } "do" { RECORD; return GRUB_PARSER_TOKEN_DO; } "done" { RECORD; return GRUB_PARSER_TOKEN_DONE; } From d0b526b2778db75c5cfd01182de7f3808f466a1a Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 27 Jun 2011 13:57:03 +0200 Subject: [PATCH 709/869] * grub-core/loader/i386/bsd.c (grub_bsd_load): Handle relocator failure if it happens. --- ChangeLog | 5 +++++ grub-core/loader/i386/bsd.c | 7 ++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 4cdbc2b15..c097af2f7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-06-27 Vladimir Serbinenko + + * grub-core/loader/i386/bsd.c (grub_bsd_load): Handle relocator failure + if it happens. + 2011-06-27 Vladimir Serbinenko Implement time command. diff --git a/grub-core/loader/i386/bsd.c b/grub-core/loader/i386/bsd.c index 6487dc3df..dffe48257 100644 --- a/grub-core/loader/i386/bsd.c +++ b/grub-core/loader/i386/bsd.c @@ -1322,6 +1322,11 @@ grub_bsd_load (int argc, char *argv[]) goto fail; relocator = grub_relocator_new (); + if (!relocator) + { + grub_file_close (file); + goto fail; + } elf = grub_elf_file (file); if (elf) @@ -1343,7 +1348,7 @@ grub_bsd_load (int argc, char *argv[]) fail: if (grub_errno != GRUB_ERR_NONE) - grub_dl_unref (my_mod); + grub_dl_unref (my_mod); return grub_errno; } From ba7df45ee6be05bb9fd781041f915f112fa8e52c Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 27 Jun 2011 14:14:11 +0200 Subject: [PATCH 710/869] Chainloading on coreboot support. * grub-core/Makefile.core.def (chain): Add coreboot. * grub-core/loader/i386/coreboot/chainloader.c: New file. --- ChangeLog | 7 + grub-core/Makefile.core.def | 2 + grub-core/loader/i386/coreboot/chainloader.c | 145 +++++++++++++++++++ 3 files changed, 154 insertions(+) create mode 100644 grub-core/loader/i386/coreboot/chainloader.c diff --git a/ChangeLog b/ChangeLog index c097af2f7..9922f2a2b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2011-06-27 Vladimir Serbinenko + + Chainloading on coreboot support. + + * grub-core/Makefile.core.def (chain): Add coreboot. + * grub-core/loader/i386/coreboot/chainloader.c: New file. + 2011-06-27 Vladimir Serbinenko * grub-core/loader/i386/bsd.c (grub_bsd_load): Handle relocator failure diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def index b10c16d55..faed6cc85 100644 --- a/grub-core/Makefile.core.def +++ b/grub-core/Makefile.core.def @@ -1298,7 +1298,9 @@ module = { name = chain; efi = loader/efi/chainloader.c; i386_pc = loader/i386/pc/chainloader.c; + i386_coreboot = loader/i386/corepayload.c; enable = i386_pc; + enable = i386_coreboot; enable = efi; }; diff --git a/grub-core/loader/i386/coreboot/chainloader.c b/grub-core/loader/i386/coreboot/chainloader.c new file mode 100644 index 000000000..3f85aa3a9 --- /dev/null +++ b/grub-core/loader/i386/coreboot/chainloader.c @@ -0,0 +1,145 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2011 Free Software Foundation, Inc. + * + * GRUB is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see . + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +GRUB_MOD_LICENSE ("GPLv3+"); + +static grub_addr_t entry; +static struct grub_relocator *relocator = NULL; + +static grub_err_t +grub_chain_boot (void) +{ + struct grub_relocator32_state state; + + grub_video_set_mode ("text", 0, 0); + + state.eip = entry; + return grub_relocator32_boot (relocator, state); +} + +static grub_err_t +grub_chain_unload (void) +{ + grub_relocator_unload (relocator); + relocator = NULL; + + return GRUB_ERR_NONE; +} + +static grub_err_t +grub_chain_elf32_hook (Elf32_Phdr * phdr, grub_addr_t * addr, int *do_load) +{ + grub_err_t err; + grub_relocator_chunk_t ch; + + if (phdr->p_type != PT_LOAD) + { + *do_load = 0; + return 0; + } + + *do_load = 1; + err = grub_relocator_alloc_chunk_addr (relocator, &ch, + phdr->p_paddr, phdr->p_memsz); + if (err) + return err; + + *addr = (grub_addr_t) get_virtual_current_address (ch); + + return GRUB_ERR_NONE; +} + + +static grub_err_t +grub_cmd_chain (grub_command_t cmd __attribute__ ((unused)), + int argc, char *argv[]) +{ + grub_err_t err; + grub_file_t file; + grub_elf_t elf; + + if (argc != 1) + return grub_error (GRUB_ERR_BAD_ARGUMENT, "filename expected"); + + grub_loader_unset (); + + file = grub_file_open (argv[0]); + if (!file) + return grub_errno; + + relocator = grub_relocator_new (); + if (!relocator) + { + grub_file_close (file); + return grub_errno; + } + + elf = grub_elf_file (file); + if (!elf) + { + grub_relocator_unload (relocator); + relocator = 0; + grub_file_close (file); + } + + if (!grub_elf_is_elf32 (elf)) + { + grub_relocator_unload (relocator); + relocator = 0; + grub_elf_close (elf); + } + + entry = elf->ehdr.ehdr32.e_entry & 0xFFFFFF; + + err = grub_elf32_load (elf, grub_chain_elf32_hook, 0, 0); + + grub_elf_close (elf); + if (err) + return err; + + grub_loader_set (grub_chain_boot, grub_chain_unload, 0); + return GRUB_ERR_NONE; +} + +static grub_command_t cmd_chain; + +GRUB_MOD_INIT (chain) +{ + cmd_chain = grub_register_command ("chainloader", grub_cmd_chain, + N_("FILE"), N_("Load another payload")); +} + +GRUB_MOD_FINI (chain) +{ + grub_unregister_command (cmd_chain); + grub_chain_unload (); +} From 5afeb5bdd615f18ef58316132112a3a9b6e4c823 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 27 Jun 2011 19:26:52 +0200 Subject: [PATCH 711/869] * grub-core/disk/pata.c (grub_pata_initialize) [QEMU_MIPS]: Fix a mismerge. --- ChangeLog | 5 +++++ grub-core/disk/pata.c | 8 +++----- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9922f2a2b..a9dacd42b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-06-27 Vladimir Serbinenko + + * grub-core/disk/pata.c (grub_pata_initialize) [QEMU_MIPS]: Fix a + mismerge. + 2011-06-27 Vladimir Serbinenko Chainloading on coreboot support. diff --git a/grub-core/disk/pata.c b/grub-core/disk/pata.c index ac3b91a41..95828e8f6 100644 --- a/grub-core/disk/pata.c +++ b/grub-core/disk/pata.c @@ -438,15 +438,13 @@ grub_pata_initialize (void) } #else static grub_err_t -grub_ata_initialize (void) +grub_pata_initialize (void) { int i; for (i = 0; i < 2; i++) { - grub_ata_device_initialize (i, 0, grub_ata_ioaddress[i], - grub_ata_ioaddress2[i]); - grub_ata_device_initialize (i, 1, grub_ata_ioaddress[i], - grub_ata_ioaddress2[i]); + grub_pata_device_initialize (i, 0, grub_pata_ioaddress[i]); + grub_pata_device_initialize (i, 1, grub_pata_ioaddress[i]); } return 0; } From 8d5d8444bd95338d487e715e9c93fa3328137b9d Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 27 Jun 2011 19:30:16 +0200 Subject: [PATCH 712/869] * grub-core/Makefile.core.def (chain): Fix coreboot filename. --- ChangeLog | 4 ++++ grub-core/Makefile.core.def | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index a9dacd42b..81d98716d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2011-06-27 Vladimir Serbinenko + + * grub-core/Makefile.core.def (chain): Fix coreboot filename. + 2011-06-27 Vladimir Serbinenko * grub-core/disk/pata.c (grub_pata_initialize) [QEMU_MIPS]: Fix a diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def index faed6cc85..fd69e9c22 100644 --- a/grub-core/Makefile.core.def +++ b/grub-core/Makefile.core.def @@ -1298,7 +1298,7 @@ module = { name = chain; efi = loader/efi/chainloader.c; i386_pc = loader/i386/pc/chainloader.c; - i386_coreboot = loader/i386/corepayload.c; + i386_coreboot = loader/i386/coreboot/chainloader.c; enable = i386_pc; enable = i386_coreboot; enable = efi; From 548947916b74f8b4b66f88a4cf08b233fd31047c Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Tue, 28 Jun 2011 17:05:41 +0100 Subject: [PATCH 713/869] * grub-core/term/gfxterm.c (grub_virtual_screen_setup): Use default_bg_color rather than black. (grub_gfxterm_fullscreen): Likewise. (grub_gfxterm_background_color_cmd): Save new background color in default_bg_color. --- ChangeLog | 8 ++++++++ grub-core/term/gfxterm.c | 16 +++++++++------- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index 81d98716d..4b8d8f149 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2011-06-28 Colin Watson + + * grub-core/term/gfxterm.c (grub_virtual_screen_setup): Use + default_bg_color rather than black. + (grub_gfxterm_fullscreen): Likewise. + (grub_gfxterm_background_color_cmd): Save new background color in + default_bg_color. + 2011-06-27 Vladimir Serbinenko * grub-core/Makefile.core.def (chain): Fix coreboot filename. diff --git a/grub-core/term/gfxterm.c b/grub-core/term/gfxterm.c index 9e3d8eeb1..2f8deac18 100644 --- a/grub-core/term/gfxterm.c +++ b/grub-core/term/gfxterm.c @@ -131,6 +131,7 @@ static unsigned int bitmap_width; static unsigned int bitmap_height; static struct grub_video_bitmap *bitmap; static int blend_text_bg; +static grub_video_rgba_color_t default_bg_color = { 0, 0, 0, 0 }; static struct grub_dirty_region dirty_region; @@ -266,7 +267,8 @@ grub_virtual_screen_setup (unsigned int x, unsigned int y, grub_video_set_active_render_target (render_target); - virtual_screen.bg_color_display = grub_video_map_rgba(0, 0, 0, 0); + virtual_screen.bg_color_display = + grub_video_map_rgba_color (default_bg_color); /* Clear out text buffer. */ for (i = 0; i < virtual_screen.columns * virtual_screen.rows; i++) @@ -338,8 +340,8 @@ grub_gfxterm_fullscreen (void) double_redraw = mode_info.mode_type & GRUB_VIDEO_MODE_TYPE_DOUBLE_BUFFERED && !(mode_info.mode_type & GRUB_VIDEO_MODE_TYPE_UPDATING_SWAP); - /* Make sure screen is black. */ - color = grub_video_map_rgb (0, 0, 0); + /* Make sure screen is set to the default background color. */ + color = grub_video_map_rgba_color (default_bg_color); grub_video_fill_rect (color, 0, 0, mode_info.width, mode_info.height); if (double_redraw) { @@ -1189,7 +1191,6 @@ static grub_err_t grub_gfxterm_background_color_cmd (grub_command_t cmd __attribute__ ((unused)), int argc, char **args) { - grub_video_rgba_color_t color; struct grub_video_render_target *old_target; if (argc != 1) @@ -1199,7 +1200,7 @@ grub_gfxterm_background_color_cmd (grub_command_t cmd __attribute__ ((unused)), if (grub_video_get_info (NULL) != GRUB_ERR_NONE) return grub_errno; - if (grub_video_parse_color (args[0], &color) != GRUB_ERR_NONE) + if (grub_video_parse_color (args[0], &default_bg_color) != GRUB_ERR_NONE) return grub_errno; /* Destroy existing background bitmap if loaded. */ @@ -1216,9 +1217,10 @@ grub_gfxterm_background_color_cmd (grub_command_t cmd __attribute__ ((unused)), compatible with the text layer. */ grub_video_get_active_render_target (&old_target); grub_video_set_active_render_target (text_layer); - virtual_screen.bg_color = grub_video_map_rgba_color (color); + virtual_screen.bg_color = grub_video_map_rgba_color (default_bg_color); grub_video_set_active_render_target (old_target); - virtual_screen.bg_color_display = grub_video_map_rgba_color (color); + virtual_screen.bg_color_display = + grub_video_map_rgba_color (default_bg_color); blend_text_bg = 1; /* Mark whole screen as dirty. */ From 574618a2e9a1dc8daf46c0e929acb0353f5f0101 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 2 Jul 2011 14:09:36 +0200 Subject: [PATCH 714/869] unify prefix handling across platforms --- grub-core/Makefile.core.def | 5 +- grub-core/boot/i386/pc/diskboot.S | 2 +- grub-core/disk/efi/efidisk.c | 30 +++-- grub-core/kern/efi/init.c | 84 ++---------- grub-core/kern/emu/main.c | 16 +-- grub-core/kern/i386/coreboot/init.c | 5 +- grub-core/kern/i386/efi/init.c | 6 - grub-core/kern/i386/pc/init.c | 78 +++++------ grub-core/kern/ia64/efi/init.c | 6 - grub-core/kern/ieee1275/cmain.c | 4 + grub-core/kern/ieee1275/init.c | 90 ++++++------- grub-core/kern/ieee1275/openfw.c | 5 + grub-core/kern/main.c | 70 ++++++++-- grub-core/kern/mips/init.c | 4 +- grub-core/kern/sparc64/ieee1275/init.c | 174 ------------------------- include/grub/kernel.h | 5 +- include/grub/offsets.h | 4 +- 17 files changed, 189 insertions(+), 399 deletions(-) delete mode 100644 grub-core/kern/sparc64/ieee1275/init.c diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def index ac969e09c..df852e09e 100644 --- a/grub-core/Makefile.core.def +++ b/grub-core/Makefile.core.def @@ -102,6 +102,7 @@ kernel = { ieee1275 = kern/ieee1275/mmap.c; ieee1275 = kern/ieee1275/openfw.c; ieee1275 = term/ieee1275/ofconsole.c; + ieee1275 = kern/ieee1275/init.c; terminfoinkernel = term/terminfo.c; terminfoinkernel = term/tparm.c; @@ -153,8 +154,6 @@ kernel = { i386_multiboot = kern/i386/multiboot_mmap.c; i386_multiboot = kern/i386/tsc.c; - i386_ieee1275 = kern/ieee1275/init.c; - mips = kern/mips/cache.S; mips = kern/mips/dl.c; mips = kern/mips/init.c; @@ -179,14 +178,12 @@ kernel = { extra_dist = video/sm712_init.c; mips_loongson = commands/keylayouts.c; - powerpc_ieee1275 = kern/ieee1275/init.c; powerpc_ieee1275 = kern/powerpc/cache.S; powerpc_ieee1275 = kern/powerpc/dl.c; sparc64_ieee1275 = kern/sparc64/cache.S; sparc64_ieee1275 = kern/sparc64/dl.c; sparc64_ieee1275 = kern/sparc64/ieee1275/ieee1275.c; - sparc64_ieee1275 = kern/sparc64/ieee1275/init.c; emu = disk/host.c; emu = gnulib/progname.c; diff --git a/grub-core/boot/i386/pc/diskboot.S b/grub-core/boot/i386/pc/diskboot.S index 92f223f0d..336c3bcca 100644 --- a/grub-core/boot/i386/pc/diskboot.S +++ b/grub-core/boot/i386/pc/diskboot.S @@ -83,7 +83,7 @@ LOCAL(setup_sectors): /* the maximum is limited to 0x7f because of Phoenix EDD */ xorl %eax, %eax - movb $0x7f, %al + movb $0x1, %al /* how many do we really want to read? */ cmpw %ax, 8(%di) /* compare against total number of sectors */ diff --git a/grub-core/disk/efi/efidisk.c b/grub-core/disk/efi/efidisk.c index 35602513e..5dc753046 100644 --- a/grub-core/disk/efi/efidisk.c +++ b/grub-core/disk/efi/efidisk.c @@ -530,7 +530,7 @@ grub_efidisk_open (const char *name, struct grub_disk *disk) and total sectors should be replaced with total blocks. */ grub_dprintf ("efidisk", "m = %p, last block = %llx, block size = %x\n", m, (unsigned long long) m->last_block, m->block_size); - disk->total_sectors = m->last_block; + disk->total_sectors = m->last_block + 1; if (m->block_size & (m->block_size - 1) || !m->block_size) return grub_error (GRUB_ERR_IO, "invalid sector size %d", m->block_size); @@ -788,19 +788,27 @@ grub_efidisk_get_device_name (grub_efi_handle_t *handle) /* Find a partition which matches the hard drive device path. */ grub_memcpy (&hd, ldp, sizeof (hd)); - grub_partition_iterate (parent, find_partition); - - if (! tpart) + if (hd.partition_start == 0 + && hd.partition_size == grub_disk_get_size (parent)) { - grub_disk_close (parent); - return 0; + device_name = grub_strdup (parent->name); } + else + { + char *partition_name; - { - char *partition_name = grub_partition_get_name (tpart); - device_name = grub_xasprintf ("%s,%s", parent->name, partition_name); - grub_free (partition_name); - } + grub_partition_iterate (parent, find_partition); + + if (! tpart) + { + grub_disk_close (parent); + return 0; + } + + partition_name = grub_partition_get_name (tpart); + device_name = grub_xasprintf ("%s,%s", parent->name, partition_name); + grub_free (partition_name); + } grub_disk_close (parent); return device_name; diff --git a/grub-core/kern/efi/init.c b/grub-core/kern/efi/init.c index 1b0a872b4..a7325acc6 100644 --- a/grub-core/kern/efi/init.c +++ b/grub-core/kern/efi/init.c @@ -43,83 +43,21 @@ grub_efi_init (void) } void -grub_efi_set_prefix (void) +grub_machine_get_bootlocation (char **device, char **path) { grub_efi_loaded_image_t *image = NULL; - char *device = NULL; - char *path = NULL; + char *p; - { - char *pptr = NULL; - if (grub_prefix[0] == '(') - { - pptr = grub_strrchr (grub_prefix, ')'); - if (pptr) - { - device = grub_strndup (grub_prefix + 1, pptr - grub_prefix - 1); - pptr++; - } - } - if (!pptr) - pptr = grub_prefix; - if (pptr[0]) - path = grub_strdup (pptr); - } + image = grub_efi_get_loaded_image (grub_efi_image_handle); + if (!image) + return; + *device = grub_efidisk_get_device_name (image->device_handle); + *path = grub_efi_get_filename (image->file_path); - if ((!device || device[0] == ',' || !device[0]) || !path) - image = grub_efi_get_loaded_image (grub_efi_image_handle); - if (image) - { - if (!device) - device = grub_efidisk_get_device_name (image->device_handle); - else if (device[0] == ',' || !device[0]) - { - /* We have a partition, but still need to fill in the drive. */ - char *image_device, *comma, *new_device; - - image_device = grub_efidisk_get_device_name (image->device_handle); - comma = grub_strchr (image_device, ','); - if (comma) - { - char *drive = grub_strndup (image_device, comma - image_device); - new_device = grub_xasprintf ("%s%s", drive, device); - grub_free (drive); - } - else - new_device = grub_xasprintf ("%s%s", image_device, device); - - grub_free (image_device); - grub_free (device); - device = new_device; - } - } - - if (image && !path) - { - char *p; - - path = grub_efi_get_filename (image->file_path); - - /* Get the directory. */ - p = grub_strrchr (path, '/'); - if (p) - *p = '\0'; - } - - if (device && path) - { - char *prefix; - - prefix = grub_xasprintf ("(%s)%s", device, path); - if (prefix) - { - grub_env_set ("prefix", prefix); - grub_free (prefix); - } - } - - grub_free (device); - grub_free (path); + /* Get the directory. */ + p = grub_strrchr (*path, '/'); + if (p) + *p = '\0'; } void diff --git a/grub-core/kern/emu/main.c b/grub-core/kern/emu/main.c index 0a7645992..096e97090 100644 --- a/grub-core/kern/emu/main.c +++ b/grub-core/kern/emu/main.c @@ -49,7 +49,7 @@ static jmp_buf main_env; /* Store the prefix specified by an argument. */ -static char *prefix = NULL; +static char *root_dev = NULL, *dir = DEFAULT_DIRECTORY; int grub_no_autoload; @@ -71,11 +71,10 @@ grub_machine_init (void) } void -grub_machine_set_prefix (void) +grub_machine_get_bootlocation (char **device, char **path) { - grub_env_set ("prefix", prefix); - free (prefix); - prefix = 0; + *device = root_dev; + *path = dir; } void @@ -84,6 +83,8 @@ grub_machine_fini (void) grub_console_fini (); } +char grub_prefix[64] = ""; + static struct option options[] = @@ -132,8 +133,6 @@ void grub_emu_init (void); int main (int argc, char *argv[]) { - char *root_dev = 0; - char *dir = DEFAULT_DIRECTORY; char *dev_map = DEFAULT_DEVICE_MAP; volatile int hold = 0; int opt; @@ -219,9 +218,6 @@ main (int argc, char *argv[]) dir = xstrdup (dir); else dir = grub_make_system_path_relative_to_its_root (dir); - prefix = xmalloc (strlen (root_dev) + 2 + strlen (dir) + 1); - sprintf (prefix, "(%s)%s", root_dev, dir); - free (dir); /* Start GRUB! */ if (setjmp (main_env) == 0) diff --git a/grub-core/kern/i386/coreboot/init.c b/grub-core/kern/i386/coreboot/init.c index 434b9b5a8..ebbea2523 100644 --- a/grub-core/kern/i386/coreboot/init.c +++ b/grub-core/kern/i386/coreboot/init.c @@ -107,10 +107,9 @@ grub_machine_init (void) } void -grub_machine_set_prefix (void) +grub_machine_get_bootlocation (char **device __attribute__ ((unused)), + char **path __attribute__ ((unused))) { - /* Initialize the prefix. */ - grub_env_set ("prefix", grub_prefix); } void diff --git a/grub-core/kern/i386/efi/init.c b/grub-core/kern/i386/efi/init.c index f73f828c6..6bd8f3e87 100644 --- a/grub-core/kern/i386/efi/init.c +++ b/grub-core/kern/i386/efi/init.c @@ -39,9 +39,3 @@ grub_machine_fini (void) { grub_efi_fini (); } - -void -grub_machine_set_prefix (void) -{ - grub_efi_set_prefix (); -} diff --git a/grub-core/kern/i386/pc/init.c b/grub-core/kern/i386/pc/init.c index d8c337bde..3aedaf6d8 100644 --- a/grub-core/kern/i386/pc/init.c +++ b/grub-core/kern/i386/pc/init.c @@ -45,52 +45,39 @@ struct mem_region static struct mem_region mem_regions[MAX_REGIONS]; static int num_regions; -static char * -make_install_device (void) +void +grub_machine_get_bootlocation (char **device, + char **path __attribute__ ((unused))) { + char *ptr; + + /* No hardcoded root partition - make it from the boot drive and the + partition number encoded at the install time. */ + if (grub_boot_drive == GRUB_BOOT_MACHINE_PXE_DL) + { + *device = grub_strdup ("pxe"); + return; + } + /* XXX: This should be enough. */ - char dev[100], *ptr = dev; +#define DEV_SIZE 100 + *device = grub_malloc (DEV_SIZE); + ptr = *device; + grub_snprintf (*device, DEV_SIZE, + "%cd%u", (grub_boot_drive & 0x80) ? 'h' : 'f', + grub_boot_drive & 0x7f); + ptr += grub_strlen (ptr); - if (grub_prefix[0] != '(') - { - /* No hardcoded root partition - make it from the boot drive and the - partition number encoded at the install time. */ - if (grub_boot_drive == GRUB_BOOT_MACHINE_PXE_DL) - { - grub_strcpy (dev, "(pxe"); - ptr += sizeof ("(pxe") - 1; - } - else - { - grub_snprintf (dev, sizeof (dev), - "(%cd%u", (grub_boot_drive & 0x80) ? 'h' : 'f', - grub_boot_drive & 0x7f); - ptr += grub_strlen (ptr); + if (grub_install_dos_part >= 0) + grub_snprintf (ptr, DEV_SIZE - (ptr - *device), + ",%u", grub_install_dos_part + 1); + ptr += grub_strlen (ptr); - if (grub_install_dos_part >= 0) - grub_snprintf (ptr, sizeof (dev) - (ptr - dev), - ",%u", grub_install_dos_part + 1); - ptr += grub_strlen (ptr); - - if (grub_install_bsd_part >= 0) - grub_snprintf (ptr, sizeof (dev) - (ptr - dev), ",%u", - grub_install_bsd_part + 1); - ptr += grub_strlen (ptr); - } - - grub_snprintf (ptr, sizeof (dev) - (ptr - dev), ")%s", grub_prefix); - grub_strcpy (grub_prefix, dev); - } - else if (grub_prefix[1] == ',' || grub_prefix[1] == ')') - { - /* We have a prefix, but still need to fill in the boot drive. */ - grub_snprintf (dev, sizeof (dev), - "(%cd%u%s", (grub_boot_drive & 0x80) ? 'h' : 'f', - grub_boot_drive & 0x7f, grub_prefix + 1); - grub_strcpy (grub_prefix, dev); - } - - return grub_prefix; + if (grub_install_bsd_part >= 0) + grub_snprintf (ptr, DEV_SIZE - (ptr - *device), ",%u", + grub_install_bsd_part + 1); + ptr += grub_strlen (ptr); + *ptr = 0; } /* Add a memory region. */ @@ -211,13 +198,6 @@ grub_machine_init (void) grub_tsc_init (); } -void -grub_machine_set_prefix (void) -{ - /* Initialize the prefix. */ - grub_env_set ("prefix", make_install_device ()); -} - void grub_machine_fini (void) { diff --git a/grub-core/kern/ia64/efi/init.c b/grub-core/kern/ia64/efi/init.c index 6bb4219ac..e2fa58090 100644 --- a/grub-core/kern/ia64/efi/init.c +++ b/grub-core/kern/ia64/efi/init.c @@ -40,12 +40,6 @@ grub_machine_fini (void) grub_efi_fini (); } -void -grub_machine_set_prefix (void) -{ - grub_efi_set_prefix (); -} - void grub_arch_sync_caches (void *address, grub_size_t len) { diff --git a/grub-core/kern/ieee1275/cmain.c b/grub-core/kern/ieee1275/cmain.c index 2fbe809b2..eeb462c5e 100644 --- a/grub-core/kern/ieee1275/cmain.c +++ b/grub-core/kern/ieee1275/cmain.c @@ -60,6 +60,10 @@ grub_ieee1275_find_options (void) int is_olpc = 0; int is_qemu = 0; +#ifdef _sparc64 + grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_NO_PARTITION_0); +#endif + grub_ieee1275_finddevice ("/", &root); grub_ieee1275_finddevice ("/options", &options); grub_ieee1275_finddevice ("/openprom", &openprom); diff --git a/grub-core/kern/ieee1275/init.c b/grub-core/kern/ieee1275/init.c index 3c55096a4..3c6332553 100644 --- a/grub-core/kern/ieee1275/init.c +++ b/grub-core/kern/ieee1275/init.c @@ -35,6 +35,9 @@ #include #include #include +#ifdef __sparc__ +#include +#endif /* The minimal heap size we can live with. */ #define HEAP_MIN_SIZE (unsigned long) (2 * 1024 * 1024) @@ -49,6 +52,10 @@ extern char _start[]; extern char _end[]; +#ifdef __sparc__ +grub_addr_t grub_ieee1275_original_stack; +#endif + void grub_exit (void) { @@ -71,51 +78,39 @@ grub_translate_ieee1275_path (char *filepath) } void -grub_machine_set_prefix (void) +grub_machine_get_bootlocation (char **device, char **path) { char bootpath[64]; /* XXX check length */ char *filename; - char *prefix; grub_bootp_t bootp_pckt; - char addr[GRUB_NET_MAX_STR_ADDR_LEN]; /* Set the net prefix when possible. */ if (grub_getbootp && (bootp_pckt = grub_getbootp())) { - grub_uint32_t n = bootp_pckt->siaddr; - grub_snprintf (addr, GRUB_NET_MAX_STR_ADDR_LEN, "%d.%d.%d.%d", - ((n >> 24) & 0xff), ((n >> 16) & 0xff), - ((n >> 8) & 0xff), ((n >> 0) & 0xff)); - prefix = grub_xasprintf ("(tftp,%s)%s", addr,grub_prefix); - grub_env_set ("prefix", prefix); - grub_free (prefix); + grub_uint32_t n = bootp_pckt->siaddr; + char addr[GRUB_NET_MAX_STR_ADDR_LEN]; + grub_snprintf (addr, GRUB_NET_MAX_STR_ADDR_LEN, "%d.%d.%d.%d", + ((n >> 24) & 0xff), ((n >> 16) & 0xff), + ((n >> 8) & 0xff), ((n >> 0) & 0xff)); + *device = grub_xasprintf ("(tftp,%s)", addr); return; } - if (grub_prefix[0]) - { - grub_env_set ("prefix", grub_prefix); - /* Prefix is hardcoded in the core image. */ - return; - } - if (grub_ieee1275_get_property (grub_ieee1275_chosen, "bootpath", &bootpath, sizeof (bootpath), 0)) { /* Should never happen. */ grub_printf ("/chosen/bootpath property missing!\n"); - grub_env_set ("prefix", ""); return; } /* Transform an OF device path to a GRUB path. */ - prefix = grub_ieee1275_encode_devname (bootpath); + *device = grub_ieee1275_encode_devname (bootpath); filename = grub_ieee1275_get_filename (bootpath); if (filename) { - char *newprefix; char *lastslash = grub_strrchr (filename, '\\'); /* Truncate at last directory. */ @@ -124,23 +119,22 @@ grub_machine_set_prefix (void) *lastslash = '\0'; grub_translate_ieee1275_path (filename); - newprefix = grub_xasprintf ("%s%s", prefix, filename); - if (newprefix) - { - grub_free (prefix); - prefix = newprefix; - } + *path = filename; } } - - grub_env_set ("prefix", prefix); - - grub_free (filename); - grub_free (prefix); } /* Claim some available memory in the first /memory node. */ -static void grub_claim_heap (void) +#ifdef __sparc__ +static void +grub_claim_heap (void) +{ + grub_mm_init_region ((void *) (grub_modules_get_end () + + GRUB_KERNEL_MACHINE_STACK_SIZE), 0x200000); +} +#else +static void +grub_claim_heap (void) { unsigned long total = 0; @@ -208,23 +202,14 @@ static void grub_claim_heap (void) else grub_machine_mmap_iterate (heap_init); } +#endif -static grub_uint64_t ieee1275_get_time_ms (void); - -void -grub_machine_init (void) +static void +grub_parse_cmdline (void) { - char args[256]; grub_ssize_t actual; + char args[256]; - grub_ieee1275_init (); - - grub_console_init_early (); - grub_claim_heap (); - grub_console_init_lately (); - grub_ofdisk_init (); - - /* Process commandline. */ if (grub_ieee1275_get_property (grub_ieee1275_chosen, "bootargs", &args, sizeof args, &actual) == 0 && actual > 1) @@ -257,6 +242,21 @@ grub_machine_init (void) } } } +} + +static grub_uint64_t ieee1275_get_time_ms (void); + +void +grub_machine_init (void) +{ + grub_ieee1275_init (); + + grub_console_init_early (); + grub_claim_heap (); + grub_console_init_lately (); + grub_ofdisk_init (); + + grub_parse_cmdline (); grub_install_get_time_ms (ieee1275_get_time_ms); } diff --git a/grub-core/kern/ieee1275/openfw.c b/grub-core/kern/ieee1275/openfw.c index db4bec90a..8fc373c55 100644 --- a/grub-core/kern/ieee1275/openfw.c +++ b/grub-core/kern/ieee1275/openfw.c @@ -369,6 +369,11 @@ grub_ieee1275_parse_args (const char *path, enum grub_ieee1275_parse_type ptype) ret = grub_strdup (args); else ret = grub_strndup (args, (grub_size_t)(comma - args)); + /* Consistently provide numbered partitions to GRUB. + OpenBOOT traditionally uses alphabetical partition + specifiers. */ + if (ret[0] >= 'a' && ret[0] <= 'z') + ret[0] = '1' + (ret[0] - 'a'); } } diff --git a/grub-core/kern/main.c b/grub-core/kern/main.c index cc9758988..4818d6af3 100644 --- a/grub-core/kern/main.c +++ b/grub-core/kern/main.c @@ -129,27 +129,74 @@ grub_env_write_root (struct grub_env_var *var __attribute__ ((unused)), return grub_strdup (val); } -/* Set the root device according to the dl prefix. */ static void -grub_set_root_dev (void) +grub_set_prefix_and_root (void) { - const char *prefix; + char *device = NULL; + char *path = NULL; + char *fwdevice = NULL; + char *fwpath = NULL; grub_register_variable_hook ("root", 0, grub_env_write_root); - prefix = grub_env_get ("prefix"); + { + char *pptr = NULL; + if (grub_prefix[0] == '(') + { + pptr = grub_strrchr (grub_prefix, ')'); + if (pptr) + { + device = grub_strndup (grub_prefix + 1, pptr - grub_prefix - 1); + pptr++; + } + } + if (!pptr) + pptr = grub_prefix; + if (pptr[0]) + path = grub_strdup (pptr); + } + if ((!device || device[0] == ',' || !device[0]) || !path) + grub_machine_get_bootlocation (&fwdevice, &fwpath); - if (prefix) + if (!device && fwdevice) + device = fwdevice; + else if (fwdevice && (device[0] == ',' || !device[0])) { - char *dev; + /* We have a partition, but still need to fill in the drive. */ + char *comma, *new_device; - dev = grub_file_get_device_name (prefix); - if (dev) + comma = grub_strchr (fwdevice, ','); + if (comma) { - grub_env_set ("root", dev); - grub_free (dev); + char *drive = grub_strndup (fwdevice, comma - fwdevice); + new_device = grub_xasprintf ("%s%s", drive, device); + grub_free (drive); } + else + new_device = grub_xasprintf ("%s%s", fwdevice, device); + + grub_free (fwdevice); + grub_free (device); + device = new_device; } + if (fwpath && !path) + path = fwpath; + if (device) + { + char *prefix; + + prefix = grub_xasprintf ("(%s)%s", device, path ? : ""); + if (prefix) + { + grub_env_set ("prefix", prefix); + grub_free (prefix); + } + grub_env_set ("root", device); + } + + grub_free (device); + grub_free (path); + grub_print_error (); } /* Load the normal mode module and execute the normal mode if possible. */ @@ -187,8 +234,7 @@ grub_main (void) /* It is better to set the root device as soon as possible, for convenience. */ - grub_machine_set_prefix (); - grub_set_root_dev (); + grub_set_prefix_and_root (); grub_env_export ("root"); grub_env_export ("prefix"); diff --git a/grub-core/kern/mips/init.c b/grub-core/kern/mips/init.c index bfa08f56a..353f679e6 100644 --- a/grub-core/kern/mips/init.c +++ b/grub-core/kern/mips/init.c @@ -38,7 +38,7 @@ grub_get_rtc (void) } void -grub_machine_set_prefix (void) +grub_machine_get_bootlocation (char **device __attribute__ ((unused)), + char **path __attribute__ ((unused))) { - grub_env_set ("prefix", grub_prefix); } diff --git a/grub-core/kern/sparc64/ieee1275/init.c b/grub-core/kern/sparc64/ieee1275/init.c deleted file mode 100644 index 72ee1f136..000000000 --- a/grub-core/kern/sparc64/ieee1275/init.c +++ /dev/null @@ -1,174 +0,0 @@ -/* init.c -- Initialize GRUB on SPARC64. */ -/* - * GRUB -- GRand Unified Bootloader - * Copyright (C) 2009 Free Software Foundation, Inc. - * - * GRUB is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * GRUB is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GRUB. If not, see . - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -grub_addr_t grub_ieee1275_original_stack; - -void -grub_exit (void) -{ - grub_ieee1275_exit (); -} - -static grub_uint64_t -ieee1275_get_time_ms (void) -{ - grub_uint32_t msecs = 0; - - grub_ieee1275_milliseconds (&msecs); - - return msecs; -} - -grub_uint32_t -grub_get_rtc (void) -{ - return ieee1275_get_time_ms (); -} - -grub_addr_t -grub_arch_modules_addr (void) -{ - extern char _end[]; - return (grub_addr_t) _end; -} - -void -grub_machine_set_prefix (void) -{ - if (grub_prefix[0] != '(') - { - char bootpath[IEEE1275_MAX_PATH_LEN]; - char *prefix, *path, *colon; - grub_ssize_t actual; - - if (grub_ieee1275_get_property (grub_ieee1275_chosen, "bootpath", - &bootpath, sizeof (bootpath), &actual)) - { - /* Should never happen. */ - grub_printf ("/chosen/bootpath property missing!\n"); - grub_env_set ("prefix", ""); - return; - } - - /* Transform an OF device path to a GRUB path. */ - colon = grub_strchr (bootpath, ':'); - if (colon) - { - char *part = colon + 1; - - /* Consistently provide numbered partitions to GRUB. - OpenBOOT traditionally uses alphabetical partition - specifiers. */ - if (part[0] >= 'a' && part[0] <= 'z') - part[0] = '1' + (part[0] - 'a'); - } - prefix = grub_ieee1275_encode_devname (bootpath); - - path = grub_xasprintf("%s%s", prefix, grub_prefix); - - grub_strcpy (grub_prefix, path); - - grub_free (path); - grub_free (prefix); - } - - grub_env_set ("prefix", grub_prefix); -} - -static void -grub_heap_init (void) -{ - grub_mm_init_region ((void *) (grub_modules_get_end () - + GRUB_KERNEL_MACHINE_STACK_SIZE), 0x200000); -} - -static void -grub_parse_cmdline (void) -{ - grub_ssize_t actual; - char args[256]; - - if (grub_ieee1275_get_property (grub_ieee1275_chosen, "bootargs", &args, - sizeof args, &actual) == 0 - && actual > 1) - { - int i = 0; - - while (i < actual) - { - char *command = &args[i]; - char *end; - char *val; - - end = grub_strchr (command, ';'); - if (end == 0) - i = actual; /* No more commands after this one. */ - else - { - *end = '\0'; - i += end - command + 1; - while (grub_isspace(args[i])) - i++; - } - - /* Process command. */ - val = grub_strchr (command, '='); - if (val) - { - *val = '\0'; - grub_env_set (command, val + 1); - } - } - } -} - -void -grub_machine_init (void) -{ - grub_ieee1275_init (); - grub_console_init_early (); - grub_heap_init (); - grub_console_init_lately (); - - grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_NO_PARTITION_0); - grub_ofdisk_init (); - - grub_parse_cmdline (); - grub_install_get_time_ms (ieee1275_get_time_ms); -} - -void -grub_machine_fini (void) -{ - grub_ofdisk_fini (); - grub_console_fini (); -} diff --git a/include/grub/kernel.h b/include/grub/kernel.h index 2ecc73df4..6a5f91c3d 100644 --- a/include/grub/kernel.h +++ b/include/grub/kernel.h @@ -84,12 +84,13 @@ void grub_machine_init (void); void EXPORT_FUNC(grub_machine_fini) (void); /* The machine-specific prefix initialization. */ -void grub_machine_set_prefix (void); +void +grub_machine_get_bootlocation (char **device, char **path); /* Register all the exported symbols. This is automatically generated. */ void grub_register_exported_symbols (void); -#if ! defined (ASM_FILE) && !defined (GRUB_MACHINE_EMU) +#if ! defined (ASM_FILE) extern char grub_prefix[]; #endif diff --git a/include/grub/offsets.h b/include/grub/offsets.h index af724096d..c04961fc6 100644 --- a/include/grub/offsets.h +++ b/include/grub/offsets.h @@ -169,8 +169,10 @@ /* Non-zero value is only needed for PowerMacs. */ #define GRUB_KERNEL_I386_IEEE1275_MOD_GAP 0x0 #define GRUB_KERNEL_I386_COREBOOT_MOD_GAP 0x0 +#define GRUB_KERNEL_POWERPC_IEEE1275_MOD_GAP 0x0 #define GRUB_KERNEL_POWERPC_IEEE1275_MOD_ALIGN 0x1000 +#define GRUB_KERNEL_SPARC64_IEEE1275_MOD_ALIGN 0x1 #define GRUB_KERNEL_MIPS_LOONGSON_MOD_ALIGN 0x1 #define GRUB_KERNEL_MIPS_ARC_MOD_ALIGN 0x1 @@ -179,7 +181,7 @@ /* Minimal gap between _end and the start of the modules. It's a hack for PowerMac to prevent "CLAIM failed" error. The real fix is to rewrite grub-mkimage to generate valid ELF files. */ -#define GRUB_KERNEL_POWERPC_IEEE1275_MOD_GAP 0x8000 +#define GRUB_KERNEL_SPARC64_IEEE1275_MOD_GAP 0x8000 #ifdef GRUB_MACHINE #define GRUB_OFFSETS_CONCAT_(a,b,c) a ## b ## c From cae730b4526f250a3d5073c00911e35b7abdd7d7 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 2 Jul 2011 16:56:35 +0200 Subject: [PATCH 715/869] Automatically determine prefix when netbooted on EFI --- grub-core/disk/efi/efidisk.c | 153 ++++++++--------------------- grub-core/kern/efi/efi.c | 48 +++++++++ grub-core/kern/efi/init.c | 6 ++ grub-core/net/drivers/efi/efinet.c | 49 ++++++++- grub-core/net/net.c | 53 ++++++++-- include/grub/efi/api.h | 35 +++++++ include/grub/efi/efi.h | 8 ++ include/grub/net.h | 8 +- 8 files changed, 237 insertions(+), 123 deletions(-) diff --git a/grub-core/disk/efi/efidisk.c b/grub-core/disk/efi/efidisk.c index 5dc753046..07f0f6859 100644 --- a/grub-core/disk/efi/efidisk.c +++ b/grub-core/disk/efi/efidisk.c @@ -84,54 +84,6 @@ find_last_device_path (const grub_efi_device_path_t *dp) return p; } -/* Compare device paths. */ -static int -compare_device_paths (const grub_efi_device_path_t *dp1, - const grub_efi_device_path_t *dp2) -{ - if (! dp1 || ! dp2) - /* Return non-zero. */ - return 1; - - while (1) - { - grub_efi_uint8_t type1, type2; - grub_efi_uint8_t subtype1, subtype2; - grub_efi_uint16_t len1, len2; - int ret; - - type1 = GRUB_EFI_DEVICE_PATH_TYPE (dp1); - type2 = GRUB_EFI_DEVICE_PATH_TYPE (dp2); - - if (type1 != type2) - return (int) type2 - (int) type1; - - subtype1 = GRUB_EFI_DEVICE_PATH_SUBTYPE (dp1); - subtype2 = GRUB_EFI_DEVICE_PATH_SUBTYPE (dp2); - - if (subtype1 != subtype2) - return (int) subtype1 - (int) subtype2; - - len1 = GRUB_EFI_DEVICE_PATH_LENGTH (dp1); - len2 = GRUB_EFI_DEVICE_PATH_LENGTH (dp2); - - if (len1 != len2) - return (int) len1 - (int) len2; - - ret = grub_memcmp (dp1, dp2, len1); - if (ret != 0) - return ret; - - if (GRUB_EFI_END_ENTIRE_DEVICE_PATH (dp1)) - break; - - dp1 = (grub_efi_device_path_t *) ((char *) dp1 + len1); - dp2 = (grub_efi_device_path_t *) ((char *) dp2 + len2); - } - - return 0; -} - static struct grub_efidisk_data * make_devices (void) { @@ -214,7 +166,7 @@ find_parent_device (struct grub_efidisk_data *devices, if (parent == d) continue; - if (compare_device_paths (parent->device_path, dp) == 0) + if (grub_efi_compare_device_paths (parent->device_path, dp) == 0) { /* Found. */ if (! parent->last_device_path) @@ -249,7 +201,7 @@ iterate_child_devices (struct grub_efidisk_data *devices, ldp->length[0] = sizeof (*ldp); ldp->length[1] = 0; - if (compare_device_paths (dp, d->device_path) == 0) + if (grub_efi_compare_device_paths (dp, d->device_path) == 0) if (hook (p)) { grub_free (dp); @@ -273,11 +225,11 @@ add_device (struct grub_efidisk_data **devices, struct grub_efidisk_data *d) { int ret; - ret = compare_device_paths (find_last_device_path ((*p)->device_path), - find_last_device_path (d->device_path)); + ret = grub_efi_compare_device_paths (find_last_device_path ((*p)->device_path), + find_last_device_path (d->device_path)); if (ret == 0) - ret = compare_device_paths ((*p)->device_path, - d->device_path); + ret = grub_efi_compare_device_paths ((*p)->device_path, + d->device_path); if (ret == 0) return; else if (ret > 0) @@ -706,7 +658,35 @@ grub_efidisk_get_device_handle (grub_disk_t disk) char * grub_efidisk_get_device_name (grub_efi_handle_t *handle) { - grub_efi_device_path_t *dp, *ldp; + grub_efi_device_path_t *dp, *ldp, *sdp; + /* This is a hard disk partition. */ + grub_disk_t parent = 0; + auto int find_parent_disk (const char *name); + + /* Find the disk which is the parent of a given hard disk partition. */ + int find_parent_disk (const char *name) + { + grub_disk_t disk; + + disk = grub_disk_open (name); + if (! disk) + return 1; + + if (disk->dev->id == GRUB_DISK_DEVICE_EFIDISK_ID) + { + struct grub_efidisk_data *d; + + d = disk->data; + if (grub_efi_compare_device_paths (d->device_path, sdp) == 0) + { + parent = disk; + return 1; + } + } + + grub_disk_close (disk); + return 0; + } dp = grub_efi_get_device_path (handle); if (! dp) @@ -720,40 +700,12 @@ grub_efidisk_get_device_name (grub_efi_handle_t *handle) && (GRUB_EFI_DEVICE_PATH_SUBTYPE (ldp) == GRUB_EFI_HARD_DRIVE_DEVICE_PATH_SUBTYPE)) { - /* This is a hard disk partition. */ - grub_disk_t parent = 0; grub_partition_t tpart = NULL; char *device_name; grub_efi_device_path_t *dup_dp, *dup_ldp; grub_efi_hard_drive_device_path_t hd; - auto int find_parent_disk (const char *name); auto int find_partition (grub_disk_t disk, const grub_partition_t part); - /* Find the disk which is the parent of a given hard disk partition. */ - int find_parent_disk (const char *name) - { - grub_disk_t disk; - - disk = grub_disk_open (name); - if (! disk) - return 1; - - if (disk->dev->id == GRUB_DISK_DEVICE_EFIDISK_ID) - { - struct grub_efidisk_data *d; - - d = disk->data; - if (compare_device_paths (d->device_path, dup_dp) == 0) - { - parent = disk; - return 1; - } - } - - grub_disk_close (disk); - return 0; - } - /* Find the identical partition. */ int find_partition (grub_disk_t disk __attribute__ ((unused)), const grub_partition_t part) @@ -780,6 +732,8 @@ grub_efidisk_get_device_name (grub_efi_handle_t *handle) dup_ldp->length[0] = sizeof (*dup_ldp); dup_ldp->length[1] = 0; + sdp = dup_dp; + grub_efidisk_iterate (find_parent_disk); grub_free (dup_dp); @@ -816,36 +770,15 @@ grub_efidisk_get_device_name (grub_efi_handle_t *handle) else { /* This should be an entire disk. */ - auto int find_disk (const char *name); char *device_name = 0; - int find_disk (const char *name) - { - grub_disk_t disk; + sdp = dp; - disk = grub_disk_open (name); - if (! disk) - return 1; - - if (disk->dev->id == GRUB_DISK_DEVICE_EFIDISK_ID) - { - struct grub_efidisk_data *d; - - d = disk->data; - if (compare_device_paths (d->device_path, dp) == 0) - { - device_name = grub_strdup (disk->name); - grub_disk_close (disk); - return 1; - } - } - - grub_disk_close (disk); - return 0; - - } - - grub_efidisk_iterate (find_disk); + grub_efidisk_iterate (find_parent_disk); + if (!parent) + return NULL; + device_name = grub_strdup (parent->name); + grub_disk_close (parent); return device_name; } diff --git a/grub-core/kern/efi/efi.c b/grub-core/kern/efi/efi.c index c95058733..d0994a940 100644 --- a/grub-core/kern/efi/efi.c +++ b/grub-core/kern/efi/efi.c @@ -746,3 +746,51 @@ grub_efi_print_device_path (grub_efi_device_path_t *dp) dp = (grub_efi_device_path_t *) ((char *) dp + len); } } + +/* Compare device paths. */ +int +grub_efi_compare_device_paths (const grub_efi_device_path_t *dp1, + const grub_efi_device_path_t *dp2) +{ + if (! dp1 || ! dp2) + /* Return non-zero. */ + return 1; + + while (1) + { + grub_efi_uint8_t type1, type2; + grub_efi_uint8_t subtype1, subtype2; + grub_efi_uint16_t len1, len2; + int ret; + + type1 = GRUB_EFI_DEVICE_PATH_TYPE (dp1); + type2 = GRUB_EFI_DEVICE_PATH_TYPE (dp2); + + if (type1 != type2) + return (int) type2 - (int) type1; + + subtype1 = GRUB_EFI_DEVICE_PATH_SUBTYPE (dp1); + subtype2 = GRUB_EFI_DEVICE_PATH_SUBTYPE (dp2); + + if (subtype1 != subtype2) + return (int) subtype1 - (int) subtype2; + + len1 = GRUB_EFI_DEVICE_PATH_LENGTH (dp1); + len2 = GRUB_EFI_DEVICE_PATH_LENGTH (dp2); + + if (len1 != len2) + return (int) len1 - (int) len2; + + ret = grub_memcmp (dp1, dp2, len1); + if (ret != 0) + return ret; + + if (GRUB_EFI_END_ENTIRE_DEVICE_PATH (dp1)) + break; + + dp1 = (grub_efi_device_path_t *) ((char *) dp1 + len1); + dp2 = (grub_efi_device_path_t *) ((char *) dp2 + len2); + } + + return 0; +} diff --git a/grub-core/kern/efi/init.c b/grub-core/kern/efi/init.c index a7325acc6..4dfb06284 100644 --- a/grub-core/kern/efi/init.c +++ b/grub-core/kern/efi/init.c @@ -42,6 +42,10 @@ grub_efi_init (void) grub_efidisk_init (); } +void (*grub_efi_net_config) (grub_efi_handle_t hnd, + char **device, + char **path); + void grub_machine_get_bootlocation (char **device, char **path) { @@ -53,6 +57,8 @@ grub_machine_get_bootlocation (char **device, char **path) return; *device = grub_efidisk_get_device_name (image->device_handle); *path = grub_efi_get_filename (image->file_path); + if (!*device && grub_efi_net_config) + grub_efi_net_config (image->device_handle, device, path); /* Get the directory. */ p = grub_strrchr (*path, '/'); diff --git a/grub-core/net/drivers/efi/efinet.c b/grub-core/net/drivers/efi/efinet.c index a6e005601..29bc66183 100644 --- a/grub-core/net/drivers/efi/efinet.c +++ b/grub-core/net/drivers/efi/efinet.c @@ -27,14 +27,14 @@ GRUB_MOD_LICENSE ("GPLv3+"); /* GUID. */ static grub_efi_guid_t net_io_guid = GRUB_EFI_SIMPLE_NETWORK_GUID; - +static grub_efi_guid_t pxe_io_guid = GRUB_EFI_PXE_GUID; static grub_err_t send_card_buffer (const struct grub_net_card *dev, struct grub_net_buff *pack) { grub_efi_status_t st; - grub_efi_simple_network_t *net = dev->data; + grub_efi_simple_network_t *net = dev->efi_net; st = efi_call_7 (net->transmit, net, 0, pack->tail - pack->data, pack->data, NULL, NULL, NULL); if (st != GRUB_EFI_SUCCESS) @@ -46,7 +46,7 @@ static grub_ssize_t get_card_packet (const struct grub_net_card *dev, struct grub_net_buff *nb) { - grub_efi_simple_network_t *net = dev->data; + grub_efi_simple_network_t *net = dev->efi_net; grub_err_t err; grub_efi_status_t st; grub_efi_uintn_t bufsize = 1500; @@ -139,21 +139,62 @@ grub_efinet_findcards (void) grub_memcpy (card->default_address.mac, net->mode->current_address, sizeof (card->default_address.mac)); - card->data = net; + card->efi_net = net; + card->efi_handle = *handle; grub_net_card_register (card); } grub_free (handles); } +static void +grub_efi_net_config_real (grub_efi_handle_t hnd, char **device, + char **path) +{ + struct grub_net_card *card; + grub_efi_device_path_t *dp; + + dp = grub_efi_get_device_path (hnd); + if (! dp) + return; + + FOR_NET_CARDS (card) + { + grub_efi_device_path_t *cdp; + struct grub_efi_pxe *pxe; + struct grub_efi_pxe_mode *pxe_mode; + if (card->driver != &efidriver) + continue; + cdp = grub_efi_get_device_path (card->efi_handle); + if (! cdp) + continue; + if (grub_efi_compare_device_paths (dp, cdp) != 0) + continue; + pxe = grub_efi_open_protocol (hnd, &pxe_io_guid, + GRUB_EFI_OPEN_PROTOCOL_GET_PROTOCOL); + if (! pxe) + continue; + pxe_mode = pxe->mode; + grub_net_configure_by_dhcp_ack (card->name, card, 0, + (struct grub_net_bootp_packet *) + &pxe_mode->dhcp_ack, + sizeof (pxe_mode->dhcp_ack), + 1, device, path); + return; + } +} + + GRUB_MOD_INIT(efinet) { grub_efinet_findcards (); + grub_efi_net_config = grub_efi_net_config_real; } GRUB_MOD_FINI(ofnet) { struct grub_net_card *card; + grub_efi_net_config = 0; FOR_NET_CARDS (card) if (card->driver && !grub_strcmp (card->driver->name, "efinet")) { diff --git a/grub-core/net/net.c b/grub-core/net/net.c index 34148f52c..2ecb709b9 100644 --- a/grub-core/net/net.c +++ b/grub-core/net/net.c @@ -936,7 +936,8 @@ grub_net_configure_by_dhcp_ack (const char *name, const struct grub_net_card *card, grub_net_interface_flags_t flags, const struct grub_net_bootp_packet *bp, - grub_size_t size) + grub_size_t size, + int is_def, char **device, char **path) { grub_net_network_level_address_t addr; grub_net_link_level_address_t hwaddr; @@ -945,6 +946,11 @@ grub_net_configure_by_dhcp_ack (const char *name, addr.type = GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4; addr.ipv4 = bp->your_ip; + if (device) + *device = 0; + if (path) + *path = 0; + grub_memcpy (hwaddr.mac, bp->mac_addr, bp->hw_len < sizeof (hwaddr.mac) ? bp->hw_len : sizeof (hwaddr.mac)); @@ -975,26 +981,57 @@ grub_net_configure_by_dhcp_ack (const char *name, if (size > OFFSET_OF (boot_file, bp)) set_env_limn_ro (name, "boot_file", (char *) bp->boot_file, sizeof (bp->boot_file)); + if (is_def) + default_server = 0; if (size > OFFSET_OF (server_name, bp) && bp->server_name[0]) { set_env_limn_ro (name, "dhcp_server_name", (char *) bp->server_name, sizeof (bp->server_name)); - if (!default_server) + if (is_def && !default_server) { default_server = grub_strdup (bp->server_name); - grub_errno = GRUB_ERR_NONE; - } + grub_print_error (); + } + if (device && !*device) + { + *device = grub_xasprintf ("tftp,%s", bp->server_name); + grub_print_error (); + } } - if (!default_server) + if (is_def && !default_server) { default_server = grub_xasprintf ("%d.%d.%d.%d", ((grub_uint8_t *) &bp->server_ip)[0], ((grub_uint8_t *) &bp->server_ip)[1], ((grub_uint8_t *) &bp->server_ip)[2], ((grub_uint8_t *) &bp->server_ip)[3]); - grub_errno = GRUB_ERR_NONE; - } + grub_print_error (); + } + + if (device && !*device) + { + *device = grub_xasprintf ("tftp,%d.%d.%d.%d", + ((grub_uint8_t *) &bp->server_ip)[0], + ((grub_uint8_t *) &bp->server_ip)[1], + ((grub_uint8_t *) &bp->server_ip)[2], + ((grub_uint8_t *) &bp->server_ip)[3]); + grub_print_error (); + } + if (size > OFFSET_OF (boot_file, bp) && path) + { + *path = grub_strndup (bp->boot_file, sizeof (bp->boot_file)); + grub_print_error (); + if (*path) + { + char *slash; + slash = grub_strrchr (*path, '/'); + if (slash) + *slash = 0; + else + **path = 0; + } + } if (size > OFFSET_OF (vendor, bp)) parse_dhcp_vendor (name, &bp->vendor, size - OFFSET_OF (vendor, bp)); @@ -1025,7 +1062,7 @@ grub_net_process_dhcp (struct grub_net_buff *nb, } grub_net_configure_by_dhcp_ack (name, card, 0, (const struct grub_net_bootp_packet *) nb->data, - (nb->tail - nb->data)); + (nb->tail - nb->data), 0, 0, 0); grub_free (name); if (grub_errno) grub_print_error (); diff --git a/include/grub/efi/api.h b/include/grub/efi/api.h index a3dde0eff..5cd1686ea 100644 --- a/include/grub/efi/api.h +++ b/include/grub/efi/api.h @@ -89,6 +89,11 @@ { 0x9a, 0x2d, 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d } \ } +#define GRUB_EFI_PXE_GUID \ + { 0x03c4e603, 0xac28, 0x11d3, \ + { 0x9a, 0x2d, 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d } \ + } + #define GRUB_EFI_DEVICE_PATH_GUID \ { 0x09576e91, 0x6d3f, 0x11d2, \ { 0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b } \ @@ -1118,6 +1123,36 @@ struct grub_efi_simple_text_output_interface }; typedef struct grub_efi_simple_text_output_interface grub_efi_simple_text_output_interface_t; +typedef grub_uint8_t grub_efi_pxe_packet_t[1472]; + +typedef struct grub_efi_pxe_mode +{ + grub_uint8_t unused[52]; + grub_efi_pxe_packet_t dhcp_discover; + grub_efi_pxe_packet_t dhcp_ack; + grub_efi_pxe_packet_t proxy_offer; + grub_efi_pxe_packet_t pxe_discover; + grub_efi_pxe_packet_t pxe_reply; +} grub_efi_pxe_mode_t; + +typedef struct grub_efi_pxe +{ + grub_uint64_t rev; + void (*start) (void); + void (*stop) (void); + void (*dhcp) (void); + void (*discover) (void); + void (*mftp) (void); + void (*udpwrite) (void); + void (*udpread) (void); + void (*setipfilter) (void); + void (*arp) (void); + void (*setparams) (void); + void (*setstationip) (void); + void (*setpackets) (void); + struct grub_efi_pxe_mode *mode; +} grub_efi_pxe_t; + #define GRUB_EFI_BLACK 0x00 #define GRUB_EFI_BLUE 0x01 #define GRUB_EFI_GREEN 0x02 diff --git a/include/grub/efi/efi.h b/include/grub/efi/efi.h index e9c57dd11..e98f99507 100644 --- a/include/grub/efi/efi.h +++ b/include/grub/efi/efi.h @@ -62,6 +62,14 @@ grub_err_t EXPORT_FUNC (grub_efi_set_virtual_address_map) (grub_efi_uintn_t memo grub_efi_uint32_t descriptor_version, grub_efi_memory_descriptor_t *virtual_map); +int +EXPORT_FUNC (grub_efi_compare_device_paths) (const grub_efi_device_path_t *dp1, + const grub_efi_device_path_t *dp2); + +extern void (*EXPORT_VAR(grub_efi_net_config)) (grub_efi_handle_t hnd, + char **device, + char **path); + void grub_efi_mm_init (void); void grub_efi_mm_fini (void); void grub_efi_init (void); diff --git a/include/grub/net.h b/include/grub/net.h index ee94ebcc6..6aaf391d5 100644 --- a/include/grub/net.h +++ b/include/grub/net.h @@ -109,6 +109,11 @@ struct grub_net_card grub_net_card_flags_t flags; union { + struct + { + struct grub_efi_simple_network *efi_net; + void *efi_handle; + }; void *data; int data_num; }; @@ -404,7 +409,8 @@ grub_net_configure_by_dhcp_ack (const char *name, const struct grub_net_card *card, grub_net_interface_flags_t flags, const struct grub_net_bootp_packet *bp, - grub_size_t size); + grub_size_t size, + int is_def, char **device, char **path); void grub_net_process_dhcp (struct grub_net_buff *nb, From 6708faafdea4e3b27879e089e772babb78bfe7f2 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 2 Jul 2011 17:58:23 +0200 Subject: [PATCH 716/869] Fix broken blksize negotiation, fix broken seek and change a way net device is filled n i386-pc --- grub-core/kern/file.c | 4 -- grub-core/kern/i386/pc/init.c | 8 ++-- grub-core/net/drivers/i386/pc/pxe.c | 73 +++++++++++++++++++++++------ grub-core/net/net.c | 28 +++++++---- grub-core/net/tftp.c | 26 +++++++--- include/grub/i386/pc/kernel.h | 2 + include/grub/net.h | 2 +- include/grub/net/tftp.h | 6 --- 8 files changed, 105 insertions(+), 44 deletions(-) diff --git a/grub-core/kern/file.c b/grub-core/kern/file.c index 2407e72c5..f69ef6fd4 100644 --- a/grub-core/kern/file.c +++ b/grub-core/kern/file.c @@ -25,7 +25,6 @@ #include #include -grub_err_t (*grub_file_net_seek) (struct grub_file *file, grub_off_t offset) = NULL; void (*EXPORT_VAR (grub_grubnet_fini)) (void); grub_file_filter_t grub_file_filters_all[GRUB_FILE_FILTER_MAX]; @@ -183,9 +182,6 @@ grub_file_seek (grub_file_t file, grub_off_t offset) return -1; } - if (file->device->net && grub_file_net_seek) - grub_file_net_seek (file, offset); - old = file->offset; file->offset = offset; diff --git a/grub-core/kern/i386/pc/init.c b/grub-core/kern/i386/pc/init.c index 3aedaf6d8..24fe8fed9 100644 --- a/grub-core/kern/i386/pc/init.c +++ b/grub-core/kern/i386/pc/init.c @@ -45,9 +45,10 @@ struct mem_region static struct mem_region mem_regions[MAX_REGIONS]; static int num_regions; +void (*grub_pc_net_config) (char **device, char **path); + void -grub_machine_get_bootlocation (char **device, - char **path __attribute__ ((unused))) +grub_machine_get_bootlocation (char **device, char **path) { char *ptr; @@ -55,7 +56,8 @@ grub_machine_get_bootlocation (char **device, partition number encoded at the install time. */ if (grub_boot_drive == GRUB_BOOT_MACHINE_PXE_DL) { - *device = grub_strdup ("pxe"); + if (grub_pc_net_config) + grub_pc_net_config (device, path); return; } diff --git a/grub-core/net/drivers/i386/pc/pxe.c b/grub-core/net/drivers/i386/pc/pxe.c index 144df964c..51f4023a6 100644 --- a/grub-core/net/drivers/i386/pc/pxe.c +++ b/grub-core/net/drivers/i386/pc/pxe.c @@ -28,6 +28,7 @@ #include #include #include +#include GRUB_MOD_LICENSE ("GPLv3+"); @@ -45,6 +46,22 @@ struct grub_pxe_undi_open grub_uint8_t mcast[8][6]; } __attribute__ ((packed)); +struct grub_pxe_undi_info +{ + grub_uint16_t status; + grub_uint16_t base_io; + grub_uint16_t int_number; + grub_uint16_t mtu; + grub_uint16_t hwtype; + grub_uint16_t hwaddrlen; + grub_uint8_t current_addr[16]; + grub_uint8_t permanent_addr[16]; + grub_uint32_t romaddr; + grub_uint16_t rxbufct; + grub_uint16_t txbufct; +} __attribute__ ((packed)); + + struct grub_pxe_undi_isr { grub_uint16_t status; @@ -259,7 +276,7 @@ struct grub_net_card grub_pxe_card = void grub_pxe_unload (void) { - if (grub_pxe_pxenv) + if (pxe_rm_entry) { grub_pxe_call (GRUB_PXENV_UNDI_CLOSE, (void *) GRUB_MEMORY_MACHINE_SCRATCH_ADDR, @@ -269,17 +286,11 @@ grub_pxe_unload (void) } } -GRUB_MOD_INIT(pxe) +static void +grub_pc_net_config_real (char **device, char **path) { - struct grub_pxe_bangpxe *pxenv; - struct grub_pxenv_get_cached_info ci; struct grub_net_bootp_packet *bp; - struct grub_pxe_undi_open *ou; - - pxenv = grub_pxe_scan (); - if (! pxenv) - return; - + struct grub_pxenv_get_cached_info ci; ci.packet_type = GRUB_PXENV_PACKET_TYPE_DHCP_ACK; ci.buffer = 0; ci.buffer_size = 0; @@ -289,9 +300,41 @@ GRUB_MOD_INIT(pxe) bp = LINEAR (ci.buffer); - grub_memcpy (grub_pxe_card.default_address.mac, bp->mac_addr, - bp->hw_len < sizeof (grub_pxe_card.default_address.mac) - ? bp->hw_len : sizeof (grub_pxe_card.default_address.mac)); + grub_net_configure_by_dhcp_ack ("pxe", &grub_pxe_card, 0, + bp, GRUB_PXE_BOOTP_SIZE, + 1, device, path); +} + +GRUB_MOD_INIT(pxe) +{ + struct grub_pxe_bangpxe *pxenv; + struct grub_pxe_undi_open *ou; + struct grub_pxe_undi_info *ui; + unsigned i; + + pxenv = grub_pxe_scan (); + if (! pxenv) + return; + + ui = (void *) GRUB_MEMORY_MACHINE_SCRATCH_ADDR; + grub_memset (ui, 0, sizeof (*ui)); + grub_pxe_call (GRUB_PXENV_UNDI_GET_INFORMATION, ui, pxe_rm_entry); + + grub_memcpy (grub_pxe_card.default_address.mac, ui->current_addr, + sizeof (grub_pxe_card.default_address.mac)); + for (i = 0; i < sizeof (grub_pxe_card.default_address.mac); i++) + if (grub_pxe_card.default_address.mac[i] != 0) + break; + if (i != sizeof (grub_pxe_card.default_address.mac)) + { + for (i = 0; i < sizeof (grub_pxe_card.default_address.mac); i++) + if (grub_pxe_card.default_address.mac[i] != 0xff) + break; + } + if (i == sizeof (grub_pxe_card.default_address.mac)) + grub_memcpy (grub_pxe_card.default_address.mac, ui->permanent_addr, + sizeof (grub_pxe_card.default_address.mac)); + grub_pxe_card.default_address.type = GRUB_NET_LINK_LEVEL_PROTOCOL_ETHERNET; ou = (void *) GRUB_MEMORY_MACHINE_SCRATCH_ADDR; @@ -303,11 +346,11 @@ GRUB_MOD_INIT(pxe) return; grub_net_card_register (&grub_pxe_card); - grub_net_configure_by_dhcp_ack ("pxe", &grub_pxe_card, 0, - bp, GRUB_PXE_BOOTP_SIZE); + grub_pc_net_config = grub_pc_net_config_real; } GRUB_MOD_FINI(pxe) { + grub_pc_net_config = 0; grub_pxe_unload (); } diff --git a/grub-core/net/net.c b/grub-core/net/net.c index 2ecb709b9..a56860eed 100644 --- a/grub-core/net/net.c +++ b/grub-core/net/net.c @@ -664,6 +664,7 @@ grub_net_open_real (const char *name) else ret->server = NULL; ret->fs = &grub_net_fs; + ret->offset = 0; return ret; } } @@ -784,7 +785,7 @@ grub_net_poll_cards (unsigned time) /* Read from the packets list*/ static grub_ssize_t -grub_net_fs_read (grub_file_t file, char *buf, grub_size_t len) +grub_net_fs_read_real (grub_file_t file, char *buf, grub_size_t len) { grub_net_socket_t sock = file->device->net->socket; struct grub_net_buff *nb; @@ -802,6 +803,7 @@ grub_net_fs_read (grub_file_t file, char *buf, grub_size_t len) amount = len; len -= amount; total += amount; + file->device->net->offset += amount; if (buf) { grub_memcpy (ptr, nb->data, amount); @@ -829,28 +831,40 @@ grub_net_fs_read (grub_file_t file, char *buf, grub_size_t len) return total; } -/* Read from the packets list*/ static grub_err_t grub_net_seek_real (struct grub_file *file, grub_off_t offset) { grub_net_socket_t sock = file->device->net->socket; struct grub_net_buff *nb; - grub_size_t len = offset - file->offset; + grub_size_t len = offset - file->device->net->offset; if (!len) return GRUB_ERR_NONE; /* We cant seek backwards past the current packet. */ - if (file->offset > offset) + if (file->device->net->offset > offset) { nb = sock->packs.first->nb; - return grub_netbuff_push (nb, file->offset - offset); + return grub_netbuff_push (nb, file->device->net->offset - offset); } - grub_net_fs_read (file, NULL, len); + grub_net_fs_read_real (file, NULL, len); return GRUB_ERR_NONE; } +static grub_ssize_t +grub_net_fs_read (grub_file_t file, char *buf, grub_size_t len) +{ + if (file->offset != file->device->net->offset) + { + grub_err_t err; + err = grub_net_seek_real (file, file->offset); + if (err) + return err; + } + return grub_net_fs_read_real (file, buf, len); +} + static char * grub_env_write_readonly (struct grub_env_var *var __attribute__ ((unused)), const char *val __attribute__ ((unused))) @@ -1384,7 +1398,6 @@ GRUB_MOD_INIT(net) grub_fs_register (&grub_net_fs); grub_net_open = grub_net_open_real; - grub_file_net_seek = grub_net_seek_real; grub_grubnet_fini = grub_grubnet_fini_real; } @@ -1400,6 +1413,5 @@ GRUB_MOD_FINI(net) grub_unregister_command (cmd_getdhcp); grub_fs_unregister (&grub_net_fs); grub_net_open = NULL; - grub_file_net_seek = NULL; grub_grubnet_fini = NULL; } diff --git a/grub-core/net/tftp.c b/grub-core/net/tftp.c index 24f30eb7a..b112f643e 100644 --- a/grub-core/net/tftp.c +++ b/grub-core/net/tftp.c @@ -11,6 +11,13 @@ GRUB_MOD_LICENSE ("GPLv3+"); +typedef struct tftp_data +{ + grub_uint64_t file_size; + grub_uint64_t block; + grub_uint32_t block_size; +} *tftp_data_t; + static grub_err_t tftp_open (struct grub_file *file, const char *filename) { @@ -85,9 +92,9 @@ tftp_open (struct grub_file *file, const char *filename) if (file->device->net->socket->status != 0) break; /* Retry. */ - /*err = grub_net_send_udp_packet (file->device->net->socket, &nb); - if (err) - return err; */ + err = grub_net_send_udp_packet (file->device->net->socket, &nb); + if (err) + return err; } if (file->device->net->socket->status == 0) @@ -110,11 +117,11 @@ tftp_receive (grub_net_socket_t sock, struct grub_net_buff *nb) nb_ack.head = nbdata; nb_ack.end = nbdata + sizeof (nbdata); - tftph = (struct tftphdr *) nb->data; switch (grub_be_to_cpu16 (tftph->opcode)) { case TFTP_OACK: + data->block_size = 512; for (ptr = nb->data + sizeof (tftph->opcode); ptr < nb->tail;) { if (grub_memcmp (ptr, "tsize\0", sizeof ("tsize\0") - 1) == 0) @@ -122,6 +129,11 @@ tftp_receive (grub_net_socket_t sock, struct grub_net_buff *nb) data->file_size = grub_strtoul (ptr + sizeof ("tsize\0") - 1, 0, 0); } + if (grub_memcmp (ptr, "blksize\0", sizeof ("blksize\0") - 1) == 0) + { + data->block_size = grub_strtoul (ptr + sizeof ("blksize\0") - 1, + 0, 0); + } while (ptr < nb->tail && *ptr) ptr++; ptr++; @@ -139,12 +151,12 @@ tftp_receive (grub_net_socket_t sock, struct grub_net_buff *nb) { data->block++; unsigned size = nb->tail - nb->data; - if (size < 1024) + if (size < data->block_size) sock->status = 2; /* Prevent garbage in broken cards. */ - if (size > 1024) + if (size > data->block_size) { - err = grub_netbuff_unput (nb, size - 1024); + err = grub_netbuff_unput (nb, size - data->block_size); if (err) return err; } diff --git a/include/grub/i386/pc/kernel.h b/include/grub/i386/pc/kernel.h index 1de37a5d5..dd50aa833 100644 --- a/include/grub/i386/pc/kernel.h +++ b/include/grub/i386/pc/kernel.h @@ -44,6 +44,8 @@ extern grub_int32_t grub_install_bsd_part; /* The boot BIOS drive number. */ extern grub_uint8_t EXPORT_VAR(grub_boot_drive); +extern void (*EXPORT_VAR(grub_pc_net_config)) (char **device, char **path); + #endif /* ! ASM_FILE */ #endif /* ! KERNEL_MACHINE_HEADER */ diff --git a/include/grub/net.h b/include/grub/net.h index 6aaf391d5..494826625 100644 --- a/include/grub/net.h +++ b/include/grub/net.h @@ -242,11 +242,11 @@ typedef struct grub_net char *server; grub_net_app_level_t protocol; grub_net_socket_t socket; + grub_off_t offset; grub_fs_t fs; } *grub_net_t; extern grub_net_t (*EXPORT_VAR (grub_net_open)) (const char *name); -extern grub_err_t (*EXPORT_VAR (grub_file_net_seek)) (struct grub_file *file, grub_off_t offset); extern void (*EXPORT_VAR (grub_grubnet_fini)) (void); struct grub_net_network_level_interface diff --git a/include/grub/net/tftp.h b/include/grub/net/tftp.h index c67380817..0d8cbd1de 100644 --- a/include/grub/net/tftp.h +++ b/include/grub/net/tftp.h @@ -43,12 +43,6 @@ /* * own here because this is cleaner, and maps to the same data layout. * */ -typedef struct tftp_data - { - int file_size; - int block; - } *tftp_data_t; - struct tftphdr { grub_uint16_t opcode; From cbe20661f64d0820c3768ec1fe319436be192f22 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 2 Jul 2011 18:05:40 +0200 Subject: [PATCH 717/869] minor stylistic cleanup --- grub-core/net/tftp.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/grub-core/net/tftp.c b/grub-core/net/tftp.c index b112f643e..700f0effd 100644 --- a/grub-core/net/tftp.c +++ b/grub-core/net/tftp.c @@ -75,7 +75,8 @@ tftp_open (struct grub_file *file, const char *filename) rrq += grub_strlen ("0") + 1; hdrlen = sizeof (tftph->opcode) + rrqlen; - if ((err = grub_netbuff_unput (&nb, nb.tail - (nb.data + hdrlen))) != GRUB_ERR_NONE) + err = grub_netbuff_unput (&nb, nb.tail - (nb.data + hdrlen)); + if (err) return err; file->device->net->socket->out_port = TFTP_SERVER_PORT; From 0c51bb63c5ef4555dab8aeedcaed309160111cd7 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 2 Jul 2011 18:57:24 +0200 Subject: [PATCH 718/869] add missing brackets in efi_wrap macroses --- include/grub/efi/api.h | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/include/grub/efi/api.h b/include/grub/efi/api.h index 5cd1686ea..b20baa015 100644 --- a/include/grub/efi/api.h +++ b/include/grub/efi/api.h @@ -1359,27 +1359,31 @@ typedef struct grub_efi_block_io grub_efi_block_io_t; #define efi_call_0(func) \ efi_wrap_0(func) #define efi_call_1(func, a) \ - efi_wrap_1(func, (grub_uint64_t) a) + efi_wrap_1(func, (grub_uint64_t) (a)) #define efi_call_2(func, a, b) \ - efi_wrap_2(func, (grub_uint64_t) a, (grub_uint64_t) b) + efi_wrap_2(func, (grub_uint64_t) (a), (grub_uint64_t) (b)) #define efi_call_3(func, a, b, c) \ - efi_wrap_3(func, (grub_uint64_t) a, (grub_uint64_t) b, (grub_uint64_t) c) + efi_wrap_3(func, (grub_uint64_t) (a), (grub_uint64_t) (b), \ + (grub_uint64_t) (c)) #define efi_call_4(func, a, b, c, d) \ - efi_wrap_4(func, (grub_uint64_t) a, (grub_uint64_t) b, (grub_uint64_t) c, \ - (grub_uint64_t) d) + efi_wrap_4(func, (grub_uint64_t) (a), (grub_uint64_t) (b), \ + (grub_uint64_t) (c), (grub_uint64_t) (d)) #define efi_call_5(func, a, b, c, d, e) \ - efi_wrap_5(func, (grub_uint64_t) a, (grub_uint64_t) b, (grub_uint64_t) c, \ - (grub_uint64_t) d, (grub_uint64_t) e) + efi_wrap_5(func, (grub_uint64_t) (a), (grub_uint64_t) (b), \ + (grub_uint64_t) (c), (grub_uint64_t) (d), (grub_uint64_t) (e)) #define efi_call_6(func, a, b, c, d, e, f) \ - efi_wrap_6(func, (grub_uint64_t) a, (grub_uint64_t) b, (grub_uint64_t) c, \ - (grub_uint64_t) d, (grub_uint64_t) e, (grub_uint64_t) f) + efi_wrap_6(func, (grub_uint64_t) (a), (grub_uint64_t) (b), \ + (grub_uint64_t) (c), (grub_uint64_t) (d), (grub_uint64_t) (e), \ + (grub_uint64_t) (f)) #define efi_call_7(func, a, b, c, d, e, f, g) \ - efi_wrap_7(func, (grub_uint64_t) a, (grub_uint64_t) b, (grub_uint64_t) c, \ - (grub_uint64_t) d, (grub_uint64_t) e, (grub_uint64_t) f, (grub_uint64_t) g) + efi_wrap_7(func, (grub_uint64_t) (a), (grub_uint64_t) (b), \ + (grub_uint64_t) (c), (grub_uint64_t) (d), (grub_uint64_t) (e), \ + (grub_uint64_t) (f), (grub_uint64_t) (g)) #define efi_call_10(func, a, b, c, d, e, f, g, h, i, j) \ - efi_wrap_10(func, (grub_uint64_t) a, (grub_uint64_t) b, (grub_uint64_t) c, \ - (grub_uint64_t) d, (grub_uint64_t) e, (grub_uint64_t) f, (grub_uint64_t) g, \ - (grub_uint64_t) h, (grub_uint64_t) i, (grub_uint64_t) j) + efi_wrap_10(func, (grub_uint64_t) (a), (grub_uint64_t) (b), \ + (grub_uint64_t) (c), (grub_uint64_t) (d), (grub_uint64_t) (e), \ + (grub_uint64_t) (f), (grub_uint64_t) (g), (grub_uint64_t) (h), \ + (grub_uint64_t) (i), (grub_uint64_t) (j)) grub_uint64_t EXPORT_FUNC(efi_wrap_0) (void *func); grub_uint64_t EXPORT_FUNC(efi_wrap_1) (void *func, grub_uint64_t arg1); From c4d038f632e39faba9506122af29d926cff9267e Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 2 Jul 2011 20:11:29 +0200 Subject: [PATCH 719/869] Don't react to adressed bootp packets unless in bootp transaction --- grub-core/kern/emu/main.c | 10 +++++--- grub-core/net/ip.c | 51 +++++++++++++++++++-------------------- grub-core/net/net.c | 12 ++++----- grub-core/net/udp.c | 7 +++--- include/grub/net.h | 2 +- 5 files changed, 43 insertions(+), 39 deletions(-) diff --git a/grub-core/kern/emu/main.c b/grub-core/kern/emu/main.c index 096e97090..2092d03cb 100644 --- a/grub-core/kern/emu/main.c +++ b/grub-core/kern/emu/main.c @@ -49,7 +49,7 @@ static jmp_buf main_env; /* Store the prefix specified by an argument. */ -static char *root_dev = NULL, *dir = DEFAULT_DIRECTORY; +static char *root_dev = NULL, *dir = NULL; int grub_no_autoload; @@ -139,14 +139,18 @@ main (int argc, char *argv[]) set_program_name (argv[0]); + dir = xstrdup (DEFAULT_DIRECTORY); + while ((opt = getopt_long (argc, argv, "r:d:m:vH:hV", options, 0)) != -1) switch (opt) { case 'r': - root_dev = optarg; + free (root_dev); + root_dev = xstrdup (optarg); break; case 'd': - dir = optarg; + free (dir); + dir = xstrdup (optarg); break; case 'm': dev_map = optarg; diff --git a/grub-core/net/ip.c b/grub-core/net/ip.c index 776937a6e..8b06f7d11 100644 --- a/grub-core/net/ip.c +++ b/grub-core/net/ip.c @@ -65,50 +65,49 @@ grub_net_recv_ip_packets (struct grub_net_buff * nb, { struct iphdr *iph = (struct iphdr *) nb->data; grub_err_t err; - struct grub_net_network_level_interface *inf; + struct grub_net_network_level_interface *inf = NULL; err = grub_netbuff_pull (nb, sizeof (*iph)); if (err) return err; - FOR_NET_NETWORK_LEVEL_INTERFACES (inf) + /* DHCP needs special treatment since we don't know IP yet. */ { - if (inf->card == card - && inf->address.type == GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4 - && inf->address.ipv4 == iph->dest - && grub_net_hwaddr_cmp (&inf->hwaddress, hwaddress) == 0) - break; + struct udphdr *udph; + udph = (struct udphdr *) nb->data; + if (iph->protocol == IP_UDP && grub_be_to_cpu16 (udph->dst) == 68) + { + FOR_NET_NETWORK_LEVEL_INTERFACES (inf) + if (inf->card == card + && inf->address.type == GRUB_NET_NETWORK_LEVEL_PROTOCOL_DHCP_RECV + && grub_net_hwaddr_cmp (&inf->hwaddress, hwaddress) == 0) + { + err = grub_netbuff_pull (nb, sizeof (*udph)); + if (err) + return err; + grub_net_process_dhcp (nb, inf->card); + grub_netbuff_free (nb); + } + return GRUB_ERR_NONE; + } } + if (!inf) { FOR_NET_NETWORK_LEVEL_INTERFACES (inf) + { if (inf->card == card - && inf->address.type == GRUB_NET_NETWORK_LEVEL_PROTOCOL_PROMISC + && inf->address.type == GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4 + && inf->address.ipv4 == iph->dest && grub_net_hwaddr_cmp (&inf->hwaddress, hwaddress) == 0) - break; - } - if (!inf) - { - if (iph->protocol == IP_UDP - && grub_net_hwaddr_cmp (&card->default_address, hwaddress) == 0) - { - struct udphdr *udph; - udph = (struct udphdr *) nb->data; - err = grub_netbuff_pull (nb, sizeof (*udph)); - if (err) - return err; - if (grub_be_to_cpu16 (udph->dst) == 68) - grub_net_process_dhcp (nb, card); - } - grub_netbuff_free (nb); - return GRUB_ERR_NONE; + break; + } } switch (iph->protocol) { case IP_UDP: return grub_net_recv_udp_packet (nb, inf); - break; default: grub_netbuff_free (nb); break; diff --git a/grub-core/net/net.c b/grub-core/net/net.c index a56860eed..d5f9e374e 100644 --- a/grub-core/net/net.c +++ b/grub-core/net/net.c @@ -119,7 +119,7 @@ match_net (const grub_net_network_level_netaddress_t *net, return 0; switch (net->type) { - case GRUB_NET_NETWORK_LEVEL_PROTOCOL_PROMISC: + case GRUB_NET_NETWORK_LEVEL_PROTOCOL_DHCP_RECV: return 0; case GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4: { @@ -238,8 +238,8 @@ grub_net_addr_to_str (const grub_net_network_level_address_t *target, char *buf) { switch (target->type) { - case GRUB_NET_NETWORK_LEVEL_PROTOCOL_PROMISC: - grub_strcpy (buf, "promisc"); + case GRUB_NET_NETWORK_LEVEL_PROTOCOL_DHCP_RECV: + grub_strcpy (buf, "temporary"); return; case GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4: { @@ -521,8 +521,8 @@ print_net_address (const grub_net_network_level_netaddress_t *target) { switch (target->type) { - case GRUB_NET_NETWORK_LEVEL_PROTOCOL_PROMISC: - grub_printf ("promisc\n"); + case GRUB_NET_NETWORK_LEVEL_PROTOCOL_DHCP_RECV: + grub_printf ("temporary\n"); break; case GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4: { @@ -1257,7 +1257,7 @@ grub_cmd_bootp (struct grub_command *cmd __attribute__ ((unused)), grub_free (ifaces); return grub_errno; } - ifaces[j].address.type = GRUB_NET_NETWORK_LEVEL_PROTOCOL_PROMISC; + ifaces[j].address.type = GRUB_NET_NETWORK_LEVEL_PROTOCOL_DHCP_RECV; grub_memcpy (&ifaces[j].hwaddress, &card->default_address, sizeof (ifaces[j].hwaddress)); j++; diff --git a/grub-core/net/udp.c b/grub-core/net/udp.c index 95134c0cf..b9339e49a 100644 --- a/grub-core/net/udp.c +++ b/grub-core/net/udp.c @@ -32,8 +32,11 @@ grub_net_recv_udp_packet (struct grub_net_buff * nb, { struct udphdr *udph; grub_net_socket_t sock; + grub_err_t err; udph = (struct udphdr *) nb->data; - grub_netbuff_pull (nb, sizeof (*udph)); + err = grub_netbuff_pull (nb, sizeof (*udph)); + if (err) + return err; FOR_NET_SOCKETS (sock) { @@ -54,8 +57,6 @@ grub_net_recv_udp_packet (struct grub_net_buff * nb, return GRUB_ERR_NONE; } } - if (grub_be_to_cpu16 (udph->dst) == 68) - grub_net_process_dhcp (nb, inf->card); grub_netbuff_free (nb); return GRUB_ERR_NONE; } diff --git a/include/grub/net.h b/include/grub/net.h index 494826625..630fd33fb 100644 --- a/include/grub/net.h +++ b/include/grub/net.h @@ -123,7 +123,7 @@ struct grub_net_network_level_interface; typedef enum grub_network_level_protocol_id { - GRUB_NET_NETWORK_LEVEL_PROTOCOL_PROMISC, + GRUB_NET_NETWORK_LEVEL_PROTOCOL_DHCP_RECV, GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4 } grub_network_level_protocol_id_t; From 77546584e1466b4702a60b83df674ca4337b2627 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Sutre?= Date: Sat, 2 Jul 2011 21:22:19 +0200 Subject: [PATCH 720/869] Use @PACKAGE@ instead of hardcoded name when sourcing grub-mkconfig_lib. --- ChangeLog | 14 ++++++++++++++ util/grub-mkconfig.in | 2 +- util/grub.d/00_header.in | 2 +- util/grub.d/10_hurd.in | 2 +- util/grub.d/10_kfreebsd.in | 2 +- util/grub.d/10_linux.in | 2 +- util/grub.d/10_netbsd.in | 2 +- util/grub.d/10_windows.in | 2 +- util/grub.d/20_linux_xen.in | 2 +- util/grub.d/30_os-prober.in | 2 +- util/update-grub_lib.in | 2 +- 11 files changed, 24 insertions(+), 10 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4b8d8f149..e091265d4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +2011-07-02 GrĂ©goire Sutre + + * util/grub-mkconfig.in: Use @PACKAGE@ instead of hardcoded name when + sourcing grub-mkconfig_lib. + * util/update-grub_lib.in: Likewise. + * util/grub.d/00_header.in: Likewise. + * util/grub.d/10_hurd.in: Likewise. + * util/grub.d/10_kfreebsd.in: Likewise. + * util/grub.d/10_linux.in: Likewise. + * util/grub.d/10_netbsd.in: Likewise. + * util/grub.d/10_windows.in: Likewise. + * util/grub.d/20_linux_xen.in: Likewise. + * util/grub.d/30_os-prober.in: Likewise. + 2011-06-28 Colin Watson * grub-core/term/gfxterm.c (grub_virtual_screen_setup): Use diff --git a/util/grub-mkconfig.in b/util/grub-mkconfig.in index 4d627c057..cf94d1065 100644 --- a/util/grub-mkconfig.in +++ b/util/grub-mkconfig.in @@ -95,7 +95,7 @@ do esac done -. ${libdir}/grub/grub-mkconfig_lib +. ${libdir}/@PACKAGE@/grub-mkconfig_lib if [ "x$EUID" = "x" ] ; then EUID=`id -u` diff --git a/util/grub.d/00_header.in b/util/grub.d/00_header.in index 9da1511f5..7b8871d4d 100644 --- a/util/grub.d/00_header.in +++ b/util/grub.d/00_header.in @@ -25,7 +25,7 @@ libdir=@libdir@ locale_dir=`echo ${GRUB_PREFIX}/locale | sed ${transform}` grub_lang=`echo $LANG | cut -d . -f 1` -. ${libdir}/grub/grub-mkconfig_lib +. ${libdir}/@PACKAGE@/grub-mkconfig_lib # Do this as early as possible, since other commands might depend on it. # (e.g. the `loadfont' command might need lvm or raid modules) diff --git a/util/grub.d/10_hurd.in b/util/grub.d/10_hurd.in index 8c54eab97..9ca01f0a8 100644 --- a/util/grub.d/10_hurd.in +++ b/util/grub.d/10_hurd.in @@ -20,7 +20,7 @@ set -e prefix=@prefix@ exec_prefix=@exec_prefix@ libdir=@libdir@ -. ${libdir}/grub/grub-mkconfig_lib +. ${libdir}/@PACKAGE@/grub-mkconfig_lib CLASS="--class gnu --class os" diff --git a/util/grub.d/10_kfreebsd.in b/util/grub.d/10_kfreebsd.in index 3600c74f9..2ade4ea35 100644 --- a/util/grub.d/10_kfreebsd.in +++ b/util/grub.d/10_kfreebsd.in @@ -21,7 +21,7 @@ prefix=@prefix@ exec_prefix=@exec_prefix@ bindir=@bindir@ libdir=@libdir@ -. ${libdir}/grub/grub-mkconfig_lib +. ${libdir}/@PACKAGE@/grub-mkconfig_lib export TEXTDOMAIN=@PACKAGE@ export TEXTDOMAINDIR=@localedir@ diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in index 1d1eb403f..97e7c6523 100644 --- a/util/grub.d/10_linux.in +++ b/util/grub.d/10_linux.in @@ -21,7 +21,7 @@ prefix=@prefix@ exec_prefix=@exec_prefix@ bindir=@bindir@ libdir=@libdir@ -. ${libdir}/grub/grub-mkconfig_lib +. ${libdir}/@PACKAGE@/grub-mkconfig_lib export TEXTDOMAIN=@PACKAGE@ export TEXTDOMAINDIR=@localedir@ diff --git a/util/grub.d/10_netbsd.in b/util/grub.d/10_netbsd.in index ffd31ad93..c257aeb3c 100644 --- a/util/grub.d/10_netbsd.in +++ b/util/grub.d/10_netbsd.in @@ -21,7 +21,7 @@ prefix=@prefix@ exec_prefix=@exec_prefix@ bindir=@bindir@ libdir=@libdir@ -. ${libdir}/grub/grub-mkconfig_lib +. ${libdir}/@PACKAGE@/grub-mkconfig_lib export TEXTDOMAIN=@PACKAGE@ export TEXTDOMAINDIR=@localedir@ diff --git a/util/grub.d/10_windows.in b/util/grub.d/10_windows.in index fd068dd2d..941267a9f 100644 --- a/util/grub.d/10_windows.in +++ b/util/grub.d/10_windows.in @@ -20,7 +20,7 @@ set -e prefix=@prefix@ exec_prefix=@exec_prefix@ libdir=@libdir@ -. ${libdir}/grub/grub-mkconfig_lib +. ${libdir}/@PACKAGE@/grub-mkconfig_lib case "`uname 2>/dev/null`" in CYGWIN*) ;; diff --git a/util/grub.d/20_linux_xen.in b/util/grub.d/20_linux_xen.in index 083391c40..c0b255598 100644 --- a/util/grub.d/20_linux_xen.in +++ b/util/grub.d/20_linux_xen.in @@ -21,7 +21,7 @@ prefix=@prefix@ exec_prefix=@exec_prefix@ bindir=@bindir@ libdir=@libdir@ -. ${libdir}/grub/grub-mkconfig_lib +. ${libdir}/@PACKAGE@/grub-mkconfig_lib export TEXTDOMAIN=@PACKAGE@ export TEXTDOMAINDIR=@localedir@ diff --git a/util/grub.d/30_os-prober.in b/util/grub.d/30_os-prober.in index d9d4b0a96..c0b5d7cd7 100644 --- a/util/grub.d/30_os-prober.in +++ b/util/grub.d/30_os-prober.in @@ -21,7 +21,7 @@ prefix=@prefix@ exec_prefix=@exec_prefix@ libdir=@libdir@ -. ${libdir}/grub/grub-mkconfig_lib +. ${libdir}/@PACKAGE@/grub-mkconfig_lib if [ "x${GRUB_DISABLE_OS_PROBER}" = "xtrue" ]; then exit 0 diff --git a/util/update-grub_lib.in b/util/update-grub_lib.in index 998452e67..430ce1308 100644 --- a/util/update-grub_lib.in +++ b/util/update-grub_lib.in @@ -18,6 +18,6 @@ prefix=@prefix@ exec_prefix=@exec_prefix@ libdir=@libdir@ -. ${libdir}/grub/grub-mkconfig_lib +. ${libdir}/@PACKAGE@/grub-mkconfig_lib grub_warn "update-grub_lib is deprecated, use grub-mkconfig_lib instead" From 7e0c2d162afd175580074eb7386811e0694aaed3 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 2 Jul 2011 22:13:33 +0200 Subject: [PATCH 721/869] Restructurisations, cleanups and few bugfixes --- grub-core/net/arp.c | 3 +- grub-core/net/net.c | 94 +++++++---------- grub-core/net/tftp.c | 226 ++++++++++++++++++++++++----------------- grub-core/net/udp.c | 65 +++++++++--- include/grub/net.h | 25 +++-- include/grub/net/udp.h | 16 +++ 6 files changed, 251 insertions(+), 178 deletions(-) diff --git a/grub-core/net/arp.c b/grub-core/net/arp.c index fecde3282..d726f2c3a 100644 --- a/grub-core/net/arp.c +++ b/grub-core/net/arp.c @@ -144,7 +144,8 @@ grub_net_arp_receive (struct grub_net_buff *nb) FOR_NET_NETWORK_LEVEL_INTERFACES (inf) { /* Am I the protocol address target? */ - if (grub_memcmp (target_protocol_address, &inf->address.ipv4, 6) == 0 + if (inf->address.type == GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4 + && grub_memcmp (target_protocol_address, &inf->address.ipv4, 4) == 0 && grub_be_to_cpu16 (arp_header->op) == ARP_REQUEST) { grub_net_link_level_address_t aux; diff --git a/grub-core/net/net.c b/grub-core/net/net.c index d5f9e374e..595379a99 100644 --- a/grub-core/net/net.c +++ b/grub-core/net/net.c @@ -27,6 +27,7 @@ #include #include #include +#include #include #include @@ -630,25 +631,27 @@ grub_net_open_real (const char *name) { protnamelen = comma - name; server = comma + 1; + protname = name; } else { protnamelen = grub_strlen (name); server = default_server; + protname = name; } } if (!server) { grub_error (GRUB_ERR_NET_BAD_ADDRESS, "no server"); return NULL; - } + } FOR_NET_APP_LEVEL (proto) { if (grub_memcmp (proto->name, protname, protnamelen) == 0 && proto->name[protnamelen] == 0) { - grub_net_t ret = grub_malloc (sizeof (*ret)); + grub_net_t ret = grub_zalloc (sizeof (*ret)); if (!ret) return NULL; ret->protocol = proto; @@ -665,6 +668,7 @@ grub_net_open_real (const char *name) ret->server = NULL; ret->fs = &grub_net_fs; ret->offset = 0; + ret->eof = 0; return ret; } } @@ -686,61 +690,26 @@ grub_net_fs_dir (grub_device_t device, const char *path __attribute__ ((unused)) static grub_err_t grub_net_fs_open (struct grub_file *file, const char *name) { - grub_err_t err; - grub_net_network_level_address_t addr; - struct grub_net_network_level_interface *inf; - grub_net_network_level_address_t gateway; - grub_net_socket_t socket; - static int port = 25300; - - err = grub_net_resolve_address (file->device->net->server, &addr); - if (err) - return err; - - err = grub_net_route_address (addr, &gateway, &inf); - if (err) - return err; - - socket = (grub_net_socket_t) grub_malloc (sizeof (*socket)); - if (socket == NULL) - return grub_errno; - - socket->inf = inf; - socket->out_nla = addr; - socket->in_port = port++; - socket->status = 0; - socket->app = file->device->net->protocol; - socket->packs.first = NULL; - socket->packs.last = NULL; - file->device->net->socket = socket; - grub_net_socket_register (socket); - - err = file->device->net->protocol->open (file,name); - if (err) - goto fail; - file->not_easily_seekable = 1; - - return GRUB_ERR_NONE; -fail: - grub_net_socket_unregister (socket); - grub_free (socket); - return err; + file->device->net->packs.first = NULL; + file->device->net->packs.last = NULL; + file->device->net->name = grub_strdup (name); + if (!file->device->net->name) + return grub_errno; + return file->device->net->protocol->open (file, name); } static grub_err_t grub_net_fs_close (grub_file_t file) { - grub_net_socket_t sock = file->device->net->socket; - while (sock->packs.first) + while (file->device->net->packs.first) { - grub_netbuff_free (sock->packs.first->nb); - grub_net_remove_packet (sock->packs.first); + grub_netbuff_free (file->device->net->packs.first->nb); + grub_net_remove_packet (file->device->net->packs.first); } - grub_net_socket_unregister (sock); - grub_free (sock); + file->device->net->protocol->close (file); + grub_free (file->device->net->name); return GRUB_ERR_NONE; - } static void @@ -787,9 +756,9 @@ grub_net_poll_cards (unsigned time) static grub_ssize_t grub_net_fs_read_real (grub_file_t file, char *buf, grub_size_t len) { - grub_net_socket_t sock = file->device->net->socket; + grub_net_t sock = file->device->net; struct grub_net_buff *nb; - char *ptr = buf; + char *ptr = buf; grub_size_t amount, total = 0; int try = 0; while (try <= 3) @@ -820,7 +789,7 @@ grub_net_fs_read_real (grub_file_t file, char *buf, grub_size_t len) if (!len) return total; } - if (sock->status == 1) + if (!sock->eof) { try++; grub_net_poll_cards (200); @@ -834,18 +803,29 @@ grub_net_fs_read_real (grub_file_t file, char *buf, grub_size_t len) static grub_err_t grub_net_seek_real (struct grub_file *file, grub_off_t offset) { - grub_net_socket_t sock = file->device->net->socket; - struct grub_net_buff *nb; grub_size_t len = offset - file->device->net->offset; if (!len) return GRUB_ERR_NONE; - /* We cant seek backwards past the current packet. */ if (file->device->net->offset > offset) - { - nb = sock->packs.first->nb; - return grub_netbuff_push (nb, file->device->net->offset - offset); + { + grub_err_t err; + while (file->device->net->packs.first) + { + grub_netbuff_free (file->device->net->packs.first->nb); + grub_net_remove_packet (file->device->net->packs.first); + } + file->device->net->protocol->close (file); + + file->device->net->packs.first = NULL; + file->device->net->packs.last = NULL; + file->device->net->offset = 0; + file->device->net->eof = 0; + err = file->device->net->protocol->open (file, file->device->net->name); + if (err) + return err; + len = offset; } grub_net_fs_read_real (file, NULL, len); diff --git a/grub-core/net/tftp.c b/grub-core/net/tftp.c index 700f0effd..6ffe27669 100644 --- a/grub-core/net/tftp.c +++ b/grub-core/net/tftp.c @@ -16,8 +16,107 @@ typedef struct tftp_data grub_uint64_t file_size; grub_uint64_t block; grub_uint32_t block_size; + int have_oack; + grub_net_socket_t sock; } *tftp_data_t; +static grub_err_t +tftp_receive (grub_net_socket_t sock __attribute__ ((unused)), + struct grub_net_buff *nb, + void *f) +{ + grub_file_t file = f; + struct tftphdr *tftph = (void *) nb->data; + char nbdata[512]; + tftp_data_t data = file->data; + grub_err_t err; + char *ptr; + struct grub_net_buff nb_ack; + + nb_ack.head = nbdata; + nb_ack.end = nbdata + sizeof (nbdata); + + tftph = (struct tftphdr *) nb->data; + switch (grub_be_to_cpu16 (tftph->opcode)) + { + case TFTP_OACK: + data->block_size = 512; + data->have_oack = 1; + for (ptr = nb->data + sizeof (tftph->opcode); ptr < nb->tail;) + { + if (grub_memcmp (ptr, "tsize\0", sizeof ("tsize\0") - 1) == 0) + { + data->file_size = grub_strtoul (ptr + sizeof ("tsize\0") - 1, + 0, 0); + } + if (grub_memcmp (ptr, "blksize\0", sizeof ("blksize\0") - 1) == 0) + { + data->block_size = grub_strtoul (ptr + sizeof ("blksize\0") - 1, + 0, 0); + } + while (ptr < nb->tail && *ptr) + ptr++; + ptr++; + } + data->block = 0; + grub_netbuff_free (nb); + break; + case TFTP_DATA: + err = grub_netbuff_pull (nb, sizeof (tftph->opcode) + + sizeof (tftph->u.data.block)); + if (err) + return err; + if (grub_be_to_cpu16 (tftph->u.data.block) == data->block + 1) + { + unsigned size = nb->tail - nb->data; + data->block++; + if (size < data->block_size) + { + file->device->net->eof = 1; + } + /* Prevent garbage in broken cards. */ + if (size > data->block_size) + { + err = grub_netbuff_unput (nb, size - data->block_size); + if (err) + return err; + } + /* If there is data, puts packet in socket list. */ + if ((nb->tail - nb->data) > 0) + grub_net_put_packet (&file->device->net->packs, nb); + else + grub_netbuff_free (nb); + } + else + { + grub_netbuff_free (nb); + return GRUB_ERR_NONE; + } + break; + case TFTP_ERROR: + grub_netbuff_free (nb); + return grub_error (GRUB_ERR_IO, (char *) tftph->u.err.errmsg); + } + grub_netbuff_clear (&nb_ack); + grub_netbuff_reserve (&nb_ack, 512); + err = grub_netbuff_push (&nb_ack, sizeof (tftph->opcode) + + sizeof (tftph->u.ack.block)); + if (err) + return err; + + tftph = (struct tftphdr *) nb_ack.data; + tftph->opcode = grub_cpu_to_be16 (TFTP_ACK); + tftph->u.ack.block = grub_cpu_to_be16 (data->block); + + err = grub_net_send_udp_packet (data->sock, &nb_ack); + if (file->device->net->eof) + { + grub_net_udp_close (data->sock); + data->sock = NULL; + } + return err; +} + static grub_err_t tftp_open (struct grub_file *file, const char *filename) { @@ -31,17 +130,17 @@ tftp_open (struct grub_file *file, const char *filename) tftp_data_t data; grub_err_t err; - data = grub_malloc (sizeof (*data)); + data = grub_zalloc (sizeof (*data)); if (!data) return grub_errno; - file->device->net->socket->data = (void *) data; nb.head = open_data; nb.end = open_data + sizeof (open_data); grub_netbuff_clear (&nb); grub_netbuff_reserve (&nb, 1500); - if ((err = grub_netbuff_push (&nb, sizeof (*tftph))) != GRUB_ERR_NONE) + err = grub_netbuff_push (&nb, sizeof (*tftph)); + if (err) return err; tftph = (struct tftphdr *) nb.data; @@ -78,11 +177,21 @@ tftp_open (struct grub_file *file, const char *filename) err = grub_netbuff_unput (&nb, nb.tail - (nb.data + hdrlen)); if (err) return err; - file->device->net->socket->out_port = TFTP_SERVER_PORT; - err = grub_net_send_udp_packet (file->device->net->socket, &nb); + file->not_easily_seekable = 1; + file->data = data; + data->sock = grub_net_udp_open (file->device->net->server, + TFTP_SERVER_PORT, tftp_receive, + file); + if (!data->sock) + return grub_errno; + + err = grub_net_send_udp_packet (data->sock, &nb); if (err) - return err; + { + grub_net_udp_close (data->sock); + return err; + } /* Receive OACK packet. */ for (i = 0; i < 3; i++) @@ -90,106 +199,34 @@ tftp_open (struct grub_file *file, const char *filename) grub_net_poll_cards (100); if (grub_errno) return grub_errno; - if (file->device->net->socket->status != 0) + if (data->have_oack) break; /* Retry. */ - err = grub_net_send_udp_packet (file->device->net->socket, &nb); + err = grub_net_send_udp_packet (data->sock, &nb); if (err) - return err; + { + grub_net_udp_close (data->sock); + return err; + } } - if (file->device->net->socket->status == 0) - return grub_error (GRUB_ERR_TIMEOUT, "Time out opening tftp."); + if (!data->have_oack) + { + grub_net_udp_close (data->sock); + return grub_error (GRUB_ERR_TIMEOUT, "Time out opening tftp."); + } file->size = data->file_size; return GRUB_ERR_NONE; } static grub_err_t -tftp_receive (grub_net_socket_t sock, struct grub_net_buff *nb) +tftp_close (struct grub_file *file) { - struct tftphdr *tftph; - char nbdata[128]; - tftp_data_t data = sock->data; - grub_err_t err; - char *ptr; - struct grub_net_buff nb_ack; - - nb_ack.head = nbdata; - nb_ack.end = nbdata + sizeof (nbdata); - - tftph = (struct tftphdr *) nb->data; - switch (grub_be_to_cpu16 (tftph->opcode)) - { - case TFTP_OACK: - data->block_size = 512; - for (ptr = nb->data + sizeof (tftph->opcode); ptr < nb->tail;) - { - if (grub_memcmp (ptr, "tsize\0", sizeof ("tsize\0") - 1) == 0) - { - data->file_size = grub_strtoul (ptr + sizeof ("tsize\0") - 1, - 0, 0); - } - if (grub_memcmp (ptr, "blksize\0", sizeof ("blksize\0") - 1) == 0) - { - data->block_size = grub_strtoul (ptr + sizeof ("blksize\0") - 1, - 0, 0); - } - while (ptr < nb->tail && *ptr) - ptr++; - ptr++; - } - sock->status = 1; - data->block = 0; - grub_netbuff_clear (nb); - break; - case TFTP_DATA: - err = grub_netbuff_pull (nb, sizeof (tftph->opcode) + - sizeof (tftph->u.data.block)); - if (err) - return err; - if (grub_be_to_cpu16 (tftph->u.data.block) == data->block + 1) - { - data->block++; - unsigned size = nb->tail - nb->data; - if (size < data->block_size) - sock->status = 2; - /* Prevent garbage in broken cards. */ - if (size > data->block_size) - { - err = grub_netbuff_unput (nb, size - data->block_size); - if (err) - return err; - } - } - else - grub_netbuff_clear (nb); - - break; - case TFTP_ERROR: - grub_netbuff_clear (nb); - return grub_error (GRUB_ERR_IO, (char *) tftph->u.err.errmsg); - break; - } - grub_netbuff_clear (&nb_ack); - grub_netbuff_reserve (&nb_ack, 128); - err = grub_netbuff_push (&nb_ack, sizeof (tftph->opcode) - + sizeof (tftph->u.ack.block)); - if (err) - return err; - - tftph = (struct tftphdr *) nb_ack.data; - tftph->opcode = grub_cpu_to_be16 (TFTP_ACK); - tftph->u.ack.block = grub_cpu_to_be16 (data->block); - - err = grub_net_send_udp_packet (sock, &nb_ack); - return err; -} - -static grub_err_t -tftp_close (struct grub_file *file __attribute__ ((unused))) -{ - grub_free (file->device->net->socket->data); + tftp_data_t data = file->data; + if (data->sock) + grub_net_udp_close (data->sock); + grub_free (data); return GRUB_ERR_NONE; } @@ -197,7 +234,6 @@ static struct grub_net_app_protocol grub_tftp_protocol = { .name = "tftp", .open = tftp_open, - .read = tftp_receive, .close = tftp_close }; diff --git a/grub-core/net/udp.c b/grub-core/net/udp.c index b9339e49a..47a67a967 100644 --- a/grub-core/net/udp.c +++ b/grub-core/net/udp.c @@ -4,6 +4,46 @@ #include #include +grub_net_socket_t +grub_net_udp_open (char *server, + grub_uint16_t out_port, + grub_err_t (*recv_hook) (grub_net_socket_t sock, + struct grub_net_buff *nb, + void *data), + void *recv_hook_data) +{ + grub_err_t err; + grub_net_network_level_address_t addr; + struct grub_net_network_level_interface *inf; + grub_net_network_level_address_t gateway; + grub_net_socket_t socket; + static int in_port = 25300; + + err = grub_net_resolve_address (server, &addr); + if (err) + return NULL; + + err = grub_net_route_address (addr, &gateway, &inf); + if (err) + return NULL; + + socket = grub_zalloc (sizeof (*socket)); + if (socket == NULL) + return NULL; + + socket->x_out_port = out_port; + socket->x_inf = inf; + socket->x_out_nla = addr; + socket->x_in_port = in_port++; + socket->x_status = GRUB_NET_SOCKET_START; + socket->recv_hook = recv_hook; + socket->recv_hook_data = recv_hook_data; + + grub_net_socket_register (socket); + + return socket; +} + grub_err_t grub_net_send_udp_packet (const grub_net_socket_t socket, struct grub_net_buff *nb) @@ -16,14 +56,14 @@ grub_net_send_udp_packet (const grub_net_socket_t socket, return err; udph = (struct udphdr *) nb->data; - udph->src = grub_cpu_to_be16 (socket->in_port); - udph->dst = grub_cpu_to_be16 (socket->out_port); + udph->src = grub_cpu_to_be16 (socket->x_in_port); + udph->dst = grub_cpu_to_be16 (socket->x_out_port); /* No chechksum. */ udph->chksum = 0; udph->len = grub_cpu_to_be16 (nb->tail - nb->data); - return grub_net_send_ip_packet (socket->inf, &(socket->out_nla), nb); + return grub_net_send_ip_packet (socket->x_inf, &(socket->x_out_nla), nb); } grub_err_t @@ -40,20 +80,17 @@ grub_net_recv_udp_packet (struct grub_net_buff * nb, FOR_NET_SOCKETS (sock) { - if (grub_be_to_cpu16 (udph->dst) == sock->in_port - && inf == sock->inf && sock->app) + if (grub_be_to_cpu16 (udph->dst) == sock->x_in_port + && inf == sock->x_inf && sock->recv_hook) { - if (sock->status == 0) - sock->out_port = grub_be_to_cpu16 (udph->src); + if (sock->x_status == GRUB_NET_SOCKET_START) + { + sock->x_out_port = grub_be_to_cpu16 (udph->src); + sock->x_status = GRUB_NET_SOCKET_ESTABLISHED; + } /* App protocol remove its own reader. */ - sock->app->read (sock, nb); - - /* If there is data, puts packet in socket list. */ - if ((nb->tail - nb->data) > 0) - grub_net_put_packet (&sock->packs, nb); - else - grub_netbuff_free (nb); + sock->recv_hook (sock, nb, sock->recv_hook_data); return GRUB_ERR_NONE; } } diff --git a/include/grub/net.h b/include/grub/net.h index 630fd33fb..0656787a6 100644 --- a/include/grub/net.h +++ b/include/grub/net.h @@ -201,22 +201,23 @@ struct grub_net_app_protocol int (*hook) (const char *filename, const struct grub_dirhook_info *info)); grub_err_t (*open) (struct grub_file *file, const char *filename); - grub_err_t (*read) (grub_net_socket_t sock, struct grub_net_buff *nb); grub_err_t (*close) (struct grub_file *file); - grub_err_t (*label) (grub_device_t device, char **label); }; struct grub_net_socket { struct grub_net_socket *next; - int status; - int in_port; - int out_port; - grub_net_app_level_t app; - grub_net_network_level_address_t out_nla; - struct grub_net_network_level_interface *inf; - grub_net_packets_t packs; - void *data; + + enum { GRUB_NET_SOCKET_START, + GRUB_NET_SOCKET_ESTABLISHED, + GRUB_NET_SOCKET_CLOSED } x_status; + int x_in_port; + int x_out_port; + grub_err_t (*recv_hook) (grub_net_socket_t sock, struct grub_net_buff *nb, + void *recv); + void *recv_hook_data; + grub_net_network_level_address_t x_out_nla; + struct grub_net_network_level_interface *x_inf; }; extern struct grub_net_socket *grub_net_sockets; @@ -240,10 +241,12 @@ grub_net_socket_unregister (grub_net_socket_t sock) typedef struct grub_net { char *server; + char *name; grub_net_app_level_t protocol; - grub_net_socket_t socket; + grub_net_packets_t packs; grub_off_t offset; grub_fs_t fs; + int eof; } *grub_net_t; extern grub_net_t (*EXPORT_VAR (grub_net_open)) (const char *name); diff --git a/include/grub/net/udp.h b/include/grub/net/udp.h index eacf3325c..272612299 100644 --- a/include/grub/net/udp.h +++ b/include/grub/net/udp.h @@ -11,6 +11,22 @@ struct udphdr grub_uint16_t chksum; } __attribute__ ((packed)); + +grub_net_socket_t +grub_net_udp_open (char *server, + grub_uint16_t out_port, + grub_err_t (*recv_hook) (grub_net_socket_t sock, + struct grub_net_buff *nb, + void *data), + void *recv_hook_data); + +static inline void +grub_net_udp_close (grub_net_socket_t sock) +{ + grub_net_socket_unregister (sock); + grub_free (sock); +} + grub_err_t grub_net_send_udp_packet (const grub_net_socket_t socket , struct grub_net_buff *nb); From 671a78acb0648d3d73c95ab0f021f907499aacc0 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Tue, 5 Jul 2011 14:34:10 +0200 Subject: [PATCH 722/869] cleanup pxe and efi network release --- grub-core/Makefile.core.def | 6 ---- grub-core/commands/i386/pc/pxecmd.c | 54 ----------------------------- grub-core/net/drivers/efi/efinet.c | 17 ++++----- grub-core/net/drivers/i386/pc/pxe.c | 50 ++++++++++++++++++++------ grub-core/net/net.c | 13 ------- include/grub/net.h | 23 ++---------- 6 files changed, 47 insertions(+), 116 deletions(-) delete mode 100644 grub-core/commands/i386/pc/pxecmd.c diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def index 2c9f48076..7004aaf23 100644 --- a/grub-core/Makefile.core.def +++ b/grub-core/Makefile.core.def @@ -714,12 +714,6 @@ module = { common = commands/probe.c; }; -module = { - name = pxecmd; - i386_pc = commands/i386/pc/pxecmd.c; - enable = i386_pc; -}; - module = { name = read; common = commands/read.c; diff --git a/grub-core/commands/i386/pc/pxecmd.c b/grub-core/commands/i386/pc/pxecmd.c deleted file mode 100644 index dffa15a3a..000000000 --- a/grub-core/commands/i386/pc/pxecmd.c +++ /dev/null @@ -1,54 +0,0 @@ -/* pxe.c - command to control the pxe driver */ -/* - * GRUB -- GRand Unified Bootloader - * Copyright (C) 2008,2009 Free Software Foundation, Inc. - * - * GRUB is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * GRUB is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GRUB. If not, see . - */ - -#include -#include -#include -#include -#include -#include - -GRUB_MOD_LICENSE ("GPLv3+"); - -static grub_err_t -grub_cmd_pxe_unload (grub_command_t cmd __attribute__ ((unused)), - int argc __attribute__ ((unused)), - char **args __attribute__ ((unused))) -{ - if (! grub_pxe_pxenv) - return grub_error (GRUB_ERR_FILE_NOT_FOUND, "no pxe environment"); - - grub_pxe_unload (); - - return 0; -} - -static grub_command_t cmd; - -GRUB_MOD_INIT(pxecmd) -{ - cmd = grub_register_command ("pxe_unload", grub_cmd_pxe_unload, - 0, - N_("Unload PXE environment.")); -} - -GRUB_MOD_FINI(pxecmd) -{ - grub_unregister_command (cmd); -} diff --git a/grub-core/net/drivers/efi/efinet.c b/grub-core/net/drivers/efi/efinet.c index 1328cd57c..4b2ffc038 100644 --- a/grub-core/net/drivers/efi/efinet.c +++ b/grub-core/net/drivers/efi/efinet.c @@ -184,23 +184,18 @@ grub_efi_net_config_real (grub_efi_handle_t hnd, char **device, } } - GRUB_MOD_INIT(efinet) { grub_efinet_findcards (); grub_efi_net_config = grub_efi_net_config_real; } -GRUB_MOD_FINI(ofnet) +GRUB_MOD_FINI(efinet) { - struct grub_net_card *card; - grub_efi_net_config = 0; - FOR_NET_CARDS (card) - if (card->driver && !grub_strcmp (card->driver->name, "efinet")) - { - card->driver->fini (card); - card->driver = NULL; - } - grub_net_card_driver_unregister (&efidriver); + struct grub_net_card *card, *next; + + FOR_NET_CARDS_SAFE (card, next) + if (card->driver && grub_strcmp (card->driver->name, "efinet") == 0) + grub_net_card_unregister (card); } diff --git a/grub-core/net/drivers/i386/pc/pxe.c b/grub-core/net/drivers/i386/pc/pxe.c index 51f4023a6..81607eb57 100644 --- a/grub-core/net/drivers/i386/pc/pxe.c +++ b/grub-core/net/drivers/i386/pc/pxe.c @@ -22,8 +22,8 @@ #include #include #include -#include #include +#include #include #include @@ -273,19 +273,36 @@ struct grub_net_card grub_pxe_card = .name = "pxe" }; -void -grub_pxe_unload (void) +static grub_err_t +grub_pxe_fini_hw (int noreturn __attribute__ ((unused))) { if (pxe_rm_entry) - { - grub_pxe_call (GRUB_PXENV_UNDI_CLOSE, - (void *) GRUB_MEMORY_MACHINE_SCRATCH_ADDR, - pxe_rm_entry); - grub_net_card_unregister (&grub_pxe_card); - grub_pxe_pxenv = 0; - } + grub_pxe_call (GRUB_PXENV_UNDI_CLOSE, + (void *) GRUB_MEMORY_MACHINE_SCRATCH_ADDR, + pxe_rm_entry); + + return GRUB_ERR_NONE; } +static grub_err_t +grub_pxe_restore_hw (void) +{ + struct grub_pxe_undi_open *ou; + ou = (void *) GRUB_MEMORY_MACHINE_SCRATCH_ADDR; + grub_memset (ou, 0, sizeof (*ou)); + ou->pkt_filter = 4; + grub_pxe_call (GRUB_PXENV_UNDI_OPEN, ou, pxe_rm_entry); + + if (ou->status) + { + grub_net_card_unregister (&grub_pxe_card); + return grub_error (GRUB_ERR_IO, "can't open UNDI"); + } + return GRUB_ERR_NONE; +} + +static void *fini_hnd; + static void grub_pc_net_config_real (char **device, char **path) { @@ -303,6 +320,7 @@ grub_pc_net_config_real (char **device, char **path) grub_net_configure_by_dhcp_ack ("pxe", &grub_pxe_card, 0, bp, GRUB_PXE_BOOTP_SIZE, 1, device, path); + } GRUB_MOD_INIT(pxe) @@ -347,10 +365,20 @@ GRUB_MOD_INIT(pxe) grub_net_card_register (&grub_pxe_card); grub_pc_net_config = grub_pc_net_config_real; + fini_hnd = grub_loader_register_preboot_hook (grub_pxe_fini_hw, + grub_pxe_restore_hw, + GRUB_LOADER_PREBOOT_HOOK_PRIO_DISK); } GRUB_MOD_FINI(pxe) { + struct grub_net_card *card, *next; + grub_pc_net_config = 0; - grub_pxe_unload (); + grub_pxe_fini_hw (0); + grub_net_card_unregister (&grub_pxe_card); + FOR_NET_CARDS_SAFE (card, next) + if (card->driver && grub_strcmp (card->driver->name, "pxe") == 0) + grub_net_card_unregister (card); + grub_loader_unregister_preboot_hook (fini_hnd); } diff --git a/grub-core/net/net.c b/grub-core/net/net.c index 595379a99..96bbd1712 100644 --- a/grub-core/net/net.c +++ b/grub-core/net/net.c @@ -52,7 +52,6 @@ struct grub_net_route struct grub_net_route *grub_net_routes = NULL; struct grub_net_network_level_interface *grub_net_network_level_interfaces = NULL; struct grub_net_card *grub_net_cards = NULL; -struct grub_net_card_driver *grub_net_card_drivers = NULL; struct grub_net_network_level_protocol *grub_net_network_level_protocols = NULL; static struct grub_fs grub_net_fs; @@ -1321,16 +1320,6 @@ grub_cmd_bootp (struct grub_command *cmd __attribute__ ((unused)), return err; } -static void -grub_grubnet_fini_real (void) -{ - struct grub_net_card *card; - - FOR_NET_CARDS (card) - if (card->driver) - card->driver->fini (card); -} - static struct grub_fs grub_net_fs = { .name = "netfs", @@ -1378,7 +1367,6 @@ GRUB_MOD_INIT(net) grub_fs_register (&grub_net_fs); grub_net_open = grub_net_open_real; - grub_grubnet_fini = grub_grubnet_fini_real; } GRUB_MOD_FINI(net) @@ -1393,5 +1381,4 @@ GRUB_MOD_FINI(net) grub_unregister_command (cmd_getdhcp); grub_fs_unregister (&grub_net_fs); grub_net_open = NULL; - grub_grubnet_fini = NULL; } diff --git a/include/grub/net.h b/include/grub/net.h index 0656787a6..e9a3793db 100644 --- a/include/grub/net.h +++ b/include/grub/net.h @@ -60,32 +60,12 @@ struct grub_net_card_driver { struct grub_net_card_driver *next; char *name; - grub_err_t (*init) (struct grub_net_card *dev); - grub_err_t (*fini) (struct grub_net_card *dev); grub_err_t (*send) (const struct grub_net_card *dev, struct grub_net_buff *buf); grub_ssize_t (*recv) (const struct grub_net_card *dev, struct grub_net_buff *buf); }; -extern struct grub_net_card_driver *grub_net_card_drivers; - -static inline void -grub_net_card_driver_register (struct grub_net_card_driver *driver) -{ - grub_list_push (GRUB_AS_LIST_P (&grub_net_card_drivers), - GRUB_AS_LIST (driver)); -} - -static inline void -grub_net_card_driver_unregister (struct grub_net_card_driver *driver) -{ - grub_list_remove (GRUB_AS_LIST_P (&grub_net_card_drivers), - GRUB_AS_LIST (driver)); -} - -#define FOR_NET_CARD_DRIVERS(var) for (var = grub_net_card_drivers; var; var = var->next) - typedef struct grub_net_packet { struct grub_net_packet *next; @@ -250,7 +230,6 @@ typedef struct grub_net } *grub_net_t; extern grub_net_t (*EXPORT_VAR (grub_net_open)) (const char *name); -extern void (*EXPORT_VAR (grub_grubnet_fini)) (void); struct grub_net_network_level_interface { @@ -350,6 +329,8 @@ grub_net_card_unregister (struct grub_net_card *card) } #define FOR_NET_CARDS(var) for (var = grub_net_cards; var; var = var->next) +#define FOR_NET_CARDS_SAFE(var, next) for (var = grub_net_cards, next = var->next; var; var = next, next = var->next) + struct grub_net_session * grub_net_open_tcp (char *address, grub_uint16_t port); From 275f8264e42781db403a26871462a6a25e53bb50 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Tue, 5 Jul 2011 14:55:28 +0200 Subject: [PATCH 723/869] Prevent garbage from getting into aout header --- util/grub-mkimage.c | 1 + 1 file changed, 1 insertion(+) diff --git a/util/grub-mkimage.c b/util/grub-mkimage.c index 9fc37df2b..042bcf2df 100644 --- a/util/grub-mkimage.c +++ b/util/grub-mkimage.c @@ -1278,6 +1278,7 @@ generate_image (const char *dir, char *prefix, FILE *out, char *mods[], aout_size = core_size + sizeof (*aout_head); aout_img = xmalloc (aout_size); aout_head = aout_img; + grub_memset (aout_head, 0, sizeof (*aout_head)); aout_head->a_midmag = grub_host_to_target32 ((AOUT_MID_SUN << 16) | AOUT32_OMAGIC); aout_head->a_text = grub_host_to_target32 (core_size); From 382077365b92c5727f748dcd87f90ea30dd320ad Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Tue, 5 Jul 2011 15:10:47 +0200 Subject: [PATCH 724/869] Fix mod_gap definition --- include/grub/offsets.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/grub/offsets.h b/include/grub/offsets.h index c04961fc6..e8170fcbe 100644 --- a/include/grub/offsets.h +++ b/include/grub/offsets.h @@ -169,7 +169,7 @@ /* Non-zero value is only needed for PowerMacs. */ #define GRUB_KERNEL_I386_IEEE1275_MOD_GAP 0x0 #define GRUB_KERNEL_I386_COREBOOT_MOD_GAP 0x0 -#define GRUB_KERNEL_POWERPC_IEEE1275_MOD_GAP 0x0 +#define GRUB_KERNEL_SPARC64_IEEE1275_MOD_GAP 0x0 #define GRUB_KERNEL_POWERPC_IEEE1275_MOD_ALIGN 0x1000 #define GRUB_KERNEL_SPARC64_IEEE1275_MOD_ALIGN 0x1 @@ -181,7 +181,7 @@ /* Minimal gap between _end and the start of the modules. It's a hack for PowerMac to prevent "CLAIM failed" error. The real fix is to rewrite grub-mkimage to generate valid ELF files. */ -#define GRUB_KERNEL_SPARC64_IEEE1275_MOD_GAP 0x8000 +#define GRUB_KERNEL_POWERPC_IEEE1275_MOD_GAP 0x8000 #ifdef GRUB_MACHINE #define GRUB_OFFSETS_CONCAT_(a,b,c) a ## b ## c From 0bc2cd0f82b274ab67fea73da9c5ead92b63a05f Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Tue, 5 Jul 2011 16:37:14 +0200 Subject: [PATCH 725/869] Reintroduce open/close of net cards. Clean up ofnet. --- grub-core/Makefile.am | 3 - grub-core/kern/ieee1275/init.c | 44 +++--- grub-core/kern/ieee1275/openfw.c | 111 ++++++++------ grub-core/net/drivers/efi/efinet.c | 2 +- grub-core/net/drivers/i386/pc/pxe.c | 54 ++----- grub-core/net/drivers/ieee1275/ofnet.c | 203 +++++++++++++------------ grub-core/net/ethernet.c | 10 +- grub-core/net/net.c | 71 ++++++++- include/grub/i386/pc/pxe.h | 2 - include/grub/ieee1275/ieee1275.h | 10 +- include/grub/ieee1275/ofnet.h | 66 -------- include/grub/net.h | 22 +-- 12 files changed, 313 insertions(+), 285 deletions(-) delete mode 100644 include/grub/ieee1275/ofnet.h diff --git a/grub-core/Makefile.am b/grub-core/Makefile.am index c3ecba9cf..2edf85a50 100644 --- a/grub-core/Makefile.am +++ b/grub-core/Makefile.am @@ -115,7 +115,6 @@ endif if COND_i386_ieee1275 KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/ieee1275/ieee1275.h -KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/ieee1275/ofnet.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/terminfo.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/extcmd.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/lib/arg.h @@ -175,7 +174,6 @@ endif if COND_powerpc_ieee1275 KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/ieee1275/ieee1275.h -KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/ieee1275/ofnet.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/terminfo.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/extcmd.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/lib/arg.h @@ -183,7 +181,6 @@ endif if COND_sparc64_ieee1275 KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/ieee1275/ieee1275.h -KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/ieee1275/ofnet.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/sparc64/ieee1275/ieee1275.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/terminfo.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/extcmd.h diff --git a/grub-core/kern/ieee1275/init.c b/grub-core/kern/ieee1275/init.c index 3c6332553..81b06c88e 100644 --- a/grub-core/kern/ieee1275/init.c +++ b/grub-core/kern/ieee1275/init.c @@ -31,7 +31,6 @@ #include #include #include -#include #include #include #include @@ -77,25 +76,16 @@ grub_translate_ieee1275_path (char *filepath) } } +void (*grub_ieee1275_net_config) (const char *dev, + char **device, + char **path); void grub_machine_get_bootlocation (char **device, char **path) { char bootpath[64]; /* XXX check length */ char *filename; - grub_bootp_t bootp_pckt; - - /* Set the net prefix when possible. */ - if (grub_getbootp && (bootp_pckt = grub_getbootp())) - { - grub_uint32_t n = bootp_pckt->siaddr; - char addr[GRUB_NET_MAX_STR_ADDR_LEN]; - grub_snprintf (addr, GRUB_NET_MAX_STR_ADDR_LEN, "%d.%d.%d.%d", - ((n >> 24) & 0xff), ((n >> 16) & 0xff), - ((n >> 8) & 0xff), ((n >> 0) & 0xff)); - *device = grub_xasprintf ("(tftp,%s)", addr); - return; - } - + char *type; + if (grub_ieee1275_get_property (grub_ieee1275_chosen, "bootpath", &bootpath, sizeof (bootpath), 0)) { @@ -106,7 +96,27 @@ grub_machine_get_bootlocation (char **device, char **path) /* Transform an OF device path to a GRUB path. */ - *device = grub_ieee1275_encode_devname (bootpath); + type = grub_ieee1275_get_device_type (bootpath); + if (type && grub_strcmp (type, "network") == 0) + { + char *dev, *canon; + char *ptr; + dev = grub_ieee1275_get_aliasdevname (bootpath); + canon = grub_ieee1275_canonicalise_devname (dev); + ptr = canon + grub_strlen (canon) - 1; + while (ptr > canon && (*ptr == ',' || *ptr == ':')) + ptr--; + ptr++; + *ptr = 0; + + if (grub_ieee1275_net_config) + grub_ieee1275_net_config (canon, device, path); + grub_free (dev); + grub_free (canon); + } + else + *device = grub_ieee1275_encode_devname (bootpath); + grub_free (type); filename = grub_ieee1275_get_filename (bootpath); if (filename) @@ -264,8 +274,6 @@ grub_machine_init (void) void grub_machine_fini (void) { - if (grub_grubnet_fini) - grub_grubnet_fini (); grub_ofdisk_fini (); grub_console_fini (); } diff --git a/grub-core/kern/ieee1275/openfw.c b/grub-core/kern/ieee1275/openfw.c index 8fc373c55..2cecd8c7f 100644 --- a/grub-core/kern/ieee1275/openfw.c +++ b/grub-core/kern/ieee1275/openfw.c @@ -22,16 +22,15 @@ #include #include #include -#include #include #include -grub_bootp_t (*grub_getbootp) (void); enum grub_ieee1275_parse_type { GRUB_PARSE_FILENAME, GRUB_PARSE_PARTITION, - GRUB_PARSE_DEVICE + GRUB_PARSE_DEVICE, + GRUB_PARSE_DEVICE_TYPE }; /* Walk children of 'devpath', calling hook for each. */ @@ -322,14 +321,9 @@ grub_ieee1275_parse_args (const char *path, enum grub_ieee1275_parse_type ptype) { char type[64]; /* XXX check size. */ char *device = grub_ieee1275_get_devname (path); - char *args = grub_ieee1275_get_devargs (path); char *ret = 0; grub_ieee1275_phandle_t dev; - if (!args) - /* Shouldn't happen. */ - return 0; - /* We need to know what type of device it is in order to parse the full file path properly. */ if (grub_ieee1275_finddevice (device, &dev)) @@ -344,55 +338,86 @@ grub_ieee1275_parse_args (const char *path, enum grub_ieee1275_parse_type ptype) goto fail; } - if (!grub_strcmp ("block", type)) + switch (ptype) { - /* The syntax of the device arguments is defined in the CHRP and PReP - IEEE1275 bindings: "[partition][,[filename]]". */ - char *comma = grub_strchr (args, ','); + case GRUB_PARSE_DEVICE: + ret = grub_strdup (device); + break; + case GRUB_PARSE_DEVICE_TYPE: + ret = grub_strdup (type); + break; + case GRUB_PARSE_FILENAME: + { + char *comma; + char *args; - if (ptype == GRUB_PARSE_FILENAME) - { - if (comma) - { - char *filepath = comma + 1; + if (grub_strcmp ("block", type) != 0) + goto unknown; - /* Make sure filepath has leading backslash. */ - if (filepath[0] != '\\') - ret = grub_xasprintf ("\\%s", filepath); - else - ret = grub_strdup (filepath); + args = grub_ieee1275_get_devargs (path); + if (!args) + /* Shouldn't happen. */ + return 0; + + /* The syntax of the device arguments is defined in the CHRP and PReP + IEEE1275 bindings: "[partition][,[filename]]". */ + comma = grub_strchr (args, ','); + + if (comma) + { + char *filepath = comma + 1; + + /* Make sure filepath has leading backslash. */ + if (filepath[0] != '\\') + ret = grub_xasprintf ("\\%s", filepath); + else + ret = grub_strdup (filepath); } + grub_free (args); } - else if (ptype == GRUB_PARSE_PARTITION) - { - if (!comma) - ret = grub_strdup (args); - else - ret = grub_strndup (args, (grub_size_t)(comma - args)); - /* Consistently provide numbered partitions to GRUB. - OpenBOOT traditionally uses alphabetical partition - specifiers. */ - if (ret[0] >= 'a' && ret[0] <= 'z') - ret[0] = '1' + (ret[0] - 'a'); - } - } + break; + case GRUB_PARSE_PARTITION: + { + char *comma; + char *args; - else if (!grub_strcmp ("network", type)) - { - if (ptype == GRUB_PARSE_DEVICE) - ret = grub_strdup(device); - } - else - { + if (grub_strcmp ("block", type) != 0) + goto unknown; + + args = grub_ieee1275_get_devargs (path); + if (!args) + /* Shouldn't happen. */ + return 0; + + comma = grub_strchr (args, ','); + if (!comma) + ret = grub_strdup (args); + else + ret = grub_strndup (args, (grub_size_t)(comma - args)); + /* Consistently provide numbered partitions to GRUB. + OpenBOOT traditionally uses alphabetical partition + specifiers. */ + if (ret[0] >= 'a' && ret[0] <= 'z') + ret[0] = '1' + (ret[0] - 'a'); + grub_free (args); + } + break; + default: + unknown: grub_printf ("Unsupported type %s for device %s\n", type, device); } fail: grub_free (device); - grub_free (args); return ret; } +char * +grub_ieee1275_get_device_type (const char *path) +{ + return grub_ieee1275_parse_args (path, GRUB_PARSE_DEVICE_TYPE); +} + char * grub_ieee1275_get_aliasdevname (const char *path) { diff --git a/grub-core/net/drivers/efi/efinet.c b/grub-core/net/drivers/efi/efinet.c index 4b2ffc038..5c6aac608 100644 --- a/grub-core/net/drivers/efi/efinet.c +++ b/grub-core/net/drivers/efi/efinet.c @@ -195,7 +195,7 @@ GRUB_MOD_FINI(efinet) struct grub_net_card *card, *next; FOR_NET_CARDS_SAFE (card, next) - if (card->driver && grub_strcmp (card->driver->name, "efinet") == 0) + if (card->driver == &efidriver) grub_net_card_unregister (card); } diff --git a/grub-core/net/drivers/i386/pc/pxe.c b/grub-core/net/drivers/i386/pc/pxe.c index 81607eb57..aa10cbbfa 100644 --- a/grub-core/net/drivers/i386/pc/pxe.c +++ b/grub-core/net/drivers/i386/pc/pxe.c @@ -23,7 +23,6 @@ #include #include #include -#include #include #include @@ -261,20 +260,8 @@ grub_pxe_send (const struct grub_net_card *dev __attribute__ ((unused)), return 0; } -struct grub_net_card_driver grub_pxe_card_driver = -{ - .send = grub_pxe_send, - .recv = grub_pxe_recv -}; - -struct grub_net_card grub_pxe_card = -{ - .driver = &grub_pxe_card_driver, - .name = "pxe" -}; - static grub_err_t -grub_pxe_fini_hw (int noreturn __attribute__ ((unused))) +grub_pxe_close (const struct grub_net_card *dev __attribute__ ((unused))) { if (pxe_rm_entry) grub_pxe_call (GRUB_PXENV_UNDI_CLOSE, @@ -285,7 +272,7 @@ grub_pxe_fini_hw (int noreturn __attribute__ ((unused))) } static grub_err_t -grub_pxe_restore_hw (void) +grub_pxe_open (const struct grub_net_card *dev __attribute__ ((unused))) { struct grub_pxe_undi_open *ou; ou = (void *) GRUB_MEMORY_MACHINE_SCRATCH_ADDR; @@ -294,14 +281,23 @@ grub_pxe_restore_hw (void) grub_pxe_call (GRUB_PXENV_UNDI_OPEN, ou, pxe_rm_entry); if (ou->status) - { - grub_net_card_unregister (&grub_pxe_card); - return grub_error (GRUB_ERR_IO, "can't open UNDI"); - } + return grub_error (GRUB_ERR_IO, "can't open UNDI"); return GRUB_ERR_NONE; } -static void *fini_hnd; +struct grub_net_card_driver grub_pxe_card_driver = +{ + .open = grub_pxe_open, + .close = grub_pxe_close, + .send = grub_pxe_send, + .recv = grub_pxe_recv +}; + +struct grub_net_card grub_pxe_card = +{ + .driver = &grub_pxe_card_driver, + .name = "pxe" +}; static void grub_pc_net_config_real (char **device, char **path) @@ -355,30 +351,12 @@ GRUB_MOD_INIT(pxe) grub_pxe_card.default_address.type = GRUB_NET_LINK_LEVEL_PROTOCOL_ETHERNET; - ou = (void *) GRUB_MEMORY_MACHINE_SCRATCH_ADDR; - grub_memset (ou, 0, sizeof (*ou)); - ou->pkt_filter = 4; - grub_pxe_call (GRUB_PXENV_UNDI_OPEN, ou, pxe_rm_entry); - - if (ou->status) - return; - grub_net_card_register (&grub_pxe_card); grub_pc_net_config = grub_pc_net_config_real; - fini_hnd = grub_loader_register_preboot_hook (grub_pxe_fini_hw, - grub_pxe_restore_hw, - GRUB_LOADER_PREBOOT_HOOK_PRIO_DISK); } GRUB_MOD_FINI(pxe) { - struct grub_net_card *card, *next; - grub_pc_net_config = 0; - grub_pxe_fini_hw (0); grub_net_card_unregister (&grub_pxe_card); - FOR_NET_CARDS_SAFE (card, next) - if (card->driver && grub_strcmp (card->driver->name, "pxe") == 0) - grub_net_card_unregister (card); - grub_loader_unregister_preboot_hook (fini_hnd); } diff --git a/grub-core/net/drivers/ieee1275/ofnet.c b/grub-core/net/drivers/ieee1275/ofnet.c index e5a6bfcad..cc29d0987 100644 --- a/grub-core/net/drivers/ieee1275/ofnet.c +++ b/grub-core/net/drivers/ieee1275/ofnet.c @@ -17,7 +17,6 @@ */ #include -#include #include #include #include @@ -25,8 +24,15 @@ GRUB_MOD_LICENSE ("GPLv3+"); +struct grub_ofnetcard_data +{ + char *path; + grub_ieee1275_ihandle_t handle; + grub_uint32_t mtu; +}; + static grub_err_t -card_open (struct grub_net_card *dev) +card_open (const struct grub_net_card *dev) { int status; struct grub_ofnetcard_data *data = dev->data; @@ -44,14 +50,13 @@ card_open (struct grub_net_card *dev) return GRUB_ERR_NONE; } -static grub_err_t -card_close (struct grub_net_card *dev) +static void +card_close (const struct grub_net_card *dev) { struct grub_ofnetcard_data *data = dev->data; if (data->handle) grub_ieee1275_close (data->handle); - return GRUB_ERR_NONE; } static grub_err_t @@ -93,8 +98,8 @@ get_card_packet (const struct grub_net_card *dev, struct grub_net_buff *nb) static struct grub_net_card_driver ofdriver = { .name = "ofnet", - .init = card_open, - .fini = card_close, + .open = card_open, + .close = card_close, .send = send_card_buffer, .recv = get_card_packet }; @@ -112,39 +117,87 @@ bootp_response_properties[] = { .name = "bootpreply-packet", .offset = 0x2a}, }; -static grub_bootp_t -grub_getbootp_real (void) +static void +grub_ieee1275_net_config_real (const char *devpath, char **device, char **path) { - grub_bootp_t packet = grub_malloc (sizeof *packet); - char *bootp_response; - grub_ssize_t size; - unsigned int i; + struct grub_net_card *card; - for (i = 0; i < ARRAY_SIZE (bootp_response_properties); i++) - if (grub_ieee1275_get_property_length (grub_ieee1275_chosen, - bootp_response_properties[i].name, - &size) >= 0) - break; + /* FIXME: Check that it's the right card. */ + FOR_NET_CARDS (card) + { + char *bootp_response; + char *cardpath; + char *canon; - if (size < 0) - return NULL; + grub_ssize_t size = -1; + unsigned int i; - bootp_response = grub_malloc (size); - if (grub_ieee1275_get_property (grub_ieee1275_chosen, - bootp_response_properties[i].name, - bootp_response, size, 0) < 0) - return NULL; + if (card->driver != &ofdriver) + continue; - grub_memcpy (packet, bootp_response + bootp_response_properties[i].offset, sizeof (*packet)); - grub_free (bootp_response); - return packet; + cardpath = ((struct grub_ofnetcard_data *) card->data)->path; + canon = grub_ieee1275_canonicalise_devname (cardpath); + if (grub_strcmp (devpath, canon) != 0) + { + grub_free (canon); + continue; + } + grub_free (canon); + + for (i = 0; i < ARRAY_SIZE (bootp_response_properties); i++) + if (grub_ieee1275_get_property_length (grub_ieee1275_chosen, + bootp_response_properties[i].name, + &size) >= 0) + break; + + if (size < 0) + return; + + bootp_response = grub_malloc (size); + if (!bootp_response) + { + grub_print_error (); + return; + } + if (grub_ieee1275_get_property (grub_ieee1275_chosen, + bootp_response_properties[i].name, + bootp_response, size, 0) < 0) + return; + + grub_net_configure_by_dhcp_ack (card->name, card, 0, + (struct grub_net_bootp_packet *) + &bootp_response + + bootp_response_properties[i].offset, + size - bootp_response_properties[i].offset, + 1, device, path); + return; + } +} + +static char * +find_alias (const char *fullname) +{ + char *ret = NULL; + auto int find_alias_hook (struct grub_ieee1275_devalias *alias); + + int find_alias_hook (struct grub_ieee1275_devalias *alias) + { + if (grub_strcmp (alias->path, fullname) == 0) + { + ret = grub_strdup (alias->name); + return 1; + } + return 0; + } + + grub_devalias_iterate (find_alias_hook); + grub_errno = GRUB_ERR_NONE; + return ret; } static void grub_ofnet_findcards (void) { - int i = 0; - auto int search_net_devices (struct grub_ieee1275_devalias *alias); int search_net_devices (struct grub_ieee1275_devalias *alias) @@ -155,6 +208,7 @@ grub_ofnet_findcards (void) struct grub_net_card *card; grub_ieee1275_phandle_t devhandle; grub_net_link_level_address_t lla; + char *shortname; ofdata = grub_malloc (sizeof (struct grub_ofnetcard_data)); if (!ofdata) @@ -162,7 +216,7 @@ grub_ofnet_findcards (void) grub_print_error (); return 1; } - card = grub_malloc (sizeof (struct grub_net_card)); + card = grub_zalloc (sizeof (struct grub_net_card)); if (!card) { grub_free (ofdata); @@ -177,11 +231,19 @@ grub_ofnet_findcards (void) if (grub_ieee1275_get_integer_property (devhandle, "max-frame-size", &(ofdata->mtu), sizeof (ofdata->mtu), 0)) - return grub_error (GRUB_ERR_IO, "Couldn't retrieve mtu size."); + { + ofdata->mtu = 1500; + } - if (grub_ieee1275_get_property - (devhandle, "mac-address", &(lla.mac), 6, 0)) - return grub_error (GRUB_ERR_IO, "Couldn't retrieve mac address."); + if (grub_ieee1275_get_property (devhandle, "mac-address", + &(lla.mac), 6, 0) + && grub_ieee1275_get_property (devhandle, "local-mac-address", + &(lla.mac), 6, 0)) + { + grub_error (GRUB_ERR_IO, "Couldn't retrieve mac address."); + grub_print_error (); + return 0; + } lla.type = GRUB_NET_LINK_LEVEL_PROTOCOL_ETHERNET; card->default_address = lla; @@ -189,7 +251,11 @@ grub_ofnet_findcards (void) card->driver = NULL; card->data = ofdata; card->flags = 0; - card->name = grub_xasprintf ("eth%d", i++); + shortname = find_alias (alias->path); + card->name = grub_xasprintf ("ofnet_%s", shortname ? : alias->path); + grub_free (shortname); + + card->driver = &ofdriver; grub_net_card_register (card); return 0; } @@ -200,69 +266,18 @@ grub_ofnet_findcards (void) grub_ieee1275_devices_iterate (search_net_devices); } -static void -grub_ofnet_probecards (void) -{ - struct grub_net_card *card; - struct grub_net_card_driver *driver; - struct grub_net_network_level_interface *inter; - grub_bootp_t bootp_pckt; - grub_net_network_level_address_t addr; - grub_net_network_level_netaddress_t net; - bootp_pckt = grub_getbootp (); - - /* Assign correspondent driver for each device. */ - FOR_NET_CARDS (card) - { - FOR_NET_CARD_DRIVERS (driver) - { - if (driver->init (card) == GRUB_ERR_NONE) - { - card->driver = driver; - if (bootp_pckt - && grub_memcmp (bootp_pckt->chaddr, card->default_address.mac, 6) == 0) - { - addr.type = GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4; - addr.ipv4 = bootp_pckt->yiaddr; - grub_net_add_addr ("bootp_cli_addr", card, addr, - card->default_address, 0); - FOR_NET_NETWORK_LEVEL_INTERFACES (inter) - if (grub_strcmp (inter->name, "bootp_cli_addr") == 0) - break; - net.type = addr.type; - net.ipv4.base = addr.ipv4; - net.ipv4.masksize = 24; - grub_net_add_route ("bootp-router", net, inter); - } - break; - } - } - } - grub_free (bootp_pckt); - -} - GRUB_MOD_INIT(ofnet) { - struct grub_net_card *card; - grub_getbootp = grub_getbootp_real; - grub_net_card_driver_register (&ofdriver); grub_ofnet_findcards (); - grub_ofnet_probecards (); - FOR_NET_CARDS (card) - if (card->driver == NULL) - grub_net_card_unregister (card); + grub_ieee1275_net_config = grub_ieee1275_net_config_real; } GRUB_MOD_FINI(ofnet) { - struct grub_net_card *card; - FOR_NET_CARDS (card) - if (card->driver && !grub_strcmp (card->driver->name, "ofnet")) - { - card->driver->fini (card); - card->driver = NULL; - } - grub_net_card_driver_unregister (&ofdriver); - grub_getbootp = NULL; + struct grub_net_card *card, *next; + + FOR_NET_CARDS_SAFE (card, next) + if (card->driver && grub_strcmp (card->driver->name, "ofnet") == 0) + grub_net_card_unregister (card); + grub_ieee1275_net_config = 0; } diff --git a/grub-core/net/ethernet.c b/grub-core/net/ethernet.c index 175d0b65f..3006c9d93 100644 --- a/grub-core/net/ethernet.c +++ b/grub-core/net/ethernet.c @@ -25,7 +25,15 @@ send_ethernet_packet (struct grub_net_network_level_interface *inf, grub_memcpy (eth->src, inf->hwaddress.mac, 6); eth->type = grub_cpu_to_be16 (ethertype); - + if (!inf->card->opened) + { + err = GRUB_ERR_NONE; + if (inf->card->driver->open) + err = inf->card->driver->open (inf->card); + if (err) + return err; + inf->card->opened = 1; + } return inf->card->driver->send (inf->card, nb); } diff --git a/grub-core/net/net.c b/grub-core/net/net.c index 96bbd1712..a3b76cae0 100644 --- a/grub-core/net/net.c +++ b/grub-core/net/net.c @@ -30,6 +30,7 @@ #include #include #include +#include GRUB_MOD_LICENSE ("GPLv3+"); @@ -58,6 +59,7 @@ static struct grub_fs grub_net_fs; static inline void grub_net_network_level_interface_unregister (struct grub_net_network_level_interface *inter) { + inter->card->num_ifaces--; *inter->prev = inter->next; if (inter->next) inter->next->prev = inter->prev; @@ -65,6 +67,24 @@ grub_net_network_level_interface_unregister (struct grub_net_network_level_inter inter->prev = 0; } +void +grub_net_card_unregister (struct grub_net_card *card) +{ + struct grub_net_network_level_interface *inf, *next; + FOR_NET_NETWORK_LEVEL_INTERFACES_SAFE(inf, next) + if (inf->card == card) + grub_net_network_level_interface_unregister (inf); + if (card->opened) + { + if (card->driver->close) + card->driver->close (card); + card->opened = 0; + } + grub_list_remove (GRUB_AS_LIST_P (&grub_net_cards), + GRUB_AS_LIST (card)); +} + + static inline void grub_net_route_register (struct grub_net_route *route) { @@ -336,6 +356,7 @@ grub_net_network_level_interface_register (struct grub_net_network_level_interfa grub_register_variable_hook (name, 0, addr_set_env); } + inter->card->num_ifaces++; inter->prev = &grub_net_network_level_interfaces; inter->next = grub_net_network_level_interfaces; if (inter->next) @@ -345,7 +366,7 @@ grub_net_network_level_interface_register (struct grub_net_network_level_interfa struct grub_net_network_level_interface * grub_net_add_addr (const char *name, - const struct grub_net_card *card, + struct grub_net_card *card, grub_net_network_level_address_t addr, grub_net_link_level_address_t hwaddress, grub_net_interface_flags_t flags) @@ -714,6 +735,20 @@ grub_net_fs_close (grub_file_t file) static void receive_packets (struct grub_net_card *card) { + if (card->num_ifaces == 0) + return; + if (!card->opened) + { + grub_err_t err = GRUB_ERR_NONE; + if (card->driver->open) + err = card->driver->open (card); + if (err) + { + grub_errno = GRUB_ERR_NONE; + return; + } + card->opened = 1; + } while (1) { /* Maybe should be better have a fixed number of packets for each card @@ -926,7 +961,7 @@ parse_dhcp_vendor (const char *name, void *vend, int limit) struct grub_net_network_level_interface * grub_net_configure_by_dhcp_ack (const char *name, - const struct grub_net_card *card, + struct grub_net_card *card, grub_net_interface_flags_t flags, const struct grub_net_bootp_packet *bp, grub_size_t size, @@ -1042,7 +1077,7 @@ grub_net_configure_by_dhcp_ack (const char *name, void grub_net_process_dhcp (struct grub_net_buff *nb, - const struct grub_net_card *card) + struct grub_net_card *card) { char *name; struct grub_net_network_level_interface *inf; @@ -1228,6 +1263,7 @@ grub_cmd_bootp (struct grub_command *cmd __attribute__ ((unused)), if (j) ifaces[j].prev = &ifaces[j-1].next; ifaces[j].name = grub_xasprintf ("%s:dhcp_tmp", card->name); + card->num_ifaces++; if (!ifaces[j].name) { unsigned i; @@ -1331,6 +1367,29 @@ static struct grub_fs grub_net_fs = .uuid = NULL, .mtime = NULL, }; + +static grub_err_t +grub_net_fini_hw (int noreturn __attribute__ ((unused))) +{ + struct grub_net_card *card; + FOR_NET_CARDS (card) + if (card->opened) + { + if (card->driver->close) + card->driver->close (card); + card->opened = 0; + } + return GRUB_ERR_NONE; +} + +static grub_err_t +grub_net_restore_hw (void) +{ + return GRUB_ERR_NONE; +} + +static void *fini_hnd; + static grub_command_t cmd_addaddr, cmd_deladdr, cmd_addroute, cmd_delroute; static grub_command_t cmd_lsroutes, cmd_lscards, cmd_getdhcp, cmd_bootp; static grub_command_t cmd_dhcp, cmd_lsaddr; @@ -1367,6 +1426,11 @@ GRUB_MOD_INIT(net) grub_fs_register (&grub_net_fs); grub_net_open = grub_net_open_real; + fini_hnd = grub_loader_register_preboot_hook (grub_net_fini_hw, + grub_net_restore_hw, + GRUB_LOADER_PREBOOT_HOOK_PRIO_DISK); + grub_net_fini_hw (0); + grub_loader_unregister_preboot_hook (fini_hnd); } GRUB_MOD_FINI(net) @@ -1381,4 +1445,5 @@ GRUB_MOD_FINI(net) grub_unregister_command (cmd_getdhcp); grub_fs_unregister (&grub_net_fs); grub_net_open = NULL; + grub_loader_unregister_preboot_hook (fini_hnd); } diff --git a/include/grub/i386/pc/pxe.h b/include/grub/i386/pc/pxe.h index 781b53df5..376a18962 100644 --- a/include/grub/i386/pc/pxe.h +++ b/include/grub/i386/pc/pxe.h @@ -287,8 +287,6 @@ int EXPORT_FUNC(grub_pxe_call) (int func, void * data, grub_uint32_t pxe_rm_entr extern struct grub_pxe_bangpxe *grub_pxe_pxenv; -void grub_pxe_unload (void); - #endif #endif /* GRUB_CPU_PXE_H */ diff --git a/include/grub/ieee1275/ieee1275.h b/include/grub/ieee1275/ieee1275.h index 87294610d..81590ee4b 100644 --- a/include/grub/ieee1275/ieee1275.h +++ b/include/grub/ieee1275/ieee1275.h @@ -64,12 +64,9 @@ struct grub_ieee1275_common_hdr typedef grub_uint32_t grub_ieee1275_ihandle_t; typedef grub_uint32_t grub_ieee1275_phandle_t; -struct grub_ofnetcard_data -{ - char *path; - grub_ieee1275_ihandle_t handle; - grub_uint32_t mtu; -}; +extern void (*EXPORT_VAR(grub_ieee1275_net_config)) (const char *dev, + char **device, + char **path); /* Maps a device alias to a pathname. */ extern grub_ieee1275_phandle_t EXPORT_VAR(grub_ieee1275_chosen); @@ -203,5 +200,6 @@ int EXPORT_FUNC(grub_ieee1275_devices_iterate) (int (*hook) alias)); char *EXPORT_FUNC(grub_ieee1275_get_aliasdevname) (const char *path); char *EXPORT_FUNC(grub_ieee1275_canonicalise_devname) (const char *path); +char *EXPORT_FUNC(grub_ieee1275_get_device_type) (const char *path); #endif /* ! GRUB_IEEE1275_HEADER */ diff --git a/include/grub/ieee1275/ofnet.h b/include/grub/ieee1275/ofnet.h deleted file mode 100644 index c7284df38..000000000 --- a/include/grub/ieee1275/ofnet.h +++ /dev/null @@ -1,66 +0,0 @@ -/* - * GRUB -- GRand Unified Bootloader - * Copyright (C) 2002,2007 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 . - */ - -#ifndef GRUB_OFNET_HEADER -#define GRUB_OFNET_HEADER 1 - -#include -#include -#include - -struct grub_ofnet -{ - /* The net name. */ - const char *name; - - /* The OF device string. */ - char *dev; - /*server ip*/ - char *sip; - /*client ip*/ - char *cip; - /*gateway*/ - char *gat; - /**/ - int type; -}; - -typedef struct grub_ofnet *grub_ofnet_t; - -struct grub_bootp { - grub_uint8_t op; /* 1 = BOOTREQUEST, 2 = BOOTREPLY */ - grub_uint8_t htype; /* Hardware address type. */ - grub_uint8_t hlen; /* Hardware address length */ - grub_uint8_t hops; /* Used by gateways in cross-gateway booting. */ - grub_uint32_t xid; /* Transaction ID */ - grub_uint16_t secs; /* Seconds elapsed. */ - grub_uint16_t unused; /* Unused. */ - grub_uint32_t ciaddr; /* Client IP address, */ - grub_uint32_t yiaddr; /* Client IP address filled by server. */ - grub_uint32_t siaddr; /* Server IP address. */ - grub_uint32_t giaddr; /* Gateway IP address. */ - unsigned char chaddr [16]; /* Client hardware address */ - char sname [64]; /* Server name */ - char file [128]; /* Boot filename */ - unsigned char vend [64]; -}; - -typedef struct grub_bootp* grub_bootp_t; - -extern grub_bootp_t (*EXPORT_VAR (grub_getbootp)) (void); -#endif /* ! GRUB_NET_HEADER */ diff --git a/include/grub/net.h b/include/grub/net.h index e9a3793db..85fdef365 100644 --- a/include/grub/net.h +++ b/include/grub/net.h @@ -60,6 +60,8 @@ struct grub_net_card_driver { struct grub_net_card_driver *next; char *name; + grub_err_t (*open) (const struct grub_net_card *dev); + void (*close) (const struct grub_net_card *dev); grub_err_t (*send) (const struct grub_net_card *dev, struct grub_net_buff *buf); grub_ssize_t (*recv) (const struct grub_net_card *dev, @@ -87,6 +89,8 @@ struct grub_net_card struct grub_net_card_driver *driver; grub_net_link_level_address_t default_address; grub_net_card_flags_t flags; + int num_ifaces; + int opened; union { struct @@ -236,7 +240,7 @@ struct grub_net_network_level_interface struct grub_net_network_level_interface *next; struct grub_net_network_level_interface **prev; char *name; - const struct grub_net_card *card; + struct grub_net_card *card; grub_net_network_level_address_t address; grub_net_link_level_address_t hwaddress; grub_net_interface_flags_t flags; @@ -284,7 +288,7 @@ grub_net_session_recv (struct grub_net_session *session, void *buf, struct grub_net_network_level_interface * grub_net_add_addr (const char *name, - const struct grub_net_card *card, + struct grub_net_card *card, grub_net_network_level_address_t addr, grub_net_link_level_address_t hwaddress, grub_net_interface_flags_t flags); @@ -321,12 +325,8 @@ grub_net_card_register (struct grub_net_card *card) GRUB_AS_LIST (card)); } -static inline void -grub_net_card_unregister (struct grub_net_card *card) -{ - grub_list_remove (GRUB_AS_LIST_P (&grub_net_cards), - GRUB_AS_LIST (card)); -} +void +grub_net_card_unregister (struct grub_net_card *card); #define FOR_NET_CARDS(var) for (var = grub_net_cards; var; var = var->next) #define FOR_NET_CARDS_SAFE(var, next) for (var = grub_net_cards, next = var->next; var; var = next, next = var->next) @@ -390,7 +390,7 @@ struct grub_net_bootp_packet struct grub_net_network_level_interface * grub_net_configure_by_dhcp_ack (const char *name, - const struct grub_net_card *card, + struct grub_net_card *card, grub_net_interface_flags_t flags, const struct grub_net_bootp_packet *bp, grub_size_t size, @@ -398,7 +398,7 @@ grub_net_configure_by_dhcp_ack (const char *name, void grub_net_process_dhcp (struct grub_net_buff *nb, - const struct grub_net_card *card); + struct grub_net_card *card); int grub_net_hwaddr_cmp (const grub_net_link_level_address_t *a, @@ -418,6 +418,8 @@ grub_net_addr_to_str (const grub_net_network_level_address_t *target, extern struct grub_net_network_level_interface *grub_net_network_level_interfaces; #define FOR_NET_NETWORK_LEVEL_INTERFACES(var) for (var = grub_net_network_level_interfaces; var; var = var->next) +#define FOR_NET_NETWORK_LEVEL_INTERFACES_SAFE(var,next) for (var = grub_net_network_level_interfaces, next = var->next; var; var = next, next = var->next) + grub_err_t grub_net_send_link_layer (struct grub_net_network_level_interface *inf, struct grub_net_buff *nb, grub_net_link_level_address_t *target); From a07a81b33550ed050cbd70b18f8eb0d9177559fc Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Tue, 5 Jul 2011 20:24:20 +0200 Subject: [PATCH 726/869] CMOS support on sparc. * gentpl.py (cmos): Add powerpc and sparc. * grub-core/Makefile.core.def (datetime): Add lib/ieee1275/cmos.c on powerpc and sparc. * grub-core/lib/cmos_datetime.c (grub_get_datetime) [__powerpc__ || __sparc__]: Rename to grub_get_datetime_cmos. (grub_set_datetime) [__powerpc__ || __sparc__]: Likewise to grub_set_datetime_cmos. * grub-core/lib/ieee1275/cmos.c: New file. * grub-core/lib/ieee1275/datetime.c (no_ieee1275_rtc): New vaiable. (find_rtc): Set no_ieee1275_rtc on error. (grub_get_datetime): Call grub_get_datetime_cmos on error. (grub_set_datetime): Call grub_set_datetime_cmos on error. * include/grub/cmos.h (grub_cmos_read): Return grub_err_t since it may fail. Move value to argument. All users updated (grub_cmos_write): Likewise. (grub_cmos_read) [__powerpc__ || __sparc__]: Rewritten. (grub_cmos_write) [__powerpc__ || __sparc__]: Likewise. * include/grub/datetime.h [__powerpc__ || __sparc__]: Declare grub_get_datetime_cmos and grub_set_datetime_cmos. --- ChangeLog | 24 ++++++++++ gentpl.py | 4 +- grub-core/Makefile.core.def | 3 ++ grub-core/commands/i386/cmostest.c | 14 ++++-- grub-core/lib/cmos_datetime.c | 68 ++++++++++++++++++++------- grub-core/lib/ieee1275/cmos.c | 75 ++++++++++++++++++++++++++++++ grub-core/lib/ieee1275/datetime.c | 14 +++++- include/grub/cmos.h | 48 +++++++++++++++++-- include/grub/datetime.h | 7 +++ 9 files changed, 231 insertions(+), 26 deletions(-) create mode 100644 grub-core/lib/ieee1275/cmos.c diff --git a/ChangeLog b/ChangeLog index e091265d4..694a97972 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,27 @@ +2011-07-05 Vladimir Serbinenko + + CMOS support on sparc. + + * gentpl.py (cmos): Add powerpc and sparc. + * grub-core/Makefile.core.def (datetime): Add lib/ieee1275/cmos.c on + powerpc and sparc. + * grub-core/lib/cmos_datetime.c (grub_get_datetime) + [__powerpc__ || __sparc__]: Rename to grub_get_datetime_cmos. + (grub_set_datetime) [__powerpc__ || __sparc__]: Likewise to + grub_set_datetime_cmos. + * grub-core/lib/ieee1275/cmos.c: New file. + * grub-core/lib/ieee1275/datetime.c (no_ieee1275_rtc): New vaiable. + (find_rtc): Set no_ieee1275_rtc on error. + (grub_get_datetime): Call grub_get_datetime_cmos on error. + (grub_set_datetime): Call grub_set_datetime_cmos on error. + * include/grub/cmos.h (grub_cmos_read): Return grub_err_t since it may + fail. Move value to argument. All users updated + (grub_cmos_write): Likewise. + (grub_cmos_read) [__powerpc__ || __sparc__]: Rewritten. + (grub_cmos_write) [__powerpc__ || __sparc__]: Likewise. + * include/grub/datetime.h [__powerpc__ || __sparc__]: Declare + grub_get_datetime_cmos and grub_set_datetime_cmos. + 2011-07-02 GrĂ©goire Sutre * util/grub-mkconfig.in: Use @PACKAGE@ instead of hardcoded name when diff --git a/gentpl.py b/gentpl.py index 6e2df076b..31cde1e81 100644 --- a/gentpl.py +++ b/gentpl.py @@ -30,7 +30,9 @@ GROUPS["ieee1275"] = [ "i386_ieee1275", "sparc64_ieee1275", "powerpc_ieee1275" GROUPS["noemu"] = GRUB_PLATFORMS[:]; GROUPS["noemu"].remove("emu") # Groups based on hardware features -GROUPS["cmos"] = GROUPS["x86"][:] + ["mips_loongson", "mips_qemu_mips"]; GROUPS["cmos"].remove("i386_efi"); GROUPS["cmos"].remove("x86_64_efi") +GROUPS["cmos"] = GROUPS["x86"][:] + ["mips_loongson", "mips_qemu_mips", + "sparc64_ieee1275", "powerpc_ieee1275"] +GROUPS["cmos"].remove("i386_efi"); GROUPS["cmos"].remove("x86_64_efi") GROUPS["pci"] = GROUPS["x86"] + ["mips_loongson"] GROUPS["usb"] = GROUPS["pci"] diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def index fd69e9c22..16c940c61 100644 --- a/grub-core/Makefile.core.def +++ b/grub-core/Makefile.core.def @@ -1192,6 +1192,9 @@ module = { efi = lib/efi/datetime.c; sparc64_ieee1275 = lib/ieee1275/datetime.c; powerpc_ieee1275 = lib/ieee1275/datetime.c; + sparc64_ieee1275 = lib/ieee1275/cmos.c; + powerpc_ieee1275 = lib/ieee1275/cmos.c; + mips_arc = lib/arc/datetime.c; enable = noemu; }; diff --git a/grub-core/commands/i386/cmostest.c b/grub-core/commands/i386/cmostest.c index c79bd0387..6439159bd 100644 --- a/grub-core/commands/i386/cmostest.c +++ b/grub-core/commands/i386/cmostest.c @@ -46,12 +46,17 @@ grub_cmd_cmostest (struct grub_command *cmd __attribute__ ((unused)), { int byte, bit; grub_err_t err; + grub_uint8_t value; err = parse_args (argc, argv, &byte, &bit); if (err) return err; - if (grub_cmos_read (byte) & (1 << bit)) + err = grub_cmos_read (byte, &value); + if (err) + return err; + + if (value & (1 << bit)) return GRUB_ERR_NONE; return grub_error (GRUB_ERR_TEST_FAILURE, "false"); @@ -63,13 +68,16 @@ grub_cmd_cmosclean (struct grub_command *cmd __attribute__ ((unused)), { int byte, bit; grub_err_t err; + grub_uint8_t value; err = parse_args (argc, argv, &byte, &bit); + if (err) + return err; + err = grub_cmos_read (byte, &value); if (err) return err; - grub_cmos_write (byte, grub_cmos_read (byte) & (~(1 << bit))); - return GRUB_ERR_NONE; + return grub_cmos_write (byte, value & (~(1 << bit))); } static grub_command_t cmd, cmd_clean; diff --git a/grub-core/lib/cmos_datetime.c b/grub-core/lib/cmos_datetime.c index 73c5a03c0..86cd91180 100644 --- a/grub-core/lib/cmos_datetime.c +++ b/grub-core/lib/cmos_datetime.c @@ -23,30 +23,44 @@ GRUB_MOD_LICENSE ("GPLv3+"); +#if !defined (__powerpc__) && !defined (__sparc__) +#define grub_get_datetime_cmos grub_get_datetime +#define grub_set_datetime_cmos grub_set_datetime +#endif + grub_err_t -grub_get_datetime (struct grub_datetime *datetime) +grub_get_datetime_cmos (struct grub_datetime *datetime) { int is_bcd, is_12hour; grub_uint8_t value, flag; + grub_err_t err; - flag = grub_cmos_read (GRUB_CMOS_INDEX_STATUS_B); + err = grub_cmos_read (GRUB_CMOS_INDEX_STATUS_B, &flag); + if (err) + return err; is_bcd = ! (flag & GRUB_CMOS_STATUS_B_BINARY); - value = grub_cmos_read (GRUB_CMOS_INDEX_YEAR); + err = grub_cmos_read (GRUB_CMOS_INDEX_YEAR, &value); + if (err) + return err; if (is_bcd) value = grub_bcd_to_num (value); datetime->year = value; datetime->year += (value < 80) ? 2000 : 1900; - value = grub_cmos_read (GRUB_CMOS_INDEX_MONTH); + err = grub_cmos_read (GRUB_CMOS_INDEX_MONTH, &value); + if (err) + return err; if (is_bcd) value = grub_bcd_to_num (value); datetime->month = value; - value = grub_cmos_read (GRUB_CMOS_INDEX_DAY_OF_MONTH); + err = grub_cmos_read (GRUB_CMOS_INDEX_DAY_OF_MONTH, &value); + if (err) + return err; if (is_bcd) value = grub_bcd_to_num (value); @@ -54,7 +68,9 @@ grub_get_datetime (struct grub_datetime *datetime) is_12hour = ! (flag & GRUB_CMOS_STATUS_B_24HOUR); - value = grub_cmos_read (GRUB_CMOS_INDEX_HOUR); + err = grub_cmos_read (GRUB_CMOS_INDEX_HOUR, &value); + if (err) + return err; if (is_12hour) { is_12hour = (value & 0x80); @@ -71,13 +87,18 @@ grub_get_datetime (struct grub_datetime *datetime) datetime->hour = value; - value = grub_cmos_read (GRUB_CMOS_INDEX_MINUTE); + err = grub_cmos_read (GRUB_CMOS_INDEX_MINUTE, &value); + if (err) + return err; + if (is_bcd) value = grub_bcd_to_num (value); datetime->minute = value; - value = grub_cmos_read (GRUB_CMOS_INDEX_SECOND); + err = grub_cmos_read (GRUB_CMOS_INDEX_SECOND, &value); + if (err) + return err; if (is_bcd) value = grub_bcd_to_num (value); @@ -87,12 +108,15 @@ grub_get_datetime (struct grub_datetime *datetime) } grub_err_t -grub_set_datetime (struct grub_datetime *datetime) +grub_set_datetime_cmos (struct grub_datetime *datetime) { int is_bcd, is_12hour; grub_uint8_t value, flag; + grub_err_t err; - flag = grub_cmos_read (GRUB_CMOS_INDEX_STATUS_B); + err = grub_cmos_read (GRUB_CMOS_INDEX_STATUS_B, &flag); + if (err) + return err; is_bcd = ! (flag & GRUB_CMOS_STATUS_B_BINARY); @@ -102,21 +126,27 @@ grub_set_datetime (struct grub_datetime *datetime) if (is_bcd) value = grub_num_to_bcd (value); - grub_cmos_write (GRUB_CMOS_INDEX_YEAR, value); + err = grub_cmos_write (GRUB_CMOS_INDEX_YEAR, value); + if (err) + return err; value = datetime->month; if (is_bcd) value = grub_num_to_bcd (value); - grub_cmos_write (GRUB_CMOS_INDEX_MONTH, value); + err = grub_cmos_write (GRUB_CMOS_INDEX_MONTH, value); + if (err) + return err; value = datetime->day; if (is_bcd) value = grub_num_to_bcd (value); - grub_cmos_write (GRUB_CMOS_INDEX_DAY_OF_MONTH, value); + err = grub_cmos_write (GRUB_CMOS_INDEX_DAY_OF_MONTH, value); + if (err) + return err; value = datetime->hour; @@ -138,21 +168,27 @@ grub_set_datetime (struct grub_datetime *datetime) if (is_12hour) value |= 0x80; - grub_cmos_write (GRUB_CMOS_INDEX_HOUR, value); + err = grub_cmos_write (GRUB_CMOS_INDEX_HOUR, value); + if (err) + return err; value = datetime->minute; if (is_bcd) value = grub_num_to_bcd (value); - grub_cmos_write (GRUB_CMOS_INDEX_MINUTE, value); + err = grub_cmos_write (GRUB_CMOS_INDEX_MINUTE, value); + if (err) + return err; value = datetime->second; if (is_bcd) value = grub_num_to_bcd (value); - grub_cmos_write (GRUB_CMOS_INDEX_SECOND, value); + err = grub_cmos_write (GRUB_CMOS_INDEX_SECOND, value); + if (err) + return err; return 0; } diff --git a/grub-core/lib/ieee1275/cmos.c b/grub-core/lib/ieee1275/cmos.c new file mode 100644 index 000000000..fa57db9e7 --- /dev/null +++ b/grub-core/lib/ieee1275/cmos.c @@ -0,0 +1,75 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2011 Free Software Foundation, Inc. + * + * GRUB is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see . + */ + +#include +#include +#include +#include +#include + +volatile grub_uint8_t *grub_cmos_port = 0; +grub_err_t +grub_cmos_find_port (void) +{ + auto int hook (struct grub_ieee1275_devalias *alias); + int hook (struct grub_ieee1275_devalias *alias) + { + grub_ieee1275_phandle_t dev; + grub_uint32_t addr[2]; + grub_ssize_t actual; + /* Enough to check if it's "m5819" */ + char compat[100]; + if (grub_ieee1275_finddevice (alias->path, &dev)) + return 0; + if (grub_ieee1275_get_property (dev, "compatible", compat, sizeof (compat), + 0)) + return 0; + if (grub_strcmp (compat, "m5819") != 0) + return 0; + if (grub_ieee1275_get_integer_property (dev, "address", + addr, sizeof (addr), &actual)) + return 0; + if (actual == 4) + { + grub_cmos_port = (volatile grub_uint8_t *) (grub_addr_t) addr[0]; + return 1; + } + +#if GRUB_CPU_SIZEOF_VOID_P == 8 + if (actual == 8) + { + grub_cmos_port = (volatile grub_uint8_t *) + ((((grub_addr_t) addr[0]) << 32) | addr[1]); + return 1; + } +#else + if (actual == 8 && addr[0] == 0) + { + grub_cmos_port = (volatile grub_uint8_t *) addr[1]; + return 1; + } +#endif + return 0; + } + + grub_ieee1275_devices_iterate (hook); + if (!grub_cmos_port) + return grub_error (GRUB_ERR_IO, "no cmos found"); + + return GRUB_ERR_NONE; +} diff --git a/grub-core/lib/ieee1275/datetime.c b/grub-core/lib/ieee1275/datetime.c index 4105c639b..1947135fe 100644 --- a/grub-core/lib/ieee1275/datetime.c +++ b/grub-core/lib/ieee1275/datetime.c @@ -21,10 +21,14 @@ #include #include #include +#if defined (__powerpc__) || defined (__sparc__) +#include +#endif GRUB_MOD_LICENSE ("GPLv3+"); static char *rtc = 0; +static int no_ieee1275_rtc = 0; static void find_rtc (void) @@ -42,6 +46,8 @@ find_rtc (void) } grub_ieee1275_devices_iterate (hook); + if (!rtc) + no_ieee1275_rtc = 1; } grub_err_t @@ -64,10 +70,12 @@ grub_get_datetime (struct grub_datetime *datetime) int status; grub_ieee1275_ihandle_t ihandle; + if (no_ieee1275_rtc) + return grub_get_datetime_cmos (datetime); if (!rtc) find_rtc (); if (!rtc) - return grub_error (GRUB_ERR_IO, "no RTC found"); + return grub_get_datetime_cmos (datetime); status = grub_ieee1275_open (rtc, &ihandle); if (status == -1) @@ -114,10 +122,12 @@ grub_set_datetime (struct grub_datetime *datetime) int status; grub_ieee1275_ihandle_t ihandle; + if (no_ieee1275_rtc) + return grub_set_datetime_cmos (datetime); if (!rtc) find_rtc (); if (!rtc) - return grub_error (GRUB_ERR_IO, "no RTC found"); + return grub_set_datetime_cmos (datetime); status = grub_ieee1275_open (rtc, &ihandle); if (status == -1) diff --git a/include/grub/cmos.h b/include/grub/cmos.h index f508e3bf6..331513cd7 100644 --- a/include/grub/cmos.h +++ b/include/grub/cmos.h @@ -20,8 +20,10 @@ #define GRUB_CMOS_H 1 #include +#if !defined (__powerpc__) && !defined (__sparc__) #include #include +#endif #define GRUB_CMOS_INDEX_SECOND 0 #define GRUB_CMOS_INDEX_SECOND_ALARM 1 @@ -55,18 +57,56 @@ grub_num_to_bcd (grub_uint8_t a) return (((a / 10) << 4) + (a % 10)); } -static inline grub_uint8_t -grub_cmos_read (grub_uint8_t index) +#if !defined (__powerpc__) && !defined (__sparc__) +static inline grub_err_t +grub_cmos_read (grub_uint8_t index, grub_uint8_t *val) { grub_outb (index, GRUB_CMOS_ADDR_REG); - return grub_inb (GRUB_CMOS_DATA_REG); + *val = grub_inb (GRUB_CMOS_DATA_REG); + return GRUB_ERR_NONE; } -static inline void +static inline grub_err_t grub_cmos_write (grub_uint8_t index, grub_uint8_t value) { grub_outb (index, GRUB_CMOS_ADDR_REG); grub_outb (value, GRUB_CMOS_DATA_REG); + return GRUB_ERR_NONE; +} +#else +grub_err_t grub_cmos_find_port (void); +extern volatile grub_uint8_t *grub_cmos_port; + +static inline grub_err_t +grub_cmos_read (grub_uint8_t index, grub_uint8_t *val) +{ + if (!grub_cmos_port) + { + grub_err_t err; + err = grub_cmos_find_port (); + if (err) + return err; + } + grub_cmos_port[0] = index; + *val = grub_cmos_port[1]; + return GRUB_ERR_NONE; } +static inline grub_err_t +grub_cmos_write (grub_uint8_t index, grub_uint8_t val) +{ + if (!grub_cmos_port) + { + grub_err_t err; + err = grub_cmos_find_port (); + if (err) + return err; + } + grub_cmos_port[0] = index; + grub_cmos_port[1] = val; + return GRUB_ERR_NONE; +} + +#endif + #endif /* GRUB_CMOS_H */ diff --git a/include/grub/datetime.h b/include/grub/datetime.h index c20fc8c36..dea0f8ea9 100644 --- a/include/grub/datetime.h +++ b/include/grub/datetime.h @@ -125,4 +125,11 @@ grub_datetime2unixtime (const struct grub_datetime *datetime, grub_int32_t *nix) return 1; } +#if defined (__powerpc__) || defined (__sparc__) +grub_err_t +grub_get_datetime_cmos (struct grub_datetime *datetime); +grub_err_t +grub_set_datetime_cmos (struct grub_datetime *datetime); +#endif + #endif /* ! KERNEL_DATETIME_HEADER */ From d73459943924af0345797052934ab61417a5f84d Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Tue, 5 Jul 2011 21:00:01 +0200 Subject: [PATCH 727/869] MIPS qemu at_keyboard support. * gentpl.py (videoinkernel): Add qemu-mips. * grub-core/Makefile.am (KERNEL_HEADER_FILES): Add necessary headers. * grub-core/Makefile.core.def (kernel): Add at_keyboard and layout. * grub-core/kern/mips/qemu_mips/init.c (grub_machine_init): Init new modules. * grub-core/term/at_keyboard.c (grub_keyboard_controller_init) [GRUB_MACHINE_MIPS_QEMU_MIPS]: Don't consider original set. * grub-core/term/serial.c (grub_serial_register) [GRUB_MACHINE_MIPS_QEMU_MIPS]: Make com0 explicitly active. --- ChangeLog | 14 +++++++++++++ gentpl.py | 2 +- grub-core/Makefile.am | 13 ++++++++++++ grub-core/Makefile.core.def | 2 ++ grub-core/kern/mips/qemu_mips/init.c | 20 ++++++++++++++++++ grub-core/term/at_keyboard.c | 4 ++-- grub-core/term/serial.c | 11 ++++++++++ include/grub/mips/qemu_mips/at_keyboard.h | 25 +++++++++++++++++++++++ 8 files changed, 88 insertions(+), 3 deletions(-) create mode 100644 include/grub/mips/qemu_mips/at_keyboard.h diff --git a/ChangeLog b/ChangeLog index 694a97972..644a7cf6a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +2011-07-05 Vladimir Serbinenko + + MIPS qemu at_keyboard support. + + * gentpl.py (videoinkernel): Add qemu-mips. + * grub-core/Makefile.am (KERNEL_HEADER_FILES): Add necessary headers. + * grub-core/Makefile.core.def (kernel): Add at_keyboard and layout. + * grub-core/kern/mips/qemu_mips/init.c (grub_machine_init): Init new + modules. + * grub-core/term/at_keyboard.c (grub_keyboard_controller_init) + [GRUB_MACHINE_MIPS_QEMU_MIPS]: Don't consider original set. + * grub-core/term/serial.c (grub_serial_register) + [GRUB_MACHINE_MIPS_QEMU_MIPS]: Make com0 explicitly active. + 2011-07-05 Vladimir Serbinenko CMOS support on sparc. diff --git a/gentpl.py b/gentpl.py index 31cde1e81..e431293eb 100644 --- a/gentpl.py +++ b/gentpl.py @@ -37,7 +37,7 @@ GROUPS["pci"] = GROUPS["x86"] + ["mips_loongson"] GROUPS["usb"] = GROUPS["pci"] # If gfxterm is main output console integrate it into kernel -GROUPS["videoinkernel"] = ["mips_loongson"] +GROUPS["videoinkernel"] = ["mips_loongson", "mips_qemu_mips"] GROUPS["videomodules"] = GRUB_PLATFORMS[:]; for i in GROUPS["videoinkernel"]: GROUPS["videomodules"].remove(i) diff --git a/grub-core/Makefile.am b/grub-core/Makefile.am index c3ecba9cf..28a143413 100644 --- a/grub-core/Makefile.am +++ b/grub-core/Makefile.am @@ -145,7 +145,20 @@ KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/arc/arc.h endif if COND_mips_qemu_mips +KERNEL_HEADER_FILES += $(top_builddir)/include/grub/keyboard_layouts.h +KERNEL_HEADER_FILES += $(top_builddir)/include/grub/machine/kernel.h +KERNEL_HEADER_FILES += $(top_builddir)/include/grub/cpu/cache.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/bitmap.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/video.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/gfxterm.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/font.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/bitmap_scale.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/bufio.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/serial.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/loader.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/terminfo.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/extcmd.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/lib/arg.h endif if COND_mips_loongson diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def index 16c940c61..328f7186f 100644 --- a/grub-core/Makefile.core.def +++ b/grub-core/Makefile.core.def @@ -162,6 +162,8 @@ kernel = { mips_qemu_mips = kern/mips/qemu_mips/init.c; mips_qemu_mips = term/ns8250.c; mips_qemu_mips = term/serial.c; + mips_qemu_mips = term/at_keyboard.c; + mips_qemu_mips = commands/keylayouts.c; mips_arc = kern/mips/arc/init.c; mips_arc = term/arc/console.c; diff --git a/grub-core/kern/mips/qemu_mips/init.c b/grub-core/kern/mips/qemu_mips/init.c index 2180b347a..2016aeb3d 100644 --- a/grub-core/kern/mips/qemu_mips/init.c +++ b/grub-core/kern/mips/qemu_mips/init.c @@ -12,6 +12,16 @@ extern void grub_serial_init (void); extern void grub_terminfo_init (void); +extern void grub_at_keyboard_init (void); +extern void grub_video_init (void); +extern void grub_bitmap_init (void); +extern void grub_font_init (void); +extern void grub_gfxterm_init (void); +extern void grub_at_keyboard_init (void); +extern void grub_serial_init (void); +extern void grub_terminfo_init (void); +extern void grub_keylayouts_init (void); +extern void grub_boot_init (void); void grub_machine_init (void) @@ -27,8 +37,18 @@ grub_machine_init (void) grub_install_get_time_ms (grub_rtc_get_time_ms); + grub_video_init (); + grub_bitmap_init (); + grub_font_init (); + grub_gfxterm_init (); + + grub_keylayouts_init (); + grub_at_keyboard_init (); + grub_terminfo_init (); grub_serial_init (); + + grub_boot_init (); } void diff --git a/grub-core/term/at_keyboard.c b/grub-core/term/at_keyboard.c index e86df6f35..b81e76230 100644 --- a/grub-core/term/at_keyboard.c +++ b/grub-core/term/at_keyboard.c @@ -259,7 +259,7 @@ grub_keyboard_controller_write (grub_uint8_t c) grub_outb (c, KEYBOARD_REG_DATA); } -#if !defined (GRUB_MACHINE_MIPS_LOONGSON) && !defined (GRUB_MACHINE_QEMU) +#if !defined (GRUB_MACHINE_MIPS_LOONGSON) && !defined (GRUB_MACHINE_QEMU) && !defined (GRUB_MACHINE_MIPS_QEMU_MIPS) static grub_uint8_t grub_keyboard_controller_read (void) @@ -569,7 +569,7 @@ grub_keyboard_controller_init (struct grub_term_input *term __attribute__ ((unus keyboard_controller_wait_until_ready (); grub_inb (KEYBOARD_REG_DATA); } -#if defined (GRUB_MACHINE_MIPS_LOONGSON) || defined (GRUB_MACHINE_QEMU) +#if defined (GRUB_MACHINE_MIPS_LOONGSON) || defined (GRUB_MACHINE_QEMU) || defined (GRUB_MACHINE_MIPS_QEMU_MIPS) grub_keyboard_controller_orig = 0; grub_keyboard_orig_set = 2; #else diff --git a/grub-core/term/serial.c b/grub-core/term/serial.c index add112f4a..0381349a4 100644 --- a/grub-core/term/serial.c +++ b/grub-core/term/serial.c @@ -313,6 +313,17 @@ grub_serial_register (struct grub_serial_port *port) grub_term_register_input_inactive ("serial_*", in); grub_term_register_output_inactive ("serial_*", out); } +#elif defined (GRUB_MACHINE_MIPS_QEMU_MIPS) + if (grub_strcmp (port->name, "com0") == 0) + { + grub_term_register_input_active ("serial_*", in); + grub_term_register_output_active ("serial_*", out); + } + else + { + grub_term_register_input_inactive ("serial_*", in); + grub_term_register_output_inactive ("serial_*", out); + } #else grub_term_register_input ("serial_*", in); grub_term_register_output ("serial_*", out); diff --git a/include/grub/mips/qemu_mips/at_keyboard.h b/include/grub/mips/qemu_mips/at_keyboard.h new file mode 100644 index 000000000..37cc625d1 --- /dev/null +++ b/include/grub/mips/qemu_mips/at_keyboard.h @@ -0,0 +1,25 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2007,2008,2009 Free Software Foundation, Inc. + * + * GRUB is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see . + */ + +#ifndef GRUB_MACHINE_AT_KEYBOARD_HEADER +#define GRUB_MACHINE_AT_KEYBOARD_HEADER 1 + +#define KEYBOARD_REG_DATA 0xb4000060 +#define KEYBOARD_REG_STATUS 0xb4000064 + +#endif From 748ccabea1fe40d6240f1abaa5e0612920b366ea Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Tue, 5 Jul 2011 21:42:36 +0200 Subject: [PATCH 728/869] MIPS qemu flash support. * grub-core/boot/mips/startup_raw.S [GRUB_MACHINE_MIPS_QEMU_MIPS]: Check magic. * grub-core/kern/mips/qemu_mips/init.c (probe_mem): New function. (grub_machine_init): Probe memory if its size isn't known. * util/grub-mkimage.c (image_targets): Add flash targets. (generate_image): Handle flash targets. --- ChangeLog | 11 +++++ grub-core/boot/mips/startup_raw.S | 16 ++++++- grub-core/kern/mips/qemu_mips/init.c | 28 ++++++++++- util/grub-mkimage.c | 69 +++++++++++++++++++++++++++- 4 files changed, 121 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 644a7cf6a..3772dc028 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2011-07-05 Vladimir Serbinenko + + MIPS qemu flash support. + + * grub-core/boot/mips/startup_raw.S [GRUB_MACHINE_MIPS_QEMU_MIPS]: Check + magic. + * grub-core/kern/mips/qemu_mips/init.c (probe_mem): New function. + (grub_machine_init): Probe memory if its size isn't known. + * util/grub-mkimage.c (image_targets): Add flash targets. + (generate_image): Handle flash targets. + 2011-07-05 Vladimir Serbinenko MIPS qemu at_keyboard support. diff --git a/grub-core/boot/mips/startup_raw.S b/grub-core/boot/mips/startup_raw.S index e6dfadaf9..4ecff5efd 100644 --- a/grub-core/boot/mips/startup_raw.S +++ b/grub-core/boot/mips/startup_raw.S @@ -54,8 +54,22 @@ codestart: /* Parse arguments. Has to be done before relocation. So need to do it in asm. */ #ifdef GRUB_MACHINE_MIPS_QEMU_MIPS + lui $t0, %hi (((16 << 20) - 264 + 4) | 0x80000000) + lw $t1, %lo (((16 << 20) - 264 + 4) | 0x80000000) ($t0) + + lui $t2, 0x1234 + ori $t2, 0x5678 + + bne $t1, $t2, 1f + nop + lui $t0, %hi (((16 << 20) - 264) | 0x80000000) - lw $s4, %lo (((16 << 20) - 264) | 0x80000000) ($t0) + b 2f + lw $s4, %lo (((16 << 20) - 264) | 0x80000000) ($t0) + +1: + li $s4, 0 +2: #endif #ifdef GRUB_MACHINE_MIPS_LOONGSON diff --git a/grub-core/kern/mips/qemu_mips/init.c b/grub-core/kern/mips/qemu_mips/init.c index 2016aeb3d..0c3113fe2 100644 --- a/grub-core/kern/mips/qemu_mips/init.c +++ b/grub-core/kern/mips/qemu_mips/init.c @@ -23,11 +23,36 @@ extern void grub_terminfo_init (void); extern void grub_keylayouts_init (void); extern void grub_boot_init (void); +static inline int +probe_mem (grub_addr_t addr) +{ + volatile grub_uint8_t *ptr = (grub_uint8_t *) (0xa0000000 | addr); + grub_uint8_t c = *ptr; + *ptr = 0xAA; + if (*ptr != 0xAA) + return 0; + *ptr = 0x55; + if (*ptr != 0x55) + return 0; + *ptr = c; + return 1; +} + void grub_machine_init (void) { grub_addr_t modend; + if (grub_arch_memsize == 0) + { + int i; + + for (i = 27; i >= 0; i--) + if (probe_mem (grub_arch_memsize | (1 << i))) + grub_arch_memsize |= (1 << i); + grub_arch_memsize++; + } + /* FIXME: measure this. */ grub_arch_cpuclock = 64000000; @@ -40,7 +65,6 @@ grub_machine_init (void) grub_video_init (); grub_bitmap_init (); grub_font_init (); - grub_gfxterm_init (); grub_keylayouts_init (); grub_at_keyboard_init (); @@ -49,6 +73,8 @@ grub_machine_init (void) grub_serial_init (); grub_boot_init (); + + grub_gfxterm_init (); } void diff --git a/util/grub-mkimage.c b/util/grub-mkimage.c index 9fc37df2b..002696d07 100644 --- a/util/grub-mkimage.c +++ b/util/grub-mkimage.c @@ -67,7 +67,8 @@ struct image_target_desc IMAGE_I386_PC, IMAGE_EFI, IMAGE_COREBOOT, IMAGE_SPARC64_AOUT, IMAGE_SPARC64_RAW, IMAGE_I386_IEEE1275, IMAGE_LOONGSON_ELF, IMAGE_QEMU, IMAGE_PPC, IMAGE_YEELOONG_FLASH, - IMAGE_FULOONG_FLASH, IMAGE_I386_PC_PXE, IMAGE_MIPS_ARC + IMAGE_FULOONG_FLASH, IMAGE_I386_PC_PXE, IMAGE_MIPS_ARC, + IMAGE_QEMU_MIPS_FLASH } id; enum { @@ -466,6 +467,50 @@ struct image_target_desc image_targets[] = .link_align = GRUB_KERNEL_MIPS_QEMU_MIPS_LINK_ALIGN, .default_compression = COMPRESSION_NONE }, + { + .dirname = "mips-qemu_mips", + .names = { "mips-qemu_mips-flash", NULL }, + .voidp_sizeof = 4, + .bigendian = 1, + .id = IMAGE_QEMU_MIPS_FLASH, + .flags = PLATFORM_FLAGS_DECOMPRESSORS, + .prefix = GRUB_KERNEL_MIPS_QEMU_MIPS_PREFIX, + .prefix_end = GRUB_KERNEL_MIPS_QEMU_MIPS_PREFIX_END, + .raw_size = 0, + .total_module_size = GRUB_KERNEL_MIPS_QEMU_MIPS_TOTAL_MODULE_SIZE, + .compressed_size = TARGET_NO_FIELD, + .kernel_image_size = TARGET_NO_FIELD, + .section_align = 1, + .vaddr_offset = 0, + .install_dos_part = TARGET_NO_FIELD, + .install_bsd_part = TARGET_NO_FIELD, + .link_addr = GRUB_KERNEL_MIPS_QEMU_MIPS_LINK_ADDR, + .elf_target = EM_MIPS, + .link_align = GRUB_KERNEL_MIPS_QEMU_MIPS_LINK_ALIGN, + .default_compression = COMPRESSION_NONE + }, + { + .dirname = "mipsel-qemu_mips", + .names = { "mipsel-qemu_mips-flash", NULL }, + .voidp_sizeof = 4, + .bigendian = 0, + .id = IMAGE_QEMU_MIPS_FLASH, + .flags = PLATFORM_FLAGS_DECOMPRESSORS, + .prefix = GRUB_KERNEL_MIPS_QEMU_MIPS_PREFIX, + .prefix_end = GRUB_KERNEL_MIPS_QEMU_MIPS_PREFIX_END, + .raw_size = 0, + .total_module_size = GRUB_KERNEL_MIPS_QEMU_MIPS_TOTAL_MODULE_SIZE, + .compressed_size = TARGET_NO_FIELD, + .kernel_image_size = TARGET_NO_FIELD, + .section_align = 1, + .vaddr_offset = 0, + .install_dos_part = TARGET_NO_FIELD, + .install_bsd_part = TARGET_NO_FIELD, + .link_addr = GRUB_KERNEL_MIPS_QEMU_MIPS_LINK_ADDR, + .elf_target = EM_MIPS, + .link_align = GRUB_KERNEL_MIPS_QEMU_MIPS_LINK_ALIGN, + .default_compression = COMPRESSION_NONE + }, { .dirname = "mips-qemu_mips", .names = { "mips-qemu_mips-elf", NULL }, @@ -1389,6 +1434,28 @@ generate_image (const char *dir, char *prefix, FILE *out, char *mods[], core_size = rom_size; } break; + case IMAGE_QEMU_MIPS_FLASH: + { + char *rom_img; + size_t rom_size; + + if (core_size > 512 * 1024) + grub_util_error ("firmware image is too big"); + rom_size = 512 * 1024; + + rom_img = xmalloc (rom_size); + memset (rom_img, 0, rom_size); + + memcpy (rom_img, core_img, core_size); + + memset (rom_img + core_size, 0, + rom_size - core_size); + + free (core_img); + core_img = rom_img; + core_size = rom_size; + } + break; case IMAGE_MIPS_ARC: { char *ecoff_img; From 93c06ff9c6490af246ce3620c11d5cc638903e7f Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Tue, 5 Jul 2011 23:46:15 +0200 Subject: [PATCH 729/869] VGA text support in qemu-mips * grub-core/Makefile.core.def (kernel): Add term/i386/pc/vga_text.c, term/i386/vga_common.c and kern/vga_init.c on qemu-mips. * grub-core/kern/mips/qemu_mips/init.c (grub_machine_init): Init vga text. * grub-core/kern/i386/qemu/init.c: Renamed to ... * grub-core/kern/vga_init.c: ... this. * grub-core/kern/vga_init.c (VGA_ADDR) [__mips__]: Adjust. (grub_qemu_init_cirrus) [__mips__]: Skip PCI and adjust the I/O base. * grub-core/term/i386/pc/vga_text.c (VGA_TEXT_SCREEN) [__mips__]: Adjust. * include/grub/vga.h [GRUB_MACHINE_MIPS_QEMU_MIPS]: Declare GRUB_MACHINE_PCI_IO_BASE. --- ChangeLog | 17 ++++++++++++++ grub-core/Makefile.core.def | 5 +++- grub-core/kern/mips/qemu_mips/init.c | 5 ++++ .../kern/{i386/qemu/init.c => vga_init.c} | 23 +++++++++++++++---- grub-core/term/i386/pc/vga_text.c | 6 ++++- include/grub/mips/qemu_mips/kernel.h | 1 + include/grub/vga.h | 5 ++++ 7 files changed, 56 insertions(+), 6 deletions(-) rename grub-core/kern/{i386/qemu/init.c => vga_init.c} (90%) diff --git a/ChangeLog b/ChangeLog index 3772dc028..c2d386032 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,20 @@ +2011-07-05 Vladimir Serbinenko + + VGA text support in qemu-mips + + * grub-core/Makefile.core.def (kernel): Add term/i386/pc/vga_text.c, + term/i386/vga_common.c and kern/vga_init.c on qemu-mips. + * grub-core/kern/mips/qemu_mips/init.c (grub_machine_init): Init vga + text. + * grub-core/kern/i386/qemu/init.c: Renamed to ... + * grub-core/kern/vga_init.c: ... this. + * grub-core/kern/vga_init.c (VGA_ADDR) [__mips__]: Adjust. + (grub_qemu_init_cirrus) [__mips__]: Skip PCI and adjust the I/O base. + * grub-core/term/i386/pc/vga_text.c (VGA_TEXT_SCREEN) [__mips__]: + Adjust. + * include/grub/vga.h [GRUB_MACHINE_MIPS_QEMU_MIPS]: Declare + GRUB_MACHINE_PCI_IO_BASE. + 2011-07-05 Vladimir Serbinenko MIPS qemu flash support. diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def index 328f7186f..807f5b357 100644 --- a/grub-core/Makefile.core.def +++ b/grub-core/Makefile.core.def @@ -143,7 +143,7 @@ kernel = { i386_pc = term/i386/pc/console.c; i386_qemu = bus/pci.c; - i386_qemu = kern/i386/qemu/init.c; + i386_qemu = kern/vga_init.c; i386_qemu = kern/i386/qemu/mmap.c; i386_qemu = kern/i386/tsc.c; @@ -164,6 +164,9 @@ kernel = { mips_qemu_mips = term/serial.c; mips_qemu_mips = term/at_keyboard.c; mips_qemu_mips = commands/keylayouts.c; + mips_qemu_mips = term/i386/pc/vga_text.c; + mips_qemu_mips = term/i386/vga_common.c; + mips_qemu_mips = kern/vga_init.c; mips_arc = kern/mips/arc/init.c; mips_arc = term/arc/console.c; diff --git a/grub-core/kern/mips/qemu_mips/init.c b/grub-core/kern/mips/qemu_mips/init.c index 0c3113fe2..db9cc796a 100644 --- a/grub-core/kern/mips/qemu_mips/init.c +++ b/grub-core/kern/mips/qemu_mips/init.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include @@ -22,6 +23,7 @@ extern void grub_serial_init (void); extern void grub_terminfo_init (void); extern void grub_keylayouts_init (void); extern void grub_boot_init (void); +extern void grub_vga_text_init (void); static inline int probe_mem (grub_addr_t addr) @@ -69,6 +71,9 @@ grub_machine_init (void) grub_keylayouts_init (); grub_at_keyboard_init (); + grub_qemu_init_cirrus (); + grub_vga_text_init (); + grub_terminfo_init (); grub_serial_init (); diff --git a/grub-core/kern/i386/qemu/init.c b/grub-core/kern/vga_init.c similarity index 90% rename from grub-core/kern/i386/qemu/init.c rename to grub-core/kern/vga_init.c index 054dfa86b..889d0128e 100644 --- a/grub-core/kern/i386/qemu/init.c +++ b/grub-core/kern/vga_init.c @@ -1,6 +1,6 @@ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2010 Free Software Foundation, Inc. + * Copyright (C) 2010,2011 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -16,7 +16,9 @@ * along with GRUB. If not, see . */ +#ifndef __mips__ #include +#endif #include #include #include @@ -43,7 +45,17 @@ static struct {grub_uint8_t r, g, b, a; } colors[] = {0xFE, 0xFE, 0xFE, 0xFF} // 15 = white }; +#ifdef __mips__ +extern unsigned char ascii_bitmaps[]; +#else #include +#endif + +#ifdef __mips__ +#define VGA_ADDR 0xb00a0000 +#else +#define VGA_ADDR 0xa0000 +#endif static void load_font (void) @@ -61,7 +73,7 @@ load_font (void) grub_vga_gr_write (0xff, GRUB_VGA_GR_BITMASK); for (i = 0; i < 128; i++) - grub_memcpy ((void *) (0xa0000 + 32 * i), ascii_bitmaps + 16 * i, 16); + grub_memcpy ((void *) (VGA_ADDR + 32 * i), ascii_bitmaps + 16 * i, 16); } static void @@ -78,6 +90,7 @@ load_palette (void) void grub_qemu_init_cirrus (void) { +#ifndef __mips__ auto int NESTED_FUNC_ATTR find_card (grub_pci_device_t dev, grub_pci_id_t pciid); int NESTED_FUNC_ATTR find_card (grub_pci_device_t dev, grub_pci_id_t pciid __attribute__ ((unused))) { @@ -106,8 +119,10 @@ grub_qemu_init_cirrus (void) } grub_pci_iterate (find_card); +#endif - grub_outb (GRUB_VGA_IO_MISC_COLOR, GRUB_VGA_IO_MISC_WRITE); + grub_outb (GRUB_VGA_IO_MISC_COLOR, + GRUB_MACHINE_PCI_IO_BASE + GRUB_VGA_IO_MISC_WRITE); load_font (); @@ -143,5 +158,5 @@ grub_qemu_init_cirrus (void) grub_vga_cr_write (14, GRUB_VGA_CR_CURSOR_START); grub_vga_cr_write (15, GRUB_VGA_CR_CURSOR_END); - grub_outb (0x20, 0x3c0); + grub_outb (0x20, GRUB_MACHINE_PCI_IO_BASE + GRUB_VGA_IO_ARX); } diff --git a/grub-core/term/i386/pc/vga_text.c b/grub-core/term/i386/pc/vga_text.c index 1816bfae2..9abffcc0a 100644 --- a/grub-core/term/i386/pc/vga_text.c +++ b/grub-core/term/i386/pc/vga_text.c @@ -18,7 +18,7 @@ #include #include -#include +#include #include #include @@ -29,7 +29,11 @@ GRUB_MOD_LICENSE ("GPLv3+"); static int grub_curr_x, grub_curr_y; +#ifdef __mips__ +#define VGA_TEXT_SCREEN ((grub_uint16_t *) 0xb00b8000) +#else #define VGA_TEXT_SCREEN ((grub_uint16_t *) 0xb8000) +#endif static void screen_write_char (int x, int y, short c) diff --git a/include/grub/mips/qemu_mips/kernel.h b/include/grub/mips/qemu_mips/kernel.h index c08405e83..66add4b2e 100644 --- a/include/grub/mips/qemu_mips/kernel.h +++ b/include/grub/mips/qemu_mips/kernel.h @@ -25,6 +25,7 @@ void EXPORT_FUNC (grub_reboot) (void); void EXPORT_FUNC (grub_halt) (void); +void grub_qemu_init_cirrus (void); #endif diff --git a/include/grub/vga.h b/include/grub/vga.h index bf4439599..58ec3ba15 100644 --- a/include/grub/vga.h +++ b/include/grub/vga.h @@ -19,7 +19,12 @@ #ifndef GRUB_VGA_HEADER #define GRUB_VGA_HEADER 1 +#ifndef GRUB_MACHINE_MIPS_QEMU_MIPS #include +#else +#include +#define GRUB_MACHINE_PCI_IO_BASE 0xb4000000 +#endif enum { From 72b9ad936abf84dbcd4a55b31fe64d316d1bd62a Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 6 Jul 2011 02:49:04 +0200 Subject: [PATCH 730/869] fix declarations in pxe --- grub-core/net/drivers/i386/pc/pxe.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/grub-core/net/drivers/i386/pc/pxe.c b/grub-core/net/drivers/i386/pc/pxe.c index aa10cbbfa..cd598ea72 100644 --- a/grub-core/net/drivers/i386/pc/pxe.c +++ b/grub-core/net/drivers/i386/pc/pxe.c @@ -260,15 +260,13 @@ grub_pxe_send (const struct grub_net_card *dev __attribute__ ((unused)), return 0; } -static grub_err_t +static void grub_pxe_close (const struct grub_net_card *dev __attribute__ ((unused))) { if (pxe_rm_entry) grub_pxe_call (GRUB_PXENV_UNDI_CLOSE, (void *) GRUB_MEMORY_MACHINE_SCRATCH_ADDR, pxe_rm_entry); - - return GRUB_ERR_NONE; } static grub_err_t @@ -322,7 +320,6 @@ grub_pc_net_config_real (char **device, char **path) GRUB_MOD_INIT(pxe) { struct grub_pxe_bangpxe *pxenv; - struct grub_pxe_undi_open *ou; struct grub_pxe_undi_info *ui; unsigned i; From cf1337aa029a66e8936fa799dbf48d4feabf1f8f Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 6 Jul 2011 02:50:35 +0200 Subject: [PATCH 731/869] * grub-core/kern/i386/qemu/mmap.c (grub_machine_mmap_init): Use new grub_read_cmos prototype. --- ChangeLog | 5 +++++ grub-core/kern/i386/qemu/mmap.c | 21 ++++++++++++++------- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index c2d386032..06b71a246 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-07-05 Vladimir Serbinenko + + * grub-core/kern/i386/qemu/mmap.c (grub_machine_mmap_init): Use new + grub_read_cmos prototype. + 2011-07-05 Vladimir Serbinenko VGA text support in qemu-mips diff --git a/grub-core/kern/i386/qemu/mmap.c b/grub-core/kern/i386/qemu/mmap.c index 208f36b7e..2b0c7f6a7 100644 --- a/grub-core/kern/i386/qemu/mmap.c +++ b/grub-core/kern/i386/qemu/mmap.c @@ -41,8 +41,11 @@ static grub_uint64_t mem_size, above_4g; void grub_machine_mmap_init () { - mem_size = ((grub_uint64_t) grub_cmos_read (QEMU_CMOS_MEMSIZE_HIGH)) << 24 - | ((grub_uint64_t) grub_cmos_read (QEMU_CMOS_MEMSIZE_LOW)) << 16; + grub_uint8_t high, low, b, c, d; + grub_cmos_read (QEMU_CMOS_MEMSIZE_HIGH, &high); + grub_cmos_read (QEMU_CMOS_MEMSIZE_LOW, &low); + mem_size = ((grub_uint64_t) high) << 24 + | ((grub_uint64_t) low) << 16; if (mem_size > 0) { /* Don't ask... */ @@ -50,15 +53,19 @@ grub_machine_mmap_init () } else { + grub_cmos_read (QEMU_CMOS_MEMSIZE2_HIGH, &high); + grub_cmos_read (QEMU_CMOS_MEMSIZE2_LOW, &low); mem_size - = ((((grub_uint64_t) grub_cmos_read (QEMU_CMOS_MEMSIZE2_HIGH)) << 18) - | ((grub_uint64_t) (grub_cmos_read (QEMU_CMOS_MEMSIZE2_LOW)) << 10)) + = ((((grub_uint64_t) high) << 18) | (((grub_uint64_t) low) << 10)) + 1024 * 1024; } - above_4g = (((grub_uint64_t) grub_cmos_read (0x5b)) << 16) - | (((grub_uint64_t) grub_cmos_read (0x5c)) << 24) - | (((grub_uint64_t) grub_cmos_read (0x5d)) << 32); + grub_cmos_read (0x5b, &b); + grub_cmos_read (0x5c, &c); + grub_cmos_read (0x5d, &d); + above_4g = (((grub_uint64_t) b) << 16) + | (((grub_uint64_t) c) << 24) + | (((grub_uint64_t) d) << 32); } grub_err_t From b975df6348fdf7bb02d107dd4fff92965e5f9182 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 6 Jul 2011 12:53:37 +0200 Subject: [PATCH 732/869] Send TFTP_ERROR on tftp premature close. Several cleanups --- grub-core/net/ethernet.c | 40 ++++++++++++ grub-core/net/ip.c | 46 +++++++++++++- grub-core/net/net.c | 1 + grub-core/net/tftp.c | 118 +++++++++++++++++++++++++++++++++++- include/grub/net.h | 34 +++-------- include/grub/net/device.h | 0 include/grub/net/ethernet.h | 41 ++++++------- include/grub/net/ip.h | 63 ++++++++++--------- include/grub/net/tftp.h | 68 --------------------- include/grub/net/udp.h | 4 +- 10 files changed, 262 insertions(+), 153 deletions(-) delete mode 100644 include/grub/net/device.h delete mode 100644 include/grub/net/tftp.h diff --git a/grub-core/net/ethernet.c b/grub-core/net/ethernet.c index 3006c9d93..acd33bcf6 100644 --- a/grub-core/net/ethernet.c +++ b/grub-core/net/ethernet.c @@ -1,3 +1,21 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2010,2011 Free Software Foundation, Inc. + * + * GRUB is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see . + */ + #include #include #include @@ -8,6 +26,28 @@ #include #include +#define LLCADDRMASK 0x7f + +struct etherhdr +{ + grub_uint8_t dst[6]; + grub_uint8_t src[6]; + grub_uint16_t type; +} __attribute__ ((packed)); + +struct llchdr +{ + grub_uint8_t dsap; + grub_uint8_t ssap; + grub_uint8_t ctrl; +} __attribute__ ((packed)); + +struct snaphdr +{ + grub_uint8_t oui[3]; + grub_uint16_t type; +} __attribute__ ((packed)); + grub_err_t send_ethernet_packet (struct grub_net_network_level_interface *inf, struct grub_net_buff *nb, diff --git a/grub-core/net/ip.c b/grub-core/net/ip.c index 8b06f7d11..642a67f18 100644 --- a/grub-core/net/ip.c +++ b/grub-core/net/ip.c @@ -1,3 +1,21 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2010,2011 Free Software Foundation, Inc. + * + * GRUB is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see . + */ + #include #include #include @@ -7,8 +25,32 @@ #include #include +struct iphdr { + grub_uint8_t verhdrlen; + grub_uint8_t service; + grub_uint16_t len; + grub_uint16_t ident; + grub_uint16_t frags; + grub_uint8_t ttl; + grub_uint8_t protocol; + grub_uint16_t chksum; + grub_uint32_t src; + grub_uint32_t dest; +} __attribute__ ((packed)) ; + +struct ip6hdr +{ + grub_uint8_t version:4, priority:4; + grub_uint8_t flow_lbl[3]; + grub_uint16_t payload_len; + grub_uint8_t nexthdr; + grub_uint8_t hop_limit; + grub_uint8_t saddr[16]; + grub_uint8_t daddr[16]; +} __attribute__ ((packed)); + grub_uint16_t -ipchksum (void *ipv, int len) +grub_net_ip_chksum (void *ipv, int len) { grub_uint16_t *ip = (grub_uint16_t *) ipv; grub_uint32_t sum = 0; @@ -48,7 +90,7 @@ grub_net_send_ip_packet (struct grub_net_network_level_interface * inf, iph->dest = target->ipv4; iph->chksum = 0; - iph->chksum = ipchksum ((void *) nb->data, sizeof (*iph)); + iph->chksum = grub_net_ip_chksum ((void *) nb->data, sizeof (*iph)); /* Determine link layer target address via ARP. */ err = grub_net_arp_resolve (inf, target, &ll_target_addr); diff --git a/grub-core/net/net.c b/grub-core/net/net.c index a3b76cae0..0d664d9b5 100644 --- a/grub-core/net/net.c +++ b/grub-core/net/net.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include diff --git a/grub-core/net/tftp.c b/grub-core/net/tftp.c index 6ffe27669..be1534021 100644 --- a/grub-core/net/tftp.c +++ b/grub-core/net/tftp.c @@ -1,5 +1,22 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2010,2011 Free Software Foundation, Inc. + * + * GRUB is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see . + */ + #include -#include #include #include #include @@ -11,6 +28,74 @@ GRUB_MOD_LICENSE ("GPLv3+"); +/* IP port for the MTFTP server used for Intel's PXE */ +enum + { + MTFTP_SERVER_PORT = 75, + MTFTP_CLIENT_PORT = 76, + /* IP port for the TFTP server */ + TFTP_SERVER_PORT = 69 + }; + +enum + { + TFTP_DEFAULTSIZE_PACKET = 512, + TFTP_MAX_PACKET = 1432 + }; + +enum + { + TFTP_CODE_EOF = 1, + TFTP_CODE_MORE = 2, + TFTP_CODE_ERROR = 3, + TFTP_CODE_BOOT = 4, + TFTP_CODE_CFG = 5 + }; + +enum + { + TFTP_RRQ = 1, + TFTP_WRQ = 2, + TFTP_DATA = 3, + TFTP_ACK = 4, + TFTP_ERROR = 5, + TFTP_OACK = 6 + }; + +enum + { + TFTP_EUNDEF = 0, /* not defined */ + TFTP_ENOTFOUND = 1, /* file not found */ + TFTP_EACCESS = 2, /* access violation */ + TFTP_ENOSPACE = 3, /* disk full or allocation exceeded */ + TFTP_EBADOP = 4, /* illegal TFTP operation */ + TFTP_EBADID = 5, /* unknown transfer ID */ + TFTP_EEXISTS = 6, /* file already exists */ + TFTP_ENOUSER = 7 /* no such user */ + }; + +struct tftphdr { + grub_uint16_t opcode; + union { + grub_int8_t rrq[TFTP_DEFAULTSIZE_PACKET]; + struct { + grub_uint16_t block; + grub_int8_t download[TFTP_MAX_PACKET]; + } data; + struct { + grub_uint16_t block; + } ack; + struct { + grub_uint16_t errcode; + grub_int8_t errmsg[TFTP_DEFAULTSIZE_PACKET]; + } err; + struct { + grub_int8_t data[TFTP_DEFAULTSIZE_PACKET+2]; + } oack; + } u; +} __attribute__ ((packed)) ; + + typedef struct tftp_data { grub_uint64_t file_size; @@ -40,7 +125,7 @@ tftp_receive (grub_net_socket_t sock __attribute__ ((unused)), switch (grub_be_to_cpu16 (tftph->opcode)) { case TFTP_OACK: - data->block_size = 512; + data->block_size = TFTP_DEFAULTSIZE_PACKET; data->have_oack = 1; for (ptr = nb->data + sizeof (tftph->opcode); ptr < nb->tail;) { @@ -224,8 +309,35 @@ static grub_err_t tftp_close (struct grub_file *file) { tftp_data_t data = file->data; + if (data->sock) - grub_net_udp_close (data->sock); + { + char nbdata[512]; + grub_err_t err; + struct grub_net_buff nb_err; + struct tftphdr *tftph; + + nb_err.head = nbdata; + nb_err.end = nbdata + sizeof (nbdata); + + grub_netbuff_clear (&nb_err); + grub_netbuff_reserve (&nb_err, 512); + err = grub_netbuff_push (&nb_err, sizeof (tftph->opcode) + + sizeof (tftph->u.err.errcode) + + sizeof ("closed")); + if (!err) + { + tftph = (struct tftphdr *) nb_err.data; + tftph->opcode = grub_cpu_to_be16 (TFTP_ERROR); + tftph->u.err.errcode = grub_cpu_to_be16 (TFTP_EUNDEF); + grub_memcpy (tftph->u.err.errmsg, "closed", sizeof ("closed")); + + err = grub_net_send_udp_packet (data->sock, &nb_err); + } + if (err) + grub_print_error (); + grub_net_udp_close (data->sock); + } grub_free (data); return GRUB_ERR_NONE; } diff --git a/include/grub/net.h b/include/grub/net.h index 85fdef365..0ac0838cf 100644 --- a/include/grub/net.h +++ b/include/grub/net.h @@ -1,6 +1,6 @@ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2010 Free Software Foundation, Inc. + * Copyright (C) 2010,2011 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -82,6 +82,10 @@ typedef struct grub_net_packets grub_net_packet_t *last; } grub_net_packets_t; +#ifdef GRUB_MACHINE_EFI +#include +#endif + struct grub_net_card { struct grub_net_card *next; @@ -93,11 +97,13 @@ struct grub_net_card int opened; union { +#ifdef GRUB_MACHINE_EFI struct { struct grub_efi_simple_network *efi_net; - void *efi_handle; + grub_efi_handle_t efi_handle; }; +#endif void *data; int data_num; }; @@ -420,30 +426,6 @@ extern struct grub_net_network_level_interface *grub_net_network_level_interface #define FOR_NET_NETWORK_LEVEL_INTERFACES_SAFE(var,next) for (var = grub_net_network_level_interfaces, next = var->next; var; var = next, next = var->next) -grub_err_t grub_net_send_link_layer (struct grub_net_network_level_interface *inf, - struct grub_net_buff *nb, - grub_net_link_level_address_t *target); - -typedef int -(*grub_net_packet_handler_t) (struct grub_net_buff *nb, - struct grub_net_network_level_interface *inf); - -grub_err_t grub_net_recv_link_layer (struct grub_net_network_level_interface *inf, - grub_net_packet_handler_t handler); - - -grub_err_t -grub_net_recv_ip_packets (struct grub_net_buff *nb, - const struct grub_net_card *card, - const grub_net_link_level_address_t *hwaddress); - -grub_err_t -grub_net_send_ip_packet (struct grub_net_network_level_interface *inf, - const grub_net_network_level_address_t *target, - struct grub_net_buff *nb); - -#define FOR_NET_NL_PACKETS(inf, var) FOR_PACKETS(inf->nl_pending, var) - void grub_net_poll_cards (unsigned time); diff --git a/include/grub/net/device.h b/include/grub/net/device.h deleted file mode 100644 index e69de29bb..000000000 diff --git a/include/grub/net/ethernet.h b/include/grub/net/ethernet.h index a841dc12c..a68aafd96 100644 --- a/include/grub/net/ethernet.h +++ b/include/grub/net/ethernet.h @@ -1,30 +1,26 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2010,2011 Free Software Foundation, Inc. + * + * GRUB is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see . + */ + #ifndef GRUB_NET_ETHERNET_HEADER #define GRUB_NET_ETHERNET_HEADER 1 #include #include -#define LLCADDRMASK 0x7f - -struct etherhdr -{ - grub_uint8_t dst[6]; - grub_uint8_t src[6]; - grub_uint16_t type; -} __attribute__ ((packed)); - -struct llchdr -{ - grub_uint8_t dsap; - grub_uint8_t ssap; - grub_uint8_t ctrl; -} __attribute__ ((packed)); - -struct snaphdr -{ - grub_uint8_t oui[3]; - grub_uint16_t type; -} __attribute__ ((packed)); - /* IANA Ethertype */ enum { @@ -32,7 +28,6 @@ enum GRUB_NET_ETHERTYPE_ARP = 0x0806 }; - grub_err_t send_ethernet_packet (struct grub_net_network_level_interface *inf, struct grub_net_buff *nb, diff --git a/include/grub/net/ip.h b/include/grub/net/ip.h index cb8481a7d..9bed1e19c 100644 --- a/include/grub/net/ip.h +++ b/include/grub/net/ip.h @@ -1,35 +1,42 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2010,2011 Free Software Foundation, Inc. + * + * GRUB is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see . + */ + #ifndef GRUB_NET_IP_HEADER #define GRUB_NET_IP_HEADER 1 #include +#include -struct iphdr { - grub_uint8_t verhdrlen; - grub_uint8_t service; - grub_uint16_t len; - grub_uint16_t ident; - grub_uint16_t frags; - grub_uint8_t ttl; - grub_uint8_t protocol; - grub_uint16_t chksum; - grub_uint32_t src; - grub_uint32_t dest; -} __attribute__ ((packed)) ; - -struct ip6hdr -{ - grub_uint8_t version:4, priority:4; - grub_uint8_t flow_lbl[3]; - grub_uint16_t payload_len; - grub_uint8_t nexthdr; - grub_uint8_t hop_limit; - grub_uint8_t saddr[16]; - grub_uint8_t daddr[16]; -} __attribute__ ((packed)); - -#define IP_UDP 0x11 /* UDP protocol */ +enum + { + IP_UDP = 0x11 /* UDP protocol */ + }; #define IP_BROADCAST 0xFFFFFFFF -grub_uint16_t ipchksum(void *ipv, int len); -void ipv4_ini(void); -void ipv4_fini(void); +grub_uint16_t grub_net_ip_chksum(void *ipv, int len); + +grub_err_t +grub_net_recv_ip_packets (struct grub_net_buff *nb, + const struct grub_net_card *card, + const grub_net_link_level_address_t *hwaddress); + +grub_err_t +grub_net_send_ip_packet (struct grub_net_network_level_interface *inf, + const grub_net_network_level_address_t *target, + struct grub_net_buff *nb); + #endif diff --git a/include/grub/net/tftp.h b/include/grub/net/tftp.h deleted file mode 100644 index 0d8cbd1de..000000000 --- a/include/grub/net/tftp.h +++ /dev/null @@ -1,68 +0,0 @@ -#ifndef GRUB_NET_TFTP_HEADER -#define GRUB_NET_TFTP_HEADER 1 - -#include -#include -#include - -/* IP port for the MTFTP server used for Intel's PXE */ -#define MTFTP_SERVER_PORT 75 -#define MTFTP_CLIENT_PORT 76 - -#define TFTP_DEFAULTSIZE_PACKET 512 -#define TFTP_MAX_PACKET 1432 - -/* IP port for the TFTP server */ -#define TFTP_SERVER_PORT 69 - - -/* We define these based on what's in arpa/tftp.h. We just like our - * names better, cause they're clearer */ -#define TFTP_RRQ 1 -#define TFTP_WRQ 2 -#define TFTP_DATA 3 -#define TFTP_ACK 4 -#define TFTP_ERROR 5 -#define TFTP_OACK 6 - -#define TFTP_CODE_EOF 1 -#define TFTP_CODE_MORE 2 -#define TFTP_CODE_ERROR 3 -#define TFTP_CODE_BOOT 4 -#define TFTP_CODE_CFG 5 - -#define TFTP_EUNDEF 0 /* not defined */ -#define TFTP_ENOTFOUND 1 /* file not found */ -#define TFTP_EACCESS 2 /* access violation */ -#define TFTP_ENOSPACE 3 /* disk full or allocation exceeded */ -#define TFTP_EBADOP 4 /* illegal TFTP operation */ -#define TFTP_EBADID 5 /* unknown transfer ID */ -#define TFTP_EEXISTS 6 /* file already exists */ -#define TFTP_ENOUSER 7 /* no such user */ - - /* * own here because this is cleaner, and maps to the same data layout. - * */ - - -struct tftphdr { - grub_uint16_t opcode; - union { - grub_int8_t rrq[TFTP_DEFAULTSIZE_PACKET]; - struct { - grub_uint16_t block; - grub_int8_t download[TFTP_MAX_PACKET]; - } data; - struct { - grub_uint16_t block; - } ack; - struct { - grub_uint16_t errcode; - grub_int8_t errmsg[TFTP_DEFAULTSIZE_PACKET]; - } err; - struct { - grub_int8_t data[TFTP_DEFAULTSIZE_PACKET+2]; - } oack; - } u; -} __attribute__ ((packed)) ; - -#endif diff --git a/include/grub/net/udp.h b/include/grub/net/udp.h index 272612299..5aacf8abb 100644 --- a/include/grub/net/udp.h +++ b/include/grub/net/udp.h @@ -28,13 +28,11 @@ grub_net_udp_close (grub_net_socket_t sock) } grub_err_t -grub_net_send_udp_packet (const grub_net_socket_t socket , struct grub_net_buff *nb); +grub_net_send_udp_packet (const grub_net_socket_t socket, struct grub_net_buff *nb); grub_err_t grub_net_recv_udp_packet (struct grub_net_buff *nb, struct grub_net_network_level_interface *inf); -#define FOR_NET_UDP_PACKETS(inf, var) FOR_PACKETS(inf->udp_pending, var) - #endif From 1c3fcdee151a95730444352b2fb5774bfdd75ce6 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 6 Jul 2011 13:13:45 +0200 Subject: [PATCH 733/869] buffer network files. Fix incorrect net_fini_hw and unregister calls --- grub-core/net/net.c | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/grub-core/net/net.c b/grub-core/net/net.c index 0d664d9b5..1f2e2b7d4 100644 --- a/grub-core/net/net.c +++ b/grub-core/net/net.c @@ -32,6 +32,7 @@ #include #include #include +#include GRUB_MOD_LICENSE ("GPLv3+"); @@ -709,15 +710,36 @@ grub_net_fs_dir (grub_device_t device, const char *path __attribute__ ((unused)) } static grub_err_t -grub_net_fs_open (struct grub_file *file, const char *name) +grub_net_fs_open (struct grub_file *file_out, const char *name) { + grub_err_t err; + struct grub_file *file, *bufio; + + file = grub_malloc (sizeof (*file)); + if (!file) + return grub_errno; + + grub_memcpy (file, file_out, sizeof (struct grub_file)); file->device->net->packs.first = NULL; file->device->net->packs.last = NULL; file->device->net->name = grub_strdup (name); if (!file->device->net->name) return grub_errno; - return file->device->net->protocol->open (file, name); + err = file->device->net->protocol->open (file, name); + if (err) + return err; + bufio = grub_bufio_open (file, 32768); + if (! bufio) + { + file->device->net->protocol->close (file); + grub_free (file->device->net->name); + grub_free (file); + return grub_errno; + } + + grub_memcpy (file_out, bufio, sizeof (struct grub_file)); + return GRUB_ERR_NONE; } static grub_err_t @@ -1430,8 +1452,6 @@ GRUB_MOD_INIT(net) fini_hnd = grub_loader_register_preboot_hook (grub_net_fini_hw, grub_net_restore_hw, GRUB_LOADER_PREBOOT_HOOK_PRIO_DISK); - grub_net_fini_hw (0); - grub_loader_unregister_preboot_hook (fini_hnd); } GRUB_MOD_FINI(net) @@ -1446,5 +1466,6 @@ GRUB_MOD_FINI(net) grub_unregister_command (cmd_getdhcp); grub_fs_unregister (&grub_net_fs); grub_net_open = NULL; + grub_net_fini_hw (0); grub_loader_unregister_preboot_hook (fini_hnd); } From 228ccedb5e7870931b628da5f1f758be65dac623 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 6 Jul 2011 13:37:33 +0200 Subject: [PATCH 734/869] poll cards when idle --- grub-core/kern/term.c | 4 ++++ grub-core/net/net.c | 11 +++++++++++ include/grub/kernel.h | 3 +++ 3 files changed, 18 insertions(+) diff --git a/grub-core/kern/term.c b/grub-core/kern/term.c index 7b3593161..d7c65dd82 100644 --- a/grub-core/kern/term.c +++ b/grub-core/kern/term.c @@ -29,6 +29,7 @@ struct grub_term_output *grub_term_outputs; struct grub_term_input *grub_term_inputs; void (*grub_term_poll_usb) (void) = NULL; +void (*grub_net_poll_cards_idle) (void) = NULL; /* Put a Unicode character. */ static void @@ -91,6 +92,9 @@ grub_checkkey (void) if (grub_term_poll_usb) grub_term_poll_usb (); + if (grub_net_poll_cards_idle) + grub_net_poll_cards_idle (); + FOR_ACTIVE_TERM_INPUTS(term) { pending_key = term->getkey (term); diff --git a/grub-core/net/net.c b/grub-core/net/net.c index 1f2e2b7d4..bee4f8321 100644 --- a/grub-core/net/net.c +++ b/grub-core/net/net.c @@ -33,6 +33,7 @@ #include #include #include +#include GRUB_MOD_LICENSE ("GPLv3+"); @@ -809,6 +810,14 @@ grub_net_poll_cards (unsigned time) } } +static void +grub_net_poll_cards_idle_real (void) +{ + struct grub_net_card *card; + FOR_NET_CARDS (card) + receive_packets (card); +} + /* Read from the packets list*/ static grub_ssize_t grub_net_fs_read_real (grub_file_t file, char *buf, grub_size_t len) @@ -1452,6 +1461,7 @@ GRUB_MOD_INIT(net) fini_hnd = grub_loader_register_preboot_hook (grub_net_fini_hw, grub_net_restore_hw, GRUB_LOADER_PREBOOT_HOOK_PRIO_DISK); + grub_net_poll_cards_idle = grub_net_poll_cards_idle_real; } GRUB_MOD_FINI(net) @@ -1468,4 +1478,5 @@ GRUB_MOD_FINI(net) grub_net_open = NULL; grub_net_fini_hw (0); grub_loader_unregister_preboot_hook (fini_hnd); + grub_net_poll_cards_idle = grub_net_poll_cards_idle_real; } diff --git a/include/grub/kernel.h b/include/grub/kernel.h index 6a5f91c3d..aef585668 100644 --- a/include/grub/kernel.h +++ b/include/grub/kernel.h @@ -90,6 +90,9 @@ grub_machine_get_bootlocation (char **device, char **path); /* Register all the exported symbols. This is automatically generated. */ void grub_register_exported_symbols (void); +extern void (*EXPORT_VAR(grub_net_poll_cards_idle)) (void); + + #if ! defined (ASM_FILE) extern char grub_prefix[]; #endif From 138eeb3625b22b9b5b286813088d8edca09ff2af Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 6 Jul 2011 13:52:35 +0200 Subject: [PATCH 735/869] Move bootp into a separate file --- grub-core/Makefile.core.def | 1 + grub-core/net/net.c | 514 +----------------------------------- include/grub/net.h | 16 ++ 3 files changed, 24 insertions(+), 507 deletions(-) diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def index d1e1d30e4..7bceaa98f 100644 --- a/grub-core/Makefile.core.def +++ b/grub-core/Makefile.core.def @@ -1579,6 +1579,7 @@ module = { module = { name = net; common = net/net.c; + common = net/bootp.c; common = net/ip.c; common = net/udp.c; common = net/ethernet.c; diff --git a/grub-core/net/net.c b/grub-core/net/net.c index bee4f8321..bc16fbde5 100644 --- a/grub-core/net/net.c +++ b/grub-core/net/net.c @@ -16,10 +16,8 @@ * along with GRUB. If not, see . */ -#include #include #include -#include #include #include #include @@ -28,16 +26,14 @@ #include #include #include -#include #include -#include #include #include #include GRUB_MOD_LICENSE ("GPLv3+"); -static char *default_server; +char *grub_net_default_server; struct grub_net_route { @@ -59,17 +55,6 @@ struct grub_net_card *grub_net_cards = NULL; struct grub_net_network_level_protocol *grub_net_network_level_protocols = NULL; static struct grub_fs grub_net_fs; -static inline void -grub_net_network_level_interface_unregister (struct grub_net_network_level_interface *inter) -{ - inter->card->num_ifaces--; - *inter->prev = inter->next; - if (inter->next) - inter->next->prev = inter->prev; - inter->next = 0; - inter->prev = 0; -} - void grub_net_card_unregister (struct grub_net_card *card) { @@ -644,7 +629,7 @@ grub_net_open_real (const char *name) { protname = "tftp"; protnamelen = sizeof ("tftp") - 1; - server = default_server; + server = grub_net_default_server; } else { @@ -659,7 +644,7 @@ grub_net_open_real (const char *name) else { protnamelen = grub_strlen (name); - server = default_server; + server = grub_net_default_server; protname = name; } } @@ -911,483 +896,6 @@ grub_net_fs_read (grub_file_t file, char *buf, grub_size_t len) return grub_net_fs_read_real (file, buf, len); } -static char * -grub_env_write_readonly (struct grub_env_var *var __attribute__ ((unused)), - const char *val __attribute__ ((unused))) -{ - return NULL; -} - -static void -set_env_limn_ro (const char *intername, const char *suffix, - char *value, grub_size_t len) -{ - char c; - char varname[sizeof ("net_") + grub_strlen (intername) + sizeof ("_") - + grub_strlen (suffix)]; - grub_snprintf (varname, sizeof (varname), "net_%s_%s", intername, suffix); - c = value[len]; - value[len] = 0; - grub_env_set (varname, value); - value[len] = c; - grub_register_variable_hook (varname, 0, grub_env_write_readonly); -} - -static void -parse_dhcp_vendor (const char *name, void *vend, int limit) -{ - grub_uint8_t *ptr, *ptr0; - - ptr = ptr0 = vend; - - if (ptr[0] != GRUB_NET_BOOTP_RFC1048_MAGIC_0 - || ptr[1] != GRUB_NET_BOOTP_RFC1048_MAGIC_1 - || ptr[2] != GRUB_NET_BOOTP_RFC1048_MAGIC_2 - || ptr[3] != GRUB_NET_BOOTP_RFC1048_MAGIC_3) - return; - ptr = ptr + sizeof (grub_uint32_t); - while (ptr - ptr0 < limit) - { - grub_uint8_t tagtype; - grub_uint8_t taglength; - - tagtype = *ptr++; - - /* Pad tag. */ - if (tagtype == 0) - continue; - - /* End tag. */ - if (tagtype == 0xff) - return; - - taglength = *ptr++; - - switch (tagtype) - { - case 12: - set_env_limn_ro (name, "hostname", (char *) ptr, taglength); - break; - - case 15: - set_env_limn_ro (name, "domain", (char *) ptr, taglength); - break; - - case 17: - set_env_limn_ro (name, "rootpath", (char *) ptr, taglength); - break; - - case 18: - set_env_limn_ro (name, "extensionspath", (char *) ptr, taglength); - break; - - /* If you need any other options please contact GRUB - developpement team. */ - } - - ptr += taglength; - } -} - -#define OFFSET_OF(x, y) ((grub_uint8_t *)((y)->x) - (grub_uint8_t *)(y)) - -struct grub_net_network_level_interface * -grub_net_configure_by_dhcp_ack (const char *name, - struct grub_net_card *card, - grub_net_interface_flags_t flags, - const struct grub_net_bootp_packet *bp, - grub_size_t size, - int is_def, char **device, char **path) -{ - grub_net_network_level_address_t addr; - grub_net_link_level_address_t hwaddr; - struct grub_net_network_level_interface *inter; - - addr.type = GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4; - addr.ipv4 = bp->your_ip; - - if (device) - *device = 0; - if (path) - *path = 0; - - grub_memcpy (hwaddr.mac, bp->mac_addr, - bp->hw_len < sizeof (hwaddr.mac) ? bp->hw_len - : sizeof (hwaddr.mac)); - hwaddr.type = GRUB_NET_LINK_LEVEL_PROTOCOL_ETHERNET; - - inter = grub_net_add_addr (name, card, addr, hwaddr, flags); - { - grub_net_network_level_netaddress_t target; - grub_net_network_level_address_t gw; - char rname[grub_strlen (name) + sizeof ("_gw")]; - - target.type = GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4; - target.ipv4.base = bp->server_ip; - target.ipv4.masksize = 32; - gw.type = GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4; - gw.ipv4 = bp->gateway_ip; - grub_snprintf (rname, sizeof (rname), "%s_gw", name); - grub_net_add_route_gw (rname, target, gw); - } - { - grub_net_network_level_netaddress_t target; - target.type = GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4; - target.ipv4.base = bp->gateway_ip; - target.ipv4.masksize = 32; - grub_net_add_route (name, target, inter); - } - - if (size > OFFSET_OF (boot_file, bp)) - set_env_limn_ro (name, "boot_file", (char *) bp->boot_file, - sizeof (bp->boot_file)); - if (is_def) - default_server = 0; - if (size > OFFSET_OF (server_name, bp) - && bp->server_name[0]) - { - set_env_limn_ro (name, "dhcp_server_name", (char *) bp->server_name, - sizeof (bp->server_name)); - if (is_def && !default_server) - { - default_server = grub_strdup (bp->server_name); - grub_print_error (); - } - if (device && !*device) - { - *device = grub_xasprintf ("tftp,%s", bp->server_name); - grub_print_error (); - } - } - if (is_def && !default_server) - { - default_server = grub_xasprintf ("%d.%d.%d.%d", - ((grub_uint8_t *) &bp->server_ip)[0], - ((grub_uint8_t *) &bp->server_ip)[1], - ((grub_uint8_t *) &bp->server_ip)[2], - ((grub_uint8_t *) &bp->server_ip)[3]); - grub_print_error (); - } - - if (device && !*device) - { - *device = grub_xasprintf ("tftp,%d.%d.%d.%d", - ((grub_uint8_t *) &bp->server_ip)[0], - ((grub_uint8_t *) &bp->server_ip)[1], - ((grub_uint8_t *) &bp->server_ip)[2], - ((grub_uint8_t *) &bp->server_ip)[3]); - grub_print_error (); - } - if (size > OFFSET_OF (boot_file, bp) && path) - { - *path = grub_strndup (bp->boot_file, sizeof (bp->boot_file)); - grub_print_error (); - if (*path) - { - char *slash; - slash = grub_strrchr (*path, '/'); - if (slash) - *slash = 0; - else - **path = 0; - } - } - if (size > OFFSET_OF (vendor, bp)) - parse_dhcp_vendor (name, &bp->vendor, size - OFFSET_OF (vendor, bp)); - - inter->dhcp_ack = grub_malloc (size); - if (inter->dhcp_ack) - { - grub_memcpy (inter->dhcp_ack, bp, size); - inter->dhcp_acklen = size; - } - else - grub_errno = GRUB_ERR_NONE; - - return inter; -} - -void -grub_net_process_dhcp (struct grub_net_buff *nb, - struct grub_net_card *card) -{ - char *name; - struct grub_net_network_level_interface *inf; - - name = grub_xasprintf ("%s:dhcp", card->name); - if (!name) - { - grub_print_error (); - return; - } - grub_net_configure_by_dhcp_ack (name, card, - 0, (const struct grub_net_bootp_packet *) nb->data, - (nb->tail - nb->data), 0, 0, 0); - grub_free (name); - if (grub_errno) - grub_print_error (); - else - { - FOR_NET_NETWORK_LEVEL_INTERFACES(inf) - if (grub_memcmp (inf->name, card->name, grub_strlen (card->name)) == 0 - && grub_memcmp (inf->name + grub_strlen (card->name), - ":dhcp_tmp", sizeof (":dhcp_tmp") - 1) == 0) - { - grub_net_network_level_interface_unregister (inf); - break; - } - } -} - -static char -hexdigit (grub_uint8_t val) -{ - if (val < 10) - return val + '0'; - return val + 'a' - 10; -} - -static grub_err_t -grub_cmd_dhcpopt (struct grub_command *cmd __attribute__ ((unused)), - int argc, char **args) -{ - struct grub_net_network_level_interface *inter; - int num; - grub_uint8_t *ptr; - grub_uint8_t taglength; - - if (argc < 4) - return grub_error (GRUB_ERR_BAD_ARGUMENT, "4 arguments expected"); - - FOR_NET_NETWORK_LEVEL_INTERFACES (inter) - if (grub_strcmp (inter->name, args[1]) == 0) - break; - - if (!inter) - return grub_error (GRUB_ERR_BAD_ARGUMENT, - N_("unrecognised interface %s"), args[1]); - - if (!inter->dhcp_ack) - return grub_error (GRUB_ERR_IO, N_("no DHCP info found")); - - if (inter->dhcp_acklen <= OFFSET_OF (vendor, inter->dhcp_ack)) - return grub_error (GRUB_ERR_IO, N_("no DHCP options found")); - - num = grub_strtoul (args[2], 0, 0); - if (grub_errno) - return grub_errno; - - ptr = inter->dhcp_ack->vendor; - - if (ptr[0] != GRUB_NET_BOOTP_RFC1048_MAGIC_0 - || ptr[1] != GRUB_NET_BOOTP_RFC1048_MAGIC_1 - || ptr[2] != GRUB_NET_BOOTP_RFC1048_MAGIC_2 - || ptr[3] != GRUB_NET_BOOTP_RFC1048_MAGIC_3) - return grub_error (GRUB_ERR_IO, N_("no DHCP options found")); - ptr = ptr + sizeof (grub_uint32_t); - while (1) - { - grub_uint8_t tagtype; - - if (ptr >= ((grub_uint8_t *) inter->dhcp_ack) + inter->dhcp_acklen) - return grub_error (GRUB_ERR_IO, N_("no DHCP option %d found"), num); - - tagtype = *ptr++; - - /* Pad tag. */ - if (tagtype == 0) - continue; - - /* End tag. */ - if (tagtype == 0xff) - return grub_error (GRUB_ERR_IO, N_("no DHCP option %d found"), num); - - taglength = *ptr++; - - if (tagtype == num) - break; - ptr += taglength; - } - - if (grub_strcmp (args[3], "string") == 0) - { - char *val = grub_malloc (taglength + 1); - if (!val) - return grub_errno; - grub_memcpy (val, ptr, taglength); - val[taglength] = 0; - if (args[0][0] == '-' && args[0][1] == 0) - grub_printf ("%s\n", val); - else - return grub_env_set (args[0], val); - return GRUB_ERR_NONE; - } - - if (grub_strcmp (args[3], "number") == 0) - { - grub_uint64_t val = 0; - int i; - for (i = 0; i < taglength; i++) - val = (val << 8) | ptr[i]; - if (args[0][0] == '-' && args[0][1] == 0) - grub_printf ("%llu\n", (unsigned long long) val); - else - { - char valn[64]; - grub_printf (valn, sizeof (valn), "%lld\n", (unsigned long long) val); - return grub_env_set (args[0], valn); - } - return GRUB_ERR_NONE; - } - - if (grub_strcmp (args[3], "hex") == 0) - { - char *val = grub_malloc (2 * taglength + 1); - int i; - if (!val) - return grub_errno; - for (i = 0; i < taglength; i++) - { - val[2 * i] = hexdigit (ptr[i] >> 4); - val[2 * i + 1] = hexdigit (ptr[i] & 0xf); - } - val[2 * taglength] = 0; - if (args[0][0] == '-' && args[0][1] == 0) - grub_printf ("%s\n", val); - else - return grub_env_set (args[0], val); - return GRUB_ERR_NONE; - } - - return grub_error (GRUB_ERR_BAD_ARGUMENT, - "unrecognised format specification %s", args[3]); -} - -static grub_err_t -grub_cmd_bootp (struct grub_command *cmd __attribute__ ((unused)), - int argc, char **args) -{ - struct grub_net_card *card; - struct grub_net_network_level_interface *ifaces; - grub_size_t ncards = 0; - unsigned j = 0; - int interval; - grub_err_t err; - - FOR_NET_CARDS (card) - { - if (argc > 0 && grub_strcmp (card->name, args[0]) != 0) - continue; - ncards++; - } - - ifaces = grub_zalloc (ncards * sizeof (ifaces[0])); - if (!ifaces) - return grub_errno; - - j = 0; - FOR_NET_CARDS (card) - { - if (argc > 0 && grub_strcmp (card->name, args[0]) != 0) - continue; - ifaces[j].card = card; - ifaces[j].next = &ifaces[j+1]; - if (j) - ifaces[j].prev = &ifaces[j-1].next; - ifaces[j].name = grub_xasprintf ("%s:dhcp_tmp", card->name); - card->num_ifaces++; - if (!ifaces[j].name) - { - unsigned i; - for (i = 0; i < j; i++) - grub_free (ifaces[i].name); - grub_free (ifaces); - return grub_errno; - } - ifaces[j].address.type = GRUB_NET_NETWORK_LEVEL_PROTOCOL_DHCP_RECV; - grub_memcpy (&ifaces[j].hwaddress, &card->default_address, - sizeof (ifaces[j].hwaddress)); - j++; - } - ifaces[ncards - 1].next = grub_net_network_level_interfaces; - if (grub_net_network_level_interfaces) - grub_net_network_level_interfaces->prev = & ifaces[ncards - 1].next; - grub_net_network_level_interfaces = &ifaces[0]; - ifaces[0].prev = &grub_net_network_level_interfaces; - for (interval = 200; interval < 10000; interval *= 2) - { - int done = 0; - for (j = 0; j < ncards; j++) - { - struct grub_net_bootp_packet *pack; - struct grub_datetime date; - grub_int32_t t; - struct grub_net_buff *nb; - struct udphdr *udph; - grub_net_network_level_address_t target; - - if (!ifaces[j].prev) - continue; - nb = grub_netbuff_alloc (sizeof (*pack)); - if (!nb) - return grub_errno; - err = grub_netbuff_reserve (nb, sizeof (*pack) + 64 + 128); - if (err) - return err; - err = grub_netbuff_push (nb, sizeof (*pack) + 64); - if (err) - return err; - pack = (void *) nb->data; - done = 1; - grub_memset (pack, 0, sizeof (*pack) + 64); - pack->opcode = 1; - pack->hw_type = 1; - pack->hw_len = 6; - err = grub_get_datetime (&date); - if (err || !grub_datetime2unixtime (&date, &t)) - { - grub_errno = GRUB_ERR_NONE; - t = 0; - } - pack->ident = grub_cpu_to_be32 (t); - pack->seconds = 0;//grub_cpu_to_be16 (t); - - grub_memcpy (&pack->mac_addr, &ifaces[j].hwaddress.mac, 6); - - grub_netbuff_push (nb, sizeof (*udph)); - - udph = (struct udphdr *) nb->data; - udph->src = grub_cpu_to_be16 (68); - udph->dst = grub_cpu_to_be16 (67); - udph->chksum = 0; - udph->len = grub_cpu_to_be16 (nb->tail - nb->data); - - target.type = GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4; - target.ipv4 = 0xffffffff; - - err = grub_net_send_ip_packet (&ifaces[j], &target, nb); - if (err) - return err; - } - if (!done) - break; - grub_net_poll_cards (interval); - } - - err = GRUB_ERR_NONE; - for (j = 0; j < ncards; j++) - { - if (!ifaces[j].prev) - continue; - grub_error_push (); - grub_net_network_level_interface_unregister (&ifaces[j]); - err = grub_error (GRUB_ERR_FILE_NOT_FOUND, "couldn't configure %s", - ifaces[j].card->name); - } - - return err; -} - static struct grub_fs grub_net_fs = { .name = "netfs", @@ -1423,8 +931,8 @@ grub_net_restore_hw (void) static void *fini_hnd; static grub_command_t cmd_addaddr, cmd_deladdr, cmd_addroute, cmd_delroute; -static grub_command_t cmd_lsroutes, cmd_lscards, cmd_getdhcp, cmd_bootp; -static grub_command_t cmd_dhcp, cmd_lsaddr; +static grub_command_t cmd_lsroutes, cmd_lscards; +static grub_command_t cmd_lsaddr; GRUB_MOD_INIT(net) { @@ -1446,15 +954,7 @@ GRUB_MOD_INIT(net) "", N_("list network cards")); cmd_lsaddr = grub_register_command ("net_ls_addr", grub_cmd_listaddrs, "", N_("list network addresses")); - cmd_bootp = grub_register_command ("net_bootp", grub_cmd_bootp, - "[CARD]", - N_("perform a bootp autoconfiguration")); - cmd_dhcp = grub_register_command ("net_dhcp", grub_cmd_bootp, - "[CARD]", - N_("perform a bootp autoconfiguration")); - cmd_getdhcp = grub_register_command ("net_get_dhcp_option", grub_cmd_dhcpopt, - N_("VAR INTERFACE NUMBER DESCRIPTION"), - N_("retrieve DHCP option and save it into VAR. If VAR is - then print the value.")); + grub_bootp_init (); grub_fs_register (&grub_net_fs); grub_net_open = grub_net_open_real; @@ -1466,6 +966,7 @@ GRUB_MOD_INIT(net) GRUB_MOD_FINI(net) { + grub_bootp_fini (); grub_unregister_command (cmd_addaddr); grub_unregister_command (cmd_deladdr); grub_unregister_command (cmd_addroute); @@ -1473,7 +974,6 @@ GRUB_MOD_FINI(net) grub_unregister_command (cmd_lsroutes); grub_unregister_command (cmd_lscards); grub_unregister_command (cmd_lsaddr); - grub_unregister_command (cmd_getdhcp); grub_fs_unregister (&grub_net_fs); grub_net_open = NULL; grub_net_fini_hw (0); diff --git a/include/grub/net.h b/include/grub/net.h index 0ac0838cf..92e637d89 100644 --- a/include/grub/net.h +++ b/include/grub/net.h @@ -429,4 +429,20 @@ extern struct grub_net_network_level_interface *grub_net_network_level_interface void grub_net_poll_cards (unsigned time); +void grub_bootp_init (void); +void grub_bootp_fini (void); + +static inline void +grub_net_network_level_interface_unregister (struct grub_net_network_level_interface *inter) +{ + inter->card->num_ifaces--; + *inter->prev = inter->next; + if (inter->next) + inter->next->prev = inter->prev; + inter->next = 0; + inter->prev = 0; +} + +extern char *grub_net_default_server; + #endif /* ! GRUB_NET_HEADER */ From 6cf88dfd7aa8091e7dfe48c5a1e6e722b48c8a37 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 6 Jul 2011 15:02:19 +0200 Subject: [PATCH 736/869] add missing file --- grub-core/net/bootp.c | 527 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 527 insertions(+) create mode 100644 grub-core/net/bootp.c diff --git a/grub-core/net/bootp.c b/grub-core/net/bootp.c new file mode 100644 index 000000000..a1aaf402f --- /dev/null +++ b/grub-core/net/bootp.c @@ -0,0 +1,527 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2010,2011 Free Software Foundation, Inc. + * + * GRUB is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see . + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +static char * +grub_env_write_readonly (struct grub_env_var *var __attribute__ ((unused)), + const char *val __attribute__ ((unused))) +{ + return NULL; +} + +static void +set_env_limn_ro (const char *intername, const char *suffix, + char *value, grub_size_t len) +{ + char c; + char varname[sizeof ("net_") + grub_strlen (intername) + sizeof ("_") + + grub_strlen (suffix)]; + grub_snprintf (varname, sizeof (varname), "net_%s_%s", intername, suffix); + c = value[len]; + value[len] = 0; + grub_env_set (varname, value); + value[len] = c; + grub_register_variable_hook (varname, 0, grub_env_write_readonly); +} + +static void +parse_dhcp_vendor (const char *name, void *vend, int limit) +{ + grub_uint8_t *ptr, *ptr0; + + ptr = ptr0 = vend; + + if (ptr[0] != GRUB_NET_BOOTP_RFC1048_MAGIC_0 + || ptr[1] != GRUB_NET_BOOTP_RFC1048_MAGIC_1 + || ptr[2] != GRUB_NET_BOOTP_RFC1048_MAGIC_2 + || ptr[3] != GRUB_NET_BOOTP_RFC1048_MAGIC_3) + return; + ptr = ptr + sizeof (grub_uint32_t); + while (ptr - ptr0 < limit) + { + grub_uint8_t tagtype; + grub_uint8_t taglength; + + tagtype = *ptr++; + + /* Pad tag. */ + if (tagtype == 0) + continue; + + /* End tag. */ + if (tagtype == 0xff) + return; + + taglength = *ptr++; + + switch (tagtype) + { + case 12: + set_env_limn_ro (name, "hostname", (char *) ptr, taglength); + break; + + case 15: + set_env_limn_ro (name, "domain", (char *) ptr, taglength); + break; + + case 17: + set_env_limn_ro (name, "rootpath", (char *) ptr, taglength); + break; + + case 18: + set_env_limn_ro (name, "extensionspath", (char *) ptr, taglength); + break; + + /* If you need any other options please contact GRUB + developpement team. */ + } + + ptr += taglength; + } +} + +#define OFFSET_OF(x, y) ((grub_uint8_t *)((y)->x) - (grub_uint8_t *)(y)) + +struct grub_net_network_level_interface * +grub_net_configure_by_dhcp_ack (const char *name, + struct grub_net_card *card, + grub_net_interface_flags_t flags, + const struct grub_net_bootp_packet *bp, + grub_size_t size, + int is_def, char **device, char **path) +{ + grub_net_network_level_address_t addr; + grub_net_link_level_address_t hwaddr; + struct grub_net_network_level_interface *inter; + + addr.type = GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4; + addr.ipv4 = bp->your_ip; + + if (device) + *device = 0; + if (path) + *path = 0; + + grub_memcpy (hwaddr.mac, bp->mac_addr, + bp->hw_len < sizeof (hwaddr.mac) ? bp->hw_len + : sizeof (hwaddr.mac)); + hwaddr.type = GRUB_NET_LINK_LEVEL_PROTOCOL_ETHERNET; + + inter = grub_net_add_addr (name, card, addr, hwaddr, flags); + { + grub_net_network_level_netaddress_t target; + grub_net_network_level_address_t gw; + char rname[grub_strlen (name) + sizeof ("_gw")]; + + target.type = GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4; + target.ipv4.base = bp->server_ip; + target.ipv4.masksize = 32; + gw.type = GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4; + gw.ipv4 = bp->gateway_ip; + grub_snprintf (rname, sizeof (rname), "%s_gw", name); + grub_net_add_route_gw (rname, target, gw); + } + { + grub_net_network_level_netaddress_t target; + target.type = GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4; + target.ipv4.base = bp->gateway_ip; + target.ipv4.masksize = 32; + grub_net_add_route (name, target, inter); + } + + if (size > OFFSET_OF (boot_file, bp)) + set_env_limn_ro (name, "boot_file", (char *) bp->boot_file, + sizeof (bp->boot_file)); + if (is_def) + grub_net_default_server = 0; + if (size > OFFSET_OF (server_name, bp) + && bp->server_name[0]) + { + set_env_limn_ro (name, "dhcp_server_name", (char *) bp->server_name, + sizeof (bp->server_name)); + if (is_def && !grub_net_default_server) + { + grub_net_default_server = grub_strdup (bp->server_name); + grub_print_error (); + } + if (device && !*device) + { + *device = grub_xasprintf ("tftp,%s", bp->server_name); + grub_print_error (); + } + } + if (is_def && !grub_net_default_server) + { + grub_net_default_server = grub_xasprintf ("%d.%d.%d.%d", + ((grub_uint8_t *) &bp->server_ip)[0], + ((grub_uint8_t *) &bp->server_ip)[1], + ((grub_uint8_t *) &bp->server_ip)[2], + ((grub_uint8_t *) &bp->server_ip)[3]); + grub_print_error (); + } + + if (device && !*device) + { + *device = grub_xasprintf ("tftp,%d.%d.%d.%d", + ((grub_uint8_t *) &bp->server_ip)[0], + ((grub_uint8_t *) &bp->server_ip)[1], + ((grub_uint8_t *) &bp->server_ip)[2], + ((grub_uint8_t *) &bp->server_ip)[3]); + grub_print_error (); + } + if (size > OFFSET_OF (boot_file, bp) && path) + { + *path = grub_strndup (bp->boot_file, sizeof (bp->boot_file)); + grub_print_error (); + if (*path) + { + char *slash; + slash = grub_strrchr (*path, '/'); + if (slash) + *slash = 0; + else + **path = 0; + } + } + if (size > OFFSET_OF (vendor, bp)) + parse_dhcp_vendor (name, &bp->vendor, size - OFFSET_OF (vendor, bp)); + + inter->dhcp_ack = grub_malloc (size); + if (inter->dhcp_ack) + { + grub_memcpy (inter->dhcp_ack, bp, size); + inter->dhcp_acklen = size; + } + else + grub_errno = GRUB_ERR_NONE; + + return inter; +} + +void +grub_net_process_dhcp (struct grub_net_buff *nb, + struct grub_net_card *card) +{ + char *name; + struct grub_net_network_level_interface *inf; + + name = grub_xasprintf ("%s:dhcp", card->name); + if (!name) + { + grub_print_error (); + return; + } + grub_net_configure_by_dhcp_ack (name, card, + 0, (const struct grub_net_bootp_packet *) nb->data, + (nb->tail - nb->data), 0, 0, 0); + grub_free (name); + if (grub_errno) + grub_print_error (); + else + { + FOR_NET_NETWORK_LEVEL_INTERFACES(inf) + if (grub_memcmp (inf->name, card->name, grub_strlen (card->name)) == 0 + && grub_memcmp (inf->name + grub_strlen (card->name), + ":dhcp_tmp", sizeof (":dhcp_tmp") - 1) == 0) + { + grub_net_network_level_interface_unregister (inf); + break; + } + } +} + +static char +hexdigit (grub_uint8_t val) +{ + if (val < 10) + return val + '0'; + return val + 'a' - 10; +} + +static grub_err_t +grub_cmd_dhcpopt (struct grub_command *cmd __attribute__ ((unused)), + int argc, char **args) +{ + struct grub_net_network_level_interface *inter; + int num; + grub_uint8_t *ptr; + grub_uint8_t taglength; + + if (argc < 4) + return grub_error (GRUB_ERR_BAD_ARGUMENT, "4 arguments expected"); + + FOR_NET_NETWORK_LEVEL_INTERFACES (inter) + if (grub_strcmp (inter->name, args[1]) == 0) + break; + + if (!inter) + return grub_error (GRUB_ERR_BAD_ARGUMENT, + N_("unrecognised interface %s"), args[1]); + + if (!inter->dhcp_ack) + return grub_error (GRUB_ERR_IO, N_("no DHCP info found")); + + if (inter->dhcp_acklen <= OFFSET_OF (vendor, inter->dhcp_ack)) + return grub_error (GRUB_ERR_IO, N_("no DHCP options found")); + + num = grub_strtoul (args[2], 0, 0); + if (grub_errno) + return grub_errno; + + ptr = inter->dhcp_ack->vendor; + + if (ptr[0] != GRUB_NET_BOOTP_RFC1048_MAGIC_0 + || ptr[1] != GRUB_NET_BOOTP_RFC1048_MAGIC_1 + || ptr[2] != GRUB_NET_BOOTP_RFC1048_MAGIC_2 + || ptr[3] != GRUB_NET_BOOTP_RFC1048_MAGIC_3) + return grub_error (GRUB_ERR_IO, N_("no DHCP options found")); + ptr = ptr + sizeof (grub_uint32_t); + while (1) + { + grub_uint8_t tagtype; + + if (ptr >= ((grub_uint8_t *) inter->dhcp_ack) + inter->dhcp_acklen) + return grub_error (GRUB_ERR_IO, N_("no DHCP option %d found"), num); + + tagtype = *ptr++; + + /* Pad tag. */ + if (tagtype == 0) + continue; + + /* End tag. */ + if (tagtype == 0xff) + return grub_error (GRUB_ERR_IO, N_("no DHCP option %d found"), num); + + taglength = *ptr++; + + if (tagtype == num) + break; + ptr += taglength; + } + + if (grub_strcmp (args[3], "string") == 0) + { + char *val = grub_malloc (taglength + 1); + if (!val) + return grub_errno; + grub_memcpy (val, ptr, taglength); + val[taglength] = 0; + if (args[0][0] == '-' && args[0][1] == 0) + grub_printf ("%s\n", val); + else + return grub_env_set (args[0], val); + return GRUB_ERR_NONE; + } + + if (grub_strcmp (args[3], "number") == 0) + { + grub_uint64_t val = 0; + int i; + for (i = 0; i < taglength; i++) + val = (val << 8) | ptr[i]; + if (args[0][0] == '-' && args[0][1] == 0) + grub_printf ("%llu\n", (unsigned long long) val); + else + { + char valn[64]; + grub_printf (valn, sizeof (valn), "%lld\n", (unsigned long long) val); + return grub_env_set (args[0], valn); + } + return GRUB_ERR_NONE; + } + + if (grub_strcmp (args[3], "hex") == 0) + { + char *val = grub_malloc (2 * taglength + 1); + int i; + if (!val) + return grub_errno; + for (i = 0; i < taglength; i++) + { + val[2 * i] = hexdigit (ptr[i] >> 4); + val[2 * i + 1] = hexdigit (ptr[i] & 0xf); + } + val[2 * taglength] = 0; + if (args[0][0] == '-' && args[0][1] == 0) + grub_printf ("%s\n", val); + else + return grub_env_set (args[0], val); + return GRUB_ERR_NONE; + } + + return grub_error (GRUB_ERR_BAD_ARGUMENT, + "unrecognised format specification %s", args[3]); +} + +static grub_err_t +grub_cmd_bootp (struct grub_command *cmd __attribute__ ((unused)), + int argc, char **args) +{ + struct grub_net_card *card; + struct grub_net_network_level_interface *ifaces; + grub_size_t ncards = 0; + unsigned j = 0; + int interval; + grub_err_t err; + + FOR_NET_CARDS (card) + { + if (argc > 0 && grub_strcmp (card->name, args[0]) != 0) + continue; + ncards++; + } + + ifaces = grub_zalloc (ncards * sizeof (ifaces[0])); + if (!ifaces) + return grub_errno; + + j = 0; + FOR_NET_CARDS (card) + { + if (argc > 0 && grub_strcmp (card->name, args[0]) != 0) + continue; + ifaces[j].card = card; + ifaces[j].next = &ifaces[j+1]; + if (j) + ifaces[j].prev = &ifaces[j-1].next; + ifaces[j].name = grub_xasprintf ("%s:dhcp_tmp", card->name); + card->num_ifaces++; + if (!ifaces[j].name) + { + unsigned i; + for (i = 0; i < j; i++) + grub_free (ifaces[i].name); + grub_free (ifaces); + return grub_errno; + } + ifaces[j].address.type = GRUB_NET_NETWORK_LEVEL_PROTOCOL_DHCP_RECV; + grub_memcpy (&ifaces[j].hwaddress, &card->default_address, + sizeof (ifaces[j].hwaddress)); + j++; + } + ifaces[ncards - 1].next = grub_net_network_level_interfaces; + if (grub_net_network_level_interfaces) + grub_net_network_level_interfaces->prev = & ifaces[ncards - 1].next; + grub_net_network_level_interfaces = &ifaces[0]; + ifaces[0].prev = &grub_net_network_level_interfaces; + for (interval = 200; interval < 10000; interval *= 2) + { + int done = 0; + for (j = 0; j < ncards; j++) + { + struct grub_net_bootp_packet *pack; + struct grub_datetime date; + grub_int32_t t; + struct grub_net_buff *nb; + struct udphdr *udph; + grub_net_network_level_address_t target; + + if (!ifaces[j].prev) + continue; + nb = grub_netbuff_alloc (sizeof (*pack)); + if (!nb) + return grub_errno; + err = grub_netbuff_reserve (nb, sizeof (*pack) + 64 + 128); + if (err) + return err; + err = grub_netbuff_push (nb, sizeof (*pack) + 64); + if (err) + return err; + pack = (void *) nb->data; + done = 1; + grub_memset (pack, 0, sizeof (*pack) + 64); + pack->opcode = 1; + pack->hw_type = 1; + pack->hw_len = 6; + err = grub_get_datetime (&date); + if (err || !grub_datetime2unixtime (&date, &t)) + { + grub_errno = GRUB_ERR_NONE; + t = 0; + } + pack->ident = grub_cpu_to_be32 (t); + pack->seconds = 0;//grub_cpu_to_be16 (t); + + grub_memcpy (&pack->mac_addr, &ifaces[j].hwaddress.mac, 6); + + grub_netbuff_push (nb, sizeof (*udph)); + + udph = (struct udphdr *) nb->data; + udph->src = grub_cpu_to_be16 (68); + udph->dst = grub_cpu_to_be16 (67); + udph->chksum = 0; + udph->len = grub_cpu_to_be16 (nb->tail - nb->data); + + target.type = GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4; + target.ipv4 = 0xffffffff; + + err = grub_net_send_ip_packet (&ifaces[j], &target, nb); + if (err) + return err; + } + if (!done) + break; + grub_net_poll_cards (interval); + } + + err = GRUB_ERR_NONE; + for (j = 0; j < ncards; j++) + { + if (!ifaces[j].prev) + continue; + grub_error_push (); + grub_net_network_level_interface_unregister (&ifaces[j]); + err = grub_error (GRUB_ERR_FILE_NOT_FOUND, "couldn't configure %s", + ifaces[j].card->name); + } + + return err; +} + +static grub_command_t cmd_dhcp, cmd_getdhcp, cmd_bootp; + +void +grub_bootp_init (void) +{ + cmd_bootp = grub_register_command ("net_bootp", grub_cmd_bootp, + "[CARD]", + N_("perform a bootp autoconfiguration")); + cmd_dhcp = grub_register_command ("net_dhcp", grub_cmd_bootp, + "[CARD]", + N_("perform a bootp autoconfiguration")); + cmd_getdhcp = grub_register_command ("net_get_dhcp_option", grub_cmd_dhcpopt, + N_("VAR INTERFACE NUMBER DESCRIPTION"), + N_("retrieve DHCP option and save it into VAR. If VAR is - then print the value.")); +} + +void +grub_bootp_fini (void) +{ + grub_unregister_command (cmd_getdhcp); + grub_unregister_command (cmd_dhcp); + grub_unregister_command (cmd_bootp); +} From c97dbbf2f28c7d3026e9109790167b646d76ac5e Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 6 Jul 2011 17:40:24 +0200 Subject: [PATCH 737/869] Fix a memory leak --- grub-core/disk/ieee1275/ofdisk.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/grub-core/disk/ieee1275/ofdisk.c b/grub-core/disk/ieee1275/ofdisk.c index 0a935d5c2..7868b14b1 100644 --- a/grub-core/disk/ieee1275/ofdisk.c +++ b/grub-core/disk/ieee1275/ofdisk.c @@ -243,14 +243,24 @@ grub_ofdisk_open (const char *name, grub_disk_t disk) grub_dprintf ("disk", "Opening `%s'.\n", devpath); if (grub_ieee1275_finddevice (devpath, &dev)) - return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "can't read device properties"); + { + grub_free (devpath); + return grub_error (GRUB_ERR_UNKNOWN_DEVICE, + "can't read device properties"); + } if (grub_ieee1275_get_property (dev, "device_type", prop, sizeof (prop), &actual)) - return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "can't read the device type"); + { + grub_free (devpath); + return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "can't read the device type"); + } if (grub_strcmp (prop, "block")) - return grub_error (GRUB_ERR_BAD_DEVICE, "not a block device"); + { + grub_free (devpath); + return grub_error (GRUB_ERR_BAD_DEVICE, "not a block device"); + } /* XXX: There is no property to read the number of blocks. There should be a property `#blocks', but it is not there. Perhaps it From c2aa00f059ab09bd427703c874d8ff7936ba3d39 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 6 Jul 2011 17:40:36 +0200 Subject: [PATCH 738/869] Fix a memory leak --- grub-core/kern/dl.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/grub-core/kern/dl.c b/grub-core/kern/dl.c index 5f214e378..1841bf1f5 100644 --- a/grub-core/kern/dl.c +++ b/grub-core/kern/dl.c @@ -688,11 +688,9 @@ grub_dl_load_file (const char *filename) grub_file_close (file); mod = grub_dl_load_core (core, size); + grub_free (core); if (! mod) - { - grub_free (core); - return 0; - } + return 0; mod->ref_count--; return mod; From f872d4744e66dde8cccbc9a189ac39e432851e92 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 6 Jul 2011 17:40:56 +0200 Subject: [PATCH 739/869] Fix compilation error --- grub-core/kern/ieee1275/openfw.c | 1 - 1 file changed, 1 deletion(-) diff --git a/grub-core/kern/ieee1275/openfw.c b/grub-core/kern/ieee1275/openfw.c index 2cecd8c7f..4e705a4d8 100644 --- a/grub-core/kern/ieee1275/openfw.c +++ b/grub-core/kern/ieee1275/openfw.c @@ -23,7 +23,6 @@ #include #include #include -#include enum grub_ieee1275_parse_type { From e1a0e1b42841f02481f8051cccf9669aa5a231a4 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 6 Jul 2011 17:41:19 +0200 Subject: [PATCH 740/869] Fix the usage of unsupported %zx --- grub-core/kern/mm.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/grub-core/kern/mm.c b/grub-core/kern/mm.c index d54f3f240..ee4d58d81 100644 --- a/grub-core/kern/mm.c +++ b/grub-core/kern/mm.c @@ -515,7 +515,7 @@ grub_debug_malloc (const char *file, int line, grub_size_t size) void *ptr; if (grub_mm_debug) - grub_printf ("%s:%d: malloc (0x%zx) = ", file, line, size); + grub_printf ("%s:%d: malloc (0x%" PRIxGRUB_SIZE ") = ", file, line, size); ptr = grub_malloc (size); if (grub_mm_debug) grub_printf ("%p\n", ptr); @@ -528,7 +528,7 @@ grub_debug_zalloc (const char *file, int line, grub_size_t size) void *ptr; if (grub_mm_debug) - grub_printf ("%s:%d: zalloc (0x%zx) = ", file, line, size); + grub_printf ("%s:%d: zalloc (0x%" PRIxGRUB_SIZE ") = ", file, line, size); ptr = grub_zalloc (size); if (grub_mm_debug) grub_printf ("%p\n", ptr); @@ -547,7 +547,7 @@ void * grub_debug_realloc (const char *file, int line, void *ptr, grub_size_t size) { if (grub_mm_debug) - grub_printf ("%s:%d: realloc (%p, 0x%zx) = ", file, line, ptr, size); + grub_printf ("%s:%d: realloc (%p, 0x%" PRIxGRUB_SIZE ") = ", file, line, ptr, size); ptr = grub_realloc (ptr, size); if (grub_mm_debug) grub_printf ("%p\n", ptr); @@ -561,8 +561,8 @@ grub_debug_memalign (const char *file, int line, grub_size_t align, void *ptr; if (grub_mm_debug) - grub_printf ("%s:%d: memalign (0x%zx, 0x%zx) = ", - file, line, align, size); + grub_printf ("%s:%d: memalign (0x%" PRIxGRUB_SIZE ", 0x%" PRIxGRUB_SIZE + ") = ", file, line, align, size); ptr = grub_memalign (align, size); if (grub_mm_debug) grub_printf ("%p\n", ptr); From c3bf5267b016238d09455c843d425e7a9ce30e83 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 6 Jul 2011 17:41:49 +0200 Subject: [PATCH 741/869] Fix a memory leak --- grub-core/net/bootp.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/grub-core/net/bootp.c b/grub-core/net/bootp.c index a1aaf402f..84bdc04d7 100644 --- a/grub-core/net/bootp.c +++ b/grub-core/net/bootp.c @@ -444,13 +444,22 @@ grub_cmd_bootp (struct grub_command *cmd __attribute__ ((unused)), continue; nb = grub_netbuff_alloc (sizeof (*pack)); if (!nb) - return grub_errno; + { + grub_netbuff_free (nb); + return grub_errno; + } err = grub_netbuff_reserve (nb, sizeof (*pack) + 64 + 128); if (err) - return err; + { + grub_netbuff_free (nb); + return err; + } err = grub_netbuff_push (nb, sizeof (*pack) + 64); if (err) - return err; + { + grub_netbuff_free (nb); + return err; + } pack = (void *) nb->data; done = 1; grub_memset (pack, 0, sizeof (*pack) + 64); @@ -480,6 +489,7 @@ grub_cmd_bootp (struct grub_command *cmd __attribute__ ((unused)), target.ipv4 = 0xffffffff; err = grub_net_send_ip_packet (&ifaces[j], &target, nb); + grub_netbuff_free (nb); if (err) return err; } @@ -491,6 +501,7 @@ grub_cmd_bootp (struct grub_command *cmd __attribute__ ((unused)), err = GRUB_ERR_NONE; for (j = 0; j < ncards; j++) { + grub_free (ifaces[j].name); if (!ifaces[j].prev) continue; grub_error_push (); @@ -499,6 +510,7 @@ grub_cmd_bootp (struct grub_command *cmd __attribute__ ((unused)), ifaces[j].card->name); } + grub_free (ifaces); return err; } From d1831ca48a8ee052599f129c36e346336fae6b17 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 6 Jul 2011 18:21:07 +0200 Subject: [PATCH 742/869] Limit idle polling frequency --- grub-core/net/drivers/ieee1275/ofnet.c | 1 + grub-core/net/net.c | 10 +++++++++- include/grub/net.h | 2 ++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/grub-core/net/drivers/ieee1275/ofnet.c b/grub-core/net/drivers/ieee1275/ofnet.c index cc29d0987..20d45ee3d 100644 --- a/grub-core/net/drivers/ieee1275/ofnet.c +++ b/grub-core/net/drivers/ieee1275/ofnet.c @@ -253,6 +253,7 @@ grub_ofnet_findcards (void) card->flags = 0; shortname = find_alias (alias->path); card->name = grub_xasprintf ("ofnet_%s", shortname ? : alias->path); + card->idle_poll_delay_ms = 1; grub_free (shortname); card->driver = &ofdriver; diff --git a/grub-core/net/net.c b/grub-core/net/net.c index bc16fbde5..641aebd64 100644 --- a/grub-core/net/net.c +++ b/grub-core/net/net.c @@ -768,6 +768,7 @@ receive_packets (struct grub_net_card *card) if (!nb) { grub_print_error (); + card->last_poll = grub_get_time_ms (); return; } @@ -775,6 +776,7 @@ receive_packets (struct grub_net_card *card) if (actual < 0) { grub_netbuff_free (nb); + card->last_poll = grub_get_time_ms (); break; } grub_net_recv_ethernet_packet (nb, card); @@ -800,7 +802,13 @@ grub_net_poll_cards_idle_real (void) { struct grub_net_card *card; FOR_NET_CARDS (card) - receive_packets (card); + { + grub_uint64_t ctime = grub_get_time_ms (); + + if (ctime < card->last_poll + || ctime >= card->last_poll + card->idle_poll_delay_ms) + receive_packets (card); + } } /* Read from the packets list*/ diff --git a/include/grub/net.h b/include/grub/net.h index 92e637d89..45d08f3f5 100644 --- a/include/grub/net.h +++ b/include/grub/net.h @@ -95,6 +95,8 @@ struct grub_net_card grub_net_card_flags_t flags; int num_ifaces; int opened; + unsigned idle_poll_delay_ms; + grub_uint64_t last_poll; union { #ifdef GRUB_MACHINE_EFI From 697ffdc55b6fcb150e19ad5f746142edbcf5e372 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 6 Jul 2011 18:21:24 +0200 Subject: [PATCH 743/869] Fix a memory leak --- grub-core/net/net.c | 1 + 1 file changed, 1 insertion(+) diff --git a/grub-core/net/net.c b/grub-core/net/net.c index 641aebd64..0f8a60413 100644 --- a/grub-core/net/net.c +++ b/grub-core/net/net.c @@ -725,6 +725,7 @@ grub_net_fs_open (struct grub_file *file_out, const char *name) } grub_memcpy (file_out, bufio, sizeof (struct grub_file)); + grub_free (bufio); return GRUB_ERR_NONE; } From 1c358e5948c43ac7684c2067c9aa035dd3493778 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 6 Jul 2011 22:15:58 +0200 Subject: [PATCH 744/869] * po/POTFILES.in: Regenerate. --- ChangeLog | 4 + po/POTFILES.in | 342 ++++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 328 insertions(+), 18 deletions(-) diff --git a/ChangeLog b/ChangeLog index 110a980f0..e6aace254 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2011-07-06 Vladimir Serbinenko + + * po/POTFILES.in: Regenerate. + 2011-07-06 Vladimir Serbinenko Unify sparc init with other ieee1275. diff --git a/po/POTFILES.in b/po/POTFILES.in index 8329fdf0a..2bf4aa10c 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -1,5 +1,22 @@ -# List of files which contain translatable strings. +grub-core/boot/decompressor/minilib.c +grub-core/boot/decompressor/none.c +grub-core/boot/decompressor/xz.c +grub-core/bus/bonito.c +grub-core/bus/cs5536.c +grub-core/bus/emu/pci.c +grub-core/bus/pci.c +grub-core/bus/usb/emu/usb.c +grub-core/bus/usb/ohci.c +grub-core/bus/usb/serial/common.c +grub-core/bus/usb/serial/ftdi.c +grub-core/bus/usb/serial/pl2303.c +grub-core/bus/usb/uhci.c +grub-core/bus/usb/usb.c +grub-core/bus/usb/usbhub.c +grub-core/bus/usb/usbtrans.c grub-core/commands/acpi.c +grub-core/commands/acpihalt.c +grub-core/commands/arc/lsdev.c grub-core/commands/blocklist.c grub-core/commands/boot.c grub-core/commands/cat.c @@ -7,33 +24,41 @@ grub-core/commands/cmp.c grub-core/commands/configfile.c grub-core/commands/date.c grub-core/commands/echo.c +grub-core/commands/efi/acpi.c grub-core/commands/efi/fixvideo.c grub-core/commands/efi/loadbios.c +grub-core/commands/efi/lsefimmap.c +grub-core/commands/efi/lsefisystab.c +grub-core/commands/efi/lssal.c +grub-core/commands/extcmd.c grub-core/commands/gptsync.c grub-core/commands/halt.c grub-core/commands/hashsum.c grub-core/commands/hdparm.c grub-core/commands/help.c grub-core/commands/hexdump.c +grub-core/commands/i386/cmostest.c grub-core/commands/i386/cpuid.c +grub-core/commands/i386/pc/acpi.c grub-core/commands/i386/pc/drivemap.c grub-core/commands/i386/pc/halt.c grub-core/commands/i386/pc/lsapm.c grub-core/commands/i386/pc/play.c -grub-core/commands/i386/pc/pxecmd.c +grub-core/commands/i386/pc/sendkey.c grub-core/commands/ieee1275/suspend.c grub-core/commands/iorw.c grub-core/commands/keylayouts.c grub-core/commands/keystatus.c grub-core/commands/legacycfg.c grub-core/commands/loadenv.c -grub-core/commands/ls.c grub-core/commands/lsacpi.c +grub-core/commands/ls.c grub-core/commands/lsmmap.c grub-core/commands/lspci.c grub-core/commands/memrw.c grub-core/commands/menuentry.c grub-core/commands/minicmd.c +grub-core/commands/mips/loongson/lsspd.c grub-core/commands/parttool.c grub-core/commands/password.c grub-core/commands/password_pbkdf2.c @@ -51,67 +76,348 @@ grub-core/commands/sleep.c grub-core/commands/terminal.c grub-core/commands/test.c grub-core/commands/testload.c +grub-core/commands/time.c grub-core/commands/true.c grub-core/commands/usbtest.c grub-core/commands/videoinfo.c grub-core/commands/videotest.c +grub-core/commands/wildcard.c grub-core/commands/xnu_uuid.c - +grub-core/disk/ahci.c +grub-core/disk/arc/arcdisk.c +grub-core/disk/ata.c +grub-core/disk/dmraid_nvidia.c +grub-core/disk/efi/efidisk.c +grub-core/disk/host.c +grub-core/disk/i386/pc/biosdisk.c +grub-core/disk/ieee1275/nand.c +grub-core/disk/ieee1275/ofdisk.c grub-core/disk/loopback.c - +grub-core/disk/lvm.c +grub-core/disk/mdraid1x_linux.c +grub-core/disk/mdraid_linux.c +grub-core/disk/memdisk.c +grub-core/disk/pata.c +grub-core/disk/raid5_recover.c +grub-core/disk/raid6_recover.c +grub-core/disk/raid.c +grub-core/disk/scsi.c +grub-core/disk/usbms.c +grub-core/efiemu/i386/coredetect.c +grub-core/efiemu/i386/loadcore32.c +grub-core/efiemu/i386/loadcore64.c +grub-core/efiemu/i386/nocfgtables.c +grub-core/efiemu/i386/pc/cfgtables.c +grub-core/efiemu/loadcore32.c +grub-core/efiemu/loadcore64.c +grub-core/efiemu/loadcore.c +grub-core/efiemu/loadcore_common.c grub-core/efiemu/main.c - +grub-core/efiemu/mm.c +grub-core/efiemu/pnvram.c +grub-core/efiemu/prepare32.c +grub-core/efiemu/prepare64.c +grub-core/efiemu/prepare.c +grub-core/efiemu/runtime/efiemu.c +grub-core/efiemu/symbols.c +grub-core/font/font.c grub-core/font/font_cmd.c - +grub-core/fs/affs.c +grub-core/fs/afs_be.c +grub-core/fs/afs.c +grub-core/fs/befs_be.c +grub-core/fs/befs.c +grub-core/fs/btrfs.c +grub-core/fs/cpio.c +grub-core/fs/ext2.c +grub-core/fs/fat.c +grub-core/fs/fshelp.c +grub-core/fs/hfs.c +grub-core/fs/hfsplus.c +grub-core/fs/iso9660.c +grub-core/fs/jfs.c +grub-core/fs/minix2.c +grub-core/fs/minix3.c +grub-core/fs/minix.c +grub-core/fs/nilfs2.c +grub-core/fs/ntfs.c +grub-core/fs/ntfscomp.c +grub-core/fs/reiserfs.c +grub-core/fs/romfs.c +grub-core/fs/sfs.c +grub-core/fs/squash4.c +grub-core/fs/tar.c +grub-core/fs/udf.c +grub-core/fs/ufs2.c +grub-core/fs/ufs.c +grub-core/fs/xfs.c +grub-core/fs/zfs/zfs.c +grub-core/fs/zfs/zfs_fletcher.c +grub-core/fs/zfs/zfsinfo.c +grub-core/fs/zfs/zfs_lzjb.c +grub-core/fs/zfs/zfs_sha256.c +grub-core/gentrigtables.c grub-core/gettext/gettext.c - +grub-core/gfxmenu/font.c +grub-core/gfxmenu/gfxmenu.c +grub-core/gfxmenu/gui_box.c +grub-core/gfxmenu/gui_canvas.c +grub-core/gfxmenu/gui_circular_progress.c +grub-core/gfxmenu/gui_image.c +grub-core/gfxmenu/gui_label.c +grub-core/gfxmenu/gui_list.c grub-core/gfxmenu/gui_progress_bar.c - +grub-core/gfxmenu/gui_string_util.c +grub-core/gfxmenu/gui_util.c +grub-core/gfxmenu/icon_manager.c +grub-core/gfxmenu/model.c +grub-core/gfxmenu/theme_loader.c +grub-core/gfxmenu/view.c +grub-core/gfxmenu/widget-box.c grub-core/hello/hello.c - +grub-core/hook/datehook.c +grub-core/io/bufio.c +grub-core/io/gzio.c +grub-core/io/xzio.c +grub-core/kern/command.c grub-core/kern/corecmd.c +grub-core/kern/device.c +grub-core/kern/disk.c +grub-core/kern/dl.c +grub-core/kern/efi/efi.c +grub-core/kern/efi/init.c +grub-core/kern/efi/mm.c +grub-core/kern/elf.c +grub-core/kern/emu/cache.c +grub-core/kern/emu/console.c +grub-core/kern/emu/full.c +grub-core/kern/emu/getroot.c grub-core/kern/emu/hostdisk.c +grub-core/kern/emu/hostfs.c +grub-core/kern/emu/lite.c +grub-core/kern/emu/main.c grub-core/kern/emu/misc.c +grub-core/kern/emu/mm.c +grub-core/kern/emu/time.c +grub-core/kern/env.c grub-core/kern/err.c - +grub-core/kern/file.c +grub-core/kern/fs.c +grub-core/kern/generic/millisleep.c +grub-core/kern/generic/rtc_get_time_ms.c +grub-core/kern/i386/coreboot/init.c +grub-core/kern/i386/coreboot/mmap.c +grub-core/kern/i386/dl.c +grub-core/kern/i386/efi/init.c +grub-core/kern/i386/multiboot_mmap.c +grub-core/kern/i386/pc/init.c +grub-core/kern/i386/pc/mmap.c +grub-core/kern/i386/pit.c +grub-core/kern/i386/qemu/mmap.c +grub-core/kern/i386/tsc.c +grub-core/kern/ia64/dl.c +grub-core/kern/ia64/dl_helper.c +grub-core/kern/ia64/efi/init.c +grub-core/kern/ieee1275/cmain.c +grub-core/kern/ieee1275/ieee1275.c +grub-core/kern/ieee1275/init.c +grub-core/kern/ieee1275/mmap.c +grub-core/kern/ieee1275/openfw.c +grub-core/kern/list.c +grub-core/kern/main.c +grub-core/kern/mips/arc/init.c +grub-core/kern/mips/dl.c +grub-core/kern/mips/init.c +grub-core/kern/mips/loongson/init.c +grub-core/kern/mips/qemu_mips/init.c +grub-core/kern/misc.c +grub-core/kern/mm.c +grub-core/kern/parser.c +grub-core/kern/partition.c +grub-core/kern/powerpc/dl.c +grub-core/kern/rescue_parser.c +grub-core/kern/rescue_reader.c +grub-core/kern/sparc64/dl.c +grub-core/kern/sparc64/ieee1275/ieee1275.c +grub-core/kern/term.c +grub-core/kern/time.c +grub-core/kern/vga_init.c +grub-core/kern/x86_64/dl.c +grub-core/lib/arc/datetime.c grub-core/lib/arg.c - +grub-core/lib/cmdline.c +grub-core/lib/cmos_datetime.c +grub-core/lib/crc.c +grub-core/lib/crypto.c +grub-core/lib/efi/datetime.c +grub-core/lib/efi/halt.c +grub-core/lib/efi/relocator.c +grub-core/lib/emu/halt.c +grub-core/lib/envblk.c +grub-core/lib/hexdump.c +grub-core/lib/i386/halt.c +grub-core/lib/i386/pc/biosnum.c +grub-core/lib/i386/pc/vesa_modes_table.c +grub-core/lib/i386/relocator.c +grub-core/lib/ieee1275/cmos.c +grub-core/lib/ieee1275/datetime.c +grub-core/lib/ieee1275/halt.c +grub-core/lib/ieee1275/relocator.c +grub-core/lib/legacy_parse.c +grub-core/lib/LzFind.c +grub-core/lib/LzmaDec.c +grub-core/lib/LzmaEnc.c +grub-core/lib/mips/relocator.c +grub-core/lib/pbkdf2.c +grub-core/lib/powerpc/relocator.c +grub-core/lib/reed_solomon.c +grub-core/lib/relocator.c +grub-core/lib/xzembed/xz_dec_bcj.c +grub-core/lib/xzembed/xz_dec_lzma2.c +grub-core/lib/xzembed/xz_dec_stream.c +grub-core/loader/aout.c grub-core/loader/efi/appleloader.c grub-core/loader/efi/chainloader.c +grub-core/loader/i386/bsd32.c +grub-core/loader/i386/bsd64.c grub-core/loader/i386/bsd.c +grub-core/loader/i386/bsd_pagetable.c +grub-core/loader/i386/bsdXX.c +grub-core/loader/i386/coreboot/chainloader.c grub-core/loader/i386/linux.c +grub-core/loader/i386/multiboot_mbi.c grub-core/loader/i386/pc/chainloader.c +grub-core/loader/i386/pc/freedos.c grub-core/loader/i386/pc/linux.c grub-core/loader/i386/pc/ntldr.c grub-core/loader/i386/xnu.c +grub-core/loader/ia64/efi/linux.c +grub-core/loader/macho32.c +grub-core/loader/macho64.c +grub-core/loader/macho.c +grub-core/loader/machoXX.c grub-core/loader/mips/linux.c grub-core/loader/multiboot.c +grub-core/loader/multiboot_elfxx.c +grub-core/loader/multiboot_mbi2.c grub-core/loader/powerpc/ieee1275/linux.c grub-core/loader/sparc64/ieee1275/linux.c grub-core/loader/xnu.c - +grub-core/loader/xnu_resume.c +grub-core/mmap/efi/mmap.c +grub-core/mmap/i386/mmap.c +grub-core/mmap/i386/pc/mmap.c +grub-core/mmap/i386/uppermem.c +grub-core/mmap/mips/uppermem.c grub-core/mmap/mmap.c - +grub-core/net/arp.c +grub-core/net/bootp.c +grub-core/net/drivers/efi/efinet.c +grub-core/net/drivers/emu/emunet.c +grub-core/net/drivers/i386/pc/pxe.c +grub-core/net/drivers/ieee1275/ofnet.c +grub-core/net/ethernet.c +grub-core/net/ip.c +grub-core/net/netbuff.c +grub-core/net/net.c +grub-core/net/tftp.c +grub-core/net/udp.c grub-core/normal/auth.c +grub-core/normal/autofs.c +grub-core/normal/charset.c grub-core/normal/cmdline.c grub-core/normal/color.c +grub-core/normal/completion.c grub-core/normal/context.c +grub-core/normal/crypto.c +grub-core/normal/datetime.c grub-core/normal/dyncmd.c grub-core/normal/main.c grub-core/normal/menu.c grub-core/normal/menu_entry.c grub-core/normal/menu_text.c grub-core/normal/misc.c - +grub-core/normal/term.c +grub-core/partmap/acorn.c +grub-core/partmap/amiga.c +grub-core/partmap/apple.c +grub-core/partmap/bsdlabel.c +grub-core/partmap/dvh.c +grub-core/partmap/gpt.c +grub-core/partmap/msdos.c +grub-core/partmap/sun.c +grub-core/partmap/sunpc.c +grub-core/parttool/msdospart.c +grub-core/script/argv.c +grub-core/script/execute.c +grub-core/script/function.c +grub-core/script/lexer.c grub-core/script/main.c - +grub-core/script/script.c +grub-core/term/arc/console.c +grub-core/term/at_keyboard.c +grub-core/term/efi/console.c grub-core/term/gfxterm.c +grub-core/term/i386/pc/console.c +grub-core/term/i386/pc/vga_text.c +grub-core/term/i386/vga_common.c +grub-core/term/ieee1275/ofconsole.c +grub-core/term/ns8250.c grub-core/term/serial.c grub-core/term/terminfo.c - +grub-core/term/tparm.c +grub-core/term/usb_keyboard.c +grub-core/tests/example_functional_test.c +grub-core/tests/lib/functional_test.c +grub-core/tests/lib/test.c grub-core/tests/test_blockarg.c - +grub-core/video/bitmap.c +grub-core/video/bitmap_scale.c +grub-core/video/bochs.c +grub-core/video/cirrus.c +grub-core/video/colors.c +grub-core/video/efi_gop.c +grub-core/video/efi_uga.c +grub-core/video/emu/sdl.c +grub-core/video/fb/fbblit.c +grub-core/video/fb/fbfill.c +grub-core/video/fb/fbutil.c +grub-core/video/fb/video_fb.c +grub-core/video/i386/pc/vbe.c +grub-core/video/i386/pc/vga.c +grub-core/video/ieee1275.c +grub-core/video/readers/jpeg.c +grub-core/video/readers/png.c +grub-core/video/readers/tga.c +grub-core/video/sis315_init.c +grub-core/video/sis315pro.c +grub-core/video/sm712.c +grub-core/video/sm712_init.c +grub-core/video/video.c +tests/example_unit_test.c +tests/lib/unit_test.c +util/bin2h.c +util/deviceiter.c +util/devicemap.c util/grub-editenv.c util/grub-fstest.c +util/grub-macho2img.c +util/grub-menulst2cfg.c +util/grub-mkdevicemap.c +util/grub-mkfont.c util/grub-mkimage.c +util/grub-mkimagexx.c +util/grub-mklayout.c +util/grub-mkpasswd-pbkdf2.c +util/grub-mkrelpath.c +util/grub-pe2elf.c +util/grub-probe.c +util/grub-script-check.c util/grub-setup.c +util/ieee1275/devicemap.c +util/ieee1275/grub-ofpathname.c +util/ieee1275/ofpath.c +util/lvm.c +util/misc.c +util/raid.c +util/resolve.c From 0044d1db2e43943112aac3f3482e97d66584e645 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Thu, 7 Jul 2011 21:46:25 +0200 Subject: [PATCH 745/869] Simplify disk opening --- grub-core/disk/arc/arcdisk.c | 6 +++++- grub-core/disk/ata.c | 3 +-- grub-core/disk/efi/efidisk.c | 3 +-- grub-core/disk/host.c | 3 +-- grub-core/disk/i386/pc/biosdisk.c | 3 +-- grub-core/disk/ieee1275/nand.c | 3 +-- grub-core/disk/ieee1275/ofdisk.c | 3 +-- grub-core/disk/loopback.c | 3 +-- grub-core/disk/lvm.c | 6 ++---- grub-core/disk/memdisk.c | 3 +-- grub-core/disk/raid.c | 4 ++-- grub-core/disk/scsi.c | 3 +-- grub-core/kern/disk.c | 28 +++++++++------------------- grub-core/kern/emu/hostdisk.c | 3 +-- include/grub/disk.h | 4 +--- 15 files changed, 29 insertions(+), 49 deletions(-) diff --git a/grub-core/disk/arc/arcdisk.c b/grub-core/disk/arc/arcdisk.c index 7dff30931..170bf521d 100644 --- a/grub-core/disk/arc/arcdisk.c +++ b/grub-core/disk/arc/arcdisk.c @@ -79,7 +79,8 @@ arcdisk_hash_add (char *devpath) static int -grub_arcdisk_iterate (int (*hook_in) (const char *name)) +grub_arcdisk_iterate (int (*hook_in) (const char *name), + grub_disk_pull_t pull) { auto int hook (const char *name, const struct grub_arc_component *comp); int hook (const char *name, const struct grub_arc_component *comp) @@ -90,6 +91,9 @@ grub_arcdisk_iterate (int (*hook_in) (const char *name)) return 0; return hook_in (name); } + if (pull != GRUB_DISK_PULL_NONE) + return 0; + return grub_arc_iterate_devs (hook, 1); } diff --git a/grub-core/disk/ata.c b/grub-core/disk/ata.c index 9a09ee158..8add7f4de 100644 --- a/grub-core/disk/ata.c +++ b/grub-core/disk/ata.c @@ -412,8 +412,7 @@ grub_ata_iterate (int (*hook_in) (const char *name), } static grub_err_t -grub_ata_open (const char *name, grub_disk_t disk, - grub_disk_pull_t pull __attribute__ ((unused))) +grub_ata_open (const char *name, grub_disk_t disk) { unsigned id, bus; struct grub_ata *ata; diff --git a/grub-core/disk/efi/efidisk.c b/grub-core/disk/efi/efidisk.c index 4ae1d7bb9..85969cc1d 100644 --- a/grub-core/disk/efi/efidisk.c +++ b/grub-core/disk/efi/efidisk.c @@ -454,8 +454,7 @@ get_device (struct grub_efidisk_data *devices, int num) } static grub_err_t -grub_efidisk_open (const char *name, struct grub_disk *disk, - grub_disk_pull_t pull __attribute__ ((unused))) +grub_efidisk_open (const char *name, struct grub_disk *disk) { int num; struct grub_efidisk_data *d = 0; diff --git a/grub-core/disk/host.c b/grub-core/disk/host.c index 5376cc6ce..5ee0d2e56 100644 --- a/grub-core/disk/host.c +++ b/grub-core/disk/host.c @@ -39,8 +39,7 @@ grub_host_iterate (int (*hook) (const char *name), } static grub_err_t -grub_host_open (const char *name, grub_disk_t disk, - grub_disk_pull_t pull __attribute__ ((unused))) +grub_host_open (const char *name, grub_disk_t disk) { if (grub_strcmp (name, "host")) return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "not a host disk"); diff --git a/grub-core/disk/i386/pc/biosdisk.c b/grub-core/disk/i386/pc/biosdisk.c index 1198d4305..e152b9d89 100644 --- a/grub-core/disk/i386/pc/biosdisk.c +++ b/grub-core/disk/i386/pc/biosdisk.c @@ -328,8 +328,7 @@ grub_biosdisk_iterate (int (*hook) (const char *name), } static grub_err_t -grub_biosdisk_open (const char *name, grub_disk_t disk, - grub_disk_pull_t pull __attribute__ ((unused))) +grub_biosdisk_open (const char *name, grub_disk_t disk) { grub_uint64_t total_sectors = 0; int drive; diff --git a/grub-core/disk/ieee1275/nand.c b/grub-core/disk/ieee1275/nand.c index 4be5b5641..94d62bc4f 100644 --- a/grub-core/disk/ieee1275/nand.c +++ b/grub-core/disk/ieee1275/nand.c @@ -58,8 +58,7 @@ grub_nand_read (grub_disk_t disk, grub_disk_addr_t sector, grub_size_t size, char *buf); static grub_err_t -grub_nand_open (const char *name, grub_disk_t disk, - grub_disk_pull_t pull __attribute__ ((unused))) +grub_nand_open (const char *name, grub_disk_t disk) { grub_ieee1275_ihandle_t dev_ihandle = 0; struct grub_nand_data *data = 0; diff --git a/grub-core/disk/ieee1275/ofdisk.c b/grub-core/disk/ieee1275/ofdisk.c index 7b7db3a08..2cd43d80a 100644 --- a/grub-core/disk/ieee1275/ofdisk.c +++ b/grub-core/disk/ieee1275/ofdisk.c @@ -233,8 +233,7 @@ compute_dev_path (const char *name) } static grub_err_t -grub_ofdisk_open (const char *name, grub_disk_t disk, - grub_disk_pull_t pull __attribute__ ((unused))) +grub_ofdisk_open (const char *name, grub_disk_t disk) { grub_ieee1275_phandle_t dev; char *devpath; diff --git a/grub-core/disk/loopback.c b/grub-core/disk/loopback.c index 21345af57..dca83b7c6 100644 --- a/grub-core/disk/loopback.c +++ b/grub-core/disk/loopback.c @@ -148,8 +148,7 @@ grub_loopback_iterate (int (*hook) (const char *name), } static grub_err_t -grub_loopback_open (const char *name, grub_disk_t disk, - grub_disk_pull_t pull __attribute__ ((unused))) +grub_loopback_open (const char *name, grub_disk_t disk) { struct grub_loopback *dev; diff --git a/grub-core/disk/lvm.c b/grub-core/disk/lvm.c index 9e304c001..06e9f6d6a 100644 --- a/grub-core/disk/lvm.c +++ b/grub-core/disk/lvm.c @@ -181,8 +181,7 @@ find_lv (const char *name) static const char *scan_for = NULL; static grub_err_t -grub_lvm_open (const char *name, grub_disk_t disk, - grub_disk_pull_t pull) +grub_lvm_open (const char *name, grub_disk_t disk) { struct grub_lvm_lv *lv = NULL; int explicit = 0; @@ -192,8 +191,7 @@ grub_lvm_open (const char *name, grub_disk_t disk, lv = find_lv (name); - if (! lv && !scan_depth && - pull == (explicit ? GRUB_DISK_PULL_RESCAN : GRUB_DISK_PULL_RESCAN_UNTYPED)) + if (! lv && !scan_depth && explicit) { scan_for = name; scan_depth++; diff --git a/grub-core/disk/memdisk.c b/grub-core/disk/memdisk.c index 775234055..ed570c6a0 100644 --- a/grub-core/disk/memdisk.c +++ b/grub-core/disk/memdisk.c @@ -40,8 +40,7 @@ grub_memdisk_iterate (int (*hook) (const char *name), } static grub_err_t -grub_memdisk_open (const char *name, grub_disk_t disk, - grub_disk_pull_t pull __attribute__ ((unused))) +grub_memdisk_open (const char *name, grub_disk_t disk) { if (grub_strcmp (name, "memdisk")) return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "not a memdisk"); diff --git a/grub-core/disk/raid.c b/grub-core/disk/raid.c index a7d36bfb2..5d8326daf 100644 --- a/grub-core/disk/raid.c +++ b/grub-core/disk/raid.c @@ -257,7 +257,7 @@ find_array (const char *name) } static grub_err_t -grub_raid_open (const char *name, grub_disk_t disk, grub_disk_pull_t pull) +grub_raid_open (const char *name, grub_disk_t disk) { struct grub_raid_array *array; unsigned n; @@ -268,7 +268,7 @@ grub_raid_open (const char *name, grub_disk_t disk, grub_disk_pull_t pull) array = find_array (name); - if (! array && pull == GRUB_DISK_PULL_RESCAN) + if (! array) { scan_devices (name); if (grub_errno) diff --git a/grub-core/disk/scsi.c b/grub-core/disk/scsi.c index 5ab5177e9..610cc4dc5 100644 --- a/grub-core/disk/scsi.c +++ b/grub-core/disk/scsi.c @@ -371,8 +371,7 @@ grub_scsi_iterate (int (*hook) (const char *name), } static grub_err_t -grub_scsi_open (const char *name, grub_disk_t disk, - grub_disk_pull_t pull __attribute__ ((unused))) +grub_scsi_open (const char *name, grub_disk_t disk) { grub_scsi_dev_t p; grub_scsi_t scsi; diff --git a/grub-core/kern/disk.c b/grub-core/kern/disk.c index 022157434..5584030bd 100644 --- a/grub-core/kern/disk.c +++ b/grub-core/kern/disk.c @@ -206,13 +206,9 @@ grub_disk_dev_iterate (int (*hook) (const char *name)) grub_disk_pull_t pull; for (pull = 0; pull < GRUB_DISK_PULL_MAX; pull++) - { - if (pull == GRUB_DISK_PULL_RESCAN_UNTYPED) - continue; - for (p = grub_disk_dev_list; p; p = p->next) - if (p->iterate && (p->iterate) (hook, pull)) - return 1; - } + for (p = grub_disk_dev_list; p; p = p->next) + if (p->iterate && (p->iterate) (hook, pull)) + return 1; return 0; } @@ -243,7 +239,6 @@ grub_disk_open (const char *name) grub_disk_dev_t dev; char *raw = (char *) name; grub_uint64_t current_time; - grub_disk_pull_t pull; grub_dprintf ("disk", "Opening `%s'...\n", name); @@ -270,19 +265,14 @@ grub_disk_open (const char *name) if (! disk->name) goto fail; - for (pull = 0; pull < GRUB_DISK_PULL_MAX; pull++) + for (dev = grub_disk_dev_list; dev; dev = dev->next) { - for (dev = grub_disk_dev_list; dev; dev = dev->next) - { - if ((dev->open) (raw, disk, pull) == GRUB_ERR_NONE) - break; - else if (grub_errno == GRUB_ERR_UNKNOWN_DEVICE) - grub_errno = GRUB_ERR_NONE; - else - goto fail; - } - if (dev) + if ((dev->open) (raw, disk) == GRUB_ERR_NONE) break; + else if (grub_errno == GRUB_ERR_UNKNOWN_DEVICE) + grub_errno = GRUB_ERR_NONE; + else + goto fail; } if (! dev) diff --git a/grub-core/kern/emu/hostdisk.c b/grub-core/kern/emu/hostdisk.c index a2f9ce084..59d7a4a2c 100644 --- a/grub-core/kern/emu/hostdisk.c +++ b/grub-core/kern/emu/hostdisk.c @@ -227,8 +227,7 @@ grub_util_biosdisk_iterate (int (*hook) (const char *name), } static grub_err_t -grub_util_biosdisk_open (const char *name, grub_disk_t disk, - grub_disk_pull_t pull __attribute__ ((unused))) +grub_util_biosdisk_open (const char *name, grub_disk_t disk) { int drive; struct stat st; diff --git a/include/grub/disk.h b/include/grub/disk.h index efa27a4d2..2b6d02972 100644 --- a/include/grub/disk.h +++ b/include/grub/disk.h @@ -56,7 +56,6 @@ typedef enum GRUB_DISK_PULL_NONE, GRUB_DISK_PULL_REMOVABLE, GRUB_DISK_PULL_RESCAN, - GRUB_DISK_PULL_RESCAN_UNTYPED, GRUB_DISK_PULL_MAX } grub_disk_pull_t; @@ -74,8 +73,7 @@ struct grub_disk_dev grub_disk_pull_t pull); /* Open the device named NAME, and set up DISK. */ - grub_err_t (*open) (const char *name, struct grub_disk *disk, - grub_disk_pull_t pull); + grub_err_t (*open) (const char *name, struct grub_disk *disk); /* Close the disk DISK. */ void (*close) (struct grub_disk *disk); From cd8fe79a594a644773493ac339a4a1ebf73dd527 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 8 Jul 2011 03:59:05 +0200 Subject: [PATCH 746/869] Fix compilation on GNU/Linux. * grub-core/kern/emu/getroot.c (grub_util_pull_device) [!FreeBSD]: Disable geli. (grub_util_get_grub_dev) [!FreeBSD]: Likewise. (grub_util_pull_device) [HAVE_DEVICE_MAPPER]: Fix const and func name. * grub-core/disk/cryptodisk.c (grub_cryptodisk_open): Fix proto. --- ChangeLog | 10 ++++++++++ grub-core/disk/cryptodisk.c | 3 +-- grub-core/kern/emu/getroot.c | 9 ++++++--- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index b587dae2a..4bef20b13 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2011-07-07 Vladimir Serbinenko + + Fix compilation on GNU/Linux. + + * grub-core/kern/emu/getroot.c (grub_util_pull_device) [!FreeBSD]: + Disable geli. + (grub_util_get_grub_dev) [!FreeBSD]: Likewise. + (grub_util_pull_device) [HAVE_DEVICE_MAPPER]: Fix const and func name. + * grub-core/disk/cryptodisk.c (grub_cryptodisk_open): Fix proto. + 2011-07-07 Vladimir Serbinenko 2011-07-07 Michael Gorven 2011-07-07 Clemens Fruhwirth diff --git a/grub-core/disk/cryptodisk.c b/grub-core/disk/cryptodisk.c index 1a5e8164b..2852b65c4 100644 --- a/grub-core/disk/cryptodisk.c +++ b/grub-core/disk/cryptodisk.c @@ -413,8 +413,7 @@ grub_cryptodisk_iterate (int (*hook) (const char *name), } static grub_err_t -grub_cryptodisk_open (const char *name, grub_disk_t disk, - grub_disk_pull_t pull __attribute__ ((unused))) +grub_cryptodisk_open (const char *name, grub_disk_t disk) { grub_cryptodisk_t dev; diff --git a/grub-core/kern/emu/getroot.c b/grub-core/kern/emu/getroot.c index 380c5a7d1..9986fc5fc 100644 --- a/grub-core/kern/emu/getroot.c +++ b/grub-core/kern/emu/getroot.c @@ -975,6 +975,7 @@ grub_util_pull_device (const char *os_dev) switch (ab) { case GRUB_DEV_ABSTRACTION_GELI: +#if defined (__FreeBSD__) || defined(__FreeBSD_kernel__) { char *whole; struct gmesh mesh; @@ -1035,8 +1036,8 @@ grub_util_pull_device (const char *os_dev) grub_free (grdev); } - } +#endif break; case GRUB_DEV_ABSTRACTION_LVM: @@ -1065,14 +1066,14 @@ grub_util_pull_device (const char *os_dev) grub_util_pull_device (subdev); } } - if (ab == GRUB_DEV_ABSTRACTION_CRYPTO && lastsubdev) + if (ab == GRUB_DEV_ABSTRACTION_LUKS && lastsubdev) { char *grdev = grub_util_get_grub_dev (lastsubdev); dm_tree_free (tree); if (grdev) { grub_err_t err; - err = grub_luks_cheat_mount (grdev, os_dev); + err = grub_cryptodisk_cheat_mount (grdev, os_dev); if (err) grub_util_error ("Can't mount crypto: %s", grub_errmsg); } @@ -1141,6 +1142,7 @@ grub_util_get_grub_dev (const char *os_dev) break; case GRUB_DEV_ABSTRACTION_GELI: +#if defined (__FreeBSD__) || defined(__FreeBSD_kernel__) { char *whole; struct gmesh mesh; @@ -1187,6 +1189,7 @@ grub_util_get_grub_dev (const char *os_dev) } } } +#endif break; case GRUB_DEV_ABSTRACTION_RAID: From def9832af6b454f077c01100155c6a787b0b5f4d Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 8 Jul 2011 04:06:02 +0200 Subject: [PATCH 747/869] * po/POTFILES.in: Regenerate. --- ChangeLog | 4 ++ po/POTFILES.in | 117 ++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 120 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 4bef20b13..e86b3a4f1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2011-07-08 Vladimir Serbinenko + + * po/POTFILES.in: Regenerate. + 2011-07-07 Vladimir Serbinenko Fix compilation on GNU/Linux. diff --git a/po/POTFILES.in b/po/POTFILES.in index 2bf4aa10c..83cb48b2c 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -83,16 +83,20 @@ grub-core/commands/videoinfo.c grub-core/commands/videotest.c grub-core/commands/wildcard.c grub-core/commands/xnu_uuid.c +grub-core/disk/AFSplitter.c grub-core/disk/ahci.c grub-core/disk/arc/arcdisk.c grub-core/disk/ata.c +grub-core/disk/cryptodisk.c grub-core/disk/dmraid_nvidia.c grub-core/disk/efi/efidisk.c +grub-core/disk/geli.c grub-core/disk/host.c grub-core/disk/i386/pc/biosdisk.c grub-core/disk/ieee1275/nand.c grub-core/disk/ieee1275/ofdisk.c grub-core/disk/loopback.c +grub-core/disk/luks.c grub-core/disk/lvm.c grub-core/disk/mdraid1x_linux.c grub-core/disk/mdraid_linux.c @@ -174,6 +178,59 @@ grub-core/gfxmenu/model.c grub-core/gfxmenu/theme_loader.c grub-core/gfxmenu/view.c grub-core/gfxmenu/widget-box.c +grub-core/gnulib/alloca.c +grub-core/gnulib/argp-ba.c +grub-core/gnulib/argp-eexst.c +grub-core/gnulib/argp-fmtstream.c +grub-core/gnulib/argp-fs-xinl.c +grub-core/gnulib/argp-help.c +grub-core/gnulib/argp-parse.c +grub-core/gnulib/argp-pin.c +grub-core/gnulib/argp-pv.c +grub-core/gnulib/argp-pvh.c +grub-core/gnulib/argp-xinl.c +grub-core/gnulib/asnprintf.c +grub-core/gnulib/basename-lgpl.c +grub-core/gnulib/btowc.c +grub-core/gnulib/dirname-lgpl.c +grub-core/gnulib/error.c +grub-core/gnulib/fnmatch.c +grub-core/gnulib/fnmatch_loop.c +grub-core/gnulib/getdelim.c +grub-core/gnulib/getline.c +grub-core/gnulib/getopt1.c +grub-core/gnulib/getopt.c +grub-core/gnulib/localcharset.c +grub-core/gnulib/malloc.c +grub-core/gnulib/mbrtowc.c +grub-core/gnulib/mbsinit.c +grub-core/gnulib/mbsrtowcs.c +grub-core/gnulib/mbsrtowcs-state.c +grub-core/gnulib/memchr.c +grub-core/gnulib/mempcpy.c +grub-core/gnulib/nl_langinfo.c +grub-core/gnulib/printf-args.c +grub-core/gnulib/printf-parse.c +grub-core/gnulib/progname.c +grub-core/gnulib/rawmemchr.c +grub-core/gnulib/realloc.c +grub-core/gnulib/regcomp.c +grub-core/gnulib/regex.c +grub-core/gnulib/regexec.c +grub-core/gnulib/regex_internal.c +grub-core/gnulib/sleep.c +grub-core/gnulib/stdio-write.c +grub-core/gnulib/strcasecmp.c +grub-core/gnulib/strchrnul.c +grub-core/gnulib/strerror.c +grub-core/gnulib/stripslash.c +grub-core/gnulib/strncasecmp.c +grub-core/gnulib/strndup.c +grub-core/gnulib/strnlen1.c +grub-core/gnulib/strnlen.c +grub-core/gnulib/vasnprintf.c +grub-core/gnulib/vsnprintf.c +grub-core/gnulib/wcrtomb.c grub-core/hello/hello.c grub-core/hook/datehook.c grub-core/io/bufio.c @@ -198,6 +255,7 @@ grub-core/kern/emu/lite.c grub-core/kern/emu/main.c grub-core/kern/emu/misc.c grub-core/kern/emu/mm.c +grub-core/kern/emu/raid.c grub-core/kern/emu/time.c grub-core/kern/env.c grub-core/kern/err.c @@ -264,6 +322,63 @@ grub-core/lib/ieee1275/datetime.c grub-core/lib/ieee1275/halt.c grub-core/lib/ieee1275/relocator.c grub-core/lib/legacy_parse.c +grub-core/lib/libgcrypt/cipher/ac.c +grub-core/lib/libgcrypt/cipher/arcfour.c +grub-core/lib/libgcrypt/cipher/blowfish.c +grub-core/lib/libgcrypt/cipher/camellia.c +grub-core/lib/libgcrypt/cipher/camellia-glue.c +grub-core/lib/libgcrypt/cipher/cast5.c +grub-core/lib/libgcrypt/cipher/cipher.c +grub-core/lib/libgcrypt/cipher/crc.c +grub-core/lib/libgcrypt/cipher/des.c +grub-core/lib/libgcrypt/cipher/dsa.c +grub-core/lib/libgcrypt/cipher/ecc.c +grub-core/lib/libgcrypt/cipher/elgamal.c +grub-core/lib/libgcrypt/cipher/hash-common.c +grub-core/lib/libgcrypt/cipher/hmac-tests.c +grub-core/lib/libgcrypt/cipher/md4.c +grub-core/lib/libgcrypt/cipher/md5.c +grub-core/lib/libgcrypt/cipher/md.c +grub-core/lib/libgcrypt/cipher/primegen.c +grub-core/lib/libgcrypt/cipher/pubkey.c +grub-core/lib/libgcrypt/cipher/rfc2268.c +grub-core/lib/libgcrypt/cipher/rijndael.c +grub-core/lib/libgcrypt/cipher/rmd160.c +grub-core/lib/libgcrypt/cipher/rsa.c +grub-core/lib/libgcrypt/cipher/seed.c +grub-core/lib/libgcrypt/cipher/serpent.c +grub-core/lib/libgcrypt/cipher/sha1.c +grub-core/lib/libgcrypt/cipher/sha256.c +grub-core/lib/libgcrypt/cipher/sha512.c +grub-core/lib/libgcrypt/cipher/tiger.c +grub-core/lib/libgcrypt/cipher/twofish.c +grub-core/lib/libgcrypt/cipher/whirlpool.c +grub-core/lib/libgcrypt-grub/cipher/arcfour.c +grub-core/lib/libgcrypt-grub/cipher/blowfish.c +grub-core/lib/libgcrypt-grub/cipher/camellia.c +grub-core/lib/libgcrypt-grub/cipher/camellia-glue.c +grub-core/lib/libgcrypt-grub/cipher/cast5.c +grub-core/lib/libgcrypt-grub/cipher/crc.c +grub-core/lib/libgcrypt-grub/cipher/des.c +grub-core/lib/libgcrypt-grub/cipher/dsa.c +grub-core/lib/libgcrypt-grub/cipher/ecc.c +grub-core/lib/libgcrypt-grub/cipher/elgamal.c +grub-core/lib/libgcrypt-grub/cipher/init.c +grub-core/lib/libgcrypt-grub/cipher/md4.c +grub-core/lib/libgcrypt-grub/cipher/md5.c +grub-core/lib/libgcrypt-grub/cipher/primegen.c +grub-core/lib/libgcrypt-grub/cipher/rfc2268.c +grub-core/lib/libgcrypt-grub/cipher/rijndael.c +grub-core/lib/libgcrypt-grub/cipher/rmd160.c +grub-core/lib/libgcrypt-grub/cipher/rsa.c +grub-core/lib/libgcrypt-grub/cipher/seed.c +grub-core/lib/libgcrypt-grub/cipher/serpent.c +grub-core/lib/libgcrypt-grub/cipher/sha1.c +grub-core/lib/libgcrypt-grub/cipher/sha256.c +grub-core/lib/libgcrypt-grub/cipher/sha512.c +grub-core/lib/libgcrypt-grub/cipher/tiger.c +grub-core/lib/libgcrypt-grub/cipher/twofish.c +grub-core/lib/libgcrypt-grub/cipher/whirlpool.c grub-core/lib/LzFind.c grub-core/lib/LzmaDec.c grub-core/lib/LzmaEnc.c @@ -371,6 +486,7 @@ grub-core/tests/example_functional_test.c grub-core/tests/lib/functional_test.c grub-core/tests/lib/test.c grub-core/tests/test_blockarg.c +grub-core/unidata.c grub-core/video/bitmap.c grub-core/video/bitmap_scale.c grub-core/video/bochs.c @@ -419,5 +535,4 @@ util/ieee1275/grub-ofpathname.c util/ieee1275/ofpath.c util/lvm.c util/misc.c -util/raid.c util/resolve.c From 2e418de6460421240d5109b115b937694e6ba96e Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 8 Jul 2011 13:33:12 +0200 Subject: [PATCH 748/869] Remove getroot.c from core on emu platform. * grub-core/Makefile.core.def (kernel): Remove kern/emu/getroot.c and kern/emu/raid.c. * grub-core/kern/emu/main.c (main): Don't try to guess root device. It's useless. * grub-core/kern/emu/misc.c (get_win32_path): Moved from here... * util/getroot.c (get_win32_path): ... here. * grub-core/kern/emu/misc.c (fini_libzfs): Moved from here... * util/getroot.c (fini_libzfs): ... here. * grub-core/kern/emu/misc.c (grub_get_libzfs_handle): Moved from here... * util/getroot.c (grub_get_libzfs_handle): ... here. * grub-core/kern/emu/misc.c (grub_find_zpool_from_dir): Moved from here... * util/getroot.c (grub_find_zpool_from_dir): ... here. * grub-core/kern/emu/misc.c (grub_make_system_path_relative_to_its_root): Moved from here... * util/getroot.c (grub_make_system_path_relative_to_its_root): ... here. * grub-core/kern/emu/getroot.c: Moved from here ... * util/getroot.c: ... here. All users updated. * grub-core/kern/emu/raid.c: Moved from here ... * util/raid.c: ... here. All users updated. --- ChangeLog | 25 +++ Makefile.util.def | 4 +- grub-core/Makefile.core.def | 2 - grub-core/kern/emu/main.c | 21 +- grub-core/kern/emu/misc.c | 267 ------------------------- {grub-core/kern/emu => util}/getroot.c | 259 ++++++++++++++++++++++++ {grub-core/kern/emu => util}/raid.c | 0 7 files changed, 289 insertions(+), 289 deletions(-) rename {grub-core/kern/emu => util}/getroot.c (84%) rename {grub-core/kern/emu => util}/raid.c (100%) diff --git a/ChangeLog b/ChangeLog index e86b3a4f1..33c5b0b92 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,28 @@ +2011-07-08 Vladimir Serbinenko + + Remove getroot.c from core on emu platform. + + * grub-core/Makefile.core.def (kernel): Remove kern/emu/getroot.c and + kern/emu/raid.c. + * grub-core/kern/emu/main.c (main): Don't try to guess root device. It's + useless. + * grub-core/kern/emu/misc.c (get_win32_path): Moved from here... + * util/getroot.c (get_win32_path): ... here. + * grub-core/kern/emu/misc.c (fini_libzfs): Moved from here... + * util/getroot.c (fini_libzfs): ... here. + * grub-core/kern/emu/misc.c (grub_get_libzfs_handle): Moved from here... + * util/getroot.c (grub_get_libzfs_handle): ... here. + * grub-core/kern/emu/misc.c (grub_find_zpool_from_dir): + Moved from here... + * util/getroot.c (grub_find_zpool_from_dir): ... here. + * grub-core/kern/emu/misc.c + (grub_make_system_path_relative_to_its_root): Moved from here... + * util/getroot.c (grub_make_system_path_relative_to_its_root): ... here. + * grub-core/kern/emu/getroot.c: Moved from here ... + * util/getroot.c: ... here. All users updated. + * grub-core/kern/emu/raid.c: Moved from here ... + * util/raid.c: ... here. All users updated. + 2011-07-08 Vladimir Serbinenko * po/POTFILES.in: Regenerate. diff --git a/Makefile.util.def b/Makefile.util.def index 18dd2fef8..c87020493 100644 --- a/Makefile.util.def +++ b/Makefile.util.def @@ -9,8 +9,8 @@ library = { common = grub-core/kern/command.c; common = grub-core/kern/device.c; common = grub-core/kern/disk.c; - common = grub-core/kern/emu/getroot.c; - common = grub-core/kern/emu/raid.c; + common = util/getroot.c; + common = util/raid.c; common = grub-core/kern/emu/hostdisk.c; common = grub-core/kern/emu/misc.c; common = grub-core/kern/emu/mm.c; diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def index 7200bd3e9..0924602f3 100644 --- a/grub-core/Makefile.core.def +++ b/grub-core/Makefile.core.def @@ -195,8 +195,6 @@ kernel = { emu = gnulib/error.c; emu = kern/emu/cache_s.S; emu = kern/emu/console.c; - emu = kern/emu/getroot.c; - emu = kern/emu/raid.c; emu = kern/emu/hostdisk.c; emu = kern/emu/hostfs.c; emu = kern/emu/main.c; diff --git a/grub-core/kern/emu/main.c b/grub-core/kern/emu/main.c index 2092d03cb..9a58acd9e 100644 --- a/grub-core/kern/emu/main.c +++ b/grub-core/kern/emu/main.c @@ -111,7 +111,7 @@ usage (int status) "\n" "GRUB emulator.\n" "\n" - " -r, --root-device=DEV use DEV as the root device [default=guessed]\n" + " -r, --root-device=DEV use DEV as the root device [default=host]\n" " -m, --device-map=FILE use FILE as the device map [default=%s]\n" " -d, --directory=DIR use GRUB files in the directory DIR [default=%s]\n" " -v, --verbose print verbose messages\n" @@ -204,24 +204,9 @@ main (int argc, char *argv[]) /* Make sure that there is a root device. */ if (! root_dev) - { - char *device_name = grub_guess_root_device (dir); - if (! device_name) - grub_util_error ("cannot find a device for %s", dir); + root_dev = grub_strdup ("host"); - root_dev = grub_util_get_grub_dev (device_name); - if (! root_dev) - { - grub_util_info ("guessing the root device failed, because of `%s'", - grub_errmsg); - grub_util_error ("cannot guess the root device. Specify the option `--root-device'"); - } - } - - if (strcmp (root_dev, "host") == 0) - dir = xstrdup (dir); - else - dir = grub_make_system_path_relative_to_its_root (dir); + dir = xstrdup (dir); /* Start GRUB! */ if (setjmp (main_env) == 0) diff --git a/grub-core/kern/emu/misc.c b/grub-core/kern/emu/misc.c index 44c40b010..737f5f1a9 100644 --- a/grub-core/kern/emu/misc.c +++ b/grub-core/kern/emu/misc.c @@ -46,14 +46,6 @@ # include #endif -#ifdef HAVE_LIBZFS -# include -#endif - -#ifdef HAVE_LIBNVPAIR -# include -#endif - #ifdef HAVE_SYS_PARAM_H # include #endif @@ -242,265 +234,6 @@ canonicalize_file_name (const char *path) return ret; } -#ifdef __CYGWIN__ -/* Convert POSIX path to Win32 path, - remove drive letter, replace backslashes. */ -static char * -get_win32_path (const char *path) -{ - char winpath[PATH_MAX]; - if (cygwin_conv_path (CCP_POSIX_TO_WIN_A, path, winpath, sizeof(winpath))) - grub_util_error ("cygwin_conv_path() failed"); - - int len = strlen (winpath); - int offs = (len > 2 && winpath[1] == ':' ? 2 : 0); - - int i; - for (i = offs; i < len; i++) - if (winpath[i] == '\\') - winpath[i] = '/'; - return xstrdup (winpath + offs); -} -#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 (); - - if (__libzfs_handle) - 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) -{ - char *slash; - - *poolname = *poolfs = NULL; - -#if defined(HAVE_STRUCT_STATFS_F_FSTYPENAME) && defined(HAVE_STRUCT_STATFS_F_MNTFROMNAME) - /* FreeBSD and GNU/kFreeBSD. */ - { - struct statfs mnt; - - if (statfs (dir, &mnt) != 0) - return; - - if (strcmp (mnt.f_fstypename, "zfs") != 0) - return; - - *poolname = xstrdup (mnt.f_mntfromname); - } -#elif defined(HAVE_GETEXTMNTENT) - /* Solaris. */ - { - struct stat st; - struct extmnttab mnt; - - if (stat (dir, &st) != 0) - return; - - FILE *mnttab = fopen ("/etc/mnttab", "r"); - if (! mnttab) - return; - - while (getextmntent (mnttab, &mnt, sizeof (mnt)) == 0) - { - if (makedev (mnt.mnt_major, mnt.mnt_minor) == st.st_dev - && !strcmp (mnt.mnt_fstype, "zfs")) - { - *poolname = xstrdup (mnt.mnt_special); - break; - } - } - - fclose (mnttab); - } -#endif - - if (! *poolname) - return; - - 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 - can be appended a slash unconditionally). */ -char * -grub_make_system_path_relative_to_its_root (const char *path) -{ - struct stat st; - char *p, *buf, *buf2, *buf3, *ret; - uintptr_t offset = 0; - dev_t num; - size_t len; - -#if defined(HAVE_LIBZFS) && defined(HAVE_LIBNVPAIR) - char *poolfs = NULL; -#endif - - /* canonicalize. */ - p = canonicalize_file_name (path); - if (p == NULL) - 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; - buf = xstrdup (p); - free (p); - - if (stat (buf, &st) < 0) - grub_util_error ("cannot stat %s: %s", buf, strerror (errno)); - - buf2 = xstrdup (buf); - num = st.st_dev; - - /* This loop sets offset to the number of chars of the root - directory we're inspecting. */ - while (1) - { - p = strrchr (buf, '/'); - if (p == NULL) - /* This should never happen. */ - grub_util_error ("FIXME: no / in buf. (make_system_path_relative_to_its_root)"); - if (p != buf) - *p = 0; - else - *++p = 0; - - if (stat (buf, &st) < 0) - grub_util_error ("cannot stat %s: %s", buf, strerror (errno)); - - /* buf is another filesystem; we found it. */ - if (st.st_dev != num) - { - /* offset == 0 means path given is the mount point. - This works around special-casing of "/" in Un*x. This function never - prints trailing slashes (so that its output can be appended a slash - unconditionally). Each slash in is considered a preceding slash, and - therefore the root directory is an empty string. */ - if (offset == 0) - { - free (buf); -#ifdef __linux__ - { - char *bind; - grub_free (grub_find_root_device_from_mountinfo (buf2, &bind)); - if (bind && bind[0] && bind[1]) - { - buf3 = bind; - goto parsedir; - } - grub_free (bind); - } -#endif - free (buf2); -#if defined(HAVE_LIBZFS) && defined(HAVE_LIBNVPAIR) - if (poolfs) - return xasprintf ("/%s/@", poolfs); -#endif - return xstrdup (""); - } - else - break; - } - - offset = p - buf; - /* offset == 1 means root directory. */ - if (offset == 1) - { - /* Include leading slash. */ - offset = 0; - break; - } - } - free (buf); - buf3 = xstrdup (buf2 + offset); - buf2[offset] = 0; -#ifdef __linux__ - { - char *bind; - grub_free (grub_find_root_device_from_mountinfo (buf2, &bind)); - if (bind && bind[0] && bind[1]) - { - char *temp = buf3; - buf3 = grub_xasprintf ("%s%s%s", bind, buf3[0] == '/' ?"":"/", buf3); - grub_free (temp); - } - grub_free (bind); - } -#endif - - free (buf2); - -#ifdef __CYGWIN__ - if (st.st_dev != (DEV_CYGDRIVE_MAJOR << 16)) - { - /* Reached some mount point not below /cygdrive. - GRUB does not know Cygwin's emulated mounts, - convert to Win32 path. */ - grub_util_info ("Cygwin path = %s\n", buf3); - char * temp = get_win32_path (buf3); - free (buf3); - buf3 = temp; - } -#endif - - parsedir: - /* Remove trailing slashes, return empty string if root directory. */ - len = strlen (buf3); - while (len > 0 && buf3[len - 1] == '/') - { - buf3[len - 1] = '\0'; - len--; - } - -#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 static void device_mapper_null_log (int level __attribute__ ((unused)), const char *file __attribute__ ((unused)), diff --git a/grub-core/kern/emu/getroot.c b/util/getroot.c similarity index 84% rename from grub-core/kern/emu/getroot.c rename to util/getroot.c index 9986fc5fc..71064583f 100644 --- a/grub-core/kern/emu/getroot.c +++ b/util/getroot.c @@ -1330,3 +1330,262 @@ grub_util_check_char_device (const char *blk_dev) else return 0; } + +#ifdef __CYGWIN__ +/* Convert POSIX path to Win32 path, + remove drive letter, replace backslashes. */ +static char * +get_win32_path (const char *path) +{ + char winpath[PATH_MAX]; + if (cygwin_conv_path (CCP_POSIX_TO_WIN_A, path, winpath, sizeof(winpath))) + grub_util_error ("cygwin_conv_path() failed"); + + int len = strlen (winpath); + int offs = (len > 2 && winpath[1] == ':' ? 2 : 0); + + int i; + for (i = offs; i < len; i++) + if (winpath[i] == '\\') + winpath[i] = '/'; + return xstrdup (winpath + offs); +} +#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 (); + + if (__libzfs_handle) + 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) +{ + char *slash; + + *poolname = *poolfs = NULL; + +#if defined(HAVE_STRUCT_STATFS_F_FSTYPENAME) && defined(HAVE_STRUCT_STATFS_F_MNTFROMNAME) + /* FreeBSD and GNU/kFreeBSD. */ + { + struct statfs mnt; + + if (statfs (dir, &mnt) != 0) + return; + + if (strcmp (mnt.f_fstypename, "zfs") != 0) + return; + + *poolname = xstrdup (mnt.f_mntfromname); + } +#elif defined(HAVE_GETEXTMNTENT) + /* Solaris. */ + { + struct stat st; + struct extmnttab mnt; + + if (stat (dir, &st) != 0) + return; + + FILE *mnttab = fopen ("/etc/mnttab", "r"); + if (! mnttab) + return; + + while (getextmntent (mnttab, &mnt, sizeof (mnt)) == 0) + { + if (makedev (mnt.mnt_major, mnt.mnt_minor) == st.st_dev + && !strcmp (mnt.mnt_fstype, "zfs")) + { + *poolname = xstrdup (mnt.mnt_special); + break; + } + } + + fclose (mnttab); + } +#endif + + if (! *poolname) + return; + + 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 + can be appended a slash unconditionally). */ +char * +grub_make_system_path_relative_to_its_root (const char *path) +{ + struct stat st; + char *p, *buf, *buf2, *buf3, *ret; + uintptr_t offset = 0; + dev_t num; + size_t len; + +#if defined(HAVE_LIBZFS) && defined(HAVE_LIBNVPAIR) + char *poolfs = NULL; +#endif + + /* canonicalize. */ + p = canonicalize_file_name (path); + if (p == NULL) + 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; + buf = xstrdup (p); + free (p); + + if (stat (buf, &st) < 0) + grub_util_error ("cannot stat %s: %s", buf, strerror (errno)); + + buf2 = xstrdup (buf); + num = st.st_dev; + + /* This loop sets offset to the number of chars of the root + directory we're inspecting. */ + while (1) + { + p = strrchr (buf, '/'); + if (p == NULL) + /* This should never happen. */ + grub_util_error ("FIXME: no / in buf. (make_system_path_relative_to_its_root)"); + if (p != buf) + *p = 0; + else + *++p = 0; + + if (stat (buf, &st) < 0) + grub_util_error ("cannot stat %s: %s", buf, strerror (errno)); + + /* buf is another filesystem; we found it. */ + if (st.st_dev != num) + { + /* offset == 0 means path given is the mount point. + This works around special-casing of "/" in Un*x. This function never + prints trailing slashes (so that its output can be appended a slash + unconditionally). Each slash in is considered a preceding slash, and + therefore the root directory is an empty string. */ + if (offset == 0) + { + free (buf); +#ifdef __linux__ + { + char *bind; + grub_free (grub_find_root_device_from_mountinfo (buf2, &bind)); + if (bind && bind[0] && bind[1]) + { + buf3 = bind; + goto parsedir; + } + grub_free (bind); + } +#endif + free (buf2); +#if defined(HAVE_LIBZFS) && defined(HAVE_LIBNVPAIR) + if (poolfs) + return xasprintf ("/%s/@", poolfs); +#endif + return xstrdup (""); + } + else + break; + } + + offset = p - buf; + /* offset == 1 means root directory. */ + if (offset == 1) + { + /* Include leading slash. */ + offset = 0; + break; + } + } + free (buf); + buf3 = xstrdup (buf2 + offset); + buf2[offset] = 0; +#ifdef __linux__ + { + char *bind; + grub_free (grub_find_root_device_from_mountinfo (buf2, &bind)); + if (bind && bind[0] && bind[1]) + { + char *temp = buf3; + buf3 = grub_xasprintf ("%s%s%s", bind, buf3[0] == '/' ?"":"/", buf3); + grub_free (temp); + } + grub_free (bind); + } +#endif + + free (buf2); + +#ifdef __CYGWIN__ + if (st.st_dev != (DEV_CYGDRIVE_MAJOR << 16)) + { + /* Reached some mount point not below /cygdrive. + GRUB does not know Cygwin's emulated mounts, + convert to Win32 path. */ + grub_util_info ("Cygwin path = %s\n", buf3); + char * temp = get_win32_path (buf3); + free (buf3); + buf3 = temp; + } +#endif + + parsedir: + /* Remove trailing slashes, return empty string if root directory. */ + len = strlen (buf3); + while (len > 0 && buf3[len - 1] == '/') + { + buf3[len - 1] = '\0'; + len--; + } + +#if defined(HAVE_LIBZFS) && defined(HAVE_LIBNVPAIR) + if (poolfs) + { + ret = xasprintf ("/%s/@%s", poolfs, buf3); + free (buf3); + } + else +#endif + ret = buf3; + + return ret; +} diff --git a/grub-core/kern/emu/raid.c b/util/raid.c similarity index 100% rename from grub-core/kern/emu/raid.c rename to util/raid.c From 16a2bab03c78d1f727ab48fe9af47abe6bea7b22 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 10 Jul 2011 15:32:43 +0200 Subject: [PATCH 749/869] * util/grub-install.in: Source grub-mkconfig_lib. --- ChangeLog | 4 ++++ util/grub-install.in | 2 ++ 2 files changed, 6 insertions(+) diff --git a/ChangeLog b/ChangeLog index 33c5b0b92..96b48f2fe 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2011-07-10 Vladimir Serbinenko + + * util/grub-install.in: Source grub-mkconfig_lib. + 2011-07-08 Vladimir Serbinenko Remove getroot.c from core on emu platform. diff --git a/util/grub-install.in b/util/grub-install.in index 09894d0d0..711c9c7e2 100644 --- a/util/grub-install.in +++ b/util/grub-install.in @@ -59,6 +59,8 @@ update_nvram=yes removable=no efi_quiet= +. ${libdir}/@PACKAGE@/grub-mkconfig_lib + # Get GRUB_DISTRIBUTOR. if test -f "${sysconfdir}/default/grub" ; then . "${sysconfdir}/default/grub" From c4edd548324dd0c1bfdd5d8cc4566de25074fdb6 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 10 Jul 2011 15:33:57 +0200 Subject: [PATCH 750/869] * grub-core/disk/efi/efidisk.c (grub_efidisk_get_device_name): Fix incorrect memory usage. --- ChangeLog | 5 +++++ grub-core/disk/efi/efidisk.c | 9 +++------ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index 96b48f2fe..cf2354f6d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-07-10 Vladimir Serbinenko + + * grub-core/disk/efi/efidisk.c (grub_efidisk_get_device_name): Fix + incorrect memory usage. + 2011-07-10 Vladimir Serbinenko * util/grub-install.in: Source grub-mkconfig_lib. diff --git a/grub-core/disk/efi/efidisk.c b/grub-core/disk/efi/efidisk.c index 85969cc1d..0baeb8e4b 100644 --- a/grub-core/disk/efi/efidisk.c +++ b/grub-core/disk/efi/efidisk.c @@ -709,7 +709,7 @@ grub_efidisk_get_device_name (grub_efi_handle_t *handle) && (GRUB_EFI_DEVICE_PATH_SUBTYPE (ldp) == GRUB_EFI_HARD_DRIVE_DEVICE_PATH_SUBTYPE)) { - grub_partition_t tpart = NULL; + char *partition_name = NULL; char *device_name; grub_efi_device_path_t *dup_dp, *dup_ldp; grub_efi_hard_drive_device_path_t hd; @@ -722,7 +722,7 @@ grub_efidisk_get_device_name (grub_efi_handle_t *handle) if (grub_partition_get_start (part) == hd.partition_start && grub_partition_get_len (part) == hd.partition_size) { - tpart = part; + partition_name = grub_partition_get_name (part); return 1; } @@ -760,17 +760,14 @@ grub_efidisk_get_device_name (grub_efi_handle_t *handle) } else { - char *partition_name; - grub_partition_iterate (parent, find_partition); - if (! tpart) + if (! partition_name) { grub_disk_close (parent); return 0; } - partition_name = grub_partition_get_name (tpart); device_name = grub_xasprintf ("%s,%s", parent->name, partition_name); grub_free (partition_name); } From e4bcf6258cd128aa81257ca8dd217596f9cd5771 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 10 Jul 2011 15:56:56 +0200 Subject: [PATCH 751/869] * po/POTFILES.in: Regenerate. --- ChangeLog | 4 + po/POTFILES.in | 1076 ++++++++++++++++++++++++------------------------ 2 files changed, 542 insertions(+), 538 deletions(-) diff --git a/ChangeLog b/ChangeLog index cf2354f6d..84167f226 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2011-07-10 Vladimir Serbinenko + + * po/POTFILES.in: Regenerate. + 2011-07-10 Vladimir Serbinenko * grub-core/disk/efi/efidisk.c (grub_efidisk_get_device_name): Fix diff --git a/po/POTFILES.in b/po/POTFILES.in index 83cb48b2c..ebb0aadaa 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -1,538 +1,538 @@ -grub-core/boot/decompressor/minilib.c -grub-core/boot/decompressor/none.c -grub-core/boot/decompressor/xz.c -grub-core/bus/bonito.c -grub-core/bus/cs5536.c -grub-core/bus/emu/pci.c -grub-core/bus/pci.c -grub-core/bus/usb/emu/usb.c -grub-core/bus/usb/ohci.c -grub-core/bus/usb/serial/common.c -grub-core/bus/usb/serial/ftdi.c -grub-core/bus/usb/serial/pl2303.c -grub-core/bus/usb/uhci.c -grub-core/bus/usb/usb.c -grub-core/bus/usb/usbhub.c -grub-core/bus/usb/usbtrans.c -grub-core/commands/acpi.c -grub-core/commands/acpihalt.c -grub-core/commands/arc/lsdev.c -grub-core/commands/blocklist.c -grub-core/commands/boot.c -grub-core/commands/cat.c -grub-core/commands/cmp.c -grub-core/commands/configfile.c -grub-core/commands/date.c -grub-core/commands/echo.c -grub-core/commands/efi/acpi.c -grub-core/commands/efi/fixvideo.c -grub-core/commands/efi/loadbios.c -grub-core/commands/efi/lsefimmap.c -grub-core/commands/efi/lsefisystab.c -grub-core/commands/efi/lssal.c -grub-core/commands/extcmd.c -grub-core/commands/gptsync.c -grub-core/commands/halt.c -grub-core/commands/hashsum.c -grub-core/commands/hdparm.c -grub-core/commands/help.c -grub-core/commands/hexdump.c -grub-core/commands/i386/cmostest.c -grub-core/commands/i386/cpuid.c -grub-core/commands/i386/pc/acpi.c -grub-core/commands/i386/pc/drivemap.c -grub-core/commands/i386/pc/halt.c -grub-core/commands/i386/pc/lsapm.c -grub-core/commands/i386/pc/play.c -grub-core/commands/i386/pc/sendkey.c -grub-core/commands/ieee1275/suspend.c -grub-core/commands/iorw.c -grub-core/commands/keylayouts.c -grub-core/commands/keystatus.c -grub-core/commands/legacycfg.c -grub-core/commands/loadenv.c -grub-core/commands/lsacpi.c -grub-core/commands/ls.c -grub-core/commands/lsmmap.c -grub-core/commands/lspci.c -grub-core/commands/memrw.c -grub-core/commands/menuentry.c -grub-core/commands/minicmd.c -grub-core/commands/mips/loongson/lsspd.c -grub-core/commands/parttool.c -grub-core/commands/password.c -grub-core/commands/password_pbkdf2.c -grub-core/commands/probe.c -grub-core/commands/read.c -grub-core/commands/reboot.c -grub-core/commands/regexp.c -grub-core/commands/search.c -grub-core/commands/search_file.c -grub-core/commands/search_label.c -grub-core/commands/search_uuid.c -grub-core/commands/search_wrap.c -grub-core/commands/setpci.c -grub-core/commands/sleep.c -grub-core/commands/terminal.c -grub-core/commands/test.c -grub-core/commands/testload.c -grub-core/commands/time.c -grub-core/commands/true.c -grub-core/commands/usbtest.c -grub-core/commands/videoinfo.c -grub-core/commands/videotest.c -grub-core/commands/wildcard.c -grub-core/commands/xnu_uuid.c -grub-core/disk/AFSplitter.c -grub-core/disk/ahci.c -grub-core/disk/arc/arcdisk.c -grub-core/disk/ata.c -grub-core/disk/cryptodisk.c -grub-core/disk/dmraid_nvidia.c -grub-core/disk/efi/efidisk.c -grub-core/disk/geli.c -grub-core/disk/host.c -grub-core/disk/i386/pc/biosdisk.c -grub-core/disk/ieee1275/nand.c -grub-core/disk/ieee1275/ofdisk.c -grub-core/disk/loopback.c -grub-core/disk/luks.c -grub-core/disk/lvm.c -grub-core/disk/mdraid1x_linux.c -grub-core/disk/mdraid_linux.c -grub-core/disk/memdisk.c -grub-core/disk/pata.c -grub-core/disk/raid5_recover.c -grub-core/disk/raid6_recover.c -grub-core/disk/raid.c -grub-core/disk/scsi.c -grub-core/disk/usbms.c -grub-core/efiemu/i386/coredetect.c -grub-core/efiemu/i386/loadcore32.c -grub-core/efiemu/i386/loadcore64.c -grub-core/efiemu/i386/nocfgtables.c -grub-core/efiemu/i386/pc/cfgtables.c -grub-core/efiemu/loadcore32.c -grub-core/efiemu/loadcore64.c -grub-core/efiemu/loadcore.c -grub-core/efiemu/loadcore_common.c -grub-core/efiemu/main.c -grub-core/efiemu/mm.c -grub-core/efiemu/pnvram.c -grub-core/efiemu/prepare32.c -grub-core/efiemu/prepare64.c -grub-core/efiemu/prepare.c -grub-core/efiemu/runtime/efiemu.c -grub-core/efiemu/symbols.c -grub-core/font/font.c -grub-core/font/font_cmd.c -grub-core/fs/affs.c -grub-core/fs/afs_be.c -grub-core/fs/afs.c -grub-core/fs/befs_be.c -grub-core/fs/befs.c -grub-core/fs/btrfs.c -grub-core/fs/cpio.c -grub-core/fs/ext2.c -grub-core/fs/fat.c -grub-core/fs/fshelp.c -grub-core/fs/hfs.c -grub-core/fs/hfsplus.c -grub-core/fs/iso9660.c -grub-core/fs/jfs.c -grub-core/fs/minix2.c -grub-core/fs/minix3.c -grub-core/fs/minix.c -grub-core/fs/nilfs2.c -grub-core/fs/ntfs.c -grub-core/fs/ntfscomp.c -grub-core/fs/reiserfs.c -grub-core/fs/romfs.c -grub-core/fs/sfs.c -grub-core/fs/squash4.c -grub-core/fs/tar.c -grub-core/fs/udf.c -grub-core/fs/ufs2.c -grub-core/fs/ufs.c -grub-core/fs/xfs.c -grub-core/fs/zfs/zfs.c -grub-core/fs/zfs/zfs_fletcher.c -grub-core/fs/zfs/zfsinfo.c -grub-core/fs/zfs/zfs_lzjb.c -grub-core/fs/zfs/zfs_sha256.c -grub-core/gentrigtables.c -grub-core/gettext/gettext.c -grub-core/gfxmenu/font.c -grub-core/gfxmenu/gfxmenu.c -grub-core/gfxmenu/gui_box.c -grub-core/gfxmenu/gui_canvas.c -grub-core/gfxmenu/gui_circular_progress.c -grub-core/gfxmenu/gui_image.c -grub-core/gfxmenu/gui_label.c -grub-core/gfxmenu/gui_list.c -grub-core/gfxmenu/gui_progress_bar.c -grub-core/gfxmenu/gui_string_util.c -grub-core/gfxmenu/gui_util.c -grub-core/gfxmenu/icon_manager.c -grub-core/gfxmenu/model.c -grub-core/gfxmenu/theme_loader.c -grub-core/gfxmenu/view.c -grub-core/gfxmenu/widget-box.c -grub-core/gnulib/alloca.c -grub-core/gnulib/argp-ba.c -grub-core/gnulib/argp-eexst.c -grub-core/gnulib/argp-fmtstream.c -grub-core/gnulib/argp-fs-xinl.c -grub-core/gnulib/argp-help.c -grub-core/gnulib/argp-parse.c -grub-core/gnulib/argp-pin.c -grub-core/gnulib/argp-pv.c -grub-core/gnulib/argp-pvh.c -grub-core/gnulib/argp-xinl.c -grub-core/gnulib/asnprintf.c -grub-core/gnulib/basename-lgpl.c -grub-core/gnulib/btowc.c -grub-core/gnulib/dirname-lgpl.c -grub-core/gnulib/error.c -grub-core/gnulib/fnmatch.c -grub-core/gnulib/fnmatch_loop.c -grub-core/gnulib/getdelim.c -grub-core/gnulib/getline.c -grub-core/gnulib/getopt1.c -grub-core/gnulib/getopt.c -grub-core/gnulib/localcharset.c -grub-core/gnulib/malloc.c -grub-core/gnulib/mbrtowc.c -grub-core/gnulib/mbsinit.c -grub-core/gnulib/mbsrtowcs.c -grub-core/gnulib/mbsrtowcs-state.c -grub-core/gnulib/memchr.c -grub-core/gnulib/mempcpy.c -grub-core/gnulib/nl_langinfo.c -grub-core/gnulib/printf-args.c -grub-core/gnulib/printf-parse.c -grub-core/gnulib/progname.c -grub-core/gnulib/rawmemchr.c -grub-core/gnulib/realloc.c -grub-core/gnulib/regcomp.c -grub-core/gnulib/regex.c -grub-core/gnulib/regexec.c -grub-core/gnulib/regex_internal.c -grub-core/gnulib/sleep.c -grub-core/gnulib/stdio-write.c -grub-core/gnulib/strcasecmp.c -grub-core/gnulib/strchrnul.c -grub-core/gnulib/strerror.c -grub-core/gnulib/stripslash.c -grub-core/gnulib/strncasecmp.c -grub-core/gnulib/strndup.c -grub-core/gnulib/strnlen1.c -grub-core/gnulib/strnlen.c -grub-core/gnulib/vasnprintf.c -grub-core/gnulib/vsnprintf.c -grub-core/gnulib/wcrtomb.c -grub-core/hello/hello.c -grub-core/hook/datehook.c -grub-core/io/bufio.c -grub-core/io/gzio.c -grub-core/io/xzio.c -grub-core/kern/command.c -grub-core/kern/corecmd.c -grub-core/kern/device.c -grub-core/kern/disk.c -grub-core/kern/dl.c -grub-core/kern/efi/efi.c -grub-core/kern/efi/init.c -grub-core/kern/efi/mm.c -grub-core/kern/elf.c -grub-core/kern/emu/cache.c -grub-core/kern/emu/console.c -grub-core/kern/emu/full.c -grub-core/kern/emu/getroot.c -grub-core/kern/emu/hostdisk.c -grub-core/kern/emu/hostfs.c -grub-core/kern/emu/lite.c -grub-core/kern/emu/main.c -grub-core/kern/emu/misc.c -grub-core/kern/emu/mm.c -grub-core/kern/emu/raid.c -grub-core/kern/emu/time.c -grub-core/kern/env.c -grub-core/kern/err.c -grub-core/kern/file.c -grub-core/kern/fs.c -grub-core/kern/generic/millisleep.c -grub-core/kern/generic/rtc_get_time_ms.c -grub-core/kern/i386/coreboot/init.c -grub-core/kern/i386/coreboot/mmap.c -grub-core/kern/i386/dl.c -grub-core/kern/i386/efi/init.c -grub-core/kern/i386/multiboot_mmap.c -grub-core/kern/i386/pc/init.c -grub-core/kern/i386/pc/mmap.c -grub-core/kern/i386/pit.c -grub-core/kern/i386/qemu/mmap.c -grub-core/kern/i386/tsc.c -grub-core/kern/ia64/dl.c -grub-core/kern/ia64/dl_helper.c -grub-core/kern/ia64/efi/init.c -grub-core/kern/ieee1275/cmain.c -grub-core/kern/ieee1275/ieee1275.c -grub-core/kern/ieee1275/init.c -grub-core/kern/ieee1275/mmap.c -grub-core/kern/ieee1275/openfw.c -grub-core/kern/list.c -grub-core/kern/main.c -grub-core/kern/mips/arc/init.c -grub-core/kern/mips/dl.c -grub-core/kern/mips/init.c -grub-core/kern/mips/loongson/init.c -grub-core/kern/mips/qemu_mips/init.c -grub-core/kern/misc.c -grub-core/kern/mm.c -grub-core/kern/parser.c -grub-core/kern/partition.c -grub-core/kern/powerpc/dl.c -grub-core/kern/rescue_parser.c -grub-core/kern/rescue_reader.c -grub-core/kern/sparc64/dl.c -grub-core/kern/sparc64/ieee1275/ieee1275.c -grub-core/kern/term.c -grub-core/kern/time.c -grub-core/kern/vga_init.c -grub-core/kern/x86_64/dl.c -grub-core/lib/arc/datetime.c -grub-core/lib/arg.c -grub-core/lib/cmdline.c -grub-core/lib/cmos_datetime.c -grub-core/lib/crc.c -grub-core/lib/crypto.c -grub-core/lib/efi/datetime.c -grub-core/lib/efi/halt.c -grub-core/lib/efi/relocator.c -grub-core/lib/emu/halt.c -grub-core/lib/envblk.c -grub-core/lib/hexdump.c -grub-core/lib/i386/halt.c -grub-core/lib/i386/pc/biosnum.c -grub-core/lib/i386/pc/vesa_modes_table.c -grub-core/lib/i386/relocator.c -grub-core/lib/ieee1275/cmos.c -grub-core/lib/ieee1275/datetime.c -grub-core/lib/ieee1275/halt.c -grub-core/lib/ieee1275/relocator.c -grub-core/lib/legacy_parse.c -grub-core/lib/libgcrypt/cipher/ac.c -grub-core/lib/libgcrypt/cipher/arcfour.c -grub-core/lib/libgcrypt/cipher/blowfish.c -grub-core/lib/libgcrypt/cipher/camellia.c -grub-core/lib/libgcrypt/cipher/camellia-glue.c -grub-core/lib/libgcrypt/cipher/cast5.c -grub-core/lib/libgcrypt/cipher/cipher.c -grub-core/lib/libgcrypt/cipher/crc.c -grub-core/lib/libgcrypt/cipher/des.c -grub-core/lib/libgcrypt/cipher/dsa.c -grub-core/lib/libgcrypt/cipher/ecc.c -grub-core/lib/libgcrypt/cipher/elgamal.c -grub-core/lib/libgcrypt/cipher/hash-common.c -grub-core/lib/libgcrypt/cipher/hmac-tests.c -grub-core/lib/libgcrypt/cipher/md4.c -grub-core/lib/libgcrypt/cipher/md5.c -grub-core/lib/libgcrypt/cipher/md.c -grub-core/lib/libgcrypt/cipher/primegen.c -grub-core/lib/libgcrypt/cipher/pubkey.c -grub-core/lib/libgcrypt/cipher/rfc2268.c -grub-core/lib/libgcrypt/cipher/rijndael.c -grub-core/lib/libgcrypt/cipher/rmd160.c -grub-core/lib/libgcrypt/cipher/rsa.c -grub-core/lib/libgcrypt/cipher/seed.c -grub-core/lib/libgcrypt/cipher/serpent.c -grub-core/lib/libgcrypt/cipher/sha1.c -grub-core/lib/libgcrypt/cipher/sha256.c -grub-core/lib/libgcrypt/cipher/sha512.c -grub-core/lib/libgcrypt/cipher/tiger.c -grub-core/lib/libgcrypt/cipher/twofish.c -grub-core/lib/libgcrypt/cipher/whirlpool.c -grub-core/lib/libgcrypt-grub/cipher/arcfour.c -grub-core/lib/libgcrypt-grub/cipher/blowfish.c -grub-core/lib/libgcrypt-grub/cipher/camellia.c -grub-core/lib/libgcrypt-grub/cipher/camellia-glue.c -grub-core/lib/libgcrypt-grub/cipher/cast5.c -grub-core/lib/libgcrypt-grub/cipher/crc.c -grub-core/lib/libgcrypt-grub/cipher/des.c -grub-core/lib/libgcrypt-grub/cipher/dsa.c -grub-core/lib/libgcrypt-grub/cipher/ecc.c -grub-core/lib/libgcrypt-grub/cipher/elgamal.c -grub-core/lib/libgcrypt-grub/cipher/init.c -grub-core/lib/libgcrypt-grub/cipher/md4.c -grub-core/lib/libgcrypt-grub/cipher/md5.c -grub-core/lib/libgcrypt-grub/cipher/primegen.c -grub-core/lib/libgcrypt-grub/cipher/rfc2268.c -grub-core/lib/libgcrypt-grub/cipher/rijndael.c -grub-core/lib/libgcrypt-grub/cipher/rmd160.c -grub-core/lib/libgcrypt-grub/cipher/rsa.c -grub-core/lib/libgcrypt-grub/cipher/seed.c -grub-core/lib/libgcrypt-grub/cipher/serpent.c -grub-core/lib/libgcrypt-grub/cipher/sha1.c -grub-core/lib/libgcrypt-grub/cipher/sha256.c -grub-core/lib/libgcrypt-grub/cipher/sha512.c -grub-core/lib/libgcrypt-grub/cipher/tiger.c -grub-core/lib/libgcrypt-grub/cipher/twofish.c -grub-core/lib/libgcrypt-grub/cipher/whirlpool.c -grub-core/lib/LzFind.c -grub-core/lib/LzmaDec.c -grub-core/lib/LzmaEnc.c -grub-core/lib/mips/relocator.c -grub-core/lib/pbkdf2.c -grub-core/lib/powerpc/relocator.c -grub-core/lib/reed_solomon.c -grub-core/lib/relocator.c -grub-core/lib/xzembed/xz_dec_bcj.c -grub-core/lib/xzembed/xz_dec_lzma2.c -grub-core/lib/xzembed/xz_dec_stream.c -grub-core/loader/aout.c -grub-core/loader/efi/appleloader.c -grub-core/loader/efi/chainloader.c -grub-core/loader/i386/bsd32.c -grub-core/loader/i386/bsd64.c -grub-core/loader/i386/bsd.c -grub-core/loader/i386/bsd_pagetable.c -grub-core/loader/i386/bsdXX.c -grub-core/loader/i386/coreboot/chainloader.c -grub-core/loader/i386/linux.c -grub-core/loader/i386/multiboot_mbi.c -grub-core/loader/i386/pc/chainloader.c -grub-core/loader/i386/pc/freedos.c -grub-core/loader/i386/pc/linux.c -grub-core/loader/i386/pc/ntldr.c -grub-core/loader/i386/xnu.c -grub-core/loader/ia64/efi/linux.c -grub-core/loader/macho32.c -grub-core/loader/macho64.c -grub-core/loader/macho.c -grub-core/loader/machoXX.c -grub-core/loader/mips/linux.c -grub-core/loader/multiboot.c -grub-core/loader/multiboot_elfxx.c -grub-core/loader/multiboot_mbi2.c -grub-core/loader/powerpc/ieee1275/linux.c -grub-core/loader/sparc64/ieee1275/linux.c -grub-core/loader/xnu.c -grub-core/loader/xnu_resume.c -grub-core/mmap/efi/mmap.c -grub-core/mmap/i386/mmap.c -grub-core/mmap/i386/pc/mmap.c -grub-core/mmap/i386/uppermem.c -grub-core/mmap/mips/uppermem.c -grub-core/mmap/mmap.c -grub-core/net/arp.c -grub-core/net/bootp.c -grub-core/net/drivers/efi/efinet.c -grub-core/net/drivers/emu/emunet.c -grub-core/net/drivers/i386/pc/pxe.c -grub-core/net/drivers/ieee1275/ofnet.c -grub-core/net/ethernet.c -grub-core/net/ip.c -grub-core/net/netbuff.c -grub-core/net/net.c -grub-core/net/tftp.c -grub-core/net/udp.c -grub-core/normal/auth.c -grub-core/normal/autofs.c -grub-core/normal/charset.c -grub-core/normal/cmdline.c -grub-core/normal/color.c -grub-core/normal/completion.c -grub-core/normal/context.c -grub-core/normal/crypto.c -grub-core/normal/datetime.c -grub-core/normal/dyncmd.c -grub-core/normal/main.c -grub-core/normal/menu.c -grub-core/normal/menu_entry.c -grub-core/normal/menu_text.c -grub-core/normal/misc.c -grub-core/normal/term.c -grub-core/partmap/acorn.c -grub-core/partmap/amiga.c -grub-core/partmap/apple.c -grub-core/partmap/bsdlabel.c -grub-core/partmap/dvh.c -grub-core/partmap/gpt.c -grub-core/partmap/msdos.c -grub-core/partmap/sun.c -grub-core/partmap/sunpc.c -grub-core/parttool/msdospart.c -grub-core/script/argv.c -grub-core/script/execute.c -grub-core/script/function.c -grub-core/script/lexer.c -grub-core/script/main.c -grub-core/script/script.c -grub-core/term/arc/console.c -grub-core/term/at_keyboard.c -grub-core/term/efi/console.c -grub-core/term/gfxterm.c -grub-core/term/i386/pc/console.c -grub-core/term/i386/pc/vga_text.c -grub-core/term/i386/vga_common.c -grub-core/term/ieee1275/ofconsole.c -grub-core/term/ns8250.c -grub-core/term/serial.c -grub-core/term/terminfo.c -grub-core/term/tparm.c -grub-core/term/usb_keyboard.c -grub-core/tests/example_functional_test.c -grub-core/tests/lib/functional_test.c -grub-core/tests/lib/test.c -grub-core/tests/test_blockarg.c -grub-core/unidata.c -grub-core/video/bitmap.c -grub-core/video/bitmap_scale.c -grub-core/video/bochs.c -grub-core/video/cirrus.c -grub-core/video/colors.c -grub-core/video/efi_gop.c -grub-core/video/efi_uga.c -grub-core/video/emu/sdl.c -grub-core/video/fb/fbblit.c -grub-core/video/fb/fbfill.c -grub-core/video/fb/fbutil.c -grub-core/video/fb/video_fb.c -grub-core/video/i386/pc/vbe.c -grub-core/video/i386/pc/vga.c -grub-core/video/ieee1275.c -grub-core/video/readers/jpeg.c -grub-core/video/readers/png.c -grub-core/video/readers/tga.c -grub-core/video/sis315_init.c -grub-core/video/sis315pro.c -grub-core/video/sm712.c -grub-core/video/sm712_init.c -grub-core/video/video.c -tests/example_unit_test.c -tests/lib/unit_test.c -util/bin2h.c -util/deviceiter.c -util/devicemap.c -util/grub-editenv.c -util/grub-fstest.c -util/grub-macho2img.c -util/grub-menulst2cfg.c -util/grub-mkdevicemap.c -util/grub-mkfont.c -util/grub-mkimage.c -util/grub-mkimagexx.c -util/grub-mklayout.c -util/grub-mkpasswd-pbkdf2.c -util/grub-mkrelpath.c -util/grub-pe2elf.c -util/grub-probe.c -util/grub-script-check.c -util/grub-setup.c -util/ieee1275/devicemap.c -util/ieee1275/grub-ofpathname.c -util/ieee1275/ofpath.c -util/lvm.c -util/misc.c -util/resolve.c +./grub-core/boot/decompressor/minilib.c +./grub-core/boot/decompressor/none.c +./grub-core/boot/decompressor/xz.c +./grub-core/bus/bonito.c +./grub-core/bus/cs5536.c +./grub-core/bus/emu/pci.c +./grub-core/bus/pci.c +./grub-core/bus/usb/emu/usb.c +./grub-core/bus/usb/ohci.c +./grub-core/bus/usb/serial/common.c +./grub-core/bus/usb/serial/ftdi.c +./grub-core/bus/usb/serial/pl2303.c +./grub-core/bus/usb/uhci.c +./grub-core/bus/usb/usb.c +./grub-core/bus/usb/usbhub.c +./grub-core/bus/usb/usbtrans.c +./grub-core/commands/acpi.c +./grub-core/commands/acpihalt.c +./grub-core/commands/arc/lsdev.c +./grub-core/commands/blocklist.c +./grub-core/commands/boot.c +./grub-core/commands/cat.c +./grub-core/commands/cmp.c +./grub-core/commands/configfile.c +./grub-core/commands/date.c +./grub-core/commands/echo.c +./grub-core/commands/efi/acpi.c +./grub-core/commands/efi/fixvideo.c +./grub-core/commands/efi/loadbios.c +./grub-core/commands/efi/lsefimmap.c +./grub-core/commands/efi/lsefisystab.c +./grub-core/commands/efi/lssal.c +./grub-core/commands/extcmd.c +./grub-core/commands/gptsync.c +./grub-core/commands/halt.c +./grub-core/commands/hashsum.c +./grub-core/commands/hdparm.c +./grub-core/commands/help.c +./grub-core/commands/hexdump.c +./grub-core/commands/i386/cmostest.c +./grub-core/commands/i386/cpuid.c +./grub-core/commands/i386/pc/acpi.c +./grub-core/commands/i386/pc/drivemap.c +./grub-core/commands/i386/pc/halt.c +./grub-core/commands/i386/pc/lsapm.c +./grub-core/commands/i386/pc/play.c +./grub-core/commands/i386/pc/sendkey.c +./grub-core/commands/ieee1275/suspend.c +./grub-core/commands/iorw.c +./grub-core/commands/keylayouts.c +./grub-core/commands/keystatus.c +./grub-core/commands/legacycfg.c +./grub-core/commands/loadenv.c +./grub-core/commands/lsacpi.c +./grub-core/commands/ls.c +./grub-core/commands/lsmmap.c +./grub-core/commands/lspci.c +./grub-core/commands/memrw.c +./grub-core/commands/menuentry.c +./grub-core/commands/minicmd.c +./grub-core/commands/mips/loongson/lsspd.c +./grub-core/commands/parttool.c +./grub-core/commands/password.c +./grub-core/commands/password_pbkdf2.c +./grub-core/commands/probe.c +./grub-core/commands/read.c +./grub-core/commands/reboot.c +./grub-core/commands/regexp.c +./grub-core/commands/search.c +./grub-core/commands/search_file.c +./grub-core/commands/search_label.c +./grub-core/commands/search_uuid.c +./grub-core/commands/search_wrap.c +./grub-core/commands/setpci.c +./grub-core/commands/sleep.c +./grub-core/commands/terminal.c +./grub-core/commands/test.c +./grub-core/commands/testload.c +./grub-core/commands/time.c +./grub-core/commands/true.c +./grub-core/commands/usbtest.c +./grub-core/commands/videoinfo.c +./grub-core/commands/videotest.c +./grub-core/commands/wildcard.c +./grub-core/commands/xnu_uuid.c +./grub-core/disk/AFSplitter.c +./grub-core/disk/ahci.c +./grub-core/disk/arc/arcdisk.c +./grub-core/disk/ata.c +./grub-core/disk/cryptodisk.c +./grub-core/disk/dmraid_nvidia.c +./grub-core/disk/efi/efidisk.c +./grub-core/disk/geli.c +./grub-core/disk/host.c +./grub-core/disk/i386/pc/biosdisk.c +./grub-core/disk/ieee1275/nand.c +./grub-core/disk/ieee1275/ofdisk.c +./grub-core/disk/loopback.c +./grub-core/disk/luks.c +./grub-core/disk/lvm.c +./grub-core/disk/mdraid1x_linux.c +./grub-core/disk/mdraid_linux.c +./grub-core/disk/memdisk.c +./grub-core/disk/pata.c +./grub-core/disk/raid5_recover.c +./grub-core/disk/raid6_recover.c +./grub-core/disk/raid.c +./grub-core/disk/scsi.c +./grub-core/disk/usbms.c +./grub-core/efiemu/i386/coredetect.c +./grub-core/efiemu/i386/loadcore32.c +./grub-core/efiemu/i386/loadcore64.c +./grub-core/efiemu/i386/nocfgtables.c +./grub-core/efiemu/i386/pc/cfgtables.c +./grub-core/efiemu/loadcore32.c +./grub-core/efiemu/loadcore64.c +./grub-core/efiemu/loadcore.c +./grub-core/efiemu/loadcore_common.c +./grub-core/efiemu/main.c +./grub-core/efiemu/mm.c +./grub-core/efiemu/pnvram.c +./grub-core/efiemu/prepare32.c +./grub-core/efiemu/prepare64.c +./grub-core/efiemu/prepare.c +./grub-core/efiemu/runtime/efiemu.c +./grub-core/efiemu/symbols.c +./grub-core/font/font.c +./grub-core/font/font_cmd.c +./grub-core/fs/affs.c +./grub-core/fs/afs_be.c +./grub-core/fs/afs.c +./grub-core/fs/befs_be.c +./grub-core/fs/befs.c +./grub-core/fs/btrfs.c +./grub-core/fs/cpio.c +./grub-core/fs/ext2.c +./grub-core/fs/fat.c +./grub-core/fs/fshelp.c +./grub-core/fs/hfs.c +./grub-core/fs/hfsplus.c +./grub-core/fs/iso9660.c +./grub-core/fs/jfs.c +./grub-core/fs/minix2.c +./grub-core/fs/minix3.c +./grub-core/fs/minix.c +./grub-core/fs/nilfs2.c +./grub-core/fs/ntfs.c +./grub-core/fs/ntfscomp.c +./grub-core/fs/reiserfs.c +./grub-core/fs/romfs.c +./grub-core/fs/sfs.c +./grub-core/fs/squash4.c +./grub-core/fs/tar.c +./grub-core/fs/udf.c +./grub-core/fs/ufs2.c +./grub-core/fs/ufs.c +./grub-core/fs/xfs.c +./grub-core/fs/zfs/zfs.c +./grub-core/fs/zfs/zfs_fletcher.c +./grub-core/fs/zfs/zfsinfo.c +./grub-core/fs/zfs/zfs_lzjb.c +./grub-core/fs/zfs/zfs_sha256.c +./grub-core/gentrigtables.c +./grub-core/gettext/gettext.c +./grub-core/gfxmenu/font.c +./grub-core/gfxmenu/gfxmenu.c +./grub-core/gfxmenu/gui_box.c +./grub-core/gfxmenu/gui_canvas.c +./grub-core/gfxmenu/gui_circular_progress.c +./grub-core/gfxmenu/gui_image.c +./grub-core/gfxmenu/gui_label.c +./grub-core/gfxmenu/gui_list.c +./grub-core/gfxmenu/gui_progress_bar.c +./grub-core/gfxmenu/gui_string_util.c +./grub-core/gfxmenu/gui_util.c +./grub-core/gfxmenu/icon_manager.c +./grub-core/gfxmenu/model.c +./grub-core/gfxmenu/theme_loader.c +./grub-core/gfxmenu/view.c +./grub-core/gfxmenu/widget-box.c +./grub-core/gnulib/alloca.c +./grub-core/gnulib/argp-ba.c +./grub-core/gnulib/argp-eexst.c +./grub-core/gnulib/argp-fmtstream.c +./grub-core/gnulib/argp-fs-xinl.c +./grub-core/gnulib/argp-help.c +./grub-core/gnulib/argp-parse.c +./grub-core/gnulib/argp-pin.c +./grub-core/gnulib/argp-pv.c +./grub-core/gnulib/argp-pvh.c +./grub-core/gnulib/argp-xinl.c +./grub-core/gnulib/asnprintf.c +./grub-core/gnulib/basename-lgpl.c +./grub-core/gnulib/btowc.c +./grub-core/gnulib/dirname-lgpl.c +./grub-core/gnulib/error.c +./grub-core/gnulib/fnmatch.c +./grub-core/gnulib/fnmatch_loop.c +./grub-core/gnulib/getdelim.c +./grub-core/gnulib/getline.c +./grub-core/gnulib/getopt1.c +./grub-core/gnulib/getopt.c +./grub-core/gnulib/localcharset.c +./grub-core/gnulib/malloc.c +./grub-core/gnulib/mbrtowc.c +./grub-core/gnulib/mbsinit.c +./grub-core/gnulib/mbsrtowcs.c +./grub-core/gnulib/mbsrtowcs-state.c +./grub-core/gnulib/memchr.c +./grub-core/gnulib/mempcpy.c +./grub-core/gnulib/nl_langinfo.c +./grub-core/gnulib/printf-args.c +./grub-core/gnulib/printf-parse.c +./grub-core/gnulib/progname.c +./grub-core/gnulib/rawmemchr.c +./grub-core/gnulib/realloc.c +./grub-core/gnulib/regcomp.c +./grub-core/gnulib/regex.c +./grub-core/gnulib/regexec.c +./grub-core/gnulib/regex_internal.c +./grub-core/gnulib/sleep.c +./grub-core/gnulib/stdio-write.c +./grub-core/gnulib/strcasecmp.c +./grub-core/gnulib/strchrnul.c +./grub-core/gnulib/strerror.c +./grub-core/gnulib/stripslash.c +./grub-core/gnulib/strncasecmp.c +./grub-core/gnulib/strndup.c +./grub-core/gnulib/strnlen1.c +./grub-core/gnulib/strnlen.c +./grub-core/gnulib/vasnprintf.c +./grub-core/gnulib/vsnprintf.c +./grub-core/gnulib/wcrtomb.c +./grub-core/hello/hello.c +./grub-core/hook/datehook.c +./grub-core/io/bufio.c +./grub-core/io/gzio.c +./grub-core/io/xzio.c +./grub-core/kern/command.c +./grub-core/kern/corecmd.c +./grub-core/kern/device.c +./grub-core/kern/disk.c +./grub-core/kern/dl.c +./grub-core/kern/efi/efi.c +./grub-core/kern/efi/init.c +./grub-core/kern/efi/mm.c +./grub-core/kern/elf.c +./grub-core/kern/emu/cache.c +./grub-core/kern/emu/console.c +./grub-core/kern/emu/full.c +./grub-core/kern/emu/hostdisk.c +./grub-core/kern/emu/hostfs.c +./grub-core/kern/emu/lite.c +./grub-core/kern/emu/main.c +./grub-core/kern/emu/misc.c +./grub-core/kern/emu/mm.c +./grub-core/kern/emu/time.c +./grub-core/kern/env.c +./grub-core/kern/err.c +./grub-core/kern/file.c +./grub-core/kern/fs.c +./grub-core/kern/generic/millisleep.c +./grub-core/kern/generic/rtc_get_time_ms.c +./grub-core/kern/i386/coreboot/init.c +./grub-core/kern/i386/coreboot/mmap.c +./grub-core/kern/i386/dl.c +./grub-core/kern/i386/efi/init.c +./grub-core/kern/i386/multiboot_mmap.c +./grub-core/kern/i386/pc/init.c +./grub-core/kern/i386/pc/mmap.c +./grub-core/kern/i386/pit.c +./grub-core/kern/i386/qemu/mmap.c +./grub-core/kern/i386/tsc.c +./grub-core/kern/ia64/dl.c +./grub-core/kern/ia64/dl_helper.c +./grub-core/kern/ia64/efi/init.c +./grub-core/kern/ieee1275/cmain.c +./grub-core/kern/ieee1275/ieee1275.c +./grub-core/kern/ieee1275/init.c +./grub-core/kern/ieee1275/mmap.c +./grub-core/kern/ieee1275/openfw.c +./grub-core/kern/list.c +./grub-core/kern/main.c +./grub-core/kern/mips/arc/init.c +./grub-core/kern/mips/dl.c +./grub-core/kern/mips/init.c +./grub-core/kern/mips/loongson/init.c +./grub-core/kern/mips/qemu_mips/init.c +./grub-core/kern/misc.c +./grub-core/kern/mm.c +./grub-core/kern/parser.c +./grub-core/kern/partition.c +./grub-core/kern/powerpc/dl.c +./grub-core/kern/rescue_parser.c +./grub-core/kern/rescue_reader.c +./grub-core/kern/sparc64/dl.c +./grub-core/kern/sparc64/ieee1275/ieee1275.c +./grub-core/kern/term.c +./grub-core/kern/time.c +./grub-core/kern/vga_init.c +./grub-core/kern/x86_64/dl.c +./grub-core/lib/arc/datetime.c +./grub-core/lib/arg.c +./grub-core/lib/cmdline.c +./grub-core/lib/cmos_datetime.c +./grub-core/lib/crc.c +./grub-core/lib/crypto.c +./grub-core/lib/efi/datetime.c +./grub-core/lib/efi/halt.c +./grub-core/lib/efi/relocator.c +./grub-core/lib/emu/halt.c +./grub-core/lib/envblk.c +./grub-core/lib/hexdump.c +./grub-core/lib/i386/halt.c +./grub-core/lib/i386/pc/biosnum.c +./grub-core/lib/i386/pc/vesa_modes_table.c +./grub-core/lib/i386/relocator.c +./grub-core/lib/ieee1275/cmos.c +./grub-core/lib/ieee1275/datetime.c +./grub-core/lib/ieee1275/halt.c +./grub-core/lib/ieee1275/relocator.c +./grub-core/lib/legacy_parse.c +./grub-core/lib/libgcrypt/cipher/ac.c +./grub-core/lib/libgcrypt/cipher/arcfour.c +./grub-core/lib/libgcrypt/cipher/blowfish.c +./grub-core/lib/libgcrypt/cipher/camellia.c +./grub-core/lib/libgcrypt/cipher/camellia-glue.c +./grub-core/lib/libgcrypt/cipher/cast5.c +./grub-core/lib/libgcrypt/cipher/cipher.c +./grub-core/lib/libgcrypt/cipher/crc.c +./grub-core/lib/libgcrypt/cipher/des.c +./grub-core/lib/libgcrypt/cipher/dsa.c +./grub-core/lib/libgcrypt/cipher/ecc.c +./grub-core/lib/libgcrypt/cipher/elgamal.c +./grub-core/lib/libgcrypt/cipher/hash-common.c +./grub-core/lib/libgcrypt/cipher/hmac-tests.c +./grub-core/lib/libgcrypt/cipher/md4.c +./grub-core/lib/libgcrypt/cipher/md5.c +./grub-core/lib/libgcrypt/cipher/md.c +./grub-core/lib/libgcrypt/cipher/primegen.c +./grub-core/lib/libgcrypt/cipher/pubkey.c +./grub-core/lib/libgcrypt/cipher/rfc2268.c +./grub-core/lib/libgcrypt/cipher/rijndael.c +./grub-core/lib/libgcrypt/cipher/rmd160.c +./grub-core/lib/libgcrypt/cipher/rsa.c +./grub-core/lib/libgcrypt/cipher/seed.c +./grub-core/lib/libgcrypt/cipher/serpent.c +./grub-core/lib/libgcrypt/cipher/sha1.c +./grub-core/lib/libgcrypt/cipher/sha256.c +./grub-core/lib/libgcrypt/cipher/sha512.c +./grub-core/lib/libgcrypt/cipher/tiger.c +./grub-core/lib/libgcrypt/cipher/twofish.c +./grub-core/lib/libgcrypt/cipher/whirlpool.c +./grub-core/lib/libgcrypt-grub/cipher/arcfour.c +./grub-core/lib/libgcrypt-grub/cipher/blowfish.c +./grub-core/lib/libgcrypt-grub/cipher/camellia.c +./grub-core/lib/libgcrypt-grub/cipher/camellia-glue.c +./grub-core/lib/libgcrypt-grub/cipher/cast5.c +./grub-core/lib/libgcrypt-grub/cipher/crc.c +./grub-core/lib/libgcrypt-grub/cipher/des.c +./grub-core/lib/libgcrypt-grub/cipher/dsa.c +./grub-core/lib/libgcrypt-grub/cipher/ecc.c +./grub-core/lib/libgcrypt-grub/cipher/elgamal.c +./grub-core/lib/libgcrypt-grub/cipher/init.c +./grub-core/lib/libgcrypt-grub/cipher/md4.c +./grub-core/lib/libgcrypt-grub/cipher/md5.c +./grub-core/lib/libgcrypt-grub/cipher/primegen.c +./grub-core/lib/libgcrypt-grub/cipher/rfc2268.c +./grub-core/lib/libgcrypt-grub/cipher/rijndael.c +./grub-core/lib/libgcrypt-grub/cipher/rmd160.c +./grub-core/lib/libgcrypt-grub/cipher/rsa.c +./grub-core/lib/libgcrypt-grub/cipher/seed.c +./grub-core/lib/libgcrypt-grub/cipher/serpent.c +./grub-core/lib/libgcrypt-grub/cipher/sha1.c +./grub-core/lib/libgcrypt-grub/cipher/sha256.c +./grub-core/lib/libgcrypt-grub/cipher/sha512.c +./grub-core/lib/libgcrypt-grub/cipher/tiger.c +./grub-core/lib/libgcrypt-grub/cipher/twofish.c +./grub-core/lib/libgcrypt-grub/cipher/whirlpool.c +./grub-core/lib/LzFind.c +./grub-core/lib/LzmaDec.c +./grub-core/lib/LzmaEnc.c +./grub-core/lib/mips/relocator.c +./grub-core/lib/pbkdf2.c +./grub-core/lib/powerpc/relocator.c +./grub-core/lib/reed_solomon.c +./grub-core/lib/relocator.c +./grub-core/lib/xzembed/xz_dec_bcj.c +./grub-core/lib/xzembed/xz_dec_lzma2.c +./grub-core/lib/xzembed/xz_dec_stream.c +./grub-core/loader/aout.c +./grub-core/loader/efi/appleloader.c +./grub-core/loader/efi/chainloader.c +./grub-core/loader/i386/bsd32.c +./grub-core/loader/i386/bsd64.c +./grub-core/loader/i386/bsd.c +./grub-core/loader/i386/bsd_pagetable.c +./grub-core/loader/i386/bsdXX.c +./grub-core/loader/i386/coreboot/chainloader.c +./grub-core/loader/i386/linux.c +./grub-core/loader/i386/multiboot_mbi.c +./grub-core/loader/i386/pc/chainloader.c +./grub-core/loader/i386/pc/freedos.c +./grub-core/loader/i386/pc/linux.c +./grub-core/loader/i386/pc/ntldr.c +./grub-core/loader/i386/xnu.c +./grub-core/loader/ia64/efi/linux.c +./grub-core/loader/macho32.c +./grub-core/loader/macho64.c +./grub-core/loader/macho.c +./grub-core/loader/machoXX.c +./grub-core/loader/mips/linux.c +./grub-core/loader/multiboot.c +./grub-core/loader/multiboot_elfxx.c +./grub-core/loader/multiboot_mbi2.c +./grub-core/loader/powerpc/ieee1275/linux.c +./grub-core/loader/sparc64/ieee1275/linux.c +./grub-core/loader/xnu.c +./grub-core/loader/xnu_resume.c +./grub-core/mmap/efi/mmap.c +./grub-core/mmap/i386/mmap.c +./grub-core/mmap/i386/pc/mmap.c +./grub-core/mmap/i386/uppermem.c +./grub-core/mmap/mips/uppermem.c +./grub-core/mmap/mmap.c +./grub-core/net/arp.c +./grub-core/net/bootp.c +./grub-core/net/drivers/efi/efinet.c +./grub-core/net/drivers/emu/emunet.c +./grub-core/net/drivers/i386/pc/pxe.c +./grub-core/net/drivers/ieee1275/ofnet.c +./grub-core/net/ethernet.c +./grub-core/net/ip.c +./grub-core/net/netbuff.c +./grub-core/net/net.c +./grub-core/net/tftp.c +./grub-core/net/udp.c +./grub-core/normal/auth.c +./grub-core/normal/autofs.c +./grub-core/normal/charset.c +./grub-core/normal/cmdline.c +./grub-core/normal/color.c +./grub-core/normal/completion.c +./grub-core/normal/context.c +./grub-core/normal/crypto.c +./grub-core/normal/datetime.c +./grub-core/normal/dyncmd.c +./grub-core/normal/main.c +./grub-core/normal/menu.c +./grub-core/normal/menu_entry.c +./grub-core/normal/menu_text.c +./grub-core/normal/misc.c +./grub-core/normal/term.c +./grub-core/partmap/acorn.c +./grub-core/partmap/amiga.c +./grub-core/partmap/apple.c +./grub-core/partmap/bsdlabel.c +./grub-core/partmap/dvh.c +./grub-core/partmap/gpt.c +./grub-core/partmap/msdos.c +./grub-core/partmap/sun.c +./grub-core/partmap/sunpc.c +./grub-core/parttool/msdospart.c +./grub-core/script/argv.c +./grub-core/script/execute.c +./grub-core/script/function.c +./grub-core/script/lexer.c +./grub-core/script/main.c +./grub-core/script/script.c +./grub-core/term/arc/console.c +./grub-core/term/at_keyboard.c +./grub-core/term/efi/console.c +./grub-core/term/gfxterm.c +./grub-core/term/i386/pc/console.c +./grub-core/term/i386/pc/vga_text.c +./grub-core/term/i386/vga_common.c +./grub-core/term/ieee1275/ofconsole.c +./grub-core/term/ns8250.c +./grub-core/term/serial.c +./grub-core/term/terminfo.c +./grub-core/term/tparm.c +./grub-core/term/usb_keyboard.c +./grub-core/tests/example_functional_test.c +./grub-core/tests/lib/functional_test.c +./grub-core/tests/lib/test.c +./grub-core/tests/test_blockarg.c +./grub-core/unidata.c +./grub-core/video/bitmap.c +./grub-core/video/bitmap_scale.c +./grub-core/video/bochs.c +./grub-core/video/cirrus.c +./grub-core/video/colors.c +./grub-core/video/efi_gop.c +./grub-core/video/efi_uga.c +./grub-core/video/emu/sdl.c +./grub-core/video/fb/fbblit.c +./grub-core/video/fb/fbfill.c +./grub-core/video/fb/fbutil.c +./grub-core/video/fb/video_fb.c +./grub-core/video/i386/pc/vbe.c +./grub-core/video/i386/pc/vga.c +./grub-core/video/ieee1275.c +./grub-core/video/readers/jpeg.c +./grub-core/video/readers/png.c +./grub-core/video/readers/tga.c +./grub-core/video/sis315_init.c +./grub-core/video/sis315pro.c +./grub-core/video/sm712.c +./grub-core/video/sm712_init.c +./grub-core/video/video.c +./tests/example_unit_test.c +./tests/lib/unit_test.c +./util/bin2h.c +./util/deviceiter.c +./util/devicemap.c +./util/getroot.c +./util/grub-editenv.c +./util/grub-fstest.c +./util/grub-macho2img.c +./util/grub-menulst2cfg.c +./util/grub-mkdevicemap.c +./util/grub-mkfont.c +./util/grub-mkimage.c +./util/grub-mkimagexx.c +./util/grub-mklayout.c +./util/grub-mkpasswd-pbkdf2.c +./util/grub-mkrelpath.c +./util/grub-pe2elf.c +./util/grub-probe.c +./util/grub-script-check.c +./util/grub-setup.c +./util/ieee1275/devicemap.c +./util/ieee1275/grub-ofpathname.c +./util/ieee1275/ofpath.c +./util/lvm.c +./util/misc.c +./util/raid.c +./util/resolve.c From ca5572a9ad872fd26712d0fbae1ab63adc64787b Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 10 Jul 2011 16:06:31 +0200 Subject: [PATCH 752/869] * util/grub-install.in: Recognize ESP mounted at /boot/EFI. --- ChangeLog | 4 ++++ util/grub-install.in | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/ChangeLog b/ChangeLog index 84167f226..0b386157c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2011-07-10 Vladimir Serbinenko + + * util/grub-install.in: Recognize ESP mounted at /boot/EFI. + 2011-07-10 Vladimir Serbinenko * po/POTFILES.in: Regenerate. diff --git a/util/grub-install.in b/util/grub-install.in index 711c9c7e2..1e9e1a2fd 100644 --- a/util/grub-install.in +++ b/util/grub-install.in @@ -335,6 +335,12 @@ if [ x"$platform" = xefi ]; then if test "x$install_device" != "x`"$grub_mkdevicemap" --device-map=/dev/stdout | "$grub_probe" --target=device --device-map=/dev/stdin "${bootdir}"`"; then efidir="${bootdir}/efi" fi + elif test -d "${bootdir}/EFI"; then + install_device="`"$grub_mkdevicemap" --device-map=/dev/stdout | "$grub_probe" --target=device --device-map=/dev/stdin "${bootdir}/EFI"`" + # Is it a mount point? + if test "x$install_device" != "x`"$grub_mkdevicemap" --device-map=/dev/stdout | "$grub_probe" --target=device --device-map=/dev/stdin "${bootdir}"`"; then + efidir="${bootdir}/EFI" + fi elif test -n "$rootdir" && test "x$rootdir" != "x/"; then # The EFI System Partition may have been given directly using # --root-directory. From bf66054fb3969fffed65b0fa6dea535ae368a0f8 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 23 Jul 2011 16:44:40 +0200 Subject: [PATCH 753/869] * grub-core/kern/mips/cache_flush.S [GRUB_MACHINE_MIPS_LOONGSON]: Flush all four ways. --- ChangeLog | 5 +++++ grub-core/kern/mips/cache_flush.S | 7 +++++++ 2 files changed, 12 insertions(+) diff --git a/ChangeLog b/ChangeLog index e4ca1a6c3..55f097965 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-07-23 Vladimir Serbinenko + + * grub-core/kern/mips/cache_flush.S [GRUB_MACHINE_MIPS_LOONGSON]: Flush + all four ways. + 2011-07-21 Colin Watson Preferred resolution detection for VBE. diff --git a/grub-core/kern/mips/cache_flush.S b/grub-core/kern/mips/cache_flush.S index a352fd8ba..c03c337b5 100644 --- a/grub-core/kern/mips/cache_flush.S +++ b/grub-core/kern/mips/cache_flush.S @@ -9,6 +9,13 @@ subu $t1, $t3, $t2 1: cache 1, 0($t0) + /* All four ways. */ +#ifdef GRUB_MACHINE_MIPS_LOONGSON + cache 1, 1($t0) + cache 1, 2($t0) + cache 1, 3($t0) +#endif + addiu $t1, $t1, -0x4 bne $t1, $zero, 1b addiu $t0, $t0, 0x4 From a1167439107cc51d864452c7249c994f6b5b2ce1 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 23 Jul 2011 17:14:38 +0200 Subject: [PATCH 754/869] * include/grub/mips/kernel.h: Fix define conflict. --- ChangeLog | 4 ++++ include/grub/mips/kernel.h | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 55f097965..15e7344f2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2011-07-23 Vladimir Serbinenko + + * include/grub/mips/kernel.h: Fix define conflict. + 2011-07-23 Vladimir Serbinenko * grub-core/kern/mips/cache_flush.S [GRUB_MACHINE_MIPS_LOONGSON]: Flush diff --git a/include/grub/mips/kernel.h b/include/grub/mips/kernel.h index d82d0a97d..d351f17cb 100644 --- a/include/grub/mips/kernel.h +++ b/include/grub/mips/kernel.h @@ -16,8 +16,8 @@ * along with GRUB. If not, see . */ -#ifndef GRUB_KERNEL_MACHINE_HEADER -#define GRUB_KERNEL_MACHINE_HEADER 1 +#ifndef GRUB_KERNEL_CPU_HEADER +#define GRUB_KERNEL_CPU_HEADER 1 #include From 6be1c01fd721bbea8353e0c0ad547a2c0056640c Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 23 Jul 2011 17:18:31 +0200 Subject: [PATCH 755/869] * include/grub/video.h: add missing EXPORT_FUND on grub_video_edid_checksum and grub_video_edid_preferred_mode. --- ChangeLog | 5 +++++ include/grub/video.h | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 15e7344f2..71c33569f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-07-23 Vladimir Serbinenko + + * include/grub/video.h: add missing EXPORT_FUND on + grub_video_edid_checksum and grub_video_edid_preferred_mode. + 2011-07-23 Vladimir Serbinenko * include/grub/mips/kernel.h: Fix define conflict. diff --git a/include/grub/video.h b/include/grub/video.h index b2adff11d..e30589a3d 100644 --- a/include/grub/video.h +++ b/include/grub/video.h @@ -486,8 +486,8 @@ grub_err_t EXPORT_FUNC (grub_video_set_active_render_target) (struct grub_video_ grub_err_t grub_video_get_active_render_target (struct grub_video_render_target **target); -grub_err_t grub_video_edid_checksum (struct grub_video_edid_info *edid_info); -grub_err_t grub_video_edid_preferred_mode (struct grub_video_edid_info *edid_info, +grub_err_t EXPORT_FUNC (grub_video_edid_checksum) (struct grub_video_edid_info *edid_info); +grub_err_t EXPORT_FUNC (grub_video_edid_preferred_mode) (struct grub_video_edid_info *edid_info, unsigned int *width, unsigned int *height); From 583168a216e477bfbf6039ddc331d5827833ec08 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 23 Jul 2011 18:18:14 +0200 Subject: [PATCH 756/869] * grub-core/disk/pata.c (grub_pata_readwrite): Add missing wait. --- ChangeLog | 4 ++++ grub-core/disk/pata.c | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/ChangeLog b/ChangeLog index 71c33569f..2eb0c0fcd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2011-07-23 Vladimir Serbinenko + + * grub-core/disk/pata.c (grub_pata_readwrite): Add missing wait. + 2011-07-23 Vladimir Serbinenko * include/grub/video.h: add missing EXPORT_FUND on diff --git a/grub-core/disk/pata.c b/grub-core/disk/pata.c index ff6f77366..c54fe91ab 100644 --- a/grub-core/disk/pata.c +++ b/grub-core/disk/pata.c @@ -177,6 +177,10 @@ grub_pata_readwrite (struct grub_ata *disk, /* Start command. */ grub_pata_regset (dev, GRUB_ATA_REG_CMD, parms->taskfile.cmd); + /* Wait for !BSY. */ + if (grub_pata_wait_not_busy (dev, GRUB_ATA_TOUT_DATA)) + return grub_errno; + /* Check status. */ grub_int8_t sts = grub_pata_regget (dev, GRUB_ATA_REG_STATUS); grub_dprintf ("pata", "status=0x%x\n", sts); From b70e4cb08d055181585c9b1d3e7a0366e90d17f5 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 25 Jul 2011 07:48:19 +0200 Subject: [PATCH 757/869] * grub-core/normal/menu.c (grub_menu_execute_entry): Fix NULL dereference. --- ChangeLog | 5 +++++ grub-core/normal/menu.c | 7 +++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2eb0c0fcd..5069e5651 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-07-23 Vladimir Serbinenko + + * grub-core/normal/menu.c (grub_menu_execute_entry): Fix NULL + dereference. + 2011-07-23 Vladimir Serbinenko * grub-core/disk/pata.c (grub_pata_readwrite): Add missing wait. diff --git a/grub-core/normal/menu.c b/grub-core/normal/menu.c index 5844cb2f0..2c127794b 100644 --- a/grub-core/normal/menu.c +++ b/grub-core/normal/menu.c @@ -232,7 +232,8 @@ grub_menu_execute_entry(grub_menu_entry_t entry, int auto_boot) grub_env_export ("chosen"); grub_free (buf); } - for (ptr = def; *ptr; ptr++) + + for (ptr = def; ptr && *ptr; ptr++) { if (ptr[0] == '>' && ptr[1] == '>') { @@ -242,10 +243,12 @@ grub_menu_execute_entry(grub_menu_entry_t entry, int auto_boot) if (ptr[0] == '>') break; } - if (ptr[0] && ptr[1]) + + if (ptr && ptr[0] && ptr[1]) grub_env_set ("default", ptr + 1); else grub_env_unset ("default"); + grub_script_execute_sourcecode (entry->sourcecode, entry->argc, entry->args); if (errs_before != grub_err_printed_errors) From c77069f5ae4107323bf71c8c9d8505048acae740 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 25 Jul 2011 07:57:29 +0200 Subject: [PATCH 758/869] * util/grub-mkrescue.in: Add missing quotes. --- ChangeLog | 6 +++++- util/grub-mkrescue.in | 14 +++++++------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5069e5651..570de50e1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,8 @@ -2011-07-23 Vladimir Serbinenko +2011-07-25 Vladimir Serbinenko + + * util/grub-mkrescue.in: Add missing quotes. + +2011-07-25 Vladimir Serbinenko * grub-core/normal/menu.c (grub_menu_execute_entry): Fix NULL dereference. diff --git a/util/grub-mkrescue.in b/util/grub-mkrescue.in index f054c43a9..4c96dd42b 100644 --- a/util/grub-mkrescue.in +++ b/util/grub-mkrescue.in @@ -31,15 +31,15 @@ pkglib_DATA="moddep.lst command.lst fs.lst partmap.lst parttool.lst handler.lst self=`basename $0` -multiboot_dir=${libdir}/$(echo ${PACKAGE_TARNAME} | sed ${transform})/i386-multiboot -coreboot_dir=${libdir}/$(echo ${PACKAGE_TARNAME} | sed ${transform})/i386-coreboot -qemu_dir=${libdir}/$(echo ${PACKAGE_TARNAME} | sed ${transform})/i386-qemu -pc_dir=${libdir}/$(echo ${PACKAGE_TARNAME} | sed ${transform})/i386-pc -efi32_dir=${libdir}/$(echo ${PACKAGE_TARNAME} | sed ${transform})/i386-efi -efi64_dir=${libdir}/$(echo ${PACKAGE_TARNAME} | sed ${transform})/x86_64-efi +multiboot_dir="${libdir}/$(echo ${PACKAGE_TARNAME} | sed ${transform})/i386-multiboot" +coreboot_dir="${libdir}/$(echo ${PACKAGE_TARNAME} | sed ${transform})/i386-coreboot" +qemu_dir="${libdir}/$(echo ${PACKAGE_TARNAME} | sed ${transform})/i386-qemu" +pc_dir="${libdir}/$(echo ${PACKAGE_TARNAME} | sed ${transform})/i386-pc" +efi32_dir="${libdir}/$(echo ${PACKAGE_TARNAME} | sed ${transform})/i386-efi" +efi64_dir="${libdir}/$(echo ${PACKAGE_TARNAME} | sed ${transform})/x86_64-efi" rom_directory= override_dir= -grub_mkimage=${bindir}/`echo grub-mkimage | sed ${transform}` +grub_mkimage="${bindir}/`echo grub-mkimage | sed ${transform}`" xorriso=xorriso From 922275976579ecd9ebaa88eba3fb5e8933e9c93f Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 25 Jul 2011 08:06:20 +0200 Subject: [PATCH 759/869] * util/grub-install.in: Don't use uhci outside of x86. --- ChangeLog | 4 ++++ util/grub-install.in | 6 +++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 570de50e1..32dfada58 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2011-07-25 Vladimir Serbinenko + + * util/grub-install.in: Don't use uhci outside of x86. + 2011-07-25 Vladimir Serbinenko * util/grub-mkrescue.in: Add missing quotes. diff --git a/util/grub-install.in b/util/grub-install.in index 1e9e1a2fd..3d2420b91 100644 --- a/util/grub-install.in +++ b/util/grub-install.in @@ -504,7 +504,11 @@ if [ "x$disk_module" = xata ]; then fi if [ "x$disk_module" = xnative ]; then - disk_module="pata ahci ohci uhci usbms" + disk_module="pata ahci ohci" + if [ "x$target_cpu" = "xi386" ] || [ "x$target_cpu" = "xx86_64" ]; then + disk_module="$disk_module uhci" + fi + disk_module="$disk_module usbms" fi # The order in this list is critical. Be careful when modifying it. From 6795300e7f230ac552c984ef051f0ae79f318bcf Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 25 Jul 2011 08:14:34 +0200 Subject: [PATCH 760/869] Support ATA disks with 4K sectors. * include/grub/ata.h (grub_ata): New member log_sector_size. * grub-core/disk/ata.c (grub_ata_dumpinfo): Show sector size. (grub_ata_identify): Read sector size. (grub_ata_readwrite): Use log_sector_size rather than hardcoded value. --- ChangeLog | 9 +++++++++ grub-core/disk/ata.c | 23 ++++++++++++++++++++--- include/grub/ata.h | 1 + 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 32dfada58..5c4e20c28 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2011-07-25 Vladimir Serbinenko + + Support ATA disks with non-4K sectors. + + * include/grub/ata.h (grub_ata): New member log_sector_size. + * grub-core/disk/ata.c (grub_ata_dumpinfo): Show sector size. + (grub_ata_identify): Read sector size. + (grub_ata_readwrite): Use log_sector_size rather than hardcoded value. + 2011-07-25 Vladimir Serbinenko * util/grub-install.in: Don't use uhci outside of x86. diff --git a/grub-core/disk/ata.c b/grub-core/disk/ata.c index 8add7f4de..330635f57 100644 --- a/grub-core/disk/ata.c +++ b/grub-core/disk/ata.c @@ -57,6 +57,7 @@ grub_ata_dumpinfo (struct grub_ata *dev, char *info) { grub_dprintf ("ata", "Addressing: %d\n", dev->addr); grub_dprintf ("ata", "Sectors: %lld\n", (unsigned long long) dev->size); + grub_dprintf ("ata", "Sector size: %u\n", 1U << dev->log_sector_size); } } @@ -170,6 +171,21 @@ grub_ata_identify (struct grub_ata *dev) else dev->size = grub_le_to_cpu64(*((grub_uint64_t *) &info16[100])); + if (info16[106] & (1 << 12)) + { + grub_uint32_t secsize; + secsize = grub_le_to_cpu32 (*((grub_uint32_t *) &info16[117])); + if (secsize & (secsize - 1) || !secsize + || secsize > 1048576) + secsize = 256; + for (dev->log_sector_size = 0; + (1U << dev->log_sector_size) < secsize; + dev->log_sector_size++); + dev->log_sector_size++; + } + else + dev->log_sector_size = 9; + /* Read CHS information. */ dev->cylinders = info16[1]; dev->heads = info16[3]; @@ -314,7 +330,7 @@ grub_ata_readwrite (grub_disk_t disk, grub_disk_addr_t sector, grub_ata_setaddress (ata, &parms, sector, batch, addressing); parms.taskfile.cmd = (! rw ? cmd : cmd_write); parms.buffer = buf; - parms.size = batch * GRUB_DISK_SECTOR_SIZE; + parms.size = batch << ata->log_sector_size; parms.write = rw; if (ata->dma) parms.dma = 1; @@ -322,9 +338,9 @@ grub_ata_readwrite (grub_disk_t disk, grub_disk_addr_t sector, err = ata->dev->readwrite (ata, &parms, 0); if (err) return err; - if (parms.size != batch * GRUB_DISK_SECTOR_SIZE) + if (parms.size != batch << ata->log_sector_size) return grub_error (GRUB_ERR_READ_ERROR, "incomplete read"); - buf += GRUB_DISK_SECTOR_SIZE * batch; + buf += batch << ata->log_sector_size; sector += batch; nsectors += batch; } @@ -433,6 +449,7 @@ grub_ata_open (const char *name, grub_disk_t disk) return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "not an ATA harddisk"); disk->total_sectors = ata->size; + disk->log_sector_size = ata->log_sector_size; disk->id = grub_make_scsi_id (id, bus, 0); diff --git a/include/grub/ata.h b/include/grub/ata.h index 6938b6a42..1a19f27aa 100644 --- a/include/grub/ata.h +++ b/include/grub/ata.h @@ -170,6 +170,7 @@ struct grub_ata /* Sector count. */ grub_uint64_t size; + grub_uint32_t log_sector_size; /* CHS maximums. */ grub_uint16_t cylinders; From 41aa28ea2a7c90c14016a122ae604c95aa4a8697 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 25 Jul 2011 08:19:30 +0200 Subject: [PATCH 761/869] New script grub-mkstandalone. * Makefile.util.def (grub-mkstandalone): New script. * docs/man/grub-mkstandalone.h2m: New file. * util/grub-mkstandalone.in: Likewise. --- ChangeLog | 10 +- Makefile.util.def | 6 ++ docs/man/grub-mkstandalone.h2m | 4 + util/grub-mkstandalone.in | 189 +++++++++++++++++++++++++++++++++ 4 files changed, 208 insertions(+), 1 deletion(-) create mode 100644 docs/man/grub-mkstandalone.h2m create mode 100644 util/grub-mkstandalone.in diff --git a/ChangeLog b/ChangeLog index 5c4e20c28..2593d598b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,14 @@ 2011-07-25 Vladimir Serbinenko - Support ATA disks with non-4K sectors. + New script grub-mkstandalone. + + * Makefile.util.def (grub-mkstandalone): New script. + * docs/man/grub-mkstandalone.h2m: New file. + * util/grub-mkstandalone.in: Likewise. + +2011-07-25 Vladimir Serbinenko + + Support ATA disks with 4K sectors. * include/grub/ata.h (grub_ata): New member log_sector_size. * grub-core/disk/ata.c (grub_ata_dumpinfo): Show sector size. diff --git a/Makefile.util.def b/Makefile.util.def index c87020493..d86cb9761 100644 --- a/Makefile.util.def +++ b/Makefile.util.def @@ -412,6 +412,12 @@ script = { enable = powerpc_ieee1275; }; +script = { + mansection = 1; + name = grub-mkstandalone; + common = util/grub-mkstandalone.in; +}; + script = { mansection = 8; installdir = sbin; diff --git a/docs/man/grub-mkstandalone.h2m b/docs/man/grub-mkstandalone.h2m new file mode 100644 index 000000000..c77313978 --- /dev/null +++ b/docs/man/grub-mkstandalone.h2m @@ -0,0 +1,4 @@ +[NAME] +grub-mkstandalone \- make a memdisk-based GRUB image +[SEE ALSO] +.BR grub-mkimage (1) diff --git a/util/grub-mkstandalone.in b/util/grub-mkstandalone.in new file mode 100644 index 000000000..aaff99051 --- /dev/null +++ b/util/grub-mkstandalone.in @@ -0,0 +1,189 @@ +#! /bin/sh +set -e + +# Make GRUB rescue image +# Copyright (C) 1999,2000,2001,2002,2003,2004,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 . + +# Initialize some variables. +transform="@program_transform_name@" + +prefix=@prefix@ +exec_prefix=@exec_prefix@ +bindir=@bindir@ +libdir=@libdir@ +PACKAGE_NAME=@PACKAGE_NAME@ +PACKAGE_TARNAME=@PACKAGE_TARNAME@ +PACKAGE_VERSION=@PACKAGE_VERSION@ +pkglib_DATA="moddep.lst command.lst fs.lst partmap.lst parttool.lst handler.lst video.lst crypto.lst terminal.lst" + +self=`basename $0` + +source_dirrectory= +compression=auto +format= +grub_mkimage=${bindir}/`echo grub-mkimage | sed ${transform}` +source= + +# Usage: usage +# Print the usage. +usage () { + cat <. +EOF +} + +argument () { + opt=$1 + shift + + if test $# -eq 0; then + echo "$0: option requires an argument -- '$opt'" 1>&2 + exit 1 + fi + echo $1 +} + +# Check the arguments. +while test $# -gt 0 +do + option=$1 + shift + + case "$option" in + -h | --help) + usage + exit 0 ;; + -v | --version) + echo "$self (${PACKAGE_NAME}) ${PACKAGE_VERSION}" + exit 0 ;; + + --modules) + modules=`argument $option "$@"`; shift ;; + --modules=*) + modules=`echo "$option" | sed 's/--modules=//'` ;; + + -o | --output) + output_image=`argument $option "$@"`; shift ;; + --output=*) + output_image=`echo "$option" | sed 's/--output=//'` ;; + + --directory | -d) + source_directory=`argument $option "$@"`; shift ;; + --directory=*) + source_directory=`echo "$option" | sed 's/--rom-directory=//'` ;; + + --grub-mkimage) + grub_mkimage=`argument $option "$@"`; shift ;; + --grub-mkimage=*) + grub_mkimage=`echo "$option" | sed 's/--grub-mkimage=//'` ;; + + --compression | -C) + compression=`argument $option "$@"`; shift ;; + --compression=*) + compression=`echo "${option}/" | sed 's/--xorriso=//'` ;; + + --format | -O) + format=`argument $option "$@"`; shift ;; + --format=*) + format=`echo "${option}/" | sed 's/--xorriso=//'` ;; + + *) + source="${source} ${option} $@"; break ;; + esac +done + +if [ "x${output_image}" = x ] ; then + echo "output file must be given" >&2 + usage + exit 1 +fi + +if [ "x${format}" = x ] ; then + echo "format must be given" >&2 + usage + exit 1 +fi + +if [ "x$source_directory" = x ] ; then + cpu="`echo $format | awk -F - '{ print $1; }'`" + platform="`echo $format | awk -F - '{ print $2; }'`" + case "$platform" in + yeeloong | fuloong) + platform=loongson ;; + esac + case "$cpu-$platform" in + mips-loongson) + cpu=mipsel ;; + esac + source_directory="${libdir}/$(echo ${PACKAGE_TARNAME} | sed ${transform})/$cpu-$platform" +fi + +set $grub_mkimage dummy +if test -f "$1"; then + : +else + echo "$1: Not found." 1>&2 + exit 1 +fi + +memdisk_dir="`mktemp -d "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"`" || exit 1 +mkdir -p "${memdisk_dir}"/boot/grub + +for file in "${source_directory}/"*.mod "${source_directory}/"efiemu32.o "${source_directory}/"efiemu64.o; do + if test -f "$file"; then + cp -f "$file" "${memdisk_dir}"/boot/grub/ + fi +done +for file in ${pkglib_DATA}; do + if test -f "${source_directory}/${file}"; then + cp -f "${source_directory}/${file}" "${memdisk_dir}"/boot/grub/ + fi +done + +mkdir -p "${memdisk_dir}"/boot/grub/locale +for file in "${source_directory}"/po/*.mo; do + if test -f "$file"; then + cp -f "$file" "${memdisk_dir}"/boot/grub/locale/ + fi +done + +for file in $source; do + cp -f "$file" "${memdisk_dir}"/"$file"; +done + +memdisk_img=`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` || exit 1 + +(cd "${memdisk_dir}"; tar -cf - * $source) > "${memdisk_img}" +rm -rf "${memdisk_dir}" +$grub_mkimage -O "${format}" -C "$compression" -d "${source_directory}" -m "${memdisk_img}" -o "$output_image" --prefix='(memdisk)/boot/grub' memdisk tar $modules +rm -rf "${memdisk_img}" + +exit 0 From 303b6246a3a44d51cf9263b754efbfe0e5f4272a Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Tue, 26 Jul 2011 11:59:47 +0100 Subject: [PATCH 762/869] * util/grub-install.in: Don't source grub-mkconfig_lib until after processing arguments (otherwise help2man fails when GRUB has not yet been installed). --- ChangeLog | 6 ++++++ util/grub-install.in | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2593d598b..fa33902ab 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2011-07-26 Colin Watson + + * util/grub-install.in: Don't source grub-mkconfig_lib until after + processing arguments (otherwise help2man fails when GRUB has not yet + been installed). + 2011-07-25 Vladimir Serbinenko New script grub-mkstandalone. diff --git a/util/grub-install.in b/util/grub-install.in index 3d2420b91..f9e1510d1 100644 --- a/util/grub-install.in +++ b/util/grub-install.in @@ -59,8 +59,6 @@ update_nvram=yes removable=no efi_quiet= -. ${libdir}/@PACKAGE@/grub-mkconfig_lib - # Get GRUB_DISTRIBUTOR. if test -f "${sysconfdir}/default/grub" ; then . "${sysconfdir}/default/grub" @@ -265,6 +263,8 @@ do esac done +. ${libdir}/@PACKAGE@/grub-mkconfig_lib + if test "x$install_device" = x && ([ "${target_cpu}-${platform}" = "i386-pc" ] \ || [ "${target_cpu}-${platform}" = "sparc64-ieee1275" ]); then echo "install_device not specified." 1>&2 From 20168fcafeed3d87f437914a09e35a926c009faa Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Tue, 26 Jul 2011 16:19:47 +0100 Subject: [PATCH 763/869] * configure.ac: The Loongson port requires grub-mkfont due to its use of -DUSE_ASCII_FAILBACK. Raise an error if it is not going to be built. --- ChangeLog | 6 ++++++ configure.ac | 3 +++ 2 files changed, 9 insertions(+) diff --git a/ChangeLog b/ChangeLog index fa33902ab..19e034dc0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2011-07-26 Colin Watson + + * configure.ac: The Loongson port requires grub-mkfont due to its + use of -DUSE_ASCII_FAILBACK. Raise an error if it is not going to + be built. + 2011-07-26 Colin Watson * util/grub-install.in: Don't source grub-mkconfig_lib until after diff --git a/configure.ac b/configure.ac index f674a90aa..e6d726548 100644 --- a/configure.ac +++ b/configure.ac @@ -866,6 +866,9 @@ enable_grub_mkfont=yes else enable_grub_mkfont=no fi +if test x"$enable_grub_mkfont" = xno && test "x$platform" = xloongson; then + AC_MSG_ERROR([loongson port needs grub-mkfont]) +fi AC_SUBST([enable_grub_mkfont]) AC_SUBST([freetype_cflags]) AC_SUBST([freetype_libs]) From 66816d85565bc362b07ce0c623c3379d6b21119e Mon Sep 17 00:00:00 2001 From: Robert Millan Date: Wed, 3 Aug 2011 13:30:46 +0200 Subject: [PATCH 764/869] 2011-08-03 Robert Millan * include/grub/zfs/zap_leaf.h (typedef union zap_leaf_chunk): Mark la_array as packed. Reported by: Zachary Bedell --- ChangeLog | 6 ++++++ include/grub/zfs/zap_leaf.h | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 19e034dc0..184b0d763 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2011-08-03 Robert Millan + + * include/grub/zfs/zap_leaf.h (typedef union zap_leaf_chunk): Mark + la_array as packed. + Reported by: Zachary Bedell + 2011-07-26 Colin Watson * configure.ac: The Loongson port requires grub-mkfont due to its diff --git a/include/grub/zfs/zap_leaf.h b/include/grub/zfs/zap_leaf.h index 1ef654054..5adfdc290 100644 --- a/include/grub/zfs/zap_leaf.h +++ b/include/grub/zfs/zap_leaf.h @@ -90,7 +90,7 @@ typedef union zap_leaf_chunk { { grub_uint8_t la_array[ZAP_LEAF_ARRAY_BYTES]; grub_uint64_t la_array64; - }; + } __attribute__ ((packed)); grub_uint16_t la_next; /* next blk or CHAIN_END */ } l_array; struct zap_leaf_free { From 6dc212f953b2ff19245a125a938e35b8b0f929ba Mon Sep 17 00:00:00 2001 From: Robert Millan Date: Wed, 10 Aug 2011 22:24:02 +0200 Subject: [PATCH 765/869] 2011-08-10 Robert Millan Detect LSI MegaRAID SAS (`mfi') devices on GNU/kFreeBSD. * util/deviceiter.c [__FreeBSD_kernel__] (get_mfi_disk_name): New function. [__FreeBSD_kernel__] (grub_util_iterate_devices): Scan for mfi (/dev/mfid[0-9]+) devices using get_mfi_disk_name(). --- ChangeLog | 9 +++++++++ util/deviceiter.c | 19 +++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/ChangeLog b/ChangeLog index 184b0d763..039621768 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2011-08-10 Robert Millan + + Detect LSI MegaRAID SAS (`mfi') devices on GNU/kFreeBSD. + + * util/deviceiter.c [__FreeBSD_kernel__] (get_mfi_disk_name): New + function. + [__FreeBSD_kernel__] (grub_util_iterate_devices): Scan for mfi + (/dev/mfid[0-9]+) devices using get_mfi_disk_name(). + 2011-08-03 Robert Millan * include/grub/zfs/zap_leaf.h (typedef union zap_leaf_chunk): Mark diff --git a/util/deviceiter.c b/util/deviceiter.c index 2a8acec0e..208dcfdde 100644 --- a/util/deviceiter.c +++ b/util/deviceiter.c @@ -298,6 +298,12 @@ get_ataraid_disk_name (char *name, int unit) { sprintf (name, "/dev/ar%d", unit); } + +static void +get_mfi_disk_name (char *name, int unit) +{ + sprintf (name, "/dev/mfid%d", unit); +} #endif #ifdef __linux__ @@ -661,6 +667,19 @@ grub_util_iterate_devices (int NESTED_FUNC_ATTR (*hook) (const char *, int), goto out; } } + + /* LSI MegaRAID SAS. */ + for (i = 0; i < 32; i++) + { + char name[20]; + + get_mfi_disk_name (name, i); + if (check_device_readable_unique (name)) + { + if (hook (name, 0)) + goto out; + } + } #endif #ifdef __linux__ From 1f1a380be9ba10bf904240106b3bbb274c11e65a Mon Sep 17 00:00:00 2001 From: Szymon Janc Date: Sun, 14 Aug 2011 11:39:31 +0200 Subject: [PATCH 766/869] Import minilzo library for LZO decompression support. * grub-core/lib/minilzo/lzoconf.h: New file. * grub-core/lib/minilzo/lzodefs.h: Likewise. * grub-core/lib/minilzo/minilzo.c: Likewise. * grub-core/lib/minilzo/minilzo.h: Likewise. * include/grub/types.h (GRUB_UCHAR_MAX): New define. (GRUB_USHRT_MAX): Likewise. (GRUB_UINT_MAX): Likewise. * grub-core/lib/posix_wrap/limits.h (USHRT_MAX): New define. (UINT_MAX): Likewise. (CHAR_BIT): Likewise. * grub-core/lib/posix_wrap/sys/types.h (ULONG_MAX): Moved to grub-core/lib/posix_wrap/limits.h (UCHAR_MAX): Likewise. --- ChangeLog.lzo | 18 + grub-core/lib/minilzo/lzoconf.h | 446 +++ grub-core/lib/minilzo/lzodefs.h | 1852 +++++++++++ grub-core/lib/minilzo/minilzo.c | 4562 ++++++++++++++++++++++++++ grub-core/lib/minilzo/minilzo.h | 109 + grub-core/lib/posix_wrap/limits.h | 31 + grub-core/lib/posix_wrap/sys/types.h | 3 - include/grub/types.h | 4 + 8 files changed, 7022 insertions(+), 3 deletions(-) create mode 100644 ChangeLog.lzo create mode 100644 grub-core/lib/minilzo/lzoconf.h create mode 100644 grub-core/lib/minilzo/lzodefs.h create mode 100644 grub-core/lib/minilzo/minilzo.c create mode 100644 grub-core/lib/minilzo/minilzo.h diff --git a/ChangeLog.lzo b/ChangeLog.lzo new file mode 100644 index 000000000..6f5191db2 --- /dev/null +++ b/ChangeLog.lzo @@ -0,0 +1,18 @@ +2011-08-14 Szymon Janc + + Import minilzo library for LZO decompression support. + + * grub-core/lib/minilzo/lzoconf.h: New file. + * grub-core/lib/minilzo/lzodefs.h: Likewise. + * grub-core/lib/minilzo/minilzo.c: Likewise. + * grub-core/lib/minilzo/minilzo.h: Likewise. + * include/grub/types.h (GRUB_UCHAR_MAX): New define. + (GRUB_USHRT_MAX): Likewise. + (GRUB_UINT_MAX): Likewise. + * grub-core/lib/posix_wrap/limits.h (USHRT_MAX): New define. + (UINT_MAX): Likewise. + (CHAR_BIT): Likewise. + * grub-core/lib/posix_wrap/sys/types.h (ULONG_MAX): Moved to + grub-core/lib/posix_wrap/limits.h + (UCHAR_MAX): Likewise. + diff --git a/grub-core/lib/minilzo/lzoconf.h b/grub-core/lib/minilzo/lzoconf.h new file mode 100644 index 000000000..1d0fe14fc --- /dev/null +++ b/grub-core/lib/minilzo/lzoconf.h @@ -0,0 +1,446 @@ +/* lzoconf.h -- configuration of the LZO data compression library + + This file is part of the LZO real-time data compression library. + + Copyright (C) 2011 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2010 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2009 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2008 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2007 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2006 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2005 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2004 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2003 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2002 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2001 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2000 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 1999 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 1998 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 1997 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 1996 Markus Franz Xaver Johannes Oberhumer + All Rights Reserved. + + The LZO library 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 2 of + the License, or (at your option) any later version. + + The LZO library 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 the LZO library; see the file COPYING. + If not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + Markus F.X.J. Oberhumer + + http://www.oberhumer.com/opensource/lzo/ + */ + + +#ifndef __LZOCONF_H_INCLUDED +#define __LZOCONF_H_INCLUDED 1 + +#define LZO_VERSION 0x2050 +#define LZO_VERSION_STRING "2.05" +#define LZO_VERSION_DATE "Apr 23 2011" + +/* internal Autoconf configuration file - only used when building LZO */ +#if defined(LZO_HAVE_CONFIG_H) +# include +#endif +#include +#include + + +/*********************************************************************** +// LZO requires a conforming +************************************************************************/ + +#if !defined(CHAR_BIT) || (CHAR_BIT != 8) +# error "invalid CHAR_BIT" +#endif +#if !defined(UCHAR_MAX) || !defined(UINT_MAX) || !defined(ULONG_MAX) +# error "check your compiler installation" +#endif +#if (USHRT_MAX < 1) || (UINT_MAX < 1) || (ULONG_MAX < 1) +# error "your limits.h macros are broken" +#endif + +/* get OS and architecture defines */ +#ifndef __LZODEFS_H_INCLUDED +#include "lzodefs.h" +#endif + + +#ifdef __cplusplus +extern "C" { +#endif + + +/*********************************************************************** +// some core defines +************************************************************************/ + +#if !defined(LZO_UINT32_C) +# if (UINT_MAX < LZO_0xffffffffL) +# define LZO_UINT32_C(c) c ## UL +# else +# define LZO_UINT32_C(c) ((c) + 0U) +# endif +#endif + +/* memory checkers */ +#if !defined(__LZO_CHECKER) +# if defined(__BOUNDS_CHECKING_ON) +# define __LZO_CHECKER 1 +# elif defined(__CHECKER__) +# define __LZO_CHECKER 1 +# elif defined(__INSURE__) +# define __LZO_CHECKER 1 +# elif defined(__PURIFY__) +# define __LZO_CHECKER 1 +# endif +#endif + + +/*********************************************************************** +// integral and pointer types +************************************************************************/ + +/* lzo_uint should match size_t */ +#if !defined(LZO_UINT_MAX) +# if defined(LZO_ABI_LLP64) /* WIN64 */ +# if defined(LZO_OS_WIN64) + typedef unsigned __int64 lzo_uint; + typedef __int64 lzo_int; +# else + typedef unsigned long long lzo_uint; + typedef long long lzo_int; +# endif +# define LZO_UINT_MAX 0xffffffffffffffffull +# define LZO_INT_MAX 9223372036854775807LL +# define LZO_INT_MIN (-1LL - LZO_INT_MAX) +# elif defined(LZO_ABI_IP32L64) /* MIPS R5900 */ + typedef unsigned int lzo_uint; + typedef int lzo_int; +# define LZO_UINT_MAX UINT_MAX +# define LZO_INT_MAX INT_MAX +# define LZO_INT_MIN INT_MIN +# elif (ULONG_MAX >= LZO_0xffffffffL) + typedef unsigned long lzo_uint; + typedef long lzo_int; +# define LZO_UINT_MAX ULONG_MAX +# define LZO_INT_MAX LONG_MAX +# define LZO_INT_MIN LONG_MIN +# else +# error "lzo_uint" +# endif +#endif + +/* Integral types with 32 bits or more. */ +#if !defined(LZO_UINT32_MAX) +# if (UINT_MAX >= LZO_0xffffffffL) + typedef unsigned int lzo_uint32; + typedef int lzo_int32; +# define LZO_UINT32_MAX UINT_MAX +# define LZO_INT32_MAX INT_MAX +# define LZO_INT32_MIN INT_MIN +# elif (ULONG_MAX >= LZO_0xffffffffL) + typedef unsigned long lzo_uint32; + typedef long lzo_int32; +# define LZO_UINT32_MAX ULONG_MAX +# define LZO_INT32_MAX LONG_MAX +# define LZO_INT32_MIN LONG_MIN +# else +# error "lzo_uint32" +# endif +#endif + +/* Integral types with exactly 64 bits. */ +#if !defined(LZO_UINT64_MAX) +# if (LZO_UINT_MAX >= LZO_0xffffffffL) +# if ((((LZO_UINT_MAX) >> 31) >> 31) == 3) +# define lzo_uint64 lzo_uint +# define lzo_int64 lzo_int +# define LZO_UINT64_MAX LZO_UINT_MAX +# define LZO_INT64_MAX LZO_INT_MAX +# define LZO_INT64_MIN LZO_INT_MIN +# endif +# elif (ULONG_MAX >= LZO_0xffffffffL) +# if ((((ULONG_MAX) >> 31) >> 31) == 3) + typedef unsigned long lzo_uint64; + typedef long lzo_int64; +# define LZO_UINT64_MAX ULONG_MAX +# define LZO_INT64_MAX LONG_MAX +# define LZO_INT64_MIN LONG_MIN +# endif +# endif +#endif + +/* The larger type of lzo_uint and lzo_uint32. */ +#if (LZO_UINT_MAX >= LZO_UINT32_MAX) +# define lzo_xint lzo_uint +#else +# define lzo_xint lzo_uint32 +#endif + +/* Memory model that allows to access memory at offsets of lzo_uint. */ +#if !defined(__LZO_MMODEL) +# if (LZO_UINT_MAX <= UINT_MAX) +# define __LZO_MMODEL /*empty*/ +# elif defined(LZO_HAVE_MM_HUGE_PTR) +# define __LZO_MMODEL_HUGE 1 +# define __LZO_MMODEL __huge +# else +# define __LZO_MMODEL /*empty*/ +# endif +#endif + +/* no typedef here because of const-pointer issues */ +#define lzo_bytep unsigned char __LZO_MMODEL * +#define lzo_charp char __LZO_MMODEL * +#define lzo_voidp void __LZO_MMODEL * +#define lzo_shortp short __LZO_MMODEL * +#define lzo_ushortp unsigned short __LZO_MMODEL * +#define lzo_uint32p lzo_uint32 __LZO_MMODEL * +#define lzo_int32p lzo_int32 __LZO_MMODEL * +#if defined(LZO_UINT64_MAX) +#define lzo_uint64p lzo_uint64 __LZO_MMODEL * +#define lzo_int64p lzo_int64 __LZO_MMODEL * +#endif +#define lzo_uintp lzo_uint __LZO_MMODEL * +#define lzo_intp lzo_int __LZO_MMODEL * +#define lzo_xintp lzo_xint __LZO_MMODEL * +#define lzo_voidpp lzo_voidp __LZO_MMODEL * +#define lzo_bytepp lzo_bytep __LZO_MMODEL * +/* deprecated - use 'lzo_bytep' instead of 'lzo_byte *' */ +#define lzo_byte unsigned char __LZO_MMODEL + +typedef int lzo_bool; + + +/*********************************************************************** +// function types +************************************************************************/ + +/* name mangling */ +#if !defined(__LZO_EXTERN_C) +# ifdef __cplusplus +# define __LZO_EXTERN_C extern "C" +# else +# define __LZO_EXTERN_C extern +# endif +#endif + +/* calling convention */ +#if !defined(__LZO_CDECL) +# define __LZO_CDECL __lzo_cdecl +#endif + +/* DLL export information */ +#if !defined(__LZO_EXPORT1) +# define __LZO_EXPORT1 /*empty*/ +#endif +#if !defined(__LZO_EXPORT2) +# define __LZO_EXPORT2 /*empty*/ +#endif + +/* __cdecl calling convention for public C and assembly functions */ +#if !defined(LZO_PUBLIC) +# define LZO_PUBLIC(_rettype) __LZO_EXPORT1 _rettype __LZO_EXPORT2 __LZO_CDECL +#endif +#if !defined(LZO_EXTERN) +# define LZO_EXTERN(_rettype) __LZO_EXTERN_C LZO_PUBLIC(_rettype) +#endif +#if !defined(LZO_PRIVATE) +# define LZO_PRIVATE(_rettype) static _rettype __LZO_CDECL +#endif + +/* function types */ +typedef int +(__LZO_CDECL *lzo_compress_t) ( const lzo_bytep src, lzo_uint src_len, + lzo_bytep dst, lzo_uintp dst_len, + lzo_voidp wrkmem ); + +typedef int +(__LZO_CDECL *lzo_decompress_t) ( const lzo_bytep src, lzo_uint src_len, + lzo_bytep dst, lzo_uintp dst_len, + lzo_voidp wrkmem ); + +typedef int +(__LZO_CDECL *lzo_optimize_t) ( lzo_bytep src, lzo_uint src_len, + lzo_bytep dst, lzo_uintp dst_len, + lzo_voidp wrkmem ); + +typedef int +(__LZO_CDECL *lzo_compress_dict_t)(const lzo_bytep src, lzo_uint src_len, + lzo_bytep dst, lzo_uintp dst_len, + lzo_voidp wrkmem, + const lzo_bytep dict, lzo_uint dict_len ); + +typedef int +(__LZO_CDECL *lzo_decompress_dict_t)(const lzo_bytep src, lzo_uint src_len, + lzo_bytep dst, lzo_uintp dst_len, + lzo_voidp wrkmem, + const lzo_bytep dict, lzo_uint dict_len ); + + +/* Callback interface. Currently only the progress indicator ("nprogress") + * is used, but this may change in a future release. */ + +struct lzo_callback_t; +typedef struct lzo_callback_t lzo_callback_t; +#define lzo_callback_p lzo_callback_t __LZO_MMODEL * + +/* malloc & free function types */ +typedef lzo_voidp (__LZO_CDECL *lzo_alloc_func_t) + (lzo_callback_p self, lzo_uint items, lzo_uint size); +typedef void (__LZO_CDECL *lzo_free_func_t) + (lzo_callback_p self, lzo_voidp ptr); + +/* a progress indicator callback function */ +typedef void (__LZO_CDECL *lzo_progress_func_t) + (lzo_callback_p, lzo_uint, lzo_uint, int); + +struct lzo_callback_t +{ + /* custom allocators (set to 0 to disable) */ + lzo_alloc_func_t nalloc; /* [not used right now] */ + lzo_free_func_t nfree; /* [not used right now] */ + + /* a progress indicator callback function (set to 0 to disable) */ + lzo_progress_func_t nprogress; + + /* NOTE: the first parameter "self" of the nalloc/nfree/nprogress + * callbacks points back to this struct, so you are free to store + * some extra info in the following variables. */ + lzo_voidp user1; + lzo_xint user2; + lzo_xint user3; +}; + + +/*********************************************************************** +// error codes and prototypes +************************************************************************/ + +/* Error codes for the compression/decompression functions. Negative + * values are errors, positive values will be used for special but + * normal events. + */ +#define LZO_E_OK 0 +#define LZO_E_ERROR (-1) +#define LZO_E_OUT_OF_MEMORY (-2) /* [lzo_alloc_func_t failure] */ +#define LZO_E_NOT_COMPRESSIBLE (-3) /* [not used right now] */ +#define LZO_E_INPUT_OVERRUN (-4) +#define LZO_E_OUTPUT_OVERRUN (-5) +#define LZO_E_LOOKBEHIND_OVERRUN (-6) +#define LZO_E_EOF_NOT_FOUND (-7) +#define LZO_E_INPUT_NOT_CONSUMED (-8) +#define LZO_E_NOT_YET_IMPLEMENTED (-9) /* [not used right now] */ +#define LZO_E_INVALID_ARGUMENT (-10) + + +#ifndef lzo_sizeof_dict_t +# define lzo_sizeof_dict_t ((unsigned)sizeof(lzo_bytep)) +#endif + +/* lzo_init() should be the first function you call. + * Check the return code ! + * + * lzo_init() is a macro to allow checking that the library and the + * compiler's view of various types are consistent. + */ +#define lzo_init() __lzo_init_v2(LZO_VERSION,(int)sizeof(short),(int)sizeof(int),\ + (int)sizeof(long),(int)sizeof(lzo_uint32),(int)sizeof(lzo_uint),\ + (int)lzo_sizeof_dict_t,(int)sizeof(char *),(int)sizeof(lzo_voidp),\ + (int)sizeof(lzo_callback_t)) +LZO_EXTERN(int) __lzo_init_v2(unsigned,int,int,int,int,int,int,int,int,int); + +/* version functions (useful for shared libraries) */ +LZO_EXTERN(unsigned) lzo_version(void); +LZO_EXTERN(const char *) lzo_version_string(void); +LZO_EXTERN(const char *) lzo_version_date(void); +LZO_EXTERN(const lzo_charp) _lzo_version_string(void); +LZO_EXTERN(const lzo_charp) _lzo_version_date(void); + +/* string functions */ +LZO_EXTERN(int) + lzo_memcmp(const lzo_voidp a, const lzo_voidp b, lzo_uint len); +LZO_EXTERN(lzo_voidp) + lzo_memcpy(lzo_voidp dst, const lzo_voidp src, lzo_uint len); +LZO_EXTERN(lzo_voidp) + lzo_memmove(lzo_voidp dst, const lzo_voidp src, lzo_uint len); +LZO_EXTERN(lzo_voidp) + lzo_memset(lzo_voidp buf, int c, lzo_uint len); + +/* checksum functions */ +LZO_EXTERN(lzo_uint32) + lzo_adler32(lzo_uint32 c, const lzo_bytep buf, lzo_uint len); +LZO_EXTERN(lzo_uint32) + lzo_crc32(lzo_uint32 c, const lzo_bytep buf, lzo_uint len); +LZO_EXTERN(const lzo_uint32p) + lzo_get_crc32_table(void); + +/* misc. */ +LZO_EXTERN(int) _lzo_config_check(void); +typedef union { lzo_bytep p; lzo_uint u; } __lzo_pu_u; +typedef union { lzo_bytep p; lzo_uint32 u32; } __lzo_pu32_u; +typedef union { void *vp; lzo_bytep bp; lzo_uint u; lzo_uint32 u32; unsigned long l; } lzo_align_t; + +/* align a char pointer on a boundary that is a multiple of 'size' */ +LZO_EXTERN(unsigned) __lzo_align_gap(const lzo_voidp p, lzo_uint size); +#define LZO_PTR_ALIGN_UP(p,size) \ + ((p) + (lzo_uint) __lzo_align_gap((const lzo_voidp)(p),(lzo_uint)(size))) + + +/*********************************************************************** +// deprecated macros - only for backward compatibility with LZO v1.xx +************************************************************************/ + +#if defined(LZO_CFG_COMPAT) + +#define __LZOCONF_H 1 + +#if defined(LZO_ARCH_I086) +# define __LZO_i386 1 +#elif defined(LZO_ARCH_I386) +# define __LZO_i386 1 +#endif + +#if defined(LZO_OS_DOS16) +# define __LZO_DOS 1 +# define __LZO_DOS16 1 +#elif defined(LZO_OS_DOS32) +# define __LZO_DOS 1 +#elif defined(LZO_OS_WIN16) +# define __LZO_WIN 1 +# define __LZO_WIN16 1 +#elif defined(LZO_OS_WIN32) +# define __LZO_WIN 1 +#endif + +#define __LZO_CMODEL /*empty*/ +#define __LZO_DMODEL /*empty*/ +#define __LZO_ENTRY __LZO_CDECL +#define LZO_EXTERN_CDECL LZO_EXTERN +#define LZO_ALIGN LZO_PTR_ALIGN_UP + +#define lzo_compress_asm_t lzo_compress_t +#define lzo_decompress_asm_t lzo_decompress_t + +#endif /* LZO_CFG_COMPAT */ + + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /* already included */ + + +/* vim:set ts=4 et: */ diff --git a/grub-core/lib/minilzo/lzodefs.h b/grub-core/lib/minilzo/lzodefs.h new file mode 100644 index 000000000..0e40e332a --- /dev/null +++ b/grub-core/lib/minilzo/lzodefs.h @@ -0,0 +1,1852 @@ +/* lzodefs.h -- architecture, OS and compiler specific defines + + This file is part of the LZO real-time data compression library. + + Copyright (C) 2011 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2010 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2009 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2008 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2007 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2006 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2005 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2004 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2003 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2002 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2001 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2000 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 1999 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 1998 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 1997 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 1996 Markus Franz Xaver Johannes Oberhumer + All Rights Reserved. + + The LZO library 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 2 of + the License, or (at your option) any later version. + + The LZO library 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 the LZO library; see the file COPYING. + If not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + Markus F.X.J. Oberhumer + + http://www.oberhumer.com/opensource/lzo/ + */ + + +#ifndef __LZODEFS_H_INCLUDED +#define __LZODEFS_H_INCLUDED 1 + +#if defined(__CYGWIN32__) && !defined(__CYGWIN__) +# define __CYGWIN__ __CYGWIN32__ +#endif +#if defined(__IBMCPP__) && !defined(__IBMC__) +# define __IBMC__ __IBMCPP__ +#endif +#if defined(__ICL) && defined(_WIN32) && !defined(__INTEL_COMPILER) +# define __INTEL_COMPILER __ICL +#endif +#if 1 && defined(__INTERIX) && defined(__GNUC__) && !defined(_ALL_SOURCE) +# define _ALL_SOURCE 1 +#endif +#if defined(__mips__) && defined(__R5900__) +# if !defined(__LONG_MAX__) +# define __LONG_MAX__ 9223372036854775807L +# endif +#endif +#if defined(__INTEL_COMPILER) && defined(__linux__) +# pragma warning(disable: 193) +#endif +#if defined(__KEIL__) && defined(__C166__) +# pragma warning disable = 322 +#elif 0 && defined(__C251__) +# pragma warning disable = 322 +#endif +#if defined(_MSC_VER) && !defined(__INTEL_COMPILER) && !defined(__MWERKS__) +# if (_MSC_VER >= 1300) +# pragma warning(disable: 4668) +# endif +#endif +#if 0 && defined(__WATCOMC__) +# if (__WATCOMC__ >= 1050) && (__WATCOMC__ < 1060) +# pragma warning 203 9 +# endif +#endif +#if defined(__BORLANDC__) && defined(__MSDOS__) && !defined(__FLAT__) +# pragma option -h +#endif +#if 0 +#define LZO_0xffffL 0xfffful +#define LZO_0xffffffffL 0xfffffffful +#else +#define LZO_0xffffL 65535ul +#define LZO_0xffffffffL 4294967295ul +#endif +#if (LZO_0xffffL == LZO_0xffffffffL) +# error "your preprocessor is broken 1" +#endif +#if (16ul * 16384ul != 262144ul) +# error "your preprocessor is broken 2" +#endif +#if 0 +#if (32767 >= 4294967295ul) +# error "your preprocessor is broken 3" +#endif +#if (65535u >= 4294967295ul) +# error "your preprocessor is broken 4" +#endif +#endif +#if (UINT_MAX == LZO_0xffffL) +#if defined(__ZTC__) && defined(__I86__) && !defined(__OS2__) +# if !defined(MSDOS) +# define MSDOS 1 +# endif +# if !defined(_MSDOS) +# define _MSDOS 1 +# endif +#elif 0 && defined(__VERSION) && defined(MB_LEN_MAX) +# if (__VERSION == 520) && (MB_LEN_MAX == 1) +# if !defined(__AZTEC_C__) +# define __AZTEC_C__ __VERSION +# endif +# if !defined(__DOS__) +# define __DOS__ 1 +# endif +# endif +#endif +#endif +#if defined(_MSC_VER) && defined(M_I86HM) && (UINT_MAX == LZO_0xffffL) +# define ptrdiff_t long +# define _PTRDIFF_T_DEFINED 1 +#endif +#if (UINT_MAX == LZO_0xffffL) +# undef __LZO_RENAME_A +# undef __LZO_RENAME_B +# if defined(__AZTEC_C__) && defined(__DOS__) +# define __LZO_RENAME_A 1 +# elif defined(_MSC_VER) && defined(MSDOS) +# if (_MSC_VER < 600) +# define __LZO_RENAME_A 1 +# elif (_MSC_VER < 700) +# define __LZO_RENAME_B 1 +# endif +# elif defined(__TSC__) && defined(__OS2__) +# define __LZO_RENAME_A 1 +# elif defined(__MSDOS__) && defined(__TURBOC__) && (__TURBOC__ < 0x0410) +# define __LZO_RENAME_A 1 +# elif defined(__PACIFIC__) && defined(DOS) +# if !defined(__far) +# define __far far +# endif +# if !defined(__near) +# define __near near +# endif +# endif +# if defined(__LZO_RENAME_A) +# if !defined(__cdecl) +# define __cdecl cdecl +# endif +# if !defined(__far) +# define __far far +# endif +# if !defined(__huge) +# define __huge huge +# endif +# if !defined(__near) +# define __near near +# endif +# if !defined(__pascal) +# define __pascal pascal +# endif +# if !defined(__huge) +# define __huge huge +# endif +# elif defined(__LZO_RENAME_B) +# if !defined(__cdecl) +# define __cdecl _cdecl +# endif +# if !defined(__far) +# define __far _far +# endif +# if !defined(__huge) +# define __huge _huge +# endif +# if !defined(__near) +# define __near _near +# endif +# if !defined(__pascal) +# define __pascal _pascal +# endif +# elif (defined(__PUREC__) || defined(__TURBOC__)) && defined(__TOS__) +# if !defined(__cdecl) +# define __cdecl cdecl +# endif +# if !defined(__pascal) +# define __pascal pascal +# endif +# endif +# undef __LZO_RENAME_A +# undef __LZO_RENAME_B +#endif +#if (UINT_MAX == LZO_0xffffL) +#if defined(__AZTEC_C__) && defined(__DOS__) +# define LZO_BROKEN_CDECL_ALT_SYNTAX 1 +#elif defined(_MSC_VER) && defined(MSDOS) +# if (_MSC_VER < 600) +# define LZO_BROKEN_INTEGRAL_CONSTANTS 1 +# endif +# if (_MSC_VER < 700) +# define LZO_BROKEN_INTEGRAL_PROMOTION 1 +# define LZO_BROKEN_SIZEOF 1 +# endif +#elif defined(__PACIFIC__) && defined(DOS) +# define LZO_BROKEN_INTEGRAL_CONSTANTS 1 +#elif defined(__TURBOC__) && defined(__MSDOS__) +# if (__TURBOC__ < 0x0150) +# define LZO_BROKEN_CDECL_ALT_SYNTAX 1 +# define LZO_BROKEN_INTEGRAL_CONSTANTS 1 +# define LZO_BROKEN_INTEGRAL_PROMOTION 1 +# endif +# if (__TURBOC__ < 0x0200) +# define LZO_BROKEN_SIZEOF 1 +# endif +# if (__TURBOC__ < 0x0400) && defined(__cplusplus) +# define LZO_BROKEN_CDECL_ALT_SYNTAX 1 +# endif +#elif (defined(__PUREC__) || defined(__TURBOC__)) && defined(__TOS__) +# define LZO_BROKEN_CDECL_ALT_SYNTAX 1 +# define LZO_BROKEN_SIZEOF 1 +#endif +#endif +#if defined(__WATCOMC__) && (__WATCOMC__ < 900) +# define LZO_BROKEN_INTEGRAL_CONSTANTS 1 +#endif +#if defined(_CRAY) && defined(_CRAY1) +# define LZO_BROKEN_SIGNED_RIGHT_SHIFT 1 +#endif +#define LZO_PP_STRINGIZE(x) #x +#define LZO_PP_MACRO_EXPAND(x) LZO_PP_STRINGIZE(x) +#define LZO_PP_CONCAT2(a,b) a ## b +#define LZO_PP_CONCAT3(a,b,c) a ## b ## c +#define LZO_PP_CONCAT4(a,b,c,d) a ## b ## c ## d +#define LZO_PP_CONCAT5(a,b,c,d,e) a ## b ## c ## d ## e +#define LZO_PP_ECONCAT2(a,b) LZO_PP_CONCAT2(a,b) +#define LZO_PP_ECONCAT3(a,b,c) LZO_PP_CONCAT3(a,b,c) +#define LZO_PP_ECONCAT4(a,b,c,d) LZO_PP_CONCAT4(a,b,c,d) +#define LZO_PP_ECONCAT5(a,b,c,d,e) LZO_PP_CONCAT5(a,b,c,d,e) +#if 1 +#define LZO_CPP_STRINGIZE(x) #x +#define LZO_CPP_MACRO_EXPAND(x) LZO_CPP_STRINGIZE(x) +#define LZO_CPP_CONCAT2(a,b) a ## b +#define LZO_CPP_CONCAT3(a,b,c) a ## b ## c +#define LZO_CPP_CONCAT4(a,b,c,d) a ## b ## c ## d +#define LZO_CPP_CONCAT5(a,b,c,d,e) a ## b ## c ## d ## e +#define LZO_CPP_ECONCAT2(a,b) LZO_CPP_CONCAT2(a,b) +#define LZO_CPP_ECONCAT3(a,b,c) LZO_CPP_CONCAT3(a,b,c) +#define LZO_CPP_ECONCAT4(a,b,c,d) LZO_CPP_CONCAT4(a,b,c,d) +#define LZO_CPP_ECONCAT5(a,b,c,d,e) LZO_CPP_CONCAT5(a,b,c,d,e) +#endif +#define __LZO_MASK_GEN(o,b) (((((o) << ((b)-1)) - (o)) << 1) + (o)) +#if 1 && defined(__cplusplus) +# if !defined(__STDC_CONSTANT_MACROS) +# define __STDC_CONSTANT_MACROS 1 +# endif +# if !defined(__STDC_LIMIT_MACROS) +# define __STDC_LIMIT_MACROS 1 +# endif +#endif +#if defined(__cplusplus) +# define LZO_EXTERN_C extern "C" +#else +# define LZO_EXTERN_C extern +#endif +#if !defined(__LZO_OS_OVERRIDE) +#if (LZO_OS_FREESTANDING) +# define LZO_INFO_OS "freestanding" +#elif (LZO_OS_EMBEDDED) +# define LZO_INFO_OS "embedded" +#elif 1 && defined(__IAR_SYSTEMS_ICC__) +# define LZO_OS_EMBEDDED 1 +# define LZO_INFO_OS "embedded" +#elif defined(__CYGWIN__) && defined(__GNUC__) +# define LZO_OS_CYGWIN 1 +# define LZO_INFO_OS "cygwin" +#elif defined(__EMX__) && defined(__GNUC__) +# define LZO_OS_EMX 1 +# define LZO_INFO_OS "emx" +#elif defined(__BEOS__) +# define LZO_OS_BEOS 1 +# define LZO_INFO_OS "beos" +#elif defined(__Lynx__) +# define LZO_OS_LYNXOS 1 +# define LZO_INFO_OS "lynxos" +#elif defined(__OS400__) +# define LZO_OS_OS400 1 +# define LZO_INFO_OS "os400" +#elif defined(__QNX__) +# define LZO_OS_QNX 1 +# define LZO_INFO_OS "qnx" +#elif defined(__BORLANDC__) && defined(__DPMI32__) && (__BORLANDC__ >= 0x0460) +# define LZO_OS_DOS32 1 +# define LZO_INFO_OS "dos32" +#elif defined(__BORLANDC__) && defined(__DPMI16__) +# define LZO_OS_DOS16 1 +# define LZO_INFO_OS "dos16" +#elif defined(__ZTC__) && defined(DOS386) +# define LZO_OS_DOS32 1 +# define LZO_INFO_OS "dos32" +#elif defined(__OS2__) || defined(__OS2V2__) +# if (UINT_MAX == LZO_0xffffL) +# define LZO_OS_OS216 1 +# define LZO_INFO_OS "os216" +# elif (UINT_MAX == LZO_0xffffffffL) +# define LZO_OS_OS2 1 +# define LZO_INFO_OS "os2" +# else +# error "check your limits.h header" +# endif +#elif defined(__WIN64__) || defined(_WIN64) || defined(WIN64) +# define LZO_OS_WIN64 1 +# define LZO_INFO_OS "win64" +#elif defined(__WIN32__) || defined(_WIN32) || defined(WIN32) || defined(__WINDOWS_386__) +# define LZO_OS_WIN32 1 +# define LZO_INFO_OS "win32" +#elif defined(__MWERKS__) && defined(__INTEL__) +# define LZO_OS_WIN32 1 +# define LZO_INFO_OS "win32" +#elif defined(__WINDOWS__) || defined(_WINDOWS) || defined(_Windows) +# if (UINT_MAX == LZO_0xffffL) +# define LZO_OS_WIN16 1 +# define LZO_INFO_OS "win16" +# elif (UINT_MAX == LZO_0xffffffffL) +# define LZO_OS_WIN32 1 +# define LZO_INFO_OS "win32" +# else +# error "check your limits.h header" +# endif +#elif defined(__DOS__) || defined(__MSDOS__) || defined(_MSDOS) || defined(MSDOS) || (defined(__PACIFIC__) && defined(DOS)) +# if (UINT_MAX == LZO_0xffffL) +# define LZO_OS_DOS16 1 +# define LZO_INFO_OS "dos16" +# elif (UINT_MAX == LZO_0xffffffffL) +# define LZO_OS_DOS32 1 +# define LZO_INFO_OS "dos32" +# else +# error "check your limits.h header" +# endif +#elif defined(__WATCOMC__) +# if defined(__NT__) && (UINT_MAX == LZO_0xffffL) +# define LZO_OS_DOS16 1 +# define LZO_INFO_OS "dos16" +# elif defined(__NT__) && (__WATCOMC__ < 1100) +# define LZO_OS_WIN32 1 +# define LZO_INFO_OS "win32" +# elif defined(__linux__) || defined(__LINUX__) +# define LZO_OS_POSIX 1 +# define LZO_INFO_OS "posix" +# else +# error "please specify a target using the -bt compiler option" +# endif +#elif defined(__palmos__) +# define LZO_OS_PALMOS 1 +# define LZO_INFO_OS "palmos" +#elif defined(__TOS__) || defined(__atarist__) +# define LZO_OS_TOS 1 +# define LZO_INFO_OS "tos" +#elif defined(macintosh) && !defined(__ppc__) +# define LZO_OS_MACCLASSIC 1 +# define LZO_INFO_OS "macclassic" +#elif defined(__VMS) +# define LZO_OS_VMS 1 +# define LZO_INFO_OS "vms" +#elif ((defined(__mips__) && defined(__R5900__)) || defined(__MIPS_PSX2__)) +# define LZO_OS_CONSOLE 1 +# define LZO_OS_CONSOLE_PS2 1 +# define LZO_INFO_OS "console" +# define LZO_INFO_OS_CONSOLE "ps2" +#elif (defined(__mips__) && defined(__psp__)) +# define LZO_OS_CONSOLE 1 +# define LZO_OS_CONSOLE_PSP 1 +# define LZO_INFO_OS "console" +# define LZO_INFO_OS_CONSOLE "psp" +#else +# define LZO_OS_POSIX 1 +# define LZO_INFO_OS "posix" +#endif +#if (LZO_OS_POSIX) +# if defined(_AIX) || defined(__AIX__) || defined(__aix__) +# define LZO_OS_POSIX_AIX 1 +# define LZO_INFO_OS_POSIX "aix" +# elif defined(__FreeBSD__) +# define LZO_OS_POSIX_FREEBSD 1 +# define LZO_INFO_OS_POSIX "freebsd" +# elif defined(__hpux__) || defined(__hpux) +# define LZO_OS_POSIX_HPUX 1 +# define LZO_INFO_OS_POSIX "hpux" +# elif defined(__INTERIX) +# define LZO_OS_POSIX_INTERIX 1 +# define LZO_INFO_OS_POSIX "interix" +# elif defined(__IRIX__) || defined(__irix__) +# define LZO_OS_POSIX_IRIX 1 +# define LZO_INFO_OS_POSIX "irix" +# elif defined(__linux__) || defined(__linux) || defined(__LINUX__) +# define LZO_OS_POSIX_LINUX 1 +# define LZO_INFO_OS_POSIX "linux" +# elif defined(__APPLE__) || defined(__MACOS__) +# define LZO_OS_POSIX_MACOSX 1 +# define LZO_INFO_OS_POSIX "macosx" +# elif defined(__minix__) || defined(__minix) +# define LZO_OS_POSIX_MINIX 1 +# define LZO_INFO_OS_POSIX "minix" +# elif defined(__NetBSD__) +# define LZO_OS_POSIX_NETBSD 1 +# define LZO_INFO_OS_POSIX "netbsd" +# elif defined(__OpenBSD__) +# define LZO_OS_POSIX_OPENBSD 1 +# define LZO_INFO_OS_POSIX "openbsd" +# elif defined(__osf__) +# define LZO_OS_POSIX_OSF 1 +# define LZO_INFO_OS_POSIX "osf" +# elif defined(__solaris__) || defined(__sun) +# if defined(__SVR4) || defined(__svr4__) +# define LZO_OS_POSIX_SOLARIS 1 +# define LZO_INFO_OS_POSIX "solaris" +# else +# define LZO_OS_POSIX_SUNOS 1 +# define LZO_INFO_OS_POSIX "sunos" +# endif +# elif defined(__ultrix__) || defined(__ultrix) +# define LZO_OS_POSIX_ULTRIX 1 +# define LZO_INFO_OS_POSIX "ultrix" +# elif defined(_UNICOS) +# define LZO_OS_POSIX_UNICOS 1 +# define LZO_INFO_OS_POSIX "unicos" +# else +# define LZO_OS_POSIX_UNKNOWN 1 +# define LZO_INFO_OS_POSIX "unknown" +# endif +#endif +#endif +#if (LZO_OS_DOS16 || LZO_OS_OS216 || LZO_OS_WIN16) +# if (UINT_MAX != LZO_0xffffL) +# error "this should not happen" +# endif +# if (ULONG_MAX != LZO_0xffffffffL) +# error "this should not happen" +# endif +#endif +#if (LZO_OS_DOS32 || LZO_OS_OS2 || LZO_OS_WIN32 || LZO_OS_WIN64) +# if (UINT_MAX != LZO_0xffffffffL) +# error "this should not happen" +# endif +# if (ULONG_MAX != LZO_0xffffffffL) +# error "this should not happen" +# endif +#endif +#if defined(CIL) && defined(_GNUCC) && defined(__GNUC__) +# define LZO_CC_CILLY 1 +# define LZO_INFO_CC "Cilly" +# if defined(__CILLY__) +# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__CILLY__) +# else +# define LZO_INFO_CCVER "unknown" +# endif +#elif 0 && defined(SDCC) && defined(__VERSION__) && !defined(__GNUC__) +# define LZO_CC_SDCC 1 +# define LZO_INFO_CC "sdcc" +# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(SDCC) +#elif defined(__PATHSCALE__) && defined(__PATHCC_PATCHLEVEL__) +# define LZO_CC_PATHSCALE (__PATHCC__ * 0x10000L + __PATHCC_MINOR__ * 0x100 + __PATHCC_PATCHLEVEL__) +# define LZO_INFO_CC "Pathscale C" +# define LZO_INFO_CCVER __PATHSCALE__ +#elif defined(__INTEL_COMPILER) +# define LZO_CC_INTELC 1 +# define LZO_INFO_CC "Intel C" +# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__INTEL_COMPILER) +# if defined(_WIN32) || defined(_WIN64) +# define LZO_CC_SYNTAX_MSC 1 +# else +# define LZO_CC_SYNTAX_GNUC 1 +# endif +#elif defined(__POCC__) && defined(_WIN32) +# define LZO_CC_PELLESC 1 +# define LZO_INFO_CC "Pelles C" +# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__POCC__) +#elif defined(__clang__) && defined(__llvm__) && defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__VERSION__) +# if defined(__GNUC_PATCHLEVEL__) +# define LZO_CC_CLANG_GNUC (__GNUC__ * 0x10000L + __GNUC_MINOR__ * 0x100 + __GNUC_PATCHLEVEL__) +# else +# define LZO_CC_CLANG_GNUC (__GNUC__ * 0x10000L + __GNUC_MINOR__ * 0x100) +# endif +# if defined(__clang_major__) && defined(__clang_minor__) && defined(__clang_patchlevel__) +# define LZO_CC_CLANG_CLANG (__clang_major__ * 0x10000L + __clang_minor__ * 0x100 + __clang_patchlevel__) +# else +# define LZO_CC_CLANG_CLANG 0x010000L +# endif +# define LZO_CC_CLANG LZO_CC_CLANG_GNUC +# define LZO_INFO_CC "clang" +# define LZO_INFO_CCVER __VERSION__ +#elif defined(__llvm__) && defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__VERSION__) +# if defined(__GNUC_PATCHLEVEL__) +# define LZO_CC_LLVM_GNUC (__GNUC__ * 0x10000L + __GNUC_MINOR__ * 0x100 + __GNUC_PATCHLEVEL__) +# else +# define LZO_CC_LLVM_GNUC (__GNUC__ * 0x10000L + __GNUC_MINOR__ * 0x100) +# endif +# define LZO_CC_LLVM LZO_CC_LLVM_GNUC +# define LZO_INFO_CC "llvm-gcc" +# define LZO_INFO_CCVER __VERSION__ +#elif defined(__GNUC__) && defined(__VERSION__) +# if defined(__GNUC_MINOR__) && defined(__GNUC_PATCHLEVEL__) +# define LZO_CC_GNUC (__GNUC__ * 0x10000L + __GNUC_MINOR__ * 0x100 + __GNUC_PATCHLEVEL__) +# elif defined(__GNUC_MINOR__) +# define LZO_CC_GNUC (__GNUC__ * 0x10000L + __GNUC_MINOR__ * 0x100) +# else +# define LZO_CC_GNUC (__GNUC__ * 0x10000L) +# endif +# define LZO_INFO_CC "gcc" +# define LZO_INFO_CCVER __VERSION__ +#elif defined(__ACK__) && defined(_ACK) +# define LZO_CC_ACK 1 +# define LZO_INFO_CC "Amsterdam Compiler Kit C" +# define LZO_INFO_CCVER "unknown" +#elif defined(__AZTEC_C__) +# define LZO_CC_AZTECC 1 +# define LZO_INFO_CC "Aztec C" +# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__AZTEC_C__) +#elif defined(__CODEGEARC__) +# define LZO_CC_CODEGEARC 1 +# define LZO_INFO_CC "CodeGear C" +# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__CODEGEARC__) +#elif defined(__BORLANDC__) +# define LZO_CC_BORLANDC 1 +# define LZO_INFO_CC "Borland C" +# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__BORLANDC__) +#elif defined(_CRAYC) && defined(_RELEASE) +# define LZO_CC_CRAYC 1 +# define LZO_INFO_CC "Cray C" +# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(_RELEASE) +#elif defined(__DMC__) && defined(__SC__) +# define LZO_CC_DMC 1 +# define LZO_INFO_CC "Digital Mars C" +# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__DMC__) +#elif defined(__DECC) +# define LZO_CC_DECC 1 +# define LZO_INFO_CC "DEC C" +# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__DECC) +#elif defined(__HIGHC__) +# define LZO_CC_HIGHC 1 +# define LZO_INFO_CC "MetaWare High C" +# define LZO_INFO_CCVER "unknown" +#elif defined(__IAR_SYSTEMS_ICC__) +# define LZO_CC_IARC 1 +# define LZO_INFO_CC "IAR C" +# if defined(__VER__) +# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__VER__) +# else +# define LZO_INFO_CCVER "unknown" +# endif +#elif defined(__IBMC__) +# define LZO_CC_IBMC 1 +# define LZO_INFO_CC "IBM C" +# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__IBMC__) +#elif defined(__KEIL__) && defined(__C166__) +# define LZO_CC_KEILC 1 +# define LZO_INFO_CC "Keil C" +# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__C166__) +#elif defined(__LCC__) && defined(_WIN32) && defined(__LCCOPTIMLEVEL) +# define LZO_CC_LCCWIN32 1 +# define LZO_INFO_CC "lcc-win32" +# define LZO_INFO_CCVER "unknown" +#elif defined(__LCC__) +# define LZO_CC_LCC 1 +# define LZO_INFO_CC "lcc" +# if defined(__LCC_VERSION__) +# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__LCC_VERSION__) +# else +# define LZO_INFO_CCVER "unknown" +# endif +#elif defined(_MSC_VER) +# define LZO_CC_MSC 1 +# define LZO_INFO_CC "Microsoft C" +# if defined(_MSC_FULL_VER) +# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(_MSC_VER) "." LZO_PP_MACRO_EXPAND(_MSC_FULL_VER) +# else +# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(_MSC_VER) +# endif +#elif defined(__MWERKS__) +# define LZO_CC_MWERKS 1 +# define LZO_INFO_CC "Metrowerks C" +# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__MWERKS__) +#elif (defined(__NDPC__) || defined(__NDPX__)) && defined(__i386) +# define LZO_CC_NDPC 1 +# define LZO_INFO_CC "Microway NDP C" +# define LZO_INFO_CCVER "unknown" +#elif defined(__PACIFIC__) +# define LZO_CC_PACIFICC 1 +# define LZO_INFO_CC "Pacific C" +# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__PACIFIC__) +#elif defined(__PGI) && (defined(__linux__) || defined(__WIN32__)) +# define LZO_CC_PGI 1 +# define LZO_INFO_CC "Portland Group PGI C" +# define LZO_INFO_CCVER "unknown" +#elif defined(__PUREC__) && defined(__TOS__) +# define LZO_CC_PUREC 1 +# define LZO_INFO_CC "Pure C" +# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__PUREC__) +#elif defined(__SC__) && defined(__ZTC__) +# define LZO_CC_SYMANTECC 1 +# define LZO_INFO_CC "Symantec C" +# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__SC__) +#elif defined(__SUNPRO_C) +# define LZO_INFO_CC "SunPro C" +# if ((__SUNPRO_C)+0 > 0) +# define LZO_CC_SUNPROC __SUNPRO_C +# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__SUNPRO_C) +# else +# define LZO_CC_SUNPROC 1 +# define LZO_INFO_CCVER "unknown" +# endif +#elif defined(__SUNPRO_CC) +# define LZO_INFO_CC "SunPro C" +# if ((__SUNPRO_CC)+0 > 0) +# define LZO_CC_SUNPROC __SUNPRO_CC +# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__SUNPRO_CC) +# else +# define LZO_CC_SUNPROC 1 +# define LZO_INFO_CCVER "unknown" +# endif +#elif defined(__TINYC__) +# define LZO_CC_TINYC 1 +# define LZO_INFO_CC "Tiny C" +# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__TINYC__) +#elif defined(__TSC__) +# define LZO_CC_TOPSPEEDC 1 +# define LZO_INFO_CC "TopSpeed C" +# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__TSC__) +#elif defined(__WATCOMC__) +# define LZO_CC_WATCOMC 1 +# define LZO_INFO_CC "Watcom C" +# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__WATCOMC__) +#elif defined(__TURBOC__) +# define LZO_CC_TURBOC 1 +# define LZO_INFO_CC "Turbo C" +# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__TURBOC__) +#elif defined(__ZTC__) +# define LZO_CC_ZORTECHC 1 +# define LZO_INFO_CC "Zortech C" +# if (__ZTC__ == 0x310) +# define LZO_INFO_CCVER "0x310" +# else +# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__ZTC__) +# endif +#else +# define LZO_CC_UNKNOWN 1 +# define LZO_INFO_CC "unknown" +# define LZO_INFO_CCVER "unknown" +#endif +#if 0 && (LZO_CC_MSC && (_MSC_VER >= 1200)) && !defined(_MSC_FULL_VER) +# error "LZO_CC_MSC: _MSC_FULL_VER is not defined" +#endif +#if !defined(__LZO_ARCH_OVERRIDE) && !(LZO_ARCH_GENERIC) && defined(_CRAY) +# if (UINT_MAX > LZO_0xffffffffL) && defined(_CRAY) +# if defined(_CRAYMPP) || defined(_CRAYT3D) || defined(_CRAYT3E) +# define LZO_ARCH_CRAY_MPP 1 +# elif defined(_CRAY1) +# define LZO_ARCH_CRAY_PVP 1 +# endif +# endif +#endif +#if !defined(__LZO_ARCH_OVERRIDE) +#if (LZO_ARCH_GENERIC) +# define LZO_INFO_ARCH "generic" +#elif (LZO_OS_DOS16 || LZO_OS_OS216 || LZO_OS_WIN16) +# define LZO_ARCH_I086 1 +# define LZO_ARCH_IA16 1 +# define LZO_INFO_ARCH "i086" +#elif defined(__alpha__) || defined(__alpha) || defined(_M_ALPHA) +# define LZO_ARCH_ALPHA 1 +# define LZO_INFO_ARCH "alpha" +#elif (LZO_ARCH_CRAY_MPP) && (defined(_CRAYT3D) || defined(_CRAYT3E)) +# define LZO_ARCH_ALPHA 1 +# define LZO_INFO_ARCH "alpha" +#elif defined(__amd64__) || defined(__x86_64__) || defined(_M_AMD64) +# define LZO_ARCH_AMD64 1 +# define LZO_INFO_ARCH "amd64" +#elif defined(__thumb__) || (defined(_M_ARM) && defined(_M_THUMB)) +# define LZO_ARCH_ARM 1 +# define LZO_ARCH_ARM_THUMB 1 +# define LZO_INFO_ARCH "arm_thumb" +#elif defined(__IAR_SYSTEMS_ICC__) && defined(__ICCARM__) +# define LZO_ARCH_ARM 1 +# if defined(__CPU_MODE__) && ((__CPU_MODE__)+0 == 1) +# define LZO_ARCH_ARM_THUMB 1 +# define LZO_INFO_ARCH "arm_thumb" +# elif defined(__CPU_MODE__) && ((__CPU_MODE__)+0 == 2) +# define LZO_INFO_ARCH "arm" +# else +# define LZO_INFO_ARCH "arm" +# endif +#elif defined(__arm__) || defined(_M_ARM) +# define LZO_ARCH_ARM 1 +# define LZO_INFO_ARCH "arm" +#elif (UINT_MAX <= LZO_0xffffL) && defined(__AVR__) +# define LZO_ARCH_AVR 1 +# define LZO_INFO_ARCH "avr" +#elif defined(__avr32__) || defined(__AVR32__) +# define LZO_ARCH_AVR32 1 +# define LZO_INFO_ARCH "avr32" +#elif defined(__bfin__) +# define LZO_ARCH_BLACKFIN 1 +# define LZO_INFO_ARCH "blackfin" +#elif (UINT_MAX == LZO_0xffffL) && defined(__C166__) +# define LZO_ARCH_C166 1 +# define LZO_INFO_ARCH "c166" +#elif defined(__cris__) +# define LZO_ARCH_CRIS 1 +# define LZO_INFO_ARCH "cris" +#elif defined(__IAR_SYSTEMS_ICC__) && defined(__ICCEZ80__) +# define LZO_ARCH_EZ80 1 +# define LZO_INFO_ARCH "ez80" +#elif defined(__H8300__) || defined(__H8300H__) || defined(__H8300S__) || defined(__H8300SX__) +# define LZO_ARCH_H8300 1 +# define LZO_INFO_ARCH "h8300" +#elif defined(__hppa__) || defined(__hppa) +# define LZO_ARCH_HPPA 1 +# define LZO_INFO_ARCH "hppa" +#elif defined(__386__) || defined(__i386__) || defined(__i386) || defined(_M_IX86) || defined(_M_I386) +# define LZO_ARCH_I386 1 +# define LZO_ARCH_IA32 1 +# define LZO_INFO_ARCH "i386" +#elif (LZO_CC_ZORTECHC && defined(__I86__)) +# define LZO_ARCH_I386 1 +# define LZO_ARCH_IA32 1 +# define LZO_INFO_ARCH "i386" +#elif (LZO_OS_DOS32 && LZO_CC_HIGHC) && defined(_I386) +# define LZO_ARCH_I386 1 +# define LZO_ARCH_IA32 1 +# define LZO_INFO_ARCH "i386" +#elif defined(__ia64__) || defined(__ia64) || defined(_M_IA64) +# define LZO_ARCH_IA64 1 +# define LZO_INFO_ARCH "ia64" +#elif (UINT_MAX == LZO_0xffffL) && defined(__m32c__) +# define LZO_ARCH_M16C 1 +# define LZO_INFO_ARCH "m16c" +#elif defined(__IAR_SYSTEMS_ICC__) && defined(__ICCM16C__) +# define LZO_ARCH_M16C 1 +# define LZO_INFO_ARCH "m16c" +#elif defined(__m32r__) +# define LZO_ARCH_M32R 1 +# define LZO_INFO_ARCH "m32r" +#elif (LZO_OS_TOS) || defined(__m68k__) || defined(__m68000__) || defined(__mc68000__) || defined(__mc68020__) || defined(_M_M68K) +# define LZO_ARCH_M68K 1 +# define LZO_INFO_ARCH "m68k" +#elif (UINT_MAX == LZO_0xffffL) && defined(__C251__) +# define LZO_ARCH_MCS251 1 +# define LZO_INFO_ARCH "mcs251" +#elif (UINT_MAX == LZO_0xffffL) && defined(__C51__) +# define LZO_ARCH_MCS51 1 +# define LZO_INFO_ARCH "mcs51" +#elif defined(__IAR_SYSTEMS_ICC__) && defined(__ICC8051__) +# define LZO_ARCH_MCS51 1 +# define LZO_INFO_ARCH "mcs51" +#elif defined(__mips__) || defined(__mips) || defined(_MIPS_ARCH) || defined(_M_MRX000) +# define LZO_ARCH_MIPS 1 +# define LZO_INFO_ARCH "mips" +#elif (UINT_MAX == LZO_0xffffL) && defined(__MSP430__) +# define LZO_ARCH_MSP430 1 +# define LZO_INFO_ARCH "msp430" +#elif defined(__IAR_SYSTEMS_ICC__) && defined(__ICC430__) +# define LZO_ARCH_MSP430 1 +# define LZO_INFO_ARCH "msp430" +#elif defined(__powerpc__) || defined(__powerpc) || defined(__ppc__) || defined(__PPC__) || defined(_M_PPC) || defined(_ARCH_PPC) || defined(_ARCH_PWR) +# define LZO_ARCH_POWERPC 1 +# define LZO_INFO_ARCH "powerpc" +#elif defined(__s390__) || defined(__s390) || defined(__s390x__) || defined(__s390x) +# define LZO_ARCH_S390 1 +# define LZO_INFO_ARCH "s390" +#elif defined(__sh__) || defined(_M_SH) +# define LZO_ARCH_SH 1 +# define LZO_INFO_ARCH "sh" +#elif defined(__sparc__) || defined(__sparc) || defined(__sparcv8) +# define LZO_ARCH_SPARC 1 +# define LZO_INFO_ARCH "sparc" +#elif defined(__SPU__) +# define LZO_ARCH_SPU 1 +# define LZO_INFO_ARCH "spu" +#elif (UINT_MAX == LZO_0xffffL) && defined(__z80) +# define LZO_ARCH_Z80 1 +# define LZO_INFO_ARCH "z80" +#elif (LZO_ARCH_CRAY_PVP) +# if defined(_CRAYSV1) +# define LZO_ARCH_CRAY_SV1 1 +# define LZO_INFO_ARCH "cray_sv1" +# elif (_ADDR64) +# define LZO_ARCH_CRAY_T90 1 +# define LZO_INFO_ARCH "cray_t90" +# elif (_ADDR32) +# define LZO_ARCH_CRAY_YMP 1 +# define LZO_INFO_ARCH "cray_ymp" +# else +# define LZO_ARCH_CRAY_XMP 1 +# define LZO_INFO_ARCH "cray_xmp" +# endif +#else +# define LZO_ARCH_UNKNOWN 1 +# define LZO_INFO_ARCH "unknown" +#endif +#endif +#if 1 && (LZO_ARCH_UNKNOWN) && (LZO_OS_DOS32 || LZO_OS_OS2) +# error "FIXME - missing define for CPU architecture" +#endif +#if 1 && (LZO_ARCH_UNKNOWN) && (LZO_OS_WIN32) +# error "FIXME - missing WIN32 define for CPU architecture" +#endif +#if 1 && (LZO_ARCH_UNKNOWN) && (LZO_OS_WIN64) +# error "FIXME - missing WIN64 define for CPU architecture" +#endif +#if (LZO_OS_OS216 || LZO_OS_WIN16) +# define LZO_ARCH_I086PM 1 +# define LZO_ARCH_IA16PM 1 +#elif 1 && (LZO_OS_DOS16 && defined(BLX286)) +# define LZO_ARCH_I086PM 1 +# define LZO_ARCH_IA16PM 1 +#elif 1 && (LZO_OS_DOS16 && defined(DOSX286)) +# define LZO_ARCH_I086PM 1 +# define LZO_ARCH_IA16PM 1 +#elif 1 && (LZO_OS_DOS16 && LZO_CC_BORLANDC && defined(__DPMI16__)) +# define LZO_ARCH_I086PM 1 +# define LZO_ARCH_IA16PM 1 +#endif +#if (LZO_ARCH_ARM_THUMB) && !(LZO_ARCH_ARM) +# error "this should not happen" +#endif +#if (LZO_ARCH_I086PM) && !(LZO_ARCH_I086) +# error "this should not happen" +#endif +#if (LZO_ARCH_I086) +# if (UINT_MAX != LZO_0xffffL) +# error "this should not happen" +# endif +# if (ULONG_MAX != LZO_0xffffffffL) +# error "this should not happen" +# endif +#endif +#if (LZO_ARCH_I386) +# if (UINT_MAX != LZO_0xffffL) && defined(__i386_int16__) +# error "this should not happen" +# endif +# if (UINT_MAX != LZO_0xffffffffL) && !defined(__i386_int16__) +# error "this should not happen" +# endif +# if (ULONG_MAX != LZO_0xffffffffL) +# error "this should not happen" +# endif +#endif +#if !defined(__LZO_MM_OVERRIDE) +#if (LZO_ARCH_I086) +#if (UINT_MAX != LZO_0xffffL) +# error "this should not happen" +#endif +#if defined(__TINY__) || defined(M_I86TM) || defined(_M_I86TM) +# define LZO_MM_TINY 1 +#elif defined(__HUGE__) || defined(_HUGE_) || defined(M_I86HM) || defined(_M_I86HM) +# define LZO_MM_HUGE 1 +#elif defined(__SMALL__) || defined(M_I86SM) || defined(_M_I86SM) || defined(SMALL_MODEL) +# define LZO_MM_SMALL 1 +#elif defined(__MEDIUM__) || defined(M_I86MM) || defined(_M_I86MM) +# define LZO_MM_MEDIUM 1 +#elif defined(__COMPACT__) || defined(M_I86CM) || defined(_M_I86CM) +# define LZO_MM_COMPACT 1 +#elif defined(__LARGE__) || defined(M_I86LM) || defined(_M_I86LM) || defined(LARGE_MODEL) +# define LZO_MM_LARGE 1 +#elif (LZO_CC_AZTECC) +# if defined(_LARGE_CODE) && defined(_LARGE_DATA) +# define LZO_MM_LARGE 1 +# elif defined(_LARGE_CODE) +# define LZO_MM_MEDIUM 1 +# elif defined(_LARGE_DATA) +# define LZO_MM_COMPACT 1 +# else +# define LZO_MM_SMALL 1 +# endif +#elif (LZO_CC_ZORTECHC && defined(__VCM__)) +# define LZO_MM_LARGE 1 +#else +# error "unknown memory model" +#endif +#if (LZO_OS_DOS16 || LZO_OS_OS216 || LZO_OS_WIN16) +#define LZO_HAVE_MM_HUGE_PTR 1 +#define LZO_HAVE_MM_HUGE_ARRAY 1 +#if (LZO_MM_TINY) +# undef LZO_HAVE_MM_HUGE_ARRAY +#endif +#if (LZO_CC_AZTECC || LZO_CC_PACIFICC || LZO_CC_ZORTECHC) +# undef LZO_HAVE_MM_HUGE_PTR +# undef LZO_HAVE_MM_HUGE_ARRAY +#elif (LZO_CC_DMC || LZO_CC_SYMANTECC) +# undef LZO_HAVE_MM_HUGE_ARRAY +#elif (LZO_CC_MSC && defined(_QC)) +# undef LZO_HAVE_MM_HUGE_ARRAY +# if (_MSC_VER < 600) +# undef LZO_HAVE_MM_HUGE_PTR +# endif +#elif (LZO_CC_TURBOC && (__TURBOC__ < 0x0295)) +# undef LZO_HAVE_MM_HUGE_ARRAY +#endif +#if (LZO_ARCH_I086PM) && !(LZO_HAVE_MM_HUGE_PTR) +# if (LZO_OS_DOS16) +# error "this should not happen" +# elif (LZO_CC_ZORTECHC) +# else +# error "this should not happen" +# endif +#endif +#ifdef __cplusplus +extern "C" { +#endif +#if (LZO_CC_BORLANDC && (__BORLANDC__ >= 0x0200)) + extern void __near __cdecl _AHSHIFT(void); +# define LZO_MM_AHSHIFT ((unsigned) _AHSHIFT) +#elif (LZO_CC_DMC || LZO_CC_SYMANTECC || LZO_CC_ZORTECHC) + extern void __near __cdecl _AHSHIFT(void); +# define LZO_MM_AHSHIFT ((unsigned) _AHSHIFT) +#elif (LZO_CC_MSC || LZO_CC_TOPSPEEDC) + extern void __near __cdecl _AHSHIFT(void); +# define LZO_MM_AHSHIFT ((unsigned) _AHSHIFT) +#elif (LZO_CC_TURBOC && (__TURBOC__ >= 0x0295)) + extern void __near __cdecl _AHSHIFT(void); +# define LZO_MM_AHSHIFT ((unsigned) _AHSHIFT) +#elif ((LZO_CC_AZTECC || LZO_CC_PACIFICC || LZO_CC_TURBOC) && LZO_OS_DOS16) +# define LZO_MM_AHSHIFT 12 +#elif (LZO_CC_WATCOMC) + extern unsigned char _HShift; +# define LZO_MM_AHSHIFT ((unsigned) _HShift) +#else +# error "FIXME - implement LZO_MM_AHSHIFT" +#endif +#ifdef __cplusplus +} +#endif +#endif +#elif (LZO_ARCH_C166) +#if !defined(__MODEL__) +# error "FIXME - C166 __MODEL__" +#elif ((__MODEL__) == 0) +# define LZO_MM_SMALL 1 +#elif ((__MODEL__) == 1) +# define LZO_MM_SMALL 1 +#elif ((__MODEL__) == 2) +# define LZO_MM_LARGE 1 +#elif ((__MODEL__) == 3) +# define LZO_MM_TINY 1 +#elif ((__MODEL__) == 4) +# define LZO_MM_XTINY 1 +#elif ((__MODEL__) == 5) +# define LZO_MM_XSMALL 1 +#else +# error "FIXME - C166 __MODEL__" +#endif +#elif (LZO_ARCH_MCS251) +#if !defined(__MODEL__) +# error "FIXME - MCS251 __MODEL__" +#elif ((__MODEL__) == 0) +# define LZO_MM_SMALL 1 +#elif ((__MODEL__) == 2) +# define LZO_MM_LARGE 1 +#elif ((__MODEL__) == 3) +# define LZO_MM_TINY 1 +#elif ((__MODEL__) == 4) +# define LZO_MM_XTINY 1 +#elif ((__MODEL__) == 5) +# define LZO_MM_XSMALL 1 +#else +# error "FIXME - MCS251 __MODEL__" +#endif +#elif (LZO_ARCH_MCS51) +#if !defined(__MODEL__) +# error "FIXME - MCS51 __MODEL__" +#elif ((__MODEL__) == 1) +# define LZO_MM_SMALL 1 +#elif ((__MODEL__) == 2) +# define LZO_MM_LARGE 1 +#elif ((__MODEL__) == 3) +# define LZO_MM_TINY 1 +#elif ((__MODEL__) == 4) +# define LZO_MM_XTINY 1 +#elif ((__MODEL__) == 5) +# define LZO_MM_XSMALL 1 +#else +# error "FIXME - MCS51 __MODEL__" +#endif +#elif (LZO_ARCH_CRAY_PVP) +# define LZO_MM_PVP 1 +#else +# define LZO_MM_FLAT 1 +#endif +#if (LZO_MM_COMPACT) +# define LZO_INFO_MM "compact" +#elif (LZO_MM_FLAT) +# define LZO_INFO_MM "flat" +#elif (LZO_MM_HUGE) +# define LZO_INFO_MM "huge" +#elif (LZO_MM_LARGE) +# define LZO_INFO_MM "large" +#elif (LZO_MM_MEDIUM) +# define LZO_INFO_MM "medium" +#elif (LZO_MM_PVP) +# define LZO_INFO_MM "pvp" +#elif (LZO_MM_SMALL) +# define LZO_INFO_MM "small" +#elif (LZO_MM_TINY) +# define LZO_INFO_MM "tiny" +#else +# error "unknown memory model" +#endif +#endif +#if defined(SIZEOF_SHORT) +# define LZO_SIZEOF_SHORT (SIZEOF_SHORT) +#endif +#if defined(SIZEOF_INT) +# define LZO_SIZEOF_INT (SIZEOF_INT) +#endif +#if defined(SIZEOF_LONG) +# define LZO_SIZEOF_LONG (SIZEOF_LONG) +#endif +#if defined(SIZEOF_LONG_LONG) +# define LZO_SIZEOF_LONG_LONG (SIZEOF_LONG_LONG) +#endif +#if defined(SIZEOF___INT16) +# define LZO_SIZEOF___INT16 (SIZEOF___INT16) +#endif +#if defined(SIZEOF___INT32) +# define LZO_SIZEOF___INT32 (SIZEOF___INT32) +#endif +#if defined(SIZEOF___INT64) +# define LZO_SIZEOF___INT64 (SIZEOF___INT64) +#endif +#if defined(SIZEOF_VOID_P) +# define LZO_SIZEOF_VOID_P (SIZEOF_VOID_P) +#endif +#if defined(SIZEOF_SIZE_T) +# define LZO_SIZEOF_SIZE_T (SIZEOF_SIZE_T) +#endif +#if defined(SIZEOF_PTRDIFF_T) +# define LZO_SIZEOF_PTRDIFF_T (SIZEOF_PTRDIFF_T) +#endif +#define __LZO_LSR(x,b) (((x)+0ul) >> (b)) +#if !defined(LZO_SIZEOF_SHORT) +# if (LZO_ARCH_CRAY_PVP) +# define LZO_SIZEOF_SHORT 8 +# elif (USHRT_MAX == LZO_0xffffL) +# define LZO_SIZEOF_SHORT 2 +# elif (__LZO_LSR(USHRT_MAX,7) == 1) +# define LZO_SIZEOF_SHORT 1 +# elif (__LZO_LSR(USHRT_MAX,15) == 1) +# define LZO_SIZEOF_SHORT 2 +# elif (__LZO_LSR(USHRT_MAX,31) == 1) +# define LZO_SIZEOF_SHORT 4 +# elif (__LZO_LSR(USHRT_MAX,63) == 1) +# define LZO_SIZEOF_SHORT 8 +# elif (__LZO_LSR(USHRT_MAX,127) == 1) +# define LZO_SIZEOF_SHORT 16 +# else +# error "LZO_SIZEOF_SHORT" +# endif +#endif +#if !defined(LZO_SIZEOF_INT) +# if (LZO_ARCH_CRAY_PVP) +# define LZO_SIZEOF_INT 8 +# elif (UINT_MAX == LZO_0xffffL) +# define LZO_SIZEOF_INT 2 +# elif (UINT_MAX == LZO_0xffffffffL) +# define LZO_SIZEOF_INT 4 +# elif (__LZO_LSR(UINT_MAX,7) == 1) +# define LZO_SIZEOF_INT 1 +# elif (__LZO_LSR(UINT_MAX,15) == 1) +# define LZO_SIZEOF_INT 2 +# elif (__LZO_LSR(UINT_MAX,31) == 1) +# define LZO_SIZEOF_INT 4 +# elif (__LZO_LSR(UINT_MAX,63) == 1) +# define LZO_SIZEOF_INT 8 +# elif (__LZO_LSR(UINT_MAX,127) == 1) +# define LZO_SIZEOF_INT 16 +# else +# error "LZO_SIZEOF_INT" +# endif +#endif +#if !defined(LZO_SIZEOF_LONG) +# if (ULONG_MAX == LZO_0xffffffffL) +# define LZO_SIZEOF_LONG 4 +# elif (__LZO_LSR(ULONG_MAX,7) == 1) +# define LZO_SIZEOF_LONG 1 +# elif (__LZO_LSR(ULONG_MAX,15) == 1) +# define LZO_SIZEOF_LONG 2 +# elif (__LZO_LSR(ULONG_MAX,31) == 1) +# define LZO_SIZEOF_LONG 4 +# elif (__LZO_LSR(ULONG_MAX,63) == 1) +# define LZO_SIZEOF_LONG 8 +# elif (__LZO_LSR(ULONG_MAX,127) == 1) +# define LZO_SIZEOF_LONG 16 +# else +# error "LZO_SIZEOF_LONG" +# endif +#endif +#if !defined(LZO_SIZEOF_LONG_LONG) && !defined(LZO_SIZEOF___INT64) +#if (LZO_SIZEOF_LONG > 0 && LZO_SIZEOF_LONG < 8) +# if defined(__LONG_MAX__) && defined(__LONG_LONG_MAX__) +# if (LZO_CC_GNUC >= 0x030300ul) +# if ((__LONG_MAX__)+0 == (__LONG_LONG_MAX__)+0) +# define LZO_SIZEOF_LONG_LONG LZO_SIZEOF_LONG +# elif (__LZO_LSR(__LONG_LONG_MAX__,30) == 1) +# define LZO_SIZEOF_LONG_LONG 4 +# endif +# endif +# endif +#endif +#endif +#if !defined(LZO_SIZEOF_LONG_LONG) && !defined(LZO_SIZEOF___INT64) +#if (LZO_SIZEOF_LONG > 0 && LZO_SIZEOF_LONG < 8) +#if (LZO_ARCH_I086 && LZO_CC_DMC) +#elif (LZO_CC_CILLY) && defined(__GNUC__) +# define LZO_SIZEOF_LONG_LONG 8 +#elif (LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE) +# define LZO_SIZEOF_LONG_LONG 8 +#elif ((LZO_OS_WIN32 || LZO_OS_WIN64 || defined(_WIN32)) && LZO_CC_MSC && (_MSC_VER >= 1400)) +# define LZO_SIZEOF_LONG_LONG 8 +#elif (LZO_OS_WIN64 || defined(_WIN64)) +# define LZO_SIZEOF___INT64 8 +#elif (LZO_ARCH_I386 && (LZO_CC_DMC)) +# define LZO_SIZEOF_LONG_LONG 8 +#elif (LZO_ARCH_I386 && (LZO_CC_SYMANTECC && (__SC__ >= 0x700))) +# define LZO_SIZEOF_LONG_LONG 8 +#elif (LZO_ARCH_I386 && (LZO_CC_INTELC && defined(__linux__))) +# define LZO_SIZEOF_LONG_LONG 8 +#elif (LZO_ARCH_I386 && (LZO_CC_MWERKS || LZO_CC_PELLESC || LZO_CC_PGI || LZO_CC_SUNPROC)) +# define LZO_SIZEOF_LONG_LONG 8 +#elif (LZO_ARCH_I386 && (LZO_CC_INTELC || LZO_CC_MSC)) +# define LZO_SIZEOF___INT64 8 +#elif ((LZO_OS_WIN32 || defined(_WIN32)) && (LZO_CC_MSC)) +# define LZO_SIZEOF___INT64 8 +#elif (LZO_ARCH_I386 && (LZO_CC_BORLANDC && (__BORLANDC__ >= 0x0520))) +# define LZO_SIZEOF___INT64 8 +#elif (LZO_ARCH_I386 && (LZO_CC_WATCOMC && (__WATCOMC__ >= 1100))) +# define LZO_SIZEOF___INT64 8 +#elif (LZO_CC_WATCOMC && defined(_INTEGRAL_MAX_BITS) && (_INTEGRAL_MAX_BITS == 64)) +# define LZO_SIZEOF___INT64 8 +#elif (LZO_OS_OS400 || defined(__OS400__)) && defined(__LLP64_IFC__) +# define LZO_SIZEOF_LONG_LONG 8 +#elif (defined(__vms) || defined(__VMS)) && (__INITIAL_POINTER_SIZE+0 == 64) +# define LZO_SIZEOF_LONG_LONG 8 +#elif (LZO_CC_SDCC) && (LZO_SIZEOF_INT == 2) +#elif 1 && defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) +# define LZO_SIZEOF_LONG_LONG 8 +#endif +#endif +#endif +#if defined(__cplusplus) && (LZO_CC_GNUC) +# if (LZO_CC_GNUC < 0x020800ul) +# undef LZO_SIZEOF_LONG_LONG +# endif +#endif +#if (LZO_CFG_NO_LONG_LONG) || defined(__NO_LONG_LONG) +# undef LZO_SIZEOF_LONG_LONG +#endif +#if !defined(LZO_SIZEOF_VOID_P) +#if (LZO_ARCH_I086) +# define __LZO_WORDSIZE 2 +# if (LZO_MM_TINY || LZO_MM_SMALL || LZO_MM_MEDIUM) +# define LZO_SIZEOF_VOID_P 2 +# elif (LZO_MM_COMPACT || LZO_MM_LARGE || LZO_MM_HUGE) +# define LZO_SIZEOF_VOID_P 4 +# else +# error "LZO_MM" +# endif +#elif (LZO_ARCH_AVR || LZO_ARCH_Z80) +# define __LZO_WORDSIZE 1 +# define LZO_SIZEOF_VOID_P 2 +#elif (LZO_ARCH_C166 || LZO_ARCH_MCS51 || LZO_ARCH_MCS251 || LZO_ARCH_MSP430) +# define LZO_SIZEOF_VOID_P 2 +#elif (LZO_ARCH_H8300) +# if defined(__NORMAL_MODE__) +# define __LZO_WORDSIZE 4 +# define LZO_SIZEOF_VOID_P 2 +# elif defined(__H8300H__) || defined(__H8300S__) || defined(__H8300SX__) +# define __LZO_WORDSIZE 4 +# define LZO_SIZEOF_VOID_P 4 +# else +# define __LZO_WORDSIZE 2 +# define LZO_SIZEOF_VOID_P 2 +# endif +# if (LZO_CC_GNUC && (LZO_CC_GNUC < 0x040000ul)) && (LZO_SIZEOF_INT == 4) +# define LZO_SIZEOF_SIZE_T LZO_SIZEOF_INT +# define LZO_SIZEOF_PTRDIFF_T LZO_SIZEOF_INT +# endif +#elif (LZO_ARCH_M16C) +# define __LZO_WORDSIZE 2 +# if defined(__m32c_cpu__) || defined(__m32cm_cpu__) +# define LZO_SIZEOF_VOID_P 4 +# else +# define LZO_SIZEOF_VOID_P 2 +# endif +#elif (LZO_SIZEOF_LONG == 8) && ((defined(__mips__) && defined(__R5900__)) || defined(__MIPS_PSX2__)) +# define __LZO_WORDSIZE 8 +# define LZO_SIZEOF_VOID_P 4 +#elif defined(__LLP64__) || defined(__LLP64) || defined(_LLP64) || defined(_WIN64) +# define __LZO_WORDSIZE 8 +# define LZO_SIZEOF_VOID_P 8 +#elif (LZO_OS_OS400 || defined(__OS400__)) && defined(__LLP64_IFC__) +# define LZO_SIZEOF_VOID_P LZO_SIZEOF_LONG +# define LZO_SIZEOF_SIZE_T LZO_SIZEOF_LONG +# define LZO_SIZEOF_PTRDIFF_T LZO_SIZEOF_LONG +#elif (LZO_OS_OS400 || defined(__OS400__)) +# define __LZO_WORDSIZE LZO_SIZEOF_LONG +# define LZO_SIZEOF_VOID_P 16 +# define LZO_SIZEOF_SIZE_T LZO_SIZEOF_LONG +# define LZO_SIZEOF_PTRDIFF_T LZO_SIZEOF_LONG +#elif (defined(__vms) || defined(__VMS)) && (__INITIAL_POINTER_SIZE+0 == 64) +# define LZO_SIZEOF_VOID_P 8 +# define LZO_SIZEOF_SIZE_T LZO_SIZEOF_LONG +# define LZO_SIZEOF_PTRDIFF_T LZO_SIZEOF_LONG +#elif (LZO_ARCH_SPU) +# if 0 +# define __LZO_WORDSIZE 16 +# endif +# define LZO_SIZEOF_VOID_P 4 +#else +# define LZO_SIZEOF_VOID_P LZO_SIZEOF_LONG +#endif +#endif +#if !defined(LZO_WORDSIZE) +# if defined(__LZO_WORDSIZE) +# define LZO_WORDSIZE __LZO_WORDSIZE +# else +# define LZO_WORDSIZE LZO_SIZEOF_VOID_P +# endif +#endif +#if !defined(LZO_SIZEOF_SIZE_T) +#if (LZO_ARCH_I086 || LZO_ARCH_M16C) +# define LZO_SIZEOF_SIZE_T 2 +#else +# define LZO_SIZEOF_SIZE_T LZO_SIZEOF_VOID_P +#endif +#endif +#if !defined(LZO_SIZEOF_PTRDIFF_T) +#if (LZO_ARCH_I086) +# if (LZO_MM_TINY || LZO_MM_SMALL || LZO_MM_MEDIUM || LZO_MM_HUGE) +# define LZO_SIZEOF_PTRDIFF_T LZO_SIZEOF_VOID_P +# elif (LZO_MM_COMPACT || LZO_MM_LARGE) +# if (LZO_CC_BORLANDC || LZO_CC_TURBOC) +# define LZO_SIZEOF_PTRDIFF_T 4 +# else +# define LZO_SIZEOF_PTRDIFF_T 2 +# endif +# else +# error "LZO_MM" +# endif +#else +# define LZO_SIZEOF_PTRDIFF_T LZO_SIZEOF_SIZE_T +#endif +#endif +#if (LZO_ABI_NEUTRAL_ENDIAN) +# undef LZO_ABI_BIG_ENDIAN +# undef LZO_ABI_LITTLE_ENDIAN +#elif !(LZO_ABI_BIG_ENDIAN) && !(LZO_ABI_LITTLE_ENDIAN) +#if (LZO_ARCH_ALPHA) && (LZO_ARCH_CRAY_MPP) +# define LZO_ABI_BIG_ENDIAN 1 +#elif (LZO_ARCH_IA64) && (LZO_OS_POSIX_LINUX || LZO_OS_WIN64) +# define LZO_ABI_LITTLE_ENDIAN 1 +#elif (LZO_ARCH_ALPHA || LZO_ARCH_AMD64 || LZO_ARCH_BLACKFIN || LZO_ARCH_CRIS || LZO_ARCH_I086 || LZO_ARCH_I386 || LZO_ARCH_MSP430) +# define LZO_ABI_LITTLE_ENDIAN 1 +#elif (LZO_ARCH_AVR32 || LZO_ARCH_M68K || LZO_ARCH_S390) +# define LZO_ABI_BIG_ENDIAN 1 +#elif 1 && defined(__IAR_SYSTEMS_ICC__) && defined(__LITTLE_ENDIAN__) +# if (__LITTLE_ENDIAN__ == 1) +# define LZO_ABI_LITTLE_ENDIAN 1 +# else +# define LZO_ABI_BIG_ENDIAN 1 +# endif +#elif 1 && defined(__BIG_ENDIAN__) && !defined(__LITTLE_ENDIAN__) +# define LZO_ABI_BIG_ENDIAN 1 +#elif 1 && defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__) +# define LZO_ABI_LITTLE_ENDIAN 1 +#elif 1 && (LZO_ARCH_ARM) && defined(__ARMEB__) && !defined(__ARMEL__) +# define LZO_ABI_BIG_ENDIAN 1 +#elif 1 && (LZO_ARCH_ARM) && defined(__ARMEL__) && !defined(__ARMEB__) +# define LZO_ABI_LITTLE_ENDIAN 1 +#elif 1 && (LZO_ARCH_MIPS) && defined(__MIPSEB__) && !defined(__MIPSEL__) +# define LZO_ABI_BIG_ENDIAN 1 +#elif 1 && (LZO_ARCH_MIPS) && defined(__MIPSEL__) && !defined(__MIPSEB__) +# define LZO_ABI_LITTLE_ENDIAN 1 +#endif +#endif +#if (LZO_ABI_BIG_ENDIAN) && (LZO_ABI_LITTLE_ENDIAN) +# error "this should not happen" +#endif +#if (LZO_ABI_BIG_ENDIAN) +# define LZO_INFO_ABI_ENDIAN "be" +#elif (LZO_ABI_LITTLE_ENDIAN) +# define LZO_INFO_ABI_ENDIAN "le" +#elif (LZO_ABI_NEUTRAL_ENDIAN) +# define LZO_INFO_ABI_ENDIAN "neutral" +#endif +#if (LZO_SIZEOF_INT == 1 && LZO_SIZEOF_LONG == 2 && LZO_SIZEOF_VOID_P == 2) +# define LZO_ABI_I8LP16 1 +# define LZO_INFO_ABI_PM "i8lp16" +#elif (LZO_SIZEOF_INT == 2 && LZO_SIZEOF_LONG == 2 && LZO_SIZEOF_VOID_P == 2) +# define LZO_ABI_ILP16 1 +# define LZO_INFO_ABI_PM "ilp16" +#elif (LZO_SIZEOF_INT == 4 && LZO_SIZEOF_LONG == 4 && LZO_SIZEOF_VOID_P == 4) +# define LZO_ABI_ILP32 1 +# define LZO_INFO_ABI_PM "ilp32" +#elif (LZO_SIZEOF_INT == 4 && LZO_SIZEOF_LONG == 4 && LZO_SIZEOF_VOID_P == 8 && LZO_SIZEOF_SIZE_T == 8) +# define LZO_ABI_LLP64 1 +# define LZO_INFO_ABI_PM "llp64" +#elif (LZO_SIZEOF_INT == 4 && LZO_SIZEOF_LONG == 8 && LZO_SIZEOF_VOID_P == 8) +# define LZO_ABI_LP64 1 +# define LZO_INFO_ABI_PM "lp64" +#elif (LZO_SIZEOF_INT == 8 && LZO_SIZEOF_LONG == 8 && LZO_SIZEOF_VOID_P == 8) +# define LZO_ABI_ILP64 1 +# define LZO_INFO_ABI_PM "ilp64" +#elif (LZO_SIZEOF_INT == 4 && LZO_SIZEOF_LONG == 8 && LZO_SIZEOF_VOID_P == 4) +# define LZO_ABI_IP32L64 1 +# define LZO_INFO_ABI_PM "ip32l64" +#endif +#if !defined(__LZO_LIBC_OVERRIDE) +#if (LZO_LIBC_NAKED) +# define LZO_INFO_LIBC "naked" +#elif (LZO_LIBC_FREESTANDING) +# define LZO_INFO_LIBC "freestanding" +#elif (LZO_LIBC_MOSTLY_FREESTANDING) +# define LZO_INFO_LIBC "mfreestanding" +#elif (LZO_LIBC_ISOC90) +# define LZO_INFO_LIBC "isoc90" +#elif (LZO_LIBC_ISOC99) +# define LZO_INFO_LIBC "isoc99" +#elif defined(__dietlibc__) +# define LZO_LIBC_DIETLIBC 1 +# define LZO_INFO_LIBC "dietlibc" +#elif defined(_NEWLIB_VERSION) +# define LZO_LIBC_NEWLIB 1 +# define LZO_INFO_LIBC "newlib" +#elif defined(__UCLIBC__) && defined(__UCLIBC_MAJOR__) && defined(__UCLIBC_MINOR__) +# if defined(__UCLIBC_SUBLEVEL__) +# define LZO_LIBC_UCLIBC (__UCLIBC_MAJOR__ * 0x10000L + __UCLIBC_MINOR__ * 0x100 + __UCLIBC_SUBLEVEL__) +# else +# define LZO_LIBC_UCLIBC 0x00090bL +# endif +# define LZO_INFO_LIBC "uclibc" +#elif defined(__GLIBC__) && defined(__GLIBC_MINOR__) +# define LZO_LIBC_GLIBC (__GLIBC__ * 0x10000L + __GLIBC_MINOR__ * 0x100) +# define LZO_INFO_LIBC "glibc" +#elif (LZO_CC_MWERKS) && defined(__MSL__) +# define LZO_LIBC_MSL __MSL__ +# define LZO_INFO_LIBC "msl" +#elif 1 && defined(__IAR_SYSTEMS_ICC__) +# define LZO_LIBC_ISOC90 1 +# define LZO_INFO_LIBC "isoc90" +#else +# define LZO_LIBC_DEFAULT 1 +# define LZO_INFO_LIBC "default" +#endif +#endif +#if !defined(__lzo_gnuc_extension__) +#if (LZO_CC_GNUC >= 0x020800ul) +# define __lzo_gnuc_extension__ __extension__ +#elif (LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) +# define __lzo_gnuc_extension__ __extension__ +#else +# define __lzo_gnuc_extension__ /*empty*/ +#endif +#endif +#if !defined(__lzo_ua_volatile) +# define __lzo_ua_volatile volatile +#endif +#if !defined(__lzo_alignof) +#if (LZO_CC_CILLY || LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE || LZO_CC_PGI) +# define __lzo_alignof(e) __alignof__(e) +#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 700)) +# define __lzo_alignof(e) __alignof__(e) +#elif (LZO_CC_MSC && (_MSC_VER >= 1300)) +# define __lzo_alignof(e) __alignof(e) +#elif (LZO_CC_SUNPROC && (LZO_CC_SUNPROC >= 0x5100)) +# define __lzo_alignof(e) __alignof__(e) +#endif +#endif +#if defined(__lzo_alignof) +# define __lzo_HAVE_alignof 1 +#endif +#if !defined(__lzo_constructor) +#if (LZO_CC_GNUC >= 0x030400ul) +# define __lzo_constructor __attribute__((__constructor__,__used__)) +#elif (LZO_CC_GNUC >= 0x020700ul) +# define __lzo_constructor __attribute__((__constructor__)) +#elif (LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) +# define __lzo_constructor __attribute__((__constructor__)) +#endif +#endif +#if defined(__lzo_constructor) +# define __lzo_HAVE_constructor 1 +#endif +#if !defined(__lzo_destructor) +#if (LZO_CC_GNUC >= 0x030400ul) +# define __lzo_destructor __attribute__((__destructor__,__used__)) +#elif (LZO_CC_GNUC >= 0x020700ul) +# define __lzo_destructor __attribute__((__destructor__)) +#elif (LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) +# define __lzo_destructor __attribute__((__destructor__)) +#endif +#endif +#if defined(__lzo_destructor) +# define __lzo_HAVE_destructor 1 +#endif +#if (__lzo_HAVE_destructor) && !(__lzo_HAVE_constructor) +# error "this should not happen" +#endif +#if !defined(__lzo_inline) +#if (LZO_CC_TURBOC && (__TURBOC__ <= 0x0295)) +#elif defined(__cplusplus) +# define __lzo_inline inline +#elif (LZO_CC_BORLANDC && (__BORLANDC__ >= 0x0550)) +# define __lzo_inline __inline +#elif (LZO_CC_CILLY || LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE || LZO_CC_PGI) +# define __lzo_inline __inline__ +#elif (LZO_CC_DMC) +# define __lzo_inline __inline +#elif (LZO_CC_INTELC) +# define __lzo_inline __inline +#elif (LZO_CC_MWERKS && (__MWERKS__ >= 0x2405)) +# define __lzo_inline __inline +#elif (LZO_CC_MSC && (_MSC_VER >= 900)) +# define __lzo_inline __inline +#elif (LZO_CC_SUNPROC && (LZO_CC_SUNPROC >= 0x5100)) +# define __lzo_inline __inline__ +#elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) +# define __lzo_inline inline +#endif +#endif +#if defined(__lzo_inline) +# define __lzo_HAVE_inline 1 +#else +# define __lzo_inline /*empty*/ +#endif +#if !defined(__lzo_forceinline) +#if (LZO_CC_GNUC >= 0x030200ul) +# define __lzo_forceinline __inline__ __attribute__((__always_inline__)) +#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 450) && LZO_CC_SYNTAX_MSC) +# define __lzo_forceinline __forceinline +#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 800) && LZO_CC_SYNTAX_GNUC) +# define __lzo_forceinline __inline__ __attribute__((__always_inline__)) +#elif (LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) +# define __lzo_forceinline __inline__ __attribute__((__always_inline__)) +#elif (LZO_CC_MSC && (_MSC_VER >= 1200)) +# define __lzo_forceinline __forceinline +#elif (LZO_CC_SUNPROC && (LZO_CC_SUNPROC >= 0x5100)) +# define __lzo_forceinline __inline__ __attribute__((__always_inline__)) +#endif +#endif +#if defined(__lzo_forceinline) +# define __lzo_HAVE_forceinline 1 +#else +# define __lzo_forceinline /*empty*/ +#endif +#if !defined(__lzo_noinline) +#if 1 && (LZO_ARCH_I386) && (LZO_CC_GNUC >= 0x040000ul) && (LZO_CC_GNUC < 0x040003ul) +# define __lzo_noinline __attribute__((__noinline__,__used__)) +#elif (LZO_CC_GNUC >= 0x030200ul) +# define __lzo_noinline __attribute__((__noinline__)) +#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 600) && LZO_CC_SYNTAX_MSC) +# define __lzo_noinline __declspec(noinline) +#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 800) && LZO_CC_SYNTAX_GNUC) +# define __lzo_noinline __attribute__((__noinline__)) +#elif (LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) +# define __lzo_noinline __attribute__((__noinline__)) +#elif (LZO_CC_MSC && (_MSC_VER >= 1300)) +# define __lzo_noinline __declspec(noinline) +#elif (LZO_CC_MWERKS && (__MWERKS__ >= 0x3200) && (LZO_OS_WIN32 || LZO_OS_WIN64)) +# if defined(__cplusplus) +# else +# define __lzo_noinline __declspec(noinline) +# endif +#elif (LZO_CC_SUNPROC && (LZO_CC_SUNPROC >= 0x5100)) +# define __lzo_noinline __attribute__((__noinline__)) +#endif +#endif +#if defined(__lzo_noinline) +# define __lzo_HAVE_noinline 1 +#else +# define __lzo_noinline /*empty*/ +#endif +#if (__lzo_HAVE_forceinline || __lzo_HAVE_noinline) && !(__lzo_HAVE_inline) +# error "this should not happen" +#endif +#if !defined(__lzo_noreturn) +#if (LZO_CC_GNUC >= 0x020700ul) +# define __lzo_noreturn __attribute__((__noreturn__)) +#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 450) && LZO_CC_SYNTAX_MSC) +# define __lzo_noreturn __declspec(noreturn) +#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 600) && LZO_CC_SYNTAX_GNUC) +# define __lzo_noreturn __attribute__((__noreturn__)) +#elif (LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) +# define __lzo_noreturn __attribute__((__noreturn__)) +#elif (LZO_CC_MSC && (_MSC_VER >= 1200)) +# define __lzo_noreturn __declspec(noreturn) +#endif +#endif +#if defined(__lzo_noreturn) +# define __lzo_HAVE_noreturn 1 +#else +# define __lzo_noreturn /*empty*/ +#endif +#if !defined(__lzo_nothrow) +#if (LZO_CC_GNUC >= 0x030300ul) +# define __lzo_nothrow __attribute__((__nothrow__)) +#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 450) && LZO_CC_SYNTAX_MSC) && defined(__cplusplus) +# define __lzo_nothrow __declspec(nothrow) +#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 900) && LZO_CC_SYNTAX_GNUC) +# define __lzo_nothrow __attribute__((__nothrow__)) +#elif (LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) +# define __lzo_nothrow __attribute__((__nothrow__)) +#elif (LZO_CC_MSC && (_MSC_VER >= 1200)) && defined(__cplusplus) +# define __lzo_nothrow __declspec(nothrow) +#endif +#endif +#if defined(__lzo_nothrow) +# define __lzo_HAVE_nothrow 1 +#else +# define __lzo_nothrow /*empty*/ +#endif +#if !defined(__lzo_restrict) +#if (LZO_CC_GNUC >= 0x030400ul) +# define __lzo_restrict __restrict__ +#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 600) && LZO_CC_SYNTAX_GNUC) +# define __lzo_restrict __restrict__ +#elif (LZO_CC_CLANG || LZO_CC_LLVM) +# define __lzo_restrict __restrict__ +#elif (LZO_CC_MSC && (_MSC_VER >= 1400)) +# define __lzo_restrict __restrict +#endif +#endif +#if defined(__lzo_restrict) +# define __lzo_HAVE_restrict 1 +#else +# define __lzo_restrict /*empty*/ +#endif +#if !defined(__lzo_likely) && !defined(__lzo_unlikely) +#if (LZO_CC_GNUC >= 0x030200ul) +# define __lzo_likely(e) (__builtin_expect(!!(e),1)) +# define __lzo_unlikely(e) (__builtin_expect(!!(e),0)) +#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 800)) +# define __lzo_likely(e) (__builtin_expect(!!(e),1)) +# define __lzo_unlikely(e) (__builtin_expect(!!(e),0)) +#elif (LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) +# define __lzo_likely(e) (__builtin_expect(!!(e),1)) +# define __lzo_unlikely(e) (__builtin_expect(!!(e),0)) +#endif +#endif +#if defined(__lzo_likely) +# define __lzo_HAVE_likely 1 +#else +# define __lzo_likely(e) (e) +#endif +#if defined(__lzo_unlikely) +# define __lzo_HAVE_unlikely 1 +#else +# define __lzo_unlikely(e) (e) +#endif +#if !defined(LZO_UNUSED) +# if (LZO_CC_BORLANDC && (__BORLANDC__ >= 0x0600)) +# define LZO_UNUSED(var) ((void) &var) +# elif (LZO_CC_BORLANDC || LZO_CC_HIGHC || LZO_CC_NDPC || LZO_CC_PELLESC || LZO_CC_TURBOC) +# define LZO_UNUSED(var) if (&var) ; else +# elif (LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE) +# define LZO_UNUSED(var) ((void) var) +# elif (LZO_CC_MSC && (_MSC_VER < 900)) +# define LZO_UNUSED(var) if (&var) ; else +# elif (LZO_CC_KEILC) +# define LZO_UNUSED(var) {extern int __lzo_unused[1-2*!(sizeof(var)>0)];} +# elif (LZO_CC_PACIFICC) +# define LZO_UNUSED(var) ((void) sizeof(var)) +# elif (LZO_CC_WATCOMC) && defined(__cplusplus) +# define LZO_UNUSED(var) ((void) var) +# else +# define LZO_UNUSED(var) ((void) &var) +# endif +#endif +#if !defined(LZO_UNUSED_FUNC) +# if (LZO_CC_BORLANDC && (__BORLANDC__ >= 0x0600)) +# define LZO_UNUSED_FUNC(func) ((void) func) +# elif (LZO_CC_BORLANDC || LZO_CC_NDPC || LZO_CC_TURBOC) +# define LZO_UNUSED_FUNC(func) if (func) ; else +# elif (LZO_CC_CLANG || LZO_CC_LLVM) +# define LZO_UNUSED_FUNC(func) ((void) &func) +# elif (LZO_CC_MSC && (_MSC_VER < 900)) +# define LZO_UNUSED_FUNC(func) if (func) ; else +# elif (LZO_CC_MSC) +# define LZO_UNUSED_FUNC(func) ((void) &func) +# elif (LZO_CC_KEILC || LZO_CC_PELLESC) +# define LZO_UNUSED_FUNC(func) {extern int __lzo_unused[1-2*!(sizeof((int)func)>0)];} +# else +# define LZO_UNUSED_FUNC(func) ((void) func) +# endif +#endif +#if !defined(LZO_UNUSED_LABEL) +# if (LZO_CC_WATCOMC) && defined(__cplusplus) +# define LZO_UNUSED_LABEL(l) switch(0) case 1:goto l +# elif (LZO_CC_CLANG || LZO_CC_INTELC || LZO_CC_WATCOMC) +# define LZO_UNUSED_LABEL(l) if (0) goto l +# else +# define LZO_UNUSED_LABEL(l) switch(0) case 1:goto l +# endif +#endif +#if !defined(LZO_DEFINE_UNINITIALIZED_VAR) +# if 0 +# define LZO_DEFINE_UNINITIALIZED_VAR(type,var,init) type var +# elif 0 && (LZO_CC_GNUC) +# define LZO_DEFINE_UNINITIALIZED_VAR(type,var,init) type var = var +# else +# define LZO_DEFINE_UNINITIALIZED_VAR(type,var,init) type var = init +# endif +#endif +#if !defined(LZO_UNCONST_CAST) +# if 0 && defined(__cplusplus) +# define LZO_UNCONST_CAST(t,e) (const_cast (e)) +# elif (LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE) +# define LZO_UNCONST_CAST(t,e) ((t) ((void *) ((char *) ((lzo_uintptr_t) ((const void *) (e)))))) +# else +# define LZO_UNCONST_CAST(t,e) ((t) ((void *) ((char *) ((const void *) (e))))) +# endif +#endif +#if !defined(LZO_COMPILE_TIME_ASSERT_HEADER) +# if (LZO_CC_AZTECC || LZO_CC_ZORTECHC) +# define LZO_COMPILE_TIME_ASSERT_HEADER(e) extern int __lzo_cta[1-!(e)]; +# elif (LZO_CC_DMC || LZO_CC_SYMANTECC) +# define LZO_COMPILE_TIME_ASSERT_HEADER(e) extern int __lzo_cta[1u-2*!(e)]; +# elif (LZO_CC_TURBOC && (__TURBOC__ == 0x0295)) +# define LZO_COMPILE_TIME_ASSERT_HEADER(e) extern int __lzo_cta[1-!(e)]; +# else +# define LZO_COMPILE_TIME_ASSERT_HEADER(e) extern int __lzo_cta[1-2*!(e)]; +# endif +#endif +#if !defined(LZO_COMPILE_TIME_ASSERT) +# if (LZO_CC_AZTECC) +# define LZO_COMPILE_TIME_ASSERT(e) {typedef int __lzo_cta_t[1-!(e)];} +# elif (LZO_CC_DMC || LZO_CC_PACIFICC || LZO_CC_SYMANTECC || LZO_CC_ZORTECHC) +# define LZO_COMPILE_TIME_ASSERT(e) switch(0) case 1:case !(e):break; +# elif (LZO_CC_MSC && (_MSC_VER < 900)) +# define LZO_COMPILE_TIME_ASSERT(e) switch(0) case 1:case !(e):break; +# elif (LZO_CC_TURBOC && (__TURBOC__ == 0x0295)) +# define LZO_COMPILE_TIME_ASSERT(e) switch(0) case 1:case !(e):break; +# else +# define LZO_COMPILE_TIME_ASSERT(e) {typedef int __lzo_cta_t[1-2*!(e)];} +# endif +#endif +#if (LZO_ARCH_I086 || LZO_ARCH_I386) && (LZO_OS_DOS16 || LZO_OS_DOS32 || LZO_OS_OS2 || LZO_OS_OS216 || LZO_OS_WIN16 || LZO_OS_WIN32 || LZO_OS_WIN64) +# if (LZO_CC_GNUC || LZO_CC_HIGHC || LZO_CC_NDPC || LZO_CC_PACIFICC) +# elif (LZO_CC_DMC || LZO_CC_SYMANTECC || LZO_CC_ZORTECHC) +# define __lzo_cdecl __cdecl +# define __lzo_cdecl_atexit /*empty*/ +# define __lzo_cdecl_main __cdecl +# if (LZO_OS_OS2 && (LZO_CC_DMC || LZO_CC_SYMANTECC)) +# define __lzo_cdecl_qsort __pascal +# elif (LZO_OS_OS2 && (LZO_CC_ZORTECHC)) +# define __lzo_cdecl_qsort _stdcall +# else +# define __lzo_cdecl_qsort __cdecl +# endif +# elif (LZO_CC_WATCOMC) +# define __lzo_cdecl __cdecl +# else +# define __lzo_cdecl __cdecl +# define __lzo_cdecl_atexit __cdecl +# define __lzo_cdecl_main __cdecl +# define __lzo_cdecl_qsort __cdecl +# endif +# if (LZO_CC_GNUC || LZO_CC_HIGHC || LZO_CC_NDPC || LZO_CC_PACIFICC || LZO_CC_WATCOMC) +# elif (LZO_OS_OS2 && (LZO_CC_DMC || LZO_CC_SYMANTECC)) +# define __lzo_cdecl_sighandler __pascal +# elif (LZO_OS_OS2 && (LZO_CC_ZORTECHC)) +# define __lzo_cdecl_sighandler _stdcall +# elif (LZO_CC_MSC && (_MSC_VER >= 1400)) && defined(_M_CEE_PURE) +# define __lzo_cdecl_sighandler __clrcall +# elif (LZO_CC_MSC && (_MSC_VER >= 600 && _MSC_VER < 700)) +# if defined(_DLL) +# define __lzo_cdecl_sighandler _far _cdecl _loadds +# elif defined(_MT) +# define __lzo_cdecl_sighandler _far _cdecl +# else +# define __lzo_cdecl_sighandler _cdecl +# endif +# else +# define __lzo_cdecl_sighandler __cdecl +# endif +#elif (LZO_ARCH_I386) && (LZO_CC_WATCOMC) +# define __lzo_cdecl __cdecl +#elif (LZO_ARCH_M68K && LZO_OS_TOS && (LZO_CC_PUREC || LZO_CC_TURBOC)) +# define __lzo_cdecl cdecl +#endif +#if !defined(__lzo_cdecl) +# define __lzo_cdecl /*empty*/ +#endif +#if !defined(__lzo_cdecl_atexit) +# define __lzo_cdecl_atexit /*empty*/ +#endif +#if !defined(__lzo_cdecl_main) +# define __lzo_cdecl_main /*empty*/ +#endif +#if !defined(__lzo_cdecl_qsort) +# define __lzo_cdecl_qsort /*empty*/ +#endif +#if !defined(__lzo_cdecl_sighandler) +# define __lzo_cdecl_sighandler /*empty*/ +#endif +#if !defined(__lzo_cdecl_va) +# define __lzo_cdecl_va __lzo_cdecl +#endif +#if !(LZO_CFG_NO_WINDOWS_H) +#if (LZO_OS_CYGWIN || (LZO_OS_EMX && defined(__RSXNT__)) || LZO_OS_WIN32 || LZO_OS_WIN64) +# if (LZO_CC_WATCOMC && (__WATCOMC__ < 1000)) +# elif (LZO_OS_WIN32 && LZO_CC_GNUC) && defined(__PW32__) +# elif ((LZO_OS_CYGWIN || defined(__MINGW32__)) && (LZO_CC_GNUC && (LZO_CC_GNUC < 0x025f00ul))) +# else +# define LZO_HAVE_WINDOWS_H 1 +# endif +#endif +#endif +#if (LZO_ARCH_ALPHA) +# define LZO_OPT_AVOID_UINT_INDEX 1 +# define LZO_OPT_AVOID_SHORT 1 +# define LZO_OPT_AVOID_USHORT 1 +#elif (LZO_ARCH_AMD64) +# define LZO_OPT_AVOID_INT_INDEX 1 +# define LZO_OPT_AVOID_UINT_INDEX 1 +# define LZO_OPT_UNALIGNED16 1 +# define LZO_OPT_UNALIGNED32 1 +# define LZO_OPT_UNALIGNED64 1 +#elif (LZO_ARCH_ARM && LZO_ARCH_ARM_THUMB) +#elif (LZO_ARCH_ARM) +# define LZO_OPT_AVOID_SHORT 1 +# define LZO_OPT_AVOID_USHORT 1 +#elif (LZO_ARCH_CRIS) +# define LZO_OPT_UNALIGNED16 1 +# define LZO_OPT_UNALIGNED32 1 +#elif (LZO_ARCH_I386) +# define LZO_OPT_UNALIGNED16 1 +# define LZO_OPT_UNALIGNED32 1 +#elif (LZO_ARCH_IA64) +# define LZO_OPT_AVOID_INT_INDEX 1 +# define LZO_OPT_AVOID_UINT_INDEX 1 +# define LZO_OPT_PREFER_POSTINC 1 +#elif (LZO_ARCH_M68K) +# define LZO_OPT_PREFER_POSTINC 1 +# define LZO_OPT_PREFER_PREDEC 1 +# if defined(__mc68020__) && !defined(__mcoldfire__) +# define LZO_OPT_UNALIGNED16 1 +# define LZO_OPT_UNALIGNED32 1 +# endif +#elif (LZO_ARCH_MIPS) +# define LZO_OPT_AVOID_UINT_INDEX 1 +#elif (LZO_ARCH_POWERPC) +# define LZO_OPT_PREFER_PREINC 1 +# define LZO_OPT_PREFER_PREDEC 1 +# if (LZO_ABI_BIG_ENDIAN) +# define LZO_OPT_UNALIGNED16 1 +# define LZO_OPT_UNALIGNED32 1 +# endif +#elif (LZO_ARCH_S390) +# define LZO_OPT_UNALIGNED16 1 +# define LZO_OPT_UNALIGNED32 1 +# if (LZO_SIZEOF_SIZE_T == 8) +# define LZO_OPT_UNALIGNED64 1 +# endif +#elif (LZO_ARCH_SH) +# define LZO_OPT_PREFER_POSTINC 1 +# define LZO_OPT_PREFER_PREDEC 1 +#endif +#ifndef LZO_CFG_NO_INLINE_ASM +#if (LZO_CC_LLVM) +# define LZO_CFG_NO_INLINE_ASM 1 +#endif +#endif +#ifndef LZO_CFG_NO_UNALIGNED +#if (LZO_ABI_NEUTRAL_ENDIAN) || (LZO_ARCH_GENERIC) +# define LZO_CFG_NO_UNALIGNED 1 +#endif +#endif +#if (LZO_CFG_NO_UNALIGNED) +# undef LZO_OPT_UNALIGNED16 +# undef LZO_OPT_UNALIGNED32 +# undef LZO_OPT_UNALIGNED64 +#endif +#if (LZO_CFG_NO_INLINE_ASM) +#elif (LZO_ARCH_I386 && (LZO_OS_DOS32 || LZO_OS_WIN32) && (LZO_CC_DMC || LZO_CC_INTELC || LZO_CC_MSC || LZO_CC_PELLESC)) +# define LZO_ASM_SYNTAX_MSC 1 +#elif (LZO_OS_WIN64 && (LZO_CC_DMC || LZO_CC_INTELC || LZO_CC_MSC || LZO_CC_PELLESC)) +#elif (LZO_ARCH_I386 && LZO_CC_GNUC && (LZO_CC_GNUC == 0x011f00ul)) +#elif (LZO_ARCH_I386 && (LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_INTELC || LZO_CC_PATHSCALE)) +# define LZO_ASM_SYNTAX_GNUC 1 +#elif (LZO_ARCH_AMD64 && (LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_INTELC || LZO_CC_PATHSCALE)) +# define LZO_ASM_SYNTAX_GNUC 1 +#endif +#if (LZO_ASM_SYNTAX_GNUC) +#if (LZO_ARCH_I386 && LZO_CC_GNUC && (LZO_CC_GNUC < 0x020000ul)) +# define __LZO_ASM_CLOBBER "ax" +#elif (LZO_CC_INTELC) +# define __LZO_ASM_CLOBBER "memory" +#else +# define __LZO_ASM_CLOBBER "cc", "memory" +#endif +#endif +#if defined(__LZO_INFOSTR_MM) +#elif (LZO_MM_FLAT) && (defined(__LZO_INFOSTR_PM) || defined(LZO_INFO_ABI_PM)) +# define __LZO_INFOSTR_MM "" +#elif defined(LZO_INFO_MM) +# define __LZO_INFOSTR_MM "." LZO_INFO_MM +#else +# define __LZO_INFOSTR_MM "" +#endif +#if defined(__LZO_INFOSTR_PM) +#elif defined(LZO_INFO_ABI_PM) +# define __LZO_INFOSTR_PM "." LZO_INFO_ABI_PM +#else +# define __LZO_INFOSTR_PM "" +#endif +#if defined(__LZO_INFOSTR_ENDIAN) +#elif defined(LZO_INFO_ABI_ENDIAN) +# define __LZO_INFOSTR_ENDIAN "." LZO_INFO_ABI_ENDIAN +#else +# define __LZO_INFOSTR_ENDIAN "" +#endif +#if defined(__LZO_INFOSTR_OSNAME) +#elif defined(LZO_INFO_OS_CONSOLE) +# define __LZO_INFOSTR_OSNAME LZO_INFO_OS "." LZO_INFO_OS_CONSOLE +#elif defined(LZO_INFO_OS_POSIX) +# define __LZO_INFOSTR_OSNAME LZO_INFO_OS "." LZO_INFO_OS_POSIX +#else +# define __LZO_INFOSTR_OSNAME LZO_INFO_OS +#endif +#if defined(__LZO_INFOSTR_LIBC) +#elif defined(LZO_INFO_LIBC) +# define __LZO_INFOSTR_LIBC "." LZO_INFO_LIBC +#else +# define __LZO_INFOSTR_LIBC "" +#endif +#if defined(__LZO_INFOSTR_CCVER) +#elif defined(LZO_INFO_CCVER) +# define __LZO_INFOSTR_CCVER " " LZO_INFO_CCVER +#else +# define __LZO_INFOSTR_CCVER "" +#endif +#define LZO_INFO_STRING \ + LZO_INFO_ARCH __LZO_INFOSTR_MM __LZO_INFOSTR_PM __LZO_INFOSTR_ENDIAN \ + " " __LZO_INFOSTR_OSNAME __LZO_INFOSTR_LIBC " " LZO_INFO_CC __LZO_INFOSTR_CCVER + +#endif /* already included */ + +/* vim:set ts=4 et: */ diff --git a/grub-core/lib/minilzo/minilzo.c b/grub-core/lib/minilzo/minilzo.c new file mode 100644 index 000000000..25a1f68b3 --- /dev/null +++ b/grub-core/lib/minilzo/minilzo.c @@ -0,0 +1,4562 @@ +/* minilzo.c -- mini subset of the LZO real-time data compression library + + This file is part of the LZO real-time data compression library. + + Copyright (C) 2011 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2010 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2009 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2008 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2007 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2006 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2005 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2004 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2003 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2002 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2001 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2000 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 1999 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 1998 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 1997 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 1996 Markus Franz Xaver Johannes Oberhumer + All Rights Reserved. + + The LZO library 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 2 of + the License, or (at your option) any later version. + + The LZO library 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 the LZO library; see the file COPYING. + If not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + Markus F.X.J. Oberhumer + + http://www.oberhumer.com/opensource/lzo/ + */ + +/* + * NOTE: + * the full LZO package can be found at + * http://www.oberhumer.com/opensource/lzo/ + */ + +#define __LZO_IN_MINILZO 1 + +#if defined(LZO_CFG_FREESTANDING) +# undef MINILZO_HAVE_CONFIG_H +# define LZO_LIBC_FREESTANDING 1 +# define LZO_OS_FREESTANDING 1 +#endif + +#ifdef MINILZO_HAVE_CONFIG_H +# include +#endif +#include +#include +#if defined(MINILZO_CFG_USE_INTERNAL_LZODEFS) + +#ifndef __LZODEFS_H_INCLUDED +#define __LZODEFS_H_INCLUDED 1 + +#if defined(__CYGWIN32__) && !defined(__CYGWIN__) +# define __CYGWIN__ __CYGWIN32__ +#endif +#if defined(__IBMCPP__) && !defined(__IBMC__) +# define __IBMC__ __IBMCPP__ +#endif +#if defined(__ICL) && defined(_WIN32) && !defined(__INTEL_COMPILER) +# define __INTEL_COMPILER __ICL +#endif +#if 1 && defined(__INTERIX) && defined(__GNUC__) && !defined(_ALL_SOURCE) +# define _ALL_SOURCE 1 +#endif +#if defined(__mips__) && defined(__R5900__) +# if !defined(__LONG_MAX__) +# define __LONG_MAX__ 9223372036854775807L +# endif +#endif +#if defined(__INTEL_COMPILER) && defined(__linux__) +# pragma warning(disable: 193) +#endif +#if defined(__KEIL__) && defined(__C166__) +# pragma warning disable = 322 +#elif 0 && defined(__C251__) +# pragma warning disable = 322 +#endif +#if defined(_MSC_VER) && !defined(__INTEL_COMPILER) && !defined(__MWERKS__) +# if (_MSC_VER >= 1300) +# pragma warning(disable: 4668) +# endif +#endif +#if 0 && defined(__WATCOMC__) +# if (__WATCOMC__ >= 1050) && (__WATCOMC__ < 1060) +# pragma warning 203 9 +# endif +#endif +#if defined(__BORLANDC__) && defined(__MSDOS__) && !defined(__FLAT__) +# pragma option -h +#endif +#if 0 +#define LZO_0xffffL 0xfffful +#define LZO_0xffffffffL 0xfffffffful +#else +#define LZO_0xffffL 65535ul +#define LZO_0xffffffffL 4294967295ul +#endif +#if (LZO_0xffffL == LZO_0xffffffffL) +# error "your preprocessor is broken 1" +#endif +#if (16ul * 16384ul != 262144ul) +# error "your preprocessor is broken 2" +#endif +#if 0 +#if (32767 >= 4294967295ul) +# error "your preprocessor is broken 3" +#endif +#if (65535u >= 4294967295ul) +# error "your preprocessor is broken 4" +#endif +#endif +#if (UINT_MAX == LZO_0xffffL) +#if defined(__ZTC__) && defined(__I86__) && !defined(__OS2__) +# if !defined(MSDOS) +# define MSDOS 1 +# endif +# if !defined(_MSDOS) +# define _MSDOS 1 +# endif +#elif 0 && defined(__VERSION) && defined(MB_LEN_MAX) +# if (__VERSION == 520) && (MB_LEN_MAX == 1) +# if !defined(__AZTEC_C__) +# define __AZTEC_C__ __VERSION +# endif +# if !defined(__DOS__) +# define __DOS__ 1 +# endif +# endif +#endif +#endif +#if defined(_MSC_VER) && defined(M_I86HM) && (UINT_MAX == LZO_0xffffL) +# define ptrdiff_t long +# define _PTRDIFF_T_DEFINED 1 +#endif +#if (UINT_MAX == LZO_0xffffL) +# undef __LZO_RENAME_A +# undef __LZO_RENAME_B +# if defined(__AZTEC_C__) && defined(__DOS__) +# define __LZO_RENAME_A 1 +# elif defined(_MSC_VER) && defined(MSDOS) +# if (_MSC_VER < 600) +# define __LZO_RENAME_A 1 +# elif (_MSC_VER < 700) +# define __LZO_RENAME_B 1 +# endif +# elif defined(__TSC__) && defined(__OS2__) +# define __LZO_RENAME_A 1 +# elif defined(__MSDOS__) && defined(__TURBOC__) && (__TURBOC__ < 0x0410) +# define __LZO_RENAME_A 1 +# elif defined(__PACIFIC__) && defined(DOS) +# if !defined(__far) +# define __far far +# endif +# if !defined(__near) +# define __near near +# endif +# endif +# if defined(__LZO_RENAME_A) +# if !defined(__cdecl) +# define __cdecl cdecl +# endif +# if !defined(__far) +# define __far far +# endif +# if !defined(__huge) +# define __huge huge +# endif +# if !defined(__near) +# define __near near +# endif +# if !defined(__pascal) +# define __pascal pascal +# endif +# if !defined(__huge) +# define __huge huge +# endif +# elif defined(__LZO_RENAME_B) +# if !defined(__cdecl) +# define __cdecl _cdecl +# endif +# if !defined(__far) +# define __far _far +# endif +# if !defined(__huge) +# define __huge _huge +# endif +# if !defined(__near) +# define __near _near +# endif +# if !defined(__pascal) +# define __pascal _pascal +# endif +# elif (defined(__PUREC__) || defined(__TURBOC__)) && defined(__TOS__) +# if !defined(__cdecl) +# define __cdecl cdecl +# endif +# if !defined(__pascal) +# define __pascal pascal +# endif +# endif +# undef __LZO_RENAME_A +# undef __LZO_RENAME_B +#endif +#if (UINT_MAX == LZO_0xffffL) +#if defined(__AZTEC_C__) && defined(__DOS__) +# define LZO_BROKEN_CDECL_ALT_SYNTAX 1 +#elif defined(_MSC_VER) && defined(MSDOS) +# if (_MSC_VER < 600) +# define LZO_BROKEN_INTEGRAL_CONSTANTS 1 +# endif +# if (_MSC_VER < 700) +# define LZO_BROKEN_INTEGRAL_PROMOTION 1 +# define LZO_BROKEN_SIZEOF 1 +# endif +#elif defined(__PACIFIC__) && defined(DOS) +# define LZO_BROKEN_INTEGRAL_CONSTANTS 1 +#elif defined(__TURBOC__) && defined(__MSDOS__) +# if (__TURBOC__ < 0x0150) +# define LZO_BROKEN_CDECL_ALT_SYNTAX 1 +# define LZO_BROKEN_INTEGRAL_CONSTANTS 1 +# define LZO_BROKEN_INTEGRAL_PROMOTION 1 +# endif +# if (__TURBOC__ < 0x0200) +# define LZO_BROKEN_SIZEOF 1 +# endif +# if (__TURBOC__ < 0x0400) && defined(__cplusplus) +# define LZO_BROKEN_CDECL_ALT_SYNTAX 1 +# endif +#elif (defined(__PUREC__) || defined(__TURBOC__)) && defined(__TOS__) +# define LZO_BROKEN_CDECL_ALT_SYNTAX 1 +# define LZO_BROKEN_SIZEOF 1 +#endif +#endif +#if defined(__WATCOMC__) && (__WATCOMC__ < 900) +# define LZO_BROKEN_INTEGRAL_CONSTANTS 1 +#endif +#if defined(_CRAY) && defined(_CRAY1) +# define LZO_BROKEN_SIGNED_RIGHT_SHIFT 1 +#endif +#define LZO_PP_STRINGIZE(x) #x +#define LZO_PP_MACRO_EXPAND(x) LZO_PP_STRINGIZE(x) +#define LZO_PP_CONCAT2(a,b) a ## b +#define LZO_PP_CONCAT3(a,b,c) a ## b ## c +#define LZO_PP_CONCAT4(a,b,c,d) a ## b ## c ## d +#define LZO_PP_CONCAT5(a,b,c,d,e) a ## b ## c ## d ## e +#define LZO_PP_ECONCAT2(a,b) LZO_PP_CONCAT2(a,b) +#define LZO_PP_ECONCAT3(a,b,c) LZO_PP_CONCAT3(a,b,c) +#define LZO_PP_ECONCAT4(a,b,c,d) LZO_PP_CONCAT4(a,b,c,d) +#define LZO_PP_ECONCAT5(a,b,c,d,e) LZO_PP_CONCAT5(a,b,c,d,e) +#if 1 +#define LZO_CPP_STRINGIZE(x) #x +#define LZO_CPP_MACRO_EXPAND(x) LZO_CPP_STRINGIZE(x) +#define LZO_CPP_CONCAT2(a,b) a ## b +#define LZO_CPP_CONCAT3(a,b,c) a ## b ## c +#define LZO_CPP_CONCAT4(a,b,c,d) a ## b ## c ## d +#define LZO_CPP_CONCAT5(a,b,c,d,e) a ## b ## c ## d ## e +#define LZO_CPP_ECONCAT2(a,b) LZO_CPP_CONCAT2(a,b) +#define LZO_CPP_ECONCAT3(a,b,c) LZO_CPP_CONCAT3(a,b,c) +#define LZO_CPP_ECONCAT4(a,b,c,d) LZO_CPP_CONCAT4(a,b,c,d) +#define LZO_CPP_ECONCAT5(a,b,c,d,e) LZO_CPP_CONCAT5(a,b,c,d,e) +#endif +#define __LZO_MASK_GEN(o,b) (((((o) << ((b)-1)) - (o)) << 1) + (o)) +#if 1 && defined(__cplusplus) +# if !defined(__STDC_CONSTANT_MACROS) +# define __STDC_CONSTANT_MACROS 1 +# endif +# if !defined(__STDC_LIMIT_MACROS) +# define __STDC_LIMIT_MACROS 1 +# endif +#endif +#if defined(__cplusplus) +# define LZO_EXTERN_C extern "C" +#else +# define LZO_EXTERN_C extern +#endif +#if !defined(__LZO_OS_OVERRIDE) +#if (LZO_OS_FREESTANDING) +# define LZO_INFO_OS "freestanding" +#elif (LZO_OS_EMBEDDED) +# define LZO_INFO_OS "embedded" +#elif 1 && defined(__IAR_SYSTEMS_ICC__) +# define LZO_OS_EMBEDDED 1 +# define LZO_INFO_OS "embedded" +#elif defined(__CYGWIN__) && defined(__GNUC__) +# define LZO_OS_CYGWIN 1 +# define LZO_INFO_OS "cygwin" +#elif defined(__EMX__) && defined(__GNUC__) +# define LZO_OS_EMX 1 +# define LZO_INFO_OS "emx" +#elif defined(__BEOS__) +# define LZO_OS_BEOS 1 +# define LZO_INFO_OS "beos" +#elif defined(__Lynx__) +# define LZO_OS_LYNXOS 1 +# define LZO_INFO_OS "lynxos" +#elif defined(__OS400__) +# define LZO_OS_OS400 1 +# define LZO_INFO_OS "os400" +#elif defined(__QNX__) +# define LZO_OS_QNX 1 +# define LZO_INFO_OS "qnx" +#elif defined(__BORLANDC__) && defined(__DPMI32__) && (__BORLANDC__ >= 0x0460) +# define LZO_OS_DOS32 1 +# define LZO_INFO_OS "dos32" +#elif defined(__BORLANDC__) && defined(__DPMI16__) +# define LZO_OS_DOS16 1 +# define LZO_INFO_OS "dos16" +#elif defined(__ZTC__) && defined(DOS386) +# define LZO_OS_DOS32 1 +# define LZO_INFO_OS "dos32" +#elif defined(__OS2__) || defined(__OS2V2__) +# if (UINT_MAX == LZO_0xffffL) +# define LZO_OS_OS216 1 +# define LZO_INFO_OS "os216" +# elif (UINT_MAX == LZO_0xffffffffL) +# define LZO_OS_OS2 1 +# define LZO_INFO_OS "os2" +# else +# error "check your limits.h header" +# endif +#elif defined(__WIN64__) || defined(_WIN64) || defined(WIN64) +# define LZO_OS_WIN64 1 +# define LZO_INFO_OS "win64" +#elif defined(__WIN32__) || defined(_WIN32) || defined(WIN32) || defined(__WINDOWS_386__) +# define LZO_OS_WIN32 1 +# define LZO_INFO_OS "win32" +#elif defined(__MWERKS__) && defined(__INTEL__) +# define LZO_OS_WIN32 1 +# define LZO_INFO_OS "win32" +#elif defined(__WINDOWS__) || defined(_WINDOWS) || defined(_Windows) +# if (UINT_MAX == LZO_0xffffL) +# define LZO_OS_WIN16 1 +# define LZO_INFO_OS "win16" +# elif (UINT_MAX == LZO_0xffffffffL) +# define LZO_OS_WIN32 1 +# define LZO_INFO_OS "win32" +# else +# error "check your limits.h header" +# endif +#elif defined(__DOS__) || defined(__MSDOS__) || defined(_MSDOS) || defined(MSDOS) || (defined(__PACIFIC__) && defined(DOS)) +# if (UINT_MAX == LZO_0xffffL) +# define LZO_OS_DOS16 1 +# define LZO_INFO_OS "dos16" +# elif (UINT_MAX == LZO_0xffffffffL) +# define LZO_OS_DOS32 1 +# define LZO_INFO_OS "dos32" +# else +# error "check your limits.h header" +# endif +#elif defined(__WATCOMC__) +# if defined(__NT__) && (UINT_MAX == LZO_0xffffL) +# define LZO_OS_DOS16 1 +# define LZO_INFO_OS "dos16" +# elif defined(__NT__) && (__WATCOMC__ < 1100) +# define LZO_OS_WIN32 1 +# define LZO_INFO_OS "win32" +# elif defined(__linux__) || defined(__LINUX__) +# define LZO_OS_POSIX 1 +# define LZO_INFO_OS "posix" +# else +# error "please specify a target using the -bt compiler option" +# endif +#elif defined(__palmos__) +# define LZO_OS_PALMOS 1 +# define LZO_INFO_OS "palmos" +#elif defined(__TOS__) || defined(__atarist__) +# define LZO_OS_TOS 1 +# define LZO_INFO_OS "tos" +#elif defined(macintosh) && !defined(__ppc__) +# define LZO_OS_MACCLASSIC 1 +# define LZO_INFO_OS "macclassic" +#elif defined(__VMS) +# define LZO_OS_VMS 1 +# define LZO_INFO_OS "vms" +#elif ((defined(__mips__) && defined(__R5900__)) || defined(__MIPS_PSX2__)) +# define LZO_OS_CONSOLE 1 +# define LZO_OS_CONSOLE_PS2 1 +# define LZO_INFO_OS "console" +# define LZO_INFO_OS_CONSOLE "ps2" +#elif (defined(__mips__) && defined(__psp__)) +# define LZO_OS_CONSOLE 1 +# define LZO_OS_CONSOLE_PSP 1 +# define LZO_INFO_OS "console" +# define LZO_INFO_OS_CONSOLE "psp" +#else +# define LZO_OS_POSIX 1 +# define LZO_INFO_OS "posix" +#endif +#if (LZO_OS_POSIX) +# if defined(_AIX) || defined(__AIX__) || defined(__aix__) +# define LZO_OS_POSIX_AIX 1 +# define LZO_INFO_OS_POSIX "aix" +# elif defined(__FreeBSD__) +# define LZO_OS_POSIX_FREEBSD 1 +# define LZO_INFO_OS_POSIX "freebsd" +# elif defined(__hpux__) || defined(__hpux) +# define LZO_OS_POSIX_HPUX 1 +# define LZO_INFO_OS_POSIX "hpux" +# elif defined(__INTERIX) +# define LZO_OS_POSIX_INTERIX 1 +# define LZO_INFO_OS_POSIX "interix" +# elif defined(__IRIX__) || defined(__irix__) +# define LZO_OS_POSIX_IRIX 1 +# define LZO_INFO_OS_POSIX "irix" +# elif defined(__linux__) || defined(__linux) || defined(__LINUX__) +# define LZO_OS_POSIX_LINUX 1 +# define LZO_INFO_OS_POSIX "linux" +# elif defined(__APPLE__) || defined(__MACOS__) +# define LZO_OS_POSIX_MACOSX 1 +# define LZO_INFO_OS_POSIX "macosx" +# elif defined(__minix__) || defined(__minix) +# define LZO_OS_POSIX_MINIX 1 +# define LZO_INFO_OS_POSIX "minix" +# elif defined(__NetBSD__) +# define LZO_OS_POSIX_NETBSD 1 +# define LZO_INFO_OS_POSIX "netbsd" +# elif defined(__OpenBSD__) +# define LZO_OS_POSIX_OPENBSD 1 +# define LZO_INFO_OS_POSIX "openbsd" +# elif defined(__osf__) +# define LZO_OS_POSIX_OSF 1 +# define LZO_INFO_OS_POSIX "osf" +# elif defined(__solaris__) || defined(__sun) +# if defined(__SVR4) || defined(__svr4__) +# define LZO_OS_POSIX_SOLARIS 1 +# define LZO_INFO_OS_POSIX "solaris" +# else +# define LZO_OS_POSIX_SUNOS 1 +# define LZO_INFO_OS_POSIX "sunos" +# endif +# elif defined(__ultrix__) || defined(__ultrix) +# define LZO_OS_POSIX_ULTRIX 1 +# define LZO_INFO_OS_POSIX "ultrix" +# elif defined(_UNICOS) +# define LZO_OS_POSIX_UNICOS 1 +# define LZO_INFO_OS_POSIX "unicos" +# else +# define LZO_OS_POSIX_UNKNOWN 1 +# define LZO_INFO_OS_POSIX "unknown" +# endif +#endif +#endif +#if (LZO_OS_DOS16 || LZO_OS_OS216 || LZO_OS_WIN16) +# if (UINT_MAX != LZO_0xffffL) +# error "this should not happen" +# endif +# if (ULONG_MAX != LZO_0xffffffffL) +# error "this should not happen" +# endif +#endif +#if (LZO_OS_DOS32 || LZO_OS_OS2 || LZO_OS_WIN32 || LZO_OS_WIN64) +# if (UINT_MAX != LZO_0xffffffffL) +# error "this should not happen" +# endif +# if (ULONG_MAX != LZO_0xffffffffL) +# error "this should not happen" +# endif +#endif +#if defined(CIL) && defined(_GNUCC) && defined(__GNUC__) +# define LZO_CC_CILLY 1 +# define LZO_INFO_CC "Cilly" +# if defined(__CILLY__) +# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__CILLY__) +# else +# define LZO_INFO_CCVER "unknown" +# endif +#elif 0 && defined(SDCC) && defined(__VERSION__) && !defined(__GNUC__) +# define LZO_CC_SDCC 1 +# define LZO_INFO_CC "sdcc" +# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(SDCC) +#elif defined(__PATHSCALE__) && defined(__PATHCC_PATCHLEVEL__) +# define LZO_CC_PATHSCALE (__PATHCC__ * 0x10000L + __PATHCC_MINOR__ * 0x100 + __PATHCC_PATCHLEVEL__) +# define LZO_INFO_CC "Pathscale C" +# define LZO_INFO_CCVER __PATHSCALE__ +#elif defined(__INTEL_COMPILER) +# define LZO_CC_INTELC 1 +# define LZO_INFO_CC "Intel C" +# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__INTEL_COMPILER) +# if defined(_WIN32) || defined(_WIN64) +# define LZO_CC_SYNTAX_MSC 1 +# else +# define LZO_CC_SYNTAX_GNUC 1 +# endif +#elif defined(__POCC__) && defined(_WIN32) +# define LZO_CC_PELLESC 1 +# define LZO_INFO_CC "Pelles C" +# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__POCC__) +#elif defined(__clang__) && defined(__llvm__) && defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__VERSION__) +# if defined(__GNUC_PATCHLEVEL__) +# define LZO_CC_CLANG_GNUC (__GNUC__ * 0x10000L + __GNUC_MINOR__ * 0x100 + __GNUC_PATCHLEVEL__) +# else +# define LZO_CC_CLANG_GNUC (__GNUC__ * 0x10000L + __GNUC_MINOR__ * 0x100) +# endif +# if defined(__clang_major__) && defined(__clang_minor__) && defined(__clang_patchlevel__) +# define LZO_CC_CLANG_CLANG (__clang_major__ * 0x10000L + __clang_minor__ * 0x100 + __clang_patchlevel__) +# else +# define LZO_CC_CLANG_CLANG 0x010000L +# endif +# define LZO_CC_CLANG LZO_CC_CLANG_GNUC +# define LZO_INFO_CC "clang" +# define LZO_INFO_CCVER __VERSION__ +#elif defined(__llvm__) && defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__VERSION__) +# if defined(__GNUC_PATCHLEVEL__) +# define LZO_CC_LLVM_GNUC (__GNUC__ * 0x10000L + __GNUC_MINOR__ * 0x100 + __GNUC_PATCHLEVEL__) +# else +# define LZO_CC_LLVM_GNUC (__GNUC__ * 0x10000L + __GNUC_MINOR__ * 0x100) +# endif +# define LZO_CC_LLVM LZO_CC_LLVM_GNUC +# define LZO_INFO_CC "llvm-gcc" +# define LZO_INFO_CCVER __VERSION__ +#elif defined(__GNUC__) && defined(__VERSION__) +# if defined(__GNUC_MINOR__) && defined(__GNUC_PATCHLEVEL__) +# define LZO_CC_GNUC (__GNUC__ * 0x10000L + __GNUC_MINOR__ * 0x100 + __GNUC_PATCHLEVEL__) +# elif defined(__GNUC_MINOR__) +# define LZO_CC_GNUC (__GNUC__ * 0x10000L + __GNUC_MINOR__ * 0x100) +# else +# define LZO_CC_GNUC (__GNUC__ * 0x10000L) +# endif +# define LZO_INFO_CC "gcc" +# define LZO_INFO_CCVER __VERSION__ +#elif defined(__ACK__) && defined(_ACK) +# define LZO_CC_ACK 1 +# define LZO_INFO_CC "Amsterdam Compiler Kit C" +# define LZO_INFO_CCVER "unknown" +#elif defined(__AZTEC_C__) +# define LZO_CC_AZTECC 1 +# define LZO_INFO_CC "Aztec C" +# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__AZTEC_C__) +#elif defined(__CODEGEARC__) +# define LZO_CC_CODEGEARC 1 +# define LZO_INFO_CC "CodeGear C" +# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__CODEGEARC__) +#elif defined(__BORLANDC__) +# define LZO_CC_BORLANDC 1 +# define LZO_INFO_CC "Borland C" +# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__BORLANDC__) +#elif defined(_CRAYC) && defined(_RELEASE) +# define LZO_CC_CRAYC 1 +# define LZO_INFO_CC "Cray C" +# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(_RELEASE) +#elif defined(__DMC__) && defined(__SC__) +# define LZO_CC_DMC 1 +# define LZO_INFO_CC "Digital Mars C" +# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__DMC__) +#elif defined(__DECC) +# define LZO_CC_DECC 1 +# define LZO_INFO_CC "DEC C" +# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__DECC) +#elif defined(__HIGHC__) +# define LZO_CC_HIGHC 1 +# define LZO_INFO_CC "MetaWare High C" +# define LZO_INFO_CCVER "unknown" +#elif defined(__IAR_SYSTEMS_ICC__) +# define LZO_CC_IARC 1 +# define LZO_INFO_CC "IAR C" +# if defined(__VER__) +# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__VER__) +# else +# define LZO_INFO_CCVER "unknown" +# endif +#elif defined(__IBMC__) +# define LZO_CC_IBMC 1 +# define LZO_INFO_CC "IBM C" +# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__IBMC__) +#elif defined(__KEIL__) && defined(__C166__) +# define LZO_CC_KEILC 1 +# define LZO_INFO_CC "Keil C" +# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__C166__) +#elif defined(__LCC__) && defined(_WIN32) && defined(__LCCOPTIMLEVEL) +# define LZO_CC_LCCWIN32 1 +# define LZO_INFO_CC "lcc-win32" +# define LZO_INFO_CCVER "unknown" +#elif defined(__LCC__) +# define LZO_CC_LCC 1 +# define LZO_INFO_CC "lcc" +# if defined(__LCC_VERSION__) +# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__LCC_VERSION__) +# else +# define LZO_INFO_CCVER "unknown" +# endif +#elif defined(_MSC_VER) +# define LZO_CC_MSC 1 +# define LZO_INFO_CC "Microsoft C" +# if defined(_MSC_FULL_VER) +# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(_MSC_VER) "." LZO_PP_MACRO_EXPAND(_MSC_FULL_VER) +# else +# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(_MSC_VER) +# endif +#elif defined(__MWERKS__) +# define LZO_CC_MWERKS 1 +# define LZO_INFO_CC "Metrowerks C" +# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__MWERKS__) +#elif (defined(__NDPC__) || defined(__NDPX__)) && defined(__i386) +# define LZO_CC_NDPC 1 +# define LZO_INFO_CC "Microway NDP C" +# define LZO_INFO_CCVER "unknown" +#elif defined(__PACIFIC__) +# define LZO_CC_PACIFICC 1 +# define LZO_INFO_CC "Pacific C" +# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__PACIFIC__) +#elif defined(__PGI) && (defined(__linux__) || defined(__WIN32__)) +# define LZO_CC_PGI 1 +# define LZO_INFO_CC "Portland Group PGI C" +# define LZO_INFO_CCVER "unknown" +#elif defined(__PUREC__) && defined(__TOS__) +# define LZO_CC_PUREC 1 +# define LZO_INFO_CC "Pure C" +# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__PUREC__) +#elif defined(__SC__) && defined(__ZTC__) +# define LZO_CC_SYMANTECC 1 +# define LZO_INFO_CC "Symantec C" +# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__SC__) +#elif defined(__SUNPRO_C) +# define LZO_INFO_CC "SunPro C" +# if ((__SUNPRO_C)+0 > 0) +# define LZO_CC_SUNPROC __SUNPRO_C +# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__SUNPRO_C) +# else +# define LZO_CC_SUNPROC 1 +# define LZO_INFO_CCVER "unknown" +# endif +#elif defined(__SUNPRO_CC) +# define LZO_INFO_CC "SunPro C" +# if ((__SUNPRO_CC)+0 > 0) +# define LZO_CC_SUNPROC __SUNPRO_CC +# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__SUNPRO_CC) +# else +# define LZO_CC_SUNPROC 1 +# define LZO_INFO_CCVER "unknown" +# endif +#elif defined(__TINYC__) +# define LZO_CC_TINYC 1 +# define LZO_INFO_CC "Tiny C" +# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__TINYC__) +#elif defined(__TSC__) +# define LZO_CC_TOPSPEEDC 1 +# define LZO_INFO_CC "TopSpeed C" +# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__TSC__) +#elif defined(__WATCOMC__) +# define LZO_CC_WATCOMC 1 +# define LZO_INFO_CC "Watcom C" +# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__WATCOMC__) +#elif defined(__TURBOC__) +# define LZO_CC_TURBOC 1 +# define LZO_INFO_CC "Turbo C" +# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__TURBOC__) +#elif defined(__ZTC__) +# define LZO_CC_ZORTECHC 1 +# define LZO_INFO_CC "Zortech C" +# if (__ZTC__ == 0x310) +# define LZO_INFO_CCVER "0x310" +# else +# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__ZTC__) +# endif +#else +# define LZO_CC_UNKNOWN 1 +# define LZO_INFO_CC "unknown" +# define LZO_INFO_CCVER "unknown" +#endif +#if 0 && (LZO_CC_MSC && (_MSC_VER >= 1200)) && !defined(_MSC_FULL_VER) +# error "LZO_CC_MSC: _MSC_FULL_VER is not defined" +#endif +#if !defined(__LZO_ARCH_OVERRIDE) && !(LZO_ARCH_GENERIC) && defined(_CRAY) +# if (UINT_MAX > LZO_0xffffffffL) && defined(_CRAY) +# if defined(_CRAYMPP) || defined(_CRAYT3D) || defined(_CRAYT3E) +# define LZO_ARCH_CRAY_MPP 1 +# elif defined(_CRAY1) +# define LZO_ARCH_CRAY_PVP 1 +# endif +# endif +#endif +#if !defined(__LZO_ARCH_OVERRIDE) +#if (LZO_ARCH_GENERIC) +# define LZO_INFO_ARCH "generic" +#elif (LZO_OS_DOS16 || LZO_OS_OS216 || LZO_OS_WIN16) +# define LZO_ARCH_I086 1 +# define LZO_ARCH_IA16 1 +# define LZO_INFO_ARCH "i086" +#elif defined(__alpha__) || defined(__alpha) || defined(_M_ALPHA) +# define LZO_ARCH_ALPHA 1 +# define LZO_INFO_ARCH "alpha" +#elif (LZO_ARCH_CRAY_MPP) && (defined(_CRAYT3D) || defined(_CRAYT3E)) +# define LZO_ARCH_ALPHA 1 +# define LZO_INFO_ARCH "alpha" +#elif defined(__amd64__) || defined(__x86_64__) || defined(_M_AMD64) +# define LZO_ARCH_AMD64 1 +# define LZO_INFO_ARCH "amd64" +#elif defined(__thumb__) || (defined(_M_ARM) && defined(_M_THUMB)) +# define LZO_ARCH_ARM 1 +# define LZO_ARCH_ARM_THUMB 1 +# define LZO_INFO_ARCH "arm_thumb" +#elif defined(__IAR_SYSTEMS_ICC__) && defined(__ICCARM__) +# define LZO_ARCH_ARM 1 +# if defined(__CPU_MODE__) && ((__CPU_MODE__)+0 == 1) +# define LZO_ARCH_ARM_THUMB 1 +# define LZO_INFO_ARCH "arm_thumb" +# elif defined(__CPU_MODE__) && ((__CPU_MODE__)+0 == 2) +# define LZO_INFO_ARCH "arm" +# else +# define LZO_INFO_ARCH "arm" +# endif +#elif defined(__arm__) || defined(_M_ARM) +# define LZO_ARCH_ARM 1 +# define LZO_INFO_ARCH "arm" +#elif (UINT_MAX <= LZO_0xffffL) && defined(__AVR__) +# define LZO_ARCH_AVR 1 +# define LZO_INFO_ARCH "avr" +#elif defined(__avr32__) || defined(__AVR32__) +# define LZO_ARCH_AVR32 1 +# define LZO_INFO_ARCH "avr32" +#elif defined(__bfin__) +# define LZO_ARCH_BLACKFIN 1 +# define LZO_INFO_ARCH "blackfin" +#elif (UINT_MAX == LZO_0xffffL) && defined(__C166__) +# define LZO_ARCH_C166 1 +# define LZO_INFO_ARCH "c166" +#elif defined(__cris__) +# define LZO_ARCH_CRIS 1 +# define LZO_INFO_ARCH "cris" +#elif defined(__IAR_SYSTEMS_ICC__) && defined(__ICCEZ80__) +# define LZO_ARCH_EZ80 1 +# define LZO_INFO_ARCH "ez80" +#elif defined(__H8300__) || defined(__H8300H__) || defined(__H8300S__) || defined(__H8300SX__) +# define LZO_ARCH_H8300 1 +# define LZO_INFO_ARCH "h8300" +#elif defined(__hppa__) || defined(__hppa) +# define LZO_ARCH_HPPA 1 +# define LZO_INFO_ARCH "hppa" +#elif defined(__386__) || defined(__i386__) || defined(__i386) || defined(_M_IX86) || defined(_M_I386) +# define LZO_ARCH_I386 1 +# define LZO_ARCH_IA32 1 +# define LZO_INFO_ARCH "i386" +#elif (LZO_CC_ZORTECHC && defined(__I86__)) +# define LZO_ARCH_I386 1 +# define LZO_ARCH_IA32 1 +# define LZO_INFO_ARCH "i386" +#elif (LZO_OS_DOS32 && LZO_CC_HIGHC) && defined(_I386) +# define LZO_ARCH_I386 1 +# define LZO_ARCH_IA32 1 +# define LZO_INFO_ARCH "i386" +#elif defined(__ia64__) || defined(__ia64) || defined(_M_IA64) +# define LZO_ARCH_IA64 1 +# define LZO_INFO_ARCH "ia64" +#elif (UINT_MAX == LZO_0xffffL) && defined(__m32c__) +# define LZO_ARCH_M16C 1 +# define LZO_INFO_ARCH "m16c" +#elif defined(__IAR_SYSTEMS_ICC__) && defined(__ICCM16C__) +# define LZO_ARCH_M16C 1 +# define LZO_INFO_ARCH "m16c" +#elif defined(__m32r__) +# define LZO_ARCH_M32R 1 +# define LZO_INFO_ARCH "m32r" +#elif (LZO_OS_TOS) || defined(__m68k__) || defined(__m68000__) || defined(__mc68000__) || defined(__mc68020__) || defined(_M_M68K) +# define LZO_ARCH_M68K 1 +# define LZO_INFO_ARCH "m68k" +#elif (UINT_MAX == LZO_0xffffL) && defined(__C251__) +# define LZO_ARCH_MCS251 1 +# define LZO_INFO_ARCH "mcs251" +#elif (UINT_MAX == LZO_0xffffL) && defined(__C51__) +# define LZO_ARCH_MCS51 1 +# define LZO_INFO_ARCH "mcs51" +#elif defined(__IAR_SYSTEMS_ICC__) && defined(__ICC8051__) +# define LZO_ARCH_MCS51 1 +# define LZO_INFO_ARCH "mcs51" +#elif defined(__mips__) || defined(__mips) || defined(_MIPS_ARCH) || defined(_M_MRX000) +# define LZO_ARCH_MIPS 1 +# define LZO_INFO_ARCH "mips" +#elif (UINT_MAX == LZO_0xffffL) && defined(__MSP430__) +# define LZO_ARCH_MSP430 1 +# define LZO_INFO_ARCH "msp430" +#elif defined(__IAR_SYSTEMS_ICC__) && defined(__ICC430__) +# define LZO_ARCH_MSP430 1 +# define LZO_INFO_ARCH "msp430" +#elif defined(__powerpc__) || defined(__powerpc) || defined(__ppc__) || defined(__PPC__) || defined(_M_PPC) || defined(_ARCH_PPC) || defined(_ARCH_PWR) +# define LZO_ARCH_POWERPC 1 +# define LZO_INFO_ARCH "powerpc" +#elif defined(__s390__) || defined(__s390) || defined(__s390x__) || defined(__s390x) +# define LZO_ARCH_S390 1 +# define LZO_INFO_ARCH "s390" +#elif defined(__sh__) || defined(_M_SH) +# define LZO_ARCH_SH 1 +# define LZO_INFO_ARCH "sh" +#elif defined(__sparc__) || defined(__sparc) || defined(__sparcv8) +# define LZO_ARCH_SPARC 1 +# define LZO_INFO_ARCH "sparc" +#elif defined(__SPU__) +# define LZO_ARCH_SPU 1 +# define LZO_INFO_ARCH "spu" +#elif (UINT_MAX == LZO_0xffffL) && defined(__z80) +# define LZO_ARCH_Z80 1 +# define LZO_INFO_ARCH "z80" +#elif (LZO_ARCH_CRAY_PVP) +# if defined(_CRAYSV1) +# define LZO_ARCH_CRAY_SV1 1 +# define LZO_INFO_ARCH "cray_sv1" +# elif (_ADDR64) +# define LZO_ARCH_CRAY_T90 1 +# define LZO_INFO_ARCH "cray_t90" +# elif (_ADDR32) +# define LZO_ARCH_CRAY_YMP 1 +# define LZO_INFO_ARCH "cray_ymp" +# else +# define LZO_ARCH_CRAY_XMP 1 +# define LZO_INFO_ARCH "cray_xmp" +# endif +#else +# define LZO_ARCH_UNKNOWN 1 +# define LZO_INFO_ARCH "unknown" +#endif +#endif +#if 1 && (LZO_ARCH_UNKNOWN) && (LZO_OS_DOS32 || LZO_OS_OS2) +# error "FIXME - missing define for CPU architecture" +#endif +#if 1 && (LZO_ARCH_UNKNOWN) && (LZO_OS_WIN32) +# error "FIXME - missing WIN32 define for CPU architecture" +#endif +#if 1 && (LZO_ARCH_UNKNOWN) && (LZO_OS_WIN64) +# error "FIXME - missing WIN64 define for CPU architecture" +#endif +#if (LZO_OS_OS216 || LZO_OS_WIN16) +# define LZO_ARCH_I086PM 1 +# define LZO_ARCH_IA16PM 1 +#elif 1 && (LZO_OS_DOS16 && defined(BLX286)) +# define LZO_ARCH_I086PM 1 +# define LZO_ARCH_IA16PM 1 +#elif 1 && (LZO_OS_DOS16 && defined(DOSX286)) +# define LZO_ARCH_I086PM 1 +# define LZO_ARCH_IA16PM 1 +#elif 1 && (LZO_OS_DOS16 && LZO_CC_BORLANDC && defined(__DPMI16__)) +# define LZO_ARCH_I086PM 1 +# define LZO_ARCH_IA16PM 1 +#endif +#if (LZO_ARCH_ARM_THUMB) && !(LZO_ARCH_ARM) +# error "this should not happen" +#endif +#if (LZO_ARCH_I086PM) && !(LZO_ARCH_I086) +# error "this should not happen" +#endif +#if (LZO_ARCH_I086) +# if (UINT_MAX != LZO_0xffffL) +# error "this should not happen" +# endif +# if (ULONG_MAX != LZO_0xffffffffL) +# error "this should not happen" +# endif +#endif +#if (LZO_ARCH_I386) +# if (UINT_MAX != LZO_0xffffL) && defined(__i386_int16__) +# error "this should not happen" +# endif +# if (UINT_MAX != LZO_0xffffffffL) && !defined(__i386_int16__) +# error "this should not happen" +# endif +# if (ULONG_MAX != LZO_0xffffffffL) +# error "this should not happen" +# endif +#endif +#if !defined(__LZO_MM_OVERRIDE) +#if (LZO_ARCH_I086) +#if (UINT_MAX != LZO_0xffffL) +# error "this should not happen" +#endif +#if defined(__TINY__) || defined(M_I86TM) || defined(_M_I86TM) +# define LZO_MM_TINY 1 +#elif defined(__HUGE__) || defined(_HUGE_) || defined(M_I86HM) || defined(_M_I86HM) +# define LZO_MM_HUGE 1 +#elif defined(__SMALL__) || defined(M_I86SM) || defined(_M_I86SM) || defined(SMALL_MODEL) +# define LZO_MM_SMALL 1 +#elif defined(__MEDIUM__) || defined(M_I86MM) || defined(_M_I86MM) +# define LZO_MM_MEDIUM 1 +#elif defined(__COMPACT__) || defined(M_I86CM) || defined(_M_I86CM) +# define LZO_MM_COMPACT 1 +#elif defined(__LARGE__) || defined(M_I86LM) || defined(_M_I86LM) || defined(LARGE_MODEL) +# define LZO_MM_LARGE 1 +#elif (LZO_CC_AZTECC) +# if defined(_LARGE_CODE) && defined(_LARGE_DATA) +# define LZO_MM_LARGE 1 +# elif defined(_LARGE_CODE) +# define LZO_MM_MEDIUM 1 +# elif defined(_LARGE_DATA) +# define LZO_MM_COMPACT 1 +# else +# define LZO_MM_SMALL 1 +# endif +#elif (LZO_CC_ZORTECHC && defined(__VCM__)) +# define LZO_MM_LARGE 1 +#else +# error "unknown memory model" +#endif +#if (LZO_OS_DOS16 || LZO_OS_OS216 || LZO_OS_WIN16) +#define LZO_HAVE_MM_HUGE_PTR 1 +#define LZO_HAVE_MM_HUGE_ARRAY 1 +#if (LZO_MM_TINY) +# undef LZO_HAVE_MM_HUGE_ARRAY +#endif +#if (LZO_CC_AZTECC || LZO_CC_PACIFICC || LZO_CC_ZORTECHC) +# undef LZO_HAVE_MM_HUGE_PTR +# undef LZO_HAVE_MM_HUGE_ARRAY +#elif (LZO_CC_DMC || LZO_CC_SYMANTECC) +# undef LZO_HAVE_MM_HUGE_ARRAY +#elif (LZO_CC_MSC && defined(_QC)) +# undef LZO_HAVE_MM_HUGE_ARRAY +# if (_MSC_VER < 600) +# undef LZO_HAVE_MM_HUGE_PTR +# endif +#elif (LZO_CC_TURBOC && (__TURBOC__ < 0x0295)) +# undef LZO_HAVE_MM_HUGE_ARRAY +#endif +#if (LZO_ARCH_I086PM) && !(LZO_HAVE_MM_HUGE_PTR) +# if (LZO_OS_DOS16) +# error "this should not happen" +# elif (LZO_CC_ZORTECHC) +# else +# error "this should not happen" +# endif +#endif +#ifdef __cplusplus +extern "C" { +#endif +#if (LZO_CC_BORLANDC && (__BORLANDC__ >= 0x0200)) + extern void __near __cdecl _AHSHIFT(void); +# define LZO_MM_AHSHIFT ((unsigned) _AHSHIFT) +#elif (LZO_CC_DMC || LZO_CC_SYMANTECC || LZO_CC_ZORTECHC) + extern void __near __cdecl _AHSHIFT(void); +# define LZO_MM_AHSHIFT ((unsigned) _AHSHIFT) +#elif (LZO_CC_MSC || LZO_CC_TOPSPEEDC) + extern void __near __cdecl _AHSHIFT(void); +# define LZO_MM_AHSHIFT ((unsigned) _AHSHIFT) +#elif (LZO_CC_TURBOC && (__TURBOC__ >= 0x0295)) + extern void __near __cdecl _AHSHIFT(void); +# define LZO_MM_AHSHIFT ((unsigned) _AHSHIFT) +#elif ((LZO_CC_AZTECC || LZO_CC_PACIFICC || LZO_CC_TURBOC) && LZO_OS_DOS16) +# define LZO_MM_AHSHIFT 12 +#elif (LZO_CC_WATCOMC) + extern unsigned char _HShift; +# define LZO_MM_AHSHIFT ((unsigned) _HShift) +#else +# error "FIXME - implement LZO_MM_AHSHIFT" +#endif +#ifdef __cplusplus +} +#endif +#endif +#elif (LZO_ARCH_C166) +#if !defined(__MODEL__) +# error "FIXME - C166 __MODEL__" +#elif ((__MODEL__) == 0) +# define LZO_MM_SMALL 1 +#elif ((__MODEL__) == 1) +# define LZO_MM_SMALL 1 +#elif ((__MODEL__) == 2) +# define LZO_MM_LARGE 1 +#elif ((__MODEL__) == 3) +# define LZO_MM_TINY 1 +#elif ((__MODEL__) == 4) +# define LZO_MM_XTINY 1 +#elif ((__MODEL__) == 5) +# define LZO_MM_XSMALL 1 +#else +# error "FIXME - C166 __MODEL__" +#endif +#elif (LZO_ARCH_MCS251) +#if !defined(__MODEL__) +# error "FIXME - MCS251 __MODEL__" +#elif ((__MODEL__) == 0) +# define LZO_MM_SMALL 1 +#elif ((__MODEL__) == 2) +# define LZO_MM_LARGE 1 +#elif ((__MODEL__) == 3) +# define LZO_MM_TINY 1 +#elif ((__MODEL__) == 4) +# define LZO_MM_XTINY 1 +#elif ((__MODEL__) == 5) +# define LZO_MM_XSMALL 1 +#else +# error "FIXME - MCS251 __MODEL__" +#endif +#elif (LZO_ARCH_MCS51) +#if !defined(__MODEL__) +# error "FIXME - MCS51 __MODEL__" +#elif ((__MODEL__) == 1) +# define LZO_MM_SMALL 1 +#elif ((__MODEL__) == 2) +# define LZO_MM_LARGE 1 +#elif ((__MODEL__) == 3) +# define LZO_MM_TINY 1 +#elif ((__MODEL__) == 4) +# define LZO_MM_XTINY 1 +#elif ((__MODEL__) == 5) +# define LZO_MM_XSMALL 1 +#else +# error "FIXME - MCS51 __MODEL__" +#endif +#elif (LZO_ARCH_CRAY_PVP) +# define LZO_MM_PVP 1 +#else +# define LZO_MM_FLAT 1 +#endif +#if (LZO_MM_COMPACT) +# define LZO_INFO_MM "compact" +#elif (LZO_MM_FLAT) +# define LZO_INFO_MM "flat" +#elif (LZO_MM_HUGE) +# define LZO_INFO_MM "huge" +#elif (LZO_MM_LARGE) +# define LZO_INFO_MM "large" +#elif (LZO_MM_MEDIUM) +# define LZO_INFO_MM "medium" +#elif (LZO_MM_PVP) +# define LZO_INFO_MM "pvp" +#elif (LZO_MM_SMALL) +# define LZO_INFO_MM "small" +#elif (LZO_MM_TINY) +# define LZO_INFO_MM "tiny" +#else +# error "unknown memory model" +#endif +#endif +#if defined(SIZEOF_SHORT) +# define LZO_SIZEOF_SHORT (SIZEOF_SHORT) +#endif +#if defined(SIZEOF_INT) +# define LZO_SIZEOF_INT (SIZEOF_INT) +#endif +#if defined(SIZEOF_LONG) +# define LZO_SIZEOF_LONG (SIZEOF_LONG) +#endif +#if defined(SIZEOF_LONG_LONG) +# define LZO_SIZEOF_LONG_LONG (SIZEOF_LONG_LONG) +#endif +#if defined(SIZEOF___INT16) +# define LZO_SIZEOF___INT16 (SIZEOF___INT16) +#endif +#if defined(SIZEOF___INT32) +# define LZO_SIZEOF___INT32 (SIZEOF___INT32) +#endif +#if defined(SIZEOF___INT64) +# define LZO_SIZEOF___INT64 (SIZEOF___INT64) +#endif +#if defined(SIZEOF_VOID_P) +# define LZO_SIZEOF_VOID_P (SIZEOF_VOID_P) +#endif +#if defined(SIZEOF_SIZE_T) +# define LZO_SIZEOF_SIZE_T (SIZEOF_SIZE_T) +#endif +#if defined(SIZEOF_PTRDIFF_T) +# define LZO_SIZEOF_PTRDIFF_T (SIZEOF_PTRDIFF_T) +#endif +#define __LZO_LSR(x,b) (((x)+0ul) >> (b)) +#if !defined(LZO_SIZEOF_SHORT) +# if (LZO_ARCH_CRAY_PVP) +# define LZO_SIZEOF_SHORT 8 +# elif (USHRT_MAX == LZO_0xffffL) +# define LZO_SIZEOF_SHORT 2 +# elif (__LZO_LSR(USHRT_MAX,7) == 1) +# define LZO_SIZEOF_SHORT 1 +# elif (__LZO_LSR(USHRT_MAX,15) == 1) +# define LZO_SIZEOF_SHORT 2 +# elif (__LZO_LSR(USHRT_MAX,31) == 1) +# define LZO_SIZEOF_SHORT 4 +# elif (__LZO_LSR(USHRT_MAX,63) == 1) +# define LZO_SIZEOF_SHORT 8 +# elif (__LZO_LSR(USHRT_MAX,127) == 1) +# define LZO_SIZEOF_SHORT 16 +# else +# error "LZO_SIZEOF_SHORT" +# endif +#endif +#if !defined(LZO_SIZEOF_INT) +# if (LZO_ARCH_CRAY_PVP) +# define LZO_SIZEOF_INT 8 +# elif (UINT_MAX == LZO_0xffffL) +# define LZO_SIZEOF_INT 2 +# elif (UINT_MAX == LZO_0xffffffffL) +# define LZO_SIZEOF_INT 4 +# elif (__LZO_LSR(UINT_MAX,7) == 1) +# define LZO_SIZEOF_INT 1 +# elif (__LZO_LSR(UINT_MAX,15) == 1) +# define LZO_SIZEOF_INT 2 +# elif (__LZO_LSR(UINT_MAX,31) == 1) +# define LZO_SIZEOF_INT 4 +# elif (__LZO_LSR(UINT_MAX,63) == 1) +# define LZO_SIZEOF_INT 8 +# elif (__LZO_LSR(UINT_MAX,127) == 1) +# define LZO_SIZEOF_INT 16 +# else +# error "LZO_SIZEOF_INT" +# endif +#endif +#if !defined(LZO_SIZEOF_LONG) +# if (ULONG_MAX == LZO_0xffffffffL) +# define LZO_SIZEOF_LONG 4 +# elif (__LZO_LSR(ULONG_MAX,7) == 1) +# define LZO_SIZEOF_LONG 1 +# elif (__LZO_LSR(ULONG_MAX,15) == 1) +# define LZO_SIZEOF_LONG 2 +# elif (__LZO_LSR(ULONG_MAX,31) == 1) +# define LZO_SIZEOF_LONG 4 +# elif (__LZO_LSR(ULONG_MAX,63) == 1) +# define LZO_SIZEOF_LONG 8 +# elif (__LZO_LSR(ULONG_MAX,127) == 1) +# define LZO_SIZEOF_LONG 16 +# else +# error "LZO_SIZEOF_LONG" +# endif +#endif +#if !defined(LZO_SIZEOF_LONG_LONG) && !defined(LZO_SIZEOF___INT64) +#if (LZO_SIZEOF_LONG > 0 && LZO_SIZEOF_LONG < 8) +# if defined(__LONG_MAX__) && defined(__LONG_LONG_MAX__) +# if (LZO_CC_GNUC >= 0x030300ul) +# if ((__LONG_MAX__)+0 == (__LONG_LONG_MAX__)+0) +# define LZO_SIZEOF_LONG_LONG LZO_SIZEOF_LONG +# elif (__LZO_LSR(__LONG_LONG_MAX__,30) == 1) +# define LZO_SIZEOF_LONG_LONG 4 +# endif +# endif +# endif +#endif +#endif +#if !defined(LZO_SIZEOF_LONG_LONG) && !defined(LZO_SIZEOF___INT64) +#if (LZO_SIZEOF_LONG > 0 && LZO_SIZEOF_LONG < 8) +#if (LZO_ARCH_I086 && LZO_CC_DMC) +#elif (LZO_CC_CILLY) && defined(__GNUC__) +# define LZO_SIZEOF_LONG_LONG 8 +#elif (LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE) +# define LZO_SIZEOF_LONG_LONG 8 +#elif ((LZO_OS_WIN32 || LZO_OS_WIN64 || defined(_WIN32)) && LZO_CC_MSC && (_MSC_VER >= 1400)) +# define LZO_SIZEOF_LONG_LONG 8 +#elif (LZO_OS_WIN64 || defined(_WIN64)) +# define LZO_SIZEOF___INT64 8 +#elif (LZO_ARCH_I386 && (LZO_CC_DMC)) +# define LZO_SIZEOF_LONG_LONG 8 +#elif (LZO_ARCH_I386 && (LZO_CC_SYMANTECC && (__SC__ >= 0x700))) +# define LZO_SIZEOF_LONG_LONG 8 +#elif (LZO_ARCH_I386 && (LZO_CC_INTELC && defined(__linux__))) +# define LZO_SIZEOF_LONG_LONG 8 +#elif (LZO_ARCH_I386 && (LZO_CC_MWERKS || LZO_CC_PELLESC || LZO_CC_PGI || LZO_CC_SUNPROC)) +# define LZO_SIZEOF_LONG_LONG 8 +#elif (LZO_ARCH_I386 && (LZO_CC_INTELC || LZO_CC_MSC)) +# define LZO_SIZEOF___INT64 8 +#elif ((LZO_OS_WIN32 || defined(_WIN32)) && (LZO_CC_MSC)) +# define LZO_SIZEOF___INT64 8 +#elif (LZO_ARCH_I386 && (LZO_CC_BORLANDC && (__BORLANDC__ >= 0x0520))) +# define LZO_SIZEOF___INT64 8 +#elif (LZO_ARCH_I386 && (LZO_CC_WATCOMC && (__WATCOMC__ >= 1100))) +# define LZO_SIZEOF___INT64 8 +#elif (LZO_CC_WATCOMC && defined(_INTEGRAL_MAX_BITS) && (_INTEGRAL_MAX_BITS == 64)) +# define LZO_SIZEOF___INT64 8 +#elif (LZO_OS_OS400 || defined(__OS400__)) && defined(__LLP64_IFC__) +# define LZO_SIZEOF_LONG_LONG 8 +#elif (defined(__vms) || defined(__VMS)) && (__INITIAL_POINTER_SIZE+0 == 64) +# define LZO_SIZEOF_LONG_LONG 8 +#elif (LZO_CC_SDCC) && (LZO_SIZEOF_INT == 2) +#elif 1 && defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) +# define LZO_SIZEOF_LONG_LONG 8 +#endif +#endif +#endif +#if defined(__cplusplus) && (LZO_CC_GNUC) +# if (LZO_CC_GNUC < 0x020800ul) +# undef LZO_SIZEOF_LONG_LONG +# endif +#endif +#if (LZO_CFG_NO_LONG_LONG) || defined(__NO_LONG_LONG) +# undef LZO_SIZEOF_LONG_LONG +#endif +#if !defined(LZO_SIZEOF_VOID_P) +#if (LZO_ARCH_I086) +# define __LZO_WORDSIZE 2 +# if (LZO_MM_TINY || LZO_MM_SMALL || LZO_MM_MEDIUM) +# define LZO_SIZEOF_VOID_P 2 +# elif (LZO_MM_COMPACT || LZO_MM_LARGE || LZO_MM_HUGE) +# define LZO_SIZEOF_VOID_P 4 +# else +# error "LZO_MM" +# endif +#elif (LZO_ARCH_AVR || LZO_ARCH_Z80) +# define __LZO_WORDSIZE 1 +# define LZO_SIZEOF_VOID_P 2 +#elif (LZO_ARCH_C166 || LZO_ARCH_MCS51 || LZO_ARCH_MCS251 || LZO_ARCH_MSP430) +# define LZO_SIZEOF_VOID_P 2 +#elif (LZO_ARCH_H8300) +# if defined(__NORMAL_MODE__) +# define __LZO_WORDSIZE 4 +# define LZO_SIZEOF_VOID_P 2 +# elif defined(__H8300H__) || defined(__H8300S__) || defined(__H8300SX__) +# define __LZO_WORDSIZE 4 +# define LZO_SIZEOF_VOID_P 4 +# else +# define __LZO_WORDSIZE 2 +# define LZO_SIZEOF_VOID_P 2 +# endif +# if (LZO_CC_GNUC && (LZO_CC_GNUC < 0x040000ul)) && (LZO_SIZEOF_INT == 4) +# define LZO_SIZEOF_SIZE_T LZO_SIZEOF_INT +# define LZO_SIZEOF_PTRDIFF_T LZO_SIZEOF_INT +# endif +#elif (LZO_ARCH_M16C) +# define __LZO_WORDSIZE 2 +# if defined(__m32c_cpu__) || defined(__m32cm_cpu__) +# define LZO_SIZEOF_VOID_P 4 +# else +# define LZO_SIZEOF_VOID_P 2 +# endif +#elif (LZO_SIZEOF_LONG == 8) && ((defined(__mips__) && defined(__R5900__)) || defined(__MIPS_PSX2__)) +# define __LZO_WORDSIZE 8 +# define LZO_SIZEOF_VOID_P 4 +#elif defined(__LLP64__) || defined(__LLP64) || defined(_LLP64) || defined(_WIN64) +# define __LZO_WORDSIZE 8 +# define LZO_SIZEOF_VOID_P 8 +#elif (LZO_OS_OS400 || defined(__OS400__)) && defined(__LLP64_IFC__) +# define LZO_SIZEOF_VOID_P LZO_SIZEOF_LONG +# define LZO_SIZEOF_SIZE_T LZO_SIZEOF_LONG +# define LZO_SIZEOF_PTRDIFF_T LZO_SIZEOF_LONG +#elif (LZO_OS_OS400 || defined(__OS400__)) +# define __LZO_WORDSIZE LZO_SIZEOF_LONG +# define LZO_SIZEOF_VOID_P 16 +# define LZO_SIZEOF_SIZE_T LZO_SIZEOF_LONG +# define LZO_SIZEOF_PTRDIFF_T LZO_SIZEOF_LONG +#elif (defined(__vms) || defined(__VMS)) && (__INITIAL_POINTER_SIZE+0 == 64) +# define LZO_SIZEOF_VOID_P 8 +# define LZO_SIZEOF_SIZE_T LZO_SIZEOF_LONG +# define LZO_SIZEOF_PTRDIFF_T LZO_SIZEOF_LONG +#elif (LZO_ARCH_SPU) +# if 0 +# define __LZO_WORDSIZE 16 +# endif +# define LZO_SIZEOF_VOID_P 4 +#else +# define LZO_SIZEOF_VOID_P LZO_SIZEOF_LONG +#endif +#endif +#if !defined(LZO_WORDSIZE) +# if defined(__LZO_WORDSIZE) +# define LZO_WORDSIZE __LZO_WORDSIZE +# else +# define LZO_WORDSIZE LZO_SIZEOF_VOID_P +# endif +#endif +#if !defined(LZO_SIZEOF_SIZE_T) +#if (LZO_ARCH_I086 || LZO_ARCH_M16C) +# define LZO_SIZEOF_SIZE_T 2 +#else +# define LZO_SIZEOF_SIZE_T LZO_SIZEOF_VOID_P +#endif +#endif +#if !defined(LZO_SIZEOF_PTRDIFF_T) +#if (LZO_ARCH_I086) +# if (LZO_MM_TINY || LZO_MM_SMALL || LZO_MM_MEDIUM || LZO_MM_HUGE) +# define LZO_SIZEOF_PTRDIFF_T LZO_SIZEOF_VOID_P +# elif (LZO_MM_COMPACT || LZO_MM_LARGE) +# if (LZO_CC_BORLANDC || LZO_CC_TURBOC) +# define LZO_SIZEOF_PTRDIFF_T 4 +# else +# define LZO_SIZEOF_PTRDIFF_T 2 +# endif +# else +# error "LZO_MM" +# endif +#else +# define LZO_SIZEOF_PTRDIFF_T LZO_SIZEOF_SIZE_T +#endif +#endif +#if (LZO_ABI_NEUTRAL_ENDIAN) +# undef LZO_ABI_BIG_ENDIAN +# undef LZO_ABI_LITTLE_ENDIAN +#elif !(LZO_ABI_BIG_ENDIAN) && !(LZO_ABI_LITTLE_ENDIAN) +#if (LZO_ARCH_ALPHA) && (LZO_ARCH_CRAY_MPP) +# define LZO_ABI_BIG_ENDIAN 1 +#elif (LZO_ARCH_IA64) && (LZO_OS_POSIX_LINUX || LZO_OS_WIN64) +# define LZO_ABI_LITTLE_ENDIAN 1 +#elif (LZO_ARCH_ALPHA || LZO_ARCH_AMD64 || LZO_ARCH_BLACKFIN || LZO_ARCH_CRIS || LZO_ARCH_I086 || LZO_ARCH_I386 || LZO_ARCH_MSP430) +# define LZO_ABI_LITTLE_ENDIAN 1 +#elif (LZO_ARCH_AVR32 || LZO_ARCH_M68K || LZO_ARCH_S390) +# define LZO_ABI_BIG_ENDIAN 1 +#elif 1 && defined(__IAR_SYSTEMS_ICC__) && defined(__LITTLE_ENDIAN__) +# if (__LITTLE_ENDIAN__ == 1) +# define LZO_ABI_LITTLE_ENDIAN 1 +# else +# define LZO_ABI_BIG_ENDIAN 1 +# endif +#elif 1 && defined(__BIG_ENDIAN__) && !defined(__LITTLE_ENDIAN__) +# define LZO_ABI_BIG_ENDIAN 1 +#elif 1 && defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__) +# define LZO_ABI_LITTLE_ENDIAN 1 +#elif 1 && (LZO_ARCH_ARM) && defined(__ARMEB__) && !defined(__ARMEL__) +# define LZO_ABI_BIG_ENDIAN 1 +#elif 1 && (LZO_ARCH_ARM) && defined(__ARMEL__) && !defined(__ARMEB__) +# define LZO_ABI_LITTLE_ENDIAN 1 +#elif 1 && (LZO_ARCH_MIPS) && defined(__MIPSEB__) && !defined(__MIPSEL__) +# define LZO_ABI_BIG_ENDIAN 1 +#elif 1 && (LZO_ARCH_MIPS) && defined(__MIPSEL__) && !defined(__MIPSEB__) +# define LZO_ABI_LITTLE_ENDIAN 1 +#endif +#endif +#if (LZO_ABI_BIG_ENDIAN) && (LZO_ABI_LITTLE_ENDIAN) +# error "this should not happen" +#endif +#if (LZO_ABI_BIG_ENDIAN) +# define LZO_INFO_ABI_ENDIAN "be" +#elif (LZO_ABI_LITTLE_ENDIAN) +# define LZO_INFO_ABI_ENDIAN "le" +#elif (LZO_ABI_NEUTRAL_ENDIAN) +# define LZO_INFO_ABI_ENDIAN "neutral" +#endif +#if (LZO_SIZEOF_INT == 1 && LZO_SIZEOF_LONG == 2 && LZO_SIZEOF_VOID_P == 2) +# define LZO_ABI_I8LP16 1 +# define LZO_INFO_ABI_PM "i8lp16" +#elif (LZO_SIZEOF_INT == 2 && LZO_SIZEOF_LONG == 2 && LZO_SIZEOF_VOID_P == 2) +# define LZO_ABI_ILP16 1 +# define LZO_INFO_ABI_PM "ilp16" +#elif (LZO_SIZEOF_INT == 4 && LZO_SIZEOF_LONG == 4 && LZO_SIZEOF_VOID_P == 4) +# define LZO_ABI_ILP32 1 +# define LZO_INFO_ABI_PM "ilp32" +#elif (LZO_SIZEOF_INT == 4 && LZO_SIZEOF_LONG == 4 && LZO_SIZEOF_VOID_P == 8 && LZO_SIZEOF_SIZE_T == 8) +# define LZO_ABI_LLP64 1 +# define LZO_INFO_ABI_PM "llp64" +#elif (LZO_SIZEOF_INT == 4 && LZO_SIZEOF_LONG == 8 && LZO_SIZEOF_VOID_P == 8) +# define LZO_ABI_LP64 1 +# define LZO_INFO_ABI_PM "lp64" +#elif (LZO_SIZEOF_INT == 8 && LZO_SIZEOF_LONG == 8 && LZO_SIZEOF_VOID_P == 8) +# define LZO_ABI_ILP64 1 +# define LZO_INFO_ABI_PM "ilp64" +#elif (LZO_SIZEOF_INT == 4 && LZO_SIZEOF_LONG == 8 && LZO_SIZEOF_VOID_P == 4) +# define LZO_ABI_IP32L64 1 +# define LZO_INFO_ABI_PM "ip32l64" +#endif +#if !defined(__LZO_LIBC_OVERRIDE) +#if (LZO_LIBC_NAKED) +# define LZO_INFO_LIBC "naked" +#elif (LZO_LIBC_FREESTANDING) +# define LZO_INFO_LIBC "freestanding" +#elif (LZO_LIBC_MOSTLY_FREESTANDING) +# define LZO_INFO_LIBC "mfreestanding" +#elif (LZO_LIBC_ISOC90) +# define LZO_INFO_LIBC "isoc90" +#elif (LZO_LIBC_ISOC99) +# define LZO_INFO_LIBC "isoc99" +#elif defined(__dietlibc__) +# define LZO_LIBC_DIETLIBC 1 +# define LZO_INFO_LIBC "dietlibc" +#elif defined(_NEWLIB_VERSION) +# define LZO_LIBC_NEWLIB 1 +# define LZO_INFO_LIBC "newlib" +#elif defined(__UCLIBC__) && defined(__UCLIBC_MAJOR__) && defined(__UCLIBC_MINOR__) +# if defined(__UCLIBC_SUBLEVEL__) +# define LZO_LIBC_UCLIBC (__UCLIBC_MAJOR__ * 0x10000L + __UCLIBC_MINOR__ * 0x100 + __UCLIBC_SUBLEVEL__) +# else +# define LZO_LIBC_UCLIBC 0x00090bL +# endif +# define LZO_INFO_LIBC "uclibc" +#elif defined(__GLIBC__) && defined(__GLIBC_MINOR__) +# define LZO_LIBC_GLIBC (__GLIBC__ * 0x10000L + __GLIBC_MINOR__ * 0x100) +# define LZO_INFO_LIBC "glibc" +#elif (LZO_CC_MWERKS) && defined(__MSL__) +# define LZO_LIBC_MSL __MSL__ +# define LZO_INFO_LIBC "msl" +#elif 1 && defined(__IAR_SYSTEMS_ICC__) +# define LZO_LIBC_ISOC90 1 +# define LZO_INFO_LIBC "isoc90" +#else +# define LZO_LIBC_DEFAULT 1 +# define LZO_INFO_LIBC "default" +#endif +#endif +#if !defined(__lzo_gnuc_extension__) +#if (LZO_CC_GNUC >= 0x020800ul) +# define __lzo_gnuc_extension__ __extension__ +#elif (LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) +# define __lzo_gnuc_extension__ __extension__ +#else +# define __lzo_gnuc_extension__ /*empty*/ +#endif +#endif +#if !defined(__lzo_ua_volatile) +# define __lzo_ua_volatile volatile +#endif +#if !defined(__lzo_alignof) +#if (LZO_CC_CILLY || LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE || LZO_CC_PGI) +# define __lzo_alignof(e) __alignof__(e) +#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 700)) +# define __lzo_alignof(e) __alignof__(e) +#elif (LZO_CC_MSC && (_MSC_VER >= 1300)) +# define __lzo_alignof(e) __alignof(e) +#elif (LZO_CC_SUNPROC && (LZO_CC_SUNPROC >= 0x5100)) +# define __lzo_alignof(e) __alignof__(e) +#endif +#endif +#if defined(__lzo_alignof) +# define __lzo_HAVE_alignof 1 +#endif +#if !defined(__lzo_constructor) +#if (LZO_CC_GNUC >= 0x030400ul) +# define __lzo_constructor __attribute__((__constructor__,__used__)) +#elif (LZO_CC_GNUC >= 0x020700ul) +# define __lzo_constructor __attribute__((__constructor__)) +#elif (LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) +# define __lzo_constructor __attribute__((__constructor__)) +#endif +#endif +#if defined(__lzo_constructor) +# define __lzo_HAVE_constructor 1 +#endif +#if !defined(__lzo_destructor) +#if (LZO_CC_GNUC >= 0x030400ul) +# define __lzo_destructor __attribute__((__destructor__,__used__)) +#elif (LZO_CC_GNUC >= 0x020700ul) +# define __lzo_destructor __attribute__((__destructor__)) +#elif (LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) +# define __lzo_destructor __attribute__((__destructor__)) +#endif +#endif +#if defined(__lzo_destructor) +# define __lzo_HAVE_destructor 1 +#endif +#if (__lzo_HAVE_destructor) && !(__lzo_HAVE_constructor) +# error "this should not happen" +#endif +#if !defined(__lzo_inline) +#if (LZO_CC_TURBOC && (__TURBOC__ <= 0x0295)) +#elif defined(__cplusplus) +# define __lzo_inline inline +#elif (LZO_CC_BORLANDC && (__BORLANDC__ >= 0x0550)) +# define __lzo_inline __inline +#elif (LZO_CC_CILLY || LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE || LZO_CC_PGI) +# define __lzo_inline __inline__ +#elif (LZO_CC_DMC) +# define __lzo_inline __inline +#elif (LZO_CC_INTELC) +# define __lzo_inline __inline +#elif (LZO_CC_MWERKS && (__MWERKS__ >= 0x2405)) +# define __lzo_inline __inline +#elif (LZO_CC_MSC && (_MSC_VER >= 900)) +# define __lzo_inline __inline +#elif (LZO_CC_SUNPROC && (LZO_CC_SUNPROC >= 0x5100)) +# define __lzo_inline __inline__ +#elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) +# define __lzo_inline inline +#endif +#endif +#if defined(__lzo_inline) +# define __lzo_HAVE_inline 1 +#else +# define __lzo_inline /*empty*/ +#endif +#if !defined(__lzo_forceinline) +#if (LZO_CC_GNUC >= 0x030200ul) +# define __lzo_forceinline __inline__ __attribute__((__always_inline__)) +#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 450) && LZO_CC_SYNTAX_MSC) +# define __lzo_forceinline __forceinline +#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 800) && LZO_CC_SYNTAX_GNUC) +# define __lzo_forceinline __inline__ __attribute__((__always_inline__)) +#elif (LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) +# define __lzo_forceinline __inline__ __attribute__((__always_inline__)) +#elif (LZO_CC_MSC && (_MSC_VER >= 1200)) +# define __lzo_forceinline __forceinline +#elif (LZO_CC_SUNPROC && (LZO_CC_SUNPROC >= 0x5100)) +# define __lzo_forceinline __inline__ __attribute__((__always_inline__)) +#endif +#endif +#if defined(__lzo_forceinline) +# define __lzo_HAVE_forceinline 1 +#else +# define __lzo_forceinline /*empty*/ +#endif +#if !defined(__lzo_noinline) +#if 1 && (LZO_ARCH_I386) && (LZO_CC_GNUC >= 0x040000ul) && (LZO_CC_GNUC < 0x040003ul) +# define __lzo_noinline __attribute__((__noinline__,__used__)) +#elif (LZO_CC_GNUC >= 0x030200ul) +# define __lzo_noinline __attribute__((__noinline__)) +#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 600) && LZO_CC_SYNTAX_MSC) +# define __lzo_noinline __declspec(noinline) +#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 800) && LZO_CC_SYNTAX_GNUC) +# define __lzo_noinline __attribute__((__noinline__)) +#elif (LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) +# define __lzo_noinline __attribute__((__noinline__)) +#elif (LZO_CC_MSC && (_MSC_VER >= 1300)) +# define __lzo_noinline __declspec(noinline) +#elif (LZO_CC_MWERKS && (__MWERKS__ >= 0x3200) && (LZO_OS_WIN32 || LZO_OS_WIN64)) +# if defined(__cplusplus) +# else +# define __lzo_noinline __declspec(noinline) +# endif +#elif (LZO_CC_SUNPROC && (LZO_CC_SUNPROC >= 0x5100)) +# define __lzo_noinline __attribute__((__noinline__)) +#endif +#endif +#if defined(__lzo_noinline) +# define __lzo_HAVE_noinline 1 +#else +# define __lzo_noinline /*empty*/ +#endif +#if (__lzo_HAVE_forceinline || __lzo_HAVE_noinline) && !(__lzo_HAVE_inline) +# error "this should not happen" +#endif +#if !defined(__lzo_noreturn) +#if (LZO_CC_GNUC >= 0x020700ul) +# define __lzo_noreturn __attribute__((__noreturn__)) +#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 450) && LZO_CC_SYNTAX_MSC) +# define __lzo_noreturn __declspec(noreturn) +#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 600) && LZO_CC_SYNTAX_GNUC) +# define __lzo_noreturn __attribute__((__noreturn__)) +#elif (LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) +# define __lzo_noreturn __attribute__((__noreturn__)) +#elif (LZO_CC_MSC && (_MSC_VER >= 1200)) +# define __lzo_noreturn __declspec(noreturn) +#endif +#endif +#if defined(__lzo_noreturn) +# define __lzo_HAVE_noreturn 1 +#else +# define __lzo_noreturn /*empty*/ +#endif +#if !defined(__lzo_nothrow) +#if (LZO_CC_GNUC >= 0x030300ul) +# define __lzo_nothrow __attribute__((__nothrow__)) +#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 450) && LZO_CC_SYNTAX_MSC) && defined(__cplusplus) +# define __lzo_nothrow __declspec(nothrow) +#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 900) && LZO_CC_SYNTAX_GNUC) +# define __lzo_nothrow __attribute__((__nothrow__)) +#elif (LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) +# define __lzo_nothrow __attribute__((__nothrow__)) +#elif (LZO_CC_MSC && (_MSC_VER >= 1200)) && defined(__cplusplus) +# define __lzo_nothrow __declspec(nothrow) +#endif +#endif +#if defined(__lzo_nothrow) +# define __lzo_HAVE_nothrow 1 +#else +# define __lzo_nothrow /*empty*/ +#endif +#if !defined(__lzo_restrict) +#if (LZO_CC_GNUC >= 0x030400ul) +# define __lzo_restrict __restrict__ +#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 600) && LZO_CC_SYNTAX_GNUC) +# define __lzo_restrict __restrict__ +#elif (LZO_CC_CLANG || LZO_CC_LLVM) +# define __lzo_restrict __restrict__ +#elif (LZO_CC_MSC && (_MSC_VER >= 1400)) +# define __lzo_restrict __restrict +#endif +#endif +#if defined(__lzo_restrict) +# define __lzo_HAVE_restrict 1 +#else +# define __lzo_restrict /*empty*/ +#endif +#if !defined(__lzo_likely) && !defined(__lzo_unlikely) +#if (LZO_CC_GNUC >= 0x030200ul) +# define __lzo_likely(e) (__builtin_expect(!!(e),1)) +# define __lzo_unlikely(e) (__builtin_expect(!!(e),0)) +#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 800)) +# define __lzo_likely(e) (__builtin_expect(!!(e),1)) +# define __lzo_unlikely(e) (__builtin_expect(!!(e),0)) +#elif (LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) +# define __lzo_likely(e) (__builtin_expect(!!(e),1)) +# define __lzo_unlikely(e) (__builtin_expect(!!(e),0)) +#endif +#endif +#if defined(__lzo_likely) +# define __lzo_HAVE_likely 1 +#else +# define __lzo_likely(e) (e) +#endif +#if defined(__lzo_unlikely) +# define __lzo_HAVE_unlikely 1 +#else +# define __lzo_unlikely(e) (e) +#endif +#if !defined(LZO_UNUSED) +# if (LZO_CC_BORLANDC && (__BORLANDC__ >= 0x0600)) +# define LZO_UNUSED(var) ((void) &var) +# elif (LZO_CC_BORLANDC || LZO_CC_HIGHC || LZO_CC_NDPC || LZO_CC_PELLESC || LZO_CC_TURBOC) +# define LZO_UNUSED(var) if (&var) ; else +# elif (LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE) +# define LZO_UNUSED(var) ((void) var) +# elif (LZO_CC_MSC && (_MSC_VER < 900)) +# define LZO_UNUSED(var) if (&var) ; else +# elif (LZO_CC_KEILC) +# define LZO_UNUSED(var) {extern int __lzo_unused[1-2*!(sizeof(var)>0)];} +# elif (LZO_CC_PACIFICC) +# define LZO_UNUSED(var) ((void) sizeof(var)) +# elif (LZO_CC_WATCOMC) && defined(__cplusplus) +# define LZO_UNUSED(var) ((void) var) +# else +# define LZO_UNUSED(var) ((void) &var) +# endif +#endif +#if !defined(LZO_UNUSED_FUNC) +# if (LZO_CC_BORLANDC && (__BORLANDC__ >= 0x0600)) +# define LZO_UNUSED_FUNC(func) ((void) func) +# elif (LZO_CC_BORLANDC || LZO_CC_NDPC || LZO_CC_TURBOC) +# define LZO_UNUSED_FUNC(func) if (func) ; else +# elif (LZO_CC_CLANG || LZO_CC_LLVM) +# define LZO_UNUSED_FUNC(func) ((void) &func) +# elif (LZO_CC_MSC && (_MSC_VER < 900)) +# define LZO_UNUSED_FUNC(func) if (func) ; else +# elif (LZO_CC_MSC) +# define LZO_UNUSED_FUNC(func) ((void) &func) +# elif (LZO_CC_KEILC || LZO_CC_PELLESC) +# define LZO_UNUSED_FUNC(func) {extern int __lzo_unused[1-2*!(sizeof((int)func)>0)];} +# else +# define LZO_UNUSED_FUNC(func) ((void) func) +# endif +#endif +#if !defined(LZO_UNUSED_LABEL) +# if (LZO_CC_WATCOMC) && defined(__cplusplus) +# define LZO_UNUSED_LABEL(l) switch(0) case 1:goto l +# elif (LZO_CC_CLANG || LZO_CC_INTELC || LZO_CC_WATCOMC) +# define LZO_UNUSED_LABEL(l) if (0) goto l +# else +# define LZO_UNUSED_LABEL(l) switch(0) case 1:goto l +# endif +#endif +#if !defined(LZO_DEFINE_UNINITIALIZED_VAR) +# if 0 +# define LZO_DEFINE_UNINITIALIZED_VAR(type,var,init) type var +# elif 0 && (LZO_CC_GNUC) +# define LZO_DEFINE_UNINITIALIZED_VAR(type,var,init) type var = var +# else +# define LZO_DEFINE_UNINITIALIZED_VAR(type,var,init) type var = init +# endif +#endif +#if !defined(LZO_UNCONST_CAST) +# if 0 && defined(__cplusplus) +# define LZO_UNCONST_CAST(t,e) (const_cast (e)) +# elif (LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE) +# define LZO_UNCONST_CAST(t,e) ((t) ((void *) ((char *) ((lzo_uintptr_t) ((const void *) (e)))))) +# else +# define LZO_UNCONST_CAST(t,e) ((t) ((void *) ((char *) ((const void *) (e))))) +# endif +#endif +#if !defined(LZO_COMPILE_TIME_ASSERT_HEADER) +# if (LZO_CC_AZTECC || LZO_CC_ZORTECHC) +# define LZO_COMPILE_TIME_ASSERT_HEADER(e) extern int __lzo_cta[1-!(e)]; +# elif (LZO_CC_DMC || LZO_CC_SYMANTECC) +# define LZO_COMPILE_TIME_ASSERT_HEADER(e) extern int __lzo_cta[1u-2*!(e)]; +# elif (LZO_CC_TURBOC && (__TURBOC__ == 0x0295)) +# define LZO_COMPILE_TIME_ASSERT_HEADER(e) extern int __lzo_cta[1-!(e)]; +# else +# define LZO_COMPILE_TIME_ASSERT_HEADER(e) extern int __lzo_cta[1-2*!(e)]; +# endif +#endif +#if !defined(LZO_COMPILE_TIME_ASSERT) +# if (LZO_CC_AZTECC) +# define LZO_COMPILE_TIME_ASSERT(e) {typedef int __lzo_cta_t[1-!(e)];} +# elif (LZO_CC_DMC || LZO_CC_PACIFICC || LZO_CC_SYMANTECC || LZO_CC_ZORTECHC) +# define LZO_COMPILE_TIME_ASSERT(e) switch(0) case 1:case !(e):break; +# elif (LZO_CC_MSC && (_MSC_VER < 900)) +# define LZO_COMPILE_TIME_ASSERT(e) switch(0) case 1:case !(e):break; +# elif (LZO_CC_TURBOC && (__TURBOC__ == 0x0295)) +# define LZO_COMPILE_TIME_ASSERT(e) switch(0) case 1:case !(e):break; +# else +# define LZO_COMPILE_TIME_ASSERT(e) {typedef int __lzo_cta_t[1-2*!(e)];} +# endif +#endif +#if (LZO_ARCH_I086 || LZO_ARCH_I386) && (LZO_OS_DOS16 || LZO_OS_DOS32 || LZO_OS_OS2 || LZO_OS_OS216 || LZO_OS_WIN16 || LZO_OS_WIN32 || LZO_OS_WIN64) +# if (LZO_CC_GNUC || LZO_CC_HIGHC || LZO_CC_NDPC || LZO_CC_PACIFICC) +# elif (LZO_CC_DMC || LZO_CC_SYMANTECC || LZO_CC_ZORTECHC) +# define __lzo_cdecl __cdecl +# define __lzo_cdecl_atexit /*empty*/ +# define __lzo_cdecl_main __cdecl +# if (LZO_OS_OS2 && (LZO_CC_DMC || LZO_CC_SYMANTECC)) +# define __lzo_cdecl_qsort __pascal +# elif (LZO_OS_OS2 && (LZO_CC_ZORTECHC)) +# define __lzo_cdecl_qsort _stdcall +# else +# define __lzo_cdecl_qsort __cdecl +# endif +# elif (LZO_CC_WATCOMC) +# define __lzo_cdecl __cdecl +# else +# define __lzo_cdecl __cdecl +# define __lzo_cdecl_atexit __cdecl +# define __lzo_cdecl_main __cdecl +# define __lzo_cdecl_qsort __cdecl +# endif +# if (LZO_CC_GNUC || LZO_CC_HIGHC || LZO_CC_NDPC || LZO_CC_PACIFICC || LZO_CC_WATCOMC) +# elif (LZO_OS_OS2 && (LZO_CC_DMC || LZO_CC_SYMANTECC)) +# define __lzo_cdecl_sighandler __pascal +# elif (LZO_OS_OS2 && (LZO_CC_ZORTECHC)) +# define __lzo_cdecl_sighandler _stdcall +# elif (LZO_CC_MSC && (_MSC_VER >= 1400)) && defined(_M_CEE_PURE) +# define __lzo_cdecl_sighandler __clrcall +# elif (LZO_CC_MSC && (_MSC_VER >= 600 && _MSC_VER < 700)) +# if defined(_DLL) +# define __lzo_cdecl_sighandler _far _cdecl _loadds +# elif defined(_MT) +# define __lzo_cdecl_sighandler _far _cdecl +# else +# define __lzo_cdecl_sighandler _cdecl +# endif +# else +# define __lzo_cdecl_sighandler __cdecl +# endif +#elif (LZO_ARCH_I386) && (LZO_CC_WATCOMC) +# define __lzo_cdecl __cdecl +#elif (LZO_ARCH_M68K && LZO_OS_TOS && (LZO_CC_PUREC || LZO_CC_TURBOC)) +# define __lzo_cdecl cdecl +#endif +#if !defined(__lzo_cdecl) +# define __lzo_cdecl /*empty*/ +#endif +#if !defined(__lzo_cdecl_atexit) +# define __lzo_cdecl_atexit /*empty*/ +#endif +#if !defined(__lzo_cdecl_main) +# define __lzo_cdecl_main /*empty*/ +#endif +#if !defined(__lzo_cdecl_qsort) +# define __lzo_cdecl_qsort /*empty*/ +#endif +#if !defined(__lzo_cdecl_sighandler) +# define __lzo_cdecl_sighandler /*empty*/ +#endif +#if !defined(__lzo_cdecl_va) +# define __lzo_cdecl_va __lzo_cdecl +#endif +#if !(LZO_CFG_NO_WINDOWS_H) +#if (LZO_OS_CYGWIN || (LZO_OS_EMX && defined(__RSXNT__)) || LZO_OS_WIN32 || LZO_OS_WIN64) +# if (LZO_CC_WATCOMC && (__WATCOMC__ < 1000)) +# elif (LZO_OS_WIN32 && LZO_CC_GNUC) && defined(__PW32__) +# elif ((LZO_OS_CYGWIN || defined(__MINGW32__)) && (LZO_CC_GNUC && (LZO_CC_GNUC < 0x025f00ul))) +# else +# define LZO_HAVE_WINDOWS_H 1 +# endif +#endif +#endif +#if (LZO_ARCH_ALPHA) +# define LZO_OPT_AVOID_UINT_INDEX 1 +# define LZO_OPT_AVOID_SHORT 1 +# define LZO_OPT_AVOID_USHORT 1 +#elif (LZO_ARCH_AMD64) +# define LZO_OPT_AVOID_INT_INDEX 1 +# define LZO_OPT_AVOID_UINT_INDEX 1 +# define LZO_OPT_UNALIGNED16 1 +# define LZO_OPT_UNALIGNED32 1 +# define LZO_OPT_UNALIGNED64 1 +#elif (LZO_ARCH_ARM && LZO_ARCH_ARM_THUMB) +#elif (LZO_ARCH_ARM) +# define LZO_OPT_AVOID_SHORT 1 +# define LZO_OPT_AVOID_USHORT 1 +#elif (LZO_ARCH_CRIS) +# define LZO_OPT_UNALIGNED16 1 +# define LZO_OPT_UNALIGNED32 1 +#elif (LZO_ARCH_I386) +# define LZO_OPT_UNALIGNED16 1 +# define LZO_OPT_UNALIGNED32 1 +#elif (LZO_ARCH_IA64) +# define LZO_OPT_AVOID_INT_INDEX 1 +# define LZO_OPT_AVOID_UINT_INDEX 1 +# define LZO_OPT_PREFER_POSTINC 1 +#elif (LZO_ARCH_M68K) +# define LZO_OPT_PREFER_POSTINC 1 +# define LZO_OPT_PREFER_PREDEC 1 +# if defined(__mc68020__) && !defined(__mcoldfire__) +# define LZO_OPT_UNALIGNED16 1 +# define LZO_OPT_UNALIGNED32 1 +# endif +#elif (LZO_ARCH_MIPS) +# define LZO_OPT_AVOID_UINT_INDEX 1 +#elif (LZO_ARCH_POWERPC) +# define LZO_OPT_PREFER_PREINC 1 +# define LZO_OPT_PREFER_PREDEC 1 +# if (LZO_ABI_BIG_ENDIAN) +# define LZO_OPT_UNALIGNED16 1 +# define LZO_OPT_UNALIGNED32 1 +# endif +#elif (LZO_ARCH_S390) +# define LZO_OPT_UNALIGNED16 1 +# define LZO_OPT_UNALIGNED32 1 +# if (LZO_SIZEOF_SIZE_T == 8) +# define LZO_OPT_UNALIGNED64 1 +# endif +#elif (LZO_ARCH_SH) +# define LZO_OPT_PREFER_POSTINC 1 +# define LZO_OPT_PREFER_PREDEC 1 +#endif +#ifndef LZO_CFG_NO_INLINE_ASM +#if (LZO_CC_LLVM) +# define LZO_CFG_NO_INLINE_ASM 1 +#endif +#endif +#ifndef LZO_CFG_NO_UNALIGNED +#if (LZO_ABI_NEUTRAL_ENDIAN) || (LZO_ARCH_GENERIC) +# define LZO_CFG_NO_UNALIGNED 1 +#endif +#endif +#if (LZO_CFG_NO_UNALIGNED) +# undef LZO_OPT_UNALIGNED16 +# undef LZO_OPT_UNALIGNED32 +# undef LZO_OPT_UNALIGNED64 +#endif +#if (LZO_CFG_NO_INLINE_ASM) +#elif (LZO_ARCH_I386 && (LZO_OS_DOS32 || LZO_OS_WIN32) && (LZO_CC_DMC || LZO_CC_INTELC || LZO_CC_MSC || LZO_CC_PELLESC)) +# define LZO_ASM_SYNTAX_MSC 1 +#elif (LZO_OS_WIN64 && (LZO_CC_DMC || LZO_CC_INTELC || LZO_CC_MSC || LZO_CC_PELLESC)) +#elif (LZO_ARCH_I386 && LZO_CC_GNUC && (LZO_CC_GNUC == 0x011f00ul)) +#elif (LZO_ARCH_I386 && (LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_INTELC || LZO_CC_PATHSCALE)) +# define LZO_ASM_SYNTAX_GNUC 1 +#elif (LZO_ARCH_AMD64 && (LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_INTELC || LZO_CC_PATHSCALE)) +# define LZO_ASM_SYNTAX_GNUC 1 +#endif +#if (LZO_ASM_SYNTAX_GNUC) +#if (LZO_ARCH_I386 && LZO_CC_GNUC && (LZO_CC_GNUC < 0x020000ul)) +# define __LZO_ASM_CLOBBER "ax" +#elif (LZO_CC_INTELC) +# define __LZO_ASM_CLOBBER "memory" +#else +# define __LZO_ASM_CLOBBER "cc", "memory" +#endif +#endif +#if defined(__LZO_INFOSTR_MM) +#elif (LZO_MM_FLAT) && (defined(__LZO_INFOSTR_PM) || defined(LZO_INFO_ABI_PM)) +# define __LZO_INFOSTR_MM "" +#elif defined(LZO_INFO_MM) +# define __LZO_INFOSTR_MM "." LZO_INFO_MM +#else +# define __LZO_INFOSTR_MM "" +#endif +#if defined(__LZO_INFOSTR_PM) +#elif defined(LZO_INFO_ABI_PM) +# define __LZO_INFOSTR_PM "." LZO_INFO_ABI_PM +#else +# define __LZO_INFOSTR_PM "" +#endif +#if defined(__LZO_INFOSTR_ENDIAN) +#elif defined(LZO_INFO_ABI_ENDIAN) +# define __LZO_INFOSTR_ENDIAN "." LZO_INFO_ABI_ENDIAN +#else +# define __LZO_INFOSTR_ENDIAN "" +#endif +#if defined(__LZO_INFOSTR_OSNAME) +#elif defined(LZO_INFO_OS_CONSOLE) +# define __LZO_INFOSTR_OSNAME LZO_INFO_OS "." LZO_INFO_OS_CONSOLE +#elif defined(LZO_INFO_OS_POSIX) +# define __LZO_INFOSTR_OSNAME LZO_INFO_OS "." LZO_INFO_OS_POSIX +#else +# define __LZO_INFOSTR_OSNAME LZO_INFO_OS +#endif +#if defined(__LZO_INFOSTR_LIBC) +#elif defined(LZO_INFO_LIBC) +# define __LZO_INFOSTR_LIBC "." LZO_INFO_LIBC +#else +# define __LZO_INFOSTR_LIBC "" +#endif +#if defined(__LZO_INFOSTR_CCVER) +#elif defined(LZO_INFO_CCVER) +# define __LZO_INFOSTR_CCVER " " LZO_INFO_CCVER +#else +# define __LZO_INFOSTR_CCVER "" +#endif +#define LZO_INFO_STRING \ + LZO_INFO_ARCH __LZO_INFOSTR_MM __LZO_INFOSTR_PM __LZO_INFOSTR_ENDIAN \ + " " __LZO_INFOSTR_OSNAME __LZO_INFOSTR_LIBC " " LZO_INFO_CC __LZO_INFOSTR_CCVER + +#endif + +#endif + +#undef LZO_HAVE_CONFIG_H +#include "minilzo.h" + +#if !defined(MINILZO_VERSION) || (MINILZO_VERSION != 0x2050) +# error "version mismatch in miniLZO source files" +#endif + +#ifdef MINILZO_HAVE_CONFIG_H +# define LZO_HAVE_CONFIG_H 1 +#endif + +#ifndef __LZO_CONF_H +#define __LZO_CONF_H 1 + +#if !defined(__LZO_IN_MINILZO) +#if (LZO_CFG_FREESTANDING) +# define LZO_LIBC_FREESTANDING 1 +# define LZO_OS_FREESTANDING 1 +# define ACC_LIBC_FREESTANDING 1 +# define ACC_OS_FREESTANDING 1 +#endif +#if (LZO_CFG_NO_UNALIGNED) +# define ACC_CFG_NO_UNALIGNED 1 +#endif +#if (LZO_ARCH_GENERIC) +# define ACC_ARCH_GENERIC 1 +#endif +#if (LZO_ABI_NEUTRAL_ENDIAN) +# define ACC_ABI_NEUTRAL_ENDIAN 1 +#endif +#if (LZO_HAVE_CONFIG_H) +# define ACC_CONFIG_NO_HEADER 1 +#endif +#if defined(LZO_CFG_EXTRA_CONFIG_HEADER) +# include LZO_CFG_EXTRA_CONFIG_HEADER +#endif +#if defined(__LZOCONF_H) || defined(__LZOCONF_H_INCLUDED) +# error "include this file first" +#endif +#include "lzo/lzoconf.h" +#endif + +#if (LZO_VERSION < 0x02000) || !defined(__LZOCONF_H_INCLUDED) +# error "version mismatch" +#endif + +#if (LZO_CC_BORLANDC && LZO_ARCH_I086) +# pragma option -h +#endif + +#if (LZO_CC_MSC && (_MSC_VER >= 1000)) +# pragma warning(disable: 4127 4701) +#endif +#if (LZO_CC_MSC && (_MSC_VER >= 1300)) +# pragma warning(disable: 4820) +# pragma warning(disable: 4514 4710 4711) +#endif + +#if (LZO_CC_SUNPROC) +#if !defined(__cplusplus) +# pragma error_messages(off,E_END_OF_LOOP_CODE_NOT_REACHED) +# pragma error_messages(off,E_LOOP_NOT_ENTERED_AT_TOP) +# pragma error_messages(off,E_STATEMENT_NOT_REACHED) +#endif +#endif + +#if (__LZO_MMODEL_HUGE) && !(LZO_HAVE_MM_HUGE_PTR) +# error "this should not happen - check defines for __huge" +#endif + +#if defined(__LZO_IN_MINILZO) || defined(LZO_CFG_FREESTANDING) +#elif (LZO_OS_DOS16 || LZO_OS_OS216 || LZO_OS_WIN16) +# define ACC_WANT_ACC_INCD_H 1 +# define ACC_WANT_ACC_INCE_H 1 +# define ACC_WANT_ACC_INCI_H 1 +#elif 1 +# include +#else +# define ACC_WANT_ACC_INCD_H 1 +#endif + +#if (LZO_ARCH_I086) +# define ACC_MM_AHSHIFT LZO_MM_AHSHIFT +# define ACC_PTR_FP_OFF(x) (((const unsigned __far*)&(x))[0]) +# define ACC_PTR_FP_SEG(x) (((const unsigned __far*)&(x))[1]) +# define ACC_PTR_MK_FP(s,o) ((void __far*)(((unsigned long)(s)<<16)+(unsigned)(o))) +#endif + +#if !defined(lzo_uintptr_t) +# if defined(__LZO_MMODEL_HUGE) +# define lzo_uintptr_t unsigned long +# elif 1 && defined(LZO_OS_OS400) && (LZO_SIZEOF_VOID_P == 16) +# define __LZO_UINTPTR_T_IS_POINTER 1 + typedef char* lzo_uintptr_t; +# define lzo_uintptr_t lzo_uintptr_t +# elif (LZO_SIZEOF_SIZE_T == LZO_SIZEOF_VOID_P) +# define lzo_uintptr_t size_t +# elif (LZO_SIZEOF_LONG == LZO_SIZEOF_VOID_P) +# define lzo_uintptr_t unsigned long +# elif (LZO_SIZEOF_INT == LZO_SIZEOF_VOID_P) +# define lzo_uintptr_t unsigned int +# elif (LZO_SIZEOF_LONG_LONG == LZO_SIZEOF_VOID_P) +# define lzo_uintptr_t unsigned long long +# else +# define lzo_uintptr_t size_t +# endif +#endif +LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_uintptr_t) >= sizeof(lzo_voidp)) + +#if 1 && !defined(LZO_CFG_FREESTANDING) +#if 1 && !defined(HAVE_STRING_H) +#define HAVE_STRING_H 1 +#endif +#if 1 && !defined(HAVE_MEMCMP) +#define HAVE_MEMCMP 1 +#endif +#if 1 && !defined(HAVE_MEMCPY) +#define HAVE_MEMCPY 1 +#endif +#if 1 && !defined(HAVE_MEMMOVE) +#define HAVE_MEMMOVE 1 +#endif +#if 1 && !defined(HAVE_MEMSET) +#define HAVE_MEMSET 1 +#endif +#endif + +#if 1 && defined(HAVE_STRING_H) +#include +#endif + +#if (LZO_CFG_FREESTANDING) +# undef HAVE_MEMCMP +# undef HAVE_MEMCPY +# undef HAVE_MEMMOVE +# undef HAVE_MEMSET +#endif + +#if !(HAVE_MEMCMP) +# undef memcmp +# define memcmp(a,b,c) lzo_memcmp(a,b,c) +#elif !(__LZO_MMODEL_HUGE) +# undef lzo_memcmp +# define lzo_memcmp(a,b,c) memcmp(a,b,c) +#endif +#if !(HAVE_MEMCPY) +# undef memcpy +# define memcpy(a,b,c) lzo_memcpy(a,b,c) +#elif !(__LZO_MMODEL_HUGE) +# undef lzo_memcpy +# define lzo_memcpy(a,b,c) memcpy(a,b,c) +#endif +#if !(HAVE_MEMMOVE) +# undef memmove +# define memmove(a,b,c) lzo_memmove(a,b,c) +#elif !(__LZO_MMODEL_HUGE) +# undef lzo_memmove +# define lzo_memmove(a,b,c) memmove(a,b,c) +#endif +#if !(HAVE_MEMSET) +# undef memset +# define memset(a,b,c) lzo_memset(a,b,c) +#elif !(__LZO_MMODEL_HUGE) +# undef lzo_memset +# define lzo_memset(a,b,c) memset(a,b,c) +#endif + +#undef NDEBUG +#if (LZO_CFG_FREESTANDING) +# undef LZO_DEBUG +# define NDEBUG 1 +# undef assert +# define assert(e) ((void)0) +#else +# if !defined(LZO_DEBUG) +# define NDEBUG 1 +# endif +# include +#endif + +#if 0 && defined(__BOUNDS_CHECKING_ON) +# include +#else +# define BOUNDS_CHECKING_OFF_DURING(stmt) stmt +# define BOUNDS_CHECKING_OFF_IN_EXPR(expr) (expr) +#endif + +#if !defined(__lzo_inline) +# define __lzo_inline /*empty*/ +#endif +#if !defined(__lzo_forceinline) +# define __lzo_forceinline /*empty*/ +#endif +#if !defined(__lzo_noinline) +# define __lzo_noinline /*empty*/ +#endif + +#if (LZO_CFG_PGO) +# undef __acc_likely +# undef __acc_unlikely +# undef __lzo_likely +# undef __lzo_unlikely +# define __acc_likely(e) (e) +# define __acc_unlikely(e) (e) +# define __lzo_likely(e) (e) +# define __lzo_unlikely(e) (e) +#endif + +#if 1 +# define LZO_BYTE(x) ((unsigned char) (x)) +#else +# define LZO_BYTE(x) ((unsigned char) ((x) & 0xff)) +#endif + +#define LZO_MAX(a,b) ((a) >= (b) ? (a) : (b)) +#define LZO_MIN(a,b) ((a) <= (b) ? (a) : (b)) +#define LZO_MAX3(a,b,c) ((a) >= (b) ? LZO_MAX(a,c) : LZO_MAX(b,c)) +#define LZO_MIN3(a,b,c) ((a) <= (b) ? LZO_MIN(a,c) : LZO_MIN(b,c)) + +#define lzo_sizeof(type) ((lzo_uint) (sizeof(type))) + +#define LZO_HIGH(array) ((lzo_uint) (sizeof(array)/sizeof(*(array)))) + +#define LZO_SIZE(bits) (1u << (bits)) +#define LZO_MASK(bits) (LZO_SIZE(bits) - 1) + +#define LZO_LSIZE(bits) (1ul << (bits)) +#define LZO_LMASK(bits) (LZO_LSIZE(bits) - 1) + +#define LZO_USIZE(bits) ((lzo_uint) 1 << (bits)) +#define LZO_UMASK(bits) (LZO_USIZE(bits) - 1) + +#if !defined(DMUL) +#if 0 + +# define DMUL(a,b) ((lzo_xint) ((lzo_uint32)(a) * (lzo_uint32)(b))) +#else +# define DMUL(a,b) ((lzo_xint) ((a) * (b))) +#endif +#endif + +#if 1 && (LZO_ARCH_AMD64 || LZO_ARCH_I386 || LZO_ARCH_POWERPC) +# if (LZO_SIZEOF_SHORT == 2) +# define LZO_UNALIGNED_OK_2 1 +# endif +# if (LZO_SIZEOF_INT == 4) +# define LZO_UNALIGNED_OK_4 1 +# endif +#endif +#if 1 && (LZO_ARCH_AMD64) +# if defined(LZO_UINT64_MAX) +# define LZO_UNALIGNED_OK_8 1 +# endif +#endif +#if (LZO_CFG_NO_UNALIGNED) +# undef LZO_UNALIGNED_OK_2 +# undef LZO_UNALIGNED_OK_4 +# undef LZO_UNALIGNED_OK_8 +#endif + +#undef UA_GET16 +#undef UA_SET16 +#undef UA_COPY16 +#undef UA_GET32 +#undef UA_SET32 +#undef UA_COPY32 +#undef UA_GET64 +#undef UA_SET64 +#undef UA_COPY64 +#if defined(LZO_UNALIGNED_OK_2) + LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(unsigned short) == 2) +# if 1 && defined(ACC_UA_COPY16) +# define UA_GET16 ACC_UA_GET16 +# define UA_SET16 ACC_UA_SET16 +# define UA_COPY16 ACC_UA_COPY16 +# else +# define UA_GET16(p) (* (__lzo_ua_volatile const lzo_ushortp) (__lzo_ua_volatile const lzo_voidp) (p)) +# define UA_SET16(p,v) ((* (__lzo_ua_volatile lzo_ushortp) (__lzo_ua_volatile lzo_voidp) (p)) = (unsigned short) (v)) +# define UA_COPY16(d,s) UA_SET16(d, UA_GET16(s)) +# endif +#endif +#if defined(LZO_UNALIGNED_OK_4) || defined(LZO_ALIGNED_OK_4) + LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_uint32) == 4) +# if 1 && defined(ACC_UA_COPY32) +# define UA_GET32 ACC_UA_GET32 +# define UA_SET32 ACC_UA_SET32 +# define UA_COPY32 ACC_UA_COPY32 +# else +# define UA_GET32(p) (* (__lzo_ua_volatile const lzo_uint32p) (__lzo_ua_volatile const lzo_voidp) (p)) +# define UA_SET32(p,v) ((* (__lzo_ua_volatile lzo_uint32p) (__lzo_ua_volatile lzo_voidp) (p)) = (lzo_uint32) (v)) +# define UA_COPY32(d,s) UA_SET32(d, UA_GET32(s)) +# endif +#endif +#if defined(LZO_UNALIGNED_OK_8) + LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_uint64) == 8) +# if 1 && defined(ACC_UA_COPY64) +# define UA_GET64 ACC_UA_GET64 +# define UA_SET64 ACC_UA_SET64 +# define UA_COPY64 ACC_UA_COPY64 +# else +# define UA_GET64(p) (* (__lzo_ua_volatile const lzo_uint64p) (__lzo_ua_volatile const lzo_voidp) (p)) +# define UA_SET64(p,v) ((* (__lzo_ua_volatile lzo_uint64p) (__lzo_ua_volatile lzo_voidp) (p)) = (lzo_uint64) (v)) +# define UA_COPY64(d,s) UA_SET64(d, UA_GET64(s)) +# endif +#endif + +#define MEMCPY8_DS(dest,src,len) \ + lzo_memcpy(dest,src,len); dest += len; src += len + +#define BZERO8_PTR(s,l,n) \ + lzo_memset((lzo_voidp)(s),0,(lzo_uint)(l)*(n)) + +#define MEMCPY_DS(dest,src,len) \ + do *dest++ = *src++; while (--len > 0) + +LZO_EXTERN(const lzo_bytep) lzo_copyright(void); + +#ifndef __LZO_PTR_H +#define __LZO_PTR_H 1 + +#ifdef __cplusplus +extern "C" { +#endif + +#if !defined(lzo_uintptr_t) +# if (__LZO_MMODEL_HUGE) +# define lzo_uintptr_t unsigned long +# else +# define lzo_uintptr_t acc_uintptr_t +# ifdef __ACC_INTPTR_T_IS_POINTER +# define __LZO_UINTPTR_T_IS_POINTER 1 +# endif +# endif +#endif + +#if (LZO_ARCH_I086) +#define PTR(a) ((lzo_bytep) (a)) +#define PTR_ALIGNED_4(a) ((ACC_PTR_FP_OFF(a) & 3) == 0) +#define PTR_ALIGNED2_4(a,b) (((ACC_PTR_FP_OFF(a) | ACC_PTR_FP_OFF(b)) & 3) == 0) +#elif (LZO_MM_PVP) +#define PTR(a) ((lzo_bytep) (a)) +#define PTR_ALIGNED_8(a) ((((lzo_uintptr_t)(a)) >> 61) == 0) +#define PTR_ALIGNED2_8(a,b) ((((lzo_uintptr_t)(a)|(lzo_uintptr_t)(b)) >> 61) == 0) +#else +#define PTR(a) ((lzo_uintptr_t) (a)) +#define PTR_LINEAR(a) PTR(a) +#define PTR_ALIGNED_4(a) ((PTR_LINEAR(a) & 3) == 0) +#define PTR_ALIGNED_8(a) ((PTR_LINEAR(a) & 7) == 0) +#define PTR_ALIGNED2_4(a,b) (((PTR_LINEAR(a) | PTR_LINEAR(b)) & 3) == 0) +#define PTR_ALIGNED2_8(a,b) (((PTR_LINEAR(a) | PTR_LINEAR(b)) & 7) == 0) +#endif + +#define PTR_LT(a,b) (PTR(a) < PTR(b)) +#define PTR_GE(a,b) (PTR(a) >= PTR(b)) +#define PTR_DIFF(a,b) (PTR(a) - PTR(b)) +#define pd(a,b) ((lzo_uint) ((a)-(b))) + +LZO_EXTERN(lzo_uintptr_t) +__lzo_ptr_linear(const lzo_voidp ptr); + +typedef union +{ + char a_char; + unsigned char a_uchar; + short a_short; + unsigned short a_ushort; + int a_int; + unsigned int a_uint; + long a_long; + unsigned long a_ulong; + lzo_int a_lzo_int; + lzo_uint a_lzo_uint; + lzo_int32 a_lzo_int32; + lzo_uint32 a_lzo_uint32; +#if defined(LZO_UINT64_MAX) + lzo_int64 a_lzo_int64; + lzo_uint64 a_lzo_uint64; +#endif + ptrdiff_t a_ptrdiff_t; + lzo_uintptr_t a_lzo_uintptr_t; + lzo_voidp a_lzo_voidp; + void * a_void_p; + lzo_bytep a_lzo_bytep; + lzo_bytepp a_lzo_bytepp; + lzo_uintp a_lzo_uintp; + lzo_uint * a_lzo_uint_p; + lzo_uint32p a_lzo_uint32p; + lzo_uint32 * a_lzo_uint32_p; + unsigned char * a_uchar_p; + char * a_char_p; +} +lzo_full_align_t; + +#ifdef __cplusplus +} +#endif + +#endif + +#ifndef LZO_DETERMINISTIC +#define LZO_DETERMINISTIC 1 +#endif + +#ifndef LZO_DICT_USE_PTR +#define LZO_DICT_USE_PTR 1 +#if 0 && (LZO_ARCH_I086) +# undef LZO_DICT_USE_PTR +# define LZO_DICT_USE_PTR 0 +#endif +#endif + +#if (LZO_DICT_USE_PTR) +# define lzo_dict_t const lzo_bytep +# define lzo_dict_p lzo_dict_t __LZO_MMODEL * +#else +# define lzo_dict_t lzo_uint +# define lzo_dict_p lzo_dict_t __LZO_MMODEL * +#endif + +#endif + +#if !defined(MINILZO_CFG_SKIP_LZO_PTR) + +LZO_PUBLIC(lzo_uintptr_t) +__lzo_ptr_linear(const lzo_voidp ptr) +{ + lzo_uintptr_t p; + +#if (LZO_ARCH_I086) + p = (((lzo_uintptr_t)(ACC_PTR_FP_SEG(ptr))) << (16 - ACC_MM_AHSHIFT)) + (ACC_PTR_FP_OFF(ptr)); +#elif (LZO_MM_PVP) + p = (lzo_uintptr_t) (ptr); + p = (p << 3) | (p >> 61); +#else + p = (lzo_uintptr_t) PTR_LINEAR(ptr); +#endif + + return p; +} + +LZO_PUBLIC(unsigned) +__lzo_align_gap(const lzo_voidp ptr, lzo_uint size) +{ +#if defined(__LZO_UINTPTR_T_IS_POINTER) + size_t n = (size_t) ptr; + n = (((n + size - 1) / size) * size) - n; +#else + lzo_uintptr_t p, n; + p = __lzo_ptr_linear(ptr); + n = (((p + size - 1) / size) * size) - p; +#endif + + assert(size > 0); + assert((long)n >= 0); + assert(n <= size); + return (unsigned)n; +} + +#endif +#if !defined(MINILZO_CFG_SKIP_LZO_UTIL) + +/* If you use the LZO library in a product, I would appreciate that you + * keep this copyright string in the executable of your product. + */ + +static const char __lzo_copyright[] = +#if !defined(__LZO_IN_MINLZO) + LZO_VERSION_STRING; +#else + "\r\n\n" + "LZO data compression library.\n" + "$Copyright: LZO Copyright (C) 1996-2011 Markus Franz Xaver Johannes Oberhumer\n" + "\n" + "http://www.oberhumer.com $\n\n" + "$Id: LZO version: v" LZO_VERSION_STRING ", " LZO_VERSION_DATE " $\n" + "$Info: " LZO_INFO_STRING " $\n"; +#endif + +LZO_PUBLIC(const lzo_bytep) +lzo_copyright(void) +{ +#if (LZO_OS_DOS16 && LZO_CC_TURBOC) + return (lzo_voidp) __lzo_copyright; +#else + return (const lzo_bytep) __lzo_copyright; +#endif +} + +LZO_PUBLIC(unsigned) +lzo_version(void) +{ + return LZO_VERSION; +} + +LZO_PUBLIC(const char *) +lzo_version_string(void) +{ + return LZO_VERSION_STRING; +} + +LZO_PUBLIC(const char *) +lzo_version_date(void) +{ + return LZO_VERSION_DATE; +} + +LZO_PUBLIC(const lzo_charp) +_lzo_version_string(void) +{ + return LZO_VERSION_STRING; +} + +LZO_PUBLIC(const lzo_charp) +_lzo_version_date(void) +{ + return LZO_VERSION_DATE; +} + +#define LZO_BASE 65521u +#define LZO_NMAX 5552 + +#define LZO_DO1(buf,i) s1 += buf[i]; s2 += s1 +#define LZO_DO2(buf,i) LZO_DO1(buf,i); LZO_DO1(buf,i+1); +#define LZO_DO4(buf,i) LZO_DO2(buf,i); LZO_DO2(buf,i+2); +#define LZO_DO8(buf,i) LZO_DO4(buf,i); LZO_DO4(buf,i+4); +#define LZO_DO16(buf,i) LZO_DO8(buf,i); LZO_DO8(buf,i+8); + +LZO_PUBLIC(lzo_uint32) +lzo_adler32(lzo_uint32 adler, const lzo_bytep buf, lzo_uint len) +{ + lzo_uint32 s1 = adler & 0xffff; + lzo_uint32 s2 = (adler >> 16) & 0xffff; + unsigned k; + + if (buf == NULL) + return 1; + + while (len > 0) + { + k = len < LZO_NMAX ? (unsigned) len : LZO_NMAX; + len -= k; + if (k >= 16) do + { + LZO_DO16(buf,0); + buf += 16; + k -= 16; + } while (k >= 16); + if (k != 0) do + { + s1 += *buf++; + s2 += s1; + } while (--k > 0); + s1 %= LZO_BASE; + s2 %= LZO_BASE; + } + return (s2 << 16) | s1; +} + +#undef LZO_DO1 +#undef LZO_DO2 +#undef LZO_DO4 +#undef LZO_DO8 +#undef LZO_DO16 + +#endif +#if !defined(MINILZO_CFG_SKIP_LZO_STRING) +#undef lzo_memcmp +#undef lzo_memcpy +#undef lzo_memmove +#undef lzo_memset +#if !defined(__LZO_MMODEL_HUGE) +# undef LZO_HAVE_MM_HUGE_PTR +#endif +#define lzo_hsize_t lzo_uint +#define lzo_hvoid_p lzo_voidp +#define lzo_hbyte_p lzo_bytep +#define LZOLIB_PUBLIC(r,f) LZO_PUBLIC(r) f +#define lzo_hmemcmp lzo_memcmp +#define lzo_hmemcpy lzo_memcpy +#define lzo_hmemmove lzo_memmove +#define lzo_hmemset lzo_memset +#define __LZOLIB_HMEMCPY_CH_INCLUDED 1 +#if !defined(LZOLIB_PUBLIC) +# define LZOLIB_PUBLIC(r,f) r __LZOLIB_FUNCNAME(f) +#endif +LZOLIB_PUBLIC(int, lzo_hmemcmp) (const lzo_hvoid_p s1, const lzo_hvoid_p s2, lzo_hsize_t len) +{ +#if (LZO_HAVE_MM_HUGE_PTR) || !(HAVE_MEMCMP) + const lzo_hbyte_p p1 = (const lzo_hbyte_p) s1; + const lzo_hbyte_p p2 = (const lzo_hbyte_p) s2; + if __lzo_likely(len > 0) do + { + int d = *p1 - *p2; + if (d != 0) + return d; + p1++; p2++; + } while __lzo_likely(--len > 0); + return 0; +#else + return memcmp(s1, s2, len); +#endif +} +LZOLIB_PUBLIC(lzo_hvoid_p, lzo_hmemcpy) (lzo_hvoid_p dest, const lzo_hvoid_p src, lzo_hsize_t len) +{ +#if (LZO_HAVE_MM_HUGE_PTR) || !(HAVE_MEMCPY) + lzo_hbyte_p p1 = (lzo_hbyte_p) dest; + const lzo_hbyte_p p2 = (const lzo_hbyte_p) src; + if (!(len > 0) || p1 == p2) + return dest; + do + *p1++ = *p2++; + while __lzo_likely(--len > 0); + return dest; +#else + return memcpy(dest, src, len); +#endif +} +LZOLIB_PUBLIC(lzo_hvoid_p, lzo_hmemmove) (lzo_hvoid_p dest, const lzo_hvoid_p src, lzo_hsize_t len) +{ +#if (LZO_HAVE_MM_HUGE_PTR) || !(HAVE_MEMMOVE) + lzo_hbyte_p p1 = (lzo_hbyte_p) dest; + const lzo_hbyte_p p2 = (const lzo_hbyte_p) src; + if (!(len > 0) || p1 == p2) + return dest; + if (p1 < p2) + { + do + *p1++ = *p2++; + while __lzo_likely(--len > 0); + } + else + { + p1 += len; + p2 += len; + do + *--p1 = *--p2; + while __lzo_likely(--len > 0); + } + return dest; +#else + return memmove(dest, src, len); +#endif +} +LZOLIB_PUBLIC(lzo_hvoid_p, lzo_hmemset) (lzo_hvoid_p s, int c, lzo_hsize_t len) +{ +#if (LZO_HAVE_MM_HUGE_PTR) || !(HAVE_MEMSET) + lzo_hbyte_p p = (lzo_hbyte_p) s; + if __lzo_likely(len > 0) do + *p++ = (unsigned char) c; + while __lzo_likely(--len > 0); + return s; +#else + return memset(s, c, len); +#endif +} +#undef LZOLIB_PUBLIC +#endif +#if !defined(MINILZO_CFG_SKIP_LZO_INIT) + +#if !defined(__LZO_IN_MINILZO) + +#define ACC_WANT_ACC_CHK_CH 1 +#undef ACCCHK_ASSERT + + ACCCHK_ASSERT_IS_SIGNED_T(lzo_int) + ACCCHK_ASSERT_IS_UNSIGNED_T(lzo_uint) + + ACCCHK_ASSERT_IS_SIGNED_T(lzo_int32) + ACCCHK_ASSERT_IS_UNSIGNED_T(lzo_uint32) + ACCCHK_ASSERT((LZO_UINT32_C(1) << (int)(8*sizeof(LZO_UINT32_C(1))-1)) > 0) + ACCCHK_ASSERT(sizeof(lzo_uint32) >= 4) +#if defined(LZO_UINT64_MAX) + ACCCHK_ASSERT(sizeof(lzo_uint64) == 8) + ACCCHK_ASSERT_IS_SIGNED_T(lzo_int64) + ACCCHK_ASSERT_IS_UNSIGNED_T(lzo_uint64) +#endif + +#if !defined(__LZO_UINTPTR_T_IS_POINTER) + ACCCHK_ASSERT_IS_UNSIGNED_T(lzo_uintptr_t) +#endif + ACCCHK_ASSERT(sizeof(lzo_uintptr_t) >= sizeof(lzo_voidp)) + + ACCCHK_ASSERT_IS_UNSIGNED_T(lzo_xint) + ACCCHK_ASSERT(sizeof(lzo_xint) >= sizeof(lzo_uint32)) + ACCCHK_ASSERT(sizeof(lzo_xint) >= sizeof(lzo_uint)) + ACCCHK_ASSERT(sizeof(lzo_xint) == sizeof(lzo_uint32) || sizeof(lzo_xint) == sizeof(lzo_uint)) + +#endif +#undef ACCCHK_ASSERT + +#if 0 +#define WANT_lzo_bitops_clz32 1 +#define WANT_lzo_bitops_clz64 1 +#endif +#define WANT_lzo_bitops_ctz32 1 +#define WANT_lzo_bitops_ctz64 1 + +#if (defined(_WIN32) || defined(_WIN64)) && ((LZO_CC_INTELC && (__INTEL_COMPILER >= 1000)) || (LZO_CC_MSC && (_MSC_VER >= 1400))) +#include +#if !defined(lzo_bitops_clz32) && defined(WANT_lzo_bitops_clz32) && 0 +#pragma intrinsic(_BitScanReverse) +static __lzo_inline unsigned lzo_bitops_clz32(lzo_uint32 v) +{ + unsigned long r; + (void) _BitScanReverse(&r, v); + return (unsigned) r; +} +#define lzo_bitops_clz32 lzo_bitops_clz32 +#endif +#if !defined(lzo_bitops_clz64) && defined(WANT_lzo_bitops_clz64) && defined(LZO_UINT64_MAX) && 0 +#pragma intrinsic(_BitScanReverse64) +static __lzo_inline unsigned lzo_bitops_clz64(lzo_uint64 v) +{ + unsigned long r; + (void) _BitScanReverse64(&r, v); + return (unsigned) r; +} +#define lzo_bitops_clz64 lzo_bitops_clz64 +#endif +#if !defined(lzo_bitops_ctz32) && defined(WANT_lzo_bitops_ctz32) +#pragma intrinsic(_BitScanForward) +static __lzo_inline unsigned lzo_bitops_ctz32(lzo_uint32 v) +{ + unsigned long r; + (void) _BitScanForward(&r, v); + return (unsigned) r; +} +#define lzo_bitops_ctz32 lzo_bitops_ctz32 +#endif +#if !defined(lzo_bitops_ctz64) && defined(WANT_lzo_bitops_ctz64) && defined(LZO_UINT64_MAX) +#pragma intrinsic(_BitScanForward64) +static __lzo_inline unsigned lzo_bitops_ctz64(lzo_uint64 v) +{ + unsigned long r; + (void) _BitScanForward64(&r, v); + return (unsigned) r; +} +#define lzo_bitops_ctz64 lzo_bitops_ctz64 +#endif + +#elif (LZO_CC_CLANG || (LZO_CC_GNUC >= 0x030400ul) || (LZO_CC_INTELC && (__INTEL_COMPILER >= 1000)) || LZO_CC_LLVM) +#if !defined(lzo_bitops_clz32) && defined(WANT_lzo_bitops_clz32) +#define lzo_bitops_clz32(v) ((unsigned) __builtin_clz(v)) +#endif +#if !defined(lzo_bitops_clz64) && defined(WANT_lzo_bitops_clz64) && defined(LZO_UINT64_MAX) +#define lzo_bitops_clz64(v) ((unsigned) __builtin_clzll(v)) +#endif +#if !defined(lzo_bitops_ctz32) && defined(WANT_lzo_bitops_ctz32) +#define lzo_bitops_ctz32(v) ((unsigned) __builtin_ctz(v)) +#endif +#if !defined(lzo_bitops_ctz64) && defined(WANT_lzo_bitops_ctz64) && defined(LZO_UINT64_MAX) +#define lzo_bitops_ctz64(v) ((unsigned) __builtin_ctzll(v)) +#endif +#if !defined(lzo_bitops_popcount32) && defined(WANT_lzo_bitops_popcount32) +#define lzo_bitops_popcount32(v) ((unsigned) __builtin_popcount(v)) +#endif +#if !defined(lzo_bitops_popcount32) && defined(WANT_lzo_bitops_popcount64) && defined(LZO_UINT64_MAX) +#define lzo_bitops_popcount64(v) ((unsigned) __builtin_popcountll(v)) +#endif +#endif + +#if 0 +#define u2p(ptr,off) ((lzo_voidp) (((lzo_bytep)(lzo_voidp)(ptr)) + (off))) +#else +static __lzo_noinline lzo_voidp u2p(lzo_voidp ptr, lzo_uint off) +{ + return (lzo_voidp) ((lzo_bytep) ptr + off); +} +#endif + +LZO_PUBLIC(int) +_lzo_config_check(void) +{ + lzo_bool r = 1; + union { + lzo_xint a[2]; unsigned char b[2*LZO_MAX(8,sizeof(lzo_xint))]; +#if defined(LZO_UNALIGNED_OK_8) + lzo_uint64 c[2]; +#endif + unsigned short x[2]; lzo_uint32 y[2]; lzo_uint z[2]; + } u; + lzo_voidp p; + + u.a[0] = u.a[1] = 0; + p = u2p(&u, 0); + r &= ((* (lzo_bytep) p) == 0); +#if !defined(LZO_CFG_NO_CONFIG_CHECK) +#if defined(LZO_ABI_BIG_ENDIAN) + u.a[0] = u.a[1] = 0; u.b[sizeof(lzo_uint) - 1] = 128; + p = u2p(&u, 0); + r &= ((* (lzo_uintp) p) == 128); +#endif +#if defined(LZO_ABI_LITTLE_ENDIAN) + u.a[0] = u.a[1] = 0; u.b[0] = 128; + p = u2p(&u, 0); + r &= ((* (lzo_uintp) p) == 128); +#endif +#if defined(LZO_UNALIGNED_OK_2) + u.a[0] = u.a[1] = 0; + u.b[0] = 1; u.b[sizeof(unsigned short) + 1] = 2; + p = u2p(&u, 1); + r &= ((* (lzo_ushortp) p) == 0); +#endif +#if defined(LZO_UNALIGNED_OK_4) + u.a[0] = u.a[1] = 0; + u.b[0] = 3; u.b[sizeof(lzo_uint32) + 1] = 4; + p = u2p(&u, 1); + r &= ((* (lzo_uint32p) p) == 0); +#endif +#if defined(LZO_UNALIGNED_OK_8) + u.c[0] = u.c[1] = 0; + u.b[0] = 5; u.b[sizeof(lzo_uint64) + 1] = 6; + p = u2p(&u, 1); + r &= ((* (lzo_uint64p) p) == 0); +#endif +#if defined(lzo_bitops_clz32) + { unsigned i; lzo_uint32 v = 1; + for (i = 0; i < 31; i++, v <<= 1) + r &= lzo_bitops_clz32(v) == 31 - i; + } +#endif +#if defined(lzo_bitops_clz64) + { unsigned i; lzo_uint64 v = 1; + for (i = 0; i < 63; i++, v <<= 1) + r &= lzo_bitops_clz64(v) == 63 - i; + } +#endif +#if defined(lzo_bitops_ctz32) + { unsigned i; lzo_uint32 v = 1; + for (i = 0; i < 31; i++, v <<= 1) + r &= lzo_bitops_ctz32(v) == i; + } +#endif +#if defined(lzo_bitops_ctz64) + { unsigned i; lzo_uint64 v = 1; + for (i = 0; i < 63; i++, v <<= 1) + r &= lzo_bitops_ctz64(v) == i; + } +#endif +#endif + + return r == 1 ? LZO_E_OK : LZO_E_ERROR; +} + +LZO_PUBLIC(int) +__lzo_init_v2(unsigned v, int s1, int s2, int s3, int s4, int s5, + int s6, int s7, int s8, int s9) +{ + int r; + +#if defined(__LZO_IN_MINILZO) +#elif (LZO_CC_MSC && ((_MSC_VER) < 700)) +#else +#define ACC_WANT_ACC_CHK_CH 1 +#undef ACCCHK_ASSERT +#define ACCCHK_ASSERT(expr) LZO_COMPILE_TIME_ASSERT(expr) +#endif +#undef ACCCHK_ASSERT + + if (v == 0) + return LZO_E_ERROR; + + r = (s1 == -1 || s1 == (int) sizeof(short)) && + (s2 == -1 || s2 == (int) sizeof(int)) && + (s3 == -1 || s3 == (int) sizeof(long)) && + (s4 == -1 || s4 == (int) sizeof(lzo_uint32)) && + (s5 == -1 || s5 == (int) sizeof(lzo_uint)) && + (s6 == -1 || s6 == (int) lzo_sizeof_dict_t) && + (s7 == -1 || s7 == (int) sizeof(char *)) && + (s8 == -1 || s8 == (int) sizeof(lzo_voidp)) && + (s9 == -1 || s9 == (int) sizeof(lzo_callback_t)); + if (!r) + return LZO_E_ERROR; + + r = _lzo_config_check(); + if (r != LZO_E_OK) + return r; + + return r; +} + +#if !defined(__LZO_IN_MINILZO) + +#if (LZO_OS_WIN16 && LZO_CC_WATCOMC) && defined(__SW_BD) + +#if 0 +BOOL FAR PASCAL LibMain ( HANDLE hInstance, WORD wDataSegment, + WORD wHeapSize, LPSTR lpszCmdLine ) +#else +int __far __pascal LibMain ( int a, short b, short c, long d ) +#endif +{ + LZO_UNUSED(a); LZO_UNUSED(b); LZO_UNUSED(c); LZO_UNUSED(d); + return 1; +} + +#endif + +#endif + +#endif + +#define LZO1X 1 +#define LZO_EOF_CODE 1 +#define M2_MAX_OFFSET 0x0800 + +#if !defined(MINILZO_CFG_SKIP_LZO1X_1_COMPRESS) + +#if 1 && defined(UA_GET32) +#undef LZO_DICT_USE_PTR +#define LZO_DICT_USE_PTR 0 +#undef lzo_dict_t +#define lzo_dict_t unsigned short +#endif + +#define LZO_NEED_DICT_H 1 +#ifndef D_BITS +#define D_BITS 14 +#endif +#define D_INDEX1(d,p) d = DM(DMUL(0x21,DX3(p,5,5,6)) >> 5) +#define D_INDEX2(d,p) d = (d & (D_MASK & 0x7ff)) ^ (D_HIGH | 0x1f) +#if 1 +#define DINDEX(dv,p) DM(((DMUL(0x1824429d,dv)) >> (32-D_BITS))) +#else +#define DINDEX(dv,p) DM((dv) + ((dv) >> (32-D_BITS))) +#endif + +#ifndef __LZO_CONFIG1X_H +#define __LZO_CONFIG1X_H 1 + +#if !defined(LZO1X) && !defined(LZO1Y) && !defined(LZO1Z) +# define LZO1X 1 +#endif + +#if !defined(__LZO_IN_MINILZO) +#include "lzo/lzo1x.h" +#endif + +#ifndef LZO_EOF_CODE +#define LZO_EOF_CODE 1 +#endif +#undef LZO_DETERMINISTIC + +#define M1_MAX_OFFSET 0x0400 +#ifndef M2_MAX_OFFSET +#define M2_MAX_OFFSET 0x0800 +#endif +#define M3_MAX_OFFSET 0x4000 +#define M4_MAX_OFFSET 0xbfff + +#define MX_MAX_OFFSET (M1_MAX_OFFSET + M2_MAX_OFFSET) + +#define M1_MIN_LEN 2 +#define M1_MAX_LEN 2 +#define M2_MIN_LEN 3 +#ifndef M2_MAX_LEN +#define M2_MAX_LEN 8 +#endif +#define M3_MIN_LEN 3 +#define M3_MAX_LEN 33 +#define M4_MIN_LEN 3 +#define M4_MAX_LEN 9 + +#define M1_MARKER 0 +#define M2_MARKER 64 +#define M3_MARKER 32 +#define M4_MARKER 16 + +#ifndef MIN_LOOKAHEAD +#define MIN_LOOKAHEAD (M2_MAX_LEN + 1) +#endif + +#if defined(LZO_NEED_DICT_H) + +#ifndef LZO_HASH +#define LZO_HASH LZO_HASH_LZO_INCREMENTAL_B +#endif +#define DL_MIN_LEN M2_MIN_LEN + +#ifndef __LZO_DICT_H +#define __LZO_DICT_H 1 + +#ifdef __cplusplus +extern "C" { +#endif + +#if !defined(D_BITS) && defined(DBITS) +# define D_BITS DBITS +#endif +#if !defined(D_BITS) +# error "D_BITS is not defined" +#endif +#if (D_BITS < 16) +# define D_SIZE LZO_SIZE(D_BITS) +# define D_MASK LZO_MASK(D_BITS) +#else +# define D_SIZE LZO_USIZE(D_BITS) +# define D_MASK LZO_UMASK(D_BITS) +#endif +#define D_HIGH ((D_MASK >> 1) + 1) + +#if !defined(DD_BITS) +# define DD_BITS 0 +#endif +#define DD_SIZE LZO_SIZE(DD_BITS) +#define DD_MASK LZO_MASK(DD_BITS) + +#if !defined(DL_BITS) +# define DL_BITS (D_BITS - DD_BITS) +#endif +#if (DL_BITS < 16) +# define DL_SIZE LZO_SIZE(DL_BITS) +# define DL_MASK LZO_MASK(DL_BITS) +#else +# define DL_SIZE LZO_USIZE(DL_BITS) +# define DL_MASK LZO_UMASK(DL_BITS) +#endif + +#if (D_BITS != DL_BITS + DD_BITS) +# error "D_BITS does not match" +#endif +#if (D_BITS < 6 || D_BITS > 18) +# error "invalid D_BITS" +#endif +#if (DL_BITS < 6 || DL_BITS > 20) +# error "invalid DL_BITS" +#endif +#if (DD_BITS < 0 || DD_BITS > 6) +# error "invalid DD_BITS" +#endif + +#if !defined(DL_MIN_LEN) +# define DL_MIN_LEN 3 +#endif +#if !defined(DL_SHIFT) +# define DL_SHIFT ((DL_BITS + (DL_MIN_LEN - 1)) / DL_MIN_LEN) +#endif + +#define LZO_HASH_GZIP 1 +#define LZO_HASH_GZIP_INCREMENTAL 2 +#define LZO_HASH_LZO_INCREMENTAL_A 3 +#define LZO_HASH_LZO_INCREMENTAL_B 4 + +#if !defined(LZO_HASH) +# error "choose a hashing strategy" +#endif + +#undef DM +#undef DX + +#if (DL_MIN_LEN == 3) +# define _DV2_A(p,shift1,shift2) \ + (((( (lzo_xint)((p)[0]) << shift1) ^ (p)[1]) << shift2) ^ (p)[2]) +# define _DV2_B(p,shift1,shift2) \ + (((( (lzo_xint)((p)[2]) << shift1) ^ (p)[1]) << shift2) ^ (p)[0]) +# define _DV3_B(p,shift1,shift2,shift3) \ + ((_DV2_B((p)+1,shift1,shift2) << (shift3)) ^ (p)[0]) +#elif (DL_MIN_LEN == 2) +# define _DV2_A(p,shift1,shift2) \ + (( (lzo_xint)(p[0]) << shift1) ^ p[1]) +# define _DV2_B(p,shift1,shift2) \ + (( (lzo_xint)(p[1]) << shift1) ^ p[2]) +#else +# error "invalid DL_MIN_LEN" +#endif +#define _DV_A(p,shift) _DV2_A(p,shift,shift) +#define _DV_B(p,shift) _DV2_B(p,shift,shift) +#define DA2(p,s1,s2) \ + (((((lzo_xint)((p)[2]) << (s2)) + (p)[1]) << (s1)) + (p)[0]) +#define DS2(p,s1,s2) \ + (((((lzo_xint)((p)[2]) << (s2)) - (p)[1]) << (s1)) - (p)[0]) +#define DX2(p,s1,s2) \ + (((((lzo_xint)((p)[2]) << (s2)) ^ (p)[1]) << (s1)) ^ (p)[0]) +#define DA3(p,s1,s2,s3) ((DA2((p)+1,s2,s3) << (s1)) + (p)[0]) +#define DS3(p,s1,s2,s3) ((DS2((p)+1,s2,s3) << (s1)) - (p)[0]) +#define DX3(p,s1,s2,s3) ((DX2((p)+1,s2,s3) << (s1)) ^ (p)[0]) +#define DMS(v,s) ((lzo_uint) (((v) & (D_MASK >> (s))) << (s))) +#define DM(v) DMS(v,0) + +#if (LZO_HASH == LZO_HASH_GZIP) +# define _DINDEX(dv,p) (_DV_A((p),DL_SHIFT)) + +#elif (LZO_HASH == LZO_HASH_GZIP_INCREMENTAL) +# define __LZO_HASH_INCREMENTAL 1 +# define DVAL_FIRST(dv,p) dv = _DV_A((p),DL_SHIFT) +# define DVAL_NEXT(dv,p) dv = (((dv) << DL_SHIFT) ^ p[2]) +# define _DINDEX(dv,p) (dv) +# define DVAL_LOOKAHEAD DL_MIN_LEN + +#elif (LZO_HASH == LZO_HASH_LZO_INCREMENTAL_A) +# define __LZO_HASH_INCREMENTAL 1 +# define DVAL_FIRST(dv,p) dv = _DV_A((p),5) +# define DVAL_NEXT(dv,p) \ + dv ^= (lzo_xint)(p[-1]) << (2*5); dv = (((dv) << 5) ^ p[2]) +# define _DINDEX(dv,p) ((DMUL(0x9f5f,dv)) >> 5) +# define DVAL_LOOKAHEAD DL_MIN_LEN + +#elif (LZO_HASH == LZO_HASH_LZO_INCREMENTAL_B) +# define __LZO_HASH_INCREMENTAL 1 +# define DVAL_FIRST(dv,p) dv = _DV_B((p),5) +# define DVAL_NEXT(dv,p) \ + dv ^= p[-1]; dv = (((dv) >> 5) ^ ((lzo_xint)(p[2]) << (2*5))) +# define _DINDEX(dv,p) ((DMUL(0x9f5f,dv)) >> 5) +# define DVAL_LOOKAHEAD DL_MIN_LEN + +#else +# error "choose a hashing strategy" +#endif + +#ifndef DINDEX +#define DINDEX(dv,p) ((lzo_uint)((_DINDEX(dv,p)) & DL_MASK) << DD_BITS) +#endif +#if !defined(DINDEX1) && defined(D_INDEX1) +#define DINDEX1 D_INDEX1 +#endif +#if !defined(DINDEX2) && defined(D_INDEX2) +#define DINDEX2 D_INDEX2 +#endif + +#if !defined(__LZO_HASH_INCREMENTAL) +# define DVAL_FIRST(dv,p) ((void) 0) +# define DVAL_NEXT(dv,p) ((void) 0) +# define DVAL_LOOKAHEAD 0 +#endif + +#if !defined(DVAL_ASSERT) +#if defined(__LZO_HASH_INCREMENTAL) && !defined(NDEBUG) +#if (LZO_CC_CLANG || (LZO_CC_GNUC >= 0x020700ul) || LZO_CC_LLVM) +static void __attribute__((__unused__)) +#else +static void +#endif +DVAL_ASSERT(lzo_xint dv, const lzo_bytep p) +{ + lzo_xint df; + DVAL_FIRST(df,(p)); + assert(DINDEX(dv,p) == DINDEX(df,p)); +} +#else +# define DVAL_ASSERT(dv,p) ((void) 0) +#endif +#endif + +#if (LZO_DICT_USE_PTR) +# define DENTRY(p,in) (p) +# define GINDEX(m_pos,m_off,dict,dindex,in) m_pos = dict[dindex] +#else +# define DENTRY(p,in) ((lzo_dict_t) pd(p, in)) +# define GINDEX(m_pos,m_off,dict,dindex,in) m_off = dict[dindex] +#endif + +#if (DD_BITS == 0) + +# define UPDATE_D(dict,drun,dv,p,in) dict[ DINDEX(dv,p) ] = DENTRY(p,in) +# define UPDATE_I(dict,drun,index,p,in) dict[index] = DENTRY(p,in) +# define UPDATE_P(ptr,drun,p,in) (ptr)[0] = DENTRY(p,in) + +#else + +# define UPDATE_D(dict,drun,dv,p,in) \ + dict[ DINDEX(dv,p) + drun++ ] = DENTRY(p,in); drun &= DD_MASK +# define UPDATE_I(dict,drun,index,p,in) \ + dict[ (index) + drun++ ] = DENTRY(p,in); drun &= DD_MASK +# define UPDATE_P(ptr,drun,p,in) \ + (ptr) [ drun++ ] = DENTRY(p,in); drun &= DD_MASK + +#endif + +#if (LZO_DICT_USE_PTR) + +#define LZO_CHECK_MPOS_DET(m_pos,m_off,in,ip,max_offset) \ + (m_pos == NULL || (m_off = pd(ip, m_pos)) > max_offset) + +#define LZO_CHECK_MPOS_NON_DET(m_pos,m_off,in,ip,max_offset) \ + (BOUNDS_CHECKING_OFF_IN_EXPR(( \ + m_pos = ip - (lzo_uint) PTR_DIFF(ip,m_pos), \ + PTR_LT(m_pos,in) || \ + (m_off = (lzo_uint) PTR_DIFF(ip,m_pos)) == 0 || \ + m_off > max_offset ))) + +#else + +#define LZO_CHECK_MPOS_DET(m_pos,m_off,in,ip,max_offset) \ + (m_off == 0 || \ + ((m_off = pd(ip, in) - m_off) > max_offset) || \ + (m_pos = (ip) - (m_off), 0) ) + +#define LZO_CHECK_MPOS_NON_DET(m_pos,m_off,in,ip,max_offset) \ + (pd(ip, in) <= m_off || \ + ((m_off = pd(ip, in) - m_off) > max_offset) || \ + (m_pos = (ip) - (m_off), 0) ) + +#endif + +#if (LZO_DETERMINISTIC) +# define LZO_CHECK_MPOS LZO_CHECK_MPOS_DET +#else +# define LZO_CHECK_MPOS LZO_CHECK_MPOS_NON_DET +#endif + +#ifdef __cplusplus +} +#endif + +#endif + +#endif + +#endif + +#define LZO_DETERMINISTIC !(LZO_DICT_USE_PTR) + +#ifndef DO_COMPRESS +#define DO_COMPRESS lzo1x_1_compress +#endif + +#if 1 && defined(DO_COMPRESS) && !defined(do_compress) +# define do_compress LZO_CPP_ECONCAT2(DO_COMPRESS,_core) +#endif + +#if defined(UA_GET64) +# define WANT_lzo_bitops_ctz64 1 +#elif defined(UA_GET32) +# define WANT_lzo_bitops_ctz32 1 +#endif + +#if (defined(_WIN32) || defined(_WIN64)) && ((LZO_CC_INTELC && (__INTEL_COMPILER >= 1000)) || (LZO_CC_MSC && (_MSC_VER >= 1400))) +#include +#if !defined(lzo_bitops_clz32) && defined(WANT_lzo_bitops_clz32) && 0 +#pragma intrinsic(_BitScanReverse) +static __lzo_inline unsigned lzo_bitops_clz32(lzo_uint32 v) +{ + unsigned long r; + (void) _BitScanReverse(&r, v); + return (unsigned) r; +} +#define lzo_bitops_clz32 lzo_bitops_clz32 +#endif +#if !defined(lzo_bitops_clz64) && defined(WANT_lzo_bitops_clz64) && defined(LZO_UINT64_MAX) && 0 +#pragma intrinsic(_BitScanReverse64) +static __lzo_inline unsigned lzo_bitops_clz64(lzo_uint64 v) +{ + unsigned long r; + (void) _BitScanReverse64(&r, v); + return (unsigned) r; +} +#define lzo_bitops_clz64 lzo_bitops_clz64 +#endif +#if !defined(lzo_bitops_ctz32) && defined(WANT_lzo_bitops_ctz32) +#pragma intrinsic(_BitScanForward) +static __lzo_inline unsigned lzo_bitops_ctz32(lzo_uint32 v) +{ + unsigned long r; + (void) _BitScanForward(&r, v); + return (unsigned) r; +} +#define lzo_bitops_ctz32 lzo_bitops_ctz32 +#endif +#if !defined(lzo_bitops_ctz64) && defined(WANT_lzo_bitops_ctz64) && defined(LZO_UINT64_MAX) +#pragma intrinsic(_BitScanForward64) +static __lzo_inline unsigned lzo_bitops_ctz64(lzo_uint64 v) +{ + unsigned long r; + (void) _BitScanForward64(&r, v); + return (unsigned) r; +} +#define lzo_bitops_ctz64 lzo_bitops_ctz64 +#endif + +#elif (LZO_CC_CLANG || (LZO_CC_GNUC >= 0x030400ul) || (LZO_CC_INTELC && (__INTEL_COMPILER >= 1000)) || LZO_CC_LLVM) +#if !defined(lzo_bitops_clz32) && defined(WANT_lzo_bitops_clz32) +#define lzo_bitops_clz32(v) ((unsigned) __builtin_clz(v)) +#endif +#if !defined(lzo_bitops_clz64) && defined(WANT_lzo_bitops_clz64) && defined(LZO_UINT64_MAX) +#define lzo_bitops_clz64(v) ((unsigned) __builtin_clzll(v)) +#endif +#if !defined(lzo_bitops_ctz32) && defined(WANT_lzo_bitops_ctz32) +#define lzo_bitops_ctz32(v) ((unsigned) __builtin_ctz(v)) +#endif +#if !defined(lzo_bitops_ctz64) && defined(WANT_lzo_bitops_ctz64) && defined(LZO_UINT64_MAX) +#define lzo_bitops_ctz64(v) ((unsigned) __builtin_ctzll(v)) +#endif +#if !defined(lzo_bitops_popcount32) && defined(WANT_lzo_bitops_popcount32) +#define lzo_bitops_popcount32(v) ((unsigned) __builtin_popcount(v)) +#endif +#if !defined(lzo_bitops_popcount32) && defined(WANT_lzo_bitops_popcount64) && defined(LZO_UINT64_MAX) +#define lzo_bitops_popcount64(v) ((unsigned) __builtin_popcountll(v)) +#endif +#endif + +static __lzo_noinline lzo_uint +do_compress ( const lzo_bytep in , lzo_uint in_len, + lzo_bytep out, lzo_uintp out_len, + lzo_uint ti, lzo_voidp wrkmem) +{ + register const lzo_bytep ip; + lzo_bytep op; + const lzo_bytep const in_end = in + in_len; + const lzo_bytep const ip_end = in + in_len - 20; + const lzo_bytep ii; + lzo_dict_p const dict = (lzo_dict_p) wrkmem; + + op = out; + ip = in; + ii = ip - ti; + + ip += ti < 4 ? 4 - ti : 0; + for (;;) + { + const lzo_bytep m_pos; +#if !(LZO_DETERMINISTIC) + LZO_DEFINE_UNINITIALIZED_VAR(lzo_uint, m_off, 0); + lzo_uint m_len; + lzo_uint dindex; +next: + if __lzo_unlikely(ip >= ip_end) + break; + DINDEX1(dindex,ip); + GINDEX(m_pos,m_off,dict,dindex,in); + if (LZO_CHECK_MPOS_NON_DET(m_pos,m_off,in,ip,M4_MAX_OFFSET)) + goto literal; +#if 1 + if (m_off <= M2_MAX_OFFSET || m_pos[3] == ip[3]) + goto try_match; + DINDEX2(dindex,ip); +#endif + GINDEX(m_pos,m_off,dict,dindex,in); + if (LZO_CHECK_MPOS_NON_DET(m_pos,m_off,in,ip,M4_MAX_OFFSET)) + goto literal; + if (m_off <= M2_MAX_OFFSET || m_pos[3] == ip[3]) + goto try_match; + goto literal; + +try_match: +#if defined(UA_GET32) + if (UA_GET32(m_pos) != UA_GET32(ip)) +#else + if (m_pos[0] != ip[0] || m_pos[1] != ip[1] || m_pos[2] != ip[2] || m_pos[3] != ip[3]) +#endif + { +literal: + UPDATE_I(dict,0,dindex,ip,in); + ip += 1 + ((ip - ii) >> 5); + continue; + } + UPDATE_I(dict,0,dindex,ip,in); +#else + lzo_uint m_off; + lzo_uint m_len; + { + lzo_uint32 dv; + lzo_uint dindex; +literal: + ip += 1 + ((ip - ii) >> 5); +next: + if __lzo_unlikely(ip >= ip_end) + break; + dv = UA_GET32(ip); + dindex = DINDEX(dv,ip); + GINDEX(m_off,m_pos,in+dict,dindex,in); + UPDATE_I(dict,0,dindex,ip,in); + if __lzo_unlikely(dv != UA_GET32(m_pos)) + goto literal; + } +#endif + + { + register lzo_uint t = pd(ip,ii); + if (t != 0) + { + if (t <= 3) + { + op[-2] |= LZO_BYTE(t); +#if defined(UA_COPY32) + UA_COPY32(op, ii); + op += t; +#else + { do *op++ = *ii++; while (--t > 0); } +#endif + } +#if defined(UA_COPY32) || defined(UA_COPY64) + else if (t <= 16) + { + *op++ = LZO_BYTE(t - 3); +#if defined(UA_COPY64) + UA_COPY64(op, ii); + UA_COPY64(op+8, ii+8); +#else + UA_COPY32(op, ii); + UA_COPY32(op+4, ii+4); + UA_COPY32(op+8, ii+8); + UA_COPY32(op+12, ii+12); +#endif + op += t; + } +#endif + else + { + if (t <= 18) + *op++ = LZO_BYTE(t - 3); + else + { + register lzo_uint tt = t - 18; + *op++ = 0; + while __lzo_unlikely(tt > 255) + { + tt -= 255; +#if 1 && (LZO_CC_MSC && (_MSC_VER >= 1400)) + * (volatile unsigned char *) op++ = 0; +#else + *op++ = 0; +#endif + } + assert(tt > 0); + *op++ = LZO_BYTE(tt); + } +#if defined(UA_COPY32) || defined(UA_COPY64) + do { +#if defined(UA_COPY64) + UA_COPY64(op, ii); + UA_COPY64(op+8, ii+8); +#else + UA_COPY32(op, ii); + UA_COPY32(op+4, ii+4); + UA_COPY32(op+8, ii+8); + UA_COPY32(op+12, ii+12); +#endif + op += 16; ii += 16; t -= 16; + } while (t >= 16); if (t > 0) +#endif + { do *op++ = *ii++; while (--t > 0); } + } + } + } + m_len = 4; + { +#if defined(UA_GET64) + lzo_uint64 v; + v = UA_GET64(ip + m_len) ^ UA_GET64(m_pos + m_len); + if __lzo_unlikely(v == 0) { + do { + m_len += 8; + v = UA_GET64(ip + m_len) ^ UA_GET64(m_pos + m_len); + if __lzo_unlikely(ip + m_len >= ip_end) + goto m_len_done; + } while (v == 0); + } +#if (LZO_ABI_LITTLE_ENDIAN) && defined(lzo_bitops_ctz64) + m_len += lzo_bitops_ctz64(v) / CHAR_BIT; +#elif (LZO_ABI_LITTLE_ENDIAN) + if ((v & UCHAR_MAX) == 0) do { + v >>= CHAR_BIT; + m_len += 1; + } while ((v & UCHAR_MAX) == 0); +#else + if (ip[m_len] == m_pos[m_len]) do { + m_len += 1; + } while (ip[m_len] == m_pos[m_len]); +#endif +#elif defined(UA_GET32) + lzo_uint32 v; + v = UA_GET32(ip + m_len) ^ UA_GET32(m_pos + m_len); + if __lzo_unlikely(v == 0) { + do { + m_len += 4; + v = UA_GET32(ip + m_len) ^ UA_GET32(m_pos + m_len); + if __lzo_unlikely(ip + m_len >= ip_end) + goto m_len_done; + } while (v == 0); + } +#if (LZO_ABI_LITTLE_ENDIAN) && defined(lzo_bitops_ctz32) + m_len += lzo_bitops_ctz32(v) / CHAR_BIT; +#elif (LZO_ABI_LITTLE_ENDIAN) + if ((v & UCHAR_MAX) == 0) do { + v >>= CHAR_BIT; + m_len += 1; + } while ((v & UCHAR_MAX) == 0); +#else + if (ip[m_len] == m_pos[m_len]) do { + m_len += 1; + } while (ip[m_len] == m_pos[m_len]); +#endif +#else + if __lzo_unlikely(ip[m_len] == m_pos[m_len]) { + do { + m_len += 1; + if __lzo_unlikely(ip + m_len >= ip_end) + goto m_len_done; + } while (ip[m_len] == m_pos[m_len]); + } +#endif + } +m_len_done: + m_off = pd(ip,m_pos); + ip += m_len; + ii = ip; + if (m_len <= M2_MAX_LEN && m_off <= M2_MAX_OFFSET) + { + m_off -= 1; +#if defined(LZO1X) + *op++ = LZO_BYTE(((m_len - 1) << 5) | ((m_off & 7) << 2)); + *op++ = LZO_BYTE(m_off >> 3); +#elif defined(LZO1Y) + *op++ = LZO_BYTE(((m_len + 1) << 4) | ((m_off & 3) << 2)); + *op++ = LZO_BYTE(m_off >> 2); +#endif + } + else if (m_off <= M3_MAX_OFFSET) + { + m_off -= 1; + if (m_len <= M3_MAX_LEN) + *op++ = LZO_BYTE(M3_MARKER | (m_len - 2)); + else + { + m_len -= M3_MAX_LEN; + *op++ = M3_MARKER | 0; + while __lzo_unlikely(m_len > 255) + { + m_len -= 255; +#if 1 && (LZO_CC_MSC && (_MSC_VER >= 1400)) + * (volatile unsigned char *) op++ = 0; +#else + *op++ = 0; +#endif + } + *op++ = LZO_BYTE(m_len); + } + *op++ = LZO_BYTE(m_off << 2); + *op++ = LZO_BYTE(m_off >> 6); + } + else + { + m_off -= 0x4000; + if (m_len <= M4_MAX_LEN) + *op++ = LZO_BYTE(M4_MARKER | ((m_off >> 11) & 8) | (m_len - 2)); + else + { + m_len -= M4_MAX_LEN; + *op++ = LZO_BYTE(M4_MARKER | ((m_off >> 11) & 8)); + while __lzo_unlikely(m_len > 255) + { + m_len -= 255; +#if 1 && (LZO_CC_MSC && (_MSC_VER >= 1400)) + * (volatile unsigned char *) op++ = 0; +#else + *op++ = 0; +#endif + } + *op++ = LZO_BYTE(m_len); + } + *op++ = LZO_BYTE(m_off << 2); + *op++ = LZO_BYTE(m_off >> 6); + } + goto next; + } + + *out_len = pd(op, out); + return pd(in_end,ii); +} + +LZO_PUBLIC(int) +DO_COMPRESS ( const lzo_bytep in , lzo_uint in_len, + lzo_bytep out, lzo_uintp out_len, + lzo_voidp wrkmem ) +{ + const lzo_bytep ip = in; + lzo_bytep op = out; + lzo_uint l = in_len; + lzo_uint t = 0; + + while (l > 20) + { + lzo_uint ll = l; + lzo_uintptr_t ll_end; +#if 0 || (LZO_DETERMINISTIC) + ll = LZO_MIN(ll, 49152); +#endif + ll_end = (lzo_uintptr_t)ip + ll; + if ((ll_end + ((t + ll) >> 5)) <= ll_end || (const lzo_bytep)(ll_end + ((t + ll) >> 5)) <= ip + ll) + break; +#if (LZO_DETERMINISTIC) + lzo_memset(wrkmem, 0, ((lzo_uint)1 << D_BITS) * sizeof(lzo_dict_t)); +#endif + t = do_compress(ip,ll,op,out_len,t,wrkmem); + ip += ll; + op += *out_len; + l -= ll; + } + t += l; + + if (t > 0) + { + const lzo_bytep ii = in + in_len - t; + + if (op == out && t <= 238) + *op++ = LZO_BYTE(17 + t); + else if (t <= 3) + op[-2] |= LZO_BYTE(t); + else if (t <= 18) + *op++ = LZO_BYTE(t - 3); + else + { + lzo_uint tt = t - 18; + + *op++ = 0; + while (tt > 255) + { + tt -= 255; +#if 1 && (LZO_CC_MSC && (_MSC_VER >= 1400)) + + * (volatile unsigned char *) op++ = 0; +#else + *op++ = 0; +#endif + } + assert(tt > 0); + *op++ = LZO_BYTE(tt); + } + do *op++ = *ii++; while (--t > 0); + } + + *op++ = M4_MARKER | 1; + *op++ = 0; + *op++ = 0; + + *out_len = pd(op, out); + return LZO_E_OK; +} + +#endif + +#undef do_compress +#undef DO_COMPRESS +#undef LZO_HASH + +#undef LZO_TEST_OVERRUN +#undef DO_DECOMPRESS +#define DO_DECOMPRESS lzo1x_decompress + +#if !defined(MINILZO_CFG_SKIP_LZO1X_DECOMPRESS) + +#if defined(LZO_TEST_OVERRUN) +# if !defined(LZO_TEST_OVERRUN_INPUT) +# define LZO_TEST_OVERRUN_INPUT 2 +# endif +# if !defined(LZO_TEST_OVERRUN_OUTPUT) +# define LZO_TEST_OVERRUN_OUTPUT 2 +# endif +# if !defined(LZO_TEST_OVERRUN_LOOKBEHIND) +# define LZO_TEST_OVERRUN_LOOKBEHIND 1 +# endif +#endif + +#undef TEST_IP +#undef TEST_OP +#undef TEST_LB +#undef TEST_LBO +#undef NEED_IP +#undef NEED_OP +#undef HAVE_TEST_IP +#undef HAVE_TEST_OP +#undef HAVE_NEED_IP +#undef HAVE_NEED_OP +#undef HAVE_ANY_IP +#undef HAVE_ANY_OP + +#if defined(LZO_TEST_OVERRUN_INPUT) +# if (LZO_TEST_OVERRUN_INPUT >= 1) +# define TEST_IP (ip < ip_end) +# endif +# if (LZO_TEST_OVERRUN_INPUT >= 2) +# define NEED_IP(x) \ + if ((lzo_uint)(ip_end - ip) < (lzo_uint)(x)) goto input_overrun +# endif +#endif + +#if defined(LZO_TEST_OVERRUN_OUTPUT) +# if (LZO_TEST_OVERRUN_OUTPUT >= 1) +# define TEST_OP (op <= op_end) +# endif +# if (LZO_TEST_OVERRUN_OUTPUT >= 2) +# undef TEST_OP +# define NEED_OP(x) \ + if ((lzo_uint)(op_end - op) < (lzo_uint)(x)) goto output_overrun +# endif +#endif + +#if defined(LZO_TEST_OVERRUN_LOOKBEHIND) +# define TEST_LB(m_pos) if (m_pos < out || m_pos >= op) goto lookbehind_overrun +# define TEST_LBO(m_pos,o) if (m_pos < out || m_pos >= op - (o)) goto lookbehind_overrun +#else +# define TEST_LB(m_pos) ((void) 0) +# define TEST_LBO(m_pos,o) ((void) 0) +#endif + +#if !defined(LZO_EOF_CODE) && !defined(TEST_IP) +# define TEST_IP (ip < ip_end) +#endif + +#if defined(TEST_IP) +# define HAVE_TEST_IP 1 +#else +# define TEST_IP 1 +#endif +#if defined(TEST_OP) +# define HAVE_TEST_OP 1 +#else +# define TEST_OP 1 +#endif + +#if defined(NEED_IP) +# define HAVE_NEED_IP 1 +#else +# define NEED_IP(x) ((void) 0) +#endif +#if defined(NEED_OP) +# define HAVE_NEED_OP 1 +#else +# define NEED_OP(x) ((void) 0) +#endif + +#if defined(HAVE_TEST_IP) || defined(HAVE_NEED_IP) +# define HAVE_ANY_IP 1 +#endif +#if defined(HAVE_TEST_OP) || defined(HAVE_NEED_OP) +# define HAVE_ANY_OP 1 +#endif + +#if defined(DO_DECOMPRESS) +LZO_PUBLIC(int) +DO_DECOMPRESS ( const lzo_bytep in , lzo_uint in_len, + lzo_bytep out, lzo_uintp out_len, + lzo_voidp wrkmem ) +#endif +{ + register lzo_bytep op; + register const lzo_bytep ip; + register lzo_uint t; +#if defined(COPY_DICT) + lzo_uint m_off; + const lzo_bytep dict_end; +#else + register const lzo_bytep m_pos; +#endif + + const lzo_bytep const ip_end = in + in_len; +#if defined(HAVE_ANY_OP) + lzo_bytep const op_end = out + *out_len; +#endif +#if defined(LZO1Z) + lzo_uint last_m_off = 0; +#endif + + LZO_UNUSED(wrkmem); + +#if defined(COPY_DICT) + if (dict) + { + if (dict_len > M4_MAX_OFFSET) + { + dict += dict_len - M4_MAX_OFFSET; + dict_len = M4_MAX_OFFSET; + } + dict_end = dict + dict_len; + } + else + { + dict_len = 0; + dict_end = NULL; + } +#endif + + *out_len = 0; + + op = out; + ip = in; + + if (*ip > 17) + { + t = *ip++ - 17; + if (t < 4) + goto match_next; + assert(t > 0); NEED_OP(t); NEED_IP(t+1); + do *op++ = *ip++; while (--t > 0); + goto first_literal_run; + } + + while (TEST_IP && TEST_OP) + { + t = *ip++; + if (t >= 16) + goto match; + if (t == 0) + { + NEED_IP(1); + while (*ip == 0) + { + t += 255; + ip++; + NEED_IP(1); + } + t += 15 + *ip++; + } + assert(t > 0); NEED_OP(t+3); NEED_IP(t+4); +#if defined(LZO_UNALIGNED_OK_8) && defined(LZO_UNALIGNED_OK_4) + t += 3; + if (t >= 8) do + { + UA_COPY64(op,ip); + op += 8; ip += 8; t -= 8; + } while (t >= 8); + if (t >= 4) + { + UA_COPY32(op,ip); + op += 4; ip += 4; t -= 4; + } + if (t > 0) + { + *op++ = *ip++; + if (t > 1) { *op++ = *ip++; if (t > 2) { *op++ = *ip++; } } + } +#elif defined(LZO_UNALIGNED_OK_4) || defined(LZO_ALIGNED_OK_4) +#if !defined(LZO_UNALIGNED_OK_4) + if (PTR_ALIGNED2_4(op,ip)) + { +#endif + UA_COPY32(op,ip); + op += 4; ip += 4; + if (--t > 0) + { + if (t >= 4) + { + do { + UA_COPY32(op,ip); + op += 4; ip += 4; t -= 4; + } while (t >= 4); + if (t > 0) do *op++ = *ip++; while (--t > 0); + } + else + do *op++ = *ip++; while (--t > 0); + } +#if !defined(LZO_UNALIGNED_OK_4) + } + else +#endif +#endif +#if !defined(LZO_UNALIGNED_OK_4) && !defined(LZO_UNALIGNED_OK_8) + { + *op++ = *ip++; *op++ = *ip++; *op++ = *ip++; + do *op++ = *ip++; while (--t > 0); + } +#endif + +first_literal_run: + + t = *ip++; + if (t >= 16) + goto match; +#if defined(COPY_DICT) +#if defined(LZO1Z) + m_off = (1 + M2_MAX_OFFSET) + (t << 6) + (*ip++ >> 2); + last_m_off = m_off; +#else + m_off = (1 + M2_MAX_OFFSET) + (t >> 2) + (*ip++ << 2); +#endif + NEED_OP(3); + t = 3; COPY_DICT(t,m_off) +#else +#if defined(LZO1Z) + t = (1 + M2_MAX_OFFSET) + (t << 6) + (*ip++ >> 2); + m_pos = op - t; + last_m_off = t; +#else + m_pos = op - (1 + M2_MAX_OFFSET); + m_pos -= t >> 2; + m_pos -= *ip++ << 2; +#endif + TEST_LB(m_pos); NEED_OP(3); + *op++ = *m_pos++; *op++ = *m_pos++; *op++ = *m_pos; +#endif + goto match_done; + + do { +match: + if (t >= 64) + { +#if defined(COPY_DICT) +#if defined(LZO1X) + m_off = 1 + ((t >> 2) & 7) + (*ip++ << 3); + t = (t >> 5) - 1; +#elif defined(LZO1Y) + m_off = 1 + ((t >> 2) & 3) + (*ip++ << 2); + t = (t >> 4) - 3; +#elif defined(LZO1Z) + m_off = t & 0x1f; + if (m_off >= 0x1c) + m_off = last_m_off; + else + { + m_off = 1 + (m_off << 6) + (*ip++ >> 2); + last_m_off = m_off; + } + t = (t >> 5) - 1; +#endif +#else +#if defined(LZO1X) + m_pos = op - 1; + m_pos -= (t >> 2) & 7; + m_pos -= *ip++ << 3; + t = (t >> 5) - 1; +#elif defined(LZO1Y) + m_pos = op - 1; + m_pos -= (t >> 2) & 3; + m_pos -= *ip++ << 2; + t = (t >> 4) - 3; +#elif defined(LZO1Z) + { + lzo_uint off = t & 0x1f; + m_pos = op; + if (off >= 0x1c) + { + assert(last_m_off > 0); + m_pos -= last_m_off; + } + else + { + off = 1 + (off << 6) + (*ip++ >> 2); + m_pos -= off; + last_m_off = off; + } + } + t = (t >> 5) - 1; +#endif + TEST_LB(m_pos); assert(t > 0); NEED_OP(t+3-1); + goto copy_match; +#endif + } + else if (t >= 32) + { + t &= 31; + if (t == 0) + { + NEED_IP(1); + while (*ip == 0) + { + t += 255; + ip++; + NEED_IP(1); + } + t += 31 + *ip++; + } +#if defined(COPY_DICT) +#if defined(LZO1Z) + m_off = 1 + (ip[0] << 6) + (ip[1] >> 2); + last_m_off = m_off; +#else + m_off = 1 + (ip[0] >> 2) + (ip[1] << 6); +#endif +#else +#if defined(LZO1Z) + { + lzo_uint off = 1 + (ip[0] << 6) + (ip[1] >> 2); + m_pos = op - off; + last_m_off = off; + } +#elif defined(LZO_UNALIGNED_OK_2) && defined(LZO_ABI_LITTLE_ENDIAN) + m_pos = op - 1; + m_pos -= UA_GET16(ip) >> 2; +#else + m_pos = op - 1; + m_pos -= (ip[0] >> 2) + (ip[1] << 6); +#endif +#endif + ip += 2; + } + else if (t >= 16) + { +#if defined(COPY_DICT) + m_off = (t & 8) << 11; +#else + m_pos = op; + m_pos -= (t & 8) << 11; +#endif + t &= 7; + if (t == 0) + { + NEED_IP(1); + while (*ip == 0) + { + t += 255; + ip++; + NEED_IP(1); + } + t += 7 + *ip++; + } +#if defined(COPY_DICT) +#if defined(LZO1Z) + m_off += (ip[0] << 6) + (ip[1] >> 2); +#else + m_off += (ip[0] >> 2) + (ip[1] << 6); +#endif + ip += 2; + if (m_off == 0) + goto eof_found; + m_off += 0x4000; +#if defined(LZO1Z) + last_m_off = m_off; +#endif +#else +#if defined(LZO1Z) + m_pos -= (ip[0] << 6) + (ip[1] >> 2); +#elif defined(LZO_UNALIGNED_OK_2) && defined(LZO_ABI_LITTLE_ENDIAN) + m_pos -= UA_GET16(ip) >> 2; +#else + m_pos -= (ip[0] >> 2) + (ip[1] << 6); +#endif + ip += 2; + if (m_pos == op) + goto eof_found; + m_pos -= 0x4000; +#if defined(LZO1Z) + last_m_off = pd((const lzo_bytep)op, m_pos); +#endif +#endif + } + else + { +#if defined(COPY_DICT) +#if defined(LZO1Z) + m_off = 1 + (t << 6) + (*ip++ >> 2); + last_m_off = m_off; +#else + m_off = 1 + (t >> 2) + (*ip++ << 2); +#endif + NEED_OP(2); + t = 2; COPY_DICT(t,m_off) +#else +#if defined(LZO1Z) + t = 1 + (t << 6) + (*ip++ >> 2); + m_pos = op - t; + last_m_off = t; +#else + m_pos = op - 1; + m_pos -= t >> 2; + m_pos -= *ip++ << 2; +#endif + TEST_LB(m_pos); NEED_OP(2); + *op++ = *m_pos++; *op++ = *m_pos; +#endif + goto match_done; + } + +#if defined(COPY_DICT) + + NEED_OP(t+3-1); + t += 3-1; COPY_DICT(t,m_off) + +#else + + TEST_LB(m_pos); assert(t > 0); NEED_OP(t+3-1); +#if defined(LZO_UNALIGNED_OK_8) && defined(LZO_UNALIGNED_OK_4) + if (op - m_pos >= 8) + { + t += (3 - 1); + if (t >= 8) do + { + UA_COPY64(op,m_pos); + op += 8; m_pos += 8; t -= 8; + } while (t >= 8); + if (t >= 4) + { + UA_COPY32(op,m_pos); + op += 4; m_pos += 4; t -= 4; + } + if (t > 0) + { + *op++ = m_pos[0]; + if (t > 1) { *op++ = m_pos[1]; if (t > 2) { *op++ = m_pos[2]; } } + } + } + else +#elif defined(LZO_UNALIGNED_OK_4) || defined(LZO_ALIGNED_OK_4) +#if !defined(LZO_UNALIGNED_OK_4) + if (t >= 2 * 4 - (3 - 1) && PTR_ALIGNED2_4(op,m_pos)) + { + assert((op - m_pos) >= 4); +#else + if (t >= 2 * 4 - (3 - 1) && (op - m_pos) >= 4) + { +#endif + UA_COPY32(op,m_pos); + op += 4; m_pos += 4; t -= 4 - (3 - 1); + do { + UA_COPY32(op,m_pos); + op += 4; m_pos += 4; t -= 4; + } while (t >= 4); + if (t > 0) do *op++ = *m_pos++; while (--t > 0); + } + else +#endif + { +copy_match: + *op++ = *m_pos++; *op++ = *m_pos++; + do *op++ = *m_pos++; while (--t > 0); + } + +#endif + +match_done: +#if defined(LZO1Z) + t = ip[-1] & 3; +#else + t = ip[-2] & 3; +#endif + if (t == 0) + break; + +match_next: + assert(t > 0); assert(t < 4); NEED_OP(t); NEED_IP(t+1); +#if 0 + do *op++ = *ip++; while (--t > 0); +#else + *op++ = *ip++; + if (t > 1) { *op++ = *ip++; if (t > 2) { *op++ = *ip++; } } +#endif + t = *ip++; + } while (TEST_IP && TEST_OP); + } + +#if defined(HAVE_TEST_IP) || defined(HAVE_TEST_OP) + *out_len = pd(op, out); + return LZO_E_EOF_NOT_FOUND; +#endif + +eof_found: + assert(t == 1); + *out_len = pd(op, out); + return (ip == ip_end ? LZO_E_OK : + (ip < ip_end ? LZO_E_INPUT_NOT_CONSUMED : LZO_E_INPUT_OVERRUN)); + +#if defined(HAVE_NEED_IP) +input_overrun: + *out_len = pd(op, out); + return LZO_E_INPUT_OVERRUN; +#endif + +#if defined(HAVE_NEED_OP) +output_overrun: + *out_len = pd(op, out); + return LZO_E_OUTPUT_OVERRUN; +#endif + +#if defined(LZO_TEST_OVERRUN_LOOKBEHIND) +lookbehind_overrun: + *out_len = pd(op, out); + return LZO_E_LOOKBEHIND_OVERRUN; +#endif +} + +#endif + +#define LZO_TEST_OVERRUN 1 +#undef DO_DECOMPRESS +#define DO_DECOMPRESS lzo1x_decompress_safe + +#if !defined(MINILZO_CFG_SKIP_LZO1X_DECOMPRESS_SAFE) + +#if defined(LZO_TEST_OVERRUN) +# if !defined(LZO_TEST_OVERRUN_INPUT) +# define LZO_TEST_OVERRUN_INPUT 2 +# endif +# if !defined(LZO_TEST_OVERRUN_OUTPUT) +# define LZO_TEST_OVERRUN_OUTPUT 2 +# endif +# if !defined(LZO_TEST_OVERRUN_LOOKBEHIND) +# define LZO_TEST_OVERRUN_LOOKBEHIND 1 +# endif +#endif + +#undef TEST_IP +#undef TEST_OP +#undef TEST_LB +#undef TEST_LBO +#undef NEED_IP +#undef NEED_OP +#undef HAVE_TEST_IP +#undef HAVE_TEST_OP +#undef HAVE_NEED_IP +#undef HAVE_NEED_OP +#undef HAVE_ANY_IP +#undef HAVE_ANY_OP + +#if defined(LZO_TEST_OVERRUN_INPUT) +# if (LZO_TEST_OVERRUN_INPUT >= 1) +# define TEST_IP (ip < ip_end) +# endif +# if (LZO_TEST_OVERRUN_INPUT >= 2) +# define NEED_IP(x) \ + if ((lzo_uint)(ip_end - ip) < (lzo_uint)(x)) goto input_overrun +# endif +#endif + +#if defined(LZO_TEST_OVERRUN_OUTPUT) +# if (LZO_TEST_OVERRUN_OUTPUT >= 1) +# define TEST_OP (op <= op_end) +# endif +# if (LZO_TEST_OVERRUN_OUTPUT >= 2) +# undef TEST_OP +# define NEED_OP(x) \ + if ((lzo_uint)(op_end - op) < (lzo_uint)(x)) goto output_overrun +# endif +#endif + +#if defined(LZO_TEST_OVERRUN_LOOKBEHIND) +# define TEST_LB(m_pos) if (m_pos < out || m_pos >= op) goto lookbehind_overrun +# define TEST_LBO(m_pos,o) if (m_pos < out || m_pos >= op - (o)) goto lookbehind_overrun +#else +# define TEST_LB(m_pos) ((void) 0) +# define TEST_LBO(m_pos,o) ((void) 0) +#endif + +#if !defined(LZO_EOF_CODE) && !defined(TEST_IP) +# define TEST_IP (ip < ip_end) +#endif + +#if defined(TEST_IP) +# define HAVE_TEST_IP 1 +#else +# define TEST_IP 1 +#endif +#if defined(TEST_OP) +# define HAVE_TEST_OP 1 +#else +# define TEST_OP 1 +#endif + +#if defined(NEED_IP) +# define HAVE_NEED_IP 1 +#else +# define NEED_IP(x) ((void) 0) +#endif +#if defined(NEED_OP) +# define HAVE_NEED_OP 1 +#else +# define NEED_OP(x) ((void) 0) +#endif + +#if defined(HAVE_TEST_IP) || defined(HAVE_NEED_IP) +# define HAVE_ANY_IP 1 +#endif +#if defined(HAVE_TEST_OP) || defined(HAVE_NEED_OP) +# define HAVE_ANY_OP 1 +#endif + +#if defined(DO_DECOMPRESS) +LZO_PUBLIC(int) +DO_DECOMPRESS ( const lzo_bytep in , lzo_uint in_len, + lzo_bytep out, lzo_uintp out_len, + lzo_voidp wrkmem ) +#endif +{ + register lzo_bytep op; + register const lzo_bytep ip; + register lzo_uint t; +#if defined(COPY_DICT) + lzo_uint m_off; + const lzo_bytep dict_end; +#else + register const lzo_bytep m_pos; +#endif + + const lzo_bytep const ip_end = in + in_len; +#if defined(HAVE_ANY_OP) + lzo_bytep const op_end = out + *out_len; +#endif +#if defined(LZO1Z) + lzo_uint last_m_off = 0; +#endif + + LZO_UNUSED(wrkmem); + +#if defined(COPY_DICT) + if (dict) + { + if (dict_len > M4_MAX_OFFSET) + { + dict += dict_len - M4_MAX_OFFSET; + dict_len = M4_MAX_OFFSET; + } + dict_end = dict + dict_len; + } + else + { + dict_len = 0; + dict_end = NULL; + } +#endif + + *out_len = 0; + + op = out; + ip = in; + + if (*ip > 17) + { + t = *ip++ - 17; + if (t < 4) + goto match_next; + assert(t > 0); NEED_OP(t); NEED_IP(t+1); + do *op++ = *ip++; while (--t > 0); + goto first_literal_run; + } + + while (TEST_IP && TEST_OP) + { + t = *ip++; + if (t >= 16) + goto match; + if (t == 0) + { + NEED_IP(1); + while (*ip == 0) + { + t += 255; + ip++; + NEED_IP(1); + } + t += 15 + *ip++; + } + assert(t > 0); NEED_OP(t+3); NEED_IP(t+4); +#if defined(LZO_UNALIGNED_OK_8) && defined(LZO_UNALIGNED_OK_4) + t += 3; + if (t >= 8) do + { + UA_COPY64(op,ip); + op += 8; ip += 8; t -= 8; + } while (t >= 8); + if (t >= 4) + { + UA_COPY32(op,ip); + op += 4; ip += 4; t -= 4; + } + if (t > 0) + { + *op++ = *ip++; + if (t > 1) { *op++ = *ip++; if (t > 2) { *op++ = *ip++; } } + } +#elif defined(LZO_UNALIGNED_OK_4) || defined(LZO_ALIGNED_OK_4) +#if !defined(LZO_UNALIGNED_OK_4) + if (PTR_ALIGNED2_4(op,ip)) + { +#endif + UA_COPY32(op,ip); + op += 4; ip += 4; + if (--t > 0) + { + if (t >= 4) + { + do { + UA_COPY32(op,ip); + op += 4; ip += 4; t -= 4; + } while (t >= 4); + if (t > 0) do *op++ = *ip++; while (--t > 0); + } + else + do *op++ = *ip++; while (--t > 0); + } +#if !defined(LZO_UNALIGNED_OK_4) + } + else +#endif +#endif +#if !defined(LZO_UNALIGNED_OK_4) && !defined(LZO_UNALIGNED_OK_8) + { + *op++ = *ip++; *op++ = *ip++; *op++ = *ip++; + do *op++ = *ip++; while (--t > 0); + } +#endif + +first_literal_run: + + t = *ip++; + if (t >= 16) + goto match; +#if defined(COPY_DICT) +#if defined(LZO1Z) + m_off = (1 + M2_MAX_OFFSET) + (t << 6) + (*ip++ >> 2); + last_m_off = m_off; +#else + m_off = (1 + M2_MAX_OFFSET) + (t >> 2) + (*ip++ << 2); +#endif + NEED_OP(3); + t = 3; COPY_DICT(t,m_off) +#else +#if defined(LZO1Z) + t = (1 + M2_MAX_OFFSET) + (t << 6) + (*ip++ >> 2); + m_pos = op - t; + last_m_off = t; +#else + m_pos = op - (1 + M2_MAX_OFFSET); + m_pos -= t >> 2; + m_pos -= *ip++ << 2; +#endif + TEST_LB(m_pos); NEED_OP(3); + *op++ = *m_pos++; *op++ = *m_pos++; *op++ = *m_pos; +#endif + goto match_done; + + do { +match: + if (t >= 64) + { +#if defined(COPY_DICT) +#if defined(LZO1X) + m_off = 1 + ((t >> 2) & 7) + (*ip++ << 3); + t = (t >> 5) - 1; +#elif defined(LZO1Y) + m_off = 1 + ((t >> 2) & 3) + (*ip++ << 2); + t = (t >> 4) - 3; +#elif defined(LZO1Z) + m_off = t & 0x1f; + if (m_off >= 0x1c) + m_off = last_m_off; + else + { + m_off = 1 + (m_off << 6) + (*ip++ >> 2); + last_m_off = m_off; + } + t = (t >> 5) - 1; +#endif +#else +#if defined(LZO1X) + m_pos = op - 1; + m_pos -= (t >> 2) & 7; + m_pos -= *ip++ << 3; + t = (t >> 5) - 1; +#elif defined(LZO1Y) + m_pos = op - 1; + m_pos -= (t >> 2) & 3; + m_pos -= *ip++ << 2; + t = (t >> 4) - 3; +#elif defined(LZO1Z) + { + lzo_uint off = t & 0x1f; + m_pos = op; + if (off >= 0x1c) + { + assert(last_m_off > 0); + m_pos -= last_m_off; + } + else + { + off = 1 + (off << 6) + (*ip++ >> 2); + m_pos -= off; + last_m_off = off; + } + } + t = (t >> 5) - 1; +#endif + TEST_LB(m_pos); assert(t > 0); NEED_OP(t+3-1); + goto copy_match; +#endif + } + else if (t >= 32) + { + t &= 31; + if (t == 0) + { + NEED_IP(1); + while (*ip == 0) + { + t += 255; + ip++; + NEED_IP(1); + } + t += 31 + *ip++; + } +#if defined(COPY_DICT) +#if defined(LZO1Z) + m_off = 1 + (ip[0] << 6) + (ip[1] >> 2); + last_m_off = m_off; +#else + m_off = 1 + (ip[0] >> 2) + (ip[1] << 6); +#endif +#else +#if defined(LZO1Z) + { + lzo_uint off = 1 + (ip[0] << 6) + (ip[1] >> 2); + m_pos = op - off; + last_m_off = off; + } +#elif defined(LZO_UNALIGNED_OK_2) && defined(LZO_ABI_LITTLE_ENDIAN) + m_pos = op - 1; + m_pos -= UA_GET16(ip) >> 2; +#else + m_pos = op - 1; + m_pos -= (ip[0] >> 2) + (ip[1] << 6); +#endif +#endif + ip += 2; + } + else if (t >= 16) + { +#if defined(COPY_DICT) + m_off = (t & 8) << 11; +#else + m_pos = op; + m_pos -= (t & 8) << 11; +#endif + t &= 7; + if (t == 0) + { + NEED_IP(1); + while (*ip == 0) + { + t += 255; + ip++; + NEED_IP(1); + } + t += 7 + *ip++; + } +#if defined(COPY_DICT) +#if defined(LZO1Z) + m_off += (ip[0] << 6) + (ip[1] >> 2); +#else + m_off += (ip[0] >> 2) + (ip[1] << 6); +#endif + ip += 2; + if (m_off == 0) + goto eof_found; + m_off += 0x4000; +#if defined(LZO1Z) + last_m_off = m_off; +#endif +#else +#if defined(LZO1Z) + m_pos -= (ip[0] << 6) + (ip[1] >> 2); +#elif defined(LZO_UNALIGNED_OK_2) && defined(LZO_ABI_LITTLE_ENDIAN) + m_pos -= UA_GET16(ip) >> 2; +#else + m_pos -= (ip[0] >> 2) + (ip[1] << 6); +#endif + ip += 2; + if (m_pos == op) + goto eof_found; + m_pos -= 0x4000; +#if defined(LZO1Z) + last_m_off = pd((const lzo_bytep)op, m_pos); +#endif +#endif + } + else + { +#if defined(COPY_DICT) +#if defined(LZO1Z) + m_off = 1 + (t << 6) + (*ip++ >> 2); + last_m_off = m_off; +#else + m_off = 1 + (t >> 2) + (*ip++ << 2); +#endif + NEED_OP(2); + t = 2; COPY_DICT(t,m_off) +#else +#if defined(LZO1Z) + t = 1 + (t << 6) + (*ip++ >> 2); + m_pos = op - t; + last_m_off = t; +#else + m_pos = op - 1; + m_pos -= t >> 2; + m_pos -= *ip++ << 2; +#endif + TEST_LB(m_pos); NEED_OP(2); + *op++ = *m_pos++; *op++ = *m_pos; +#endif + goto match_done; + } + +#if defined(COPY_DICT) + + NEED_OP(t+3-1); + t += 3-1; COPY_DICT(t,m_off) + +#else + + TEST_LB(m_pos); assert(t > 0); NEED_OP(t+3-1); +#if defined(LZO_UNALIGNED_OK_8) && defined(LZO_UNALIGNED_OK_4) + if (op - m_pos >= 8) + { + t += (3 - 1); + if (t >= 8) do + { + UA_COPY64(op,m_pos); + op += 8; m_pos += 8; t -= 8; + } while (t >= 8); + if (t >= 4) + { + UA_COPY32(op,m_pos); + op += 4; m_pos += 4; t -= 4; + } + if (t > 0) + { + *op++ = m_pos[0]; + if (t > 1) { *op++ = m_pos[1]; if (t > 2) { *op++ = m_pos[2]; } } + } + } + else +#elif defined(LZO_UNALIGNED_OK_4) || defined(LZO_ALIGNED_OK_4) +#if !defined(LZO_UNALIGNED_OK_4) + if (t >= 2 * 4 - (3 - 1) && PTR_ALIGNED2_4(op,m_pos)) + { + assert((op - m_pos) >= 4); +#else + if (t >= 2 * 4 - (3 - 1) && (op - m_pos) >= 4) + { +#endif + UA_COPY32(op,m_pos); + op += 4; m_pos += 4; t -= 4 - (3 - 1); + do { + UA_COPY32(op,m_pos); + op += 4; m_pos += 4; t -= 4; + } while (t >= 4); + if (t > 0) do *op++ = *m_pos++; while (--t > 0); + } + else +#endif + { +copy_match: + *op++ = *m_pos++; *op++ = *m_pos++; + do *op++ = *m_pos++; while (--t > 0); + } + +#endif + +match_done: +#if defined(LZO1Z) + t = ip[-1] & 3; +#else + t = ip[-2] & 3; +#endif + if (t == 0) + break; + +match_next: + assert(t > 0); assert(t < 4); NEED_OP(t); NEED_IP(t+1); +#if 0 + do *op++ = *ip++; while (--t > 0); +#else + *op++ = *ip++; + if (t > 1) { *op++ = *ip++; if (t > 2) { *op++ = *ip++; } } +#endif + t = *ip++; + } while (TEST_IP && TEST_OP); + } + +#if defined(HAVE_TEST_IP) || defined(HAVE_TEST_OP) + *out_len = pd(op, out); + return LZO_E_EOF_NOT_FOUND; +#endif + +eof_found: + assert(t == 1); + *out_len = pd(op, out); + return (ip == ip_end ? LZO_E_OK : + (ip < ip_end ? LZO_E_INPUT_NOT_CONSUMED : LZO_E_INPUT_OVERRUN)); + +#if defined(HAVE_NEED_IP) +input_overrun: + *out_len = pd(op, out); + return LZO_E_INPUT_OVERRUN; +#endif + +#if defined(HAVE_NEED_OP) +output_overrun: + *out_len = pd(op, out); + return LZO_E_OUTPUT_OVERRUN; +#endif + +#if defined(LZO_TEST_OVERRUN_LOOKBEHIND) +lookbehind_overrun: + *out_len = pd(op, out); + return LZO_E_LOOKBEHIND_OVERRUN; +#endif +} + +#endif + +/***** End of minilzo.c *****/ + diff --git a/grub-core/lib/minilzo/minilzo.h b/grub-core/lib/minilzo/minilzo.h new file mode 100644 index 000000000..74fefa9fe --- /dev/null +++ b/grub-core/lib/minilzo/minilzo.h @@ -0,0 +1,109 @@ +/* minilzo.h -- mini subset of the LZO real-time data compression library + + This file is part of the LZO real-time data compression library. + + Copyright (C) 2011 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2010 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2009 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2008 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2007 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2006 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2005 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2004 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2003 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2002 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2001 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2000 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 1999 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 1998 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 1997 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 1996 Markus Franz Xaver Johannes Oberhumer + All Rights Reserved. + + The LZO library 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 2 of + the License, or (at your option) any later version. + + The LZO library 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 the LZO library; see the file COPYING. + If not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + Markus F.X.J. Oberhumer + + http://www.oberhumer.com/opensource/lzo/ + */ + +/* + * NOTE: + * the full LZO package can be found at + * http://www.oberhumer.com/opensource/lzo/ + */ + + +#ifndef __MINILZO_H +#define __MINILZO_H 1 + +#define MINILZO_VERSION 0x2050 + +#ifdef __LZOCONF_H +# error "you cannot use both LZO and miniLZO" +#endif + +#undef LZO_HAVE_CONFIG_H +#include "lzoconf.h" + +#if !defined(LZO_VERSION) || (LZO_VERSION != MINILZO_VERSION) +# error "version mismatch in header files" +#endif + + +#ifdef __cplusplus +extern "C" { +#endif + + +/*********************************************************************** +// +************************************************************************/ + +/* Memory required for the wrkmem parameter. + * When the required size is 0, you can also pass a NULL pointer. + */ + +#define LZO1X_MEM_COMPRESS LZO1X_1_MEM_COMPRESS +#define LZO1X_1_MEM_COMPRESS ((lzo_uint32) (16384L * lzo_sizeof_dict_t)) +#define LZO1X_MEM_DECOMPRESS (0) + + +/* compression */ +LZO_EXTERN(int) +lzo1x_1_compress ( const lzo_bytep src, lzo_uint src_len, + lzo_bytep dst, lzo_uintp dst_len, + lzo_voidp wrkmem ); + +/* decompression */ +LZO_EXTERN(int) +lzo1x_decompress ( const lzo_bytep src, lzo_uint src_len, + lzo_bytep dst, lzo_uintp dst_len, + lzo_voidp wrkmem /* NOT USED */ ); + +/* safe decompression with overrun testing */ +LZO_EXTERN(int) +lzo1x_decompress_safe ( const lzo_bytep src, lzo_uint src_len, + lzo_bytep dst, lzo_uintp dst_len, + lzo_voidp wrkmem /* NOT USED */ ); + + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /* already included */ + diff --git a/grub-core/lib/posix_wrap/limits.h b/grub-core/lib/posix_wrap/limits.h index e69de29bb..fe8523e68 100644 --- a/grub-core/lib/posix_wrap/limits.h +++ b/grub-core/lib/posix_wrap/limits.h @@ -0,0 +1,31 @@ +/* + * 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 . + */ + +#ifndef GRUB_POSIX_LIMITS_H +#define GRUB_POSIX_LIMITS_H + +#include + +#define UCHAR_MAX GRUB_UCHAR_MAX +#define USHRT_MAX GRUB_USHRT_MAX +#define UINT_MAX GRUB_UINT_MAX +#define ULONG_MAX GRUB_ULONG_MAX + +#define CHAR_BIT 8 + +#endif diff --git a/grub-core/lib/posix_wrap/sys/types.h b/grub-core/lib/posix_wrap/sys/types.h index 69e49509e..0c58d6c44 100644 --- a/grub-core/lib/posix_wrap/sys/types.h +++ b/grub-core/lib/posix_wrap/sys/types.h @@ -24,9 +24,6 @@ typedef grub_size_t size_t; typedef enum { false = 0, true = 1 } bool; -#define ULONG_MAX GRUB_ULONG_MAX -#define UCHAR_MAX 0xff - typedef grub_uint8_t uint8_t; typedef grub_uint16_t uint16_t; typedef grub_uint32_t uint32_t; diff --git a/include/grub/types.h b/include/grub/types.h index 4fd7a3a4b..32d255d40 100644 --- a/include/grub/types.h +++ b/include/grub/types.h @@ -116,6 +116,10 @@ typedef grub_int32_t grub_ssize_t; # define PRIuGRUB_SIZE "u" #endif +#define GRUB_UCHAR_MAX 0xFF +#define GRUB_USHRT_MAX 65535 +#define GRUB_UINT_MAX 4294967295U + #if GRUB_CPU_SIZEOF_LONG == 8 # define GRUB_ULONG_MAX 18446744073709551615UL # define GRUB_LONG_MAX 9223372036854775807L From b2d7e331e2b5cb9899a13e5e105e96d2632da995 Mon Sep 17 00:00:00 2001 From: Szymon Janc Date: Sun, 14 Aug 2011 11:41:19 +0200 Subject: [PATCH 767/869] Add helper functions for easier unaligned memory access. * include/grub/types.h (grub_get_unaligned16): New function. (grub_get_unaligned32): Likewise. (grub_get_unaligned64): Likewise. --- ChangeLog.lzo | 8 ++++++++ include/grub/types.h | 27 +++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/ChangeLog.lzo b/ChangeLog.lzo index 6f5191db2..701715747 100644 --- a/ChangeLog.lzo +++ b/ChangeLog.lzo @@ -1,3 +1,11 @@ +2001-08-14 Szymon Janc + + Add helper functions for easier unaligned memory access. + + * include/grub/types.h (grub_get_unaligned16): New function. + (grub_get_unaligned32): Likewise. + (grub_get_unaligned64): Likewise. + 2011-08-14 Szymon Janc Import minilzo library for LZO decompression support. diff --git a/include/grub/types.h b/include/grub/types.h index 32d255d40..f057dd3d3 100644 --- a/include/grub/types.h +++ b/include/grub/types.h @@ -222,4 +222,31 @@ static inline grub_uint64_t grub_swap_bytes64(grub_uint64_t x) # define grub_cpu_to_le32_compile_time(x) ((grub_uint32_t) (x)) #endif /* ! WORDS_BIGENDIAN */ +static inline grub_uint16_t grub_get_unaligned16(void *ptr) +{ + struct + { + grub_uint16_t d; + } __attribute__((packed)) *dd = ptr; + return dd->d; +} + +static inline grub_uint32_t grub_get_unaligned32(void *ptr) +{ + struct + { + grub_uint32_t d; + } __attribute__((packed)) *dd = ptr; + return dd->d; +} + +static inline grub_uint64_t grub_get_unaligned64(void *ptr) +{ + struct + { + grub_uint64_t d; + } __attribute__((packed)) *dd = ptr; + return dd->d; +} + #endif /* ! GRUB_TYPES_HEADER */ From b6085f323611098c84177e90701809b6a8c5dcaf Mon Sep 17 00:00:00 2001 From: Szymon Janc Date: Sun, 14 Aug 2011 11:42:53 +0200 Subject: [PATCH 768/869] * grub-core/fs/btrfs.c: Some code style fixes. --- ChangeLog.lzo | 4 + grub-core/fs/btrfs.c | 187 +++++++++++++++++++++---------------------- 2 files changed, 94 insertions(+), 97 deletions(-) diff --git a/ChangeLog.lzo b/ChangeLog.lzo index 701715747..0a9d852a4 100644 --- a/ChangeLog.lzo +++ b/ChangeLog.lzo @@ -1,3 +1,7 @@ +2011-08-14 Szymon Janc + + * grub-core/fs/btrfs.c: Some code style fixes. + 2001-08-14 Szymon Janc Add helper functions for easier unaligned memory access. diff --git a/grub-core/fs/btrfs.c b/grub-core/fs/btrfs.c index 6470c9819..1336c8f02 100644 --- a/grub-core/fs/btrfs.c +++ b/grub-core/fs/btrfs.c @@ -41,7 +41,7 @@ struct grub_btrfs_device } __attribute__ ((packed)); struct grub_btrfs_superblock -{ +{ grub_btrfs_checksum_t checksum; grub_btrfs_uuid_t uuid; grub_uint8_t dummy[0x10]; @@ -160,7 +160,8 @@ struct grub_btrfs_leaf_descriptor { unsigned depth; unsigned allocated; - struct { + struct + { grub_disk_addr_t addr; unsigned iter; unsigned maxiter; @@ -179,7 +180,7 @@ struct grub_btrfs_time { grub_int64_t sec; grub_uint32_t nanosec; -} __attribute__ ((aligned(4))); +} __attribute__ ((aligned (4))); struct grub_btrfs_inode { @@ -219,8 +220,8 @@ struct grub_btrfs_extent_data #define GRUB_BTRFS_OBJECT_ID_CHUNK 0x100 static grub_disk_addr_t superblock_sectors[] = { 64 * 2, 64 * 1024 * 2, - 256 * 1048576 * 2, - 1048576ULL * 1048576ULL * 2 }; + 256 * 1048576 * 2, 1048576ULL * 1048576ULL * 2 +}; static grub_err_t grub_btrfs_read_logical (struct grub_btrfs_data *data, @@ -283,7 +284,7 @@ free_iterator (struct grub_btrfs_leaf_descriptor *desc) } static grub_err_t -save_ref (struct grub_btrfs_leaf_descriptor *desc, +save_ref (struct grub_btrfs_leaf_descriptor *desc, grub_disk_addr_t addr, unsigned i, unsigned m, int l) { desc->depth++; @@ -307,7 +308,7 @@ save_ref (struct grub_btrfs_leaf_descriptor *desc, static int next (struct grub_btrfs_data *data, struct grub_btrfs_leaf_descriptor *desc, - grub_disk_addr_t *outaddr, grub_size_t *outsize, + grub_disk_addr_t * outaddr, grub_size_t * outsize, struct grub_btrfs_key *key_out) { grub_err_t err; @@ -316,8 +317,8 @@ next (struct grub_btrfs_data *data, for (; desc->depth > 0; desc->depth--) { desc->data[desc->depth - 1].iter++; - if (desc->data[desc->depth - 1].iter - < desc->data[desc->depth - 1].maxiter) + if (desc->data[desc->depth - 1].iter < + desc->data[desc->depth - 1].maxiter) break; } if (desc->depth == 0) @@ -330,17 +331,17 @@ next (struct grub_btrfs_data *data, err = grub_btrfs_read_logical (data, desc->data[desc->depth - 1].iter * sizeof (node) + sizeof (struct btrfs_header) - + desc->data[desc->depth - 1].addr, &node, - sizeof (node)); + + desc->data[desc->depth - 1].addr, + &node, sizeof (node)); if (err) return -err; - err = grub_btrfs_read_logical (data, grub_le_to_cpu64 (node.addr), &head, - sizeof (head)); + err = grub_btrfs_read_logical (data, grub_le_to_cpu64 (node.addr), + &head, sizeof (head)); if (err) return -err; - save_ref (desc, grub_le_to_cpu64 (node.addr), 0, + save_ref (desc, grub_le_to_cpu64 (node.addr), 0, grub_le_to_cpu32 (head.nitems), !head.level); } err = grub_btrfs_read_logical (data, desc->data[desc->depth - 1].iter @@ -354,15 +355,15 @@ next (struct grub_btrfs_data *data, *outaddr = desc->data[desc->depth - 1].addr + sizeof (struct btrfs_header) + grub_le_to_cpu32 (leaf.offset); *key_out = leaf.key; - return 1; + return 1; } static grub_err_t lower_bound (struct grub_btrfs_data *data, - const struct grub_btrfs_key *key_in, + const struct grub_btrfs_key *key_in, struct grub_btrfs_key *key_out, grub_disk_addr_t root, - grub_disk_addr_t *outaddr, grub_size_t *outsize, + grub_disk_addr_t * outaddr, grub_size_t * outsize, struct grub_btrfs_leaf_descriptor *desc) { grub_disk_addr_t addr = root; @@ -410,8 +411,9 @@ lower_bound (struct grub_btrfs_data *data, grub_dprintf ("btrfs", "internal node (depth %d) %" PRIxGRUB_UINT64_T " %x %" PRIxGRUB_UINT64_T "\n", depth, - node.key.object_id, node.key.type, node.key.offset); - + node.key.object_id, node.key.type, + node.key.offset); + if (key_cmp (&node.key, key_in) == 0) { err = GRUB_ERR_NONE; @@ -433,7 +435,7 @@ lower_bound (struct grub_btrfs_data *data, err = GRUB_ERR_NONE; if (desc) err = save_ref (desc, addr - sizeof (head), i - 1, - grub_le_to_cpu32 (head.nitems), 0); + grub_le_to_cpu32 (head.nitems), 0); if (err) return err; addr = grub_le_to_cpu64 (node_last.addr); @@ -457,7 +459,7 @@ lower_bound (struct grub_btrfs_data *data, &leaf, sizeof (leaf)); if (err) return err; - + grub_dprintf ("btrfs", "leaf (depth %d) %" PRIxGRUB_UINT64_T " %x %" PRIxGRUB_UINT64_T "\n", depth, @@ -465,31 +467,31 @@ lower_bound (struct grub_btrfs_data *data, if (key_cmp (&leaf.key, key_in) == 0) { - grub_memcpy (key_out, &leaf.key, sizeof(*key_out)); + grub_memcpy (key_out, &leaf.key, sizeof (*key_out)); *outsize = grub_le_to_cpu32 (leaf.size); *outaddr = addr + grub_le_to_cpu32 (leaf.offset); if (desc) return save_ref (desc, addr - sizeof (head), i, grub_le_to_cpu32 (head.nitems), 1); - return GRUB_ERR_NONE; + return GRUB_ERR_NONE; } - + if (key_cmp (&leaf.key, key_in) > 0) break; - + have_last = 1; leaf_last = leaf; } if (have_last) { - grub_memcpy (key_out, &leaf_last.key, sizeof(*key_out)); + grub_memcpy (key_out, &leaf_last.key, sizeof (*key_out)); *outsize = grub_le_to_cpu32 (leaf_last.size); *outaddr = addr + grub_le_to_cpu32 (leaf_last.offset); if (desc) return save_ref (desc, addr - sizeof (head), i - 1, grub_le_to_cpu32 (head.nitems), 1); - return GRUB_ERR_NONE; + return GRUB_ERR_NONE; } *outsize = 0; *outaddr = 0; @@ -503,8 +505,7 @@ lower_bound (struct grub_btrfs_data *data, } static grub_device_t -find_device (struct grub_btrfs_data *data, grub_uint64_t id, - int do_rescan) +find_device (struct grub_btrfs_data *data, grub_uint64_t id, int do_rescan) { grub_device_t dev_found = NULL; auto int hook (const char *name); @@ -540,7 +541,7 @@ find_device (struct grub_btrfs_data *data, grub_uint64_t id, grub_device_close (dev); return 0; } - + dev_found = dev; return 1; } @@ -579,17 +580,16 @@ find_device (struct grub_btrfs_data *data, grub_uint64_t id, } static grub_err_t -grub_btrfs_read_logical (struct grub_btrfs_data *data, - grub_disk_addr_t addr, +grub_btrfs_read_logical (struct grub_btrfs_data *data, grub_disk_addr_t addr, void *buf, grub_size_t size) { while (size > 0) { grub_uint8_t *ptr; struct grub_btrfs_key *key; - struct grub_btrfs_chunk_item *chunk; + struct grub_btrfs_chunk_item *chunk; grub_uint64_t csize; - grub_err_t err = 0; + grub_err_t err = 0; struct grub_btrfs_key key_out; int challoc = 0; grub_device_t dev; @@ -601,20 +601,20 @@ grub_btrfs_read_logical (struct grub_btrfs_data *data, addr); for (ptr = data->sblock.bootstrap_mapping; ptr < data->sblock.bootstrap_mapping - + sizeof (data->sblock.bootstrap_mapping) - - sizeof (struct grub_btrfs_key); - ) + + sizeof (data->sblock.bootstrap_mapping) + - sizeof (struct grub_btrfs_key);) { key = (struct grub_btrfs_key *) ptr; if (key->type != GRUB_BTRFS_ITEM_TYPE_CHUNK) break; chunk = (struct grub_btrfs_chunk_item *) (key + 1); - grub_dprintf ("btrfs", "%" PRIxGRUB_UINT64_T " %" PRIxGRUB_UINT64_T " \n", + grub_dprintf ("btrfs", + "%" PRIxGRUB_UINT64_T " %" PRIxGRUB_UINT64_T " \n", grub_le_to_cpu64 (key->offset), grub_le_to_cpu64 (chunk->size)); if (grub_le_to_cpu64 (key->offset) <= addr - && addr < grub_le_to_cpu64 (key->offset) - + grub_le_to_cpu64 (chunk->size)) + && addr < + grub_le_to_cpu64 (key->offset) + grub_le_to_cpu64 (chunk->size)) goto chunk_found; ptr += sizeof (*key) + sizeof (*chunk) + sizeof (struct grub_btrfs_chunk_stripe) @@ -704,11 +704,11 @@ grub_btrfs_read_logical (struct grub_btrfs_data *data, middle = grub_divmod64 (off, grub_le_to_cpu64 (chunk->stripe_length), &low); - + high = grub_divmod64 (middle, grub_le_to_cpu16 (chunk->nstripes), &stripen); - stripe_offset = low + grub_le_to_cpu64 (chunk->stripe_length) - * high; + stripe_offset = + low + grub_le_to_cpu64 (chunk->stripe_length) * high; csize = grub_le_to_cpu64 (chunk->stripe_length) - low; break; } @@ -719,7 +719,7 @@ grub_btrfs_read_logical (struct grub_btrfs_data *data, middle = grub_divmod64 (off, grub_le_to_cpu64 (chunk->stripe_length), &low); - + high = grub_divmod64 (middle, grub_le_to_cpu16 (chunk->nsubstripes), &stripen); @@ -759,7 +759,8 @@ grub_btrfs_read_logical (struct grub_btrfs_data *data, paddr = stripe->offset + stripe_offset; grub_dprintf ("btrfs", "chunk 0x%" PRIxGRUB_UINT64_T - "+0x%" PRIxGRUB_UINT64_T " (%d stripes (%d substripes) of %" + "+0x%" PRIxGRUB_UINT64_T + " (%d stripes (%d substripes) of %" PRIxGRUB_UINT64_T ") stripe %" PRIxGRUB_UINT64_T " maps to 0x%" PRIxGRUB_UINT64_T "\n", grub_le_to_cpu64 (key->offset), @@ -769,7 +770,7 @@ grub_btrfs_read_logical (struct grub_btrfs_data *data, grub_le_to_cpu64 (chunk->stripe_length), stripen, stripe->offset); grub_dprintf ("btrfs", "reading paddr 0x%" PRIxGRUB_UINT64_T - " for laddr 0x%" PRIxGRUB_UINT64_T"\n", paddr, + " for laddr 0x%" PRIxGRUB_UINT64_T "\n", paddr, addr); dev = find_device (data, stripe->device_id, j); @@ -815,7 +816,7 @@ grub_btrfs_mount (grub_device_t dev) } data = grub_zalloc (sizeof (*data)); - if (! data) + if (!data) return NULL; err = read_sblock (dev->disk, &data->sblock); @@ -866,8 +867,7 @@ grub_btrfs_read_inode (struct grub_btrfs_data *data, key_in.type = GRUB_BTRFS_ITEM_TYPE_INODE_ITEM; key_in.offset = 0; - err = lower_bound (data, &key_in, &key_out, tree, - &elemaddr, &elemsize, NULL); + err = lower_bound (data, &key_in, &key_out, tree, &elemaddr, &elemsize, NULL); if (err) return err; if (num != key_out.object_id @@ -917,19 +917,17 @@ grub_btrfs_extent_read (struct grub_btrfs_data *data, if (!data->extent) return grub_errno; - err = grub_btrfs_read_logical (data, elemaddr, - data->extent, elemsize); + err = grub_btrfs_read_logical (data, elemaddr, data->extent, + elemsize); if (err) return err; - data->extend = data->extstart - + grub_le_to_cpu64 (data->extent->size); + data->extend = data->extstart + grub_le_to_cpu64 (data->extent->size); if (data->extent->type == GRUB_BTRFS_EXTENT_REGULAR - && (char *) &data->extent + elemsize - >= (char *) &data->extent->filled - + sizeof (data->extent->filled)) - data->extend = data->extstart - + grub_le_to_cpu64 (data->extent->filled); + && (char *) &data->extent + elemsize >= + (char *) &data->extent->filled + sizeof (data->extent->filled)) + data->extend = + data->extstart + grub_le_to_cpu64 (data->extent->filled); grub_dprintf ("btrfs", "extent 0x%" PRIxGRUB_UINT64_T "+0x%" PRIxGRUB_UINT64_T " (0x%" @@ -966,8 +964,7 @@ grub_btrfs_extent_read (struct grub_btrfs_data *data, if (data->extent->encoding) { - grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, - "encoding not supported"); + grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, "encoding not supported"); return -1; } @@ -1008,8 +1005,8 @@ grub_btrfs_extent_read (struct grub_btrfs_data *data, grub_free (tmp); return -1; } - if (grub_zlib_decompress (tmp, zsize, extoff - + grub_le_to_cpu64 (data->extent->offset), + if (grub_zlib_decompress (tmp, zsize, extoff + + grub_le_to_cpu64 (data->extent->offset), buf, csize) != (grub_ssize_t) csize) { grub_free (tmp); @@ -1021,14 +1018,13 @@ grub_btrfs_extent_read (struct grub_btrfs_data *data, err = grub_btrfs_read_logical (data, grub_le_to_cpu64 (data->extent->laddr) + grub_le_to_cpu64 (data->extent->offset) - + extoff, - buf, csize); + + extoff, buf, csize); if (err) return -1; break; default: grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, - "unsupported extent type 0x%x", data->extent->type); + "unsupported extent type 0x%x", data->extent->type); return -1; } buf += csize; @@ -1041,7 +1037,7 @@ grub_btrfs_extent_read (struct grub_btrfs_data *data, static grub_err_t find_path (struct grub_btrfs_data *data, const char *path, struct grub_btrfs_key *key, - grub_uint64_t *tree, grub_uint8_t *type) + grub_uint64_t * tree, grub_uint8_t * type) { const char *slash = path; grub_err_t err; @@ -1096,9 +1092,9 @@ find_path (struct grub_btrfs_data *data, key->type = GRUB_BTRFS_ITEM_TYPE_DIR_ITEM; key->offset = grub_cpu_to_le64 (~grub_getcrc32c (1, ctoken, ctokenlen)); - - err = lower_bound (data, key, &key_out, *tree, - &elemaddr, &elemsize, NULL); + + err = lower_bound (data, key, &key_out, *tree, &elemaddr, &elemsize, + NULL); if (err) { grub_free (direl); @@ -1140,7 +1136,7 @@ find_path (struct grub_btrfs_data *data, for (cdirel = direl; (grub_uint8_t *) cdirel - (grub_uint8_t *) direl - < (grub_ssize_t) elemsize; + < (grub_ssize_t) elemsize; cdirel = (void *) ((grub_uint8_t *) (direl + 1) + grub_le_to_cpu16 (cdirel->n) + grub_le_to_cpu16 (cdirel->m))) @@ -1174,7 +1170,7 @@ find_path (struct grub_btrfs_data *data, return grub_error (GRUB_ERR_SYMLINK_LOOP, "too deep nesting of symlinks"); } - + err = grub_btrfs_read_inode (data, &inode, cdirel->key.object_id, *tree); if (err) @@ -1205,7 +1201,7 @@ find_path (struct grub_btrfs_data *data, grub_free (tmp); return grub_errno; } - grub_memcpy (tmp + grub_le_to_cpu64 (inode.size), path, + grub_memcpy (tmp + grub_le_to_cpu64 (inode.size), path, grub_strlen (path) + 1); grub_free (path_alloc); grub_free (origpath); @@ -1247,8 +1243,7 @@ find_path (struct grub_btrfs_data *data, grub_free (origpath); return err; } - err = grub_btrfs_read_logical (data, elemaddr, - &ri, sizeof (ri)); + err = grub_btrfs_read_logical (data, elemaddr, &ri, sizeof (ri)); if (err) { grub_free (direl); @@ -1279,7 +1274,7 @@ find_path (struct grub_btrfs_data *data, grub_free (path_alloc); grub_free (origpath); grub_free (direl); - return grub_error (GRUB_ERR_BAD_FS, "unrecognised object type 0x%x", + return grub_error (GRUB_ERR_BAD_FS, "unrecognised object type 0x%x", cdirel->key.type); } } @@ -1290,8 +1285,8 @@ find_path (struct grub_btrfs_data *data, static grub_err_t grub_btrfs_dir (grub_device_t device, const char *path, - int (*hook) (const char *filename, - const struct grub_dirhook_info *info)) + int (*hook) (const char *filename, + const struct grub_dirhook_info * info)) { struct grub_btrfs_data *data = grub_btrfs_mount (device); struct grub_btrfs_key key_in, key_out; @@ -1312,10 +1307,9 @@ grub_btrfs_dir (grub_device_t device, const char *path, if (err) return err; if (type != GRUB_BTRFS_DIR_ITEM_TYPE_DIRECTORY) - return grub_error (GRUB_ERR_BAD_FILE_TYPE, "not a directory"); + return grub_error (GRUB_ERR_BAD_FILE_TYPE, "not a directory"); - err = lower_bound (data, &key_in, &key_out, tree, - &elemaddr, &elemsize, &desc); + err = lower_bound (data, &key_in, &key_out, tree, &elemaddr, &elemsize, &desc); if (err) return err; if (key_out.type != GRUB_BTRFS_ITEM_TYPE_DIR_ITEM @@ -1355,7 +1349,7 @@ grub_btrfs_dir (grub_device_t device, const char *path, for (cdirel = direl; (grub_uint8_t *) cdirel - (grub_uint8_t *) direl - < (grub_ssize_t) elemsize; + < (grub_ssize_t) elemsize; cdirel = (void *) ((grub_uint8_t *) (direl + 1) + grub_le_to_cpu16 (cdirel->n) + grub_le_to_cpu16 (cdirel->m))) @@ -1384,7 +1378,7 @@ grub_btrfs_dir (grub_device_t device, const char *path, } while (r > 0); - out: +out: grub_free (direl); free_iterator (&desc); @@ -1456,7 +1450,7 @@ grub_btrfs_uuid (grub_device_t device, char **uuid) *uuid = NULL; data = grub_btrfs_mount (device); - if (! data) + if (!data) return grub_errno; *uuid = grub_xasprintf ("%04x%04x-%04x-%04x-%04x-%04x%04x%04x", @@ -1482,7 +1476,7 @@ grub_btrfs_label (grub_device_t device, char **label) *label = NULL; data = grub_btrfs_mount (device); - if (! data) + if (!data) return grub_errno; *label = grub_strndup (data->sblock.label, sizeof (data->sblock.label)); @@ -1492,26 +1486,25 @@ grub_btrfs_label (grub_device_t device, char **label) return grub_errno; } -static struct grub_fs grub_btrfs_fs = - { - .name = "btrfs", - .dir = grub_btrfs_dir, - .open = grub_btrfs_open, - .read = grub_btrfs_read, - .close = grub_btrfs_close, - .uuid = grub_btrfs_uuid, - .label = grub_btrfs_label, +static struct grub_fs grub_btrfs_fs = { + .name = "btrfs", + .dir = grub_btrfs_dir, + .open = grub_btrfs_open, + .read = grub_btrfs_read, + .close = grub_btrfs_close, + .uuid = grub_btrfs_uuid, + .label = grub_btrfs_label, #ifdef GRUB_UTIL - .reserved_first_sector = 1, + .reserved_first_sector = 1, #endif - }; +}; -GRUB_MOD_INIT(btrfs) +GRUB_MOD_INIT (btrfs) { grub_fs_register (&grub_btrfs_fs); } -GRUB_MOD_FINI(btrfs) +GRUB_MOD_FINI (btrfs) { grub_fs_unregister (&grub_btrfs_fs); } From 095f077e6db33fefb9c9eae6fcbb47b2bef577f8 Mon Sep 17 00:00:00 2001 From: Szymon Janc Date: Sun, 14 Aug 2011 11:46:05 +0200 Subject: [PATCH 769/869] Add support for LZO compression in btrfs. * Makefile.util.def (libgrubmods.a): Add minilzo.c and add required flags to cflags in cppflags. * Makefile.core.def (btrfs): Likewise. * grub-core/fs/btrfs.c: Include minilzo.h. (grub_btrfs_superblock): Add sectorsize, nodesize, leafsize, stripsize and dummy5 field. (GRUB_BTRFS_COMPRESSION_LZO): New define. (grub_btrfs_extent_read): Add support for LZO compression type. --- ChangeLog.lzo | 13 ++++ Makefile.util.def | 3 + grub-core/Makefile.core.def | 3 + grub-core/fs/btrfs.c | 136 ++++++++++++++++++++++++++++++++---- 4 files changed, 143 insertions(+), 12 deletions(-) diff --git a/ChangeLog.lzo b/ChangeLog.lzo index 0a9d852a4..c89255389 100644 --- a/ChangeLog.lzo +++ b/ChangeLog.lzo @@ -1,3 +1,16 @@ +2011-08-14 Szymon Janc + + Add support for LZO compression in btrfs. + + * Makefile.util.def (libgrubmods.a): Add minilzo.c and add required flags + to cflags in cppflags. + * Makefile.core.def (btrfs): Likewise. + * grub-core/fs/btrfs.c: Include minilzo.h. + (grub_btrfs_superblock): Add sectorsize, nodesize, leafsize, stripsize and + dummy5 field. + (GRUB_BTRFS_COMPRESSION_LZO): New define. + (grub_btrfs_extent_read): Add support for LZO compression type. + 2011-08-14 Szymon Janc * grub-core/fs/btrfs.c: Some code style fixes. diff --git a/Makefile.util.def b/Makefile.util.def index d86cb9761..3628e48f6 100644 --- a/Makefile.util.def +++ b/Makefile.util.def @@ -33,6 +33,8 @@ library = { library = { name = libgrubmods.a; + cflags = '$(CFLAGS_POSIX) -Wno-undef'; + cppflags = '-I$(srcdir)/lib/posix_wrap -I$(top_srcdir)/grub-core/lib/minilzo -DMINILZO_HAVE_CONFIG_H'; common_nodist = grub_script.tab.c; common_nodist = grub_script.yy.c; @@ -107,6 +109,7 @@ library = { common = grub-core/script/argv.c; common = grub-core/io/gzio.c; common = grub-core/kern/ia64/dl_helper.c; + common = grub-core/lib/minilzo/minilzo.c; }; program = { diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def index 0924602f3..1ff179c67 100644 --- a/grub-core/Makefile.core.def +++ b/grub-core/Makefile.core.def @@ -979,6 +979,9 @@ module = { name = btrfs; common = fs/btrfs.c; common = lib/crc.c; + common = lib/minilzo/minilzo.c; + cflags = '$(CFLAGS_POSIX) -Wno-undef'; + cppflags = '-I$(srcdir)/lib/posix_wrap -I$(srcdir)/lib/minilzo -DMINILZO_HAVE_CONFIG_H'; }; module = { diff --git a/grub-core/fs/btrfs.c b/grub-core/fs/btrfs.c index 1336c8f02..1d24da3e3 100644 --- a/grub-core/fs/btrfs.c +++ b/grub-core/fs/btrfs.c @@ -26,6 +26,7 @@ #include #include #include +#include "minilzo.h" GRUB_MOD_LICENSE ("GPLv3+"); @@ -51,10 +52,15 @@ struct grub_btrfs_superblock grub_uint64_t chunk_tree; grub_uint8_t dummy2[0x20]; grub_uint64_t root_dir_objectid; - grub_uint8_t dummy3[0x41]; + grub_uint8_t dummy3[0x8]; + grub_uint32_t sectorsize; + grub_uint32_t nodesize; + grub_uint32_t leafsize; + grub_uint32_t stripsize; + grub_uint8_t dummy4[0x29]; struct grub_btrfs_device this_device; char label[0x100]; - grub_uint8_t dummy4[0x100]; + grub_uint8_t dummy5[0x100]; grub_uint8_t bootstrap_mapping[0x800]; } __attribute__ ((packed)); @@ -216,6 +222,7 @@ struct grub_btrfs_extent_data #define GRUB_BTRFS_COMPRESSION_NONE 0 #define GRUB_BTRFS_COMPRESSION_ZLIB 1 +#define GRUB_BTRFS_COMPRESSION_LZO 2 #define GRUB_BTRFS_OBJECT_ID_CHUNK 0x100 @@ -954,7 +961,8 @@ grub_btrfs_extent_read (struct grub_btrfs_data *data, } if (data->extent->compression != GRUB_BTRFS_COMPRESSION_NONE - && data->extent->compression != GRUB_BTRFS_COMPRESSION_ZLIB) + && data->extent->compression != GRUB_BTRFS_COMPRESSION_ZLIB + && data->extent->compression != GRUB_BTRFS_COMPRESSION_LZO) { grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, "compression type 0x%x not supported", @@ -980,6 +988,42 @@ grub_btrfs_extent_read (struct grub_btrfs_data *data, != (grub_ssize_t) csize) return -1; } + else if (data->extent->compression == GRUB_BTRFS_COMPRESSION_LZO) + { + grub_uint32_t total_size, chunk_size; + unsigned char *obuf; + unsigned char *ibuf = (unsigned char *) data->extent->inl; + lzo_uint ocnt = extoff + csize; + int ret; + + obuf = grub_malloc (extoff + csize); + if (!obuf) + return -1; + + total_size = grub_le_to_cpu32 (grub_get_unaligned32 (ibuf)); + ibuf += sizeof (total_size); + + chunk_size = grub_le_to_cpu32 (grub_get_unaligned32 (ibuf)); + ibuf += sizeof (chunk_size); + + /* Can we have multiple chunks in inline extent? */ + if (chunk_size + (sizeof (grub_uint32_t) * 2) != total_size) + { + grub_free (obuf); + return -1; + } + + ret = lzo1x_decompress_safe (ibuf, chunk_size, obuf, &ocnt, NULL); + + if (ret != LZO_E_OK) + { + grub_free (obuf); + return -1; + } + + grub_memcpy (buf, obuf + extoff, ocnt - extoff); + grub_free (obuf); + } else grub_memcpy (buf, data->extent->inl + extoff, csize); break; @@ -989,9 +1033,10 @@ grub_btrfs_extent_read (struct grub_btrfs_data *data, grub_memset (buf, 0, csize); break; } - if (data->extent->compression == GRUB_BTRFS_COMPRESSION_ZLIB) + + if (data->extent->compression != GRUB_BTRFS_COMPRESSION_NONE) { - char *tmp; + void *tmp; grub_uint64_t zsize; zsize = grub_le_to_cpu64 (data->extent->compressed_size); tmp = grub_malloc (zsize); @@ -1005,16 +1050,83 @@ grub_btrfs_extent_read (struct grub_btrfs_data *data, grub_free (tmp); return -1; } - if (grub_zlib_decompress (tmp, zsize, extoff + - grub_le_to_cpu64 (data->extent->offset), - buf, csize) != (grub_ssize_t) csize) + + if (data->extent->compression == GRUB_BTRFS_COMPRESSION_ZLIB) { + grub_ssize_t ret; + + ret = grub_zlib_decompress (tmp, zsize, extoff + + grub_le_to_cpu64 (data->extent->offset), + buf, csize); + grub_free (tmp); - return -1; + + if (ret != (grub_ssize_t) csize) + return -1; + + break; } - grub_free (tmp); - break; - } + else if (data->extent->compression == GRUB_BTRFS_COMPRESSION_LZO) + { + grub_uint32_t total_size, chunk_size, usize = 0; + grub_size_t off = extoff; + unsigned char *chunk, *ibuf = tmp; + char *obuf = buf; + /* XXX Is this correct size from sblock? */ + grub_uint32_t udata_size = grub_le_to_cpu32 (data->sblock.sectorsize); + + chunk = grub_malloc (udata_size); + if (!chunk) + { + grub_free (tmp); + return -1; + } + + /* XXX Use this for some sanity checks while decompressing. */ + total_size = grub_le_to_cpu32 (grub_get_unaligned32 (ibuf)); + ibuf += sizeof (total_size); + + chunk_size = grub_le_to_cpu32 (grub_get_unaligned32 (ibuf)); + ibuf += sizeof (chunk_size); + + /* Jump to first chunk with requested data. */ + while (off >= udata_size) + { + chunk_size = grub_le_to_cpu32 (grub_get_unaligned32 (ibuf)); + ibuf += sizeof (chunk_size); + ibuf += chunk_size; + off -= udata_size; + } + + while (usize < csize) + { + chunk_size = grub_le_to_cpu32 (grub_get_unaligned32 (ibuf)); + lzo_uint csize2 = udata_size; + int diff; + + ibuf += sizeof (chunk_size); + + if (lzo1x_decompress_safe (ibuf, chunk_size, chunk, &csize2, NULL) != LZO_E_OK) + { + grub_free (tmp); + grub_free (chunk); + return -1; + } + + diff = grub_min (csize2 - off, csize - usize); + + grub_memcpy (obuf, chunk + off, diff); + obuf += diff; + ibuf += chunk_size; + usize += diff; + off = 0; + } + + grub_free (tmp); + grub_free (chunk); + break; + } + } err = grub_btrfs_read_logical (data, grub_le_to_cpu64 (data->extent->laddr) + grub_le_to_cpu64 (data->extent->offset) From 5f60ccac6f0c1a4236a964bed630c95ab67331cb Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Mon, 15 Aug 2011 23:21:29 +0100 Subject: [PATCH 770/869] * util/grub-probe.c: Remove duplicate #include. --- ChangeLog | 4 ++++ util/grub-probe.c | 1 - 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 039621768..b4ec6f677 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2011-08-15 Colin Watson + + * util/grub-probe.c: Remove duplicate #include. + 2011-08-10 Robert Millan Detect LSI MegaRAID SAS (`mfi') devices on GNU/kFreeBSD. diff --git a/util/grub-probe.c b/util/grub-probe.c index 7c0a75123..3f519bcb4 100644 --- a/util/grub-probe.c +++ b/util/grub-probe.c @@ -21,7 +21,6 @@ #include #include #include -#include #include #include #include From 828bc390d82e119133877f67ddd1eb3795fb8afc Mon Sep 17 00:00:00 2001 From: Mario Limonciello Date: Mon, 15 Aug 2011 23:30:11 +0100 Subject: [PATCH 771/869] * util/grub-probe.c (probe): Canonicalise the path argument, fixing use of "/path/.." as in grub-install for EFI as well as handling symlinks correctly. Fixes Debian bug #637768. --- ChangeLog | 8 ++++++++ util/grub-probe.c | 5 ++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index b4ec6f677..f3c2cf690 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2011-08-15 Mario Limonciello +2011-08-15 Colin Watson + + * util/grub-probe.c (probe): Canonicalise the path argument, fixing + use of "/path/.." as in grub-install for EFI as well as handling + symlinks correctly. + Fixes Debian bug #637768. + 2011-08-15 Colin Watson * util/grub-probe.c: Remove duplicate #include. diff --git a/util/grub-probe.c b/util/grub-probe.c index 3f519bcb4..ae58c89f3 100644 --- a/util/grub-probe.c +++ b/util/grub-probe.c @@ -180,7 +180,10 @@ probe (const char *path, char *device_name) #endif } else - device_name = grub_guess_root_device (path); + { + grub_path = canonicalize_file_name (path); + device_name = grub_guess_root_device (grub_path); + } if (! device_name) grub_util_error ("cannot find a device for %s (is /dev mounted?)", path); From b1257f653367e8d21b625276f53f086d68fab0b3 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Tue, 16 Aug 2011 16:11:10 +0200 Subject: [PATCH 772/869] Don't accept text modes on EFI when booting Linux. * grub-core/loader/i386/linux.c (ACCEPTS_PURE_TEXT): New define. (grub_linux_boot) [!ACCEPTS_PURE_TEXT]: Restrict to graphics modes. --- ChangeLog | 7 +++++++ grub-core/loader/i386/linux.c | 17 +++++++++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index f3c2cf690..fc1ea8713 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2011-08-16 Vladimir Serbinenko + + Don't accept text modes on EFI when booting Linux. + + * grub-core/loader/i386/linux.c (ACCEPTS_PURE_TEXT): New define. + (grub_linux_boot) [!ACCEPTS_PURE_TEXT]: Restrict to graphics modes. + 2011-08-15 Mario Limonciello 2011-08-15 Colin Watson diff --git a/grub-core/loader/i386/linux.c b/grub-core/loader/i386/linux.c index 9e3d482ab..5356d7ace 100644 --- a/grub-core/loader/i386/linux.c +++ b/grub-core/loader/i386/linux.c @@ -45,15 +45,18 @@ GRUB_MOD_LICENSE ("GPLv3+"); #include #define HAS_VGA_TEXT 0 #define DEFAULT_VIDEO_MODE "auto" +#define ACCEPTS_PURE_TEXT 0 #elif defined (GRUB_MACHINE_IEEE1275) #include #define HAS_VGA_TEXT 0 #define DEFAULT_VIDEO_MODE "text" +#define ACCEPTS_PURE_TEXT 1 #else #include #include #define HAS_VGA_TEXT 1 #define DEFAULT_VIDEO_MODE "text" +#define ACCEPTS_PURE_TEXT 1 #endif #define GRUB_LINUX_CL_OFFSET 0x1000 @@ -483,12 +486,22 @@ grub_linux_boot (void) tmp = grub_xasprintf ("%s;" DEFAULT_VIDEO_MODE, modevar); if (! tmp) return grub_errno; +#if ACCEPTS_PURE_TEXT err = grub_video_set_mode (tmp, 0, 0); +#else + err = grub_video_set_mode (tmp, GRUB_VIDEO_MODE_TYPE_PURE_TEXT, 0); +#endif grub_free (tmp); } else - err = grub_video_set_mode (DEFAULT_VIDEO_MODE, 0, 0); - + { +#if ACCEPTS_PURE_TEXT + err = grub_video_set_mode (DEFAULT_VIDEO_MODE, 0, 0); +#else + err = grub_video_set_mode (DEFAULT_VIDEO_MODE, + GRUB_VIDEO_MODE_TYPE_PURE_TEXT, 0); +#endif + } if (err) { grub_print_error (); From 5c144cc8b2cd13b88a0cd214cfa8ee8207aad1c0 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Tue, 16 Aug 2011 16:19:06 +0200 Subject: [PATCH 773/869] * util/grub-setup.c (main): Add missing gcry initialisation. --- ChangeLog | 4 ++++ util/grub-setup.c | 1 + 2 files changed, 5 insertions(+) diff --git a/ChangeLog b/ChangeLog index fc1ea8713..7acaf320c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2011-08-16 Vladimir Serbinenko + + * util/grub-setup.c (main): Add missing gcry initialisation. + 2011-08-16 Vladimir Serbinenko Don't accept text modes on EFI when booting Linux. diff --git a/util/grub-setup.c b/util/grub-setup.c index 8482e11c9..2505c03a4 100644 --- a/util/grub-setup.c +++ b/util/grub-setup.c @@ -893,6 +893,7 @@ main (int argc, char *argv[]) /* Initialize all modules. */ grub_init_all (); + grub_gcry_init_all (); grub_lvm_fini (); grub_mdraid09_fini (); From 43526629e58ac5d5eec0c7b6454bb96d750d197b Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Tue, 16 Aug 2011 23:10:38 +0200 Subject: [PATCH 774/869] * grub-core/fs/jfs.c (grub_jfs_read_file): New parameter ino. All users updated. (grub_jfs_lookup_symlink): Use correct starting inode. --- ChangeLog | 6 ++++++ grub-core/fs/jfs.c | 15 ++++++--------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7acaf320c..c414d79e7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2011-08-16 Vladimir Serbinenko + + * grub-core/fs/jfs.c (grub_jfs_read_file): New parameter ino. + All users updated. + (grub_jfs_lookup_symlink): Use correct starting inode. + 2011-08-16 Vladimir Serbinenko * util/grub-setup.c (main): Add missing gcry initialisation. diff --git a/grub-core/fs/jfs.c b/grub-core/fs/jfs.c index 36ec5fd25..ebc2c688a 100644 --- a/grub-core/fs/jfs.c +++ b/grub-core/fs/jfs.c @@ -614,7 +614,8 @@ grub_jfs_read_file (struct grub_jfs_data *data, /* Find the file with the pathname PATH on the filesystem described by DATA. */ static grub_err_t -grub_jfs_find_file (struct grub_jfs_data *data, const char *path) +grub_jfs_find_file (struct grub_jfs_data *data, const char *path, + grub_uint32_t start_ino) { char fpath[grub_strlen (path)]; char *name = fpath; @@ -623,7 +624,7 @@ grub_jfs_find_file (struct grub_jfs_data *data, const char *path) grub_strncpy (fpath, path, grub_strlen (path) + 1); - if (grub_jfs_read_inode (data, GRUB_JFS_AGGR_INODE, &data->currinode)) + if (grub_jfs_read_inode (data, start_ino, &data->currinode)) return grub_errno; /* Skip the first slashes. */ @@ -724,11 +725,7 @@ grub_jfs_lookup_symlink (struct grub_jfs_data *data, grub_uint32_t ino) if (symlink[0] == '/') ino = 2; - /* Now load in the old inode. */ - if (grub_jfs_read_inode (data, ino, &data->currinode)) - return grub_errno; - - grub_jfs_find_file (data, symlink); + grub_jfs_find_file (data, symlink, ino); if (grub_errno) grub_error (grub_errno, "cannot follow symlink `%s'", symlink); @@ -750,7 +747,7 @@ grub_jfs_dir (grub_device_t device, const char *path, if (!data) goto fail; - if (grub_jfs_find_file (data, path)) + if (grub_jfs_find_file (data, path, GRUB_JFS_AGGR_INODE)) goto fail; diro = grub_jfs_opendir (data, &data->currinode); @@ -801,7 +798,7 @@ grub_jfs_open (struct grub_file *file, const char *name) if (!data) goto fail; - grub_jfs_find_file (data, name); + grub_jfs_find_file (data, name, GRUB_JFS_AGGR_INODE); if (grub_errno) goto fail; From 2bba8cfd55fb65fe92d47c9b14d6953940128a5e Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Tue, 16 Aug 2011 23:12:20 +0200 Subject: [PATCH 775/869] * grub-core/kern/emu/hostdisk.c (grub_util_biosdisk_iterate): Skip with non-zero pull. --- ChangeLog | 5 +++++ grub-core/kern/emu/hostdisk.c | 3 +++ 2 files changed, 8 insertions(+) diff --git a/ChangeLog b/ChangeLog index c414d79e7..946dcbd80 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-08-16 Vladimir Serbinenko + + * grub-core/kern/emu/hostdisk.c (grub_util_biosdisk_iterate): Skip with + non-zero pull. + 2011-08-16 Vladimir Serbinenko * grub-core/fs/jfs.c (grub_jfs_read_file): New parameter ino. diff --git a/grub-core/kern/emu/hostdisk.c b/grub-core/kern/emu/hostdisk.c index d1f76b28c..000ef2f79 100644 --- a/grub-core/kern/emu/hostdisk.c +++ b/grub-core/kern/emu/hostdisk.c @@ -217,6 +217,9 @@ grub_util_biosdisk_iterate (int (*hook) (const char *name), { unsigned i; + if (pull != GRUB_DISK_PULL_NONE) + return 0; + for (i = 0; i < sizeof (map) / sizeof (map[0]); i++) if (map[i].drive && hook (map[i].drive)) return 1; From d6beefcfc9d3451fe262b6d57ccc215db8ce5681 Mon Sep 17 00:00:00 2001 From: Szymon Janc Date: Wed, 17 Aug 2011 19:40:25 +0200 Subject: [PATCH 776/869] Add initial support for lzop files decompression. * grub-core/Makefile.core.def (lzopio): New module. * grub-core/io/lzopio.c: New file. * include/grub/file.h (grub_file_filter_id): New compression filter GRUB_FILE_FILTER_LZOPIO. --- ChangeLog.lzo | 9 + grub-core/Makefile.core.def | 8 + grub-core/io/lzopio.c | 527 ++++++++++++++++++++++++++++++++++++ include/grub/file.h | 1 + 4 files changed, 545 insertions(+) create mode 100644 grub-core/io/lzopio.c diff --git a/ChangeLog.lzo b/ChangeLog.lzo index c89255389..782c6b60d 100644 --- a/ChangeLog.lzo +++ b/ChangeLog.lzo @@ -1,3 +1,12 @@ +2011-08-17 Szymon Janc + + Add initial support for lzop files decompression. + + * grub-core/Makefile.core.def (lzopio): New module. + * grub-core/io/lzopio.c: New file. + * include/grub/file.h (grub_file_filter_id): New compression filter + GRUB_FILE_FILTER_LZOPIO. + 2011-08-14 Szymon Janc Add support for LZO compression in btrfs. diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def index 1ff179c67..67959d861 100644 --- a/grub-core/Makefile.core.def +++ b/grub-core/Makefile.core.def @@ -1651,6 +1651,14 @@ module = { cppflags = '-I$(srcdir)/lib/posix_wrap -I$(srcdir)/lib/xzembed'; }; +module = { + name = lzopio; + common = io/lzopio.c; + common = lib/minilzo/minilzo.c; + cflags = '$(CFLAGS_POSIX) -Wno-undef'; + cppflags = '-I$(srcdir)/lib/posix_wrap -I$(srcdir)/lib/minilzo -DMINILZO_HAVE_CONFIG_H'; +}; + module = { name = testload; common = commands/testload.c; diff --git a/grub-core/io/lzopio.c b/grub-core/io/lzopio.c new file mode 100644 index 000000000..4ccc41a16 --- /dev/null +++ b/grub-core/io/lzopio.c @@ -0,0 +1,527 @@ +/* lzopio.c - decompression support for lzop */ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2011 Free Software Foundation, Inc. + * + * GRUB is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see . + */ + +#include +#include +#include +#include +#include + +#include "minilzo.h" + +GRUB_MOD_LICENSE ("GPLv3+"); + +#define LZOP_MAGIC "\x89\x4c\x5a\x4f\x00\x0d\x0a\x1a\x0a" +#define LZOP_MAGIC_SIZE 9 +#define CHECK_SIZE 4 +#define NEW_LZO_LIB 0x0940 +#define MIN_HEADER_SIZE 0 +#define MAX_HEADER_SIZE 0 + +/* Header flags - copied from conf.h of LZOP source code. */ +#define F_ADLER32_D 0x00000001L +#define F_ADLER32_C 0x00000002L +#define F_STDIN 0x00000004L +#define F_STDOUT 0x00000008L +#define F_NAME_DEFAULT 0x00000010L +#define F_DOSISH 0x00000020L +#define F_H_EXTRA_FIELD 0x00000040L +#define F_H_GMTDIFF 0x00000080L +#define F_CRC32_D 0x00000100L +#define F_CRC32_C 0x00000200L +#define F_MULTIPART 0x00000400L +#define F_H_FILTER 0x00000800L +#define F_H_CRC32 0x00001000L +#define F_H_PATH 0x00002000L +#define F_MASK 0x00003FFFL + +struct block_header +{ + grub_uint32_t usize; + grub_uint32_t csize; + grub_uint32_t ucheck; + grub_uint32_t ccheck; + unsigned char *cdata; + unsigned char *udata; +}; + +struct grub_lzopio +{ + grub_file_t file; + int ucheck; /* XXX Use gcry to validate checks. */ + int ccheck; + grub_off_t saved_off; /* Rounded down to block boundary. */ + grub_off_t start_block_off; + struct block_header block; +}; + +typedef struct grub_lzopio *grub_lzopio_t; +static struct grub_fs grub_lzopio_fs; + +/* Some helper functions. Memory allocated by those function is free either + * on next read_block_header() or on close() so no risk of leaks. This makes + * those function simpler. */ + +/* Read block header from file, after successful exit file points to + * beginning of block data. */ +static int +read_block_header (struct grub_lzopio *lzopio) +{ + /* Free cached block data if any. */ + grub_free (lzopio->block.udata); + grub_free (lzopio->block.cdata); + lzopio->block.udata = NULL; + lzopio->block.cdata = NULL; + + if (grub_file_read (lzopio->file, &lzopio->block.usize, + sizeof (lzopio->block.usize)) != + sizeof (lzopio->block.usize)) + return -1; + + lzopio->block.usize = grub_be_to_cpu32 (lzopio->block.usize); + + /* Last block has uncompressed data size == 0 and no other fields. */ + if (lzopio->block.usize == 0) + { + if (grub_file_tell (lzopio->file) == grub_file_size (lzopio->file)) + return 0; + else + return -1; + } + + /* Read compressed data block size. */ + if (grub_file_read (lzopio->file, &lzopio->block.csize, + sizeof (lzopio->block.csize)) != + sizeof (lzopio->block.csize)) + return -1; + + lzopio->block.csize = grub_be_to_cpu32 (lzopio->block.csize); + + /* XXX Handle incompressible data case here rather than in uncompress_block. + * This will allow to handle switch of ccheck/ucheck easier and also + * make uncompress_block() a bit simpler. */ + + /* Read data checks. */ + if (lzopio->ucheck) + { + if (grub_file_read (lzopio->file, &lzopio->block.ucheck, + sizeof (lzopio->block.ucheck)) != + sizeof (lzopio->block.ucheck)) + return -1; + } + + if (lzopio->ccheck) + { + if (grub_file_read (lzopio->file, &lzopio->block.ccheck, + sizeof (lzopio->block.ccheck)) != + sizeof (lzopio->block.ccheck)) + return -1; + } + return 0; +} + +/* Read block data into memory. File must be set to beginning of block data. + * Can't be called on last block. */ +static int +read_block_data (struct grub_lzopio *lzopio) +{ + lzopio->block.cdata = grub_malloc (lzopio->block.csize); + if (!lzopio->block.cdata) + return -1; + + if (grub_file_read (lzopio->file, lzopio->block.cdata, lzopio->block.csize) + != (grub_ssize_t) lzopio->block.csize) + return -1; + + if (lzopio->ccheck) + { + /* XXX Validate data checksum here. */ + } + + return 0; +} + +/* Read block data, uncompressed and also store it in memory. */ +/* XXX Investigate possibility of in-place decompression to reduce memory + * footprint. */ +static int +uncompress_block (struct grub_lzopio *lzopio) +{ + lzo_uint usize = lzopio->block.usize; + + if (read_block_data (lzopio) < 0) + return -1; + + if (lzopio->block.usize > lzopio->block.csize) + { + lzopio->block.udata = grub_malloc (lzopio->block.usize); + if (!lzopio->block.udata) + return -1; + + if (lzo1x_decompress_safe (lzopio->block.cdata, lzopio->block.csize, + lzopio->block.udata, &usize, + NULL) != LZO_E_OK) + return -1; + + if (lzopio->ucheck) + { + /* XXX Validate data checksum here. */ + } + + /* Compressed data can be free now. */ + grub_free (lzopio->block.cdata); + lzopio->block.cdata = NULL; + } + /* Incompressible block of data. */ + else if (lzopio->block.usize == lzopio->block.csize) + { + lzopio->block.udata = lzopio->block.cdata; + lzopio->block.cdata = NULL; + } + else + { + return -1; + } + + return 0; +} + +/* Jump to next block and read its header. */ +static int +jump_block (struct grub_lzopio *lzopio) +{ + /* only jump if block was not decompressed (and read from disk) */ + if (!lzopio->block.udata) + { + grub_off_t off = grub_file_tell (lzopio->file) + lzopio->block.csize; + + if (grub_file_seek (lzopio->file, off) == ((grub_off_t) - 1)) + return -1; + } + + lzopio->saved_off += lzopio->block.usize; + + return read_block_header (lzopio); +} + +static int +calculate_uncompressed_size (grub_file_t file) +{ + grub_lzopio_t lzopio = file->data; + grub_off_t usize_total = 0; + + if (read_block_header (lzopio) < 0) + return 0; + + /* FIXME: Don't do this for not easily seekable files. */ + while (lzopio->block.usize != 0) + { + usize_total += lzopio->block.usize; + + if (jump_block (lzopio) < 0) + return 0; + } + + file->size = usize_total; + + return 1; +} + +/* XXX Do something with this function, it is insane now:) */ +static int +test_header (grub_file_t file) +{ + grub_lzopio_t lzopio = file->data; + unsigned char magic[LZOP_MAGIC_SIZE]; + grub_uint16_t lzopver, ver, ver_ext; + grub_uint8_t method, level, name_len; + grub_uint32_t flags, mode, filter, mtime_lo, mtime_hi, checksum; + unsigned char *name = NULL; + + if (grub_file_read (lzopio->file, magic, sizeof (magic)) != sizeof (magic)) + { + grub_error (GRUB_ERR_BAD_FILE_TYPE, "no lzop magic found"); + return 0; + } + + if (grub_memcmp (magic, LZOP_MAGIC, LZOP_MAGIC_SIZE) != 0) + { + grub_error (GRUB_ERR_BAD_FILE_TYPE, "no lzop magic found"); + return 0; + } + + /* LZOP version. */ + if (grub_file_read (lzopio->file, &lzopver, sizeof (lzopver)) != + sizeof (lzopver)) + goto CORRUPTED; + + /* LZO lib version. */ + if (grub_file_read (lzopio->file, &ver, sizeof (ver)) != sizeof (ver)) + goto CORRUPTED; + + ver = grub_be_to_cpu16 (ver); + + if (ver >= NEW_LZO_LIB) + { + /* Read version of lib needed to extract data. */ + if (grub_file_read (lzopio->file, &ver_ext, sizeof (ver_ext)) != + sizeof (ver_ext)) + goto CORRUPTED; + + /* Too new version, should upgrade minilzo? */ + if (grub_be_to_cpu16 (ver_ext) > MINILZO_VERSION) + { + grub_error (GRUB_ERR_BAD_COMPRESSED_DATA, + "unsupported LZO version"); + return 0; + } + } + + if (grub_file_read (lzopio->file, &method, sizeof (method)) != + sizeof (method)) + goto CORRUPTED; + + if (ver >= NEW_LZO_LIB) + { + if (grub_file_read (lzopio->file, &level, sizeof (level)) != + sizeof (level)) + goto CORRUPTED; + } + + if (grub_file_read (lzopio->file, &flags, sizeof (flags)) != sizeof (flags)) + goto CORRUPTED; + + flags = grub_be_to_cpu32 (flags); + + if (flags & F_CRC32_D) + lzopio->ucheck = 1; + else if (flags & F_ADLER32_D) + lzopio->ucheck = 2; + + if (flags & F_CRC32_C) + lzopio->ccheck = 1; + else if (flags & F_ADLER32_C) + lzopio->ccheck = 2; + + if (flags & F_H_FILTER) + { + if (grub_file_read (lzopio->file, &filter, sizeof (filter)) != + sizeof (filter)) + goto CORRUPTED; + } + + if (grub_file_read (lzopio->file, &mode, sizeof (mode)) != sizeof (mode)) + goto CORRUPTED; + + if (grub_file_read (lzopio->file, &mtime_lo, sizeof (mtime_lo)) != + sizeof (mtime_lo)) + goto CORRUPTED; + + if (ver >= NEW_LZO_LIB) + { + if (grub_file_read (lzopio->file, &mtime_hi, sizeof (mtime_hi)) != + sizeof (mtime_hi)) + goto CORRUPTED; + } + + if (grub_file_read (lzopio->file, &name_len, sizeof (name_len)) != + sizeof (name_len)) + goto CORRUPTED; + + if (name_len != 0) + { + name = grub_malloc (name_len); + if (!name) + return 0; + + if (grub_file_read (lzopio->file, name, name_len) != name_len) + { + grub_free (name); + goto CORRUPTED; + } + } + + if (grub_file_read (lzopio->file, &checksum, sizeof (checksum)) != + sizeof (checksum)) + { + grub_free (name); + goto CORRUPTED; + } + + grub_free (name); + + /* XXX Validate header checksum here. */ + if (checksum == checksum) + { + lzopio->start_block_off = grub_file_tell (lzopio->file); + + if (calculate_uncompressed_size (file) < 0) + goto CORRUPTED; + + lzopio->saved_off = 0; + + /* Get back to start block. */ + grub_file_seek (lzopio->file, lzopio->start_block_off); + + /* Read first block - grub_lzopio_read() expects valid block. */ + if (read_block_header (lzopio) < 0) + goto CORRUPTED; + + return 1; + } + +CORRUPTED: + grub_error (GRUB_ERR_BAD_COMPRESSED_DATA, "lzop file corrupted"); + return 0; +} + +static grub_file_t +grub_lzopio_open (grub_file_t io) +{ + grub_file_t file; + grub_lzopio_t lzopio; + + file = (grub_file_t) grub_zalloc (sizeof (*file)); + if (!file) + return 0; + + lzopio = grub_zalloc (sizeof (*lzopio)); + if (!lzopio) + { + grub_free (file); + return 0; + } + + lzopio->file = io; + + file->device = io->device; + file->offset = 0; + file->data = lzopio; + file->read_hook = 0; + file->fs = &grub_lzopio_fs; + file->size = GRUB_FILE_SIZE_UNKNOWN; + file->not_easily_seekable = 1; + + if (grub_file_tell (lzopio->file) != 0) + grub_file_seek (lzopio->file, 0); + + if (!test_header (file)) + { + grub_errno = GRUB_ERR_NONE; + grub_file_seek (io, 0); + grub_free (lzopio); + grub_free (file); + + return io; + } + + return file; +} + +static grub_ssize_t +grub_lzopio_read (grub_file_t file, char *buf, grub_size_t len) +{ + grub_lzopio_t lzopio = file->data; + grub_ssize_t ret = 0; + + /* Backward seek before last read block. */ + if (lzopio->saved_off > grub_file_tell (file)) + { + lzopio->saved_off = 0; + grub_file_seek (lzopio->file, lzopio->start_block_off); + + if (read_block_header (lzopio) < 0) + goto CORRUPTED; + } + + /* Forward to first block with requested data. */ + while (lzopio->saved_off + lzopio->block.usize <= grub_file_tell (file)) + { + /* EOF, could be possible files with unknown size. */ + if (lzopio->block.usize == 0) + return 0; + + if (jump_block (lzopio) < 0) + goto CORRUPTED; + } + + while (len != 0 && lzopio->block.usize != 0) + { + grub_off_t off = grub_file_tell (file) - lzopio->saved_off; + long to_copy; + + /* Block not decompressed yet. */ + if (!lzopio->block.udata && uncompress_block (lzopio) < 0) + goto CORRUPTED; + + /* Copy requested data into buffer. */ + to_copy = grub_min (lzopio->block.usize - off, len); + grub_memcpy (buf, lzopio->block.udata + off, to_copy); + + len -= to_copy; + buf += to_copy; + ret += to_copy; + + /* Read to next block if needed. */ + if (len > 0 && read_block_header (lzopio) < 0) + goto CORRUPTED; + } + + return ret; + +CORRUPTED: + grub_error (GRUB_ERR_BAD_COMPRESSED_DATA, "lzop file corrupted"); + return -1; +} + +/* Release everything, including the underlying file object. */ +static grub_err_t +grub_lzopio_close (grub_file_t file) +{ + grub_lzopio_t lzopio = file->data; + + grub_file_close (lzopio->file); + grub_free (lzopio->block.cdata); + grub_free (lzopio->block.udata); + grub_free (lzopio); + + /* Device must not be closed twice. */ + file->device = 0; + return grub_errno; +} + +static struct grub_fs grub_lzopio_fs = { + .name = "lzopio", + .dir = 0, + .open = 0, + .read = grub_lzopio_read, + .close = grub_lzopio_close, + .label = 0, + .next = 0 +}; + +GRUB_MOD_INIT (lzopio) +{ + grub_file_filter_register (GRUB_FILE_FILTER_LZOPIO, grub_lzopio_open); +} + +GRUB_MOD_FINI (lzopio) +{ + grub_file_filter_unregister (GRUB_FILE_FILTER_LZOPIO); +} diff --git a/include/grub/file.h b/include/grub/file.h index 3adb1706f..8fe87e6b4 100644 --- a/include/grub/file.h +++ b/include/grub/file.h @@ -56,6 +56,7 @@ typedef enum grub_file_filter_id { GRUB_FILE_FILTER_GZIO, GRUB_FILE_FILTER_XZIO, + GRUB_FILE_FILTER_LZOPIO, GRUB_FILE_FILTER_MAX, GRUB_FILE_FILTER_COMPRESSION_FIRST = GRUB_FILE_FILTER_GZIO, GRUB_FILE_FILTER_COMPRESSION_LAST = GRUB_FILE_FILTER_XZIO, From 055e2b8b4f31be61160384d202c2f90422a723c2 Mon Sep 17 00:00:00 2001 From: Szymon Janc Date: Fri, 19 Aug 2011 17:24:18 +0200 Subject: [PATCH 777/869] * configure.ac: Fixed typo in --enable-cache-stats description. --- ChangeLog.cacheinfo | 4 ++++ configure.ac | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/ChangeLog.cacheinfo b/ChangeLog.cacheinfo index a26271cca..7e24e1083 100644 --- a/ChangeLog.cacheinfo +++ b/ChangeLog.cacheinfo @@ -1,3 +1,7 @@ +2011-08-19 Szymon Janc + + * configure.ac: Fixed typo in --enable-cache-stats description. + 2010-10-05 Szymon Janc Make enable of disk cache statistics code configurable. diff --git a/configure.ac b/configure.ac index 5f7846d41..224c9c9de 100644 --- a/configure.ac +++ b/configure.ac @@ -719,7 +719,7 @@ AC_ARG_ENABLE([mm-debug], AC_ARG_ENABLE([cache-stats], AS_HELP_STRING([--enable-cache-stats], - [enable disk cache statistics collection])]) + [enable disk cache statistics collection])) if test x$enable_cache_stats = xyes; then DISK_CACHE_STATS=1 From fb739ccd7923fb3d11d825d744faaf1cdf884d73 Mon Sep 17 00:00:00 2001 From: Szymon Janc Date: Fri, 19 Aug 2011 20:06:42 +0200 Subject: [PATCH 778/869] * Makefile.am (AUTOMAKE_OPTIONS): = Added -Wno-portability flag. * grub-core/Makefile.am: Likewise. --- ChangeLog | 5 +++++ Makefile.am | 2 +- grub-core/Makefile.am | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 946dcbd80..17e2643b8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-08-19 Szymon Janc + + * Makefile.am (AUTOMAKE_OPTIONS): = Added -Wno-portability flag. + * grub-core/Makefile.am: Likewise. + 2011-08-16 Vladimir Serbinenko * grub-core/kern/emu/hostdisk.c (grub_util_biosdisk_iterate): Skip with diff --git a/Makefile.am b/Makefile.am index 9301c91a5..c5f486e0d 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,4 +1,4 @@ -AUTOMAKE_OPTIONS = subdir-objects +AUTOMAKE_OPTIONS = subdir-objects -Wno-portability DEPDIR = .deps-util SUBDIRS = grub-core/gnulib . grub-core po docs util/bash-completion.d diff --git a/grub-core/Makefile.am b/grub-core/Makefile.am index 3a085eb2c..f30014635 100644 --- a/grub-core/Makefile.am +++ b/grub-core/Makefile.am @@ -1,4 +1,4 @@ -AUTOMAKE_OPTIONS = subdir-objects +AUTOMAKE_OPTIONS = subdir-objects -Wno-portability DEPDIR=.deps-core From 14a2562cf7e8bb2d6f8d13b297d8e3b07308d945 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 19 Aug 2011 22:46:11 +0200 Subject: [PATCH 779/869] Rename Fuloong into Fuloong 2F. Add new ID for Fuloong2E. * grub-core/Makefile.core.def (fwstart_fuloong): Rename fwstart_fuloong into fwstart_fuloong2f. Use boot/mips/loongson/fuloong2f.S. * grub-core/boot/mips/loongson/fuloong.S: Rename to ... * grub-core/boot/mips/loongson/fuloong2f.S: ... this. (FULOONG): Rename to ... (FULOONG2F): ... this. All users updated. * grub-core/boot/mips/startup_raw.S (machtype_fuloong_str): Rename to (machtype_fuloong2f_str): ... this. (machtype_fuloong2e_str): New string. Check for machtype_fuloong2e_str. * grub-core/loader/mips/linux.c (loongson_machtypes) [GRUB_MACHINE_MIPS_LOONGSON]: Add GRUB_ARCH_MACHINE_FULOONG2E. * grub-core/term/serial.c (loongson_defserial) [GRUB_MACHINE_MIPS_LOONGSON]: New array. (grub_serial_register) [GRUB_MACHINE_MIPS_LOONGSON]: Use loongson_defserial. * include/grub/mips/loongson/kernel.h (GRUB_ARCH_MACHINE_FULOONG): Rename to ... (GRUB_ARCH_MACHINE_FULOONG2F): ... this. (GRUB_ARCH_MACHINE_FULOONG2E): New const. * util/grub-mkimage.c (image_target_desc): Rename IMAGE_FULOONG_FLASH to IMAGE_FULOONG2F_FLASH. All users updated. (image_targets): Rename images. * util/grub-mkstandalone.in: Accept fuloong2f and fuloong2e. --- ChangeLog | 29 +++++++++++++++++++ grub-core/Makefile.core.def | 4 +-- .../mips/loongson/{fuloong.S => fuloong2f.S} | 2 +- grub-core/boot/mips/loongson/fwstart.S | 26 ++++++++--------- grub-core/boot/mips/startup_raw.S | 14 +++++---- grub-core/bus/cs5536.c | 2 +- grub-core/kern/mips/loongson/init.c | 4 ++- grub-core/kern/mips/startup.S | 2 +- grub-core/loader/mips/linux.c | 3 +- grub-core/term/serial.c | 13 +++++++-- include/grub/mips/loongson/kernel.h | 3 +- util/grub-mkimage.c | 17 ++++++----- util/grub-mkstandalone.in | 2 +- 13 files changed, 82 insertions(+), 39 deletions(-) rename grub-core/boot/mips/loongson/{fuloong.S => fuloong2f.S} (51%) diff --git a/ChangeLog b/ChangeLog index 21975a2d3..fdc89b5a2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,32 @@ +2011-08-19 Vladimir Serbinenko + + Rename Fuloong into Fuloong 2F. Add new ID for Fuloong2E. + + * grub-core/Makefile.core.def (fwstart_fuloong): Rename fwstart_fuloong + into fwstart_fuloong2f. Use boot/mips/loongson/fuloong2f.S. + * grub-core/boot/mips/loongson/fuloong.S: Rename to ... + * grub-core/boot/mips/loongson/fuloong2f.S: ... this. + (FULOONG): Rename to ... + (FULOONG2F): ... this. All users updated. + * grub-core/boot/mips/startup_raw.S (machtype_fuloong_str): Rename to + (machtype_fuloong2f_str): ... this. + (machtype_fuloong2e_str): New string. + Check for machtype_fuloong2e_str. + * grub-core/loader/mips/linux.c (loongson_machtypes) + [GRUB_MACHINE_MIPS_LOONGSON]: Add GRUB_ARCH_MACHINE_FULOONG2E. + * grub-core/term/serial.c (loongson_defserial) + [GRUB_MACHINE_MIPS_LOONGSON]: New array. + (grub_serial_register) [GRUB_MACHINE_MIPS_LOONGSON]: Use + loongson_defserial. + * include/grub/mips/loongson/kernel.h (GRUB_ARCH_MACHINE_FULOONG): + Rename to ... + (GRUB_ARCH_MACHINE_FULOONG2F): ... this. + (GRUB_ARCH_MACHINE_FULOONG2E): New const. + * util/grub-mkimage.c (image_target_desc): Rename IMAGE_FULOONG_FLASH + to IMAGE_FULOONG2F_FLASH. All users updated. + (image_targets): Rename images. + * util/grub-mkstandalone.in: Accept fuloong2f and fuloong2e. + 2011-08-19 Szymon Janc Make enable of disk cache statistics code configurable. diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def index de57d2f0c..f129e98db 100644 --- a/grub-core/Makefile.core.def +++ b/grub-core/Makefile.core.def @@ -363,8 +363,8 @@ image = { }; image = { - name = fwstart_fuloong; - mips_loongson = boot/mips/loongson/fuloong.S; + name = fwstart_fuloong2f; + mips_loongson = boot/mips/loongson/fuloong2f.S; objcopyflags = '-O binary'; ldflags = '-static-libgcc -lgcc -Wl,-N,-S,-Ttext,0xbfc00000,-Bstatic'; enable = mips_loongson; diff --git a/grub-core/boot/mips/loongson/fuloong.S b/grub-core/boot/mips/loongson/fuloong2f.S similarity index 51% rename from grub-core/boot/mips/loongson/fuloong.S rename to grub-core/boot/mips/loongson/fuloong2f.S index 5df0d54c1..a88c81efe 100644 --- a/grub-core/boot/mips/loongson/fuloong.S +++ b/grub-core/boot/mips/loongson/fuloong2f.S @@ -1,2 +1,2 @@ -#define FULOONG 1 +#define FULOONG2F 1 #include "fwstart.S" diff --git a/grub-core/boot/mips/loongson/fwstart.S b/grub-core/boot/mips/loongson/fwstart.S index 38e87ad72..7ed5d30ae 100644 --- a/grub-core/boot/mips/loongson/fwstart.S +++ b/grub-core/boot/mips/loongson/fwstart.S @@ -26,7 +26,7 @@ #include #include -#ifdef FULOONG +#ifdef FULOONG2F #define GRUB_MACHINE_SERIAL_PORT GRUB_MACHINE_SERIAL_PORT2 #define GRUB_MACHINE_SERIAL_DIVISOR_115200 GRUB_MACHINE_SERIAL_PORT2_DIVISOR_115200 #else @@ -43,10 +43,10 @@ start: _start: __start: - /* Put serial init as soon as possible. But on Fuloong serial is past - Geode, so on Fuloong we need Geode first. + /* Put serial init as soon as possible. But on Fuloong2f serial is past + Geode, so on Fuloong2f we need Geode first. */ -#ifndef FULOONG +#ifndef FULOONG2F bal serial_hw_init nop #endif @@ -72,7 +72,7 @@ retry_cs5536: bnel $t2, $t3, 1b sll $t4, $t4, 1 -#ifndef FULOONG +#ifndef FULOONG2F bal message addiu $a0, $a0, %lo(cs5536_found) bal printhex @@ -95,7 +95,7 @@ retry_cs5536: bal gpio_init nop -#ifdef FULOONG +#ifdef FULOONG2F bal serial_hw_init nop #endif @@ -130,7 +130,7 @@ retry_cs5536: sb $t1, %lo(GRUB_MACHINE_PCI_IO_BASE + GRUB_CS5536_LBAR_SMBUS + GRUB_CS5536_SMB_REG_CTRL3) ($t0) sb $t1, %lo(GRUB_MACHINE_PCI_IO_BASE + GRUB_CS5536_LBAR_SMBUS + GRUB_CS5536_SMB_REG_CTRL2) ($t0) - /* Yeeloong and Fuloong have only one memory slot. */ + /* Yeeloong and Fuloong2f have only one memory slot. */ /* Output first byte on serial for debugging. */ ori $a1, $zero, GRUB_SMB_RAM_START_ADDR bal read_spd @@ -252,7 +252,7 @@ gpio_init: /* In: none. Out: none. Clobbered: $t0, $t1, $t2, $a0, $a1, $a2. */ serial_hw_init: move $t2, $ra -#ifdef FULOONG +#ifdef FULOONG2F lui $a0, %hi(GRUB_CS5536_MSR_DIVIL_LEG_IO) addiu $a0, $a0, %lo(GRUB_CS5536_MSR_DIVIL_LEG_IO) lui $a1, %hi (GRUB_CS5536_MSR_DIVIL_LEG_IO_UART2_COM3 \ @@ -471,7 +471,7 @@ regdump: .quad 0x0100020200010101 /* 4 */ .quad 0x0a04030603050203 /* 6 */ .quad 0x0f0e040000010a0b /* 7 */ -#ifdef FULOONG +#ifdef FULOONG2F .quad 0x0000000100000001 /* 8 */ #else .quad 0x0000010200000102 /* 8 */ @@ -482,7 +482,7 @@ regdump: .quad 0x002a3c0615000000 /* c */ .quad 0x002a002a002a002a /* d */ .quad 0x002a002a002a002a /* e */ -#ifdef FULOONG +#ifdef FULOONG2F .quad 0x00b40020005b0004 /* f */ #else .quad 0x00b40020006d0004 /* f */ @@ -503,7 +503,7 @@ regdump: /* Dump of GPIO connections. FIXME: Remove useless and macroify. */ gpio_dump: -#ifdef FULOONG +#ifdef FULOONG2F .long 0xffff0000, 0x2eefd110, 0xffff0000, 0xffff0000 .long 0x2eefd110, 0xffff0000, 0x1000efff, 0xefff1000 .long 0x3df3c20c, 0xffff0000, 0xffff0000, 0xffff0000 @@ -740,8 +740,8 @@ continue: lui $t0, %hi(cached_continue - 0x20000000) addiu $t0, $t0, %lo(cached_continue - 0x20000000) jr $t0 -#ifdef FULOONG - addiu $a2, $zero, -(1 + GRUB_ARCH_MACHINE_FULOONG) +#ifdef FULOONG2F + addiu $a2, $zero, -(1 + GRUB_ARCH_MACHINE_FULOONG2F) #else addiu $a2, $zero, -(1 + GRUB_ARCH_MACHINE_YEELOONG) #endif diff --git a/grub-core/boot/mips/startup_raw.S b/grub-core/boot/mips/startup_raw.S index 4ecff5efd..aefd387b6 100644 --- a/grub-core/boot/mips/startup_raw.S +++ b/grub-core/boot/mips/startup_raw.S @@ -109,7 +109,7 @@ argcont: DO_PARSE (memsizestr, $s4) DO_PARSE (highmemsizestr, $s5) DO_CHECKT1 (pmon_yeeloong_verstr, GRUB_ARCH_MACHINE_YEELOONG) - DO_CHECKT1 (pmon_fuloong_verstr, GRUB_ARCH_MACHINE_FULOONG) + DO_CHECKT1 (pmon_fuloong2f_verstr, GRUB_ARCH_MACHINE_FULOONG2F) 2: b argcont addiu $t0, $t0, 4 @@ -155,11 +155,12 @@ memsizestr: .asciiz "memsize=" highmemsizestr: .asciiz "highmemsize=" machtype_yeeloong_str1: .asciiz "machtype=8.9" machtype_yeeloong_str2: .asciiz "machtype=lemote-yeeloong-" -machtype_fuloong_str: .asciiz "machtype=lemote-fuloong-" +machtype_fuloong2f_str: .asciiz "machtype=lemote-fuloong-2f" +machtype_fuloong2e_str: .asciiz "machtype=lemote-fuloong-2e" pmon_yeeloong_str: .asciiz "PMON_VER=LM8" -pmon_fuloong_str: .asciiz "PMON_VER=LM6" +pmon_fuloong2f_str: .asciiz "PMON_VER=LM6" pmon_yeeloong_verstr: .asciiz "Version=LM8" -pmon_fuloong_verstr: .asciiz "Version=LM6" +pmon_fuloong2f_verstr: .asciiz "Version=LM6" .p2align 2 argdone: @@ -173,8 +174,9 @@ argdone: DO_CHECKA1 (machtype_yeeloong_str1, GRUB_ARCH_MACHINE_YEELOONG) DO_CHECKA1 (machtype_yeeloong_str2, GRUB_ARCH_MACHINE_YEELOONG) DO_CHECKA1 (pmon_yeeloong_str, GRUB_ARCH_MACHINE_YEELOONG) - DO_CHECKA1 (machtype_fuloong_str, GRUB_ARCH_MACHINE_FULOONG) - DO_CHECKA1 (pmon_fuloong_str, GRUB_ARCH_MACHINE_FULOONG) + DO_CHECKA1 (machtype_fuloong2f_str, GRUB_ARCH_MACHINE_FULOONG2F) + DO_CHECKA1 (machtype_fuloong2e_str, GRUB_ARCH_MACHINE_FULOONG2E) + DO_CHECKA1 (pmon_fuloong2f_str, GRUB_ARCH_MACHINE_FULOONG2F) addiu $a0, $a0, -1 b argdone addiu $a1, $a1, 4 diff --git a/grub-core/bus/cs5536.c b/grub-core/bus/cs5536.c index 58ffeb60a..1aae7852e 100644 --- a/grub-core/bus/cs5536.c +++ b/grub-core/bus/cs5536.c @@ -281,7 +281,7 @@ grub_cs5536_init_geode (grub_pci_device_t dev) | GRUB_CS5536_MSR_DIVIL_LEG_IO_RTC_ENABLE0 | GRUB_CS5536_MSR_DIVIL_LEG_IO_RTC_ENABLE1); break; - case GRUB_ARCH_MACHINE_FULOONG: + case GRUB_ARCH_MACHINE_FULOONG2F: grub_cs5536_write_msr (dev, GRUB_CS5536_MSR_DIVIL_LEG_IO, GRUB_CS5536_MSR_DIVIL_LEG_IO_UART2_COM3 | GRUB_CS5536_MSR_DIVIL_LEG_IO_UART1_COM1 diff --git a/grub-core/kern/mips/loongson/init.c b/grub-core/kern/mips/loongson/init.c index bcef391b9..0e4948beb 100644 --- a/grub-core/kern/mips/loongson/init.c +++ b/grub-core/kern/mips/loongson/init.c @@ -213,7 +213,9 @@ grub_halt (void) { switch (grub_arch_machine) { - case GRUB_ARCH_MACHINE_FULOONG: + case GRUB_ARCH_MACHINE_FULOONG2E: + break; + case GRUB_ARCH_MACHINE_FULOONG2F: { grub_pci_device_t dev; grub_port_t p; diff --git a/grub-core/kern/mips/startup.S b/grub-core/kern/mips/startup.S index 6220a8c33..da6450237 100644 --- a/grub-core/kern/mips/startup.S +++ b/grub-core/kern/mips/startup.S @@ -61,7 +61,7 @@ VARIABLE (grub_arch_highmemsize) .long 0 #ifdef GRUB_MACHINE_MIPS_LOONGSON VARIABLE (grub_arch_machine) - .long GRUB_ARCH_MACHINE_FULOONG + .long GRUB_ARCH_MACHINE_FULOONG2F #endif cont: /* Save our base. */ diff --git a/grub-core/loader/mips/linux.c b/grub-core/loader/mips/linux.c index 64c4a0531..2b4875983 100644 --- a/grub-core/loader/mips/linux.c +++ b/grub-core/loader/mips/linux.c @@ -41,7 +41,8 @@ GRUB_MOD_LICENSE ("GPLv3+"); const char loongson_machtypes[][60] = { [GRUB_ARCH_MACHINE_YEELOONG] = "machtype=lemote-yeeloong-2f-8.9inches", - [GRUB_ARCH_MACHINE_FULOONG] = "machtype=lemote-fuloong-2f-unknown" + [GRUB_ARCH_MACHINE_FULOONG2F] = "machtype=lemote-fuloong-2f-unknown", + [GRUB_ARCH_MACHINE_FULOONG2E] = "machtype=lemote-fuloong-2e-unknown" }; #endif diff --git a/grub-core/term/serial.c b/grub-core/term/serial.c index 0381349a4..b724a945a 100644 --- a/grub-core/term/serial.c +++ b/grub-core/term/serial.c @@ -239,6 +239,15 @@ grub_cmd_serial (grub_extcmd_context_t ctxt, int argc, char **args) return GRUB_ERR_NONE; } +#ifdef GRUB_MACHINE_MIPS_LOONGSON +const char loongson_defserial[][6] = + { + [GRUB_ARCH_MACHINE_YEELOONG] = "com0", + [GRUB_ARCH_MACHINE_FULOONG2F] = "com2", + [GRUB_ARCH_MACHINE_FULOONG2E] = "com1" + }; +#endif + grub_err_t grub_serial_register (struct grub_serial_port *port) { @@ -301,9 +310,7 @@ grub_serial_register (struct grub_serial_port *port) port->term_out = out; grub_terminfo_output_register (out, "vt100"); #ifdef GRUB_MACHINE_MIPS_LOONGSON - if (grub_strcmp (port->name, - (grub_arch_machine == GRUB_ARCH_MACHINE_YEELOONG) - ? "com0" : "com2") == 0) + if (grub_strcmp (port->name, loongson_defserial[grub_arch_machine]) == 0) { grub_term_register_input_active ("serial_*", in); grub_term_register_output_active ("serial_*", out); diff --git a/include/grub/mips/loongson/kernel.h b/include/grub/mips/loongson/kernel.h index 612221ed2..ba94e4331 100644 --- a/include/grub/mips/loongson/kernel.h +++ b/include/grub/mips/loongson/kernel.h @@ -23,7 +23,8 @@ #include #define GRUB_ARCH_MACHINE_YEELOONG 0 -#define GRUB_ARCH_MACHINE_FULOONG 1 +#define GRUB_ARCH_MACHINE_FULOONG2F 1 +#define GRUB_ARCH_MACHINE_FULOONG2E 2 #ifndef ASM_FILE diff --git a/util/grub-mkimage.c b/util/grub-mkimage.c index b05507242..420690923 100644 --- a/util/grub-mkimage.c +++ b/util/grub-mkimage.c @@ -67,7 +67,7 @@ struct image_target_desc IMAGE_I386_PC, IMAGE_EFI, IMAGE_COREBOOT, IMAGE_SPARC64_AOUT, IMAGE_SPARC64_RAW, IMAGE_I386_IEEE1275, IMAGE_LOONGSON_ELF, IMAGE_QEMU, IMAGE_PPC, IMAGE_YEELOONG_FLASH, - IMAGE_FULOONG_FLASH, IMAGE_I386_PC_PXE, IMAGE_MIPS_ARC, + IMAGE_FULOONG2F_FLASH, IMAGE_I386_PC_PXE, IMAGE_MIPS_ARC, IMAGE_QEMU_MIPS_FLASH } id; enum @@ -298,10 +298,10 @@ struct image_target_desc image_targets[] = }, { .dirname = "mipsel-loongson", - .names = { "mipsel-fuloong-flash", NULL }, + .names = { "mipsel-fuloong2f-flash", NULL }, .voidp_sizeof = 4, .bigendian = 0, - .id = IMAGE_FULOONG_FLASH, + .id = IMAGE_FULOONG2F_FLASH, .flags = PLATFORM_FLAGS_DECOMPRESSORS, .prefix = GRUB_KERNEL_MIPS_LOONGSON_PREFIX, .prefix_end = GRUB_KERNEL_MIPS_LOONGSON_PREFIX_END, @@ -321,6 +321,7 @@ struct image_target_desc image_targets[] = { .dirname = "mipsel-loongson", .names = { "mipsel-loongson-elf", "mipsel-yeeloong-elf", + "mipsel-fuloong2f-elf", "mipsel-fuloong2e-elf", "mipsel-fuloong-elf", NULL }, .voidp_sizeof = 4, .bigendian = 0, @@ -1362,7 +1363,7 @@ generate_image (const char *dir, char *prefix, FILE *out, char *mods[], } break; case IMAGE_YEELOONG_FLASH: - case IMAGE_FULOONG_FLASH: + case IMAGE_FULOONG2F_FLASH: { char *rom_img; size_t rom_size; @@ -1381,7 +1382,7 @@ generate_image (const char *dir, char *prefix, FILE *out, char *mods[], 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; /* None yet. */ - const grub_uint8_t fuloong_fwstart_good_hash[512 / 8] = + const grub_uint8_t fuloong2f_fwstart_good_hash[512 / 8] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, @@ -1393,10 +1394,10 @@ generate_image (const char *dir, char *prefix, FILE *out, char *mods[], }; const grub_uint8_t *fwstart_good_hash; - if (image_target->id == IMAGE_FULOONG_FLASH) + if (image_target->id == IMAGE_FULOONG2F_FLASH) { - fwstart_good_hash = fuloong_fwstart_good_hash; - boot_path = grub_util_get_path (dir, "fwstart_fuloong.img"); + fwstart_good_hash = fuloong2f_fwstart_good_hash; + boot_path = grub_util_get_path (dir, "fwstart_fuloong2f.img"); } else { diff --git a/util/grub-mkstandalone.in b/util/grub-mkstandalone.in index aaff99051..e140ecc82 100644 --- a/util/grub-mkstandalone.in +++ b/util/grub-mkstandalone.in @@ -136,7 +136,7 @@ if [ "x$source_directory" = x ] ; then cpu="`echo $format | awk -F - '{ print $1; }'`" platform="`echo $format | awk -F - '{ print $2; }'`" case "$platform" in - yeeloong | fuloong) + yeeloong | fuloong | fuloong2f | fuloong2e) platform=loongson ;; esac case "$cpu-$platform" in From 9594c6897ec93b27066244a71005f262dab91f82 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 19 Aug 2011 22:49:48 +0200 Subject: [PATCH 780/869] * configure.ac: Don't impose march=loongson2f on loongson platform. (It can still be specified in TARGET_CFLAGS) --- ChangeLog | 5 +++++ configure.ac | 17 ----------------- 2 files changed, 5 insertions(+), 17 deletions(-) diff --git a/ChangeLog b/ChangeLog index fdc89b5a2..c2f501c00 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-08-19 Vladimir Serbinenko + + * configure.ac: Don't impose march=loongson2f on loongson platform. (It + can still be specified in TARGET_CFLAGS) + 2011-08-19 Vladimir Serbinenko Rename Fuloong into Fuloong 2F. Add new ID for Fuloong2E. diff --git a/configure.ac b/configure.ac index 224c9c9de..9cfbd2340 100644 --- a/configure.ac +++ b/configure.ac @@ -412,23 +412,6 @@ if test "x$grub_cv_cc_fno_dwarf2_cfi_asm" = xyes; then TARGET_CFLAGS="$TARGET_CFLAGS -fno-dwarf2-cfi-asm" fi -if test "${target_cpu}-${platform}" = mipsel-loongson; then - AC_CACHE_CHECK([whether -march=loongson2f works], [grub_cv_cc_march_loongson2f], [ - SAVE_CFLAGS="$CFLAGS" - CFLAGS="$CFLAGS -march=loongson2f" - AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])], - [grub_cv_cc_march_loongson2f=yes], - [grub_cv_cc_march_loongson2f=no]) - CFLAGS="$SAVE_CFLAGS" - ]) - - if test "x$grub_cv_cc_march_loongson2f" = xyes; then - TARGET_CFLAGS="$TARGET_CFLAGS -march=loongson2f" - else - TARGET_CFLAGS="$TARGET_CFLAGS -march=mips3" - fi -fi - grub_apple_target_cc if test x$grub_cv_apple_target_cc = xyes ; then TARGET_CPPFLAGS="$TARGET_CPPFLAGS -DAPPLE_CC=1" From 1227c1339017349e6d011fe4bc927ff394141272 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 19 Aug 2011 22:56:49 +0200 Subject: [PATCH 781/869] Fix PCI iterating on functions >= 4. * grub-core/bus/pci.c (grub_pci_iterate): Remove useless ghost skipping. * include/grub/mips/loongson/pci.h (GRUB_LOONGSON_OHCI_GHOST_FUNCTION): Removed. (GRUB_LOONGSON_EHCI_GHOST_FUNCTION): Likewise. (grub_pci_read): Fix bitmask. (grub_pci_read_word): Likewise. (grub_pci_read_byte): Likewise. (grub_pci_write): Likewise. (grub_pci_write_word): Likewise. (grub_pci_write_byte): Likewise. --- ChangeLog | 15 +++++++++++++++ grub-core/bus/pci.c | 10 ---------- include/grub/mips/loongson/pci.h | 14 ++++++-------- 3 files changed, 21 insertions(+), 18 deletions(-) diff --git a/ChangeLog b/ChangeLog index c2f501c00..cfd46dad7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +2011-08-19 Vladimir Serbinenko + + Fix PCI iterating on functions >= 4. + + * grub-core/bus/pci.c (grub_pci_iterate): Remove useless ghost skipping. + * include/grub/mips/loongson/pci.h (GRUB_LOONGSON_OHCI_GHOST_FUNCTION): + Removed. + (GRUB_LOONGSON_EHCI_GHOST_FUNCTION): Likewise. + (grub_pci_read): Fix bitmask. + (grub_pci_read_word): Likewise. + (grub_pci_read_byte): Likewise. + (grub_pci_write): Likewise. + (grub_pci_write_word): Likewise. + (grub_pci_write_byte): Likewise. + 2011-08-19 Vladimir Serbinenko * configure.ac: Don't impose march=loongson2f on loongson platform. (It diff --git a/grub-core/bus/pci.c b/grub-core/bus/pci.c index 51006a20e..f007ec33a 100644 --- a/grub-core/bus/pci.c +++ b/grub-core/bus/pci.c @@ -115,16 +115,6 @@ grub_pci_iterate (grub_pci_iteratefunc_t hook) continue; } -#ifdef GRUB_MACHINE_MIPS_LOONGSON - /* Skip ghosts. */ - if (id == GRUB_LOONGSON_OHCI_PCIID - && dev.function == GRUB_LOONGSON_OHCI_GHOST_FUNCTION) - continue; - if (id == GRUB_LOONGSON_EHCI_PCIID - && dev.function == GRUB_LOONGSON_EHCI_GHOST_FUNCTION) - continue; -#endif - if (hook (dev, id)) return; diff --git a/include/grub/mips/loongson/pci.h b/include/grub/mips/loongson/pci.h index 3f828c2f8..57c7dd1fc 100644 --- a/include/grub/mips/loongson/pci.h +++ b/include/grub/mips/loongson/pci.h @@ -26,8 +26,6 @@ #define GRUB_LOONGSON_OHCI_PCIID 0x00351033 #define GRUB_LOONGSON_EHCI_PCIID 0x00e01033 -#define GRUB_LOONGSON_OHCI_GHOST_FUNCTION 4 -#define GRUB_LOONGSON_EHCI_GHOST_FUNCTION 5 #define GRUB_PCI_NUM_BUS 1 #define GRUB_PCI_NUM_DEVICES 16 @@ -66,7 +64,7 @@ grub_pci_read (grub_pci_address_t addr) { GRUB_MACHINE_PCI_CONF_CTRL_REG = 1 << ((addr >> 11) & 0xf); return *(volatile grub_uint32_t *) (GRUB_MACHINE_PCI_CONFSPACE - | (addr & 0x03ff)); + | (addr & 0x07ff)); } static inline grub_uint16_t @@ -74,7 +72,7 @@ grub_pci_read_word (grub_pci_address_t addr) { GRUB_MACHINE_PCI_CONF_CTRL_REG = 1 << ((addr >> 11) & 0xf); return *(volatile grub_uint16_t *) (GRUB_MACHINE_PCI_CONFSPACE - | (addr & 0x03ff)); + | (addr & 0x07ff)); } static inline grub_uint8_t @@ -82,7 +80,7 @@ grub_pci_read_byte (grub_pci_address_t addr) { GRUB_MACHINE_PCI_CONF_CTRL_REG = 1 << ((addr >> 11) & 0xf); return *(volatile grub_uint8_t *) (GRUB_MACHINE_PCI_CONFSPACE - | (addr & 0x03ff)); + | (addr & 0x07ff)); } static inline void @@ -90,7 +88,7 @@ grub_pci_write (grub_pci_address_t addr, grub_uint32_t data) { GRUB_MACHINE_PCI_CONF_CTRL_REG = 1 << ((addr >> 11) & 0xf); *(volatile grub_uint32_t *) (GRUB_MACHINE_PCI_CONFSPACE - | (addr & 0x03ff)) = data; + | (addr & 0x07ff)) = data; } static inline void @@ -98,7 +96,7 @@ grub_pci_write_word (grub_pci_address_t addr, grub_uint16_t data) { GRUB_MACHINE_PCI_CONF_CTRL_REG = 1 << ((addr >> 11) & 0xf); *(volatile grub_uint16_t *) (GRUB_MACHINE_PCI_CONFSPACE - | (addr & 0x03ff)) = data; + | (addr & 0x07ff)) = data; } static inline void @@ -106,7 +104,7 @@ grub_pci_write_byte (grub_pci_address_t addr, grub_uint8_t data) { GRUB_MACHINE_PCI_CONF_CTRL_REG = 1 << ((addr >> 11) & 0xf); *(volatile grub_uint8_t *) (GRUB_MACHINE_PCI_CONFSPACE - | (addr & 0x03ff)) = data; + | (addr & 0x07ff)) = data; } volatile void * From 84beb0eeb95ef792fd1bab516324e62f0fb50b09 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 19 Aug 2011 22:59:24 +0200 Subject: [PATCH 782/869] * grub-core/kern/misc.c (grub_vprintf): Fix a bug on malloc failure. --- ChangeLog | 4 ++++ grub-core/kern/misc.c | 1 + 2 files changed, 5 insertions(+) diff --git a/ChangeLog b/ChangeLog index cfd46dad7..5e45756c8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2011-08-19 Vladimir Serbinenko + + * grub-core/kern/misc.c (grub_vprintf): Fix a bug on malloc failure. + 2011-08-19 Vladimir Serbinenko Fix PCI iterating on functions >= 4. diff --git a/grub-core/kern/misc.c b/grub-core/kern/misc.c index a3dfabf82..ebf80f100 100644 --- a/grub-core/kern/misc.c +++ b/grub-core/kern/misc.c @@ -210,6 +210,7 @@ grub_vprintf (const char *fmt, va_list args) buf[PREALLOC_SIZE - 2] = '.'; buf[PREALLOC_SIZE - 1] = '.'; buf[PREALLOC_SIZE] = 0; + curbuf = buf; } else s = grub_vsnprintf_real (curbuf, s, fmt, ap2); From 0d1fd0113ba001d6fd379274e34ff7c3782ee347 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 19 Aug 2011 23:04:18 +0200 Subject: [PATCH 783/869] * include/grub/mips/loongson.h (GRUB_CPU_LOONGSON_COP0_PRID): New define. * grub-core/kern/mips/loongson/init.c (grub_machine_init): Check that PRID matches the detected subplatform and reset the subplatform if it doesn't. --- ChangeLog | 8 ++++++++ grub-core/kern/mips/loongson/init.c | 17 +++++++++++++++++ include/grub/mips/loongson.h | 1 + 3 files changed, 26 insertions(+) diff --git a/ChangeLog b/ChangeLog index 5e45756c8..23283d924 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2011-08-19 Vladimir Serbinenko + + * include/grub/mips/loongson.h (GRUB_CPU_LOONGSON_COP0_PRID): New + define. + * grub-core/kern/mips/loongson/init.c (grub_machine_init): Check + that PRID matches the detected subplatform and reset the subplatform + if it doesn't. + 2011-08-19 Vladimir Serbinenko * grub-core/kern/misc.c (grub_vprintf): Fix a bug on malloc failure. diff --git a/grub-core/kern/mips/loongson/init.c b/grub-core/kern/mips/loongson/init.c index 0e4948beb..7df0ec876 100644 --- a/grub-core/kern/mips/loongson/init.c +++ b/grub-core/kern/mips/loongson/init.c @@ -123,6 +123,23 @@ void grub_machine_init (void) { grub_addr_t modend; + grub_uint32_t prid; + + asm volatile ("mfc0 %0, " GRUB_CPU_LOONGSON_COP0_PRID : "=r" (prid)); + + switch (prid) + { + /* Loongson 2E. */ + case 0x6302: + grub_arch_machine = GRUB_ARCH_MACHINE_FULOONG2E; + break; + /* Loongson 2F. */ + case 0x6303: + if (grub_arch_machine != GRUB_ARCH_MACHINE_FULOONG2F + && grub_arch_machine != GRUB_ARCH_MACHINE_YEELOONG) + grub_arch_machine = GRUB_ARCH_MACHINE_YEELOONG; + break; + } /* FIXME: measure this. */ if (grub_arch_busclock == 0) diff --git a/include/grub/mips/loongson.h b/include/grub/mips/loongson.h index ce5eb5e3d..e6f0241f2 100644 --- a/include/grub/mips/loongson.h +++ b/include/grub/mips/loongson.h @@ -66,6 +66,7 @@ #define GRUB_CPU_LOONGSON_COP0_BADVADDR GRUB_CPU_REGISTER_WRAP($8) #define GRUB_CPU_LOONGSON_COP0_CAUSE GRUB_CPU_REGISTER_WRAP($13) #define GRUB_CPU_LOONGSON_COP0_EPC GRUB_CPU_REGISTER_WRAP($14) +#define GRUB_CPU_LOONGSON_COP0_PRID GRUB_CPU_REGISTER_WRAP($15) #define GRUB_CPU_LOONGSON_COP0_CACHE_TAGLO GRUB_CPU_REGISTER_WRAP($28) #define GRUB_CPU_LOONGSON_COP0_CACHE_TAGHI GRUB_CPU_REGISTER_WRAP($29) From d94497eacaac10d678f1d4919ac257ce7040c6d8 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 19 Aug 2011 23:08:36 +0200 Subject: [PATCH 784/869] * grub-core/Makefile.core.def (kernel): Add video/radeon_fuloong2e.c on loongson. * grub-core/kern/mips/loongson/init.c (grub_machine_init): Init video_radeon_fuloong2e. * grub-core/video/radeon_fuloong2e.c: New file. * include/grub/video.h (grub_video_id_t): Add new ID GRUB_VIDEO_DRIVER_RADEON_FULOONG2E. --- ChangeLog | 10 ++ grub-core/Makefile.core.def | 1 + grub-core/kern/mips/loongson/init.c | 2 + grub-core/video/radeon_fuloong2e.c | 231 ++++++++++++++++++++++++++++ include/grub/video.h | 1 + 5 files changed, 245 insertions(+) create mode 100644 grub-core/video/radeon_fuloong2e.c diff --git a/ChangeLog b/ChangeLog index 23283d924..2bff79544 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2011-08-19 Vladimir Serbinenko + + * grub-core/Makefile.core.def (kernel): Add video/radeon_fuloong2e.c on + loongson. + * grub-core/kern/mips/loongson/init.c (grub_machine_init): Init + video_radeon_fuloong2e. + * grub-core/video/radeon_fuloong2e.c: New file. + * include/grub/video.h (grub_video_id_t): Add new ID + GRUB_VIDEO_DRIVER_RADEON_FULOONG2E. + 2011-08-19 Vladimir Serbinenko * include/grub/mips/loongson.h (GRUB_CPU_LOONGSON_COP0_PRID): New diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def index f129e98db..e95d87d37 100644 --- a/grub-core/Makefile.core.def +++ b/grub-core/Makefile.core.def @@ -180,6 +180,7 @@ kernel = { mips_loongson = term/serial.c; mips_loongson = video/sm712.c; mips_loongson = video/sis315pro.c; + mips_loongson = video/radeon_fuloong2e.c; extra_dist = video/sm712_init.c; mips_loongson = commands/keylayouts.c; diff --git a/grub-core/kern/mips/loongson/init.c b/grub-core/kern/mips/loongson/init.c index 7df0ec876..5a95d29ed 100644 --- a/grub-core/kern/mips/loongson/init.c +++ b/grub-core/kern/mips/loongson/init.c @@ -35,6 +35,7 @@ extern void grub_video_sm712_init (void); extern void grub_video_sis315pro_init (void); +extern void grub_video_radeon_fuloong2e_init (void); extern void grub_video_init (void); extern void grub_bitmap_init (void); extern void grub_font_init (void); @@ -206,6 +207,7 @@ grub_machine_init (void) grub_video_init (); grub_video_sm712_init (); grub_video_sis315pro_init (); + grub_video_radeon_fuloong2e_init (); grub_bitmap_init (); grub_font_init (); grub_gfxterm_init (); diff --git a/grub-core/video/radeon_fuloong2e.c b/grub-core/video/radeon_fuloong2e.c new file mode 100644 index 000000000..3a65b6720 --- /dev/null +++ b/grub-core/video/radeon_fuloong2e.c @@ -0,0 +1,231 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2005,2006,2007,2008,2009,2010,2011 Free Software Foundation, Inc. + * + * GRUB is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see . + */ + +#define grub_video_render_target grub_video_fbrender_target + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define GRUB_RADEON_FULOONG2E_TOTAL_MEMORY_SPACE 1048576 + +static struct +{ + struct grub_video_mode_info mode_info; + struct grub_video_render_target *render_target; + + grub_uint8_t *ptr; + int mapped; + grub_uint32_t base; + grub_pci_device_t dev; +} framebuffer; + +static grub_err_t +grub_video_radeon_fuloong2e_video_init (void) +{ + /* Reset frame buffer. */ + grub_memset (&framebuffer, 0, sizeof(framebuffer)); + + return grub_video_fb_init (); +} + +static grub_err_t +grub_video_radeon_fuloong2e_video_fini (void) +{ + if (framebuffer.mapped) + grub_pci_device_unmap_range (framebuffer.dev, framebuffer.ptr, + GRUB_RADEON_FULOONG2E_TOTAL_MEMORY_SPACE); + + return grub_video_fb_fini (); +} + +static grub_err_t +grub_video_radeon_fuloong2e_setup (unsigned int width, unsigned int height, + unsigned int mode_type, unsigned int mode_mask __attribute__ ((unused))) +{ + int depth; + grub_err_t err; + int found = 0; + +#ifndef TEST + 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))) + { + grub_pci_address_t addr; + grub_uint32_t class; + + addr = grub_pci_make_address (dev, GRUB_PCI_REG_CLASS); + class = grub_pci_read (addr); + + if (((class >> 16) & 0xffff) != GRUB_PCI_CLASS_SUBCLASS_VGA + || pciid != 0x515a1002) + return 0; + + found = 1; + + addr = grub_pci_make_address (dev, GRUB_PCI_REG_ADDRESS_REG0); + framebuffer.base = grub_pci_read (addr); + framebuffer.dev = dev; + + return 1; + } + + /* Decode depth from mode_type. If it is zero, then autodetect. */ + depth = (mode_type & GRUB_VIDEO_MODE_TYPE_DEPTH_MASK) + >> GRUB_VIDEO_MODE_TYPE_DEPTH_POS; + + if ((width != 640 && width != 0) || (height != 480 && height != 0) + || (depth != 16 && depth != 0)) + return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, + "Only 1024x600x16 is supported"); + + grub_pci_iterate (find_card); + if (!found) + return grub_error (GRUB_ERR_IO, "Couldn't find graphics card"); +#endif + /* Fill mode info details. */ + framebuffer.mode_info.width = 640; + framebuffer.mode_info.height = 480; + framebuffer.mode_info.mode_type = GRUB_VIDEO_MODE_TYPE_RGB; + framebuffer.mode_info.bpp = 16; + framebuffer.mode_info.bytes_per_pixel = 2; + framebuffer.mode_info.pitch = 640 * 2; + framebuffer.mode_info.number_of_colors = 256; + framebuffer.mode_info.red_mask_size = 5; + framebuffer.mode_info.red_field_pos = 11; + framebuffer.mode_info.green_mask_size = 6; + framebuffer.mode_info.green_field_pos = 5; + framebuffer.mode_info.blue_mask_size = 5; + framebuffer.mode_info.blue_field_pos = 0; + framebuffer.mode_info.reserved_mask_size = 0; + framebuffer.mode_info.reserved_field_pos = 0; +#ifndef TEST + framebuffer.mode_info.blit_format + = grub_video_get_blit_format (&framebuffer.mode_info); +#endif + + /* We can safely discard volatile attribute. */ +#ifndef TEST + framebuffer.ptr + = (void *) grub_pci_device_map_range (framebuffer.dev, + framebuffer.base, + GRUB_RADEON_FULOONG2E_TOTAL_MEMORY_SPACE); +#endif + framebuffer.mapped = 1; + + /* Prevent garbage from appearing on the screen. */ + grub_memset (framebuffer.ptr, 0x55, + framebuffer.mode_info.height * framebuffer.mode_info.pitch); + +#ifndef TEST + err = grub_video_fb_create_render_target_from_pointer (&framebuffer + .render_target, + &framebuffer.mode_info, + framebuffer.ptr); + + if (err) + return err; + + err = grub_video_fb_set_active_render_target (framebuffer.render_target); + + if (err) + return err; + + /* Copy default palette to initialize emulated palette. */ + err = grub_video_fb_set_palette (0, GRUB_VIDEO_FBSTD_NUMCOLORS, + grub_video_fbstd_colors); +#endif + return err; +} + +static grub_err_t +grub_video_radeon_fuloong2e_swap_buffers (void) +{ + /* TODO: Implement buffer swapping. */ + return GRUB_ERR_NONE; +} + +static grub_err_t +grub_video_radeon_fuloong2e_set_active_render_target (struct grub_video_render_target *target) +{ + if (target == GRUB_VIDEO_RENDER_TARGET_DISPLAY) + target = framebuffer.render_target; + + return grub_video_fb_set_active_render_target (target); +} + +static grub_err_t +grub_video_radeon_fuloong2e_get_info_and_fini (struct grub_video_mode_info *mode_info, + void **framebuf) +{ + grub_memcpy (mode_info, &(framebuffer.mode_info), sizeof (*mode_info)); + *framebuf = (char *) framebuffer.ptr; + + grub_video_fb_fini (); + + return GRUB_ERR_NONE; +} + +static struct grub_video_adapter grub_video_radeon_fuloong2e_adapter = + { + .name = "RADEON RV100 QZ (Fuloong2E) Video Driver", + .id = GRUB_VIDEO_DRIVER_RADEON_FULOONG2E, + + .prio = GRUB_VIDEO_ADAPTER_PRIO_NATIVE, + + .init = grub_video_radeon_fuloong2e_video_init, + .fini = grub_video_radeon_fuloong2e_video_fini, + .setup = grub_video_radeon_fuloong2e_setup, + .get_info = grub_video_fb_get_info, + .get_info_and_fini = grub_video_radeon_fuloong2e_get_info_and_fini, + .set_palette = grub_video_fb_set_palette, + .get_palette = grub_video_fb_get_palette, + .set_viewport = grub_video_fb_set_viewport, + .get_viewport = grub_video_fb_get_viewport, + .map_color = grub_video_fb_map_color, + .map_rgb = grub_video_fb_map_rgb, + .map_rgba = grub_video_fb_map_rgba, + .unmap_color = grub_video_fb_unmap_color, + .fill_rect = grub_video_fb_fill_rect, + .blit_bitmap = grub_video_fb_blit_bitmap, + .blit_render_target = grub_video_fb_blit_render_target, + .scroll = grub_video_fb_scroll, + .swap_buffers = grub_video_radeon_fuloong2e_swap_buffers, + .create_render_target = grub_video_fb_create_render_target, + .delete_render_target = grub_video_fb_delete_render_target, + .set_active_render_target = grub_video_radeon_fuloong2e_set_active_render_target, + .get_active_render_target = grub_video_fb_get_active_render_target, + + .next = 0 + }; + +GRUB_MOD_INIT(video_radeon_fuloong2e) +{ + grub_video_register (&grub_video_radeon_fuloong2e_adapter); +} + +GRUB_MOD_FINI(video_radeon_fuloong2e) +{ + grub_video_unregister (&grub_video_radeon_fuloong2e_adapter); +} diff --git a/include/grub/video.h b/include/grub/video.h index e30589a3d..352544c85 100644 --- a/include/grub/video.h +++ b/include/grub/video.h @@ -282,6 +282,7 @@ typedef enum grub_video_driver_id GRUB_VIDEO_DRIVER_BOCHS, GRUB_VIDEO_DRIVER_SDL, GRUB_VIDEO_DRIVER_SIS315PRO, + GRUB_VIDEO_DRIVER_RADEON_FULOONG2E, } grub_video_driver_id_t; typedef enum grub_video_adapter_prio From f87abff5381b312299b37f3d2a1b9d121e8ff8ff Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 19 Aug 2011 23:11:09 +0200 Subject: [PATCH 785/869] * grub-core/kern/mips/loongson/init.c (grub_reboot): Reboot Fuloong. * include/grub/cs5536.h (GRUB_CS5536_MSR_DIVIL_RESET): New definition. --- ChangeLog | 5 +++++ grub-core/kern/mips/loongson/init.c | 23 +++++++++++++++++++++-- include/grub/cs5536.h | 1 + 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2bff79544..d8ad1d634 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-08-19 Vladimir Serbinenko + + * grub-core/kern/mips/loongson/init.c (grub_reboot): Reboot Fuloong. + * include/grub/cs5536.h (GRUB_CS5536_MSR_DIVIL_RESET): New definition. + 2011-08-19 Vladimir Serbinenko * grub-core/Makefile.core.def (kernel): Add video/radeon_fuloong2e.c on diff --git a/grub-core/kern/mips/loongson/init.c b/grub-core/kern/mips/loongson/init.c index 5a95d29ed..d1cac7a67 100644 --- a/grub-core/kern/mips/loongson/init.c +++ b/grub-core/kern/mips/loongson/init.c @@ -269,8 +269,27 @@ grub_exit (void) void grub_reboot (void) { - grub_write_ec (GRUB_MACHINE_EC_COMMAND_REBOOT); - + switch (grub_arch_machine) + { + case GRUB_ARCH_MACHINE_FULOONG2E: + grub_outb (grub_inb (0xbfe00104) & ~4, 0xbfe00104); + grub_outb (grub_inb (0xbfe00104) | 4, 0xbfe00104); + break; + case GRUB_ARCH_MACHINE_FULOONG2F: + { + grub_pci_device_t dev; + if (!grub_cs5536_find (&dev)) + break; + grub_cs5536_write_msr (dev, GRUB_CS5536_MSR_DIVIL_RESET, + grub_cs5536_read_msr (dev, + GRUB_CS5536_MSR_DIVIL_RESET) + | 1); + break; + } + case GRUB_ARCH_MACHINE_YEELOONG: + grub_write_ec (GRUB_MACHINE_EC_COMMAND_REBOOT); + break; + } grub_millisleep (1500); grub_printf ("Reboot failed\n"); diff --git a/include/grub/cs5536.h b/include/grub/cs5536.h index 103b30633..fcacb23e8 100644 --- a/include/grub/cs5536.h +++ b/include/grub/cs5536.h @@ -77,6 +77,7 @@ #define GRUB_CS5536_MSR_DIVIL_LEG_IO_F_REMAP 0x04000000 #define GRUB_CS5536_MSR_DIVIL_LEG_IO_UART1_COM1 0x00070000 #define GRUB_CS5536_MSR_DIVIL_LEG_IO_UART2_COM3 0x00500000 +#define GRUB_CS5536_MSR_DIVIL_RESET 0x80000017 #define GRUB_CS5536_MSR_DIVIL_IRQ_MAPPER_PRIMARY_MASK 0x80000024 #define GRUB_CS5536_MSR_DIVIL_IRQ_MAPPER_LPC_MASK 0x80000025 #define GRUB_CS5536_DIVIL_LPC_INTERRUPTS 0x1002 From 4334690fbf512f5df2de965e8f5a89695734184e Mon Sep 17 00:00:00 2001 From: Szymon Janc Date: Sat, 20 Aug 2011 02:05:08 +0200 Subject: [PATCH 786/869] More work on LZO for btrfs support. Some fixes and code refactoring. --- ChangeLog.lzo | 11 +++ grub-core/fs/btrfs.c | 176 +++++++++++++++++++++---------------------- 2 files changed, 96 insertions(+), 91 deletions(-) diff --git a/ChangeLog.lzo b/ChangeLog.lzo index 782c6b60d..2ff940e21 100644 --- a/ChangeLog.lzo +++ b/ChangeLog.lzo @@ -1,3 +1,14 @@ +2011-08-20 Szymon Janc + + More work on LZO for btrfs support. Some fixes and code refactoring. + + * grub-core/fs/btrfs.c (grub_btrfs_superblock): Removed sectorsize, + nodesize, leafsize, stripsize and dummy5 fields. + (grub_btrfs_lzo_decompress): New function. + (grub_btrfs_extent_read): Use grub_btrfs_lzo_decompress for LZO blocks + decompression. + (GRUB_BTRFS_LZO_BLOCK_SIZE): New define. + 2011-08-17 Szymon Janc Add initial support for lzop files decompression. diff --git a/grub-core/fs/btrfs.c b/grub-core/fs/btrfs.c index 1d24da3e3..7af735630 100644 --- a/grub-core/fs/btrfs.c +++ b/grub-core/fs/btrfs.c @@ -31,6 +31,7 @@ GRUB_MOD_LICENSE ("GPLv3+"); #define GRUB_BTRFS_SIGNATURE "_BHRfS_M" +#define GRUB_BTRFS_LZO_BLOCK_SIZE 4096 typedef grub_uint8_t grub_btrfs_checksum_t[0x20]; typedef grub_uint16_t grub_btrfs_uuid_t[8]; @@ -52,15 +53,10 @@ struct grub_btrfs_superblock grub_uint64_t chunk_tree; grub_uint8_t dummy2[0x20]; grub_uint64_t root_dir_objectid; - grub_uint8_t dummy3[0x8]; - grub_uint32_t sectorsize; - grub_uint32_t nodesize; - grub_uint32_t leafsize; - grub_uint32_t stripsize; - grub_uint8_t dummy4[0x29]; + grub_uint8_t dummy3[0x41]; struct grub_btrfs_device this_device; char label[0x100]; - grub_uint8_t dummy5[0x100]; + grub_uint8_t dummy4[0x100]; grub_uint8_t bootstrap_mapping[0x800]; } __attribute__ ((packed)); @@ -884,6 +880,77 @@ grub_btrfs_read_inode (struct grub_btrfs_data *data, return grub_btrfs_read_logical (data, elemaddr, inode, sizeof (*inode)); } +static int +grub_btrfs_lzo_decompress(char *ibuf, grub_size_t isize, grub_off_t off, + char *obuf, grub_size_t osize) +{ + grub_uint32_t total_size, cblock_size; + unsigned char buf[GRUB_BTRFS_LZO_BLOCK_SIZE]; + + total_size = grub_le_to_cpu32 (grub_get_unaligned32 (ibuf)); + ibuf += sizeof (total_size); + + if (isize < total_size) + return -1; + + while (osize != 0) + { + lzo_uint usize = GRUB_BTRFS_LZO_BLOCK_SIZE; + + cblock_size = grub_le_to_cpu32 (grub_get_unaligned32 (ibuf)); + ibuf += sizeof (cblock_size); + + if (cblock_size > GRUB_BTRFS_LZO_BLOCK_SIZE) + return -1; + + /* Jump forward to first block with requested data. */ + if (off >= GRUB_BTRFS_LZO_BLOCK_SIZE) + { + off -= GRUB_BTRFS_LZO_BLOCK_SIZE; + ibuf += cblock_size; + continue; + } + + /* First block partially filled with requested data. */ + if (off > 0) + { + if (lzo1x_decompress_safe ((lzo_bytep)ibuf, cblock_size, buf, &usize, + NULL) != LZO_E_OK) + return -1; + + grub_memcpy(obuf, buf + off, usize - off); + + osize -= usize - off; + obuf += usize - off; + ibuf += cblock_size; + off = 0; + continue; + } + + /* 'Main' case, decompress whole block directly to output buffer. */ + if (osize >= GRUB_BTRFS_LZO_BLOCK_SIZE) + { + if (lzo1x_decompress_safe ((lzo_bytep)ibuf, cblock_size, + (lzo_bytep)obuf, &usize, NULL) != LZO_E_OK) + return -1; + + osize -= usize; + obuf += usize; + ibuf += cblock_size; + } + else /* Last possible block partially filled with requested data. */ + { + if (lzo1x_decompress_safe ((lzo_bytep)ibuf, cblock_size, buf, &usize, + NULL) != LZO_E_OK) + return -1; + + grub_memcpy(obuf, buf, osize); + break; + } + } + return 0; +} + static grub_ssize_t grub_btrfs_extent_read (struct grub_btrfs_data *data, grub_uint64_t ino, grub_uint64_t tree, @@ -990,39 +1057,11 @@ grub_btrfs_extent_read (struct grub_btrfs_data *data, } else if (data->extent->compression == GRUB_BTRFS_COMPRESSION_LZO) { - grub_uint32_t total_size, chunk_size; - unsigned char *obuf; - unsigned char *ibuf = (unsigned char *) data->extent->inl; - lzo_uint ocnt = extoff + csize; - int ret; - - obuf = grub_malloc (extoff + csize); - if (!obuf) + if (grub_btrfs_lzo_decompress(data->extent->inl, data->extsize - + ((grub_uint8_t *) data->extent->inl + - (grub_uint8_t *) data->extent), + extoff, buf, csize) < 0) return -1; - - total_size = grub_le_to_cpu32 (grub_get_unaligned32 (ibuf)); - ibuf += sizeof (total_size); - - chunk_size = grub_le_to_cpu32 (grub_get_unaligned32 (ibuf)); - ibuf += sizeof (chunk_size); - - /* Can we have multiple chunks in inline extent? */ - if (chunk_size + (sizeof (grub_uint32_t) * 2) != total_size) - { - grub_free (obuf); - return -1; - } - - ret = lzo1x_decompress_safe (ibuf, chunk_size, obuf, &ocnt, NULL); - - if (ret != LZO_E_OK) - { - grub_free (obuf); - return -1; - } - - grub_memcpy (buf, obuf + extoff, ocnt - extoff); - grub_free (obuf); } else grub_memcpy (buf, data->extent->inl + extoff, csize); @@ -1068,62 +1107,17 @@ grub_btrfs_extent_read (struct grub_btrfs_data *data, } else if (data->extent->compression == GRUB_BTRFS_COMPRESSION_LZO) { - grub_uint32_t total_size, chunk_size, usize = 0; - grub_size_t off = extoff; - unsigned char *chunk, *ibuf = tmp; - char *obuf = buf; - /* XXX Is this correct size from sblock? */ - grub_uint32_t udata_size = grub_le_to_cpu32 (data->sblock.sectorsize); + int ret ; - chunk = grub_malloc (udata_size); - if (!chunk) - { - grub_free (tmp); - return -1; - } + ret = grub_btrfs_lzo_decompress (tmp, zsize, extoff + + grub_le_to_cpu64 (data->extent->offset), + buf, csize); - /* XXX Use this for some sanity checks while decompressing. */ - total_size = grub_le_to_cpu32 (grub_get_unaligned32 (ibuf)); - ibuf += sizeof (total_size); + grub_free(tmp); - chunk_size = grub_le_to_cpu32 (grub_get_unaligned32 (ibuf)); - ibuf += sizeof (chunk_size); + if (ret < 0) + return -1; - /* Jump to first chunk with requested data. */ - while (off >= udata_size) - { - chunk_size = grub_le_to_cpu32 (grub_get_unaligned32 (ibuf)); - ibuf += sizeof (chunk_size); - ibuf += chunk_size; - off -= udata_size; - } - - while (usize < csize) - { - chunk_size = grub_le_to_cpu32 (grub_get_unaligned32 (ibuf)); - lzo_uint csize2 = udata_size; - int diff; - - ibuf += sizeof (chunk_size); - - if (lzo1x_decompress_safe (ibuf, chunk_size, chunk, &csize2, NULL) != LZO_E_OK) - { - grub_free (tmp); - grub_free (chunk); - return -1; - } - - diff = grub_min (csize2 - off, csize - usize); - - grub_memcpy (obuf, chunk + off, diff); - obuf += diff; - ibuf += chunk_size; - usize += diff; - off = 0; - } - - grub_free (tmp); - grub_free (chunk); break; } } From a5219af18967bcca59478a4515b36c77caa814bd Mon Sep 17 00:00:00 2001 From: Szymon Janc Date: Sat, 20 Aug 2011 11:48:46 +0200 Subject: [PATCH 787/869] * grub-core/io/gzio.c (grub_gzio_open): Always return original io if file type was not recognized correctly (not gzip or corrupted). --- ChangeLog | 5 +++++ grub-core/io/gzio.c | 7 ++----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index d8ad1d634..17e39bf15 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-08-20 Szymon Janc + + * grub-core/io/gzio.c (grub_gzio_open): Always return original io if + file type was not recognized correctly (not gzip or corrupted). + 2011-08-19 Vladimir Serbinenko * grub-core/kern/mips/loongson/init.c (grub_reboot): Reboot Fuloong. diff --git a/grub-core/io/gzio.c b/grub-core/io/gzio.c index 5d3e5332e..7380221aa 100644 --- a/grub-core/io/gzio.c +++ b/grub-core/io/gzio.c @@ -1179,12 +1179,9 @@ grub_gzio_open (grub_file_t io) grub_free (gzio); grub_free (file); grub_file_seek (io, 0); + grub_errno = GRUB_ERR_NONE; - if (grub_errno == GRUB_ERR_BAD_FILE_TYPE) - { - grub_errno = GRUB_ERR_NONE; - return io; - } + return io; } return file; From fe8d4a7bc207d44170a24534f13355230250dc5b Mon Sep 17 00:00:00 2001 From: Szymon Janc Date: Sat, 20 Aug 2011 11:58:41 +0200 Subject: [PATCH 788/869] * grub-core/loader/i386/linux.c (grub_linux_setup_video): Add GRUB_VIDEO_DRIVER_RADEON_FULOONG2E to switch case statement. --- ChangeLog | 5 +++++ grub-core/loader/i386/linux.c | 1 + 2 files changed, 6 insertions(+) diff --git a/ChangeLog b/ChangeLog index 17e39bf15..742a8cec2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-08-20 Szymon Janc + + * grub-core/loader/i386/linux.c (grub_linux_setup_video): Add + GRUB_VIDEO_DRIVER_RADEON_FULOONG2E to switch case statement. + 2011-08-20 Szymon Janc * grub-core/io/gzio.c (grub_gzio_open): Always return original io if diff --git a/grub-core/loader/i386/linux.c b/grub-core/loader/i386/linux.c index 5356d7ace..fded7bb0a 100644 --- a/grub-core/loader/i386/linux.c +++ b/grub-core/loader/i386/linux.c @@ -374,6 +374,7 @@ grub_linux_setup_video (struct linux_kernel_params *params) case GRUB_VIDEO_DRIVER_VGA: case GRUB_VIDEO_DRIVER_CIRRUS: case GRUB_VIDEO_DRIVER_BOCHS: + case GRUB_VIDEO_DRIVER_RADEON_FULOONG2E: /* Make gcc happy. */ case GRUB_VIDEO_DRIVER_SDL: case GRUB_VIDEO_DRIVER_NONE: From 7dc3c6863edb827234ec6045026dfc9f2ab9fffd Mon Sep 17 00:00:00 2001 From: Szymon Janc Date: Sat, 20 Aug 2011 13:04:38 +0200 Subject: [PATCH 789/869] Add grub-fstest option to uncompress data for commands. * util/grub-fstest.c (uncompress): New var. (options): New option -u. --- ChangeLog | 7 +++++++ util/grub-fstest.c | 9 ++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 742a8cec2..76526f4ec 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2011-08-20 Szymon Janc + + Add grub-fstest option to uncompress data for commands. + + * util/grub-fstest.c (uncompress): New var. + (options): New option -u. + 2011-08-20 Szymon Janc * grub-core/loader/i386/linux.c (grub_linux_setup_video): Add diff --git a/util/grub-fstest.c b/util/grub-fstest.c index 972d462da..ad64701a2 100644 --- a/util/grub-fstest.c +++ b/util/grub-fstest.c @@ -68,6 +68,7 @@ enum { #define BUF_SIZE 32256 static grub_disk_addr_t skip, leng; +static int uncompress = 0; static void read_file (char *pathname, int (*hook) (grub_off_t ofs, char *buf, int len)) @@ -111,7 +112,8 @@ read_file (char *pathname, int (*hook) (grub_off_t ofs, char *buf, int len)) return; } - grub_file_filter_disable_compression (); + if (uncompress == 0) + grub_file_filter_disable_compression (); file = grub_file_open (pathname); if (!file) { @@ -409,6 +411,7 @@ static struct argp_option options[] = { {"debug", 'd', "S", 0, N_("Set debug environment variable."), 2}, {"crypto", 'C', NULL, OPTION_ARG_OPTIONAL, N_("Mount crypto devices."), 2}, {"verbose", 'v', NULL, OPTION_ARG_OPTIONAL, N_("Print verbose messages."), 2}, + {"uncompress", 'u', NULL, OPTION_ARG_OPTIONAL, N_("Uncompress data."), 2}, {0, 0, 0, 0, 0, 0} }; @@ -469,6 +472,10 @@ argp_parser (int key, char *arg, struct argp_state *state) verbosity++; return 0; + case 'u': + uncompress = 1; + return 0; + case ARGP_KEY_END: if (args_count < num_disks) { From 9a8d32a24fe7d0a1865be8ae83308cc001d1d091 Mon Sep 17 00:00:00 2001 From: Szymon Janc Date: Sat, 20 Aug 2011 18:24:54 +0200 Subject: [PATCH 790/869] Add support for adler32 checksuming. * grub-core/lib/adler32.c: New file. * Makefile.util.def (library): Add grub-core/lib/adler32.c to common. * util/import_gcry.py (cryptolist): Add adler32. --- ChangeLog.lzo | 8 ++ Makefile.util.def | 1 + grub-core/Makefile.core.def | 5 ++ grub-core/lib/adler32.c | 152 ++++++++++++++++++++++++++++++++++++ util/import_gcry.py | 2 + 5 files changed, 168 insertions(+) create mode 100644 grub-core/lib/adler32.c diff --git a/ChangeLog.lzo b/ChangeLog.lzo index 2ff940e21..d24d913d8 100644 --- a/ChangeLog.lzo +++ b/ChangeLog.lzo @@ -1,3 +1,11 @@ +2011-08-20 Szymon Janc + + Add support for adler32 checksuming. + + * grub-core/lib/adler32.c: New file. + * Makefile.util.def (library): Add grub-core/lib/adler32.c to common. + * util/import_gcry.py (cryptolist): Add adler32. + 2011-08-20 Szymon Janc More work on LZO for btrfs support. Some fixes and code refactoring. diff --git a/Makefile.util.def b/Makefile.util.def index 3628e48f6..365f718a1 100644 --- a/Makefile.util.def +++ b/Makefile.util.def @@ -91,6 +91,7 @@ library = { common = grub-core/lib/LzFind.c; common = grub-core/lib/LzmaEnc.c; common = grub-core/lib/crc.c; + common = grub-core/lib/adler32.c; common = grub-core/normal/datetime.c; common = grub-core/normal/misc.c; common = grub-core/partmap/acorn.c; diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def index fc017b780..77dc7ed4b 100644 --- a/grub-core/Makefile.core.def +++ b/grub-core/Makefile.core.def @@ -1687,3 +1687,8 @@ module = { common = commands/cacheinfo.c; condition = COND_ENABLE_CACHE_STATS; }; + +module = { + name = adler32; + common = lib/adler32.c; +}; diff --git a/grub-core/lib/adler32.c b/grub-core/lib/adler32.c new file mode 100644 index 000000000..cc40735cb --- /dev/null +++ b/grub-core/lib/adler32.c @@ -0,0 +1,152 @@ +/* adler32.c - adler32 check. */ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2011 Free Software Foundation, Inc. + * + * GRUB is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see . + */ + +#include +#include +#include + +/* Based on adler32() from adler32.c of zlib-1.2.5 library. */ + +#define BASE 65521UL +#define NMAX 5552 + +#define DO1(buf,i) {adler += (buf)[i]; sum2 += adler;} +#define DO2(buf,i) DO1(buf,i); DO1(buf,i+1); +#define DO4(buf,i) DO2(buf,i); DO2(buf,i+2); +#define DO8(buf,i) DO4(buf,i); DO4(buf,i+4); +#define DO16(buf) DO8(buf,0); DO8(buf,8); + +static grub_uint32_t +update_adler32 (grub_uint32_t adler, const grub_uint8_t *buf, grub_size_t len) +{ + unsigned long sum2; + unsigned int n; + + sum2 = (adler >> 16) & 0xffff; + adler &= 0xffff; + + if (len == 1) + { + adler += buf[0]; + if (adler >= BASE) + adler -= BASE; + sum2 += adler; + if (sum2 >= BASE) + sum2 -= BASE; + return adler | (sum2 << 16); + } + + if (len < 16) + { + while (len--) + { + adler += *buf++; + sum2 += adler; + } + if (adler >= BASE) + adler -= BASE; + sum2 %= BASE; + return adler | (sum2 << 16); + } + + while (len >= NMAX) + { + len -= NMAX; + n = NMAX / 16; + do + { + DO16 (buf); + buf += 16; + } + while (--n); + adler %= BASE; + sum2 %= BASE; + } + + if (len) + { + while (len >= 16) + { + len -= 16; + DO16 (buf); + buf += 16; + } + while (len--) + { + adler += *buf++; + sum2 += adler; + } + adler %= BASE; + sum2 %= BASE; + } + + return adler | (sum2 << 16); +} + +typedef struct +{ + grub_uint32_t adler; + grub_uint8_t buf[4]; +} +adler32_context; + +static void +adler32_init (void *context) +{ + adler32_context *ctx = (adler32_context *) context; + ctx->adler = 1; +} + +static void +adler32_write (void *context, const void *inbuf, grub_size_t inlen) +{ + adler32_context *ctx = (adler32_context *) context; + if (!inbuf) + return; + ctx->adler = update_adler32 (ctx->adler, inbuf, inlen); +} + +static grub_uint8_t * +adler32_read (void *context) +{ + adler32_context *ctx = (adler32_context *) context; + return ctx->buf; +} + +static void +adler32_final (void *context __attribute__ ((unused))) +{ +} + +gcry_md_spec_t _gcry_digest_spec_adler32 = { + "ADLER32",0 , 0, 0 , 4, + adler32_init, adler32_write, adler32_final, adler32_read, + sizeof (adler32_context), + .blocksize = 64 +}; + +GRUB_MOD_INIT(adler32) +{ + grub_md_register (&_gcry_digest_spec_adler32); +} + +GRUB_MOD_FINI(adler32) +{ + grub_md_unregister (&_gcry_digest_spec_adler32); +} diff --git a/util/import_gcry.py b/util/import_gcry.py index 727492f10..ee75b1b8e 100644 --- a/util/import_gcry.py +++ b/util/import_gcry.py @@ -81,6 +81,8 @@ cryptolist.write ("AES-128: gcry_rijndael\n"); cryptolist.write ("AES-192: gcry_rijndael\n"); cryptolist.write ("AES-256: gcry_rijndael\n"); +cryptolist.write ("ADLER32: adler32\n"); + for cipher_file in cipher_files: infile = os.path.join (cipher_dir_in, cipher_file) outfile = os.path.join (cipher_dir_out, cipher_file) From ab178c084a251fe568430f250d9719979957ec53 Mon Sep 17 00:00:00 2001 From: Szymon Janc Date: Sat, 20 Aug 2011 21:10:00 +0200 Subject: [PATCH 791/869] * acinclude.m4: Use AC_LANG_PROGRAM macro to generate source code for AC_LANG_CONFTEST macros. --- ChangeLog | 5 +++++ acinclude.m4 | 16 ++++++++++------ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index 76526f4ec..88b883028 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-08-21 Szymon Janc + + * acinclude.m4: Use AC_LANG_PROGRAM macro to generate source code for + AC_LANG_CONFTEST macros. + 2011-08-20 Szymon Janc Add grub-fstest option to uncompress data for commands. diff --git a/acinclude.m4 b/acinclude.m4 index 7c38155d4..5c623baee 100644 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -316,14 +316,14 @@ fi dnl Check if the C compiler generates calls to `__enable_execute_stack()'. AC_DEFUN([grub_CHECK_ENABLE_EXECUTE_STACK],[ AC_MSG_CHECKING([whether `$CC' generates calls to `__enable_execute_stack()']) -AC_LANG_CONFTEST([[ +AC_LANG_CONFTEST([AC_LANG_SOURCE([[ void f (int (*p) (void)); void g (int i) { int nestedfunc (void) { return i; } f (nestedfunc); } -]]) +]])]) if AC_TRY_COMMAND([${CC-cc} ${CFLAGS} -S conftest.c]) && test -s conftest.s; then true else @@ -346,7 +346,9 @@ AC_DEFUN([grub_CHECK_STACK_PROTECTOR],[ ssp_possible=yes] AC_MSG_CHECKING([whether `$CC' accepts `-fstack-protector']) # Is this a reliable test case? -AC_LANG_CONFTEST([[void foo (void) { volatile char a[8]; a[3]; }]]) +AC_LANG_CONFTEST([AC_LANG_SOURCE([[ +void foo (void) { volatile char a[8]; a[3]; } +]])]) [# `$CC -c -o ...' might not be portable. But, oh, well... Is calling # `ac_compile' like this correct, after all? if eval "$ac_compile -S -fstack-protector -o conftest.s" 2> /dev/null; then] @@ -364,7 +366,9 @@ AC_DEFUN([grub_CHECK_STACK_ARG_PROBE],[ [# Smashing stack arg probe. sap_possible=yes] AC_MSG_CHECKING([whether `$CC' accepts `-mstack-arg-probe']) -AC_LANG_CONFTEST([[void foo (void) { volatile char a[8]; a[3]; }]]) +AC_LANG_CONFTEST([AC_LANG_SOURCE([[ +void foo (void) { volatile char a[8]; a[3]; } +]])]) [if eval "$ac_compile -S -mstack-arg-probe -o conftest.s" 2> /dev/null; then] AC_MSG_RESULT([yes]) [# Should we clear up other files as well, having called `AC_LANG_CONFTEST'? @@ -399,7 +403,7 @@ AC_DEFUN([grub_CHECK_PIE],[ pie_possible=yes] AC_MSG_CHECKING([whether `$CC' has `-fPIE' as default]) # Is this a reliable test case? -AC_LANG_CONFTEST([[ +AC_LANG_CONFTEST([AC_LANG_SOURCE([[ #ifdef __PIE__ int main() { return 0; @@ -407,7 +411,7 @@ int main() { #else #error NO __PIE__ DEFINED #endif -]]) +]])]) [# `$CC -c -o ...' might not be portable. But, oh, well... Is calling # `ac_compile' like this correct, after all? From 6401c37058fd2ea0ddf187d6a8c2563471dc0252 Mon Sep 17 00:00:00 2001 From: Szymon Janc Date: Sun, 21 Aug 2011 14:49:07 +0200 Subject: [PATCH 792/869] Return correct adler32 value in read() call. --- grub-core/lib/adler32.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/grub-core/lib/adler32.c b/grub-core/lib/adler32.c index cc40735cb..6fb0b00f8 100644 --- a/grub-core/lib/adler32.c +++ b/grub-core/lib/adler32.c @@ -102,7 +102,6 @@ update_adler32 (grub_uint32_t adler, const grub_uint8_t *buf, grub_size_t len) typedef struct { grub_uint32_t adler; - grub_uint8_t buf[4]; } adler32_context; @@ -126,7 +125,7 @@ static grub_uint8_t * adler32_read (void *context) { adler32_context *ctx = (adler32_context *) context; - return ctx->buf; + return (grub_uint8_t *) &ctx->adler; } static void From 90b0a05579001a4474b69f65c98501bb8078a8c3 Mon Sep 17 00:00:00 2001 From: Szymon Janc Date: Sun, 21 Aug 2011 18:48:19 +0200 Subject: [PATCH 793/869] Various bug fixes and improvements in lzopio. Should properly handle more files now. Also added support for lzop checksums verification. --- grub-core/io/lzopio.c | 174 +++++++++++++++++++++++++++--------------- 1 file changed, 113 insertions(+), 61 deletions(-) diff --git a/grub-core/io/lzopio.c b/grub-core/io/lzopio.c index 4ccc41a16..f80d4beb9 100644 --- a/grub-core/io/lzopio.c +++ b/grub-core/io/lzopio.c @@ -22,17 +22,15 @@ #include #include #include - +#include #include "minilzo.h" GRUB_MOD_LICENSE ("GPLv3+"); #define LZOP_MAGIC "\x89\x4c\x5a\x4f\x00\x0d\x0a\x1a\x0a" #define LZOP_MAGIC_SIZE 9 -#define CHECK_SIZE 4 -#define NEW_LZO_LIB 0x0940 -#define MIN_HEADER_SIZE 0 -#define MAX_HEADER_SIZE 0 +#define LZOP_CHECK_SIZE 4 +#define LZOP_NEW_LIB 0x0940 /* Header flags - copied from conf.h of LZOP source code. */ #define F_ADLER32_D 0x00000001L @@ -64,8 +62,10 @@ struct block_header struct grub_lzopio { grub_file_t file; - int ucheck; /* XXX Use gcry to validate checks. */ - int ccheck; + int has_ccheck; + int has_ucheck; + const gcry_md_spec_t *ucheck_fun; + const gcry_md_spec_t *ccheck_fun; grub_off_t saved_off; /* Rounded down to block boundary. */ grub_off_t start_block_off; struct block_header block; @@ -74,15 +74,16 @@ struct grub_lzopio typedef struct grub_lzopio *grub_lzopio_t; static struct grub_fs grub_lzopio_fs; -/* Some helper functions. Memory allocated by those function is free either - * on next read_block_header() or on close() so no risk of leaks. This makes - * those function simpler. */ +/* Some helper functions. On errors memory allocated by those function is free + * either on close() so no risk of leaks. This makes functions simpler. */ /* Read block header from file, after successful exit file points to * beginning of block data. */ static int read_block_header (struct grub_lzopio *lzopio) { + lzopio->saved_off += lzopio->block.usize; + /* Free cached block data if any. */ grub_free (lzopio->block.udata); grub_free (lzopio->block.cdata); @@ -113,26 +114,40 @@ read_block_header (struct grub_lzopio *lzopio) lzopio->block.csize = grub_be_to_cpu32 (lzopio->block.csize); - /* XXX Handle incompressible data case here rather than in uncompress_block. - * This will allow to handle switch of ccheck/ucheck easier and also - * make uncompress_block() a bit simpler. */ + /* Corrupted. */ + if (lzopio->block.csize > lzopio->block.usize) + return -1; - /* Read data checks. */ - if (lzopio->ucheck) + /* Read checksum of uncompressed data. */ + if (lzopio->has_ucheck) { if (grub_file_read (lzopio->file, &lzopio->block.ucheck, sizeof (lzopio->block.ucheck)) != sizeof (lzopio->block.ucheck)) return -1; + + lzopio->block.ucheck = grub_be_to_cpu32 (lzopio->block.ucheck); } - if (lzopio->ccheck) + /* Read checksum of compressed data. */ + if (lzopio->has_ccheck) { - if (grub_file_read (lzopio->file, &lzopio->block.ccheck, - sizeof (lzopio->block.ccheck)) != - sizeof (lzopio->block.ccheck)) - return -1; + /* Incompressible data block. */ + if (lzopio->block.csize == lzopio->block.usize) + { + lzopio->block.ccheck = lzopio->block.ucheck; + } + else + { + if (grub_file_read (lzopio->file, &lzopio->block.ccheck, + sizeof (lzopio->block.ccheck)) != + sizeof (lzopio->block.ccheck)) + return -1; + + lzopio->block.ccheck = grub_be_to_cpu32 (lzopio->block.ccheck); + } } + return 0; } @@ -149,9 +164,19 @@ read_block_data (struct grub_lzopio *lzopio) != (grub_ssize_t) lzopio->block.csize) return -1; - if (lzopio->ccheck) + if (lzopio->ccheck_fun) { - /* XXX Validate data checksum here. */ + grub_uint8_t context[lzopio->ccheck_fun->contextsize]; + + lzopio->ccheck_fun->init (context); + lzopio->ccheck_fun->write (context, lzopio->block.cdata, + lzopio->block.csize); + lzopio->ccheck_fun->final (context); + + if (grub_memcmp + (lzopio->ccheck_fun->read (context), &lzopio->block.ccheck, + sizeof (lzopio->block.ccheck)) != 0) + return -1; } return 0; @@ -159,7 +184,7 @@ read_block_data (struct grub_lzopio *lzopio) /* Read block data, uncompressed and also store it in memory. */ /* XXX Investigate possibility of in-place decompression to reduce memory - * footprint. */ + * footprint. Or try to uncompress directly to buf if possible. */ static int uncompress_block (struct grub_lzopio *lzopio) { @@ -168,35 +193,41 @@ uncompress_block (struct grub_lzopio *lzopio) if (read_block_data (lzopio) < 0) return -1; - if (lzopio->block.usize > lzopio->block.csize) - { - lzopio->block.udata = grub_malloc (lzopio->block.usize); - if (!lzopio->block.udata) - return -1; - - if (lzo1x_decompress_safe (lzopio->block.cdata, lzopio->block.csize, - lzopio->block.udata, &usize, - NULL) != LZO_E_OK) - return -1; - - if (lzopio->ucheck) - { - /* XXX Validate data checksum here. */ - } - - /* Compressed data can be free now. */ - grub_free (lzopio->block.cdata); - lzopio->block.cdata = NULL; - } - /* Incompressible block of data. */ - else if (lzopio->block.usize == lzopio->block.csize) + /* Incompressible data. */ + if (lzopio->block.csize == lzopio->block.usize) { lzopio->block.udata = lzopio->block.cdata; lzopio->block.cdata = NULL; } else { - return -1; + lzopio->block.udata = grub_malloc (lzopio->block.usize); + if (!lzopio->block.udata) + return -1; + + if (lzo1x_decompress_safe (lzopio->block.cdata, lzopio->block.csize, + lzopio->block.udata, &usize, NULL) + != LZO_E_OK) + return -1; + + if (lzopio->ucheck_fun) + { + grub_uint8_t context[lzopio->ucheck_fun->contextsize]; + + lzopio->ucheck_fun->init (context); + lzopio->ucheck_fun->write (context, lzopio->block.udata, + lzopio->block.usize); + lzopio->ucheck_fun->final (context); + + if (grub_memcmp + (lzopio->ucheck_fun->read (context), &lzopio->block.ucheck, + sizeof (lzopio->block.ucheck)) != 0) + return -1; + } + + /* Compressed data can be free now. */ + grub_free (lzopio->block.cdata); + lzopio->block.cdata = NULL; } return 0; @@ -215,8 +246,6 @@ jump_block (struct grub_lzopio *lzopio) return -1; } - lzopio->saved_off += lzopio->block.usize; - return read_block_header (lzopio); } @@ -243,7 +272,7 @@ calculate_uncompressed_size (grub_file_t file) return 1; } -/* XXX Do something with this function, it is insane now:) */ +/* XXX Do something with this function... */ static int test_header (grub_file_t file) { @@ -253,6 +282,7 @@ test_header (grub_file_t file) grub_uint8_t method, level, name_len; grub_uint32_t flags, mode, filter, mtime_lo, mtime_hi, checksum; unsigned char *name = NULL; + const gcry_md_spec_t *hcheck; if (grub_file_read (lzopio->file, magic, sizeof (magic)) != sizeof (magic)) { @@ -277,7 +307,7 @@ test_header (grub_file_t file) ver = grub_be_to_cpu16 (ver); - if (ver >= NEW_LZO_LIB) + if (ver >= LZOP_NEW_LIB) { /* Read version of lib needed to extract data. */ if (grub_file_read (lzopio->file, &ver_ext, sizeof (ver_ext)) != @@ -297,7 +327,7 @@ test_header (grub_file_t file) sizeof (method)) goto CORRUPTED; - if (ver >= NEW_LZO_LIB) + if (ver >= LZOP_NEW_LIB) { if (grub_file_read (lzopio->file, &level, sizeof (level)) != sizeof (level)) @@ -310,14 +340,33 @@ test_header (grub_file_t file) flags = grub_be_to_cpu32 (flags); if (flags & F_CRC32_D) - lzopio->ucheck = 1; + { + lzopio->has_ucheck = 1; + lzopio->ucheck_fun = grub_crypto_lookup_md_by_name ("crc32"); + } else if (flags & F_ADLER32_D) - lzopio->ucheck = 2; + { + lzopio->has_ucheck = 1; + lzopio->ucheck_fun = grub_crypto_lookup_md_by_name ("adler32"); + } if (flags & F_CRC32_C) - lzopio->ccheck = 1; + { + lzopio->has_ccheck = 1; + lzopio->ccheck_fun = grub_crypto_lookup_md_by_name ("crc32"); + } else if (flags & F_ADLER32_C) - lzopio->ccheck = 2; + { + lzopio->has_ccheck = 1; + lzopio->ccheck_fun = grub_crypto_lookup_md_by_name ("adler32"); + } + + if (flags & F_H_CRC32) + hcheck = grub_crypto_lookup_md_by_name ("crc32"); + else + hcheck = grub_crypto_lookup_md_by_name ("adler32"); + + hcheck++; if (flags & F_H_FILTER) { @@ -333,7 +382,7 @@ test_header (grub_file_t file) sizeof (mtime_lo)) goto CORRUPTED; - if (ver >= NEW_LZO_LIB) + if (ver >= LZOP_NEW_LIB) { if (grub_file_read (lzopio->file, &mtime_hi, sizeof (mtime_hi)) != sizeof (mtime_hi)) @@ -374,8 +423,6 @@ test_header (grub_file_t file) if (calculate_uncompressed_size (file) < 0) goto CORRUPTED; - lzopio->saved_off = 0; - /* Get back to start block. */ grub_file_seek (lzopio->file, lzopio->start_block_off); @@ -383,6 +430,7 @@ test_header (grub_file_t file) if (read_block_header (lzopio) < 0) goto CORRUPTED; + lzopio->saved_off = 0; return 1; } @@ -439,15 +487,17 @@ grub_lzopio_read (grub_file_t file, char *buf, grub_size_t len) { grub_lzopio_t lzopio = file->data; grub_ssize_t ret = 0; + grub_off_t off; /* Backward seek before last read block. */ if (lzopio->saved_off > grub_file_tell (file)) { - lzopio->saved_off = 0; grub_file_seek (lzopio->file, lzopio->start_block_off); if (read_block_header (lzopio) < 0) goto CORRUPTED; + + lzopio->saved_off = 0; } /* Forward to first block with requested data. */ @@ -461,9 +511,10 @@ grub_lzopio_read (grub_file_t file, char *buf, grub_size_t len) goto CORRUPTED; } + off = grub_file_tell (file) - lzopio->saved_off; + while (len != 0 && lzopio->block.usize != 0) { - grub_off_t off = grub_file_tell (file) - lzopio->saved_off; long to_copy; /* Block not decompressed yet. */ @@ -477,8 +528,9 @@ grub_lzopio_read (grub_file_t file, char *buf, grub_size_t len) len -= to_copy; buf += to_copy; ret += to_copy; + off = 0; - /* Read to next block if needed. */ + /* Read next block if needed. */ if (len > 0 && read_block_header (lzopio) < 0) goto CORRUPTED; } From 1f0e4eed6bdd61b8653625bfb5646bb3d70365be Mon Sep 17 00:00:00 2001 From: Szymon Janc Date: Mon, 22 Aug 2011 09:18:22 +0200 Subject: [PATCH 794/869] * include/grub/file.h (grub_file_filter_id): Set GRUB_FILE_FILTER_LZOPIO as GRUB_FILE_FILTER_COMPRESSION_LAST. --- ChangeLog.lzo | 5 +++++ include/grub/file.h | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/ChangeLog.lzo b/ChangeLog.lzo index d24d913d8..e3d08c6da 100644 --- a/ChangeLog.lzo +++ b/ChangeLog.lzo @@ -1,3 +1,8 @@ +2011-08-22 Szymon Janc + + * include/grub/file.h (grub_file_filter_id): Set + GRUB_FILE_FILTER_LZOPIO as GRUB_FILE_FILTER_COMPRESSION_LAST. + 2011-08-20 Szymon Janc Add support for adler32 checksuming. diff --git a/include/grub/file.h b/include/grub/file.h index 8fe87e6b4..e08ac2e26 100644 --- a/include/grub/file.h +++ b/include/grub/file.h @@ -59,7 +59,7 @@ typedef enum grub_file_filter_id GRUB_FILE_FILTER_LZOPIO, GRUB_FILE_FILTER_MAX, GRUB_FILE_FILTER_COMPRESSION_FIRST = GRUB_FILE_FILTER_GZIO, - GRUB_FILE_FILTER_COMPRESSION_LAST = GRUB_FILE_FILTER_XZIO, + GRUB_FILE_FILTER_COMPRESSION_LAST = GRUB_FILE_FILTER_LZOPIO, } grub_file_filter_id_t; typedef grub_file_t (*grub_file_filter_t) (grub_file_t in); From 4155e6974ad15f963eff5dfbe03cb36b48c7183b Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Tue, 23 Aug 2011 11:18:00 +0200 Subject: [PATCH 795/869] * util/grub-install.in: Move cryptodisk logic to appropriate place. --- ChangeLog | 4 ++++ util/grub-install.in | 13 ++++++++----- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 88b883028..26af06ed3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2011-08-23 Vladimir Serbinenko + + * util/grub-install.in: Move cryptodisk logic to appropriate place. + 2011-08-21 Szymon Janc * acinclude.m4: Use AC_LANG_PROGRAM macro to generate source code for diff --git a/util/grub-install.in b/util/grub-install.in index f9e1510d1..d11d24421 100644 --- a/util/grub-install.in +++ b/util/grub-install.in @@ -558,11 +558,6 @@ if [ "x${devabstraction_module}" = "x" ] ; then exit 1 fi - if [ x$GRUB_CRYPTODISK_ENABLE = xy ]; then - for uuid in "`"${grub_probe}" --device "${device}" --target=cryptodisk_uuid`"; do - echo "cryptomount -u $uuid" - done - fi echo "search.fs_uuid ${uuid} root " >> "${grubdir}/load.cfg" echo 'set prefix=($root)'"${relative_grubdir}" >> "${grubdir}/load.cfg" @@ -577,6 +572,14 @@ if [ "x${devabstraction_module}" = "x" ] ; then fi fi else + if [ x$GRUB_CRYPTODISK_ENABLE = xy ]; then + for uuid in "`"${grub_probe}" --device "${grub_device}" --target=cryptodisk_uuid`"; do + echo "cryptomount -u $uuid" >> "${grubdir}/load.cfg" + done + fi + + config_opt="-c ${grubdir}/load.cfg " + prefix_drive=`"$grub_probe" --device-map="${device_map}" --target=drive --device "${grub_device}"` || exit 1 fi From ab80f326f47e2e83aaf35ac8b05e8b2c7e0966c8 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Tue, 23 Aug 2011 11:19:26 +0200 Subject: [PATCH 796/869] * grub-core/commands/wildcard.c (make_regex): Handle @. --- ChangeLog | 4 ++++ grub-core/commands/wildcard.c | 1 + 2 files changed, 5 insertions(+) diff --git a/ChangeLog b/ChangeLog index 26af06ed3..345f8f4cd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2011-08-23 Vladimir Serbinenko + + * grub-core/commands/wildcard.c (make_regex): Handle @. + 2011-08-23 Vladimir Serbinenko * util/grub-install.in: Move cryptodisk logic to appropriate place. diff --git a/grub-core/commands/wildcard.c b/grub-core/commands/wildcard.c index d2f4347d5..256c07e51 100644 --- a/grub-core/commands/wildcard.c +++ b/grub-core/commands/wildcard.c @@ -139,6 +139,7 @@ make_regex (const char *start, const char *end, regex_t *regexp) case '.': case '(': case ')': + case '@': buffer[i++] = '\\'; buffer[i++] = ch; break; From ca51c4a04f4a67fe86bcdbddd899a28ae508f8a4 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Tue, 23 Aug 2011 11:20:56 +0200 Subject: [PATCH 797/869] * grub-core/kern/mips/loongson/init.c (grub_machine_init): Handle the case of less than 256 MiB of RAM. --- ChangeLog | 5 +++++ grub-core/kern/mips/loongson/init.c | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 345f8f4cd..ad7dea7c8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-08-23 Vladimir Serbinenko + + * grub-core/kern/mips/loongson/init.c (grub_machine_init): Handle the + case of less than 256 MiB of RAM. + 2011-08-23 Vladimir Serbinenko * grub-core/commands/wildcard.c (make_regex): Handle @. diff --git a/grub-core/kern/mips/loongson/init.c b/grub-core/kern/mips/loongson/init.c index d1cac7a67..2d1a0653e 100644 --- a/grub-core/kern/mips/loongson/init.c +++ b/grub-core/kern/mips/loongson/init.c @@ -188,7 +188,7 @@ grub_machine_init (void) } else { - grub_arch_memsize = (totalmem >> 20); + grub_arch_memsize = totalmem; grub_arch_highmemsize = 0; } From 00b98c9b2ef86d4cc4254dd163798388fc1f4d52 Mon Sep 17 00:00:00 2001 From: Szymon Janc Date: Tue, 23 Aug 2011 19:49:01 +0200 Subject: [PATCH 798/869] * grub-core/fs/btrfs.c (grub_btrfs_lzo_decompress): Random fixes and some cleanup. --- grub-core/fs/btrfs.c | 120 ++++++++++++++++++++----------------------- 1 file changed, 56 insertions(+), 64 deletions(-) diff --git a/grub-core/fs/btrfs.c b/grub-core/fs/btrfs.c index 7af735630..ae1ce1c7d 100644 --- a/grub-core/fs/btrfs.c +++ b/grub-core/fs/btrfs.c @@ -31,7 +31,17 @@ GRUB_MOD_LICENSE ("GPLv3+"); #define GRUB_BTRFS_SIGNATURE "_BHRfS_M" + +/* From http://www.oberhumer.com/opensource/lzo/lzofaq.php + * LZO will expand incompressible data by a little amount. I still haven't + * computed the exact values, but I suggest using these formulas for + * a worst-case expansion calculation: + * + * output_block_size = input_block_size + (input_block_size / 16) + 64 + 3 + * */ #define GRUB_BTRFS_LZO_BLOCK_SIZE 4096 +#define GRUB_BTRFS_LZO_BLOCK_MAX_CSIZE (GRUB_BTRFS_LZO_BLOCK_SIZE + \ + (GRUB_BTRFS_LZO_BLOCK_SIZE / 16) + 64 + 3) typedef grub_uint8_t grub_btrfs_checksum_t[0x20]; typedef grub_uint16_t grub_btrfs_uuid_t[8]; @@ -880,11 +890,11 @@ grub_btrfs_read_inode (struct grub_btrfs_data *data, return grub_btrfs_read_logical (data, elemaddr, inode, sizeof (*inode)); } -static int +static grub_ssize_t grub_btrfs_lzo_decompress(char *ibuf, grub_size_t isize, grub_off_t off, char *obuf, grub_size_t osize) { - grub_uint32_t total_size, cblock_size; + grub_uint32_t total_size, cblock_size, uncompressed = 0; unsigned char buf[GRUB_BTRFS_LZO_BLOCK_SIZE]; total_size = grub_le_to_cpu32 (grub_get_unaligned32 (ibuf)); @@ -893,62 +903,54 @@ grub_btrfs_lzo_decompress(char *ibuf, grub_size_t isize, grub_off_t off, if (isize < total_size) return -1; - while (osize != 0) + /* Jump forward to first block with requested data. */ + while (off >= GRUB_BTRFS_LZO_BLOCK_SIZE) + { + cblock_size = grub_le_to_cpu32 (grub_get_unaligned32 (ibuf)); + ibuf += sizeof (cblock_size); + + off -= GRUB_BTRFS_LZO_BLOCK_SIZE; + ibuf += cblock_size; + } + + while (osize > 0) { lzo_uint usize = GRUB_BTRFS_LZO_BLOCK_SIZE; cblock_size = grub_le_to_cpu32 (grub_get_unaligned32 (ibuf)); ibuf += sizeof (cblock_size); - if (cblock_size > GRUB_BTRFS_LZO_BLOCK_SIZE) - return -1; - - /* Jump forward to first block with requested data. */ - if (off >= GRUB_BTRFS_LZO_BLOCK_SIZE) + /* Block partially filled with requested data. */ + if (off > 0 || osize < GRUB_BTRFS_LZO_BLOCK_SIZE) { - off -= GRUB_BTRFS_LZO_BLOCK_SIZE; - ibuf += cblock_size; - continue; - } + grub_size_t to_copy = grub_min(osize, GRUB_BTRFS_LZO_BLOCK_SIZE - off); - /* First block partially filled with requested data. */ - if (off > 0) - { if (lzo1x_decompress_safe ((lzo_bytep)ibuf, cblock_size, buf, &usize, NULL) != LZO_E_OK) return -1; - grub_memcpy(obuf, buf + off, usize - off); + grub_memcpy(obuf, buf + off, to_copy); - osize -= usize - off; - obuf += usize - off; + osize -= to_copy; + uncompressed += to_copy; + obuf += to_copy; ibuf += cblock_size; off = 0; continue; } /* 'Main' case, decompress whole block directly to output buffer. */ - if (osize >= GRUB_BTRFS_LZO_BLOCK_SIZE) - { - if (lzo1x_decompress_safe ((lzo_bytep)ibuf, cblock_size, - (lzo_bytep)obuf, &usize, NULL) != LZO_E_OK) - return -1; + if (lzo1x_decompress_safe ((lzo_bytep)ibuf, cblock_size, (lzo_bytep)obuf, + &usize, NULL) != LZO_E_OK) + return -1; - osize -= usize; - obuf += usize; - ibuf += cblock_size; - } - else /* Last possible block partially filled with requested data. */ - { - if (lzo1x_decompress_safe ((lzo_bytep)ibuf, cblock_size, buf, &usize, - NULL) != LZO_E_OK) - return -1; - - grub_memcpy(obuf, buf, osize); - break; - } + osize -= usize; + uncompressed += usize; + obuf += usize; + ibuf += cblock_size; } - return 0; + + return uncompressed; } static grub_ssize_t @@ -1060,7 +1062,8 @@ grub_btrfs_extent_read (struct grub_btrfs_data *data, if (grub_btrfs_lzo_decompress(data->extent->inl, data->extsize - ((grub_uint8_t *) data->extent->inl - (grub_uint8_t *) data->extent), - extoff, buf, csize) < 0) + extoff, buf, csize) + != (grub_ssize_t) csize) return -1; } else @@ -1075,8 +1078,10 @@ grub_btrfs_extent_read (struct grub_btrfs_data *data, if (data->extent->compression != GRUB_BTRFS_COMPRESSION_NONE) { - void *tmp; + char *tmp; grub_uint64_t zsize; + grub_ssize_t ret; + zsize = grub_le_to_cpu64 (data->extent->compressed_size); tmp = grub_malloc (zsize); if (!tmp) @@ -1091,36 +1096,23 @@ grub_btrfs_extent_read (struct grub_btrfs_data *data, } if (data->extent->compression == GRUB_BTRFS_COMPRESSION_ZLIB) - { - grub_ssize_t ret; - - ret = grub_zlib_decompress (tmp, zsize, extoff - + grub_le_to_cpu64 (data->extent->offset), - buf, csize); - - grub_free (tmp); - - if (ret != (grub_ssize_t) csize) - return -1; - - break; - } - else if (data->extent->compression == GRUB_BTRFS_COMPRESSION_LZO) - { - int ret ; - - ret = grub_btrfs_lzo_decompress (tmp, zsize, extoff + ret = grub_zlib_decompress (tmp, zsize, extoff + grub_le_to_cpu64 (data->extent->offset), buf, csize); + else if (data->extent->compression == GRUB_BTRFS_COMPRESSION_LZO) + ret = grub_btrfs_lzo_decompress (tmp, zsize, extoff + + grub_le_to_cpu64 (data->extent->offset), + buf, csize); + else + ret = -1; - grub_free(tmp); + grub_free(tmp); - if (ret < 0) - return -1; + if (ret != (grub_ssize_t) csize) + return -1; - break; - } - } + break; + } err = grub_btrfs_read_logical (data, grub_le_to_cpu64 (data->extent->laddr) + grub_le_to_cpu64 (data->extent->offset) From ec543969bf07fbe60423ece81b29cd315116388b Mon Sep 17 00:00:00 2001 From: Szymon Janc Date: Tue, 23 Aug 2011 19:53:49 +0200 Subject: [PATCH 799/869] * Makefile.util.def (libgrubmods.a): Add grub-core/io/lzopio.c to common. --- ChangeLog.lzo | 5 +++++ Makefile.util.def | 1 + 2 files changed, 6 insertions(+) diff --git a/ChangeLog.lzo b/ChangeLog.lzo index e3d08c6da..ef6145061 100644 --- a/ChangeLog.lzo +++ b/ChangeLog.lzo @@ -1,3 +1,8 @@ +2011-08-23 Szymon Janc + + * Makefile.util.def (libgrubmods.a): Add grub-core/io/lzopio.c to + common. + 2011-08-22 Szymon Janc * include/grub/file.h (grub_file_filter_id): Set diff --git a/Makefile.util.def b/Makefile.util.def index 365f718a1..1fe4f2464 100644 --- a/Makefile.util.def +++ b/Makefile.util.def @@ -109,6 +109,7 @@ library = { common = grub-core/script/script.c; common = grub-core/script/argv.c; common = grub-core/io/gzio.c; + common = grub-core/io/lzopio.c; common = grub-core/kern/ia64/dl_helper.c; common = grub-core/lib/minilzo/minilzo.c; }; From 579c12fbb4b757fc26cb6fcbe265250f734eaf68 Mon Sep 17 00:00:00 2001 From: Szymon Janc Date: Wed, 24 Aug 2011 11:24:10 +0200 Subject: [PATCH 800/869] * grub-core/fs/btrfs.c: Some minor cleanups. --- grub-core/fs/btrfs.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/grub-core/fs/btrfs.c b/grub-core/fs/btrfs.c index ae1ce1c7d..534ce15de 100644 --- a/grub-core/fs/btrfs.c +++ b/grub-core/fs/btrfs.c @@ -894,7 +894,7 @@ static grub_ssize_t grub_btrfs_lzo_decompress(char *ibuf, grub_size_t isize, grub_off_t off, char *obuf, grub_size_t osize) { - grub_uint32_t total_size, cblock_size, uncompressed = 0; + grub_uint32_t total_size, cblock_size, ret = 0; unsigned char buf[GRUB_BTRFS_LZO_BLOCK_SIZE]; total_size = grub_le_to_cpu32 (grub_get_unaligned32 (ibuf)); @@ -909,6 +909,9 @@ grub_btrfs_lzo_decompress(char *ibuf, grub_size_t isize, grub_off_t off, cblock_size = grub_le_to_cpu32 (grub_get_unaligned32 (ibuf)); ibuf += sizeof (cblock_size); + if (cblock_size > GRUB_BTRFS_LZO_BLOCK_MAX_CSIZE) + return -1; + off -= GRUB_BTRFS_LZO_BLOCK_SIZE; ibuf += cblock_size; } @@ -920,6 +923,9 @@ grub_btrfs_lzo_decompress(char *ibuf, grub_size_t isize, grub_off_t off, cblock_size = grub_le_to_cpu32 (grub_get_unaligned32 (ibuf)); ibuf += sizeof (cblock_size); + if (cblock_size > GRUB_BTRFS_LZO_BLOCK_MAX_CSIZE) + return -1; + /* Block partially filled with requested data. */ if (off > 0 || osize < GRUB_BTRFS_LZO_BLOCK_SIZE) { @@ -929,28 +935,29 @@ grub_btrfs_lzo_decompress(char *ibuf, grub_size_t isize, grub_off_t off, NULL) != LZO_E_OK) return -1; + to_copy = grub_min(to_copy, usize); grub_memcpy(obuf, buf + off, to_copy); osize -= to_copy; - uncompressed += to_copy; + ret += to_copy; obuf += to_copy; ibuf += cblock_size; off = 0; continue; } - /* 'Main' case, decompress whole block directly to output buffer. */ + /* Decompress whole block directly to output buffer. */ if (lzo1x_decompress_safe ((lzo_bytep)ibuf, cblock_size, (lzo_bytep)obuf, &usize, NULL) != LZO_E_OK) return -1; osize -= usize; - uncompressed += usize; + ret += usize; obuf += usize; ibuf += cblock_size; } - return uncompressed; + return ret; } static grub_ssize_t From 2221ab6c62fdd6473f1ae4f147739b585fde8e1b Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Mon, 5 Sep 2011 13:58:33 +0100 Subject: [PATCH 801/869] * util/grub-mkconfig_lib.in (grub_file_is_not_garbage): Return 1 for */README* as well as README*. Reported by: Axel Beckert. --- ChangeLog | 6 ++++++ util/grub-mkconfig_lib.in | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index ad7dea7c8..c84aa30aa 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2011-09-05 Colin Watson + + * util/grub-mkconfig_lib.in (grub_file_is_not_garbage): Return 1 for + */README* as well as README*. + Reported by: Axel Beckert. + 2011-08-23 Vladimir Serbinenko * grub-core/kern/mips/loongson/init.c (grub_machine_init): Handle the diff --git a/util/grub-mkconfig_lib.in b/util/grub-mkconfig_lib.in index 901b5752f..a453a6bb5 100644 --- a/util/grub-mkconfig_lib.in +++ b/util/grub-mkconfig_lib.in @@ -157,7 +157,7 @@ grub_file_is_not_garbage () if test -f "$1" ; then case "$1" in *.dpkg-*) return 1 ;; # debian dpkg - README*) return 1 ;; # documentation + README*|*/README*) return 1 ;; # documentation esac else return 1 From 9c4f9ca010ddf432c7c83cdabaf36c7a4b956cd6 Mon Sep 17 00:00:00 2001 From: Szymon Janc Date: Tue, 6 Sep 2011 21:21:13 +0200 Subject: [PATCH 802/869] * grub-core/io/lzopio.c (test_header): Some cleanups. --- grub-core/io/lzopio.c | 177 +++++++++++++++++++----------------------- 1 file changed, 81 insertions(+), 96 deletions(-) diff --git a/grub-core/io/lzopio.c b/grub-core/io/lzopio.c index f80d4beb9..e303b29a3 100644 --- a/grub-core/io/lzopio.c +++ b/grub-core/io/lzopio.c @@ -272,72 +272,60 @@ calculate_uncompressed_size (grub_file_t file) return 1; } -/* XXX Do something with this function... */ +struct lzop_header +{ + grub_uint8_t magic[LZOP_MAGIC_SIZE]; + grub_uint16_t lzop_version; + grub_uint16_t lib_version; + grub_uint16_t lib_version_ext; + grub_uint8_t method; + grub_uint8_t level; + grub_uint32_t flags; + /* grub_uint32_t filter; */ /* No filters support. Rarely used anyway. */ + grub_uint32_t mode; + grub_uint32_t mtime_lo; + grub_uint32_t mtime_hi; + grub_uint8_t name_len; +} __attribute__ ((packed)); + static int test_header (grub_file_t file) { grub_lzopio_t lzopio = file->data; - unsigned char magic[LZOP_MAGIC_SIZE]; - grub_uint16_t lzopver, ver, ver_ext; - grub_uint8_t method, level, name_len; - grub_uint32_t flags, mode, filter, mtime_lo, mtime_hi, checksum; - unsigned char *name = NULL; + struct lzop_header header; + grub_uint32_t flags, checksum; const gcry_md_spec_t *hcheck; + grub_uint8_t *context = NULL; + grub_uint8_t *name = NULL; - if (grub_file_read (lzopio->file, magic, sizeof (magic)) != sizeof (magic)) + if (grub_file_read (lzopio->file, &header, sizeof (header)) != sizeof (header)) { grub_error (GRUB_ERR_BAD_FILE_TYPE, "no lzop magic found"); return 0; } - if (grub_memcmp (magic, LZOP_MAGIC, LZOP_MAGIC_SIZE) != 0) + if (grub_memcmp (header.magic, LZOP_MAGIC, LZOP_MAGIC_SIZE) != 0) { grub_error (GRUB_ERR_BAD_FILE_TYPE, "no lzop magic found"); return 0; } - /* LZOP version. */ - if (grub_file_read (lzopio->file, &lzopver, sizeof (lzopver)) != - sizeof (lzopver)) - goto CORRUPTED; - - /* LZO lib version. */ - if (grub_file_read (lzopio->file, &ver, sizeof (ver)) != sizeof (ver)) - goto CORRUPTED; - - ver = grub_be_to_cpu16 (ver); - - if (ver >= LZOP_NEW_LIB) + if (grub_be_to_cpu16(header.lib_version) < LZOP_NEW_LIB) { - /* Read version of lib needed to extract data. */ - if (grub_file_read (lzopio->file, &ver_ext, sizeof (ver_ext)) != - sizeof (ver_ext)) - goto CORRUPTED; - - /* Too new version, should upgrade minilzo? */ - if (grub_be_to_cpu16 (ver_ext) > MINILZO_VERSION) - { - grub_error (GRUB_ERR_BAD_COMPRESSED_DATA, - "unsupported LZO version"); - return 0; - } + grub_error (GRUB_ERR_BAD_COMPRESSED_DATA, + "unsupported (too old) LZOP version"); + return 0; } - if (grub_file_read (lzopio->file, &method, sizeof (method)) != - sizeof (method)) - goto CORRUPTED; - - if (ver >= LZOP_NEW_LIB) + /* Too new version, should upgrade minilzo? */ + if (grub_be_to_cpu16 (header.lib_version_ext) > MINILZO_VERSION) { - if (grub_file_read (lzopio->file, &level, sizeof (level)) != - sizeof (level)) - goto CORRUPTED; + grub_error (GRUB_ERR_BAD_COMPRESSED_DATA, + "unsupported (too new) LZO version"); + return 0; } - if (grub_file_read (lzopio->file, &flags, sizeof (flags)) != sizeof (flags)) - goto CORRUPTED; - - flags = grub_be_to_cpu32 (flags); + flags = grub_be_to_cpu32 (header.flags); if (flags & F_CRC32_D) { @@ -366,76 +354,73 @@ test_header (grub_file_t file) else hcheck = grub_crypto_lookup_md_by_name ("adler32"); - hcheck++; + if (hcheck) { + context = grub_malloc(hcheck->contextsize); + if (! context) + return 0; - if (flags & F_H_FILTER) + hcheck->init(context); + + /* MAGIC is not included in check calculation. */ + hcheck->write(context, &header.lzop_version, sizeof(header)- LZOP_MAGIC_SIZE); + } + + if (header.name_len != 0) { - if (grub_file_read (lzopio->file, &filter, sizeof (filter)) != - sizeof (filter)) - goto CORRUPTED; - } - - if (grub_file_read (lzopio->file, &mode, sizeof (mode)) != sizeof (mode)) - goto CORRUPTED; - - if (grub_file_read (lzopio->file, &mtime_lo, sizeof (mtime_lo)) != - sizeof (mtime_lo)) - goto CORRUPTED; - - if (ver >= LZOP_NEW_LIB) - { - if (grub_file_read (lzopio->file, &mtime_hi, sizeof (mtime_hi)) != - sizeof (mtime_hi)) - goto CORRUPTED; - } - - if (grub_file_read (lzopio->file, &name_len, sizeof (name_len)) != - sizeof (name_len)) - goto CORRUPTED; - - if (name_len != 0) - { - name = grub_malloc (name_len); - if (!name) - return 0; - - if (grub_file_read (lzopio->file, name, name_len) != name_len) + name = grub_malloc (header.name_len); + if (! name) { - grub_free (name); + grub_free (context); + return 0; + } + + if (grub_file_read (lzopio->file, name, header.name_len) != + header.name_len) + { + grub_free(name); goto CORRUPTED; } + + if (hcheck) + hcheck->write(context, name, header.name_len); + + grub_free(name); } + if (hcheck) + hcheck->final(context); + if (grub_file_read (lzopio->file, &checksum, sizeof (checksum)) != sizeof (checksum)) - { - grub_free (name); + goto CORRUPTED; + + if (hcheck) + { + checksum = grub_cpu_to_be32(checksum); + if (memcmp(&checksum, hcheck->read(context), sizeof(checksum)) != 0) goto CORRUPTED; - } + } - grub_free (name); + lzopio->start_block_off = grub_file_tell (lzopio->file); - /* XXX Validate header checksum here. */ - if (checksum == checksum) - { - lzopio->start_block_off = grub_file_tell (lzopio->file); + if (calculate_uncompressed_size (file) < 0) + goto CORRUPTED; - if (calculate_uncompressed_size (file) < 0) - goto CORRUPTED; + /* Get back to start block. */ + grub_file_seek (lzopio->file, lzopio->start_block_off); - /* Get back to start block. */ - grub_file_seek (lzopio->file, lzopio->start_block_off); + /* Read first block - grub_lzopio_read() expects valid block. */ + if (read_block_header (lzopio) < 0) + goto CORRUPTED; - /* Read first block - grub_lzopio_read() expects valid block. */ - if (read_block_header (lzopio) < 0) - goto CORRUPTED; - - lzopio->saved_off = 0; - return 1; - } + lzopio->saved_off = 0; + return 1; CORRUPTED: grub_error (GRUB_ERR_BAD_COMPRESSED_DATA, "lzop file corrupted"); + + grub_free(name); + return 0; } From 1a7d7db97f34d0c38dd64655ef944b4cf0768ed9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Sutre?= Date: Sat, 17 Sep 2011 23:01:48 +0200 Subject: [PATCH 803/869] Get sector size from disk label for NetBSD. --- ChangeLog | 5 +++++ grub-core/kern/emu/hostdisk.c | 5 ++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index c84aa30aa..1acdce29e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-09-17 GrĂ©goire Sutre + + * grub-core/kern/emu/hostdisk.c (grub_util_get_fd_sectors) [__NetBSD__]: + Get sector size from disk label. + 2011-09-05 Colin Watson * util/grub-mkconfig_lib.in (grub_file_is_not_garbage): Return 1 for diff --git a/grub-core/kern/emu/hostdisk.c b/grub-core/kern/emu/hostdisk.c index 000ef2f79..b4c4eef7c 100644 --- a/grub-core/kern/emu/hostdisk.c +++ b/grub-core/kern/emu/hostdisk.c @@ -265,10 +265,13 @@ grub_util_get_fd_sectors (int fd, unsigned *log_secsize) # if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) if (ioctl (fd, DIOCGSECTORSIZE, §or_size)) + goto fail; +# elif defined(__NetBSD__) + sector_size = label.d_secsize; # else if (ioctl (fd, BLKSSZGET, §or_size)) -# endif goto fail; +# endif if (sector_size & (sector_size - 1) || !sector_size) goto fail; From 20fd15f9db1e5379d264e29f0f28e0b96391bf95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Sutre?= Date: Sat, 17 Sep 2011 23:40:10 +0200 Subject: [PATCH 804/869] Add LIBUTIL for grub-mkrelpath and grub-fstest. Fixes build on NetBSD. --- ChangeLog | 6 ++++++ Makefile.util.def | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1acdce29e..a454f2f84 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2011-09-17 GrĂ©goire Sutre + + * Makefile.util.def (grub-mkrelpath): Add LIBUTIL for getrawpartition(3) + on NetBSD. + * Makefile.util.def (grub-fstest): Likewise. + 2011-09-17 GrĂ©goire Sutre * grub-core/kern/emu/hostdisk.c (grub_util_get_fd_sectors) [__NetBSD__]: diff --git a/Makefile.util.def b/Makefile.util.def index d86cb9761..713729c55 100644 --- a/Makefile.util.def +++ b/Makefile.util.def @@ -147,7 +147,7 @@ program = { ldadd = libgrubgcry.a; ldadd = libgrubkern.a; ldadd = grub-core/gnulib/libgnu.a; - ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM)'; + ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBUTIL) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM)'; }; program = { @@ -226,7 +226,7 @@ program = { ldadd = libgrubgcry.a; ldadd = libgrubkern.a; ldadd = grub-core/gnulib/libgnu.a; - ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM)'; + ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBUTIL) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM)'; }; program = { From 69915030942771f6813ebc238e86e05b5112f3b5 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 28 Sep 2011 14:07:53 +0200 Subject: [PATCH 805/869] * grub-core/kern/emu/hostdisk.c (grub_util_biosdisk_is_floppy): Return 0 if disk isn't biosdisk. --- ChangeLog | 5 +++++ grub-core/kern/emu/hostdisk.c | 3 +++ 2 files changed, 8 insertions(+) diff --git a/ChangeLog b/ChangeLog index a454f2f84..9d19fe450 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-09-28 Vladimir Serbinenko + + * grub-core/kern/emu/hostdisk.c (grub_util_biosdisk_is_floppy): + Return 0 if disk isn't biosdisk. + 2011-09-17 GrĂ©goire Sutre * Makefile.util.def (grub-mkrelpath): Add LIBUTIL for getrawpartition(3) diff --git a/grub-core/kern/emu/hostdisk.c b/grub-core/kern/emu/hostdisk.c index b4c4eef7c..a9a8c066e 100644 --- a/grub-core/kern/emu/hostdisk.c +++ b/grub-core/kern/emu/hostdisk.c @@ -1841,6 +1841,9 @@ grub_util_biosdisk_is_floppy (grub_disk_t disk) struct stat st; int fd; + if (disk->dev != &grub_util_biosdisk_dev) + return 0; + fd = open (map[disk->id].device, O_RDONLY); /* Shouldn't happen. */ if (fd == -1) From 2ded951ef70998ebebabd7b73d1a6bf0006a93d7 Mon Sep 17 00:00:00 2001 From: Andreas Born Date: Wed, 28 Sep 2011 14:19:21 +0200 Subject: [PATCH 806/869] Fix incorrect identifiers in bash-completion. * util/bash-completion.d/grub-completion.bash.in (_grub_mkpasswd-pbkdf2): Rename to ... (_grub_mkpasswd_pbkdf2): ... this. All users updated. (_grub_script-check): Rename to ... (_grub_script_check): ... this. All users updated. --- ChangeLog | 10 ++++++++++ util/bash-completion.d/grub-completion.bash.in | 8 ++++---- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9d19fe450..5cc753c11 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2011-09-28 Andreas Born + + Fix incorrect identifiers in bash-completion. + + * util/bash-completion.d/grub-completion.bash.in + (_grub_mkpasswd-pbkdf2): Rename to ... + (_grub_mkpasswd_pbkdf2): ... this. All users updated. + (_grub_script-check): Rename to ... + (_grub_script_check): ... this. All users updated. + 2011-09-28 Vladimir Serbinenko * grub-core/kern/emu/hostdisk.c (grub_util_biosdisk_is_floppy): diff --git a/util/bash-completion.d/grub-completion.bash.in b/util/bash-completion.d/grub-completion.bash.in index 65cbb80ee..64d49fe0b 100644 --- a/util/bash-completion.d/grub-completion.bash.in +++ b/util/bash-completion.d/grub-completion.bash.in @@ -402,7 +402,7 @@ unset __grub_mkimage_program # # grub-mkpasswd-pbkdf2 # -_grub_mkpasswd-pbkdf2 () { +_grub_mkpasswd_pbkdf2 () { local cur COMPREPLY=() @@ -417,7 +417,7 @@ _grub_mkpasswd-pbkdf2 () { } __grub_mkpasswd_pbkdf2_program=$( echo grub-mkpasswd-pbkdf2 | sed "@program_transform_name@" ) have ${__grub_mkpasswd_pbkdf2_program} && \ - complete -F _grub_mkpasswd-pbkdf2 -o filenames ${__grub_mkpasswd_pbkdf2_program} + complete -F _grub_mkpasswd_pbkdf2 -o filenames ${__grub_mkpasswd_pbkdf2_program} unset __grub_mkpasswd_pbkdf2_program @@ -462,7 +462,7 @@ unset __grub_probe_program # # grub-script-check # -_grub_script-check () { +_grub_script_check () { local cur COMPREPLY=() @@ -477,7 +477,7 @@ _grub_script-check () { } __grub_script_check_program=$( echo grub-script-check | sed "@program_transform_name@" ) have ${__grub_script_check_program} && \ - complete -F _grub_script-check -o filenames ${__grub_script_check_program} + complete -F _grub_script_check -o filenames ${__grub_script_check_program} # Local variables: From 91a1a164d66dfdeb4d36ac5bc4f39f62e4aee58f Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 28 Sep 2011 16:43:00 +0200 Subject: [PATCH 807/869] * grub-core/loader/multiboot_elfxx.c (Elf_Shdr): Set according to loader. --- ChangeLog | 5 +++++ grub-core/loader/multiboot_elfxx.c | 3 +++ 2 files changed, 8 insertions(+) diff --git a/ChangeLog b/ChangeLog index 5cc753c11..d415a4bcd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-09-28 Thomas Haller + + * grub-core/loader/multiboot_elfxx.c (Elf_Shdr): Set according to + loader. + 2011-09-28 Andreas Born Fix incorrect identifiers in bash-completion. diff --git a/grub-core/loader/multiboot_elfxx.c b/grub-core/loader/multiboot_elfxx.c index 0c29fe9c2..c6c88f177 100644 --- a/grub-core/loader/multiboot_elfxx.c +++ b/grub-core/loader/multiboot_elfxx.c @@ -22,12 +22,14 @@ # define ELFCLASSXX ELFCLASS32 # define Elf_Ehdr Elf32_Ehdr # define Elf_Phdr Elf32_Phdr +# define Elf_Shdr Elf32_Shdr #elif defined(MULTIBOOT_LOAD_ELF64) # define XX 64 # define E_MACHINE MULTIBOOT_ELF64_MACHINE # define ELFCLASSXX ELFCLASS64 # define Elf_Ehdr Elf64_Ehdr # define Elf_Phdr Elf64_Phdr +# define Elf_Shdr Elf64_Shdr #else #error "I'm confused" #endif @@ -223,3 +225,4 @@ CONCAT(grub_multiboot_load_elf, XX) (grub_file_t file, void *buffer) #undef ELFCLASSXX #undef Elf_Ehdr #undef Elf_Phdr +#undef Elf_Shdr From e0b0dc837b9717842584623126577c74c2dd65d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Sutre?= Date: Wed, 28 Sep 2011 23:45:57 +0200 Subject: [PATCH 808/869] Make knetbsd pass bootinfo bootdisk and bootwedge. --- ChangeLog | 12 +++++ grub-core/loader/i386/bsd.c | 84 +++++++++++++++++++++++++++++ include/grub/bsdlabel.h | 5 +- include/grub/i386/netbsd_bootinfo.h | 11 ++++ 4 files changed, 111 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index d415a4bcd..8cdd158cd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2011-09-28 GrĂ©goire Sutre + + * include/grub/bsdlabel.h (grub_partition_bsd_disk_label): Add fields + type and packname. + * include/grub/i386/netbsd_bootinfo.h (NETBSD_BTINFO_BOOTDISK): + Resurrected. + (NETBSD_BTINFO_BOOTWEDGE): New definition. + (grub_netbsd_btinfo_bootwedge): New struct. + * grub-core/loader/i386/bsd.c (grub_netbsd_add_boot_disk_and_wedge): + New function. + (grub_cmd_netbsd): Call grub_netbsd_add_boot_disk_and_wedge. + 2011-09-28 Thomas Haller * grub-core/loader/multiboot_elfxx.c (Elf_Shdr): Set according to diff --git a/grub-core/loader/i386/bsd.c b/grub-core/loader/i386/bsd.c index dffe48257..18ebeb760 100644 --- a/grub-core/loader/i386/bsd.c +++ b/grub-core/loader/i386/bsd.c @@ -33,6 +33,8 @@ #include #include #include +#include +#include GRUB_MOD_LICENSE ("GPLv3+"); @@ -946,6 +948,86 @@ grub_netbsd_add_modules (void) return err; } +/* + * Adds NetBSD bootinfo bootdisk and bootwedge. The partition identified + * in these bootinfo fields is the root device. + */ +static void +grub_netbsd_add_boot_disk_and_wedge (void) +{ + grub_device_t dev; + grub_disk_t disk; + grub_partition_t part; + grub_uint32_t biosdev; + grub_uint32_t partmapsector; + struct grub_partition_bsd_disk_label *label; + grub_uint64_t buf[GRUB_DISK_SECTOR_SIZE / 8]; + grub_uint8_t *hash; + grub_uint64_t ctx[(GRUB_MD_MD5->contextsize + 7) / 8]; + + dev = grub_device_open (0); + if (! (dev && dev->disk && dev->disk->partition)) + goto fail; + + disk = dev->disk; + part = disk->partition; + + if (disk->dev && disk->dev->id == GRUB_DISK_DEVICE_BIOSDISK_ID) + biosdev = (grub_uint32_t) disk->id & 0xff; + else + biosdev = 0xff; + + /* Absolute sector of the partition map describing this partition. */ + partmapsector = grub_partition_get_start (part->parent) + part->offset; + + disk->partition = part->parent; + if (grub_disk_read (disk, part->offset, 0, GRUB_DISK_SECTOR_SIZE, buf) != GRUB_ERR_NONE) + goto fail; + disk->partition = part; + + /* Fill bootwedge. */ + { + struct grub_netbsd_btinfo_bootwedge biw; + + grub_memset (&biw, 0, sizeof (biw)); + biw.biosdev = biosdev; + biw.startblk = grub_partition_get_start (part); + biw.nblks = part->len; + biw.matchblk = partmapsector; + biw.matchnblks = 1; + + GRUB_MD_MD5->init (&ctx); + GRUB_MD_MD5->write (&ctx, buf, GRUB_DISK_SECTOR_SIZE); + GRUB_MD_MD5->final (&ctx); + hash = GRUB_MD_MD5->read (&ctx); + memcpy (biw.matchhash, hash, 16); + + grub_bsd_add_meta (NETBSD_BTINFO_BOOTWEDGE, &biw, sizeof (biw)); + } + + /* Fill bootdisk if this a NetBSD disk label. */ + label = (struct grub_partition_bsd_disk_label *) &buf; + if (part->partmap != NULL && + (grub_strcmp (part->partmap->name, "netbsd") == 0) && + label->magic == grub_cpu_to_le32 (GRUB_PC_PARTITION_BSD_LABEL_MAGIC)) + { + struct grub_netbsd_btinfo_bootdisk bid; + + grub_memset (&bid, 0, sizeof (bid)); + bid.labelsector = partmapsector; + bid.label.type = label->type; + bid.label.checksum = label->checksum; + memcpy (bid.label.packname, label->packname, 16); + bid.biosdev = biosdev; + bid.partition = part->number; + grub_bsd_add_meta (NETBSD_BTINFO_BOOTDISK, &bid, sizeof (bid)); + } + +fail: + if (dev) + grub_device_close (dev); +} + static grub_err_t grub_netbsd_boot (void) { @@ -1607,6 +1689,8 @@ grub_cmd_netbsd (grub_extcmd_context_t ctxt, int argc, char *argv[]) grub_bsd_add_meta (NETBSD_BTINFO_CONSOLE, &cons, sizeof (cons)); } + grub_netbsd_add_boot_disk_and_wedge (); + grub_loader_set (grub_netbsd_boot, grub_bsd_unload, 0); } diff --git a/include/grub/bsdlabel.h b/include/grub/bsdlabel.h index 636bd41a1..b10336c01 100644 --- a/include/grub/bsdlabel.h +++ b/include/grub/bsdlabel.h @@ -80,7 +80,10 @@ struct grub_partition_bsd_entry struct grub_partition_bsd_disk_label { grub_uint32_t magic; - grub_uint8_t padding[128]; + grub_uint16_t type; + grub_uint8_t unused1[18]; + grub_uint8_t packname[16]; + grub_uint8_t unused2[92]; grub_uint32_t magic2; grub_uint16_t checksum; grub_uint16_t num_partitions; diff --git a/include/grub/i386/netbsd_bootinfo.h b/include/grub/i386/netbsd_bootinfo.h index fd429a251..228f26aaa 100644 --- a/include/grub/i386/netbsd_bootinfo.h +++ b/include/grub/i386/netbsd_bootinfo.h @@ -51,9 +51,11 @@ #define NETBSD_BTINFO_BOOTPATH 0 #define NETBSD_BTINFO_ROOTDEVICE 1 +#define NETBSD_BTINFO_BOOTDISK 3 #define NETBSD_BTINFO_CONSOLE 6 #define NETBSD_BTINFO_SYMTAB 8 #define NETBSD_BTINFO_MEMMAP 9 +#define NETBSD_BTINFO_BOOTWEDGE 10 #define NETBSD_BTINFO_MODULES 11 #define NETBSD_BTINFO_FRAMEBUF 12 @@ -83,6 +85,15 @@ struct grub_netbsd_btinfo_bootdisk grub_uint32_t partition; }; +struct grub_netbsd_btinfo_bootwedge { + grub_uint32_t biosdev; + grub_disk_addr_t startblk; + grub_uint64_t nblks; + grub_disk_addr_t matchblk; + grub_uint64_t matchnblks; + grub_uint8_t matchhash[16]; /* MD5 hash */ +} __packed; + struct grub_netbsd_btinfo_symtab { grub_uint32_t nsyms; From cca7ccd8ff3bd697110c8f55b9e30b78662235f8 Mon Sep 17 00:00:00 2001 From: Mario Limonciello Date: Thu, 29 Sep 2011 10:32:24 +0200 Subject: [PATCH 809/869] Remove extra declaration of sleep for mingw32. * util/misc.c (sleep) [__MINGW32__]: Removed. * include/grub/util/misc.h (sleep) [__MINGW32__]: Likewise. --- ChangeLog | 7 +++++++ include/grub/util/misc.h | 1 - util/misc.c | 5 ----- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index 8cdd158cd..6e4aac746 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2011-09-29 Mario Limonciello + + Remove extra declaration of sleep for mingw32. + + * util/misc.c (sleep) [__MINGW32__]: Removed. + * include/grub/util/misc.h (sleep) [__MINGW32__]: Likewise. + 2011-09-28 GrĂ©goire Sutre * include/grub/bsdlabel.h (grub_partition_bsd_disk_label): Add fields diff --git a/include/grub/util/misc.h b/include/grub/util/misc.h index 48dfbb868..419c8661c 100644 --- a/include/grub/util/misc.h +++ b/include/grub/util/misc.h @@ -47,7 +47,6 @@ void grub_util_write_image_at (const void *img, size_t size, off_t offset, void sync (void); int fsync (int fno); -void sleep(int s); grub_int64_t grub_util_get_disk_size (char *name); diff --git a/util/misc.c b/util/misc.c index cfbae609b..e4425358a 100644 --- a/util/misc.c +++ b/util/misc.c @@ -316,11 +316,6 @@ int fsync (int fno __attribute__ ((unused))) return 0; } -void sleep (int s) -{ - Sleep (s * 1000); -} - grub_int64_t grub_util_get_disk_size (char *name) { From c05de0329b198bed24e8b8e120877958d9a8cead Mon Sep 17 00:00:00 2001 From: Mario Limonciello Date: Thu, 29 Sep 2011 10:36:55 +0200 Subject: [PATCH 810/869] * grub-core/kern/emu/misc.c (canonicalize_file_name) [__MINGW32__]: Use _fullpath. --- ChangeLog | 5 +++++ grub-core/kern/emu/misc.c | 6 +++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 6e4aac746..bc5508d32 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-09-29 Mario Limonciello + + * grub-core/kern/emu/misc.c (canonicalize_file_name) [__MINGW32__]: Use + _fullpath. + 2011-09-29 Mario Limonciello Remove extra declaration of sleep for mingw32. diff --git a/grub-core/kern/emu/misc.c b/grub-core/kern/emu/misc.c index 737f5f1a9..6f5ea9fb9 100644 --- a/grub-core/kern/emu/misc.c +++ b/grub-core/kern/emu/misc.c @@ -224,7 +224,11 @@ char * canonicalize_file_name (const char *path) { char *ret; -#ifdef PATH_MAX +#ifdef __MINGW32__ + ret = xmalloc (PATH_MAX); + if (!_fullpath (ret, path, PATH_MAX)) + return NULL; +#elif defined (PATH_MAX) ret = xmalloc (PATH_MAX); if (!realpath (path, ret)) return NULL; From d1ab689de800eb4a7d66306c96d9dd4f502cf4e5 Mon Sep 17 00:00:00 2001 From: Mario Limonciello Date: Thu, 29 Sep 2011 10:39:44 +0200 Subject: [PATCH 811/869] * util/misc.c (grub_util_get_disk_size) [__MINGW32__]: Strip trailing slashes on PHYSICALDRIVE%d paths when making Windows CreateFile calls. --- ChangeLog | 5 +++++ util/misc.c | 2 ++ 2 files changed, 7 insertions(+) diff --git a/ChangeLog b/ChangeLog index bc5508d32..df31ef3e3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-09-29 Mario Limonciello + + * util/misc.c (grub_util_get_disk_size) [__MINGW32__]: Strip trailing + slashes on PHYSICALDRIVE%d paths when making Windows CreateFile calls. + 2011-09-29 Mario Limonciello * grub-core/kern/emu/misc.c (canonicalize_file_name) [__MINGW32__]: Use diff --git a/util/misc.c b/util/misc.c index e4425358a..72bedde0c 100644 --- a/util/misc.c +++ b/util/misc.c @@ -55,6 +55,7 @@ #ifdef __MINGW32__ #include #include +#include "dirname.h" #endif #ifdef GRUB_UTIL @@ -322,6 +323,7 @@ grub_util_get_disk_size (char *name) HANDLE hd; grub_int64_t size = -1LL; + strip_trailing_slashes(name); hd = CreateFile (name, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, 0, OPEN_EXISTING, 0, 0); From fc5efcc08346469bb9f4bbb3c3f0b3f4b8c5b4b6 Mon Sep 17 00:00:00 2001 From: Mads Kiilerich Date: Thu, 29 Sep 2011 10:50:25 +0200 Subject: [PATCH 812/869] * grub-core/Makefile.core.def (kernel): Add kern/i386/int.S to extra_dist. --- ChangeLog | 5 +++++ grub-core/Makefile.core.def | 1 + 2 files changed, 6 insertions(+) diff --git a/ChangeLog b/ChangeLog index df31ef3e3..db2e0b1f6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-09-29 Mads Kiilerich + + * grub-core/Makefile.core.def (kernel): Add kern/i386/int.S to + extra_dist. + 2011-09-29 Mario Limonciello * util/misc.c (grub_util_get_disk_size) [__MINGW32__]: Strip trailing diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def index e95d87d37..e9e4f06d8 100644 --- a/grub-core/Makefile.core.def +++ b/grub-core/Makefile.core.def @@ -219,6 +219,7 @@ kernel = { videoinkernel = commands/boot.c; + extra_dist = kern/i386/int.S; extra_dist = kern/i386/realmode.S; extra_dist = kern/i386/pc/lzma_decode.S; extra_dist = kern/mips/cache_flush.S; From 8667a314babe5f09580d06d86a3db6489cdcc31e Mon Sep 17 00:00:00 2001 From: BVK Chaitanya Date: Fri, 30 Sep 2011 18:49:37 -0700 Subject: [PATCH 813/869] * gentpl.py: Use Autogen macros so that the output template file (Makefile.tpl) size is reduced. --- ChangeLog | 5 +++ gentpl.py | 114 +++++++++++++++++++++++++++++++++++++++++++++++------- 2 files changed, 105 insertions(+), 14 deletions(-) diff --git a/ChangeLog b/ChangeLog index db2e0b1f6..ad0e6792f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-08-25 BVK Chaitanya + + * gentpl.py: Use Autogen macros so that the output template file + (Makefile.tpl) size is reduced. + 2011-09-29 Mads Kiilerich * grub-core/Makefile.core.def (kernel): Add kern/i386/int.S to diff --git a/gentpl.py b/gentpl.py index e431293eb..cb6b663d9 100644 --- a/gentpl.py +++ b/gentpl.py @@ -183,6 +183,17 @@ def foreach_platform_specific_value(platform, suffix, nonetag, closure): r += "[+ ELSE +][+ FOR " + nonetag + " +]" + closure("[+ ." + nonetag + " +]") + "[+ ENDFOR +][+ ENDIF +]" return r +# +# Returns autogen code that defines an autogen macro using the +# definition given in the 'snippet'. +# +def define_autogen_macro(name, snippet): + r = "" + r += "[+ DEFINE " + name + " +]" + r += snippet + r += "[+ ENDDEF +]\n" + return r + # # Template for handling values from sum of all groups for a platform, # for example: @@ -245,10 +256,18 @@ def foreach_enabled_platform(closure): # emu_condition = COND_GRUB_EMU_USB; # }; # +def define_macro_for_platform_conditionals_if_statement(p): + return define_autogen_macro( + "if_" + p + "_conditionals", + foreach_platform_specific_value(platform, "_condition", "condition", lambda cond: "if " + cond + "\n")) +def define_macro_for_platform_conditionals_endif_statement(p): + return define_autogen_macro( + "endif_" + p + "_conditionals", + foreach_platform_specific_value(platform, "_condition", "condition", lambda cond: "endif " + cond + "\n")) def under_platform_specific_conditionals(platform, snippet): - r = foreach_platform_specific_value(platform, "_condition", "condition", lambda cond: "if " + cond + "\n") + r = "[+ if_" + platform + "_conditionals +]" r += snippet - r += foreach_platform_specific_value(platform, "_condition", "condition", lambda cond: "endif " + cond + "\n") + r += "[+ endif_" + platform + "_conditionals +]" return r def platform_specific_values(platform, suffix, nonetag): @@ -261,18 +280,69 @@ def platform_values(platform, suffix): def extra_dist(): return foreach_value("extra_dist", lambda value: value + " ") -def platform_sources(p): return platform_values(p, "") -def platform_nodist_sources(p): return platform_values(p, "_nodist") -def platform_dependencies(p): return platform_values(p, "dependencies", "_dependencies") +def define_macro_for_platform_sources(p): + return define_autogen_macro( + "get_" + p + "_sources", + platform_values(p, "")) +def define_macro_for_platform_nodist_sources(p): + return define_autogen_macro( + "get_" + p + "_nodist_sources", + platform_values(p, "_nodist")) +def define_macro_for_platform_dependencies(p): + return define_autogen_macro( + "get_" + p + "_dependencies", + platform_values(p, "dependencies", "_dependencies")) +def platform_sources(p): return "[+ get_" + p + "_sources +]" +def platform_nodist_sources(p): return "[+ get_" + p + "_nodist_sources +]" +def platform_dependencies(p): return "[+ get_" + p + "_dependencies +]" -def platform_startup(p): return platform_specific_values(p, "_startup", "startup") -def platform_ldadd(p): return platform_specific_values(p, "_ldadd", "ldadd") -def platform_cflags(p): return platform_specific_values(p, "_cflags", "cflags") -def platform_ldflags(p): return platform_specific_values(p, "_ldflags", "ldflags") -def platform_cppflags(p): return platform_specific_values(p, "_cppflags", "cppflags") -def platform_ccasflags(p): return platform_specific_values(p, "_ccasflags", "ccasflags") -def platform_stripflags(p): return platform_specific_values(p, "_stripflags", "stripflags") -def platform_objcopyflags(p): return platform_specific_values(p, "_objcopyflags", "objcopyflags") +# +# Returns Autogen code which defines the autogen macros that collect +# platform specific values for cflags, ldflags, etc. tags. +# +def define_macro_for_platform_startup(p): + return define_autogen_macro( + "get_" + p + "_startup", + platform_specific_values(p, "_startup", "startup")) +def define_macro_for_platform_cflags(p): + return define_autogen_macro( + "get_" + p + "_cflags", + platform_specific_values(p, "_cflags", "cflags")) +def define_macro_for_platform_ldadd(p): + return define_autogen_macro( + "get_" + p + "_ldadd", + platform_specific_values(p, "_ldadd", "ldadd")) +def define_macro_for_platform_ldflags(p): + return define_autogen_macro( + "get_" + p + "_ldflags", + platform_specific_values(p, "_ldflags", "ldflags")) +def define_macro_for_platform_cppflags(p): + return define_autogen_macro( + "get_" + p + "_cppflags", + platform_specific_values(p, "_cppflags", "cppflags")) +def define_macro_for_platform_ccasflags(p): + return define_autogen_macro( + "get_" + p + "_ccasflags", + platform_specific_values(p, "_ccasflags", "ccasflags")) +def define_macro_for_platform_stripflags(p): + return define_autogen_macro( + "get_" + p + "_stripflags", + platform_specific_values(p, "_stripflags", "stripflags")) +def define_macro_for_platform_objcopyflags(p): + return define_autogen_macro( + "get_" + p + "_objcopyflags", + platform_specific_values(p, "_objcopyflags", "objcopyflags")) +# +# Autogen calls to invoke the above macros. +# +def platform_startup(p): return "[+ get_" + p + "_startup +]" +def platform_ldadd(p): return "[+ get_" + p + "_ldadd +]" +def platform_cflags(p): return "[+ get_" + p + "_cflags +]" +def platform_ldflags(p): return "[+ get_" + p + "_ldflags +]" +def platform_cppflags(p): return "[+ get_" + p + "_cppflags +]" +def platform_ccasflags(p): return "[+ get_" + p + "_ccasflags +]" +def platform_stripflags(p): return "[+ get_" + p + "_stripflags +]" +def platform_objcopyflags(p): return "[+ get_" + p + "_objcopyflags +]" # # Emit snippet only the first time through for the current name. @@ -489,7 +559,6 @@ def script_rules(): def data_rules(): return rules("data", data) -print "[+ AutoGen5 template +]\n" a = module_rules() b = kernel_rules() c = image_rules() @@ -499,6 +568,23 @@ f = script_rules() g = data_rules() z = global_variable_initializers() +print "[+ AutoGen5 template +]\n" +for p in GRUB_PLATFORMS: + print define_macro_for_platform_sources(p) + print define_macro_for_platform_nodist_sources(p) + # print define_macro_for_platform_dependencies(p) + + print define_macro_for_platform_startup(p) + print define_macro_for_platform_cflags(p) + print define_macro_for_platform_ldadd(p) + print define_macro_for_platform_ldflags(p) + print define_macro_for_platform_cppflags(p) + print define_macro_for_platform_ccasflags(p) + print define_macro_for_platform_stripflags(p) + print define_macro_for_platform_objcopyflags(p) + + print define_macro_for_platform_conditionals_if_statement(p) + print define_macro_for_platform_conditionals_endif_statement(p) # print z # initializer for all vars print a print b From ce79cc99d500a92c927a15647d0c86bde6d0448c Mon Sep 17 00:00:00 2001 From: starous Date: Sat, 1 Oct 2011 21:27:29 +0200 Subject: [PATCH 814/869] @Rock changes - fixed coreboot problem --- ChangeLog | 5 +++++ grub-core/bus/usb/uhci.c | 48 +++++++++++++++++++++++++++++++++++----- 2 files changed, 48 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index ad0e6792f..5d1fc0c69 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-10-01 Ales Nesrsta + + * grub-core/bus/usb/uhci.c: Changes made by Rock Cui - thanks! + (fixed problem related to using UHCI with coreboot). + 2011-08-25 BVK Chaitanya * gentpl.py: Use Autogen macros so that the output template file diff --git a/grub-core/bus/usb/uhci.c b/grub-core/bus/usb/uhci.c index 99e597f6d..260b7e876 100644 --- a/grub-core/bus/usb/uhci.c +++ b/grub-core/bus/usb/uhci.c @@ -36,11 +36,33 @@ GRUB_MOD_LICENSE ("GPLv3+"); typedef enum { GRUB_UHCI_REG_USBCMD = 0x00, + GRUB_UHCI_REG_USBINTR = 0x04, GRUB_UHCI_REG_FLBASEADD = 0x08, GRUB_UHCI_REG_PORTSC1 = 0x10, - GRUB_UHCI_REG_PORTSC2 = 0x12 + GRUB_UHCI_REG_PORTSC2 = 0x12, + GRUB_UHCI_REG_USBLEGSUP = 0xc0 } grub_uhci_reg_t; +/* R/WC legacy support bits */ +#define GRUB_UHCI_LEGSUP_END_A20GATE (1 << 15) +#define GRUB_UHCI_TRAP_BY_64H_WSTAT (1 << 11) +#define GRUB_UHCI_TRAP_BY_64H_RSTAT (1 << 10) +#define GRUB_UHCI_TRAP_BY_60H_WSTAT (1 << 9) +#define GRUB_UHCI_TRAP_BY_60H_RSTAT (1 << 8) + +/* Reset all legacy support - clear all R/WC bits and all R/W bits */ +#define GRUB_UHCI_RESET_LEGSUP_SMI ( GRUB_UHCI_LEGSUP_END_A20GATE \ + | GRUB_UHCI_TRAP_BY_64H_WSTAT \ + | GRUB_UHCI_TRAP_BY_64H_RSTAT \ + | GRUB_UHCI_TRAP_BY_60H_WSTAT \ + | GRUB_UHCI_TRAP_BY_60H_RSTAT ) + +/* Some UHCI commands */ +#define GRUB_UHCI_CMD_RUN_STOP (1 << 0) +#define GRUB_UHCI_CMD_HCRESET (1 << 1) +#define GRUB_UHCI_CMD_MAXP (1 << 7) + +/* Important bits in structures */ #define GRUB_UHCI_LINK_TERMINATE 1 #define GRUB_UHCI_LINK_QUEUE_HEAD 2 @@ -181,6 +203,11 @@ grub_uhci_pci_iter (grub_pci_device_t dev, if (class != 0x0c || subclass != 0x03 || interf != 0x00) return 0; + /* Set bus master - needed for coreboot or broken BIOSes */ + addr = grub_pci_make_address (dev, GRUB_PCI_REG_COMMAND); + grub_pci_write_word(addr, + GRUB_PCI_COMMAND_BUS_MASTER | grub_pci_read_word(addr)); + /* Determine IO base address. */ addr = grub_pci_make_address (dev, GRUB_PCI_REG_ADDRESS_REG4); base = grub_pci_read (addr); @@ -195,6 +222,19 @@ grub_uhci_pci_iter (grub_pci_device_t dev, u->iobase = base & GRUB_UHCI_IOMASK; + /* Reset PIRQ and SMI */ + addr = grub_pci_make_address (dev, GRUB_UHCI_REG_USBLEGSUP); + grub_pci_write_word(addr, GRUB_UHCI_RESET_LEGSUP_SMI); + /* Reset the HC */ + grub_uhci_writereg16(u, GRUB_UHCI_REG_USBCMD, GRUB_UHCI_CMD_HCRESET); + grub_millisleep(5); + /* Disable interrupts and commands (just to be safe) */ + grub_uhci_writereg16(u, GRUB_UHCI_REG_USBINTR, 0); + /* Finish HC reset, HC remains disabled */ + grub_uhci_writereg16(u, GRUB_UHCI_REG_USBCMD, 0); + /* Read back to be sure PCI write is done */ + grub_uhci_readreg16(u, GRUB_UHCI_REG_USBCMD); + /* Reserve a page for the frame list. */ u->framelist = grub_memalign (4096, 4096); if (! u->framelist) @@ -252,9 +292,6 @@ grub_uhci_pci_iter (grub_pci_device_t dev, u->td[N_TD - 2].linkptr = 0; u->tdfree = u->td; - /* Make sure UHCI is disabled! */ - grub_uhci_writereg16 (u, GRUB_UHCI_REG_USBCMD, 0); - /* Setup the frame list pointers. Since no isochronous transfers are and will be supported, they all point to the (same!) queue head. */ @@ -285,7 +322,8 @@ grub_uhci_pci_iter (grub_pci_device_t dev, u->qh[N_QH - 1].linkptr = 1; /* Enable UHCI again. */ - grub_uhci_writereg16 (u, GRUB_UHCI_REG_USBCMD, 1 | (1 << 7)); + grub_uhci_writereg16 (u, GRUB_UHCI_REG_USBCMD, + GRUB_UHCI_CMD_RUN_STOP | GRUB_UHCI_CMD_MAXP); /* UHCI is initialized and ready for transfers. */ grub_dprintf ("uhci", "UHCI initialized\n"); From 139d67a82fb1738e642424e2d425916d97c8e098 Mon Sep 17 00:00:00 2001 From: Szymon Janc Date: Mon, 3 Oct 2011 21:50:32 +0200 Subject: [PATCH 815/869] * grub-core/fs/btrfs.c: Fix code style regressions. --- grub-core/fs/btrfs.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/grub-core/fs/btrfs.c b/grub-core/fs/btrfs.c index 534ce15de..5b8dca559 100644 --- a/grub-core/fs/btrfs.c +++ b/grub-core/fs/btrfs.c @@ -330,8 +330,8 @@ next (struct grub_btrfs_data *data, for (; desc->depth > 0; desc->depth--) { desc->data[desc->depth - 1].iter++; - if (desc->data[desc->depth - 1].iter < - desc->data[desc->depth - 1].maxiter) + if (desc->data[desc->depth - 1].iter + < desc->data[desc->depth - 1].maxiter) break; } if (desc->depth == 0) @@ -376,7 +376,7 @@ lower_bound (struct grub_btrfs_data *data, const struct grub_btrfs_key *key_in, struct grub_btrfs_key *key_out, grub_disk_addr_t root, - grub_disk_addr_t * outaddr, grub_size_t * outsize, + grub_disk_addr_t *outaddr, grub_size_t *outsize, struct grub_btrfs_leaf_descriptor *desc) { grub_disk_addr_t addr = root; @@ -626,8 +626,8 @@ grub_btrfs_read_logical (struct grub_btrfs_data *data, grub_disk_addr_t addr, grub_le_to_cpu64 (key->offset), grub_le_to_cpu64 (chunk->size)); if (grub_le_to_cpu64 (key->offset) <= addr - && addr < - grub_le_to_cpu64 (key->offset) + grub_le_to_cpu64 (chunk->size)) + && addr < grub_le_to_cpu64 (key->offset) + + grub_le_to_cpu64 (chunk->size)) goto chunk_found; ptr += sizeof (*key) + sizeof (*chunk) + sizeof (struct grub_btrfs_chunk_stripe) @@ -1007,8 +1007,8 @@ grub_btrfs_extent_read (struct grub_btrfs_data *data, data->extend = data->extstart + grub_le_to_cpu64 (data->extent->size); if (data->extent->type == GRUB_BTRFS_EXTENT_REGULAR - && (char *) &data->extent + elemsize >= - (char *) &data->extent->filled + sizeof (data->extent->filled)) + && (char *) &data->extent + elemsize + >= (char *) &data->extent->filled + sizeof (data->extent->filled)) data->extend = data->extstart + grub_le_to_cpu64 (data->extent->filled); @@ -1113,7 +1113,7 @@ grub_btrfs_extent_read (struct grub_btrfs_data *data, else ret = -1; - grub_free(tmp); + grub_free (tmp); if (ret != (grub_ssize_t) csize) return -1; @@ -1142,7 +1142,7 @@ grub_btrfs_extent_read (struct grub_btrfs_data *data, static grub_err_t find_path (struct grub_btrfs_data *data, const char *path, struct grub_btrfs_key *key, - grub_uint64_t * tree, grub_uint8_t * type) + grub_uint64_t *tree, grub_uint8_t *type) { const char *slash = path; grub_err_t err; @@ -1391,7 +1391,7 @@ find_path (struct grub_btrfs_data *data, static grub_err_t grub_btrfs_dir (grub_device_t device, const char *path, int (*hook) (const char *filename, - const struct grub_dirhook_info * info)) + const struct grub_dirhook_info *info)) { struct grub_btrfs_data *data = grub_btrfs_mount (device); struct grub_btrfs_key key_in, key_out; From c5ed9266fc216a2c62781b87d6a4ff97315a70f0 Mon Sep 17 00:00:00 2001 From: Szymon Janc Date: Mon, 3 Oct 2011 22:06:10 +0200 Subject: [PATCH 816/869] * grub-core/io/lzopio.c: Improve crypt context alignment. --- grub-core/io/lzopio.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/grub-core/io/lzopio.c b/grub-core/io/lzopio.c index e303b29a3..d804c31b0 100644 --- a/grub-core/io/lzopio.c +++ b/grub-core/io/lzopio.c @@ -166,7 +166,7 @@ read_block_data (struct grub_lzopio *lzopio) if (lzopio->ccheck_fun) { - grub_uint8_t context[lzopio->ccheck_fun->contextsize]; + grub_uint64_t context[(lzopio->ccheck_fun->contextsize + 7) / 8]; lzopio->ccheck_fun->init (context); lzopio->ccheck_fun->write (context, lzopio->block.cdata, @@ -212,7 +212,7 @@ uncompress_block (struct grub_lzopio *lzopio) if (lzopio->ucheck_fun) { - grub_uint8_t context[lzopio->ucheck_fun->contextsize]; + grub_uint64_t context[(lzopio->ccheck_fun->contextsize + 7) / 8]; lzopio->ucheck_fun->init (context); lzopio->ucheck_fun->write (context, lzopio->block.udata, From 0e2b7e39f2e2d9089efb307d9e58aedf3e5b1c57 Mon Sep 17 00:00:00 2001 From: Szymon Janc Date: Mon, 3 Oct 2011 22:25:06 +0200 Subject: [PATCH 817/869] * grub-core/fs/btrfs.c: Include instead of "minilzo.h". * grub-core/io/lzopio.c: Likewise. --- grub-core/fs/btrfs.c | 2 +- grub-core/io/lzopio.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/grub-core/fs/btrfs.c b/grub-core/fs/btrfs.c index 5b8dca559..93642f789 100644 --- a/grub-core/fs/btrfs.c +++ b/grub-core/fs/btrfs.c @@ -26,7 +26,7 @@ #include #include #include -#include "minilzo.h" +#include GRUB_MOD_LICENSE ("GPLv3+"); diff --git a/grub-core/io/lzopio.c b/grub-core/io/lzopio.c index d804c31b0..e2bbf79b7 100644 --- a/grub-core/io/lzopio.c +++ b/grub-core/io/lzopio.c @@ -23,7 +23,7 @@ #include #include #include -#include "minilzo.h" +#include GRUB_MOD_LICENSE ("GPLv3+"); From b871e8ebcca01098727b1bc324e490b8de5a5a1b Mon Sep 17 00:00:00 2001 From: Szymon Janc Date: Mon, 3 Oct 2011 23:01:14 +0200 Subject: [PATCH 818/869] * grub-core/Makefile.core.def (btrfs): Remove minilzo.c from common. --- grub-core/Makefile.core.def | 1 - 1 file changed, 1 deletion(-) diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def index 77dc7ed4b..b58a75f67 100644 --- a/grub-core/Makefile.core.def +++ b/grub-core/Makefile.core.def @@ -980,7 +980,6 @@ module = { name = btrfs; common = fs/btrfs.c; common = lib/crc.c; - common = lib/minilzo/minilzo.c; cflags = '$(CFLAGS_POSIX) -Wno-undef'; cppflags = '-I$(srcdir)/lib/posix_wrap -I$(srcdir)/lib/minilzo -DMINILZO_HAVE_CONFIG_H'; }; From bc4d3f4809353539891a04bc218ff7ef37cb2536 Mon Sep 17 00:00:00 2001 From: Szymon Janc Date: Tue, 4 Oct 2011 21:10:21 +0200 Subject: [PATCH 819/869] * grub-core/io/lzopio.c (calculate_uncompressed_size): Fix return code. --- grub-core/io/lzopio.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/grub-core/io/lzopio.c b/grub-core/io/lzopio.c index e2bbf79b7..02a70f4d8 100644 --- a/grub-core/io/lzopio.c +++ b/grub-core/io/lzopio.c @@ -256,7 +256,7 @@ calculate_uncompressed_size (grub_file_t file) grub_off_t usize_total = 0; if (read_block_header (lzopio) < 0) - return 0; + return -1; /* FIXME: Don't do this for not easily seekable files. */ while (lzopio->block.usize != 0) @@ -264,12 +264,12 @@ calculate_uncompressed_size (grub_file_t file) usize_total += lzopio->block.usize; if (jump_block (lzopio) < 0) - return 0; + return -1; } file->size = usize_total; - return 1; + return 0; } struct lzop_header From fe942b7dbb891a3f092acdb63a63ee0376cb5cba Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 5 Oct 2011 11:53:36 +0200 Subject: [PATCH 820/869] * grub-core/Makefile.core.def: Eliminate rarely used emu_condition. This in perspective decreases the complexity of build system and fixes compilation right now. --- grub-core/Makefile.core.def | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def index e9e4f06d8..3b701633c 100644 --- a/grub-core/Makefile.core.def +++ b/grub-core/Makefile.core.def @@ -400,11 +400,15 @@ module = { module = { name = usb; common = bus/usb/usb.c; - noemu = bus/usb/usbtrans.c; - noemu = bus/usb/usbhub.c; - enable = emu; + common = bus/usb/usbtrans.c; + common = bus/usb/usbhub.c; enable = usb; - emu_condition = COND_GRUB_EMU_USB; +}; + +module = { + name = emuusb; + common = bus/usb/usb.c; + condition = COND_GRUB_EMU_USB; }; module = { @@ -439,18 +443,22 @@ module = { module = { name = pci; - noemu = bus/pci.c; - emu = bus/emu/pci.c; - emu = commands/lspci.c; + common = bus/pci.c; - enable = emu; enable = i386_pc; enable = i386_efi; enable = x86_64_efi; enable = i386_ieee1275; enable = i386_coreboot; enable = i386_multiboot; - emu_condition = COND_GRUB_EMU_PCI; +}; + +module = { + name = emupci; + common = bus/emu/pci.c; + common = commands/lspci.c; + + condition = COND_GRUB_EMU_PCI; }; module = { @@ -788,8 +796,6 @@ module = { name = usbtest; common = commands/usbtest.c; enable = usb; - enable = emu; - emu_condition = COND_GRUB_EMU_USB; }; module = { @@ -903,8 +909,6 @@ module = { name = usbms; common = disk/usbms.c; enable = usb; - enable = emu; - emu_condition = COND_GRUB_EMU_USB; }; module = { @@ -1446,9 +1450,7 @@ module = { common = term/serial.c; x86 = term/ns8250.c; - enable = emu; enable = x86; - emu_condition = COND_GRUB_EMU_USB; }; module = { From a98f4a0808308815c5580d3ac23b2442d02ced33 Mon Sep 17 00:00:00 2001 From: Robert Millan Date: Sun, 9 Oct 2011 21:13:00 +0200 Subject: [PATCH 821/869] 2011-10-09 Robert Millan LVM support for FreeBSD and GNU/kFreeBSD. * util/lvm.c (grub_util_lvm_isvolume): Enable on FreeBSD and GNU/kFreeBSD. (LVM_DEV_MAPPER_STRING): Move from here ... * include/grub/util/lvm.h (LVM_DEV_MAPPER_STRING): ... to here. * util/getroot.c: Include `'. (grub_util_get_dev_abstraction): Enable grub_util_biosdisk_is_present() on FreeBSD and GNU/kFreeBSD. Check for LVM abstraction on FreeBSD and GNU/kFreeBSD. (grub_util_get_grub_dev): Replace "/dev/mapper/" with `LVM_DEV_MAPPER_STRING'. Enable LVM and mdRAID only on platforms that support it. * util/grub-setup.c (main): Check for LVM also on FreeBSD and GNU/kFreeBSD. * util/grub.d/10_kfreebsd.in: Load `geom_linux_lvm' kernel module when LVM abstraction is required for ${GRUB_DEVICE}. --- ChangeLog | 20 ++++++++++++++++++++ include/grub/util/lvm.h | 9 ++++++++- util/getroot.c | 24 ++++++++++++++++-------- util/grub-setup.c | 6 ++++-- util/grub.d/10_kfreebsd.in | 8 +++++++- util/lvm.c | 9 +++------ 6 files changed, 58 insertions(+), 18 deletions(-) diff --git a/ChangeLog b/ChangeLog index 6484cf826..19db47e04 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,23 @@ +2011-10-09 Robert Millan + + LVM support for FreeBSD and GNU/kFreeBSD. + + * util/lvm.c (grub_util_lvm_isvolume): Enable on FreeBSD and + GNU/kFreeBSD. + (LVM_DEV_MAPPER_STRING): Move from here ... + * include/grub/util/lvm.h (LVM_DEV_MAPPER_STRING): ... to here. + * util/getroot.c: Include `'. + (grub_util_get_dev_abstraction): Enable + grub_util_biosdisk_is_present() on FreeBSD and GNU/kFreeBSD. + Check for LVM abstraction on FreeBSD and GNU/kFreeBSD. + (grub_util_get_grub_dev): Replace "/dev/mapper/" with + `LVM_DEV_MAPPER_STRING'. Enable LVM and mdRAID only on platforms that + support it. + * util/grub-setup.c (main): Check for LVM also on FreeBSD and + GNU/kFreeBSD. + * util/grub.d/10_kfreebsd.in: Load `geom_linux_lvm' kernel module + when LVM abstraction is required for ${GRUB_DEVICE}. + 2011-10-06 Szymon Janc Add support for LZO compression in GRUB: diff --git a/include/grub/util/lvm.h b/include/grub/util/lvm.h index 7a4c76c6b..ff268f83f 100644 --- a/include/grub/util/lvm.h +++ b/include/grub/util/lvm.h @@ -1,7 +1,7 @@ /* lvm.h - LVM support for GRUB utils. */ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2006,2007 Free Software Foundation, Inc. + * Copyright (C) 2006,2007,2011 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -20,7 +20,14 @@ #ifndef GRUB_LVM_UTIL_HEADER #define GRUB_LVM_UTIL_HEADER 1 +#if defined(__linux__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__) + #ifdef __linux__ +#define LVM_DEV_MAPPER_STRING "/dev/mapper/" +#else +#define LVM_DEV_MAPPER_STRING "/dev/linux_lvm/" +#endif + int grub_util_lvm_isvolume (char *name); #endif diff --git a/util/getroot.c b/util/getroot.c index 71064583f..7c5602e71 100644 --- a/util/getroot.c +++ b/util/getroot.c @@ -1,7 +1,7 @@ /* getroot.c - Get root device */ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 1999,2000,2001,2002,2003,2006,2007,2008,2009,2010 Free Software Foundation, Inc. + * Copyright (C) 1999,2000,2001,2002,2003,2006,2007,2008,2009,2010,2011 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -33,6 +33,7 @@ #include #include #include +#include #include #ifdef HAVE_DEVICE_MAPPER @@ -856,12 +857,14 @@ grub_util_get_geom_abstraction (const char *dev) int grub_util_get_dev_abstraction (const char *os_dev __attribute__((unused))) { -#ifdef __linux__ - enum grub_dev_abstraction_types ret; - +#if defined(__linux__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__) /* User explicitly claims that this drive is visible by BIOS. */ if (grub_util_biosdisk_is_present (os_dev)) return GRUB_DEV_ABSTRACTION_NONE; +#endif + +#ifdef __linux__ + enum grub_dev_abstraction_types ret; /* Check for LVM and LUKS. */ ret = grub_util_get_dm_abstraction (os_dev); @@ -880,6 +883,10 @@ grub_util_get_dev_abstraction (const char *os_dev __attribute__((unused))) grub_util_info ("abstraction of %s is %s", os_dev, abs); if (abs && grub_strcasecmp (abs, "eli") == 0) return GRUB_DEV_ABSTRACTION_GELI; + + /* Check for LVM. */ + if (!strncmp (os_dev, LVM_DEV_MAPPER_STRING, sizeof(LVM_DEV_MAPPER_STRING)-1)) + return GRUB_DEV_ABSTRACTION_LVM; #endif /* No abstraction found. */ @@ -1111,11 +1118,12 @@ grub_util_get_grub_dev (const char *os_dev) switch (grub_util_get_dev_abstraction (os_dev)) { +#if defined(__linux__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__) case GRUB_DEV_ABSTRACTION_LVM: { unsigned short i, len; - grub_size_t offset = sizeof ("/dev/mapper/") - 1; + grub_size_t offset = sizeof (LVM_DEV_MAPPER_STRING) - 1; len = strlen (os_dev) - offset + 1; grub_dev = xmalloc (len + sizeof ("lvm/")); @@ -1191,7 +1199,9 @@ grub_util_get_grub_dev (const char *os_dev) } #endif break; +#endif +#ifdef __linux__ case GRUB_DEV_ABSTRACTION_RAID: if (os_dev[7] == '_' && os_dev[8] == 'd') @@ -1267,7 +1277,6 @@ grub_util_get_grub_dev (const char *os_dev) else grub_util_error ("unknown kind of RAID device `%s'", os_dev); -#ifdef __linux__ { char *mdadm_name = get_mdadm_uuid (os_dev); struct stat st; @@ -1292,9 +1301,8 @@ grub_util_get_grub_dev (const char *os_dev) free (mdadm_name); } } -#endif /* __linux__ */ - break; +#endif /* __linux__ */ default: /* GRUB_DEV_ABSTRACTION_NONE */ grub_dev = grub_util_biosdisk_get_grub_dev (os_dev); diff --git a/util/grub-setup.c b/util/grub-setup.c index 2505c03a4..b3a6c5c76 100644 --- a/util/grub-setup.c +++ b/util/grub-setup.c @@ -1,7 +1,7 @@ /* grub-setup.c - make GRUB usable */ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 1999,2000,2001,2002,2003,2004,2005,2006,2007,2008,2009,2010 Free Software Foundation, Inc. + * Copyright (C) 1999,2000,2001,2002,2003,2004,2005,2006,2007,2008,2009,2010,2011 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -954,10 +954,12 @@ main (int argc, char *argv[]) arguments.dir ? : DEFAULT_DIRECTORY); } -#ifdef __linux__ +#if defined(__linux__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__) if (grub_util_lvm_isvolume (root_dev)) must_embed = 1; +#endif +#ifdef __linux__ if (root_dev[0] == 'm' && root_dev[1] == 'd' && ((root_dev[2] >= '0' && root_dev[2] <= '9') || root_dev[2] == '/')) { diff --git a/util/grub.d/10_kfreebsd.in b/util/grub.d/10_kfreebsd.in index 2ade4ea35..e4bfc06cb 100644 --- a/util/grub.d/10_kfreebsd.in +++ b/util/grub.d/10_kfreebsd.in @@ -2,7 +2,7 @@ set -e # grub-mkconfig helper script. -# Copyright (C) 2006,2007,2008,2009,2010 Free Software Foundation, Inc. +# Copyright (C) 2006,2007,2008,2009,2010,2011 Free Software Foundation, Inc. # # GRUB is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -98,6 +98,12 @@ EOF load_kfreebsd_module acpi true + for abstraction in dummy $(grub-probe -t abstraction --device ${GRUB_DEVICE}) ; do + case $abstraction in + lvm) load_kfreebsd_module geom_linux_lvm false ;; + esac + done + case "${kfreebsd_fs}" in zfs) load_kfreebsd_module opensolaris false diff --git a/util/lvm.c b/util/lvm.c index bb2c19fe3..0bc271e46 100644 --- a/util/lvm.c +++ b/util/lvm.c @@ -1,7 +1,7 @@ /* lvm.c - LVM support for GRUB utils. */ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2006,2007,2008 Free Software Foundation, Inc. + * Copyright (C) 2006,2007,2008,2011 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -17,8 +17,7 @@ * along with GRUB. If not, see . */ -/* We only support LVM on Linux. */ -#ifdef __linux__ +#if defined(__linux__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__) #include #include #include @@ -26,8 +25,6 @@ #include #include -#define LVM_DEV_MAPPER_STRING "/dev/mapper/" - int grub_util_lvm_isvolume (char *name) { @@ -49,4 +46,4 @@ grub_util_lvm_isvolume (char *name) return 1; } -#endif /* ! __linux__ */ +#endif From 0eb8ffb1f579d4507d78a822c843e334417f9ba1 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 14 Oct 2011 19:16:37 +0200 Subject: [PATCH 822/869] * grub-core/lib/posix_wrap/ctype.h (isxdigit): Use grub_isxdigit. * include/grub/misc.h (grub_isxdigit): New function. * grub-core/video/colors.c (my_isxdigit): Removed. All users switched to grub_isxdigit. * grub-core/term/serial.c (grub_serial_find): Fix in case of port number starting with a letter. --- ChangeLog | 15 +++++++++++++++ grub-core/lib/posix_wrap/ctype.h | 3 +-- grub-core/term/serial.c | 2 +- grub-core/video/colors.c | 10 +--------- include/grub/misc.h | 6 ++++++ 5 files changed, 24 insertions(+), 12 deletions(-) diff --git a/ChangeLog b/ChangeLog index 19db47e04..44882054c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2011-10-14 Vladimir Serbinenko + + * grub-core/lib/posix_wrap/ctype.h (isxdigit): Use grub_isxdigit. + * include/grub/misc.h (grub_isxdigit): New function. + * grub-core/video/colors.c (my_isxdigit): Removed. All users + switched to grub_isxdigit. + * grub-core/term/serial.c (grub_serial_find): Fix in case of port + number starting with a letter. + 2011-10-09 Robert Millan LVM support for FreeBSD and GNU/kFreeBSD. @@ -63,6 +72,12 @@ (grub_get_unaligned64): Likewise. * util/import_gcry.py (cryptolist): Add adler32. +2011-10-05 Vladimir Serbinenko + + * grub-core/Makefile.core.def: Eliminate rarely used emu_condition. This + in perspective decreases the complexity of build system and fixes + compilation right now. + 2011-10-01 Ales Nesrsta * grub-core/bus/usb/uhci.c: Changes made by Rock Cui - thanks! diff --git a/grub-core/lib/posix_wrap/ctype.h b/grub-core/lib/posix_wrap/ctype.h index 2dc3e53e9..9589778b6 100644 --- a/grub-core/lib/posix_wrap/ctype.h +++ b/grub-core/lib/posix_wrap/ctype.h @@ -54,8 +54,7 @@ isupper (int c) static inline int isxdigit (int c) { - return (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F') - || (c >= '0' && c <= '9'); + return grub_isxdigit (c); } static inline int diff --git a/grub-core/term/serial.c b/grub-core/term/serial.c index b724a945a..306694192 100644 --- a/grub-core/term/serial.c +++ b/grub-core/term/serial.c @@ -136,7 +136,7 @@ grub_serial_find (char *name) #ifndef GRUB_MACHINE_EMU if (!port && grub_memcmp (name, "port", sizeof ("port") - 1) == 0 - && grub_isdigit (name [sizeof ("port") - 1])) + && grub_isxdigit (name [sizeof ("port") - 1])) { name = grub_serial_ns8250_add_port (grub_strtoul (&name[sizeof ("port") - 1], 0, 16)); diff --git a/grub-core/video/colors.c b/grub-core/video/colors.c index 3119c0249..06625183e 100644 --- a/grub-core/video/colors.c +++ b/grub-core/video/colors.c @@ -211,14 +211,6 @@ grub_video_get_named_color (const char *name, return 0; } -static __inline int -my_isxdigit (char c) -{ - return ((c >= '0' && c <= '9') - || (c >= 'a' && c <= 'f') - || (c >= 'A' && c <= 'F')); -} - static int parse_hex_color_component (const char *s, unsigned start, unsigned end) { @@ -267,7 +259,7 @@ grub_video_parse_color (const char *s, grub_video_rgba_color_t *color) /* Count the hexits to determine the format. */ int hexits = 0; const char *end = s; - while (my_isxdigit (*end)) + while (grub_isxdigit (*end)) { end++; hexits++; diff --git a/include/grub/misc.h b/include/grub/misc.h index da4bd4a7e..66e74d8a8 100644 --- a/include/grub/misc.h +++ b/include/grub/misc.h @@ -136,6 +136,12 @@ grub_isdigit (int c) return (c >= '0' && c <= '9'); } +static inline int +grub_isxdigit (int c) +{ + return (c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F'); +} + static inline int grub_isalnum (int c) { From c81296b65fad1d9bb4e5e2bb433719e5644827f0 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 14 Oct 2011 19:20:44 +0200 Subject: [PATCH 823/869] * grub-core/kern/emu/hostdisk.c (convert_system_partition_to_system_disk): Don't assume that children of mapper nodes are mapper nodes. --- ChangeLog | 6 ++++++ grub-core/kern/emu/hostdisk.c | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 44882054c..3be8005a7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2011-10-14 Vladimir Serbinenko + + * grub-core/kern/emu/hostdisk.c + (convert_system_partition_to_system_disk): Don't assume that children + of mapper nodes are mapper nodes. + 2011-10-14 Vladimir Serbinenko * grub-core/lib/posix_wrap/ctype.h (isxdigit): Use grub_isxdigit. diff --git a/grub-core/kern/emu/hostdisk.c b/grub-core/kern/emu/hostdisk.c index a9a8c066e..23417a64d 100644 --- a/grub-core/kern/emu/hostdisk.c +++ b/grub-core/kern/emu/hostdisk.c @@ -1416,7 +1416,7 @@ convert_system_partition_to_system_disk (const char *os_dev, struct stat *st) if (tree) dm_tree_free (tree); free (path); - char *ret = grub_find_device ("/dev/mapper", + char *ret = grub_find_device ("/dev", (major << 8) | minor); return ret; } From d891955241a5976694738b63c752bb9e35d248a5 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 14 Oct 2011 22:41:21 +0200 Subject: [PATCH 824/869] Fix overflow with >2GiB file on HFS+. >4GiB wasn't tested. * grub-core/fs/hfsplus.c (grub_hfsplus_btree): Use more appropriate types. (grub_hfsplus_btree_recoffset): Likewise. (grub_hfsplus_btree_recptr): Likewise. (grub_hfsplus_find_block): Likewise. (grub_hfsplus_btree_search): Likewise. (grub_hfsplus_read_block): Likewise. (grub_hfsplus_read_file): Likewise. (grub_hfsplus_mount): Likewise. (grub_hfsplus_btree_iterate_node): Likewise. (grub_hfsplus_btree_search): Likewise. (grub_hfsplus_iterate_dir): Likewise. (grub_hfsplus_read): A small code simplification. --- ChangeLog | 18 +++++++++++++++ grub-core/fs/hfsplus.c | 52 ++++++++++++++++++++---------------------- 2 files changed, 43 insertions(+), 27 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3be8005a7..9a8b38fd0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,21 @@ +2011-10-14 Vladimir Serbinenko + + Fix overflow with >2GiB file on HFS+. >4GiB wasn't tested. + + * grub-core/fs/hfsplus.c (grub_hfsplus_btree): Use more appropriate + types. + (grub_hfsplus_btree_recoffset): Likewise. + (grub_hfsplus_btree_recptr): Likewise. + (grub_hfsplus_find_block): Likewise. + (grub_hfsplus_btree_search): Likewise. + (grub_hfsplus_read_block): Likewise. + (grub_hfsplus_read_file): Likewise. + (grub_hfsplus_mount): Likewise. + (grub_hfsplus_btree_iterate_node): Likewise. + (grub_hfsplus_btree_search): Likewise. + (grub_hfsplus_iterate_dir): Likewise. + (grub_hfsplus_read): A small code simplification. + 2011-10-14 Vladimir Serbinenko * grub-core/kern/emu/hostdisk.c diff --git a/grub-core/fs/hfsplus.c b/grub-core/fs/hfsplus.c index 304b32126..245cd93a5 100644 --- a/grub-core/fs/hfsplus.c +++ b/grub-core/fs/hfsplus.c @@ -214,7 +214,7 @@ struct grub_fshelp_node struct grub_hfsplus_btree { grub_uint32_t root; - int nodesize; + grub_size_t nodesize; /* Catalog file node. */ struct grub_fshelp_node file; @@ -236,7 +236,7 @@ struct grub_hfsplus_data /* This is the offset into the physical disk for an embedded HFS+ filesystem (one inside a plain HFS wrapper). */ - int embedded_offset; + grub_disk_addr_t embedded_offset; int case_sensitive; }; @@ -245,7 +245,7 @@ static grub_dl_t my_mod; /* Return the offset of the record with the index INDEX, in the node NODE which is part of the B+ tree BTREE. */ -static inline unsigned int +static inline grub_off_t grub_hfsplus_btree_recoffset (struct grub_hfsplus_btree *btree, struct grub_hfsplus_btnode *node, int index) { @@ -263,7 +263,7 @@ grub_hfsplus_btree_recptr (struct grub_hfsplus_btree *btree, struct grub_hfsplus_btnode *node, int index) { char *cnode = (char *) node; - unsigned int offset; + grub_off_t offset; offset = grub_hfsplus_btree_recoffset (btree, node, index); return (struct grub_hfsplus_key *) &cnode[offset]; } @@ -272,12 +272,12 @@ grub_hfsplus_btree_recptr (struct grub_hfsplus_btree *btree, /* Find the extent that points to FILEBLOCK. If it is not in one of the 8 extents described by EXTENT, return -1. In that case set FILEBLOCK to the next block. */ -static int +static grub_disk_addr_t grub_hfsplus_find_block (struct grub_hfsplus_extent *extent, - int *fileblock) + grub_disk_addr_t *fileblock) { int i; - grub_size_t blksleft = *fileblock; + grub_disk_addr_t blksleft = *fileblock; /* First lookup the file in the given extents. */ for (i = 0; i < 8; i++) @@ -288,7 +288,7 @@ grub_hfsplus_find_block (struct grub_hfsplus_extent *extent, } *fileblock = blksleft; - return -1; + return 0xffffffffffffffffULL; } static grub_err_t @@ -296,7 +296,8 @@ grub_hfsplus_btree_search (struct grub_hfsplus_btree *btree, struct grub_hfsplus_key_internal *key, int (*compare_keys) (struct grub_hfsplus_key *keya, struct grub_hfsplus_key_internal *keyb), - struct grub_hfsplus_btnode **matchnode, int *keyoffset); + struct grub_hfsplus_btnode **matchnode, + grub_off_t *keyoffset); static int grub_hfsplus_cmp_extkey (struct grub_hfsplus_key *keya, struct grub_hfsplus_key_internal *keyb); @@ -307,15 +308,15 @@ static grub_disk_addr_t grub_hfsplus_read_block (grub_fshelp_node_t node, grub_disk_addr_t fileblock) { struct grub_hfsplus_btnode *nnode = 0; - int blksleft = fileblock; + grub_disk_addr_t blksleft = fileblock; struct grub_hfsplus_extent *extents = &node->extents[0]; while (1) { struct grub_hfsplus_extkey *key; struct grub_hfsplus_extkey_internal extoverflow; - int blk; - int ptr; + grub_disk_addr_t blk; + grub_off_t ptr; /* Try to find this block in the current set of extents. */ blk = grub_hfsplus_find_block (extents, &blksleft); @@ -325,7 +326,7 @@ grub_hfsplus_read_block (grub_fshelp_node_t node, grub_disk_addr_t fileblock) grub_free (nnode); nnode = 0; - if (blk != -1) + if (blk != 0xffffffffffffffffULL) return (blk + (node->data->embedded_offset >> (node->data->log2blksize - GRUB_DISK_SECTOR_BITS))); @@ -376,7 +377,7 @@ static grub_ssize_t grub_hfsplus_read_file (grub_fshelp_node_t node, void NESTED_FUNC_ATTR (*read_hook) (grub_disk_addr_t sector, unsigned offset, unsigned length), - int pos, grub_size_t len, char *buf) + grub_off_t pos, grub_size_t len, char *buf) { return grub_fshelp_read_file (node->data->disk, node, read_hook, pos, len, buf, grub_hfsplus_read_block, @@ -411,9 +412,9 @@ grub_hfsplus_mount (grub_disk_t disk) data->embedded_offset = 0; if (grub_be_to_cpu16 (volheader.hfs.magic) == GRUB_HFS_MAGIC) { - int extent_start; - int ablk_size; - int ablk_start; + grub_disk_addr_t extent_start; + grub_disk_addr_t ablk_size; + grub_disk_addr_t ablk_start; /* See if there's an embedded HFS+ filesystem. */ if (grub_be_to_cpu16 (volheader.hfs.embed_sig) != GRUB_HFSPLUS_MAGIC) @@ -601,10 +602,10 @@ grub_hfsplus_read_symlink (grub_fshelp_node_t node) static int grub_hfsplus_btree_iterate_node (struct grub_hfsplus_btree *btree, struct grub_hfsplus_btnode *first_node, - int first_rec, + grub_disk_addr_t first_rec, int (*hook) (void *record)) { - int rec; + grub_disk_addr_t rec; for (;;) { @@ -642,12 +643,13 @@ grub_hfsplus_btree_search (struct grub_hfsplus_btree *btree, struct grub_hfsplus_key_internal *key, int (*compare_keys) (struct grub_hfsplus_key *keya, struct grub_hfsplus_key_internal *keyb), - struct grub_hfsplus_btnode **matchnode, int *keyoffset) + struct grub_hfsplus_btnode **matchnode, + grub_off_t *keyoffset) { grub_uint64_t currnode; char *node; struct grub_hfsplus_btnode *nodedesc; - int rec; + grub_disk_addr_t rec; node = grub_malloc (btree->nodesize); if (! node) @@ -825,7 +827,7 @@ grub_hfsplus_iterate_dir (grub_fshelp_node_t dir, struct grub_hfsplus_key_internal intern; struct grub_hfsplus_btnode *node; - int ptr; + grub_disk_addr_t ptr; /* Create a key that points to the first entry in the directory. */ intern.catkey.parent = dir->fileid; @@ -894,7 +896,6 @@ grub_hfsplus_close (grub_file_t file) return GRUB_ERR_NONE; } - /* Read LEN bytes data from FILE into BUF. */ static grub_ssize_t grub_hfsplus_read (grub_file_t file, char *buf, grub_size_t len) @@ -902,13 +903,10 @@ grub_hfsplus_read (grub_file_t file, char *buf, grub_size_t len) struct grub_hfsplus_data *data = (struct grub_hfsplus_data *) file->data; - int size = grub_hfsplus_read_file (&data->opened_file, file->read_hook, + return grub_hfsplus_read_file (&data->opened_file, file->read_hook, file->offset, len, buf); - - return size; } - static grub_err_t grub_hfsplus_dir (grub_device_t device, const char *path, int (*hook) (const char *filename, From 0017e5ef84cb4c7ac135254a52256d700e1c7dcb Mon Sep 17 00:00:00 2001 From: Robert Millan Date: Sat, 15 Oct 2011 13:33:41 +0200 Subject: [PATCH 825/869] 2011-10-15 Robert Millan Fix build problem on FreeBSD and GNU/kFreeBSD. * util/getroot.c [__FreeBSD_kernel__]: Include `'. --- ChangeLog | 6 ++++++ util/getroot.c | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/ChangeLog b/ChangeLog index 9a8b38fd0..723531f5c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2011-10-15 Robert Millan + + Fix build problem on FreeBSD and GNU/kFreeBSD. + + * util/getroot.c [__FreeBSD_kernel__]: Include `'. + 2011-10-14 Vladimir Serbinenko Fix overflow with >2GiB file on HFS+. >4GiB wasn't tested. diff --git a/util/getroot.c b/util/getroot.c index 7c5602e71..510049acb 100644 --- a/util/getroot.c +++ b/util/getroot.c @@ -52,6 +52,10 @@ # include #endif +#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) +# include +#endif + #if defined(HAVE_LIBZFS) && defined(HAVE_LIBNVPAIR) # include # include From 8bcebcb8e4cb75b0b6deffeb735c9fe26eb437b1 Mon Sep 17 00:00:00 2001 From: Robert Millan Date: Sat, 15 Oct 2011 18:37:55 +0200 Subject: [PATCH 826/869] 2011-10-15 Robert Millan * util/getroot.c (grub_util_get_grub_dev): Fix OS selection #ifdefs. --- ChangeLog | 4 ++++ util/getroot.c | 6 ++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 723531f5c..11b14ec28 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2011-10-15 Robert Millan + + * util/getroot.c (grub_util_get_grub_dev): Fix OS selection #ifdefs. + 2011-10-15 Robert Millan Fix build problem on FreeBSD and GNU/kFreeBSD. diff --git a/util/getroot.c b/util/getroot.c index 510049acb..3d6f9370c 100644 --- a/util/getroot.c +++ b/util/getroot.c @@ -1137,7 +1137,9 @@ grub_util_get_grub_dev (const char *os_dev) } break; +#endif +#ifdef __linux__ case GRUB_DEV_ABSTRACTION_LUKS: { char *uuid, *dash; @@ -1152,9 +1154,10 @@ grub_util_get_grub_dev (const char *os_dev) grub_free (uuid); } break; +#endif - case GRUB_DEV_ABSTRACTION_GELI: #if defined (__FreeBSD__) || defined(__FreeBSD_kernel__) + case GRUB_DEV_ABSTRACTION_GELI: { char *whole; struct gmesh mesh; @@ -1201,7 +1204,6 @@ grub_util_get_grub_dev (const char *os_dev) } } } -#endif break; #endif From 3b619ae116833fa8624d72f4c83b9c8f266ab5a5 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 16 Oct 2011 11:48:54 +0200 Subject: [PATCH 827/869] * grub-core/fs/xfs.c (grub_xfs_inode): New field fork_offset. (GRUB_XFS_INO_AGBITS): Make into inline function. (GRUB_XFS_INO_INOINAG): Likewise. (GRUB_XFS_INO_AG): Likewise. (GRUB_XFS_FSB_TO_BLOCK): Likewise. (GRUB_XFS_EXTENT_OFFSET): Likewise. (GRUB_XFS_EXTENT_BLOCK): Likewise. (GRUB_XFS_EXTENT_SIZE): Likewise. (GRUB_XFS_ROUND_TO_DIRENT): Likewise. (GRUB_XFS_NEXT_DIRENT): Likewise. (grub_xfs_read_block): Rewrite the btree parsing. Fixes invalid BMAP. (grub_xfs_read_file): Fix offset type. --- ChangeLog | 15 ++++++ grub-core/fs/xfs.c | 111 ++++++++++++++++++++++++++++++++------------- 2 files changed, 94 insertions(+), 32 deletions(-) diff --git a/ChangeLog b/ChangeLog index 11b14ec28..abe19dc78 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +2011-10-16 Vladimir Serbinenko + + * grub-core/fs/xfs.c (grub_xfs_inode): New field fork_offset. + (GRUB_XFS_INO_AGBITS): Make into inline function. + (GRUB_XFS_INO_INOINAG): Likewise. + (GRUB_XFS_INO_AG): Likewise. + (GRUB_XFS_FSB_TO_BLOCK): Likewise. + (GRUB_XFS_EXTENT_OFFSET): Likewise. + (GRUB_XFS_EXTENT_BLOCK): Likewise. + (GRUB_XFS_EXTENT_SIZE): Likewise. + (GRUB_XFS_ROUND_TO_DIRENT): Likewise. + (GRUB_XFS_NEXT_DIRENT): Likewise. + (grub_xfs_read_block): Rewrite the btree parsing. Fixes invalid BMAP. + (grub_xfs_read_file): Fix offset type. + 2011-10-15 Robert Millan * util/getroot.c (grub_util_get_grub_dev): Fix OS selection #ifdefs. diff --git a/grub-core/fs/xfs.c b/grub-core/fs/xfs.c index eb0783407..3dc5e0af0 100644 --- a/grub-core/fs/xfs.c +++ b/grub-core/fs/xfs.c @@ -120,7 +120,9 @@ struct grub_xfs_inode grub_uint64_t nblocks; grub_uint32_t extsize; grub_uint32_t nextents; - grub_uint8_t unused3[20]; + grub_uint16_t unused3; + grub_uint8_t fork_offset; + grub_uint8_t unused4[17]; union { char raw[156]; @@ -154,7 +156,7 @@ struct grub_xfs_data grub_disk_t disk; int pos; int bsize; - int agsize; + grub_uint32_t agsize; struct grub_fshelp_node diropen; }; @@ -168,33 +170,67 @@ static grub_dl_t my_mod; #define FILETYPE_INO_DIRECTORY 0040000 #define FILETYPE_INO_SYMLINK 0120000 -#define GRUB_XFS_INO_AGBITS(data) \ - ((data)->sblock.log2_agblk + (data)->sblock.log2_inop) -#define GRUB_XFS_INO_INOINAG(data, ino) \ - (grub_be_to_cpu64 (ino) & ((1LL << GRUB_XFS_INO_AGBITS (data)) - 1)) -#define GRUB_XFS_INO_AG(data,ino) \ - (grub_be_to_cpu64 (ino) >> GRUB_XFS_INO_AGBITS (data)) +static inline int +GRUB_XFS_INO_AGBITS(struct grub_xfs_data *data) +{ + return ((data)->sblock.log2_agblk + (data)->sblock.log2_inop); +} -#define GRUB_XFS_FSB_TO_BLOCK(data, fsb) \ - (((fsb) >> (data)->sblock.log2_agblk) * (data)->agsize \ - + ((fsb) & ((1LL << (data)->sblock.log2_agblk) - 1))) +static inline grub_uint64_t +GRUB_XFS_INO_INOINAG (struct grub_xfs_data *data, + grub_uint64_t ino) +{ + return (grub_be_to_cpu64 (ino) & ((1LL << GRUB_XFS_INO_AGBITS (data)) - 1)); +} -#define GRUB_XFS_EXTENT_OFFSET(exts,ex) \ - ((grub_be_to_cpu32 (exts[ex][0]) & ~(1 << 31)) << 23 \ - | grub_be_to_cpu32 (exts[ex][1]) >> 9) +static inline grub_uint64_t +GRUB_XFS_INO_AG (struct grub_xfs_data *data, + grub_uint64_t ino) +{ + return (grub_be_to_cpu64 (ino) >> GRUB_XFS_INO_AGBITS (data)); +} -#define GRUB_XFS_EXTENT_BLOCK(exts,ex) \ - ((grub_uint64_t) (grub_be_to_cpu32 (exts[ex][1]) \ - & (0x1ff)) << 43 \ - | (grub_uint64_t) grub_be_to_cpu32 (exts[ex][2]) << 11 \ - | grub_be_to_cpu32 (exts[ex][3]) >> 21) +static inline grub_disk_addr_t +GRUB_XFS_FSB_TO_BLOCK (struct grub_xfs_data *data, grub_disk_addr_t fsb) +{ + return ((fsb >> data->sblock.log2_agblk) * data->agsize + + (fsb & ((1LL << data->sblock.log2_agblk) - 1))); +} -#define GRUB_XFS_EXTENT_SIZE(exts,ex) \ - (grub_be_to_cpu32 (exts[ex][3]) & ((1 << 20) - 1)) +static inline grub_uint64_t +GRUB_XFS_EXTENT_OFFSET (grub_xfs_extent *exts, int ex) +{ + return ((grub_be_to_cpu32 (exts[ex][0]) & ~(1 << 31)) << 23 + | grub_be_to_cpu32 (exts[ex][1]) >> 9); +} + +static inline grub_uint64_t +GRUB_XFS_EXTENT_BLOCK (grub_xfs_extent *exts, int ex) +{ + return ((grub_uint64_t) (grub_be_to_cpu32 (exts[ex][1]) + & (0x1ff)) << 43 + | (grub_uint64_t) grub_be_to_cpu32 (exts[ex][2]) << 11 + | grub_be_to_cpu32 (exts[ex][3]) >> 21); +} + +static inline grub_uint64_t +GRUB_XFS_EXTENT_SIZE (grub_xfs_extent *exts, int ex) +{ + return (grub_be_to_cpu32 (exts[ex][3]) & ((1 << 20) - 1)); +} + +static inline int +GRUB_XFS_ROUND_TO_DIRENT (int pos) +{ + return ((((pos) + 8 - 1) / 8) * 8); +} + +static inline int +GRUB_XFS_NEXT_DIRENT (int pos, int len) +{ + return (pos) + GRUB_XFS_ROUND_TO_DIRENT (8 + 1 + len + 2); +} -#define GRUB_XFS_ROUND_TO_DIRENT(pos) ((((pos) + 8 - 1) / 8) * 8) -#define GRUB_XFS_NEXT_DIRENT(pos,len) \ - (pos) + GRUB_XFS_ROUND_TO_DIRENT (8 + 1 + len + 2) static inline grub_uint64_t grub_xfs_inode_block (struct grub_xfs_data *data, @@ -250,13 +286,23 @@ grub_xfs_read_block (grub_fshelp_node_t node, grub_disk_addr_t fileblock) if (node->inode.format == XFS_INODE_FORMAT_BTREE) { grub_uint64_t *keys; + int recoffset; - leaf = grub_malloc (node->data->sblock.bsize); + leaf = grub_malloc (node->data->bsize); if (leaf == 0) return 0; nrec = grub_be_to_cpu16 (node->inode.data.btree.numrecs); keys = &node->inode.data.btree.keys[0]; + if (node->inode.fork_offset) + recoffset = (node->inode.fork_offset + - ((char *) &node->inode.data.btree.keys - (char *) &node->inode)) + / (2 * sizeof (grub_uint64_t)); + else + recoffset = ((1 << node->data->sblock.log2_inode) + - ((char *) &node->inode.data.btree.keys + - (char *) &node->inode)) + / (2 * sizeof (grub_uint64_t)); do { int i; @@ -273,12 +319,9 @@ grub_xfs_read_block (grub_fshelp_node_t node, grub_disk_addr_t fileblock) grub_free (leaf); return 0; } - if (grub_disk_read (node->data->disk, - grub_be_to_cpu64 (keys[i - 1 + nrec]) - << (node->data->sblock.log2_bsize - - GRUB_DISK_SECTOR_BITS), - 0, node->data->sblock.bsize, leaf)) + GRUB_XFS_FSB_TO_BLOCK (node->data, grub_be_to_cpu64 (keys[i - 1 + recoffset])) << (node->data->sblock.log2_bsize - GRUB_DISK_SECTOR_BITS), + 0, node->data->bsize, leaf)) return 0; if (grub_strncmp ((char *) leaf->magic, "BMAP", 4)) @@ -290,7 +333,11 @@ grub_xfs_read_block (grub_fshelp_node_t node, grub_disk_addr_t fileblock) nrec = grub_be_to_cpu16 (leaf->numrecs); keys = &leaf->keys[0]; - } while (leaf->level); + recoffset = ((node->data->bsize - ((char *) &leaf->keys + - (char *) leaf)) + / (2 * sizeof (grub_uint64_t))); + } + while (leaf->level); exts = (grub_xfs_extent *) keys; } else if (node->inode.format == XFS_INODE_FORMAT_EXT) @@ -336,7 +383,7 @@ static grub_ssize_t grub_xfs_read_file (grub_fshelp_node_t node, void NESTED_FUNC_ATTR (*read_hook) (grub_disk_addr_t sector, unsigned offset, unsigned length), - int pos, grub_size_t len, char *buf) + grub_off_t pos, grub_size_t len, char *buf) { return grub_fshelp_read_file (node->data->disk, node, read_hook, pos, len, buf, grub_xfs_read_block, From 177b960ea44f146bb6b9e3c7be87bd3669b0d823 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 16 Oct 2011 11:53:27 +0200 Subject: [PATCH 828/869] Fix python 3.x incompatibilities. * gentpl.py: Put brackets around print strings. * util/import_gcry.py: Open explicitly as utf-8. Use in instead of has_key. --- ChangeLog | 8 ++++++++ gentpl.py | 40 ++++++++++++++++++++-------------------- util/import_gcry.py | 28 +++++++++++++++------------- 3 files changed, 43 insertions(+), 33 deletions(-) diff --git a/ChangeLog b/ChangeLog index abe19dc78..d5fbffcd4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2011-10-16 Vladimir Serbinenko + + Fix python 3.x incompatibilities. + + * gentpl.py: Put brackets around print strings. + * util/import_gcry.py: Open explicitly as utf-8. + Use in instead of has_key. + 2011-10-16 Vladimir Serbinenko * grub-core/fs/xfs.c (grub_xfs_inode): New field fork_offset. diff --git a/gentpl.py b/gentpl.py index cb6b663d9..af210a040 100644 --- a/gentpl.py +++ b/gentpl.py @@ -568,28 +568,28 @@ f = script_rules() g = data_rules() z = global_variable_initializers() -print "[+ AutoGen5 template +]\n" +print ("[+ AutoGen5 template +]\n") for p in GRUB_PLATFORMS: - print define_macro_for_platform_sources(p) - print define_macro_for_platform_nodist_sources(p) + print (define_macro_for_platform_sources(p)) + print (define_macro_for_platform_nodist_sources(p)) # print define_macro_for_platform_dependencies(p) - print define_macro_for_platform_startup(p) - print define_macro_for_platform_cflags(p) - print define_macro_for_platform_ldadd(p) - print define_macro_for_platform_ldflags(p) - print define_macro_for_platform_cppflags(p) - print define_macro_for_platform_ccasflags(p) - print define_macro_for_platform_stripflags(p) - print define_macro_for_platform_objcopyflags(p) + print (define_macro_for_platform_startup(p)) + print (define_macro_for_platform_cflags(p)) + print (define_macro_for_platform_ldadd(p)) + print (define_macro_for_platform_ldflags(p)) + print (define_macro_for_platform_cppflags(p)) + print (define_macro_for_platform_ccasflags(p)) + print (define_macro_for_platform_stripflags(p)) + print (define_macro_for_platform_objcopyflags(p)) - print define_macro_for_platform_conditionals_if_statement(p) - print define_macro_for_platform_conditionals_endif_statement(p) + print (define_macro_for_platform_conditionals_if_statement(p)) + print (define_macro_for_platform_conditionals_endif_statement(p)) # print z # initializer for all vars -print a -print b -print c -print d -print e -print f -print g +print (a) +print (b) +print (c) +print (d) +print (e) +print (f) +print (g) diff --git a/util/import_gcry.py b/util/import_gcry.py index ee75b1b8e..720f19303 100644 --- a/util/import_gcry.py +++ b/util/import_gcry.py @@ -20,6 +20,7 @@ import re import sys import os import datetime +import codecs if len (sys.argv) < 3: print ("Usage: %s SOURCE DESTINATION" % sys.argv[0]) @@ -40,9 +41,9 @@ except: print ("WARNING: %s already exists" % cipher_dir_out) cipher_files = os.listdir (cipher_dir_in) -conf = open (os.path.join ("grub-core", "Makefile.gcry.def"), "w") +conf = codecs.open (os.path.join ("grub-core", "Makefile.gcry.def"), "w", "utf-8") conf.write ("AutoGen definitions Makefile.tpl;\n\n") -confutil = open ("Makefile.utilgcry.def", "w") +confutil = codecs.open ("Makefile.utilgcry.def", "w", "utf-8") confutil.write ("AutoGen definitions Makefile.tpl;\n\n") confutil.write ("library = {\n"); confutil.write (" name = libgrubgcry.a;\n"); @@ -69,7 +70,7 @@ mdblocksizes = {"_gcry_digest_spec_crc32" : 64, "_gcry_digest_spec_tiger" : 64, "_gcry_digest_spec_whirlpool" : 64} -cryptolist = open (os.path.join (cipher_dir_out, "crypto.lst"), "w") +cryptolist = codecs.open (os.path.join (cipher_dir_out, "crypto.lst"), "w", "utf-8") # rijndael is the only cipher using aliases. So no need for mangling, just # hardcode it @@ -98,8 +99,8 @@ for cipher_file in cipher_files: nch = False if re.match (".*\.[ch]$", cipher_file): isc = re.match (".*\.c$", cipher_file) - f = open (infile, "r") - fw = open (outfile, "w") + f = codecs.open (infile, "r", "utf-8") + fw = codecs.open (outfile, "w", "utf-8") fw.write ("/* This file was automatically imported with \n") fw.write (" import_gcry.py. Please don't modify it */\n") fw.write ("#include \n") @@ -125,6 +126,7 @@ for cipher_file in cipher_files: isglue = True modname = "gcry_%s" % modname for line in f: + line = line if skip_statement: if not re.search (";", line) is None: skip_statement = False @@ -151,7 +153,7 @@ for cipher_file in cipher_files: fw.write (" .modname = \"%s\",\n" % modname); fw.write ("#endif\n"); if ismd: - if not mdblocksizes.has_key (mdname): + if not (mdname in mdblocksizes): print ("ERROR: Unknown digest blocksize: %s\n" % mdname) exit (1) @@ -324,28 +326,28 @@ cryptolist.close () chlog = "%s * crypto.lst: New file.\n" % chlog outfile = os.path.join (cipher_dir_out, "types.h") -fw=open (outfile, "w") +fw=codecs.open (outfile, "w", "utf-8") fw.write ("#include \n") fw.write ("#include \n") chlog = "%s * types.h: New file.\n" % chlog fw.close () outfile = os.path.join (cipher_dir_out, "memory.h") -fw=open (outfile, "w") +fw=codecs.open (outfile, "w", "utf-8") fw.write ("#include \n") chlog = "%s * memory.h: New file.\n" % chlog fw.close () outfile = os.path.join (cipher_dir_out, "cipher.h") -fw=open (outfile, "w") +fw=codecs.open (outfile, "w", "utf-8") fw.write ("#include \n") fw.write ("#include \n") chlog = "%s * cipher.h: Likewise.\n" % chlog fw.close () outfile = os.path.join (cipher_dir_out, "g10lib.h") -fw=open (outfile, "w") +fw=codecs.open (outfile, "w", "utf-8") fw.write ("#include \n") chlog = "%s * g10lib.h: Likewise.\n" % chlog fw.close () @@ -355,7 +357,7 @@ outfile = os.path.join (cipher_dir_out, "ChangeLog") conf.close (); -initfile = open (os.path.join (cipher_dir_out, "init.c"), "w") +initfile = codecs.open (os.path.join (cipher_dir_out, "init.c"), "w", "utf-8") for module in modules: initfile.write ("extern void grub_%s_init (void);\n" % module) initfile.write ("extern void grub_%s_fini (void);\n" % module) @@ -380,8 +382,8 @@ confutil.write ("};\n"); confutil.close (); -f=open (infile, "r") -fw=open (outfile, "w") +f=codecs.open (infile, "r", "utf-8") +fw=codecs.open (outfile, "w", "utf-8") dt = datetime.date.today () fw.write ("%04d-%02d-%02d Automatic import tool\n" % \ (dt.year,dt.month, dt.day)) From 366e34fa5a49d022f3f01861c7d6ee6d7268a8a1 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 16 Oct 2011 11:57:48 +0200 Subject: [PATCH 829/869] Fix few obvious type discrepancies. * grub-core/fs/affs.c (grub_affs_read_file): Use grub_off_t for offset. * grub-core/fs/afs.c (grub_afs_read_file): Likewise. * grub-core/fs/fshelp.c (grub_fshelp_find_file): Remove leftover variable. * grub-core/fs/hfs.c (grub_hfs_read_file): Use grub_off_t for offset and connected types. * grub-core/fs/nilfs2.c (grub_nilfs2_read_file): Use grub_off_t for offset. (grub_nilfs2_iterate_dir): Use grub_off_t for fpos. * grub-core/fs/sfs.c (grub_sfs_read_file): Use grub_off_t for offset. * grub-core/fs/ufs.c (grub_ufs_read_file): Use grub_off_t for offset and connected types. --- ChangeLog | 17 +++++++++++++++++ grub-core/fs/affs.c | 2 +- grub-core/fs/afs.c | 2 +- grub-core/fs/fshelp.c | 1 - grub-core/fs/hfs.c | 24 +++++++++++++----------- grub-core/fs/nilfs2.c | 4 ++-- grub-core/fs/sfs.c | 2 +- grub-core/fs/ufs.c | 23 +++++++++++++---------- 8 files changed, 48 insertions(+), 27 deletions(-) diff --git a/ChangeLog b/ChangeLog index d5fbffcd4..2e44b4c26 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,20 @@ +2011-10-16 Vladimir Serbinenko + + Fix few obvious type discrepancies. + + * grub-core/fs/affs.c (grub_affs_read_file): Use grub_off_t for offset. + * grub-core/fs/afs.c (grub_afs_read_file): Likewise. + * grub-core/fs/fshelp.c (grub_fshelp_find_file): Remove leftover + variable. + * grub-core/fs/hfs.c (grub_hfs_read_file): Use grub_off_t for offset + and connected types. + * grub-core/fs/nilfs2.c (grub_nilfs2_read_file): Use grub_off_t for + offset. + (grub_nilfs2_iterate_dir): Use grub_off_t for fpos. + * grub-core/fs/sfs.c (grub_sfs_read_file): Use grub_off_t for offset. + * grub-core/fs/ufs.c (grub_ufs_read_file): Use grub_off_t for offset + and connected types. + 2011-10-16 Vladimir Serbinenko Fix python 3.x incompatibilities. diff --git a/grub-core/fs/affs.c b/grub-core/fs/affs.c index e17540e2f..adf2932bd 100644 --- a/grub-core/fs/affs.c +++ b/grub-core/fs/affs.c @@ -160,7 +160,7 @@ static grub_ssize_t grub_affs_read_file (grub_fshelp_node_t node, void NESTED_FUNC_ATTR (*read_hook) (grub_disk_addr_t sector, unsigned offset, unsigned length), - int pos, grub_size_t len, char *buf) + grub_off_t pos, grub_size_t len, char *buf) { return grub_fshelp_read_file (node->data->disk, node, read_hook, pos, len, buf, grub_affs_read_block, diff --git a/grub-core/fs/afs.c b/grub-core/fs/afs.c index 35ef49937..b64ebb52c 100644 --- a/grub-core/fs/afs.c +++ b/grub-core/fs/afs.c @@ -336,7 +336,7 @@ static grub_ssize_t grub_afs_read_file (grub_fshelp_node_t node, void NESTED_FUNC_ATTR (*read_hook) (grub_disk_addr_t sector, unsigned offset, unsigned length), - int pos, grub_size_t len, char *buf) + grub_off_t pos, grub_size_t len, char *buf) { return grub_fshelp_read_file (node->data->disk, node, read_hook, pos, len, buf, grub_afs_read_block, diff --git a/grub-core/fs/fshelp.c b/grub-core/fs/fshelp.c index 2ff78c423..275cb9e1b 100644 --- a/grub-core/fs/fshelp.c +++ b/grub-core/fs/fshelp.c @@ -61,7 +61,6 @@ grub_fshelp_find_file (const char *path, grub_fshelp_node_t rootnode, char fpath[grub_strlen (currpath) + 1]; char *name = fpath; char *next; - // unsigned int pos = 0; enum grub_fshelp_filetype type = GRUB_FSHELP_DIR; grub_fshelp_node_t currnode = currroot; grub_fshelp_node_t oldnode = currroot; diff --git a/grub-core/fs/hfs.c b/grub-core/fs/hfs.c index 6f27c69c4..973a2d2ef 100644 --- a/grub-core/fs/hfs.c +++ b/grub-core/fs/hfs.c @@ -244,22 +244,24 @@ static grub_ssize_t grub_hfs_read_file (struct grub_hfs_data *data, void NESTED_FUNC_ATTR (*read_hook) (grub_disk_addr_t sector, unsigned offset, unsigned length), - int pos, grub_size_t len, char *buf) + grub_off_t pos, grub_size_t len, char *buf) { - int i; - int blockcnt; + grub_off_t i; + grub_off_t blockcnt; - blockcnt = ((len + pos) - + data->blksz - 1) / data->blksz; + blockcnt = grub_divmod64 (((len + pos) + + data->blksz - 1), data->blksz, 0); - for (i = pos / data->blksz; i < blockcnt; i++) + for (i = grub_divmod64 (pos, data->blksz, 0); i < blockcnt; i++) { - int blknr; - int blockoff = pos % data->blksz; - int blockend = data->blksz; + grub_disk_addr_t blknr; + grub_off_t blockoff; + grub_off_t blockend = data->blksz; int skipfirst = 0; + grub_divmod64 (pos, data->blksz, &blockoff); + blknr = grub_hfs_block (data, data->extents, data->fileid, i, 1); if (grub_errno) return -1; @@ -267,7 +269,7 @@ grub_hfs_read_file (struct grub_hfs_data *data, /* Last block. */ if (i == blockcnt - 1) { - blockend = (len + pos) % data->blksz; + grub_divmod64 ((len + pos), data->blksz, &blockend); /* The last portion is exactly EXT2_BLOCK_SIZE (data). */ if (! blockend) @@ -275,7 +277,7 @@ grub_hfs_read_file (struct grub_hfs_data *data, } /* First block. */ - if (i == pos / data->blksz) + if (i == grub_divmod64 (pos, data->blksz, 0)) { skipfirst = blockoff; blockend -= skipfirst; diff --git a/grub-core/fs/nilfs2.c b/grub-core/fs/nilfs2.c index 44fb213bd..62cf167c7 100644 --- a/grub-core/fs/nilfs2.c +++ b/grub-core/fs/nilfs2.c @@ -628,7 +628,7 @@ grub_nilfs2_read_file (grub_fshelp_node_t node, sector, unsigned offset, unsigned length), - int pos, grub_size_t len, char *buf) + grub_off_t pos, grub_size_t len, char *buf) { return grub_fshelp_read_file (node->data->disk, node, read_hook, pos, len, buf, grub_nilfs2_read_block, @@ -866,7 +866,7 @@ grub_nilfs2_iterate_dir (grub_fshelp_node_t dir, enum grub_fshelp_filetype filetype, grub_fshelp_node_t node)) { - unsigned int fpos = 0; + grub_off_t fpos = 0; struct grub_fshelp_node *diro = (struct grub_fshelp_node *) dir; if (!diro->inode_read) diff --git a/grub-core/fs/sfs.c b/grub-core/fs/sfs.c index 19ae90715..f1e09ccbd 100644 --- a/grub-core/fs/sfs.c +++ b/grub-core/fs/sfs.c @@ -250,7 +250,7 @@ static grub_ssize_t grub_sfs_read_file (grub_fshelp_node_t node, void NESTED_FUNC_ATTR (*read_hook) (grub_disk_addr_t sector, unsigned offset, unsigned length), - int pos, grub_size_t len, char *buf) + grub_off_t pos, grub_size_t len, char *buf) { return grub_fshelp_read_file (node->data->disk, node, read_hook, pos, len, buf, grub_sfs_read_block, diff --git a/grub-core/fs/ufs.c b/grub-core/fs/ufs.c index 0f4ea0019..435fec6a5 100644 --- a/grub-core/fs/ufs.c +++ b/grub-core/fs/ufs.c @@ -285,26 +285,29 @@ static grub_ssize_t grub_ufs_read_file (struct grub_ufs_data *data, void NESTED_FUNC_ATTR (*read_hook) (grub_disk_addr_t sector, unsigned offset, unsigned length), - int pos, grub_size_t len, char *buf) + grub_off_t pos, grub_size_t len, char *buf) { struct grub_ufs_sblock *sblock = &data->sblock; - int i; - int blockcnt; + grub_off_t i; + grub_off_t blockcnt; /* Adjust len so it we can't read past the end of the file. */ if (len + pos > INODE_SIZE (data)) len = INODE_SIZE (data) - pos; - blockcnt = (len + pos + UFS_BLKSZ (sblock) - 1) / UFS_BLKSZ (sblock); + blockcnt = grub_divmod64 ((len + pos + UFS_BLKSZ (sblock) - 1), + UFS_BLKSZ (sblock), 0); - for (i = pos / UFS_BLKSZ (sblock); i < blockcnt; i++) + for (i = grub_divmod64 (pos, UFS_BLKSZ (sblock), 0); i < blockcnt; i++) { - int blknr; - int blockoff = pos % UFS_BLKSZ (sblock); - int blockend = UFS_BLKSZ (sblock); + grub_disk_addr_t blknr; + grub_off_t blockoff; + grub_off_t blockend = UFS_BLKSZ (sblock); int skipfirst = 0; + grub_divmod64 (pos, UFS_BLKSZ (sblock), &blockoff); + blknr = grub_ufs_get_file_block (data, i); if (grub_errno) return -1; @@ -312,14 +315,14 @@ grub_ufs_read_file (struct grub_ufs_data *data, /* Last block. */ if (i == blockcnt - 1) { - blockend = (len + pos) % UFS_BLKSZ (sblock); + grub_divmod64 (len + pos, UFS_BLKSZ (sblock), &blockend); if (!blockend) blockend = UFS_BLKSZ (sblock); } /* First block. */ - if (i == (pos / (int) UFS_BLKSZ (sblock))) + if (i == grub_divmod64 (pos, UFS_BLKSZ (sblock), 0)) { skipfirst = blockoff; blockend -= skipfirst; From 2afb7f6cbf5ca5c49750c70b07f67d4733f66061 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 16 Oct 2011 15:15:35 +0200 Subject: [PATCH 830/869] * configure.ac: Check for __ctzdi2 and __ctzsi2. * include/grub/libgcc.h: Include __ctzdi2 and __ctzsi2 if present. --- ChangeLog | 5 +++++ configure.ac | 2 +- include/grub/libgcc.h | 6 ++++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 2e44b4c26..0592459c3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-10-16 Vladimir Serbinenko + + * configure.ac: Check for __ctzdi2 and __ctzsi2. + * include/grub/libgcc.h: Include __ctzdi2 and __ctzsi2 if present. + 2011-10-16 Vladimir Serbinenko Fix few obvious type discrepancies. diff --git a/configure.ac b/configure.ac index 9cfbd2340..6aafdf13d 100644 --- a/configure.ac +++ b/configure.ac @@ -587,7 +587,7 @@ CFLAGS="$CFLAGS -Wl,--defsym,abort=main" fi # Check for libgcc symbols -AC_CHECK_FUNCS(__bswapsi2 __bswapdi2 __ashldi3 __ashrdi3 __lshrdi3 __trampoline_setup __ucmpdi2 _restgpr_14_x __ia64_trampoline __udivsi3 __umoddi3 __udivdi3 __divsi3 __modsi3 __umodsi3 __moddi3 __divdi3) +AC_CHECK_FUNCS(__bswapsi2 __bswapdi2 __ashldi3 __ashrdi3 __lshrdi3 __trampoline_setup __ucmpdi2 _restgpr_14_x __ia64_trampoline __udivsi3 __umoddi3 __udivdi3 __divsi3 __modsi3 __umodsi3 __moddi3 __divdi3 __ctzdi2 __ctzsi2) if test "x$TARGET_APPLE_CC" = x1 ; then CFLAGS="$TARGET_CFLAGS -nostdlib" diff --git a/include/grub/libgcc.h b/include/grub/libgcc.h index 19723fd23..7a433dc68 100644 --- a/include/grub/libgcc.h +++ b/include/grub/libgcc.h @@ -63,6 +63,12 @@ void EXPORT_FUNC (__divsi3) (void); # ifdef HAVE___MODSI3 void EXPORT_FUNC (__modsi3) (void); # endif +# ifdef HAVE___CTZDI2 +void EXPORT_FUNC (__ctzdi2) (void); +# endif +# ifdef HAVE___CTZSI2 +void EXPORT_FUNC (__ctzsi2) (void); +# endif #endif # ifdef HAVE___IA64_TRAMPOLINE From 39705fadd7ed2d4f78df6f48abc13150464a5698 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 16 Oct 2011 15:23:29 +0200 Subject: [PATCH 831/869] Replace grub_module_iterate with FOR_MODULES. * grub-core/disk/memdisk.c (GRUB_MOD_INIT): Switched to new interface. * grub-core/kern/efi/efi.c (grub_arch_modules_addr): Renamed to... (grub_efi_modules_addr): ...this. * grub-core/kern/efi/init.c (grub_modbase): New variable. (grub_efi_init): Set grub_modbase. * grub-core/kern/emu/main.c (grub_arch_modules_addr): Removed. (grub_modbase): New variable. * grub-core/kern/i386/coreboot/init.c (grub_arch_modules_addr): Removed. (grub_modbase): New variable. (grub_machine_init): Set grub_modbase. * grub-core/kern/i386/pc/init.c (grub_arch_modules_addr): Removed. (grub_modbase): New variable. (grub_machine_init): Set grub_modbase. * grub-core/kern/ieee1275/init.c (grub_arch_modules_addr): Removed. (grub_modbase): New variable. (grub_machine_init): Set grub_modbase. * grub-core/kern/main.c (grub_module_iterate): Remove. (grub_modules_get_end): Use grub_modbase. (grub_load_modules): Use FOR_MODULES. (grub_load_config): Likewise. * grub-core/kern/mips/arc/init.c (grub_arch_modules_addr): Removed. (grub_modbase): New variable. (grub_machine_init): Set grub_modbase. * grub-core/kern/mips/loongson/init.c (grub_arch_modules_addr): Removed. (grub_modbase): New variable. (grub_machine_init): Set grub_modbase. * grub-core/kern/mips/qemu_mips/init.c (grub_arch_modules_addr): Removed. (grub_modbase): New variable. (grub_machine_init): Set grub_modbase. * include/grub/efi/efi.h (grub_efi_modules_addr): New declaration. * include/grub/kernel.h (grub_arch_modules_addr): Removed. (grub_module_iterate): Likewise. (grub_modbase): New variable declaration. (FOR_MODULES): New macro. --- ChangeLog | 40 ++++++++++++++ grub-core/disk/memdisk.c | 34 +++++------- grub-core/kern/efi/efi.c | 2 +- grub-core/kern/efi/init.c | 3 + grub-core/kern/emu/main.c | 6 +- grub-core/kern/i386/coreboot/init.c | 19 +++---- grub-core/kern/i386/pc/init.c | 13 ++--- grub-core/kern/ieee1275/init.c | 11 ++-- grub-core/kern/main.c | 83 +++++++++------------------- grub-core/kern/mips/arc/init.c | 8 +-- grub-core/kern/mips/loongson/init.c | 6 +- grub-core/kern/mips/qemu_mips/init.c | 6 +- include/grub/efi/efi.h | 2 + include/grub/kernel.h | 10 +++- 14 files changed, 117 insertions(+), 126 deletions(-) diff --git a/ChangeLog b/ChangeLog index 0592459c3..2ce132a14 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,43 @@ +2011-10-16 Vladimir Serbinenko + + Replace grub_module_iterate with FOR_MODULES. + + * grub-core/disk/memdisk.c (GRUB_MOD_INIT): Switched to new interface. + * grub-core/kern/efi/efi.c (grub_arch_modules_addr): Renamed to... + (grub_efi_modules_addr): ...this. + * grub-core/kern/efi/init.c (grub_modbase): New variable. + (grub_efi_init): Set grub_modbase. + * grub-core/kern/emu/main.c (grub_arch_modules_addr): Removed. + (grub_modbase): New variable. + * grub-core/kern/i386/coreboot/init.c (grub_arch_modules_addr): Removed. + (grub_modbase): New variable. + (grub_machine_init): Set grub_modbase. + * grub-core/kern/i386/pc/init.c (grub_arch_modules_addr): Removed. + (grub_modbase): New variable. + (grub_machine_init): Set grub_modbase. + * grub-core/kern/ieee1275/init.c (grub_arch_modules_addr): Removed. + (grub_modbase): New variable. + (grub_machine_init): Set grub_modbase. + * grub-core/kern/main.c (grub_module_iterate): Remove. + (grub_modules_get_end): Use grub_modbase. + (grub_load_modules): Use FOR_MODULES. + (grub_load_config): Likewise. + * grub-core/kern/mips/arc/init.c (grub_arch_modules_addr): Removed. + (grub_modbase): New variable. + (grub_machine_init): Set grub_modbase. + * grub-core/kern/mips/loongson/init.c (grub_arch_modules_addr): Removed. + (grub_modbase): New variable. + (grub_machine_init): Set grub_modbase. + * grub-core/kern/mips/qemu_mips/init.c (grub_arch_modules_addr): + Removed. + (grub_modbase): New variable. + (grub_machine_init): Set grub_modbase. + * include/grub/efi/efi.h (grub_efi_modules_addr): New declaration. + * include/grub/kernel.h (grub_arch_modules_addr): Removed. + (grub_module_iterate): Likewise. + (grub_modbase): New variable declaration. + (FOR_MODULES): New macro. + 2011-10-16 Vladimir Serbinenko * configure.ac: Check for __ctzdi2 and __ctzsi2. diff --git a/grub-core/disk/memdisk.c b/grub-core/disk/memdisk.c index ed570c6a0..4de0971ae 100644 --- a/grub-core/disk/memdisk.c +++ b/grub-core/disk/memdisk.c @@ -86,30 +86,24 @@ static struct grub_disk_dev grub_memdisk_dev = GRUB_MOD_INIT(memdisk) { - auto int hook (struct grub_module_header *); - int hook (struct grub_module_header *header) - { - if (header->type == OBJ_TYPE_MEMDISK) - { - char *memdisk_orig_addr; - memdisk_orig_addr = (char *) header + sizeof (struct grub_module_header); + struct grub_module_header *header; + FOR_MODULES (header) + if (header->type == OBJ_TYPE_MEMDISK) + { + char *memdisk_orig_addr; + memdisk_orig_addr = (char *) header + sizeof (struct grub_module_header); - grub_dprintf ("memdisk", "Found memdisk image at %p\n", memdisk_orig_addr); + grub_dprintf ("memdisk", "Found memdisk image at %p\n", memdisk_orig_addr); - memdisk_size = header->size - sizeof (struct grub_module_header); - memdisk_addr = grub_malloc (memdisk_size); + memdisk_size = header->size - sizeof (struct grub_module_header); + memdisk_addr = grub_malloc (memdisk_size); - grub_dprintf ("memdisk", "Copying memdisk image to dynamic memory\n"); - grub_memmove (memdisk_addr, memdisk_orig_addr, memdisk_size); + grub_dprintf ("memdisk", "Copying memdisk image to dynamic memory\n"); + grub_memmove (memdisk_addr, memdisk_orig_addr, memdisk_size); - grub_disk_dev_register (&grub_memdisk_dev); - return 1; - } - - return 0; - } - - grub_module_iterate (hook); + grub_disk_dev_register (&grub_memdisk_dev); + break; + } } GRUB_MOD_FINI(memdisk) diff --git a/grub-core/kern/efi/efi.c b/grub-core/kern/efi/efi.c index d0994a940..e27dd1ad0 100644 --- a/grub-core/kern/efi/efi.c +++ b/grub-core/kern/efi/efi.c @@ -218,7 +218,7 @@ grub_get_rtc (void) /* Search the mods section from the PE32/PE32+ image. This code uses a PE32 header, but should work with PE32+ as well. */ grub_addr_t -grub_arch_modules_addr (void) +grub_efi_modules_addr (void) { grub_efi_loaded_image_t *image; struct grub_pe32_header *header; diff --git a/grub-core/kern/efi/init.c b/grub-core/kern/efi/init.c index 4dfb06284..942ab0256 100644 --- a/grub-core/kern/efi/init.c +++ b/grub-core/kern/efi/init.c @@ -26,9 +26,12 @@ #include #include +grub_addr_t grub_modbase; + void grub_efi_init (void) { + grub_modbase = grub_efi_modules_addr (); /* First of all, initialize the console so that GRUB can display messages. */ grub_console_init (); diff --git a/grub-core/kern/emu/main.c b/grub-core/kern/emu/main.c index 9a58acd9e..d5c09ad47 100644 --- a/grub-core/kern/emu/main.c +++ b/grub-core/kern/emu/main.c @@ -53,11 +53,7 @@ static char *root_dev = NULL, *dir = NULL; int grub_no_autoload; -grub_addr_t -grub_arch_modules_addr (void) -{ - return 0; -} +grub_addr_t grub_modbase = 0; void grub_reboot (void) diff --git a/grub-core/kern/i386/coreboot/init.c b/grub-core/kern/i386/coreboot/init.c index ebbea2523..b7510ff98 100644 --- a/grub-core/kern/i386/coreboot/init.c +++ b/grub-core/kern/i386/coreboot/init.c @@ -56,10 +56,18 @@ grub_exit (void) grub_cpu_idle (); } +#ifdef GRUB_MACHINE_QEMU +grub_addr_t grub_modbase; +#else +grub_addr_t grub_modbase = ALIGN_UP((grub_addr_t) _end, GRUB_KERNEL_MACHINE_MOD_ALIGN); +#endif + void grub_machine_init (void) { #ifdef GRUB_MACHINE_QEMU + grub_modbase = grub_core_entry_addr + grub_kernel_image_size; + grub_qemu_init_cirrus (); #endif /* Initialize the console as early as possible. */ @@ -118,14 +126,3 @@ grub_machine_fini (void) grub_vga_text_fini (); grub_stop_floppy (); } - -/* Return the end of the core image. */ -grub_addr_t -grub_arch_modules_addr (void) -{ -#ifdef GRUB_MACHINE_QEMU - return grub_core_entry_addr + grub_kernel_image_size; -#else - return ALIGN_UP((grub_addr_t) _end, GRUB_KERNEL_MACHINE_MOD_ALIGN); -#endif -} diff --git a/grub-core/kern/i386/pc/init.c b/grub-core/kern/i386/pc/init.c index 24fe8fed9..62269de78 100644 --- a/grub-core/kern/i386/pc/init.c +++ b/grub-core/kern/i386/pc/init.c @@ -129,6 +129,8 @@ compact_mem_regions (void) } } +grub_addr_t grub_modbase; + void grub_machine_init (void) { @@ -137,6 +139,9 @@ grub_machine_init (void) int grub_lower_mem; #endif + grub_modbase = GRUB_MEMORY_MACHINE_DECOMPRESSION_ADDR + + (grub_kernel_image_size - GRUB_KERNEL_MACHINE_RAW_SIZE); + /* Initialize the console as early as possible. */ grub_console_init (); @@ -206,11 +211,3 @@ grub_machine_fini (void) grub_console_fini (); grub_stop_floppy (); } - -/* Return the end of the core image. */ -grub_addr_t -grub_arch_modules_addr (void) -{ - return GRUB_MEMORY_MACHINE_DECOMPRESSION_ADDR - + (grub_kernel_image_size - GRUB_KERNEL_MACHINE_RAW_SIZE); -} diff --git a/grub-core/kern/ieee1275/init.c b/grub-core/kern/ieee1275/init.c index 81b06c88e..76f932d09 100644 --- a/grub-core/kern/ieee1275/init.c +++ b/grub-core/kern/ieee1275/init.c @@ -256,9 +256,14 @@ grub_parse_cmdline (void) static grub_uint64_t ieee1275_get_time_ms (void); +grub_addr_t grub_modbase; + void grub_machine_init (void) { + grub_modbase = ALIGN_UP((grub_addr_t) _end + + GRUB_KERNEL_MACHINE_MOD_GAP, + GRUB_KERNEL_MACHINE_MOD_ALIGN); grub_ieee1275_init (); grub_console_init_early (); @@ -293,9 +298,3 @@ grub_get_rtc (void) { return ieee1275_get_time_ms (); } - -grub_addr_t -grub_arch_modules_addr (void) -{ - return ALIGN_UP((grub_addr_t) _end + GRUB_KERNEL_MACHINE_MOD_GAP, GRUB_KERNEL_MACHINE_MOD_ALIGN); -} diff --git a/grub-core/kern/main.c b/grub-core/kern/main.c index 0cec93d89..9e1971773 100644 --- a/grub-core/kern/main.c +++ b/grub-core/kern/main.c @@ -30,45 +30,20 @@ #include #include -void -grub_module_iterate (int (*hook) (struct grub_module_header *header)) -{ - struct grub_module_info *modinfo; - struct grub_module_header *header; - grub_addr_t modbase; - - modbase = grub_arch_modules_addr (); - modinfo = (struct grub_module_info *) modbase; - - /* Check if there are any modules. */ - if ((modinfo == 0) || modinfo->magic != GRUB_MODULE_MAGIC) - return; - - for (header = (struct grub_module_header *) (modbase + modinfo->offset); - header < (struct grub_module_header *) (modbase + modinfo->size); - header = (struct grub_module_header *) ((char *) header + header->size)) - { - if (hook (header)) - break; - } -} - /* This is actualy platform-independant but used only on loongson and sparc. */ #if defined (GRUB_MACHINE_MIPS_LOONGSON) || defined (GRUB_MACHINE_MIPS_QEMU_MIPS) || defined (GRUB_MACHINE_SPARC64) grub_addr_t grub_modules_get_end (void) { struct grub_module_info *modinfo; - grub_addr_t modbase; - modbase = grub_arch_modules_addr (); - modinfo = (struct grub_module_info *) modbase; + modinfo = (struct grub_module_info *) grub_modbase; /* Check if there are any modules. */ if ((modinfo == 0) || modinfo->magic != GRUB_MODULE_MAGIC) - return modbase; + return grub_modbase; - return modbase + modinfo->size; + return grub_modbase + modinfo->size; } #endif @@ -76,42 +51,36 @@ grub_modules_get_end (void) static void grub_load_modules (void) { - auto int hook (struct grub_module_header *); - int hook (struct grub_module_header *header) - { - /* Not an ELF module, skip. */ - if (header->type != OBJ_TYPE_ELF) - return 0; + struct grub_module_header *header; + FOR_MODULES (header) + { + /* Not an ELF module, skip. */ + if (header->type != OBJ_TYPE_ELF) + continue; - if (! grub_dl_load_core ((char *) header + sizeof (struct grub_module_header), - (header->size - sizeof (struct grub_module_header)))) - grub_fatal ("%s", grub_errmsg); + if (! grub_dl_load_core ((char *) header + sizeof (struct grub_module_header), + (header->size - sizeof (struct grub_module_header)))) + grub_fatal ("%s", grub_errmsg); - if (grub_errno) - grub_print_error (); - - return 0; - } - - grub_module_iterate (hook); + if (grub_errno) + grub_print_error (); + } } static void grub_load_config (void) { - auto int hook (struct grub_module_header *); - int hook (struct grub_module_header *header) - { - /* Not an embedded config, skip. */ - if (header->type != OBJ_TYPE_CONFIG) - return 0; - - grub_parser_execute ((char *) header + - sizeof (struct grub_module_header)); - return 1; - } - - grub_module_iterate (hook); + struct grub_module_header *header; + FOR_MODULES (header) + { + /* Not an embedded config, skip. */ + if (header->type != OBJ_TYPE_CONFIG) + continue; + + grub_parser_execute ((char *) header + + sizeof (struct grub_module_header)); + break; + } } /* Write hook for the environment variables of root. Remove surrounding diff --git a/grub-core/kern/mips/arc/init.c b/grub-core/kern/mips/arc/init.c index 514b481f6..2e25335ca 100644 --- a/grub-core/kern/mips/arc/init.c +++ b/grub-core/kern/mips/arc/init.c @@ -125,12 +125,14 @@ grub_machine_mmap_iterate (grub_memory_hook_t hook) } extern grub_uint32_t grub_total_modules_size; +grub_addr_t grub_modbase; void grub_machine_init (void) { struct grub_arc_memory_descriptor *cur = NULL; + grub_modbase = GRUB_KERNEL_MIPS_ARC_LINK_ADDR - grub_total_modules_size; grub_console_init_early (); /* FIXME: measure this. */ @@ -164,12 +166,6 @@ grub_machine_init (void) grub_arcdisk_init (); } -grub_addr_t -grub_arch_modules_addr (void) -{ - return GRUB_KERNEL_MIPS_ARC_LINK_ADDR - grub_total_modules_size; -} - void grub_machine_fini (void) { diff --git a/grub-core/kern/mips/loongson/init.c b/grub-core/kern/mips/loongson/init.c index 2d1a0653e..8acfb0767 100644 --- a/grub-core/kern/mips/loongson/init.c +++ b/grub-core/kern/mips/loongson/init.c @@ -298,9 +298,5 @@ grub_reboot (void) } extern char _end[]; +grub_addr_t grub_modbase = (grub_addr_t) _end; -grub_addr_t -grub_arch_modules_addr (void) -{ - return (grub_addr_t) _end; -} diff --git a/grub-core/kern/mips/qemu_mips/init.c b/grub-core/kern/mips/qemu_mips/init.c index db9cc796a..4921c42bf 100644 --- a/grub-core/kern/mips/qemu_mips/init.c +++ b/grub-core/kern/mips/qemu_mips/init.c @@ -113,9 +113,5 @@ grub_machine_mmap_iterate (grub_memory_hook_t hook) } extern char _end[]; +grub_addr_t grub_modbase = (grub_addr_t) _end; -grub_addr_t -grub_arch_modules_addr (void) -{ - return (grub_addr_t) _end; -} diff --git a/include/grub/efi/efi.h b/include/grub/efi/efi.h index e98f99507..7ecda58ab 100644 --- a/include/grub/efi/efi.h +++ b/include/grub/efi/efi.h @@ -70,6 +70,8 @@ extern void (*EXPORT_VAR(grub_efi_net_config)) (grub_efi_handle_t hnd, char **device, char **path); +grub_addr_t grub_efi_modules_addr (void); + void grub_efi_mm_init (void); void grub_efi_mm_fini (void); void grub_efi_init (void); diff --git a/include/grub/kernel.h b/include/grub/kernel.h index aef585668..d8c0fed33 100644 --- a/include/grub/kernel.h +++ b/include/grub/kernel.h @@ -68,9 +68,15 @@ struct grub_module_info64 #define grub_module_info grub_module_info32 #endif -extern grub_addr_t grub_arch_modules_addr (void); +extern grub_addr_t EXPORT_VAR (grub_modbase); -extern void EXPORT_FUNC(grub_module_iterate) (int (*hook) (struct grub_module_header *)); +#define FOR_MODULES(var) for (\ + var = grub_modbase ? (struct grub_module_header *) \ + (grub_modbase + (((struct grub_module_info *) grub_modbase)->offset)) : 0;\ + var && (grub_addr_t) var \ + < (grub_modbase + (((struct grub_module_info *) grub_modbase)->size)); \ + var = (struct grub_module_header *) \ + ((char *) var + ((struct grub_module_header *) var)->size)) grub_addr_t grub_modules_get_end (void); From a97501d2389d524323293395636b43aec73f1761 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Tue, 18 Oct 2011 15:21:51 +0200 Subject: [PATCH 832/869] Make grub_prefix into module to fix the arbitrary limit and save some space. * grub-core/kern/emu/main.c (grub_prefix): Removed. * grub-core/kern/i386/coreboot/startup.S (grub_prefix): Likewise. * grub-core/kern/i386/efi/startup.S (grub_prefix): Likewise. * grub-core/kern/i386/ieee1275/startup.S (grub_prefix): Likewise. * grub-core/kern/i386/pc/startup.S (grub_prefix): Likewise. * grub-core/kern/i386/qemu/startup.S (grub_prefix): Likewise. * grub-core/kern/ia64/efi/startup.S (grub_prefix): Likewise. * grub-core/kern/mips/startup.S (grub_prefix): Likewise. * grub-core/kern/powerpc/ieee1275/startup.S (grub_prefix): Likewise. * grub-core/kern/sparc64/ieee1275/crt0.S (grub_prefix): Likewise. * grub-core/kern/x86_64/efi/startup.S (grub_prefix): Likewise. * include/grub/ia64/efi/kernel.h: Removed. * include/grub/kernel.h: New module type OBJ_TYPE_PREFIX. (grub_prefix): Removed. * include/grub/offsets.h (GRUB_KERNEL_I386_PC_PREFIX): Removed. (GRUB_KERNEL_I386_PC_PREFIX_END): Likewise. (GRUB_KERNEL_I386_QEMU_PREFIX): Likewise. (GRUB_KERNEL_I386_QEMU_PREFIX_END): Likewise. (GRUB_KERNEL_SPARC64_IEEE1275_PREFIX): Likewise. (GRUB_KERNEL_SPARC64_IEEE1275_PREFIX_END): Likewise. (GRUB_KERNEL_POWERPC_IEEE1275_PREFIX): Likewise. (GRUB_KERNEL_POWERPC_IEEE1275_PREFIX_END): Likewise. (GRUB_KERNEL_MIPS_LOONGSON_PREFIX): Likewise. (GRUB_KERNEL_MIPS_LOONGSON_PREFIX_END): Likewise. (GRUB_KERNEL_MIPS_QEMU_MIPS_PREFIX): Likewise. (GRUB_KERNEL_MIPS_QEMU_MIPS_PREFIX_END): Likewise. (GRUB_KERNEL_MIPS_ARC_PREFIX): Likewise. (GRUB_KERNEL_MIPS_ARC_PREFIX_END): Likewise. (GRUB_KERNEL_I386_EFI_PREFIX): Likewise. (GRUB_KERNEL_I386_EFI_PREFIX_END): Likewise. (GRUB_KERNEL_IA64_EFI_PREFIX): Likewise. (GRUB_KERNEL_IA64_EFI_PREFIX_END): Likewise. (GRUB_KERNEL_X86_64_EFI_PREFIX): Likewise. (GRUB_KERNEL_X86_64_EFI_PREFIX_END): Likewise. (GRUB_KERNEL_I386_COREBOOT_PREFIX): Likewise. (GRUB_KERNEL_I386_COREBOOT_PREFIX_END): Likewise. (GRUB_KERNEL_I386_MULTIBOOT_PREFIX): Likewise. (GRUB_KERNEL_I386_MULTIBOOT_PREFIX_END): Likewise. (GRUB_KERNEL_I386_IEEE1275_PREFIX): Likewise. (GRUB_KERNEL_I386_IEEE1275_PREFIX_END): Likewise. (GRUB_KERNEL_MACHINE_PREFIX): Likewise. (GRUB_KERNEL_MACHINE_PREFIX_END): Likewise. * grub-core/kern/main.c (grub_set_prefix_and_root): Retrieve grub_prefix from module. * util/grub-mkimage.c (image_target_desc): Removed prefix and prefix_end. (image_targets): Likewise. (generate_image): Put prefix as a module. --- ChangeLog | 54 ++++++++++++++++++ grub-core/kern/emu/main.c | 2 - grub-core/kern/i386/coreboot/startup.S | 15 ----- grub-core/kern/i386/efi/startup.S | 11 ---- grub-core/kern/i386/ieee1275/startup.S | 18 ------ grub-core/kern/i386/pc/startup.S | 11 ---- grub-core/kern/i386/qemu/startup.S | 8 --- grub-core/kern/ia64/efi/startup.S | 10 ---- grub-core/kern/main.c | 49 +++++++++------- grub-core/kern/mips/startup.S | 11 ---- grub-core/kern/powerpc/ieee1275/startup.S | 14 ----- grub-core/kern/sparc64/ieee1275/crt0.S | 8 --- grub-core/kern/x86_64/efi/startup.S | 15 ----- include/grub/ia64/efi/kernel.h | 34 ------------ include/grub/kernel.h | 8 +-- include/grub/offsets.h | 53 ------------------ util/grub-mkimage.c | 68 ++++++++--------------- 17 files changed, 106 insertions(+), 283 deletions(-) delete mode 100644 include/grub/ia64/efi/kernel.h diff --git a/ChangeLog b/ChangeLog index 2ce132a14..a758fc275 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,57 @@ +2011-10-18 Vladimir Serbinenko + + Make grub_prefix into module to fix the arbitrary limit and save + some space. + + * grub-core/kern/emu/main.c (grub_prefix): Removed. + * grub-core/kern/i386/coreboot/startup.S (grub_prefix): Likewise. + * grub-core/kern/i386/efi/startup.S (grub_prefix): Likewise. + * grub-core/kern/i386/ieee1275/startup.S (grub_prefix): Likewise. + * grub-core/kern/i386/pc/startup.S (grub_prefix): Likewise. + * grub-core/kern/i386/qemu/startup.S (grub_prefix): Likewise. + * grub-core/kern/ia64/efi/startup.S (grub_prefix): Likewise. + * grub-core/kern/mips/startup.S (grub_prefix): Likewise. + * grub-core/kern/powerpc/ieee1275/startup.S (grub_prefix): Likewise. + * grub-core/kern/sparc64/ieee1275/crt0.S (grub_prefix): Likewise. + * grub-core/kern/x86_64/efi/startup.S (grub_prefix): Likewise. + * include/grub/ia64/efi/kernel.h: Removed. + * include/grub/kernel.h: New module type OBJ_TYPE_PREFIX. + (grub_prefix): Removed. + * include/grub/offsets.h (GRUB_KERNEL_I386_PC_PREFIX): Removed. + (GRUB_KERNEL_I386_PC_PREFIX_END): Likewise. + (GRUB_KERNEL_I386_QEMU_PREFIX): Likewise. + (GRUB_KERNEL_I386_QEMU_PREFIX_END): Likewise. + (GRUB_KERNEL_SPARC64_IEEE1275_PREFIX): Likewise. + (GRUB_KERNEL_SPARC64_IEEE1275_PREFIX_END): Likewise. + (GRUB_KERNEL_POWERPC_IEEE1275_PREFIX): Likewise. + (GRUB_KERNEL_POWERPC_IEEE1275_PREFIX_END): Likewise. + (GRUB_KERNEL_MIPS_LOONGSON_PREFIX): Likewise. + (GRUB_KERNEL_MIPS_LOONGSON_PREFIX_END): Likewise. + (GRUB_KERNEL_MIPS_QEMU_MIPS_PREFIX): Likewise. + (GRUB_KERNEL_MIPS_QEMU_MIPS_PREFIX_END): Likewise. + (GRUB_KERNEL_MIPS_ARC_PREFIX): Likewise. + (GRUB_KERNEL_MIPS_ARC_PREFIX_END): Likewise. + (GRUB_KERNEL_I386_EFI_PREFIX): Likewise. + (GRUB_KERNEL_I386_EFI_PREFIX_END): Likewise. + (GRUB_KERNEL_IA64_EFI_PREFIX): Likewise. + (GRUB_KERNEL_IA64_EFI_PREFIX_END): Likewise. + (GRUB_KERNEL_X86_64_EFI_PREFIX): Likewise. + (GRUB_KERNEL_X86_64_EFI_PREFIX_END): Likewise. + (GRUB_KERNEL_I386_COREBOOT_PREFIX): Likewise. + (GRUB_KERNEL_I386_COREBOOT_PREFIX_END): Likewise. + (GRUB_KERNEL_I386_MULTIBOOT_PREFIX): Likewise. + (GRUB_KERNEL_I386_MULTIBOOT_PREFIX_END): Likewise. + (GRUB_KERNEL_I386_IEEE1275_PREFIX): Likewise. + (GRUB_KERNEL_I386_IEEE1275_PREFIX_END): Likewise. + (GRUB_KERNEL_MACHINE_PREFIX): Likewise. + (GRUB_KERNEL_MACHINE_PREFIX_END): Likewise. + * grub-core/kern/main.c (grub_set_prefix_and_root): Retrieve grub_prefix + from module. + * util/grub-mkimage.c (image_target_desc): Removed prefix and + prefix_end. + (image_targets): Likewise. + (generate_image): Put prefix as a module. + 2011-10-16 Vladimir Serbinenko Replace grub_module_iterate with FOR_MODULES. diff --git a/grub-core/kern/emu/main.c b/grub-core/kern/emu/main.c index d5c09ad47..8d15f17c5 100644 --- a/grub-core/kern/emu/main.c +++ b/grub-core/kern/emu/main.c @@ -79,8 +79,6 @@ grub_machine_fini (void) grub_console_fini (); } -char grub_prefix[64] = ""; - static struct option options[] = diff --git a/grub-core/kern/i386/coreboot/startup.S b/grub-core/kern/i386/coreboot/startup.S index 07c5437c0..5e7767bb9 100644 --- a/grub-core/kern/i386/coreboot/startup.S +++ b/grub-core/kern/i386/coreboot/startup.S @@ -40,21 +40,6 @@ start: _start: jmp codestart - /* - * This is a special data area at a fixed offset from the beginning. - */ - - . = _start + GRUB_KERNEL_MACHINE_PREFIX - -VARIABLE(grub_prefix) - /* to be filled by grub-mkimage */ - - /* - * Leave some breathing room for the prefix. - */ - - . = _start + GRUB_KERNEL_MACHINE_PREFIX_END - /* * Support for booting GRUB from a Multiboot boot loader (e.g. GRUB itself). */ diff --git a/grub-core/kern/i386/efi/startup.S b/grub-core/kern/i386/efi/startup.S index 5b464ab83..49b05c1e6 100644 --- a/grub-core/kern/i386/efi/startup.S +++ b/grub-core/kern/i386/efi/startup.S @@ -41,17 +41,6 @@ _start: * This is a special data area 8 bytes from the beginning. */ - . = _start + 0x8 - -VARIABLE(grub_prefix) - /* to be filled by grub-mkimage */ - - /* - * Leave some breathing room for the prefix. - */ - - . = _start + 0x50 - codestart: /* * EFI_SYSTEM_TABLE * and EFI_HANDLE are passed on the stack. diff --git a/grub-core/kern/i386/ieee1275/startup.S b/grub-core/kern/i386/ieee1275/startup.S index 82087323b..6b39f5f3a 100644 --- a/grub-core/kern/i386/ieee1275/startup.S +++ b/grub-core/kern/i386/ieee1275/startup.S @@ -36,24 +36,6 @@ start: _start: - jmp codestart - - /* - * This is a special data area at a fixed offset from the beginning. - */ - - . = _start + GRUB_KERNEL_MACHINE_PREFIX - -VARIABLE(grub_prefix) - /* to be filled by grub-mkimage */ - - /* - * Leave some breathing room for the prefix. - */ - - . = _start + GRUB_KERNEL_MACHINE_PREFIX_END - -codestart: movl %eax, EXT_C(grub_ieee1275_entry_fn) jmp EXT_C(grub_main) diff --git a/grub-core/kern/i386/pc/startup.S b/grub-core/kern/i386/pc/startup.S index 0fe114add..3bbe34753 100644 --- a/grub-core/kern/i386/pc/startup.S +++ b/grub-core/kern/i386/pc/startup.S @@ -455,17 +455,6 @@ gate_a20_check_state: */ . = _start + GRUB_KERNEL_MACHINE_RAW_SIZE - . = _start + GRUB_KERNEL_MACHINE_PREFIX -VARIABLE(grub_prefix) - /* to be filled by grub-mkimage */ - - /* - * Leave some breathing room for the prefix. - */ - . = _start + GRUB_KERNEL_MACHINE_PREFIX_END - - - /* * grub_exit() * diff --git a/grub-core/kern/i386/qemu/startup.S b/grub-core/kern/i386/qemu/startup.S index 7834d1df5..6500de620 100644 --- a/grub-core/kern/i386/qemu/startup.S +++ b/grub-core/kern/i386/qemu/startup.S @@ -34,14 +34,6 @@ VARIABLE(grub_core_entry_addr) .long 0 VARIABLE(grub_kernel_image_size) .long 0 -VARIABLE(grub_prefix) - /* to be filled by grub-mkimage */ - - /* - * Leave some breathing room for the prefix. - */ - - . = _start + GRUB_KERNEL_MACHINE_PREFIX_END codestart: /* Relocate to low memory. First we figure out our location. diff --git a/grub-core/kern/ia64/efi/startup.S b/grub-core/kern/ia64/efi/startup.S index b5e26a204..d75c6d7cc 100644 --- a/grub-core/kern/ia64/efi/startup.S +++ b/grub-core/kern/ia64/efi/startup.S @@ -42,13 +42,3 @@ _start: br.ret.sptk.few rp .endp _start - - . = _start + GRUB_KERNEL_MACHINE_PREFIX -VARIABLE(grub_prefix) - .byte 0 - /* to be filled by grub-mkimage */ - - /* - * Leave some breathing room for the prefix. - */ - . = _start + GRUB_KERNEL_MACHINE_PREFIX_END diff --git a/grub-core/kern/main.c b/grub-core/kern/main.c index 9e1971773..77be11422 100644 --- a/grub-core/kern/main.c +++ b/grub-core/kern/main.c @@ -105,25 +105,32 @@ grub_set_prefix_and_root (void) char *path = NULL; char *fwdevice = NULL; char *fwpath = NULL; + char *prefix; + struct grub_module_header *header; + + FOR_MODULES (header) + if (header->type == OBJ_TYPE_PREFIX) + prefix = (char *) header + sizeof (struct grub_module_header); grub_register_variable_hook ("root", 0, grub_env_write_root); - { - char *pptr = NULL; - if (grub_prefix[0] == '(') - { - pptr = grub_strrchr (grub_prefix, ')'); - if (pptr) - { - device = grub_strndup (grub_prefix + 1, pptr - grub_prefix - 1); - pptr++; - } - } - if (!pptr) - pptr = grub_prefix; - if (pptr[0]) - path = grub_strdup (pptr); - } + if (prefix) + { + char *pptr = NULL; + if (prefix[0] == '(') + { + pptr = grub_strrchr (prefix, ')'); + if (pptr) + { + device = grub_strndup (prefix + 1, pptr - prefix - 1); + pptr++; + } + } + if (!pptr) + pptr = prefix; + if (pptr[0]) + path = grub_strdup (pptr); + } if ((!device || device[0] == ',' || !device[0]) || !path) grub_machine_get_bootlocation (&fwdevice, &fwpath); @@ -152,13 +159,13 @@ grub_set_prefix_and_root (void) path = fwpath; if (device) { - char *prefix; + char *prefix_set; - prefix = grub_xasprintf ("(%s)%s", device, path ? : ""); - if (prefix) + prefix_set = grub_xasprintf ("(%s)%s", device, path ? : ""); + if (prefix_set) { - grub_env_set ("prefix", prefix); - grub_free (prefix); + grub_env_set ("prefix", prefix_set); + grub_free (prefix_set); } grub_env_set ("root", device); } diff --git a/grub-core/kern/mips/startup.S b/grub-core/kern/mips/startup.S index da6450237..2476038bc 100644 --- a/grub-core/kern/mips/startup.S +++ b/grub-core/kern/mips/startup.S @@ -40,17 +40,6 @@ start: VARIABLE(grub_total_modules_size) .long 0 - . = _start + GRUB_KERNEL_MACHINE_PREFIX - -VARIABLE(grub_prefix) - - /* to be filled by grub-mkimage */ - - /* - * Leave some breathing room for the prefix. - */ - - . = _start + GRUB_KERNEL_MACHINE_PREFIX_END VARIABLE (grub_arch_busclock) .long 0 VARIABLE (grub_arch_cpuclock) diff --git a/grub-core/kern/powerpc/ieee1275/startup.S b/grub-core/kern/powerpc/ieee1275/startup.S index 0b1c23346..b26c47edb 100644 --- a/grub-core/kern/powerpc/ieee1275/startup.S +++ b/grub-core/kern/powerpc/ieee1275/startup.S @@ -28,20 +28,6 @@ .globl start, _start start: _start: - b codestart - - . = _start + GRUB_KERNEL_MACHINE_PREFIX - -VARIABLE(grub_prefix) - /* to be filled by grub-mkimage */ - - /* - * Leave some breathing room for the prefix. - */ - - . = _start + GRUB_KERNEL_MACHINE_PREFIX_END - -codestart: li 2, 0 li 13, 0 diff --git a/grub-core/kern/sparc64/ieee1275/crt0.S b/grub-core/kern/sparc64/ieee1275/crt0.S index cebdca2b6..1466a56f8 100644 --- a/grub-core/kern/sparc64/ieee1275/crt0.S +++ b/grub-core/kern/sparc64/ieee1275/crt0.S @@ -35,14 +35,6 @@ VARIABLE(grub_kernel_image_size) .word 0 VARIABLE(grub_compressed_size) .word 0 -VARIABLE(grub_prefix) - /* to be filled by grub-mkimage */ - - /* - * Leave some breathing room for the prefix. - */ - - . = EXT_C(_start) + GRUB_KERNEL_MACHINE_PREFIX_END codestart: /* Copy the modules past the end of the kernel image. diff --git a/grub-core/kern/x86_64/efi/startup.S b/grub-core/kern/x86_64/efi/startup.S index fb4fc7b64..37efde7fc 100644 --- a/grub-core/kern/x86_64/efi/startup.S +++ b/grub-core/kern/x86_64/efi/startup.S @@ -39,21 +39,6 @@ _start: . = _start + 0x6 .byte GRUB_BOOT_VERSION_MAJOR, GRUB_BOOT_VERSION_MINOR - /* - * This is a special data area 8 bytes from the beginning. - */ - - . = _start + 0x8 - -VARIABLE(grub_prefix) - /* to be filled by grub-mkimage */ - - /* - * Leave some breathing room for the prefix. - */ - - . = _start + 0x50 - codestart: movq %rcx, EXT_C(grub_efi_image_handle)(%rip) movq %rdx, EXT_C(grub_efi_system_table)(%rip) diff --git a/include/grub/ia64/efi/kernel.h b/include/grub/ia64/efi/kernel.h deleted file mode 100644 index ae75380f0..000000000 --- a/include/grub/ia64/efi/kernel.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - * GRUB -- GRand Unified Bootloader - * Copyright (C) 2002,2003,2007,2008,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 . - */ - -#ifndef GRUB_MACHINE_KERNEL_HEADER -#define GRUB_MACHINE_KERNEL_HEADER 1 - -/* The offset of GRUB_PREFIX. */ -#define GRUB_KERNEL_MACHINE_PREFIX 0x8 - -/* End of the data section. */ -#define GRUB_KERNEL_MACHINE_DATA_END 0x50 - -#ifndef ASM_FILE -/* The prefix which points to the directory where GRUB modules and its - configuration file are located. */ -extern char grub_prefix[]; -#endif - -#endif /* ! GRUB_MACHINE_KERNEL_HEADER */ diff --git a/include/grub/kernel.h b/include/grub/kernel.h index d8c0fed33..2ff6b2469 100644 --- a/include/grub/kernel.h +++ b/include/grub/kernel.h @@ -26,7 +26,8 @@ enum { OBJ_TYPE_ELF, OBJ_TYPE_MEMDISK, - OBJ_TYPE_CONFIG + OBJ_TYPE_CONFIG, + OBJ_TYPE_PREFIX }; /* The module header. */ @@ -98,9 +99,4 @@ void grub_register_exported_symbols (void); extern void (*EXPORT_VAR(grub_net_poll_cards_idle)) (void); - -#if ! defined (ASM_FILE) -extern char grub_prefix[]; -#endif - #endif /* ! GRUB_KERNEL_HEADER */ diff --git a/include/grub/offsets.h b/include/grub/offsets.h index e8170fcbe..526cfee68 100644 --- a/include/grub/offsets.h +++ b/include/grub/offsets.h @@ -42,12 +42,6 @@ #define GRUB_KERNEL_I386_PC_NO_REED_SOLOMON_PART 0x730 -/* The offset of GRUB_PREFIX. */ -#define GRUB_KERNEL_I386_PC_PREFIX GRUB_KERNEL_I386_PC_RAW_SIZE - -/* End of the data section. */ -#define GRUB_KERNEL_I386_PC_PREFIX_END (GRUB_KERNEL_I386_PC_PREFIX + 0x40) - /* The segment where the kernel is loaded. */ #define GRUB_BOOT_I386_PC_KERNEL_SEG 0x800 @@ -66,12 +60,6 @@ /* The offset of GRUB_KERNEL_IMAGE_SIZE. */ #define GRUB_KERNEL_I386_QEMU_KERNEL_IMAGE_SIZE 0xc -/* The offset of GRUB_PREFIX. */ -#define GRUB_KERNEL_I386_QEMU_PREFIX 0x10 - -/* End of the data section. */ -#define GRUB_KERNEL_I386_QEMU_PREFIX_END 0x50 - #define GRUB_KERNEL_I386_QEMU_LINK_ADDR 0x8200 /* The offset of GRUB_TOTAL_MODULE_SIZE. */ @@ -83,20 +71,12 @@ /* The offset of GRUB_COMPRESSED_SIZE. */ #define GRUB_KERNEL_SPARC64_IEEE1275_COMPRESSED_SIZE 0x10 -/* The offset of GRUB_PREFIX. */ -#define GRUB_KERNEL_SPARC64_IEEE1275_PREFIX 0x14 - -/* End of the data section. */ -#define GRUB_KERNEL_SPARC64_IEEE1275_PREFIX_END 0x114 - #define GRUB_BOOT_SPARC64_IEEE1275_LIST_SIZE 12 #define GRUB_BOOT_SPARC64_IEEE1275_IMAGE_ADDRESS 0x4400 #define GRUB_KERNEL_SPARC64_IEEE1275_RAW_SIZE 0 #define GRUB_KERNEL_SPARC64_IEEE1275_LINK_ADDR 0x4400 -#define GRUB_KERNEL_POWERPC_IEEE1275_PREFIX 0x4 -#define GRUB_KERNEL_POWERPC_IEEE1275_PREFIX_END 0x44 #define GRUB_KERNEL_POWERPC_IEEE1275_LINK_ALIGN 4 #define GRUB_KERNEL_POWERPC_IEEE1275_LINK_ADDR 0x200000 @@ -109,8 +89,6 @@ #define GRUB_KERNEL_MIPS_LOONGSON_UNCOMPRESSED_ADDR 0x10 #define GRUB_KERNEL_MIPS_LOONGSON_TOTAL_MODULE_SIZE 0x08 -#define GRUB_KERNEL_MIPS_LOONGSON_PREFIX 0x0c -#define GRUB_KERNEL_MIPS_LOONGSON_PREFIX_END 0x54 #define GRUB_KERNEL_MIPS_QEMU_MIPS_LINK_ADDR 0x80200000 #define GRUB_KERNEL_MIPS_QEMU_MIPS_LINK_ALIGN 32 @@ -118,8 +96,6 @@ #define GRUB_KERNEL_MIPS_QEMU_MIPS_UNCOMPRESSED_SIZE 0xc #define GRUB_KERNEL_MIPS_QEMU_MIPS_UNCOMPRESSED_ADDR 0x10 #define GRUB_KERNEL_MIPS_QEMU_MIPS_TOTAL_MODULE_SIZE 0x08 -#define GRUB_KERNEL_MIPS_QEMU_MIPS_PREFIX 0x0c -#define GRUB_KERNEL_MIPS_QEMU_MIPS_PREFIX_END 0x54 #define GRUB_KERNEL_MIPS_ARC_LINK_ADDR 0x8bd00000 @@ -130,36 +106,9 @@ #define GRUB_KERNEL_MIPS_ARC_UNCOMPRESSED_ADDR 0x10 #define GRUB_KERNEL_MIPS_ARC_TOTAL_MODULE_SIZE 0x08 -#define GRUB_KERNEL_MIPS_ARC_PREFIX 0x0c -#define GRUB_KERNEL_MIPS_ARC_PREFIX_END 0x54 -/* The offset of GRUB_PREFIX. */ -#define GRUB_KERNEL_I386_EFI_PREFIX 0x8 - -/* End of the data section. */ -#define GRUB_KERNEL_I386_EFI_PREFIX_END 0x50 - -/* The offset of GRUB_PREFIX. */ -#define GRUB_KERNEL_IA64_EFI_PREFIX 0x50 - -/* End of the data section. */ -#define GRUB_KERNEL_IA64_EFI_PREFIX_END 0xa0 - -/* The offset of GRUB_PREFIX. */ -#define GRUB_KERNEL_X86_64_EFI_PREFIX 0x8 - -/* End of the data section. */ -#define GRUB_KERNEL_X86_64_EFI_PREFIX_END 0x50 - -#define GRUB_KERNEL_I386_COREBOOT_PREFIX 0x2 -#define GRUB_KERNEL_I386_COREBOOT_PREFIX_END 0x42 #define GRUB_KERNEL_I386_COREBOOT_LINK_ADDR 0x8200 -#define GRUB_KERNEL_I386_MULTIBOOT_PREFIX GRUB_KERNEL_I386_COREBOOT_PREFIX -#define GRUB_KERNEL_I386_MULTIBOOT_PREFIX_END GRUB_KERNEL_I386_COREBOOT_PREFIX_END - -#define GRUB_KERNEL_I386_IEEE1275_PREFIX 0x2 -#define GRUB_KERNEL_I386_IEEE1275_PREFIX_END 0x42 #define GRUB_KERNEL_I386_IEEE1275_LINK_ADDR 0x10000 #define GRUB_KERNEL_I386_IEEE1275_MOD_ALIGN 0x1000 @@ -194,8 +143,6 @@ #define GRUB_KERNEL_MACHINE_UNCOMPRESSED_SIZE GRUB_OFFSETS_CONCAT (GRUB_KERNEL_, GRUB_MACHINE, _UNCOMPRESSED_SIZE) #define GRUB_KERNEL_MACHINE_UNCOMPRESSED_ADDR GRUB_OFFSETS_CONCAT (GRUB_KERNEL_, GRUB_MACHINE, _UNCOMPRESSED_ADDR) -#define GRUB_KERNEL_MACHINE_PREFIX GRUB_OFFSETS_CONCAT (GRUB_KERNEL_, GRUB_MACHINE, _PREFIX) -#define GRUB_KERNEL_MACHINE_PREFIX_END GRUB_OFFSETS_CONCAT (GRUB_KERNEL_, GRUB_MACHINE, _PREFIX_END) #define GRUB_BOOT_MACHINE_KERNEL_SEG GRUB_OFFSETS_CONCAT (GRUB_BOOT_, GRUB_MACHINE, _KERNEL_SEG) #define GRUB_MEMORY_MACHINE_UPPER GRUB_OFFSETS_CONCAT (GRUB_MEMORY_, GRUB_MACHINE, _UPPER) #define GRUB_KERNEL_MACHINE_RAW_SIZE GRUB_OFFSETS_CONCAT (GRUB_KERNEL_, GRUB_MACHINE, _RAW_SIZE) diff --git a/util/grub-mkimage.c b/util/grub-mkimage.c index 420690923..4440fdd12 100644 --- a/util/grub-mkimage.c +++ b/util/grub-mkimage.c @@ -77,8 +77,6 @@ struct image_target_desc PLATFORM_FLAGS_DECOMPRESSORS = 2, PLATFORM_FLAGS_MODULES_BEFORE_KERNEL = 4, } flags; - unsigned prefix; - unsigned prefix_end; unsigned raw_size; unsigned total_module_size; unsigned kernel_image_size; @@ -110,8 +108,6 @@ struct image_target_desc image_targets[] = .bigendian = 0, .id = IMAGE_COREBOOT, .flags = PLATFORM_FLAGS_NONE, - .prefix = GRUB_KERNEL_I386_COREBOOT_PREFIX, - .prefix_end = GRUB_KERNEL_I386_COREBOOT_PREFIX_END, .raw_size = 0, .total_module_size = TARGET_NO_FIELD, .kernel_image_size = TARGET_NO_FIELD, @@ -133,8 +129,6 @@ struct image_target_desc image_targets[] = .bigendian = 0, .id = IMAGE_COREBOOT, .flags = PLATFORM_FLAGS_NONE, - .prefix = GRUB_KERNEL_I386_MULTIBOOT_PREFIX, - .prefix_end = GRUB_KERNEL_I386_MULTIBOOT_PREFIX_END, .raw_size = 0, .total_module_size = TARGET_NO_FIELD, .kernel_image_size = TARGET_NO_FIELD, @@ -156,8 +150,6 @@ struct image_target_desc image_targets[] = .bigendian = 0, .id = IMAGE_I386_PC, .flags = PLATFORM_FLAGS_LZMA, - .prefix = GRUB_KERNEL_I386_PC_PREFIX, - .prefix_end = GRUB_KERNEL_I386_PC_PREFIX_END, .raw_size = GRUB_KERNEL_I386_PC_RAW_SIZE, .total_module_size = GRUB_KERNEL_I386_PC_TOTAL_MODULE_SIZE, .kernel_image_size = GRUB_KERNEL_I386_PC_KERNEL_IMAGE_SIZE, @@ -175,8 +167,6 @@ struct image_target_desc image_targets[] = .bigendian = 0, .id = IMAGE_I386_PC_PXE, .flags = PLATFORM_FLAGS_LZMA, - .prefix = GRUB_KERNEL_I386_PC_PREFIX, - .prefix_end = GRUB_KERNEL_I386_PC_PREFIX_END, .raw_size = GRUB_KERNEL_I386_PC_RAW_SIZE, .total_module_size = GRUB_KERNEL_I386_PC_TOTAL_MODULE_SIZE, .kernel_image_size = GRUB_KERNEL_I386_PC_KERNEL_IMAGE_SIZE, @@ -194,8 +184,6 @@ struct image_target_desc image_targets[] = .bigendian = 0, .id = IMAGE_EFI, .flags = PLATFORM_FLAGS_NONE, - .prefix = GRUB_KERNEL_I386_EFI_PREFIX, - .prefix_end = GRUB_KERNEL_I386_EFI_PREFIX_END, .raw_size = 0, .total_module_size = TARGET_NO_FIELD, .kernel_image_size = TARGET_NO_FIELD, @@ -219,8 +207,6 @@ struct image_target_desc image_targets[] = .bigendian = 0, .id = IMAGE_I386_IEEE1275, .flags = PLATFORM_FLAGS_NONE, - .prefix = GRUB_KERNEL_I386_IEEE1275_PREFIX, - .prefix_end = GRUB_KERNEL_I386_IEEE1275_PREFIX_END, .raw_size = 0, .total_module_size = TARGET_NO_FIELD, .kernel_image_size = TARGET_NO_FIELD, @@ -242,8 +228,6 @@ struct image_target_desc image_targets[] = .bigendian = 0, .id = IMAGE_QEMU, .flags = PLATFORM_FLAGS_NONE, - .prefix = GRUB_KERNEL_I386_QEMU_PREFIX, - .prefix_end = GRUB_KERNEL_I386_QEMU_PREFIX_END, .raw_size = 0, .total_module_size = TARGET_NO_FIELD, .compressed_size = TARGET_NO_FIELD, @@ -261,8 +245,6 @@ struct image_target_desc image_targets[] = .bigendian = 0, .id = IMAGE_EFI, .flags = PLATFORM_FLAGS_NONE, - .prefix = GRUB_KERNEL_X86_64_EFI_PREFIX, - .prefix_end = GRUB_KERNEL_X86_64_EFI_PREFIX_END, .raw_size = 0, .total_module_size = TARGET_NO_FIELD, .kernel_image_size = TARGET_NO_FIELD, @@ -281,8 +263,6 @@ struct image_target_desc image_targets[] = .bigendian = 0, .id = IMAGE_YEELOONG_FLASH, .flags = PLATFORM_FLAGS_DECOMPRESSORS, - .prefix = GRUB_KERNEL_MIPS_LOONGSON_PREFIX, - .prefix_end = GRUB_KERNEL_MIPS_LOONGSON_PREFIX_END, .raw_size = 0, .total_module_size = GRUB_KERNEL_MIPS_LOONGSON_TOTAL_MODULE_SIZE, .compressed_size = TARGET_NO_FIELD, @@ -303,8 +283,6 @@ struct image_target_desc image_targets[] = .bigendian = 0, .id = IMAGE_FULOONG2F_FLASH, .flags = PLATFORM_FLAGS_DECOMPRESSORS, - .prefix = GRUB_KERNEL_MIPS_LOONGSON_PREFIX, - .prefix_end = GRUB_KERNEL_MIPS_LOONGSON_PREFIX_END, .raw_size = 0, .total_module_size = GRUB_KERNEL_MIPS_LOONGSON_TOTAL_MODULE_SIZE, .compressed_size = TARGET_NO_FIELD, @@ -327,8 +305,6 @@ struct image_target_desc image_targets[] = .bigendian = 0, .id = IMAGE_LOONGSON_ELF, .flags = PLATFORM_FLAGS_DECOMPRESSORS, - .prefix = GRUB_KERNEL_MIPS_LOONGSON_PREFIX, - .prefix_end = GRUB_KERNEL_MIPS_LOONGSON_PREFIX_END, .raw_size = 0, .total_module_size = GRUB_KERNEL_MIPS_LOONGSON_TOTAL_MODULE_SIZE, .compressed_size = TARGET_NO_FIELD, @@ -349,8 +325,6 @@ struct image_target_desc image_targets[] = .bigendian = 1, .id = IMAGE_PPC, .flags = PLATFORM_FLAGS_NONE, - .prefix = GRUB_KERNEL_POWERPC_IEEE1275_PREFIX, - .prefix_end = GRUB_KERNEL_POWERPC_IEEE1275_PREFIX_END, .raw_size = 0, .total_module_size = TARGET_NO_FIELD, .kernel_image_size = TARGET_NO_FIELD, @@ -372,8 +346,6 @@ struct image_target_desc image_targets[] = .bigendian = 1, .id = IMAGE_SPARC64_RAW, .flags = PLATFORM_FLAGS_NONE, - .prefix = GRUB_KERNEL_SPARC64_IEEE1275_PREFIX, - .prefix_end = GRUB_KERNEL_SPARC64_IEEE1275_PREFIX_END, .raw_size = GRUB_KERNEL_SPARC64_IEEE1275_RAW_SIZE, .total_module_size = GRUB_KERNEL_SPARC64_IEEE1275_TOTAL_MODULE_SIZE, .kernel_image_size = GRUB_KERNEL_SPARC64_IEEE1275_KERNEL_IMAGE_SIZE, @@ -391,8 +363,6 @@ struct image_target_desc image_targets[] = .bigendian = 1, .id = IMAGE_SPARC64_AOUT, .flags = PLATFORM_FLAGS_NONE, - .prefix = GRUB_KERNEL_SPARC64_IEEE1275_PREFIX, - .prefix_end = GRUB_KERNEL_SPARC64_IEEE1275_PREFIX_END, .raw_size = GRUB_KERNEL_SPARC64_IEEE1275_RAW_SIZE, .total_module_size = GRUB_KERNEL_SPARC64_IEEE1275_TOTAL_MODULE_SIZE, .kernel_image_size = GRUB_KERNEL_SPARC64_IEEE1275_KERNEL_IMAGE_SIZE, @@ -410,8 +380,6 @@ struct image_target_desc image_targets[] = .bigendian = 0, .id = IMAGE_EFI, .flags = PLATFORM_FLAGS_NONE, - .prefix = GRUB_KERNEL_IA64_EFI_PREFIX, - .prefix_end = GRUB_KERNEL_IA64_EFI_PREFIX_END, .raw_size = 0, .total_module_size = TARGET_NO_FIELD, .kernel_image_size = TARGET_NO_FIELD, @@ -431,8 +399,6 @@ struct image_target_desc image_targets[] = .id = IMAGE_MIPS_ARC, .flags = (PLATFORM_FLAGS_DECOMPRESSORS | PLATFORM_FLAGS_MODULES_BEFORE_KERNEL), - .prefix = GRUB_KERNEL_MIPS_ARC_PREFIX, - .prefix_end = GRUB_KERNEL_MIPS_ARC_PREFIX_END, .raw_size = 0, .total_module_size = GRUB_KERNEL_MIPS_ARC_TOTAL_MODULE_SIZE, .compressed_size = TARGET_NO_FIELD, @@ -453,8 +419,6 @@ struct image_target_desc image_targets[] = .bigendian = 0, .id = IMAGE_LOONGSON_ELF, .flags = PLATFORM_FLAGS_DECOMPRESSORS, - .prefix = GRUB_KERNEL_MIPS_QEMU_MIPS_PREFIX, - .prefix_end = GRUB_KERNEL_MIPS_QEMU_MIPS_PREFIX_END, .raw_size = 0, .total_module_size = GRUB_KERNEL_MIPS_QEMU_MIPS_TOTAL_MODULE_SIZE, .compressed_size = TARGET_NO_FIELD, @@ -475,8 +439,6 @@ struct image_target_desc image_targets[] = .bigendian = 1, .id = IMAGE_QEMU_MIPS_FLASH, .flags = PLATFORM_FLAGS_DECOMPRESSORS, - .prefix = GRUB_KERNEL_MIPS_QEMU_MIPS_PREFIX, - .prefix_end = GRUB_KERNEL_MIPS_QEMU_MIPS_PREFIX_END, .raw_size = 0, .total_module_size = GRUB_KERNEL_MIPS_QEMU_MIPS_TOTAL_MODULE_SIZE, .compressed_size = TARGET_NO_FIELD, @@ -497,8 +459,6 @@ struct image_target_desc image_targets[] = .bigendian = 0, .id = IMAGE_QEMU_MIPS_FLASH, .flags = PLATFORM_FLAGS_DECOMPRESSORS, - .prefix = GRUB_KERNEL_MIPS_QEMU_MIPS_PREFIX, - .prefix_end = GRUB_KERNEL_MIPS_QEMU_MIPS_PREFIX_END, .raw_size = 0, .total_module_size = GRUB_KERNEL_MIPS_QEMU_MIPS_TOTAL_MODULE_SIZE, .compressed_size = TARGET_NO_FIELD, @@ -519,8 +479,6 @@ struct image_target_desc image_targets[] = .bigendian = 1, .id = IMAGE_LOONGSON_ELF, .flags = PLATFORM_FLAGS_DECOMPRESSORS, - .prefix = GRUB_KERNEL_MIPS_QEMU_MIPS_PREFIX, - .prefix_end = GRUB_KERNEL_MIPS_QEMU_MIPS_PREFIX_END, .raw_size = 0, .total_module_size = GRUB_KERNEL_MIPS_QEMU_MIPS_TOTAL_MODULE_SIZE, .compressed_size = TARGET_NO_FIELD, @@ -797,6 +755,7 @@ generate_image (const char *dir, char *prefix, FILE *out, char *mods[], char *kernel_img, *core_img; size_t kernel_size, total_module_size, core_size, exec_size; size_t memdisk_size = 0, config_size = 0, config_size_pure = 0; + size_t prefix_size = 0; char *kernel_path; size_t offset; struct grub_util_path_list *path_list, *p, *next; @@ -833,6 +792,12 @@ generate_image (const char *dir, char *prefix, FILE *out, char *mods[], total_module_size += config_size + sizeof (struct grub_module_header); } + if (prefix) + { + prefix_size = ALIGN_ADDR (strlen (prefix) + 1); + total_module_size += prefix_size + sizeof (struct grub_module_header); + } + for (p = path_list; p; p = p->next) total_module_size += (ALIGN_ADDR (grub_util_get_image_size (p->name)) + sizeof (struct grub_module_header)); @@ -848,10 +813,6 @@ generate_image (const char *dir, char *prefix, FILE *out, char *mods[], total_module_size, &start_address, &rel_section, &reloc_size, &align, image_target); - if (image_target->prefix + strlen (prefix) + 1 > image_target->prefix_end) - grub_util_error (_("prefix is too long")); - strcpy (kernel_img + image_target->prefix, prefix); - if ((image_target->flags & PLATFORM_FLAGS_DECOMPRESSORS) && (image_target->total_module_size != TARGET_NO_FIELD)) *((grub_uint32_t *) (kernel_img + image_target->total_module_size)) @@ -943,6 +904,21 @@ generate_image (const char *dir, char *prefix, FILE *out, char *mods[], offset += config_size; } + if (prefix) + { + struct grub_module_header *header; + + header = (struct grub_module_header *) (kernel_img + offset); + memset (header, 0, sizeof (struct grub_module_header)); + header->type = grub_host_to_target32 (OBJ_TYPE_PREFIX); + header->size = grub_host_to_target32 (prefix_size + sizeof (*header)); + offset += sizeof (*header); + + grub_memset (kernel_img + offset, 0, prefix_size); + grub_strcpy (kernel_img + offset, prefix); + offset += prefix_size; + } + grub_util_info ("kernel_img=%p, kernel_size=0x%x", kernel_img, kernel_size); compress_kernel (image_target, kernel_img, kernel_size + total_module_size, &core_img, &core_size, comp); From 544c24876e2f20e217c615e10cb802aa1d8295be Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 19 Oct 2011 16:53:18 +0200 Subject: [PATCH 833/869] Move grub_reboot out of the kernel. * grub-core/Makefile.core.def (reboot): Add platform-specific files. * grub-core/kern/efi/efi.c (grub_reboot): Moved to ... * grub-core/lib/efi/reboot.c: ... here. * grub-core/kern/i386/efi/startup.S: Remove including of realmode.S. * grub-core/kern/i386/ieee1275/startup.S: Likewise. * grub-core/kern/i386/pc/startup.S (grub_exit): Inline cold_reboot. * grub-core/kern/i386/realmode.S (grub_reboot): Moved to... * grub-core/lib/i386/reboot_trampoline.S: ... here. * grub-core/kern/ieee1275/openfw.c (grub_reboot): Moved to... * grub-core/lib/ieee1275/reboot.c: ... here. * grub-core/kern/mips/arc/init.c (grub_reboot): Moved to... * grub-core/lib/mips/arc/reboot.c: ... here. * grub-core/kern/mips/loongson/init.c (grub_reboot): Moved to... * grub-core/lib/mips/loongson/reboot.c: ...here. * grub-core/kern/mips/qemu_mips/init.c (grub_reboot): Moved to... * grub-core/lib/mips/qemu_mips/reboot.c: ... here. * include/grub/emu/misc.h (grub_reboot): New function declaration. * include/grub/i386/reboot.h: New file. * include/grub/mips/loongson/ec.h: Fix includes. * include/grub/mips/qemu_mips/kernel.h (grub_reboot): Removed. * include/grub/misc.h (grub_reboot): Don't mark as kernel function. * grub-core/lib/i386/reboot.c: New file. --- ChangeLog | 27 ++++++++++++ grub-core/Makefile.core.def | 19 ++++++--- grub-core/kern/efi/efi.c | 12 ------ grub-core/kern/i386/efi/startup.S | 2 - grub-core/kern/i386/ieee1275/startup.S | 6 --- grub-core/kern/i386/pc/startup.S | 5 ++- grub-core/kern/i386/realmode.S | 15 ------- grub-core/kern/ieee1275/openfw.c | 10 ----- grub-core/kern/mips/arc/init.c | 12 ------ grub-core/kern/mips/loongson/init.c | 32 -------------- grub-core/kern/mips/qemu_mips/init.c | 6 --- grub-core/lib/efi/reboot.c | 32 ++++++++++++++ grub-core/lib/i386/reboot.c | 59 ++++++++++++++++++++++++++ grub-core/lib/i386/reboot_trampoline.S | 33 ++++++++++++++ grub-core/lib/ieee1275/reboot.c | 27 ++++++++++++ grub-core/lib/mips/arc/reboot.c | 34 +++++++++++++++ grub-core/lib/mips/loongson/reboot.c | 57 +++++++++++++++++++++++++ grub-core/lib/mips/qemu_mips/reboot.c | 25 +++++++++++ include/grub/emu/misc.h | 3 ++ include/grub/i386/reboot.h | 28 ++++++++++++ include/grub/mips/loongson/ec.h | 4 ++ include/grub/mips/qemu_mips/kernel.h | 1 - include/grub/misc.h | 2 +- 23 files changed, 348 insertions(+), 103 deletions(-) create mode 100644 grub-core/lib/efi/reboot.c create mode 100644 grub-core/lib/i386/reboot.c create mode 100644 grub-core/lib/i386/reboot_trampoline.S create mode 100644 grub-core/lib/ieee1275/reboot.c create mode 100644 grub-core/lib/mips/arc/reboot.c create mode 100644 grub-core/lib/mips/loongson/reboot.c create mode 100644 grub-core/lib/mips/qemu_mips/reboot.c create mode 100644 include/grub/i386/reboot.h diff --git a/ChangeLog b/ChangeLog index a758fc275..9bea2dc0a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,30 @@ +2011-10-19 Vladimir Serbinenko + + Move grub_reboot out of the kernel. + + * grub-core/Makefile.core.def (reboot): Add platform-specific files. + * grub-core/kern/efi/efi.c (grub_reboot): Moved to ... + * grub-core/lib/efi/reboot.c: ... here. + * grub-core/kern/i386/efi/startup.S: Remove including of realmode.S. + * grub-core/kern/i386/ieee1275/startup.S: Likewise. + * grub-core/kern/i386/pc/startup.S (grub_exit): Inline cold_reboot. + * grub-core/kern/i386/realmode.S (grub_reboot): Moved to... + * grub-core/lib/i386/reboot_trampoline.S: ... here. + * grub-core/kern/ieee1275/openfw.c (grub_reboot): Moved to... + * grub-core/lib/ieee1275/reboot.c: ... here. + * grub-core/kern/mips/arc/init.c (grub_reboot): Moved to... + * grub-core/lib/mips/arc/reboot.c: ... here. + * grub-core/kern/mips/loongson/init.c (grub_reboot): Moved to... + * grub-core/lib/mips/loongson/reboot.c: ...here. + * grub-core/kern/mips/qemu_mips/init.c (grub_reboot): Moved to... + * grub-core/lib/mips/qemu_mips/reboot.c: ... here. + * include/grub/emu/misc.h (grub_reboot): New function declaration. + * include/grub/i386/reboot.h: New file. + * include/grub/mips/loongson/ec.h: Fix includes. + * include/grub/mips/qemu_mips/kernel.h (grub_reboot): Removed. + * include/grub/misc.h (grub_reboot): Don't mark as kernel function. + * grub-core/lib/i386/reboot.c: New file. + 2011-10-18 Vladimir Serbinenko Make grub_prefix into module to fix the arbitrary limit and save diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def index 84739e8fa..396f73b44 100644 --- a/grub-core/Makefile.core.def +++ b/grub-core/Makefile.core.def @@ -633,6 +633,20 @@ module = { emu = lib/emu/halt.c; }; +module = { + name = reboot; + i386 = lib/i386/reboot.c; + i386 = lib/i386/reboot_trampoline.S; + ia64_efi = lib/efi/reboot.c; + x86_64_efi = lib/efi/reboot.c; + powerpc_ieee1275 = lib/ieee1275/reboot.c; + sparc64_ieee1275 = lib/ieee1275/reboot.c; + mips_arc = lib/mips/arc/reboot.c; + mips_loongson = lib/mips/loongson/reboot.c; + mips_qemu_mips = lib/mips/qemu_mips/reboot.c; + common = commands/reboot.c; +}; + module = { name = hashsum; common = commands/hashsum.c; @@ -733,11 +747,6 @@ module = { common = commands/read.c; }; -module = { - name = reboot; - common = commands/reboot.c; -}; - module = { name = search; common = commands/search_wrap.c; diff --git a/grub-core/kern/efi/efi.c b/grub-core/kern/efi/efi.c index e27dd1ad0..9a2c5e64d 100644 --- a/grub-core/kern/efi/efi.c +++ b/grub-core/kern/efi/efi.c @@ -163,18 +163,6 @@ grub_exit (void) for (;;) ; } -/* On i386, a firmware-independant grub_reboot() is provided by realmode.S. */ -#ifndef __i386__ -void -grub_reboot (void) -{ - grub_efi_fini (); - efi_call_4 (grub_efi_system_table->runtime_services->reset_system, - GRUB_EFI_RESET_COLD, GRUB_EFI_SUCCESS, 0, NULL); - for (;;) ; -} -#endif - grub_err_t grub_efi_set_virtual_address_map (grub_efi_uintn_t memory_map_size, grub_efi_uintn_t descriptor_size, diff --git a/grub-core/kern/i386/efi/startup.S b/grub-core/kern/i386/efi/startup.S index 49b05c1e6..0f904d7b3 100644 --- a/grub-core/kern/i386/efi/startup.S +++ b/grub-core/kern/i386/efi/startup.S @@ -51,5 +51,3 @@ codestart: movl %eax, EXT_C(grub_efi_system_table) call EXT_C(grub_main) ret - -#include "../realmode.S" diff --git a/grub-core/kern/i386/ieee1275/startup.S b/grub-core/kern/i386/ieee1275/startup.S index 6b39f5f3a..245583bdb 100644 --- a/grub-core/kern/i386/ieee1275/startup.S +++ b/grub-core/kern/i386/ieee1275/startup.S @@ -39,9 +39,3 @@ _start: movl %eax, EXT_C(grub_ieee1275_entry_fn) jmp EXT_C(grub_main) -/* - * prot_to_real and associated structures (but NOT real_to_prot, that is - * only needed for BIOS gates). - */ -#include "../realmode.S" - diff --git a/grub-core/kern/i386/pc/startup.S b/grub-core/kern/i386/pc/startup.S index 3bbe34753..a70a2a7db 100644 --- a/grub-core/kern/i386/pc/startup.S +++ b/grub-core/kern/i386/pc/startup.S @@ -465,7 +465,10 @@ FUNCTION(grub_exit) .code16 /* Tell the BIOS a boot failure. If this does not work, reboot. */ int $0x18 - jmp cold_reboot + /* set 0x472 to 0x0000 for cold boot (0x1234 for warm boot) */ + movw $0x0472, %di + movw %ax, (%di) + ljmp $0xf000, $0xfff0 .code32 /* diff --git a/grub-core/kern/i386/realmode.S b/grub-core/kern/i386/realmode.S index 578c8d2a8..3e8a13892 100644 --- a/grub-core/kern/i386/realmode.S +++ b/grub-core/kern/i386/realmode.S @@ -225,18 +225,3 @@ realcseg: DATA32 ret .code32 - -/* - * grub_reboot() - * - * Reboot the system. At the moment, rely on BIOS. - */ -FUNCTION(grub_reboot) - call prot_to_real - .code16 -cold_reboot: - /* set 0x472 to 0x0000 for cold boot (0x1234 for warm boot) */ - movw $0x0472, %di - movw %ax, (%di) - ljmp $0xf000, $0xfff0 - .code32 diff --git a/grub-core/kern/ieee1275/openfw.c b/grub-core/kern/ieee1275/openfw.c index 4e705a4d8..23065e3e3 100644 --- a/grub-core/kern/ieee1275/openfw.c +++ b/grub-core/kern/ieee1275/openfw.c @@ -456,16 +456,6 @@ grub_ieee1275_encode_devname (const char *path) return encoding; } -/* On i386, a firmware-independant grub_reboot() is provided by realmode.S. */ -#ifndef __i386__ -void -grub_reboot (void) -{ - grub_ieee1275_interpret ("reset-all", 0); - for (;;) ; -} -#endif - /* Resolve aliases. */ char * grub_ieee1275_canonicalise_devname (const char *path) diff --git a/grub-core/kern/mips/arc/init.c b/grub-core/kern/mips/arc/init.c index 2e25335ca..ec0fa521a 100644 --- a/grub-core/kern/mips/arc/init.c +++ b/grub-core/kern/mips/arc/init.c @@ -195,15 +195,3 @@ grub_exit (void) while (1); } -void -grub_reboot (void) -{ - GRUB_ARC_FIRMWARE_VECTOR->restart (); - - grub_millisleep (1500); - - grub_printf ("Reboot failed\n"); - grub_refresh (); - while (1); -} - diff --git a/grub-core/kern/mips/loongson/init.c b/grub-core/kern/mips/loongson/init.c index 8acfb0767..6ddf151f2 100644 --- a/grub-core/kern/mips/loongson/init.c +++ b/grub-core/kern/mips/loongson/init.c @@ -30,7 +30,6 @@ #include #include #include -#include #include extern void grub_video_sm712_init (void); @@ -266,37 +265,6 @@ grub_exit (void) grub_halt (); } -void -grub_reboot (void) -{ - switch (grub_arch_machine) - { - case GRUB_ARCH_MACHINE_FULOONG2E: - grub_outb (grub_inb (0xbfe00104) & ~4, 0xbfe00104); - grub_outb (grub_inb (0xbfe00104) | 4, 0xbfe00104); - break; - case GRUB_ARCH_MACHINE_FULOONG2F: - { - grub_pci_device_t dev; - if (!grub_cs5536_find (&dev)) - break; - grub_cs5536_write_msr (dev, GRUB_CS5536_MSR_DIVIL_RESET, - grub_cs5536_read_msr (dev, - GRUB_CS5536_MSR_DIVIL_RESET) - | 1); - break; - } - case GRUB_ARCH_MACHINE_YEELOONG: - grub_write_ec (GRUB_MACHINE_EC_COMMAND_REBOOT); - break; - } - grub_millisleep (1500); - - grub_printf ("Reboot failed\n"); - grub_refresh (); - while (1); -} - extern char _end[]; grub_addr_t grub_modbase = (grub_addr_t) _end; diff --git a/grub-core/kern/mips/qemu_mips/init.c b/grub-core/kern/mips/qemu_mips/init.c index 4921c42bf..d331e1b24 100644 --- a/grub-core/kern/mips/qemu_mips/init.c +++ b/grub-core/kern/mips/qemu_mips/init.c @@ -99,12 +99,6 @@ grub_halt (void) while (1); } -void -grub_reboot (void) -{ - while (1); -} - grub_err_t grub_machine_mmap_iterate (grub_memory_hook_t hook) { diff --git a/grub-core/lib/efi/reboot.c b/grub-core/lib/efi/reboot.c new file mode 100644 index 000000000..9382370f7 --- /dev/null +++ b/grub-core/lib/efi/reboot.c @@ -0,0 +1,32 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2011 Free Software Foundation, Inc. + * + * GRUB is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see . + */ + +#include +#include +#include +#include +#include + +void +grub_reboot (void) +{ + grub_machine_fini (); + efi_call_4 (grub_efi_system_table->runtime_services->reset_system, + GRUB_EFI_RESET_COLD, GRUB_EFI_SUCCESS, 0, NULL); + for (;;) ; +} diff --git a/grub-core/lib/i386/reboot.c b/grub-core/lib/i386/reboot.c new file mode 100644 index 000000000..ef28f7f65 --- /dev/null +++ b/grub-core/lib/i386/reboot.c @@ -0,0 +1,59 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2011 Free Software Foundation, Inc. + * + * GRUB is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see . + */ + +#include +#include +#include +#include +#include +#include + +void +grub_reboot (void) +{ + struct grub_relocator *relocator = NULL; + grub_relocator_chunk_t ch; + grub_err_t err; + void *buf; + struct grub_relocator16_state state; + grub_uint16_t segment; + + relocator = grub_relocator_new (); + if (!relocator) + while (1); + err = grub_relocator_alloc_chunk_align (relocator, &ch, 0x1000, 0x1000, + grub_reboot_end - grub_reboot_start, + 16, GRUB_RELOCATOR_PREFERENCE_NONE); + if (err) + while (1); + buf = get_virtual_current_address (ch); + grub_memcpy (buf, grub_reboot_start, grub_reboot_end - grub_reboot_start); + + segment = ((grub_addr_t) get_physical_target_address (ch)) >> 4; + state.gs = state.fs = state.es = state.ds = state.ss = segment; + state.sp = 0; + state.cs = segment; + state.ip = 0; + + grub_stop_floppy (); + + err = grub_relocator16_boot (relocator, state); + + while (1); +} + diff --git a/grub-core/lib/i386/reboot_trampoline.S b/grub-core/lib/i386/reboot_trampoline.S new file mode 100644 index 000000000..18bcfb287 --- /dev/null +++ b/grub-core/lib/i386/reboot_trampoline.S @@ -0,0 +1,33 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2011 Free Software Foundation, Inc. + * + * GRUB is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see . + */ + +#include +#include + + .p2align 4 + +VARIABLE(grub_reboot_start) + .code16 + + /* set 0x472 to 0x0000 for cold boot (0x1234 for warm boot) */ + movw $0x0472, %di + movw %ax, (%di) + ljmp $0xf000, $0xfff0 + + .code32 +VARIABLE(grub_reboot_end) diff --git a/grub-core/lib/ieee1275/reboot.c b/grub-core/lib/ieee1275/reboot.c new file mode 100644 index 000000000..91c8779f2 --- /dev/null +++ b/grub-core/lib/ieee1275/reboot.c @@ -0,0 +1,27 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2011 Free Software Foundation, Inc. + * + * GRUB is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see . + */ + +#include +#include + +void +grub_reboot (void) +{ + grub_ieee1275_interpret ("reset-all", 0); + for (;;) ; +} diff --git a/grub-core/lib/mips/arc/reboot.c b/grub-core/lib/mips/arc/reboot.c new file mode 100644 index 000000000..f0d085765 --- /dev/null +++ b/grub-core/lib/mips/arc/reboot.c @@ -0,0 +1,34 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2011 Free Software Foundation, Inc. + * + * GRUB is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see . + */ + +#include +#include +#include +#include + +void +grub_reboot (void) +{ + GRUB_ARC_FIRMWARE_VECTOR->restart (); + + grub_millisleep (1500); + + grub_printf ("Reboot failed\n"); + grub_refresh (); + while (1); +} diff --git a/grub-core/lib/mips/loongson/reboot.c b/grub-core/lib/mips/loongson/reboot.c new file mode 100644 index 000000000..f099ba250 --- /dev/null +++ b/grub-core/lib/mips/loongson/reboot.c @@ -0,0 +1,57 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2011 Free Software Foundation, Inc. + * + * GRUB is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see . + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +void +grub_reboot (void) +{ + switch (grub_arch_machine) + { + case GRUB_ARCH_MACHINE_FULOONG2E: + grub_outb (grub_inb (0xbfe00104) & ~4, 0xbfe00104); + grub_outb (grub_inb (0xbfe00104) | 4, 0xbfe00104); + break; + case GRUB_ARCH_MACHINE_FULOONG2F: + { + grub_pci_device_t dev; + if (!grub_cs5536_find (&dev)) + break; + grub_cs5536_write_msr (dev, GRUB_CS5536_MSR_DIVIL_RESET, + grub_cs5536_read_msr (dev, + GRUB_CS5536_MSR_DIVIL_RESET) + | 1); + break; + } + case GRUB_ARCH_MACHINE_YEELOONG: + grub_write_ec (GRUB_MACHINE_EC_COMMAND_REBOOT); + break; + } + grub_millisleep (1500); + + grub_printf ("Reboot failed\n"); + grub_refresh (); + while (1); +} diff --git a/grub-core/lib/mips/qemu_mips/reboot.c b/grub-core/lib/mips/qemu_mips/reboot.c new file mode 100644 index 000000000..a5c41ee78 --- /dev/null +++ b/grub-core/lib/mips/qemu_mips/reboot.c @@ -0,0 +1,25 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2011 Free Software Foundation, Inc. + * + * GRUB is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see . + */ + +#include + +void +grub_reboot (void) +{ + while (1); +} diff --git a/include/grub/emu/misc.h b/include/grub/emu/misc.h index fcf9da473..b4b8f7d28 100644 --- a/include/grub/emu/misc.h +++ b/include/grub/emu/misc.h @@ -82,4 +82,7 @@ int grub_device_mapper_supported (void); char *grub_find_root_device_from_mountinfo (const char *dir, char **relroot); +void EXPORT_FUNC(grub_reboot) (void); + + #endif /* GRUB_EMU_MISC_H */ diff --git a/include/grub/i386/reboot.h b/include/grub/i386/reboot.h new file mode 100644 index 000000000..c2716f3fa --- /dev/null +++ b/include/grub/i386/reboot.h @@ -0,0 +1,28 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2011 Free Software Foundation, Inc. + * + * GRUB is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see . + */ + +#ifndef GRUB_REBOOT_H +#define GRUB_REBOOT_H 1 + +#ifndef ASM_FILE + +extern grub_uint8_t grub_reboot_end[], grub_reboot_start[]; + +#endif + +#endif diff --git a/include/grub/mips/loongson/ec.h b/include/grub/mips/loongson/ec.h index 62d1d33d9..3f8ff9931 100644 --- a/include/grub/mips/loongson/ec.h +++ b/include/grub/mips/loongson/ec.h @@ -19,6 +19,10 @@ #ifndef GRUB_EC_MACHINE_HEADER #define GRUB_EC_MACHINE_HEADER 1 +#include +#include +#include + #define GRUB_MACHINE_EC_MAGIC_PORT1 0x381 #define GRUB_MACHINE_EC_MAGIC_PORT2 0x382 #define GRUB_MACHINE_EC_DATA_PORT 0x383 diff --git a/include/grub/mips/qemu_mips/kernel.h b/include/grub/mips/qemu_mips/kernel.h index 66add4b2e..1e7e32401 100644 --- a/include/grub/mips/qemu_mips/kernel.h +++ b/include/grub/mips/qemu_mips/kernel.h @@ -23,7 +23,6 @@ #ifndef ASM_FILE -void EXPORT_FUNC (grub_reboot) (void); void EXPORT_FUNC (grub_halt) (void); void grub_qemu_init_cirrus (void); diff --git a/include/grub/misc.h b/include/grub/misc.h index 66e74d8a8..0a0a4135e 100644 --- a/include/grub/misc.h +++ b/include/grub/misc.h @@ -343,7 +343,7 @@ grub_div_roundup (unsigned int x, unsigned int y) } /* Reboot the machine. */ -void EXPORT_FUNC (grub_reboot) (void) __attribute__ ((noreturn)); +void grub_reboot (void) __attribute__ ((noreturn)); #ifdef GRUB_MACHINE_PCBIOS /* Halt the system, using APM if possible. If NO_APM is true, don't From f8f72eb890273c7dc6cae48420d21a3d4e437213 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 19 Oct 2011 20:28:09 +0200 Subject: [PATCH 834/869] * grub-core/kern/ieee1275/openfw.c (grub_ieee1275_encode_devname): Don't add the bogus brackets. --- ChangeLog | 5 +++++ grub-core/kern/ieee1275/openfw.c | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index d66419216..ee678a9e3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-10-19 Vladimir Serbinenko + + * grub-core/kern/ieee1275/openfw.c (grub_ieee1275_encode_devname): + Don't add the bogus brackets. + 2011-10-19 Vladimir Serbinenko ExFAT support. diff --git a/grub-core/kern/ieee1275/openfw.c b/grub-core/kern/ieee1275/openfw.c index 23065e3e3..57252d96b 100644 --- a/grub-core/kern/ieee1275/openfw.c +++ b/grub-core/kern/ieee1275/openfw.c @@ -445,10 +445,10 @@ grub_ieee1275_encode_devname (const char *path) /* GRUB partition 1 is OF partition 0. */ partno++; - encoding = grub_xasprintf ("(%s,%d)", device, partno); + encoding = grub_xasprintf ("%s,%d", device, partno); } else - encoding = grub_xasprintf ("(%s)", device); + encoding = grub_strdup (device); grub_free (partition); grub_free (device); From 36dd20ad0bc2bd9b46ce48cc0425512018cac21f Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 19 Oct 2011 20:30:06 +0200 Subject: [PATCH 835/869] * grub-core/kern/main.c (grub_set_prefix_and_root): Init prefix. --- ChangeLog | 4 ++++ grub-core/kern/main.c | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index ee678a9e3..6210a4eab 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2011-10-19 Vladimir Serbinenko + + * grub-core/kern/main.c (grub_set_prefix_and_root): Init prefix. + 2011-10-19 Vladimir Serbinenko * grub-core/kern/ieee1275/openfw.c (grub_ieee1275_encode_devname): diff --git a/grub-core/kern/main.c b/grub-core/kern/main.c index 77be11422..bf2789860 100644 --- a/grub-core/kern/main.c +++ b/grub-core/kern/main.c @@ -105,7 +105,7 @@ grub_set_prefix_and_root (void) char *path = NULL; char *fwdevice = NULL; char *fwpath = NULL; - char *prefix; + char *prefix = NULL; struct grub_module_header *header; FOR_MODULES (header) From e55599dcbf2f4773674995703cbf1a71cba3e355 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 19 Oct 2011 20:35:41 +0200 Subject: [PATCH 836/869] * util/grub-install.in: Declare IEEE1275 as able to find out the disk name. --- ChangeLog | 5 +++++ util/grub-install.in | 6 +++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 6210a4eab..afbc8aec7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-10-19 Vladimir Serbinenko + + * util/grub-install.in: Declare IEEE1275 as able to find out the disk + name. + 2011-10-19 Vladimir Serbinenko * grub-core/kern/main.c (grub_set_prefix_and_root): Init prefix. diff --git a/util/grub-install.in b/util/grub-install.in index d11d24421..e1255f4f7 100644 --- a/util/grub-install.in +++ b/util/grub-install.in @@ -544,11 +544,11 @@ if [ "x${devabstraction_module}" = "x" ] ; then # Strip partition number grub_partition="`echo "${grub_drive}" | sed -e 's/^[^,]*[,)]//; s/)$//'`" grub_drive="`echo "${grub_drive}" | sed -e s/,[a-z0-9,]*//g`" - if ([ "x$disk_module" != x ] && [ "x$disk_module" != xbiosdisk ]) || [ "x${grub_drive}" != "x${install_drive}" ] || ([ "x$platform" != xefi ] && [ "x$platform" != xpc ] && [ x"${target_cpu}-${platform}" != x"sparc64-ieee1275" ]); then + if ([ "x$disk_module" != x ] && [ "x$disk_module" != xbiosdisk ]) || [ "x${grub_drive}" != "x${install_drive}" ] || ([ "x$platform" != xefi ] && [ "x$platform" != xpc ] && [ x"${platform}" != x"ieee1275" ]); then # generic method (used on coreboot and ata mod) uuid="`"$grub_probe" --device-map="${device_map}" --target=fs_uuid --device "${grub_device}"`" if [ "x${uuid}" = "x" ] ; then - if [ "x$platform" != xefi ] && [ "x$platform" != xpc ] && [ x"${target_cpu}-${platform}" != x"sparc64-ieee1275" ]; then + if [ "x$platform" != xefi ] && [ "x$platform" != xpc ] && [ x"${platform}" != x"ieee1275" ]; then echo "UUID needed with $platform, but the filesystem containing ${grubdir} does not support UUIDs." 1>&2 elif [ "$disk_module" = ata ]; then echo "UUID needed with ata mod, but the filesystem containing ${grubdir} does not support UUIDs." 1>&2 @@ -563,7 +563,7 @@ if [ "x${devabstraction_module}" = "x" ] ; then echo 'set prefix=($root)'"${relative_grubdir}" >> "${grubdir}/load.cfg" config_opt="-c ${grubdir}/load.cfg " modules="$modules search_fs_uuid" - elif [ "x$platform" = xefi ] || [ "x$platform" = xpc ]; then + elif [ "x$platform" = xefi ] || [ "x$platform" = xpc ] || [ "x$platform" = xieee1275 ]; then # we need to hardcode the partition number in the core image's prefix. if [ x"$grub_partition" = x ]; then prefix_drive="()" From de9c615e5c5b9d692ac00be91b16a0576a371e25 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 19 Oct 2011 23:01:44 +0200 Subject: [PATCH 837/869] Removed unused GRUB_BOOT_VERSION. Check for kernel version is better done with a dedicated section. * grub-core/boot/sparc64/ieee1275/boot.S: Remove GRUB_BOOT_VERSION. Ensure the correct position of boot_path. * grub-core/kern/i386/efi/startup.S: Remove GRUB_BOOT_VERSION. * grub-core/kern/i386/pc/startup.S: Likewise. Ensure correct position of other fields. * grub-core/kern/x86_64/efi/startup.S: Remove GRUB_BOOT_VERSION. * include/grub/boot.h: Removed. All references removed. * include/grub/sparc64/ieee1275/boot.h (GRUB_BOOT_MACHINE_VER_MAJ): Removed. (GRUB_BOOT_MACHINE_BOOT_DEVPATH): Make it lower. --- ChangeLog | 16 +++++++++++++ grub-core/Makefile.am | 1 - grub-core/boot/i386/pc/boot.S | 1 - grub-core/boot/i386/pc/cdboot.S | 1 - grub-core/boot/i386/pc/lnxboot.S | 1 - grub-core/boot/sparc64/ieee1275/boot.S | 5 +--- grub-core/boot/sparc64/ieee1275/diskboot.S | 1 - grub-core/kern/i386/efi/startup.S | 17 -------------- grub-core/kern/i386/pc/startup.S | 19 ++++++--------- grub-core/kern/x86_64/efi/callwrap.S | 1 - grub-core/kern/x86_64/efi/startup.S | 13 ----------- include/grub/boot.h | 27 ---------------------- include/grub/sparc64/ieee1275/boot.h | 4 +--- 13 files changed, 25 insertions(+), 82 deletions(-) delete mode 100644 include/grub/boot.h diff --git a/ChangeLog b/ChangeLog index afbc8aec7..1159d32a5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,19 @@ +2011-10-19 Vladimir Serbinenko + + Removed unused GRUB_BOOT_VERSION. Check for kernel version is better + done with a dedicated section. + + * grub-core/boot/sparc64/ieee1275/boot.S: Remove GRUB_BOOT_VERSION. + Ensure the correct position of boot_path. + * grub-core/kern/i386/efi/startup.S: Remove GRUB_BOOT_VERSION. + * grub-core/kern/i386/pc/startup.S: Likewise. Ensure correct position of + other fields. + * grub-core/kern/x86_64/efi/startup.S: Remove GRUB_BOOT_VERSION. + * include/grub/boot.h: Removed. All references removed. + * include/grub/sparc64/ieee1275/boot.h (GRUB_BOOT_MACHINE_VER_MAJ): + Removed. + (GRUB_BOOT_MACHINE_BOOT_DEVPATH): Make it lower. + 2011-10-19 Vladimir Serbinenko * util/grub-install.in: Declare IEEE1275 as able to find out the disk diff --git a/grub-core/Makefile.am b/grub-core/Makefile.am index f30014635..3bd192602 100644 --- a/grub-core/Makefile.am +++ b/grub-core/Makefile.am @@ -78,7 +78,6 @@ KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/partition.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/term.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/time.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/mm_private.h -KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/boot.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/net.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/libgcc.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/memory.h diff --git a/grub-core/boot/i386/pc/boot.S b/grub-core/boot/i386/pc/boot.S index 635599a24..314f14016 100644 --- a/grub-core/boot/i386/pc/boot.S +++ b/grub-core/boot/i386/pc/boot.S @@ -18,7 +18,6 @@ */ #include -#include #include /* diff --git a/grub-core/boot/i386/pc/cdboot.S b/grub-core/boot/i386/pc/cdboot.S index 33569ce9d..d939835a9 100644 --- a/grub-core/boot/i386/pc/cdboot.S +++ b/grub-core/boot/i386/pc/cdboot.S @@ -18,7 +18,6 @@ */ #include -#include #include #include #include diff --git a/grub-core/boot/i386/pc/lnxboot.S b/grub-core/boot/i386/pc/lnxboot.S index 2c7596026..bb43ed73c 100644 --- a/grub-core/boot/i386/pc/lnxboot.S +++ b/grub-core/boot/i386/pc/lnxboot.S @@ -19,7 +19,6 @@ #include #include -#include #include #include #include diff --git a/grub-core/boot/sparc64/ieee1275/boot.S b/grub-core/boot/sparc64/ieee1275/boot.S index f08258f47..f79699502 100644 --- a/grub-core/boot/sparc64/ieee1275/boot.S +++ b/grub-core/boot/sparc64/ieee1275/boot.S @@ -17,7 +17,6 @@ * along with GRUB. If not, see . */ -#include #include .text @@ -29,9 +28,6 @@ pic_base: call boot_continue mov %o4, CIF_REG - . = _start + GRUB_BOOT_MACHINE_VER_MAJ -boot_version: .byte GRUB_BOOT_VERSION_MAJOR, GRUB_BOOT_VERSION_MINOR - /* The offsets to these locations are defined by the * GRUB_BOOT_MACHINE_foo macros in include/grub/sparc/ieee1275/boot.h, * and grub-setup uses this to patch these next three values as needed. @@ -44,6 +40,7 @@ boot_version: .byte GRUB_BOOT_VERSION_MAJOR, GRUB_BOOT_VERSION_MINOR * After loading in that block we will execute it by jumping to the * load address plus the size of the prepended A.OUT header (32 bytes). */ + . = _start + GRUB_BOOT_MACHINE_BOOT_DEVPATH boot_path: . = _start + GRUB_BOOT_MACHINE_KERNEL_BYTE boot_path_end: diff --git a/grub-core/boot/sparc64/ieee1275/diskboot.S b/grub-core/boot/sparc64/ieee1275/diskboot.S index 83dfee098..e020f6221 100644 --- a/grub-core/boot/sparc64/ieee1275/diskboot.S +++ b/grub-core/boot/sparc64/ieee1275/diskboot.S @@ -17,7 +17,6 @@ * along with GRUB. If not, see . */ -#include #include #include diff --git a/grub-core/kern/i386/efi/startup.S b/grub-core/kern/i386/efi/startup.S index 0f904d7b3..fc5ea3dac 100644 --- a/grub-core/kern/i386/efi/startup.S +++ b/grub-core/kern/i386/efi/startup.S @@ -19,29 +19,12 @@ #include #include -#include .file "startup.S" .text .globl start, _start start: _start: - jmp codestart - - /* - * Compatibility version number - * - * These MUST be at byte offset 6 and 7 of the executable - * DO NOT MOVE !!! - */ - . = _start + 0x6 - .byte GRUB_BOOT_VERSION_MAJOR, GRUB_BOOT_VERSION_MINOR - - /* - * This is a special data area 8 bytes from the beginning. - */ - -codestart: /* * EFI_SYSTEM_TABLE * and EFI_HANDLE are passed on the stack. */ diff --git a/grub-core/kern/i386/pc/startup.S b/grub-core/kern/i386/pc/startup.S index a70a2a7db..0350431d9 100644 --- a/grub-core/kern/i386/pc/startup.S +++ b/grub-core/kern/i386/pc/startup.S @@ -43,7 +43,6 @@ #include #include -#include #include #include #include @@ -75,31 +74,27 @@ LOCAL (base): #else ljmp $0, $ABS(LOCAL (codestart)) #endif - /* - * Compatibility version number - * - * These MUST be at byte offset 6 and 7 of the executable - * DO NOT MOVE !!! - */ - . = _start + 0x6 - .byte GRUB_BOOT_VERSION_MAJOR, GRUB_BOOT_VERSION_MINOR /* - * This is a special data area 8 bytes from the beginning. + * This is a special data area. */ - . = _start + 0x8 - + . = _start + GRUB_KERNEL_I386_PC_TOTAL_MODULE_SIZE VARIABLE(grub_total_module_size) .long 0 + . = _start + GRUB_KERNEL_I386_PC_KERNEL_IMAGE_SIZE VARIABLE(grub_kernel_image_size) .long 0 + . = _start + GRUB_KERNEL_I386_PC_COMPRESSED_SIZE VARIABLE(grub_compressed_size) .long 0 + . = _start + GRUB_KERNEL_I386_PC_INSTALL_DOS_PART VARIABLE(grub_install_dos_part) .long 0xFFFFFFFF + . = _start + GRUB_KERNEL_I386_PC_INSTALL_BSD_PART VARIABLE(grub_install_bsd_part) .long 0xFFFFFFFF + . = _start + GRUB_KERNEL_I386_PC_REED_SOLOMON_REDUNDANCY reed_solomon_redundancy: .long 0 diff --git a/grub-core/kern/x86_64/efi/callwrap.S b/grub-core/kern/x86_64/efi/callwrap.S index cc2c8aa05..dced859ac 100644 --- a/grub-core/kern/x86_64/efi/callwrap.S +++ b/grub-core/kern/x86_64/efi/callwrap.S @@ -19,7 +19,6 @@ #include #include -#include /* * x86_64 uses registry to pass parameters. Unfortunately, gcc and efi use diff --git a/grub-core/kern/x86_64/efi/startup.S b/grub-core/kern/x86_64/efi/startup.S index 37efde7fc..f86f01969 100644 --- a/grub-core/kern/x86_64/efi/startup.S +++ b/grub-core/kern/x86_64/efi/startup.S @@ -19,7 +19,6 @@ #include #include -#include .file "startup.S" .text @@ -28,18 +27,6 @@ start: _start: - jmp codestart - - /* - * Compatibility version number - * - * These MUST be at byte offset 6 and 7 of the executable - * DO NOT MOVE !!! - */ - . = _start + 0x6 - .byte GRUB_BOOT_VERSION_MAJOR, GRUB_BOOT_VERSION_MINOR - -codestart: movq %rcx, EXT_C(grub_efi_image_handle)(%rip) movq %rdx, EXT_C(grub_efi_system_table)(%rip) diff --git a/include/grub/boot.h b/include/grub/boot.h deleted file mode 100644 index 235774863..000000000 --- a/include/grub/boot.h +++ /dev/null @@ -1,27 +0,0 @@ -/* - * GRUB -- GRand Unified Bootloader - * Copyright (C) 2002,2007 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 . - */ - -#ifndef GRUB_BOOT_HEADER -#define GRUB_BOOT_HEADER 1 - -#define GRUB_BOOT_VERSION_MAJOR 4 -#define GRUB_BOOT_VERSION_MINOR 0 -#define GRUB_BOOT_VERSION ((GRUB_BOOT_VERSION_MINOR << 8) \ - | GRUB_BOOT_VERSION_MAJOR) - -#endif /* ! GRUB_BOOT_HEADER */ diff --git a/include/grub/sparc64/ieee1275/boot.h b/include/grub/sparc64/ieee1275/boot.h index 112d19bc7..60edc712e 100644 --- a/include/grub/sparc64/ieee1275/boot.h +++ b/include/grub/sparc64/ieee1275/boot.h @@ -39,9 +39,7 @@ #define GRUB_BOOT_MACHINE_SIGNATURE 0xbb44aa55 -#define GRUB_BOOT_MACHINE_VER_MAJ 0x08 - -#define GRUB_BOOT_MACHINE_BOOT_DEVPATH 0x0a +#define GRUB_BOOT_MACHINE_BOOT_DEVPATH 0x08 #define GRUB_BOOT_MACHINE_BOOT_DEVPATH_END 0x80 From fcf1d67219695832a42525d3f9c9dc0730e72bf5 Mon Sep 17 00:00:00 2001 From: Szymon Janc Date: Wed, 19 Oct 2011 23:11:48 +0200 Subject: [PATCH 838/869] * grub-core/bus/usb/uhci.c (grub_uhci_setup_transfer): Fix possible NULL pointer dereference. --- ChangeLog | 5 +++++ grub-core/bus/usb/uhci.c | 7 +++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1159d32a5..96abe1229 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-10-19 Szymon Janc + + * grub-core/bus/usb/uhci.c (grub_uhci_setup_transfer): Fix possible + NULL pointer dereference. + 2011-10-19 Vladimir Serbinenko Removed unused GRUB_BOOT_VERSION. Check for kernel version is better diff --git a/grub-core/bus/usb/uhci.c b/grub-core/bus/usb/uhci.c index 260b7e876..a9a4c45a2 100644 --- a/grub-core/bus/usb/uhci.c +++ b/grub-core/bus/usb/uhci.c @@ -544,8 +544,11 @@ grub_uhci_setup_transfer (grub_usb_controller_t dev, { grub_size_t actual = 0; /* Terminate and free. */ - td_prev->linkptr2 = 0; - td_prev->linkptr = 1; + if (td_prev) + { + td_prev->linkptr2 = 0; + td_prev->linkptr = 1; + } if (cdata->td_first) grub_free_queue (u, cdata->qh, cdata->td_first, NULL, &actual); From 766f7d08092a0904cb00af1b419fb8b8edcdb51b Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Thu, 20 Oct 2011 08:13:00 +0200 Subject: [PATCH 839/869] Remove redundant grub_kernel_image_size. * grub-core/kern/i386/coreboot/init.c (grub_machine_init): Use _edata and _start. * grub-core/kern/i386/coreboot/startup.S: Move multiboot header after the small code. It moves it only by few bytes but simplifies the code. * grub-core/kern/i386/pc/init.c (grub_machine_init): Use _edata and _start. * grub-core/kern/i386/pc/startup.S: Use _edata and _start. (grub_kernel_image_size): Removed. * grub-core/kern/i386/qemu/startup.S: Use _edata and _start. (grub_kernel_image_size): Removed. [APPLE_CC]: Remove apple compiler support. i386-qemu port can't be compiled with Apple toolchain. * grub-core/kern/sparc64/ieee1275/crt0.S: Remove leftover fields. * include/grub/i386/pc/kernel.h (grub_kernel_image_size): Removed. * include/grub/i386/qemu/kernel.h (grub_kernel_image_size): Removed. (grub_total_module_size): Likewise. * include/grub/offsets.h (GRUB_KERNEL_I386_PC_KERNEL_IMAGE_SIZE): Removed. (GRUB_KERNEL_I386_PC_COMPRESSED_SIZE): Put it lower. (GRUB_KERNEL_I386_PC_INSTALL_DOS_PART): Likewise. (GRUB_KERNEL_I386_PC_INSTALL_BSD_PART): Likewise. (GRUB_KERNEL_I386_PC_REED_SOLOMON_REDUNDANCY): Likewise. (GRUB_KERNEL_I386_QEMU_KERNEL_IMAGE_SIZE): Removed. (GRUB_KERNEL_SPARC64_IEEE1275_KERNEL_IMAGE_SIZE): Likewise. (GRUB_KERNEL_SPARC64_IEEE1275_COMPRESSED_SIZE): Likewise. * include/grub/sparc64/ieee1275/kernel.h (grub_kernel_image_size): Removed. (grub_total_module_size): Removed. * util/grub-mkimage.c (image_target_desc): Remove image_size. (image_targets): Likewise. Set .compressed_size to no field on sparc. (generate_image): Remove kernel_image_size handling. --- ChangeLog | 37 ++++++++++++++++++++++++++ grub-core/kern/i386/coreboot/init.c | 7 ++--- grub-core/kern/i386/coreboot/startup.S | 27 +++++++++---------- grub-core/kern/i386/pc/init.c | 3 ++- grub-core/kern/i386/pc/startup.S | 5 +--- grub-core/kern/i386/qemu/startup.S | 20 +------------- grub-core/kern/sparc64/ieee1275/crt0.S | 4 --- include/grub/i386/pc/kernel.h | 3 --- include/grub/i386/qemu/kernel.h | 6 ----- include/grub/offsets.h | 20 +++----------- include/grub/sparc64/ieee1275/kernel.h | 6 ----- util/grub-mkimage.c | 28 ++----------------- 12 files changed, 63 insertions(+), 103 deletions(-) diff --git a/ChangeLog b/ChangeLog index 96abe1229..bf96dc095 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,40 @@ +2011-10-20 Vladimir Serbinenko + + Remove redundant grub_kernel_image_size. + + * grub-core/kern/i386/coreboot/init.c (grub_machine_init): Use + _edata and _start. + * grub-core/kern/i386/coreboot/startup.S: Move multiboot header after + the small code. It moves it only by few bytes but simplifies the code. + * grub-core/kern/i386/pc/init.c (grub_machine_init): Use _edata and + _start. + * grub-core/kern/i386/pc/startup.S: Use _edata and _start. + (grub_kernel_image_size): Removed. + * grub-core/kern/i386/qemu/startup.S: Use _edata and _start. + (grub_kernel_image_size): Removed. + [APPLE_CC]: Remove apple compiler support. i386-qemu port can't be + compiled with Apple toolchain. + * grub-core/kern/sparc64/ieee1275/crt0.S: Remove leftover fields. + * include/grub/i386/pc/kernel.h (grub_kernel_image_size): Removed. + * include/grub/i386/qemu/kernel.h (grub_kernel_image_size): Removed. + (grub_total_module_size): Likewise. + * include/grub/offsets.h (GRUB_KERNEL_I386_PC_KERNEL_IMAGE_SIZE): + Removed. + (GRUB_KERNEL_I386_PC_COMPRESSED_SIZE): Put it lower. + (GRUB_KERNEL_I386_PC_INSTALL_DOS_PART): Likewise. + (GRUB_KERNEL_I386_PC_INSTALL_BSD_PART): Likewise. + (GRUB_KERNEL_I386_PC_REED_SOLOMON_REDUNDANCY): Likewise. + (GRUB_KERNEL_I386_QEMU_KERNEL_IMAGE_SIZE): Removed. + (GRUB_KERNEL_SPARC64_IEEE1275_KERNEL_IMAGE_SIZE): Likewise. + (GRUB_KERNEL_SPARC64_IEEE1275_COMPRESSED_SIZE): Likewise. + * include/grub/sparc64/ieee1275/kernel.h (grub_kernel_image_size): + Removed. + (grub_total_module_size): Removed. + * util/grub-mkimage.c (image_target_desc): Remove image_size. + (image_targets): Likewise. + Set .compressed_size to no field on sparc. + (generate_image): Remove kernel_image_size handling. + 2011-10-19 Szymon Janc * grub-core/bus/usb/uhci.c (grub_uhci_setup_transfer): Fix possible diff --git a/grub-core/kern/i386/coreboot/init.c b/grub-core/kern/i386/coreboot/init.c index b7510ff98..95209bb70 100644 --- a/grub-core/kern/i386/coreboot/init.c +++ b/grub-core/kern/i386/coreboot/init.c @@ -38,8 +38,9 @@ #include #endif -extern char _start[]; -extern char _end[]; +extern grub_uint8_t _start[]; +extern grub_uint8_t _end[]; +extern grub_uint8_t _edata[]; grub_uint32_t grub_get_rtc (void) @@ -66,7 +67,7 @@ void grub_machine_init (void) { #ifdef GRUB_MACHINE_QEMU - grub_modbase = grub_core_entry_addr + grub_kernel_image_size; + grub_modbase = grub_core_entry_addr + (_edata - _start); grub_qemu_init_cirrus (); #endif diff --git a/grub-core/kern/i386/coreboot/startup.S b/grub-core/kern/i386/coreboot/startup.S index 5e7767bb9..dc2c62a25 100644 --- a/grub-core/kern/i386/coreboot/startup.S +++ b/grub-core/kern/i386/coreboot/startup.S @@ -38,21 +38,6 @@ .globl start, _start start: _start: - jmp codestart - -/* - * Support for booting GRUB from a Multiboot boot loader (e.g. GRUB itself). - */ - .p2align 2 /* force 4-byte alignment */ -multiboot_header: - /* magic */ - .long 0x1BADB002 - /* flags */ - .long MULTIBOOT_MEMORY_INFO - /* checksum */ - .long -0x1BADB002 - MULTIBOOT_MEMORY_INFO - -codestart: #ifdef GRUB_MACHINE_MULTIBOOT cmpl $MULTIBOOT_BOOTLOADER_MAGIC, %eax jne 0f @@ -66,6 +51,18 @@ codestart: /* jump to the main body of C code */ jmp EXT_C(grub_main) +/* + * Support for booting GRUB from a Multiboot boot loader (e.g. GRUB itself). + */ + .p2align 2 /* force 4-byte alignment */ +multiboot_header: + /* magic */ + .long 0x1BADB002 + /* flags */ + .long MULTIBOOT_MEMORY_INFO + /* checksum */ + .long -0x1BADB002 - MULTIBOOT_MEMORY_INFO + /* * prot_to_real and associated structures (but NOT real_to_prot, that is * only needed for BIOS gates). diff --git a/grub-core/kern/i386/pc/init.c b/grub-core/kern/i386/pc/init.c index 62269de78..be26fdea1 100644 --- a/grub-core/kern/i386/pc/init.c +++ b/grub-core/kern/i386/pc/init.c @@ -130,6 +130,7 @@ compact_mem_regions (void) } grub_addr_t grub_modbase; +extern grub_uint8_t _start[], _edata[]; void grub_machine_init (void) @@ -140,7 +141,7 @@ grub_machine_init (void) #endif grub_modbase = GRUB_MEMORY_MACHINE_DECOMPRESSION_ADDR - + (grub_kernel_image_size - GRUB_KERNEL_MACHINE_RAW_SIZE); + + ((_edata - _start) - GRUB_KERNEL_MACHINE_RAW_SIZE); /* Initialize the console as early as possible. */ grub_console_init (); diff --git a/grub-core/kern/i386/pc/startup.S b/grub-core/kern/i386/pc/startup.S index 0350431d9..a0ef71f90 100644 --- a/grub-core/kern/i386/pc/startup.S +++ b/grub-core/kern/i386/pc/startup.S @@ -81,9 +81,6 @@ LOCAL (base): . = _start + GRUB_KERNEL_I386_PC_TOTAL_MODULE_SIZE VARIABLE(grub_total_module_size) - .long 0 - . = _start + GRUB_KERNEL_I386_PC_KERNEL_IMAGE_SIZE -VARIABLE(grub_kernel_image_size) .long 0 . = _start + GRUB_KERNEL_I386_PC_COMPRESSED_SIZE VARIABLE(grub_compressed_size) @@ -226,7 +223,7 @@ post_reed_solomon: movl $(_start + GRUB_KERNEL_MACHINE_RAW_SIZE), %esi pushl %edi pushl %esi - movl EXT_C(grub_kernel_image_size), %ecx + movl $(BSS_START_SYMBOL - _start), %ecx addl EXT_C(grub_total_module_size), %ecx subl $GRUB_KERNEL_MACHINE_RAW_SIZE, %ecx pushl %ecx diff --git a/grub-core/kern/i386/qemu/startup.S b/grub-core/kern/i386/qemu/startup.S index 6500de620..0761807ed 100644 --- a/grub-core/kern/i386/qemu/startup.S +++ b/grub-core/kern/i386/qemu/startup.S @@ -32,8 +32,6 @@ _start: . = _start + GRUB_KERNEL_I386_QEMU_CORE_ENTRY_ADDR VARIABLE(grub_core_entry_addr) .long 0 -VARIABLE(grub_kernel_image_size) - .long 0 codestart: /* Relocate to low memory. First we figure out our location. @@ -45,11 +43,7 @@ codestart: value of `grub_core_entry_addr' in %esi. */ xorw %si, %si - /* ... which allows us to access `grub_kernel_image_size' - before relocation. */ - movl (grub_kernel_image_size - _start)(%esi), %ecx - - + movl $(_edata - _start), %ecx movl $_start, %edi cld rep @@ -57,24 +51,12 @@ codestart: ljmp $GRUB_MEMORY_MACHINE_PROT_MODE_CSEG, $1f 1: -#ifdef APPLE_CC - /* clean out the bss */ - bss_start_abs = ABS (bss_start) - bss_end_abs = ABS (bss_end) - - movl bss_start_abs, %edi - - /* compute the bss length */ - movl bss_end_abs, %ecx - subl %edi, %ecx -#else /* clean out the bss */ movl $BSS_START_SYMBOL, %edi /* compute the bss length */ movl $END_SYMBOL, %ecx subl %edi, %ecx -#endif /* clean out */ xorl %eax, %eax diff --git a/grub-core/kern/sparc64/ieee1275/crt0.S b/grub-core/kern/sparc64/ieee1275/crt0.S index 1466a56f8..9d91fba48 100644 --- a/grub-core/kern/sparc64/ieee1275/crt0.S +++ b/grub-core/kern/sparc64/ieee1275/crt0.S @@ -31,10 +31,6 @@ _start: VARIABLE(grub_total_module_size) .word 0 -VARIABLE(grub_kernel_image_size) - .word 0 -VARIABLE(grub_compressed_size) - .word 0 codestart: /* Copy the modules past the end of the kernel image. diff --git a/include/grub/i386/pc/kernel.h b/include/grub/i386/pc/kernel.h index dd50aa833..2dcdbb7a6 100644 --- a/include/grub/i386/pc/kernel.h +++ b/include/grub/i386/pc/kernel.h @@ -29,9 +29,6 @@ #include #include -/* The size of kernel image. */ -extern grub_int32_t grub_kernel_image_size; - /* The total size of module images following the kernel. */ extern grub_int32_t grub_total_module_size; diff --git a/include/grub/i386/qemu/kernel.h b/include/grub/i386/qemu/kernel.h index df06e6731..f34206b3a 100644 --- a/include/grub/i386/qemu/kernel.h +++ b/include/grub/i386/qemu/kernel.h @@ -28,12 +28,6 @@ extern grub_addr_t grub_core_entry_addr; -/* The size of kernel image. */ -extern grub_int32_t grub_kernel_image_size; - -/* The total size of module images following the kernel. */ -extern grub_int32_t grub_total_module_size; - void grub_qemu_init_cirrus (void); #endif /* ! ASM_FILE */ diff --git a/include/grub/offsets.h b/include/grub/offsets.h index 526cfee68..aa65cd5cc 100644 --- a/include/grub/offsets.h +++ b/include/grub/offsets.h @@ -22,20 +22,17 @@ /* The offset of GRUB_TOTAL_MODULE_SIZE. */ #define GRUB_KERNEL_I386_PC_TOTAL_MODULE_SIZE 0x8 -/* The offset of GRUB_KERNEL_IMAGE_SIZE. */ -#define GRUB_KERNEL_I386_PC_KERNEL_IMAGE_SIZE 0xc - /* The offset of GRUB_COMPRESSED_SIZE. */ -#define GRUB_KERNEL_I386_PC_COMPRESSED_SIZE 0x10 +#define GRUB_KERNEL_I386_PC_COMPRESSED_SIZE 0x0c /* The offset of GRUB_INSTALL_DOS_PART. */ -#define GRUB_KERNEL_I386_PC_INSTALL_DOS_PART 0x14 +#define GRUB_KERNEL_I386_PC_INSTALL_DOS_PART 0x10 /* The offset of GRUB_INSTALL_BSD_PART. */ -#define GRUB_KERNEL_I386_PC_INSTALL_BSD_PART 0x18 +#define GRUB_KERNEL_I386_PC_INSTALL_BSD_PART 0x14 /* Offset of reed_solomon_redundancy. */ -#define GRUB_KERNEL_I386_PC_REED_SOLOMON_REDUNDANCY 0x1c +#define GRUB_KERNEL_I386_PC_REED_SOLOMON_REDUNDANCY 0x18 /* The size of the first region which won't be compressed. */ #define GRUB_KERNEL_I386_PC_RAW_SIZE 0xcd0 @@ -57,20 +54,11 @@ /* The offset of GRUB_CORE_ENTRY_ADDR. */ #define GRUB_KERNEL_I386_QEMU_CORE_ENTRY_ADDR 0x8 -/* The offset of GRUB_KERNEL_IMAGE_SIZE. */ -#define GRUB_KERNEL_I386_QEMU_KERNEL_IMAGE_SIZE 0xc - #define GRUB_KERNEL_I386_QEMU_LINK_ADDR 0x8200 /* The offset of GRUB_TOTAL_MODULE_SIZE. */ #define GRUB_KERNEL_SPARC64_IEEE1275_TOTAL_MODULE_SIZE 0x8 -/* The offset of GRUB_KERNEL_IMAGE_SIZE. */ -#define GRUB_KERNEL_SPARC64_IEEE1275_KERNEL_IMAGE_SIZE 0xc - -/* The offset of GRUB_COMPRESSED_SIZE. */ -#define GRUB_KERNEL_SPARC64_IEEE1275_COMPRESSED_SIZE 0x10 - #define GRUB_BOOT_SPARC64_IEEE1275_LIST_SIZE 12 #define GRUB_BOOT_SPARC64_IEEE1275_IMAGE_ADDRESS 0x4400 diff --git a/include/grub/sparc64/ieee1275/kernel.h b/include/grub/sparc64/ieee1275/kernel.h index 5aa50b852..9a00bea61 100644 --- a/include/grub/sparc64/ieee1275/kernel.h +++ b/include/grub/sparc64/ieee1275/kernel.h @@ -26,12 +26,6 @@ #include #include -/* The size of kernel image. */ -extern grub_int32_t grub_kernel_image_size; - -/* The total size of module images following the kernel. */ -extern grub_int32_t grub_total_module_size; - #endif /* ! ASM_FILE */ #endif /* ! GRUB_KERNEL_MACHINE_HEADER */ diff --git a/util/grub-mkimage.c b/util/grub-mkimage.c index 4440fdd12..fb1c5babe 100644 --- a/util/grub-mkimage.c +++ b/util/grub-mkimage.c @@ -79,7 +79,6 @@ struct image_target_desc } flags; unsigned raw_size; unsigned total_module_size; - unsigned kernel_image_size; unsigned compressed_size; unsigned link_align; grub_uint16_t elf_target; @@ -110,7 +109,6 @@ struct image_target_desc image_targets[] = .flags = PLATFORM_FLAGS_NONE, .raw_size = 0, .total_module_size = TARGET_NO_FIELD, - .kernel_image_size = TARGET_NO_FIELD, .compressed_size = TARGET_NO_FIELD, .section_align = 1, .vaddr_offset = 0, @@ -131,7 +129,6 @@ struct image_target_desc image_targets[] = .flags = PLATFORM_FLAGS_NONE, .raw_size = 0, .total_module_size = TARGET_NO_FIELD, - .kernel_image_size = TARGET_NO_FIELD, .compressed_size = TARGET_NO_FIELD, .section_align = 1, .vaddr_offset = 0, @@ -152,7 +149,6 @@ struct image_target_desc image_targets[] = .flags = PLATFORM_FLAGS_LZMA, .raw_size = GRUB_KERNEL_I386_PC_RAW_SIZE, .total_module_size = GRUB_KERNEL_I386_PC_TOTAL_MODULE_SIZE, - .kernel_image_size = GRUB_KERNEL_I386_PC_KERNEL_IMAGE_SIZE, .compressed_size = GRUB_KERNEL_I386_PC_COMPRESSED_SIZE, .section_align = 1, .vaddr_offset = 0, @@ -169,7 +165,6 @@ struct image_target_desc image_targets[] = .flags = PLATFORM_FLAGS_LZMA, .raw_size = GRUB_KERNEL_I386_PC_RAW_SIZE, .total_module_size = GRUB_KERNEL_I386_PC_TOTAL_MODULE_SIZE, - .kernel_image_size = GRUB_KERNEL_I386_PC_KERNEL_IMAGE_SIZE, .compressed_size = GRUB_KERNEL_I386_PC_COMPRESSED_SIZE, .section_align = 1, .vaddr_offset = 0, @@ -186,7 +181,6 @@ struct image_target_desc image_targets[] = .flags = PLATFORM_FLAGS_NONE, .raw_size = 0, .total_module_size = TARGET_NO_FIELD, - .kernel_image_size = TARGET_NO_FIELD, .compressed_size = TARGET_NO_FIELD, .section_align = GRUB_PE32_SECTION_ALIGNMENT, .vaddr_offset = ALIGN_UP (GRUB_PE32_MSDOS_STUB_SIZE @@ -209,7 +203,6 @@ struct image_target_desc image_targets[] = .flags = PLATFORM_FLAGS_NONE, .raw_size = 0, .total_module_size = TARGET_NO_FIELD, - .kernel_image_size = TARGET_NO_FIELD, .compressed_size = TARGET_NO_FIELD, .section_align = 1, .vaddr_offset = 0, @@ -231,7 +224,6 @@ struct image_target_desc image_targets[] = .raw_size = 0, .total_module_size = TARGET_NO_FIELD, .compressed_size = TARGET_NO_FIELD, - .kernel_image_size = GRUB_KERNEL_I386_QEMU_KERNEL_IMAGE_SIZE, .section_align = 1, .vaddr_offset = 0, .install_dos_part = TARGET_NO_FIELD, @@ -247,7 +239,6 @@ struct image_target_desc image_targets[] = .flags = PLATFORM_FLAGS_NONE, .raw_size = 0, .total_module_size = TARGET_NO_FIELD, - .kernel_image_size = TARGET_NO_FIELD, .compressed_size = TARGET_NO_FIELD, .section_align = GRUB_PE32_SECTION_ALIGNMENT, .vaddr_offset = EFI64_HEADER_SIZE, @@ -266,7 +257,6 @@ struct image_target_desc image_targets[] = .raw_size = 0, .total_module_size = GRUB_KERNEL_MIPS_LOONGSON_TOTAL_MODULE_SIZE, .compressed_size = TARGET_NO_FIELD, - .kernel_image_size = TARGET_NO_FIELD, .section_align = 1, .vaddr_offset = 0, .install_dos_part = TARGET_NO_FIELD, @@ -286,7 +276,6 @@ struct image_target_desc image_targets[] = .raw_size = 0, .total_module_size = GRUB_KERNEL_MIPS_LOONGSON_TOTAL_MODULE_SIZE, .compressed_size = TARGET_NO_FIELD, - .kernel_image_size = TARGET_NO_FIELD, .section_align = 1, .vaddr_offset = 0, .install_dos_part = TARGET_NO_FIELD, @@ -308,7 +297,6 @@ struct image_target_desc image_targets[] = .raw_size = 0, .total_module_size = GRUB_KERNEL_MIPS_LOONGSON_TOTAL_MODULE_SIZE, .compressed_size = TARGET_NO_FIELD, - .kernel_image_size = TARGET_NO_FIELD, .section_align = 1, .vaddr_offset = 0, .install_dos_part = TARGET_NO_FIELD, @@ -327,7 +315,6 @@ struct image_target_desc image_targets[] = .flags = PLATFORM_FLAGS_NONE, .raw_size = 0, .total_module_size = TARGET_NO_FIELD, - .kernel_image_size = TARGET_NO_FIELD, .compressed_size = TARGET_NO_FIELD, .section_align = 1, .vaddr_offset = 0, @@ -348,8 +335,7 @@ struct image_target_desc image_targets[] = .flags = PLATFORM_FLAGS_NONE, .raw_size = GRUB_KERNEL_SPARC64_IEEE1275_RAW_SIZE, .total_module_size = GRUB_KERNEL_SPARC64_IEEE1275_TOTAL_MODULE_SIZE, - .kernel_image_size = GRUB_KERNEL_SPARC64_IEEE1275_KERNEL_IMAGE_SIZE, - .compressed_size = GRUB_KERNEL_SPARC64_IEEE1275_COMPRESSED_SIZE, + .compressed_size = TARGET_NO_FIELD, .section_align = 1, .vaddr_offset = 0, .install_dos_part = TARGET_NO_FIELD, @@ -365,8 +351,7 @@ struct image_target_desc image_targets[] = .flags = PLATFORM_FLAGS_NONE, .raw_size = GRUB_KERNEL_SPARC64_IEEE1275_RAW_SIZE, .total_module_size = GRUB_KERNEL_SPARC64_IEEE1275_TOTAL_MODULE_SIZE, - .kernel_image_size = GRUB_KERNEL_SPARC64_IEEE1275_KERNEL_IMAGE_SIZE, - .compressed_size = GRUB_KERNEL_SPARC64_IEEE1275_COMPRESSED_SIZE, + .compressed_size = TARGET_NO_FIELD, .section_align = 1, .vaddr_offset = 0, .install_dos_part = TARGET_NO_FIELD, @@ -382,7 +367,6 @@ struct image_target_desc image_targets[] = .flags = PLATFORM_FLAGS_NONE, .raw_size = 0, .total_module_size = TARGET_NO_FIELD, - .kernel_image_size = TARGET_NO_FIELD, .compressed_size = TARGET_NO_FIELD, .section_align = GRUB_PE32_SECTION_ALIGNMENT, .vaddr_offset = EFI64_HEADER_SIZE, @@ -402,7 +386,6 @@ struct image_target_desc image_targets[] = .raw_size = 0, .total_module_size = GRUB_KERNEL_MIPS_ARC_TOTAL_MODULE_SIZE, .compressed_size = TARGET_NO_FIELD, - .kernel_image_size = TARGET_NO_FIELD, .section_align = 1, .vaddr_offset = 0, .install_dos_part = TARGET_NO_FIELD, @@ -422,7 +405,6 @@ struct image_target_desc image_targets[] = .raw_size = 0, .total_module_size = GRUB_KERNEL_MIPS_QEMU_MIPS_TOTAL_MODULE_SIZE, .compressed_size = TARGET_NO_FIELD, - .kernel_image_size = TARGET_NO_FIELD, .section_align = 1, .vaddr_offset = 0, .install_dos_part = TARGET_NO_FIELD, @@ -442,7 +424,6 @@ struct image_target_desc image_targets[] = .raw_size = 0, .total_module_size = GRUB_KERNEL_MIPS_QEMU_MIPS_TOTAL_MODULE_SIZE, .compressed_size = TARGET_NO_FIELD, - .kernel_image_size = TARGET_NO_FIELD, .section_align = 1, .vaddr_offset = 0, .install_dos_part = TARGET_NO_FIELD, @@ -462,7 +443,6 @@ struct image_target_desc image_targets[] = .raw_size = 0, .total_module_size = GRUB_KERNEL_MIPS_QEMU_MIPS_TOTAL_MODULE_SIZE, .compressed_size = TARGET_NO_FIELD, - .kernel_image_size = TARGET_NO_FIELD, .section_align = 1, .vaddr_offset = 0, .install_dos_part = TARGET_NO_FIELD, @@ -482,7 +462,6 @@ struct image_target_desc image_targets[] = .raw_size = 0, .total_module_size = GRUB_KERNEL_MIPS_QEMU_MIPS_TOTAL_MODULE_SIZE, .compressed_size = TARGET_NO_FIELD, - .kernel_image_size = TARGET_NO_FIELD, .section_align = 1, .vaddr_offset = 0, .install_dos_part = TARGET_NO_FIELD, @@ -935,9 +914,6 @@ generate_image (const char *dir, char *prefix, FILE *out, char *mods[], && image_target->total_module_size != TARGET_NO_FIELD) *((grub_uint32_t *) (kernel_img + image_target->total_module_size)) = grub_host_to_target32 (total_module_size); - if (image_target->kernel_image_size != TARGET_NO_FIELD) - *((grub_uint32_t *) (kernel_img + image_target->kernel_image_size)) - = grub_host_to_target32 (kernel_size); if (image_target->compressed_size != TARGET_NO_FIELD) *((grub_uint32_t *) (kernel_img + image_target->compressed_size)) = grub_host_to_target32 (core_size - image_target->raw_size); From 7bec1053db4da195301d418bd82dd5316b28002e Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 23 Oct 2011 22:40:26 +0200 Subject: [PATCH 840/869] * util/grub.d/10_hurd.in: Add datarootdir as per automake manual suggestion. * util/grub.d/10_kfreebsd.in: Likewise. * util/grub.d/10_linux.in: Likewise. * util/grub.d/10_netbsd.in: Likewise. * util/grub.d/10_windows.in: Likewise. * util/grub.d/20_linux_xen.in: Likewise. --- ChangeLog | 10 ++++++++++ util/grub.d/10_hurd.in | 1 + util/grub.d/10_kfreebsd.in | 1 + util/grub.d/10_linux.in | 1 + util/grub.d/10_netbsd.in | 1 + util/grub.d/10_windows.in | 1 + util/grub.d/20_linux_xen.in | 1 + 7 files changed, 16 insertions(+) diff --git a/ChangeLog b/ChangeLog index bf96dc095..0b179811c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2011-10-20 Vladimir Serbinenko + + * util/grub.d/10_hurd.in: Add datarootdir as per automake manual + suggestion. + * util/grub.d/10_kfreebsd.in: Likewise. + * util/grub.d/10_linux.in: Likewise. + * util/grub.d/10_netbsd.in: Likewise. + * util/grub.d/10_windows.in: Likewise. + * util/grub.d/20_linux_xen.in: Likewise. + 2011-10-20 Vladimir Serbinenko Remove redundant grub_kernel_image_size. diff --git a/util/grub.d/10_hurd.in b/util/grub.d/10_hurd.in index 9ca01f0a8..d04b0a4fe 100644 --- a/util/grub.d/10_hurd.in +++ b/util/grub.d/10_hurd.in @@ -20,6 +20,7 @@ set -e prefix=@prefix@ exec_prefix=@exec_prefix@ libdir=@libdir@ +datarootdir=@datarootdir@ . ${libdir}/@PACKAGE@/grub-mkconfig_lib CLASS="--class gnu --class os" diff --git a/util/grub.d/10_kfreebsd.in b/util/grub.d/10_kfreebsd.in index e4bfc06cb..e668f3fd9 100644 --- a/util/grub.d/10_kfreebsd.in +++ b/util/grub.d/10_kfreebsd.in @@ -21,6 +21,7 @@ prefix=@prefix@ exec_prefix=@exec_prefix@ bindir=@bindir@ libdir=@libdir@ +datarootdir=@datarootdir@ . ${libdir}/@PACKAGE@/grub-mkconfig_lib export TEXTDOMAIN=@PACKAGE@ diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in index 97e7c6523..c3565096b 100644 --- a/util/grub.d/10_linux.in +++ b/util/grub.d/10_linux.in @@ -21,6 +21,7 @@ prefix=@prefix@ exec_prefix=@exec_prefix@ bindir=@bindir@ libdir=@libdir@ +datarootdir=@datarootdir@ . ${libdir}/@PACKAGE@/grub-mkconfig_lib export TEXTDOMAIN=@PACKAGE@ diff --git a/util/grub.d/10_netbsd.in b/util/grub.d/10_netbsd.in index c257aeb3c..8c232b01b 100644 --- a/util/grub.d/10_netbsd.in +++ b/util/grub.d/10_netbsd.in @@ -21,6 +21,7 @@ prefix=@prefix@ exec_prefix=@exec_prefix@ bindir=@bindir@ libdir=@libdir@ +datarootdir=@datarootdir@ . ${libdir}/@PACKAGE@/grub-mkconfig_lib export TEXTDOMAIN=@PACKAGE@ diff --git a/util/grub.d/10_windows.in b/util/grub.d/10_windows.in index 941267a9f..0a848880d 100644 --- a/util/grub.d/10_windows.in +++ b/util/grub.d/10_windows.in @@ -20,6 +20,7 @@ set -e prefix=@prefix@ exec_prefix=@exec_prefix@ libdir=@libdir@ +datarootdir=@datarootdir@ . ${libdir}/@PACKAGE@/grub-mkconfig_lib case "`uname 2>/dev/null`" in diff --git a/util/grub.d/20_linux_xen.in b/util/grub.d/20_linux_xen.in index c0b255598..2f1b4af88 100644 --- a/util/grub.d/20_linux_xen.in +++ b/util/grub.d/20_linux_xen.in @@ -21,6 +21,7 @@ prefix=@prefix@ exec_prefix=@exec_prefix@ bindir=@bindir@ libdir=@libdir@ +datarootdir=@datarootdir@ . ${libdir}/@PACKAGE@/grub-mkconfig_lib export TEXTDOMAIN=@PACKAGE@ From 7a5c54a437d148d3f8de45b3adaa9a77d6e5de44 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 23 Oct 2011 22:53:21 +0200 Subject: [PATCH 841/869] * util/grub-install.in: Add datarootdir as per automake manual suggestion. * util/grub-mknetdir.in: Likewise. --- ChangeLog | 8 +++++++- util/grub-install.in | 1 + util/grub-mknetdir.in | 1 + 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 0b179811c..17db9da19 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,10 @@ -2011-10-20 Vladimir Serbinenko +2011-10-23 Vladimir Serbinenko + + * util/grub-install.in: Add datarootdir as per automake manual + suggestion. + * util/grub-mknetdir.in: Likewise. + +2011-10-23 Vladimir Serbinenko * util/grub.d/10_hurd.in: Add datarootdir as per automake manual suggestion. diff --git a/util/grub-install.in b/util/grub-install.in index e1255f4f7..fdbe10e76 100644 --- a/util/grub-install.in +++ b/util/grub-install.in @@ -31,6 +31,7 @@ PACKAGE_VERSION=@PACKAGE_VERSION@ target_cpu=@target_cpu@ platform=@platform@ host_os=@host_os@ +datarootdir=@datarootdir@ pkglibdir="${libdir}/`echo ${PACKAGE_TARNAME}/${target_cpu}-${platform} | sed ${transform}`" localedir="@datadir@/locale" diff --git a/util/grub-mknetdir.in b/util/grub-mknetdir.in index 52598a8c9..e5a2172fd 100644 --- a/util/grub-mknetdir.in +++ b/util/grub-mknetdir.in @@ -29,6 +29,7 @@ PACKAGE_TARNAME=@PACKAGE_TARNAME@ PACKAGE_VERSION=@PACKAGE_VERSION@ host_os=@host_os@ localedir=@datadir@/locale +datarootdir=@datarootdir@ pkglib_DATA="moddep.lst command.lst fs.lst partmap.lst parttool.lst handler.lst video.lst crypto.lst terminal.lst" self=`basename $0` From d1e293bbfac2f1890d6d8ab4fbc72adb43536adf Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 23 Oct 2011 22:55:32 +0200 Subject: [PATCH 842/869] * grub-core/io/lzopio.c (test_header): Fix incorrect memcmp instead of grub_memcmp usage. --- ChangeLog | 5 +++++ grub-core/io/lzopio.c | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 17db9da19..5899c1e95 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-10-23 Vladimir Serbinenko + + * grub-core/io/lzopio.c (test_header): Fix incorrect memcmp instead of + grub_memcmp usage. + 2011-10-23 Vladimir Serbinenko * util/grub-install.in: Add datarootdir as per automake manual diff --git a/grub-core/io/lzopio.c b/grub-core/io/lzopio.c index 02a70f4d8..bd6f8e738 100644 --- a/grub-core/io/lzopio.c +++ b/grub-core/io/lzopio.c @@ -397,7 +397,7 @@ test_header (grub_file_t file) if (hcheck) { checksum = grub_cpu_to_be32(checksum); - if (memcmp(&checksum, hcheck->read(context), sizeof(checksum)) != 0) + if (grub_memcmp (&checksum, hcheck->read(context), sizeof(checksum)) != 0) goto CORRUPTED; } From 3ce69fc90f62b3ca01239bdc826d4960df15ce83 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 23 Oct 2011 23:04:57 +0200 Subject: [PATCH 843/869] * grub-core/kern/i386/pc/startup.S (grub_exit): Add missing zeroing-out. * grub-core/lib/i386/reboot_trampoline.S (grub_reboot_start): Likewise. --- ChangeLog | 6 ++++++ grub-core/kern/i386/pc/startup.S | 1 + grub-core/lib/i386/reboot_trampoline.S | 1 + 3 files changed, 8 insertions(+) diff --git a/ChangeLog b/ChangeLog index 5899c1e95..f5b846ddd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2011-10-23 Vladimir Serbinenko + + * grub-core/kern/i386/pc/startup.S (grub_exit): Add missing zeroing-out. + * grub-core/lib/i386/reboot_trampoline.S (grub_reboot_start): + Likewise. + 2011-10-23 Vladimir Serbinenko * grub-core/io/lzopio.c (test_header): Fix incorrect memcmp instead of diff --git a/grub-core/kern/i386/pc/startup.S b/grub-core/kern/i386/pc/startup.S index a0ef71f90..5277695b1 100644 --- a/grub-core/kern/i386/pc/startup.S +++ b/grub-core/kern/i386/pc/startup.S @@ -458,6 +458,7 @@ FUNCTION(grub_exit) /* Tell the BIOS a boot failure. If this does not work, reboot. */ int $0x18 /* set 0x472 to 0x0000 for cold boot (0x1234 for warm boot) */ + xorw %ax, %ax movw $0x0472, %di movw %ax, (%di) ljmp $0xf000, $0xfff0 diff --git a/grub-core/lib/i386/reboot_trampoline.S b/grub-core/lib/i386/reboot_trampoline.S index 18bcfb287..c088cd081 100644 --- a/grub-core/lib/i386/reboot_trampoline.S +++ b/grub-core/lib/i386/reboot_trampoline.S @@ -26,6 +26,7 @@ VARIABLE(grub_reboot_start) /* set 0x472 to 0x0000 for cold boot (0x1234 for warm boot) */ movw $0x0472, %di + xorw %ax, %ax movw %ax, (%di) ljmp $0xf000, $0xfff0 From f8bc22a832e290cd5fa80572e248762f71a7274f Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 23 Oct 2011 23:20:11 +0200 Subject: [PATCH 844/869] * util/ieee1275/grub-ofpathname.c: Add missing include. --- ChangeLog | 4 ++++ util/ieee1275/grub-ofpathname.c | 2 ++ 2 files changed, 6 insertions(+) diff --git a/ChangeLog b/ChangeLog index f5b846ddd..39a85696e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2011-10-23 Vladimir Serbinenko + + * util/ieee1275/grub-ofpathname.c: Add missing include. + 2011-10-23 Vladimir Serbinenko * grub-core/kern/i386/pc/startup.S (grub_exit): Add missing zeroing-out. diff --git a/util/ieee1275/grub-ofpathname.c b/util/ieee1275/grub-ofpathname.c index a9bc2cfda..ee81457b3 100644 --- a/util/ieee1275/grub-ofpathname.c +++ b/util/ieee1275/grub-ofpathname.c @@ -24,6 +24,8 @@ #include "progname.h" +#include + int main(int argc, char **argv) { char *of_path; From 18c575e5c5c4a1df3aadb602244e31677bb8631d Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 23 Oct 2011 23:22:38 +0200 Subject: [PATCH 845/869] * util/grub-setup.c: Add missing include. --- ChangeLog | 4 ++++ util/grub-setup.c | 1 + 2 files changed, 5 insertions(+) diff --git a/ChangeLog b/ChangeLog index 39a85696e..7eb57b134 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2011-10-23 Vladimir Serbinenko + + * util/grub-setup.c: Add missing include. + 2011-10-23 Vladimir Serbinenko * util/ieee1275/grub-ofpathname.c: Add missing include. diff --git a/util/grub-setup.c b/util/grub-setup.c index b3a6c5c76..99de26f76 100644 --- a/util/grub-setup.c +++ b/util/grub-setup.c @@ -49,6 +49,7 @@ #include "progname.h" #include #include +#include #define _GNU_SOURCE 1 #include From 4e94ae657595a0b13656ebf16e65fbd071783663 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 23 Oct 2011 23:25:06 +0200 Subject: [PATCH 846/869] * include/grub/misc.h (grub_memcpy): Declare grub_memcpy with static inline function rather than a define. --- ChangeLog | 5 +++++ include/grub/misc.h | 9 +++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7eb57b134..782da923e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-10-23 Vladimir Serbinenko + + * include/grub/misc.h (grub_memcpy): Declare grub_memcpy with static + inline function rather than a define. + 2011-10-23 Vladimir Serbinenko * util/grub-setup.c: Add missing include. diff --git a/include/grub/misc.h b/include/grub/misc.h index 0a0a4135e..5bc159e7d 100644 --- a/include/grub/misc.h +++ b/include/grub/misc.h @@ -49,14 +49,19 @@ #define COMPILE_TIME_ASSERT(cond) switch (0) { case 1: case !(cond): ; } #define grub_dprintf(condition, fmt, args...) grub_real_dprintf(GRUB_FILE, __LINE__, condition, fmt, ## args) -/* XXX: If grub_memmove is too slow, we must implement grub_memcpy. */ -#define grub_memcpy(d,s,n) grub_memmove ((d), (s), (n)) void *EXPORT_FUNC(grub_memmove) (void *dest, const void *src, grub_size_t n); char *EXPORT_FUNC(grub_strcpy) (char *dest, const char *src); char *EXPORT_FUNC(grub_strncpy) (char *dest, const char *src, int c); char *EXPORT_FUNC(grub_stpcpy) (char *dest, const char *src); +/* XXX: If grub_memmove is too slow, we must implement grub_memcpy. */ +static inline void * +grub_memcpy (void *dest, const void *src, grub_size_t n) +{ + return grub_memmove (dest, src, n); +} + static inline char * grub_strcat (char *dest, const char *src) { From 4defb8d59b16c713460ea0929b4439ace3dc2705 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 23 Oct 2011 23:28:23 +0200 Subject: [PATCH 847/869] * grub-core/lib/posix_wrap/string.h (memcpy) [GRUB_UTIL]: New inline function. * grub-core/lib/libgcrypt_wrap/cipher_wrap.h (memcpy) [GRUB_UTIL]: Likewise. (memset) [GRUB_UTIL]: Likewise. (memcmp) [GRUB_UTIL]: Likewise. --- ChangeLog | 9 +++++++++ grub-core/lib/libgcrypt_wrap/cipher_wrap.h | 21 ++++++++++++++++++++- grub-core/lib/posix_wrap/string.h | 8 ++++++++ 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 782da923e..579f510b0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2011-10-23 Vladimir Serbinenko + + * grub-core/lib/posix_wrap/string.h (memcpy) [GRUB_UTIL]: + New inline function. + * grub-core/lib/libgcrypt_wrap/cipher_wrap.h (memcpy) [GRUB_UTIL]: + Likewise. + (memset) [GRUB_UTIL]: Likewise. + (memcmp) [GRUB_UTIL]: Likewise. + 2011-10-23 Vladimir Serbinenko * include/grub/misc.h (grub_memcpy): Declare grub_memcpy with static diff --git a/grub-core/lib/libgcrypt_wrap/cipher_wrap.h b/grub-core/lib/libgcrypt_wrap/cipher_wrap.h index 59febaeb5..0141400fc 100644 --- a/grub-core/lib/libgcrypt_wrap/cipher_wrap.h +++ b/grub-core/lib/libgcrypt_wrap/cipher_wrap.h @@ -87,6 +87,25 @@ fips_mode (void) return 0; } -#define memset grub_memset +#ifdef GRUB_UTIL +static inline void * +memcpy (void *dest, const void *src, grub_size_t n) +{ + return grub_memcpy (dest, src, n); +} + +static inline void * +memset (void *s, int c, grub_size_t n) +{ + return grub_memset (s, c, n); +} + +static inline int +memcmp (const void *s1, const void *s2, grub_size_t n) +{ + return grub_memcmp (s1, s2, n); +} +#endif + #endif diff --git a/grub-core/lib/posix_wrap/string.h b/grub-core/lib/posix_wrap/string.h index 4224836e2..f38c97ba4 100644 --- a/grub-core/lib/posix_wrap/string.h +++ b/grub-core/lib/posix_wrap/string.h @@ -39,4 +39,12 @@ strcasecmp (const char *s1, const char *s2) return grub_strcasecmp (s1, s2); } +#ifdef GRUB_UTIL +static inline void * +memcpy (void *dest, const void *src, grub_size_t n) +{ + return grub_memcpy (dest, src, n); +} +#endif + #endif From 124df5f6caabf6be40434c75b4c945f908d01904 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 23 Oct 2011 23:32:06 +0200 Subject: [PATCH 848/869] Fine grainely disable warnings on lexer. Remove Wno-error on it. * grub-core/Makefile.core.def (normal): Remove -Wno-error. * grub-core/script/lexer.c: Declare yytext_ptr to avoid having yylex_strncpy. * grub-core/script/yylex.l: Add fine-grained #pragma. --- ChangeLog | 9 +++++++++ grub-core/Makefile.core.def | 2 +- grub-core/script/lexer.c | 1 + grub-core/script/yylex.l | 3 +++ 4 files changed, 14 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 579f510b0..637fa622b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2011-10-23 Vladimir Serbinenko + + Fine grainely disable warnings on lexer. Remove Wno-error on it. + + * grub-core/Makefile.core.def (normal): Remove -Wno-error. + * grub-core/script/lexer.c: Declare yytext_ptr to avoid having + yylex_strncpy. + * grub-core/script/yylex.l: Add fine-grained #pragma. + 2011-10-23 Vladimir Serbinenko * grub-core/lib/posix_wrap/string.h (memcpy) [GRUB_UTIL]: diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def index 7cb83924c..6d3c31ea6 100644 --- a/grub-core/Makefile.core.def +++ b/grub-core/Makefile.core.def @@ -1395,7 +1395,7 @@ module = { extra_dist = script/yylex.l; extra_dist = script/parser.y; - cflags = '$(CFLAGS_POSIX) -Wno-error'; + cflags = '$(CFLAGS_POSIX)'; cppflags = '$(CPPFLAGS_POSIX)'; }; diff --git a/grub-core/script/lexer.c b/grub-core/script/lexer.c index 98279079f..53697c734 100644 --- a/grub-core/script/lexer.c +++ b/grub-core/script/lexer.c @@ -24,6 +24,7 @@ #include #include +#define yytext_ptr char * #include "grub_script.tab.h" #include "grub_script.yy.h" diff --git a/grub-core/script/yylex.l b/grub-core/script/yylex.l index 7195a880d..012d88dbc 100644 --- a/grub-core/script/yylex.l +++ b/grub-core/script/yylex.l @@ -24,6 +24,9 @@ #include #include "grub_script.tab.h" +#pragma GCC diagnostic ignored "-Wunused-parameter" +#pragma GCC diagnostic ignored "-Wmissing-prototypes" + #define yyfree grub_lexer_yyfree #define yyalloc grub_lexer_yyalloc #define yyrealloc grub_lexer_yyrealloc From 3471ecdfd9c08e59f37f8ec8fd530aef26e9f1e4 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 23 Oct 2011 23:34:30 +0200 Subject: [PATCH 849/869] * grub-core/lib/setjmp.S [__ia64__]: Include ./ia64/longjmp.S. --- ChangeLog | 4 ++++ grub-core/lib/setjmp.S | 1 + 2 files changed, 5 insertions(+) diff --git a/ChangeLog b/ChangeLog index 637fa622b..6daca7214 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2011-10-23 Vladimir Serbinenko + + * grub-core/lib/setjmp.S [__ia64__]: Include ./ia64/longjmp.S. + 2011-10-23 Vladimir Serbinenko Fine grainely disable warnings on lexer. Remove Wno-error on it. diff --git a/grub-core/lib/setjmp.S b/grub-core/lib/setjmp.S index b04fd7439..fb7f94767 100644 --- a/grub-core/lib/setjmp.S +++ b/grub-core/lib/setjmp.S @@ -10,6 +10,7 @@ #include "./powerpc/setjmp.S" #elif defined(__ia64__) #include "./ia64/setjmp.S" +#include "./ia64/longjmp.S" #else #error "Unknown target cpu type" #endif From e084ba18957266042721af925a58d744daf8b842 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 23 Oct 2011 23:39:00 +0200 Subject: [PATCH 850/869] * util/import_gcry.py: Accept space between # and include. --- ChangeLog | 4 ++++ util/import_gcry.py | 5 ++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 6daca7214..fc5ab9806 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2011-10-23 Vladimir Serbinenko + + * util/import_gcry.py: Accept space between # and include. + 2011-10-23 Vladimir Serbinenko * grub-core/lib/setjmp.S [__ia64__]: Include ./ia64/longjmp.S. diff --git a/util/import_gcry.py b/util/import_gcry.py index 720f19303..befa5ef5f 100644 --- a/util/import_gcry.py +++ b/util/import_gcry.py @@ -189,10 +189,9 @@ for cipher_file in cipher_files: continue else: fw.write (holdline) - m = re.match ("#include <.*>", line) + m = re.match ("# *include <(.*)>", line) if not m is None: - chmsg = "Removed including of %s" % \ - m.group () [len ("#include <"):len (m.group ()) - 1] + chmsg = "Removed including of %s" % m.groups ()[0] if nch: chlognew = "%s\n %s" % (chlognew, chmsg) else: From 534d769e579ad77100d11a397387ebff68fb90cd Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 23 Oct 2011 23:40:53 +0200 Subject: [PATCH 851/869] * util/import_gcry.py: Automatically fix camellia.c and camellia.h. --- ChangeLog | 4 ++++ util/import_gcry.py | 14 ++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/ChangeLog b/ChangeLog index fc5ab9806..0198ba4ee 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2011-10-23 Vladimir Serbinenko + + * util/import_gcry.py: Automatically fix camellia.c and camellia.h. + 2011-10-23 Vladimir Serbinenko * util/import_gcry.py: Accept space between # and include. diff --git a/util/import_gcry.py b/util/import_gcry.py index befa5ef5f..7591d8f0e 100644 --- a/util/import_gcry.py +++ b/util/import_gcry.py @@ -104,6 +104,20 @@ for cipher_file in cipher_files: fw.write ("/* This file was automatically imported with \n") fw.write (" import_gcry.py. Please don't modify it */\n") fw.write ("#include \n") + if cipher_file == "camellia.c": + fw.write ("#include \"camellia.h\"\n") + if cipher_file == "camellia.h": + fw.write ("#include \n") + fw.write ("void camellia_setup128(const unsigned char *key, grub_uint32_t *subkey);\n") + fw.write ("void camellia_setup192(const unsigned char *key, grub_uint32_t *subkey);\n") + fw.write ("void camellia_setup256(const unsigned char *key, grub_uint32_t *subkey);\n") + fw.write ("void camellia_encrypt128(const grub_uint32_t *subkey, grub_uint32_t *io);\n") + fw.write ("void camellia_encrypt192(const grub_uint32_t *subkey, grub_uint32_t *io);\n") + fw.write ("void camellia_encrypt256(const grub_uint32_t *subkey, grub_uint32_t *io);\n") + fw.write ("void camellia_decrypt128(const grub_uint32_t *subkey, grub_uint32_t *io);\n") + fw.write ("void camellia_decrypt192(const grub_uint32_t *subkey, grub_uint32_t *io);\n") + fw.write ("void camellia_decrypt256(const grub_uint32_t *subkey, grub_uint32_t *io);\n") + fw.write ("#define memcpy grub_memcpy\n") # Whole libgcrypt is distributed under GPLv3+ or compatible if isc: fw.write ("GRUB_MOD_LICENSE (\"GPLv3+\");\n") From f646e143090e26fc8087f3395fc2c1e03190c584 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 23 Oct 2011 23:55:38 +0200 Subject: [PATCH 852/869] * grub-core/lib/reed_solomon.c (gf_invert): Declare as const and save some space. * include/grub/offsets.h (GRUB_KERNEL_I386_PC_RAW_SIZE): Decrease. (GRUB_KERNEL_I386_PC_NO_REED_SOLOMON_PART): Likewise. --- ChangeLog | 7 +++++++ grub-core/lib/reed_solomon.c | 4 ++-- include/grub/offsets.h | 4 ++-- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 0198ba4ee..ea8804bd1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2011-10-23 Vladimir Serbinenko + + * grub-core/lib/reed_solomon.c (gf_invert): Declare as const and + save some space. + * include/grub/offsets.h (GRUB_KERNEL_I386_PC_RAW_SIZE): Decrease. + (GRUB_KERNEL_I386_PC_NO_REED_SOLOMON_PART): Likewise. + 2011-10-23 Vladimir Serbinenko * util/import_gcry.py: Automatically fix camellia.c and camellia.h. diff --git a/grub-core/lib/reed_solomon.c b/grub-core/lib/reed_solomon.c index 365b76003..78d249c2f 100644 --- a/grub-core/lib/reed_solomon.c +++ b/grub-core/lib/reed_solomon.c @@ -57,13 +57,13 @@ typedef grub_uint16_t gf_double_t; #define GF_POLYNOMIAL 0x1d #define GF_INVERT2 0x8e #if defined (STANDALONE) && !defined (TEST) -static char *gf_invert __attribute__ ((section(".text"))) = (void *) 0x100000; +static gf_single_t * const gf_invert __attribute__ ((section(".text"))) = (void *) 0x100000; static char *scratch __attribute__ ((section(".text"))) = (void *) 0x100100; #else #if defined (STANDALONE) static char *scratch; #endif -static grub_uint8_t gf_invert[256]; +static gf_single_t gf_invert[256]; #endif #define SECTOR_SIZE 512 diff --git a/include/grub/offsets.h b/include/grub/offsets.h index aa65cd5cc..92354f700 100644 --- a/include/grub/offsets.h +++ b/include/grub/offsets.h @@ -35,9 +35,9 @@ #define GRUB_KERNEL_I386_PC_REED_SOLOMON_REDUNDANCY 0x18 /* The size of the first region which won't be compressed. */ -#define GRUB_KERNEL_I386_PC_RAW_SIZE 0xcd0 +#define GRUB_KERNEL_I386_PC_RAW_SIZE 0xc70 -#define GRUB_KERNEL_I386_PC_NO_REED_SOLOMON_PART 0x730 +#define GRUB_KERNEL_I386_PC_NO_REED_SOLOMON_PART 0x6e0 /* The segment where the kernel is loaded. */ #define GRUB_BOOT_I386_PC_KERNEL_SEG 0x800 From 89481cabbdbbf8dfd937f06f6195bc4135fb86d0 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 24 Oct 2011 01:31:06 +0200 Subject: [PATCH 853/869] * grub-core/fs/fat.c (grub_fat_label) [MODE_EXFAT]: Set *label to 0 if no label is found. (grub_fat_iterate_dir): Fix file size type. (grub_fat_iterate_dir): Likewise. --- ChangeLog | 7 +++++++ grub-core/fs/fat.c | 8 +++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index ea8804bd1..306358faa 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2011-10-23 Vladimir Serbinenko + + * grub-core/fs/fat.c (grub_fat_label) [MODE_EXFAT]: Set *label to 0 + if no label is found. + (grub_fat_iterate_dir): Fix file size type. + (grub_fat_iterate_dir): Likewise. + 2011-10-23 Vladimir Serbinenko * grub-core/lib/reed_solomon.c (gf_invert): Declare as const and diff --git a/grub-core/fs/fat.c b/grub-core/fs/fat.c index ae705bcfb..36a43fca0 100644 --- a/grub-core/fs/fat.c +++ b/grub-core/fs/fat.c @@ -485,7 +485,7 @@ grub_fat_read_data (grub_disk_t disk, struct grub_fat_data *data, + data->logical_sector_bits + GRUB_DISK_SECTOR_BITS); logical_cluster = offset >> logical_cluster_bits; - offset &= (1 << logical_cluster_bits) - 1; + offset &= (1ULL << logical_cluster_bits) - 1; if (logical_cluster < data->cur_cluster_num) { @@ -631,9 +631,9 @@ grub_fat_iterate_dir (grub_disk_t disk, struct grub_fat_data *data, case 0xc0: node.first_cluster = grub_cpu_to_le32 (sec.type_specific.stream_extension.first_cluster); node.valid_size - = grub_cpu_to_le32 (sec.type_specific.stream_extension.valid_size); + = grub_cpu_to_le64 (sec.type_specific.stream_extension.valid_size); node.file_size - = grub_cpu_to_le32 (sec.type_specific.stream_extension.file_size); + = grub_cpu_to_le64 (sec.type_specific.stream_extension.file_size); node.have_stream = 1; break; case 0xc1: @@ -1026,6 +1026,8 @@ grub_fat_label (grub_device_t device, char **label) if (! data) return grub_errno; + *label = NULL; + while (1) { offset += sizeof (dir); From e0864e7ab7b79f2f08ab749e6be84dadfa0119e3 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 24 Oct 2011 10:45:47 +0200 Subject: [PATCH 854/869] Minix FS fixes. * grub-core/fs/minix.c (GRUB_MINIX_INODE_SIZE): Size is always 32-bit. (grub_minix_inode) [!MODE_MINIX2 && !MODE_MINIX3]: Make size 32-bit. Rename ctime to mtime. All users updated. (grub_minix_get_file_block): Fix types and double indirect computations. --- ChangeLog | 9 +++++++++ grub-core/fs/minix.c | 34 ++++++++++++++++------------------ 2 files changed, 25 insertions(+), 18 deletions(-) diff --git a/ChangeLog b/ChangeLog index 306358faa..9065162fe 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2011-10-24 Vladimir Serbinenko + + Minix FS fixes. + + * grub-core/fs/minix.c (GRUB_MINIX_INODE_SIZE): Size is always 32-bit. + (grub_minix_inode) [!MODE_MINIX2 && !MODE_MINIX3]: Make size 32-bit. + Rename ctime to mtime. All users updated. + (grub_minix_get_file_block): Fix types and double indirect computations. + 2011-10-23 Vladimir Serbinenko * grub-core/fs/fat.c (grub_fat_label) [MODE_EXFAT]: Set *label to 0 diff --git a/grub-core/fs/minix.c b/grub-core/fs/minix.c index 055f89095..1db2883cd 100644 --- a/grub-core/fs/minix.c +++ b/grub-core/fs/minix.c @@ -63,7 +63,7 @@ typedef grub_uint16_t grub_minix_ino_t; #define grub_minix_le_to_cpu_ino grub_le_to_cpu16 #endif -#define GRUB_MINIX_INODE_SIZE(data) (grub_minix_le_to_cpu_n (data->inode.size)) +#define GRUB_MINIX_INODE_SIZE(data) (grub_le_to_cpu32 (data->inode.size)) #define GRUB_MINIX_INODE_MODE(data) (grub_le_to_cpu16 (data->inode.mode)) #define GRUB_MINIX_INODE_DIR_ZONES(data,blk) (grub_minix_le_to_cpu_n \ (data->inode.dir_zones[blk])) @@ -133,15 +133,14 @@ struct grub_minix_inode grub_uint32_t indir_zone; grub_uint32_t double_indir_zone; grub_uint32_t unused; - }; #else struct grub_minix_inode { grub_uint16_t mode; grub_uint16_t uid; - grub_uint16_t size; - grub_uint32_t ctime; + grub_uint32_t size; + grub_uint32_t mtime; grub_uint8_t gid; grub_uint8_t nlinks; grub_uint16_t dir_zones[7]; @@ -168,15 +167,19 @@ static grub_dl_t my_mod; static grub_err_t grub_minix_find_file (struct grub_minix_data *data, const char *path); -static int +static grub_minix_uintn_t grub_minix_get_file_block (struct grub_minix_data *data, unsigned int blk) { - int indir; + grub_minix_uintn_t indir; + const grub_uint32_t block_per_zone = (GRUB_MINIX_ZONESZ + / GRUB_MINIX_INODE_BLKSZ (data)); - auto int grub_get_indir (int, int); + auto grub_minix_uintn_t grub_get_indir (grub_minix_uintn_t, + grub_minix_uintn_t); /* Read the block pointer in ZONE, on the offset NUM. */ - int grub_get_indir (int zone, int num) + grub_minix_uintn_t grub_get_indir (grub_minix_uintn_t zone, + grub_minix_uintn_t num) { grub_minix_uintn_t indirn; grub_disk_read (data->disk, @@ -192,21 +195,20 @@ grub_minix_get_file_block (struct grub_minix_data *data, unsigned int blk) /* Indirect block. */ blk -= GRUB_MINIX_INODE_DIR_BLOCKS; - if (blk < GRUB_MINIX_ZONESZ / GRUB_MINIX_INODE_BLKSZ (data)) + if (blk < block_per_zone) { indir = grub_get_indir (GRUB_MINIX_INODE_INDIR_ZONE (data), blk); return indir; } /* Double indirect block. */ - blk -= GRUB_MINIX_ZONESZ / GRUB_MINIX_INODE_BLKSZ (data); - if (blk < (GRUB_MINIX_ZONESZ / GRUB_MINIX_INODE_BLKSZ (data)) - * (GRUB_MINIX_ZONESZ / GRUB_MINIX_INODE_BLKSZ (data))) + blk -= block_per_zone; + if (blk < block_per_zone * block_per_zone) { indir = grub_get_indir (GRUB_MINIX_INODE_DINDIR_ZONE (data), - blk / GRUB_MINIX_ZONESZ); + blk / block_per_zone); - indir = grub_get_indir (indir, blk % GRUB_MINIX_ZONESZ); + indir = grub_get_indir (indir, blk % block_per_zone); return indir; } @@ -536,11 +538,7 @@ grub_minix_dir (grub_device_t device, const char *path, info.dir = ((GRUB_MINIX_INODE_MODE (data) & GRUB_MINIX_IFDIR) == GRUB_MINIX_IFDIR); info.mtimeset = 1; -#ifndef MODE_MINIX2 - info.mtime = grub_le_to_cpu32 (data->inode.ctime); -#else info.mtime = grub_le_to_cpu32 (data->inode.mtime); -#endif if (hook (filename, &info) ? 1 : 0) break; From 6e536dc8ad96e3ca1ae878a4250ec87d6bdccb71 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 24 Oct 2011 16:16:28 +0200 Subject: [PATCH 855/869] Support triple indirect on minix2 and minix3. * grub-core/fs/minix.c (grub_minix_inode) [MODE_MINIX2 || MODE_MINIX3]: Declare triple_indir_zone. (grub_minix_get_file_block) [MODE_MINIX2 || MODE_MINIX3]: Handle triple indirect. --- ChangeLog | 9 +++++++++ grub-core/fs/minix.c | 16 +++++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 9065162fe..12117d6a0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2011-10-24 Vladimir Serbinenko + + Support triple indirect on minix2 and minix3. + + * grub-core/fs/minix.c (grub_minix_inode) [MODE_MINIX2 || MODE_MINIX3]: + Declare triple_indir_zone. + (grub_minix_get_file_block) [MODE_MINIX2 || MODE_MINIX3]: Handle triple + indirect. + 2011-10-24 Vladimir Serbinenko Minix FS fixes. diff --git a/grub-core/fs/minix.c b/grub-core/fs/minix.c index 1db2883cd..43785b657 100644 --- a/grub-core/fs/minix.c +++ b/grub-core/fs/minix.c @@ -132,7 +132,7 @@ struct grub_minix_inode grub_uint32_t dir_zones[7]; grub_uint32_t indir_zone; grub_uint32_t double_indir_zone; - grub_uint32_t unused; + grub_uint32_t triple_indir_zone; }; #else struct grub_minix_inode @@ -213,6 +213,20 @@ grub_minix_get_file_block (struct grub_minix_data *data, unsigned int blk) return indir; } +#if defined (MODE_MINIX3) || defined (MODE_MINIX2) + blk -= block_per_zone * block_per_zone; + if (blk < ((grub_uint64_t) block_per_zone * (grub_uint64_t) block_per_zone + * (grub_uint64_t) block_per_zone)) + { + indir = grub_get_indir (grub_minix_le_to_cpu_n (data->inode.triple_indir_zone), + (blk / block_per_zone) / block_per_zone); + indir = grub_get_indir (indir, (blk / block_per_zone) % block_per_zone); + indir = grub_get_indir (indir, blk % block_per_zone); + + return indir; + } +#endif + /* This should never happen. */ grub_error (GRUB_ERR_OUT_OF_RANGE, "file bigger than maximum size"); From 68c72069d927f5f7c907de32d4d9fa43d453c78c Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 24 Oct 2011 17:02:02 +0200 Subject: [PATCH 856/869] * grub-core/fs/jfs.c (grub_jfs_blkno): Use more appropriate types. (grub_jfs_blkno): Fix incorrect shift. (grub_jfs_read_file): Use more appropriate types. --- ChangeLog | 6 ++++++ grub-core/fs/jfs.c | 18 +++++++++--------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index 12117d6a0..7d216e1d7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2011-10-24 Vladimir Serbinenko + + * grub-core/fs/jfs.c (grub_jfs_blkno): Use more appropriate types. + (grub_jfs_blkno): Fix incorrect shift. + (grub_jfs_read_file): Use more appropriate types. + 2011-10-24 Vladimir Serbinenko Support triple indirect on minix2 and minix3. diff --git a/grub-core/fs/jfs.c b/grub-core/fs/jfs.c index ebc2c688a..4a7bb0214 100644 --- a/grub-core/fs/jfs.c +++ b/grub-core/fs/jfs.c @@ -253,11 +253,11 @@ static grub_int64_t grub_jfs_blkno (struct grub_jfs_data *data, struct grub_jfs_inode *inode, grub_uint64_t blk) { - auto int getblk (struct grub_jfs_treehead *treehead, - struct grub_jfs_tree_extent *extents); + auto grub_int64_t getblk (struct grub_jfs_treehead *treehead, + struct grub_jfs_tree_extent *extents); - int getblk (struct grub_jfs_treehead *treehead, - struct grub_jfs_tree_extent *extents) + grub_int64_t getblk (struct grub_jfs_treehead *treehead, + struct grub_jfs_tree_extent *extents) { int found = -1; int i; @@ -269,7 +269,7 @@ grub_jfs_blkno (struct grub_jfs_data *data, struct grub_jfs_inode *inode, /* Read the leafnode. */ if (grub_le_to_cpu32 (extents[i].offset2) <= blk && ((grub_le_to_cpu16 (extents[i].extent.length)) - + (extents[i].extent.length2 << 8) + + (extents[i].extent.length2 << 16) + grub_le_to_cpu32 (extents[i].offset2)) > blk) return (blk - grub_le_to_cpu32 (extents[i].offset2) + grub_le_to_cpu32 (extents[i].extent.blk2)); @@ -288,7 +288,7 @@ grub_jfs_blkno (struct grub_jfs_data *data, struct grub_jfs_inode *inode, } tree; if (grub_disk_read (data->disk, - grub_le_to_cpu32 (extents[found].extent.blk2) + ((grub_disk_addr_t) grub_le_to_cpu32 (extents[found].extent.blk2)) << (grub_le_to_cpu16 (data->sblock.log2_blksz) - GRUB_DISK_SECTOR_BITS), 0, sizeof (tree), (char *) &tree)) @@ -558,10 +558,10 @@ static grub_ssize_t grub_jfs_read_file (struct grub_jfs_data *data, void NESTED_FUNC_ATTR (*read_hook) (grub_disk_addr_t sector, unsigned offset, unsigned length), - grub_uint64_t pos, grub_size_t len, char *buf) + grub_off_t pos, grub_size_t len, char *buf) { - grub_uint64_t i; - grub_uint64_t blockcnt; + grub_off_t i; + grub_off_t blockcnt; blockcnt = (len + pos + grub_le_to_cpu32 (data->sblock.blksz) - 1) >> grub_le_to_cpu16 (data->sblock.log2_blksz); From 5bbd28b8cebbb365faebccf25119a2e6712731ad Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 24 Oct 2011 21:33:35 +0200 Subject: [PATCH 857/869] Fix 2G limit on ZFS. * grub-core/fs/zfs/zfs.c (zio_checksum_verify): Use more appropriate types. (uberblock_verify): Likewise. (dmu_read): Likewise. (grub_zfs_read): Likewise. Remove invalid cast. --- ChangeLog | 10 ++++++++++ grub-core/fs/zfs/zfs.c | 11 ++++++----- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7d216e1d7..e8cd7ea77 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2011-10-24 Vladimir Serbinenko + + Fix 2G limit on ZFS. + + * grub-core/fs/zfs/zfs.c (zio_checksum_verify): Use more appropriate + types. + (uberblock_verify): Likewise. + (dmu_read): Likewise. + (grub_zfs_read): Likewise. Remove invalid cast. + 2011-10-24 Vladimir Serbinenko * grub-core/fs/jfs.c (grub_jfs_blkno): Use more appropriate types. diff --git a/grub-core/fs/zfs/zfs.c b/grub-core/fs/zfs/zfs.c index 1eea13b26..9d6ad7055 100644 --- a/grub-core/fs/zfs/zfs.c +++ b/grub-core/fs/zfs/zfs.c @@ -242,7 +242,7 @@ static zio_checksum_info_t zio_checksum_table[ZIO_CHECKSUM_FUNCTIONS] = { */ static grub_err_t zio_checksum_verify (zio_cksum_t zc, grub_uint32_t checksum, - grub_zfs_endian_t endian, char *buf, int size) + grub_zfs_endian_t endian, char *buf, grub_size_t size) { zio_eck_t *zec = (zio_eck_t *) (buf + size) - 1; zio_checksum_info_t *ci = &zio_checksum_table[checksum]; @@ -337,7 +337,7 @@ vdev_uberblock_compare (uberblock_t * ub1, uberblock_t * ub2) * */ static grub_err_t -uberblock_verify (uberblock_phys_t * ub, int offset) +uberblock_verify (uberblock_phys_t * ub, grub_uint64_t offset) { uberblock_t *uber = &ub->ubp_uberblock; grub_err_t err; @@ -620,7 +620,8 @@ static grub_err_t dmu_read (dnode_end_t * dn, grub_uint64_t blkid, void **buf, grub_zfs_endian_t *endian_out, struct grub_zfs_data *data) { - int idx, level; + int level; + grub_off_t idx; blkptr_t *bp_array = dn->dn.dn_blkptr; int epbs = dn->dn.dn_indblkshift - SPA_BLKPTRSHIFT; blkptr_t *bp; @@ -2266,7 +2267,7 @@ static grub_ssize_t grub_zfs_read (grub_file_t file, char *buf, grub_size_t len) { struct grub_zfs_data *data = (struct grub_zfs_data *) file->data; - int blksz, movesize; + grub_size_t blksz, movesize; grub_size_t length; grub_size_t read; grub_err_t err; @@ -2320,7 +2321,7 @@ grub_zfs_read (grub_file_t file, char *buf, grub_size_t len) data->file_start = blkid * blksz; data->file_end = data->file_start + blksz; - movesize = MIN (length, data->file_end - (int) file->offset - read); + movesize = MIN (length, data->file_end - file->offset - read); grub_memmove (buf, data->file_buf + file->offset + read - data->file_start, movesize); From f4d9b64bba4e748922056437f0408071376c66b5 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Tue, 25 Oct 2011 17:38:22 +0200 Subject: [PATCH 858/869] * grub-core/fs/romfs.c (grub_romfs_open): Add missing return. --- ChangeLog | 4 ++++ grub-core/fs/romfs.c | 1 + 2 files changed, 5 insertions(+) diff --git a/ChangeLog b/ChangeLog index e8cd7ea77..1b1975215 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2011-10-25 Vladimir Serbinenko + + * grub-core/fs/romfs.c (grub_romfs_open): Add missing return. + 2011-10-24 Vladimir Serbinenko Fix 2G limit on ZFS. diff --git a/grub-core/fs/romfs.c b/grub-core/fs/romfs.c index 58dc98f34..713e8293f 100644 --- a/grub-core/fs/romfs.c +++ b/grub-core/fs/romfs.c @@ -367,6 +367,7 @@ grub_romfs_open (struct grub_file *file, const char *name) file->size = grub_be_to_cpu32 (fdiro->file.size); file->data = fdiro; + return GRUB_ERR_NONE; fail: grub_free (data); From 9f326fba96eb04658e7720585e8ad9c643631ced Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Tue, 25 Oct 2011 18:01:57 +0200 Subject: [PATCH 859/869] * grub-core/kern/disk.c (grub_disk_read_small): Fix memory leak. --- ChangeLog | 4 ++++ grub-core/kern/disk.c | 3 +++ 2 files changed, 7 insertions(+) diff --git a/ChangeLog b/ChangeLog index 1b1975215..7eef0f796 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2011-10-25 Vladimir Serbinenko + + * grub-core/kern/disk.c (grub_disk_read_small): Fix memory leak. + 2011-10-25 Vladimir Serbinenko * grub-core/fs/romfs.c (grub_romfs_open): Add missing return. diff --git a/grub-core/kern/disk.c b/grub-core/kern/disk.c index f296b9d0f..460d8778f 100644 --- a/grub-core/kern/disk.c +++ b/grub-core/kern/disk.c @@ -442,6 +442,7 @@ grub_disk_read_small (grub_disk_t disk, grub_disk_addr_t sector, } } + grub_free (tmp_buf); grub_errno = GRUB_ERR_NONE; { @@ -468,9 +469,11 @@ grub_disk_read_small (grub_disk_t disk, grub_disk_addr_t sector, grub_error_push (); grub_dprintf ("disk", "%s read failed\n", disk->name); grub_error_pop (); + grub_free (tmp_buf); return grub_errno; } grub_memcpy (buf, tmp_buf + offset, size); + grub_free (tmp_buf); return GRUB_ERR_NONE; } } From 9f12e664cc1b815cc01000cf87559a3c303de2e6 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Tue, 25 Oct 2011 18:09:00 +0200 Subject: [PATCH 860/869] Fix handling of uncompressed blocks on squashfs and break 4G limit. * grub-core/fs/squash4.c (grub_squash_super): Add block_size. Remove unused flags. (grub_squash_inode): Add long_file and block_size. (grub_squash_cache_inode): New struct. (grub_squash_dirent): Make types into enum. (SQUASH_TYPE_LONG_REGULAR): New type. (grub_squash_frag_desc): Add field size. (SQUASH_BLOCK_FLAGS): New enum. (grub_squash_data): Use grub_squash_cache_inode. (grub_fshelp_node): Make ino_chunk 64-bit. (read_chunk): Minor argument change. All users updated. (squash_mount): Use correct le_to_cpu. (grub_squash_open): Handle LONG_REGULAR. (direct_read): New function. (grub_squash_read_data): Handle blocks correctly. --- ChangeLog | 20 ++++ grub-core/fs/squash4.c | 254 ++++++++++++++++++++++++++++++++--------- 2 files changed, 223 insertions(+), 51 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7eef0f796..586de218f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,23 @@ +2011-10-25 Vladimir Serbinenko + + Fix handling of uncompressed blocks on squashfs and break 4G limit. + + * grub-core/fs/squash4.c (grub_squash_super): Add block_size. Remove + unused flags. + (grub_squash_inode): Add long_file and block_size. + (grub_squash_cache_inode): New struct. + (grub_squash_dirent): Make types into enum. + (SQUASH_TYPE_LONG_REGULAR): New type. + (grub_squash_frag_desc): Add field size. + (SQUASH_BLOCK_FLAGS): New enum. + (grub_squash_data): Use grub_squash_cache_inode. + (grub_fshelp_node): Make ino_chunk 64-bit. + (read_chunk): Minor argument change. All users updated. + (squash_mount): Use correct le_to_cpu. + (grub_squash_open): Handle LONG_REGULAR. + (direct_read): New function. + (grub_squash_read_data): Handle blocks correctly. + 2011-10-25 Vladimir Serbinenko * grub-core/kern/disk.c (grub_disk_read_small): Fix memory leak. diff --git a/grub-core/fs/squash4.c b/grub-core/fs/squash4.c index 4f1265582..d45732c16 100644 --- a/grub-core/fs/squash4.c +++ b/grub-core/fs/squash4.c @@ -42,7 +42,7 @@ GRUB_MOD_LICENSE ("GPLv3+"); exttblptr RAW superblock UID/GID table is the array ot uint32_t - unk1 contains pointer to unk3 followed by some chunk. + unk1 contains pointer to fragment table followed by some chunk. unk2 containts one uint64_t */ @@ -52,13 +52,9 @@ struct grub_squash_super #define SQUASH_MAGIC 0x73717368 grub_uint32_t dummy1; grub_uint32_t creation_time; - grub_uint32_t dummy2; + grub_uint32_t block_size; grub_uint64_t dummy3; - grub_uint8_t flags; -#define SQUASH_FLAG_UNCOMPRESSED_INODES 1 -#define SQUASH_FLAG_UNCOMPRESSED_DATA 2 -#define SQUASH_FLAG_UNCOMPRESSED_FRAGMENTS 8 - grub_uint8_t dummy4[7]; + grub_uint64_t dummy4; grub_uint16_t root_ino_offset; grub_uint32_t root_ino_chunk; grub_uint16_t dummy5; @@ -71,7 +67,6 @@ struct grub_squash_super grub_uint64_t unk2offset; } __attribute__ ((packed)); - /* Chunk-based */ struct grub_squash_inode { @@ -87,7 +82,18 @@ struct grub_squash_inode grub_uint32_t fragment; grub_uint32_t offset; grub_uint32_t size; + grub_uint32_t block_size[0]; } __attribute__ ((packed)) file; + struct { + grub_uint32_t dummy; + grub_uint64_t chunk; + grub_uint64_t size; + grub_uint32_t dummy2[3]; + grub_uint32_t fragment; + grub_uint32_t offset; + grub_uint32_t dummy3; + grub_uint32_t block_size[0]; + } __attribute__ ((packed)) long_file; struct { grub_uint32_t dummy1; grub_uint32_t chunk; @@ -104,6 +110,15 @@ struct grub_squash_inode } __attribute__ ((packed)); } __attribute__ ((packed)); +struct grub_squash_cache_inode +{ + struct grub_squash_inode ino; + grub_disk_addr_t ino_chunk; + grub_uint16_t ino_offset; + grub_uint32_t *block_sizes; + grub_disk_addr_t *cumulated_block_sizes; +}; + /* Chunk-based. */ struct grub_squash_dirent_header { @@ -117,29 +132,46 @@ struct grub_squash_dirent grub_uint16_t ino_offset; grub_uint16_t dummy; grub_uint16_t type; -#define SQUASH_TYPE_DIR 1 -#define SQUASH_TYPE_REGULAR 2 -#define SQUASH_TYPE_SYMLINK 3 /* Actually the value is the length of name - 1. */ grub_uint16_t namelen; char name[0]; } __attribute__ ((packed)); +enum + { + SQUASH_TYPE_DIR = 1, + SQUASH_TYPE_REGULAR = 2, + SQUASH_TYPE_SYMLINK = 3, + SQUASH_TYPE_LONG_REGULAR = 9, + }; + + struct grub_squash_frag_desc { grub_uint64_t offset; - grub_uint64_t dummy; + grub_uint32_t size; + grub_uint32_t dummy; } __attribute__ ((packed)); +enum + { + SQUASH_CHUNK_FLAGS = 0x8000, + SQUASH_CHUNK_UNCOMPRESSED = 0x8000 + }; + +enum + { + SQUASH_BLOCK_FLAGS = 0x1000000, + SQUASH_BLOCK_UNCOMPRESSED = 0x1000000 + }; + #define SQUASH_CHUNK_SIZE 0x2000 -#define SQUASH_CHUNK_FLAGS 0x8000 -#define SQUASH_CHUNK_UNCOMPRESSED 0x8000 struct grub_squash_data { grub_disk_t disk; struct grub_squash_super sb; - struct grub_squash_inode ino; + struct grub_squash_cache_inode ino; grub_uint64_t fragments; }; @@ -147,12 +179,12 @@ struct grub_fshelp_node { struct grub_squash_data *data; struct grub_squash_inode ino; - grub_uint32_t ino_chunk; + grub_disk_addr_t ino_chunk; grub_uint16_t ino_offset; }; static grub_err_t -read_chunk (grub_disk_t disk, void *buf, grub_size_t len, +read_chunk (struct grub_squash_data *data, void *buf, grub_size_t len, grub_uint64_t chunk, grub_off_t offset) { grub_uint64_t chunk_start; @@ -164,7 +196,8 @@ read_chunk (grub_disk_t disk, void *buf, grub_size_t len, grub_err_t err; while (1) { - err = grub_disk_read (disk, chunk_start >> GRUB_DISK_SECTOR_BITS, + err = grub_disk_read (data->disk, + chunk_start >> GRUB_DISK_SECTOR_BITS, chunk_start & (GRUB_DISK_SECTOR_SIZE - 1), sizeof (d), &d); if (err) @@ -182,7 +215,7 @@ read_chunk (grub_disk_t disk, void *buf, grub_size_t len, if (grub_le_to_cpu16 (d) & SQUASH_CHUNK_UNCOMPRESSED) { grub_disk_addr_t a = chunk_start + 2 + offset; - err = grub_disk_read (disk, (a >> GRUB_DISK_SECTOR_BITS), + err = grub_disk_read (data->disk, (a >> GRUB_DISK_SECTOR_BITS), a & (GRUB_DISK_SECTOR_SIZE - 1), csize, buf); if (err) @@ -197,7 +230,7 @@ read_chunk (grub_disk_t disk, void *buf, grub_size_t len, if (!tmp) return grub_errno; /* FIXME: buffer uncompressed data. */ - err = grub_disk_read (disk, (a >> GRUB_DISK_SECTOR_BITS), + err = grub_disk_read (data->disk, (a >> GRUB_DISK_SECTOR_BITS), a & (GRUB_DISK_SECTOR_SIZE - 1), bsize, tmp); if (err) @@ -240,9 +273,10 @@ squash_mount (grub_disk_t disk) return NULL; } - err = grub_disk_read (disk, grub_le_to_cpu32 (sb.unk1offset) + err = grub_disk_read (disk, + grub_le_to_cpu64 (sb.unk1offset) >> GRUB_DISK_SECTOR_BITS, - grub_le_to_cpu32 (sb.unk1offset) + grub_le_to_cpu64 (sb.unk1offset) & (GRUB_DISK_SECTOR_SIZE - 1), sizeof (frag), &frag); if (grub_errno == GRUB_ERR_OUT_OF_RANGE) grub_error (GRUB_ERR_BAD_FS, "not a squash4"); @@ -254,7 +288,7 @@ squash_mount (grub_disk_t disk) return NULL; data->sb = sb; data->disk = disk; - data->fragments = frag; + data->fragments = grub_le_to_cpu64 (frag); return data; } @@ -266,7 +300,7 @@ grub_squash_read_symlink (grub_fshelp_node_t node) grub_err_t err; ret = grub_malloc (grub_le_to_cpu32 (node->ino.symlink.namelen) + 1); - err = read_chunk (node->data->disk, ret, + err = read_chunk (node->data, ret, grub_le_to_cpu32 (node->ino.symlink.namelen), grub_le_to_cpu64 (node->data->sb.inodeoffset) + node->ino_chunk, @@ -300,7 +334,7 @@ grub_squash_iterate_dir (grub_fshelp_node_t dir, struct grub_squash_dirent_header dh; grub_err_t err; - err = read_chunk (dir->data->disk, &dh, sizeof (dh), + err = read_chunk (dir->data, &dh, sizeof (dh), grub_le_to_cpu64 (dir->data->sb.diroffset) + grub_le_to_cpu32 (dir->ino.dir.chunk), off); if (err) @@ -315,14 +349,14 @@ grub_squash_iterate_dir (grub_fshelp_node_t dir, struct grub_squash_dirent di; struct grub_squash_inode ino; - err = read_chunk (dir->data->disk, &di, sizeof (di), + err = read_chunk (dir->data, &di, sizeof (di), grub_le_to_cpu64 (dir->data->sb.diroffset) + grub_le_to_cpu32 (dir->ino.dir.chunk), off); if (err) return 0; off += sizeof (di); - err = read_chunk (dir->data->disk, &ino, sizeof (ino), + err = read_chunk (dir->data, &ino, sizeof (ino), grub_le_to_cpu64 (dir->data->sb.inodeoffset) + grub_le_to_cpu32 (dh.ino_chunk), grub_cpu_to_le16 (di.ino_offset)); @@ -332,7 +366,7 @@ grub_squash_iterate_dir (grub_fshelp_node_t dir, buf = grub_malloc (grub_le_to_cpu16 (di.namelen) + 2); if (!buf) return 0; - err = read_chunk (dir->data->disk, buf, + err = read_chunk (dir->data, buf, grub_le_to_cpu16 (di.namelen) + 1, grub_le_to_cpu64 (dir->data->sb.diroffset) + grub_le_to_cpu32 (dir->ino.dir.chunk), off); @@ -370,7 +404,7 @@ make_root_node (struct grub_squash_data *data, struct grub_fshelp_node *root) grub_memset (root, 0, sizeof (*root)); root->data = data; - return read_chunk (data->disk, &root->ino, sizeof (root->ino), + return read_chunk (data, &root->ino, sizeof (root->ino), grub_le_to_cpu64 (data->sb.inodeoffset) + grub_le_to_cpu16 (data->sb.root_ino_chunk), grub_cpu_to_le16 (data->sb.root_ino_offset)); @@ -445,48 +479,166 @@ grub_squash_open (struct grub_file *file, const char *name) } file->data = data; - data->ino = fdiro->ino; - file->size = grub_le_to_cpu32 (fdiro->ino.file.size); + data->ino.ino = fdiro->ino; + data->ino.block_sizes = NULL; + data->ino.cumulated_block_sizes = NULL; + data->ino.ino_chunk = fdiro->ino_chunk; + data->ino.ino_offset = fdiro->ino_offset; + + if (fdiro->ino.type + == grub_cpu_to_le16_compile_time (SQUASH_TYPE_LONG_REGULAR)) + file->size = grub_le_to_cpu64 (fdiro->ino.long_file.size); + else + file->size = grub_le_to_cpu32 (fdiro->ino.file.size); return GRUB_ERR_NONE; } +static grub_ssize_t +direct_read (struct grub_squash_data *data, + struct grub_squash_cache_inode *ino, + grub_off_t off, char *buf, grub_size_t len) +{ + grub_err_t err; + grub_off_t cumulated_uncompressed_size = 0; + grub_uint64_t a; + grub_size_t i; + grub_size_t origlen = len; + + if (ino->ino.type == grub_cpu_to_le16_compile_time (SQUASH_TYPE_LONG_REGULAR)) + a = grub_le_to_cpu64 (ino->ino.long_file.chunk); + else + a = grub_le_to_cpu32 (ino->ino.file.chunk); + + if (!ino->block_sizes) + { + grub_off_t total_size; + grub_size_t total_blocks; + grub_size_t block_offset; + if (ino->ino.type + == grub_cpu_to_le16_compile_time (SQUASH_TYPE_LONG_REGULAR)) + { + total_size = grub_le_to_cpu64 (ino->ino.long_file.size); + block_offset = ((char *) &ino->ino.long_file.block_size + - (char *) &ino->ino); + } + else + { + total_size = grub_le_to_cpu32 (ino->ino.file.size); + block_offset = ((char *) &ino->ino.file.block_size + - (char *) &ino->ino); + } + total_blocks = grub_divmod64 (total_size + + grub_le_to_cpu32 (data->sb.block_size) - 1, + grub_le_to_cpu32 (data->sb.block_size), + 0); + ino->block_sizes = grub_malloc (total_blocks + * sizeof (ino->block_sizes[0])); + ino->cumulated_block_sizes = grub_malloc (total_blocks + * sizeof (ino->cumulated_block_sizes[0])); + if (!ino->block_sizes || !ino->cumulated_block_sizes) + { + grub_free (ino->block_sizes); + grub_free (ino->cumulated_block_sizes); + ino->block_sizes = 0; + ino->cumulated_block_sizes = 0; + return -1; + } + err = read_chunk (data, ino->block_sizes, + total_blocks * sizeof (ino->block_sizes[0]), + grub_le_to_cpu64 (data->sb.inodeoffset) + + ino->ino_chunk, + ino->ino_offset + block_offset); + if (err) + { + grub_free (ino->block_sizes); + grub_free (ino->cumulated_block_sizes); + ino->block_sizes = 0; + ino->cumulated_block_sizes = 0; + return -1; + } + ino->cumulated_block_sizes[0] = 0; + for (i = 1; i < total_blocks; i++) + ino->cumulated_block_sizes[i] = ino->cumulated_block_sizes[i - 1] + + (grub_le_to_cpu32 (ino->block_sizes[i - 1]) & ~SQUASH_BLOCK_FLAGS); + } + + if (a == 0) + a = sizeof (struct grub_squash_super); + i = grub_divmod64 (off, grub_le_to_cpu32 (data->sb.block_size), 0); + cumulated_uncompressed_size = grub_le_to_cpu32 (data->sb.block_size) + * (grub_disk_addr_t) i; + while (cumulated_uncompressed_size < off + len) + { + grub_size_t boff, read; + boff = off - cumulated_uncompressed_size; + read = grub_le_to_cpu32 (data->sb.block_size) - boff; + if (read > len) + read = len; + if (!(ino->block_sizes[i] & SQUASH_BLOCK_UNCOMPRESSED)) + err = grub_zlib_disk_read (data->disk, + ino->cumulated_block_sizes[i] + a, + boff, buf, read); + else + err = grub_disk_read (data->disk, + (ino->cumulated_block_sizes[i] + a + boff) + >> GRUB_DISK_SECTOR_BITS, + (ino->cumulated_block_sizes[i] + a + boff) + & (GRUB_DISK_SECTOR_SIZE - 1), + read, buf); + if (err) + return -1; + off += read; + len -= read; + buf += read; + cumulated_uncompressed_size += grub_le_to_cpu32 (data->sb.block_size); + i++; + } + return origlen; +} + + static grub_ssize_t grub_squash_read_data (struct grub_squash_data *data, - grub_disk_t disk, const struct grub_squash_inode *ino, + struct grub_squash_cache_inode *ino, grub_off_t off, char *buf, grub_size_t len) { grub_err_t err; grub_uint64_t a, b; + grub_uint32_t fragment; int compressed = 0; + struct grub_squash_frag_desc frag; - if (grub_le_to_cpu16 (ino->file.fragment) == 0xffff) + if (ino->ino.type == grub_cpu_to_le16_compile_time (SQUASH_TYPE_LONG_REGULAR)) { - if (grub_le_to_cpu32 (ino->file.chunk)) - a = grub_le_to_cpu32 (ino->file.chunk); - else - a = sizeof (struct grub_squash_super); - compressed = !(data->sb.flags & SQUASH_FLAG_UNCOMPRESSED_DATA); + a = grub_le_to_cpu64 (ino->ino.long_file.chunk); + fragment = grub_le_to_cpu32 (ino->ino.long_file.fragment); } else { - struct grub_squash_frag_desc frag; - err = read_chunk (disk, &frag, sizeof (frag), - data->fragments, sizeof (frag) - * grub_le_to_cpu16 (ino->file.fragment)); - if (err) - return -1; - a = grub_le_to_cpu64 (frag.offset) + grub_le_to_cpu32 (ino->file.chunk); - compressed = !(data->sb.flags & SQUASH_FLAG_UNCOMPRESSED_FRAGMENTS); + a = grub_le_to_cpu32 (ino->ino.file.chunk); + fragment = grub_le_to_cpu32 (ino->ino.file.fragment); } - b = grub_le_to_cpu32 (data->ino.file.offset) + off; - + if (fragment == 0xffffffff) + return direct_read (data, ino, off, buf, len); + + err = read_chunk (data, &frag, sizeof (frag), + data->fragments, sizeof (frag) * fragment); + if (err) + return -1; + a += grub_le_to_cpu64 (frag.offset); + compressed = !(frag.size & SQUASH_BLOCK_UNCOMPRESSED); + if (ino->ino.type == grub_cpu_to_le16_compile_time (SQUASH_TYPE_LONG_REGULAR)) + b = grub_le_to_cpu64 (ino->ino.long_file.offset) + off; + else + b = grub_le_to_cpu32 (ino->ino.file.offset) + off; + /* FIXME: cache uncompressed chunks. */ if (compressed) - err = grub_zlib_disk_read (disk, a, b, buf, len); + err = grub_zlib_disk_read (data->disk, a, b, buf, len); else - err = grub_disk_read (disk, (a + b) >> GRUB_DISK_SECTOR_BITS, + err = grub_disk_read (data->disk, (a + b) >> GRUB_DISK_SECTOR_BITS, (a + b) & (GRUB_DISK_SECTOR_SIZE - 1), len, buf); if (err) return -1; @@ -498,7 +650,7 @@ grub_squash_read (grub_file_t file, char *buf, grub_size_t len) { struct grub_squash_data *data = file->data; - return grub_squash_read_data (data, file->device->disk, &data->ino, + return grub_squash_read_data (data, &data->ino, file->offset, buf, len); } From d4888031f2577c86f354393bf4e2e5f22ea25bd4 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Tue, 25 Oct 2011 18:12:36 +0200 Subject: [PATCH 861/869] Fix tar 4G limit and handle paths containing dot. * grub-core/fs/cpio.c (grub_cpio_data): Use grub_off_t for offsets. (canonicalize): New function. (grub_cpio_find_file): Use canonicalize. Store offs in grub_disk_addr_t. (grub_cpio_dir): Use grub_disk_addr_t. (grub_cpio_open): Likewise. --- ChangeLog | 11 ++++ grub-core/fs/cpio.c | 134 ++++++++++++++++++++++++++------------------ 2 files changed, 89 insertions(+), 56 deletions(-) diff --git a/ChangeLog b/ChangeLog index 586de218f..19bf1326e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2011-10-25 Vladimir Serbinenko + + Fix tar 4G limit and handle paths containing dot. + + * grub-core/fs/cpio.c (grub_cpio_data): Use grub_off_t for offsets. + (canonicalize): New function. + (grub_cpio_find_file): Use canonicalize. Store offs in + grub_disk_addr_t. + (grub_cpio_dir): Use grub_disk_addr_t. + (grub_cpio_open): Likewise. + 2011-10-25 Vladimir Serbinenko Fix handling of uncompressed blocks on squashfs and break 4G limit. diff --git a/grub-core/fs/cpio.c b/grub-core/fs/cpio.c index 0d84382ac..92531390e 100644 --- a/grub-core/fs/cpio.c +++ b/grub-core/fs/cpio.c @@ -71,80 +71,102 @@ struct head struct grub_cpio_data { grub_disk_t disk; - grub_uint32_t hofs; - grub_uint32_t dofs; - grub_uint32_t size; + grub_off_t hofs; + grub_off_t dofs; + grub_off_t size; }; static grub_dl_t my_mod; +static inline void +canonicalize (char *name) +{ + char *iptr, *optr; + for (iptr = name, optr = name; *iptr; ) + { + while (*iptr == '/') + iptr++; + if (iptr[0] == '.' && (iptr[1] == '/' || iptr[1] == 0)) + { + iptr += 2; + continue; + } + while (*iptr && *iptr != '/') + *optr++ = *iptr++; + if (*iptr) + *optr++ = *iptr++; + } + *optr = 0; +} + static grub_err_t grub_cpio_find_file (struct grub_cpio_data *data, char **name, - grub_int32_t *mtime, grub_uint32_t * ofs) + grub_int32_t *mtime, grub_disk_addr_t * ofs) { #ifndef MODE_USTAR - struct head hd; + struct head hd; - if (grub_disk_read - (data->disk, 0, data->hofs, sizeof (hd), &hd)) - return grub_errno; + if (grub_disk_read (data->disk, 0, data->hofs, sizeof (hd), &hd)) + return grub_errno; - if (hd.magic != MAGIC_BCPIO) - return grub_error (GRUB_ERR_BAD_FS, "invalid cpio archive"); + if (hd.magic != MAGIC_BCPIO) + return grub_error (GRUB_ERR_BAD_FS, "invalid cpio archive"); - data->size = (((grub_uint32_t) hd.filesize_1) << 16) + hd.filesize_2; - if (mtime) - *mtime = (((grub_uint32_t) hd.mtime_1) << 16) + hd.mtime_2; + data->size = (((grub_uint32_t) hd.filesize_1) << 16) + hd.filesize_2; + if (mtime) + *mtime = (((grub_uint32_t) hd.mtime_1) << 16) + hd.mtime_2; - if (hd.namesize & 1) - hd.namesize++; + if (hd.namesize & 1) + hd.namesize++; - if ((*name = grub_malloc (hd.namesize)) == NULL) - return grub_errno; + if ((*name = grub_malloc (hd.namesize)) == NULL) + return grub_errno; - if (grub_disk_read (data->disk, 0, data->hofs + sizeof (hd), - hd.namesize, *name)) - { - grub_free (*name); - return grub_errno; - } + if (grub_disk_read (data->disk, 0, data->hofs + sizeof (hd), + hd.namesize, *name)) + { + grub_free (*name); + return grub_errno; + } - if (data->size == 0 && hd.mode == 0 && hd.namesize == 11 + 1 - && ! grub_memcmp(*name, "TRAILER!!!", 11)) - { - *ofs = 0; - return GRUB_ERR_NONE; - } + if (data->size == 0 && hd.mode == 0 && hd.namesize == 11 + 1 + && ! grub_memcmp(*name, "TRAILER!!!", 11)) + { + *ofs = 0; + return GRUB_ERR_NONE; + } - data->dofs = data->hofs + sizeof (hd) + hd.namesize; - *ofs = data->dofs + data->size; - if (data->size & 1) - (*ofs)++; + canonicalize (*name); + + data->dofs = data->hofs + sizeof (hd) + hd.namesize; + *ofs = data->dofs + data->size; + if (data->size & 1) + (*ofs)++; #else - struct head hd; + struct head hd; - if (grub_disk_read - (data->disk, 0, data->hofs, sizeof (hd), &hd)) - return grub_errno; + if (grub_disk_read (data->disk, 0, data->hofs, sizeof (hd), &hd)) + return grub_errno; - if (!hd.name[0]) - { - *ofs = 0; - return GRUB_ERR_NONE; - } + if (!hd.name[0]) + { + *ofs = 0; + return GRUB_ERR_NONE; + } - if (grub_memcmp (hd.magic, MAGIC_USTAR, sizeof (MAGIC_USTAR) - 1)) - return grub_error (GRUB_ERR_BAD_FS, "invalid tar archive"); + if (grub_memcmp (hd.magic, MAGIC_USTAR, sizeof (MAGIC_USTAR) - 1)) + return grub_error (GRUB_ERR_BAD_FS, "invalid tar archive"); - if ((*name = grub_strdup (hd.name)) == NULL) - return grub_errno; + if ((*name = grub_strdup (hd.name)) == NULL) + return grub_errno; - data->size = grub_strtoul (hd.size, NULL, 8); - data->dofs = data->hofs + GRUB_DISK_SECTOR_SIZE; - *ofs = data->dofs + ((data->size + GRUB_DISK_SECTOR_SIZE - 1) & - ~(GRUB_DISK_SECTOR_SIZE - 1)); - if (mtime) - *mtime = grub_strtoul (hd.mtime, NULL, 8); + data->size = grub_strtoull (hd.size, NULL, 8); + data->dofs = data->hofs + GRUB_DISK_SECTOR_SIZE; + *ofs = data->dofs + ((data->size + GRUB_DISK_SECTOR_SIZE - 1) & + ~(GRUB_DISK_SECTOR_SIZE - 1)); + if (mtime) + *mtime = grub_strtoul (hd.mtime, NULL, 8); + canonicalize (*name); #endif return GRUB_ERR_NONE; } @@ -191,10 +213,10 @@ grub_cpio_dir (grub_device_t device, const char *path, const struct grub_dirhook_info *info)) { struct grub_cpio_data *data; - grub_uint32_t ofs; + grub_disk_addr_t ofs; char *prev, *name; const char *np; - int len; + grub_size_t len; grub_dl_ref (my_mod); @@ -230,7 +252,7 @@ grub_cpio_dir (grub_device_t device, const char *path, if (p) *p = 0; - if ((!prev) || (grub_strcmp (prev, name) != 0)) + if (((!prev) || (grub_strcmp (prev, name) != 0)) && name[len] != 0) { struct grub_dirhook_info info; grub_memset (&info, 0, sizeof (info)); @@ -262,7 +284,7 @@ static grub_err_t grub_cpio_open (grub_file_t file, const char *name) { struct grub_cpio_data *data; - grub_uint32_t ofs; + grub_disk_addr_t ofs; char *fn; int i, j; From e12119495df2f7213169985c10889ec46b205b8e Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Tue, 25 Oct 2011 18:18:58 +0200 Subject: [PATCH 862/869] Support multi-extent iso files. * grub-core/fs/iso9660.c (grub_iso9660_data): Remove first_sector. Add node. (grub_fshelp_node): Revamp. All users updated. (FLAG_*): New enum. (read_node): New function. (grub_iso9660_susp_iterate): Use read_node. Receive a node as argument. All users updated. (grub_iso9660_mount): Don't attempt to read sua when there is none. (get_node_size): New function. (grub_iso9660_iterate_dir): Use read_node. Agglomerate multi-extent entries. Fix memory leak on . and .. (grub_iso9660_read): Use read_node. (grub_iso9660_close): Free node. --- ChangeLog | 19 ++++ grub-core/fs/iso9660.c | 208 +++++++++++++++++++++++++++++------------ 2 files changed, 167 insertions(+), 60 deletions(-) diff --git a/ChangeLog b/ChangeLog index 19bf1326e..a9b26a313 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,22 @@ +2011-10-25 Vladimir Serbinenko + + Support multi-extent iso files. + + * grub-core/fs/iso9660.c (grub_iso9660_data): Remove first_sector. + Add node. + (grub_fshelp_node): Revamp. All users updated. + (FLAG_*): New enum. + (read_node): New function. + (grub_iso9660_susp_iterate): Use read_node. Receive a node as argument. + All users updated. + (grub_iso9660_mount): Don't attempt to read sua when there is none. + (get_node_size): New function. + (grub_iso9660_iterate_dir): Use read_node. Agglomerate multi-extent + entries. + Fix memory leak on . and .. + (grub_iso9660_read): Use read_node. + (grub_iso9660_close): Free node. + 2011-10-25 Vladimir Serbinenko Fix tar 4G limit and handle paths containing dot. diff --git a/grub-core/fs/iso9660.c b/grub-core/fs/iso9660.c index 5b53ca597..f6cbbca95 100644 --- a/grub-core/fs/iso9660.c +++ b/grub-core/fs/iso9660.c @@ -149,22 +149,28 @@ struct grub_iso9660_data { struct grub_iso9660_primary_voldesc voldesc; grub_disk_t disk; - unsigned int first_sector; int rockridge; int susp_skip; int joliet; + struct grub_fshelp_node *node; }; struct grub_fshelp_node { struct grub_iso9660_data *data; - struct grub_iso9660_dir dirent; - unsigned int size; - unsigned int blk; - unsigned int dir_blk; - unsigned int dir_off; + grub_size_t have_dirents, alloc_dirents; + grub_off_t dir_off; + struct grub_iso9660_dir dirents[8]; }; +enum + { + FLAG_TYPE_PLAIN = 0, + FLAG_TYPE_DIR = 2, + FLAG_TYPE = 3, + FLAG_MORE_EXTENTS = 0x80 + }; + static grub_dl_t my_mod; @@ -214,30 +220,69 @@ iso9660_to_unixtime2 (const struct grub_iso9660_date2 *i, grub_int32_t *nix) return 1; } +static grub_err_t +read_node (grub_fshelp_node_t node, grub_off_t off, grub_size_t len, char *buf) +{ + grub_size_t i = 0; + + while (len > 0) + { + grub_size_t toread; + grub_err_t err; + while (i < node->have_dirents + && off >= grub_le_to_cpu32 (node->dirents[i].size)) + { + off -= grub_le_to_cpu32 (node->dirents[i].size); + i++; + } + if (i == node->have_dirents) + return grub_error (GRUB_ERR_OUT_OF_RANGE, "read out of range"); + toread = grub_le_to_cpu32 (node->dirents[i].size); + if (toread > len) + toread = len; + err = grub_disk_read (node->data->disk, + ((grub_disk_addr_t) grub_le_to_cpu32 (node->dirents[i].first_sector)) << GRUB_ISO9660_LOG2_BLKSZ, + off, toread, buf); + if (err) + return err; + len -= toread; + off += toread; + buf += toread; + } + return GRUB_ERR_NONE; +} + /* Iterate over the susp entries, starting with block SUA_BLOCK on the offset SUA_POS with a size of SUA_SIZE bytes. Hook is called for every entry. */ static grub_err_t -grub_iso9660_susp_iterate (struct grub_iso9660_data *data, - int sua_block, int sua_pos, int sua_size, +grub_iso9660_susp_iterate (grub_fshelp_node_t node, grub_off_t off, + grub_size_t sua_size, grub_err_t (*hook) (struct grub_iso9660_susp_entry *entry)) { char *sua; struct grub_iso9660_susp_entry *entry; + grub_disk_addr_t ce_block; + int is_ce = 0; auto grub_err_t load_sua (void); /* Load a part of the System Usage Area. */ grub_err_t load_sua (void) { + grub_err_t err; sua = grub_malloc (sua_size); if (!sua) return grub_errno; - if (grub_disk_read (data->disk, sua_block, sua_pos, - sua_size, sua)) - return grub_errno; + if (is_ce) + err = grub_disk_read (node->data->disk, ce_block, off, + sua_size, sua); + else + err = read_node (node, off, sua_size, sua); + if (err) + return err; entry = (struct grub_iso9660_susp_entry *) sua; return 0; @@ -259,10 +304,11 @@ grub_iso9660_susp_iterate (struct grub_iso9660_data *data, { struct grub_iso9660_susp_ce *ce; + is_ce = 1; ce = (struct grub_iso9660_susp_ce *) entry; sua_size = grub_le_to_cpu32 (ce->len); - sua_pos = grub_le_to_cpu32 (ce->off); - sua_block = grub_le_to_cpu32 (ce->blk) << GRUB_ISO9660_LOG2_BLKSZ; + off = grub_le_to_cpu32 (ce->off); + ce_block = grub_le_to_cpu32 (ce->blk) << GRUB_ISO9660_LOG2_BLKSZ; grub_free (sua); if (load_sua ()) @@ -383,6 +429,9 @@ grub_iso9660_mount (grub_disk_t disk) + (rootdir.namelen % 2) - 1); sua_size = rootdir.len - sua_pos; + if (!sua_size) + return data; + sua = grub_malloc (sua_size); if (! sua) goto fail; @@ -400,6 +449,14 @@ grub_iso9660_mount (grub_disk_t disk) /* Test if the SUSP protocol is used on this filesystem. */ if (grub_strncmp ((char *) entry->sig, "SP", 2) == 0) { + struct grub_fshelp_node rootnode; + + rootnode.data = data; + rootnode.alloc_dirents = 0; + rootnode.have_dirents = 1; + rootnode.dir_off = 0; + rootnode.dirents[0] = data->voldesc.rootdir; + /* The 2nd data byte stored how many bytes are skipped every time to get to the SUA (System Usage Area). */ data->susp_skip = entry->data[2]; @@ -407,9 +464,7 @@ grub_iso9660_mount (grub_disk_t disk) /* Iterate over the entries in the SUA area to detect extensions. */ - if (grub_iso9660_susp_iterate (data, - (grub_le_to_cpu32 (data->voldesc.rootdir.first_sector) - << GRUB_ISO9660_LOG2_BLKSZ), + if (grub_iso9660_susp_iterate (&rootnode, sua_pos, sua_size, susp_iterate)) goto fail; } @@ -502,10 +557,10 @@ grub_iso9660_read_symlink (grub_fshelp_node_t node) return 0; } - sua_off = (sizeof (node->dirent) + node->dirent.namelen + 1 - - (node->dirent.namelen % 2) + sua_off = (sizeof (node->dirents[0]) + node->dirents[0].namelen + 1 + - (node->dirents[0].namelen % 2) + node->data->susp_skip); - sua_size = node->dirent.len - sua_off; + sua_size = node->dirents[0].len - sua_off; symlink = grub_malloc (1); if (!symlink) @@ -513,8 +568,7 @@ grub_iso9660_read_symlink (grub_fshelp_node_t node) *symlink = '\0'; - if (grub_iso9660_susp_iterate (node->data, node->dir_blk, - node->dir_off + sua_off, + if (grub_iso9660_susp_iterate (node, node->dir_off + sua_off, sua_size, susp_iterate_sl)) { grub_free (symlink); @@ -524,6 +578,16 @@ grub_iso9660_read_symlink (grub_fshelp_node_t node) return symlink; } +static grub_off_t +get_node_size (grub_fshelp_node_t node) +{ + grub_off_t ret = 0; + grub_size_t i; + + for (i = 0; i < node->have_dirents; i++) + ret += grub_le_to_cpu32 (node->dirents[i].size); + return ret; +} static int grub_iso9660_iterate_dir (grub_fshelp_node_t dir, @@ -533,10 +597,11 @@ grub_iso9660_iterate_dir (grub_fshelp_node_t dir, grub_fshelp_node_t node)) { struct grub_iso9660_dir dirent; - unsigned int offset = 0; + grub_off_t offset = 0; char *filename; int filename_alloc = 0; enum grub_fshelp_filetype type; + grub_off_t len; auto grub_err_t susp_iterate_dir (struct grub_iso9660_susp_entry *); @@ -598,13 +663,11 @@ grub_iso9660_iterate_dir (grub_fshelp_node_t dir, return 0; } - for (; offset < dir->size; offset += dirent.len) + len = get_node_size (dir); + + for (; offset < len; offset += dirent.len) { - if (grub_disk_read (dir->data->disk, - (dir->blk << GRUB_ISO9660_LOG2_BLKSZ) - + offset / GRUB_DISK_SECTOR_SIZE, - offset % GRUB_DISK_SECTOR_SIZE, - sizeof (dirent), (char *) &dirent)) + if (read_node (dir, offset, sizeof (dirent), (char *) &dirent)) return 0; /* The end of the block, skip to the next one. */ @@ -629,39 +692,30 @@ grub_iso9660_iterate_dir (grub_fshelp_node_t dir, type = GRUB_FSHELP_UNKNOWN; if (dir->data->rockridge - && grub_iso9660_susp_iterate (dir->data, - (dir->blk << GRUB_ISO9660_LOG2_BLKSZ) - + (sua_off - / GRUB_DISK_SECTOR_SIZE), - sua_off % GRUB_DISK_SECTOR_SIZE, - sua_size, susp_iterate_dir)) + && grub_iso9660_susp_iterate (dir, sua_off, sua_size, + susp_iterate_dir)) return 0; /* Read the name. */ - if (grub_disk_read (dir->data->disk, - (dir->blk << GRUB_ISO9660_LOG2_BLKSZ) - + nameoffset / GRUB_DISK_SECTOR_SIZE, - nameoffset % GRUB_DISK_SECTOR_SIZE, - dirent.namelen, (char *) name)) + if (read_node (dir, nameoffset, dirent.namelen, (char *) name)) return 0; node = grub_malloc (sizeof (struct grub_fshelp_node)); if (!node) return 0; + node->alloc_dirents = ARRAY_SIZE (node->dirents); + node->have_dirents = 1; + /* Setup a new node. */ node->data = dir->data; - node->size = grub_le_to_cpu32 (dirent.size); - node->blk = grub_le_to_cpu32 (dirent.first_sector); - node->dir_blk = ((dir->blk << GRUB_ISO9660_LOG2_BLKSZ) - + offset / GRUB_DISK_SECTOR_SIZE); - node->dir_off = offset % GRUB_DISK_SECTOR_SIZE; + node->dir_off = offset; /* If the filetype was not stored using rockridge, use whatever is stored in the iso9660 filesystem. */ if (type == GRUB_FSHELP_UNKNOWN) { - if ((dirent.flags & 3) == 2) + if ((dirent.flags & FLAG_TYPE) == FLAG_TYPE_DIR) type = GRUB_FSHELP_DIR; else type = GRUB_FSHELP_REG; @@ -678,7 +732,10 @@ grub_iso9660_iterate_dir (grub_fshelp_node_t dir, /* . and .. */ if (dirent.namelen == 1 && (name[0] == 0 || name[0] == 1)) - continue; + { + grub_free (node); + continue; + } else filename = name; } @@ -701,7 +758,35 @@ grub_iso9660_iterate_dir (grub_fshelp_node_t dir, filename_alloc = 1; } - node->dirent = dirent; + node->dirents[0] = dirent; + while (dirent.flags & FLAG_MORE_EXTENTS) + { + offset += dirent.len; + if (read_node (dir, offset, sizeof (dirent), (char *) &dirent)) + { + if (filename_alloc) + grub_free (filename); + grub_free (node); + return 0; + } + if (node->have_dirents >= node->alloc_dirents) + { + struct grub_fshelp_node *new_node; + node->alloc_dirents *= 2; + new_node = grub_malloc (sizeof (struct grub_fshelp_node) + + ((node->alloc_dirents + - ARRAY_SIZE (node->dirents)) + * sizeof (node->dirents[0]))); + if (!new_node) + { + if (filename_alloc) + grub_free (filename); + grub_free (node); + return 0; + } + } + node->dirents[node->have_dirents++] = dirent; + } if (hook (filename, type, node)) { if (filename_alloc) @@ -738,7 +823,7 @@ grub_iso9660_dir (grub_device_t device, const char *path, struct grub_dirhook_info info; grub_memset (&info, 0, sizeof (info)); info.dir = ((filetype & GRUB_FSHELP_TYPE_MASK) == GRUB_FSHELP_DIR); - info.mtimeset = !!iso9660_to_unixtime2 (&node->dirent.mtime, &info.mtime); + info.mtimeset = !!iso9660_to_unixtime2 (&node->dirents[0].mtime, &info.mtime); grub_free (node); return hook (filename, &info); @@ -751,8 +836,10 @@ grub_iso9660_dir (grub_device_t device, const char *path, goto fail; rootnode.data = data; - rootnode.blk = grub_le_to_cpu32 (data->voldesc.rootdir.first_sector); - rootnode.size = grub_le_to_cpu32 (data->voldesc.rootdir.size); + rootnode.alloc_dirents = 0; + rootnode.have_dirents = 1; + rootnode.dir_off = 0; + rootnode.dirents[0] = data->voldesc.rootdir; /* Use the fshelp function to traverse the path. */ if (grub_fshelp_find_file (path, &rootnode, @@ -792,8 +879,10 @@ grub_iso9660_open (struct grub_file *file, const char *name) goto fail; rootnode.data = data; - rootnode.blk = grub_le_to_cpu32 (data->voldesc.rootdir.first_sector); - rootnode.size = grub_le_to_cpu32 (data->voldesc.rootdir.size); + rootnode.alloc_dirents = 0; + rootnode.have_dirents = 1; + rootnode.dir_off = 0; + rootnode.dirents[0] = data->voldesc.rootdir; /* Use the fshelp function to traverse the path. */ if (grub_fshelp_find_file (name, &rootnode, @@ -803,10 +892,9 @@ grub_iso9660_open (struct grub_file *file, const char *name) GRUB_FSHELP_REG)) goto fail; - data->first_sector = foundnode->blk; - + data->node = foundnode; file->data = data; - file->size = foundnode->size; + file->size = get_node_size (foundnode); file->offset = 0; return 0; @@ -828,10 +916,7 @@ grub_iso9660_read (grub_file_t file, char *buf, grub_size_t len) /* XXX: The file is stored in as a single extent. */ data->disk->read_hook = file->read_hook; - grub_disk_read (data->disk, - data->first_sector << GRUB_ISO9660_LOG2_BLKSZ, - file->offset, - len, buf); + read_node (data->node, file->offset, len, buf); data->disk->read_hook = NULL; if (grub_errno) @@ -844,7 +929,10 @@ grub_iso9660_read (grub_file_t file, char *buf, grub_size_t len) static grub_err_t grub_iso9660_close (grub_file_t file) { - grub_free (file->data); + struct grub_iso9660_data *data = + (struct grub_iso9660_data *) file->data; + grub_free (data->node); + grub_free (data); grub_dl_unref (my_mod); From db82136381f991edb8fe9bb28406a03ec1d19e2d Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Tue, 25 Oct 2011 18:20:39 +0200 Subject: [PATCH 863/869] * grub-core/loader/i386/bsd.c (grub_netbsd_add_boot_disk_and_wedge): Use union to avoid breaking strict-aliasing rules. --- ChangeLog | 5 +++++ grub-core/loader/i386/bsd.c | 20 +++++++++++--------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index a9b26a313..8c8af24e4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-10-25 Vladimir Serbinenko + + * grub-core/loader/i386/bsd.c (grub_netbsd_add_boot_disk_and_wedge): + Use union to avoid breaking strict-aliasing rules. + 2011-10-25 Vladimir Serbinenko Support multi-extent iso files. diff --git a/grub-core/loader/i386/bsd.c b/grub-core/loader/i386/bsd.c index 18ebeb760..f2d0845f8 100644 --- a/grub-core/loader/i386/bsd.c +++ b/grub-core/loader/i386/bsd.c @@ -960,8 +960,10 @@ grub_netbsd_add_boot_disk_and_wedge (void) grub_partition_t part; grub_uint32_t biosdev; grub_uint32_t partmapsector; - struct grub_partition_bsd_disk_label *label; - grub_uint64_t buf[GRUB_DISK_SECTOR_SIZE / 8]; + union { + grub_uint64_t raw[GRUB_DISK_SECTOR_SIZE / 8]; + struct grub_partition_bsd_disk_label label; + } buf; grub_uint8_t *hash; grub_uint64_t ctx[(GRUB_MD_MD5->contextsize + 7) / 8]; @@ -981,7 +983,8 @@ grub_netbsd_add_boot_disk_and_wedge (void) partmapsector = grub_partition_get_start (part->parent) + part->offset; disk->partition = part->parent; - if (grub_disk_read (disk, part->offset, 0, GRUB_DISK_SECTOR_SIZE, buf) != GRUB_ERR_NONE) + if (grub_disk_read (disk, part->offset, 0, GRUB_DISK_SECTOR_SIZE, buf.raw) + != GRUB_ERR_NONE) goto fail; disk->partition = part; @@ -997,7 +1000,7 @@ grub_netbsd_add_boot_disk_and_wedge (void) biw.matchnblks = 1; GRUB_MD_MD5->init (&ctx); - GRUB_MD_MD5->write (&ctx, buf, GRUB_DISK_SECTOR_SIZE); + GRUB_MD_MD5->write (&ctx, buf.raw, GRUB_DISK_SECTOR_SIZE); GRUB_MD_MD5->final (&ctx); hash = GRUB_MD_MD5->read (&ctx); memcpy (biw.matchhash, hash, 16); @@ -1006,18 +1009,17 @@ grub_netbsd_add_boot_disk_and_wedge (void) } /* Fill bootdisk if this a NetBSD disk label. */ - label = (struct grub_partition_bsd_disk_label *) &buf; if (part->partmap != NULL && (grub_strcmp (part->partmap->name, "netbsd") == 0) && - label->magic == grub_cpu_to_le32 (GRUB_PC_PARTITION_BSD_LABEL_MAGIC)) + buf.label.magic == grub_cpu_to_le32 (GRUB_PC_PARTITION_BSD_LABEL_MAGIC)) { struct grub_netbsd_btinfo_bootdisk bid; grub_memset (&bid, 0, sizeof (bid)); bid.labelsector = partmapsector; - bid.label.type = label->type; - bid.label.checksum = label->checksum; - memcpy (bid.label.packname, label->packname, 16); + bid.label.type = buf.label.type; + bid.label.checksum = buf.label.checksum; + memcpy (bid.label.packname, buf.label.packname, 16); bid.biosdev = biosdev; bid.partition = part->number; grub_bsd_add_meta (NETBSD_BTINFO_BOOTDISK, &bid, sizeof (bid)); From 66b40850331be5979d85a3d0583c7bd74c704b08 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Tue, 25 Oct 2011 21:52:48 +0200 Subject: [PATCH 864/869] Fix symlink handling on iso9660. * grub-core/fs/iso9660.c (grub_fshelp_node): Remove dir_off. Add symlink All users updated. (grub_iso9660_susp_iterate): Accept zero-size iterate. (grub_iso9660_read_symlink): Moved most of code ... (grub_iso9660_iterate_dir): ... here. Fill node->symlink. --- ChangeLog | 10 +++ grub-core/fs/iso9660.c | 182 ++++++++++++++++++----------------------- 2 files changed, 90 insertions(+), 102 deletions(-) diff --git a/ChangeLog b/ChangeLog index 8c8af24e4..d40675db7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2011-10-25 Vladimir Serbinenko + + Fix symlink handling on iso9660. + + * grub-core/fs/iso9660.c (grub_fshelp_node): Remove dir_off. Add symlink + All users updated. + (grub_iso9660_susp_iterate): Accept zero-size iterate. + (grub_iso9660_read_symlink): Moved most of code ... + (grub_iso9660_iterate_dir): ... here. Fill node->symlink. + 2011-10-25 Vladimir Serbinenko * grub-core/loader/i386/bsd.c (grub_netbsd_add_boot_disk_and_wedge): diff --git a/grub-core/fs/iso9660.c b/grub-core/fs/iso9660.c index f6cbbca95..f3e828b89 100644 --- a/grub-core/fs/iso9660.c +++ b/grub-core/fs/iso9660.c @@ -159,7 +159,7 @@ struct grub_fshelp_node { struct grub_iso9660_data *data; grub_size_t have_dirents, alloc_dirents; - grub_off_t dir_off; + char *symlink; struct grub_iso9660_dir dirents[8]; }; @@ -257,7 +257,7 @@ read_node (grub_fshelp_node_t node, grub_off_t off, grub_size_t len, char *buf) every entry. */ static grub_err_t grub_iso9660_susp_iterate (grub_fshelp_node_t node, grub_off_t off, - grub_size_t sua_size, + grub_ssize_t sua_size, grub_err_t (*hook) (struct grub_iso9660_susp_entry *entry)) { @@ -288,6 +288,9 @@ grub_iso9660_susp_iterate (grub_fshelp_node_t node, grub_off_t off, return 0; } + if (sua_size <= 0) + return GRUB_ERR_NONE; + if (load_sua ()) return grub_errno; @@ -454,7 +457,7 @@ grub_iso9660_mount (grub_disk_t disk) rootnode.data = data; rootnode.alloc_dirents = 0; rootnode.have_dirents = 1; - rootnode.dir_off = 0; + rootnode.symlink = 0; rootnode.dirents[0] = data->voldesc.rootdir; /* The 2nd data byte stored how many bytes are skipped every time @@ -480,102 +483,7 @@ grub_iso9660_mount (grub_disk_t disk) static char * grub_iso9660_read_symlink (grub_fshelp_node_t node) { - int sua_off; - int sua_size; - char *symlink = 0; - int addslash = 0; - - auto void add_part (const char *part, int len); - auto grub_err_t susp_iterate_sl (struct grub_iso9660_susp_entry *); - - /* Extend the symlink. */ - void add_part (const char *part, int len) - { - int size = grub_strlen (symlink); - - symlink = grub_realloc (symlink, size + len + 1); - if (! symlink) - return; - - grub_strncat (symlink, part, len); - } - - /* Read in a symlink. */ - grub_err_t susp_iterate_sl (struct grub_iso9660_susp_entry *entry) - { - if (grub_strncmp ("SL", (char *) entry->sig, 2) == 0) - { - unsigned int pos = 1; - - /* The symlink is not stored as a POSIX symlink, translate it. */ - while (pos < grub_le_to_cpu32 (entry->len)) - { - if (addslash) - { - add_part ("/", 1); - addslash = 0; - } - - /* The current position is the `Component Flag'. */ - switch (entry->data[pos] & 30) - { - case 0: - { - /* The data on pos + 2 is the actual data, pos + 1 - is the length. Both are part of the `Component - Record'. */ - add_part ((char *) &entry->data[pos + 2], - entry->data[pos + 1]); - if ((entry->data[pos] & 1)) - addslash = 1; - - break; - } - - case 2: - add_part ("./", 2); - break; - - case 4: - add_part ("../", 3); - break; - - case 8: - add_part ("/", 1); - break; - } - /* In pos + 1 the length of the `Component Record' is - stored. */ - pos += entry->data[pos + 1] + 2; - } - - /* Check if `grub_realloc' failed. */ - if (grub_errno) - return grub_errno; - } - - return 0; - } - - sua_off = (sizeof (node->dirents[0]) + node->dirents[0].namelen + 1 - - (node->dirents[0].namelen % 2) - + node->data->susp_skip); - sua_size = node->dirents[0].len - sua_off; - - symlink = grub_malloc (1); - if (!symlink) - return 0; - - *symlink = '\0'; - - if (grub_iso9660_susp_iterate (node, node->dir_off + sua_off, - sua_size, susp_iterate_sl)) - { - grub_free (symlink); - return 0; - } - - return symlink; + return node->symlink ? grub_strdup (node->symlink) : grub_strdup (""); } static grub_off_t @@ -602,6 +510,23 @@ grub_iso9660_iterate_dir (grub_fshelp_node_t dir, int filename_alloc = 0; enum grub_fshelp_filetype type; grub_off_t len; + char *symlink = 0; + int addslash = 0; + + auto void add_part (const char *part, int len); + + /* Extend the symlink. */ + void add_part (const char *part, int len2) + { + int size = symlink ? grub_strlen (symlink) : 0; + + symlink = grub_realloc (symlink, size + len2 + 1); + if (! symlink) + return; + + symlink[size] = 0; + grub_strncat (symlink, part, len2); + } auto grub_err_t susp_iterate_dir (struct grub_iso9660_susp_entry *); @@ -659,6 +584,56 @@ grub_iso9660_iterate_dir (grub_fshelp_node_t dir, type = GRUB_FSHELP_UNKNOWN; } } + else if (grub_strncmp ("SL", (char *) entry->sig, 2) == 0) + { + unsigned int pos = 1; + + /* The symlink is not stored as a POSIX symlink, translate it. */ + while (pos + sizeof (*entry) < grub_le_to_cpu32 (entry->len)) + { + if (addslash) + { + add_part ("/", 1); + addslash = 0; + } + + /* The current position is the `Component Flag'. */ + switch (entry->data[pos] & 30) + { + case 0: + { + /* The data on pos + 2 is the actual data, pos + 1 + is the length. Both are part of the `Component + Record'. */ + add_part ((char *) &entry->data[pos + 2], + entry->data[pos + 1]); + if ((entry->data[pos] & 1)) + addslash = 1; + + break; + } + + case 2: + add_part ("./", 2); + break; + + case 4: + add_part ("../", 3); + break; + + case 8: + add_part ("/", 1); + break; + } + /* In pos + 1 the length of the `Component Record' is + stored. */ + pos += entry->data[pos + 1] + 2; + } + + /* Check if `grub_realloc' failed. */ + if (grub_errno) + return grub_errno; + } return 0; } @@ -667,6 +642,9 @@ grub_iso9660_iterate_dir (grub_fshelp_node_t dir, for (; offset < len; offset += dirent.len) { + symlink = 0; + addslash = 0; + if (read_node (dir, offset, sizeof (dirent), (char *) &dirent)) return 0; @@ -709,7 +687,7 @@ grub_iso9660_iterate_dir (grub_fshelp_node_t dir, /* Setup a new node. */ node->data = dir->data; - node->dir_off = offset; + node->symlink = symlink; /* If the filetype was not stored using rockridge, use whatever is stored in the iso9660 filesystem. */ @@ -838,7 +816,7 @@ grub_iso9660_dir (grub_device_t device, const char *path, rootnode.data = data; rootnode.alloc_dirents = 0; rootnode.have_dirents = 1; - rootnode.dir_off = 0; + rootnode.symlink = 0; rootnode.dirents[0] = data->voldesc.rootdir; /* Use the fshelp function to traverse the path. */ @@ -881,7 +859,7 @@ grub_iso9660_open (struct grub_file *file, const char *name) rootnode.data = data; rootnode.alloc_dirents = 0; rootnode.have_dirents = 1; - rootnode.dir_off = 0; + rootnode.symlink = 0; rootnode.dirents[0] = data->voldesc.rootdir; /* Use the fshelp function to traverse the path. */ From 19832ddb37a6e4a034a2501954fd01a8ff935c73 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Tue, 25 Oct 2011 21:53:57 +0200 Subject: [PATCH 865/869] * grub-core/fs/fat.c (grub_fat_uuid): Make uppercase to match Linux. --- ChangeLog | 4 ++++ grub-core/fs/fat.c | 3 +++ 2 files changed, 7 insertions(+) diff --git a/ChangeLog b/ChangeLog index d40675db7..9f05edaa2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2011-10-25 Vladimir Serbinenko + + * grub-core/fs/fat.c (grub_fat_uuid): Make uppercase to match Linux. + 2011-10-25 Vladimir Serbinenko Fix symlink handling on iso9660. diff --git a/grub-core/fs/fat.c b/grub-core/fs/fat.c index 36a43fca0..fb1113814 100644 --- a/grub-core/fs/fat.c +++ b/grub-core/fs/fat.c @@ -1117,9 +1117,12 @@ grub_fat_uuid (grub_device_t device, char **uuid) data = grub_fat_mount (disk); if (data) { + char *ptr; *uuid = grub_xasprintf ("%04x-%04x", (grub_uint16_t) (data->uuid >> 16), (grub_uint16_t) data->uuid); + for (ptr = *uuid; ptr && *ptr; ptr++) + *ptr = grub_toupper (*ptr); } else *uuid = NULL; From e9cc6b7b0e26f38b22a72ecc931273b22a9e1d2a Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 26 Oct 2011 00:29:46 +0200 Subject: [PATCH 866/869] * grub-core/fs/ntfs.c (grub_ntfs_uuid): Fix a memory leak. --- ChangeLog | 4 ++++ grub-core/fs/ntfs.c | 5 +++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9f05edaa2..3b0b4697a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2011-10-25 Vladimir Serbinenko + + * grub-core/fs/ntfs.c (grub_ntfs_uuid): Fix a memory leak. + 2011-10-25 Vladimir Serbinenko * grub-core/fs/fat.c (grub_fat_uuid): Make uppercase to match Linux. diff --git a/grub-core/fs/ntfs.c b/grub-core/fs/ntfs.c index 5d128bcc0..6b8455c34 100644 --- a/grub-core/fs/ntfs.c +++ b/grub-core/fs/ntfs.c @@ -1087,14 +1087,15 @@ grub_ntfs_uuid (grub_device_t device, char **uuid) if (*uuid) for (ptr = *uuid; *ptr; ptr++) *ptr = grub_toupper (*ptr); + free_file (&data->mmft); + free_file (&data->cmft); + grub_free (data); } else *uuid = NULL; grub_dl_unref (my_mod); - grub_free (data); - return grub_errno; } From 67e2bd718e9ddd0571a28358e8928dc320e2d76e Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 26 Oct 2011 00:32:17 +0200 Subject: [PATCH 867/869] Read label on HFS+. * grub-core/fs/hfsplus.c (grub_hfsplus_cmp_catkey_id): New function. (grub_hfsplus_btree_search): Fix types. (grub_hfsplus_label): Implement. --- ChangeLog | 8 ++++ grub-core/fs/hfsplus.c | 87 ++++++++++++++++++++++++++++++++++++++---- 2 files changed, 88 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3b0b4697a..17e215b62 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2011-10-25 Vladimir Serbinenko + + Read label on HFS+. + + * grub-core/fs/hfsplus.c (grub_hfsplus_cmp_catkey_id): New function. + (grub_hfsplus_btree_search): Fix types. + (grub_hfsplus_label): Implement. + 2011-10-25 Vladimir Serbinenko * grub-core/fs/ntfs.c (grub_ntfs_uuid): Fix a memory leak. diff --git a/grub-core/fs/hfsplus.c b/grub-core/fs/hfsplus.c index 245cd93a5..3d9bc42fa 100644 --- a/grub-core/fs/hfsplus.c +++ b/grub-core/fs/hfsplus.c @@ -553,6 +553,25 @@ grub_hfsplus_cmp_catkey (struct grub_hfsplus_key *keya, return diff; } +/* Compare the on disk catalog key KEYA with the catalog key we are + looking for (KEYB). */ +static int +grub_hfsplus_cmp_catkey_id (struct grub_hfsplus_key *keya, + struct grub_hfsplus_key_internal *keyb) +{ + struct grub_hfsplus_catkey *catkey_a = &keya->catkey; + struct grub_hfsplus_catkey_internal *catkey_b = &keyb->catkey; + + /* Safe unsigned comparison */ + grub_uint32_t aparent = grub_be_to_cpu32 (catkey_a->parent); + if (aparent > catkey_b->parent) + return 1; + if (aparent < catkey_b->parent) + return -1; + + return 0; +} + /* Compare the on disk extent overflow key KEYA with the extent overflow key we are looking for (KEYB). */ static int @@ -662,7 +681,8 @@ grub_hfsplus_btree_search (struct grub_hfsplus_btree *btree, /* Read a node. */ if (grub_hfsplus_read_file (&btree->file, 0, - (long)currnode * (long)btree->nodesize, + (grub_disk_addr_t) currnode + * (grub_disk_addr_t) btree->nodesize, btree->nodesize, (char *) node) <= 0) { grub_free (node); @@ -961,13 +981,66 @@ grub_hfsplus_dir (grub_device_t device, const char *path, static grub_err_t -grub_hfsplus_label (grub_device_t device __attribute__((unused)) - , char **label __attribute__((unused))) +grub_hfsplus_label (grub_device_t device, char **label) { - /* XXX: It's not documented how to read a label. */ - return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, - "reading the label of a HFS+ " - "partition is not implemented"); + struct grub_hfsplus_data *data; + grub_disk_t disk = device->disk; + struct grub_hfsplus_catkey *catkey; + int i, label_len; + struct grub_hfsplus_key_internal intern; + struct grub_hfsplus_btnode *node; + grub_disk_addr_t ptr; + + *label = 0; + + data = grub_hfsplus_mount (disk); + if (!data) + return grub_errno; + + /* Create a key that points to the label. */ + intern.catkey.parent = 1; + intern.catkey.name = ""; + + /* First lookup the first entry. */ + if (grub_hfsplus_btree_search (&data->catalog_tree, &intern, + grub_hfsplus_cmp_catkey_id, &node, &ptr)) + { + grub_free (data); + return 0; + } + + catkey = (struct grub_hfsplus_catkey *) + grub_hfsplus_btree_recptr (&data->catalog_tree, node, 0); + + label_len = grub_be_to_cpu16 (catkey->namelen); + for (i = 0; i < label_len; i++) + { + catkey->name[i] = grub_be_to_cpu16 (catkey->name[i]); + + /* If the name is obviously invalid, skip this node. */ + if (catkey->name[i] == 0) + return 0; + } + + *label = grub_malloc (label_len + 1); + if (! *label) + return grub_errno; + + if (! grub_utf16_to_utf8 ((grub_uint8_t *) (*label), catkey->name, + label_len)) + { + grub_free (node); + grub_free (*label); + grub_free (data); + *label = 0; + return grub_errno; + } + (*label)[label_len] = '\0'; + + grub_free (node); + grub_free (data); + + return GRUB_ERR_NONE; } /* Get mtime. */ From c0584900ee804a1b8d1a687cfd042321f05f2150 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 26 Oct 2011 00:35:41 +0200 Subject: [PATCH 868/869] * grub-core/fs/jfs.c (grub_jfs_sblock): Fix offset to volname. --- ChangeLog | 4 ++++ grub-core/fs/jfs.c | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 17e215b62..683fd53f3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2011-10-25 Vladimir Serbinenko + + * grub-core/fs/jfs.c (grub_jfs_sblock): Fix offset to volname. + 2011-10-25 Vladimir Serbinenko Read label on HFS+. diff --git a/grub-core/fs/jfs.c b/grub-core/fs/jfs.c index 4a7bb0214..c5e82bfec 100644 --- a/grub-core/fs/jfs.c +++ b/grub-core/fs/jfs.c @@ -52,9 +52,9 @@ struct grub_jfs_sblock grub_uint32_t blksz; grub_uint16_t log2_blksz; - grub_uint8_t unused[71]; + grub_uint8_t unused[79]; grub_uint8_t volname[11]; - grub_uint8_t unused2[32]; + grub_uint8_t unused2[24]; grub_uint8_t uuid[16]; }; From 5587329c914465659893d484363d919c1fe35c71 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 26 Oct 2011 17:32:21 +0200 Subject: [PATCH 869/869] ZFS fixes. * grub-core/fs/zfs/zfs.c (fzap_iterate): Fix handling of indexes sharing the same block. Iterate over correct number of indices. (dnode_get_path): Handle symlinks correctly. --- ChangeLog | 8 ++++++ grub-core/fs/zfs/zfs.c | 64 +++++++++++++++++++++++++++++++++--------- 2 files changed, 59 insertions(+), 13 deletions(-) diff --git a/ChangeLog b/ChangeLog index 683fd53f3..9787d8f9e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2011-10-25 Vladimir Serbinenko + + ZFS fixes. + + * grub-core/fs/zfs/zfs.c (fzap_iterate): Fix handling of indexes + sharing the same block. Iterate over correct number of indices. + (dnode_get_path): Handle symlinks correctly. + 2011-10-25 Vladimir Serbinenko * grub-core/fs/jfs.c (grub_jfs_sblock): Fix offset to volname. diff --git a/grub-core/fs/zfs/zfs.c b/grub-core/fs/zfs/zfs.c index 9d6ad7055..6721cddc1 100644 --- a/grub-core/fs/zfs/zfs.c +++ b/grub-core/fs/zfs/zfs.c @@ -941,7 +941,7 @@ fzap_iterate (dnode_end_t * zap_dnode, zap_phys_t * zap, { zap_leaf_phys_t *l; void *l_in; - grub_uint64_t idx, blkid; + grub_uint64_t idx, idx2, blkid; grub_uint16_t chunk; int blksft = zfs_log2 (grub_zfs_to_cpu16 (zap_dnode->dn.dn_datablkszsec, zap_dnode->endian) << DNODE_SHIFT); @@ -964,10 +964,16 @@ fzap_iterate (dnode_end_t * zap_dnode, zap_phys_t * zap, grub_error (GRUB_ERR_BAD_FS, "ZAP leaf is too small"); return 0; } - for (idx = 0; idx < zap->zap_ptrtbl.zt_numblks; idx++) + for (idx = 0; idx < (1ULL << zap->zap_ptrtbl.zt_shift); idx++) { blkid = ((grub_uint64_t *) zap)[idx + (1 << (blksft - 3 - 1))]; + for (idx2 = 0; idx2 < idx; idx2++) + if (blkid == ((grub_uint64_t *) zap)[idx2 + (1 << (blksft - 3 - 1))]) + break; + if (idx2 != idx) + continue; + err = dmu_read (zap_dnode, blkid, &l_in, &endian, data); l = l_in; if (err) @@ -1093,7 +1099,7 @@ zap_iterate (dnode_end_t * zap_dnode, return 0; block_type = grub_zfs_to_cpu64 (*((grub_uint64_t *) zapbuf), endian); - grub_dprintf ("zfs", "zap read\n"); + grub_dprintf ("zfs", "zap iterate\n"); if (block_type == ZBT_MICRO) { @@ -1310,22 +1316,55 @@ dnode_get_path (dnode_end_t * mdn, const char *path_in, dnode_end_t * dn, break; *path = ch; -#if 0 - if (((grub_zfs_to_cpu64(((znode_phys_t *) DN_BONUS (&dnode_path->dn.dn))->zp_mode, dnode_path->dn.endian) >> 12) & 0xf) == 0xa && ch) + if (((grub_zfs_to_cpu64(((znode_phys_t *) DN_BONUS (&dnode_path->dn.dn))->zp_mode, dnode_path->dn.endian) >> 12) & 0xf) == 0xa) { + char *sym_value; + grub_size_t avail_in_dnode; + grub_size_t sym_sz; + int free_symval = 0; char *oldpath = path, *oldpathbuf = path_buf; - path = path_buf - = grub_malloc (sizeof (dnode_path->dn.dn.dn_bonus) - - sizeof (znode_phys_t) + grub_strlen (oldpath) + 1); + sym_value = ((char *) DN_BONUS (&dnode_path->dn.dn) + sizeof (struct znode_phys)); + avail_in_dnode = (char *) (&dnode_path->dn + 1) - sym_value; + + sym_sz = grub_zfs_to_cpu64 (((znode_phys_t *) DN_BONUS (&dnode_path->dn.dn))->zp_size, dnode_path->dn.endian); + + if (sym_sz > avail_in_dnode - 8) + { + grub_size_t block; + grub_size_t blksz; + blksz = (grub_zfs_to_cpu16 (dnode_path->dn.dn.dn_datablkszsec, + dnode_path->dn.endian) + << SPA_MINBLOCKSHIFT); + + sym_value = grub_malloc (sym_sz); + if (!sym_value) + return grub_errno; + for (block = 0; block < (sym_sz + blksz - 1) / blksz; block++) + { + void *t; + grub_size_t movesize; + + err = dmu_read (&(dnode_path->dn), block, &t, 0, data); + if (err) + return err; + + movesize = MIN (sym_sz - block * blksz, blksz); + + grub_memcpy (sym_value + block * blksz, t, movesize); + grub_free (t); + } + free_symval = 1; + } + path = path_buf = grub_malloc (sym_sz + grub_strlen (oldpath) + 1); if (!path_buf) { grub_free (oldpathbuf); return grub_errno; } - grub_memcpy (path, - (char *) DN_BONUS(&dnode_path->dn.dn) + sizeof (znode_phys_t), - sizeof (dnode_path->dn.dn.dn_bonus) - sizeof (znode_phys_t)); - path [sizeof (dnode_path->dn.dn.dn_bonus) - sizeof (znode_phys_t)] = 0; + grub_memcpy (path, sym_value, sym_sz); + if (free_symval) + grub_free (sym_value); + path [sym_sz] = 0; grub_memcpy (path + grub_strlen (path), oldpath, grub_strlen (oldpath) + 1); @@ -1343,7 +1382,6 @@ dnode_get_path (dnode_end_t * mdn, const char *path_in, dnode_end_t * dn, grub_free (dn_new); } } -#endif } if (!err)