This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TM4C1294NCPDT: Ethernet Flash Bootloader

Part Number: TM4C1294NCPDT

Tool/software:

Hi there

I want to make boot_emac_flash (ethernet bootloader) wait for a time and to check if there is update or not then goes to application, that's because i don;t want the application to pass the control to bootloader i just want upon reset is the only time bootloader can update the software is this possible ?

  • Hi,

      You can configure bl_config.h so that if there is state change on a specified pin then it will force an update. 

      Also refer to the bl_startup_ccs.s file in the bootloader directory. I probably explained to you in another post. After reset, the bootloader will first check if there is a valid application image by checking the application's stack pointer and reset vector. If they are valid which is your case, then the bootloader will simply just jump tot the application. However, look at line 264. You can define your how hook function before jumping to the application if you want the bootloader to check for other conditions or  as you wish to wait for some time. You are free to customize the bootloader with the hookup function. 

  • You can define your how hook function before jumping to the application if you want the bootloader to check for other conditions or  as you wish to wait for some time. You are free to customize the bootloader with the hookup function. 

    where i can customize this function. where does it exist ?

  • Refer to the bl_config.h file for details. Uncomment line 1379 and define your own hook function MyHwInitFunc(). 

  • i add this code to bl_startup_ccs.s RESTISR code and weird behaviour happens, when i first program the application (boot_demo_emac) it burns well, but when i try to update the code upon click reset the LM flasher does not recognize the ethernet connection but when the appliation tun it begins recognize the ethernet connection.  

  • when i first program the application (boot_demo_emac) it burns well, but when i try to update the code upon click reset the LM flasher does not recognize the ethernet connection but when the appliation tun it begins recognize the ethernet connection.

    How long are you waiting in the loop before jumping to the application? While you are in the loop, the Ethernet is not yet setup. You might want to try to add your hook after the Ethernet is setup. See below highlighted in red where hooks may be plugged. 

    ;;*****************************************************************************
    ;;
    ;; Initialize the processor by copying the boot loader from flash to SRAM, zero
    ;; filling the .bss section, and moving the vector table to the beginning of
    ;; SRAM. The return address is modified to point to the SRAM copy of the boot
    ;; loader instead of the flash copy, resulting in a branch to the copy now in
    ;; SRAM.
    ;;
    ;;*****************************************************************************
    .ref bss_run
    bss_start .word bss_run
    .ref __STACK_TOP
    bss_end .word __STACK_TOP

    .thumbfunc ProcessorInit
    ProcessorInit: .asmfunc
    ;;
    ;; Copy the code image from flash to SRAM.
    ;;
    movs r0, #0x0000
    movs r1, #0x0000
    movt r1, #0x2000
    ldr r2, bss_start
    copy_loop:
    ldr r3, [r0], #4
    str r3, [r1], #4
    cmp r1, r2
    blt copy_loop

    ;;
    ;; Zero fill the .bss section.
    ;;
    movs r0, #0x0000
    ldr r2, bss_end
    zero_loop:
    str r0, [r1], #4
    cmp r1, r2
    blt zero_loop

    ;;
    ;; Set the vector table pointer to the beginning of SRAM.
    ;;
    movw r0, #(NVIC_VTABLE & 0xffff)
    movt r0, #(NVIC_VTABLE >> 16)
    movs r1, #0x0000
    movt r1, #0x2000
    str r1, [r0]

    ;;
    ;; Set the return address to the code just copied into SRAM.
    ;;
    orr lr, lr, #0x20000000

    ;;
    ;; Return to the caller.
    ;;
    bx lr
    .endasmfunc

    ;;*****************************************************************************
    ;;
    ;; The reset handler, which gets called when the processor starts.
    ;;
    ;;*****************************************************************************
    .thumbfunc ResetISR
    ResetISR: .asmfunc
    ;;
    ;; Enable the floating-point unit. This must be done here in case any
    ;; later C functions use floating point. Note that some toolchains will
    ;; use the FPU registers for general workspace even if no explicit floating
    ;; point data types are in use.
    ;;
    movw r0, #0xED88
    movt r0, #0xE000
    ldr r1, [r0]
    orr r1, r1, #0x00F00000
    str r1, [r0]

    ;;
    ;; Initialize the processor.
    ;;
    bl ProcessorInit

    ;;
    ;; Call the user-supplied low level hardware initialization function
    ;; if provided.
    ;;
    .if $$defined(BL_HW_INIT_FN_HOOK)
    .ref BL_HW_INIT_FN_HOOK
    bl BL_HW_INIT_FN_HOOK
    .endif

    ;;
    ;; See if an update should be performed.
    ;;
    .ref CheckForceUpdate
    bl CheckForceUpdate
    cbz r0, CallApplication

    ;;
    ;; Configure the microcontroller.
    ;;
    .thumbfunc EnterBootLoader
    EnterBootLoader:
    .if $$defined(ENET_ENABLE_UPDATE)
    .ref ConfigureEnet
    bl ConfigureEnet
    .elseif $$defined(CAN_ENABLE_UPDATE)
    .ref ConfigureCAN
    bl ConfigureCAN
    .elseif $$defined(USB_ENABLE_UPDATE)
    .ref ConfigureUSB
    bl ConfigureUSB
    .else
    .ref ConfigureDevice
    bl ConfigureDevice
    .endif

    ;;
    ;; Call the user-supplied initialization function if provided.
    ;;
    .if $$defined(BL_INIT_FN_HOOK)
    .ref BL_INIT_FN_HOOK
    bl BL_INIT_FN_HOOK
    .endif

    ;;
    ;; Branch to the update handler.
    ;;
    .if $$defined(ENET_ENABLE_UPDATE)
    .ref UpdateBOOTP
    b UpdateBOOTP
    .elseif $$defined(CAN_ENABLE_UPDATE)
    .ref UpdaterCAN
    b UpdaterCAN
    .elseif $$defined(USB_ENABLE_UPDATE)
    .ref UpdaterUSB
    b UpdaterUSB
    .else
    .ref Updater
    b Updater
    .endif
    .endasmfunc

    ;;
    ;; This is a second symbol to allow starting the application from the boot
    ;; loader the linker may not like the perceived jump.
    ;;
    .global StartApplication
    .thumbfunc StartApplication
    StartApplication:
    ;;
    ;; Call the application via the reset handler in its vector table. Load
    ;; the address of the application vector table.
    ;;
    .thumbfunc CallApplication
    CallApplication: .asmfunc
    ;;
    ;; Copy the application's vector table to the target address if necessary.
    ;; Note that incorrect boot loader configuration could cause this to
    ;; corrupt the code! Setting VTABLE_START_ADDRESS to 0x20000000 (the start
    ;; of SRAM) is safe since this will use the same memory that the boot loader
    ;; already uses for its vector table. Great care will have to be taken if
    ;; other addresses are to be used.
    ;;
    .if (APP_START_ADDRESS != VTABLE_START_ADDRESS)
    movw r0, #(VTABLE_START_ADDRESS & 0xffff)
    .if (VTABLE_START_ADDRESS > 0xffff)
    movt r0, #(VTABLE_START_ADDRESS >> 16)
    .endif
    movw r1, #(APP_START_ADDRESS & 0xffff)
    .if (APP_START_ADDRESS > 0xffff)
    movt r1, #(APP_START_ADDRESS >> 16)
    .endif

    ;;
    ;; Calculate the end address of the vector table assuming that it has the
    ;; maximum possible number of vectors. We don't know how many the app has
    ;; populated so this is the safest approach though it may copy some non
    ;; vector data if the app table is smaller than the maximum.
    ;;
    movw r2, #(70 * 4)
    adds r2, r2, r0
    VectorCopyLoop:
    ldr r3, [r1], #4
    str r3, [r0], #4
    cmp r0, r2
    blt VectorCopyLoop
    .endif

    ;;
    ;; Set the application's vector table start address. Typically this is the
    ;; application start address but in some cases an application may relocate
    ;; this so we can't assume that these two addresses are equal.
    ;;
    movw r0, #(VTABLE_START_ADDRESS & 0xffff)
    .if (VTABLE_START_ADDRESS > 0xffff)
    movt r0, #(VTABLE_START_ADDRESS >> 16)
    .endif
    movw r1, #(NVIC_VTABLE & 0xffff)
    movt r1, #(NVIC_VTABLE >> 16)
    str r0, [r1]

    ;;
    ;; Load the stack pointer from the application's vector table.
    ;;
    .if (APP_START_ADDRESS != VTABLE_START_ADDRESS)
    movw r0, #(APP_START_ADDRESS & 0xffff)
    .if (APP_START_ADDRESS > 0xffff)
    movt r0, #(APP_START_ADDRESS >> 16)
    .endif
    .endif
    ldr sp, [r0]

    ;;
    ;; Load the initial PC from the application's vector table and branch to
    ;; the application's entry point.
    ;;
    ldr r0, [r0, #4]
    bx r0
    .endasmfunc

    ;;*****************************************************************************
    ;;
    ;; The update handler, which gets called when the application would like to
    ;; start an update.
    ;;
    ;;*****************************************************************************
    .thumbfunc UpdateHandler
    UpdateHandler: .asmfunc
    ;;
    ;; Initialize the processor.
    ;;
    bl ProcessorInit

    ;;
    ;; Load the stack pointer from the vector table.
    ;;
    movs r0, #0x0000
    ldr sp, [r0]

    ;;
    ;; Call the user-supplied low level hardware initialization function
    ;; if provided.
    ;;
    .if $$defined(BL_HW_INIT_FN_HOOK)
    bl BL_HW_INIT_FN_HOOK
    .endif

    ;;
    ;; Call the user-supplied re-initialization function if provided.
    ;;
    .if $$defined(BL_REINIT_FN_HOOK)
    .ref BL_REINIT_FN_HOOK
    bl BL_REINIT_FN_HOOK
    .endif

    ;;
    ;; Branch to the update handler.
    ;;
    .if $$defined(ENET_ENABLE_UPDATE)
    b UpdateBOOTP
    .elseif $$defined(CAN_ENABLE_UPDATE)
    .ref AppUpdaterCAN
    b AppUpdaterCAN
    .elseif $$defined(USB_ENABLE_UPDATE)
    .ref AppUpdaterUSB
    b AppUpdaterUSB
    .else
    b Updater
    .endif
    .endasmfunc

    ;;*****************************************************************************
    ;;
    ;; The NMI handler.
    ;;
    ;;*****************************************************************************
    .thumbfunc NmiSR
    NmiSR: .asmfunc
    .if $$defined(ENABLE_MOSCFAIL_HANDLER)
    ;;
    ;; Grab the fault frame from the stack (the stack will be cleared by the
    ;; processor initialization that follows).
    ;;
    ldm sp, {r4-r11}
    mov r12, lr

    ;;
    ;; Initialize the processor.
    ;;
    bl ProcessorInit

    ;;
    ;; Restore the stack frame.
    ;;
    mov lr, r12
    stm sp, {r4-r11}

    ;;
    ;; Save the link register.
    ;;
    mov r9, lr

    ;;
    ;; Call the user-supplied low level hardware initialization function
    ;; if provided.
    ;;
    .if $$defined(BL_HW_INIT_FN_HOOK)
    bl BL_HW_INIT_FN_HOOK
    .endif

    ;;
    ;; See if an update should be performed.
    ;;
    bl CheckForceUpdate
    cbz r0, EnterApplication

    ;;
    ;; Clear the MOSCFAIL bit in RESC.
    ;;
    movw r0, #(SYSCTL_RESC & 0xffff)
    movt r0, #(SYSCTL_RESC >> 16)
    ldr r1, [r0]
    bic r1, r1, #SYSCTL_RESC_MOSCFAIL
    str r1, [r0]

    ;;
    ;; Fix up the PC on the stack so that the boot pin check is bypassed
    ;; (since it has already been performed).
    ;;
    ldr r0, =EnterBootLoader
    bic r0, #0x00000001
    str r0, [sp, #0x18]

    ;;
    ;; Return from the NMI handler. This will then start execution of the
    ;; boot loader.
    ;;
    bx r9

    ;;
    ;; Restore the link register.
    ;;
    EnterApplication:
    mov lr, r9

    ;;
    ;; Copy the application's vector table to the target address if necessary.
    ;; Note that incorrect boot loader configuration could cause this to
    ;; corrupt the code! Setting VTABLE_START_ADDRESS to 0x20000000 (the start
    ;; of SRAM) is safe since this will use the same memory that the boot loader
    ;; already uses for its vector table. Great care will have to be taken if
    ;; other addresses are to be used.
    ;;
    .if (APP_START_ADDRESS != VTABLE_START_ADDRESS)
    movw r0, #(VTABLE_START_ADDRESS & 0xffff)
    .if (VTABLE_START_ADDRESS > 0xffff)
    movt r0, #(VTABLE_START_ADDRESS >> 16)
    .endif
    movw r1, #(APP_START_ADDRESS & 0xffff)
    .if (APP_START_ADDRESS > 0xffff)
    movt r1, #(APP_START_ADDRESS >> 16)
    .endif

    ;;
    ;; Calculate the end address of the vector table assuming that it has the
    ;; maximum possible number of vectors. We don't know how many the app has
    ;; populated so this is the safest approach though it may copy some non
    ;; vector data if the app table is smaller than the maximum.
    ;;
    movw r2, #(70 * 4)
    adds r2, r2, r0
    VectorCopyLoop2:
    ldr r3, [r1], #4
    str r3, [r0], #4
    cmp r0, r2
    blt VectorCopyLoop2
    .endif

    ;;
    ;; Set the application's vector table start address. Typically this is the
    ;; application start address but in some cases an application may relocate
    ;; this so we can't assume that these two addresses are equal.
    ;;
    movw r0, #(VTABLE_START_ADDRESS & 0xffff)
    .if (VTABLE_START_ADDRESS > 0xffff)
    movt r0, #(VTABLE_START_ADDRESS >> 16)
    .endif
    movw r1, #(NVIC_VTABLE & 0xffff)
    movt r1, #(NVIC_VTABLE >> 16)
    str r0, [r1]

    ;;
    ;; Remove the NMI stack frame from the boot loader's stack.
    ;;
    ldmia sp, {r4-r11}

    ;;
    ;; Get the application's stack pointer.
    ;;
    .if (APP_START_ADDRESS != VTABLE_START_ADDRESS)
    movw r0, #(APP_START_ADDRESS & 0xffff)
    .if (APP_START_ADDRESS > 0xffff)
    movt r0, #(APP_START_ADDRESS >> 16)
    .endif
    .endif
    ldr sp, [r0, #0x00]

    ;;
    ;; Fix up the NMI stack frame's return address to be the reset handler of
    ;; the application.
    ;;
    ldr r10, [r0, #0x04]
    bic r10, #0x00000001

    ;;
    ;; Store the NMI stack frame onto the application's stack.
    ;;
    stmdb sp!, {r4-r11}

    ;;
    ;; Branch to the application's NMI handler.
    ;;
    ldr r0, [r0, #0x08]
    bx r0
    .else
    ;;
    ;; Loop forever since there is nothing that we can do about a NMI.
    ;;
    b NmiSR
    .endif
    .endasmfunc

    ;;*****************************************************************************
    ;;
    ;; The hard fault handler.
    ;;
    ;;*****************************************************************************
    .thumbfunc FaultISR
    FaultISR: .asmfunc
    ;;
    ;; Loop forever since there is nothing that we can do about a hard fault.
    ;;
    b FaultISR
    .endasmfunc

    ;;*****************************************************************************
    ;;
    ;; The default interrupt handler.
    ;;
    ;;*****************************************************************************
    .thumbfunc IntDefaultHandler
    IntDefaultHandler: .asmfunc
    ;;
    ;; Loop forever since there is nothing that we can do about an unexpected
    ;; interrupt.
    ;;
    b IntDefaultHandler
    .endasmfunc

    ;;*****************************************************************************
    ;;
    ;; Provides a small delay. The loop below takes 3 cycles/loop.
    ;;
    ;;*****************************************************************************
    ; .globl Delay
    .thumbfunc Delay
    Delay: .asmfunc
    subs r0, #1
    bne Delay
    bx lr
    .endasmfunc

    .thumbfunc _c_int00
    .global _c_int00
    _c_int00: .asmfunc
    b ResetISR

    ;;*****************************************************************************
    ;;
    ;; This is the end of the file.
    ;;
    ;;*****************************************************************************
    .end

  • How long are you waiting in the loop before jumping to the application? While you are in the loop, the Ethernet is not yet setup. You might want to try to add your hook after the Ethernet is setup. See below highlighted in red where hooks may be plugged. 

    i wait one minute according to the delay, what is this hook and which file should i define in and what is its purpose ?

  • I think you wan to call BL_HW_INIT_FN_HOOK function before you call CheckForceUpdate. In the BL_HW_INIT_FN_HOOK, you should also configure Ethernet. If you only put some wait statements inside BL_HW_INIT_FN_HOOK, then how would you prevent LM flash programmer from sending Ethernet packets to the MCU when the MCU Ethernet is not yet configured.