[2f2dd126] | 1 | #!/bin/bash
|
---|
| 2 | #
|
---|
| 3 | # Copyright (c) 2016 Jiri Svoboda
|
---|
| 4 | # All rights reserved.
|
---|
| 5 | #
|
---|
| 6 | # Redistribution and use in source and binary forms, with or without
|
---|
| 7 | # modification, are permitted provided that the following conditions
|
---|
| 8 | # are met:
|
---|
| 9 | #
|
---|
| 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.
|
---|
| 17 | #
|
---|
| 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.
|
---|
| 28 | #
|
---|
| 29 |
|
---|
| 30 | #
|
---|
| 31 | # Script to generate/update prebuilt Grub2 in HelenOS source tree
|
---|
| 32 | # Be sure you know what you are doing!
|
---|
| 33 | #
|
---|
| 34 |
|
---|
[3876300] | 35 | origdir="$(cd "$(dirname "$0")" && pwd)"
|
---|
[2f2dd126] | 36 | helenosdir="$origdir/../.."
|
---|
[3876300] | 37 | workdir="$origdir/grub-src"
|
---|
| 38 | builddir="$origdir/grub-build"
|
---|
[2f2dd126] | 39 | git_repo="git://git.savannah.gnu.org/grub.git"
|
---|
| 40 | grub_rev="bc220962e366b1b46769ed6f9fa5be603ba58ab5"
|
---|
| 41 |
|
---|
[b1478ff] | 42 | build_ia32amd64_pc=false
|
---|
| 43 | build_ia32amd64_efi=false
|
---|
| 44 | build_arm64_efi=false
|
---|
| 45 |
|
---|
[2f2dd126] | 46 | function grub_build()
|
---|
| 47 | {
|
---|
[b1478ff] | 48 | platform="$1"
|
---|
| 49 | conf_target="$2"
|
---|
| 50 | conf_platform="$3"
|
---|
[2f2dd126] | 51 |
|
---|
[b1478ff] | 52 | ./configure --prefix="$builddir/$platform" --target="$conf_target" --with-platform="$conf_platform" --disable-werror || exit 1
|
---|
[2f2dd126] | 53 | make clean || exit 1
|
---|
| 54 | make install || exit 1
|
---|
| 55 | }
|
---|
| 56 |
|
---|
| 57 | function grub_files_update()
|
---|
| 58 | {
|
---|
| 59 | gdir="$1"
|
---|
| 60 | platform="$2"
|
---|
| 61 |
|
---|
[b1478ff] | 62 | echo "$grub_rev" > "$helenosdir"/boot/grub/"$gdir"/REVISION || exit 1
|
---|
| 63 | rm -rf "$helenosdir"/boot/grub/"$gdir"/"$platform" || exit 1
|
---|
| 64 | cp -R "$builddir"/"$platform"/lib*/grub/"$platform" "$helenosdir"/boot/grub/"$gdir" || exit 1
|
---|
| 65 | rm -f "$helenosdir"/boot/grub/"$gdir"/"$platform"/*.image || exit 1
|
---|
| 66 | rm -f "$helenosdir"/boot/grub/"$gdir"/"$platform"/*.module || exit 1
|
---|
| 67 | git add "$helenosdir"/boot/grub/"$gdir"/"$platform" || exit 1
|
---|
| 68 | }
|
---|
| 69 |
|
---|
| 70 | function show_usage()
|
---|
| 71 | {
|
---|
| 72 | echo "Script to generate/update prebuild Grub2 in HelenOS source tree"
|
---|
| 73 | echo
|
---|
| 74 | echo "Syntax:"
|
---|
| 75 | echo " $0 <target>"
|
---|
| 76 | echo
|
---|
| 77 | echo "Possible targets are:"
|
---|
| 78 | echo " ia32+amd64-pc"
|
---|
| 79 | echo " ia32+amd64-efi"
|
---|
| 80 | echo " arm64-efi"
|
---|
| 81 | echo " all build all targets"
|
---|
| 82 | echo
|
---|
| 83 |
|
---|
| 84 | exit 3
|
---|
[2f2dd126] | 85 | }
|
---|
| 86 |
|
---|
[b1478ff] | 87 | if [ "$#" -ne "1" ] ; then
|
---|
| 88 | show_usage
|
---|
| 89 | fi
|
---|
| 90 |
|
---|
| 91 | case "$1" in
|
---|
| 92 | ia32+amd64-pc)
|
---|
| 93 | build_ia32amd64_pc=true
|
---|
| 94 | ;;
|
---|
| 95 | ia32+amd64-efi)
|
---|
| 96 | build_ia32amd64_efi=true
|
---|
| 97 | ;;
|
---|
| 98 | arm64-efi)
|
---|
| 99 | build_arm64_efi=true
|
---|
| 100 | ;;
|
---|
| 101 | all)
|
---|
| 102 | build_ia32amd64_pc=true
|
---|
| 103 | build_ia32amd64_efi=true
|
---|
| 104 | build_arm64_efi=true
|
---|
| 105 | ;;
|
---|
| 106 | *)
|
---|
| 107 | show_usage
|
---|
| 108 | ;;
|
---|
| 109 | esac
|
---|
| 110 |
|
---|
[2f2dd126] | 111 | # Prepare a clone of Grub2 repo
|
---|
| 112 | if [ ! -d "$workdir" ] ; then
|
---|
| 113 | rm -rf "$workdir" "$builddir" || exit 1
|
---|
| 114 | git clone "$git_repo" "$workdir" || exit 1
|
---|
| 115 | fi
|
---|
[5b39be2] | 116 |
|
---|
| 117 | cd "$workdir" || exit 1
|
---|
| 118 | git pull || exit 1
|
---|
| 119 | git reset --hard "$grub_rev" || exit 1
|
---|
| 120 |
|
---|
[2f2dd126] | 121 | ./autogen.sh || exit 1
|
---|
[b1478ff] | 122 |
|
---|
| 123 | if $build_ia32amd64_pc ; then
|
---|
| 124 | cd "$workdir" || exit 1
|
---|
| 125 | grub_build i386-pc i386 pc
|
---|
| 126 |
|
---|
| 127 | # Extract El Torrito boot image for i386-pc
|
---|
| 128 | cd "$helenosdir"/boot/grub/ia32-pc || exit 1
|
---|
| 129 | rm -f pc.img || exit 1
|
---|
| 130 | "$builddir"/i386-pc/bin/grub-mkrescue -o phony --xorriso="$origdir/getimage.sh" || exit 1
|
---|
| 131 |
|
---|
| 132 | grub_files_update ia32-pc i386-pc
|
---|
| 133 | fi
|
---|
| 134 |
|
---|
| 135 | if $build_ia32amd64_efi ; then
|
---|
| 136 | cd "$workdir" || exit 1
|
---|
| 137 |
|
---|
| 138 | # Build each platform to a different directory
|
---|
| 139 | grub_build i386-efi i386 efi
|
---|
| 140 | grub_build x86_64-efi x86_64 efi
|
---|
| 141 |
|
---|
| 142 | # Extract El Torrito boot image for i386-efi
|
---|
| 143 | cd "$helenosdir"/boot/grub/ia32-efi || exit 1
|
---|
| 144 | rm -f efi.img.gz || exit 1
|
---|
| 145 | "$builddir"/i386-efi/bin/grub-mkrescue -o phony --xorriso="$origdir/getimage.sh" || exit 1
|
---|
| 146 | mv efi.img i386-efi.img
|
---|
| 147 |
|
---|
| 148 | # Extract El Torrito boot image for x86_64-efi
|
---|
| 149 | cd "$helenosdir"/boot/grub/ia32-efi || exit 1
|
---|
| 150 | rm -f efi.img.gz || exit 1
|
---|
| 151 | "$builddir"/x86_64-efi/bin/grub-mkrescue -o phony --xorriso="$origdir/getimage.sh" || exit 1
|
---|
| 152 |
|
---|
| 153 | # Combine El Torrito boot images for x86_64-efi and i386-efi
|
---|
| 154 | mkdir tmp || exit 1
|
---|
| 155 | mcopy -ns -i i386-efi.img ::efi tmp || exit 1
|
---|
| 156 | mcopy -s -i efi.img tmp/* :: || exit 1
|
---|
| 157 | gzip efi.img || exit 1
|
---|
| 158 | rm -rf tmp || exit 1
|
---|
| 159 | rm -f i386-efi.img || exit 1
|
---|
| 160 |
|
---|
| 161 | # Update Grub files for all platforms
|
---|
| 162 | grub_files_update ia32-efi i386-efi
|
---|
| 163 | grub_files_update ia32-efi x86_64-efi
|
---|
| 164 | fi
|
---|
| 165 |
|
---|
| 166 | if $build_arm64_efi ; then
|
---|
| 167 | cd "$workdir" || exit 1
|
---|
| 168 |
|
---|
| 169 | # Check that the expected compiler is present on PATH
|
---|
| 170 | if ! [ -x "$(command -v aarch64-linux-gnu-gcc)" ] ; then
|
---|
| 171 | echo "Error: aarch64-linux-gnu-gcc is missing" >&2
|
---|
| 172 | exit 1
|
---|
| 173 | fi
|
---|
| 174 |
|
---|
| 175 | grub_build arm64-efi aarch64-linux-gnu efi
|
---|
| 176 |
|
---|
| 177 | # Extract El Torrito boot image for arm64-efi
|
---|
| 178 | cd "$helenosdir"/boot/grub/arm64-efi || exit 1
|
---|
| 179 | rm -f efi.img.gz || exit 1
|
---|
| 180 | "$builddir"/arm64-efi/bin/grub-mkrescue -o phony --xorriso="$origdir/getimage.sh" || exit 1
|
---|
| 181 | gzip efi.img || exit 1
|
---|
| 182 |
|
---|
| 183 | grub_files_update arm64-efi arm64-efi
|
---|
| 184 | fi
|
---|
[2f2dd126] | 185 |
|
---|
| 186 | echo "GRUB update successful."
|
---|