Пример #1
0
const char* EnterRunCfgFN(configure_slot_t slot_fn, configure_slot_t slot_js)
{
	int ret = 0;
	const char* run_cfg_fn = strings_storage_get(slot_fn, 0);
	char run_cfg_fn_new[MAX_PATH];
	const char *run_cfg_fn_js;
	do {
		log_printf(
			"\n"
			"Enter a custom name for this configuration, or leave blank to use the default\n"
			" (%s): ", run_cfg_fn
		);
		console_read(run_cfg_fn_new, sizeof(run_cfg_fn_new));
		if(run_cfg_fn_new[0]) {
			run_cfg_fn = strings_sprintf(slot_fn, "%s", run_cfg_fn_new);
		}
		run_cfg_fn_js = strings_sprintf(slot_js, "%s.js", run_cfg_fn);
		if(PathFileExists(run_cfg_fn_js)) {
			log_printf("\"%s\" already exists. ", run_cfg_fn_js);
			ret = !Ask("Overwrite?");
		} else {
			ret = 0;
		}
	} while(ret);
	return run_cfg_fn;
}
Пример #2
0
void PMAPI PM_saveConsoleState(void *stateBuf,int console_id)
{
#ifdef __QNXNTO__
    int     fd;
    int     flags;

    if ((fd = open("/dev/con1", O_RDWR)) == -1)
        return;
    flags = _CONCTL_INVISIBLE_CHG | _CONCTL_INVISIBLE;
    devctl(fd, DCMD_CHR_SERCTL, &flags, sizeof flags, 0);
    close(fd);
#else
    uchar   *buf = &((uchar*)stateBuf)[PM_getVGAStateSize()];

    /* Save QNX 4 console state */
    console_read(cc, -1, 0, NULL, 0,
        (int *)buf+1, (int *)buf+2, NULL);
    *(int *)buf = console_ctrl(cc, -1,
        CONSOLE_NORESIZE | CONSOLE_NOSWITCH | CONSOLE_INVISIBLE,
        CONSOLE_NORESIZE | CONSOLE_NOSWITCH | CONSOLE_INVISIBLE);

    /* Save state of VGA registers */
    PM_saveVGAState(stateBuf);
#endif
}
Пример #3
0
static void lnp_console_execute_command(char *out_buffer, int buffer_len, 
		int function_id, char *args) {
	switch (function_id) {
		case COMMAND_ID:
			console_id(out_buffer, buffer_len, args);
			break;
		case COMMAND_WRITE:
			console_write(out_buffer, buffer_len, args);
			break;
		case COMMAND_READ:
			console_read(out_buffer, buffer_len, args);
			break;
		case COMMAND_FLUSH:
			console_flush(out_buffer, buffer_len, args);
			break;
		case COMMAND_CONNECTIONS:
			console_connections(out_buffer, buffer_len, args);
			break;
		case COMMAND_HISTORY:
			console_history(out_buffer, buffer_len, args);
			break;
		case COMMAND_CONNECT:
			console_connect(out_buffer, buffer_len, args);
			break;
		case COMMAND_KEYS:
			console_print_keys(out_buffer, buffer_len, args);
			break;
	}
}
Пример #4
0
ssize_t
lisp_read(HANDLE hfile, void *buf, unsigned int count) {
  switch(GetFileType(hfile)) {
  case FILE_TYPE_CHAR:
    return console_read(hfile, buf, count);
    break;

  case FILE_TYPE_PIPE:          /* pipe or one of these newfangled socket things */
    {
      int socktype, optlen = sizeof(int);
      if ((getsockopt((SOCKET)hfile, SOL_SOCKET, SO_TYPE, (char *)&socktype, &optlen) != 0) && (GetLastError() == WSAENOTSOCK)) {
        return pipe_read(hfile, buf, count);
      }
    }
    /* It's a socket, fall through */
    
  case FILE_TYPE_DISK:
    return lisp_standard_read(hfile, buf, count);
    break;

  default:
    errno = EBADF;
    return -1;
  }
}
Пример #5
0
/*-----------------------------------------------------------------------------------*/
char
ctk_arch_getkey(void)
{
  char k;

  console_read();
  k = keys[keys_out++];

  available--;
  return k;
}
Пример #6
0
void *readFromConsole() {
    while (1) {
        P_kt_sem(consoleWait);
        char newChar = console_read();
        if (CRBisFull() == 0) {
            writeCRB(&newChar);
            V_kt_sem(nelem);
        }
    }
    //V_kt_sem(readok);
}
Пример #7
0
static void console_readnum(int *num,unsigned char *ch)
{
    int total = 0;

    for (;;) {
	total = (total * 10) + (*ch - '0');
	while (console_read(ch,1) != 1) { POLL(); }
	if (!((*ch >= '0') && (*ch <= '9'))) break;
	}

    *num = total;
}
Пример #8
0
static int console_command(console_state cs)
{
  int i,o;
  int ntokens;
  char req[MAX_REQ];
  char tokens[MAX_TOK][MAX_TOKLEN];

  struct console_cmd_params_t p;
  memset(&p,0,sizeof(struct console_cmd_params_t));
  p.cs = cs;

  switch (console_read(cs,req,sizeof(req))) 
    {
    case -1:
      console_write(cs,"   cannot read command\n");
      return CON_QUIT;
    case 0:
      return CON_CMD_NONE;
    default:
      // DBG_PRINT("wsim:con:main: read -%s-\n",req);
      break;
    }

  if ((ntokens = get_tokens(req,tokens,console_ui_delim)) == 0)
    {
      return console_cmd_help(&p);
    }
  
  for(i=0; i < cs->cmd_max ; i++)
    {
      if (strcasecmp(cs->commands[i].name,tokens[0]) == 0)
	{
	  if (cs->commands[i].nb_option > (ntokens - 1))
	    {
	      console_write(cs,"  incorrect number of arguments for %s\n",tokens[0]);
	      return CON_CMD_ERROR;
	    }
	  for(o=0; o < ntokens; o++)
	    {
	      p.options[o] = tokens[o+1];
	    }
	  
	  p.nopt = ntokens - 1;
	  return cs->commands[i].fun(&p);
	}
    }

  console_write(cs,"   unknown command %s\n\n",tokens[0]);

  return CON_CMD_ERROR;
}
Пример #9
0
void console_buf(struct CharBuf *charbuf)
{
	while(1) {
		P_kt_sem(consoleWait);
		P_kt_sem(nslots);
		charbuf->buffer[charbuf->tail] = console_read();
		charbuf->tail = (charbuf->tail+1) % 256;

		V_kt_sem(nelem); 
		if (bufCount < 256)
			bufCount++;
	}

}
Пример #10
0
int Ask(const char *question)
{
	int ret = 0;
	while(ret != 'y' && ret != 'n') {
		char buf[2];
		if(question) {
			log_printf(question);
		}
		log_printf(" (y/n) ");

		console_read(buf, sizeof(buf));
		ret = tolower(buf[0]);
	}
	return ret == 'y';
}
Пример #11
0
int console_read_guarantee( Console* cons, uchar* data, uint size )
{
	uint complete = 0;
	int status = 0;

	while( complete < size ) {
		status = console_read( cons, data + complete, size );
		if( status != ERR_NONE ){
			return status;
		}
		complete += cons->last_read;
	}

	return ERR_NONE;
}
static void cfe_autostart(void)
{
    char *env;
    int noauto = 0;
    char ch = 0;
    uint64_t now;
    uint64_t timeout;
    int delay = 1;      /* 1s */

    env = env_getenv("STARTUP");
    if (!env) return;

    leds_on();

    xprintf("Auto boot\n");

    now = _getticks();
    timeout = now + delay *(cfe_cpu_speed/(CPUCFG_CYCLESPERCPUTICK));

    while(now < timeout)
    {
        while (console_status()) {
            console_read(&ch,1);
            if (ch == 3)
                noauto = TRUE;	/* Ctrl-C means no auto */
        }

        if (recovery_button_status())
        {
            noauto = TRUE;
        }

        if (noauto == TRUE)
            break;

        now = _getticks();
    }

    leds_off();

    if (noauto) {
	xprintf("Startup canceled\n");
	return;
	}

    ui_docommands(env);
}
Пример #13
0
void debugconsole_init()
{
	int read_offset = 0;
	int read;
	default_console->info.handle_backspace = 0;

	while (1)
	{
		printPrompt();

		read_offset = 0;
		while (read_offset < 255)
		{
			read = console_read(NULL, currentLine + read_offset, 1);

			if (currentLine[read_offset] == 0x8 || currentLine[read_offset] == 0x7f)
			{
				if (read_offset == 0) continue;
				currentLine[read_offset--] = 0;
				currentLine[read_offset] = 0;
				console_write2(NULL, "\x08");
				continue;
			}

			if (currentLine[read_offset] == '\n' || currentLine[read_offset] == '\r')
			{
				currentLine[read_offset] = '\0';
				break;
			}

			read_offset += read;
		}

        char *strtok;
        char *command = kmalloc(sizeof(char) * 255);
        char *arg = kmalloc(sizeof(char) * 32);
        char **argv = kmalloc(sizeof(char*) * 32);
        uint8_t argc = 0;

        command = strtok_r(currentLine, " ", &strtok);
        while ((arg = strtok_r(NULL, " ", &strtok))) {
            argv[argc++] = arg;
        }

		executeCommand(command, argc, argv);
	}
}
Пример #14
0
//Console buffer. Code buffers input from the console until a program requests it with a call to read(). CREATE.
//a thread whose sole job is to read characters from the console and put them into a buffer.
void *console_buffer(void *arg)
{
  //printf("Goes into the console_buffer\n");
  //  int cbTail = 0;
  //int cbHead =0;
  //char *filename = (char *)arg;
  //these are used to convert the char to int and place into buf
  int i;
  char c;
  //int stop =1;
  PIPE *pipe= (PIPE *)arg;
  //printf("Enters console_buffer\n");
  //while(stop)
  while(pipe->ref_count!=0) //bc it it is then you have to deallocate
    {
      P_kt_sem(consoleWait);
      //printf("P_kt_sem(consoleWait): %i\n",kt_getval(consoleWait));
      //have to check if the buffer is full or not
      //printf("Enters while loop in console\n");
      //if not full yet
      //if (cbTail !=cbSize)
      if (pipe->pbuf_tail!=256)
        {
      	  //printf("We are reading from the console into the buffer\n");	  
      	  //currently a char
      	  c = console_read();
      	  //	  printf("Reading from console: %c\n", c);
      	  //conversion to a int bc buffer holds ints only
      	  i = c -'0';
      	  //  printf("Coverted c into i: %i\n",i);
      	  //enqueue - insert it into the buffer cb, enter through the back! and 256 size of the buffer
          //cbTail = (cbTail+1)%256; //this is a shortcut
          pipe->pbuf_tail = (pipe->pbuf_tail+1)%256;
      	  pipe->read_buf[pipe->pbuf_tail] = i;
      	  //printf("Placed into cb[%i]: %i\n", cbTail, cb[cbTail]);
      	  //	 	  printf("This is in index %i: %c %i\n", cbTail, c, cb[cbTail]);
      	  
      	  
      	  //Step 17:
      	  V_kt_sem(nelem);
      	  //printf("V_kt_sem(nelem): %i\n",kt_getval(nelem));
      	}
    }
  //  printf("Exits while loop in console buffer\n");
  kt_exit();
}
Пример #15
0
int console_service(struct sim *s)
{
	/* fpga --> console */
	SERIAL_SOURCE_ACK = 1;
	if(SERIAL_SOURCE_STB == 1) {
		s->serial_tx_data = SERIAL_SOURCE_DATA;
		console_write(s, &(s->serial_tx_data), 1);
	}

	/* console --> fpga */
	SERIAL_SINK_STB = 0;
	if(console_read(s, &(s->serial_rx_data)))
	{
		SERIAL_SINK_STB = 1;
		SERIAL_SINK_DATA = s->serial_rx_data;
	}
	return 0;
}
Пример #16
0
void *console_buf_read(void *arg) {
	char c;
	int i;

	while (sysStopRead != 1) {
		P_kt_sem(consoleWait);

		if (!full(consoleBufferTail, consoleSize)) {
			c = console_read();
			i = c - '0';

			add_to_queue(consoleBuffer, &consoleBufferTail, i);
			V_kt_sem(nelem);
		}
	}

	kt_exit();
}
Пример #17
0
/**
 * Executes the issued command
 */
void console_exec(char *buf) {
    if(strncmp(buf, "cd", 2) == 0) {
        console_cd(dir, buf);
    } else if(strncmp(buf, "start", 5) == 0) {
        console_start(dir, buf);
    } else if(strncmp(buf, "read", 4) == 0) {
        console_read(dir, buf);
    } else if(strncmp(buf, "write", 5) == 0) {
        console_write(dir, buf);
    } else if(strncmp(buf, "touch", 5) == 0) {
        console_touch(dir, buf);
    } else if(strncmp(buf, "delete", 6) == 0) {
        console_delete(dir, buf);
    } else if(strcmp(buf, "hoho") == 0) {
        printk("hoho\n");
    } else if(strcmp(buf, "help") == 0) {
        printk("Help:\nhoho - prints hoho\nhelp - shows help\nmeminfo - prints RAM info\ncpuinfo - shows CPU info\nls - shows filesystem devices\nread - reads a file\nstart - starts a program\nclear - clears the screen\nhalt - shuts down\nreboot - reboots the pc\n");
    } else if(strcmp(buf, "meminfo") == 0) {
        print_meminfo();
    } else if(strcmp(buf, "cpuinfo") == 0) {
        printk("%s\n", get_cpu_vendor(0));
    } else if(strcmp(buf, "ls") == 0) {
        if(dir[0] == 0) {
            vfs_ls();
        } else {
            vfs_ls_dir(dir);
        }
    } else if(strcmp(buf, "clear") == 0) {
        clear();
    } else if(strcmp(buf, "proc") == 0) {
        print_procs();
    } else if(strcmp(buf, "halt") == 0) {
        printk("Shutting down\n");
        halt();
        while(1);
    } else if(strcmp(buf, "reboot") == 0) {
        printk("Rebooting\n");
        reboot();
    } else {
        printk("Command not found\n");
    }
}
Пример #18
0
int
main(int argc, char **argv)
{
#ifdef	NOTHREADS
	fd_set fds;
	int rv;
#endif

	if (console_init(0, 1, cmds, sizeof (cmds) / sizeof (*cmds), exitcb,
	    "test> ") < 0) {
		fprintf(stderr, "console_init failed\n");
		exit(1);
	}

#ifdef	NOTHREADS
	FD_ZERO(&fds);
	FD_SET(0, &fds);
	while ((rv = select(1, &fds, NULL, NULL, NULL)) >= 0) {
		if (FD_ISSET(0, &fds)) {
#ifdef	USE_READLINE
			console_read_char();
#else
			console_read();
#endif	/* USE_READLINE */
		}
		else {
			printf("fd other than stdin ready\n");
		}
	}
#else
	for (;;) {
		sleep(20);
	}
#endif

	exit(0);
}
Пример #19
0
// --------------------------------------------------------------------------
//
// Function
//		Name:    FdGetLine::ReadMore()
//		Purpose: Read more bytes from the handle, possible the
//			 console, into mBuffer and return the number of
//			 bytes read, 0 on EOF or -1 on error.
//		Created: 2011/04/22
//
// --------------------------------------------------------------------------
int FdGetLine::ReadMore(int Timeout)
{
	int bytes;
	
#ifdef WIN32
	if (mFileHandle == _fileno(stdin))
	{
		bytes = console_read(mBuffer, sizeof(mBuffer));
	}
	else
	{
		bytes = ::read(mFileHandle, mBuffer, sizeof(mBuffer));
	}
#else // !WIN32
	bytes = ::read(mFileHandle, mBuffer, sizeof(mBuffer));
#endif // WIN32

	if(bytes == 0)
	{
		mPendingEOF = true;
	}

	return bytes;
}
Пример #20
0
/*
 *  board_final_init()
 *
 *  Do any final initialization, such as adding commands to the
 *  user interface.
 *
 *  If you don't want a user interface, put the startup code here.
 *  This routine is called just before CFE starts its user interface.
 *
 *  Input parameters:
 *     nothing
 *
 *  Return value:
 *     nothing
 */
void
board_final_init(void)
{
	char *addr, *mask, *wait_time;
	char buf[512], *cur = buf;
#ifdef CFG_ROMBOOT
	char *laddr = NULL;
#endif
#if !CFG_SIM
	char *boot_cfg = NULL;
	char *go_cmd = "go;";
#endif
	int commit = 0;
	uint32 ncdl;
#if CFG_WL && CFG_WLU && CFG_SIM
	char *ssid;
#endif

	ui_init_bcm947xxcmds();

	/* Force commit of embedded NVRAM */
	commit = restore_defaults;

	/* Set the SDRAM NCDL value into NVRAM if not already done */
	if ((getintvar(NULL, "sdram_ncdl") == 0) &&
	    ((ncdl = si_memc_get_ncdl(sih)) != 0)) {
		sprintf(buf, "0x%x", ncdl);
		nvram_set("sdram_ncdl", buf);
		commit = 1;
	}

	/* Set the bootloader version string if not already done */
	sprintf(buf, "CFE %s", EPI_VERSION_STR);
	if (strcmp(nvram_safe_get("pmon_ver"), buf) != 0) {
		nvram_set("pmon_ver", buf);
		commit = 1;
	}

	/* Set the size of the nvram area if not already done */
	sprintf(buf, "%d", MAX_NVRAM_SPACE);
	if (strcmp(nvram_safe_get("nvram_space"), buf) != 0) {
		nvram_set("nvram_space", buf);
		commit = 1;
	}

#ifdef RTL8365MB
	int ret = -1, retry = 0;
	rtk_port_mac_ability_t pa;

	GPIO_INIT();
	for(retry = 0; ret && retry < 10; ++retry)
	{
		ret = rtk_switch_init();
		if(ret) cfe_usleep(10000);
		else break;
	}
	printf("rtl8354mb initialized(%d)(retry %d) %s\n", ret, retry, ret?"failed":"");

        ret = rtk_port_phyEnableAll_set(1);
        if(ret)	printf("rtk port_phyEnableAll Failed!(%d)\n", ret);
	else printf("rtk port_phyEnableAll ok\n");

        /* configure & set GMAC ports */
        pa.forcemode       = MAC_FORCE;
        pa.speed           = SPD_1000M;
        pa.duplex          = FULL_DUPLEX;
        pa.link            = 1;
        pa.nway            = 0;
        pa.rxpause         = 0;
        pa.txpause         = 0;

        ret = rtk_port_macForceLinkExt_set(EXT_PORT0, MODE_EXT_RGMII, &pa);
        if(ret)	printf("rtk port_macForceLink_set ext_Port0 Failed!(%d)\n", ret);
	else printf("rtk port_macForceLink_set ext_Port0 ok\n");	

        /* asic chk */
        rtk_uint32 retVal, retVal2;
        rtk_uint32 data, data2;
        if((retVal = rtl8367c_getAsicReg(0x1311, &data)) != RT_ERR_OK || (retVal2 = rtl8367c_getAsicReg(0x1305, &data2)) != RT_ERR_OK) {
                printf("get failed(%d)(%d). (%x)(supposed to be 0x1016)\n", retVal, retVal2, data);
        }
        else {      /* get ok, then chk reg*/
                printf("get ok, chk 0x1311:%x(0x1016), 0x1305:%x(b4~b7:0x1)\n", data, data2);
                if(data != 0x1016){
                        printf("\n!! rtl reg 0x1311 error: (%d)(get %x)\n", retVal, data);
                }
                if((data2 & 0xf0) != 0x10) {
                        printf("\n!! rtl reg 0x1305 error: (%d)(get %x)\n", retVal, data2);
                }
        }

        /* reset tx/rx delay */
        retVal = rtk_port_rgmiiDelayExt_set(EXT_PORT0, 1, 4);
        if (retVal != RT_ERR_OK)
                printf("\n!! rtl set delay failed (%d)\n", retVal);
#endif

#if CFG_FLASH || CFG_SFLASH || CFG_NFLASH
#if !CFG_SIM
	/* Commit NVRAM only if in FLASH */
	if (
#ifdef BCMNVRAMW
		!nvram_inotp() &&
#endif
		commit) {
		printf("Committing NVRAM...");
		nvram_commit();
		printf("done\n");
		if (restore_defaults) {
#ifdef BCM_DEVINFO
                        /* devinfo nvram hash table sync */
                        devinfo_nvram_sync();
#endif
			printf("Waiting for wps button release...");
			reset_release_wait();
			printf("done\n");
		}
	}

	/* Reboot after restoring defaults */
	if (restore_defaults)
		si_watchdog(sih, 1);
#endif	/* !CFG_SIM */
#else
	if (commit)
		printf("Flash not configured, not commiting NVRAM...\n");
#endif /* CFG_FLASH || CFG_SFLASH || CFG_NFLASH */

	/*
	 * Read the wait_time NVRAM variable and set the tftp max retries.
	 * Assumption: tftp_rrq_timeout & tftp_recv_timeout are set to 1sec.
	 */
	if ((wait_time = nvram_get("wait_time")) != NULL) {
		tftp_max_retries = atoi(wait_time);
		if (tftp_max_retries > MAX_WAIT_TIME)
			tftp_max_retries = MAX_WAIT_TIME;
		else if (tftp_max_retries < MIN_WAIT_TIME)
			tftp_max_retries = MIN_WAIT_TIME;
	}
#ifdef CFG_ROMBOOT
	else if (board_bootdev_rom(sih)) {
		tftp_max_retries = 10;
	}
#endif

	/* Configure network */
	if (cfe_finddev("eth0")) {
		int res;

		if ((addr = nvram_get("lan_ipaddr")) &&
		    (mask = nvram_get("lan_netmask")))
			sprintf(buf, "ifconfig eth0 -addr=%s -mask=%s",
			        addr, mask);
		else
			sprintf(buf, "ifconfig eth0 -auto");

		res = ui_docommand(buf);

#ifdef CFG_ROMBOOT
		/* Try indefinite netboot only while booting from ROM
		 * and we are sure that we dont have valid nvram in FLASH
		 */
		while (board_bootdev_rom(sih) && !addr) {
			char ch;

			cur = buf;
			/* Check if something typed at console */
			if (console_status()) {
				console_read(&ch, 1);
				/* Check for Ctrl-C */
				if (ch == 3) {
					if (laddr)
						MFREE(osh, laddr, MAX_SCRIPT_FSIZE);
					xprintf("Stopped auto netboot!!!\n");
					return;
				}
			}

			if (!res) {
				char *bserver, *bfile, *load_ptr;

				if (!laddr)
					laddr = MALLOC(osh, MAX_SCRIPT_FSIZE);

				if (!laddr) {
					load_ptr = (char *) 0x00008000;
					xprintf("Failed malloc for boot_script, Using :0x%x\n",
						(unsigned int)laddr);
				}
				else {
					load_ptr = laddr;
				}
				bserver = (bserver = env_getenv("BOOT_SERVER"))
					? bserver:"192.168.1.1";

				if ((bfile = env_getenv("BOOT_FILE"))) {
					int len;

					if (((len = strlen(bfile)) > 5) &&
					    !strncmp((bfile + len - 5), "cfesh", 5)) {
						cur += sprintf(cur,
						"batch -raw -tftp -addr=0x%x -max=0x%x %s:%s;",
							(unsigned int)load_ptr,
							MAX_SCRIPT_FSIZE, bserver, bfile);
					}
					if (((len = strlen(bfile)) > 3)) {
						if (!strncmp((bfile + len - 3), "elf", 3)) {
							cur += sprintf(cur,
							"boot -elf -tftp -max=0x5000000 %s:%s;",
							bserver, bfile);
						}
						if (!strncmp((bfile + len - 3), "raw", 3)) {
							cur += sprintf(cur,
							"boot -raw -z -tftp -addr=0x00008000"
							" -max=0x5000000 %s:%s;",
							bserver, bfile);
						}
					}
				}
				else {  /* Make last effort */
					cur += sprintf(cur,
						"batch -raw -tftp -addr=0x%x -max=0x%x %s:%s;",
						(unsigned int)load_ptr, MAX_SCRIPT_FSIZE,
						bserver, "cfe_script.cfesh");
					cur += sprintf(cur,
						"boot -elf -tftp -max=0x5000000 %s:%s;",
						bserver, "boot_file.elf");
					cur += sprintf(cur,
						"boot -raw -z -tftp -addr=0x00008000"
						" -max=0x5000000 %s:%s;",
						bserver, "boot_file.raw");
				}

				ui_docommand(buf);
				cfe_sleep(3*CFE_HZ);
			}

			sprintf(buf, "ifconfig eth0 -auto");
			res = ui_docommand(buf);
		}
#endif /* CFG_ROMBOOT */
	}
#if CFG_WL && CFG_WLU && CFG_SIM
	if ((ssid = nvram_get("wl0_ssid"))) {
		sprintf(buf, "wl join %s", ssid);
		ui_docommand(buf);
	}
#endif

#if !CFG_SIM
	/* Try to run boot_config command if configured.
	 * make sure to leave space for "go" command.
	 */
	if ((boot_cfg = nvram_get("boot_config"))) {
		if (strlen(boot_cfg) < (sizeof(buf) - sizeof(go_cmd)))
			cur += sprintf(cur, "%s;", boot_cfg);
		else
			printf("boot_config too long, skipping to autoboot\n");
	}

	/* Boot image */
	cur += sprintf(cur, go_cmd);
#endif	/* !CFG_SIM */

	/* Startup */
	if (cur > buf)
		env_setenv("STARTUP", buf, ENV_FLG_NORMAL);
}
Пример #21
0
static int _tftpd_open(tftp_info_t *info,char *hostname,char *filename,int mode)
{
    ebuf_t *buf = NULL;
    uint16_t type;
    int res;
    int retries;
    char ch = 0;
#ifdef RESCUE_MODE
	uint8_t asuslink[13] = "ASUSSPACELINK";
	uint8_t maclink[13]="snxxxxxxxxxxx";
	unsigned char tftpmask[4] = { 0xff, 0xff, 0xff, 0x00 };
	int i;
	char tftpnull;
	uint8_t ipaddr[4] = { 0xc0, 0xa8, 0x01, 0x0c };
	uint8_t hwaddr[6] = { 0x00, 0xe0, 0x18, 0x00, 0x3e, 0xc4 };
#endif

    /*
     * Open a UDP socket
     */    

    info->tftp_socket = udp_socket(UDP_PROTO_TFTP);
    info->tftp_lastblock = 0;
    info->tftp_error = 0;
    info->tftp_filemode = mode;

    /*
     * Listen for requests
     */

    res = udp_bind(info->tftp_socket,UDP_PROTO_TFTP);
    if (res < 0) return res;

    res = CFE_ERR_TIMEOUT;

    for (retries = 0; retries < tftp_max_retries; retries++) {
	while (console_status()) {
	    console_read(&ch,1);
	    if (ch == 3) break;
	}
	if (ch == 3) {
	    res = CFE_ERR_INTR;
	    break;
	}

	buf = udp_recv_with_timeout(info->tftp_socket,tftp_recv_timeout);
	if (buf == NULL) continue;

	/*
	 * Process the request
	 */

	ebuf_get_u16_be(buf,type);

	switch (type) {
	    case TFTP_OP_RRQ:
#ifdef RESCUE_MODE
                         udp_connect(info->tftp_socket,(uint16_t) buf->eb_usrdata);
                         ackport = buf->eb_usrdata;
                         memcpy(info->tftp_ipaddr,buf->eb_usrptr,IP_ADDR_LEN);
                         info->tftp_blknum = 1;
                         info->tftp_blklen = 0;
                         for (i=0; i<13; i++) {
                                if (buf->eb_ptr[i] != asuslink[i])
                                                break;
                         }
                         if (i==13) {
                                tftpipfrom[0]=buf->eb_ptr[16];
                                tftpipfrom[1]=buf->eb_ptr[15];
                                tftpipfrom[2]=buf->eb_ptr[14];
                                tftpipfrom[3]=buf->eb_ptr[13];
                                tftpipto[0]=buf->eb_usrptr[0];
                                tftpipto[1]=buf->eb_usrptr[1];
                                tftpipto[2]=buf->eb_usrptr[2];
                                tftpipto[3]=buf->eb_usrptr[3];
                                        net_setparam(NET_IPADDR,tftpipfrom);
                                        net_setparam(NET_NETMASK,tftpmask);
                                        net_setparam(NET_GATEWAY,tftpipfrom);
                                        ui_myshowifconfig();
                                        net_setnetvars();
                                        for (i=0; i<4; i++)
                                                ipaddr[i]=tftpipto[i];
                                        for (i=0; i<6; i++)
                                                hwaddr[i]=buf->eb_data[6+i];
                                        buf = udp_alloc();
                                        if (!buf) {
                                                res = CFE_ERR_TIMEOUT;
                                                break;
                                        }
                                        ebuf_append_u16_be(buf, 3);
                                        ebuf_append_u16_be(buf, 1);
                                        ebuf_append_bytes(buf,&tftpnull, 0);
                                        arp_delete(ipaddr);
                                        arp_add(ipaddr,hwaddr);
                                        udp_send(info->tftp_socket, buf, tftpipto);
                                }
                                else {
                                        for (i=0; i<13; i++) {
                                                if (buf->eb_ptr[i] != maclink[i])
                                                        break;
                                        }
                                        if (i==13) {
                                                tftpipfrom[0]=buf->eb_ptr[16];
                                                tftpipfrom[1]=buf->eb_ptr[15];
                                                tftpipfrom[2]=buf->eb_ptr[14];
                                                tftpipfrom[3]=buf->eb_ptr[13];
                                                tftpipto[0]=buf->eb_usrptr[0];
                                                tftpipto[1]=buf->eb_usrptr[1];
                                                tftpipto[2]=buf->eb_usrptr[2];
                                                tftpipto[3]=buf->eb_usrptr[3];
                                                net_setparam(NET_IPADDR,tftpipfrom);
                                                net_setparam(NET_NETMASK,tftpmask);
                                                net_setparam(NET_GATEWAY,tftpipfrom);
                                                ui_myshowifconfig();
                                                net_setnetvars();
                                                for (i=0; i<4; i++)
                                                        ipaddr[i]=tftpipto[i];
                                                for (i=0; i<6; i++)
                                                        hwaddr[i]=buf->eb_data[6+i];
                                                buf = udp_alloc();
                                                if (!buf) {
                                                        res = CFE_ERR_TIMEOUT;
                                                break;
                                        }
                                        ebuf_append_u16_be(buf, 3);
                                        ebuf_append_u16_be(buf, 1);
                                        ebuf_append_bytes(buf,&tftpnull, 0);
                                        arp_delete(ipaddr);
                                        arp_add(ipaddr,hwaddr);
                                        udp_send(info->tftp_socket, buf, tftpipto);
                                }
                        }
                        res = CFE_ERR_TIMEOUT;
#else
		udp_connect(info->tftp_socket,(uint16_t) buf->eb_usrdata);
		memcpy(info->tftp_ipaddr,buf->eb_usrptr,IP_ADDR_LEN);
		info->tftp_blknum = 1;
		info->tftp_blklen = 0;
		res = 0;
#endif
		break;

	    case TFTP_OP_WRQ:
		udp_connect(info->tftp_socket,(uint16_t) buf->eb_usrdata);
		memcpy(info->tftp_ipaddr,buf->eb_usrptr,IP_ADDR_LEN);
		info->tftp_blknum = 0;
		res = _tftp_readmore(info);
		break;

	    default:
		/* 
		 * we aren't expecting any of these messages
		 */
		res = CFE_ERR_PROTOCOLERR;
		break;
	}

	udp_free(buf);
	break;
    }

    if (res) {
	udp_close(info->tftp_socket);
	info->tftp_socket = -1;
    }

    return res;
}
static int _tftpd_open(tftp_info_t *info,char *hostname,char *filename,int mode)
{
    ebuf_t *buf = NULL;
    uint16_t type;
    int res;
    int retries;
    char ch = 0;

    /*
     * Open a UDP socket
     */    

    info->tftp_socket = udp_socket(UDP_PROTO_TFTP);
    info->tftp_lastblock = 0;
    info->tftp_error = 0;
    info->tftp_filemode = mode;

    /*
     * Listen for requests
     */

    res = udp_bind(info->tftp_socket,UDP_PROTO_TFTP);
    if (res < 0) return res;

    res = CFE_ERR_TIMEOUT;

    for (retries = 0; retries < tftp_max_retries; retries++) {
	while (console_status()) {
	    console_read(&ch,1);
	    if (ch == 3) break;
	}
	if (ch == 3) {
	    res = CFE_ERR_INTR;
	    break;
	}

	buf = udp_recv_with_timeout(info->tftp_socket,tftp_recv_timeout);
	if (buf == NULL) continue;

	/*
	 * Process the request
	 */

	ebuf_get_u16_be(buf,type);

	switch (type) {
	    case TFTP_OP_RRQ:
		udp_connect(info->tftp_socket,(uint16_t) buf->eb_usrdata);
		memcpy(info->tftp_ipaddr,buf->eb_usrptr,IP_ADDR_LEN);
		info->tftp_blknum = 1;
		info->tftp_blklen = 0;
		res = 0;
		break;

	    case TFTP_OP_WRQ:
		udp_connect(info->tftp_socket,(uint16_t) buf->eb_usrdata);
		memcpy(info->tftp_ipaddr,buf->eb_usrptr,IP_ADDR_LEN);
		info->tftp_blknum = 0;
		res = _tftp_readmore(info);
		break;

	    default:
		/* 
		 * we aren't expecting any of these messages
		 */
		res = CFE_ERR_PROTOCOLERR;
		break;
	}

	udp_free(buf);
	break;
    }

    if (res) {
	udp_close(info->tftp_socket);
	info->tftp_socket = -1;
    }

    return res;
}
Пример #23
0
int console_readline_noedit(char *prompt,char *str,int len)
{
    int reading = 1;
    char ch;
    int res = -1;
    int idx = 0;

    console_inreadline++;

    if (prompt && *prompt) console_write(prompt,strlen(prompt));

    POLL();
    while (reading) {

	/*
	 * If someone used console_log (above) or hit Control-C (below),
	 * redisplay the prompt and the string we've got so far.
	 */

	if (console_redisplay) {
	    if (prompt && *prompt) console_write(prompt,strlen(prompt));
	    console_write(str,idx);
	    console_redisplay = 0;
	    continue;
	    }

#if defined(CONFIG_MIPS_BRCM)

	/*
	 * If a background process has set the global g_console_abort flag, stop
	 * reading from the keyboard.
	 */

	if (g_console_abort) {
	    g_console_abort = 0;
	    break;
	    }

#endif

	/*
	 * if nobody's typed anything, keep polling
	 */

	if (console_status() == 0) {
	    POLL();
	    continue;
	    }

	/*
	 * Get the char from the keyboard
	 */

	res = console_read(&ch,1);
	if (res < 0) break;
	if (res == 0) continue;

	/*
	 * And dispatch it
	 */

	switch (ch) {
	    case 3:	/* Ctrl-C */
		console_write("^C\r\n",4);
		console_redisplay = 1;
		idx = 0;
		break;
	    case 0x7f:
	    case '\b':
		if (idx > 0) {
		    idx--;
		    console_write("\b \b",3);
		    }
		break;
	    case 21:	/* Ctrl-U */
		while (idx > 0) {
		    idx--;
		    console_write("\b \b",3);
		    }
		break;
	    case '\r':
	    case '\n':
		console_write("\r\n",2);
		reading = 0;
		break;
	    default:
		if (ch >= ' ') {
		    if (idx < (len-1)) {
			str[idx] = ch;
			idx++;
			console_write(&ch,1);
			}
		    }
		break;
	    }
	}
    POLL();

    console_inreadline--;

    str[idx] = 0;
    return idx;
}
Пример #24
0
/*
 *  board_final_init()
 *
 *  Do any final initialization, such as adding commands to the
 *  user interface.
 *
 *  If you don't want a user interface, put the startup code here.
 *  This routine is called just before CFE starts its user interface.
 *
 *  Input parameters:
 *     nothing
 *
 *  Return value:
 *     nothing
 */
void
board_final_init(void)
{
	char *addr, *mask, *wait_time;
	char buf[512], *cur = buf;
#ifdef CFG_ROMBOOT
	char *laddr = NULL;
#endif
#if !CFG_SIM
	char *boot_cfg = NULL;
	char *go_cmd = "go;";
#endif
	int commit = 0;
	uint32 ncdl;
#if CFG_WL && CFG_WLU && CFG_SIM
	char *ssid;
#endif

	ui_init_bcm947xxcmds();

	/* Force commit of embedded NVRAM */
//	commit = restore_defaults;
	commit = 0;

	/* Set the SDRAM NCDL value into NVRAM if not already done */
	if ((getintvar(NULL, "sdram_ncdl") == 0) &&
	    ((ncdl = si_memc_get_ncdl(sih)) != 0)) {
		sprintf(buf, "0x%x", ncdl);
		nvram_set("sdram_ncdl", buf);
		commit = 1;
	}

	/* Set the bootloader version string if not already done */
	sprintf(buf, "CFE %s", EPI_VERSION_STR);
	if (strcmp(nvram_safe_get("pmon_ver"), buf) != 0) {
		nvram_set("pmon_ver", buf);
		commit = 1;
	}


	/* Set the size of the nvram area if not already done */
	sprintf(buf, "%d", MAX_NVRAM_SPACE);
	if (strcmp(nvram_safe_get("nvram_space"), buf) != 0) {
		nvram_set("nvram_space", buf);
		commit = 1;
	}

#if CFG_FLASH || CFG_SFLASH || CFG_NFLASH
#if !CFG_SIM
	/* Commit NVRAM only if in FLASH */
	if (
#ifdef BCMNVRAMW
		!nvram_inotp() &&
#endif
		commit) {
		printf("Committing NVRAM...");
		nvram_commit();
		printf("done\n");
		if (restore_defaults) {
			printf("Waiting for reset button release...");
			reset_release_wait();
			printf("done\n");
		}
	}

	/* Reboot after restoring defaults */
	if (restore_defaults)
		si_watchdog(sih, 1);
#endif	/* !CFG_SIM */
#else
	if (commit)
		printf("Flash not configured, not commiting NVRAM...\n");
#endif /* CFG_FLASH || CFG_SFLASH || CFG_NFLASH */

	/*
	 * Read the wait_time NVRAM variable and set the tftp max retries.
	 * Assumption: tftp_rrq_timeout & tftp_recv_timeout are set to 1sec.
	 */
	if ((wait_time = nvram_get("wait_time")) != NULL) {
		tftp_max_retries = atoi(wait_time);
		if (tftp_max_retries > MAX_WAIT_TIME)
			tftp_max_retries = MAX_WAIT_TIME;
		else if (tftp_max_retries < MIN_WAIT_TIME)
			tftp_max_retries = MIN_WAIT_TIME;
	}
#ifdef CFG_ROMBOOT
	else if (board_bootdev_rom(sih)) {
		tftp_max_retries = 10;
	}
#endif

	/* Configure network */
	if (cfe_finddev("eth0")) {
		int res;

		if ((addr = nvram_get("lan_ipaddr")) &&
		    (mask = nvram_get("lan_netmask")))
			sprintf(buf, "ifconfig eth0 -addr=%s -mask=%s",
			        addr, mask);
		else
			sprintf(buf, "ifconfig eth0 -auto");

		res = ui_docommand(buf);

#ifdef CFG_ROMBOOT
		/* Try indefinite netboot only while booting from ROM
		 * and we are sure that we dont have valid nvram in FLASH
		 */
		while (board_bootdev_rom(sih) && !addr) {
			char ch;

			cur = buf;
			/* Check if something typed at console */
			if (console_status()) {
				console_read(&ch, 1);
				/* Check for Ctrl-C */
				if (ch == 3) {
					if (laddr)
						MFREE(osh, laddr, MAX_SCRIPT_FSIZE);
					xprintf("Stopped auto netboot!!!\n");
					return;
				}
			}

			if (!res) {
				char *bserver, *bfile, *load_ptr;

				if (!laddr)
					laddr = MALLOC(osh, MAX_SCRIPT_FSIZE);

				if (!laddr) {
					load_ptr = (char *) 0x00008000;
					xprintf("Failed malloc for boot_script, Using :0x%x\n",
						(unsigned int)laddr);
				}
				else {
					load_ptr = laddr;
				}
				bserver = (bserver = env_getenv("BOOT_SERVER"))
					? bserver:"192.168.1.1";

				if ((bfile = env_getenv("BOOT_FILE"))) {
					int len;

					if (((len = strlen(bfile)) > 5) &&
					    !strncmp((bfile + len - 5), "cfesh", 5)) {
						cur += sprintf(cur,
						"batch -raw -tftp -addr=0x%x -max=0x%x %s:%s;",
							(unsigned int)load_ptr,
							MAX_SCRIPT_FSIZE, bserver, bfile);
					}
					if (((len = strlen(bfile)) > 3)) {
						if (!strncmp((bfile + len - 3), "elf", 3)) {
							cur += sprintf(cur,
							"boot -elf -tftp -max=0x5000000 %s:%s;",
							bserver, bfile);
						}
						if (!strncmp((bfile + len - 3), "raw", 3)) {
							cur += sprintf(cur,
							"boot -raw -z -tftp -addr=0x00008000"
							" -max=0x5000000 %s:%s;",
							bserver, bfile);
						}
					}
				}
				else {  /* Make last effort */
					cur += sprintf(cur,
						"batch -raw -tftp -addr=0x%x -max=0x%x %s:%s;",
						(unsigned int)load_ptr, MAX_SCRIPT_FSIZE,
						bserver, "cfe_script.cfesh");
					cur += sprintf(cur,
						"boot -elf -tftp -max=0x5000000 %s:%s;",
						bserver, "boot_file.elf");
					cur += sprintf(cur,
						"boot -raw -z -tftp -addr=0x00008000"
						" -max=0x5000000 %s:%s;",
						bserver, "boot_file.raw");
				}

				ui_docommand(buf);
				cfe_sleep(3*CFE_HZ);
			}

			sprintf(buf, "ifconfig eth0 -auto");
			res = ui_docommand(buf);
		}
#endif /* CFG_ROMBOOT */
	}
#if CFG_WL && CFG_WLU && CFG_SIM
	if ((ssid = nvram_get("wl0_ssid"))) {
		sprintf(buf, "wl join %s", ssid);
		ui_docommand(buf);
	}
#endif

#if !CFG_SIM
	/* Try to run boot_config command if configured.
	 * make sure to leave space for "go" command.
	 */
	if ((boot_cfg = nvram_get("boot_config"))) {
		if (strlen(boot_cfg) < (sizeof(buf) - sizeof(go_cmd)))
			cur += sprintf(cur, "%s;", boot_cfg);
		else
			printf("boot_config too long, skipping to autoboot\n");
	}

	/* Boot image */
	cur += sprintf(cur, go_cmd);
#endif	/* !CFG_SIM */

	/* Startup */
	if (cur > buf)
		env_setenv("STARTUP", buf, ENV_FLG_NORMAL);
}
Пример #25
0
/*-----------------------------------------------------------------------------------*/
unsigned char
ctk_mouse_button(void)
{
  console_read();
  return button;
}
Пример #26
0
/*-----------------------------------------------------------------------------------*/
unsigned short
ctk_mouse_y(void)
{
  console_read();
  return ypos;
}
Пример #27
0
/*-----------------------------------------------------------------------------------*/
unsigned char
ctk_arch_keyavail(void)
{
  console_read();
  return available;
}
Пример #28
0
//Sends a command and reads but ignores the reply
int send_cmd(const char *cmd)
{
    char buffer[512];
    int ret;
    int i;

    ENTRY;

    if(trace_cmd)
    {
        CON(" ->DUT:%s",cmd);
    }

    error_msg = no_error;

    if(console_write(connection,cmd))
    {
        sprintf(is_error, "Failed to send cmd to WiFi-chip");
        error_msg = is_error;
        RETURNI(-1);
    }

    i=0;

    while(1)
    {
        memset(buffer,0,sizeof(buffer));
        usleep(5000);
        ret = console_read(connection, buffer, sizeof(buffer));
        if(ret < 0)
        {
            sprintf(is_error, "Reading response from WiFi-chip failed");
            error_msg = is_error;
            RETURNI(-1);
        }

        if(ret == 0)
        {
            if(i++ > 1)
                break;

            continue;
        }

        if(strlen(buffer) > 2)
        {
            if(memcmp(&buffer[2],"RXSTAT:",7) == 0)
            {
                int value[32];
                int num = 0;
                char *pos = &buffer[9];
                int a;

                //makes bad valued point out...
                memset(value,0xFF,sizeof(value));

                for(num = 0; num < 32; num++)
                {
                    value[num] = atoi(pos);
                    pos = strchr(pos,',');
                    if(pos == NULL)
                        break;

                    pos++;
                }
                num++;

                rx_frames += value[2] + value[3] + value[4] + value[5];
                bad_crc_frames += value[10];
            }
        }
    }

    RETURNI(SUCCESS);
}