mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Marco Felsch <m.felsch@pengutronix.de>
To: "Daniel Brát" <danek.brat@gmail.com>
Cc: barebox@lists.infradead.org
Subject: Re: [PATCH 2/5] ARM: rpi: add serial number readout
Date: Wed, 8 Feb 2023 10:17:02 +0100	[thread overview]
Message-ID: <20230208091702.sj4lmnttzv726mep@pengutronix.de> (raw)
In-Reply-To: <20230207010525.2693-3-danek.brat@gmail.com>

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 <danek.brat@gmail.com>
> ---
>  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	other threads:[~2023-02-08  9:20 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-07  1:05 [PATCH 0/5] rpi: platform code improvements Daniel Brát
2023-02-07  1:05 ` [PATCH 1/5] ARM: rpi: rename function getting mac address Daniel Brát
2023-02-07  1:05 ` [PATCH 2/5] ARM: rpi: add serial number readout Daniel Brát
2023-02-08  9:17   ` Marco Felsch [this message]
2023-02-07  1:05 ` [PATCH 3/5] ARM: rpi: rework rpi board init code Daniel Brát
2023-02-08  9:18   ` Marco Felsch
2023-02-07  1:05 ` [PATCH 4/5] ARM: rpi: add machine-id support Daniel Brát
2023-02-07  1:05 ` [PATCH 5/5] ARM: rpi: enable reset source detection in defconfig Daniel Brát

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230208091702.sj4lmnttzv726mep@pengutronix.de \
    --to=m.felsch@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=danek.brat@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox