]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ArmPkg/Library/BdsLib/BdsLinuxAtag.c
ARM Packages: Fixed line endings
[mirror_edk2.git] / ArmPkg / Library / BdsLib / BdsLinuxAtag.c
index 253cf65f36109c6ad861d28966294dbaa9c04e90..8946b142365b2f3061f44a2d727baabb6e8e595e 100644 (file)
-/** @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"
-
-// Point to the current ATAG
-STATIC LINUX_ATAG *mLinuxKernelCurrentAtag;
-
-STATIC
-VOID
-SetupCoreTag (
-  IN UINT32 PageSize
-  )
-{
-  mLinuxKernelCurrentAtag->header.size = tag_size(LINUX_ATAG_CORE);
-  mLinuxKernelCurrentAtag->header.type = ATAG_CORE;
-
-  mLinuxKernelCurrentAtag->body.core_tag.flags    = 1;            /* ensure read-only */
-  mLinuxKernelCurrentAtag->body.core_tag.pagesize = PageSize;     /* systems PageSize (4k) */
-  mLinuxKernelCurrentAtag->body.core_tag.rootdev  = 0;            /* zero root device (typically overridden from kernel command line )*/
-
-  // move pointer to next tag
-  mLinuxKernelCurrentAtag = next_tag_address(mLinuxKernelCurrentAtag);
-}
-
-STATIC
-VOID
-SetupMemTag (
-  IN UINTN StartAddress,
-  IN UINT32 Size
-  )
-{
-  mLinuxKernelCurrentAtag->header.size = tag_size(LINUX_ATAG_MEM);
-  mLinuxKernelCurrentAtag->header.type = ATAG_MEM;
-
-  mLinuxKernelCurrentAtag->body.mem_tag.start = StartAddress;    /* Start of memory chunk for AtagMem */
-  mLinuxKernelCurrentAtag->body.mem_tag.size  = Size;             /* Size of memory chunk for AtagMem */
-
-  // move pointer to next tag
-  mLinuxKernelCurrentAtag = next_tag_address(mLinuxKernelCurrentAtag);
-}
-
-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) {
-    mLinuxKernelCurrentAtag->header.size = ((UINT32)sizeof(LINUX_ATAG_HEADER) + LineLength + (UINT32)3) >> 2;
-    mLinuxKernelCurrentAtag->header.type = ATAG_CMDLINE;
-
-    /* place CommandLine into tag */
-    AsciiStrCpy(mLinuxKernelCurrentAtag->body.cmdline_tag.cmdline, CmdLine);
-
-    // move pointer to next tag
-    mLinuxKernelCurrentAtag = next_tag_address(mLinuxKernelCurrentAtag);
-  }
-}
-
-STATIC
-VOID
-SetupEndTag (
-  VOID
-  )
-{
-  // Empty tag ends list; this has zero length and no body
-  mLinuxKernelCurrentAtag->header.type = ATAG_NONE;
-  mLinuxKernelCurrentAtag->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(mLinuxKernelCurrentAtag->header).
-   */
-  mLinuxKernelCurrentAtag = (LINUX_ATAG*)((UINT32)mLinuxKernelCurrentAtag + sizeof(mLinuxKernelCurrentAtag->header));
-}
-
-EFI_STATUS
-PrepareAtagList (
-  IN  CONST CHAR8*     CommandLineString,
-  IN  EFI_PHYSICAL_ADDRESS InitrdImage,
-  IN  UINTN            InitrdImageSize,
-  OUT LINUX_ATAG       **AtagBase,
-  OUT UINT32           *AtagSize
-  )
-{
-  EFI_STATUS                  Status;
-  LIST_ENTRY                  *ResourceLink;
-  LIST_ENTRY                  ResourceList;
-  EFI_PHYSICAL_ADDRESS        AtagStartAddress;
-  BDS_SYSTEM_MEMORY_RESOURCE  *Resource;
-
-  AtagStartAddress = LINUX_ATAG_MAX_OFFSET;
-  Status = gBS->AllocatePages (AllocateMaxAddress, EfiBootServicesData, EFI_SIZE_TO_PAGES(ATAG_MAX_SIZE), &AtagStartAddress);
-  if (EFI_ERROR(Status)) {
-    DEBUG ((EFI_D_ERROR,"Failed to allocate Atag at 0x%lX (%r)\n",AtagStartAddress,Status));
-    Status = gBS->AllocatePages (AllocateAnyPages, EfiBootServicesData, EFI_SIZE_TO_PAGES(ATAG_MAX_SIZE), &AtagStartAddress);
-    ASSERT_EFI_ERROR(Status);
-  }
-
-  // Ready to setup the atag list
-  mLinuxKernelCurrentAtag = (LINUX_ATAG*)(UINTN)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*)ResourceLink;
-    DEBUG((EFI_D_INFO,"- [0x%08X,0x%08X]\n",(UINT32)Resource->PhysicalStart,(UINT32)Resource->PhysicalStart+(UINT32)Resource->ResourceLength));
-    SetupMemTag( (UINT32)Resource->PhysicalStart, (UINT32)Resource->ResourceLength );
-    ResourceLink = ResourceLink->ForwardLink;
-  }
-
-  // CommandLine setting root device
-  if (CommandLineString) {
-    SetupCmdlineTag (CommandLineString);
-  }
-
-  if (InitrdImageSize > 0 && InitrdImage != 0) {
-    mLinuxKernelCurrentAtag->header.size = tag_size(LINUX_ATAG_INITRD2);
-    mLinuxKernelCurrentAtag->header.type = ATAG_INITRD2;
-
-    mLinuxKernelCurrentAtag->body.initrd2_tag.start = (UINT32)InitrdImage;
-    mLinuxKernelCurrentAtag->body.initrd2_tag.size = (UINT32)InitrdImageSize;
-
-    // Move pointer to next tag
-    mLinuxKernelCurrentAtag = next_tag_address(mLinuxKernelCurrentAtag);
-  }
-
-  // End of tags
-  SetupEndTag();
-
-  // Calculate atag list size
-  *AtagBase = (LINUX_ATAG*)(UINTN)AtagStartAddress;
-  *AtagSize = (UINT32)mLinuxKernelCurrentAtag - (UINT32)AtagStartAddress + 1;
-
-  return EFI_SUCCESS;
-}
-
+/** @file\r
+*\r
+*  Copyright (c) 2011-2012, ARM Limited. All rights reserved.\r
+*  \r
+*  This program and the accompanying materials                          \r
+*  are licensed and made available under the terms and conditions of the BSD License         \r
+*  which accompanies this distribution.  The full text of the license may be found at        \r
+*  http://opensource.org/licenses/bsd-license.php                                            \r
+*\r
+*  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
+*  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
+*\r
+**/\r
+\r
+#include "BdsInternal.h"\r
+#include "BdsLinuxLoader.h"\r
+\r
+// Point to the current ATAG\r
+STATIC LINUX_ATAG *mLinuxKernelCurrentAtag;\r
+\r
+STATIC\r
+VOID\r
+SetupCoreTag (\r
+  IN UINT32 PageSize\r
+  )\r
+{\r
+  mLinuxKernelCurrentAtag->header.size = tag_size(LINUX_ATAG_CORE);\r
+  mLinuxKernelCurrentAtag->header.type = ATAG_CORE;\r
+\r
+  mLinuxKernelCurrentAtag->body.core_tag.flags    = 1;            /* ensure read-only */\r
+  mLinuxKernelCurrentAtag->body.core_tag.pagesize = PageSize;     /* systems PageSize (4k) */\r
+  mLinuxKernelCurrentAtag->body.core_tag.rootdev  = 0;            /* zero root device (typically overridden from kernel command line )*/\r
+\r
+  // move pointer to next tag\r
+  mLinuxKernelCurrentAtag = next_tag_address(mLinuxKernelCurrentAtag);\r
+}\r
+\r
+STATIC\r
+VOID\r
+SetupMemTag (\r
+  IN UINTN StartAddress,\r
+  IN UINT32 Size\r
+  )\r
+{\r
+  mLinuxKernelCurrentAtag->header.size = tag_size(LINUX_ATAG_MEM);\r
+  mLinuxKernelCurrentAtag->header.type = ATAG_MEM;\r
+\r
+  mLinuxKernelCurrentAtag->body.mem_tag.start = StartAddress;    /* Start of memory chunk for AtagMem */\r
+  mLinuxKernelCurrentAtag->body.mem_tag.size  = Size;             /* Size of memory chunk for AtagMem */\r
+\r
+  // move pointer to next tag\r
+  mLinuxKernelCurrentAtag = next_tag_address(mLinuxKernelCurrentAtag);\r
+}\r
+\r
+STATIC\r
+VOID\r
+SetupCmdlineTag (\r
+  IN CONST CHAR8 *CmdLine\r
+  )\r
+{\r
+  UINT32 LineLength;\r
+\r
+  // Increment the line length by 1 to account for the null string terminator character\r
+  LineLength = AsciiStrLen(CmdLine) + 1;\r
+\r
+  /* Check for NULL strings.\r
+   * Do not insert a tag for an empty CommandLine, don't even modify the tag address pointer.\r
+   * Remember, you have at least one null string terminator character.\r
+   */\r
+  if(LineLength > 1) {\r
+    mLinuxKernelCurrentAtag->header.size = ((UINT32)sizeof(LINUX_ATAG_HEADER) + LineLength + (UINT32)3) >> 2;\r
+    mLinuxKernelCurrentAtag->header.type = ATAG_CMDLINE;\r
+\r
+    /* place CommandLine into tag */\r
+    AsciiStrCpy(mLinuxKernelCurrentAtag->body.cmdline_tag.cmdline, CmdLine);\r
+\r
+    // move pointer to next tag\r
+    mLinuxKernelCurrentAtag = next_tag_address(mLinuxKernelCurrentAtag);\r
+  }\r
+}\r
+\r
+STATIC\r
+VOID\r
+SetupInitrdTag (\r
+  IN UINT32 InitrdImage,\r
+  IN UINT32 InitrdImageSize\r
+  )\r
+{\r
+  mLinuxKernelCurrentAtag->header.size = tag_size(LINUX_ATAG_INITRD2);\r
+  mLinuxKernelCurrentAtag->header.type = ATAG_INITRD2;\r
+\r
+  mLinuxKernelCurrentAtag->body.initrd2_tag.start = InitrdImage;\r
+  mLinuxKernelCurrentAtag->body.initrd2_tag.size = InitrdImageSize;\r
+\r
+  // Move pointer to next tag\r
+  mLinuxKernelCurrentAtag = next_tag_address(mLinuxKernelCurrentAtag);\r
+}\r
+STATIC\r
+VOID\r
+SetupEndTag (\r
+  VOID\r
+  )\r
+{\r
+  // Empty tag ends list; this has zero length and no body\r
+  mLinuxKernelCurrentAtag->header.type = ATAG_NONE;\r
+  mLinuxKernelCurrentAtag->header.size = 0;\r
+\r
+  /* We can not calculate the next address by using the standard macro:\r
+   * Params = next_tag_address(Params);\r
+   * because it relies on the header.size, which here it is 0 (zero).\r
+   * The easiest way is to add the sizeof(mLinuxKernelCurrentAtag->header).\r
+   */\r
+  mLinuxKernelCurrentAtag = (LINUX_ATAG*)((UINT32)mLinuxKernelCurrentAtag + sizeof(mLinuxKernelCurrentAtag->header));\r
+}\r
+\r
+EFI_STATUS\r
+PrepareAtagList (\r
+  IN  CONST CHAR8*          CommandLineString,\r
+  IN  EFI_PHYSICAL_ADDRESS  InitrdImage,\r
+  IN  UINTN                 InitrdImageSize,\r
+  OUT EFI_PHYSICAL_ADDRESS  *AtagBase,\r
+  OUT UINT32                *AtagSize\r
+  )\r
+{\r
+  EFI_STATUS                  Status;\r
+  LIST_ENTRY                  *ResourceLink;\r
+  LIST_ENTRY                  ResourceList;\r
+  EFI_PHYSICAL_ADDRESS        AtagStartAddress;\r
+  BDS_SYSTEM_MEMORY_RESOURCE  *Resource;\r
+\r
+  AtagStartAddress = LINUX_ATAG_MAX_OFFSET;\r
+  Status = gBS->AllocatePages (AllocateMaxAddress, EfiBootServicesData, EFI_SIZE_TO_PAGES(ATAG_MAX_SIZE), &AtagStartAddress);\r
+  if (EFI_ERROR(Status)) {\r
+    DEBUG ((EFI_D_WARN, "Warning: Failed to allocate Atag at 0x%lX (%r). The Atag will be allocated somewhere else in System Memory.\n", AtagStartAddress, Status));\r
+    Status = gBS->AllocatePages (AllocateAnyPages, EfiBootServicesData, EFI_SIZE_TO_PAGES(ATAG_MAX_SIZE), &AtagStartAddress);\r
+    ASSERT_EFI_ERROR(Status);\r
+  }\r
+\r
+  // Ready to setup the atag list\r
+  mLinuxKernelCurrentAtag = (LINUX_ATAG*)(UINTN)AtagStartAddress;\r
+\r
+  // Standard core tag 4k PageSize\r
+  SetupCoreTag( (UINT32)SIZE_4KB );\r
+\r
+  // Physical memory setup\r
+  GetSystemMemoryResources (&ResourceList);\r
+  ResourceLink = ResourceList.ForwardLink;\r
+  while (ResourceLink != NULL && ResourceLink != &ResourceList) {\r
+    Resource = (BDS_SYSTEM_MEMORY_RESOURCE*)ResourceLink;\r
+    DEBUG((EFI_D_INFO,"- [0x%08X,0x%08X]\n",(UINT32)Resource->PhysicalStart,(UINT32)Resource->PhysicalStart+(UINT32)Resource->ResourceLength));\r
+    SetupMemTag( (UINT32)Resource->PhysicalStart, (UINT32)Resource->ResourceLength );\r
+    ResourceLink = ResourceLink->ForwardLink;\r
+  }\r
+\r
+  // CommandLine setting root device\r
+  if (CommandLineString) {\r
+    SetupCmdlineTag (CommandLineString);\r
+  }\r
+\r
+  if (InitrdImageSize > 0 && InitrdImage != 0) {\r
+    SetupInitrdTag ((UINT32)InitrdImage, (UINT32)InitrdImageSize);\r
+  }\r
+\r
+  // End of tags\r
+  SetupEndTag();\r
+\r
+  // Calculate atag list size\r
+  *AtagBase = AtagStartAddress;\r
+  *AtagSize = (UINT32)mLinuxKernelCurrentAtag - (UINT32)AtagStartAddress + 1;\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r