From patchwork Mon Jun 23 16:12:55 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Filippov X-Patchwork-Id: 363016 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 1941E140077 for ; Tue, 24 Jun 2014 02:17:45 +1000 (EST) Received: from localhost ([::1]:54633 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wz6wB-0008D9-6P for incoming@patchwork.ozlabs.org; Mon, 23 Jun 2014 12:17:43 -0400 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) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=/6Jmkp38zfdy8IRHFa6AAkCLbizg3uzcIBwI7vt0tHg=; b=KsGjQY6B810ycBVSHONoSb7I/C9xTw7dQaG7EyemI6MFGLdN1IPHGBg6yVGWkCyhm6 VNpFSbNnPsemf4NfYB4kZB/LQuZaFuV7Fh8CgdCv+SCzAUF856qHC3VYUBCxznVC5v9H Zabdv2wWuef9s3HAyT8Dafcde8yO6j8hXH7s10i1dU6ynGpUYhnoyUxsbz+xc/h1ZKpk UqOYkxbnr8fMRDcItpAEH29LYPGlyAaiSIhkrKxRbSEZTVmPI9ZRGUTY/6cinAerMytb PFO7JSO4IJU4Z9b3k7z/UfRssc/LlxRtktK5/DPCaqW4u3upz7g5HMmk1ehoW4kePO9B /DpQ== X-Received: by 10.152.29.66 with SMTP id i2mr2253273lah.82.1403540016974; Mon, 23 Jun 2014 09:13:36 -0700 (PDT) Received: from octofox.metropolis ([5.18.161.252]) by mx.google.com with ESMTPSA id z6sm8040505laj.39.2014.06.23.09.13.35 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 23 Jun 2014 09:13:36 -0700 (PDT) From: Max Filippov To: qemu-devel@nongnu.org Date: Mon, 23 Jun 2014 20:12:55 +0400 Message-Id: <1403539976-22581-9-git-send-email-jcmvbkbc@gmail.com> X-Mailer: git-send-email 1.8.1.4 In-Reply-To: <1403539976-22581-1-git-send-email-jcmvbkbc@gmail.com> References: <1403539976-22581-1-git-send-email-jcmvbkbc@gmail.com> X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:4010:c04::235 Cc: Max Filippov , Waldemar Brodkorb Subject: [Qemu-devel] [PATCH 8/9] hw/xtensa/xtfpga: implement DTB loading X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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;