U-Boot on QEMU
  1. Lab 1 Setup u-boot ARM development Environment
  2. Lab 2 Modify some code
  3. Lab 3 Network based u-boot

Lab 1 Setup u-boot ARM development Environment

Aim to configure u-boot development environment, the commands use code style.

1. Linux development environment

本次实验用的Linux的发行版是 Ubuntu 16.04.2 LTS。使用Linaro ( https://www.linaro.org/ )提供的开发工具链。Linaro 是一个ARM开发机构的联盟,旨在建立一个ARM开发的生态系统。

2. 加入专门针对ARM Linux开发提供编译开发环境的源PPA

理解什么是PPA(Personal Package Archives),把软件源加入ubuntu的详细指导参见如下软件:

https://wiki.linaro.org/Platform/Systems/Repository

a) add the key
wget -O - http://repo.linaro.org/ubuntu/linarorepo.key|sudo apt-key add -

b) add to sources list

Add the linaro-overlay repo with these lines into below file

/etc/apt/sources.list.d/linaro-maintainers-ubuntu-tools-xenial.list

that contains these lines:

deb http://repo.linaro.org/ubuntu/linaro-overlay xenial main
deb-src http://repo.linaro.org/ubuntu/linaro-overlay xenial main

c) then check the update , sudo apt-get update etc.

sudo apt-get install linaro-image-tools qemu-user-static qemu-system

1创建linux 的image的工具,2 This package provides the user mode emulation binaries, built statically.

e) 安装交叉编译器

$ sudo apt-get install gcc-arm-linux-gnueabi g++-arm-linux-gnueabi

f) 安装桥连代码

*$ sudo apt install bridge-utils

网卡桥连代码,可以暂时不装

$ wget -c ftp://ftp.denx.de/pub/u-boot/u-boot-2017.05.tar.bz2
$ tar xvf u-boot-2017.05.tar.bz2
$ cd u-boot-2017.05/
$ make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- vexpress_ca9x4_defconfig
$ make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi-
using the following to check supported machine types
qemu-system-arm --machine help
Finally boot u-boot with QEMU simulated hardware

qemu-system-arm -M vexpress-a9 -m 128M -nographic -kernel u-boot

To kill the QEMU system
killall qemu-system-arm

Lab 2 Modify some code

源代码里面的README文件有很多重要的信息,可以帮助学习U-Boot的代码修改。

1 . Modify the .config

2. using "make menuconfig" , same as 1) also used in Linux kernel config.  If it misses curses files, try the following or similar

sudo apt-get install libncurses5-dev

3. check some board info
=> bdinfo
arch_number = 0x000008E0
boot_params = 0x60002000
DRAM bank   = 0x00000000
-> start    = 0x60000000
-> size     = 0x08000000
DRAM bank   = 0x00000001
-> start    = 0x80000000
-> size     = 0x00000004
eth0name    = smc911x-0
ethaddr     = 52:54:00:12:34:56
current eth = smc911x-0
ip_addr     = <NULL>
baudrate    = 38400 bps
TLB addr    = 0x67FF0000
relocaddr   = 0x67F7C000
reloc off   = 0x0777C000
irq_sp      = 0x67EDBEF0
sp start    = 0x67EDBEE0


3. Check flash memory information and modify the flash code to make it works
u-boot command:
setenv bootdelay 60
saveenv
=> saveenv
Saving Environment to Flash...
Error: end address not on sector boundary
Error: end address not on sector boundary
=>

Flash bank 1:
=> flinfo
Bank # 1: CFI conformant flash (32 x 16)  Size: 64 MB in 128 Sectors
  Intel Extended command set, Manufacturer ID: 0x89, Device ID: 0x0018
  Erase timeout: 16384 ms, write timeout: 3 ms
  Buffer write timeout: 3 ms, buffer size: 2048 bytes
  Sector Start Addresses:
  40000000   RO   40080000     ......

Flash bank 2:
Bank # 2: CFI conformant flash (32 x 16)  Size: 64 MB in 128 Sectors
  Intel Extended command set, Manufacturer ID: 0x89, Device ID: 0x0018
  Erase timeout: 16384 ms, write timeout: 3 ms
  Buffer write timeout: 3 ms, buffer size: 2048 bytes
  Sector Start Addresses:
  44000000        44080000  .........

Modify the Flash Driver Code

Because of flinfo
Bank # 1: CFI conformant flash (32 x 16)  Size: 64 MB in 128 Sectors
  Intel Extended command set, Manufacturer ID: 0x89, Device ID: 0x0018
——
From the output above, we know 64MB / 128 sector = 64*1024 K / 128 = 512 K per Sector
Therefore we modify this file: include/configs/vexpress_common.h
cp include/configs/vexpress_common.h include/configs/vexpress_common.h.org

/* 255 0x40000 sectors + first or last sector may have 4 erase regions = 259 */
#define CONFIG_SYS_MAX_FLASH_SECT       256             /*YW 259->256 Max sectors */
#define FLASH_MAX_SECTOR_SIZE           0x00080000      /*YW 40000->80000 256->512 KB sectors */

Display the Env variables in flash

md 47F00000 400
=> md 47F00000 100
47f00000: a51c88ee 68637261 6d72613d 75616200    ....arch=arm.bau
47f00010: 74617264 38333d65 00303034 72616f62    drate=38400.boar
47f00020: 65763d64 65727078 62007373 6472616f    d=vexpress.board
47f00030: 6d616e5f 65763d65 65727078 62007373    _name=vexpress.b
47f00040: 5f746f6f 63735f61 74706972 616f6c3d    oot_a_script=loa

Display the Env variables in flash

reset the board now the Env is saved!

Create the patch from diff so that the change can be quickly made:

diff -u vexpress_common.h.org vexpress_common.h > vexpress_common.patch

patch vexpress_common.h vexpress_common.patch

If you want to save the configure in simulated flash permanently, you shall use the latest QEMU 2.9.0 and compile from source. Also make some changes to the board configs.

Lab 3 Network based u-boot