Initial implementation 36/10336/4 accepted/tizen/ivi/stable accepted/tizen/20130930.163623 accepted/tizen_ivi_stable/20131116.012044 submit/tizen/20130930.092513 submit/tizen_ivi_stable/20131116.010126
authorArtem Bityutskiy <artem.bityutskiy@linux.intel.com>
Wed, 25 Sep 2013 05:15:32 +0000 (08:15 +0300)
committerArtem Bityutskiy <artem.bityutskiy@linux.intel.com>
Mon, 30 Sep 2013 09:24:37 +0000 (12:24 +0300)
Change-Id: I66f2ef7853384a17348593f2d6a4e17b77b9035c
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
packaging/setup-mbr-ivi.changes [new file with mode: 0644]
packaging/setup-mbr-ivi.manifest [new file with mode: 0644]
packaging/setup-mbr-ivi.spec [new file with mode: 0644]
setup-extlinux-conf [new file with mode: 0755]
setup-mbr-ivi [new file with mode: 0755]

diff --git a/packaging/setup-mbr-ivi.changes b/packaging/setup-mbr-ivi.changes
new file mode 100644 (file)
index 0000000..e85a50e
--- /dev/null
@@ -0,0 +1,2 @@
+* Wed Sep 25 05:13:52 UTC 2013 Artem Bityutskiy <artem.bityutskiy@linux.intel.com> 1.0
+- This package configures the system to boot on legacy BIOS platforms.
diff --git a/packaging/setup-mbr-ivi.manifest b/packaging/setup-mbr-ivi.manifest
new file mode 100644 (file)
index 0000000..017d22d
--- /dev/null
@@ -0,0 +1,5 @@
+<manifest>
+ <request>
+    <domain name="_"/>
+ </request>
+</manifest>
diff --git a/packaging/setup-mbr-ivi.spec b/packaging/setup-mbr-ivi.spec
new file mode 100644 (file)
index 0000000..1d8cfa9
--- /dev/null
@@ -0,0 +1,46 @@
+Name:           setup-mbr-ivi
+Version:        1.0
+Release:        8
+License:        GPL-2.0
+Summary:        Legacy BIOS boot setup
+Url:            http://www.tizen.org
+Group:          System/Configuration
+Source:         %{name}_%{version}.tar.gz
+Requires:       syslinux-extlinux
+Requires:       /usr/bin/dd
+Requires:       /usr/bin/sed
+Requires:       /usr/bin/sort
+Requires:       /usr/bin/grep
+Requires:       /usr/bin/printf
+ExclusiveArch:  %{ix86} x86_64
+
+%description
+Configure the system to support booting on legacy BIOS platforms.
+
+###
+### PREP
+###
+%prep
+%setup -q -n %{name}-%{version}
+
+###
+### INSTALL
+###
+%install
+install -d %{buildroot}/%{_sbindir}
+install -m755 setup-mbr-ivi %{buildroot}/%{_sbindir}
+install -m755 setup-extlinux-conf %{buildroot}/%{_sbindir}
+
+###
+### CLEAN
+###
+%clean
+rm -rf %{buildroot}
+
+###
+### FILES
+###
+%files
+%defattr(-,root,root)
+%{_sbindir}/setup-mbr-ivi
+%{_sbindir}/setup-extlinux-conf
diff --git a/setup-extlinux-conf b/setup-extlinux-conf
new file mode 100755 (executable)
index 0000000..42ba2d2
--- /dev/null
@@ -0,0 +1,45 @@
+#!/bin/sh -efu
+
+# Copyright 2013 Intel Corporation
+# Author: Artem Bityutskiy
+# License: GPLv2
+
+# This scripts then scans the boot partition, finds out which kernels are
+# available, and updates the extlinux configuration file: adds missing kernel
+# records and delets non-existing kernels records. The default boot kernel is
+# always the one with the latest version.
+#
+# This scripts makes several assumptions.
+# 1. There is already a valid extlinux configuration at the boot partition
+# 2. The kernel binary names are 'vmlinuz-<version>'
+# 3. Extlinux uses the kernel pointed to by the "vmlinuz" symlink
+
+PROG="setup-extlinux-conf"
+
+# This is a helper function which printfs an error message and exits
+fatal()
+{
+       printf "%s\n" "$PROG: error: $1" 1>&2
+       exit 1
+}
+
+# Make sure the installer framework variables are defined
+[ "${INSTALLERFW_MOUNT_PREFIX:+x}" == "x" ] ||
+       fatal "installer framework environment variables not found"
+
+# Get the boot directory path
+boot_path="$INSTALLERFW_MOUNT_PREFIX/boot"
+
+# Make sure the extlinux configuration file exists
+conf_file="$boot_path/extlinux/extlinux.conf"
+[ -f "$conf_file" ] || \
+       fatal "cannot find the extlinux configuration file (\"$conf_file\")"
+
+# Get the newest installed kernel
+newest_kernel="$(ls -1 "$boot_path" | grep '^vmlinuz-' | sort -r | head -n1)"
+[ -n "$newest_kernel" ] || \
+       fatal "no vmlinuz-* files found in \"$boot_path\""
+
+# Update the "vmlinuz" symlink
+ln -sf "$newest_kernel" "$boot_path/vmlinuz" || \
+       fatal "cannot create symlink: $boot_path/vmlinuz --> $newest_kernel
diff --git a/setup-mbr-ivi b/setup-mbr-ivi
new file mode 100755 (executable)
index 0000000..0d516e4
--- /dev/null
@@ -0,0 +1,128 @@
+#!/bin/sh -efu
+
+# Copyright 2013 Intel Corporation
+# Author: Artem Bityutskiy
+# License: GPLv2
+
+#
+# This is a simple script which installs the extlinux bootloader and creates
+# a valid extlinux.conf configuration file. This script requires a number of
+# environment variables to be defined. Namely:
+#
+# 1. INSTALLERFW_PART_COUNT - count of partitions
+# 2. INSTALLERFW_PARTX_MOUNTPOINT - mount point of partition number X
+#    (0 <= X < $INSTALLERFW_PART_COUNT)
+# 3. INSTALLERFW_PARTX_PARTUUID - GPT GUID (AKA PARTUUID) of partition number X
+# 4. INSTALLERFW_MOUNT_PREFIX - where the target partitions are mounted (the
+#    "root" directory of the file-system we install extlinux to)
+# 5. INSTALLERFW_PARTX_DISK_DEVNODE_NOW - the disk device node which contains
+#    partition number X, (0 <= X < $INSTALLERFW_PART_COUNT).
+
+PROG="setup-mbr-ivi"
+
+# Print debugging information
+print_debug_info()
+{
+       printf "%s\n" "INSTALLERFW_MOUNT_PREFIX=$INSTALLERFW_MOUNT_PREFIX"
+       printf "%s\n" "INSTALLERFW_PART_COUNT=$INSTALLERFW_PART_COUNT"
+       printf "%s\n" "INSTALLERFW_PART0_FSOPTS=$INSTALLERFW_PART0_FSOPTS"
+       printf "%s\n" "INSTALLERFW_PART0_FSTYPE=$INSTALLERFW_PART0_FSTYPE"
+       printf "%s\n" "INSTALLERFW_PART0_UUID=$INSTALLERFW_PART0_UUID"
+       printf "%s\n" "INSTALLERFW_PART0_MOUNTPOINT=$INSTALLERFW_PART0_MOUNTPOINT"
+       printf "%s\n" "INSTALLERFW_PART0_ALIGN=$INSTALLERFW_PART0_ALIGN"
+       printf "%s\n" "INSTALLERFW_PART0_BOOTFLAG=$INSTALLERFW_PART0_BOOTFLAG"
+       printf "%s\n" "INSTALLERFW_PART0_SIZE=$INSTALLERFW_PART0_SIZE"
+       printf "%s\n" "INSTALLERFW_PART0_TYPE_ID=$INSTALLERFW_PART0_TYPE_ID"
+       printf "%s\n" "INSTALLERFW_PART0_LABEL=$INSTALLERFW_PART0_LABEL"
+       printf "%s\n" "INSTALLERFW_PART0_DEVNODE=$INSTALLERFW_PART0_DEVNODE"
+       printf "%s\n" "INSTALLERFW_PART0_DISK_DEVNODE=$INSTALLERFW_PART0_DISK_DEVNODE"
+       printf "%s\n" "INSTALLERFW_PART0_DEVNODE_NOW=$INSTALLERFW_PART0_DEVNODE_NOW"
+       printf "%s\n" "INSTALLERFW_PART0_DISK_DEVNODE_NOW=$INSTALLERFW_PART0_DISK_DEVNODE_NOW"
+       printf "%s\n" "INSTALLERFW_PART0_PARTUUID=$INSTALLERFW_PART0_PARTUUID"
+       printf "%s\n" "INSTALLERFW_PART1_FSOPTS=$INSTALLERFW_PART1_FSOPTS"
+       printf "%s\n" "INSTALLERFW_PART1_FSTYPE=$INSTALLERFW_PART1_FSTYPE"
+       printf "%s\n" "INSTALLERFW_PART1_UUID=$INSTALLERFW_PART1_UUID"
+       printf "%s\n" "INSTALLERFW_PART1_MOUNTPOINT=$INSTALLERFW_PART1_MOUNTPOINT"
+       printf "%s\n" "INSTALLERFW_PART1_ALIGN=$INSTALLERFW_PART1_ALIGN"
+       printf "%s\n" "INSTALLERFW_PART1_BOOTFLAG=$INSTALLERFW_PART1_BOOTFLAG"
+       printf "%s\n" "INSTALLERFW_PART1_SIZE=$INSTALLERFW_PART1_SIZE"
+       printf "%s\n" "INSTALLERFW_PART1_TYPE_ID=$INSTALLERFW_PART1_TYPE_ID"
+       printf "%s\n" "INSTALLERFW_PART1_LABEL=$INSTALLERFW_PART1_LABEL"
+       printf "%s\n" "INSTALLERFW_PART1_DEVNODE=$INSTALLERFW_PART1_DEVNODE"
+       printf "%s\n" "INSTALLERFW_PART1_DISK_DEVNODE=$INSTALLERFW_PART1_DISK_DEVNODE"
+       printf "%s\n" "INSTALLERFW_PART1_DEVNODE_NOW=$INSTALLERFW_PART1_DEVNODE_NOW"
+       printf "%s\n" "INSTALLERFW_PART1_DISK_DEVNODE_NOW=$INSTALLERFW_PART1_DISK_DEVNODE_NOW"
+       printf "%s\n" "INSTALLERFW_PART1_PARTUUID=$INSTALLERFW_PART1_PARTUUID"
+       printf "%s\n" "INSTALLERFW_DISTRO_NAME=$INSTALLERFW_DISTRO_NAME"
+       printf "%s\n" "INSTALLERFW_KERNEL_OPTS=$INSTALLERFW_KERNEL_OPTS"
+       printf "%s\n" "INSTALLERFW_INSTALLER_NAME=$INSTALLERFW_INSTALLER_NAME"
+       printf "%s\n" "INSTALLERFW_PTABLE_FORMAT=$INSTALLERFW_PTABLE_FORMAT"
+
+       cat /proc/mounts
+       ls -l /dev/
+       ls -l /dev/mapper
+}
+
+# This is a helper function which prints an error message and exits
+fatal()
+{
+       printf "%s\n" "$PROG: error: $1" 1>&2
+       exit 1
+}
+
+#print_debug_info
+
+# Make sure the installer framework variables are defined
+[ "${INSTALLERFW_PART_COUNT:+x}" == "x" ] ||
+       fatal "installer framework environment variables not found"
+
+# Find the required root and boot parition parameters
+pnum=0
+root_partuuid=
+boot_mountpoint=
+
+while [ "$pnum" -lt "$INSTALLERFW_PART_COUNT" ]; do
+       mountpoint="INSTALLERFW_PART${pnum}_MOUNTPOINT"
+       mountpoint="$(eval printf "%s" '$'$mountpoint)"
+
+       # Find out all the required data for the root and boot partition
+       if [ "$mountpoint" == "/" ]; then
+               root_partuuid="INSTALLERFW_PART${pnum}_PARTUUID"
+               root_partuuid="$(eval printf "%s" '$'$root_partuuid)"
+       # The boot parition has to be at "/boot"
+       elif [ "$mountpoint" == "/boot" ]; then
+               boot_mountpoint="$mountpoint"
+               mbr_devnode="INSTALLERFW_PART${pnum}_DISK_DEVNODE_NOW"
+               mbr_devnode="$(eval printf "%s" '$'$mbr_devnode)"
+       fi
+
+       pnum="$((pnum+1))"
+done
+
+bootdir="$INSTALLERFW_MOUNT_PREFIX/$boot_mountpoint"
+extlinuxdir="$bootdir/extlinux"
+
+# Install extlinux
+extlinux_binary="$INSTALLERFW_MOUNT_PREFIX/sbin/extlinux"
+"$extlinux_binary" -i "$extlinuxdir" || \
+       fatal "cannot install extlinux to $extlinuxdir"
+
+# Install the MBR part of extlinux
+mbr_bin="$INSTALLERFW_MOUNT_PREFIX/usr/share/syslinux/gptmbr.bin"
+dd if="$mbr_bin" of="$mbr_devnode" || \
+       fatal "cannot install MBR: dd if=$mbr_bin of=$mbr_devnode"
+
+# Make the newest kernel to be the one we boot
+newest_kernel="$(ls -1 "$bootdir" | grep "^vmlinuz-" | sort -r | head -n1)"
+ln -sf "$newest_kernel" "$bootdir/vmlinuz" || \
+       fatal "cannot create symlink: $bootdir/vmlinuz --> $newest_kernel"
+
+# Create the extlinux.conf file
+cat > "$extlinuxdir/extlinux.conf" <<EOF
+prompt 0
+timeout 0
+default tizen
+label tizen
+       linux ../vmlinuz
+       append $INSTALLERFW_KERNEL_OPTS root=PARTUUID=$root_partuuid
+EOF