[PATCH v5 02/28] efi: Add EFI uclass for media

2021-12-04 Thread Simon Glass
At present UCLASS_EFI is used to represent an EFI filesystem among other
things. The description of this uclass is "EFI managed devices" which is
pretty vague. The only driver that uses this uclass is in fact not a real
U-Boot driver, since its operations do not include a struct udevice.

Rather than mess with this, create a new UCLASS_EFI_MEDIA uclass to handle
EFI media such as disks. Make this the uclass to use for EFI media so that
it can be used with 'part list', for example.

The existing implementation using UCLASS_EFI remains as is, for
discussion.

Signed-off-by: Simon Glass 
---

(no changes since v2)

Changes in v2:
- Add MAINTAINERS entry
- Show the correct interface type with 'part list'
- Update the commit message to explain things better

 MAINTAINERS  |  3 +++
 arch/sandbox/dts/test.dts|  4 
 disk/part.c  |  5 -
 drivers/block/Kconfig| 23 +++
 drivers/block/Makefile   |  3 +++
 drivers/block/blk-uclass.c   |  2 ++
 drivers/block/efi-media-uclass.c | 15 +++
 drivers/block/sb_efi_media.c | 20 
 include/blk.h|  1 +
 include/dm/uclass-id.h   |  1 +
 test/dm/Makefile |  1 +
 test/dm/efi_media.c  | 24 
 12 files changed, 101 insertions(+), 1 deletion(-)
 create mode 100644 drivers/block/efi-media-uclass.c
 create mode 100644 drivers/block/sb_efi_media.c
 create mode 100644 test/dm/efi_media.c

diff --git a/MAINTAINERS b/MAINTAINERS
index 9045e509d73..5b162ad2978 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -714,8 +714,11 @@ W: 
https://u-boot.readthedocs.io/en/latest/develop/uefi/u-boot_on_efi.html
 F: board/efi/efi-x86_app
 F: configs/efi-x86_app*
 F: doc/develop/uefi/u-boot_on_efi.rst
+F: drivers/block/efi-media-uclass.c
+F: drivers/block/sb_efi_media.c
 F: lib/efi/efi_app.c
 F: scripts/build-efi.sh
+F: test/dm/efi_media.c
 
 EFI PAYLOAD
 M: Heinrich Schuchardt 
diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts
index e5261bb9fa2..48ca3e1e472 100644
--- a/arch/sandbox/dts/test.dts
+++ b/arch/sandbox/dts/test.dts
@@ -499,6 +499,10 @@
compatible = "sandbox,clk-ccf";
};
 
+   efi-media {
+   compatible = "sandbox,efi-media";
+   };
+
eth@10002000 {
compatible = "sandbox,eth";
reg = <0x10002000 0x1000>;
diff --git a/disk/part.c b/disk/part.c
index fe1ebd4adf7..e857a9f9585 100644
--- a/disk/part.c
+++ b/disk/part.c
@@ -296,8 +296,11 @@ static void print_part_header(const char *type, struct 
blk_desc *dev_desc)
case IF_TYPE_VIRTIO:
puts("VirtIO");
break;
+   case IF_TYPE_EFI_MEDIA:
+   puts("EFI");
+   break;
default:
-   puts ("UNKNOWN");
+   puts("UNKNOWN");
break;
}
printf (" device %d  --   Partition Type: %s\n\n",
diff --git a/drivers/block/Kconfig b/drivers/block/Kconfig
index 56a4eec05ac..755fdccb574 100644
--- a/drivers/block/Kconfig
+++ b/drivers/block/Kconfig
@@ -61,6 +61,29 @@ config TPL_BLOCK_CACHE
help
  This option enables the disk-block cache in TPL
 
+config EFI_MEDIA
+   bool "Support EFI media drivers"
+   default y if EFI || SANDBOX
+   help
+ Enable this to support media devices on top of UEFI. This enables
+ just the uclass so you also need a specific driver to make this do
+ anything.
+
+ For sandbox there is a test driver.
+
+if EFI_MEDIA
+
+config EFI_MEDIA_SANDBOX
+   bool "Sandbox EFI media driver"
+   depends on SANDBOX
+   default y
+   help
+ Enables a simple sandbox media driver, used for testing just the
+ EFI_MEDIA uclass. It does not do anything useful, since sandbox does
+ not actually support running on top of UEFI.
+
+endif  # EFI_MEDIA
+
 config IDE
bool "Support IDE controllers"
select HAVE_BLOCK_DEVICE
diff --git a/drivers/block/Makefile b/drivers/block/Makefile
index 94ab5c6f906..3778633da1d 100644
--- a/drivers/block/Makefile
+++ b/drivers/block/Makefile
@@ -14,3 +14,6 @@ obj-$(CONFIG_IDE) += ide.o
 endif
 obj-$(CONFIG_SANDBOX) += sandbox.o
 obj-$(CONFIG_$(SPL_TPL_)BLOCK_CACHE) += blkcache.o
+
+obj-$(CONFIG_EFI_MEDIA) += efi-media-uclass.o
+obj-$(CONFIG_EFI_MEDIA_SANDBOX) += sb_efi_media.o
diff --git a/drivers/block/blk-uclass.c b/drivers/block/blk-uclass.c
index a7470ae28d5..4ae8af6d609 100644
--- a/drivers/block/blk-uclass.c
+++ b/drivers/block/blk-uclass.c
@@ -28,6 +28,7 @@ static const char *if_typename_str[IF_TYPE_COUNT] = {
[IF_TYPE_SATA]  = "sata",
[IF_TYPE_HOST]  = "host",
[IF_TYPE_NVME]  = "nvme",
+   [IF_TYPE_EFI_MEDIA] = "efi",
[IF_TYPE_EFI_LOADER]= "efiloader",
[IF_TYPE_VIRTIO]   

Re: [PATCH v5 02/28] efi: Add EFI uclass for media

2021-12-09 Thread Heinrich Schuchardt

On 12/4/21 07:56, Simon Glass wrote:

At present UCLASS_EFI is used to represent an EFI filesystem among other


%s/UCLASS_EFI/UCLASS_EFI_LOADER/


things. The description of this uclass is "EFI managed devices" which is
pretty vague. The only driver that uses this uclass is in fact not a real
U-Boot driver, since its operations do not include a struct udevice.

Rather than mess with this, create a new UCLASS_EFI_MEDIA uclass to handle
EFI media such as disks. Make this the uclass to use for EFI media so that


The new uclass is for devices provided by an UEFI implementation loading
U-Boot as an EFI application.


it can be used with 'part list', for example.

The existing implementation using UCLASS_EFI remains as is, for


%s/UCLASS_EFI/UCLASS_EFI_LOADER/

The existing uclass is for devices created by UEFI applications loaded
by U-Boot.



discussion.

Signed-off-by: Simon Glass 
---

(no changes since v2)

Changes in v2:
- Add MAINTAINERS entry
- Show the correct interface type with 'part list'
- Update the commit message to explain things better

  MAINTAINERS  |  3 +++
  arch/sandbox/dts/test.dts|  4 
  disk/part.c  |  5 -
  drivers/block/Kconfig| 23 +++
  drivers/block/Makefile   |  3 +++
  drivers/block/blk-uclass.c   |  2 ++
  drivers/block/efi-media-uclass.c | 15 +++
  drivers/block/sb_efi_media.c | 20 
  include/blk.h|  1 +
  include/dm/uclass-id.h   |  1 +
  test/dm/Makefile |  1 +
  test/dm/efi_media.c  | 24 
  12 files changed, 101 insertions(+), 1 deletion(-)
  create mode 100644 drivers/block/efi-media-uclass.c
  create mode 100644 drivers/block/sb_efi_media.c
  create mode 100644 test/dm/efi_media.c

diff --git a/MAINTAINERS b/MAINTAINERS
index 9045e509d73..5b162ad2978 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -714,8 +714,11 @@ W: 
https://u-boot.readthedocs.io/en/latest/develop/uefi/u-boot_on_efi.html
  F:board/efi/efi-x86_app
  F:configs/efi-x86_app*
  F:doc/develop/uefi/u-boot_on_efi.rst
+F: drivers/block/efi-media-uclass.c
+F: drivers/block/sb_efi_media.c
  F:lib/efi/efi_app.c
  F:scripts/build-efi.sh
+F: test/dm/efi_media.c

  EFI PAYLOAD
  M:Heinrich Schuchardt 
diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts
index e5261bb9fa2..48ca3e1e472 100644
--- a/arch/sandbox/dts/test.dts
+++ b/arch/sandbox/dts/test.dts
@@ -499,6 +499,10 @@
compatible = "sandbox,clk-ccf";
};

+   efi-media {
+   compatible = "sandbox,efi-media";
+   };
+
eth@10002000 {
compatible = "sandbox,eth";
reg = <0x10002000 0x1000>;
diff --git a/disk/part.c b/disk/part.c
index fe1ebd4adf7..e857a9f9585 100644
--- a/disk/part.c
+++ b/disk/part.c
@@ -296,8 +296,11 @@ static void print_part_header(const char *type, struct 
blk_desc *dev_desc)
case IF_TYPE_VIRTIO:
puts("VirtIO");
break;
+   case IF_TYPE_EFI_MEDIA:
+   puts("EFI");
+   break;
default:
-   puts ("UNKNOWN");
+   puts("UNKNOWN");
break;
}
printf (" device %d  --   Partition Type: %s\n\n",
diff --git a/drivers/block/Kconfig b/drivers/block/Kconfig
index 56a4eec05ac..755fdccb574 100644
--- a/drivers/block/Kconfig
+++ b/drivers/block/Kconfig
@@ -61,6 +61,29 @@ config TPL_BLOCK_CACHE
help
  This option enables the disk-block cache in TPL

+config EFI_MEDIA
+   bool "Support EFI media drivers"
+   default y if EFI || SANDBOX
+   help
+ Enable this to support media devices on top of UEFI. This enables
+ just the uclass so you also need a specific driver to make this do
+ anything.
+
+ For sandbox there is a test driver.
+
+if EFI_MEDIA
+
+config EFI_MEDIA_SANDBOX
+   bool "Sandbox EFI media driver"
+   depends on SANDBOX
+   default y
+   help
+ Enables a simple sandbox media driver, used for testing just the
+ EFI_MEDIA uclass. It does not do anything useful, since sandbox does
+ not actually support running on top of UEFI.
+
+endif  # EFI_MEDIA
+
  config IDE
bool "Support IDE controllers"
select HAVE_BLOCK_DEVICE
diff --git a/drivers/block/Makefile b/drivers/block/Makefile
index 94ab5c6f906..3778633da1d 100644
--- a/drivers/block/Makefile
+++ b/drivers/block/Makefile
@@ -14,3 +14,6 @@ obj-$(CONFIG_IDE) += ide.o
  endif
  obj-$(CONFIG_SANDBOX) += sandbox.o
  obj-$(CONFIG_$(SPL_TPL_)BLOCK_CACHE) += blkcache.o
+
+obj-$(CONFIG_EFI_MEDIA) += efi-media-uclass.o
+obj-$(CONFIG_EFI_MEDIA_SANDBOX) += sb_efi_media.o
diff --git a/drivers/block/blk-uclass.c b/drivers/block/blk-uclass.c
index a7470ae28d5..4ae8af6d609 100644
--- a/drivers/block/blk-uclass.c
+++ b/drivers/block/blk-ucla