Sync up ArmPkg with patch from mailing list. Changed name of BdsLib.h to BdsUnixLib.h and fixed a lot of issues with Xcode building.

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@11293 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
andrewfish
2011-02-02 22:35:30 +00:00
parent 7373d15a98
commit 1bfda055df
113 changed files with 7979 additions and 964 deletions

View File

@@ -0,0 +1,102 @@
/** @file
*
* Copyright (c) 2011, ARM Limited. All rights reserved.
*
* This program and the accompanying materials
* are licensed and made available under the terms and conditions of the BSD License
* which accompanies this distribution. The full text of the license may be found at
* http://opensource.org/licenses/bsd-license.php
*
* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
*
**/
#include "BdsInternal.h"
EFI_STATUS
BdsLoadPeCoff (
IN BDS_FILE *EfiAppFile
)
{
EFI_STATUS Status;
EFI_HANDLE ImageHandle;
MEDIA_FW_VOL_FILEPATH_DEVICE_PATH NewNode;
EFI_DEVICE_PATH_PROTOCOL *DevicePath;
// Only support loading from FV right now
ASSERT(EfiAppFile->Type == BDS_FILETYPE_FV);
// Generate the Device Path for the file
DevicePath = DuplicateDevicePath(EfiAppFile->DevicePath);
EfiInitializeFwVolDevicepathNode (&NewNode, &(EfiAppFile->File.Fv.Guid));
DevicePath = AppendDevicePathNode (DevicePath, (EFI_DEVICE_PATH_PROTOCOL *)&NewNode);
Status = gBS->LoadImage (TRUE, gImageHandle, DevicePath, NULL, 0, &ImageHandle);
if (!EFI_ERROR (Status)) {
Status = gBS->StartImage (ImageHandle, NULL, NULL);
}
return Status;
}
EFI_STATUS BdsLoadApplicationFromPath(
IN CHAR16* EfiAppPath
) {
EFI_STATUS Status;
BDS_FILE EfiAppFile;
// Need to connect every drivers to ensure no dependencies are missing for the application
Status = BdsConnectAllDrivers();
if (EFI_ERROR(Status)) {
DEBUG ((EFI_D_ERROR, "FAIL to connect all drivers\n"));
return Status;
}
// Locate the application from a device path
Status = BdsLoadFilePath(EfiAppPath, &EfiAppFile);
if (EFI_ERROR(Status)) {
DEBUG ((EFI_D_ERROR, "ERROR: Do not find EFI application %s\n",EfiAppPath));
return Status;
}
// Start the application
Status = BdsLoadPeCoff(&EfiAppFile);
return Status;
}
EFI_STATUS BdsLoadApplication(
IN CHAR16* EfiApp
) {
EFI_STATUS Status;
UINTN NoHandles, HandleIndex;
EFI_HANDLE *Handles;
BDS_FILE EfiAppFile;
// Need to connect every drivers to ensure no dependencies are missing for the application
Status = BdsConnectAllDrivers();
if (EFI_ERROR(Status)) {
DEBUG ((EFI_D_ERROR, "FAIL to connect all drivers\n"));
return Status;
}
// Search the application in any Firmware Volume
Status = gBS->LocateHandleBuffer (ByProtocol, &gEfiFirmwareVolume2ProtocolGuid, NULL, &NoHandles, &Handles);
if (EFI_ERROR (Status) || (NoHandles == 0)) {
DEBUG ((EFI_D_ERROR, "FAIL to find Firmware Volume\n"));
return Status;
}
// Search in all Firmware Volume for the EFI Application
for (HandleIndex = 0; HandleIndex < NoHandles; HandleIndex++) {
Status = BdsLoadFileFromFirmwareVolume(Handles[HandleIndex],EfiApp,EFI_FV_FILETYPE_APPLICATION,&EfiAppFile);
if (!EFI_ERROR (Status)) {
// Start the application
Status = BdsLoadPeCoff(&EfiAppFile);
return Status;
}
}
return Status;
}

View File

