JSON->NPDM: Write IRQs in the correct order

This commit is contained in:
roblabla 2018-09-27 00:59:50 +00:00 committed by yellows8
parent 34a304999c
commit 23b1993b42
2 changed files with 8 additions and 6 deletions

View File

@ -370,17 +370,18 @@ int ParseKipConfiguration(const char *json, KipHeader *kip_hdr) {
goto PARSE_CAPS_END; goto PARSE_CAPS_END;
} }
const cJSON *irq = NULL; const cJSON *irq = NULL;
int desc_idx = 0;
cJSON_ArrayForEach(irq, value) { cJSON_ArrayForEach(irq, value) {
desc <<= 10;
if (cJSON_IsNull(irq)) { if (cJSON_IsNull(irq)) {
desc |= 0x3FF; desc |= 0x3FF << desc_idx;
} else if (cJSON_IsNumber(irq)) { } else if (cJSON_IsNumber(irq)) {
desc |= ((u16)(irq->valueint)) & 0x3FF; desc |= (((u16)(irq->valueint)) & 0x3FF) << desc_idx;
} else { } else {
fprintf(stderr, "Failed to parse IRQ value.\n"); fprintf(stderr, "Failed to parse IRQ value.\n");
status = 0; status = 0;
goto PARSE_CAPS_END; goto PARSE_CAPS_END;
} }
desc_idx += 10;
} }
kip_hdr->Capabilities[cur_cap++] = (u32)((desc << 12) | (0x07FF)); kip_hdr->Capabilities[cur_cap++] = (u32)((desc << 12) | (0x07FF));
} else if (!strcmp(type_str, "application_type")) { } else if (!strcmp(type_str, "application_type")) {

View File

@ -518,17 +518,18 @@ int CreateNpdm(const char *json, void **dst, u32 *dst_size) {
goto NPDM_BUILD_END; goto NPDM_BUILD_END;
} }
const cJSON *irq = NULL; const cJSON *irq = NULL;
int desc_idx = 0;
cJSON_ArrayForEach(irq, value) { cJSON_ArrayForEach(irq, value) {
desc <<= 10;
if (cJSON_IsNull(irq)) { if (cJSON_IsNull(irq)) {
desc |= 0x3FF; desc |= 0x3FF << desc_idx;
} else if (cJSON_IsNumber(irq)) { } else if (cJSON_IsNumber(irq)) {
desc |= ((u16)(irq->valueint)) & 0x3FF; desc |= (((u16)(irq->valueint)) & 0x3FF) << desc_idx;
} else { } else {
fprintf(stderr, "Failed to parse IRQ value.\n"); fprintf(stderr, "Failed to parse IRQ value.\n");
status = 0; status = 0;
goto NPDM_BUILD_END; goto NPDM_BUILD_END;
} }
desc_idx += 10;
} }
caps[cur_cap++] = (u32)((desc << 12) | (0x07FF)); caps[cur_cap++] = (u32)((desc << 12) | (0x07FF));
} else if (!strcmp(type_str, "application_type")) { } else if (!strcmp(type_str, "application_type")) {