Skip to content
This repository has been archived by the owner on Sep 26, 2024. It is now read-only.

Commit

Permalink
Merge pull request #132 from parameshbabu/master
Browse files Browse the repository at this point in the history
Recovery tools update
  • Loading branch information
parameshbabu authored Sep 28, 2017
2 parents ef2baee + fbb341d commit 4ff1186
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -225,9 +225,10 @@
<!-- Recovery Partition -->
<Partition>
<Name>MMOS</Name>
<FileSystem>FAT32</FileSystem>
<TotalSectors>4096000</TotalSectors>
<!--MinFreeSectors>6553600</MinFreeSectors-->
<Type>{ebd0a0a2-b9e5-4433-87c0-68b6b72699c7}</Type>
<FileSystem>NTFS</FileSystem>
<TotalSectors>4915200</TotalSectors>
</Partition>
<Partition>
<Name>Data</Name>
Expand Down
18 changes: 4 additions & 14 deletions Templates/recovery/diskpart_assign.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,16 @@ sel disk 0
lis vol

sel vol 0
remove all noerr
assign letter="P" noerr

sel vol 1
remove all noerr
assign letter "C" noerr
format fs=NTFS quick label=MainOS override noerr
assign letter=P noerr

sel vol 2
remove all noerr
assign letter "R" noerr
assign letter=R noerr

sel vol 3
remove all noerr
assign letter="D" noerr
format fs=NTFS quick label=Data override noerr
assign letter=D noerr

sel vol 4
remove all noerr
assign letter="E" noerr
assign letter=E noerr

lis vol
exit
14 changes: 14 additions & 0 deletions Templates/recovery/diskpart_format.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
sel disk 0

sel vol 1
remove all dismount noerr
assign letter=C noerr
format fs=NTFS quick label="MainOS" override noerr

sel vol 3
remove all dismount noerr
assign letter=D noerr
format fs=NTFS quick label="Data" override noerr

lis vol
exit
12 changes: 4 additions & 8 deletions Templates/recovery/diskpart_remove.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,16 @@ sel disk 0
lis vol

sel vol 0
remove all noerr

sel vol 1
remove all noerr
assign letter "C" noerr
remove letter=P noerr

sel vol 2
remove all noerr
remove letter=R noerr

sel vol 3
remove all noerr
remove letter=D noerr

sel vol 4
remove all noerr
remove letter=E noerr

lis vol
exit
68 changes: 26 additions & 42 deletions Templates/recovery/startnet.cmd
Original file line number Diff line number Diff line change
@@ -1,50 +1,34 @@
@echo off
REM startnet.cmd

REM Launch UI to cover screen
REM start recoverygui.exe

echo IoT recovery initializing...
wpeinit

REM Format partitions and assign drive letters
REM Assign drive letters
call diskpart /s diskpart_assign.txt

REM Define drive letters (assigned by diskpart script)
set MAINOSDRIVE=C
set EFIDRIVE=E
set RECOVERYDRIVE=R
set DATADRIVE=D
set DPPDRIVE=P

REM Apply EFIESP partition WIM file
dism /apply-image /ImageFile:%RECOVERYDRIVE%:\efiesp.wim /index:1 /ApplyDir:%EFIDRIVE%:\
REM This will reset BCD to defaults, so immediately reset recovery parameter in case of power loss
bcdedit /store %EFIDRIVE%:\EFI\microsoft\boot\bcd /set {bootmgr} bootsequence {a5935ff2-32ba-4617-bf36-5ac314b3f9bf}

REM Apply the MainOS and Data partition WIM files. The order below is important - do not change
dism /apply-image /ImageFile:%RECOVERYDRIVE%:\data.wim /index:1 /ApplyDir:%DATADRIVE%:\ /Compact
dism /apply-image /ImageFile:%RECOVERYDRIVE%:\mainos.wim /index:1 /ApplyDir:%MAINOSDRIVE%:\ /Compact

