mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/3] digest.h: needs errno definitions
@ 2019-07-16 10:58 Bastian Krause
  2019-07-16 10:58 ` [PATCH 2/3] common: machine_id: introduce machine id generation and pass id on Bastian Krause
  2019-07-16 10:58 ` [PATCH 3/3] nvmem: ocotp: set unique id as machine-id hashable Bastian Krause
  0 siblings, 2 replies; 13+ messages in thread
From: Bastian Krause @ 2019-07-16 10:58 UTC (permalink / raw)
  To: barebox; +Cc: Juergen Borleis, Bastian Krause

From: Juergen Borleis <jbe@pengutronix.de>

digest_set_key() returns -ENOTSUPP conditionally, so include errno.h.

Fixes: 2f3c3f512b ("digest: add HMAC support for md5, sha1, sha224, sha256, sha384, sha512")
Signed-off-by: Juergen Borleis <jbe@pengutronix.de>
Signed-off-by: Bastian Krause <bst@pengutronix.de>
---
 include/digest.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/include/digest.h b/include/digest.h
index 474bdd160a..176084146b 100644
--- a/include/digest.h
+++ b/include/digest.h
@@ -20,6 +20,7 @@
 #define __DIGEST_H__
 
 #include <linux/list.h>
+#include <errno.h>
 
 struct digest;
 
-- 
2.20.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH 2/3] common: machine_id: introduce machine id generation and pass id on
  2019-07-16 10:58 [PATCH 1/3] digest.h: needs errno definitions Bastian Krause
@ 2019-07-16 10:58 ` Bastian Krause
  2019-07-17  9:48   ` Sascha Hauer
                     ` (2 more replies)
  2019-07-16 10:58 ` [PATCH 3/3] nvmem: ocotp: set unique id as machine-id hashable Bastian Krause
  1 sibling, 3 replies; 13+ messages in thread
From: Bastian Krause @ 2019-07-16 10:58 UTC (permalink / raw)
  To: barebox; +Cc: Bastian Krause

By default systemd generates a machine id on first boot and tries to
persist it (see `man machine-id`). When the root file system is read-only
systemd cannot persist the machine id. In case multiple redundant slots
are used the machine id will vary. When not handled explicitly the
machine id will also change during updates.

It is possible to pass a machine id to the kernel which will be used by
systemd (systemd.machine_id=).

This adds functionality to pass device-specific information that will be
hashed to generate a persistent unique machine id. The machine id will
be finally added to the kernel parameters via the
linux.bootargs.machine_id global variable.

Note: if multiple sources provide hashable device-specific information
(via machine_id_set_hashable()) the information provided by the last call
prior to the late initcall set_machine_id() is used to generate the
machine id from. Thus when updating barebox the machine id might change.

Signed-off-by: Bastian Krause <bst@pengutronix.de>
---
 common/Kconfig       | 11 ++++++++
 common/Makefile      |  1 +
 common/machine_id.c  | 65 ++++++++++++++++++++++++++++++++++++++++++++
 include/machine_id.h |  6 ++++
 4 files changed, 83 insertions(+)
 create mode 100644 common/machine_id.c
 create mode 100644 include/machine_id.h

diff --git a/common/Kconfig b/common/Kconfig
index 8aad5baecd..4b2d79350d 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -982,6 +982,17 @@ config RESET_SOURCE
 	  of the reset and why the bootloader is currently running. It can be
 	  useful for any kind of system recovery or repair.
 
+config MACHINE_ID
+	bool "pass machine-id to kernel"
+	depends on FLEXIBLE_BOOTARGS
+	select DIGEST
+	select DIGEST_SHA1_GENERIC
+	help
+	  Sets the linux.bootargs.machine_id global variable with a value of
+	  systemd.machine_id=UID. The UID is a persistent device-specific
+	  id. It is a hash over device-specific information provided by various
+	  sources.
+
 endmenu
 
 menu "Debugging"
diff --git a/common/Makefile b/common/Makefile
index a284655fc1..10960169f9 100644
--- a/common/Makefile
+++ b/common/Makefile
@@ -11,6 +11,7 @@ obj-y				+= bootsource.o
 obj-$(CONFIG_ELF)		+= elf.o
 obj-y				+= restart.o
 obj-y				+= poweroff.o
+obj-$(CONFIG_MACHINE_ID)	+= machine_id.o
 obj-$(CONFIG_AUTO_COMPLETE)	+= complete.o
 obj-y				+= version.o
 obj-$(CONFIG_BAREBOX_UPDATE)	+= bbu.o
