added A/B partition update
This commit is contained in:
parent
699d2bca99
commit
f59261bb70
@ -1,3 +1,54 @@
|
||||
# static config
|
||||
setenv boot_partition_a 2
|
||||
setenv boot_partition_b 3
|
||||
setenv boot_limit 2
|
||||
setenv boot_partition_base "/dev/mmcblk0p"
|
||||
|
||||
|
||||
# set default values if env not set
|
||||
if printenv boot_count; then
|
||||
else
|
||||
setenv boot_count 1
|
||||
fi
|
||||
|
||||
if printenv boot_partition; then
|
||||
# check if valid partition a or b
|
||||
if test ${boot_partition} -ne ${boot_partition_a} && test ${boot_partition} -ne ${boot_partition_b}; then
|
||||
setenv boot_partition ${boot_partition_a}
|
||||
fi
|
||||
else
|
||||
setenv boot_partition ${boot_partition_a}
|
||||
fi
|
||||
|
||||
|
||||
# switch boot partition if boot count exceed limit
|
||||
if test ${boot_count} -ge ${boot_limit}; then
|
||||
echo "!!! Boot limit exceed !!!"
|
||||
|
||||
if test ${boot_partition} -eq ${boot_partition_a}; then
|
||||
setenv boot_partition ${boot_partition_b}
|
||||
else
|
||||
setenv boot_partition ${boot_partition_a}
|
||||
fi
|
||||
setenv boot_count 0
|
||||
|
||||
echo "Switch active partition to ${boot_partition_base}${boot_partition}"
|
||||
fi
|
||||
|
||||
# increase boot_count
|
||||
setexpr boot_count ${boot_count} + 1
|
||||
|
||||
# store settings
|
||||
saveenv
|
||||
|
||||
# load bootargs from pi boot loader
|
||||
fdt addr ${fdt_addr} && fdt get value bootargs /chosen bootargs
|
||||
ext4load mmc 0:2 ${kernel_addr_r} /boot/uImage
|
||||
|
||||
# overwrite boot partition
|
||||
setexpr bootargs sub " root=[^ ]+" " root=${boot_partition_base}${boot_partition}" "${bootargs}"
|
||||
|
||||
# load kernel and boot
|
||||
ext4load mmc 0:${boot_partition} ${kernel_addr_r} /boot/uImage
|
||||
bootm ${kernel_addr_r} - ${fdt_addr}
|
||||
|
||||
reset
|
@ -10,14 +10,14 @@ set -e
|
||||
: ${TIME_ZONE:="Etc/UTC"}
|
||||
: ${HOST_NAME:="alpine"}
|
||||
: ${ROOT_PASSWORD:="alpine"}
|
||||
: ${IMG_NAME:="alpine-${ALPINE_BRANCH}-sdcard.img"}
|
||||
: ${IMG_NAME:="alpine-${ALPINE_BRANCH}-sdcard"}
|
||||
|
||||
|
||||
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
||||
# static config
|
||||
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
||||
RES_PATH=/resources/
|
||||
BASE_PACKAGES="alpine-base tzdata parted ifupdown e2fsprogs-extra util-linux coreutils linux-rpi2"
|
||||
BASE_PACKAGES="alpine-base tzdata parted ifupdown e2fsprogs-extra util-linux coreutils linux-rpi2 uboot-tools"
|
||||
|
||||
WORK_PATH="/work"
|
||||
OUTPUT_PATH="/output"
|
||||
@ -149,9 +149,59 @@ tmpfs /tmp tmpfs defaults 0 0
|
||||
tmpfs /run tmpfs defaults 0 0
|
||||
EOF
|
||||
|
||||
# custom
|
||||
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
||||
echo ">> Move persistent data to /data"
|
||||
|
||||
# prepare /data
|
||||
cat >${ROOTFS_PATH}/etc/local.d/20-data_prepare.start <<EOF
|
||||
#!/bin/sh
|
||||
mkdir -p /data/root/
|
||||
|
||||
mkdir -p /data/dropbear/
|
||||
if [ ! -f /data/dropbear/dropbear.conf ]; then
|
||||
cp /etc/conf.d/dropbear_org /data/dropbear/dropbear.conf
|
||||
fi
|
||||
|
||||
EOF
|
||||
chmod +x ${ROOTFS_PATH}/etc/local.d/20-data_prepare.start
|
||||
|
||||
# link root dir
|
||||
rmdir ${ROOTFS_PATH}/root
|
||||
ln -s /data/root ${ROOTFS_PATH}/root
|
||||
|
||||
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
||||
|
||||
|
||||
# uboot tools config
|
||||
cat >${ROOTFS_PATH}/etc/fw_env.config <<EOF
|
||||
/uboot/uboot.env 0x0000 0x4000
|
||||
EOF
|
||||
|
||||
# TODO REMOVE THIS
|
||||
# mark system as booted (should be moved to application)
|
||||
cat >${ROOTFS_PATH}/etc/local.d/99-uboot.start <<EOF
|
||||
#!/bin/sh
|
||||
mount -o remount,rw /uboot
|
||||
|
||||
fw_setenv boot_count 1
|
||||
|
||||
sync
|
||||
mount -o remount,ro /uboot
|
||||
EOF
|
||||
chmod +x ${ROOTFS_PATH}/etc/local.d/99-uboot.start
|
||||
|
||||
# copy helper scripts
|
||||
cp ${RES_PATH}/scripts/* ${ROOTFS_PATH}/sbin/
|
||||
|
||||
|
||||
# TODO configurable
|
||||
# dropbear
|
||||
chroot_exec apk add dropbear
|
||||
chroot_exec rc-update add dropbear
|
||||
ln -s /data/dropbear/ ${ROOTFS_PATH}/etc/dropbear
|
||||
|
||||
mv ${ROOTFS_PATH}/etc/conf.d/dropbear ${ROOTFS_PATH}/etc/conf.d/dropbear_org
|
||||
ln -s /data/dropbear/dropbear.conf ${ROOTFS_PATH}/etc/conf.d/dropbear
|
||||
|
||||
|
||||
rm -rf ${ROOTFS_PATH}/var/cache/apk/*
|
||||
@ -259,7 +309,7 @@ image boot.vfat {
|
||||
vfat {
|
||||
label = "boot"
|
||||
}
|
||||
size = 32M
|
||||
size = 100M
|
||||
}
|
||||
EOF
|
||||
make_image ${BOOTFS_PATH} ${WORK_PATH}/genimage_boot.cfg
|
||||
@ -315,5 +365,12 @@ image sdcard.img {
|
||||
EOF
|
||||
make_image ${IMAGE_PATH} ${WORK_PATH}/genimage_sdcard.cfg
|
||||
|
||||
echo ">> Compress images"
|
||||
# copy final image
|
||||
cp ${IMAGE_PATH}/sdcard.img ${OUTPUT_PATH}/${IMG_NAME}
|
||||
gzip -c ${IMAGE_PATH}/sdcard.img > ${OUTPUT_PATH}/${IMG_NAME}.img.gz
|
||||
gzip -c ${IMAGE_PATH}/rootfs.ext4 > ${OUTPUT_PATH}/${IMG_NAME}_update.img.gz
|
||||
|
||||
# create checksums
|
||||
cd ${OUTPUT_PATH}/
|
||||
sha256sum ${IMG_NAME}.img.gz > ${IMG_NAME}.img.gz.sha256
|
||||
sha256sum ${IMG_NAME}_update.img.gz > ${IMG_NAME}_update.img.gz.sha256
|
||||
|
@ -1,4 +1,10 @@
|
||||
#!/bin/sh -e
|
||||
|
||||
# resize already done?
|
||||
if [ -f /data/resize_done ]; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
logger -t "rc.resizedata" "Expanding root partition"
|
||||
|
||||
# Detect root partition device
|
||||
@ -57,4 +63,4 @@ partprobe /dev/${ROOT_DEV} &&
|
||||
|
||||
mount -a
|
||||
|
||||
chmod -x /etc/local.d/90-resizedata.start
|
||||
touch /data/resize_done
|
||||
|
11
resources/scripts/ab_active
Executable file
11
resources/scripts/ab_active
Executable file
@ -0,0 +1,11 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
# get current partition index
|
||||
current_idx=$(rdev | sed 's#/dev/mmcblk0p\([^ ]*\).*#\1#')
|
||||
|
||||
if [ $current_idx -eq 2 ]; then
|
||||
echo "Active partition: A"
|
||||
else
|
||||
echo "Active partition: B"
|
||||
fi
|
40
resources/scripts/ab_flash
Executable file
40
resources/scripts/ab_flash
Executable file
@ -0,0 +1,40 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
image_file=$1
|
||||
|
||||
if [ -z $image_file ]; then
|
||||
echo "USAGE: $0 [IMAGE_PATH]"
|
||||
return 1
|
||||
fi
|
||||
|
||||
# change to directory containing update file
|
||||
cd $(dirname $image_file)
|
||||
|
||||
# check integrity of image
|
||||
sha256sum -c ${image_file}.sha256
|
||||
|
||||
# get current partition index
|
||||
current_idx=$(rdev | sed 's#/dev/mmcblk0p\([^ ]*\).*#\1#')
|
||||
|
||||
if [ $current_idx -eq 2 ]; then
|
||||
echo "Start update for partition B"
|
||||
flash_idx=3
|
||||
else
|
||||
echo "Start update for partition A"
|
||||
flash_idx=2
|
||||
fi
|
||||
|
||||
flash_device="/dev/mmcblk0p${flash_idx}"
|
||||
|
||||
# flash device
|
||||
gunzip -c ${image_file} | dd of=${flash_device} status=progress
|
||||
|
||||
|
||||
# switch active partition
|
||||
mount -o remount,rw /uboot
|
||||
fw_setenv boot_partition ${flash_idx}
|
||||
sync
|
||||
mount -o remount,ro /uboot
|
||||
|
||||
echo "Update complete -> please reboot"
|
Loading…
Reference in New Issue
Block a user