51
Upgrade without Bricking Arnout Vandecappelle © 2012 Essensium N.V. This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License http://mind.be/content/Presentation_Upgrade-without-Bricking.pdf or .odp

Upgrade without Bricking · Efficient Upgrading in a Purely Functional Component Deployment Model. In George Heineman et al. (Ed.), Eighth International SIGSOFT Symposium on Component-based

  • Upload
    others

  • View
    7

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Upgrade without Bricking · Efficient Upgrading in a Purely Functional Component Deployment Model. In George Heineman et al. (Ed.), Eighth International SIGSOFT Symposium on Component-based

Upgrade without Bricking

Arnout Vandecappelle

© 2012 Essensium N.V.This work is licensed under a

Creative Commons Attribution-ShareAlike 3.0 Unported License

http://mind.be/content/Presentation_Upgrade-without-Bricking.pdf or .odp

Page 2: Upgrade without Bricking · Efficient Upgrading in a Purely Functional Component Deployment Model. In George Heineman et al. (Ed.), Eighth International SIGSOFT Symposium on Component-based

You never knowwhere your product will be used

High-precision GNSS receiver

Page 3: Upgrade without Bricking · Efficient Upgrading in a Purely Functional Component Deployment Model. In George Heineman et al. (Ed.), Eighth International SIGSOFT Symposium on Component-based

You never knowwhere your product will be used

Page 4: Upgrade without Bricking · Efficient Upgrading in a Purely Functional Component Deployment Model. In George Heineman et al. (Ed.), Eighth International SIGSOFT Symposium on Component-based

What if you install new firmwareon remote systems?

Page 5: Upgrade without Bricking · Efficient Upgrading in a Purely Functional Component Deployment Model. In George Heineman et al. (Ed.), Eighth International SIGSOFT Symposium on Component-based

What if you install new firmwareon remote systems?

Murphy's Law

Page 6: Upgrade without Bricking · Efficient Upgrading in a Purely Functional Component Deployment Model. In George Heineman et al. (Ed.), Eighth International SIGSOFT Symposium on Component-based

What if you install new firmwareon remote systems?

Murphy's Law

Page 7: Upgrade without Bricking · Efficient Upgrading in a Purely Functional Component Deployment Model. In George Heineman et al. (Ed.), Eighth International SIGSOFT Symposium on Component-based

Upgrade without Bricking

Arnout Vandecappelle

© 2012 Essensium N.V.This work is licensed under a

Creative Commons Attribution-ShareAlike 3.0 Unported License

http://mind.be/content/Presentation_Upgrade-without-Bricking.pdf or .odp

Page 8: Upgrade without Bricking · Efficient Upgrading in a Purely Functional Component Deployment Model. In George Heineman et al. (Ed.), Eighth International SIGSOFT Symposium on Component-based

Overview

1 Failure mechanisms● Power failure● Bad firmware● Communication errors

2 Boot loader upgrade

3 Package-based upgrade

Page 9: Upgrade without Bricking · Efficient Upgrading in a Purely Functional Component Deployment Model. In George Heineman et al. (Ed.), Eighth International SIGSOFT Symposium on Component-based

Overview

1 Failure mechanisms● Power failure● Bad firmware● Communication errors

2 Boot loader upgrade

3 Package-based upgrade

Page 10: Upgrade without Bricking · Efficient Upgrading in a Purely Functional Component Deployment Model. In George Heineman et al. (Ed.), Eighth International SIGSOFT Symposium on Component-based

Power failure

Power fails during upgrade

⇒ new firmware only partially written

Solutions:

Add fail-safe firmware

Detect failed power

Atomic update of firmware images

Use journalling filesystemfor writable data

Page 11: Upgrade without Bricking · Efficient Upgrading in a Purely Functional Component Deployment Model. In George Heineman et al. (Ed.), Eighth International SIGSOFT Symposium on Component-based

Detecting power failure:Switch to fail-safe firmware

bootloader

currentfirmware

configfiles

fail-safeFW

1. Boot current firmware

