int rom_add_file(const char *file, const char *fw_dir,

                 target_phys_addr_t addr, int32_t bootindex)

{

    Rom *rom;

    int rc, fd = -1;

    char devpath[100];



    rom = g_malloc0(sizeof(*rom));

    rom->name = g_strdup(file);

    rom->path = qemu_find_file(QEMU_FILE_TYPE_BIOS, rom->name);

    if (rom->path == NULL) {

        rom->path = g_strdup(file);

    }



    fd = open(rom->path, O_RDONLY | O_BINARY);

    if (fd == -1) {

        fprintf(stderr, "Could not open option rom '%s': %s\n",

                rom->path, strerror(errno));

        goto err;

    }



    if (fw_dir) {

        rom->fw_dir  = g_strdup(fw_dir);

        rom->fw_file = g_strdup(file);

    }

    rom->addr    = addr;

    rom->romsize = lseek(fd, 0, SEEK_END);

    rom->data    = g_malloc0(rom->romsize);

    lseek(fd, 0, SEEK_SET);

    rc = read(fd, rom->data, rom->romsize);

    if (rc != rom->romsize) {

        fprintf(stderr, "rom: file %-20s: read error: rc=%d (expected %zd)\n",

                rom->name, rc, rom->romsize);

        goto err;

    }

    close(fd);

    rom_insert(rom);

    if (rom->fw_file && fw_cfg) {

        const char *basename;

        char fw_file_name[56];



        basename = strrchr(rom->fw_file, '/');

        if (basename) {

            basename++;

        } else {

            basename = rom->fw_file;

        }

        snprintf(fw_file_name, sizeof(fw_file_name), "%s/%s", rom->fw_dir,

                 basename);

        fw_cfg_add_file(fw_cfg, fw_file_name, rom->data, rom->romsize);

        snprintf(devpath, sizeof(devpath), "/rom@%s", fw_file_name);

    } else {

        snprintf(devpath, sizeof(devpath), "/rom@" TARGET_FMT_plx, addr);

    }



    add_boot_device_path(bootindex, NULL, devpath);

    return 0;



err:

    if (fd != -1)

        close(fd);

    g_free(rom->data);

    g_free(rom->path);

    g_free(rom->name);

    g_free(rom);

    return -1;

}

int rom_add_file(const char *file, const char *fw_dir,

                 target_phys_addr_t addr, int32_t bootindex)

{

    Rom *rom;

    int rc, fd = -1;

    char devpath[100];



    rom = g_malloc0(sizeof(*rom));

    rom->name = g_strdup(file);

    rom->path = qemu_find_file(QEMU_FILE_TYPE_BIOS, rom->name);

    if (rom->path == NULL) {

        rom->path = g_strdup(file);

    }



    fd = open(rom->path, O_RDONLY | O_BINARY);

    if (fd == -1) {

        fprintf(stderr, "Could not open option rom '%s': %s\n",

                rom->path, strerror(errno));

        goto err;

    }



    if (fw_dir) {

        rom->fw_dir  = g_strdup(fw_dir);

        rom->fw_file = g_strdup(file);

    }

    rom->addr    = addr;

    rom->romsize = lseek(fd, 0, SEEK_END);

    rom->data    = g_malloc0(rom->romsize);

    lseek(fd, 0, SEEK_SET);

    rc = read(fd, rom->data, rom->romsize);

    if (rc != rom->romsize) {

        fprintf(stderr, "rom: file %-20s: read error: rc=%d (expected %zd)\n",

                rom->name, rc, rom->romsize);

        goto err;

    }

    close(fd);

    rom_insert(rom);

    if (rom->fw_file && fw_cfg) {

        const char *basename;

        char fw_file_name[56];



        basename = strrchr(rom->fw_file, '/');

        if (basename) {

            basename++;

        } else {

            basename = rom->fw_file;

        }

        snprintf(fw_file_name, sizeof(fw_file_name), "%s/%s", rom->fw_dir,

                 basename);

        fw_cfg_add_file(fw_cfg, fw_file_name, rom->data, rom->romsize);

        snprintf(devpath, sizeof(devpath), "/rom@%s", fw_file_name);

    } else {

        snprintf(devpath, sizeof(devpath), "/rom@" TARGET_FMT_plx, addr);

    }



    add_boot_device_path(bootindex, NULL, devpath);

    return 0;



err:

    if (fd != -1)

        close(fd);

    g_free(rom->data);

    g_free(rom->path);

    g_free(rom->name);

    g_free(rom);

    return -1;

}

int FUNC_0(const char *VAR_0, const char *VAR_1,

                 target_phys_addr_t VAR_2, int32_t VAR_3)