@@ -0,0 +1,182 @@
/** @file
*
* Copyright (c) 2011, ARM Limited. All rights reserved.
*
* This program and the accompanying materials
* are licensed and made available under the terms and conditions of the BSD License
* which accompanies this distribution. The full text of the license may be found at
* http://opensource.org/licenses/bsd-license.php
*
* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
*
**/
#include "BdsInternal.h"
// Count the number of DevicePath Node
static UINTN NumberNodeFromDevicePath(
IN EFI_DEVICE_PATH_PROTOCOL* DevicePath
) {
UINTN NumberDevicePathNode = 0;
while (!IsDevicePathEnd (DevicePath)) {
NumberDevicePathNode++;
DevicePath = NextDevicePathNode(DevicePath);
}
return NumberDevicePathNode;
}
// Extract the FilePath from the Device Path
CHAR16* BdsExtractFilePathFromDevicePath(
IN CONST CHAR16 *StrDevicePath,
IN UINTN NumberDevicePathNode
) {
UINTN Node;
CHAR16 *Str;
Str = (CHAR16*)StrDevicePath;
Node = 0;
while ((Str != NULL) && (*Str != L'\0') && (Node < NumberDevicePathNode)) {
if ((*Str == L'/') || (*Str == L'\\')) {
Node++;
}
Str++;
}
if (*Str == L'\0') {
return NULL;
} else {
return Str;
}
}
EFI_STATUS
BdsLoadDevicePath(
IN EFI_DEVICE_PATH_PROTOCOL* DevicePath,
OUT EFI_HANDLE *Handle
) {
EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath;
EFI_STATUS Status;
if ((DevicePath == NULL) || (Handle == NULL)) {
return EFI_INVALID_PARAMETER;
}
do {
RemainingDevicePath = DevicePath;
// The LocateDevicePath() function locates all devices on DevicePath that support Protocol and returns
// the handle to the device that is closest to DevicePath. On output, the device path pointer is modified
// to point to the remaining part of the device path
Status = gBS->LocateDevicePath(&gEfiDevicePathProtocolGuid,&RemainingDevicePath,Handle);
if (!EFI_ERROR (Status)) {
// Recursive = FALSE: We do not want to start all the device tree
Status = gBS->ConnectController (*Handle, NULL, RemainingDevicePath, FALSE);
}
// We need to check if RemainingDevicePath does not point on the last node. Otherwise, calling
// NextDevicePathNode() will return an undetermined Device Path Node
if (!IsDevicePathEnd (RemainingDevicePath)) {
RemainingDevicePath = NextDevicePathNode (RemainingDevicePath);
}
} while (!EFI_ERROR (Status) && !IsDevicePathEnd (RemainingDevicePath));
if (!EFI_ERROR (Status)) {
// Now, we have got the whole Device Path connected, call again ConnectController to ensure all the supported Driver
// Binding Protocol are connected (such as DiskIo and SimpleFileSystem)
RemainingDevicePath = DevicePath;
Status = gBS->LocateDevicePath(&gEfiDevicePathProtocolGuid,&RemainingDevicePath,Handle);
if (!EFI_ERROR (Status)) {
Status = gBS->ConnectController (*Handle, NULL, RemainingDevicePath, FALSE);
if (EFI_ERROR (Status)) {
// If the last node is a Memory Map Device Path just return EFI_SUCCESS.
if ((RemainingDevicePath->Type == HARDWARE_DEVICE_PATH) && (RemainingDevicePath->SubType == HW_MEMMAP_DP)) {
Status = EFI_SUCCESS;
}
}
}
} else if (IsDevicePathEnd (RemainingDevicePath)) {
// Case when the DevicePath contains a MemoryMap Device Path Node and all drivers are connected.
// Ensure the Device Path exists
RemainingDevicePath = DevicePath;
Status = gBS->LocateDevicePath(&gEfiDevicePathProtocolGuid,&RemainingDevicePath,Handle);
}
return Status;
}
EFI_STATUS
BdsLoadFilePath (
IN CONST CHAR16 *DeviceFilePath,
OUT BDS_FILE *File
) {
EFI_DEVICE_PATH_PROTOCOL *DevicePath;
EFI_DEVICE_PATH_FROM_TEXT_PROTOCOL *EfiDevicePathFromTextProtocol;
EFI_STATUS Status;
EFI_HANDLE Handle;
UINTN NumberDevicePathNode;
CHAR16 *FilePath;
//Do a sanity check on the Device file path
if (DeviceFilePath == NULL) {
return EFI_INVALID_PARAMETER;
}
// Convert the Device Path String into Device Path Protocol
Status = gBS->LocateProtocol(&gEfiDevicePathFromTextProtocolGuid, NULL, (VOID **)&EfiDevicePathFromTextProtocol);
ASSERT_EFI_ERROR(Status);
DevicePath = EfiDevicePathFromTextProtocol->ConvertTextToDevicePath(DeviceFilePath);
//Do a sanity check on the Device Path
if (DevicePath == NULL) {
return EFI_INVALID_PARAMETER;
}
// Count the number of DevicePath Node
NumberDevicePathNode = NumberNodeFromDevicePath(DevicePath);
// Extract the FilePath from the Device Path
FilePath = BdsExtractFilePathFromDevicePath(DeviceFilePath,NumberDevicePathNode);
Status = BdsLoadDevicePath(DevicePath,&Handle);
if (EFI_ERROR (Status)) {
return Status;
}
//If FilePath == NULL then let consider if a MemoryMap Device Path
if (FilePath == NULL) {
// Check if the Node is a MemoryMap Device Path
Status = BdsLoadFileFromMemMap(Handle,DevicePath,File);
} else {
Status = BdsLoadFileFromSimpleFileSystem(Handle,FilePath,File);
if (EFI_ERROR (Status)) {
Status = BdsLoadFileFromFirmwareVolume(Handle,FilePath,EFI_FV_FILETYPE_ALL,File);
}
}
if (!EFI_ERROR (Status)) {
File->DevicePath = DevicePath;
}
return Status;
}
EFI_STATUS BdsCopyRawFileToRuntimeMemory(
IN BDS_FILE *File,
OUT VOID **FileImage,
OUT UINTN *FileSize
) {
if (File == NULL) {
return EFI_INVALID_PARAMETER;
}
if (File->Type == BDS_FILETYPE_FS) {
return BdsCopyRawFileToRuntimeMemoryFS(File->File.Fs.Handle,FileImage,FileSize);
} else if (File->Type == BDS_FILETYPE_FV) {
return BdsCopyRawFileToRuntimeMemoryFV(&(File->File.Fv),FileImage,FileSize);
} else if (File->Type == BDS_FILETYPE_MEM) {
return BdsCopyRawFileToRuntimeMemoryMemMap(&(File->File.Mem),FileImage,FileSize);
} else {
return EFI_INVALID_PARAMETER;
}
}

View File

@@ -0,0 +1,86 @@
/** @file
*
* Copyright (c) 2011, ARM Limited. All rights reserved.
*
* This program and the accompanying materials
* are licensed and made available under the terms and conditions of the BSD License
* which accompanies this distribution. The full text of the license may be found at
* http://opensource.org/licenses/bsd-license.php
*
* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
*
**/
#include "BdsInternal.h"
EFI_STATUS BdsLoadFileFromSimpleFileSystem(
IN EFI_HANDLE Handle,
IN CHAR16 *FilePath,
OUT BDS_FILE *File
) {
EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *FsProtocol;
EFI_FILE_PROTOCOL *Fs;
EFI_STATUS Status;
EFI_FILE_PROTOCOL *FileHandle = NULL;
if (File == NULL) {
return EFI_INVALID_PARAMETER;
}
Status = gBS->HandleProtocol(Handle,&gEfiSimpleFileSystemProtocolGuid, (VOID **)&FsProtocol);
if (EFI_ERROR(Status)) {
return Status;
}
//Try to Open the volume and get root directory
Status = FsProtocol->OpenVolume(FsProtocol, &Fs);
if (EFI_ERROR(Status)) {
return Status;
}
Status = Fs->Open(Fs, &FileHandle, FilePath, EFI_FILE_MODE_READ, 0);
File->Type = BDS_FILETYPE_FS;
File->FilePath = FilePath;
File->File.Fs.Handle = FileHandle;
return Status;
}
EFI_STATUS BdsCopyRawFileToRuntimeMemoryFS(
IN EFI_FILE_PROTOCOL *File,
OUT VOID **FileImage,
OUT UINTN *FileSize
) {
EFI_FILE_INFO *FileInfo;
UINTN Size;
VOID* Image;
EFI_STATUS Status;
Size = 0;
File->GetInfo(File, &gEfiFileInfoGuid, &Size, NULL);
FileInfo = AllocatePool (Size);
Status = File->GetInfo(File, &gEfiFileInfoGuid, &Size, FileInfo);
if (EFI_ERROR(Status)) {
return Status;
}
// Get the file size
Size = FileInfo->FileSize;
if (FileSize) {
*FileSize = Size;
}
FreePool(FileInfo);
Image = AllocateRuntimePool(Size);
if (Image == NULL) {
return EFI_OUT_OF_RESOURCES;
}
Status = File->Read(File, &Size, Image);
if (!EFI_ERROR(Status)) {
*FileImage = Image;
}
return Status;
}

