Starting kernel and file system from uboot.

After installing u-boot has to transfer the control to the Linux kernel, which in its turn has to mount a root filesystem after starting.

The U-boot variables bootargs and bootcmd are responsible for the linux kernel and file system location.

Usually Linux kernel image with the uImage format and the filesystem image are located on a flash drive in the ready to use devices.

In this case while starting wich nand-flash and using of ubifs, the u-boot variables will look like this:

set bootargs 'console=ttyS0,115200 ubi.mtd=2 root=ubi0:rootfsU rootfstype=ubifs init=/etc/preinit'
set bootcmd 'nand read.e $(loadaddr) kernel; bootm $(loadaddr)'

Script example for creating of ubi image:

#!/bin/sh

mkfs.ubifs -q -r $WORKING_DIR/openWrtSMV628/build_dir/target-arm_v5te_uClibc-0.9.33.2_eabi/root-smv628 -m 2048 -e 129024 -c
2047 -o ubifs.img
ubinize -o /home/dima/Tftpboot/mrv/brd6282/ubi.img -m 2048 -p 128KiB -s 512 ubinize.cfg

While using nor-flash and filesystem with jffs2 format the u-boot variables will look as follows:

set bootargs 'console=ttyS0,115200 root=/dev/mtdblock2 rootfstype=jffs2 loglevel=7 init=/etc/preinit'
set bootcmd 'bootm 0xf8100000'

Script example for creating of jffs2 image:

#!/bin/sh

$WORKING_DIR/openWrtSMV628/build_dir/host/mtd-utils-1.4.5/mkfs.jffs2 \
 -x lzma rtime --squash -e0x40000 \
 -d $WORKING_DIR/openWrtSMV628/build_dir/target-arm_v5te_uClibc-0.9.33.2_eabi/root-smv628 \
 -o /home/dima/Tftpboot/mrv/brd6282/rootfs.jffs2

One more starting variant could be when the file system is located on the external usb-stick.

set bootargs 'console=ttyS0,115200 root=/dev/sda1 rootwait rw loglevel=8 init=/etc/preinit'

In this case it is important the presence of the option rootwait that allows to wait until initialization of the usb-stick via Linux kernel.

Very often, when a project is under debug stage and regular the device's firmware takes a lot of time, we can use a network boot using tftp:
и регулярная прошивка устройства:

set bootargs 'console=ttyS0,115200 root=/dev/ram rw loglevel=8 init=/etc/preinit'
set bootcmd 'set ethact egiga0; tf $(loadaddr) mrv/brd6282/uImage;tf 0x3000000 mrv/brd6282/ramdisk.img;bootm $(loadaddr) 0x3000000'

At the same time the file system is presented in the form of a ramdisk

To create a ramdisk from the tree of file system we can use the following script(where RFS is a file system):

#!/bin/sh

rm -f /tmp/ramdisk.img
rm -f /tmp/ramdisk.img.gz
rm -f /tmp/ramdisk_with_title.img

RDSIZE=220000
BLKSIZE=1024

dd if=/dev/zero of=/tmp/ramdisk.img bs=$BLKSIZE count=$RDSIZE

mke2fs -F -m 0 -b $BLKSIZE /tmp/ramdisk.img $RDSIZE

sudo mount /tmp/ramdisk.img /mnt/initrd -t ext2 -o loop

sudo cp -R ./RFS/* /mnt/initrd

sudo umount /mnt/initrd
gzip -9 /tmp/ramdisk.img

mkimage -A arm -C none -O linux -T ramdisk -a 0x0000000 -e 0x0000000 -n LinuxRamDisk -d /tmp/ramdisk.img.gz /tmp/ramdisk_with_title.img
cp /tmp/ramdisk_with_title.img /home/dima/Tftpboot/mrv/brd6282/ramdisk.img

The ramdisk can be placed on a flash drive. Then the variables will look like this:

set bootargs 'console=ttyS0,115200 root=/dev/ram rw loglevel=8 init=/etc/preinit'
set bootcmd 'nand read.e $(loadaddr) kernel; nand read.e 0x3000000 0x00600000 0x300000;bootm $(loadaddr) 0x3000000'

We can also combine. For example the kernel throuh tftp, file systen from usb-stick:

set bootargs 'console=ttyS0,115200 ubi.mtd=2 root=ubi0:rootfsU rootfstype=ubifs init=/etc/preinit'
set bootcmd 'set ethact egiga1; tf $(loadaddr) mrv/brd6282/uImage; bootm $(loadaddr)'

When the size of file system in megabytes or tens of megabytes then the starting throuh TFTP is convenient, but if the filesystem size of hundreds of megabytes then the starting itself is not fast сама загрузка будет не быстрой) and the RAM has to store such sizes. In this case we can use NFS:

setenv bootargs 'console=ttyS0,115200 root=/dev/nfs rw nfsroot=192.168.1.10:/home/dima/Nfsboot/fsl ip=192.168.1.100:192.168.1.10:192.168.1.10:255.255.255.0::eth0: loglevel=7'
setenv bootcmd 'tf 1000000 mrv/brd6282/uImage; bootm 1000000'

In this example, the kernel is started via tftp and the filesystem is mounted via nfs.

Another example of an alternative way for starting. It was helpful to me when I had a device for which I had no source codes of u-boot and for this reason I did not want to make changes to the factory variables of u-boot.
To do this, temporary variables had benn created and the device was started using the commands: run new_boot

set newBootArgs 'set bootargs console=ttyS0,115200 root=/dev/ram rw loglevel=8 init=/etc/preinit'
set newBootCmd 'set ethact egiga1;tf $(loadaddr) mrv/brd6282/uImage;tf 0x3000000 mrv/brd6282/ramdisk.img;bootm $(loadaddr) 0x3000000'
set new_boot 'run newBootArgs; run newBootCmd;'