Exemple #1
0
static int cmd_sym_load_add(int clear, char **arg)
{
	FILE *in;
	char * path;

	if (clear && prompt_abort(MODIFY_SYMS))
		return 0;

	path = expand_tilde(*arg);
	if (!path)
		return -1;

	in = fopen(path, "rb");
	free(path);
	if (!in) {
		printc_err("sym: %s: %s\n", *arg, last_error());
		return -1;
	}

	if (clear) {
		stab_clear();
		unmark_modified(MODIFY_SYMS);
	} else {
		mark_modified(MODIFY_SYMS);
	}

	if (binfile_syms(in) < 0) {
		fclose(in);
		return -1;
	}

	fclose(in);

	return 0;
}
Exemple #2
0
static int cmd_prog(cproc_t cp, char **arg)
{
    device_t dev = cproc_device(cp);
    stab_t stab = cproc_stab(cp);
    FILE *in;
    struct prog_data prog;

    if (cproc_prompt_abort(cp, CPROC_MODIFY_SYMS))
        return 0;

    in = fopen(*arg, "r");
    if (!in) {
        fprintf(stderr, "prog: %s: %s\n", *arg, strerror(errno));
        return -1;
    }

    if (dev->ctl(dev, DEVICE_CTL_HALT) < 0) {
        fclose(in);
        return -1;
    }

    prog_init(&prog, dev);

    if (binfile_extract(in, prog_feed, &prog) < 0) {
        fclose(in);
        return -1;
    }

    if (binfile_info(in) & BINFILE_HAS_SYMS) {
        stab_clear(stab);
        binfile_syms(in, stab);
    }

    fclose(in);

    if (prog_flush(&prog) < 0)
        return -1;

    if (dev->ctl(dev, DEVICE_CTL_RESET) < 0) {
        fprintf(stderr, "prog: failed to reset after programming\n");
        return -1;
    }

    cproc_unmodify(cp, CPROC_MODIFY_SYMS);
    return 0;
}