From patchwork Fri Sep 5 15:15:26 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 386396 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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 ozlabs.org (Postfix) with ESMTPS id 23C5E1400B6 for ; Sat, 6 Sep 2014 01:16:22 +1000 (EST) Received: from localhost ([::1]:58412 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XPvFM-0004ld-70 for incoming@patchwork.ozlabs.org; Fri, 05 Sep 2014 11:16:20 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60089) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XPvEk-0003mv-I8 for qemu-devel@nongnu.org; Fri, 05 Sep 2014 11:15:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XPvEe-0002kp-Km for qemu-devel@nongnu.org; Fri, 05 Sep 2014 11:15:42 -0400 Received: from mail-we0-f178.google.com ([74.125.82.178]:55423) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XPvEe-0002kf-F2 for qemu-devel@nongnu.org; Fri, 05 Sep 2014 11:15:36 -0400 Received: by mail-we0-f178.google.com with SMTP id q58so426019wes.37 for ; Fri, 05 Sep 2014 08:15:32 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=YVzCEmMPjqaYOZVPRry67+lVn7mV2oxavK6Mff8vsqk=; b=l6tBLiSLNc+ZJIBJrgW9dsteO4YQ5qVKPcfOXZ9FDYWHnyF5zOguedLQXN2/XTgiML p43zBm0PblrsBb38tamT5z59x8adUVhgrVZcvweqgIDQrUx+UUP0BANMUKYAkz5coS8m +SEmpMDDces8wIaErHqum3vTVIbI4Z1en/j9PplfjG04iVkNtXL0Uiuqcz0fYUzBy+mG W90jcSamWD0uuTxtu3kE07uEyiAx4dNKvFgmAIdRNoVoc+bnMwjyTD86guLFsM7dHh/v f2gVhcektOpKEhgx+QS0gV++X0t1A7MMgXiRV9IR/OzwB3BBOgGuTYnT70ETRxLtHUNX Tj8Q== X-Gm-Message-State: ALoCoQnvtNvcXvQwjbnEHel0oqARF60JuZXAm59ItFVUNTpL/w9rc8Xa0pqI06HiDTWdrWQH+sgs X-Received: by 10.180.105.8 with SMTP id gi8mr4633052wib.46.1409930132875; Fri, 05 Sep 2014 08:15:32 -0700 (PDT) Received: from ards-macbook-pro.local (cag06-7-83-153-85-71.fbx.proxad.net. [83.153.85.71]) by mx.google.com with ESMTPSA id wx3sm1734308wjc.19.2014.09.05.08.15.31 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 05 Sep 2014 08:15:32 -0700 (PDT) From: Ard Biesheuvel To: peter.maydell@linaro.org, qemu-devel@nongnu.org Date: Fri, 5 Sep 2014 17:15:26 +0200 Message-Id: <1409930126-28449-7-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1409930126-28449-1-git-send-email-ard.biesheuvel@linaro.org> References: <1409930126-28449-1-git-send-email-ard.biesheuvel@linaro.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 74.125.82.178 Cc: fu.wei@linaro.org, christoffer.dall@linaro.org, Ard Biesheuvel Subject: [Qemu-devel] [PATCH 6/6] hw/arm/boot: enable DTB support when booting ELF images 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 Add support for loading DTB images when booting ELF images via -kernel. The DTB image is located at the next 4 KB boundary above the highest address covered by the loaded ELF image. Signed-off-by: Ard Biesheuvel --- hw/arm/boot.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/hw/arm/boot.c b/hw/arm/boot.c index 8d8653978dfe..60c4f6af7884 100644 --- a/hw/arm/boot.c +++ b/hw/arm/boot.c @@ -458,7 +458,7 @@ void arm_load_kernel(ARMCPU *cpu, struct arm_boot_info *info) int kernel_size; int initrd_size; int is_linux = 0; - uint64_t elf_entry; + uint64_t elf_entry, elf_low_addr; int elf_machine; hwaddr entry, kernel_load_offset; int big_endian; @@ -529,7 +529,21 @@ void arm_load_kernel(ARMCPU *cpu, struct arm_boot_info *info) /* Assume that raw images are linux kernels, and ELF images are not. */ kernel_size = load_elf(info->kernel_filename, NULL, NULL, &elf_entry, - NULL, NULL, big_endian, elf_machine, 1); + &elf_low_addr, NULL, big_endian, elf_machine, 1); + if (kernel_size > 0 && have_dtb(info)) { + /* If we have a DTB in combination with an ELF executable image, + * put the DTB at the base of RAM like we do for bootloaders. + */ + uint32_t dtb_size; + + if (load_dtb(info->loader_start, info, &dtb_size)) { + exit(1); + } + if (info->loader_start + dtb_size > elf_low_addr) { + fprintf(stderr, "Image %s overlaps DTB\n", info->kernel_filename); + exit(1); + } + } entry = elf_entry; if (kernel_size < 0) { kernel_size = load_uimage(info->kernel_filename, &entry, NULL,