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