How to Compile and boot MQX and where to write a boot loader

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to Compile and boot MQX and where to write a boot loader

Jump to solution
13,100 Views
CarlFST60L
Senior Contributor II

 

We need to be able to compile and boot an 'image' of MQX from a bootloader. We will be periodically uploading new MQX images as updates become available (either from MQX, or our own updates). When I say MQX Image, I mean MQX RToS with our application code which can be booted from some bootloader...

 

We cannot find complete information in the user guide which covers any requirments to be able to perform any boot loader functions, not even memory control or details on how MQX boots, memory control of code sections or the organisation and building blocks of MQX...

 

Please assist us buy supplying some essential information about the operating system:

 

- Where do we write the C function for a bootloader exactly (pre MQX running)? This code really needs to be able to be seperated from the rest of the MQX image to allow it to update the MQX image without overwriting itself (see memory diagram below).

 

- How are the memory locations controlled for the above (How do we fix the location of the bootloader software and MQX application image)?

 

- How do we actually boot to the address of this MQX image we have created?

 

- Is there any other memory requirments we must meet to allow MQX to boot properly, or, to get our firware to enter and exit properly?

 

Here is how the I think the memory map might look...

 

---------------------------

- START BOOTLOADER address of where reset vector points, this part of code is fixed in firmware

 

Pre MQX - pre MQX/C setup requiments..

USER Mem - boot loader function which updates MQX Image in the other flash blocks (flash routines etc here)

Pre MQX - pre MQX image boot, this might be a bit of both user code and MQX code, no idea...

Pre MQX - MQX image boot function, might clean memory / allocate memory and actually jumps to MQX image

 

- END BOOTLOADER

---------------------------

- START MQX + USER APPLICATION MQX Image which will be updated

 

MQX RToS + Application Code as normal

 

- END MQX + USER APPLICATION

---------------------------


 

 

Message Edited by CarlFST60L on 2009-03-22 10:49 PM
0 Kudos
Reply
1 Solution
2,255 Views
jart
Contributor II

Hi,

 

I have attached a new version of my bootloader. In this version I have moved the bootloader to the first page of flash. This solves the problem I described at the end of my last post. Also to use this version you do not need to modify the file vectors.cw. If you did change the vectors.cw file you can change it back. You must still replace the file intflash_usb.lcf with the contents of lcf.txt as described above.

 

upgrade3_forum_zip.zip

Message Edited by t.dowe on 2009-08-27 02:40 PM

View solution in original post

0 Kudos
Reply
24 Replies
2,006 Views
kleckerspur
Contributor III

Cant dowload the file !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

0 Kudos
Reply
2,006 Views
EdProulx
Contributor I

Hi,

 

I think I understand what you were trying to do. My requirement, and hence issue:

 

- I need to be able to load an application that is independent of the bootloader as an independent project of C.W.

- the application will loaded into flash at a specific address

- the bootloader will know where this address is located, and upon reset, simply jump to the application's entry point

 

I am very new to Freescale and C.w., I am trying to get a better undestanding of the "xxx.lcf" link control file and how the control statements in the .lcf file work, and what they mean. I also cannot (or have not) find a "use guide description" of the linker control file.

 

Any guideline to information would be greatly appreciated.

 

Ed

 

--------------------------------------

 

(if you want to know why I want to do this: I will want to have the running applciation be able to download a 2nd application image to a different section of flash while it is running, then update a table in the bootloader, and when the commit is complete, upon the next system reset, the bootloader will jump to the new application entry point)

 

0 Kudos
Reply
2,006 Views
CarlFST60L
Senior Contributor II

I agree that the documentation on how to setup MQX to boot along with the linker is not suffecient for 'easy' boot loader application development. I made a note of this in the MQX Feedback thread.

 

Hopefully the next version will include a boot loader and some example on a basic serial boot loader along with details about how to manage MQX memory locations with the LCF

Message Edited by CarlFST60L on 2009-07-28 02:37 AM
0 Kudos
Reply
2,006 Views
butok
NXP Employee
NXP Employee

