A microcontroller (2) comprises a processor (3) and a memory (11). The memory (11) comprises a first-stage bootloader region (41), a first second-stage bootloader region (43), a second second-stage bootloader region (45), and an application region (47) for storing an application (29). A first-stage bootloader (25) is stored in the first-stage bootloader region (41) and an active second-stage bootloader (27) is stored in an active one of the first (43) and second (45) second-stage bootloader regions. The processor (3) is configured to execute instructions from the first-stage bootloader (25) when the microcontroller (2) is reset. The first-stage bootloader (25) comprises instructions for transferring execution from the first-stage bootloader (25) to the active second-stage bootloader (27), which comprises instructions for transferring execution to an address in the application region (47), and for causing the processor (3) to write a replacement second-stage bootloader (27) to whichever of the first (43) and second (45) second-stage bootloader regions is not the active region. The first-stage bootloader (25) comprises instructions for detecting the replacement second-stage bootloader (27) in whichever of the first (43) and second (45) second-stage bootloader regions is not the active region and for transferring execution to the replacement second-stage bootloader (27) when the microcontroller (2) is next reset.
展开▼