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
190cc11deaSTim Harveywill 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.
250cc11deaSTim Harvey - 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
740cc11deaSTim HarveyDiscovered Bad Block Table (DBBT).  The SPL build artifact from u-boot is
750cc11deaSTim Harveyan imximage.
760cc11deaSTim Harvey
770cc11deaSTim HarveyThe 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.
800cc11deaSTim HarveyThe image can be programmed from either u-boot or Linux:
810cc11deaSTim Harvey
820cc11deaSTim Harveyu-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
10740e999caSTim Harveybooted, 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
152*6122f0d5STim Harvey4. Falcon Mode
153*6122f0d5STim Harvey------------------------------
154*6122f0d5STim Harvey
155*6122f0d5STim HarveyThe Gateworks Ventana board config enables Falcon mode (CONFIG_SPL_OS_BOOT)
156*6122f0d5STim Harveywhich allows the SPL to boot directly to an OS instead of to U-Boot
157*6122f0d5STim Harvey(u-boot.img) thus acheiving a faster overall boot time. The time savings
158*6122f0d5STim Harveydepends on your boot medium (ie NAND Flash vs micro-SD) and size/storage
159*6122f0d5STim Harveyof the OS. The time savings can be anywhere from 2 seconds (256MB NAND Flash
160*6122f0d5STim Harveywith ~1MB kernel) to 6 seconds or more (2GB NAND Flash with ~6 kernel)
161*6122f0d5STim Harvey
162*6122f0d5STim HarveyThe Gateworks Ventana board supports Falcon mode for the following boot
163*6122f0d5STim Harveymedium:
164*6122f0d5STim Harvey - NAND flash
165*6122f0d5STim Harvey - micro-SD
166*6122f0d5STim Harvey
167*6122f0d5STim HarveyFor all boot mediums, raw mode is used. While support of more complex storage
168*6122f0d5STim Harveysuch as files on top of FAT/EXT filesystem is possible but not practical
169*6122f0d5STim Harveyas the size of the SPL is fairly limitted (to 64KB based on the smallest
170*6122f0d5STim Harveysize of available IMX6 iRAM) as well as the fact that this would increase
171*6122f0d5STim HarveyOS load time which defeats the purpose of Falcon mode in the first place.
172*6122f0d5STim Harvey
173*6122f0d5STim HarveyThe SPL decides to boot either U-Boot (u-boot.img) or the OS (args + kernel)
174*6122f0d5STim Harveybased on the return value of the spl_start_uboot() function. While often
175*6122f0d5STim Harveythis can simply be the state of a GPIO based pushbutton or DIP switch, for
176*6122f0d5STim HarveyGateworks Ventana, we use the U-Boot environment 'boot_os' variable which if
177*6122f0d5STim Harveyset to '1' will choose to boot the OS rather than U-Boot. While the choice
178*6122f0d5STim Harveyof adding env support to the SPL adds a little bit of time to the boot
179*6122f0d5STim Harveyprocess as well as (significant really) SPL code space this was deemed most
180*6122f0d5STim Harveyflexible as within the large variety of Gateworks Ventana boards not all of
181*6122f0d5STim Harveythem have a user pushbutton and that pushbutton may be configured as a hard
182*6122f0d5STim Harveyreset per user configuration.
183*6122f0d5STim Harvey
184*6122f0d5STim HarveyTo use Falcon mode it is required that you first 'prepare' the 'args' data
185*6122f0d5STim Harveythat is stored on your boot medium along with the kernel (which can be any
186*6122f0d5STim HarveyOS or bare-metal application). In the case of the Linux kernel the 'args'
187*6122f0d5STim Harveyis the flatenned device-tree which normally gets altered prior to booting linux
188*6122f0d5STim Harveyby U-Boot's 'bootm' command. To achieve this for SPL we use the
189*6122f0d5STim Harvey'spl export fdt' command in U-Boot after loading the kernel and dtb which
190*6122f0d5STim Harveywill go through the same process of modifying the device-tree for the board
191*6122f0d5STim Harveybeing executed on but not jump to the kernel. This allows you to save the
192*6122f0d5STim Harveyargs data to the location the SPL expects it and then enable Falcon mode.
193*6122f0d5STim Harvey
194*6122f0d5STim HarveyIt is important to realize that there are certain values in the dtb that
195*6122f0d5STim Harveyare board model specific (IMX6Q vs IMX6DL for example) and board specific
196*6122f0d5STim Harvey(board serial number, MAC addrs) so you do not want to use the 'args'
197*6122f0d5STim Harveydata prepared from one board on another board.
198*6122f0d5STim Harvey
199*6122f0d5STim Harvey4.1. Falcon Mode on NAND flash
200*6122f0d5STim Harvey------------------------------
201*6122f0d5STim HarveyTo prepare a Gateworks Ventana board that boots from NAND flash for Falcon
202*6122f0d5STim Harveymode you must program your flash such that the 'args' and 'kernel' are
203*6122f0d5STim Harveylocated where defined at compile time by the following:
204*6122f0d5STim Harvey   CONFIG_CMD_SPL_NAND_OFS         17MB - offset of 'args'
205*6122f0d5STim Harvey   CONFIG_SYS_NAND_SPL_KERNEL_OFFS 18MB - offset of 'kernel'
206*6122f0d5STim Harvey
207*6122f0d5STim HarveyThe location offsets defined above are defaults chosen by Gateworks and are
208*6122f0d5STim Harveyflexible if you want to re-define them.
209*6122f0d5STim Harvey
210*6122f0d5STim HarveyThe following steps executed in U-Boot will configure Falcon mode for NAND
211*6122f0d5STim Harveyusing rootfs (ubi), kernel (uImage), and dtb from the network:
212*6122f0d5STim Harvey
213*6122f0d5STim Harvey # change mtd partitions to the above mapping
214*6122f0d5STim Harvey Ventana > setenv mtdparts 'mtdparts=nand:14m(spl),2m(uboot),1m(env),1m(args),10m(kernel),-(rootfs)'
215*6122f0d5STim Harvey
216*6122f0d5STim Harvey # flash rootfs (at 28MB)
217*6122f0d5STim Harvey Ventana > tftp ${loadaddr} rootfs_${flash_layout}.ubi && \
218*6122f0d5STim Harvey   nand erase.part rootfs && nand write ${loadaddr} rootfs ${filesize}
219*6122f0d5STim Harvey
220*6122f0d5STim Harvey # load the device-tree
221*6122f0d5STim Harvey Ventana > tftp ${fdt_addr} ventana/${fdt_file2}
222*6122f0d5STim Harvey
223*6122f0d5STim Harvey # load the kernel
224*6122f0d5STim Harvey Ventana > tftp ${loadaddr} ventana/uImage
225*6122f0d5STim Harvey
226*6122f0d5STim Harvey # flash kernel (at 18MB)
227*6122f0d5STim Harvey Ventana > nand erase.part kernel && nand write ${loadaddr} kernel ${filesize}
228*6122f0d5STim Harvey
229*6122f0d5STim Harvey # set kernel args for the console and rootfs (used by spl export)
230*6122f0d5STim Harvey Ventana > setenv bootargs 'console=ttymxc1,115200 root=ubi0:rootfs ubi.mtd=5 rootfstype=ubifs quiet'
231*6122f0d5STim Harvey
232*6122f0d5STim Harvey # create args based on env, board, EEPROM, and dtb
233*6122f0d5STim Harvey Ventana > spl export fdt ${loadaddr} - ${fdt_addr}
234*6122f0d5STim Harvey
235*6122f0d5STim Harvey # flash args (at 17MB)
236*6122f0d5STim Harvey Ventana > nand erase.part args && nand write 18000000 args 100000
237*6122f0d5STim Harvey
238*6122f0d5STim Harvey # set boot_os env var to enable booting to Linux
239*6122f0d5STim Harvey Ventana > setenv boot_os 1 && saveenv
240*6122f0d5STim Harvey
241*6122f0d5STim HarveyBe sure to adjust 'bootargs' above to your OS needs (this will be different
242*6122f0d5STim Harveyfor various distros such as OpenWrt, Yocto, Android, etc). You can use the
243*6122f0d5STim Harveyvalue obtained from 'cat /proc/cmdline' when booted to Linux.
244*6122f0d5STim Harvey
245*6122f0d5STim HarveyThis information is taken from:
246*6122f0d5STim Harvey  http://trac.gateworks.com/wiki/ventana/bootloader/falcon-mode#nand
247*6122f0d5STim Harvey
248*6122f0d5STim Harvey
249*6122f0d5STim Harvey4.2. Falcon Mode on micro-SD card
250*6122f0d5STim Harvey---------------------------------
251*6122f0d5STim Harvey
252*6122f0d5STim HarveyTo prepare a Gateworks Ventana board with a primary boot device of micro-SD
253*6122f0d5STim Harveyyou first need to make sure you build U-Boot with CONFIG_ENV_IS_IN_MMC
254*6122f0d5STim Harveyinstead of CONFIG_ENV_IS_IN_NAND.
255*6122f0d5STim Harvey
256*6122f0d5STim HarveyFor micro-SD based Falcon mode you must program your micro-SD such that
257*6122f0d5STim Harveythe 'args' and 'kernel' are located where defined at compile time
258*6122f0d5STim Harveyby the following:
259*6122f0d5STim Harvey   CONFIG_SYS_MMCSD_RAW_MODE_ARGS_SECTOR 0x800 (1MB) - offset of 'args'
260*6122f0d5STim Harvey   CONFIG_SYS_MMCSD_RAW_MODE_KERNEL_SECTOR 0x1000 (2MB) - offset of 'kernel'
261*6122f0d5STim Harvey
262*6122f0d5STim HarveyThe location offsets defined above are defaults chosen by Gateworks and are
263*6122f0d5STim Harveyflexible if you want to re-define them.
264*6122f0d5STim Harvey
265*6122f0d5STim HarveyFirst you must prepare a micro-SD such that the SPL can be loaded by the
266*6122f0d5STim HarveyIMX6 BOOT ROM (fixed offset of 1KB), and U-Boot can be loaded by the SPL
267*6122f0d5STim Harvey(fixed offset of 69KB defined by CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR).
268*6122f0d5STim Harvey
269*6122f0d5STim HarveyThe following shell commands are executed on a Linux host (adjust DEV to the
270*6122f0d5STim Harveyblock storage device of your micro-SD):
271*6122f0d5STim Harvey
272*6122f0d5STim Harvey DEV=/dev/sdc
273*6122f0d5STim Harvey # zero out 1MB of device
274*6122f0d5STim Harvey sudo dd if=/dev/zero of=$DEV count=1 bs=1M oflag=sync status=none && sync
275*6122f0d5STim Harvey # copy SPL to 1KB offset
276*6122f0d5STim Harvey sudo dd if=SPL of=$DEV bs=1K seek=1 oflag=sync status=none && sync
277*6122f0d5STim Harvey # copy U-Boot to 69KB offset
278*6122f0d5STim Harvey sudo dd if=u-boot.img of=$DEV bs=1K seek=69 oflag=sync status=none && sync
279*6122f0d5STim Harvey # create a partition table with a single rootfs partition starting at 10MB
280*6122f0d5STim Harvey printf "10,,L\n" | sudo sfdisk --in-order --no-reread -L -uM $DEV && sync
281*6122f0d5STim Harvey # format partition
282*6122f0d5STim Harvey sudo mkfs.ext4 -L root ${DEV}1
283*6122f0d5STim Harvey # mount the partition
284*6122f0d5STim Harvey sudo udisks --mount ${DEV}1
285*6122f0d5STim Harvey # extract filesystem
286*6122f0d5STim Harvey sudo tar xvf rootfs.tar.gz -C /media/root
287*6122f0d5STim Harvey # flush and unmount
288*6122f0d5STim Harvey sync && sudo umount /media/root
289*6122f0d5STim Harvey
290*6122f0d5STim HarveyNow that your micro-SD partitioning has been adjusted to leave room for the
291*6122f0d5STim Harveyraw 'args' and 'kernel' data boot the board with the prepared micro-SD, break
292*6122f0d5STim Harveyout in U-Boot and use the following to enable Falcon mode:
293*6122f0d5STim Harvey
294*6122f0d5STim Harvey # load device-tree from rootfs
295*6122f0d5STim Harvey Ventana > ext2load mmc 0:1 ${fdt_addr} boot/${fdt_file2}
296*6122f0d5STim Harvey
297*6122f0d5STim Harvey # load kernel from rootfs
298*6122f0d5STim Harvey Ventana > ext2load mmc 0:1 ${loadaddr} boot/uImage
299*6122f0d5STim Harvey
300*6122f0d5STim Harvey # write kernel at 2MB offset
301*6122f0d5STim Harvey Ventana > mmc write ${loadaddr} 0x1000 0x4000
302*6122f0d5STim Harvey
303*6122f0d5STim Harvey # setup kernel bootargs
304*6122f0d5STim Harvey Ventana > setenv bootargs 'console=ttymxc1,115200 root=/dev/mmcblk0p1 rootfstype=ext4 rootwait rw'
305*6122f0d5STim Harvey
306*6122f0d5STim Harvey # prepare args
307*6122f0d5STim Harvey Ventana > spl export fdt ${loadaddr} - ${fdt_addr}
308*6122f0d5STim Harvey
309*6122f0d5STim Harvey # write args 1MB data (0x800 sectors) to 1MB offset (0x800 sectors)
310*6122f0d5STim Harvey Ventana > mmc write 18000000 0x800 0x800
311*6122f0d5STim Harvey
312*6122f0d5STim Harvey # set boot_os to enable falcon mode
313*6122f0d5STim Harvey Ventana > setenv boot_os 1 && saveenv
314*6122f0d5STim Harvey
315*6122f0d5STim HarveyBe sure to adjust 'bootargs' above to your OS needs (this will be different
316*6122f0d5STim Harveyfor various distros such as OpenWrt, Yocto, Android, etc). You can use the
317*6122f0d5STim Harveyvalue obtained from 'cat /proc/cmdline' when booted to Linux.
318*6122f0d5STim Harvey
319*6122f0d5STim HarveyThis information is taken from:
320*6122f0d5STim Harvey  http://trac.gateworks.com/wiki/ventana/bootloader/falcon-mode#microsd
321