Git Product home page Git Product logo

vscp-bootloader's Introduction

VSCP L1 Bootloader

License Repo Status Release

A generic VSCP L1 bootloader, which supports the standard bootloader algorithm. It provides the possibility to program a new firmware image to a VSCP node.

VSCP

Logo

The Very Simple Control Protocol (VSCP), an open and free protocol for IoT/m2m automation tasks.

More information can be found on the main site http://www.vscp.org

VSCP Standard Bootloader Algorithm

VSCP standard bootloader algorithm

Description

The bootloader algorithm follows the standard VSCP bootloader algorithm. The following description contains more details about how it proceeds.

  1. Determine whether a) the user force bootloader mode, b) an valid application is present and shall be started, c) the application jumped to the bootloader, d) no application is present.

  2. Conditions for case a):

    • If the segment initialization button is pressed during power-up, stay in the bootloader. Go to step 6.
  3. Conditions for case b):

    • The segment initialization button is released.
    • The boot flag in the persistent memory shall contain 0xAA for destination application. If all conditions met, jump to the application otherwise go to step 6.
  4. Conditions for case c):

    • The hardware jumper is not set.
    • The boot flag in the persistent memory shall contain 0xBB for destination bootloader. If all conditions met, go to step 9.
  5. Conditions for case d):

    • The segment initialization button is released.
    • The boot flag in the persistent memory shall contain anything else than 0xAA and 0xBB. If all conditions met, go to step 6.
  6. Send a "new node online/probe" event, so that the programming tool knows the node is available now. Node id 0xFE is used!

  7. If any "ACK probe" event is received, the node shall go to sleep mode, because the nickname is already used.

  8. Wait (infinite) for the "enter bootloader" event. Only if the received nickname and GUID are equal to the internal ones of the node, validate the proposed programming algorithm. If the algorithm is supported, continue with next step, otherwise a "NACK enter bootloader" event will be sent.

  9. Because the application already received the "enter bootloader" event and validated its parameters, a "ACK enter bootloader" event shall be sent back now in the bootloader. Send the flash block size (= flash page size) and the number of blocks as parameters.

  10. Wait (infinite) for the "start block data transfer" event. If the proposed memory type is correct acknowledge it via "ACK start block data transfer" event otherwise via "NACK start block data transfer" event.

  11. Now several "block data" events will be received, until the complete block is transfered. Every received block data shall be written to RAM buffer. After the last data is transfered, a CRC16-CCITT shall be calculated over the whole block. And an "ACK block data" event shall be sent with the calculated CRC as parameter.

  12. If a complete block is received, wait for a "program block" event. This is the trigger to delete a flash page and write the block RAM buffer to the flash page. If the block is successful written, send an "ACK program block" event to confirm it. Otherwise send an "NAK program block" event. Note that before writing the first block to flash, write 0xFF to boot flag in the persistent memory. This shall be done here, because after this, there is no way back.

  13. The next block shall be handled (go to step 10), except an "drop nickname/reset device" event is received. In this case the block programming operation shall be stopped.

  14. Validate the application in the flash. If the application is valid, a "ACK activate new image" event shall be sent, the boot flag in the persistent memory shall be set to 0xAA and reboot the node. Otherwise "NAK activate new image" event shall be sent and the node shall go to sleep.

Notes:

  • Unused bytes in a flash block shall be 0xFF.
  • The host shall send always an image in the size of the whole application section.
  • Because the AVR has flash pages, but the VSCP has blocks, both are considered as equal.
  • If the programming procedure is aborted by "drop nickname/reset device" event the node reboots.

Error codes:

  • 0 - Programming algorithm not supported
  • 1 - Memory type not supported
  • 2 - Bad block number
  • 3 - Invalid message

Facts

  • The bootloader supports only programming the program space right now.
  • The bootloader can only handle complete blocks. If the last block is not completly received from a programmer, the bootloader will infinite wait for the rest! In other words, the size of the new application shall be always a multiple of the block size.

FAQ

How to integrate it?

Include the following files to your project:

  • /src/crc16ccitt.h
  • /src/crc16ccitt.c
  • /src/vscp_bootloader.h
  • /src/vscp_bootloader.c

Additional include the following files to your project from the vscp-framework:

  • /src/vscp_class_l1.h
  • /src/vscp_types.h
  • /src/vscp_type_protocol.h

Copy the templates to your project and adapt them to your needs:

  • /templates/vscp_bl_adapter.h
  • /templates/vscp_bl_adapter.c
  • /templates/vscp_platform.h
  • /templates/vscp_tp\adapter.h
  • /templates/vscp_tp\adapter.c

Call in your main routine the

  • vscp_bootloader_init() and
  • vscp_bootloader_run()

Note that the vscp_bootloader_run() will never return!

How can a application be programmed via bootloader?

Why does the node sends a new node online event with 0xFE?

If the bootloader starts, it try to figure out whether a valid application is programmed or not. In this case it seems there is no valid application and therefore most probably an invalid persistent memory. Now the bootloader simulates a new node with nickname 0xFE, so that you are able to program a new application via programmer.

If you think the application should be valid, because you programmed it just a minute ago via debugger ... can it be that you forgot to program a valid persistent memory? ;-)

Issues, Ideas And Bugs

If you have further ideas or you found some bugs, great! Create a issue or if you are able and willing to fix it by yourself, clone the repository and create a pull request.

License

The whole source code is published under the MIT license.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, shall be licensed as above, without any additional terms or conditions.

vscp-bootloader's People

Contributors

blueandi avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.