Hexagon: Fix virt boot
v2 cover Hexagon: Fix virt boot
The virt machine -bios option didn't work for h2 loadlinux. Refactor virt to use the logic in hex-board which works for loadlinux boots on the machines which use hex-board.
Fully reviewed series, to be included in upcoming PR.
Changes in v2:
- remove the 0xa0000000 shift for kernel load
v1: https://lore.kernel.org/qemu-devel/[email protected]/
Brian Cain (3):
hw/hexagon: share the Hexagon VM guest boot code hw/hexagon/virt: fix firmware boot hw/hexagon: fix FDT address and size cells
include/hw/hexagon/hex-board.h | 36 +++++++ hw/hexagon/hex-board.c | 153 ++++++++++++++++++++++++++-- hw/hexagon/qcom_dsp.c | 178 +++------------------------------ hw/hexagon/virt.c | 68 ++++++++++--- tests/qtest/boot-serial-test.c | 5 +- 5 files changed, 253 insertions(+), 187 deletions(-)
Signature · 1 line
2.34.1
PATCH v2 1/3 hw/hexagon: share the Hexagon VM guest boot code
The DSP subsystem machines boot a guest kernel through the hypervisor firmware. Move that code, the DT nodes, guest timer, into hex-board so that it can be used by virt.
No functional change, this will be used by a subsequent commit.
--- include/hw/hexagon/hex-board.h | 35 +++++++ hw/hexagon/hex-board.c | 138 +++++++++++++++++++++++++ hw/hexagon/qcom_dsp.c | 178 +++------------------------------ 3 files changed, 187 insertions(+), 164 deletions(-)
include/hw/hexagon/hex-board.h +35 -0
@@ -53,6 +53,41 @@ uint64_t hex_board_load_elf(const char *filename,uint64_t (*translate)(void *opaque,uint64_t addr), void *opaque, uint64_t *high); +/* The most RAM that a guest of the Hexagon VM host maps for its kernel. */ +#define HEX_BOARD_MAX_KERNEL_RAM (896 * MiB) + +/* Add a /memory node for @size bytes of RAM at @base. */ +void hex_board_fdt_add_memory (MachineState *ms,hwaddr base,hwaddr size); + +/* +* Add the node that tells a guest's timer driver which interrupt to expect. +* The Hexagon VM host provides the timer itself through hypercalls, so +* nothing backs the window at @base. +*/ +void hex_board_fdt_add_vm_timer (MachineState *ms,hwaddr base,hwaddr size, +int irq); + +/* +* Boot a guest kernel through the Hexagon VM host firmware (H2). Load the +* firmware ELF @firmware as it is linked and the kernel ELF named by -kernel +* relocated by @kernel_addr. Place the device tree, whose size is +* @fdt_size, after the kernel, and the -initrd after that, in the RAM +* that spans from @ddr_base for the machine's RAM size. Write a boot stub +* at @stub_base that passes the device tree address in r1:r0 and enters the +* firmware, and return @stub_base, where CPU 0 starts. The device tree +* address is returned in @fdt_addr. Exits on failure. +*/ +uint64_t hex_board_load_vm_guest (MachineState *ms,const char *firmware, +hwaddr ddr_base,hwaddr kernel_addr, +hwaddr stub_base,int fdt_size, +hwaddr *fdt_addr); + +/* +* Reject -initrd unless the guest boots through firmware, which is when +* @firmware is set and -kernel is given. +*/ +void hex_board_check_initrd (MachineState *ms,bool firmware); +/* Copy the device tree to @addr and refresh its rng-seed on reset. */ void hex_board_load_fdt (MachineState *ms,int fdt_size,hwaddr addr);
hw/hexagon/hex-board.c +138 -0
150 lines not on this page · raw message
hw/hexagon/qcom_dsp.c +14 -164
227 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH v2 2/3 hw/hexagon/virt: fix firmware boot
In reply to Brian Cain-bios on virt only loaded a raw image of at most 64 KiB at address zero. This is insufficient for H2 firmware, which is usually hundreds of KiB.
Boot a kernel given with -kernel through the firmware given with -bios. Load both ELFs at their declared physical addresses, place the device tree and initrd after the kernel, and enter the firmware through a boot stub that passes the device tree in r1:r0.
--- include/hw/hexagon/hex-board.h | 17 +++++---- hw/hexagon/hex-board.c | 10 +++-- hw/hexagon/virt.c | 68 ++++++++++++++++++++++++++-------- tests/qtest/boot-serial-test.c | 5 ++- 4 files changed, 71 insertions(+), 29 deletions(-)
include/hw/hexagon/hex-board.h +9 -8
@@ -69,16 +69,17 @@ void hex_board_fdt_add_vm_timer(MachineState *ms, hwaddr base, hwaddr size,/* * Boot a guest kernel through the Hexagon VM host firmware (H2). Load the -* firmware ELF @firmware as it is linked and the kernel ELF named by -kernel -* relocated by @kernel_addr. Place the device tree, whose size is -* @fdt_size, after the kernel, and the -initrd after that, in the RAM -* that spans from @ddr_base for the machine's RAM size. Write a boot stub -* at @stub_base that passes the device tree address in r1:r0 and enters the -* firmware, and return @stub_base, where CPU 0 starts. The device tree -* address is returned in @fdt_addr. Exits on failure. +* firmware ELF @firmware as it is linked and the kernel ELF named by -kernel. +* @kernel_load_offset is added to the kernel's physical addresses; zero loads +* the ELF as linked. Place the device tree, whose size is @fdt_size, after +* the kernel, and the -initrd after that, in the RAM that spans from +* @ddr_base for the machine's RAM size. Write a boot stub at @stub_base that +* passes the device tree address in r1:r0 and enters the firmware, and return +* @stub_base, where CPU 0 starts. The device tree address is returned in +* @fdt_addr. Exits on failure. */ uint64_t hex_board_load_vm_guest (MachineState *ms,const char *firmware, -hwaddr ddr_base,hwaddr kernel_addr, +hwaddr ddr_base,hwaddr kernel_load_offset,hwaddr stub_base,int fdt_size,hwaddr *fdt_addr);
hw/hexagon/hex-board.c +6 -4
@@ -337,7 +337,7 @@ void hex_board_check_initrd(MachineState *ms, bool firmware) }uint64_t hex_board_load_vm_guest (MachineState *ms,const char *firmware, -hwaddr ddr_base,hwaddr kernel_addr, +hwaddr ddr_base,hwaddr kernel_load_offset,hwaddr stub_base,int fdt_size,hwaddr *fdt_addr) {
@@ -345,15 +345,17 @@ uint64_t hex_board_load_vm_guest(MachineState *ms, const char *firmware,hwaddr ram_end = ddr_base + ms->ram_size;uint32_t stub[ARRAY_SIZE (vm_boot_stub)]; -if (ddr_base > stub_base || ram_end <= kernel_addr) { +if (ddr_base > stub_base || ram_end <= kernel_load_offset) {error_report ("RAM (%" PRIu64" MiB at 0x%" HWADDR_PRIx") is too " "small: the kernel is loaded at 0x%" HWADDR_PRIx, - ms->ram_size / MiB, ddr_base, kernel_addr); + ms->ram_size / MiB, ddr_base, kernel_load_offset);exit (1 ); } firmware_entry =hex_board_load_elf (firmware,NULL ,NULL ,NULL ); -hex_board_load_elf (ms->kernel_filename, vm_guest_translate, &kernel_addr, +hex_board_load_elf (ms->kernel_filename, + kernel_load_offset ? vm_guest_translate :NULL , + kernel_load_offset ? &kernel_load_offset :NULL , &image_high); *fdt_addr =QEMU_ALIGN_UP (image_high +16 * MiB,4 * MiB);hex_board_load_initrd (ms, ram_end, *fdt_addr, fdt_size);
hw/hexagon/virt.c +53 -15
126 lines not on this page · raw message
tests/qtest/boot-serial-test.c +3 -2
@@ -146,7 +146,7 @@ static const uint8_t bios_hexagon[] = {0x00 ,0x40 ,0x00 ,0x01 ,/* immext(#0x10000000) */ 0x00 ,0xc0 ,0x00 ,0x78 ,/* r0 = ##0x10000000 */ 0x54 ,0xc0 ,0x00 ,0x3c ,/* memb(r0+#0) = #0x54 Write 'T' */ -0xf8 ,0xff ,0xff ,0x59 /* jump 0x0 ; Loop back to start */ +0xfa ,0xff ,0xff ,0x59 /* jump _start */ }; typedef struct testdef {
@@ -201,7 +201,8 @@ static const testdef_t tests[] = { { "arm", "microbit", "", "T", sizeof(kernel_nrf51), kernel_nrf51 }, { "arm", "stm32vldiscovery", "", "T", sizeof(kernel_stm32vldiscovery), kernel_stm32vldiscovery }, - { "hexagon", "virt", "", "TT", sizeof(bios_hexagon), NULL, bios_hexagon }, + { "hexagon", "virt", "", "TT", sizeof(bios_hexagon), NULL, + bios_hexagon }, { NULL } };
Signature · 1 line
2.34.1
PATCH v2 3/3 hw/hexagon: fix FDT address and size cells
In reply to Brian CainHexagon MMUs support 64-bit physical addresses. Describe the root and /soc buses with two address cells and two size cells so their child reg properties can represent the full address and size range.
--- hw/hexagon/hex-board.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)
hw/hexagon/hex-board.c +7 -6
@@ -43,13 +43,13 @@ void hex_board_create_fdt(MachineState *ms, const char *model, ms->fdt = fdt;qemu_fdt_setprop_cell (fdt,"/" ,"#address-cells" ,0x2 ); -qemu_fdt_setprop_cell (fdt,"/" ,"#size-cells" ,0x1 ); +qemu_fdt_setprop_cell (fdt,"/" ,"#size-cells" ,0x2 );qemu_fdt_setprop_string (fdt,"/" ,"model" , model);qemu_fdt_setprop_string (fdt,"/" ,"compatible" , compatible);qemu_fdt_add_subnode (fdt,"/soc" );qemu_fdt_setprop_cell (fdt,"/soc" ,"#address-cells" ,0x2 ); -qemu_fdt_setprop_cell (fdt,"/soc" ,"#size-cells" ,0x1 ); +qemu_fdt_setprop_cell (fdt,"/soc" ,"#size-cells" ,0x2 );qemu_fdt_setprop (fdt,"/soc" ,"ranges" ,NULL ,0 );qemu_fdt_add_subnode (fdt,"/chosen" );
@@ -78,7 +78,7 @@ int32_t hex_board_fdt_add_l2vic(MachineState *ms,qemu_fdt_setprop_cell (ms->fdt, nodename,"#interrupt-cells" ,2 );qemu_fdt_setprop (ms->fdt, nodename,"compatible" , compat,sizeof (compat));qemu_fdt_setprop_cells (ms->fdt, nodename,"reg" ,0 , cfg->l2vic_base, - cfg->l2vic_size); +0 , cfg->l2vic_size);qemu_fdt_setprop (ms->fdt, nodename,"interrupt-controller" ,NULL ,0 );qemu_fdt_setprop_cell (ms->fdt, nodename,"phandle" , l2vic_phandle);
@@ -95,7 +95,8 @@ void hex_board_fdt_add_hvx(MachineState *ms,qemu_fdt_setprop_string (ms->fdt,"/soc/vtcm" ,"compatible" ,"qcom,hexagon_vtcm" );qemu_fdt_setprop_cells (ms->fdt,"/soc/vtcm" ,"reg" ,0 , - t->vtcm_base <<16 , t->vtcm_size_kb *1024 ); + t->vtcm_base <<16 ,0 , + t->vtcm_size_kb *1024 ); }if (t->ext_contexts >0 ) {
@@ -175,7 +176,7 @@ void hex_board_create_uart(MachineState *ms, hwaddr base, hwaddr size,qemu_fdt_add_subnode (ms->fdt, nodename);/* Can't use setprop_string because of the embedded NUL */ qemu_fdt_setprop (ms->fdt, nodename,"compatible" , compat,sizeof (compat)); -qemu_fdt_setprop_cells (ms->fdt, nodename,"reg" ,0 , base, size); +qemu_fdt_setprop_cells (ms->fdt, nodename,"reg" ,0 , base,0 , size);fdt_set_irq (ms, nodename, irq);qemu_fdt_setprop_cell (ms->fdt, nodename,"interrupt-parent" , l2vic_phandle);
@@ -211,7 +212,7 @@ void hex_board_create_virtio(MachineState *ms, hwaddr base, hwaddr size,qemu_fdt_add_subnode (ms->fdt, nodename);qemu_fdt_setprop_string (ms->fdt, nodename,"compatible" ,"virtio,mmio" ); -qemu_fdt_setprop_cells (ms->fdt, nodename,"reg" ,0 , slot, size); +qemu_fdt_setprop_cells (ms->fdt, nodename,"reg" ,0 , slot,0 , size);fdt_set_irq (ms, nodename, irq);qemu_fdt_setprop_cell (ms->fdt, nodename,"interrupt-parent" , l2vic_phandle);
Signature · 1 line
2.34.1