aboutsummaryrefslogtreecommitdiffstats
path: root/common/mentor-swupdate/recipes-core/initrdscripts/files
diff options
context:
space:
mode:
Diffstat (limited to 'common/mentor-swupdate/recipes-core/initrdscripts/files')
-rw-r--r--common/mentor-swupdate/recipes-core/initrdscripts/files/0001-init-install-efi-SWU-fallback-incase-WDT-fired-SWU-p.patch28
-rw-r--r--common/mentor-swupdate/recipes-core/initrdscripts/files/0001-init-install-efi-manage-partitioning-scheme-as-per-M.patch168
-rw-r--r--common/mentor-swupdate/recipes-core/initrdscripts/files/0002-init-install-efi-SWU-add-setup-WDT-routine-to-enable.patch39
-rw-r--r--common/mentor-swupdate/recipes-core/initrdscripts/files/0002-init-install-efi-do-not-blacklist-root-device-for-ud.patch31
-rw-r--r--common/mentor-swupdate/recipes-core/initrdscripts/files/0003-init-install-efi-SWU-start-the-WDT-as-soon-as-a-menu.patch27
-rw-r--r--common/mentor-swupdate/recipes-core/initrdscripts/files/0003-init-install-efi-deploy-kernel-images-as-imageA.patch47
-rw-r--r--common/mentor-swupdate/recipes-core/initrdscripts/files/0004-init-install-efi-pick-kernel-and-rootfs-from-grub.en.patch73
-rw-r--r--common/mentor-swupdate/recipes-core/initrdscripts/files/0005-init-install-efi-create-fallback-entry.patch40
-rw-r--r--common/mentor-swupdate/recipes-core/initrdscripts/files/0006-init-install-efi-don-t-unnecessarily-set-the-rootfs-.patch29
-rw-r--r--common/mentor-swupdate/recipes-core/initrdscripts/files/0007-init-install-efi-grub-don-t-set-a-timeout.patch30
10 files changed, 512 insertions, 0 deletions
diff --git a/common/mentor-swupdate/recipes-core/initrdscripts/files/0001-init-install-efi-SWU-fallback-incase-WDT-fired-SWU-p.patch b/common/mentor-swupdate/recipes-core/initrdscripts/files/0001-init-install-efi-SWU-fallback-incase-WDT-fired-SWU-p.patch
new file mode 100644
index 00000000..33a458a0
--- /dev/null
+++ b/common/mentor-swupdate/recipes-core/initrdscripts/files/0001-init-install-efi-SWU-fallback-incase-WDT-fired-SWU-p.patch
@@ -0,0 +1,28 @@
+From 2b8e67eb5899962528ab821754c76abd1bc4aef3 Mon Sep 17 00:00:00 2001
+From: "Arsalan H. Awan" <Arsalan_Awan@mentor.com>
+Date: Thu, 14 Feb 2019 14:31:03 +0500
+Subject: [PATCH 1/3] init-install-efi/SWU: fallback incase WDT fired & SWU
+ performed
+
+Signed-off-by: Arsalan H. Awan <Arsalan_Awan@mentor.com>
+---
+ init-install-efi.sh | 3 +++
+ 1 file changed, 3 insertions(+)
+
+diff --git a/init-install-efi.sh b/init-install-efi.sh
+index ba0de76..e259785 100644
+--- a/init-install-efi.sh
++++ b/init-install-efi.sh
+@@ -320,6 +320,9 @@ save_env --file ${GRUBENV#\/boot} RFS
+ $cmd
+ }
+ FALL_BACK
++ # Mentor - SWUpdate - set the default boot as per the WDT and SWU status
++ # If WDT fired && SWU performed, fallback to last working state, else normal boot
++ sed -i "/default=boot/a if ! amd-wdt getstatus; then\n if test \$KERNEL != \$FB_KERNEL; then\n set default='fallback'\n fi\nfi\n" $GRUBCFG
+ fi
+
+ if [ -d /run/media/$1/loader ]; then
+--
+2.11.1
+
diff --git a/common/mentor-swupdate/recipes-core/initrdscripts/files/0001-init-install-efi-manage-partitioning-scheme-as-per-M.patch b/common/mentor-swupdate/recipes-core/initrdscripts/files/0001-init-install-efi-manage-partitioning-scheme-as-per-M.patch
new file mode 100644
index 00000000..73afa447
--- /dev/null
+++ b/common/mentor-swupdate/recipes-core/initrdscripts/files/0001-init-install-efi-manage-partitioning-scheme-as-per-M.patch
@@ -0,0 +1,168 @@
+From bc6af3b77cbfa06a76d0d04d668c9883494fe8dd Mon Sep 17 00:00:00 2001
+From: Awais Belal <awais_belal@mentor.com>
+Date: Fri, 11 Jan 2019 12:04:02 +0500
+Subject: [PATCH 1/7] init-install-efi: manage partitioning scheme as per MEL
+ SWUpdate
+
+The partitioning scheme is updated in order to support SWUpdate
+in a dual-copy approach with additional partitions for persistent
+and data storage. This is a hardcoded scheme for now so it can
+only support devices with at least a minimum size of 8GB which
+yields a data partition of around 600MB considering a few factors.
+
+Signed-off-by: Awais Belal <awais_belal@mentor.com>
+---
+ init-install-efi.sh | 76 ++++++++++++++++++++++++++++++++++++++++++-----------
+ 1 file changed, 61 insertions(+), 15 deletions(-)
+
+diff --git a/init-install-efi.sh b/init-install-efi.sh
+index 82b0aa8..5fb2ae4 100644
+--- a/init-install-efi.sh
++++ b/init-install-efi.sh
+@@ -21,6 +21,8 @@ fi
+ # add 10M to provide some extra space for users and account
+ # for rounding in the above subtractions
+ boot_size=$(( boot_size + 10 ))
++# MEL - SWUpdate - we'll be keeping two kernel binaries so simply take twice the size
++boot_size=$(( boot_size * 2 ))
+
+ # 5% for swap
+ swap_ratio=5
+@@ -147,12 +149,32 @@ fi
+
+ disk_size=$(parted ${device} unit mb print | grep '^Disk .*: .*MB' | cut -d" " -f 3 | sed -e "s/MB//")
+
++# MEL - SWUpdate - dual-copy approach
++# Here's the partitioning scheme
++# Partition Size Mode
++# boot Calculated from the installation device RW
++# root(1) 3G R
++# root(2) 3G R
++# persistent 1G RW
++# userdata Whatever's left from all other parts RW
++# swap 5% of disk size swap
++rootfs_size=3072
++rootfs1_start=$((boot_size))
++rootfs1_end=$((rootfs1_start+rootfs_size))
++rootfs2_start=$rootfs1_end
++rootfs2_end=$((rootfs2_start+rootfs_size))
++
++persistent_size=1024
++persistent_start=$rootfs2_end
++persistent_end=$((persistent_start+persistent_size))
++
+ swap_size=$((disk_size*swap_ratio/100))
+-rootfs_size=$((disk_size-boot_size-swap_size))
+
+-rootfs_start=$((boot_size))
+-rootfs_end=$((rootfs_start+rootfs_size))
+-swap_start=$((rootfs_end))
++userdata_size=$((disk_size-boot_size-rootfs_size*2-persistent_size-swap_size))
++userdata_start=$persistent_end
++userdata_end=$((userdata_start+userdata_size))
++
++swap_start=$((userdata_end))
+
+ # MMC devices are special in a couple of ways
+ # 1) they use a partition prefix character 'p'
+@@ -171,12 +193,17 @@ if [ -n `readlink /dev/disk/by-id/usb* | grep $TARGET_DEVICE_NAME` ]; then
+ fi
+
+ bootfs=${device}${part_prefix}1
+-rootfs=${device}${part_prefix}2
+-swap=${device}${part_prefix}3
++rootfs1=${device}${part_prefix}2
++rootfs2=${device}${part_prefix}3
++persistent=${device}${part_prefix}4
++userdata=${device}${part_prefix}5
++swap=${device}${part_prefix}6
+
+ echo "*****************"
+ echo "Boot partition size: $boot_size MB ($bootfs)"
+-echo "Rootfs partition size: $rootfs_size MB ($rootfs)"
++echo "Per rootfs partition size: $rootfs_size MB ($rootfs)"
++echo "Persistent partition size: $persistent_size MB ($rootfs)"
++echo "User data partition size: $userdata_size MB ($rootfs)"
+ echo "Swap partition size: $swap_size MB ($swap)"
+ echo "*****************"
+ echo "Deleting partition table on ${device} ..."
+@@ -189,8 +216,17 @@ echo "Creating boot partition on $bootfs"
+ parted ${device} mkpart boot fat32 0% $boot_size
+ parted ${device} set 1 boot on
+
+-echo "Creating rootfs partition on $rootfs"
+-parted ${device} mkpart root ext4 $rootfs_start $rootfs_end
++echo "Creating rootfs partition 1 on $rootfs1"
++parted ${device} mkpart platform ext4 $rootfs1_start $rootfs1_end
++
++echo "Creating rootfs partition 2 on $rootfs2"
++parted ${device} mkpart platform ext4 $rootfs2_start $rootfs2_end
++
++echo "Creating persistent partition on $persistent"
++parted ${device} mkpart persistent ext4 $persistent_start $persistent_end
++
++echo "Creating user data partition on $userdata"
++parted ${device} mkpart data ext4 $userdata_start $userdata_end
+
+ echo "Creating swap partition on $swap"
+ parted ${device} mkpart swap linux-swap $swap_start 100%
+@@ -199,7 +235,7 @@ parted ${device} print
+
+ echo "Waiting for device nodes..."
+ C=0
+-while [ $C -ne 3 ] && [ ! -e $bootfs -o ! -e $rootfs -o ! -e $swap ]; do
++while [ $C -ne 3 ] && [ ! -e $bootfs -o ! -e $rootfs1 -o ! -e $rootfs2 -o ! -e $persistent -o ! -e $userdata -o ! -e $swap ]; do
+ C=$(( C + 1 ))
+ sleep 1
+ done
+@@ -207,8 +243,17 @@ done
+ echo "Formatting $bootfs to vfat..."
+ mkfs.vfat $bootfs
+
+-echo "Formatting $rootfs to ext4..."
+-mkfs.ext4 $rootfs
++echo "Formatting $rootfs1 to ext4..."
++mkfs.ext4 $rootfs1
++
++echo "Formatting $rootfs2 to ext4..."
++mkfs.ext4 $rootfs2
++
++echo "Formatting $persistent to ext4..."
++mkfs.ext4 $persistent
++
++echo "Formatting $userdata to ext4..."
++mkfs.ext4 $userdata
+
+ echo "Formatting swap partition...($swap)"
+ mkswap $swap
+@@ -218,7 +263,8 @@ mkdir /src_root
+ mkdir -p /boot
+
+ # Handling of the target root partition
+-mount $rootfs /tgt_root
++# MEL - SWUpdate - simply install to rootfs1 for now
++mount $rootfs1 /tgt_root
+ mount -o rw,loop,noatime,nodiratime /run/media/$1/$2 /src_root
+ echo "Copying rootfs files..."
+ cp -a /src_root/* /tgt_root
+@@ -245,7 +291,7 @@ mkdir -p $EFIDIR
+ cp /run/media/$1/EFI/BOOT/*.efi $EFIDIR
+
+ if [ -f /run/media/$1/EFI/BOOT/grub.cfg ]; then
+- root_part_uuid=$(blkid -o value -s PARTUUID ${rootfs})
++ root_part_uuid=$(blkid -o value -s PARTUUID ${rootfs1})
+ GRUBCFG="$EFIDIR/grub.cfg"
+ cp /run/media/$1/EFI/BOOT/grub.cfg $GRUBCFG
+ # Update grub config for the installed image
+@@ -261,7 +307,7 @@ if [ -f /run/media/$1/EFI/BOOT/grub.cfg ]; then
+ fi
+
+ if [ -d /run/media/$1/loader ]; then
+- rootuuid=$(blkid -o value -s PARTUUID ${rootfs})
++ rootuuid=$(blkid -o value -s PARTUUID ${rootfs1})
+ SYSTEMDBOOT_CFGS="/boot/loader/entries/*.conf"
+ # copy config files for systemd-boot
+ cp -dr /run/media/$1/loader /boot
+--
+2.11.1
+
diff --git a/common/mentor-swupdate/recipes-core/initrdscripts/files/0002-init-install-efi-SWU-add-setup-WDT-routine-to-enable.patch b/common/mentor-swupdate/recipes-core/initrdscripts/files/0002-init-install-efi-SWU-add-setup-WDT-routine-to-enable.patch
new file mode 100644
index 00000000..22d4a626
--- /dev/null
+++ b/common/mentor-swupdate/recipes-core/initrdscripts/files/0002-init-install-efi-SWU-add-setup-WDT-routine-to-enable.patch
@@ -0,0 +1,39 @@
+From 34fb95494f01cd0adbcfae5d113f669336d8cf0c Mon Sep 17 00:00:00 2001
+From: "Arsalan H. Awan" <Arsalan_Awan@mentor.com>
+Date: Fri, 8 Mar 2019 12:05:56 +0500
+Subject: [PATCH 2/3] init-install-efi/SWU: add setup WDT routine to enable if
+ mel_wdt is 1
+
+> set WDT timeout to 60s by default to reboot in case system hangs.
+> start WDT ONLY IF mel_wdt is set to 1.
+>> this allows user to disable the WDT in case the user is doing
+ kernel debugging or so and wants the system to keep running.
+> enable WDT (set mel_wdt=1) by default
+
+Signed-off-by: Arsalan H. Awan <Arsalan_Awan@mentor.com>
+---
+ init-install-efi.sh | 8 ++++++++
+ 1 file changed, 8 insertions(+)
+
+diff --git a/init-install-efi.sh b/init-install-efi.sh
+index e259785..270b254 100644
+--- a/init-install-efi.sh
++++ b/init-install-efi.sh
+@@ -323,6 +323,14 @@ FALL_BACK
+ # Mentor - SWUpdate - set the default boot as per the WDT and SWU status
+ # If WDT fired && SWU performed, fallback to last working state, else normal boot
+ sed -i "/default=boot/a if ! amd-wdt getstatus; then\n if test \$KERNEL != \$FB_KERNEL; then\n set default='fallback'\n fi\nfi\n" $GRUBCFG
++ # Mentor - SWUpdate - setup routine for WDT
++ sed -i "/menuentry.*boot/i function setup_wdt {\n}\n" $GRUBCFG
++ # > If mel_wdt is set to 1, ONLY THEN start the WDT
++ sed -i "/function setup_wdt/a if test \$mel_wdt -eq 1; then amd-wdt start; fi" $GRUBCFG
++ # > set WDT timeout value to 60s by default
++ sed -i "/function setup_wdt/a amd-wdt settime 60" $GRUBCFG
++ # Mentor - SWUpdate - enable WDT by default
++ sed -i "/menuentry.*boot/i set mel_wdt=1\n" $GRUBCFG
+ fi
+
+ if [ -d /run/media/$1/loader ]; then
+--
+2.11.1
+
diff --git a/common/mentor-swupdate/recipes-core/initrdscripts/files/0002-init-install-efi-do-not-blacklist-root-device-for-ud.patch b/common/mentor-swupdate/recipes-core/initrdscripts/files/0002-init-install-efi-do-not-blacklist-root-device-for-ud.patch
new file mode 100644
index 00000000..0abed1bb
--- /dev/null
+++ b/common/mentor-swupdate/recipes-core/initrdscripts/files/0002-init-install-efi-do-not-blacklist-root-device-for-ud.patch
@@ -0,0 +1,31 @@
+From 701cddcf67faff9234d1c07278f580aea10cd71a Mon Sep 17 00:00:00 2001
+From: Awais Belal <awais_belal@mentor.com>
+Date: Fri, 11 Jan 2019 17:20:07 +0500
+Subject: [PATCH 2/7] init-install-efi: do not blacklist root device for udev
+
+We want all partitions to show up so that SWUpdate can
+create its links accordingly.
+
+Signed-off-by: Awais Belal <awais_belal@mentor.com>
+---
+ init-install-efi.sh | 4 ----
+ 1 file changed, 4 deletions(-)
+
+diff --git a/init-install-efi.sh b/init-install-efi.sh
+index 5fb2ae4..6e713ba 100644
+--- a/init-install-efi.sh
++++ b/init-install-efi.sh
+@@ -273,10 +273,6 @@ if [ -d /tgt_root/etc/ ] ; then
+ swap_part_uuid=$(blkid -o value -s PARTUUID ${swap})
+ echo "/dev/disk/by-partuuid/$swap_part_uuid swap swap defaults 0 0" >> /tgt_root/etc/fstab
+ echo "UUID=$boot_uuid /boot vfat defaults 1 2" >> /tgt_root/etc/fstab
+- # We dont want udev to mount our root device while we're booting...
+- if [ -d /tgt_root/etc/udev/ ] ; then
+- echo "${device}" >> /tgt_root/etc/udev/mount.blacklist
+- fi
+ fi
+
+ umount /src_root
+--
+2.11.1
+
diff --git a/common/mentor-swupdate/recipes-core/initrdscripts/files/0003-init-install-efi-SWU-start-the-WDT-as-soon-as-a-menu.patch b/common/mentor-swupdate/recipes-core/initrdscripts/files/0003-init-install-efi-SWU-start-the-WDT-as-soon-as-a-menu.patch
new file mode 100644
index 00000000..cbec24aa
--- /dev/null
+++ b/common/mentor-swupdate/recipes-core/initrdscripts/files/0003-init-install-efi-SWU-start-the-WDT-as-soon-as-a-menu.patch
@@ -0,0 +1,27 @@
+From 64dd7084103bddf314365271981bf535e863e647 Mon Sep 17 00:00:00 2001
+From: "Arsalan H. Awan" <Arsalan_Awan@mentor.com>
+Date: Fri, 8 Mar 2019 12:15:56 +0500
+Subject: [PATCH 3/3] init-install-efi/SWU: start the WDT as soon as a
+ menuentry is selected
+
+Signed-off-by: Arsalan H. Awan <Arsalan_Awan@mentor.com>
+---
+ init-install-efi.sh | 2 ++
+ 1 file changed, 2 insertions(+)
+
+diff --git a/init-install-efi.sh b/init-install-efi.sh
+index 270b254..502b0ce 100644
+--- a/init-install-efi.sh
++++ b/init-install-efi.sh
+@@ -331,6 +331,8 @@ FALL_BACK
+ sed -i "/function setup_wdt/a amd-wdt settime 60" $GRUBCFG
+ # Mentor - SWUpdate - enable WDT by default
+ sed -i "/menuentry.*boot/i set mel_wdt=1\n" $GRUBCFG
++ # Mentor - SWUpdate - start the WDT as soon as a menuentry is selected
++ sed -i "/menuentry/a setup_wdt" $GRUBCFG
+ fi
+
+ if [ -d /run/media/$1/loader ]; then
+--
+2.11.1
+
diff --git a/common/mentor-swupdate/recipes-core/initrdscripts/files/0003-init-install-efi-deploy-kernel-images-as-imageA.patch b/common/mentor-swupdate/recipes-core/initrdscripts/files/0003-init-install-efi-deploy-kernel-images-as-imageA.patch
new file mode 100644
index 00000000..c417da6c
--- /dev/null
+++ b/common/mentor-swupdate/recipes-core/initrdscripts/files/0003-init-install-efi-deploy-kernel-images-as-imageA.patch
@@ -0,0 +1,47 @@
+From 5c72bcb27e0d0528abde7e03700a210f38200046 Mon Sep 17 00:00:00 2001
+From: Awais Belal <awais_belal@mentor.com>
+Date: Sat, 12 Jan 2019 01:22:14 +0500
+Subject: [PATCH 3/7] init-install-efi: deploy kernel images as imageA
+
+With a single boot partition we keep two copies of
+kernel to support the AB approach so deploy kernels
+as imageA on scratch installation.
+
+Signed-off-by: Awais Belal <awais_belal@mentor.com>
+---
+ init-install-efi.sh | 9 +++++++--
+ 1 file changed, 7 insertions(+), 2 deletions(-)
+
+diff --git a/init-install-efi.sh b/init-install-efi.sh
+index 6e713ba..8905cfa 100644
+--- a/init-install-efi.sh
++++ b/init-install-efi.sh
+@@ -286,9 +286,9 @@ mkdir -p $EFIDIR
+ # Copy the efi loader
+ cp /run/media/$1/EFI/BOOT/*.efi $EFIDIR
+
++GRUBCFG="$EFIDIR/grub.cfg"
+ if [ -f /run/media/$1/EFI/BOOT/grub.cfg ]; then
+ root_part_uuid=$(blkid -o value -s PARTUUID ${rootfs1})
+- GRUBCFG="$EFIDIR/grub.cfg"
+ cp /run/media/$1/EFI/BOOT/grub.cfg $GRUBCFG
+ # Update grub config for the installed image
+ # Delete the install entry
+@@ -324,8 +324,13 @@ umount /tgt_root
+ # Copy kernel artifacts. To add more artifacts just add to types
+ # For now just support kernel types already being used by something in OE-core
+ for types in bzImage zImage vmlinux vmlinuz fitImage; do
++ # MEL - SWUpdate - copy all kernel images as <image>A, this is our first copy
+ for kernel in `find /run/media/$1/ -name $types*`; do
+- cp $kernel /boot
++ kernel_name=$(basename $kernel)
++ cp $kernel /boot/${kernel_name}A
++ if [ -e $GRUBCFG ]; then
++ sed -i "s/\/${kernel_name} /\/${kernel_name}A /" $GRUBCFG
++ fi
+ done
+ done
+
+--
+2.11.1
+
diff --git a/common/mentor-swupdate/recipes-core/initrdscripts/files/0004-init-install-efi-pick-kernel-and-rootfs-from-grub.en.patch b/common/mentor-swupdate/recipes-core/initrdscripts/files/0004-init-install-efi-pick-kernel-and-rootfs-from-grub.en.patch
new file mode 100644
index 00000000..1548f505
--- /dev/null
+++ b/common/mentor-swupdate/recipes-core/initrdscripts/files/0004-init-install-efi-pick-kernel-and-rootfs-from-grub.en.patch
@@ -0,0 +1,73 @@
+From 78d26166a8ad1bc8d29822d45a6a382b87fa095d Mon Sep 17 00:00:00 2001
+From: Awais Belal <awais_belal@mentor.com>
+Date: Mon, 14 Jan 2019 19:40:50 +0500
+Subject: [PATCH 4/7] init-install-efi: pick kernel and rootfs from grub.env
+
+This allows for simply modifying variables to switch between
+different kernels and rootfs from user-space without having to
+modify grub configurations directly.
+
+Signed-off-by: Awais Belal <awais_belal@mentor.com>
+---
+ init-install-efi.sh | 22 +++++++++++++++++++---
+ 1 file changed, 19 insertions(+), 3 deletions(-)
+
+diff --git a/init-install-efi.sh b/init-install-efi.sh
+index 2adfe02..d69520f 100644
+--- a/init-install-efi.sh
++++ b/init-install-efi.sh
+@@ -287,6 +287,7 @@ mkdir -p $EFIDIR
+ cp /run/media/$1/EFI/BOOT/*.efi $EFIDIR
+
+ GRUBCFG="$EFIDIR/grub.cfg"
++GRUBENV="$EFIDIR/grub.env"
+ if [ -f /run/media/$1/EFI/BOOT/grub.cfg ]; then
+ root_part_uuid=$(blkid -o value -s PARTUUID ${rootfs1})
+ cp /run/media/$1/EFI/BOOT/grub.cfg $GRUBCFG
+@@ -297,9 +298,14 @@ if [ -f /run/media/$1/EFI/BOOT/grub.cfg ]; then
+ sed -i "/initrd /d" $GRUBCFG
+ # Delete any LABEL= strings
+ sed -i "s/ LABEL=[^ ]*/ /" $GRUBCFG
++ # Mentor- SWUpdate - force grub to load our env which we'll use to specify RFS and KERNEL
++ sed -i "1iload_env --file ${GRUBENV#\/boot}" $GRUBCFG
++ # Set current and fallback rootfs using variable via our grub.env
++ grub-editenv $GRUBENV set "RFS=PARTUUID=$root_part_uuid"
++ grub-editenv $GRUBENV set "FB_RFS=PARTUUID=$root_part_uuid"
+ # Replace root= and add additional standard boot options
+ # We use root as a sentinel value, as vmlinuz is no longer guaranteed
+- sed -i "s/ root=[^ ]*/ root=PARTUUID=$root_part_uuid rw $rootwait quiet /g" $GRUBCFG
++ sed -i "s/ root=[^ ]*/ root=\$RFS rw $rootwait quiet /g" $GRUBCFG
+ fi
+
+ if [ -d /run/media/$1/loader ]; then
+@@ -321,15 +327,25 @@ fi
+
+ umount /tgt_root
+
++if [ -e "/proc/cmdline" ]; then
++ current_kernel=$(basename $(cat /proc/cmdline | awk '{print $1}' | cut -d"=" -f2))
++fi
+ # Copy kernel artifacts. To add more artifacts just add to types
+ # For now just support kernel types already being used by something in OE-core
+ for types in bzImage zImage vmlinux vmlinuz fitImage; do
+ # MEL - SWUpdate - copy all kernel images as <image>A, this is our first copy
+ for kernel in `find /run/media/$1/ -name $types*`; do
+ kernel_name=$(basename $kernel)
+- cp $kernel /boot/${kernel_name}A
++ cp ${kernel} /boot/${kernel_name}A
+ if [ -e $GRUBCFG ]; then
+- sed -i "s/\/${kernel_name} /\/${kernel_name}A /" $GRUBCFG
++ if [ "${kernel_name}" = "${current_kernel}" ]; then
++ sed -i "s/\/${kernel_name} /\/\$KERNEL /" $GRUBCFG
++ # Set the current and fallback kernel to current kernel's <image>A
++ grub-editenv $GRUBENV set "KERNEL=${kernel_name}A"
++ grub-editenv $GRUBENV set "FB_KERNEL=${kernel_name}A"
++ else
++ sed -i "s/\/${kernel_name} /\/${kernel_name}A /" $GRUBCFG
++ fi
+ fi
+ done
+ done
+--
+2.11.1
+
diff --git a/common/mentor-swupdate/recipes-core/initrdscripts/files/0005-init-install-efi-create-fallback-entry.patch b/common/mentor-swupdate/recipes-core/initrdscripts/files/0005-init-install-efi-create-fallback-entry.patch
new file mode 100644
index 00000000..cbebadbc
--- /dev/null
+++ b/common/mentor-swupdate/recipes-core/initrdscripts/files/0005-init-install-efi-create-fallback-entry.patch
@@ -0,0 +1,40 @@
+From 723470df51c6314d166e80636e393316339700a1 Mon Sep 17 00:00:00 2001
+From: Awais Belal <awais_belal@mentor.com>
+Date: Wed, 16 Jan 2019 16:12:19 +0500
+Subject: [PATCH 5/7] init-install-efi: create fallback entry
+
+In case of an update failure we need to switch
+our bootparams and fallback to the fallback (FB_)
+vars which are a known good configuration.
+
+Signed-off-by: Awais Belal <awais_belal@mentor.com>
+---
+ init-install-efi.sh | 12 ++++++++++++
+ 1 file changed, 12 insertions(+)
+
+diff --git a/init-install-efi.sh b/init-install-efi.sh
+index ae7e32b..cdab4d6 100644
+--- a/init-install-efi.sh
++++ b/init-install-efi.sh
+@@ -306,6 +306,18 @@ if [ -f /run/media/$1/EFI/BOOT/grub.cfg ]; then
+ # Replace root= and add additional standard boot options
+ # We use root as a sentinel value, as vmlinuz is no longer guaranteed
+ sed -i "s/ root=[^ ]*/ root=\$RFS rw $rootwait quiet /g" $GRUBCFG
++ # Mentor - SWUpdate - create our fallback menuentry
++ sed -i "1ifallback=1" $GRUBCFG
++ cmd=$(grep "linux " $GRUBCFG)
++ cat >> $GRUBCFG <<FALL_BACK
++menuentry 'fallback'{
++set KERNEL=\$FB_KERNEL
++set RFS=\$FB_RFS
++save_env --file ${GRUBENV#\/boot} KERNEL
++save_env --file ${GRUBENV#\/boot} RFS
++$cmd
++}
++FALL_BACK
+ fi
+
+ if [ -d /run/media/$1/loader ]; then
+--
+2.11.1
+
diff --git a/common/mentor-swupdate/recipes-core/initrdscripts/files/0006-init-install-efi-don-t-unnecessarily-set-the-rootfs-.patch b/common/mentor-swupdate/recipes-core/initrdscripts/files/0006-init-install-efi-don-t-unnecessarily-set-the-rootfs-.patch
new file mode 100644
index 00000000..e5c03702
--- /dev/null
+++ b/common/mentor-swupdate/recipes-core/initrdscripts/files/0006-init-install-efi-don-t-unnecessarily-set-the-rootfs-.patch
@@ -0,0 +1,29 @@
+From 74e5fc2d0044f474b42f83918ddd70658fb2013a Mon Sep 17 00:00:00 2001
+From: Awais Belal <awais_belal@mentor.com>
+Date: Wed, 16 Jan 2019 16:15:56 +0500
+Subject: [PATCH 6/7] init-install-efi: don't unnecessarily set the rootfs to
+ rw
+
+Specifically in swupdate we use a ro rootfs.
+
+Signed-off-by: Awais Belal <awais_belal@mentor.com>
+---
+ init-install-efi.sh | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/init-install-efi.sh b/init-install-efi.sh
+index cdab4d6..efe0c64 100644
+--- a/init-install-efi.sh
++++ b/init-install-efi.sh
+@@ -305,7 +305,7 @@ if [ -f /run/media/$1/EFI/BOOT/grub.cfg ]; then
+ grub-editenv $GRUBENV set "FB_RFS=PARTUUID=$root_part_uuid"
+ # Replace root= and add additional standard boot options
+ # We use root as a sentinel value, as vmlinuz is no longer guaranteed
+- sed -i "s/ root=[^ ]*/ root=\$RFS rw $rootwait quiet /g" $GRUBCFG
++ sed -i "s/ root=[^ ]*/ root=\$RFS $rootwait quiet /g" $GRUBCFG
+ # Mentor - SWUpdate - create our fallback menuentry
+ sed -i "1ifallback=1" $GRUBCFG
+ cmd=$(grep "linux " $GRUBCFG)
+--
+2.11.1
+
diff --git a/common/mentor-swupdate/recipes-core/initrdscripts/files/0007-init-install-efi-grub-don-t-set-a-timeout.patch b/common/mentor-swupdate/recipes-core/initrdscripts/files/0007-init-install-efi-grub-don-t-set-a-timeout.patch
new file mode 100644
index 00000000..19500143
--- /dev/null
+++ b/common/mentor-swupdate/recipes-core/initrdscripts/files/0007-init-install-efi-grub-don-t-set-a-timeout.patch
@@ -0,0 +1,30 @@
+From 31a8e28e9a1735d58fa0a70ea92d66233fe48c4b Mon Sep 17 00:00:00 2001
+From: Awais Belal <awais_belal@mentor.com>
+Date: Wed, 16 Jan 2019 16:18:54 +0500
+Subject: [PATCH 7/7] init-install-efi: grub don't set a timeout
+
+We don't want our installed system to show grub
+menus as it wouldn't make any sense and we also
+want to switch to the fallback entry seamlessly.
+
+Signed-off-by: Awais Belal <awais_belal@mentor.com>
+---
+ init-install-efi.sh | 2 ++
+ 1 file changed, 2 insertions(+)
+
+diff --git a/init-install-efi.sh b/init-install-efi.sh
+index efe0c64..ba0de76 100644
+--- a/init-install-efi.sh
++++ b/init-install-efi.sh
+@@ -298,6 +298,8 @@ if [ -f /run/media/$1/EFI/BOOT/grub.cfg ]; then
+ sed -i "/initrd /d" $GRUBCFG
+ # Delete any LABEL= strings
+ sed -i "s/ LABEL=[^ ]*/ /" $GRUBCFG
++ # Mentor- SWUpdate - don't set a timeout
++ sed -i "s/timeout=.*/timeout=0/" $GRUBCFG
+ # Mentor- SWUpdate - force grub to load our env which we'll use to specify RFS and KERNEL
+ sed -i "1iload_env --file ${GRUBENV#\/boot}" $GRUBCFG
+ # Set current and fallback rootfs using variable via our grub.env
+--
+2.11.1
+