#ifdef GRUB_MACHINE_PCBIOS
if (GRUB_KERNEL_MACHINE_LINK_ADDR + core_size > GRUB_MEMORY_MACHINE_UPPER)
- grub_util_error (_("Core image is too big (%p > %p)\n"),
+ grub_util_error (_("core image is too big (%p > %p)"),
- GRUB_KERNEL_MACHINE_LINK_ADDR + core_size, GRUB_MEMORY_MACHINE_UPPER);
+ GRUB_KERNEL_MACHINE_LINK_ADDR + core_size,
+ GRUB_MEMORY_MACHINE_UPPER);
+#endif
+
+#if defined(GRUB_MACHINE_MIPS)
+ if (format == GRUB_PLATFORM_IMAGE_ELF)
+ {
+ char *elf_img;
+ size_t program_size;
+ Elf32_Ehdr *ehdr;
+ Elf32_Phdr *phdr;
+ grub_uint32_t target_addr;
+
+ program_size = ALIGN_UP (core_size, 4);
+
+ elf_img = xmalloc (program_size + sizeof (*ehdr) + sizeof (*phdr));
+ memset (elf_img, 0, program_size + sizeof (*ehdr) + sizeof (*phdr));
+ memcpy (elf_img + sizeof (*ehdr) + sizeof (*phdr), core_img, core_size);
+ ehdr = (void *) elf_img;
+ phdr = (void *) (elf_img + sizeof (*ehdr));
+ memcpy (ehdr->e_ident, ELFMAG, SELFMAG);
+ ehdr->e_ident[EI_CLASS] = ELFCLASS32;
+#ifdef GRUB_CPU_MIPSEL
+ ehdr->e_ident[EI_DATA] = ELFDATA2LSB;
+#else
+ ehdr->e_ident[EI_DATA] = ELFDATA2MSB;
+#endif
+ ehdr->e_ident[EI_VERSION] = EV_CURRENT;
+ ehdr->e_ident[EI_OSABI] = ELFOSABI_NONE;
+ ehdr->e_type = grub_host_to_target16 (ET_EXEC);
+ ehdr->e_machine = grub_host_to_target16 (EM_MIPS);
+ ehdr->e_version = grub_host_to_target32 (EV_CURRENT);
+
+ ehdr->e_phoff = grub_host_to_target32 ((char *) phdr - (char *) ehdr);
+ ehdr->e_phentsize = grub_host_to_target16 (sizeof (*phdr));
+ ehdr->e_phnum = grub_host_to_target16 (1);
+
+ /* No section headers. */
+ ehdr->e_shoff = grub_host_to_target32 (0);
+ ehdr->e_shentsize = grub_host_to_target16 (0);
+ ehdr->e_shnum = grub_host_to_target16 (0);
+ ehdr->e_shstrndx = grub_host_to_target16 (0);
+
+ ehdr->e_ehsize = grub_host_to_target16 (sizeof (*ehdr));
+
+ phdr->p_type = grub_host_to_target32 (PT_LOAD);
+ phdr->p_offset = grub_host_to_target32 (sizeof (*ehdr) + sizeof (*phdr));
+ phdr->p_flags = grub_host_to_target32 (PF_R | PF_W | PF_X);
+
+ target_addr = ALIGN_UP (GRUB_KERNEL_MACHINE_LINK_ADDR
+ + kernel_size + total_module_size, 32);
+ ehdr->e_entry = grub_host_to_target32 (target_addr);
+ 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 (GRUB_KERNEL_MACHINE_LINK_ALIGN);
+ ehdr->e_flags = grub_host_to_target32 (0x1000 | EF_MIPS_NOREORDER
+ | EF_MIPS_PIC | EF_MIPS_CPIC);
+ phdr->p_filesz = grub_host_to_target32 (core_size);
+ phdr->p_memsz = grub_host_to_target32 (core_size);
+
+ free (core_img);
+ core_img = elf_img;
+ core_size = program_size + sizeof (*ehdr) + sizeof (*phdr);
+ }
#endif
grub_util_write_image (core_img, core_size, out);