@@ -399,7 +399,48 @@ int ParseKipConfiguration(const char *json, KipHeader *kip_hdr) {
399399 }
400400 desc = (u32 )((page_address >> 12 ) & 0x00FFFFFFULL );
401401 kip_hdr -> Capabilities [cur_cap ++ ] = (u32 )((desc << 8 ) | (0x007F ));
402- } else if (!strcmp (type_str , "irq_pair" )) {
402+ } else if (!strcmp (type_str , "map_region" )) {
403+ if (cur_cap + 1 > 0x20 ) {
404+ fprintf (stderr , "Error: Too many capabilities!\n" );
405+ status = 0 ;
406+ goto PARSE_CAPS_END ;
407+ }
408+ if (!cJSON_IsArray (value )) {
409+ fprintf (stderr , "Map Region capability value must be array!\n" );
410+ status = 0 ;
411+ goto PARSE_CAPS_END ;
412+ }
413+ u8 regions [3 ] = {0 };
414+ int is_ro [3 ] = {0 };
415+ const cJSON * cur_region = NULL ;
416+ int index = 0 ;
417+ cJSON_ArrayForEach (cur_region , value ) {
418+ if (index >= 3 ) {
419+ fprintf (stderr , "Too many region descriptors!\n" );
420+ status = 0 ;
421+ goto PARSE_CAPS_END ;
422+ }
423+ if (!cJSON_IsObject (cur_region )) {
424+ fprintf (stderr , "Region descriptor value must be object!\n" );
425+ status = 0 ;
426+ goto PARSE_CAPS_END ;
427+ }
428+
429+ if (!cJSON_GetU8 (cur_region , "region_type" , & regions [index ]) ||
430+ !cJSON_GetBoolean (cur_region , "is_ro" , & is_ro [index ])) {
431+ status = 0 ;
432+ goto PARSE_CAPS_END ;
433+ }
434+
435+ index ++ ;
436+ }
437+
438+ u32 capability = 0x3FF ;
439+ for (int i = 0 ; i < 3 ; ++ i ) {
440+ capability |= ((regions [i ] & 0x3F ) | ((is_ro [i ] & 1 ) << 6 )) << (11 + 7 * i );
441+ }
442+ kip_hdr -> Capabilities [cur_cap ++ ] = capability ;
443+ } else if (!strcmp (type_str , "irq_pair" )) {
403444 if (cur_cap + 1 > 0x20 ) {
404445 fprintf (stderr , "Error: Too many capabilities!\n" );
405446 status = 0 ;
0 commit comments