View File

@@ -0,0 +1,136 @@
/** @file
*
* Copyright (c) 2011, ARM Limited. All rights reserved.
*
* This program and the accompanying materials
* are licensed and made available under the terms and conditions of the BSD License
* which accompanies this distribution. The full text of the license may be found at
* http://opensource.org/licenses/bsd-license.php
*
* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
*
**/
#include "BdsInternal.h"
EFI_STATUS BdsLoadFileFromFirmwareVolume(
IN EFI_HANDLE FvHandle,
IN CHAR16 *FilePath,
IN EFI_FV_FILETYPE FileTypeFilter,
OUT BDS_FILE *File
) {
EFI_FIRMWARE_VOLUME2_PROTOCOL *FvProtocol;
VOID *Key;
EFI_STATUS Status, FileStatus;
EFI_GUID NameGuid;
EFI_FV_FILETYPE FileType;
EFI_FV_FILE_ATTRIBUTES Attributes;
UINTN Size;
UINTN UiStringLen;
CHAR16 *UiSection;
UINT32 Authentication;
if (File == NULL) {
return EFI_INVALID_PARAMETER;
}
Status = gBS->HandleProtocol(FvHandle,&gEfiFirmwareVolume2ProtocolGuid, (VOID **)&FvProtocol);
if (EFI_ERROR(Status)) {
return Status;
}
// Length of FilePath
UiStringLen = StrLen (FilePath);
// Allocate Key
Key = AllocatePool (FvProtocol->KeySize);
ASSERT (Key != NULL);
ZeroMem (Key, FvProtocol->KeySize);
do {
// Search in all files
FileType = FileTypeFilter;
Status = FvProtocol->GetNextFile (FvProtocol, Key, &FileType, &NameGuid, &Attributes, &Size);
if (!EFI_ERROR (Status)) {
UiSection = NULL;
FileStatus = FvProtocol->ReadSection (
FvProtocol,
&NameGuid,
EFI_SECTION_USER_INTERFACE,
0,
(VOID **)&UiSection,
&Size,
&Authentication
);
if (!EFI_ERROR (FileStatus)) {
if (StrnCmp (FilePath, UiSection, UiStringLen) == 0) {
//
// We found a UiString match.
//
//*FileGuid = NameGuid;
File->Type = BDS_FILETYPE_FV;
File->FilePath = FilePath;
CopyGuid (&(File->File.Fv.Guid),&NameGuid);
File->File.Fv.FvProtocol = FvProtocol;
File->File.Fv.FileType = FileType;
Status = gBS->HandleProtocol(FvHandle,&gEfiDevicePathProtocolGuid, (VOID **)&(File->DevicePath));
FreePool (Key);
FreePool (UiSection);
return FileStatus;
}
FreePool (UiSection);
}
}
} while (!EFI_ERROR (Status));
FreePool(Key);
return Status;
}
EFI_STATUS BdsCopyRawFileToRuntimeMemoryFV(
IN BDS_FV_FILE *FvFile,
OUT VOID **FileImage,
OUT UINTN *FileSize
) {
EFI_STATUS Status = EFI_INVALID_PARAMETER;
EFI_FIRMWARE_VOLUME2_PROTOCOL *FvProtocol;
EFI_FV_FILETYPE FileType;
EFI_GUID* NameGuid;
EFI_FV_FILE_ATTRIBUTES Attributes;
UINT32 Authentication;
FvProtocol = FvFile->FvProtocol;
FileType = FvFile->FileType;
NameGuid = &(FvFile->Guid);
if (FileType == EFI_FV_FILETYPE_RAW) {
*FileImage = NULL;
*FileSize = 0;
Status = FvProtocol->ReadFile(
FvProtocol,NameGuid, // IN
FileImage,FileSize, // IN OUT
&FileType,&Attributes,&Authentication // OUT
);
ASSERT_EFI_ERROR(Status);
// This raw file also contains a header
*FileSize = *FileSize - 4;
*FileImage = (UINT8*)FileImage + 4;
} else if (FileType == EFI_FV_FILETYPE_FREEFORM) {
Status = FvProtocol->ReadSection (
FvProtocol,NameGuid,EFI_SECTION_RAW,0, // IN
FileImage,FileSize, // IN OUT
&Authentication // OUT
);
ASSERT_EFI_ERROR(Status);
} else {
ASSERT(0); //Maybe support application as well ???
}
return Status;
}

View File

