From patchwork Sat Jun 28 01:25:28 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roy Franz X-Patchwork-Id: 32648 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pd0-f198.google.com (mail-pd0-f198.google.com [209.85.192.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 3380C200B9 for ; Sat, 28 Jun 2014 01:27:32 +0000 (UTC) Received: by mail-pd0-f198.google.com with SMTP id y10sf21512814pdj.5 for ; Fri, 27 Jun 2014 18:27:31 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:date:message-id:in-reply-to :references:cc:subject:precedence:list-id:list-unsubscribe:list-post :list-help:list-subscribe:mime-version:sender:errors-to :x-original-sender:x-original-authentication-results:mailing-list :list-archive:content-type:content-transfer-encoding; bh=o6Y6ZhLNl5Fix+0HEUuYRTHNdiWTBBBLxzwV3JM3IVw=; b=EpKlES4NSRJjKc4AVUHk3TK0NpDDTbCr9ndEKeRtWq0/gTRvDCa2X/01IAxdVPAoCm 8a3X2HkuZ1LAmFOhRN15j7c9CzigAnd632BMsnDseWBzg9rz35XBZ3jGjFhhzZ+naJ6A SNie2Kbswc4+76WkqQAp8jWwPemBVbnBtkuZf2FnmRyKYY7JqW3a0XzeV7IG7bkPBcXj 0K3l2DKNkBsWZ3JLHlxFS8j8oZXVlQK0W+VpNGW64FLAECn8/ypCIsVxK0D8QJ90JgGu efrd0wguVZfv9Ideb+mcoC7bym1Nbxh6TMmxo8seZ4Q7p98s1V8H3EolaqC3DgzzY12/ j60w== X-Gm-Message-State: ALoCoQlb/N7rOFIS9zAVO42IyZIJ3FiSvCtSvGribtgLn6X2sd+jutLsLyWLug4l80XO/qblcIec X-Received: by 10.66.102.68 with SMTP id fm4mr7900692pab.27.1403918851534; Fri, 27 Jun 2014 18:27:31 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.101.78 with SMTP id t72ls813369qge.32.gmail; Fri, 27 Jun 2014 18:27:31 -0700 (PDT) X-Received: by 10.52.182.163 with SMTP id ef3mr19248545vdc.22.1403918851437; Fri, 27 Jun 2014 18:27:31 -0700 (PDT) Received: from mail-ve0-f174.google.com (mail-ve0-f174.google.com [209.85.128.174]) by mx.google.com with ESMTPS id t9si1184422vdg.45.2014.06.27.18.27.31 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 27 Jun 2014 18:27:31 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.128.174 as permitted sender) client-ip=209.85.128.174; Received: by mail-ve0-f174.google.com with SMTP id jx11so6159557veb.33 for ; Fri, 27 Jun 2014 18:27:31 -0700 (PDT) X-Received: by 10.52.29.236 with SMTP id n12mr19303861vdh.38.1403918851312; Fri, 27 Jun 2014 18:27:31 -0700 (PDT) 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.221.37.5 with SMTP id tc5csp147847vcb; Fri, 27 Jun 2014 18:27:30 -0700 (PDT) X-Received: by 10.52.30.9 with SMTP id o9mr19194892vdh.15.1403918849917; Fri, 27 Jun 2014 18:27:29 -0700 (PDT) Received: from lists.xen.org (lists.xen.org. [50.57.142.19]) by mx.google.com with ESMTPS id sk10si7227745vec.81.2014.06.27.18.27.29 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Fri, 27 Jun 2014 18:27:29 -0700 (PDT) Received-SPF: none (google.com: xen-devel-bounces@lists.xen.org does not designate permitted sender hosts) client-ip=50.57.142.19; Received: from localhost ([127.0.0.1] helo=lists.xen.org) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1X0hP2-0007Ll-Rb; Sat, 28 Jun 2014 01:26:04 +0000 Received: from mail6.bemta4.messagelabs.com ([85.158.143.247]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1X0hP0-0007Ji-Tq for xen-devel@lists.xen.org; Sat, 28 Jun 2014 01:26:03 +0000 Received: from [85.158.143.35:17347] by server-3.bemta-4.messagelabs.com id 04/78-16194-AA91EA35; Sat, 28 Jun 2014 01:26:02 +0000 X-Env-Sender: roy.franz@linaro.org X-Msg-Ref: server-5.tower-21.messagelabs.com!1403918759!14412247!1 X-Originating-IP: [209.85.220.48] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 6.11.3; banners=-,-,- X-VirusChecked: Checked Received: (qmail 25797 invoked from network); 28 Jun 2014 01:26:01 -0000 Received: from mail-pa0-f48.google.com (HELO mail-pa0-f48.google.com) (209.85.220.48) by server-5.tower-21.messagelabs.com with RC4-SHA encrypted SMTP; 28 Jun 2014 01:26:01 -0000 Received: by mail-pa0-f48.google.com with SMTP id et14so5363391pad.21 for ; Fri, 27 Jun 2014 18:25:59 -0700 (PDT) X-Received: by 10.68.130.6 with SMTP id oa6mr34626840pbb.102.1403918759322; Fri, 27 Jun 2014 18:25:59 -0700 (PDT) Received: from rfranz-t520.local (c-24-10-97-91.hsd1.ca.comcast.net. [24.10.97.91]) by mx.google.com with ESMTPSA id eh4sm16637918pbc.79.2014.06.27.18.25.58 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 27 Jun 2014 18:25:58 -0700 (PDT) From: Roy Franz To: xen-devel@lists.xen.org, ian.campbell@citrix.com, stefano.stabellini@citrix.com, tim@xen.org, jbeulich@suse.com, keir@xen.org Date: Sat, 28 Jun 2014 02:25:28 +0100 Message-Id: <1403918735-30027-13-git-send-email-roy.franz@linaro.org> X-Mailer: git-send-email 2.0.0 In-Reply-To: <1403918735-30027-1-git-send-email-roy.franz@linaro.org> References: <1403918735-30027-1-git-send-email-roy.franz@linaro.org> Cc: Roy Franz , fu.wei@linaro.org, linaro-uefi@lists.linaro.org Subject: [Xen-devel] [PATCH RFC 12/19] create handle_cmdline() function X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: List-Unsubscribe: , List-Post: , List-Help: , List-Subscribe: , MIME-Version: 1.0 Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: roy.franz@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.128.174 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 List-Archive: Create handle_cmdline() function in preparation for sharing to allow x86 and ARM architectures to share the command line processing. Signed-off-by: Roy Franz --- xen/arch/x86/efi/boot.c | 126 ++++++++++++++++++++++++++++++------------------ 1 file changed, 79 insertions(+), 47 deletions(-) diff --git a/xen/arch/x86/efi/boot.c b/xen/arch/x86/efi/boot.c index 912b6de..6ee3c1f 100644 --- a/xen/arch/x86/efi/boot.c +++ b/xen/arch/x86/efi/boot.c @@ -345,6 +345,74 @@ static void __init relocate_image(unsigned long delta) } } + +void __init handle_cmdline(EFI_LOADED_IMAGE *loaded_image, + CHAR16 **cfg_file_name, bool_t *base_video, + CHAR16 **image_name, CHAR16 **section_name) +{ + + unsigned int i, argc; + CHAR16 **argv; + + + if ( !cfg_file_name || !base_video || !image_name ) + { + PrintStr(L"Invalid args to handle_cmdline\r\n"); + blexit(NULL); + } + + argc = get_argv(0, NULL, loaded_image->LoadOptions, + loaded_image->LoadOptionsSize); + if ( argc > 0 && + efi_bs->AllocatePool(EfiLoaderData, + (argc + 1) * sizeof(*argv) + + loaded_image->LoadOptionsSize, + (void **)&argv) == EFI_SUCCESS ) + get_argv(argc, argv, loaded_image->LoadOptions, + loaded_image->LoadOptionsSize); + else + argc = 0; + + for ( i = 1; i < argc; ++i ) + { + CHAR16 *ptr = argv[i]; + + if ( !ptr ) + break; + if ( *ptr == L'/' || *ptr == L'-' ) + { + if ( wstrcmp(ptr + 1, L"basevideo") == 0 ) + *base_video = 1; + else if ( wstrncmp(ptr + 1, L"cfg=", 4) == 0 ) + *cfg_file_name = ptr + 5; + else if ( i + 1 < argc && wstrcmp(ptr + 1, L"cfg") == 0 ) + *cfg_file_name = argv[++i]; + else if ( wstrcmp(ptr + 1, L"help") == 0 || + (ptr[1] == L'?' && !ptr[2]) ) + { + PrintStr(L"Xen EFI Loader options:\r\n"); + PrintStr(L"-basevideo retain current video mode\r\n"); + PrintStr(L"-cfg= specify configuration file\r\n"); + PrintStr(L"-help, -? display this help\r\n"); + blexit(NULL); + } + else + { + PrintStr(L"WARNING: Unknown command line option '"); + PrintStr(ptr); + PrintStr(L"' ignored\r\n"); + } + } + else + *section_name = ptr; + } + + if ( argc ) + { + *image_name = *argv; + } +} + extern const s32 __trampoline_rel_start[], __trampoline_rel_stop[]; extern const s32 __trampoline_seg_start[], __trampoline_seg_stop[]; @@ -374,8 +442,9 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable) static EFI_GUID __initdata shim_lock_guid = SHIM_LOCK_PROTOCOL_GUID; EFI_LOADED_IMAGE *loaded_image; EFI_STATUS status; - unsigned int i, argc; - CHAR16 **argv, *file_name, *cfg_file_name = NULL; + unsigned int i; + CHAR16 *file_name, *cfg_file_name = NULL, *image_name = NULL; + CHAR16 *section_name = NULL; UINTN cols, rows, depth, size, map_key, info_size, gop_mode = ~0; EFI_HANDLE *handles = NULL; EFI_SHIM_LOCK_PROTOCOL *shim_lock; @@ -414,50 +483,13 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable) /* Get the file system interface. */ dir_handle = get_parent_handle(loaded_image, &file_name); - argc = get_argv(0, NULL, loaded_image->LoadOptions, - loaded_image->LoadOptionsSize); - if ( argc > 0 && - efi_bs->AllocatePool(EfiLoaderData, - (argc + 1) * sizeof(*argv) + - loaded_image->LoadOptionsSize, - (void **)&argv) == EFI_SUCCESS ) - get_argv(argc, argv, loaded_image->LoadOptions, - loaded_image->LoadOptionsSize); - else - argc = 0; - for ( i = 1; i < argc; ++i ) - { - CHAR16 *ptr = argv[i]; + handle_cmdline(loaded_image, + &cfg_file_name, + &base_video, + &image_name, + §ion_name); - if ( !ptr ) - break; - if ( *ptr == L'/' || *ptr == L'-' ) - { - if ( wstrcmp(ptr + 1, L"basevideo") == 0 ) - base_video = 1; - else if ( wstrncmp(ptr + 1, L"cfg=", 4) == 0 ) - cfg_file_name = ptr + 5; - else if ( i + 1 < argc && wstrcmp(ptr + 1, L"cfg") == 0 ) - cfg_file_name = argv[++i]; - else if ( wstrcmp(ptr + 1, L"help") == 0 || - (ptr[1] == L'?' && !ptr[2]) ) - { - PrintStr(L"Xen EFI Loader options:\r\n"); - PrintStr(L"-basevideo retain current video mode\r\n"); - PrintStr(L"-cfg= specify configuration file\r\n"); - PrintStr(L"-help, -? display this help\r\n"); - blexit(NULL); - } - else - { - PrintStr(L"WARNING: Unknown command line option '"); - PrintStr(ptr); - PrintStr(L"' ignored\r\n"); - } - } - else - section.w = ptr; - } + section.w = section_name; if ( !base_video ) { @@ -564,9 +596,9 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable) if ( name.s ) place_string(&mbi.cmdline, name.s); /* Insert image name last, as it gets prefixed to the other options. */ - if ( argc ) + if ( image_name ) { - name.w = *argv; + name.w = image_name; w2s(&name); } else