@@ -105,6 +105,8 @@ extern const uint8_t __mpfs_nuttx_start[];
105
105
extern const uint8_t __mpfs_nuttx_end [];
106
106
extern const uint8_t _ssbi_zerodev [];
107
107
extern const uint8_t _esbi_zerodev [];
108
+ extern const uint8_t _sbi_heap_start [];
109
+ extern const uint8_t _sbi_heap_size [];
108
110
109
111
/****************************************************************************
110
112
* Private Function Prototypes
@@ -470,27 +472,41 @@ static void mpfs_opensbi_scratch_setup(uint32_t hartid)
470
472
(unsigned long )mpfs_hart_to_scratch ;
471
473
g_scratches [hartid ].scratch .platform_addr = (unsigned long )& platform ;
472
474
473
- /* Our FW area in l2lim section. OpenSBI needs to be aware of it in order
474
- * to protect the area. However, we set the PMP values already and lock
475
- * them so that OpenSBI has no chance override then.
475
+ /* Our FW area, heap and the scratch area are in l2lim.
476
+ *
477
+ * The memory is organized as follows:
478
+ *
479
+ * ----------------------------------------------------------------------
480
+ * | | | |
481
+ * | SBI .text (0000h) | SBI heap (8000h) | SBI scratch (8000h + 4000h) |
482
+ * | | | |
483
+ * ----------------------------------------------------------------------
484
+ *
485
+ * The reason for this organization is that the RX and RW areas can be set
486
+ * to the physical memory protection unit (PMP) as two contiguous areas.
476
487
*/
477
488
478
489
g_scratches [hartid ].scratch .fw_start = (unsigned long )_ssbi_zerodev ;
479
490
g_scratches [hartid ].scratch .fw_size = (unsigned long )_esbi_zerodev -
480
491
(unsigned long )_ssbi_zerodev ;
481
492
482
- g_scratches [hartid ].scratch .fw_rw_offset =
483
- (unsigned long )g_scratches [hartid ].scratch .fw_size ;
493
+ /* RW area starts from the heap */
484
494
485
- /* fw_rw_offset needs to be an aligned address */
495
+ g_scratches [hartid ].scratch .fw_heap_offset =
496
+ (unsigned long )_sbi_heap_start -
497
+ (unsigned long )g_scratches [hartid ].scratch .fw_start ;
486
498
487
- g_scratches [hartid ].scratch .fw_rw_offset += 1024 * 2 ;
488
- g_scratches [hartid ].scratch .fw_rw_offset &= 0xffffff800 ;
489
- g_scratches [hartid ].scratch .fw_size =
490
- g_scratches [hartid ].scratch .fw_rw_offset ;
499
+ g_scratches [hartid ].scratch .fw_heap_size =
500
+ (unsigned long )_sbi_heap_size ;
491
501
492
- g_scratches [hartid ].scratch .fw_heap_offset =
493
- (unsigned long )g_scratches [hartid ].scratch .fw_size ;
502
+ g_scratches [hartid ].scratch .fw_rw_offset =
503
+ g_scratches [hartid ].scratch .fw_heap_offset ;
504
+
505
+ /* Because sbi_heap_init does not work otherwise */
506
+
507
+ g_scratches [hartid ].scratch .fw_size =
508
+ g_scratches [hartid ].scratch .fw_heap_offset +
509
+ g_scratches [hartid ].scratch .fw_heap_size ;
494
510
495
511
/* Heap minimum is 16k. Otherwise sbi_heap.c fails:
496
512
* hpctrl.hksize = hpctrl.size / HEAP_HOUSEKEEPING_FACTOR;
@@ -500,10 +516,17 @@ static void mpfs_opensbi_scratch_setup(uint32_t hartid)
500
516
* hpctrl.hksize gets to be zero making the OpenSBI crash.
501
517
*/
502
518
503
- g_scratches [hartid ].scratch .fw_heap_size = 1024 * 16 ;
504
- g_scratches [hartid ].scratch .fw_size =
505
- g_scratches [hartid ].scratch .fw_heap_offset +
506
- g_scratches [hartid ].scratch .fw_heap_size ;
519
+ if (g_scratches [hartid ].scratch .fw_heap_size < 0x4000 )
520
+ {
521
+ sbi_panic (__func__ );
522
+ }
523
+
524
+ /* fw_rw_offset needs to be an aligned address */
525
+
526
+ if (g_scratches [hartid ].scratch .fw_rw_offset & 0x7FF )
527
+ {
528
+ sbi_panic (__func__ );
529
+ }
507
530
}
508
531
509
532
/****************************************************************************
0 commit comments