Page 12: Upgrade without Bricking · Efficient Upgrading in a Purely Functional Component Deployment Model. In George Heineman et al. (Ed.), Eighth International SIGSOFT Symposium on Component-based

Detecting power failure:Switch to fail-safe firmware

bootloader

configfiles

fail-safeFW

2. Switch to fail-safe

currentfirmware

Page 13: Upgrade without Bricking · Efficient Upgrading in a Purely Functional Component Deployment Model. In George Heineman et al. (Ed.), Eighth International SIGSOFT Symposium on Component-based

Detecting power failure:Switch to fail-safe firmware

bootloader

newfirmware

configfiles

fail-safeFW

3. Overwrite firmware

Page 14: Upgrade without Bricking · Efficient Upgrading in a Purely Functional Component Deployment Model. In George Heineman et al. (Ed.), Eighth International SIGSOFT Symposium on Component-based

Detecting power failure:Switch to fail-safe firmware

bootloader

configfiles

fail-safeFW

4. Fail-safe restarts upgrade

newfirmware

Page 15: Upgrade without Bricking · Efficient Upgrading in a Purely Functional Component Deployment Model. In George Heineman et al. (Ed.), Eighth International SIGSOFT Symposium on Component-based

Detecting power failure:Switch to fail-safe firmware

bootloader

configfiles

fail-safeFW

5. back to new firmware

newfirmware

Page 16: Upgrade without Bricking · Efficient Upgrading in a Purely Functional Component Deployment Model. In George Heineman et al. (Ed.), Eighth International SIGSOFT Symposium on Component-based

Can bootloader switch to fail-safeatomically?

Grub, extlinuxOverwrite a file⇒Make sure overwrite is atomic, using rename(2)⇒Relies on atomicity of underlying

filesystem implementatione.g. ext4: mount with barrier=1

U-BootOverwrite environment

⇒ Catastrophic if power fails during environment write

Page 17: Upgrade without Bricking · Efficient Upgrading in a Purely Functional Component Deployment Model. In George Heineman et al. (Ed.), Eighth International SIGSOFT Symposium on Component-based

Atomic switchingthrough boot-loader's fallback

All boot loaders have a fallback mechanism

Destroy normal boot before starting the upgrade

Put the normal boot in a separateboot-loader script,so it can be destroyed independently

Create boot script atomically

Page 18: Upgrade without Bricking · Efficient Upgrading in a Purely Functional Component Deployment Model. In George Heineman et al. (Ed.), Eighth International SIGSOFT Symposium on Component-based

gupies projectcollects upgrade tools

Generic UPgrade Infrastructure for Embedded Systems

https://gitorious.org/gupies

Generate boot scripts (atomically)

Boot loader config to use boot script and failsafe

Upgrade skeleton to write image andboot script

Page 19: Upgrade without Bricking · Efficient Upgrading in a Purely Functional Component Deployment Model. In George Heineman et al. (Ed.), Eighth International SIGSOFT Symposium on Component-based

Overview

1 Failure mechanisms● Power failure● Bad firmware● Communication errors

2 Boot loader upgrade

3 Package-based upgrade

Page 20: Upgrade without Bricking · Efficient Upgrading in a Purely Functional Component Deployment Model. In George Heineman et al. (Ed.), Eighth International SIGSOFT Symposium on Component-based

Bad firmware

New firmware fails on some devices

Solutions:

Fall back on previous (known good) firmware

Fail-safe firmware that can do upgrades

Upgrade script included in upgrade image

Watchdog reboot +boot fail-safe after bad boot

Page 21: Upgrade without Bricking · Efficient Upgrading in a Purely Functional Component Deployment Model. In George Heineman et al. (Ed.), Eighth International SIGSOFT Symposium on Component-based

Typical flash layoutwith known good and fail-safe firmware

bootloader

newfirmware

known goodfirmware

configfiles

fail-safeFW

fallback fallback

watchdog

Page 22: Upgrade without Bricking · Efficient Upgrading in a Purely Functional Component Deployment Model. In George Heineman et al. (Ed.), Eighth International SIGSOFT Symposium on Component-based

