Skip to content

Commit 75fb578

Browse files
committed
img4: Use lookup table to retrieve tag name in img4_stitch_component()
Instead of maintaining another component -> tag mapping, we use the already existing function _img4_get_component_tag() to retrieve the corresponding tag name.
1 parent d2cf14f commit 75fb578

File tree

1 file changed

+37
-28
lines changed

1 file changed

+37
-28
lines changed

src/img4.c

Lines changed: 37 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,7 @@ static const char *_img4_get_component_tag(const char *compname)
291291
{ "Ap,AudioPowerAttachChime", "aupr" },
292292
{ "Ap,BootabilityBrainTrustCache", "trbb" },
293293
{ "Ap,CIO", "ciof" },
294+
{ "Ap,DCP2", "dcp2" },
294295
{ "Ap,HapticAssets", "hpas" },
295296
{ "Ap,LocalBoot", "lobo" },
296297
{ "Ap,LocalPolicy", "lpol" },
@@ -303,6 +304,10 @@ static const char *_img4_get_component_tag(const char *compname)
303304
{ "Ap,RestoreDCP2", "rdc2", },
304305
{ "Ap,RestoreTMU", "rtmu" },
305306
{ "Ap,Scorpius", "scpf" },
307+
{ "Ap,RestoreSecureM3Firmware", "rsm3" },
308+
{ "Ap,RestoreSecurePageTableMonitor", "rspt" },
309+
{ "Ap,RestoreTrustedExecutionMonitor", "rtrx" },
310+
{ "Ap,RestorecL4", "rxcl" },
306311
{ "Ap,SystemVolumeCanonicalMetadata", "msys" },
307312
{ "Ap,TMU", "tmuf" },
308313
{ "Ap,VolumeUUID", "vuid" },
@@ -425,35 +430,39 @@ int img4_stitch_component(const char* component_name, const void* component_data
425430
const void *tag = asn1_find_element(1, ASN1_IA5_STRING, component_data);
426431
if (tag) {
427432
logger(LL_DEBUG, "Tag found\n");
428-
if (strcmp(component_name, "RestoreKernelCache") == 0) {
429-
memcpy((void*)tag, "rkrn", 4);
430-
} else if (strcmp(component_name, "RestoreDeviceTree") == 0) {
431-
memcpy((void*)tag, "rdtr", 4);
432-
} else if (strcmp(component_name, "RestoreSEP") == 0) {
433-
memcpy((void*)tag, "rsep", 4);
434-
} else if (strcmp(component_name, "RestoreLogo") == 0) {
435-
memcpy((void*)tag, "rlgo", 4);
436-
} else if (strcmp(component_name, "RestoreTrustCache") == 0) {
437-
memcpy((void*)tag, "rtsc", 4);
438-
} else if (strcmp(component_name, "RestoreDCP") == 0) {
439-
memcpy((void*)tag, "rdcp", 4);
440-
} else if (strcmp(component_name, "Ap,RestoreTMU") == 0) {
441-
memcpy((void*)tag, "rtmu", 4);
442-
} else if (strcmp(component_name, "Ap,RestoreCIO") == 0) {
443-
memcpy((void*)tag, "rcio", 4);
444-
} else if (strcmp(component_name, "Ap,RestoreDCP2") == 0) {
445-
memcpy((void*)tag, "rdc2", 4);
446-
} else if (strcmp(component_name, "Ap,DCP2") == 0) {
447-
memcpy((void*)tag, "dcp2", 4);
448-
} else if (strcmp(component_name, "Ap,RestoreSecureM3Firmware") == 0) {
449-
memcpy((void*)tag, "rsm3", 4);
450-
} else if (strcmp(component_name, "Ap,RestoreSecurePageTableMonitor") == 0) {
451-
memcpy((void*)tag, "rspt", 4);
452-
} else if (strcmp(component_name, "Ap,RestoreTrustedExecutionMonitor") == 0) {
453-
memcpy((void*)tag, "rtrx", 4);
454-
} else if (strcmp(component_name, "Ap,RestorecL4") == 0) {
455-
memcpy((void*)tag, "rxcl", 4);
433+
const char* matches[] = {
434+
"RestoreKernelCache",
435+
"RestoreKernelCache",
436+
"RestoreSEP",
437+
"RestoreLogo",
438+
"RestoreTrustCache",
439+
"RestoreDCP",
440+
"Ap,RestoreDCP2",
441+
"Ap,RestoreTMU",
442+
"Ap,RestoreCIO",
443+
"Ap,DCP2",
444+
"Ap,RestoreSecureM3Firmware",
445+
"Ap,RestoreSecurePageTableMonitor",
446+
"Ap,RestoreTrustedExecutionMonitor",
447+
"Ap,RestorecL4",
448+
NULL
449+
};
450+
int i = 0;
451+
while (matches[i]) {
452+
if (!strcmp(matches[i], component_name)) {
453+
const char* comptag = _img4_get_component_tag(component_name);
454+
if (comptag) {
455+
memcpy((void*)tag, comptag, 4);
456+
} else {
457+
logger(LL_WARNING, "Cannot find tag for component '%s'\n", component_name);
458+
}
459+
break;
460+
}
461+
i++;
456462
}
463+
} else {
464+
logger(LL_ERROR, "Personalization failed for component '%s': Tag not found\n", component_name);
465+
return -1;
457466
}
458467

459468
// check if we have a *-TBM entry for the given component

0 commit comments

Comments
 (0)