flash/nor: improved API of flash_driver.info & fixed buffer overruns
[openocd.git] / src / flash / nor / efm32.c
index 6f290076241da781741f0eb39fb2c44fa02d275b..6461e4c7257521494ba7e9b2fa9c12c5d40959e1 100644 (file)
@@ -324,23 +324,7 @@ static int efm32x_read_info(struct flash_bank *bank,
        return ERROR_OK;
 }
 
-/*
- * Helper to create a human friendly string describing a part
- */
-static int efm32x_decode_info(struct efm32_info *info, char *buf, int buf_size)
-{
-       int printed = 0;
-       printed = snprintf(buf, buf_size, "%s Gecko, rev %d",
-                       info->family_data->name, info->prod_rev);
-
-       if (printed >= buf_size)
-               return ERROR_BUF_TOO_SMALL;
-
-       return ERROR_OK;
-}
-
-/* flash bank efm32 <base> <size> 0 0 <target#>
- */
+/* flash bank efm32 <base> <size> 0 0 <target#> */
 FLASH_BANK_COMMAND_HANDLER(efm32x_flash_bank_command)
 {
        struct efm32x_flash_bank *efm32x_info;
@@ -961,7 +945,6 @@ static int efm32x_probe(struct flash_bank *bank)
        struct efm32_info efm32_mcu_info;
        int ret;
        uint32_t base_address = 0x00000000;
-       char buf[256];
 
        efm32x_info->probed = false;
        memset(efm32x_info->lb_page, 0xff, LOCKBITS_PAGE_SZ);
@@ -970,11 +953,8 @@ static int efm32x_probe(struct flash_bank *bank)
        if (ERROR_OK != ret)
                return ret;
 
-       ret = efm32x_decode_info(&efm32_mcu_info, buf, sizeof(buf));
-       if (ERROR_OK != ret)
-               return ret;
-
-       LOG_INFO("detected part: %s", buf);
+       LOG_INFO("detected part: %s Gecko, rev %d",
+                       efm32_mcu_info.family_data->name, efm32_mcu_info.prod_rev);
        LOG_INFO("flash size = %dkbytes", efm32_mcu_info.flash_sz_kib);
        LOG_INFO("flash page size = %dbytes", efm32_mcu_info.page_size);
 
@@ -1044,10 +1024,10 @@ static int efm32x_protect_check(struct flash_bank *bank)
        return ERROR_OK;
 }
 
-static int get_efm32x_info(struct flash_bank *bank, char *buf, int buf_size)
+static int get_efm32x_info(struct flash_bank *bank, struct command_invocation *cmd)
 {
        struct efm32_info info;
-       int ret = 0;
+       int ret;
 
        ret = efm32x_read_info(bank, &info);
        if (ERROR_OK != ret) {
@@ -1055,7 +1035,8 @@ static int get_efm32x_info(struct flash_bank *bank, char *buf, int buf_size)
                return ret;
        }
 
-       return efm32x_decode_info(&info, buf, buf_size);
+       command_print_sameline(cmd, "%s Gecko, rev %d", info.family_data->name, info.prod_rev);
+       return ERROR_OK;
 }
 
 COMMAND_HANDLER(efm32x_handle_debuglock_command)

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)