Categories
Arduino atmega328

How to use ATmega328P lock bits to protect your firmware

Before you wonder how to lock the atmega328p microcontrollers which are backbone of Arduino Uno, this is done with lock bits which you can program in atmega328p microcontroller to protect from reading. In this post we are going to summarize the lock fuse bits in atmega328p microcontrollers. We will describe how to use these available lock bits in atmega328p for protecting unauthorized access of firmware or accidental write. So let’s begin.

Introduction to Locks bits of Atmega328p

Lock bits of Atmega328p microcontroller are set of fuse available in fuse section of atmega328 microcontroller for protecting the accidental overwrite of bootloader, and/or to protect the unauthorized reading of firmware. These fuse bits could be read and write with avrdude.

These lock bits are 3 in number and could be referred as LB0, LB1, and LB2. Let’s dive into each of these locks bits to further understand them.

LB0 Lock Bit of ATmega328

This lock bit of atmega328p microcontroller is used for protecting the bootloader section. If you are not aware of what bootloader is, I would suggest refereeing to the datasheet of atmega328p and the Arduino. Arduino is one of the major hardware board which use the atmega328 microcontroller in his very famous Arduino uno board. When you try to upload the sketch on your Arduino Uno board, it used the Opti boot bootloader which is already programmed into the Atmega328p chip, to upload the Arduino sketch on Arduino uno board. If the LB0 lock bit of the ATmega328 microcontroller is written to 1 then the bootloader on that microcontroller cannot be overwritten. In short this LB0 lock bit of atmega328p microcontroller locks the bootloader section of the atmega328p microcontroller.

So, if you are using the bootloader to upload your code onto the microcontroller, you may want to prevent users to accidently upload their own firmware without the bootloader which may cause to override the bootloader section of the microcontroller. You can simply set this LB0 fuse bit in atmega328 microcontroller and it will prevent user for doing so by protecting the bootloader section.

LB1 Lock bit of the Atmega328

The LB1 lock bit in the fuse bit section of the atmega328 microcontroller is used to protect the firmware written in the Flash memory of the atmega328 microcontroller. It is the most crucial part of the lock bits of the microcontroller where we want to prevent the unauthorized access of the firmware. Which means your proprietary firmware should not be read or overwrite by any unauthorized user. Simply set the LB1 lock bit in the fuse bits of the atmega328 microcontroller.

LB2 Lock Bit of the Atmega328

This is the most secure option for locking the atmega328 microcontroller, which also means that you have to completely erase the previous bootloader and Firmware written onto the microcontroller before you update your new firmware onto the microcontroller.

It is important to note that setting the lock bits can make it more difficult to recover from a programming error. If you accidentally set the LB2 lock bit, the only way to clear it is to erase the entire microcontroller. If you are not sure whether or not to set the lock bits, it is best to err on the side of caution and leave them unset. You can always set the lock bits later if you need to.

Google Bard

By Abdul Rehman

My name is Abdul Rehman and I love to do Reasearch in Embedded Systems, Artificial Intelligence, Computer Vision and Engineering related fields. With 10+ years of experience in Research and Development field in Embedded systems I touched lot of technologies including Web development, and Mobile Application development. Now with the help of Social Presence, I like to share my knowledge and to document everything I learned and still learning.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.