Xtensa fixes and improvements queue 2014-06-29:

- fix FLASH mapping to boot region for KC705;
 - clean up boot parameters passing;
 - add uImage, DTB and initrd support.
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v1
 
 iQIcBAABAgAGBQJTr0RgAAoJEFH5zJH4P6BEn54QAJchMWQ9tlmXIG/ziVOSxHnS
 G+VDSarwIZvaxUvwPZoxDI65w7Tb2tquihW1P3FJ0ssnaFfBVliPZNmVxYK/cmhy
 deRoZdj7w5aAP8J6OueBu56pmrSs4LzxVV7PXdrZezMkz6YUEX5PGihpFvgGk8Fm
 oHaj0Ml66GRrK2OnZnCo1bxZLnqDdo3JSxRq2YgcsgdbI7SjJv6tGRHqJDz89wN+
 gtdudb4yijrtc1SvfYLRC13/nWNM3JHkEtMaK2oTUFvoUtcERVYvBSulSiD2etmT
 L7Hf5wVwPah8HNq3x9dz/ytY9D7GC2lJ0BZOfXPge/CjmPMhnLS8czAUtUq8sMKF
 dWa9cFvK7qD57FQozqmZTcrWMXMusN9K69rUJV7b88UFTRnmI7dKruO8MHWsdi2L
 R66ds6020A4ZdBFMV+A1C/W2gsNSRoDJZXfesmhGawvxeFI9uQJe6H0vhDfVusGM
 s8+AOpt6myNW75l13/rUmWsZymvpqnUFX4JZuS92pPiS+BTh0knmufsU1gofpawc
 r7tsZcSkHLelgd1gKmuI5c4WLeweVpRQ7Wg5IqLQWDbr/EAn4NRPRsYzDfnkuRfA
 Yq8UkZU3yh2841OueM6AjIj+Hyu9WFc94ul3hRN2zUS0wTOsf7g6h5etmuT383XE
 PC8LYK8QOqpr+3NyHCn+
 =9PLS
 -----END PGP SIGNATURE-----

Merge remote-tracking branch 'remotes/xtensa/tags/20140629-xtensa' into staging

Xtensa fixes and improvements queue 2014-06-29:
- fix FLASH mapping to boot region for KC705;
- clean up boot parameters passing;
- add uImage, DTB and initrd support.

# gpg: Signature made Sat 28 Jun 2014 23:40:32 BST using RSA key ID F83FA044
# gpg: Good signature from "Max Filippov <max.filippov@cogentembedded.com>"
# gpg:                 aka "Max Filippov <jcmvbkbc@gmail.com>"

* remotes/xtensa/tags/20140629-xtensa:
  hw/xtensa/xtfpga: implement initrd loading
  hw/xtensa/xtfpga: implement DTB loading
  hw/xtensa/xtfpga: implement uImage loading
  hw/xtensa/xtfpga: add memory info to bootparam
  hw/xtensa/xtfpga: refactor bootparameters filling
  hw/xtensa/xtfpga: use symbolic constants for bootparam tags
  hw/xtensa/xtfpga: retrieve parameters from machine_opts
  hw/xtensa: replace fprintfs with error_report
  hw/xtensa: remove extraneous xtensa_ prefix from file names
  hw/xtensa/xtfpga: fix FLASH mapping to boot region for KC705

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
This commit is contained in:
Peter Maydell 2014-06-29 16:17:50 +01:00
commit 4daebe014e
5 changed files with 165 additions and 53 deletions

View file

@ -1,3 +1,3 @@
obj-y += pic_cpu.o
obj-y += xtensa_sim.o
obj-y += xtensa_lx60.o
obj-y += sim.o
obj-y += xtfpga.o

49
hw/xtensa/bootparam.h Normal file
View file

@ -0,0 +1,49 @@
#ifndef HW_XTENSA_BOOTPARAM
#define HW_XTENSA_BOOTPARAM
#define BP_TAG_COMMAND_LINE 0x1001 /* command line (0-terminated string)*/
#define BP_TAG_INITRD 0x1002 /* ramdisk addr and size (bp_meminfo) */
#define BP_TAG_MEMORY 0x1003 /* memory addr and size (bp_meminfo) */
#define BP_TAG_SERIAL_BAUDRATE 0x1004 /* baud rate of current console. */
#define BP_TAG_SERIAL_PORT 0x1005 /* serial device of current console */
#define BP_TAG_FDT 0x1006 /* flat device tree addr */
#define BP_TAG_FIRST 0x7B0B /* first tag with a version number */
#define BP_TAG_LAST 0x7E0B /* last tag */
typedef struct BpTag {
uint16_t tag;
uint16_t size;
} BpTag;
typedef struct BpMemInfo {
uint32_t type;
uint32_t start;
uint32_t end;
} BpMemInfo;
#define MEMORY_TYPE_CONVENTIONAL 0x1000
#define MEMORY_TYPE_NONE 0x2000
static inline size_t get_tag_size(size_t data_size)
{
return data_size + sizeof(BpTag) + 4;
}
static inline ram_addr_t put_tag(ram_addr_t addr, uint16_t tag,
size_t size, const void *data)
{
BpTag bp_tag = {
.tag = tswap16(tag),
.size = tswap16((size + 3) & ~3),
};
cpu_physical_memory_write(addr, &bp_tag, sizeof(bp_tag));
addr += sizeof(bp_tag);
cpu_physical_memory_write(addr, data, size);
addr += (size + 3) & ~3;
return addr;
}
#endif

