flash/nor: use command_print() in command "flash banks"
[openocd.git] / src / flash / mflash.c
index ea1673f09d47282e7d4d5d7775df188c8491e251..acf1441b7e236928b015f0c261e90a89d89259a2 100644 (file)
@@ -12,9 +12,7 @@
  *   GNU General Public License for more details.                          *
  *                                                                         *
  *   You should have received a copy of the GNU General Public License     *
- *   along with this program; if not, write to the                         *
- *   Free Software Foundation, Inc.,                                       *
- *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.           *
+ *   along with this program.  If not, see <http://www.gnu.org/licenses/>. *
  ***************************************************************************/
 
 #ifdef HAVE_CONFIG_H
@@ -261,11 +259,11 @@ static int mg_dsk_wait(mg_io_type_wait wait_local, uint32_t time_var)
                                case mg_io_wait_rdy:
                                        if (status & mg_io_rbit_status_ready)
                                                return ERROR_OK;
-
+                                       /* fallthrough */
                                case mg_io_wait_drq:
                                        if (status & mg_io_rbit_status_data_req)
                                                return ERROR_OK;
-
+                                       /* fallthrough */
                                default:
                                        break;
                        }
@@ -425,7 +423,7 @@ COMMAND_HANDLER(mg_probe_cmd)
        ret = mg_mflash_probe();
 
        if (ret == ERROR_OK) {
-               command_print(CMD_CTX,
+               command_print(CMD,
                        "mflash (total %" PRIu32 " sectors) found at 0x%8.8" PRIx32 "",
                        mflash_bank->drv_info->tot_sects,
                        mflash_bank->base);
@@ -749,7 +747,7 @@ COMMAND_HANDLER(mg_write_cmd)
 {
        uint32_t address, cnt, res, i;
        uint8_t *buffer;
-       struct fileio fileio;
+       struct fileio *fileio;
        int ret;
 
        if (CMD_ARGC != 3)
@@ -761,15 +759,15 @@ COMMAND_HANDLER(mg_write_cmd)
        if (ret != ERROR_OK)
                return ret;
 
-       int filesize;
+       size_t filesize;
        buffer = malloc(MG_FILEIO_CHUNK);
        if (!buffer) {
-               fileio_close(&fileio);
+               fileio_close(fileio);
                return ERROR_FAIL;
        }
-       int retval = fileio_size(&fileio, &filesize);
+       int retval = fileio_size(fileio, &filesize);
        if (retval != ERROR_OK) {
-               fileio_close(&fileio);
+               fileio_close(fileio);
                free(buffer);
                return retval;
        }
@@ -782,7 +780,7 @@ COMMAND_HANDLER(mg_write_cmd)
 
        size_t buf_cnt;
        for (i = 0; i < cnt; i++) {
-               ret = fileio_read(&fileio, MG_FILEIO_CHUNK, buffer, &buf_cnt);
+               ret = fileio_read(fileio, MG_FILEIO_CHUNK, buffer, &buf_cnt);
                if (ret != ERROR_OK)
                        goto mg_write_cmd_err;
                ret = mg_mflash_write(address, buffer, MG_FILEIO_CHUNK);
@@ -792,7 +790,7 @@ COMMAND_HANDLER(mg_write_cmd)
        }
 
        if (res) {
-               ret = fileio_read(&fileio, res, buffer, &buf_cnt);
+               ret = fileio_read(fileio, res, buffer, &buf_cnt);
                if (ret != ERROR_OK)
                        goto mg_write_cmd_err;
                ret = mg_mflash_write(address, buffer, res);
@@ -801,19 +799,19 @@ COMMAND_HANDLER(mg_write_cmd)
        }
 
        if (duration_measure(&bench) == ERROR_OK) {
-               command_print(CMD_CTX, "wrote %ld bytes from file %s "
-                       "in %fs (%0.3f kB/s)", (long)filesize, CMD_ARGV[1],
+               command_print(CMD, "wrote %zu bytes from file %s "
+                       "in %fs (%0.3f kB/s)", filesize, CMD_ARGV[1],
                        duration_elapsed(&bench), duration_kbps(&bench, filesize));
        }
 
        free(buffer);
-       fileio_close(&fileio);
+       fileio_close(fileio);
 
        return ERROR_OK;
 
 mg_write_cmd_err:
        free(buffer);
-       fileio_close(&fileio);
+       fileio_close(fileio);
 
        return ret;
 }
@@ -822,7 +820,7 @@ COMMAND_HANDLER(mg_dump_cmd)
 {
        uint32_t address, size, cnt, res, i;
        uint8_t *buffer;
-       struct fileio fileio;
+       struct fileio *fileio;
        int ret;
 
        if (CMD_ARGC != 4)
@@ -837,7 +835,7 @@ COMMAND_HANDLER(mg_dump_cmd)
 
        buffer = malloc(MG_FILEIO_CHUNK);
        if (!buffer) {
-               fileio_close(&fileio);
+               fileio_close(fileio);
                return ERROR_FAIL;
        }
 
@@ -852,7 +850,7 @@ COMMAND_HANDLER(mg_dump_cmd)
                ret = mg_mflash_read(address, buffer, MG_FILEIO_CHUNK);
                if (ret != ERROR_OK)
                        goto mg_dump_cmd_err;
-               ret = fileio_write(&fileio, MG_FILEIO_CHUNK, buffer, &size_written);
+               ret = fileio_write(fileio, MG_FILEIO_CHUNK, buffer, &size_written);
                if (ret != ERROR_OK)
                        goto mg_dump_cmd_err;
                address += MG_FILEIO_CHUNK;
@@ -862,26 +860,26 @@ COMMAND_HANDLER(mg_dump_cmd)
                ret = mg_mflash_read(address, buffer, res);
                if (ret != ERROR_OK)
                        goto mg_dump_cmd_err;
-               ret = fileio_write(&fileio, res, buffer, &size_written);
+               ret = fileio_write(fileio, res, buffer, &size_written);
                if (ret != ERROR_OK)
                        goto mg_dump_cmd_err;
        }
 
        if (duration_measure(&bench) == ERROR_OK) {
-               command_print(CMD_CTX, "dump image (address 0x%8.8" PRIx32 " "
+               command_print(CMD, "dump image (address 0x%8.8" PRIx32 " "
                        "size %" PRIu32 ") to file %s in %fs (%0.3f kB/s)",
                        address, size, CMD_ARGV[1],
                        duration_elapsed(&bench), duration_kbps(&bench, size));
        }
 
        free(buffer);
-       fileio_close(&fileio);
+       fileio_close(fileio);
 
        return ERROR_OK;
 
 mg_dump_cmd_err:
        free(buffer);
-       fileio_close(&fileio);
+       fileio_close(fileio);
 
        return ret;
 }
@@ -1329,6 +1327,7 @@ static const struct command_registration mflash_exec_command_handlers[] = {
                .handler = mg_probe_cmd,
                .mode = COMMAND_EXEC,
                .help = "Detect bank configuration information",
+               .usage = "",
        },
        {
                .name = "write",

Linking to existing account procedure

If you already have an account and want to add another login method you MUST first sign in with your existing account and then change URL to read https://review.openocd.org/login/?link to get to this page again but this time it'll work for linking. Thank you.

SSH host keys fingerprints

1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=..              |
|+o..   .         |
|*.o   . .        |
|+B . . .         |
|Bo. = o S        |
|Oo.+ + =         |
|oB=.* = . o      |
| =+=.+   + E     |
|. .=o   . o      |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)