OS Updater improvements (#19914)

* Clear hashes before swapping

* add retry logic

* better retry logic

* actually fail on retries exceeded
pull/19916/head
Willem Melching 4 years ago committed by GitHub
parent 9f2088e2c3
commit fe91b8a1b4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 12
      launch_chffrplus.sh
  2. 45
      selfdrive/hardware/tici/agnos.py

@ -146,6 +146,12 @@ function tici_init {
if [[ "$SYSTEM_HASH" == "$SYSTEM_HASH_EXPECTED" && "$BOOT_HASH" == "$BOOT_HASH_EXPECTED" ]]; then if [[ "$SYSTEM_HASH" == "$SYSTEM_HASH_EXPECTED" && "$BOOT_HASH" == "$BOOT_HASH_EXPECTED" ]]; then
echo "Swapping active slot to $OTHER_SLOT_NUMBER" echo "Swapping active slot to $OTHER_SLOT_NUMBER"
# Clean hashes before swapping to prevent looping
dd if=/dev/zero of="/dev/disk/by-partlabel/system$OTHER_SLOT" bs=1 seek="$SYSTEM_SIZE" count=64
dd if=/dev/zero of="/dev/disk/by-partlabel/boot$OTHER_SLOT" bs=1 seek="$BOOT_SIZE" count=64
sync
abctl --set_active "$OTHER_SLOT_NUMBER" abctl --set_active "$OTHER_SLOT_NUMBER"
sleep 1 sleep 1
@ -154,6 +160,12 @@ function tici_init {
echo "Hash mismatch, downloading agnos" echo "Hash mismatch, downloading agnos"
if $DIR/selfdrive/hardware/tici/agnos.py $MANIFEST; then if $DIR/selfdrive/hardware/tici/agnos.py $MANIFEST; then
echo "Download done, swapping active slot to $OTHER_SLOT_NUMBER" echo "Download done, swapping active slot to $OTHER_SLOT_NUMBER"
# Clean hashes before swapping to prevent looping
dd if=/dev/zero of="/dev/disk/by-partlabel/system$OTHER_SLOT" bs=1 seek="$SYSTEM_SIZE" count=64
dd if=/dev/zero of="/dev/disk/by-partlabel/boot$OTHER_SLOT" bs=1 seek="$BOOT_SIZE" count=64
sync
abctl --set_active "$OTHER_SLOT_NUMBER" abctl --set_active "$OTHER_SLOT_NUMBER"
fi fi

@ -76,19 +76,7 @@ def unsparsify(f):
raise Exception("Unhandled sparse chunk type") raise Exception("Unhandled sparse chunk type")
def flash_agnos_update(manifest_path, cloudlog, spinner=None): def flash_partition(cloudlog, spinner, target_slot, partition):
update = json.load(open(manifest_path))
current_slot = subprocess.check_output(["abctl", "--boot_slot"], encoding='utf-8').strip()
target_slot = "_b" if current_slot == "_a" else "_a"
target_slot_number = "0" if target_slot == "_a" else "1"
cloudlog.info(f"Current slot {current_slot}, target slot {target_slot}")
# set target slot as unbootable
os.system(f"abctl --set_unbootable {target_slot_number}")
for partition in update:
cloudlog.info(f"Downloading and writing {partition['name']}") cloudlog.info(f"Downloading and writing {partition['name']}")
downloader = StreamingDecompressor(partition['url']) downloader = StreamingDecompressor(partition['url'])
@ -129,6 +117,37 @@ def flash_agnos_update(manifest_path, cloudlog, spinner=None):
os.sync() os.sync()
out.write(partition['hash_raw'].lower().encode()) out.write(partition['hash_raw'].lower().encode())
def flash_agnos_update(manifest_path, cloudlog, spinner=None):
update = json.load(open(manifest_path))
current_slot = subprocess.check_output(["abctl", "--boot_slot"], encoding='utf-8').strip()
target_slot = "_b" if current_slot == "_a" else "_a"
target_slot_number = "0" if target_slot == "_a" else "1"
cloudlog.info(f"Current slot {current_slot}, target slot {target_slot}")
# set target slot as unbootable
os.system(f"abctl --set_unbootable {target_slot_number}")
for partition in update:
success = False
for retries in range(10):
try:
flash_partition(cloudlog, spinner, target_slot, partition)
success = True
break
except requests.exceptions.RequestException:
spinner.update("Waiting for internet...")
cloudlog.info(f"Failed to download {partition['name']}, retrying ({retries})")
time.sleep(10)
if not success:
cloudlog.info(f"Failed to flash {partition['name']}, aborting")
raise Exception("Maximum retries exceeded")
cloudlog.info(f"AGNOS ready on slot {target_slot}") cloudlog.info(f"AGNOS ready on slot {target_slot}")

Loading…
Cancel
Save