REM Restore Junctions for Data/DPP/MMOS partitions
REM Only necessary when recovery WIMs not generated from same FFU
mountvol %DATADRIVE%:\ /L > volumeguid_data
set /p VOLUMEGUIDDATA=<volumeguid_data
rmdir %MAINOSDRIVE%:\Data
mklink /J %MAINOSDRIVE%:\Data %VOLUMEGUIDDATA%

mountvol %DPPDRIVE%:\ /L > volumeguid_dpp
set /p VOLUMEGUIDDPP=<volumeguid_dpp
rmdir %MAINOSDRIVE%:\DPP
mklink /J %MAINOSDRIVE%:\DPP %VOLUMEGUIDDPP%

mountvol %RECOVERYDRIVE%:\ /L > volumeguid_recovery
set /p VOLUMEGUIDRECOVERY=<volumeguid_recovery
rmdir %MAINOSDRIVE%:\MMOS
mklink /J %MAINOSDRIVE%:\MMOS %VOLUMEGUIDRECOVERY%

REM Fix up MountedDevices registry to point to correct Data partition GUID
set VOL=%VOLUMEGUIDDATA%
set VOL=%VOL: =%
set UDRIVEBINARYBLOB=444D494F3A49443A%vol:~17,2%%vol:~15,2%%vol:~13,2%%vol:~11,2%%vol:~22,2%%vol:~20,2%%vol:~27,2%%vol:~25,2%%vol:~30,4%%vol:~35,12%
reg load "HKLM\RecoveryIoTSystem" %MAINOSDRIVE%:\windows\system32\config\system
reg add "HKLM\RecoveryIoTSystem\MountedDevices" /v "\DosDevices\U:" /t REG_BINARY /f /d %UDRIVEBINARYBLOB%
reg unload "HKLM\RecoveryIoTSystem"
set EFIDRIVE=E

REM Initilize logging
set RECOVERY_LOG_FOLDER=%RECOVERYDRIVE%:\recoverylogs
md %RECOVERY_LOG_FOLDER%
echo --- Device recovery initiated --- >>%RECOVERY_LOG_FOLDER%\recovery_log.txt
call time /t >>%RECOVERY_LOG_FOLDER%\recovery_log.txt
copy %WINDIR%\system32\winpeshl.log %RECOVERY_LOG_FOLDER%

REM Ensure recovery WIM files are available
if not exist %RECOVERYDRIVE%:\data.wim echo Missing data.wim file! >>%RECOVERY_LOG_FOLDER%\recovery_log.txt && goto exit
if not exist %RECOVERYDRIVE%:\mainos.wim echo Missing mainos.wim file! >>%RECOVERY_LOG_FOLDER%\recovery_log.txt && goto exit
if not exist %RECOVERYDRIVE%:\efiesp.wim echo Missing efiesp.wim file! >>%RECOVERY_LOG_FOLDER%\recovery_log.txt && goto exit

REM Perform recovery operations, logging to MMOS log file
call startnet_recovery.cmd >>%RECOVERY_LOG_FOLDER%\recovery_log.txt

:exit
call time /t >>%RECOVERY_LOG_FOLDER%\recovery_log.txt
echo --- Device recovery completed --- >>%RECOVERY_LOG_FOLDER%\recovery_log.txt

REM Go back to MainOS on next boot
bcdedit /store %EFIDRIVE%:\EFI\microsoft\boot\bcd /set {bootmgr} bootsequence {01de5a27-8705-40db-bad6-96fa5187d4a6}
Expand Down
45 changes: 45 additions & 0 deletions Templates/recovery/startnet_recovery.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
REM startnet_recovery.cmd

REM Format MainOS and Data partitions
call diskpart /s diskpart_format.txt

REM Define drive letters (assigned by diskpart script)
set MAINOSDRIVE=C
set EFIDRIVE=E
set RECOVERYDRIVE=R
set DATADRIVE=D
set DPPDRIVE=P

