From patchwork Mon Mar 19 13:58:25 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Aleksandar Rikalo X-Patchwork-Id: 10292385 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 8F266600F6 for ; Mon, 19 Mar 2018 14:02:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D9A962913C for ; Mon, 19 Mar 2018 14:02:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CE48C29150; Mon, 19 Mar 2018 14:02:46 +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 2BC2E2910C for ; Mon, 19 Mar 2018 14:02:35 +0000 (UTC) Received: from localhost ([::1]:42195 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1exvMv-0008UB-2h for patchwork-qemu-devel@patchwork.kernel.org; Mon, 19 Mar 2018 10:02:33 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37493) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1exvLP-0007Uy-Rf for qemu-devel@nongnu.org; Mon, 19 Mar 2018 10:01:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1exvLL-00057C-Bf for qemu-devel@nongnu.org; Mon, 19 Mar 2018 10:00:59 -0400 Received: from mx2.rt-rk.com ([89.216.37.149]:37525 helo=mail.rt-rk.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1exvLK-0004qx-Vw for qemu-devel@nongnu.org; Mon, 19 Mar 2018 10:00:55 -0400 Received: from localhost (localhost [127.0.0.1]) by mail.rt-rk.com (Postfix) with ESMTP id 1C1511A47D2; Mon, 19 Mar 2018 15:00:31 +0100 (CET) X-Virus-Scanned: amavisd-new at rt-rk.com Received: from rtrkw304-lin.domain.local (rtrkw304-lin.domain.local [10.10.13.79]) by mail.rt-rk.com (Postfix) with ESMTPSA id F3B391A47B1; Mon, 19 Mar 2018 15:00:30 +0100 (CET) From: Aleksandar Rikalo To: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Date: Mon, 19 Mar 2018 14:58:25 +0100 Message-Id: <1521467905-8791-1-git-send-email-aleksandar.rikalo@rt-rk.com> X-Mailer: git-send-email 1.9.1 MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 89.216.37.149 Subject: [Qemu-devel] [PATCH v2] target-mips: Add initrd support for the Boston board 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, Petar Jovanovic , Paul Burton , Aleksandar Rikalo , Yongbok Kim , Aurelien Jarno Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Aleksandar Rikalo Add support for initial ramdisk loading for the Mips Boston board. Signed-off-by: Aleksandar Rikalo Reviewed-by: Philippe Mathieu-Daudé --- Changes since previous version according to Philippe's comments: - 'long inird_size' is changed to 'target_ulong initrd_size', as it should be - error_report() is used instead of fprintf() hw/mips/boston.c | 54 +++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 45 insertions(+), 9 deletions(-) diff --git a/hw/mips/boston.c b/hw/mips/boston.c index fb23161..6960a60 100644 --- a/hw/mips/boston.c +++ b/hw/mips/boston.c @@ -30,6 +30,7 @@ #include "hw/loader-fit.h" #include "hw/mips/cps.h" #include "hw/mips/cpudevs.h" +#include "hw/mips/mips.h" #include "hw/pci-host/xilinx-pcie.h" #include "qapi/error.h" #include "qemu/cutils.h" @@ -333,10 +334,12 @@ static const void *boston_fdt_filter(void *opaque, const void *fdt_orig, { BostonState *s = BOSTON(opaque); MachineState *machine = s->mach; - const char *cmdline; + GString *cmdline; int err; void *fdt; size_t fdt_sz, ram_low_sz, ram_high_sz; + target_ulong initrd_size; + ram_addr_t initrd_offset; fdt_sz = fdt_totalsize(fdt_orig) * 2; fdt = g_malloc0(fdt_sz); @@ -347,20 +350,53 @@ static const void *boston_fdt_filter(void *opaque, const void *fdt_orig, return NULL; } - cmdline = (machine->kernel_cmdline && machine->kernel_cmdline[0]) - ? machine->kernel_cmdline : " "; - err = qemu_fdt_setprop_string(fdt, "/chosen", "bootargs", cmdline); - if (err < 0) { - fprintf(stderr, "couldn't set /chosen/bootargs\n"); - return NULL; - } - ram_low_sz = MIN(256 * M_BYTE, machine->ram_size); ram_high_sz = machine->ram_size - ram_low_sz; qemu_fdt_setprop_sized_cells(fdt, "/memory@0", "reg", 1, 0x00000000, 1, ram_low_sz, 1, 0x90000000, 1, ram_high_sz); + cmdline = g_string_new(machine->kernel_cmdline); + + /* load initrd */ + initrd_offset = 0; + if (machine->initrd_filename) { + initrd_size = get_image_size(machine->initrd_filename); + if (initrd_size != (target_ulong) -1) { + /* The kernel allocates the bootmap memory in the low memory after + the initrd. It takes at most 128kiB for 2GB RAM and 4kiB + pages. */ + initrd_offset = (ram_low_sz - initrd_size - 131072 + - ~INITRD_PAGE_MASK) & INITRD_PAGE_MASK; + + if ((int64_t)cpu_mips_kseg0_to_phys(NULL, *load_addr + fdt_sz) + >= (int64_t)initrd_offset) { + error_report("memory too small for initial ram disk '%s'", + machine->initrd_filename); + exit(1); + } + + initrd_size = load_image_targphys(machine->initrd_filename, + initrd_offset, + initrd_size); + } + if (initrd_size == (target_ulong) -1) { + error_report("could not load initial ram disk '%s'", + machine->initrd_filename); + exit(1); + } + g_string_append_printf(cmdline, " rd_start=0x%" PRIx64 " rd_size=%li", + cpu_mips_phys_to_kseg0(NULL, initrd_offset), + initrd_size); + } + + err = qemu_fdt_setprop_string(fdt, "/chosen", "bootargs", cmdline->str); + g_string_free(cmdline, true); + if (err < 0) { + error_report("couldn't set /chosen/bootargs"); + exit(1); + } + fdt = g_realloc(fdt, fdt_totalsize(fdt)); qemu_fdt_dumpdtb(fdt, fdt_sz);