I'm developing a product with an AVR (atmega328p). I'm using the optiboot bootloader. I'm using a windows machine.
My main goal is to protect our software as much as I'm able to (I know AVRs aren't 100% secure).
To my understanding, using avrdude the .hex file can be read from AVRs unless the Data Memory Lock Bits (LB1 and LB2) are set to "0." Once set, the .hex file read will not be the true .hex file in flash memory.
I'd like to learn how to set these lock bits, and verify my code cannot be read back out.
So I'm here to share what I've learned so far and to get everyone's feedback on how I can verify the lock-bits are doing their job.
Here's my steps so far:
- Found that lock bits can either be changed in the bootloader, and the bootloader re-flashed, or by using avrdude.
- Lock bits and fuse bits can be changed in the "boards.txt" file usually found in C:\Users\"YourUserNameHere"\Downloads\optiboot-master\optiboot-master\optiboot\boards.txt
- If you can burn a bootloader onto AVR using "arduino as ISP", you can also use it with avrdude interaction (without having to buy a programmer)
- Using arduino UNO as "arduino as isp" I am able to interact with atmega328p using avrdude.
- I can read my .hex file out with the command "C:\Users\"YourUserNameHere">avrdude -P COM3 -b 19200 -c stk500v1 -p m328p -U flash:r:mySoftware.hex:r"
- Next I burn the bootloader with lock_bits set to (0x0C : 0b1100 : 0b x x LB2 LB2)
- Or using avrdude: C:\Users\"YourUserNameHere">avrdude -c stk500v1 -p m328p -P COM3 -b 19200 -U lock:w:0x0C:m
- Now the .hex file is blank (0KB of data).
Everywhere I read, people have said (and also Atmel) that when you try to read out the .hex file from an AVR with LB1 and LB2 set to "0" the .hex file will contain the "Low byte of the memory address" that looks like:
00 00 01 01 02 02 03 03 04 04 .. 0E 0E 0F 0F 10 10 11 11 12 12... and so on
But when my lock bits are active, when I read my .hex file, I get an absolutely empty file.
Am i doing something wrong, or did the Atmel documentation change?
atmega328p datasheet: http://www.atmel.com/Images/Atme...
In-System Programming application note: http://www.atmel.com/Images/Atme...
avrdude guide: https://learn.sparkfun.com/tutor...
Binary to hex converter: Frhed