Please note that User Registration has been temporarily disabled due to a recent increase in automated registrations. If anyone needs an account, please request one here: RequestAccount. Thanks for your patience!--Wmat (talk)
Please email User:Wmat if you experience any issues with the Request Account form.

EBC Exercise 21a Boot Sequence

Revision as of 15:40, 1 October 2012 by Yoder (Talk | contribs)

Jump to: navigation, search

thumb‎ Embedded Linux Class by Mark A. Yoder

Up to this point we've always booted the Beagle into Linux and worked from there. Now it's time to learn what has to happen before we can run Linux. To do this you need to look at the output of the serial port so see the boot sequence.

Booting Up

Boot up your bone and connect to the serial port using the screen command. Hit return and log in.

host$ screen /dev/ttyUSB0 115200
|       |                  .-.           o o        
|   |   |-----.-----.-----.| |   .----..-----.-----.
|       |     | __  |  ---'| '--.|  .-'|     |     |
|   |   |  |  |     |---  ||  --'|  |  |  '  | | | |
'---'---'--'--'--.  |-----------'  '-----'-'-'-'
                -'  |

The Angstrom Distribution beaglebone ttyO0 

Angstrom v2012.05 - Kernel 3.2.25

beaglebone login: root


Now shutdown and be ready to hit return when you get the u-boot prompt.

beagle$ shutdown -r now
Sending SIGTERM to remaining processes...
Sending SIGKILL to remaining processes...
Unmounting file systems.
Unmounted /dev/mqueue.
Unmounted /sys/kernel/debug.
Disabling swaps.
Detaching loop devices.
Detaching DM devices.
[  599.018005] Restarting system.

These first messages are from the kernel shutting down.

U-Boot Starting

The following messages are the boot sequence.

U-Boot SPL 2011.09-00053-gb423c52 (Aug 10 2012 - 11:26:55)
Texas Instruments Revision detection unimplemented
No daughter card present
No AC power, disabling frequency switch
reading u-boot.img
reading u-boot.img

U-Boot 2011.09-00053-gb423c52 (Aug 10 2012 - 11:26:55)

I2C:   ready
DRAM:  256 MiB
WARNING: Caches not enabled
No daughter card present
NAND:  HW ECC Hamming Code selected
No NAND device found!!!
0 MiB
*** Warning - readenv() failed, using default environment

Net:   cpsw
Hit any key to stop autoboot:  0 

U-Boot help

You are now in the u-boot boot loader. Try help

U-Boot# help
?       - alias for 'help'
askenv  - get environment variables from stdin
base    - print or set address offset
bdinfo  - print Board Info structure
boot    - boot default, i.e., run 'bootcmd'
bootd   - boot default, i.e., run 'bootcmd'
bootm   - boot application image from memory
bootp   - boot image via network using BOOTP/TFTP protocol
cmp     - memory compare
coninfo - print console devices and information
cp      - memory copy
crc32   - checksum calculation
dcache  - enable or disable data cache
dhcp    - boot image via network using DHCP/TFTP protocol
echo    - echo args to console
editenv - edit environment variable
env     - environment handling commands
exit    - exit script
ext2load- load binary file from a Ext2 filesystem
ext2ls  - list files in a directory (default /)
ext4load- load binary file from a Ext2 filesystem
ext4ls  - list files in a directory (default /)
false   - do nothing, unsuccessfully
fatinfo - print information about filesystem
fatload - load binary file from a dos filesystem
fatls   - list files in a directory (default /)
go      - start application at address 'addr'
help    - print command description/usage
i2c     - I2C sub-system
icache  - enable or disable instruction cache
iminfo  - print header information for application image
imxtract- extract a part of a multi-image
itest   - return true/false on integer compare
loadb   - load binary file over serial line (kermit mode)
loads   - load S-Record file over serial line
loady   - load binary file over serial line (ymodem mode)
loop    - infinite loop on address range
md      - memory display
mm      - memory modify (auto-incrementing address)
mmc     - MMC sub system
mmcinfo - display MMC info
mtest   - simple RAM read/write test
mw      - memory write (fill)
nand    - NAND sub-system
nandecc - Switch NAND ECC calculation algorithm b/w hardware and software
nboot   - boot from NAND device
nfs     - boot image via network using NFS protocol
nm      - memory modify (constant address)
ping    - send ICMP ECHO_REQUEST to network host
printenv- print environment variables
reset   - Perform RESET of the CPU
run     - run commands in an environment variable
saveenv - save environment variables to persistent storage
setenv  - set environment variables
sf      - SPI flash sub-system
showvar - print local hushshell variables
sleep   - delay execution for some time
source  - run script from memory
test    - minimal test like /bin/sh
tftpboot- boot image via network using TFTP protocol
true    - do nothing, successfully
version - print monitor, compiler and linker version

Discovering what boot does

Your goal is to discover what happens when the boot command is run.

U-Boot# help boot
boot - boot default, i.e., run 'bootcmd'
U-boot# print bootcmd
bootcmd=if mmc rescan; then echo SD/MMC found on device ${mmc_dev}; 
if run loadbootenv; then echo Loaded environment from ${bootenv};run importbootenv;fi;
if test -n $uenvcmd; then echo Running uenvcmd ...;run uenvcmd;fi;
if run mmc_load_uimage_ext4; then run mmc_args;bootm ${kloadaddr};fi;fi;run nand_boot;

Figure out what's happening above by 'pretty printing' bootcmd. That is, properly format the code so you can follow the flow.

