From patchwork Fri Nov 7 22:14:16 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roy Franz X-Patchwork-Id: 40449 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f200.google.com (mail-wi0-f200.google.com [209.85.212.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id B843D218C0 for ; Fri, 7 Nov 2014 22:16:13 +0000 (UTC) Received: by mail-wi0-f200.google.com with SMTP id h11sf2345567wiw.11 for ; Fri, 07 Nov 2014 14:16:13 -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:from:to:date:message-id: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=WS7Em6Erw31R5rdi0TN1JMXZUIFdrur0YSpj6fQXRSM=; b=Eb6g9n5uuk4CYv5PnaxsyvqJmvXk4ZTBWONMMPtgF62Ncm2U0021FLSjtZUny7p4sX I3toFLtu7k4WJTjez68qkqAj+Lyq/DicpIQT3NKivkBpx85/6jEk4kq5PYfjN/ALj/3j vKrr5g7UTC8MIpA50E3/Ho4zslPQdkrRdFRS3QSuIo3saTBJvbBO9b1s7ftuzptcDgTE E6F3E3c/l4Sv7T9pIIaexdPaCyA0ErFzKvSQuTI2X4jcC35HV2D07ct+mJZZWa55yCcl 5i2lC/bPeZUaTkKKnzAL7gzBwlH+MJvHgd0vT4lvMTEtKv09uHz74JRZSWG2rUJrjMZH 915g== X-Gm-Message-State: ALoCoQl/rWs0w7dw/vRbH7BkW4tbq+J2OQefPbTMMVELnN7qUYokZASc8yKM4KqKBM1KcFKFhUyx X-Received: by 10.112.55.10 with SMTP id n10mr10139lbp.14.1415398572935; Fri, 07 Nov 2014 14:16:12 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.43.166 with SMTP id x6ls258902lal.93.gmail; Fri, 07 Nov 2014 14:16:12 -0800 (PST) X-Received: by 10.112.162.73 with SMTP id xy9mr4632762lbb.94.1415398572524; Fri, 07 Nov 2014 14:16:12 -0800 (PST) Received: from mail-la0-f52.google.com (mail-la0-f52.google.com. [209.85.215.52]) by mx.google.com with ESMTPS id wz10si16543538lbb.109.2014.11.07.14.16.12 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 07 Nov 2014 14:16:12 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.52 as permitted sender) client-ip=209.85.215.52; Received: by mail-la0-f52.google.com with SMTP id pv20so5243821lab.11 for ; Fri, 07 Nov 2014 14:16:12 -0800 (PST) X-Received: by 10.152.27.38 with SMTP id q6mr4751553lag.92.1415398572374; Fri, 07 Nov 2014 14:16:12 -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.184.201 with SMTP id ew9csp280765lbc; Fri, 7 Nov 2014 14:16:11 -0800 (PST) X-Received: by 10.52.234.230 with SMTP id uh6mr8024861vdc.10.1415398570711; Fri, 07 Nov 2014 14:16:10 -0800 (PST) Received: from lists.xen.org (lists.xen.org. [50.57.142.19]) by mx.google.com with ESMTPS id wu2si7431057vcb.39.2014.11.07.14.16.10 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Fri, 07 Nov 2014 14:16:10 -0800 (PST) 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 1XmrnY-0004JQ-I9; Fri, 07 Nov 2014 22:14:28 +0000 Received: from mail6.bemta4.messagelabs.com ([85.158.143.247]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1XmrnW-0004JH-Ln for xen-devel@lists.xen.org; Fri, 07 Nov 2014 22:14:26 +0000 Received: from [85.158.143.35] by server-3.bemta-4.messagelabs.com id C0/D8-09936-2444D545; Fri, 07 Nov 2014 22:14:26 +0000 X-Env-Sender: roy.franz@linaro.org X-Msg-Ref: server-5.tower-21.messagelabs.com!1415398463!12292040!1 X-Originating-IP: [209.85.192.178] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 6.12.4; banners=-,-,- X-VirusChecked: Checked Received: (qmail 7384 invoked from network); 7 Nov 2014 22:14:24 -0000 Received: from mail-pd0-f178.google.com (HELO mail-pd0-f178.google.com) (209.85.192.178) by server-5.tower-21.messagelabs.com with RC4-SHA encrypted SMTP; 7 Nov 2014 22:14:24 -0000 Received: by mail-pd0-f178.google.com with SMTP id fp1so4054743pdb.23 for ; Fri, 07 Nov 2014 14:14:23 -0800 (PST) X-Received: by 10.70.38.134 with SMTP id g6mr15399130pdk.124.1415398463041; Fri, 07 Nov 2014 14:14:23 -0800 (PST) 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 mz5sm5740250pdb.35.2014.11.07.14.14.21 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 07 Nov 2014 14:14:22 -0800 (PST) From: Roy Franz To: xen-devel@lists.xen.org, ian.campbell@citrix.com, stefano.stabellini@citrix.com, tim@xen.org, jbeulich@suse.com Date: Fri, 7 Nov 2014 14:14:16 -0800 Message-Id: <1415398456-27423-1-git-send-email-roy.franz@linaro.org> X-Mailer: git-send-email 2.1.1 Cc: Roy Franz , daniel.kiper@oracle.com, fu.wei@linaro.org Subject: [Xen-devel] [PATCH for-4.5 v3] EFI: Ignore EFI commandline, skip console setup when booted from GRUB 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.215.52 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: Update EFI code to completely ignore the EFI comnandline when booted from GRUB. Previusly it was parsed of EFI boot specific options, but these aren't used when booted from GRUB. Don't do EFI console or video configuration when booted by GRUB. The EFI boot code does some console and video initialization to support native EFI boot from the EFI boot manager or EFI shell. This initlization should not be done when booted using GRUB. Update EFI documentation to indicate that it describes EFI native boot, and does not apply at all when Xen is booted using GRUB. Signed-off-by: Roy Franz --- --- This patch implements what I understand to be the desired behavior when booting an EFI Xen image via GRUB based on the thread last week. The EFI command line is not used, and the Xen commandline comes via the multiboot protocol (and in the ARM case the multiboot FDT bindings). This brings the x86 and arm64 GRUB EFI boot cases into alignment in not using the EFI commandline. The current state of the arm64 code takes the Xen commandline from the FDT, but still looks in the EFI commandline for EFI boot specific options. If unexpected options are passed in the EFI commandline, it will generate "unrecognized option" ouput for all unexpected options. I think this should be considered for 4.5. Changes since v2: * Rephrased documentation update to avoid "multi-boot aware bootloader", as this is a more general concept that implies things not required for this patch. Changes from v1: * Fixed style, and removed blank line changes * Reviewed scope of variables now that more code is in if ( use_cfg_file ) block docs/misc/efi.markdown | 5 ++ xen/common/efi/boot.c | 240 +++++++++++++++++++++++++------------------------ 2 files changed, 128 insertions(+), 117 deletions(-) diff --git a/docs/misc/efi.markdown b/docs/misc/efi.markdown index 5e48aa3..c3a0b0a 100644 --- a/docs/misc/efi.markdown +++ b/docs/misc/efi.markdown @@ -29,6 +29,11 @@ separators will be tried) to be present in the same directory as the binary. (To illustrate the name handling, a binary named `xen-4.2-unstable.efi` would try `xen-4.2-unstable.cfg`, `xen-4.2.cfg`, `xen-4.cfg`, and `xen.cfg` in order.) One can override this with a command line option (`-cfg=`). +This configuration file and EFI commandline are only used for booting directly +from EFI firmware, or when using an simple EFI application loader. When booting +using a bootloader such as GRUB that loads the dom0 kernel and any other +required modules, the EFI commandline is ignored. In this case all information +is passed to Xen using the multiboot2 protocol (x86), or using a FDT (arm64). The configuration file consists of one or more sections headed by a section name enclosed in square brackets, with individual values specified in each diff --git a/xen/common/efi/boot.c b/xen/common/efi/boot.c index 4257341..471dff7 100644 --- a/xen/common/efi/boot.c +++ b/xen/common/efi/boot.c @@ -697,7 +697,7 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable) EFI_STATUS status; unsigned int i, argc; CHAR16 **argv, *file_name, *cfg_file_name = NULL, *options = NULL; - UINTN cols, rows, depth, size, map_key, info_size, gop_mode = ~0; + UINTN map_key, info_size, gop_mode = ~0; EFI_HANDLE *handles = NULL; EFI_SHIM_LOCK_PROTOCOL *shim_lock; EFI_GRAPHICS_OUTPUT_PROTOCOL *gop = NULL; @@ -705,6 +705,7 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable) union string section = { NULL }, name; bool_t base_video = 0; char *option_str; + bool_t use_cfg_file; efi_ih = ImageHandle; efi_bs = SystemTable->BootServices; @@ -717,6 +718,7 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable) StdOut = SystemTable->ConOut; StdErr = SystemTable->StdErr ?: StdOut; + use_cfg_file = efi_arch_use_config_file(SystemTable); status = efi_bs->HandleProtocol(ImageHandle, &loaded_image_guid, (void **)&loaded_image); @@ -725,67 +727,71 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable) efi_arch_load_addr_check(loaded_image); - argc = get_argv(0, NULL, loaded_image->LoadOptions, - loaded_image->LoadOptionsSize, NULL); - 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, &options); - else - argc = 0; - for ( i = 1; i < argc; ++i ) + if ( use_cfg_file ) { - CHAR16 *ptr = argv[i]; - - if ( !ptr ) - break; - if ( *ptr == L'/' || *ptr == L'-' ) + argc = get_argv(0, NULL, loaded_image->LoadOptions, + loaded_image->LoadOptionsSize, NULL); + 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, &options); + else + argc = 0; + for ( i = 1; i < argc; ++i ) { - 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]) ) + CHAR16 *ptr = argv[i]; + + if ( !ptr ) + break; + if ( *ptr == L'/' || *ptr == L'-' ) { - 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); + 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 - { - PrintStr(L"WARNING: Unknown command line option '"); - PrintStr(ptr); - PrintStr(L"' ignored\r\n"); - } + section.w = ptr; } - else - section.w = ptr; - } - if ( !base_video ) - { - unsigned int best; - - for ( i = 0, size = 0, best = StdOut->Mode->Mode; - i < StdOut->Mode->MaxMode; ++i ) + if ( !base_video ) { - if ( StdOut->QueryMode(StdOut, i, &cols, &rows) == EFI_SUCCESS && - cols * rows > size ) + unsigned int best; + UINTN cols, rows, size; + + for ( i = 0, size = 0, best = StdOut->Mode->Mode; + i < StdOut->Mode->MaxMode; ++i ) { - size = cols * rows; - best = i; + if ( StdOut->QueryMode(StdOut, i, &cols, &rows) == EFI_SUCCESS && + cols * rows > size ) + { + size = cols * rows; + best = i; + } } + if ( best != StdOut->Mode->Mode ) + StdOut->SetMode(StdOut, best); } - if ( best != StdOut->Mode->Mode ) - StdOut->SetMode(StdOut, best); } PrintStr(L"Xen " __stringify(XEN_VERSION) "." __stringify(XEN_SUBVERSION) @@ -793,37 +799,38 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable) efi_arch_relocate_image(0); - if ( StdOut->QueryMode(StdOut, StdOut->Mode->Mode, - &cols, &rows) == EFI_SUCCESS ) - efi_arch_console_init(cols, rows); - - size = 0; - status = efi_bs->LocateHandle(ByProtocol, &gop_guid, NULL, &size, NULL); - if ( status == EFI_BUFFER_TOO_SMALL ) - status = efi_bs->AllocatePool(EfiLoaderData, size, (void **)&handles); - if ( !EFI_ERROR(status) ) - status = efi_bs->LocateHandle(ByProtocol, &gop_guid, NULL, &size, - handles); - if ( EFI_ERROR(status) ) - size = 0; - for ( i = 0; i < size / sizeof(*handles); ++i ) - { - status = efi_bs->HandleProtocol(handles[i], &gop_guid, (void **)&gop); - if ( EFI_ERROR(status) ) - continue; - status = gop->QueryMode(gop, gop->Mode->Mode, &info_size, &mode_info); - if ( !EFI_ERROR(status) ) - break; - } - if ( handles ) - efi_bs->FreePool(handles); - if ( EFI_ERROR(status) ) - gop = NULL; - - cols = rows = depth = 0; - if ( efi_arch_use_config_file(SystemTable) ) + if ( use_cfg_file ) { EFI_FILE_HANDLE dir_handle; + UINTN depth, cols, rows, size; + + size = cols = rows = depth = 0; + + if ( StdOut->QueryMode(StdOut, StdOut->Mode->Mode, + &cols, &rows) == EFI_SUCCESS ) + efi_arch_console_init(cols, rows); + + status = efi_bs->LocateHandle(ByProtocol, &gop_guid, NULL, &size, NULL); + if ( status == EFI_BUFFER_TOO_SMALL ) + status = efi_bs->AllocatePool(EfiLoaderData, size, (void **)&handles); + if ( !EFI_ERROR(status) ) + status = efi_bs->LocateHandle(ByProtocol, &gop_guid, NULL, &size, + handles); + if ( EFI_ERROR(status) ) + size = 0; + for ( i = 0; i < size / sizeof(*handles); ++i ) + { + status = efi_bs->HandleProtocol(handles[i], &gop_guid, (void **)&gop); + if ( EFI_ERROR(status) ) + continue; + status = gop->QueryMode(gop, gop->Mode->Mode, &info_size, &mode_info); + if ( !EFI_ERROR(status) ) + break; + } + if ( handles ) + efi_bs->FreePool(handles); + if ( EFI_ERROR(status) ) + gop = NULL; /* Get the file system interface. */ dir_handle = get_parent_handle(loaded_image, &file_name); @@ -931,45 +938,44 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable) dir_handle->Close(dir_handle); - } - - if ( gop && !base_video ) - { - for ( i = size = 0; i < gop->Mode->MaxMode; ++i ) + if ( gop && !base_video ) { - unsigned int bpp = 0; - - status = gop->QueryMode(gop, i, &info_size, &mode_info); - if ( EFI_ERROR(status) ) - continue; - switch ( mode_info->PixelFormat ) - { - case PixelBitMask: - bpp = hweight32(mode_info->PixelInformation.RedMask | - mode_info->PixelInformation.GreenMask | - mode_info->PixelInformation.BlueMask); - break; - case PixelRedGreenBlueReserved8BitPerColor: - case PixelBlueGreenRedReserved8BitPerColor: - bpp = 24; - break; - default: - continue; - } - if ( cols == mode_info->HorizontalResolution && - rows == mode_info->VerticalResolution && - (!depth || bpp == depth) ) + for ( i = size = 0; i < gop->Mode->MaxMode; ++i ) { - gop_mode = i; - break; - } - if ( !cols && !rows && - mode_info->HorizontalResolution * - mode_info->VerticalResolution > size ) - { - size = mode_info->HorizontalResolution * - mode_info->VerticalResolution; - gop_mode = i; + unsigned int bpp = 0; + + status = gop->QueryMode(gop, i, &info_size, &mode_info); + if ( EFI_ERROR(status) ) + continue; + switch ( mode_info->PixelFormat ) + { + case PixelBitMask: + bpp = hweight32(mode_info->PixelInformation.RedMask | + mode_info->PixelInformation.GreenMask | + mode_info->PixelInformation.BlueMask); + break; + case PixelRedGreenBlueReserved8BitPerColor: + case PixelBlueGreenRedReserved8BitPerColor: + bpp = 24; + break; + default: + continue; + } + if ( cols == mode_info->HorizontalResolution && + rows == mode_info->VerticalResolution && + (!depth || bpp == depth) ) + { + gop_mode = i; + break; + } + if ( !cols && !rows && + mode_info->HorizontalResolution * + mode_info->VerticalResolution > size ) + { + size = mode_info->HorizontalResolution * + mode_info->VerticalResolution; + gop_mode = i; + } } } }