@@ -0,0 +1,73 @@
/** @file
*
* Copyright (c) 2011, ARM Limited. All rights reserved.
*
* This program and the accompanying materials
* are licensed and made available under the terms and conditions of the BSD License
* which accompanies this distribution. The full text of the license may be found at
* http://opensource.org/licenses/bsd-license.php
*
* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
*
**/
#include "BdsInternal.h"
EFI_STATUS BdsLoadFileFromMemMap (
IN EFI_HANDLE Handle,
IN EFI_DEVICE_PATH_PROTOCOL *DevicePath,
OUT BDS_FILE *File
) {
EFI_DEVICE_PATH_PROTOCOL *LastDevicePath;
if ((File == NULL) || (DevicePath == NULL) || (IsDevicePathEnd (DevicePath))) {
return EFI_INVALID_PARAMETER;
}
// Check if the last node of the device Path is a Memory Map Device Node
LastDevicePath = DevicePath;
DevicePath = NextDevicePathNode(DevicePath);
while (!IsDevicePathEnd (DevicePath)) {
LastDevicePath = DevicePath;
DevicePath = NextDevicePathNode(DevicePath);
}
if ((LastDevicePath->Type != HARDWARE_DEVICE_PATH) || (LastDevicePath->SubType != HW_MEMMAP_DP)) {
return EFI_UNSUPPORTED;
}
File->Type = BDS_FILETYPE_MEM;
File->File.Mem.MemoryType = ((MEMMAP_DEVICE_PATH*)LastDevicePath)->MemoryType;
File->File.Mem.StartingAddress = ((MEMMAP_DEVICE_PATH*)LastDevicePath)->StartingAddress;
File->File.Mem.EndingAddress = ((MEMMAP_DEVICE_PATH*)LastDevicePath)->EndingAddress;
return EFI_SUCCESS;
}
EFI_STATUS BdsCopyRawFileToRuntimeMemoryMemMap(
IN BDS_MEM_FILE *MemFile,
OUT VOID **FileImage,
OUT UINTN *FileSize
) {
UINTN Size;
VOID* Image;
Size = MemFile->EndingAddress - MemFile->StartingAddress;
if ((Size == 0) || (FileImage == NULL)) {
return EFI_INVALID_PARAMETER;
}
if (FileSize != NULL) {
*FileSize = Size;
}
Image = AllocateRuntimePool(Size);
if (Image == NULL) {
return EFI_OUT_OF_RESOURCES;
}
*FileImage = CopyMem(Image,(CONST VOID*)(UINTN)MemFile->StartingAddress,Size);
return EFI_SUCCESS;
}

View File

@@ -0,0 +1,183 @@
/** @file
*
* Copyright (c) 2011, ARM Limited. All rights reserved.
*
* This program and the accompanying materials
* are licensed and made available under the terms and conditions of the BSD License
* which accompanies this distribution. The full text of the license may be found at
* http://opensource.org/licenses/bsd-license.php
*
* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
*
**/
#include "BdsInternal.h"
#include <Library/DxeServicesTableLib.h>
#include <Library/HobLib.h>
EFI_STATUS
ShutdownUefiBootServices( VOID )
{
EFI_STATUS Status;
UINTN MemoryMapSize;
EFI_MEMORY_DESCRIPTOR *MemoryMap;
UINTN MapKey;
UINTN DescriptorSize;
UINT32 DescriptorVersion;
UINTN Pages;
MemoryMap = NULL;
MemoryMapSize = 0;
do {
Status = gBS->GetMemoryMap (
&MemoryMapSize,
MemoryMap,
&MapKey,
&DescriptorSize,
&DescriptorVersion
);
if (Status == EFI_BUFFER_TOO_SMALL) {
Pages = EFI_SIZE_TO_PAGES (MemoryMapSize) + 1;
MemoryMap = AllocatePages (Pages);
//
// Get System MemoryMap
//
Status = gBS->GetMemoryMap (
&MemoryMapSize,
MemoryMap,
&MapKey,
&DescriptorSize,
&DescriptorVersion
);
// Don't do anything between the GetMemoryMap() and ExitBootServices()
if (!EFI_ERROR (Status)) {
Status = gBS->ExitBootServices (gImageHandle, MapKey);
if (EFI_ERROR (Status)) {
FreePages (MemoryMap, Pages);
MemoryMap = NULL;
MemoryMapSize = 0;
}
}
}
} while (EFI_ERROR (Status));
return Status;
}
EFI_STATUS
BdsConnectAllDrivers( VOID ) {
UINTN HandleCount, Index;
EFI_HANDLE *HandleBuffer;
EFI_STATUS Status;
do {
// Locate all the driver handles
Status = gBS->LocateHandleBuffer (
AllHandles,
NULL,
NULL,
&HandleCount,
&HandleBuffer
);
if (EFI_ERROR (Status)) {
break;
}
// Connect every handles
for (Index = 0; Index < HandleCount; Index++) {
gBS->ConnectController(HandleBuffer[Index], NULL, NULL, TRUE);
}
if (HandleBuffer != NULL) {
FreePool (HandleBuffer);
}
// Check if new handles have been created after the start of the previous handles
Status = gDS->Dispatch ();
} while (!EFI_ERROR(Status));
return EFI_SUCCESS;
}
STATIC EFI_STATUS InsertSystemMemoryResources(LIST_ENTRY *ResourceList, EFI_HOB_RESOURCE_DESCRIPTOR *ResHob) {
BDS_SYSTEM_MEMORY_RESOURCE NewResource;
LIST_ENTRY *Link;
BDS_SYSTEM_MEMORY_RESOURCE *Resource;
//DEBUG ((EFI_D_ERROR, "** InsertSystemMemoryResources(0x%X,0x%X)\n",(UINT32)ResHob->PhysicalStart,(UINT32)ResHob->ResourceLength));
if (IsListEmpty (ResourceList)) {
ZeroMem(&NewResource,sizeof(BDS_SYSTEM_MEMORY_RESOURCE));
NewResource.PhysicalStart = ResHob->PhysicalStart;
NewResource.ResourceLength = ResHob->ResourceLength;
InsertTailList (ResourceList, &NewResource.Link);
return EFI_SUCCESS;
}
//for (Link = GetFirstNode (ResourceList); !IsNull (ResourceList,Link); Link = GetNextNode (ResourceList,Link)) {
Link = ResourceList->ForwardLink;
while (Link != NULL && Link != ResourceList) {
Resource = (BDS_SYSTEM_MEMORY_RESOURCE*)Link;
//DEBUG ((EFI_D_ERROR, " - (0x%X,0x%X)\n",(UINT32)Resource->PhysicalStart,(UINT32)Resource->ResourceLength));
// Sanity Check. The resources should not overlapped.
ASSERT(!((ResHob->PhysicalStart >= Resource->PhysicalStart) && (ResHob->PhysicalStart < (Resource->PhysicalStart + Resource->ResourceLength))));
ASSERT(!((ResHob->PhysicalStart + ResHob->ResourceLength >= Resource->PhysicalStart) &&
((ResHob->PhysicalStart + ResHob->ResourceLength) < (Resource->PhysicalStart + Resource->ResourceLength))));
// The new resource is attached after this resource descriptor
if (ResHob->PhysicalStart == Resource->PhysicalStart + Resource->ResourceLength) {
Resource->ResourceLength = Resource->ResourceLength + ResHob->ResourceLength;
//DEBUG ((EFI_D_ERROR, "** Attached new Length:0x%X\n",(UINT32)Resource->ResourceLength));
return EFI_SUCCESS;
}
// The new resource is attached before this resource descriptor
else if (ResHob->PhysicalStart + ResHob->ResourceLength == Resource->PhysicalStart) {
Resource->PhysicalStart = ResHob->PhysicalStart;
Resource->ResourceLength = Resource->ResourceLength + ResHob->ResourceLength;
//DEBUG ((EFI_D_ERROR, "** Attached2 new Length:0x%X\n",(UINT32)Resource->ResourceLength));
return EFI_SUCCESS;
}
Link = Link->ForwardLink;
}
// None of the Resource of the list is attached to this ResHob. Create a new entry for it
ZeroMem(&NewResource,sizeof(BDS_SYSTEM_MEMORY_RESOURCE));
NewResource.PhysicalStart = ResHob->PhysicalStart;
NewResource.ResourceLength = ResHob->ResourceLength;
InsertTailList (ResourceList, &NewResource.Link);
return EFI_SUCCESS;
}
EFI_STATUS GetSystemMemoryResources(LIST_ENTRY *ResourceList) {
EFI_HOB_RESOURCE_DESCRIPTOR *ResHob;
InitializeListHead (ResourceList);
// Find the first System Memory Resource Descriptor
ResHob = (EFI_HOB_RESOURCE_DESCRIPTOR *)GetFirstHob (EFI_HOB_TYPE_RESOURCE_DESCRIPTOR);
while ((ResHob != NULL) && (ResHob->ResourceType != EFI_RESOURCE_SYSTEM_MEMORY)) {
ResHob = (EFI_HOB_RESOURCE_DESCRIPTOR *)GetNextHob (EFI_HOB_TYPE_RESOURCE_DESCRIPTOR,(VOID *)((UINTN)ResHob + ResHob->Header.HobLength));
}
// Did not find any
if (ResHob == NULL) {
return EFI_NOT_FOUND;
} else {
InsertSystemMemoryResources(ResourceList, ResHob);
}
ResHob = (EFI_HOB_RESOURCE_DESCRIPTOR *)GetNextHob (EFI_HOB_TYPE_RESOURCE_DESCRIPTOR,(VOID *)((UINTN)ResHob + ResHob->Header.HobLength));
while (ResHob != NULL) {
if (ResHob->ResourceType == EFI_RESOURCE_SYSTEM_MEMORY) {
InsertSystemMemoryResources(ResourceList, ResHob);
}
ResHob = (EFI_HOB_RESOURCE_DESCRIPTOR *)GetNextHob (EFI_HOB_TYPE_RESOURCE_DESCRIPTOR,(VOID *)((UINTN)ResHob + ResHob->Header.HobLength));
}
return EFI_SUCCESS;
}