diff --git a/common/machine_id.c b/common/machine_id.c
new file mode 100644
index 0000000000..54c1820086
--- /dev/null
+++ b/common/machine_id.c
@@ -0,0 +1,65 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (C) 2019 Pengutronix, Bastian Krause <kernel@pengutronix.de>
+ */
+
+#define pr_fmt(fmt) "machine-id: " fmt
+
+#include <common.h>
+#include <init.h>
+#include <digest.h>
+#include <globalvar.h>
+#include <crypto/sha.h>
+#include <machine_id.h>
+
+#define MACHINE_ID_LENGTH 32
+
+static void *__machine_id_hashable;
+static size_t __machine_id_hashable_length;
+
+
+void machine_id_set_hashable(void *hashable, size_t len)
+{
+	__machine_id_hashable = hashable;
+	__machine_id_hashable_length = len;
+}
+
+static int machine_id_set_bootarg(void)
+{
+	struct digest *digest = NULL;
+	unsigned char machine_id[SHA1_DIGEST_SIZE];
+	char *hex_id;
+	int ret = 0;
+
+	if (!__machine_id_hashable) {
+		pr_warn("No hashable set, will not pass id to kernel\n");
+		goto out;
+	}
+
+	hex_id = "systemd.machine_id=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
+
+	digest = digest_alloc_by_algo(HASH_ALGO_SHA1);
+	ret = digest_init(digest);
+	if (ret)
+		goto out;
+
+	ret = digest_update(digest, &__machine_id_hashable,
+			    __machine_id_hashable_length);
+	if (ret)
+		goto out;
+
+	ret = digest_final(digest, machine_id);
+	if (ret)
+		goto out;
+
+	/* use the first 16 bytes of the sha1 hash as the machine-id */
+	bin2hex(&hex_id[19], &machine_id[0], MACHINE_ID_LENGTH/2);
+
+	globalvar_add_simple("linux.bootargs.machine_id", &hex_id[0]);
+
+out:
+	digest_free(digest);
+	return ret;
+
+}
+late_initcall(machine_id_set_bootarg);
diff --git a/include/machine_id.h b/include/machine_id.h
new file mode 100644
index 0000000000..e4a9dacd4d
--- /dev/null
+++ b/include/machine_id.h
@@ -0,0 +1,6 @@
+#ifndef __MACHINE_ID_H__
+#define __MACHINE_ID_H__
+
+void machine_id_set_hashable(void *hashable, size_t len);
+
+#endif  /* __MACHINE_ID_H__ */
-- 
2.20.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH 3/3] nvmem: ocotp: set unique id as machine-id hashable
  2019-07-16 10:58 [PATCH 1/3] digest.h: needs errno definitions Bastian Krause
  2019-07-16 10:58 ` [PATCH 2/3] common: machine_id: introduce machine id generation and pass id on Bastian Krause
@ 2019-07-16 10:58 ` Bastian Krause
  2019-07-17  9:50   ` Sascha Hauer
  1 sibling, 1 reply; 13+ messages in thread
From: Bastian Krause @ 2019-07-16 10:58 UTC (permalink / raw)
  To: barebox; +Cc: Bastian Krause

Pass the OCOTP unique id as hashable information to machine id
generation.

Signed-off-by: Bastian Krause <bst@pengutronix.de>
---
 drivers/nvmem/ocotp.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/drivers/nvmem/ocotp.c b/drivers/nvmem/ocotp.c
index 3f9f162860..6f76ad9ac0 100644
--- a/drivers/nvmem/ocotp.c
+++ b/drivers/nvmem/ocotp.c
@@ -29,6 +29,7 @@
 #include <regmap.h>
 #include <linux/clk.h>
 #include <mach/ocotp.h>
+#include <machine_id.h>
 #include <linux/nvmem-provider.h>
 
 /*
@@ -77,6 +78,9 @@
 #define MAC_OFFSET_1			(0x24 * 4)
 #define MAX_MAC_OFFSETS			2
 #define MAC_BYTES			8
+#define UNIQUE_ID_NUM			2
+/* 0 <= n < UNIQUE_ID_NUM */
+#define UNIQUE_ID(n)			(OCOTP_WORD(0x410 + 0x10 * (n)) | OCOTP_BIT(0) | OCOTP_WIDTH(32))
 
 enum imx_ocotp_format_mac_direction {
 	OCOTP_HW_TO_MAC,
@@ -548,6 +552,23 @@ static int imx_ocotp_read(struct device_d *dev, const int offset, void *val,
 	return regmap_bulk_read(priv->map, offset, val, bytes);
 }
 
+static int imx_ocotp_set_unique_machine_id(void)
+{
+	uint32_t unique_id_parts[UNIQUE_ID_NUM];
+	int ret, i;
+
+	for (i = 0; i < UNIQUE_ID_NUM; i++) {
+		ret = imx_ocotp_read_field(UNIQUE_ID(i), &unique_id_parts[i]);
+		if (ret < 0)
+			goto out;
+	}
+
+	machine_id_set_hashable(&unique_id_parts, sizeof(unique_id_parts));
+
+out:
+	return ret;
+}
+
 static const struct nvmem_bus imx_ocotp_nvmem_bus = {
 	.write = imx_ocotp_write,
 	.read  = imx_ocotp_read,
@@ -633,6 +654,9 @@ static int imx_ocotp_probe(struct device_d *dev)
 				  ethaddr->value, ethaddr);
 	}
 
+	if (IS_ENABLED(CONFIG_MACHINE_ID))
+		imx_ocotp_set_unique_machine_id();
+
 	imx_ocotp_init_dt(priv);
 
 	dev_add_param_bool(&(priv->dev), "sense_enable", NULL, NULL, &priv->sense_enable, priv);
-- 
2.20.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 2/3] common: machine_id: introduce machine id generation and pass id on
  2019-07-16 10:58 ` [PATCH 2/3] common: machine_id: introduce machine id generation and pass id on Bastian Krause
@ 2019-07-17  9:48   ` Sascha Hauer
  2019-07-17  9:58     ` Bastian Krause
  2019-07-17  9:53   ` Ahmad Fatoum
  2019-07-17 10:02   ` Roland Hieber
  2 siblings, 1 reply; 13+ messages in thread
From: Sascha Hauer @ 2019-07-17  9:48 UTC (permalink / raw)
  To: Bastian Krause; +Cc: barebox

On Tue, Jul 16, 2019 at 12:58:36PM +0200, Bastian Krause wrote:
> By default systemd generates a machine id on first boot and tries to
> persist it (see `man machine-id`). When the root file system is read-only
> systemd cannot persist the machine id. In case multiple redundant slots
> are used the machine id will vary. When not handled explicitly the
> machine id will also change during updates.
> 
> It is possible to pass a machine id to the kernel which will be used by
> systemd (systemd.machine_id=).
> 
> This adds functionality to pass device-specific information that will be
> hashed to generate a persistent unique machine id. The machine id will
> be finally added to the kernel parameters via the
> linux.bootargs.machine_id global variable.
> 
> Note: if multiple sources provide hashable device-specific information
> (via machine_id_set_hashable()) the information provided by the last call
> prior to the late initcall set_machine_id() is used to generate the
> machine id from. Thus when updating barebox the machine id might change.
> 
> Signed-off-by: Bastian Krause <bst@pengutronix.de>
> ---
>  common/Kconfig       | 11 ++++++++
>  common/Makefile      |  1 +
>  common/machine_id.c  | 65 ++++++++++++++++++++++++++++++++++++++++++++
>  include/machine_id.h |  6 ++++
>  4 files changed, 83 insertions(+)
>  create mode 100644 common/machine_id.c
>  create mode 100644 include/machine_id.h
> 
> diff --git a/common/Kconfig b/common/Kconfig
> index 8aad5baecd..4b2d79350d 100644
> --- a/common/Kconfig
> +++ b/common/Kconfig
> @@ -982,6 +982,17 @@ config RESET_SOURCE
>  	  of the reset and why the bootloader is currently running. It can be
>  	  useful for any kind of system recovery or repair.
>  
> +config MACHINE_ID
> +	bool "pass machine-id to kernel"
> +	depends on FLEXIBLE_BOOTARGS
> +	select DIGEST
> +	select DIGEST_SHA1_GENERIC
> +	help
> +	  Sets the linux.bootargs.machine_id global variable with a value of
> +	  systemd.machine_id=UID. The UID is a persistent device-specific
> +	  id. It is a hash over device-specific information provided by various
> +	  sources.
> +
>  endmenu
>  
>  menu "Debugging"
> diff --git a/common/Makefile b/common/Makefile
> index a284655fc1..10960169f9 100644
> --- a/common/Makefile
> +++ b/common/Makefile
> @@ -11,6 +11,7 @@ obj-y				+= bootsource.o
>  obj-$(CONFIG_ELF)		+= elf.o
>  obj-y				+= restart.o
>  obj-y				+= poweroff.o
> +obj-$(CONFIG_MACHINE_ID)	+= machine_id.o
>  obj-$(CONFIG_AUTO_COMPLETE)	+= complete.o
>  obj-y				+= version.o
>  obj-$(CONFIG_BAREBOX_UPDATE)	+= bbu.o
> diff --git a/common/machine_id.c b/common/machine_id.c
> new file mode 100644
> index 0000000000..54c1820086
> --- /dev/null
> +++ b/common/machine_id.c
> @@ -0,0 +1,65 @@
> +/* SPDX-License-Identifier: GPL-2.0 */
> +/*
> + * Copyright (C) 2019 Pengutronix, Bastian Krause <kernel@pengutronix.de>
> + */
> +
> +#define pr_fmt(fmt) "machine-id: " fmt
> +
> +#include <common.h>
> +#include <init.h>
> +#include <digest.h>
> +#include <globalvar.h>
> +#include <crypto/sha.h>
> +#include <machine_id.h>
> +
> +#define MACHINE_ID_LENGTH 32
> +
> +static void *__machine_id_hashable;
> +static size_t __machine_id_hashable_length;
> +
> +
> +void machine_id_set_hashable(void *hashable, size_t len)

