Re: [PATCH 1/3] rng: Introduce SPL_DM_RNG

2024-05-05 Thread Fabio Estevam
On Thu, Apr 25, 2024 at 8:03 PM Marek Vasut  wrote:
>
> Add SPL variant of DM_RNG so that the DM_RNG can be disabled in SPL
> if necessary. This may be necessary due to e.g. size constraints of
> the SPL.
>
> Signed-off-by: Marek Vasut 

Applied all, thanks.


[PATCH 1/3] rng: Introduce SPL_DM_RNG

2024-04-25 Thread Marek Vasut
Add SPL variant of DM_RNG so that the DM_RNG can be disabled in SPL
if necessary. This may be necessary due to e.g. size constraints of
the SPL.

Signed-off-by: Marek Vasut 
---
Cc: Angelo Dureghello 
Cc: Emanuele Ghidoli 
Cc: Fabio Estevam 
Cc: Gaurav Jain 
Cc: Heinrich Schuchardt 
Cc: Marek Vasut 
Cc: Michal Simek 
Cc: Simon Glass 
Cc: Stefan Roese 
Cc: Sughosh Ganu 
Cc: Svyatoslav Ryhel 
Cc: Tim Harvey 
Cc: Tom Rini 
Cc: u-boot@lists.denx.de
---
 boot/pxe_utils.c| 4 +---
 boot/vbe_request.c  | 2 +-
 drivers/Makefile| 2 +-
 drivers/crypto/fsl/jr.c | 4 ++--
 drivers/rng/Kconfig | 7 +++
 drivers/rng/Makefile| 2 +-
 lib/uuid.c  | 2 +-
 net/net_rand.h  | 2 +-
 test/dm/Makefile| 2 +-
 9 files changed, 16 insertions(+), 11 deletions(-)

diff --git a/boot/pxe_utils.c b/boot/pxe_utils.c
index 96205626750..5c1c962ff4c 100644
--- a/boot/pxe_utils.c
+++ b/boot/pxe_utils.c
@@ -21,9 +21,7 @@
 #include 
 #include 
 
-#ifdef CONFIG_DM_RNG
 #include 
-#endif
 
 #include 
 #include 
@@ -323,7 +321,7 @@ static int label_localboot(struct pxe_label *label)
 
 static void label_boot_kaslrseed(void)
 {
-#ifdef CONFIG_DM_RNG
+#if CONFIG_IS_ENABLED(DM_RNG)
ulong fdt_addr;
struct fdt_header *working_fdt;
size_t n = 0x8;
diff --git a/boot/vbe_request.c b/boot/vbe_request.c
index 917251afa1c..0293ac6c869 100644
--- a/boot/vbe_request.c
+++ b/boot/vbe_request.c
@@ -36,7 +36,7 @@ static int handle_random_req(ofnode node, int default_size,
u32 size;
int ret;
 
-   if (!IS_ENABLED(CONFIG_DM_RNG))
+   if (!CONFIG_IS_ENABLED(DM_RNG))
return -ENOTSUPP;
 
if (ofnode_read_u32(node, "vbe,size", )) {
diff --git a/drivers/Makefile b/drivers/Makefile
index bf73b7718ce..9195dafd37e 100644
--- a/drivers/Makefile
+++ b/drivers/Makefile
@@ -126,7 +126,7 @@ obj-$(CONFIG_W1_EEPROM) += w1-eeprom/
 obj-$(CONFIG_MACH_PIC32) += ddr/microchip/
 obj-$(CONFIG_FUZZ) += fuzz/
 obj-$(CONFIG_DM_HWSPINLOCK) += hwspinlock/
-obj-$(CONFIG_DM_RNG) += rng/
+obj-$(CONFIG_$(SPL_TPL_)DM_RNG) += rng/
 endif
 
 obj-y += soc/
diff --git a/drivers/crypto/fsl/jr.c b/drivers/crypto/fsl/jr.c
index 203f1625215..8ae5c434bdb 100644
--- a/drivers/crypto/fsl/jr.c
+++ b/drivers/crypto/fsl/jr.c
@@ -787,7 +787,7 @@ init:
}
 #if CONFIG_IS_ENABLED(OF_CONTROL)
if (ofnode_valid(scu_node)) {
-   if (IS_ENABLED(CONFIG_DM_RNG)) {
+   if (CONFIG_IS_ENABLED(DM_RNG)) {
ret = device_bind_driver(NULL, "caam-rng", "caam-rng", 
NULL);
if (ret)
printf("Couldn't bind rng driver (%d)\n", ret);
@@ -810,7 +810,7 @@ init:
return -1;
}
 
-   if (IS_ENABLED(CONFIG_DM_RNG)) {
+   if (CONFIG_IS_ENABLED(DM_RNG)) {
ret = device_bind_driver(NULL, "caam-rng", "caam-rng",
 NULL);
if (ret)
diff --git a/drivers/rng/Kconfig b/drivers/rng/Kconfig
index cd72852a479..5758ae192a6 100644
--- a/drivers/rng/Kconfig
+++ b/drivers/rng/Kconfig
@@ -6,6 +6,13 @@ config DM_RNG
  This interface is used to initialise the rng device and to
  read the random seed from the device.
 
+config SPL_DM_RNG
+   bool "Driver support for Random Number Generator devices in SPL"
+   depends on SPL_DM
+   help
+ This option is an SPL-variant of the DM_RNG option.
+ See the help of DM_RNG for details.
+
 if DM_RNG
 
 config RNG_MESON
diff --git a/drivers/rng/Makefile b/drivers/rng/Makefile
index ecae1a3da33..c1f1c616e00 100644
--- a/drivers/rng/Makefile
+++ b/drivers/rng/Makefile
@@ -3,7 +3,7 @@
 # Copyright (c) 2019, Linaro Limited
 #
 
-obj-$(CONFIG_DM_RNG) += rng-uclass.o
+obj-$(CONFIG_$(SPL_TPL_)DM_RNG) += rng-uclass.o
 obj-$(CONFIG_RNG_MESON) += meson-rng.o
 obj-$(CONFIG_RNG_SANDBOX) += sandbox_rng.o
 obj-$(CONFIG_RNG_MSM) += msm_rng.o
diff --git a/lib/uuid.c b/lib/uuid.c
index 2d7d99535e7..dfa2320ba26 100644
--- a/lib/uuid.c
+++ b/lib/uuid.c
@@ -378,7 +378,7 @@ void gen_rand_uuid(unsigned char *uuid_bin)
struct udevice *devp;
u32 randv = 0;
 
-   if (IS_ENABLED(CONFIG_DM_RNG)) {
+   if (CONFIG_IS_ENABLED(DM_RNG)) {
ret = uclass_get_device(UCLASS_RNG, 0, );
if (!ret) {
ret = dm_rng_read(devp, , sizeof(randv));
diff --git a/net/net_rand.h b/net/net_rand.h
index d3c5559adfd..686e85f2b53 100644
--- a/net/net_rand.h
+++ b/net/net_rand.h
@@ -42,7 +42,7 @@ static inline void srand_mac(void)
struct udevice *devp;
u32 randv = 0;
 
-   if (IS_ENABLED(CONFIG_DM_RNG)) {
+   if (CONFIG_IS_ENABLED(DM_RNG)) {
ret = uclass_get_device(UCLASS_RNG, 0, );
if (ret) {
ret = dm_rng_read(devp, , sizeof(randv));
diff --git a/test/dm/Makefile