Skip to content

Commit 980dbbf

Browse files
SciresMfincs
authored andcommitted
npdmtool: add compatibility for 8.0.0+ memory region capabilities
1 parent 793b056 commit 980dbbf

2 files changed

Lines changed: 42 additions & 1 deletion

File tree

src/elf2kip.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ int ParseKipConfiguration(const char *json, KipHeader *kip_hdr) {
440440
capability |= ((regions[i] & 0x3F) | ((is_ro[i] & 1) << 6)) << (11 + 7 * i);
441441
}
442442
kip_hdr->Capabilities[cur_cap++] = capability;
443-
} else if (!strcmp(type_str, "irq_pair")) {
443+
} else if (!strcmp(type_str, "irq_pair")) {
444444
if (cur_cap + 1 > 0x20) {
445445
fprintf(stderr, "Error: Too many capabilities!\n");
446446
status = 0;

src/npdmtool.c

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -687,6 +687,47 @@ int CreateNpdm(const char *json, void **dst, u32 *dst_size) {
687687
}
688688
desc = (u32)((page_address >> 12) & 0x00FFFFFFULL);
689689
caps[cur_cap++] = (u32)((desc << 8) | (0x007F));
690+
} else if (!strcmp(type_str, "map_region")) {
691+
if (cur_cap + 1 > 0x20) {
692+
fprintf(stderr, "Error: Too many capabilities!\n");
693+
status = 0;
694+
goto NPDM_BUILD_END;
695+
}
696+
if (!cJSON_IsArray(value)) {
697+
fprintf(stderr, "Map Region capability value must be array!\n");
698+
status = 0;
699+
goto NPDM_BUILD_END;
700+
}
701+
u8 regions[3] = {0};
702+
int is_ro[3] = {0};
703+
const cJSON *cur_region = NULL;
704+
int index = 0;
705+
cJSON_ArrayForEach(cur_region, value) {
706+
if (index >= 3) {
707+
fprintf(stderr, "Too many region descriptors!\n");
708+
status = 0;
709+
goto NPDM_BUILD_END;
710+
}
711+
if (!cJSON_IsObject(cur_region)) {
712+
fprintf(stderr, "Region descriptor value must be object!\n");
713+
status = 0;
714+
goto NPDM_BUILD_END;
715+
}
716+
717+
if (!cJSON_GetU8(cur_region, "region_type", &regions[index]) ||
718+
!cJSON_GetBoolean(cur_region, "is_ro", &is_ro[index])) {
719+
status = 0;
720+
goto NPDM_BUILD_END;
721+
}
722+
723+
index++;
724+
}
725+
726+
u32 capability = 0x3FF;
727+
for (int i = 0; i < 3; ++i) {
728+
capability |= ((regions[i] & 0x3F) | ((is_ro[i] & 1) << 6)) << (11 + 7 * i);
729+
}
730+
caps[cur_cap++] = capability;
690731
} else if (!strcmp(type_str, "irq_pair")) {
691732
if (!cJSON_IsArray(value) || cJSON_GetArraySize(value) != 2) {
692733
fprintf(stderr, "Error: IRQ Pairs must have size 2 array value.\n");

0 commit comments

Comments
 (0)