]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - keystone-rtos/ibl.git/commitdiff
C6474 required changes
authorMike Line <m-line1@ti.com>
Wed, 27 Oct 2010 17:39:17 +0000 (13:39 -0400)
committerMike Line <m-line1@ti.com>
Wed, 27 Oct 2010 17:39:17 +0000 (13:39 -0400)
Removed Elf and Nand to fit the boot into the 32k byte i2c on the evm.
Squashed the i2c image as much as possible.
Modified the emif3.1 programming sequence as required by the 6474.

15 files changed:
src/cfg/c6474/iblcfg.h
src/device/c6474/c6474.c
src/ethboot/ethboot.c
src/hw/ddrs/emif31/emif31.c
src/interp/coff/cload.c
src/interp/elf/ibl_elf.h
src/main/iblmain.c
src/make/c64x/makedefs.mk
src/make/ibl_c6474/i2crom_le.map
src/make/ibl_c6474/ibl.cmd
src/make/makestg2
src/nandboot/nandboot.c
src/util/i2cWrite/i2cWrite.c
src/util/romparse/romparse.c
src/util/romparse/romparse.h

index 6ed069fcbf22ee98a509426c9d0d3b5f321e326c..d75946a05523d95dfbff7aa1597883d6e911a0ec 100644 (file)
  #define IBL_I2C_CFG_EEPROM_BUS_ADDR    0x50
 #endif
 
-#define IBL_I2C_CFG_TABLE_DATA_ADDR     (0x10000 - 0x300)
+#define IBL_I2C_CFG_TABLE_DATA_ADDR     (0x8000 - 0x300)
  
  
 
+/**
+ * @brief No NAND support. Define the function call to be a void statement
+ */
+#define iblNandBoot()
+
+/**
+ * @brief No Elf support
+ */
+#define iblIsElf(x)         FALSE
+#define iblBootElf(x,y)     for (;;);
 
 
 #endif
index fe2747650f0d48d48ed68d22a86d67a82fc9e727..9622bcd25df197d59c1febcbc48ad3b4bdd82f9c 100644 (file)
 extern cregister unsigned int DNUM;
 
 
-#if 0
-/**
- * @brief The default boot configuration table is filled in
- *
- * @details
- *   A default ibl configuraiton table is provided when one is not found
- *   preloaded.
- */
-void deviceLoadDefaultIblTable (void)
-{
-    uint32 macA, macB;
-
-#if 0  /* This is really the default. Switching to a direct tftp boot until I have a bootp server
-        * on a private lan for test */
-    ibl.ethConfig[0].ethPriority = ibl_LOWEST_PRIORITY;
-    ibl.ethConfig[0].port        = 0;
-    ibl.ethConfig[0].doBootp     = TRUE;
-    ibl.ethConfig[0].bootFormat  = ibl_BOOT_FORMAT_AUTO;
-
-    memset (&ibl.ethConfig[0].ethInfo, 0, sizeof(ibl.ethConfig[0].ethInfo));
-#endif
-
-    /* This is the temporary code */
-    ibl.ethConfig[0].ethPriority      = ibl_LOWEST_PRIORITY;
-    ibl.ethConfig[0].port             = 0;
-    ibl.ethConfig[0].doBootp          = FALSE;
-    ibl.ethConfig[0].useBootpServerIp = FALSE;
-    ibl.ethConfig[0].useBootpFileName = FALSE;
-    ibl.ethConfig[0].bootFormat       = ibl_BOOT_FORMAT_NAME;
-
-    memset (&ibl.ethConfig[0].ethInfo, 0, sizeof(ibl.ethConfig[0].ethInfo));
-
-    ibl.ethConfig[0].ethInfo.ipAddr[0] = 10;
-    ibl.ethConfig[0].ethInfo.ipAddr[1] = 218;
-    ibl.ethConfig[0].ethInfo.ipAddr[2] = 109;
-    ibl.ethConfig[0].ethInfo.ipAddr[3] = 21;
-
-    ibl.ethConfig[0].ethInfo.serverIp[0] = 10;
-    ibl.ethConfig[0].ethInfo.serverIp[1] = 218;
-    ibl.ethConfig[0].ethInfo.serverIp[2] = 109;
-    ibl.ethConfig[0].ethInfo.serverIp[3] = 196;
-
-    ibl.ethConfig[0].ethInfo.gatewayIp[0] = 10;
-    ibl.ethConfig[0].ethInfo.gatewayIp[1] = 218;
-    ibl.ethConfig[0].ethInfo.gatewayIp[2] = 109;
-    ibl.ethConfig[0].ethInfo.gatewayIp[3] = 1;
-
-    /* Leave hw address as 0 */
-
-    strcpy (ibl.ethConfig[0].ethInfo.fileName, "test2_little.out");
-
-    ibl.ethConfig[0].blob.startAddress  = 0x00200000;       /* Base address of SL2 */
-    ibl.ethConfig[0].blob.sizeBytes     = 0x000c0000;       /* All of SL2 */
-    ibl.ethConfig[0].blob.branchAddress = 0x00200000;       /* Base of SL2 */
-
-
-
-    macA = *((uint32 *)0x2a80700);
-    macB = *((uint32 *)0x2a80704);
-
-    ibl.ethConfig[0].ethInfo.hwAddress[0] = (macA >> 24) & 0xff;
-    ibl.ethConfig[0].ethInfo.hwAddress[1] = (macA >> 16) & 0xff;
-    ibl.ethConfig[0].ethInfo.hwAddress[2] = (macA >>  8) & 0xff;
-    ibl.ethConfig[0].ethInfo.hwAddress[3] = (macA >>  0) & 0xff;
-    ibl.ethConfig[0].ethInfo.hwAddress[4] = (macB >> 24) & 0xff;
-    ibl.ethConfig[0].ethInfo.hwAddress[5] = (macB >> 16) & 0xff;
-
-
-    ibl.ethConfig[1].ethPriority = ibl_DEVICE_NOBOOT;
-
-
-    /* MDIO configuration */
-    ibl.mdioConfig.nMdioOps = 8;
-    ibl.mdioConfig.mdioClkDiv = 0x20;
-    ibl.mdioConfig.interDelay = 1400;   /* ~2ms at 700 MHz */
-
-    ibl.mdioConfig.mdio[0] =  (1 << 30) | (27 << 21) | (24 << 16) | 0x848b;
-    ibl.mdioConfig.mdio[1] =  (1 << 30) | (20 << 21) | (24 << 16) | 0x0ce0;
-    ibl.mdioConfig.mdio[2] =  (1 << 30) | (24 << 21) | (24 << 16) | 0x4101;
-    ibl.mdioConfig.mdio[3] =  (1 << 30) | ( 0 << 21) | (24 << 16) | 0x9140;
-
-    ibl.mdioConfig.mdio[4] =  (1 << 30) | (27 << 21) | (25 << 16) | 0x848b;
-    ibl.mdioConfig.mdio[5] =  (1 << 30) | (20 << 21) | (25 << 16) | 0x0ce0;
-    ibl.mdioConfig.mdio[6] =  (1 << 30) | (24 << 21) | (25 << 16) | 0x4101;
-    ibl.mdioConfig.mdio[7] =  (1 << 30) | ( 0 << 21) | (25 << 16) | 0x9140;
-
-
-    /* Main Pll configuration */
-    ibl.pllConfig[ibl_MAIN_PLL].doEnable = TRUE;
-    ibl.pllConfig[ibl_MAIN_PLL].prediv   = 1;
-    ibl.pllConfig[ibl_MAIN_PLL].mult     = 28;
-    ibl.pllConfig[ibl_MAIN_PLL].postdiv  = 1;
-
-    ibl.pllConfig[ibl_MAIN_PLL].pllOutFreqMhz = 500;
-
-    /* The DDR PLL. The multipliers/dividers are fixed, so are really dont cares */
-    ibl.pllConfig[ibl_DDR_PLL].doEnable = TRUE;
-
-    /* The network PLL. The multipliers/dividers are fixed */
-    ibl.pllConfig[ibl_NET_PLL].doEnable = TRUE;
-
-    /* EMIF configuration */
-    ibl.ddrConfig.uEmif.emif3p1.sdcfg  = 0x00538832; /* timing, 32bit wide */
-    ibl.ddrConfig.uEmif.emif3p1.sdrfc  = 0x0000073B; /* Refresh 533Mhz */ 
-    ibl.ddrConfig.uEmif.emif3p1.sdtim1 = 0x47245BD2; /* Timing 1 */
-    ibl.ddrConfig.uEmif.emif3p1.sdtim2 = 0x0125DC44; /* Timing 2 */
-    ibl.ddrConfig.uEmif.emif3p1.dmcctl = 0x50001906; /* PHY read latency for CAS 5 is 5 + 2 - 1 */
-
-
-    /* NAND configuration for the MT29F1G08 flash */
-    ibl.nandConfig.nandPriority = ibl_HIGHEST_PRIORITY;
-    ibl.nandConfig.bootFormat   = ibl_BOOT_FORMAT_COFF;
-
-    ibl.nandConfig.nandInfo.busWidthBits  = 8;
-    ibl.nandConfig.nandInfo.pageSizeBytes = 2048;
-    ibl.nandConfig.nandInfo.pageEccBytes  = 64;
-    ibl.nandConfig.nandInfo.pagesPerBlock = 64;
-    ibl.nandConfig.nandInfo.totalBlocks   = 1024;
-
-    ibl.nandConfig.nandInfo.addressBytes  = 4;
-    ibl.nandConfig.nandInfo.lsbFirst      = TRUE;
-    ibl.nandConfig.nandInfo.blockOffset   = 22;
-    ibl.nandConfig.nandInfo.pageOffset    = 16;
-    ibl.nandConfig.nandInfo.columnOffset  = 0;
-
-    ibl.nandConfig.nandInfo.resetCommand    = 0xff;
-    ibl.nandConfig.nandInfo.readCommandPre  = 0;
-    ibl.nandConfig.nandInfo.readCommandPost = 0x30;
-    ibl.nandConfig.nandInfo.postCommand     = TRUE;
-    
-
-}
-#endif
-
 /**
  *  @brief Determine if an address is local
  *
@@ -260,6 +126,7 @@ int32 devicePowerPeriph (int32 modNum)
  *  @details  On the evm the nand controller is enabled by setting 
  *            gpio 14 high
  */
