Kinetis Boot Loader for SREC UART, SD Card and USB-MSD loading

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

Kinetis Boot Loader for SREC UART, SD Card and USB-MSD loading

27,534 Views
mjbcswitzerland
Specialist V

Hi All

There has always been a high demand for boot loader solutions and the uTasker project includes a number of these which have proven to be quite popular, even for use with applications from different sources.

The demands as to how the loader operates are quite varied and so a flexible loader has been put together which allows the following modes of boot loader operation in one single loader:

- UART S-REC loading at 115200 Baud

- SD Card loading (a new software is copied to an SD card and inserted)

- USB-MSD (the board apears as a disk drive and the software can be copied)

This allows all of the three possibilites to be used in a compatible manner. The boot loader size (with all modes enabled together) is about 25k. If some modes are not required they can be mixed as necessary in the project and so much smaller Flash size needed.

For K60 Tower Kit users there is a package at µTasker Test Software and Demos which allows it to be used immediately for any application up to 130k in size. The loader is documented at http://www.utasker.com/docs/uTasker/uTaskerSerialLoader.PDF and there is also a video showing its flexible operation at Kinetis K60 Tower Kit - Flexible Boot Loader - YouTube

Note that the complete package also supports encryption (to allow code distribution without reverse enginering possibility), USB-DFU, HS-USB and Ethernet loader (Web Server based - about 18k Flash) for chips with Ethernet.

Regards

Mark

Labels (2)
148 Replies

921 Views
luishs
Senior Contributor I

Ok, fine, thank you very much Mark.


Kind Regards

0 Kudos

921 Views
mjbcswitzerland
Specialist V

Hi All

I have been asked to make a demonstration video of configuring and using the Ethernet Web Browser loader.
This can now be found at https://youtu.be/g71PGlQy6eI

Regards

Mark

921 Views
laibarashid
Contributor I

Hi Mark

I have build the bootloader with eth_interface enabled , at first when i

browsed the IP address , the corresponding yellow page appeared and i

successfully loaded the application on board , then i disconnected the

board and tried the same process later, the browser is giving an error

message IP is taking too long to respond.

The first time it went successful and now i don't know why my browser is

not loading the yellow page.

Please help me solve the issue.

Regards

0 Kudos

921 Views
mjbcswitzerland
Specialist V

Hi

Do you correctly re-enter the Ethernet loader when trying to connect to the board? (Force the loader mode by holding down the switch).

If the loader is operating again it will respond to pings and web browser connection requests as before since the same code runs, whether the application part of flash is programmed or not.

You could also do a flash erase with the debugger, program the loader again and verify correct operation as the first time, thus excluding possible network problems that may have started later.

Regards

Mark

P.S. Which board/processor is being used? Try also a power cycle rather that a reset to see whether there is a difference.

0 Kudos

921 Views
laibarashid
Contributor I

Thanks for the help Mark. Can you please also explain to me how i can use

iPv6 instead of iPv4.

Waiting for your reply.

Regards

0 Kudos

921 Views
mjbcswitzerland
Specialist V

Hi

To work also with IPv6 you just need to enable the define

    #define USE_IPV6                                                     // enable IPv6
in config.h.
You can optionally also use IPv6 in IPv4 tunneling
with
    #define USE_IPV6INV4                                             // support tunneling IPv6 ind IPv4

The device will respond on its link-local address (depends on its MAC address) and on a global IPv6 address defined in webInterface.c by

{ _IP6_ADD_DIGIT(0x2001), _IP6_ADD_DIGIT(0x0470), _IP6_ADD_DIGIT(0x0026), _IP6_ADD_DIGIT(0x0105), _IP6_ADD_DIGIT(0x0000), _IP6_ADD_DIGIT(0x0000), _IP6_ADD_DIGIT(0x0000), _IP6_ADD_DIGIT(0x0030) }, // default global IPv6 address


You can get IPv6 information from the IPv6 user's guide at http://www.utasker.com/docs/uTasker/uTaskerIPV6.PDF
plus some general practical IPv6 information from the video https://www.youtube.com/watch?v=BMPXhtoUeJo&feature=youtu.be

uTasker services (like web server) and applications are compatible with both IPv4 and IPv6 so nothing else needs to be changed.

Regards

Mark

0 Kudos

921 Views
laibarashid
Contributor I

Mark, i have enabled IPv6 and using by browser , i have searched the IPv6

address[2001:470:26:105::30] as in webinterface.c file, just like i search

IPv4 address 192.168.0.125, but it does load giving the message This site

can’t be reached

took too long to respond.

Am i missing something? How can i solve this issue?

On Fri, Aug 11, 2017 at 8:55 PM, mjbcswitzerland <admin@community.nxp.com>

0 Kudos

921 Views
mjbcswitzerland
Specialist V

Hi

Try pinging the link-local address (assuming MAC address is still 00-00-00-00-00-05) with
ping fe80::200:ff:fe00:5
and connecting via browser using the address
http://[fe80::200:ff:fe00:5]/

I just checked this and it was OK.

I couldn't test the global address because my Windows 10 PC errors it without even trying to connect (and does the same for any other global address tried).

Regards

Mark

0 Kudos

921 Views
luishs
Senior Contributor I

Hello Mark.

Some questions please:

1.- My board install a MK66FX1M0VLQ18, so 1Mb flash instead of 2Mb. Then I must type linker script K_1M_256.ld ??
2.- If my SD card socket do not has CARD DETECT switch, how may I config project to force always to start boot mode to check if there is a SD card present and with file to update flash memory ?.
3.- What is the file name for the file in SD card to update flash memory, may config that file name ?

4.- This bootloader support encrypted files, for example XTEA ?.
      if do not support may you tell me what is the source code to may I add my own decrypt XTEA routine ?
      If support encryption, provide the software tool to encrypt the HEX or BIN file ??

Kind Regards and thank you.

0 Kudos

921 Views
mjbcswitzerland
Specialist V

Hi Luis

1. K_1M_256.ld is the correct liker script file for this device. However, since the loader only uses a few kBytes any Flash size will work.

2. To always start the loader just set
#define FORCE_BOOT()    1
Set also
#define RETAIN_LOADER_MODE() 0

so that it jumps to the application after checking the card.

3. The default is
#define NEW_SOFTWARE_FILE            "software.bin"
and can be changed as required.
If WILDCARD_FILES is enabled also wildcard matches are possible (eg. software?.bin would recognise software1.bin, software2.bin etc. or softwaer*.bin would recognise software234.bin, software345.bin etc.)
The details and how to set the options are described in chapter 12 of http://www.utasker.com/docs/uTasker/uTaskerSerialLoader.PDF

4. Encryption is enabled with ENCRYPTED_CARD_CONTENT
All details are also in the same chapter of the document.
If you need different encryption methods you can change the source in the function fnUpdateSoftware() in disk_loader.c to suit.
If you build and test the project with Visual Studio and run the loader in the simulator you can then test the details much easier and faster than on the HW and test the new code with an encrypted file content.

Regards

Mark

921 Views
luishs
Senior Contributor I

Ok, thank you very much Mark, very useful your replies, thanks for so good support.

Do you think in the future your bootloader will may support Atmel Cortex M7, SAM S70, E70, V70 ?

Kind Regards.

0 Kudos

921 Views
mjbcswitzerland
Specialist V

Luis

