From patchwork Wed Nov 7 00:44:33 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 150366 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp4555236ljp; Tue, 6 Nov 2018 16:42:31 -0800 (PST) X-Google-Smtp-Source: AJdET5e9kE3A6Fg/JmNgKmaqxS6S58NYFIyvdH8rs0puC41RSYWAIZbyGWAja/BIld7+DjAUOxzf X-Received: by 2002:a17:906:2da9:: with SMTP id g9-v6mr108323eji.67.1541551351753; Tue, 06 Nov 2018 16:42:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541551351; cv=none; d=google.com; s=arc-20160816; b=xvoHygXJ0YW6+ixYZ5e4TcHKZVocJaUPmQZMOlLL52QKbGmmopl3s6oMaLD0+sfC1W UJDuFOm0KnRsjhGg8bC0m15S3oYTJqIed9D+RwCcQc0xMJOP5AY/acYiMXIXHf4vgxdE 917yEolWKqyWIeB9fvfc3a7jc3kHNQnlb/CHliqFbUPhW2qrDMm4ud0Lkf+jSlLT0SKR 3MsQTxvncJ/FOsKSvXRY9y4rjq1iFgZmww5LtygWHBMQ/qAsvctzB5Ymb5YYq5yzY+BY T+Ej5i2CTVhECKzYbbEOlmfmrOIUIrX8RqwToWif+XnwJUENzkYS0YFY9N3x6nUfGGFk qE2g== 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:message-id:date:to:from:dkim-signature; bh=aeWfbizHoZv5nZsh0Lcyhb9mIX9ikgpnbXzyeJvlrxU=; b=UNjdNEFzuEMNDeXxSlaPI7LxTy6ge1YMkJF+iYEnmCX8OBS/+dBSow8PQWcw3bQPgu 4tUVXDW8oxDhTRqZH+JBON4sJeBMcjoFRvRV3WkNN7s57m0Il4m5EzfihuxSYoifpGlv 7RHWNKPych4ELShC+J5mCBs/g9vhKiMscuAm8CbHnTPz/3anEAh9lTW8RErtCDZ8YnjY 7RxMGQBTkWQESYmyX9YEngdjWB58E2Ob8KSBMtZ69KmDB8sHHUm8vpyusNmpqOGDWAw6 g2NG1beUjQQaKvhEmDFbfmwrQ4pyaBshhqA0WcwZvSJQltrvq8/2egUacPkMUUoC0cwR Fa5w== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=Ib4LFqwt; 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 k6-v6si6706503edk.323.2018.11.06.16.42.31; Tue, 06 Nov 2018 16:42:31 -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=Ib4LFqwt; 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 15D5EC223E9; Wed, 7 Nov 2018 00:42:28 +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_DNSWL_NONE, 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 7AA85C223E9; Wed, 7 Nov 2018 00:42:26 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 3397BC223E9; Wed, 7 Nov 2018 00:42:25 +0000 (UTC) Received: from mail-yb1-f194.google.com (mail-yb1-f194.google.com [209.85.219.194]) by lists.denx.de (Postfix) with ESMTPS id 9D65DC21DD7 for ; Wed, 7 Nov 2018 00:42:24 +0000 (UTC) Received: by mail-yb1-f194.google.com with SMTP id p144-v6so6148927yba.11 for ; Tue, 06 Nov 2018 16:42:24 -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:mime-version :content-transfer-encoding; bh=OI5gh0nWF6I0YMQWT1smhvKgKU/mIhq5m46Ts4nuKQ4=; b=Ib4LFqwtxXD1bjLYphc4r5uG/oFJGkGYMzBsnWTUt422MBPpuXsinxhGD+EFnW4I43 F7yks1R9b0Z0lUDk7herx9vAeuUckUboIxSbnWfSDcvEnBrXmX8mvMCKYCSAgjkrknRG ovtMIk/Lc/lc0/oeOq/x1DnnejQTAGeG5jXJM= 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:mime-version :content-transfer-encoding; bh=OI5gh0nWF6I0YMQWT1smhvKgKU/mIhq5m46Ts4nuKQ4=; b=bHG03eHl/sVKF6V+BMMRVCPR8oIOXRaJMJHF2PDYYE2xFeef8tCb0XdHogK/N99JVM MYxMUCiJKPuRQzuPZ3Z1rY3qMECZfCr+NSuuUmtZwaL8P6dvJSbgGt/nPm/StP99pWyN I4XzYj7dg4oaUzbf+VzJNKEVmgDJXDfsuZ3gqNgHQrkXHIYJElnLEmopALslpcVinV0d R9458dqoI0qPRXLEXhkNSKzrcQuPGqiM7mzaH4r5ia/Y4YdHQk+irjY8pnUZ2vWQ4b3a D/+YQ3nYDuLsf4jfP1jZgMRbic5Z8zR1arrB28na5pPY9FA7j63vvubr2Xhzn2/RIU3z RbIg== X-Gm-Message-State: AGRZ1gLfylZXoOsjPFvyRQ+ibcHOIBW3nty4OOEmNE8s/+mLrJb7IxmM bqZnCf6GRj2HQcC6z/OSWZ3+sg== X-Received: by 2002:a25:870e:: with SMTP id a14-v6mr14033304ybl.253.1541551343143; Tue, 06 Nov 2018 16:42:23 -0800 (PST) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id v129-v6sm1929461ywa.8.2018.11.06.16.42.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 06 Nov 2018 16:42:22 -0800 (PST) From: AKASHI Takahiro To: trini@konsulko.com, agraf@suse.de Date: Wed, 7 Nov 2018 09:44:33 +0900 Message-Id: <20181107004434.31491-1-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.19.0 MIME-Version: 1.0 Cc: xypron.glpk@gmx.de, u-boot@lists.denx.de Subject: [U-Boot] [PATCH 1/2] 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 Wed Nov 7 00:44:34 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 150367 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp4555558ljp; Tue, 6 Nov 2018 16:42:59 -0800 (PST) X-Google-Smtp-Source: AJdET5fYcQZk6t6WdfwtOzqVAGQipfOJqkqW0V/2YufNVyQRn00AW37T3upS7stALB4ZlaQCraiW X-Received: by 2002:a50:8c01:: with SMTP id p1-v6mr150675edp.48.1541551379681; Tue, 06 Nov 2018 16:42:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541551379; cv=none; d=google.com; s=arc-20160816; b=A/ZzjjTg0sQyIQghwakuZwy+weEGFFNg1P1A+sjqgII8WzHxe96l5HYiF/UN/cEier U3D/V2AOU934IZw59t1PvLFP0RrTpHS7QM+aS8pxty0a2f5EK2zycdt4+Y6/xcD/1XJE jD1uc3umNgFx+fOU4yKUaUGiwD2bx9/fJ3kwocNDMEquuNTWmVGEfRKVIl1Oxa4XRA14 yB8KDrrIPxo0wQVEwcnSMj3PBeoZ+vPHAJspJK1hdaWrZ/JSAMf4bae+ELGD6ADtQcTG Om1kPmYnVSQb+820VA4fD13s7qoLGQDnOQF0vwruTdLSD2AHy2kbnqIEXnpokG7ShdH0 hhuA== 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=py2NU9GVee1AKJg6y2727mOPBKidi+R7k5YcMgWKs+0=; b=p+QBCwK8C0RCs6xXoGnRrjIHTC72UuHkbNg54W4xCEny53sdAwluz/SFiomub+n+dN jtvD3xy3GOoWG6K4CyHCSB89/p7IRkeVis2MOn6vbwdqaZQVmBqXX+MKBJIj30+xD9Vx ZDm1Bm05XyEtcTBTBDyOnBtVgcyCRqAtCd8Kah14Io3jk+j/Im/WV6rAQstZUSQslN4D NDURtUv16YYT8zTBJT4T4rYqH8uKiVKn2Q/LwownMa0Ht6DOIk5Cyt/yhWy3Y5oy5YMN T04RGFl0EYin/OT+TEia/rhc3GIy1fOGqFB6y1n6y6q5Am5T/8XQjtt9/diQWxznTDBt rPhQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=kzrASXGU; 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 e1-v6si370840ejc.189.2018.11.06.16.42.59; Tue, 06 Nov 2018 16:42:59 -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=kzrASXGU; 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 54200C2272D; Wed, 7 Nov 2018 00:42:57 +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_DNSWL_BLOCKED, 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 26660C22784; Wed, 7 Nov 2018 00:42:55 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id D2AD3C22784; Wed, 7 Nov 2018 00:42:40 +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 BDE42C22756 for ; Wed, 7 Nov 2018 00:42:36 +0000 (UTC) Received: by mail-yb1-f193.google.com with SMTP id d18-v6so6168793yba.4 for ; Tue, 06 Nov 2018 16:42:36 -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=srpHyqt9M9rqsnrsllIJm4YIpN9aiUsSFG+4BcGoMAg=; b=kzrASXGUK56CMXDUI0Z6Y3zlxzp2NnJ58IEmvJquK5zJTwXo5ep6FNIqMMaxPCdUGz Faiv1Wh5by6kyyNNiCJyHRSpC3Le55d1T29nJbrUyJTWVVuTXQ9iRRf9i0zHm8nLeh5r 6zn20EjeVASG5wx+g6txo+Wt+O8iARZ1jYzd4= 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=srpHyqt9M9rqsnrsllIJm4YIpN9aiUsSFG+4BcGoMAg=; b=Db35m0lSIBg7ZPiDjIYyV7GUEYCaVxppdsN5i4XP+7/CJrxm+PP7hSHUboetg4yxOU oXYRUXrCJjsEds6h1dHk4WBs4H5IzF+0GDQ+kvPU0DAHdY3NgVs6ZFkkHpOIwiC2fEmf CsYGsx34ws7BsDEF+JdbIicoSAgjMJQBsKRnicmUoFHWh+1Vse3+sxL/IDLt2xReCV4h U4s2SZJcWW8Ftcy7D4+E3KrHNX1PDeIU0AbSLJTk4Daq4kbWV5X6bQuFkgtz1so02MEA rc+p6Idgj/Yqt/9xVH+LaFwxHTps4dedbMFgiqI4Ac0b7jZ1Wreo8Vqw2FUYOHrxc7fr 3pEA== X-Gm-Message-State: AGRZ1gITzbEzDzjDRNaEMeorvGhuJPuHIBH30BV84BBpWng0Cq0RIlGj p1M3nGe7kAE22h1GF0v0OoNQKQ== X-Received: by 2002:a25:7c41:: with SMTP id x62-v6mr17491421ybc.72.1541551355459; Tue, 06 Nov 2018 16:42:35 -0800 (PST) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id r13-v6sm11303621ywc.52.2018.11.06.16.42.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 06 Nov 2018 16:42:35 -0800 (PST) From: AKASHI Takahiro To: trini@konsulko.com, agraf@suse.de Date: Wed, 7 Nov 2018 09:44:34 +0900 Message-Id: <20181107004434.31491-2-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181107004434.31491-1-takahiro.akashi@linaro.org> References: <20181107004434.31491-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 Cc: xypron.glpk@gmx.de, u-boot@lists.denx.de Subject: [U-Boot] [PATCH 2/2] 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 | 8 +- include/efi_loader.h | 2 + lib/efi_loader/efi_disk.c | 150 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 159 insertions(+), 1 deletion(-) diff --git a/cmd/bootefi.c b/cmd/bootefi.c index 3cefb4d0ecaa..493022a09482 100644 --- a/cmd/bootefi.c +++ b/cmd/bootefi.c @@ -57,8 +57,14 @@ 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 != OBJ_LIST_NOT_INITIALIZED) { +#ifdef CONFIG_PARTITIONS + ret = efi_disk_update(); + if (ret != EFI_SUCCESS) + printf("+++ updating disks failed\n"); +#endif 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..e5a080281dba 100644 --- a/include/efi_loader.h +++ b/include/efi_loader.h @@ -260,6 +260,8 @@ 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); +/* 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..e1d47f34049b 100644 --- a/lib/efi_loader/efi_disk.c +++ b/lib/efi_loader/efi_disk.c @@ -14,10 +14,13 @@ const efi_guid_t efi_block_io_guid = BLOCK_IO_GUID; +#define _EFI_DISK_MARK_DELETE 0x1 + /** * 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 +33,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; @@ -440,3 +444,149 @@ efi_status_t efi_disk_register(void) return EFI_SUCCESS; } + +static void efi_disk_mark_delete(struct efi_disk_obj *disk) +{ + disk->flags |= _EFI_DISK_MARK_DELETE; +} + +static void efi_disk_mark_undelete(struct efi_disk_obj *disk) +{ + disk->flags &= ~_EFI_DISK_MARK_DELETE; +} + +static bool efi_disk_delete_marked(struct efi_disk_obj *disk) +{ + return disk->flags & _EFI_DISK_MARK_DELETE; +} + +static efi_status_t efi_disk_mark_delete_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_delete(disk); + } + + *handlesp = handles; + + return num; +} + +static int efi_disk_mark_undelete_handles(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_mark_undelete(disk); + disks++; + } + } + + return disks; +} + +static efi_status_t efi_disk_delete_all(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_delete_marked(disk)) + continue; + + efi_delete_handle(handles[i]); + } + + return EFI_SUCCESS; +} + +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; + + ret = efi_disk_mark_delete_all(&handles); + if (ret & EFI_ERROR_MASK) + return ret; + + n = (int)ret; + ret = EFI_SUCCESS; + for (uclass_first_device_check(UCLASS_BLK, &dev); dev; + uclass_next_device_check(&dev)) { + desc = dev_get_uclass_platdata(dev); + if (n && efi_disk_mark_undelete_handles(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) { + printf("ERROR: failure to add disk device %s, r = %lu\n", + dev->name, ret & ~EFI_ERROR_MASK); + break; + } + 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) { + if (ret != EFI_SUCCESS) + efi_disk_mark_undelete_handles(NULL, handles, n); + else + ret = efi_disk_delete_all(handles, n); + free(handles); + } + + return ret; +#else + return EFI_SUCCESS; +#endif +}