Lock bit and upload via bootloader

Hi everyone

I have been searching the web, yet I couldn't find final answer. I would like to lock Atmega328p, so no one could download it's content, yet I would still like to be able to program the uC through USART port using FTDI serial interface.

My sketches are written on Arduino IDE, and for now I have been uploading sketches directly via it's interface.

I would like to know is it possible to use Arduino bootloader for uploading and still prevent reading. If not, what bootloader should I install in order to upload sketches (hex format?) via USART but still disable someone from reading the code from uC - both via USART or SPI. I would still like to be able to use serial communication via USART when program in running.

Thanks for advices

The current Arduino bootloaders all provide flash-read capabilities, and the current upload procedure relies on that for verification of correct upload. If you want to turn off flash-read over serial, you need a new bootloader and a new upload procedure.

Note that AFAIK, there is no "write only" protection mode for the SPI interface; if you want to turn off the ability to read via ISP programmer, you must also turn of write via ISP. I don't think this affects write-via bootloader, so it should be possible to implement a "secure bootloader" of some kind.

Note that I'm pretty sure that I can write a program that when uploaded would immediately dump most of the flash content, and the current bootloaders do not erase unprogrammed pages, so that would be another thing you'd have to change to prevent access to "most" of your program...

Erase via ISP is likely to still work, and HVPP can always erase.

I've seen some "Secure Bootloader" products for AVR advertised. They cost money (touché!) and I don't know anything about how secure they might actually be.

@westfw: Thanks for your reply. So I guess the most simple solution would be not to use bootloader at all and upload program via SPI, then lock it with Lock bit. And when program is needed to be uploaded, Erase the AVR via SPI, reset fuse, upload new program and repeat procedure?

I guess that is also an option. Not most convenient one, but still, better than nothing.

Are those fuse settings correct for ATMega328P: Lock bit: 0x03 (LPM and SPM prohibited in Application section, LPM and SPM prohibited in Bootloader section)

Should SPIEN (Serial program downloading) also be disabled? Should I pay attention also to Boot Flash Section size, since I won't use bootloader?

I was planning to Export Compiled Binary from Arduino IDE and upload it to uC via AVRDude.

Thanks again

the most simple solution would be not to use bootloader at all and upload program via SPI, then lock it with Lock bit. And when program is needed to be uploaded, Erase the AVR via SPI, reset fuse, upload new program and repeat procedure?

Yes, for some definitions of "most simple."

Are those fuse settings correct for ATMega328P: Lock bit: 0x03 (LPM and SPM prohibited in Application section, LPM and SPM prohibited in Bootloader section)

You VERY MUCH need "lpm" to work from the application section. It's needed for all the pgmspace "store data in flash" features, including F("String"), the pin table used by the Arduino core, and even the C startup code copying the .data section into RAM. I don't really know much about the details of protection; I THINK that if you're not using the bootloader, then all the bootloader lock bits are irrelevant and all you need to worry about are the lock bits. 0x3C?

Should SPIEN (Serial program downloading) also be disabled?

Not if you want to be able to do that "ISP Erase and re-program" part. (Also, I don't think you CAN disable this while using ISP programming.)

Should I pay attention also to Boot Flash Section size, since I won't use bootloader?

Probably not, but you should change the BOOTRST fuse.