Skip to content

Latest commit

Β 

History

History
296 lines (235 loc) Β· 7.33 KB

File metadata and controls

296 lines (235 loc) Β· 7.33 KB

Ararext Bootloader - Quick Reference

πŸš€ Quick Start (5 Minutes)

1. Prerequisites

rustup target add thumbv7em-none-eabihf
sudo apt-get install arm-none-eabi-binutils

2. Build

cd /home/ararext/update_projects/ararext-bootloader
cargo build --release

3. Flash

# Convert to binary
arm-none-eabi-objcopy -O binary \
    target/thumbv7em-none-eabihf/release/ararext-bootloader \
    ararext-bootloader.bin

# Flash to device (using OpenOCD)
openocd -f interface/stlink.cfg -f target/stm32f4x.cfg \
    -c "program ararext-bootloader.bin 0x08000000 verify reset exit"

πŸ“ Project Structure

ararext-bootloader/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ main.rs           # Entry point and bootloader loop
β”‚   β”œβ”€β”€ constants.rs      # Definitions and constants
β”‚   β”œβ”€β”€ uart.rs           # UART communication
β”‚   β”œβ”€β”€ handlers.rs       # Command implementations
β”‚   β”œβ”€β”€ memory.rs         # Memory operations
β”‚   β”œβ”€β”€ crc.rs            # CRC verification
β”‚   └── flash.rs          # Flash management
β”œβ”€β”€ Cargo.toml            # Project manifest
β”œβ”€β”€ memory.x              # Memory layout
β”œβ”€β”€ README.md             # Full documentation
β”œβ”€β”€ BUILD.md              # Build guide
β”œβ”€β”€ ARCHITECTURE.md       # Design documentation
β”œβ”€β”€ COMPARISON.md         # C vs Rust comparison
└── PROJECT_SUMMARY.md    # This summary

🎯 Available Commands

Code Command Purpose
0x51 GET_VER Get bootloader version
0x52 GET_HELP List commands
0x53 GET_CID Get chip ID
0x54 GET_RDP_STATUS Get protection level
0x55 GO_TO_ADDR Jump to address
0x56 FLASH_ERASE Erase sectors
0x57 MEM_WRITE Write memory
0x58 EN_RW_PROTECT Enable protection
0x59 MEM_READ Read memory
0x5A READ_SECTOR_P Query protection
0x5B OTP_READ Read OTP
0x5C DIS_R_W_PROTECT Disable protection

πŸ”§ Common Operations

Compile Debug Build

cargo build

Compile Release Build (Optimized)

cargo build --release

Check Code Without Building

cargo check

View Documentation

cargo doc --open

Run Tests (Once Added)

cargo test

Clean Build Artifacts

cargo clean

πŸ”Œ Hardware Configuration

UART Interfaces

  • USART2: Command/Control (PA2/PA3) - 115200 bps
  • USART3: Debug output (PB10/PB11) - 115200 bps

GPIO

  • PA0: Mode button (LOW=bootloader, HIGH=app)
  • PA5: Status LED

Memory Map

  • 0x08000000: Bootloader (Sectors 0-1)
  • 0x08008000: User application (Sectors 2-7)

πŸ“Š Binary Sizes

  • Debug: ~45 KB
  • Release: ~25 KB
  • With LTO: ~23 KB

⚑ Performance

  • Startup: ~10ms
  • Command processing: <1ms
  • Sector erase: ~100ms
  • Byte write: ~1ms

πŸ› Debugging

View Serial Output

miniterm /dev/ttyUSB0 115200
# or
screen /dev/ttyUSB0 115200

Debug with GDB

# Terminal 1: Start OpenOCD
openocd -f interface/stlink.cfg -f target/stm32f4x.cfg

# Terminal 2: Debug
arm-none-eabi-gdb target/thumbv7em-none-eabihf/release/ararext-bootloader
(gdb) target remote :3333
(gdb) load
(gdb) break main
(gdb) continue

