rom loader: fix sparc -kernel boot.

Changes:
(1) register pstrcpy_targphys() in rom list, it is used for kernel
command lines by a number of architectures.
(2) add rom_ptr() function to get a pointer for applying changes
to loaded images.  Needed for example to tell the linux kernel
where it finds the initrd image by updating the header.
(3) make sparc use rom_ptr for initrd setup.

booting sparc-test works now, and 'info roms' shows this:

(qemu) info roms
addr=0000000000000000 size=0x2a3828 mem=ram name="phdr #0: vmlinux-2.6.11+tcx"
addr=00000000007ff000 size=0x00000e mem=ram name="cmdline"
addr=0000000000800000 size=0x400000 mem=ram name="/root/qemu-test/sparc-test/linux.img"
addr=0000000070000000 size=0x0e4000 mem=rom name="phdr #0: /home/kraxel/projects/qemu/build-zfull/pc-bios/openbios-sparc32"

reboot via 'system_reset' works too.

Patchworks-ID: 35262
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
This commit is contained in:
Gerd Hoffmann 2009-10-07 13:37:06 +02:00 committed by Anthony Liguori
parent d549db5a73
commit 3c178e72e0
14 changed files with 54 additions and 24 deletions

View File

@ -365,7 +365,7 @@ void axisdev88_init (ram_addr_t ram_size,
/* Let the kernel know we are modifying the cmdline. */
env->regs[10] = 0x87109563;
env->regs[11] = 0x40000000;
pstrcpy_targphys(env->regs[11], 256, kernel_cmdline);
pstrcpy_targphys("cmdline", env->regs[11], 256, kernel_cmdline);
}
}
env->pc = bootstrap_pc;

View File

@ -157,7 +157,7 @@ void bareetraxfs_init (ram_addr_t ram_size,
/* Let the kernel know we are modifying the cmdline. */
env->regs[10] = 0x87109563;
env->regs[11] = 0x40000000;
pstrcpy_targphys(env->regs[11], 256, kernel_cmdline);
pstrcpy_targphys("cmdline", env->regs[11], 256, kernel_cmdline);
}
}
env->pc = bootstrap_pc;

View File

