Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Real time embedded FreeRTOS mailing list 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem TCP & FAT Training




Loading

Create a new task from a différent binary

Posted by Francois Gervais on December 12, 2009
Hi,
I'm am wondering if it's possible to create a task from a different binary file. Let say I have my "kernel" running and I'd like to start another task with a file on a sdcard or something compiled by someone else. Like on uClinux when you just execute an elf file and it gets its own process. I'd like to do this so a user don't have to bundle the kernel to its application.

The way I'm thinking of doing it right now is doing it without an OS and split my RAM and ROM so my kernel would be using the end of the end of the RAM and ROM and the user application the rest of the memory. To load all that I would bootstrap, load my kernel to the end of the memory and init it. Then load the user application and jump to it. Then the kernel would do it's things using interrupts.

Any body have a better alternative? I'm out of google buzz words to continue my research so please feed me a little.

Thanks
Francois

RE: Create a new task from a différent binary

Posted by Richard Damon on December 12, 2009
I don't think you will have any problems with FreeRTOS itself in trying to do this. The one impact on the user program would be that you would have compiled FreeRTOS with a specific set of options (in FreeRTOSconfig.h) and the user has lost the ability to customize this.

Where the difficulty lies is you are in essence needing to do a dynamic link. Your kernel section needs to find a way to know where to find the needed entries to the user program for the tasks it will provide and an entry to initialize the memory used by the user section. The user section will need to have a way to refer back to the routines & data in the kernel that it needs to reference. Note that this includes not only the FreeRTOS functions themselves, but may include the parts of the run time library that FreeRTOS loaded.

If the user is providing just a small piece of code, and your kernel is most of the application, it may be worth the pain to make this happen (unless the tool set already supports this, in which case it may be easy). If the user is providing mostly full application, trying to make it "easier" on them by bundling freeRTOS on the board may be more work then they save from not just including it into their code.

RE: Create a new task from a différent binary

Posted by Dmitri Snejko on December 12, 2009
It is possible. Not really like in uCLinux but similar to some extend. I have a kernel image permanent loaded in the flash memory and applications re\-loadable. There is also a bootloader which can reload images to fixed addresses including the kernel and allows start them. The kernel image and apps compiled separate but shear include files. The key thing is how to link the app without os calls. The kernel image has a table which provides addresses for kernel's calls. The table location is fixed and known to the application, also the table format and offsets for each function is predefined too and not changing. For the application each os call is replaced with a macro like
move a0, table\_start+call\_offset
jmp (a0)
The app should be able to initialize memory belonged to os, allocate treads and start the scheduler. The kernel includes FreeRtos and dynamic memory.

RE: Create a new task from a différent binary

Posted by Francois Gervais on December 12, 2009
Thanks for all your answers,

dsnejko that seems exactly what I want to do. At first, for the communication app to kernel I was thinking of using software interrupt because I though there was no other way. A little like when you're making calls to the bios on a PC.

I'll try to do some tests in that direction but if you have any other information on the linking process please let me know. Anything from a website link to a little piece of code. I played a little with linker script in the past but I think that is going to be one step further.

Thanks a lot
Francois

RE: Create a new task from a différent binary

Posted by Dmitri Snejko on December 13, 2009
I am using CodeWarrior and ColdFire port. All linking is done with assembler so my macro would not work for your toolchain. I have a common file included on both sides. It describes table offsets and macros for table insertion and calling. Something like this, name it lib_links.inc:

.public _xTaskCreate
.public _vTaskDelay

INSERT_LINK:.macro ref
.org OFFSET&&ref
.long ref
.endm


JUMP_LINK: .macro ref
&&ref: move.l _LIB_LINK_TABLE + OFFSET&&ref, a0
jmp (a0)
.endm


The kernel build includes an assembler file similar to:


.global _LIB_LINK_TABLE
.include lib_links.inc

.text
_LIB_LINK_TABLE:
_LIB_LINK_TABLE_START:
_FREERTOS_LINK_TABLE:
INSERT_LINK _xTaskCreate
INSERT_LINK _vTaskDelay

The application build includes an assembler file similar to:

