Re: dynamic execution of tasks in uC

From: onestone (onestoneXYZ_at_ABCbigpond.net.au)
Date: 06/19/04


Date: Sat, 19 Jun 2004 15:04:31 GMT

heiko_greiner@hotmail.com wrote:

>>...It is a fairly simple task to do this on any
>>micro that can execute code from RAM. I used this technique on a HC05
>>around 1990, as part of a security system, and use a similar technique
>>now on MSP430's to up date software/implement security functions etc.
>>
>>Al
>
>
> First of all, i meant the hardware required for uCLinux might be to
> expensive for my budget ;-)
>
> Al, do you have a link to a project, using ram (or flash?) for dynamic
> tasks? Or can you try to explain how to implement such a technique ?
>
> thanks,
>
> Heiko.

Hello Heiko. The principles are simple. Take the MSP430 for example,
which I currently use in a lot of products/projects. It can execute code
from RAM. There are many ways to execute external tasks. The mechanism
you use will usually depend upon whether the task request is generated
by the process, or externally. Where I have used this for process
requested tasks I have typically had an external secure memory store
which holds the desired task. Thus the micro itself contains no security
information useful to anyone hacking the system. In it's simplest form
the following hopefully will convey the concept. IT ISN'T MEANT TO BE
WORKING CODE!

;******** COMMS PROTOCOL MESSAGE TYPE CONSTANTS

SENDDATA EQU 01
READDATA EQU 02
SENDSTATUS EQU 03
FETCHTASK EQU 04

        ORG RAMSTART

CODEBUFF: DS 512 ;RESERVE 512 BYTES AS CODE BUFFER
TASKQ DS 32 ;RESERVE 16 SLOTS FOR TASK
OTHER VARS..

        ORG PROGSTART

RESET:
        MOV #RAMEND,SP
        CALL #INIT ;PERFORM BASIC START UP
        CLR R4 ;R4 RESERVED AS TASKQ POINTER
        CLR &TASKQ ;SET NULL TASK IN Q0
MAIN:
        CALL #TASKQ(R4) ;EXECUTE THE NEXT TASK
        DECD R4
        JC MAIN
        CLR R4
        JMP MAIN

NULLTASK:
        RET

/*******************************************************************

        ETASK IS A REQUEST TO EXECUTE A TASK STORED EXTERNALLY
        IN THIS SIMPLE EXAMPLE THERE IS ONLY PROVISION FOR ONE ETASK.
        A CRUDE SINGLE BYTE COMMAND IS SENT TO SOME EXTERNAL SOURCE
        INSTRUCTING IT TO DOWNLOAD THE CODE TO BE EXECUTED. THE RECEIVED DATA
WILL BE PLACED IN CODEBUFF. YOU THEN GET TWO CHOICES(AT LEAST).
AFTER SENDING THE COMMAND BYTE. LOOP UNTIL THE CODE IS RECEIVED (FOR
WHEN IT MUST EXECUTE IMMEDIATELY. oR SIMPLY EXIT
        AND ALLOW THE RECEIVE PROTOCOL TO PUSH THE NEW TASK ONTO THE
        QUEUE.

********************************************************************/

ETASK:
        MOV #CODEBUFF,&RX_PTR ;SET RECEIVE DATA POINTER
        MOV.B #FETCHTASK,&TXDATA ;DON'T NEED A TASK, PROTOCOL IS ;SINGLE
BYTE FROM MICRO.
        RET

/***********************************************************************

        RECEIVE MESSAGE STRUCTURE

ADDR 0 MSG TYPE
ADDR 1 DATA LENGTH IN WORDS N
ADDR 2 TASKMSB ;TASK TO BE EXECTUTED UPON DOWNLOAD
ADDR 3 TASKLSB
ADDR 4 DATA
ADDR 5 ...
ADDR 2N+4 ...
ADDR 2N+5 MSB CRC
ADDR 2N+6 LSB CRC
        
ONCE THE MESSAGE HAS BEEN RECEIVED AND VERIFIED The TASK contained
within the message, actually the address of CODEBUFF, is placed into the
TASKQ.

On most occasions I erase the entire code buffer after completion, so,
if this is the case the message header might include a double task
entry, where the firts task placed on the Q (assuming FILO handling) is
the clean up routine.

Typuically the original ETASK might be placed on the queue by an
external interrupt, such a a key press, or detection of a DALLAS secure
memory device.

This is obviously an over simplified explanation, but most of the
necessary elements are there. Most assemblers will generate code for RAM
based source, but keeping the source relocatable will be necessary
sometimes.

The second method is even more powerful, the originating request is
external. The message protocol for the receiver simply places certain
data from each message in the TASKQ. This could be done EVERY TIME a
message is received, as a simple camouflage method using NULLTASK. Or
may only be done for certain message types.

Of course more than one program or function may be buried in the
downloaded code. For example you may download the code necessary to
re-write internal flash using this method, and at the same time download
a decryption algorithm which takes existing data in FLASH, DECRYPTS IT,
then stores it back where it came from. using micro controlled shut down
you can guarantee reverting the flash upon completion, unless the user
pulls power, or RUN an address translator from RAM, and even if power is
pulled the code will be hard to decipher.

Lots of interesting things you can do with this.

Cheers

Al



Relevant Pages

  • Re: Application Object Replacement
    ... does anyone have any ideas on how to use a different technique ... > My Linux server has 1GB of RAM. ... indeed most forms of *nix are phenomonally good at cacheing file i/o ... Or of course you could put the files in a ramdisk, but there's not a lot of ...
    (comp.lang.php)
  • Re: New ARM Cortex Microcontroller Product Family from STMicroelectronics
    ... the answer is YES - the ST part can execute code from RAM off the data bus. ... FLASH speeds). ...
    (comp.arch.embedded)
  • Re: High Dynamic Range Images
    ... There is a learning curve but the technique is not hard to learn. ... If you have the usual Mac with only 1gb RAM you should double ... The usual Mac also has a woefully small hard drive so you should also obtain ... hardware if your next computer is a real computer. ...
    (rec.photo.digital)
  • Re: Signal Integrity and series termination
    ... resistor as close as possible to the driver to avoid signal integrity ... In my design I have a micro ... in one case micro is the driver and RAM is the load ... the data bus with 20ohm resistor pack How should I go about it? ...
    (sci.electronics.design)
  • Re: Urgent: Loading image into ROM
    ... I am using WinCE 6.0 and an ARM board. ... If you have a ROM or a NOR flash you may be able to do that, if you have a NAND flash, a disk on chip or other flash-based storage memory you can't execute code from it. ... You'll need to load code from storage, copy it in RAM and execute it. ...
    (microsoft.public.windowsce.platbuilder)