7265837194cd367c02e9e6efb04b1ae932977af7
[mirror_edk2.git] / DuetPkg / CreateBootDisk.bat
1 @echo off
2 @REM ## @file
3 @REM #
4 @REM # Copyright (c) 2010 - 2014, Intel Corporation. All rights reserved.<BR>
5 @REM #
6 @REM # This program and the accompanying materials
7 @REM # are licensed and made available under the terms and conditions of the BSD License
8 @REM # which accompanies this distribution. The full text of the license may be found at
9 @REM # http://opensource.org/licenses/bsd-license.php
10 @REM # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 @REM # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12 @REM #
13 @REM #
14 @REM ##
15
16 @REM Set up environment at first.
17
18 set BASETOOLS_DIR=%WORKSPACE_TOOLS_PATH%\Bin\Win32
19 set BOOTSECTOR_BIN_DIR=%WORKSPACE%\DuetPkg\BootSector\bin
20 set DISK_LABEL=DUET
21 set PROCESSOR=""
22 set STEP=1
23 call %WORKSPACE%\DuetPkg\GetVariables.bat
24
25 echo on
26
27 if "%1"=="" goto Help
28 if "%2"=="" goto Help
29 if "%3"=="" goto Help
30 if "%4"=="" goto Set_BootDisk
31 if "%4"=="step2" (@set STEP=2) else @set TARGET_ARCH=%4
32 if "%5"=="step2" @set STEP=2
33 :Set_BootDisk
34 set EFI_BOOT_DISK=%2
35 if "%TARGET_ARCH%"=="IA32" set PROCESSOR=IA32
36 if "%TARGET_ARCH%"=="X64" set PROCESSOR=X64
37 if %PROCESSOR%=="" goto WrongArch
38 set BUILD_DIR=%WORKSPACE%\Build\DuetPkg%PROCESSOR%\%TARGET%_%TOOL_CHAIN_TAG%
39
40 if "%1"=="floppy" goto CreateFloppy
41 if "%1"=="file" goto CreateFile
42 if "%1"=="usb" goto CreateUsb
43 if "%1"=="ide" goto CreateIde
44
45 goto Help
46
47 :CreateFloppy
48 if NOT "%3"=="FAT12" goto WrongFATType
49 echo Start to create floppy boot disk ...
50 echo Format %EFI_BOOT_DISK% ...
51 echo.> FormatCommandInput.txt
52 echo.n>> FormatCommandInput.txt
53 format /v:%DISK_LABEL% /q %EFI_BOOT_DISK% < FormatCommandInput.txt > NUL
54 del FormatCommandInput.txt
55 echo Create boot sector ...
56 %BASETOOLS_DIR%\Genbootsector.exe -i %EFI_BOOT_DISK% -o FDBs.com
57 copy %BOOTSECTOR_BIN_DIR%\Bootsect.com FDBs-1.com
58 %BASETOOLS_DIR%\Bootsectimage.exe -g FDBs.com FDBs-1.com -f
59 @REM @del FDBS.com
60 %BASETOOLS_DIR%\Genbootsector.exe -o %EFI_BOOT_DISK% -i FDBs-1.com
61 del FDBs-1.com
62 echo Done.
63 copy %BUILD_DIR%\FV\EfiLdr %EFI_BOOT_DISK%
64 goto CreateBootFile
65
66 :CreateFile
67 if NOT "%3"=="FAT12" goto WrongFATType
68 echo Start to create file boot disk ...
69 echo Create boot sector ...
70 %BASETOOLS_DIR%\Genbootsector.exe -i %EFI_BOOT_DISK% -o FDBs.com
71 copy %BOOTSECTOR_BIN_DIR%\Bootsect.com FDBs-1.com
72 %BASETOOLS_DIR%\Bootsectimage.exe -g FDBs.com FDBs-1.com -f
73 REM @del FDBS.com
74 %BASETOOLS_DIR%\Genbootsector.exe -o %EFI_BOOT_DISK% -i FDBs-1.com
75 del FDBs-1.com
76 echo Done.
77 goto end
78
79 :CreateUsb
80 echo Start to create usb boot disk ...
81 if "%3"=="FAT16" goto CreateUsb_FAT16
82 if "%3"=="FAT32" goto CreateUsb_FAT32
83 if "%3"=="FAT12" goto WrongFATType
84
85 :CreateUsb_FAT16
86 if "%STEP%"=="2" goto CreateUsb_FAT16_step2
87 echo Format %EFI_BOOT_DISK% ...
88 echo.> FormatCommandInput.txt
89 format /FS:FAT /v:%DISK_LABEL% /q %EFI_BOOT_DISK% < FormatCommandInput.txt > NUL
90 del FormatCommandInput.txt
91 echo Create boot sector ...
92 %BASETOOLS_DIR%\Genbootsector.exe -i %EFI_BOOT_DISK% -o UsbBs16.com
93 copy %BOOTSECTOR_BIN_DIR%\Bs16.com Bs16-1.com
94 %BASETOOLS_DIR%\Bootsectimage.exe -g UsbBs16.com Bs16-1.com -f
95 %BASETOOLS_DIR%\Genbootsector.exe -o %EFI_BOOT_DISK% -i Bs16-1.com
96 del Bs16-1.com
97 %BASETOOLS_DIR%\Genbootsector.exe -m -o %EFI_BOOT_DISK% -i %BOOTSECTOR_BIN_DIR%\Mbr.com
98 echo Done.
99 echo PLEASE UNPLUG USB, THEN PLUG IT AGAIN!
100 goto end
101
102 :CreateUsb_FAT16_step2
103 copy %BUILD_DIR%\FV\EfiLdr16 %EFI_BOOT_DISK%
104 goto CreateBootFile
105
106 :CreateUsb_FAT32
107 if "%STEP%"=="2" goto CreateUsb_FAT32_step2
108 echo Format %EFI_BOOT_DISK% ...
109 echo.> FormatCommandInput.txt
110 format /FS:FAT32 /v:%DISK_LABEL% /q %EFI_BOOT_DISK% < FormatCommandInput.txt > NUL
111 del FormatCommandInput.txt
112 echo Create boot sector ...
113 %BASETOOLS_DIR%\Genbootsector.exe -i %EFI_BOOT_DISK% -o UsbBs32.com
114 copy %BOOTSECTOR_BIN_DIR%\Bs32.com Bs32-1.com
115 %BASETOOLS_DIR%\Bootsectimage.exe -g UsbBs32.com Bs32-1.com -f
116 del UsbBs32.com
117 %BASETOOLS_DIR%\Genbootsector.exe -o %EFI_BOOT_DISK% -i Bs32-1.com
118 del Bs32-1.com
119 %BASETOOLS_DIR%\Genbootsector.exe -m -o %EFI_BOOT_DISK% -i %BOOTSECTOR_BIN_DIR%\Mbr.com
120 echo Done.
121 echo PLEASE UNPLUG USB, THEN PLUG IT AGAIN!
122 goto end
123
124 :CreateUsb_FAT32_step2
125 copy %BUILD_DIR%\FV\EfiLdr20 %EFI_BOOT_DISK%
126 goto CreateBootFile
127
128 :CreateIde
129 goto end
130
131 :CreateBootFile
132 mkdir %EFI_BOOT_DISK%\efi\boot
133 copy %WORKSPACE%\ShellBinPkg\UefiShell\%PROCESSOR%\Shell.efi %EFI_BOOT_DISK%\efi\boot\boot%PROCESSOR%.efi /y
134 goto end
135
136 :WrongFATType
137 echo Wrong FAT type %3 for %1
138 goto end
139
140 :WrongArch
141 echo Error! Wrong architecture.
142 goto Help
143
144 :Help
145 echo "Usage: CreateBootDisk [usb|floppy|ide] DiskNumber [FAT12|FAT16|FAT32] [IA32|X64]"
146 :end
147 echo on