πŸ” Key Safety Features

βœ… CRC-32 verification on incoming protocol frames βœ… Address validation before jumping βœ… Compile-time buffer overflow prevention βœ… Type-safe command parsing βœ… Unsupported operations fail closed with NACK

πŸ“š Documentation Map

Document Purpose
README.md Overview & features
BUILD.md Build & flashing guide
ARCHITECTURE.md Design details
COMPARISON.md C vs Rust analysis
PROJECT_SUMMARY.md High-level summary

πŸ› οΈ Customization

Change MCU Target

Edit .cargo/config.toml:

target = "thumbv7em-none-eabihf"  # Keep for F407

Modify Clock Speed

In main.rs:

let clocks = rcc.cfgr
    .use_hse(8.mhz())
    .sysclk(84.mhz())  // Change here
    .freeze();

Add Custom Commands

  1. Add command code to constants.rs
  2. Create handler in handlers.rs
  3. Add dispatch case in main.rs bootloader_loop

🚨 Troubleshooting

Issue Solution
"linker 'arm-none-eabi-gcc' not found" sudo apt-get install arm-none-eabi-binutils
"failed to find 'rust-lld'" rustup component add rust-src
Flash write fails Run BL_DIS_R_W_PROTECT (0x5C) first
GDB "connection refused" Check OpenOCD is running
Serial port not found Check device connected with lsusb

πŸ’‘ Tips & Tricks

Faster Development

cargo check  # Just check syntax, no build
cargo check --all-targets  # Include tests/examples

Optimize Binary Size

# In Cargo.toml [profile.release]
opt-level = "z"  # Size optimization
lto = true       # Link-time optimization

Monitor Build Size

# See binary sections
arm-none-eabi-objdump -h target/thumbv7em-none-eabihf/release/ararext-bootloader

# Analyze size breakdown
cargo bloat --release

Parallel Flashing

# Flash multiple devices simultaneously
for device in /dev/ttyUSB*; do
    st-link --write ararext-bootloader.bin 0x08000000 &
done

πŸ“ˆ Metrics

Metric Value
Lines of Code ~800
Modules 7
Commands 12
Binary Size 25 KB
RAM Usage 3 KB
Build Time 90s
Target STM32F407xx

πŸ”— Useful Links

πŸ“ Version History

Version Status Notes
0.1.0 ⚠️ In progress Core command protocol active; some command handlers still return NACK

πŸ“‹ Checklist for Deployment

  • Build passes without warnings: cargo build --release
  • Binary size < 32 KB: ~25 KB
  • Device flashed successfully
  • Button boot into bootloader works
  • Required command subset tested end-to-end (GET_VER, GET_HELP, GET_CID, GET_RDP_STATUS, GO_TO_ADDR, MEM_READ)
  • CRC validation verified
  • User app jumps successfully
  • Serial communication verified at 115200 bps

πŸŽ“ Learning Path

  1. Start here: README.md (30 min)
  2. Understand: ARCHITECTURE.md (45 min)
  3. Compare: COMPARISON.md (30 min)
  4. Build: BUILD.md instructions (15 min)
  5. Code dive: Explore src/ modules (60+ min)

✨ Key Advantages

βœ… Memory Safe: Compile-time guarantees, no unsafe surprises βœ… Well Organized: 7 focused modules, not 1 monolithic file βœ… Type Safe: Commands and regions are typed, not raw bytes βœ… Better Errors: Compiler catches bugs before runtime βœ… Documented: Comprehensive guides and inline documentation βœ… Honest Status: Unimplemented features explicitly return NACK

🎯 Next Steps

  1. Try it: Build and flash to your device
  2. Explore: Review ARCHITECTURE.md
  3. Customize: Add your own commands
  4. Extend: Implement OTA updates
  5. Deploy: Use in your product

For detailed information, see the full documentation in README.md, BUILD.md, and ARCHITECTURE.md

Last Updated: 2026
Status: ⚠️ Active Development