index 070f250e58293c7f1c001c7c23780d61a6ea7c33..fb64d6e265be7baa748ba3e8787300420bd81c3c 100644 (file)
***************************************************************************************/
#include <stdlib.h>
#include <stdio.h>
+#include<ctype.h>
#include <string.h>
#include "platform.h"
#include "types.h"
/* EEPROM writer utility version */
-char version[] = "01.00.00.00";
+char version[] = "01.00.00.05";
+
/* The input file name is hard coded */
char *input_file = "eepromwriter_input.txt";
#define FILE_NAME "file_name"
#define BUS_ADDR "bus_addr"
#define START_ADDR "start_addr"
+#define SWAP_DATA "swap_data"
/* Memory address to store the write data */
-#define WRITE_DATA_ADDRESS 0x80000000
+#define WRITE_DATA_ADDRESS 0x0C000000
/******************************************************************************
* Structure: EEPROM_WRITER_INFO_T
char file_name[MAX_LINE_LENGTH]; /* CCS format data file name */
uint32_t busAddr; /* Slave bus address */
uint32_t startAddr; /* Start address to write */
+ uint32_t swapData; /* Swap byte in the 32-bit word of the data */
uint32_t deviceTotalBytes; /* Total number of bytes available in the device */
uint32_t writeBytes; /* Number of bytes to be written into the device */
uint8_t *writeData; /* Address to store the write data */
EEPROM_WRITER_INFO_T eepromWriterInfo;
+/* OSAL functions for Platform Library */
+uint8_t *Osal_platformMalloc (uint32_t num_bytes, uint32_t alignment)
+{
+ return malloc(num_bytes);
+}
+
+void Osal_platformFree (uint8_t *dataPtr, uint32_t num_bytes)
+{
+ /* Free up the memory */
+ if (dataPtr)
+ {
+ free(dataPtr);
+ }
+}
+
+void Osal_platformSpiCsEnter(void)
+{
+ return;
+}
+
+void Osal_platformSpiCsExit (void)
+{
+ return;
+}
+
/******************************************************************************
* Function: print_platform_errno
******************************************************************************/
printf ("Returned platform error number is %d\n", platform_errno);
}
+/******************************************************************************
+ * Function: form_block
+ *
+ * Form a block of data to write to the NOR. The block is
+ * created as a byte stream from the 4 byte stream in which
+ * the MSB is always sent first.
+ ******************************************************************************/
+void
+formBlock
+(
+ uint32_t *data,
+ uint32_t blockSize,
+ uint8_t *scratch
+)
+{
+ uint32_t i, j;
+
+ /* Convert the data to a byte stream */
+ for (i = j = 0; j < blockSize; i++, j+=4)
+ {
+ scratch[j+0] = (data[i] >> 24) & 0xff;
+ scratch[j+1] = (data[i] >> 16) & 0xff;
+ scratch[j+2] = (data[i] >> 8) & 0xff;
+ scratch[j+3] = (data[i] >> 0) & 0xff;
+ }
+}
+
/******************************************************************************
* Function: flash_eeprom
*
PLATFORM_DEVICE_info *p_device
)
{
+ uint8_t *scrach_block;
+
printf ("Writing %d bytes from DSP memory address 0x%08x to EEPROM bus address 0x%04x starting from device address 0x%04x ...\n",
eepromWriterInfo.writeBytes,
(uint32_t)eepromWriterInfo.writeData,
eepromWriterInfo.busAddr,
eepromWriterInfo.startAddr);
- if(platform_device_write(p_device->handle, eepromWriterInfo.startAddr, eepromWriterInfo.writeData, eepromWriterInfo.writeBytes) != Platform_EOK)
+ if (eepromWriterInfo.swapData)
+ {
+ scrach_block = malloc(eepromWriterInfo.deviceTotalBytes);
+ if (scrach_block == NULL)
+ {
+ printf ("Can not allocate scratch block memory!\n");
+ return (FALSE);
+ }
+ formBlock((uint32_t *)(eepromWriterInfo.writeData), eepromWriterInfo.deviceTotalBytes, scrach_block);
+ }
+ else
+ {
+ scrach_block = eepromWriterInfo.writeData;
+ }
+
+ if(platform_device_write(p_device->handle, eepromWriterInfo.startAddr, scrach_block, eepromWriterInfo.writeBytes) != Platform_EOK)
{
print_platform_errno();
+ if (eepromWriterInfo.swapData)
+ free (scrach_block);
return FALSE;
}
+ if(eepromWriterInfo.swapData)
+ free (scrach_block);
+
return TRUE;
}
PLATFORM_DEVICE_info *p_device
)
{
- uint32_t i;
+ uint32_t i, j;
+ uint8_t *scrach_block;
+ uint32_t *read_data_w;
printf ("Reading %d bytes from EEPROM bus address 0x%04x to DSP memory address 0x%08x starting from device address 0x%04x ...\n",
eepromWriterInfo.writeBytes,
(uint32_t)eepromWriterInfo.readData,
eepromWriterInfo.startAddr);
- if(platform_device_read(p_device->handle, eepromWriterInfo.startAddr, eepromWriterInfo.readData, eepromWriterInfo.writeBytes) != Platform_EOK)
+ if (eepromWriterInfo.swapData)
+ {
+ scrach_block = malloc(eepromWriterInfo.deviceTotalBytes);
+ if (scrach_block == NULL)
+ {
+ printf ("Can not allocate scratch block memory!\n");
+ return (FALSE);
+ }
+ }
+ else
+ {
+ scrach_block = eepromWriterInfo.readData;
+ }
+
+ if(platform_device_read(p_device->handle, eepromWriterInfo.startAddr, scrach_block, eepromWriterInfo.writeBytes) != Platform_EOK)
{
print_platform_errno();
return FALSE;
printf ("Verifying data read ...\n");
+ if (eepromWriterInfo.swapData)
+ {
+ /* Convert the packed data */
+ read_data_w = (uint32_t *)(eepromWriterInfo.readData);
+ for (i = 0, j = 0; i < eepromWriterInfo.deviceTotalBytes; i += 4)
+ read_data_w[j++] = (scrach_block[i+0] << 24) | (scrach_block[i+1] << 16) | (scrach_block[i+2] << 8) | scrach_block[i+3];
+ }
+
+
for (i = 0; i < eepromWriterInfo.writeBytes; i++)
{
if (eepromWriterInfo.readData[i] != eepromWriterInfo.writeData[i])
return (TRUE);
}
+int32_t
+xtoi
+(
+ char *xs,
+ uint32_t *result
+)
+{
+ uint32_t szlen = strlen(xs);
+ int32_t i, xv, fact;
+
+ if (szlen > 0)
+ {
+ /* Converting more than 32bit hexadecimal value? */
+ if (szlen>8) return 2; /* exit */
+
+ /* Begin conversion here */
+ *result = 0;
+ fact = 1;
+
+ /* Run until no more character to convert */
+ for(i=szlen-1; i>=0 ;i--)
+ {
+ if (isxdigit(*(xs+i)))
+ {
+ if (*(xs+i)>=97)
+ {
+ xv = ( *(xs+i) - 97) + 10;
+ }
+ else if ( *(xs+i) >= 65)
+ {
+ xv = (*(xs+i) - 65) + 10;
+ }
+ else
+ {
+ xv = *(xs+i) - 48;
+ }
+ *result += (xv * fact);
+ fact *= 16;
+ }
+ else
+ {
+ // Conversion was abnormally terminated
+ // by non hexadecimal digit, hence
+ // returning only the converted with
+ // an error value 4 (illegal hex character)
+ return 4;
+ }
+ }
+ return 0;
+ }
+
+ // Nothing to convert
+ return 1;
+}
+
+
/******************************************************************************
* Function: parse_input_file
******************************************************************************/
)
{
char line[MAX_LINE_LENGTH];
- char tokens[] = " :=;\n";
+ char tokens[] = " :=;\n\r";
char *key, *data;
memset(line, 0, MAX_LINE_LENGTH);
return FALSE;
}
- eepromWriterInfo.busAddr = (uint32_t)atoi(data);
+ if ((data[0] == '0') && (data[1] == 'x' || data[1] == 'X'))
+ {
+ if (xtoi (&data[2], &eepromWriterInfo.busAddr) != 0)
+ {
+ return FALSE;
+ }
+ }
+ else
+ {
+ eepromWriterInfo.busAddr = (uint32_t)atoi(data);
+ }
fgets(line, MAX_LINE_LENGTH, fp);
key = (char *)strtok(line, tokens);
eepromWriterInfo.startAddr = (uint32_t)atoi(data);
+ fgets(line, MAX_LINE_LENGTH, fp);
+ key = (char *)strtok(line, tokens);
+ data = (char *)strtok(NULL, tokens);
+
+ if(strlen(data) == 0)
+ {
+ return FALSE;
+ }
+
+ if(strcmp(key, SWAP_DATA) != 0)
+ {
+ return FALSE;
+ }
+
+ eepromWriterInfo.swapData = (uint32_t)atoi(data);
+
return TRUE;
}
/******************************************************************************
- * Function: parse_ccs_file
+ * Function: find_file_length
******************************************************************************/
static Bool
-parse_ccs_file
+find_file_length
(
FILE* fp
)
{
char line[MAX_LINE_LENGTH];
char *pEnd;
+ char *ext;
uint32_t data_len, write_addr;
memset(line, 0, MAX_LINE_LENGTH);
- fgets(line, MAX_LINE_LENGTH, fp);
+ ext = strrchr(eepromWriterInfo.file_name, '.');
- /* Read the write address from the CCS header */
- strtoul (line,&pEnd,16);
- strtoul (pEnd,&pEnd,16);
- write_addr = strtoul (pEnd,&pEnd,16);
- strtoul (pEnd,&pEnd,16);
- /* Read the data length */
- data_len = (strtoul (pEnd,NULL,16)) * 4;
+ if (ext && (strcmp(ext, ".dat") == 0))
+ {
+
+ fgets(line, MAX_LINE_LENGTH, fp);
+
+ /* Read the write address from the CCS header */
+ strtoul (line,&pEnd,16);
+ strtoul (pEnd,&pEnd,16);
+ write_addr = strtoul (pEnd,&pEnd,16);
+ strtoul (pEnd,&pEnd,16);
+
+ /* Read the data length */
+ data_len = (strtoul (pEnd,NULL,16)) * 4;
+ }
+ else
+ {
+ /* find the data length by seeking to the end and getting position */
+ fseek(fp, 0, SEEK_END);
+ data_len = ftell(fp);
+ fseek(fp, 0, SEEK_SET);
+ }
+
if (data_len > (eepromWriterInfo.deviceTotalBytes - eepromWriterInfo.startAddr))
{
printf ("The data file is too big to fit into the device.\n");
/* Initialize main Platform lib */
memset(&init_config, 0, sizeof(platform_init_config));
- memset(&init_flags, 1, sizeof(platform_init_flags));
+ memset(&init_flags, 0x01, sizeof(platform_init_flags));
+ init_flags.pll = 0;
+ init_flags.ddr = 0;
+ init_flags.phy = 0;
+
if (platform_init(&init_flags, &init_config) != Platform_EOK)
{
printf ("Platform init failed!\n");
}
/* Parse the CCS format file */
- ret = parse_ccs_file(fp);
+ ret = find_file_length(fp);
fclose (fp);
if (ret == FALSE)
{