RSS订阅信息安全技术跟踪与研究:技术、平台、会议、论文、产业
你现在的位置:首页 / 技术积累 / 正文

[转]U-Boot on BeagleBone Black

0 技术积累 | 2015年7月16日
转载申明:本站原创,欢迎转载。但转载时请保留原文地址。
原文地址:http://www.vonwei.com/post/ubootonBBB.html

关于在BBB开发板上构建U-BOOT的全解析,比较详细易懂。

U-Boot on BeagleBone Black

Understanding the boot up mechanism of the BeagleBone Black is important to be able to modify it. As we later want to change the Linux Kernel itself we need to know how it is started by the BeagleBone.

The AM335x processor on the BeagleBone Black has many configurable options where it can boot from which are all documented in Chapter 26 of the AM335x ARM? Cortex?-A8 Microprocessors Technical Reference Manual. The BeagleBone Black provides by alternative boot sequences which are selectable by the boot switch (S2). In default mode (S2 not pressed) it tries to boot from

  1. MMC1 (onboard eMMC),

  2. MMC0 (microSD),

  3. UART0,

  4. USB0.

Usually it will find something in the onboard eMMC and boot from there. If S2 is pressed during power-up the boot sequence is changed to

  1. SPI0,

  2. MMC0 (microSD),

  3. UART0,

  4. USB0.

As there is usually nothing bootable found on SPI0 it will boot from the microSD card. The onboard eMMC or an external microSD card have to be formatted in a special way for the AM335x processor to find its boot file, which is described very good on the MMC boot format wiki page at TI. If the AM335x processor finds a valid formatted MMC it searchings for a file named MLO on the first partition and if it is found it boots from that file.

This is very U-Boot kicks in. U-Boot is a very versatile boot loader which can be used on the BeagleBone Black. U-Boot provides this MLO file as a second-stage boot-loader which then loads the actual U-Boot which has to be provided as a file named u-boot.bin in the same directory. U-Boot itself will then look for a file named uEnv.txt for further configuration and then act upon it.

Formatting a microSD card

Now as we have the theoretical background, let's try it our self. The following steps were all done on a (virtual) Ubuntu Linux system. Our microSD card is connected to /dev/sdb as has a size of 16 GB. The content of the SD card fill be deleted during this procedure. Instead of calculating the exact partitions sizes needed as explained by the MMC boot format wiki page we use a script which does everything for use. Download, make it executable and run it by

wget http://dev.gentoo.org/~armin76/arm/beaglebone/mkcard.sh
chmod +x mkcard.sh
sudo ./mkcard.sh /dev/sdb

Be sure to have /dev/sdb pointing to your microSD card and not anything else! In the output of the script you can see the partition table it created and in our case it was a
primary FAT23 partition of 72261 blocks in size and a Linux ext4 partition of 15478627 blocks in size:

1024+0 records in
1024+0 records out
1048576 bytes (1.0 MB) copied, 0.447124 s, 2.3 MB/s
Disk /dev/sdb doesn't contain a valid partition table
DISK SIZE - 15931539456 bytes
CYLINDERS - 1936
Checking that no-one is using this disk right now ...
OK
Disk /dev/sdb: 1936 cylinders, 255 heads, 63 sectors/track
sfdisk: ERROR: sector 0 does not have an msdos signature
 /dev/sdb: unrecognized partition table type
Old situation:
No partitions found
New situation:
Units = cylinders of 8225280 bytes, blocks of 1024 bytes, counting from 0
   Device Boot Start     End   #cyls    #blocks   Id  System
/dev/sdb1   *      0+      8       9-     72261    c  W95 FAT32 (LBA)
/dev/sdb2          9    1935    1927   15478627+  83  Linux
/dev/sdb3          0       -       0          0    0  Empty
/dev/sdb4          0       -       0          0    0  Empty
Successfully wrote the new partition table
Re-reading the partition table ...
If you created or changed a DOS partition, /dev/foo7, say, then use dd(1)
to zero the first 512 bytes:  dd if=/dev/zero of=/dev/foo7 bs=512 count=1
(See fdisk(8).)
umount: /dev/sdb1: not mounted
mkfs.fat 3.0.26 (2014-03-07)
mkfs.fat: warning - lowercase labels might not work properly with DOS or Windows
umount: /dev/sdb2: not mounted
mke2fs 1.42.9 (4-Feb-2014)
Filesystem label=rootfs
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
969136 inodes, 3869656 blocks
193482 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=3963617280
119 block groups
32768 blocks per group, 32768 fragments per group
8144 inodes per group
Superblock backups stored on blocks: 
	32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208
Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

Now you can mount the boot partition manually or replug the microSD card as most systems will mount it then automatically.

Compiling U-Boot

