Zephyr引导(基础)

本文基于Zephyr起步(原生)和nrf52840dk_nrf52840开发板

目录

配置

mcuboot

1
2
3
4
vim ~/zephyrproject/bootloader/mcuboot/boot/zephyr/prj.conf
# 将 CONFIG_BOOT_UPGRADE_ONLY=n
# 修改
# 为 CONFIG_BOOT_UPGRADE_ONLY=y

makefile

1
cd ~/zephyrproject/bootloader/mcuboot/samples/zephyr
  • 改动1
1
2
3
4
vim Makefile
# 将 --slot-size 0x60000
# 修改
# 为 --slot-size 0x67000
  • 上述修改保持和开发板设备树(flash0)配置一致
1
cat ~/zephyrproject/zephyr/boards/arm/nrf52840dk_nrf52840/nrf52840dk_nrf52840.dts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# 已省略其他无关配置
&flash0 {
partitions {
boot_partition: partition@0 {
label = "mcuboot";
reg = <0x000000000 0x0000C000>;
};
slot0_partition: partition@c000 {
label = "image-0";
reg = <0x0000C000 0x00067000>;
};
slot1_partition: partition@73000 {
label = "image-1";
reg = <0x00073000 0x00067000>;
};
};
};
  • 改动2
1
2
3
4
vim Makefile
# 将 --pad \
# 修改
# 为 --pad --confirm \
  • 改动3
1
vim Makefile
1
2
3
4
5
6
7
8
9
10
11
flash_boot:
$(PYOCD) flash -a 0 mcuboot.bin --target nrf52840

flash_hello1:
$(PYOCD) flash -a 0xc000 signed-hello1.bin --target nrf52840

flash_hello2:
$(PYOCD) flash -a 0x73000 signed-hello2.bin --target nrf52840

flash_full:
$(PYOCD) flash -e chip -a 0 full.bin --target nrf52840
  • 上述烧录命令依赖于工具pyocd 安装方法如下
1
2
3
4
pip3 install -U pyocd

pyocd -V
# 0.33.1

运行

  • 完整烧录
1
2
3
4
5
6
7
cd ~/zephyrproject/bootloader/mcuboot/samples/zephyr

make clean

make full.bin BOARD=nrf52840dk_nrf52840

make flash_full

zephyr-bootloader-01.png

  • 更新烧录
1
make flash_hello2

zephyr-bootloader-02.png

  • 复位开发板

zephyr-bootloader-03.png

工具

  • readelf - display information about ELF files
1
2
3
brew install binutils

readelf -S build/nrf52840dk_nrf52840/hello2/zephyr/zephyr.elf
1
2
3
4
5
6
7
There are 27 section headers, starting at offset 0xa32e4:

Section Headers:
[Nr] Name Type Addr Off Size ES Flg Lk Inf Al
[ 0] NULL 00000000 000000 000000 00 0 0 0
[ 1] rom_start PROGBITS 0000c000 0000c0 000300 00 WAX 0 0 4
[ 2] text PROGBITS 0000c300 0003c0 0045fc 00 AX 0 0 4
  • hexinfo - summarize a hex file’s contents
1
2
3
pip3 install -U intelhex

hexinfo.py build/nrf52840dk_nrf52840/hello2/zephyr/zephyr.hex
1
2
3
4
- file: 'build/nrf52840dk_nrf52840/hello2/zephyr/zephyr.hex'
entry: 0x0000D6BD
data:
- { first: 0x0000C000, last: 0x00010E27, length: 0x00004E28 }

参考