Commit a9a28591 authored by Max Filippov's avatar Max Filippov
Browse files

hw/xtensa/xtfpga: refactor bootparameters filling



Separate filling first/last tag and size calculation from the kernel
command line setup.

Signed-off-by: default avatarMax Filippov <jcmvbkbc@gmail.com>
parent 62dbaede
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -16,6 +16,11 @@ typedef struct BpTag {
    uint16_t size;
} BpTag;

static inline size_t get_tag_size(size_t data_size)
{
    return data_size + sizeof(BpTag) + 4;
}

static inline ram_addr_t put_tag(ram_addr_t addr, uint16_t tag,
        size_t size, const void *data)
{
+16 −12
Original line number Diff line number Diff line
@@ -237,26 +237,30 @@ static void lx_init(const LxBoardDesc *board, MachineState *machine)

    /* Use presence of kernel file name as 'boot from SRAM' switch. */
    if (kernel_filename) {
        size_t bp_size = 2 * get_tag_size(0);
        uint32_t tagptr = 0xfe000000 + board->sram_size;
        uint32_t cur_tagptr;

        rom = g_malloc(sizeof(*rom));
        memory_region_init_ram(rom, NULL, "lx60.sram", board->sram_size);
        vmstate_register_ram_global(rom);
        memory_region_add_subregion(system_memory, 0xfe000000, rom);

        /* Put kernel bootparameters to the end of that SRAM */
        if (kernel_cmdline) {
            size_t cmdline_size = strlen(kernel_cmdline) + 1;
            size_t bp_size = sizeof(BpTag[4]) + cmdline_size;
            uint32_t tagptr = (0xfe000000 + board->sram_size - bp_size) & ~0xff;
            bp_size += get_tag_size(strlen(kernel_cmdline) + 1);
        }

            env->regs[2] = tagptr;
        /* Put kernel bootparameters to the end of that SRAM */
        tagptr = (tagptr - bp_size) & ~0xff;
        cur_tagptr = put_tag(tagptr, BP_TAG_FIRST, 0, NULL);

            tagptr = put_tag(tagptr, BP_TAG_FIRST, 0, NULL);
            if (cmdline_size > 1) {
                tagptr = put_tag(tagptr, BP_TAG_COMMAND_LINE,
                        cmdline_size, kernel_cmdline);
            }
            tagptr = put_tag(tagptr, BP_TAG_LAST, 0, NULL);
        if (kernel_cmdline) {
            cur_tagptr = put_tag(cur_tagptr, BP_TAG_COMMAND_LINE,
                                 strlen(kernel_cmdline) + 1, kernel_cmdline);
        }
        cur_tagptr = put_tag(cur_tagptr, BP_TAG_LAST, 0, NULL);
        env->regs[2] = tagptr;

        uint64_t elf_entry;
        uint64_t elf_lowaddr;
        int success = load_elf(kernel_filename, translate_phys_addr, cpu,