+#if 0
 int32 deviceConfigureForNand(void)
 {
        hwGpioSetDirection(NAND_MODE_GPIO, GPIO_OUT);
@@ -267,6 +134,7 @@ int32 deviceConfigureForNand(void)
     return (0);
 
 }
+#endif
 
 
 /**
index 090c9b6db7e7aa39191795702ac51c9a6a1ebab0..c4e2f52f845b47163ab325f256bb6e2cdeccc258 100644 (file)
 #include "mdioapi.h"
 #include <string.h>
 
+/**
+ *  @brief Remove the possible re-definition of iblEthBoot. iblcfg.h defines this to be a void
+ *         statement if there is no ethernet boot support. It must be re-enabled for the compile
+ */
+#ifdef iblEthBoot
+ #undef iblEthBoot
+#endif
 
 /* Convert an IP address from unsigned char to IPN (uint32) */
 #define FORM_IPN(x)     (  (x[0] << 24) | \
index d21ed88878f348c4bb44278c08dadaa6680c3671..3c7e6c433a46bdfa444b49013c10fa84d5058f35 100644 (file)
@@ -24,7 +24,7 @@ void hwEmif3p1Enable (iblEmif3p1_t *cfg)
 {
     uint32 v;
 
-    v = cfg->sdcfg | (1 << 15);  /* Unlock */
+    v = cfg->sdcfg | (1 << 15) | (1 << 23);  /* Timing unlock (bit 15), boot unlock (bit 23) set */
     DEVICE_REG32_W (DEVICE_DDR_BASE + DDR_REG_SDCFG, v);
 
     DEVICE_REG32_W (DEVICE_DDR_BASE + DDR_REG_SDRFC,  cfg->sdrfc);
@@ -32,7 +32,11 @@ void hwEmif3p1Enable (iblEmif3p1_t *cfg)
     DEVICE_REG32_W (DEVICE_DDR_BASE + DDR_REG_SDTIM2, cfg->sdtim2);
     DEVICE_REG32_W (DEVICE_DDR_BASE + DDR_REG_DMCCTL, cfg->dmcctl);
 
-    v = cfg->sdcfg & (~(1 << 15));  /* lock */
+    v = v & (~(1 << 23));  /* Clear boot lock */
+    DEVICE_REG32_W (DEVICE_DDR_BASE + DDR_REG_SDCFG, v);
+
+
+    v = v & (~(1 << 15));  /* Clear timing lock */
     DEVICE_REG32_W (DEVICE_DDR_BASE + DDR_REG_SDCFG, v);
     
 }