FYI:

You may look at the FNET TFTP Bootloader (available for K2, K3, Lasko and Reindeer Coldfire),
that is part of the FNET project: http://fnet.sourceforge.net/

 

Just look at FNET Bootloader related chapters:
 - FNET Bootloader Quick Start:

   http://fnet.sourceforge.net/manual/quick_start_boot.html
 - Add FNET Bootloader support to an existing project:

   http://fnet.sourceforge.net/manual/how_to_add_boot.html

 

As I know, some customers are going to use it in its own real MQX-based projects.

 

Best regards,
Andrey Butok

0 Kudos
Reply
2,006 Views
CarlFST60L
Senior Contributor II

Thanks for that link, I will check it out.

 

We have written a managed firmware updater along with a simple PC program to download and mange the firware update (either via serial or a UDP connection). We have managed to setup 2 MQX images so we can roll back in the event of some failure along with a smart boot loader that can check images for boot records etc

 

 

0 Kudos
Reply
2,006 Views
jart
Contributor II

Hi,


I have attached my bootloader project. It can update the firmware of the M52259EVB board with a new S19 file from a USB memory stick.

To use the program you must change two file. Firstly replace the file vectors.cw (in Freescale MQX 3.0\mqx\source\bsp\m52259evb) with the one provided in the zip. You should keep a copy of the original as the new one will only work with projects that include the bootloader. You must then recompile the mqx. Secondly, open the upgrade2.mcp project in codewarrior and replace the content of the file intflash_usb.lcf with lcf.txt from the project folder.

Then compile the project and flash it to the chip. Rename the S19 that you want the bootloader to use to “FIRMWARE.S19” and place it in the root of a memory stick. Plug the memory stick into the EVB board and the upgrade will begin. Progress can be monitored on UART0 at 115200 baud.

The project works by splitting the flash up into three segments. The first segment is 252 kB in size and holds the main program. The second is also 252 kB and is used to store the new firmware temporarily before it flash into the first segment. The last is 8 kB and contains the bootloader program.
 
When the program starts up it jumps to the bootloader code which checks if there is new firmware in the second segment of flash. If there is it copy the code from the second segment to the first then erases the second segment. It will then reset the MCU. If the bootloader does not find new firmware it will exit and the mqx will start up.

The mqx program will look for a S19 file called “FIRMWARE.S19” on the USB stick. If it is found it will decode the file and write it to the second segment of flash.

The main problem with this method is that if something goes wrong and the very first page of flash is not written correctly the MCU will not start up after the next reset. To minimise the amount if time the system is at risk my bootloader erase the first page of flash and reprograms it separately. A better solution would be to put the bootloader in the first page of flash so it never has to be erased. But this mean moving the mqx and having a specified start address for the mqx. It would be very useful is this functionality was built into the mqx.

Message Edited by jart on 2009-03-27 02:37 PM
Message Edited by t.dowe on 2009-08-27 02:03 PM
0 Kudos
Reply
2,256 Views
jart
Contributor II

Hi,

 

I have attached a new version of my bootloader. In this version I have moved the bootloader to the first page of flash. This solves the problem I described at the end of my last post. Also to use this version you do not need to modify the file vectors.cw. If you did change the vectors.cw file you can change it back. You must still replace the file intflash_usb.lcf with the contents of lcf.txt as described above.

 

upgrade3_forum_zip.zip

Message Edited by t.dowe on 2009-08-27 02:40 PM
0 Kudos
Reply
2,006 Views
Rpalenci
Contributor II

Hi,

 

I am very interesting in see your project about bootloader in MQX but your file attached is not  working.

Would be it possible  correct this link for can see the project?

 

Best regards and thanks a lot. 

0 Kudos
Reply
2,006 Views
rbuti
Contributor I

Hi,

the file posted by "Jart" is not anymore downloadble, could anyone post it again ?

 

regards

  Roberto

Message Edited by rbuti on 2009-09-07 03:10 PM
0 Kudos
Reply
2,006 Views
MQXuser
Contributor III

