All Projects β†’ mihaigalos β†’ miniboot

mihaigalos / miniboot

Licence: GPL-3.0 license
πŸ—οΈ An I2C bootloader for Arduino.

Programming Languages

Makefile
30231 projects
c
50402 projects - #5 most used programming language
python
139335 projects - #7 most used programming language
C++
36643 projects - #6 most used programming language
Starlark
911 projects
shell
77523 projects

Projects that are alternatives of or similar to miniboot

I2C EEPROM
Library for I2C EEPROM - 24LC256
Stars: ✭ 27 (-56.45%)
Mutual labels:  i2c, arduino-library, eeprom
frt
Lightweight, easy-to-use wrapper around the Arduino_FreeRTOS_Library
Stars: ✭ 18 (-70.97%)
Mutual labels:  avr, arduino-library
optiboot flash
Optiboot subtree for MightyCore, MegaCore, MiniCore and MajorCore
Stars: ✭ 48 (-22.58%)
Mutual labels:  avr, bootloader
Tinygo
Go compiler for small places. Microcontrollers, WebAssembly (WASM/WASI), and command-line tools. Based on LLVM.
Stars: ✭ 9,068 (+14525.81%)
Mutual labels:  avr, i2c
Arduino-GPIO
General Purpose Input/Output (GPIO) library for Arduino
Stars: ✭ 43 (-30.65%)
Mutual labels:  avr, arduino-library
Arduino-Log
Simple application log library. supporting multiple log levels, custom output & flash memory support.
Stars: ✭ 132 (+112.9%)
Mutual labels:  avr, arduino-library
PCF8591 library
Library to use i2c analog IC with arduino and esp8266. Can read analog value and write analog value with only 2 wire (perfect for ESP-01).
Stars: ✭ 24 (-61.29%)
Mutual labels:  i2c, arduino-library
Nintendoextensionctrl
Arduino library for communicating with Nintendo extension controllers
Stars: ✭ 67 (+8.06%)
Mutual labels:  i2c, arduino-library
Arduino boards
Board definitions for SparkFun-manufactured AVR, ARM, and ESP-based Arduino boards.
Stars: ✭ 189 (+204.84%)
Mutual labels:  avr, bootloader
arduino-remote-uploader
Over-the-air arduino programming via xbee, wifi or nordic
Stars: ✭ 31 (-50%)
Mutual labels:  arduino-library, eeprom
I2c Moisture Sensor
I2C based soil moisture sensor
Stars: ✭ 194 (+212.9%)
Mutual labels:  avr, i2c
TimerInterrupt
This library enables you to use Interrupt from Hardware Timers on an Arduino, such as Nano, UNO, Mega, etc. It now supports 16 ISR-based timers, while consuming only 1 hardware Timer. Timers' interval is very long (ulong millisecs). The most important feature is they're ISR-based timers. Therefore, their executions are not blocked by bad-behavin…
Stars: ✭ 76 (+22.58%)
Mutual labels:  avr, arduino-library
PalatisSoftPWM
Software PWM library for Arduino
Stars: ✭ 16 (-74.19%)
Mutual labels:  avr, arduino-library
digital-electronics-2
AVR course at Brno University of Technology
Stars: ✭ 12 (-80.65%)
Mutual labels:  avr, i2c
Liquidmenu
Menu creation Arduino library for LCDs, wraps LiquidCrystal.
Stars: ✭ 141 (+127.42%)
Mutual labels:  i2c, arduino-library
Si446x
Si4463 Radio Library for AVR and Arduino
Stars: ✭ 52 (-16.13%)
Mutual labels:  avr, arduino-library
ariadne-bootloader
A little less unfinished TFTP bootloader for Arduino Ethernet or Arduino with Ethernet Shield
Stars: ✭ 40 (-35.48%)
Mutual labels:  avr, bootloader
drivers-for-mcu
The driver for the microprocessor
Stars: ✭ 68 (+9.68%)
Mutual labels:  i2c, eeprom
Ssd1306
Driver for SSD1306, SSD1331, SSD1351, IL9163, ILI9341, ST7735, PCD8544, Nokia 5110 displays running on Arduino/ESP32/Linux (Rasperry) platforms
Stars: ✭ 303 (+388.71%)
Mutual labels:  i2c, arduino-library
Micronucleus
ATTiny usb bootloader with a strong emphasis on bootloader compactness.
Stars: ✭ 1,240 (+1900%)
Mutual labels:  avr, bootloader

Miniboot - an I2C bootloader for Arduino

CI license LoC

Miniboot is an I2C bootloader for Arduino, tested on AtMega328p. It is designed to reflash the Mega328p with code residing in an external I2C memory or another I2C device. For testing, CAT24M01 1Mbit (128kByte) external EEPROM was used.

Requirements

Miniboot depends on avr-bootloader-common for commonalities between bootloaders. This dependency will be automatically downloaded by bazel so you don't have to.

Flash size requirements are <2kBytes. With respect to RAM, AtMega328p's 2kBytes should be enough, actual stack usage is way lower than that anyway.

$ avr-size -B miniboot.elf
   text    data     bss     dec     hex filename
   1944       0       0    1944     798 miniboot.elf

Usage

Flash the correct fuses

Please use the following reccommended fuses, or compatible:

// Fuses : Ext: 0xFF, Hi: 0xD8, Lo: 0xE2

Get the sources

git clone --recursive https://github.com/mihaigalos/miniboot.git

Build the hex

Building is managed by bazel, so make sure you have it first.

  • bazel build --config=328p --verbose_failures //:miniboot.elf
  • bazel build --config=328p --verbose_failures //:miniboot_hex

Once Miniboot starts

