Bootloader

Okay, let's build a simple bootloader

We have 256 pages, 4KiB each, for a total of 1MiB.

I rarely need more than like... 64KiB, so let's just chop it up into for sections:

  • Section 0:
    • Pages 0..64
    • Bootloader goes here (fixed addr)
  • Section 1:
    • Pages 64..128
    • This is the "active" sector
    • Application goes here (fixed addr)
  • Section 2:
    • Pages 128..192
    • This is "backup page A"
  • Section 3:
    • Pages 192..256
    • This is "backup page B"

The bootloader

The bootloader is really simple. It just does the "flash to active section" operation, and jumping to main.

It should:

  • On boot, check and see if a new image was flashed (some kind of header metadata?)
    • If so, check the validity, at least:
      • Checksum/signature of the image
      • Maybe check the reset vector is within section 1?
    • Erase Section 1
    • Flash Section N to section 1
    • Write metadata page
    • GOTO boot
  • Check and see if an image was just flashed, but didn't meet "live" check
    • If so, check the validity of the "other" image
    • If valid
      • Do the flashing steps above
    • If not:
      • Blinky forever :(
      • TODO: Serial bootloader recovery
  • Boot
    • set vtor
    • set "info passing" page
    • bootload

Data Layouts

Section 0

It's just a regular app image. Nothing special.

Section 1

  • Page 64: Metadata
  • Page 65..128: Application

Metadata:

StartEndLenName
0000001616Image UUID
0016003216Image Poly1305 Tag
003200364Image Len (pages)
............
012801324Boot sequence number
013201364Has been flashed tagword
013601404Has fully booted tagword

Section 2/3

  • Page 64: Metadata
  • Page 65..128: Application

Metadata:

StartEndLenName
0000001616Image UUID
0016003216Image Poly1305 Tag
003200364Image Len (pages)
............
012801324Boot sequence number
013201364Has been flashed tagword
013601404Has fully booted tagword

Memory comms

Put... somewhere in memory?

| Start | End | Len | Name | | 0000 | 0004 | 4 | Pointer to Section 1 Hdr (Self) | | 0004 | 0008 | 4 | Pointer to Section N Hdr (Self) | | 0008 | 0012 | 4 | Pointer to Section M Hdr (Other) | | 0012 | 0013 | 1 | Is first boot? |

Thinking slow

T0

  • Bootload
  • Active - 001
  • Slot A - 001
  • Slot B - EMPTY

T1

  • Bootload
  • Active - 002
  • Slot A - 001 <-- should be written, needs erase
  • Slot B - 002

Thinking flow

how am I gunna bootload a dom? is it way easier?

Sub Dom <--------- "Erase partition" ---------> "Ack" (5ms erase) ---------> "Erase 1% complete..." (15ms wait) (5ms erase) ---------> "Erase 2% complete..." ... ---------> "Erase completed" <--------- "Begin bootload (metadata)" ---------> "Ack" ---------> "Gimme 0..256" <--------- 256 byte payload (2.5ms write) (7.5ms wait) ---------> "Gimme 256..512" <--------- 256 byte payload (2.5ms write) (7.5ms wait) ... ---------> "Bootload complete" <--------- "Reset" (device resets) (5s active erase) (2.5s active write) (device boots)