setup-efi-ivi: amend the kernel entry file
[profile/ivi/setup-efi-ivi.git] / setup-efi-ivi
1 #!/bin/sh -ef
2
3 # Copyright 2013 Intel Corporation
4 # Author: Artem Bityutskiy
5 # License: GPLv2
6
7 PROG="setup-efi-ivi"
8
9 # This is a helper function which prints an error message and exits
10 fatal()
11 {
12         printf "%s\n" "$PROG: error: $1" 1>&2
13         exit 1
14 }
15
16 boot_mountpoint="/boot"
17
18 # Make sure the installer framework variables are defined
19 [ "x$INSTALLERFW_INSTALLER_NAME" != "x" ] ||
20         fatal "installer framework environment variables not found"
21
22 # Find the root and boot paritions
23 pnum=0
24 root_partuuid=
25 boot_fstype=
26
27 while [ "$pnum" -lt "$INSTALLERFW_PART_COUNT" ]; do
28         mountpoint="INSTALLERFW_PART${pnum}_MOUNTPOINT"
29         mountpoint="$(eval printf "%s" '$'$mountpoint)"
30
31         # Find out all the required data for the root and boot partition
32         if [ "$mountpoint" == "/" ]; then
33                 root_partuuid=INSTALLERFW_PART${pnum}_PARTUUID
34                 root_partuuid="$(eval printf "%s" '$'$root_partuuid)"
35         elif [ "$mountpoint" == "$boot_mountpoint" ]; then
36                 boot_fstype=INSTALLERFW_PART${pnum}_FSTYPE
37                 boot_fstype="$(eval printf "%s" '$'$boot_fstype)"
38         fi
39
40         pnum="$((pnum+1))"
41 done
42
43 # Make sure that the boot partition has a FAT file-system
44 [ "$boot_fstype" == "vfat" ] || \
45         fatal "boot partition has to have type \"vfat\""
46
47 # Make sure gummiboot is installed in the system
48 if ! ([ -f /usr/lib/gummiboot/gummibootia32.efi ] || \
49       [ -f /usr/lib/gummiboot/gummibootx64.efi ]); then
50         fatal "\"/usr/lib/gummiboot/gummiboot*.efi\" files not found!"
51 fi
52
53 # Install gummiboot
54 mkdir -p "$boot_mountpoint/EFI/boot"
55 [ -f "/usr/lib/gummiboot/gummibootia32.efi" ] &&
56         cp "/usr/lib/gummiboot/gummibootia32.efi" "$boot_mountpoint/EFI/boot/bootia32.efi"
57 [ -f "/usr/lib/gummiboot/gummibootx64.efi" ] &&
58         cp "/usr/lib/gummiboot/gummibootx64.efi" "$boot_mountpoint/boot/EFI/boot/bootx64.efi"
59
60 # Find out the latest kernel binary in boot partition
61 vmlinuz="$(ls -1 "$boot_mountpoint" | grep "^vmlinuz-" | sort -r | head -n1)"
62 vmlinuz_version="$(printf "%s" $vmlinuz | sed -e 's/vmlinuz-\(.*\)/\1/')"
63
64 # Create the gummiboot configuration file
65 mkdir -p "$boot_mountpoint/loader"
66
67 cat > "$boot_mountpoint/loader/loader.conf" <<-EOF
68 timeout 0
69 default vmlinuz-$vmlinuz_version.conf
70 EOF
71
72 # Create the default gummiboot entry
73 mkdir -p "$boot_mountpoint/loader/entries"
74 cat > "$boot_mountpoint/loader/entries/vmlinuz-$vmlinuz_version.conf" <<-EOF
75 title Tizen IVI 3.0
76 version $vmlinuz_version
77 efi/$vmlinuz
78 options $INSTALLERFW_KERNEL_OPTS root=PARTUUID=$root_partuuid
79 EOF