Older versions (with less features) have been used on AVR32, ATMEL SAM7, STR9x, Luminary Micro (M3), STM32 (M3/M4/M7), Coldfire V2s, LPC2xxx and LPC17xx families. However I am concentrating on Kinetis parts nowadays (and, apart from STM32, the others are now legacy) so doubt that the devices that you mention will be supported unless someone specifically wants to port (it only needs the HAL layer for the chip's peripherals, which is not that complicated to do).

Regards

Mark

921 Views
luishs
Senior Contributor I

OK, I understand, thanks Mark.

About HAL, do you mean all source code in Hardware folder library ?, I may try to port it to Atmel SAM S70, I'm very interested in Cortex M7, Atmel SAM are cheaper and easier to found than Kinetis, though currently I work with the three ARM family, STM32, NXP Kinetis and Atmel SAM S70.

I see also that you library support Teensy 3.6, and my custom board is working with same MK66 Kinetis though in LQFP socket instead of BGA. What is main difference, if some, between select Teensy 3.6 or FRDM-66F in your library ?

Kind Regards

0 Kudos

921 Views
mjbcswitzerland
Specialist V


Luis

>>About HAL, do you mean all source code in Hardware folder library ?
Yes, the rest of the code is almost 100% HW independent so by changing the drivers in the hardware folder other chips can be used.

>>What is main difference, if some, between select Teensy 3.6 or FRDM-66F in your library
The Teensy 3.6 connects the FS USB and not the HS USB in its HW so the UDB interface is switched. The Teensy 3.6 has a 16MHz crystal (as opposed to the FRDM-K66F's 12MHz crystal). Also it uses a K66FX1M0 rather than K66FN2M.

If you search the project for "FRDM_K66F" and "TEENSY_3_6" you will see the differences in the code - there are really only a few config differences. You can also do the same for "TEENSY_3_1" (which is very different at the HW level) or any of the other approx. 70 Kinetis boards that it supports 'out-of-the-box' to see that there are generally only a few lines of configuration difference between each.
The HW library adapts itself automatically (doesn't need a separate project and individual resources for each) which makes maintenance and generic further development very simple to do; plus, all chips are simulated so it is usually not necessary to debug on the HW, making project use many times easier and faster than developers are used to based on traditional methods. Finally it can be built with about 12 IDEs, meaning no restrictions and porting between favorite IDEs.
With about 50 combinations of loader types possible (most can be mixed), on about 70 standard boards (custom boards are simple to add), with 12 different IDEs, it gives about 40'000 possible combinations in a single project (this is for Kinetis - not mentioning possibly other processor families) - and with simple maintenance of the whole package.

Regards

Mark

921 Views
luishs
Senior Contributor I

Thanks Mark.

One question about the Linker Script. 
I see when use the uTasker bootloader, the user application must compile to run from address 0x00008080, so must modify the Linker Script.

I have look at the uTasker library and seem there are many linker script files ready to compile to start at flash address 0x00008080, I see many linker scripts in folders for GNU Kinetis, IAR7, GreenHills, Atollic, CodeWarrior and uVision.

I work currently with MK66 (custom board) with KDS and with Teensy 3.6 (same MK66). The question is if I must modify my own linker script in KDS and Teensy, or your library provide linker script files ready to use with KDS and Arduino/Teensy ?.

I understand that only need modify the start of flash to 0x00008080, though I have read in the forum something about interrupt vectors.

One more question, please. I have config to compile for Teensy 3.6, but when I compile there is this error:
Applications/uTaskerSerialBoot/disk_loader.c:385: undefined reference to `RETAIN_LOADER_MODE' collect2.exe: error: ld returned 1 exit status 

And previously this warning:
Applications/uTaskerSerialBoot/disk_loader.c:385:9: warning: implicit declaration of function 'RETAIN_LOADER_MODE' [-Wimplicit-function-declaration]


What is the problem when I tried to compile for Teensy 3.6 ?.

Kind Regards.

0 Kudos

921 Views
mjbcswitzerland
Specialist V

Luis

The linker script files are used by the uTasker projects (BM-loader, serial loader or application). If you build an application with different sources you can modify whichever linker script that is being used accordingly (use the K_2M_256_BM.ld as reference for the adjustments).
Beware that 0x8080 is used as standard for loaders including USB-MSD device loading but 0x8000 tends to be used when no USB-MSD is included (the 0x80 bytes in Flash are used to save a file object so the the name, date, etc. of the loaded firmware via USB-MSD is visible).
If the serial loader code is smaller than 32k (which is usually the case - 32k is needed only by loaders with many features) the application jump address (UTASKER_APP_START) - and the linker address - can be set lower in memory to save space.

See the appendix in the serial loader user's manual for a guide to configuring foreign applications, including a link to a guide specific for Arduino (as commonly used by Teensy users).


The Teensy 3.6 target is missing a definition for RETAIN_LOADER_MODE() [used by SD card loading]. This state is checked after the SD card has been searched for a file to load (or after failure to detect the SD card after a short time) and if TRUE it will remain in the loader mode rather than jumping to an available application.

You can add
    #define RETAIN_LOADER_MODE()   (_READ_PORT_MASK(C, SWITCH_1) == 0)   // pull this input down to force boot loader mode (connect pin pad 22 to GND at reset)
so that it checks the same input as used to force the loader operation - or you can define your own criteria.

Regards

Mark

921 Views
luishs
Senior Contributor I

Thanks Mark.

Im not sure yet to understand some details.

You say the address to jump to user application is defined in UTASKER_APP_START, I see this define is in Loader.h, and when I choose Teensy 3.6 or FRDM-K66F, this is:

            #define UTASKER_APP_START     (32 * 1024)                    // application starts at this address

so this is 32768, 0x8000 in hex. But this is calculated automatically or I may/must configure it ?.

With current source code I understand I must configure the Linker Script for my applications to start in address 0x8000, so different to address 0x8080 that put in forum for Teensy. Thats right ??


FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 256K
to
FLASH (rx) : ORIGIN = 0x00008080, LENGTH = 256K 

I do not understand what is exactly the utility of RETAIN_LOADER_MODE. You say if it's TRUE, will force to keep in boot mode instead of to jump to user application, after the SD card has been searched for a file to load or after failure to detect the SD card after a short time. In the example you have put, seem this is configure to enter in boot mode if push and hold a switch in board, so I understand that with that example boot mode only will run if push that switch or if no user application present, and if user application present and do not push the switch, always will jump to user application.

How I must config the #define RETAIN_LOADER_MODE ? if I want that bootloader always check, when start, that SD card is present and with file to update firmware ?. I do not want enter in boot mode with a switch, I want that bootloader, when start, always check SD card and new firmware to update it, if present in SD card.

 

I think you replied me already about this question, but Im not sure if I have understand it correctly. With #define FORCE_BOOT() 1 and #define RETAIN_LOADER_MODE() 0, the bootloader, when start, always will check my SD card (without push any switch) and if SD card present and with a software.bin file, will update user application and will jump to it ?

2. To always start the loader just set 
#define FORCE_BOOT()    1
Set also 
#define RETAIN_LOADER_MODE() 0

so that it jumps to the application after checking the card.

Three more questions please:

1.- uTaskerConvert may work with HEX input file ??, this is the format of compiled program by Arduino with Teensy 3.6, a .HEX file instead of a .BIN.
So may I use for example uTaskerConvert  program.hex  output.bin -0x1234 –a748b6531124

2.- When I configure Project Properties > C/C++ General > Indexer, Enable project specific settings, Use active build configuration, Apply, OK, like see in your video, when I  Exit from KDS and start again do not keep this configuration, I must configure again each time I run KDS. What is the problem ? 

3.- The Bootloader binary, that I compile from KDS, is protected to avoid read and extract from microcontroller ?, I do not have yet experience with Kinetis and do not know yet how I must write a binary to microcontroller to avoid that somebody may read and extract binary. I work with Segger Jlink programmer to write binary to MK66, do not know if read protection must configure in Jlink software (J-Flash) or I must configure it in KDS or in your library source code.

Kind Regards

0 Kudos

921 Views
mjbcswitzerland
Specialist V

Luis

Notice
#if defined MEMORY_SWAP
    #define _UTASKER_APP_START_       (FLASH_START_ADDRESS)
#elif defined USB_INTERFACE && defined USB_MSD_DEVICE_LOADER
    #define _UTASKER_APP_START_       (UTASKER_APP_START + (ROOT_FILE_ENTRIES * 32)) // when USB is used the start of application space is used for FAT entries
#else
    #define _UTASKER_APP_START_       (UTASKER_APP_START)
#endif

If you don't enable USB-MSD device loading (possibly in parallel with others) 0x8000 is used.
If you do add USB-MSD loading the start address is shifted by 0x80 (to 0x8080).

Assuming you don't use USB-MSD device loading you therefore need 0x8000 (and not 0x8080).
All values are however adjustable if you want by changing them in Loader.h.

The Teensy 3.1, for which the the guide was written, ALWAYS uses USB-MSD since it is the only standard interface that the hardware has and is therefore 0x8080.

#define FORCE_BOOT() is used to decide immediately after reset whether an existing application should be jumped to or whether the serial loader is to be executed.
Since you have no SD card detect switch which can be used for this (and no push button switches) a value of 1 will cause the serial loader to ALWAYS be executed, which I believe is correct for you.

#define RETAIN_LOADER_MODE() is used to decide whether to remain in the serial loader mode AFTER the SD card loading operation has completed (if there is no SD card this is after failure to mount the disk after a few attempts - about 4s). If you have no switch to attach it to, a value of 0 is necessary so that the application is always jumped to (otherwise it will remain in the serial loader forever).


The uTasker utilities are described at http://www.utasker.com/forum/index.php?topic=1445.0
uTaskerConvert expects only binary input files.
To convert Arduino's HEX file to a binary file follow instruction 5. at http://www.utasker.com/forum/index.php?topic=1869.0

>>properties > C/C++ General > Indexer
This is a problem with KDS. It doesn't save this setting so it either needs to be set each time the IDE is started or else just ignore that fact that it shows used files as being not active - it doesn't stop the build working, it just looks strange.

To set read protection (secured mode) change this line in app_hw_kinetis.h
#define KINETIS_FLASH_CONFIGURATION_SECURITY           (FTFL_FSEC_SEC_UNSECURE | FTFL_FSEC_FSLACC_GRANTED | FTFL_FSEC_MEEN_ENABLED | FTFL_FSEC_KEYEN_ENABLED)
to
#define KINETIS_FLASH_CONFIGURATION_SECURITY           (FTFL_FSEC_SEC_SECURE | FTFL_FSEC_FSLACC_GRANTED | FTFL_FSEC_MEEN_ENABLED | FTFL_FSEC_KEYEN_ENABLED)

However, many debuggers will not program the value to the chip to protect against users from securing devices unintentionally. You may need to contact Segger to find out the setting for your debugger that allows it. If using the JLink OpenSDA debugger in KDS it should be possible by choosing the device name "MK66FN2M0xxx18 (allow security)" rather than "MK66FN2M0xxx18" in the debugger setting (according to the list of supported devices at https://www.segger.com/downloads/supported-devices.php).


Regards

Mark

921 Views
luishs
Senior Contributor I

Ok, thank you very much Mark.

0 Kudos

921 Views
luishs
Senior Contributor I

Hello.

Its possible use this software with Kinetis MK66 ??, I need a bootloader with micro SD card for MK66.

Kind Regards

0 Kudos

921 Views
mjbcswitzerland
Specialist V

Hi

Yes, it can be used on any Kinetis part, including the K66.

Regards

Mark

0 Kudos