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 33*d883fcc6STim HarveyFor NAND FLASH based boards: 34*d883fcc6STim Harvey make gwventana_nand_config 35*d883fcc6STim Harvey make 36*d883fcc6STim Harvey 37*d883fcc6STim HarveyFor EMMC FLASH based boards: 38*d883fcc6STim Harvey make gwventana_emmc_config 390cc11deaSTim Harvey make 400cc11deaSTim Harvey 410cc11deaSTim Harvey 4240e999caSTim Harvey3. Boot source: 4340e999caSTim Harvey--------------- 4440e999caSTim Harvey 4540e999caSTim HarveyThe Gateworks Ventana boards support booting from NAND or micro-SD depending 4640e999caSTim Harveyon the board model. The IMX6 BOOT ROM will choose a boot media based on eFUSE 4740e999caSTim Harveysettings programmed at the factory. 4840e999caSTim Harvey 4940e999caSTim HarveyBoards with NAND flash will always boot from NAND, and NAND-less boards will 5040e999caSTim Harveyalways boot from micro-SD. However, it is possible to use the U-Boot bmode 5140e999caSTim Harveycommand (or the technique it uses) to essentially bootstrap to another boot 5240e999caSTim Harveymedia at runtime. 5340e999caSTim Harvey 5440e999caSTim Harvey3.1. boot from NAND 5540e999caSTim Harvey------------------- 5659189a8bSTim Harvey 5759189a8bSTim HarveyThe i.MX6 BOOT ROM expects some structures that provide details of NAND layout 5859189a8bSTim Harveyand bad block information (referred to as 'bootstreams') which are replicated 590cc11deaSTim Harveymultiple times in NAND. The number of replications and their spacing (referred 600cc11deaSTim Harveyto as search stride) is configurable through board strapping options and/or 610cc11deaSTim HarveyeFUSE settings (BOOT_SEARCH_COUNT / Pages in block from BOOT_CFG2). In 620cc11deaSTim Harveyaddition, the i.MX6 BOOT ROM Flash Configuration Block (FCB) supports two 630cc11deaSTim Harveycopies of a bootloader in flash in the case that a bad block has corrupted one. 640cc11deaSTim HarveyThe Freescale 'kobs-ng' application from the Freescale LTIB BSP, which runs 650cc11deaSTim Harveyunder Linux and operates on an MTD partition, must be used to program the 660cc11deaSTim Harveybootstream in order to setup this flash structure correctly. 6759189a8bSTim Harvey 6859189a8bSTim HarveyThe Gateworks Ventana boards with NAND flash have been factory programmed 6959189a8bSTim Harveysuch that their eFUSE settings expect 2 copies of the boostream (this is 7059189a8bSTim Harveyspecified by providing kobs-ng with the --search_exponent=1 argument). Once in 710cc11deaSTim HarveyLinux with MTD support for the NAND on /dev/mtd0 you can program the SPL 7259189a8bSTim Harveywith: 7359189a8bSTim Harvey 740cc11deaSTim Harveykobs-ng init -v -x --search_exponent=1 SPL 7559189a8bSTim Harvey 760cc11deaSTim HarveyThe kobs-ng application uses an imximage which contains the Image Vector Table 770cc11deaSTim Harvey(IVT) and Device Configuration Data (DCD) structures that the i.MX6 BOOT ROM 780cc11deaSTim Harveyrequires to boot. The kobs-ng adds the Firmware Configuration Block (FCB) and 79a187559eSBin MengDiscovered Bad Block Table (DBBT). The SPL build artifact from U-Boot is 800cc11deaSTim Harveyan imximage. 810cc11deaSTim Harvey 82a187559eSBin MengThe u-boot.img, which is the non SPL U-Boot binary appended to a U-Boot image 830cc11deaSTim Harveyheader must be programmed in the NAND flash boot device at an offset hard 840cc11deaSTim Harveycoded in the SPL. For the Ventana boards, this has been chosen to be 14MB. 85a187559eSBin MengThe image can be programmed from either U-Boot or Linux: 860cc11deaSTim Harvey 87a187559eSBin MengU-Boot: 880cc11deaSTim HarveyVentana > setenv mtdparts mtdparts=nand:14m(spl),2m(uboot),1m(env),-(rootfs) 890cc11deaSTim HarveyVentana > tftp ${loadaddr} u-boot.img && nand erase.part uboot && \ 900cc11deaSTim Harvey nand write ${loadaddr} uboot ${filesize} 910cc11deaSTim Harvey 920cc11deaSTim HarveyLinux: 930cc11deaSTim Harveynandwrite /dev/mtd1 u-boot.img 940cc11deaSTim Harvey 950cc11deaSTim HarveyThe above assumes the default Ventana partitioning scheme which is configured 960cc11deaSTim Harveyvia the mtdparts env var: 970cc11deaSTim Harvey - spl: 14MB 980cc11deaSTim Harvey - uboot: 2M 990cc11deaSTim Harvey - env: 1M 1000cc11deaSTim Harvey - rootfs: the rest 10159189a8bSTim Harvey 10259189a8bSTim HarveyThis information is taken from: 10340e999caSTim Harvey http://trac.gateworks.com/wiki/ventana/bootloader#nand 10440e999caSTim Harvey 10540e999caSTim HarveyMore details about the i.MX6 BOOT ROM can be found in the IMX6 reference manual. 10640e999caSTim Harvey 107*d883fcc6STim Harvey3.1. boot from MMC (eMMC/microSD) 108*d883fcc6STim Harvey--------------------------------- 10940e999caSTim Harvey 11040e999caSTim HarveyWhen the IMX6 eFUSE settings have been factory programmed to boot from 111*d883fcc6STim HarveyMMC the SPL will be loaded from offset 0x400 (1KB). Once the SPL is 112a187559eSBin Mengbooted, it will load and execute U-Boot (u-boot.img) from offset 69KB 11340e999caSTim Harveyon the micro-SD (defined by CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR). 11440e999caSTim Harvey 11540e999caSTim HarveyWhile it is technically possible to enable the SPL to be able to load 11640e999caSTim HarveyU-Boot from a file on a FAT/EXT filesystem on the micro-SD, we chose to 11740e999caSTim Harveyuse raw micro-SD access to keep the code-size and boot time of the SPL down. 11840e999caSTim Harvey 119*d883fcc6STim HarveyFor these reasons an MMC device that will be used as an IMX6 primary boot 12040e999caSTim Harveydevice must be carefully partitioned and prepared. 12140e999caSTim Harvey 12240e999caSTim HarveyThe following shell commands are executed on a Linux host (adjust DEV to the 123*d883fcc6STim Harveyblock storage device of your MMC, ie /dev/mmcblk0): 12440e999caSTim Harvey 12540e999caSTim Harvey DEV=/dev/sdc 12640e999caSTim Harvey # zero out 1MB of device 12740e999caSTim Harvey sudo dd if=/dev/zero of=$DEV count=1 bs=1M oflag=sync status=none && sync 12840e999caSTim Harvey # copy SPL to 1KB offset 12940e999caSTim Harvey sudo dd if=SPL of=$DEV bs=1K seek=1 oflag=sync status=none && sync 13040e999caSTim Harvey # copy U-Boot to 69KB offset 13140e999caSTim Harvey sudo dd if=u-boot.img of=$DEV bs=1K seek=69 oflag=sync status=none && sync 13240e999caSTim Harvey # create a partition table with a single rootfs partition starting at 1MB 13340e999caSTim Harvey printf "1,,L\n" | sudo sfdisk --in-order --no-reread -L -uM $DEV && sync 13440e999caSTim Harvey # format partition 13540e999caSTim Harvey sudo mkfs.ext4 -L root ${DEV}1 13640e999caSTim Harvey # mount the partition 13740e999caSTim Harvey sudo udisks --mount ${DEV}1 13840e999caSTim Harvey # extract filesystem 13940e999caSTim Harvey sudo tar xvf rootfs.tar.gz -C /media/root 14040e999caSTim Harvey # flush and unmount 14140e999caSTim Harvey sync && sudo umount /media/root 14240e999caSTim Harvey 14340e999caSTim HarveyThe above assumes the default Ventana micro-SD partitioning scheme 14440e999caSTim Harvey - spl : 1KB-69KB (68KB) required by IMX6 BOOT ROM 14540e999caSTim Harvey - uboot : 69KB-709KB (640KB) defined by 14640e999caSTim Harvey CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR 14740e999caSTim Harvey - env : 709KB-965KB (256KB) defined by 14840e999caSTim Harvey CONFIG_ENV_MMC_SIZE 14940e999caSTim Harvey CONFIG_ENV_MMC_OFFSET_REDUND 15040e999caSTim Harvey - rootfs : 1MB- 15140e999caSTim Harvey 15240e999caSTim HarveyThis information is taken from: 15340e999caSTim Harvey http://trac.gateworks.com/wiki/ventana/bootloader#microsd 15459189a8bSTim Harvey 15559189a8bSTim HarveyMore details about the i.MX6 BOOT ROM can be found in the IMX6 reference manual. 15659189a8bSTim Harvey 1576122f0d5STim Harvey4. Falcon Mode 1586122f0d5STim Harvey------------------------------ 1596122f0d5STim Harvey 1606122f0d5STim HarveyThe Gateworks Ventana board config enables Falcon mode (CONFIG_SPL_OS_BOOT) 1616122f0d5STim Harveywhich allows the SPL to boot directly to an OS instead of to U-Boot 1626122f0d5STim Harvey(u-boot.img) thus acheiving a faster overall boot time. The time savings 1636122f0d5STim Harveydepends on your boot medium (ie NAND Flash vs micro-SD) and size/storage 1646122f0d5STim Harveyof the OS. The time savings can be anywhere from 2 seconds (256MB NAND Flash 1656122f0d5STim Harveywith ~1MB kernel) to 6 seconds or more (2GB NAND Flash with ~6 kernel) 1666122f0d5STim Harvey 1676122f0d5STim HarveyThe Gateworks Ventana board supports Falcon mode for the following boot 1686122f0d5STim Harveymedium: 1696122f0d5STim Harvey - NAND flash 1706122f0d5STim Harvey - micro-SD 1716122f0d5STim Harvey 1726122f0d5STim HarveyFor all boot mediums, raw mode is used. While support of more complex storage 1736122f0d5STim Harveysuch as files on top of FAT/EXT filesystem is possible but not practical 1746122f0d5STim Harveyas the size of the SPL is fairly limitted (to 64KB based on the smallest 1756122f0d5STim Harveysize of available IMX6 iRAM) as well as the fact that this would increase 1766122f0d5STim HarveyOS load time which defeats the purpose of Falcon mode in the first place. 1776122f0d5STim Harvey 1786122f0d5STim HarveyThe SPL decides to boot either U-Boot (u-boot.img) or the OS (args + kernel) 1796122f0d5STim Harveybased on the return value of the spl_start_uboot() function. While often 1806122f0d5STim Harveythis can simply be the state of a GPIO based pushbutton or DIP switch, for 1813c0fd17fSTim HarveyGateworks Ventana, we use an EEPROM register on i2c-0 at 0x50:0x00: 1823c0fd17fSTim Harveyset to '0' will choose to boot to U-Boot and otherwise it will boot to OS. 1836122f0d5STim Harvey 1846122f0d5STim HarveyTo use Falcon mode it is required that you first 'prepare' the 'args' data 1856122f0d5STim Harveythat is stored on your boot medium along with the kernel (which can be any 1866122f0d5STim HarveyOS or bare-metal application). In the case of the Linux kernel the 'args' 1876122f0d5STim Harveyis the flatenned device-tree which normally gets altered prior to booting linux 1886122f0d5STim Harveyby U-Boot's 'bootm' command. To achieve this for SPL we use the 1896122f0d5STim Harvey'spl export fdt' command in U-Boot after loading the kernel and dtb which 1906122f0d5STim Harveywill go through the same process of modifying the device-tree for the board 1916122f0d5STim Harveybeing executed on but not jump to the kernel. This allows you to save the 1926122f0d5STim Harveyargs data to the location the SPL expects it and then enable Falcon mode. 1936122f0d5STim Harvey 1946122f0d5STim HarveyIt is important to realize that there are certain values in the dtb that 1956122f0d5STim Harveyare board model specific (IMX6Q vs IMX6DL for example) and board specific 1966122f0d5STim Harvey(board serial number, MAC addrs) so you do not want to use the 'args' 1976122f0d5STim Harveydata prepared from one board on another board. 1986122f0d5STim Harvey 1996122f0d5STim Harvey4.1. Falcon Mode on NAND flash 2006122f0d5STim Harvey------------------------------ 2016122f0d5STim HarveyTo prepare a Gateworks Ventana board that boots from NAND flash for Falcon 2026122f0d5STim Harveymode you must program your flash such that the 'args' and 'kernel' are 2036122f0d5STim Harveylocated where defined at compile time by the following: 2046122f0d5STim Harvey CONFIG_CMD_SPL_NAND_OFS 17MB - offset of 'args' 2056122f0d5STim Harvey CONFIG_SYS_NAND_SPL_KERNEL_OFFS 18MB - offset of 'kernel' 2066122f0d5STim Harvey 2076122f0d5STim HarveyThe location offsets defined above are defaults chosen by Gateworks and are 2086122f0d5STim Harveyflexible if you want to re-define them. 2096122f0d5STim Harvey 2106122f0d5STim HarveyThe following steps executed in U-Boot will configure Falcon mode for NAND 2116122f0d5STim Harveyusing rootfs (ubi), kernel (uImage), and dtb from the network: 2126122f0d5STim Harvey 2136122f0d5STim Harvey # change mtd partitions to the above mapping 2146122f0d5STim Harvey Ventana > setenv mtdparts 'mtdparts=nand:14m(spl),2m(uboot),1m(env),1m(args),10m(kernel),-(rootfs)' 2156122f0d5STim Harvey 2166122f0d5STim Harvey # flash rootfs (at 28MB) 2176122f0d5STim Harvey Ventana > tftp ${loadaddr} rootfs_${flash_layout}.ubi && \ 2186122f0d5STim Harvey nand erase.part rootfs && nand write ${loadaddr} rootfs ${filesize} 2196122f0d5STim Harvey 2206122f0d5STim Harvey # load the device-tree 2216122f0d5STim Harvey Ventana > tftp ${fdt_addr} ventana/${fdt_file2} 2226122f0d5STim Harvey 2236122f0d5STim Harvey # load the kernel 2246122f0d5STim Harvey Ventana > tftp ${loadaddr} ventana/uImage 2256122f0d5STim Harvey 2266122f0d5STim Harvey # flash kernel (at 18MB) 2276122f0d5STim Harvey Ventana > nand erase.part kernel && nand write ${loadaddr} kernel ${filesize} 2286122f0d5STim Harvey 2296122f0d5STim Harvey # set kernel args for the console and rootfs (used by spl export) 2306122f0d5STim Harvey Ventana > setenv bootargs 'console=ttymxc1,115200 root=ubi0:rootfs ubi.mtd=5 rootfstype=ubifs quiet' 2316122f0d5STim Harvey 2326122f0d5STim Harvey # create args based on env, board, EEPROM, and dtb 2336122f0d5STim Harvey Ventana > spl export fdt ${loadaddr} - ${fdt_addr} 2346122f0d5STim Harvey 2356122f0d5STim Harvey # flash args (at 17MB) 2366122f0d5STim Harvey Ventana > nand erase.part args && nand write 18000000 args 100000 2376122f0d5STim Harvey 2383c0fd17fSTim Harvey # set i2c register 0x50:0x00=0 to boot to Linux 2393c0fd17fSTim Harvey Ventana > i2c dev 0 && i2c mw 0x50 0x00.0 0 1 2406122f0d5STim Harvey 2416122f0d5STim HarveyBe sure to adjust 'bootargs' above to your OS needs (this will be different 2426122f0d5STim Harveyfor various distros such as OpenWrt, Yocto, Android, etc). You can use the 2436122f0d5STim Harveyvalue obtained from 'cat /proc/cmdline' when booted to Linux. 2446122f0d5STim Harvey 2456122f0d5STim HarveyThis information is taken from: 2466122f0d5STim Harvey http://trac.gateworks.com/wiki/ventana/bootloader/falcon-mode#nand 2476122f0d5STim Harvey 2486122f0d5STim Harvey 2496122f0d5STim Harvey4.2. Falcon Mode on micro-SD card 2506122f0d5STim Harvey--------------------------------- 2516122f0d5STim Harvey 2526122f0d5STim HarveyTo prepare a Gateworks Ventana board with a primary boot device of micro-SD 2536122f0d5STim Harveyyou first need to make sure you build U-Boot with CONFIG_ENV_IS_IN_MMC 2546122f0d5STim Harveyinstead of CONFIG_ENV_IS_IN_NAND. 2556122f0d5STim Harvey 2566122f0d5STim HarveyFor micro-SD based Falcon mode you must program your micro-SD such that 2576122f0d5STim Harveythe 'args' and 'kernel' are located where defined at compile time 2586122f0d5STim Harveyby the following: 2596122f0d5STim Harvey CONFIG_SYS_MMCSD_RAW_MODE_ARGS_SECTOR 0x800 (1MB) - offset of 'args' 2606122f0d5STim Harvey CONFIG_SYS_MMCSD_RAW_MODE_KERNEL_SECTOR 0x1000 (2MB) - offset of 'kernel' 2616122f0d5STim Harvey 2626122f0d5STim HarveyThe location offsets defined above are defaults chosen by Gateworks and are 2636122f0d5STim Harveyflexible if you want to re-define them. 2646122f0d5STim Harvey 2656122f0d5STim HarveyFirst you must prepare a micro-SD such that the SPL can be loaded by the 2666122f0d5STim HarveyIMX6 BOOT ROM (fixed offset of 1KB), and U-Boot can be loaded by the SPL 2676122f0d5STim Harvey(fixed offset of 69KB defined by CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR). 2686122f0d5STim Harvey 2696122f0d5STim HarveyThe following shell commands are executed on a Linux host (adjust DEV to the 2706122f0d5STim Harveyblock storage device of your micro-SD): 2716122f0d5STim Harvey 2726122f0d5STim Harvey DEV=/dev/sdc 2736122f0d5STim Harvey # zero out 1MB of device 2746122f0d5STim Harvey sudo dd if=/dev/zero of=$DEV count=1 bs=1M oflag=sync status=none && sync 2756122f0d5STim Harvey # copy SPL to 1KB offset 2766122f0d5STim Harvey sudo dd if=SPL of=$DEV bs=1K seek=1 oflag=sync status=none && sync 2776122f0d5STim Harvey # copy U-Boot to 69KB offset 2786122f0d5STim Harvey sudo dd if=u-boot.img of=$DEV bs=1K seek=69 oflag=sync status=none && sync 2796122f0d5STim Harvey # create a partition table with a single rootfs partition starting at 10MB 2806122f0d5STim Harvey printf "10,,L\n" | sudo sfdisk --in-order --no-reread -L -uM $DEV && sync 2816122f0d5STim Harvey # format partition 2826122f0d5STim Harvey sudo mkfs.ext4 -L root ${DEV}1 2836122f0d5STim Harvey # mount the partition 2846122f0d5STim Harvey sudo udisks --mount ${DEV}1 2856122f0d5STim Harvey # extract filesystem 2866122f0d5STim Harvey sudo tar xvf rootfs.tar.gz -C /media/root 2876122f0d5STim Harvey # flush and unmount 2886122f0d5STim Harvey sync && sudo umount /media/root 2896122f0d5STim Harvey 2906122f0d5STim HarveyNow that your micro-SD partitioning has been adjusted to leave room for the 2916122f0d5STim Harveyraw 'args' and 'kernel' data boot the board with the prepared micro-SD, break 2926122f0d5STim Harveyout in U-Boot and use the following to enable Falcon mode: 2936122f0d5STim Harvey 2946122f0d5STim Harvey # load device-tree from rootfs 2956122f0d5STim Harvey Ventana > ext2load mmc 0:1 ${fdt_addr} boot/${fdt_file2} 2966122f0d5STim Harvey 2976122f0d5STim Harvey # load kernel from rootfs 2986122f0d5STim Harvey Ventana > ext2load mmc 0:1 ${loadaddr} boot/uImage 2996122f0d5STim Harvey 3006122f0d5STim Harvey # write kernel at 2MB offset 3016122f0d5STim Harvey Ventana > mmc write ${loadaddr} 0x1000 0x4000 3026122f0d5STim Harvey 3036122f0d5STim Harvey # setup kernel bootargs 3046122f0d5STim Harvey Ventana > setenv bootargs 'console=ttymxc1,115200 root=/dev/mmcblk0p1 rootfstype=ext4 rootwait rw' 3056122f0d5STim Harvey 3066122f0d5STim Harvey # prepare args 3076122f0d5STim Harvey Ventana > spl export fdt ${loadaddr} - ${fdt_addr} 3086122f0d5STim Harvey 3096122f0d5STim Harvey # write args 1MB data (0x800 sectors) to 1MB offset (0x800 sectors) 3106122f0d5STim Harvey Ventana > mmc write 18000000 0x800 0x800 3116122f0d5STim Harvey 3123c0fd17fSTim Harvey # set i2c register 0x50:0x00=0 to boot to Linux 3133c0fd17fSTim Harvey Ventana > i2c dev 0 && i2c mw 0x50 0x00.0 0 1 3146122f0d5STim Harvey 3156122f0d5STim HarveyBe sure to adjust 'bootargs' above to your OS needs (this will be different 3166122f0d5STim Harveyfor various distros such as OpenWrt, Yocto, Android, etc). You can use the 3176122f0d5STim Harveyvalue obtained from 'cat /proc/cmdline' when booted to Linux. 3186122f0d5STim Harvey 3196122f0d5STim HarveyThis information is taken from: 3206122f0d5STim Harvey http://trac.gateworks.com/wiki/ventana/bootloader/falcon-mode#microsd 321