const void *

> +{
> +	__machine_id_hashable = hashable;
> +	__machine_id_hashable_length = len;

You should make a copy rather than storing the pointer.

> +}
> +
> +static int machine_id_set_bootarg(void)
> +{
> +	struct digest *digest = NULL;
> +	unsigned char machine_id[SHA1_DIGEST_SIZE];
> +	char *hex_id;
> +	int ret = 0;
> +
> +	if (!__machine_id_hashable) {
> +		pr_warn("No hashable set, will not pass id to kernel\n");

I don't think this is worth a warning. With this series this will be
issued for example on all non i.MX6 boards enabled in imx_v7_defconfig.

> +		goto out;
> +	}
> +
> +	hex_id = "systemd.machine_id=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";

This string should be treated const, better allocate hex_id.

> +
> +	digest = digest_alloc_by_algo(HASH_ALGO_SHA1);
> +	ret = digest_init(digest);
> +	if (ret)
> +		goto out;
> +
> +	ret = digest_update(digest, &__machine_id_hashable,
> +			    __machine_id_hashable_length);

You are hashing the address of the __machine_id_hashable pointer here.

> +	if (ret)
> +		goto out;
> +
> +	ret = digest_final(digest, machine_id);
> +	if (ret)
> +		goto out;
> +
> +	/* use the first 16 bytes of the sha1 hash as the machine-id */
> +	bin2hex(&hex_id[19], &machine_id[0], MACHINE_ID_LENGTH/2);
> +
> +	globalvar_add_simple("linux.bootargs.machine_id", &hex_id[0]);
> +
> +out:
> +	digest_free(digest);
> +	return ret;
> +
> +}
> +late_initcall(machine_id_set_bootarg);
> diff --git a/include/machine_id.h b/include/machine_id.h
> new file mode 100644
> index 0000000000..e4a9dacd4d
> --- /dev/null
> +++ b/include/machine_id.h
> @@ -0,0 +1,6 @@
> +#ifndef __MACHINE_ID_H__
> +#define __MACHINE_ID_H__
> +
> +void machine_id_set_hashable(void *hashable, size_t len);

You should add a static inline wrapper for CONFIG_MACHINE_ID disabled.

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 3/3] nvmem: ocotp: set unique id as machine-id hashable
  2019-07-16 10:58 ` [PATCH 3/3] nvmem: ocotp: set unique id as machine-id hashable Bastian Krause
@ 2019-07-17  9:50   ` Sascha Hauer
  0 siblings, 0 replies; 13+ messages in thread
From: Sascha Hauer @ 2019-07-17  9:50 UTC (permalink / raw)
  To: Bastian Krause; +Cc: barebox

On Tue, Jul 16, 2019 at 12:58:37PM +0200, Bastian Krause wrote:
> Pass the OCOTP unique id as hashable information to machine id
> generation.
> 
> Signed-off-by: Bastian Krause <bst@pengutronix.de>
> ---
>  drivers/nvmem/ocotp.c | 24 ++++++++++++++++++++++++
>  1 file changed, 24 insertions(+)
> 
> diff --git a/drivers/nvmem/ocotp.c b/drivers/nvmem/ocotp.c
> index 3f9f162860..6f76ad9ac0 100644
> --- a/drivers/nvmem/ocotp.c
> +++ b/drivers/nvmem/ocotp.c
> @@ -29,6 +29,7 @@
>  #include <regmap.h>
>  #include <linux/clk.h>
>  #include <mach/ocotp.h>
> +#include <machine_id.h>
>  #include <linux/nvmem-provider.h>
>  
>  /*
> @@ -77,6 +78,9 @@
>  #define MAC_OFFSET_1			(0x24 * 4)
>  #define MAX_MAC_OFFSETS			2
>  #define MAC_BYTES			8
> +#define UNIQUE_ID_NUM			2
> +/* 0 <= n < UNIQUE_ID_NUM */
> +#define UNIQUE_ID(n)			(OCOTP_WORD(0x410 + 0x10 * (n)) | OCOTP_BIT(0) | OCOTP_WIDTH(32))
>  
>  enum imx_ocotp_format_mac_direction {
>  	OCOTP_HW_TO_MAC,
> @@ -548,6 +552,23 @@ static int imx_ocotp_read(struct device_d *dev, const int offset, void *val,
>  	return regmap_bulk_read(priv->map, offset, val, bytes);
>  }
>  
> +static int imx_ocotp_set_unique_machine_id(void)
> +{
> +	uint32_t unique_id_parts[UNIQUE_ID_NUM];
> +	int ret, i;
> +
> +	for (i = 0; i < UNIQUE_ID_NUM; i++) {
> +		ret = imx_ocotp_read_field(UNIQUE_ID(i), &unique_id_parts[i]);
> +		if (ret < 0)
> +			goto out;
> +	}
> +
> +	machine_id_set_hashable(&unique_id_parts, sizeof(unique_id_parts));

So unique_id_parts is on the stack. As said, better make a copy in
machine_id_set_hashable() ;)

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 2/3] common: machine_id: introduce machine id generation and pass id on
  2019-07-16 10:58 ` [PATCH 2/3] common: machine_id: introduce machine id generation and pass id on Bastian Krause
  2019-07-17  9:48   ` Sascha Hauer
@ 2019-07-17  9:53   ` Ahmad Fatoum
  2019-07-17 10:02   ` Roland Hieber
  2 siblings, 0 replies; 13+ messages in thread
From: Ahmad Fatoum @ 2019-07-17  9:53 UTC (permalink / raw)
  To: barebox

