+ for (i = 0; i < cnt; i++) {
+ if ((ret = fileio_read(&fileio, MG_FILEIO_CHUNK, buffer, &buf_cnt)) !=
+ ERROR_OK)
+ goto mg_write_cmd_err;
+ if ((ret = mg_mflash_write(address, buffer, MG_FILEIO_CHUNK)) != ERROR_OK)
+ goto mg_write_cmd_err;
+ address += MG_FILEIO_CHUNK;
+ }
+
+ if (res) {
+ if ((ret = fileio_read(&fileio, res, buffer, &buf_cnt)) != ERROR_OK)
+ goto mg_write_cmd_err;
+ if ((ret = mg_mflash_write(address, buffer, res)) != ERROR_OK)
+ goto mg_write_cmd_err;
+ }