Skip to contentSkip to conversation

raspi: fixup additional vc created nodes

PATCH Superseded Denis Osterland-Heim 3 participants 5 messages Aug 2, 2023 – Sep 12, 2023 1 message not in the archive Arm (32-bit)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

PATCH 1/2 raspi: support to read vc values via dt-2nd boot

From: Denis OSTERLAND-HEIM <[email protected]>

In case of boot via dt-2nd pbl does not copy dtb, because it is not executed. With this patch the values were read and registered as fix-ups. It also adds a inif function that only fix-ups the ethernet MAC address.

---
 arch/arm/boards/raspberry-pi/rpi-common.c | 32 ++++++++++++++---------

 1 file changed, 20 insertions(+), 12 deletions(-)
(quoted diff) +0 -0

b/arch/arm/boards/raspberry-pi/rpi-common.c
index 56e7eebd61..2f525e7d70 100644

arch/arm/boards/raspberry-pi/rpi-common.c +0 -0
@@ -110,6 +110,12 @@ static void rpi_add_led(void)

                led_set_trigger(LED_TRIGGER_HEARTBEAT, &l->led); }

+static int rpi_eth_init(struct rpi_priv *priv)
+{
+       rpi_set_usbethaddr();
+       return 0;
+}
+
 static int rpi_b_init(struct rpi_priv *priv)
 {
        rpi_leds[0].gpio = 16;
@@ -276,16 +282,12 @@ static u32 rpi_boot_mode, rpi_boot_part;
  * Some parameters are defined here:
  *
https://www.raspberrypi.com/documentation/computers/configuration.html#part4
  */
-static void rpi_vc_fdt_parse(void *fdt)
+static void rpi_vc_fdt_parse(struct device_node *root)
 {
        int ret;
-       struct device_node *root, *chosen, *bootloader, *memory; +       struct device_node *chosen, *bootloader, *memory; char *str;

-       root = of_unflatten_dtb(fdt, INT_MAX);
-       if (IS_ERR(root))
-               return;
-
        str = of_read_vc_string(root, "serial-number");
        if (str) {
                barebox_set_serial_number(str);
@@ -363,7 +365,7 @@ static void rpi_vc_fdt_parse(void *fdt) return;
 }

-static void rpi_vc_fdt(void)
+static struct device_node *rpi_vc_fdt(void)
 {
        void *saved_vc_fdt;
        struct fdt_header *oftree;
@@ -379,17 +381,17 @@ static void rpi_vc_fdt(void)
                if (oftree->totalsize)
                        pr_err("there was an error copying fdt in pbl:
%d\n",
                                        be32_to_cpu(oftree-

Quoted 1 line

totalsize));

-               return;
+               return ERR_PTR(-EINVAL);
        }

        if (magic != FDT_MAGIC)
-               return;
+               return ERR_PTR(-EINVAL);

        size = be32_to_cpu(oftree->totalsize);
        if (write_file("/vc.dtb", saved_vc_fdt, size)) pr_err("failed to save videocore fdt to a file\n"); -
-       rpi_vc_fdt_parse(saved_vc_fdt);
+
+       return of_unflatten_dtb(saved_vc_fdt, INT_MAX);
 }

 static void rpi_set_kernel_name(void) {
@@ -452,6 +454,7 @@ static int rpi_devices_probe(struct device *dev) const struct rpi_machine_data *dcfg;
        struct regulator *reg;
        struct rpi_priv *priv;
+       struct device_node *root;
        const char *name, *ptr;
        char *hostname;
        int ret;
@@ -480,7 +483,8 @@ static int rpi_devices_probe(struct device *dev) bcm2835_register_fb(); armlinux_set_architecture(MACH_TYPE_BCM2708); rpi_env_init();
-       rpi_vc_fdt();
+       root = rpi_vc_fdt();
+       rpi_vc_fdt_parse(IS_ERR(root) ? priv->dev->device_node : root); rpi_set_kernel_name();

        if (dcfg && dcfg->init)
@@ -599,6 +603,7 @@ static const struct rpi_machine_data rpi_3_ids[] = {
                .init = rpi_b_plus_init,
        }, {
                .hw_id = BCM2837_BOARD_REV_CM3,
+               .init = rpi_eth_init,
        }, {
                .hw_id = BCM2837B0_BOARD_REV_CM3_PLUS,
        }, {
@@ -611,10 +616,13 @@ static const struct rpi_machine_data rpi_3_ids[] = {
 static const struct rpi_machine_data rpi_4_ids[] = {
        {
                .hw_id = BCM2711_BOARD_REV_4_B,
+               .init = rpi_eth_init,
        }, {
                .hw_id = BCM2711_BOARD_REV_400,
+               .init = rpi_eth_init,
        }, {
                .hw_id = BCM2711_BOARD_REV_CM4,
+               .init = rpi_eth_init,
        }, {
                .hw_id = U8_MAX
        },

Signature · 1 line
2.39.3
Acked-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] raspi: support to read vc values via dt-2nd boot

Quoted 8 lines · Denis Osterland-Heim

From: Denis OSTERLAND-HEIM <[email protected]>

In case of boot via dt-2nd pbl does not copy dtb, because it is not executed. With this patch the values were read and registered as fix-ups. It also adds a inif function that only fix-ups the ethernet MAC address.

Quoted 117 lines

---
 arch/arm/boards/raspberry-pi/rpi-common.c | 32 ++++++++++++++---------

 1 file changed, 20 insertions(+), 12 deletions(-)
arch/arm/boards/raspberry-pi/rpi-common.c +0 -0
index 56e7eebd61..2f525e7d70 100644
@@ -110,6 +110,12 @@ static void rpi_add_led(void)
                 led_set_trigger(LED_TRIGGER_HEARTBEAT, &l->led);
  }

arch/arm/boards/raspberry-pi/rpi-common.c +6 -0
+static int rpi_eth_init(struct rpi_priv *priv)
+{
+       rpi_set_usbethaddr();
+       return 0;
+}
+

 static int rpi_b_init(struct rpi_priv *priv)
 {
        rpi_leds[0].gpio = 16;

arch/arm/boards/raspberry-pi/rpi-common.c +0 -0
@@ -276,16 +282,12 @@ static u32 rpi_boot_mode, rpi_boot_part;
   * Some parameters are defined here:
   *

https://www.raspberrypi.com/documentation/computers/configuration.html#part4
  */

arch/arm/boards/raspberry-pi/rpi-common.c +1 -1
-static void rpi_vc_fdt_parse(void *fdt)
+static void rpi_vc_fdt_parse(struct device_node *root)

 {
        int ret;
-       struct device_node *root, *chosen, *bootloader, *memory; +       struct device_node *chosen, *bootloader, *memory; char *str;

-       root = of_unflatten_dtb(fdt, INT_MAX);
-       if (IS_ERR(root))
-               return;
-
        str = of_read_vc_string(root, "serial-number"); if (str) {
                barebox_set_serial_number(str);

arch/arm/boards/raspberry-pi/rpi-common.c +0 -0
@@ -363,7 +365,7 @@ static void rpi_vc_fdt_parse(void *fdt)
         return;
  }

arch/arm/boards/raspberry-pi/rpi-common.c +1 -1
-static void rpi_vc_fdt(void)
+static struct device_node *rpi_vc_fdt(void)

 {
        void *saved_vc_fdt;
        struct fdt_header *oftree;

arch/arm/boards/raspberry-pi/rpi-common.c +0 -0
@@ -379,17 +381,17 @@ static void rpi_vc_fdt(void)
                 if (oftree->totalsize)

                        pr_err("there was an error copying fdt in pbl:
%d\n",
                                        be32_to_cpu(oftree-

Quoted 1 line

totalsize));

-               return;
+               return ERR_PTR(-EINVAL);
        }

        if (magic != FDT_MAGIC)
-               return;
+               return ERR_PTR(-EINVAL);

        size = be32_to_cpu(oftree->totalsize);
        if (write_file("/vc.dtb", saved_vc_fdt, size)) pr_err("failed to save videocore fdt to a file\n"); -
-       rpi_vc_fdt_parse(saved_vc_fdt);
+
+       return of_unflatten_dtb(saved_vc_fdt, INT_MAX); }

 static void rpi_set_kernel_name(void) {

arch/arm/boards/raspberry-pi/rpi-common.c +3 -1
@@ -452,6 +454,7 @@ static int rpi_devices_probe(struct device *dev)
         const struct rpi_machine_data *dcfg;
         struct regulator *reg;
         struct rpi_priv *priv;
+       struct device_node *root;
         const char *name, *ptr;
         char *hostname;
         int ret;
@@ -480,7 +483,8 @@ static int rpi_devices_probe(struct device *dev)
         bcm2835_register_fb();
         armlinux_set_architecture(MACH_TYPE_BCM2708);
         rpi_env_init();
-       rpi_vc_fdt();
+       root = rpi_vc_fdt();
+       rpi_vc_fdt_parse(IS_ERR(root) ? priv->dev->device_node : root);
         rpi_set_kernel_name();


        if (dcfg && dcfg->init)

arch/arm/boards/raspberry-pi/rpi-common.c +1 -0
@@ -599,6 +603,7 @@ static const struct rpi_machine_data rpi_3_ids[] =
 {
                 .init = rpi_b_plus_init,
         }, {
                 .hw_id = BCM2837_BOARD_REV_CM3,
+               .init = rpi_eth_init,
         }, {
                 .hw_id = BCM2837B0_BOARD_REV_CM3_PLUS,

        }, {

arch/arm/boards/raspberry-pi/rpi-common.c +3 -0
@@ -611,10 +616,13 @@ static const struct rpi_machine_data rpi_3_ids[]
 = {
  static const struct rpi_machine_data rpi_4_ids[] = {
         {
                 .hw_id = BCM2711_BOARD_REV_4_B,
+               .init = rpi_eth_init,
         }, {
                 .hw_id = BCM2711_BOARD_REV_400,
+               .init = rpi_eth_init,
         }, {
                 .hw_id = BCM2711_BOARD_REV_CM4,
+               .init = rpi_eth_init,
         }, {

                .hw_id = U8_MAX
        },

Signature · 4 lines
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |
#3 lore raw

Re: [PATCH 1/2] raspi: support to read vc values via dt-2nd boot

In reply to Denis Osterland-Heim

Hi Denis,

Quoted 11 lines · Denis Osterland-Heim

From: Denis OSTERLAND-HEIM <[email protected]>

In case of boot via dt-2nd pbl does not copy dtb, because it is not executed. With this patch the values were read and registered as fix-ups. It also adds a inif function that only fix-ups the ethernet MAC address.

---
 arch/arm/boards/raspberry-pi/rpi-common.c | 32 ++++++++++++++---------

 1 file changed, 20 insertions(+), 12 deletions(-)

Sorry for not handling this earlier. I always forgot to trigger Ahmad to have a look at this patch. Now I did and he looked at it, but I can't apply as whitespaces are mangled.

Please resend with proper formatting.

Sascha

Signature · 4 lines
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |
#4 lore raw

PATCH 2/2 raspi: fixup additional vc created nodes

In reply to a message not in the archive

From: Denis OSTERLAND-HEIM <[email protected]>

The video core creates some additional nodes.
This code takes over this values.
The /hat node is only there if an raspi hat with EEPROM is detected.

---
 arch/arm/boards/raspberry-pi/rpi-common.c | 38 +++++++++++++++++------

 1 file changed, 29 insertions(+), 9 deletions(-)
(quoted diff) +0 -0

b/arch/arm/boards/raspberry-pi/rpi-common.c
index 2f525e7d70..9c85c85d14 100644

arch/arm/boards/raspberry-pi/rpi-common.c +0 -0
@@ -264,19 +264,36 @@ static enum reset_src_type

rpi_decode_pm_rsts(struct device_node *chosen,

 static int rpi_vc_fdt_fixup(struct device_node *root, void *data) {
-       const struct device_node *vc_chosen = data;
-       struct device_node *chosen;
+       const struct device_node *vc_node = data;
+       struct device_node *node;
+       struct property *pp;

-       chosen = of_create_node(root, "/chosen");
-       if (!chosen)
+       node = of_create_node(root, vc_node->full_name);
+       if (!node)
                return -ENOMEM;

-       of_copy_property(vc_chosen, "overlay_prefix", chosen); -       of_copy_property(vc_chosen, "os_prefix", chosen);
+       for_each_property_of_node(vc_node, pp)
+               of_copy_property(vc_node, pp->name, node);

        return 0;
 }

+static struct device_node *register_vc_fixup(struct device_node *root, const char *path)
+{
+       struct device_node *ret, *tmp;
+
+       ret = of_find_node_by_path_from(root, path);
+       if (ret) {
+               tmp = of_dup(ret);
+               tmp->full_name = xstrdup(ret->full_name);
+               of_register_fixup(rpi_vc_fdt_fixup, tmp);
+       } else {
+               pr_info("no '%s' node found in vc fdt\n", path); +       }
+
+       return ret;
+}
+
 static u32 rpi_boot_mode, rpi_boot_part;
 /* Extract useful information from the VideoCore FDT we got.
  * Some parameters are defined here:
@@ -300,14 +317,17 @@ static void rpi_vc_fdt_parse(struct device_node *root)
                free(str);
        }

-       chosen = of_find_node_by_path_from(root, "/chosen"); +       register_vc_fixup(root, "/system");
+       register_vc_fixup(root, "/axi");
+       register_vc_fixup(root, "/reserved-memory");
+       register_vc_fixup(root, "/hat");
+       register_vc_fixup(root, "/chosen/bootloader");
+       chosen = register_vc_fixup(root, "/chosen");
        if (!chosen) {
                pr_err("no '/chosen' node found in vc fdt\n"); goto out;
        }

-       of_register_fixup(rpi_vc_fdt_fixup, of_dup(chosen)); -
        bootloader = of_find_node_by_name(chosen, "bootloader");
        str = of_read_vc_string(chosen, "bootargs");

Signature · 1 line
2.39.3
Acked-by on v1 2/2
#5 lore raw
Quoted 7 lines · Denis Osterland-Heim

From: Denis OSTERLAND-HEIM <[email protected]>

The video core creates some additional nodes.
This code takes over this values.
The /hat node is only there if an raspi hat with EEPROM is detected.

Quoted 76 lines

---
 arch/arm/boards/raspberry-pi/rpi-common.c | 38 +++++++++++++++++------

 1 file changed, 29 insertions(+), 9 deletions(-)
arch/arm/boards/raspberry-pi/rpi-common.c +0 -0
index 2f525e7d70..9c85c85d14 100644
@@ -264,19 +264,36 @@ static enum reset_src_type
 rpi_decode_pm_rsts(struct device_node *chosen,


 static int rpi_vc_fdt_fixup(struct device_node *root, void *data) {
-       const struct device_node *vc_chosen = data;
-       struct device_node *chosen;
+       const struct device_node *vc_node = data;
+       struct device_node *node;
+       struct property *pp;

-       chosen = of_create_node(root, "/chosen");
-       if (!chosen)
+       node = of_create_node(root, vc_node->full_name);
+       if (!node)
                return -ENOMEM;

-       of_copy_property(vc_chosen, "overlay_prefix", chosen); -       of_copy_property(vc_chosen, "os_prefix", chosen);
+       for_each_property_of_node(vc_node, pp)
+               of_copy_property(vc_node, pp->name, node);

        return 0;
 }

+static struct device_node *register_vc_fixup(struct device_node *root, const char *path)

arch/arm/boards/raspberry-pi/rpi-common.c +15 -0
+{
+       struct device_node *ret, *tmp;
+
+       ret = of_find_node_by_path_from(root, path);
+       if (ret) {
+               tmp = of_dup(ret);
+               tmp->full_name = xstrdup(ret->full_name);
+               of_register_fixup(rpi_vc_fdt_fixup, tmp);
+       } else {
+               pr_info("no '%s' node found in vc fdt\n", path);
+       }
+
+       return ret;
+}
+

 static u32 rpi_boot_mode, rpi_boot_part;
 /* Extract useful information from the VideoCore FDT we got.
  * Some parameters are defined here:

arch/arm/boards/raspberry-pi/rpi-common.c +0 -0
@@ -300,14 +317,17 @@ static void rpi_vc_fdt_parse(struct device_node
 *root)
                 free(str);
         }


-       chosen = of_find_node_by_path_from(root, "/chosen"); +       register_vc_fixup(root, "/system");
+       register_vc_fixup(root, "/axi");
+       register_vc_fixup(root, "/reserved-memory");
+       register_vc_fixup(root, "/hat");
+       register_vc_fixup(root, "/chosen/bootloader"); +       chosen = register_vc_fixup(root, "/chosen"); if (!chosen) {
                pr_err("no '/chosen' node found in vc fdt\n"); goto out;
        }

-       of_register_fixup(rpi_vc_fdt_fixup, of_dup(chosen)); -
        bootloader = of_find_node_by_name(chosen, "bootloader");
        str = of_read_vc_string(chosen, "bootargs");

Signature · 4 lines
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |