コード例 #1
0
int do_mem_crc32(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
{
	ulong addr, crc, length, vcrc;
	int ac, verify;
	ulong *ptr;
	char **av;

	if (argc < 3) {
		print_cmd_help(cmdtp);
		return 1;
	}

	av = argv + 1;
	ac = argc - 1;

	if (strcmp(*av, "-v") == 0) {
		verify = 1;
		av++;
		ac--;

		if (ac < 3) {
			print_cmd_help(cmdtp);
			return 1;
		}
	} else {
		verify = 0;
	}

	addr = simple_strtoul(*av++, NULL, 16);
	length = simple_strtoul(*av++, NULL, 16);

	crc = tinf_crc32((const char *)addr, length);

	if (!verify) {
		printf("CRC32 checksum for data at 0x%08lX ~ 0x%08lX: 0x%08lX\n",
			addr, addr + length - 1, crc);
		if (ac > 2) {
			ptr = (ulong *)simple_strtoul(*av++, NULL, 16);
			*ptr = crc;
		}
	} else {
		vcrc = simple_strtoul(*av++, NULL, 16);
		if (vcrc != crc) {
			printf("## Error: CRC32 checksum for data at 0x%08lX ~ 0x%08lX: 0x%08lX (not 0x%08lX!)\n",
				addr, addr + length - 1, crc, vcrc);

			return 1;
		}
	}

	return 0;
}
コード例 #2
0
static void print_help(void)
{
	int n;
	printf("commands:\n");
	for (n = 0; wpa_cli_commands[n].cmd; n++)
		print_cmd_help(&wpa_cli_commands[n], "  ");
}
コード例 #3
0
int do_setenv(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]){
	if(argc < 2){
		print_cmd_help(cmdtp);
		return(1);
	}

	return(_do_setenv(flag, argc, argv));
}
コード例 #4
0
int do_mem_cp(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
{
	ulong addr, dest, count;
	int size;

	if (argc != 4) {
		print_cmd_help(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);
	dest  = simple_strtoul(argv[2], NULL, 16);
	count = simple_strtoul(argv[3], NULL, 16);

	if (count == 0) {
		puts("## Error: zero length?\n");
		return 1;
	}

#if !defined(CFG_NO_FLASH)
	/* check if we are copying to Flash */
	if (addr2info(dest) != NULL) {
		int rc;

		puts("Copying to FLASH...\n");

		rc = flash_write((char *)addr, dest, count * size);

		if (rc != 0) {
			flash_perror(rc);
			return 1;
		}

		puts("Done!\n\n");

		return 0;
	}
#endif /* !CFG_NO_FLASH */

	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;
}
コード例 #5
0
static void print_help(FILE *stream, const char *cmd)
{
	int n;

	fprintf(stream, "commands:\n");
	for (n = 0; hostapd_cli_commands[n].cmd; n++) {
		if (cmd == NULL || str_starts(hostapd_cli_commands[n].cmd, cmd))
			print_cmd_help(stream, &hostapd_cli_commands[n], "  ");
	}
}
コード例 #6
0
int do_mem_mw(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
{
	ulong addr, writeval, count;
	int size;

	if ((argc < 3) || (argc > 4)) {
		print_cmd_help(cmdtp);
		return 1;
	}

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

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

	/* Get the value to write */
	writeval = simple_strtoul(argv[2], NULL, 16);

	/* Count ? */
	if (argc == 4)
		count = simple_strtoul(argv[3], NULL, 16);
	else
		count = 1;

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

		addr += size;
	}

	return 0;
}
コード例 #7
0
ファイル: hush.c プロジェクト: Dark1X/u-boot_mod
/* run_pipe_real() starts all the jobs, but doesn't wait for anything
 * to finish.  See checkjobs().
 *
 * return code is normally -1, when the caller has to wait for children
 * to finish to determine the exit status of the pipe.  If the pipe
 * is a simple builtin command, however, the action is done by the
 * time run_pipe_real returns, and the exit code is provided as the
 * return value.
 *
 * The input of the pipe is always stdin, the output is always
 * stdout.  The outpipe[] mechanism in BusyBox-0.48 lash is bogus,
 * because it tries to avoid running the command substitution in
 * subshell, when that is in fact necessary.  The subshell process
 * now has its stdout directed to the input of the appropriate pipe,
 * so this routine is noticeably simpler.
 */
static int run_pipe_real(struct pipe *pi) {
	int i;
	int nextin;
	int flag = do_repeat ? CMD_FLAG_REPEAT : 0;
	struct child_prog *child;
	cmd_tbl_t *cmdtp;
	char *p;
# if __GNUC__
	/* Avoid longjmp clobbering */
	(void) &i;
	(void) &nextin;
	(void) &child;
# endif

	nextin = 0;

	/* Check if this is a simple builtin (not part of a pipe).
	 * Builtins within pipes have to fork anyway, and are handled in
	 * pseudo_exec.  "echo foo | read bar" doesn't work on bash, either.
	 */
	if (pi->num_progs == 1)
		child = &(pi->progs[0]);
	if (pi->num_progs == 1 && child->group) {
		int rcode;
		debug_printf("non-subshell grouping\n");
		rcode = run_list_real(child->group);
		return rcode;
	} else if (pi->num_progs == 1 && pi->progs[0].argv != NULL) {
		for (i = 0; is_assignment(child->argv[i]); i++) { /* nothing */
		}
		if (i != 0 && child->argv[i] == NULL) {
			/* assignments, but no command: set the local environment */
			for (i = 0; child->argv[i] != NULL; i++) {

				/* Ok, this case is tricky.  We have to decide if this is a
				 * local variable, or an already exported variable.  If it is
				 * already exported, we have to export the new value.  If it is
				 * not exported, we need only set this as a local variable.
				 * This junk is all to decide whether or not to export this
				 * variable. */
				int export_me = 0;
				char *name, *value;
				name = xstrdup(child->argv[i]);
				debug_printf("Local environment set: %s\n", name);
				value = strchr(name, '=');
				if (value)
					*value = 0;
				free(name);
				p = insert_var_value(child->argv[i]);
				set_local_var(p, export_me);
				if (p != child->argv[i])
					free(p);
			}
			return EXIT_SUCCESS; /* don't worry about errors in set_local_var() yet */
		}
		for (i = 0; is_assignment(child->argv[i]); i++) {
			p = insert_var_value(child->argv[i]);
			set_local_var(p, 0);
			if (p != child->argv[i]) {
				child->sp--;
				free(p);
			}
		}
		if (child->sp) {
			char * str = NULL;

			str = make_string((child->argv + i));
			parse_string_outer(str, FLAG_EXIT_FROM_LOOP | FLAG_REPARSING);
			free(str);
			return last_return_code;
		}

		/* check ";", because ,example , argv consist from
		 * "help;flinfo" must not execute
		 */
		if (strchr(child->argv[i], ';')) {
			printf_err("unknown command '%s' - try 'help' or use 'run' command\n", child->argv[i]);
			return -1;
		}

		/* Look up command in command table */
		if ((cmdtp = find_cmd(child->argv[i])) == NULL) {
			printf_err("unknown command '%s' - try 'help'\n", child->argv[i]);
			return -1; /* give up after bad command */
		} else {
			int rcode;
#if defined(CONFIG_CMD_BOOTD)
			extern int do_bootd (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);

			/* avoid "bootd" recursion */
			if (cmdtp->cmd == do_bootd) {
				if (flag & CMD_FLAG_BOOTD) {
					printf_err("'bootd' recursion detected!\n");
					return -1;
				} else {
					flag |= CMD_FLAG_BOOTD;
				}
			}
#endif /* CONFIG_CMD_BOOTD */
			/* found - check max args */
			if ((child->argc - i) > cmdtp->maxargs) {
				print_cmd_help(cmdtp);
				return -1;
			}
			child->argv += i; /* XXX horrible hack */
			/* OK - call function to do the command */
			rcode = (cmdtp->cmd)(cmdtp, flag, child->argc - i, &child->argv[i]);

			if (!cmdtp->repeatable)
				flag_repeat = 0;

			child->argv -= i; /* XXX restore hack so free() can work right */

			return rcode;
		}
	}
	return -1;
}
コード例 #8
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 *argv[])
{
	ulong addr, i;
	int nbytes, size;
	extern char console_buffer[];

	if (argc != 2) {
		print_cmd_help(cmdtp);
		return 1;
	}

	/* 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);
	}

	/*
	 * 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;
		} else {
			char *endp;
			i = simple_strtoul(console_buffer, &endp, 16);
			nbytes = endp - console_buffer;

			if (nbytes) {
				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;
}
コード例 #9
0
int do_mem_md(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
{
	ulong addr, length;
	ulong i, nbytes, linebytes;
	u_char *cp;
	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) {
		print_cmd_help(cmdtp);
		return 1;
	}

	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);

		/*
		 * 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);
	}

	/*
	 * 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];
		uint *uip = (uint *)linebuf;
		ushort *usp = (ushort *)linebuf;
		u_char *ucp = (u_char *)linebuf;

		printf("%08lX:", addr);

		linebytes = (nbytes > DISP_LINE_LEN) ? DISP_LINE_LEN : nbytes;

		for (i = 0; i < linebytes; i += size) {
			if (size == 4) {
				printf(" %08X", (*uip++ = *((uint *)addr)));
			} else if (size == 2) {
				printf(" %04X", (*usp++ = *((ushort *)addr)));
			} else {
				printf(" %02X", (*ucp++ = *((u_char *)addr)));
			}

			addr += size;
		}

		puts("    ");
		cp = (u_char *)linebuf;

		for (i = 0; i < linebytes; i++) {
			if ((*cp < 0x20) || (*cp > 0x7e))
				putc('.');
			else
				printf("%c", *cp);

			cp++;
		}

		putc('\n');
		nbytes -= linebytes;

		if (ctrlc()) {
			rc = 1;
			break;
		}

	} while (nbytes > 0);

	dp_last_addr = addr;
	dp_last_length = length;
	dp_last_size = size;

	return rc;
}
コード例 #10
0
int do_iminfo(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
{
	int tpl_type;
	u32 addr, data;
	image_header_t *hdr = &header;
	tplink_image_header_t *tpl_hdr;

	tpl_type = 0;

	if (argc == 2) {
		addr = simple_strtoul(argv[1], NULL, 16);
	} else {
		print_cmd_help(cmdtp);
		return 1;
	}

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

	/* Check what header type we have */
	memmove(&data, (char *)addr, sizeof(u32));

	switch (ntohl(data)) {
	case TPL_IH_VERSION_V1:
		tpl_type = 1;

		tpl_hdr = (tplink_image_header_t *)addr;
		print_tpl_ih_v1(tpl_hdr);
		break;
	case IH_MAGIC:
		print_uboot_ih((image_header_t *)addr);
		memmove(&header, (char *)addr, sizeof(image_header_t));
		break;
	case TPL_IH_VERSION_V2:
	case TPL_IH_VERSION_V3:
	default:
		puts("## Error: unsupported image header\n");
		return 1;
	}

	/* Always verify header CRC */
	if (ih_header_crc(hdr, tpl_type) != 0) {
		puts("## Error: header checksum mismatch!\n");
		return 1;
	}

	/* And data.. here always */
	if (tpl_type) {
		data = addr + sizeof(tplink_image_header_t);
	} else {
		data = addr + sizeof(image_header_t);
	}

	if (ih_data_crc(data, hdr, tpl_type, 1) != 0) {
		puts("## Error: data checksum mismatch!\n");
		return 1;
	}

	puts("\n");

	return 0;
}
コード例 #11
0
int do_askenv( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]){
	extern char console_buffer[CFG_CBSIZE];
	char message[CFG_CBSIZE];
	int size = CFG_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){
		print_cmd_help(cmdtp);
		return(1);
	}
	/* Check the syntax */
	switch(argc){
		case 1:
		print_cmd_help(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 >= CFG_CBSIZE){
		size = CFG_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));
}