Difference between revisions of "User:Mna./FreeLoader, bootcd and bootrecords"
m (→OS_LOADING_METHOD) |
m (→OS_LOADING_METHOD) |
||
Line 51: | Line 51: | ||
===OS_LOADING_METHOD=== | ===OS_LOADING_METHOD=== | ||
− | '''BootMain'''() calls '''RunLoader'''() //bootmgr.c | + | '''BootMain'''() calls '''RunLoader'''() //''bootmgr.c'' |
'''RunLoader'''() calls '''LoadOperatingSystem'''() | '''RunLoader'''() calls '''LoadOperatingSystem'''() | ||
− | '''LoadOperatingSystem'''() lookups the OS_LOADING_METHOD and calls found loading method. | + | '''LoadOperatingSystem'''() lookups the OS_LOADING_METHOD and calls found ''loading method''. |
− | //VOID LoadOperatingSystem(IN OperatingSystemItem* OperatingSystem); //@\boot\freeldr\freeldr\bootmgr.c | + | //VOID LoadOperatingSystem(IN OperatingSystemItem* OperatingSystem); //''@\boot\freeldr\freeldr\bootmgr.c'' |
OS_LOADING_METHOD is a function pointer field in the table of OSLoadingMethods (in bootmgr.c) : | OS_LOADING_METHOD is a function pointer field in the table of OSLoadingMethods (in bootmgr.c) : | ||
Line 64: | Line 64: | ||
IN USHORT OperatingSystemVersion); | IN USHORT OperatingSystemVersion); | ||
</pre> | </pre> | ||
− | Most used ''loading methods'' are: | + | Most used ''loading methods'' are: LoadAndBootWindows(), LoadReactOSSetup() (@''\boot\freeldr\freeldr\windows\ {winldr.c,setupldr.c}'' ) |
− | Windows2003/LoadAndBootWindows() is a normal/default loading method, called by installed ReactOS. | + | * Windows2003/'''LoadAndBootWindows'''() is a normal/default loading method, called by installed ReactOS. |
− | ReactOSSetup/LoadReactOSSetup() is a method called by ReactOS bootcd installer ''usetup.exe''. | + | * ReactOSSetup/'''LoadReactOSSetup'''() is a method called by ReactOS bootcd installer ''usetup.exe''. |
List of all ReactOS loading methods: | List of all ReactOS loading methods: |
Revision as of 10:51, 25 March 2014
Contents
FreeLoader freeldr Architecture
FreeLoader Initialization
When FreeLoader gets control it
- saves the boot drive, passed to it in the DL register, partition number passed in the DH register
- sets up the stack,
- enables protected mode, and
- calls BootMain().
--based on quote from \boot\freeldr\notes.txt
Freeloader calls hierarchy
BootMain
VOID BootMain(LPSTR CmdLine) is layed in \boot\freeldr\freeldr\freeldr.c
It is main Freeldr function:
VOID BootMain(LPSTR CmdLine) { CmdLineParse(CmdLine); MachInit(CmdLine); FsInit(); DebugInit(); TRACE("BootMain() called.\n"); if (!UiInitialize(FALSE)) { UiMessageBoxCritical("Unable to initialize UI.\n"); goto quit; } if (!MmInitializeMemoryManager()) { UiMessageBoxCritical("Unable to initialize memory manager"); goto quit; } #ifdef _M_IX86 HalpInitializePciStubs(); HalpInitBusHandler(); #endif RunLoader(); quit: /* If we reach this point, something went wrong before, therefore reboot */ DiskStopFloppyMotor(); Reboot(); }
\boot\freeldr\freeldr\debug.c : DebugInit() Initializes Rs232 port, among other things.
OS_LOADING_METHOD
BootMain() calls RunLoader() //bootmgr.c
RunLoader() calls LoadOperatingSystem()
LoadOperatingSystem() lookups the OS_LOADING_METHOD and calls found loading method.
//VOID LoadOperatingSystem(IN OperatingSystemItem* OperatingSystem); //@\boot\freeldr\freeldr\bootmgr.c
OS_LOADING_METHOD is a function pointer field in the table of OSLoadingMethods (in bootmgr.c) :
typedef VOID (*OS_LOADING_METHOD)(IN OperatingSystemItem* OperatingSystem, IN USHORT OperatingSystemVersion);
Most used loading methods are: LoadAndBootWindows(), LoadReactOSSetup() (@\boot\freeldr\freeldr\windows\ {winldr.c,setupldr.c} )
- Windows2003/LoadAndBootWindows() is a normal/default loading method, called by installed ReactOS.
- ReactOSSetup/LoadReactOSSetup() is a method called by ReactOS bootcd installer usetup.exe.
List of all ReactOS loading methods:
{"ReactOSSetup", 0 , LoadReactOSSetup }, #ifdef _M_IX86 {"BootSector" , 0 , LoadAndBootBootSector}, {"Drive" , 0 , LoadAndBootDrive }, {"Partition" , 0 , LoadAndBootPartition }, {"Linux" , 0 , LoadAndBootLinux }, {"Windows" , 0 , LoadAndBootWindows }, {"WindowsNT40" , _WIN32_WINNT_NT4 , LoadAndBootWindows }, #endif {"Windows2003" , _WIN32_WINNT_WS03, LoadAndBootWindows },
DoOptionsMenu()
Options menu is activated by pressing F8 key.
RunLoader() checks keys and activates; calls DoOptionsMenu() (options.c)
FreeLoader loading
freeldr.sys is started by some type of BootRecord (BR): MBR, VBR, CD boot sector.
How bootcd installer usetup.exe writes MBR
When installing the ReactOS some component should write MBR/VBR to let freeldr.sys start at boot time.
This is done by usetup.exe :
- BootLoaderHarddiskMbrPage(&Ir) and its helpers:
- InstallMbrBootCodeToDisk()/2 and
- InstallVBRToPartition()/4.
- InstallFatBootcodeToPartition()/4
/** Side note related with bug in usetup.exe -bug writing MBR/VBR in some (frequent) cases: */ MBRInstallType: usetup.exe variable keeps Boot Record installation mode: 0-None (skip installation) 1-floppy MBR 2-Hdd MBR & VBR Files: /base/setup/reactos/ reactos.c : struct SetupData has field MBRInstallType /base/setup/usetup/interface/ usetup.c : use of MBRInstallType data.
usetup.exe : Page BOOT_LOADER_HARDDISK_MBR_PAGE is handled by: BootLoaderHarddiskMbrPage(&Ir); ( @/base/setup/usetup/interface/usetup.c)
BootLoaderHarddiskMbrPage function creates/writes MBR and VBR records.
/*** So the main errors are here: This function somehow is not called or the call/subcalls are failed. */
BootLoaderHarddiskMbrPage(&Ir); /* Step 1: Write the VBR */ InstallVBRToPartition()/4 if (!NT_SUCCESS(Status)) { MUIDisplayError(ERROR_WRITE_BOOT, Ir, POPUP_WAIT_ENTER); return QUIT_PAGE; } /* Step 2: Write the MBR */ writes bootcd '\loader\dosmbr.bin' into the MBR-place
InstallVBRToPartition/4 (@/base/setup/usetup/bootsup.c)
InstallVBRToPartition(): if (PartitionType is FAT_PartitionType ) return InstallFatBootcodeToPartition/4 else return STATUS_UNSUCCESSFUL;
FAT_PartitionType |
---|
PARTITION_FAT_12 |
PARTITION_FAT_16 |
PARTITION_HUGE |
PARTITION_XINT13 |
PARTITION_FAT32 |
PARTITION_FAT32_XINT13 |
InstallFatBootcodeToPartition()/4:
Copies original bootsector file to: %DEST%\bootsect.ros file.
FS ID/PartitionType | Freeloader boot sector binary original name | Source file name |
---|---|---|
FAT32: PARTITION_FAT32, PARTITION_FAT32_XINT13 | fat32.bin | fat32.S |
FAT16: else-branche of if | fat.bin | fat.S |
otherwise something is failed | - | - |
Legacy: Also there is a (pretty old,circa 2001) component in ReactOS source: installfreeldr (source: /boot/freeldr/install; binary: unknown). It writes FAT32 MBR only.
Boot record types (MBR, VBR, boot sectors, boot records of boot cd/livecd
TBW: InstallFatBootcodeToPartition-sourced + others (isoboot + ext2(?) etc)
Parameters boot record passes to FreeLdr: (fat32 & cdrom) (?fat16 doesn't pass DH?)
- boot drive number in DL register. It is BIOS drive number: 0x80 is the 1st drive, 0x81 - 2nd etc.
- boot partition number (0-based) in DH register (0 for CDROM)
bootcd and FreeLoader during 1st stage setup
- Note: ReactOS 1st stage setup run by usetup.exe shouldn't be confused with 1st stage loading of (ReactOS or GRUB) bootloader. These are totally different things.
- GRUB loading stages are: 1st stage: loading the MBR, 1.5 stage (...), 2nd stage: running modules from grub host filesystem, from (hdX,msdosY)/boot/grub/i386-pc/*.mod
usetup.exe
bootcd main installer module is a usetup.exe (@\base\setup\usetup\*)
usetup.exe is:
- nativecui module
- Uses libraries: zlib, inflib, ext2lib, vfatlib
BootOptions of bootcd
BootOptions of bootcd are: '/NOGUIBOOT /KDSERIAL /DEBUGPORT=COM1 /FIRSTCHANCE'
// (../../boot/freeldr/freeldr/windows/setupldr.c:219) trace: BootOptions: '/NOGUIBOOT /KDSERIAL /DEBUGPORT=COM1 /FIRSTCHANCE'
Is read by LoadReactOSSetup(): by setup method of ntoskrnl-loader; designed for usetup.exe.
Specified in: bootcd.ISO\reactos\txtsetup.sif : SetupData/[Dbg]OsLoadOptions :
{setupldr.c: InfFindFirstLine(InfHandle, "SetupData", "OsLoadOptions", &InfContext) or { {setupldr.c: InfFindFirstLine(InfHandle, "SetupData", "DbgOsLoadOptions", &InfContext) depending of DBG variable (DBG is now defined by default).
The source file copied to bootcd.ISO is: \boot\bootdata\txtsetup.sif
... [SetupData] DefaultPath = \ReactOS OsLoadOptions = "/NOGUIBOOT /NODEBUG" DbgOsLoadOptions = "/NOGUIBOOT /KDSERIAL /DEBUGPORT=COM1 /FIRSTCHANCE" ...
bootcd - Blue TextUI MessageBox "Opening hive file failed!"
Blue TextUI MessageBox "Opening hive file failed!"
Is a symptom of trying to run bootcd as normal reactos installation, with should has registry.
bootcd hasn't any registry installed. (look for file: %Root%\SYSTEM32\CONFIG\SYSTEM)
wlregistry.c: UiMessageBox("Opening hive file failed!");
of /boot/freeldr/freeldr/windows/wlregistry.c
WinLdrLoadSystemHive()/3
BOOLEAN WinLdrLoadSystemHive(IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock, IN LPCSTR DirectoryPath, IN LPCSTR HiveName) /* Concatenate path and filename to get the full name */ strcpy(FullHiveName, DirectoryPath); strcat(FullHiveName, HiveName); //Print(L"Loading %s...\n", FullHiveName); Status = ArcOpen(FullHiveName, OpenReadOnly, &FileId); if (Status != ESUCCESS) { *** UiMessageBox("Opening hive file failed!"); return FALSE; }
WinLdrScanSystemHive() calls WinLdrLoadSystemHive()
BOOLEAN WinLdrScanSystemHive()/2 strcpy(SearchPath, DirectoryPath); strcat(SearchPath, "SYSTEM32\\CONFIG\\"); Status = WinLdrLoadSystemHive(LoaderBlock, SearchPath, "SYSTEM"); // Fail if failed... if (!Status) return FALSE;
How bootcd is built
Quote from \boot\CMakeLists.txt:
add_custom_target(bootcd COMMAND native-cdmake -j -m -b ${CMAKE_CURRENT_BINARY_DIR}/freeldr/bootsect/isoboot.bin \ @${CMAKE_CURRENT_BINARY_DIR}/bootcd.lst REACTOS ${REACTOS_BINARY_DIR}/bootcd.iso DEPENDS native-cdmake VERBATIM)
CMAKE_CURRENT_BINARY_DIR = \output-MinGW-i386\reactos\boot
How livecd is built:
Quote from \boot\CMakeLists.txt:
add_custom_target(livecd COMMAND native-cdmake -j -m -b ${CMAKE_CURRENT_BINARY_DIR}/freeldr/bootsect/isoboot.bin \ @${CMAKE_CURRENT_BINARY_DIR}/livecd.lst REACTOS ${REACTOS_BINARY_DIR}/livecd.iso DEPENDS native-cdmake VERBATIM)
How isoboot.bin file is built:
CreateBootSectorTarget(isoboot ${CMAKE_CURRENT_SOURCE_DIR}/isoboot.S ${CMAKE_CURRENT_BINARY_DIR}/isoboot.bin 7000)
freeldr.sys on livecd: freeldr.sys on Livecd is renamed to setupldr.sys because isoboot.bin looks for setupldr.sys
ntoskrnl.exe loading and start
Entry point : _KiSystemStartup@4; subsystem:native