Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory initialization files #2136

Open
merveyubogluu opened this issue Dec 11, 2024 · 3 comments
Open

Memory initialization files #2136

merveyubogluu opened this issue Dec 11, 2024 · 3 comments

Comments

@merveyubogluu
Copy link

Hi, I wanted to understand how Litex actually creates the memory files using Migen. I wanted to compile my own C codes and be able to use the created binary. I actually used the --integrated_rom_init method for instructions but i couldnt find a way for extracting the data memory information from the binary and did not understand how Litex does it.

Does anyone know something about this?

@enjoy-digital
Copy link
Owner

Hi @merveyubogluu,

When you use --integrated-rom-init and pass a binary, LiteX automatically invokes get_mem_data() on that binary to produce the initialization arrays. These arrays are then used directly to initialize the on-chip ROM, as can be seen here:

# Initialize ROM from binary file when provided.

        # ROM.
        # Initialize ROM from binary file when provided.
        if isinstance(integrated_rom_init, str):
            integrated_rom_init = get_mem_data(integrated_rom_init,
                endianness = "little", # FIXME: Depends on CPU.
                data_width = bus_data_width
            )
            integrated_rom_size = 4*len(integrated_rom_init)

Otherwise, more generally: LiteX uses get_mem_data() to convert a given binary or JSON memory image into Python arrays that initialize its internal memories at build time. These arrays are then passed as the init parameter to Migen’s Memory modules, ensuring that when the design is synthesized and loaded onto the FPGA, the memory blocks already contain the specified instructions or data.

@merveyubogluu
Copy link
Author

Hi thanks for the quick response. I understood the part what get_mem_data function does however it actually generates the instructions from the binary only. I was wondering how other memories are generated? Cause when I create an SoC without using the --integrated-rom-init, it generates a memory file. When I include a binary, it still generates the other memory but with a ROM (instruction memory) also. My question was how Litex build that memory (in this case i think its data memory) not the instruction memory.

@enjoy-digital
Copy link
Owner

Hi,

only the ROM is initialized with contents, other memory are not initialized. The CPU will however copy some data to RAM when booting, but it's the CPU/firmware that does it not the SoC. So LiteX only knows how to initialize the ROM and the CPU does the rest.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants