4
0
raspi-alpine-builder/resources/boot.cmd

124 lines
3.7 KiB
Batchfile
Raw Normal View History

2019-11-08 22:33:12 +01:00
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
2019-11-03 16:04:17 +01:00
# static config
2019-11-08 22:33:12 +01:00
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
setenv boot_partition_a 0x02
setenv boot_partition_b 0x03
setenv boot_limit 0x02
2019-11-03 16:04:17 +01:00
setenv boot_partition_base "/dev/mmcblk0p"
2019-11-08 22:33:12 +01:00
setenv addr_version 0x10000
setenv addr_boot_counter 0x10001
setenv addr_boot_partition 0x10002
2019-11-03 16:04:17 +01:00
2019-11-08 22:33:12 +01:00
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# load persistence values
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# clear memory
mw.b 0x10000 0 0x404
# load uboot file
fatload mmc 0:1 0x10000 uboot.dat 0x400
# check CRC
crc32 0x10000 0x3FC 0x10400
if itest *0x103FC -ne *0x10400; then
echo "invalid CRC -> fallback to default values"
# default values
mw.b ${addr_version} 0x01
mw.b ${addr_boot_counter} 0x00
mw.b ${addr_boot_partition} ${boot_partition_a}
2019-11-03 16:04:17 +01:00
fi
2019-11-08 22:33:12 +01:00
# ensure boot partition is valid
if itest.b *${addr_boot_partition} -ne ${boot_partition_a} && test.b *${addr_boot_partition} -ne ${boot_partition_b}; then
mw.b ${addr_boot_partition} ${boot_partition_a}
2019-11-03 16:04:17 +01:00
fi
2019-11-08 22:33:12 +01:00
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# fallback boot
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
echo "Check fallback boot"
2019-11-03 16:04:17 +01:00
# switch boot partition if boot count exceed limit
2019-11-08 22:33:12 +01:00
if itest.b *${addr_boot_counter} -ge ${boot_limit}; then
2019-11-03 16:04:17 +01:00
echo "!!! Boot limit exceed !!!"
2019-11-08 22:33:12 +01:00
if itest *${addr_boot_partition} -eq ${boot_partition_a}; then
mv.b ${addr_boot_partition} ${boot_partition_b}
2019-11-03 16:04:17 +01:00
else
2019-11-08 22:33:12 +01:00
mv.b ${addr_boot_partition} ${boot_partition_a}
2019-11-03 16:04:17 +01:00
fi
2019-11-08 22:33:12 +01:00
mw.b ${addr_boot_counter} 0
2019-11-03 16:04:17 +01:00
2019-11-08 22:33:12 +01:00
setexpr.b boot_partition *${addr_boot_partition}
2019-11-03 16:04:17 +01:00
echo "Switch active partition to ${boot_partition_base}${boot_partition}"
2019-11-08 22:33:12 +01:00
else
# increase boot_count
setexpr.b tmp *${addr_boot_counter} + 1
mw.b ${addr_boot_counter} ${tmp}
setexpr.b boot_partition *${addr_boot_partition}
2019-11-03 16:04:17 +01:00
fi
2019-11-08 22:33:12 +01:00
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# store persistence values
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# overwrite version
mw.b 0x10000 0x01
# calculate crc
crc32 0x10000 0x3FC 0x103FC
# save to uboot file
fatwrite mmc 0:1 0x10000 uboot.dat 0x400
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# select kernel
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
echo "select kernel"
setenv boot_kernel "/boot/uImage"
# only if new pi a new kernel is required
2020-01-23 19:27:52 +01:00
# https://www.raspberrypi.org/documentation/hardware/raspberrypi/revision-codes/README.md
2019-11-08 22:33:12 +01:00
setexpr board_new_pi ${board_revision} \& 0x800000
if test ${board_new_pi} > 0; then
echo "new board"
# get cpu id from revision
setexpr board_cpu ${board_revision} \& 0xF000
2020-01-23 19:27:52 +01:00
# BCM2836 (pi2)
if test ${board_cpu} == 0x1000; then
2019-11-08 22:33:12 +01:00
setenv boot_kernel "/boot/uImage2"
fi
2020-01-23 19:27:52 +01:00
# BCM2837 (pi3)
if test ${board_cpu} == 0x2000; then
setenv boot_kernel "/boot/uImage2"
fi
# BCM2711 (pi4)
if test ${board_cpu} > 0x3000; then
setenv boot_kernel "/boot/uImage4"
fi
2019-11-08 22:33:12 +01:00
else
echo "old board"
fi
echo "Load kernel ${boot_kernel}"
2019-11-03 16:04:17 +01:00
2019-11-08 22:33:12 +01:00
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# boot
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
2019-11-03 16:04:17 +01:00
# load bootargs from pi boot loader
2019-11-02 23:51:56 +01:00
fdt addr ${fdt_addr} && fdt get value bootargs /chosen bootargs
2019-11-03 16:04:17 +01:00
# overwrite boot partition
setexpr bootargs sub " root=[^ ]+" " root=${boot_partition_base}${boot_partition}" "${bootargs}"
# load kernel and boot
2019-11-08 22:33:12 +01:00
ext4load mmc 0:${boot_partition} ${kernel_addr_r} ${boot_kernel}
2019-11-02 23:51:56 +01:00
bootm ${kernel_addr_r} - ${fdt_addr}
2019-11-03 16:04:17 +01:00
2019-11-08 22:33:12 +01:00
reset