Make sure all IDT fields are initialized
[helenos.git] / tools / grub / grub-update.sh
blob6e1ab258bd448bdf9bfb60d34960069844d4e226
1 #!/bin/bash
3 # Copyright (c) 2016 Jiri Svoboda
4 # All rights reserved.
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
8 # are met:
10 # - Redistributions of source code must retain the above copyright
11 # notice, this list of conditions and the following disclaimer.
12 # - Redistributions in binary form must reproduce the above copyright
13 # notice, this list of conditions and the following disclaimer in the
14 # documentation and/or other materials provided with the distribution.
15 # - The name of the author may not be used to endorse or promote products
16 # derived from this software without specific prior written permission.
18 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 # Script to generate/update prebuilt Grub2 in HelenOS source tree
32 # Be sure you know what you are doing!
35 origdir="$(cd "$(dirname "$0")" && pwd)"
36 helenosdir="$origdir/../.."
37 workdir="$origdir/grub-src"
38 builddir="$origdir/grub-build"
39 git_repo="git://git.savannah.gnu.org/grub.git"
40 grub_rev="bc220962e366b1b46769ed6f9fa5be603ba58ab5"
42 function grub_build()
44 target="$1"
45 platform="$2"
47 ./configure --prefix="$builddir/$target-$platform" --target="$target" --with-platform="$platform" || exit 1
48 make clean || exit 1
49 make install || exit 1
52 function grub_files_update()
54 gdir="$1"
55 platform="$2"
57 rm -rf "$helenosdir"/boot/"$gdir"/"$platform" || exit 1
58 cp -R "$builddir"/"$platform"/lib64/grub/"$platform" "$helenosdir"/boot/"$gdir" || exit 1
59 rm -f "$helenosdir"/boot/"$gdir"/"$platform"/*.image || exit 1
60 rm -f "$helenosdir"/boot/"$gdir"/"$platform"/*.module || exit 1
61 git add "$helenosdir"/boot/"$gdir"/"$platform" || exit 1
64 # Prepare a clone of Grub2 repo
65 if [ ! -d "$workdir" ] ; then
66 rm -rf "$workdir" "$builddir" || exit 1
67 git clone "$git_repo" "$workdir" || exit 1
70 cd "$workdir" || exit 1
71 git pull || exit 1
72 git reset --hard "$grub_rev" || exit 1
74 echo "$grub_rev" >"$helenosdir"/boot/grub.pc/REVISION || exit 1
75 echo "$grub_rev" > "$helenosdir"/boot/grub.efi/REVISION || exit 1
77 # Build each platform to a different directory
78 ./autogen.sh || exit 1
79 grub_build i386 pc
80 grub_build i386 efi
81 grub_build x86_64 efi
83 # Extract El Torrito boot image for i386-pc
84 cd "$helenosdir"/boot/grub.pc || exit 1
85 rm -f pc.img || exit 1
86 "$builddir"/i386-pc/bin/grub-mkrescue -o phony --xorriso="$origdir/getimage.sh" || exit 1
88 # Extract El Torrito boot image for i386-efi
89 cd "$helenosdir"/boot/grub.efi || exit 1
90 rm -f efi.img.gz || exit 1
91 "$builddir"/i386-efi/bin/grub-mkrescue -o phony --xorriso="$origdir/getimage.sh" || exit 1
92 mv efi.img i386-efi.img
94 # Extract El Torrito boot image for x86_64-efi
95 cd "$helenosdir"/boot/grub.efi || exit 1
96 rm -f efi.img.gz || exit 1
97 "$builddir"/x86_64-efi/bin/grub-mkrescue -o phony --xorriso="$origdir/getimage.sh" || exit 1
99 # Combine El Torrito boot images for x86_64-efi and i386-efi
100 mkdir tmp || exit 1
101 mcopy -ns -i i386-efi.img ::efi tmp || exit 1
102 mcopy -s -i efi.img tmp/* :: || exit 1
103 gzip efi.img || exit 1
104 rm -rf tmp || exit 1
105 rm -f i386-efi.img || exit 1
107 # Update Grub files for all platforms
108 grub_files_update grub.pc i386-pc
109 grub_files_update grub.efi i386-efi
110 grub_files_update grub.efi x86_64-efi
112 echo "GRUB update successful."