/* * 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; /* Finally write data to flash */ for (info = info_first; info <= info_last && cnt > 0; ++info) { ulong len = info->start[0] + info->size - addr; if (len > cnt) len = cnt; if ((i = write_buff(info, (uchar *)src, addr, len)) != 0) return i; cnt -= len; addr += len; src += len; } return ERR_OK; }
/*----------------------------------------------------------------------- * 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; __maybe_unused char *src_orig = src; __maybe_unused char *addr_orig = (char *)addr; __maybe_unused ulong cnt_orig = cnt; 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; if ((i = write_buff(info, (uchar *)src, addr, len)) != 0) { return (i); } cnt -= len; addr += len; src += len; } #if defined(CONFIG_FLASH_VERIFY) if (memcmp(src_orig, addr_orig, cnt_orig)) { printf("\nVerify failed!\n"); return ERR_PROG_ERROR; } #endif /* CONFIG_SYS_FLASH_VERIFY_AFTER_WRITE */ return (ERR_OK); }
/*----------------------------------------------------------------------- * 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) { #ifdef CONFIG_SPD823TS return (ERR_TIMOUT); /* any other error codes are possible as well */ #else 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; int j; 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); } } } printf("\rWriting "); for (j=0; j<20; j++) putc(177); printf("\rWriting "); /* 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; if ((i = write_buff(info, src, addr, len)) != 0) { return (i); } cnt -= len; addr += len; src += len; } return (ERR_OK); #endif /* CONFIG_SPD823TS */ }
int kn_msgque_write(kn_msgque_writer_t writer,void *_msg,void (*fn_destroy)(void*)) { errno = 0; if(!_msg){ errno = INVAILD_MSG; return -1; } struct msg *msg = calloc(1,sizeof(*msg)); msg->fn_destroy = fn_destroy; msg->data = _msg; int ret; if(writer->buffsize) ret = write_buff(writer,msg); else ret = write_nobuff(writer->msgque,msg); return ret; }
static int cfi_mtd_write(struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen, const u_char *buf) { flash_info_t *fi = mtd->priv; u_long t = fi->start[0] + to; int error; flash_set_verbose(0); error = write_buff(fi, (u_char*)buf, t, len); flash_set_verbose(1); if (!error) { *retlen = len; return 0; } return -EIO; }
/*----------------------------------------------------------------------- * 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; } if((i = write_buff(info, (uchar *)src, addr, len)) != 0){ return(i); } cnt -= len; addr += len; src += len; } return(ERR_OK); }