Safe Upgrade of Embedded Systems Arnout Vandecappelle

Safe Upgrade of Embedded Systems Arnout Vandecappelle

Safe upgrade of embedded systems 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_Safe-Upgrade.pdf or .odp You never know where your product will be used High-precision GNSS receiver Safe upgrade Arnout Vandecappelle You never know where your product will be used Safe upgrade Arnout Vandecappelle What if you install new firmware on remote systems? Safe upgrade Arnout Vandecappelle What if you install new firmware on remote systems? Murphy's Law Safe upgrade Arnout Vandecappelle What if you install new firmware on remote systems? Murphy's Law Safe upgrade Arnout Vandecappelle Safe upgrade of embedded systems 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_Safe-Upgrade.pdf or .odp Overview 1 Failure mechanisms ● Power failure ● Bad firmware ● Flash corruption ● Communication errors 2 Boot loader upgrade 3 Package-based upgrade Safe upgrade Arnout Vandecappelle 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 filesystem for writable data Safe upgrade Arnout Vandecappelle Detecting power failure: Switch to fail-safe firmware 1. Boot current firmware fail- boot current config safe loader firmware files FW Safe upgrade Arnout Vandecappelle Detecting power failure: Switch to fail-safe firmware 2. Switch to fail-safe fail- boot current config safe loader firmware files FW Safe upgrade Arnout Vandecappelle Detecting power failure: Switch to fail-safe firmware fail- boot new config safe loader firmware files FW 3. Overwrite firmware Safe upgrade Arnout Vandecappelle Detecting power failure: Switch to fail-safe firmware 4. Fail-safe restarts upgrade fail- boot new config safe loader firmware files FW Safe upgrade Arnout Vandecappelle Detecting power failure: Switch to fail-safe firmware 5. back to new firmware fail- boot new config safe loader firmware files FW Safe upgrade Arnout Vandecappelle Can bootloader switch to fail-safe atomically? Grub, extlinux Overwrite a file ⇒ Make sure overwrite is atomic, using rename(2) ⇒ Relies on atomicity of underlying filesystem implementation e.g. ext4: mount with barrier=1 U-Boot Overwrite environment ⇒ Catastrophic if power fails during environment write Use CRC to validate new image Safe upgrade Arnout Vandecappelle Detecting power failure: CRC check check CRC fallback fail- boot new config safe loader firmware files FW Safe upgrade Arnout Vandecappelle Detecting power failure: CRC check doesn't (always) work check CRC fallback fail- boot new config safe loader firmware files FW 60MB ⇒ several minutes to check Safe upgrade Arnout Vandecappelle Detecting power failure: CRC check of header only check CRC fallback fail- boot current config safe loader firmware files FW Safe upgrade Arnout Vandecappelle Detecting power failure with CRC: Write images non-linearly check CRC fallback fail- boot current config safe loader firmware files FW Safe upgrade Arnout Vandecappelle Detecting power failure with CRC: Write images non-linearly check CRC fallback fail- boot new config safe loader firmware files FW Safe upgrade Arnout Vandecappelle UBI provides NAND-aware atomic updates fail- boot new config safe loader firmware files FW fail- boot UBI safe loader FW part. part. partition 2 1 3 MTD device (NAND Flash) Safe upgrade Arnout Vandecappelle 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 Safe upgrade Arnout Vandecappelle Typical flash layout with known good and fail-safe firmware fallback fallback fail- boot new known good config safe loader firmware firmware files FW watchdog Safe upgrade Arnout Vandecappelle Boot procedure with watchdog fail- boot new known good config safe loader firmware firmware files FW Safe upgrade Arnout Vandecappelle Boot procedure with watchdog fail- boot new known good config safe loader firmware firmware files FW Reboot when watchdog timer expires Reset watchdog if firmware runs well Force reboot if firmware does not run well Safe upgrade Arnout Vandecappelle Overview 1 Failure mechanisms ● Bad firmware ● Power failure ● Flash corruption ● Communication errors 2 Boot loader upgrade 3 Package-based upgrade Safe upgrade Arnout Vandecappelle Flash corruption Flash storage is unreliable: each individual bit becomes unusable after N writes Error correcting codes (ECC): detect & correct bit errors when reading Wear levelling: don't reuse the same block all the time Bad blocks: stop using a block if too many errors Flash filesystem must handle these problems Safe upgrade Arnout Vandecappelle UBI provides safe NAND writing current previous fail- boot config firmware firmware safe loader files volume volume FW fail- boot UBI safe loader FW part. part. partition 2 1 3 MTD device (NAND Flash) Safe upgrade Arnout Vandecappelle UBI provides safe upgrade current new fail- boot config firmware firmware safe loader files volume volume FW fail- boot UBI safe loader FW part. part. partition 2 1 3 MTD device (NAND Flash) Safe upgrade Arnout Vandecappelle Intermezzo: SD cards etc. are bad news current new fail- boot config firmware firmware safe loader files kernel + initramfs kernel + initramfs FW part. part. partition 2 (ext4fs) 1 3 SD card controller NAND bank 1 NAND bank 2 Safe upgrade Arnout Vandecappelle Intermezzo: SD cards etc. are bad news current new fail- boot config firmware firmware safe loader files kernel + initramfs kernel + initramfs FW part. part. partition 2 (ext4fs) 1 3 SD card controller NAND bank 1 NAND bank 2 See http://elinux.org/images/4/49/Elc2011_bergmann.pdf Safe upgrade Arnout Vandecappelle Intermezzo: SD cards etc. are bad news Atomic rename at ext4fs level current new fail- boot config firmware firmware safe loader files kernel + initramfs kernel + initramfs FW part. part. partition 2 (ext4fs) 1 3 SD card controller NAND bank 1 NAND bank 2 See http://elinux.org/images/4/49/Elc2011_bergmann.pdf Safe upgrade Arnout Vandecappelle Intermezzo: SD cards etc. are bad news Atomic rename at ext4fs level current new fail- boot config firmware firmware safe loader files kernel + initramfs kernel + initramfs FW part. part. partition 2 (ext4fs) 1 3 No real control of what happens SD card controller NAND bank 1 NAND bank 2 See http://elinux.org/images/4/49/Elc2011_bergmann.pdf Safe upgrade Arnout Vandecappelle Overview 1 Failure mechanisms ● Bad firmware ● Power failure ● Flash corruption ● Communication errors 2 Boot loader upgrade 3 Package-based upgrade Safe upgrade Arnout Vandecappelle Communication failures: Incomplete upgrade file Safe upgrade Arnout Vandecappelle Communication failures: False upgrade file injection Safe upgrade Arnout Vandecappelle Solution for communication failures: verify data before writing private key gpg --sign <file> public key gpg < <file> > <out> Safe upgrade Arnout Vandecappelle Take care with signed upgrade files Make it possible to install new public keys . Signer 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 If upgrade file doesn't fit in memory: . Split it in chunks . Add an index (to checkSafe upgrade integrityArnout Vandecappelle ) Overview 1 Failure mechanisms ● Bad firmware ● Power failure ● Flash corruption ● Communication errors 2 Boot loader upgrade 3 Package-based upgrade Safe upgrade Arnout Vandecappelle Upgrade of boot loader is never safe If boot loader is broken No recovery is possible (unless a ROM boot loader comes first) ⇒ don't put bugs in the boot loader ⇒ don't put features in the boot loader Safe upgrade Arnout Vandecappelle Upgrade of boot loader with backup media NAND boot new known good config Flash loader firmware firmware files ROM boot fail- Serial boot safe Flash loader FW Safe upgrade Arnout Vandecappelle Upgrade of boot loader with backup media NAND boot new known good config Flash loader firmware firmware files ROM 1. Destroy old boot loader boot fail- Serial boot safe Flash loader FW Safe upgrade Arnout Vandecappelle Upgrade of boot loader with backup media NAND boot new known good config Flash loader firmware firmware files ROM 1. Destroy old boot loader boot 2. Write new bootloader fail- Serial boot safe Flash loader FW Safe upgrade Arnout Vandecappelle Upgrade of boot loader with backup media NAND boot new known good config Flash loader firmware firmware files ROM 1. Destroy old boot loader boot 2. Write new bootloader 3. In case of failure, fail- Serial boot will boot from backup safe Flash loader media FW Safe upgrade Arnout Vandecappelle Upgrade of boot loader with backup media NAND boot new known good config Flash loader firmware firmware files ROM 1. Destroy old boot loader boot 2. Write new boot loader 3. In case of failure, fail- Serial boot will boot from backup safe Flash loader media FW 4. Write magic number, Safe upgradesoArnout new Vandecappelle boot loader is selected Overview 1 Failure mechanisms ● Bad firmware ● Power failure ● Flash corruption ● Communication errors 2 Boot loader upgrade 3 Package-based upgrade Safe upgrade Arnout Vandecappelle Packaged-based upgrades

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    52 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us