Author Topic: Adding uTasker_BM Bootloader to existing (non-uT) CW project  (Read 8176 times)

Offline fridgefreezer

  • Newbie
  • *
  • Posts: 7
    • View Profile
Hi all, this is my 1st post so please be gentle ;)
First off I must thank Mark for all his help on the Freescale forums, his posts have helped me sort out a lot of problems both of my own doing & some which are all Freescale's own  ::)

I have a large project on the MCF52259, all in C (using CW7.2) that I need to add a flash upgrade/bootloader routine to. Whilst looking round for info I found references to the uTasker "bare minimum" bootloader and it sounds almost perfect for what we need, with a few minor tweaks.

Our hardware is sat on an RS485 bus, which is how the firmware data will arrive (we already have routines to Rx & parse the .s19 data through the protocol we're using). We have an Atmel AT25DF081A SPI flash chip in it which we intend to read the data into before flashing the micro. I think the AT25 is compatible with the AT45 supported in the uTasker project.

The ideal situation is to end up with a single .s19 file which can be burnt to new boards which contains both bootloader & main app code.

I have registered & downloaded the latest uTasker project, and loaded uTaskerBootCW7.0.mcp into CodeWarrior. I've also read the two PDF's (http://www.utasker.com/docs/uTasker/BM-Booloader_for_M5223X.PDF & http://www.utasker.com/docs/uTasker/uTaskerBoot_003.PDF) but due to all the "extra" #defines and options in the code I'm having a bit of trouble understanding the basics of what I need to do to integrate this into an existing project - the main project is not using uTasker, and before anyone suggests it no we don't have time to port the entire project over! :P

My first steps have been to duplicate the bootloader project and then remove all the #defines which are not being used (EG for different processors) but that only gets me so far as the project links in a lot of files from the main uTasker project, which means a lot of stuff to look through to try and work out if we can remove them or not.

All we really need is a bootloader which starts up, checks for new data in the SPI Flash and then flashes the micro. Being able to fall back to a serial command line on some condition (EG spare pin held low) would be nice but not essential.

We do not want to use the uTaskerConvert.exe application if possible, as it would lead to extra work changing our legacy .s19-based RS485 uploader to support the different filetype.

So, the short version of all my rambling is:
- What can we strip out of the uTaskerBootCW7.0.mcp project to leave us with a bare-bones routine which only checks SPI Flash and either upgrades or continues to the main app?

- How do I build the uTaskerBoot project to give me code I can include in my main project without using uTaskerConvert.exe?

- How do I modify my existing project to include the compiled uTaskerBoot code? I understand modifying the start address in the project_FLASH.lcf as per the PDF:
[flash (RX) : ORIGIN = 0x0001000, LENGTH = 0x0003F000]
Is there some way to automatically include & place the bootloader code before the main app?

Apologies for the rambling newbie questions, I've come into the embedded programming lark sideways so there are some big blind-spots in my knowledge  :-\

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3237
    • View Profile
    • uTasker
Re: Adding uTasker_BM Bootloader to existing (non-uT) CW project
« Reply #1 on: May 03, 2011, 10:26:23 PM »
Hi

1) I think that you will need the project uTaskerBoot (the bare-minium one). This is in fact only about four files
uTaskerBootLoader.c
M5223X_boot.c
mcf5223X_boot.s

flash_config.s (or flash_config_sec.s if the FLASH is to be protected - but to be used extremely carefully...)

Otherwise it doesn't contain anything from the OS etc. (just the Flash drivers really). You can strip out some defines for other processors but it is not really necessary. The project define _M5223X ensures that only the relevant parts for this processor are used.

This is completely independent of the code that will run as application (the application just needs to be linked to the correct address and not try to use interrupt vectors of its own from SRAM).

Note that the "Bare-minimum" loader doesn't need to be integrated into any other projects.

2) When you copy the data to SPI Flash you need to save it to the correct location and ensure that it has a small header (used to verify its length and checksum etc.). As long as this is correct (you can calculate and save it as part of your storage function) you don't need to use any conversion programs. uTaskerConvert.exe will add a suitable header to a binary file, but is not necessarily appropriate if you are transfering as SREC.

3) There are several method to generate an SREC with boot loader and application in one file:
- load boot loader and application seperately (eg using CW7.x as described in the M522XX boot loader document) to the board: Now read back the content and store as a single REC (or binary) file, which now includes the complete contents.
- Use a convertion utility to combine the two files. There are a lots of free utilities of working with SREC file on the Internet. The uTasker utilities can also do such things but I think that it only supports saving as .ihex format (due to this requirement in the NXP projects).

4) The serial loader project can be used as stand-alone or back-up solution. Again it doesn't need to be integrated into any project since it is a complete stand-alone project - it just needs to be configured to know which address the application starts on and how big the largest applicatin can be (or is allowed to be). I would look at http://www.utasker.com/docs/uTasker/uTaskerSecureSREC.pdf to get an idea of the possibility of working with the bare-minumum boot loader and a secondary boot loader (this allows maximum flexibility) but is probably not really needed according to your requirements (I still think that you can load the bare-minimum loader, combined with your existing project [linked at the correct offset or course] and you are in fact already more or less finished.


To be sure that the specific question have been answered:

Quote
- What can we strip out of the uTaskerBootCW7.0.mcp project to leave us with a bare-bones routine which only checks SPI Flash and either upgrades or continues to the main app?

The boot-loader project is already stripped to a minimum so there is nothing that can be removed (or needs to be removed). It will be less that 2k in size when working with only the FLASH memory driver or a bit larger than 2k when working with SPI Flash since it then needs both FLASH and SPI Flash drivers at the same time.

Quote
- How do I build the uTaskerBoot project to give me code I can include in my main project without using uTaskerConvert.exe?

The code can be combined with your application (using CW7, simply download the project to your board and then download you application and that was it). uTaskerConvert.exe has nothing to do with the boot loader - it is only used to prepare a new application that is then suitable for downloading as binary (usually via USB or Ethernet).

Quote
- How do I modify my existing project to include the compiled uTaskerBoot code? I understand modifying the start address in the project_FLASH.lcf as per the PDF:
[flash (RX) : ORIGIN = 0x0001000, LENGTH = 0x0003F000]
Is there some way to automatically include & place the bootloader code before the main app?

There is no need to include the code in youir project. The shift in the reset vector is correct in your application so that it follows the boot loader in physical FLASH at the correct location (it must start at a new FLASH SECTOR boundary and can not be contiguous to it in memory - otherwise the boot loader would delete itself when deleting the start of the application area). Simply download the two projects one after the other from CW7 when developing and then use an SREC combining utility to make a single SREC containing the two images for the factory later.

Good luck

Regards

Mark


Offline fridgefreezer

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: Adding uTasker_BM Bootloader to existing (non-uT) CW project
« Reply #2 on: May 10, 2011, 07:22:46 PM »
Thanks Mark!  :)