Go Down

Topic: I don't see why not but I don't know so much. (Read 566 times) previous topic - next topic

GoForSmoke

Apr 16, 2019, 05:37 am Last Edit: Apr 16, 2019, 05:38 am by GoForSmoke
Okay just suppose you put executable bytes in PROGMEM, you can load the address and jump or call indirect and run them?

Is there some sort of PROGMEM can't do that? 

I'm looking at if possible copying segments of compiled code to flash at run time (with Mighty_MCU) as inlined hex and run that. Well, at least short commands.

1) http://gammon.com.au/blink  <-- tasking Arduino 1-2-3
2) http://gammon.com.au/serial <-- techniques howto
3) http://gammon.com.au/interrupts
Your sketch can sense ongoing process events in time.
Your sketch can make events to control it over time.

pert

What's "Mighty_MCU"? I did a Google search for it, but the only result was a previous forum thread by you.

Juraj

I am not sure if I understand, but

The Optiboot 8 has a function to write to flash, which can be called from application (skech). I use this function in the ArduinoOTA library to write new version of the application received over network to upper part of the flash memory. Other function added to Optiboot by me the copies the application to address 0 and resets the board.

So yes it is possible to write a function to flash and jump to it.

https://github.com/jandrassy/ArduinoOTA/blob/master/src/utility/optiboot.h
https://github.com/MCUdude/optiboot_flash/pull/5/commits/d671e2287b20f7fe26b31c9da1605a73876a36e0
https://github.com/Optiboot/optiboot/pull/269/commits/b998bfef2dbd14cf1ec4a3ee10268e1e49a6dd60

GoForSmoke

My poor short-term, this is the MCUdude MightyCore;  https://github.com/MCUdude/MightyCore

I am not sure if I understand, but

The Optiboot 8 has a function to write to flash, which can be called from application (skech). I use this function in the ArduinoOTA library to write new version of the application received over network to upper part of the flash memory. Other function added to Optiboot by me the copies the application to address 0 and resets the board.

So yes it is possible to write a function to flash and jump to it.

https://github.com/jandrassy/ArduinoOTA/blob/master/src/utility/optiboot.h
https://github.com/MCUdude/optiboot_flash/pull/5/commits/d671e2287b20f7fe26b31c9da1605a73876a36e0
https://github.com/Optiboot/optiboot/pull/269/commits/b998bfef2dbd14cf1ec4a3ee10268e1e49a6dd60
You run the hex in the upper part and it copies itself over the old hex down low?

I look for addressing the upper 64K of a 1284P's flash and find reference to the RAMPZ register for use by ELPM/SPM.
And then when I look in the Instruction Set Summary there is no ELPM. SPM yes, ELPM no.

Okay, got the AVR IS Manual and straightened out... 1284P instructions are 16/32 bit, the IP is to 64K 16 bit words in flash. A 2-byte Z jump or call can reach anywhere in 128K.

Oh my that manual really helps.
1) http://gammon.com.au/blink  <-- tasking Arduino 1-2-3
2) http://gammon.com.au/serial <-- techniques howto
3) http://gammon.com.au/interrupts
Your sketch can sense ongoing process events in time.
Your sketch can make events to control it over time.

pert

My poor short-term, this is the MCUdude MightyCore;  https://github.com/MCUdude/MightyCore
A fine choice! As a bonus, MightyCore comes with the version of Optiboot that allows writing to flash from the user application:
https://github.com/MCUdude/MightyCore#write-to-own-flash

Juraj

#5
Apr 16, 2019, 09:53 am Last Edit: Apr 16, 2019, 10:06 am by Juraj
You run the hex in the upper part and it copies itself over the old hex down low?

the library in the running sketch writes the new version into upper half and then the bootloader copies it to address 0 to run it after reset

look for addressing the upper 64K of a 1284P's flash and find reference to the RAMPZ register for use by ELPM/SPM.
And then when I look in the Instruction Set Summary there is no ELPM. SPM yes, ELPM no.

Okay, got the AVR IS Manual and straightened out... 1284P instructions are 16/32 bit, the IP is to 64K 16 bit words in flash. A 2-byte Z jump or call can reach anywhere in 128K.
ATmega2560 has EIND to access the upper 128 kB

I had an interesting problem on ATmega2560

westfw


Quote
just suppose you put executable bytes in PROGMEM, you can load the address and jump or call indirect and run them?
Yes.  This is what the bootloader does, after all...

Quote
Is there some sort of PROGMEM can't do that?
Normally, only the "bootloader section" of flash can write PROGMEM.
As several people have pointed out, newer versions of Optiboot (as from https://github.com/Optiboot/optiboot "recently", or from MightyCore and the other MCUDude cores for quite some time) have a function in the bootloader section that can be called from anywhere in the application.



GoForSmoke

the library in the running sketch writes the new version into upper half and then the bootloader copies it to address 0 to run it after reset

So you never jump to or call the code loaded in the upper end?

1) http://gammon.com.au/blink  <-- tasking Arduino 1-2-3
2) http://gammon.com.au/serial <-- techniques howto
3) http://gammon.com.au/interrupts
Your sketch can sense ongoing process events in time.
Your sketch can make events to control it over time.

Juraj

#8
Apr 16, 2019, 11:01 am Last Edit: Apr 16, 2019, 11:02 am by Juraj
So you never jump to or call the code loaded in the upper end?


I call the functions in bootloader. bootloader is at the end of the flash.

read my avrfreaks question and answer. it will give you insight
https://www.avrfreaks.net/forum/eicall-app-bootloader-atmega-2560-jumps-address-0x1fe01-without-eind-set

Go Up