Beispiel #1
0
char	*my_str_intro(char *enter, char *find, char *replace)
{
  char	*output;
  int	i;
  int	len;

  i = 0;
  len = my_strlen(enter) + my_strlen(replace) - my_strlen(find) + 1;
  if ((output = malloc(sizeof(char) * len)) == NULL)
    return (NULL);
  output = my_memset(output, '\0', len);
  while (find_cmd(enter, find) != 0 && *enter != '\0')
    {
      output[i++] = *enter;
      enter++;
    }
  if (find_cmd(enter, find) == 0)
    while (*replace != '\0')
	{
	  output[i++] = *replace;
	  replace++;
	}
  while (*enter != '\0' && output[i])
    {
      output[i++] = *enter;
      enter++;
    }
  return (output);
}
static int API_add_command(va_list ap)
{
	cmd_tbl_t *oldcmd, *newcmd;
	int cmdNum=0;
	char buffer[9];
	newcmd = (cmd_tbl_t*)va_arg(ap, u_int32_t);
	sprintf(buffer, "tempCmd%d", cmdNum);
	oldcmd = find_cmd(buffer);
	while(oldcmd==NULL)
	{
		cmdNum++;
		if(cmdNum==MONITOR_CMD)
			return 1;
		sprintf(buffer, "tempCmd%d", cmdNum);
		oldcmd = find_cmd(buffer);
	}
	oldcmd->name = (char*)malloc(sizeof(char)*strlen(newcmd->name));
	strcpy(oldcmd->name, newcmd->name);
	oldcmd->maxargs = newcmd->maxargs;
	oldcmd->repeatable = newcmd->repeatable;
	oldcmd->cmd = newcmd->cmd;
	oldcmd->usage = (char*)malloc(sizeof(char)*strlen(newcmd->usage));
	strcpy(oldcmd->usage, newcmd->usage);
	oldcmd->help = (char*)malloc(sizeof(char)*strlen(newcmd->help));
	strcpy(oldcmd->help, newcmd->help);
	printf("Added command to monitor named %s\n", oldcmd->name);
	return 0;
}
Beispiel #3
0
/* Recursively process a command line string s and find the command
   corresponding to it. This can be ambiguous, full, incomplete,
   non-existent. */
static int process(char *s, char ** next, command_t *lookup,
		   command_t **result, char **prev)
{
    *result = find_cmd(s, lookup, next);
    *prev = s; 

    /* non existent */
    if ( ! *result ) 
	return CMD_NONE;

    /* found entry: is it ambigous, i.e. not exact command name and
       more than one command in the list matches.  Note that find_cmd
       points to the first ambiguous entry */
    if ( strncasecmp(s, (*result)->name, strlen((*result)->name)) &&
	 find_cmd(s, (*result) + 1, next)) 
	return CMD_AMBIG;

    /* found a unique command: component or full? */
    if ( (*result)->func ) {
	return CMD_COMPLETE;
    } else {
	if ( *next == '\0' ) {
	    return CMD_INCOMPLETE;
	} else {
	    return process(*next, next, (*result)->sub_cmd, result, prev);
	}
    }
}
Beispiel #4
0
main()
{ 
  char name[64]; int pid, cmd;

  while(1){
    pid = getpid();
    color = 0x000A + (pid % 6);
       
    printf("----------------------------------------------\n");
    printf("I am proc %d in U mode: running segment=%x\n",getpid(), getcs());
    show_menu();
    printf("Command ? ");
    gets(name); 
    if (name[0]==0) 
        continue;

    cmd = find_cmd(name);
    switch(cmd){
           case 0 : getpid();   break;
           case 1 : ps();       break;
           case 2 : chname();   break;
           case 3 : kmode();    break;
           case 4 : kswitch();  break;
           case 5 : wait();     break;
           case 6 : exit();     break;

           default: invalid(name); break;
    }
  }
}
Beispiel #5
0
main()
{ 
  char name[64]; int pid, cmd;
color = 0x0F;
  while(1){
    printf("----------------------------------------------\n");
    pid = getpid();
    
     printf("I am proc %d in U mode: running segment=%x\n", pid, getcs());
    show_menu();
    printf("Command ? ");

    gets(name); 
    if (name[0]==0) 
        continue;

    cmd = find_cmd(name);
    switch(cmd){
           case 0 : getpid();   break;
           case 1 : ps();       break;
           case 2 : chname();   break;
           case 3 : pid = kfork();   
           printf("fork returned: %d\n", pid);
            break;
           case 4 : kswitch();  break;
           case 5 : wait();     break;
           case 6 : exit();     break;
           case 7 : pid = exec();   
           printf("exec returned: %d\n", pid);  break;

           default: invalid(name); break;
    }
  }
}
Beispiel #6
0
main()
{ 
  char name[64]; int cmd;
  int pid;
  while(1){
       pid = getpid();
       printf("==============================================\n");
       printf("Das ist prozess %d im Umode segment=%x\n", pid, getcs());
       show_menu();
       printf("Command ? ");
       gets(name); 
       if (name[0]==0) 
           continue;

       cmd = find_cmd(name);
       switch(cmd){
           case 0 : getpid();  break;
           case 1 : ps();       break;
           case 2 : chname();   break;
           case 3 : kmode();    break;
           case 4 : kswitch();  break;
           case 5 : mywait();   break;
           case 6 : myexit();   break;
           case 7 : ufork();    break;
           case 8 : myexec("/bin/u1"); break; 
           case 9 : sin(); break;
           case 10: sout(); break;
          default: invalid(name); break;
       }
  }
}
Beispiel #7
0
/*
 * Runs the given boot command securely.  Specifically:
 * - Doesn't run the command with the shell (run_command or parse_string_outer),
 *   since that's a lot of code surface that an attacker might exploit.
 *   Because of this, we don't do any argument parsing--the secure boot command
 *   has to be a full-fledged u-boot command.
 * - Doesn't check for keypresses before booting, since that could be a
 *   security hole; also disables Ctrl-C.
 * - Doesn't allow the command to return.
 *
 * Upon any failures, this function will drop into an infinite loop after
 * printing the error message to console.
 */
void cli_secure_boot_cmd(const char *cmd)
{
	cmd_tbl_t *cmdtp;
	int rc;

	if (!cmd) {
		printf("## Error: Secure boot command not specified\n");
		goto err;
	}

	/* Disable Ctrl-C just in case some command is used that checks it. */
	disable_ctrlc(1);

	/* Find the command directly. */
	cmdtp = find_cmd(cmd);
	if (!cmdtp) {
		printf("## Error: \"%s\" not defined\n", cmd);
		goto err;
	}

	/* Run the command, forcing no flags and faking argc and argv. */
	rc = (cmdtp->cmd)(cmdtp, 0, 1, (char **)&cmd);

	/* Shouldn't ever return from boot command. */
	printf("## Error: \"%s\" returned (code %d)\n", cmd, rc);

err:
	/*
	 * Not a whole lot to do here.  Rebooting won't help much, since we'll
	 * just end up right back here.  Just loop.
	 */
	hang();
}
Beispiel #8
0
void main(void){
    uart0_init();
    led_init();
    nand_init();
    irq_init();

    int i = 0;
    for(i = 0;i < 10;i++){
        uart0_puts("\nShell #");
        uart0_gets(buf,MAX_LEN);

        const cmd_t *ptr;
        ptr = find_cmd(buf);
        if(ptr != 0){
            ptr->call_back();
        }else{
            uart0_puts("\nNot find Cmd");
        }

        /*if(!my_strcmp(buf,"ledon")){
            uart0_puts(buf);
            led_on();
            continue;
        }else if(!my_strcmp(buf,"ledoff")){
            uart0_puts(buf);
            led_off();
            continue;
        }else{
            uart0_puts("\nNot command!!!");
            continue;
        }*/
    }
}
Beispiel #9
0
int do_time(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
	const int target_argc = argc - 1;
	int retval = 0;
	unsigned long int cycles = 0;
	cmd_tbl_t *target_cmdtp = NULL;

	if (argc == 1) {
		printf("no command provided\n");
		return 1;
	}

	/* parse command */
	target_cmdtp = find_cmd(argv[1]);
	if (!target_cmdtp) {
		printf("command not found: %s\n", argv[1]);
		return 1;
	}

	if (target_argc > target_cmdtp->maxargs) {
		printf("maxarags exceeded: %d > %d\n", target_argc,
				target_cmdtp->maxargs);
		return 1;
	}

	/* run the command and report run time */
	cycles = get_timer_masked();
	retval = target_cmdtp->cmd(target_cmdtp, 0, target_argc, argv + 1);
	cycles = get_timer_masked() - cycles;

	putc('\n');
	report_time(cycles);

	return retval;
}
Beispiel #10
0
int cmd_process(int flag, int argc, char * const argv[],
		int *repeatable, unsigned long *ticks)
{
	enum command_ret_t rc = CMD_RET_SUCCESS;
	cmd_tbl_t *cmdtp;

	/* Look up command in command table */
	cmdtp = find_cmd(argv[0]);
	if (cmdtp == NULL) {
		printf("Unknown command '%s' - try 'help'\n", argv[0]);
		return 1;
	}

	/* found - check max args */
	if (argc > cmdtp->maxargs)
		rc = CMD_RET_USAGE;

	/* If OK so far, then do the command */
	if (!rc) {
		if (ticks)
			; //*ticks = get_timer(0);
		rc = cmd_call(cmdtp, flag, argc, argv);
		if (ticks)
			; //*ticks = get_timer(*ticks);
		if (!(cmdtp->info & CMD_INFO_REPEATABLE))
			*repeatable = 0;
	}
	if (rc == CMD_RET_USAGE)
		cmd_usage(cmdtp);

	return rc;
}
Beispiel #11
0
int execute_command(int argc, char **argv)
{
	struct command *cmdtp;
	int ret;
	struct getopt_context gc;

	getopt_context_store(&gc);

	/* Look up command in command table */
	if ((cmdtp = find_cmd(argv[0]))) {
		/* OK - call function to do the command */
		ret = cmdtp->cmd(argc, argv);
		if (ret == COMMAND_ERROR_USAGE) {
			barebox_cmd_usage(cmdtp);
			ret = COMMAND_ERROR;
		}
	} else {
#ifdef CONFIG_CMD_HELP
		printf ("Unknown command '%s' - try 'help'\n", argv[0]);
#else
		printf ("Unknown command '%s'\n", argv[0]);
#endif
		ret = -1;	/* give up after bad command */
	}

	getopt_context_restore(&gc);

	return ret;
}
Beispiel #12
0
main()
{ 
    char name[64];
    int pid, cmd, out;
    printf("in u2.c\n");

    while(1)
    {
        pid = getpid();

        color = 0x0C;

        printf("----------------------------------------------\n");
        printf("I am proc %d in U2 mode: running segment=%x\n", getpid(), getcs());
        show_menu();
        printf("Your Order ? ");
        gets(name); 
        if (name[0]==0) 
            continue;

        cmd = find_cmd(name);

        if (cmd >= 0)
        {
            out = commands[cmd].f();
        }
        else
        {
            invalid(name);
        }
    }
}
Beispiel #13
0
main()
{ 
  char name[64]; int cmd;
  /* resetVideo();*/
  while(1){
       pid = get_pid();
       printf("==============================================\n");
       printf("I am task %d in Umode at segment=%x\n", pid, getcs());

       show_menu();
       printf("Command ? ");
       mgets(name); 
       if (name[0]==0) 
           continue;

       cmd = find_cmd(name);
       switch(cmd){
           case 0 : get_pid();  break;
           case 1 : ps();       break;
           case 2 : chname();   break;
           case 3 : kmode();    break;
           case 4 : kswitch();  break;
           case 5 : mywait();   break;
           case 6 : myexit();   break;
           case 7 : ufork();    break;
           case 8 : myexec("/u2");  break;
           case 9 : sin();      break;
           case 10 : sout();    break;
           default: invalid(name); break;
       }
  }
}
Beispiel #14
0
main()
{ 
  char name[64]; int pid, cmd;
  char c;

  while(1){
    
    color = 0x0C;
       
    printf("----------------------------------------------\n");
    pid = getpid();
    printf("I am proc %d in U mode: running segment=%x\n", pid, getcs());
    show_menu();
    printf("Command ? ");
    gets(name); 
    if (name[0]==0) 
        continue;

    cmd = find_cmd(name);
    switch(cmd){
           case 0 : getpid();   break;
           case 1 : ps();       break;
           case 2 : chname();   break;
           case 3 : kfork();    break;
           case 4 : kswitch();  break;
           case 5 : wait();     break;
           case 6 : exit();     break;
           case 7 : c = kgetc();  putc(c); putc('\n'); putc('\r'); break;
           case 8 : kputc();    break;

           default: invalid(name); break;
    }
  }
}
/*
** Parsing the args and return cpt
*/
int			check_arguments(int nb_arg, char **argument)
{
  int			cpt;
  int			cpt_arg;
  int			flag;

  if (nb_arg == 1)
    return (1);
  cpt = 1;
  flag = continu_parsing(nb_arg, argument);
  while (cpt < nb_arg)
    {
      cpt_arg = 1;
      if (cpt < flag)
	{
	  if ((argument[cpt][0] == '-' && my_strlen(argument[cpt]) > 1))
	      while (cpt_arg < my_strlen(argument[cpt]))
		{
		  if (is_valid(argument[cpt][cpt_arg]) == 1)
		    cpt_arg++;
		  else
		    return (0);
		}
	}
      cpt++;
    }
  return (find_cmd(cpt, argument));
}
Beispiel #16
0
main(int argc, char *argv[])
{
  char name[64]; int pid, cmd, segment, i;

  while(1){
       pid = getpid();
       color = 0x000B + (pid % 5);
       segment = (pid+1)*0x1000;
       printf("==============================================\n");
       printf("I am proc %din U mode: segment=%x\n", pid, segment);
       show_menu();
       printf("Command ? ");
       gets(name);
       if (name[0]==0)
           continue;

       cmd = find_cmd(name);

       switch(cmd){
           case 0 : getpid();   break;
           case 1 : ps();       break;
           case 2 : chname();   break;
           case 3 : kmode();    break;
           case 4 : kswitch();  break;
           case 5 : wait();     break;

           case 6 : exit();     break;
           case 7 : fork();     break;
           case 8 : exec();     break;
           case 9 : do_itimer(); break;

           default: invalid(name); break;
       }
  }
}
Beispiel #17
0
/* Recursively process a command line string s and find the command
   corresponding to it. This can be ambiguous, full, incomplete,
   non-existent. */
static int process(char *s, char ** next, command_t *lookup,
                   command_t **result, char **prev)
{
        *result = find_cmd(s, lookup, next);
        *prev = s;

        /* non existent */
        if (!*result)
                return CMD_NONE;

        /* found entry: is it ambigous, i.e. not exact command name and
           more than one command in the list matches.  Note that find_cmd
           points to the first ambiguous entry */
        if (strncasecmp(s, (*result)->pc_name, strlen((*result)->pc_name))) {
                char *another_next;
                command_t *another_result = find_cmd(s, (*result) + 1,
                                                     &another_next);
                int found_another = 0;

                while (another_result) {
                        if (strncasecmp(s, another_result->pc_name,
                                        strlen(another_result->pc_name)) == 0){
                                *result = another_result;
                                *next = another_next;
                                goto got_it;
                        }
                        another_result = find_cmd(s, another_result + 1,
                                                  &another_next);
                        found_another = 1;
                }
                if (found_another)
                        return CMD_AMBIG;
        }

got_it:
        /* found a unique command: component or full? */
        if ( (*result)->pc_func ) {
                return CMD_COMPLETE;
        } else {
                if ( *next == '\0' ) {
                        return CMD_INCOMPLETE;
                } else {
                        return process(*next, next, (*result)->pc_sub_cmd,
                                       result, prev);
                }
        }
}
Beispiel #18
0
enum command_ret_t cmd_process(int flag, int argc, char * const argv[],
			       int *repeatable, ulong *ticks)
{
	enum command_ret_t rc = CMD_RET_SUCCESS;
	cmd_tbl_t *cmdtp;

#if defined(CONFIG_SYS_XTRACE)
	char *xtrace;

	xtrace = env_get("xtrace");
	if (xtrace) {
		puts("+");
		for (int i = 0; i < argc; i++) {
			puts(" ");
			puts(argv[i]);
		}
		puts("\n");
	}
#endif

	/* Look up command in command table */
	cmdtp = find_cmd(argv[0]);
	if (cmdtp == NULL) {
		printf("Unknown command '%s' - try 'help'\n", argv[0]);
		return 1;
	}

	/* found - check max args */
	if (argc > cmdtp->maxargs)
		rc = CMD_RET_USAGE;

#if defined(CONFIG_CMD_BOOTD)
	/* avoid "bootd" recursion */
	else if (cmdtp->cmd == do_bootd) {
		if (flag & CMD_FLAG_BOOTD) {
			puts("'bootd' recursion detected\n");
			rc = CMD_RET_FAILURE;
		} else {
			flag |= CMD_FLAG_BOOTD;
		}
	}
#endif

	/* If OK so far, then do the command */
	if (!rc) {
		int newrep;

		if (ticks)
			*ticks = get_timer(0);
		rc = cmd_call(cmdtp, flag, argc, argv, &newrep);
		if (ticks)
			*ticks = get_timer(*ticks);
		*repeatable &= newrep;
	}
	if (rc == CMD_RET_USAGE)
		rc = cmd_usage(cmdtp);
	return rc;
}
Beispiel #19
0
int
main(int argc, char **argv) {
	int fd, d, j, k;
	char *p;

	/* egcs-2.91.66 is buggy and says:
	   blockdev.c:93: warning: `d' might be used uninitialized */
	d = 0;

	progname = argv[0];
	if ((p = strrchr(progname, '/')) != NULL)
		progname = p+1;

	setlocale(LC_ALL, "");
	bindtextdomain(PACKAGE, LOCALEDIR);
	textdomain(PACKAGE);

	if (argc < 2)
		usage();

	/* -V not together with commands */
	if (!strcmp(argv[1], "-V") || !strcmp(argv[1], "--version")) {
		printf("%s from %s\n", progname, util_linux_version);
		exit(0);
	}

	/* do each of the commands on each of the devices */
	/* devices start after last command */
	for (d = 1; d < argc; d++) {
		j = find_cmd(argv[d]);
		if (j >= 0) {
			if (bdcms[j].argtype == ARGINTA)
				d++;
			continue;
		}
		if (!strcmp(argv[d], "--")) {
			d++;
			break;
		}
		if (argv[d][0] != '-')
			break;
	}

	if (d >= argc)
		usage();

	for (k = d; k < argc; k++) {
		fd = open(argv[k], O_RDONLY, 0);
		if (fd < 0) {
			perror(argv[k]);
			exit(1);
		}
		do_commands(fd, argv, d);
	}
	return 0;
}
Beispiel #20
0
static void		handle_validated_cmd(t_state *state, char **cmds)
{
	char	*cmd;

	if ((cmd = find_cmd(state, cmds[0])))
	{
		run_cmd(&state->env, cmd, cmds);
		ft_strdel(&cmd);
	}
}
static void install_auto_complete_handler(const char *cmd,
		int (*complete)(int argc, char *argv[], char last_char, int maxv, char *cmdv[]))
{
	cmd_tbl_t *cmdtp;

	cmdtp = find_cmd(cmd);
	if (cmdtp == NULL)
		return;

	cmdtp->complete = complete;
}
Beispiel #22
0
main(int argc, char *argv[])
{ 
    int pid, cmd, i;
    char name[64];
    ucolor = 0;
    clearScreen(UMODE);
    printf("enter main() : argc = %d\n", argc);
    for (i=0; i<argc; i++)
        printf("argv[%d] = %s\n", i, argv[i]);

    while(1){
        pid = getpid();
        color = ucolor ? ucolor:0x000B + (pid % 5);// avoid black on black baground
        cmd?resetCursor(UMODE):1;
        printf("----------------------------------------------\n");
        printf("I am proc %din U mode: segment=%x\n", pid, (pid+1)*0x1000);
        show_menu();
        printf("Command ? ");
        getCurPos(UMODE);
        printf("                                                                      \n");
        setCurPos(ux_col,uy_row,UMODE);
        gets(name);
        clearScreenRegion(K_X_PRINT_OFFSET,80,U_Y_PRINT_OFFSET-1,24,UMODE);
        if (name[0]==0) 
            continue;

        cmd = find_cmd(name);
        
        getCurPos(UMODE);
        setCurPos(K_X_PRINT_OFFSET,U_Y_PRINT_OFFSET,UMODE);
        switch(cmd){
            case 0 : do_getpid();   break;
            case 1 : ps();          break;
            case 2 : chname();      break;
            case 3 : kmode();       break;
            case 4 : kswitch();     break;
            case 5 : wait();        break;
            case 6 : exit();        break;
            case 7 : fork();        break;
            case 8 : exec();        break;
            case 9 : ucolor = chcolor();     break;

            case 10: pipe();        break;
            case 11: pfd();         break;
            case 12: read_pipe();   break;
            case 13: write_pipe();  break;
            case 14: close_pipe();  break;
            
            default: invalid(name); break;
        }
        setCurPos(ux_col,uy_row,UMODE);
    }
}
int check_script_encrypt(char *script_buf)
{
    char *_argv[CONFIG_SYS_MAXARGS + 1];
    char *next_line = NULL;
    char *u8TempBuf = NULL;
    char *u8TempPtr = NULL;
    unsigned int lineNum = 0;
    UBOOT_TRACE("IN\n"); 

    // duplicate script for check_script_encrypt
    u8TempBuf=(char *)malloc(getScritSizeOfUpgradeImage());
    u8TempPtr=u8TempBuf;    
    if(u8TempBuf == NULL)
    {
        UBOOT_ERROR("no memory for check_script_encrypt!!\n");
        return -1;
    }
    memcpy(u8TempBuf,script_buf,getScritSizeOfUpgradeImage());

    for(lineNum=0;lineNum<2;lineNum++)//Check two lines
    { 
        next_line = get_script_next_line(&u8TempBuf);

        if((next_line==NULL) || (strlen(next_line)>MAX_LINE_SIZE))
        {
            UBOOT_DEBUG("%dth line not found\n",lineNum);
            free(u8TempPtr);
            return TRUE;
        }
        else
        {      /* parse command to argv */
            if ( parse_line (next_line, _argv) == 0) 
            {
                  UBOOT_DEBUG("%dth line doesn't find any argument \n",lineNum);
                  free(u8TempPtr);
                  return TRUE;
            }
            else
            {   /* Look up command in command table */
                if (find_cmd(_argv[0]) == NULL) 
                {                     
                      UBOOT_DEBUG("%dth line doesn't find any cmd \n",lineNum);
                      free(u8TempPtr);
                      return TRUE;
                }
            }
        }
    }
    free(u8TempPtr);

    UBOOT_TRACE("OK\n");     
    return FALSE;
}
Beispiel #24
0
int
docmd (int argc, char **argv)
{
  struct cmdtab *cmd = find_cmd (argv[0]);
  if (!cmd)
    {
      mu_error ("%u: unknown command %s", line_num, argv[0]);
      return 1;
    }
  else
    cmd->fun (argc, argv);
  return 0;
}
Beispiel #25
0
/*
 * Use puts() instead of printf() to avoid printf buffer overflow
 * for long help messages
 */
int do_help (cmd_tbl_t *cmdtp, bd_t *bd, int flag, int argc, char *argv[])
{
	int i;

	if (argc == 1) {	/* print short help (usage) */

		for (cmdtp=&cmd_tbl[0]; cmdtp->name; cmdtp++) {
			/* allow user abort */
			if (had_ctrlc() || ctrlc())
				return 1;

			if (cmdtp->usage == NULL)
				continue;
			puts (cmdtp->usage);
		}

		return 0;
	}

	/*
	 * command help (long version)
	 */
	for (i=1; i<argc; ++i) {
		if ((cmdtp = find_cmd(argv[i])) != NULL) {
#ifdef	CFG_LONGHELP
			/* found - print (long) help info */
			puts (cmdtp->name);
			putc (' ');
			if (cmdtp->help) {
				puts (cmdtp->help);
			} else {
				puts ("- No help available.\n");
			}
			putc ('\n');
#else	/* no long help available */
			if (cmdtp->usage)
				puts (cmdtp->usage);
#endif	/* CFG_LONGHELP */
			if(had_ctrlc())
				break;
		}
		else {
			printf ("Unknown command '%s' - try 'help'"
				" without arguments for list of all"
				" known commands\n\n",
				argv[i]
			);
		}
	}
 	return 0;
}
Beispiel #26
0
int main(int argc, char *argv[]) { 
	char name[64];
	int pid, cmd;
	int pd[2];

	while(1){

		printf("\n----------------------------------------------\n");
		#ifndef _LAB_3_
			printf("I am proc %d in U mode with ppid %d: running segment=%x\n",getpid(), getppid(), getcs());
		#else
			printf("I am proc "); getpid(); printf(" in U mode: running segment=%x\n", getcs());
		#endif

		#ifdef _SLEEPER_
			while(1) {
				printf("PID: %d PPID: %d\n", getpid(), getppid());
				sleep(5);
				return 0;
			}
		#endif

		show_menu();
		printf("Command? ");
		gets(name);
		printf("\n"); 
		if (name[0]==0) 
		continue;

		cmd = find_cmd(name);
		switch(cmd){
			case 0:		getpid();	break;
			case 1:		ps();		break;
			case 2:		chname();	break;
			case 3:		kswitch();	break;
			case 4:		wait();		break;
			case 5:		ufork();	break;
			case 6:		uexec();	break;
			case 7: 	exit();		break;
			case 8: 	pipe(pd);	break;
			case 9: 	pfd();		break;
			case 10:	uclose();	break;
			case 11:	uread();	break;
			case 12:	uwrite();	break;
			case 13:	usleep();	break;
			default:invalid(name);break;
		}
	}
}
Beispiel #27
0
void cm5200_fwupdate(void)
{
	cmd_tbl_t *bcmd;
	char *rsargs;
	char *tmp = NULL;
	char ka[16];
	char *argv[3] = { "bootm", ka, NULL };

	/* Check if rescue system is disabled... */
	if (getenv("norescue")) {
		printf(LOG_PREFIX "Rescue System disabled.\n");
		return;
	}

	/* Check if we have a USB storage device and load image */
	if (load_rescue_image(LOAD_ADDR))
		return;

	bcmd = find_cmd("bootm");
	if (!bcmd)
		return;

	sprintf(ka, "%lx", (ulong)LOAD_ADDR);

	/* prepare our bootargs */
	rsargs = getenv("rs-args");
	if (!rsargs)
		rsargs = RS_BOOTARGS;
	else {
		tmp = malloc(strlen(rsargs+1));
		if (!tmp) {
			printf(LOG_PREFIX "Memory allocation failed\n");
			return;
		}
		strcpy(tmp, rsargs);
		rsargs = tmp;
	}

	setenv("bootargs", rsargs);

	if (rsargs == tmp)
		free(rsargs);

	printf(LOG_PREFIX "Starting update system (bootargs=%s)...\n", rsargs);
	do_bootm(bcmd, 0, 2, argv);
}
Beispiel #28
0
int Parser_help(int argc, char **argv)
{
        char line[1024];
        char *next, *prev, *tmp;
        command_t *result, *ambig;
        int i;

        if ( argc == 1 ) {
                Parser_qhelp(argc, argv);
                return 0;
        }

        line[0]='\0';
        for ( i = 1 ;  i < argc ; i++ ) {
                strcat(line, argv[i]);
        }

        switch ( process(line, &next, top_level, &result, &prev) ) {
        case CMD_COMPLETE:
                fprintf(stderr, "%s: %s\n",line, result->pc_help);
                break;
        case CMD_NONE:
                fprintf(stderr, "%s: Unknown command.\n", line);
                break;
        case CMD_INCOMPLETE:
                fprintf(stderr,
                        "'%s' incomplete command.  Use '%s x' where x is one of:\n",
                        line, line);
                fprintf(stderr, "\t");
                for (i = 0; result->pc_sub_cmd[i].pc_name; i++) {
                        fprintf(stderr, "%s ", result->pc_sub_cmd[i].pc_name);
                }
                fprintf(stderr, "\n");
                break;
        case CMD_AMBIG:
                fprintf(stderr, "Ambiguous command \'%s\'\nOptions: ", line);
                while( (ambig = find_cmd(prev, result, &tmp)) ) {
                        fprintf(stderr, "%s ", ambig->pc_name);
                        result = ambig + 1;
                }
                fprintf(stderr, "\n");
                break;
        }
        return 0;
}
Beispiel #29
0
/* Calls bootm with the parameters given */
static int call_bootm(int argc, char * const argv[], const char *subcommand[])
{
	char *bootm_argv[5];

	int i = 0;
	int ret = 0;
	int j;

	/* create paramter array */
	bootm_argv[0] = "do_bootm";
	switch (argc) {
	case 3:
		bootm_argv[4] = argv[2]; /* fdt addr */
	case 2:
		bootm_argv[3] = argv[1]; /* initrd addr */
	case 1:
		bootm_argv[2] = argv[0]; /* kernel addr */
	}


	/*
	 * - do the work -
	 * exec subcommands of do_bootm to init the images
	 * data structure
	 */
	while (subcommand[i] != NULL) {
		bootm_argv[1] = (char *)subcommand[i];
		debug("args %d: %s %s ", argc, bootm_argv[0], bootm_argv[1]);
		for (j = 0; j < argc; j++)
			debug("%s ", bootm_argv[j + 2]);
		debug("\n");

		ret = do_bootm(find_cmd("do_bootm"), 0, argc+2,
			bootm_argv);
		debug("Subcommand retcode: %d\n", ret);
		i++;
	}

	if (ret) {
		printf("ERROR prep subcommand failed!\n");
		return -1;
	}

	return 0;
}
Beispiel #30
0
/* take a string and execute the function or print help */
int execute_line(char * line)
{
        command_t         *cmd, *ambig;
        char *prev;
        char *next, *tmp;
        char *argv[MAXARGS];
        int         i;
        int rc = 0;

        switch (process(line, &next, top_level, &cmd, &prev)) {
        case CMD_AMBIG:
                fprintf(stderr, "Ambiguous command \'%s\'\nOptions: ", line);
                while( (ambig = find_cmd(prev, cmd, &tmp)) ) {
                        fprintf(stderr, "%s ", ambig->pc_name);
                        cmd = ambig + 1;
                }
                fprintf(stderr, "\n");
                break;
        case CMD_NONE:
                fprintf(stderr, "No such command, type help\n");
                break;
        case CMD_INCOMPLETE:
                fprintf(stderr,
                        "'%s' incomplete command.  Use '%s x' where x is one of:\n",
                        line, line);
                fprintf(stderr, "\t");
                for (i = 0; cmd->pc_sub_cmd[i].pc_name; i++) {
                        fprintf(stderr, "%s ", cmd->pc_sub_cmd[i].pc_name);
                }
                fprintf(stderr, "\n");
                break;
        case CMD_COMPLETE:
                i = line2args(line, argv, MAXARGS);
                rc = (cmd->pc_func)(i, argv);

                if (rc == CMD_HELP)
                        fprintf(stderr, "%s\n", cmd->pc_help);

                break;
        }

        return rc;
}