b334c3bbf34eeabc0c8792fbeb2ab261d2b3a42a
[reactos.git] / reactos / boot / freeldr / freeldr / arch / arm / macharm.c
1 /*
2 * PROJECT: ReactOS Boot Loader
3 * LICENSE: BSD - See COPYING.ARM in the top level directory
4 * FILE: boot/freeldr/arch/arm/marcharm.c
5 * PURPOSE: Provides abstraction between the ARM Boot Loader and FreeLDR
6 * PROGRAMMERS: ReactOS Portable Systems Group
7 */
8
9 /* INCLUDES *******************************************************************/
10
11 #include <freeldr.h>
12
13 /* GLOBALS ********************************************************************/
14
15 UCHAR BootStack[0x4000];
16 PUCHAR BootStackEnd = &BootStack[0x3FFF];
17 PARM_BOARD_CONFIGURATION_BLOCK ArmBoardBlock;
18 ULONG BootDrive, BootPartition;
19 VOID ArmPrepareForReactOS(IN BOOLEAN Setup);
20 ADDRESS_RANGE ArmBoardMemoryMap[16];
21 ULONG ArmBoardMemoryMapRangeCount;
22
23 /* FUNCTIONS ******************************************************************/
24
25 VOID
26 ArmInit(IN PARM_BOARD_CONFIGURATION_BLOCK BootContext)
27 {
28 ULONG i;
29
30 //
31 // Remember the pointer
32 //
33 ArmBoardBlock = BootContext;
34
35 //
36 // Let's make sure we understand the boot-loader
37 //
38 ASSERT(ArmBoardBlock->MajorVersion == ARM_BOARD_CONFIGURATION_MAJOR_VERSION);
39 ASSERT(ArmBoardBlock->MinorVersion == ARM_BOARD_CONFIGURATION_MINOR_VERSION);
40
41 //
42 // This should probably go away once we support more boards
43 //
44 ASSERT((ArmBoardBlock->BoardType == MACH_TYPE_FEROCEON) ||
45 (ArmBoardBlock->BoardType == MACH_TYPE_VERSATILE_PB) ||
46 (ArmBoardBlock->BoardType == MACH_TYPE_OMAP3_BEAGLE));
47
48 //
49 // Save data required for memory initialization
50 //
51 ArmBoardMemoryMapRangeCount = ArmBoardBlock->MemoryMapEntryCount;
52 ASSERT(ArmBoardMemoryMapRangeCount != 0);
53 ASSERT(ArmBoardMemoryMapRangeCount < 16);
54 for (i = 0; i < ArmBoardMemoryMapRangeCount; i++)
55 {
56 //
57 // Copy each entry
58 //
59 RtlCopyMemory(&ArmBoardMemoryMap[i],
60 &ArmBoardBlock->MemoryMap[i],
61 sizeof(ADDRESS_RANGE));
62 }
63
64 //
65 // Call FreeLDR's portable entrypoint with our command-line
66 //
67 BootMain(ArmBoardBlock->CommandLine);
68 }
69
70 BOOLEAN
71 ArmDiskGetDriveGeometry(IN ULONG DriveNumber,
72 OUT PGEOMETRY Geometry)
73 {
74 ASSERT(gRamDiskBase == NULL);
75 return FALSE;
76 }
77
78 BOOLEAN
79 ArmDiskReadLogicalSectors(IN ULONG DriveNumber,
80 IN ULONGLONG SectorNumber,
81 IN ULONG SectorCount,
82 IN PVOID Buffer)
83 {
84 ASSERT(gRamDiskBase == NULL);
85 return FALSE;
86 }
87
88 ULONG
89 ArmDiskGetCacheableBlockCount(IN ULONG DriveNumber)
90 {
91 ASSERT(gRamDiskBase == NULL);
92 return FALSE;
93 }
94
95 PCONFIGURATION_COMPONENT_DATA
96 ArmHwDetect(VOID)
97 {
98 PCONFIGURATION_COMPONENT_DATA RootNode;
99
100 //
101 // Create the root node
102 //
103 FldrCreateSystemKey(&RootNode);
104
105 //
106 // Write null component information
107 //
108 FldrSetComponentInformation(RootNode,
109 0x0,
110 0x0,
111 0xFFFFFFFF);
112
113 //
114 // TODO:
115 // There's no such thing as "PnP" on embedded hardware.
116 // The boot loader will send us a device tree, similar to ACPI
117 // or OpenFirmware device trees, and we will convert it to ARC.
118 //
119
120 //
121 // Return the root node
122 //
123 return RootNode;
124 }
125
126 ULONG
127 ArmMemGetMemoryMap(OUT PBIOS_MEMORY_MAP BiosMemoryMap,
128 IN ULONG MaxMemoryMapSize)
129 {
130 //
131 // Return whatever the board returned to us (CS0 Base + Size and FLASH0)
132 //
133 RtlCopyMemory(BiosMemoryMap,
134 ArmBoardBlock->MemoryMap,
135 ArmBoardBlock->MemoryMapEntryCount * sizeof(BIOS_MEMORY_MAP));
136 return ArmBoardBlock->MemoryMapEntryCount;
137 }
138
139 VOID
140 MachInit(IN PCCH CommandLine)
141 {
142 //
143 // Setup board-specific ARM routines
144 //
145 switch (ArmBoardBlock->BoardType)
146 {
147 //
148 // Check for Feroceon-base boards
149 //
150 case MACH_TYPE_FEROCEON:
151
152 //
153 // These boards use a UART16550. Set us up for 115200 bps
154 //
155 ArmFeroSerialInit(115200);
156 MachVtbl.ConsPutChar = ArmFeroPutChar;
157 MachVtbl.ConsKbHit = ArmFeroKbHit;
158 MachVtbl.ConsGetCh = ArmFeroGetCh;
159 break;
160
161 //
162 // Check for ARM Versatile PB boards
163 //
164 case MACH_TYPE_VERSATILE_PB:
165
166 //
167 // These boards use a PrimeCell UART (PL011)
168 //
169 ArmVersaSerialInit(115200);
170 MachVtbl.ConsPutChar = ArmVersaPutChar;
171 MachVtbl.ConsKbHit = ArmVersaKbHit;
172 MachVtbl.ConsGetCh = ArmVersaGetCh;
173 break;
174
175 //
176 // Check for TI OMAP3 boards
177 // For now that means only Beagle, but ZOOM and others should be ok too
178 //
179 case MACH_TYPE_OMAP3_BEAGLE:
180
181 //
182 // These boards use a UART16550
183 //
184 ArmOmap3SerialInit(115200);
185 MachVtbl.ConsPutChar = ArmOmap3PutChar;
186 MachVtbl.ConsKbHit = ArmOmap3KbHit;
187 MachVtbl.ConsGetCh = ArmOmap3GetCh;
188 break;
189
190 default:
191 ASSERT(FALSE);
192 }
193
194 //
195 // Setup generic ARM routines for all boards
196 //
197 MachVtbl.PrepareForReactOS = ArmPrepareForReactOS;
198 MachVtbl.GetMemoryMap = ArmMemGetMemoryMap;
199 MachVtbl.HwDetect = ArmHwDetect;
200
201 //
202 // Setup disk I/O routines, switch to ramdisk ones for non-NAND boot
203 //
204 MachVtbl.DiskReadLogicalSectors = ArmDiskReadLogicalSectors;
205 MachVtbl.DiskGetDriveGeometry = ArmDiskGetDriveGeometry;
206 MachVtbl.DiskGetCacheableBlockCount = ArmDiskGetCacheableBlockCount;
207 RamDiskSwitchFromBios();
208
209 //
210 // Now set default disk handling routines -- we don't need to override
211 //
212 MachVtbl.DiskGetBootVolume = DiskGetBootVolume;
213 MachVtbl.DiskGetSystemVolume = DiskGetSystemVolume;
214 MachVtbl.DiskGetBootPath = DiskGetBootPath;
215 MachVtbl.DiskGetBootDevice = DiskGetBootDevice;
216 MachVtbl.DiskBootingFromFloppy = DiskBootingFromFloppy;
217 MachVtbl.DiskNormalizeSystemPath = DiskNormalizeSystemPath;
218 MachVtbl.DiskGetPartitionEntry = DiskGetPartitionEntry;
219
220 //
221 // We can now print to the console
222 //
223 TuiPrintf("%s for ARM\n", GetFreeLoaderVersionString());
224 TuiPrintf("Bootargs: %s\n", CommandLine);
225 }