Skip to content

Commit 23b1993

Browse files
roblablayellows8
authored andcommitted
JSON->NPDM: Write IRQs in the correct order
1 parent 34a3049 commit 23b1993

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

src/elf2kip.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -370,17 +370,18 @@ int ParseKipConfiguration(const char *json, KipHeader *kip_hdr) {
370370
goto PARSE_CAPS_END;
371371
}
372372
const cJSON *irq = NULL;
373+
int desc_idx = 0;
373374
cJSON_ArrayForEach(irq, value) {
374-
desc <<= 10;
375375
if (cJSON_IsNull(irq)) {
376-
desc |= 0x3FF;
376+
desc |= 0x3FF << desc_idx;
377377
} else if (cJSON_IsNumber(irq)) {
378-
desc |= ((u16)(irq->valueint)) & 0x3FF;
378+
desc |= (((u16)(irq->valueint)) & 0x3FF) << desc_idx;
379379
} else {
380380
fprintf(stderr, "Failed to parse IRQ value.\n");
381381
status = 0;
382382
goto PARSE_CAPS_END;
383383
}
384+
desc_idx += 10;
384385
}
385386
kip_hdr->Capabilities[cur_cap++] = (u32)((desc << 12) | (0x07FF));
386387
} else if (!strcmp(type_str, "application_type")) {

src/npdmtool.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -518,17 +518,18 @@ int CreateNpdm(const char *json, void **dst, u32 *dst_size) {
518518
goto NPDM_BUILD_END;
519519
}
520520
const cJSON *irq = NULL;
521+
int desc_idx = 0;
521522
cJSON_ArrayForEach(irq, value) {
522-
desc <<= 10;
523523
if (cJSON_IsNull(irq)) {
524-
desc |= 0x3FF;
524+
desc |= 0x3FF << desc_idx;
525525
} else if (cJSON_IsNumber(irq)) {
526-
desc |= ((u16)(irq->valueint)) & 0x3FF;
526+
desc |= (((u16)(irq->valueint)) & 0x3FF) << desc_idx;
527527
} else {
528528
fprintf(stderr, "Failed to parse IRQ value.\n");
529529
status = 0;
530530
goto NPDM_BUILD_END;
531531
}
532+
desc_idx += 10;
532533
}
533534
caps[cur_cap++] = (u32)((desc << 12) | (0x07FF));
534535
} else if (!strcmp(type_str, "application_type")) {

0 commit comments

Comments
 (0)