From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43797) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wz6sN-00033m-BY for qemu-devel@nongnu.org; Mon, 23 Jun 2014 12:13:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Wz6sE-0001mG-7T for qemu-devel@nongnu.org; Mon, 23 Jun 2014 12:13:47 -0400 Received: from mail-lb0-x235.google.com ([2a00:1450:4010:c04::235]:49586) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wz6sD-0001m7-Ve for qemu-devel@nongnu.org; Mon, 23 Jun 2014 12:13:38 -0400 Received: by mail-lb0-f181.google.com with SMTP id p9so4766955lbv.40 for ; Mon, 23 Jun 2014 09:13:37 -0700 (PDT) From: Max Filippov Date: Mon, 23 Jun 2014 20:12:55 +0400 Message-Id: <1403539976-22581-9-git-send-email-jcmvbkbc@gmail.com> In-Reply-To: <1403539976-22581-1-git-send-email-jcmvbkbc@gmail.com> References: <1403539976-22581-1-git-send-email-jcmvbkbc@gmail.com> Subject: [Qemu-devel] [PATCH 8/9] hw/xtensa/xtfpga: implement DTB loading List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Max Filippov , Waldemar Brodkorb Signed-off-by: Max Filippov --- hw/xtensa/xtfpga.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/hw/xtensa/xtfpga.c b/hw/xtensa/xtfpga.c index 0e0d825..01825d6 100644 --- a/hw/xtensa/xtfpga.c +++ b/hw/xtensa/xtfpga.c @@ -37,6 +37,7 @@ #include "hw/block/flash.h" #include "sysemu/blockdev.h" #include "sysemu/char.h" +#include "sysemu/device_tree.h" #include "qemu/error-report.h" #include "bootparam.h" @@ -178,6 +179,7 @@ static void lx_init(const LxBoardDesc *board, MachineState *machine) const char *cpu_model = machine->cpu_model; 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"); int n; if (!cpu_model) { @@ -246,6 +248,9 @@ static void lx_init(const LxBoardDesc *board, MachineState *machine) .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); @@ -255,6 +260,9 @@ static void lx_init(const LxBoardDesc *board, MachineState *machine) if (kernel_cmdline) { bp_size += get_tag_size(strlen(kernel_cmdline) + 1); } + if (dtb_filename) { + bp_size += get_tag_size(sizeof(uint32_t)); + } /* Put kernel bootparameters to the end of that SRAM */ tagptr = (tagptr - bp_size) & ~0xff; @@ -266,6 +274,21 @@ static void lx_init(const LxBoardDesc *board, MachineState *machine) 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); + } cur_tagptr = put_tag(cur_tagptr, BP_TAG_LAST, 0, NULL); env->regs[2] = tagptr; -- 1.8.1.4