From patchwork Thu Dec 18 18:04:15 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fu Wei Fu X-Patchwork-Id: 42469 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f200.google.com (mail-lb0-f200.google.com [209.85.217.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 1EB5826C6B for ; Thu, 18 Dec 2014 18:04:49 +0000 (UTC) Received: by mail-lb0-f200.google.com with SMTP id f15sf1175965lbj.3 for ; Thu, 18 Dec 2014 10:04:48 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:message-id:date:from:organization :user-agent:mime-version:to:subject:cc:precedence:reply-to:list-id :list-unsubscribe:list-archive:list-post:list-help:list-subscribe :content-type:content-transfer-encoding:errors-to:sender :x-original-sender:x-original-authentication-results:mailing-list; bh=hZt0SMMw1x/mzb9UuqIQYUxsls9jWVWQQUdHbtFhWwM=; b=Pbyw0wvtyv8rCnrqFWAKPX09752W3vnn3tuuNyaiEcEmt/8IQedxjqu/0uSgoKA0UV Zpp5gYxRSp5GdFUOlwBKHs5aNpqaYgxV85PADb+LoF2fVe5xbfdND+ZIRRiOZEhjt78/ 1MbcgtEoghMsC7EOBGQ4MA41BPBmob/nMmmrVXj7eAzcniLaauEIVhURifpN5RgkivHV PHCz8bsEhKXgQZyROTzhoAzmTDL3qJazxuSH7yewHRaRIYKwEi3BMjLiQA1pcrmjhBQR sgZPyYAprGcVklXJjeq+wNt2qSAyrN2UZvEKfjfu/5sV5kfGQZcJJmDGraufv5lbLAgU wxhA== X-Gm-Message-State: ALoCoQnXCsOuoISouEwmsxYDG7DYssgJMOMIasGDhfBG9d0EYeBds+jAilGec+kr+6eOB8FfkP/O X-Received: by 10.112.219.199 with SMTP id pq7mr536538lbc.9.1418925888126; Thu, 18 Dec 2014 10:04:48 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.36.5 with SMTP id m5ls1070456laj.71.gmail; Thu, 18 Dec 2014 10:04:47 -0800 (PST) X-Received: by 10.112.159.129 with SMTP id xc1mr3636971lbb.24.1418925887772; Thu, 18 Dec 2014 10:04:47 -0800 (PST) Received: from mail-lb0-f171.google.com (mail-lb0-f171.google.com. [209.85.217.171]) by mx.google.com with ESMTPS id m4si7555835lbd.106.2014.12.18.10.04.47 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 18 Dec 2014 10:04:47 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.171 as permitted sender) client-ip=209.85.217.171; Received: by mail-lb0-f171.google.com with SMTP id w7so1420169lbi.2 for ; Thu, 18 Dec 2014 10:04:47 -0800 (PST) X-Received: by 10.112.170.36 with SMTP id aj4mr3564136lbc.3.1418925887334; Thu, 18 Dec 2014 10:04:47 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.142.69 with SMTP id ru5csp22838lbb; Thu, 18 Dec 2014 10:04:46 -0800 (PST) X-Received: by 10.224.137.131 with SMTP id w3mr5908166qat.95.1418925885362; Thu, 18 Dec 2014 10:04:45 -0800 (PST) Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id t19si9020295qac.130.2014.12.18.10.04.44 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Thu, 18 Dec 2014 10:04:45 -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; Received: from localhost ([::1]:55173 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y1fRM-0001b9-Fv for patch@linaro.org; Thu, 18 Dec 2014 13:04:44 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54664) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y1fR5-0001Zv-HS for grub-devel@gnu.org; Thu, 18 Dec 2014 13:04:33 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Y1fQz-0003Va-Fu for grub-devel@gnu.org; Thu, 18 Dec 2014 13:04:27 -0500 Received: from mail-pa0-f53.google.com ([209.85.220.53]:44624) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y1fQz-0003VQ-7E for grub-devel@gnu.org; Thu, 18 Dec 2014 13:04:21 -0500 Received: by mail-pa0-f53.google.com with SMTP id kq14so1870367pab.12 for ; Thu, 18 Dec 2014 10:04:20 -0800 (PST) X-Received: by 10.70.130.108 with SMTP id od12mr5388189pdb.109.1418925860270; Thu, 18 Dec 2014 10:04:20 -0800 (PST) Received: from [192.168.1.11] ([59.58.226.187]) by mx.google.com with ESMTPSA id ig1sm7379147pbc.41.2014.12.18.10.04.18 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 Dec 2014 10:04:19 -0800 (PST) Message-ID: <5493171F.5010402@linaro.org> Date: Fri, 19 Dec 2014 02:04:15 +0800 From: Fu Wei Organization: Linaro User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.3.0 MIME-Version: 1.0 To: grub-devel@gnu.org, Leif Lindholm , Ian Campbell Subject: [PATCH 2/5] arm64: Move some #define from X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.85.220.53 Cc: Roy Franz , Jon Masters , linaro-uefi X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list Reply-To: The development of GNU GRUB List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , Errors-To: grub-devel-bounces+patch=linaro.org@gnu.org Sender: grub-devel-bounces+patch=linaro.org@gnu.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: fu.wei@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.171 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 grub-core/loader/arm64/linux.c to include/grub/arm64/linux.h Reason: (1)make code more orderly (2)these #define can be used by other files which includs include/grub/arm64/linux.h Make some shared functions for multiboot.c Signed-off-by: Fu Wei Reviewed-by: Leif Lindholm --- grub-core/loader/arm64/linux.c | 59 +++++++++++++++++++++--------------------- include/grub/arm64/linux.h | 11 ++++++++ 2 files changed, 41 insertions(+), 29 deletions(-) diff --git a/grub-core/loader/arm64/linux.c b/grub-core/loader/arm64/linux.c index 564a75a..987f5b9 100644 --- a/grub-core/loader/arm64/linux.c +++ b/grub-core/loader/arm64/linux.c @@ -33,12 +33,6 @@ GRUB_MOD_LICENSE ("GPLv3+"); -#define GRUB_EFI_PAGE_SHIFT 12 -#define BYTES_TO_PAGES(bytes) (((bytes) + 0xfff) >> GRUB_EFI_PAGE_SHIFT) -#define GRUB_EFI_PE_MAGIC 0x5A4D - -static grub_efi_guid_t fdt_guid = GRUB_EFI_DEVICE_TREE_GUID; - static grub_dl_t my_mod; static int loaded; @@ -58,6 +52,7 @@ static void * get_firmware_fdt (void) { grub_efi_configuration_table_t *tables; + grub_efi_guid_t fdt_guid = GRUB_EFI_DEVICE_TREE_GUID; void *firmware_fdt = NULL; unsigned int i; @@ -75,8 +70,8 @@ get_firmware_fdt (void) return firmware_fdt; } -static void -get_fdt (void) +void * +grub_linux_get_fdt (void) { void *raw_fdt; grub_size_t size; @@ -99,7 +94,7 @@ get_fdt (void) grub_dprintf ("linux", "allocating %ld bytes for fdt\n", size); fdt = grub_efi_allocate_pages (0, BYTES_TO_PAGES (size)); if (!fdt) - return; + return NULL; if (raw_fdt) { @@ -110,10 +105,11 @@ get_fdt (void) { grub_fdt_create_empty_tree (fdt, size); } + return fdt; } -static grub_err_t -check_kernel (struct grub_arm64_linux_kernel_header *lh) +grub_err_t +grub_arm64_uefi_check_image (struct grub_arm64_linux_kernel_header * lh) { if (lh->magic != GRUB_ARM64_LINUX_MAGIC) return grub_error(GRUB_ERR_BAD_OS, "invalid magic number"); @@ -131,14 +127,14 @@ check_kernel (struct grub_arm64_linux_kernel_header *lh) } static grub_err_t -finalize_params (void) +finalize_params_linux (void) { grub_efi_boot_services_t *b; + grub_efi_guid_t fdt_guid = GRUB_EFI_DEVICE_TREE_GUID; grub_efi_status_t status; int node, retval; - get_fdt (); - if (!fdt) + if (!grub_linux_get_fdt ()) goto failure; node = grub_fdt_find_subnode (fdt, 0, "chosen"); @@ -240,21 +236,16 @@ out: return grub_errno; } -static grub_err_t -grub_linux_boot (void) +grub_err_t +grub_arm64_uefi_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; grub_efi_boot_services_t *b; grub_efi_status_t status; - grub_err_t retval; grub_efi_loaded_image_t *loaded_image; int len; - retval = finalize_params(); - if (retval != GRUB_ERR_NONE) - return retval; - mempath = grub_malloc (2 * sizeof (grub_efi_memory_mapped_device_path_t)); if (!mempath) return grub_errno; @@ -263,8 +254,8 @@ grub_linux_boot (void) mempath[0].header.subtype = GRUB_EFI_MEMORY_MAPPED_DEVICE_PATH_SUBTYPE; mempath[0].header.length = grub_cpu_to_le16_compile_time (sizeof (*mempath)); mempath[0].memory_type = GRUB_EFI_LOADER_DATA; - mempath[0].start_address = (grub_addr_t) kernel_addr; - mempath[0].end_address = (grub_addr_t) kernel_addr + kernel_size; + mempath[0].start_address = addr; + mempath[0].end_address = addr + size; mempath[1].header.type = GRUB_EFI_END_DEVICE_PATH_TYPE; mempath[1].header.subtype = GRUB_EFI_END_ENTIRE_DEVICE_PATH_SUBTYPE; @@ -273,16 +264,16 @@ grub_linux_boot (void) b = grub_efi_system_table->boot_services; status = b->load_image (0, grub_efi_image_handle, (grub_efi_device_path_t *) mempath, - kernel_addr, kernel_size, &image_handle); + (void *) addr, size, &image_handle); if (status != GRUB_EFI_SUCCESS) return grub_error (GRUB_ERR_BAD_OS, "cannot load image"); - grub_dprintf ("linux", "linux command line: '%s'\n", linux_args); + grub_dprintf ("linux", "linux command line: '%s'\n", args); /* Convert command line to UCS-2 */ loaded_image = grub_efi_get_loaded_image (image_handle); loaded_image->load_options_size = len = - (grub_strlen (linux_args) + 1) * sizeof (grub_efi_char16_t); + (grub_strlen (args) + 1) * sizeof (grub_efi_char16_t); loaded_image->load_options = grub_efi_allocate_pages (0, BYTES_TO_PAGES (loaded_image->load_options_size)); @@ -291,9 +282,9 @@ grub_linux_boot (void) loaded_image->load_options_size = 2 * grub_utf8_to_utf16 (loaded_image->load_options, len, - (grub_uint8_t *) linux_args, len, NULL); + (grub_uint8_t *) args, len, NULL); - grub_dprintf("linux", "starting image %p\n", image_handle); + grub_dprintf ("linux", "starting image %p\n", image_handle); status = b->start_image (image_handle, 0, NULL); /* When successful, not reached */ @@ -305,6 +296,16 @@ grub_linux_boot (void) } static grub_err_t +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)); +} + +static grub_err_t grub_linux_unload (void) { grub_dl_unref (my_mod); @@ -400,7 +401,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 (check_kernel (&lh) != GRUB_ERR_NONE) + if (grub_arm64_uefi_check_image (&lh) != GRUB_ERR_NONE) goto fail; grub_loader_unset(); diff --git a/include/grub/arm64/linux.h b/include/grub/arm64/linux.h index 864e5dc..65796d9 100644 --- a/include/grub/arm64/linux.h +++ b/include/grub/arm64/linux.h @@ -23,6 +23,10 @@ #define GRUB_ARM64_LINUX_MAGIC 0x644d5241 /* 'ARM\x64' */ +#define GRUB_EFI_PAGE_SHIFT 12 +#define BYTES_TO_PAGES(bytes) (((bytes) + 0xfff) >> GRUB_EFI_PAGE_SHIFT) +#define GRUB_EFI_PE_MAGIC 0x5A4D + /* From linux/Documentation/arm64/booting.txt */ struct grub_arm64_linux_kernel_header { @@ -38,4 +42,11 @@ struct grub_arm64_linux_kernel_header grub_uint32_t hdr_offset; /* Offset of PE/COFF header */ }; +/* Declare the functions for getting dtb and checking/booting image */ +void *grub_linux_get_fdt (void); +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 */