On 16/7/19 12:58, Bastian Krause wrote:
> By default systemd generates a machine id on first boot and tries to
> persist it (see `man machine-id`). When the root file system is read-only
> systemd cannot persist the machine id. In case multiple redundant slots
> are used the machine id will vary. When not handled explicitly the
> machine id will also change during updates.
> 
> It is possible to pass a machine id to the kernel which will be used by
> systemd (systemd.machine_id=).
> 
> This adds functionality to pass device-specific information that will be
> hashed to generate a persistent unique machine id. The machine id will
> be finally added to the kernel parameters via the
> linux.bootargs.machine_id global variable.
> 
> Note: if multiple sources provide hashable device-specific information
> (via machine_id_set_hashable()) the information provided by the last call
> prior to the late initcall set_machine_id() is used to generate the
> machine id from. Thus when updating barebox the machine id might change.
> 
> Signed-off-by: Bastian Krause <bst@pengutronix.de>
> ---
>  common/Kconfig       | 11 ++++++++
>  common/Makefile      |  1 +
>  common/machine_id.c  | 65 ++++++++++++++++++++++++++++++++++++++++++++
>  include/machine_id.h |  6 ++++
>  4 files changed, 83 insertions(+)
>  create mode 100644 common/machine_id.c
>  create mode 100644 include/machine_id.h
> 
> diff --git a/common/Kconfig b/common/Kconfig
> index 8aad5baecd..4b2d79350d 100644
> --- a/common/Kconfig
> +++ b/common/Kconfig
> @@ -982,6 +982,17 @@ config RESET_SOURCE
>  	  of the reset and why the bootloader is currently running. It can be
>  	  useful for any kind of system recovery or repair.
>  
> +config MACHINE_ID
> +	bool "pass machine-id to kernel"
> +	depends on FLEXIBLE_BOOTARGS
> +	select DIGEST
> +	select DIGEST_SHA1_GENERIC

Hmm, wouldn't it be better to depend on SHA1 to allow use of DIGEST_SHA1_ARM?

> +	help
> +	  Sets the linux.bootargs.machine_id global variable with a value of
> +	  systemd.machine_id=UID. The UID is a persistent device-specific
> +	  id. It is a hash over device-specific information provided by various
> +	  sources.
> +
>  endmenu
>  
>  menu "Debugging"
> diff --git a/common/Makefile b/common/Makefile
> index a284655fc1..10960169f9 100644
> --- a/common/Makefile
> +++ b/common/Makefile
> @@ -11,6 +11,7 @@ obj-y				+= bootsource.o
>  obj-$(CONFIG_ELF)		+= elf.o
>  obj-y				+= restart.o
>  obj-y				+= poweroff.o
> +obj-$(CONFIG_MACHINE_ID)	+= machine_id.o
>  obj-$(CONFIG_AUTO_COMPLETE)	+= complete.o
>  obj-y				+= version.o
>  obj-$(CONFIG_BAREBOX_UPDATE)	+= bbu.o
> diff --git a/common/machine_id.c b/common/machine_id.c
> new file mode 100644
> index 0000000000..54c1820086
> --- /dev/null
> +++ b/common/machine_id.c
> @@ -0,0 +1,65 @@
> +/* SPDX-License-Identifier: GPL-2.0 */
> +/*
> + * Copyright (C) 2019 Pengutronix, Bastian Krause <kernel@pengutronix.de>
> + */
> +
> +#define pr_fmt(fmt) "machine-id: " fmt
> +
> +#include <common.h>
> +#include <init.h>
> +#include <digest.h>
> +#include <globalvar.h>
> +#include <crypto/sha.h>
> +#include <machine_id.h>
> +
> +#define MACHINE_ID_LENGTH 32
> +
> +static void *__machine_id_hashable;
> +static size_t __machine_id_hashable_length;
> +
> +
> +void machine_id_set_hashable(void *hashable, size_t len)
> +{
> +	__machine_id_hashable = hashable;
> +	__machine_id_hashable_length = len;
> +}
> +
> +static int machine_id_set_bootarg(void)
> +{
> +	struct digest *digest = NULL;
> +	unsigned char machine_id[SHA1_DIGEST_SIZE];
> +	char *hex_id;

That should be an char hex_id[], no? You're writing into read-only memory here.

> +	int ret = 0;
> +
> +	if (!__machine_id_hashable) {
> +		pr_warn("No hashable set, will not pass id to kernel\n");
> +		goto out;
> +	}
> +
> +	hex_id = "systemd.machine_id=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
> +
> +	digest = digest_alloc_by_algo(HASH_ALGO_SHA1);
> +	ret = digest_init(digest);
> +	if (ret)
> +		goto out;
> +
> +	ret = digest_update(digest, &__machine_id_hashable,
> +			    __machine_id_hashable_length);
> +	if (ret)
> +		goto out;
> +
> +	ret = digest_final(digest, machine_id);
> +	if (ret)
> +		goto out;
> +
> +	/* use the first 16 bytes of the sha1 hash as the machine-id */
> +	bin2hex(&hex_id[19], &machine_id[0], MACHINE_ID_LENGTH/2);
> +
> +	globalvar_add_simple("linux.bootargs.machine_id", &hex_id[0]);
> +
> +out:
> +	digest_free(digest);
> +	return ret;
> +
> +}
> +late_initcall(machine_id_set_bootarg);
> diff --git a/include/machine_id.h b/include/machine_id.h
> new file mode 100644
> index 0000000000..e4a9dacd4d
> --- /dev/null
> +++ b/include/machine_id.h
> @@ -0,0 +1,6 @@
> +#ifndef __MACHINE_ID_H__
> +#define __MACHINE_ID_H__
> +
> +void machine_id_set_hashable(void *hashable, size_t len);
> +
> +#endif  /* __MACHINE_ID_H__ */
> 

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 2/3] common: machine_id: introduce machine id generation and pass id on
  2019-07-17  9:48   ` Sascha Hauer
@ 2019-07-17  9:58     ` Bastian Krause
  2019-07-17 10:31       ` Sascha Hauer
  0 siblings, 1 reply; 13+ messages in thread
From: Bastian Krause @ 2019-07-17  9:58 UTC (permalink / raw)
  To: Sascha Hauer; +Cc: barebox


On 7/17/19 11:48 AM, Sascha Hauer wrote:
> On Tue, Jul 16, 2019 at 12:58:36PM +0200, Bastian Krause wrote:
>> By default systemd generates a machine id on first boot and tries to
>> persist it (see `man machine-id`). When the root file system is read-only
>> systemd cannot persist the machine id. In case multiple redundant slots
>> are used the machine id will vary. When not handled explicitly the
>> machine id will also change during updates.
>>
>> It is possible to pass a machine id to the kernel which will be used by
>> systemd (systemd.machine_id=).
>>
>> This adds functionality to pass device-specific information that will be
>> hashed to generate a persistent unique machine id. The machine id will
>> be finally added to the kernel parameters via the
>> linux.bootargs.machine_id global variable.
>>
>> Note: if multiple sources provide hashable device-specific information
>> (via machine_id_set_hashable()) the information provided by the last call
>> prior to the late initcall set_machine_id() is used to generate the
>> machine id from. Thus when updating barebox the machine id might change.
>>
>> Signed-off-by: Bastian Krause <bst@pengutronix.de>
>> ---
>>  common/Kconfig       | 11 ++++++++
>>  common/Makefile      |  1 +
>>  common/machine_id.c  | 65 ++++++++++++++++++++++++++++++++++++++++++++
>>  include/machine_id.h |  6 ++++
>>  4 files changed, 83 insertions(+)
>>  create mode 100644 common/machine_id.c
>>  create mode 100644 include/machine_id.h
>>
>> diff --git a/common/Kconfig b/common/Kconfig
>> index 8aad5baecd..4b2d79350d 100644
>> --- a/common/Kconfig
>> +++ b/common/Kconfig
>> @@ -982,6 +982,17 @@ config RESET_SOURCE
>>  	  of the reset and why the bootloader is currently running. It can be
>>  	  useful for any kind of system recovery or repair.
>>  
>> +config MACHINE_ID
>> +	bool "pass machine-id to kernel"
>> +	depends on FLEXIBLE_BOOTARGS
>> +	select DIGEST
>> +	select DIGEST_SHA1_GENERIC
>> +	help
>> +	  Sets the linux.bootargs.machine_id global variable with a value of
>> +	  systemd.machine_id=UID. The UID is a persistent device-specific
>> +	  id. It is a hash over device-specific information provided by various
>> +	  sources.
>> +
>>  endmenu
>>  
>>  menu "Debugging"
>> diff --git a/common/Makefile b/common/Makefile
>> index a284655fc1..10960169f9 100644
>> --- a/common/Makefile
>> +++ b/common/Makefile
>> @@ -11,6 +11,7 @@ obj-y				+= bootsource.o
>>  obj-$(CONFIG_ELF)		+= elf.o
>>  obj-y				+= restart.o
>>  obj-y				+= poweroff.o
>> +obj-$(CONFIG_MACHINE_ID)	+= machine_id.o
>>  obj-$(CONFIG_AUTO_COMPLETE)	+= complete.o
>>  obj-y				+= version.o
>>  obj-$(CONFIG_BAREBOX_UPDATE)	+= bbu.o
>> diff --git a/common/machine_id.c b/common/machine_id.c
>> new file mode 100644
>> index 0000000000..54c1820086
>> --- /dev/null
>> +++ b/common/machine_id.c
>> @@ -0,0 +1,65 @@
>> +/* SPDX-License-Identifier: GPL-2.0 */
>> +/*
>> + * Copyright (C) 2019 Pengutronix, Bastian Krause <kernel@pengutronix.de>
>> + */
>> +
>> +#define pr_fmt(fmt) "machine-id: " fmt
>> +
>> +#include <common.h>
>> +#include <init.h>
>> +#include <digest.h>
>> +#include <globalvar.h>
>> +#include <crypto/sha.h>
>> +#include <machine_id.h>
>> +
>> +#define MACHINE_ID_LENGTH 32
>> +
>> +static void *__machine_id_hashable;
>> +static size_t __machine_id_hashable_length;
>> +
>> +
>> +void machine_id_set_hashable(void *hashable, size_t len)
> 
> const void *
> 
>> +{
>> +	__machine_id_hashable = hashable;
>> +	__machine_id_hashable_length = len;
> 
> You should make a copy rather than storing the pointer.
> 
>> +}
>> +
>> +static int machine_id_set_bootarg(void)
>> +{
>> +	struct digest *digest = NULL;
>> +	unsigned char machine_id[SHA1_DIGEST_SIZE];
>> +	char *hex_id;
>> +	int ret = 0;
>> +
>> +	if (!__machine_id_hashable) {
>> +		pr_warn("No hashable set, will not pass id to kernel\n");
> 
> I don't think this is worth a warning. With this series this will be
> issued for example on all non i.MX6 boards enabled in imx_v7_defconfig.

If I enable CONFIG_MACHINE_ID I'd expect the machine id being passed to
the kernel. This is not the case for these boards. Isn't that somewhat
surprising?

Bastian

-- 
Pengutronix e.K.
Industrial Linux Solutions
http://www.pengutronix.de/
Peiner Str. 6-8, 31137 Hildesheim, Germany
Amtsgericht Hildesheim, HRA 2686

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 2/3] common: machine_id: introduce machine id generation and pass id on
  2019-07-16 10:58 ` [PATCH 2/3] common: machine_id: introduce machine id generation and pass id on Bastian Krause
  2019-07-17  9:48   ` Sascha Hauer
  2019-07-17  9:53   ` Ahmad Fatoum
@ 2019-07-17 10:02   ` Roland Hieber
  2019-07-17 10:31     ` Ahmad Fatoum
  2 siblings, 1 reply; 13+ messages in thread
From: Roland Hieber @ 2019-07-17 10:02 UTC (permalink / raw)
  To: Bastian Krause; +Cc: barebox

On Tue, Jul 16, 2019 at 12:58:36PM +0200, Bastian Krause wrote:
> By default systemd generates a machine id on first boot and tries to
> persist it (see `man machine-id`). When the root file system is read-only
> systemd cannot persist the machine id. In case multiple redundant slots
> are used the machine id will vary. When not handled explicitly the
> machine id will also change during updates.
> 
> It is possible to pass a machine id to the kernel which will be used by
> systemd (systemd.machine_id=).
> 
> This adds functionality to pass device-specific information that will be
> hashed to generate a persistent unique machine id. The machine id will
> be finally added to the kernel parameters via the
> linux.bootargs.machine_id global variable.
> 
> Note: if multiple sources provide hashable device-specific information
> (via machine_id_set_hashable()) the information provided by the last call
> prior to the late initcall set_machine_id() is used to generate the
> machine id from. Thus when updating barebox the machine id might change.

I would also add this paragraph to the kconfig help text, so it is more
visible for users.

 - Roland