Miniboot reads the metadata header and it starts reflashing the microcontroller with the information stated there. It expects the following memory layout of the metadata in the (external) I2C memory:

  • [last free byte pointer] : 2 bytes - should point to first byte after the appplication. Ignored.
  • ['m' 'i' 'n' 'i' 'b' 'o' 'o' 't'] : 8 bytes.
  • [name of application] : 10 bytes - user defined.
  • [timestamp application] : 4 bytes - unix timestamp when the application in the I2C memory was generated.
  • [timestamp of write] : 4 bytes - unix timestamp when the application was flashed to the I2c memory.
  • [CRC32] : 4 bytes - generated with polynomial representation 0xEDB88320. Details in Drivers/CRC.
  • [length] : 2 bytes - amount of bytes for the application.
  • [application] : length bytes - actual payload of the application code.

Miniboot computes a CRC32 checksum on the payload, excluding the header metadata and starting with the first byte of the application. It is important that the length be at byte location 32 and the application start at byte 34.

Bootloader start address

Miniboot can be modified to place the bootloader code at a specific address, via the macro BOOTLOADER_START_ADDRESS. Please ensure that the address lies in the bootloader section, specified by the High fusebits. I recommend using at least 1024 words (2048 bytes) for the bootloader section (Hi fuse : 0xD8). If you choose to modify miniboot, please ensure that your new bootloader fits in the section you specify with the Hi fuse.

Computing the hexadecimal address for bootloader start section:

  • bazel clean; bazel build --config=328p --verbose_failures //:miniboot_hex ; take output, let's say it's 2123 (or similar).
  • for the size of your device (32kB = 1024 * 32 = 32768 bytes) minus above value 2123... = 30645.
  • Which yields 30645 / 128 (128 = mega328p page size in bytes) = 239.41 pages of flash memory.
  • round it down to 239 - our new bootloader address is 239 * 128 = 30592, in hex = 7780h.
  • put the value in the BOOTLOADER_START_ADDRESS variable in the BUILD file.

Internal EEPROM last application timestamp

After running, miniboot writes the application timestamp (specified earlier) to 4 bytes in the microcontroller's internal EEPROM. The next time the system restarts, it will compare the application's timestamp with the information it reads from the internal eeprom and will only rewrite it again if the timestamp is different or the internal eeprom is unprogrammed (4 bytes of 0xFF). This prevents a new unnecessary rewrite on each system restart.

The variable EEPROM_CONFIGURATION_START_BYTE can be edited to generate the desired macro in bootloader.h for the above logic.

Storing the application in the external EEPROM

Create the binary file

Export the hex file of the application (the one you want to transfer to the I2C memory) to binary before continuing:

avr-objcopy -I ihex application.hex -O binary application.bin

Send it!

Disclaimer: At the time of this posting, I was using Windows. Sigh. alt text

We finally want to send it over to the microcontroller which will write it to the I2C memory.

You may choose to use the UART method or the Monolithic Binary Method.

  • The Monolithic Binary Method: creates a sketch with Arduino which contains a copy-pasted version of the application.hex and its associated metadata filled in manually.
  • The UART Method: uses YAT Terminal to fill in the application payload and metadata in the external EEPROM.

I personally think the UART Method is easier and more generic.

Please be aware, the metadata needs to be present alongside the payload. Without proper setup of the
metadata (i.e. : timestamp and CRC), the payload will be ignored by miniboot and not be reflashed.

The Monolithic Binary Method

Don't let the name scare you. πŸ˜€

You can compose your metadata by hand, using my eeprom driver, store both the metadata and the payload in the external I2C, for miniboot to use. Have a look at the blink_hex variable in intel_hex.cpp. You need to compile the example sketch and flash the MCU with it. Once it runs successfuly, you will have the code in the external I2C EEPROM.

The UART Method

Br@y's Terminal is broken when using the send file feature. Use YAT Terminal to send the file via UART instead.

First, the Arduino board needs to be flashed with the miniboot_uart_to_eeprom_uploader.hex sketch which can be found in the Drivers/Eeprom/bin folder in this repo. This will read from the UART and will put the information in the external I2C memory.

At this point, you will need a USB to UART bridge hooked up to your Arduino's UART.

In YAT, go to Terminal->Settings and select your baudrate:

  • If your Arduino is running at 16Mhz : select 600 bits per second.
  • If your Arduino is running at 8Mhz or have a custom board runing at 8Mhz: select 300 bits per second.

The low baudrate ensures the external EEPROM has time to write the payload it receives, since the communication is asynchronous.

When asked to do so, follow the instructions to input the application unix timestamp, the unix timestamp of the time of writing, crc value and the data length. For the unix timestamp, you can use the epoch converter. For computing the crc32 on your binary file, drag and drop the application.bin created earlier in the webpage found here.

You will next be prompted to switch to binary mode and send the binary file.

YAT tries to parse the \r\n sequence when sending, which leads to an error being shown and the transmission is interrupted, the file is not fully sent. To overcome this, ->select Terminal Type: binary. Select Binary Settings... and uncheck everything.

Next select the exported binary file (application.bin) and click Send File.

You should now be able to send the file in full.

No global variables

Miniboot uses no global variables. Thus you can call bootloader functions from the application, without worrying that the application's variables will get overwritten by the bootloader code.

Why should you care, you may ask? Well, if you find you need to compile and link functions which are already present in miniboot, you can just call them from your application to miniboot, potentially reducing the application size.

More details in Section # 14 (Can the application use code built into the bootloader) of doc/bootloader_faq.pdf or AvrFreaks.

License

This software is freely available under the GNU GPL v3.0 aegis, please consult the LICENSE file for further information.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].