View previous topic :: View next topic |
Author |
Message |
igortab
Joined: 08 Oct 2009 Posts: 14 Location: Sydney
|
Posted: Mon Jun 09, 2014 10:30 pm Post subject: Problem Including Bootloader Code in Application Program |
|
|
I want to include a compiled bootloader code in to an application program.
This allows factory programming of both in one go as oppose to programming a bootloader and then bootloading the application program
I have been doing this for years with Atmega chips like this:
Code: | $Boot=$F800
$Inc BootLoader,NoSize,"My_BootLoader.bin" |
(My_BootLoader.bin file is a binary image of bootloader code only, compiled with Bascom AVR).
However, this doesn't work with Xmega 256A3U:
Code: | $Boot=$20000
$Inc BootLoader,NoSize,"My_BootLoader.bin" |
I have also tried:
Code: | $RomStart=$20000
$Inc BootLoader,NoSize,"My_BootLoader.bin" |
All I need the compiler to do is to place the code from My_BootLoader.bin file at location $20000
If anyone can help, it would be much appreciated.
(BASCOM-AVR version : 2.0.7.7 ) |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 6025 Location: Holland
|
Posted: Tue Jun 10, 2014 9:22 am Post subject: |
|
|
you need to add :
! .ORG $the WORD address of the loader
'put the $Inc here _________________ Mark |
|
Back to top |
|
|
igortab
Joined: 08 Oct 2009 Posts: 14 Location: Sydney
|
Posted: Tue Jun 10, 2014 11:26 am Post subject: |
|
|
Thank you for your help Mark.
Unfortunately, it didn't quite work. While the compiler placed the bootloader code at the right address,
it also placed a lot of data, including application program constants, after the bootloader code.
It also generated an error message: "Program will overwrite bootloader...." as the compiler is not aware
that the code following ! .ORG $20000 is a bootloader code.
I have tested the code with Ver 2.0.7.7 and it works fine with Atmega chips:
Code: | $Boot=$F800
$Inc BootLoader,NoSize,"My_BootLoader.bin" |
Is there a reason why it shouldn't work with Xmega chips? |
|
Back to top |
|
|
Evert :-)
Joined: 18 Feb 2005 Posts: 2159
|
|
Back to top |
|
|
igortab
Joined: 08 Oct 2009 Posts: 14 Location: Sydney
|
Posted: Tue Jun 10, 2014 1:24 pm Post subject: |
|
|
Just tried using $LoaderSize in main program but it made no difference.
It's not the error that's the problem as the compiler still generates HEX and BIN files.
It's the fact that the compiler stores constants and other data from the main program
after the bootloader code. This makes the total size of the file bigger than can fit in to flash.
This makes sense (to me) as the compiler is not aware that code following $20000 is a bootloader
and treats it as part of the main program. |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 6025 Location: Holland
|
Posted: Tue Jun 10, 2014 1:31 pm Post subject: |
|
|
please post an example that works for you with atmega. (with all files).
and also a sample for xmega. the inc file can be rubbish, and the main program can be minimal, but i need some real code to look at that contains your used settings. _________________ Mark |
|
Back to top |
|
|
igortab
Joined: 08 Oct 2009 Posts: 14 Location: Sydney
|
Posted: Wed Jun 11, 2014 8:06 pm Post subject: |
|
|
Example files attached.
Please note how "Boot_ATmega128.bas" correctly generates output binary and hex files and "Boot_Xmega256A3U.bas" does not.
Best regards. |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 6025 Location: Holland
|
Posted: Wed Jun 11, 2014 9:00 pm Post subject: |
|
|
The combined use of the old $Boot and $Inc is very nice.
I found the problem and changed it. it will be in the next update.
as a workaround you can merge the hex files. _________________ Mark |
|
Back to top |
|
|
Duesentrieb72
Joined: 17 Feb 2006 Posts: 44
|
Posted: Fri Feb 27, 2015 9:24 am Post subject: |
|
|
Hello Mark,
I'm sorry to ask, but I didn't understand how to include BootLoader code in aplication program right...
I compiled the BootLoader and have the .bin / .hex of it.
Next I put this at the beginning of my application:
$loader = &H30000 ' adress eg. datasheet for ATXmega384C3
$inc Bootloader , Nosize , "MA2_Front_Bootloader_2.bin"
This gives the Error
Error : 344 Line : 2359 Program will overwrite bootloader [ 392854 too long] , in File : C:\PROGRAM FILES (X86)\MCS ELECTRONICS\BASCOM-AVR\LIB\FP_TRIG.LBX
Error : 80 Line : 1360 Code does not fit into target chip , in File : C:\PROGRAM FILES (X86)\MCS ELECTRONICS\BASCOM-AVR\LIB\FP_TRIG.LBX
If I merge the BootLoader code manualy in the bin-file at the right position, everything is fine and works.
But it would be very nice to include the BootLoader automaticaly
µC = ATXmega384C3
Compiler version :2.0.7.8
Compiler build :2.0.7.8.001
IDE version :2.0.7.8.001
Thanks a lot,
Düsentrieb72 |
|
Back to top |
|
|
igortab
Joined: 08 Oct 2009 Posts: 14 Location: Sydney
|
Posted: Fri Feb 27, 2015 3:41 pm Post subject: |
|
|
Put these 2 lines at the very end of your program.
$Boot=$XXXX (XXXX = Bootloader start address in uC memory)
$Inc BootLoader,NoSize,"My_BootLoader.bin"
This is how it used to work.
Best regards,
Igor Tabakov |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 6025 Location: Holland
|
Posted: Fri Feb 27, 2015 4:08 pm Post subject: |
|
|
exact, have a look at Igors sample that he attached earlier. _________________ Mark |
|
Back to top |
|
|
Duesentrieb72
Joined: 17 Feb 2006 Posts: 44
|
Posted: Fri Feb 27, 2015 4:19 pm Post subject: |
|
|
Hi Igor and Mark,
thanks a lot for your fast reply.
It works...
Duesentrieb72 |
|
Back to top |
|
|
hzz
Joined: 20 Feb 2007 Posts: 314
|
Posted: Sat Jun 08, 2019 12:18 am Post subject: Including the bootloader with $Boot and $Inc |
|
|
I have tried to include the compiler as indicated in this thread with version 2.0.8.1 and get the error:
Error : 344 Line : 200 Program will overwrite bootloader [ 256840 too long] , in File : D:\DESARROLLO\Ei_2.26\Main.bas
Just want to know if problem has not been solved in 2.0.8.1 or am I doing something wrong.
Regards |
|
Back to top |
|
|
njepsen
Joined: 13 Aug 2007 Posts: 471
|
Posted: Mon Sep 16, 2019 4:21 am Post subject: |
|
|
I have tried this for several hours and been completely unsuccessful. Here is my bootloader, which works if I compile & download it to the device. Code: |
'-------------------------------------------------------------------------------
'
Dim Starterr As Byte
Starterr = Peek(0)
Writeeeprom Starterr , 80 'save MCUSCR (Register 0) to eeprom
Starterr = 125
Writeeeprom Starterr , 100 'confirm that BL is present
$regfile = "m1284pdef.dat"
Const Loaderchip = 1284
$loader = &HF000 ' 4096 words, bootloader starts at HF000
Const Maxwordbit = 7 ' Z7 is maximum bit '
Const Loadsize = &HF000 * 2 ' highest Number of bytes to load
$crystal = 9830400
$hwstack = 128
$swstack = 128
$framesize = 128
' Define here name of Hex-File
Const Filenamehex = "Boot.hex"
Const Filenamehexdone = "BootDone.hex"
Disable Interrupts
Open "comc.3:38400,8,n,1" For Output As #1 'my debug port
Print #1 , "Bootloader started" ' Boot-loader Started
Waitms 500 ' Time for Card to settle
'-------------------------------------------------------------------------------
Dim Btemp1 As Byte
'Print #1 , "Checking SD card"
$include "config_mmcsd_hc.bas" 'set up the high capacity SD card comms ver boot2.1
' Check success of card initializing
If Gbdriveerror <> 0 Then
' Print #1 , "SD card init error"
' Print #1 , "e" ; Hex(gbdriveerror) ' Error during card initializing
Goto Startmain
End If
' Include AVR-DOS Configuration and library
$include "Config_AVR-DOS_boot.BAS"
Print #1 , "D = init DOS file system"
Btemp1 = Initfilesystem(1) ' Get File system
' use 0 for drive without Master boot record
If Btemp1 <> 0 Then
' Print #1 , "Err reading DOS file system"
' Print #1 , "e" ; Hex(btemp1) ' Error at reading file system
Goto Startmain
End If
Dim _sec As Byte , _min As Byte , _hour As Byte , _day As Byte , _month As Byte , _year As Byte
Const _userclock = 0
Const Maxword =(2 ^ Maxwordbit) * 2 '128
Const Maxwordshift = Maxwordbit + 1
Const Maxpages = Loadsize / Maxword
Const Fn = 10 ' file-number
'Dim the used variables
Dim Strline As String * 80 ' input line from file
Dim Blinebytes As Byte ' data bytes in hex-line
Dim Blinedataposition As Byte ' first/current position of hex-data in line
Dim Blineendposition As Byte
Dim Blinestatus As Byte
Dim Blinelen As Byte
Dim Strtemp As String * 4
Dim Berror As Byte ' error byte
Dim Strname1 As String * 12
Dim Strname2 As String * 12
Dim J As Byte , Spmcrval As Byte ' self program command byte value
Dim Bprog As Byte
Dim Z As Long 'this is the Z pointer word
Dim Vl As Byte , Vh As Byte ' these bytes are used for the data values
Dim Wrd As Word , Page As Word 'these vars contain the page and word address
Dim Bcrc As Byte
Dim Buf(128) As Byte
Dim Bufpointer As Byte
Dim Lfilelen As Long
Disable Interrupts 'we do not use ints
'*****************************************************************************
'---- Start Boot loader
'
'Check if boot.hex is there
Lfilelen = Filelen(filenamehex)
If Lfilelen > 0 Then
Gosub Flashhex
Else
Print #1 , "No boot file found"
End If
'***************************************************************************
Startmain:
Print #1 , "Start Main";
Goto _reset
End
''**************************************************************************
Flashhex:
' 1. check Hex-File
Bprog = 0 ' check Intel Hex File
Print #1 , "Checking hex file"
Gosub Bootload
' 2. Flash from Hex-File
Bprog = 1 ' program flash
'Print #1 , "Programing Flash from Hex file"
Gosub Bootload
#if Varexist( "FileNameHexDone")
Strname1 = Filenamehex
Strname2 = Filenamehexdone
Kill Strname2
' Print #1 , "Renaming boot.hex file"
Name Strname1 As Strname2
'Boot successfull at this point.
'Write a file
'to the sd card to indicate this
'which can be read by the main program
Strname1 = "success_.txt"
Open Strname1 For Binary As #128
J = 89 '89 = bootload successful.78 = not successful
Put #128 , J
Flush #128
Close #128
#endif
Goto Startmain:
'***************************************************************************
' Boot loader part (same for File-Checking and Flashing)
Bootload:
Open Filenamehex For Input As #fn
If Gbdoserror > 0 Then
' Print #1 , "DOS error during file opening" ; Hex(gbdoserror)
Berror = 1
Goto Here:
End If
Page = 0
Wrd = 0
If Bprog = 1 Then
Spmcrval = 3 : Gosub Do_spm ' erase the first page
Spmcrval = 17 : Gosub Do_spm ' re-enable page
End If
Berror = 0
Bufpointer = 1
Blinebytes = 0
Lfilelen = 0
Do
If Blinebytes = 0 Then
Gosub Loadhexfileline
End If
Select Case Blinestatus
Case 0 ' read normal data line
Lfilelen = Lfilelen + Blinebytes
If Lfilelen > Loadsize Then
' Print #1 , " wrong flash size" ' Wrong Flash Size
Berror = 1
Exit Do
End If
For Blinedataposition = Blinedataposition To Blineendposition Step 2
Strtemp = Mid(strline , Blinedataposition , 2)
Btemp1 = Hexval(strtemp)
Buf(bufpointer) = Btemp1
Incr Bufpointer
If Bufpointer > 128 Then
Gosub Writepage
Bufpointer = 1
End If
Decr Blinebytes
Next
Case 1 ' address extend record
Blinebytes = 0 ' prepare for reading next line
' Address extend line, do nothing
Case 2
' EOF Line read
If Bufpointer > 1 Then
Gosub Writepage
End If
If Wrd > 0 Then
Wrd = 0
Spmcrval = 5 : Gosub Do_spm
Spmcrval = 17 : Gosub Do_spm
End If
Exit Do
Case Else ' Error
Print #1 , "Line error " ; Hex(blinestatus) ; " "
Berror = 1
Exit Do
End Select
Loop
Close #fn
Here:
If Berror > 0 Then
'all errors captured at this point.
'success.txt written as error, to Sd card
'which causes a text
'' Strname1 = "success_.txt"
'' Open Strname1 For Binary As #128
'' J = 78 '78 = N = not successful
'' Put #128 , J
'' Flush #128
'' Close #128
Goto Startmain ' restart in case of error
End If
Return
'*******************************************************************************
Loadhexfileline:
If Eof(#fn) <> 0 Then
Blinestatus = 8 ' no regular end of File
Return
End If
Line Input #fn , Strline
If Gbdoserror <> 0 Then
Blinestatus = 7 'DOS error
Return
End If
Strtemp = Mid(strline , 1 , 1) ' check for starting ":"
If Strtemp <> ":" Then
Blinestatus = 6
Return
End If
' Check Checksum
Blinelen = Len(strline)
Bcrc = 0
For Btemp1 = 2 To Blinelen Step 2
Strtemp = Mid(strline , Btemp1 , 2)
Bcrc = Bcrc + Hexval(strtemp)
Next
If Bcrc <> 0 Then
Blinestatus = 9 'checksum error
Return
End If
' Number of bytes
Strtemp = Mid(strline , 2 , 2)
Blinebytes = Hexval(strtemp)
If Blinebytes > 0 Then
Blinedataposition = 10
Btemp1 = Blinebytes * 2
Blineendposition = Btemp1 + 8
End If
' Type of Record
Strtemp = Mid(strline , 8 , 2)
Select Case Strtemp
Case "00" ' normal data record
Blinestatus = 0
Case "01" ' address extend record (> 64KB)
Blinestatus = 2
Case "02" ' EOF record
Blinestatus = 1
Case Else ' unknown record type (Error?)
Blinestatus = 5
End Select
Return
'*******************************************************************************
'write one or more pages
Writepage:
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
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
Wrd = 0 ' Z pointer needs wrd to be 0
Spmcrval = 5 : Gosub Do_spm ' write page
Spmcrval = 17 : Gosub Do_spm ' re-enable page
Page = Page + 1 ' next page
If Page <= Maxpages Then ' avoid to erase first page of bootlaoder
Spmcrval = 3 : Gosub Do_spm ' erase next page
Spmcrval = 17 : Gosub Do_spm ' re-enable page
End If
End If
Next
Return
Do_spm:
Z = Page 'make equal to page
Shift Z , Left , Maxwordshift 'shift to proper place
Z = Z + Wrd
If Bprog <> 1 Then
Return
End If
Bitwait Spmcsr.0 , Reset ' check for previous SPM complete
Bitwait Eecr.1 , Reset
'wait for eeprom 'add word
lds r30,{Z}
lds r31,{Z+1}
#if Loaderchip = 1284
lds r24,{Z+2}
sts rampz,r24 ' we need to set rampz also for the M128
#endif
lds r0, {vl} 'store them into r0 and r1 registers
lds r1, {vh}
Spmcsr = Spmcrval 'assign register
spm 'this is an asm instruction
nop
nop
Return
|
Here is the program I'm trying to attach it to:
Code: |
'*******************************************************************************
$regfile = "m1284pdef.dat" 'my processor
$crystal = 9830400 'system crystal
$framesize = 800 ' Located at top of 16k of SRAM
$hwstack = 550 '
$swstack = 550 '
$frameprotect = 1
Disable Jtag
'-------------------------------------------------------------------------------
'Open a software UART TRANSMIT channel for debug on software ser port
Open "comc.3:38400,8,n,1" For Output As #1 '
Open "comc.2:38400,8,n,1" For Input As #5
'****************************************************
Print #1 , ""
Print #1 , ">>******* DID A REBOOT **********<<"
Print #1 , ">> File Version " ; Version(3)
Print #1 , ">> File Version " ; Version(1)
Print #1 , ""
'Main Loop
do
Print #1 , ""
print #1 , ">> start over"
wait 2
loop
End
'**************************************************
$loader = $F000
$Inc Bootloader , NoSize , "j:\Dropbox\projects\mybootloader.bin"
end
|
The $loader command finds the .bin file ok ( and if i corrupt the name it comes back and says it cant find the file, so that works.
BUT When I reset the chip, it does not run the bootloader.
The fuse settings are:
BootRST - ticked
BOOTSZ Bootflashsize=4096 words start addr = $F000 _________________ Neil |
|
Back to top |
|
|
andro
Joined: 12 Mar 2007 Posts: 94 Location: Ljubljana
|
Posted: Wed Nov 27, 2019 10:40 pm Post subject: |
|
|
Hello Neil,
does Your bootloader work or not?
BR
Andrej |
|
Back to top |
|
|
|
|
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
|
|