]>
Commit | Line | Data |
---|---|---|
23b01c83 RC |
1 | /** @file\r |
2 | *\r | |
3 | * Copyright (c) 2011-2015, ARM Limited. All rights reserved.\r | |
4 | *\r | |
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 | |
12 | *\r | |
13 | **/\r | |
14 | \r | |
15 | #include "LinuxAtag.h"\r | |
16 | #include "LinuxLoader.h"\r | |
17 | \r | |
18 | // Point to the current ATAG\r | |
19 | STATIC LINUX_ATAG *mLinuxKernelCurrentAtag;\r | |
20 | \r | |
21 | STATIC\r | |
22 | VOID\r | |
23 | SetupCoreTag (\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 | |
38 | STATIC\r | |
39 | VOID\r | |
40 | SetupMemTag (\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 | |
55 | STATIC\r | |
56 | VOID\r | |
57 | SetupCmdlineTag (\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 | |
82 | STATIC\r | |
83 | VOID\r | |
84 | SetupInitrdTag (\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 | |
98 | STATIC\r | |
99 | VOID\r | |
100 | SetupEndTag (\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 | |
116 | EFI_STATUS\r | |
117 | PrepareAtagList (\r | |
118 | IN EFI_PHYSICAL_ADDRESS SystemMemoryBase,\r | |
119 | IN CONST CHAR8* CommandLineString,\r | |
120 | IN EFI_PHYSICAL_ADDRESS InitrdImage,\r | |
121 | IN UINTN InitrdImageSize,\r | |
122 | OUT EFI_PHYSICAL_ADDRESS *AtagBase,\r | |
123 | OUT UINT32 *AtagSize\r | |
124 | )\r | |
125 | {\r | |
126 | EFI_STATUS Status;\r | |
127 | LIST_ENTRY *ResourceLink;\r | |
128 | LIST_ENTRY ResourceList;\r | |
129 | EFI_PHYSICAL_ADDRESS AtagStartAddress;\r | |
130 | SYSTEM_MEMORY_RESOURCE *Resource;\r | |
131 | \r | |
132 | AtagStartAddress = LINUX_ATAG_MAX_OFFSET;\r | |
133 | Status = gBS->AllocatePages (AllocateMaxAddress, EfiBootServicesData, EFI_SIZE_TO_PAGES (ATAG_MAX_SIZE), &AtagStartAddress);\r | |
134 | if (EFI_ERROR (Status)) {\r | |
135 | 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 | |
136 | Status = gBS->AllocatePages (AllocateAnyPages, EfiBootServicesData, EFI_SIZE_TO_PAGES (ATAG_MAX_SIZE), &AtagStartAddress);\r | |
137 | if (EFI_ERROR (Status)) {\r | |
138 | return Status;\r | |
139 | }\r | |
140 | }\r | |
141 | \r | |
142 | // Ready to setup the atag list\r | |
143 | mLinuxKernelCurrentAtag = (LINUX_ATAG*)(UINTN)AtagStartAddress;\r | |
144 | \r | |
145 | // Standard core tag 4k PageSize\r | |
146 | SetupCoreTag ( (UINT32)SIZE_4KB );\r | |
147 | \r | |
148 | // Physical memory setup\r | |
149 | GetSystemMemoryResources (&ResourceList);\r | |
150 | ResourceLink = ResourceList.ForwardLink;\r | |
151 | while (ResourceLink != NULL && ResourceLink != &ResourceList) {\r | |
152 | Resource = (SYSTEM_MEMORY_RESOURCE*)ResourceLink;\r | |
153 | DEBUG ((EFI_D_INFO, "- [0x%08X,0x%08X]\n",\r | |
154 | (UINT32)Resource->PhysicalStart,\r | |
155 | (UINT32)Resource->PhysicalStart + (UINT32)Resource->ResourceLength));\r | |
156 | SetupMemTag ((UINT32)Resource->PhysicalStart, (UINT32)Resource->ResourceLength );\r | |
157 | ResourceLink = ResourceLink->ForwardLink;\r | |
158 | }\r | |
159 | \r | |
160 | // CommandLine setting root device\r | |
161 | if (CommandLineString) {\r | |
162 | SetupCmdlineTag (CommandLineString);\r | |
163 | }\r | |
164 | \r | |
165 | if (InitrdImageSize > 0 && InitrdImage != 0) {\r | |
166 | SetupInitrdTag ((UINT32)InitrdImage, (UINT32)InitrdImageSize);\r | |
167 | }\r | |
168 | \r | |
169 | // End of tags\r | |
170 | SetupEndTag ();\r | |
171 | \r | |
172 | // Calculate atag list size\r | |
173 | *AtagBase = AtagStartAddress;\r | |
174 | *AtagSize = (UINT32)mLinuxKernelCurrentAtag - (UINT32)AtagStartAddress + 1;\r | |
175 | \r | |
176 | return EFI_SUCCESS;\r | |
177 | }\r |