Has anyone used the FNET project?

 

I have used the loader a few times but now I want to directly program an application using the programer.
I am able to program the application but when I try to debugg it, an Exception vector name: Address Error appears. What could be the change the loader made to my microcontroller?

Another thing is that I am able to load an application using the loader but the application is not working properly, ethernet and usb are not working. My status led is flashing fine but I dont know where to start in order to make ethernet and USB work. Any ideas?

 

Thank you in advanced

0 Kudos
Reply
2,006 Views
admin
Specialist II

Hello, I have just downloaded the FNET project from http://fnet.sourceforge.net/ and started testing  the FNET Shell Demo over the TWR - MCF52259 development kit. It works just fine, I can use execute the basic shell commands: set, get, info,.... from the Hyper Terminal Console.


But when y try to test the FNET Bootloader, I do exactly what the FNET Bootloader Quick Start says about to compile and download the project to the Internal Flash of the MCF52259. But when I run the program nothing happens in the Hyper Terminal Console of my computer.


The FNET Shell Demo is working well, meaning that the hyper terminal is also working well, but when I try the FNET Bootloader I don't see the FNET Bootloader welcome message in the console. 


Since It is a Bootloader, I don't know if I have to set an specific memory range where that program has to be downloaded to the internal flash.


Can anyone please give me some advice or help. I will really appreciate it.


Many thanks and my best regards.

 


0 Kudos
Reply
2,006 Views
DavidS
NXP Employee
NXP Employee

Hi Alejandro,

Please look at the FNET/fnet_doc/fnet_user_manual.chm -> FNET How-To->"Add FNET Bootloader support to existing project"

Your application code should start at 0xC000. 

Hopefully this will help.

Regards,

David

0 Kudos
Reply
2,006 Views
admin
Specialist II

Hello David. Tank you so much for you quick anwer.

 

I have read the Add FNET Bootloader support to an existing project document and I have some questions.

 

 

1. What exactly do I have to do to test the FNET Bootloader for the TWR - MCF52259 development kit and see the FNET Bootloader welcome message in my terminal program window just like FNET Bootloader Quick Start document shows?

 

Parameters loaded.************************************************ FNET Bootloader************************************************ FNET TCP/IP Stack for MCF5225X Version 0.9.0 Built Feb  1 2011 at 15:52:42 by IAR Copyright 2005-2011 by Freescale Semiconductor GNU LGPLv3************************************************ Interface        : eth0 IP address       : 192.168.1.22 (set manually) Subnet mask      : 255.255.254.0 Gateway          : 10.171.88.254 MAC address      : 00:04:9F:15:52:55 Link status      : unconnected TX Packets       : 4 RX Packets       : 0 DHCP client      : disabled TFTP server      : disabled Enter 'help' for command list.************************************************Startup script: tftps************************************************  TFTP server (192.168.1.22) started.************************************************BOOT>

I don't see this in my terminal program window after following the step by step FNET Bootloader Quick Start document. What could I be missing?

 

Do I have to change any configuration for the Flash Memory of the MCF52259 (linker file, CW7.2 compiler or Flash Programmer address range) to make the FNET Bootloader Quick Start demo work?


In relation with the Addind the FNET Bootloader support to existing project documentation.


Do I have to change the sections of the linker command file of the project  twrmcf52259_boot.mcp or I have to Flash the program twrmcf52259_boot.mcp to the board like the FNET Bootloader Quick Start document says and then Flash any application with sections of its linker command file being changed?

 

I am confused. Please can you explain me how to do the things right?

 

I know that FNET twrmcf52259_boot.mcp project is a bootloader, but how to make it work?

 

Thank you very much.

 

0 Kudos
Reply
2,006 Views
butok
NXP Employee
NXP Employee

Hi Alejandro,

 

As I see you still have some issues.

You can look at the NOT-official AN "Adding an Ethernet Bootloader to Freescale MQX", you can find it here:
https://sourceforge.net/projects/fnet/files/fnet/AN/

 

Best regards,

Andrey Butok

0 Kudos
Reply
2,006 Views
admin
Specialist II