View File

@@ -0,0 +1,136 @@
/** @file
*
* Copyright (c) 2011, ARM Limited. All rights reserved.
*
* This program and the accompanying materials
* are licensed and made available under the terms and conditions of the BSD License
* which accompanies this distribution. The full text of the license may be found at
* http://opensource.org/licenses/bsd-license.php
*
* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
*
**/
#ifndef __BDS_INTERNAL_H__
#define __BDS_INTERNAL_H__
#include <PiDxe.h>
#include <Library/BaseLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Library/UefiLib.h>
#include <Library/DevicePathLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/DebugLib.h>
#include <Library/BdsUnixLib.h>
#include <Guid/FileInfo.h>
#include <Protocol/DevicePath.h>
#include <Protocol/DevicePathFromText.h>
#include <Protocol/SimpleFileSystem.h>
#include <Protocol/FirmwareVolume2.h>
typedef enum { BDS_FILETYPE_MEM, BDS_FILETYPE_FS, BDS_FILETYPE_FV } BDS_FILE_TYPE;
typedef struct {
UINT32 MemoryType;
EFI_PHYSICAL_ADDRESS StartingAddress;
EFI_PHYSICAL_ADDRESS EndingAddress;
} BDS_MEM_FILE;
typedef struct {
EFI_FILE_PROTOCOL *Handle;
} BDS_FS_FILE;
typedef struct {
EFI_FIRMWARE_VOLUME2_PROTOCOL *FvProtocol;
EFI_FV_FILETYPE FileType;
EFI_GUID Guid;
} BDS_FV_FILE;
typedef struct _BDS_FILE {
CHAR16* FilePath;
EFI_DEVICE_PATH_PROTOCOL *DevicePath;
BDS_FILE_TYPE Type;
union {
BDS_MEM_FILE Mem;
BDS_FS_FILE Fs;
BDS_FV_FILE Fv;
} File;
} BDS_FILE;
typedef struct _BDS_SYSTEM_MEMORY_RESOURCE {
LIST_ENTRY Link; // This attribute must be the first entry of this structure (to avoid pointer computation)
EFI_PHYSICAL_ADDRESS PhysicalStart;
UINT64 ResourceLength;
} BDS_SYSTEM_MEMORY_RESOURCE;
// BdsHelper.c
EFI_STATUS
ShutdownUefiBootServices( VOID );
EFI_STATUS
GetSystemMemoryResources (LIST_ENTRY *ResourceList);
// BdsFilePath.c
EFI_STATUS BdsLoadDevicePath(
IN EFI_DEVICE_PATH_PROTOCOL* DevicePath,
OUT EFI_HANDLE *Handle
);
EFI_STATUS BdsLoadFilePath(
IN CONST CHAR16 *DeviceFilePath,
OUT BDS_FILE *File
);
EFI_STATUS BdsCopyRawFileToRuntimeMemory(
IN BDS_FILE *File,
OUT VOID **FileImage,
OUT UINTN *FileSize
);
// BdsFilePathFs.c
EFI_STATUS BdsLoadFileFromSimpleFileSystem(
IN EFI_HANDLE Handle,
IN CHAR16 *FilePath,
OUT BDS_FILE *File
);
EFI_STATUS BdsCopyRawFileToRuntimeMemoryFS(
IN EFI_FILE_PROTOCOL *File,
OUT VOID **FileImage,
OUT UINTN *FileSize
);
// BdsFilePathFv.c
EFI_STATUS BdsLoadFileFromFirmwareVolume(
IN EFI_HANDLE FvHandle,
IN CHAR16 *FilePath,
IN EFI_FV_FILETYPE FileTypeFilter,
OUT BDS_FILE *File
);
EFI_STATUS BdsCopyRawFileToRuntimeMemoryFV(
IN BDS_FV_FILE *FvFile,
OUT VOID **FileImage,
OUT UINTN *FileSize
);
// BdsFilePathMem.c
EFI_STATUS BdsLoadFileFromMemMap (
IN EFI_HANDLE Handle,
IN EFI_DEVICE_PATH_PROTOCOL *DevicePath,
OUT BDS_FILE *File
);
EFI_STATUS BdsCopyRawFileToRuntimeMemoryMemMap(
IN BDS_MEM_FILE *MemFile,
OUT VOID **FileImage,
OUT UINTN *FileSize
);
#endif

View File

@@ -0,0 +1,63 @@
#/* @file
# Copyright (c) 2011, ARM Limited. All rights reserved.
#
# This program and the accompanying materials
# are licensed and made available under the terms and conditions of the BSD License
# which accompanies this distribution. The full text of the license may be found at
# http://opensource.org/licenses/bsd-license.php
#
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#
#*/
[Defines]
INF_VERSION = 0x00010005
BASE_NAME = BdsLib
FILE_GUID = ddbf73a0-bb25-11df-8e4e-0002a5d5c51b
MODULE_TYPE = UEFI_DRIVER
VERSION_STRING = 1.0
LIBRARY_CLASS = BdsLib
[Sources.common]
BdsFilePath.c
BdsFilePathFs.c
BdsFilePathFv.c
BdsFilePathMem.c
BdsLinuxLoader.c
BdsAppLoader.c
BdsHelper.c
[Packages]
MdePkg/MdePkg.dec
EmbeddedPkg/EmbeddedPkg.dec
ArmPkg/ArmPkg.dec
[LibraryClasses]
DevicePathLib
BaseLib
HobLib
DebugLib
UefiDriverEntryPoint
DxeServicesTableLib
ArmLib
[Guids]
gEfiFileInfoGuid
[Protocols]
gEfiBdsArchProtocolGuid
gEfiDevicePathProtocolGuid
gEfiDevicePathFromTextProtocolGuid
gEfiSimpleFileSystemProtocolGuid
gEfiFirmwareVolume2ProtocolGuid
[FeaturePcd]
[FixedPcd]
gArmTokenSpaceGuid.PcdArmMachineType
[Pcd]
[Depex]
TRUE

View File

