2015年11月12日 星期四

在 raspberry pi 2 上使用 u-boot

一般 soc 都會提供 u-boot 來當作 bootloader, 不過 rpi2 並沒有, u-boot 有很多豐富的功能, 在操作 rpi2 時, 也許有額外的助益, 來看看怎麼安裝 u-boot。

ref:
http://elinux.org/RPi_U-Boot
git clone git://github.com/swarren/u-boot.git
git checkout -b rpi_dev origin/rpi_dev

git clone git://git.denx.de/u-boot.git
make rpi_2_defconfig
make 
cp u-boot.bin /sd_card/part1
cp /sd_card/part1/config.txt /sd_card/part1/config.txt.bak
echo 'kernel=u-boot.bin' > /sd_card/part1/config.txt
u-boot 環境變數

dhcpuboot=usb start; dhcp u-boot.uimg; bootm
distro_bootcmd=for target in ${boot_targets}; do run bootcmd_${target}; done
fdt_addr_r=0x02000000
fdtfile=bcm2836-rpi-2-b.dtb
kernel_addr_r=0x01000000
loadaddr=0x00200000
mmc_boot=if mmc dev ${devnum}; then setenv devtype mmc; run scan_dev_for_boot_part; fi
pxefile_addr_r=0x00100000
ramdisk_addr_r=0x02100000
scan_dev_for_boot=echo Scanning ${devtype} ${devnum}:${bootpart}...; for prefix in ${boot_prefixes}; do rune
scan_dev_for_boot_part=part list ${devtype} ${devnum} -bootable devplist; env exists devplist || setenv deve
scan_dev_for_extlinux=if test -e ${devtype} ${devnum}:${bootpart} ${prefix}extlinux/extlinux.conf; then echi
scan_dev_for_scripts=for script in ${boot_scripts}; do if test -e ${devtype} ${devnum}:${bootpart} ${prefixe
scriptaddr=0x00000000
soc=bcm283x
stderr=serial,lcd
stdin=serial,usbkbd
stdout=serial,lcd
usb_boot=usb start; if usb dev ${devnum}; then setenv devtype usb; run scan_dev_for_boot_part; fi
usbethaddr=b8:27:eb:90:b1:7b
vendor=raspberrypi


Environment size: 2188/16380 bytes U-Boot>


可以用 uart 接出來看到 u-boot 畫面。當然電視的畫面也有, 不過有點歪歪的就是。

u-boot 畫面


zImage 是我自己編譯出來的 kernel, 複製到 sdcard 上, 使用以下 u-boot 指令載入 kernel:
載入 linux
 1 # Tell Linux that it is booting on a Raspberry Pi2
 2 setenv machid 0x00000c42
 3 # Set the kernel boot command line
 4 setenv bootargs "earlyprintk console=tty0 console=ttyAMA0 root=/dev/mmcblk0p2 rootfstype=ext4 rootwait noinitrd"
 5 # Save these changes to u-boot's environment
 6 saveenv
 7 # Load the existing Linux kernel into RAM
 8 fatload mmc 0:1 ${kernel_addr_r} zImage
 9 # Boot the kernel we have just loaded
10 bootz ${kernel_addr_r}


u-boot 已經愈來愈複雜了, 熟悉它不是壞事, 很多 soc 有提供了 u-boot, 也提供很複雜的載入指令, 在接觸到其他 soc 時, 就不會那麼陌生。

20230210 補充:

另外隨著 qemu (QEMU emulator version 7.2.0 (Debian 1:7.2+dfsg-2) ) 的開發, 目前也有 rpi2 的模擬器, 可以執行這個 u-boot, 但是時靈時不靈, 運氣好 u-boot 可以跑起來, 如 list 1。
qemu-system-arm -machine raspi2b -no-reboot -nographic -kernel ./u-boot

list 1. u-boot on qemu rpi2
  1 descent@debian-vm:u-boot$ ./qu.sh
  2
  3 U-Boot 2023.04-rc1-00335-gd1f5dbe664 (Feb 09 2023 - 15:12:42 +0800)
  4
  5 DRAM:  960 MiB
  6 RPI 2 Model B (0xa21041)
  7 Core:  63 devices, 14 uclasses, devicetree: embed
  8 MMC:   mmc@7e202000: 0
  9 Loading Environment from FAT... WARNING at drivers/mmc/bcm2835_sdhost.c:414/bcm2835_send_command()!
 10 WARNING at drivers/mmc/bcm2835_sdhost.c:414/bcm2835_send_command()!
 11 Card did not respond to voltage select! : -110
 12 ** Bad device specification mmc 0 **
 13 In:    serial
 14 Out:   vidconsole
 15 Err:   vidconsole
 16 Net:   No ethernet found.
 17 starting USB...
 18 Bus usb@7e980000: USB DWC2
 19 scanning bus usb@7e980000 for devices... 1 USB Device(s) found
 20        scanning usb for storage devices... 0 Storage Device(s) found
 21 Hit any key to stop autoboot:  0
 22 WARNING at drivers/mmc/bcm2835_sdhost.c:414/bcm2835_send_command()!
 23 WARNING at drivers/mmc/bcm2835_sdhost.c:414/bcm2835_send_command()!
 24 WARNING at drivers/mmc/bcm2835_sdhost.c:414/bcm2835_send_command()!
 25 Card did not respond to voltage select! : -110
 26 MMC Device 1 not found
 27 no mmc device at slot 1
 28 MMC Device 2 not found
 29 no mmc device at slot 2
 30
 31 Device 0: unknown device
 32 No ethernet found.
 33 missing environment variable: pxeuuid
 34 Retrieving file: pxelinux.cfg/00000000
 35 No ethernet found.
 36 Retrieving file: pxelinux.cfg/0000000
 37 No ethernet found.
 38 Retrieving file: pxelinux.cfg/000000
 39 No ethernet found.
 40 Retrieving file: pxelinux.cfg/00000
 41 No ethernet found.
 42 Retrieving file: pxelinux.cfg/0000
 43 No ethernet found.
 44 Retrieving file: pxelinux.cfg/000
 45 No ethernet found.
 46 Retrieving file: pxelinux.cfg/00
 47 No ethernet found.
 48 Retrieving file: pxelinux.cfg/0
 49 No ethernet found.
 50 Retrieving file: pxelinux.cfg/default-arm-bcm283x-rpi
 51 No ethernet found.
 52 Retrieving file: pxelinux.cfg/default-arm-bcm283x
 53 No ethernet found.
 54 Retrieving file: pxelinux.cfg/default-arm
 55 No ethernet found.
 56 Retrieving file: pxelinux.cfg/default
 57 No ethernet found.
 58 Config file not found
 59 No ethernet found.
 60 No ethernet found.
 61 U-Boot> help
 62 ?         - alias for 'help'
 63 base      - print or set address offset
 64 bdinfo    - print Board Info structure
 65 blkcache  - block cache diagnostics and control
 66 boot      - boot default, i.e., run 'bootcmd'
 67 bootd     - boot default, i.e., run 'bootcmd'
 68 bootefi   - Boots an EFI payload from memory
 69 bootelf   - Boot from an ELF image in memory
 70 bootflow  - Boot flows
 71 bootm     - boot application image from memory
 72 bootp     - boot image via network using BOOTP/TFTP protocol
 73 bootvx    - Boot vxWorks from an ELF image
 74 bootz     - boot Linux zImage image from memory
 75 cls       - clear screen
 76 cmp       - memory compare
 77 coninfo   - print console devices and information
 78 cp        - memory copy
 79 crc32     - checksum calculation
 80 dhcp      - boot image via network using DHCP/TFTP protocol
 81 dm        - Driver model low level access
 82 echo      - echo args to console
 83 editenv   - edit environment variable
 84 env       - environment handling commands
 85 exit      - exit script
 86 ext2load  - load binary file from a Ext2 filesystem
 87 ext2ls    - list files in a directory (default /)
 88 ext4load  - load binary file from a Ext4 filesystem
 89 ext4ls    - list files in a directory (default /)
 90 ext4size  - determine a file's size
 91 false     - do nothing, unsuccessfully
 92 fatinfo   - print information about filesystem
 93 fatload   - load binary file from a dos filesystem
 94 fatls     - list files in a directory (default /)
 95 fatmkdir  - create a directory
 96 fatrm     - delete a file
 97 fatsize   - determine a file's size
 98 fatwrite  - write file into a dos filesystem
 99 fdt       - flattened device tree utility commands
100 fstype    - Look up a filesystem type
101 fstypes   - List supported filesystem types
102 fsuuid    - Look up a filesystem UUID
103 go        - start application at address 'addr'
104 gpio      - query and control gpio pins
105 help      - print command description/usage
106 iminfo    - print header information for application image
107 imxtract  - extract a part of a multi-image
108 itest     - return true/false on integer compare
109 lcdputs   - print string on video framebuffer
110 ln        - Create a symbolic link
111 load      - load binary file from a filesystem
112 loadb     - load binary file over serial line (kermit mode)
113 loads     - load S-Record file over serial line
114 loadx     - load binary file over serial line (xmodem mode)
115 loady     - load binary file over serial line (ymodem mode)
116 loop      - infinite loop on address range
117 ls        - list files in a directory (default /)
118 md        - memory display
119 mii       - MII utility commands
120 mm        - memory modify (auto-incrementing address)
121 mmc       - MMC sub system
122 mmcinfo   - display MMC info
123 mw        - memory write (fill)
124 net       - NET sub-system
125 nfs       - boot image via network using NFS protocol
126 nm        - memory modify (constant address)
127 panic     - Panic with optional message
128 part      - disk partition related commands
129 ping      - send ICMP ECHO_REQUEST to network host
130 pinmux    - show pin-controller muxing
131 printenv  - print environment variables
132 pxe       - commands to get and boot from pxe files
133 random    - fill memory with random pattern
134 reset     - Perform RESET of the CPU
135 run       - run commands in an environment variable
136 save      - save file to a filesystem
137 saveenv   - save environment variables to persistent storage
138 setcurs   - set cursor position within screen
139 setenv    - set environment variables
140 setexpr   - set environment variable as the result of eval expression
141 showvar   - print local hushshell variables
142 size      - determine a file's size
143 sleep     - delay execution for some time
144 source    - run script from memory
145 sysboot   - command to get and boot from syslinux files
146 test      - minimal test like /bin/sh
147 tftpboot  - load file via network using TFTP protocol
148 true      - do nothing, successfully
149 usb       - USB sub-system
150 usbboot   - boot from USB device
151 version   - print monitor, compiler and linker version
152 U-Boot>
list 2. bdinfo
 1 U-Boot> bdinfo
 2 boot_params = 0x00000100
 3 DRAM bank   = 0x00000000
 4 -> start    = 0x00000000
 5 -> size     = 0x3c000000
 6 flashstart  = 0x00000000
 7 flashsize   = 0x00000000
 8 flashoffset = 0x00000000
 9 baudrate    = 115200 bps
10 relocaddr   = 0x3bf70000
11 reloc off   = 0x3bf68000
12 Build       = 32-bit
13 current eth = unknown
14 ethaddr     = 52:54:00:12:34:57
15 IP addr     = <NULL>
16 fdt_blob    = 0x00073510
17 new_fdt     = 0x00000000
18 fdt_size    = 0x00000000
19 Video       = hdmi@7e902000 active
20 FB base     = 0x3c100000
21 FB size     = 640x480x32
22 lmb_dump_all:
23  memory.cnt  = 0x1
24  memory[0]	[0x0-0x3bffffff], 0x3c000000 bytes flags: 0
25  reserved.cnt  = 0x3
26  reserved[0]	[0x0-0xfff], 0x00001000 bytes flags: 0
27  reserved[1]	[0x3ab67000-0x3bffffff], 0x01499000 bytes flags: 0
28  reserved[2]	[0x3bb67b90-0x3bffffff], 0x00498470 bytes flags: 0
29 devicetree  = embed
30 arch_number = 0x00000000
31 TLB addr    = 0x3bff0000
32 irq_sp      = 0x3bb6bea0
33 sp start    = 0x3bb6be90
34 Early malloc usage: 374 / 400
35 U-Boot>
ref: Booting a Raspberry Pi2, with u-boot and HYP enabled

沒有留言:

張貼留言

使用 google 的 reCAPTCHA 驗證碼, 總算可以輕鬆留言了。

我實在受不了 spam 了, 又不想讓大家的眼睛花掉, 只好放棄匿名留言。這是沒辦法中的辦法了。留言的朋友需要有 google 帳號。