The next step is to compile U-Boot. As we need to cross compile this for the BeagleBone Black we need a suitable compiler. On Ubuntu this can be installed relatively easy by

sudo apt-get install gcc-arm-linux-gnueabihf

Now we clone the git repository, create a default configuration and cross compile it for the BeagleBone Black by

git clone git://git.denx.de/u-boot.git && cd u-boot
make am335x_boneblack_defconfig
ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- make

We should get a MLO and u-boot.bin file in the current directory and can copy those onto the boot partition of microSD card.

Configuring U-Boot

To configure U-Boot we create a file uEnv.txt on the boot partition and fill it, e.g. with

console=ttyO0,115200n8
ipaddr=192.168.23.2
serverip=192.168.23.1
rootpath=/exports/rootfs
netargs=setenv bootargs console=${console} ${optargs} root=/dev/nfs nfsroot=${serverip}:${rootpath},${nfsopts} rw ip=${ipaddr}:${serverip}:192.168.23.1:255.255.255.0:beaglebone:eth0:none:192.168.23.1
netboot=echo Booting from network ...; tftp ${loadaddr} ${bootfile}; tftp ${fdtaddr} ${fdtfile}; run netargs; bootz ${loadaddr} - ${fdtaddr}
uenvcmd=run netboot

to instruct U-Boot to get the Linux Kernel and device tree via TFTP. The details are depending on your configuration :).

Booting ...

Finally we can now boot from our microSD card. To see the actual boot process a RS232 cable like theTTL-232R-3V3 from FTDI is very handy. Just plug it to the J1 connector and open a serial terminal of your choice. Plug in the microSD card and hold down the S2 boot switch to force booting from the microSD card. You will see hopefully something like

U-Boot SPL 2014.10-rc1 (Aug 22 2014 - 19:20:25)
reading u-boot.img
reading u-boot.img
U-Boot 2014.10-rc1 (Aug 22 2014 - 19:20:25)
I2C:   ready
DRAM:  512 MiB
MMC:   OMAP SD/MMC: 0, OMAP SD/MMC: 1
Using default environment
Net:not set. Validating first E-fuse MAC
cpsw, usb_ether
Hit any key to stop autoboot:  0
switch to partitions #0, OK
mmc0 is current device
SD/MMC found on device 0
reading uEnv.txt
454 bytes read in 4 ms (110.4 KiB/s)
Loaded environment from uEnv.txt
Importing environment from mmc ...
Running uenvcmd ...
Booting from network ... 
cpsw Waiting for PHY auto negotiation to complete. done
link up on port 0, speed 100, full duplex
Using cpsw device
TFTP from server 192.168.23.36; our IP address is 192.168.23.30
Filename 'zImage'.
Load address: 0x82000000 
Loading: #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         ####
         1.5 MiB/s
done
Bytes transferred = 6342632 (60c7e8 hex)
link up on port 0, speed 100, full duplex
Using cpsw device
TFTP from server 192.168.23.36; our IP address is 192.168.23.30
Filename 'am335x-boneblack.dtb'.
Load address: 0x88000000 
Loading: #######
         1.2 MiB/s
done
Bytes transferred = 31882 (7c8a hex)
Kernel image @ 0x82000000 [ 0x000000 - 0x60c7e8 ]
## Flattened Device Tree blob at 88000000
   Booting using the fdt blob at 0x88000000
   Loading Device Tree to 8fff5000, end 8ffffc89 ... OK
Starting kernel ...

where we first can see of the U-Boot SPL (MLO file) and then afterwards U-Boot itself. Then it reads the uEnv.txt configuration file and acts upon it.

Always boot from microSD

If you always want to boot from your microSD card you can invalidate the boot partition on the onboard eMMC. Then the AM335x processor will always fail back to the second boot option in the default order which is the microSD card. This can be done easily by booting your favourite Linux distro on the BeagleBone Black and issue an

sudo dd if=/dev/zero of=/dev/mmcblk1 bs=1024 count=1024

Be warned: This will wipe your boot partition on the eMMC!



  • ------------------分隔线----------------

  • 如果感兴趣,欢迎关注本站微信号,跟踪最新博文信息,手机微信扫一扫下面的二维码,即可关注!
  • 微月信公众号
  • 推荐您阅读更多有关于“ uboot  BeagleBone Black   ”的文章

    请填写你的在线分享代码
    上一篇:C编程警戒:慎用char下一篇:[转]PDB文件:每个开发者必须知道的

    猜你喜欢

    评论列表:

    发表评论

    必填

    选填

    选填

    必填,不填不让过哦,嘻嘻。

    记住我,下次回复时不用重新输入个人信息

    本站介绍
    最近发表
    本年最热文章
    本月最热文章
    网站分类
    文章归档