Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/flasher #417

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion contracts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
include balena-image.inc

# Provide any deltas required for the flasher image
BALENA_BOOT_PARTITION_FILES:append = " ${BALENA_EXTRA_BOOT_FILES}\
"
46 changes: 3 additions & 43 deletions layers/meta-balena-topic/recipes-core/images/balena-image.bbappend
Original file line number Diff line number Diff line change
@@ -1,45 +1,5 @@
DEPENDS += "balena-bootscript"
include balena-image.inc

BALENA_BOOT_BIN ?= ""
DEPENDS += "${BALENA_BOOT_BIN}"

# Add components that we need to boot
IMAGE_INSTALL += "\
bootscript \
kernel-module-rtl88x2bu \
iperf3 \
${IMAGE_INSTALL_MACHINE_EXTRAS} \
"

BALENA_EXTRA_BOOT_FILES:zynqmp = "boot.bin:/boot.bin u-boot.itb:/u-boot.itb balena-bootscript.scr:/boot.scr"
BALENA_EXTRA_BOOT_FILES:zynq = "boot.bin:/boot.bin u-boot.img:/u-boot.img balena-bootscript.scr:/boot.scr"
BALENA_EXTRA_BOOT_FILES:lcbzu9 = "lcb-boot.bin:/boot.bin u-boot.itb:/u-boot.itb balena-bootscript.scr:/boot.scr"
BALENA_BOOT_PARTITION_FILES:append = " ${BALENA_EXTRA_BOOT_FILES}"

DEVICETREELINKS ??= "system.dtb ${DEVICETREE}"

# Postprocessing to reduce the amount of work to be done
# by configuration scripts
topicbalena_rootfs_postprocess() {
/bin/echo -e "${DEVICETREELINKS}" | while read LINK TARGET
do
if [ -n "${TARGET}" ]
then
/bin/echo "DT: ${LINK}->${TARGET}"
ln -s ${TARGET} ${IMAGE_ROOTFS}/boot/${LINK}
fi
done
}
ROOTFS_POSTPROCESS_COMMAND += "topicbalena_rootfs_postprocess; "


# Sizes in KiB.
# We need to increase the rootfs size to make space for additional drivers in ROOTFS.
# BalenaOS image has a 700MB max size defined in 'image_types_balena.bbclass'
IMAGE_ROOTFS_SIZE="409600"

# We require access to the git repository here, so we must run outside fakeroot
do_addrevisioninfo() {
git rev-parse --verify --short HEAD >> ${IMAGE_ROOTFS}${sysconfdir}/revision
}
addtask do_addrevisioninfo before do_image after do_rootfs
BALENA_BOOT_PARTITION_FILES:append = " ${BALENA_EXTRA_BOOT_FILES}\
"
44 changes: 44 additions & 0 deletions layers/meta-balena-topic/recipes-core/images/balena-image.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
DEPENDS += "balena-bootscript"

BALENA_BOOT_BIN ?= ""
DEPENDS += "${BALENA_BOOT_BIN}"

# Add components that we need to boot
IMAGE_INSTALL += "\
bootscript \
kernel-module-rtl88x2bu \
iperf3 \
${IMAGE_INSTALL_MACHINE_EXTRAS} \
"

BALENA_EXTRA_BOOT_FILES:zynqmp = "boot.bin:/boot.bin u-boot.itb:/u-boot.itb balena-bootscript.scr:/boot.scr"
BALENA_EXTRA_BOOT_FILES:zynq = "boot.bin:/boot.bin u-boot.img:/u-boot.img balena-bootscript.scr:/boot.scr"
BALENA_EXTRA_BOOT_FILES:lcbzu9 = "lcb-boot.bin:/boot.bin u-boot.itb:/u-boot.itb balena-bootscript.scr:/boot.scr"

DEVICETREELINKS ??= "system.dtb ${DEVICETREE}"

# Postprocessing to reduce the amount of work to be done
# by configuration scripts
topicbalena_rootfs_postprocess() {
/bin/echo -e "${DEVICETREELINKS}" | while read LINK TARGET
do
if [ -n "${TARGET}" ]
then
/bin/echo "DT: ${LINK}->${TARGET}"
ln -s ${TARGET} ${IMAGE_ROOTFS}/boot/${LINK}
fi
done
}
ROOTFS_POSTPROCESS_COMMAND += "topicbalena_rootfs_postprocess; "


