159189a8bSTim HarveyU-Boot for the Gateworks Ventana Product Family boards 259189a8bSTim Harvey 359189a8bSTim HarveyThis file contains information for the port of U-Boot to the Gateworks 459189a8bSTim HarveyVentana Product family boards. 559189a8bSTim Harvey 640e999caSTim HarveyThe entire Ventana product family (http://www.gateworks.com/product#ventana) 740e999caSTim Harveyis supported by a single bootloader build by using a common SPL and U-Boot 840e999caSTim Harveythat dynamically determines the characterstics of the board at runtime via 940e999caSTim Harveyinformation from an EEPROM on the board programmed at the factory and supports 1040e999caSTim Harveyall of the various boot mediums available. 1140e999caSTim Harvey 120cc11deaSTim Harvey1. Secondary Program Loader (SPL) 130cc11deaSTim Harvey--------------------------------- 140cc11deaSTim Harvey 150cc11deaSTim HarveyThe i.MX6 has a BOOT ROM PPL (Primary Program Loader) which supports loading 160cc11deaSTim Harveyan executable image from various boot devices. 170cc11deaSTim Harvey 180cc11deaSTim HarveyThe Gateworks Ventana board config uses an SPL build configuration. This 19a187559eSBin Mengwill build the following artifacts from U-Boot source: 200cc11deaSTim Harvey - SPL - Secondary Program Loader that the i.MX6 BOOT ROM (Primary Program 210cc11deaSTim Harvey Loader) boots. This detects CPU/DRAM configuration, configures 220cc11deaSTim Harvey The DRAM controller, loads u-boot.img from the detected boot device, 230cc11deaSTim Harvey and jumps to it. As this is booted from the PPL, it has an IVT/DCD 240cc11deaSTim Harvey table. 25a187559eSBin Meng - u-boot.img - The main U-Boot core which is u-boot.bin with a image header. 260cc11deaSTim Harvey 270cc11deaSTim Harvey 280cc11deaSTim Harvey2. Build 290cc11deaSTim Harvey-------- 300cc11deaSTim Harvey 310cc11deaSTim HarveyTo build U-Boot for the Gateworks Ventana product family: 320cc11deaSTim Harvey 330cc11deaSTim Harvey make gwventana_config 340cc11deaSTim Harvey make 350cc11deaSTim Harvey 360cc11deaSTim Harvey 3740e999caSTim Harvey3. Boot source: 3840e999caSTim Harvey--------------- 3940e999caSTim Harvey 4040e999caSTim HarveyThe Gateworks Ventana boards support booting from NAND or micro-SD depending 4140e999caSTim Harveyon the board model. The IMX6 BOOT ROM will choose a boot media based on eFUSE 4240e999caSTim Harveysettings programmed at the factory. 4340e999caSTim Harvey 4440e999caSTim HarveyBoards with NAND flash will always boot from NAND, and NAND-less boards will 4540e999caSTim Harveyalways boot from micro-SD. However, it is possible to use the U-Boot bmode 4640e999caSTim Harveycommand (or the technique it uses) to essentially bootstrap to another boot 4740e999caSTim Harveymedia at runtime. 4840e999caSTim Harvey 4940e999caSTim Harvey3.1. boot from NAND 5040e999caSTim Harvey------------------- 5159189a8bSTim Harvey 5259189a8bSTim HarveyThe i.MX6 BOOT ROM expects some structures that provide details of NAND layout 5359189a8bSTim Harveyand bad block information (referred to as 'bootstreams') which are replicated 540cc11deaSTim Harveymultiple times in NAND. The number of replications and their spacing (referred 550cc11deaSTim Harveyto as search stride) is configurable through board strapping options and/or 560cc11deaSTim HarveyeFUSE settings (BOOT_SEARCH_COUNT / Pages in block from BOOT_CFG2). In 570cc11deaSTim Harveyaddition, the i.MX6 BOOT ROM Flash Configuration Block (FCB) supports two 580cc11deaSTim Harveycopies of a bootloader in flash in the case that a bad block has corrupted one. 590cc11deaSTim HarveyThe Freescale 'kobs-ng' application from the Freescale LTIB BSP, which runs 600cc11deaSTim Harveyunder Linux and operates on an MTD partition, must be used to program the 610cc11deaSTim Harveybootstream in order to setup this flash structure correctly. 6259189a8bSTim Harvey 6359189a8bSTim HarveyThe Gateworks Ventana boards with NAND flash have been factory programmed 6459189a8bSTim Harveysuch that their eFUSE settings expect 2 copies of the boostream (this is 6559189a8bSTim Harveyspecified by providing kobs-ng with the --search_exponent=1 argument). Once in 660cc11deaSTim HarveyLinux with MTD support for the NAND on /dev/mtd0 you can program the SPL 6759189a8bSTim Harveywith: 6859189a8bSTim Harvey 690cc11deaSTim Harveykobs-ng init -v -x --search_exponent=1 SPL 7059189a8bSTim Harvey 710cc11deaSTim HarveyThe kobs-ng application uses an imximage which contains the Image Vector Table 720cc11deaSTim Harvey(IVT) and Device Configuration Data (DCD) structures that the i.MX6 BOOT ROM 730cc11deaSTim Harveyrequires to boot. The kobs-ng adds the Firmware Configuration Block (FCB) and 74a187559eSBin MengDiscovered Bad Block Table (DBBT). The SPL build artifact from U-Boot is 750cc11deaSTim Harveyan imximage. 760cc11deaSTim Harvey 77a187559eSBin MengThe u-boot.img, which is the non SPL U-Boot binary appended to a U-Boot image 780cc11deaSTim Harveyheader must be programmed in the NAND flash boot device at an offset hard 790cc11deaSTim Harveycoded in the SPL. For the Ventana boards, this has been chosen to be 14MB. 80a187559eSBin MengThe image can be programmed from either U-Boot or Linux: 810cc11deaSTim Harvey 82a187559eSBin MengU-Boot: 830cc11deaSTim HarveyVentana > setenv mtdparts mtdparts=nand:14m(spl),2m(uboot),1m(env),-(rootfs) 840cc11deaSTim HarveyVentana > tftp ${loadaddr} u-boot.img && nand erase.part uboot && \ 850cc11deaSTim Harvey nand write ${loadaddr} uboot ${filesize} 860cc11deaSTim Harvey 870cc11deaSTim HarveyLinux: 880cc11deaSTim Harveynandwrite /dev/mtd1 u-boot.img 890cc11deaSTim Harvey 900cc11deaSTim HarveyThe above assumes the default Ventana partitioning scheme which is configured 910cc11deaSTim Harveyvia the mtdparts env var: 920cc11deaSTim Harvey - spl: 14MB 930cc11deaSTim Harvey - uboot: 2M 940cc11deaSTim Harvey - env: 1M 950cc11deaSTim Harvey - rootfs: the rest 9659189a8bSTim Harvey 9759189a8bSTim HarveyThis information is taken from: 9840e999caSTim Harvey http://trac.gateworks.com/wiki/ventana/bootloader#nand 9940e999caSTim Harvey 10040e999caSTim HarveyMore details about the i.MX6 BOOT ROM can be found in the IMX6 reference manual. 10140e999caSTim Harvey 10240e999caSTim Harvey3.1. boot from micro-SD 10340e999caSTim Harvey----------------------- 10440e999caSTim Harvey 10540e999caSTim HarveyWhen the IMX6 eFUSE settings have been factory programmed to boot from 10640e999caSTim Harveymicro-SD the SPL will be loaded from offset 0x400 (1KB). Once the SPL is 107a187559eSBin Mengbooted, it will load and execute U-Boot (u-boot.img) from offset 69KB 10840e999caSTim Harveyon the micro-SD (defined by CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR). 10940e999caSTim Harvey 11040e999caSTim HarveyWhile it is technically possible to enable the SPL to be able to load 11140e999caSTim HarveyU-Boot from a file on a FAT/EXT filesystem on the micro-SD, we chose to 11240e999caSTim Harveyuse raw micro-SD access to keep the code-size and boot time of the SPL down. 11340e999caSTim Harvey 11440e999caSTim HarveyFor these reasons a micro-SD that will be used as an IMX6 primary boot 11540e999caSTim Harveydevice must be carefully partitioned and prepared. 11640e999caSTim Harvey 11740e999caSTim HarveyThe following shell commands are executed on a Linux host (adjust DEV to the 11840e999caSTim Harveyblock storage device of your micro-SD): 11940e999caSTim Harvey 12040e999caSTim Harvey DEV=/dev/sdc 12140e999caSTim Harvey # zero out 1MB of device 12240e999caSTim Harvey sudo dd if=/dev/zero of=$DEV count=1 bs=1M oflag=sync status=none && sync 12340e999caSTim Harvey # copy SPL to 1KB offset 12440e999caSTim Harvey sudo dd if=SPL of=$DEV bs=1K seek=1 oflag=sync status=none && sync 12540e999caSTim Harvey # copy U-Boot to 69KB offset 12640e999caSTim Harvey sudo dd if=u-boot.img of=$DEV bs=1K seek=69 oflag=sync status=none && sync 12740e999caSTim Harvey # create a partition table with a single rootfs partition starting at 1MB 12840e999caSTim Harvey printf "1,,L\n" | sudo sfdisk --in-order --no-reread -L -uM $DEV && sync 12940e999caSTim Harvey # format partition 13040e999caSTim Harvey sudo mkfs.ext4 -L root ${DEV}1 13140e999caSTim Harvey # mount the partition 13240e999caSTim Harvey sudo udisks --mount ${DEV}1 13340e999caSTim Harvey # extract filesystem 13440e999caSTim Harvey sudo tar xvf rootfs.tar.gz -C /media/root 13540e999caSTim Harvey # flush and unmount 13640e999caSTim Harvey sync && sudo umount /media/root 13740e999caSTim Harvey 13840e999caSTim HarveyThe above assumes the default Ventana micro-SD partitioning scheme 13940e999caSTim Harvey - spl : 1KB-69KB (68KB) required by IMX6 BOOT ROM 14040e999caSTim Harvey - uboot : 69KB-709KB (640KB) defined by 14140e999caSTim Harvey CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR 14240e999caSTim Harvey - env : 709KB-965KB (256KB) defined by 14340e999caSTim Harvey CONFIG_ENV_MMC_SIZE 14440e999caSTim Harvey CONFIG_ENV_MMC_OFFSET_REDUND 14540e999caSTim Harvey - rootfs : 1MB- 14640e999caSTim Harvey 14740e999caSTim HarveyThis information is taken from: 14840e999caSTim Harvey http://trac.gateworks.com/wiki/ventana/bootloader#microsd 14959189a8bSTim Harvey 15059189a8bSTim HarveyMore details about the i.MX6 BOOT ROM can be found in the IMX6 reference manual. 15159189a8bSTim Harvey 1526122f0d5STim Harvey4. Falcon Mode 1536122f0d5STim Harvey------------------------------ 1546122f0d5STim Harvey 1556122f0d5STim HarveyThe Gateworks Ventana board config enables Falcon mode (CONFIG_SPL_OS_BOOT) 1566122f0d5STim Harveywhich allows the SPL to boot directly to an OS instead of to U-Boot 1576122f0d5STim Harvey(u-boot.img) thus acheiving a faster overall boot time. The time savings 1586122f0d5STim Harveydepends on your boot medium (ie NAND Flash vs micro-SD) and size/storage 1596122f0d5STim Harveyof the OS. The time savings can be anywhere from 2 seconds (256MB NAND Flash 1606122f0d5STim Harveywith ~1MB kernel) to 6 seconds or more (2GB NAND Flash with ~6 kernel) 1616122f0d5STim Harvey 1626122f0d5STim HarveyThe Gateworks Ventana board supports Falcon mode for the following boot 1636122f0d5STim Harveymedium: 1646122f0d5STim Harvey - NAND flash 1656122f0d5STim Harvey - micro-SD 1666122f0d5STim Harvey 1676122f0d5STim HarveyFor all boot mediums, raw mode is used. While support of more complex storage 1686122f0d5STim Harveysuch as files on top of FAT/EXT filesystem is possible but not practical 1696122f0d5STim Harveyas the size of the SPL is fairly limitted (to 64KB based on the smallest 1706122f0d5STim Harveysize of available IMX6 iRAM) as well as the fact that this would increase 1716122f0d5STim HarveyOS load time which defeats the purpose of Falcon mode in the first place. 1726122f0d5STim Harvey 1736122f0d5STim HarveyThe SPL decides to boot either U-Boot (u-boot.img) or the OS (args + kernel) 1746122f0d5STim Harveybased on the return value of the spl_start_uboot() function. While often 1756122f0d5STim Harveythis can simply be the state of a GPIO based pushbutton or DIP switch, for 176*3c0fd17fSTim HarveyGateworks Ventana, we use an EEPROM register on i2c-0 at 0x50:0x00: 177*3c0fd17fSTim Harveyset to '0' will choose to boot to U-Boot and otherwise it will boot to OS. 1786122f0d5STim Harvey 1796122f0d5STim HarveyTo use Falcon mode it is required that you first 'prepare' the 'args' data 1806122f0d5STim Harveythat is stored on your boot medium along with the kernel (which can be any 1816122f0d5STim HarveyOS or bare-metal application). In the case of the Linux kernel the 'args' 1826122f0d5STim Harveyis the flatenned device-tree which normally gets altered prior to booting linux 1836122f0d5STim Harveyby U-Boot's 'bootm' command. To achieve this for SPL we use the 1846122f0d5STim Harvey'spl export fdt' command in U-Boot after loading the kernel and dtb which 1856122f0d5STim Harveywill go through the same process of modifying the device-tree for the board 1866122f0d5STim Harveybeing executed on but not jump to the kernel. This allows you to save the 1876122f0d5STim Harveyargs data to the location the SPL expects it and then enable Falcon mode. 1886122f0d5STim Harvey 1896122f0d5STim HarveyIt is important to realize that there are certain values in the dtb that 1906122f0d5STim Harveyare board model specific (IMX6Q vs IMX6DL for example) and board specific 1916122f0d5STim Harvey(board serial number, MAC addrs) so you do not want to use the 'args' 1926122f0d5STim Harveydata prepared from one board on another board. 1936122f0d5STim Harvey 1946122f0d5STim Harvey4.1. Falcon Mode on NAND flash 1956122f0d5STim Harvey------------------------------ 1966122f0d5STim HarveyTo prepare a Gateworks Ventana board that boots from NAND flash for Falcon 1976122f0d5STim Harveymode you must program your flash such that the 'args' and 'kernel' are 1986122f0d5STim Harveylocated where defined at compile time by the following: 1996122f0d5STim Harvey CONFIG_CMD_SPL_NAND_OFS 17MB - offset of 'args' 2006122f0d5STim Harvey CONFIG_SYS_NAND_SPL_KERNEL_OFFS 18MB - offset of 'kernel' 2016122f0d5STim Harvey 2026122f0d5STim HarveyThe location offsets defined above are defaults chosen by Gateworks and are 2036122f0d5STim Harveyflexible if you want to re-define them. 2046122f0d5STim Harvey 2056122f0d5STim HarveyThe following steps executed in U-Boot will configure Falcon mode for NAND 2066122f0d5STim Harveyusing rootfs (ubi), kernel (uImage), and dtb from the network: 2076122f0d5STim Harvey 2086122f0d5STim Harvey # change mtd partitions to the above mapping 2096122f0d5STim Harvey Ventana > setenv mtdparts 'mtdparts=nand:14m(spl),2m(uboot),1m(env),1m(args),10m(kernel),-(rootfs)' 2106122f0d5STim Harvey 2116122f0d5STim Harvey # flash rootfs (at 28MB) 2126122f0d5STim Harvey Ventana > tftp ${loadaddr} rootfs_${flash_layout}.ubi && \ 2136122f0d5STim Harvey nand erase.part rootfs && nand write ${loadaddr} rootfs ${filesize} 2146122f0d5STim Harvey 2156122f0d5STim Harvey # load the device-tree 2166122f0d5STim Harvey Ventana > tftp ${fdt_addr} ventana/${fdt_file2} 2176122f0d5STim Harvey 2186122f0d5STim Harvey # load the kernel 2196122f0d5STim Harvey Ventana > tftp ${loadaddr} ventana/uImage 2206122f0d5STim Harvey 2216122f0d5STim Harvey # flash kernel (at 18MB) 2226122f0d5STim Harvey Ventana > nand erase.part kernel && nand write ${loadaddr} kernel ${filesize} 2236122f0d5STim Harvey 2246122f0d5STim Harvey # set kernel args for the console and rootfs (used by spl export) 2256122f0d5STim Harvey Ventana > setenv bootargs 'console=ttymxc1,115200 root=ubi0:rootfs ubi.mtd=5 rootfstype=ubifs quiet' 2266122f0d5STim Harvey 2276122f0d5STim Harvey # create args based on env, board, EEPROM, and dtb 2286122f0d5STim Harvey Ventana > spl export fdt ${loadaddr} - ${fdt_addr} 2296122f0d5STim Harvey 2306122f0d5STim Harvey # flash args (at 17MB) 2316122f0d5STim Harvey Ventana > nand erase.part args && nand write 18000000 args 100000 2326122f0d5STim Harvey 233*3c0fd17fSTim Harvey # set i2c register 0x50:0x00=0 to boot to Linux 234*3c0fd17fSTim Harvey Ventana > i2c dev 0 && i2c mw 0x50 0x00.0 0 1 2356122f0d5STim Harvey 2366122f0d5STim HarveyBe sure to adjust 'bootargs' above to your OS needs (this will be different 2376122f0d5STim Harveyfor various distros such as OpenWrt, Yocto, Android, etc). You can use the 2386122f0d5STim Harveyvalue obtained from 'cat /proc/cmdline' when booted to Linux. 2396122f0d5STim Harvey 2406122f0d5STim HarveyThis information is taken from: 2416122f0d5STim Harvey http://trac.gateworks.com/wiki/ventana/bootloader/falcon-mode#nand 2426122f0d5STim Harvey 2436122f0d5STim Harvey 2446122f0d5STim Harvey4.2. Falcon Mode on micro-SD card 2456122f0d5STim Harvey--------------------------------- 2466122f0d5STim Harvey 2476122f0d5STim HarveyTo prepare a Gateworks Ventana board with a primary boot device of micro-SD 2486122f0d5STim Harveyyou first need to make sure you build U-Boot with CONFIG_ENV_IS_IN_MMC 2496122f0d5STim Harveyinstead of CONFIG_ENV_IS_IN_NAND. 2506122f0d5STim Harvey 2516122f0d5STim HarveyFor micro-SD based Falcon mode you must program your micro-SD such that 2526122f0d5STim Harveythe 'args' and 'kernel' are located where defined at compile time 2536122f0d5STim Harveyby the following: 2546122f0d5STim Harvey CONFIG_SYS_MMCSD_RAW_MODE_ARGS_SECTOR 0x800 (1MB) - offset of 'args' 2556122f0d5STim Harvey CONFIG_SYS_MMCSD_RAW_MODE_KERNEL_SECTOR 0x1000 (2MB) - offset of 'kernel' 2566122f0d5STim Harvey 2576122f0d5STim HarveyThe location offsets defined above are defaults chosen by Gateworks and are 2586122f0d5STim Harveyflexible if you want to re-define them. 2596122f0d5STim Harvey 2606122f0d5STim HarveyFirst you must prepare a micro-SD such that the SPL can be loaded by the 2616122f0d5STim HarveyIMX6 BOOT ROM (fixed offset of 1KB), and U-Boot can be loaded by the SPL 2626122f0d5STim Harvey(fixed offset of 69KB defined by CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR). 2636122f0d5STim Harvey 2646122f0d5STim HarveyThe following shell commands are executed on a Linux host (adjust DEV to the 2656122f0d5STim Harveyblock storage device of your micro-SD): 2666122f0d5STim Harvey 2676122f0d5STim Harvey DEV=/dev/sdc 2686122f0d5STim Harvey # zero out 1MB of device 2696122f0d5STim Harvey sudo dd if=/dev/zero of=$DEV count=1 bs=1M oflag=sync status=none && sync 2706122f0d5STim Harvey # copy SPL to 1KB offset 2716122f0d5STim Harvey sudo dd if=SPL of=$DEV bs=1K seek=1 oflag=sync status=none && sync 2726122f0d5STim Harvey # copy U-Boot to 69KB offset 2736122f0d5STim Harvey sudo dd if=u-boot.img of=$DEV bs=1K seek=69 oflag=sync status=none && sync 2746122f0d5STim Harvey # create a partition table with a single rootfs partition starting at 10MB 2756122f0d5STim Harvey printf "10,,L\n" | sudo sfdisk --in-order --no-reread -L -uM $DEV && sync 2766122f0d5STim Harvey # format partition 2776122f0d5STim Harvey sudo mkfs.ext4 -L root ${DEV}1 2786122f0d5STim Harvey # mount the partition 2796122f0d5STim Harvey sudo udisks --mount ${DEV}1 2806122f0d5STim Harvey # extract filesystem 2816122f0d5STim Harvey sudo tar xvf rootfs.tar.gz -C /media/root 2826122f0d5STim Harvey # flush and unmount 2836122f0d5STim Harvey sync && sudo umount /media/root 2846122f0d5STim Harvey 2856122f0d5STim HarveyNow that your micro-SD partitioning has been adjusted to leave room for the 2866122f0d5STim Harveyraw 'args' and 'kernel' data boot the board with the prepared micro-SD, break 2876122f0d5STim Harveyout in U-Boot and use the following to enable Falcon mode: 2886122f0d5STim Harvey 2896122f0d5STim Harvey # load device-tree from rootfs 2906122f0d5STim Harvey Ventana > ext2load mmc 0:1 ${fdt_addr} boot/${fdt_file2} 2916122f0d5STim Harvey 2926122f0d5STim Harvey # load kernel from rootfs 2936122f0d5STim Harvey Ventana > ext2load mmc 0:1 ${loadaddr} boot/uImage 2946122f0d5STim Harvey 2956122f0d5STim Harvey # write kernel at 2MB offset 2966122f0d5STim Harvey Ventana > mmc write ${loadaddr} 0x1000 0x4000 2976122f0d5STim Harvey 2986122f0d5STim Harvey # setup kernel bootargs 2996122f0d5STim Harvey Ventana > setenv bootargs 'console=ttymxc1,115200 root=/dev/mmcblk0p1 rootfstype=ext4 rootwait rw' 3006122f0d5STim Harvey 3016122f0d5STim Harvey # prepare args 3026122f0d5STim Harvey Ventana > spl export fdt ${loadaddr} - ${fdt_addr} 3036122f0d5STim Harvey 3046122f0d5STim Harvey # write args 1MB data (0x800 sectors) to 1MB offset (0x800 sectors) 3056122f0d5STim Harvey Ventana > mmc write 18000000 0x800 0x800 3066122f0d5STim Harvey 307*3c0fd17fSTim Harvey # set i2c register 0x50:0x00=0 to boot to Linux 308*3c0fd17fSTim Harvey Ventana > i2c dev 0 && i2c mw 0x50 0x00.0 0 1 3096122f0d5STim Harvey 3106122f0d5STim HarveyBe sure to adjust 'bootargs' above to your OS needs (this will be different 3116122f0d5STim Harveyfor various distros such as OpenWrt, Yocto, Android, etc). You can use the 3126122f0d5STim Harveyvalue obtained from 'cat /proc/cmdline' when booted to Linux. 3136122f0d5STim Harvey 3146122f0d5STim HarveyThis information is taken from: 3156122f0d5STim Harvey http://trac.gateworks.com/wiki/ventana/bootloader/falcon-mode#microsd 316