From patchwork Mon Aug 22 20:57:40 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leif Lindholm X-Patchwork-Id: 74463 Delivered-To: patch@linaro.org Received: by 10.140.29.52 with SMTP id a49csp1761379qga; Mon, 22 Aug 2016 13:58:50 -0700 (PDT) X-Received: by 10.237.41.225 with SMTP id o88mr26375395qtd.18.1471899530212; Mon, 22 Aug 2016 13:58:50 -0700 (PDT) Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id v127si15150050qkb.250.2016.08.22.13.58.50 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 22 Aug 2016 13:58:50 -0700 (PDT) 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 dis=NONE) header.from=linaro.org Received: from localhost ([::1]:43158 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bbwIz-0000YH-LM for patch@linaro.org; Mon, 22 Aug 2016 16:58:49 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56780) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bbwI3-0000WE-8Q for grub-devel@gnu.org; Mon, 22 Aug 2016 16:57:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bbwHx-00085V-SE for grub-devel@gnu.org; Mon, 22 Aug 2016 16:57:51 -0400 Received: from mail-wm0-x22b.google.com ([2a00:1450:400c:c09::22b]:35051) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bbwHx-00085C-IV for grub-devel@gnu.org; Mon, 22 Aug 2016 16:57:45 -0400 Received: by mail-wm0-x22b.google.com with SMTP id f65so136985019wmi.0 for ; Mon, 22 Aug 2016 13:57:45 -0700 (PDT) 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=gwNtivfsVGD+AizNvKbjD5OQNaEu/3Em/M1sIT0YxNU=; b=Y7YKKy76zzOtpuFfMvTYUzIGxq2RCQLlJXcF9yH5vexGAug87pmTK4ULldp0x9H2NN fZlBZyUcknL4qU3vWQTs1EaHWgyfFvnCGwd6yny+jFOSg8vRf0QRC2ieBa13+6uDm9Lw bcXdVPUMfvYzDxXUoIG58FBkzK7cAhKiOzzoQ= 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=gwNtivfsVGD+AizNvKbjD5OQNaEu/3Em/M1sIT0YxNU=; b=CuoKQ5oJ5ztrCi2p2KQT5iJwD4GrHrm069IDBhe/FWj70G27fEPdXvl0tDyz8nHFAb SJgdDD187HKtnsTsTqFyVEw+3DUMO1upqmuuwn3yvE78grcwSapMNmaSevIKG/R4M7uq 6xJlXJSe6uCLHBniF1mkbF6MVf2bzgw1ADkW/PJvbR9We76Kk5iQToOUnqUrR6h0EFfC /RYm2YMGYB7ieq6qu1mZwrwywvE+0+YN662Qbh0KSxXRdqPCBU1Z+4waHVOrbzZ5MrcI Jn8T0hGjvfZN8wWc2lCJ5ah6ztGu8MPXDgC6ovxecmW+nxGgSE9HUvLIOpfNG+FKIk77 5n4Q== X-Gm-Message-State: AEkoous/JfYPrm0lhG+Oku1+dtc2f6sy7ITjjZaR1Y9RjaI7KrW5lT4Dyujk5xd/LN/sOhvE X-Received: by 10.194.135.205 with SMTP id pu13mr19320531wjb.37.1471899464642; Mon, 22 Aug 2016 13:57:44 -0700 (PDT) Received: from mohikan.mushroom.smurfnet.nu (cpc92308-cmbg19-2-0-cust814.5-4.cable.virginm.net. [82.24.251.47]) by smtp.gmail.com with ESMTPSA id p71sm23578958wmf.9.2016.08.22.13.57.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 22 Aug 2016 13:57:44 -0700 (PDT) From: Leif Lindholm To: grub-devel@gnu.org Subject: [PATCH 3/3] Reuse arm64 efi linux loader for arm Date: Mon, 22 Aug 2016 21:57:40 +0100 Message-Id: <1471899460-13596-4-git-send-email-leif.lindholm@linaro.org> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1471899460-13596-1-git-send-email-leif.lindholm@linaro.org> References: <1471899460-13596-1-git-send-email-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::22b 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: agraf@suse.de 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 not necessarily acting in an entirely 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 loader. This also drops the ability to boot kernels without the efi stub support on 32-bit arm efi grub. --- grub-core/Makefile.core.def | 5 +++-- grub-core/kern/arm/efi/misc.c | 30 --------------------------- grub-core/loader/arm/linux.c | 48 +++++-------------------------------------- include/grub/arm/efi/loader.h | 1 - include/grub/arm/efi/memory.h | 3 +++ include/grub/arm/linux.h | 43 +++++++++++++++++++------------------- 6 files changed, 32 insertions(+), 98 deletions(-) -- 2.1.4 _______________________________________________ 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 89e338d..b8fb104 100644 --- a/grub-core/Makefile.core.def +++ b/grub-core/Makefile.core.def @@ -1665,7 +1665,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; @@ -1674,7 +1675,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 index 7cd4184..036f857 100644 --- a/grub-core/kern/arm/efi/misc.c +++ b/grub-core/kern/arm/efi/misc.c @@ -170,33 +170,3 @@ grub_efi_allocate_loader_memory (grub_uint32_t min_offset, grub_uint32_t size) 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 5b39f02..83c0e0d 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 index 4bab18e..1bcc79e 100644 --- a/include/grub/arm/efi/loader.h +++ b/include/grub/arm/efi/loader.h @@ -19,7 +19,6 @@ #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); diff --git a/include/grub/arm/efi/memory.h b/include/grub/arm/efi/memory.h index 2c64918..986f656 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 059dbba..078eaa5 100644 --- a/include/grub/arm/linux.h +++ b/include/grub/arm/linux.h @@ -20,38 +20,37 @@ #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 +# define FDT_ADDITIONAL_ENTRIES_SIZE 0x300 + #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) -static inline grub_addr_t -grub_arm_firmware_get_boot_data (void) -{ - return 0; -} -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 +#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 #endif /* ! GRUB_LINUX_CPU_HEADER */