/* Initialize nand flash access */ hndnand_t * hndnand_init(si_t *sih) { uint32 origidx; ASSERT(sih); /* Already initialized ? */ if (hndnand) return hndnand; origidx = si_coreidx(sih); #ifdef __mips__ if (!hndnand) hndnand = nflash_init(sih); #endif #ifdef __ARM_ARCH_7A__ if (!hndnand) hndnand = nandcore_init(sih); #endif si_setcoreidx(sih, origidx); return hndnand; }
/* Probe for NVRAM header */ static int early_nvram_init(void) { struct nvram_header *header; chipcregs_t *cc; struct sflash *info = NULL; int i; uint32 base, off, lim; u32 *src, *dst; uint32 fltype; #ifdef NFLASH_SUPPORT struct nflash *nfl_info = NULL; uint32 blocksize; #endif header = (struct nvram_header *)ram_nvram_buf; if ((cc = si_setcore(sih, CC_CORE_ID, 0)) != NULL) { #ifdef NFLASH_SUPPORT if ((sih->ccrev == 38) && ((sih->chipst & (1 << 4)) != 0)) { fltype = NFLASH; base = KSEG1ADDR(SI_FLASH1); } else #endif { fltype = readl(&cc->capabilities) & CC_CAP_FLASH_MASK; base = KSEG1ADDR(SI_FLASH2); } switch (fltype) { case PFLASH: lim = SI_FLASH2_SZ; break; case SFLASH_ST: case SFLASH_AT: if ((info = sflash_init(sih, cc)) == NULL) return -1; lim = info->size; break; #ifdef NFLASH_SUPPORT case NFLASH: if ((nfl_info = nflash_init(sih, cc)) == NULL) return -1; lim = SI_FLASH1_SZ; break; #endif case FLASH_NONE: default: return -1; } } else { /* extif assumed, Stop at 4 MB */ base = KSEG1ADDR(SI_FLASH1); lim = SI_FLASH1_SZ; } #ifdef NFLASH_SUPPORT if (nfl_info != NULL) { blocksize = nfl_info->blocksize; off = blocksize; while (off <= lim) { if (nflash_checkbadb(sih, cc, off) != 0) { off += blocksize; continue; } header = (struct nvram_header *) KSEG1ADDR(base + off); if (header->magic == NVRAM_MAGIC) if (nvram_calc_crc(header) == (uint8) header->crc_ver_init) { goto found; } off += blocksize; } } else #endif off = FLASH_MIN; #ifdef RTN66U_NVRAM_64K_SUPPORT header = (struct nvram_header *) KSEG1ADDR(base + lim - 0x8000); if(header->magic==0xffffffff) { header = (struct nvram_header *) KSEG1ADDR(base + 1 KB); if (nvram_valid(header)) goto found; } #endif while (off <= lim) { /* Windowed flash access */ header = (struct nvram_header *) KSEG1ADDR(base + off - NVRAM_SPACE); if (nvram_valid(header)) goto found; off <<= 1; } /* Try embedded NVRAM at 4 KB and 1 KB as last resorts */ header = (struct nvram_header *) KSEG1ADDR(base + 4 KB); if (nvram_valid(header)) goto found; header = (struct nvram_header *) KSEG1ADDR(base + 1 KB); if (nvram_valid(header)) goto found; return -1; found: src = (u32 *) header; dst = (u32 *) nvram_buf; for (i = 0; i < sizeof(struct nvram_header); i += 4) *dst++ = *src++; for (; i < header->len && i < NVRAM_SPACE; i += 4) *dst++ = ltoh32(*src++); return 0; }
void test_0(UNSIGNED argc, VOID *argv) { STATUS status; int ch; int i=0, j, k; U32 padr; U32 *ptr; int bus_num = 0; /* Access argc and argv just to avoid compilation warnings. */ status = (STATUS) argc + (STATUS) argv; printf("Ready###\n"); print_help(); for(;;){ if ( ttyA_poll() == 0) { ch = ttyA_in(); switch(ch){ case 'i': status = nflash_init(); if ( status != OK) printf("Error in init - 528 \n\r"); else printf("Init OK - 528 \n\r"); break; case 'I': status = nflash_init_noecc(); if ( status != OK) printf("Error in init 512 \n\r"); else printf("Init OK - 512 \n\r"); break; case 'g': case 'G': nflash_get_id(0); break; case 'e': case 'E': if ( nflash_erase_block(0) == OK) printf("Erase OK\n\r"); else printf("Erase Fail\n\r"); break; case 'r': for(j=0; j < 16; j++) { status = nflash_read_page(lbuf, j); printf("\n\rPage %d :", j); for(i=0; i < PAGE_SIZE; i++) { if (lbuf[i] != 0xFF) { printf("Not Blank", j); break; } } printf("STUTUS %d\n\r", status); mem_print((U32)lbuf, PAGE_SIZE); } break; case 'R': for(j=0; j < 16; j++) { nflash_read_noecc(lbuf, j * PAGE_SIZE, PAGE_SIZE); printf("\n\rPage %d :", j); for(i=0; i < PAGE_SIZE; i++) { if (lbuf[i] != 0xFF) { printf("Not Blank", j); break; } } printf("\n\r"); mem_print((U32)lbuf, PAGE_SIZE); } break; case 'p': printf("Programming..."); for(j=0; j < 16; j++) { for(i=0; i < PAGE_SIZE; i++) { lbuf[i] = j + 2; if ( (i % 128) == 0) lbuf[i] |= 0x80; } if ( (status = nflash_write_page(lbuf, j)) != OK) printf("Err, Page %d status %d\n\r", j, status); } printf("Done\n\r"); break; case 'P': for(j=0; j < 16; j++) { for(i=0; i < PAGE_SIZE; i++) lbuf[i] = j + 2; if ( nflash_program_noecc(lbuf, j * PAGE_SIZE, PAGE_SIZE) != OK) printf("Program Error, Page %d\n\r", j); } break; case 'x': case 'X': { U32 *mptr = (U32 *)0xA0000001; *mptr = 1; } break; case 'u': case 'U': { int i; for(i=0; i < 10; i++) { while(!(RUART(0)->rlsr & ST_LSR_TX_EMPTY)) ; RUART(0)->holding = 'A'; } } break; case 'a': case 'A': *((U8 *)(0xBC088000)) = 0; break; case ' ': print_help(); break; default: printf("%c", ch); break; } } NU_Sleep(10); } }