source: mainline/tools/grub/grub-update.sh@ d776329b

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

Do not depend on scripts being run from the directory they reside in.

  • Property mode set to 100755
File size: 3.9 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="$(cd "$(dirname "$0")" && pwd)"
36helenosdir="$origdir/../.."
37workdir="$origdir/grub-src"
38builddir="$origdir/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 rm -f "$helenosdir"/boot/"$gdir"/"$platform"/*.module || exit 1
61 bzr add "$helenosdir"/boot/"$gdir"/"$platform" || exit 1
62}
63
64# Prepare a clone of Grub2 repo
65if [ ! -d "$workdir" ] ; then
66 rm -rf "$workdir" "$builddir" || exit 1
67 git clone "$git_repo" "$workdir" || exit 1
68fi
69
70cd "$workdir" || exit 1
71git pull || exit 1
72git reset --hard "$grub_rev" || exit 1
73
74echo "$grub_rev" >"$helenosdir"/boot/grub.pc/REVISION || exit 1
75echo "$grub_rev" > "$helenosdir"/boot/grub.efi/REVISION || exit 1
76
77# Build each platform to a different directory
78./autogen.sh || exit 1
79grub_build i386 pc
80grub_build i386 efi
81grub_build x86_64 efi
82
83# Extract El Torrito boot image for i386-pc
84cd "$helenosdir"/boot/grub.pc || exit 1
85rm -f pc.img || exit 1
86"$builddir"/i386-pc/bin/grub-mkrescue -o phony --xorriso="$origdir/getimage.sh" || exit 1
87
88# Extract El Torrito boot image for i386-efi
89cd "$helenosdir"/boot/grub.efi || exit 1
90rm -f efi.img.gz || exit 1
91"$builddir"/i386-efi/bin/grub-mkrescue -o phony --xorriso="$origdir/getimage.sh" || exit 1
92mv efi.img i386-efi.img
93
94# Extract El Torrito boot image for x86_64-efi
95cd "$helenosdir"/boot/grub.efi || exit 1
96rm -f efi.img.gz || exit 1
97"$builddir"/x86_64-efi/bin/grub-mkrescue -o phony --xorriso="$origdir/getimage.sh" || exit 1
98
99# Combine El Torrito boot images for x86_64-efi and i386-efi
100mkdir tmp || exit 1
101mcopy -ns -i i386-efi.img ::efi tmp || exit 1
102mcopy -s -i efi.img tmp/* :: || exit 1
103gzip efi.img || exit 1
104rm -rf tmp || exit 1
105rm -f i386-efi.img || exit 1
106
107# Update Grub files for all platforms
108grub_files_update grub.pc i386-pc
109grub_files_update grub.efi i386-efi
110grub_files_update grub.efi x86_64-efi
111
112echo "GRUB update successful."
Note: See TracBrowser for help on using the repository browser.