PHYTEC SOM Detection API v3
cover PHYTEC SOM Detection API v3
This patch series adds support for the EEPROM v3 API.
V3 is backwards compatible to V2 and therefore, the V2 image still exists at the beginning. Only the API version changed from 2 to 3.
V3 is a block-based memory layout organized as singled-linked list with different types of blocks. This is a more flexible approach and allows us to extend it by more block types in the future.
The V3 data starts with a 8-byte large header which defines the block count (u8), V3 subversion (u8) and data payload length (u16). Additionally the header contains a CRC8 checksum a 3 reserved bytes.
Each block starts with a 4-byte large header which defined the block type (u8), the absolute address of the next block (u16) and a CRC8 checksum. The content itself is defined via the block type and we currently have 2 different types:
1) MAC: Contains the Ethernet interface number (u8), MAC address (6 x u8) and a CRC8 checksum.
Daniel Schultz (6):
board: phytec: common: Move eeprom read to new function
board: phytec: common: Define PHYTEC_API2_DATA_LEN
board: phytec: common: Move API v2 init to new function
board: phytec: common: Add API v3
board: phytec: common: k3: Set MAC
configs: phycore_am62x_a53_defconfig: Enable CONFIG_ENV_OVERWRITE
board/phytec/common/Kconfig | 9 + board/phytec/common/Makefile | 2 +- board/phytec/common/k3/board.c | 23 ++ board/phytec/common/phytec_som_detection.c | 228 +++++++++++++++--- board/phytec/common/phytec_som_detection.h | 9 + .../common/phytec_som_detection_blocks.c | 105 ++++++++ .../common/phytec_som_detection_blocks.h | 61 +++++ configs/phycore_am62x_a53_defconfig | 1 + 8 files changed, 408 insertions(+), 30 deletions(-) create mode 100644 board/phytec/common/phytec_som_detection_blocks.c create mode 100644 board/phytec/common/phytec_som_detection_blocks.h
Signature · 1 line
2.25.1
Am 22.05.24 um 08:18 schrieb Daniel Schultz:
Quoted 13 lines
This patch series adds support for the EEPROM v3 API.
V3 is backwards compatible to V2 and therefore, the V2 image still exists at the beginning. Only the API version changed from 2 to 3.
V3 is a block-based memory layout organized as singled-linked list with different types of blocks. This is a more flexible approach and allows us to extend it by more block types in the future.
The V3 data starts with a 8-byte large header which defines the block count (u8), V3 subversion (u8) and data payload length (u16). Additionally the header contains a CRC8 checksum a 3 reserved bytes.
Quoted 7 lines
Each block starts with a 4-byte large header which defined the block type (u8), the absolute address of the next block (u16) and a CRC8 checksum. The content itself is defined via the block type and we currently have 2 different types:
1) MAC: Contains the Ethernet interface number (u8), MAC address (6 x u8) and a CRC8 checksum.
For this series,
PATCH 1/6 board: phytec: common: Move eeprom read to new function
In reply to Daniel SchultzWe need to read multiple times from different offsets in API v3. Move the EEPROM read logic into a dedicated function to make it usable multiple times.
--- board/phytec/common/phytec_som_detection.c | 38 ++++++++++++++-------- 1 file changed, 24 insertions(+), 14 deletions(-)
board/phytec/common/phytec_som_detection.c +24 -14
@@ -47,16 +47,9 @@ int phytec_eeprom_data_setup(struct phytec_eeprom_data *data,return ret; } -int phytec_eeprom_data_init (struct phytec_eeprom_data *data, -int bus_num,int addr) +int phytec_eeprom_read (u8 *data,int bus_num,int addr,int size,int offset) { -int ret, i; -unsigned int crc; -u8 *ptr; -const unsigned int payload_size =sizeof (struct phytec_eeprom_payload ); - -if (!data) - data = &eeprom_data; +int ret;#if CONFIG_IS_ENABLED (DM_I2C )struct udevice *dev;
@@ -64,19 +57,36 @@ int phytec_eeprom_data_init(struct phytec_eeprom_data *data, ret =i2c_get_chip_for_busnum (bus_num, addr,2 , &dev);if (ret) {pr_err ("%s: i2c EEPROM not found: %i.\n" , __func__, ret); - goto err; +return ret; } - ret =dm_i2c_read (dev,0 , (uint8_t *)data, payload_size); + ret =dm_i2c_read (dev, offset, (uint8_t *)data, size);if (ret) {pr_err ("%s: Unable to read EEPROM data: %i\n" , __func__, ret); - goto err; +return ret; }#else i2c_set_bus_num (bus_num); - ret =i2c_read (addr,0 ,2 , (uint8_t *)data, -sizeof (struct phytec_eeprom_data )); + ret =i2c_read (addr, offset,2 , (uint8_t *)data, size);#endif +return ret; +} + +int phytec_eeprom_data_init (struct phytec_eeprom_data *data, +int bus_num,int addr) +{ +int ret, i; +unsigned int crc; +u8 *ptr; +const unsigned int payload_size =sizeof (struct phytec_eeprom_payload ); + +if (!data) + data = &eeprom_data; + + ret =phytec_eeprom_read ((u8 *)data, bus_num, addr, + payload_size,0 ); +if (ret) + goto err;if (data->payload.api_rev ==0xff ) {pr_err ("%s: EEPROM is not flashed. Prototype?\n" , __func__);
Signature · 1 line
2.25.1
PATCH 2/6 board: phytec: common: Define PHYTEC_API2_DATA_LEN
In reply to Daniel SchultzThe EEPROM image length for API v2 is fixed to 32 bytes. No need to use sizeof while this value won't change. This value is also be required for API v3 to know where the API v3 header starts.
--- board/phytec/common/phytec_som_detection.c | 9 ++++----- board/phytec/common/phytec_som_detection.h | 2 ++ 2 files changed, 6 insertions(+), 5 deletions(-)
board/phytec/common/phytec_som_detection.c +4 -5
@@ -78,13 +78,12 @@ int phytec_eeprom_data_init(struct phytec_eeprom_data *data,int ret, i;unsigned int crc;u8 *ptr; -const unsigned int payload_size =sizeof (struct phytec_eeprom_payload );if (!data) data = &eeprom_data; ret =phytec_eeprom_read ((u8 *)data, bus_num, addr, - payload_size,0 ); +PHYTEC_API2_DATA_LEN ,0 );if (ret) goto err;
@@ -95,11 +94,11 @@ int phytec_eeprom_data_init(struct phytec_eeprom_data *data, } ptr = (u8 *)data; -for (i =0 ; i < payload_size; ++i) +for (i =0 ; i <PHYTEC_API2_DATA_LEN ; ++i)if (ptr[i] !=0x0 )break ; -if (i == payload_size) { +if (i ==PHYTEC_API2_DATA_LEN ) {pr_err ("%s: EEPROM data is all zero. Erased?\n" , __func__); ret = -EINVAL ; goto err;
@@ -111,7 +110,7 @@ int phytec_eeprom_data_init(struct phytec_eeprom_data *data,return 0 ; } - crc =crc8 (0 , (const unsigned char *)&data->payload, payload_size); + crc =crc8 (0 , (const unsigned char *)&data->payload,PHYTEC_API2_DATA_LEN );debug ("%s: crc: %x\n" , __func__, crc);if (crc) {
board/phytec/common/phytec_som_detection.h +2 -0
@@ -10,6 +10,8 @@#define PHYTEC_MAX_OPTIONS 17#define PHYTEC_EEPROM_INVAL 0xff +#define PHYTEC_API2_DATA_LEN 32 +#define PHYTEC_GET_OPTION (option) \ (((option) > '9') ? (option) - 'A' + 10 : (option) - '0')
Signature · 1 line
2.25.1
PATCH 3/6 board: phytec: common: Move API v2 init to new function
In reply to Daniel SchultzMove the entire initialization code for API v2 into a dedicated function. This rework will allow to easily integrate the API v3 as next step during init.
--- board/phytec/common/phytec_som_detection.c | 38 +++++++++++++--------- 1 file changed, 23 insertions(+), 15 deletions(-)
board/phytec/common/phytec_som_detection.c +23 -15
@@ -72,11 +72,29 @@ int phytec_eeprom_read(u8 *data, int bus_num, int addr, int size, int offset)return ret; } +int phytec_eeprom_data_init_v2 (struct phytec_eeprom_data *data) +{ +unsigned int crc; + +if (!data) +return -1 ; + + crc =crc8 (0 , (const unsigned char *)&data->payload,PHYTEC_API2_DATA_LEN ); +debug ("%s: crc: %x\n" , __func__, crc); + +if (crc) { +pr_err ("%s: CRC mismatch. EEPROM data is not usable.\n" , + __func__); +return -EINVAL ; + } + +return 0 ; +} +int phytec_eeprom_data_init (struct phytec_eeprom_data *data,int bus_num,int addr) {int ret, i; -unsigned int crc;u8 *ptr;if (!data)
@@ -104,20 +122,10 @@ int phytec_eeprom_data_init(struct phytec_eeprom_data *data, goto err; } -/* We are done here for early revisions */ -if (data->payload.api_rev <=PHYTEC_API_REV1 ) { - data->valid = true; -return 0 ; - } - - crc =crc8 (0 , (const unsigned char *)&data->payload,PHYTEC_API2_DATA_LEN ); -debug ("%s: crc: %x\n" , __func__, crc); - -if (crc) { -pr_err ("%s: CRC mismatch. EEPROM data is not usable.\n" , - __func__); - ret = -EINVAL ; - goto err; +if (data->payload.api_rev >=PHYTEC_API_REV2 ) { + ret =phytec_eeprom_data_init_v2 (data); +if (ret) + goto err; } data->valid = true;
Signature · 1 line
2.25.1
PATCH 4/6 board: phytec: common: Add API v3
In reply to Daniel SchultzThis API is based on a block structure with a 8 Byte large API v3 header and various of different blocks following. It extends our current API v2, which is always 32 Byte large, and is located directly after v2.
Add the MAC block as first block type. It contains the physical Ehternet interface number, a MAC address and a CRC checksum over the MAC payload.
--- board/phytec/common/Kconfig | 9 ++ board/phytec/common/Makefile | 2 +- board/phytec/common/phytec_som_detection.c | 153 ++++++++++++++++++ board/phytec/common/phytec_som_detection.h | 7 + .../common/phytec_som_detection_blocks.c | 105 ++++++++++++ .../common/phytec_som_detection_blocks.h | 61 +++++++ 6 files changed, 336 insertions(+), 1 deletion(-) create mode 100644 board/phytec/common/phytec_som_detection_blocks.c create mode 100644 board/phytec/common/phytec_som_detection_blocks.h
board/phytec/common/Kconfig +9 -0
@@ -4,6 +4,13 @@ config PHYTEC_SOM_DETECTION help Support of I2C EEPROM based SoM detection. +config PHYTEC_SOM_DETECTION_BLOCKS + bool "Extend SoM detection with block support" + depends on PHYTEC_SOM_DETECTION + help + Extend the I2C EEPROM based SoM detection with API v3. This API + introduces blocks with different payloads. + config PHYTEC_IMX8M_SOM_DETECTION bool "Support SoM detection for i.MX8M PHYTEC platforms" depends on ARCH_IMX8M && PHYTEC_SOM_DETECTION
@@ -16,6 +23,7 @@ config PHYTEC_AM62_SOM_DETECTION bool "Support SoM detection for AM62x PHYTEC platforms" depends on (TARGET_PHYCORE_AM62X_A53 || TARGET_PHYCORE_AM62X_R5) && \ PHYTEC_SOM_DETECTION + select PHYTEC_SOM_DETECTION_BLOCKS default y help Support of I2C EEPROM based SoM detection. Supported
@@ -25,6 +33,7 @@ config PHYTEC_AM64_SOM_DETECTION bool "Support SoM detection for AM64x PHYTEC platforms" depends on (TARGET_PHYCORE_AM64X_A53 || TARGET_PHYCORE_AM64X_R5) && \ PHYTEC_SOM_DETECTION + select PHYTEC_SOM_DETECTION_BLOCKS default y help Support of I2C EEPROM based SoM detection. Supported
board/phytec/common/Makefile +1 -1
@@ -9,6 +9,6 @@ else obj-$(CONFIG_ARCH_K3) += k3/ endif -obj-y += phytec_som_detection.o +obj-y += phytec_som_detection.o phytec_som_detection_blocks.o obj-$(CONFIG_ARCH_K3) += am6_som_detection.o obj-$(CONFIG_ARCH_IMX8M) += imx8m_som_detection.o
board/phytec/common/phytec_som_detection.c +153 -0
183 lines not on this page · raw message
board/phytec/common/phytec_som_detection.h +7 -0
@@ -7,6 +7,8 @@#ifndef _PHYTEC_SOM_DETECTION_H#define _PHYTEC_SOM_DETECTION_H +#include "phytec_som_detection_blocks.h" +#define PHYTEC_MAX_OPTIONS 17#define PHYTEC_EEPROM_INVAL 0xff
@@ -19,6 +21,7 @@ enum {PHYTEC_API_REV0 =0 ,PHYTEC_API_REV1 ,PHYTEC_API_REV2 , + PHYTEC_API_REV3, }; enum phytec_som_type_str {
@@ -63,6 +66,7 @@ struct phytec_eeprom_payload {struct phytec_api0_data data_api0;struct phytec_api2_data data_api2; } data; +struct phytec_api3_element *block_head; } __packed;struct phytec_eeprom_data {
@@ -88,4 +92,7 @@ struct extension *phytec_add_extension(const char *name, const char *overlay, const char *other);#endif /* IS_ENABLED(CONFIG_CMD_EXTENSION) */ +struct phytec_api3_element * +__maybe_unused phytec_get_block_head (struct phytec_eeprom_data *data); +#endif /* _PHYTEC_SOM_DETECTION_H */
board/phytec/common/phytec_som_detection_blocks.c new file +105 -0
105 lines not on this page · raw message
board/phytec/common/phytec_som_detection_blocks.h new file +61 -0
61 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH 5/6 board: phytec: common: k3: Set MAC
In reply to Daniel SchultzRead the EEPROM API v3 content and set all available MAC-Addresses to the environment.
--- board/phytec/common/k3/board.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+)
board/phytec/common/k3/board.c +23 -0
@@ -8,6 +8,8 @@#include <spl.h> #include <asm/arch/hardware.h> +#include "../am6_som_detection.h" +#if IS_ENABLED (CONFIG_ENV_IS_IN_FAT ) ||IS_ENABLED (CONFIG_ENV_IS_IN_MMC )int mmc_get_env_dev (void ) {
@@ -68,6 +70,27 @@ int board_late_init(void)break ; }; +if (IS_ENABLED (CONFIG_PHYTEC_SOM_DETECTION_BLOCKS )) { +struct phytec_api3_element *block_element; +struct phytec_eeprom_data data; +int ret; + + ret =phytec_eeprom_data_setup (&data,0 ,EEPROM_ADDR ); +if (ret || !data.valid) +return 0 ; + + PHYTEC_API3_FOREACH_BLOCK(block_element, &data) { +switch (block_element->block_type) { +case PHYTEC_API3_BLOCK_MAC : +phytec_blocks_add_mac_to_env (block_element); +break ; +default : +debug ("%s: Unknown block type %i\n" , __func__, + block_element->block_type); + } + } + } +return 0 ; }#endif
Signature · 1 line
2.25.1
Re: [Upstream] [PATCH 5/6] board: phytec: common: k3: Set MAC
Am 22.05.24 um 08:18 schrieb Daniel Schultz:
Quoted 23 lines
Read the EEPROM API v3 content and set all available MAC-Addresses to the environment.
Signed-off-by Daniel Schultz <[email protected]>--- board/phytec/common/k3/board.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+)board/phytec/common/k3/board.c +2
-0@@ -8,6 +8,8 @@#include <spl.h> #include <asm/arch/hardware.h> +#include "../am6_som_detection.h" +#if IS_ENABLED (CONFIG_ENV_IS_IN_FAT ) ||IS_ENABLED (CONFIG_ENV_IS_IN_MMC )int mmc_get_env_dev (void ) {@@ -68,6 +70,27 @@ int board_late_init(void)break ;
board/phytec/common/k3/board.c int board_late_init(void) · line 80
Quoted 10 lines
board/phytec/common/k3/board.c +8
-0}; +if (IS_ENABLED (CONFIG_PHYTEC_SOM_DETECTION_BLOCKS )) { +struct phytec_api3_element *block_element; +struct phytec_eeprom_data data; +int ret; + + ret =phytec_eeprom_data_setup (&data,0 ,EEPROM_ADDR ); +if (ret || !data.valid) +return 0 ;
Don't you want to return an error or at least print a warning?
Apart from that,
Quoted 16 lines
board/phytec/common/k3/board.c +13
-0+ + PHYTEC_API3_FOREACH_BLOCK(block_element, &data) { +switch (block_element->block_type) { +case PHYTEC_API3_BLOCK_MAC : +phytec_blocks_add_mac_to_env (block_element); +break ; +default : +debug ("%s: Unknown block type %i\n" , __func__, + block_element->block_type); + } + } + } +return 0 ; }#endif
PATCH 6/6 configs: phycore_am62x_a53_defconfig: Enable CONFIG_ENV_OVERWRITE
In reply to Daniel SchultzEnable CONFIG_ENV_OVERWRITE to overwrite ethaddr in the environment. This is required because our environment is not located in the boot partition.
--- configs/phycore_am62x_a53_defconfig | 1 + 1 file changed, 1 insertion(+)
configs/phycore_am62x_a53_defconfig +1 -0
@@ -59,6 +59,7 @@ CONFIG_SPL_OF_CONTROL=y CONFIG_MULTI_DTB_FIT=y CONFIG_SPL_MULTI_DTB_FIT=y CONFIG_SPL_MULTI_DTB_FIT_NO_COMPRESSION=y +CONFIG_ENV_OVERWRITE=y CONFIG_ENV_IS_IN_MMC=y CONFIG_SYS_MMC_ENV_DEV=1 CONFIG_NET_RANDOM_ETHADDR=y
Signature · 1 line
2.25.1
Re: [Upstream] [PATCH 6/6] configs: phycore_am62x_a53_defconfig: Enable CONFIG_ENV_OVERWRITE
Hi Daniel,
Am 22.05.24 um 08:18 schrieb Daniel Schultz:
Quoted 7 lines
Enable
CONFIG_ENV_OVERWRITEto overwrite ethaddr in the environment. This is required because our environment is not located in the boot partition.Signed-off-by Daniel Schultz <[email protected]>--- configs/phycore_am62x_a53_defconfig | 1 +
What about the change for the phycore_am64x?
Quoted 14 lines
1 file changed, 1 insertion(+)configs/phycore_am62x_a53_defconfig +1
-0@@ -59,6 +59,7 @@ CONFIG_SPL_OF_CONTROL=y CONFIG_MULTI_DTB_FIT=y CONFIG_SPL_MULTI_DTB_FIT=y CONFIG_SPL_MULTI_DTB_FIT_NO_COMPRESSION=y +CONFIG_ENV_OVERWRITE=y CONFIG_ENV_IS_IN_MMC=y CONFIG_SYS_MMC_ENV_DEV=1 CONFIG_NET_RANDOM_ETHADDR=y
Re: [Upstream] [PATCH 6/6] configs: phycore_am62x_a53_defconfig: Enable CONFIG_ENV_OVERWRITE
Hi,
Quoted 11 lines · Wadim Egorov
Hi Daniel,
Am 22.05.24 um 08:18 schrieb Daniel Schultz:
Quoted 7 lines
Enable
CONFIG_ENV_OVERWRITEto overwrite ethaddr in the environment. This is required because our environment is not located in the boot partition.Signed-off-by Daniel Schultz <[email protected]>---
configs/phycore_am62x_a53_defconfig | 1 +What about the change for the
phycore_am64x?
Will enable phyCORE-AM64x later with additional changes to enable SOM detection.
Regards,
Daniel
Quoted 16 lines
Quoted 16 lines
1 file changed, 1 insertion(+)configs/phycore_am62x_a53_defconfig +0
-0@@ -59,6 +59,7 @@ CONFIG_SPL_OF_CONTROL=y
CONFIG_MULTI_DTB_FIT=y
CONFIG_SPL_MULTI_DTB_FIT=y
CONFIG_SPL_MULTI_DTB_FIT_NO_COMPRESSION=y
+CONFIG_ENV_OVERWRITE=y
CONFIG_ENV_IS_IN_MMC=y
CONFIG_SYS_MMC_ENV_DEV=1
CONFIG_NET_RANDOM_ETHADDR=y
Quoted 10 lines · Daniel Schultz
This patch series adds support for the EEPROM v3 API.
V3 is backwards compatible to V2 and therefore, the V2 image still exists at the beginning. Only the API version changed from 2 to 3.
V3 is a block-based memory layout organized as singled-linked list with different types of blocks. This is a more flexible approach and allows us to extend it by more block types in the future.
[...]
Applied to u-boot/next, thanks!
Signature · 1 line
Tom