/*
 * This function is shared between the create and update subcommands.
 * The difference between the two subcommands is that when the FIP file
 * is created, the parsing of an existing FIP is skipped.  This results
 * in update_fip() creating the new FIP file from scratch because the
 * internal image table is not populated.
 */
static void update_fip(void)
{
    toc_entry_t *toc_entry;
    image_t *image;

    /* Add or replace images in the FIP file. */
    for (toc_entry = toc_entries;
            toc_entry->cmdline_name != NULL;
            toc_entry++) {
        if (toc_entry->action != DO_PACK)
            continue;

        image = read_image_from_file(toc_entry, toc_entry->action_arg);
        if (toc_entry->image != NULL) {
            if (verbose)
                log_dbgx("Replacing image %s.bin with %s",
                         toc_entry->cmdline_name,
                         toc_entry->action_arg);
            replace_image(toc_entry->image, image);
        } else {
            if (verbose)
                log_dbgx("Adding image %s",
                         toc_entry->action_arg);
            add_image(image);
        }
        /* Link backpointer from lookup entry. */
        toc_entry->image = image;

        free(toc_entry->action_arg);
        toc_entry->action_arg = NULL;
    }
}
/*
 * This function is shared between the create and update subcommands.
 * The difference between the two subcommands is that when the FIP file
 * is created, the parsing of an existing FIP is skipped.  This results
 * in update_fip() creating the new FIP file from scratch because the
 * internal image table is not populated.
 */
static void update_fip(void)
{
    toc_entry_t *toc_entry;
    image_t *new_image, *old_image;

    /* Add or replace images in the FIP file. */
    for (toc_entry = toc_entries;
            toc_entry->cmdline_name != NULL;
            toc_entry++) {
        if (toc_entry->action != DO_PACK)
            continue;

        new_image = read_image_from_file(&toc_entry->uuid,
                                         toc_entry->action_arg);
        old_image = lookup_image_from_uuid(&toc_entry->uuid);
        if (old_image != NULL) {
            if (verbose)
                log_dbgx("Replacing image %s.bin with %s",
                         toc_entry->cmdline_name,
                         toc_entry->action_arg);
            replace_image(old_image, new_image);
        } else {
            if (verbose)
                log_dbgx("Adding image %s",
                         toc_entry->action_arg);
            add_image(new_image);
        }

        free(toc_entry->action_arg);
        toc_entry->action_arg = NULL;
    }
}