Commit 10be5b5d3a8d8dd1aa8be95d339c0fdf498c3687

Authored by Paul Kocialkowski
Committed by Simon Glass
1 parent d8abb46b37

fdt: Pass the device serial number through devicetree

Before device-tree, the device serial number used to be passed to the kernel
using ATAGs (on ARM). This is now deprecated and all the handover to the kernel
should now be done using device-tree. Thus, this passes the serial-number
property to the kernel using the serial-number property of the root node, as
expected by the kernel.

The serial number is a string that somewhat represents the device's serial
number. It might come from some form of storage (e.g. an eeprom) and be
programmed at factory-time by the manufacturer or come from identification
bits available in e.g. the SoC.

Signed-off-by: Paul Kocialkowski <contact@paulk.fr>
Reviewed-by: Simon Glass <sgj@chromium.org>

Showing 4 changed files with 34 additions and 0 deletions Side-by-side Diff

common/fdt_support.c
... ... @@ -194,6 +194,31 @@
194 194 return fdt_setprop_u32(fdt, nodeoffset, name, (uint32_t)val);
195 195 }
196 196  
  197 +int fdt_root(void *fdt)
  198 +{
  199 + char *serial;
  200 + int err;
  201 +
  202 + err = fdt_check_header(fdt);
  203 + if (err < 0) {
  204 + printf("fdt_root: %s\n", fdt_strerror(err));
  205 + return err;
  206 + }
  207 +
  208 + serial = getenv("serial#");
  209 + if (serial) {
  210 + err = fdt_setprop(fdt, 0, "serial-number", serial,
  211 + strlen(serial) + 1);
  212 +
  213 + if (err < 0) {
  214 + printf("WARNING: could not set serial-number %s.\n",
  215 + fdt_strerror(err));
  216 + return err;
  217 + }
  218 + }
  219 +
  220 + return 0;
  221 +}
197 222  
198 223 int fdt_initrd(void *fdt, ulong initrd_start, ulong initrd_end)
199 224 {
... ... @@ -471,6 +471,10 @@
471 471 int ret = -EPERM;
472 472 int fdt_ret;
473 473  
  474 + if (fdt_root(blob) < 0) {
  475 + printf("ERROR: root node setup failed\n");
  476 + goto err;
  477 + }
474 478 if (fdt_chosen(blob) < 0) {
475 479 printf("ERROR: /chosen node create failed\n");
476 480 goto err;
doc/device-tree-bindings/root.txt
  1 +The root node
  2 +
  3 +Optional properties:
  4 + - serial-number : a string representing the device's serial number
include/fdt_support.h
... ... @@ -16,6 +16,7 @@
16 16 const char *prop, const u32 dflt);
17 17 u32 fdt_getprop_u32_default(const void *fdt, const char *path,
18 18 const char *prop, const u32 dflt);
  19 +int fdt_root(void *fdt);
19 20 int fdt_chosen(void *fdt);
20 21 int fdt_initrd(void *fdt, ulong initrd_start, ulong initrd_end);
21 22 void do_fixup_by_path(void *fdt, const char *path, const char *prop,