summaryrefslogtreecommitdiff
path: root/DuetPkg/CreateBootDisk.sh
blob: 897ba9bc9369cfb193d0c026b02726c6a9a931f2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
#! /bin/sh

## @file
#
#  Copyright (c) 2010 - 2014, Intel Corporation. All rights reserved.<BR>
#
#  This program and the accompanying materials
#  are licensed and made available under the terms and conditions of the BSD License
#  which accompanies this distribution. The full text of the license may be found at
#  http://opensource.org/licenses/bsd-license.php
#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#
#
##

# Set up environment at fisrt.

if [ -z "$EDK_TOOLS_PATH" ]
then
export BASETOOLS_DIR=$WORKSPACE/Conf/BaseToolsSource/Source/C/bin
else
export BASETOOLS_DIR=$EDK_TOOLS_PATH/Source/C/bin
fi

export BOOTSECTOR_BIN_DIR=$WORKSPACE/DuetPkg/BootSector/bin
export DISK_LABEL=DUET
export PROCESS_MARK=TRUE

if [ \
     -z "$*" -o \
     "$*" = "-?" -o \
     "$*" = "-h" -o \
     "$*" = "--help" \
   ]
then
    echo "Usage: CreateBootDisk [usb|floppy|ide|file] MediaPath DevicePath [FAT12|FAT16|FAT32] [IA32|X64]"
    echo "e.g. : CreateBootDisk floppy /media/floppy0 /dev/fd0 FAT12 IA32"
    PROCESS_MARK=FALSE
fi

case "$5" in
   IA32)
     export PROCESSOR=IA32
     ;;
   X64)
     export PROCESSOR=X64
     ;;
   *)
     echo Invalid Architecture string, should be only IA32 or X64
     return 1
esac

. $WORKSPACE/DuetPkg/SetEnv_$PROCESSOR.sh
export BUILD_DIR=$WORKSPACE/Build/DuetPkg$PROCESSOR/DEBUG_$TOOLCHAIN


export EFI_BOOT_MEDIA=$2
export EFI_BOOT_DEVICE=$3

if [ "$PROCESS_MARK" = TRUE ]
then
    case "$1" in
        floppy)
            if [ "$4" = FAT12 ]
            then
                echo Start to create floppy boot disk ...
                echo Format $EFI_BOOT_MEDIA ...
                ## Format floppy disk
                umount $EFI_BOOT_MEDIA
                mkfs.msdos $EFI_BOOT_DEVICE
                mount $EFI_BOOT_DEVICE $EFI_BOOT_MEDIA
                echo Create boot sector ...
                ## Linux version of GenBootSector has not pass build yet.
                $BASETOOLS_DIR/GnuGenBootSector -i $EFI_BOOT_DEVICE -o FDBs.com
                cp $BOOTSECTOR_BIN_DIR/bootsect.com FDBs-1.com
                $BASETOOLS_DIR/BootSectImage -g FDBs.com FDBs-1.com -f
                $BASETOOLS_DIR/GnuGenBootSector -o $EFI_BOOT_DEVICE -i FDBs-1.com
                rm FDBs-1.com
                cp $BUILD_DIR/FV/Efildr $EFI_BOOT_MEDIA

                mkdir -p $EFI_BOOT_MEDIA/efi
                mkdir -p $EFI_BOOT_MEDIA/efi/boot
                if [ "$5" = IA32 ]
                then
                    cp $WORKSPACE/ShellBinPkg/UefiShell/Ia32/Shell.efi $EFI_BOOT_MEDIA/efi/boot/boot$5.efi
                else
                    if [ "$5" = X64 ]
                    then
                        cp $WORKSPACE/ShellBinPkg/UefiShell/X64/Shell.efi $EFI_BOOT_MEDIA/efi/boot/boot$5.efi
                    else
                        echo Wrong Arch!
                    fi
                fi
                echo Done.
            else
                echo "Wrong FAT type $4 for floppy!"
            fi
            ;;

        file) # CreateFile
            if [ "$4" = FAT12 ]
                then
                echo "Start to create file boot disk ..."
                dd bs=512 count=2880 if=/dev/zero of=$EFI_BOOT_MEDIA
                mkfs.msdos -F 12 $EFI_BOOT_MEDIA

                mcopy -i $EFI_BOOT_MEDIA $BUILD_DIR/FV/Efildr ::/Efildr
                mmd -i $EFI_BOOT_MEDIA ::/efi ::/efi/boot
                if [ "$5" = IA32 ]
                then
                    mcopy -i $EFI_BOOT_MEDIA $WORKSPACE/ShellBinPkg/UefiShell/Ia32/Shell.efi ::/efi/boot/boot$5.efi
                elif [ "$5" = X64 ]
                then
                    mcopy -i $EFI_BOOT_MEDIA $WORKSPACE/ShellBinPkg/UefiShell/X64/Shell.efi ::/efi/boot/boot$5.efi
                else
                    echo Wrong Arch!
                fi
                mdir -i $EFI_BOOT_MEDIA -s ::

                ## Linux version of GenBootSector has not pass build yet.
                $BASETOOLS_DIR/GnuGenBootSector -i $EFI_BOOT_MEDIA -o $EFI_BOOT_MEDIA.bs0
                cp $BOOTSECTOR_BIN_DIR/bootsect.com $EFI_BOOT_MEDIA.bs1
                $BASETOOLS_DIR/BootSectImage -g $EFI_BOOT_MEDIA.bs0 $EFI_BOOT_MEDIA.bs1
                $BASETOOLS_DIR/GnuGenBootSector -o $EFI_BOOT_MEDIA -i $EFI_BOOT_MEDIA.bs1
                rm $EFI_BOOT_MEDIA.bs[0-1]
                echo Done.
            else
                echo "Wrong FAT type" $4 "for floppy!"
            fi
            ;;

        usb) # CreateUsb

            if [ "$4" = FAT16 ]
            then
                if [ "$6" = step2 ]
                then
                    cp $BUILD_DIR/FV/Efildr16 $EFI_BOOT_MEDIA
                    mkdir $EFI_BOOT_MEDIA/efi/boot
                    if [ "$5" = IA32 ]
                    then
                        cp $WORKSPACE/ShellBinPkg/UefiShell/Ia32/Shell.efi $EFI_BOOT_MEDIA/efi/boot/boot$5.efi
                    else
                        if [ "$5" = X64 ]
                        then
                            cp $WORKSPACE/ShellBinPkg/UefiShell/X64/Shell.efi $EFI_BOOT_MEDIA/efi/boot/boot$5.efi
                        else
                            echo Wrong Arch!
                        fi
                    fi
                    echo "step2 Done!"
                else
                    echo Format $EFI_BOOT_DEVICE ...
                    #Do format command.
                    echo Create boot sector ...
                    ## Linux version of GenBootSector & Bootsectimage has not pass build yet.
                    $BASETOOLS_DIR/GnuGenBootSector -i $EFI_BOOT_DEVICE -o UsbBs16.com
                    cp $BOOTSECTOR_BIN_DIR/bs16.com Bs16-1.com
                    $BASETOOLS_DIR/BootSectImage -g UsbBs16.com Bs16-1.com -f
                    $BASETOOLS_DIR/GnuGenBootSector -o $EFI_BOOT_DEVICE -i Bs16-1.com
                    rm Bs16-1.com
                    $BASETOOLS_DIR/GnuGenBootSector -m -o $EFI_BOOT_DEVICE -i $BOOTSECTOR_BIN_DIR/Mbr.com
                    echo Done.
                    echo PLEASE UNPLUG USB, THEN PLUG IT AGAIN TO DO STEP2!
                fi
            elif [ "$4" = FAT32 ]
            then
                if [ "$6" = step2 ]
                then
                    cp $BUILD_DIR/FV/Efildr20 $EFI_BOOT_MEDIA
                    mkdir $EFI_BOOT_MEDIA/efi/boot
                    if [ "$5" = IA32 ]
                    then
                        cp $WORKSPACE/ShellBinPkg/UefiShell/Ia32/Shell.efi $EFI_BOOT_MEDIA/efi/boot/boot$5.efi
                    else
                        if [ "$5" = X64 ]
                        then
                            cp $WORKSPACE/ShellBinPkg/UefiShell/X64/Shell.efi $EFI_BOOT_MEDIA/efi/boot/boot$5.efi
                        else
                            echo Wrong Arch!
                        fi
                    fi
                    echo "step2 Done!"
                else
                    echo Format $EFI_BOOT_DEVICE ...
                    #Do format command.
                    echo Create boot sector ...
                    ## Linux version of GenBootSector & Bootsectimage has not pass build yet.
                    $BASETOOLS_DIR/GnuGenBootSector -i $EFI_BOOT_DEVICE -o UsbBs32.com
                    cp $BOOTSECTOR_BIN_DIR/bs32.com Bs32-1.com
                    $BASETOOLS_DIR/BootSectImage -g UsbBs32.com Bs32-1.com -f
                    $BASETOOLS_DIR/GnuGenBootSector -o $EFI_BOOT_DEVICE -i Bs32-1.com
                    rm Bs32-1.com
                    $BASETOOLS_DIR/GnuGenBootSector -m -o $EFI_BOOT_DEVICE -i $BOOTSECTOR_BIN_DIR/Mbr.com
                    echo Done.
                    echo PLEASE UNPLUG USB, THEN PLUG IT AGAIN TO DO STEP2!
                fi
            else
                echo "Wrong FAT type $1 for floppy!"
            fi

            ;;

        ide) # CreateIde
        echo "Not support yet!"
        ;;
        *)
        echo "Arg1 should be [floppy | file | usb | ide] !"

    esac
fi