C12 Embedded systems in MicroPython and C · Practice
Bootloaders and firmware updates
Problems dealt one at a time, with new numbers every time. The kinds you miss come back more often, and you can keep going as long as you like.
Check
A device has 512 KB of flash, a 16 KB bootloader and 8 KB of records. How large can each of two A/B application slots be?
Check
How long does it take to send a 200 KB image over a UART at 9600 baud with 10 bits per byte?
Write units the way you normally would: 1.5 s and 1500 ms are the same answer.
Check
Erasing room for a 210 KB image in flash with 8 KB pages, each taking 40 ms, takes how long?
Write units the way you normally would: 1.5 s and 1500 ms are the same answer.
Check
A bootloader checks a CRC over 64 KB at 4 cycles per byte on a 200 MHz core. How long does that take?
Write units the way you normally would: 1.5 ms, 1500 µs and 0.0015 s are the same answer.
Check
A data logger shares its flash pages with firmware updates. Each update erases every page of one A/B slot once; the flash endures 10000 erase cycles per page.
(a)
How many updates can the device take before a slot's pages wear out, alternating slots?
(b)
At 2 updates per day, how many years is that?
Check
Simulate power failures during A/B updates. State: two slots, each None (erased), 'partial', or a version number; and active, the committed slot index. An update to version v runs these steps in order on the inactive slot: erase (slot becomes None), write (becomes 'partial'), finish (becomes v), commit (active switches to it). Write update(state, v, fail_at) that performs steps until index fail_at (0 to 4; 4 means no failure), and boot(state) returning the version that would run, or None if the active slot isn't a complete version. Starting from slots [1, None], active 0, apply 200 updates with fail_at = rng.randrange(5) (rng = random.Random(seed)) and version numbers 2, 3, ...; set bricked (how many times boot returned None after an update) and final (the running version at the end).
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
With 128 KB of flash and an 8 KB bootloader (no records), how big can each A/B slot be?
Check
How long does a 50 KB transfer take at 57600 baud?
Write units the way you normally would: 1.5 s and 1500 ms are the same answer.
A kind of problem counts as solid once you've got it right on the first try twice in a row. Back to the lesson · Practice every topic in C12