From patchwork Fri Sep 27 16:56:36 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 20675 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-vc0-f197.google.com (mail-vc0-f197.google.com [209.85.220.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 87FD825E77 for ; Fri, 27 Sep 2013 16:57:28 +0000 (UTC) Received: by mail-vc0-f197.google.com with SMTP id gd11sf2560917vcb.4 for ; Fri, 27 Sep 2013 09:57:28 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=HofJDu0zEFz+DZ91wUPKnto21+nP1J/hwI5loiuTgyo=; b=nN1Cf5QZmyipj51j8shIs0pkb1FLhHVvCl2ROmbF3ySFtvb+xcucd8TmumbnslThZG tAjiQwIq5H9QIjxaSwhFcos65U+B1naRWWNQW5xnqkM9mbfLrnVXHW8zbX6a8AVCv1yh t83GFUXIsCfDN6NERRzr8EKX7VQq8/AMiQY/iOJwWxJAbeAdkPFNQtFL3H/SZ1GPYp1N nt7ZRlQvJe/wEJepV1qi7ribWXJ6BNMZ2NvRWI3p9WuRAsmC1l3e0eBSeRnDvbdhO/Mv u3XH5YxvYC0LaR6u3dwkfAfekuuRIhl6HJlv0aqCSzU0mNy4t3qCmbfGHZrPR9g262UO wvkw== X-Gm-Message-State: ALoCoQl/yGpjxE7XJVTrHVcAuZfoMz85HdvOnPRudyGvltYHYo0o3vx2ELSEaDVOl62hQavVSejo X-Received: by 10.236.34.134 with SMTP id s6mr1225207yha.49.1380301048302; Fri, 27 Sep 2013 09:57:28 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.24.172 with SMTP id v12ls1397450qef.91.gmail; Fri, 27 Sep 2013 09:57:28 -0700 (PDT) X-Received: by 10.220.13.20 with SMTP id z20mr7255149vcz.0.1380301048170; Fri, 27 Sep 2013 09:57:28 -0700 (PDT) Received: from mail-ve0-f175.google.com (mail-ve0-f175.google.com [209.85.128.175]) by mx.google.com with ESMTPS id k17si2051762vck.102.1969.12.31.16.00.00 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 27 Sep 2013 09:57:28 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.128.175 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.128.175; Received: by mail-ve0-f175.google.com with SMTP id jy13so2198145veb.20 for ; Fri, 27 Sep 2013 09:56:58 -0700 (PDT) X-Received: by 10.52.98.35 with SMTP id ef3mr1148309vdb.37.1380301018008; Fri, 27 Sep 2013 09:56:58 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.220.174.196 with SMTP id u4csp439654vcz; Fri, 27 Sep 2013 09:56:57 -0700 (PDT) X-Received: by 10.194.175.193 with SMTP id cc1mr2386097wjc.54.1380301016665; Fri, 27 Sep 2013 09:56:56 -0700 (PDT) Received: from mail-we0-f181.google.com (mail-we0-f181.google.com [74.125.82.181]) by mx.google.com with ESMTPS id kx10si3244811wjb.51.1969.12.31.16.00.00 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 27 Sep 2013 09:56:56 -0700 (PDT) Received-SPF: neutral (google.com: 74.125.82.181 is neither permitted nor denied by best guess record for domain of julien.grall@linaro.org) client-ip=74.125.82.181; Received: by mail-we0-f181.google.com with SMTP id p61so3004378wes.12 for ; Fri, 27 Sep 2013 09:56:55 -0700 (PDT) X-Received: by 10.194.175.66 with SMTP id by2mr2156294wjc.59.1380301015688; Fri, 27 Sep 2013 09:56:55 -0700 (PDT) Received: from belegaer.uk.xensource.com. ([185.25.64.249]) by mx.google.com with ESMTPSA id q5sm15639406wiz.3.1969.12.31.16.00.00 (version=TLSv1.2 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 27 Sep 2013 09:56:55 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xen.org Cc: stefano.stabellini@eu.citrix.com, ian.campbell@citrix.com, patches@linaro.org, tim@xen.org, Julien Grall Subject: [PATCH v3 4/5] xen/arm: Add support to load initrd in dom0 Date: Fri, 27 Sep 2013 17:56:36 +0100 Message-Id: <1380300997-28099-5-git-send-email-julien.grall@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1380300997-28099-1-git-send-email-julien.grall@linaro.org> References: <1380300997-28099-1-git-send-email-julien.grall@linaro.org> X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: julien.grall@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.128.175 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Signed-off-by: Julien Grall Acked-by: Ian Campbell --- Changes in v3: - s/ALIGN/ROUNDUP/ Changes in v2: - Align the initrd and DTB length to 2MB --- xen/arch/arm/domain_build.c | 101 +++++++++++++++++++++++++++++++++++++------ xen/arch/arm/kernel.c | 20 +++++---- xen/arch/arm/kernel.h | 2 + 3 files changed, 102 insertions(+), 21 deletions(-) diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c index fb1fa56..4f91327 100644 --- a/xen/arch/arm/domain_build.c +++ b/xen/arch/arm/domain_build.c @@ -163,12 +163,16 @@ static int write_properties(struct domain *d, struct kernel_info *kinfo, * * * remember xen,dom0-bootargs if we don't already have * bootargs (from module #1, above). - * * remove bootargs, xen,dom0-bootargs and xen,xen-bootargs. + * * remove bootargs, xen,dom0-bootargs, xen,xen-bootargs, + * linux,initrd-start and linux,initrd-end. */ if ( dt_node_path_is_equal(np, "/chosen") ) { - if ( dt_property_name_is_equal(pp, "xen,xen-bootargs") ) + if ( dt_property_name_is_equal(pp, "xen,xen-bootargs") || + dt_property_name_is_equal(pp, "linux,initrd-start") || + dt_property_name_is_equal(pp, "linux,initrd-end") ) continue; + if ( dt_property_name_is_equal(pp, "xen,dom0-bootargs") ) { had_dom0_bootargs = 1; @@ -214,12 +218,22 @@ static int write_properties(struct domain *d, struct kernel_info *kinfo, strlen(bootargs) + 1); if ( res ) return res; - } - /* - * XXX should populate /chosen/linux,initrd-{start,end} here if we - * have module[2] - */ + /* + * If the bootloader provides an initrd, we must create a placeholder + * for the initrd properties. The values will be replaced later. + */ + if ( early_info.modules.module[MOD_INITRD].size ) + { + res = fdt_property_cell(kinfo->fdt, "linux,initrd-start", 0); + if ( res ) + return res; + + res = fdt_property_cell(kinfo->fdt, "linux,initrd-end", 0); + if ( res ) + return res; + } + } return 0; } @@ -765,6 +779,8 @@ static int prepare_dtb(struct domain *d, struct kernel_info *kinfo) int new_size; int ret; paddr_t end; + paddr_t initrd_len; + paddr_t dtb_len; ASSERT(dt_host && (dt_host->sibling == NULL)); @@ -791,8 +807,10 @@ static int prepare_dtb(struct domain *d, struct kernel_info *kinfo) if ( ret < 0 ) goto err; - /* Actual new size */ - new_size = fdt_totalsize(kinfo->fdt); + /* Align DTB and initrd size to 2Mb. Linux only requires 4 byte alignment */ + initrd_len = ROUNDUP(early_info.modules.module[MOD_INITRD].size, MB(2)); + dtb_len = ROUNDUP(fdt_totalsize(kinfo->fdt), MB(2)); + new_size = initrd_len + dtb_len; /* * DTB must be loaded such that it does not conflict with the @@ -801,14 +819,14 @@ static int prepare_dtb(struct domain *d, struct kernel_info *kinfo) * the recommendation in Documentation/arm64/booting.txt is below * 512MB. Place at 128MB, (or, if we have less RAM, as high as * possible) in order to satisfy both. + * If the bootloader provides an initrd, it will be loaded just + * after the DTB. */ end = kinfo->mem.bank[0].start + kinfo->mem.bank[0].size; end = MIN(kinfo->mem.bank[0].start + (128<<20) + new_size, end); - kinfo->dtb_paddr = end - new_size; - - /* Align the address to 2Mb. Linux only requires 4 byte alignment */ - kinfo->dtb_paddr &= ~((2 << 20) - 1); + kinfo->initrd_paddr = end - initrd_len; + kinfo->dtb_paddr = kinfo->initrd_paddr - dtb_len; if ( kinfo->dtb_paddr < kinfo->mem.bank[0].start || kinfo->mem.bank[0].start + new_size > end ) @@ -841,6 +859,61 @@ static void dtb_load(struct kernel_info *kinfo) xfree(kinfo->fdt); } +static void initrd_load(struct kernel_info *kinfo) +{ + paddr_t load_addr = kinfo->initrd_paddr; + paddr_t paddr = early_info.modules.module[MOD_INITRD].start; + paddr_t len = early_info.modules.module[MOD_INITRD].size; + unsigned long offs; + int node; + int res; + + if ( !len ) + return; + + printk("Loading dom0 initrd from %"PRIpaddr" to 0x%"PRIpaddr"-0x%"PRIpaddr"\n", + paddr, load_addr, load_addr + len); + + /* Fix up linux,initrd-start and linux,initrd-end in /chosen */ + node = fdt_path_offset(kinfo->fdt, "/chosen"); + if ( node < 0 ) + panic("Cannot find the /chosen node"); + + res = fdt_setprop_inplace_cell(kinfo->fdt, node, "linux,initrd-start", + load_addr); + if ( res ) + panic("Cannot fix up \"linux,initrd-start\" property\n"); + + res = fdt_setprop_inplace_cell(kinfo->fdt, node, "linux,initrd-end", + load_addr + len); + if ( res ) + panic("Cannot fix up \"linux,initrd-end\" property\n"); + + for ( offs = 0; offs < len; ) + { + int rc; + paddr_t s, l, ma; + void *dst; + + s = offs & ~PAGE_MASK; + l = min(PAGE_SIZE - s, len); + + rc = gvirt_to_maddr(load_addr + offs, &ma); + if ( rc ) + { + panic("\nUnable to translate guest address\n"); + return; + } + + dst = map_domain_page(ma>>PAGE_SHIFT); + + copy_from_paddr(dst + s, paddr + offs, l, BUFFERABLE); + + unmap_domain_page(dst); + offs += l; + } +} + int construct_dom0(struct domain *d) { struct kernel_info kinfo = {}; @@ -877,6 +950,8 @@ int construct_dom0(struct domain *d) p2m_load_VTTBR(d); kernel_load(&kinfo); + /* initrd_load will fix up the fdt, so call it before dtb_load */ + initrd_load(&kinfo); dtb_load(&kinfo); discard_initial_modules(); diff --git a/xen/arch/arm/kernel.c b/xen/arch/arm/kernel.c index 6d2c164..315d12c 100644 --- a/xen/arch/arm/kernel.c +++ b/xen/arch/arm/kernel.c @@ -72,15 +72,22 @@ static void kernel_zimage_check_overlap(struct kernel_info *info) { paddr_t zimage_start = info->zimage.load_addr; paddr_t zimage_end = info->zimage.load_addr + info->zimage.len; - paddr_t dtb_start = info->dtb_paddr; - paddr_t dtb_end = info->dtb_paddr + fdt_totalsize(info->fdt); + paddr_t start = info->dtb_paddr; + paddr_t end; - if ( (dtb_start > zimage_end) || (dtb_end < zimage_start) ) + end = info->initrd_paddr + early_info.modules.module[MOD_INITRD].size; + + /* + * In the dom0 memory, the initrd will be just after the DTB. So we + * only need to check if the zImage range will overlap the + * DTB-initrd range. + */ + if ( (start > zimage_end) || (end < zimage_start) ) return; panic(XENLOG_ERR "The kernel(0x%"PRIpaddr"-0x%"PRIpaddr - ") is overlapping the DTB(0x%"PRIpaddr"-0x%"PRIpaddr")\n", - zimage_start, zimage_end, dtb_start, dtb_end); + ") is overlapping the DTB-initrd(0x%"PRIpaddr"-0x%"PRIpaddr")\n", + zimage_start, zimage_end, start, end); } static void kernel_zimage_load(struct kernel_info *info) @@ -335,9 +342,6 @@ int kernel_prepare(struct kernel_info *info) paddr_t start, size; - if ( early_info.modules.nr_mods > MOD_INITRD ) - panic("Cannot handle dom0 initrd yet\n"); - if ( early_info.modules.nr_mods < MOD_KERNEL ) { printk("No boot modules found, trying flash\n"); diff --git a/xen/arch/arm/kernel.h b/xen/arch/arm/kernel.h index c900e74..debf590 100644 --- a/xen/arch/arm/kernel.h +++ b/xen/arch/arm/kernel.h @@ -21,6 +21,8 @@ struct kernel_info { paddr_t dtb_paddr; paddr_t entry; + paddr_t initrd_paddr; + void *kernel_img; unsigned kernel_order;