Skip to content
Merged
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
38 changes: 28 additions & 10 deletions bin/prod/create-recore-config
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#!/bin/bash

set -euo pipefail

SERIAL_NR=$1
OFFSET=17408

info() {
echo "[info] $1" >> /var/log/reflash.log
Expand Down Expand Up @@ -52,23 +55,38 @@ fi
info "Calibration file valid"

DEV=`lsblk -n -o NAME | grep 'mmcblk[0-2]$'`
DEV_BOOT="/dev/${DEV}boot0"

echo 0 > "/sys/block/${DEV}boot0/force_ro"

info "Creating boot partition"
dd if=/dev/zero of=/dev/${DEV}boot0
partprobe
printf "g\nn\n\n\n\nw\n" | fdisk /dev/${DEV}boot0
partprobe
mkfs.ext4 -E nodiscard /dev/${DEV}boot0p1
# The kernel doesn't create a child partition node for eMMC boot
# partitions (there's no ${DEV_BOOT}p1), and mount-config/other readers
# loop-mount the raw device directly at a byte offset - so the
# filesystem has to be created the same way, not via fdisk/mkfs on a
# nonexistent partition node.
info "Creating config filesystem"
# Zeroing the whole device this way always ends in "No space left on
# device" once dd hits the end of the block device - that's the
# expected way it finishes, not a real failure.
dd if=/dev/zero of="$DEV_BOOT" bs=1M || true
LOOP=$(losetup -f --show -o "$OFFSET" "$DEV_BOOT")
# metadata_csum (default-on in e2fsprogs 1.47) leaves no room for the
# dir-leaf checksum once the filesystem picks a 1K block size, which it
# does at this size - reads then fail with "Bad message". Disable it.
mkfs.ext4 -F -q -O ^metadata_csum,^64bit -E nodiscard "$LOOP"

mount-config
# mount-config always mounts read-only (it's meant for readers); the
# create path needs to write, so mount the loop device directly rather
# than going through mount-config/unmount-config here.
mkdir -p /mnt/config
mount "$LOOP" /mnt/config
echo "$SNR" > /mnt/config/serial_number

info "Downloading calibration file ${FILE}"
wget $URL
mv ${FILE} /mnt/config
wget -O "/mnt/config/${FILE}" "$URL"

unmount-config
sync
umount /mnt/config
losetup -d "$LOOP"
echo 1 > "/sys/block/${DEV}boot0/force_ro"
info "Done"
2 changes: 1 addition & 1 deletion bin/prod/get-recore-serial-number
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ CONFIG_DIR="${REFLASH_CONFIG_DIR:-/mnt/config}"

mount-config
cat "$CONFIG_DIR/serial_number"
umount "$CONFIG_DIR/"
unmount-config
2 changes: 1 addition & 1 deletion test/bats/getters.bats
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ teardown() { teardown_sandbox; }
mkdir -p "$REFLASH_CONFIG_DIR"
echo "RC-0001-XYZ" > "$REFLASH_CONFIG_DIR/serial_number"
stub_silent mount-config
stub_silent umount
stub_silent unmount-config
run "$PROD_BIN/get-recore-serial-number"
[ "$status" -eq 0 ]
[ "$output" = "RC-0001-XYZ" ]
Expand Down
Loading