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