# Sizes in KiB.
# We need to increase the rootfs size to make space for additional drivers in ROOTFS.
# BalenaOS image has a 700MB max size defined in 'image_types_balena.bbclass'
IMAGE_ROOTFS_SIZE="409600"

# We require access to the git repository here, so we must run outside fakeroot
do_addrevisioninfo() {
git rev-parse --verify --short HEAD >> ${IMAGE_ROOTFS}${sysconfdir}/revision
}
addtask do_addrevisioninfo before do_image after do_rootfs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/bin/sh

#
# Script used by hostapps updater to flash bootloader onto internal media
#

set -o errexit

# machine specific data

bootbin_file="boot.bin"
bootbin_block_size=512
bootbin_seek_blocks=64

itb_file="u-boot.itb"
itb_block_size=512
itb_seek_blocks=24576

bootscr_file="boot.scr"
bootscr_block_size=512
bootscr_seek_blocks=16384

device="/dev/"$(findmnt --noheadings --canonicalize --output SOURCE /mnt/boot/ | xargs lsblk -no pkname)

# we sort the update files list by ascending memory addresses these binaries will be written to
update_files="bootbin itb bootscr"

for i in $update_files; do
current_update_file=$(eval echo \$${i}_file)
block_size=$(eval echo \$${i}_block_size)
seek_blocks=$(eval echo \$${i}_seek_blocks)

# calculate size and md5sum of the binary to update from the update bundle
update_size=$(stat -c%s /resin-boot/$current_update_file)
update_md5sum=$(md5sum /resin-boot/$current_update_file | awk '{print $1'})

# calculate number of bytes to skip when computing the checksum of the data we want to update (i.e. the data already written to $device)
skip_bytes=$((block_size * seek_blocks))

# calculate md5sum of the data already written to $device, using $update_size bytes and skipping $skip_bytes from $device
existing_md5sum=$(dd if=$device skip=$skip_bytes bs=1 count=$update_size status=none | md5sum | awk '{print $1}')

if [ ! "$existing_md5sum" = "$update_md5sum" ] || [ -n "$force_write" ]; then
# we are flashing a binary and let's signal that we need to also flash the remaining binaries
# (if we do not write the remaining binaries when the previous one was written then the board may not boot anymore, due to the nature of the secure boot mechanism on the Rockchip hardware)
force_write=true
echo "Flashing $current_update_file to $device"
dd if=/resin-boot/$current_update_file of=$device conv=fdatasync seek=$seek_blocks bs=$block_size
fi
done
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FILESEXTRAPATHS_append := ":${THISDIR}/files"

HOSTAPP_HOOKS += " \
99-resin-uboot \
99-flash-bootloader \
"
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# write internal balenaOS image to the eMMC
INTERNAL_DEVICE_KERNEL = "mmcblk0"
4 changes: 2 additions & 2 deletions lcbzu9.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ module.exports =

yocto:
machine: 'lcbzu9'
image: 'balena-image'
image: 'balena-image-flasher'
fstype: 'balenaos-img'
version: 'yocto-honister'
deployArtifact: 'balena-image-lcbzu9.balenaos-img'
deployArtifact: 'balena-image-flasher-lcbzu9.balenaos-img'

configuration:
config:
Expand Down
4 changes: 3 additions & 1 deletion scripts/autobuild.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ mkdir -p build/artefacts
for m in *.coffee
do
MACHINE=`basename $m .coffee`
./balena-yocto-scripts/build/balena-build.sh -d ${MACHINE} -s ~/shared_downloads_and_sstate
./balena-yocto-scripts/build/balena-build.sh -d ${MACHINE} -i balena-image -s ~/shared_downloads_and_sstate
./balena-yocto-scripts/build/balena-build.sh -d ${MACHINE} -i balena-image-flasher -s ~/shared_downloads_and_sstate
xz -3 < build/tmp/deploy/images/${MACHINE}/balena-image-${MACHINE}.balenaos-img > build/artefacts/balena-image-${MACHINE}.balenaos-img.xz &
xz -3 < build/tmp/deploy/images/${MACHINE}/balena-image-flasher-${MACHINE}.balenaos-img > build/artefacts/balena-image-flasher-${MACHINE}.balenaos-img.xz &
done
wait