Fix package license to Apache-2.0
[AGL/meta-agl.git] / meta-agl-bsp / meta-raspberrypi / recipes-bsp / u-boot / files / 0001-board-raspberrypi-add-serial-and-revision-to-the-dev-2019.07.patch
1 From 86cc911aaa958fedf2ea9cb04b4af17f5357815d Mon Sep 17 00:00:00 2001
2 From: Anton Gerasimov <anton.gerasimov@here.com>
3 Date: Fri, 1 Feb 2019 14:39:48 +0100
4 Subject: [PATCH] board: raspberrypi: add serial and revision to the device
5  tree
6
7 Raspberry Pi bootloader adds this node to fdt, but if u-boot script
8 doesn't reuse the tree provided by it, this information is lost.
9
10 Revision and serial are displayed in /proc/cpuinfo after boot.
11
12 Signed-off-by: Anton Gerasimov <anton.gerasimov@here.com>
13 ---
14  board/raspberrypi/rpi/rpi.c | 31 +++++++++++++++++++++++++++++--
15  1 file changed, 29 insertions(+), 2 deletions(-)
16
17 diff --git a/board/raspberrypi/rpi/rpi.c b/board/raspberrypi/rpi/rpi.c
18 index 35f5939552..114178397e 100644
19 --- a/board/raspberrypi/rpi/rpi.c
20 +++ b/board/raspberrypi/rpi/rpi.c
21 @@ -241,6 +241,8 @@ static uint32_t rev_scheme;
22  static uint32_t rev_type;
23  static const struct rpi_model *model;
24  
25 +uint64_t serial;
26 +
27  #ifdef CONFIG_ARM64
28  static struct mm_region bcm2837_mem_map[] = {
29         {
30 @@ -384,8 +386,8 @@ static void set_serial_number(void)
31                 return;
32         }
33  
34 -       snprintf(serial_string, sizeof(serial_string), "%016llx",
35 -                msg->get_board_serial.body.resp.serial);
36 +       serial = msg->get_board_serial.body.resp.serial;
37 +       snprintf(serial_string, sizeof(serial_string), "%016llx", serial);
38         env_set("serial#", serial_string);
39  }
40  
41 @@ -478,6 +480,29 @@ void *board_fdt_blob_setup(void)
42         return (void *)fw_dtb_pointer;
43  }
44  
45 +static int ft_add_revision_info(void *blob) {
46 +       int off;
47 +       int ret;
48 +
49 +       off = fdt_subnode_offset(blob, 0, "system");
50 +
51 +       if (off < 0) {
52 +               off = fdt_add_subnode(blob, 0, "system");
53 +               if (off < 0)
54 +                       return -1;
55 +       }
56 +
57 +       ret = fdt_setprop_u64(blob, off, "linux,serial", serial);
58 +       if (ret < 0)
59 +               return -1;
60 +
61 +       ret = fdt_setprop_u32(blob, off, "linux,revision", revision);
62 +       if (ret < 0)
63 +               return -1;
64 +
65 +       return 0;
66 +}
67 +
68  int ft_board_setup(void *blob, bd_t *bd)
69  {
70         /*
71 @@ -487,6 +512,8 @@ int ft_board_setup(void *blob, bd_t *bd)
72          */
73         lcd_dt_simplefb_add_node(blob);
74  
75 +       ft_add_revision_info(blob);
76 +
77  #ifdef CONFIG_EFI_LOADER
78         /* Reserve the spin table */
79         efi_add_memory_map(0, 1, EFI_RESERVED_MEMORY_TYPE, 0);
80 -- 
81 2.17.1
82