2010-02-01 18:33:24 +00:00
|
|
|
/*
|
|
|
|
* PROJECT: ReactOS Boot Loader
|
|
|
|
* LICENSE: BSD - See COPYING.ARM in the top level directory
|
|
|
|
* FILE: boot/armllb/os/loader.c
|
|
|
|
* PURPOSE: OS Loader Code for LLB
|
|
|
|
* PROGRAMMERS: ReactOS Portable Systems Group
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "precomp.h"
|
|
|
|
|
|
|
|
BIOS_MEMORY_MAP MemoryMap[32];
|
|
|
|
ARM_BOARD_CONFIGURATION_BLOCK ArmBlock;
|
2010-02-02 00:14:14 +00:00
|
|
|
POSLOADER_INIT LoaderInit;
|
|
|
|
|
2010-02-01 18:33:24 +00:00
|
|
|
VOID
|
|
|
|
NTAPI
|
2010-02-02 00:14:14 +00:00
|
|
|
LlbAllocateMemoryEntry(IN BIOS_MEMORY_TYPE Type,
|
|
|
|
IN ULONG BaseAddress,
|
|
|
|
IN ULONG Length)
|
2010-02-01 18:33:24 +00:00
|
|
|
{
|
|
|
|
PBIOS_MEMORY_MAP Entry;
|
|
|
|
|
|
|
|
/* Get the next memory entry */
|
|
|
|
Entry = MemoryMap;
|
|
|
|
while (Entry->Length) Entry++;
|
|
|
|
|
|
|
|
/* Fill it out */
|
|
|
|
Entry->Length = Length;
|
|
|
|
Entry->BaseAddress = BaseAddress;
|
|
|
|
Entry->Type = Type;
|
|
|
|
|
|
|
|
/* Block count */
|
|
|
|
ArmBlock.MemoryMapEntryCount++;
|
|
|
|
}
|
|
|
|
|
|
|
|
VOID
|
|
|
|
NTAPI
|
|
|
|
LlbSetCommandLine(IN PCHAR CommandLine)
|
|
|
|
{
|
|
|
|
/* Copy the command line in the ARM block */
|
|
|
|
strcpy(ArmBlock.CommandLine, CommandLine);
|
|
|
|
}
|
|
|
|
|
|
|
|
VOID
|
|
|
|
NTAPI
|
|
|
|
LlbBuildArmBlock(VOID)
|
|
|
|
{
|
|
|
|
/* Write version number */
|
|
|
|
ArmBlock.MajorVersion = ARM_BOARD_CONFIGURATION_MAJOR_VERSION;
|
|
|
|
ArmBlock.MinorVersion = ARM_BOARD_CONFIGURATION_MINOR_VERSION;
|
|
|
|
|
|
|
|
/* Get arch type */
|
|
|
|
ArmBlock.BoardType = LlbHwGetBoardType();
|
|
|
|
|
|
|
|
/* Get peripheral clock rate */
|
|
|
|
ArmBlock.ClockRate = LlbHwGetPClk();
|
|
|
|
|
|
|
|
/* Get timer and serial port base addresses */
|
|
|
|
ArmBlock.TimerRegisterBase = LlbHwGetTmr0Base();
|
|
|
|
ArmBlock.UartRegisterBase = LlbHwGetUartBase(LlbHwGetSerialUart());
|
|
|
|
|
2010-02-02 00:14:14 +00:00
|
|
|
/* Debug */
|
2010-02-03 03:14:59 +00:00
|
|
|
DbgPrint("Machine Identifier: %lx\nPCLK: %d\nTIMER 0: %p\nSERIAL UART: %p\n",
|
|
|
|
ArmBlock.BoardType,
|
|
|
|
ArmBlock.ClockRate,
|
|
|
|
ArmBlock.TimerRegisterBase,
|
|
|
|
ArmBlock.UartRegisterBase);
|
2010-02-02 00:14:14 +00:00
|
|
|
|
2010-02-01 18:33:24 +00:00
|
|
|
/* Now load the memory map */
|
|
|
|
ArmBlock.MemoryMap = MemoryMap;
|
2010-02-02 17:21:19 +00:00
|
|
|
|
|
|
|
/* Write firmware callbacks */
|
|
|
|
ArmBlock.ConsPutChar = LlbFwPutChar;
|
|
|
|
ArmBlock.ConsKbHit = LlbFwKbHit;
|
|
|
|
ArmBlock.ConsGetCh = LlbFwGetCh;
|
2010-02-04 05:43:02 +00:00
|
|
|
ArmBlock.VideoClearScreen = LlbFwVideoClearScreen;
|
|
|
|
ArmBlock.VideoSetDisplayMode = LlbFwVideoSetDisplayMode;
|
|
|
|
ArmBlock.VideoGetDisplaySize = LlbFwVideoGetDisplaySize;
|
|
|
|
ArmBlock.VideoPutChar = LlbFwVideoPutChar;
|
2010-02-04 06:44:06 +00:00
|
|
|
ArmBlock.GetTime = LlbFwGetTime;
|
2010-02-01 18:33:24 +00:00
|
|
|
}
|
|
|
|
|
2010-02-02 00:14:14 +00:00
|
|
|
VOID
|
|
|
|
NTAPI
|
|
|
|
LlbBuildMemoryMap(VOID)
|
|
|
|
{
|
|
|
|
/* Zero out the memory map */
|
|
|
|
memset(MemoryMap, 0, sizeof(MemoryMap));
|
|
|
|
|
2010-02-03 03:14:59 +00:00
|
|
|
/* Call the hardware-specific function for hardware-defined regions */
|
2010-02-02 00:14:14 +00:00
|
|
|
LlbHwBuildMemoryMap(MemoryMap);
|
|
|
|
}
|
|
|
|
|
2010-11-23 17:14:41 +00:00
|
|
|
//
|
|
|
|
// Should go to hwdev.c
|
|
|
|
//
|
|
|
|
POSLOADER_INIT
|
|
|
|
NTAPI
|
|
|
|
LlbHwLoadOsLoaderFromRam(VOID)
|
|
|
|
{
|
|
|
|
ULONG Base, RootFs, Size;
|
|
|
|
PCHAR Offset;
|
|
|
|
CHAR CommandLine[64];
|
|
|
|
|
|
|
|
/* On versatile we load the RAMDISK with initrd */
|
|
|
|
LlbEnvGetRamDiskInformation(&RootFs, &Size);
|
|
|
|
DbgPrint("Root fs: %lx, size: %lx\n", RootFs, Size);
|
|
|
|
|
|
|
|
/* The OS Loader is at 0x20000, always */
|
|
|
|
Base = 0x20000;
|
|
|
|
|
|
|
|
/* Read image offset */
|
|
|
|
Offset = LlbEnvRead("rdoffset");
|
|
|
|
|
|
|
|
/* Set parameters for the OS loader */
|
|
|
|
snprintf(CommandLine,
|
|
|
|
sizeof(CommandLine),
|
|
|
|
"rdbase=0x%x rdsize=0x%x rdoffset=%s",
|
|
|
|
RootFs, Size, Offset);
|
|
|
|
LlbSetCommandLine(CommandLine);
|
|
|
|
|
|
|
|
/* Return the OS loader base address */
|
|
|
|
return (POSLOADER_INIT)Base;
|
|
|
|
}
|
|
|
|
|
2010-02-02 00:14:14 +00:00
|
|
|
VOID
|
|
|
|
NTAPI
|
|
|
|
LlbLoadOsLoader(VOID)
|
|
|
|
{
|
|
|
|
PCHAR BootDevice;
|
|
|
|
|
|
|
|
/* Read the current boot device */
|
2010-02-02 17:21:19 +00:00
|
|
|
BootDevice = LlbEnvRead("boot-device");
|
2010-02-02 00:14:14 +00:00
|
|
|
printf("Loading OS Loader from: %s...\n", BootDevice);
|
|
|
|
if (!strcmp(BootDevice, "NAND"))
|
|
|
|
{
|
|
|
|
// todo
|
|
|
|
}
|
|
|
|
else if (!strcmp(BootDevice, "RAMDISK"))
|
|
|
|
{
|
|
|
|
/* Call the hardware-specific function */
|
|
|
|
LoaderInit = LlbHwLoadOsLoaderFromRam();
|
|
|
|
}
|
|
|
|
else if (!strcmp(BootDevice, "MMC") ||
|
|
|
|
!strcmp(BootDevice, "SD"))
|
|
|
|
{
|
|
|
|
//todo
|
|
|
|
}
|
|
|
|
else if (!strcmp(BootDevice, "HDD"))
|
|
|
|
{
|
|
|
|
//todo
|
|
|
|
}
|
2010-11-23 17:14:41 +00:00
|
|
|
|
|
|
|
LoaderInit = (PVOID)0x80000000;
|
|
|
|
#ifdef _ZOOM2_ // need something better than this...
|
|
|
|
LoaderInit = (PVOID)0x81070000;
|
|
|
|
#endif
|
2010-02-02 17:21:19 +00:00
|
|
|
printf("OS Loader loaded at 0x%p...JUMP!\n\n\n\n\n", LoaderInit);
|
2010-02-02 00:14:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
VOID
|
|
|
|
NTAPI
|
2010-02-03 23:17:16 +00:00
|
|
|
LlbBoot(VOID)
|
2010-02-02 00:14:14 +00:00
|
|
|
{
|
|
|
|
/* Setup the ARM block */
|
|
|
|
LlbBuildArmBlock();
|
|
|
|
|
|
|
|
/* Build the memory map */
|
|
|
|
LlbBuildMemoryMap();
|
|
|
|
|
|
|
|
/* Load the OS loader */
|
|
|
|
LlbLoadOsLoader();
|
2010-11-23 17:14:41 +00:00
|
|
|
|
2010-02-02 00:14:14 +00:00
|
|
|
/* Jump to the OS Loader (FreeLDR in this case) */
|
|
|
|
LoaderInit(&ArmBlock);
|
|
|
|
}
|
|
|
|
|
2010-02-01 18:33:24 +00:00
|
|
|
/* EOF */
|