From patchwork Tue Jul 22 00:43:30 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roy Franz X-Patchwork-Id: 34023 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ie0-f197.google.com (mail-ie0-f197.google.com [209.85.223.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 8CA8F20492 for ; Tue, 22 Jul 2014 00:47:12 +0000 (UTC) Received: by mail-ie0-f197.google.com with SMTP id rp18sf65419858iec.8 for ; Mon, 21 Jul 2014 17:47:12 -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=Equ1J24XPhk+G5bVUu0iRACUly1mBJATsogDjf16Ow8=; b=jXonvZBu6flIigtyEOBWBNXd7T/qenoNGiPS/xDlhmwdu27ARAbr1O5c1R0wSX0pqj Qf//YHycs+v25VCslRxAVnk7yB7nI7QaT3uIuynfNplALj0nPF0M9fAvIPQvrNn3g9Po BG3JwbHc+cN+55YaaBs2h83wGKI2PNKPlzOTAEVRzGWSr4ht/YPvglgPRW+FgcQu1wyr kXc1PYAhed5V/5pwfON6RwQUrx4Bk70sNDt4odJE/mK83033uz6bwV2xt4FX6+svp0Qd H7FaDlo9ZTX5IMX5d+5zBUMX9EOg4MJNTJFy3/0Z/z3pa3BFad944iBkP9BfLjstPpbj n4Rw== X-Gm-Message-State: ALoCoQnSqvtgiZ0ntPVkrCA3+pL6tzAhkST5Cri1sJSh9nFaLYS9t5Yd6m4teLayZfm4HNyu6XdX X-Received: by 10.182.51.228 with SMTP id n4mr14744570obo.28.1405990032066; Mon, 21 Jul 2014 17:47:12 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.19.16 with SMTP id 16ls2313429qgg.57.gmail; Mon, 21 Jul 2014 17:47:11 -0700 (PDT) X-Received: by 10.52.253.39 with SMTP id zx7mr29425443vdc.2.1405990031939; Mon, 21 Jul 2014 17:47:11 -0700 (PDT) Received: from mail-vc0-f174.google.com (mail-vc0-f174.google.com [209.85.220.174]) by mx.google.com with ESMTPS id kc6si12830750vdb.69.2014.07.21.17.47.11 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 21 Jul 2014 17:47:11 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.174 as permitted sender) client-ip=209.85.220.174; Received: by mail-vc0-f174.google.com with SMTP id la4so13464143vcb.5 for ; Mon, 21 Jul 2014 17:47:11 -0700 (PDT) X-Received: by 10.52.129.200 with SMTP id ny8mr2799881vdb.27.1405990031861; Mon, 21 Jul 2014 17:47:11 -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 tc5csp154208vcb; Mon, 21 Jul 2014 17:47:11 -0700 (PDT) X-Received: by 10.42.89.204 with SMTP id h12mr9976987icm.37.1405990031164; Mon, 21 Jul 2014 17:47:11 -0700 (PDT) Received: from lists.xen.org (lists.xen.org. [50.57.142.19]) by mx.google.com with ESMTPS id y16si32977944igp.1.2014.07.21.17.47.10 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Mon, 21 Jul 2014 17:47:11 -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 1X9OBl-0000AX-Kb; Tue, 22 Jul 2014 00:44:17 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1X9OBj-00009l-TB for xen-devel@lists.xen.org; Tue, 22 Jul 2014 00:44:16 +0000 Received: from [85.158.137.68:55398] by server-17.bemta-3.messagelabs.com id BC/3F-27015-FD3BDC35; Tue, 22 Jul 2014 00:44:15 +0000 X-Env-Sender: roy.franz@linaro.org X-Msg-Ref: server-16.tower-31.messagelabs.com!1405989851!17180560!1 X-Originating-IP: [209.85.192.170] 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 30729 invoked from network); 22 Jul 2014 00:44:13 -0000 Received: from mail-pd0-f170.google.com (HELO mail-pd0-f170.google.com) (209.85.192.170) by server-16.tower-31.messagelabs.com with RC4-SHA encrypted SMTP; 22 Jul 2014 00:44:13 -0000 Received: by mail-pd0-f170.google.com with SMTP id g10so10094098pdj.15 for ; Mon, 21 Jul 2014 17:44:11 -0700 (PDT) X-Received: by 10.70.96.207 with SMTP id du15mr7654740pdb.133.1405989851532; Mon, 21 Jul 2014 17:44:11 -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 fl3sm15417298pbc.35.2014.07.21.17.44.10 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 21 Jul 2014 17:44:10 -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: Mon, 21 Jul 2014 17:43:30 -0700 Message-Id: <1405989815-25236-8-git-send-email-roy.franz@linaro.org> X-Mailer: git-send-email 2.0.0 In-Reply-To: <1405989815-25236-1-git-send-email-roy.franz@linaro.org> References: <1405989815-25236-1-git-send-email-roy.franz@linaro.org> Cc: Roy Franz , fu.wei@linaro.org, linaro-uefi@lists.linaro.org Subject: [Xen-devel] [PATCH V2 07/12] 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.220.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 | 127 +++++++++++++++++++++++++++++------------------- 1 file changed, 77 insertions(+), 50 deletions(-) diff --git a/xen/arch/x86/efi/boot.c b/xen/arch/x86/efi/boot.c index fa6aca4..2ef86d1 100644 --- a/xen/arch/x86/efi/boot.c +++ b/xen/arch/x86/efi/boot.c @@ -744,6 +744,74 @@ static void __init relocate_image(unsigned long delta) } } + +bool_t __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"); + return 0; + } + + 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"); + return 0; + } + else + { + PrintStr(L"WARNING: Unknown command line option '"); + PrintStr(ptr); + PrintStr(L"' ignored\r\n"); + } + } + else + *section_name = ptr; + } + + if ( argc ) + *image_name = *argv; + + return 1; +} + extern const s32 __trampoline_rel_start[], __trampoline_rel_stop[]; extern const s32 __trampoline_seg_start[], __trampoline_seg_stop[]; @@ -773,8 +841,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 = NULL, *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; @@ -814,53 +883,11 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable) /* Get the file system interface. */ dir_handle = get_parent_handle(loaded_image, &file_name); - if ( !dir_handle ) - blexit(L"EFI get_parent_handle failed."); + if ( !handle_cmdline(loaded_image, &cfg_file_name, &base_video, &image_name, + §ion_name) ) + 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.w = ptr; - } + section.w = section_name; if ( !base_video ) { @@ -976,9 +1003,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