BaseTools/BinToPcd: Fix Python 2.7.x compatibility issue
[mirror_edk2.git] / DuetPkg / CreateBootDisk.bat
1 @echo off
2 @REM ## @file
3 @REM #
4 @REM # Copyright (c) 2010 - 2016, 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=%EDK_TOOLS_BIN%
19 set BOOTSECTOR_BIN_DIR=%WORKSPACE%\DuetPkg\BootSector\bin
20 set DISK_LABEL=DUET
21 set PROCESSOR=""
22 set STEP=1
23
24 if "%1"=="" goto Help
25 if "%2"=="" goto Help
26 if "%3"=="" goto Help
27 if "%4"=="" goto Set_BootDisk
28 if "%4"=="step2" (@set STEP=2) else @set TARGET_ARCH=%4
29 if "%5"=="step2" @set STEP=2
30 :Set_BootDisk
31 set EFI_BOOT_DISK=%2
32 if "%TARGET_ARCH%"=="IA32" set PROCESSOR=IA32
33 if "%TARGET_ARCH%"=="X64" set PROCESSOR=X64
34 if %PROCESSOR%=="" goto WrongArch
35 call %WORKSPACE%\DuetPkg\SetEnv_%PROCESSOR%.bat
36 set BUILD_DIR=%WORKSPACE%\Build\DuetPkg%PROCESSOR%\%TARGET%_%TOOL_CHAIN_TAG%
37
38 if "%1"=="floppy" goto CreateFloppy
39 if "%1"=="file" goto CreateFile
40 if "%1"=="usb" goto CreateUsb
41 if "%1"=="ide" goto CreateIde
42
43 goto Help
44
45 :CreateFloppy
46 if NOT "%3"=="FAT12" goto WrongFATType
47 echo Start to create floppy boot disk ...
48 echo Format %EFI_BOOT_DISK% ...
49 echo.> FormatCommandInput.txt
50 echo.n>> FormatCommandInput.txt
51 format /v:%DISK_LABEL% /q %EFI_BOOT_DISK% < FormatCommandInput.txt > NUL
52 del FormatCommandInput.txt
53 echo Create boot sector ...
54 %BASETOOLS_DIR%\Genbootsector.exe -i %EFI_BOOT_DISK% -o FDBs.com
55 copy %BOOTSECTOR_BIN_DIR%\Bootsect.com FDBs-1.com
56 %BASETOOLS_DIR%\Bootsectimage.exe -g FDBs.com FDBs-1.com -f
57 @REM @del FDBS.com
58 %BASETOOLS_DIR%\Genbootsector.exe -o %EFI_BOOT_DISK% -i FDBs-1.com
59 del FDBs-1.com
60 echo Done.
61 copy %BUILD_DIR%\FV\EfiLdr %EFI_BOOT_DISK%
62 goto CreateBootFile
63
64 :CreateFile
65 if NOT "%3"=="FAT12" goto WrongFATType
66 echo Start to create file boot disk ...
67 echo Create boot sector ...
68 %BASETOOLS_DIR%\Genbootsector.exe -i %EFI_BOOT_DISK% -o FDBs.com
69 copy %BOOTSECTOR_BIN_DIR%\Bootsect.com FDBs-1.com
70 %BASETOOLS_DIR%\Bootsectimage.exe -g FDBs.com FDBs-1.com -f
71 REM @del FDBS.com
72 %BASETOOLS_DIR%\Genbootsector.exe -o %EFI_BOOT_DISK% -i FDBs-1.com
73 del FDBs-1.com
74 echo Done.
75 goto end
76
77 :CreateUsb
78 echo Start to create usb boot disk ...
79 if "%3"=="FAT16" goto CreateUsb_FAT16
80 if "%3"=="FAT32" goto CreateUsb_FAT32
81 if "%3"=="FAT12" goto WrongFATType
82
83 :CreateUsb_FAT16
84 if "%STEP%"=="2" goto CreateUsb_FAT16_step2
85 echo Format %EFI_BOOT_DISK% ...
86 echo.> FormatCommandInput.txt
87 format /FS:FAT /v:%DISK_LABEL% /q %EFI_BOOT_DISK% < FormatCommandInput.txt > NUL
88 del FormatCommandInput.txt
89 echo Create boot sector ...
90 %BASETOOLS_DIR%\Genbootsector.exe -i %EFI_BOOT_DISK% -o UsbBs16.com
91 copy %BOOTSECTOR_BIN_DIR%\Bs16.com Bs16-1.com
92 %BASETOOLS_DIR%\Bootsectimage.exe -g UsbBs16.com Bs16-1.com -f
93 %BASETOOLS_DIR%\Genbootsector.exe -o %EFI_BOOT_DISK% -i Bs16-1.com
94 del Bs16-1.com
95 %BASETOOLS_DIR%\Genbootsector.exe -m -o %EFI_BOOT_DISK% -i %BOOTSECTOR_BIN_DIR%\Mbr.com
96 echo Done.
97 echo PLEASE UNPLUG USB, THEN PLUG IT AGAIN!
98 goto end
99
100 :CreateUsb_FAT16_step2
101 copy %BUILD_DIR%\FV\EfiLdr16 %EFI_BOOT_DISK%
102 goto CreateBootFile
103
104 :CreateUsb_FAT32
105 if "%STEP%"=="2" goto CreateUsb_FAT32_step2
106 echo Format %EFI_BOOT_DISK% ...
107 echo.> FormatCommandInput.txt
108 format /FS:FAT32 /v:%DISK_LABEL% /q %EFI_BOOT_DISK% < FormatCommandInput.txt > NUL
109 del FormatCommandInput.txt
110 echo Create boot sector ...
111 %BASETOOLS_DIR%\Genbootsector.exe -i %EFI_BOOT_DISK% -o UsbBs32.com
112 copy %BOOTSECTOR_BIN_DIR%\Bs32.com Bs32-1.com
113 %BASETOOLS_DIR%\Bootsectimage.exe -g UsbBs32.com Bs32-1.com -f
114 del UsbBs32.com
115 %BASETOOLS_DIR%\Genbootsector.exe -o %EFI_BOOT_DISK% -i Bs32-1.com
116 del Bs32-1.com
117 %BASETOOLS_DIR%\Genbootsector.exe -m -o %EFI_BOOT_DISK% -i %BOOTSECTOR_BIN_DIR%\Mbr.com
118 echo Done.
119 echo PLEASE UNPLUG USB, THEN PLUG IT AGAIN!
120 goto end
121
122 :CreateUsb_FAT32_step2
123 copy %BUILD_DIR%\FV\EfiLdr20 %EFI_BOOT_DISK%
124 goto CreateBootFile
125
126 :CreateIde
127 goto end
128
129 :CreateBootFile
130 mkdir %EFI_BOOT_DISK%\efi\boot
131 copy %WORKSPACE%\ShellBinPkg\UefiShell\%PROCESSOR%\Shell.efi %EFI_BOOT_DISK%\efi\boot\boot%PROCESSOR%.efi /y
132 goto end
133
134 :WrongFATType
135 echo Wrong FAT type %3 for %1
136 goto end
137
138 :WrongArch
139 echo Error! Wrong architecture.
140 goto Help
141
142 :Help
143 echo "Usage: CreateBootDisk [usb|floppy|ide] DiskNumber [FAT12|FAT16|FAT32] [IA32|X64]"
144 :end
145 echo on