1*4882a593SmuzhiyunGeneric SPL framework 2*4882a593Smuzhiyun===================== 3*4882a593Smuzhiyun 4*4882a593SmuzhiyunOverview 5*4882a593Smuzhiyun-------- 6*4882a593Smuzhiyun 7*4882a593SmuzhiyunTo unify all existing implementations for a secondary program loader (SPL) 8*4882a593Smuzhiyunand to allow simply adding of new implementations this generic SPL framework 9*4882a593Smuzhiyunhas been created. With this framework almost all source files for a board 10*4882a593Smuzhiyuncan be reused. No code duplication or symlinking is necessary anymore. 11*4882a593Smuzhiyun 12*4882a593Smuzhiyun 13*4882a593SmuzhiyunHow it works 14*4882a593Smuzhiyun------------ 15*4882a593Smuzhiyun 16*4882a593SmuzhiyunThe object files for SPL are built separately and placed in the "spl" directory. 17*4882a593SmuzhiyunThe final binaries which are generated are u-boot-spl, u-boot-spl.bin and 18*4882a593Smuzhiyunu-boot-spl.map. 19*4882a593Smuzhiyun 20*4882a593SmuzhiyunA config option named CONFIG_SPL_BUILD is enabled by Kconfig for SPL. 21*4882a593SmuzhiyunSource files can therefore be compiled for SPL with different settings. 22*4882a593Smuzhiyun 23*4882a593SmuzhiyunFor example: 24*4882a593Smuzhiyun 25*4882a593Smuzhiyunifeq ($(CONFIG_SPL_BUILD),y) 26*4882a593Smuzhiyunobj-y += board_spl.o 27*4882a593Smuzhiyunelse 28*4882a593Smuzhiyunobj-y += board.o 29*4882a593Smuzhiyunendif 30*4882a593Smuzhiyun 31*4882a593Smuzhiyunobj-$(CONFIG_SPL_BUILD) += foo.o 32*4882a593Smuzhiyun 33*4882a593Smuzhiyun#ifdef CONFIG_SPL_BUILD 34*4882a593Smuzhiyun foo(); 35*4882a593Smuzhiyun#endif 36*4882a593Smuzhiyun 37*4882a593Smuzhiyun 38*4882a593SmuzhiyunThe building of SPL images can be enabled by CONFIG_SPL option in Kconfig. 39*4882a593Smuzhiyun 40*4882a593SmuzhiyunBecause SPL images normally have a different text base, one has to be 41*4882a593Smuzhiyunconfigured by defining CONFIG_SPL_TEXT_BASE. The linker script has to be 42*4882a593Smuzhiyundefined with CONFIG_SPL_LDSCRIPT. 43*4882a593Smuzhiyun 44*4882a593SmuzhiyunTo support generic U-Boot libraries and drivers in the SPL binary one can 45*4882a593Smuzhiyunoptionally define CONFIG_SPL_XXX_SUPPORT. Currently following options 46*4882a593Smuzhiyunare supported: 47*4882a593Smuzhiyun 48*4882a593SmuzhiyunCONFIG_SPL_LIBCOMMON_SUPPORT (common/libcommon.o) 49*4882a593SmuzhiyunCONFIG_SPL_LIBDISK_SUPPORT (disk/libdisk.o) 50*4882a593SmuzhiyunCONFIG_SPL_I2C_SUPPORT (drivers/i2c/libi2c.o) 51*4882a593SmuzhiyunCONFIG_SPL_GPIO_SUPPORT (drivers/gpio/libgpio.o) 52*4882a593SmuzhiyunCONFIG_SPL_MMC_SUPPORT (drivers/mmc/libmmc.o) 53*4882a593SmuzhiyunCONFIG_SPL_SERIAL_SUPPORT (drivers/serial/libserial.o) 54*4882a593SmuzhiyunCONFIG_SPL_SPI_FLASH_SUPPORT (drivers/mtd/spi/libspi_flash.o) 55*4882a593SmuzhiyunCONFIG_SPL_SPI_SUPPORT (drivers/spi/libspi.o) 56*4882a593SmuzhiyunCONFIG_SPL_FAT_SUPPORT (fs/fat/libfat.o) 57*4882a593SmuzhiyunCONFIG_SPL_EXT_SUPPORT 58*4882a593SmuzhiyunCONFIG_SPL_LIBGENERIC_SUPPORT (lib/libgeneric.o) 59*4882a593SmuzhiyunCONFIG_SPL_POWER_SUPPORT (drivers/power/libpower.o) 60*4882a593SmuzhiyunCONFIG_SPL_NAND_SUPPORT (drivers/mtd/nand/raw/libnand.o) 61*4882a593SmuzhiyunCONFIG_SPL_DRIVERS_MISC_SUPPORT (drivers/misc) 62*4882a593SmuzhiyunCONFIG_SPL_DMA_SUPPORT (drivers/dma/libdma.o) 63*4882a593SmuzhiyunCONFIG_SPL_POST_MEM_SUPPORT (post/drivers/memory.o) 64*4882a593SmuzhiyunCONFIG_SPL_NAND_LOAD (drivers/mtd/nand/raw/nand_spl_load.o) 65*4882a593SmuzhiyunCONFIG_SPL_SPI_LOAD (drivers/mtd/spi/spi_spl_load.o) 66*4882a593SmuzhiyunCONFIG_SPL_RAM_DEVICE (common/spl/spl.c) 67*4882a593SmuzhiyunCONFIG_SPL_WATCHDOG_SUPPORT (drivers/watchdog/libwatchdog.o) 68*4882a593Smuzhiyun 69*4882a593Smuzhiyun 70*4882a593SmuzhiyunDebugging 71*4882a593Smuzhiyun--------- 72*4882a593Smuzhiyun 73*4882a593SmuzhiyunWhen building SPL with DEBUG set you may also need to set CONFIG_PANIC_HANG 74*4882a593Smuzhiyunas in most cases do_reset is not defined within SPL. 75*4882a593Smuzhiyun 76*4882a593Smuzhiyun 77*4882a593SmuzhiyunEstimating stack usage 78*4882a593Smuzhiyun---------------------- 79*4882a593Smuzhiyun 80*4882a593SmuzhiyunWith gcc 4.6 (and later) and the use of GNU cflow it is possible to estimate 81*4882a593Smuzhiyunstack usage at various points in run sequence of SPL. The -fstack-usage option 82*4882a593Smuzhiyunto gcc will produce '.su' files (such as arch/arm/cpu/armv7/syslib.su) that 83*4882a593Smuzhiyunwill give stack usage information and cflow can construct program flow. 84*4882a593Smuzhiyun 85*4882a593SmuzhiyunMust have gcc 4.6 or later, which supports -fstack-usage 86*4882a593Smuzhiyun 87*4882a593Smuzhiyun1) Build normally 88*4882a593Smuzhiyun2) Perform the following shell command to generate a list of C files used in 89*4882a593SmuzhiyunSPL: 90*4882a593Smuzhiyun$ find spl -name '*.su' | sed -e 's:^spl/::' -e 's:[.]su$:.c:' > used-spl.list 91*4882a593Smuzhiyun3) Execute cflow: 92*4882a593Smuzhiyun$ cflow --main=board_init_r `cat used-spl.list` 2>&1 | $PAGER 93*4882a593Smuzhiyun 94*4882a593Smuzhiyuncflow will spit out a number of warnings as it does not parse 95*4882a593Smuzhiyunthe config files and picks functions based on #ifdef. Parsing the '.i' 96*4882a593Smuzhiyunfiles instead introduces another set of headaches. These warnings are 97*4882a593Smuzhiyunnot usually important to understanding the flow, however. 98