]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - keystone-rtos/ibl.git/blobdiff - src/util/iblConfig/src/iblConfig.c
Corrected merge for 6657 ibl
[keystone-rtos/ibl.git] / src / util / iblConfig / src / iblConfig.c
index 64f4b3a1986bc1b3da477099de256a41a4ff069f..143ba4fd609870f0f564d431799c179860e060dc 100644 (file)
@@ -1,23 +1,29 @@
 #include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#include <stdint.h>
-#include <arpa/inet.h>
 #include "device.h"
 
 #define TRUE 1
 #define FALSE 0
-#define MAX_LINE_LENGTH 40
-char *input_file = "input.txt";
+#define MAX_LINE_LENGTH 80
+#define DEFAULT_ETHBOOT_IDX 0
+#define EVM_C6678_ETHBOOT_IDX 2
 
 /* Parameters defined in the input_file */
 #define FILE_NAME      "file_name"
 #define DEVICE_ID      "device"
 #define OFFSET_ADDR    "offset"
+#define DOBOOTP  "ethBoot-doBootp"
+#define BOOTFORMAT  "ethBoot-bootFormat"
+#define IPADDR  "ethBoot-ipAddr"
+#define SERVERIP  "ethBoot-serverIp"
+#define GATEWAYIP  "ethBoot-gatewayIp"
+#define NETMASK  "ethBoot-netmask"
+#define FILENAME  "ethBoot-fileName"
 
+
+char *input_file = "./input.txt";
 char        file_name[MAX_LINE_LENGTH];
 uint32_t    device_id;
-uint32_t    offset = I2C_MAP_ADDR;
+uint32_t    offset;
 
 #define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
 typedef ibl_t (*ibl_config_fn)(void);
@@ -25,7 +31,7 @@ typedef ibl_t (*ibl_config_fn)(void);
 int main (void)
 {
     ibl_t ibl_params;
-    FILE    *fp;
+    FILE    *fp, *mfp;
     int    ret;
     ibl_config_fn cfg[] = {
            [1] = &c6455_ibl_config,
@@ -35,14 +41,15 @@ int main (void)
            [5] = &c6472_ibl_config,
            [6] = &c6678_ibl_config,
            [7] = &c6670_ibl_config,
+           [8] = &c6657_ibl_config,
     };
     int ncfgs = ARRAY_SIZE(cfg);
 
     fp = fopen(input_file, "r");
     if (fp == NULL)
     {
-        printf("Error in opening %s input file\n", input_file);
-        return;
+           printf("Error in opening %s input file\n", input_file);
+           return;
     }
 
     ret = parse_input_file(fp);
@@ -55,7 +62,7 @@ int main (void)
     }
 
 
-    fp = fopen (file_name, "r+");
+    fp = fopen (file_name, "r+b");
     if (fp == NULL)
     {
         printf ("Failed to open file %s\n", file_name);
@@ -71,15 +78,21 @@ int main (void)
 
     if (device_id > 0 && device_id < ncfgs)
            ibl_params = (*cfg[device_id])();
+               
+       mfp = fopen(input_file, "r");
+       modifyIblConfig(mfp, &ibl_params);
+       fclose(mfp);
     
     if (fwrite((void*)&ibl_params, sizeof(ibl_t), 1, fp) != 1) {
         fclose(fp);
         return -1;
     }
 
+
     printf ("Generated updated binary %s\n", file_name);
 
     fclose(fp);
+    return 0;
 }
 
 int32_t 
@@ -206,3 +219,71 @@ int parse_input_file(FILE *fp)
     return TRUE;
 }
 
+int modifyIblConfig(FILE *fp, ibl_t *ibl)
+{
+    char line[MAX_LINE_LENGTH];
+    char tokens[] = " :=;\n\r";
+    char *key, *data;
+       unsigned char ethBootIdx=DEFAULT_ETHBOOT_IDX, i0, i1, i2, i3;
+    if ((device_id == 6) || (device_id == 7)) 
+        ethBootIdx = EVM_C6678_ETHBOOT_IDX;
+    memset(line, 0, MAX_LINE_LENGTH);
+
+    while(fgets(line, MAX_LINE_LENGTH, fp) != '\0')
+       {
+               key  = (char *)strtok(line, tokens);
+               data = (char *)strtok(NULL, tokens);
+               if ( (key == NULL) || (data == NULL) ) {} 
+               else if (strcmp(key, DOBOOTP) == 0)
+               {
+                       if (strcmp(data, "TRUE") == 0)
+                               ibl->bootModes[ethBootIdx].u.ethBoot.doBootp = TRUE;
+                       else
+                               ibl->bootModes[ethBootIdx].u.ethBoot.doBootp = FALSE;
+               }
+               else if (strcmp(key, BOOTFORMAT) == 0)
+               {
+                       if (strcmp(data, "ibl_BOOT_FORMAT_ELF") == 0)
+                               ibl->bootModes[ethBootIdx].u.ethBoot.bootFormat = ibl_BOOT_FORMAT_ELF;
+                       else
+                               ibl->bootModes[ethBootIdx].u.ethBoot.bootFormat = ibl_BOOT_FORMAT_BBLOB;
+               }
+               else if (strcmp(key, IPADDR) == 0)
+               {
+                       i0 = atoi((unsigned char*)strtok(data, "."));
+                       i1 = atoi((unsigned char*)strtok(NULL, "."));
+                       i2 = atoi((unsigned char*)strtok(NULL, "."));
+                       i3 = atoi((unsigned char*)strtok(NULL, "."));
+                       SETIP(ibl->bootModes[ethBootIdx].u.ethBoot.ethInfo.ipAddr, i0, i1, i2, i3);
+               }
+               else if (strcmp(key, SERVERIP) == 0)
+               {
+                       i0 = atoi((unsigned char*)strtok(data, "."));
+                       i1 = atoi((unsigned char*)strtok(NULL, "."));
+                       i2 = atoi((unsigned char*)strtok(NULL, "."));
+                       i3 = atoi((unsigned char*)strtok(NULL, "."));
+                       SETIP(ibl->bootModes[ethBootIdx].u.ethBoot.ethInfo.serverIp, i0, i1, i2, i3);
+               }
+               else if (strcmp(key, GATEWAYIP) == 0)
+               {
+                       i0 = atoi((unsigned char*)strtok(data, "."));
+                       i1 = atoi((unsigned char*)strtok(NULL, "."));
+                       i2 = atoi((unsigned char*)strtok(NULL, "."));
+                       i3 = atoi((unsigned char*)strtok(NULL, "."));
+                       SETIP(ibl->bootModes[ethBootIdx].u.ethBoot.ethInfo.gatewayIp, i0, i1, i2, i3);
+               }
+               else if (strcmp(key, NETMASK) == 0)
+               {
+                       i0 = atoi((unsigned char*)strtok(data, "."));
+                       i1 = atoi((unsigned char*)strtok(NULL, "."));
+                       i2 = atoi((unsigned char*)strtok(NULL, "."));
+                       i3 = atoi((unsigned char*)strtok(NULL, "."));
+                       SETIP(ibl->bootModes[ethBootIdx].u.ethBoot.ethInfo.netmask, i0, i1, i2, i3);
+               }
+               else if (strcmp(key, FILENAME) == 0)
+               {
+                       strcpy(ibl->bootModes[ethBootIdx].u.ethBoot.ethInfo.fileName, data);
+               }
+       }
+    return TRUE;
+}