klu2 | ab9cb4b | 2010-03-18 02:36:52 +0000 | [diff] [blame] | 1 | #! /bin/sh |
| 2 | |
| 3 | ## @file |
| 4 | # |
hhtian | b1f700a | 2010-04-28 12:39:50 +0000 | [diff] [blame] | 5 | # Copyright (c) 2010, 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 |
klu2 | e88f305 | 2009-06-22 03:01:53 +0000 | [diff] [blame] | 82 | $BASETOOLS_DIR/BootSectImage -g FDBs.com $BOOTSECTOR_BIN_DIR/bootsect.com -f |
| 83 | $BASETOOLS_DIR/GnuGenBootSector -o $EFI_BOOT_DEVICE -i $BOOTSECTOR_BIN_DIR/bootsect.com |
gikidy | 6976b5c | 2009-03-31 06:38:37 +0000 | [diff] [blame] | 84 | |
| 85 | cp $BUILD_DIR/FV/Efildr $EFI_BOOT_MEDIA |
| 86 | |
| 87 | mkdir -p $EFI_BOOT_MEDIA/efi |
| 88 | mkdir -p $EFI_BOOT_MEDIA/efi/boot |
eric_tian | e843cdd | 2010-01-19 08:28:28 +0000 | [diff] [blame] | 89 | if [ "$5" = IA32 ] |
| 90 | then |
| 91 | cp $WORKSPACE/EdkShellBinPkg/MinimumShell/Ia32/Shell.efi $EFI_BOOT_MEDIA/efi/boot/bootia32.efi |
| 92 | else |
| 93 | if [ "$5" = X64 ] |
| 94 | then |
| 95 | cp $WORKSPACE/EdkShellBinPkg/MinimumShell/X64/Shell.efi $EFI_BOOT_MEDIA/efi/boot/bootx64.efi |
| 96 | else |
| 97 | echo Wrong Arch! |
| 98 | fi |
| 99 | fi |
gikidy | 5b7021e | 2009-03-03 06:27:07 +0000 | [diff] [blame] | 100 | echo Done. |
gikidy | 6976b5c | 2009-03-31 06:38:37 +0000 | [diff] [blame] | 101 | else |
| 102 | echo "Wrong FAT type $4 for floppy!" |
gikidy | 5b7021e | 2009-03-03 06:27:07 +0000 | [diff] [blame] | 103 | fi |
gikidy | 6976b5c | 2009-03-31 06:38:37 +0000 | [diff] [blame] | 104 | ;; |
| 105 | |
| 106 | file) # CreateFile |
| 107 | if [ "$4" = FAT12 ] |
| 108 | then |
| 109 | echo "Start to create file boot disk ..." |
jljusten | 5c1138b | 2010-10-16 18:50:43 +0000 | [diff] [blame] | 110 | dd bs=512 count=2880 if=/dev/zero of=$EFI_BOOT_MEDIA |
| 111 | mkfs.msdos -F 12 $EFI_BOOT_MEDIA |
| 112 | |
| 113 | mcopy -i $EFI_BOOT_MEDIA $BUILD_DIR/FV/Efildr ::/Efildr |
| 114 | mmd -i $EFI_BOOT_MEDIA ::/efi ::/efi/boot |
| 115 | if [ "$5" = IA32 ] |
| 116 | then |
| 117 | mcopy -i $EFI_BOOT_MEDIA $WORKSPACE/EdkShellBinPkg/MinimumShell/Ia32/Shell.efi ::/efi/boot/bootia32.efi |
| 118 | elif [ "$5" = X64 ] |
| 119 | then |
| 120 | mcopy -i $EFI_BOOT_MEDIA $WORKSPACE/EdkShellBinPkg/MinimumShell/X64/Shell.efi ::/efi/boot/bootx64.efi |
| 121 | else |
| 122 | echo Wrong Arch! |
| 123 | fi |
| 124 | mdir -i $EFI_BOOT_MEDIA -s :: |
| 125 | |
gikidy | 6976b5c | 2009-03-31 06:38:37 +0000 | [diff] [blame] | 126 | ## Linux version of GenBootSector has not pass build yet. |
jljusten | 5c1138b | 2010-10-16 18:50:43 +0000 | [diff] [blame] | 127 | $BASETOOLS_DIR/GnuGenBootSector -i $EFI_BOOT_MEDIA -o $EFI_BOOT_MEDIA.bs0 |
jljusten | 8df0bd2 | 2010-12-06 06:06:54 +0000 | [diff] [blame^] | 128 | cp $BOOTSECTOR_BIN_DIR/bootsect.com $EFI_BOOT_MEDIA.bs1 |
| 129 | $BASETOOLS_DIR/BootSectImage -g $EFI_BOOT_MEDIA.bs0 $EFI_BOOT_MEDIA.bs1 |
| 130 | $BASETOOLS_DIR/GnuGenBootSector -o $EFI_BOOT_MEDIA -i $EFI_BOOT_MEDIA.bs1 |
| 131 | rm $EFI_BOOT_MEDIA.bs[0-1] |
gikidy | 6976b5c | 2009-03-31 06:38:37 +0000 | [diff] [blame] | 132 | echo Done. |
| 133 | else |
| 134 | echo "Wrong FAT type" $4 "for floppy!" |
| 135 | fi |
| 136 | ;; |
| 137 | |
| 138 | usb) # CreateUsb |
| 139 | |
| 140 | if [ "$4" = FAT16 ] |
| 141 | then |
eric_tian | e843cdd | 2010-01-19 08:28:28 +0000 | [diff] [blame] | 142 | if [ "$6" = step2 ] |
gikidy | 6976b5c | 2009-03-31 06:38:37 +0000 | [diff] [blame] | 143 | then |
| 144 | cp $BUILD_DIR/FV/Efildr16 $EFI_BOOT_MEDIA |
| 145 | mkdir $EFI_BOOT_MEDIA/efi/boot |
eric_tian | e843cdd | 2010-01-19 08:28:28 +0000 | [diff] [blame] | 146 | if [ "$5" = IA32 ] |
| 147 | then |
| 148 | cp $WORKSPACE/EdkShellBinPkg/MinimumShell/Ia32/Shell.efi $EFI_BOOT_MEDIA/efi/boot/bootia32.efi |
| 149 | else |
| 150 | if [ "$5" = X64 ] |
| 151 | then |
| 152 | cp $WORKSPACE/EdkShellBinPkg/MinimumShell/X64/Shell.efi $EFI_BOOT_MEDIA/efi/boot/bootx64.efi |
| 153 | else |
| 154 | echo Wrong Arch! |
| 155 | fi |
| 156 | fi |
gikidy | 6976b5c | 2009-03-31 06:38:37 +0000 | [diff] [blame] | 157 | echo "step2 Done!" |
| 158 | else |
| 159 | echo Format $EFI_BOOT_DEVICE ... |
| 160 | #Do format command. |
| 161 | echo Create boot sector ... |
| 162 | ## Linux version of GenBootSector & Bootsectimage has not pass build yet. |
| 163 | $BASETOOLS_DIR/GnuGenBootSector -i $EFI_BOOT_DEVICE -o UsbBs16.com |
klu2 | e88f305 | 2009-06-22 03:01:53 +0000 | [diff] [blame] | 164 | $BASETOOLS_DIR/BootSectImage -g UsbBs16.com $BOOTSECTOR_BIN_DIR/bs16.com -f |
| 165 | $BASETOOLS_DIR/GnuGenBootSector -o $EFI_BOOT_DEVICE -i $BOOTSECTOR_BIN_DIR/bs16.com |
| 166 | $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] | 167 | echo Done. |
| 168 | echo PLEASE UNPLUG USB, THEN PLUG IT AGAIN TO DO STEP2! |
| 169 | fi |
| 170 | elif [ "$4" = FAT32 ] |
| 171 | then |
eric_tian | e843cdd | 2010-01-19 08:28:28 +0000 | [diff] [blame] | 172 | if [ "$6" = step2 ] |
gikidy | 6976b5c | 2009-03-31 06:38:37 +0000 | [diff] [blame] | 173 | then |
| 174 | cp $BUILD_DIR/FV/Efildr20 $EFI_BOOT_MEDIA |
| 175 | mkdir $EFI_BOOT_MEDIA/efi/boot |
eric_tian | e843cdd | 2010-01-19 08:28:28 +0000 | [diff] [blame] | 176 | if [ "$5" = IA32 ] |
| 177 | then |
| 178 | cp $WORKSPACE/EdkShellBinPkg/MinimumShell/Ia32/Shell.efi $EFI_BOOT_MEDIA/efi/boot/bootia32.efi |
| 179 | else |
| 180 | if [ "$5" = X64 ] |
| 181 | then |
| 182 | cp $WORKSPACE/EdkShellBinPkg/MinimumShell/X64/Shell.efi $EFI_BOOT_MEDIA/efi/boot/bootx64.efi |
| 183 | else |
| 184 | echo Wrong Arch! |
| 185 | fi |
| 186 | fi |
gikidy | 6976b5c | 2009-03-31 06:38:37 +0000 | [diff] [blame] | 187 | echo "step2 Done!" |
| 188 | else |
| 189 | echo Format $EFI_BOOT_DEVICE ... |
| 190 | #Do format command. |
| 191 | echo Create boot sector ... |
| 192 | ## Linux version of GenBootSector & Bootsectimage has not pass build yet. |
| 193 | $BASETOOLS_DIR/GnuGenBootSector -i $EFI_BOOT_DEVICE -o UsbBs32.com |
klu2 | e88f305 | 2009-06-22 03:01:53 +0000 | [diff] [blame] | 194 | $BASETOOLS_DIR/BootSectImage -g UsbBs32.com $BOOTSECTOR_BIN_DIR/bs32.com -f |
| 195 | $BASETOOLS_DIR/GnuGenBootSector -o $EFI_BOOT_DEVICE -i $BOOTSECTOR_BIN_DIR/bs32.com |
| 196 | $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] | 197 | echo Done. |
| 198 | echo PLEASE UNPLUG USB, THEN PLUG IT AGAIN TO DO STEP2! |
| 199 | fi |
| 200 | else |
| 201 | echo "Wrong FAT type $1 for floppy!" |
| 202 | fi |
| 203 | |
| 204 | ;; |
| 205 | |
| 206 | ide) # CreateIde |
| 207 | echo "Not support yet!" |
gikidy | 5b7021e | 2009-03-03 06:27:07 +0000 | [diff] [blame] | 208 | ;; |
gikidy | 6976b5c | 2009-03-31 06:38:37 +0000 | [diff] [blame] | 209 | *) |
| 210 | echo "Arg1 should be [floppy | file | usb | ide] !" |
gikidy | 5b7021e | 2009-03-03 06:27:07 +0000 | [diff] [blame] | 211 | |
gikidy | 6976b5c | 2009-03-31 06:38:37 +0000 | [diff] [blame] | 212 | esac |
| 213 | fi |