I don't see why not but I don't know so much.

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.

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

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.

My poor short-term, this is the MCUdude MightyCore; GitHub - MCUdude/MightyCore: Arduino hardware package for ATmega1284, ATmega644, ATmega324, ATmega324PB, ATmega164, ATmega32, ATmega16 and ATmega8535

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.

ArduinoOTA/optiboot.h at master · jandrassy/ArduinoOTA · GitHub
added copy_flash_pages function by jandrassy · Pull Request #5 · MCUdude/optiboot_flash · GitHub
added optional copy_flash_pages function to load application from internal flash by jandrassy · Pull Request #269 · Optiboot/optiboot · GitHub

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.

GoForSmoke:
My poor short-term, this is the MCUdude MightyCore; GitHub - MCUdude/MightyCore: Arduino hardware package for ATmega1284, ATmega644, ATmega324, ATmega324PB, ATmega164, ATmega32, ATmega16 and ATmega8535

A fine choice! As a bonus, MightyCore comes with the version of Optiboot that allows writing to flash from the user application:

GoForSmoke:
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

GoForSmoke:
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

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...

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 GitHub - Optiboot/optiboot: Small and Fast Bootloader for Arduino and other Atmel AVR chips "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.

Juraj:
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?

GoForSmoke:
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