From patchwork Tue Feb 28 22:35:31 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leif Lindholm X-Patchwork-Id: 94667 Delivered-To: patch@linaro.org Received: by 10.140.20.113 with SMTP id 104csp1528595qgi; Tue, 28 Feb 2017 14:38:26 -0800 (PST) X-Received: by 10.200.53.237 with SMTP id l42mr5802026qtb.264.1488321506950; Tue, 28 Feb 2017 14:38:26 -0800 (PST) Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id 93si2630276qkv.164.2017.02.28.14.38.26 for (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 28 Feb 2017 14:38:26 -0800 (PST) Received-SPF: pass (google.com: domain of grub-devel-bounces+patch=linaro.org@gnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org; spf=pass (google.com: domain of grub-devel-bounces+patch=linaro.org@gnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=grub-devel-bounces+patch=linaro.org@gnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:37450 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ciqPY-0007Sb-FT for patch@linaro.org; Tue, 28 Feb 2017 17:38:24 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36682) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ciqMx-0004qo-KY for grub-devel@gnu.org; Tue, 28 Feb 2017 17:35:44 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ciqMw-0004YC-K1 for grub-devel@gnu.org; Tue, 28 Feb 2017 17:35:43 -0500 Received: from mail-wr0-x22d.google.com ([2a00:1450:400c:c0c::22d]:36450) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ciqMw-0004XH-Du for grub-devel@gnu.org; Tue, 28 Feb 2017 17:35:42 -0500 Received: by mail-wr0-x22d.google.com with SMTP id u108so18391597wrb.3 for ; Tue, 28 Feb 2017 14:35:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=XSOLKBaUhtn9O/vplOz1mskzWnFdB3dMvLkXx3NCJNw=; b=EwCs0oUFAGApdssGFcNyvh+ILhmDUCfn3ya96a2x7kSIRrXIWKsX+4gaRFmQol7tZm 7VhmjR8+npdgprg//GOXPdsCo2SwV7q+sm70I6qjdG263UBlon+k2EvE6vLc1Cr54vT3 SM61CYuiZPUVqADs8ZSgVyfDX3oI0pF+lQSuw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=XSOLKBaUhtn9O/vplOz1mskzWnFdB3dMvLkXx3NCJNw=; b=BE3tdJV+/9Dkp0vMCi0FRou5sfreGSJaKZSPzbDswijxghpkeXEXAdppTd/PqFNtzV TeeA1U/8fWDp+QHGxtyKTfw0z/3xnViEwszwtVqRDFUoL7/mWrw/LxCOd58PGBk807jK ulX1v7tHO4bu0UX+rgE1EAQ9EpUVmneRGbeoXuHLbpW32Qd+Syzk7bKMiNtgO4TNLpic gogdQi21/pye4OoNPJHf3CwBNJO9yendCKx+MqOrEZTDQLeKQY0R3zD/jjznkShYUuwC cFRnfHbH1HVvyqtqZKKmeFr8N6HPwoXwY6yZ8upPkX/FdsqI6crRbaTeR94g19y7iVz1 kGSg== X-Gm-Message-State: AMke39lHCV7vdTQu+gFKVzXz8mLD2s0V0TFMY8Op23Jq4lEnQaXU2pnPLPFDsxTjbc8Is96y X-Received: by 10.223.168.43 with SMTP id l40mr4271396wrc.150.1488321339862; Tue, 28 Feb 2017 14:35:39 -0800 (PST) Received: from mohikan.hemma.eciton.net ([2a01:348:6:8735:e23f:49ff:fe6d:9d26]) by smtp.gmail.com with ESMTPSA id 40sm4043391wry.22.2017.02.28.14.35.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 28 Feb 2017 14:35:39 -0800 (PST) From: Leif Lindholm To: grub-devel@gnu.org Subject: [PATCH 1/7] efi: add grub_efi_get_dram_base() function for arm* Date: Tue, 28 Feb 2017 22:35:31 +0000 Message-Id: <20170228223537.9685-2-leif.lindholm@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170228223537.9685-1-leif.lindholm@linaro.org> References: <20170228223537.9685-1-leif.lindholm@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c0c::22d X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: The development of GNU GRUB Cc: Laszlo Ersek , Gerd Hoffmann , Alexander Graf , ard.biesheuvel@linaro.org MIME-Version: 1.0 Errors-To: grub-devel-bounces+patch=linaro.org@gnu.org Sender: "Grub-devel" Since ARM platforms do not have a common memory map, add a helper function that finds the lowest address region with the EFI_MEMORY_WB attribute set in the UEFI memory map. Required for the (32-bit) arm linux loader to restrict the initrd location to where it will be accessible by the kernel at runtime. Signed-off-by: Leif Lindholm --- grub-core/kern/efi/mm.c | 42 ++++++++++++++++++++++++++++++++++++++++++ include/grub/efi/efi.h | 1 + 2 files changed, 43 insertions(+) -- 2.11.0 _______________________________________________ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel diff --git a/grub-core/kern/efi/mm.c b/grub-core/kern/efi/mm.c index 20a47aaf5..460a4b763 100644 --- a/grub-core/kern/efi/mm.c +++ b/grub-core/kern/efi/mm.c @@ -525,3 +525,45 @@ grub_efi_mm_init (void) grub_efi_free_pages ((grub_addr_t) memory_map, 2 * BYTES_TO_PAGES (MEMORY_MAP_SIZE)); } + +#if defined (__arm__) || defined (__aarch64__) +grub_err_t +grub_efi_get_dram_base(grub_addr_t *base_addr) +{ + grub_efi_memory_descriptor_t *memory_map; + grub_efi_memory_descriptor_t *desc; + grub_efi_uintn_t mmap_size; + grub_efi_uintn_t desc_size; + + mmap_size = (1 << GRUB_EFI_PAGE_SHIFT); + while (1) + { + int ret; + + memory_map = grub_malloc (mmap_size); + if (! memory_map) + return GRUB_ERR_OUT_OF_MEMORY; + ret = grub_efi_get_memory_map (&mmap_size, memory_map, NULL, + &desc_size, NULL); + if (ret > 0) + break; + + grub_free (memory_map); + if (ret == 0) + return GRUB_ERR_BUG; + + mmap_size += (1 << GRUB_EFI_PAGE_SHIFT); + } + + for (desc = memory_map, *base_addr = GRUB_UINT_MAX; + (grub_addr_t) desc < ((grub_addr_t) memory_map + mmap_size); + desc = NEXT_MEMORY_DESCRIPTOR (desc, desc_size)) + { + if (desc->attribute & GRUB_EFI_MEMORY_WB) + if (desc->physical_start < *base_addr) + *base_addr = desc->physical_start; + } + + return GRUB_ERR_NONE; +} +#endif diff --git a/include/grub/efi/efi.h b/include/grub/efi/efi.h index e9c601f34..845fc2438 100644 --- a/include/grub/efi/efi.h +++ b/include/grub/efi/efi.h @@ -83,6 +83,7 @@ extern void (*EXPORT_VAR(grub_efi_net_config)) (grub_efi_handle_t hnd, #if defined(__arm__) || defined(__aarch64__) void *EXPORT_FUNC(grub_efi_get_firmware_fdt)(void); +grub_err_t EXPORT_FUNC(grub_efi_get_dram_base)(grub_addr_t *); #endif grub_addr_t grub_efi_modules_addr (void); From patchwork Tue Feb 28 22:35:32 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leif Lindholm X-Patchwork-Id: 94672 Delivered-To: patch@linaro.org Received: by 10.140.20.113 with SMTP id 104csp1531548qgi; Tue, 28 Feb 2017 14:48:08 -0800 (PST) X-Received: by 10.55.120.69 with SMTP id t66mr5687441qkc.182.1488322088475; Tue, 28 Feb 2017 14:48:08 -0800 (PST) Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id l66si2670282qkd.4.2017.02.28.14.48.07 for (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 28 Feb 2017 14:48:08 -0800 (PST) Received-SPF: pass (google.com: domain of grub-devel-bounces+patch=linaro.org@gnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org; spf=pass (google.com: domain of grub-devel-bounces+patch=linaro.org@gnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=grub-devel-bounces+patch=linaro.org@gnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:37491 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ciqYw-0004u8-2S for patch@linaro.org; Tue, 28 Feb 2017 17:48:06 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36670) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ciqMx-0004qN-3D for grub-devel@gnu.org; Tue, 28 Feb 2017 17:35:44 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ciqMw-0004Xn-0S for grub-devel@gnu.org; Tue, 28 Feb 2017 17:35:43 -0500 Received: from mail-wr0-x235.google.com ([2a00:1450:400c:c0c::235]:36452) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ciqMv-0004XT-QH for grub-devel@gnu.org; Tue, 28 Feb 2017 17:35:41 -0500 Received: by mail-wr0-x235.google.com with SMTP id u108so18391757wrb.3 for ; Tue, 28 Feb 2017 14:35:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=YT2qqCsNAUUEhGh7ex2vZyFseNHCB1tlc2xBJM3ZK2g=; b=TwjwZPHitK/8xOGs9jrea2cOFFVQ0a89S4prk0yZw5+ZqWSB5tva0/Nx2H7D5jhshQ Qo4a9i1wtk/neXXfQryoR6jpDyFjusKK8IHilayFi/Pj5dTSLSFw9qLagGY1+jnwIZD0 BruSiF3fzd0DBVi+rB9mk2qtbDliPN55mSv3U= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=YT2qqCsNAUUEhGh7ex2vZyFseNHCB1tlc2xBJM3ZK2g=; b=gHeJBVa58782UT+KrU2cH3/5GHzwfIVljT+w5MswBDqvwjy1ecLXCY/FwunMkvH8NC x5NZh0Cu8w0VOmofbYj6enPNW2Z8X13pZi54Cz3XsfUGM/aapF6tIpb0VzhvPJHuSsM1 KKcgFSH/tvZE7yf17LFeSwNX9uPKQpnjT6OGHCIcrsxhbJdiW7I3bGrtreqvwb79gt/H 42yolQFV8quOUC6p9BH0+MzSt03JpovRt/q0ljo1ZgomBNPGZt4z42CWiZUie/2JWlMW LLDNmN5PvTbLN6kok2BaXILqKpScj76rZyGS1B8SG40R2ZDHfXpaqY8gnN3ASj9xwYLw a0Cw== X-Gm-Message-State: AMke39mk75vhhvqNF6M3Dw2FT0UBvdsJzfpQwDywuM9N8Q8daep9kSRAfI9Lyr1JG+krbBer X-Received: by 10.223.133.164 with SMTP id 33mr4387025wrt.39.1488321340727; Tue, 28 Feb 2017 14:35:40 -0800 (PST) Received: from mohikan.hemma.eciton.net ([2a01:348:6:8735:e23f:49ff:fe6d:9d26]) by smtp.gmail.com with ESMTPSA id 40sm4043391wry.22.2017.02.28.14.35.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 28 Feb 2017 14:35:40 -0800 (PST) From: Leif Lindholm To: grub-devel@gnu.org Subject: [PATCH 2/7] efi: refactor grub_efi_allocate_pages Date: Tue, 28 Feb 2017 22:35:32 +0000 Message-Id: <20170228223537.9685-3-leif.lindholm@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170228223537.9685-1-leif.lindholm@linaro.org> References: <20170228223537.9685-1-leif.lindholm@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c0c::235 X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: The development of GNU GRUB Cc: Laszlo Ersek , Gerd Hoffmann , Alexander Graf , ard.biesheuvel@linaro.org MIME-Version: 1.0 Errors-To: grub-devel-bounces+patch=linaro.org@gnu.org Sender: "Grub-devel" Expose a new function, grub_efi_allocate_pages_real(), making it possible to specify allocation type and memory type as supported by the UEFI AllocatePages boot service. Make grub_efi_allocate_pages() a consumer of the new function, maintaining its old functionality. Also delete some left-around #if 1/#else blocks in the affected functions. Signed-off-by: Leif Lindholm --- grub-core/kern/efi/mm.c | 46 ++++++++++++++++++++++++---------------------- include/grub/efi/efi.h | 5 +++++ 2 files changed, 29 insertions(+), 22 deletions(-) -- 2.11.0 _______________________________________________ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel diff --git a/grub-core/kern/efi/mm.c b/grub-core/kern/efi/mm.c index 460a4b763..7b1763bc5 100644 --- a/grub-core/kern/efi/mm.c +++ b/grub-core/kern/efi/mm.c @@ -51,36 +51,20 @@ int grub_efi_is_finished = 0; /* Allocate pages. Return the pointer to the first of allocated pages. */ void * -grub_efi_allocate_pages (grub_efi_physical_address_t address, - grub_efi_uintn_t pages) +grub_efi_allocate_pages_real (grub_efi_physical_address_t address, + grub_efi_uintn_t pages, + grub_efi_allocate_type_t alloctype, + grub_efi_memory_type_t memtype) { - grub_efi_allocate_type_t type; grub_efi_status_t status; grub_efi_boot_services_t *b; -#if 1 /* Limit the memory access to less than 4GB for 32-bit platforms. */ if (address > GRUB_EFI_MAX_USABLE_ADDRESS) return 0; -#endif - -#if 1 - if (address == 0) - { - type = GRUB_EFI_ALLOCATE_MAX_ADDRESS; - address = GRUB_EFI_MAX_USABLE_ADDRESS; - } - else - type = GRUB_EFI_ALLOCATE_ADDRESS; -#else - if (address == 0) - type = GRUB_EFI_ALLOCATE_ANY_PAGES; - else - type = GRUB_EFI_ALLOCATE_ADDRESS; -#endif b = grub_efi_system_table->boot_services; - status = efi_call_4 (b->allocate_pages, type, GRUB_EFI_LOADER_DATA, pages, &address); + status = efi_call_4 (b->allocate_pages, alloctype, memtype, pages, &address); if (status != GRUB_EFI_SUCCESS) return 0; @@ -89,7 +73,7 @@ grub_efi_allocate_pages (grub_efi_physical_address_t address, /* Uggh, the address 0 was allocated... This is too annoying, so reallocate another one. */ address = GRUB_EFI_MAX_USABLE_ADDRESS; - status = efi_call_4 (b->allocate_pages, type, GRUB_EFI_LOADER_DATA, pages, &address); + status = efi_call_4 (b->allocate_pages, alloctype, memtype, pages, &address); grub_efi_free_pages (0, pages); if (status != GRUB_EFI_SUCCESS) return 0; @@ -98,6 +82,24 @@ grub_efi_allocate_pages (grub_efi_physical_address_t address, return (void *) ((grub_addr_t) address); } +void * +grub_efi_allocate_pages (grub_efi_physical_address_t address, + grub_efi_uintn_t pages) +{ + grub_efi_allocate_type_t alloctype; + + if (address == 0) + { + alloctype = GRUB_EFI_ALLOCATE_MAX_ADDRESS; + address = GRUB_EFI_MAX_USABLE_ADDRESS; + } + else + alloctype = GRUB_EFI_ALLOCATE_ADDRESS; + + return grub_efi_allocate_pages_real (address, pages, alloctype, + GRUB_EFI_LOADER_DATA); +} + /* Free pages starting from ADDRESS. */ void grub_efi_free_pages (grub_efi_physical_address_t address, diff --git a/include/grub/efi/efi.h b/include/grub/efi/efi.h index 845fc2438..904722174 100644 --- a/include/grub/efi/efi.h +++ b/include/grub/efi/efi.h @@ -38,6 +38,11 @@ void *EXPORT_FUNC(grub_efi_open_protocol) (grub_efi_handle_t handle, int EXPORT_FUNC(grub_efi_set_text_mode) (int on); void EXPORT_FUNC(grub_efi_stall) (grub_efi_uintn_t microseconds); void * +EXPORT_FUNC(grub_efi_allocate_pages_real) (grub_efi_physical_address_t address, + grub_efi_uintn_t pages, + grub_efi_allocate_type_t alloctype, + grub_efi_memory_type_t memtype); +void * EXPORT_FUNC(grub_efi_allocate_pages) (grub_efi_physical_address_t address, grub_efi_uintn_t pages); void EXPORT_FUNC(grub_efi_free_pages) (grub_efi_physical_address_t address, From patchwork Tue Feb 28 22:35:33 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leif Lindholm X-Patchwork-Id: 94670 Delivered-To: patch@linaro.org Received: by 10.140.20.113 with SMTP id 104csp1529538qgi; Tue, 28 Feb 2017 14:41:27 -0800 (PST) X-Received: by 10.200.3.130 with SMTP id t2mr5891089qtg.211.1488321687893; Tue, 28 Feb 2017 14:41:27 -0800 (PST) Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id a128si2625864qkd.243.2017.02.28.14.41.27 for (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 28 Feb 2017 14:41:27 -0800 (PST) Received-SPF: pass (google.com: domain of grub-devel-bounces+patch=linaro.org@gnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org; spf=pass (google.com: domain of grub-devel-bounces+patch=linaro.org@gnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=grub-devel-bounces+patch=linaro.org@gnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:37464 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ciqST-0000lP-9k for patch@linaro.org; Tue, 28 Feb 2017 17:41:25 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36706) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ciqMy-0004rW-Gk for grub-devel@gnu.org; Tue, 28 Feb 2017 17:35:45 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ciqMx-0004YP-11 for grub-devel@gnu.org; Tue, 28 Feb 2017 17:35:44 -0500 Received: from mail-wr0-x234.google.com ([2a00:1450:400c:c0c::234]:34852) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ciqMw-0004Xu-OB for grub-devel@gnu.org; Tue, 28 Feb 2017 17:35:42 -0500 Received: by mail-wr0-x234.google.com with SMTP id g10so18364335wrg.2 for ; Tue, 28 Feb 2017 14:35:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=zYbDCIugu2TG0/MhE1kRglOw/XM5pDU6HGALJzUc4wM=; b=cMv0lv6K4Yob13UHctyuOkJHctWHDqNNKAZW1yN2zFusGRs2MWFcLDEld5ZsrdxvnS 8dsNJ2e2Z0rVImCyQtX5QVq6eqeuGXh4JLFIE0tJJoojZyiGfposj27pCkg9lJkLABcW sL/DT27Bi/jPjuzfT/E2Ws0FhgDQZaPNdxC2s= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=zYbDCIugu2TG0/MhE1kRglOw/XM5pDU6HGALJzUc4wM=; b=ElNi7/1DWjxVC3wvjDVAVK/RXiKo6FSZdeEYpKl9bWgiAydS0tSG78u1JIfVTYVYTn oJ7iLp7DVC8HEg14kk3WFsw1PtGnlC9K1ozpIOG9ga4u5looB7StkH40fA/CtYWwqqfc rL09j3ccnIOJVyQxbAlnwGfBu1UFh2WWQ9KQbf23Jx0C5v/t55AQb2FoMpDiBM/wuRAT /3XnDVYHwBjMM3Qx2l8DAphb559X32EnLGd8Bt/anFo1M1nYRHKpN12nhUehCUWzQULR chhS+Mfzs1KhapJxXSKxi9JU2KlPqsb32/OO43DkQYXdmunKCAhmTUdI36iGwYulfHB4 Kacw== X-Gm-Message-State: AMke39njK2c2xWOKScQbR3YF48vW2yYsLI7NHrGxd02cIC1OrjYtfLsjibqXhJFo6uNOIs0j X-Received: by 10.223.154.225 with SMTP id a88mr4146542wrc.5.1488321341660; Tue, 28 Feb 2017 14:35:41 -0800 (PST) Received: from mohikan.hemma.eciton.net ([2a01:348:6:8735:e23f:49ff:fe6d:9d26]) by smtp.gmail.com with ESMTPSA id 40sm4043391wry.22.2017.02.28.14.35.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 28 Feb 2017 14:35:41 -0800 (PST) From: Leif Lindholm To: grub-devel@gnu.org Subject: [PATCH 3/7] efi: move fdt helper library Date: Tue, 28 Feb 2017 22:35:33 +0000 Message-Id: <20170228223537.9685-4-leif.lindholm@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170228223537.9685-1-leif.lindholm@linaro.org> References: <20170228223537.9685-1-leif.lindholm@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c0c::234 X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: The development of GNU GRUB Cc: Laszlo Ersek , Gerd Hoffmann , Alexander Graf , ard.biesheuvel@linaro.org MIME-Version: 1.0 Errors-To: grub-devel-bounces+patch=linaro.org@gnu.org Sender: "Grub-devel" There is nothing ARM64 (or even ARM) specific about the efi fdt helper library, which is used for locating or overriding a firmware-provided devicetree in a UEFI system - so move it to loader/efi for reuse. Move the fdtload.h include file to grub/efi and move the (at least theoretically) machine dependent page size definitions to grub/machine/memory.h. --- grub-core/Makefile.core.def | 2 +- grub-core/loader/arm64/linux.c | 3 ++- grub-core/loader/arm64/xen_boot.c | 3 ++- grub-core/loader/{arm64 => efi}/fdt.c | 11 ++++++----- include/grub/arm64/efi/memory.h | 3 +++ include/grub/{arm64 => efi}/fdtload.h | 3 --- 6 files changed, 14 insertions(+), 11 deletions(-) rename grub-core/loader/{arm64 => efi}/fdt.c (93%) rename include/grub/{arm64 => efi}/fdtload.h (89%) -- 2.11.0 _______________________________________________ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def index 2dfa22a92..2d8d8618d 100644 --- a/grub-core/Makefile.core.def +++ b/grub-core/Makefile.core.def @@ -1677,7 +1677,7 @@ module = { module = { name = fdt; - arm64 = loader/arm64/fdt.c; + arm64 = loader/efi/fdt.c; common = lib/fdt.c; enable = fdt; }; diff --git a/grub-core/loader/arm64/linux.c b/grub-core/loader/arm64/linux.c index 9519d2e4d..02e405460 100644 --- a/grub-core/loader/arm64/linux.c +++ b/grub-core/loader/arm64/linux.c @@ -26,11 +26,12 @@ #include #include #include -#include #include +#include #include #include #include +#include GRUB_MOD_LICENSE ("GPLv3+"); diff --git a/grub-core/loader/arm64/xen_boot.c b/grub-core/loader/arm64/xen_boot.c index a914eb8e2..341805c50 100644 --- a/grub-core/loader/arm64/xen_boot.c +++ b/grub-core/loader/arm64/xen_boot.c @@ -27,12 +27,13 @@ #include #include #include -#include #include #include +#include #include /* required by struct xen_hypervisor_header */ #include #include +#include GRUB_MOD_LICENSE ("GPLv3+"); diff --git a/grub-core/loader/arm64/fdt.c b/grub-core/loader/efi/fdt.c similarity index 93% rename from grub-core/loader/arm64/fdt.c rename to grub-core/loader/efi/fdt.c index db49cf649..e2899c47b 100644 --- a/grub-core/loader/arm64/fdt.c +++ b/grub-core/loader/efi/fdt.c @@ -18,12 +18,13 @@ #include #include -#include #include #include #include #include #include +#include +#include static void *loaded_fdt; static void *fdt; @@ -32,12 +33,12 @@ void * grub_fdt_load (grub_size_t additional_size) { void *raw_fdt; - grub_size_t size; + unsigned int size; if (fdt) { size = GRUB_EFI_BYTES_TO_PAGES (grub_fdt_get_totalsize (fdt)); - grub_efi_free_pages ((grub_efi_physical_address_t) fdt, size); + grub_efi_free_pages ((grub_addr_t) fdt, size); } if (loaded_fdt) @@ -49,7 +50,7 @@ grub_fdt_load (grub_size_t additional_size) raw_fdt ? grub_fdt_get_totalsize (raw_fdt) : GRUB_FDT_EMPTY_TREE_SZ; size += additional_size; - grub_dprintf ("linux", "allocating %ld bytes for fdt\n", size); + grub_dprintf ("linux", "allocating %d bytes for fdt\n", size); fdt = grub_efi_allocate_pages (0, GRUB_EFI_BYTES_TO_PAGES (size)); if (!fdt) return NULL; @@ -88,7 +89,7 @@ grub_fdt_unload (void) { if (!fdt) { return; } - grub_efi_free_pages ((grub_efi_physical_address_t) fdt, + grub_efi_free_pages ((grub_addr_t) fdt, GRUB_EFI_BYTES_TO_PAGES (grub_fdt_get_totalsize (fdt))); fdt = NULL; } diff --git a/include/grub/arm64/efi/memory.h b/include/grub/arm64/efi/memory.h index c6cb32417..9414b69e0 100644 --- a/include/grub/arm64/efi/memory.h +++ b/include/grub/arm64/efi/memory.h @@ -3,4 +3,7 @@ #define GRUB_EFI_MAX_USABLE_ADDRESS 0xffffffffffffULL +#define GRUB_EFI_PAGE_SHIFT 12 +#define GRUB_EFI_BYTES_TO_PAGES(bytes) (((bytes) + 0xfff) >> GRUB_EFI_PAGE_SHIFT) + #endif /* ! GRUB_MEMORY_CPU_HEADER */ diff --git a/include/grub/arm64/fdtload.h b/include/grub/efi/fdtload.h similarity index 89% rename from include/grub/arm64/fdtload.h rename to include/grub/efi/fdtload.h index 7b9ddba91..713c9424d 100644 --- a/include/grub/arm64/fdtload.h +++ b/include/grub/efi/fdtload.h @@ -29,7 +29,4 @@ grub_fdt_unload (void); grub_err_t grub_fdt_install (void); -#define GRUB_EFI_PAGE_SHIFT 12 -#define GRUB_EFI_BYTES_TO_PAGES(bytes) (((bytes) + 0xfff) >> GRUB_EFI_PAGE_SHIFT) - #endif From patchwork Tue Feb 28 22:35:34 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leif Lindholm X-Patchwork-Id: 94674 Delivered-To: patch@linaro.org Received: by 10.140.20.113 with SMTP id 104csp1531928qgi; Tue, 28 Feb 2017 14:49:34 -0800 (PST) X-Received: by 10.237.57.169 with SMTP id m38mr6480366qte.196.1488322174199; Tue, 28 Feb 2017 14:49:34 -0800 (PST) Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id s14si2673844qki.21.2017.02.28.14.49.33 for (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 28 Feb 2017 14:49:34 -0800 (PST) Received-SPF: pass (google.com: domain of grub-devel-bounces+patch=linaro.org@gnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org; spf=pass (google.com: domain of grub-devel-bounces+patch=linaro.org@gnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=grub-devel-bounces+patch=linaro.org@gnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:37496 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ciqaJ-0005YL-Lg for patch@linaro.org; Tue, 28 Feb 2017 17:49:31 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36719) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ciqMz-0004sm-Po for grub-devel@gnu.org; Tue, 28 Feb 2017 17:35:47 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ciqMy-0004ZE-9U for grub-devel@gnu.org; Tue, 28 Feb 2017 17:35:45 -0500 Received: from mail-wr0-x22e.google.com ([2a00:1450:400c:c0c::22e]:34857) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ciqMy-0004Yh-0I for grub-devel@gnu.org; Tue, 28 Feb 2017 17:35:44 -0500 Received: by mail-wr0-x22e.google.com with SMTP id g10so18364601wrg.2 for ; Tue, 28 Feb 2017 14:35:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=6xVO8GJRW3RczGWwDBySBzDCgwUyRNnrkpftW5gWfpA=; b=CScdKFu7mUfidoIyq/4zqCz2joRQcUL8u2WX3dKtvoID0dErrunNdaUYXRyjb+3Uez f2/UaRoBQysyrg1Za7HHArQAHS5dOv92DcH/numJz0gzl2hG4/5TJrzACgf+JzqIIvdd lvCuELzLvzWbCpl+HeUyDRljQkM7BuHUSqIs4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=6xVO8GJRW3RczGWwDBySBzDCgwUyRNnrkpftW5gWfpA=; b=LJbYjWV728xxDr9EZitqM60Huo5jkQ6f6ewostab/PwKaEP85Bcabv7EVo6rdr6krJ xr7Zs4rU0QSRfBYldolwNlAVze/3NqCI8vgoWdYkpSv0m9u7w8hYosuu83cfXvn2hxzF PDPVDToohK5gI3e7OKjDBRkXwEBySClBokT/sI3jYesalMkx8leZrXXo/5dOldx7Cpe+ YthEAFxku8qHShOqP9I2Rfc7wqmAmXe2XI/Rd85KMAltqpzeBUF+MGnKlNU5CrjHyy53 YG4eG+qexGnliu8VhCz0TALOCjl3mJrSoUADZQ/mn1zmyMmjWazHXD7RUY8TyvrnPOQk imDw== X-Gm-Message-State: AMke39kEZyIa0pCXb/az46TvSMQCkUxhZC4hEBYeKDPt39aMktX5RlrIluYTU+f/oOm7YOci X-Received: by 10.223.177.132 with SMTP id q4mr4156967wra.83.1488321342662; Tue, 28 Feb 2017 14:35:42 -0800 (PST) Received: from mohikan.hemma.eciton.net ([2a01:348:6:8735:e23f:49ff:fe6d:9d26]) by smtp.gmail.com with ESMTPSA id 40sm4043391wry.22.2017.02.28.14.35.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 28 Feb 2017 14:35:42 -0800 (PST) From: Leif Lindholm To: grub-devel@gnu.org Subject: [PATCH 4/7] arm64: make efi linux loader more generic Date: Tue, 28 Feb 2017 22:35:34 +0000 Message-Id: <20170228223537.9685-5-leif.lindholm@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170228223537.9685-1-leif.lindholm@linaro.org> References: <20170228223537.9685-1-leif.lindholm@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c0c::22e X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: The development of GNU GRUB Cc: Laszlo Ersek , Gerd Hoffmann , Alexander Graf , ard.biesheuvel@linaro.org MIME-Version: 1.0 Errors-To: grub-devel-bounces+patch=linaro.org@gnu.org Sender: "Grub-devel" In order to enable reuse of the arm64 efi linux loader for arm, change a few function names and macros. Add a global definition of GRUB_PE32_MAGIC in grub/efi/pe32.h. Make the arm64 loader 32/64-bit safe. Also update the arm64 xen loader, since it depends on some of the functions in the linux loader. Signed-off-by: Leif Lindholm --- grub-core/loader/arm64/linux.c | 31 ++++++++++++++----------------- grub-core/loader/arm64/xen_boot.c | 12 ++++++------ include/grub/arm64/linux.h | 13 ++----------- include/grub/efi/efi.h | 4 ++++ include/grub/efi/pe32.h | 2 ++ 5 files changed, 28 insertions(+), 34 deletions(-) -- 2.11.0 _______________________________________________ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel diff --git a/grub-core/loader/arm64/linux.c b/grub-core/loader/arm64/linux.c index 02e405460..37de3ed05 100644 --- a/grub-core/loader/arm64/linux.c +++ b/grub-core/loader/arm64/linux.c @@ -48,18 +48,16 @@ static grub_addr_t initrd_start; static grub_addr_t initrd_end; grub_err_t -grub_arm64_uefi_check_image (struct grub_arm64_linux_kernel_header * lh) +grub_efi_linux_check_image (struct grub_linux_kernel_header * lh) { - if (lh->magic != GRUB_ARM64_LINUX_MAGIC) + if (lh->magic != GRUB_LINUX_MAGIC_SIGNATURE) return grub_error(GRUB_ERR_BAD_OS, "invalid magic number"); - if ((lh->code0 & 0xffff) != GRUB_EFI_PE_MAGIC) + if ((lh->code0 & 0xffff) != GRUB_PE32_MAGIC) return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, N_("plain image kernel not supported - rebuild with CONFIG_(U)EFI_STUB enabled")); grub_dprintf ("linux", "UEFI stub kernel:\n"); - grub_dprintf ("linux", "text_offset = 0x%012llx\n", - (long long unsigned) lh->text_offset); grub_dprintf ("linux", "PE/COFF header @ %08x\n", lh->hdr_offset); return GRUB_ERR_NONE; @@ -87,8 +85,8 @@ finalize_params_linux (void) /* Set initrd info */ if (initrd_start && initrd_end > initrd_start) { - grub_dprintf ("linux", "Initrd @ 0x%012lx-0x%012lx\n", - initrd_start, initrd_end); + grub_dprintf ("linux", "Initrd @ %p-%p\n", + (void *) initrd_start, (void *) initrd_end); retval = grub_fdt_set_prop64 (fdt, node, "linux,initrd-start", initrd_start); @@ -111,7 +109,7 @@ failure: } grub_err_t -grub_arm64_uefi_boot_image (grub_addr_t addr, grub_size_t size, char *args) +grub_efi_linux_boot_image (grub_addr_t addr, grub_size_t size, char *args) { grub_efi_memory_mapped_device_path_t *mempath; grub_efi_handle_t image_handle; @@ -163,7 +161,7 @@ grub_arm64_uefi_boot_image (grub_addr_t addr, grub_size_t size, char *args) /* When successful, not reached */ b->unload_image (image_handle); - grub_efi_free_pages ((grub_efi_physical_address_t) loaded_image->load_options, + grub_efi_free_pages ((grub_addr_t) loaded_image->load_options, GRUB_EFI_BYTES_TO_PAGES (loaded_image->load_options_size)); return grub_errno; @@ -175,8 +173,8 @@ grub_linux_boot (void) if (finalize_params_linux () != GRUB_ERR_NONE) return grub_errno; - return (grub_arm64_uefi_boot_image((grub_addr_t)kernel_addr, - kernel_size, linux_args)); + return (grub_efi_linux_boot_image((grub_addr_t)kernel_addr, + kernel_size, linux_args)); } static grub_err_t @@ -190,7 +188,7 @@ grub_linux_unload (void) initrd_start = initrd_end = 0; grub_free (linux_args); if (kernel_addr) - grub_efi_free_pages ((grub_efi_physical_address_t) kernel_addr, + grub_efi_free_pages ((grub_addr_t) kernel_addr, GRUB_EFI_BYTES_TO_PAGES (kernel_size)); grub_fdt_unload (); return GRUB_ERR_NONE; @@ -242,8 +240,7 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), fail: grub_initrd_close (&initrd_ctx); if (initrd_mem && !initrd_start) - grub_efi_free_pages ((grub_efi_physical_address_t) initrd_mem, - initrd_pages); + grub_efi_free_pages ((grub_addr_t) initrd_mem, initrd_pages); return grub_errno; } @@ -253,7 +250,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), int argc, char *argv[]) { grub_file_t file = 0; - struct grub_arm64_linux_kernel_header lh; + struct grub_linux_kernel_header lh; grub_dl_ref (my_mod); @@ -272,7 +269,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), if (grub_file_read (file, &lh, sizeof (lh)) < (long) sizeof (lh)) return grub_errno; - if (grub_arm64_uefi_check_image (&lh) != GRUB_ERR_NONE) + if (grub_efi_linux_check_image (&lh) != GRUB_ERR_NONE) goto fail; grub_loader_unset(); @@ -330,7 +327,7 @@ fail: grub_free (linux_args); if (kernel_addr && !loaded) - grub_efi_free_pages ((grub_efi_physical_address_t) kernel_addr, + grub_efi_free_pages ((grub_addr_t) kernel_addr, GRUB_EFI_BYTES_TO_PAGES (kernel_size)); return grub_errno; diff --git a/grub-core/loader/arm64/xen_boot.c b/grub-core/loader/arm64/xen_boot.c index 341805c50..fa574aecd 100644 --- a/grub-core/loader/arm64/xen_boot.c +++ b/grub-core/loader/arm64/xen_boot.c @@ -67,7 +67,7 @@ typedef enum module_type module_type_t; struct xen_hypervisor_header { - struct grub_arm64_linux_kernel_header efi_head; + struct grub_linux_kernel_header efi_head; /* This is always PE\0\0. */ grub_uint8_t signature[GRUB_PE32_SIGNATURE_SIZE]; @@ -254,9 +254,9 @@ xen_boot (void) if (err) return err; - return grub_arm64_uefi_boot_image (xen_hypervisor->start, - xen_hypervisor->size, - xen_hypervisor->cmdline); + return grub_efi_linux_boot_image (xen_hypervisor->start, + xen_hypervisor->size, + xen_hypervisor->cmdline); } static void @@ -442,8 +442,8 @@ grub_cmd_xen_hypervisor (grub_command_t cmd __attribute__ ((unused)), if (grub_file_read (file, &sh, sizeof (sh)) != (long) sizeof (sh)) goto fail; - if (grub_arm64_uefi_check_image - ((struct grub_arm64_linux_kernel_header *) &sh) != GRUB_ERR_NONE) + if (grub_efi_linux_check_image + ((struct grub_linux_kernel_header *) &sh) != GRUB_ERR_NONE) goto fail; grub_file_seek (file, 0); diff --git a/include/grub/arm64/linux.h b/include/grub/arm64/linux.h index 1ea23696e..e53be83b1 100644 --- a/include/grub/arm64/linux.h +++ b/include/grub/arm64/linux.h @@ -19,14 +19,10 @@ #ifndef GRUB_LINUX_CPU_HEADER #define GRUB_LINUX_CPU_HEADER 1 -#include - -#define GRUB_ARM64_LINUX_MAGIC 0x644d5241 /* 'ARM\x64' */ - -#define GRUB_EFI_PE_MAGIC 0x5A4D +#define GRUB_LINUX_MAGIC_SIGNATURE 0x644d5241 /* 'ARM\x64' */ /* From linux/Documentation/arm64/booting.txt */ -struct grub_arm64_linux_kernel_header +struct grub_linux_kernel_header { grub_uint32_t code0; /* Executable code */ grub_uint32_t code1; /* Executable code */ @@ -40,9 +36,4 @@ struct grub_arm64_linux_kernel_header grub_uint32_t hdr_offset; /* Offset of PE/COFF header */ }; -grub_err_t grub_arm64_uefi_check_image (struct grub_arm64_linux_kernel_header - *lh); -grub_err_t grub_arm64_uefi_boot_image (grub_addr_t addr, grub_size_t size, - char *args); - #endif /* ! GRUB_LINUX_CPU_HEADER */ diff --git a/include/grub/efi/efi.h b/include/grub/efi/efi.h index 904722174..395daeae3 100644 --- a/include/grub/efi/efi.h +++ b/include/grub/efi/efi.h @@ -89,6 +89,10 @@ extern void (*EXPORT_VAR(grub_efi_net_config)) (grub_efi_handle_t hnd, #if defined(__arm__) || defined(__aarch64__) void *EXPORT_FUNC(grub_efi_get_firmware_fdt)(void); grub_err_t EXPORT_FUNC(grub_efi_get_dram_base)(grub_addr_t *); +#include +grub_err_t grub_efi_linux_check_image(struct grub_linux_kernel_header *lh); +grub_err_t grub_efi_linux_boot_image(grub_addr_t addr, grub_size_t size, + char *args); #endif grub_addr_t grub_efi_modules_addr (void); diff --git a/include/grub/efi/pe32.h b/include/grub/efi/pe32.h index f79c36c02..7d44732d2 100644 --- a/include/grub/efi/pe32.h +++ b/include/grub/efi/pe32.h @@ -45,6 +45,8 @@ #define GRUB_PE32_MSDOS_STUB_SIZE 0x80 +#define GRUB_PE32_MAGIC 0x5a4d + /* According to the spec, the minimal alignment is 512 bytes... But some examples (such as EFI drivers in the Intel Sample Implementation) use 32 bytes (0x20) instead, and it seems From patchwork Tue Feb 28 22:35:35 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leif Lindholm X-Patchwork-Id: 94671 Delivered-To: patch@linaro.org Received: by 10.140.20.113 with SMTP id 104csp1529690qgi; Tue, 28 Feb 2017 14:41:57 -0800 (PST) X-Received: by 10.55.11.10 with SMTP id 10mr5871802qkl.100.1488321717857; Tue, 28 Feb 2017 14:41:57 -0800 (PST) Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id 40si2639702qkx.163.2017.02.28.14.41.57 for (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 28 Feb 2017 14:41:57 -0800 (PST) Received-SPF: pass (google.com: domain of grub-devel-bounces+patch=linaro.org@gnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org; spf=pass (google.com: domain of grub-devel-bounces+patch=linaro.org@gnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=grub-devel-bounces+patch=linaro.org@gnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:37466 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ciqSx-0001Ec-2I for patch@linaro.org; Tue, 28 Feb 2017 17:41:55 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36743) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ciqN1-0004uP-8B for grub-devel@gnu.org; Tue, 28 Feb 2017 17:35:49 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ciqMz-0004Zc-0Y for grub-devel@gnu.org; Tue, 28 Feb 2017 17:35:47 -0500 Received: from mail-wr0-x22d.google.com ([2a00:1450:400c:c0c::22d]:34860) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ciqMy-0004Z6-Mm for grub-devel@gnu.org; Tue, 28 Feb 2017 17:35:44 -0500 Received: by mail-wr0-x22d.google.com with SMTP id g10so18364775wrg.2 for ; Tue, 28 Feb 2017 14:35:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=+nZXfT3OnfVLtZBGJt7afE4Ia07dBLqdTODyy3HymQE=; b=DLUEnvJ75BF/IBhWMSib8+AKRXD0Sm89FESX0r2JTw0dPVByomNu1tI6XX22xK10eT 5XJsPeVdXuw4BRrWvPZhEiPmGXNSUg9QyP81uEiTrUxvQPmAk4CJf93eA8dLm6NrEyei yf8SFV03HQeW4RFvV/66QuYoZwTUwAu/rpyFI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=+nZXfT3OnfVLtZBGJt7afE4Ia07dBLqdTODyy3HymQE=; b=SOYrWhe/ABEAi/ARLIPCo0eHLdhu8fUphsT+/B1gt5vw9pL7rkV0VkNbwcy+sxDGB7 lYTHUG/JJlarO6RX/fBjVS8nO+V+vqx8GhgEidMXG5rxaCERAZM8fd+sMdGKe70mZ8ya IGFBcy+CU9H5KVlx5d/scsQXdtoDf8P6g22QzKNjn0Pnafrr3lFFrrarHyt6v20vz1PC Ys5ei4UCfFWPXb6loAf4syQHeaAwxq7x5XxAzYYoKMmLGyruBnCb+txRHp7e7UhRKs/K S45jyW+RGtHSyDaLhw01ko0iOo3Au375yIWv7uU/EXk/3j+5i0bLg3YFhrTk5LFzhXBU MDPg== X-Gm-Message-State: AMke39m+UlTCMGkrEVNy3F5j2CnpZ4Ysi5qnTN5tFikz93UZmeJhNQP5SZjrjIe5xDW0LFQr X-Received: by 10.223.153.17 with SMTP id x17mr4185830wrb.55.1488321343574; Tue, 28 Feb 2017 14:35:43 -0800 (PST) Received: from mohikan.hemma.eciton.net ([2a01:348:6:8735:e23f:49ff:fe6d:9d26]) by smtp.gmail.com with ESMTPSA id 40sm4043391wry.22.2017.02.28.14.35.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 28 Feb 2017 14:35:43 -0800 (PST) From: Leif Lindholm To: grub-devel@gnu.org Subject: [PATCH 5/7] arm: reuse arm64 linux loader on efi systems Date: Tue, 28 Feb 2017 22:35:35 +0000 Message-Id: <20170228223537.9685-6-leif.lindholm@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170228223537.9685-1-leif.lindholm@linaro.org> References: <20170228223537.9685-1-leif.lindholm@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c0c::22d X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: The development of GNU GRUB Cc: Laszlo Ersek , Gerd Hoffmann , Alexander Graf , ard.biesheuvel@linaro.org MIME-Version: 1.0 Errors-To: grub-devel-bounces+patch=linaro.org@gnu.org Sender: "Grub-devel" The original 32-bit arm EFI Linux loader reused the 32-bit Linux loader for U-Boot. However, this meant it was acting in an entirely not UEFI-compliant fashion. Since EFI stub loader support for arm went into upstream Linux for 4.5, we can now reuse the same loader as is used on arm64. This results in some now-redundant code being dropped from the U-Boot linux loader, and the arm efi port in general. This also drops the ability to boot kernels without the efi stub support on 32-bit arm efi grub. Signed-off-by: Leif Lindholm --- grub-core/Makefile.am | 1 - grub-core/Makefile.core.def | 6 +- grub-core/kern/arm/efi/misc.c | 202 ------------------------------------------ grub-core/loader/arm/linux.c | 48 ++-------- include/grub/arm/efi/loader.h | 26 ------ include/grub/arm/efi/memory.h | 3 + include/grub/arm/linux.h | 30 +++---- 7 files changed, 22 insertions(+), 294 deletions(-) delete mode 100644 grub-core/kern/arm/efi/misc.c delete mode 100644 include/grub/arm/efi/loader.h -- 2.11.0 _______________________________________________ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel diff --git a/grub-core/Makefile.am b/grub-core/Makefile.am index 04e9395fd..44bb981c2 100644 --- a/grub-core/Makefile.am +++ b/grub-core/Makefile.am @@ -240,7 +240,6 @@ KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/arm/system.h endif if COND_arm_efi -KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/arm/efi/loader.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/efi/efi.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/efi/disk.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/arm/system.h diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def index 2d8d8618d..a929f15a6 100644 --- a/grub-core/Makefile.core.def +++ b/grub-core/Makefile.core.def @@ -211,7 +211,6 @@ kernel = { ia64_efi = kern/ia64/cache.c; arm_efi = kern/arm/efi/init.c; - arm_efi = kern/arm/efi/misc.c; arm_efi = kern/efi/fdt.c; arm64_efi = kern/arm64/efi/init.c; @@ -1668,7 +1667,8 @@ module = { powerpc_ieee1275 = loader/powerpc/ieee1275/linux.c; sparc64_ieee1275 = loader/sparc64/ieee1275/linux.c; ia64_efi = loader/ia64/efi/linux.c; - arm = loader/arm/linux.c; + arm_uboot = loader/arm/linux.c; + arm_efi = loader/arm64/linux.c; arm64 = loader/arm64/linux.c; common = loader/linux.c; common = lib/cmdline.c; @@ -1677,7 +1677,7 @@ module = { module = { name = fdt; - arm64 = loader/efi/fdt.c; + efi = loader/efi/fdt.c; common = lib/fdt.c; enable = fdt; }; diff --git a/grub-core/kern/arm/efi/misc.c b/grub-core/kern/arm/efi/misc.c deleted file mode 100644 index 7cd41842a..000000000 --- a/grub-core/kern/arm/efi/misc.c +++ /dev/null @@ -1,202 +0,0 @@ -/* misc.c - various system functions for an arm-based EFI system */ -/* - * GRUB -- GRand Unified Bootloader - * Copyright (C) 2013 Free Software Foundation, Inc. - * - * GRUB is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * GRUB is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GRUB. If not, see . - */ - -#include -#include -#include -#include -#include -#include - -static inline grub_size_t -page_align (grub_size_t size) -{ - return (size + (1 << 12) - 1) & (~((1 << 12) - 1)); -} - -/* Find the optimal number of pages for the memory map. Is it better to - move this code to efi/mm.c? */ -static grub_efi_uintn_t -find_mmap_size (void) -{ - static grub_efi_uintn_t mmap_size = 0; - - if (mmap_size != 0) - return mmap_size; - - mmap_size = (1 << 12); - while (1) - { - int ret; - grub_efi_memory_descriptor_t *mmap; - grub_efi_uintn_t desc_size; - - mmap = grub_malloc (mmap_size); - if (! mmap) - return 0; - - ret = grub_efi_get_memory_map (&mmap_size, mmap, 0, &desc_size, 0); - grub_free (mmap); - - if (ret < 0) - { - grub_error (GRUB_ERR_IO, "cannot get memory map"); - return 0; - } - else if (ret > 0) - break; - - mmap_size += (1 << 12); - } - - /* Increase the size a bit for safety, because GRUB allocates more on - later, and EFI itself may allocate more. */ - mmap_size += (1 << 12); - - return page_align (mmap_size); -} - -#define NEXT_MEMORY_DESCRIPTOR(desc, size) \ - ((grub_efi_memory_descriptor_t *) ((char *) (desc) + (size))) -#define PAGE_SHIFT 12 - -void * -grub_efi_allocate_loader_memory (grub_uint32_t min_offset, grub_uint32_t size) -{ - grub_efi_uintn_t desc_size; - grub_efi_memory_descriptor_t *mmap, *mmap_end; - grub_efi_uintn_t mmap_size, tmp_mmap_size; - grub_efi_memory_descriptor_t *desc; - void *mem = NULL; - grub_addr_t min_start = 0; - - mmap_size = find_mmap_size(); - if (!mmap_size) - return NULL; - - mmap = grub_malloc(mmap_size); - if (!mmap) - return NULL; - - tmp_mmap_size = mmap_size; - if (grub_efi_get_memory_map (&tmp_mmap_size, mmap, 0, &desc_size, 0) <= 0) - { - grub_error (GRUB_ERR_IO, "cannot get memory map"); - goto fail; - } - - mmap_end = NEXT_MEMORY_DESCRIPTOR (mmap, tmp_mmap_size); - /* Find lowest accessible RAM location */ - { - int found = 0; - for (desc = mmap ; !found && (desc < mmap_end) ; - desc = NEXT_MEMORY_DESCRIPTOR(desc, desc_size)) - { - switch (desc->type) - { - case GRUB_EFI_CONVENTIONAL_MEMORY: - case GRUB_EFI_LOADER_CODE: - case GRUB_EFI_LOADER_DATA: - min_start = desc->physical_start + min_offset; - found = 1; - break; - default: - break; - } - } - } - - /* First, find free pages for the real mode code - and the memory map buffer. */ - for (desc = mmap ; desc < mmap_end ; - desc = NEXT_MEMORY_DESCRIPTOR(desc, desc_size)) - { - grub_uint64_t start, end; - - grub_dprintf("mm", "%s: 0x%08x bytes @ 0x%08x\n", - __FUNCTION__, - (grub_uint32_t) (desc->num_pages << PAGE_SHIFT), - (grub_uint32_t) (desc->physical_start)); - - if (desc->type != GRUB_EFI_CONVENTIONAL_MEMORY) - continue; - - start = desc->physical_start; - end = start + (desc->num_pages << PAGE_SHIFT); - grub_dprintf("mm", "%s: start=0x%016llx, end=0x%016llx\n", - __FUNCTION__, start, end); - start = start < min_start ? min_start : start; - if (start + size > end) - continue; - grub_dprintf("mm", "%s: let's allocate some (0x%x) pages @ 0x%08x...\n", - __FUNCTION__, (size >> PAGE_SHIFT), (grub_addr_t) start); - mem = grub_efi_allocate_pages (start, (size >> PAGE_SHIFT) + 1); - grub_dprintf("mm", "%s: retval=0x%08x\n", - __FUNCTION__, (grub_addr_t) mem); - if (! mem) - { - grub_error (GRUB_ERR_OUT_OF_MEMORY, "cannot allocate memory"); - goto fail; - } - break; - } - - if (! mem) - { - grub_error (GRUB_ERR_OUT_OF_MEMORY, "cannot allocate memory"); - goto fail; - } - - grub_free (mmap); - return mem; - - fail: - grub_free (mmap); - return NULL; -} - -grub_err_t -grub_efi_prepare_platform (void) -{ - grub_efi_uintn_t mmap_size; - grub_efi_uintn_t map_key; - grub_efi_uintn_t desc_size; - grub_efi_uint32_t desc_version; - grub_efi_memory_descriptor_t *mmap_buf; - grub_err_t err; - - /* - * Cloned from IA64 - * Must be done after grub_machine_fini because map_key is used by - *exit_boot_services. - */ - mmap_size = find_mmap_size (); - if (! mmap_size) - return GRUB_ERR_OUT_OF_MEMORY; - mmap_buf = grub_efi_allocate_pages (0, page_align (mmap_size) >> 12); - if (! mmap_buf) - return GRUB_ERR_OUT_OF_MEMORY; - - err = grub_efi_finish_boot_services (&mmap_size, mmap_buf, &map_key, - &desc_size, &desc_version); - if (err != GRUB_ERR_NONE) - return err; - - return GRUB_ERR_NONE; -} diff --git a/grub-core/loader/arm/linux.c b/grub-core/loader/arm/linux.c index 5b39f02bb..83c0e0d0f 100644 --- a/grub-core/loader/arm/linux.c +++ b/grub-core/loader/arm/linux.c @@ -46,9 +46,6 @@ static void *fdt_addr; typedef void (*kernel_entry_t) (int, unsigned long, void *); -#define LINUX_ZIMAGE_OFFSET 0x24 -#define LINUX_ZIMAGE_MAGIC 0x016f2818 - #define LINUX_PHYS_OFFSET (0x00008000) #define LINUX_INITRD_PHYS_OFFSET (LINUX_PHYS_OFFSET + 0x02000000) #define LINUX_FDT_PHYS_OFFSET (LINUX_INITRD_PHYS_OFFSET - 0x10000) @@ -274,15 +271,6 @@ linux_boot (void) */ linuxmain = (kernel_entry_t) linux_addr; -#ifdef GRUB_MACHINE_EFI - { - grub_err_t err; - err = grub_efi_prepare_platform(); - if (err != GRUB_ERR_NONE) - return err; - } -#endif - grub_arm_disable_caches_mmu (); linuxmain (0, machine_type, fdt_addr); @@ -296,17 +284,12 @@ linux_boot (void) static grub_err_t linux_load (const char *filename, grub_file_t file) { + struct grub_linux_kernel_header *lh; int size; size = grub_file_size (file); -#ifdef GRUB_MACHINE_EFI - linux_addr = (grub_addr_t) grub_efi_allocate_loader_memory (LINUX_PHYS_OFFSET, size); - if (!linux_addr) - return grub_errno; -#else linux_addr = LINUX_ADDRESS; -#endif grub_dprintf ("loader", "Loading Linux to 0x%08x\n", (grub_addr_t) linux_addr); @@ -318,9 +301,10 @@ linux_load (const char *filename, grub_file_t file) return grub_errno; } - if (size > LINUX_ZIMAGE_OFFSET + 4 - && *(grub_uint32_t *) (linux_addr + LINUX_ZIMAGE_OFFSET) - == LINUX_ZIMAGE_MAGIC) + lh = (void *) linux_addr; + + if ((grub_size_t) size > sizeof (*lh) && + lh->magic == GRUB_LINUX_MAGIC_SIGNATURE) ; else if (size > 0x8000 && *(grub_uint32_t *) (linux_addr) == 0xea000006 && machine_type == GRUB_ARM_MACHINE_TYPE_RASPBERRY_PI) @@ -410,20 +394,7 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), size = grub_get_initrd_size (&initrd_ctx); -#ifdef GRUB_MACHINE_EFI - if (initrd_start) - grub_efi_free_pages (initrd_start, - (initrd_end - initrd_start + 0xfff) >> 12); - initrd_start = (grub_addr_t) grub_efi_allocate_loader_memory (LINUX_INITRD_PHYS_OFFSET, size); - - if (!initrd_start) - { - grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("out of memory")); - goto fail; - } -#else initrd_start = LINUX_INITRD_ADDRESS; -#endif grub_dprintf ("loader", "Loading initrd to 0x%08x\n", (grub_addr_t) initrd_start); @@ -473,16 +444,7 @@ grub_cmd_devicetree (grub_command_t cmd __attribute__ ((unused)), goto out; } -#ifdef GRUB_MACHINE_EFI - fdt_addr = grub_efi_allocate_loader_memory (LINUX_FDT_PHYS_OFFSET, size); - if (!fdt_addr) - { - grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("out of memory")); - goto out; - } -#else fdt_addr = (void *) LINUX_FDT_ADDRESS; -#endif grub_dprintf ("loader", "Loading device tree to 0x%08x\n", (grub_addr_t) fdt_addr); diff --git a/include/grub/arm/efi/loader.h b/include/grub/arm/efi/loader.h deleted file mode 100644 index 4bab18e83..000000000 --- a/include/grub/arm/efi/loader.h +++ /dev/null @@ -1,26 +0,0 @@ -/* - * GRUB -- GRand Unified Bootloader - * Copyright (C) 2013 Free Software Foundation, Inc. - * - * GRUB is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * GRUB is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GRUB. If not, see . - */ - -#ifndef GRUB_LOADER_MACHINE_HEADER -#define GRUB_LOADER_MACHINE_HEADER 1 - -grub_err_t EXPORT_FUNC (grub_efi_prepare_platform) (void); -void * EXPORT_FUNC (grub_efi_allocate_loader_memory) (grub_uint32_t min_offset, - grub_uint32_t size); - -#endif /* ! GRUB_LOADER_MACHINE_HEADER */ diff --git a/include/grub/arm/efi/memory.h b/include/grub/arm/efi/memory.h index 2c64918e3..986f656d6 100644 --- a/include/grub/arm/efi/memory.h +++ b/include/grub/arm/efi/memory.h @@ -3,4 +3,7 @@ #define GRUB_EFI_MAX_USABLE_ADDRESS 0xffffffff +#define GRUB_EFI_PAGE_SHIFT 12 +#define GRUB_EFI_BYTES_TO_PAGES(bytes) (((bytes) + 0xfff) >> GRUB_EFI_PAGE_SHIFT) + #endif /* ! GRUB_MEMORY_CPU_HEADER */ diff --git a/include/grub/arm/linux.h b/include/grub/arm/linux.h index a66caad13..7267f4358 100644 --- a/include/grub/arm/linux.h +++ b/include/grub/arm/linux.h @@ -20,34 +20,26 @@ #ifndef GRUB_LINUX_CPU_HEADER #define GRUB_LINUX_CPU_HEADER 1 -#define LINUX_ZIMAGE_OFFSET 0x24 -#define LINUX_ZIMAGE_MAGIC 0x016f2818 +#define GRUB_LINUX_MAGIC_SIGNATURE 0x016f2818 -#include "system.h" +struct grub_linux_kernel_header { + grub_uint32_t code0; + grub_uint32_t reserved1[8]; + grub_uint32_t magic; + grub_uint32_t start; /* _start */ + grub_uint32_t end; /* _edata */ + grub_uint32_t reserved2[4]; + grub_uint32_t hdr_offset; +}; #if defined GRUB_MACHINE_UBOOT +# include "system.h" # include # define LINUX_ADDRESS (start_of_ram + 0x8000) # define LINUX_INITRD_ADDRESS (start_of_ram + 0x02000000) # define LINUX_FDT_ADDRESS (LINUX_INITRD_ADDRESS - 0x10000) # define grub_arm_firmware_get_boot_data grub_uboot_get_boot_data # define grub_arm_firmware_get_machine_type grub_uboot_get_machine_type -#elif defined GRUB_MACHINE_EFI -# include -# include -/* On UEFI platforms - load the images at the lowest available address not - less than *_PHYS_OFFSET from the first available memory location. */ -# define LINUX_PHYS_OFFSET (0x00008000) -# define LINUX_INITRD_PHYS_OFFSET (LINUX_PHYS_OFFSET + 0x02000000) -# define LINUX_FDT_PHYS_OFFSET (LINUX_INITRD_PHYS_OFFSET - 0x10000) -# define grub_arm_firmware_get_boot_data (grub_addr_t)grub_efi_get_firmware_fdt -static inline grub_uint32_t -grub_arm_firmware_get_machine_type (void) -{ - return GRUB_ARM_MACHINE_TYPE_FDT; -} #endif -#define FDT_ADDITIONAL_ENTRIES_SIZE 0x300 - #endif /* ! GRUB_LINUX_CPU_HEADER */ From patchwork Tue Feb 28 22:35:36 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leif Lindholm X-Patchwork-Id: 94668 Delivered-To: patch@linaro.org Received: by 10.140.20.113 with SMTP id 104csp1528911qgi; Tue, 28 Feb 2017 14:39:25 -0800 (PST) X-Received: by 10.55.66.68 with SMTP id p65mr5428090qka.187.1488321565818; Tue, 28 Feb 2017 14:39:25 -0800 (PST) Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id c50si2631167qtc.208.2017.02.28.14.39.25 for (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 28 Feb 2017 14:39:25 -0800 (PST) Received-SPF: pass (google.com: domain of grub-devel-bounces+patch=linaro.org@gnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org; spf=pass (google.com: domain of grub-devel-bounces+patch=linaro.org@gnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=grub-devel-bounces+patch=linaro.org@gnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:37455 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ciqQV-0008Bx-Bb for patch@linaro.org; Tue, 28 Feb 2017 17:39:23 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36731) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ciqN0-0004ts-LG for grub-devel@gnu.org; Tue, 28 Feb 2017 17:35:47 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ciqMz-0004aW-Oh for grub-devel@gnu.org; Tue, 28 Feb 2017 17:35:46 -0500 Received: from mail-wm0-x22f.google.com ([2a00:1450:400c:c09::22f]:37236) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ciqMz-0004ZZ-Io for grub-devel@gnu.org; Tue, 28 Feb 2017 17:35:45 -0500 Received: by mail-wm0-x22f.google.com with SMTP id v77so22995343wmv.0 for ; Tue, 28 Feb 2017 14:35:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=O6HHy6/htsEbLN7rpdmqy7+INOJzMX+ImQ8jn5i4/JM=; b=Mm5ZqCvpIXRRcmAHGLbzEb8v/sfhf732h9Hg5m10wNMM4y0keWYKuMz2VUjvaJzafR 7/sqCcYhmp1LHrWzSPGpp17j0yGYfal21yuAzvKfJ5Tw6lDrc1ykG5NTK8AKaLx0H0dN 3iK2fW2RII+XbS0fiCrcLDQJxzvpF4MAABc78= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=O6HHy6/htsEbLN7rpdmqy7+INOJzMX+ImQ8jn5i4/JM=; b=Z1wdhyW82bF6Bvy+huWlHqSmG/gXdFBblnKnOYkAziGdGL3fTpcHlWmFQwSWQL1fMr 6BS1DbwOhGkFB5Jq44CriEzAf9gOJB7iXUIGv073zrBSVfO9HkIrPpV/NbZB5oDLdOv0 W4iB9mewpfdR3KE9REe49rlufXHxVnQjLZLMRTDSU2mpcwrTby8ygeg7rRIcKVIOC0RM ItQEsjHwhqhKJz2i42NTI7mbZZNsZY8TLQRoPWNG2OQ17cXspF9OKBfjYxuw1taq21db ooP+1TU+wO3s90j5dx+FYDWBdVGZagLAGSAQH3Ks4L6rcY7zqAQtUHfO3e9KRWq7Dzfc uXRg== X-Gm-Message-State: AMke39kzphlWL4plXHQg+Ws9uh/TqLoTxmn6GQPk9RUI5dbBs5FraTSfHRDX4vx2kSz0S9O7 X-Received: by 10.28.71.21 with SMTP id u21mr640397wma.1.1488321344510; Tue, 28 Feb 2017 14:35:44 -0800 (PST) Received: from mohikan.hemma.eciton.net ([2a01:348:6:8735:e23f:49ff:fe6d:9d26]) by smtp.gmail.com with ESMTPSA id 40sm4043391wry.22.2017.02.28.14.35.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 28 Feb 2017 14:35:43 -0800 (PST) From: Leif Lindholm To: grub-devel@gnu.org Subject: [PATCH 6/7] efi: restrict arm/arm64 linux loader initrd placement Date: Tue, 28 Feb 2017 22:35:36 +0000 Message-Id: <20170228223537.9685-7-leif.lindholm@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170228223537.9685-1-leif.lindholm@linaro.org> References: <20170228223537.9685-1-leif.lindholm@linaro.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:400c:c09::22f X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: The development of GNU GRUB Cc: Laszlo Ersek , Gerd Hoffmann , Alexander Graf , ard.biesheuvel@linaro.org MIME-Version: 1.0 Errors-To: grub-devel-bounces+patch=linaro.org@gnu.org Sender: "Grub-devel" The 32-bit arm Linux kernel is built as a zImage, which self-decompresses down to near start of RAM. In order for an initrd/initramfs to be accessible, it needs to be placed within the first ~768MB of RAM. The initrd loader built into the kernel EFI stub restricts this down to 512MB for simplicity - so enable the same restriction in grub. For arm64, the requirement is within a 1GB aligned 32GB window also covering the (runtime) kernel image. Since the EFI stub loader itself will attempt to relocate to near start of RAM, force initrd to be loaded completely within the first 32GB of RAM. Signed-off-by: Leif Lindholm --- grub-core/loader/arm64/linux.c | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) -- 2.11.0 _______________________________________________ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel diff --git a/grub-core/loader/arm64/linux.c b/grub-core/loader/arm64/linux.c index 37de3ed05..c67c1316c 100644 --- a/grub-core/loader/arm64/linux.c +++ b/grub-core/loader/arm64/linux.c @@ -35,6 +35,23 @@ GRUB_MOD_LICENSE ("GPLv3+"); +/* + * As per linux/Documentation/arm/Booting + * ARM initrd needs to be covered by kernel linear mapping, + * so place it in the first 512MB of DRAM. + * + * As per linux/Documentation/arm64/booting.txt + * ARM64 initrd needs to be contained entirely within a 1GB aligned window + * of up to 32GB of size that covers the kernel image as well. + * Since the EFI stub loader will attempt to load the kernel near start of + * RAM, place the buffer in the first 32GB of RAM. + */ +#ifdef __arm__ +#define INITRD_MAX_ADDRESS_OFFSET (512U * 1024 * 1024) +#else /* __aarch64__ */ +#define INITRD_MAX_ADDRESS_OFFSET (32ULL * 1024 * 1024 * 1024) +#endif + static grub_dl_t my_mod; static int loaded; @@ -194,6 +211,25 @@ grub_linux_unload (void) return GRUB_ERR_NONE; } +/* + * This function returns a pointer to a legally allocated initrd buffer, + * or NULL if unsuccessful + */ +static void * +allocate_initrd_mem (int initrd_pages) +{ + grub_addr_t max_addr; + + if (grub_efi_get_dram_base (&max_addr) != GRUB_ERR_NONE) + return NULL; + + max_addr += INITRD_MAX_ADDRESS_OFFSET - 1; + + return grub_efi_allocate_pages_real (max_addr, initrd_pages, + GRUB_EFI_ALLOCATE_MAX_ADDRESS, + GRUB_EFI_LOADER_DATA); +} + static grub_err_t grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), int argc, char *argv[]) @@ -222,7 +258,8 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), grub_dprintf ("linux", "Loading initrd\n"); initrd_pages = (GRUB_EFI_BYTES_TO_PAGES (initrd_size)); - initrd_mem = grub_efi_allocate_pages (0, initrd_pages); + initrd_mem = allocate_initrd_mem (initrd_pages); + if (!initrd_mem) { grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("out of memory")); From patchwork Tue Feb 28 22:35:37 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leif Lindholm X-Patchwork-Id: 94669 Delivered-To: patch@linaro.org Received: by 10.140.20.113 with SMTP id 104csp1529424qgi; Tue, 28 Feb 2017 14:41:09 -0800 (PST) X-Received: by 10.237.36.116 with SMTP id s49mr6024571qtc.128.1488321669440; Tue, 28 Feb 2017 14:41:09 -0800 (PST) Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id t128si2622119qkb.291.2017.02.28.14.41.09 for (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 28 Feb 2017 14:41:09 -0800 (PST) Received-SPF: pass (google.com: domain of grub-devel-bounces+patch=linaro.org@gnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org; spf=pass (google.com: domain of grub-devel-bounces+patch=linaro.org@gnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=grub-devel-bounces+patch=linaro.org@gnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:37463 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ciqSB-0000YC-0A for patch@linaro.org; Tue, 28 Feb 2017 17:41:07 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36749) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ciqN1-0004ui-ED for grub-devel@gnu.org; Tue, 28 Feb 2017 17:35:48 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ciqN0-0004b0-Lt for grub-devel@gnu.org; Tue, 28 Feb 2017 17:35:47 -0500 Received: from mail-wm0-x22f.google.com ([2a00:1450:400c:c09::22f]:36081) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ciqN0-0004af-F9 for grub-devel@gnu.org; Tue, 28 Feb 2017 17:35:46 -0500 Received: by mail-wm0-x22f.google.com with SMTP id v77so96291366wmv.1 for ; Tue, 28 Feb 2017 14:35:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=k40hvaiiAPb9KtxKtSUVxyRM1mHccocC4rK6H4oUbnw=; b=Kz6Guc/nWDJoDdrW3RBMdonVTUezBVaiuvWSF8aYuZBZaYjvGrOGCyCuGNF/Z0O4CR Fd7zOka3MPBR+Kuldsg4/qjxahK2gtuYoTgyj5SgkbY+2YvXYTYfXpuOOrm0IbZSpIJm zKa6gEpFyDrlHXXXC91xyrWm898/9KEvpSbnA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=k40hvaiiAPb9KtxKtSUVxyRM1mHccocC4rK6H4oUbnw=; b=amDXYOlzeUJG6qokunKQTPlCdqODSeXJpVtBMz7VOrk5QAvDgQlTeD+ItMOGlEOL90 XMm4YUw5uStd5ZMNtpjATj/nJ7a09/pZ3k6aeu6CtDur+fXV9rYh+N17AH5lrcJp3W4e C0UnW5KWsaQESBDps49WDa+r1FGDVjTnLkaICYVp0torJmoG7UCkd3iWgUzr2tu+n7M/ yCjaU9CvNItxBc1vEPs0AYhltgbHIorFb7sxnpVx8252kN2E7VOOfckMbWa4POAzB8Qu 6FbPP98VREN1o+y210yvTwkMX/4ZKxjx6yj5BcK+9C6HOdiiEl/3BvXxWV9jVDlCRacC Vvug== X-Gm-Message-State: AMke39k5MVwfPVhl8DOEscMx3qGfTDgaL5SDF23VQeVr/bDJBFWj1tJ8M73HUl956guIGlJM X-Received: by 10.28.215.138 with SMTP id o132mr627316wmg.41.1488321345520; Tue, 28 Feb 2017 14:35:45 -0800 (PST) Received: from mohikan.hemma.eciton.net ([2a01:348:6:8735:e23f:49ff:fe6d:9d26]) by smtp.gmail.com with ESMTPSA id 40sm4043391wry.22.2017.02.28.14.35.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 28 Feb 2017 14:35:44 -0800 (PST) From: Leif Lindholm To: grub-devel@gnu.org Subject: [PATCH 7/7] efi: change heap allocation type to GRUB_EFI_LOADER_CODE Date: Tue, 28 Feb 2017 22:35:37 +0000 Message-Id: <20170228223537.9685-8-leif.lindholm@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170228223537.9685-1-leif.lindholm@linaro.org> References: <20170228223537.9685-1-leif.lindholm@linaro.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:400c:c09::22f X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: The development of GNU GRUB Cc: Laszlo Ersek , Gerd Hoffmann , Alexander Graf , ard.biesheuvel@linaro.org MIME-Version: 1.0 Errors-To: grub-devel-bounces+patch=linaro.org@gnu.org Sender: "Grub-devel" With upcoming changes to EDK2, allocations of type EFI_LOADER_DATA may not return regions with execute ability. Since modules are loaded onto the heap, change the heap allocation type to GRUB_EFI_LOADER_CODE in order to permit execution on systems with this feature enabled. Closes: 50420 Signed-off-by: Leif Lindholm --- grub-core/kern/efi/mm.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) -- 2.11.0 _______________________________________________ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel diff --git a/grub-core/kern/efi/mm.c b/grub-core/kern/efi/mm.c index 7b1763bc5..f27a48e68 100644 --- a/grub-core/kern/efi/mm.c +++ b/grub-core/kern/efi/mm.c @@ -404,7 +404,9 @@ add_memory_regions (grub_efi_memory_descriptor_t *memory_map, pages = required_pages; } - addr = grub_efi_allocate_pages (start, pages); + addr = grub_efi_allocate_pages_real (start, pages, + GRUB_EFI_ALLOCATE_ADDRESS, + GRUB_EFI_LOADER_CODE); if (! addr) grub_fatal ("cannot allocate conventional memory %p with %u pages", (void *) ((grub_addr_t) start),