[U-Boot] [PATCH v2 1/1] board: raspberrypi: add serial and revision to the device tree

Anton Gerasimov tossel at gmail.com
Wed Feb 20 12:09:13 UTC 2019


Raspberry Pi bootloader adds this node to fdt, but if u-boot script
doesn't reuse the tree provided by it, this information is lost.

Revision and serial are displayed in /proc/cpuinfo after boot.

Suggested-By: Ricardo Salveti <rsalveti at rsalveti.net>
Reported-by: Karl Eaves <karleeaves at gmail.com>
Signed-off-by: Anton Gerasimov <tossel at gmail.com>
---
 board/raspberrypi/rpi/rpi.c | 35 +++++++++++++++++++++++++++++++++--
 1 file changed, 33 insertions(+), 2 deletions(-)

diff --git a/board/raspberrypi/rpi/rpi.c b/board/raspberrypi/rpi/rpi.c
index 153a1fdcb7..f6a2cdfbfd 100644
--- a/board/raspberrypi/rpi/rpi.c
+++ b/board/raspberrypi/rpi/rpi.c
@@ -238,6 +238,8 @@ static uint32_t rev_scheme;
 static uint32_t rev_type;
 static const struct rpi_model *model;
 
+static uint64_t serial;
+
 #ifdef CONFIG_ARM64
 static struct mm_region bcm2837_mem_map[] = {
 	{
@@ -381,8 +383,8 @@ static void set_serial_number(void)
 		return;
 	}
 
-	snprintf(serial_string, sizeof(serial_string), "%016llx",
-		 msg->get_board_serial.body.resp.serial);
+	serial = msg->get_board_serial.body.resp.serial;
+	snprintf(serial_string, sizeof(serial_string), "%016llx", serial);
 	env_set("serial#", serial_string);
 }
 
@@ -475,6 +477,33 @@ void *board_fdt_blob_setup(void)
 	return (void *)fw_dtb_pointer;
 }
 
+static int ft_add_revision_info(void *blob) {
+	int off;
+	int ret;
+
+	off = fdt_subnode_offset(blob, 0, "system");
+
+	if (off < 0) {
+		off = fdt_add_subnode(blob, 0, "system");
+		if (off < 0)
+			return -1;
+	}
+
+	if (!fdt_getprop(blob, off, "linux,serial", NULL))  {
+		ret = fdt_setprop_u64(blob, off, "linux,serial", serial);
+		if (ret < 0)
+			return -1;
+	}
+
+	if (!fdt_getprop(blob, off, "linux,revision", NULL))  {
+		ret = fdt_setprop_u32(blob, off, "linux,revision", revision);
+		if (ret < 0)
+			return -1;
+	}
+
+	return 0;
+}
+
 int ft_board_setup(void *blob, bd_t *bd)
 {
 	/*
@@ -484,6 +513,8 @@ int ft_board_setup(void *blob, bd_t *bd)
 	 */
 	lcd_dt_simplefb_add_node(blob);
 
+	ft_add_revision_info(blob);
+
 #ifdef CONFIG_EFI_LOADER
 	/* Reserve the spin table */
 	efi_add_memory_map(0, 1, EFI_RESERVED_MEMORY_TYPE, 0);
-- 
2.19.1



More information about the U-Boot mailing list