ShubhamTaple opened a new pull request, #22138:
URL: https://github.com/apache/nuttx/pull/22138

   ## Summary
   
   The separate-PSRAM-heap path was broken in three ways:
   
   1. `up_extraheaps_init()` still used the removed `config.heap` field 
(`config.heap = KRN_HEAP`). `struct mm_heap_config_s` now exposes `allocheap` 
instead. Set `config.allocheap = true` so the heap control block, and therefore 
its mutex, is allocated from the kernel heap in SRAM. Placing the lock in PSRAM 
is unsafe because atomic operations do not exclude the other core there.
   
   2. `up_allocate_kheap()` and `up_allocate_heap()` unconditionally used 
`g_idle_topstack` / `PSRAM_START` without checking whether PSRAM was actually 
fitted. On boards without PSRAM this yielded a zero-sized user heap and a 
kernel heap that ran into the user region. Detect the PSRAM size and fall back 
to splitting internal SRAM between the kernel heap 
(`CONFIG_MM_KERNEL_HEAPSIZE`) and the user heap. The protected build uses 
`USERSPACE->us_bssend` as the base of the split.
   
   3. `g_psramheap` was file-static, so nothing outside `rp23xx_heaps.c` could 
refer to the PSRAM heap. Drop `static` and declare it `extern` in a new 
`rp23xx_heaps.h` header.
   
   Also add the missing `<nuttx/userspace.h>` include needed by the 
`CONFIG_BUILD_PROTECTED` paths, and assert that the computed heap range is 
non-empty.
   
   ## Impact
   
   - **Users:** Boards without fitted PSRAM now get a usable user heap instead 
of a zero-sized heap. Boards with PSRAM retain their existing heap layout.
   - **Build process:** No Kconfig changes. Fixes compatibility with the 
current `mm_heap_config_s` and adds the internal `rp23xx_heaps.h` header.
   - **Hardware:** No register programming or PSRAM initialization changes; 
only heap range calculation is affected.
   - **Security:** No new attack surface. Corrects heap boundaries and adds 
assertions to validate the computed ranges in protected builds.
   - **Compatibility:** No API or ABI breakage. `g_psramheap` was previously 
file-static, and the removed `config.heap` field is already absent upstream.
   
   
   ## Testing
   
   **Host**: Linux x86_64, arm-none-eabi-gcc (15:13.2.rel1-2) 13.2.1 20231009
   
   **Target**: `raspberrypi-pico-2:nsh` (ARM Cortex-M33, RP2350) — 
**build-only**, no hardware run.
   
   **Verified**: the configuration builds cleanly before and after the patch:
   
   ```bash
   make distclean
   ./tools/configure.sh raspberrypi-pico-2:nsh
   make menuconfig   # CONFIG_RP23XX_PSRAM, CONFIG_RP23XX_PSRAM_HEAP_SEPARATE,
                     # CONFIG_ARCH_HAVE_EXTRA_HEAPS, CONFIG_MM_KERNEL_HEAP 
enabled
   make -j$(nproc)
   ```
   
   ```text
   LD: nuttx
   Memory region         Used Size  Region Size  %age Used
              FLASH:      171800 B         4 MB      4.10%
                RAM:       13184 B       512 KB      2.51%
          SCRATCH_X:           0 B         4 KB      0.00%
          SCRATCH_Y:           0 B         4 KB      0.00%
   Generating: nuttx.uf2
   Done.
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to