{

    Rom *rom;

    int VAR_4, VAR_5 = -1;

    char VAR_6[100];



    rom = g_malloc0(sizeof(*rom));

    rom->name = g_strdup(VAR_0);

    rom->path = qemu_find_file(QEMU_FILE_TYPE_BIOS, rom->name);

    if (rom->path == NULL) {

        rom->path = g_strdup(VAR_0);

    }



    VAR_5 = open(rom->path, O_RDONLY | O_BINARY);

    if (VAR_5 == -1) {

        fprintf(stderr, "Could not open option rom '%s': %s\n",

                rom->path, strerror(errno));

        goto err;

    }



    if (VAR_1) {

        rom->VAR_1  = g_strdup(VAR_1);

        rom->fw_file = g_strdup(VAR_0);

    }

    rom->VAR_2    = VAR_2;

    rom->romsize = lseek(VAR_5, 0, SEEK_END);

    rom->data    = g_malloc0(rom->romsize);

    lseek(VAR_5, 0, SEEK_SET);

    VAR_4 = read(VAR_5, rom->data, rom->romsize);

    if (VAR_4 != rom->romsize) {

        fprintf(stderr, "rom: VAR_0 %-20s: read error: VAR_4=%d (expected %zd)\n",

                rom->name, VAR_4, rom->romsize);

        goto err;

    }

    close(VAR_5);

    rom_insert(rom);

    if (rom->fw_file && fw_cfg) {

        const char *VAR_7;

        char VAR_8[56];



        VAR_7 = strrchr(rom->fw_file, '/');

        if (VAR_7) {

            VAR_7++;

        } else {

            VAR_7 = rom->fw_file;

        }

        snprintf(VAR_8, sizeof(VAR_8), "%s/%s", rom->VAR_1,

                 VAR_7);

        fw_cfg_add_file(fw_cfg, VAR_8, rom->data, rom->romsize);

        snprintf(VAR_6, sizeof(VAR_6), "/rom@%s", VAR_8);

    } else {

        snprintf(VAR_6, sizeof(VAR_6), "/rom@" TARGET_FMT_plx, VAR_2);

    }



    add_boot_device_path(VAR_3, NULL, VAR_6);

    return 0;



err:

    if (VAR_5 != -1)

        close(VAR_5);

    g_free(rom->data);

    g_free(rom->path);

    g_free(rom->name);

    g_free(rom);

    return -1;

}

int FUNC_0(const char *VAR_0, const char *VAR_1,
target_phys_addr_t VAR_2, int32_t VAR_3)
{ Rom *rom; int VAR_4, VAR_5 = -1; char VAR_6[100]; rom = g_malloc0(sizeof(*rom)); rom->name = g_strdup(VAR_0); rom->path = qemu_find_file(QEMU_FILE_TYPE_BIOS, rom->name); if (rom->path == NULL) { rom->path = g_strdup(VAR_0); } VAR_5 = open(rom->path, O_RDONLY | O_BINARY); if (VAR_5 == -1) { fprintf(stderr, "Could not open option rom '%s': %s\n",
rom->path, strerror(errno)); goto err; } if (VAR_1) { rom->VAR_1  = g_strdup(VAR_1); rom->fw_file = g_strdup(VAR_0); } rom->VAR_2    = VAR_2; rom->romsize = lseek(VAR_5, 0, SEEK_END); rom->data    = g_malloc0(rom->romsize); lseek(VAR_5, 0, SEEK_SET); VAR_4 = read(VAR_5, rom->data, rom->romsize); if (VAR_4 != rom->romsize) { fprintf(stderr, "rom: VAR_0 %-20s: read error: VAR_4=%d (expected %zd)\n",
rom->name, VAR_4, rom->romsize); goto err; } close(VAR_5); rom_insert(rom); if (rom->fw_file && fw_cfg) { const char *VAR_7; char VAR_8[56]; VAR_7 = strrchr(rom->fw_file, '/'); if (VAR_7) { VAR_7++; } else { VAR_7 = rom->fw_file; } snprintf(VAR_8, sizeof(VAR_8), "%s/%s", rom->VAR_1,
VAR_7); fw_cfg_add_file(fw_cfg, VAR_8, rom->data, rom->romsize); snprintf(VAR_6, sizeof(VAR_6), "/rom@%s", VAR_8); } else { snprintf(VAR_6, sizeof(VAR_6), "/rom@" TARGET_FMT_plx, VAR_2); } add_boot_device_path(VAR_3, NULL, VAR_6); return 0; err:
if (VAR_5 != -1)
close(VAR_5); g_free(rom->data); g_free(rom->path); g_free(rom->name); g_free(rom); return -1; }