>From nuttx/include/nuttx/mm/mm.h, MM_KERNEL_USRHEAP_INIT should always be >defined for CONFIG_BUILD_FLAT: /* Terminology: * * - Flat Build: In the flat build (CONFIG_BUILD_FLAT=y), there is only a * single heap access with the standard allocations (malloc/free). This * heap is referred to as the user heap. The kernel logic must * initialize this single heap at boot time. * - Protected build: In the protected build (CONFIG_BUILD_PROTECTED=y) * where an MPU is used to protect a region of otherwise flat memory, * there will be two allocators: One that allocates protected (kernel) * memory and one that allocates unprotected (user) memory. These are * referred to as the kernel and user heaps, respectively. Both must be * initialized by the kernel logic at boot time. * - Kernel Build: If the architecture has an MMU, then it may support the * kernel build (CONFIG_BUILD_KERNEL=y). In this configuration, there * is one kernel heap but multiple user heaps: One per task group. * However, in this case, the kernel need only be concerned about * initializing the single kernel heap here. User heaps will be created * as tasks are created. * * These special definitions are provided: * * MM_KERNEL_USRHEAP_INIT * Special kernel interfaces to the kernel user-heap are required * for heap initialization. * CONFIG_MM_KERNEL_HEAP * The configuration requires a kernel heap that must initialized * at boot-up. */
#undef MM_KERNEL_USRHEAP_INIT #if defined(CONFIG_BUILD_PROTECTED) && defined(__KERNEL__) # define MM_KERNEL_USRHEAP_INIT 1 #elif !defined(CONFIG_BUILD_KERNEL) # define MM_KERNEL_USRHEAP_INIT 1 #endif > -----Original Message----- > From: Laitinen, Jukka <jukka.laiti...@intel.com> > Sent: Monday, May 25, 2020 1:28 PM > To: dev@nuttx.apache.org > Subject: RE: Correct call sequence to initialize the heap in > CONFIG_BUILD_FLAT? > > So I was left without heap at boot, and crashing (also stacks of course, but > that was not what I meant to say). > > > > Hi, > > Right now, looking at the file nx_start.c, all calls to up_allocate_heap are > being done when one of these flags are defined: > #if defined(MM_KERNEL_USRHEAP_INIT) || defined(CONFIG_MM_KERNEL_HEAP) || \ > defined(CONFIG_MM_PGALLOC) > > I was just left without stack when re-basing to the latest master, using > CONFIG_BUILD_FLAT. I wonder what is the proper way to call > up_allocate_heap in this case? > > I initially made this in include/nuttx/mm/mm.h: > -#if !defined(CONFIG_BUILD_KERNEL) && defined(__KERNEL__) > +#if (!defined(CONFIG_BUILD_KERNEL) && defined(__KERNEL__)) || > defined(CONFIG_BUILD_FLAT) > # define MM_KERNEL_USRHEAP_INIT 1 > #endif > > This gives me the proper heap initialization from nx_start.c, but I wonder if > this is the right way to do? I have probably missed > something here... > > Thanks, > Jukka