]> git.proxmox.com Git - mirror_edk2.git/blame - ArmPkg/Library/BdsLib/Arm/BdsLinuxAtag.c
ARM Packages: Removed trailing spaces
[mirror_edk2.git] / ArmPkg / Library / BdsLib / Arm / BdsLinuxAtag.c
CommitLineData
1e57a462 1/** @file\r
2*\r
3* Copyright (c) 2011-2012, ARM Limited. All rights reserved.\r
1e57a462 4*\r
3402aac7
RC
5* This program and the accompanying materials\r
6* are licensed and made available under the terms and conditions of the BSD License\r
7* which accompanies this distribution. The full text of the license may be found at\r
8* http://opensource.org/licenses/bsd-license.php\r
9*\r
10* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
1e57a462 12*\r
13**/\r
14\r
15#include "BdsInternal.h"\r
16#include "BdsLinuxLoader.h"\r
17\r
18// Point to the current ATAG\r
19STATIC LINUX_ATAG *mLinuxKernelCurrentAtag;\r
20\r
21STATIC\r
22VOID\r
23SetupCoreTag (\r
24 IN UINT32 PageSize\r
25 )\r
26{\r
27 mLinuxKernelCurrentAtag->header.size = tag_size(LINUX_ATAG_CORE);\r
28 mLinuxKernelCurrentAtag->header.type = ATAG_CORE;\r
29\r
30 mLinuxKernelCurrentAtag->body.core_tag.flags = 1; /* ensure read-only */\r
31 mLinuxKernelCurrentAtag->body.core_tag.pagesize = PageSize; /* systems PageSize (4k) */\r
32 mLinuxKernelCurrentAtag->body.core_tag.rootdev = 0; /* zero root device (typically overridden from kernel command line )*/\r
33\r
34 // move pointer to next tag\r
35 mLinuxKernelCurrentAtag = next_tag_address(mLinuxKernelCurrentAtag);\r
36}\r
37\r
38STATIC\r
39VOID\r
40SetupMemTag (\r
41 IN UINTN StartAddress,\r
42 IN UINT32 Size\r
43 )\r
44{\r
45 mLinuxKernelCurrentAtag->header.size = tag_size(LINUX_ATAG_MEM);\r
46 mLinuxKernelCurrentAtag->header.type = ATAG_MEM;\r
47\r
48 mLinuxKernelCurrentAtag->body.mem_tag.start = StartAddress; /* Start of memory chunk for AtagMem */\r
49 mLinuxKernelCurrentAtag->body.mem_tag.size = Size; /* Size of memory chunk for AtagMem */\r
50\r
51 // move pointer to next tag\r
52 mLinuxKernelCurrentAtag = next_tag_address(mLinuxKernelCurrentAtag);\r
53}\r
54\r
55STATIC\r
56VOID\r
57SetupCmdlineTag (\r
58 IN CONST CHAR8 *CmdLine\r
59 )\r
60{\r
61 UINT32 LineLength;\r
62\r
63 // Increment the line length by 1 to account for the null string terminator character\r
64 LineLength = AsciiStrLen(CmdLine) + 1;\r
65\r
66 /* Check for NULL strings.\r
67 * Do not insert a tag for an empty CommandLine, don't even modify the tag address pointer.\r
68 * Remember, you have at least one null string terminator character.\r
69 */\r
70 if(LineLength > 1) {\r
71 mLinuxKernelCurrentAtag->header.size = ((UINT32)sizeof(LINUX_ATAG_HEADER) + LineLength + (UINT32)3) >> 2;\r
72 mLinuxKernelCurrentAtag->header.type = ATAG_CMDLINE;\r
73\r
74 /* place CommandLine into tag */\r
75 AsciiStrCpy(mLinuxKernelCurrentAtag->body.cmdline_tag.cmdline, CmdLine);\r
76\r
77 // move pointer to next tag\r
78 mLinuxKernelCurrentAtag = next_tag_address(mLinuxKernelCurrentAtag);\r
79 }\r
80}\r
81\r
82STATIC\r
83VOID\r
84SetupInitrdTag (\r
85 IN UINT32 InitrdImage,\r
86 IN UINT32 InitrdImageSize\r
87 )\r
88{\r
89 mLinuxKernelCurrentAtag->header.size = tag_size(LINUX_ATAG_INITRD2);\r
90 mLinuxKernelCurrentAtag->header.type = ATAG_INITRD2;\r
91\r
92 mLinuxKernelCurrentAtag->body.initrd2_tag.start = InitrdImage;\r
93 mLinuxKernelCurrentAtag->body.initrd2_tag.size = InitrdImageSize;\r
94\r
95 // Move pointer to next tag\r
96 mLinuxKernelCurrentAtag = next_tag_address(mLinuxKernelCurrentAtag);\r
97}\r
98STATIC\r
99VOID\r
100SetupEndTag (\r
101 VOID\r
102 )\r
103{\r
104 // Empty tag ends list; this has zero length and no body\r
105 mLinuxKernelCurrentAtag->header.type = ATAG_NONE;\r
106 mLinuxKernelCurrentAtag->header.size = 0;\r
107\r
108 /* We can not calculate the next address by using the standard macro:\r
109 * Params = next_tag_address(Params);\r
110 * because it relies on the header.size, which here it is 0 (zero).\r
111 * The easiest way is to add the sizeof(mLinuxKernelCurrentAtag->header).\r
112 */\r
113 mLinuxKernelCurrentAtag = (LINUX_ATAG*)((UINT32)mLinuxKernelCurrentAtag + sizeof(mLinuxKernelCurrentAtag->header));\r
114}\r
115\r
116EFI_STATUS\r
117PrepareAtagList (\r
118 IN CONST CHAR8* CommandLineString,\r
119 IN EFI_PHYSICAL_ADDRESS InitrdImage,\r
120 IN UINTN InitrdImageSize,\r
121 OUT EFI_PHYSICAL_ADDRESS *AtagBase,\r
122 OUT UINT32 *AtagSize\r
123 )\r
124{\r
125 EFI_STATUS Status;\r
126 LIST_ENTRY *ResourceLink;\r
127 LIST_ENTRY ResourceList;\r
128 EFI_PHYSICAL_ADDRESS AtagStartAddress;\r
129 BDS_SYSTEM_MEMORY_RESOURCE *Resource;\r
130\r
131 AtagStartAddress = LINUX_ATAG_MAX_OFFSET;\r
132 Status = gBS->AllocatePages (AllocateMaxAddress, EfiBootServicesData, EFI_SIZE_TO_PAGES(ATAG_MAX_SIZE), &AtagStartAddress);\r
133 if (EFI_ERROR(Status)) {\r
134 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
135 Status = gBS->AllocatePages (AllocateAnyPages, EfiBootServicesData, EFI_SIZE_TO_PAGES(ATAG_MAX_SIZE), &AtagStartAddress);\r
136 ASSERT_EFI_ERROR(Status);\r
137 }\r
138\r
139 // Ready to setup the atag list\r
140 mLinuxKernelCurrentAtag = (LINUX_ATAG*)(UINTN)AtagStartAddress;\r
141\r
142 // Standard core tag 4k PageSize\r
143 SetupCoreTag( (UINT32)SIZE_4KB );\r
144\r
145 // Physical memory setup\r
146 GetSystemMemoryResources (&ResourceList);\r
147 ResourceLink = ResourceList.ForwardLink;\r
148 while (ResourceLink != NULL && ResourceLink != &ResourceList) {\r
149 Resource = (BDS_SYSTEM_MEMORY_RESOURCE*)ResourceLink;\r
150 DEBUG((EFI_D_INFO,"- [0x%08X,0x%08X]\n",(UINT32)Resource->PhysicalStart,(UINT32)Resource->PhysicalStart+(UINT32)Resource->ResourceLength));\r
151 SetupMemTag( (UINT32)Resource->PhysicalStart, (UINT32)Resource->ResourceLength );\r
152 ResourceLink = ResourceLink->ForwardLink;\r
153 }\r
154\r
155 // CommandLine setting root device\r
156 if (CommandLineString) {\r
157 SetupCmdlineTag (CommandLineString);\r
158 }\r
159\r
160 if (InitrdImageSize > 0 && InitrdImage != 0) {\r
161 SetupInitrdTag ((UINT32)InitrdImage, (UINT32)InitrdImageSize);\r
162 }\r
163\r
164 // End of tags\r
165 SetupEndTag();\r
166\r
167 // Calculate atag list size\r
168 *AtagBase = AtagStartAddress;\r
169 *AtagSize = (UINT32)mLinuxKernelCurrentAtag - (UINT32)AtagStartAddress + 1;\r
170\r
171 return EFI_SUCCESS;\r
172}\r
173\r