View file

@ -31,6 +31,7 @@
#include "elf.h"
#include "exec/memory.h"
#include "exec/address-spaces.h"
#include "qemu/error-report.h"
static uint64_t translate_phys_addr(void *opaque, uint64_t addr)
{
@ -63,8 +64,9 @@ static void xtensa_sim_init(MachineState *machine)
for (n = 0; n < smp_cpus; n++) {
cpu = cpu_xtensa_init(cpu_model);
if (cpu == NULL) {
fprintf(stderr, "Unable to find CPU definition\n");
exit(1);
error_report("unable to find CPU definition '%s'\n",
cpu_model);
exit(EXIT_FAILURE);
}
env = &cpu->env;

View file

@ -1,25 +0,0 @@
#ifndef HW_XTENSA_BOOTPARAM
#define HW_XTENSA_BOOTPARAM
typedef struct BpTag {
uint16_t tag;
uint16_t size;
} BpTag;
static inline ram_addr_t put_tag(ram_addr_t addr, uint16_t tag,
size_t size, const void *data)
{
BpTag bp_tag = {
.tag = tswap16(tag),
.size = tswap16((size + 3) & ~3),
};
cpu_physical_memory_write(addr, &bp_tag, sizeof(bp_tag));
addr += sizeof(bp_tag);
cpu_physical_memory_write(addr, data, size);
addr += (size + 3) & ~3;
return addr;
}
#endif

View file

@ -37,11 +37,14 @@
#include "hw/block/flash.h"
#include "sysemu/blockdev.h"
#include "sysemu/char.h"
#include "xtensa_bootparam.h"
#include "sysemu/device_tree.h"
#include "qemu/error-report.h"
#include "bootparam.h"
typedef struct LxBoardDesc {
hwaddr flash_base;
size_t flash_size;
size_t flash_boot_base;
size_t flash_sector_size;
size_t sram_size;
} LxBoardDesc;
@ -172,9 +175,12 @@ static void lx_init(const LxBoardDesc *board, MachineState *machine)
MemoryRegion *ram, *rom, *system_io;
DriveInfo *dinfo;
pflash_t *flash = NULL;
QemuOpts *machine_opts = qemu_get_machine_opts();
const char *cpu_model = machine->cpu_model;
const char *kernel_filename = machine->kernel_filename;
const char *kernel_cmdline = machine->kernel_cmdline;
const char *kernel_filename = qemu_opt_get(machine_opts, "kernel");
const char *kernel_cmdline = qemu_opt_get(machine_opts, "append");
const char *dtb_filename = qemu_opt_get(machine_opts, "dtb");
const char *initrd_filename = qemu_opt_get(machine_opts, "initrd");
int n;
if (!cpu_model) {
@ -184,8 +190,9 @@ static void lx_init(const LxBoardDesc *board, MachineState *machine)
for (n = 0; n < smp_cpus; n++) {
cpu = cpu_xtensa_init(cpu_model);
if (cpu == NULL) {
fprintf(stderr, "Unable to find CPU definition\n");
exit(1);
error_report("unable to find CPU definition '%s'\n",
cpu_model);
exit(EXIT_FAILURE);
}
env = &cpu->env;
@ -226,39 +233,117 @@ static void lx_init(const LxBoardDesc *board, MachineState *machine)
board->flash_size / board->flash_sector_size,
4, 0x0000, 0x0000, 0x0000, 0x0000, be);
if (flash == NULL) {
fprintf(stderr, "Unable to mount pflash\n");
exit(1);
error_report("unable to mount pflash\n");
exit(EXIT_FAILURE);
}
}
/* Use presence of kernel file name as 'boot from SRAM' switch. */
if (kernel_filename) {
uint32_t entry_point = env->pc;
size_t bp_size = 3 * get_tag_size(0); /* first/last and memory tags */
uint32_t tagptr = 0xfe000000 + board->sram_size;
uint32_t cur_tagptr;
BpMemInfo memory_location = {
.type = tswap32(MEMORY_TYPE_CONVENTIONAL),
.start = tswap32(0),
.end = tswap32(machine->ram_size),
};
uint32_t lowmem_end = machine->ram_size < 0x08000000 ?
machine->ram_size : 0x08000000;
uint32_t cur_lowmem = QEMU_ALIGN_UP(lowmem_end / 2, 4096);
rom = g_malloc(sizeof(*rom));
memory_region_init_ram(rom, NULL, "lx60.sram", board->sram_size);
vmstate_register_ram_global(rom);
memory_region_add_subregion(system_memory, 0xfe000000, rom);
/* Put kernel bootparameters to the end of that SRAM */
if (kernel_cmdline) {
size_t cmdline_size = strlen(kernel_cmdline) + 1;
size_t bp_size = sizeof(BpTag[4]) + cmdline_size;
uint32_t tagptr = (0xfe000000 + board->sram_size - bp_size) & ~0xff;
env->regs[2] = tagptr;
tagptr = put_tag(tagptr, 0x7b0b, 0, NULL);
if (cmdline_size > 1) {
tagptr = put_tag(tagptr, 0x1001,
cmdline_size, kernel_cmdline);
}
tagptr = put_tag(tagptr, 0x7e0b, 0, NULL);
bp_size += get_tag_size(strlen(kernel_cmdline) + 1);
}
if (dtb_filename) {
bp_size += get_tag_size(sizeof(uint32_t));
}
if (initrd_filename) {
bp_size += get_tag_size(sizeof(BpMemInfo));
}
/* Put kernel bootparameters to the end of that SRAM */
tagptr = (tagptr - bp_size) & ~0xff;
cur_tagptr = put_tag(tagptr, BP_TAG_FIRST, 0, NULL);
cur_tagptr = put_tag(cur_tagptr, BP_TAG_MEMORY,
sizeof(memory_location), &memory_location);
if (kernel_cmdline) {
cur_tagptr = put_tag(cur_tagptr, BP_TAG_COMMAND_LINE,
strlen(kernel_cmdline) + 1, kernel_cmdline);
}
if (dtb_filename) {
int fdt_size;
void *fdt = load_device_tree(dtb_filename, &fdt_size);
uint32_t dtb_addr = tswap32(cur_lowmem);
if (!fdt) {
error_report("could not load DTB '%s'\n", dtb_filename);
exit(EXIT_FAILURE);
}
cpu_physical_memory_write(cur_lowmem, fdt, fdt_size);
cur_tagptr = put_tag(cur_tagptr, BP_TAG_FDT,
sizeof(dtb_addr), &dtb_addr);
cur_lowmem = QEMU_ALIGN_UP(cur_lowmem + fdt_size, 4096);
}
if (initrd_filename) {
BpMemInfo initrd_location = { 0 };
int initrd_size = load_ramdisk(initrd_filename, cur_lowmem,
lowmem_end - cur_lowmem);
if (initrd_size < 0) {
initrd_size = load_image_targphys(initrd_filename,
cur_lowmem,
lowmem_end - cur_lowmem);
}
if (initrd_size < 0) {
error_report("could not load initrd '%s'\n", initrd_filename);
exit(EXIT_FAILURE);
}
initrd_location.start = tswap32(cur_lowmem);
initrd_location.end = tswap32(cur_lowmem + initrd_size);
cur_tagptr = put_tag(cur_tagptr, BP_TAG_INITRD,
sizeof(initrd_location), &initrd_location);
cur_lowmem = QEMU_ALIGN_UP(cur_lowmem + initrd_size, 4096);
}
cur_tagptr = put_tag(cur_tagptr, BP_TAG_LAST, 0, NULL);
env->regs[2] = tagptr;
uint64_t elf_entry;
uint64_t elf_lowaddr;
int success = load_elf(kernel_filename, translate_phys_addr, cpu,
&elf_entry, &elf_lowaddr, NULL, be, ELF_MACHINE, 0);
if (success > 0) {
env->pc = elf_entry;
entry_point = elf_entry;
} else {
hwaddr ep;
int is_linux;
success = load_uimage(kernel_filename, &ep, NULL, &is_linux);
if (success > 0 && is_linux) {
entry_point = ep;
} else {
error_report("could not load kernel '%s'\n",
kernel_filename);
exit(EXIT_FAILURE);
}
}
if (entry_point != env->pc) {
static const uint8_t jx_a0[] = {
#ifdef TARGET_WORDS_BIGENDIAN
0x0a, 0, 0,
#else
0xa0, 0, 0,
#endif
};
env->regs[0] = entry_point;
cpu_physical_memory_write(env->pc, jx_a0, sizeof(jx_a0));
}
} else {
if (flash) {
@ -266,9 +351,9 @@ static void lx_init(const LxBoardDesc *board, MachineState *machine)
MemoryRegion *flash_io = g_malloc(sizeof(*flash_io));
memory_region_init_alias(flash_io, NULL, "lx60.flash",
flash_mr, 0,
board->flash_size < 0x02000000 ?
board->flash_size : 0x02000000);
flash_mr, board->flash_boot_base,
board->flash_size - board->flash_boot_base < 0x02000000 ?
board->flash_size - board->flash_boot_base : 0x02000000);
memory_region_add_subregion(system_memory, 0xfe000000,
flash_io);
}
@ -313,6 +398,7 @@ static void xtensa_kc705_init(MachineState *machine)
static const LxBoardDesc kc705_board = {
.flash_base = 0xf0000000,
.flash_size = 0x08000000,
.flash_boot_base = 0x06000000,
.flash_sector_size = 0x20000,
.sram_size = 0x2000000,
};