avr-libc-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[avr-libc-dev] boot page erase / write with "runaway code" check


From: Štefan Hladnik
Subject: [avr-libc-dev] boot page erase / write with "runaway code" check
Date: Sat, 18 Feb 2012 16:48:19 +0100

Hi all,

On my project I run into problems with overwriting of the flash caused by
runaway code. So I coded the assembly code that does it's best to avoid
that. For this I use local volatile variable which is initialized to 0xa5
(I believe it's safer to have it on stack - if it would be global it could
somehow stay on 0xa5 value and stack is much more random). If code somehow
jumps anywhere before that, software will take care of skipping the write
code. If it jumps after, this variable will not be set to 0xa5 and spm
instruction will be skipped. The final check is done just within those 4
cycles, so there no chance to jump somewhere in the middle here. I also use
__zero_reg__ to minimize chances that 'valid' value would be already in
register. The only possibility would now be that there is 0xa5 at exactly
the right position on stack.

I found this really useful, so I thought some might be interested. Maybe
this could even be included into avr/boot.h. If nothing else, at least to
make people reading the docs aware of this issue... It took me quite some
time to realize what is going wrong in my application, didn't even think
about such scenario before.

Regards,
Stefan

Attachment: boot_ext.c
Description: Text Data

Attachment: boot_ext.h
Description: Text Data

Attachment: boot_ext_example.c
Description: Text Data


reply via email to

[Prev in Thread] Current Thread [Next in Thread]