source: mainline/tools/grub/grub-update.sh@ 5b39be2

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 5b39be2 was 5b39be2, checked in by Jiri Svoboda <jiri@…>, 9 years ago

Reset to the right revision even if clone does not exist yet.

  • Property mode set to 100755
File size: 3.8 KB
Line 
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
35origdir="$(pwd)"
36helenosdir="$origdir/../.."
37workdir="$(pwd)/grub-src"
38builddir="$(pwd)/grub-build"
39git_repo="git://git.savannah.gnu.org/grub.git"
40grub_rev="bc220962e366b1b46769ed6f9fa5be603ba58ab5"
41
42function grub_build()
43{
44 target="$1"
45 platform="$2"
46
47 ./configure --prefix="$builddir/$target-$platform" --target="$target" --with-platform="$platform" || exit 1
48 make clean || exit 1
49 make install || exit 1
50}
51
52function grub_files_update()
53{
54 gdir="$1"
55 platform="$2"
56
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 bzr add "$helenosdir"/boot/"$gdir"/"$platform" || exit 1
61}
62
63# Prepare a clone of Grub2 repo
64if [ ! -d "$workdir" ] ; then
65 rm -rf "$workdir" "$builddir" || exit 1
66 git clone "$git_repo" "$workdir" || exit 1
67fi
68
69cd "$workdir" || exit 1
70git pull || exit 1
71git reset --hard "$grub_rev" || exit 1
72
73echo "$grub_rev" >"$helenosdir"/boot/grub.pc/REVISION || exit 1
74echo "$grub_rev" > "$helenosdir"/boot/grub.efi/REVISION || exit 1
75
76# Build each platform to a different directory
77./autogen.sh || exit 1
78grub_build i386 pc
79grub_build i386 efi
80grub_build x86_64 efi
81
82# Extract El Torrito boot image for i386-pc
83cd "$helenosdir"/boot/grub.pc || exit 1
84rm -f pc.img || exit 1
85"$builddir"/i386-pc/bin/grub-mkrescue -o phony --xorriso="$origdir/getimage.sh" || exit 1
86
87# Extract El Torrito boot image for i386-efi
88cd "$helenosdir"/boot/grub.efi || exit 1
89rm -f efi.img.gz || exit 1
90"$builddir"/i386-efi/bin/grub-mkrescue -o phony --xorriso="$origdir/getimage.sh" || exit 1
91mv efi.img i386-efi.img
92
93# Extract El Torrito boot image for x86_64-efi
94cd "$helenosdir"/boot/grub.efi || exit 1
95rm -f efi.img.gz || exit 1
96"$builddir"/x86_64-efi/bin/grub-mkrescue -o phony --xorriso="$origdir/getimage.sh" || exit 1
97
98# Combine El Torrito boot images for x86_64-efi and i386-efi
99mkdir tmp || exit 1
100mcopy -ns -i i386-efi.img ::efi tmp || exit 1
101mcopy -s -i efi.img tmp/* :: || exit 1
102gzip efi.img || exit 1
103rm -rf tmp || exit 1
104rm -f i386-efi.img || exit 1
105
106# Update Grub files for all platforms
107grub_files_update grub.pc i386-pc
108grub_files_update grub.efi i386-efi
109grub_files_update grub.efi x86_64-efi
110
111# Clean up
112rm -rf "$builddir" || exit 1
113
114echo "GRUB update successful."
Note: See TracBrowser for help on using the repository browser.