[PATCH 3/5] common: machine_id: deprecate machine_id_set_hashable

Ahmad Fatoum a.fatoum at pengutronix.de
Sun Jun 27 23:40:34 PDT 2021


The Kconfig symbol already warns users that barebox updates
that add new instances of machine_id_set_hashable may cause the machine
ID to change making the future less useful. Recent changes allow the
board DT to identify a specific nvmem cell to use for supplying a machine
ID, making the old way of drivers providing machine IDs and possibly
overriding each other no longer necessary or recommended.

Make this explicit by allowing the old code to be disabled. As we only
have a single user now and won't accept any new ones, we can remove the
warning about it possibly changing after update.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 common/Kconfig        | 18 +++++++++++-------
 common/machine_id.c   | 11 ++++++++---
 drivers/nvmem/Kconfig |  1 +
 drivers/nvmem/ocotp.c |  7 ++++++-
 include/machine_id.h  | 16 ----------------
 5 files changed, 26 insertions(+), 27 deletions(-)
 delete mode 100644 include/machine_id.h

diff --git a/common/Kconfig b/common/Kconfig
index a4a109f04f08..a2aa0b2568de 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -1069,13 +1069,11 @@ config MACHINE_ID
 	select NVMEM
 	help
 	  Compute a persistent machine-specific id and store it to $global.machine_id.
-	  The id is a hash of device-specific information added either via
-	  machine_id_set_hashable() or by hashing the nvmem cell referenced by the
-	  /chosen/barebox,machine-id device tree property.
-
-	  With machine_id_set_hashable(), the last call prior to the late initcall
-	  set_machine_id() willl be used to generate the machine id. This means
-	  updating barebox may change the machine id!
+	  The id is a hash of device-specific information. This information
+	  comes from the nvmem cell device tree node path described by the
+	  /chosen/barebox,machine-id-path property. As a special case, the i.MX6 OCOTP
+	  driver supplies the SoC UID as hashable for when /chosen/barebox,machine-id-path
+	  is not specified.
 
 	  global.bootm.provide_machine_id may be used to automatically set
 	  the linux.bootargs.machine_id global variable with a value of
@@ -1084,6 +1082,12 @@ config MACHINE_ID
 	  Note: if no hashable information is available no machine id will be passed
 	  to the kernel.
 
+config MACHINE_ID_LEGACY
+	bool
+	help
+	  Selected by i.MX OCOTP driver, so it can set the SoC UID as hashable.
+	  New platforms should use /chosen/barebox,machine-id-path instead.
+
 config SYSTEMD_OF_WATCHDOG
 	bool "inform devicetree-enabled kernel of used watchdog"
 	depends on WATCHDOG && OFTREE && FLEXIBLE_BOOTARGS
diff --git a/common/machine_id.c b/common/machine_id.c
index fd2f0888a6cd..8303c0b7aa87 100644
--- a/common/machine_id.c
+++ b/common/machine_id.c
@@ -9,23 +9,24 @@
 #include <globalvar.h>
 #include <magicvar.h>
 #include <crypto/sha.h>
-#include <machine_id.h>
 #include <linux/err.h>
 #include <linux/nvmem-consumer.h>
 #include <of.h>
 
 #define MACHINE_ID_LENGTH 32
 
+#ifdef CONFIG_MACHINE_ID_LEGACY
 static void *__machine_id_hashable;
 static size_t __machine_id_hashable_length;
 
-
+/* Shouldn't be called from new code */
+void machine_id_set_hashable(const void *hashable, size_t len);
 void machine_id_set_hashable(const void *hashable, size_t len)
 {
-
 	__machine_id_hashable = xmemdup(hashable, len);
 	__machine_id_hashable_length = len;
 }
+#endif
 
 static const void *machine_id_get_hashable(size_t *len)
 {
@@ -52,8 +53,12 @@ static const void *machine_id_get_hashable(size_t *len)
 	return ret;
 
 no_cell:
+#ifdef CONFIG_MACHINE_ID_LEGACY
 	*len = __machine_id_hashable_length;
 	return __machine_id_hashable;
+#else
+	return NULL;
+#endif
 }
 
 static int machine_id_set_globalvar(void)
diff --git a/drivers/nvmem/Kconfig b/drivers/nvmem/Kconfig
index 3781f7a839fc..08a5765573a8 100644
--- a/drivers/nvmem/Kconfig
+++ b/drivers/nvmem/Kconfig
@@ -25,6 +25,7 @@ config NVMEM_SNVS_LPGPR
 config IMX_OCOTP
 	tristate "i.MX6 On Chip OTP controller"
 	depends on ARCH_IMX6 || ARCH_VF610 || ARCH_IMX8M || ARCH_IMX7
+	select MACHINE_ID_LEGACY
 	depends on OFDEVICE
 	help
 	  This adds support for the i.MX6 On-Chip OTP controller. Currently the
diff --git a/drivers/nvmem/ocotp.c b/drivers/nvmem/ocotp.c
index b2fad3c68770..0b10e52a86ba 100644
--- a/drivers/nvmem/ocotp.c
+++ b/drivers/nvmem/ocotp.c
@@ -29,7 +29,6 @@
 #include <regmap.h>
 #include <linux/clk.h>
 #include <mach/ocotp.h>
-#include <machine_id.h>
 #include <mach/ocotp-fusemap.h>
 #include <linux/nvmem-provider.h>
 
@@ -689,6 +688,7 @@ static int imx_ocotp_read(void *ctx, unsigned offset, void *val, size_t bytes)
 
 static void imx_ocotp_set_unique_machine_id(void)
 {
+	extern void machine_id_set_hashable(const void *hashable, size_t len);
 	uint32_t unique_id_parts[UNIQUE_ID_NUM];
 	int i;
 
@@ -785,6 +785,11 @@ static int imx_ocotp_probe(struct device_d *dev)
 				  ethaddr->value, ethaddr);
 	}
 
+	/* Special case: new machine id providers should provide a nvmem cell
+	 * and reference its path via /chosen/barebox,machine-id-path.
+	 * For i.MX, we support the legacy way of the driver supplying the
+	 * hash instead
+	 */
 	if (IS_ENABLED(CONFIG_MACHINE_ID))
 		imx_ocotp_set_unique_machine_id();
 
diff --git a/include/machine_id.h b/include/machine_id.h
deleted file mode 100644
index 31d5e0bb2851..000000000000
--- a/include/machine_id.h
+++ /dev/null
@@ -1,16 +0,0 @@
-#ifndef __MACHINE_ID_H__
-#define __MACHINE_ID_H__
-
-#if IS_ENABLED(CONFIG_MACHINE_ID)
-
-void machine_id_set_hashable(const void *hashable, size_t len);
-
-#else
-
-static inline void machine_id_set_hashable(const void *hashable, size_t len)
-{
-}
-
-#endif /* CONFIG_MACHINE_ID */
-
-#endif  /* __MACHINE_ID_H__ */
-- 
2.30.2




More information about the barebox mailing list