* [U-Boot] [PATCH] rpi: set board serial number in environment
@ 2016-02-22 21:06 Lubomir Rintel
2016-02-23 6:30 ` Stephen Warren
2016-02-25 15:26 ` [U-Boot] " Tom Rini
0 siblings, 2 replies; 3+ messages in thread
From: Lubomir Rintel @ 2016-02-22 21:06 UTC (permalink / raw)
To: u-boot
Gets propagated into the device tree and then into /proc/cpuinfo where
users often expect it.
Signed-off-by: Lubomir Rintel <lkundrak@v3.sk>
---
arch/arm/mach-bcm283x/include/mach/mbox.h | 11 +++++++++++
board/raspberrypi/rpi/rpi.c | 33 +++++++++++++++++++++++++++++++
2 files changed, 44 insertions(+)
diff --git a/arch/arm/mach-bcm283x/include/mach/mbox.h b/arch/arm/mach-bcm283x/include/mach/mbox.h
index 0039d09..072ff2d 100644
--- a/arch/arm/mach-bcm283x/include/mach/mbox.h
+++ b/arch/arm/mach-bcm283x/include/mach/mbox.h
@@ -150,6 +150,17 @@ struct bcm2835_mbox_tag_get_mac_address {
} body;
};
+#define BCM2835_MBOX_TAG_GET_BOARD_SERIAL 0x00010004
+
+struct bcm2835_mbox_tag_get_board_serial {
+ struct bcm2835_mbox_tag_hdr tag_hdr;
+ union {
+ struct __packed {
+ u64 serial;
+ } resp;
+ } body;
+};
+
#define BCM2835_MBOX_TAG_GET_ARM_MEMORY 0x00010005
struct bcm2835_mbox_tag_get_arm_mem {
diff --git a/board/raspberrypi/rpi/rpi.c b/board/raspberrypi/rpi/rpi.c
index 86a2232..7a75d43 100644
--- a/board/raspberrypi/rpi/rpi.c
+++ b/board/raspberrypi/rpi/rpi.c
@@ -5,6 +5,7 @@
*/
#include <common.h>
+#include <inttypes.h>
#include <config.h>
#include <dm.h>
#include <fdt_support.h>
@@ -57,6 +58,12 @@ struct msg_get_board_rev {
u32 end_tag;
};
+struct msg_get_board_serial {
+ struct bcm2835_mbox_hdr hdr;
+ struct bcm2835_mbox_tag_get_board_serial get_board_serial;
+ u32 end_tag;
+};
+
struct msg_get_mac_address {
struct bcm2835_mbox_hdr hdr;
struct bcm2835_mbox_tag_get_mac_address get_mac_address;
@@ -288,6 +295,30 @@ static void set_board_info(void)
}
#endif /* CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG */
+static void set_serial_number(void)
+{
+ ALLOC_CACHE_ALIGN_BUFFER(struct msg_get_board_serial, msg, 1);
+ int ret;
+ char serial_string[17] = { 0 };
+
+ if (getenv("serial#"))
+ return;
+
+ BCM2835_MBOX_INIT_HDR(msg);
+ BCM2835_MBOX_INIT_TAG_NO_REQ(&msg->get_board_serial, GET_BOARD_SERIAL);
+
+ ret = bcm2835_mbox_call_prop(BCM2835_MBOX_PROP_CHAN, &msg->hdr);
+ if (ret) {
+ printf("bcm2835: Could not query board serial\n");
+ /* Ignore error; not critical */
+ return;
+ }
+
+ snprintf(serial_string, sizeof(serial_string), "%016" PRIx64,
+ msg->get_board_serial.body.resp.serial);
+ setenv("serial#", serial_string);
+}
+
int misc_init_r(void)
{
set_fdtfile();
@@ -295,6 +326,8 @@ int misc_init_r(void)
#ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
set_board_info();
#endif
+ set_serial_number();
+
return 0;
}
--
2.5.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2016-02-25 15:26 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-02-22 21:06 [U-Boot] [PATCH] rpi: set board serial number in environment Lubomir Rintel
2016-02-23 6:30 ` Stephen Warren
2016-02-25 15:26 ` [U-Boot] " Tom Rini
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox