writing "pages" to program memory

so i am using the arduino mege for this , that one has a good decent amount of program memory . now here is what i need . i want to reserve 60kb of program memory (flash memory) . i want to be completely empty . i managed to get the mega to read at a high speed off of an sd card . so can i reserve the space , then write data to it from the sd card ? the execute at the beginning of the 60kb space ? .

it should be independent from the other main program . there is a command to write pages "SPM - Store Program Memory" and i think i can the program to execute a an exact address of the program memory but can the whole thing all togeather work ?

i want to reserve 60kb of program memory (flash memory) .

For what purpose? Odd amounts of memory are harder to deal with than even amounts. 64K is an even amount. 60K is not.

How are you writing to the flash memory from an SD card? Only the bootloader can write to flash memory when the MCU is running.

i know , just let it be 64kb .

reading off of an SD card is not that complicated so it can be done in the bootloader . you can fit quite a decent amount of code in there . i want the system to execute external programs .

reading off of an SD card is not that complicated so it can be done in the bootloader

Have you actually tried that?

yeah , i managed to play raw headerless 8bit PCM music files off of an SD card at a rate of 15660khz using the arduino mega and an sd card and an 8bit DAC .

now i want to write data from the sd card to the program memory of the chip

now i want to write data from the sd card to the program memory of the chip

When? When the SD card is inserted? When the Arduino starts?

Program memory is generally read only. Only the bootloader can write to program memory.

ok here is it , basically i am writing my own bootloader . and the whole program is in the bootloader .

then i load the program and execute it . when i want to leave the program i will do a chip reset and go back to the bootloader .

amine2: yeah , i managed to play raw headerless 8bit PCM music files off of an SD card at a rate of 15660khz using the arduino mega and an sd card and an 8bit DAC .

now i want to write data from the sd card to the program memory of the chip

I think there is a modified bootloader that has functions that can be called from a executing program (not bootloader) to write to flash memory on the fly. I recall seeing posts about it about a month ago so maybe someone can point you to it.

thank you . i hope so

though what is the bootloader size limit ? is there a limit to what you can put in the bootloader ? like interrupts and stuff