Fix zone allocator init on 1GB Pi 4

It was mistakenly assumed there would be a high heap available on the
1GB Raspberry Pi 4, which caused a boot failure on this model.

Check that there is a high heap available before attempting to allocate
from it, and fall back on the low heap if not.
This commit is contained in:
Dale Whinham committed 2021-05-04 20:20:06 +01:00
1 parent 0de1309b02
commit 5065f0c500
2 files changed
+19 -8

No files matched your search

+1
View File
@@ -34,6 +34,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- USB plug/unplug events now bring mt32-pi out of power saving mode.
- Some USB MIDI devices that violate the USB specification were unusable (discussion #102) - a workaround in the USB driver has been implemented. Thanks to @fabbrimichele for reporting and @rsta2 for the fix!
- Hang on "Init USB" when no USB controller is present (e.g. a Compute Module 4-based system with no external XHCI controller). Huge thanks to Serdaco for donating the CM4 and I/O board for testing!
- Boot failure on the 1GB Raspberry Pi 4/CM4 because of a bug in the memory allocator.
## [0.9.1] - 2021-03-20
+18 -8
View File
@@ -27,6 +27,8 @@
#include "utility.h"
#include "zoneallocator.h"
constexpr size_t MallocHeapSize = 32 * MEGABYTE;
const char ZoneAllocatorName[] = "zoneallocator";
// #define ZONE_ALLOCATOR_DEBUG
@@ -55,14 +57,22 @@ bool CZoneAllocator::Initialize()
CMemorySystem* pMemorySystem = CMemorySystem::Get();
CLogger* pLogger = CLogger::Get();
#if RASPPI >= 4
// Allocate all of the remaining HIGH region
m_nHeapSize = pMemorySystem->GetHeapFreeSpace(HEAP_HIGH) - sizeof(THeapBlockHeader);
m_pHeap = pMemorySystem->HeapAllocate(m_nHeapSize, HEAP_HIGH);
#else
// Allocate the majority of the remaining LOW region
m_nHeapSize = pMemorySystem->GetHeapFreeSpace(HEAP_LOW) - 32 * MEGABYTE;
m_pHeap = pMemorySystem->HeapAllocate(m_nHeapSize, HEAP_LOW);
#if RASPI >= 4
const size_t nHighHeapSize = pMemorySystem->GetHeapFreeSpace(HEAP_HIGH);
if (nHighHeapSize)
{
// >1GB RAM Pi 4 - allocate all of the remaining HIGH region
m_nHeapSize = nHighHeapSize - sizeof(THeapBlockHeader);
m_pHeap = pMemorySystem->HeapAllocate(m_nHeapSize, HEAP_HIGH);
}
else
{
#endif
// Allocate the majority of the remaining LOW region; leave some space for Circle/libc malloc()
m_nHeapSize = pMemorySystem->GetHeapFreeSpace(HEAP_LOW) - MallocHeapSize;
m_pHeap = pMemorySystem->HeapAllocate(m_nHeapSize, HEAP_LOW);
#if RASPI >= 4
}
#endif
if (!m_pHeap)