Revision abe147e0 hw/fw_cfg.c

b/hw/fw_cfg.c
47 47

  
48 48
struct _FWCfgState {
49 49
    FWCfgEntry entries[2][FW_CFG_MAX_ENTRY];
50
    FWCfgFiles *files;
50 51
    uint16_t cur_entry;
51 52
    uint32_t cur_offset;
52 53
};
......
273 274
    return 1;
274 275
}
275 276

  
277
int fw_cfg_add_file(FWCfgState *s,  const char *dir, const char *filename,
278
                    uint8_t *data, uint32_t len)
279
{
280
    const char *basename;
281
    int index;
282

  
283
    if (!s->files) {
284
        int dsize = sizeof(uint32_t) + sizeof(FWCfgFile) * FW_CFG_FILE_SLOTS;
285
        s->files = qemu_mallocz(dsize);
286
        fw_cfg_add_bytes(s, FW_CFG_FILE_DIR, (uint8_t*)s->files, dsize);
287
    }
288

  
289
    index = be32_to_cpu(s->files->count);
290
    if (index == FW_CFG_FILE_SLOTS) {
291
        fprintf(stderr, "fw_cfg: out of file slots\n");
292
        return 0;
293
    }
294

  
295
    fw_cfg_add_bytes(s, FW_CFG_FILE_FIRST + index, data, len);
296

  
297
    basename = strrchr(filename, '/');
298
    if (basename) {
299
        basename++;
300
    } else {
301
        basename = filename;
302
    }
303
    if (dir) {
304
        snprintf(s->files->f[index].name, sizeof(s->files->f[index].name),
305
                 "%s/%s", dir, basename);
306
    } else {
307
        snprintf(s->files->f[index].name, sizeof(s->files->f[index].name),
308
                 "%s", basename);
309
    }
310
    s->files->f[index].size   = cpu_to_be32(len);
311
    s->files->f[index].select = cpu_to_be16(FW_CFG_FILE_FIRST + index);
312
    FW_CFG_DPRINTF("%s: #%d: %s (%d bytes)\n", __FUNCTION__,
313
                   index, s->files->f[index].name, len);
314

  
315
    s->files->count = cpu_to_be32(index+1);
316
    return 1;
317
}
318

  
276 319
FWCfgState *fw_cfg_init(uint32_t ctl_port, uint32_t data_port,
277 320
                        target_phys_addr_t ctl_addr, target_phys_addr_t data_addr)
278 321
{

Also available in: Unified diff