/***********************************************************************
 *
 * Function: cmd_exec
 *
 * Purpose: Executes a program or at an address
 *
 * Processing:
 *     See function.
 *
 * Parameters: None
 *
 * Outputs: None
 *
 * Returns: TRUE if the command was good, otherwise FALSE
 *
 * Notes: None
 *
 **********************************************************************/
BOOL_32 cmd_exec(void) 
{
	UNS_8 *curp;
	UNS_32 ea;
	BOOL_32 execgood;

	/* An address was passed, use it */
	if (parse_get_entry_count() == 1) {
		if (sysinfo.lfile.startaddr != (PFV) 0xFFFFFFFF) 
		{
			menuexit = TRUE;
		}
	}
	else if (parse_get_entry_count() == 2) {
		curp = get_parsed_entry(1);
		execgood = str_hex_to_val(curp, &ea);
		if (execgood == TRUE) 
		{
			menuexit = TRUE;
			sysinfo.lfile.startaddr = (PFV) ea;
		}
	}

	return TRUE;
}
Exemplo n.º 2
0
/***********************************************************************
*
* Function: cmd_peek
*
* Purpose: Peek command
*
* Processing:
*     Parse the string elements for the peek command and display the
*     peeked value.
*
* Parameters: None
*
* Outputs: None
*
* Returns: TRUE if the command was processed, otherwise FALSE
*
* Notes: None
*
**********************************************************************/
static BOOL_32 cmd_peek(void)
{
    UNS_32 newaddr, newwidth;

    /* If only 1 parsed command, then print at current address and
       width */
    if (parse_get_entry_count() > 1)
    {
        /* Get address */
        newaddr = cmd_get_field_val(1);

        /* Width */
        newwidth = last_width;
        if (parse_get_entry_count() >= 3)
        {
            newwidth = cmd_get_field_val(2);
            if (!((newwidth == 1) || (newwidth == 2) ||
                    (newwidth == 4)))
            {
                newwidth = 1;
            }
        }

        last_addr = newaddr;
        last_width = newwidth;
    }

    /* Based on width, limit address start */
    last_addr = last_addr & ~(last_width - 1);

    /* Dump data */
    hex_dump(last_addr, last_width, 1);

    return TRUE;
}
Exemplo n.º 3
0
/***********************************************************************
 *
 * Function: cmd_dump
 *
 * Purpose: Dump command
 *
 * Processing:
 *     Parse the string elements for the dump command and display the
 *     dumped values.
 *
 * Parameters: None
 *
 * Outputs: None
 *
 * Returns: TRUE if the command was processed, otherwise FALSE
 *
 * Notes: None
 *
 **********************************************************************/
static BOOL_32 cmd_dump(void)
{
    UNS_32 newaddr, newwidth, newtrans;

    /* If only 1 parsed command, then print at current address and
       width */
    if (parse_get_entry_count() > 1)
    {
        newaddr = dump_addr;
        newwidth = dump_width;
        newtrans = dump_trans;

        /* Get address */
        newaddr = cmd_get_field_val(1);

        /* Convert decimal value to width */
        if (parse_get_entry_count() >= 3)
        {
            newtrans = cmd_get_field_val(2);
        }
        if (parse_get_entry_count() >= 4)
        {
            newwidth = cmd_get_field_val(3);
            if (!((newwidth == 1) || (newwidth == 2) ||
                    (newwidth == 4)))
            {
                newwidth = 1;
            }
        }

        dump_addr = newaddr;
        dump_width = newwidth;
        dump_trans = newtrans;

        /* Limit dump size to 1024 bytes */
        if ((dump_trans * dump_width) > 1024)
        {
            dump_trans = dump_trans / dump_width;
        }
    }

    /* Based on width, limit address start */
    dump_addr = dump_addr & ~(dump_width - 1);

    /* Dump data and increment address */
    hex_dump(dump_addr, dump_width, dump_trans);
    dump_addr = dump_addr + (dump_width * dump_trans);

    return TRUE;
}
Exemplo n.º 4
0
/***********************************************************************
 *
 * Function: cmd_help
 *
 * Purpose: Processes the help command
 *
 * Processing:
 *     See function.
 *
 * Parameters: None
 *
 * Outputs: None
 *
 * Returns: Nothing
 *
 * Notes: None
 *
 **********************************************************************/
BOOL_32 cmd_help(void)
{
	GROUP_LIST_T *pGroup = &group_list_head;
	UNS_8 *str = get_parsed_entry(1);
	CMD_ROUTE_T *pCmd;

	// If this is just the help command with no arguments, then display
	// the standard help message
	if (parse_get_entry_count() == 1)
	{
		cmd_show_group_help(pGroup, FALSE);
	}
	else
	{
		// Verify second argument
		if (str_cmp(str, "menu") == 0)
		{
			// Show everything
			while (pGroup != NULL)
			{
				cmd_show_group_help(pGroup, FALSE);
				pGroup = pGroup->next_group;
			}
		}
		else if (str_cmp(str, "all") == 0)
		{
			// Show everything
			while (pGroup != NULL)
			{
				cmd_show_group_help(pGroup, TRUE);
				pGroup = pGroup->next_group;
			}
		}
		else
		{
			// Second argument is either a command or group name, so
			// attempt to find the matching name
			if (cmd_find_index(str, &pGroup, &pCmd) == FALSE)
			{
				// No matching group or command
				term_dat_out_crlf(helperr_msg);
			}
			else
			{
				if (pCmd != NULL)
				{
					cmd_show_cmd_help(pCmd);
				}
				else
				{
					cmd_show_group_help(pGroup, TRUE);
				}
			}
		}
	}

	return TRUE;
}
/***********************************************************************
 *
 * Function: cmd_maddr
 *
 * Purpose: Sets MAC address of ethernet device
 *
 * Processing:
 *     See function.
 *
 * Parameters: None
 *
 * Outputs: None
 *
 * Returns: TRUE if the command was good, otherwise FALSE
 *
 * Notes: None
 *
 **********************************************************************/
BOOL_32 cmd_maddr(void) {
	int idx, offs;
	UNS_8 *p8, *curp, mac[8], str[16];
	UNS_32 ea;
	BOOL_32 goodmac = FALSE;

	str [0] = '0';
	str [1] = 'x';
	str [4] = '\0';
	mac [6] = mac [7] = 0;

	/* An address was passed, use it */
	if (parse_get_entry_count() == 2) {
		curp = get_parsed_entry(1);
		goodmac = TRUE;
		offs = 0;
		for (idx = 0; idx < 6; idx++) {
			str [2] = curp[offs];
			str [3] = curp[offs + 1];
			goodmac &= str_hex_to_val(str, &ea);
			mac [idx] = (UNS_8) ea;
			offs += 3;
		}

		if (goodmac == TRUE) 
		{
			/* Yes NO VERIFY? */
			term_dat_out(smac_msg);
            if (prompt_yesno() != FALSE)
			{
				/* Save structure */
				for (idx = 0; idx < 8; idx++) {
					phyhwdesc.mac [idx] = mac [idx];
				}
				p8 = (UNS_8 *) &phyhwdesc;
				for (idx = 0; idx < sizeof(phyhwdesc); idx++) 
				{
					phy3250_sspwrite(*p8, (PHY3250_SEEPROM_CFGOFS + idx));
					p8++;
				}
			}
		}
		else
		{
			term_dat_out_crlf(macafail_msg);
		}
	}

	return goodmac;
}
Exemplo n.º 6
0
/***********************************************************************
 *
 * Function: cmd_script
 *
 * Purpose: Sets up, enables, or disables startup scripting
 *
 * Processing:
 *     See function.
 *
 * Parameters: None
 *
 * Outputs: None
 *
 * Returns: TRUE if the command was accepted, otherwise FALSE
 *
 * Notes: None
 *
 **********************************************************************/
static BOOL_32 cmd_script(void)
{
    BOOL_32 update = FALSE, parsed = FALSE;
    UNS_8 *str = get_parsed_entry(1);

    if (parse_get_entry_count() == 2) {
        /* on, off, or setup commands? */
        if (str_cmp(str, "on") == 0)
        {
            if ((syscfg.scr.number_entries > 0) &&
                    (syscfg.scr.enabled == FALSE)) {
                syscfg.scr.enabled = TRUE;
                update = TRUE;
            }
            parsed = TRUE;
        }
        else if (str_cmp(str, "off") == 0)
        {
            if (syscfg.scr.enabled == TRUE) {
                syscfg.scr.enabled = FALSE;
                update = TRUE;
            }

            parsed = TRUE;
        }
        else if (str_cmp(str, "setup") == 0)
        {
            syscfg.scr.enabled = TRUE;
            update = parsed = script_capture();
        }
        else
            term_dat_out_crlf((UNS_8 *)
                              "Invalid script command, type help script for more "
                              "info");

        if (update)
            cfg_save(&syscfg);
    }

    return parsed;
}
Exemplo n.º 7
0
/***********************************************************************
 *
 * Function: cmd_parse_fields
 *
 * Purpose: Parses and verifies parsed field entries
 *
 * Processing:
 *     See function.
 *
 * Parameters:
 *     pCmd : Pointer to command to verify parsing for
 *
 * Outputs: None
 *
 * Returns: Nothing
 *
 * Notes: None
 *
 **********************************************************************/
BOOL_32 cmd_parse_fields(CMD_ROUTE_T *pCmd)
{
	UNS_32 tval, *parse_list = pCmd->parse_list;
	int pfield, fields = parse_get_entry_count();
	BOOL_32 good = TRUE;

	// If the command has a free-form parse, then just exit
	if ((*parse_list & PARSE_TYPE_FREE) != 0)
	{
		return TRUE;
	}

	// Process list
	pfield = 0;
	while ((pfield < fields) && (good == TRUE))
	{
		if (pfield == 0)
		{
			// This is just the command name
			tval = (UNS_32) get_parsed_entry(0);
		}
		else
		{
			// Parse based on expected type
			switch (*parse_list & 0xF)
			{
				case PARSE_TYPE_STR:
					tval = (UNS_32) get_parsed_entry(pfield);
					break;

				case PARSE_TYPE_DEC:
					good = str_dec_to_val(get_parsed_entry(pfield),
						&tval);
					break;

				case PARSE_TYPE_HEX:
					good = str_hex_to_val(get_parsed_entry(pfield),
						&tval);
					break;

				default:
					good = FALSE;
			}
		}

		// Save pointer or value
		pFData [pfield] = tval;

		// Is this the last entry?
		if (pfield >= (fields - 1))
		{
			// Is this entry marked with the end or optional flag?
			if ((*parse_list & (PARSE_TYPE_OPT | PARSE_TYPE_END)) == 0)
			{
				// Not, parse line ended unexpectedly
				good = FALSE;
			}
		}
		else
		{
			/* Verify the parse line isn't too long */
			if ((*parse_list & PARSE_TYPE_END) != 0)
			{
				/* Command line is too long */
				good = FALSE;
			}
		}

		/* Next entries */
		parse_list++;
		pfield++;
	}

	return good;
}
/***********************************************************************
 *
 * Function: cmd_update
 *
 * Purpose: Updates the stage 1 bootloader
 *
 * Processing:
 *     See function.
 *
 * Parameters: None
 *
 * Outputs: None
 *
 * Returns: Always returns TRUE.
 *
 * Notes: None
 *
 **********************************************************************/
BOOL_32 cmd_update(void) 
{
	BOOL_32 updated = FALSE;

	/* Is an image in memory? */
	if (sysinfo.lfile.flt == FLT_NONE) 
	{
		term_dat_out_crlf(updnoim_msg);
		return TRUE;
	}

	/* Is an image in memory a raw image? */
	if (sysinfo.lfile.flt != FLT_RAW) 
	{
		term_dat_out_crlf(updnotraw_msg);
		return TRUE;
	}

	/* Is the image in memory contiguous? */
	if (sysinfo.lfile.contiguous == FALSE) 
	{
		term_dat_out_crlf(updnotc_msg);
		return TRUE;
	}

	/* Is the image for stage 1 or the kickstart loader */
	if (parse_get_entry_count() == 2) 
	{
		/* Get passed command */
		if (str_cmp(get_parsed_entry(1), "kick") == 0) 
		{
			/* Updating block 0, does the image exceed 15.5K(small block)? 
			*  large block 54K
			*/
			if (sysinfo.lfile.num_bytes > (31 * 512)) 
			{
				term_dat_out_crlf(updgt31_msg);
				return TRUE;
			}
			else 
			{
				updated = nand_kickstart_update();
			}
		}
	}
	else 
	{
		/* Updating block 0, does the image exceed 256K? */
		if (sysinfo.lfile.num_bytes > (256 * 512)) 
		{
			term_dat_out_crlf(updgt256_msg);
			return TRUE;
		}
		else 
		{
			updated = nand_bootloader_update();
		}
	}

	/* Image in memory passes all checks, FLASH it at start of
	   block 0 */
	if (updated == FALSE) 
	{
		term_dat_out_crlf(updfail_msg);
	}
	else 
	{
		term_dat_out_crlf(updgood_msg);
	}

	return TRUE;
}
/***********************************************************************
 *
 * Function: cmd_aboot
 *
 * Purpose: Sets autoboot source
 *
 * Processing:
 *     See function.
 *
 * Parameters: None
 *
 * Outputs: None
 *
 * Returns: Always returns TRUE
 *
 * Notes: None
 *
 **********************************************************************/
BOOL_32 cmd_aboot(void) 
{
	UNS_8 *curp;
	UNS_32 addr;
	BOOL_32 processed = TRUE, ready = FALSE;
	INT_32 nexidx;
	ABOOT_SETUP_T abs;

	abs.fname [0] = '\0';
	if (parse_get_entry_count() >= 3) 
	{
		/* Get source */
		curp = get_parsed_entry(1);
		nexidx = 2;
		if (str_cmp(curp, "term") == 0) 
		{
			/* Clear break */
			term_break();
			abs.abootsrc = SRC_TERM;
		}
		else if (str_cmp(curp, "blk") == 0) 
		{
			abs.abootsrc = SRC_BLKDEV;

			/* Get filename */
			curp = get_parsed_entry(2);
			memcpy(abs.fname, curp, str_size(curp));
			abs.fname[str_size(curp)] = '\0';
			nexidx = 3;
		}
		else if (str_cmp(curp, "flash") == 0) 
		{
			abs.abootsrc = SRC_NAND;
		}
		else if (str_cmp(curp, "none") == 0) 
		{
			abs.abootsrc = SRC_NONE;
		}
		else
		{
			term_dat_out_crlf(invalsrc_msg);
			processed = FALSE;
		}

		/* Get file type */
		curp = get_parsed_entry(nexidx);
		abs.flt = FLT_NONE;
		if (str_cmp(curp, "elf") == 0) 
		{
			abs.flt = FLT_ELF;
		}
		else if (str_cmp(curp, "raw") == 0) 
		{
			abs.flt = FLT_RAW;
		}
		else if (str_cmp(curp, "bin") == 0) 
		{
			abs.flt = FLT_BIN;
		}
		else if (str_cmp(curp, "srec") == 0) 
		{
			abs.flt = FLT_SREC;
		}
		else 
		{
			abs.flt = FLT_NONE;
			term_dat_out(unkft_msg);
			term_dat_out_crlf(curp);
			processed = FALSE;
		}

		/* Next index */
		nexidx++;

		/* Handle each file type */
		if (processed == TRUE) 
		{
			switch (abs.flt) 
			{
				case FLT_RAW:
					/* Get load address */
					curp = get_parsed_entry(nexidx);
					ready = str_hex_to_val(curp, &addr);
					if (ready == TRUE) 
					{
						abs.loadaddr = addr;
						abs.startaddr = addr;
					}
					else 
					{
						term_dat_out_crlf(rawna_msg);
					}

					/* Start address */
					nexidx++;
					curp = get_parsed_entry(nexidx);
					if (curp != NULL) 
					{
						ready &= str_hex_to_val(curp, &addr);
						if (ready == TRUE) 
						{
							abs.startaddr = addr;
						}
					}
					break;

				case FLT_BIN:
					ready = FALSE; /* TBD not supported yet */
					processed = TRUE;
					break;

				case FLT_SREC:
					ready = TRUE;
					processed = TRUE;
					break;

				case FLT_ELF:
					ready = FALSE; /* TBD not supported yet */
					processed = TRUE;
					break;

				default:
					break;
			}
		}
	}

	if (ready == TRUE) 
	{
		syscfg.aboot = abs;
		cfg_save(&syscfg);
		term_dat_out_crlf(bsgood_msg);
	}
	else 
	{
		term_dat_out_crlf(bsbad_msg);
	}

	return TRUE;
}
Exemplo n.º 10
0
/***********************************************************************
 *
 * Function: cmd_load
 *
 * Purpose: Load command
 *
 * Processing:
 *     For the load command, start parsing subcommand elements and
 *     route to the specific handler.
 *
 * Parameters: None
 *
 * Outputs: None
 *
 * Returns: Always returns TRUE
 *
 * Notes: None
 *
 **********************************************************************/
BOOL_32 cmd_load(void) {
	UNS_8 *curp;
	UNS_32 addr;
	BOOL_32 processed = TRUE, loaded = FALSE;
	FILE_DATA_T fdata;
	SRC_LOAD_T src = SRC_TERM;
	INT_32 nexidx;
	UNS_8 *fname;

	if (parse_get_entry_count() >= 3) 
	{
		/* Get source */
		curp = get_parsed_entry(1);
		nexidx = 2;
		if (str_cmp(curp, "term") == 0) 
		{
			/* Clear break */
			term_break();
			src = SRC_TERM;
		}
		else if (str_cmp(curp, "blk") == 0) 
		{
			src = SRC_BLKDEV;
			nexidx = 3;
		}
		else if (str_cmp(curp, "flash") == 0) 
		{
			src = SRC_NAND;
		}
		else 
		{
			term_dat_out_crlf(invalsrc_msg);
			processed = FALSE;
		}

		/* Get file type */
		curp = get_parsed_entry(nexidx);
		fdata.flt = FLT_NONE;
		if (str_cmp(curp, "elf") == 0) 
		{
			fdata.flt = FLT_ELF;
		}
		else if (str_cmp(curp, "raw") == 0) 
		{
			fdata.flt = FLT_RAW;
		}
		else if (str_cmp(curp, "bin") == 0) 
		{
			fdata.flt = FLT_BIN;
		}
		else if (str_cmp(curp, "srec") == 0) 
		{
			fdata.flt = FLT_SREC;
		}
		else 
		{
			fdata.flt = FLT_NONE;
			term_dat_out(unkft_msg);
			term_dat_out_crlf(curp);
			processed = FALSE;
		}

		/* Next index */
		nexidx++;

		/* Handle each file type */
		if (processed == TRUE) 
		{
			/* Get filename */
			fname = get_parsed_entry(2);

			switch (fdata.flt) 
			{
				case FLT_RAW:
					/* Get load address */
					curp = get_parsed_entry(nexidx);
					loaded = str_hex_to_val(curp, &addr);
					if (loaded == TRUE) 
					{
						fdata.loadaddr = addr;
						fdata.startaddr = (PFV) addr;
					}
					else 
					{
						term_dat_out_crlf(rawna_msg);
					}

					/* Start address */
					nexidx++;
					curp = get_parsed_entry(nexidx);
					if (curp != NULL) 
					{
						loaded &= str_hex_to_val(curp, &addr);
						if (loaded == TRUE) 
						{
							fdata.startaddr = (PFV) addr;
						}
					}

					if (loaded == TRUE) 
					{
						loaded = raw_load(&fdata, fdata.loadaddr,
							fname, src);
					}

					processed = TRUE;
					break;

				case FLT_BIN:
					processed = TRUE; /* TBD not supported yet */
					break;

				case FLT_SREC:
					loaded = srec_parse(&fdata, src, fname);
					break;

				case FLT_ELF:
					processed = TRUE; /* TBD not supported yet */
					break;

				default:
					break;
			}
		}
	}

	if (loaded == TRUE) 
	{
		term_dat_out_crlf(floaded_msg);
		sysinfo.lfile.loadaddr = fdata.loadaddr;
		sysinfo.lfile.flt = fdata.flt;
		sysinfo.lfile.num_bytes = fdata.num_bytes;
		sysinfo.lfile.startaddr = fdata.startaddr;
		sysinfo.lfile.contiguous = fdata.contiguous;
		sysinfo.lfile.loaded = TRUE;
	}
	else 
	{
		term_dat_out_crlf(notloaded_msg);
		sysinfo.lfile.loadaddr = 0xFFFFFFFF;
		sysinfo.lfile.flt = FLT_NONE;
		sysinfo.lfile.num_bytes = 0;
		sysinfo.lfile.startaddr = (PFV) 0xFFFFFFFF;
		processed = FALSE;
	}

	return TRUE;
}