target/cortex_m: check core implementor field
Presently, we only look at the Part Number field of the CPUID, and completely ignore the Implmentor field, simply assuming it to be ARM. Parts have since been found, with different implementors, that use overlapping part numbers, causing detection to fail. Expand the "part number" field to be a full implementor+part number, excluding the revision/patch fields, to make checking more reliable. Change-Id: Id81774f829104f57a0c105320d0d2e479fa01522 Signed-off-by: Karl Palsson <karlp@tweak.au> Reviewed-on: https://review.openocd.org/c/openocd/+/7845 Tested-by: jenkins Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
This commit is contained in:
committed by
Antonio Borneo
parent
a4b4750e38
commit
05ee889155
@@ -50,63 +50,63 @@
|
||||
/* Supported Cortex-M Cores */
|
||||
static const struct cortex_m_part_info cortex_m_parts[] = {
|
||||
{
|
||||
.partno = CORTEX_M0_PARTNO,
|
||||
.impl_part = CORTEX_M0_PARTNO,
|
||||
.name = "Cortex-M0",
|
||||
.arch = ARM_ARCH_V6M,
|
||||
},
|
||||
{
|
||||
.partno = CORTEX_M0P_PARTNO,
|
||||
.impl_part = CORTEX_M0P_PARTNO,
|
||||
.name = "Cortex-M0+",
|
||||
.arch = ARM_ARCH_V6M,
|
||||
},
|
||||
{
|
||||
.partno = CORTEX_M1_PARTNO,
|
||||
.impl_part = CORTEX_M1_PARTNO,
|
||||
.name = "Cortex-M1",
|
||||
.arch = ARM_ARCH_V6M,
|
||||
},
|
||||
{
|
||||
.partno = CORTEX_M3_PARTNO,
|
||||
.impl_part = CORTEX_M3_PARTNO,
|
||||
.name = "Cortex-M3",
|
||||
.arch = ARM_ARCH_V7M,
|
||||
.flags = CORTEX_M_F_TAR_AUTOINCR_BLOCK_4K,
|
||||
},
|
||||
{
|
||||
.partno = CORTEX_M4_PARTNO,
|
||||
.impl_part = CORTEX_M4_PARTNO,
|
||||
.name = "Cortex-M4",
|
||||
.arch = ARM_ARCH_V7M,
|
||||
.flags = CORTEX_M_F_HAS_FPV4 | CORTEX_M_F_TAR_AUTOINCR_BLOCK_4K,
|
||||
},
|
||||
{
|
||||
.partno = CORTEX_M7_PARTNO,
|
||||
.impl_part = CORTEX_M7_PARTNO,
|
||||
.name = "Cortex-M7",
|
||||
.arch = ARM_ARCH_V7M,
|
||||
.flags = CORTEX_M_F_HAS_FPV5,
|
||||
},
|
||||
{
|
||||
.partno = CORTEX_M23_PARTNO,
|
||||
.impl_part = CORTEX_M23_PARTNO,
|
||||
.name = "Cortex-M23",
|
||||
.arch = ARM_ARCH_V8M,
|
||||
},
|
||||
{
|
||||
.partno = CORTEX_M33_PARTNO,
|
||||
.impl_part = CORTEX_M33_PARTNO,
|
||||
.name = "Cortex-M33",
|
||||
.arch = ARM_ARCH_V8M,
|
||||
.flags = CORTEX_M_F_HAS_FPV5,
|
||||
},
|
||||
{
|
||||
.partno = CORTEX_M35P_PARTNO,
|
||||
.impl_part = CORTEX_M35P_PARTNO,
|
||||
.name = "Cortex-M35P",
|
||||
.arch = ARM_ARCH_V8M,
|
||||
.flags = CORTEX_M_F_HAS_FPV5,
|
||||
},
|
||||
{
|
||||
.partno = CORTEX_M55_PARTNO,
|
||||
.impl_part = CORTEX_M55_PARTNO,
|
||||
.name = "Cortex-M55",
|
||||
.arch = ARM_ARCH_V8M,
|
||||
.flags = CORTEX_M_F_HAS_FPV5,
|
||||
},
|
||||
{
|
||||
.partno = STAR_MC1_PARTNO,
|
||||
.impl_part = STAR_MC1_PARTNO,
|
||||
.name = "STAR-MC1",
|
||||
.arch = ARM_ARCH_V8M,
|
||||
.flags = CORTEX_M_F_HAS_FPV5,
|
||||
@@ -2526,18 +2526,18 @@ int cortex_m_examine(struct target *target)
|
||||
if (retval != ERROR_OK)
|
||||
return retval;
|
||||
|
||||
/* Get ARCH and CPU types */
|
||||
const enum cortex_m_partno core_partno = (cpuid & ARM_CPUID_PARTNO_MASK) >> ARM_CPUID_PARTNO_POS;
|
||||
/* Inspect implementor/part to look for recognized cores */
|
||||
unsigned int impl_part = cpuid & (ARM_CPUID_IMPLEMENTOR_MASK | ARM_CPUID_PARTNO_MASK);
|
||||
|
||||
for (unsigned int n = 0; n < ARRAY_SIZE(cortex_m_parts); n++) {
|
||||
if (core_partno == cortex_m_parts[n].partno) {
|
||||
if (impl_part == cortex_m_parts[n].impl_part) {
|
||||
cortex_m->core_info = &cortex_m_parts[n];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!cortex_m->core_info) {
|
||||
LOG_TARGET_ERROR(target, "Cortex-M PARTNO 0x%x is unrecognized", core_partno);
|
||||
LOG_TARGET_ERROR(target, "Cortex-M CPUID: 0x%x is unrecognized", cpuid);
|
||||
return ERROR_FAIL;
|
||||
}
|
||||
|
||||
@@ -2549,7 +2549,7 @@ int cortex_m_examine(struct target *target)
|
||||
(uint8_t)((cpuid >> 0) & 0xf));
|
||||
|
||||
cortex_m->maskints_erratum = false;
|
||||
if (core_partno == CORTEX_M7_PARTNO) {
|
||||
if (impl_part == CORTEX_M7_PARTNO) {
|
||||
uint8_t rev, patch;
|
||||
rev = (cpuid >> 20) & 0xf;
|
||||
patch = (cpuid >> 0) & 0xf;
|
||||
|
||||
Reference in New Issue
Block a user