[U-Boot] [PATCH 1/3] imx: Add a common way for detecting NXP boards revision
From: Fabio Estevam NXP development boards based on i.MX6/i.MX7 contain the board revision information stored in the fuses. Introduce a common function that can be shared by different boards and convert mx6sabreauto to use this new mechanism. Signed-off-by: Fabio Estevam --- arch/arm/include/asm/mach-imx/sys_proto.h | 3 ++ arch/arm/mach-imx/Kconfig | 8 + arch/arm/mach-imx/cpu.c | 27 + board/freescale/mx6sabreauto/mx6sabreauto.c | 47 ++--- configs/mx6sabreauto_defconfig | 1 + 5 files changed, 41 insertions(+), 45 deletions(-) diff --git a/arch/arm/include/asm/mach-imx/sys_proto.h b/arch/arm/include/asm/mach-imx/sys_proto.h index 7036343..d5e3eec 100644 --- a/arch/arm/include/asm/mach-imx/sys_proto.h +++ b/arch/arm/include/asm/mach-imx/sys_proto.h @@ -109,6 +109,9 @@ void imx_set_wdog_powerdown(bool enable); int board_mmc_get_env_dev(int devno); +int nxp_board_rev(void); +const char *nxp_board_rev_string(void); + /* * Initializes on-chip ethernet controllers. * to override, implement board_eth_init() diff --git a/arch/arm/mach-imx/Kconfig b/arch/arm/mach-imx/Kconfig index cd8b8d2..81ab125 100644 --- a/arch/arm/mach-imx/Kconfig +++ b/arch/arm/mach-imx/Kconfig @@ -61,3 +61,11 @@ config CMD_HDMIDETECT help This enables the 'hdmidet' command which detects if an HDMI monitor is connected. + +config NXP_BOARD_REVISION + bool "Read NXP board revision from fuses" + depends on ARCH_MX6 || ARCH_MX7 + help + NXP boards based on i.MX6/7 contain the board revision information + stored in the fuses. Select this option if you want to be able to + retrieve the board revision information. diff --git a/arch/arm/mach-imx/cpu.c b/arch/arm/mach-imx/cpu.c index 18205dc..84e829e 100644 --- a/arch/arm/mach-imx/cpu.c +++ b/arch/arm/mach-imx/cpu.c @@ -323,3 +323,30 @@ void set_chipselect_size(int const cs_size) writel(reg, &iomuxc_regs->gpr[1]); } + +#ifdef CONFIG_NXP_BOARD_REVISION +int nxp_board_rev(void) +{ + /* +* Get Board ID information from OCOTP_GP1[15:8] +* RevA: 0x1 +* RevB: 0x2 +* RevC: 0x3 +*/ + struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR; + struct fuse_bank *bank = &ocotp->bank[4]; + struct fuse_bank4_regs *fuse = + (struct fuse_bank4_regs *)bank->fuse_regs; + + return (readl(&fuse->gp1) >> 8 & 0x0F); +} + +const char *nxp_board_rev_string(void) +{ + char *rev = "A" - 1; + + rev += nxp_board_rev(); + + return rev; +} +#endif diff --git a/board/freescale/mx6sabreauto/mx6sabreauto.c b/board/freescale/mx6sabreauto/mx6sabreauto.c index bdeb5f7..ced254a 100644 --- a/board/freescale/mx6sabreauto/mx6sabreauto.c +++ b/board/freescale/mx6sabreauto/mx6sabreauto.c @@ -397,39 +397,9 @@ int board_eth_init(bd_t *bis) return cpu_eth_init(bis); } -#define BOARD_REV_B 0x200 -#define BOARD_REV_A 0x100 - -static int mx6sabre_rev(void) -{ - /* -* Get Board ID information from OCOTP_GP1[15:8] -* i.MX6Q ARD RevA: 0x01 -* i.MX6Q ARD RevB: 0x02 -*/ - struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR; - struct fuse_bank *bank = &ocotp->bank[4]; - struct fuse_bank4_regs *fuse = - (struct fuse_bank4_regs *)bank->fuse_regs; - int reg = readl(&fuse->gp1); - int ret; - - switch (reg >> 8 & 0x0F) { - case 0x02: - ret = BOARD_REV_B; - break; - case 0x01: - default: - ret = BOARD_REV_A; - break; - } - - return ret; -} - u32 get_board_rev(void) { - int rev = mx6sabre_rev(); + int rev = nxp_board_rev(); return (get_cpu_rev() & ~(0xF << 8)) | rev; } @@ -703,20 +673,7 @@ int board_late_init(void) int checkboard(void) { - int rev = mx6sabre_rev(); - char *revname; - - switch (rev) { - case BOARD_REV_B: - revname = "B"; - break; - case BOARD_REV_A: - default: - revname = "A"; - break; - } - - printf("Board: MX6Q-Sabreauto rev%s\n", revname); + printf("Board: MX6Q-Sabreauto rev%s\n", nxp_board_rev_string()); return 0; } diff --git a/configs/mx6sabreauto_defconfig b/configs/mx6sabreauto_defconfig index 418a836..215700b 100644 --- a/configs/mx6sabreauto_defconfig +++ b/configs/mx6sabreauto_defconfig @@ -8,6 +8,7 @@ CONFIG_SPL_MMC_SUPPORT=y CONFIG_SPL_SERIAL_SUPPORT=y CONFIG_SPL_LIBDISK_SUPPORT=y CONFIG_SPL_WATCHDOG_SUPPORT=y +CONFIG_NXP_BOARD_REVISION=y CONFIG_SYS_EXTRA_OPTIONS="IMX_CONFIG=arch/arm/mach-imx/spl_sd.cfg" # CONFIG_CONSOLE_MUX is not set CONFIG_SYS_CONSOLE_IS_IN_ENV=y -- 2.7.4 ___ U-Boot mailing list U-Boot@lists.denx
Re: [U-Boot] [PATCH 1/3] imx: Add a common way for detecting NXP boards revision
Hi Fabio, On 22/11/2017 14:15, Fabio Estevam wrote: > From: Fabio Estevam > > NXP development boards based on i.MX6/i.MX7 contain the board > revision information stored in the fuses. > This is a good idea. > Introduce a common function that can be shared by different boards and > convert mx6sabreauto to use this new mechanism. > > Signed-off-by: Fabio Estevam > --- > arch/arm/include/asm/mach-imx/sys_proto.h | 3 ++ > arch/arm/mach-imx/Kconfig | 8 + > arch/arm/mach-imx/cpu.c | 27 + > board/freescale/mx6sabreauto/mx6sabreauto.c | 47 > ++--- > configs/mx6sabreauto_defconfig | 1 + > 5 files changed, 41 insertions(+), 45 deletions(-) > > diff --git a/arch/arm/include/asm/mach-imx/sys_proto.h > b/arch/arm/include/asm/mach-imx/sys_proto.h > index 7036343..d5e3eec 100644 > --- a/arch/arm/include/asm/mach-imx/sys_proto.h > +++ b/arch/arm/include/asm/mach-imx/sys_proto.h > @@ -109,6 +109,9 @@ void imx_set_wdog_powerdown(bool enable); > > int board_mmc_get_env_dev(int devno); > > +int nxp_board_rev(void); > +const char *nxp_board_rev_string(void); > + > /* > * Initializes on-chip ethernet controllers. > * to override, implement board_eth_init() > diff --git a/arch/arm/mach-imx/Kconfig b/arch/arm/mach-imx/Kconfig > index cd8b8d2..81ab125 100644 > --- a/arch/arm/mach-imx/Kconfig > +++ b/arch/arm/mach-imx/Kconfig > @@ -61,3 +61,11 @@ config CMD_HDMIDETECT > help > This enables the 'hdmidet' command which detects if an HDMI monitor > is connected. > + > +config NXP_BOARD_REVISION > + bool "Read NXP board revision from fuses" > + depends on ARCH_MX6 || ARCH_MX7 > + help > + NXP boards based on i.MX6/7 contain the board revision information > + stored in the fuses. Select this option if you want to be able to > + retrieve the board revision information. > diff --git a/arch/arm/mach-imx/cpu.c b/arch/arm/mach-imx/cpu.c > index 18205dc..84e829e 100644 > --- a/arch/arm/mach-imx/cpu.c > +++ b/arch/arm/mach-imx/cpu.c ACK. And maybe this can be used by other boards, too, instead of reinvent the wheel any time :-) > @@ -323,3 +323,30 @@ void set_chipselect_size(int const cs_size) > > writel(reg, &iomuxc_regs->gpr[1]); > } > + > +#ifdef CONFIG_NXP_BOARD_REVISION > +int nxp_board_rev(void) > +{ > + /* > + * Get Board ID information from OCOTP_GP1[15:8] > + * RevA: 0x1 > + * RevB: 0x2 > + * RevC: 0x3 > + */ > + struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR; > + struct fuse_bank *bank = &ocotp->bank[4]; > + struct fuse_bank4_regs *fuse = > + (struct fuse_bank4_regs *)bank->fuse_regs; > + > + return (readl(&fuse->gp1) >> 8 & 0x0F); > +} > + > +const char *nxp_board_rev_string(void) > +{ > + char *rev = "A" - 1; > + > + rev += nxp_board_rev(); > + > + return rev; > +} > +#endif > diff --git a/board/freescale/mx6sabreauto/mx6sabreauto.c > b/board/freescale/mx6sabreauto/mx6sabreauto.c > index bdeb5f7..ced254a 100644 > --- a/board/freescale/mx6sabreauto/mx6sabreauto.c > +++ b/board/freescale/mx6sabreauto/mx6sabreauto.c > @@ -397,39 +397,9 @@ int board_eth_init(bd_t *bis) > return cpu_eth_init(bis); > } > > -#define BOARD_REV_B 0x200 > -#define BOARD_REV_A 0x100 > - > -static int mx6sabre_rev(void) > -{ > - /* > - * Get Board ID information from OCOTP_GP1[15:8] > - * i.MX6Q ARD RevA: 0x01 > - * i.MX6Q ARD RevB: 0x02 > - */ > - struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR; > - struct fuse_bank *bank = &ocotp->bank[4]; > - struct fuse_bank4_regs *fuse = > - (struct fuse_bank4_regs *)bank->fuse_regs; > - int reg = readl(&fuse->gp1); > - int ret; > - > - switch (reg >> 8 & 0x0F) { > - case 0x02: > - ret = BOARD_REV_B; > - break; > - case 0x01: > - default: > - ret = BOARD_REV_A; > - break; > - } > - > - return ret; > -} > - > u32 get_board_rev(void) > { > - int rev = mx6sabre_rev(); > + int rev = nxp_board_rev(); > > return (get_cpu_rev() & ~(0xF << 8)) | rev; > } > @@ -703,20 +673,7 @@ int board_late_init(void) > > int checkboard(void) > { > - int rev = mx6sabre_rev(); > - char *revname; > - > - switch (rev) { > - case BOARD_REV_B: > - revname = "B"; > - break; > - case BOARD_REV_A: > - default: > - revname = "A"; > - break; > - } > - > - printf("Board: MX6Q-Sabreauto rev%s\n", revname); > + printf("Board: MX6Q-Sabreauto rev%s\n", nxp_board_rev_string()); > > return 0; > } > diff --git a/configs/mx6sabreauto_defconfig b/configs/mx6sabreauto_defconfig > index 418a836..215700b 100644 > --- a/configs/mx6sabreauto_defconfig > +++ b/configs/mx6sabreauto_defconfig > @@ -8,6 +8,7 @@ CONFIG_SP
Re: [U-Boot] [PATCH 1/3] imx: Add a common way for detecting NXP boards revision
On Wed, 22 Nov 2017 11:15:26 -0200 Fabio Estevam wrote: > From: Fabio Estevam > > NXP development boards based on i.MX6/i.MX7 contain the board > revision information stored in the fuses. > > Introduce a common function that can be shared by different boards and > convert mx6sabreauto to use this new mechanism. > > Signed-off-by: Fabio Estevam > --- > arch/arm/include/asm/mach-imx/sys_proto.h | 3 ++ > arch/arm/mach-imx/Kconfig | 8 + > arch/arm/mach-imx/cpu.c | 27 + > board/freescale/mx6sabreauto/mx6sabreauto.c | 47 > ++--- > configs/mx6sabreauto_defconfig | 1 + 5 files changed, > 41 insertions(+), 45 deletions(-) > > diff --git a/arch/arm/include/asm/mach-imx/sys_proto.h > b/arch/arm/include/asm/mach-imx/sys_proto.h index 7036343..d5e3eec > 100644 --- a/arch/arm/include/asm/mach-imx/sys_proto.h > +++ b/arch/arm/include/asm/mach-imx/sys_proto.h > @@ -109,6 +109,9 @@ void imx_set_wdog_powerdown(bool enable); > > int board_mmc_get_env_dev(int devno); > > +int nxp_board_rev(void); > +const char *nxp_board_rev_string(void); > + > /* > * Initializes on-chip ethernet controllers. > * to override, implement board_eth_init() > diff --git a/arch/arm/mach-imx/Kconfig b/arch/arm/mach-imx/Kconfig > index cd8b8d2..81ab125 100644 > --- a/arch/arm/mach-imx/Kconfig > +++ b/arch/arm/mach-imx/Kconfig > @@ -61,3 +61,11 @@ config CMD_HDMIDETECT > help > This enables the 'hdmidet' command which detects if an > HDMI monitor is connected. > + > +config NXP_BOARD_REVISION > + bool "Read NXP board revision from fuses" > + depends on ARCH_MX6 || ARCH_MX7 > + help > + NXP boards based on i.MX6/7 contain the board revision > information > + stored in the fuses. Select this option if you want to be > able to > + retrieve the board revision information. > diff --git a/arch/arm/mach-imx/cpu.c b/arch/arm/mach-imx/cpu.c > index 18205dc..84e829e 100644 > --- a/arch/arm/mach-imx/cpu.c > +++ b/arch/arm/mach-imx/cpu.c > @@ -323,3 +323,30 @@ void set_chipselect_size(int const cs_size) > > writel(reg, &iomuxc_regs->gpr[1]); > } > + > +#ifdef CONFIG_NXP_BOARD_REVISION > +int nxp_board_rev(void) > +{ > + /* > + * Get Board ID information from OCOTP_GP1[15:8] > + * RevA: 0x1 > + * RevB: 0x2 > + * RevC: 0x3 > + */ > + struct ocotp_regs *ocotp = (struct ocotp_regs > *)OCOTP_BASE_ADDR; > + struct fuse_bank *bank = &ocotp->bank[4]; > + struct fuse_bank4_regs *fuse = > + (struct fuse_bank4_regs *)bank->fuse_regs; > + > + return (readl(&fuse->gp1) >> 8 & 0x0F); > +} > + > +const char *nxp_board_rev_string(void) > +{ > + char *rev = "A" - 1; > + > + rev += nxp_board_rev(); > + > + return rev; > +} > +#endif > diff --git a/board/freescale/mx6sabreauto/mx6sabreauto.c > b/board/freescale/mx6sabreauto/mx6sabreauto.c index bdeb5f7..ced254a > 100644 --- a/board/freescale/mx6sabreauto/mx6sabreauto.c > +++ b/board/freescale/mx6sabreauto/mx6sabreauto.c > @@ -397,39 +397,9 @@ int board_eth_init(bd_t *bis) > return cpu_eth_init(bis); > } > > -#define BOARD_REV_B 0x200 > -#define BOARD_REV_A 0x100 > - > -static int mx6sabre_rev(void) > -{ > - /* > - * Get Board ID information from OCOTP_GP1[15:8] > - * i.MX6Q ARD RevA: 0x01 > - * i.MX6Q ARD RevB: 0x02 > - */ > - struct ocotp_regs *ocotp = (struct ocotp_regs > *)OCOTP_BASE_ADDR; > - struct fuse_bank *bank = &ocotp->bank[4]; > - struct fuse_bank4_regs *fuse = > - (struct fuse_bank4_regs *)bank->fuse_regs; > - int reg = readl(&fuse->gp1); > - int ret; > - > - switch (reg >> 8 & 0x0F) { > - case 0x02: > - ret = BOARD_REV_B; > - break; > - case 0x01: > - default: > - ret = BOARD_REV_A; > - break; > - } > - > - return ret; > -} > - > u32 get_board_rev(void) > { > - int rev = mx6sabre_rev(); > + int rev = nxp_board_rev(); > > return (get_cpu_rev() & ~(0xF << 8)) | rev; > } > @@ -703,20 +673,7 @@ int board_late_init(void) > > int checkboard(void) > { > - int rev = mx6sabre_rev(); > - char *revname; > - > - switch (rev) { > - case BOARD_REV_B: > - revname = "B"; > - break; > - case BOARD_REV_A: > - default: > - revname = "A"; > - break; > - } > - > - printf("Board: MX6Q-Sabreauto rev%s\n", revname); > + printf("Board: MX6Q-Sabreauto rev%s\n", > nxp_board_rev_string()); > return 0; > } > diff --git a/configs/mx6sabreauto_defconfig > b/configs/mx6sabreauto_defconfig index 418a836..215700b 100644 > --- a/configs/mx6sabreauto_defconfig > +++ b/configs/mx6sabreauto_defconfig > @@ -8,6 +8,7 @@ CONFIG_SPL_MMC_SUPPORT=y > CONFIG_SPL_SERIAL_SUPPORT=y > CONFIG_SPL_LIBDISK_SUPPORT=y > CONFIG_SPL_WATCHDOG_SUPPORT=y > +CONFIG_NXP_B
Re: [U-Boot] [PATCH 1/3] imx: Add a common way for detecting NXP boards revision
Hi Fabio, On 22/11/2017 14:15, Fabio Estevam wrote: > From: Fabio Estevam > > NXP development boards based on i.MX6/i.MX7 contain the board > revision information stored in the fuses. > > Introduce a common function that can be shared by different boards and > convert mx6sabreauto to use this new mechanism. > > Signed-off-by: Fabio Estevam > --- > arch/arm/include/asm/mach-imx/sys_proto.h | 3 ++ > arch/arm/mach-imx/Kconfig | 8 + > arch/arm/mach-imx/cpu.c | 27 + > board/freescale/mx6sabreauto/mx6sabreauto.c | 47 > ++--- > configs/mx6sabreauto_defconfig | 1 + > 5 files changed, 41 insertions(+), 45 deletions(-) > > diff --git a/arch/arm/include/asm/mach-imx/sys_proto.h > b/arch/arm/include/asm/mach-imx/sys_proto.h > index 7036343..d5e3eec 100644 > --- a/arch/arm/include/asm/mach-imx/sys_proto.h > +++ b/arch/arm/include/asm/mach-imx/sys_proto.h > @@ -109,6 +109,9 @@ void imx_set_wdog_powerdown(bool enable); > > int board_mmc_get_env_dev(int devno); > > +int nxp_board_rev(void); > +const char *nxp_board_rev_string(void); > + > /* > * Initializes on-chip ethernet controllers. > * to override, implement board_eth_init() > diff --git a/arch/arm/mach-imx/Kconfig b/arch/arm/mach-imx/Kconfig > index cd8b8d2..81ab125 100644 > --- a/arch/arm/mach-imx/Kconfig > +++ b/arch/arm/mach-imx/Kconfig > @@ -61,3 +61,11 @@ config CMD_HDMIDETECT > help > This enables the 'hdmidet' command which detects if an HDMI monitor > is connected. > + > +config NXP_BOARD_REVISION > + bool "Read NXP board revision from fuses" > + depends on ARCH_MX6 || ARCH_MX7 > + help > + NXP boards based on i.MX6/7 contain the board revision information > + stored in the fuses. Select this option if you want to be able to > + retrieve the board revision information. > diff --git a/arch/arm/mach-imx/cpu.c b/arch/arm/mach-imx/cpu.c > index 18205dc..84e829e 100644 > --- a/arch/arm/mach-imx/cpu.c > +++ b/arch/arm/mach-imx/cpu.c > @@ -323,3 +323,30 @@ void set_chipselect_size(int const cs_size) > > writel(reg, &iomuxc_regs->gpr[1]); > } > + > +#ifdef CONFIG_NXP_BOARD_REVISION > +int nxp_board_rev(void) > +{ > + /* > + * Get Board ID information from OCOTP_GP1[15:8] > + * RevA: 0x1 > + * RevB: 0x2 > + * RevC: 0x3 > + */ > + struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR; > + struct fuse_bank *bank = &ocotp->bank[4]; > + struct fuse_bank4_regs *fuse = > + (struct fuse_bank4_regs *)bank->fuse_regs; > + > + return (readl(&fuse->gp1) >> 8 & 0x0F); > +} > + > +const char *nxp_board_rev_string(void) > +{ > + char *rev = "A" - 1; > + > + rev += nxp_board_rev(); I am applying this and I note this point. It looks like it does not do what you meant. rev is a char pointer, it is set to a a fix string ("A", maybe rodata), and then the pointer is decreased to 1 (going to Nirvana ?). Compiler is not happy, too, it notes that address is out of bounds. I have also noted that mx6sxsabresd_spl_defconfig has not CONFIG_NXP_BOARD_REVISION set, and build is broken. Can you take a look and resend patch with fixes ? Thanks, Stefano -- = DENX Software Engineering GmbH, Managing Director: Wolfgang Denk HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: +49-8142-66989-53 Fax: +49-8142-66989-80 Email: sba...@denx.de = ___ U-Boot mailing list U-Boot@lists.denx.de https://lists.denx.de/listinfo/u-boot
Re: [U-Boot] [PATCH 1/3] imx: Add a common way for detecting NXP boards revision
Hi Stefano, On Mon, Nov 27, 2017 at 7:15 AM, Stefano Babic wrote: > I am applying this and I note this point. It looks like it does not do > what you meant. > > rev is a char pointer, it is set to a a fix string ("A", maybe rodata), > and then the pointer is decreased to 1 (going to Nirvana ?). > > Compiler is not happy, too, it notes that address is out of bounds. > > I have also noted that mx6sxsabresd_spl_defconfig has not > CONFIG_NXP_BOARD_REVISION set, and build is broken. Can you take a look > and resend patch with fixes ? I will fix and resend. Thanks ___ U-Boot mailing list U-Boot@lists.denx.de https://lists.denx.de/listinfo/u-boot