Programming SRAM over SWD
If you have a linker script which links your executable to an appropriate address for ram, then you could interpret the hex file and extract the payload bytes.

But it would probably be easier to use arm-none-eabi-objcopy, ie

arm-none-eabi-objcopy -O binary myproject.elf myproject.bin


This will give you a raw binary file that you can write to the chip starting at the base address you linked for.  Note that in doing things this way the base address is not preserved in the file itself - you will have to make sure you keep that consistent between the file creation and the file usage.  Still, this is a fairly common choice - many simple flashing programs only understand raw binaries, with the destination address given explicitly on the command line.

To fully run from RAM, you need a chip that lets your relocate the vector table there; some do and some do not.  If you can do that in a way that survives reset and have the reset vector in the table pointed to your code in RAM it may work.  Or your could write a table pointing the reset vector at RAM to the usual location in flash.  Keep in mind that the use of resetting to RAM is a bit limited, as there normally would be no program there to execute, unless something put it there.  And the something can do a little cleanup and just branch to the starting address.