Closed xobs closed 5 years ago
It turns out this is already possible in litex.
Create the ROM this way:
from litex.soc.interconnect import wishbone
class RandomFirmwareROM(wishbone.SRAM):
def __init__(self, size):
import random
# Seed the random data with a fixed number, so different bitstreams
# can all share firmware.
random.seed(2373)
data = []
for d in range(int(size / 4)):
data.append(random.getrandbits(32))
print("Firmware {} bytes of random data".format(size))
wishbone.SRAM.__init__(self, size, read_only=True, init=data)
Then, register the rom:
class BaseSoC(SoCCore):
def __init__(self, platform, **kwargs):
SoCCore.__init__(self, platform, clk_freq, **kwargs)
kwargs['integrated_rom_size']=0
bios_size = 0x2c00
self.submodules.firmware_ram = RandomFirmwareROM(bios_size)
self.add_constant("ROM_DISABLE", 1)
# self.add_memory_region("rom", kwargs['cpu_reset_address'], bios_size)
self.register_rom(self.firmware_ram.bus, bios_size)
To repack the top.bin
file, use ice40-repack
Thanks for sharing, this will be very useful.
The ICE40 toolchain has the ability to patch block ram in the emitted bitstream. However, because it uses heuristics to locate the memory, it requires that the ram contain random data.
It is possible to hack litex to generate a ROM image that fills the entire area with random data:
We can then patch the emitted rom file with the actual contents of
bios.bin
.There are a few issues:
icebram
bios.bin
file must be converted to 32-bit hex values and padded to fill the entire memoryI'm not very good with python, so I hacked together a C program and shell script combination that fixes up
mem.init
and patches it with the contents ofbios.bin
.C program:
Shell script: