1*c2c66affSColin Finck /*
2*c2c66affSColin Finck * PROJECT: ReactOS Boot Loader
3*c2c66affSColin Finck * LICENSE: BSD - See COPYING.ARM in the top level directory
4*c2c66affSColin Finck * FILE: boot/armllb/envir.c
5*c2c66affSColin Finck * PURPOSE: LLB Environment Variable Routines
6*c2c66affSColin Finck * PROGRAMMERS: ReactOS Portable Systems Group
7*c2c66affSColin Finck */
8*c2c66affSColin Finck
9*c2c66affSColin Finck #include "precomp.h"
10*c2c66affSColin Finck
11*c2c66affSColin Finck ULONG LlbEnvHwPageSize;
12*c2c66affSColin Finck ULONG LlbEnvHwMemStart = 0;
13*c2c66affSColin Finck ULONG LlbEnvHwMemSize = 0;
14*c2c66affSColin Finck ULONG LlbEnvRamDiskStart = 0;
15*c2c66affSColin Finck ULONG LlbEnvRamDiskSize = 0;
16*c2c66affSColin Finck ULONG LlbEnvHwRevision;
17*c2c66affSColin Finck CHAR LlbEnvCmdLine[256];
18*c2c66affSColin Finck CHAR LlbValueData[32];
19*c2c66affSColin Finck
20*c2c66affSColin Finck VOID
21*c2c66affSColin Finck NTAPI
LlbEnvParseArguments(IN PATAG Arguments)22*c2c66affSColin Finck LlbEnvParseArguments(IN PATAG Arguments)
23*c2c66affSColin Finck {
24*c2c66affSColin Finck PATAG Atag;
25*c2c66affSColin Finck
26*c2c66affSColin Finck /* Parse the ATAGs */
27*c2c66affSColin Finck Atag = Arguments;
28*c2c66affSColin Finck while (Atag->Hdr.Size)
29*c2c66affSColin Finck {
30*c2c66affSColin Finck /* Check tag type */
31*c2c66affSColin Finck switch (Atag->Hdr.Tag)
32*c2c66affSColin Finck {
33*c2c66affSColin Finck case ATAG_CORE:
34*c2c66affSColin Finck
35*c2c66affSColin Finck /* Save page size */
36*c2c66affSColin Finck LlbEnvHwPageSize = Atag->u.Core.PageSize;
37*c2c66affSColin Finck break;
38*c2c66affSColin Finck
39*c2c66affSColin Finck case ATAG_REVISION:
40*c2c66affSColin Finck
41*c2c66affSColin Finck /* Save page size */
42*c2c66affSColin Finck LlbEnvHwRevision = Atag->u.Revision.Rev;
43*c2c66affSColin Finck break;
44*c2c66affSColin Finck
45*c2c66affSColin Finck case ATAG_MEM:
46*c2c66affSColin Finck
47*c2c66affSColin Finck /* Save RAM start and size */
48*c2c66affSColin Finck if (!LlbEnvHwMemStart) LlbEnvHwMemStart = Atag->u.Mem.Start;
49*c2c66affSColin Finck LlbEnvHwMemSize += Atag->u.Mem.Size;
50*c2c66affSColin Finck break;
51*c2c66affSColin Finck
52*c2c66affSColin Finck case ATAG_INITRD2:
53*c2c66affSColin Finck
54*c2c66affSColin Finck /* Save RAMDISK start and size */
55*c2c66affSColin Finck LlbEnvRamDiskStart = Atag->u.InitRd2.Start;
56*c2c66affSColin Finck LlbEnvRamDiskSize = Atag->u.InitRd2.Size;
57*c2c66affSColin Finck
58*c2c66affSColin Finck #ifdef _BEAGLE_
59*c2c66affSColin Finck /* Make sure it's 16MB-aligned */
60*c2c66affSColin Finck LlbEnvRamDiskSize = (LlbEnvRamDiskSize + (16 * 1024 * 1024) - 1)
61*c2c66affSColin Finck &~ ((16 * 1024 * 1024) - 1);
62*c2c66affSColin Finck
63*c2c66affSColin Finck /* The RAMDISK actually starts 16MB later */
64*c2c66affSColin Finck LlbEnvRamDiskStart += 16 * 1024 * 1024;
65*c2c66affSColin Finck LlbEnvRamDiskSize -= 16 * 1024 * 1024;
66*c2c66affSColin Finck #endif
67*c2c66affSColin Finck break;
68*c2c66affSColin Finck
69*c2c66affSColin Finck case ATAG_CMDLINE:
70*c2c66affSColin Finck
71*c2c66affSColin Finck /* Save command line */
72*c2c66affSColin Finck strncpy(LlbEnvCmdLine,
73*c2c66affSColin Finck Atag->u.CmdLine.CmdLine,
74*c2c66affSColin Finck Atag->Hdr.Size * sizeof(ULONG));
75*c2c66affSColin Finck break;
76*c2c66affSColin Finck
77*c2c66affSColin Finck /* Nothing left to handle */
78*c2c66affSColin Finck case ATAG_NONE:
79*c2c66affSColin Finck default:
80*c2c66affSColin Finck break;
81*c2c66affSColin Finck }
82*c2c66affSColin Finck
83*c2c66affSColin Finck /* Next tag */
84*c2c66affSColin Finck Atag = (PATAG)((PULONG)Atag + Atag->Hdr.Size);
85*c2c66affSColin Finck }
86*c2c66affSColin Finck
87*c2c66affSColin Finck /* For debugging */
88*c2c66affSColin Finck DbgPrint("[BOOTROM] Board Revision: %lx PageSize: %dKB RAM: %dMB CMDLINE: %s\n"
89*c2c66affSColin Finck "[RAMDISK] Base: %lx Size: %dMB\n",
90*c2c66affSColin Finck LlbEnvHwRevision,
91*c2c66affSColin Finck LlbEnvHwPageSize / 1024, LlbEnvHwMemSize / 1024 / 1024, LlbEnvCmdLine,
92*c2c66affSColin Finck LlbEnvRamDiskStart, LlbEnvRamDiskSize / 1024 / 1024);
93*c2c66affSColin Finck }
94*c2c66affSColin Finck
95*c2c66affSColin Finck VOID
96*c2c66affSColin Finck NTAPI
LlbEnvGetMemoryInformation(IN PULONG Base,IN PULONG Size)97*c2c66affSColin Finck LlbEnvGetMemoryInformation(IN PULONG Base,
98*c2c66affSColin Finck IN PULONG Size)
99*c2c66affSColin Finck {
100*c2c66affSColin Finck /* Return RAM information */
101*c2c66affSColin Finck *Base = LlbEnvHwMemStart;
102*c2c66affSColin Finck *Size = LlbEnvHwMemSize;
103*c2c66affSColin Finck }
104*c2c66affSColin Finck
105*c2c66affSColin Finck BOOLEAN
106*c2c66affSColin Finck NTAPI
LlbEnvGetRamDiskInformation(IN PULONG Base,IN PULONG Size)107*c2c66affSColin Finck LlbEnvGetRamDiskInformation(IN PULONG Base,
108*c2c66affSColin Finck IN PULONG Size)
109*c2c66affSColin Finck {
110*c2c66affSColin Finck /* Do we have a ramdisk? */
111*c2c66affSColin Finck if (LlbEnvRamDiskSize == 0)
112*c2c66affSColin Finck {
113*c2c66affSColin Finck /* No */
114*c2c66affSColin Finck *Base = 0;
115*c2c66affSColin Finck *Size = 0;
116*c2c66affSColin Finck return FALSE;
117*c2c66affSColin Finck }
118*c2c66affSColin Finck
119*c2c66affSColin Finck /* Return ramdisk information */
120*c2c66affSColin Finck *Base = LlbEnvRamDiskStart;
121*c2c66affSColin Finck *Size = LlbEnvRamDiskSize;
122*c2c66affSColin Finck return TRUE;
123*c2c66affSColin Finck }
124*c2c66affSColin Finck
125*c2c66affSColin Finck PCHAR
126*c2c66affSColin Finck NTAPI
LlbEnvRead(IN PCHAR ValueName)127*c2c66affSColin Finck LlbEnvRead(IN PCHAR ValueName)
128*c2c66affSColin Finck {
129*c2c66affSColin Finck PCHAR ValuePointer;
130*c2c66affSColin Finck ULONG Length = 0;
131*c2c66affSColin Finck
132*c2c66affSColin Finck /* Search for the value name */
133*c2c66affSColin Finck ValuePointer = strstr(LlbEnvCmdLine, ValueName);
134*c2c66affSColin Finck if (ValuePointer)
135*c2c66affSColin Finck {
136*c2c66affSColin Finck /* Get the value data and its length */
137*c2c66affSColin Finck ValuePointer += strlen(ValueName) + 1;
138*c2c66affSColin Finck if (strchr(ValuePointer, ','))
139*c2c66affSColin Finck {
140*c2c66affSColin Finck /* Stop before next parameter */
141*c2c66affSColin Finck Length = strchr(ValuePointer, ',') - ValuePointer;
142*c2c66affSColin Finck }
143*c2c66affSColin Finck else
144*c2c66affSColin Finck {
145*c2c66affSColin Finck /* Stop before the string ends */
146*c2c66affSColin Finck Length = strlen(ValuePointer);
147*c2c66affSColin Finck }
148*c2c66affSColin Finck
149*c2c66affSColin Finck /* Copy it */
150*c2c66affSColin Finck strncpy(LlbValueData, ValuePointer, Length);
151*c2c66affSColin Finck }
152*c2c66affSColin Finck
153*c2c66affSColin Finck /* Terminate the data */
154*c2c66affSColin Finck LlbValueData[Length] = ANSI_NULL;
155*c2c66affSColin Finck
156*c2c66affSColin Finck /* Return the data */
157*c2c66affSColin Finck return LlbValueData;
158*c2c66affSColin Finck }
159*c2c66affSColin Finck
160*c2c66affSColin Finck /* EOF */
161*c2c66affSColin Finck
162