From 21fb5aff39ec63ae7c69b02d26e694f07016816f Mon Sep 17 00:00:00 2001 From: Amaury Pouly Date: Tue, 27 Sep 2016 00:09:06 +0100 Subject: nwztools: rework upg scripts The exec_file allows to embed a script/executable and run it on target. It takes of unpacking, remounting contents rw and redirect output to exec.txt at the root of the drive. More generally, rework how the makefile works. Change-Id: Iec719227be96e80701ad8f5398d2d34389f4da9e --- utils/nwztools/scripts/exec_file.sh | 62 +++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 utils/nwztools/scripts/exec_file.sh (limited to 'utils/nwztools/scripts/exec_file.sh') diff --git a/utils/nwztools/scripts/exec_file.sh b/utils/nwztools/scripts/exec_file.sh new file mode 100644 index 0000000000..059014de2c --- /dev/null +++ b/utils/nwztools/scripts/exec_file.sh @@ -0,0 +1,62 @@ +#!/bin/sh + +# The updater script on the NWZ has a major bug/feature: +# it does NOT clear the update flag if the update scrit fails +# thus causing a update/reboot loop and a bricked device +# always clear to make sure we don't end up being screwed +nvpflag fup 0xFFFFFFFF + +# +# This script extracts the second file from the UPG to /tmp and runs it +# + + +# go to /tmp +cd /tmp + +# get content partition path +CONTENTS="/contents" +CONTENTS_PART=`mount | grep contents | awk '{ print $1 }'` + +lcdmsg -c -f /usr/local/bin/font_08x12.bmp -l 0,3 "Contents partition:\n$CONTENTS_PART" + +# 2) We need to remount the contents partition in read-write mode be able to +# write something on it +lcdmsg -f /usr/local/bin/font_08x12.bmp -l 0,6 "Remount $CONTENTS rw" +if ! mount -o remount,rw $CONTENTS_PART $CONTENTS +then + lcdmsg -f /usr/local/bin/font_08x12.bmp -l 0,7 "ERROR: remount failed" + sleep 3 + exit 0 +fi + +# get update filename +_UPDATE_FN_=`nvpstr ufn` + +# extract second file +fwpchk -f /contents/$_UPDATE_FN_.UPG -c -1 exec +if [ "$?" != 0 ]; then + lcdmsg -f /usr/local/bin/font_08x12.bmp -l 0,7 "ERROR: no file to execute" + sleep 3 + exit 0 +fi + +# make it executable +chmod 755 exec +if [ "$?" != 0 ]; then + lcdmsg -f /usr/local/bin/font_08x12.bmp -l 0,7 "ERROR: cannot make it executable" + sleep 3 + exit 0 +fi + +# run it and redirect all outputs to exec.txt +lcdmsg -f /usr/local/bin/font_08x12.bmp -l 0,7 "Running file..." +/tmp/exec 2>&1 >$CONTENTS/exec.txt + +# 4) Success screen +lcdmsg -f /usr/local/bin/font_08x12.bmp -l 0,15 "Rebooting in 3 seconds." +sleep 3 +sync + +# finish +exit 0 -- cgit v1.2.3