1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/boardsupport/emulator/emulatorbsp/estart/estartmain.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,331 @@
1.4 +// Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +// wins\estart\estartmain.cpp
1.18 +//
1.19 +//
1.20 +
1.21 +#include <e32std.h>
1.22 +#include <f32fsys.h>
1.23 +#include <e32uid.h>
1.24 +#include "estart.h"
1.25 +
1.26 +#include <e32wins.h>
1.27 +#include <emulator.h>
1.28 +#define WIN32_LEAN_AND_MEAN
1.29 +#pragma warning( disable : 4201 ) // nonstandard extension used : nameless struct/union
1.30 +#include <windows.h>
1.31 +#pragma warning( default : 4201 ) // nonstandard extension used : nameless struct/union
1.32 +
1.33 +
1.34 +
1.35 +_LIT(KLitAddFsFail,"Add fs fail");
1.36 +_LIT(KLitConnectFsFail2,"Connect fs 2 fail");
1.37 +_LIT(KLitNoWS,"No WSERV");
1.38 +_LIT(KStartupModeFail,"Get startup mode failed");
1.39 +_LIT(KLocalFsName,"elocal");
1.40 +
1.41 +class TWinsFSStartup : public TFSStartup
1.42 + {
1.43 +public:
1.44 + virtual TInt StartSystem();
1.45 + virtual TInt DefaultLocalDrive(TInt aLocalDrive);
1.46 + virtual TPtrC LocalDriveMappingFileName();
1.47 +#if !defined(AUTODETECT_DISABLE)
1.48 + virtual TInt GetNextStandardFSInfoEntry(const SFileSystemInfo** anEntry,TInt aPos);
1.49 +#endif
1.50 +public:
1.51 + void LocalFSInitialisation();
1.52 +protected:
1.53 + TInt GetStartupMode();
1.54 + };
1.55 +
1.56 +#if !defined(AUTODETECT_DISABLE)
1.57 +TInt DetectEmulRAM(RLocalDrive ld, TInt cr, TLocalDriveCapsV2& caps)
1.58 + {
1.59 + (void)ld;
1.60 + (void)cr;
1.61 + if (caps.iType==EMediaRam)
1.62 + return KErrNone;
1.63 + return KErrGeneral;
1.64 + }
1.65 +
1.66 +TInt DetectEmul_CF_FAT(RLocalDrive ld, TInt cr, TLocalDriveCapsV2& caps)
1.67 + {
1.68 + (void)ld;
1.69 + (void)cr;
1.70 + if (caps.iType!=EMediaHardDisk || !(caps.iDriveAtt & KDriveAttRemovable))
1.71 + return KErrGeneral;
1.72 + if (cr==KErrNotReady)
1.73 + return KErrNone; // removable and not ready - assume fat
1.74 + if (cr==KErrNone && PartitionIsFAT(caps.iPartitionType))
1.75 + return KErrNone;
1.76 + return KErrGeneral;
1.77 + }
1.78 +
1.79 +TInt DetectEmul_CF_FAT32(RLocalDrive ld, TInt cr, TLocalDriveCapsV2& caps)
1.80 + {
1.81 + (void)ld;
1.82 + (void)cr;
1.83 + if (caps.iType!=EMediaHardDisk || !(caps.iDriveAtt & KDriveAttRemovable))
1.84 + return KErrGeneral;
1.85 + if (cr==KErrNotReady)
1.86 + return KErrNone; // removable and not ready - assume fat
1.87 + if (cr==KErrNone && (PartitionIsFAT32(caps.iPartitionType) || PartitionIsFAT(caps.iPartitionType)) )
1.88 + return KErrNone;
1.89 + return KErrGeneral;
1.90 + }
1.91 +#endif
1.92 +
1.93 +
1.94 +_LIT(KLocalDriveMappingFileSysBin,"Z:\\SYS\\DATA\\ESTART.TXT");
1.95 +TPtrC TWinsFSStartup::LocalDriveMappingFileName()
1.96 + {
1.97 + __ASSERT_ALWAYS(InitCompositeFileSystem()==KErrNone,User::Panic(_L("InitCompositeFileSystem failed."),0));
1.98 + return(KLocalDriveMappingFileSysBin());
1.99 + }
1.100 +
1.101 +LOCAL_C void AutoRun()
1.102 + {
1.103 + // Ensure that any background initialisation completes before auto-running
1.104 + RProcess me;
1.105 + me.SetPriority(EPriorityLow);
1.106 + const char* autorun = EmulatorAutoRun();
1.107 + if (autorun)
1.108 + {
1.109 + TInt r = KErrNone;
1.110 + const char* cmdline = EmulatorCommandLine();
1.111 + TFileName exe;
1.112 + exe.Copy(TPtrC8((const TText8*)autorun));
1.113 + TPtrC8 c((const TText8*)cmdline);
1.114 + HBufC* command = HBufC::New(c.Length());
1.115 + if (!command)
1.116 + r = KErrNoMemory;
1.117 + else
1.118 + {
1.119 + TPtr ptr(command->Des());
1.120 + ptr.Copy(c);
1.121 + RProcess p;
1.122 + r = p.Create(exe, *command);
1.123 + if (r == KErrNone)
1.124 + {
1.125 + TRequestStatus s;
1.126 + p.Logon(s);
1.127 + me.SetPriority(EPriorityHigh); // ensure we detect termination early
1.128 + p.Resume();
1.129 + p.Close();
1.130 + User::WaitForRequest(s);
1.131 + r = s.Int();
1.132 + }
1.133 + }
1.134 + Emulator::Escape(); // make sure we don't get suspended while exiting
1.135 + ExitProcess(r);
1.136 + }
1.137 + }
1.138 +
1.139 +const TInt WinsDefaultLocalDrives[KMaxLocalDrives]=
1.140 + {
1.141 + EDriveY, //0
1.142 + EDriveX, //1 MMC - Slot 0, partition 0
1.143 + KDriveInvalid, //2 MMC - Slot 0, partition 1
1.144 + EDriveT, //3 MMC - Slot 1, partition 0
1.145 + KDriveInvalid, //4 MMC - Slot 1, partition 1
1.146 + EDriveU, //5 NAND - USER DATA
1.147 + EDriveV, //6 NAND - CODE
1.148 + KDriveInvalid, //7
1.149 + EDriveW, //8
1.150 + KDriveInvalid, //9
1.151 + KDriveInvalid, //10
1.152 + KDriveInvalid, //11
1.153 + KDriveInvalid, //12
1.154 + KDriveInvalid, //13
1.155 + KDriveInvalid, //14
1.156 + KDriveInvalid //15
1.157 + };
1.158 +
1.159 +TInt TWinsFSStartup::DefaultLocalDrive(TInt aLocalDrive)
1.160 + {
1.161 +
1.162 + return(WinsDefaultLocalDrives[aLocalDrive]);
1.163 + }
1.164 +
1.165 +#if !defined(AUTODETECT_DISABLE)
1.166 +const TInt KMaxWinsFSInfoTableEntries=7;
1.167 +LOCAL_D const SFileSystemInfo FileSystems[KMaxWinsFSInfoTableEntries] =
1.168 + {
1.169 + {DetectEmulRAM, _S("efat32"), _S("fat"), 0, FS_FORMAT_CORRUPT},
1.170 + {DetectEmul_CF_FAT32,_S("efat32"), _S("fat"), 0, FS_FORMAT_CORRUPT},
1.171 + {DetectFtl, _S("efat32"), _S("fat"), 0, FS_FORMAT_CORRUPT},
1.172 + {DetectRofs, _S("erofs"), _S("rofs"), 0, FS_DISMNT_CORRUPT},
1.173 + {DetectEneaLFFS, _S("elffs"), _S("lffs"), 0, FS_FORMAT_CORRUPT},
1.174 + {DetectIso9660, _S("iso9660"), 0, 0, 0},
1.175 + {DetectNtfs, _S("ntfs"), 0, 0, 0},
1.176 + };
1.177 +
1.178 +// additional structure for DetectFtl entry with extension set to "0"
1.179 +LOCAL_D const SFileSystemInfo FileSystemForDetectFtl =
1.180 + {DetectFtl, _S("efat32"), _S("fat"), 0, FS_FORMAT_CORRUPT};
1.181 +
1.182 +
1.183 +TInt TWinsFSStartup::GetNextStandardFSInfoEntry(const SFileSystemInfo** anEntry,TInt aPos)
1.184 + {
1.185 + if (aPos<KMaxWinsFSInfoTableEntries)
1.186 + {
1.187 + *anEntry=&FileSystems[aPos];
1.188 + return(KErrNone);
1.189 + }
1.190 + else
1.191 + return(KErrNotFound);
1.192 + }
1.193 +#endif
1.194 +
1.195 +void TWinsFSStartup::LocalFSInitialisation()
1.196 +//
1.197 +// Add and mount local file system
1.198 +//
1.199 + {
1.200 +
1.201 + DEBUGPRINT("LocalFSInitialisation");
1.202 +
1.203 + // Add local file system
1.204 + TInt r=iFs.AddFileSystem(KLocalFsName);
1.205 + if (r!=KErrNone)
1.206 + User::Panic(KLitAddFsFail,r);
1.207 +
1.208 + // Close and reopen to make sure the session path is updated
1.209 + iFs.Close();
1.210 + r = iFs.Connect();
1.211 + if (r!=KErrNone)
1.212 + User::Panic(KLitConnectFsFail2,r);
1.213 +
1.214 + TInt i;
1.215 + _LIT(KLitLocalFsName,"Win32");
1.216 + TChar drive;
1.217 + TBuf<4> root=_L("?:\\");
1.218 + for(i=0;i<KMaxDrives-1;++i)
1.219 + {
1.220 + r=RFs::DriveToChar(i,drive);
1.221 + if(r!=KErrNone)
1.222 + continue;
1.223 + root[0]=(TText)drive;
1.224 + TFileName dummy;
1.225 + if (MapEmulatedFileName(dummy,root)==KErrNone)
1.226 + {
1.227 + r=iFs.MountFileSystem(KLitLocalFsName,i);
1.228 + DEBUGPRINT2("MountFileSystem() on drive %d r=%d",i,r);
1.229 + }
1.230 + }
1.231 + }
1.232 +
1.233 +_LIT(KWindowServerRootName1, "EWSRV.EXE");
1.234 +_LIT(KWindowServerRootName2, "WSERV.EXE");
1.235 +_LIT(KSystemStarterName, "z:\\sys\\bin\\SYSSTART.EXE");
1.236 +_LIT(KSystemStateManager, "z:\\sys\\bin\\SYSSTATEMGR.EXE");
1.237 +_LIT(KPropertyError, "RProperty return error");
1.238 +
1.239 +TInt TWinsFSStartup::StartSystem()
1.240 + {
1.241 + // Get boot mode with need to access file server
1.242 + TInt r = GetStartupModeFromFile();
1.243 + if (r != KErrNotSupported)
1.244 + {
1.245 + if (r != KErrNone)
1.246 + User::Panic(KStartupModeFail,r);
1.247 + // Update startup mode property value
1.248 + r = RProperty::Set(KUidSystemCategory, KSystemStartupModeKey, iStartupMode);
1.249 + if (r != KErrNone)
1.250 + User::Panic(KPropertyError, r);
1.251 + }
1.252 +
1.253 + // Launch system starter and return unless in noGui or textshell mode
1.254 + TBool noSysStart = EFalse;
1.255 + UserSvr::HalFunction(EHalGroupEmulator,EEmulatorHalBoolProperty, (TAny*)"_NOSYSSTART", &noSysStart);
1.256 +
1.257 + if (!EmulatorNoGui() && !EmulatorTextShell() && !EmulatorMiniGui() && !noSysStart)
1.258 + {
1.259 + RProcess ws;
1.260 + r=ws.Create(KSystemStateManager, KNullDesC);
1.261 + if (r!=KErrNone)
1.262 + {
1.263 + r=ws.Create(KSystemStarterName, KNullDesC);
1.264 + if (r==KErrNone)
1.265 + {
1.266 + TRequestStatus status;
1.267 + ws.Rendezvous(status);
1.268 + ws.Resume();
1.269 + User::WaitForRequest(status);
1.270 + // Some system starters may not exit on completion.
1.271 + if (ws.ExitType() != EExitKill && ws.ExitType() != EExitPending)
1.272 + User::Panic(_L("SysStart died"),status.Int());
1.273 + ws.Close();
1.274 + return KErrNone;
1.275 + }
1.276 + }
1.277 + else
1.278 + {
1.279 + TRequestStatus status;
1.280 + ws.Rendezvous(status);
1.281 + ws.Resume();
1.282 + User::WaitForRequest(status);
1.283 + if (ws.ExitType() != EExitKill && ws.ExitType() != EExitPending)
1.284 + User::Panic(_L("SysStart died"),status.Int());
1.285 + ws.Close();
1.286 + return KErrNone;
1.287 + }
1.288 + }
1.289 +
1.290 + // Start system agent 2, continue if executable not found, otherwise panic
1.291 + r = StartSysAgt2();
1.292 + if (r!=KErrNone && r!=KErrNotFound)
1.293 + User::Panic(_L("Error launching System Agent"),r);
1.294 +
1.295 + // If noGui specifed, then we're done
1.296 + if (EmulatorNoGui())
1.297 + return KErrNone;
1.298 +
1.299 + // Attempt to start the appropriate window server
1.300 + TDriveList list;
1.301 + iFs.DriveList(list);
1.302 + if (!EmulatorTextShell() && CreateServer(list,KWindowServerRootName2))
1.303 + return KErrNone;
1.304 + if (!CreateServer(list,KWindowServerRootName1))
1.305 + User::Panic(KLitNoWS,KErrNotFound);
1.306 +
1.307 + return KErrNone;
1.308 + }
1.309 +
1.310 +TInt TWinsFSStartup::GetStartupMode()
1.311 + {
1.312 + UserSvr::HalFunction(EHalGroupEmulator, EEmulatorHalIntProperty,
1.313 + (TAny*)"StartupMode", &iStartupMode);
1.314 + return(KErrNone);
1.315 + }
1.316 +
1.317 +GLDEF_C TInt E32Main()
1.318 + {
1.319 +
1.320 + TWinsFSStartup fsStart;
1.321 + fsStart.Init();
1.322 +
1.323 + fsStart.LocalFSInitialisation();
1.324 + fsStart.Run();
1.325 +
1.326 + fsStart.StartSystem();
1.327 +
1.328 + fsStart.Close();
1.329 +
1.330 + AutoRun();
1.331 +
1.332 + return(0);
1.333 + }
1.334 +