Typical flash layoutwith known good and fail-safe firmware

bootloader

newfirmware

known goodfirmware

configfiles

fail-safeFW

fallback fallback

watchdog

Page 23: Upgrade without Bricking · Efficient Upgrading in a Purely Functional Component Deployment Model. In George Heineman et al. (Ed.), Eighth International SIGSOFT Symposium on Component-based

Boot procedure with watchdog

bootloader

newfirmware

known goodfirmware

configfiles

fail-safeFW

Page 24: Upgrade without Bricking · Efficient Upgrading in a Purely Functional Component Deployment Model. In George Heineman et al. (Ed.), Eighth International SIGSOFT Symposium on Component-based

Boot procedure with watchdog

bootloader

newfirmware

known goodfirmware

configfiles

fail-safeFW

Reboot when watchdog timer expiresReset watchdog if firmware runs wellForce reboot if firmware does not run well

Page 25: Upgrade without Bricking · Efficient Upgrading in a Purely Functional Component Deployment Model. In George Heineman et al. (Ed.), Eighth International SIGSOFT Symposium on Component-based

gupies projecthas infrastructure for known-good

Keep track of valid firmware imagestaking into account multiple components(kernel, rootfs)

Clean up old components

Page 26: Upgrade without Bricking · Efficient Upgrading in a Purely Functional Component Deployment Model. In George Heineman et al. (Ed.), Eighth International SIGSOFT Symposium on Component-based

Overview

1 Failure mechanisms● Power failure● Bad firmware● Communication errors

2 Boot loader upgrade

3 Package-based upgrade

Page 27: Upgrade without Bricking · Efficient Upgrading in a Purely Functional Component Deployment Model. In George Heineman et al. (Ed.), Eighth International SIGSOFT Symposium on Component-based

Communication failures:Incomplete upgrade file

Page 28: Upgrade without Bricking · Efficient Upgrading in a Purely Functional Component Deployment Model. In George Heineman et al. (Ed.), Eighth International SIGSOFT Symposium on Component-based

Communication failures:False upgrade file injection

Page 29: Upgrade without Bricking · Efficient Upgrading in a Purely Functional Component Deployment Model. In George Heineman et al. (Ed.), Eighth International SIGSOFT Symposium on Component-based

Solution for communication failures:verify data before writing

private keygpg --sign <file>

public keygpg < <file> > <out>

Page 30: Upgrade without Bricking · Efficient Upgrading in a Purely Functional Component Deployment Model. In George Heineman et al. (Ed.), Eighth International SIGSOFT Symposium on Component-based

Take care with signed upgrade files

Make it possible to install new public keysSigner key may expire

Give third parties possibility to create upgrades

Avoid tivoization

Make it possible to install revocations

Signer key may be stolen

Make new keys and revocations accessible to fail-safe

Page 31: Upgrade without Bricking · Efficient Upgrading in a Purely Functional Component Deployment Model. In George Heineman et al. (Ed.), Eighth International SIGSOFT Symposium on Component-based

Split in chunksfor streaming upgrade

bootloader

newfirmware

configfiles

fail-safeFW

newfirmware

No need to keepentire upgrade in memory

Early abort in case of failure

Page 32: Upgrade without Bricking · Efficient Upgrading in a Purely Functional Component Deployment Model. In George Heineman et al. (Ed.), Eighth International SIGSOFT Symposium on Component-based

gupies has infrastructurefor chunked upgrade streams

GUP format

Code to generate/parse GUP

Verify GUP with GPG

Create GUP script from fragments

Page 33: Upgrade without Bricking · Efficient Upgrading in a Purely Functional Component Deployment Model. In George Heineman et al. (Ed.), Eighth International SIGSOFT Symposium on Component-based

GUP format makes streaming possible# SU2 HEADER START #totalsize=70568...# PAYLOAD 0000 #...# HASHES 0000 #bde893df2da0...# PAYLOAD 0001 #...# SU2 HEADER END #-----BEGIN PGP SIGNATURE-----...-----END PGP SIGNATURE-----#! /bin/sh...

