Hi Daniel,

thanks for the patch.

On 23-02-07, Daniel Brát wrote:
> Remove querying for serial-number node from vc fdt, since it's not
> guaranteed to always be there (older firmwares dont provide it).
> Instead, retrieve board's serial number via the mbox api.

Is this possible for all RPi's out there?

> Signed-off-by: Daniel Brát <[email protected]>
> ---
>  arch/arm/boards/raspberry-pi/lowlevel.h     |  1 +
>  arch/arm/boards/raspberry-pi/mbox-helpers.c | 27 +++++++++++++++++++++
>  arch/arm/boards/raspberry-pi/rpi-common.c   | 21 +++++++++++-----
>  arch/arm/mach-bcm283x/include/mach/mbox.h   | 13 ++++++++++
>  4 files changed, 56 insertions(+), 6 deletions(-)
> 
> diff --git a/arch/arm/boards/raspberry-pi/lowlevel.h 
> b/arch/arm/boards/raspberry-pi/lowlevel.h
> index 260f96c714..d2699b9b08 100644
> --- a/arch/arm/boards/raspberry-pi/lowlevel.h
> +++ b/arch/arm/boards/raspberry-pi/lowlevel.h
> @@ -12,5 +12,6 @@
>  ssize_t rpi_get_arm_mem(void);
>  int rpi_get_ethaddr(u8 mac[6]);
>  int rpi_get_board_rev(void);
> +int rpi_get_board_serial(u64 *serial);
>  
>  #endif /* __ARCH_ARM_BOARDS_LOWLEVEL_H__ */
> diff --git a/arch/arm/boards/raspberry-pi/mbox-helpers.c 
> b/arch/arm/boards/raspberry-pi/mbox-helpers.c
> index 50fc1c5b45..62c65d1267 100644
> --- a/arch/arm/boards/raspberry-pi/mbox-helpers.c
> +++ b/arch/arm/boards/raspberry-pi/mbox-helpers.c
> @@ -16,6 +16,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;
> @@ -71,3 +77,24 @@ int rpi_get_board_rev(void)
>  
>       return msg->get_board_rev.body.resp.rev;
>  }
> +
> +int rpi_get_board_serial(u64 *serial)
> +{
> +     int ret;
> +
> +     BCM2835_MBOX_STACK_ALIGN(struct msg_get_board_serial, msg);
> +     BCM2835_MBOX_INIT_HDR(msg);
> +     BCM2835_MBOX_INIT_TAG(&msg->get_board_serial, GET_BOARD_SERIAL);
> +
> +     if (!serial)
> +             return -EINVAL;
> +
> +     ret = bcm2835_mbox_call_prop(BCM2835_MBOX_PROP_CHAN, &msg->hdr);
> +     if (ret) {
> +             pr_err("Could not query board serial\n");
> +             return ret;
> +     }
> +
> +     *serial = msg->get_board_serial.body.resp.serial;
> +     return 0;
> +}
> diff --git a/arch/arm/boards/raspberry-pi/rpi-common.c 
> b/arch/arm/boards/raspberry-pi/rpi-common.c
> index 8d1e74acab..a8f180ae92 100644
> --- a/arch/arm/boards/raspberry-pi/rpi-common.c
> +++ b/arch/arm/boards/raspberry-pi/rpi-common.c
> @@ -60,6 +60,19 @@ struct rpi_priv {
>       const char *name;
>  };
>  
> +static void rpi_set_serial_number(void)
> +{
> +     u64 serial;
> +     char *serial_str;
> +
> +     if (rpi_get_board_serial(&serial))
> +             return;
> +
> +     serial_str = basprintf("%016llx", serial);
> +     barebox_set_serial_number(serial_str);
> +     free(serial_str);
> +}
> +
>  static void rpi_set_ethaddr(void)
>  {
>       u8 mac[ETH_ALEN];
> @@ -265,12 +278,6 @@ static void rpi_vc_fdt_parse(void *fdt)
>       if (IS_ERR(root))
>               return;
>  
> -     str = of_read_vc_string(root, "serial-number");
> -     if (str) {
> -             barebox_set_serial_number(str);
> -             free(str);
> -     }
> -
>       str = of_read_vc_string(root, "model");
>       if (str) {
>               barebox_set_model(str);
> @@ -446,6 +453,8 @@ static int rpi_devices_probe(struct device *dev)
>       if (IS_ERR(dcfg))
>               goto free_priv;
>  
> +     rpi_set_serial_number();
> +
>       /* construct short recognizable host name */
>       name = of_device_get_match_compatible(priv->dev);
>       ptr = strchr(name, ',');
> diff --git a/arch/arm/mach-bcm283x/include/mach/mbox.h 
> b/arch/arm/mach-bcm283x/include/mach/mbox.h
> index 92cadba62c..008ea2e614 100644
> --- a/arch/arm/mach-bcm283x/include/mach/mbox.h
> +++ b/arch/arm/mach-bcm283x/include/mach/mbox.h
> @@ -201,6 +201,19 @@ 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 {
> +             } req;
> +             struct __packed {
> +                     u64 serial;
> +             } resp;

Why do we need the __packed here?

Regards,
  Marco

> +     } body;
> +};
> +
>  #define BCM2835_MBOX_TAG_GET_ARM_MEMORY              0x00010005
>  
>  struct bcm2835_mbox_tag_get_arm_mem {
> -- 
> 2.34.1
> 
> 
> 

Reply via email to