> 
> Signed-off-by: Bastian Krause <bst@pengutronix.de>
> ---
>  common/Kconfig       | 11 ++++++++
>  common/Makefile      |  1 +
>  common/machine_id.c  | 65 ++++++++++++++++++++++++++++++++++++++++++++
>  include/machine_id.h |  6 ++++
>  4 files changed, 83 insertions(+)
>  create mode 100644 common/machine_id.c
>  create mode 100644 include/machine_id.h
> 
> diff --git a/common/Kconfig b/common/Kconfig
> index 8aad5baecd..4b2d79350d 100644
> --- a/common/Kconfig
> +++ b/common/Kconfig
> @@ -982,6 +982,17 @@ config RESET_SOURCE
>  	  of the reset and why the bootloader is currently running. It can be
>  	  useful for any kind of system recovery or repair.
>  
> +config MACHINE_ID
> +	bool "pass machine-id to kernel"
> +	depends on FLEXIBLE_BOOTARGS
> +	select DIGEST
> +	select DIGEST_SHA1_GENERIC
> +	help
> +	  Sets the linux.bootargs.machine_id global variable with a value of
> +	  systemd.machine_id=UID. The UID is a persistent device-specific
> +	  id. It is a hash over device-specific information provided by various
> +	  sources.
> +
>  endmenu
>  
>  menu "Debugging"
> diff --git a/common/Makefile b/common/Makefile
> index a284655fc1..10960169f9 100644
> --- a/common/Makefile
> +++ b/common/Makefile
> @@ -11,6 +11,7 @@ obj-y				+= bootsource.o
>  obj-$(CONFIG_ELF)		+= elf.o
>  obj-y				+= restart.o
>  obj-y				+= poweroff.o
> +obj-$(CONFIG_MACHINE_ID)	+= machine_id.o
>  obj-$(CONFIG_AUTO_COMPLETE)	+= complete.o
>  obj-y				+= version.o
>  obj-$(CONFIG_BAREBOX_UPDATE)	+= bbu.o
> diff --git a/common/machine_id.c b/common/machine_id.c
> new file mode 100644
> index 0000000000..54c1820086
> --- /dev/null
> +++ b/common/machine_id.c
> @@ -0,0 +1,65 @@
> +/* SPDX-License-Identifier: GPL-2.0 */
> +/*
> + * Copyright (C) 2019 Pengutronix, Bastian Krause <kernel@pengutronix.de>
> + */
> +
> +#define pr_fmt(fmt) "machine-id: " fmt
> +
> +#include <common.h>
> +#include <init.h>
> +#include <digest.h>
> +#include <globalvar.h>
> +#include <crypto/sha.h>
> +#include <machine_id.h>
> +
> +#define MACHINE_ID_LENGTH 32
> +
> +static void *__machine_id_hashable;
> +static size_t __machine_id_hashable_length;
> +
> +
> +void machine_id_set_hashable(void *hashable, size_t len)
> +{
> +	__machine_id_hashable = hashable;
> +	__machine_id_hashable_length = len;
> +}
> +
> +static int machine_id_set_bootarg(void)
> +{
> +	struct digest *digest = NULL;
> +	unsigned char machine_id[SHA1_DIGEST_SIZE];
> +	char *hex_id;
> +	int ret = 0;
> +
> +	if (!__machine_id_hashable) {
> +		pr_warn("No hashable set, will not pass id to kernel\n");
> +		goto out;
> +	}
> +
> +	hex_id = "systemd.machine_id=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
> +
> +	digest = digest_alloc_by_algo(HASH_ALGO_SHA1);
> +	ret = digest_init(digest);
> +	if (ret)
> +		goto out;
> +
> +	ret = digest_update(digest, &__machine_id_hashable,
> +			    __machine_id_hashable_length);
> +	if (ret)
> +		goto out;
> +
> +	ret = digest_final(digest, machine_id);
> +	if (ret)
> +		goto out;
> +
> +	/* use the first 16 bytes of the sha1 hash as the machine-id */
> +	bin2hex(&hex_id[19], &machine_id[0], MACHINE_ID_LENGTH/2);
> +
> +	globalvar_add_simple("linux.bootargs.machine_id", &hex_id[0]);
> +
> +out:
> +	digest_free(digest);
> +	return ret;
> +
> +}
> +late_initcall(machine_id_set_bootarg);
> diff --git a/include/machine_id.h b/include/machine_id.h
> new file mode 100644
> index 0000000000..e4a9dacd4d
> --- /dev/null
> +++ b/include/machine_id.h
> @@ -0,0 +1,6 @@
> +#ifndef __MACHINE_ID_H__
> +#define __MACHINE_ID_H__
> +
> +void machine_id_set_hashable(void *hashable, size_t len);
> +
> +#endif  /* __MACHINE_ID_H__ */
> -- 
> 2.20.1
> 
> 
> _______________________________________________
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
> 

