Esempio n. 1
0
/**
 * mirror_ubi_volumes - mirror redundant pairs of volumes
 * @devno	UBI device number
 * @pfi_ubis	list of PFI header data
 *
 * Error handling:
 *	when UBI system couldn't be opened
 *	- returns -PFIFLASH_ERR_UBI_OPEN, err_buf matches text to err
 **/
static int
mirror_ubi_volumes(uint32_t devno, list_t pfi_ubis,
		   char *err_buf, size_t err_buf_size)
{
	int rc;
	uint32_t j;
	list_t ptr;
	pfi_ubi_t i;
	ubi_lib_t ulib;

	rc = 0;
	ulib = NULL;

	log_msg("[ mirror ...");

	rc = ubi_open(&ulib);
	if (rc != 0) {
		rc = -PFIFLASH_ERR_UBI_OPEN;
		EBUF(PFIFLASH_ERRSTR[-rc]);
		goto err;
	}

	/**
	 * Execute all mirror operations on redundant groups.
	 * Create a volume within a redundant group if it does
	 * not exist already (this is a precondition of
	 * ubimirror).
	 */
	foreach(i, ptr, pfi_ubis) {
		for (j = 0; j < i->ids_size; j++) {
			/* skip self-match */
			if (i->ids[j] == i->ids[i->curr_seqnum])
				continue;

			rc = my_ubi_rmvol(devno, i->ids[j],
					  err_buf, err_buf_size);
			if (rc != 0)
				goto err;

			rc = my_ubi_mkvol(devno, j, i,
					  err_buf, err_buf_size);
			if (rc != 0)
				goto err;
		}
	}

	foreach(i, ptr, pfi_ubis) {
		rc = ubimirror(devno, i->curr_seqnum, i->ids, i->ids_size,
			       err_buf, err_buf_size);
		if (rc != 0)
			goto err;
	}
Esempio n. 2
0
int
main(int argc, char **argv) {
	int rc = 0;
	unsigned int ids[VOL_ARGS_MAX];
	char err_buf[1024];

	myargs args = {
		.action = ACT_NORMAL,
		.side = -1,
		.vol_no = 0,
		.vol = {"", ""},
		.options = NULL,
	};

	parse_opt(argc, argv, &args);
	if (args.action == ACT_ARGP_ERR) {
		rc = 127;
		goto err;
	}
	if (args.action == ACT_ARGP_ABORT) {
		rc = 126;
		goto out;
	}
	if (args.vol_no < VOL_ARGS_MAX) {
		fprintf(stderr, "missing volume number for %s\n",
			args.vol_no == 0 ? "source and target" : "target");
		rc = 125;
		goto out;
	}
	for( rc = 0; rc < args.vol_no; ++rc){
		char *endp;
		ids[rc] = strtoul(args.vol[rc], &endp, 0);
		if( *endp != '\0' ){
			fprintf(stderr, "invalid volume number %s\n",
					args.vol[rc]);
			rc = 125;
			goto out;
		}
	}
	rc = ubimirror(EXAMPLE_UBI_DEVICE, args.side, ids, args.vol_no,
		       err_buf, sizeof(err_buf));
	if( rc ){
		err_buf[sizeof err_buf - 1] = '\0';
		fprintf(stderr, err_buf);
		if( rc < 0 )
			rc = -rc;
	}
 out:
 err:
	return rc;
}
static int
do_mirror(int volno)
{
	char errbuf[1024];
	uint32_t ids[2];
	int rc;
	int src_volno_idx = 0;

	ids[0] = EXAMPLE_BOOTENV_VOL_ID_1;
	ids[1] = EXAMPLE_BOOTENV_VOL_ID_2;

	if (volno == EXAMPLE_BOOTENV_VOL_ID_2)
		src_volno_idx = 1;

	rc = ubimirror(EXAMPLE_UBI_DEVICE, src_volno_idx, ids, 2, errbuf,
		       sizeof errbuf);
	if( rc )
		err_msg(errbuf);
	return rc;
}