@@ -0,0 +1,337 @@
/** @file
*
* Copyright (c) 2011, ARM Limited. All rights reserved.
*
* This program and the accompanying materials
* are licensed and made available under the terms and conditions of the BSD License
* which accompanies this distribution. The full text of the license may be found at
* http://opensource.org/licenses/bsd-license.php
*
* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
*
**/
#include "BdsInternal.h"
#include "BdsLinuxLoader.h"
#include <Library/PcdLib.h>
#include <Library/ArmLib.h>
#include <Library/HobLib.h>
STATIC
EFI_STATUS
GetARMLinuxMachineType (
IN BOOLEAN FdtSupported,
OUT UINT32 *MachineType
) {
if (FdtSupported)
{
// FDT requires that the machine type is set to the maximum 32-bit number.
*MachineType = 0xFFFFFFFF;
}
else
{
// Non-FDT requires a specific machine type.
// This OS Boot loader supports just one machine type,
// but that could change in the future.
*MachineType = PcdGet32(PcdArmMachineType);
}
return EFI_SUCCESS;
}
STATIC
VOID
SetupCoreTag( IN UINT32 PageSize )
{
Params->header.size = tag_size(atag_core);
Params->header.type = ATAG_CORE;
Params->body.core_tag.flags = 1; /* ensure read-only */
Params->body.core_tag.pagesize = PageSize; /* systems PageSize (4k) */
Params->body.core_tag.rootdev = 0; /* zero root device (typically overridden from kernel command line )*/
Params = next_tag_address(Params); /* move pointer to next tag */
}
STATIC
VOID
SetupMemTag( IN UINTN StartAddress, IN UINT32 Size )
{
Params->header.size = tag_size(atag_mem);
Params->header.type = ATAG_MEM;
Params->body.mem_tag.start = StartAddress; /* Start of memory chunk for AtagMem */
Params->body.mem_tag.size = Size; /* Size of memory chunk for AtagMem */
Params = next_tag_address(Params); /* move pointer to next tag */
}
STATIC
VOID
SetupCmdlineTag( IN CONST CHAR8 *CmdLine )
{
UINT32 LineLength;
// Increment the line length by 1 to account for the null string terminator character
LineLength = AsciiStrLen(CmdLine) + 1;
/* Check for NULL strings.
* Do not insert a tag for an empty CommandLine, don't even modify the tag address pointer.
* Remember, you have at least one null string terminator character.
*/
if( LineLength > 1 )
{
Params->header.size = ((UINT32)sizeof(struct atag_header) + LineLength + (UINT32)3) >> 2;
Params->header.type = ATAG_CMDLINE;
/* place CommandLine into tag */
AsciiStrCpy(Params->body.cmdline_tag.cmdline, CmdLine);
Params = next_tag_address(Params); /* move pointer to next tag */
}
}
STATIC
VOID
SetupEndTag( VOID )
{
// Empty tag ends list; this has zero length and no body
Params->header.type = ATAG_NONE;
Params->header.size = 0;
/* We can not calculate the next address by using the standard macro:
* Params = next_tag_address(Params);
* because it relies on the header.size, which here it is 0 (zero).
* The easiest way is to add the sizeof(Params->header).
*/
Params = (struct atag *)((UINT32)Params + sizeof(Params->header));
}
STATIC
EFI_STATUS
PrepareAtagList(
IN OUT struct atag **AtagStartAddress,
IN CONST CHAR8* CommandLineString,
OUT UINT32 *AtagSize
) {
LIST_ENTRY *ResourceLink;
LIST_ENTRY ResourceList;
BDS_SYSTEM_MEMORY_RESOURCE *Resource;
// If no address supplied then this function will decide where to put it
if( *AtagStartAddress == 0 )
{
/* WARNING: At the time of writing (2010-July-30) the linux kernel expects
* the atag list it in the first 1MB of memory and preferably at address 0x100.
* This has a very high risk of overwriting UEFI code, but as
* the linux kernel does not expect any runtime services from uefi
* and there is no afterlife section following the linux kernel termination,
* it does not matter if we stamp over that memory area.
*
* The proposed workaround is to create the atag list somewhere in boot services memory
* and then transfer it to address 0x100 (or to runtime services memory) immediately
* before starting the kernel.
* An additional benefit of this is that when we copy the ATAG list to it's final place,
* we can trim down the memory allocation size. Before we create the list we don't know
* how much space it is going to take, so we are over-allocating space.
*/
*AtagStartAddress = (struct atag *) AllocatePool(ATAG_MAX_SIZE);
}
// Ensure the pointer is not NULL.
ASSERT( *AtagStartAddress != (struct atag *)NULL );
// Ready to setup the atag list
Params = *AtagStartAddress;
// Standard core tag 4k PageSize
SetupCoreTag( (UINT32)SIZE_4KB );
// Physical memory setup
GetSystemMemoryResources(&ResourceList);
ResourceLink = ResourceList.ForwardLink;
while (ResourceLink != NULL && ResourceLink != &ResourceList) {
Resource = (BDS_SYSTEM_MEMORY_RESOURCE*)ResourceList.ForwardLink;
SetupMemTag( (UINT32)Resource->PhysicalStart, (UINT32)Resource->ResourceLength );
ResourceLink = ResourceLink->ForwardLink;
}
// CommandLine setting root device
SetupCmdlineTag( CommandLineString );
// end of tags
SetupEndTag();
// Calculate atag list size
*AtagSize = (UINT32)Params - (UINT32)*AtagStartAddress + 1;
return EFI_SUCCESS;
}
STATIC
EFI_STATUS
PreparePlatformHardware( VOID )
{
//Note: Interrupts will be disabled by the GIC driver when ExitBootServices() will be called.
// clean, invalidate, disable data cache
ArmCleanInvalidateDataCache();
ArmDisableDataCache();
// Invalidate and disable the Instruction cache
ArmInvalidateInstructionCache ();
ArmDisableInstructionCache ();
// turn off MMU
ArmInvalidateTlb();
ArmDisableMmu();
return EFI_SUCCESS;
}
/*************************************************
* R0, R1, R2 correspond to registers R0, R1, R2
*************************************************/
//STATIC
EFI_STATUS
StartLinuxKernel( IN VOID* KernelAddress, IN UINTN R0, IN UINTN R1, IN UINTN R2 )
{
VOID (*Kernel)(UINT32 Zero, UINT32 Arch, UINTN AtagListParams);
// set the kernel address
Kernel = (VOID (*)(UINT32, UINT32, UINTN)) KernelAddress;
// Outside BootServices, so can't use Print();
DEBUG((EFI_D_ERROR, "\nStarting the kernel:\n\n"));
// jump to kernel with register set
Kernel( R0, R1, R2 );
// Kernel should never exit
// After Life services are not provided
ASSERT( FALSE );
return EFI_SUCCESS;
}
EFI_STATUS BdsBootLinux(
IN CONST CHAR16* LinuxKernel,
IN CONST CHAR8* ATag,
IN CONST CHAR16* Fdt
) {
BDS_FILE LinuxKernelFile;
BDS_FILE FdtFile;
EFI_STATUS Status;
VOID* LinuxImage;
UINT32 KernelParamsSize;
VOID* KernelParamsAddress = NULL;
UINTN KernelParamsNewAddress;
UINTN *AtagAddress;
UINT32 MachineType;
BOOLEAN FdtSupported = FALSE;
EFI_HOB_RESOURCE_DESCRIPTOR *ResHob;
// Load the Linux kernel from a device path
Status = BdsLoadFilePath(LinuxKernel, &LinuxKernelFile);
if (EFI_ERROR(Status)) {
DEBUG ((EFI_D_ERROR, "ERROR: Do not find Linux kernel %s\n",LinuxKernel));
return Status;
}
// Copy the Linux Kernel from the raw file to Runtime memory
Status = BdsCopyRawFileToRuntimeMemory(&LinuxKernelFile,&LinuxImage,NULL);
if (EFI_ERROR(Status)) {
goto Exit;
}
// Load the FDT binary from a device path
Status = BdsLoadFilePath(Fdt, &FdtFile);
if (!EFI_ERROR(Status)) {
// Copy the FDT binary from the raw file to Runtime memory
Status = BdsCopyRawFileToRuntimeMemory(&FdtFile,&KernelParamsAddress,&KernelParamsSize);
if (EFI_ERROR(Status)) {
goto Exit;
} else {
FdtSupported = TRUE;
}
}
/**********************************************************
* Setup the platform type
**********************************************************/
Status = GetARMLinuxMachineType(FdtSupported, &MachineType);
if(EFI_ERROR(Status))
{
Print(L"ERROR : Can not prepare ARM Linux machine type. Status=0x%X\n", Status);
goto Exit;
}
if (!FdtSupported) {
/**********************************************************
* Setup the ATAG list
**********************************************************/
// By setting address=0 we leave the memory allocation to the function
AtagAddress = 0;
Status = PrepareAtagList( (struct atag **)&AtagAddress, ATag, &KernelParamsSize );
KernelParamsAddress = (VOID*)AtagAddress;
if(EFI_ERROR(Status))
{
Print(L"ERROR : Can not prepare ATAG list. Status=0x%X\n", Status);
goto Exit;
}
}
/**********************************************************
* Switch off interrupts, caches, mmu, etc
**********************************************************/
Status = PreparePlatformHardware();
if(EFI_ERROR(Status))
{
Print(L"ERROR : Can not prepare platform hardware. Status=0x%X\n", Status);
goto Exit;
}
// Initialize the ATag destination
KernelParamsNewAddress = 0x100;
// Update the ATag destination by finding the start address of the first System Memory Resource Descriptor Hob
ResHob = (EFI_HOB_RESOURCE_DESCRIPTOR *)GetFirstHob (EFI_HOB_TYPE_RESOURCE_DESCRIPTOR);
while (ResHob != NULL) {
if (ResHob->ResourceType == EFI_RESOURCE_SYSTEM_MEMORY) {
KernelParamsNewAddress = (UINTN)ResHob->PhysicalStart + 0x100;
break;
}
ResHob = (EFI_HOB_RESOURCE_DESCRIPTOR *)GetNextHob (EFI_HOB_TYPE_RESOURCE_DESCRIPTOR, (VOID *)((UINTN)ResHob + ResHob->Header.HobLength));
}
// Shut down UEFI boot services. ExitBootServices() will notify every driver that created an event on
// ExitBootServices event. Example the Interrupt DXE driver will disable the interrupts on this event.
Status = ShutdownUefiBootServices();
if(EFI_ERROR(Status))
{
Print(L"ERROR : Can not shutdown UEFI boot services. Status=0x%X\n", Status);
goto Exit;
}
// Move the kernel parameters to any address inside the first 1MB.
// This is necessary because the ARM Linux kernel requires
// the FTD / ATAG List to reside entirely inside the first 1MB of
// physical memory.
CopyMem((VOID*)KernelParamsNewAddress, KernelParamsAddress, KernelParamsSize);
//**********************************************************
// * Start the Linux Kernel
// **********************************************************
// Lift off ...
Status = StartLinuxKernel(LinuxImage, (UINTN)0, (UINTN)MachineType, KernelParamsNewAddress );
// Only be here if we fail to start Linux
DEBUG((EFI_D_ERROR, "ERROR : Can not start the kernel. Status=0x%X\n", Status));
Exit:
// Free Runtimee Memory (kernel and FDT)
return Status;
}

