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