We could only conditionally do this, if we know we are going to need to add nodes. But it's easier to just do this unconditionally.
Signed-off-by: Rob Clark robdclark@gmail.com --- .../Application/ConfigTableLoader/DtbLoader.c | 38 +++++++++++++++++++ .../ConfigTableLoader/DtbLoader.inf | 1 + 2 files changed, 39 insertions(+)
diff --git a/EmbeddedPkg/Application/ConfigTableLoader/DtbLoader.c b/EmbeddedPkg/Application/ConfigTableLoader/DtbLoader.c index c32c4a8dd3..2d32cc5b64 100644 --- a/EmbeddedPkg/Application/ConfigTableLoader/DtbLoader.c +++ b/EmbeddedPkg/Application/ConfigTableLoader/DtbLoader.c @@ -162,6 +162,43 @@ ReadSmbiosInfo (VOID) return EFI_SUCCESS; }
+#define FDT_ADDITIONAL_SIZE 0x400 + +/* Increase the size of the FDT blob so that we can patch in new nodes */ +STATIC +EFI_STATUS +ResizeBlob ( + IN OUT VOID **Blob + ) +{ + VOID *NewBlob; + UINTN NewSize; + INTN Err; + + NewSize = fdt_totalsize (*Blob) + FDT_ADDITIONAL_SIZE; + NewBlob = AllocatePool (NewSize); + if (!NewBlob) { + Print (L"%a:%d: allocation failed\n", __func__, __LINE__); + return EFI_OUT_OF_RESOURCES; + } + + Err = fdt_open_into (*Blob, NewBlob, NewSize); + if (Err) { + Print (L"Could not expand fdt: %a\n", fdt_strerror (Err)); + FreePool (NewBlob); + return EFI_OUT_OF_RESOURCES; + } + + /* Successfully Resized: */ + mBlobInfo.FileSize += FDT_ADDITIONAL_SIZE; + mBlobInfo.Data = NewBlob; + + FreePool (*Blob); + *Blob = NewBlob; + + return EFI_SUCCESS; +} + STATIC EFI_STATUS ReadBlob ( @@ -452,6 +489,7 @@ LoadAndRegisterDtb (VOID) if (!EFI_ERROR (Status)) { EFI_EVENT ExitBootServicesEvent;
+ ResizeBlob (&Blob); RegisterDtBlob (Blob);
Status = gBS->CreateEvent ( diff --git a/EmbeddedPkg/Application/ConfigTableLoader/DtbLoader.inf b/EmbeddedPkg/Application/ConfigTableLoader/DtbLoader.inf index 751fe175ea..1f73594d60 100644 --- a/EmbeddedPkg/Application/ConfigTableLoader/DtbLoader.inf +++ b/EmbeddedPkg/Application/ConfigTableLoader/DtbLoader.inf @@ -32,6 +32,7 @@
[LibraryClasses] BaseLib + FdtLib UefiDriverEntryPoint UefiBootServicesTableLib UefiRuntimeServicesTableLib