View previous topic :: View next topic |
Author |
Message |
KenHorse
Joined: 16 Jul 2004 Posts: 523
|
Posted: Tue Nov 10, 2020 9:51 pm Post subject: Bootloader being overwritten during program execution? |
|
|
I'm running the Bascom bootloader in an M2561 and may have experienced the loaded program overwriting (or partially overwriting) the bootloader. And while I have seen loading too large a program into the AVR overwriting the bootloader I have never seen an overwrite (at least what I perceive to be an overwrite as the only way to correct it is to reload the bootloader itself) from the loaded program itself running
(BASCOM-AVR version : 2.0.8.3 ) |
|
Back to top |
|
|
Evert :-)
Joined: 18 Feb 2005 Posts: 2159
|
|
Back to top |
|
|
AdrianJ
Joined: 16 Jan 2006 Posts: 2483 Location: Queensland
|
Posted: Tue Nov 10, 2020 10:51 pm Post subject: |
|
|
You can also set a fuse to disable writing to the bootloader area. Obviously, do this after installing the bootloader !
And for added general security, set another fuse bit to prevent any read access to the bootloader too. Then its extremely difficult for a 3rd party to access your loader and take it over to read your code, or install foreign software. _________________ Adrian Jansen
Computer language is a framework for creativity |
|
Back to top |
|
|
KenHorse
Joined: 16 Jul 2004 Posts: 523
|
Posted: Wed Nov 11, 2020 12:47 am Post subject: |
|
|
Evert wrote: | Are you using $loadersize in your main prog to tell the compiler you are using flash space for the bootloader? |
Yes but doesn't that just protect that a program won't compile larger than is safe for the bootloader? In other words, if I know the compiled code size won't invade the bootloader memory, isn't that effectively the same thing? |
|
Back to top |
|
|
KenHorse
Joined: 16 Jul 2004 Posts: 523
|
Posted: Wed Nov 11, 2020 12:48 am Post subject: |
|
|
AdrianJ wrote: | You can also set a fuse to disable writing to the bootloader area. Obviously, do this after installing the bootloader !
And for added general security, set another fuse bit to prevent any read access to the bootloader too. Then its extremely difficult for a 3rd party to access your loader and take it over to read your code, or install foreign software. |
There's a good idea....... |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 6025 Location: Holland
|
Posted: Wed Nov 11, 2020 9:46 am Post subject: |
|
|
all remarks are excellent. i want to add this.
you can limit the write so it will not write into the boot area, or any other area you might want to protect.
depending on the chip you set a constant named maxpages. the writepage will check the value so it will not erase the next page
Code: | #if Loaderchip = 88 'Mega88
$loader = $c00 'this address you can find in the datasheet
'the loader address is the same as the boot vector address
Const Maxwordbit = 5
Const Maxpages = 96 - 1 ' total WORD pages available for program
Config Com1 = Dummy , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0
#endif
|
code from the writepage :
Code: | For J = 1 To 128 Step 2 'we write 2 bytes into a page
Vl = Buf(j) : Vh = Buf(j + 1) 'get Low and High bytes
!lds r0, {vl} 'store them into r0 and r1 registers
!lds r1, {vh}
Spmcrval = 1 : Gosub Do_spm 'write value into page at word address
Wrd = Wrd + 2 ' word address increases with 2 because LS bit of Z is not used
If Wrd = Maxword Then ' page is full
Wrd = 0 'Z pointer needs wrd to be 0
Spmcrval = 5 : Gosub Do_spm 'write page
Spmcrval = 17 : Gosub Do_spm ' re-enable page
If Page < Maxpages Then 'only if we are not erasing the bootspace
Page = Page + 1 'next page
Spmcrval = 3 : Gosub Do_spm ' erase next page
Spmcrval = 17 : Gosub Do_spm ' re-enable page
Else
Portd.7 = 0 : Waitms 200
End If
End If
Next
|
_________________ Mark |
|
Back to top |
|
|
KenHorse
Joined: 16 Jul 2004 Posts: 523
|
Posted: Thu Dec 10, 2020 8:55 pm Post subject: |
|
|
So what's the difference(s) between preventing SPM and/or LPM from "accessing" the bootloader? |
|
Back to top |
|
|
|