Microcontroller Advanced Topics: #4: Bootloading
Microcontroller Advanced Topics: #4: Bootloading
Topics
#4: Bootloading
Kevin Balke
[email protected]
UCLA IEEE 2016
Rationale
1. We are engineers…
2. Fun!
3. …
4. Profit!
CODE FOR THIS WORKSHOP:
https://goo.gl/Tc07Yh
Overview
1. What are we trying to achieve, and why is it important?
a. Some motivating examples
2. Definitions
3. File Formats
4. Communication Systems
5. Memory Model
6. Recap of ARM Registers, Stack, Execution, and Instructions
7. Program startup procedure
8. Linker Scripts
9. Programming Flash
10. Additional Resources
You are Building a Satellite...
● It's going to space
● You can't plug a cable into it once it leaves
● How do you fix it if it stops working?
● Need some way to load new code… and then boot that code...
BOOTLOADER
You're doing NATCAR...
● You want to change your algorithms
○ Not just live tuning, actually a different implementation!
○ How can we achieve this?
○ What code actually needs to be changed?
■ Does the code that runs the servo need to be changed?
■ Is it possible to change just the control code?
file1 file2
Contains
arbitrary binary Contains ASCII
data characters
Programs are Data
● Machine code = binary data
● Try this:
kb@box:~$ cat /bin/cat | hexdump -Cv
● Or this:
kb@box:~$ objdump -D /bin/cat
0000829c <main>:
int main(void) { 829c: e52db004 push {fp} ; (str fp, [sp, #-
int foo = 4]!)
82a0: e28db000 add fp, sp, #0
1; 82a4: e24dd00c sub sp, sp, #12
foo = 2; 82a8: e3a03001 mov r3, #1
Compile 82ac: e50b3008 str r3, [fp, #-8]
return 82b0: e3a03002 mov r3, #2
foo; 82b4: e50b3008 str r3, [fp, #-8]
82b8: e51b3008 ldr r3, [fp, #-8]
} 82bc: e1a00003 mov r0, r3
82c0: e24bd000 sub sp, fp, #0
C program code 82c4: e49db004 pop {fp} ; (ldr fp, [sp], #4)
82c8: e12fff1e bx lr
21 foo
SP
Low addresses
ARM Assembly (Cortex-M4) http://goo.gl/KIzC6L
● Calling convention:
○ Function arguments stored in registers
○ Return value in R0
○ LR set to return address on branch to routine ({bl #label} instruction, “branch and link”)
● Some useful instructions:
Instruction Op1 Op2 Op3 Desc.
pop {Ra, Rb, … , Rz} N/A N/A Pop registers from stack
REGION_ALIAS("REGION_BOOT_TEXT", BOOT_FLASH);
REGION_ALIAS("REGION_PROG_TEXT", PROG_FLASH); Region Aliases
REGION_ALIAS("REGION_BSS", SRAM);
...
SECTIONS {
PROVIDE (__prog_text_start__ = 0x00001000);
PROVIDE (__prog_text_end__ = 0x00040000);
Provisions
...
OR
This presentation:
https://goo.gl/jX0lGN
Thanks for coming!
My contact info:
Kevin Balke
[email protected]
Extra credit
First 3 people to complete one of the following assignments get free 3D printing
credit!
http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0553a/CIHJJEIH.ht
ml ← ARM Cortex-M4 online instruction set reference
Installing Drivers
● http://energia.nu/guide/guide_windows/ ← Installing the TivaC driver
● https://learn.sparkfun.com/tutorials/disabling-driver-signature-on-windows-8 ←
disabling driver signing enforcement (requires reboot)
● http://energia.nu/download/ ← Energia download (flash drive available at
presentation)