Exemple #1
0
int _do_help (cmd_tbl_t *cmd_start, int cmd_items, cmd_tbl_t * cmdtp, int
	      flag, int argc, char * const argv[])
{
	int i;
	int rcode = 0;

	if (argc == 1) {	/*show list of commands */
		cmd_tbl_t *cmd_array[cmd_items];
		int i, j, swaps;

		/* Make array of commands from .uboot_cmd section */
		cmdtp = cmd_start;
		for (i = 0; i < cmd_items; i++) {
			cmd_array[i] = cmdtp++;
		}

		/* Sort command list (trivial bubble sort) */
		for (i = cmd_items - 1; i > 0; --i) {
			swaps = 0;
			for (j = 0; j < i; ++j) {
				if (strcmp (cmd_array[j]->name,
					    cmd_array[j + 1]->name) > 0) {
					cmd_tbl_t *tmp;
					tmp = cmd_array[j];
					cmd_array[j] = cmd_array[j + 1];
					cmd_array[j + 1] = tmp;
					++swaps;
				}
			}
			if (!swaps)
				break;
		}

		/* print short help (usage) */
		for (i = 0; i < cmd_items; i++) {
			const char *usage = cmd_array[i]->usage;

			/* allow user abort */
			if (ctrlc ())
				return 1;
			if (usage == NULL)
				continue;
			printf("%-*s- %s\n", CONFIG_SYS_HELP_CMD_WIDTH,
			       cmd_array[i]->name, usage);
		}
		return 0;
	}
	/*
	 * command help (long version)
	 */
	for (i = 1; i < argc; ++i) {
		if ((cmdtp = find_cmd_tbl (argv[i], cmd_start, cmd_items )) != NULL) {
			rcode |= cmd_usage(cmdtp);
		} else {
			printf ("Unknown command '%s' - try 'help'"
				" without arguments for list of all"
				" known commands\n\n", argv[i]
					);
			rcode = 1;
		}
	}
	return rcode;
}
Exemple #2
0
static int
netboot_common (proto_t proto, cmd_tbl_t *cmdtp, int argc, char * const argv[])
{
	char *s;
	char *end;
	int   rcode = 0;
	int   size;
	ulong addr;

	/* pre-set load_addr */
	if ((s = getenv("loadaddr")) != NULL) {
		load_addr = simple_strtoul(s, NULL, 16);
	}

	switch (argc) {
	case 1:
		break;

	case 2:	/*
		 * Only one arg - accept two forms:
		 * Just load address, or just boot file name. The latter
		 * form must be written in a format which can not be
		 * mis-interpreted as a valid number.
		 */
		addr = simple_strtoul(argv[1], &end, 16);
		/* use default loadaddr address is 0 */
		if (!addr)
			addr = load_addr;
		else if (end == (argv[1] + strlen(argv[1])))
			load_addr = addr;
		else
			copy_filename(BootFile, argv[1], sizeof(BootFile));
		break;

	case 3:
		addr = simple_strtoul(argv[1], &end, 16);
		/* use default loadaddr address is 0 */
		if (!addr)
			addr = load_addr;
		else if (end == (argv[1] + strlen(argv[1])))
			load_addr = addr;

		copy_filename (BootFile, argv[2], sizeof(BootFile));

		break;

	default:
		show_boot_progress (-80);
		return cmd_usage(cmdtp);
	}


	show_boot_progress (80);
	if ((size = NetLoop(proto)) < 0) {
		show_boot_progress (-81);
		return 1;
	}

	show_boot_progress (81);
	/* NetLoop ok, update environment */
	netboot_update_env();

	/* done if no file was loaded (no errors though) */
	if (size == 0) {
		show_boot_progress (-82);
		return 0;
	}

	/* flush cache */
	flush_cache(load_addr, size);

	/* Loading ok, check if we should attempt an auto-start */
	if (((s = getenv("autostart")) != NULL) && (strcmp(s,"yes") == 0)) {
		char *local_args[2];
		local_args[0] = argv[0];
		local_args[1] = NULL;

		printf ("Automatic boot of image at addr 0x%08lX ...\n",
			load_addr);
		show_boot_progress (82);
		rcode = do_bootm (cmdtp, 0, 1, local_args);
	}

	if (rcode < 0)
		show_boot_progress (-83);
	else
		show_boot_progress (84);
	return rcode;
}
Exemple #3
0
int do_ddr(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
{
	size_t length;
	char *cmd;
	int total;
	int option = 0, tmp = 0, tmp2 = 0;
	total = 0;

	length = 0x80000;

	if (argc < 3)
		goto usage;

	cmd = argv[1];

	if (strcmp(cmd, "training") == 0) {
		writel(0x0, DDRT_OPTION_REG);
		tmp = atoi(argv[2]);
		tmp2 = DDRT_OPTION_CMD;
		tmp2 <<= 16;
		tmp |= tmp2;
		writel(tmp, DDRT_OPTION_REG);
		udelay(10000);
		printf("DDR trainning starting......\n");
		printf("please wait and wait!!!\n");
		udelay(10000);
		reset_cpu(0);
		udelay(10000);
		return 0;
	} else if (strcmp(cmd, "pressure") == 0) {
		if (argc == 4) {
			total = atoi(argv[3]);
			option = atoi(argv[2]);
			if (option == 2)
				ddr_training_ssn_pressure(total,
						DDRT_MODE_READ);
			else if (option == 1)
				ddr_training_ssn_pressure(total,
						DDRT_MODE_WRITE);
			else if (option == 3)
				ddr_training_ssn_pressure(total, DDRT_MODE_WR);
			else
				goto usage;
		} else
			goto usage;

		return 0;

	} else if (strcmp(cmd, "cycpressure") == 0) {
		if (argc == 4) {
			total = atoi(argv[3]);
			ddr_cyc_pressure(total, atoi(argv[2]));
		}
		return 0;

	} else if (strcmp(cmd, "result") == 0) {
		ddr_result_printf();

		return 0;

	} else
		goto usage;

usage:
	cmd_usage(cmdtp);
	return 0;
}
Exemple #4
0
int do_bootm_subcommand (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
{
	int ret = 0;
	int state;
	cmd_tbl_t *c;
	boot_os_fn *boot_fn;

	c = find_cmd_tbl(argv[1], &cmd_bootm_sub[0], ARRAY_SIZE(cmd_bootm_sub));

	if (c) {
		state = (int)c->cmd;

		/* treat start special since it resets the state machine */
		if (state == BOOTM_STATE_START) {
			argc--;
			argv++;
			return bootm_start(cmdtp, flag, argc, argv);
		}
	}
	/* Unrecognized command */
	else {
		cmd_usage(cmdtp);
		return 1;
	}

	if (images.state >= state) {
		printf ("Trying to execute a command out of order\n");
		cmd_usage(cmdtp);
		return 1;
	}

	images.state |= state;
	boot_fn = boot_os[images.os.os];

	switch (state) {
		ulong load_end;
		case BOOTM_STATE_START:
			/* should never occur */
			break;
		case BOOTM_STATE_LOADOS:
			ret = bootm_load_os(images.os, &load_end, 0);
			if (ret)
				return ret;

			lmb_reserve(&images.lmb, images.os.load,
					(load_end - images.os.load));
			break;
#if defined(CONFIG_PPC) || defined(CONFIG_M68K) || defined(CONFIG_SPARC)
		case BOOTM_STATE_RAMDISK:
		{
			ulong rd_len = images.rd_end - images.rd_start;
			char str[17];

			ret = boot_ramdisk_high(&images.lmb, images.rd_start,
				rd_len, &images.initrd_start, &images.initrd_end);
			if (ret)
				return ret;

			sprintf(str, "%lx", images.initrd_start);
			setenv("initrd_start", str);
			sprintf(str, "%lx", images.initrd_end);
			setenv("initrd_end", str);
		}
			break;
#endif
#if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_SYS_BOOTMAPSZ)
		case BOOTM_STATE_FDT:
		{
			ulong bootmap_base = getenv_bootm_low();
			ret = boot_relocate_fdt(&images.lmb, bootmap_base,
				&images.ft_addr, &images.ft_len);
			break;
		}
#endif
		case BOOTM_STATE_OS_CMDLINE:
			ret = boot_fn(BOOTM_STATE_OS_CMDLINE, argc, argv, &images);
			if (ret)
				printf ("cmdline subcommand not supported\n");
			break;
		case BOOTM_STATE_OS_BD_T:
			ret = boot_fn(BOOTM_STATE_OS_BD_T, argc, argv, &images);
			if (ret)
				printf ("bdt subcommand not supported\n");
			break;
		case BOOTM_STATE_OS_PREP:
			ret = boot_fn(BOOTM_STATE_OS_PREP, argc, argv, &images);
			if (ret)
				printf ("prep subcommand not supported\n");
			break;
		case BOOTM_STATE_OS_GO:
			disable_interrupts();
			arch_preboot_os();
			boot_fn(BOOTM_STATE_OS_GO, argc, argv, &images);
			break;
	}

	return ret;
}
Exemple #5
0
static void
parse_long_opts(int ind, char *opt_arg)
{
    int errno;
    struct ether_addr *mac;

    errno = 0;
    switch(ind) {
        case CMD_OPT_IND:
            cmd_usage();
        case HLP_OPT_IND:
            usage();
        case GET_OPT_IND:
        case CRT_OPT_IND:
        case DEL_OPT_IND:
            nh_id = strtoul(opt_arg, NULL, 0);
            if (errno)
                usage();
            nh_set = 1;
            break;
        case OIF_OPT_IND:
            if_id = strtoul(opt_arg, NULL, 0);
            if (errno) 
                usage();
            break;
        case SMAC_OPT_IND:
            mac = ether_aton(opt_arg);
            if (mac)
                memcpy(src_mac, mac, sizeof(src_mac));
            else
                cmd_usage();
            break;
        case DMAC_OPT_IND:
            mac = ether_aton(opt_arg);
            if (mac)
                memcpy(dst_mac, mac, sizeof(dst_mac));
            else
                cmd_usage();
            break;
        case VRF_OPT_IND:
            vrf_id = strtoul(opt_arg, NULL, 0);
            if (errno) 
                usage();
            break;
        case TYPE_OPT_IND:
            type = strtoul(opt_arg, NULL, 0);
            if (errno) 
                usage();
            break;
        case SIP_OPT_IND:
            inet_aton(opt_arg, &sip);
            break;
        case DIP_OPT_IND:
            inet_aton(opt_arg, &dip);
            break;
        case SPORT_OPT_IND:
            sport = strtoul(opt_arg, NULL, 0);
            if (errno) 
                usage();
            break;
        case CNI_OPT_IND:
            comp_nh[comp_nh_ind++] = strtoul(opt_arg, NULL, 0);
            if (errno)
                usage();
            break;
        case LBL_OPT_IND:
            lbl[lbl_ind++] = strtoul(opt_arg, NULL, 0);
            if (errno)
                usage();
        case DPORT_OPT_IND:
            dport = strtoul(opt_arg, NULL, 0);
            if (errno) 
                usage();
    }
}
Exemple #6
0
/* Modify memory.
 *
 * Syntax:
 *	mm{.b, .w, .l} {addr}
 *	nm{.b, .w, .l} {addr}
 */
static int
mod_mem(cmd_tbl_t *cmdtp, int incrflag, int flag, int argc, char * const argv[])
{
	ulong	addr, i;
	int	nbytes, size;
	extern char console_buffer[];

	if (argc != 2)
		return cmd_usage(cmdtp);

#ifdef CONFIG_BOOT_RETRY_TIME
	reset_cmd_timeout();	/* got a good command to get here */
#endif
	/* We use the last specified parameters, unless new ones are
	 * entered.
	 */
	addr = mm_last_addr;
	size = mm_last_size;

	if ((flag & CMD_FLAG_REPEAT) == 0) {
		/* New command specified.  Check for a size specification.
		 * Defaults to long if no or incorrect specification.
		 */
		if ((size = cmd_get_data_size(argv[0], 4)) < 0)
			return 1;

		/* Address is specified since argc > 1
		*/
		addr = simple_strtoul(argv[1], NULL, 16);
		addr += base_address;
	}

#ifdef CONFIG_HAS_DATAFLASH
	if (addr_dataflash(addr)){
		puts ("Can't modify DataFlash in place. Use cp instead.\n\r");
		return 0;
	}
#endif

#ifdef CONFIG_BLACKFIN
	if (addr_bfin_on_chip_mem(addr)) {
		puts ("Can't modify L1 instruction in place. Use cp instead.\n\r");
		return 0;
	}
#endif

	/* Print the address, followed by value.  Then accept input for
	 * the next value.  A non-converted value exits.
	 */
	do {
		printf("%08lx:", addr);
		if (size == 4)
			printf(" %08x", *((uint   *)addr));
		else if (size == 2)
			printf(" %04x", *((ushort *)addr));
		else
			printf(" %02x", *((u_char *)addr));

		nbytes = readline (" ? ");
		if (nbytes == 0 || (nbytes == 1 && console_buffer[0] == '-')) {
			/* <CR> pressed as only input, don't modify current
			 * location and move to next. "-" pressed will go back.
			 */
			if (incrflag)
				addr += nbytes ? -size : size;
			nbytes = 1;
#ifdef CONFIG_BOOT_RETRY_TIME
			reset_cmd_timeout(); /* good enough to not time out */
#endif
		}
#ifdef CONFIG_BOOT_RETRY_TIME
		else if (nbytes == -2) {
			break;	/* timed out, exit the command	*/
		}
#endif
		else {
			char *endp;
			i = simple_strtoul(console_buffer, &endp, 16);
			nbytes = endp - console_buffer;
			if (nbytes) {
#ifdef CONFIG_BOOT_RETRY_TIME
				/* good enough to not time out
				 */
				reset_cmd_timeout();
#endif
				if (size == 4)
					*((uint   *)addr) = i;
				else if (size == 2)
					*((ushort *)addr) = i;
				else
					*((u_char *)addr) = i;
				if (incrflag)
					addr += size;
			}
		}
	} while (nbytes);

	mm_last_addr = addr;
	mm_last_size = size;
	return 0;
}
Exemple #7
0
int do_data(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
{
	int i, dev, ret = 0;
	ulong addr;
	loff_t off, size;
	char *cmd, *s;
	char	str[128];

	cmd = argv[1];
	if (argc < 3)
		goto usage;
	
	if (get_off_size(argc - 2, argv + 2,  &off, &size) != 0)
		return 1;

	printk("erase data : %s %d  off =%llx ,size=%llx\n",__func__,__LINE__, off, size);
	
	if (strcmp(cmd, "erase") == 0){

		printk(" %s %d\n",__func__,__LINE__);
		if(POR_NAND_BOOT()){
			printk("NAND BOOT,nand_env_relocate_spec : %s %d \n",__func__,__LINE__);
			if(size == 0){
				sprintf(str, "nand erase 0x%llx", off);
				printf("command:	%s\n", str);
				run_command("nand device 1",0);
				run_command(str, 0);
			}else{
				sprintf(str, "nand erase 0x%llx 0x%llx", off, size);
				printf("command:    %s\n", str);
				run_command("nand device 1",0);
				run_command(str, 0);
			}
			printk("nand erase data \n");
		}else if(POR_EMMC_BOOT()) {
			printk("MMC BOOT, %s %d \n",__func__,__LINE__);
			if(size == 0){
				run_command("mmc erase 1", 0);
			}
			printk("mmc erase data \n");
		}else{
			ret = run_command("nand exist", 0);
			printk("do_data else: %s %d , nand exist ret %d\n",__func__,__LINE__, ret);
			if(!run_command("nand exist", 0)){
				if(size == 0){
					sprintf(str, "nand erase 0x%llx", off);
					printf("command:	%s\n", str);
					run_command(str, 0);
				}else{
					sprintf(str, "nand erase 0x%llx 0x%llx", off, size);
					printf("command:	%s\n", str);
					run_command(str, 0);
				}
				printk("nand erase data \n");
			}else if(!run_command("mmcinfo 1", 0)){
				if(size == 0){
					run_command("mmc erase 1", 0);
				}
				printk("mmc erase data \n");
			}
		}
		
	}else{
		goto usage;
	}

	return ret;
	
usage:
	cmd_usage(cmdtp);
	return 1;
}
/*
 * env import [-d] [-t | -b | -c] addr [size]
 *	-d:	delete existing environment before importing;
 *		otherwise overwrite / append to existion definitions
 *	-t:	assume text format; either "size" must be given or the
 *		text data must be '\0' terminated
 *	-b:	assume binary format ('\0' separated, "\0\0" terminated)
 *	-c:	assume checksum protected environment format
 *	addr:	memory address to read from
 *	size:	length of input data; if missing, proper '\0'
 *		termination is mandatory
 */
static int do_env_import(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
	char	*cmd, *addr;
	char	sep = '\n';
	int	chk = 0;
	int	fmt = 0;
	int	del = 0;
	size_t	size;

	cmd = *argv;

	while (--argc > 0 && **++argv == '-') {
		char *arg = *argv;
		while (*++arg) {
			switch (*arg) {
			case 'b':		/* raw binary format */
				if (fmt++)
					goto sep_err;
				sep = '\0';
				break;
			case 'c':		/* external checksum format */
				if (fmt++)
					goto sep_err;
				sep = '\0';
				chk = 1;
				break;
			case 't':		/* text format */
				if (fmt++)
					goto sep_err;
				sep = '\n';
				break;
			case 'd':
				del = 1;
				break;
			default:
				return cmd_usage(cmdtp);
			}
		}
	}

	if (argc < 1)
		return cmd_usage(cmdtp);

	if (!fmt)
		printf("## Warning: defaulting to text format\n");

	addr = (char *)simple_strtoul(argv[0], NULL, 16);

	if (argc == 2) {
		size = simple_strtoul(argv[1], NULL, 16);
	} else {
		char *s = addr;

		size = 0;

		while (size < MAX_ENV_SIZE) {
			if ((*s == sep) && (*(s+1) == '\0'))
				break;
			++s;
			++size;
		}
		if (size == MAX_ENV_SIZE) {
			printf("## Warning: Input data exceeds %d bytes"
				" - truncated\n", MAX_ENV_SIZE);
		}
		++size;
		printf("## Info: input data size = %zd = 0x%zX\n", size, size);
	}

	if (chk) {
		uint32_t crc;
		env_t *ep = (env_t *)addr;

		size -= offsetof(env_t, data);
		memcpy(&crc, &ep->crc, sizeof(crc));

		if (crc32(0, ep->data, size) != crc) {
			puts("## Error: bad CRC, import failed\n");
			return 1;
		}
		addr = (char *)ep->data;
	}

	if (himport_r(&env_htab, addr, size, sep, del ? 0 : H_NOCLEAR) == 0) {
		error("Environment import failed: errno = %d\n", errno);
		return 1;
	}
	gd->flags |= GD_FLG_ENV_READY;

	return 0;

sep_err:
	printf("## %s: only one of \"-b\", \"-c\" or \"-t\" allowed\n",
		cmd);
	return 1;
}
static int do_vbexport_test_diskrw(cmd_tbl_t *cmdtp, int flag,
		int argc, char * const argv[])
{
	int ret = 0;
	VbDiskInfo *disk_info;
	VbExDiskHandle_t handle;
	uint32_t disk_count, test_lba_count, buf_byte_count, i;
	uint8_t *original_buf, *target_buf, *verify_buf;
	uint64_t t0, t1;

	switch (argc) {
	case 1:  /* if no argument given, use the default lba count */
		test_lba_count = DEFAULT_TEST_LBA_COUNT;
		break;
	case 2:  /* use argument */
		test_lba_count = simple_strtoul(argv[1], NULL, 10);
		if (!test_lba_count) {
			VbExDebug("The first argument is not a number!\n");
			return cmd_usage(cmdtp);
		}
		break;
	default:
		return cmd_usage(cmdtp);
	}

	/* We perform read/write operations on the first internal disk. */
	if (VbExDiskGetInfo(&disk_info, &disk_count, VB_DISK_FLAG_FIXED) ||
			disk_count == 0) {
		VbExDebug("No internal disk found!\n");
		return 1;
	}
	handle = disk_info[0].handle;
	buf_byte_count = disk_info[0].bytes_per_lba * test_lba_count;
	VbExDiskFreeInfo(disk_info, handle);

	/* Allocate the buffer and fill the target test pattern. */
	original_buf = VbExMalloc(buf_byte_count);
	target_buf = VbExMalloc(buf_byte_count);
	verify_buf = VbExMalloc(buf_byte_count);

	/* Fill the target test pattern. */
	for (i = 0; i < buf_byte_count; i++)
		target_buf[i] = i & 0xff;

	t0 = VbExGetTimer();
	if (VbExDiskRead(handle, TEST_LBA_START, test_lba_count,
			original_buf)) {
		VbExDebug("Failed to read disk.\n");
		goto out;
	}
	t1 = VbExGetTimer();
	VbExDebug("test_diskrw: disk_read, lba_count: %u, time: %llu\n",
			test_lba_count, t1 - t0);

	t0 = VbExGetTimer();
	ret = VbExDiskWrite(handle, TEST_LBA_START, test_lba_count, target_buf);
	t1 = VbExGetTimer();
	VbExDebug("test_diskrw: disk_write, lba_count: %u, time: %llu\n",
			test_lba_count, t1 - t0);

	if (ret) {
		VbExDebug("Failed to write disk.\n");
		ret = 1;
	} else {
		/* Read back and verify the data. */
		VbExDiskRead(handle, TEST_LBA_START, test_lba_count,
				verify_buf);
		if (memcmp(target_buf, verify_buf, buf_byte_count) != 0) {
			VbExDebug("Verify failed. The target data wrote "
					"wrong.\n");
			ret = 1;
		}
	}

	/* Write the original data back. */
	if (VbExDiskWrite(handle, TEST_LBA_START, test_lba_count,
			original_buf)) {
		VbExDebug("Failed to write the original data back. The disk "
				"may now be corrupt.\n");
	}

out:
	VbExDiskFreeInfo(disk_info, NULL);

	VbExFree(original_buf);
	VbExFree(target_buf);
	VbExFree(verify_buf);

	if (ret == 0)
		VbExDebug("Read and write disk test SUCCESS.\n");

	return ret;
}
int do_mem_cp ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
{
	ulong	addr, dest, count;
	int	size;

	if (argc != 4) {
		cmd_usage(cmdtp);
		return 1;
	}

	/* Check for size specification.
	*/
	if ((size = cmd_get_data_size(argv[0], 4)) < 0)
		return 1;

	addr = simple_strtoul(argv[1], NULL, 16);
	addr += base_address;

	dest = simple_strtoul(argv[2], NULL, 16);
	dest += base_address;

	count = simple_strtoul(argv[3], NULL, 16);

	if (count == 0) {
		puts ("Zero length ???\n");
		return 1;
	}

#ifndef CONFIG_SYS_NO_FLASH
	/* check if we are copying to Flash */
	if ( (addr2info(dest) != NULL)
#ifdef CONFIG_HAS_DATAFLASH
	   && (!addr_dataflash(dest))
#endif
	   ) {
		int rc;

		puts ("Copy to Flash... ");

		rc = flash_write ((char *)addr, dest, count*size);
		if (rc != 0) {
			flash_perror (rc);
			return (1);
		}
		puts ("done\n");
		return 0;
	}
#endif

#if defined(CONFIG_CMD_MMC)
	if (mmc2info(dest)) {
		int rc;

		puts ("Copy to MMC... ");
		switch (rc = mmc_write ((uchar *)addr, dest, count*size)) {
		case 0:
			putc ('\n');
			return 1;
		case -1:
			puts ("failed\n");
			return 1;
		default:
			printf ("%s[%d] FIXME: rc=%d\n",__FILE__,__LINE__,rc);
			return 1;
		}
		puts ("done\n");
		return 0;
	}

	if (mmc2info(addr)) {
		int rc;

		puts ("Copy from MMC... ");
		switch (rc = mmc_read (addr, (uchar *)dest, count*size)) {
		case 0:
			putc ('\n');
			return 1;
		case -1:
			puts ("failed\n");
			return 1;
		default:
			printf ("%s[%d] FIXME: rc=%d\n",__FILE__,__LINE__,rc);
			return 1;
		}
		puts ("done\n");
		return 0;
	}
#endif

#ifdef CONFIG_HAS_DATAFLASH
	/* Check if we are copying from RAM or Flash to DataFlash */
	if (addr_dataflash(dest) && !addr_dataflash(addr)){
		int rc;

		puts ("Copy to DataFlash... ");

		rc = write_dataflash (dest, addr, count*size);

		if (rc != 1) {
			dataflash_perror (rc);
			return (1);
		}
		puts ("done\n");
		return 0;
	}

	/* Check if we are copying from DataFlash to RAM */
	if (addr_dataflash(addr) && !addr_dataflash(dest)
#ifndef CONFIG_SYS_NO_FLASH
				 && (addr2info(dest) == NULL)
#endif
	   ){
		int rc;
		rc = read_dataflash(addr, count * size, (char *) dest);
		if (rc != 1) {
			dataflash_perror (rc);
			return (1);
		}
		return 0;
	}

	if (addr_dataflash(addr) && addr_dataflash(dest)){
		puts ("Unsupported combination of source/destination.\n\r");
		return 1;
	}
#endif

#ifdef CONFIG_BLACKFIN
	/* See if we're copying to/from L1 inst */
	if (addr_bfin_on_chip_mem(dest) || addr_bfin_on_chip_mem(addr)) {
		memcpy((void *)dest, (void *)addr, count * size);
		return 0;
	}
#endif

	while (count-- > 0) {
		if (size == 4)
			*((ulong  *)dest) = *((ulong  *)addr);
		else if (size == 2)
			*((ushort *)dest) = *((ushort *)addr);
		else
			*((u_char *)dest) = *((u_char *)addr);
		addr += size;
		dest += size;
	}
	return 0;
}
Exemple #11
0
/* Modify memory.
 *
 * Syntax:
 *	evb440spe wrclk prom0,prom1
 */
static int setBootStrapClock(cmd_tbl_t *cmdtp, int incrflag, int flag,
		int argc, char * const argv[])
{
	uchar	chip;
	ulong	data;
	int	nbytes;
	extern char console_buffer[];

	char sysClock[4];
	char cpuClock[4];
	char plbClock[4];
	char pcixClock[4];

	if (argc < 3)
		return cmd_usage(cmdtp);

	if (strcmp(argv[2], "prom0") == 0)
		chip = IIC0_BOOTPROM_ADDR;
	else
		chip = IIC0_ALT_BOOTPROM_ADDR;

	do {
		printf("enter sys clock frequency 33 or 66 MHz or quit to abort\n");
		nbytes = readline (" ? ");

		if (strcmp(console_buffer, "quit") == 0)
			return 0;

		if ((strcmp(console_buffer, "33") != 0) &
				(strcmp(console_buffer, "66") != 0))
			nbytes=0;

		strcpy(sysClock, console_buffer);

	} while (nbytes == 0);

	do {
		if (strcmp(sysClock, "66") == 0) {
			printf("enter cpu clock frequency 400, 533 MHz or quit to abort\n");
		} else {
#ifdef	CONFIG_STRESS
			printf("enter cpu clock frequency 400, 500, 533, 667 MHz or quit to abort\n");
#else
			printf("enter cpu clock frequency 400, 500, 533 MHz or quit to abort\n");
#endif
		}
		nbytes = readline (" ? ");

		if (strcmp(console_buffer, "quit") == 0)
			return 0;

		if (strcmp(sysClock, "66") == 0) {
			if ((strcmp(console_buffer, "400") != 0) &
					(strcmp(console_buffer, "533") != 0)
#ifdef	CONFIG_STRESS
					& (strcmp(console_buffer, "667") != 0)
#endif
			   ) {
				nbytes = 0;
			}
		} else {
			if ((strcmp(console_buffer, "400") != 0) &
					(strcmp(console_buffer, "500") != 0) &
					(strcmp(console_buffer, "533") != 0)
#ifdef	CONFIG_STRESS
					& (strcmp(console_buffer, "667") != 0)
#endif
			   ) {
				nbytes = 0;
			}
		}

		strcpy(cpuClock, console_buffer);

	} while (nbytes == 0);

	if (strcmp(cpuClock, "500") == 0){
		strcpy(plbClock, "166");
	} else if (strcmp(cpuClock, "533") == 0){
		strcpy(plbClock, "133");
	} else {
		do {
			if (strcmp(cpuClock, "400") == 0)
				printf("enter plb clock frequency 100, 133 MHz or quit to abort\n");

#ifdef	CONFIG_STRESS
			if (strcmp(cpuClock, "667") == 0)
				printf("enter plb clock frequency 133, 166 MHz or quit to abort\n");

#endif
			nbytes = readline (" ? ");

			if (strcmp(console_buffer, "quit") == 0)
				return 0;

			if (strcmp(cpuClock, "400") == 0) {
				if ((strcmp(console_buffer, "100") != 0) &
						(strcmp(console_buffer, "133") != 0))
					nbytes = 0;
			}
#ifdef	CONFIG_STRESS
			if (strcmp(cpuClock, "667") == 0) {
				if ((strcmp(console_buffer, "133") != 0) &
						(strcmp(console_buffer, "166") != 0))
					nbytes = 0;
			}
#endif
			strcpy(plbClock, console_buffer);

		} while (nbytes == 0);
	}

	do {
		printf("enter Pci-X clock frequency 33, 66, 100 or 133 MHz or quit to abort\n");
		nbytes = readline (" ? ");

		if (strcmp(console_buffer, "quit") == 0)
			return 0;

		if ((strcmp(console_buffer, "33") != 0) &
				(strcmp(console_buffer, "66") != 0) &
				(strcmp(console_buffer, "100") != 0) &
				(strcmp(console_buffer, "133") != 0)) {
			nbytes = 0;
		}
		strcpy(pcixClock, console_buffer);

	} while (nbytes == 0);

	printf("\nsys clk   = %s MHz\n", sysClock);
	printf("cpu clk   = %s MHz\n", cpuClock);
	printf("plb clk   = %s MHz\n", plbClock);
	printf("Pci-X clk = %s MHz\n", pcixClock);

	do {
		printf("\npress [y] to write I2C bootstrap \n");
		printf("or [n] to abort.  \n");
		printf("Don't forget to set board switches \n");
		printf("according to your choice before re-starting \n");
		printf("(refer to 440spe_uboot_kit_um_1_01.pdf) \n");

		nbytes = readline (" ? ");
		if (strcmp(console_buffer, "n") == 0)
			return 0;

	} while (nbytes == 0);

	if (strcmp(sysClock, "33") == 0) {
		if ((strcmp(cpuClock, "400") == 0) &
				(strcmp(plbClock, "100") == 0))
			data = 0x8678c206;

		if ((strcmp(cpuClock, "400") == 0) &
				(strcmp(plbClock, "133") == 0))
			data = 0x8678c2c6;

		if ((strcmp(cpuClock, "500") == 0))
			data = 0x8778f2c6;

		if ((strcmp(cpuClock, "533") == 0))
			data = 0x87790252;

#ifdef	CONFIG_STRESS
		if ((strcmp(cpuClock, "667") == 0) &
				(strcmp(plbClock, "133") == 0))
			data = 0x87794256;

		if ((strcmp(cpuClock, "667") == 0) &
				(strcmp(plbClock, "166") == 0))
			data = 0x87794206;

#endif
	}
	if (strcmp(sysClock, "66") == 0) {
		if ((strcmp(cpuClock, "400") == 0) &
				(strcmp(plbClock, "100") == 0))
			data = 0x84706206;

		if ((strcmp(cpuClock, "400") == 0) &
				(strcmp(plbClock, "133") == 0))
			data = 0x847062c6;

		if ((strcmp(cpuClock, "533") == 0))
			data = 0x85708206;

#ifdef	CONFIG_STRESS
		if ((strcmp(cpuClock, "667") == 0) &
				(strcmp(plbClock, "133") == 0))
			data = 0x8570a256;

		if ((strcmp(cpuClock, "667") == 0) &
				(strcmp(plbClock, "166") == 0))
			data = 0x8570a206;

#endif
	}

#ifdef	DEBUG
	printf(" pin strap0 to write in i2c  = %x\n", data);
#endif	/* DEBUG */

	if (i2c_write(chip, 0, 1, (uchar *)&data, 4) != 0)
		printf("Error writing strap0 in %s\n", argv[2]);

	if (strcmp(pcixClock, "33") == 0)
		data = 0x00000701;

	if (strcmp(pcixClock, "66") == 0)
		data = 0x00000601;

	if (strcmp(pcixClock, "100") == 0)
		data = 0x00000501;

	if (strcmp(pcixClock, "133") == 0)
		data = 0x00000401;

	if (strcmp(plbClock, "166") == 0)
		data = data | 0x05950000;
	else
		data = data | 0x05A50000;

#ifdef	DEBUG
	printf(" pin strap1 to write in i2c  = %x\n", data);
#endif	/* DEBUG */

	udelay(1000);
	if (i2c_write(chip, 4, 1, (uchar *)&data, 4) != 0)
		printf("Error writing strap1 in %s\n", argv[2]);

	return 0;
}
Exemple #12
0
/****************************************************************************
 * main routine do_fdcboot
 */
int do_fdcboot (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
	FD_GEO_STRUCT *pFG = (FD_GEO_STRUCT *)floppy_type;
	FDC_COMMAND_STRUCT *pCMD = &cmd;
	unsigned long addr,imsize;
	image_header_t *hdr;  /* used for fdc boot */
	unsigned char boot_drive;
	int i,nrofblk;
	char *ep;
	int rcode = 0;
#if defined(CONFIG_FIT)
	const void *fit_hdr = NULL;
#endif

	switch (argc) {
	case 1:
		addr = CONFIG_SYS_LOAD_ADDR;
		boot_drive=CONFIG_SYS_FDC_DRIVE_NUMBER;
		break;
	case 2:
		addr = simple_strtoul(argv[1], NULL, 16);
		boot_drive=CONFIG_SYS_FDC_DRIVE_NUMBER;
		break;
	case 3:
		addr = simple_strtoul(argv[1], NULL, 16);
		boot_drive=simple_strtoul(argv[2], NULL, 10);
		break;
	default:
		return cmd_usage(cmdtp);
	}
	/* setup FDC and scan for drives  */
	if(fdc_setup(boot_drive,pCMD,pFG)==FALSE) {
		printf("\n** Error in setup FDC **\n");
		return 1;
	}
	if(fdc_check_drive(pCMD,pFG)==FALSE) {
		printf("\n** Error in check_drives **\n");
		return 1;
	}
	if((pCMD->flags&(1<<boot_drive))==0) {
		/* drive not available */
		printf("\n** Drive %d not availabe **\n",boot_drive);
		return 1;
	}
	if((pCMD->flags&(0x10<<boot_drive))==0) {
		/* no disk inserted */
		printf("\n** No disk inserted in drive %d **\n",boot_drive);
		return 1;
	}
	/* ok, we have a valid source */
	pCMD->drive=boot_drive;
	/* read first block */
	pCMD->blnr=0;
	if(fdc_read_data((unsigned char *)addr,1,pCMD,pFG)==FALSE) {
		printf("\nRead error:");
		for(i=0;i<7;i++)
			printf("result%d: 0x%02X\n",i,pCMD->result[i]);
		return 1;
	}

	switch (genimg_get_format ((void *)addr)) {
	case IMAGE_FORMAT_LEGACY:
		hdr = (image_header_t *)addr;
		image_print_contents (hdr);

		imsize = image_get_image_size (hdr);
		break;
#if defined(CONFIG_FIT)
	case IMAGE_FORMAT_FIT:
		fit_hdr = (const void *)addr;
		puts ("Fit image detected...\n");

		imsize = fit_get_size (fit_hdr);
		break;
#endif
	default:
		puts ("** Unknown image type\n");
		return 1;
	}

	nrofblk=imsize/512;
	if((imsize%512)>0)
		nrofblk++;
	printf("Loading %ld Bytes (%d blocks) at 0x%08lx..\n",imsize,nrofblk,addr);
	pCMD->blnr=0;
	if(fdc_read_data((unsigned char *)addr,nrofblk,pCMD,pFG)==FALSE) {
		/* read image block */
		printf("\nRead error:");
		for(i=0;i<7;i++)
			printf("result%d: 0x%02X\n",i,pCMD->result[i]);
		return 1;
	}
	printf("OK %ld Bytes loaded.\n",imsize);

	flush_cache (addr, imsize);

#if defined(CONFIG_FIT)
	/* This cannot be done earlier, we need complete FIT image in RAM first */
	if (genimg_get_format ((void *)addr) == IMAGE_FORMAT_FIT) {
		if (!fit_check_format (fit_hdr)) {
			puts ("** Bad FIT image format\n");
			return 1;
		}
		fit_print_contents (fit_hdr);
	}
#endif

	/* Loading ok, update default load address */
	load_addr = addr;

	/* Check if we should attempt an auto-start */
	if (((ep = getenv("autostart")) != NULL) && (strcmp(ep,"yes") == 0)) {
		char *local_args[2];

		local_args[0] = argv[0];
		local_args[1] = NULL;

		printf ("Automatic boot of image at addr 0x%08lX ...\n", addr);

		do_bootm (cmdtp, 0, 1, local_args);
		rcode ++;
	}
	return rcode;
}
int do_eeprom ( cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
{
	const char *const fmt =
		"\nEEPROM @0x%lX %s: addr %08lx  off %04lx  count %ld ... ";

#if defined(CONFIG_SYS_I2C_MULTI_EEPROMS)
	if (argc == 6) {
		ulong dev_addr = simple_strtoul (argv[2], NULL, 16);
		ulong addr = simple_strtoul (argv[3], NULL, 16);
		ulong off  = simple_strtoul (argv[4], NULL, 16);
		ulong cnt  = simple_strtoul (argv[5], NULL, 16);
#else
	if (argc == 5) {
		ulong dev_addr = CONFIG_SYS_DEF_EEPROM_ADDR;
		ulong addr = simple_strtoul (argv[2], NULL, 16);
		ulong off  = simple_strtoul (argv[3], NULL, 16);
		ulong cnt  = simple_strtoul (argv[4], NULL, 16);
#endif /* CONFIG_SYS_I2C_MULTI_EEPROMS */

# ifndef CONFIG_SPI
		eeprom_init ();
# endif /* !CONFIG_SPI */

		if (strcmp (argv[1], "read") == 0) {
			int rcode;

			printf (fmt, dev_addr, argv[1], addr, off, cnt);

			rcode = eeprom_read (dev_addr, off, (uchar *) addr, cnt);

			puts ("done\n");
			return rcode;
		} else if (strcmp (argv[1], "write") == 0) {
			int rcode;

			printf (fmt, dev_addr, argv[1], addr, off, cnt);

			rcode = eeprom_write (dev_addr, off, (uchar *) addr, cnt);

			puts ("done\n");
			return rcode;
		}
	}

	cmd_usage(cmdtp);
	return 1;
}
#endif

/*-----------------------------------------------------------------------
 *
 * for CONFIG_SYS_I2C_EEPROM_ADDR_LEN == 2 (16-bit EEPROM address) offset is
 *   0x000nxxxx for EEPROM address selectors at n, offset xxxx in EEPROM.
 *
 * for CONFIG_SYS_I2C_EEPROM_ADDR_LEN == 1 (8-bit EEPROM page address) offset is
 *   0x00000nxx for EEPROM address selectors and page number at n.
 */

#ifndef CONFIG_SPI
#if !defined(CONFIG_SYS_I2C_EEPROM_ADDR_LEN) || CONFIG_SYS_I2C_EEPROM_ADDR_LEN < 1 || CONFIG_SYS_I2C_EEPROM_ADDR_LEN > 2
#error CONFIG_SYS_I2C_EEPROM_ADDR_LEN must be 1 or 2
#endif
#endif

int eeprom_read (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cnt)
{
	unsigned end = offset + cnt;
	unsigned blk_off;
	int rcode = 0;

	/* Read data until done or would cross a page boundary.
	 * We must write the address again when changing pages
	 * because the next page may be in a different device.
	 */
	while (offset < end) {
		unsigned alen, len;
#if !defined(CONFIG_SYS_I2C_FRAM)
		unsigned maxlen;
#endif

#if CONFIG_SYS_I2C_EEPROM_ADDR_LEN == 1 && !defined(CONFIG_SPI_X)
		uchar addr[2];

		blk_off = offset & 0xFF;	/* block offset */

		addr[0] = offset >> 8;		/* block number */
		addr[1] = blk_off;		/* block offset */
		alen	= 2;
#else
		uchar addr[3];

		blk_off = offset & 0xFF;	/* block offset */

		addr[0] = offset >> 16;		/* block number */
		addr[1] = offset >>  8;		/* upper address octet */
		addr[2] = blk_off;		/* lower address octet */
		alen	= 3;
#endif	/* CONFIG_SYS_I2C_EEPROM_ADDR_LEN, CONFIG_SPI_X */

		addr[0] |= dev_addr;		/* insert device address */

		len = end - offset;

		/*
		 * For a FRAM device there is no limit on the number of the
		 * bytes that can be ccessed with the single read or write
		 * operation.
		 */
#if !defined(CONFIG_SYS_I2C_FRAM)
		maxlen = 0x100 - blk_off;
		if (maxlen > I2C_RXTX_LEN)
			maxlen = I2C_RXTX_LEN;
		if (len > maxlen)
			len = maxlen;
#endif

#ifdef CONFIG_SPI
		spi_read (addr, alen, buffer, len);
#else
		if (i2c_read (addr[0], offset, alen-1, buffer, len) != 0)
			rcode = 1;
#endif
		buffer += len;
		offset += len;
	}

	return rcode;
}
Exemple #14
0
static int do_zfs_load(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
{
    char *filename = NULL;
    char *ep;
    int dev;
    unsigned long part = 1;
    ulong addr = 0;
    ulong part_length;
    disk_partition_t info;
    char buf[12];
    unsigned long count;
    const char *addr_str;
    struct zfs_file zfile;
    struct device_s vdev;

    if (argc < 3)
        return CMD_RET_USAGE;

    count = 0;
    addr = simple_strtoul(argv[3], NULL, 16);
    filename = getenv("bootfile");
    switch (argc) {
    case 3:
        addr_str = getenv("loadaddr");
        if (addr_str != NULL)
            addr = simple_strtoul(addr_str, NULL, 16);
        else
            addr = CONFIG_SYS_LOAD_ADDR;

        break;
    case 4:
        break;
    case 5:
        filename = argv[4];
        break;
    case 6:
        filename = argv[4];
        count = simple_strtoul(argv[5], NULL, 16);
        break;

    default:
        return cmd_usage(cmdtp);
    }

    if (!filename) {
        puts("** No boot file defined **\n");
        return 1;
    }

    dev = (int)simple_strtoul(argv[2], &ep, 16);
    zfs_dev_desc = get_dev(argv[1], dev);
    if (zfs_dev_desc == NULL) {
        printf("** Block device %s %d not supported\n", argv[1], dev);
        return 1;
    }

    if (*ep) {
        if (*ep != ':') {
            puts("** Invalid boot device, use `dev[:part]' **\n");
            return 1;
        }
        part = simple_strtoul(++ep, NULL, 16);
    }

    if (part != 0) {
        if (get_partition_info(zfs_dev_desc, part, &info)) {
            printf("** Bad partition %lu **\n", part);
            return 1;
        }

        if (strncmp((char *)info.type, BOOT_PART_TYPE,
                    strlen(BOOT_PART_TYPE)) != 0) {
            printf("** Invalid partition type \"%s\" (expect \"" BOOT_PART_TYPE "\")\n",
                   info.type);
            return 1;
        }
        printf("Loading file \"%s\" "
               "from %s device %d:%lu %s\n",
               filename, argv[1], dev, part, info.name);
    } else {
        printf("Loading file \"%s\" from %s device %d\n",
               filename, argv[1], dev);
    }

    part_length = zfs_set_blk_dev(zfs_dev_desc, part);
    if (part_length == 0) {
        printf("**Bad partition - %s %d:%lu **\n", argv[1], dev, part);
        return 1;
    }

    vdev.part_length = part_length;

    memset(&zfile, 0, sizeof(zfile));
    zfile.device = &vdev;
    if (zfs_open(&zfile, filename)) {
        printf("** File not found %s\n", filename);
        return 1;
    }

    if ((count < zfile.size) && (count != 0))
        zfile.size = (uint64_t)count;

    if (zfs_read(&zfile, (char *)addr, zfile.size) != zfile.size) {
        printf("** Unable to read \"%s\" from %s %d:%lu **\n",
               filename, argv[1], dev, part);
        zfs_close(&zfile);
        return 1;
    }

    zfs_close(&zfile);

    /* Loading ok, update default load address */
    load_addr = addr;

    printf("%llu bytes read\n", zfile.size);
    sprintf(buf, "%llX", zfile.size);
    setenv("filesize", buf);

    return 0;
}
Exemple #15
0
int do_mem_loopw (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
	ulong	addr, length, i, data;
	int	size;
	volatile uint	*longp;
	volatile ushort *shortp;
	volatile u_char	*cp;

	if (argc < 4)
		return cmd_usage(cmdtp);

	/* Check for a size spefication.
	 * Defaults to long if no or incorrect specification.
	 */
	if ((size = cmd_get_data_size(argv[0], 4)) < 0)
		return 1;

	/* Address is always specified.
	*/
	addr = simple_strtoul(argv[1], NULL, 16);

	/* Length is the number of objects, not number of bytes.
	*/
	length = simple_strtoul(argv[2], NULL, 16);

	/* data to write */
	data = simple_strtoul(argv[3], NULL, 16);

	/* We want to optimize the loops to run as fast as possible.
	 * If we have only one object, just run infinite loops.
	 */
	if (length == 1) {
		if (size == 4) {
			longp = (uint *)addr;
			for (;;)
				*longp = data;
					}
		if (size == 2) {
			shortp = (ushort *)addr;
			for (;;)
				*shortp = data;
		}
		cp = (u_char *)addr;
		for (;;)
			*cp = data;
	}

	if (size == 4) {
		for (;;) {
			longp = (uint *)addr;
			i = length;
			while (i-- > 0)
				*longp++ = data;
		}
	}
	if (size == 2) {
		for (;;) {
			shortp = (ushort *)addr;
			i = length;
			while (i-- > 0)
				*shortp++ = data;
		}
	}
	for (;;) {
		cp = (u_char *)addr;
		i = length;
		while (i-- > 0)
			*cp++ = data;
	}
}
Exemple #16
0
static int do_zfs_load(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
	char *filename = NULL;
	int dev;
	int part;
	ulong addr = 0;
	disk_partition_t info;
	block_dev_desc_t *dev_desc;
	char buf[12];
	unsigned long count;
	const char *addr_str;
	struct zfs_file zfile;
	struct device_s vdev;

	if (argc < 3)
		return CMD_RET_USAGE;

	count = 0;
	addr = simple_strtoul(argv[3], NULL, 16);
	filename = getenv("bootfile");
	switch (argc) {
	case 3:
		addr_str = getenv("loadaddr");
		if (addr_str != NULL)
			addr = simple_strtoul(addr_str, NULL, 16);
		else
			addr = CONFIG_SYS_LOAD_ADDR;

		break;
	case 4:
		break;
	case 5:
		filename = argv[4];
		break;
	case 6:
		filename = argv[4];
		count = simple_strtoul(argv[5], NULL, 16);
		break;

	default:
		return cmd_usage(cmdtp);
	}

	if (!filename) {
		puts("** No boot file defined **\n");
		return 1;
	}

	part = get_device_and_partition(argv[1], argv[2], &dev_desc, &info, 1);
	if (part < 0)
		return 1;

	dev = dev_desc->dev;
	printf("Loading file \"%s\" from %s device %d%c%c\n",
		filename, argv[1], dev,
		part ? ':' : ' ', part ? part + '0' : ' ');

	zfs_set_blk_dev(dev_desc, &info);
	vdev.part_length = info.size;

	memset(&zfile, 0, sizeof(zfile));
	zfile.device = &vdev;
	if (zfs_open(&zfile, filename)) {
		printf("** File not found %s\n", filename);
		return 1;
	}

	if ((count < zfile.size) && (count != 0))
		zfile.size = (uint64_t)count;

	if (zfs_read(&zfile, (char *)addr, zfile.size) != zfile.size) {
		printf("** Unable to read \"%s\" from %s %d:%d **\n",
			   filename, argv[1], dev, part);
		zfs_close(&zfile);
		return 1;
	}

	zfs_close(&zfile);

	/* Loading ok, update default load address */
	load_addr = addr;

	printf("%llu bytes read\n", zfile.size);
	setenv_hex("filesize", zfile.size);

	return 0;
}
Exemple #17
0
int do_mem_md ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
	ulong	addr, length;
#if defined(CONFIG_HAS_DATAFLASH)
	ulong	nbytes, linebytes;
#endif
	int	size;
	int rc = 0;

	/* We use the last specified parameters, unless new ones are
	 * entered.
	 */
	addr = dp_last_addr;
	size = dp_last_size;
	length = dp_last_length;

	if (argc < 2)
		return cmd_usage(cmdtp);

	if ((flag & CMD_FLAG_REPEAT) == 0) {
		/* New command specified.  Check for a size specification.
		 * Defaults to long if no or incorrect specification.
		 */
		if ((size = cmd_get_data_size(argv[0], 4)) < 0)
			return 1;

		/* Address is specified since argc > 1
		*/
		addr = simple_strtoul(argv[1], NULL, 16);
		addr += base_address;

		/* If another parameter, it is the length to display.
		 * Length is the number of objects, not number of bytes.
		 */
		if (argc > 2)
			length = simple_strtoul(argv[2], NULL, 16);
	}

#if defined(CONFIG_HAS_DATAFLASH)
	/* Print the lines.
	 *
	 * We buffer all read data, so we can make sure data is read only
	 * once, and all accesses are with the specified bus width.
	 */
	nbytes = length * size;
	do {
		char	linebuf[DISP_LINE_LEN];
		void* p;
		linebytes = (nbytes>DISP_LINE_LEN)?DISP_LINE_LEN:nbytes;

		rc = read_dataflash(addr, (linebytes/size)*size, linebuf);
		p = (rc == DATAFLASH_OK) ? linebuf : (void*)addr;
		print_buffer(addr, p, size, linebytes/size, DISP_LINE_LEN/size);

		nbytes -= linebytes;
		addr += linebytes;
		if (ctrlc()) {
			rc = 1;
			break;
		}
	} while (nbytes > 0);
#else

# if defined(CONFIG_BLACKFIN)
	/* See if we're trying to display L1 inst */
	if (addr_bfin_on_chip_mem(addr)) {
		char linebuf[DISP_LINE_LEN];
		ulong linebytes, nbytes = length * size;
		do {
			linebytes = (nbytes > DISP_LINE_LEN) ? DISP_LINE_LEN : nbytes;
			memcpy(linebuf, (void *)addr, linebytes);
			print_buffer(addr, linebuf, size, linebytes/size, DISP_LINE_LEN/size);

			nbytes -= linebytes;
			addr += linebytes;
			if (ctrlc()) {
				rc = 1;
				break;
			}
		} while (nbytes > 0);
	} else
# endif

	{
		/* Print the lines. */
		print_buffer(addr, (void*)addr, size, length, DISP_LINE_LEN/size);
		addr += size*length;
	}
#endif

	dp_last_addr = addr;
	dp_last_length = length;
	dp_last_size = size;
	return (rc);
}
Exemple #18
0
static int do_ubi(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
{
	size_t size = 0;
	ulong addr = 0;
	int err = 0;

	if (argc < 2) {
		cmd_usage(cmdtp);
		return 1;
	}

	if (strcmp(argv[1], "part") == 0) {
		/* Print current partition */
		if (argc == 2) {
			if (ubi_dev.type == DEV_TYPE_NONE) {
				printf("Error, no UBI device/partition selected!\n");
				return 1;
			}

			printf("%s Device %d: %s, partition %s\n", ubi_dev.dev_name,
			       ubi_dev.nr, ubi_dev.mtd_info->name, ubi_dev.part_name);
			return 0;
		}

		if (argc < 4) {
			cmd_usage(cmdtp);
			return 1;
		}

		/* todo: get dev number for NAND... */
		ubi_dev.nr = 0;

		/*
		 * Call ubi_exit() before re-initializing the UBI subsystem
		 */
		if (ubi_initialized) {
			ubi_exit();
			del_mtd_partitions(ubi_dev.mtd_info);
		}

		/*
		 * Check for nand|onenand selection
		 */
#if defined(CONFIG_CMD_NAND)
		if (strcmp(argv[2], "nand") == 0) {
			strcpy(ubi_dev.dev_name, "NAND");
			ubi_dev.type = DEV_TYPE_NAND;
			ubi_dev.mtd_info = &nand_info[ubi_dev.nr];
		}
#endif
#if defined(CONFIG_FLASH_CFI_MTD)
		if (strcmp(argv[2], "nor") == 0) {
			strcpy(ubi_dev.dev_name, "NOR");
			ubi_dev.type = DEV_TYPE_NOR;
			ubi_dev.mtd_info = get_mtd_device_nm(CFI_MTD_DEV_NAME);
		}
#endif
#if defined(CONFIG_CMD_ONENAND)
		if (strcmp(argv[2], "onenand") == 0) {
			strcpy(ubi_dev.dev_name, "OneNAND");
			ubi_dev.type = DEV_TYPE_ONENAND;
			ubi_dev.mtd_info = &onenand_mtd;
		}
#endif

		if (ubi_dev.type == DEV_TYPE_NONE) {
			printf("Error, no UBI device/partition selected!\n");
			return 1;
		}

		strcpy(ubi_dev.part_name, argv[3]);
		err = ubi_dev_scan(ubi_dev.mtd_info, ubi_dev.part_name);
		if (err) {
			printf("UBI init error %d\n", err);
			ubi_dev.type = DEV_TYPE_NONE;
			return err;
		}

		ubi = ubi_devices[0];

		return 0;
	}

	if ((strcmp(argv[1], "part") != 0) && (ubi_dev.type == DEV_TYPE_NONE)) {
		printf("Error, no UBI device/partition selected!\n");
		return 1;
	}

	if (strcmp(argv[1], "info") == 0) {
		int layout = 0;
		if (argc > 2 && !strncmp(argv[2], "l", 1))
			layout = 1;
		return ubi_info(layout);
	}

	if (strncmp(argv[1], "create", 6) == 0) {
		int dynamic = 1;	/* default: dynamic volume */

		/* Use maximum available size */
		size = 0;

		/* E.g., create volume size type */
		if (argc == 5) {
			if (strncmp(argv[4], "s", 1) == 0)
				dynamic = 0;
			else if (strncmp(argv[4], "d", 1) != 0) {
				printf("Incorrect type\n");
				return 1;
			}
			argc--;
		}
		/* E.g., create volume size */
		if (argc == 4) {
			size = simple_strtoul(argv[3], NULL, 16);
			argc--;
		}
		/* Use maximum available size */
		if (!size)
			size = ubi->avail_pebs * ubi->leb_size;
		/* E.g., create volume */
		if (argc == 3)
			return ubi_create_vol(argv[2], size, dynamic);
	}

	if (strncmp(argv[1], "remove", 6) == 0) {
		/* E.g., remove volume */
		if (argc == 3)
			return ubi_remove_vol(argv[2]);
	}

	if (strncmp(argv[1], "write", 5) == 0) {
		if (argc < 5) {
			printf("Please see usage\n");
			return 1;
		}

		addr = simple_strtoul(argv[2], NULL, 16);
		size = simple_strtoul(argv[4], NULL, 16);

		return ubi_volume_write(argv[3], (void *)addr, size);
	}

	if (strncmp(argv[1], "read", 4) == 0) {
		size = 0;

		/* E.g., read volume size */
		if (argc == 5) {
			size = simple_strtoul(argv[4], NULL, 16);
			argc--;
		}

		/* E.g., read volume */
		if (argc == 4) {
			addr = simple_strtoul(argv[2], NULL, 16);
			argc--;
		}

		if (argc == 3)
			return ubi_volume_read(argv[3], (char *)addr, size);
	}

	printf("Please see usage\n");
	return -1;
}
Exemple #19
0
/* update_mmc [dev no] <type> 'mem' 'addr' 'length' [load addr] */
int do_update_mmc(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
{
	block_dev_desc_t *desc;
	uint64_t dst_addr = 0, mem_len = 0;
	unsigned int mem_addr = 0;
	unsigned char *p;
	char cmd[32];
	lbaint_t blk, cnt;
	int ret, dev;

	if (6 > argc)
		goto usage;

	ret = get_device("mmc", argv[1], &desc);
	if (0 > ret) {
		printf ("** Not find device mmc.%s **\n", argv[1]);
		return 1;
	}

	dev = simple_strtoul (argv[1], NULL, 10);
	sprintf(cmd, "mmc dev %d", dev);
	if (0 > run_command(cmd, 0))	/* mmc device */
		return -1;

	if (0 != strcmp(argv[2], "2ndboot")  &&
		0 != strcmp(argv[2], "boot") &&
		0 != strcmp(argv[2], "raw")  &&
		0 != strcmp(argv[2], "part"))
		goto usage;

	mem_addr = simple_strtoul (argv[3], NULL, 16);
	dst_addr = simple_strtoull(argv[4], NULL, 16);
	mem_len  = simple_strtoull(argv[5], NULL, 16);

	p   = (unsigned char *)mem_addr;
	blk = (dst_addr/MMC_BLOCK_SIZE);
	cnt = (mem_len/MMC_BLOCK_SIZE) + ((mem_len & (MMC_BLOCK_SIZE-1)) ? 1 : 0);

	flush_dcache_all();

	if (! strcmp(argv[2], "2ndboot")) {
		struct boot_dev_head *bh = (struct boot_dev_head *)mem_addr;
		struct boot_dev_mmc  *bd = (struct boot_dev_mmc *)&bh->bdi;

		bd->port_no = dev; /* set u-boot device port num */
		printf("head boot dev  = %d\n", bd->port_no);

		goto do_write;
	}

	if (! strcmp(argv[2], "boot")) {
		struct boot_dev_head head;
		struct boot_dev_head *bh = &head;
		struct boot_dev_mmc *bd = (struct boot_dev_mmc *)&bh->bdi;
		int len = sizeof(head);
		unsigned int load = CONFIG_SYS_TEXT_BASE;

		if (argc == 7)
			load = simple_strtoul (argv[6], NULL, 16);

		memset((void*)&head, 0x00, len);

		bh->load_addr = (unsigned int)load;
		bh->jump_addr = bh->load_addr;
		bh->load_size = (unsigned int)mem_len;
		bh->signature = SIGNATURE_ID;
		bd->port_no	  = dev;

		printf("head boot dev  = %d\n", bd->port_no);
		printf("head load addr = 0x%08x\n", bh->load_addr);
		printf("head load size = 0x%08x\n", bh->load_size);
		printf("head gignature = 0x%08x\n", bh->signature);

		p -= len;
		memcpy(p, bh, len);

		mem_len += MMC_BLOCK_SIZE;
		cnt = (mem_len/MMC_BLOCK_SIZE) + ((mem_len & (MMC_BLOCK_SIZE-1)) ? 1 : 0);

		goto do_write;
	}

	if (strcmp(argv[2], "part") == 0) {
		uint64_t parts[4][2] = { {0,0}, };
		uint64_t part_len = 0;
		int partno = (int)dst_addr;
		int num = 0;

		if (0 > mmc_get_part_table(desc, parts, &num))
			return 1;

		if (partno > num || 1 > partno)  {
			printf ("** Invalid mmc.%d partition number %d (1 ~ %d) **\n",
				dev, partno, num);
			return 1;
		}

		dst_addr = parts[partno-1][0];	/* set write addr from part table */
		part_len = parts[partno-1][1];
		blk = (dst_addr/MMC_BLOCK_SIZE);

 		if (0 == check_compress_ext4((char*)p, part_len)) {
			printf("update mmc.%d compressed ext4 = 0x%llx(%d) ~ 0x%llx(%d): ",
				dev, dst_addr, (unsigned int)blk, mem_len, (unsigned int)cnt);

			ret = write_compressed_ext4((char*)p, blk);
			printf("%s\n", ret?"Fail":"Done");
			return 1;
		}
		goto do_write;
	}

do_write:
	if (! blk) {
		printf("-- Fail: start %d block(0x%llx) is in MBR zone (0x200) --\n", (int)blk, dst_addr);
		return -1;
	}

	printf("update mmc.%d type %s = 0x%llx(0x%x) ~ 0x%llx(0x%x): ",
		dev, argv[2], dst_addr, (unsigned int)blk, mem_len, (unsigned int)cnt);

	ret = mmc_bwrite(dev, blk, cnt, (void const*)p);

	printf("%s\n", ret?"Done":"Fail");
	return ret;

usage:
	cmd_usage(cmdtp);
	return 1;
}
Exemple #20
0
int do_nand_env_oob(cmd_tbl_t *cmdtp, int argc, char *const argv[])
{
	int ret;
	uint32_t oob_buf[ENV_OFFSET_SIZE/sizeof(uint32_t)];
	nand_info_t *nand = &nand_info[0];
	char *cmd = argv[1];

	if (CONFIG_SYS_MAX_NAND_DEVICE == 0 || !nand->name) {
		puts("no devices available\n");
		return 1;
	}

	set_dev(0);

	if (!strcmp(cmd, "get")) {
		ret = get_nand_env_oob(nand, &nand_env_oob_offset);
		if (ret)
			return 1;

		printf("0x%08lx\n", nand_env_oob_offset);
	} else if (!strcmp(cmd, "set")) {
		loff_t addr;
		loff_t maxsize;
		struct mtd_oob_ops ops;
		int idx = 0;

		if (argc < 3)
			goto usage;

		if (arg_off(argv[2], &idx, &addr, &maxsize)) {
			puts("Offset or partition name expected\n");
			return 1;
		}

		if (idx != 0) {
			puts("Partition not on first NAND device\n");
			return 1;
		}

		if (nand->oobavail < ENV_OFFSET_SIZE) {
			printf("Insufficient available OOB bytes:\n"
			       "%d OOB bytes available but %d required for "
			       "env.oob support\n",
			       nand->oobavail, ENV_OFFSET_SIZE);
			return 1;
		}

		if ((addr & (nand->erasesize - 1)) != 0) {
			printf("Environment offset must be block-aligned\n");
			return 1;
		}

		ops.datbuf = NULL;
		ops.mode = MTD_OOB_AUTO;
		ops.ooboffs = 0;
		ops.ooblen = ENV_OFFSET_SIZE;
		ops.oobbuf = (void *) oob_buf;

		oob_buf[0] = ENV_OOB_MARKER;
		oob_buf[1] = addr / nand->erasesize;

		ret = nand->write_oob(nand, ENV_OFFSET_SIZE, &ops);
		if (ret) {
			printf("Error writing OOB block 0\n");
			return ret;
		}

		ret = get_nand_env_oob(nand, &nand_env_oob_offset);
		if (ret) {
			printf("Error reading env offset in OOB\n");
			return ret;
		}

		if (addr != nand_env_oob_offset) {
			printf("Verification of env offset in OOB failed: "
			       "0x%08llx expected but got 0x%08lx\n",
			       (unsigned long long)addr, nand_env_oob_offset);
			return 1;
		}
	} else {
		goto usage;
	}

	return ret;

usage:
	return cmd_usage(cmdtp);
}
Exemple #21
0
int do_boot(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
{
	int i, dev, ret = 0;
	ulong addr;
	loff_t off, size;
	char *cmd, *s;

	cmd = argv[1];
	if (argc < 3)
		goto usage;
		
	if (strcmp(cmd, "erase") == 0){

		printk(" %s %d\n",__func__,__LINE__);
		if(POR_NAND_BOOT()){
			printk("NAND BOOT,erase uboot : %s %d\n",__func__,__LINE__);
			run_command("nand device 0",0);
			run_command("nand erase  0",0);
			printk("nand erase  uboot \n");
		}else if(POR_SPI_BOOT()){
			printk("SPI BOOT,spi_env_relocate_spec : %s %d \n",__func__,__LINE__);
			run_command("sf probe 2",0);
			run_command("sf erase 0 200000",0);
			printk("spi erase  uboot \n");
		}else if(POR_EMMC_BOOT()) {
			printk("MMC BOOT, %s %d \n",__func__,__LINE__);
			run_command("mmcinfo 1",0);
			//write 1M 0xff from 0 addr
			run_command("mw.l 82000000 ffffffff 40000", 0);
			run_command("mmc write 1 82000000 0 800", 0);
			printk("mmc erase uboot user partition 0-1MB\n");
		}else{
			if(!run_command("sf probe 2", 0)){
				printk("SPI BOOT,spi_env_relocate_spec : %s %d \n",__func__,__LINE__);
				run_command("sf probe 2",0);
				run_command("sf erase 0 200000",0);
				printk("spi erase  uboot \n");
			}else if(!run_command("nand exist", 0)){
				printk("NAND BOOT,erase uboot : %s %d \n",__func__,__LINE__);
				run_command("nand device 0",0);
				run_command("nand erase  0",0);
				printk("nand erase  uboot \n");
			}else if(!run_command("mmcinfo 1", 0)) {
				printk("MMC BOOT, %s %d \n",__func__,__LINE__);
				//write 1M 0xff from 0 addr
				run_command("mw.l 82000000 ffffffff 40000", 0);
				run_command("mmc write 1 82000000 0 800", 0);
				printk("mmc erase uboot user partition 0-1MB\n");
			}
		}
		
	}else{
		goto usage;
	}

	return ret;
	
usage:
	cmd_usage(cmdtp);
	return 1;
}
Exemple #22
0
int do_dma_send ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
	ulong	addr, dest, count;
	int	size;
	EDMA_Config image_transfer;
	unsigned int timer_start=0;
	unsigned int timer_end=0;
	unsigned short *p=(unsigned short *)0x88000000;

	if (argc != 4)
		return cmd_usage(cmdtp);

	//for(size = 0;size<0x10000; size++)
		//*p++ = size;

	*(unsigned int *)0x01c67008 = 0x1;
	*(unsigned int *)0x01c67010 |= 0x8;
	*(unsigned int *)0x01c67024 = 0x8;
	*(unsigned int *)0x01c67030 = 0x8;

	/* Check for size specification.
	*/
	size = 2;


	addr = simple_strtoul(argv[1], NULL, 16);
	addr += base_address;

	dest = simple_strtoul(argv[2], NULL, 16);
	dest += base_address;

	count = simple_strtoul(argv[3], NULL, 16);

	if (count == 0) {
		puts ("Zero length ???\n");
		return 1;
	}
while(1)
{
	*p++ = *(unsigned int *)0x01c21414;

	IO_WRITE(EDMACC_EECRH_ADDR, 1<<3);
	
	//IO_WRITE(EDMACC_ICRH_ADDR, 1<<3);
	IO_WRITE(EDMACC_ESR_ADDR-4, 1<<3);
	//hEdma=_EDMA_MK_HANDLE(10*_EDMA_ENTRY_SIZE,EDMA_RSV6,_EDMA_TYPE_C);
	
	{
		image_transfer.opt=0x00123004;
		image_transfer.src=0x84000000;
		image_transfer.acnt=2;
		//image_transfer.bcnt=count/2;
		image_transfer.bcnt=0x2130;
		image_transfer.dst=0x2002004;
		image_transfer.srcbidx=size;
		image_transfer.dstbidx=0;
		image_transfer.link=0xFFFF;
		image_transfer.bcntrld=0;
		image_transfer.srccidx=0;
		image_transfer.dstcidx=0;
		image_transfer.ccnt=1;
	}			
	
	EDMA_config(35, &image_transfer);
	IO_WRITE(EDMACC_ICRH_ADDR, 1<<3);

	IO_WRITE(EDMACC_SECRH_ADDR, 1<<3);
	IO_WRITE(EDMACC_EESRH_ADDR, 1<<3);

	*p++ = *(unsigned int *)0x01c21414;
	//printf("dma send  tb1 start wait! time = %d\n",timer_end -timer_start);	

	while((IO_READ(EDMACC_IPRH_ADDR)&(1<<3)) ==0);

	IO_WRITE(EDMACC_EECRH_ADDR, 1<<3);

	*p++ = *(unsigned int *)0x01c21414;
	//printf("dma send  tb1 OK! time = %d\n",timer_end -timer_start);	

	IO_WRITE(EDMACC_EECR_ADDR, 1<<10);

	{
		image_transfer.opt=0x0010A004;
		image_transfer.src=0x86000000;
		image_transfer.acnt=2;
		//image_transfer.bcnt=count/2;
		image_transfer.bcnt=0x554;
		image_transfer.dst=0x2002008;
		image_transfer.srcbidx=size;
		image_transfer.dstbidx=0;
		image_transfer.link=0xffff;
		image_transfer.bcntrld=0;
		image_transfer.srccidx=0;
		image_transfer.dstcidx=0;
		image_transfer.ccnt=1;
	}
	EDMA_config(10, &image_transfer);

	
	IO_WRITE(EDMACC_ICR_ADDR, 1<<10);
	//EDMA_enableChannel(35);                        //EESR

	IO_WRITE(EDMACC_SECR_ADDR, 1<<10);
	IO_WRITE(EDMACC_ESR_ADDR, 1<<10);
	IO_WRITE(EDMACC_EESR_ADDR, 1<<10);

	*p++ = *(unsigned int *)0x01c21414;
	//printf("dma send  tb2 start wait! time = %d\n",timer_end -timer_start);	

	while((IO_READ(EDMACC_IPR_ADDR)&(1<<10)) ==0);

	IO_WRITE(EDMACC_EECR_ADDR, 1<<10);

	*p++ = *(unsigned int *)0x01c21414;	

	//printf("dma send tb2 OK! time = %d\n",timer_end -timer_start);

	if (ctrlc()) 
	{
		putc ('\n');
		break;
	}

	*p++ = *(unsigned int *)0x01c21414;	
}
	return 0;

}
static void
fs_usage(char *why)
{
    diag_printf("*** invalid 'fs' command: %s\n", why);
    cmd_usage(__FS_cmds_TAB__, &__FS_cmds_TAB_END__, "fs ");
}
Exemple #24
0
int do_dma_rev ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
	ulong	addr, dest, count;
	int	size;
	EDMA_Config image_transfer;
	unsigned int timer_start=0;
	unsigned int timer_end=0;
	unsigned short *p=(unsigned short *)0x8A000000;

	if (argc != 4)
		return cmd_usage(cmdtp);

	*(unsigned int *)0x01c67008 = 0x1;
	*(unsigned int *)0x01c67010 |= 0x8;
	*(unsigned int *)0x01c67024 = 0x8;
	*(unsigned int *)0x01c67030 = 0x8;

	/* Check for size specification.
	*/
	if ((size = cmd_get_data_size(argv[0], 4)) < 0)
		return 1;

	addr = simple_strtoul(argv[1], NULL, 16);
	addr += base_address;

	dest = simple_strtoul(argv[2], NULL, 16);
	dest += base_address;

	count = simple_strtoul(argv[3], NULL, 16);

	if (count == 0) {
		puts ("Zero length ???\n");
		return 1;
	}
	
	while(1)
	{

	*p++ = *(unsigned int *)0x01c21414;
	IO_WRITE(EDMACC_EECRH_ADDR, 1<<3);
	IO_WRITE(EDMACC_ESR_ADDR-4, 1<<3);
	
	//hEdma=_EDMA_MK_HANDLE(10*_EDMA_ENTRY_SIZE,EDMA_RSV6,_EDMA_TYPE_C);
	
	{
		image_transfer.opt=0x00123004;
		image_transfer.src=0x2002020;
		image_transfer.acnt=2;
		image_transfer.bcnt=0x2130;
		image_transfer.dst=0x85000000;
		image_transfer.srcbidx=0;
		image_transfer.dstbidx=2;
		image_transfer.link=0xffff;
		image_transfer.bcntrld=0;
		image_transfer.srccidx=0;
		image_transfer.dstcidx=0;
		//image_transfer.ccnt=count/(size*1062);
		image_transfer.ccnt=1;

	}			
		
	EDMA_config(35, &image_transfer);
	IO_WRITE(EDMACC_ICRH_ADDR, 1<<3);
	//EDMA_enableChannel(35);                        //EESR
	IO_WRITE(EDMACC_SECRH_ADDR, 1<<3);
	IO_WRITE(EDMACC_EESRH_ADDR, 1<<3);
	//EDMA_setChannel(35);                              //ESR
	//IO_WRITE(EDMACC_ESR_ADDR+4, 1<<3);

	while((IO_READ(EDMACC_IPRH_ADDR)&(1<<3)) ==0);

	IO_WRITE(EDMACC_EECRH_ADDR, 1<<3);

	*p++ = *(unsigned int *)0x01c21414;
	//printf("dma recv  tb1 OK! time = %d\n",timer_end -timer_start);	

	IO_WRITE(EDMACC_EECR_ADDR, 1<<11);
	{
		image_transfer.opt=0x0010B004;
		image_transfer.src=0x2002040;
		image_transfer.acnt=2;
		image_transfer.bcnt=0x554;
		image_transfer.dst=0x87000000;
		image_transfer.srcbidx=0;
		image_transfer.dstbidx=2;
		image_transfer.link=0xffff;
		image_transfer.bcntrld=0;
		image_transfer.srccidx=0;
		image_transfer.dstcidx=0;
		//image_transfer.ccnt=count/(size*1062);
		image_transfer.ccnt=1;

	}			
		
	EDMA_config(11, &image_transfer);
	IO_WRITE(EDMACC_ICR_ADDR, 1<<11);
	//EDMA_enableChannel(35);                        //EESR
	IO_WRITE(EDMACC_SECR_ADDR, 1<<11);
	IO_WRITE(EDMACC_ESR_ADDR, 1<<11);
	IO_WRITE(EDMACC_EESR_ADDR, 1<<11);
	//EDMA_setChannel(35);                              //ESR
	//IO_WRITE(EDMACC_ESR_ADDR+4, 1<<3);

	while((IO_READ(EDMACC_IPR_ADDR)&(1<<11)) ==0);

	IO_WRITE(EDMACC_EECR_ADDR, 1<<11);

	*p++ = *(unsigned int *)0x01c21414;	

	
	//printf("dma recv tb2 OK! time = %d\n",timer_end -timer_start);
	//run_command("cmp.b 0x86000000 0x87000000 0xAA8",0);
	//run_command("cmp.b 0x84000000 0x85000000 0x4260",0);

	if (ctrlc()) 
	{
		putc ('\n');
		break;
	}
	*p++ = *(unsigned int *)0x01c21414;	
   }
	return 0;

}
Exemple #25
0
static void
validate_options()
{
    if (opt_set(CRT_OPT_IND))
        command = 1;
    else if (opt_set(DEL_OPT_IND))
        command = 2;
    else if (opt_set(GET_OPT_IND))
        command = 4;
    else if (opt_set(LST_OPT_IND))
        command = 3;
    else
        usage();


    switch (command) {
        case 1:
            if (!nh_set)
                cmd_usage();

            flags |= NH_FLAG_VALID;
            opt_set(TYPE_OPT_IND);
            opt_set(VRF_OPT_IND);

            if (opt_set(MC_OPT_IND))
                flags |= NH_FLAG_MCAST;

            if (opt_set(POL_OPT_IND))
                flags |= NH_FLAG_POLICY_ENABLED;

            if (opt_set(RPOL_OPT_IND))
                flags |= NH_FLAG_RELAXED_POLICY;


            if (type == NH_RCV) {
                if (!opt_set(OIF_OPT_IND))
                    cmd_usage();
                if (memcmp(opt, zero_opt, sizeof(opt)))
                    cmd_usage();
            } else if (type == NH_ENCAP) {
                if (!opt_set(OIF_OPT_IND)) 
                    cmd_usage();

                if (!opt_set(EL2_OPT_IND)) {
                    if (!opt_set(SMAC_OPT_IND) || !opt_set(DMAC_OPT_IND))
                        cmd_usage();
                } else
                    flags |= NH_FLAG_ENCAP_L2;

                if (memcmp(opt, zero_opt, sizeof(opt)))
                    cmd_usage();

            } else if (type == NH_TUNNEL) {
                if (!opt_set(OIF_OPT_IND) || !opt_set(SMAC_OPT_IND) ||
                        !opt_set(DMAC_OPT_IND) || !opt_set(SIP_OPT_IND) ||
                        !opt_set(DIP_OPT_IND)) {
                    cmd_usage();
                }

                if (opt_set(UDP_OPT_IND)) {
                    flags |= NH_FLAG_TUNNEL_UDP;
                    if (!opt_set(SPORT_OPT_IND) || !opt_set(DPORT_OPT_IND))
                        cmd_usage();
                } else if (opt_set(VXLAN_OPT_IND)) {
                    flags |= NH_FLAG_TUNNEL_VXLAN;
                    if (!opt_set(SPORT_OPT_IND) || !opt_set(DPORT_OPT_IND))
                        cmd_usage();
                } else {
                    flags |= NH_FLAG_TUNNEL_GRE;
                }

                if (memcmp(opt, zero_opt, sizeof(opt)))
                    cmd_usage();
            } else if (type == NH_RESOLVE) {
                if (memcmp(opt, zero_opt, sizeof(opt)))
                    cmd_usage();
            } else if (type == NH_DISCARD) {
                if (memcmp(opt, zero_opt, sizeof(opt)))
                    cmd_usage();
            } else if (type == NH_COMPOSITE) {
                if (!opt_set(CNI_OPT_IND))
                    cmd_usage();

                if (opt_set(CL3_OPT_IND))
                    flags |= NH_FLAG_COMPOSITE_L3;
                if (opt_set(CL2_OPT_IND))
                    flags |= NH_FLAG_COMPOSITE_L2;
                if (opt_set(CFA_OPT_IND))
                    flags |= NH_FLAG_COMPOSITE_FABRIC;
                if (opt_set(CMP_OPT_IND))
                    flags |= NH_FLAG_COMPOSITE_MULTI_PROTO;
                if (opt_set(CEN_OPT_IND))
                    flags |= NH_FLAG_COMPOSITE_ENCAP;
                if (opt_set(CEVPN_OPT_IND))
                    flags |= NH_FLAG_COMPOSITE_EVPN;
                opt_set(LBL_OPT_IND);
                if (memcmp(opt, zero_opt, sizeof(opt)))
                    cmd_usage();
            } else if (type != NH_VRF_TRANSLATE) {
                cmd_usage();
            }
            break;

        case 2:
            if (!nh_set)
                cmd_usage();
            if (memcmp(opt, zero_opt, sizeof(opt)))
                    cmd_usage();
            break;

        case 3:
            if (memcmp(opt, zero_opt, sizeof(opt)))
                    usage();
            break;
        case 4:
            if (memcmp(opt, zero_opt, sizeof(opt)))
                    usage();
            break;

    }
}
Exemple #26
0
int do_mem_cmp (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
	ulong	addr1, addr2, count, ngood;
	int	size;
	int     rcode = 0;

	if (argc != 4)
		return cmd_usage(cmdtp);

	/* Check for size specification.
	*/
	if ((size = cmd_get_data_size(argv[0], 4)) < 0)
		return 1;

	addr1 = simple_strtoul(argv[1], NULL, 16);
	addr1 += base_address;

	addr2 = simple_strtoul(argv[2], NULL, 16);
	addr2 += base_address;

	count = simple_strtoul(argv[3], NULL, 16);

#ifdef CONFIG_HAS_DATAFLASH
	if (addr_dataflash(addr1) | addr_dataflash(addr2)){
		puts ("Comparison with DataFlash space not supported.\n\r");
		return 0;
	}
#endif

#ifdef CONFIG_BLACKFIN
	if (addr_bfin_on_chip_mem(addr1) || addr_bfin_on_chip_mem(addr2)) {
		puts ("Comparison with L1 instruction memory not supported.\n\r");
		return 0;
	}
#endif

	ngood = 0;

	while (count-- > 0) {
		if (size == 4) {
			ulong word1 = *(ulong *)addr1;
			ulong word2 = *(ulong *)addr2;
			if (word1 != word2) {
				printf("word at 0x%08lx (0x%08lx) "
					"!= word at 0x%08lx (0x%08lx)\n",
					addr1, word1, addr2, word2);
				rcode = 1;
				break;
			}
		}
		else if (size == 2) {
			ushort hword1 = *(ushort *)addr1;
			ushort hword2 = *(ushort *)addr2;
			if (hword1 != hword2) {
				printf("halfword at 0x%08lx (0x%04x) "
					"!= halfword at 0x%08lx (0x%04x)\n",
					addr1, hword1, addr2, hword2);
				rcode = 1;
				break;
			}
		}
		else {
			u_char byte1 = *(u_char *)addr1;
			u_char byte2 = *(u_char *)addr2;
			if (byte1 != byte2) {
				printf("byte at 0x%08lx (0x%02x) "
					"!= byte at 0x%08lx (0x%02x)\n",
					addr1, byte1, addr2, byte2);
				rcode = 1;
				break;
			}
		}
		ngood++;
		addr1 += size;
		addr2 += size;

		/* reset watchdog from time to time */
		if ((count % (64 << 10)) == 0)
			WATCHDOG_RESET();
	}

	printf("Total of %ld %s%s were the same\n",
		ngood, size == 4 ? "word" : size == 2 ? "halfword" : "byte",
		ngood == 1 ? "" : "s");
	return rcode;
}
Exemple #27
0
/*
 * env export [-t | -b | -c] [-s size] addr [var ...]
 *	-t:	export as text format; if size is given, data will be
 *		padded with '\0' bytes; if not, one terminating '\0'
 *		will be added (which is included in the "filesize"
 *		setting so you can for exmple copy this to flash and
 *		keep the termination).
 *	-b:	export as binary format (name=value pairs separated by
 *		'\0', list end marked by double "\0\0")
 *	-c:	export as checksum protected environment format as
 *		used for example by "saveenv" command
 *	-s size:
 *		size of output buffer
 *	addr:	memory address where environment gets stored
 *	var...	List of variable names that get included into the
 *		export. Without arguments, the whole environment gets
 *		exported.
 *
 * With "-c" and size is NOT given, then the export command will
 * format the data as currently used for the persistent storage,
 * i. e. it will use CONFIG_ENV_SECT_SIZE as output block size and
 * prepend a valid CRC32 checksum and, in case of redundant
 * environment, a "current" redundancy flag. If size is given, this
 * value will be used instead of CONFIG_ENV_SECT_SIZE; again, CRC32
 * checksum and redundancy flag will be inserted.
 *
 * With "-b" and "-t", always only the real data (including a
 * terminating '\0' byte) will be written; here the optional size
 * argument will be used to make sure not to overflow the user
 * provided buffer; the command will abort if the size is not
 * sufficient. Any remaining space will be '\0' padded.
 *
 * On successful return, the variable "filesize" will be set.
 * Note that filesize includes the trailing/terminating '\0' byte(s).
 *
 * Usage scenario:  create a text snapshot/backup of the current settings:
 *
 *	=> env export -t 100000
 *	=> era ${backup_addr} +${filesize}
 *	=> cp.b 100000 ${backup_addr} ${filesize}
 *
 * Re-import this snapshot, deleting all other settings:
 *
 *	=> env import -d -t ${backup_addr}
 */
static int do_env_export(cmd_tbl_t *cmdtp, int flag,
			 int argc, char * const argv[])
{
	char	buf[32];
	ulong	addr;
	char	*ptr, *cmd, *res;
	size_t	size = 0;
	ssize_t	len;
	env_t	*envp;
	char	sep = '\n';
	int	chk = 0;
	int	fmt = 0;

	cmd = *argv;

	while (--argc > 0 && **++argv == '-') {
		char *arg = *argv;
		while (*++arg) {
			switch (*arg) {
			case 'b':		/* raw binary format */
				if (fmt++)
					goto sep_err;
				sep = '\0';
				break;
			case 'c':		/* external checksum format */
				if (fmt++)
					goto sep_err;
				sep = '\0';
				chk = 1;
				break;
			case 's':		/* size given */
				if (--argc <= 0)
					return cmd_usage(cmdtp);
				size = simple_strtoul(*++argv, NULL, 16);
				goto NXTARG;
			case 't':		/* text format */
				if (fmt++)
					goto sep_err;
				sep = '\n';
				break;
			default:
				return CMD_RET_USAGE;
			}
		}
NXTARG:		;
	}

	if (argc < 1)
		return CMD_RET_USAGE;

	addr = simple_strtoul(argv[0], NULL, 16);
	ptr = map_sysmem(addr, size);

	if (size)
		memset(ptr, '\0', size);

	argc--;
	argv++;

	if (sep) {		/* export as text file */
		len = hexport_r(&env_htab, sep,
				H_MATCH_KEY | H_MATCH_IDENT,
				&ptr, size, argc, argv);
		if (len < 0) {
			error("Cannot export environment: errno = %d\n", errno);
			return 1;
		}
		sprintf(buf, "%zX", (size_t)len);
		setenv("filesize", buf);

		return 0;
	}

	envp = (env_t *)ptr;

	if (chk)		/* export as checksum protected block */
		res = (char *)envp->data;
	else			/* export as raw binary data */
		res = ptr;

	len = hexport_r(&env_htab, '\0',
			H_MATCH_KEY | H_MATCH_IDENT,
			&res, ENV_SIZE, argc, argv);
	if (len < 0) {
		error("Cannot export environment: errno = %d\n", errno);
		return 1;
	}

	if (chk) {
		envp->crc = crc32(0, envp->data, ENV_SIZE);
#ifdef CONFIG_ENV_ADDR_REDUND
		envp->flags = ACTIVE_FLAG;
#endif
	}
	setenv_hex("filesize", len + offsetof(env_t, data));

	return 0;

sep_err:
	printf("## %s: only one of \"-b\", \"-c\" or \"-t\" allowed\n",	cmd);
	return 1;
}
Exemple #28
0
int do_mem_cp ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
	ulong	addr, dest, count;
	int	size;

	if (argc != 4)
		return cmd_usage(cmdtp);

	/* Check for size specification.
	*/
	if ((size = cmd_get_data_size(argv[0], 4)) < 0)
		return 1;

	addr = simple_strtoul(argv[1], NULL, 16);
	addr += base_address;

	dest = simple_strtoul(argv[2], NULL, 16);
	dest += base_address;

	count = simple_strtoul(argv[3], NULL, 16);

	if (count == 0) {
		puts ("Zero length ???\n");
		return 1;
	}

#ifndef CONFIG_SYS_NO_FLASH
	/* check if we are copying to Flash */
	if ( (addr2info(dest) != NULL)
#ifdef CONFIG_HAS_DATAFLASH
	   && (!addr_dataflash(dest))
#endif
	   ) {
		int rc;

		puts ("Copy to Flash... ");

		rc = flash_write ((char *)addr, dest, count*size);
		if (rc != 0) {
			flash_perror (rc);
			return (1);
		}
		puts ("done\n");
		return 0;
	}
#endif

#ifdef CONFIG_HAS_DATAFLASH
	/* Check if we are copying from RAM or Flash to DataFlash */
	if (addr_dataflash(dest) && !addr_dataflash(addr)){
		int rc;

		puts ("Copy to DataFlash... ");

		rc = write_dataflash (dest, addr, count*size);

		if (rc != 1) {
			dataflash_perror (rc);
			return (1);
		}
		puts ("done\n");
		return 0;
	}

	/* Check if we are copying from DataFlash to RAM */
	if (addr_dataflash(addr) && !addr_dataflash(dest)
#ifndef CONFIG_SYS_NO_FLASH
				 && (addr2info(dest) == NULL)
#endif
	   ){
		int rc;
		rc = read_dataflash(addr, count * size, (char *) dest);
		if (rc != 1) {
			dataflash_perror (rc);
			return (1);
		}
		return 0;
	}

	if (addr_dataflash(addr) && addr_dataflash(dest)){
		puts ("Unsupported combination of source/destination.\n\r");
		return 1;
	}
#endif

#ifdef CONFIG_BLACKFIN
	/* See if we're copying to/from L1 inst */
	if (addr_bfin_on_chip_mem(dest) || addr_bfin_on_chip_mem(addr)) {
		memcpy((void *)dest, (void *)addr, count * size);
		return 0;
	}
#endif

	while (count-- > 0) {
		if (size == 4)
			*((ulong  *)dest) = *((ulong  *)addr);
		else if (size == 2)
			*((ushort *)dest) = *((ushort *)addr);
		else
			*((u_char *)dest) = *((u_char *)addr);
		addr += size;
		dest += size;

		/* reset watchdog from time to time */
		if ((count % (64 << 10)) == 0)
			WATCHDOG_RESET();
	}
	return 0;
}
int do_askenv ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
{
	extern char console_buffer[CONFIG_SYS_CBSIZE];
	char message[CONFIG_SYS_CBSIZE];
	int size = CONFIG_SYS_CBSIZE - 1;
	int len;
	char *local_args[4];

	local_args[0] = argv[0];
	local_args[1] = argv[1];
	local_args[2] = NULL;
	local_args[3] = NULL;

	if (argc < 2) {
		cmd_usage(cmdtp);
		return 1;
	}
	/* Check the syntax */
	switch (argc) {
	case 1:
		cmd_usage(cmdtp);
		return 1;

	case 2:		/* askenv envname */
		sprintf (message, "Please enter '%s':", argv[1]);
		break;

	case 3:		/* askenv envname size */
		sprintf (message, "Please enter '%s':", argv[1]);
		size = simple_strtoul (argv[2], NULL, 10);
		break;

	default:	/* askenv envname message1 ... messagen size */
	    {
		int i;
		int pos = 0;

		for (i = 2; i < argc - 1; i++) {
			if (pos) {
				message[pos++] = ' ';
			}
			strcpy (message+pos, argv[i]);
			pos += strlen(argv[i]);
		}
		message[pos] = '\0';
		size = simple_strtoul (argv[argc - 1], NULL, 10);
	    }
		break;
	}

	if (size >= CONFIG_SYS_CBSIZE)
		size = CONFIG_SYS_CBSIZE - 1;

	if (size <= 0)
		return 1;

	/* prompt for input */
	len = readline (message);

	if (size < len)
		console_buffer[size] = '\0';

	len = 2;
	if (console_buffer[0] != '\0') {
		local_args[2] = console_buffer;
		len = 3;
	}

	/* Continue calling setenv code */
	return _do_setenv (flag, len, local_args);
}
static int netboot_common(enum proto_t proto, cmd_tbl_t *cmdtp, int argc,
		char * const argv[])
{
	char *s;
	char *end;
	int   rcode = 0;
	int   size;
	ulong addr;

	/* pre-set load_addr */
	if ((s = getenv("loadaddr")) != NULL) {
		load_addr = simple_strtoul(s, NULL, 16);
	}

	switch (argc) {
	case 1:
		break;

	case 2:	/*
		 * Only one arg - accept two forms:
		 * Just load address, or just boot file name. The latter
		 * form must be written in a format which can not be
		 * mis-interpreted as a valid number.
		 */
		addr = simple_strtoul(argv[1], &end, 16);
		if (end == (argv[1] + strlen(argv[1])))
			load_addr = addr;
		else
			copy_filename(BootFile, argv[1], sizeof(BootFile));
		break;

	case 3:	load_addr = simple_strtoul(argv[1], NULL, 16);
		copy_filename(BootFile, argv[2], sizeof(BootFile));

		break;

#ifdef CONFIG_CMD_TFTPPUT
	case 4:
		if (strict_strtoul(argv[1], 16, &save_addr) < 0 ||
			strict_strtoul(argv[2], 16, &save_size) < 0) {
			printf("Invalid address/size\n");
			return cmd_usage(cmdtp);
		}
		copy_filename(BootFile, argv[3], sizeof(BootFile));
		break;
#endif
	default:
		bootstage_error(BOOTSTAGE_ID_NET_START);
		return CMD_RET_USAGE;
	}
	bootstage_mark(BOOTSTAGE_ID_NET_START);

	if ((size = NetLoop(proto)) < 0) {
		bootstage_error(BOOTSTAGE_ID_NET_NETLOOP_OK);
		return 1;
	}
	bootstage_mark(BOOTSTAGE_ID_NET_NETLOOP_OK);

	/* NetLoop ok, update environment */
	netboot_update_env();

	/* done if no file was loaded (no errors though) */
	if (size == 0) {
		bootstage_error(BOOTSTAGE_ID_NET_LOADED);
		return 0;
	}

	/* flush cache */
	flush_cache(load_addr, size);

	bootstage_mark(BOOTSTAGE_ID_NET_LOADED);

	rcode = bootm_maybe_autostart(cmdtp, argv[0]);

	if (rcode < 0)
		bootstage_error(BOOTSTAGE_ID_NET_DONE_ERR);
	else
		bootstage_mark(BOOTSTAGE_ID_NET_DONE);
	return rcode;
}