Page 34: Upgrade without Bricking · Efficient Upgrading in a Purely Functional Component Deployment Model. In George Heineman et al. (Ed.), Eighth International SIGSOFT Symposium on Component-based

Overview

1 Failure mechanisms● Power failure● Bad firmware● Communication errors

2 Boot loader upgrade

3 Package-based upgrade

Page 35: Upgrade without Bricking · Efficient Upgrading in a Purely Functional Component Deployment Model. In George Heineman et al. (Ed.), Eighth International SIGSOFT Symposium on Component-based

Upgrade of boot loader is never safe

If boot loader is broken

No recovery is possible

⇒ don't put bugs in the boot loader

⇒ don't put features in the boot loader

Page 36: Upgrade without Bricking · Efficient Upgrading in a Purely Functional Component Deployment Model. In George Heineman et al. (Ed.), Eighth International SIGSOFT Symposium on Component-based

Don't put features in boot loader

Fancy boot loader is nice in development

Don't rely on it in deploymentexcept for fallback

Put upgrade intelligencein upgrade file itself

Page 37: Upgrade without Bricking · Efficient Upgrading in a Purely Functional Component Deployment Model. In George Heineman et al. (Ed.), Eighth International SIGSOFT Symposium on Component-based

Upgrade of boot loaderwith backup media

ROMboot

bootloader

fail-safeFW

bootloader

newfirmware

known goodfirmware

configfiles

NANDFlash

SerialFlash

Page 38: Upgrade without Bricking · Efficient Upgrading in a Purely Functional Component Deployment Model. In George Heineman et al. (Ed.), Eighth International SIGSOFT Symposium on Component-based

Upgrade of boot loaderwith backup media

ROMboot

bootloader

fail-safeFW

bootloader

newfirmware

known goodfirmware

configfiles

NANDFlash

SerialFlash

1. Destroy old boot loader

Page 39: Upgrade without Bricking · Efficient Upgrading in a Purely Functional Component Deployment Model. In George Heineman et al. (Ed.), Eighth International SIGSOFT Symposium on Component-based

Upgrade of boot loaderwith backup media

ROMboot

bootloader

fail-safeFW

bootloader

newfirmware

known goodfirmware

configfiles

NANDFlash

SerialFlash

1. Destroy old boot loader

2. Write new bootloader

Page 40: Upgrade without Bricking · Efficient Upgrading in a Purely Functional Component Deployment Model. In George Heineman et al. (Ed.), Eighth International SIGSOFT Symposium on Component-based

Upgrade of boot loaderwith backup media

ROMboot

bootloader

fail-safeFW

bootloader

newfirmware

known goodfirmware

configfiles

NANDFlash

SerialFlash

1. Destroy old boot loader

2. Write new bootloader

3. In case of failure,will boot from backup media

Page 41: Upgrade without Bricking · Efficient Upgrading in a Purely Functional Component Deployment Model. In George Heineman et al. (Ed.), Eighth International SIGSOFT Symposium on Component-based

Upgrade of boot loaderwith backup media

ROMboot

bootloader

fail-safeFW

bootloader

newfirmware

known goodfirmware

configfiles

NANDFlash

SerialFlash

1. Destroy old boot loader

2. Write new boot loader

3. In case of failure,will boot from backup media

4. Write magic number,so new boot loader is selected

Page 42: Upgrade without Bricking · Efficient Upgrading in a Purely Functional Component Deployment Model. In George Heineman et al. (Ed.), Eighth International SIGSOFT Symposium on Component-based

Overview

1 Failure mechanisms● Power failure● Bad firmware● Communication errors

2 Boot loader upgrade

3 Package-based upgrade

Page 43: Upgrade without Bricking · Efficient Upgrading in a Purely Functional Component Deployment Model. In George Heineman et al. (Ed.), Eighth International SIGSOFT Symposium on Component-based

Packaged-based upgradesare not ideal for embedded systems

