Proposal to add NAND-boot support for Sunxi SPL
Subsystems (4)
PATCH v3 1/1 Proposal to add NAND-boot support for Sunxi SPL
Hereby a v3 of the patches adding NAND support to SPL. Most noticably all the feedback has been addressed: tidy structs for NAND and DMA, timeouts on wait operations and more proper use of the CCU. Patches are marked RFC mostly because I'm still contemplating the implementation of a proper full NAND driver to be used with the existing UBI subsystem. This could mean some slight changes in structure to better accomodate code sharing between sunxi-nand for SPL and U-boot. If you wish you can merge the first three patches though, I expect them not to change any further.
Thanks for earlier feedback, and don't hesitate to let me know if anything else could be improved.
Cheers,
Roy
Signature · 6 lines
IMAGINE IT >> MAKE IT Meet us online at Twitter <http://twitter.com/ultimaker>, Facebook <http://facebook.com/ultimaker>, Google+ <http://google.com/+Ultimaker> www.ultimaker.com
PATCH v3 1/4 sunxi/nand: change BLOCK_SIZE in mksunxiboot to match NAND block size
From: Daniel Kochma?ski <[email protected]>
This change is necessary to calculate correct checksum for NAND boot. Works both for MMC and NAND. Without it BROM rejects boot image as invalid (bad checksum). (Changes block size from 0x200 to 0x2000).
V2: Document decision in source too
--- tools/mksunxiboot.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
tools/mksunxiboot.c +7 -1
@@ -65,7 +65,13 @@ int gen_check_sum(struct boot_file_head *head_p)#define SUN4I_SRAM_SIZE 0x7600/* 0x7748+ is used by BROM */ #define SRAM_LOAD_MAX_SIZE (SUN4I_SRAM_SIZE - sizeof(struct boot_file_head)) -#define BLOCK_SIZE 512 + +/* +* BROM (at least on A10 and A20) requires NAND-images to be explicitly aligned +* to a multiple of 8K, and rejects the image otherwise. MMC-images are fine +* with 512B blocks. To cater for both, align to the largest of the two. +*/ +#define BLOCK_SIZE 0x2000struct boot_img {struct boot_file_head header;
Signature · 12 lines
2.1.0 -- IMAGINE IT >> MAKE IT Meet us online at Twitter <http://twitter.com/ultimaker>, Facebook <http://facebook.com/ultimaker>, Google+ <http://google.com/+Ultimaker> www.ultimaker.com
PATCH v3 2/4 sunxi: Add DMA definitions
In reply to Roy Spliet--- arch/arm/include/asm/arch-sunxi/dma.h | 16 +++++++ arch/arm/include/asm/arch-sunxi/dma_sun4i.h | 68 +++++++++++++++++++++++++++++ 2 files changed, 84 insertions(+) create mode 100644 arch/arm/include/asm/arch-sunxi/dma.h create mode 100644 arch/arm/include/asm/arch-sunxi/dma_sun4i.h
arch/arm/include/asm/arch-sunxi/dma.h new file +16 -0
@@ -0,0 +1,16 @@ +/* +* (C) Copyright 2015 Roy Spliet <[email protected]> +* +* SPDX-License-Identifier: GPL-2.0+ +*/ + +#ifndef _SUNXI_DMA_H +#define _SUNXI_DMA_H + +#if defined(CONFIG_MACH_SUN4I ) || defined(CONFIG_MACH_SUN7I ) +#include <asm/arch/dma_sun4i.h> +#else +#error "DMA definition not available for this architecture" +#endif + +#endif /* _SUNXI_DMA_H */
arch/arm/include/asm/arch-sunxi/dma_sun4i.h new file +68 -0
68 lines not on this page · raw message
Signature · 12 lines
2.1.0 -- IMAGINE IT >> MAKE IT Meet us online at Twitter <http://twitter.com/ultimaker>, Facebook <http://facebook.com/ultimaker>, Google+ <http://google.com/+Ultimaker> www.ultimaker.com
PATCH v3 3/4 sunxi: Match sun4i nand clock name with sun6i
In reply to Roy Spliet--- arch/arm/include/asm/arch-sunxi/clock_sun4i.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm/include/asm/arch-sunxi/clock_sun4i.h +1 -1
@@ -39,7 +39,7 @@ struct sunxi_ccm_reg {u32 apb0_gate;/* 0x68 apb0 module clock gating */ u32 apb1_gate;/* 0x6c apb1 module clock gating */ u8 res4[0x10 ]; -u32 nand_sclk_cfg;/* 0x80 nand sub clock control */ +u32 nand0_clk_cfg;/* 0x80 nand sub clock control */ u32 ms_sclk_cfg;/* 0x84 memory stick sub clock control */ u32 sd0_clk_cfg;/* 0x88 sd0 clock control */ u32 sd1_clk_cfg;/* 0x8c sd1 clock control */
Signature · 12 lines
2.1.0 -- IMAGINE IT >> MAKE IT Meet us online at Twitter <http://twitter.com/ultimaker>, Facebook <http://facebook.com/ultimaker>, Google+ <http://google.com/+Ultimaker> www.ultimaker.com
PATCH v3 4/4 sunxi/nand: Add support for booting from internal NAND memory
In reply to Roy SplietFrom: Daniel Kochma?ski <[email protected]>
V2:
- Rename config option
- Move to separate driver
- fix DMA directly into RAM
- Many readability upgrades
- Drop R32 and W32 macros in favour of readl/writel respectively
- Use standard port controller methods for pinctl
- Make many NAND options semi-configurable
V3:
- Use proper structs and definitions for DMA and NAND
- Fix bug wrt. page size selection
- Add time-out to waits
--- arch/arm/cpu/armv7/sunxi/board.c | 12 +- arch/arm/include/asm/arch-sunxi/gpio.h | 2 + arch/arm/include/asm/arch-sunxi/nand.h | 67 +++++++++ board/sunxi/Kconfig | 12 ++ board/sunxi/board.c | 16 ++ drivers/mtd/nand/Makefile | 1 + drivers/mtd/nand/sunxi_nand_spl.c | 268 +++++++++++++++++++++++++++++++++ include/configs/sun4i.h | 1 + include/configs/sun5i.h | 3 + include/configs/sun7i.h | 2 + include/configs/sun8i.h | 6 + include/configs/sunxi-common.h | 20 +++ 12 files changed, 408 insertions(+), 2 deletions(-) create mode 100644 arch/arm/include/asm/arch-sunxi/nand.h create mode 100644 drivers/mtd/nand/sunxi_nand_spl.c
arch/arm/cpu/armv7/sunxi/board.c +10 -2
@@ -111,8 +111,10 @@ void s_init(void)#ifdef CONFIG_SPL_BUILD /* The sunxi internal brom will try to loader external bootloader * from mmc0, nand flash, mmc2. -* Unfortunately we can't check how SPL was loaded so assume -* it's always the first SD/MMC controller +* +* Unfortunately we can't check how SPL was loaded so assume it's +* always the first SD/MMC controller, unless it was explicitly +* stated that SPL is on nand flash. */ u32 spl_boot_device (void ) {
@@ -122,6 +124,12 @@ u32 spl_boot_device(void)* enabled build. It has many restrictions and can only boot over USB. */ return BOOT_DEVICE_BOARD ; +#elif defined(CONFIG_SPL_NAND_SUPPORT ) +/* +* This is compile time configuration informing SPL, that it +* was loaded from nand flash. +*/ +return BOOT_DEVICE_NAND ;#else /* * When booting from the SD card, the "eGON.BT0" signature is expected
arch/arm/include/asm/arch-sunxi/gpio.h +2 -0
@@ -156,6 +156,8 @@ enum sunxi_gpio_number {#define SUN4I_GPB_UART0 2#define SUN5I_GPB_UART0 2 +#define SUNXI_GPC_NAND 2 +#define SUNXI_GPC_SDC2 3#define SUN6I_GPC_SDC3 4
arch/arm/include/asm/arch-sunxi/nand.h new file +67 -0
67 lines not on this page · raw message
board/sunxi/Kconfig +12 -0
@@ -269,6 +269,18 @@ config MMC_SUNXI_SLOT_EXTRA slot or emmc on mmc1 - mmc3. Setting this to 1, 2 or 3 will enable support for this. +config SPL_NAND_SUPPORT + bool "SPL/NAND mode support" + depends on SPL + default n + ---help--- + This enables support for booting from NAND internal + memory. U-Boot SPL doesn't detect where is it load from, + therefore this option is needed to properly load image from + flash. Option also disables MMC functionality on U-Boot due to + initialization errors encountered, when both controllers are + enabled. + config USB0_VBUS_PIN string "Vbus enable pin for usb0 (otg)" default ""
board/sunxi/board.c +16 -0
@@ -22,6 +22,9 @@#ifdef CONFIG_AXP221_POWER #include <axp221.h> #endif +#ifdef CONFIG_NAND_SUNXI +#include <nand.h> +#endif #include <asm/arch/clock.h> #include <asm/arch/cpu.h> #include <asm/arch/display.h>
@@ -315,6 +318,19 @@ int board_mmc_init(bd_t *bis) }#endif +void board_nand_init (void ) +{ +unsigned int pin; +static u8 ports[] =CONFIG_NAND_SUNXI_GPC_PORTS ; + +/* Configure AHB muxes to connect output pins with NAND controller */ +for (pin =0 ; pin <16 ; pin++) +sunxi_gpio_set_cfgpin (SUNXI_GPC (pin),SUNXI_GPC_NAND ); + +for (pin =0 ; pin <ARRAY_SIZE (ports); pin++) +sunxi_gpio_set_cfgpin (SUNXI_GPC (ports[pin]),SUNXI_GPC_NAND ); +} +void i2c_init_board (void ) {#ifdef CONFIG_I2C0_ENABLE
drivers/mtd/nand/Makefile +1 -0
@@ -73,5 +73,6 @@ obj-$(CONFIG_NAND_FSL_ELBC) += fsl_elbc_spl.o obj-$(CONFIG_NAND_FSL_IFC) += fsl_ifc_spl.o obj-$(CONFIG_NAND_MXC) += mxc_nand_spl.o obj-$(CONFIG_NAND_MXS) += mxs_nand_spl.o mxs_nand.o +obj-$(CONFIG_NAND_SUNXI) += sunxi_nand_spl.o endif # drivers
drivers/mtd/nand/sunxi_nand_spl.c new file +268 -0
268 lines not on this page · raw message
include/configs/sun4i.h +1 -0
@@ -18,6 +18,7 @@#endif #define CONFIG_SUNXI_USB_PHYS 3 +#define CONFIG_NAND_SUNXI_GPC_PORTS {16, 17, 18, 19, 20, 21, 22, 24}/* * Include common sunxi configuration where most the settings are
include/configs/sun5i.h +3 -0
@@ -19,6 +19,9 @@#define CONFIG_SUNXI_USB_PHYS 2 +/* \todo A13 only defines port 19, whereas A10s requires each of these */ +#define CONFIG_NAND_SUNXI_GPC_PORTS {16, 17, 18, 19} +/* * Include common sunxi configuration where most the settings are */
include/configs/sun7i.h +2 -0
@@ -24,6 +24,8 @@#define CONFIG_ARMV7_SECURE_BASE SUNXI_SRAM_B_BASE#define CONFIG_TIMER_CLK_FREQ 24000000 +#define CONFIG_NAND_SUNXI_GPC_PORTS {16, 17, 18, 19, 20, 21, 22, 24} +/* * Include common sunxi configuration where most the settings are */
include/configs/sun8i.h +6 -0
@@ -20,6 +20,12 @@#define CONFIG_SUNXI_USB_PHYS 2 +#if defined(CONFIG_MACH_SUN8I_A23 ) +#define CONFIG_NAND_SUNXI_GPC_PORTS {16, 17, 18} +#elif defined(CONFIG_MACH_SUN8I_A33 ) +#define CONFIG_NAND_SUNXI_GPC_PORTS {16} +#endif +/* * Include common sunxi configuration where most the settings are */
include/configs/sunxi-common.h +20 -0
@@ -106,8 +106,10 @@#define CONFIG_CMD_MMC #define CONFIG_MMC_SUNXI #define CONFIG_MMC_SUNXI_SLOT 0 +#if !defined(CONFIG_SPL_NAND_SUPPORT )#define CONFIG_ENV_IS_IN_MMC #define CONFIG_SYS_MMC_ENV_DEV 0/* first detected MMC controller */ +#endif /* CONFIG_SPL_NAND_SUPPORT */ #endif /* 4MB of malloc() pool */
@@ -324,6 +326,24 @@ extern int soft_i2c_gpio_scl;#define CONFIG_ENV_IS_NOWHERE #endif +#ifdef CONFIG_SPL_NAND_SUPPORT +#define CONFIG_NAND +#define CONFIG_SYS_NAND_SELF_INIT +#define CONFIG_NAND_SUNXI +#define CONFIG_CMD_SPL_WRITE_SIZE 0x000400 +#define CONFIG_SYS_NAND_U_BOOT_OFFS 0x008000 + +/* \todo Make these parameterisable in kernel config ? */ +#define CONFIG_NAND_SUNXI_PAGE_SIZE 8192 +#define CONFIG_NAND_SUNXI_ECC_STEP 1024 +#define CONFIG_NAND_SUNXI_ECC_STRENGTH 40 +#define CONFIG_NAND_SUNXI_ADDR_CYCLES 5 + +#ifndef CONFIG_NAND_SUNXI_GPC_PORTS +#error "No NAND GPC ports defined, NAND unsupported" +#endif +#endif /* CONFIG_SPL_NAND_SUPPORT */ +#define CONFIG_MISC_INIT_R #define CONFIG_SYS_CONSOLE_IS_IN_ENV
Signature · 12 lines
2.1.0 -- IMAGINE IT >> MAKE IT Meet us online at Twitter <http://twitter.com/ultimaker>, Facebook <http://facebook.com/ultimaker>, Google+ <http://google.com/+Ultimaker> www.ultimaker.com