digest.h: needs errno definitions
PATCH v2 1/3 digest.h: needs errno definitions
From: Juergen Borleis <[email protected]>
digest_set_key() returns -ENOTSUPP conditionally, so include errno.h.
---
Changes since (implicit) v1:
- no changes
--- include/digest.h | 1 + 1 file changed, 1 insertion(+)
include/digest.h +1 -0
@@ -20,6 +20,7 @@#define __DIGEST_H__#include <linux/list.h> +#include <errno.h> struct digest ;
Signature · 7 lines
2.20.1 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH v2 2/3 common: machine_id: introduce machine id generation and pass id on
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.
---
Changes since (implicit) v1:
- depend on SHA1 instead of selecting DIGEST/DIGEST_SHA1_GENERIC
- add note about multiple sources providing hashables to kconfig
- add note about no hashable provided to kconfig
- remove warning about "no hashable info provided" along with pr_fmt
- make machine_id_set_hashable()'s hashable parameter const
- make a copy of the hashable provided rather than storing the pointer
- hash data instead of pointer address
- use basprintf() and dedicated variables for hex machine id/machine id bootarg
- add static inline wrapper if CONFIG_MACHINE_ID is disabled
--- common/Kconfig | 18 +++++++++++++ common/Makefile | 1 + common/machine_id.c | 63 ++++++++++++++++++++++++++++++++++++++++++++ include/machine_id.h | 16 +++++++++++ 4 files changed, 98 insertions(+) create mode 100644 common/machine_id.c create mode 100644 include/machine_id.h
common/Kconfig +18 -0
@@ -982,6 +982,24 @@ 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 + depends on SHA1 + 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. + + 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. + + Note: if no hashable information is available no machine id will be passed + to the kernel. + endmenu menu "Debugging"
common/Makefile +1 -0
@@ -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
common/machine_id.c new file +63 -0
63 lines not on this page · raw message
include/machine_id.h new file +16 -0
@@ -0,0 +1,16 @@ +#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__ */
Signature · 7 lines
2.20.1 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
Re: [PATCH v2 2/3] common: machine_id: introduce machine id generation and pass id on
Quoted 56 lines · 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 initcallset_machine_id()is used to generate the machine id from. Thus when updating barebox the machine id might change.Signed-off-by Bastian Krause <[email protected]>---
Changes since (implicit) v1:
- depend on SHA1 instead of selecting DIGEST/DIGEST_SHA1_GENERIC
- add note about multiple sources providing hashables to kconfig
- add note about no hashable provided to kconfig
- remove warning about "no hashable info provided" along withpr_fmt
- make machine_id_set_hashable()'s hashable parameter const
- make a copy of the hashable provided rather than storing the pointer
- hash data instead of pointer address
- usebasprintf()and dedicated variables for hex machine id/machine id bootarg
- add static inline wrapper ifCONFIG_MACHINE_IDis disabled--- common/Kconfig | 18 +++++++++++++ common/Makefile | 1 + common/machine_id.c | 63 ++++++++++++++++++++++++++++++++++++++++++++ include/machine_id.h | 16 +++++++++++ 4 files changed, 98 insertions(+) create mode 100644 common/machine_id.c create mode 100644 include/machine_id.hcommon/Kconfig +7
-0@@ -982,6 +982,24 @@ 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 + depends on SHA1 + help + Sets the linux.bootargs.machine_id global variable with a value of + systemd.machine_id=UID. The UID is a persistent device-specific
common/Kconfig config RESET_SOURCE · line 1001
Quoted 10 lines
common/Kconfig +10
-0+ id. It is a hash over device-specific information provided by various + sources. + + 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. + + Note: if no hashable information is available no machine id will be passed + to the kernel.
We'll need some additional runtime control knob whether this behaviour should be used or not. Just enabling a Kconfig option shouldn't change the behaviour of barebox. A boolean global.linux.provide_machine_id flag should do it.
Also it would be nice to provide the machine-id to barebox aswell, maybe in global.machine_id.
Overall we then get this:
- set global.machine_id during barebox startup (inicalls)
- User can overwrite it with nv.machine_id if necessary
- during booting of Linux global.linux.bootargs.machine_id is initialized with the value of global.machine_id if desired (based on global.linux.provide_machine_id)
Sascha
Signature · 9 lines
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 [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH v2 3/3 nvmem: ocotp: set unique id as machine-id hashable
In reply to Bastian KrausePass the OCOTP unique id as hashable information to machine id generation.
---
Changes since (implicit) v1:
- remove explicit address-of operator for unique_id_parts
--- drivers/nvmem/ocotp.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+)
drivers/nvmem/ocotp.c +24 -0
@@ -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);
Signature · 7 lines
2.20.1 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox