/***********************************************************************
 *
 * Function: cmd_ls
 *
 * Purpose: Displays files in root directory of block device
 *
 * Processing:
 *     See function.
 *
 * Parameters: None
 *
 * Outputs: None
 *
 * Returns: Always returns TRUE
 *
 * Notes: None
 *
 **********************************************************************/
BOOL_32 cmd_ls(void) 
{
	UNS_8 dirname [32];
	BOOL_32 lp;

	/* Initialize FAT interface first */
	if (fat_init() == FALSE)
	{
		term_dat_out(blkdeverr_msg);
	}
	else
	{
		/* Show items in BLKDEV root directory */
		lp = fat_get_dir(dirname, TRUE);
		while (lp == FALSE) 
		{
			term_dat_out(" ");
			term_dat_out_crlf(dirname);
			lp = fat_get_dir(dirname, FALSE);
		}

		fat_deinit();
	}

	return TRUE;
}
Beispiel #2
0
/***********************************************************************
 *
 * Function: srec_parse
 *
 * Purpose: Load and parse an S-record file
 *
 * Processing:
 *     See function.
 *
 * Parameters:
 *     fdata    : Pointer to file data to fill
 *     src      : Data source
 *     filename : Filename (sd cards only)
 *
 * Outputs: None
 *
 * Returns: E if the file was parsed and loaded, otherwise FALSE
 *
 * Notes: None
 *
 **********************************************************************/
BOOL_32 srec_parse(FILE_DATA_T *ft,
                   SRC_LOAD_T src,
                   UNS_8 *filename) {
    UNS_8 line[384];
    int idx;
    BOOL_32 fop = FALSE, parsed = TRUE, done = FALSE;

    ft->loadaddr = 0xFFFFFFFF;
    ft->flt = FLT_RAW; /* Loaded as an S-record, saved as RAW */
    ft->num_bytes = 0;
    ft->startaddr = (PFV) 0xFFFFFFFF;
    ft->contiguous = TRUE;
    ft->loaded = FALSE;

	/* Attempt to open file if from SD source */
	if (src == SRC_BLKDEV) 
	{
		/* Init FAT filesystem and block device */
		if (fat_init() == FALSE)
		{
			term_dat_out(blkdeverr_msg);
			done = TRUE;
		}
		else
		{
			/* Try to open file */
			parsed = fat_file_open(filename);
			fop = TRUE;
			if (parsed == FALSE)
			{
				term_dat_out_crlf(nofilmsg);
				done = TRUE;
			}
		}
	}
	else if (src == SRC_NAND) 
	{
		/* Initialize NAND streamer */
		if (stream_flash_init() == FALSE) 
		{
			term_dat_out_crlf(noiif_msg);
			done = TRUE;
		}
	}
	else 
	{
		term_dat_out_crlf(rawdl_msg);
	}

    while ((done == FALSE) && (ft->loaded == FALSE)) 
    {
        /* Read line from device */
        parsed = readline(line, src);
        if (parsed == TRUE) 
        {
			/* Skip whitespace */
			idx = skip_whitespace(line, 0);

			parsed &= srec_parse_line(&line [idx], ft);
        }
		if (parsed == FALSE) 
		{
			done = TRUE;
		}
    }

	if (fop == TRUE)
	{
		fat_deinit();
	}

	return parsed;
}
Beispiel #3
0
/***********************************************************************
 *
 * Function: raw_load
 *
 * Purpose: Load a raw file from a source to memory
 *
 * Processing:
 *     See function.
 *
 * Parameters:
 *     fdata : Pointer to file data to fill
 *     addr  : Address to load data
 *     filename : Filename (sd cards only)
 *     src   : Data source
 *
 * Outputs: None
 *
 * Returns: TRUE if the file was loaded, otherwise FALSE
 *
 * Notes: None
 *
 **********************************************************************/
BOOL_32 raw_load(FILE_DATA_T *fdata,
                 UNS_32 addr,
                 UNS_8 *filename,
                 SRC_LOAD_T src) 
{
	UNS_32 rb, bytes = 0;
	UNS_8 ch, *ptr8 = (UNS_8 *) addr;
	BOOL_32 readloop, loaded = FALSE;

	if (src == SRC_TERM) 
	{
		term_dat_out_crlf(rawdl_msg);

		/* Read data from terminal until a break is encountered */
		while (term_break() == FALSE) 
		{
			if (term_dat_in(&ch, 1) > 0) 
			{
				bytes++;
				*ptr8 = ch;
				ptr8++;
			}
		}

		fdata->num_bytes = bytes;
		fdata->contiguous = TRUE;
		loaded = TRUE;
	}
	else if (src == SRC_NAND) 
	{
		/* Move image in NAND to memory */
		term_dat_out_crlf(rawnanddlns_msg);

	}
	else if (src == SRC_BLKDEV) 
	{
		/* Initialize FAT interface first */
		if (fat_init() == FALSE)
		{
			term_dat_out(blkdeverr_msg);
		}
		/* Try to open file */
		else if (fat_file_open(filename) == FALSE) 
		{
			term_dat_out_crlf(nofilmsg);
		}
		else 
		{
			fdata->num_bytes = 0;
			readloop = TRUE;
			while (readloop == TRUE) 
			{
				rb = fat_file_read(ptr8, 8);
				fdata->num_bytes += rb;
				ptr8 += 8;
				if (rb != 8) 
				{
					readloop = FALSE;
				}
			}
			fdata->contiguous = TRUE;
			loaded = TRUE;
		}

		fat_deinit();
	}

	return loaded;
}