From patchwork Thu Nov 15 04:58:08 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 151159 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp6553578ljp; Wed, 14 Nov 2018 20:56:46 -0800 (PST) X-Google-Smtp-Source: AJdET5fRkqqe83byaqej73RM30TkbwRPNTVwYia/HuBDJ/88mt031kR5+ExPm1xZG0BO0svY6Ra0 X-Received: by 2002:a17:906:5451:: with SMTP id d17-v6mr3980888ejp.65.1542257806135; Wed, 14 Nov 2018 20:56:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542257806; cv=none; d=google.com; s=arc-20160816; b=RsG4W2gLlYb0RNAELQXfbfRTisVPKy0AwU+3nTeAqFbhXWEAYGxrER7H5JVCH8JHqg vVG75KNdmGWVD7bda+jPIL9flbrEMazALCp6A3TscBgnEL+CTDo75ehHAzIOkmUpnQPM SN+AMZHuBlklZMSXwoGBSA9lfsdP+8sga1X4RRp/pxFuMXspNk6e098gwqN+3Z63P3BY XkLWe40+CItk1Ft27Fdquv1MU73kn0RLZ+cjDZjejpWygPrYAd6cg8JwXCbsnd+7Impr Mci6b1mNGrIOI8Tc14+vsqJATZhSoztMDAN3QDGeOoqizw1STMboi0ueHaKYOBLb0Fbd 0fTQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence:subject :cc:mime-version:references:in-reply-to:message-id:date:to:from :dkim-signature; bh=aeWfbizHoZv5nZsh0Lcyhb9mIX9ikgpnbXzyeJvlrxU=; b=y8IEbKLM1kmB+075oTBu0jo6BBNUfuRdY2+DCajkdqZb4nCNgMXW+ZKkuxZ1yzaszV aCAIr12U6tVH/Iw625jXL6Bd8bpNdbIOLkPLtnQOe4PNqlyxDL2DaS+jIKr6obHPn+iF EW0qX0Z2kD7Ynho5tNnqNzdWVEXpJUf3alj6ndb3mJM6kJ18UY3H8KY8tIvMAy3d2oec t4D8XJviylwOh7ilSpm2xwF1aV8TPTR+t+15HvUYQdxLOw60tT9q3dqN7uv7FXDoW31+ iMsruy5zc1SAAE2/i9uyod5hos/1BdMexLOY71wXNl/8nJGcCJlnwk3PPvxMKXUFhLMV M+7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=FnCEE9vZ; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.denx.de (dione.denx.de. [81.169.180.215]) by mx.google.com with ESMTP id g7-v6si4011150ejl.130.2018.11.14.20.56.45; Wed, 14 Nov 2018 20:56:46 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) client-ip=81.169.180.215; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=FnCEE9vZ; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: by lists.denx.de (Postfix, from userid 105) id AF2B4C222EA; Thu, 15 Nov 2018 04:56:20 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=RCVD_IN_MSPIKE_H2, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 1200FC2222E; Thu, 15 Nov 2018 04:56:19 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id C1DCEC2230E; Thu, 15 Nov 2018 04:56:08 +0000 (UTC) Received: from mail-yb1-f195.google.com (mail-yb1-f195.google.com [209.85.219.195]) by lists.denx.de (Postfix) with ESMTPS id 3C7FEC224BC for ; Thu, 15 Nov 2018 04:56:04 +0000 (UTC) Received: by mail-yb1-f195.google.com with SMTP id z2-v6so7899287ybj.2 for ; Wed, 14 Nov 2018 20:56:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=OI5gh0nWF6I0YMQWT1smhvKgKU/mIhq5m46Ts4nuKQ4=; b=FnCEE9vZPYqfu2LMapj6NZ1BqlLC20C4qOLSPuj1VnmtMe2mwKT3akiyHYNFyQ0GJr JIbsrEM7o4kDBCdH69d9ckyVwfbJIMjgQflMKtXjAk7lfHzjP1H4R5TmYG8Kmd57f8zx mbedo+6RPdxAFkPTN07kNsh35AdGXG/4VSAJs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=OI5gh0nWF6I0YMQWT1smhvKgKU/mIhq5m46Ts4nuKQ4=; b=gM2PvdKPSDN+ZD10OC3T+Av8iPeiKLdZFlEQE7TPef7YEmzf0Y0Q0DKNzhXhPu/uu0 MpVkoRixvczirlA8OGPU6VwnnKNk3fRToHpHTsdcrv2XhgrYnuysq+Jyr4SuiOWoEp4l LXHw02CAUNyA5fI0I2UvQoKcGoXTTdoMnluYYahly1q07WYcJkkbly2vcp+T4ipJhfao KtECLY7sQm308oCvbjJPFsSBaDMp7L7CU7BhB+QBMTNfEFc99Gwwn4UnmVeuPzYHie76 3qFF0mVlg5jzNZJcnWZCAXqK+fU73Dfm7RCtFc6EoLDFBu9sGKgx7ggYHA1QOrhUTE0h zi2A== X-Gm-Message-State: AGRZ1gIs0HuMTuW+V8qrPC0JwH88ofuVkk5sXGuUHM70S7TF0zkyBU0U UKBU/hKP+IoXRXNYz2Rzn+gVuQ== X-Received: by 2002:a25:1c5:: with SMTP id 188-v6mr4410714ybb.374.1542257762957; Wed, 14 Nov 2018 20:56:02 -0800 (PST) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id x4-v6sm4572394ywe.105.2018.11.14.20.56.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 14 Nov 2018 20:56:02 -0800 (PST) From: AKASHI Takahiro To: trini@konsulko.com, agraf@suse.de Date: Thu, 15 Nov 2018 13:58:08 +0900 Message-Id: <20181115045810.28736-2-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181115045810.28736-1-takahiro.akashi@linaro.org> References: <20181115045810.28736-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 Cc: xypron.glpk@gmx.de, u-boot@lists.denx.de Subject: [U-Boot] [PATCH v2 1/3] efi_loader: export efi_locate_handle() function X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" This function will be used later to implement efi_disk_update(). Signed-off-by: AKASHI Takahiro --- include/efi_loader.h | 4 ++++ lib/efi_loader/efi_boottime.c | 7 +++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/include/efi_loader.h b/include/efi_loader.h index ce0f420b5004..5cc3bded03fa 100644 --- a/include/efi_loader.h +++ b/include/efi_loader.h @@ -318,6 +318,10 @@ efi_status_t efi_create_handle(efi_handle_t *handle); void efi_delete_handle(efi_handle_t obj); /* Call this to validate a handle and find the EFI object for it */ struct efi_object *efi_search_obj(const efi_handle_t handle); +/* locate handles */ +efi_status_t efi_locate_handle(enum efi_locate_search_type search_type, + const efi_guid_t *protocol, void *search_key, + efi_uintn_t *buffer_size, efi_handle_t *buffer); /* Find a protocol on a handle */ efi_status_t efi_search_protocol(const efi_handle_t handle, const efi_guid_t *protocol_guid, diff --git a/lib/efi_loader/efi_boottime.c b/lib/efi_loader/efi_boottime.c index 8a43a5a84091..a3c56bbab552 100644 --- a/lib/efi_loader/efi_boottime.c +++ b/lib/efi_loader/efi_boottime.c @@ -1309,10 +1309,9 @@ static int efi_search(enum efi_locate_search_type search_type, * * Return: status code */ -static efi_status_t efi_locate_handle( - enum efi_locate_search_type search_type, - const efi_guid_t *protocol, void *search_key, - efi_uintn_t *buffer_size, efi_handle_t *buffer) +efi_status_t efi_locate_handle(enum efi_locate_search_type search_type, + const efi_guid_t *protocol, void *search_key, + efi_uintn_t *buffer_size, efi_handle_t *buffer) { struct efi_object *efiobj; efi_uintn_t size = 0; From patchwork Thu Nov 15 04:58:09 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 151161 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp6554289ljp; Wed, 14 Nov 2018 20:57:49 -0800 (PST) X-Google-Smtp-Source: AJdET5fXCrnsbCX9YWVZ5+g5gmB7YYDir/sExUVJtKwIC/1a2O8pkDT1ufqK4LOtd3YJCPlr1NQD X-Received: by 2002:a50:8e16:: with SMTP id 22mr1499576edw.32.1542257869044; Wed, 14 Nov 2018 20:57:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542257869; cv=none; d=google.com; s=arc-20160816; b=kqKWDg5LhvjjdklI1yIXGKGJr6nzFUabYE86gg6XUQbsWZ+bzTOPeir+VlZinsVzTC qyjJRWCvaQNeEJIGvjIvVtUwPcUi2xTXwDUxKlMPYK0uPh/Jk222CLsaGnueNWV9J8ty U/g7fOeOyZET0zrHH5Qen4RabLXg4jMAolAtqRVl07a3fm/+sa3yu3K1EecZTQYOzNy9 ulAP8UiJ7XABu1ppqq5epZGNTsYC5+CZ5anQI5orNPkR0svYF2PKE5W7tTc8PozMPEBn Mi6oHo9KJUcYvirDwZIYDTd5ml/VE3jMHQNiE62tsRFcfw+MOmcTit49DdKeX9q7YFwk +P4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence:subject :cc:mime-version:references:in-reply-to:message-id:date:to:from :dkim-signature; bh=JiN+a8Q07T1y05TwCh3TZWZuWvK2/vzpC0cwhH842CU=; b=BMohil9hRBudOWjq0sWas67qk2oaaOel+EVfso34Ru0fzPBiGHjPgo1xZ6OUE/sneQ 4Shp9zqQ947g2kYyG3BR0Rl+2qEQwvSNNNQWxqK3S2yrcN4n6BArcsXqkHPtcF8VoSNl GkVhNDaq3iRuLDkBegrKanUs04cu9DBJxyd4pu8utKgkReaa2A3yJf3/Mlcuh81yqciB GTzzL+mHnQq4+9w0JpQgFNjSRKrmZ+72XQn58PeqITOy3koJqWE7aaoPeaecOzbg/tbo XJ0lx200p7qMDZd2EacKCFsdMUnNCLBwQWL4N/sLqCYt6R1sODwy0UqgNkEZWIU3wCLv JUow== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=ht4S73Ps; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.denx.de (dione.denx.de. [81.169.180.215]) by mx.google.com with ESMTP id c16-v6si1136658ejr.327.2018.11.14.20.57.48; Wed, 14 Nov 2018 20:57:49 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) client-ip=81.169.180.215; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=ht4S73Ps; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: by lists.denx.de (Postfix, from userid 105) id A8253C224A8; Thu, 15 Nov 2018 04:56:39 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=RCVD_IN_MSPIKE_H2, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id D9445C224D1; Thu, 15 Nov 2018 04:56:21 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id CF6EBC224D1; Thu, 15 Nov 2018 04:56:11 +0000 (UTC) Received: from mail-yb1-f193.google.com (mail-yb1-f193.google.com [209.85.219.193]) by lists.denx.de (Postfix) with ESMTPS id 251C8C224DE for ; Thu, 15 Nov 2018 04:56:08 +0000 (UTC) Received: by mail-yb1-f193.google.com with SMTP id p144-v6so7856389yba.11 for ; Wed, 14 Nov 2018 20:56:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=XO5tuAPi0hvt2xSlUD/H/BifiR6issya9T/vv5gkTN8=; b=ht4S73PshQgf738MbQ6orCPIdAdaBJv2t4BF0U/XpJOGfSBJ3b2no+wrrtnx/LagNy dyUQq666CrLkEFK9QHfhYP0St6f5zAMkMhuIb/CZBnhpgKka5KCWaS2OTvuJLm8VpoBk 47pFYsQ7lCAL+mR4HSIPVQWn6b1FJKBe2/lhw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=XO5tuAPi0hvt2xSlUD/H/BifiR6issya9T/vv5gkTN8=; b=mXR4I1r3jO7gEWVeDIN2mvKMlfl7v36C7h76Hy2R2PaY3k8BZ+AU2Q9t87ZtPvoPmc ZXgyV814Mh2LdKAaz75Sisev5eTPVKlAQX9FdaZmsxGkdIGDZuXdmDXj+idXbk01Uge/ Om5r2VhQ0hfrOrIrvtMY39kFiru6gdiv3IXcexVB4XLcFriHZYHAIWrL/a89EerQjHP9 9E7NGpGR6W79LMZMXlBoIoBLFRyW1MgovbEw2zoDcD1oQ17oS3kl5Rfu0FQSdxbRhdSk 93RQDNDYnCEzkwi21kWCitQFgT96D8OhP3jGgI5S3pkWzANjJnqdCZXxr9WsspEwmsR+ osnA== X-Gm-Message-State: AGRZ1gJ2B29m6r0VR04HCjSVnf4LL+2R9stWB7c/EtbNErcxcGlxYD2q JRt6rTEzfumiLib1j0V9AaoyBw== X-Received: by 2002:a25:3c81:: with SMTP id j123-v6mr4448086yba.250.1542257766867; Wed, 14 Nov 2018 20:56:06 -0800 (PST) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id u4sm5965234ywu.92.2018.11.14.20.56.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 14 Nov 2018 20:56:06 -0800 (PST) From: AKASHI Takahiro To: trini@konsulko.com, agraf@suse.de Date: Thu, 15 Nov 2018 13:58:09 +0900 Message-Id: <20181115045810.28736-3-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181115045810.28736-1-takahiro.akashi@linaro.org> References: <20181115045810.28736-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 Cc: xypron.glpk@gmx.de, u-boot@lists.denx.de Subject: [U-Boot] [PATCH v2 2/3] efi_loader: enumerate disk devices every time X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Currently, efi_init_obj_list() scan disk devices only once, and never change a list of efi disk devices. This will possibly result in failing to find a removable storage which may be added later on. See [1]. In this patch, called is efi_disk_update() which is responsible for re-scanning UCLASS_BLK devices and removing/adding efi disks if necessary. For example, => efishell devices Scanning disk pci_mmc.blk... Found 3 disks Device Name ============================================ /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b) /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/SD(0)/SD(0) /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/SD(0)/SD(0)/HD(2,MBR,0x086246ba,0x40800,0x3f800) => usb start starting USB... USB0: USB EHCI 1.00 scanning bus 0 for devices... 3 USB Device(s) found scanning usb for storage devices... 1 Storage Device(s) found => efishell devices Scanning disk usb_mass_storage.lun0... Device Name ============================================ /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b) /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/SD(0)/SD(0) /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/SD(0)/SD(0)/HD(2,MBR,0x086246ba,0x40800,0x3f800) /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/USBClass(0,0,9,0,1)/USBClass(46f4,1,0,0,0)/HD(1,0x01,0,0x40,0x14fe4c) Without this patch, the last device, USB mass storage, won't show up. [1] https://lists.denx.de/pipermail/u-boot/2018-October/345307.html Signed-off-by: AKASHI Takahiro --- cmd/bootefi.c | 17 +++- include/efi_loader.h | 4 + lib/efi_loader/efi_disk.c | 191 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 210 insertions(+), 2 deletions(-) diff --git a/cmd/bootefi.c b/cmd/bootefi.c index 3cefb4d0ecaa..82649e211fda 100644 --- a/cmd/bootefi.c +++ b/cmd/bootefi.c @@ -56,9 +56,22 @@ efi_status_t efi_init_obj_list(void) */ efi_save_gd(); - /* Initialize once only */ - if (efi_obj_list_initialized != OBJ_LIST_NOT_INITIALIZED) + if (efi_obj_list_initialized == EFI_SUCCESS) { +#ifdef CONFIG_PARTITIONS + ret = efi_disk_update(); + if (ret != EFI_SUCCESS) + printf("+++ updating disks list failed\n"); + + /* + * It may sound odd, but most part of EFI should + * yet work. + */ +#endif return efi_obj_list_initialized; + } else if (efi_obj_list_initialized != OBJ_LIST_NOT_INITIALIZED) { + /* Initialize once only */ + return efi_obj_list_initialized; + } /* Initialize system table */ ret = efi_initialize_system_table(); diff --git a/include/efi_loader.h b/include/efi_loader.h index 5cc3bded03fa..3bae1844befb 100644 --- a/include/efi_loader.h +++ b/include/efi_loader.h @@ -260,6 +260,10 @@ efi_status_t efi_initialize_system_table(void); efi_status_t efi_console_register(void); /* Called by bootefi to make all disk storage accessible as EFI objects */ efi_status_t efi_disk_register(void); +/* Check validity of efi disk */ +bool efi_disk_is_valid(efi_handle_t handle); +/* Called by bootefi to find and update disk storage information */ +efi_status_t efi_disk_update(void); /* Create handles and protocols for the partitions of a block device */ int efi_disk_create_partitions(efi_handle_t parent, struct blk_desc *desc, const char *if_typename, int diskid, diff --git a/lib/efi_loader/efi_disk.c b/lib/efi_loader/efi_disk.c index c037526ad2d0..0c4d79ee3fc9 100644 --- a/lib/efi_loader/efi_disk.c +++ b/lib/efi_loader/efi_disk.c @@ -14,10 +14,14 @@ const efi_guid_t efi_block_io_guid = BLOCK_IO_GUID; +#define _EFI_DISK_FLAG_DELETED 0x1 /* to be removed */ +#define _EFI_DISK_FLAG_INVALID 0x80000000 /* in stale state */ + /** * struct efi_disk_obj - EFI disk object * * @header: EFI object header + * @flags: control flags * @ops: EFI disk I/O protocol interface * @ifname: interface name for block device * @dev_index: device index of block device @@ -30,6 +34,7 @@ const efi_guid_t efi_block_io_guid = BLOCK_IO_GUID; */ struct efi_disk_obj { struct efi_object header; + int flags; struct efi_block_io ops; const char *ifname; int dev_index; @@ -41,6 +46,35 @@ struct efi_disk_obj { struct blk_desc *desc; }; +static void efi_disk_mark_deleted(struct efi_disk_obj *disk) +{ + disk->flags |= _EFI_DISK_FLAG_DELETED; +} + +static void efi_disk_clear_deleted(struct efi_disk_obj *disk) +{ + disk->flags &= ~_EFI_DISK_FLAG_DELETED; +} + +static bool efi_disk_deleted_marked(struct efi_disk_obj *disk) +{ + return disk->flags & _EFI_DISK_FLAG_DELETED; +} + +static void efi_disk_mark_invalid(struct efi_disk_obj *disk) +{ + disk->flags |= _EFI_DISK_FLAG_INVALID; +} + +bool efi_disk_is_valid(efi_handle_t handle) +{ + struct efi_disk_obj *disk; + + disk = container_of(handle, struct efi_disk_obj, header); + + return !(disk->flags & _EFI_DISK_FLAG_INVALID); +} + static efi_status_t EFIAPI efi_disk_reset(struct efi_block_io *this, char extended_verification) { @@ -64,6 +98,9 @@ static efi_status_t efi_disk_rw_blocks(struct efi_block_io *this, unsigned long n; diskobj = container_of(this, struct efi_disk_obj, ops); + if (diskobj->flags & _EFI_DISK_FLAG_INVALID) + return EFI_DEVICE_ERROR; + desc = (struct blk_desc *) diskobj->desc; blksz = desc->blksz; blocks = buffer_size / blksz; @@ -440,3 +477,157 @@ efi_status_t efi_disk_register(void) return EFI_SUCCESS; } + +/* + * Mark all the block devices as "deleted," and return an array of + * handles for later use. It should be freed in a caller. + */ +static efi_status_t efi_disk_mark_deleted_all(efi_handle_t **handlesp) +{ + efi_handle_t *handles = NULL; + efi_uintn_t size = 0; + int num, i; + struct efi_disk_obj *disk; + efi_status_t ret; + + ret = efi_locate_handle(BY_PROTOCOL, &efi_block_io_guid, NULL, + &size, handles); + if (ret == EFI_BUFFER_TOO_SMALL) { + handles = calloc(1, size); + if (!handles) + return EFI_OUT_OF_RESOURCES; + + ret = efi_locate_handle(BY_PROTOCOL, &efi_block_io_guid, NULL, + &size, handles); + } + if (ret != EFI_SUCCESS) { + free(handles); + return ret; + } + + num = size / sizeof(*handles); + for (i = 0; i < num; i++) { + disk = container_of(handles[i], struct efi_disk_obj, header); + efi_disk_mark_deleted(disk); + } + + *handlesp = handles; + + return num; +} + +/* + * Clear "deleted" flag for a block device which is identified with desc. + * If desc is NULL, clear all devices. + * + * Return a number of disks cleared. + */ +static int efi_disk_clear_deleted_matched(struct blk_desc *desc, + efi_handle_t *handles, int num) +{ + struct efi_disk_obj *disk; + int disks, i; + + for (i = 0, disks = 0; i < num; i++) { + disk = container_of(handles[i], struct efi_disk_obj, header); + + if (!desc || disk->desc == desc) { + efi_disk_clear_deleted(disk); + disks++; + } + } + + return disks; +} + +/* + * Do delete all the block devices marked as "deleted" + */ +static efi_status_t efi_disk_do_delete(efi_handle_t *handles, int num) +{ + struct efi_disk_obj *disk; + int i; + + for (i = 0; i < num; i++) { + disk = container_of(handles[i], struct efi_disk_obj, header); + + if (!efi_disk_deleted_marked(disk)) + continue; + + efi_disk_mark_invalid(disk); + /* + * TODO: + * efi_delete_handle(handles[i]); + */ + } + + return EFI_SUCCESS; +} + +/* + * efi_disk_update - recreate efi disk mappings after initialization + * + * @return efi error code + */ +efi_status_t efi_disk_update(void) +{ +#ifdef CONFIG_BLK + efi_handle_t *handles = NULL; + struct udevice *dev; + struct blk_desc *desc; + const char *if_typename; + struct efi_disk_obj *disk; + int n, disks = 0; + efi_status_t ret; + + /* temporarily mark all the devices "deleted" */ + ret = efi_disk_mark_deleted_all(&handles); + if (ret & EFI_ERROR_MASK) { + printf("ERROR: Failed to rescan block devices.\n"); + return ret; + } + + n = (int)ret; + for (uclass_first_device_check(UCLASS_BLK, &dev); dev; + uclass_next_device_check(&dev)) { + desc = dev_get_uclass_platdata(dev); + if (n && efi_disk_clear_deleted_matched(desc, handles, n)) + /* existing device */ + continue; + + /* new device */ + if_typename = blk_get_if_type_name(desc->if_type); + + /* Add block device for the full device */ + printf("Scanning disk %s...\n", dev->name); + ret = efi_disk_add_dev(NULL, NULL, if_typename, + desc, desc->devnum, 0, 0, &disk); + if (ret == EFI_NOT_READY) { + printf("Disk %s not ready\n", dev->name); + continue; + } + if (ret != EFI_SUCCESS) { + printf("ERROR: failure to add disk device %s, r = %lu\n", + dev->name, ret & ~EFI_ERROR_MASK); + continue; + } + disks++; + + /* Partitions show up as block devices in EFI */ + disks += efi_disk_create_partitions(&disk->header, desc, + if_typename, + desc->devnum, dev->name); + } + + if (n) { + /* do delete "deleted" disks */ + ret = efi_disk_do_delete(handles, n); + + /* undo marking */ + efi_disk_clear_deleted_matched(NULL, handles, n); + + free(handles); + } +#endif + return EFI_SUCCESS; +} From patchwork Thu Nov 15 04:58:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 151160 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp6554167ljp; Wed, 14 Nov 2018 20:57:38 -0800 (PST) X-Google-Smtp-Source: AJdET5fqMbeTxbPNX41of2F0SzeFK9DOPfs8T0vQRiZNZLa7+2olw0R5WfTYBIC8naFH2YnVlAAV X-Received: by 2002:a50:a307:: with SMTP id 7-v6mr4315787edn.231.1542257858248; Wed, 14 Nov 2018 20:57:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542257858; cv=none; d=google.com; s=arc-20160816; b=Q9q6GyBABEIw4ivdrQwc92lBx+J6bCVMJvIDBFHuPDk6NtOdqpQ9+Wp/LoFbO7Mi0k plUB2ouffkfYI0rhwZJERIw045FaJk+H4UpRSQqGJBEkp01zrVFAS0GR3q9LkdDPgws2 kWNqeaCJE+z5Znuv3Y6Rl6okkOsZsmWnj0CaiB2rCtU35LvWkIKvzZckqIOsjYg+BSon ZZIZSSP8HodXVGW3ydOyosVVfBvI0YAP83tlS2qxNXcyltZNb9CMgAyDG2PeVZj946rQ Fm+c+wiZIaQjNMqNA0V+AvLRd4ME6oOM0I+OBCe+w65rKxe4dVRPLdKx2QoKFqk2otTZ WFtA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence:subject :cc:mime-version:references:in-reply-to:message-id:date:to:from :dkim-signature; bh=R7Zs2tqxmLWUVkb5xQOEEbmeaM14/O/XhlRknNEYMdw=; b=r1G8gpvjSoP9h9VrTNNY3aVHxFPnUB7+eeOHvZGGQjlMg9GxeqF3Pc/s7xahbyvk+X 5MOF/mKI8K97zHCiaf+UudO2J0tp9sQQxq1rWNl6ViHxrmX7QMEuvNDSS9UMr38NX4Fh GOts+KGemO+gU38CaIt/nQ7/floi3Rj1gw/MdfpLuPNEzd8SZw+WI8GoYcG5mJsgU5Y9 sZzE79GoFbC3ZH7bgfUhdqgeclGEllWpqtWp7t0hiYwtA4eTDJpntmv3TzV4Kow5J2u4 TMFffUNAkKzwyagzhxQm+dv6yuQZQudnu6oo6jMnoEmBqz9dfClbdfcpy26eqS1e0wfr SNiA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b="Ypq8DN/V"; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.denx.de (dione.denx.de. [81.169.180.215]) by mx.google.com with ESMTP id 35si3638671eds.137.2018.11.14.20.57.37; Wed, 14 Nov 2018 20:57:38 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) client-ip=81.169.180.215; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b="Ypq8DN/V"; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: by lists.denx.de (Postfix, from userid 105) id DA26AC222EA; Thu, 15 Nov 2018 04:57:04 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=RCVD_IN_MSPIKE_H2, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id A960BC2249D; Thu, 15 Nov 2018 04:56:38 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 3CB4AC223FF; Thu, 15 Nov 2018 04:56:16 +0000 (UTC) Received: from mail-yb1-f195.google.com (mail-yb1-f195.google.com [209.85.219.195]) by lists.denx.de (Postfix) with ESMTPS id D30D9C224B8 for ; Thu, 15 Nov 2018 04:56:12 +0000 (UTC) Received: by mail-yb1-f195.google.com with SMTP id h187-v6so7865561ybg.10 for ; Wed, 14 Nov 2018 20:56:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=sEmW8TD1fQj+shkOF89uMJsMyVjrnSsOTY5KRyEy8ZM=; b=Ypq8DN/VxpWmXGB0yBFZ38yTMLAzELPiGmns6oWf4gGODhkOMJPbfkWKywJ6+6w+RM s1Nn8ou/9dVZvYnttRJ1tt6PiF8wWcVPmVpvK79EgOAmfND0dAmcpDy+0wG3nrD8ydq+ 1oUJzbvlc1syR+Vwswulb2EFxTd6dqfudqShU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=sEmW8TD1fQj+shkOF89uMJsMyVjrnSsOTY5KRyEy8ZM=; b=uoUTcOM5Ex/126vDVnJvUCJC3K7i/iVDn4aanbJMWB9h0vHl/P2chmp+bMjP8x9tSS DAYV/V11bfJNhlYsO4uNAPKtxcVG6F2NvbDEv6/LSlcKmX3w4eeQ2bXE7CXhF4KpPWYr /KsR7ooXcH0V0u46AJy8Hp7mn57AO/x45Qz3myUdK5LkEjn5K/397N4Vu7cXVcS0yrRW yI0L106RQQYK9AWXALayZdDZ3Xd2BWwN4bhSeyRsxhZdBXw9wUSAaEviDSZVOdlMX54j KCKsL/K1QJ6VvgHG7ba6UZhsMJbJ7RmOnpjvRGR6+g5qzSlBPjxGfq0+FKpRErSVmXtm EWmw== X-Gm-Message-State: AGRZ1gLDUicAgPtGcZVWOuDLmE08GrU12csGNRrOdN4FzWagAhFxXyp7 NdM2JQXHvx+VhWu0yKkoOeU4dw== X-Received: by 2002:a5b:84e:: with SMTP id v14-v6mr4305512ybq.87.1542257771677; Wed, 14 Nov 2018 20:56:11 -0800 (PST) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id h145sm5014203ywc.72.2018.11.14.20.56.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 14 Nov 2018 20:56:11 -0800 (PST) From: AKASHI Takahiro To: trini@konsulko.com, agraf@suse.de Date: Thu, 15 Nov 2018 13:58:10 +0900 Message-Id: <20181115045810.28736-4-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181115045810.28736-1-takahiro.akashi@linaro.org> References: <20181115045810.28736-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 Cc: xypron.glpk@gmx.de, u-boot@lists.denx.de Subject: [U-Boot] [PATCH v2 3/3] efi_loader: remove block device details from efi file X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Logically, details on u-boot block device used to implement efi file protocol are mostly unnecessary, as well as being duplicated, in efi_file structure. Moreover, a newly introduced flag, _EFI_DISK_FLAG_INVALID, should be honored in any file operations via efi file protocol. These observation suggests that those internal details be set behind efi_disk object. So rework in this patch addresses all those issues above although there is little change in its functionality. Signed-off-by: AKASHI Takahiro --- include/efi_loader.h | 6 +++++- lib/efi_loader/efi_disk.c | 38 ++++++++++++++++++++++++++++++++++++-- lib/efi_loader/efi_file.c | 21 ++++++++------------- 3 files changed, 49 insertions(+), 16 deletions(-) diff --git a/include/efi_loader.h b/include/efi_loader.h index 3bae1844befb..108ef3fe52ee 100644 --- a/include/efi_loader.h +++ b/include/efi_loader.h @@ -264,6 +264,10 @@ efi_status_t efi_disk_register(void); bool efi_disk_is_valid(efi_handle_t handle); /* Called by bootefi to find and update disk storage information */ efi_status_t efi_disk_update(void); +/* Called by file protocol to set internal block io device */ +int efi_disk_set_blk_dev(efi_handle_t disk); +/* Called by file protocol to get disk/partition information */ +int efi_disk_get_info(efi_handle_t disk, disk_partition_t *part); /* Create handles and protocols for the partitions of a block device */ int efi_disk_create_partitions(efi_handle_t parent, struct blk_desc *desc, const char *if_typename, int diskid, @@ -355,7 +359,7 @@ void efi_signal_event(struct efi_event *event, bool check_tpl); /* open file system: */ struct efi_simple_file_system_protocol *efi_simple_file_system( - struct blk_desc *desc, int part, struct efi_device_path *dp); + efi_handle_t disk); /* open file from device-path: */ struct efi_file_handle *efi_file_from_path(struct efi_device_path *fp); diff --git a/lib/efi_loader/efi_disk.c b/lib/efi_loader/efi_disk.c index 0c4d79ee3fc9..180e8e10bb28 100644 --- a/lib/efi_loader/efi_disk.c +++ b/lib/efi_loader/efi_disk.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include @@ -254,6 +255,40 @@ efi_fs_from_path(struct efi_device_path *full_path) return handler->protocol_interface; } +/* + * Set block device for later block io's from file system protocol + * + * @disk handle to uefi disk device + * @return 0 for success, -1 for failure + */ +int efi_disk_set_blk_dev(efi_handle_t disk) +{ + struct efi_disk_obj *diskobj; + + diskobj = container_of(disk, struct efi_disk_obj, header); + + return fs_set_blk_dev_with_part(diskobj->desc, diskobj->part); +} + +/* + * Get disk/partition information + * + * @disk handle to uefi disk device + * @part pointer to disk/partition information to be returned + * @return 0 for success, -1 for failure + */ +int efi_disk_get_info(efi_handle_t disk, disk_partition_t *part) +{ + struct efi_disk_obj *diskobj; + + diskobj = container_of(disk, struct efi_disk_obj, header); + + if (diskobj->part >= 1) + return part_get_info(diskobj->desc, diskobj->part, part); + else + return part_get_info_whole_disk(diskobj->desc, part); +} + /* * Create a handle for a partition or disk * @@ -308,8 +343,7 @@ static efi_status_t efi_disk_add_dev( if (ret != EFI_SUCCESS) return ret; if (part >= 1) { - diskobj->volume = efi_simple_file_system(desc, part, - diskobj->dp); + diskobj->volume = efi_simple_file_system(&diskobj->header); ret = efi_add_protocol(&diskobj->header, &efi_simple_file_system_protocol_guid, diskobj->volume); diff --git a/lib/efi_loader/efi_file.c b/lib/efi_loader/efi_file.c index beb4fba917d8..944383224f30 100644 --- a/lib/efi_loader/efi_file.c +++ b/lib/efi_loader/efi_file.c @@ -17,9 +17,7 @@ const efi_guid_t efi_file_system_info_guid = EFI_FILE_SYSTEM_INFO_GUID; struct file_system { struct efi_simple_file_system_protocol base; - struct efi_device_path *dp; - struct blk_desc *desc; - int part; + efi_handle_t disk; }; #define to_fs(x) container_of(x, struct file_system, base) @@ -49,7 +47,10 @@ static char *basename(struct file_handle *fh) static int set_blk_dev(struct file_handle *fh) { - return fs_set_blk_dev_with_part(fh->fs->desc, fh->fs->part); + if (!efi_disk_is_valid(fh->fs->disk)) + return -1; + + return efi_disk_set_blk_dev(fh->fs->disk); } /** @@ -570,10 +571,7 @@ static efi_status_t EFIAPI efi_file_getinfo(struct efi_file_handle *file, efi_uintn_t required_size; int r; - if (fh->fs->part >= 1) - r = part_get_info(fh->fs->desc, fh->fs->part, &part); - else - r = part_get_info_whole_disk(fh->fs->desc, &part); + r = efi_disk_get_info(fh->fs->disk, &part); if (r < 0) { ret = EFI_DEVICE_ERROR; goto error; @@ -694,17 +692,14 @@ efi_open_volume(struct efi_simple_file_system_protocol *this, } struct efi_simple_file_system_protocol * -efi_simple_file_system(struct blk_desc *desc, int part, - struct efi_device_path *dp) +efi_simple_file_system(efi_handle_t disk) { struct file_system *fs; fs = calloc(1, sizeof(*fs)); fs->base.rev = EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_REVISION; fs->base.open_volume = efi_open_volume; - fs->desc = desc; - fs->part = part; - fs->dp = dp; + fs->disk = disk; return &fs->base; }