• AVR Freaks

Hot!EZBL OTA for PIC24 without dual-partitions

Author
aclarke
New Member
  • Total Posts : 12
  • Reward points : 0
  • Joined: 2010/06/10 12:49:25
  • Location: 0
  • Status: offline
2018/10/04 13:20:57 (permalink)
0

EZBL OTA for PIC24 without dual-partitions

I would like to perform over the air (OTA) updates using the Microchip Easy Bootloader Library (EZBL) and a PIC24128GA704.
 
I see in another thread that there is an good example implementation for OTA updates with EZBL but it requires a dual-partition device.
https://www.microchip.com/forums/FindPost/1065342
 
What is the easiest way to implement a similar, safe update?  I would like to download the entire image (BL2 file) over a serial port connection and verify it before I overwrite the current application version.  Is this possible with EZBL without too much work?   There is enough room for two copies of the application. I also need to reserve some space for configuration data that should not be updated by EZBL.

Embedded Systems Consulting AaronClarke.com - Blog: EmbeddedCoding.com
#1

6 Replies Related Threads

    aclarke
    New Member
    • Total Posts : 12
    • Reward points : 0
    • Joined: 2010/06/10 12:49:25
    • Location: 0
    • Status: offline
    Re: EZBL OTA for PIC24 without dual-partitions 2018/10/15 14:40:22 (permalink)
    0
    Are there any examples of using internal flash with Microchip Libraries for Applications (MLA)?   I haven't been able to find any.
     
    I would like to look at an example or get some help to define the following correctly.  
    #define DRV_FILEIO_INTERNAL_FLASH_CONFIG_DRIVE_CAPACITY 
    #define DRV_FILEIO_INTERNAL_FLASH_CONFIG_FILES_ADDRESS 
    #define DRV_FILEIO_INTERNAL_FLASH_CONFIG_ERASE_BLOCK_SIZE  // Is this just the page erase size 0x800?
    #define DRV_FILEIO_INTERNAL_FLASH_CONFIG_UNLOCK_VERIFICATION_FUNCTION(x) 
     
    I have EZBL working on the board using a serial port connection to a PC and ezbl_comm.exe.  I also have the application configuration data set up so that an update will not erase the data using EZBL_AllocFlashHole() in the application and EZBL_setNoEraseRange() in the bootloader.
     
    Now I need to implement the OTA part - I need to receive the image over serial from a radio chip with no handshaking so I can't use the serial update protocol of EZBL.  Instead, I plan to receive the file with the application instead of the bootloader store it in internal flash.  I would like to use FILEIO so I can use the EZBL_InstallFILEIO2Flash() function to perform the flash update.  That will check the .bl2 file before erasing the application and updating it.

    Embedded Systems Consulting AaronClarke.com - Blog: EmbeddedCoding.com
    #2
    aclarke
    New Member
    • Total Posts : 12
    • Reward points : 0
    • Joined: 2010/06/10 12:49:25
    • Location: 0
    • Status: offline
    Re: EZBL OTA for PIC24 without dual-partitions 2019/03/20 06:53:39 (permalink)
    0
    I will answer my own question in case anyone else has this problem.  I found a method that works for OTA updates or serial updates without BL2 protocol handshaking.  I can just load a bl2 file into program memory, check it entirely to see it's OK, then perform the update from the bootloader.
     
    I was going to use the fileio library so I could use EZBL_InstallFILEIO2Flash, it checks and installs a firmware update stored on a USB drive, but the FILEIO library was too large.  It was also unnecessary because I didn't need FAT compatibility, I only needed to store a single bl2 file in program memory before an update.  Instead, I made a copy of EZBL_InstallFILEIO2Flash() called it EZBL_InstallFlash2Flash(), and replaced FILEIO_Read()'s with a wrapper function that does the same thing with EZBL_ReadPackedFlash().   EZBL_InstallFlash2Flash() parameters are just the bl2 file program memory address and the commit value.
     
    I use EZBL_WriteROM() in my application to place the bl2 file in program memory.  I use EZBL_AllocFlashHole() in the application to reserve space in program memory that will not be erased by the bootloader during the update.  I'm not sure if that's the best way to reserve the space but it is working.
     
    After the file is downloaded, I perform the update by setting a flag and calling the bootloader task.  It checks the flag and calls the new function commit=0 to check the file and again with commit =1 to perform the update if it checks out.
     
    It also works with the serial port, I don't need any handshaking, at least at 115200, I can just binary send the file over serial with the bootloader task disabled, EZBL_WriteROM() keeps up with the UART but I haven't tested any higher rates.  I'm currently letting the application control the download this way, it recognizes the header, writes the received data to program memory.   I might move some of that functionality into the bootloader.

    Embedded Systems Consulting AaronClarke.com - Blog: EmbeddedCoding.com
    #3
    cswieson
    New Member
    • Total Posts : 2
    • Reward points : 0
    • Joined: 2019/11/13 06:45:23
    • Location: 0
    • Status: offline
    Re: EZBL OTA for PIC24 without dual-partitions 2019/11/14 14:22:38 (permalink)
    0
    Sorry to resurrect an old post, but we are looking to do pretty much exactly what you describe only on a PIC24EP512GU810.
    We are running into an issue allocating the space for the new code using EZBL_AllocFlashHole(). The bootloader project builds fine, but when trying to build the application it keeps throwing a "address for section .const conflicts with absolute section .text.otaCode" error. There is plenty of code space available.
    Did you have to do anything special to get everything to fit in properly?
    #4
    aclarke
    New Member
    • Total Posts : 12
    • Reward points : 0
    • Joined: 2010/06/10 12:49:25
    • Location: 0
    • Status: offline
    Re: EZBL OTA for PIC24 without dual-partitions 2019/11/15 13:19:33 (permalink)
    0
    I don't recall seeing that error.
     
    This is the application code for the flash hole
     
    extern unsigned long EZBL_flash_file_start_address;
    ...

    /* Space for bl2 file download storage for flash update */
    EZBL_AllocFlashHole(file_data,
                        EZBL_FLASH_FILE_SIZE, // bytes to reserve
                        FLASH_PAGE_ERASE_SIZE,
                        EZBL_FLASH_FILE_START_ADDRESS);  // -1 to let it be automatically assigned
    ...
    EZBL_flash_file_start_address = EZBL_FlashHoleAddr(file_data);
     

    Those constants are defined in a header
    #define FLASH_PAGE_ERASE_SIZE 0x800
    #define EZBL_FLASH_FILE_START_ADDRESS 0x4000
    #define EZBL_FLASH_FILE_ERASE_PAGES 28
    #define EZBL_FLASH_FILE_SIZE FLASH_PAGE_ERASE_SIZE*EZBL_FLASH_FILE_ERASE_PAGES


     
    This is in the bootloader's main.c
    unsigned long EZBL_flash_file_start_address    __attribute__((persistent));


     
     
     

    Embedded Systems Consulting AaronClarke.com - Blog: EmbeddedCoding.com
    #5
    cswieson
    New Member
    • Total Posts : 2
    • Reward points : 0
    • Joined: 2019/11/13 06:45:23
    • Location: 0
    • Status: offline
    Re: EZBL OTA for PIC24 without dual-partitions 2019/11/15 13:47:56 (permalink)
    0
    Ok, so you put the EZBL_AllocFlashHole in the application code, not the bootloader. I was trying to allocate it in the bootloader code (there was a line in the help about "By allocating the EE flash pages in your application, any EE data you have stored will get erased each time a new application is programmed by the bootloader").
     
    Did you have to worry about the bootloader erasing the flash hole when it did the install?
     
    Thanks.
    #6
    aclarke
    New Member
    • Total Posts : 12
    • Reward points : 0
    • Joined: 2010/06/10 12:49:25
    • Location: 0
    • Status: offline
    Re: EZBL OTA for PIC24 without dual-partitions 2019/11/26 09:02:29 (permalink)
    0
    Its been a while but I think I handled that using EZBL_SetNoEraseRange().
     
    int EZBL_BootloaderTask(void)
    {
        int install_return_code;
        
        if (EZBL_flash_file_ready == 1) {
            EZBL_flash_file_ready = 2; // flag that update is in progress

            // set address range not to erase now that it is programmed
            EZBL_SetNoEraseRange(EZBL_FLASH_FILE_START_ADDRESS, EZBL_FLASH_FILE_START_ADDRESS+EZBL_FLASH_FILE_SIZE-1);

            install_return_code = EZBL_InstallFlash2Flash(EZBL_flash_file_start_address, 0);
            EZBL_printf("\nEZBL_InstallFlash2Flash returned %d\n",install_return_code);
            if (install_return_code == EZBL_ERROR_SUCCESS) {
                EZBL_printf("bl2 file verified to be correct, starting firmware update\n",install_return_code);
                install_return_code = EZBL_InstallFlash2Flash(EZBL_flash_file_start_address, 1);
                EZBL_printf("EZBL_InstallFlash2Flash returned %d\n",install_return_code);
                if (install_return_code != EZBL_ERROR_SUCCESS) {
                    EZBL_printf("Firmware update failed\n");
                }
            }
            else {
                EZBL_printf("bl2 file in flash does not pass all checks, not updating\n");
            }
    ...
     
    The function EZBL_InstallFlash2Flash() is the one I created based on EZBL_InstallFILEIO2Flash()
     
     

    Embedded Systems Consulting AaronClarke.com - Blog: EmbeddedCoding.com
    #7
    Jump to:
    © 2019 APG vNext Commercial Version 4.5