From: Fabio Estevam <festevam@gmail.com>
To: sbabic@denx.de
Cc: paul.liu@linaro.org, u-boot@lists.denx.de,
Fabio Estevam <festevam@denx.de>
Subject: [PATCH v2 4/5] imx8mm-cl-iot-gate: Retrieve the serial number from EEPROM
Date: Tue, 12 Apr 2022 13:05:38 -0300 [thread overview]
Message-ID: <20220412160539.3249234-4-festevam@gmail.com> (raw)
In-Reply-To: <20220412160539.3249234-1-festevam@gmail.com>
From: Fabio Estevam <festevam@denx.de>
The serial number is located at offset 0x14 of the EEPROM
under i2c0 bus at address 0x54.
To print the serial number in Linux:
SERNUM=$(cat /proc/device-tree/serial-number)
echo $SERNUM
Signed-off-by: Fabio Estevam <festevam@denx.de>
---
Changes since v1:
- None
.../imx8mm-cl-iot-gate/imx8mm-cl-iot-gate.c | 50 +++++++++++++++++++
1 file changed, 50 insertions(+)
diff --git a/board/compulab/imx8mm-cl-iot-gate/imx8mm-cl-iot-gate.c b/board/compulab/imx8mm-cl-iot-gate/imx8mm-cl-iot-gate.c
index 779b64b140ad..27200f728efe 100644
--- a/board/compulab/imx8mm-cl-iot-gate/imx8mm-cl-iot-gate.c
+++ b/board/compulab/imx8mm-cl-iot-gate/imx8mm-cl-iot-gate.c
@@ -463,6 +463,52 @@ static int setup_mac_address(void)
return 0;
}
+static int read_serial_number(void)
+{
+ unsigned char serialnumber[6];
+ unsigned char reversed[6];
+ char serial_string[12];
+ struct udevice *dev;
+ int ret, off, i;
+
+ off = fdt_path_offset(gd->fdt_blob, "eeprom0");
+ if (off < 0) {
+ printf("No eeprom0 path offset found in DT\n");
+ return off;
+ }
+
+ ret = uclass_get_device_by_of_offset(UCLASS_I2C_EEPROM, off, &dev);
+ if (ret) {
+ printf("%s: Could not find EEPROM\n", __func__);
+ return ret;
+ }
+
+ ret = i2c_set_chip_offset_len(dev, 1);
+ if (ret)
+ return ret;
+
+ ret = i2c_eeprom_read(dev, 0x14, serialnumber, sizeof(serialnumber));
+ if (ret) {
+ printf("%s: Could not read EEPROM\n", __func__);
+ return ret;
+ }
+
+ for (i = sizeof(serialnumber) - 1; i >= 0; i--)
+ reversed[i] = serialnumber[sizeof(serialnumber) - 1 - i];
+
+ for (i = 0; i < sizeof(reversed); i++) {
+ serial_string[i * 2] = (reversed[i] >> 4) & 0xf;
+ serial_string[i * 2 + 1] = reversed[i] & 0xf;
+ }
+
+ for (i = 0; i < sizeof(serial_string); i++)
+ serial_string[i] += '0';
+
+ env_set("serial#", serial_string);
+
+ return 0;
+}
+
int board_late_init(void)
{
int ret;
@@ -476,5 +522,9 @@ int board_late_init(void)
if (ret < 0)
printf("Cannot set MAC address from EEPROM\n");
+ ret = read_serial_number();
+ if (ret < 0)
+ printf("Cannot read serial number from EEPROM\n");
+
return 0;
}
--
2.25.1
next prev parent reply other threads:[~2022-04-12 16:06 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-12 16:05 [PATCH v2 1/5] imx8mm-cl-iot-gate: Add SPL EEPROM support Fabio Estevam
2022-04-12 16:05 ` [PATCH v2 2/5] imx8mm-cl-iot-gate: Retrieve the DDR type from EEPROM Fabio Estevam
2022-04-12 18:44 ` sbabic
2022-04-12 16:05 ` [PATCH v2 3/5] imx8mm-cl-iot-gate: Retrieve the MAC address " Fabio Estevam
2022-04-12 18:42 ` sbabic
2022-04-12 16:05 ` Fabio Estevam [this message]
2022-04-12 18:47 ` [PATCH v2 4/5] imx8mm-cl-iot-gate: Retrieve the serial number " sbabic
2022-04-12 16:05 ` [PATCH v2 5/5] imx8mm-cl-iot-gate: Add redundand environment support Fabio Estevam
2022-04-12 18:47 ` sbabic
2022-04-12 18:42 ` [PATCH v2 1/5] imx8mm-cl-iot-gate: Add SPL EEPROM support sbabic
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=20220412160539.3249234-4-festevam@gmail.com \
--to=festevam@gmail.com \
--cc=festevam@denx.de \
--cc=paul.liu@linaro.org \
--cc=sbabic@denx.de \
--cc=u-boot@lists.denx.de \
/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