View File

@@ -0,0 +1,165 @@
/** @file
*
* Copyright (c) 2011, ARM Limited. All rights reserved.
*
* This program and the accompanying materials
* are licensed and made available under the terms and conditions of the BSD License
* which accompanies this distribution. The full text of the license may be found at
* http://opensource.org/licenses/bsd-license.php
*
* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
*
**/
#ifndef __BDSLINUXLOADER_H
#define __BDSLINUXLOADER_H
#define ATAG_MAX_SIZE 0x4000
//PcdKernelParamsMaxMemorySize
/* ATAG : list of possible tags */
#define ATAG_NONE 0x00000000
#define ATAG_CORE 0x54410001
#define ATAG_MEM 0x54410002
#define ATAG_VIDEOTEXT 0x54410003
#define ATAG_RAMDISK 0x54410004
#define ATAG_INITRD2 0x54420005
#define ATAG_SERIAL 0x54410006
#define ATAG_REVISION 0x54410007
#define ATAG_VIDEOLFB 0x54410008
#define ATAG_CMDLINE 0x54410009
#define ATAG_ARM_MP_CORE 0x5441000A
// Some system addresses
// These should probably come from the platform header file or from pcd values
#define DRAM_BASE 0x10000000
#define ZIMAGE_LOAD_ADDRESS (DRAM_BASE + 0x8000)
#define INITRD_LOAD_ADDRESS (DRAM_BASE + 0x800000)
#define SIZE_1B 0x00000001
#define SIZE_2B 0x00000002
#define SIZE_4B 0x00000004
#define SIZE_8B 0x00000008
#define SIZE_16B 0x00000010
#define SIZE_32B 0x00000020
#define SIZE_64B 0x00000040
#define SIZE_128B 0x00000080
#define SIZE_256B 0x00000100
#define SIZE_512B 0x00000200
#define SIZE_1KB 0x00000400
#define SIZE_2KB 0x00000800
#define SIZE_4KB 0x00001000
#define SIZE_8KB 0x00002000
#define SIZE_16KB 0x00004000
#define SIZE_32KB 0x00008000
#define SIZE_64KB 0x00010000
#define SIZE_128KB 0x00020000
#define SIZE_256KB 0x00040000
#define SIZE_512KB 0x00080000
#define SIZE_1MB 0x00100000
#define SIZE_2MB 0x00200000
#define SIZE_4MB 0x00400000
#define SIZE_8MB 0x00800000
#define SIZE_16MB 0x01000000
#define SIZE_32MB 0x02000000
#define SIZE_64MB 0x04000000
#define SIZE_100MB 0x06400000
#define SIZE_128MB 0x08000000
#define SIZE_256MB 0x10000000
#define SIZE_512MB 0x20000000
#define SIZE_1GB 0x40000000
#define SIZE_2GB 0x80000000
/* structures for each atag */
struct atag_header {
UINT32 size; /* length of tag in words including this header */
UINT32 type; /* tag type */
};
struct atag_core {
UINT32 flags;
UINT32 pagesize;
UINT32 rootdev;
};
struct atag_mem {
UINT32 size;
UINTN start;
};
struct atag_videotext {
UINT8 x;
UINT8 y;
UINT16 video_page;
UINT8 video_mode;
UINT8 video_cols;
UINT16 video_ega_bx;
UINT8 video_lines;
UINT8 video_isvga;
UINT16 video_points;
};
struct atag_ramdisk {
UINT32 flags;
UINT32 size;
UINTN start;
};
struct atag_initrd2 {
UINT32 start;
UINT32 size;
};
struct atag_serialnr {
UINT32 low;
UINT32 high;
};
struct atag_revision {
UINT32 rev;
};
struct atag_videolfb {
UINT16 lfb_width;
UINT16 lfb_height;
UINT16 lfb_depth;
UINT16 lfb_linelength;
UINT32 lfb_base;
UINT32 lfb_size;
UINT8 red_size;
UINT8 red_pos;
UINT8 green_size;
UINT8 green_pos;
UINT8 blue_size;
UINT8 blue_pos;
UINT8 rsvd_size;
UINT8 rsvd_pos;
};
struct atag_cmdline {
CHAR8 cmdline[1];
};
struct atag {
struct atag_header header;
union {
struct atag_core core_tag;
struct atag_mem mem_tag;
struct atag_videotext videotext_tag;
struct atag_ramdisk ramdisk_tag;
struct atag_initrd2 initrd2_tag;
struct atag_serialnr serialnr_tag;
struct atag_revision revision_tag;
struct atag_videolfb videolfb_tag;
struct atag_cmdline cmdline_tag;
} body;
};
#define next_tag_address(t) ((struct atag *)((UINT32)(t) + (((t)->header.size) << 2) ))
#define tag_size(type) ((UINT32)((sizeof(struct atag_header) + sizeof(struct type)) >> 2))
STATIC struct atag *Params; /* used to point at the current tag */
#endif