REM Apply EFIESP partition WIM file
dism /apply-image /ImageFile:%RECOVERYDRIVE%:\efiesp.wim /index:1 /ApplyDir:%EFIDRIVE%:\
REM This will reset BCD to defaults, so immediately reset recovery parameter in case of power loss
bcdedit /store %EFIDRIVE%:\EFI\microsoft\boot\bcd /set {bootmgr} bootsequence {a5935ff2-32ba-4617-bf36-5ac314b3f9bf}

REM Apply the MainOS and Data partition WIM files. The order below is important - do not change
dism /apply-image /ImageFile:%RECOVERYDRIVE%:\data.wim /index:1 /ApplyDir:%DATADRIVE%:\ /Compact
dism /apply-image /ImageFile:%RECOVERYDRIVE%:\mainos.wim /index:1 /ApplyDir:%MAINOSDRIVE%:\ /Compact

REM Restore Junctions for Data/DPP/MMOS partitions
REM Only necessary when recovery WIMs not generated from same FFU
mountvol %DATADRIVE%:\ /L > volumeguid_data
set /p VOLUMEGUIDDATA=<volumeguid_data
rmdir %MAINOSDRIVE%:\Data
mklink /J %MAINOSDRIVE%:\Data %VOLUMEGUIDDATA%

mountvol %DPPDRIVE%:\ /L > volumeguid_dpp
set /p VOLUMEGUIDDPP=<volumeguid_dpp
rmdir %MAINOSDRIVE%:\DPP
mklink /J %MAINOSDRIVE%:\DPP %VOLUMEGUIDDPP%

mountvol %RECOVERYDRIVE%:\ /L > volumeguid_recovery
set /p VOLUMEGUIDRECOVERY=<volumeguid_recovery
rmdir %MAINOSDRIVE%:\MMOS
mklink /J %MAINOSDRIVE%:\MMOS %VOLUMEGUIDRECOVERY%

REM Fix up MountedDevices registry to point to correct Data partition GUID
set VOL=%VOLUMEGUIDDATA%
set VOL=%VOL: =%
set UDRIVEBINARYBLOB=444D494F3A49443A%vol:~17,2%%vol:~15,2%%vol:~13,2%%vol:~11,2%%vol:~22,2%%vol:~20,2%%vol:~27,2%%vol:~25,2%%vol:~30,4%%vol:~35,12%
reg load "HKLM\RecoveryIoTSystem" %MAINOSDRIVE%:\windows\system32\config\system
reg add "HKLM\RecoveryIoTSystem\MountedDevices" /v "\DosDevices\U:" /t REG_BINARY /f /d %UDRIVEBINARYBLOB%
reg unload "HKLM\RecoveryIoTSystem"
6 changes: 4 additions & 2 deletions Tools/newwinpe.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,14 @@ if [%BSP_ARCH%] == [arm] (
)
del %BSPDIR%\driverlist.txt
) else (
echo %BSPDIR% does not exist,no drivers added. Provide BSP source directory.
echo No drivers added. Provide valid BSP source directory to add drivers.
)
)
echo Copying files into WinPE
copy "%IOTADK_ROOT%\Templates\recovery\startnet.cmd" %MOUNTDIR%\windows\system32\startnet.cmd >nul
copy "%IOTADK_ROOT%\Templates\recovery\startnet.cmd" %MOUNTDIR%\windows\system32\ >nul
copy "%IOTADK_ROOT%\Templates\recovery\startnet_recovery.cmd" %MOUNTDIR%\windows\system32\ >nul
copy "%IOTADK_ROOT%\Templates\recovery\diskpart_assign.txt" %MOUNTDIR%\windows\system32\ >nul
copy "%IOTADK_ROOT%\Templates\recovery\diskpart_format.txt" %MOUNTDIR%\windows\system32\ >nul
copy "%IOTADK_ROOT%\Templates\recovery\diskpart_remove.txt" %MOUNTDIR%\windows\system32\ >nul

echo Saving and unmounting WinPE
Expand Down

0 comments on commit 4ff1186

Please sign in to comment.