From patchwork Wed Aug 7 03:45:05 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roy Franz X-Patchwork-Id: 2839756 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 3B677BF535 for ; Wed, 7 Aug 2013 03:50:14 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 38CB3201CB for ; Wed, 7 Aug 2013 03:50:13 +0000 (UTC) Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 14A49201C7 for ; Wed, 7 Aug 2013 03:50:12 +0000 (UTC) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1V6ujv-0004NL-2L; Wed, 07 Aug 2013 03:48:50 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1V6uix-0001UP-UY; Wed, 07 Aug 2013 03:47:47 +0000 Received: from mail-gh0-f170.google.com ([209.85.160.170]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1V6uh8-0001Dt-8V for linux-arm-kernel@lists.infradead.org; Wed, 07 Aug 2013 03:46:08 +0000 Received: by mail-gh0-f170.google.com with SMTP id z10so397145ghb.1 for ; Tue, 06 Aug 2013 20:45:33 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=wT3/Ask42oCp4P0gZUKDeyz70aqnydAfihOwPQhkyBc=; b=FaYx5usWP/hhfEToQ9+GFHn5q9c39Eka1YiVW1EuANucXHDwUJbgzHgzUowejFwG9z fxW2Ep3e15zzzmhcq0WUv1TeFPgS85jIQWpBLNWhv4HqxLNDo34CBAUAfiCBBmajvUdy EnFSaOwOSGazXsNJ/9bgfJ03RALFtf8HbGiRr33oO7TU8BHSqRLIWPIy+ZjxLx6C3ycs XMC2/4bzsZ/4Umo++TW1KJmeY+FbGQOshfae7oBaYFgCnh50VvZrdfhouebGOMXR0r6P aVhRfUHoBntANMqA17m8zKsQIwSkdQfOHrn2LkYcX2k6fMbJ66mygdjHkhGjYq/f2ood krMg== X-Gm-Message-State: ALoCoQkmQfJNxM3bfEt85EllgS3NRr8N46u3K2ERuTDkieR0cEsw9KsZwWegLsTxWxdyz24lj8XI X-Received: by 10.236.69.65 with SMTP id m41mr678390yhd.228.1375847133170; Tue, 06 Aug 2013 20:45:33 -0700 (PDT) Received: from rfranz-v430.caveonetworks.com (64.2.3.195.ptr.us.xo.net. [64.2.3.195]) by mx.google.com with ESMTPSA id s65sm6814380yhs.14.2013.08.06.20.45.31 for (version=TLSv1.2 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 06 Aug 2013 20:45:32 -0700 (PDT) From: Roy Franz To: linux-kernel@vger.kernel.org, linux-efi@vger.kernel.org, linux-arm-kernel@lists.infradead.org, matt.fleming@intel.com, linux@arm.linux.org.uk Subject: [PATCH 09/17] Generalize handle_ramdisks() and rename to handle_cmdline_files(). Date: Tue, 6 Aug 2013 20:45:05 -0700 Message-Id: <1375847113-24884-10-git-send-email-roy.franz@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1375847113-24884-1-git-send-email-roy.franz@linaro.org> References: <1375847113-24884-1-git-send-email-roy.franz@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20130806_234554_469446_441ABC50 X-CRM114-Status: GOOD ( 15.07 ) X-Spam-Score: -2.6 (--) Cc: Roy Franz , dave.martin@arm.com, leif.lindholm@linaro.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The handle_cmdline_files now takes the option to handle as a string, and returns the loaded data through parameters, rather than taking an x86 specific setup_header structure. For ARM, this will be used to load a device tree blob in addition to initrd images. Signed-off-by: Roy Franz --- arch/x86/boot/compressed/eboot.c | 9 +++++- drivers/firmware/efi/efi-stub-helper.c | 50 ++++++++++++++++++-------------- 2 files changed, 37 insertions(+), 22 deletions(-) diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c index bcfdcc2..7011e33 100644 --- a/arch/x86/boot/compressed/eboot.c +++ b/arch/x86/boot/compressed/eboot.c @@ -443,6 +443,8 @@ struct boot_params *make_boot_params(void *handle, efi_system_table_t *_table) u16 *s2; u8 *s1; int i; + u64 ramdisk_addr; + u64 ramdisk_size; sys_table = _table; @@ -531,9 +533,14 @@ struct boot_params *make_boot_params(void *handle, efi_system_table_t *_table) memset(sdt, 0, sizeof(*sdt)); - status = handle_ramdisks(sys_table, image, hdr); + status = handle_cmdline_files(sys_table, image, + (char *)(unsigned long)hdr->cmd_line_ptr, + "initrd=", hdr->initrd_addr_max, + &ramdisk_addr, &ramdisk_size); if (status != EFI_SUCCESS) goto fail2; + hdr->ramdisk_image = ramdisk_addr; + hdr->ramdisk_size = ramdisk_size; return boot_params; fail2: diff --git a/drivers/firmware/efi/efi-stub-helper.c b/drivers/firmware/efi/efi-stub-helper.c index bce0473..854aada 100644 --- a/drivers/firmware/efi/efi-stub-helper.c +++ b/drivers/firmware/efi/efi-stub-helper.c @@ -267,9 +267,11 @@ static void efi_free(efi_system_table_t *sys_table_arg, unsigned long size, * We only support loading an initrd from the same filesystem as the * kernel image. */ -static efi_status_t handle_ramdisks(efi_system_table_t *sys_table_arg, - efi_loaded_image_t *image, - struct setup_header *hdr) +static efi_status_t handle_cmdline_files(efi_system_table_t *sys_table_arg, + efi_loaded_image_t *image, + char *cmd_line, char *option_string, + u64 max_addr, + u64 *load_addr, u64 *load_size) { struct initrd *initrds; unsigned long initrd_addr; @@ -285,19 +287,25 @@ static efi_status_t handle_ramdisks(efi_system_table_t *sys_table_arg, initrd_addr = 0; initrd_total = 0; - str = (char *)(unsigned long)hdr->cmd_line_ptr; + str = cmd_line; j = 0; /* See close_handles */ + if (!load_addr || !load_size) + return EFI_INVALID_PARAMETER; + + *load_addr = 0; + *load_size = 0; + if (!str || !*str) return EFI_SUCCESS; for (nr_initrds = 0; *str; nr_initrds++) { - str = strstr(str, "initrd="); + str = strstr(str, option_string); if (!str) break; - str += 7; + str += strlen(option_string); /* Skip any leading slashes */ while (*str == '/' || *str == '\\') @@ -315,11 +323,11 @@ static efi_status_t handle_ramdisks(efi_system_table_t *sys_table_arg, nr_initrds * sizeof(*initrds), &initrds); if (status != EFI_SUCCESS) { - efi_printk(sys_table_arg, "Failed to alloc mem for initrds\n"); + efi_printk(sys_table_arg, "Failed to alloc mem for file load\n"); goto fail; } - str = (char *)(unsigned long)hdr->cmd_line_ptr; + str = cmd_line; for (i = 0; i < nr_initrds; i++) { struct initrd *initrd; efi_file_handle_t *h; @@ -330,11 +338,11 @@ static efi_status_t handle_ramdisks(efi_system_table_t *sys_table_arg, efi_char16_t *p; u64 file_sz; - str = strstr(str, "initrd="); + str = strstr(str, option_string); if (!str) break; - str += 7; + str += strlen(option_string); initrd = &initrds[i]; p = filename_16; @@ -380,7 +388,7 @@ static efi_status_t handle_ramdisks(efi_system_table_t *sys_table_arg, status = efi_call_phys5(fh->open, fh, &h, filename_16, EFI_FILE_MODE_READ, (u64)0); if (status != EFI_SUCCESS) { - efi_printk(sys_table_arg, "Failed to open initrd file: "); + efi_printk(sys_table_arg, "Failed to open file file: "); efi_char16_printk(sys_table_arg, filename_16); efi_printk(sys_table_arg, "\n"); goto close_handles; @@ -392,7 +400,7 @@ static efi_status_t handle_ramdisks(efi_system_table_t *sys_table_arg, status = efi_call_phys4(h->get_info, h, &info_guid, &info_sz, NULL); if (status != EFI_BUFFER_TOO_SMALL) { - efi_printk(sys_table_arg, "Failed to get initrd info size\n"); + efi_printk(sys_table_arg, "Failed to get file info size\n"); goto close_handles; } @@ -400,7 +408,7 @@ grow: status = efi_call_phys3(sys_table_arg->boottime->allocate_pool, EFI_LOADER_DATA, info_sz, &info); if (status != EFI_SUCCESS) { - efi_printk(sys_table_arg, "Failed to alloc mem for initrd info\n"); + efi_printk(sys_table_arg, "Failed to alloc mem for file info\n"); goto close_handles; } @@ -416,7 +424,7 @@ grow: efi_call_phys1(sys_table_arg->boottime->free_pool, info); if (status != EFI_SUCCESS) { - efi_printk(sys_table_arg, "Failed to get initrd info\n"); + efi_printk(sys_table_arg, "Failed to get file info\n"); goto close_handles; } @@ -433,14 +441,14 @@ grow: * all the initrd's. */ status = efi_high_alloc(sys_table_arg, initrd_total, 0x1000, - &initrd_addr, hdr->initrd_addr_max); + &initrd_addr, max_addr); if (status != EFI_SUCCESS) { efi_printk(sys_table_arg, "Failed to alloc highmem for initrds\n"); goto close_handles; } /* We've run out of free low memory. */ - if (initrd_addr > hdr->initrd_addr_max) { + if (initrd_addr > max_addr) { efi_printk(sys_table_arg, "We've run out of free low memory\n"); status = EFI_INVALID_PARAMETER; goto free_initrd_total; @@ -461,7 +469,7 @@ grow: initrds[j].handle, &chunksize, addr); if (status != EFI_SUCCESS) { - efi_printk(sys_table_arg, "Failed to read initrd\n"); + efi_printk(sys_table_arg, "Failed to read file\n"); goto free_initrd_total; } addr += chunksize; @@ -475,8 +483,8 @@ grow: efi_call_phys1(sys_table_arg->boottime->free_pool, initrds); - hdr->ramdisk_image = initrd_addr; - hdr->ramdisk_size = initrd_total; + *load_addr = initrd_addr; + *load_size = initrd_total; return status; @@ -489,8 +497,8 @@ close_handles: free_initrds: efi_call_phys1(sys_table_arg->boottime->free_pool, initrds); fail: - hdr->ramdisk_image = 0; - hdr->ramdisk_size = 0; + *load_addr = 0; + *load_size = 0; return status; }