Use a package manager (ipkg, opkg, dpkg, rpm)and upgrade individual packages

Advantage: smaller upgrade files

Disadvantages:

Difficult to predict what is installed exactly⇒don't rely on version numbers,

but use manifest with exact package versions

More places where something can go wrong (Murphy)

No package manager is truly atomicclosest: http://nixos.org

Page 44: Upgrade without Bricking · Efficient Upgrading in a Purely Functional Component Deployment Model. In George Heineman et al. (Ed.), Eighth International SIGSOFT Symposium on Component-based

Nix package manager is largely atomic

Eelco Dolstra. Efficient Upgrading in a Purely Functional Component Deployment Model. In George Heineman et al. (Ed.), Eighth International SIGSOFT Symposium on Component-based Software Engineering (CBSE 2005), volume 3489 of Lecture Notes in Computer Science, pages 219–234, St. Louis, Missouri, USA. Springer-Verlag, May 2005. © Springer-Verlag.

PATH

Page 45: Upgrade without Bricking · Efficient Upgrading in a Purely Functional Component Deployment Model. In George Heineman et al. (Ed.), Eighth International SIGSOFT Symposium on Component-based

Atomic upgrade is possiblewith union mount

unifiedrootfs

tmpfs (rw)

tmpfs (rw)overlay (ro)

orig rootfs (ro)

• aufs• unionfs-fuse• union mount

Page 46: Upgrade without Bricking · Efficient Upgrading in a Purely Functional Component Deployment Model. In George Heineman et al. (Ed.), Eighth International SIGSOFT Symposium on Component-based

Atomic upgrade is possiblewith union mount

unifiedrootfs

tmpfs (rw)

tmpfs (rw)old overlay (ro)

orig rootfs (ro)

new overlay (ro)

• aufs• unionfs-fuse• union mount

dpkg

Page 47: Upgrade without Bricking · Efficient Upgrading in a Purely Functional Component Deployment Model. In George Heineman et al. (Ed.), Eighth International SIGSOFT Symposium on Component-based

Atomic upgrade is possiblewith union mount

unifiedrootfs

tmpfs (rw)

tmpfs (rw)old overlay (ro)

orig rootfs (ro)

new overlay (ro)

• aufs• unionfs-fuse• union mount

Page 48: Upgrade without Bricking · Efficient Upgrading in a Purely Functional Component Deployment Model. In George Heineman et al. (Ed.), Eighth International SIGSOFT Symposium on Component-based

Gupies provides infrastructurefor union mount

Script to union-mount at boot time

Components passed through /proc/cmdline

Boot script sets kernel args appropriately

Page 49: Upgrade without Bricking · Efficient Upgrading in a Purely Functional Component Deployment Model. In George Heineman et al. (Ed.), Eighth International SIGSOFT Symposium on Component-based

Conclusions

Take into account different failure mechanisms: bad firmware, power failure, communication failure, flash corruption

Put as much as possible in upgrade file

No single ideal upgrade mechanism existsSome things really depend on the hardware

gupies project collects upgrade infrastructure

Page 50: Upgrade without Bricking · Efficient Upgrading in a Purely Functional Component Deployment Model. In George Heineman et al. (Ed.), Eighth International SIGSOFT Symposium on Component-based

Take your time to get the upgrade system right!

Take into account different failure mechanisms: bad firmware, power failure, communication failure, flash corruption

Put as much as possible in upgrade file

No single ideal upgrade mechanism existsSome things really depend on the hardware

gupies project collects upgrade infrastructure

Page 51: Upgrade without Bricking · Efficient Upgrading in a Purely Functional Component Deployment Model. In George Heineman et al. (Ed.), Eighth International SIGSOFT Symposium on Component-based

www.mind.be

www.essensium.com

Essensium NVMind - Embedded Software DivisionGaston Geenslaan 9, B-3001 Leuven

Tel : +32 16-28 65 00Fax : +32 16-28 65 01

email : [email protected]

http://mind.be/content/Presentation_Upgrade-without-Bricking.pdf or .odp