Ejemplo n.º 1
0
static int inject_second_rd(const char *path, const char *second_path)
{
    int result = -1;
    uint32_t magic = 0;

    FILE *f = fopen(path, "re");
    if (!f)
    {
        ERROR("Couldn't open %s!\n", path);
        return -1;
    }
    fread(&magic, sizeof(magic), 1, f);
    fclose(f);

    mkdir(TMP_RD2_UNPACKED_DIR, 0755);

    // Decompress initrd
    int type;
    char buff[256];
    char busybox_path[256];
    snprintf(busybox_path, sizeof(busybox_path), "%s/busybox", mrom_dir());

    char *cmd[] = { busybox_path, "sh", "-c", buff, NULL };

    snprintf(buff, sizeof(buff), "B=\"%s\"; cd \"%s\"; \"$B\" cat \"%s\" | \"$B\" cpio -i", busybox_path, TMP_RD2_UNPACKED_DIR, second_path);

    int r;
    char *out = run_get_stdout_with_exit(cmd, &r);
    if (r != 0)
    {
        ERROR("Output: %s\n", out);
        ERROR("Failed to unpack second ramdisk!%s\n", buff);
        goto fail;
    }

    // Update files
    if (copy_rd_files(second_path, busybox_path) < 0)
        goto fail;

    // Pack initrd again
    snprintf(buff, sizeof(buff), "B=\"%s\"; cd \"%s\"; \"$B\" find . | \"$B\" cpio -o -H newc > \"%s\"", busybox_path, TMP_RD2_UNPACKED_DIR, second_path);

    out = run_get_stdout_with_exit(cmd, &r);
    if (r != 0)
    {
        ERROR("Output: %s\n", out);
        ERROR("Failed to pack ramdisk.cpio!\n");
        goto fail;
    }
success:
    result = 0;
fail:
    remove_dir(TMP_RD2_UNPACKED_DIR);
    return result;
}
Ejemplo n.º 2
0
char *run_get_stdout(char **cmd)
{
    int exit_code;
    return run_get_stdout_with_exit(cmd, &exit_code);
}