merge mainline and various cleanups
This commit is contained in:
commit
3666d5f636
380 changed files with 14873 additions and 1961 deletions
|
@ -29,6 +29,8 @@
|
|||
#include <grub/util/resolve.h>
|
||||
#include <grub/misc.h>
|
||||
#include <grub/offsets.h>
|
||||
#include <grub/crypto.h>
|
||||
#include <grub/dl.h>
|
||||
#include <time.h>
|
||||
|
||||
#include <stdio.h>
|
||||
|
@ -57,14 +59,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_LOONGSON_ELF, IMAGE_QEMU, IMAGE_PPC, IMAGE_YEELOONG_FLASH,
|
||||
IMAGE_FULOONG_FLASH, IMAGE_I386_PC_PXE, IMAGE_MIPS_ARC
|
||||
} id;
|
||||
enum
|
||||
{
|
||||
|
@ -86,12 +89,21 @@ struct image_target_desc
|
|||
grub_uint64_t link_addr;
|
||||
unsigned mod_gap, mod_align;
|
||||
grub_compression_t default_compression;
|
||||
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[] =
|
||||
{
|
||||
{
|
||||
.name = "i386-coreboot",
|
||||
.dirname = "i386-coreboot",
|
||||
.names = { "i386-coreboot", NULL },
|
||||
.voidp_sizeof = 4,
|
||||
.bigendian = 0,
|
||||
.id = IMAGE_COREBOOT,
|
||||
|
@ -113,7 +125,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,
|
||||
|
@ -135,7 +148,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,
|
||||
|
@ -153,7 +167,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,
|
||||
|
@ -171,7 +186,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,
|
||||
|
@ -191,9 +207,12 @@ 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",
|
||||
.dirname = "i386-ieee1275",
|
||||
.names = { "i386-ieee1275", NULL },
|
||||
.voidp_sizeof = 4,
|
||||
.bigendian = 0,
|
||||
.id = IMAGE_I386_IEEE1275,
|
||||
|
@ -215,7 +234,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,
|
||||
|
@ -233,7 +253,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,
|
||||
|
@ -245,59 +266,82 @@ 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,
|
||||
.elf_target = EM_X86_64,
|
||||
},
|
||||
{
|
||||
.name = "mipsel-yeeloong-flash",
|
||||
.dirname = "mips-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
|
||||
},
|
||||
{
|
||||
.name = "mipsel-yeeloong-elf",
|
||||
.dirname = "mips-loongson",
|
||||
.names = { "mipsel-fuloong-flash", NULL },
|
||||
.voidp_sizeof = 4,
|
||||
.bigendian = 0,
|
||||
.id = IMAGE_YEELOONG_ELF,
|
||||
.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
|
||||
},
|
||||
{
|
||||
.name = "powerpc-ieee1275",
|
||||
.dirname = "mips-loongson",
|
||||
.names = { "mipsel-loongson-elf", "mipsel-yeeloong-elf",
|
||||
"mipsel-fuloong-elf", NULL },
|
||||
.voidp_sizeof = 4,
|
||||
.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,
|
||||
.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_LOONGSON_LINK_ADDR,
|
||||
.elf_target = EM_MIPS,
|
||||
.link_align = GRUB_KERNEL_MIPS_LOONGSON_LINK_ALIGN,
|
||||
.default_compression = COMPRESSION_NONE
|
||||
},
|
||||
{
|
||||
.dirname = "powerpc-ieee1275",
|
||||
.names = { "powerpc-ieee1275", NULL },
|
||||
.voidp_sizeof = 4,
|
||||
.bigendian = 1,
|
||||
.id = IMAGE_PPC,
|
||||
|
@ -319,7 +363,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,
|
||||
|
@ -337,7 +382,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,
|
||||
|
@ -354,6 +400,70 @@ struct image_target_desc image_targets[] =
|
|||
.install_bsd_part = TARGET_NO_FIELD,
|
||||
.link_addr = GRUB_KERNEL_SPARC64_IEEE1275_LINK_ADDR
|
||||
},
|
||||
{
|
||||
.dirname = "ia64-efi",
|
||||
.names = {"ia64-efi", NULL},
|
||||
.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 = EFI64_HEADER_SIZE,
|
||||
.install_dos_part = TARGET_NO_FIELD,
|
||||
.install_bsd_part = TARGET_NO_FIELD,
|
||||
.pe_target = GRUB_PE32_MACHINE_IA64,
|
||||
.elf_target = EM_IA_64,
|
||||
},
|
||||
{
|
||||
.dirname = "mips-arc",
|
||||
.names = {"mips-arc", NULL},
|
||||
.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
|
||||
},
|
||||
{
|
||||
.dirname = "mips-qemu_mips",
|
||||
.names = { "mips-qemu_mips-elf", NULL },
|
||||
.voidp_sizeof = 4,
|
||||
.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,
|
||||
.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)))
|
||||
|
@ -799,10 +909,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;
|
||||
|
@ -901,12 +1011,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);
|
||||
|
@ -927,10 +1032,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));
|
||||
|
@ -1162,17 +1264,63 @@ 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;
|
||||
char *boot_path, *boot_img;
|
||||
size_t boot_size;
|
||||
|
||||
boot_path = grub_util_get_path (dir, "fwstart.img");
|
||||
grub_uint8_t context[GRUB_MD_SHA512->contextsize];
|
||||
/* fwstart.img is the only part which can't be tested by using *-elf
|
||||
target. Check it against the checksum. */
|
||||
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);
|
||||
|
||||
rom_size = ALIGN_UP (core_size + boot_size, 512 * 1024);
|
||||
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");
|
||||
|
||||
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);
|
||||
|
@ -1189,7 +1337,77 @@ generate_image (const char *dir, char *prefix, FILE *out, char *mods[],
|
|||
core_size = rom_size;
|
||||
}
|
||||
break;
|
||||
case IMAGE_YEELOONG_ELF:
|
||||
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_LOONGSON_ELF:
|
||||
case IMAGE_PPC:
|
||||
case IMAGE_COREBOOT:
|
||||
case IMAGE_I386_IEEE1275:
|
||||
|
@ -1202,7 +1420,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)
|
||||
|
@ -1237,7 +1455,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));
|
||||
|
@ -1250,7 +1468,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
|
||||
|
@ -1259,12 +1477,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);
|
||||
|
@ -1379,12 +1597,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++ = ' ';
|
||||
}
|
||||
|
@ -1454,10 +1672,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);
|
||||
|
@ -1552,25 +1772,19 @@ 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,
|
||||
argv + optind, memdisk, config,
|
||||
image_target, note, comp);
|
||||
|
||||
fflush (fp);
|
||||
fsync (fileno (fp));
|
||||
fclose (fp);
|
||||
|
||||
if (dir)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue