remove all trailing whitespace
This commit is contained in:
parent
d2d4966571
commit
b39f9d20a9
222 changed files with 3286 additions and 3286 deletions
|
@ -92,7 +92,7 @@ read_kernel_module (const char *dir, size_t *size)
|
|||
{
|
||||
char *kernel_image;
|
||||
char *kernel_path;
|
||||
|
||||
|
||||
kernel_path = grub_util_get_path (dir, "kernel.mod");
|
||||
*size = grub_util_get_image_size (kernel_path);
|
||||
kernel_image = grub_util_read_image (kernel_path);
|
||||
|
@ -162,7 +162,7 @@ locate_sections (Elf_Shdr *sections, Elf_Half section_entsize,
|
|||
Elf_Addr current_address;
|
||||
Elf_Addr *section_addresses;
|
||||
Elf_Shdr *s;
|
||||
|
||||
|
||||
section_addresses = xmalloc (sizeof (*section_addresses) * num_sections);
|
||||
memset (section_addresses, 0, sizeof (*section_addresses) * num_sections);
|
||||
|
||||
|
@ -176,10 +176,10 @@ locate_sections (Elf_Shdr *sections, Elf_Half section_entsize,
|
|||
{
|
||||
Elf_Word align = grub_le_to_cpu32 (s->sh_addralign);
|
||||
const char *name = strtab + grub_le_to_cpu32 (s->sh_name);
|
||||
|
||||
|
||||
if (align)
|
||||
current_address = align_address (current_address, align);
|
||||
|
||||
|
||||
grub_util_info ("locating the section %s at 0x%x",
|
||||
name, current_address);
|
||||
section_addresses[i] = current_address;
|
||||
|
@ -196,10 +196,10 @@ locate_sections (Elf_Shdr *sections, Elf_Half section_entsize,
|
|||
{
|
||||
Elf_Word align = grub_le_to_cpu32 (s->sh_addralign);
|
||||
const char *name = strtab + grub_le_to_cpu32 (s->sh_name);
|
||||
|
||||
|
||||
if (align)
|
||||
current_address = align_address (current_address, align);
|
||||
|
||||
|
||||
grub_util_info ("locating the section %s at 0x%x",
|
||||
name, current_address);
|
||||
section_addresses[i] = current_address;
|
||||
|
@ -216,7 +216,7 @@ find_symtab_section (Elf_Shdr *sections,
|
|||
{
|
||||
int i;
|
||||
Elf_Shdr *s;
|
||||
|
||||
|
||||
for (i = 0, s = sections;
|
||||
i < num_sections;
|
||||
i++, s = (Elf_Shdr *) ((char *) s + section_entsize))
|
||||
|
@ -232,7 +232,7 @@ find_strtab (Elf_Ehdr *e, Elf_Shdr *sections, Elf_Half section_entsize)
|
|||
{
|
||||
Elf_Shdr *s;
|
||||
char *strtab;
|
||||
|
||||
|
||||
s = (Elf_Shdr *) ((char *) sections
|
||||
+ grub_le_to_cpu16 (e->e_shstrndx) * section_entsize);
|
||||
strtab = (char *) e + grub_le_to_cpu32 (s->sh_offset);
|
||||
|
@ -253,13 +253,13 @@ relocate_symbols (Elf_Ehdr *e, Elf_Shdr *sections,
|
|||
Elf_Word i;
|
||||
Elf_Shdr *strtab_section;
|
||||
const char *strtab;
|
||||
|
||||
|
||||
strtab_section
|
||||
= (Elf_Shdr *) ((char *) sections
|
||||
+ (grub_le_to_cpu32 (symtab_section->sh_link)
|
||||
* section_entsize));
|
||||
strtab = (char *) e + grub_le_to_cpu32 (strtab_section->sh_offset);
|
||||
|
||||
|
||||
symtab_size = grub_le_to_cpu32 (symtab_section->sh_size);
|
||||
sym_size = grub_le_to_cpu32 (symtab_section->sh_entsize);
|
||||
symtab_offset = grub_le_to_cpu32 (symtab_section->sh_offset);
|
||||
|
@ -271,9 +271,9 @@ relocate_symbols (Elf_Ehdr *e, Elf_Shdr *sections,
|
|||
{
|
||||
Elf_Section index;
|
||||
const char *name;
|
||||
|
||||
|
||||
name = strtab + grub_le_to_cpu32 (sym->st_name);
|
||||
|
||||
|
||||
index = grub_le_to_cpu16 (sym->st_shndx);
|
||||
if (index == STN_ABS)
|
||||
{
|
||||
|
@ -288,7 +288,7 @@ 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_le_to_cpu32 (sym->st_value)
|
||||
+ section_addresses[index]);
|
||||
grub_util_info ("locating %s at 0x%x", name, sym->st_value);
|
||||
|
@ -306,7 +306,7 @@ static Elf_Addr
|
|||
get_symbol_address (Elf_Ehdr *e, Elf_Shdr *s, Elf_Word i)
|
||||
{
|
||||
Elf_Sym *sym;
|
||||
|
||||
|
||||
sym = (Elf_Sym *) ((char *) e
|
||||
+ grub_le_to_cpu32 (s->sh_offset)
|
||||
+ i * grub_le_to_cpu32 (s->sh_entsize));
|
||||
|
@ -332,7 +332,7 @@ relocate_addresses (Elf_Ehdr *e, Elf_Shdr *sections,
|
|||
{
|
||||
Elf_Half i;
|
||||
Elf_Shdr *s;
|
||||
|
||||
|
||||
for (i = 0, s = sections;
|
||||
i < num_sections;
|
||||
i++, s = (Elf_Shdr *) ((char *) s + section_entsize))
|
||||
|
@ -375,7 +375,7 @@ relocate_addresses (Elf_Ehdr *e, Elf_Shdr *sections,
|
|||
Elf_Addr sym_addr;
|
||||
Elf_Addr *target;
|
||||
Elf_Addr addend;
|
||||
|
||||
|
||||
offset = grub_le_to_cpu (r->r_offset);
|
||||
target = get_target_address (e, target_section, offset);
|
||||
info = grub_le_to_cpu (r->r_info);
|
||||
|
@ -414,7 +414,7 @@ relocate_addresses (Elf_Ehdr *e, Elf_Shdr *sections,
|
|||
break;
|
||||
|
||||
case R_X86_64_64:
|
||||
*target = grub_cpu_to_le64 (grub_le_to_cpu64 (*target)
|
||||
*target = grub_cpu_to_le64 (grub_le_to_cpu64 (*target)
|
||||
+ addend + sym_addr);
|
||||
grub_util_info ("relocating an R_X86_64_64 entry to 0x%llx at the offset 0x%llx",
|
||||
*target, offset);
|
||||
|
@ -470,7 +470,7 @@ add_fixup_entry (struct grub_pe32_fixup_block **block, grub_uint16_t type,
|
|||
FILE *out)
|
||||
{
|
||||
struct grub_pe32_fixup_block *b = *block;
|
||||
|
||||
|
||||
/* First, check if it is necessary to write out the current block. */
|
||||
if (b)
|
||||
{
|
||||
|
@ -485,7 +485,7 @@ add_fixup_entry (struct grub_pe32_fixup_block **block, grub_uint16_t type,
|
|||
Elf_Addr next_address;
|
||||
unsigned padding_size;
|
||||
size_t index;
|
||||
|
||||
|
||||
next_address = current_address + b->block_size;
|
||||
padding_size = ((align_pe32_section (next_address)
|
||||
- next_address)
|
||||
|
@ -528,7 +528,7 @@ add_fixup_entry (struct grub_pe32_fixup_block **block, grub_uint16_t type,
|
|||
{
|
||||
grub_uint16_t entry;
|
||||
size_t index;
|
||||
|
||||
|
||||
/* If not allocated yet, allocate a block with enough entries. */
|
||||
if (! b)
|
||||
{
|
||||
|
@ -559,7 +559,7 @@ static Elf_Addr
|
|||
make_header_space (FILE *out)
|
||||
{
|
||||
Elf_Addr addr;
|
||||
|
||||
|
||||
addr = get_starting_section_address ();
|
||||
write_padding (out, addr);
|
||||
|
||||
|
@ -576,7 +576,7 @@ write_text_sections (FILE *out, Elf_Addr current_address,
|
|||
Elf_Half i;
|
||||
Elf_Shdr *s;
|
||||
Elf_Addr addr;
|
||||
|
||||
|
||||
for (i = 0, s = sections;
|
||||
i < num_sections;
|
||||
i++, s = (Elf_Shdr *) ((char *) s + section_entsize))
|
||||
|
@ -586,7 +586,7 @@ write_text_sections (FILE *out, Elf_Addr current_address,
|
|||
Elf_Off offset = grub_le_to_cpu32 (s->sh_offset);
|
||||
Elf_Word size = grub_le_to_cpu32 (s->sh_size);
|
||||
const char *name = strtab + grub_le_to_cpu32 (s->sh_name);
|
||||
|
||||
|
||||
if (align)
|
||||
{
|
||||
addr = align_address (current_address, align);
|
||||
|
@ -598,13 +598,13 @@ write_text_sections (FILE *out, Elf_Addr current_address,
|
|||
current_address = addr;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
grub_util_info ("writing the text section %s at 0x%x",
|
||||
name, current_address);
|
||||
|
||||
|
||||
if (fwrite ((char *) e + offset, size, 1, out) != 1)
|
||||
grub_util_error ("write failed");
|
||||
|
||||
|
||||
current_address += size;
|
||||
}
|
||||
|
||||
|
@ -615,7 +615,7 @@ write_text_sections (FILE *out, Elf_Addr current_address,
|
|||
addr - current_address);
|
||||
write_padding (out, addr - current_address);
|
||||
}
|
||||
|
||||
|
||||
return addr;
|
||||
}
|
||||
|
||||
|
@ -629,7 +629,7 @@ write_data_sections (FILE *out, Elf_Addr current_address,
|
|||
Elf_Half i;
|
||||
Elf_Shdr *s;
|
||||
Elf_Addr addr;
|
||||
|
||||
|
||||
for (i = 0, s = sections;
|
||||
i < num_sections;
|
||||
i++, s = (Elf_Shdr *) ((char *) s + section_entsize))
|
||||
|
@ -639,7 +639,7 @@ write_data_sections (FILE *out, Elf_Addr current_address,
|
|||
Elf_Off offset = grub_le_to_cpu32 (s->sh_offset);
|
||||
Elf_Word size = grub_le_to_cpu32 (s->sh_size);
|
||||
const char *name = strtab + grub_le_to_cpu32 (s->sh_name);
|
||||
|
||||
|
||||
if (align)
|
||||
{
|
||||
addr = align_address (current_address, align);
|
||||
|
@ -651,19 +651,19 @@ write_data_sections (FILE *out, Elf_Addr current_address,
|
|||
current_address = addr;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
grub_util_info ("writing the data section %s at 0x%x",
|
||||
name, current_address);
|
||||
|
||||
|
||||
if (s->sh_type == grub_cpu_to_le32 (SHT_NOBITS))
|
||||
write_padding (out, size);
|
||||
else
|
||||
if (fwrite ((char *) e + offset, size, 1, out) != 1)
|
||||
grub_util_error ("write failed");
|
||||
|
||||
|
||||
current_address += size;
|
||||
}
|
||||
|
||||
|
||||
addr = align_pe32_section (current_address);
|
||||
if (addr != current_address)
|
||||
{
|
||||
|
@ -671,7 +671,7 @@ write_data_sections (FILE *out, Elf_Addr current_address,
|
|||
addr - current_address);
|
||||
write_padding (out, addr - current_address);
|
||||
}
|
||||
|
||||
|
||||
return addr;
|
||||
}
|
||||
|
||||
|
@ -689,7 +689,7 @@ make_mods_section (FILE *out, Elf_Addr current_address,
|
|||
memset (&modinfo, 0, sizeof (modinfo));
|
||||
|
||||
path_list = grub_util_resolve_dependencies (dir, "moddep.lst", mods);
|
||||
|
||||
|
||||
total_module_size = sizeof (struct grub_module_info);
|
||||
for (p = path_list; p; p = p->next)
|
||||
{
|
||||
|
@ -711,15 +711,15 @@ make_mods_section (FILE *out, Elf_Addr current_address,
|
|||
struct grub_module_header header;
|
||||
size_t mod_size;
|
||||
char *mod_image;
|
||||
|
||||
|
||||
memset (&header, 0, sizeof (header));
|
||||
|
||||
|
||||
grub_util_info ("adding module %s", p->name);
|
||||
|
||||
|
||||
mod_size = grub_util_get_image_size (p->name);
|
||||
header.type = grub_cpu_to_le32 (OBJ_TYPE_ELF);
|
||||
header.size = grub_cpu_to_le32 (mod_size + sizeof (header));
|
||||
|
||||
|
||||
mod_image = grub_util_read_image (p->name);
|
||||
|
||||
if (fwrite (&header, sizeof (header), 1, out) != 1
|
||||
|
@ -728,7 +728,7 @@ make_mods_section (FILE *out, Elf_Addr current_address,
|
|||
|
||||
free (mod_image);
|
||||
}
|
||||
|
||||
|
||||
for (p = path_list; p; )
|
||||
{
|
||||
struct grub_util_path_list *q;
|
||||
|
@ -737,9 +737,9 @@ make_mods_section (FILE *out, Elf_Addr current_address,
|
|||
free (p);
|
||||
p = q;
|
||||
}
|
||||
|
||||
|
||||
current_address += total_module_size;
|
||||
|
||||
|
||||
addr = align_pe32_section (current_address);
|
||||
if (addr != current_address)
|
||||
{
|
||||
|
@ -761,7 +761,7 @@ make_reloc_section (FILE *out, Elf_Addr current_address, Elf_Ehdr *e,
|
|||
Elf_Half i;
|
||||
Elf_Shdr *s;
|
||||
struct grub_pe32_fixup_block *fixup_block = 0;
|
||||
|
||||
|
||||
for (i = 0, s = sections;
|
||||
i < num_sections;
|
||||
i++, s = (Elf_Shdr *) ((char *) s + section_entsize))
|
||||
|
@ -773,15 +773,15 @@ make_reloc_section (FILE *out, Elf_Addr current_address, Elf_Ehdr *e,
|
|||
Elf_Off rtab_offset;
|
||||
Elf_Addr section_address;
|
||||
Elf_Word j;
|
||||
|
||||
|
||||
grub_util_info ("translating the relocation section %s",
|
||||
strtab + grub_le_to_cpu32 (s->sh_name));
|
||||
|
||||
|
||||
rtab_size = grub_le_to_cpu32 (s->sh_size);
|
||||
r_size = grub_le_to_cpu32 (s->sh_entsize);
|
||||
rtab_offset = grub_le_to_cpu32 (s->sh_offset);
|
||||
num_rs = rtab_size / r_size;
|
||||
|
||||
|
||||
section_address = section_addresses[grub_le_to_cpu32 (s->sh_info)];
|
||||
|
||||
for (j = 0, r = (Elf_Rel *) ((char *) e + rtab_offset);
|
||||
|
@ -888,7 +888,7 @@ make_header (FILE *out, Elf_Addr text_address, Elf_Addr data_address,
|
|||
o->image_size = grub_cpu_to_le32 (end_address);
|
||||
o->header_size = grub_cpu_to_le32 (text_address);
|
||||
o->subsystem = grub_cpu_to_le16 (GRUB_PE32_SUBSYSTEM_EFI_APPLICATION);
|
||||
|
||||
|
||||
/* Do these really matter? */
|
||||
o->stack_reserve_size = grub_cpu_to_le32 (0x10000);
|
||||
o->stack_commit_size = grub_cpu_to_le32 (0x10000);
|
||||
|
@ -896,7 +896,7 @@ make_header (FILE *out, Elf_Addr text_address, Elf_Addr data_address,
|
|||
o->heap_commit_size = grub_cpu_to_le32 (0x10000);
|
||||
|
||||
o->num_data_directories = grub_cpu_to_le32 (GRUB_PE32_NUM_DATA_DIRECTORIES);
|
||||
|
||||
|
||||
o->base_relocation_table.rva = grub_cpu_to_le32 (reloc_address);
|
||||
o->base_relocation_table.size = grub_cpu_to_le32 (end_address
|
||||
- reloc_address);
|
||||
|
@ -982,7 +982,7 @@ convert_elf (const char *dir, char *prefix, FILE *out, char *mods[])
|
|||
e = (Elf_Ehdr *) kernel_image;
|
||||
if (! check_elf_header (e, kernel_size))
|
||||
grub_util_error ("invalid ELF header");
|
||||
|
||||
|
||||
section_offset = grub_cpu_to_le32 (e->e_shoff);
|
||||
section_entsize = grub_cpu_to_le16 (e->e_shentsize);
|
||||
num_sections = grub_cpu_to_le16 (e->e_shnum);
|
||||
|
@ -1002,20 +1002,20 @@ convert_elf (const char *dir, char *prefix, FILE *out, char *mods[])
|
|||
|
||||
if (GRUB_KERNEL_MACHINE_PREFIX + strlen (prefix) + 1 > GRUB_KERNEL_MACHINE_DATA_END)
|
||||
grub_util_error ("prefix too long");
|
||||
|
||||
|
||||
strcpy (kernel_image + offset + GRUB_KERNEL_MACHINE_PREFIX, prefix);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
/* Relocate sections then symbols in the virtual address space. */
|
||||
section_addresses = locate_sections (sections, section_entsize,
|
||||
num_sections, strtab);
|
||||
|
||||
|
||||
symtab_section = find_symtab_section (sections,
|
||||
section_entsize, num_sections);
|
||||
if (! symtab_section)
|
||||
grub_util_error ("no symbol table");
|
||||
|
||||
|
||||
start_address = relocate_symbols (e, sections, symtab_section,
|
||||
section_addresses, section_entsize,
|
||||
num_sections);
|
||||
|
|
|
@ -58,11 +58,11 @@ compress_kernel (char *kernel_img, size_t kernel_size,
|
|||
{
|
||||
lzo_uint size;
|
||||
char *wrkmem;
|
||||
|
||||
|
||||
grub_util_info ("kernel_img=%p, kernel_size=0x%x", kernel_img, kernel_size);
|
||||
if (kernel_size < GRUB_KERNEL_MACHINE_RAW_SIZE)
|
||||
grub_util_error ("the core image is too small");
|
||||
|
||||
|
||||
if (lzo_init () != LZO_E_OK)
|
||||
grub_util_error ("cannot initialize LZO");
|
||||
|
||||
|
@ -70,7 +70,7 @@ compress_kernel (char *kernel_img, size_t kernel_size,
|
|||
wrkmem = xmalloc (LZO1X_999_MEM_COMPRESS);
|
||||
|
||||
memcpy (*core_img, kernel_img, GRUB_KERNEL_MACHINE_RAW_SIZE);
|
||||
|
||||
|
||||
grub_util_info ("compressing the core image");
|
||||
if (lzo1x_999_compress ((const lzo_byte *) (kernel_img
|
||||
+ GRUB_KERNEL_MACHINE_RAW_SIZE),
|
||||
|
@ -189,7 +189,7 @@ generate_image (const char *dir, char *prefix, FILE *out, char *mods[],
|
|||
size_t mod_size;
|
||||
|
||||
mod_size = grub_util_get_image_size (p->name);
|
||||
|
||||
|
||||
header = (struct grub_module_header *) (kernel_img + offset);
|
||||
header->type = grub_cpu_to_le32 (OBJ_TYPE_ELF);
|
||||
header->size = grub_cpu_to_le32 (mod_size + sizeof (*header));
|
||||
|
@ -202,7 +202,7 @@ generate_image (const char *dir, char *prefix, FILE *out, char *mods[],
|
|||
if (memdisk_path)
|
||||
{
|
||||
struct grub_module_header *header;
|
||||
|
||||
|
||||
header = (struct grub_module_header *) (kernel_img + offset);
|
||||
header->type = grub_cpu_to_le32 (OBJ_TYPE_MEMDISK);
|
||||
header->size = grub_cpu_to_le32 (memdisk_size + sizeof (*header));
|
||||
|
@ -230,7 +230,7 @@ generate_image (const char *dir, char *prefix, FILE *out, char *mods[],
|
|||
&core_img, &core_size);
|
||||
|
||||
grub_util_info ("the core size is 0x%x", core_size);
|
||||
|
||||
|
||||
num = ((core_size + GRUB_DISK_SECTOR_SIZE - 1) >> GRUB_DISK_SECTOR_BITS);
|
||||
if (num > 0xffff)
|
||||
grub_util_error ("the core image is too big");
|
||||
|
@ -239,9 +239,9 @@ generate_image (const char *dir, char *prefix, FILE *out, char *mods[],
|
|||
boot_size = grub_util_get_image_size (boot_path);
|
||||
if (boot_size != GRUB_DISK_SECTOR_SIZE)
|
||||
grub_util_error ("diskboot.img is not one sector size");
|
||||
|
||||
|
||||
boot_img = grub_util_read_image (boot_path);
|
||||
|
||||
|
||||
/* i386 is a little endian architecture. */
|
||||
*((grub_uint16_t *) (boot_img + GRUB_DISK_SECTOR_SIZE
|
||||
- GRUB_BOOT_MACHINE_LIST_SIZE + 8))
|
||||
|
@ -250,7 +250,7 @@ generate_image (const char *dir, char *prefix, FILE *out, char *mods[],
|
|||
grub_util_write_image (boot_img, boot_size, out);
|
||||
free (boot_img);
|
||||
free (boot_path);
|
||||
|
||||
|
||||
module_addr = (path_list
|
||||
? (GRUB_BOOT_MACHINE_KERNEL_ADDR + GRUB_DISK_SECTOR_SIZE
|
||||
+ kernel_size)
|
||||
|
@ -277,7 +277,7 @@ generate_image (const char *dir, char *prefix, FILE *out, char *mods[],
|
|||
if (core_size > GRUB_MEMORY_MACHINE_UPPER - GRUB_MEMORY_MACHINE_LINK_ADDR)
|
||||
grub_util_error ("Core image is too big (%p > %p)\n", core_size,
|
||||
GRUB_MEMORY_MACHINE_UPPER - GRUB_MEMORY_MACHINE_LINK_ADDR);
|
||||
|
||||
|
||||
grub_util_write_image (core_img, core_size, out);
|
||||
free (kernel_img);
|
||||
free (core_img);
|
||||
|
@ -344,7 +344,7 @@ main (int argc, char *argv[])
|
|||
FILE *fp = stdout;
|
||||
|
||||
progname = "grub-mkimage";
|
||||
|
||||
|
||||
while (1)
|
||||
{
|
||||
int c = getopt_long (argc, argv, "d:p:m:c:o:hVv", options, 0);
|
||||
|
@ -357,7 +357,7 @@ main (int argc, char *argv[])
|
|||
case 'o':
|
||||
if (output)
|
||||
free (output);
|
||||
|
||||
|
||||
output = xstrdup (optarg);
|
||||
break;
|
||||
|
||||
|
@ -373,7 +373,7 @@ main (int argc, char *argv[])
|
|||
free (memdisk);
|
||||
|
||||
memdisk = xstrdup (optarg);
|
||||
|
||||
|
||||
if (prefix)
|
||||
free (prefix);
|
||||
|
||||
|
|
|
@ -110,7 +110,7 @@ setup (const char *dir,
|
|||
FILE *fp;
|
||||
struct { grub_uint64_t start; grub_uint64_t end; } embed_region;
|
||||
embed_region.start = embed_region.end = ~0UL;
|
||||
|
||||
|
||||
auto void NESTED_FUNC_ATTR save_first_sector (grub_disk_addr_t sector, unsigned offset,
|
||||
unsigned length);
|
||||
auto void NESTED_FUNC_ATTR save_blocklists (grub_disk_addr_t sector, unsigned offset,
|
||||
|
@ -122,44 +122,44 @@ setup (const char *dir,
|
|||
const grub_partition_t p)
|
||||
{
|
||||
struct grub_pc_partition *pcdata = p->data;
|
||||
|
||||
|
||||
/* There's always an embed region, and it starts right after the MBR. */
|
||||
embed_region.start = 1;
|
||||
|
||||
|
||||
/* For its end offset, include as many dummy partitions as we can. */
|
||||
if (! grub_pc_partition_is_empty (pcdata->dos_type)
|
||||
&& ! grub_pc_partition_is_bsd (pcdata->dos_type)
|
||||
&& embed_region.end > p->start)
|
||||
embed_region.end = p->start;
|
||||
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
auto int NESTED_FUNC_ATTR find_usable_region_gpt (grub_disk_t disk,
|
||||
const grub_partition_t p);
|
||||
int NESTED_FUNC_ATTR find_usable_region_gpt (grub_disk_t disk __attribute__ ((unused)),
|
||||
const grub_partition_t p)
|
||||
{
|
||||
struct grub_gpt_partentry *gptdata = p->data;
|
||||
|
||||
|
||||
/* If there's an embed region, it is in a dedicated partition. */
|
||||
if (! memcmp (&gptdata->type, &grub_gpt_partition_type_bios_boot, 16))
|
||||
{
|
||||
embed_region.start = p->start;
|
||||
embed_region.end = p->start + p->len;
|
||||
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void NESTED_FUNC_ATTR save_first_sector (grub_disk_addr_t sector, unsigned offset,
|
||||
unsigned length)
|
||||
{
|
||||
grub_util_info ("the first sector is <%llu,%u,%u>",
|
||||
sector, offset, length);
|
||||
|
||||
|
||||
if (offset != 0 || length != GRUB_DISK_SECTOR_SIZE)
|
||||
grub_util_error ("The first sector of the core file is not sector-aligned");
|
||||
|
||||
|
@ -173,7 +173,7 @@ setup (const char *dir,
|
|||
|
||||
grub_util_info ("saving <%llu,%u,%u> with the segment 0x%x",
|
||||
sector, offset, length, (unsigned) current_segment);
|
||||
|
||||
|
||||
if (offset != 0 || last_length != GRUB_DISK_SECTOR_SIZE)
|
||||
grub_util_error ("Non-sector-aligned data is found in the core file");
|
||||
|
||||
|
@ -191,11 +191,11 @@ setup (const char *dir,
|
|||
if (block->len)
|
||||
grub_util_error ("The sectors of the core file are too fragmented");
|
||||
}
|
||||
|
||||
|
||||
last_length = length;
|
||||
current_segment += GRUB_DISK_SECTOR_SIZE >> 4;
|
||||
}
|
||||
|
||||
|
||||
/* Read the boot image by the OS service. */
|
||||
boot_path = grub_util_get_path (dir, boot_file);
|
||||
boot_size = grub_util_get_image_size (boot_path);
|
||||
|
@ -212,7 +212,7 @@ setup (const char *dir,
|
|||
+ GRUB_BOOT_MACHINE_KERNEL_SECTOR);
|
||||
boot_drive_check = (grub_uint16_t *) (boot_img
|
||||
+ GRUB_BOOT_MACHINE_DRIVE_CHECK);
|
||||
|
||||
|
||||
core_path = grub_util_get_path (dir, core_file);
|
||||
core_size = grub_util_get_image_size (core_path);
|
||||
core_sectors = ((core_size + GRUB_DISK_SECTOR_SIZE - 1)
|
||||
|
@ -221,7 +221,7 @@ setup (const char *dir,
|
|||
grub_util_error ("The size of `%s' is too small", core_path);
|
||||
else if (core_size > 0xFFFF * GRUB_DISK_SECTOR_SIZE)
|
||||
grub_util_error ("The size of `%s' is too large", core_path);
|
||||
|
||||
|
||||
core_img = grub_util_read_image (core_path);
|
||||
|
||||
/* Have FIRST_BLOCK to point to the first blocklist. */
|
||||
|
@ -264,7 +264,7 @@ setup (const char *dir,
|
|||
GRUB_BOOT_MACHINE_PART_END - GRUB_BOOT_MACHINE_WINDOWS_NT_MAGIC);
|
||||
|
||||
free (tmp_img);
|
||||
|
||||
|
||||
/* If DEST_DRIVE is a hard disk, enable the workaround, which is
|
||||
for buggy BIOSes which don't pass boot drive correctly. Instead,
|
||||
they pass 0x00 or 0x01 even when booted from 0x80. */
|
||||
|
@ -304,7 +304,7 @@ setup (const char *dir,
|
|||
dos_part = grub_le_to_cpu32 (*install_dos_part);
|
||||
bsd_part = grub_le_to_cpu32 (*install_bsd_part);
|
||||
}
|
||||
|
||||
|
||||
grub_util_info ("dos partition is %d, bsd partition is %d",
|
||||
dos_part, bsd_part);
|
||||
|
||||
|
@ -319,7 +319,7 @@ setup (const char *dir,
|
|||
grub_util_warn ("Attempting to install GRUB to a partition instead of the MBR. This is a BAD idea.");
|
||||
goto unable_to_embed;
|
||||
}
|
||||
|
||||
|
||||
/* Unlike root_dev, with dest_dev we're interested in the partition map even
|
||||
if dest_dev itself is a whole disk. */
|
||||
auto int NESTED_FUNC_ATTR identify_partmap (grub_disk_t disk,
|
||||
|
@ -331,7 +331,7 @@ setup (const char *dir,
|
|||
return 1;
|
||||
}
|
||||
grub_partition_iterate (dest_dev->disk, identify_partmap);
|
||||
|
||||
|
||||
grub_partition_iterate (dest_dev->disk, (strcmp (dest_partmap, "pc_partition_map") ?
|
||||
find_usable_region_gpt : find_usable_region_msdos));
|
||||
if (embed_region.end == embed_region.start)
|
||||
|
@ -356,69 +356,69 @@ setup (const char *dir,
|
|||
|
||||
|
||||
grub_util_info ("will embed the core image at sector 0x%llx", embed_region.start);
|
||||
|
||||
|
||||
*install_dos_part = grub_cpu_to_le32 (dos_part);
|
||||
*install_bsd_part = grub_cpu_to_le32 (bsd_part);
|
||||
|
||||
|
||||
/* The first blocklist contains the whole sectors. */
|
||||
first_block->start = grub_cpu_to_le64 (embed_region.start + 1);
|
||||
first_block->len = grub_cpu_to_le16 (core_sectors - 1);
|
||||
first_block->segment
|
||||
= grub_cpu_to_le16 (GRUB_BOOT_MACHINE_KERNEL_SEG
|
||||
+ (GRUB_DISK_SECTOR_SIZE >> 4));
|
||||
|
||||
|
||||
/* Make sure that the second blocklist is a terminator. */
|
||||
block = first_block - 1;
|
||||
block->start = 0;
|
||||
block->len = 0;
|
||||
block->segment = 0;
|
||||
|
||||
|
||||
/* Write the core image onto the disk. */
|
||||
if (grub_disk_write (dest_dev->disk, embed_region.start, 0, core_size, core_img))
|
||||
grub_util_error ("%s", grub_errmsg);
|
||||
|
||||
|
||||
/* FIXME: can this be skipped? */
|
||||
*boot_drive = 0xFF;
|
||||
*root_drive = 0xFF;
|
||||
|
||||
|
||||
*kernel_sector = grub_cpu_to_le64 (embed_region.start);
|
||||
|
||||
|
||||
/* Write the boot image onto the disk. */
|
||||
if (grub_disk_write (dest_dev->disk, 0, 0, GRUB_DISK_SECTOR_SIZE,
|
||||
boot_img))
|
||||
grub_util_error ("%s", grub_errmsg);
|
||||
|
||||
|
||||
goto finish;
|
||||
|
||||
|
||||
unable_to_embed:
|
||||
|
||||
|
||||
if (must_embed)
|
||||
grub_util_error ("Embedding is not possible, but this is required when "
|
||||
"the root device is on a RAID array or LVM volume.");
|
||||
|
||||
|
||||
grub_util_warn ("Embedding is not possible. GRUB can only be installed in this "
|
||||
"setup by using blocklists. However, blocklists are UNRELIABLE and "
|
||||
"its use is discouraged.");
|
||||
if (! force)
|
||||
grub_util_error ("If you really want blocklists, use --force.");
|
||||
|
||||
|
||||
/* Make sure that GRUB reads the identical image as the OS. */
|
||||
tmp_img = xmalloc (core_size);
|
||||
core_path_dev = grub_util_get_path (dir, core_file);
|
||||
|
||||
|
||||
/* It is a Good Thing to sync two times. */
|
||||
sync ();
|
||||
sync ();
|
||||
|
||||
#define MAX_TRIES 5
|
||||
|
||||
|
||||
for (i = 0; i < MAX_TRIES; i++)
|
||||
{
|
||||
grub_util_info ("attempting to read the core image `%s' from GRUB%s",
|
||||
core_path_dev, (i == 0) ? "" : " again");
|
||||
|
||||
|
||||
grub_disk_cache_invalidate_all ();
|
||||
|
||||
|
||||
file = grub_file_open (core_path_dev);
|
||||
if (file)
|
||||
{
|
||||
|
@ -434,7 +434,7 @@ unable_to_embed:
|
|||
#if 0
|
||||
FILE *dump;
|
||||
FILE *dump2;
|
||||
|
||||
|
||||
dump = fopen ("dump.img", "wb");
|
||||
if (dump)
|
||||
{
|
||||
|
@ -448,8 +448,8 @@ unable_to_embed:
|
|||
fwrite (core_img, 1, core_size, dump2);
|
||||
fclose (dump2);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
grub_util_info ("succeeded in opening the core image but the data is different");
|
||||
}
|
||||
else
|
||||
|
@ -465,7 +465,7 @@ unable_to_embed:
|
|||
|
||||
if (grub_errno)
|
||||
grub_util_info ("error message = %s", grub_errmsg);
|
||||
|
||||
|
||||
grub_errno = GRUB_ERR_NONE;
|
||||
sync ();
|
||||
sleep (1);
|
||||
|
@ -483,16 +483,16 @@ unable_to_embed:
|
|||
block->segment = 0;
|
||||
|
||||
block--;
|
||||
|
||||
|
||||
if ((char *) block <= core_img)
|
||||
grub_util_error ("No terminator in the core image");
|
||||
}
|
||||
|
||||
|
||||
/* Now read the core image to determine where the sectors are. */
|
||||
file = grub_file_open (core_path_dev);
|
||||
if (! file)
|
||||
grub_util_error ("%s", grub_errmsg);
|
||||
|
||||
|
||||
file->read_hook = save_first_sector;
|
||||
if (grub_file_read (file, tmp_img, GRUB_DISK_SECTOR_SIZE)
|
||||
!= GRUB_DISK_SECTOR_SIZE)
|
||||
|
@ -505,10 +505,10 @@ unable_to_embed:
|
|||
grub_util_error ("Failed to read the rest sectors of the core image");
|
||||
|
||||
grub_file_close (file);
|
||||
|
||||
|
||||
free (core_path_dev);
|
||||
free (tmp_img);
|
||||
|
||||
|
||||
*kernel_sector = grub_cpu_to_le64 (first_sector);
|
||||
|
||||
/* FIXME: can this be skipped? */
|
||||
|
@ -535,7 +535,7 @@ unable_to_embed:
|
|||
|
||||
/* Sync is a Good Thing. */
|
||||
sync ();
|
||||
|
||||
|
||||
free (core_path);
|
||||
free (core_img);
|
||||
free (boot_img);
|
||||
|
@ -591,7 +591,7 @@ static char *
|
|||
get_device_name (char *dev)
|
||||
{
|
||||
size_t len = strlen (dev);
|
||||
|
||||
|
||||
if (dev[0] != '(' || dev[len - 1] != ')')
|
||||
return 0;
|
||||
|
||||
|
@ -609,7 +609,7 @@ main (int argc, char *argv[])
|
|||
char *root_dev = 0;
|
||||
char *dest_dev;
|
||||
int must_embed = 0, force = 0;
|
||||
|
||||
|
||||
progname = "grub-setup";
|
||||
|
||||
/* Check for options. */
|
||||
|
@ -642,7 +642,7 @@ main (int argc, char *argv[])
|
|||
|
||||
dir = xstrdup (optarg);
|
||||
break;
|
||||
|
||||
|
||||
case 'm':
|
||||
if (dev_map)
|
||||
free (dev_map);
|
||||
|
@ -656,7 +656,7 @@ main (int argc, char *argv[])
|
|||
|
||||
root_dev = xstrdup (optarg);
|
||||
break;
|
||||
|
||||
|
||||
case 'f':
|
||||
force = 1;
|
||||
break;
|
||||
|
@ -700,7 +700,7 @@ main (int argc, char *argv[])
|
|||
|
||||
/* Initialize all modules. */
|
||||
grub_init_all ();
|
||||
|
||||
|
||||
dest_dev = get_device_name (argv[optind]);
|
||||
if (! dest_dev)
|
||||
{
|
||||
|
@ -722,7 +722,7 @@ main (int argc, char *argv[])
|
|||
|
||||
if (! tmp)
|
||||
grub_util_error ("Invalid root device `%s'", root_dev);
|
||||
|
||||
|
||||
tmp = xstrdup (tmp);
|
||||
free (root_dev);
|
||||
root_dev = tmp;
|
||||
|
@ -741,7 +741,7 @@ main (int argc, char *argv[])
|
|||
#ifdef __linux__
|
||||
if (grub_util_lvm_isvolume (root_dev))
|
||||
must_embed = 1;
|
||||
|
||||
|
||||
if (root_dev[0] == 'm' && root_dev[1] == 'd'
|
||||
&& root_dev[2] >= '0' && root_dev[2] <= '9')
|
||||
{
|
||||
|
@ -776,13 +776,13 @@ main (int argc, char *argv[])
|
|||
/* Free resources. */
|
||||
grub_fini_all ();
|
||||
grub_util_biosdisk_fini ();
|
||||
|
||||
|
||||
free (boot_file);
|
||||
free (core_file);
|
||||
free (dir);
|
||||
free (dev_map);
|
||||
free (root_dev);
|
||||
free (dest_dev);
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue