Re: [PATCH 0/3] efi_selftest: Update SIMPLE_NETWORK_PROTOCOL selftest

2021-10-03 Thread Masami Hiramatsu
Hi Heinrich,

What is the current status of this patch series?
Could you give me any comments?

Thank you,

2021年9月17日(金) 13:47 Masami Hiramatsu :
>
> Hi Heinrich,
>
> 2021年9月17日(金) 12:54 Heinrich Schuchardt :
> >
> > On 9/16/21 10:53 AM, Masami Hiramatsu wrote:
> > > Hello Heinrich,
> > >
> > > Here is a series of patches to update the SIMPLE_NETWORK_PROTOCOL
> > > according to the explanation in the previous thread [1].
> > >
> > > [1] https://lists.denx.de/pipermail/u-boot/2021-September/460711.html
> > >
> > > So basically this seires modifies the SNP testcase as I said
> > > in the previous mail [1].
> > >
> > > 
> > > net->get_status();
> > > if (!net->mode.MediaPresent) {
> > > error(no link up!)
> > > return;
> > > }
> > >
> > > submit_dhcp_discover()
> > > for (;;) {
> > > wait_for_event(net)
> > > while (net->receive() != EFI_NOT_READY) {
> > >// check dhcp reply
> > > }
> > > }
> > > 
> > >
> > > I removed EFI_SIMPLE_NETWORK_RECEIVE_INTERRUPT check because
> > > that is just expectation what the received packet avaiability
> > > is meaning that the EFI_SIMPLE_NETWORK_RECEIVE_INTERRUPT flag
> > > bit is set. Of course U-Boot EFI SNP implementation does it,
> > > but that is not ensured in the UEFI spec. The spec said that
> >
> > SN_GetStatus() in edk2-platforms
> > Drivers/ASIX/Bus/Usb/UsbNetworking/Ax88179/SimpleNetwork.c always
> > returns *InterruptStatus = 0.
>
> Yes, it seems to depend on driver implementation.
>
> >
> > > the get_status() should update the MediaPresent flag (which
> > > means the network link up or down). So I added the get_status()
> > > test case before starting the network test so that it can
> > > test the link status.
> > >
> > > BTW, actually the mode->media_present is not supported yet.
> > > Is there any way to get the network link status?
> >
> > The driver interface struct eth_ops has no method for determining media
> > presence. We have to assume that it is always present.
>
> Hmm, OK. So we can not implement it...
>
> Thank you,
>
> >
> > Best regards
> >
> > Heinrich
> >
> > >
> > > Thank you,
> > >
> > > ---
> > >
> > > Masami Hiramatsu (3):
> > >efi_selftest: Use EFI_SIMPLE_NETWORK_PROTOCOL::GetStatus() for 
> > > media check
> > >efi_selftest: Do not check EFI_SIMPLE_NETWORK_RECEIVE_INTERRUPT
> > >efi_selftest: Recieve the packets until the receive buffer is empty
> > >
> > >
> > >   lib/efi_selftest/efi_selftest_snp.c |   90 
> > > +++
> > >   1 file changed, 49 insertions(+), 41 deletions(-)
> > >
> > > --
> > > Masami Hiramatsu 
> > >
> >
>
>
> --
> Masami Hiramatsu



-- 
Masami Hiramatsu


[resent RFC 22/22] efi_selftest: block device: adjust dp for a test disk

2021-10-03 Thread AKASHI Takahiro
Due to efi_disk-dm integration, the resultant device path for a test disk
got slightly changed, with efi_root contained as the first component.

Signed-off-by: AKASHI Takahiro 
---
 lib/efi_selftest/efi_selftest_block_device.c | 26 ++--
 1 file changed, 24 insertions(+), 2 deletions(-)

diff --git a/lib/efi_selftest/efi_selftest_block_device.c 
b/lib/efi_selftest/efi_selftest_block_device.c
index 15f03751ac87..cac76249e6b4 100644
--- a/lib/efi_selftest/efi_selftest_block_device.c
+++ b/lib/efi_selftest/efi_selftest_block_device.c
@@ -30,6 +30,9 @@ static const efi_guid_t guid_device_path = 
EFI_DEVICE_PATH_PROTOCOL_GUID;
 static const efi_guid_t guid_simple_file_system_protocol =
EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID;
 static const efi_guid_t guid_file_system_info = EFI_FILE_SYSTEM_INFO_GUID;
+static efi_guid_t guid_uboot =
+   EFI_GUID(0xe61d73b9, 0xa384, 0x4acc, \
+0xae, 0xab, 0x82, 0xe8, 0x28, 0xf3, 0x62, 0x8b);
 static efi_guid_t guid_vendor =
EFI_GUID(0xdbca4c98, 0x6cb0, 0x694d,
 0x08, 0x72, 0x81, 0x9c, 0x65, 0x0c, 0xb7, 0xb8);
@@ -206,25 +209,44 @@ static int setup(const efi_handle_t handle,
 
ret = boottime->allocate_pool(EFI_LOADER_DATA,
  sizeof(struct efi_device_path_vendor) +
+ sizeof(struct efi_device_path_vendor) +
+ sizeof(u8) +
  sizeof(struct efi_device_path),
  (void **));
if (ret != EFI_SUCCESS) {
efi_st_error("Out of memory\n");
return EFI_ST_FAILURE;
}
+   /* first part */
vendor_node.dp.type = DEVICE_PATH_TYPE_HARDWARE_DEVICE;
vendor_node.dp.sub_type = DEVICE_PATH_SUB_TYPE_VENDOR;
vendor_node.dp.length = sizeof(struct efi_device_path_vendor);
 
-   boottime->copy_mem(_node.guid, _vendor,
+   boottime->copy_mem(_node.guid, _uboot,
   sizeof(efi_guid_t));
boottime->copy_mem(dp, _node,
   sizeof(struct efi_device_path_vendor));
+
+   /* second part */
+   vendor_node.dp.type = DEVICE_PATH_TYPE_HARDWARE_DEVICE;
+   vendor_node.dp.sub_type = DEVICE_PATH_SUB_TYPE_VENDOR;
+   vendor_node.dp.length = sizeof(struct efi_device_path_vendor) + 1;
+
+   boottime->copy_mem(_node.guid, _vendor,
+  sizeof(efi_guid_t));
+   boottime->copy_mem((char *)dp + sizeof(struct efi_device_path_vendor),
+  _node,
+  sizeof(struct efi_device_path_vendor));
+   /* vendor_data[0] */
+   *((char *)dp + sizeof(struct efi_device_path_vendor) * 2) = 0;
+
end_node.type = DEVICE_PATH_TYPE_END;
end_node.sub_type = DEVICE_PATH_SUB_TYPE_END;
end_node.length = sizeof(struct efi_device_path);
 
-   boottime->copy_mem((char *)dp + sizeof(struct efi_device_path_vendor),
+   boottime->copy_mem((char *)dp + sizeof(struct efi_device_path_vendor)
+  + sizeof(struct efi_device_path_vendor)
+  + sizeof(u8),
   _node, sizeof(struct efi_device_path));
ret = boottime->install_protocol_interface(_handle,
   _device_path,
-- 
2.33.0



[resent RFC 21/22] efi_driver: cleanup after efi_disk-dm integration

2021-10-03 Thread AKASHI Takahiro
efi_driver-specific binding will be no longer needed now that efi_disk-
dm integration takes care of efi_driver case as well.

Signed-off-by: AKASHI Takahiro 
---
 lib/efi_driver/efi_block_device.c | 24 
 1 file changed, 24 deletions(-)

diff --git a/lib/efi_driver/efi_block_device.c 
b/lib/efi_driver/efi_block_device.c
index b6afa939e1d1..1f39c93f7754 100644
--- a/lib/efi_driver/efi_block_device.c
+++ b/lib/efi_driver/efi_block_device.c
@@ -106,25 +106,6 @@ static ulong efi_bl_write(struct udevice *dev, lbaint_t 
blknr, lbaint_t blkcnt,
return blkcnt;
 }
 
-/**
- * Create partions for the block device.
- *
- * @handle:EFI handle of the block device
- * @dev:   udevice of the block device
- * Return: number of partitions created
- */
-static int efi_bl_bind_partitions(efi_handle_t handle, struct udevice *dev)
-{
-   struct blk_desc *desc;
-   const char *if_typename;
-
-   desc = dev_get_uclass_plat(dev);
-   if_typename = blk_get_if_type_name(desc->if_type);
-
-   return efi_disk_create_partitions(handle, desc, if_typename,
- desc->devnum, dev->name);
-}
-
 /**
  * Create a block device for a handle
  *
@@ -139,7 +120,6 @@ static int efi_bl_bind(efi_handle_t handle, void *interface)
char *name;
struct efi_object *obj = efi_search_obj(handle);
struct efi_block_io *io = interface;
-   int disks;
struct efi_blk_plat *plat;
 
EFI_PRINT("%s: handle %p, interface %p\n", __func__, handle, io);
@@ -184,10 +164,6 @@ static int efi_bl_bind(efi_handle_t handle, void 
*interface)
return ret;
EFI_PRINT("%s: block device '%s' created\n", __func__, bdev->name);
 
-   /* Create handles for the partions of the block device */
-   disks = efi_bl_bind_partitions(handle, bdev);
-   EFI_PRINT("Found %d partitions\n", disks);
-
return 0;
 }
 
-- 
2.33.0



[resent RFC 20/22] efi_driver: align with efi_disk-dm integration

2021-10-03 Thread AKASHI Takahiro
Signed-off-by: AKASHI Takahiro 
---
 lib/efi_driver/efi_block_device.c |  6 ++
 lib/efi_loader/efi_device_path.c  | 29 +
 lib/efi_loader/efi_disk.c | 12 +++-
 3 files changed, 46 insertions(+), 1 deletion(-)

diff --git a/lib/efi_driver/efi_block_device.c 
b/lib/efi_driver/efi_block_device.c
index 0937e3595a43..b6afa939e1d1 100644
--- a/lib/efi_driver/efi_block_device.c
+++ b/lib/efi_driver/efi_block_device.c
@@ -173,6 +173,12 @@ static int efi_bl_bind(efi_handle_t handle, void 
*interface)
plat->handle = handle;
plat->io = interface;
 
+   /*
+* FIXME: necessary because we won't do almost nothing in
+* efi_disk_create() when called from device_probe().
+*/
+   bdev->efi_obj = handle;
+
ret = device_probe(bdev);
if (ret)
return ret;
diff --git a/lib/efi_loader/efi_device_path.c b/lib/efi_loader/efi_device_path.c
index cbdb466da41c..36c77bce9a05 100644
--- a/lib/efi_loader/efi_device_path.c
+++ b/lib/efi_loader/efi_device_path.c
@@ -628,6 +628,35 @@ __maybe_unused static void *dp_fill(void *buf, struct 
udevice *dev)
return >vendor_data[1];
}
 #endif
+#ifdef CONFIG_EFI_LOADER
+   /*
+* FIXME: conflicting with CONFIG_SANDBOX
+* This case is necessary to support efi_disk's created by
+* efi_driver (and efi_driver_binding_protocol).
+* TODO:
+* The best way to work around here is to create efi_root as
+* udevice and put all efi_driver objects under it.
+*/
+   case UCLASS_ROOT: {
+   struct efi_device_path_vendor *dp;
+   struct blk_desc *desc = dev_get_uclass_plat(dev);
+   /* FIXME: guid_vendor used in selftest_block_device */
+   static efi_guid_t guid_vendor =
+   EFI_GUID(0xdbca4c98, 0x6cb0, 0x694d,
+   0x08, 0x72, 0x81, 0x9c, 0x65, 0x0c, 0xb7, 0xb8);
+
+
+   dp_fill(buf, dev->parent);
+   dp = buf;
+   ++dp;
+   dp->dp.type = DEVICE_PATH_TYPE_HARDWARE_DEVICE;
+   dp->dp.sub_type = DEVICE_PATH_SUB_TYPE_VENDOR;
+   dp->dp.length = sizeof(*dp) + 1;
+   memcpy(>guid, _vendor, sizeof(efi_guid_t));
+   dp->vendor_data[0] = desc->devnum;
+   return >vendor_data[1];
+   }
+#endif
 #ifdef CONFIG_VIRTIO_BLK
case UCLASS_VIRTIO: {
struct efi_device_path_vendor *dp;
diff --git a/lib/efi_loader/efi_disk.c b/lib/efi_loader/efi_disk.c
index dfd06dd31e4a..e7cf1567929b 100644
--- a/lib/efi_loader/efi_disk.c
+++ b/lib/efi_loader/efi_disk.c
@@ -562,11 +562,21 @@ static int efi_disk_create_part(struct udevice *dev)
 int efi_disk_create(struct udevice *dev)
 {
enum uclass_id id;
+   struct blk_desc *desc;
 
id = device_get_uclass_id(dev);
 
-   if (id == UCLASS_BLK)
+   if (id == UCLASS_BLK) {
+   /*
+* avoid creating duplicated objects now that efi_driver
+* has already created an efi_disk at this moment.
+*/
+   desc = dev_get_uclass_plat(dev);
+   if (desc->if_type == IF_TYPE_EFI)
+   return 0;
+
return efi_disk_create_raw(dev);
+   }
 
if (id == UCLASS_PARTITION)
return efi_disk_create_part(dev);
-- 
2.33.0



[resent RFC 19/22] dm: blk: call efi's device-removal hook

2021-10-03 Thread AKASHI Takahiro
Adding the callback function, efi_disk_delete(), in block devices's
pre_remove hook will allows for automatically deleting efi_disk objects
per block device.

This will eliminate any improper efi_disk objects which hold a link to
non-existing udevice structures when associated block devices are physically
un-plugged or udevices are once removed (and re-created) by executing commands
like "scsi rescan."

Signed-off-by: AKASHI Takahiro 
---
 drivers/block/blk-uclass.c | 22 ++
 1 file changed, 22 insertions(+)

diff --git a/drivers/block/blk-uclass.c b/drivers/block/blk-uclass.c
index ce45cf0a8768..b8ad267c6c61 100644
--- a/drivers/block/blk-uclass.c
+++ b/drivers/block/blk-uclass.c
@@ -847,6 +847,16 @@ static int blk_post_probe(struct udevice *dev)
return 0;
 }
 
+static int blk_pre_remove(struct udevice *dev)
+{
+   if (CONFIG_IS_ENABLED(EFI_LOADER)) {
+   if (efi_disk_delete(dev))
+   debug("*** efi_pre_remove_device failed\n");
+   }
+
+   return 0;
+}
+
 static int blk_part_post_probe(struct udevice *dev)
 {
if (CONFIG_IS_ENABLED(EFI_LOADER)) {
@@ -861,10 +871,21 @@ static int blk_part_post_probe(struct udevice *dev)
return 0;
 }
 
+static int blk_part_pre_remove(struct udevice *dev)
+{
+   if (CONFIG_IS_ENABLED(EFI_LOADER)) {
+   if (efi_disk_delete(dev))
+   debug("*** efi_pre_remove_device failed\n");
+   }
+
+   return 0;
+}
+
 UCLASS_DRIVER(blk) = {
.id = UCLASS_BLK,
.name   = "blk",
.post_probe = blk_post_probe,
+   .pre_remove = blk_pre_remove,
.per_device_plat_auto   = sizeof(struct blk_desc),
 };
 
@@ -937,6 +958,7 @@ U_BOOT_DRIVER(blk_partition) = {
 UCLASS_DRIVER(partition) = {
.id = UCLASS_PARTITION,
.post_probe = blk_part_post_probe,
+   .pre_remove = blk_part_pre_remove,
.per_device_plat_auto   = sizeof(struct disk_part),
.name   = "partition",
 };
-- 
2.33.0



[resent RFC 18/22] efi_loader: efi_disk: a helper function to delete efi_disk objects

2021-10-03 Thread AKASHI Takahiro
This function is expected to be called, in particular from dm's pre_remove
hook, when associated block devices no longer exist.

Signed-off-by: AKASHI Takahiro 
---
 include/efi_loader.h  |  2 ++
 lib/efi_loader/efi_disk.c | 54 +++
 2 files changed, 56 insertions(+)

diff --git a/include/efi_loader.h b/include/efi_loader.h
index 50f4119dcdfb..7079549bea70 100644
--- a/include/efi_loader.h
+++ b/include/efi_loader.h
@@ -519,6 +519,8 @@ void efi_carve_out_dt_rsv(void *fdt);
 efi_status_t efi_console_register(void);
 /* Called when a block devices has been probed */
 int efi_disk_create(struct udevice *dev);
+/* Called when a block devices is to be removed */
+int efi_disk_delete(struct udevice *dev);
 /* 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/efi_disk.c b/lib/efi_loader/efi_disk.c
index 74ef923d1d67..dfd06dd31e4a 100644
--- a/lib/efi_loader/efi_disk.c
+++ b/lib/efi_loader/efi_disk.c
@@ -574,6 +574,60 @@ int efi_disk_create(struct udevice *dev)
return -1;
 }
 
+static int efi_disk_delete_raw(struct udevice *dev)
+{
+   efi_handle_t handle = dev->efi_obj;
+   struct blk_desc *desc;
+   struct efi_disk_obj *diskobj;
+
+   desc = dev_get_uclass_plat(dev);
+   if (desc->if_type != IF_TYPE_EFI) {
+   diskobj = container_of(handle, struct efi_disk_obj, header);
+   efi_free_pool(diskobj->dp);
+   }
+
+   /*
+* TODO: Can we use efi_delete_handle() here?
+*/
+   efi_remove_all_protocols(handle);
+
+   efi_remove_handle(handle);
+   free(diskobj);
+
+   return 0;
+}
+
+static int efi_disk_delete_part(struct udevice *dev)
+{
+   efi_handle_t handle = dev->efi_obj;
+   struct efi_disk_obj *diskobj;
+
+   diskobj = container_of(handle, struct efi_disk_obj, header);
+
+   efi_free_pool(diskobj->dp);
+
+   efi_remove_all_protocols(handle);
+
+   efi_remove_handle(handle);
+   free(diskobj);
+
+   return 0;
+}
+
+int efi_disk_delete(struct udevice *dev)
+{
+   enum uclass_id id;
+
+   id = device_get_uclass_id(dev);
+
+   if (id == UCLASS_BLK)
+   return efi_disk_delete_raw(dev);
+   else if (id == UCLASS_PARTITION)
+   return efi_disk_delete_part(dev);
+   else
+   return -1;
+}
+
 /**
  * efi_disk_is_system_part() - check if handle refers to an EFI system 
partition
  *
-- 
2.33.0



[resent RFC 17/22] efi_loader: add efi_remove_handle()

2021-10-03 Thread AKASHI Takahiro
This function is a counterpart of efi_add_handle() and will be used
in order to remove an efi_disk object in a later patch.

Signed-off-by: AKASHI Takahiro 
---
 include/efi_loader.h  | 2 ++
 lib/efi_loader/efi_boottime.c | 8 
 2 files changed, 10 insertions(+)

diff --git a/include/efi_loader.h b/include/efi_loader.h
index cfbe1fe659ef..50f4119dcdfb 100644
--- a/include/efi_loader.h
+++ b/include/efi_loader.h
@@ -579,6 +579,8 @@ void efi_save_gd(void);
 void efi_runtime_relocate(ulong offset, struct efi_mem_desc *map);
 /* Add a new object to the object list. */
 void efi_add_handle(efi_handle_t obj);
+/* Remove a object from the object list. */
+void efi_remove_handle(efi_handle_t obj);
 /* Create handle */
 efi_status_t efi_create_handle(efi_handle_t *handle);
 /* Delete handle */
diff --git a/lib/efi_loader/efi_boottime.c b/lib/efi_loader/efi_boottime.c
index f0283b539e46..b2503b74233b 100644
--- a/lib/efi_loader/efi_boottime.c
+++ b/lib/efi_loader/efi_boottime.c
@@ -503,6 +503,14 @@ void efi_add_handle(efi_handle_t handle)
list_add_tail(>link, _obj_list);
 }
 
+void efi_remove_handle(efi_handle_t handle)
+{
+   if (!handle)
+   return;
+
+   list_del(>link);
+}
+
 /**
  * efi_create_handle() - create handle
  * @handle: new handle
-- 
2.33.0



[resent RFC 16/22] efi_loader: cleanup after efi_disk-dm integration

2021-10-03 Thread AKASHI Takahiro
efi_disk_register() will be no longer needed now that all efi_disks are
set to be created with device model thanks to efi_disk-dm integration.

Signed-off-by: AKASHI Takahiro 
---
 include/efi_loader.h   |   2 -
 lib/efi_loader/efi_disk.c  | 102 -
 lib/efi_loader/efi_setup.c |   5 --
 3 files changed, 109 deletions(-)

diff --git a/include/efi_loader.h b/include/efi_loader.h
index 751fde7fb153..cfbe1fe659ef 100644
--- a/include/efi_loader.h
+++ b/include/efi_loader.h
@@ -519,8 +519,6 @@ void efi_carve_out_dt_rsv(void *fdt);
 efi_status_t efi_console_register(void);
 /* Called when a block devices has been probed */
 int efi_disk_create(struct udevice *dev);
-/* 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 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/efi_disk.c b/lib/efi_loader/efi_disk.c
index 3fae40e034fb..74ef923d1d67 100644
--- a/lib/efi_loader/efi_disk.c
+++ b/lib/efi_loader/efi_disk.c
@@ -485,56 +485,6 @@ error:
return ret;
 }
 
-#ifndef CONFIG_BLK
-/**
- * efi_disk_create_partitions() - create handles and protocols for partitions
- *
- * Create handles and protocols for the partitions of a block device.
- *
- * @parent:handle of the parent disk
- * @desc:  block device
- * @if_typename:   interface type
- * @diskid:device number
- * @pdevname:  device name
- * Return: number of partitions created
- */
-int efi_disk_create_partitions(efi_handle_t parent, struct blk_desc *desc,
-  const char *if_typename, int diskid,
-  const char *pdevname)
-{
-   int disks = 0;
-   char devname[32] = { 0 }; /* dp->str is u16[32] long */
-   int part;
-   struct efi_device_path *dp = NULL;
-   efi_status_t ret;
-   struct efi_handler *handler;
-
-   /* Get the device path of the parent */
-   ret = efi_search_protocol(parent, _guid_device_path, );
-   if (ret == EFI_SUCCESS)
-   dp = handler->protocol_interface;
-
-   /* Add devices for each partition */
-   for (part = 1; part <= MAX_SEARCH_PARTITIONS; part++) {
-   struct disk_partition info;
-
-   if (part_get_info(desc, part, ))
-   continue;
-   snprintf(devname, sizeof(devname), "%s:%x", pdevname,
-part);
-   ret = efi_disk_add_dev(parent, dp, if_typename, desc, diskid,
-  , part, NULL);
-   if (ret != EFI_SUCCESS) {
-   log_err("Adding partition %s failed\n", pdevname);
-   continue;
-   }
-   disks++;
-   }
-
-   return disks;
-}
-#endif /* CONFIG_BLK */
-
 /*
  * Create a handle for a whole raw disk
  *
@@ -624,58 +574,6 @@ int efi_disk_create(struct udevice *dev)
return -1;
 }
 
-/**
- * efi_disk_register() - register block devices
- *
- * U-Boot doesn't have a list of all online disk devices. So when running our
- * EFI payload, we scan through all of the potentially available ones and
- * store them in our object pool.
- *
- * This function is called in efi_init_obj_list().
- *
- * TODO(s...@chromium.org): Actually with CONFIG_BLK, U-Boot does have this.
- * Consider converting the code to look up devices as needed. The EFI device
- * could be a child of the UCLASS_BLK block device, perhaps.
- *
- * Return: status code
- */
-efi_status_t efi_disk_register(void)
-{
-   struct efi_disk_obj *disk;
-   int disks = 0;
-   efi_status_t ret;
-   struct udevice *dev;
-
-   for (uclass_first_device_check(UCLASS_BLK, ); dev;
-uclass_next_device_check()) {
-   struct blk_desc *desc = dev_get_uclass_plat(dev);
-   const char *if_typename = blk_get_if_type_name(desc->if_type);
-
-   /* Add block device for the full device */
-   log_info("Scanning disk %s...\n", dev->name);
-   ret = efi_disk_add_dev(NULL, NULL, if_typename,
-   desc, desc->devnum, NULL, 0, );
-   if (ret == 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 = 
%lu\n",
-   dev->name, ret & ~EFI_ERROR_MASK);
-   return ret;
-   }
-   disks++;
-
-   /* Partitions show up as block devices in EFI */
-   disks += efi_disk_create_partitions(
-   >header, desc, if_typename,
-  

[resent RFC 14/22] efi_loader: disk: a helper function to create efi_disk objects from udevice

2021-10-03 Thread AKASHI Takahiro
Add efi_disk_create() function.

Any UEFI handle created by efi_disk_create() can be treated as a efi_disk
object, the udevice is either a UCLASS_BLK (a whole raw disk) or
UCLASS_PARTITION (a disk partition).

So this function is expected to be called every time such an udevice
is detected and activated through a device model's "probe" interface.

Signed-off-by: AKASHI Takahiro 
---
 include/efi_loader.h  |  2 +
 lib/efi_loader/efi_disk.c | 92 +++
 2 files changed, 94 insertions(+)

diff --git a/include/efi_loader.h b/include/efi_loader.h
index c440962fe522..751fde7fb153 100644
--- a/include/efi_loader.h
+++ b/include/efi_loader.h
@@ -517,6 +517,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 when a block devices has been probed */
+int efi_disk_create(struct udevice *dev);
 /* 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 install EFI_RNG_PROTOCOL */
diff --git a/lib/efi_loader/efi_disk.c b/lib/efi_loader/efi_disk.c
index cd5528046251..3fae40e034fb 100644
--- a/lib/efi_loader/efi_disk.c
+++ b/lib/efi_loader/efi_disk.c
@@ -10,6 +10,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -484,6 +485,7 @@ error:
return ret;
 }
 
+#ifndef CONFIG_BLK
 /**
  * efi_disk_create_partitions() - create handles and protocols for partitions
  *
@@ -531,6 +533,96 @@ int efi_disk_create_partitions(efi_handle_t parent, struct 
blk_desc *desc,
 
return disks;
 }
+#endif /* CONFIG_BLK */
+
+/*
+ * Create a handle for a whole raw disk
+ *
+ * @devuclass device
+ * @return 0 on success, -1 otherwise
+ */
+static int efi_disk_create_raw(struct udevice *dev)
+{
+   struct efi_disk_obj *disk;
+   struct blk_desc *desc;
+   const char *if_typename;
+   int diskid;
+   efi_status_t ret;
+
+   desc = dev_get_uclass_plat(dev);
+   if_typename = blk_get_if_type_name(desc->if_type);
+   diskid = desc->devnum;
+
+   ret = efi_disk_add_dev(NULL, NULL, if_typename, desc,
+  diskid, NULL, 0, );
+   if (ret != EFI_SUCCESS) {
+   log_err("Adding disk %s%d failed\n", if_typename, diskid);
+   return -1;
+   }
+   disk->dev = dev;
+   dev->efi_obj = >header;
+
+   return 0;
+}
+
+/*
+ * Create a handle for a disk partition
+ *
+ * @devuclass device
+ * @return 0 on success, -1 otherwise
+ */
+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_device_path *dp = NULL;
+   struct efi_disk_obj *disk;
+   efi_status_t ret;
+
+   parent = dev->parent->efi_obj;
+   desc = dev_get_uclass_plat(dev->parent);
+   if_typename = blk_get_if_type_name(desc->if_type);
+   diskid = desc->devnum;
+
+   part_data = dev_get_uclass_plat(dev);
+   part = part_data->partnum;
+   info = _data->gpt_part_info;
+
+   /* TODO: should not use desc? */
+   dp = efi_dp_from_part(desc, 0);
+
+   ret = efi_disk_add_dev(parent, dp, if_typename, desc, diskid,
+  info, part, );
+   if (ret != EFI_SUCCESS) {
+   log_err("Adding partition %s%d:%x failed\n",
+   if_typename, diskid, part);
+   return -1;
+   }
+   disk->dev = dev;
+   dev->efi_obj = >header;
+
+   return 0;
+}
+
+int efi_disk_create(struct udevice *dev)
+{
+   enum uclass_id id;
+
+   id = device_get_uclass_id(dev);
+
+   if (id == UCLASS_BLK)
+   return efi_disk_create_raw(dev);
+
+   if (id == UCLASS_PARTITION)
+   return efi_disk_create_part(dev);
+
+   return -1;
+}
 
 /**
  * efi_disk_register() - register block devices
-- 
2.33.0



[resent RFC 15/22] dm: blk: call efi's device-probe hook

2021-10-03 Thread AKASHI Takahiro
Adding this callback function, efi_disk_create() in block devices's
post_probe hook will allows for automatically creating efi_disk objects
per block device.

This will end up not only eliminating efi_disk_register() called in UEFI
initialization, but also enabling detections of new block devices even
after the initialization.

Signed-off-by: AKASHI Takahiro 
---
 drivers/block/blk-uclass.c | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/drivers/block/blk-uclass.c b/drivers/block/blk-uclass.c
index 8fbec8779e1e..ce45cf0a8768 100644
--- a/drivers/block/blk-uclass.c
+++ b/drivers/block/blk-uclass.c
@@ -9,6 +9,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -827,6 +828,11 @@ int blk_create_partitions(struct udevice *parent)
 
 static int blk_post_probe(struct udevice *dev)
 {
+   if (CONFIG_IS_ENABLED(EFI_LOADER)) {
+   if (efi_disk_create(dev))
+   debug("*** efi_post_probe_device failed\n");
+   }
+
if (IS_ENABLED(CONFIG_PARTITIONS) &&
IS_ENABLED(CONFIG_HAVE_BLOCK_DEVICE)) {
struct blk_desc *desc = dev_get_uclass_plat(dev);
@@ -843,6 +849,10 @@ static int blk_post_probe(struct udevice *dev)
 
 static int blk_part_post_probe(struct udevice *dev)
 {
+   if (CONFIG_IS_ENABLED(EFI_LOADER)) {
+   if (efi_disk_create(dev))
+   debug("*** efi_post_probe_device failed\n");
+   }
/*
 * TODO:
 * If we call blk_creat_partitions() here, it would allow for
-- 
2.33.0



[resent RFC 13/22] efi_loader: remove !CONFIG_BLK code from efi_disk

2021-10-03 Thread AKASHI Takahiro
The change in this patch will probably have been covered by other guy's patch.

Signed-off-by: AKASHI Takahiro 
---
 lib/efi_loader/efi_disk.c | 49 ---
 1 file changed, 49 deletions(-)

diff --git a/lib/efi_loader/efi_disk.c b/lib/efi_loader/efi_disk.c
index dfa6f898d586..cd5528046251 100644
--- a/lib/efi_loader/efi_disk.c
+++ b/lib/efi_loader/efi_disk.c
@@ -552,7 +552,6 @@ efi_status_t efi_disk_register(void)
struct efi_disk_obj *disk;
int disks = 0;
efi_status_t ret;
-#ifdef CONFIG_BLK
struct udevice *dev;
 
for (uclass_first_device_check(UCLASS_BLK, ); dev;
@@ -580,54 +579,6 @@ efi_status_t efi_disk_register(void)
>header, desc, if_typename,
desc->devnum, dev->name);
}
-#else
-   int i, if_type;
-
-   /* Search for all available disk devices */
-   for (if_type = 0; if_type < IF_TYPE_COUNT; if_type++) {
-   const struct blk_driver *cur_drvr;
-   const char *if_typename;
-
-   cur_drvr = blk_driver_lookup_type(if_type);
-   if (!cur_drvr)
-   continue;
-
-   if_typename = cur_drvr->if_typename;
-   log_info("Scanning disks on %s...\n", if_typename);
-   for (i = 0; i < 4; i++) {
-   struct blk_desc *desc;
-   char devname[32] = { 0 }; /* dp->str is u16[32] long */
-
-   desc = blk_get_devnum_by_type(if_type, i);
-   if (!desc)
-   continue;
-   if (desc->type == DEV_TYPE_UNKNOWN)
-   continue;
-
-   snprintf(devname, sizeof(devname), "%s%d",
-if_typename, i);
-
-   /* Add block device for the full device */
-   ret = efi_disk_add_dev(NULL, NULL, if_typename, desc,
-  i, NULL, 0, );
-   if (ret == EFI_NOT_READY) {
-   log_notice("Disk %s not ready\n", devname);
-   continue;
-   }
-   if (ret) {
-   log_err("ERROR: failure to add disk device %s, 
r = %lu\n",
-   devname, ret & ~EFI_ERROR_MASK);
-   return ret;
-   }
-   disks++;
-
-   /* Partitions show up as block devices in EFI */
-   disks += efi_disk_create_partitions
-   (>header, desc,
-if_typename, i, devname);
-   }
-   }
-#endif
log_info("Found %d disks\n", disks);
 
return EFI_SUCCESS;
-- 
2.33.0



[resent RFC 12/22] dm: add a hidden link to efi object

2021-10-03 Thread AKASHI Takahiro
This member field in udevice will be used to dereference from udevice
to efi_object (or efi_handle).

Signed-off-by: AKASHI Takahiro 
---
 include/dm/device.h | 4 
 1 file changed, 4 insertions(+)

diff --git a/include/dm/device.h b/include/dm/device.h
index 0a9718a5b81a..33b09a836f06 100644
--- a/include/dm/device.h
+++ b/include/dm/device.h
@@ -190,6 +190,10 @@ struct udevice {
 #if CONFIG_IS_ENABLED(DM_DMA)
ulong dma_offset;
 #endif
+#if CONFIG_IS_ENABLED(EFI_LOADER)
+   /* link to efi_object */
+   void *efi_obj;
+#endif
 };
 
 /**
-- 
2.33.0



[resent RFC 11/22] efi_loader: disk: use udevice instead of blk_desc

2021-10-03 Thread AKASHI Takahiro
In most of all usages, we can avoid using blk_desc which is expected
to be data private to the device not be accessed outside device drivers.

Signed-off-by: AKASHI Takahiro 
---
 lib/efi_loader/efi_disk.c | 25 -
 1 file changed, 12 insertions(+), 13 deletions(-)

diff --git a/lib/efi_loader/efi_disk.c b/lib/efi_loader/efi_disk.c
index 988907ecb910..dfa6f898d586 100644
--- a/lib/efi_loader/efi_disk.c
+++ b/lib/efi_loader/efi_disk.c
@@ -45,7 +45,7 @@ struct efi_disk_obj {
unsigned int part;
struct efi_simple_file_system_protocol *volume;
lbaint_t offset;
-   struct blk_desc *desc;
+   struct udevice *dev; /* TODO: move it to efi_object */
 };
 
 /**
@@ -80,14 +80,12 @@ static efi_status_t efi_disk_rw_blocks(struct efi_block_io 
*this,
void *buffer, enum efi_disk_direction direction)
 {
struct efi_disk_obj *diskobj;
-   struct blk_desc *desc;
int blksz;
int blocks;
unsigned long n;
 
diskobj = container_of(this, struct efi_disk_obj, ops);
-   desc = (struct blk_desc *) diskobj->desc;
-   blksz = desc->blksz;
+   blksz = diskobj->media.block_size;
blocks = buffer_size / blksz;
lba += diskobj->offset;
 
@@ -99,9 +97,9 @@ static efi_status_t efi_disk_rw_blocks(struct efi_block_io 
*this,
return EFI_BAD_BUFFER_SIZE;
 
if (direction == EFI_DISK_READ)
-   n = blk_dread(desc, lba, blocks, buffer);
+   n = blk_read(diskobj->dev, lba, blocks, buffer);
else
-   n = blk_dwrite(desc, lba, blocks, buffer);
+   n = blk_write(diskobj->dev, lba, blocks, buffer);
 
/* We don't do interrupts, so check for timers cooperatively */
efi_timer_check();
@@ -443,7 +441,6 @@ static efi_status_t efi_disk_add_dev(
diskobj->ops = block_io_disk_template;
diskobj->ifname = if_typename;
diskobj->dev_index = dev_index;
-   diskobj->desc = desc;
 
/* Fill in EFI IO Media info (for read/write callbacks) */
diskobj->media.removable_media = desc->removable;
@@ -647,20 +644,22 @@ bool efi_disk_is_system_part(efi_handle_t handle)
 {
struct efi_handler *handler;
struct efi_disk_obj *diskobj;
-   struct disk_partition info;
+   struct udevice *dev;
+   struct disk_part *part;
efi_status_t ret;
-   int r;
 
/* check if this is a block device */
ret = efi_search_protocol(handle, _block_io_guid, );
if (ret != EFI_SUCCESS)
return false;
 
+   /* find a partition udevice */
diskobj = container_of(handle, struct efi_disk_obj, header);
-
-   r = part_get_info(diskobj->desc, diskobj->part, );
-   if (r)
+   dev = diskobj->dev;
+   if (!dev || dev->driver->id != UCLASS_PARTITION)
return false;
 
-   return !!(info.bootable & PART_EFI_SYSTEM_PARTITION);
+   part = dev_get_uclass_plat(dev);
+
+   return !!(part->gpt_part_info.bootable & PART_EFI_SYSTEM_PARTITION);
 }
-- 
2.33.0



[resent RFC 10/22] dm: blk: add read/write interfaces with udevice

2021-10-03 Thread AKASHI Takahiro
In include/blk.h, Simon suggested:
===>
/*
 * These functions should take struct udevice instead of struct blk_desc,
 * but this is convenient for migration to driver model. Add a 'd' prefix
 * to the function operations, so that blk_read(), etc. can be reserved for
 * functions with the correct arguments.
 */
unsigned long blk_dread(struct blk_desc *block_dev, lbaint_t start,
lbaint_t blkcnt, void *buffer);
unsigned long blk_dwrite(struct blk_desc *block_dev, lbaint_t start,
 lbaint_t blkcnt, const void *buffer);
unsigned long blk_derase(struct blk_desc *block_dev, lbaint_t start,
 lbaint_t blkcnt);
<===

So new interfaces are provided with this patch.

They are expected to be used everywhere in U-Boot at the end. The exceptions
are block device drivers, partition drivers and efi_disk which should know
details of blk_desc structure.

Signed-off-by: AKASHI Takahiro 
---
 drivers/block/blk-uclass.c | 91 ++
 include/blk.h  |  6 +++
 2 files changed, 97 insertions(+)

diff --git a/drivers/block/blk-uclass.c b/drivers/block/blk-uclass.c
index 6ba11a8fa7f7..8fbec8779e1e 100644
--- a/drivers/block/blk-uclass.c
+++ b/drivers/block/blk-uclass.c
@@ -482,6 +482,97 @@ unsigned long blk_derase(struct blk_desc *block_dev, 
lbaint_t start,
return ops->erase(dev, start, blkcnt);
 }
 
+static struct blk_desc *dev_get_blk(struct udevice *dev)
+{
+   struct blk_desc *block_dev;
+
+   switch (device_get_uclass_id(dev)) {
+   case UCLASS_BLK:
+   block_dev = dev_get_uclass_plat(dev);
+   break;
+   case UCLASS_PARTITION:
+   block_dev = dev_get_uclass_plat(dev_get_parent(dev));
+   break;
+   default:
+   block_dev = NULL;
+   break;
+   }
+
+   return block_dev;
+}
+
+unsigned long blk_read(struct udevice *dev, lbaint_t start,
+  lbaint_t blkcnt, void *buffer)
+{
+   struct blk_desc *block_dev;
+   const struct blk_ops *ops;
+   struct disk_part *part;
+   lbaint_t start_in_disk;
+   ulong blks_read;
+
+   block_dev = dev_get_blk(dev);
+   if (!block_dev)
+   return -ENOSYS;
+
+   ops = blk_get_ops(dev);
+   if (!ops->read)
+   return -ENOSYS;
+
+   start_in_disk = start;
+   if (device_get_uclass_id(dev) == UCLASS_PARTITION) {
+   part = dev_get_uclass_plat(dev);
+   start_in_disk += part->gpt_part_info.start;
+   }
+
+   if (blkcache_read(block_dev->if_type, block_dev->devnum,
+ start_in_disk, blkcnt, block_dev->blksz, buffer))
+   return blkcnt;
+   blks_read = ops->read(dev, start, blkcnt, buffer);
+   if (blks_read == blkcnt)
+   blkcache_fill(block_dev->if_type, block_dev->devnum,
+ start_in_disk, blkcnt, block_dev->blksz, buffer);
+
+   return blks_read;
+}
+
+unsigned long blk_write(struct udevice *dev, lbaint_t start,
+   lbaint_t blkcnt, const void *buffer)
+{
+   struct blk_desc *block_dev;
+   const struct blk_ops *ops;
+
+   block_dev = dev_get_blk(dev);
+   if (!block_dev)
+   return -ENOSYS;
+
+   ops = blk_get_ops(dev);
+   if (!ops->write)
+   return -ENOSYS;
+
+   blkcache_invalidate(block_dev->if_type, block_dev->devnum);
+
+   return ops->write(dev, start, blkcnt, buffer);
+}
+
+unsigned long blk_erase(struct udevice *dev, lbaint_t start,
+   lbaint_t blkcnt)
+{
+   struct blk_desc *block_dev;
+   const struct blk_ops *ops;
+
+   block_dev = dev_get_blk(dev);
+   if (!block_dev)
+   return -ENOSYS;
+
+   ops = blk_get_ops(dev);
+   if (!ops->erase)
+   return -ENOSYS;
+
+   blkcache_invalidate(block_dev->if_type, block_dev->devnum);
+
+   return ops->erase(dev, start, blkcnt);
+}
+
 int blk_get_from_parent(struct udevice *parent, struct udevice **devp)
 {
struct udevice *dev;
diff --git a/include/blk.h b/include/blk.h
index 3d883eb1db64..f5fdd6633a09 100644
--- a/include/blk.h
+++ b/include/blk.h
@@ -284,6 +284,12 @@ unsigned long blk_dwrite(struct blk_desc *block_dev, 
lbaint_t start,
 unsigned long blk_derase(struct blk_desc *block_dev, lbaint_t start,
 lbaint_t blkcnt);
 
+unsigned long blk_read(struct udevice *dev, lbaint_t start,
+  lbaint_t blkcnt, void *buffer);
+unsigned long blk_write(struct udevice *dev, lbaint_t start,
+   lbaint_t blkcnt, const void *buffer);
+unsigned long blk_erase(struct udevice *dev, lbaint_t start,
+   lbaint_t blkcnt);
 /**
  * blk_find_device() - Find a block device
  *
-- 
2.33.0



[resent RFC 09/22] dm: blk: add a device-probe hook for scanning disk partitions

2021-10-03 Thread AKASHI Takahiro
Now that all the block device drivers have enable a probe hook, we will
call blk_create_partitions() to enumerate all the partitions and create
associated udevices when a block device is detected.

Signed-off-by: AKASHI Takahiro 
---
 drivers/block/blk-uclass.c | 15 +++
 1 file changed, 15 insertions(+)

diff --git a/drivers/block/blk-uclass.c b/drivers/block/blk-uclass.c
index dd7f3c0fe31e..6ba11a8fa7f7 100644
--- a/drivers/block/blk-uclass.c
+++ b/drivers/block/blk-uclass.c
@@ -741,11 +741,25 @@ static int blk_post_probe(struct udevice *dev)
struct blk_desc *desc = dev_get_uclass_plat(dev);
 
part_init(desc);
+
+   if (desc->part_type != PART_TYPE_UNKNOWN &&
+   blk_create_partitions(dev))
+   debug("*** creating partitions failed\n");
}
 
return 0;
 }
 
+static int blk_part_post_probe(struct udevice *dev)
+{
+   /*
+* TODO:
+* If we call blk_creat_partitions() here, it would allow for
+* "partitions in a partition".
+*/
+   return 0;
+}
+
 UCLASS_DRIVER(blk) = {
.id = UCLASS_BLK,
.name   = "blk",
@@ -821,6 +835,7 @@ U_BOOT_DRIVER(blk_partition) = {
 
 UCLASS_DRIVER(partition) = {
.id = UCLASS_PARTITION,
+   .post_probe = blk_part_post_probe,
.per_device_plat_auto   = sizeof(struct disk_part),
.name   = "partition",
 };
-- 
2.33.0



[resent RFC 08/22] dm: blk: add UCLASS_PARTITION

2021-10-03 Thread AKASHI Takahiro
UCLASS_PARTITION device will be created as a child node of
UCLASS_BLK device.

Signed-off-by: AKASHI Takahiro 
---
 drivers/block/blk-uclass.c | 111 +
 include/blk.h  |   9 +++
 include/dm/uclass-id.h |   1 +
 3 files changed, 121 insertions(+)

diff --git a/drivers/block/blk-uclass.c b/drivers/block/blk-uclass.c
index 83682dcc181a..dd7f3c0fe31e 100644
--- a/drivers/block/blk-uclass.c
+++ b/drivers/block/blk-uclass.c
@@ -12,6 +12,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -695,6 +696,44 @@ int blk_unbind_all(int if_type)
return 0;
 }
 
+int blk_create_partitions(struct udevice *parent)
+{
+   int part, count;
+   struct blk_desc *desc = dev_get_uclass_plat(parent);
+   struct disk_partition info;
+   struct disk_part *part_data;
+   char devname[32];
+   struct udevice *dev;
+   int ret;
+
+   if (!CONFIG_IS_ENABLED(PARTITIONS) ||
+   !CONFIG_IS_ENABLED(HAVE_BLOCK_DEVICE))
+   return 0;
+
+   /* Add devices for each partition */
+   for (count = 0, part = 1; part <= MAX_SEARCH_PARTITIONS; part++) {
+   if (part_get_info(desc, part, ))
+   continue;
+   snprintf(devname, sizeof(devname), "%s:%d", parent->name,
+part);
+
+   ret = device_bind_driver(parent, "blk_partition",
+strdup(devname), );
+   if (ret)
+   return ret;
+
+   part_data = dev_get_uclass_plat(dev);
+   part_data->partnum = part;
+   part_data->gpt_part_info = info;
+   count++;
+
+   device_probe(dev);
+   }
+   debug("%s: %d partitions found in %s\n", __func__, count, parent->name);
+
+   return 0;
+}
+
 static int blk_post_probe(struct udevice *dev)
 {
if (IS_ENABLED(CONFIG_PARTITIONS) &&
@@ -713,3 +752,75 @@ UCLASS_DRIVER(blk) = {
.post_probe = blk_post_probe,
.per_device_plat_auto   = sizeof(struct blk_desc),
 };
+
+static ulong blk_part_read(struct udevice *dev, lbaint_t start,
+  lbaint_t blkcnt, void *buffer)
+{
+   struct udevice *parent;
+   struct disk_part *part;
+   const struct blk_ops *ops;
+
+   parent = dev_get_parent(dev);
+   ops = blk_get_ops(parent);
+   if (!ops->read)
+   return -ENOSYS;
+
+   part = dev_get_uclass_plat(dev);
+   start += part->gpt_part_info.start;
+
+   return ops->read(parent, start, blkcnt, buffer);
+}
+
+static ulong blk_part_write(struct udevice *dev, lbaint_t start,
+   lbaint_t blkcnt, const void *buffer)
+{
+   struct udevice *parent;
+   struct disk_part *part;
+   const struct blk_ops *ops;
+
+   parent = dev_get_parent(dev);
+   ops = blk_get_ops(parent);
+   if (!ops->write)
+   return -ENOSYS;
+
+   part = dev_get_uclass_plat(dev);
+   start += part->gpt_part_info.start;
+
+   return ops->write(parent, start, blkcnt, buffer);
+}
+
+static ulong blk_part_erase(struct udevice *dev, lbaint_t start,
+   lbaint_t blkcnt)
+{
+   struct udevice *parent;
+   struct disk_part *part;
+   const struct blk_ops *ops;
+
+   parent = dev_get_parent(dev);
+   ops = blk_get_ops(parent);
+   if (!ops->erase)
+   return -ENOSYS;
+
+   part = dev_get_uclass_plat(dev);
+   start += part->gpt_part_info.start;
+
+   return ops->erase(parent, start, blkcnt);
+}
+
+static const struct blk_ops blk_part_ops = {
+   .read   = blk_part_read,
+   .write  = blk_part_write,
+   .erase  = blk_part_erase,
+};
+
+U_BOOT_DRIVER(blk_partition) = {
+   .name   = "blk_partition",
+   .id = UCLASS_PARTITION,
+   .ops= _part_ops,
+};
+
+UCLASS_DRIVER(partition) = {
+   .id = UCLASS_PARTITION,
+   .per_device_plat_auto   = sizeof(struct disk_part),
+   .name   = "partition",
+};
diff --git a/include/blk.h b/include/blk.h
index 19bab081c2cd..3d883eb1db64 100644
--- a/include/blk.h
+++ b/include/blk.h
@@ -366,6 +366,15 @@ int blk_create_devicef(struct udevice *parent, const char 
*drv_name,
   const char *name, int if_type, int devnum, int blksz,
   lbaint_t lba, struct udevice **devp);
 
+/**
+ * blk_create_partitions - Create block devices for disk partitions
+ *
+ * Create UCLASS_PARTITION udevices for each of disk partitions in @parent
+ *
+ * @parent:Whole disk device
+ */
+int blk_create_partitions(struct udevice *parent);
+
 /**
  * blk_unbind_all() - Unbind all device of the given interface type
  *
diff --git a/include/dm/uclass-id.h b/include/dm/uclass-id.h
index e7edd409f307..30892d01ce13 100644
--- a/include/dm/uclass-id.h
+++ b/include/dm/uclass-id.h
@@ -80,6 +80,7 @@ 

[resent RFC 07/22] block: ide: call device_probe() after scanning

2021-10-03 Thread AKASHI Takahiro
Every time an ide bus/port is scanned and a new device is detected,
we want to call device_probe() as it will give us a chance to run additional
post-processings for some purposes.

In particular, support for creating partitions on a device will be added.

Signed-off-by: AKASHI Takahiro 
---
 drivers/block/ide.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/drivers/block/ide.c b/drivers/block/ide.c
index c99076c6f45d..31aaed09ab70 100644
--- a/drivers/block/ide.c
+++ b/drivers/block/ide.c
@@ -1151,6 +1151,12 @@ static int ide_probe(struct udevice *udev)
 blksz, size, _dev);
if (ret)
return ret;
+
+   ret = device_probe(blk_dev);
+   if (ret) {
+   device_unbind(blk_dev);
+   return ret;
+   }
}
}
 
-- 
2.33.0



[resent RFC 06/22] sata: call device_probe() after scanning

2021-10-03 Thread AKASHI Takahiro
Every time a sata bus/port is scanned and a new device is detected,
we want to call device_probe() as it will give us a chance to run additional
post-processings for some purposes.

In particular, support for creating partitions on a device will be added.

Signed-off-by: AKASHI Takahiro 
---
 drivers/ata/dwc_ahsata.c | 10 ++
 drivers/ata/fsl_sata.c   | 11 +++
 drivers/ata/sata_mv.c|  9 +
 drivers/ata/sata_sil.c   | 12 
 4 files changed, 42 insertions(+)

diff --git a/drivers/ata/dwc_ahsata.c b/drivers/ata/dwc_ahsata.c
index 6d42548087b3..6a51c70d1170 100644
--- a/drivers/ata/dwc_ahsata.c
+++ b/drivers/ata/dwc_ahsata.c
@@ -1026,6 +1026,16 @@ int dwc_ahsata_scan(struct udevice *dev)
return ret;
}
 
+   ret = device_probe(bdev);
+   if (ret < 0) {
+   debug("Can't probe\n");
+   /* TODO: undo create */
+
+   device_unbind(bdev);
+
+   return ret;
+   }
+
return 0;
 }
 
diff --git a/drivers/ata/fsl_sata.c b/drivers/ata/fsl_sata.c
index e44db0a37458..346e9298b4c5 100644
--- a/drivers/ata/fsl_sata.c
+++ b/drivers/ata/fsl_sata.c
@@ -982,6 +982,17 @@ static int fsl_ata_probe(struct udevice *dev)
failed_number++;
continue;
}
+
+   ret = device_probe(bdev);
+   if (ret < 0) {
+   debug("Can't probe\n");
+   ret = fsl_unbind_device(blk);
+   if (ret)
+   return ret;
+
+   failed_number++;
+   continue;
+   }
}
 
if (failed_number == nr_ports)
diff --git a/drivers/ata/sata_mv.c b/drivers/ata/sata_mv.c
index 003222d47be6..09b735779ebf 100644
--- a/drivers/ata/sata_mv.c
+++ b/drivers/ata/sata_mv.c
@@ -1099,6 +1099,15 @@ static int sata_mv_probe(struct udevice *dev)
continue;
}
 
+   ret = device_probe(bdev);
+   if (ret < 0) {
+   debug("Can't probe\n");
+   /* TODO: undo create */
+
+   device_unbind(bdev);
+   continue;
+   }
+
/* If we got here, the current SATA port was probed
 * successfully, so set the probe status to successful.
 */
diff --git a/drivers/ata/sata_sil.c b/drivers/ata/sata_sil.c
index dda712f42cb2..295f7ca72303 100644
--- a/drivers/ata/sata_sil.c
+++ b/drivers/ata/sata_sil.c
@@ -864,6 +864,18 @@ static int sil_pci_probe(struct udevice *dev)
failed_number++;
continue;
}
+
+   ret = device_probe(bdev);
+   if (ret < 0) {
+   debug("Can't probe\n");
+   ret = sil_unbind_device(blk);
+   device_unbind(bdev);
+   if (ret)
+   return ret;
+
+   failed_number++;
+   continue;
+   }
}
 
if (failed_number == sata_info.maxport)
-- 
2.33.0



[resent RFC 05/22] nvme: call device_probe() after scanning

2021-10-03 Thread AKASHI Takahiro
Every time a nvme bus/port is scanned and a new device is detected,
we want to call device_probe() as it will give us a chance to run additional
post-processings for some purposes.

In particular, support for creating partitions on a device will be added.

Signed-off-by: AKASHI Takahiro 
---
 drivers/nvme/nvme.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/drivers/nvme/nvme.c b/drivers/nvme/nvme.c
index f6465ea7f482..975bbc6dc3b7 100644
--- a/drivers/nvme/nvme.c
+++ b/drivers/nvme/nvme.c
@@ -909,6 +909,12 @@ static int nvme_probe(struct udevice *udev)
 -1, 512, 0, _udev);
if (ret)
goto free_id;
+
+   ret = device_probe(ns_udev);
+   if (ret) {
+   device_unbind(ns_udev);
+   goto free_id;
+   }
}
 
free(id);
-- 
2.33.0



[resent RFC 04/22] mmc: call device_probe() after scanning

2021-10-03 Thread AKASHI Takahiro
Every time a mmc bus/port is scanned and a new device is detected,
we want to call device_probe() as it will give us a chance to run additional
post-processings for some purposes.

In particular, support for creating partitions on a device will be added.

Signed-off-by: AKASHI Takahiro 
---
 drivers/mmc/mmc-uclass.c | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/drivers/mmc/mmc-uclass.c b/drivers/mmc/mmc-uclass.c
index 3ee92d03ca23..07b5c1736439 100644
--- a/drivers/mmc/mmc-uclass.c
+++ b/drivers/mmc/mmc-uclass.c
@@ -418,6 +418,13 @@ int mmc_bind(struct udevice *dev, struct mmc *mmc, const 
struct mmc_config *cfg)
bdesc->part_type = cfg->part_type;
mmc->dev = dev;
mmc->user_speed_mode = MMC_MODES_END;
+
+   ret = device_probe(dev);
+   if (ret) {
+   device_unbind(dev);
+   return ret;
+   }
+
return 0;
 }
 
-- 
2.33.0



[resent RFC 03/22] usb: storage: call device_probe() after scanning

2021-10-03 Thread AKASHI Takahiro
Every time a usb bus/port is scanned and a new device is detected,
we want to call device_probe() as it will give us a chance to run additional
post-processings for some purposes.

In particular, support for creating partitions on a device will be added.

Signed-off-by: AKASHI Takahiro 
---
 common/usb_storage.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/common/usb_storage.c b/common/usb_storage.c
index 946c6b2b323a..5f294f17491f 100644
--- a/common/usb_storage.c
+++ b/common/usb_storage.c
@@ -239,6 +239,12 @@ static int usb_stor_probe_device(struct usb_device *udev)
if (ret)
return ret;
}
+
+   ret = device_probe(dev);
+   if (ret) {
+   device_unbind(dev);
+   return ret;
+   }
}
 #else
/* We don't have space to even probe if we hit the maximum */
-- 
2.33.0



[resent RFC 02/22] scsi: call device_probe() after scanning

2021-10-03 Thread AKASHI Takahiro
Every time a scsi bus/port is scanned and a new block device is detected,
we want to call device_probe() as it will give us a chance to run additional
post-processings for some purposes.

In particular, support for creating partitions on a device will be added.

Signed-off-by: AKASHI Takahiro 
---
 drivers/scsi/scsi.c | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
index d93d24192853..4865b5a86fd5 100644
--- a/drivers/scsi/scsi.c
+++ b/drivers/scsi/scsi.c
@@ -595,6 +595,16 @@ static int do_scsi_scan_one(struct udevice *dev, int id, 
int lun, bool verbose)
ata_swap_buf_le16((u16 *)>revision, sizeof(bd.revision) 
/ 2);
}
 
+   ret = device_probe(bdev);
+   if (ret < 0) {
+   debug("Can't probe\n");
+   /* TODO: undo create */
+
+   ret = device_unbind(bdev);
+
+   return ret;
+   }
+
if (verbose) {
printf("  Device %d: ", bdesc->devnum);
dev_print(bdesc);
-- 
2.33.0



[resent RFC 01/22] part: call part_init() in blk_get_device_by_str() only for MMC

2021-10-03 Thread AKASHI Takahiro
In blk_get_device_by_str(), the comment says: "Updates the partition table
for the specified hw partition."
Since hw partition is supported only on MMC, it makes no sense to do so
for other devices.

Signed-off-by: AKASHI Takahiro 
---
 disk/part.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/disk/part.c b/disk/part.c
index a6a8f7052bd3..b330103a5bc0 100644
--- a/disk/part.c
+++ b/disk/part.c
@@ -427,7 +427,8 @@ int blk_get_device_by_str(const char *ifname, const char 
*dev_hwpart_str,
 * Always should be done, otherwise hw partition 0 will return stale
 * data after displaying a non-zero hw partition.
 */
-   part_init(*dev_desc);
+   if ((*dev_desc)->if_type == IF_TYPE_MMC)
+   part_init(*dev_desc);
 #endif
 
 cleanup:
-- 
2.33.0



[resent RFC 00/22] efi_loader: more tightly integrate UEFI disks to device model

2021-10-03 Thread AKASHI Takahiro
# Resending the RFC as some of patches were deplicately submitted.
# See also
  https://git.linaro.org/people/takahiro.akashi/u-boot.git efi/dm_disk

The purpose of this RPC is to reignite the discussion about how UEFI
subystem would best be integrated into U-Boot device model.
In the past, I poposed a couple of patch series, the latest one[1],
while Heinrich revealed his idea[2], and the approach taken here is
something between them, with a focus on block device handlings.

# The code is a PoC and not well tested yet.

Disks in UEFI world:

In general in UEFI world, accessing to any device is performed through
a 'protocol' interface which are installed to (or associated with) the device's
UEFI handle (or an opaque pointer to UEFI object data). Protocols are
implemented by either the UEFI system itself or UEFI drivers.

For block IO's, it is a device which has EFI_BLOCK_IO_PROTOCOL (efi_disk
hereafter). Currently, every efi_disk may have one of two origins:
a.U-Boot's block devices or related partitions
  (lib/efi_loader/efi_disk.c)
b.UEFI objects which are implemented as a block device by UEFI drivers.
  (lib/efi_driver/efi_block_device.c)

All the efi_diskss as (a) will be enumelated and created only once at UEFI
subsystem initialization (efi_disk_register()), which is triggered by
first executing one of UEFI-related U-Boot commands, like "bootefi",
"setenv -e" or "efidebug".
EFI_BLOCK_IO_PROTOCOL is implemented by UEFI system using blk_desc(->ops)
in the corresponding udevice(UCLASS_BLK).

On the other hand, efi_disk as (b) will be created each time UEFI boot
services' connect_controller() is executed in UEFI app which, as a (device)
controller, gives the method to access the device's data,
ie. EFI_BLOCK_IO_PROTOCOL.

>>> more details >>>
Internally, connect_controller() search for UEFI driver that can support
this controller/protocol, 'efi_block' driver(UCLASS_EFI) in this case,
then calls the driver's 'bind' interface, which eventually installs
the controller's EFI_BLOCK_IO_PROTOCOL to efi_disk object.
'efi_block' driver also create a corresponding udevice(UCLASS_BLK) for
  * creating additional partitions efi_disk's, and
  * supporting a file system (EFI_SIMPLE_FILE_SYSTEM_PROTOCOL) on it.
<<< <<<

Issues:
===
1. While an efi_disk represents a device equally for either a whole disk
   or a partition in UEFI world, the device model treats only a whole
   disk as a real block device or udevice(UCLASS_BLK).

2. efi_disk holds and makes use of "blk_desc" data even though blk_desc
   in plat_data is supposed to be private and not to be accessed outside
   the device model.
   # This issue, though, exists for all the implmenetation of U-Boot
   # file systems as well.

For efi_disk(a),
3. A block device can be enumelated dynamically by 'scanning' a device bus
   in U-Boot, but UEFI subsystem is not able to update efi_disks accordingly.
   For examples,
=> scsi rescan; efidebug devices
=> usb start; efidebug devices ... (A)
   (A) doesn't show any usb devices detected.

=> scsi rescan; efidebug boot add -b 0 TEST scsi 0:1 ...
=> scsi rescan ... (B)
=> bootefi bootmgr ... (C)
   (C) may de-reference a bogus blk_desc pointer which has been freed by (B).
   (Please note that "scsi rescan" removes all udevices/blk_desc and then
re-create them even if nothing is changed on a bus.)

For efi_disk(b),
4. A controller (handle), combined with efi_block driver, has no
   corresponding udevice as a parent of efi_disks in DM tree, unlike, say,
   a scsi controller, even though it provides methods for block io perations.
5. There is no way supported to remove efi_disk's even after
   disconnect_controller() is called.


My approach in this RFC:

Due to functional differences in semantics, it would be difficult
to identify "udevice" structure as a handle in UEFI world. Instead, we will
have to somehow maintain a relationship between a udevice and a handle.

1-1. add a dedicated uclass, UCLASS_PARTITION, for partitions
   Currently, the uclass for paritions is not a UCLASS_BLK.
   It can be possible to define partitions as UCLASS_BLK
   (with IF_TYPE_PARTION?), but
   I'm afraid that it may introduce some chaos since udevice(UCLASS_BLK)
   is tightly coupled with 'struct blk_desc' data which is still used
   as a "structure to a whole disk" in a lot of interfaces.
   (I hope that you understand what it means.)

   In DM tree, a UCLASS_PARTITON instance has a UCLASS_BLK parent:
   For instance,
   UCLASS_SCSI  --- UCLASS_BLK   --- UCLASS_PARTITION
 (IF_TYPE_SCSI)|
  +- struct blk_desc   +- struct disk_part
  +- scsi_blk_ops  +- blk_part_ops

1-2. create partition udevices in the context of device_probe() 
   part_init() is already called in blk_post_probe(). See the commit
   d0851c893706 ("blk: Call part_init() in the post_probe() method").
   Why not enumelate 

Re: [RFC 07/22] dm: blk: add UCLASS_PARTITION

2021-10-03 Thread AKASHI Takahiro
On Fri, Oct 01, 2021 at 11:30:37AM +0200, Heinrich Schuchardt wrote:
> 
> 
> On 10/1/21 07:01, AKASHI Takahiro wrote:
> > UCLASS_PARTITION device will be created as a child node of
> > UCLASS_BLK device.
> > 
> > Signed-off-by: AKASHI Takahiro 
> > ---
> >   drivers/block/blk-uclass.c | 111 +
> >   include/blk.h  |   9 +++
> >   include/dm/uclass-id.h |   1 +
> >   3 files changed, 121 insertions(+)
> > 
> > diff --git a/drivers/block/blk-uclass.c b/drivers/block/blk-uclass.c
> > index 83682dcc181a..dd7f3c0fe31e 100644
> > --- a/drivers/block/blk-uclass.c
> > +++ b/drivers/block/blk-uclass.c
> > @@ -12,6 +12,7 @@
> >   #include 
> >   #include 
> >   #include 
> > +#include 
> >   #include 
> >   #include 
> >   #include 
> > @@ -695,6 +696,44 @@ int blk_unbind_all(int if_type)
> > return 0;
> >   }
> > 
> > +int blk_create_partitions(struct udevice *parent)
> > +{
> > +   int part, count;
> > +   struct blk_desc *desc = dev_get_uclass_plat(parent);
> > +   struct disk_partition info;
> > +   struct disk_part *part_data;
> > +   char devname[32];
> > +   struct udevice *dev;
> > +   int ret;
> > +
> > +   if (!CONFIG_IS_ENABLED(PARTITIONS) ||
> > +   !CONFIG_IS_ENABLED(HAVE_BLOCK_DEVICE))
> > +   return 0;
> > +
> > +   /* Add devices for each partition */
> > +   for (count = 0, part = 1; part <= MAX_SEARCH_PARTITIONS; part++) {
> > +   if (part_get_info(desc, part, ))
> > +   continue;
> > +   snprintf(devname, sizeof(devname), "%s:%d", parent->name,
> > +part);
> > +
> > +   ret = device_bind_driver(parent, "blk_partition",
> > +strdup(devname), );
> > +   if (ret)
> > +   return ret;
> > +
> > +   part_data = dev_get_uclass_plat(dev);
> > +   part_data->partnum = part;
> > +   part_data->gpt_part_info = info;
> > +   count++;
> > +
> > +   device_probe(dev);
> > +   }
> > +   debug("%s: %d partitions found in %s\n", __func__, count, parent->name);
> > +
> > +   return 0;
> > +}
> > +
> >   static int blk_post_probe(struct udevice *dev)
> >   {
> > if (IS_ENABLED(CONFIG_PARTITIONS) &&
> > @@ -713,3 +752,75 @@ UCLASS_DRIVER(blk) = {
> > .post_probe = blk_post_probe,
> > .per_device_plat_auto   = sizeof(struct blk_desc),
> >   };
> > +
> > +static ulong blk_part_read(struct udevice *dev, lbaint_t start,
> > +  lbaint_t blkcnt, void *buffer)
> > +{
> > +   struct udevice *parent;
> > +   struct disk_part *part;
> > +   const struct blk_ops *ops;
> > +
> > +   parent = dev_get_parent(dev);
> 
> What device type will the parent have if it is a eMMC hardware partition?
> 
> > +   ops = blk_get_ops(parent);
> > +   if (!ops->read)
> > +   return -ENOSYS;
> > +
> > +   part = dev_get_uclass_plat(dev);
> 
> You should check that we do not access the block device past the
> partition end:

Yes, I will fix all of checks.

-Takahiro Akashi

> struct blk_desc *desc = dev_get_uclass_plat(parent);
> if ((start + blkcnt) * desc->blksz < part->gpt_part_info.blksz)
>   return -EFAULT.
> 
> > +   start += part->gpt_part_info.start;
> > +
> > +   return ops->read(parent, start, blkcnt, buffer);
> > +}
> > +
> > +static ulong blk_part_write(struct udevice *dev, lbaint_t start,
> > +   lbaint_t blkcnt, const void *buffer)
> > +{
> > +   struct udevice *parent;
> > +   struct disk_part *part;
> > +   const struct blk_ops *ops;
> > +
> > +   parent = dev_get_parent(dev);
> > +   ops = blk_get_ops(parent);
> > +   if (!ops->write)
> > +   return -ENOSYS;
> > +
> > +   part = dev_get_uclass_plat(dev);
> > +   start += part->gpt_part_info.start;
> 
> here too
> 
> > +
> > +   return ops->write(parent, start, blkcnt, buffer);
> > +}
> > +
> > +static ulong blk_part_erase(struct udevice *dev, lbaint_t start,
> > +   lbaint_t blkcnt)
> > +{
> > +   struct udevice *parent;
> > +   struct disk_part *part;
> > +   const struct blk_ops *ops;
> > +
> > +   parent = dev_get_parent(dev);
> > +   ops = blk_get_ops(parent);
> > +   if (!ops->erase)
> > +   return -ENOSYS;
> > +
> > +   part = dev_get_uclass_plat(dev);
> > +   start += part->gpt_part_info.start;
> 
> here too
> 
> Best regards
> 
> Heinrich
> 
> > +
> > +   return ops->erase(parent, start, blkcnt);
> > +}
> > +
> > +static const struct blk_ops blk_part_ops = {
> > +   .read   = blk_part_read,
> > +   .write  = blk_part_write,
> > +   .erase  = blk_part_erase,
> > +};
> > +
> > +U_BOOT_DRIVER(blk_partition) = {
> > +   .name   = "blk_partition",
> > +   .id = UCLASS_PARTITION,
> > +   .ops= _part_ops,
> > +};
> > +
> > +UCLASS_DRIVER(partition) = {
> > +   .id = UCLASS_PARTITION,
> > +   .per_device_plat_auto   = sizeof(struct disk_part),
> > +   .name   = "partition",
> > +};
> > diff --git 

Re: [RFC 01/22] part: call part_init() in blk_get_device_by_str() only for MMC

2021-10-03 Thread AKASHI Takahiro
Hi Peter,

On Fri, Oct 01, 2021 at 12:48:24PM +0100, Peter Robinson wrote:
> On Fri, Oct 1, 2021 at 6:03 AM AKASHI Takahiro
>  wrote:
> >
> > In blk_get_device_by_str(), the comment says: "Updates the partition table
> > for the specified hw partition."
> > Since hw partition is supported only on MMC, it makes no sense to do so
> > for other devices.
> 
> Is it not also supported on UFS, and I believe it may also be an
> option in the NVME spec too.

Yeah, maybe.
But under the current implementation, IIUC, neither UFS nor NVME supports
hw partitions as both drivers do not provide a "select_hwpart" function
in blk_ops.
(UFS is seen as an instance of SCSI.)

-Takahiro Akashi


> > Signed-off-by: AKASHI Takahiro 
> > ---
> >  disk/part.c | 3 ++-
> >  1 file changed, 2 insertions(+), 1 deletion(-)
> >
> > diff --git a/disk/part.c b/disk/part.c
> > index a6a8f7052bd3..b330103a5bc0 100644
> > --- a/disk/part.c
> > +++ b/disk/part.c
> > @@ -427,7 +427,8 @@ int blk_get_device_by_str(const char *ifname, const 
> > char *dev_hwpart_str,
> >  * Always should be done, otherwise hw partition 0 will return stale
> >  * data after displaying a non-zero hw partition.
> >  */
> > -   part_init(*dev_desc);
> > +   if ((*dev_desc)->if_type == IF_TYPE_MMC)
> > +   part_init(*dev_desc);
> >  #endif
> >
> >  cleanup:
> > --
> > 2.33.0
> >


Re: [RFC 01/22] part: call part_init() in blk_get_device_by_str() only for MMC

2021-10-03 Thread AKASHI Takahiro
Heinrich,

On Fri, Oct 01, 2021 at 08:41:52AM +0200, Heinrich Schuchardt wrote:
> 
> 
> On 10/1/21 7:01 AM, AKASHI Takahiro wrote:
> > In blk_get_device_by_str(), the comment says: "Updates the partition table
> > for the specified hw partition."
> > Since hw partition is supported only on MMC, it makes no sense to do so
> > for other devices.
> > 
> > Signed-off-by: AKASHI Takahiro 
> > ---
> >   disk/part.c | 3 ++-
> >   1 file changed, 2 insertions(+), 1 deletion(-)
> > 
> > diff --git a/disk/part.c b/disk/part.c
> > index a6a8f7052bd3..b330103a5bc0 100644
> > --- a/disk/part.c
> > +++ b/disk/part.c
> > @@ -427,7 +427,8 @@ int blk_get_device_by_str(const char *ifname, const 
> > char *dev_hwpart_str,
> >  * Always should be done, otherwise hw partition 0 will return stale
> >  * data after displaying a non-zero hw partition.
> >  */
> > -   part_init(*dev_desc);
> > +   if ((*dev_desc)->if_type == IF_TYPE_MMC)
> > +   part_init(*dev_desc);
> 
> For an eMMC the following logical levels exist:
> 
> * device
> * hardware partition
> * software partition
> 
> Linux might show the following:
> 
> /dev/mmcblk0 - user data area
> /dev/mmcblk0boot0 - boot hardware partition 0
> /dev/mmcblk0boot1 - boot hardware partition 1
> /dev/mmcblk0rpmb - replay protected memory block
> 
> How are the different hardware partition modeled in the UEFI device path?
> Should each hardware partition be a separate udevice?
> 
> For NOR flash we also have an extra level:
> 
> => setenv mtdparts
> mtdparts=30bb.qspi:1m(U-Boot),512k(Env),512k(DTB),2m(User_FS),12m(Data_FS),4m(Factory_FS),34m(Ramdisk),10m(Linux)
> => mtd
> 
> device nor0 <30bb.qspi>, # parts = 8
>  #: namesizeoffset  mask_flags
>  0: U-Boot  0x0010  0x  0
>  1: Env 0x0008  0x0010  0
>  2: DTB 0x0008  0x0018  0
>  3: User_FS 0x0020  0x0020  0
>  4: Data_FS 0x00c0  0x0040  0
>  5: Factory_FS  0x0040  0x0100  0
>  6: Ramdisk 0x0220  0x0140  0
>  7: Linux   0x00a0  0x0360  0
> 
> active partition: nor0,0 - (U-Boot) 0x0010 @ 0x
> 
> Has part_info() to be called here too? What is the if_type?
> What are the devicepaths for these partitions?

You have good points.
MMC's hw partitions and mtd's "environment variable-based" partitions
are quite different from the rest of table-based software partitions
in terms of U-Boot block device implementation.
Both neither are handled by part_info() (under disk/* framework)
nor have dedicated "if_type's".

Even if we might have to address those issues at the end, I would like to
keep them out of my scope for now as it requires a lot of extra work.

# I wonder if we should support mtdparts partitions on U-Boot UEFI
# as it is a quite U-Boot specific feature.

-Takahiro Akashi


> Best regards
> 
> Heinrich
> 
> >   #endif
> > 
> >   cleanup:
> > 


Re: [PATCH v3 2/3] efi_loader: add UEFI GPT measurement

2021-10-03 Thread Masahisa Kojima
On Sat, 2 Oct 2021 at 01:28, Heinrich Schuchardt  wrote:
>
>
>
> On 10/1/21 13:18, Masahisa Kojima wrote:
> > This commit adds the UEFI GPT disk partition topology
> > measurement required in TCG PC Client PFP Spec.
> >
> > Signed-off-by: Masahisa Kojima 
> > ---
> >
> > Changes in v3:
> > - EV_EFI_GPT_EVENT is measured before EV_SEPARATOR, same as
> >other PCRs
> > - use PTR_ARRAY instead of ARRAY
> > - create sub-function of allocating io_aligned buffer
> > - move search_gpt_dp_node() into efi_device_path.c
> >
> >   include/blk.h|   3 +
> >   include/efi_loader.h |   3 +-
> >   include/efi_tcg2.h   |  12 +++
> >   lib/efi_loader/efi_boottime.c|   2 +-
> >   lib/efi_loader/efi_device_path.c |  27 +
> >   lib/efi_loader/efi_tcg2.c| 163 ++-
> >   6 files changed, 207 insertions(+), 3 deletions(-)
> >
> > diff --git a/include/blk.h b/include/blk.h
> > index 19bab081c2..f0cc7ca1a2 100644
> > --- a/include/blk.h
> > +++ b/include/blk.h
> > @@ -45,6 +45,9 @@ enum if_type {
> >   #define BLK_PRD_SIZE20
> >   #define BLK_REV_SIZE8
> >
> > +#define PART_FORMAT_PCAT 0x1
> > +#define PART_FORMAT_GPT  0x2
> > +
> >   /*
> >* Identifies the partition table type (ie. MBR vs GPT GUID) signature
> >*/
> > diff --git a/include/efi_loader.h b/include/efi_loader.h
> > index 13f0c24058..c557e8bee6 100644
> > --- a/include/efi_loader.h
> > +++ b/include/efi_loader.h
> > @@ -503,7 +503,7 @@ efi_status_t efi_init_variables(void);
> >   void efi_variables_boot_exit_notify(void);
> >   efi_status_t efi_tcg2_notify_exit_boot_services_failed(void);
> >   /* Measure efi application invocation */
> > -efi_status_t efi_tcg2_measure_efi_app_invocation(void);
> > +efi_status_t efi_tcg2_measure_efi_app_invocation(struct 
> > efi_loaded_image_obj *handle);
> >   /* Measure efi application exit */
> >   efi_status_t efi_tcg2_measure_efi_app_exit(void);
> >   /* Called by bootefi to initialize root node */
> > @@ -845,6 +845,7 @@ struct efi_device_path *efi_dp_from_lo(struct 
> > efi_load_option *lo,
> >  efi_uintn_t *size, efi_guid_t guid);
> >   struct efi_device_path *efi_dp_concat(const struct efi_device_path *dp1,
> > const struct efi_device_path *dp2);
> > +struct efi_device_path *search_gpt_dp_node(struct efi_device_path 
> > *device_path);
> >   efi_status_t efi_deserialize_load_option(struct efi_load_option *lo, u8 
> > *data,
> >efi_uintn_t *size);
> >   unsigned long efi_serialize_load_option(struct efi_load_option *lo, u8 
> > **data);
> > diff --git a/include/efi_tcg2.h b/include/efi_tcg2.h
> > index ca66695b39..50a59f9263 100644
> > --- a/include/efi_tcg2.h
> > +++ b/include/efi_tcg2.h
> > @@ -225,6 +225,18 @@ struct smbios_handoff_table_pointers2 {
> >   struct efi_configuration_table table_entry[];
> >   } __packed;
> >
> > +/**
> > + * struct tdUEFI_GPT_DATA - event log structure of industry standard tables
> > + * @uefi_partition_header:   gpt partition header
> > + * @number_of_partitions:the number of partition
> > + * @partitions:  partition entries
> > + */
> > +struct efi_gpt_data {
> > + gpt_header uefi_partition_header;
> > + u64 number_of_partitions;
> > + gpt_entry partitions[];
> > +} __packed;
> > +
> >   struct efi_tcg2_protocol {
> >   efi_status_t (EFIAPI * get_capability)(struct efi_tcg2_protocol *this,
> >  struct 
> > efi_tcg2_boot_service_capability *capability);
> > diff --git a/lib/efi_loader/efi_boottime.c b/lib/efi_loader/efi_boottime.c
> > index 701e2212c8..bf5661e1ee 100644
> > --- a/lib/efi_loader/efi_boottime.c
> > +++ b/lib/efi_loader/efi_boottime.c
> > @@ -3003,7 +3003,7 @@ efi_status_t EFIAPI efi_start_image(efi_handle_t 
> > image_handle,
> >
> >   if (IS_ENABLED(CONFIG_EFI_TCG2_PROTOCOL)) {
> >   if (image_obj->image_type == IMAGE_SUBSYSTEM_EFI_APPLICATION) 
> > {
> > - ret = efi_tcg2_measure_efi_app_invocation();
> > + ret = efi_tcg2_measure_efi_app_invocation(image_obj);
> >   if (ret != EFI_SUCCESS) {
> >   log_warning("tcg2 measurement fails(0x%lx)\n",
> >   ret);
> > diff --git a/lib/efi_loader/efi_device_path.c 
> > b/lib/efi_loader/efi_device_path.c
> > index cbdb466da4..6aec64f373 100644
> > --- a/lib/efi_loader/efi_device_path.c
> > +++ b/lib/efi_loader/efi_device_path.c
> > @@ -1294,3 +1294,30 @@ efi_device_path *efi_dp_from_lo(struct 
> > efi_load_option *lo,
> >
> >   return NULL;
> >   }
> > +
> > +/**
> > + * search_gpt_dp_node() - search gpt device path node
> > + *
> > + * @device_path: device path
> > + *
> > + * Return:   pointer to the gpt device path node
> > + */
> > +struct 

Re: [PATCH v3 3/3] efi_loader: add DeployedMode and AuditMode variable measurement

2021-10-03 Thread Masahisa Kojima
On Sat, 2 Oct 2021 at 01:43, Heinrich Schuchardt  wrote:
>
>
>
> On 10/1/21 13:18, Masahisa Kojima wrote:
> > This commit adds the DeployedMode and AuditMode variable
> > measurement required in TCG PC Client PFP Spec.
> >
> > Signed-off-by: Masahisa Kojima 
> > ---
> >
> > Changes in v3:
> > - read variable first, then mesure the variable
> >
> >   lib/efi_loader/efi_tcg2.c | 50 +++
> >   1 file changed, 50 insertions(+)
> >
> > diff --git a/lib/efi_loader/efi_tcg2.c b/lib/efi_loader/efi_tcg2.c
> > index 28e0362bf2..7fba4bc458 100644
> > --- a/lib/efi_loader/efi_tcg2.c
> > +++ b/lib/efi_loader/efi_tcg2.c
> > @@ -12,6 +12,7 @@
> >   #include 
> >   #include 
> >   #include 
> > +#include 
> >   #include 
> >   #include 
> >   #include 
> > @@ -1822,6 +1823,53 @@ out:
> >   return ret;
> >   }
> >
> > +/**
> > + * tcg2_measure_deployed_audit_mode() - measure deployedmode and auditmode
> > + *
> > + * @dev: TPM device
> > + *
> > + * Return:   status code
> > + */
> > +static efi_status_t tcg2_measure_deployed_audit_mode(struct udevice *dev)
> > +{
> > + u8 deployed_mode;
> > + u8 audit_mode;
> > + efi_uintn_t size;
> > + efi_status_t ret;
> > + u32 pcr_index;
> > +
> > + size = sizeof(deployed_mode);
> > + ret = efi_get_variable_int(L"DeployedMode", _global_variable_guid,
> > +NULL, , _mode, NULL);
> > + if (ret != EFI_SUCCESS)
> > + return ret;
> > +
> > + size = sizeof(audit_mode);
> > + ret = efi_get_variable_int(L"AuditMode", _global_variable_guid,
> > +NULL, , _mode, NULL);
> > + if (ret != EFI_SUCCESS)
> > + return ret;
> > +
> > + pcr_index = (deployed_mode ? 1 : 7);
> > +
> > + ret = tcg2_measure_variable(dev, pcr_index,
> > + EV_EFI_VARIABLE_DRIVER_CONFIG,
> > + L"DeployedMode",
> > + _global_variable_guid,
> > + size, _mode);
> > + if (ret != EFI_SUCCESS)
> > + return ret;
> > +
> > +
> > + ret = tcg2_measure_variable(dev, pcr_index,
> > + EV_EFI_VARIABLE_DRIVER_CONFIG,
> > + L"AuditMode",
> > + _global_variable_guid,
> > + size, _mode);
> > +
> > + return ret;
> > +}
> > +
> >   /**
> >* tcg2_measure_secure_boot_variable() - measure secure boot variables
> >*
> > @@ -1885,6 +1933,8 @@ static efi_status_t 
> > tcg2_measure_secure_boot_variable(struct udevice *dev)
> >   free(data);
> >   }
> >
> > + ret = tcg2_measure_deployed_audit_mode(dev);
>
> You do the same thing four times. A loop is preferable.

After your series(efi_loader: centralize known vendor GUIDs) is merged,
I will update this patch to use loop for the secure variables.

Thanks,
Masahisa Kojima

>
> Best regards
>
> Heinrich
>
> > +
> >   error:
> >   return ret;
> >   }
> >


[PATCH next v5 11/12] configs: aspeed: Make EXTRA_ENV_SETTINGS board specific

2021-10-03 Thread Chia-Wei Wang
Move CONFIG_EXTRA_ENV_SETTINGS to board-specific
configuration headers.

Signed-off-by: Chia-Wei Wang 
---
 include/configs/aspeed-common.h | 9 -
 include/configs/evb_ast2500.h   | 9 +
 include/configs/evb_ast2600.h   | 9 +
 3 files changed, 18 insertions(+), 9 deletions(-)

diff --git a/include/configs/aspeed-common.h b/include/configs/aspeed-common.h
index 5177bf20fa..96526e1a75 100644
--- a/include/configs/aspeed-common.h
+++ b/include/configs/aspeed-common.h
@@ -38,13 +38,4 @@
  */
 #define CONFIG_BOOTP_BOOTFILESIZE
 
-/*
- * Miscellaneous configurable options
- */
-
-#define CONFIG_EXTRA_ENV_SETTINGS \
-   "verify=yes\0"  \
-   "spi_dma=yes\0" \
-   ""
-
 #endif /* __AST_COMMON_CONFIG_H */
diff --git a/include/configs/evb_ast2500.h b/include/configs/evb_ast2500.h
index dc032c1a41..a886fd941e 100644
--- a/include/configs/evb_ast2500.h
+++ b/include/configs/evb_ast2500.h
@@ -13,4 +13,13 @@
 
 #define CONFIG_SYS_UBOOT_BASE  CONFIG_SYS_TEXT_BASE
 
+/* Memory Info */
+#define CONFIG_SYS_LOAD_ADDR   0x8300
+
+/* Misc */
+#define CONFIG_EXTRA_ENV_SETTINGS \
+   "verify=yes\0"  \
+   "spi_dma=yes\0" \
+   ""
+
 #endif /* __CONFIG_H */
diff --git a/include/configs/evb_ast2600.h b/include/configs/evb_ast2600.h
index 177a52eb91..d2aceb6663 100644
--- a/include/configs/evb_ast2600.h
+++ b/include/configs/evb_ast2600.h
@@ -10,4 +10,13 @@
 
 #define CONFIG_SYS_UBOOT_BASE  CONFIG_SYS_TEXT_BASE
 
+/* Memory Info */
+#define CONFIG_SYS_LOAD_ADDR   0x8300
+
+/* Misc */
+#define CONFIG_EXTRA_ENV_SETTINGS \
+   "verify=yes\0"  \
+   "spi_dma=yes\0" \
+   ""
+
 #endif /* __CONFIG_H */
-- 
2.17.1



[PATCH next v5 10/12] configs: ast2600-evb: Enable SPL FIT support

2021-10-03 Thread Chia-Wei Wang
Enable SPL FIT image load and verification support.
The HW accelerated SHA is also available with the
newly added support of the HACE HW hash engine.

The SPL thumb build is also enabled to keep the binary
less than 64KB to fit into the Aspeed secure boot design.

Signed-off-by: Chia-Wei Wang 
---
 configs/evb-ast2600_defconfig | 20 +---
 1 file changed, 17 insertions(+), 3 deletions(-)

diff --git a/configs/evb-ast2600_defconfig b/configs/evb-ast2600_defconfig
index 56ab885d9b..eba6940ec1 100644
--- a/configs/evb-ast2600_defconfig
+++ b/configs/evb-ast2600_defconfig
@@ -1,7 +1,8 @@
 CONFIG_ARM=y
 CONFIG_SYS_DCACHE_OFF=y
+CONFIG_SPL_SYS_THUMB_BUILD=y
 CONFIG_ARCH_ASPEED=y
-CONFIG_SYS_TEXT_BASE=0x1
+CONFIG_SYS_TEXT_BASE=0x8000
 CONFIG_ASPEED_AST2600=y
 CONFIG_TARGET_EVB_AST2600=y
 CONFIG_SPL_LIBCOMMON_SUPPORT=y
@@ -12,13 +13,17 @@ CONFIG_ENV_SIZE=0x1
 CONFIG_SYS_MALLOC_LEN=0x200
 CONFIG_DEFAULT_DEVICE_TREE="ast2600-evb"
 CONFIG_SPL_SERIAL=y
+CONFIG_SPL_STACK_R_ADDR=0x8300
 CONFIG_SPL_SIZE_LIMIT=0x1
 CONFIG_SPL=y
 # CONFIG_ARMV7_NONSEC is not set
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
 CONFIG_SYS_LOAD_ADDR=0x8300
 CONFIG_FIT=y
-# CONFIG_LEGACY_IMAGE_FORMAT is not set
+CONFIG_SPL_FIT_SIGNATURE=y
+CONFIG_SPL_LOAD_FIT=y
+CONFIG_SPL_LOAD_FIT_ADDRESS=0x1
+# CONFIG_USE_SPL_FIT_GENERATOR is not set
 CONFIG_USE_BOOTARGS=y
 CONFIG_BOOTARGS="console=ttyS4,115200n8 root=/dev/ram rw"
 CONFIG_USE_BOOTCOMMAND=y
@@ -26,8 +31,10 @@ CONFIG_BOOTCOMMAND="bootm 2010"
 # CONFIG_DISPLAY_CPUINFO is not set
 CONFIG_SPL_SIZE_LIMIT_SUBTRACT_GD=y
 CONFIG_SPL_SIZE_LIMIT_SUBTRACT_MALLOC=y
-# CONFIG_SPL_LEGACY_IMAGE_SUPPORT is not set
 CONFIG_SPL_SYS_MALLOC_SIMPLE=y
+CONFIG_SPL_STACK_R=y
+CONFIG_SPL_STACK_R_MALLOC_SIMPLE_LEN=0x200
+CONFIG_SPL_FIT_IMAGE_TINY=y
 CONFIG_SPL_DM_RESET=y
 CONFIG_SPL_RAM_SUPPORT=y
 CONFIG_SPL_RAM_DEVICE=y
@@ -47,6 +54,9 @@ CONFIG_REGMAP=y
 CONFIG_SPL_OF_TRANSLATE=y
 CONFIG_CLK=y
 CONFIG_SPL_CLK=y
+CONFIG_DM_HASH=y
+CONFIG_HASH_ASPEED=y
+CONFIG_ASPEED_ACRY=y
 CONFIG_DM_I2C=y
 CONFIG_MISC=y
 CONFIG_SPL_MISC=y
@@ -65,5 +75,9 @@ CONFIG_SYS_NS16550=y
 CONFIG_SYSRESET=y
 CONFIG_SPL_SYSRESET=y
 CONFIG_WDT=y
+CONFIG_SHA512_ALGO=y
+CONFIG_SHA512=y
+CONFIG_SHA384=y
 CONFIG_HEXDUMP=y
 # CONFIG_EFI_LOADER is not set
+CONFIG_PHANDLE_CHECK_SEQ=y
-- 
2.17.1



[PATCH next v5 12/12] configs: ast2600: Boot kernel FIT in DRAM

2021-10-03 Thread Chia-Wei Wang
AST2600 leverages the FIT hash/signature verification to fulfill
secure boot trust chain. To improve the performance and save SW
code size for those crypto operations, the two HW crypto engine,
HACE and ACRY, are enabled.

However, both of the engines can only access to data stored in
DRAM space. Therefore, we need to move the FIT image into DRAM
before the booting.

This patch update the CONFIG_BOOTCOMMAND to execute the pre-defined
ENV variable which consists of FIT image copy to memory and booting.

Signed-off-by: Chia-Wei Wang 
---
 configs/evb-ast2600_defconfig | 2 +-
 include/configs/evb_ast2600.h | 7 +++
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/configs/evb-ast2600_defconfig b/configs/evb-ast2600_defconfig
index eba6940ec1..abb156f13e 100644
--- a/configs/evb-ast2600_defconfig
+++ b/configs/evb-ast2600_defconfig
@@ -27,7 +27,7 @@ CONFIG_SPL_LOAD_FIT_ADDRESS=0x1
 CONFIG_USE_BOOTARGS=y
 CONFIG_BOOTARGS="console=ttyS4,115200n8 root=/dev/ram rw"
 CONFIG_USE_BOOTCOMMAND=y
-CONFIG_BOOTCOMMAND="bootm 2010"
+CONFIG_BOOTCOMMAND="run bootspi"
 # CONFIG_DISPLAY_CPUINFO is not set
 CONFIG_SPL_SIZE_LIMIT_SUBTRACT_GD=y
 CONFIG_SPL_SIZE_LIMIT_SUBTRACT_MALLOC=y
diff --git a/include/configs/evb_ast2600.h b/include/configs/evb_ast2600.h
index d2aceb6663..83002db317 100644
--- a/include/configs/evb_ast2600.h
+++ b/include/configs/evb_ast2600.h
@@ -14,7 +14,14 @@
 #define CONFIG_SYS_LOAD_ADDR   0x8300
 
 /* Misc */
+#define STR_HELPER(s)  #s
+#define STR(s) STR_HELPER(s)
+
 #define CONFIG_EXTRA_ENV_SETTINGS \
+   "loadaddr=" STR(CONFIG_SYS_LOAD_ADDR) "\0" \
+   "bootspi=fdt addr 2010 && fdt header get fitsize totalsize && " \
+   "cp.b 2010 ${loadaddr} ${fitsize} && bootm; " \
+   "echo Error loading kernel FIT image\0" \
"verify=yes\0"  \
"spi_dma=yes\0" \
""
-- 
2.17.1



[PATCH next v5 04/12] crypto: aspeed: Add AST2600 HACE support

2021-10-03 Thread Chia-Wei Wang
From: Johnny Huang 

Hash and Crypto Engine (HACE) is designed to accelerate the
throughput of hash data digest, and symmetric-key encryption.

Signed-off-by: Johnny Huang 
Signed-off-by: Chia-Wei Wang 
---
 drivers/crypto/Kconfig  |   2 +
 drivers/crypto/Makefile |   1 +
 drivers/crypto/aspeed/Kconfig   |  10 +
 drivers/crypto/aspeed/Makefile  |   1 +
 drivers/crypto/aspeed/aspeed_hace.c | 381 
 drivers/crypto/hash/Kconfig |   8 +
 6 files changed, 403 insertions(+)
 create mode 100644 drivers/crypto/aspeed/Kconfig
 create mode 100644 drivers/crypto/aspeed/Makefile
 create mode 100644 drivers/crypto/aspeed/aspeed_hace.c

diff --git a/drivers/crypto/Kconfig b/drivers/crypto/Kconfig
index 0082177c21..675081ecd3 100644
--- a/drivers/crypto/Kconfig
+++ b/drivers/crypto/Kconfig
@@ -4,4 +4,6 @@ source drivers/crypto/hash/Kconfig
 
 source drivers/crypto/fsl/Kconfig
 
+source drivers/crypto/aspeed/Kconfig
+
 endmenu
diff --git a/drivers/crypto/Makefile b/drivers/crypto/Makefile
index e8bae43e3f..6b762565a1 100644
--- a/drivers/crypto/Makefile
+++ b/drivers/crypto/Makefile
@@ -7,3 +7,4 @@ obj-$(CONFIG_EXYNOS_ACE_SHA)+= ace_sha.o
 obj-y += rsa_mod_exp/
 obj-y += fsl/
 obj-y += hash/
+obj-y += aspeed/
diff --git a/drivers/crypto/aspeed/Kconfig b/drivers/crypto/aspeed/Kconfig
new file mode 100644
index 00..471c06f986
--- /dev/null
+++ b/drivers/crypto/aspeed/Kconfig
@@ -0,0 +1,10 @@
+config ASPEED_HACE
+   bool "ASPEED Hash and Crypto Engine"
+   depends on DM_HASH
+   help
+ Select this option to enable a driver for using the SHA engine in
+ the ASPEED BMC SoCs.
+
+ Enabling this allows the use of SHA operations in hardware without
+ requiring the SHA software implementations. It also improves 
performance
+ and saves code size.
diff --git a/drivers/crypto/aspeed/Makefile b/drivers/crypto/aspeed/Makefile
new file mode 100644
index 00..84e6bfe82a
--- /dev/null
+++ b/drivers/crypto/aspeed/Makefile
@@ -0,0 +1 @@
+obj-$(CONFIG_ASPEED_HACE) += aspeed_hace.o
diff --git a/drivers/crypto/aspeed/aspeed_hace.c 
b/drivers/crypto/aspeed/aspeed_hace.c
new file mode 100644
index 00..1178cc6a76
--- /dev/null
+++ b/drivers/crypto/aspeed/aspeed_hace.c
@@ -0,0 +1,381 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright 2021 ASPEED Technology Inc.
+ */
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/* register offsets*/
+#define HACE_STS   0x1C
+#define   HACE_HASH_DATA_OVF   BIT(23)
+#define   HACE_HASH_INTBIT(9)
+#define   HACE_HASH_BUSY   BIT(0)
+#define HACE_HASH_DATA 0x20
+#define HACE_HASH_DIGEST   0x24
+#define HACE_HASH_HMAC_KEY 0x28
+#define HACE_HASH_DATA_LEN 0x2C
+#define HACE_HASH_CMD  0x30
+#define   HACE_HASH_MODE_ACCUM BIT(8)
+#define   HACE_HASH_ALGO_SHA1  BIT(5)
+#define   HACE_HASH_ALGO_SHA256(BIT(6) | BIT(4))
+#define   HACE_HASH_ALGO_SHA384(BIT(10) | BIT(6) | BIT(5))
+#define   HACE_HASH_ALGO_SHA512(BIT(6) | BIT(5))
+#define   HACE_HASH_SHA_BE_EN  BIT(3)
+
+/* buffer size based on SHA-512 need*/
+#define HASH_BLOCK_BUFSZ   128
+#define HASH_DIGEST_BUFSZ  64
+
+struct aspeed_hace_ctx {
+   uint8_t digest[HASH_DIGEST_BUFSZ];
+
+   uint32_t cmd;
+   enum HASH_ALGO algo;
+
+   uint32_t blk_size;
+   uint32_t pad_size;
+   uint64_t total[2];
+
+   uint8_t buf[HASH_BLOCK_BUFSZ];
+   uint32_t buf_cnt;
+} __aligned((8));
+
+struct aspeed_hace {
+   phys_addr_t base;
+   struct clk clk;
+};
+
+static const uint32_t iv_sha1[8] = {
+   0x01234567, 0x89abcdef, 0xfedcba98, 0x76543210,
+   0xf0e1d2c3, 0, 0, 0
+};
+
+static const uint32_t iv_sha256[8] = {
+   0x67e6096a, 0x85ae67bb, 0x72f36e3c, 0x3af54fa5,
+   0x7f520e51, 0x8c68059b, 0xabd9831f, 0x19cde05bUL
+};
+
+static const uint32_t iv_sha384[16] = {
+   0x5d9dbbcb, 0xd89e05c1, 0x2a299a62, 0x07d57c36,
+   0x5a015991, 0x17dd7030, 0xd8ec2f15, 0x39590ef7,
+   0x67263367, 0x310bc0ff, 0x874ab48e, 0x11155868,
+   0x0d2e0cdb, 0xa78ff964, 0x1d48b547, 0xa44ffabeUL
+};
+
+static const uint32_t iv_sha512[16] = {
+   0x67e6096a, 0x08c9bcf3, 0x85ae67bb, 0x3ba7ca84,
+   0x72f36e3c, 0x2bf894fe, 0x3af54fa5, 0xf1361d5f,
+   0x7f520e51, 0xd182e6ad, 0x8c68059b, 0x1f6c3e2b,
+   0xabd9831f, 0x6bbd41fb, 0x19cde05b, 0x79217e13UL
+};
+
+static int aspeed_hace_wait_completion(uint32_t reg, uint32_t flag, int 
timeout_us)
+{
+   uint32_t val;
+
+   return readl_poll_timeout(reg, val, (val & flag) == flag, timeout_us);
+}
+
+static int aspeed_hace_process(struct udevice *dev, void *ctx, const void 
*ibuf, uint32_t ilen)
+{
+   struct aspeed_hace *hace = dev_get_priv(dev);
+   

[PATCH next v5 03/12] clk: ast2600: Add YCLK control for HACE

2021-10-03 Thread Chia-Wei Wang
From: Joel Stanley 

Add YCLK enable for HACE, the HW hash engine of
ASPEED AST2600 SoCs.

Signed-off-by: Joel Stanley 
Signed-off-by: Chia-Wei Wang 
---
 .../arm/include/asm/arch-aspeed/scu_ast2600.h |  5 +++--
 drivers/clk/aspeed/clk_ast2600.c  | 20 +++
 2 files changed, 23 insertions(+), 2 deletions(-)

diff --git a/arch/arm/include/asm/arch-aspeed/scu_ast2600.h 
b/arch/arm/include/asm/arch-aspeed/scu_ast2600.h
index a205fb1f76..d7b500f656 100644
--- a/arch/arm/include/asm/arch-aspeed/scu_ast2600.h
+++ b/arch/arm/include/asm/arch-aspeed/scu_ast2600.h
@@ -10,8 +10,9 @@
 #define SCU_CLKGATE1_EMMC  BIT(27)
 #define SCU_CLKGATE1_MAC2  BIT(21)
 #define SCU_CLKGATE1_MAC1  BIT(20)
-#define SCU_CLKGATE1_USB_HUB   BIT(14)
-#define SCU_CLKGATE1_USB_HOST2 BIT(7)
+#define SCU_CLKGATE1_USB_HUB   BIT(14)
+#define SCU_CLKGATE1_HACE  BIT(13)
+#define SCU_CLKGATE1_USB_HOST2 BIT(7)
 
 #define SCU_CLKGATE2_FSI   BIT(30)
 #define SCU_CLKGATE2_MAC4  BIT(21)
diff --git a/drivers/clk/aspeed/clk_ast2600.c b/drivers/clk/aspeed/clk_ast2600.c
index 3a92739f5c..69128fd3c4 100644
--- a/drivers/clk/aspeed/clk_ast2600.c
+++ b/drivers/clk/aspeed/clk_ast2600.c
@@ -1013,6 +1013,23 @@ static ulong ast2600_enable_usbbhclk(struct ast2600_scu 
*scu)
return 0;
 }
 
+static ulong ast2600_enable_haceclk(struct ast2600_scu *scu)
+{
+   uint32_t reset_bit;
+   uint32_t clkgate_bit;
+
+   reset_bit = BIT(ASPEED_RESET_HACE);
+   clkgate_bit = SCU_CLKGATE1_HACE;
+
+   writel(reset_bit, >modrst_ctrl1);
+   udelay(100);
+   writel(clkgate_bit, >clkgate_clr1);
+   mdelay(20);
+   writel(reset_bit, >modrst_clr1);
+
+   return 0;
+}
+
 static int ast2600_clk_enable(struct clk *clk)
 {
struct ast2600_clk_priv *priv = dev_get_priv(clk->dev);
@@ -1051,6 +1068,9 @@ static int ast2600_clk_enable(struct clk *clk)
case ASPEED_CLK_GATE_USBPORT2CLK:
ast2600_enable_usbbhclk(priv->scu);
break;
+   case ASPEED_CLK_GATE_YCLK:
+   ast2600_enable_haceclk(priv->scu);
+   break;
default:
pr_err("can't enable clk\n");
return -ENOENT;
-- 
2.17.1



[PATCH next v5 09/12] ast2600: spl: Locate load buffer in DRAM space

2021-10-03 Thread Chia-Wei Wang
Return CONFIG_SYS_LOAD_ADDR pointing to DRAM space for
spl_get_load_buffer() to allow generic SPL image loading
code (e.g. FIT and Ymodem) to store data in DRAM.

Signed-off-by: Chia-Wei Wang 
---
 arch/arm/mach-aspeed/ast2600/spl.c | 9 +
 1 file changed, 1 insertion(+), 8 deletions(-)

diff --git a/arch/arm/mach-aspeed/ast2600/spl.c 
b/arch/arm/mach-aspeed/ast2600/spl.c
index 0d8cb29678..6c49d6aede 100644
--- a/arch/arm/mach-aspeed/ast2600/spl.c
+++ b/arch/arm/mach-aspeed/ast2600/spl.c
@@ -28,14 +28,7 @@ u32 spl_boot_device(void)
 
 struct image_header *spl_get_load_buffer(ssize_t offset, size_t size)
 {
-   /*
-* When boot from SPI, AST2600 already remap 0x ~ 0x0fff
-* to BMC SPI memory space 0x2000 ~ 0x2fff. The next stage BL
-* has been located in SPI for XIP. In this case, the load buffer for
-* SPL image loading will be set to the remapped address of the next
-* BL instead of the DRAM space CONFIG_SYS_LOAD_ADDR
-*/
-   return (struct image_header *)(CONFIG_SYS_TEXT_BASE);
+   return (struct image_header *)(CONFIG_SYS_LOAD_ADDR);
 }
 
 #ifdef CONFIG_SPL_OS_BOOT
-- 
2.17.1



[PATCH next v5 08/12] ARM: dts: ast2600: Add ACRY to device tree

2021-10-03 Thread Chia-Wei Wang
Add ACRY DTS node and enable it for AST2600 EVB.

Signed-off-by: Chia-Wei Wang 
---
 arch/arm/dts/ast2600-evb.dts | 5 +
 arch/arm/dts/ast2600.dtsi| 9 +
 2 files changed, 14 insertions(+)

diff --git a/arch/arm/dts/ast2600-evb.dts b/arch/arm/dts/ast2600-evb.dts
index adb80a30ef..05362d19bd 100644
--- a/arch/arm/dts/ast2600-evb.dts
+++ b/arch/arm/dts/ast2600-evb.dts
@@ -182,3 +182,8 @@
u-boot,dm-pre-reloc;
status = "okay";
 };
+
+ {
+   u-boot,dm-pre-reloc;
+   status = "okay";
+};
diff --git a/arch/arm/dts/ast2600.dtsi b/arch/arm/dts/ast2600.dtsi
index b8fe966c7d..31905fd208 100644
--- a/arch/arm/dts/ast2600.dtsi
+++ b/arch/arm/dts/ast2600.dtsi
@@ -195,6 +195,15 @@
status = "disabled";
};
 
+   acry: acry@1e6fa000 {
+   compatible = "aspeed,ast2600-acry";
+   reg = <0x1e6fa000 0x1000>,
+ <0x1e71 0x1>;
+   interrupts = ;
+   clocks = < ASPEED_CLK_GATE_RSACLK>;
+   status = "disabled";
+   };
+
edac: sdram@1e6e {
compatible = "aspeed,ast2600-sdram-edac";
reg = <0x1e6e 0x174>;
-- 
2.17.1



[PATCH next v5 07/12] crypto: aspeed: Add AST2600 ACRY support

2021-10-03 Thread Chia-Wei Wang
ACRY is deisnged to accerlerate ECC/RSA digital signature
generation and verification.

Signed-off-by: Chia-Wei Wang 
---
 drivers/crypto/aspeed/Kconfig   |  10 ++
 drivers/crypto/aspeed/Makefile  |   1 +
 drivers/crypto/aspeed/aspeed_acry.c | 182 
 lib/rsa/Kconfig |  10 +-
 4 files changed, 202 insertions(+), 1 deletion(-)
 create mode 100644 drivers/crypto/aspeed/aspeed_acry.c

diff --git a/drivers/crypto/aspeed/Kconfig b/drivers/crypto/aspeed/Kconfig
index 471c06f986..9bf317177a 100644
--- a/drivers/crypto/aspeed/Kconfig
+++ b/drivers/crypto/aspeed/Kconfig
@@ -8,3 +8,13 @@ config ASPEED_HACE
  Enabling this allows the use of SHA operations in hardware without
  requiring the SHA software implementations. It also improves 
performance
  and saves code size.
+
+config ASPEED_ACRY
+   bool "ASPEED RSA and ECC Engine"
+   depends on ASPEED_AST2600
+   help
+Select this option to enable a driver for using the RSA/ECC engine in
+the ASPEED BMC SoCs.
+
+Enabling this allows the use of RSA/ECC operations in hardware without 
requiring the
+software implementations. It also improves performance and saves code 
size.
diff --git a/drivers/crypto/aspeed/Makefile b/drivers/crypto/aspeed/Makefile
index 84e6bfe82a..58b55fc46e 100644
--- a/drivers/crypto/aspeed/Makefile
+++ b/drivers/crypto/aspeed/Makefile
@@ -1 +1,2 @@
 obj-$(CONFIG_ASPEED_HACE) += aspeed_hace.o
+obj-$(CONFIG_ASPEED_ACRY) += aspeed_acry.o
diff --git a/drivers/crypto/aspeed/aspeed_acry.c 
b/drivers/crypto/aspeed/aspeed_acry.c
new file mode 100644
index 00..0b948f828a
--- /dev/null
+++ b/drivers/crypto/aspeed/aspeed_acry.c
@@ -0,0 +1,182 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright 2021 ASPEED Technology Inc.
+ */
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/* ACRY register offsets */
+#define ACRY_CTRL1 0x00
+#define   ACRY_CTRL1_RSA_DMA   BIT(1)
+#define   ACRY_CTRL1_RSA_START BIT(0)
+#define ACRY_CTRL2 0x44
+#define ACRY_CTRL3 0x48
+#define   ACRY_CTRL3_SRAM_AHB_ACCESS   BIT(8)
+#define   ACRY_CTRL3_ECC_RSA_MODE_MASK GENMASK(5, 4)
+#define   ACRY_CTRL3_ECC_RSA_MODE_SHIFT4
+#define ACRY_DMA_DRAM_SADDR0x4c
+#define ACRY_DMA_DMEM_TADDR0x50
+#define   ACRY_DMA_DMEM_TADDR_LEN_MASK GENMASK(15, 0)
+#define   ACRY_DMA_DMEM_TADDR_LEN_SHIFT0
+#define ACRY_RSA_PARAM 0x58
+#define   ACRY_RSA_PARAM_EXP_MASK  GENMASK(31, 16)
+#define   ACRY_RSA_PARAM_EXP_SHIFT 16
+#define   ACRY_RSA_PARAM_MOD_MASK  GENMASK(15, 0)
+#define   ACRY_RSA_PARAM_MOD_SHIFT 0
+#define ACRY_RSA_INT_EN0x3f8
+#define   ACRY_RSA_INT_EN_RSA_READYBIT(2)
+#define   ACRY_RSA_INT_EN_RSA_CMPLTBIT(1)
+#define ACRY_RSA_INT_STS   0x3fc
+#define   ACRY_RSA_INT_STS_RSA_READY   BIT(2)
+#define   ACRY_RSA_INT_STS_RSA_CMPLT   BIT(1)
+
+/* misc. constant */
+#define ACRY_ECC_MODE  2
+#define ACRY_RSA_MODE  3
+#define ACRY_CTX_BUFSZ 0x600
+
+struct aspeed_acry {
+   phys_addr_t base;
+   phys_addr_t sram_base; /* internal sram */
+   struct clk clk;
+};
+
+static int aspeed_acry_mod_exp(struct udevice *dev, const uint8_t *sig, 
uint32_t sig_len,
+  struct key_prop *prop, uint8_t *out)
+{
+   int i, j;
+   u8 *ctx;
+   u8 *ptr;
+   u32 reg;
+   struct aspeed_acry *acry = dev_get_priv(dev);
+
+   ctx = memalign(16, ACRY_CTX_BUFSZ);
+   if (!ctx)
+   return -ENOMEM;
+
+   memset(ctx, 0, ACRY_CTX_BUFSZ);
+
+   ptr = (u8 *)prop->public_exponent;
+   for (i = prop->exp_len - 1, j = 0; i >= 0; --i) {
+   ctx[j] = ptr[i];
+   j++;
+   j = (j % 16) ? j : j + 32;
+   }
+
+   ptr = (u8 *)prop->modulus;
+   for (i = (prop->num_bits >> 3) - 1, j = 0; i >= 0; --i) {
+   ctx[j + 16] = ptr[i];
+   j++;
+   j = (j % 16) ? j : j + 32;
+   }
+
+   ptr = (u8 *)sig;
+   for (i = sig_len - 1, j = 0; i >= 0; --i) {
+   ctx[j + 32] = ptr[i];
+   j++;
+   j = (j % 16) ? j : j + 32;
+   }
+
+   writel((u32)ctx, acry->base + ACRY_DMA_DRAM_SADDR);
+
+   reg = (((prop->exp_len << 3) << ACRY_RSA_PARAM_EXP_SHIFT) & 
ACRY_RSA_PARAM_EXP_MASK) |
+ ((prop->num_bits << ACRY_RSA_PARAM_MOD_SHIFT) & 
ACRY_RSA_PARAM_MOD_MASK);
+   writel(reg, acry->base + ACRY_RSA_PARAM);
+
+   reg = (ACRY_CTX_BUFSZ << ACRY_DMA_DMEM_TADDR_LEN_SHIFT) & 
ACRY_DMA_DMEM_TADDR_LEN_MASK;
+   writel(reg, acry->base + ACRY_DMA_DMEM_TADDR);
+
+   reg = (ACRY_RSA_MODE << ACRY_CTRL3_ECC_RSA_MODE_SHIFT) & 
ACRY_CTRL3_ECC_RSA_MODE_MASK;
+   writel(reg, acry->base + ACRY_CTRL3);
+
+   writel(ACRY_CTRL1_RSA_DMA | ACRY_CTRL1_RSA_START, acry->base + 
ACRY_CTRL1);
+

[PATCH next v5 06/12] clk: ast2600: Add RSACLK control for ACRY

2021-10-03 Thread Chia-Wei Wang
Add RSACLK enable for ACRY, the HW RSA/ECC crypto engine
of ASPEED AST2600 SoCs.

As ACRY and HACE share the same reset control bit, we do not
perform the reset-hold-n-release operation during their clock
ungating process. Instead, only reset release is conducted to
prevent mutual interference.

Signed-off-by: Chia-Wei Wang 
---
 .../arm/include/asm/arch-aspeed/scu_ast2600.h |  1 +
 drivers/clk/aspeed/clk_ast2600.c  | 22 +--
 2 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/arch/arm/include/asm/arch-aspeed/scu_ast2600.h 
b/arch/arm/include/asm/arch-aspeed/scu_ast2600.h
index d7b500f656..7c5aab98b6 100644
--- a/arch/arm/include/asm/arch-aspeed/scu_ast2600.h
+++ b/arch/arm/include/asm/arch-aspeed/scu_ast2600.h
@@ -8,6 +8,7 @@
 #define SCU_UNLOCK_KEY 0x1688a8a8
 
 #define SCU_CLKGATE1_EMMC  BIT(27)
+#define SCU_CLKGATE1_ACRY  BIT(24)
 #define SCU_CLKGATE1_MAC2  BIT(21)
 #define SCU_CLKGATE1_MAC1  BIT(20)
 #define SCU_CLKGATE1_USB_HUB   BIT(14)
diff --git a/drivers/clk/aspeed/clk_ast2600.c b/drivers/clk/aspeed/clk_ast2600.c
index 69128fd3c4..f6ebf824aa 100644
--- a/drivers/clk/aspeed/clk_ast2600.c
+++ b/drivers/clk/aspeed/clk_ast2600.c
@@ -1018,11 +1018,26 @@ static ulong ast2600_enable_haceclk(struct ast2600_scu 
*scu)
uint32_t reset_bit;
uint32_t clkgate_bit;
 
+   /* share the same reset control bit with ACRY */
reset_bit = BIT(ASPEED_RESET_HACE);
clkgate_bit = SCU_CLKGATE1_HACE;
 
-   writel(reset_bit, >modrst_ctrl1);
-   udelay(100);
+   writel(clkgate_bit, >clkgate_clr1);
+   mdelay(20);
+   writel(reset_bit, >modrst_clr1);
+
+   return 0;
+}
+
+static ulong ast2600_enable_rsaclk(struct ast2600_scu *scu)
+{
+   uint32_t reset_bit;
+   uint32_t clkgate_bit;
+
+   /* share the same reset control bit with HACE */
+   reset_bit = BIT(ASPEED_RESET_HACE);
+   clkgate_bit = SCU_CLKGATE1_ACRY;
+
writel(clkgate_bit, >clkgate_clr1);
mdelay(20);
writel(reset_bit, >modrst_clr1);
@@ -1071,6 +1086,9 @@ static int ast2600_clk_enable(struct clk *clk)
case ASPEED_CLK_GATE_YCLK:
ast2600_enable_haceclk(priv->scu);
break;
+   case ASPEED_CLK_GATE_RSACLK:
+   ast2600_enable_rsaclk(priv->scu);
+   break;
default:
pr_err("can't enable clk\n");
return -ENOENT;
-- 
2.17.1



[PATCH next v5 05/12] ARM: dts: ast2600: Add HACE to device tree

2021-10-03 Thread Chia-Wei Wang
From: Joel Stanley 

Add HACE DTS node and enable it for AST2600 EVB.

Signed-off-by: Joel Stanley 
Signed-off-by: Chia-Wei Wang 
---
 arch/arm/dts/ast2600-evb.dts | 5 +
 arch/arm/dts/ast2600.dtsi| 8 
 2 files changed, 13 insertions(+)

diff --git a/arch/arm/dts/ast2600-evb.dts b/arch/arm/dts/ast2600-evb.dts
index 2abd31341c..adb80a30ef 100644
--- a/arch/arm/dts/ast2600-evb.dts
+++ b/arch/arm/dts/ast2600-evb.dts
@@ -177,3 +177,8 @@
  0x08 0x04
  0x08 0x04>;
 };
+
+ {
+   u-boot,dm-pre-reloc;
+   status = "okay";
+};
diff --git a/arch/arm/dts/ast2600.dtsi b/arch/arm/dts/ast2600.dtsi
index f121f547e6..b8fe966c7d 100644
--- a/arch/arm/dts/ast2600.dtsi
+++ b/arch/arm/dts/ast2600.dtsi
@@ -187,6 +187,14 @@
};
};
 
+   hace: hace@1e6d {
+   compatible = "aspeed,ast2600-hace";
+   reg = <0x1e6d 0x200>;
+   interrupts = ;
+   clocks = < ASPEED_CLK_GATE_YCLK>;
+   status = "disabled";
+   };
+
edac: sdram@1e6e {
compatible = "aspeed,ast2600-sdram-edac";
reg = <0x1e6e 0x174>;
-- 
2.17.1



[PATCH next v5 00/12] aspeed: Support secure boot chain with FIT image verification

2021-10-03 Thread Chia-Wei Wang
This patch series intends to provide a secure boot chain from SPL to Linux 
kernel
based on the hash and signature verification of FIT image paradigm.

To improve the performance and save code size (SPL is limited to 64KB due to 
HW-RoT),
the drviers of two HW crypto engine HACE and ACRY are also added for AST26xx 
SoCs.

As HACE and ACRY can only access to DRAM space, additional configuration and
boot command are also updated according to move each FIT image before its 
booting.

In addition, the common code of FIT image hash algorithm lookup is also revised
to leverage the HW accelerated calculation.

v5:
 - fix inconsistent parameter name due to parallel patch work

v4:
 - add new DM_HASH based driver for Aspeed HACE
 - remove SPL board init, which was originally used to probe non-DM HACE driver
 - fix typo of ARCY to ACRY
 - refactor defconfig based on the new Kconfig of U-Boot next branch

v3:
 - add SW work around for HACE HW DMA issue by resetting HACE
 - add reset control for HACE device tree node
 - sync all of the HACE error message to use debug()

v2:
 - update commit authors

Chia-Wei Wang (9):
  image: fit: Fix parameter name for hash algorithm
  aspeed: ast2600: Enlarge SRAM size
  clk: ast2600: Add RSACLK control for ACRY
  crypto: aspeed: Add AST2600 ACRY support
  ARM: dts: ast2600: Add ACRY to device tree
  ast2600: spl: Locate load buffer in DRAM space
  configs: ast2600-evb: Enable SPL FIT support
  configs: aspeed: Make EXTRA_ENV_SETTINGS board specific
  configs: ast2600: Boot kernel FIT in DRAM

Joel Stanley (2):
  clk: ast2600: Add YCLK control for HACE
  ARM: dts: ast2600: Add HACE to device tree

Johnny Huang (1):
  crypto: aspeed: Add AST2600 HACE support

 arch/arm/dts/ast2600-evb.dts  |  10 +
 arch/arm/dts/ast2600.dtsi |  17 +
 arch/arm/include/asm/arch-aspeed/platform.h   |   2 +-
 .../arm/include/asm/arch-aspeed/scu_ast2600.h |   6 +-
 arch/arm/mach-aspeed/ast2600/spl.c|   9 +-
 common/image-fit.c|   2 +-
 configs/evb-ast2600_defconfig |  22 +-
 drivers/clk/aspeed/clk_ast2600.c  |  38 ++
 drivers/crypto/Kconfig|   2 +
 drivers/crypto/Makefile   |   1 +
 drivers/crypto/aspeed/Kconfig |  20 +
 drivers/crypto/aspeed/Makefile|   2 +
 drivers/crypto/aspeed/aspeed_acry.c   | 182 +
 drivers/crypto/aspeed/aspeed_hace.c   | 381 ++
 drivers/crypto/hash/Kconfig   |   8 +
 include/configs/aspeed-common.h   |   9 -
 include/configs/evb_ast2500.h |   9 +
 include/configs/evb_ast2600.h |  16 +
 lib/rsa/Kconfig   |  10 +-
 19 files changed, 720 insertions(+), 26 deletions(-)
 create mode 100644 drivers/crypto/aspeed/Kconfig
 create mode 100644 drivers/crypto/aspeed/Makefile
 create mode 100644 drivers/crypto/aspeed/aspeed_acry.c
 create mode 100644 drivers/crypto/aspeed/aspeed_hace.c

-- 
2.17.1



[PATCH next v5 02/12] aspeed: ast2600: Enlarge SRAM size

2021-10-03 Thread Chia-Wei Wang
The AST2600 SRAM has been extended to 88KB since A1
chip revision. This patch updates the SRAM size to
offer more space for early stack/heap use.

Signed-off-by: Chia-Wei Wang 
---
 arch/arm/include/asm/arch-aspeed/platform.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm/include/asm/arch-aspeed/platform.h 
b/arch/arm/include/asm/arch-aspeed/platform.h
index d50ec5f8a9..589abd4a3f 100644
--- a/arch/arm/include/asm/arch-aspeed/platform.h
+++ b/arch/arm/include/asm/arch-aspeed/platform.h
@@ -17,7 +17,7 @@
 #define ASPEED_MAC_COUNT   4
 #define ASPEED_DRAM_BASE   0x8000
 #define ASPEED_SRAM_BASE   0x1000
-#define ASPEED_SRAM_SIZE   0x1
+#define ASPEED_SRAM_SIZE   0x16000
 #else
 #err "Unrecognized Aspeed platform."
 #endif
-- 
2.17.1



[PATCH next v5 01/12] image: fit: Fix parameter name for hash algorithm

2021-10-03 Thread Chia-Wei Wang
Fix inconsistent function parameter name of the hash algorithm.

Signed-off-by: Chia-Wei Wang 
Fixes: 92055e138f2 ("image: Drop if/elseif hash selection in calculate_hash()")
---
 common/image-fit.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/common/image-fit.c b/common/image-fit.c
index 5a0a0cc200..9e8a1f36c1 100644
--- a/common/image-fit.c
+++ b/common/image-fit.c
@@ -1229,7 +1229,7 @@ int calculate_hash(const void *data, int data_len, const 
char *name,
return -1;
}
 
-   hash_algo = hash_algo_lookup_by_name(algo);
+   hash_algo = hash_algo_lookup_by_name(name);
if (hash_algo == HASH_ALGO_INVALID) {
debug("Unsupported hash algorithm\n");
return -1;
-- 
2.17.1



RE: [PATCH next v4 09/11] configs: ast2600-evb: Enable SPL FIT support

2021-10-03 Thread ChiaWei Wang
Hi Tom,

> From: Tom Rini 
> Sent: Monday, October 4, 2021 2:41 AM
> 
> On Thu, Sep 16, 2021 at 04:52:19PM +0800, Chia-Wei Wang wrote:
> 
> > Enable SPL FIT image load and verification support.
> > The HW accelerated SHA is also available with the newly added support
> > of the HACE HW hash engine.
> >
> > The SPL thumb build is also enabled to keep the binary less than 64KB
> > to fit into the Aspeed secure boot design.
> >
> > Signed-off-by: Chia-Wei Wang 
> 
> This causes the board to fail to build:
>arm:  +   evb-ast2600
> +(evb-ast2600) common/image-fit.c: In function 'calculate_hash':
> +(evb-ast2600) common/image-fit.c:1232:46: error: 'algo' undeclared (first use
> in this function)
> +(evb-ast2600)  1232 | hash_algo =
> hash_algo_lookup_by_name(algo);
> +(evb-ast2600)   |
> ^~~~
> +(evb-ast2600) common/image-fit.c:1232:46: note: each undeclared
> +identifier is reported only once for each function it appears in
> +(evb-ast2600) make[2]: *** [common/image-fit.o] Error 1
> +(evb-ast2600) make[1]: *** [common] Error 2
> +(evb-ast2600) make: *** [sub-make] Error 2
> 
> Please rebase and repost the series, thanks!

Thanks! Will rebase to fix and send v5 ASAP.

Regards,
Chiawei


[RFC 3/3] usb: ehci-omap: Enable phy drivers to enable/reset phy

2021-10-03 Thread Adam Ford
Several omap boards use CONFIG_OMAP_EHCI_PHYx_RESET_GPIO to pull
the phy out of reset, when this should really be done inside the
phy driver.  Add functions to determine which phys are associated
the EHCI driver, hold them in reset before EHCI is initialized,
initialize the EHCI, then release the phys from reset.

Signed-off-by: Adam Ford 
---
This is an RFC because it hangs when generic_phy_get_bulk is called,
and more specifically dev_read_prop is hanging when called by
generic_phy_get_bulk.

The nop_phy shows before 'usb start' is run.
phy   0  [   ]   nop_phy   |-- hsusb2_phy

diff --git a/drivers/usb/host/ehci-omap.c b/drivers/usb/host/ehci-omap.c
index 324d2c0db1..3e707ccef5 100644
--- a/drivers/usb/host/ehci-omap.c
+++ b/drivers/usb/host/ehci-omap.c
@@ -17,7 +17,6 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
@@ -128,41 +127,6 @@ static void omap_ehci_soft_phy_reset(int port)
 }
 #endif
 
-#if defined(CONFIG_OMAP_EHCI_PHY1_RESET_GPIO) || \
-   defined(CONFIG_OMAP_EHCI_PHY2_RESET_GPIO) || \
-   defined(CONFIG_OMAP_EHCI_PHY3_RESET_GPIO)
-/* controls PHY(s) reset signal(s) */
-static inline void omap_ehci_phy_reset(int on, int delay)
-{
-   /*
-* Refer ISSUE1:
-* Hold the PHY in RESET for enough time till
-* PHY is settled and ready
-*/
-   if (delay && !on)
-   udelay(delay);
-#ifdef CONFIG_OMAP_EHCI_PHY1_RESET_GPIO
-   gpio_request(CONFIG_OMAP_EHCI_PHY1_RESET_GPIO, "USB PHY1 reset");
-   gpio_direction_output(CONFIG_OMAP_EHCI_PHY1_RESET_GPIO, !on);
-#endif
-#ifdef CONFIG_OMAP_EHCI_PHY2_RESET_GPIO
-   gpio_request(CONFIG_OMAP_EHCI_PHY2_RESET_GPIO, "USB PHY2 reset");
-   gpio_direction_output(CONFIG_OMAP_EHCI_PHY2_RESET_GPIO, !on);
-#endif
-#ifdef CONFIG_OMAP_EHCI_PHY3_RESET_GPIO
-   gpio_request(CONFIG_OMAP_EHCI_PHY3_RESET_GPIO, "USB PHY3 reset");
-   gpio_direction_output(CONFIG_OMAP_EHCI_PHY3_RESET_GPIO, !on);
-#endif
-
-   /* Hold the PHY in RESET for enough time till DIR is high */
-   /* Refer: ISSUE1 */
-   if (delay && on)
-   udelay(delay);
-}
-#else
-#define omap_ehci_phy_reset(on, delay) do {} while (0)
-#endif
-
 /*
  * Initialize the OMAP EHCI controller and PHY.
  * Based on "drivers/usb/host/ehci-omap.c" from Linux 3.1
@@ -180,9 +144,6 @@ int omap_ehci_hcd_init(int index, struct 
omap_usbhs_board_data *usbhs_pdata)
if (ret < 0)
return ret;
 
-   /* Put the PHY in RESET */
-   omap_ehci_phy_reset(1, 10);
-
ret = omap_uhh_reset();
if (ret < 0)
return ret;
@@ -260,8 +221,6 @@ int omap_ehci_hcd_init(int index, struct 
omap_usbhs_board_data *usbhs_pdata)
if (is_ehci_hsic_mode(usbhs_pdata->port_mode[i]))
omap_usbhs_hsic_init(i);
 
-   omap_ehci_phy_reset(0, 10);
-
/*
 * An undocumented "feature" in the OMAP3 EHCI controller,
 * causes suspended ports to be taken out of suspend when
@@ -337,7 +296,7 @@ struct ehci_omap_priv_data {
 #endif
enum usb_init_type init_type;
int portnr;
-   struct phy phy[OMAP_HS_USB_PORTS];
+   struct phy_bulk *phys;
int nports;
 };
 
@@ -356,6 +315,7 @@ static int omap_ehci_probe(struct udevice *dev)
struct ehci_omap_priv_data *priv = dev_get_priv(dev);
struct ehci_hccr *hccr;
struct ehci_hcor *hcor;
+   int i, ret;
 
priv->ehci = dev_read_addr_ptr(dev);
priv->portnr = dev_seq(dev);
@@ -364,7 +324,34 @@ static int omap_ehci_probe(struct udevice *dev)
hccr = (struct ehci_hccr *)>ehci->hccapbase;
hcor = (struct ehci_hcor *)>ehci->usbcmd;
 
-   return ehci_register(dev, hccr, hcor, NULL, 0, USB_INIT_HOST);
+   /* Identify Phys */
+   ret = generic_phy_get_bulk(dev, priv->phys);
+   if (ret) {
+   printf("Failed to get bulk phys\n");
+   return ret;
+   }
+
+   /* Hold Phys in reset */
+   for (i = 0; i < priv->phys->count; i++) {
+   ret = generic_phy_reset(>phys->phys[i]);
+   if (ret) {
+   printf("Failed to register EHCI\n");
+   return ret;
+   }
+   }
+
+   /* Register the EHCI */
+   ret = ehci_register(dev, hccr, hcor, NULL, 0, USB_INIT_HOST);
+   if (ret) {
+   printf("Failed to register EHCI\n");
+   return ret;
+   }
+
+   /* Pull the phys out of reset */
+   ret = generic_phy_init_bulk(priv->phys);
+   if (ret)
+   printf("Failed to initialize phys\n");
+   return ret;
 }
 
 static const struct udevice_id omap_ehci_dt_ids[] = {
-- 
2.25.1



[RFC 2/3] phy: nop-phy: Enable reset-gpios support

2021-10-03 Thread Adam Ford
Some usb-nop-xceiv devices use a gpio to put them
in reset.  Add a reset function to put them into that
state, and have the init function take them out of reset

Signed-off-by: Adam Ford 

diff --git a/drivers/phy/nop-phy.c b/drivers/phy/nop-phy.c
index 9f12ebc062..be993a764f 100644
--- a/drivers/phy/nop-phy.c
+++ b/drivers/phy/nop-phy.c
@@ -10,11 +10,24 @@
 #include 
 #include 
 #include 
+#include 
 
 struct nop_phy_priv {
struct clk_bulk bulk;
+   struct gpio_desc reset_gpio;
 };
 
+static int nop_phy_reset(struct phy *phy)
+{
+   struct nop_phy_priv *priv = dev_get_priv(phy->dev);
+
+   /* Return if there is no gpio since it's optional */
+   if (!dm_gpio_is_valid(>reset_gpio))
+   return 0;
+
+   return dm_gpio_set_value(>reset_gpio, false);
+}
+
 static int nop_phy_init(struct phy *phy)
 {
struct nop_phy_priv *priv = dev_get_priv(phy->dev);
@@ -22,7 +35,12 @@ static int nop_phy_init(struct phy *phy)
if (CONFIG_IS_ENABLED(CLK))
return clk_enable_bulk(>bulk);
 
-   return 0;
+   /* Return if there is no gpio since it's optional */
+   if (!dm_gpio_is_valid(>reset_gpio))
+   return 0;
+
+   /* If there is a reset gpio, take it out of reset */
+   return dm_gpio_set_value(>reset_gpio, true);
 }
 
 static int nop_phy_probe(struct udevice *dev)
@@ -38,6 +56,12 @@ static int nop_phy_probe(struct udevice *dev)
}
}
 
+   ret = gpio_request_by_name(dev, "reset-gpios", 0,
+  >reset_gpio,
+  GPIOD_IS_OUT);
+   if (ret != -ENOENT)
+   return ret;
+
return 0;
 }
 
@@ -49,6 +73,7 @@ static const struct udevice_id nop_phy_ids[] = {
 
 static struct phy_ops nop_phy_ops = {
.init = nop_phy_init,
+   .reset = nop_phy_reset,
 };
 
 U_BOOT_DRIVER(nop_phy) = {
-- 
2.25.1



[RFC 1/3] usb: ehci-omap: Remove dead code

2021-10-03 Thread Adam Ford
Since it's expected that DM_USB is enabled by now, remove some dead
code and the checks for DM_USB.

Signed-off-by: Adam Ford 

diff --git a/arch/arm/include/asm/ehci-omap.h b/arch/arm/include/asm/ehci-omap.h
index f970bba937..2b51b5eb99 100644
--- a/arch/arm/include/asm/ehci-omap.h
+++ b/arch/arm/include/asm/ehci-omap.h
@@ -123,17 +123,4 @@ struct omap_ehci {
u32 insreg08;   /* 0xb0 */
 };
 
-#if !CONFIG_IS_ENABLED(DM_USB) || !CONFIG_IS_ENABLED(OF_CONTROL)
-/*
- * FIXME: forward declaration of this structs needed because omap got the
- * ehci implementation backwards. move out ehci_hcd_x from board files
- */
-struct ehci_hccr;
-struct ehci_hcor;
-
-int omap_ehci_hcd_init(int index, struct omap_usbhs_board_data *usbhs_pdata,
-  struct ehci_hccr **hccr, struct ehci_hcor **hcor);
-int omap_ehci_hcd_stop(void);
-#endif
-
 #endif /* _OMAP_COMMON_EHCI_H_ */
diff --git a/drivers/usb/host/ehci-omap.c b/drivers/usb/host/ehci-omap.c
index 12c422d811..324d2c0db1 100644
--- a/drivers/usb/host/ehci-omap.c
+++ b/drivers/usb/host/ehci-omap.c
@@ -163,37 +163,14 @@ static inline void omap_ehci_phy_reset(int on, int delay)
 #define omap_ehci_phy_reset(on, delay) do {} while (0)
 #endif
 
-/* Reset is needed otherwise the kernel-driver will throw an error. */
-int omap_ehci_hcd_stop(void)
-{
-   debug("Resetting OMAP EHCI\n");
-   omap_ehci_phy_reset(1, 0);
-
-   if (omap_uhh_reset() < 0)
-   return -1;
-
-   if (omap_ehci_tll_reset() < 0)
-   return -1;
-
-   return 0;
-}
-
 /*
  * Initialize the OMAP EHCI controller and PHY.
  * Based on "drivers/usb/host/ehci-omap.c" from Linux 3.1
  * See there for additional Copyrights.
  */
-#if !CONFIG_IS_ENABLED(DM_USB) || !CONFIG_IS_ENABLED(OF_CONTROL)
 
-int omap_ehci_hcd_init(int index, struct omap_usbhs_board_data *usbhs_pdata,
-  struct ehci_hccr **hccr, struct ehci_hcor **hcor)
-{
-   *hccr = (struct ehci_hccr *)(OMAP_EHCI_BASE);
-   *hcor = (struct ehci_hcor *)(OMAP_EHCI_BASE + 0x10);
-#else
 int omap_ehci_hcd_init(int index, struct omap_usbhs_board_data *usbhs_pdata)
 {
-#endif
int ret;
unsigned int i, reg = 0, rev = 0;
 
@@ -304,8 +281,6 @@ int omap_ehci_hcd_init(int index, struct 
omap_usbhs_board_data *usbhs_pdata)
return 0;
 }
 
-#if CONFIG_IS_ENABLED(DM_USB)
-
 static struct omap_usbhs_board_data usbhs_bdata = {
.port_mode[0] = OMAP_USBHS_PORT_MODE_UNUSED,
.port_mode[1] = OMAP_USBHS_PORT_MODE_UNUSED,
@@ -409,5 +384,3 @@ U_BOOT_DRIVER(usb_omap_ehci) = {
.ops= _usb_ops,
.flags  = DM_FLAG_ALLOC_PRIV_DMA,
 };
-
-#endif
-- 
2.25.1



Re: [PATCH v8 5/5] iot2050: Enable watchdog support, but do not auto-start it

2021-10-03 Thread Tom Rini
On Sat, Sep 18, 2021 at 08:17:56AM +0200, Jan Kiszka wrote:

> From: Jan Kiszka 
> 
> This allows to use the watchdog in custom scripts but does not enforce
> that the OS has to support it as well.
> 
> Signed-off-by: Jan Kiszka 

Applied to u-boot/next, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH v8 4/5] watchdog: rti_wdt: Add support for loading firmware

2021-10-03 Thread Tom Rini
On Sat, Sep 18, 2021 at 08:17:55AM +0200, Jan Kiszka wrote:

> From: Jan Kiszka 
> 
> To avoid the need of extra boot scripting on AM65x for loading a
> watchdog firmware, add the required rproc init and loading logic for the
> first R5F core to the watchdog start handler. In case the R5F cluster is
> in lock-step mode, also initialize the second core. The firmware itself
> is embedded into U-Boot binary to ease access to it and ensure it is
> properly hashed in case of secure boot.
> 
> One possible firmware source is https://github.com/siemens/k3-rti-wdt.
> 
> The board is responsible for providing the firmware as additional
> loadable via the U-Boot fit image. The driver will pick up its location
> from /fit-images/k3-rti-wdt-firmware then.
> 
> Signed-off-by: Jan Kiszka 

Applied to u-boot/next, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH v8 2/5] board: siemens: Add support for SIMATIC IOT2050 devices

2021-10-03 Thread Tom Rini
On Sat, Sep 18, 2021 at 08:17:53AM +0200, Jan Kiszka wrote:

> From: Jan Kiszka 
> 
> This adds support for the IOT2050 Basic and Advanced devices. The Basic
> used the dual-core AM6528 GP processor, the Advanced one the AM6548 HS
> quad-core version.
> 
> Both variants are booted via a Siemens-provided FSBL that runs on the R5
> cores. Consequently, U-Boot support is targeting the A53 cores. U-Boot
> SPL, ATF and TEE have to reside in SPI flash.
> 
> Full integration into a bootable image can be found on
> https://github.com/siemens/meta-iot2050
> 
> Based on original board support by Le Jin, Gao Nian and Chao Zeng.
> 
> Signed-off-by: Jan Kiszka 

Applied to u-boot/next, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH v8 1/5] arm: dts: Add IOT2050 device tree files

2021-10-03 Thread Tom Rini
On Sat, Sep 18, 2021 at 08:17:52AM +0200, Jan Kiszka wrote:

> From: Jan Kiszka 
> 
> Prepares for the addition of the IOT2050 board which is based on the TI
> AM65x. The board comes in four variants, Basic and Advanced, each as
> product generation 1 (SR1.0) and 2 (SR2.x), so there are separate dts
> files needed. Furthermore, the SPL has its own device tree.
> 
> Based on original board support by Le Jin, Gao Nian and Chao Zeng.
> 
> Signed-off-by: Jan Kiszka 

Applied to u-boot/next, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH 11/11] pci: pcie_layerscape_fixup_common: lx2_board_fix_fdt can be static

2021-10-03 Thread Tom Rini
On Fri, Sep 17, 2021 at 03:11:30PM +0300, Vladimir Oltean wrote:

> To avoid W=1 build warnings, declare this function as static, since it
> is not used outside of this translation module.
> 
> Signed-off-by: Vladimir Oltean 
> Reviewed-by: Bin Meng 

Applied to u-boot/next, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH 10/11] pci: pcie_layerscape_fixup_common: include fdt_support.h for ft_pci_setup

2021-10-03 Thread Tom Rini
On Fri, Sep 17, 2021 at 03:11:29PM +0300, Vladimir Oltean wrote:

> The function prototype for ft_pci_setup is inside fdt_support.h, we need
> to include that header.
> 
> Signed-off-by: Vladimir Oltean 
> Reviewed-by: Bin Meng 

Applied to u-boot/next, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH 08/11] pci: _dm_pci_phys_to_bus can be static

2021-10-03 Thread Tom Rini
On Fri, Sep 17, 2021 at 03:11:27PM +0300, Vladimir Oltean wrote:

> To avoid W=1 build warnings, declare this function as static, since it
> is not used outside of this translation module.
> 
> Signed-off-by: Vladimir Oltean 
> Reviewed-by: Bin Meng 

Applied to u-boot/next, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH 09/11] pci: layerscape: ls_pcie_conf_address can be static

2021-10-03 Thread Tom Rini
On Fri, Sep 17, 2021 at 03:11:28PM +0300, Vladimir Oltean wrote:

> To avoid W=1 build warnings, declare this function as static, since it
> is not used outside of this translation module.
> 
> Signed-off-by: Vladimir Oltean 
> Reviewed-by: Bin Meng 

Applied to u-boot/next, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH 07/11] pci: pci_read_config can be static

2021-10-03 Thread Tom Rini
On Fri, Sep 17, 2021 at 03:11:26PM +0300, Vladimir Oltean wrote:

> To avoid W=1 build warnings, declare this function as static, since it
> is not used outside of this translation module.
> 
> Signed-off-by: Vladimir Oltean 
> Reviewed-by: Bin Meng 

Applied to u-boot/next, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH 06/11] pci: pci_write_config can be static

2021-10-03 Thread Tom Rini
On Fri, Sep 17, 2021 at 03:11:25PM +0300, Vladimir Oltean wrote:

> To avoid W=1 build warnings, declare this function as static, since it
> is not used outside of this translation module.
> 
> Signed-off-by: Vladimir Oltean 
> Reviewed-by: Bin Meng 

Applied to u-boot/next, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH 05/11] pci: pciinfo_header can be static

2021-10-03 Thread Tom Rini
On Fri, Sep 17, 2021 at 03:11:24PM +0300, Vladimir Oltean wrote:

> To avoid W=1 build warnings, declare this function as static, since it
> is not used outside of this translation module.
> 
> Signed-off-by: Vladimir Oltean 
> Reviewed-by: Bin Meng 

Applied to u-boot/next, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH 04/11] pci: pci_header_show can be static

2021-10-03 Thread Tom Rini
On Fri, Sep 17, 2021 at 03:11:23PM +0300, Vladimir Oltean wrote:

> To avoid W=1 build warnings, declare this function as static, since it
> is not used outside of this translation module.
> 
> Signed-off-by: Vladimir Oltean 
> Reviewed-by: Bin Meng 

Applied to u-boot/next, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH 03/11] pci: pci_bar_show can be static

2021-10-03 Thread Tom Rini
On Fri, Sep 17, 2021 at 03:11:22PM +0300, Vladimir Oltean wrote:

> To avoid W=1 build warnings, declare this function as static, since it
> is not used outside of this translation module.
> 
> Signed-off-by: Vladimir Oltean 
> Reviewed-by: Bin Meng 

Applied to u-boot/next, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH 02/11] pci: include pci_internal.h inside pci_auto.c

2021-10-03 Thread Tom Rini
On Fri, Sep 17, 2021 at 03:11:21PM +0300, Vladimir Oltean wrote:

> To avoid a build warning with W=1, provide a function prototype for
> dm_pciauto_prescan_setup_bridge, which is a non-static function whose
> definition is inside pci_auto.c.
> 
> Signed-off-by: Vladimir Oltean 
> Reviewed-by: Bin Meng 

Applied to u-boot/next, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH 01/11] pci: provide prototype for pci_skip_dev outside of #if defined(CONFIG_DM_PCI_COMPAT)

2021-10-03 Thread Tom Rini
On Fri, Sep 17, 2021 at 03:11:20PM +0300, Vladimir Oltean wrote:

> The weak definition of pci_skip_dev from drivers/pci/pci_common.c is not
> under CONFIG_DM_PCI_COMPAT, and that definition needs a previous
> function prototype declaration to avoid W=1 build warnings.
> 
> That prototype is not available due to it being under CONFIG_DM_PCI_COMPAT,
> so move it outside of that preprocessor block.
> 
> Signed-off-by: Vladimir Oltean 
> Reviewed-by: Bin Meng 

Applied to u-boot/next, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH 4/4] rtc: rx8025: revise single register write to use offset

2021-10-03 Thread Tom Rini
On Fri, Sep 17, 2021 at 06:46:04AM +, Mathew McBride wrote:

> Writing of individual registers was not functioning
> correctly as a 0 'offset' byte under DM-managed
> I2C was being appended in front of register we
> wanted to access.
> 
> Signed-off-by: Mathew McBride 

Applied to u-boot/next, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH 3/4] rtc: rx8025: set date in a single i2c transaction

2021-10-03 Thread Tom Rini
On Fri, Sep 17, 2021 at 06:46:03AM +, Mathew McBride wrote:

> The RX8025/RX8035 does not like having it's time registers
> set byte-by-byte in separate I2C transactions.
> 
> From the note at the top of the file, it appears
> target-dependent workarounds have been used in the
> past for this.
> 
> Resolve this by setting the time registers in a single
> I2C transaction.
> 
> As part of this, also ensure the '24/12' flag in the RTC
> is reset before writing the date (instead of after), otherwise
> the RX8035 will clear the seconds and minutes registers.
> 
> Tested on Traverse Ten64 (NXP LS1088A) with RX8035.
> 
> Signed-off-by: Mathew McBride 

Applied to u-boot/next, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH 2/4] rtc: rx8025: add support for EPSON RX8035.

2021-10-03 Thread Tom Rini
On Fri, Sep 17, 2021 at 06:46:02AM +, Mathew McBride wrote:

> The RX8035 is a newer model from EPSON which is
> very similar in operation to the RX8025.
> 
> The changes mirror similar ones that will be
> in Linux 5.15:
> https://lore.kernel.org/all/20210709044518.28769-2-m...@traverse.com.au/
> 
> The UBOOT_DRIVER ID has also been corrected, previously
> it declared itself as rx8010sj_rtc which is a different driver.
> 
> Signed-off-by: Mathew McBride 

Applied to u-boot/next, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH 1/4] rtc: rx8025: drop non-DM support

2021-10-03 Thread Tom Rini
On Fri, Sep 17, 2021 at 06:46:01AM +, Mathew McBride wrote:

> A search of the tree showed there is only one user
> of this driver (soon to be two) - board/socrates
> 
> The second user will be the Traverse Ten64 board.
> 
> Both these boards have DM_RTC.
> 
> Signed-off-by: Mathew McBride 

Applied to u-boot/next, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH] ARM: dts: ast2600: Make WDT by default disabled

2021-10-03 Thread Tom Rini
On Thu, Sep 16, 2021 at 02:10:09PM +0800, Chia-Wei Wang wrote:

> The WDT devices described in the general .dtsi file
> should be marked as "disabled" by default.
> 
> A WDT should be then enabled in the board specific
> .dts file on demands.
> 
> Signed-off-by: Chia-Wei Wang 
> Reviewed-by: Ryan Chen 

Applied to u-boot/next, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH] arm: ti: k3: Resync dts files and bindings with Linux Kernel v5.14

2021-10-03 Thread Tom Rini
On Fri, Sep 10, 2021 at 05:37:43PM -0400, Tom Rini wrote:

> This resyncs the dts files for all of the currently in-tree K3
> platforms, along with relevant bindings, with the v5.14 Linux Kernel
> release.  Of note are that the main-navss/mcu-navss nodes were renamed
> to main_navss / mcu_navss and so the u-boot.dtsi files needed to be
> updated to match.
> 
> Tested on j721e_evm and am65x_evm.
> 
> Signed-off-by: Tom Rini 

Applied to u-boot/next, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH] dt-bindings: pinctrl: k3: Synchronize with v5.14 kernel

2021-10-03 Thread Tom Rini
On Tue, Aug 31, 2021 at 01:12:24PM -0500, Nishanth Menon wrote:

> Synchronize with the upstream version as of v5.14 kernel tag
> 
> Signed-off-by: Nishanth Menon 

Applied to u-boot/next, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH 1/2] docs: dt: Fix a few grammar nits in the binding/schema docs

2021-10-03 Thread Randy Dunlap

On 10/3/21 11:50 AM, Simon Glass wrote:

Add missing hyphens and reword one sentence for clarity.

Signed-off-by: Simon Glass 
---

  .../devicetree/bindings/example-schema.yaml   | 14 -
  .../devicetree/bindings/writing-bindings.rst  |  2 +-
  .../devicetree/bindings/writing-schema.rst| 29 ++-
  3 files changed, 23 insertions(+), 22 deletions(-)



Reviewed-by: Randy Dunlap 

Thanks.
--
~Randy


[PATCH 2/2] dt-bindings: u-boot: Add an initial binding for config

2021-10-03 Thread Simon Glass
U-Boot makes use of the devicetree for its driver model. Devices are bound
based on the hardware description in the devicetree.

Since U-Boot is not an operating system, it has no command line or user
space to provide configuration and policy information. This must be made
available in some other way.

Therefore U-Boot uses devicetree for configuration and run-time control
and has done for approximately 9 years. This works extremely well in the
project and is very flexible. However the bindings have never been
incorporated in the devicetree bindings in the Linux tree. This could be
a good time to start this work as we try to create standard bindings for
communicating between firmware components.

Add an initial binding for this node, covering just the config node, which
is the main requirement. It is similar in concept to the chosen node, but
used for passing information between firmware components, instead of from
firmware to operating system.

Signed-off-by: Simon Glass 
---
Please be kind in your review. Some words about why this is needed are
included in the description in config.yaml file.

The last attempt to add just one property needed by U-Boot went into the
weeds 6 years ago, with what I see as confusion about the role of the
chosen node in devicetree[1].

I am trying again in the hope of reaching resolution rather than just
going around in circles with the 'devicetree is a hardware description'
argument :-)

Quoting from the introduction to latest devicetree spec[2]:

>>>
To initialize and boot a computer system, various software components
interact. Firmware might perform low-level initialization of the system
hardware before passing control to software such as an operating system,
bootloader, or  hypervisor. Bootloaders and hypervisors can, in turn,
load and transfer control to operating systems. Standard, consistent
interfaces and conventions facilitate the interactions between these
software components. In this document the term boot program is used to
generically refer to a software component that initializes the system
state and executes another software component referred to as a client
program.
<<<

This clearly envisages multiple software components in the firmware
domain and in fact that is the case today. They need some way to
communicate configuration data such as memory setup, runtime-feature
selection and developer conveniences. Devicetree seems ideal, at least for
components where the performance / memory requirements of devicetree are
affordable.

I hope that the Linux community (which owns the devicetree bindings) finds
this initiative valuable and acceptable.

[1] https://lists.denx.de/pipermail/u-boot/2015-July/218585.html
[2] https://github.com/devicetree-org/devicetree-specification/releases/tag/v0.3

 .../devicetree/bindings/u-boot/config.yaml| 137 ++
 1 file changed, 137 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/u-boot/config.yaml

diff --git a/Documentation/devicetree/bindings/u-boot/config.yaml 
b/Documentation/devicetree/bindings/u-boot/config.yaml
new file mode 100644
index 00..336577a17fdf5a
--- /dev/null
+++ b/Documentation/devicetree/bindings/u-boot/config.yaml
@@ -0,0 +1,137 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/u-boot/config.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: U-Boot configuration node
+
+maintainers:
+  - Simon Glass 
+
+description: |
+  The config node does not represent a real device, but serves as a place
+  for passing data between firmware elements, like memory maps. Data in the
+  config node does not represent the hardware. It is ignored by operating
+  systems.
+
+  Purpose of config node
+  --
+
+  A common problem with firmware is that many builds are needed to deal with 
the
+  slight variations between different, related models. For example, one model
+  may have a TPM and another may not. Devicetree provides an excellent solution
+  to this problem, in that the devicetree to actually use on a platform can be
+  injected in the factory based on which model is being manufactured at the 
time.
+
+  A related problem causing build proliferation is dealing with the differences
+  between development firmware, developer-friendly firmware (e.g. with all
+  security features present but with the ability to access the command line),
+  test firmware (which runs tests used in the factory), final production
+  firmware (before signing), signed firmware (where the signatures have been
+  inserted) and the like. Ideally all or most of these should use the same
+  U-Boot build, with just some options to determine the features available. For
+  example, being able to control whether the UART console or JTAG are 
available,
+  on any image, is a great debugging aid.
+
+  When the firmware consists of multiple parts (various U-Boot phases, TF-A,
+  OP-TEE), it is helpful that all 

[PATCH 1/2] docs: dt: Fix a few grammar nits in the binding/schema docs

2021-10-03 Thread Simon Glass
Add missing hyphens and reword one sentence for clarity.

Signed-off-by: Simon Glass 
---

 .../devicetree/bindings/example-schema.yaml   | 14 -
 .../devicetree/bindings/writing-bindings.rst  |  2 +-
 .../devicetree/bindings/writing-schema.rst| 29 ++-
 3 files changed, 23 insertions(+), 22 deletions(-)

diff --git a/Documentation/devicetree/bindings/example-schema.yaml 
b/Documentation/devicetree/bindings/example-schema.yaml
index ff6ec65145cf13..c078796ae1b556 100644
--- a/Documentation/devicetree/bindings/example-schema.yaml
+++ b/Documentation/devicetree/bindings/example-schema.yaml
@@ -119,7 +119,7 @@ properties:
 # valid for this binding.
 
   clock-frequency:
-# The type is set in the core schema. Per device schema only need to set
+# The type is set in the core schema. Per-device schema only need to set
 # constraints on the possible values.
 minimum: 100
 maximum: 40
@@ -133,24 +133,24 @@ properties:
   # *-supply is always a single phandle, so nothing more to define.
   foo-supply: true
 
-  # Vendor specific properties
+  # Vendor-specific properties
   #
-  # Vendor specific properties have slightly different schema requirements than
+  # Vendor-specific properties have slightly different schema requirements than
   # common properties. They must have at least a type definition and
   # 'description'.
   vendor,int-property:
-description: Vendor specific properties must have a description
+description: Vendor-specific properties must have a description
 $ref: /schemas/types.yaml#/definitions/uint32
 enum: [2, 4, 6, 8, 10]
 
   vendor,bool-property:
-description: Vendor specific properties must have a description. Boolean
+description: Vendor-specific properties must have a description. Boolean
   properties are one case where the json-schema 'type' keyword can be used
   directly.
 type: boolean
 
   vendor,string-array-property:
-description: Vendor specific properties should reference a type in the
+description: Vendor-specific properties should reference a type in the
   core schema.
 $ref: /schemas/types.yaml#/definitions/string-array
 items:
@@ -158,7 +158,7 @@ properties:
   - enum: [baz, boo]
 
   vendor,property-in-standard-units-microvolt:
-description: Vendor specific properties having a standard unit suffix
+description: Vendor-specific properties having a standard unit suffix
   don't need a type.
 enum: [ 100, 200, 300 ]
 
diff --git a/Documentation/devicetree/bindings/writing-bindings.rst 
b/Documentation/devicetree/bindings/writing-bindings.rst
index f7dfb98c156ee5..18d9e0689d4993 100644
--- a/Documentation/devicetree/bindings/writing-bindings.rst
+++ b/Documentation/devicetree/bindings/writing-bindings.rst
@@ -44,7 +44,7 @@ Properties
   of prior implementations. DO add new compatibles in case there are new
   features or bugs.
 
-- DO use a vendor prefix on device specific property names. Consider if
+- DO use a vendor prefix on device-specific property names. Consider if
   properties could be common among devices of the same class. Check other
   existing bindings for similar devices.
 
diff --git a/Documentation/devicetree/bindings/writing-schema.rst 
b/Documentation/devicetree/bindings/writing-schema.rst
index 23d6579aea2c26..ea21c72aeb37a6 100644
--- a/Documentation/devicetree/bindings/writing-schema.rst
+++ b/Documentation/devicetree/bindings/writing-schema.rst
@@ -4,7 +4,7 @@ Writing Devicetree Bindings in json-schema
 ==
 
 Devicetree bindings are written using json-schema vocabulary. Schema files are
-written in a JSON compatible subset of YAML. YAML is used instead of JSON as it
+written in a JSON-compatible subset of YAML. YAML is used instead of JSON as it
 is considered more human readable and has some advantages such as allowing
 comments (Prefixed with '#').
 
@@ -22,16 +22,16 @@ $id
   URI typically containing the binding's filename and path. For DT schema, it 
must
   begin with "http://devicetree.org/schemas/;. The URL is used in constructing
   references to other files specified in schema "$ref" properties. A $ref value
-  with a leading '/' will have the hostname prepended. A $ref value a relative
-  path or filename only will be prepended with the hostname and path components
-  of the current schema file's '$id' value. A URL is used even for local files,
-  but there may not actually be files present at those locations.
+  with a leading '/' will have the hostname prepended. A $ref value with only a
+  relative path or filename will be prepended with the hostname and path
+  components of the current schema file's '$id' value. A URL is used even for
+  local files, but there may not actually be files present at those locations.
 
 $schema
   Indicates the meta-schema the schema file adheres to.
 
 title
-  A one line description on the contents of the binding schema.
+  A one-line 

Re: [PATCH v8 3/5] arm64: dts: ti: k3-am65-mcu: Add RTI watchdog entry

2021-10-03 Thread Tom Rini
On Sat, Sep 18, 2021 at 08:17:54AM +0200, Jan Kiszka wrote:

> From: Jan Kiszka 
> 
> Add the DT entry for a watchdog based on RTI1. It requires additional
> firmware on the MCU R5F cores to handle the expiry, e.g.
> https://github.com/siemens/k3-rti-wdt. As this firmware will also lock
> the power domain to protect it against premature shutdown, mark it
> shared.
> 
> Aligns us to the kernel's DT in this regard.
> 
> Signed-off-by: Jan Kiszka 
> ---
>  arch/arm/dts/k3-am65-mcu.dtsi | 9 +
>  1 file changed, 9 insertions(+)
> 
> diff --git a/arch/arm/dts/k3-am65-mcu.dtsi b/arch/arm/dts/k3-am65-mcu.dtsi
> index 7454c8cec0..903796bf7d 100644
> --- a/arch/arm/dts/k3-am65-mcu.dtsi
> +++ b/arch/arm/dts/k3-am65-mcu.dtsi
> @@ -308,4 +308,13 @@
>   ti,loczrama = <1>;
>   };
>   };
> +
> + mcu_rti1: rti@4061 {
> + compatible = "ti,j7-rti-wdt";
> + reg = <0x0 0x4061 0x0 0x100>;
> + clocks = <_clks 135 0>;
> + power-domains = <_pds 135 TI_SCI_PD_SHARED>;
> + assigned-clocks = <_clks 135 0>;
> + assigned-clock-parents = <_clks 135 4>;
> + };
>  };

So, in applying
https://patchwork.ozlabs.org/project/uboot/patch/20210910213743.30793-1-tr...@konsulko.com/
to bring us fully to v5.14 for K3 platforms, this patch is no longer
needed, and I'm deferring it.  The only difference is the node name is
"watchdog@4061" not "rti@4061" but should not matter (and
doesn't look to from a quick read of the rest of the series.

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH next v4 09/11] configs: ast2600-evb: Enable SPL FIT support

2021-10-03 Thread Tom Rini
On Thu, Sep 16, 2021 at 04:52:19PM +0800, Chia-Wei Wang wrote:

> Enable SPL FIT image load and verification support.
> The HW accelerated SHA is also available with the
> newly added support of the HACE HW hash engine.
> 
> The SPL thumb build is also enabled to keep the binary
> less than 64KB to fit into the Aspeed secure boot design.
> 
> Signed-off-by: Chia-Wei Wang 

This causes the board to fail to build:
   arm:  +   evb-ast2600
+(evb-ast2600) common/image-fit.c: In function 'calculate_hash':
+(evb-ast2600) common/image-fit.c:1232:46: error: 'algo' undeclared (first use 
in this function)
+(evb-ast2600)  1232 | hash_algo = hash_algo_lookup_by_name(algo);
+(evb-ast2600)   |  ^~~~
+(evb-ast2600) common/image-fit.c:1232:46: note: each undeclared identifier is 
reported only once for each function it appears in
+(evb-ast2600) make[2]: *** [common/image-fit.o] Error 1
+(evb-ast2600) make[1]: *** [common] Error 2
+(evb-ast2600) make: *** [sub-make] Error 2

Please rebase and repost the series, thanks!

-- 
Tom


signature.asc
Description: PGP signature


[PATCH v2 7/7] doc: board: apple: Add Apple M1 documentation

2021-10-03 Thread Mark Kettenis
Provide preliminary instructions on how to get U-Boot to run on
Apple Silicon Macs.

Signed-off-by: Mark Kettenis 
---
 doc/board/apple/index.rst |  9 +++
 doc/board/apple/m1.rst| 56 +++
 doc/board/index.rst   |  1 +
 3 files changed, 66 insertions(+)
 create mode 100644 doc/board/apple/index.rst
 create mode 100644 doc/board/apple/m1.rst

diff --git a/doc/board/apple/index.rst b/doc/board/apple/index.rst
new file mode 100644
index 00..8446847818
--- /dev/null
+++ b/doc/board/apple/index.rst
@@ -0,0 +1,9 @@
+.. SPDX-License-Identifier: GPL-2.0+
+
+Apple
+=
+
+.. toctree::
+   :maxdepth: 2
+
+   m1
diff --git a/doc/board/apple/m1.rst b/doc/board/apple/m1.rst
new file mode 100644
index 00..2f2d940a4c
--- /dev/null
+++ b/doc/board/apple/m1.rst
@@ -0,0 +1,56 @@
+.. SPDX-License-Identifier: GPL-2.0+
+
+U-Boot for Apple Silicon Macs
+=
+
+Allows Apple Silicon Macs to boot U-Boot via the m1n1 bootloader
+developed by the Asahi Linux project.  At this point the machines with
+the following SoCs work:
+
+ - Apple M1 SoC
+
+On these SoCs the following hardware is supported:
+
+ - S5L serial port
+ - Framebuffer
+ - USB 3.1 Type-C ports
+
+Device trees are currently provided for the M1 Mac mini (2020, J274)
+and M1 MacBook Pro 13" (2020, J293).  The M1 MacBook Air (2020) is
+expected to work with the J293 device tree.  The M1 iMac (2021) may
+work with the J274 device tree.
+
+Building U-Boot
+---
+
+.. code-block:: bash
+
+$ export CROSS_COMPILE=aarch64-none-elf-
+$ make apple_m1_defconfig
+$ make
+
+This will build ``u-boot-nodtb.bin`` as well as devices trees for some
+of the supported machines.  These device trees can be found in the
+``arch/arm/dts`` subdirectory of your build.
+
+Image creation
+--
+
+In order to run U-Boot on an Apple Silicon Mac, U-Boot has to be used
+as a payload for the m1n1 bootloader.  Instructions for building m1n1
+can be found here:
+
+https://github.com/AsahiLinux/docs/wiki/SW%3Am1n1
+
+.. code-block:: bash
+
+$ cat m1n1.macho t8103-j274.dtb u-boot-nodtb.bin > u-boot.macho
+
+Image installation
+--
+
+Instructions on how to install U-Boot on your Mac can be found at:
+
+https://github.com/AsahiLinux/docs/wiki/Developer-Quickstart
+
+Just replace ``m1n1.macho`` with ``u-boot.macho`` in the instructions.
diff --git a/doc/board/index.rst b/doc/board/index.rst
index 33087074fa..0add55b5d3 100644
--- a/doc/board/index.rst
+++ b/doc/board/index.rst
@@ -10,6 +10,7 @@ Board-specific doc
advantech/index
AndesTech/index
amlogic/index
+   apple/index
atmel/index
congatec/index
coreboot/index
-- 
2.33.0



[PATCH v2 6/7] arm: dts: apple: Add preliminary device trees

2021-10-03 Thread Mark Kettenis
Add preliminary device trees for the Apple M1 mini (2020) and
Apple M1 Macbook Pro 13" (2020).  Device tree bindings for
the Apple M1 SoC are still being formalized and these device
trees will be synchronized with the Linux kernel as needed.

These device trees are provided as a reference only as U-Boot
uses the device tree passed by the m1n1 bootloader.

Signed-off-by: Mark Kettenis 
---
 arch/arm/dts/Makefile |   4 +
 arch/arm/dts/t8103-j274.dts   | 135 +
 arch/arm/dts/t8103-j293.dts   |  97 +++
 arch/arm/dts/t8103.dtsi   | 560 ++
 configs/apple_m1_defconfig|   1 +
 .../interrupt-controller/apple-aic.h  |  15 +
 include/dt-bindings/pinctrl/apple.h   |  13 +
 include/dt-bindings/spmi/spmi.h   |  10 +
 8 files changed, 835 insertions(+)
 create mode 100644 arch/arm/dts/t8103-j274.dts
 create mode 100644 arch/arm/dts/t8103-j293.dts
 create mode 100644 arch/arm/dts/t8103.dtsi
 create mode 100644 include/dt-bindings/interrupt-controller/apple-aic.h
 create mode 100644 include/dt-bindings/pinctrl/apple.h
 create mode 100644 include/dt-bindings/spmi/spmi.h

diff --git a/arch/arm/dts/Makefile b/arch/arm/dts/Makefile
index fc16a57e60..65152d3ddf 100644
--- a/arch/arm/dts/Makefile
+++ b/arch/arm/dts/Makefile
@@ -29,6 +29,10 @@ dtb-$(CONFIG_EXYNOS5) += exynos5250-arndale.dtb \
exynos5422-odroidxu3.dtb
 dtb-$(CONFIG_EXYNOS7420) += exynos7420-espresso7420.dtb
 
+dtb-$(CONFIG_ARCH_APPLE) += \
+   t8103-j274.dtb \
+   t8103-j293.dtb
+
 dtb-$(CONFIG_ARCH_DAVINCI) += \
da850-evm.dtb \
da850-lcdk.dtb \
diff --git a/arch/arm/dts/t8103-j274.dts b/arch/arm/dts/t8103-j274.dts
new file mode 100644
index 00..aef1ae29b6
--- /dev/null
+++ b/arch/arm/dts/t8103-j274.dts
@@ -0,0 +1,135 @@
+// SPDX-License-Identifier: GPL-2.0+ OR MIT
+/*
+ * Apple Mac mini (M1, 2020)
+ *
+ * target-type: J274
+ *
+ * Copyright The Asahi Linux Contributors
+ */
+
+/dts-v1/;
+
+#include "t8103.dtsi"
+
+/ {
+   compatible = "apple,j274", "apple,t8103", "apple,arm-platform";
+   model = "Apple Mac mini (M1, 2020)";
+
+   aliases {
+   serial0 = 
+   ethernet0 = 
+   wifi0 = 
+   };
+
+   chosen {
+   #address-cells = <2>;
+   #size-cells = <2>;
+   ranges;
+
+   stdout-path = "serial0";
+
+   framebuffer0: framebuffer@0 {
+   compatible = "apple,simple-framebuffer", 
"simple-framebuffer";
+   reg = <0 0 0 0>; /* To be filled by loader */
+   /* Format properties will be added by loader */
+   status = "disabled";
+   };
+   };
+
+   memory@8 {
+   device_type = "memory";
+   reg = <0x8 0 0x2 0>; /* To be filled by loader */
+   };
+};
+
+ {
+   status = "okay";
+};
+
+_dart_0 {
+   status = "okay";
+};
+
+_dart_1 {
+   status = "okay";
+};
+
+_dart_2 {
+   status = "okay";
+};
+
+ {
+   status = "okay";
+
+   pci0: pci@0,0 {
+   device_type = "pci";
+   reg = <0x0 0x0 0x0 0x0 0x0>;
+   pwren-gpios = < 13 0>;
+   reset-gpios = <_ap 152 0>;
+   max-link-speed = <2>;
+
+   #address-cells = <3>;
+   #size-cells = <2>;
+   ranges;
+   };
+
+   pci1: pci@1,0 {
+   device_type = "pci";
+   reg = <0x800 0x0 0x0 0x0 0x0>;
+   reset-gpios = <_ap 153 0>;
+   max-link-speed = <2>;
+
+   #address-cells = <3>;
+   #size-cells = <2>;
+   ranges;
+   };
+
+   pci2: pci@2,0 {
+   device_type = "pci";
+   reg = <0x1000 0x0 0x0 0x0 0x0>;
+   reset-gpios = <_ap 33 0>;
+   max-link-speed = <1>;
+
+   #address-cells = <3>;
+   #size-cells = <2>;
+   ranges;
+   };
+};
+
+ {
+   wifi0: network@0,0 {
+   reg = <0x1 0x0 0x0 0x0 0x0>;
+   local-mac-address = [00 00 00 00 00 00];
+   };
+};
+
+ {
+   eth0: ethernet@0,0 {
+   reg = <0x3 0x0 0x0 0x0 0x0>;
+   local-mac-address = [00 00 00 00 00 00];
+   };
+};
+
+_0_dart_0 {
+   status = "okay";
+};
+
+_0_dart_1 {
+   status = "okay";
+};
+
+_0 {
+   status = "okay";
+};
+
+_1_dart_0 {
+   status = "okay";
+};
+
+_1_dart_1 {
+   status = "okay";
+};
+
+_1 {
+   status = "okay";
+};
diff --git a/arch/arm/dts/t8103-j293.dts b/arch/arm/dts/t8103-j293.dts
new file mode 100644
index 00..4a22596cf4
--- /dev/null
+++ b/arch/arm/dts/t8103-j293.dts
@@ -0,0 +1,97 @@
+// SPDX-License-Identifier: GPL-2.0+ OR MIT
+/*
+ * Apple Macbook Pro (M1, 2020)
+ *
+ * target-type: J293
+ *
+ * Copyright The Asahi Linux 

[PATCH v2 5/7] iommu: Add Apple DART driver

2021-10-03 Thread Mark Kettenis
The DART is an IOMMU that is used on Apple's M1 SoC.  This driver
configures the DART such that it operates in bypass mode which is
enough to support DMA for the USB3 ports integrated on the SoC.

Signed-off-by: Mark Kettenis 
---
 arch/arm/Kconfig   |  1 +
 drivers/iommu/Kconfig  | 10 +++
 drivers/iommu/Makefile |  1 +
 drivers/iommu/apple_dart.c | 59 ++
 4 files changed, 71 insertions(+)
 create mode 100644 drivers/iommu/apple_dart.c

diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index 876d9c4044..91bf6a122a 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -906,6 +906,7 @@ config ARCH_APPLE
select DM_SERIAL
select DM_USB
select DM_VIDEO
+   select IOMMU
select LINUX_KERNEL_IMAGE_HEADER
select OF_CONTROL
select OF_BOARD
diff --git a/drivers/iommu/Kconfig b/drivers/iommu/Kconfig
index 8cb377560e..51694c168c 100644
--- a/drivers/iommu/Kconfig
+++ b/drivers/iommu/Kconfig
@@ -10,4 +10,14 @@ config IOMMU
help
  Enable driver model for IOMMU devices.
 
+config APPLE_DART
+   bool "Apple DART support"
+   depends on IOMMU && ARCH_APPLE
+   default y
+   help
+ Enable support for the DART on Apple SoCs.  The DART is Apple's
+ IOMMU implementation.  The driver performs the necessary
+ configuration to put the DART into bypass mode such that it can
+ be used transparently by U-Boot.
+
 endmenu
diff --git a/drivers/iommu/Makefile b/drivers/iommu/Makefile
index af1c6bbb7a..e3e0900e17 100644
--- a/drivers/iommu/Makefile
+++ b/drivers/iommu/Makefile
@@ -2,4 +2,5 @@
 
 obj-$(CONFIG_IOMMU) += iommu-uclass.o
 
+obj-$(CONFIG_APPLE_DART) += apple_dart.o
 obj-$(CONFIG_SANDBOX) += sandbox_iommu.o
diff --git a/drivers/iommu/apple_dart.c b/drivers/iommu/apple_dart.c
new file mode 100644
index 00..ff8c5fa62c
--- /dev/null
+++ b/drivers/iommu/apple_dart.c
@@ -0,0 +1,59 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2021 Mark Kettenis 
+ */
+
+#include 
+#include 
+#include 
+#include 
+
+#define DART_PARAMS2   0x0004
+#define  DART_PARAMS2_BYPASS_SUPPORT   BIT(0)
+#define DART_TLB_OP0x0020
+#define  DART_TLB_OP_OPMASK(0xfff << 20)
+#define  DART_TLB_OP_FLUSH (0x001 << 20)
+#define  DART_TLB_OP_BUSY  BIT(2)
+#define DART_TLB_OP_SIDMASK0x0034
+#define DART_ERROR_STATUS  0x0040
+#define DART_TCR(sid)  (0x0100 + 4 * (sid))
+#define  DART_TCR_TRANSLATE_ENABLE BIT(7)
+#define  DART_TCR_BYPASS_DART  BIT(8)
+#define  DART_TCR_BYPASS_DAPF  BIT(12)
+#define DART_TTBR(sid, idx)(0x0200 + 16 * (sid) + 4 * (idx))
+#define  DART_TTBR_VALID   BIT(31)
+#define  DART_TTBR_SHIFT   12
+
+static int apple_dart_probe(struct udevice *dev)
+{
+   void *base;
+   int sid, i;
+
+   base = dev_read_addr_ptr(dev);
+   if (!base)
+   return -EINVAL;
+
+   u32 params2 = readl(base + DART_PARAMS2);
+   if (params2 & DART_PARAMS2_BYPASS_SUPPORT) {
+   for (sid = 0; sid < 16; sid++) {
+   writel(DART_TCR_BYPASS_DART | DART_TCR_BYPASS_DAPF,
+  base + DART_TCR(sid));
+   for (i = 0; i < 4; i++)
+   writel(0, base + DART_TTBR(sid, i));
+   }
+   }
+
+   return 0;
+}
+
+static const struct udevice_id apple_dart_ids[] = {
+   { .compatible = "apple,t8103-dart" },
+   { /* sentinel */ }
+};
+
+U_BOOT_DRIVER(apple_dart) = {
+   .name = "apple_dart",
+   .id = UCLASS_IOMMU,
+   .of_match = apple_dart_ids,
+   .probe = apple_dart_probe
+};
-- 
2.33.0



[PATCH v2 4/7] serial: s5p: Add Apple M1 support

2021-10-03 Thread Mark Kettenis
Apple M1 SoCs include an S5L UART which is a variant of the S5P
UART.  Add support for this variant and enable it by default
on Apple SoCs.

Signed-off-by: Mark Kettenis 
---
 arch/arm/Kconfig|   1 +
 arch/arm/include/asm/arch-m1/uart.h |  41 +++
 configs/apple_m1_defconfig  |   4 ++
 drivers/serial/Kconfig  |   4 +-
 drivers/serial/serial_s5p.c | 104 ++--
 5 files changed, 130 insertions(+), 24 deletions(-)
 create mode 100644 arch/arm/include/asm/arch-m1/uart.h

diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index 4948dad4df..876d9c4044 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -899,6 +899,7 @@ config ARCH_APPLE
bool "Apple SoCs"
select ARM64
select BLK
+   select CLK
select CMD_USB
select DM
select DM_KEYBOARD
diff --git a/arch/arm/include/asm/arch-m1/uart.h 
b/arch/arm/include/asm/arch-m1/uart.h
new file mode 100644
index 00..d2a17a221e
--- /dev/null
+++ b/arch/arm/include/asm/arch-m1/uart.h
@@ -0,0 +1,41 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * (C) Copyright 2009 Samsung Electronics
+ * Minkyu Kang 
+ * Heungjun Kim 
+ */
+
+#ifndef __ASM_ARCH_UART_H_
+#define __ASM_ARCH_UART_H_
+
+#ifndef __ASSEMBLY__
+/* baudrate rest value */
+union br_rest {
+   unsigned short  slot;   /* udivslot */
+   unsigned char   value;  /* ufracval */
+};
+
+struct s5p_uart {
+   unsigned intulcon;
+   unsigned intucon;
+   unsigned intufcon;
+   unsigned intumcon;
+   unsigned intutrstat;
+   unsigned intuerstat;
+   unsigned intufstat;
+   unsigned intumstat;
+   unsigned intutxh;
+   unsigned inturxh;
+   unsigned intubrdiv;
+   union br_rest   rest;
+   unsigned char   res3[0x3fd0];
+};
+
+static inline int s5p_uart_divslot(void)
+{
+   return 0;
+}
+
+#endif /* __ASSEMBLY__ */
+
+#endif
diff --git a/configs/apple_m1_defconfig b/configs/apple_m1_defconfig
index a7ae15576b..674b74b90b 100644
--- a/configs/apple_m1_defconfig
+++ b/configs/apple_m1_defconfig
@@ -12,3 +12,7 @@ CONFIG_USB_STORAGE=y
 CONFIG_USE_PREBOOT=y
 CONFIG_PREBOOT="usb start"
 # CONFIG_GENERATE_SMBIOS_TABLE is not set
+CONFIG_DEBUG_UART=y
+CONFIG_DEBUG_UART_ANNOUNCE=y
+CONFIG_DEBUG_UART_BASE=0x23520
+CONFIG_DEBUG_UART_CLOCK=24
diff --git a/drivers/serial/Kconfig b/drivers/serial/Kconfig
index 93348c0929..033d160579 100644
--- a/drivers/serial/Kconfig
+++ b/drivers/serial/Kconfig
@@ -272,7 +272,7 @@ config DEBUG_EFI_CONSOLE
 
 config DEBUG_UART_S5P
bool "Samsung S5P"
-   depends on ARCH_EXYNOS || ARCH_S5PC1XX
+   depends on ARCH_APPLE || ARCH_EXYNOS || ARCH_S5PC1XX
help
  Select this to enable a debug UART using the serial_s5p driver. You
  will need to provide parameters to make this work. The driver will
@@ -719,7 +719,7 @@ config ROCKCHIP_SERIAL
 
 config S5P_SERIAL
bool "Support for Samsung S5P UART"
-   depends on ARCH_EXYNOS || ARCH_S5PC1XX
+   depends on ARCH_APPLE || ARCH_EXYNOS || ARCH_S5PC1XX
default y
help
  Select this to enable Samsung S5P UART support.
diff --git a/drivers/serial/serial_s5p.c b/drivers/serial/serial_s5p.c
index 6d09952a5d..53a7b0bd1b 100644
--- a/drivers/serial/serial_s5p.c
+++ b/drivers/serial/serial_s5p.c
@@ -14,24 +14,45 @@
 #include 
 #include 
 #include 
+#if !CONFIG_IS_ENABLED(ARCH_APPLE)
 #include 
+#endif
 #include 
 #include 
 #include 
 
 DECLARE_GLOBAL_DATA_PTR;
 
-#define RX_FIFO_COUNT_SHIFT0
-#define RX_FIFO_COUNT_MASK (0xff << RX_FIFO_COUNT_SHIFT)
-#define RX_FIFO_FULL   (1 << 8)
-#define TX_FIFO_COUNT_SHIFT16
-#define TX_FIFO_COUNT_MASK (0xff << TX_FIFO_COUNT_SHIFT)
-#define TX_FIFO_FULL   (1 << 24)
+enum {
+   PORT_S5P = 0,
+   PORT_S5L
+};
+
+#define S5L_RX_FIFO_COUNT_SHIFT0
+#define S5L_RX_FIFO_COUNT_MASK (0xf << S5L_RX_FIFO_COUNT_SHIFT)
+#define S5L_RX_FIFO_FULL   (1 << 8)
+#define S5L_TX_FIFO_COUNT_SHIFT4
+#define S5L_TX_FIFO_COUNT_MASK (0xf << S5L_TX_FIFO_COUNT_SHIFT)
+#define S5L_TX_FIFO_FULL   (1 << 9)
+
+#define S5P_RX_FIFO_COUNT_SHIFT0
+#define S5P_RX_FIFO_COUNT_MASK (0xff << S5P_RX_FIFO_COUNT_SHIFT)
+#define S5P_RX_FIFO_FULL   (1 << 8)
+#define S5P_TX_FIFO_COUNT_SHIFT16
+#define S5P_TX_FIFO_COUNT_MASK (0xff << S5P_TX_FIFO_COUNT_SHIFT)
+#define S5P_TX_FIFO_FULL   (1 << 24)
 
 /* Information about a serial port */
 struct s5p_serial_plat {
struct s5p_uart *reg;  /* address of registers in physical memory */
+   u8 reg_width;   /* register width */
u8 port_id; /* uart port number */
+   u8 rx_fifo_count_shift;
+   u8 tx_fifo_count_shift;
+   u32 rx_fifo_count_mask;
+   u32 tx_fifo_count_mask;
+   u32 rx_fifo_full;
+   u32 tx_fifo_full;
 };
 
 /*
@@ -71,8 +92,8 @@ static void __maybe_unused 

[PATCH v2 3/7] arm: apple: Add initial support for Apple's M1 SoC

2021-10-03 Thread Mark Kettenis
Add support for Apple's M1 SoC that is used in "Apple Silicon"
Macs.  This builds a basic U-Boot that can be used as a payload
for the m1n1 boot loader being developed by the Asahi Linux
project.

Signed-off-by: Mark Kettenis 
---
 arch/arm/Kconfig|  21 
 arch/arm/Makefile   |   1 +
 arch/arm/mach-apple/Kconfig |  18 
 arch/arm/mach-apple/Makefile|   4 +
 arch/arm/mach-apple/board.c | 161 
 arch/arm/mach-apple/lowlevel_init.S |  17 +++
 configs/apple_m1_defconfig  |  14 +++
 include/configs/apple.h |  38 +++
 8 files changed, 274 insertions(+)
 create mode 100644 arch/arm/mach-apple/Kconfig
 create mode 100644 arch/arm/mach-apple/Makefile
 create mode 100644 arch/arm/mach-apple/board.c
 create mode 100644 arch/arm/mach-apple/lowlevel_init.S
 create mode 100644 configs/apple_m1_defconfig
 create mode 100644 include/configs/apple.h

diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index b5bd3284cd..4948dad4df 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -895,6 +895,25 @@ config ARCH_NEXELL
select DM
select GPIO_EXTRA_HEADER
 
+config ARCH_APPLE
+   bool "Apple SoCs"
+   select ARM64
+   select BLK
+   select CMD_USB
+   select DM
+   select DM_KEYBOARD
+   select DM_SERIAL
+   select DM_USB
+   select DM_VIDEO
+   select LINUX_KERNEL_IMAGE_HEADER
+   select OF_CONTROL
+   select OF_BOARD
+   select POSITION_INDEPENDENT
+   select USB
+   imply CMD_DM
+   imply CMD_GPT
+   imply DISTRO_DEFAULTS
+
 config ARCH_OWL
bool "Actions Semi OWL SoCs"
select DM
@@ -1932,6 +1951,8 @@ config ISW_ENTRY_ADDR
  image headers.
 endif
 
+source "arch/arm/mach-apple/Kconfig"
+
 source "arch/arm/mach-aspeed/Kconfig"
 
 source "arch/arm/mach-at91/Kconfig"
diff --git a/arch/arm/Makefile b/arch/arm/Makefile
index c68e598a67..44178c204b 100644
--- a/arch/arm/Makefile
+++ b/arch/arm/Makefile
@@ -51,6 +51,7 @@ PLATFORM_CPPFLAGS += $(arch-y) $(tune-y)
 
 # Machine directory name.  This list is sorted alphanumerically
 # by CONFIG_* macro name.
+machine-$(CONFIG_ARCH_APPLE)   += apple
 machine-$(CONFIG_ARCH_ASPEED)  += aspeed
 machine-$(CONFIG_ARCH_AT91)+= at91
 machine-$(CONFIG_ARCH_BCM283X) += bcm283x
diff --git a/arch/arm/mach-apple/Kconfig b/arch/arm/mach-apple/Kconfig
new file mode 100644
index 00..66cab91b2a
--- /dev/null
+++ b/arch/arm/mach-apple/Kconfig
@@ -0,0 +1,18 @@
+if ARCH_APPLE
+
+config SYS_TEXT_BASE
+   default 0x
+
+config SYS_CONFIG_NAME
+   default "apple"
+
+config SYS_SOC
+   default "m1"
+
+config SYS_MALLOC_LEN
+   default 0x400
+
+config SYS_MALLOC_F_LEN
+   default 0x4000
+
+endif
diff --git a/arch/arm/mach-apple/Makefile b/arch/arm/mach-apple/Makefile
new file mode 100644
index 00..e74a8c9df1
--- /dev/null
+++ b/arch/arm/mach-apple/Makefile
@@ -0,0 +1,4 @@
+# SPDX-License-Identifier: GPL-2.0+
+
+obj-y += board.o
+obj-y += lowlevel_init.o
diff --git a/arch/arm/mach-apple/board.c b/arch/arm/mach-apple/board.c
new file mode 100644
index 00..188d31a1bd
--- /dev/null
+++ b/arch/arm/mach-apple/board.c
@@ -0,0 +1,161 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * (C) Copyright 2021 Mark Kettenis 
+ */
+
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+
+DECLARE_GLOBAL_DATA_PTR;
+
+static struct mm_region apple_mem_map[] = {
+   {
+   /* I/O */
+   .virt = 0x2,
+   .phys = 0x2,
+   .size = 8UL * SZ_1G,
+   .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
+PTE_BLOCK_NON_SHARE |
+PTE_BLOCK_PXN | PTE_BLOCK_UXN
+   }, {
+   /* I/O */
+   .virt = 0x5,
+   .phys = 0x5,
+   .size = 2UL * SZ_1G,
+   .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
+PTE_BLOCK_NON_SHARE |
+PTE_BLOCK_PXN | PTE_BLOCK_UXN
+   }, {
+   /* I/O */
+   .virt = 0x68000,
+   .phys = 0x68000,
+   .size = SZ_512M,
+   .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
+PTE_BLOCK_NON_SHARE |
+PTE_BLOCK_PXN | PTE_BLOCK_UXN
+   }, {
+   /* PCIE */
+   .virt = 0x6a000,
+   .phys = 0x6a000,
+   .size = SZ_512M,
+   .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRE) |
+PTE_BLOCK_INNER_SHARE |
+PTE_BLOCK_PXN | PTE_BLOCK_UXN
+   }, {
+   /* PCIE */
+   .virt = 0x6c000,
+   .phys = 0x6c000,
+   .size = SZ_1G,
+   .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRE) |
+

[PATCH v2 2/7] test: Add tests for IOMMU uclass

2021-10-03 Thread Mark Kettenis
Add a set of tests for the IOMMU uclass.

Signed-off-by: Mark Kettenis 
---
 arch/sandbox/dts/test.dts  |  6 ++
 configs/sandbox64_defconfig|  1 +
 configs/sandbox_defconfig  |  1 +
 configs/sandbox_flattree_defconfig |  1 +
 configs/sandbox_noinst_defconfig   |  1 +
 configs/sandbox_spl_defconfig  |  1 +
 drivers/iommu/Makefile |  2 ++
 drivers/iommu/sandbox_iommu.c  | 18 ++
 test/dm/Makefile   |  1 +
 test/dm/iommu.c| 28 
 10 files changed, 60 insertions(+)
 create mode 100644 drivers/iommu/sandbox_iommu.c
 create mode 100644 test/dm/iommu.c

diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts
index 962bdbe556..ce561c17ef 100644
--- a/arch/sandbox/dts/test.dts
+++ b/arch/sandbox/dts/test.dts
@@ -752,6 +752,11 @@
vss-microvolts = <0>;
};
 
+   iommu: iommu@0 {
+   compatible = "sandbox,iommu";
+   #iommu-cells = <0>;
+   };
+
irq: irq {
compatible = "sandbox,irq";
interrupt-controller;
@@ -1199,6 +1204,7 @@
 
usb_1: usb@1 {
compatible = "sandbox,usb";
+   iommus = <>;
hub {
compatible = "usb-hub";
usb,device-class = <9>;
diff --git a/configs/sandbox64_defconfig b/configs/sandbox64_defconfig
index f7098b4969..54893dc303 100644
--- a/configs/sandbox64_defconfig
+++ b/configs/sandbox64_defconfig
@@ -129,6 +129,7 @@ CONFIG_SPL_I2C_MUX=y
 CONFIG_I2C_ARB_GPIO_CHALLENGE=y
 CONFIG_CROS_EC_KEYB=y
 CONFIG_I8042_KEYB=y
+CONFIG_IOMMU=y
 CONFIG_LED=y
 CONFIG_LED_BLINK=y
 CONFIG_LED_GPIO=y
diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig
index ea08a9e5bd..e7726b6de9 100644
--- a/configs/sandbox_defconfig
+++ b/configs/sandbox_defconfig
@@ -166,6 +166,7 @@ CONFIG_SPL_I2C_MUX=y
 CONFIG_I2C_ARB_GPIO_CHALLENGE=y
 CONFIG_CROS_EC_KEYB=y
 CONFIG_I8042_KEYB=y
+CONFIG_IOMMU=y
 CONFIG_LED=y
 CONFIG_LED_BLINK=y
 CONFIG_LED_GPIO=y
diff --git a/configs/sandbox_flattree_defconfig 
b/configs/sandbox_flattree_defconfig
index a6e2544dc1..fc831253ec 100644
--- a/configs/sandbox_flattree_defconfig
+++ b/configs/sandbox_flattree_defconfig
@@ -106,6 +106,7 @@ CONFIG_SPL_I2C_MUX=y
 CONFIG_I2C_ARB_GPIO_CHALLENGE=y
 CONFIG_CROS_EC_KEYB=y
 CONFIG_I8042_KEYB=y
+CONFIG_IOMMU=y
 CONFIG_LED=y
 CONFIG_LED_BLINK=y
 CONFIG_LED_GPIO=y
diff --git a/configs/sandbox_noinst_defconfig b/configs/sandbox_noinst_defconfig
index 88443f5ab2..d1b82821eb 100644
--- a/configs/sandbox_noinst_defconfig
+++ b/configs/sandbox_noinst_defconfig
@@ -125,6 +125,7 @@ CONFIG_I2C_MUX=y
 CONFIG_I2C_ARB_GPIO_CHALLENGE=y
 CONFIG_CROS_EC_KEYB=y
 CONFIG_I8042_KEYB=y
+CONFIG_IOMMU=y
 CONFIG_LED=y
 CONFIG_LED_BLINK=y
 CONFIG_LED_GPIO=y
diff --git a/configs/sandbox_spl_defconfig b/configs/sandbox_spl_defconfig
index 77dd83cf6f..d91cac492b 100644
--- a/configs/sandbox_spl_defconfig
+++ b/configs/sandbox_spl_defconfig
@@ -127,6 +127,7 @@ CONFIG_I2C_MUX=y
 CONFIG_I2C_ARB_GPIO_CHALLENGE=y
 CONFIG_CROS_EC_KEYB=y
 CONFIG_I8042_KEYB=y
+CONFIG_IOMMU=y
 CONFIG_LED=y
 CONFIG_LED_BLINK=y
 CONFIG_LED_GPIO=y
diff --git a/drivers/iommu/Makefile b/drivers/iommu/Makefile
index f1ceb10150..af1c6bbb7a 100644
--- a/drivers/iommu/Makefile
+++ b/drivers/iommu/Makefile
@@ -1,3 +1,5 @@
 # SPDX-License-Identifier: GPL-2.0+
 
 obj-$(CONFIG_IOMMU) += iommu-uclass.o
+
+obj-$(CONFIG_SANDBOX) += sandbox_iommu.o
diff --git a/drivers/iommu/sandbox_iommu.c b/drivers/iommu/sandbox_iommu.c
new file mode 100644
index 00..c8161a40ae
--- /dev/null
+++ b/drivers/iommu/sandbox_iommu.c
@@ -0,0 +1,18 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2021 Mark Kettenis 
+ */
+
+#include 
+#include 
+
+static const struct udevice_id sandbox_iommu_ids[] = {
+   { .compatible = "sandbox,iommu" },
+   { /* sentinel */ }
+};
+
+U_BOOT_DRIVER(sandbox_iommu) = {
+   .name = "sandbox_iommu",
+   .id = UCLASS_IOMMU,
+   .of_match = sandbox_iommu_ids,
+};
diff --git a/test/dm/Makefile b/test/dm/Makefile
index 55162e9499..7de013f636 100644
--- a/test/dm/Makefile
+++ b/test/dm/Makefile
@@ -48,6 +48,7 @@ obj-$(CONFIG_DM_I2C) += i2c.o
 obj-$(CONFIG_SOUND) += i2s.o
 obj-y += irq.o
 obj-$(CONFIG_CLK_K210_SET_RATE) += k210_pll.o
+obj-$(CONFIG_IOMMU) += iommu.o
 obj-$(CONFIG_LED) += led.o
 obj-$(CONFIG_DM_MAILBOX) += mailbox.o
 obj-$(CONFIG_DM_MDIO) += mdio.o
diff --git a/test/dm/iommu.c b/test/dm/iommu.c
new file mode 100644
index 00..94174a7482
--- /dev/null
+++ b/test/dm/iommu.c
@@ -0,0 +1,28 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2021 Mark Kettenis 
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+static int dm_test_iommu(struct unit_test_state *uts)
+{
+   struct udevice *dev;
+
+   ut_assertok(uclass_find_device(UCLASS_IOMMU, 0, ));
+   

[PATCH v2 1/7] iommu: Add IOMMU uclass

2021-10-03 Thread Mark Kettenis
This uclass is intended to manage IOMMUs on systems where the
IOMMUs are not in bypass mode by default.  In that case U-Boot
cannot ignore the IOMMUs if it wants to use devices that need
to do DMA and sit behind such an IOMMU.

This initial IOMMU uclass implementation does not implement and
device ops and is intended for IOMMUs that have a bypass mode
that does not require address translation.  Support for IOMMUs
that do require address translation is planned and device ops
will be defined when support for such IOMMUs will be added.

Signed-off-by: Mark Kettenis 
---
 drivers/Kconfig  |  2 ++
 drivers/Makefile |  1 +
 drivers/core/device.c|  8 +++
 drivers/iommu/Kconfig| 13 +++
 drivers/iommu/Makefile   |  3 +++
 drivers/iommu/iommu-uclass.c | 45 
 include/dm/uclass-id.h   |  1 +
 include/iommu.h  | 16 +
 8 files changed, 89 insertions(+)
 create mode 100644 drivers/iommu/Kconfig
 create mode 100644 drivers/iommu/Makefile
 create mode 100644 drivers/iommu/iommu-uclass.c
 create mode 100644 include/iommu.h

diff --git a/drivers/Kconfig b/drivers/Kconfig
index 417d6f88c2..b26ca8cf70 100644
--- a/drivers/Kconfig
+++ b/drivers/Kconfig
@@ -50,6 +50,8 @@ source "drivers/i2c/Kconfig"
 
 source "drivers/input/Kconfig"
 
+source "drivers/iommu/Kconfig"
+
 source "drivers/led/Kconfig"
 
 source "drivers/mailbox/Kconfig"
diff --git a/drivers/Makefile b/drivers/Makefile
index fd218c9056..166aeb9817 100644
--- a/drivers/Makefile
+++ b/drivers/Makefile
@@ -109,6 +109,7 @@ obj-y += mtd/
 obj-y += pwm/
 obj-y += reset/
 obj-y += input/
+obj-y += iommu/
 # SOC specific infrastructure drivers.
 obj-y += smem/
 obj-y += thermal/
diff --git a/drivers/core/device.c b/drivers/core/device.c
index 29668f6fb3..5f480ad443 100644
--- a/drivers/core/device.c
+++ b/drivers/core/device.c
@@ -28,6 +28,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -543,6 +544,13 @@ int device_probe(struct udevice *dev)
goto fail;
}
 
+   if (CONFIG_IS_ENABLED(IOMMU) && dev->parent &&
+   (device_get_uclass_id(dev) != UCLASS_IOMMU)) {
+   ret = dev_iommu_probe(dev);
+   if (ret)
+   goto fail;
+   }
+
ret = device_get_dma_constraints(dev);
if (ret)
goto fail;
diff --git a/drivers/iommu/Kconfig b/drivers/iommu/Kconfig
new file mode 100644
index 00..8cb377560e
--- /dev/null
+++ b/drivers/iommu/Kconfig
@@ -0,0 +1,13 @@
+#
+# IOMMU devices
+#
+
+menu "IOMMU device drivers"
+
+config IOMMU
+   bool "Enable Driver Model for IOMMU drivers"
+   depends on DM
+   help
+ Enable driver model for IOMMU devices.
+
+endmenu
diff --git a/drivers/iommu/Makefile b/drivers/iommu/Makefile
new file mode 100644
index 00..f1ceb10150
--- /dev/null
+++ b/drivers/iommu/Makefile
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0+
+
+obj-$(CONFIG_IOMMU) += iommu-uclass.o
diff --git a/drivers/iommu/iommu-uclass.c b/drivers/iommu/iommu-uclass.c
new file mode 100644
index 00..5c55df3066
--- /dev/null
+++ b/drivers/iommu/iommu-uclass.c
@@ -0,0 +1,45 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2021 Mark Kettenis 
+ */
+
+#define LOG_CATEGORY UCLASS_IOMMU
+
+#include 
+#include 
+
+#if (CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA))
+int dev_iommu_probe(struct udevice *dev)
+{
+   struct ofnode_phandle_args args;
+   struct udevice *dev_iommu;
+   int i, count, ret = 0;
+
+   count = dev_count_phandle_with_args(dev, "iommus",
+   "#iommu-cells", 0);
+   for (i = 0; i < count; i++) {
+   ret = dev_read_phandle_with_args(dev, "iommus",
+"#iommu-cells", 0, i, );
+   if (ret) {
+   debug("%s: dev_read_phandle_with_args failed: %d\n",
+ __func__, ret);
+   return ret;
+   }
+
+   ret = uclass_get_device_by_ofnode(UCLASS_IOMMU, args.node,
+ _iommu);
+   if (ret) {
+   debug("%s: uclass_get_device_by_ofnode failed: %d\n",
+ __func__, ret);
+   return ret;
+   }
+   }
+
+   return 0;
+}
+#endif
+
+UCLASS_DRIVER(iommu) = {
+   .id = UCLASS_IOMMU,
+   .name   = "iommu",
+};
diff --git a/include/dm/uclass-id.h b/include/dm/uclass-id.h
index e7edd409f3..56aa981613 100644
--- a/include/dm/uclass-id.h
+++ b/include/dm/uclass-id.h
@@ -61,6 +61,7 @@ enum uclass_id {
UCLASS_I2C_MUX, /* I2C multiplexer */
UCLASS_I2S, /* I2S bus */
UCLASS_IDE, /* IDE device */
+   UCLASS_IOMMU,   /* 

[PATCH v2 0/7] Apple M1 Support

2021-10-03 Thread Mark Kettenis
This series adds basic support for Apple's M1 SoC to U-Boot.
This builds a basic U-Boot that can be used as a payload
for the m1n1 boot loader being developed by the Asahi Linux
project.

The goal here is to privide an UEFI interface on these machines that
allows booting various open source OSes.  This initial series provides
support for the serial port, framebuffer and the USB 3.1 Type-C ports.
It can boot a support OS (e.g. OpenBSD/arm64) from a USB disk.

This version attempts to address most comments.  It doesn't add a
proper WDT/sysreset driver yet since I prefer to do that once the
device tree bindings for that have been ironed out.


ChangeLog:

v2: - Add IOMMU uclass and use it for the DART driver
- Cut back DART driver to only support bypass mode
- Rework the S5P serial support to use more DT stuff
- Update preliminary device trees

Mark Kettenis (7):
  iommu: Add IOMMU uclass
  test: Add tests for IOMMU uclass
  arm: apple: Add initial support for Apple's M1 SoC
  serial: s5p: Add Apple M1 support
  iommu: Add Apple DART driver
  arm: dts: apple: Add preliminary device trees
  doc: board: apple: Add Apple M1 documentation

 arch/arm/Kconfig  |  23 +
 arch/arm/Makefile |   1 +
 arch/arm/dts/Makefile |   4 +
 arch/arm/dts/t8103-j274.dts   | 135 +
 arch/arm/dts/t8103-j293.dts   |  97 +++
 arch/arm/dts/t8103.dtsi   | 560 ++
 arch/arm/include/asm/arch-m1/uart.h   |  41 ++
 arch/arm/mach-apple/Kconfig   |  18 +
 arch/arm/mach-apple/Makefile  |   4 +
 arch/arm/mach-apple/board.c   | 161 +
 arch/arm/mach-apple/lowlevel_init.S   |  17 +
 arch/sandbox/dts/test.dts |   6 +
 configs/apple_m1_defconfig|  19 +
 configs/sandbox64_defconfig   |   1 +
 configs/sandbox_defconfig |   1 +
 configs/sandbox_flattree_defconfig|   1 +
 configs/sandbox_noinst_defconfig  |   1 +
 configs/sandbox_spl_defconfig |   1 +
 doc/board/apple/index.rst |   9 +
 doc/board/apple/m1.rst|  56 ++
 doc/board/index.rst   |   1 +
 drivers/Kconfig   |   2 +
 drivers/Makefile  |   1 +
 drivers/core/device.c |   8 +
 drivers/iommu/Kconfig |  23 +
 drivers/iommu/Makefile|   6 +
 drivers/iommu/apple_dart.c|  59 ++
 drivers/iommu/iommu-uclass.c  |  45 ++
 drivers/iommu/sandbox_iommu.c |  18 +
 drivers/serial/Kconfig|   4 +-
 drivers/serial/serial_s5p.c   | 104 +++-
 include/configs/apple.h   |  38 ++
 include/dm/uclass-id.h|   1 +
 .../interrupt-controller/apple-aic.h  |  15 +
 include/dt-bindings/pinctrl/apple.h   |  13 +
 include/dt-bindings/spmi/spmi.h   |  10 +
 include/iommu.h   |  16 +
 test/dm/Makefile  |   1 +
 test/dm/iommu.c   |  28 +
 39 files changed, 1525 insertions(+), 24 deletions(-)
 create mode 100644 arch/arm/dts/t8103-j274.dts
 create mode 100644 arch/arm/dts/t8103-j293.dts
 create mode 100644 arch/arm/dts/t8103.dtsi
 create mode 100644 arch/arm/include/asm/arch-m1/uart.h
 create mode 100644 arch/arm/mach-apple/Kconfig
 create mode 100644 arch/arm/mach-apple/Makefile
 create mode 100644 arch/arm/mach-apple/board.c
 create mode 100644 arch/arm/mach-apple/lowlevel_init.S
 create mode 100644 configs/apple_m1_defconfig
 create mode 100644 doc/board/apple/index.rst
 create mode 100644 doc/board/apple/m1.rst
 create mode 100644 drivers/iommu/Kconfig
 create mode 100644 drivers/iommu/Makefile
 create mode 100644 drivers/iommu/apple_dart.c
 create mode 100644 drivers/iommu/iommu-uclass.c
 create mode 100644 drivers/iommu/sandbox_iommu.c
 create mode 100644 include/configs/apple.h
 create mode 100644 include/dt-bindings/interrupt-controller/apple-aic.h
 create mode 100644 include/dt-bindings/pinctrl/apple.h
 create mode 100644 include/dt-bindings/spmi/spmi.h
 create mode 100644 include/iommu.h
 create mode 100644 test/dm/iommu.c

-- 
2.33.0



Re: [PATCH v2 6/6] arm: dts: ls1088a: change dwc3 compatible to match dwc3-generic driver

2021-10-03 Thread Michael Walle
> Benefit is, besides host mode, now user can choose device mode with
> setting of dr_mode = ?peripheral?;
> 
> Signed-off-by: Ran Wang 
> ---
> Change in v2:
>  - Remove property 'snps,dis_rxdet_inp3_quirk' due to its side effect to Linux
>kernel (USB device no detected) 
> 
>  arch/arm/dts/fsl-ls1088a.dtsi | 38 --
>  1 file changed, 28 insertions(+), 10 deletions(-)
> 
> diff --git a/arch/arm/dts/fsl-ls1088a.dtsi b/arch/arm/dts/fsl-ls1088a.dtsi
> index 6653794..9d4f40c 100644
> --- a/arch/arm/dts/fsl-ls1088a.dtsi
> +++ b/arch/arm/dts/fsl-ls1088a.dtsi
> @@ -121,18 +121,36 @@
>   interrupts = <0 21 0x4>; /* Level high type */
>   };
>  
> - usb0: usb3 at 310 {
> - compatible = "fsl,layerscape-dwc3";
> - reg = <0x0 0x310 0x0 0x1>;
> - interrupts = <0 80 0x4>; /* Level high type */
> - dr_mode = "host";
> + usb0: usb at 310 {
> + compatible = "nxp,layerscape-dwc3";
> + #address-cells = <2>;
> + #size-cells = <2>;
> + ranges;
> + dwc3 {
> + compatible = "snps,dwc3";
> + reg = <0x0 0x310 0x0 0x1>;
> + interrupts = <0 80 0x4>; /* Level high type */
> + dr_mode = "host";
> + maximum-speed = "super-speed";
> + snps,quirk-frame-length-adjustment = <0x20>;
> + snps,incr-burst-type-adjustment = <1>, <4>, <8>, <16>;
> + };

NAK. This is not the official device tree binding for this controller.
Please use the same binding as specified in linux.

NB. I'm working on this.

-michael


[PATCH] sunxi: Add support for FriendlyARM NanoPi R1S H5

2021-10-03 Thread Chukun Pan
This adds support for the NanoPi R1S H5 board.

Allwinner H5 SoC
512MB DDR3 RAM
10/100/1000M Ethernet x 2
RTL8189ETV WiFi 802.11b/g/n
USB 2.0 host port (A)
MicroSD Slot
Reset button
Serial Debug Port
WAN - LAN - SYS LED

The dts file is taken from Linux 5.14 tag, and includes the
change to the eeprom node [1], which it's not yet merged.

[1] https://lore.kernel.org/lkml/20211001145036.18129-1-amad...@jmu.edu.cn

Signed-off-by: Chukun Pan 
---
 arch/arm/dts/Makefile|   1 +
 arch/arm/dts/sun50i-h5-nanopi-r1s-h5.dts | 196 +++
 board/sunxi/MAINTAINERS  |   5 +
 configs/nanopi_r1s_h5_defconfig  |  13 ++
 4 files changed, 215 insertions(+)
 create mode 100644 arch/arm/dts/sun50i-h5-nanopi-r1s-h5.dts
 create mode 100644 configs/nanopi_r1s_h5_defconfig

diff --git a/arch/arm/dts/Makefile b/arch/arm/dts/Makefile
index 9e44817a40..e278480c1c 100644
--- a/arch/arm/dts/Makefile
+++ b/arch/arm/dts/Makefile
@@ -632,6 +632,7 @@ dtb-$(CONFIG_MACH_SUN50I_H5) += \
sun50i-h5-libretech-all-h5-cc.dtb \
sun50i-h5-nanopi-neo2.dtb \
sun50i-h5-nanopi-neo-plus2.dtb \
+   sun50i-h5-nanopi-r1s-h5.dtb \
sun50i-h5-orangepi-zero-plus.dtb \
sun50i-h5-orangepi-pc2.dtb \
sun50i-h5-orangepi-prime.dtb \
diff --git a/arch/arm/dts/sun50i-h5-nanopi-r1s-h5.dts 
b/arch/arm/dts/sun50i-h5-nanopi-r1s-h5.dts
new file mode 100644
index 00..4f01c17c49
--- /dev/null
+++ b/arch/arm/dts/sun50i-h5-nanopi-r1s-h5.dts
@@ -0,0 +1,196 @@
+// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
+/*
+ * Copyright (C) 2021 Chukun Pan 
+ *
+ * Based on sun50i-h5-nanopi-neo-plus2.dts, which is:
+ *   Copyright (C) 2017 Antony Antony 
+ *   Copyright (C) 2016 ARM Ltd.
+ */
+
+/dts-v1/;
+#include "sun50i-h5.dtsi"
+#include "sun50i-h5-cpu-opp.dtsi"
+
+#include 
+#include 
+#include 
+
+/ {
+   model = "FriendlyARM NanoPi R1S H5";
+   compatible = "friendlyarm,nanopi-r1s-h5", "allwinner,sun50i-h5";
+
+   aliases {
+   ethernet0 = 
+   ethernet1 = 
+   serial0 = 
+   };
+
+   chosen {
+   stdout-path = "serial0:115200n8";
+   };
+
+   leds {
+   compatible = "gpio-leds";
+
+   led-0 {
+   function = LED_FUNCTION_LAN;
+   color = ;
+   gpios = < 0 9 GPIO_ACTIVE_HIGH>;
+   };
+
+   led-1 {
+   function = LED_FUNCTION_STATUS;
+   color = ;
+   gpios = < 0 10 GPIO_ACTIVE_HIGH>;
+   linux,default-trigger = "heartbeat";
+   };
+
+   led-2 {
+   function = LED_FUNCTION_WAN;
+   color = ;
+   gpios = < 6 11 GPIO_ACTIVE_HIGH>;
+   };
+   };
+
+   r-gpio-keys {
+   compatible = "gpio-keys";
+
+   reset {
+   label = "reset";
+   linux,code = ;
+   gpios = <_pio 0 3 GPIO_ACTIVE_LOW>;
+   };
+   };
+
+   reg_gmac_3v3: gmac-3v3 {
+   compatible = "regulator-fixed";
+   regulator-name = "gmac-3v3";
+   regulator-min-microvolt = <330>;
+   regulator-max-microvolt = <330>;
+   startup-delay-us = <10>;
+   enable-active-high;
+   gpio = < 3 6 GPIO_ACTIVE_HIGH>;
+   };
+
+   reg_vcc3v3: vcc3v3 {
+   compatible = "regulator-fixed";
+   regulator-name = "vcc3v3";
+   regulator-min-microvolt = <330>;
+   regulator-max-microvolt = <330>;
+   };
+
+   reg_usb0_vbus: usb0-vbus {
+   compatible = "regulator-fixed";
+   regulator-name = "usb0-vbus";
+   regulator-min-microvolt = <500>;
+   regulator-max-microvolt = <500>;
+   enable-active-high;
+   gpio = <_pio 0 2 GPIO_ACTIVE_HIGH>; /* PL2 */
+   status = "okay";
+   };
+
+   vdd_cpux: gpio-regulator {
+   compatible = "regulator-gpio";
+   regulator-name = "vdd-cpux";
+   regulator-type = "voltage";
+   regulator-boot-on;
+   regulator-always-on;
+   regulator-min-microvolt = <110>;
+   regulator-max-microvolt = <130>;
+   regulator-ramp-delay = <50>; /* 4ms */
+   gpios = <_pio 0 6 GPIO_ACTIVE_HIGH>;
+   gpios-states = <0x1>;
+   states = <110 0x0>, <130 0x1>;
+   };
+
+   wifi_pwrseq: wifi_pwrseq {
+   compatible = "mmc-pwrseq-simple";
+   reset-gpios = <_pio 0 7 GPIO_ACTIVE_LOW>; /* PL7 */
+   post-power-on-delay-ms = <200>;
+   };
+};
+
+ {
+   cpu-supply = <_cpux>;
+};
+
+ {
+   status = "okay";
+};

[PATCH V2] ARM: omap3_logic: Cleanup usage of MUX_VAL

2021-10-03 Thread Adam Ford
The macro called MUX_VAL generates a writel instruction with
semicolon at the end.  This table was written to use semicolons,
however one was missed:

   MUX_VAL(CP(SYS_BOOT2),  (IEN  | PTD | DIS | M4))/* GPIO_4 */

Since the extra semicolon is unnecessary with the use of the macro,
remove all of them, and cleanup whitespace.

Reviewed-by: Wolfgang Denk 
Suggested-by: Wolfgang Denk 
Signed-off-by: Adam Ford 
---
V2:  Make white consistent

diff --git a/board/logicpd/omap3som/omap3logic.h 
b/board/logicpd/omap3som/omap3logic.h
index 63c2141783..3a6f6c1f4e 100644
--- a/board/logicpd/omap3som/omap3logic.h
+++ b/board/logicpd/omap3som/omap3logic.h
@@ -45,209 +45,209 @@ const omap3_sysinfo sysinfo = {
  */
 void set_muxconf_regs(void)
 {
-   MUX_VAL(CP(SDRC_D0), (IEN  | PTD | DIS | M0)); /*SDRC_D0*/
-   MUX_VAL(CP(SDRC_D1), (IEN  | PTD | DIS | M0)); /*SDRC_D1*/
-   MUX_VAL(CP(SDRC_D2), (IEN  | PTD | DIS | M0)); /*SDRC_D2*/
-   MUX_VAL(CP(SDRC_D3), (IEN  | PTD | DIS | M0)); /*SDRC_D3*/
-   MUX_VAL(CP(SDRC_D4), (IEN  | PTD | DIS | M0)); /*SDRC_D4*/
-   MUX_VAL(CP(SDRC_D5), (IEN  | PTD | DIS | M0)); /*SDRC_D5*/
-   MUX_VAL(CP(SDRC_D6), (IEN  | PTD | DIS | M0)); /*SDRC_D6*/
-   MUX_VAL(CP(SDRC_D7), (IEN  | PTD | DIS | M0)); /*SDRC_D7*/
-   MUX_VAL(CP(SDRC_D8), (IEN  | PTD | DIS | M0)); /*SDRC_D8*/
-   MUX_VAL(CP(SDRC_D9), (IEN  | PTD | DIS | M0)); /*SDRC_D9*/
-   MUX_VAL(CP(SDRC_D10), (IEN  | PTD | DIS | M0)); /*SDRC_D10*/
-   MUX_VAL(CP(SDRC_D11), (IEN  | PTD | DIS | M0)); /*SDRC_D11*/
-   MUX_VAL(CP(SDRC_D12), (IEN  | PTD | DIS | M0)); /*SDRC_D12*/
-   MUX_VAL(CP(SDRC_D13), (IEN  | PTD | DIS | M0)); /*SDRC_D13*/
-   MUX_VAL(CP(SDRC_D14), (IEN  | PTD | DIS | M0)); /*SDRC_D14*/
-   MUX_VAL(CP(SDRC_D15), (IEN  | PTD | DIS | M0)); /*SDRC_D15*/
-   MUX_VAL(CP(SDRC_D16), (IEN  | PTD | DIS | M0)); /*SDRC_D16*/
-   MUX_VAL(CP(SDRC_D17), (IEN  | PTD | DIS | M0)); /*SDRC_D17*/
-   MUX_VAL(CP(SDRC_D18), (IEN  | PTD | DIS | M0)); /*SDRC_D18*/
-   MUX_VAL(CP(SDRC_D19), (IEN  | PTD | DIS | M0)); /*SDRC_D19*/
-   MUX_VAL(CP(SDRC_D20), (IEN  | PTD | DIS | M0)); /*SDRC_D20*/
-   MUX_VAL(CP(SDRC_D21), (IEN  | PTD | DIS | M0)); /*SDRC_D21*/
-   MUX_VAL(CP(SDRC_D22), (IEN  | PTD | DIS | M0)); /*SDRC_D22*/
-   MUX_VAL(CP(SDRC_D23), (IEN  | PTD | DIS | M0)); /*SDRC_D23*/
-   MUX_VAL(CP(SDRC_D24), (IEN  | PTD | DIS | M0)); /*SDRC_D24*/
-   MUX_VAL(CP(SDRC_D25), (IEN  | PTD | DIS | M0)); /*SDRC_D25*/
-   MUX_VAL(CP(SDRC_D26), (IEN  | PTD | DIS | M0)); /*SDRC_D26*/
-   MUX_VAL(CP(SDRC_D27), (IEN  | PTD | DIS | M0)); /*SDRC_D27*/
-   MUX_VAL(CP(SDRC_D28), (IEN  | PTD | DIS | M0)); /*SDRC_D28*/
-   MUX_VAL(CP(SDRC_D29), (IEN  | PTD | DIS | M0)); /*SDRC_D29*/
-   MUX_VAL(CP(SDRC_D30), (IEN  | PTD | DIS | M0)); /*SDRC_D30*/
-   MUX_VAL(CP(SDRC_D31), (IEN  | PTD | DIS | M0)); /*SDRC_D31*/
-   MUX_VAL(CP(SDRC_CLK), (IEN  | PTD | DIS | M0)); /*SDRC_CLK*/
-   MUX_VAL(CP(SDRC_DQS0), (IEN  | PTD | DIS | M0)); /*SDRC_DQS0*/
-   MUX_VAL(CP(SDRC_DQS1), (IEN  | PTD | DIS | M0)); /*SDRC_DQS1*/
-   MUX_VAL(CP(SDRC_DQS2), (IEN  | PTD | DIS | M0)); /*SDRC_DQS2*/
-   MUX_VAL(CP(SDRC_DQS3), (IEN  | PTD | DIS | M0)); /*SDRC_DQS3*/
-   MUX_VAL(CP(SDRC_CKE0), (IDIS | PTU | EN  | M0)); /*SDRC_CKE0*/
-   MUX_VAL(CP(SDRC_CKE1), (IDIS | PTU | DIS | M0)); /*SDRC_CKE1*/
+   MUX_VAL(CP(SDRC_D0), (IEN  | PTD | DIS | M0)) /*SDRC_D0*/
+   MUX_VAL(CP(SDRC_D1), (IEN  | PTD | DIS | M0)) /*SDRC_D1*/
+   MUX_VAL(CP(SDRC_D2), (IEN  | PTD | DIS | M0)) /*SDRC_D2*/
+   MUX_VAL(CP(SDRC_D3), (IEN  | PTD | DIS | M0)) /*SDRC_D3*/
+   MUX_VAL(CP(SDRC_D4), (IEN  | PTD | DIS | M0)) /*SDRC_D4*/
+   MUX_VAL(CP(SDRC_D5), (IEN  | PTD | DIS | M0)) /*SDRC_D5*/
+   MUX_VAL(CP(SDRC_D6), (IEN  | PTD | DIS | M0)) /*SDRC_D6*/
+   MUX_VAL(CP(SDRC_D7), (IEN  | PTD | DIS | M0)) /*SDRC_D7*/
+   MUX_VAL(CP(SDRC_D8), (IEN  | PTD | DIS | M0)) /*SDRC_D8*/
+   MUX_VAL(CP(SDRC_D9), (IEN  | PTD | DIS | M0)) /*SDRC_D9*/
+   MUX_VAL(CP(SDRC_D10), (IEN  | PTD | DIS | M0)) /*SDRC_D10*/
+   MUX_VAL(CP(SDRC_D11), (IEN  | PTD | DIS | M0)) /*SDRC_D11*/
+   MUX_VAL(CP(SDRC_D12), (IEN  | PTD | DIS | M0)) /*SDRC_D12*/
+   MUX_VAL(CP(SDRC_D13), (IEN  | PTD | DIS | M0)) /*SDRC_D13*/
+   MUX_VAL(CP(SDRC_D14), (IEN  | PTD | DIS | M0)) /*SDRC_D14*/
+   MUX_VAL(CP(SDRC_D15), (IEN  | PTD | DIS | M0)) /*SDRC_D15*/
+   MUX_VAL(CP(SDRC_D16), (IEN  | PTD | DIS | M0)) /*SDRC_D16*/
+   MUX_VAL(CP(SDRC_D17), (IEN  | PTD | DIS | M0)) /*SDRC_D17*/
+   MUX_VAL(CP(SDRC_D18), (IEN  | PTD | DIS | M0)) /*SDRC_D18*/
+   MUX_VAL(CP(SDRC_D19), (IEN  | PTD | DIS | M0)) /*SDRC_D19*/
+   MUX_VAL(CP(SDRC_D20), (IEN  | PTD | DIS | M0)) /*SDRC_D20*/
+   MUX_VAL(CP(SDRC_D21), (IEN  | PTD | DIS | M0)) /*SDRC_D21*/
+   MUX_VAL(CP(SDRC_D22), (IEN  | PTD | DIS | M0)) /*SDRC_D22*/
+   

[PATCH] arm: mvebu: Select SPL_SKIP_LOWLEVEL_INIT on ARMADA_32BIT

2021-10-03 Thread Stefan Roese
Select SPL_SKIP_LOWLEVEL_INIT on 32bit Armada platforms via Kconfig,
as this was removed from mach/config.h in a2ac2b96 ("Convert
CONFIG_SKIP_LOWLEVEL_INIT et al to Kconfig").

Signed-off-by: Stefan Roese 
Fixes: a2ac2b96 ("Convert CONFIG_SKIP_LOWLEVEL_INIT et al to Kconfig")
Cc: Tom Rini 
Cc: Marek Behún 
Cc: Pali Rohár 
---
 arch/arm/mach-mvebu/Kconfig | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/arm/mach-mvebu/Kconfig b/arch/arm/mach-mvebu/Kconfig
index 087643725e85..54dff9986b41 100644
--- a/arch/arm/mach-mvebu/Kconfig
+++ b/arch/arm/mach-mvebu/Kconfig
@@ -11,6 +11,7 @@ config ARMADA_32BIT
select SPL_DM if SPL
select SPL_DM_SEQ_ALIAS if SPL
select SPL_OF_CONTROL if SPL
+   select SPL_SKIP_LOWLEVEL_INIT
select SPL_SIMPLE_BUS if SPL
select SUPPORT_SPL
select TRANSLATION_OFFSET
-- 
2.33.0



Re: [PATCH u-boot-marvell v3 00/39] kwboot higher baudrate

2021-10-03 Thread Stefan Roese

Hi Tom,

On 01.10.21 14:59, Tom Rini wrote:

On Fri, Oct 01, 2021 at 01:01:37PM +0200, Stefan Roese wrote:

Added to Tom to Cc

On 01.10.21 12:43, Stefan Roese wrote:

On 01.10.21 12:39, Pali Rohár wrote:

Hello!

On Friday 01 October 2021 12:28:34 Stefan Roese wrote:

First the test on "next" without the 39 patches:

[stefan@ryzen u-boot (next)]$ ./tools/kwboot -p -b u-boot-spl.kwb -t

...

DDR3 Training Sequence - Ended Successfully
Trying to boot from BOOTROM
Returning to BootROM (return address 0x0aa0)...
+xmodem: Protocol error


Not working!

And now test on "master" without the 39 patches:

[stefan@ryzen u-boot (master)]$ ./tools/kwboot -p -b u-boot-spl.kwb -t

...


Seems to okay.

Thanks,
Stefan


So something is broken in next branch. I have looked at kwboot and
kwbimage code and there is no change in next branch which is not in
master branch.

So it looks like that something not related to kwboot broke it in next
branch. And seems that git bisect on AXP hw would be required. But I do
not own AXP board, so I cannot do it.


I can try to do this here later, if I find the time.


git bisect leads to this problematic commit:

[stefan@ryzen u-boot ((ab92b38a0161...)|BISECTING)]$ git bisect good
a2ac2b964bfbb20d6791ee94b9034a50cfadb5b0 is the first bad commit
commit a2ac2b964bfbb20d6791ee94b9034a50cfadb5b0
Author: Tom Rini 
Date:   Fri Aug 27 21:18:30 2021 -0400

 Convert CONFIG_SKIP_LOWLEVEL_INIT et al to Kconfig

 This converts the following to Kconfig:
CONFIG_SKIP_LOWLEVEL_INIT
CONFIG_SKIP_LOWLEVEL_INIT_ONLY

 In order to do this, we need to introduce SPL and TPL variants of these
 options so that we can clearly disable these options only in SPL in some
 cases, and both instances in other cases.

 Signed-off-by: Tom Rini 


Frankly, I did not analyse this change fully. But it seems to
responsible for this breakage on Armada XP in "next".


OK, I guess the conversion from
arch/arm/mach-mvebu/include/mach/config.h didn't work right.  These
boards should have set CONFIG_SPL_SKIP_LOWLEVEL_INIT but don't.


Yes, this seems to be the case here.


Why it was missed, well, I can't spot the magic to include
 if it exists, but I just missed that, so I'll need to
make sure to take more care on the tricky conversions that also use
mach/config.h.  Let me know if you need me to re-convert platforms here,
or now that you know what's missing you can fix it, thanks!


I'll send a fix for "next" to the list shortly.

Thanks,
Stefan


[PATCH v3 1/4] efi_loader: treat UEFI variable name as const

2021-10-03 Thread Heinrich Schuchardt
UEFI variable names are typically constants and hence should be defined as
const. Unfortunately some of our API functions do not define the parameters
for UEFI variable names as const. This requires unnecessary conversions.

Adjust parameters of several internal functions to tre UEFI variable names
as const.

Signed-off-by: Heinrich Schuchardt 
---
v3:
no change
v2:
adjust commit message
---
 include/efi_loader.h  |  2 +-
 include/efi_variable.h| 16 ++--
 lib/efi_loader/efi_tcg2.c |  2 +-
 lib/efi_loader/efi_var_common.c   |  5 +++--
 lib/efi_loader/efi_var_mem.c  |  7 ---
 lib/efi_loader/efi_variable.c |  9 +
 lib/efi_loader/efi_variable_tee.c | 16 ++--
 7 files changed, 34 insertions(+), 23 deletions(-)

diff --git a/include/efi_loader.h b/include/efi_loader.h
index c440962fe5..125052d002 100644
--- a/include/efi_loader.h
+++ b/include/efi_loader.h
@@ -816,7 +816,7 @@ efi_status_t EFIAPI efi_query_variable_info(
u64 *remaining_variable_storage_size,
u64 *maximum_variable_size);
 
-void *efi_get_var(u16 *name, const efi_guid_t *vendor, efi_uintn_t *size);
+void *efi_get_var(const u16 *name, const efi_guid_t *vendor, efi_uintn_t 
*size);
 
 /*
  * See section 3.1.3 in the v2.7 UEFI spec for more details on
diff --git a/include/efi_variable.h b/include/efi_variable.h
index 0440d356bc..8f666b2309 100644
--- a/include/efi_variable.h
+++ b/include/efi_variable.h
@@ -32,7 +32,8 @@ enum efi_auth_var_type {
  * @timep: authentication time (seconds since start of epoch)
  * Return: status code
  */
-efi_status_t efi_get_variable_int(u16 *variable_name, const efi_guid_t *vendor,
+efi_status_t efi_get_variable_int(const u16 *variable_name,
+ const efi_guid_t *vendor,
  u32 *attributes, efi_uintn_t *data_size,
  void *data, u64 *timep);
 
@@ -47,7 +48,8 @@ efi_status_t efi_get_variable_int(u16 *variable_name, const 
efi_guid_t *vendor,
  * @ro_check:  check the read only read only bit in attributes
  * Return: status code
  */
-efi_status_t efi_set_variable_int(u16 *variable_name, const efi_guid_t *vendor,
+efi_status_t efi_set_variable_int(const u16 *variable_name,
+ const efi_guid_t *vendor,
  u32 attributes, efi_uintn_t data_size,
  const void *data, bool ro_check);
 
@@ -224,7 +226,7 @@ void efi_var_mem_del(struct efi_var_entry *var);
  * @time:  time of authentication (as seconds since start of epoch)
  * Result: status code
  */
-efi_status_t efi_var_mem_ins(u16 *variable_name,
+efi_status_t efi_var_mem_ins(const u16 *variable_name,
 const efi_guid_t *vendor, u32 attributes,
 const efi_uintn_t size1, const void *data1,
 const efi_uintn_t size2, const void *data2,
@@ -251,7 +253,8 @@ efi_status_t efi_init_secure_state(void);
  * @guid:  guid of UEFI variable
  * Return: identifier for authentication related variables
  */
-enum efi_auth_var_type efi_auth_var_get_type(u16 *name, const efi_guid_t 
*guid);
+enum efi_auth_var_type efi_auth_var_get_type(const u16 *name,
+const efi_guid_t *guid);
 
 /**
  * efi_get_next_variable_name_mem() - Runtime common code across efi variable
@@ -280,8 +283,9 @@ efi_get_next_variable_name_mem(efi_uintn_t 
*variable_name_size, u16 *variable_na
  * Return: status code
  */
 efi_status_t __efi_runtime
-efi_get_variable_mem(u16 *variable_name, const efi_guid_t *vendor, u32 
*attributes,
-efi_uintn_t *data_size, void *data, u64 *timep);
+efi_get_variable_mem(const u16 *variable_name, const efi_guid_t *vendor,
+u32 *attributes, efi_uintn_t *data_size, void *data,
+u64 *timep);
 
 /**
  * efi_get_variable_runtime() - runtime implementation of GetVariable()
diff --git a/lib/efi_loader/efi_tcg2.c b/lib/efi_loader/efi_tcg2.c
index d3b8f93f14..ed1506012b 100644
--- a/lib/efi_loader/efi_tcg2.c
+++ b/lib/efi_loader/efi_tcg2.c
@@ -1365,7 +1365,7 @@ static efi_status_t efi_append_scrtm_version(struct 
udevice *dev)
  * Return: status code
  */
 static efi_status_t tcg2_measure_variable(struct udevice *dev, u32 pcr_index,
- u32 event_type, u16 *var_name,
+ u32 event_type, const u16 *var_name,
  const efi_guid_t *guid,
  efi_uintn_t data_size, u8 *data)
 {
diff --git a/lib/efi_loader/efi_var_common.c b/lib/efi_loader/efi_var_common.c
index a00bbf1620..e179932124 100644
--- a/lib/efi_loader/efi_var_common.c
+++ 

[PATCH v3 0/4] efi_loader: centralize known vendor GUIDs

2021-10-03 Thread Heinrich Schuchardt
The UEFI specification defines which vendor GUIDs should be used for
predefined variables like 'PK'. Currently we have multiple places
where this relationship is stored.

With this patch series a function for retrieving the GUID is provided
and existing code is adjusted to used it.

v3:
Keep error handling in efi_sigstore_parse_sigdb()
v2:
Remove a superfluous value check.
Adjust commit messages and comments in the code.

Heinrich Schuchardt (4):
  efi_loader: treat UEFI variable name as const
  efi_loader: function to get GUID for variable name
  efi_loader: simplify efi_sigstore_parse_sigdb()
  efi_loader: simplify tcg2_measure_secure_boot_variable()

 include/efi_loader.h  |  2 +-
 include/efi_variable.h| 27 +--
 lib/efi_loader/efi_signature.c| 11 ++-
 lib/efi_loader/efi_tcg2.c | 31 ++-
 lib/efi_loader/efi_var_common.c   | 14 --
 lib/efi_loader/efi_var_mem.c  |  7 ---
 lib/efi_loader/efi_variable.c |  9 +
 lib/efi_loader/efi_variable_tee.c | 16 ++--
 8 files changed, 69 insertions(+), 48 deletions(-)

-- 
2.32.0



[PATCH v3 2/4] efi_loader: function to get GUID for variable name

2021-10-03 Thread Heinrich Schuchardt
In multiple places we need the default GUID matching a variable name.
The patch provides a library function. For secure boot related variables
like 'PK', 'KEK', 'db' a lookup table is used. For all other variable
names EFI_GLOBAL_VARIABLE is returned.

Signed-off-by: Heinrich Schuchardt 
---
v3:
no change
v2:
adjust function documentation
---
 include/efi_variable.h  | 11 +++
 lib/efi_loader/efi_var_common.c |  9 +
 2 files changed, 20 insertions(+)

diff --git a/include/efi_variable.h b/include/efi_variable.h
index 8f666b2309..74909e8ec6 100644
--- a/include/efi_variable.h
+++ b/include/efi_variable.h
@@ -256,6 +256,17 @@ efi_status_t efi_init_secure_state(void);
 enum efi_auth_var_type efi_auth_var_get_type(const u16 *name,
 const efi_guid_t *guid);
 
+/**
+ * efi_auth_var_get_guid() - get the predefined GUID for a variable name
+ *
+ * For secure boot related variables a lookup table is used to determine
+ * the GUID. For all other variables EFI_GLOBAL_VARIABLE is returned.
+ *
+ * @name:  name of UEFI variable
+ * Return: guid of UEFI variable
+ */
+const efi_guid_t *efi_auth_var_get_guid(const u16 *name);
+
 /**
  * efi_get_next_variable_name_mem() - Runtime common code across efi variable
  *implementations for GetNextVariable()
diff --git a/lib/efi_loader/efi_var_common.c b/lib/efi_loader/efi_var_common.c
index e179932124..3cbb7c96c2 100644
--- a/lib/efi_loader/efi_var_common.c
+++ b/lib/efi_loader/efi_var_common.c
@@ -385,6 +385,15 @@ enum efi_auth_var_type efi_auth_var_get_type(const u16 
*name,
return EFI_AUTH_VAR_NONE;
 }
 
+const efi_guid_t *efi_auth_var_get_guid(const u16 *name)
+{
+   for (size_t i = 0; i < ARRAY_SIZE(name_type); ++i) {
+   if (!u16_strcmp(name, name_type[i].name))
+   return name_type[i].guid;
+   }
+   return _global_variable_guid;
+}
+
 /**
  * efi_get_var() - read value of an EFI variable
  *
-- 
2.32.0



[PATCH v3 4/4] efi_loader: simplify tcg2_measure_secure_boot_variable()

2021-10-03 Thread Heinrich Schuchardt
Don't duplicate GUIDs.

Signed-off-by: Heinrich Schuchardt 
---
v3:
no change
v2:
no change
---
 lib/efi_loader/efi_tcg2.c | 29 +
 1 file changed, 13 insertions(+), 16 deletions(-)

diff --git a/lib/efi_loader/efi_tcg2.c b/lib/efi_loader/efi_tcg2.c
index ed1506012b..52bf1b775f 100644
--- a/lib/efi_loader/efi_tcg2.c
+++ b/lib/efi_loader/efi_tcg2.c
@@ -11,6 +11,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -79,17 +80,12 @@ static const struct digest_info hash_algo_list[] = {
},
 };
 
-struct variable_info {
-   u16 *name;
-   const efi_guid_t*guid;
-};
-
-static struct variable_info secure_variables[] = {
-   {L"SecureBoot", _global_variable_guid},
-   {L"PK", _global_variable_guid},
-   {L"KEK", _global_variable_guid},
-   {L"db", _guid_image_security_database},
-   {L"dbx", _guid_image_security_database},
+static const u16 *secure_variables[] = {
+   u"SecureBoot",
+   u"PK",
+   u"KEK",
+   u"db",
+   u"dbx",
 };
 
 #define MAX_HASH_COUNT ARRAY_SIZE(hash_algo_list)
@@ -1593,19 +1589,20 @@ static efi_status_t 
tcg2_measure_secure_boot_variable(struct udevice *dev)
 
count = ARRAY_SIZE(secure_variables);
for (i = 0; i < count; i++) {
+   const efi_guid_t *guid;
+
+   guid = efi_auth_var_get_guid(secure_variables[i]);
+
/*
 * According to the TCG2 PC Client PFP spec, "SecureBoot",
 * "PK", "KEK", "db" and "dbx" variables must be measured
 * even if they are empty.
 */
-   data = efi_get_var(secure_variables[i].name,
-  secure_variables[i].guid,
-  _size);
+   data = efi_get_var(secure_variables[i], guid, _size);
 
ret = tcg2_measure_variable(dev, 7,
EV_EFI_VARIABLE_DRIVER_CONFIG,
-   secure_variables[i].name,
-   secure_variables[i].guid,
+   secure_variables[i], guid,
data_size, data);
free(data);
if (ret != EFI_SUCCESS)
-- 
2.32.0



[PATCH v3 3/4] efi_loader: simplify efi_sigstore_parse_sigdb()

2021-10-03 Thread Heinrich Schuchardt
Simplify efi_sigstore_parse_sigdb() by using existing functions.

Signed-off-by: Heinrich Schuchardt 
---
v3:
Keep error handling in efi_sigstore_parse_sigdb()
v2:
remove a superfluous check
---
 lib/efi_loader/efi_signature.c | 11 ++-
 1 file changed, 2 insertions(+), 9 deletions(-)

diff --git a/lib/efi_loader/efi_signature.c b/lib/efi_loader/efi_signature.c
index bdd09881fc..97f6dfacd9 100644
--- a/lib/efi_loader/efi_signature.c
+++ b/lib/efi_loader/efi_signature.c
@@ -746,18 +746,11 @@ struct efi_signature_store *efi_sigstore_parse_sigdb(u16 
*name)
efi_uintn_t db_size;
efi_status_t ret;
 
-   if (!u16_strcmp(name, L"PK") || !u16_strcmp(name, L"KEK")) {
-   vendor = _global_variable_guid;
-   } else if (!u16_strcmp(name, L"db") || !u16_strcmp(name, L"dbx")) {
-   vendor = _guid_image_security_database;
-   } else {
-   EFI_PRINT("unknown signature database, %ls\n", name);
-   return NULL;
-   }
+   vendor = efi_auth_var_get_guid(name);
 
/* retrieve variable data */
db_size = 0;
-   ret = EFI_CALL(efi_get_variable(name, vendor, NULL, _size, NULL));
+   ret = efi_get_variable_int(name, vendor, NULL, _size, NULL);
if (ret == EFI_NOT_FOUND) {
EFI_PRINT("variable, %ls, not found\n", name);
sigstore = calloc(sizeof(*sigstore), 1);
-- 
2.32.0