// Initialize the flash and fill out the fInfo structure void kerSysEarlyFlashInit( void ) { flash_init(); bootFromNand = 0; #if defined(CONFIG_BCM96368) if( ((GPIO->StrapBus & MISC_STRAP_BUS_BOOT_SEL_MASK) >> MISC_STRAP_BUS_BOOT_SEL_SHIFT) == MISC_STRAP_BUS_BOOT_NAND) bootFromNand = 1; #elif defined(CONFIG_BCM96362) || defined(CONFIG_BCM96328) || defined(CONFIG_BCM93329) if( ((MISC->miscStrapBus & MISC_STRAP_BUS_BOOT_SEL_MASK) >> MISC_STRAP_BUS_BOOT_SEL_SHIFT) == MISC_STRAP_BUS_BOOT_NAND ) bootFromNand = 1; #endif #if defined(CONFIG_BCM96368) || defined(CONFIG_BCM96362) || defined(CONFIG_BCM96328) || defined(CONFIG_BCM93329) if( bootFromNand == 1 ) { NAND->NandNandBootConfig = NBC_AUTO_DEV_ID_CFG | 0x101; NAND->NandCsNandXor = 1; memcpy((unsigned char *)&bootCfeVersion, (unsigned char *) FLASH_BASE + CFE_VERSION_OFFSET, sizeof(bootCfeVersion)); memcpy((unsigned char *)&bootNvramData, (unsigned char *) FLASH_BASE + NVRAM_DATA_OFFSET, sizeof(NVRAM_DATA)); NAND->NandNandBootConfig = NBC_AUTO_DEV_ID_CFG | 0x2; NAND->NandCsNandXor = 0; } else #endif { fInfo.flash_rootfs_start_offset = flash_get_sector_size(0); if( fInfo.flash_rootfs_start_offset < FLASH_LENGTH_BOOT_ROM ) fInfo.flash_rootfs_start_offset = FLASH_LENGTH_BOOT_ROM; flash_read_buf (NVRAM_SECTOR, CFE_VERSION_OFFSET, (unsigned char *)&bootCfeVersion, sizeof(bootCfeVersion)); /* Read the flash contents into NVRAM buffer */ flash_read_buf (NVRAM_SECTOR, NVRAM_DATA_OFFSET, (unsigned char *)&bootNvramData, sizeof (NVRAM_DATA)) ; } #if 1 //defined(DEBUG_FLASH) printk("reading nvram into bootNvramData\n"); printk("ulPsiSize 0x%x\n", (unsigned int)bootNvramData.ulPsiSize); printk("backupPsi 0x%x\n", (unsigned int)bootNvramData.backupPsi); printk("ulSyslogSize 0x%x\n", (unsigned int)bootNvramData.ulSyslogSize); printk("Rootfs1 Off 0x%x\n", (unsigned int) bootNvramData.ulNandPartOfsKb[NP_ROOTFS_1]); printk("Rootfs1 Size 0x%x\n", (unsigned int) bootNvramData.ulNandPartSizeKb[NP_ROOTFS_1]); #endif if ((BpSetBoardId(bootNvramData.szBoardId) != BP_SUCCESS)) printk("\n*** Board is not initialized properly ***\n\n"); }
BcmProgramHeader * kerSysImageTagGet(void) { extern int get_part_offset(void); static unsigned char pgmHdr1[sizeof(BcmProgramHeader)]; /* for image 1 */ int sect; unsigned int fromaddr; #if defined(CONFIG_BCM_RAMDISK) memcpy(&pgmHdr1[0], (void *)0x87A00000, sizeof(BcmProgramHeader)); #else /* Get flash offset from which Linux image starts */ fromaddr = get_part_offset(); /* Conver to sector */ fromaddr += FLASH_BASE; sect = flash_get_blk((int) fromaddr); flash_read_buf( sect, 0, &pgmHdr1[0], sizeof(BcmProgramHeader) ); #endif #if 0 for(sect = 0; sect < sizeof(BcmProgramHeader); sect+=4) { printk("%08lx\n", *(unsigned long *)(pgmHdr1 + 4 * sect)); } printk("\n\n"); for(sect = 0; sect < sizeof(BcmProgramHeader); sect+=4) { printk("%08lx\n", *(unsigned long *)(0xBFC20000 + 4 * sect)); } #endif return (BcmProgramHeader *)pgmHdr1; }
unsigned long kerSysReadFromFlash( void *toaddr, unsigned long fromaddr, unsigned long len ) { int sect = flash_get_blk((int) fromaddr); unsigned char *start = flash_get_memptr(sect); flash_read_buf( sect, (int) fromaddr - (int) start, toaddr, len ); return( len ); }
BcmProgramHeader * kerAppImageTagGet(void) { static unsigned char pgmHdr1[sizeof(BcmProgramHeader)]; int sect; unsigned int fromaddr; fromaddr = FLASH_BASE + 0x1000000; sect = flash_get_blk((int) fromaddr); flash_read_buf( sect, 0, &pgmHdr1[0], sizeof(BcmProgramHeader) ); return (BcmProgramHeader *)pgmHdr1; }
// get shared blks into *** pTempBuf *** which has to be released bye the caller! // return: if pTempBuf != NULL, poits to the data with the dataSize of the buffer // !NULL -- ok // NULL -- fail static char *getSharedBlks(int start_blk, int num_blks) { int i = 0; int usedBlkSize = 0; int sect_size = 0; char *pTempBuf = NULL; char *pBuf = NULL; #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,30) /* not allowed to ignore the return of down_interruptible in new kernel */ if (down_interruptible(&semflash) ) { return NULL; } #else down_interruptible(&semflash); #endif for (i = start_blk; i < (start_blk + num_blks); i++) usedBlkSize += flash_get_sector_size((unsigned short) i); if ((pTempBuf = (char *) retriedKmalloc(usedBlkSize)) == NULL) { printk("failed to allocate memory with size: %d\n", usedBlkSize); up(&semflash); return pTempBuf; } pBuf = pTempBuf; for (i = start_blk; i < (start_blk + num_blks); i++) { sect_size = flash_get_sector_size((unsigned short) i); #if defined(DEBUG_FLASH) printk("getSharedBlks: blk=%d, sect_size=%d\n", i, sect_size); #endif flash_read_buf((unsigned short)i, 0, pBuf, sect_size); pBuf += sect_size; } up(&semflash); return pTempBuf; }
/*----------------------------------------------------------------------- * Copy memory to flash. * Make sure all target addresses are within Flash bounds, * and no protected sectors are hit. * Returns: * ERR_OK 0 - OK * ERR_TIMOUT 1 - write timeout * ERR_NOT_ERASED 2 - Flash not erased * ERR_PROTECTED 4 - target range includes protected sectors * ERR_INVAL 8 - target address not in Flash memory * ERR_ALIGN 16 - target address not aligned on boundary * (only some targets require alignment) */ int flash_write (char *src, ulong addr, ulong cnt) { int i; ulong end = addr + cnt - 1; flash_info_t *info_first = addr2info (addr); flash_info_t *info_last = addr2info (end ); flash_info_t *info; if (cnt == 0) { return (ERR_OK); } if (!info_first || !info_last) { return (ERR_INVAL); } for (info = info_first; info <= info_last; ++info) { ulong b_end = info->start[0] + info->size; /* bank end addr */ short s_end = info->sector_count - 1; for (i=0; i<info->sector_count; ++i) { ulong e_addr = (i == s_end) ? b_end : info->start[i + 1]; if ((end >= info->start[i]) && (addr < e_addr) &&(info->protect[i] != 0) ) { return (ERR_PROTECTED); } } } /* finally write data to flash */ for (info = info_first; info <= info_last && cnt>0; ++info) { ulong len; len = info->start[0] + info->size - addr; if (len > cnt) len = cnt; /*----------------------------------------------------------------------- * FUNCTION:flash_program_buf * Copy memory to flash, returns: * 0 - OK * 1 - write timeout * 2 - Flash not erased */ if( ( ( unsigned int ) src >= info_first->start[0] ) && ( ( unsigned int ) src <= info_first->start[0] + info_first->size ) ) { unsigned int *p=NULL; unsigned int i,j,tmp,addr_tmp,src_tmp; addr_tmp=addr; src_tmp = ( unsigned int ) src; for(i=0;i<(cnt>>10);i++) { p=malloc(1024); flash_read_buf( info , src , ( unsigned char *) p , 1024 ); if ( ( j = flash_program_buf( ( unsigned char *) addr , ( unsigned char *) p , 1024 ) ) != 0) { return (j); } src+=1024; addr+=1024; free(p); } if(len%1024!=0) { tmp=len%1024; p=malloc(tmp); flash_read_buf(info,src,p,tmp); if ((j = flash_program_buf( addr , p , tmp )) != 0) { return (j); } free(p); } addr=addr_tmp; src=src_tmp; } else { if ((i = flash_program_buf(addr,src,cnt)) != 0)