board: siemens: adapt factoryset reading for DM_I2C enabled boards
PATCH 1/2 board: siemens: adapt factoryset reading for DM_I2C enabled boards
For new boards we always enable DM_I2C. Extend factoryset functions to support EEPROM reading on these boards.
--- board/siemens/common/factoryset.c | 45 +++++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-)
board/siemens/common/factoryset.c +43 -2
@@ -8,6 +8,7 @@#if !defined(CONFIG_SPL_BUILD )#include <common.h> +#include <dm.h> #include <environment.h> #include <i2c.h> #include <asm/io.h>
@@ -143,16 +144,39 @@ int factoryset_read_eeprom(int i2c_addr)int i, pages =0 , size =0 ;unsigned char eeprom_buf[0x3c00 ], hdr[4 ], buf[MAX_STRING_LENGTH ];unsigned char *cp, *cp1; +#if CONFIG_IS_ENABLED (DM_I2C ) +struct udevice *bus, *dev; +int ret; +#endif #if defined(CONFIG_DFU_OVER_USB ) factory_dat.usb_vendor_id =CONFIG_USB_GADGET_VENDOR_NUM ; factory_dat.usb_product_id =CONFIG_USB_GADGET_PRODUCT_NUM ;#endif + +#if CONFIG_IS_ENABLED (DM_I2C ) + ret =uclass_get_device_by_seq (UCLASS_I2C ,EEPROM_I2C_BUS , &bus); +if (ret) + goto err; + + ret =dm_i2c_probe (bus, i2c_addr,0 , &dev); +if (ret) + goto err; + + ret =i2c_set_chip_offset_len (dev,2 ); +if (ret) + goto err; + + ret =dm_i2c_read (dev,EEPROM_FATORYSET_OFFSET , hdr,sizeof (hdr)); +if (ret) + goto err; +#else if (i2c_probe (i2c_addr)) goto err;if (i2c_read (i2c_addr,EEPROM_FATORYSET_OFFSET ,2 , hdr,sizeof (hdr))) goto err; +#endif if ((hdr[0 ] !=0x99 ) || (hdr[1 ] !=0x80 )) {printf ("FactorySet is not right in eeprom.\n" );
@@ -173,16 +197,33 @@ int factoryset_read_eeprom(int i2c_addr)* data after every time we got a record from eeprom */ debug ("Read eeprom page :\n" ); -for (i =0 ; i < pages; i++) +for (i =0 ; i < pages; i++) { +#if CONFIG_IS_ENABLED (DM_I2C ) + ret =dm_i2c_read (dev, (OFF_PG + i) *EEPR_PG_SZ , + eeprom_buf + (i *EEPR_PG_SZ ),EEPR_PG_SZ ); +if (ret) + goto err; +#else if (i2c_read (i2c_addr, (OFF_PG + i) *EEPR_PG_SZ ,2 , eeprom_buf + (i *EEPR_PG_SZ ),EEPR_PG_SZ )) goto err; +#endif + } -if (size %EEPR_PG_SZ ) +if (size %EEPR_PG_SZ ) { +#if CONFIG_IS_ENABLED (DM_I2C ) + ret =dm_i2c_read (dev, (OFF_PG + pages) *EEPR_PG_SZ , + eeprom_buf + (pages *EEPR_PG_SZ ), + size %EEPR_PG_SZ ); +if (ret) + goto err; +#else if (i2c_read (i2c_addr, (OFF_PG + pages) *EEPR_PG_SZ ,2 , eeprom_buf + (pages *EEPR_PG_SZ ), (size %EEPR_PG_SZ ))) goto err; +#endif + }/* we do below just for eeprom align */ for (i =0 ; i < size; i++)
Signature · 1 line
2.17.1
PATCH 2/2 board: siemens: extend factoryset reading for giedi and deneb boards
giedi and deneb are i.MX8X based and have additional data with WLAN MAC in factoryset container. Enable building for these boards and adapt factoryset functions to set WLAN MAC and dtb name in environment.
--- board/siemens/common/factoryset.c | 78 +++++++++++++++++++++++++------ board/siemens/common/factoryset.h | 3 ++ 2 files changed, 66 insertions(+), 15 deletions(-)
board/siemens/common/factoryset.c +63 -15
@@ -243,6 +243,20 @@ int factoryset_read_eeprom(int i2c_addr) cp1 +=3 ; } +#if CONFIG_IS_ENABLED (TARGET_GIEDI ) ||CONFIG_IS_ENABLED (TARGET_DENEB ) +/* get mac address for WLAN */ + ret =get_factory_record_val (cp, size, (uchar *)"WLAN1" , (uchar *)"mac" , + buf,MAX_STRING_LENGTH ); +if (ret >0 ) { + cp1 = buf; +for (i =0 ; i <6 ; i++) { + factory_dat.mac_wlan[i] =simple_strtoul ((char *)cp1, +NULL ,16 ); + cp1 +=3 ; + } + } +#endif +#if defined(CONFIG_DFU_OVER_USB )/* read vid and pid for dfu mode */ if (0 <= get_factory_record_val(cp, size, (uchar *)"USBD1",
@@ -305,42 +319,76 @@ err:return 1 ; } -static struct ctrl_dev *cdev = (struct ctrl_dev *)CTRL_DEVICE_BASE ; +static int get_mac_from_efuse (uint8_t mac[6 ]) +{ +#ifdef CONFIG_AM33XX +struct ctrl_dev *cdev = (struct ctrl_dev *)CTRL_DEVICE_BASE ; +uint32_t mac_hi, mac_lo; + + mac_lo =readl (&cdev->macid0l); + mac_hi =readl (&cdev->macid0h); + + mac[0 ] = mac_hi &0xFF ; + mac[1 ] = (mac_hi &0xFF00 ) >>8 ; + mac[2 ] = (mac_hi &0xFF0000 ) >>16 ; + mac[3 ] = (mac_hi &0xFF000000 ) >>24 ; + mac[4 ] = mac_lo &0xFF ; + mac[5 ] = (mac_lo &0xFF00 ) >>8 ; +#else +/* unhandled */ +memset (mac,0 ,6 ); +#endif +if (!is_valid_ethaddr (mac)) { +puts ("Warning: ethaddr not set by FactorySet or E-fuse. " ); +puts ("Set <ethaddr> variable to overcome this.\n" ); +return -1 ; + } +return 0 ; +}static int factoryset_mac_env_set (void ) {uint8_t mac_addr[6 ]; +/* Set mac from factoryset or try reading E-fuse */ debug ("FactorySet: Set mac address\n" );if (is_valid_ethaddr (factory_dat.mac)) {memcpy (mac_addr, factory_dat.mac,6 ); }else { -uint32_t mac_hi, mac_lo; -debug ("Warning: FactorySet: <ethaddr> not set. Fallback to E-fuse\n" ); - mac_lo =readl (&cdev->macid0l); - mac_hi =readl (&cdev->macid0h); - - mac_addr[0 ] = mac_hi &0xFF ; - mac_addr[1 ] = (mac_hi &0xFF00 ) >>8 ; - mac_addr[2 ] = (mac_hi &0xFF0000 ) >>16 ; - mac_addr[3 ] = (mac_hi &0xFF000000 ) >>24 ; - mac_addr[4 ] = mac_lo &0xFF ; - mac_addr[5 ] = (mac_lo &0xFF00 ) >>8 ; -if (!is_valid_ethaddr (mac_addr)) { -printf ("Warning: ethaddr not set by FactorySet or E-fuse. Set <ethaddr> variable to overcome this.\n" ); +if (get_mac_from_efuse (mac_addr) <0 )return -1 ; - } }eth_env_set_enetaddr ("ethaddr" , mac_addr); + +#if CONFIG_IS_ENABLED (TARGET_GIEDI ) ||CONFIG_IS_ENABLED (TARGET_DENEB ) +eth_env_set_enetaddr ("eth1addr" , mac_addr); + +/* wlan mac */ +if (is_valid_ethaddr (factory_dat.mac_wlan)) +eth_env_set_enetaddr ("eth2addr" , factory_dat.mac_wlan); +#endif return 0 ; } +static void factoryset_dtb_env_set (void ) +{ +/* Set ASN in environment*/ +if (factory_dat.asn[0 ] !=0 ) { +env_set ("dtb_name" , (char *)factory_dat.asn); + }else { +/* dtb suffix gets added in load script */ +env_set ("dtb_name" ,"default" ); + } +} +int factoryset_env_set (void ) {int ret =0 ; +factoryset_dtb_env_set (); +if (factoryset_mac_env_set () <0 ) ret =-1 ;
board/siemens/common/factoryset.h +3 -0
@@ -11,6 +11,9 @@struct factorysetcontainer {uchar mac[6 ]; +#if CONFIG_IS_ENABLED (TARGET_GIEDI ) ||CONFIG_IS_ENABLED (TARGET_DENEB ) +uchar mac_wlan[6 ]; +#endif int usb_vendor_id;int usb_product_id;int pxm50;
Signature · 1 line
2.17.1
PATCH 2/2 board: siemens: extend factoryset reading for giedi and deneb boards
Quoted 6 lines · Anatolij Gustschin
giedi and deneb are i.MX8X based and have additional data with WLAN MAC in factoryset container. Enable building for these boards and adapt factoryset functions to set WLAN MAC and dtb name in environment.
Signed-off-by Anatolij Gustschin <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: not available URL: <http://lists.denx.de/pipermail/u-boot/attachments/20190813/d6061b00/attachment.sig>
PATCH 1/2 board: siemens: adapt factoryset reading for DM_I2C enabled boards
In reply to Anatolij GustschinQuoted 4 lines · Anatolij Gustschin
For new boards we always enable
DM_I2C. Extend factoryset functions to support EEPROM reading on these boards.Signed-off-by Anatolij Gustschin <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: not available URL: <http://lists.denx.de/pipermail/u-boot/attachments/20190813/484c8314/attachment.sig>