-- 
Roland Hieber                     | r.hieber@pengutronix.de     |
Pengutronix e.K.                  | https://www.pengutronix.de/ |
Peiner Str. 6-8, 31137 Hildesheim | Phone: +49-5121-206917-5086 |
Amtsgericht Hildesheim, HRA 2686  | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 2/3] common: machine_id: introduce machine id generation and pass id on
  2019-07-17 10:02   ` Roland Hieber
@ 2019-07-17 10:31     ` Ahmad Fatoum
  2019-07-17 14:02       ` Bastian Krause
  0 siblings, 1 reply; 13+ messages in thread
From: Ahmad Fatoum @ 2019-07-17 10:31 UTC (permalink / raw)
  To: barebox



On 17/7/19 12:02, Roland Hieber wrote:
> On Tue, Jul 16, 2019 at 12:58:36PM +0200, Bastian Krause wrote:
>> By default systemd generates a machine id on first boot and tries to
>> persist it (see `man machine-id`). When the root file system is read-only
>> systemd cannot persist the machine id. In case multiple redundant slots
>> are used the machine id will vary. When not handled explicitly the
>> machine id will also change during updates.
>>
>> It is possible to pass a machine id to the kernel which will be used by
>> systemd (systemd.machine_id=).
>>
>> This adds functionality to pass device-specific information that will be
>> hashed to generate a persistent unique machine id. The machine id will
>> be finally added to the kernel parameters via the
>> linux.bootargs.machine_id global variable.
>>
>> Note: if multiple sources provide hashable device-specific information
>> (via machine_id_set_hashable()) the information provided by the last call
>> prior to the late initcall set_machine_id() is used to generate the
>> machine id from. Thus when updating barebox the machine id might change.
> 
> I would also add this paragraph to the kconfig help text, so it is more
> visible for users.

Maybe add a priority parameter like we do with e.g. reset reason?
That way we can have a base machine-id in the OTP, but board code can
override it with e.g. an EEPROM value which is given higher priority.

> 
>  - Roland
> 
>>
>> Signed-off-by: Bastian Krause <bst@pengutronix.de>
>> ---
>>  common/Kconfig       | 11 ++++++++
>>  common/Makefile      |  1 +
>>  common/machine_id.c  | 65 ++++++++++++++++++++++++++++++++++++++++++++
>>  include/machine_id.h |  6 ++++
>>  4 files changed, 83 insertions(+)
>>  create mode 100644 common/machine_id.c
>>  create mode 100644 include/machine_id.h
>>
>> diff --git a/common/Kconfig b/common/Kconfig
>> index 8aad5baecd..4b2d79350d 100644
>> --- a/common/Kconfig
>> +++ b/common/Kconfig
>> @@ -982,6 +982,17 @@ config RESET_SOURCE
>>  	  of the reset and why the bootloader is currently running. It can be
>>  	  useful for any kind of system recovery or repair.
>>  
>> +config MACHINE_ID
>> +	bool "pass machine-id to kernel"
>> +	depends on FLEXIBLE_BOOTARGS
>> +	select DIGEST
>> +	select DIGEST_SHA1_GENERIC
>> +	help
>> +	  Sets the linux.bootargs.machine_id global variable with a value of
>> +	  systemd.machine_id=UID. The UID is a persistent device-specific
>> +	  id. It is a hash over device-specific information provided by various
>> +	  sources.
>> +
>>  endmenu
>>  
>>  menu "Debugging"
>> diff --git a/common/Makefile b/common/Makefile
>> index a284655fc1..10960169f9 100644
>> --- a/common/Makefile
>> +++ b/common/Makefile
>> @@ -11,6 +11,7 @@ obj-y				+= bootsource.o
>>  obj-$(CONFIG_ELF)		+= elf.o
>>  obj-y				+= restart.o
>>  obj-y				+= poweroff.o
>> +obj-$(CONFIG_MACHINE_ID)	+= machine_id.o
>>  obj-$(CONFIG_AUTO_COMPLETE)	+= complete.o
>>  obj-y				+= version.o
>>  obj-$(CONFIG_BAREBOX_UPDATE)	+= bbu.o
>> diff --git a/common/machine_id.c b/common/machine_id.c
>> new file mode 100644
>> index 0000000000..54c1820086
>> --- /dev/null
>> +++ b/common/machine_id.c
>> @@ -0,0 +1,65 @@
>> +/* SPDX-License-Identifier: GPL-2.0 */
>> +/*
>> + * Copyright (C) 2019 Pengutronix, Bastian Krause <kernel@pengutronix.de>
>> + */
>> +
>> +#define pr_fmt(fmt) "machine-id: " fmt
>> +
>> +#include <common.h>
>> +#include <init.h>
>> +#include <digest.h>
>> +#include <globalvar.h>
>> +#include <crypto/sha.h>
>> +#include <machine_id.h>
>> +
>> +#define MACHINE_ID_LENGTH 32
>> +
>> +static void *__machine_id_hashable;
>> +static size_t __machine_id_hashable_length;
>> +
>> +
>> +void machine_id_set_hashable(void *hashable, size_t len)
>> +{
>> +	__machine_id_hashable = hashable;
>> +	__machine_id_hashable_length = len;
>> +}
>> +
>> +static int machine_id_set_bootarg(void)
>> +{
>> +	struct digest *digest = NULL;
>> +	unsigned char machine_id[SHA1_DIGEST_SIZE];
>> +	char *hex_id;
>> +	int ret = 0;
>> +
>> +	if (!__machine_id_hashable) {
>> +		pr_warn("No hashable set, will not pass id to kernel\n");
>> +		goto out;
>> +	}
>> +
>> +	hex_id = "systemd.machine_id=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
>> +
>> +	digest = digest_alloc_by_algo(HASH_ALGO_SHA1);
>> +	ret = digest_init(digest);
>> +	if (ret)
>> +		goto out;
>> +
>> +	ret = digest_update(digest, &__machine_id_hashable,
>> +			    __machine_id_hashable_length);
>> +	if (ret)
>> +		goto out;
>> +
>> +	ret = digest_final(digest, machine_id);
>> +	if (ret)
>> +		goto out;
>> +
>> +	/* use the first 16 bytes of the sha1 hash as the machine-id */
>> +	bin2hex(&hex_id[19], &machine_id[0], MACHINE_ID_LENGTH/2);
>> +
>> +	globalvar_add_simple("linux.bootargs.machine_id", &hex_id[0]);
>> +
>> +out:
>> +	digest_free(digest);
>> +	return ret;
>> +
>> +}
>> +late_initcall(machine_id_set_bootarg);
>> diff --git a/include/machine_id.h b/include/machine_id.h
>> new file mode 100644
>> index 0000000000..e4a9dacd4d
>> --- /dev/null
>> +++ b/include/machine_id.h
>> @@ -0,0 +1,6 @@
>> +#ifndef __MACHINE_ID_H__
>> +#define __MACHINE_ID_H__
>> +
>> +void machine_id_set_hashable(void *hashable, size_t len);
>> +
>> +#endif  /* __MACHINE_ID_H__ */
>> -- 
>> 2.20.1
>>
>>
>> _______________________________________________
>> barebox mailing list
>> barebox@lists.infradead.org
>> http://lists.infradead.org/mailman/listinfo/barebox
>>
> 

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 2/3] common: machine_id: introduce machine id generation and pass id on
  2019-07-17  9:58     ` Bastian Krause
@ 2019-07-17 10:31       ` Sascha Hauer
  2019-07-17 10:34         ` Bastian Krause
  0 siblings, 1 reply; 13+ messages in thread
From: Sascha Hauer @ 2019-07-17 10:31 UTC (permalink / raw)
  To: Bastian Krause; +Cc: barebox

On Wed, Jul 17, 2019 at 11:58:59AM +0200, Bastian Krause wrote:
> 
> >> +	struct digest *digest = NULL;
> >> +	unsigned char machine_id[SHA1_DIGEST_SIZE];
> >> +	char *hex_id;
> >> +	int ret = 0;
> >> +
> >> +	if (!__machine_id_hashable) {
> >> +		pr_warn("No hashable set, will not pass id to kernel\n");
> > 
> > I don't think this is worth a warning. With this series this will be
> > issued for example on all non i.MX6 boards enabled in imx_v7_defconfig.
> 
> If I enable CONFIG_MACHINE_ID I'd expect the machine id being passed to
> the kernel. This is not the case for these boards. Isn't that somewhat
> surprising?

With that argument we would get a lot of warnings in a imx_v7_defconfig.
A lot of features end up unused on different boards.

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 2/3] common: machine_id: introduce machine id generation and pass id on
  2019-07-17 10:31       ` Sascha Hauer
@ 2019-07-17 10:34         ` Bastian Krause
  0 siblings, 0 replies; 13+ messages in thread
From: Bastian Krause @ 2019-07-17 10:34 UTC (permalink / raw)
  To: Sascha Hauer; +Cc: barebox


On 7/17/19 12:31 PM, Sascha Hauer wrote:
> On Wed, Jul 17, 2019 at 11:58:59AM +0200, Bastian Krause wrote:
>>
>>>> +	struct digest *digest = NULL;
>>>> +	unsigned char machine_id[SHA1_DIGEST_SIZE];
>>>> +	char *hex_id;
>>>> +	int ret = 0;
>>>> +
>>>> +	if (!__machine_id_hashable) {
>>>> +		pr_warn("No hashable set, will not pass id to kernel\n");
>>>
>>> I don't think this is worth a warning. With this series this will be
>>> issued for example on all non i.MX6 boards enabled in imx_v7_defconfig.
>>
>> If I enable CONFIG_MACHINE_ID I'd expect the machine id being passed to
>> the kernel. This is not the case for these boards. Isn't that somewhat
>> surprising?
> 
> With that argument we would get a lot of warnings in a imx_v7_defconfig.
> A lot of features end up unused on different boards.

Okay, agreed. I'll remove the warning and add a note to the kconfig help
text instead.

Bastian

-- 
Pengutronix e.K.
Industrial Linux Solutions
http://www.pengutronix.de/
Peiner Str. 6-8, 31137 Hildesheim, Germany
Amtsgericht Hildesheim, HRA 2686

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 2/3] common: machine_id: introduce machine id generation and pass id on
  2019-07-17 10:31     ` Ahmad Fatoum
@ 2019-07-17 14:02       ` Bastian Krause
  2019-07-17 14:18         ` Sascha Hauer
  0 siblings, 1 reply; 13+ messages in thread
From: Bastian Krause @ 2019-07-17 14:02 UTC (permalink / raw)
  To: Ahmad Fatoum, barebox


On 7/17/19 12:31 PM, Ahmad Fatoum wrote:
> 
> 
> On 17/7/19 12:02, Roland Hieber wrote:
>> On Tue, Jul 16, 2019 at 12:58:36PM +0200, Bastian Krause wrote:
>>> By default systemd generates a machine id on first boot and tries to
>>> persist it (see `man machine-id`). When the root file system is read-only
>>> systemd cannot persist the machine id. In case multiple redundant slots
>>> are used the machine id will vary. When not handled explicitly the
>>> machine id will also change during updates.
>>>
>>> It is possible to pass a machine id to the kernel which will be used by
>>> systemd (systemd.machine_id=).
>>>
>>> This adds functionality to pass device-specific information that will be
>>> hashed to generate a persistent unique machine id. The machine id will
>>> be finally added to the kernel parameters via the
>>> linux.bootargs.machine_id global variable.
>>>
>>> Note: if multiple sources provide hashable device-specific information
>>> (via machine_id_set_hashable()) the information provided by the last call
>>> prior to the late initcall set_machine_id() is used to generate the
>>> machine id from. Thus when updating barebox the machine id might change.
>>
>> I would also add this paragraph to the kconfig help text, so it is more
>> visible for users.
> 
> Maybe add a priority parameter like we do with e.g. reset reason?
> That way we can have a base machine-id in the OTP, but board code can
> override it with e.g. an EEPROM value which is given higher priority.

Hm, that makes things complicated. At the end everybody will have their
own high priority call like..

  machine_id_set_hashable(my_board_specific_info, len, 99);

.. to have a machine id that persists such an update scenario? That does
not sound too good to me..

Any opinions on this?

Bastian

-- 
Pengutronix e.K.
Industrial Linux Solutions
http://www.pengutronix.de/
Peiner Str. 6-8, 31137 Hildesheim, Germany
Amtsgericht Hildesheim, HRA 2686

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 2/3] common: machine_id: introduce machine id generation and pass id on
  2019-07-17 14:02       ` Bastian Krause
@ 2019-07-17 14:18         ` Sascha Hauer
  0 siblings, 0 replies; 13+ messages in thread
From: Sascha Hauer @ 2019-07-17 14:18 UTC (permalink / raw)
  To: Bastian Krause; +Cc: barebox, Ahmad Fatoum

On Wed, Jul 17, 2019 at 04:02:45PM +0200, Bastian Krause wrote:
> 
> On 7/17/19 12:31 PM, Ahmad Fatoum wrote:
> > 
> > 
> > On 17/7/19 12:02, Roland Hieber wrote:
> >> On Tue, Jul 16, 2019 at 12:58:36PM +0200, Bastian Krause wrote:
> >>> By default systemd generates a machine id on first boot and tries to
> >>> persist it (see `man machine-id`). When the root file system is read-only
> >>> systemd cannot persist the machine id. In case multiple redundant slots
> >>> are used the machine id will vary. When not handled explicitly the
> >>> machine id will also change during updates.
> >>>
> >>> It is possible to pass a machine id to the kernel which will be used by
> >>> systemd (systemd.machine_id=).
> >>>
> >>> This adds functionality to pass device-specific information that will be
> >>> hashed to generate a persistent unique machine id. The machine id will
> >>> be finally added to the kernel parameters via the
> >>> linux.bootargs.machine_id global variable.
> >>>
> >>> Note: if multiple sources provide hashable device-specific information
> >>> (via machine_id_set_hashable()) the information provided by the last call
> >>> prior to the late initcall set_machine_id() is used to generate the
> >>> machine id from. Thus when updating barebox the machine id might change.
> >>
> >> I would also add this paragraph to the kconfig help text, so it is more
> >> visible for users.
> > 
> > Maybe add a priority parameter like we do with e.g. reset reason?
> > That way we can have a base machine-id in the OTP, but board code can
> > override it with e.g. an EEPROM value which is given higher priority.
> 
> Hm, that makes things complicated. At the end everybody will have their
> own high priority call like..
> 
>   machine_id_set_hashable(my_board_specific_info, len, 99);
> 
> .. to have a machine id that persists such an update scenario? That does
> not sound too good to me..
> 
> Any opinions on this?

I don't think there's going to be a race for priorities. But anyway, I
think we can introduce priorities when we really have a need for them.
Just introducing them because we might need them some day seems like
unnecessary overhead to me.

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2019-07-17 14:18 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-16 10:58 [PATCH 1/3] digest.h: needs errno definitions Bastian Krause
2019-07-16 10:58 ` [PATCH 2/3] common: machine_id: introduce machine id generation and pass id on Bastian Krause
2019-07-17  9:48   ` Sascha Hauer
2019-07-17  9:58     ` Bastian Krause
2019-07-17 10:31       ` Sascha Hauer
2019-07-17 10:34         ` Bastian Krause
2019-07-17  9:53   ` Ahmad Fatoum
2019-07-17 10:02   ` Roland Hieber
2019-07-17 10:31     ` Ahmad Fatoum
2019-07-17 14:02       ` Bastian Krause
2019-07-17 14:18         ` Sascha Hauer
2019-07-16 10:58 ` [PATCH 3/3] nvmem: ocotp: set unique id as machine-id hashable Bastian Krause
2019-07-17  9:50   ` Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox