klu2 | ab9cb4b | 2010-03-18 02:36:52 +0000 | [diff] [blame] | 1 | #! /bin/sh |
| 2 | |
| 3 | ## @file |
| 4 | # |
Ruiyu Ni | 2790926 | 2014-11-25 08:53:33 +0000 | [diff] [blame] | 5 | # Copyright (c) 2010 - 2014, Intel Corporation. All rights reserved.<BR> |
klu2 | ab9cb4b | 2010-03-18 02:36:52 +0000 | [diff] [blame] | 6 | # |
| 7 | # This program and the accompanying materials |
| 8 | # are licensed and made available under the terms and conditions of the BSD License |
| 9 | # which accompanies this distribution. The full text of the license may be found at |
| 10 | # http://opensource.org/licenses/bsd-license.php |
| 11 | # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. |
| 13 | # |
| 14 | # |
| 15 | ## |
gikidy | 5b7021e | 2009-03-03 06:27:07 +0000 | [diff] [blame] | 16 | |
| 17 | # Set up environment at fisrt. |
klu2 | ab9cb4b | 2010-03-18 02:36:52 +0000 | [diff] [blame] | 18 | |
jljusten | 5c1138b | 2010-10-16 18:50:43 +0000 | [diff] [blame] | 19 | if [ -z "$EDK_TOOLS_PATH" ] |
| 20 | then |
klu2 | df6434f | 2009-09-17 02:16:30 +0000 | [diff] [blame] | 21 | export BASETOOLS_DIR=$WORKSPACE/Conf/BaseToolsSource/Source/C/bin |
jljusten | 5c1138b | 2010-10-16 18:50:43 +0000 | [diff] [blame] | 22 | else |
| 23 | export BASETOOLS_DIR=$EDK_TOOLS_PATH/Source/C/bin |
| 24 | fi |
| 25 | |
klu2 | e88f305 | 2009-06-22 03:01:53 +0000 | [diff] [blame] | 26 | export BOOTSECTOR_BIN_DIR=$WORKSPACE/DuetPkg/BootSector/bin |
gikidy | 5b7021e | 2009-03-03 06:27:07 +0000 | [diff] [blame] | 27 | export DISK_LABEL=DUET |
gikidy | 6976b5c | 2009-03-31 06:38:37 +0000 | [diff] [blame] | 28 | export PROCESS_MARK=TRUE |
gikidy | 5b7021e | 2009-03-03 06:27:07 +0000 | [diff] [blame] | 29 | |
| 30 | if [ \ |
| 31 | -z "$*" -o \ |
| 32 | "$*" = "-?" -o \ |
| 33 | "$*" = "-h" -o \ |
| 34 | "$*" = "--help" \ |
| 35 | ] |
| 36 | then |
jljusten | 5c1138b | 2010-10-16 18:50:43 +0000 | [diff] [blame] | 37 | echo "Usage: CreateBootDisk [usb|floppy|ide|file] MediaPath DevicePath [FAT12|FAT16|FAT32] [IA32|X64] [GCC44|UNIXGCC]" |
eric_tian | e843cdd | 2010-01-19 08:28:28 +0000 | [diff] [blame] | 38 | echo "e.g. : CreateBootDisk floppy /media/floppy0 /dev/fd0 FAT12 IA32" |
gikidy | 6976b5c | 2009-03-31 06:38:37 +0000 | [diff] [blame] | 39 | PROCESS_MARK=FALSE |
gikidy | 5b7021e | 2009-03-03 06:27:07 +0000 | [diff] [blame] | 40 | fi |
| 41 | |
klu2 | ab9cb4b | 2010-03-18 02:36:52 +0000 | [diff] [blame] | 42 | case "$5" in |
| 43 | IA32) |
| 44 | export PROCESSOR=IA32 |
| 45 | ;; |
| 46 | X64) |
| 47 | export PROCESSOR=X64 |
| 48 | ;; |
| 49 | *) |
| 50 | echo Invalid Architecture string, should be only IA32 or X64 |
| 51 | return 1 |
| 52 | esac |
| 53 | |
jljusten | 5c1138b | 2010-10-16 18:50:43 +0000 | [diff] [blame] | 54 | if [ -z "$6" ] |
| 55 | then |
| 56 | TOOLCHAIN=GCC44 |
| 57 | else |
| 58 | TOOLCHAIN=$6 |
| 59 | fi |
| 60 | |
| 61 | export BUILD_DIR=$WORKSPACE/Build/DuetPkg$PROCESSOR/DEBUG_$TOOLCHAIN |
klu2 | ab9cb4b | 2010-03-18 02:36:52 +0000 | [diff] [blame] | 62 | |
| 63 | |
gikidy | 536c563 | 2009-03-24 09:23:21 +0000 | [diff] [blame] | 64 | export EFI_BOOT_MEDIA=$2 |
| 65 | export EFI_BOOT_DEVICE=$3 |
gikidy | 5b7021e | 2009-03-03 06:27:07 +0000 | [diff] [blame] | 66 | |
gikidy | 6976b5c | 2009-03-31 06:38:37 +0000 | [diff] [blame] | 67 | if [ "$PROCESS_MARK" = TRUE ] |
| 68 | then |
| 69 | case "$1" in |
| 70 | floppy) |
| 71 | if [ "$4" = FAT12 ] |
gikidy | 5b7021e | 2009-03-03 06:27:07 +0000 | [diff] [blame] | 72 | then |
gikidy | 6976b5c | 2009-03-31 06:38:37 +0000 | [diff] [blame] | 73 | echo Start to create floppy boot disk ... |
| 74 | echo Format $EFI_BOOT_MEDIA ... |
| 75 | ## Format floppy disk |
| 76 | umount $EFI_BOOT_MEDIA |
| 77 | mkfs.msdos $EFI_BOOT_DEVICE |
| 78 | mount $EFI_BOOT_DEVICE $EFI_BOOT_MEDIA |
gikidy | 5b7021e | 2009-03-03 06:27:07 +0000 | [diff] [blame] | 79 | echo Create boot sector ... |
gikidy | 6976b5c | 2009-03-31 06:38:37 +0000 | [diff] [blame] | 80 | ## Linux version of GenBootSector has not pass build yet. |
| 81 | $BASETOOLS_DIR/GnuGenBootSector -i $EFI_BOOT_DEVICE -o FDBs.com |
Eric Dong | bffaa26 | 2014-07-09 08:28:05 +0000 | [diff] [blame] | 82 | cp $BOOTSECTOR_BIN_DIR/bootsect.com FDBs-1.com |
| 83 | $BASETOOLS_DIR/BootSectImage -g FDBs.com FDBs-1.com -f |
| 84 | $BASETOOLS_DIR/GnuGenBootSector -o $EFI_BOOT_DEVICE -i FDBs-1.com |
| 85 | rm FDBs-1.com |
gikidy | 6976b5c | 2009-03-31 06:38:37 +0000 | [diff] [blame] | 86 | cp $BUILD_DIR/FV/Efildr $EFI_BOOT_MEDIA |
| 87 | |
| 88 | mkdir -p $EFI_BOOT_MEDIA/efi |
| 89 | mkdir -p $EFI_BOOT_MEDIA/efi/boot |
eric_tian | e843cdd | 2010-01-19 08:28:28 +0000 | [diff] [blame] | 90 | if [ "$5" = IA32 ] |
| 91 | then |
Ruiyu Ni | 2790926 | 2014-11-25 08:53:33 +0000 | [diff] [blame] | 92 | cp $WORKSPACE/ShellBinPkg/UefiShell/Ia32/Shell.efi $EFI_BOOT_MEDIA/efi/boot/boot$5.efi |
eric_tian | e843cdd | 2010-01-19 08:28:28 +0000 | [diff] [blame] | 93 | else |
| 94 | if [ "$5" = X64 ] |
| 95 | then |
Ruiyu Ni | 2790926 | 2014-11-25 08:53:33 +0000 | [diff] [blame] | 96 | cp $WORKSPACE/ShellBinPkg/UefiShell/X64/Shell.efi $EFI_BOOT_MEDIA/efi/boot/boot$5.efi |
eric_tian | e843cdd | 2010-01-19 08:28:28 +0000 | [diff] [blame] | 97 | else |
| 98 | echo Wrong Arch! |
| 99 | fi |
| 100 | fi |
gikidy | 5b7021e | 2009-03-03 06:27:07 +0000 | [diff] [blame] | 101 | echo Done. |
gikidy | 6976b5c | 2009-03-31 06:38:37 +0000 | [diff] [blame] | 102 | else |
| 103 | echo "Wrong FAT type $4 for floppy!" |
gikidy | 5b7021e | 2009-03-03 06:27:07 +0000 | [diff] [blame] | 104 | fi |
gikidy | 6976b5c | 2009-03-31 06:38:37 +0000 | [diff] [blame] | 105 | ;; |
| 106 | |
| 107 | file) # CreateFile |
| 108 | if [ "$4" = FAT12 ] |
| 109 | then |
| 110 | echo "Start to create file boot disk ..." |
jljusten | 5c1138b | 2010-10-16 18:50:43 +0000 | [diff] [blame] | 111 | dd bs=512 count=2880 if=/dev/zero of=$EFI_BOOT_MEDIA |
| 112 | mkfs.msdos -F 12 $EFI_BOOT_MEDIA |
| 113 | |
| 114 | mcopy -i $EFI_BOOT_MEDIA $BUILD_DIR/FV/Efildr ::/Efildr |
| 115 | mmd -i $EFI_BOOT_MEDIA ::/efi ::/efi/boot |
| 116 | if [ "$5" = IA32 ] |
| 117 | then |
Ruiyu Ni | 2790926 | 2014-11-25 08:53:33 +0000 | [diff] [blame] | 118 | mcopy -i $EFI_BOOT_MEDIA $WORKSPACE/ShellBinPkg/UefiShell/Ia32/Shell.efi ::/efi/boot/boot$5.efi |
jljusten | 5c1138b | 2010-10-16 18:50:43 +0000 | [diff] [blame] | 119 | elif [ "$5" = X64 ] |
| 120 | then |
Ruiyu Ni | 2790926 | 2014-11-25 08:53:33 +0000 | [diff] [blame] | 121 | mcopy -i $EFI_BOOT_MEDIA $WORKSPACE/ShellBinPkg/UefiShell/X64/Shell.efi ::/efi/boot/boot$5.efi |
jljusten | 5c1138b | 2010-10-16 18:50:43 +0000 | [diff] [blame] | 122 | else |
| 123 | echo Wrong Arch! |
| 124 | fi |
| 125 | mdir -i $EFI_BOOT_MEDIA -s :: |
| 126 | |
gikidy | 6976b5c | 2009-03-31 06:38:37 +0000 | [diff] [blame] | 127 | ## Linux version of GenBootSector has not pass build yet. |
jljusten | 5c1138b | 2010-10-16 18:50:43 +0000 | [diff] [blame] | 128 | $BASETOOLS_DIR/GnuGenBootSector -i $EFI_BOOT_MEDIA -o $EFI_BOOT_MEDIA.bs0 |
jljusten | 8df0bd2 | 2010-12-06 06:06:54 +0000 | [diff] [blame] | 129 | cp $BOOTSECTOR_BIN_DIR/bootsect.com $EFI_BOOT_MEDIA.bs1 |
| 130 | $BASETOOLS_DIR/BootSectImage -g $EFI_BOOT_MEDIA.bs0 $EFI_BOOT_MEDIA.bs1 |
| 131 | $BASETOOLS_DIR/GnuGenBootSector -o $EFI_BOOT_MEDIA -i $EFI_BOOT_MEDIA.bs1 |
| 132 | rm $EFI_BOOT_MEDIA.bs[0-1] |
gikidy | 6976b5c | 2009-03-31 06:38:37 +0000 | [diff] [blame] | 133 | echo Done. |
| 134 | else |
| 135 | echo "Wrong FAT type" $4 "for floppy!" |
| 136 | fi |
| 137 | ;; |
| 138 | |
| 139 | usb) # CreateUsb |
| 140 | |
| 141 | if [ "$4" = FAT16 ] |
| 142 | then |
eric_tian | e843cdd | 2010-01-19 08:28:28 +0000 | [diff] [blame] | 143 | if [ "$6" = step2 ] |
gikidy | 6976b5c | 2009-03-31 06:38:37 +0000 | [diff] [blame] | 144 | then |
| 145 | cp $BUILD_DIR/FV/Efildr16 $EFI_BOOT_MEDIA |
| 146 | mkdir $EFI_BOOT_MEDIA/efi/boot |
eric_tian | e843cdd | 2010-01-19 08:28:28 +0000 | [diff] [blame] | 147 | if [ "$5" = IA32 ] |
| 148 | then |
Ruiyu Ni | 2790926 | 2014-11-25 08:53:33 +0000 | [diff] [blame] | 149 | cp $WORKSPACE/ShellBinPkg/UefiShell/Ia32/Shell.efi $EFI_BOOT_MEDIA/efi/boot/boot$5.efi |
eric_tian | e843cdd | 2010-01-19 08:28:28 +0000 | [diff] [blame] | 150 | else |
| 151 | if [ "$5" = X64 ] |
| 152 | then |
Ruiyu Ni | 2790926 | 2014-11-25 08:53:33 +0000 | [diff] [blame] | 153 | cp $WORKSPACE/ShellBinPkg/UefiShell/X64/Shell.efi $EFI_BOOT_MEDIA/efi/boot/boot$5.efi |
eric_tian | e843cdd | 2010-01-19 08:28:28 +0000 | [diff] [blame] | 154 | else |
| 155 | echo Wrong Arch! |
| 156 | fi |
| 157 | fi |
gikidy | 6976b5c | 2009-03-31 06:38:37 +0000 | [diff] [blame] | 158 | echo "step2 Done!" |
| 159 | else |
| 160 | echo Format $EFI_BOOT_DEVICE ... |
| 161 | #Do format command. |
| 162 | echo Create boot sector ... |
| 163 | ## Linux version of GenBootSector & Bootsectimage has not pass build yet. |
| 164 | $BASETOOLS_DIR/GnuGenBootSector -i $EFI_BOOT_DEVICE -o UsbBs16.com |
Eric Dong | bffaa26 | 2014-07-09 08:28:05 +0000 | [diff] [blame] | 165 | cp $BOOTSECTOR_BIN_DIR/bs16.com Bs16-1.com |
| 166 | $BASETOOLS_DIR/BootSectImage -g UsbBs16.com Bs16-1.com -f |
| 167 | $BASETOOLS_DIR/GnuGenBootSector -o $EFI_BOOT_DEVICE -i Bs16-1.com |
| 168 | rm Bs16-1.com |
klu2 | e88f305 | 2009-06-22 03:01:53 +0000 | [diff] [blame] | 169 | $BASETOOLS_DIR/GnuGenBootSector -m -o $EFI_BOOT_DEVICE -i $BOOTSECTOR_BIN_DIR/Mbr.com |
gikidy | 6976b5c | 2009-03-31 06:38:37 +0000 | [diff] [blame] | 170 | echo Done. |
| 171 | echo PLEASE UNPLUG USB, THEN PLUG IT AGAIN TO DO STEP2! |
| 172 | fi |
| 173 | elif [ "$4" = FAT32 ] |
| 174 | then |
eric_tian | e843cdd | 2010-01-19 08:28:28 +0000 | [diff] [blame] | 175 | if [ "$6" = step2 ] |
gikidy | 6976b5c | 2009-03-31 06:38:37 +0000 | [diff] [blame] | 176 | then |
| 177 | cp $BUILD_DIR/FV/Efildr20 $EFI_BOOT_MEDIA |
| 178 | mkdir $EFI_BOOT_MEDIA/efi/boot |
eric_tian | e843cdd | 2010-01-19 08:28:28 +0000 | [diff] [blame] | 179 | if [ "$5" = IA32 ] |
| 180 | then |
Ruiyu Ni | 2790926 | 2014-11-25 08:53:33 +0000 | [diff] [blame] | 181 | cp $WORKSPACE/ShellBinPkg/UefiShell/Ia32/Shell.efi $EFI_BOOT_MEDIA/efi/boot/boot$5.efi |
eric_tian | e843cdd | 2010-01-19 08:28:28 +0000 | [diff] [blame] | 182 | else |
| 183 | if [ "$5" = X64 ] |
| 184 | then |
Ruiyu Ni | 2790926 | 2014-11-25 08:53:33 +0000 | [diff] [blame] | 185 | cp $WORKSPACE/ShellBinPkg/UefiShell/X64/Shell.efi $EFI_BOOT_MEDIA/efi/boot/boot$5.efi |
eric_tian | e843cdd | 2010-01-19 08:28:28 +0000 | [diff] [blame] | 186 | else |
| 187 | echo Wrong Arch! |
| 188 | fi |
| 189 | fi |
gikidy | 6976b5c | 2009-03-31 06:38:37 +0000 | [diff] [blame] | 190 | echo "step2 Done!" |
| 191 | else |
| 192 | echo Format $EFI_BOOT_DEVICE ... |
| 193 | #Do format command. |
| 194 | echo Create boot sector ... |
| 195 | ## Linux version of GenBootSector & Bootsectimage has not pass build yet. |
| 196 | $BASETOOLS_DIR/GnuGenBootSector -i $EFI_BOOT_DEVICE -o UsbBs32.com |
Eric Dong | bffaa26 | 2014-07-09 08:28:05 +0000 | [diff] [blame] | 197 | cp $BOOTSECTOR_BIN_DIR/bs32.com Bs32-1.com |
| 198 | $BASETOOLS_DIR/BootSectImage -g UsbBs32.com Bs32-1.com -f |
| 199 | $BASETOOLS_DIR/GnuGenBootSector -o $EFI_BOOT_DEVICE -i Bs32-1.com |
| 200 | rm Bs32-1.com |
klu2 | e88f305 | 2009-06-22 03:01:53 +0000 | [diff] [blame] | 201 | $BASETOOLS_DIR/GnuGenBootSector -m -o $EFI_BOOT_DEVICE -i $BOOTSECTOR_BIN_DIR/Mbr.com |
gikidy | 6976b5c | 2009-03-31 06:38:37 +0000 | [diff] [blame] | 202 | echo Done. |
| 203 | echo PLEASE UNPLUG USB, THEN PLUG IT AGAIN TO DO STEP2! |
| 204 | fi |
| 205 | else |
| 206 | echo "Wrong FAT type $1 for floppy!" |
| 207 | fi |
| 208 | |
| 209 | ;; |
| 210 | |
| 211 | ide) # CreateIde |
| 212 | echo "Not support yet!" |
gikidy | 5b7021e | 2009-03-03 06:27:07 +0000 | [diff] [blame] | 213 | ;; |
gikidy | 6976b5c | 2009-03-31 06:38:37 +0000 | [diff] [blame] | 214 | *) |
| 215 | echo "Arg1 should be [floppy | file | usb | ide] !" |
gikidy | 5b7021e | 2009-03-03 06:27:07 +0000 | [diff] [blame] | 216 | |
gikidy | 6976b5c | 2009-03-31 06:38:37 +0000 | [diff] [blame] | 217 | esac |
| 218 | fi |