if mmc rescan; then
  echo SD/MMC found on device ${mmc_dev};  Find out what mmc_dev is and fill it in
  if run loadbootenv; then 
    echo Loaded environment from ${bootenv};
    run importbootenv;
... and so on.

U-Boot print

It might be helpful to print the contents of all the variables and save it for future reference.

U-boot# print
bootargs_defaults=setenv bootargs console=${console} ${optargs}
bootcmd=if mmc rescan; then echo SD/MMC found on device ${mmc_dev};if run loadbootenv; then echo Loaded  
 environment from ${bootenv};run importbootenv;fi;if test -n $uenvcmd; then echo Running uenvcmd ...;run 
 uenvcmd;fi;if run mmc_load_uimage_ext4; then run mmc_args;bootm ${kloadaddr};fi;fi;run nand_boot;
importbootenv=echo Importing environment from mmc ...; env import -t $loadaddr $filesize
loadbootenv=fatload mmc ${mmc_dev} ${loadaddr} ${bootenv}
mmc_args=run bootargs_defaults;setenv bootargs ${bootargs} root=${mmc_root} rootfstype=${mmc_root_fs_type}  
mmc_boot=run mmc_args; run mmc_load_uimage_ext4; bootm ${kloadaddr}
mmc_load_uimage=fatload mmc ${mmc_dev}:1 ${kloadaddr} ${bootfile}
mmc_load_uimage_ext4=ext4load mmc ${mmc_dev}:2 ${kloadaddr} /boot/${bootfile}
mmc_root=/dev/mmcblk0p2 ro
mmc_root_fs_type=ext4 rootwait
nand_args=run bootargs_defaults;setenv bootargs ${bootargs} root=${nand_root} noinitrd  
rootfstype=${nand_root_fs_type} ip=${ip_method}
nand_boot=echo Booting from nand ...; run nand_args; nandecc hw 2; nand read.i ${kloadaddr}  
 ${nand_src_addr} ${nand_img_siz}; bootm ${kloadaddr}
nand_root=ubi0:rootfs rw ubi.mtd=7,2048
nand_root_fs_type=ubifs rootwait=1
net_args=run bootargs_defaults;setenv bootargs ${bootargs} root=/dev/nfs  
nfsroot=${serverip}:${rootpath},${nfsopts} rw ip=dhcp 
 net_boot=echo Booting from network ...; setenv autoload no; dhcp; tftp ${kloadaddr} ${bootfile}; run  
 net_args; bootm ${kloadaddr}
nor_args=run bootargs_defaults;setenv bootargs ${bootargs} root={nor_root} rootfstype=${nor_root_fs_type}  
nor_boot=echo Booting from NOR ...; run nor_args; cp.b ${0x08080000} ${kloadaddr} ${nor_img_siz}; bootm  
nor_root=/dev/mtdblock3 rw
spi_args=run bootargs_defaults;setenv bootargs ${bootargs} root=${spi_root} rootfstype=${spi_root_fs_type}  
spi_boot=echo Booting from spi ...; run spi_args; sf probe ${spi_bus_no}:0; sf read ${kloadaddr}  
 ${spi_src_addr} ${spi_img_siz}; bootm ${kloadaddr}
spi_root=/dev/mtdblock4 rw

Based on your investigation above, predict what will happen at boot time, then boot and check yourself.

U-boot boot

U-Boot# boot
SD/MMC found on device 0
reading uEnv.txt

33 bytes read
Loaded environment from uEnv.txt
Importing environment from mmc ...
Loading file "/boot/uImage" from mmc device 0:2 xxa2
3319440 bytes read
## Booting kernel from Legacy Image at 80007fc0 ...
   Image Name:   Angstrom/3.2.25/beaglebone
   Image Type:   ARM Linux Kernel Image (uncompressed)
   Data Size:    3319376 Bytes = 3.2 MiB
   Load Address: 80008000
   Entry Point:  80008000
   Verifying Checksum ... OK
   XIP Kernel Image ... OK

Starting kernel ...

Uncompressing Linux... done, booting the kernel.
systemd-fsck[56]: Angstrom-Cloud9: clean, 51868/218592 files, 304346/873534 blocks

|       |                  .-.           o o        
|   |   |-----.-----.-----.| |   .----..-----.-----.
|       |     | __  |  ---'| '--.|  .-'|     |     |
|   |   |  |  |     |---  ||  --'|  |  |  '  | | | |
'---'---'--'--'--.  |-----------'  '-----'-'-'-'
                -'  |

The Angstrom Distribution beaglebone ttyO0

Angstrom v2012.05 - Kernel 3.2.25

beaglebone login: root

Looking on the FAT partition

The SD card you have been using has 2 partitions on it. Partition 1 is a small FAT partition. These are the files you see appear when you first boot the bone. This contains the boot loaders.

The second partition is ext4 and contains the root file system. These are all the other files.

You can see the FAT partition with:

beagle$ mount /dev/mmcblk0p1 /mnt
beagle$ cd /mnt
beagle$ ls
Docs     LICENSE.txt  README.htm  autorun.inf  u-boot.img
Drivers  MLO          Uenv.txt    info.txt     uEnv.txt.orig

The file u-boot.img is U-Boot!. Look in uEnv.txt

beagle$ cat uEnv.txt
optargs=run_hardware_tests quiet

These are the arguments that are passed to the kernel when it boots. Try editing the file and removing quiet, then reboot. You should see many more boot messages.

thumb‎ Embedded Linux Class by Mark A. Yoder