From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id AD3F5C433EF for ; Sun, 2 Jan 2022 09:18:39 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id B86E381761; Sun, 2 Jan 2022 10:18:36 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=gmx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; secure) header.d=gmx.net header.i=@gmx.net header.b="Q9Y9k8nz"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 75AB581761; Sun, 2 Jan 2022 10:18:34 +0100 (CET) Received: from mout.gmx.net (mout.gmx.net [212.227.15.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 31AA2801EB for ; Sun, 2 Jan 2022 10:18:22 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=xypron.glpk@gmx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1641115100; bh=xfySCibPBPyBjIu/ch1ruHJ69OCeTrmiJwxItAaDuik=; h=X-UI-Sender-Class:Date:Subject:To:Cc:References:From:In-Reply-To; b=Q9Y9k8nzOVkN3dClmOWU5zBMGRXBaoNshoYvPlVd0kspXUq2lRm93iaYGe/CI2/28 BkOFtUVSN/QKCf625AVWg5YVqO69eCXpV+p6pYZtqeIlG+hGJNq9u7OZES4su0tvH2 hODwqUrlRFQBiNMABCzeCT/gP23BN4Kf/XiCy0bk= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from [192.168.123.94] ([88.152.144.157]) by mail.gmx.net (mrgmx004 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MBDjA-1nGYSo14bm-00CjnQ; Sun, 02 Jan 2022 10:18:20 +0100 Message-ID: <380c0a2f-61af-c51d-e2c7-f0fc5758a494@gmx.de> Date: Sun, 2 Jan 2022 10:18:18 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.4.0 Subject: Re: [RFC v2 15/20] efi_loader: disk: a helper function to create efi_disk objects from udevice Content-Language: en-US To: AKASHI Takahiro Cc: masami.hiramatsu@linaro.org, u-boot@lists.denx.de, agraf@csgraf.de, sjg@chromium.org, ilias.apalodimas@linaro.org References: <20211210064947.73361-1-takahiro.akashi@linaro.org> <20211210064947.73361-16-takahiro.akashi@linaro.org> From: Heinrich Schuchardt In-Reply-To: <20211210064947.73361-16-takahiro.akashi@linaro.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:xx6dVemjd6OdGblJLrlpxUMPCiTDFfsCHtP4vIiAunnvjVinrrC VwEyFdPWNpPoRgVXsG10e4VB/1mqu1hyT9c4SorCCj5nRTnvp5kp8nlgIK3ZR/LNkbNYZig p7HB8b26AB16fBUyEQN6IvaxNBosEok5M1fixqvux/R+XQJ5CE+9gLxiwS8z3wCnzs1QWp4 VThE9X1N4soxOHdoAswHg== X-UI-Out-Filterresults: notjunk:1;V03:K0:4jm42+hVuEg=:8kpBAuxj3LcKGTmQTym4AP d+I2Xr3BMkSguHhoutQj15GWucYsH8+izsZ9xE8RoBU/cgr8/jnlpr8Z79ANUpsvTJyvRCEmh 1CgErgRpNfEY0YGjcjQwy2/RUYivDJKsY7YfOZeLjDptPUnjodL16ZpSg8VxmVAwJVxjRqqSz nZdrVKw+RJJ6fapHs1aBflw+oxZh4pkHTk5el4x/546jStgJJVHTUSATEzbbZ7OvMl4laaZG8 zWFa+ZLzA1xYTdEeRgTCl2DMY6FHF+7lmdQwF+xrGEscIKaEXU8MGC9oHWxTYLkUn5qQreWPm 7AJ8liTjlNaYCFJIIQ7uUJMaam2Ewh/ckJv+1DoI06smP/waIdvzKtEi1uWKNxKVcRR7WYulg UQkX11J6MEeL2mrc5e5JgNq8TA5XhZTefOYCR2sdt/9SfLoH87MJwHXoPPW2wQl9vO5wmuFKm T+QdMyUFnORsL5OMF+H4xU7gySY9NIc+Y8n6NPpQwh3HRNK5vsE+JtJavUiubwBMEvmAWyz/b HS6lhYd2eB7Fg/4k/FR0drVNX3akeAOw/JojLkzCHgDo1hcFQx1pPk3N4mk/M3tyRf2sYKwRH oxz3eVNc6GrM1bB+u3VOz7GWFc/wc3lW3m1tC0nk5DUebhcF14vD9qnrd2iE5bhjUcOtP0Vka nb1Di3/xychVM8J99Vi60GoeFtw8J16fiPd6tAR7MHSTp7PnwJuHGFzpthn+CRnMgxfv5TrhZ AI4cXv99Rc2tbt41ttzRJ3xu4w7z/JWOr3XY31310piocOerHXVIJMITC29TKphu/3Mc69ans HycejkMzrWdr05lV2fhVWBPgD6gQ33hDNV5xTpf9xwIq8GW2RgCo9Fk2781mKTmP2UV1N2DRU iqKZoAqwwzl1TVqbb+SPDVgyB1qwrbtcoQd2/qHUR13w9cz0GNQjMzaIOme7tcV4zuwFk4uuC 9h/Tb5YeJ4z976P6hDRSnuWdPsQP4h54pLgsyp+5O0qtnxje7UsMJFMNYDKepOblSf33M8wzF JEY/x74A7dDzwzdSSCA85XqztR9G8KNCefPuUC/pZ02lK6dO6pYxE+pcGutLRBclYAf/ynEMD e5jPm46Lay5U+c= X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.38 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" X-Virus-Scanned: clamav-milter 0.103.2 at phobos.denx.de X-Virus-Status: Clean On 12/10/21 07:49, AKASHI Takahiro wrote: > Add efi_disk_probe() function. > This function creates an efi_disk object for a raw disk device (UCLASS_B= LK) > and additional objects for related partitions (UCLASS_PARTITION). > > So this function is expected to be called through driver model's "probe" > interface every time one raw disk device is detected and activated. > We assume that partition devices (UCLASS_PARTITION) have been created > when this function is invoked. > > Signed-off-by: AKASHI Takahiro > --- > include/efi_loader.h | 4 +- > lib/efi_loader/Kconfig | 2 + > lib/efi_loader/efi_disk.c | 206 ++++++++++++++++++++++++------------- > lib/efi_loader/efi_setup.c | 11 +- > 4 files changed, 142 insertions(+), 81 deletions(-) > > diff --git a/include/efi_loader.h b/include/efi_loader.h > index d52e399841ba..a51095930efa 100644 > --- a/include/efi_loader.h > +++ b/include/efi_loader.h > @@ -519,8 +519,8 @@ efi_status_t EFIAPI efi_convert_pointer(efi_uintn_t = debug_disposition, > void efi_carve_out_dt_rsv(void *fdt); > /* Called by bootefi to make console interface available */ > 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 efi_init_obj_list() to initialize efi_disks */ > +efi_status_t efi_disk_init(void); > /* Called by efi_init_obj_list() to install EFI_RNG_PROTOCOL */ > efi_status_t efi_rng_register(void); > /* Called by efi_init_obj_list() to install EFI_TCG2_PROTOCOL */ > diff --git a/lib/efi_loader/Kconfig b/lib/efi_loader/Kconfig > index 700dc838ddb9..108c00343fce 100644 > --- a/lib/efi_loader/Kconfig > +++ b/lib/efi_loader/Kconfig > @@ -11,6 +11,7 @@ config EFI_LOADER > # We need EFI_STUB_32BIT to be set on x86_32 with EFI_STUB > depends on !EFI_STUB || !X86 || X86_64 || EFI_STUB_32BIT > depends on BLK > + depends on EVENT > depends on DM_ETH || !NET > depends on !EFI_APP > default y if !ARM || SYS_CPU =3D armv7 || SYS_CPU =3D armv8 > @@ -41,6 +42,7 @@ config CMD_BOOTEFI_BOOTMGR > > config EFI_SETUP_EARLY > bool > + default y > > choice > prompt "Store for non-volatile UEFI variables" > diff --git a/lib/efi_loader/efi_disk.c b/lib/efi_loader/efi_disk.c > index 45127d176869..2941b0c3db47 100644 > --- a/lib/efi_loader/efi_disk.c > +++ b/lib/efi_loader/efi_disk.c > @@ -10,6 +10,9 @@ > #include > #include > #include > +#include > +#include > +#include > #include > #include > #include > @@ -487,103 +490,158 @@ error: > return ret; > } > > -/** > - * efi_disk_create_partitions() - create handles and protocols for part= itions > +/* > + * Create a handle for a whole raw disk > * > - * Create handles and protocols for the partitions of a block device. > + * @dev uclass device (UCLASS_BLK) > * > - * @parent: handle of the parent disk > - * @desc: block device > - * @if_typename: interface type > - * @diskid: device number > - * @pdevname: device name > - * Return: number of partitions created > + * Create an efi_disk object which is associated with @dev. > + * The type of @dev must be UCLASS_BLK. > + * > + * @return 0 on success, -1 otherwise > */ > -int efi_disk_create_partitions(efi_handle_t parent, struct blk_desc *de= sc, > - const char *if_typename, int diskid, > - const char *pdevname) > +static int efi_disk_create_raw(struct udevice *dev) > { > - int disks =3D 0; > - char devname[32] =3D { 0 }; /* dp->str is u16[32] long */ > - int part; > - struct efi_device_path *dp =3D NULL; > + struct efi_disk_obj *disk; > + struct blk_desc *desc; > + const char *if_typename; > + int diskid; > efi_status_t ret; > - struct efi_handler *handler; > > - /* Get the device path of the parent */ > - ret =3D efi_search_protocol(parent, &efi_guid_device_path, &handler); > - if (ret =3D=3D EFI_SUCCESS) > - dp =3D handler->protocol_interface; > - > - /* Add devices for each partition */ > - for (part =3D 1; part <=3D MAX_SEARCH_PARTITIONS; part++) { > - struct disk_partition info; > - > - if (part_get_info(desc, part, &info)) > - continue; > - snprintf(devname, sizeof(devname), "%s:%x", pdevname, > - part); > - ret =3D efi_disk_add_dev(parent, dp, if_typename, desc, diskid, > - &info, part, NULL); > - if (ret !=3D EFI_SUCCESS) { > - log_err("Adding partition %s failed\n", pdevname); > - continue; > - } > - disks++; > + desc =3D dev_get_uclass_plat(dev); > + if_typename =3D blk_get_if_type_name(desc->if_type); > + diskid =3D desc->devnum; > + > + ret =3D efi_disk_add_dev(NULL, NULL, if_typename, desc, > + diskid, NULL, 0, &disk); > + if (ret !=3D EFI_SUCCESS) { > + if (ret =3D=3D EFI_NOT_READY) > + log_notice("Disk %s not ready\n", dev->name); > + else > + log_err("Adding disk for %s failed\n", dev->name); > + > + return -1; > + } > + disk->dev =3D dev; > + if (dev_tag_set_ptr(dev, DM_TAG_EFI, &disk->header)) { > + efi_free_pool(disk->dp); > + efi_delete_handle(&disk->header); > + > + return -1; > } > > - return disks; > + return 0; > } > > -/** > - * efi_disk_register() - register block devices > - * > - * U-Boot doesn't have a list of all online disk devices. So when runni= ng our > - * EFI payload, we scan through all of the potentially available ones a= nd > - * store them in our object pool. > +/* > + * Create a handle for a disk partition > * > - * This function is called in efi_init_obj_list(). > + * @dev uclass device (UCLASS_PARTITION) > * > - * TODO(sjg@chromium.org): Actually with CONFIG_BLK, U-Boot does have t= his. > - * Consider converting the code to look up devices as needed. The EFI d= evice > - * could be a child of the UCLASS_BLK block device, perhaps. > + * Create an efi_disk object which is associated with @dev. > + * The type of @dev must be UCLASS_PARTITION. > * > - * Return: status code > + * @return 0 on success, -1 otherwise > */ > -efi_status_t efi_disk_register(void) > +static int efi_disk_create_part(struct udevice *dev) > { > + efi_handle_t parent; > + struct blk_desc *desc; > + const char *if_typename; > + struct disk_part *part_data; > + struct disk_partition *info; > + unsigned int part; > + int diskid; > + struct efi_handler *handler; > + struct efi_device_path *dp_parent; > struct efi_disk_obj *disk; > - int disks =3D 0; > efi_status_t ret; > + > + if (dev_tag_get_ptr(dev_get_parent(dev), DM_TAG_EFI, (void **)&parent)= ) > + return -1; > + > + desc =3D dev_get_uclass_plat(dev_get_parent(dev)); > + if_typename =3D blk_get_if_type_name(desc->if_type); > + diskid =3D desc->devnum; > + > + part_data =3D dev_get_uclass_plat(dev); > + part =3D part_data->partnum; > + info =3D &part_data->gpt_part_info; > + > + ret =3D efi_search_protocol(parent, &efi_guid_device_path, &handler); > + if (ret !=3D EFI_SUCCESS) > + return -1; > + dp_parent =3D (struct efi_device_path *)handler->protocol_interface; > + > + ret =3D efi_disk_add_dev(parent, dp_parent, if_typename, desc, diskid, > + info, part, &disk); > + if (ret !=3D EFI_SUCCESS) { > + log_err("Adding partition for %s failed\n", dev->name); > + return -1; > + } > + disk->dev =3D dev; > + if (dev_tag_set_ptr(dev, DM_TAG_EFI, &disk->header)) { > + efi_free_pool(disk->dp); > + efi_delete_handle(&disk->header); > + > + return -1; > + } > + > + return 0; > +} > + > +/* > + * Create efi_disk objects for a block device > + * > + * @dev uclass device (UCLASS_BLK) > + * > + * Create efi_disk objects for partitions as well as a raw disk > + * which is associated with @dev. > + * The type of @dev must be UCLASS_BLK. > + * This function is expected to be called at EV_PM_POST_PROBE. > + * > + * @return 0 on success, -1 otherwise > + */ > +static int efi_disk_probe(void *ctx, struct event *event) > +{ > struct udevice *dev; > + enum uclass_id id; > + struct udevice *child; > + int ret; > > - for (uclass_first_device_check(UCLASS_BLK, &dev); dev; > - uclass_next_device_check(&dev)) { > - struct blk_desc *desc =3D dev_get_uclass_plat(dev); > - const char *if_typename =3D blk_get_if_type_name(desc->if_type); > + dev =3D event->data.dm.dev; > + id =3D device_get_uclass_id(dev); > > - /* Add block device for the full device */ > - log_info("Scanning disk %s...\n", dev->name); > - ret =3D efi_disk_add_dev(NULL, NULL, if_typename, > - desc, desc->devnum, NULL, 0, &disk); > - if (ret =3D=3D EFI_NOT_READY) { > - log_notice("Disk %s not ready\n", dev->name); > - continue; > - } > - if (ret) { > - log_err("ERROR: failure to add disk device %s, r =3D %lu\n", > - dev->name, ret & ~EFI_ERROR_MASK); > - continue; > - } > - disks++; > + /* TODO: We won't support partitions in a partition */ > + if (id !=3D UCLASS_BLK) { > + if (id !=3D UCLASS_PARTITION) > + log_info("Not a block device: %s\n", dev->name); I get the following messages on the sandbox: Not a block device: pinmux_i2c0_pins Not a block device: i2c@0 Not a block device: rtc@61 Not a block device: bootcount@0 Not a block device: emul Not a block device: emull Why do you create these? Best regards Heinrich > + return 0; > + } > + > + ret =3D efi_disk_create_raw(dev); > + if (ret) > + return -1; > > - /* Partitions show up as block devices in EFI */ > - disks +=3D efi_disk_create_partitions( > - &disk->header, desc, if_typename, > - desc->devnum, dev->name); > + device_foreach_child(child, dev) { > + ret =3D efi_disk_create_part(child); > + if (ret) > + return -1; > } > > - log_info("Found %d disks\n", disks); > + return 0; > +} > + > +efi_status_t efi_disk_init(void) > +{ > + int ret; > + > + ret =3D event_register("efi_disk add", EVT_DM_POST_PROBE, > + efi_disk_probe, NULL); > + if (ret) { > + log_err("Event registration for efi_disk add failed\n"); > + return EFI_OUT_OF_RESOURCES; > + } > > return EFI_SUCCESS; > } > diff --git a/lib/efi_loader/efi_setup.c b/lib/efi_loader/efi_setup.c > index 1aba71cd9624..1c912b0157aa 100644 > --- a/lib/efi_loader/efi_setup.c > +++ b/lib/efi_loader/efi_setup.c > @@ -200,11 +200,12 @@ efi_status_t efi_init_obj_list(void) > if (ret !=3D EFI_SUCCESS) > goto out; > > -#ifdef CONFIG_PARTITIONS > - ret =3D efi_disk_register(); > - if (ret !=3D EFI_SUCCESS) > - goto out; > -#endif > + if (IS_ENABLED(CONFIG_BLK)) { > + ret =3D efi_disk_init(); > + if (ret !=3D EFI_SUCCESS) > + goto out; > + } > + > if (IS_ENABLED(CONFIG_EFI_RNG_PROTOCOL)) { > ret =3D efi_rng_register(); > if (ret !=3D EFI_SUCCESS)