index f0a19195561cadd84036d404b661a429cfa5ffe8..21692de8628772b69fc7866542da25c13fa54597 100644 (file)
#include "types.h"
/* NAND writer utility version */
-char version[] = "01.00.00.00";
+char version[] = "01.00.00.03";
/* The input file name is hard coded */
char *input_file = "nand_writer_input.txt";
+uint32_t swap_byte = 0;
+
/* Parameters defined in the input_file */
#define FILE_NAME "file_name"
#define START_ADDR "start_addr"
NAND_WRITER_INFO_T nandWriterInfo;
+/* 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);
+ }
+}
+
/******************************************************************************
* Function: print_platform_errno
******************************************************************************/
uint32_t block, start_block;
uint8_t *scrach_block;
- scrach_block = malloc(nandWriterInfo.blockSizeBytes);
- if (scrach_block == NULL)
+ if (swap_byte)
{
- printf ("Can not allocate scratch block memory!\n");
- return (FALSE);
+ scrach_block = malloc(nandWriterInfo.blockSizeBytes);
+ if (scrach_block == NULL)
+ {
+ printf ("Can not allocate scratch block memory!\n");
+ return (FALSE);
+ }
}
start_block = nandWriterInfo.startAddr / nandWriterInfo.blockSizeBytes;
if (++block == p_device->block_count)
{
printf ("Flash failed: End of device reached\n");
- free (scrach_block);
+ if (swap_byte) free (scrach_block);
return (FALSE);
}
}
printf ("Flashing block %d (%d bytes of %d)\n", block, wPos, nandWriterInfo.writeBytes);
+ platform_device_erase_block(p_device->handle, block);
+
wLen = nandWriterInfo.blockSizeBytes;
if (nandWriterInfo.writeBytes - wPos < nandWriterInfo.blockSizeBytes)
{
wLen = nandWriterInfo.writeBytes - wPos;
}
- formBlock((uint32_t *)(&nandWriterInfo.writeData[wPos]), nandWriterInfo.blockSizeBytes, scrach_block);
+ if (swap_byte)
+ {
+ formBlock((uint32_t *)(&nandWriterInfo.writeData[wPos]), nandWriterInfo.blockSizeBytes, scrach_block);
+ }
+ else
+ {
+ scrach_block = &nandWriterInfo.writeData[wPos];
+ }
if (platform_device_write(p_device->handle,
block*nandWriterInfo.blockSizeBytes,
scrach_block,
{
printf ("platform_device_write block # %d failed!\n", block);
print_platform_errno();
- free (scrach_block);
+ if (swap_byte) free (scrach_block);
return (FALSE);
}
}
- free (scrach_block);
+ if (swap_byte) free (scrach_block);
return (TRUE);
}
uint8_t *scrach_block;
uint32_t *read_data_w;
- scrach_block = malloc(nandWriterInfo.blockSizeBytes);
- if (scrach_block == NULL)
+ if (swap_byte)
{
- printf ("Can not allocate scratch block memory!\n");
- return (FALSE);
+ scrach_block = malloc(nandWriterInfo.blockSizeBytes);
+ if (scrach_block == NULL)
+ {
+ printf ("Can not allocate scratch block memory!\n");
+ return (FALSE);
+ }
}
start_block = nandWriterInfo.startAddr / nandWriterInfo.blockSizeBytes;
if (++block == p_device->block_count)
{
printf ("Flash failed: End of device reached\n");
- free (scrach_block);
+ if (swap_byte) free (scrach_block);
return (FALSE);
}
}
printf ("Reading and verifying block %d (%d bytes of %d)\n", block, rPos, nandWriterInfo.writeBytes);
+ if (!swap_byte)
+ {
+ scrach_block = &nandWriterInfo.readData[rPos];
+
+ }
+
/* Read a block of data */
if(platform_device_read(p_device->handle,
block*nandWriterInfo.blockSizeBytes,
printf ("marking block %d as bad, re-flash attempted\n", block);
markBlockBad (p_device, block);
}
- free (scrach_block);
+ if (swap_byte) free (scrach_block);
return (FALSE);
}
/* Convert the packed data */
- read_data_w = (uint32_t *)(&nandWriterInfo.readData[rPos]);
- for (i = 0, j = 0; i < nandWriterInfo.blockSizeBytes; 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];
+ if (swap_byte)
+ {
+ read_data_w = (uint32_t *)(&nandWriterInfo.readData[rPos]);
+ for (i = 0, j = 0; i < nandWriterInfo.blockSizeBytes; 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];
+ }
rLen = nandWriterInfo.blockSizeBytes;
if (nandWriterInfo.writeBytes - rPos < nandWriterInfo.blockSizeBytes)
{
printf ("Failure in block %d, at byte %d, (at byte %d in the data file) expected 0x%08x, read 0x%08x\n",
block, i, rPos, nandWriterInfo.writeData[i], nandWriterInfo.readData[i]);
- free (scrach_block);
+ if (swap_byte) free (scrach_block);
return (FALSE);
}
}
}
- free (scrach_block);
+ if (swap_byte) free (scrach_block);
return (TRUE);
}
/******************************************************************************
* Function: parse_input_file
******************************************************************************/
-Bool
+static Bool
parse_input_file
(
FILE* fp
}
/******************************************************************************
- * Function: parse_ccs_file
+ * Function: find_file_length
******************************************************************************/
-Bool
-parse_ccs_file
+static Bool
+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);
+ ext = strrchr(nandWriterInfo.file_name, '.');
+ if (ext && (strcmp(ext, ".dat") == 0))
+ {
fgets(line, MAX_LINE_LENGTH, fp);
/* Read the write address from the CCS header */
/* 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 > (nandWriterInfo.deviceTotalBytes - nandWriterInfo.startAddr))
{
printf ("The data file is too big to fit into the device.\n");
PLATFORM_DEVICE_info *p_device;
Bool ret;
uint32_t rCount;
+ printf("NAND Writer Utility Version %s\n\n", version);
fp = fopen(input_file, "r");
if (fp == NULL)
}
/* Parse the CCS format file */
- ret = parse_ccs_file(fp);
+ ret = find_file_length(fp);
fclose (fp);
if (ret == FALSE)
{
if (flash_nand (p_device) == FALSE)
{
printf ("NAND write giving up\n");
- break;
+ return;
}
rCount += 1;