2009-12-26 14:13:46 +01:00
|
|
|
/*
|
|
|
|
* QEMU PC System Emulator
|
|
|
|
*
|
|
|
|
* Copyright (c) 2003-2004 Fabrice Bellard
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
2016-01-26 19:17:03 +01:00
|
|
|
#include "qemu/osdep.h"
|
2018-02-01 12:18:46 +01:00
|
|
|
#include "qemu/option.h"
|
2016-01-19 21:51:44 +01:00
|
|
|
#include "cpu.h"
|
2013-02-04 15:40:22 +01:00
|
|
|
#include "hw/hw.h"
|
2013-02-05 17:06:20 +01:00
|
|
|
#include "hw/nvram/fw_cfg.h"
|
2013-03-18 17:36:02 +01:00
|
|
|
#include "multiboot.h"
|
2013-02-04 15:40:22 +01:00
|
|
|
#include "hw/loader.h"
|
2009-12-26 14:13:46 +01:00
|
|
|
#include "elf.h"
|
2012-12-17 18:20:04 +01:00
|
|
|
#include "sysemu/sysemu.h"
|
2017-12-21 18:25:18 +01:00
|
|
|
#include "qemu/error-report.h"
|
2009-12-26 14:13:46 +01:00
|
|
|
|
|
|
|
/* Show multiboot debug output */
|
|
|
|
//#define DEBUG_MULTIBOOT
|
|
|
|
|
|
|
|
#ifdef DEBUG_MULTIBOOT
|
2017-12-21 18:25:18 +01:00
|
|
|
#define mb_debug(a...) error_report(a)
|
2009-12-26 14:13:46 +01:00
|
|
|
#else
|
|
|
|
#define mb_debug(a...)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define MULTIBOOT_STRUCT_ADDR 0x9000
|
|
|
|
|
|
|
|
#if MULTIBOOT_STRUCT_ADDR > 0xf0000
|
|
|
|
#error multiboot struct needs to fit in 16 bit real mode
|
|
|
|
#endif
|
|
|
|
|
|
|
|
enum {
|
|
|
|
/* Multiboot info */
|
|
|
|
MBI_FLAGS = 0,
|
|
|
|
MBI_MEM_LOWER = 4,
|
|
|
|
MBI_MEM_UPPER = 8,
|
|
|
|
MBI_BOOT_DEVICE = 12,
|
|
|
|
MBI_CMDLINE = 16,
|
|
|
|
MBI_MODS_COUNT = 20,
|
|
|
|
MBI_MODS_ADDR = 24,
|
|
|
|
MBI_MMAP_ADDR = 48,
|
2014-10-30 06:52:03 +01:00
|
|
|
MBI_BOOTLOADER = 64,
|
2009-12-26 14:13:46 +01:00
|
|
|
|
|
|
|
MBI_SIZE = 88,
|
|
|
|
|
|
|
|
/* Multiboot modules */
|
|
|
|
MB_MOD_START = 0,
|
|
|
|
MB_MOD_END = 4,
|
|
|
|
MB_MOD_CMDLINE = 8,
|
|
|
|
|
|
|
|
MB_MOD_SIZE = 16,
|
|
|
|
|
|
|
|
/* Region offsets */
|
|
|
|
ADDR_E820_MAP = MULTIBOOT_STRUCT_ADDR + 0,
|
|
|
|
ADDR_MBI = ADDR_E820_MAP + 0x500,
|
|
|
|
|
|
|
|
/* Multiboot flags */
|
|
|
|
MULTIBOOT_FLAGS_MEMORY = 1 << 0,
|
|
|
|
MULTIBOOT_FLAGS_BOOT_DEVICE = 1 << 1,
|
|
|
|
MULTIBOOT_FLAGS_CMDLINE = 1 << 2,
|
|
|
|
MULTIBOOT_FLAGS_MODULES = 1 << 3,
|
|
|
|
MULTIBOOT_FLAGS_MMAP = 1 << 6,
|
2014-10-30 06:52:03 +01:00
|
|
|
MULTIBOOT_FLAGS_BOOTLOADER = 1 << 9,
|
2009-12-26 14:13:46 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
/* buffer holding kernel, cmdlines and mb_infos */
|
|
|
|
void *mb_buf;
|
|
|
|
/* address in target */
|
2012-10-23 12:30:10 +02:00
|
|
|
hwaddr mb_buf_phys;
|
2009-12-26 14:13:46 +01:00
|
|
|
/* size of mb_buf in bytes */
|
|
|
|
unsigned mb_buf_size;
|
|
|
|
/* offset of mb-info's in bytes */
|
2012-10-23 12:30:10 +02:00
|
|
|
hwaddr offset_mbinfo;
|
2009-12-26 14:13:46 +01:00
|
|
|
/* offset in buffer for cmdlines in bytes */
|
2012-10-23 12:30:10 +02:00
|
|
|
hwaddr offset_cmdlines;
|
2014-10-30 06:52:03 +01:00
|
|
|
/* offset in buffer for bootloader name in bytes */
|
|
|
|
hwaddr offset_bootloader;
|
2009-12-26 14:13:46 +01:00
|
|
|
/* offset of modules in bytes */
|
2012-10-23 12:30:10 +02:00
|
|
|
hwaddr offset_mods;
|
2009-12-26 14:13:46 +01:00
|
|
|
/* available slots for mb modules infos */
|
|
|
|
int mb_mods_avail;
|
|
|
|
/* currently used slots of mb modules */
|
|
|
|
int mb_mods_count;
|
|
|
|
} MultibootState;
|
|
|
|
|
2014-10-30 06:52:03 +01:00
|
|
|
const char *bootloader_name = "qemu";
|
|
|
|
|
2009-12-26 14:13:46 +01:00
|
|
|
static uint32_t mb_add_cmdline(MultibootState *s, const char *cmdline)
|
|
|
|
{
|
2012-10-23 12:30:10 +02:00
|
|
|
hwaddr p = s->offset_cmdlines;
|
2011-07-06 10:03:57 +02:00
|
|
|
char *b = (char *)s->mb_buf + p;
|
2009-12-26 14:13:46 +01:00
|
|
|
|
2016-12-15 13:32:04 +01:00
|
|
|
memcpy(b, cmdline, strlen(cmdline) + 1);
|
2011-07-06 10:03:57 +02:00
|
|
|
s->offset_cmdlines += strlen(b) + 1;
|
2009-12-26 14:13:46 +01:00
|
|
|
return s->mb_buf_phys + p;
|
|
|
|
}
|
|
|
|
|
2014-10-30 06:52:03 +01:00
|
|
|
static uint32_t mb_add_bootloader(MultibootState *s, const char *bootloader)
|
|
|
|
{
|
|
|
|
hwaddr p = s->offset_bootloader;
|
|
|
|
char *b = (char *)s->mb_buf + p;
|
|
|
|
|
|
|
|
memcpy(b, bootloader, strlen(bootloader) + 1);
|
|
|
|
s->offset_bootloader += strlen(b) + 1;
|
|
|
|
return s->mb_buf_phys + p;
|
|
|
|
}
|
|
|
|
|
2009-12-26 14:13:46 +01:00
|
|
|
static void mb_add_mod(MultibootState *s,
|
2012-10-23 12:30:10 +02:00
|
|
|
hwaddr start, hwaddr end,
|
|
|
|
hwaddr cmdline_phys)
|
2009-12-26 14:13:46 +01:00
|
|
|
{
|
|
|
|
char *p;
|
|
|
|
assert(s->mb_mods_count < s->mb_mods_avail);
|
|
|
|
|
|
|
|
p = (char *)s->mb_buf + s->offset_mbinfo + MB_MOD_SIZE * s->mb_mods_count;
|
|
|
|
|
|
|
|
stl_p(p + MB_MOD_START, start);
|
|
|
|
stl_p(p + MB_MOD_END, end);
|
|
|
|
stl_p(p + MB_MOD_CMDLINE, cmdline_phys);
|
|
|
|
|
2017-12-21 18:25:18 +01:00
|
|
|
mb_debug("mod%02d: "TARGET_FMT_plx" - "TARGET_FMT_plx,
|
2010-05-27 07:37:09 +02:00
|
|
|
s->mb_mods_count, start, end);
|
2009-12-26 14:13:46 +01:00
|
|
|
|
|
|
|
s->mb_mods_count++;
|
|
|
|
}
|
|
|
|
|
2013-04-16 02:24:08 +02:00
|
|
|
int load_multiboot(FWCfgState *fw_cfg,
|
2009-12-26 14:13:46 +01:00
|
|
|
FILE *f,
|
|
|
|
const char *kernel_filename,
|
|
|
|
const char *initrd_filename,
|
|
|
|
const char *kernel_cmdline,
|
|
|
|
int kernel_file_size,
|
|
|
|
uint8_t *header)
|
|
|
|
{
|
|
|
|
int i, is_multiboot = 0;
|
|
|
|
uint32_t flags = 0;
|
|
|
|
uint32_t mh_entry_addr;
|
|
|
|
uint32_t mh_load_addr;
|
|
|
|
uint32_t mb_kernel_size;
|
|
|
|
MultibootState mbs;
|
|
|
|
uint8_t bootinfo[MBI_SIZE];
|
|
|
|
uint8_t *mb_bootinfo_data;
|
2015-01-15 12:26:43 +01:00
|
|
|
uint32_t cmdline_len;
|
2018-05-14 19:19:12 +02:00
|
|
|
GList *mods = NULL;
|
2009-12-26 14:13:46 +01:00
|
|
|
|
|
|
|
/* Ok, let's see if it is a multiboot image.
|
|
|
|
The header is 12x32bit long, so the latest entry may be 8192 - 48. */
|
|
|
|
for (i = 0; i < (8192 - 48); i += 4) {
|
|
|
|
if (ldl_p(header+i) == 0x1BADB002) {
|
|
|
|
uint32_t checksum = ldl_p(header+i+8);
|
|
|
|
flags = ldl_p(header+i+4);
|
|
|
|
checksum += flags;
|
|
|
|
checksum += (uint32_t)0x1BADB002;
|
|
|
|
if (!checksum) {
|
|
|
|
is_multiboot = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!is_multiboot)
|
|
|
|
return 0; /* no multiboot */
|
|
|
|
|
2018-09-21 04:05:30 +02:00
|
|
|
mb_debug("I believe we found a multiboot image!");
|
2009-12-26 14:13:46 +01:00
|
|
|
memset(bootinfo, 0, sizeof(bootinfo));
|
|
|
|
memset(&mbs, 0, sizeof(mbs));
|
|
|
|
|
|
|
|
if (flags & 0x00000004) { /* MULTIBOOT_HEADER_HAS_VBE */
|
2018-09-21 04:05:30 +02:00
|
|
|
error_report("multiboot knows VBE. we don't");
|
2009-12-26 14:13:46 +01:00
|
|
|
}
|
|
|
|
if (!(flags & 0x00010000)) { /* MULTIBOOT_HEADER_HAS_ADDR */
|
|
|
|
uint64_t elf_entry;
|
|
|
|
uint64_t elf_low, elf_high;
|
|
|
|
int kernel_size;
|
|
|
|
fclose(f);
|
2010-11-04 23:22:15 +01:00
|
|
|
|
|
|
|
if (((struct elf64_hdr*)header)->e_machine == EM_X86_64) {
|
2017-12-21 18:25:18 +01:00
|
|
|
error_report("Cannot load x86-64 image, give a 32bit one.");
|
2010-11-04 23:22:15 +01:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2010-03-14 21:20:59 +01:00
|
|
|
kernel_size = load_elf(kernel_filename, NULL, NULL, &elf_entry,
|
2016-03-04 12:30:21 +01:00
|
|
|
&elf_low, &elf_high, 0, I386_ELF_MACHINE,
|
|
|
|
0, 0);
|
2009-12-26 14:13:46 +01:00
|
|
|
if (kernel_size < 0) {
|
2017-12-21 18:25:18 +01:00
|
|
|
error_report("Error while loading elf kernel");
|
2009-12-26 14:13:46 +01:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
mh_load_addr = elf_low;
|
|
|
|
mb_kernel_size = elf_high - elf_low;
|
|
|
|
mh_entry_addr = elf_entry;
|
|
|
|
|
2011-08-21 05:09:37 +02:00
|
|
|
mbs.mb_buf = g_malloc(mb_kernel_size);
|
2009-12-26 14:13:46 +01:00
|
|
|
if (rom_copy(mbs.mb_buf, mh_load_addr, mb_kernel_size) != mb_kernel_size) {
|
2017-12-21 18:25:18 +01:00
|
|
|
error_report("Error while fetching elf kernel from rom");
|
2009-12-26 14:13:46 +01:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2018-09-21 04:05:30 +02:00
|
|
|
mb_debug("loading multiboot-elf kernel "
|
2017-12-21 18:25:18 +01:00
|
|
|
"(%#x bytes) with entry %#zx",
|
|
|
|
mb_kernel_size, (size_t)mh_entry_addr);
|
2009-12-26 14:13:46 +01:00
|
|
|
} else {
|
|
|
|
/* Valid if mh_flags sets MULTIBOOT_HEADER_HAS_ADDR. */
|
|
|
|
uint32_t mh_header_addr = ldl_p(header+i+12);
|
2011-07-24 17:55:58 +02:00
|
|
|
uint32_t mh_load_end_addr = ldl_p(header+i+20);
|
|
|
|
uint32_t mh_bss_end_addr = ldl_p(header+i+24);
|
2017-09-07 08:32:56 +02:00
|
|
|
|
2009-12-26 14:13:46 +01:00
|
|
|
mh_load_addr = ldl_p(header+i+16);
|
2017-09-07 08:32:56 +02:00
|
|
|
if (mh_header_addr < mh_load_addr) {
|
2017-12-21 18:25:18 +01:00
|
|
|
error_report("invalid load_addr address");
|
2017-09-07 08:32:56 +02:00
|
|
|
exit(1);
|
|
|
|
}
|
2018-03-14 17:57:45 +01:00
|
|
|
if (mh_header_addr - mh_load_addr > i) {
|
|
|
|
error_report("invalid header_addr address");
|
|
|
|
exit(1);
|
|
|
|
}
|
2017-09-07 08:32:56 +02:00
|
|
|
|
2009-12-26 14:13:46 +01:00
|
|
|
uint32_t mb_kernel_text_offset = i - (mh_header_addr - mh_load_addr);
|
2012-03-26 21:27:00 +02:00
|
|
|
uint32_t mb_load_size = 0;
|
2009-12-26 14:13:46 +01:00
|
|
|
mh_entry_addr = ldl_p(header+i+28);
|
2012-03-26 21:27:00 +02:00
|
|
|
|
|
|
|
if (mh_load_end_addr) {
|
2017-09-07 08:32:56 +02:00
|
|
|
if (mh_load_end_addr < mh_load_addr) {
|
2017-12-21 18:25:18 +01:00
|
|
|
error_report("invalid load_end_addr address");
|
2017-09-07 08:32:56 +02:00
|
|
|
exit(1);
|
|
|
|
}
|
2012-03-26 21:27:00 +02:00
|
|
|
mb_load_size = mh_load_end_addr - mh_load_addr;
|
|
|
|
} else {
|
2017-09-07 08:32:56 +02:00
|
|
|
if (kernel_file_size < mb_kernel_text_offset) {
|
2017-12-21 18:25:18 +01:00
|
|
|
error_report("invalid kernel_file_size");
|
2017-09-07 08:32:56 +02:00
|
|
|
exit(1);
|
|
|
|
}
|
2017-12-21 18:25:15 +01:00
|
|
|
mb_load_size = kernel_file_size - mb_kernel_text_offset;
|
|
|
|
}
|
2018-03-14 17:46:38 +01:00
|
|
|
if (mb_load_size > UINT32_MAX - mh_load_addr) {
|
|
|
|
error_report("kernel does not fit in address space");
|
|
|
|
exit(1);
|
|
|
|
}
|
2017-12-21 18:25:15 +01:00
|
|
|
if (mh_bss_end_addr) {
|
|
|
|
if (mh_bss_end_addr < (mh_load_addr + mb_load_size)) {
|
2017-12-21 18:25:18 +01:00
|
|
|
error_report("invalid bss_end_addr address");
|
2017-12-21 18:25:15 +01:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
mb_kernel_size = mh_bss_end_addr - mh_load_addr;
|
|
|
|
} else {
|
|
|
|
mb_kernel_size = mb_load_size;
|
2012-03-26 21:27:00 +02:00
|
|
|
}
|
2009-12-26 14:13:46 +01:00
|
|
|
|
2017-12-21 18:25:18 +01:00
|
|
|
mb_debug("multiboot: header_addr = %#x", mh_header_addr);
|
|
|
|
mb_debug("multiboot: load_addr = %#x", mh_load_addr);
|
|
|
|
mb_debug("multiboot: load_end_addr = %#x", mh_load_end_addr);
|
|
|
|
mb_debug("multiboot: bss_end_addr = %#x", mh_bss_end_addr);
|
2018-09-21 04:05:30 +02:00
|
|
|
mb_debug("loading multiboot kernel (%#x bytes) at %#x",
|
2011-07-24 17:55:58 +02:00
|
|
|
mb_load_size, mh_load_addr);
|
2009-12-26 14:13:46 +01:00
|
|
|
|
2011-08-21 05:09:37 +02:00
|
|
|
mbs.mb_buf = g_malloc(mb_kernel_size);
|
2009-12-26 14:13:46 +01:00
|
|
|
fseek(f, mb_kernel_text_offset, SEEK_SET);
|
2011-07-24 17:55:58 +02:00
|
|
|
if (fread(mbs.mb_buf, 1, mb_load_size, f) != mb_load_size) {
|
2017-12-21 18:25:18 +01:00
|
|
|
error_report("fread() failed");
|
2009-12-26 14:13:46 +01:00
|
|
|
exit(1);
|
|
|
|
}
|
2011-07-24 17:55:58 +02:00
|
|
|
memset(mbs.mb_buf + mb_load_size, 0, mb_kernel_size - mb_load_size);
|
2009-12-26 14:13:46 +01:00
|
|
|
fclose(f);
|
|
|
|
}
|
|
|
|
|
|
|
|
mbs.mb_buf_phys = mh_load_addr;
|
|
|
|
|
|
|
|
mbs.mb_buf_size = TARGET_PAGE_ALIGN(mb_kernel_size);
|
|
|
|
mbs.offset_mbinfo = mbs.mb_buf_size;
|
|
|
|
|
2014-10-30 06:52:03 +01:00
|
|
|
/* Calculate space for cmdlines, bootloader name, and mb_mods */
|
2015-01-15 12:26:43 +01:00
|
|
|
cmdline_len = strlen(kernel_filename) + 1;
|
|
|
|
cmdline_len += strlen(kernel_cmdline) + 1;
|
2009-12-26 14:13:46 +01:00
|
|
|
if (initrd_filename) {
|
2018-05-14 19:19:12 +02:00
|
|
|
const char *r = initrd_filename;
|
2018-05-14 19:19:11 +02:00
|
|
|
cmdline_len += strlen(initrd_filename) + 1;
|
2018-05-14 19:19:12 +02:00
|
|
|
while (*r) {
|
|
|
|
char *value;
|
|
|
|
r = get_opt_value(r, &value);
|
2018-04-16 13:17:43 +02:00
|
|
|
mbs.mb_mods_avail++;
|
2018-05-14 19:19:12 +02:00
|
|
|
mods = g_list_append(mods, value);
|
|
|
|
if (*r) {
|
|
|
|
r++;
|
2018-04-16 13:17:43 +02:00
|
|
|
}
|
2009-12-26 14:13:46 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-15 12:26:43 +01:00
|
|
|
mbs.mb_buf_size += cmdline_len;
|
|
|
|
mbs.mb_buf_size += MB_MOD_SIZE * mbs.mb_mods_avail;
|
|
|
|
mbs.mb_buf_size += strlen(bootloader_name) + 1;
|
|
|
|
|
2009-12-26 14:13:46 +01:00
|
|
|
mbs.mb_buf_size = TARGET_PAGE_ALIGN(mbs.mb_buf_size);
|
|
|
|
|
2014-10-30 06:52:03 +01:00
|
|
|
/* enlarge mb_buf to hold cmdlines, bootloader, mb-info structs */
|
|
|
|
mbs.mb_buf = g_realloc(mbs.mb_buf, mbs.mb_buf_size);
|
|
|
|
mbs.offset_cmdlines = mbs.offset_mbinfo + mbs.mb_mods_avail * MB_MOD_SIZE;
|
2015-01-15 12:26:43 +01:00
|
|
|
mbs.offset_bootloader = mbs.offset_cmdlines + cmdline_len;
|
2009-12-26 14:13:46 +01:00
|
|
|
|
2018-05-14 19:19:12 +02:00
|
|
|
if (mods) {
|
|
|
|
GList *tmpl = mods;
|
2009-12-26 14:13:46 +01:00
|
|
|
mbs.offset_mods = mbs.mb_buf_size;
|
|
|
|
|
2018-05-14 19:19:12 +02:00
|
|
|
while (tmpl) {
|
2009-12-26 14:13:46 +01:00
|
|
|
char *next_space;
|
2010-08-31 09:30:38 +02:00
|
|
|
int mb_mod_length;
|
2009-12-26 14:13:46 +01:00
|
|
|
uint32_t offs = mbs.mb_buf_size;
|
2018-05-14 19:19:12 +02:00
|
|
|
char *one_file = tmpl->data;
|
2009-12-26 14:13:46 +01:00
|
|
|
|
|
|
|
/* if a space comes after the module filename, treat everything
|
|
|
|
after that as parameters */
|
2018-04-16 13:17:43 +02:00
|
|
|
hwaddr c = mb_add_cmdline(&mbs, one_file);
|
|
|
|
next_space = strchr(one_file, ' ');
|
|
|
|
if (next_space) {
|
2009-12-26 14:13:46 +01:00
|
|
|
*next_space = '\0';
|
2018-04-16 13:17:43 +02:00
|
|
|
}
|
|
|
|
mb_debug("multiboot loading module: %s", one_file);
|
|
|
|
mb_mod_length = get_image_size(one_file);
|
2009-12-26 14:13:46 +01:00
|
|
|
if (mb_mod_length < 0) {
|
2018-04-16 13:17:43 +02:00
|
|
|
error_report("Failed to open file '%s'", one_file);
|
2009-12-26 14:13:46 +01:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
mbs.mb_buf_size = TARGET_PAGE_ALIGN(mb_mod_length + mbs.mb_buf_size);
|
2011-08-21 05:09:37 +02:00
|
|
|
mbs.mb_buf = g_realloc(mbs.mb_buf, mbs.mb_buf_size);
|
2009-12-26 14:13:46 +01:00
|
|
|
|
2018-12-14 14:30:51 +01:00
|
|
|
if (load_image_size(one_file, (unsigned char *)mbs.mb_buf + offs,
|
|
|
|
mbs.mb_buf_size - offs) < 0) {
|
|
|
|
error_report("Error loading file '%s'", one_file);
|
|
|
|
exit(1);
|
|
|
|
}
|
2009-12-26 14:13:46 +01:00
|
|
|
mb_add_mod(&mbs, mbs.mb_buf_phys + offs,
|
|
|
|
mbs.mb_buf_phys + offs + mb_mod_length, c);
|
|
|
|
|
2017-12-21 18:25:18 +01:00
|
|
|
mb_debug("mod_start: %p\nmod_end: %p\n cmdline: "TARGET_FMT_plx,
|
2009-12-26 14:13:46 +01:00
|
|
|
(char *)mbs.mb_buf + offs,
|
|
|
|
(char *)mbs.mb_buf + offs + mb_mod_length, c);
|
2018-04-16 13:17:43 +02:00
|
|
|
g_free(one_file);
|
2018-05-14 19:19:12 +02:00
|
|
|
tmpl = tmpl->next;
|
|
|
|
}
|
|
|
|
g_list_free(mods);
|
2009-12-26 14:13:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Commandline support */
|
|
|
|
char kcmdline[strlen(kernel_filename) + strlen(kernel_cmdline) + 2];
|
|
|
|
snprintf(kcmdline, sizeof(kcmdline), "%s %s",
|
|
|
|
kernel_filename, kernel_cmdline);
|
|
|
|
stl_p(bootinfo + MBI_CMDLINE, mb_add_cmdline(&mbs, kcmdline));
|
|
|
|
|
2014-10-30 06:52:03 +01:00
|
|
|
stl_p(bootinfo + MBI_BOOTLOADER, mb_add_bootloader(&mbs, bootloader_name));
|
|
|
|
|
2009-12-26 14:13:46 +01:00
|
|
|
stl_p(bootinfo + MBI_MODS_ADDR, mbs.mb_buf_phys + mbs.offset_mbinfo);
|
|
|
|
stl_p(bootinfo + MBI_MODS_COUNT, mbs.mb_mods_count); /* mods_count */
|
|
|
|
|
|
|
|
/* the kernel is where we want it to be now */
|
|
|
|
stl_p(bootinfo + MBI_FLAGS, MULTIBOOT_FLAGS_MEMORY
|
|
|
|
| MULTIBOOT_FLAGS_BOOT_DEVICE
|
|
|
|
| MULTIBOOT_FLAGS_CMDLINE
|
|
|
|
| MULTIBOOT_FLAGS_MODULES
|
2014-10-30 06:52:03 +01:00
|
|
|
| MULTIBOOT_FLAGS_MMAP
|
|
|
|
| MULTIBOOT_FLAGS_BOOTLOADER);
|
2011-04-28 16:11:11 +02:00
|
|
|
stl_p(bootinfo + MBI_BOOT_DEVICE, 0x8000ffff); /* XXX: use the -boot switch? */
|
2009-12-26 14:13:46 +01:00
|
|
|
stl_p(bootinfo + MBI_MMAP_ADDR, ADDR_E820_MAP);
|
|
|
|
|
2017-12-21 18:25:18 +01:00
|
|
|
mb_debug("multiboot: entry_addr = %#x", mh_entry_addr);
|
|
|
|
mb_debug(" mb_buf_phys = "TARGET_FMT_plx, mbs.mb_buf_phys);
|
|
|
|
mb_debug(" mod_start = "TARGET_FMT_plx,
|
|
|
|
mbs.mb_buf_phys + mbs.offset_mods);
|
|
|
|
mb_debug(" mb_mods_count = %d", mbs.mb_mods_count);
|
2009-12-26 14:13:46 +01:00
|
|
|
|
|
|
|
/* save bootinfo off the stack */
|
2017-06-06 22:45:43 +02:00
|
|
|
mb_bootinfo_data = g_memdup(bootinfo, sizeof(bootinfo));
|
2009-12-26 14:13:46 +01:00
|
|
|
|
|
|
|
/* Pass variables to option rom */
|
|
|
|
fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_ENTRY, mh_entry_addr);
|
|
|
|
fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_ADDR, mh_load_addr);
|
|
|
|
fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_SIZE, mbs.mb_buf_size);
|
|
|
|
fw_cfg_add_bytes(fw_cfg, FW_CFG_KERNEL_DATA,
|
|
|
|
mbs.mb_buf, mbs.mb_buf_size);
|
|
|
|
|
|
|
|
fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_ADDR, ADDR_MBI);
|
|
|
|
fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_SIZE, sizeof(bootinfo));
|
|
|
|
fw_cfg_add_bytes(fw_cfg, FW_CFG_INITRD_DATA, mb_bootinfo_data,
|
|
|
|
sizeof(bootinfo));
|
|
|
|
|
2010-12-08 12:35:07 +01:00
|
|
|
option_rom[nb_option_roms].name = "multiboot.bin";
|
|
|
|
option_rom[nb_option_roms].bootindex = 0;
|
2009-12-26 14:13:46 +01:00
|
|
|
nb_option_roms++;
|
|
|
|
|
|
|
|
return 1; /* yes, we are multiboot */
|
|
|
|
}
|