efm32: remove duplicate part name decoding.
The probe and info methods had duplicate sections decoding family names to generate a human friendly part name. Extract this to a common helper. Change-Id: I4c6309d83c601e154b7c14ad9c15c53854ee1e98 Signed-off-by: Karl Palsson <karlp@tweak.net.au> Reviewed-on: http://openocd.zylin.com/2932 Tested-by: jenkins Reviewed-by: Andreas Färber <afaerber@suse.de> Reviewed-by: Freddie Chopin <freddie.chopin@gmail.com>
This commit is contained in:
parent
3f48732700
commit
7a8915ff64
|
@ -228,6 +228,70 @@ static int efm32x_read_info(struct flash_bank *bank,
|
||||||
return ERROR_OK;
|
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;
|
||||||
|
|
||||||
|
switch (info->part_family) {
|
||||||
|
case EZR_FAMILY_ID_WONDER_GECKO:
|
||||||
|
case EZR_FAMILY_ID_LEOPARD_GECKO:
|
||||||
|
printed = snprintf(buf, buf_size, "EZR32 ");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
printed = snprintf(buf, buf_size, "EFM32 ");
|
||||||
|
}
|
||||||
|
|
||||||
|
buf += printed;
|
||||||
|
buf_size -= printed;
|
||||||
|
|
||||||
|
if (0 >= buf_size)
|
||||||
|
return ERROR_BUF_TOO_SMALL;
|
||||||
|
|
||||||
|
switch (info->part_family) {
|
||||||
|
case EFM_FAMILY_ID_GECKO:
|
||||||
|
printed = snprintf(buf, buf_size, "Gecko");
|
||||||
|
break;
|
||||||
|
case EFM_FAMILY_ID_GIANT_GECKO:
|
||||||
|
printed = snprintf(buf, buf_size, "Giant Gecko");
|
||||||
|
break;
|
||||||
|
case EFM_FAMILY_ID_TINY_GECKO:
|
||||||
|
printed = snprintf(buf, buf_size, "Tiny Gecko");
|
||||||
|
break;
|
||||||
|
case EFM_FAMILY_ID_LEOPARD_GECKO:
|
||||||
|
case EZR_FAMILY_ID_LEOPARD_GECKO:
|
||||||
|
printed = snprintf(buf, buf_size, "Leopard Gecko");
|
||||||
|
break;
|
||||||
|
case EFM_FAMILY_ID_WONDER_GECKO:
|
||||||
|
case EZR_FAMILY_ID_WONDER_GECKO:
|
||||||
|
printed = snprintf(buf, buf_size, "Wonder Gecko");
|
||||||
|
break;
|
||||||
|
case EFM_FAMILY_ID_ZERO_GECKO:
|
||||||
|
printed = snprintf(buf, buf_size, "Zero Gecko");
|
||||||
|
break;
|
||||||
|
case EFM_FAMILY_ID_HAPPY_GECKO:
|
||||||
|
printed = snprintf(buf, buf_size, "Happy Gecko");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
buf += printed;
|
||||||
|
buf_size -= printed;
|
||||||
|
|
||||||
|
if (0 >= buf_size)
|
||||||
|
return ERROR_BUF_TOO_SMALL;
|
||||||
|
|
||||||
|
printed = snprintf(buf, buf_size, " - Rev: %d", info->prod_rev);
|
||||||
|
buf += printed;
|
||||||
|
buf_size -= printed;
|
||||||
|
|
||||||
|
if (0 >= 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)
|
FLASH_BANK_COMMAND_HANDLER(efm32x_flash_bank_command)
|
||||||
|
@ -833,6 +897,7 @@ static int efm32x_probe(struct flash_bank *bank)
|
||||||
int ret;
|
int ret;
|
||||||
int i;
|
int i;
|
||||||
uint32_t base_address = 0x00000000;
|
uint32_t base_address = 0x00000000;
|
||||||
|
char buf[256];
|
||||||
|
|
||||||
efm32x_info->probed = 0;
|
efm32x_info->probed = 0;
|
||||||
memset(efm32x_info->lb_page, 0xff, LOCKBITS_PAGE_SZ);
|
memset(efm32x_info->lb_page, 0xff, LOCKBITS_PAGE_SZ);
|
||||||
|
@ -841,36 +906,11 @@ static int efm32x_probe(struct flash_bank *bank)
|
||||||
if (ERROR_OK != ret)
|
if (ERROR_OK != ret)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
switch (efm32_mcu_info.part_family) {
|
ret = efm32x_decode_info(&efm32_mcu_info, buf, sizeof(buf));
|
||||||
case EFM_FAMILY_ID_GECKO:
|
if (ERROR_OK != ret)
|
||||||
LOG_INFO("Gecko MCU detected");
|
return ret;
|
||||||
break;
|
|
||||||
case EFM_FAMILY_ID_GIANT_GECKO:
|
|
||||||
LOG_INFO("Giant Gecko MCU detected");
|
|
||||||
break;
|
|
||||||
case EFM_FAMILY_ID_TINY_GECKO:
|
|
||||||
LOG_INFO("Tiny Gecko MCU detected");
|
|
||||||
break;
|
|
||||||
case EFM_FAMILY_ID_LEOPARD_GECKO:
|
|
||||||
case EZR_FAMILY_ID_LEOPARD_GECKO:
|
|
||||||
LOG_INFO("Leopard Gecko MCU detected");
|
|
||||||
break;
|
|
||||||
case EFM_FAMILY_ID_WONDER_GECKO:
|
|
||||||
case EZR_FAMILY_ID_WONDER_GECKO:
|
|
||||||
LOG_INFO("Wonder Gecko MCU detected");
|
|
||||||
break;
|
|
||||||
case EFM_FAMILY_ID_ZERO_GECKO:
|
|
||||||
LOG_INFO("Zero Gecko MCU detected");
|
|
||||||
break;
|
|
||||||
case EFM_FAMILY_ID_HAPPY_GECKO:
|
|
||||||
LOG_INFO("Happy Gecko MCU detected");
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
LOG_ERROR("Unsupported MCU family %d",
|
|
||||||
efm32_mcu_info.part_family);
|
|
||||||
return ERROR_FAIL;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
LOG_INFO("detected part: %s", buf);
|
||||||
LOG_INFO("flash size = %dkbytes", efm32_mcu_info.flash_sz_kib);
|
LOG_INFO("flash size = %dkbytes", efm32_mcu_info.flash_sz_kib);
|
||||||
LOG_INFO("flash page size = %dbytes", efm32_mcu_info.page_size);
|
LOG_INFO("flash page size = %dbytes", efm32_mcu_info.page_size);
|
||||||
|
|
||||||
|
@ -947,7 +987,6 @@ static int get_efm32x_info(struct flash_bank *bank, char *buf, int buf_size)
|
||||||
{
|
{
|
||||||
struct efm32_info info;
|
struct efm32_info info;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
int printed = 0;
|
|
||||||
|
|
||||||
ret = efm32x_read_info(bank, &info);
|
ret = efm32x_read_info(bank, &info);
|
||||||
if (ERROR_OK != ret) {
|
if (ERROR_OK != ret) {
|
||||||
|
@ -955,61 +994,7 @@ static int get_efm32x_info(struct flash_bank *bank, char *buf, int buf_size)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (info.part_family) {
|
return efm32x_decode_info(&info, buf, buf_size);
|
||||||
case EZR_FAMILY_ID_WONDER_GECKO:
|
|
||||||
case EZR_FAMILY_ID_LEOPARD_GECKO:
|
|
||||||
printed = snprintf(buf, buf_size, "EZR32 ");
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
printed = snprintf(buf, buf_size, "EFM32 ");
|
|
||||||
}
|
|
||||||
|
|
||||||
buf += printed;
|
|
||||||
buf_size -= printed;
|
|
||||||
|
|
||||||
if (0 >= buf_size)
|
|
||||||
return ERROR_BUF_TOO_SMALL;
|
|
||||||
|
|
||||||
switch (info.part_family) {
|
|
||||||
case EFM_FAMILY_ID_GECKO:
|
|
||||||
printed = snprintf(buf, buf_size, "Gecko");
|
|
||||||
break;
|
|
||||||
case EFM_FAMILY_ID_GIANT_GECKO:
|
|
||||||
printed = snprintf(buf, buf_size, "Giant Gecko");
|
|
||||||
break;
|
|
||||||
case EFM_FAMILY_ID_TINY_GECKO:
|
|
||||||
printed = snprintf(buf, buf_size, "Tiny Gecko");
|
|
||||||
break;
|
|
||||||
case EFM_FAMILY_ID_LEOPARD_GECKO:
|
|
||||||
case EZR_FAMILY_ID_LEOPARD_GECKO:
|
|
||||||
printed = snprintf(buf, buf_size, "Leopard Gecko");
|
|
||||||
break;
|
|
||||||
case EFM_FAMILY_ID_WONDER_GECKO:
|
|
||||||
case EZR_FAMILY_ID_WONDER_GECKO:
|
|
||||||
printed = snprintf(buf, buf_size, "Wonder Gecko");
|
|
||||||
break;
|
|
||||||
case EFM_FAMILY_ID_ZERO_GECKO:
|
|
||||||
printed = snprintf(buf, buf_size, "Zero Gecko");
|
|
||||||
break;
|
|
||||||
case EFM_FAMILY_ID_HAPPY_GECKO:
|
|
||||||
printed = snprintf(buf, buf_size, "Happy Gecko");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
buf += printed;
|
|
||||||
buf_size -= printed;
|
|
||||||
|
|
||||||
if (0 >= buf_size)
|
|
||||||
return ERROR_BUF_TOO_SMALL;
|
|
||||||
|
|
||||||
printed = snprintf(buf, buf_size, " - Rev: %d", info.prod_rev);
|
|
||||||
buf += printed;
|
|
||||||
buf_size -= printed;
|
|
||||||
|
|
||||||
if (0 >= buf_size)
|
|
||||||
return ERROR_BUF_TOO_SMALL;
|
|
||||||
|
|
||||||
return ERROR_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static const struct command_registration efm32x_exec_command_handlers[] = {
|
static const struct command_registration efm32x_exec_command_handlers[] = {
|
||||||
|
|
Loading…
Reference in New Issue