1U-Boot for the Gateworks Ventana Product Family boards
2
3This file contains information for the port of U-Boot to the Gateworks
4Ventana Product family boards.
5
6The entire Ventana product family (http://www.gateworks.com/product#ventana)
7is supported by a single bootloader build by using a common SPL and U-Boot
8that dynamically determines the characterstics of the board at runtime via
9information from an EEPROM on the board programmed at the factory and supports
10all of the various boot mediums available.
11
121. Secondary Program Loader (SPL)
13---------------------------------
14
15The i.MX6 has a BOOT ROM PPL (Primary Program Loader) which supports loading
16an executable image from various boot devices.
17
18The Gateworks Ventana board config uses an SPL build configuration. This
19will build the following artifacts from U-Boot source:
20 - SPL - Secondary Program Loader that the i.MX6 BOOT ROM (Primary Program
21         Loader) boots.  This detects CPU/DRAM configuration, configures
22         The DRAM controller, loads u-boot.img from the detected boot device,
23         and jumps to it.  As this is booted from the PPL, it has an IVT/DCD
24         table.
25 - u-boot.img - The main U-Boot core which is u-boot.bin with a image header.
26
27
282. Build
29--------
30
31To build U-Boot for the Gateworks Ventana product family:
32
33For NAND FLASH based boards:
34 make gwventana_nand_config
35 make
36
37For EMMC FLASH based boards:
38 make gwventana_emmc_config
39 make
40
41
423. Boot source:
43---------------
44
45The Gateworks Ventana boards support booting from NAND or micro-SD depending
46on the board model. The IMX6 BOOT ROM will choose a boot media based on eFUSE
47settings programmed at the factory.
48
49Boards with NAND flash will always boot from NAND, and NAND-less boards will
50always boot from micro-SD. However, it is possible to use the U-Boot bmode
51command (or the technique it uses) to essentially bootstrap to another boot
52media at runtime.
53
543.1. boot from NAND
55-------------------
56
57The i.MX6 BOOT ROM expects some structures that provide details of NAND layout
58and bad block information (referred to as 'bootstreams') which are replicated
59multiple times in NAND. The number of replications and their spacing (referred
60to as search stride) is configurable through board strapping options and/or
61eFUSE settings (BOOT_SEARCH_COUNT / Pages in block from BOOT_CFG2). In
62addition, the i.MX6 BOOT ROM Flash Configuration Block (FCB) supports two
63copies of a bootloader in flash in the case that a bad block has corrupted one.
64The Freescale 'kobs-ng' application from the Freescale LTIB BSP, which runs
65under Linux and operates on an MTD partition, must be used to program the
66bootstream in order to setup this flash structure correctly.
67
68The Gateworks Ventana boards with NAND flash have been factory programmed
69such that their eFUSE settings expect 2 copies of the boostream (this is
70specified by providing kobs-ng with the --search_exponent=1 argument). Once in
71Linux with MTD support for the NAND on /dev/mtd0 you can program the SPL
72with:
73
74kobs-ng init -v -x --search_exponent=1 SPL
75
76The kobs-ng application uses an imximage which contains the Image Vector Table
77(IVT) and Device Configuration Data (DCD) structures that the i.MX6 BOOT ROM
78requires to boot.  The kobs-ng adds the Firmware Configuration Block (FCB) and
79Discovered Bad Block Table (DBBT).  The SPL build artifact from U-Boot is
80an imximage.
81
82The u-boot.img, which is the non SPL U-Boot binary appended to a U-Boot image
83header must be programmed in the NAND flash boot device at an offset hard
84coded in the SPL. For the Ventana boards, this has been chosen to be 14MB.
85The image can be programmed from either U-Boot or Linux:
86
87U-Boot:
88Ventana > setenv mtdparts mtdparts=nand:14m(spl),2m(uboot),1m(env),-(rootfs)
89Ventana > tftp ${loadaddr} u-boot.img && nand erase.part uboot && \
90          nand write ${loadaddr} uboot ${filesize}
91
92Linux:
93nandwrite /dev/mtd1 u-boot.img
94
95The above assumes the default Ventana partitioning scheme which is configured
96via the mtdparts env var:
97 - spl: 14MB
98 - uboot: 2M
99 - env: 1M
100 - rootfs: the rest
101
102This information is taken from:
103  http://trac.gateworks.com/wiki/ventana/bootloader#nand
104
105More details about the i.MX6 BOOT ROM can be found in the IMX6 reference manual.
106
1073.1. boot from MMC (eMMC/microSD)
108---------------------------------
109
110When the IMX6 eFUSE settings have been factory programmed to boot from
111MMC the SPL will be loaded from offset 0x400 (1KB). Once the SPL is
112booted, it will load and execute U-Boot (u-boot.img) from offset 69KB
113on the micro-SD (defined by CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR).
114
115While it is technically possible to enable the SPL to be able to load
116U-Boot from a file on a FAT/EXT filesystem on the micro-SD, we chose to
117use raw micro-SD access to keep the code-size and boot time of the SPL down.
118
119For these reasons an MMC device that will be used as an IMX6 primary boot
120device must be carefully partitioned and prepared.
121
122The following shell commands are executed on a Linux host (adjust DEV to the
123block storage device of your MMC, ie /dev/mmcblk0):
124
125 DEV=/dev/sdc
126 # zero out 1MB of device
127 sudo dd if=/dev/zero of=$DEV count=1 bs=1M oflag=sync status=none && sync
128 # copy SPL to 1KB offset
129 sudo dd if=SPL of=$DEV bs=1K seek=1 oflag=sync status=none && sync
130 # copy U-Boot to 69KB offset
131 sudo dd if=u-boot.img of=$DEV bs=1K seek=69 oflag=sync status=none && sync
132 # create a partition table with a single rootfs partition starting at 1MB
133 printf "1,,L\n" | sudo sfdisk --in-order --no-reread -L -uM $DEV && sync
134 # format partition
135 sudo mkfs.ext4 -L root ${DEV}1
136 # mount the partition
137 sudo udisks --mount ${DEV}1
138 # extract filesystem
139 sudo tar xvf rootfs.tar.gz -C /media/root
140 # flush and unmount
141 sync && sudo umount /media/root
142
143The above assumes the default Ventana micro-SD partitioning scheme
144 - spl    :   1KB-69KB  (68KB)  required by IMX6 BOOT ROM
145 - uboot  :  69KB-709KB (640KB) defined by
146                                CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR
147 - env    : 709KB-965KB (256KB) defined by
148                                CONFIG_ENV_MMC_SIZE
149                                CONFIG_ENV_MMC_OFFSET_REDUND
150 - rootfs :   1MB-
151
152This information is taken from:
153  http://trac.gateworks.com/wiki/ventana/bootloader#microsd
154
155More details about the i.MX6 BOOT ROM can be found in the IMX6 reference manual.
156
1574. Falcon Mode
158------------------------------
159
160The Gateworks Ventana board config enables Falcon mode (CONFIG_SPL_OS_BOOT)
161which allows the SPL to boot directly to an OS instead of to U-Boot
162(u-boot.img) thus acheiving a faster overall boot time. The time savings
163depends on your boot medium (ie NAND Flash vs micro-SD) and size/storage
164of the OS. The time savings can be anywhere from 2 seconds (256MB NAND Flash
165with ~1MB kernel) to 6 seconds or more (2GB NAND Flash with ~6 kernel)
166
167The Gateworks Ventana board supports Falcon mode for the following boot
168medium:
169 - NAND flash
170 - micro-SD
171
172For all boot mediums, raw mode is used. While support of more complex storage
173such as files on top of FAT/EXT filesystem is possible but not practical
174as the size of the SPL is fairly limitted (to 64KB based on the smallest
175size of available IMX6 iRAM) as well as the fact that this would increase
176OS load time which defeats the purpose of Falcon mode in the first place.
177
178The SPL decides to boot either U-Boot (u-boot.img) or the OS (args + kernel)
179based on the return value of the spl_start_uboot() function. While often
180this can simply be the state of a GPIO based pushbutton or DIP switch, for
181Gateworks Ventana, we use an EEPROM register on i2c-0 at 0x50:0x00:
182set to '0' will choose to boot to U-Boot and otherwise it will boot to OS.
183
184To use Falcon mode it is required that you first 'prepare' the 'args' data
185that is stored on your boot medium along with the kernel (which can be any
186OS or bare-metal application). In the case of the Linux kernel the 'args'
187is the flatenned device-tree which normally gets altered prior to booting linux
188by U-Boot's 'bootm' command. To achieve this for SPL we use the
189'spl export fdt' command in U-Boot after loading the kernel and dtb which
190will go through the same process of modifying the device-tree for the board
191being executed on but not jump to the kernel. This allows you to save the
192args data to the location the SPL expects it and then enable Falcon mode.
193
194It is important to realize that there are certain values in the dtb that
195are board model specific (IMX6Q vs IMX6DL for example) and board specific
196(board serial number, MAC addrs) so you do not want to use the 'args'
197data prepared from one board on another board.
198
1994.1. Falcon Mode on NAND flash
200------------------------------
201To prepare a Gateworks Ventana board that boots from NAND flash for Falcon
202mode you must program your flash such that the 'args' and 'kernel' are
203located where defined at compile time by the following:
204   CONFIG_CMD_SPL_NAND_OFS         17MB - offset of 'args'
205   CONFIG_SYS_NAND_SPL_KERNEL_OFFS 18MB - offset of 'kernel'
206
207The location offsets defined above are defaults chosen by Gateworks and are
208flexible if you want to re-define them.
209
210The following steps executed in U-Boot will configure Falcon mode for NAND
211using rootfs (ubi), kernel (uImage), and dtb from the network:
212
213 # change mtd partitions to the above mapping
214 Ventana > setenv mtdparts 'mtdparts=nand:14m(spl),2m(uboot),1m(env),1m(args),10m(kernel),-(rootfs)'
215
216 # flash rootfs (at 28MB)
217 Ventana > tftp ${loadaddr} rootfs_${flash_layout}.ubi && \
218   nand erase.part rootfs && nand write ${loadaddr} rootfs ${filesize}
219
220 # load the device-tree
221 Ventana > tftp ${fdt_addr} ventana/${fdt_file2}
222
223 # load the kernel
224 Ventana > tftp ${loadaddr} ventana/uImage
225
226 # flash kernel (at 18MB)
227 Ventana > nand erase.part kernel && nand write ${loadaddr} kernel ${filesize}
228
229 # set kernel args for the console and rootfs (used by spl export)
230 Ventana > setenv bootargs 'console=ttymxc1,115200 root=ubi0:rootfs ubi.mtd=5 rootfstype=ubifs quiet'
231
232 # create args based on env, board, EEPROM, and dtb
233 Ventana > spl export fdt ${loadaddr} - ${fdt_addr}
234
235 # flash args (at 17MB)
236 Ventana > nand erase.part args && nand write 18000000 args 100000
237
238 # set i2c register 0x50:0x00=0 to boot to Linux
239 Ventana > i2c dev 0 && i2c mw 0x50 0x00.0 0 1
240
241Be sure to adjust 'bootargs' above to your OS needs (this will be different
242for various distros such as OpenWrt, Yocto, Android, etc). You can use the
243value obtained from 'cat /proc/cmdline' when booted to Linux.
244
245This information is taken from:
246  http://trac.gateworks.com/wiki/ventana/bootloader/falcon-mode#nand
247
248
2494.2. Falcon Mode on micro-SD card
250---------------------------------
251
252To prepare a Gateworks Ventana board with a primary boot device of micro-SD
253you first need to make sure you build U-Boot with CONFIG_ENV_IS_IN_MMC
254instead of CONFIG_ENV_IS_IN_NAND.
255
256For micro-SD based Falcon mode you must program your micro-SD such that
257the 'args' and 'kernel' are located where defined at compile time
258by the following:
259   CONFIG_SYS_MMCSD_RAW_MODE_ARGS_SECTOR 0x800 (1MB) - offset of 'args'
260   CONFIG_SYS_MMCSD_RAW_MODE_KERNEL_SECTOR 0x1000 (2MB) - offset of 'kernel'
261
262The location offsets defined above are defaults chosen by Gateworks and are
263flexible if you want to re-define them.
264
265First you must prepare a micro-SD such that the SPL can be loaded by the
266IMX6 BOOT ROM (fixed offset of 1KB), and U-Boot can be loaded by the SPL
267(fixed offset of 69KB defined by CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR).
268
269The following shell commands are executed on a Linux host (adjust DEV to the
270block storage device of your micro-SD):
271
272 DEV=/dev/sdc
273 # zero out 1MB of device
274 sudo dd if=/dev/zero of=$DEV count=1 bs=1M oflag=sync status=none && sync
275 # copy SPL to 1KB offset
276 sudo dd if=SPL of=$DEV bs=1K seek=1 oflag=sync status=none && sync
277 # copy U-Boot to 69KB offset
278 sudo dd if=u-boot.img of=$DEV bs=1K seek=69 oflag=sync status=none && sync
279 # create a partition table with a single rootfs partition starting at 10MB
280 printf "10,,L\n" | sudo sfdisk --in-order --no-reread -L -uM $DEV && sync
281 # format partition
282 sudo mkfs.ext4 -L root ${DEV}1
283 # mount the partition
284 sudo udisks --mount ${DEV}1
285 # extract filesystem
286 sudo tar xvf rootfs.tar.gz -C /media/root
287 # flush and unmount
288 sync && sudo umount /media/root
289
290Now that your micro-SD partitioning has been adjusted to leave room for the
291raw 'args' and 'kernel' data boot the board with the prepared micro-SD, break
292out in U-Boot and use the following to enable Falcon mode:
293
294 # load device-tree from rootfs
295 Ventana > ext2load mmc 0:1 ${fdt_addr} boot/${fdt_file2}
296
297 # load kernel from rootfs
298 Ventana > ext2load mmc 0:1 ${loadaddr} boot/uImage
299
300 # write kernel at 2MB offset
301 Ventana > mmc write ${loadaddr} 0x1000 0x4000
302
303 # setup kernel bootargs
304 Ventana > setenv bootargs 'console=ttymxc1,115200 root=/dev/mmcblk0p1 rootfstype=ext4 rootwait rw'
305
306 # prepare args
307 Ventana > spl export fdt ${loadaddr} - ${fdt_addr}
308
309 # write args 1MB data (0x800 sectors) to 1MB offset (0x800 sectors)
310 Ventana > mmc write 18000000 0x800 0x800
311
312 # set i2c register 0x50:0x00=0 to boot to Linux
313 Ventana > i2c dev 0 && i2c mw 0x50 0x00.0 0 1
314
315Be sure to adjust 'bootargs' above to your OS needs (this will be different
316for various distros such as OpenWrt, Yocto, Android, etc). You can use the
317value obtained from 'cat /proc/cmdline' when booted to Linux.
318
319This information is taken from:
320  http://trac.gateworks.com/wiki/ventana/bootloader/falcon-mode#microsd
321