From patchwork Mon Jan 7 16:31:17 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 154945 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp3706232ljp; Mon, 7 Jan 2019 09:12:09 -0800 (PST) X-Google-Smtp-Source: ALg8bN75ezaEG1jZ3piCUvABZFGx37WNb9weM481mP0s2M0Gp76hBbajk+RrsWjCAd2j62zo6oR8 X-Received: by 2002:a1c:448a:: with SMTP id r132mr8864473wma.47.1546881129896; Mon, 07 Jan 2019 09:12:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1546881129; cv=none; d=google.com; s=arc-20160816; b=IQrjiT/0jg6zvo95aTrPfS3yChBGvYUd2eEM6+k8XIAYm9fZpcU8+gh5rmV04G1eoh pK4k4llYlVbnZbTZtwJg65gASaerGSe8P43a7J/9g1o6eThhJA6+m9j5BfTdOzmcxwN9 G53ociHkBQ/s/diS92duRdr89QvXOKFdx/Kic/OEKlh/yE/AyYi6SRtxYtqlQAtI7HDi 94PKXu+8g+/aodeoAM1/yrd+kc2ORgMCrVWp/hu+NCmy/ebwuf1xJI5nSmprR9qdoAQJ HO39oojtWgCp/jWnX75GXG9VNmvcmI9lEMx5sFjrnLDWa3QLTTfjY8wrZmp0zHoV/shK vzfQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=cDFB1Ur65EARuRk/dPzzE6tv5eNAyb1OwUrHB1LwiDY=; b=akAw8Kji530pkuGcgN2TEEtQFBWI3oA0mvwx6NMTxU47oCcjKrCz8GkbpE46kbUPMy ZbQp2VzpQTCFOEJ+D8Rvu2X/+D2soqcjIxvoZmYbqNDkb840AuCe76Teh4yCTga7GIFN mi3hIF8hatMIvQLRSvz4KwqFLZUrf419hgtPyHb51+c1Gf35iARPFF0HRvW4IWDVsHdO H5fViiRZpBcPrGaH91K+YjuXOppGYx5QBH31YRS5jORDVcglx28u3/IkwdCV9y2cMC1i xQgE0pK6VBMpCtrmwO3g+nqgyNGVgG9ugbEuCO/mYvJ/KiOkGkrej1NAi3gih/IRCoAc D7sg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=DbdHnwn2; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id k133si4199990wma.31.2019.01.07.09.12.09 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 07 Jan 2019 09:12:09 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=DbdHnwn2; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([127.0.0.1]:51609 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ggYRc-0003Ke-Q9 for patch@linaro.org; Mon, 07 Jan 2019 12:12:08 -0500 Received: from eggs.gnu.org ([209.51.188.92]:46717) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ggXpO-0005gW-4K for qemu-devel@nongnu.org; Mon, 07 Jan 2019 11:32:39 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ggXpK-00038p-3B for qemu-devel@nongnu.org; Mon, 07 Jan 2019 11:32:35 -0500 Received: from mail-wr1-x443.google.com ([2a00:1450:4864:20::443]:36299) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ggXpG-0002a2-5w for qemu-devel@nongnu.org; Mon, 07 Jan 2019 11:32:32 -0500 Received: by mail-wr1-x443.google.com with SMTP id u4so1091630wrp.3 for ; Mon, 07 Jan 2019 08:32:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=cDFB1Ur65EARuRk/dPzzE6tv5eNAyb1OwUrHB1LwiDY=; b=DbdHnwn2NB2Wv4Rxick+QBawJM7fCbBdQleBqfsoAbSAQcARf0aTjjxyEx37gOQX32 XM1V4WiLHQQXOLBQc+Z77Y+lrJ44V18cN8K5MAXhSD/vGYJ8mME9kpUwxNOqdQpnLIPF QuSZiXg3tyC7EL/KDBPBx84xjKs1J5N3/+ZOg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=cDFB1Ur65EARuRk/dPzzE6tv5eNAyb1OwUrHB1LwiDY=; b=ec2lbuGusiybgJlUB253ceRdCfHWkMr58sAMG6sM2WolLlaQ7iZFFFNdIuj5fgr7GG yP6knYzFdLnhSyjnPoyhrXRw/NPFCv1swSdD/2pHWtYw8Xm+A83CDhIK1i03+mwkjF65 T6ygkmSID64E3SywIMMegwMWe4xFlDtS/1o8NMAS6F/W5HATJYK6ycu1I8r1rgtuPNqh Jd3RqasskusGYkVttLyuCvScLlQ3OTlvzTZ3TPblLm7+4AweylRd+m5LgbrRLz6ANDlT HDxkG/CszFfpjIxSz6leiXydZ6rUfi9Ge0O/p3yzBVZgmXFxizPezicNbaJ3OQsmVZdF tREQ== X-Gm-Message-State: AJcUukfV2RstSyCTuFVVi+rYVdW+ixKLqzSJyHyAlp/Qt0dHazi253R2 3njHas8Rjo8dNrvhEAG6lqCD3EuOcBL5Xw== X-Received: by 2002:adf:9c8a:: with SMTP id d10mr28094632wre.244.1546878725943; Mon, 07 Jan 2019 08:32:05 -0800 (PST) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [81.2.115.148]) by smtp.gmail.com with ESMTPSA id j14sm46039759wrv.96.2019.01.07.08.32.04 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 07 Jan 2019 08:32:05 -0800 (PST) From: Peter Maydell To: qemu-devel@nongnu.org Date: Mon, 7 Jan 2019 16:31:17 +0000 Message-Id: <20190107163117.16269-38-peter.maydell@linaro.org> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190107163117.16269-1-peter.maydell@linaro.org> References: <20190107163117.16269-1-peter.maydell@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::443 Subject: [Qemu-devel] [PULL 37/37] Support u-boot noload images for arm as used by, NetBSD/evbarm GENERIC kernel. 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: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Nick Hudson noload kernels are loaded with the u-boot image header and as a result the header size needs adding to the entry point. Fake up a hdr so the kernel image is loaded at the right address and the entry point is adjusted appropriately. The default location for the uboot file is 32MiB above bottom of DRAM. This matches the recommendation in Documentation/arm/Booting. Clarify the load_uimage API to state the passing of a load address when an image doesn't specify one, or when loading a ramdisk is expected. Adjust callers of load_uimage, etc. Signed-off-by: Nick Hudson Message-id: 11488a08-1fe0-a278-2210-deb64731107f@gmx.co.uk Reviewed-by: Peter Maydell Signed-off-by: Peter Maydell --- hw/core/uboot_image.h | 1 + include/hw/loader.h | 7 ++++++- hw/arm/boot.c | 8 +++++--- hw/core/loader.c | 19 ++++++++++++++++--- hw/microblaze/boot.c | 2 +- hw/nios2/boot.c | 2 +- hw/ppc/e500.c | 1 + hw/ppc/ppc440_bamboo.c | 2 +- hw/ppc/sam460ex.c | 2 +- 9 files changed, 33 insertions(+), 11 deletions(-) -- 2.19.2 diff --git a/hw/core/uboot_image.h b/hw/core/uboot_image.h index 34c11a70a67..608022de6ec 100644 --- a/hw/core/uboot_image.h +++ b/hw/core/uboot_image.h @@ -124,6 +124,7 @@ #define IH_TYPE_SCRIPT 6 /* Script file */ #define IH_TYPE_FILESYSTEM 7 /* Filesystem Image (any type) */ #define IH_TYPE_FLATDT 8 /* Binary Flat Device Tree Blob */ +#define IH_TYPE_KERNEL_NOLOAD 14 /* OS Kernel Image (noload) */ /* * Compression Types diff --git a/include/hw/loader.h b/include/hw/loader.h index 0a0ad808ea3..de8a29603b0 100644 --- a/include/hw/loader.h +++ b/include/hw/loader.h @@ -175,10 +175,15 @@ void load_elf_hdr(const char *filename, void *hdr, bool *is64, Error **errp); int load_aout(const char *filename, hwaddr addr, int max_sz, int bswap_needed, hwaddr target_page_size); +#define LOAD_UIMAGE_LOADADDR_INVALID (-1) + /** load_uimage_as: * @filename: Path of uimage file * @ep: Populated with program entry point. Ignored if NULL. - * @loadaddr: Populated with the load address. Ignored if NULL. + * @loadaddr: load address if none specified in the image or when loading a + * ramdisk. Populated with the load address. Ignored if NULL or + * LOAD_UIMAGE_LOADADDR_INVALID (images which do not specify a load + * address will not be loadable). * @is_linux: Is set to true if the image loaded is Linux. Ignored if NULL. * @translate_fn: optional function to translate load addresses * @translate_opaque: opaque data passed to @translate_fn diff --git a/hw/arm/boot.c b/hw/arm/boot.c index 94fce128028..c7a67af7a97 100644 --- a/hw/arm/boot.c +++ b/hw/arm/boot.c @@ -30,8 +30,9 @@ * Documentation/arm/Booting and Documentation/arm64/booting.txt * They have different preferred image load offsets from system RAM base. */ -#define KERNEL_ARGS_ADDR 0x100 -#define KERNEL_LOAD_ADDR 0x00010000 +#define KERNEL_ARGS_ADDR 0x100 +#define KERNEL_NOLOAD_ADDR 0x02000000 +#define KERNEL_LOAD_ADDR 0x00010000 #define KERNEL64_LOAD_ADDR 0x00080000 #define ARM64_TEXT_OFFSET_OFFSET 8 @@ -1082,7 +1083,8 @@ void arm_load_kernel(ARMCPU *cpu, struct arm_boot_info *info) } entry = elf_entry; if (kernel_size < 0) { - kernel_size = load_uimage_as(info->kernel_filename, &entry, NULL, + uint64_t loadaddr = info->loader_start + KERNEL_NOLOAD_ADDR; + kernel_size = load_uimage_as(info->kernel_filename, &entry, &loadaddr, &is_linux, NULL, NULL, as); } if (arm_feature(&cpu->env, ARM_FEATURE_AARCH64) && kernel_size < 0) { diff --git a/hw/core/loader.c b/hw/core/loader.c index fa41842280a..c7182dfa64b 100644 --- a/hw/core/loader.c +++ b/hw/core/loader.c @@ -613,13 +613,26 @@ static int load_uboot_image(const char *filename, hwaddr *ep, hwaddr *loadaddr, goto out; if (hdr->ih_type != image_type) { - fprintf(stderr, "Wrong image type %d, expected %d\n", hdr->ih_type, - image_type); - goto out; + if (!(image_type == IH_TYPE_KERNEL && + hdr->ih_type == IH_TYPE_KERNEL_NOLOAD)) { + fprintf(stderr, "Wrong image type %d, expected %d\n", hdr->ih_type, + image_type); + goto out; + } } /* TODO: Implement other image types. */ switch (hdr->ih_type) { + case IH_TYPE_KERNEL_NOLOAD: + if (!loadaddr || *loadaddr == LOAD_UIMAGE_LOADADDR_INVALID) { + fprintf(stderr, "this image format (kernel_noload) cannot be " + "loaded on this machine type"); + goto out; + } + + hdr->ih_load = *loadaddr + sizeof(*hdr); + hdr->ih_ep += hdr->ih_load; + /* fall through */ case IH_TYPE_KERNEL: address = hdr->ih_load; if (translate_fn) { diff --git a/hw/microblaze/boot.c b/hw/microblaze/boot.c index 35bfeda7aa7..489ab839b7c 100644 --- a/hw/microblaze/boot.c +++ b/hw/microblaze/boot.c @@ -156,7 +156,7 @@ void microblaze_load_kernel(MicroBlazeCPU *cpu, hwaddr ddr_base, /* If it wasn't an ELF image, try an u-boot image. */ if (kernel_size < 0) { - hwaddr uentry, loadaddr; + hwaddr uentry, loadaddr = LOAD_UIMAGE_LOADADDR_INVALID; kernel_size = load_uimage(kernel_filename, &uentry, &loadaddr, 0, NULL, NULL); diff --git a/hw/nios2/boot.c b/hw/nios2/boot.c index 4bb5b601d3a..ed5cb28e942 100644 --- a/hw/nios2/boot.c +++ b/hw/nios2/boot.c @@ -161,7 +161,7 @@ void nios2_load_kernel(Nios2CPU *cpu, hwaddr ddr_base, /* If it wasn't an ELF image, try an u-boot image. */ if (kernel_size < 0) { - hwaddr uentry, loadaddr; + hwaddr uentry, loadaddr = LOAD_UIMAGE_LOADADDR_INVALID; kernel_size = load_uimage(kernel_filename, &uentry, &loadaddr, 0, NULL, NULL); diff --git a/hw/ppc/e500.c b/hw/ppc/e500.c index b20fea0dfce..0581e9e3d4c 100644 --- a/hw/ppc/e500.c +++ b/hw/ppc/e500.c @@ -995,6 +995,7 @@ void ppce500_init(MachineState *machine) * Hrm. No ELF image? Try a uImage, maybe someone is giving us an * ePAPR compliant kernel */ + loadaddr = LOAD_UIMAGE_LOADADDR_INVALID; payload_size = load_uimage(filename, &bios_entry, &loadaddr, NULL, NULL, NULL); if (payload_size < 0) { diff --git a/hw/ppc/ppc440_bamboo.c b/hw/ppc/ppc440_bamboo.c index b8aa55d5266..fc061915887 100644 --- a/hw/ppc/ppc440_bamboo.c +++ b/hw/ppc/ppc440_bamboo.c @@ -179,7 +179,7 @@ static void bamboo_init(MachineState *machine) CPUPPCState *env; uint64_t elf_entry; uint64_t elf_lowaddr; - hwaddr loadaddr = 0; + hwaddr loadaddr = LOAD_UIMAGE_LOADADDR_INVALID; target_long initrd_size = 0; DeviceState *dev; int success; diff --git a/hw/ppc/sam460ex.c b/hw/ppc/sam460ex.c index 4b051c0950a..84ea592749c 100644 --- a/hw/ppc/sam460ex.c +++ b/hw/ppc/sam460ex.c @@ -402,7 +402,7 @@ static void sam460ex_init(MachineState *machine) CPUPPCState *env; PPC4xxI2CState *i2c[2]; hwaddr entry = UBOOT_ENTRY; - hwaddr loadaddr = 0; + hwaddr loadaddr = LOAD_UIMAGE_LOADADDR_INVALID; target_long initrd_size = 0; DeviceState *dev; SysBusDevice *sbdev;