index 9243c8b643299171247a7c83f07a38d379f03bf1..1ef6bde84995eb3493ebb638b4fa7fcd7c0471c2 100644 (file)
@@ -163,6 +163,8 @@ typedef struct strtab
 
 unsigned int unpack();
 
+#define reloc_read(x)   TRUE
+
 /* extern void mem_copy(unsigned char* dst, unsigned char* src, int nbytes); - defined in osal.h */
 /******************************************************************************/
 /*                                                                            */
@@ -631,8 +633,11 @@ int cload_sect_data(SCNHDR *sptr)
            /*----------------------------------------------------------------*/
            /* PERFORM THE RELOCATION AND READ IN THE NEXT RELOCATION ENTRY.  */
            /*----------------------------------------------------------------*/
+#if 0
            if (!relocate(&reloc, packet + i, curr_sect)) 
                 { free (packet); return FALSE; }
+#endif
+
 #if FILE_BASED  
            if (n_reloc++ < sptr->s_nreloc                                    &&
               (fseek(fin, sptr->s_relptr + ((int)n_reloc * relsz), 0) != 0  ||
@@ -1171,6 +1176,7 @@ char *sym_add_name(SYMENT *symptr)
 }
 #endif
 
+#if 0
 /******************************************************************************/
 /*                                                                            */
 /* RELOC_ADD() - Add an entry to the relocation symbol table.  This table     */
@@ -1834,6 +1840,7 @@ int reloc_read(RELOC *rptr, unsigned int offset)
 }
 
 
+#endif
 /*************************************************************************/
 /*                                                                       */
 /*   RELOC_SIZE()-                                                       */
@@ -1987,6 +1994,7 @@ int reloc_stop(int type)
 }
 
 
+#if 0
 /******************************************************************************/
 /*                                                                            */
 /* SYM_RELOC_AMOUNT() - Determine the amount of relocation for a particular   */
@@ -2019,6 +2027,7 @@ int sym_reloc_amount(RELOC *rp)
    return 0;
 }
 
+#endif
 
 /******************************************************************************/
 /*                                                                            */
index c5498ce388d8472194529425232d9db7fe43567a..cf6ca89937aaf08b6d59f503d92300313ece29a0 100644 (file)
 #include "iblloc.h"
  
 
+#ifndef iblBootElf
 void iblBootElf (BOOT_MODULE_FXN_TABLE *bootFxn, Uint32 *ientry_point);
+#endif
+
+#ifndef iblIsElf
 BOOL iblIsElf (Uint8 *elfhdr);
+#endif
 
 
 #endif /* _IBL_ELF_H */
index 317670bf0ef434c3e3c9a4fc43bd6b70f33bb30f..8507b5f2e4297c93040ce0c2770f6c5ce156f089 100644 (file)
@@ -162,7 +162,8 @@ void main (void)
     for (;;)  {
 
         /* Start looping through the boot modes to find the one with the lowest priority
-         * value, and try to boot it */
+         * value, and try to boot it. If a boot mode is not supported the function
+         * statement is simply defined to be a void statement */
         for (i = ibl_HIGHEST_PRIORITY; i < ibl_LOWEST_PRIORITY; i++)  {
 
             for (j = 0; j < ibl_N_ETH_PORTS; j++)  {
index dfe3c6693daccbafe02273556d5fd35cc38a1a9d..f5158c89abb41cda2e06e3668a81c80b0376b79d 100644 (file)
@@ -70,7 +70,7 @@ ifneq ($(UTIL),yes)
  ifeq ($(DEBUG),yes)
   CFLAGS  = -c -k -mi200 -ml3 -ms3 -o2 -pm -pds1111 -pds827 -pds824 -pds837 -pds1037 -pds195 -pds97 -pden -pdr $(CPUFLAGS)
  else
-  CFLAGS  = -c -k -mi200 -ml0 -ms3 -o2 -pm -pds1111 -pds827 -pds824 -pds837 -pds1037 -pds195 -pds97 -pden -pdr $(CPUFLAGS)
+  CFLAGS  = -c -k -mi200 -ml0 -ms3 -o3 -pm -pds1111 -pds827 -pds824 -pds837 -pds1037 -pds195 -pds97 -pden -pdr $(CPUFLAGS)
  endif
 else
  CFLAGS  = -c -k -mi200 -ml3 -ms3 -o2 -pm -pds1111 -pds827 -pds824 -pds837 -pds1037 -pds195 -pds97 -pden -pdr $(CPUFLAGS)
index 9a1ff2e683de3f57da9e553c6c1ce321e4d824ad..b1ae02d91bd4eed015a89eef366ffb23b2aa3b82 100644 (file)
@@ -6,7 +6,7 @@ section
   options       = 1
 
   core_freq_mhz    = 1000
-  i2c_clk_freq_khz = 400
+  i2c_clk_freq_khz = 100
 
   dev_addr_ext = 0x50
 
index 0aa80cbea840f28feca30834cae997a10b3bfda8..fdabe5adde588266d5792aa123af94cac3e47ea9 100644 (file)
@@ -11,7 +11,6 @@
 ../main/c64x/make/iblmain.oc
 ../device/c64x/make/c6474.oc
 ../ethboot/c64x/make/ethboot.oc
-../nandboot/c64x/make/nandboot.oc
 ../driver/c64x/make/net.oc
 ../driver/c64x/make/arp.oc
 ../driver/c64x/make/ip.oc
 ../driver/c64x/make/timer.oc
 ../driver/c64x/make/bootp.oc
 ../driver/c64x/make/tftp.oc
-../driver/c64x/make/nand.oc
 ../hw/c64x/make/t64.oc
 ../hw/c64x/make/cpmacdrv.oc
 ../hw/c64x/make/pll.oc
 ../hw/c64x/make/psc.oc
 ../hw/c64x/make/emif31.oc
 ../hw/c64x/make/mdio.oc
-../hw/c64x/make/gpio.oc
-../hw/c64x/make/nandgpio.oc
 ../hw/c64x/make/i2c.oc
 ../hw/c64x/make/sgmii.oc
 ../interp/c64x/make/bis.oc
 ../interp/c64x/make/gem.oc
 ../interp/c64x/make/blob.oc
 
-../interp/c64x/make/dload.oc
-../interp/c64x/make/elfwrap.oc
-../interp/c64x/make/dlw_client.oc
-../interp/c64x/make/dload_endian.oc
-../interp/c64x/make/ArrayList.oc
+/* ../interp/c64x/make/dload.oc */
+/* ../interp/c64x/make/elfwrap.oc */
+/* ../interp/c64x/make/dlw_client.oc */
+/* ../interp/c64x/make/dload_endian.oc */
+/* ../interp/c64x/make/ArrayList.oc */
 
-../ecc/c64x/make/3byte_ecc.oc
+/* ../nandboot/c64x/make/nandboot.oc */
+/* ../driver/c64x/make/nand.oc */
+/* ../ecc/c64x/make/3byte_ecc.oc */
+/* ../hw/c64x/make/gpio.oc */
+/* ../hw/c64x/make/nandgpio.oc */
 
 -c
 -stack 0x800
index 5eca673f5d90d16a43a43d0153d98cb0dbe7c365..35d3bdce0d4c5475b1f77f5d2c65a86df1e26516 100644 (file)
@@ -24,6 +24,12 @@ else
        IEXT=     be
 endif
 
+ifeq ($(TARGET),c6474)
+  COMPACT= -compact
+else
+  COMPACT=
+endif
+
 include $(IBL_ROOT)/make/$(ARCH)/makedefs.mk
 
 export ARCH
@@ -37,7 +43,7 @@ $(TARGETS): $(MODULES) utils $(RIBL)
        $(CP) ibl.b ibl_$@
        ../util/btoccs/b2i2c ibl_$@/ibl.b ibl_$@/ibl.i2c.b
        ../util/btoccs/b2ccs ibl_$@/ibl.i2c.b ibl_$@/ibl.i2c.$(IEXT).ccs
-       ../util/romparse/romparse ibl_$@/i2crom_$(IEXT).map
+       ../util/romparse/romparse $(COMPACT) ibl_$@/i2crom_$(IEXT).map
        $(CP) i2crom.ccs ibl_$@/i2crom_$(IEXT).ccs
        $(CP) i2crom.ccs ibl_$@/i2crom_$(IEXT).dat
        $(RM) i2crom.ccs ibl_le.b ibl.b
index d4fc7cdc37914b9e5ac2f3a00ba1191a8dcd66a8..e03f2344b47bb137ef7209fc58f5f10cb130f460 100644 (file)
 #include "nand.h"
 #include "device.h"
 
+/** 
+ * @brief
+ *   Nandboot is disabled through iblcfg.h. Disable the definition for the compilation
+ */
+#ifdef iblNandBoot
+ #undef iblNandBoot
+#endif
+
 
 void iblNandBoot (void)
 {
index d145002badd7ca173fd33fcf67deb3b67ccb0ef0..f3d93e09edcf2d1aef6016e054f910db1d6556d1 100644 (file)
@@ -19,6 +19,7 @@
 /* Run time configuration */
 unsigned int   deviceFreqMhz = 1000;
 unsigned short busAddress    = 0x50;
+unsigned int   i2cBlockSize  = 64;
 unsigned int   nbytes        = I2C_SIZE_BYTES;
 unsigned int   dataAddress   = 0;
 
@@ -26,8 +27,8 @@ unsigned int   dataAddress   = 0;
 #pragma DATA_SECTION(i2cData, ".i2cData")
 unsigned int i2cData[I2C_SIZE_BYTES >> 2];
 
-#define I2C_BLOCK_SIZE_BYTES    64
-unsigned char i2cBlock[I2C_BLOCK_SIZE_BYTES+4];  /* need 2 bytes for the address */
+#define I2C_MAX_BLOCK_SIZE_BYTES    256
+unsigned char i2cBlock[I2C_MAX_BLOCK_SIZE_BYTES+4];  /* need 2 bytes for the address */
 
 /** 
  *  @brief
@@ -53,7 +54,7 @@ int formBlock (unsigned int addr, int byteIndex, int n)
     p = byteIndex >> 2;
 
 
-    for (i = 0; i < I2C_BLOCK_SIZE_BYTES; i += 4, p++)  {
+    for (i = 0; i < i2cBlockSize; i += 4, p++)  {
 
         i2cBlock[i+2+0] = (i2cData[p] >> 24) & 0xff;
         i2cBlock[i+2+1] = (i2cData[p] >> 16) & 0xff;
@@ -117,11 +118,11 @@ void main (void)
 
 
 
-    for (n = 0; n < nbytes; n += I2C_BLOCK_SIZE_BYTES)  {
+    for (n = 0; n < nbytes; n += i2cBlockSize)  {
 
         remain = nbytes - n;
-        if (remain > I2C_BLOCK_SIZE_BYTES)
-            remain = I2C_BLOCK_SIZE_BYTES;
+        if (remain > i2cBlockSize)
+            remain = i2cBlockSize;
 
         /* formBlock sets up the address as well as the data */
         progBytes = formBlock (dataAddress + n, n, remain);
index 01033d967206c51f301fee5d03c318c2bd41c8bd..30e19cbd1e167daebd2c41e266e9070ff3c58269 100644 (file)
@@ -32,7 +32,9 @@ extern FILE *yyin;
  *************************************************************************************/
 BOOT_PARAMS_T boot_params[NUM_BOOT_PARAM_TABLES];
 BOOT_PARAMS_T current_table;
+int           current_file;       /* Identifies the program file in the current table */
 int           ctable_index = -1;  /* Destination of current table */
+int           max_index    =  0;  /* maximum table index, used for compacting output */
 
 /************************************************************************************
  * Declaration: The structure storing the program data files, and the number of
@@ -54,6 +56,14 @@ int       pciSet = 0;
  *************************************************************************************/
 int romBase = DATA_BASE;
 
+
+/*************************************************************************************
+ * Declaration: Args passed in from the command line
+ *************************************************************************************/
+char *inputFile;
+int   compact = 0;
+
+
 /*************************************************************************************
  * FUNCTION PURPOSE: flex/bison required support functions.
  *************************************************************************************
@@ -80,6 +90,25 @@ void initTable (BOOT_PARAMS_T *current_table)
   memset (current_table, 0, sizeof(BOOT_PARAMS_T));
 }
 
+/*************************************************************************************
+ * FUNCTION PURPOSE: Initialize the program data file table
+ *************************************************************************************
+ * DESCRIPTION: The size and tags are all setup
+ *************************************************************************************/
+void initProgFile (void)
+{
+  int i, j;
+
+  for (i = 0; i < NUM_BOOT_PARAM_TABLES; i++)  {
+    progFile[i].sizeBytes = 0;
+
+    for (j = 0; j < NUM_BOOT_PARAM_TABLES; j++)
+      progFile[i].tag[j] = -1;
+
+  }
+
+}
+
 /*************************************************************************************
  * FUNCTION PURPOSE: Complete a section
  *************************************************************************************
@@ -88,6 +117,8 @@ void initTable (BOOT_PARAMS_T *current_table)
  *************************************************************************************/
 void section (void)
 {
+  int i;
+
   /* It's an error if no section value has been declared */
   if (ctable_index == -1)  {
     fprintf (stderr, "romparse: the section did not have a boot paramter index specified\n");
@@ -109,7 +140,21 @@ void section (void)
   memcpy (&boot_params[ctable_index], &current_table, sizeof (BOOT_PARAMS_T));
   initTable (&current_table);
 
+  /* Track the maximum table index */
+  if (ctable_index > max_index)
+    max_index = ctable_index;
+
+  /* If the section referenced a data file, link the data file back to this section */
+  if (current_file >= 0)  {
+    for (i = 0; i < NUM_BOOT_PARAM_TABLES; i++)  {
+      if (progFile[current_file].tag[i] < 0)
+        progFile[current_file].tag[i] = ctable_index;
+        break;
+    }
+  }
+
   ctable_index = -1;
+  current_file = -1;
 
 } /* section */
 
@@ -138,7 +183,7 @@ int openProgFile (char *fname)
   }
 
   /* Put the section at the next available i2c rom address */
-  progFile[nProgFiles].addressBytes = romBase;
+  /* progFile[nProgFiles].addressBytes = romBase; */
 
   /* Read the one line ccs header. The length field in terms of lines */
   fgets (iline, 132, str);
@@ -154,7 +199,7 @@ int openProgFile (char *fname)
   fclose (str);
 
   /* Update the next free rom base */
-  romBase = romBase + progFile[nProgFiles].sizeBytes;
+  /* romBase = romBase + progFile[nProgFiles].sizeBytes; */
 
   i = nProgFiles;
   nProgFiles += 1;
@@ -293,7 +338,8 @@ void assignKeyStr (int value, char *y)
 
     if (!strcmp (z, progFile[i].fname))  {
       /* Found a match - copy the address */
-      current_table.i2c.dev_addr     = progFile[i].addressBytes & 0xffff;
+      current_file = i;
+      /* current_table.i2c.dev_addr     = progFile[i].addressBytes & 0xffff; */
       if (current_table.i2c.dev_addr_ext == 0)
         current_table.i2c.dev_addr_ext = 0x50;  /* hard coded to i2c rom slave address */
       return;
@@ -304,7 +350,8 @@ void assignKeyStr (int value, char *y)
   /* Open and read the ccs file, set the ROM address */
   i = openProgFile (z);
   if (i >= 0) {
-    current_table.i2c.dev_addr     = progFile[i].addressBytes & 0xffff;
+    /* current_table.i2c.dev_addr     = progFile[i].addressBytes & 0xffff; */
+    current_file = i;
     if (current_table.i2c.dev_addr_ext == 0)
         current_table.i2c.dev_addr_ext = 0x50;
   }
@@ -322,7 +369,9 @@ void createOutput (void)
   FILE *str;
   int   totalLenBytes;
   int   i, j;
+  int   nTables;
   unsigned int value, v1, v2;
+  unsigned int base;
 
   str = fopen ("i2crom.ccs", "w");
   if (str == NULL)  {
@@ -330,20 +379,38 @@ void createOutput (void)
     exit (-1);
   }
 
-  /* Compute the total size of the i2c prom. Include all the i2c boot paramater tables,
-   * as well as the PCI parameter table, (which is not necessarily present). */
-  totalLenBytes = DATA_BASE;
+  /* Compact the i2c eeprom to use the minimum memory possible */
+  base    = DATA_BASE;
+  nTables = NUM_BOOT_PARAM_TABLES; 
 
-  for (i = 0; i < nProgFiles; i++)
-    totalLenBytes += progFile[i].sizeBytes;
+  if ((compact != 0) && (pciSet == 0))  {
+    nTables = max_index + 1;
+    base    = nTables * 0x80;  /* The number of parameter tables * size of a parameter table */
+  }
 
+
+  for (i = 0; i < NUM_BOOT_PARAM_TABLES; i++)  {
+    progFile[i].addressBytes = base;
+    base = base + progFile[i].sizeBytes;
+  }
+
+  /* Setup the base program file addresses. If a parameter set has
+   * been tagged it means that this is an i2c program load */
+  for (i = 0; i < NUM_BOOT_PARAM_TABLES; i++)  {
+    for (j = 0; j < NUM_BOOT_PARAM_TABLES; j++)  {
+      if (progFile[i].tag[j] >= 0)
+        boot_params[progFile[i].tag[j]].i2c.dev_addr = progFile[i].addressBytes;
+    }
+  }
+      
+  /* The total length of the i2c eeprom is now stored in base */
   /* Write out the ccs header */
-  fprintf (str, "1651 1 10000 1 %x\n", totalLenBytes >> 2);
+  fprintf (str, "1651 1 10000 1 %x\n", base >> 2);
 
   /* Write out the boot parameter tables. 0x80 bytes will be written out.
    * There are 16 bits in every parameter field, which is why the index
    * is from 0 to 0x40 */
-  for (i = 0; i < NUM_BOOT_PARAM_TABLES; i++)  {
+  for (i = 0; i < nTables; i++)  {
     for (j = 0; j < (0x80 >> 1); j += 2)  {
       v1 = boot_params[i].parameter[j];
       v2 = boot_params[i].parameter[j+1];
@@ -354,8 +421,10 @@ void createOutput (void)
 
   /* Write out the PCI parameter base. If none was included then zeros will be
    * written out */
-  for (i = 0; i < PCI_DATA_LEN_32bit; i++)  {
-    fprintf (str, "0x%08x\n", pciFile.data[i]);
+  if (pciSet)  {
+    for (i = 0; i < PCI_DATA_LEN_32bit; i++)  {
+      fprintf (str, "0x%08x\n", pciFile.data[i]);
+    }
   }
                                 
 
@@ -380,6 +449,48 @@ void initPciParams (void)
   memset (&pciFile, 0, sizeof(pciFile_t));
 } /* initPciParams */
 
+
+
+/************************************************************************************
+ * FUNCTION PURPOSE: Parse the input arguments.
+ ************************************************************************************
+ * DESCRIPTION: Returns -1 on invalid args
+ ************************************************************************************/
+int parseIt (int argc, char *argv[])
+{
+  int i;
+
+  if (argc < 2)  {
+     fprintf (stderr, "usage: %s [-compact] inputfile\n", argv[0]);
+     return (-1);
+  }
+
+  inputFile = NULL;  
+
+  for (i = 1; i < argc;  )  {
+
+    if (!strcmp (argv[i], "-compact"))  {
+      compact = 1;
+      i += 1;
+
+    } else  {
+
+      if (inputFile != NULL)  {
+        fprintf (stderr, "usage: %s [-compact] inputfile\n", argv[0]);
+        return (-1);
+      }
+
+      inputFile = argv[i];
+      i += 1;
+    }
+  }
+
+  return (0);
+
+}
+
+
+
 /************************************************************************************
  * FUNCTION PURPOSE: main function
  ************************************************************************************
@@ -394,19 +505,23 @@ int main (int argc, char *argv[])
     initTable(&boot_params[i]);
 
   initTable (&current_table);
+  current_file = -1;
+
+  /* Initialize the program file structure */
+  initProgFile ();
 
   /* Initialize the PCI param table */
   initPciParams ();
-  
-  /* open the input  */
-  if (argc != 2)  {
-    fprintf (stderr, "usage: %s inputfile\n", argv[0]);
+
+
+  /* Parse the input parameters */
+  if (parseIt (argc, argv))
     return (-1);
-  }
 
-  yyin = fopen (argv[1], "r");
+  
+  yyin = fopen (inputFile, "r");
   if (yyin == NULL)  {
-    fprintf (stderr, "%s: could not open file %s\n", argv[0], argv[1]);
+    fprintf (stderr, "%s: could not open file %s\n", argv[0], inputFile);
     return (-1);
   }
 
index f996ab3174557190ca2dbc035bb3784cd9661173..8c3fa955adfea1ea8a6718d052c5931ddc4b1d4c 100644 (file)
@@ -38,6 +38,7 @@ typedef struct {
   int  sizeBytes;
   int  addressBytes;
   unsigned int data[MAX_DATA_LEN_32bit];
+  int  tag[NUM_BOOT_PARAM_TABLES];          /* identifies boot parameter tables which use this file */
 } progFile_t;
 
 /* Define the PCI parameter structure */