amlogic: clean up board files
Subsystems (3)
cover amlogic: clean up board files
Hi,
this series simplifies Amlogic board files by factorizing common code and removing unneeded parts. Also, it fixes printing the serial number read from efuse.
Beniamino Galvani (3):
boards: amlogic: remove ethernet gpio reset code from boards
boards: amlogic: use common function for environment initialization
arm: meson: null-terminate the serial number
arch/arm/include/asm/arch-meson/sm.h | 1 + arch/arm/mach-meson/sm.c | 29 +++++++++++++++++++++ board/amlogic/khadas-vim/khadas-vim.c | 25 +----------------- board/amlogic/libretech-cc/libretech-cc.c | 25 +----------------- board/amlogic/nanopi-k2/nanopi-k2.c | 31 +---------------------- board/amlogic/odroid-c2/odroid-c2.c | 31 +---------------------- board/amlogic/p212/p212.c | 25 +----------------- 7 files changed, 35 insertions(+), 132 deletions(-)
Signature · 1 line
2.17.1
PATCH 1/3 boards: amlogic: remove ethernet gpio reset code from boards
The reset is already handled by the designware driver using information from device tree.
--- board/amlogic/nanopi-k2/nanopi-k2.c | 6 ------ board/amlogic/odroid-c2/odroid-c2.c | 6 ------ 2 files changed, 12 deletions(-)
board/amlogic/nanopi-k2/nanopi-k2.c +0 -6
@@ -30,12 +30,6 @@ int misc_init_r(void)meson_gx_eth_init (PHY_INTERFACE_MODE_RGMII ,0 ); -/* Reset PHY on GPIOZ_14 */ -clrbits_le32 (GX_GPIO_EN (3 ),BIT (14 )); -clrbits_le32 (GX_GPIO_OUT (3 ),BIT (14 )); -mdelay (10 ); -setbits_le32 (GX_GPIO_OUT (3 ),BIT (14 )); -if (!eth_env_get_enetaddr ("ethaddr" , mac_addr)) { len =meson_sm_read_efuse (EFUSE_MAC_OFFSET , mac_addr,EFUSE_MAC_SIZE );
board/amlogic/odroid-c2/odroid-c2.c +0 -6
@@ -30,12 +30,6 @@ int misc_init_r(void)meson_gx_eth_init (PHY_INTERFACE_MODE_RGMII ,0 ); -/* Reset PHY on GPIOZ_14 */ -clrbits_le32 (GX_GPIO_EN (3 ),BIT (14 )); -clrbits_le32 (GX_GPIO_OUT (3 ),BIT (14 )); -mdelay (10 ); -setbits_le32 (GX_GPIO_OUT (3 ),BIT (14 )); -if (!eth_env_get_enetaddr ("ethaddr" , mac_addr)) { len =meson_sm_read_efuse (EFUSE_MAC_OFFSET , mac_addr,EFUSE_MAC_SIZE );
Signature · 1 line
2.17.1
PATCH 1/3 boards: amlogic: remove ethernet gpio reset code from boards
Quoted 34 lines · Beniamino Galvani
The reset is already handled by the designware driver using information from device tree.
Signed-off-by Beniamino Galvani <[email protected]>--- board/amlogic/nanopi-k2/nanopi-k2.c | 6 ------ board/amlogic/odroid-c2/odroid-c2.c | 6 ------ 2 files changed, 12 deletions(-)board/amlogic/nanopi-k2/nanopi-k2.c +0
-6@@ -30,12 +30,6 @@ int misc_init_r(void)meson_gx_eth_init (PHY_INTERFACE_MODE_RGMII ,0 ); -/* Reset PHY on GPIOZ_14 */ -clrbits_le32 (GX_GPIO_EN (3 ),BIT (14 )); -clrbits_le32 (GX_GPIO_OUT (3 ),BIT (14 )); -mdelay (10 ); -setbits_le32 (GX_GPIO_OUT (3 ),BIT (14 )); -if (!eth_env_get_enetaddr ("ethaddr" , mac_addr)) { len =meson_sm_read_efuse (EFUSE_MAC_OFFSET , mac_addr,EFUSE_MAC_SIZE );board/amlogic/odroid-c2/odroid-c2.c +0
-0@@ -30,12 +30,6 @@ int misc_init_r(void)meson_gx_eth_init (PHY_INTERFACE_MODE_RGMII ,0 );
board/amlogic/odroid-c2/odroid-c2.c int misc_init_r(void) · line 35
Quoted 10 lines
board/amlogic/odroid-c2/odroid-c2.c +0
-6-/* Reset PHY on GPIOZ_14 */ -clrbits_le32 (GX_GPIO_EN (3 ),BIT (14 )); -clrbits_le32 (GX_GPIO_OUT (3 ),BIT (14 )); -mdelay (10 ); -setbits_le32 (GX_GPIO_OUT (3 ),BIT (14 )); -if (!eth_env_get_enetaddr ("ethaddr" , mac_addr)) { len =meson_sm_read_efuse (EFUSE_MAC_OFFSET , mac_addr,EFUSE_MAC_SIZE );
PATCH 1/3 boards: amlogic: remove ethernet gpio reset code from boards
In reply to Beniamino GalvaniQuoted 5 lines · Beniamino Galvani
The reset is already handled by the designware driver using information from device tree.
Signed-off-by Beniamino Galvani <[email protected]>Acked-by Neil Armstrong <[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.infradead.org/pipermail/linux-amlogic/attachments/20180824/82676d4b/attachment.sig>
PATCH 2/3 boards: amlogic: use common function for environment initialization
In reply to Beniamino GalvaniClean up board files by moving the duplicate environment initialization to arch code.
--- arch/arm/include/asm/arch-meson/sm.h | 1 + arch/arm/mach-meson/sm.c | 27 +++++++++++++++++++++++ board/amlogic/khadas-vim/khadas-vim.c | 25 +-------------------- board/amlogic/libretech-cc/libretech-cc.c | 25 +-------------------- board/amlogic/nanopi-k2/nanopi-k2.c | 25 +-------------------- board/amlogic/odroid-c2/odroid-c2.c | 25 +-------------------- board/amlogic/p212/p212.c | 25 +-------------------- 7 files changed, 33 insertions(+), 120 deletions(-)
arch/arm/include/asm/arch-meson/sm.h +1 -0
@@ -7,5 +7,6 @@#define __MESON_SM_H__ssize_t meson_sm_read_efuse (uintptr_t offset,void *buffer,size_t size); +void meson_init_env_from_efuse (void );#endif /* __MESON_SM_H__ */
arch/arm/mach-meson/sm.c +27 -0
@@ -6,6 +6,7 @@*/ #include <common.h> +#include <environment.h> #include <asm/arch/gx.h> #include <linux/kernel.h>
@@ -14,6 +15,11 @@#define FN_EFUSE_READ 0x82000030#define FN_EFUSE_WRITE 0x82000031 +#define EFUSE_SN_OFFSET 20 +#define EFUSE_SN_SIZE 16 +#define EFUSE_MAC_OFFSET 52 +#define EFUSE_MAC_SIZE 6 +static void *shmem_input;static void *shmem_output;
@@ -54,3 +60,24 @@ ssize_t meson_sm_read_efuse(uintptr_t offset, void *buffer, size_t size)return regs.regs[0 ]; } + +void meson_init_env_from_efuse (void ) +{ +static u8 mac[EFUSE_MAC_SIZE ]; +char serial[EFUSE_SN_SIZE ]; +ssize_t len; + +if (!eth_env_get_enetaddr ("ethaddr" , mac)) { + len =meson_sm_read_efuse (EFUSE_MAC_OFFSET , + mac,EFUSE_MAC_SIZE ); +if (len ==EFUSE_MAC_SIZE &&is_valid_ethaddr (mac)) +eth_env_set_enetaddr ("ethaddr" , mac); + } + +if (!env_get ("serial#" )) { + len =meson_sm_read_efuse (EFUSE_SN_OFFSET , serial, +EFUSE_SN_SIZE ); +if (len ==EFUSE_SN_SIZE ) +env_set ("serial#" , serial); + } +}
board/amlogic/khadas-vim/khadas-vim.c +1 -24
@@ -6,18 +6,12 @@#include <common.h> #include <dm.h> -#include <environment.h> #include <asm/io.h> #include <asm/arch/gx.h> #include <asm/arch/mem.h> #include <asm/arch/sm.h> #include <asm/arch/eth.h> -#define EFUSE_SN_OFFSET 20 -#define EFUSE_SN_SIZE 16 -#define EFUSE_MAC_OFFSET 52 -#define EFUSE_MAC_SIZE 6 -int board_init (void ) {return 0 ;
@@ -25,26 +19,9 @@ int board_init(void)int misc_init_r (void ) { -u8 mac_addr[EFUSE_MAC_SIZE ]; -char serial[EFUSE_SN_SIZE ]; -ssize_t len; -meson_gx_eth_init (PHY_INTERFACE_MODE_RMII ,MESON_GXL_USE_INTERNAL_RMII_PHY ); - -if (!eth_env_get_enetaddr ("ethaddr" , mac_addr)) { - len =meson_sm_read_efuse (EFUSE_MAC_OFFSET , - mac_addr,EFUSE_MAC_SIZE ); -if (len ==EFUSE_MAC_SIZE &&is_valid_ethaddr (mac_addr)) -eth_env_set_enetaddr ("ethaddr" , mac_addr); - } - -if (!env_get ("serial#" )) { - len =meson_sm_read_efuse (EFUSE_SN_OFFSET , serial, -EFUSE_SN_SIZE ); -if (len ==EFUSE_SN_SIZE ) -env_set ("serial#" , serial); - } +meson_init_env_from_efuse ();return 0 ; }
board/amlogic/libretech-cc/libretech-cc.c +1 -24
@@ -6,18 +6,12 @@#include <common.h> #include <dm.h> -#include <environment.h> #include <asm/io.h> #include <asm/arch/gx.h> #include <asm/arch/sm.h> #include <asm/arch/eth.h> #include <asm/arch/mem.h> -#define EFUSE_SN_OFFSET 20 -#define EFUSE_SN_SIZE 16 -#define EFUSE_MAC_OFFSET 52 -#define EFUSE_MAC_SIZE 6 -int board_init (void ) {return 0 ;
@@ -25,26 +19,9 @@ int board_init(void)int misc_init_r (void ) { -u8 mac_addr[EFUSE_MAC_SIZE ]; -char serial[EFUSE_SN_SIZE ]; -ssize_t len; -meson_gx_eth_init (PHY_INTERFACE_MODE_RMII ,MESON_GXL_USE_INTERNAL_RMII_PHY ); - -if (!eth_env_get_enetaddr ("ethaddr" , mac_addr)) { - len =meson_sm_read_efuse (EFUSE_MAC_OFFSET , - mac_addr,EFUSE_MAC_SIZE ); -if (len ==EFUSE_MAC_SIZE &&is_valid_ethaddr (mac_addr)) -eth_env_set_enetaddr ("ethaddr" , mac_addr); - } - -if (!env_get ("serial#" )) { - len =meson_sm_read_efuse (EFUSE_SN_OFFSET , serial, -EFUSE_SN_SIZE ); -if (len ==EFUSE_SN_SIZE ) -env_set ("serial#" , serial); - } +meson_init_env_from_efuse ();return 0 ; }
board/amlogic/nanopi-k2/nanopi-k2.c +1 -24
@@ -5,18 +5,12 @@#include <common.h> #include <dm.h> -#include <environment.h> #include <asm/io.h> #include <asm/arch/gx.h> #include <asm/arch/sm.h> #include <asm/arch/eth.h> #include <asm/arch/mem.h> -#define EFUSE_SN_OFFSET 20 -#define EFUSE_SN_SIZE 16 -#define EFUSE_MAC_OFFSET 52 -#define EFUSE_MAC_SIZE 6 -int board_init (void ) {return 0 ;
@@ -24,25 +18,8 @@ int board_init(void)int misc_init_r (void ) { -u8 mac_addr[EFUSE_MAC_SIZE ]; -char serial[EFUSE_SN_SIZE ]; -ssize_t len; -meson_gx_eth_init (PHY_INTERFACE_MODE_RGMII ,0 ); - -if (!eth_env_get_enetaddr ("ethaddr" , mac_addr)) { - len =meson_sm_read_efuse (EFUSE_MAC_OFFSET , - mac_addr,EFUSE_MAC_SIZE ); -if (len ==EFUSE_MAC_SIZE &&is_valid_ethaddr (mac_addr)) -eth_env_set_enetaddr ("ethaddr" , mac_addr); - } - -if (!env_get ("serial#" )) { - len =meson_sm_read_efuse (EFUSE_SN_OFFSET , serial, -EFUSE_SN_SIZE ); -if (len ==EFUSE_SN_SIZE ) -env_set ("serial#" , serial); - } +meson_init_env_from_efuse ();return 0 ; }
board/amlogic/odroid-c2/odroid-c2.c +1 -24
@@ -5,18 +5,12 @@#include <common.h> #include <dm.h> -#include <environment.h> #include <asm/io.h> #include <asm/arch/gx.h> #include <asm/arch/sm.h> #include <asm/arch/eth.h> #include <asm/arch/mem.h> -#define EFUSE_SN_OFFSET 20 -#define EFUSE_SN_SIZE 16 -#define EFUSE_MAC_OFFSET 52 -#define EFUSE_MAC_SIZE 6 -int board_init (void ) {return 0 ;
@@ -24,25 +18,8 @@ int board_init(void)int misc_init_r (void ) { -u8 mac_addr[EFUSE_MAC_SIZE ]; -char serial[EFUSE_SN_SIZE ]; -ssize_t len; -meson_gx_eth_init (PHY_INTERFACE_MODE_RGMII ,0 ); - -if (!eth_env_get_enetaddr ("ethaddr" , mac_addr)) { - len =meson_sm_read_efuse (EFUSE_MAC_OFFSET , - mac_addr,EFUSE_MAC_SIZE ); -if (len ==EFUSE_MAC_SIZE &&is_valid_ethaddr (mac_addr)) -eth_env_set_enetaddr ("ethaddr" , mac_addr); - } - -if (!env_get ("serial#" )) { - len =meson_sm_read_efuse (EFUSE_SN_OFFSET , serial, -EFUSE_SN_SIZE ); -if (len ==EFUSE_SN_SIZE ) -env_set ("serial#" , serial); - } +meson_init_env_from_efuse ();return 0 ; }
board/amlogic/p212/p212.c +1 -24
@@ -6,18 +6,12 @@#include <common.h> #include <dm.h> -#include <environment.h> #include <asm/io.h> #include <asm/arch/gx.h> #include <asm/arch/sm.h> #include <asm/arch/eth.h> #include <asm/arch/mem.h> -#define EFUSE_SN_OFFSET 20 -#define EFUSE_SN_SIZE 16 -#define EFUSE_MAC_OFFSET 52 -#define EFUSE_MAC_SIZE 6 -int board_init (void ) {return 0 ;
@@ -25,25 +19,8 @@ int board_init(void)int misc_init_r (void ) { -u8 mac_addr[EFUSE_MAC_SIZE ]; -char serial[EFUSE_SN_SIZE ]; -ssize_t len; -meson_gx_eth_init (PHY_INTERFACE_MODE_RMII ,0 ); - -if (!eth_env_get_enetaddr ("ethaddr" , mac_addr)) { - len =meson_sm_read_efuse (EFUSE_MAC_OFFSET , - mac_addr,EFUSE_MAC_SIZE ); -if (len ==EFUSE_MAC_SIZE &&is_valid_ethaddr (mac_addr)) -eth_env_set_enetaddr ("ethaddr" , mac_addr); - } - -if (!env_get ("serial#" )) { - len =meson_sm_read_efuse (EFUSE_SN_OFFSET , serial, -EFUSE_SN_SIZE ); -if (len ==EFUSE_SN_SIZE ) -env_set ("serial#" , serial); - } +meson_init_env_from_efuse ();return 0 ; }
Signature · 1 line
2.17.1
PATCH 2/3 boards: amlogic: use common function for environment initialization
Hi Beniamino,
Quoted 317 lines · Beniamino Galvani
Clean up board files by moving the duplicate environment initialization to arch code.
Signed-off-by Beniamino Galvani <[email protected]>--- arch/arm/include/asm/arch-meson/sm.h | 1 + arch/arm/mach-meson/sm.c | 27 +++++++++++++++++++++++ board/amlogic/khadas-vim/khadas-vim.c | 25 +-------------------- board/amlogic/libretech-cc/libretech-cc.c | 25 +-------------------- board/amlogic/nanopi-k2/nanopi-k2.c | 25 +-------------------- board/amlogic/odroid-c2/odroid-c2.c | 25 +-------------------- board/amlogic/p212/p212.c | 25 +-------------------- 7 files changed, 33 insertions(+), 120 deletions(-)arch/arm/include/asm/arch-meson/sm.h +1
-0@@ -7,5 +7,6 @@#define __MESON_SM_H__ssize_t meson_sm_read_efuse (uintptr_t offset,void *buffer,size_t size); +void meson_init_env_from_efuse (void );#endif /* __MESON_SM_H__ */ arch/arm/mach-meson/sm.c +27
-0@@ -6,6 +6,7 @@*/ #include <common.h> +#include <environment.h> #include <asm/arch/gx.h> #include <linux/kernel.h> @@ -14,6 +15,11 @@#define FN_EFUSE_READ 0x82000030#define FN_EFUSE_WRITE 0x82000031 +#define EFUSE_SN_OFFSET 20 +#define EFUSE_SN_SIZE 16 +#define EFUSE_MAC_OFFSET 52 +#define EFUSE_MAC_SIZE 6 +static void *shmem_input;static void *shmem_output;@@ -54,3 +60,24 @@ ssize_t meson_sm_read_efuse(uintptr_t offset, void *buffer, size_t size)return regs.regs[0 ]; } + +void meson_init_env_from_efuse (void ) +{ +static u8 mac[EFUSE_MAC_SIZE ]; +char serial[EFUSE_SN_SIZE ]; +ssize_t len; + +if (!eth_env_get_enetaddr ("ethaddr" , mac)) { + len =meson_sm_read_efuse (EFUSE_MAC_OFFSET , + mac,EFUSE_MAC_SIZE ); +if (len ==EFUSE_MAC_SIZE &&is_valid_ethaddr (mac)) +eth_env_set_enetaddr ("ethaddr" , mac); + } + +if (!env_get ("serial#" )) { + len =meson_sm_read_efuse (EFUSE_SN_OFFSET , serial, +EFUSE_SN_SIZE ); +if (len ==EFUSE_SN_SIZE ) +env_set ("serial#" , serial); + } +}board/amlogic/khadas-vim/khadas-vim.c +1
-24@@ -6,18 +6,12 @@#include <common.h> #include <dm.h> -#include <environment.h> #include <asm/io.h> #include <asm/arch/gx.h> #include <asm/arch/mem.h> #include <asm/arch/sm.h> #include <asm/arch/eth.h> -#define EFUSE_SN_OFFSET 20 -#define EFUSE_SN_SIZE 16 -#define EFUSE_MAC_OFFSET 52 -#define EFUSE_MAC_SIZE 6 -int board_init (void ) {return 0 ;@@ -25,26 +19,9 @@ int board_init(void)int misc_init_r (void ) { -u8 mac_addr[EFUSE_MAC_SIZE ]; -char serial[EFUSE_SN_SIZE ]; -ssize_t len; -meson_gx_eth_init (PHY_INTERFACE_MODE_RMII ,MESON_GXL_USE_INTERNAL_RMII_PHY ); - -if (!eth_env_get_enetaddr ("ethaddr" , mac_addr)) { - len =meson_sm_read_efuse (EFUSE_MAC_OFFSET , - mac_addr,EFUSE_MAC_SIZE ); -if (len ==EFUSE_MAC_SIZE &&is_valid_ethaddr (mac_addr)) -eth_env_set_enetaddr ("ethaddr" , mac_addr); - } - -if (!env_get ("serial#" )) { - len =meson_sm_read_efuse (EFUSE_SN_OFFSET , serial, -EFUSE_SN_SIZE ); -if (len ==EFUSE_SN_SIZE ) -env_set ("serial#" , serial); - } +meson_init_env_from_efuse ();return 0 ; }board/amlogic/libretech-cc/libretech-cc.c +1
-24@@ -6,18 +6,12 @@#include <common.h> #include <dm.h> -#include <environment.h> #include <asm/io.h> #include <asm/arch/gx.h> #include <asm/arch/sm.h> #include <asm/arch/eth.h> #include <asm/arch/mem.h> -#define EFUSE_SN_OFFSET 20 -#define EFUSE_SN_SIZE 16 -#define EFUSE_MAC_OFFSET 52 -#define EFUSE_MAC_SIZE 6 -int board_init (void ) {return 0 ;@@ -25,26 +19,9 @@ int board_init(void)int misc_init_r (void ) { -u8 mac_addr[EFUSE_MAC_SIZE ]; -char serial[EFUSE_SN_SIZE ]; -ssize_t len; -meson_gx_eth_init (PHY_INTERFACE_MODE_RMII ,MESON_GXL_USE_INTERNAL_RMII_PHY ); - -if (!eth_env_get_enetaddr ("ethaddr" , mac_addr)) { - len =meson_sm_read_efuse (EFUSE_MAC_OFFSET , - mac_addr,EFUSE_MAC_SIZE ); -if (len ==EFUSE_MAC_SIZE &&is_valid_ethaddr (mac_addr)) -eth_env_set_enetaddr ("ethaddr" , mac_addr); - } - -if (!env_get ("serial#" )) { - len =meson_sm_read_efuse (EFUSE_SN_OFFSET , serial, -EFUSE_SN_SIZE ); -if (len ==EFUSE_SN_SIZE ) -env_set ("serial#" , serial); - } +meson_init_env_from_efuse ();return 0 ; }board/amlogic/nanopi-k2/nanopi-k2.c +1
-24@@ -5,18 +5,12 @@#include <common.h> #include <dm.h> -#include <environment.h> #include <asm/io.h> #include <asm/arch/gx.h> #include <asm/arch/sm.h> #include <asm/arch/eth.h> #include <asm/arch/mem.h> -#define EFUSE_SN_OFFSET 20 -#define EFUSE_SN_SIZE 16 -#define EFUSE_MAC_OFFSET 52 -#define EFUSE_MAC_SIZE 6 -int board_init (void ) {return 0 ;@@ -24,25 +18,8 @@ int board_init(void)int misc_init_r (void ) { -u8 mac_addr[EFUSE_MAC_SIZE ]; -char serial[EFUSE_SN_SIZE ]; -ssize_t len; -meson_gx_eth_init (PHY_INTERFACE_MODE_RGMII ,0 ); - -if (!eth_env_get_enetaddr ("ethaddr" , mac_addr)) { - len =meson_sm_read_efuse (EFUSE_MAC_OFFSET , - mac_addr,EFUSE_MAC_SIZE ); -if (len ==EFUSE_MAC_SIZE &&is_valid_ethaddr (mac_addr)) -eth_env_set_enetaddr ("ethaddr" , mac_addr); - } - -if (!env_get ("serial#" )) { - len =meson_sm_read_efuse (EFUSE_SN_OFFSET , serial, -EFUSE_SN_SIZE ); -if (len ==EFUSE_SN_SIZE ) -env_set ("serial#" , serial); - } +meson_init_env_from_efuse ();return 0 ; }board/amlogic/odroid-c2/odroid-c2.c +1
-24@@ -5,18 +5,12 @@#include <common.h> #include <dm.h> -#include <environment.h> #include <asm/io.h> #include <asm/arch/gx.h> #include <asm/arch/sm.h> #include <asm/arch/eth.h> #include <asm/arch/mem.h> -#define EFUSE_SN_OFFSET 20 -#define EFUSE_SN_SIZE 16 -#define EFUSE_MAC_OFFSET 52 -#define EFUSE_MAC_SIZE 6 -int board_init (void ) {return 0 ;@@ -24,25 +18,8 @@ int board_init(void)int misc_init_r (void ) { -u8 mac_addr[EFUSE_MAC_SIZE ]; -char serial[EFUSE_SN_SIZE ]; -ssize_t len; -meson_gx_eth_init (PHY_INTERFACE_MODE_RGMII ,0 ); - -if (!eth_env_get_enetaddr ("ethaddr" , mac_addr)) { - len =meson_sm_read_efuse (EFUSE_MAC_OFFSET , - mac_addr,EFUSE_MAC_SIZE ); -if (len ==EFUSE_MAC_SIZE &&is_valid_ethaddr (mac_addr)) -eth_env_set_enetaddr ("ethaddr" , mac_addr); - } - -if (!env_get ("serial#" )) { - len =meson_sm_read_efuse (EFUSE_SN_OFFSET , serial, -EFUSE_SN_SIZE ); -if (len ==EFUSE_SN_SIZE ) -env_set ("serial#" , serial); - } +meson_init_env_from_efuse ();return 0 ; }board/amlogic/p212/p212.c +0
-18@@ -6,18 +6,12 @@#include <common.h> #include <dm.h> -#include <environment.h> #include <asm/io.h> #include <asm/arch/gx.h> #include <asm/arch/sm.h> #include <asm/arch/eth.h> #include <asm/arch/mem.h> -#define EFUSE_SN_OFFSET 20 -#define EFUSE_SN_SIZE 16 -#define EFUSE_MAC_OFFSET 52 -#define EFUSE_MAC_SIZE 6 -int board_init (void ) {return 0 ;@@ -25,25 +19,8 @@ int board_init(void)int misc_init_r (void ) { -u8 mac_addr[EFUSE_MAC_SIZE ]; -char serial[EFUSE_SN_SIZE ]; -ssize_t len; -meson_gx_eth_init (PHY_INTERFACE_MODE_RMII ,0 ); - -if (!eth_env_get_enetaddr ("ethaddr" , mac_addr)) { - len =meson_sm_read_efuse (EFUSE_MAC_OFFSET , - mac_addr,EFUSE_MAC_SIZE ); -if (len ==EFUSE_MAC_SIZE &&is_valid_ethaddr (mac_addr)) -eth_env_set_enetaddr ("ethaddr" , mac_addr); - } -
board/amlogic/p212/p212.c int board_init(void) · line 26
Quoted 10 lines
board/amlogic/p212/p212.c +1
-6-if (!env_get ("serial#" )) { - len =meson_sm_read_efuse (EFUSE_SN_OFFSET , serial, -EFUSE_SN_SIZE ); -if (len ==EFUSE_SN_SIZE ) -env_set ("serial#" , serial); - } +meson_init_env_from_efuse ();return 0 ; }
In fact, only the "Odroid-C2" board uses these EFUSE offsets for MAC and Serial, so this was a task on my infinite TODO list to fix the MAC readout on the other boards and use the Serial number from ATF and drop reading it from the Efuses.
For the story, it seems that the early GXBB does not implement the Secure Monitor ChipID call, but the later and GXL/GXM does.
User can still store a serial number at offset : 18 with size 16
For MAC Address, for most products, they derive an unique mac address from the ChipID and allmost never store it on the Efuse...
And another weird stuff, Hardkernel uses a weird Efuse offset, because amlogic uses a smaller offset : 0 and size 6
At least you could refactor by passing the offsets to the meson_init_env_from_efuse() call.
Neil
PATCH 3/3 arm: meson: null-terminate the serial number
In reply to Beniamino GalvaniTerminate the serial number variable with null to avoid printing trailing garbage.
--- arch/arm/mach-meson/sm.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
arch/arm/mach-meson/sm.c +4 -2
@@ -64,7 +64,7 @@ ssize_t meson_sm_read_efuse(uintptr_t offset, void *buffer, size_t size)void meson_init_env_from_efuse (void ) {static u8 mac[EFUSE_MAC_SIZE ]; -char serial[EFUSE_SN_SIZE ]; +char serial[EFUSE_SN_SIZE +1 ];ssize_t len;if (!eth_env_get_enetaddr ("ethaddr" , mac)) {
@@ -77,7 +77,9 @@ void meson_init_env_from_efuse(void)if (!env_get ("serial#" )) { len =meson_sm_read_efuse (EFUSE_SN_OFFSET , serial,EFUSE_SN_SIZE ); -if (len ==EFUSE_SN_SIZE ) +if (len ==EFUSE_SN_SIZE ) { + serial[EFUSE_SN_SIZE ] ='\0' ;env_set ("serial#" , serial); + } } }
Signature · 1 line
2.17.1