From patchwork Sun Jun 19 05:34:17 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yoshinori Sato X-Patchwork-Id: 9186073 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id D944D601C0 for ; Sun, 19 Jun 2016 06:30:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BBF38262FF for ; Sun, 19 Jun 2016 06:30:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AC31027D16; Sun, 19 Jun 2016 06:30:02 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id AA9BF262FF for ; Sun, 19 Jun 2016 06:30:01 +0000 (UTC) Received: from localhost ([::1]:37682 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bEWF5-0005S6-Kr for patchwork-qemu-devel@patchwork.kernel.org; Sun, 19 Jun 2016 02:29:59 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58884) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bEVNZ-0001nh-Su for qemu-devel@nongnu.org; Sun, 19 Jun 2016 01:34:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bEVNV-0002LC-OT for qemu-devel@nongnu.org; Sun, 19 Jun 2016 01:34:41 -0400 Received: from mail2.asahi-net.or.jp ([202.224.39.198]:21426) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bEVNV-0002KU-3h for qemu-devel@nongnu.org; Sun, 19 Jun 2016 01:34:37 -0400 Received: from sa76r4 (y081184.ppp.asahi-net.or.jp [118.243.81.184]) by mail2.asahi-net.or.jp (Postfix) with ESMTP id 669C776B6; Sun, 19 Jun 2016 14:34:24 +0900 (JST) Received: from localhost (localhost [127.0.0.1]) by sa76r4 (Postfix) with ESMTP id 0B791363B; Sun, 19 Jun 2016 14:34:24 +0900 (JST) X-Virus-Scanned: Debian amavisd-new at sa76r4.localdomain Received: from sa76r4 ([127.0.0.1]) by localhost (sa76r4.localdomain [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id xNpc5X3t-u9r; Sun, 19 Jun 2016 14:34:23 +0900 (JST) Received: by sa76r4 (Postfix, from userid 1000) id E515B396F; Sun, 19 Jun 2016 14:34:23 +0900 (JST) From: Yoshinori Sato To: Magnus Damm , Aurelien Jarno Date: Sun, 19 Jun 2016 14:34:17 +0900 Message-Id: <1466314457-19920-1-git-send-email-ysato@users.sourceforge.jp> X-Mailer: git-send-email 2.7.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (barebone) [generic] [fuzzy] X-Received-From: 202.224.39.198 X-Mailman-Approved-At: Sun, 19 Jun 2016 02:29:34 -0400 Subject: [Qemu-devel] [PATCH] hw/sh4: Add dtb support X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-devel@nongnu.org, Yoshinori Sato Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP New SH kernel use dtb. This patch add dtb support for R2D board emulation. Signed-off-by: Yoshinori Sato --- hw/sh4/r2d.c | 52 +++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 43 insertions(+), 9 deletions(-) diff --git a/hw/sh4/r2d.c b/hw/sh4/r2d.c index f2547ed..203c117 100644 --- a/hw/sh4/r2d.c +++ b/hw/sh4/r2d.c @@ -41,6 +41,7 @@ #include "hw/usb.h" #include "hw/block/flash.h" #include "sysemu/block-backend.h" +#include "sysemu/device_tree.h" #include "exec/address-spaces.h" #define FLASH_BASE 0x00000000 @@ -51,7 +52,7 @@ #define SM501_VRAM_SIZE 0x800000 -#define BOOT_PARAMS_OFFSET 0x0001000 +#define BOOT_PARAMS_OFFSET 0x0010000 /* CONFIG_BOOT_LINK_OFFSET of Linux kernel */ #define LINUX_LOAD_OFFSET 0x0800000 #define INITRD_LOAD_OFFSET 0x1800000 @@ -198,6 +199,7 @@ static qemu_irq *r2d_fpga_init(MemoryRegion *sysmem, typedef struct ResetData { SuperHCPU *cpu; uint32_t vector; + uint32_t dtb; } ResetData; static void main_cpu_reset(void *opaque) @@ -207,6 +209,8 @@ static void main_cpu_reset(void *opaque) cpu_reset(CPU(s->cpu)); env->pc = s->vector; + /* r4_bank1 is DTB address */ + env->gregs[4 + 16] = s->dtb; } static struct QEMU_PACKED @@ -225,10 +229,12 @@ static struct QEMU_PACKED static void r2d_init(MachineState *machine) { + QemuOpts *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 *initrd_filename = machine->initrd_filename; + const char *kernel_filename; + const char *kernel_cmdline; + const char *initrd_filename; + const char *dtb_filename; SuperHCPU *cpu; CPUSH4State *env; ResetData *reset_info; @@ -258,6 +264,12 @@ static void r2d_init(MachineState *machine) reset_info->vector = env->pc; qemu_register_reset(main_cpu_reset, reset_info); + machine_opts = qemu_get_machine_opts(); + kernel_filename = qemu_opt_get(machine_opts, "kernel"); + kernel_cmdline = qemu_opt_get(machine_opts, "append"); + initrd_filename = qemu_opt_get(machine_opts, "initrd"); + dtb_filename = qemu_opt_get(machine_opts, "dtb"); + /* Allocate memory space */ memory_region_init_ram(sdram, NULL, "r2d.sdram", SDRAM_SIZE, &error_fatal); vmstate_register_ram_global(sdram); @@ -347,11 +359,33 @@ static void r2d_init(MachineState *machine) boot_params.initrd_size = tswap32(initrd_size); } - if (kernel_cmdline) { - /* I see no evidence that this .kernel_cmdline buffer requires - NUL-termination, so using strncpy should be ok. */ - strncpy(boot_params.kernel_cmdline, kernel_cmdline, - sizeof(boot_params.kernel_cmdline)); + if (!dtb_filename) { + if (kernel_cmdline) { + /* I see no evidence that this .kernel_cmdline buffer requires + NUL-termination, so using strncpy should be ok. */ + strncpy(boot_params.kernel_cmdline, kernel_cmdline, + sizeof(boot_params.kernel_cmdline)); + } + } else { + void *fdt; + int r = 0; + uint32_t addr; + int fdt_size; + + fdt = load_device_tree(dtb_filename, &fdt_size); + if (!fdt) { + return; + } + if (kernel_cmdline) { + r = qemu_fdt_setprop_string(fdt, "/chosen", "bootargs", + kernel_cmdline); + if (r < 0) { + fprintf(stderr, "couldn't set /chosen/bootargs\n"); + } + } + addr = (SDRAM_BASE + SDRAM_SIZE - fdt_size) & ~0xfff; + cpu_physical_memory_write(addr, fdt, fdt_size); + reset_info->dtb = addr; } rom_add_blob_fixed("boot_params", &boot_params, sizeof(boot_params),