Hello Butok.

I finally made the FNET Bootloader work perfectlly over the TWR MCF52259 Development Kit.

My problem was the same as seen in http://freescale.lithium.com/t5/68K-ColdFire-reg-Microprocessors/FNET-on-TWR-MCF5225x-Which-Serial-P... post: "FNET on TWR-MCF522​5x: Which Serial Port is routed to the DB9 connector?"

I have made my MQX application work with the FNET Bootloader too by following the "Adding an Ethernet Bootloader to Freescale MQX™" documentation. Everything is just working perfectly.

Now that I can use the FNET Bootloader to dowload any application or update firmware if were neccessary via TFTP. I have some questions.

1. How to automate the Update Firmware Proccess of an MQX application? (All made by the machine, only first configuration will be made by humans).

Lets suppose that we have a TFTP Server which will store the new MQX Application firmware. Since we don't know in which LAN network will the system be connected, the TFTP server IP address can be variable. Therefore it is not possible to have a default TFTP server Address for the FNET Bootloader. Then we need to first configure the system with the actual TFTP server Address by hand. As I can see It can be done with set and save commands.

After check if there is a new version of the firmware and if neccessary execute the firmware update proccess, the FNET Bootloader will start the MQX application. So far, so understood.

 

But at this time, the MQX application has been started. Then, it is the MQX application responsibility to know if there is a new version of the firmware (Issuing a simple TFTP file name check and version comparison) every period of time.

 

Once the MQX application knows there is a new version of the firmware, How can I make FNET Bootloader know that?.

 

I know that all parameters used by the FNET bootloader are stored in the upper block of Flash and are recalled after a power cycle or reset (If the Bootloader is in automatic booting mode).

 

Is it possible to modify some of these parameters (IP, netmask, gateway, TFTP IP address, script, image, etcetera...) from the MQX application, then apply a system reset to start the automatic firmware update execution?

 

Is this way the best to do an automatic firmware update?

Is there another automatic firmware update proccess already available?

 

An my last Question.

 

1. If there was a problem during the firmware update and the MQX application was not well flashed. Is the FNET bootloader able to know that?

How to know if there is a flashed data corruption and it is necessary to restart the firmware update proccess instead of starting the MQX application?

¿Is it possible to have a backup of the last working well firmware in case of a firmware update proccess crash?

 

Is  a firmware update proccess crash possible to happen, resulting in flashed data corruption?

 

 

Thanks a lot and my best regars.

 

 

0 Kudos
Reply
2,006 Views
butok
NXP Employee
NXP Employee


 

Hi Alejandro
>>1. How to automate the Update Firmware Proccess of an MQX application?

It is responsibility of the application or user to know if there is a new version of the firmware.
The application can control behavior and settings of the FNET boot-loader by changing its parameters (in the last sector of on-chip flash).
>> Is there another automatic firmware update proccess already available?

It is fully up to you. The FNET boot-loader is starting point, and you may modify it as you want.
>> If there was a problem during the firmware update and the 
>>MQX application was not well flashed. Is the FNET bootloader able to know that?

If you load SREC file, the boot-loader check the checksum for each SREC line.
Also during writing to the flash it do verification if data were written.
Also you may add your application-specific checks.
If something goes wrong => the boot-loader stays in the Shell and waiting for user actions.
User can do reset => and the boot-loader starts from beginning, or he/she can change some parameters etc.
>>Is it possible to have a backup of the last working well 
>>firmware in case of a firmware update proccess crash?

The boot-loader has this feature and you may backup current firmware.
But you should do it before flashing new one.

Thanks,
Andrey Butok

 


0 Kudos
Reply
2,006 Views
admin
Specialist II

Hello. Thank you guys for your answers. That will really help me to develop the Automatic Firmware Update

System on my MQX Application.

 

I suppose that I will have to read/write data between 0x0007F000 and 0x00080000 memory addresses (where FNET

Parameters live) to control the behavior and settings of the FNET boot-loader, all from the MQX Application.

 

