Go Down

Topic: Confused by fuse bits settings and boot loader sizes (Read 5699 times) previous topic - next topic

liuzengqiang

Aug 23, 2011, 06:36 am Last Edit: Aug 23, 2011, 06:40 am by liudr Reason: 1
I am trying to learn the fuse and lock bits of ATMEGA328P. According to the atmel data sheet:
BOOTSZ1 BOOTSZ0 Boot Size
1 1 256 words
1 0 512 words
0 1 1024 words
0 0 2048 words

So I thought that the duemilanove boot loader takes 2K bytes, and Uno's bootloader is 512B, which is how much FLASH I subtracted from 32768. Am I right?

I was testing my understanding with this calculator:

http://frank.circleofcurrent.com/fusecalc/fusecalc.php?chip=atmega328p

It seems to indicate, beside some other settings, that 256B boot loader as high fuse = 0xDA, and 1024B boot loader as high fuse = 0xDE.

Then I looked at my arduino software's boards.txt and found out that UNO's high fuse = 0xDE, and Duemilanove's high fuse = 0xDA.

I'm confused now. 512B FLASH is taken from the 32KB but only 256B was boot loader so what is the other 256B used for? Same question for the Duemilanove: 1024B boot loader but 2048B taken from 32KB? Thank you!

BTW, I just realized how to read those fuse calculators, select means 0 and non-select is 1.

In atmel document 8271, 256 words boot loader corresponds to setting of 11, with serial programming enable, gets 0xDE. The doc also says boot loader is between 0x3F00 and 0x3FFF, 256 addresses, so their word is one byte long?
SDI-12 USB Adapter, custom designs
Routinely doing USB host and device stuff
http://liudr.wordpress.com
https://www.tindie.com/stores/liudr/

westfw

Note that the bootloader fuse bits specify the number of WORDS allocated to the bootloader.  A word is two bytes, so a 512byte bootloader gets the bit settings for a 256 word boot section...

liuzengqiang


Note that the bootloader fuse bits specify the number of WORDS allocated to the bootloader.  A word is two bytes, so a 512byte bootloader gets the bit settings for a 256 word boot section...



Thanks westfw. I also just calculated 0x3F00=16384 so yes even their addresses are in words. I have not done the proper reading yet. Is atmega328p memory location addressed by words instead of bytes? I saw 0x3F00 and I thought it were an address but maybe it is just number of words in hex.
SDI-12 USB Adapter, custom designs
Routinely doing USB host and device stuff
http://liudr.wordpress.com
https://www.tindie.com/stores/liudr/

westfw

Quote
Is atmega328p memory location addressed by words instead of bytes?

All AVR instructions are multiples of 16bits long, and the flash memory is essentially 16bits wide and is addressed by the other instructions (jump, call, etc) as words, with the exception of the instructions for reading data from program memory (LPM)
The data memory (RAM) is 8 bits wide and is addressed as bytes.
This (separate address spaces and even different sizes for instruction space and data space) is the essential part of the "Harvard Architecture" used in many microcontrollers.  It's a bit more obvious on something like the low-end PIC, where the instructions are 12bits wide rather than a nice even number of bytes.

liuzengqiang

Thanks. That clears a lot of things up. I think I'm prepared to read more of that document now.
SDI-12 USB Adapter, custom designs
Routinely doing USB host and device stuff
http://liudr.wordpress.com
https://www.tindie.com/stores/liudr/

westfw

(The whole "Harvard Architecture" thing is sort of neat.  It shows up most obviously in microcoded engines, where each bit of the instruction word directly connects to some hardware gate - you can add as many bits to the instruction word as you have gates and things to control.  So it's not uncommon to have a 80bit microinstruction width...  The PIC is a great example; you have essentially similar architectures with 12, 14, or 16bit wide instructions, whose major difference is the size of the operands (destination addresses for JUMP instructions, RAM and/or register addresses...))

liuzengqiang

That is interesting. I have only dealt with such details in intel's x86 general purpose microprocessors, where instructions don't have fixed lengths. This makes sense for CPU.
SDI-12 USB Adapter, custom designs
Routinely doing USB host and device stuff
http://liudr.wordpress.com
https://www.tindie.com/stores/liudr/

retrolefty

Quote
(The whole "Harvard Architecture" thing is sort of neat.  It shows up most obviously in microcoded engines, where each bit of the instruction word directly connects to some hardware gate - you can add as many bits to the instruction word as you have gates and things to control.


That same concept can be applied to Von Neumann type computers also. In the 70s I worked for a mini-computer company (Varian Data Machines) and there 16 bit processor board used micro-coding for the instruction decoding where the output bits of the micro decoder ROM wired directly to all the hardware signals such as ALU control, register selection, bus selection, etc. I think it was 64 parallel bit outputs or maybe more. We even offered a 'writable control store' option, where the user could create their own machine language instructions and several of the customers did indeed use that option.

Lefty

liuzengqiang

So back to fuses, if I want to write sketch on an atmega328P and don't want others to clone its program to other atmega328P chips, is there any fuse I can set to achieve that? At the same time, I still want to be able to somehow update the sketch with serial boot loader in the future. Thanks.
SDI-12 USB Adapter, custom designs
Routinely doing USB host and device stuff
http://liudr.wordpress.com
https://www.tindie.com/stores/liudr/

westfw

Quote
I want to write sketch on an atmega328P and don't want others to clone its program to other atmega328P chips

Yes, in theory.    You can set the "Lock bits" (in the same byte as the boot lock bits, but different) so that serial and parallel programming can neither read nor write flash contents (you can still reprogram the chip by starting with a "chip erase" command.)  The bootloader should still be able to write to program memory at that point.  You can also disable SPI programming in general, though I'm not sure what that buys you.

However, you'll also need a new bootloader.  The current bootloaders allow reading the flash memory, and in fact verify correct programming by reading back the data and comparing it to what it thought was programmed.   Atmel has some app notes on "secure bootloaders"; I haven't read them...

liuzengqiang

So I guess I don't have a good way to protect the code maybe except for using an ISP to program the chips with all read/write access disabled using lock bits. That makes upgrade by end users difficult.
SDI-12 USB Adapter, custom designs
Routinely doing USB host and device stuff
http://liudr.wordpress.com
https://www.tindie.com/stores/liudr/

Go Up