Bootloader code size questions!

Hi ,

I am a fresh one in the Forum.

Here I have some questions when I added the bootloader into my application. I read the applicatiin note "r01an0718ej0102_rl78g13.pdf" know the sample code in CubeSuite+ , but my requirement of bootloader is different. 1) To save code space (MCU is R5F100AC 32K ROM) I hope the bootloader code size can be as small as possible. 2) don't want the bootswap function.

I removed the swap function in bootloader code and set the flash staring address to 1000H (application start address) in CubeSuite+ and tried a test application about 200H code size. but I found the map file of application allways exist the 4bytes code "@EVECT00                     02000H    00004H  CSEG AT
                  @EVECT00 @cstarte   02000H    00004H",  The last application code is at 11AEH , a) I don't know how to move the reset vector of application to 1000H in CubeSuit+ ?  b) how to further decrease the bootloader code size (for example remove the not necessary functions of FSL lib into bootloader and how to check) ?

c) Any limitation of application starting adderss (for example set the staring address to 321H ) ? d) Could I use the "code generation" of CubeSuite+ for bootloader project ? 

 

Appreciate your help.

 

Br. Frank Tsai

 

 

 

  • In reply to Kirin:

    Hi Kirin,

    a)Do you means application that used FSL and FDL library still can use the __sreg variables freely without worry about the content been destoried by the erase/write operation of FSL/FDL ?

    b)FSL/FDL will handle that avoid destory original content of SADDR area right ?

    c)Any new document describe how to use SADDR with FSL and FDL ? (The FSL application note said that "Area where RAM (stack, data buffer, etc.) used by the Flash Self-Programming Library cannot be allocated")

  • In reply to chtsai:

    Hello chtsai,

    a&b) Yes!
    Only during the flash write/erase, SADDR can not be accessed, it is not broken. (So, do not put write buffer for FSL in SADDR.)
    Although it is an exception when you use  "FSL_ChangeInterruptTable" function.

    c)No document.
    Sorry, I had misread, so sentences were rewritten in (c)

  • In reply to Kirin:

    c) Additional information
    I introduce information from Japanese Rules.
    japan.renesasrulz.com/.../8039.aspx
    I translated it from Japanese as following.

    Inte who uses FSL in RL78/G14 had a question as follows,
    > There are the following notes, What is "data buffer" ?
    >> Caution 2. Do not allocate the stack area, data buffers for use by the flash library, arguments of library
    >> functions, branch destinations in the processing of vectored interrupts, or destinations or
    >> sources for DTC transfer to the area from FFE20H to FFEDFH when performing selfprogramming
    >> or rewriting of the data flash memory.
     
    "チョコ" Choco who is a Japanese Renesas staff answered as following,
    It is an area that stores the data to be written to the flash. it never mean "all variables".
    Descriptions in here, do not set stack area and write data buffer for the self-programming library to SADDR area ,
    And interrupt or DTC that can occur during the self-programming library operations do not use the SADDR area.
    Also the data used by other (customer) programs is no problem in SADDR area.
  • In reply to Kirin:

    Hi Kirin,

    Much clear, Thanks,

    Here I built the boot project and test without problem (refernec the sample code from r01an0718_praxis01) and then I move my application (stand alone project) into the sub project of "flash project" part, but cause many error when built the "flash project", as below:

    (E) E3206 RA78K0R error E3206: Segment '@@DATA' can't allocate to memory - ignored FlashAppFW.mtsp

    (E) E3206 RA78K0R error E3206: Segment '@@INIT' can't allocate to memory - ignored FlashAppFW.mtsp

    (E) E3206 RA78K0R error E3206: Segment 'BOOT_DAT' can't allocate to memory - ignored FlashAppFW.mtsp

    (E) E3206 RA78K0R error E3206: Segment '@@INIS' can't allocate to memory - ignored FlashAppFW.mtsp

    (E) E3206 RA78K0R error E3206: Segment '@@DATS' can't allocate to memory - ignored FlashAppFW.mtsp

    (E) E3206 RA78K0R error E3206: Segment '@@INITL' can't allocate to memory - ignored FlashAppFW.mtsp

    (E) E3206 RA78K0R error E3206: Segment '@@DATAL' can't allocate to memory - ignored FlashAppFW.mtsp

    (E) E3206 RA78K0R error E3206: Segment '@@BITS' can't allocate to memory - ignored FlashAppFW.mtsp

    (E) E7001 VF78K0R error E7001: The link error was found. FlashAppFW.mtsp

    The boot FW sub-project part can successful compile/build/test without problem:

    list as below:

    CC78K0R warning W0071: ROM data are treated as far data

    CC78K0R warning W0072: Please check standard library function

    >DefaultBuild\BootFW.lmf

    >DefaultBuild\BootFW.hex

    >vf78k0r.exe

    *** Memory Area Information ***

    ROM : B5CH byte(s) real data

    RAM : DCH byte(s) real data

    *** Memory Area Information in ROM ***

    ROM : 95CH byte(s)

    OCD_ROM : 200H byte(s)

    *** Memory Area Information in RAM ***

    RAM : D0H byte(s)

    RAM_SADDR : CH byte(s)

    ------ Build ended(Error:0, Warning:12)(BootFW, DefaultBuild) ------

    My application can compile/built and test without problem when build as standalone project in cubesuit,

    as below:

    *** Memory Area Information ***

    ROM : 4B53H byte(s) real data

    RAM : 270H byte(s) real data

    *** Memory Area Information in ROM ***

    ROM : 4B53H byte(s)

    *** Memory Area Information in RAM ***

    RAM : 244H byte(s)

    RAM_SADDR : 2CH byte(s)

    ------ Build ended(Error:0, Warning:0)(COMMPTM, DefaultBuild) ------

    The target MCU is RL78/G13 R5F100AC (32KROM,2KRAM) , also use the pico FDL (T4) in my application without refernce anything(functions and variables) of BOOT FW code.

    It seems the code size and RAM still have enough space but I don't know why many segment "can't allocate to memory"

    1) How to find the reasons of errors (no map file created)?

    2) Any direction/document said how to transfer the original non-bootable application to bootable(flash) project ?

    3) The link direction seems need to do modification, here is the setting of my flash project:

    ***********************************************************

    ; Redefined ROM area

    ;***********************************************************

    ; ----------------------------------------------------------

    ; Redefined default data segment ROM

    ; ----------------------------------------------------------

    MEMORY ROM       : ( 000000H, 007800H )

    ; ----------------------------------------------------------

    ; Define new memory entry for const area

    ; ----------------------------------------------------------

    MEMORY ROM_DATA  : ( 007800H, 000400H )

    ; ----------------------------------------------------------

    ; Define new memory entry for OCD Monitor area

    ; ----------------------------------------------------------

    MEMORY OCD_ROM   : ( 007C00H, 000400H )

    ; ----------------------------------------------------------

    ; Redefined default data segment RAM

    ; ----------------------------------------------------------

    MEMORY RAM:( 0FF900H, 0520H )

    ; ----------------------------------------------------------

    ; Define new memory entry for saddr area

    ; ----------------------------------------------------------

    MEMORY RAM_SADDR : ( 0FFE20H, 0001E0H )

    anything suggestion of the link direction file.

    Best regards,

  • In reply to chtsai:

    Hello chtsai,

    > 1) How to find the reasons of errors (no map file created)?
    No idea....

    > 2) Any direction/document said how to transfer the original non-bootable application to bootable(flash) project ?
    No idea....

    It may be better to add to an original "r_fsl_praxis01_flash" little by little .
  • In reply to Kirin:

    The document below!
    documentation.renesas.com/.../r20ut2623ej0100_qsbd78.pdf
    "2.14 Prepare for Implementing Boot-flash Relink Function"

    I wasn't reading this document....
  • In reply to Kirin:

    Hi Kirin,

    Thanks, I can build the application project without error now, but I found that all the interrupts of application didn't happen,  I check the map file of flash application and sure that the interrupt in at the branch TABLE , as below

            @EVECT14                     01028H    00004H  CSEG AT

                     @EVECT14 r_cg_serial_user

                                         01028H    00004H

    * gap *                               0102CH    00010H

            @EVECT1E                     0103CH    00004H  CSEG AT

                     @EVECT1E r_cg_serial_user

                                         0103CH    00004H

    * gap *                               01040H    00008H

            @EVECT24                     01048H    00008H  CSEG AT

                     @EVECT24 r_cg_serial_user

                                         01048H    00008H

            @ECNSTL                      01050H    0001EH  CSEG PAGE64KP

                     @ECNSTL  m_flogx    01050H    0001EH

    * gap *                               0106EH    00002H

            @EVECT38                     01070H    00004H  CSEG AT

                     @EVECT38 r_cg_it_user

    * gap *                               01287H    00D79H

            @ECNST                       02000H    00392H  CSEG MIRRORP

                     @ECNST   @cstarte   02000H    00000H

    but I can't figure out why ? could help give some direction.

    Brs,

  • In reply to chtsai:

    Hello chtsai,

    I'm glad I could hear that you could build without error!

    Now, I have questions.

    1) Do you use "EI();" to make interrupt enable?

    2) Does the "IF" flag erect(=1) ?

    3) Execute the code below, what is happen?

    #pragma nop
    #pragma EI
    #pragma sfr
    #pragma interrupt INTAD AD_interrupt
    __interrupt static void AD_interrupt(void){
     NOP(); //set break point
     NOP();
     NOP();
     NOP();
     NOP();
    }
    void main (void){
    ADMK=0;
    EI();
    while(1){
      ADIF=1;
    }
    }
  • In reply to Kirin:

    Hi Kirin,

    I found that the interrupt vectors (menory address 0x06~0x7F) are redirect to 20xxH not 10xxH, which cause my application crash (reset , parity error), I had set the flash and branch table to 1000H in the boot subproject according our discussion before, the map file can't discovery this problem. Do you know how to fix this problem.

    I don't use bootswap function and set the branch table to 1000H by the repvect.bat file as we discussed before.

    Any comment is appreciate. by the way do you know how to paste picture to the reply text ?

    Brs,

  • In reply to chtsai:

    Hello chtsai,
    Probably it's because the library of startup which is already compiled is used.
    So it's necessary to compile again from a source.
    select "C:\Program Files (x86)\Renesas Electronics\CS+\CACX\CA78K0R\Vxxxxxxx\Src\cc78k0r\src\cstartb.asm" for Startup!


  • In reply to Kirin:

    Hi Kirin,

    I added the cstartb.asm into "startup" calegory then rebuilt and download , but still at 20xxH not 10xxH, the vect.inc has "ITBLTOP EQU 1000H" , also the map file of boot project I found something as below , do I miss something ?

    ;FF     boot_main

    <0100738_prIntComWdt

    ;FF     Comm_UART

    ;FF     CRC

    ;FF     TargetBL_Commands

    <0100790_fsl_descriptor_pstr

    ;FF     TargetBL_InfoBlock

    ;FF     Target_DevSpecific

    ;FF     fsl_f_init

    ;FF     fsl_f_open

    ;FF     fsl_f_close

    ;FF     fsl_f_pfunc

    ;FF     fsl_b_common

    ;FF     fsl_r_std_cmd

    ;FF     fsl_r_check_flow

    ;FF     @curem

    ;FF     @SEGREG

    ;FF     @stkinit

    ;FF     @RTARG0

    ;FF     @vect06

    <0002000ITBLTOP

    0000001MIRROR

    0000001_CODEFAR

    0000000_DATAFAR

    0000000_DHRYSTONE

    0000001_ESCOPY

    0000000_FLASH

    0000001_LIBCNSTFAR

    0000001_MIRROR

    0000000_OLDFUNC

    0000001_ORGFUNC

    0000000_PASCAL

    0000001_PATCH01

    0000000_RAMFUNC

    0000000_RL78_2

    0000000_SAVERSVD

    0000000_STATIC

    0000000_XMAC

    0000000_XMUL

    0000000_XMULDIV

    ;FF     @vect08

    <0002000ITBLTOP

    0000001MIRROR

    0000001_CODEFAR

    .....

  • In reply to chtsai:

    Hello chtsai,

    Umm, 真傷腦筋。

    Copy files below into your CS+ folder "C:\Program Files (x86)\Renesas Electronics\CS+\CACX\CA78K0R\V1.71\Lib78k0r" (Compiler version maybe different...)
    Have to copy them into the folder of the compiler version which is being used by the project.

    renesasrulz.com/.../vect1000h.zip (ITBLTOP EQU 1000H with option "-cf1166a0 -common")

    Then clean project and re-build the projects(boot and flash).

  • In reply to Kirin:

    Hi Kirin,

    Good new, it work after replaced  libs etc. with the vect1000h.zip.

    I found that it is my mistake when built files with repvect.bat before ?

    Thanks,

    Brs,

  • In reply to chtsai:

    Hi Kirin,

    interrupt is ok now, but I encounter another problem when I used the FDL with my application.

    I found the value of variables will be destroy after init the FDL, how could I avoid the problem ?  my boot project used the FSL and flash application project use the FDL, how should I declare the content of link files for those sub-projects respectively ?

    Take the R5F100AC as an example (32KROM, 2KRAM, 4KDROM)

    below is my declare sample:

    boot side:

    MEMORY RAM:( 0FF700H, 0720H ) #2KRAM

    ; ----------------------------------------------------------

    ; Define new memory entry for saddr area

    ; ----------------------------------------------------------

    MEMORY RAM_SADDR : ( 0FFE20H, 0001E0H )

    flash application side:

    ;no RAM range declaration ,

    ; will casue link error if set RAM or RAM_ADDDR

    Brs,

  • In reply to chtsai:

    Hello,

    Which address area is broken?

    And, let me know the .map file of boot.