Since I am using MQX as platform to develop the entire application, and it only shows MFS stack to manage files,

How to read/write data at a specific given flash memory address of the microcontroller?.

 

I supose there must be a function like writeBytesToIntFlashMemory(long MemAddressDest, char * BuffSource, int

SizeOfBuffSource) to write data into Flash Memory of the microcontroller. I found some source at the

https://community.freescale.com/message/60963#60963

Freescale forum but it seems that I need to integrate the complete uTasker FileSystem to have the

fnWriteBytesFlash function working on my application.

 

Does MQX already have low level writing/reading internal flash functions that I can use? If so, where can I find

them?

Is there any other alternative?

 

I actually only need that to integrate the Automatic Bootloader System to my application and be completely

happy.

 

Where can I find more information about the FNET Bootloader feature of backuping current firmware before

flashing new one that you mentioned?

 

Thank you a lot. Best Regards.

0 Kudos
Reply
2,006 Views
butok
NXP Employee
NXP Employee

 

Hi Alejandro,
>>Where can I find more information about the FNET Bootloader feature of 
>>backuping current firmware before flashing new one that you mentioned?

Try to find words  “backup”:
1)
“NOTE: The tftpup command is useful for the firmware backup before it gets overwritten in the Flash memory. This feature enables to restore the system in case the new firmware has issues. 
This command uploads content of the on-chip Flash memory, except FNET Bootloader reserved blocks, to the TFTP server. The TFTP server IP address is defined by the tftp parameter. The image-file name on the remote TFTP server is defined by the image parameter. Format of the created file (S-record, CodeWarrior binary or raw binary) is defined by type parameter.”
2) At the end of the page:
“Also you may backup the firmware. The TFTP firmware server can upload content of the on-chip Flash memory, except FNET Bootloader reserved blocks, to a TFTP client …”
>>How to read/write data at a specific given flash memory address of the microcontroller?.

I cannot suggest you how to do it using MQX drivers.
But you can reuse FNET CFM library:
fnet_cfm.c
fnet_cfm.h
FNET boot-loader parameters layout structure(s) you can find in fapp_params.h and functions in fapp_params.c.
 BTW:FNET is open-source project, and contribution is very welcome.
Best regards,
Andrey

 

 

0 Kudos
Reply
2,006 Views
admin
Specialist II

Hello Butok, and all the Freescale team.

 

Thank you very much for your help. I finally can controll de behavior of the FNET Bootloader by writing/reading the Flash Memory Location where the FNET Parameters are (0X0007F000 - 0X00080000). I am using the Flashx feature for MQX to read/write/erase any byte at any place you want of the Flash memory.

 

Here some links to use Flashx.

 

https://community.freescale.com/message/57359#57359

 

https://community.freescale.com/thread/62398

 

https://community.freescale.com/message/80014#80014

 

 

Now, what I have to do is to make the application know when It is neccessary to update the firmware in an automatic way.

 

Since a TFTP server will be used as the place where firmware versions of the application will be stored then I need to:

 

1.- Connect to the TFTP server form the MQX Application every period of time (open socket and start TFTP protocol).

2.- List the existing firmware files (start retrieving all existing files in TFTP Server). 

3.- Determine if there is a new version of the firmware (file name string manipulation and comparison (v1.3 > v1.2)).

4.- Verify if the firmware uopdate file is OK.

5.- Execute the Firmware Update Proccess if neccessary.

 

Is there any way to connect to the TFTP server and list the existing files (step 1,2) with MQX Libraries. I know there is a TFTP library but I cannot find any example to do what I need.

 

I have seen that actually I need the name of the file in order to download the file. But I have not found any algorithm to list all the existing files in the TFTP Server. Is there any way to do this?

 

Any advice or help will be really appreciated. thank you very much.

 

 

0 Kudos
Reply
2,006 Views
Mohsin455
Contributor IV

Hi  Alejandro,               

 

                             I am also trying to modify the FNET parameters from MQX application. If possible can you please share your code or provide some help ?

 

Thanks,

Mohsin

0 Kudos
Reply