+
+#if defined(CONFIG_BCM96348)
+/* *********************************************************************
+ * kerSysImageTagGet()
+ * Get the image tag
+ * Input parameters:
+ * none
+ * Return value:
+ * point to tag -- Found
+ * NULL -- failed
+ ********************************************************************* */
+PFILE_TAG kerSysImageTagGet(void)
+{
+ int i,startblock;
+ int totalBlks = flash_get_numsectors();
+ int totalSize = flash_get_total_size();
+ UINT32 crc;
+ unsigned char *sectAddr;
+ PFILE_TAG pTag;
+ unsigned char nbootflag,*bootflag;
+
+ bootflag=flash_get_memptr((byte) 0);
+
+ if (totalSize == 0x800000) {nbootflag=*bootflag;}
+ else nbootflag=1;
+
+ if (nbootflag == 2) nbootflag = 0; /*binfs is valid to boot from bfc00000*/
+ startblock = (nbootflag?1:(totalBlks>>1)+1);
+#if defined(DEBUG_FLASH)
+ printk("totalblks in tagGet=%d\n", totalBlks);
+#endif
+
+
+ // start blk, assume 1st one is always CFE
+ for (i = startblock; i < startblock + (totalBlks>>1); i++)
+ {
+ sectAddr = flash_get_memptr((byte) i);
+ crc = CRC32_INIT_VALUE;
+ crc = getCrc32(sectAddr, (UINT32)TAG_LEN-TOKEN_LEN, crc);
+ pTag = (PFILE_TAG) sectAddr;
+
+#if defined(DEBUG_FLASH)
+ printk("Check Tag crc on blk [%d]\n", i);
+#endif
+
+ if (crc == (UINT32)(*(UINT32*)(pTag->tagValidationToken)))
+ return pTag;
+ }
+
+ return (PFILE_TAG) NULL;
+}
+
+PFILE_TAG kerSysImageTagGet2(void)
+{
+ int i,startblock;
+ int totalBlks = flash_get_numsectors();
+ int totalSize = flash_get_total_size();
+ UINT32 crc;
+ unsigned char *sectAddr;
+ PFILE_TAG pTag;
+ unsigned char nbootflag,*bootflag;
+
+ bootflag=flash_get_memptr((byte) 0);
+
+ if (totalSize == 0x800000) nbootflag=1; /*always get from bf800000 */
+ else return (PFILE_TAG) NULL;
+
+ startblock = (nbootflag?1:(totalBlks>>1)+1);
+#if defined(DEBUG_FLASH)
+ printk("totalblks in tagGet=%d\n", totalBlks);
+#endif
+
+
+ // start blk, assume 1st one is always CFE
+ for (i = startblock; i < startblock + (totalBlks>>1); i++)
+ {
+ sectAddr = flash_get_memptr((byte) i);
+ crc = CRC32_INIT_VALUE;
+ crc = getCrc32(sectAddr, (UINT32)TAG_LEN-TOKEN_LEN, crc);
+ pTag = (PFILE_TAG) sectAddr;
+
+ if (*((unsigned char*) pTag->kernelLen) == 0x30 ) {
+
+#if defined(DEBUG_FLASH)
+ printk("Check Tag crc on blk [%d]\n", i);
+#endif
+
+ if (crc == (UINT32)(*(UINT32*)(pTag->tagValidationToken)))
+ return pTag;
+ }
+ }
+
+ return (PFILE_TAG) NULL;
+}
+
+
+#endif
+
+#if defined(CONFIG_BCM96338)
+PFILE_TAG kerSysImageTagGet(void)
+{
+ int i,startblock;
+ int totalBlks = flash_get_numsectors();
+ int totalSize = flash_get_total_size();
+ UINT32 crc;
+ unsigned char *sectAddr;
+ PFILE_TAG pTag;
+ unsigned char bootf1,bootf2,nbootflag=0;
+
+
+if (totalSize == 0x400000) {
+ bootf1 = *(unsigned char*) (0xbfe00000 -1); /*see design note 4MB flash layout*/
+ bootf2 = *(unsigned char*) (0xbfff0000 -1);
+ if ((bootf1 >> 2) == 0 && bootf1 ) {
+ if ((bootf2 >> 2) == 0 && bootf2 ) { /* both are valid */
+ if ((bootf1+1) == bootf2 || ((bootf1+1) >>2 == bootf2) ) nbootflag=1; /*bank2*/
+ if ((bootf2+1) == bootf1 || ((bootf2+1) >>2 == bootf1) ) nbootflag=0; /*bank1*/
+ } else nbootflag = 0; /* bank2 invalid bank1 valid */
+ }
+ else if ((bootf2 >> 2) == 0 && bootf2) nbootflag =1; /*bank 1 invalid,bank 2 valid*/
+ else nbootflag=0; /* bank1 bank2 both invalid */
+
+ printk("bootf1=%x bootf2=%x\n", bootf1,bootf2);
+}
+else nbootflag=0;
+
+ startblock = nbootflag?flash_get_blk(0xbfe00000):1;
+#if defined(DEBUG_FLASH)
+ printk("totalblks in tagGet=%d\n", totalBlks);
+#endif
+
+
+ // start blk, assume 1st one is always CFE
+ for (i = startblock; i < startblock + (totalBlks>>1); i++)
+ {
+ sectAddr = flash_get_memptr((byte) i);
+ crc = CRC32_INIT_VALUE;
+ crc = getCrc32(sectAddr, (UINT32)TAG_LEN-TOKEN_LEN, crc);
+ pTag = (PFILE_TAG) sectAddr;
+
+#if defined(DEBUG_FLASH)
+ printk("Check Tag crc on blk [%d]\n", i);
+#endif
+
+ if (crc == (UINT32)(*(UINT32*)(pTag->tagValidationToken)))
+ return pTag;
+ }
+
+ return (PFILE_TAG) NULL;
+}
+#endif