.extern _LIB_LINK_TABLE
.include lib_links.inc

.text
_LIB_LINK_TABLE_APP:
JUMP_LINK _xTaskCreate
JUMP_LINK _vTaskDelay


\_LIB\_LINK\_TABLE is a segment created in the linker command file at fixed location and known for the kernel and the app.

RE: Create a new task from a différent binary

Posted by Dmitri Snejko on December 13, 2009
Markdown spoiled it

RE: Create a new task from a différent binary

Posted by Francois Gervais on December 13, 2009
Thanks a lot

RE: Create a new task from a différent binary

Posted by Dmitri Snejko on December 13, 2009
More readable.

I am using CodeWarrior and ColdFire port. All linking is done with assembler so my macro would not work for your toolchain. I have a common file included on both sides. It describes table offsets and macros for table insertion and calling. Something like this, name it lib_links.inc:
    .public _xTaskCreate
.public _vTaskDelay
INSERT\_LINK: .macro ref
.org OFFSET&&ref
.long ref
.endm
JUMP\_LINK: .macro ref
&&ref: move.l LIB\_LINK\_TABLE + OFFSET&&ref, a0
jmp (a0)
.endm


The kernel build includes an assembler file similar to:

  .global \_LIB\_LINK\_TABLE
.include lib\_links.inc
.text
\_LIB\_LINK\_TABLE:
INSERT\_LINK \_xTaskCreate
INSERT\_LINK \_vTaskDelay


The application build includes an assembler file similar to:


.extern \_LIB\_LINK\_TABLE
.include lib\_links.inc
.text
\_LIB\_LINK\_TABLE_APP:
JUMP\_LINK \_xTaskCreate
JUMP\_LINK \_vTaskDelay


\_LIB\_LINK\_TABLE is a segment created in the linker command file at fixed location and known for the kernel and the app.

RE: Create a new task from a différent binary

Posted by Dmitri Snejko on December 13, 2009
Missed some lines for the definition file:

    .public \_xTaskCreate
.public \_vTaskDelay
INSERT\_LINK: .macro ref
.org OFFSET&&ref
.long ref
.endm
JUMP\_LINK: .macro ref
&&ref: move.l LIB\_LINK\_TABLE + OFFSET&&ref, a0
jmp (a0)
.endm
LINK\_REC\_LEN:.set 4
OFFSET\_xTaskCreate: .set (0\*LINK\_REC\_LEN)
OFFSET\_vTaskDelay:.set (1\*LINK\_REC\_LEN)

RE: Create a new task from a différent binary

Posted by Dima Suslov on November 4, 2010
I have the same question too


[ Back to the top ]    [ About FreeRTOS ]    [ Sitemap ]    [ ]




Copyright (C) 2004-2010 Richard Barry. Copyright (C) 2010-2016 Real Time Engineers Ltd.
Any and all data, files, source code, html content and documentation included in the FreeRTOSTM distribution or available on this site are the exclusive property of Real Time Engineers Ltd.. See the files license.txt (included in the distribution) and this copyright notice for more information. FreeRTOSTM and FreeRTOS.orgTM are trade marks of Real Time Engineers Ltd.

Latest News:

FreeRTOS V9.0.0 is now available for download.


Free TCP/IP and file system demos for the RTOS


Sponsored Links

⇓ Now With No Code Size Limit! ⇓
⇑ Free Download Without Registering ⇑


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Renesas Electronics Gold Alliance RTOS Partner.jpg

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Atmel RTOS partner supporting ARM Cortex-M3 and AVR32 microcontrollers

STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Xilinx Microblaze and Zynq partner

Silicon Labs low power RTOS partner

Altera RTOS partner for Nios II and Cortex-A9 SoC

Freescale Alliance RTOS Member supporting ARM and ColdFire microcontrollers

Infineon ARM Cortex-M microcontrollers

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

Cypress RTOS partner supporting ARM Cortex-M3

Fujitsu RTOS partner supporting ARM Cortex-M3 and FM3

Microsemi (previously Actel) RTOS partner supporting ARM Cortex-M3

Atollic Partner

IAR Partner

Keil ARM Partner

Embedded Artists