STATIC void flash_unlock_block_intel(struct bankdesc *b, uint32_t addr) { #ifdef DEBUG printf("Unlocking block 0x%08"PRIx32"\n", addr); #endif (void)BSP_flashReadRaw(F_CMD_WR_LCK, addr); (void)BSP_flashReadRaw(F_CMD_WR_CMD, addr); flash_pend(b, addr, TIMEOUT_US); }
STATIC uint32_t flash_write_line_s160(struct bankdesc *b, uint32_t a, char *s, uint32_t N) { uint32_t sta, nxt, j, v; union bconv buf; if ( 0 == N ) return -11; if ( N & (FLASH_STRIDE(b) - 1) ) { fprintf(stderr,"flash_write_line_s160: invalid byte count (not multiple of stride\n"); return -10; } unlk(b, a); /* address block */ fl_wr32_cmd(b, a, 0, WRBUF_DATA); /* (16-bit) word count per device */ N /= FLASH_STRIDE(b); fl_wr32_cmd(b, a, 0, N-1); /* silence compiler warning about uninitialized var (N > 0 at this point) */ v = 0; /* fill buffer */ for (nxt = a; N>0; N--) { #if (DEBUG > 4) printf("Writing DAT *0x%08"PRIx32" = 0x%08"PRIx32"\n", nxt, *(uint32_t*)s); #endif /* deal with misaligned sources */ for ( j=0; j<FLASH_STRIDE(b); j++ ) { buf.c[j] = *s++; } v = fl_x32(b, &buf); fl_wr32(b, nxt, v); nxt += FLASH_STRIDE(b); } /* burn buffer */ fl_wr32_cmd(b, a, 0, PGBUF_DATA); /* pend */ sta = flash_pend(b, nxt - FLASH_STRIDE(b), WRITE_TIMEOUT, v); return sta; }
STATIC uint32_t flash_write_line_intel(struct bankdesc *b, uint32_t a, char *s, uint32_t N) { uint32_t sta, Nspla, nxt, j; union { uint32_t u; char c[sizeof(uint32_t)]; } buf; /* address block */ if ( STA_RDYRDY != (sta = BSP_flashReadRaw(F_CMD_WR_BUF, a)) ) { return sta; } /* count per device */ N /= FLASH_STRIDE(b); /* splat out */ Nspla = (N<<8) | N; Nspla = (Nspla<<16) | Nspla; BSP_flashWriteRaw(Nspla - 0x01010101, a); /* fill buffer */ for (nxt = a; N>0; N--) { #if defined(TESTING) || (DEBUG > 4) printf("Writing DAT *0x%08"PRIx32" = 0x%08"PRIx32"\n", nxt, *(uint32_t*)s); #endif /* deal with misaligned sources */ for ( j=0; j<sizeof(buf.u); j++ ) { buf.c[j] = *s++; } *(A32)nxt = buf.u; nxt += FLASH_STRIDE(b); } BSP_flashReadRaw(F_CMD_WR_CMD, a); sta = flash_pend(b, a, TIMEOUT_US); return sta; }