@ -108,20 +108,20 @@ int load_image_targphys(const char *filename,
return size;
}
void pstrcpy_targphys(target_phys_addr_t dest, int buf_size,
void pstrcpy_targphys(const char *name, target_phys_addr_t dest, int buf_size,
const char *source)
{
static const uint8_t nul_byte = 0;
const char *nulp;
char *ptr;
if (buf_size <= 0) return;
nulp = memchr(source, 0, buf_size);
if (nulp) {
cpu_physical_memory_write_rom(dest, (uint8_t *)source,
(nulp - source) + 1);
rom_add_blob_fixed(name, source, (nulp - source) + 1, dest);
} else {
cpu_physical_memory_write_rom(dest, (uint8_t *)source, buf_size - 1);
cpu_physical_memory_write_rom(dest, &nul_byte, 1);
rom_add_blob_fixed(name, source, buf_size, dest);
ptr = rom_ptr(dest + buf_size - 1);
*ptr = 0;
}
}
@ -672,6 +672,32 @@ int rom_load_all(void)
return 0;
}
static Rom *find_rom(target_phys_addr_t addr)
{
Rom *rom;
QTAILQ_FOREACH(rom, &roms, next) {
if (rom->max)
continue;
if (rom->min > addr)
continue;
if (rom->min + rom->romsize < addr)
continue;
return rom;
}
return NULL;
}
void *rom_ptr(target_phys_addr_t addr)
{
Rom *rom;
rom = find_rom(addr);
if (!rom || !rom->data)
return NULL;
return rom->data + (addr - rom->min);
}
void do_info_roms(Monitor *mon)
{
Rom *rom;

View File

@ -15,7 +15,8 @@ int load_uimage(const char *filename, target_phys_addr_t *ep,
int read_targphys(const char *name,
int fd, target_phys_addr_t dst_addr, size_t nbytes);
void pstrcpy_targphys(target_phys_addr_t dest, int buf_size,
void pstrcpy_targphys(const char *name,
target_phys_addr_t dest, int buf_size,
const char *source);
int rom_add_file(const char *file,
@ -23,6 +24,7 @@ int rom_add_file(const char *file,
int rom_add_blob(const char *name, const void *blob, size_t len,
target_phys_addr_t min, target_phys_addr_t max, int align);
int rom_load_all(void);
void *rom_ptr(target_phys_addr_t addr);
void do_info_roms(Monitor *mon);
#define rom_add_file_fixed(_f, _a) \

View File

@ -679,7 +679,7 @@ static void prom_set(int index, const char *string, ...)
va_start(ap, string);
vsnprintf(buf, ENVP_ENTRY_SIZE, string, ap);
va_end(ap);
pstrcpy_targphys(table_addr + VIRT_TO_PHYS_ADDEND, ENVP_ENTRY_SIZE, buf);
pstrcpy_targphys("prom", table_addr + VIRT_TO_PHYS_ADDEND, ENVP_ENTRY_SIZE, buf);
}
/* Kernel */

View File

@ -130,7 +130,7 @@ static void load_kernel (CPUState *env)
} else {
ret = 0;
}
pstrcpy_targphys((16 << 20) - 256 + ret, 256,
pstrcpy_targphys("cmdline", (16 << 20) - 256 + ret, 256,
loaderparams.kernel_cmdline);
stl_phys((16 << 20) - 260, 0x12345678);

View File

@ -865,7 +865,7 @@ static void load_linux(void *fw_cfg,
initrd_max = max_ram_size-ACPI_DATA_SIZE-1;
/* kernel command line */
rom_add_blob_fixed("linux-cmdline", kernel_cmdline,
rom_add_blob_fixed("cmdline", kernel_cmdline,
strlen(kernel_cmdline)+1, cmdline_addr);
if (protocol >= 0x202) {

View File

@ -176,7 +176,7 @@ petalogix_s3adsp1800_init(ram_addr_t ram_size,
env->regs[5] = ddr_base + kernel_size;
if (kernel_cmdline && (kcmdline_len = strlen(kernel_cmdline))) {
pstrcpy_targphys(env->regs[5], 256, kernel_cmdline);
pstrcpy_targphys("cmdline", env->regs[5], 256, kernel_cmdline);
}
env->regs[6] = 0;
/* Provide a device-tree. */

View File

@ -1256,7 +1256,7 @@ int PPC_NVRAM_set_params (nvram_t *nvram, uint16_t NVRAM_size,
NVRAM_set_lword(nvram, 0x3C, kernel_size);
if (cmdline) {
/* XXX: put the cmdline in NVRAM too ? */
pstrcpy_targphys(CMDLINE_ADDR, RAM_size - CMDLINE_ADDR, cmdline);
pstrcpy_targphys("cmdline", CMDLINE_ADDR, RAM_size - CMDLINE_ADDR, cmdline);
NVRAM_set_lword(nvram, 0x40, CMDLINE_ADDR);
NVRAM_set_lword(nvram, 0x44, strlen(cmdline));
} else {

View File

@ -364,7 +364,7 @@ static void ppc_core99_init (ram_addr_t ram_size,
fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_SIZE, kernel_size);
if (kernel_cmdline) {
fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, CMDLINE_ADDR);
pstrcpy_targphys(CMDLINE_ADDR, TARGET_PAGE_SIZE, kernel_cmdline);
pstrcpy_targphys("cmdline", CMDLINE_ADDR, TARGET_PAGE_SIZE, kernel_cmdline);
} else {
fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, 0);
}

View File

@ -384,7 +384,7 @@ static void ppc_heathrow_init (ram_addr_t ram_size,
fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_SIZE, kernel_size);
if (kernel_cmdline) {
fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, CMDLINE_ADDR);
pstrcpy_targphys(CMDLINE_ADDR, TARGET_PAGE_SIZE, kernel_cmdline);
pstrcpy_targphys("cmdline", CMDLINE_ADDR, TARGET_PAGE_SIZE, kernel_cmdline);
} else {
fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, 0);
}

View File

@ -250,7 +250,7 @@ static void r2d_init(ram_addr_t ram_size,
SDRAM_BASE + LINUX_LOAD_OFFSET,
SDRAM_SIZE - LINUX_LOAD_OFFSET);
env->pc = (SDRAM_BASE + LINUX_LOAD_OFFSET) | 0xa0000000;
pstrcpy_targphys(SDRAM_BASE + 0x10100, 256, kernel_cmdline);
pstrcpy_targphys("cmdline", SDRAM_BASE + 0x10100, 256, kernel_cmdline);
} else {
kernel_size = load_image_targphys(kernel_filename, SDRAM_BASE, SDRAM_SIZE);
env->pc = SDRAM_BASE | 0xa0000000; /* Start from P2 area */

View File

@ -299,6 +299,7 @@ static unsigned long sun4m_load_kernel(const char *kernel_filename,
int linux_boot;
unsigned int i;
long initrd_size, kernel_size;
uint8_t *ptr;
linux_boot = (kernel_filename != NULL);
@ -341,9 +342,10 @@ static unsigned long sun4m_load_kernel(const char *kernel_filename,
}
if (initrd_size > 0) {
for (i = 0; i < 64 * TARGET_PAGE_SIZE; i += TARGET_PAGE_SIZE) {
if (ldl_phys(KERNEL_LOAD_ADDR + i) == 0x48647253) { // HdrS
stl_phys(KERNEL_LOAD_ADDR + i + 16, INITRD_LOAD_ADDR);
stl_phys(KERNEL_LOAD_ADDR + i + 20, initrd_size);
ptr = rom_ptr(KERNEL_LOAD_ADDR + i);
if (ldl_p(ptr) == 0x48647253) { // HdrS
stl_p(ptr + 16, INITRD_LOAD_ADDR);
stl_p(ptr + 20, initrd_size);
break;
}
}
@ -875,7 +877,7 @@ static void sun4m_hw_init(const struct sun4m_hwdef *hwdef, ram_addr_t RAM_size,
fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_SIZE, kernel_size);
if (kernel_cmdline) {
fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, CMDLINE_ADDR);
pstrcpy_targphys(CMDLINE_ADDR, TARGET_PAGE_SIZE, kernel_cmdline);
pstrcpy_targphys("cmdline", CMDLINE_ADDR, TARGET_PAGE_SIZE, kernel_cmdline);
} else {
fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, 0);
}
@ -1457,7 +1459,7 @@ static void sun4d_hw_init(const struct sun4d_hwdef *hwdef, ram_addr_t RAM_size,
fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_SIZE, kernel_size);
if (kernel_cmdline) {
fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, CMDLINE_ADDR);
pstrcpy_targphys(CMDLINE_ADDR, TARGET_PAGE_SIZE, kernel_cmdline);
pstrcpy_targphys("cmdline", CMDLINE_ADDR, TARGET_PAGE_SIZE, kernel_cmdline);
} else {
fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, 0);
}
@ -1645,7 +1647,7 @@ static void sun4c_hw_init(const struct sun4c_hwdef *hwdef, ram_addr_t RAM_size,
fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_SIZE, kernel_size);
if (kernel_cmdline) {
fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, CMDLINE_ADDR);
pstrcpy_targphys(CMDLINE_ADDR, TARGET_PAGE_SIZE, kernel_cmdline);
pstrcpy_targphys("cmdline", CMDLINE_ADDR, TARGET_PAGE_SIZE, kernel_cmdline);
} else {
fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, 0);
}

View File

@ -651,7 +651,7 @@ static void sun4uv_init(ram_addr_t RAM_size,
fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_SIZE, kernel_size);
if (kernel_cmdline) {
fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, CMDLINE_ADDR);
pstrcpy_targphys(CMDLINE_ADDR, TARGET_PAGE_SIZE, kernel_cmdline);
pstrcpy_targphys("cmdline", CMDLINE_ADDR, TARGET_PAGE_SIZE, kernel_cmdline);
} else {
fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, 0);
}