Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

Bootloader being overwritten during program execution?

 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR
View previous topic :: View next topic  
Author Message
KenHorse

Bascom Member



Joined: 16 Jul 2004
Posts: 507

blank.gif
PostPosted: Tue Nov 10, 2020 9:51 pm    Post subject: Bootloader being overwritten during program execution? Reply with quote

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
View user's profile
Evert :-)

Bascom Expert



Joined: 18 Feb 2005
Posts: 2117

netherlands.gif
PostPosted: Tue Nov 10, 2020 10:07 pm    Post subject: Reply with quote

Are you using $loadersize in your main prog to tell the compiler you are using flash space for the bootloader?
_________________
www.evertdekker.com Bascom code vault
Back to top
View user's profile Visit poster's website
AdrianJ

Bascom Expert



Joined: 16 Jan 2006
Posts: 2473
Location: Queensland

australia.gif
PostPosted: Tue Nov 10, 2020 10:51 pm    Post subject: Reply with quote

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
View user's profile Visit poster's website
KenHorse

Bascom Member



Joined: 16 Jul 2004
Posts: 507

blank.gif
PostPosted: Wed Nov 11, 2020 12:47 am    Post subject: Reply with quote

Evert Smile 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
View user's profile
KenHorse

Bascom Member



Joined: 16 Jul 2004
Posts: 507

blank.gif
PostPosted: Wed Nov 11, 2020 12:48 am    Post subject: Reply with quote

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
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5096
Location: Holland

blank.gif
PostPosted: Wed Nov 11, 2020 9:46 am    Post subject: Reply with quote

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
View user's profile Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum