Selaa lähdekoodia

Receipes to generate a swupdate image

Signed-off-by: Stefano Babic <sbabic@denx.de>
Stefano Babic 12 vuotta sitten
commit
020c327419

+ 17 - 0
COPYING.MIT

@@ -0,0 +1,17 @@
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.

+ 16 - 0
README

@@ -0,0 +1,16 @@
+meta-swupdate, Yocto layer for deploy tool
+==========================================
+
+This layer's purpose is to add support for a deployment
+mechanism of Yocto's images based on swupdate project.
+
+Layer dependencies
+------------------
+
+meta and meta-yocto must be added to the layer definitions.
+Tested with the meta-eldk layer, but not strictly required.
+
+Maintainer
+----------
+
+Stefano Babic <sbabic@denx.de>

+ 10 - 0
conf/layer.conf

@@ -0,0 +1,10 @@
+# We have a conf and classes directory, add to BBPATH
+BBPATH := "${BBPATH}:${LAYERDIR}"
+
+# We have a recipes directory, add to BBFILES
+BBFILES := "${BBFILES} ${LAYERDIR}/recipes-*/*/*.bb \
+	${LAYERDIR}/recipes-*/*/*.bbappend"
+
+BBFILE_COLLECTIONS += "swupdate"
+BBFILE_PATTERN_swupdate := "^${LAYERDIR}/"
+BBFILE_PRIORITY_swupdate = "6"

+ 24 - 0
recipes-core/initscripts/initscripts-swupdate.bb

@@ -0,0 +1,24 @@
+SUMMARY = "Different startup scripts"
+SECTION = "base"
+PR = "r0"
+LICENSE = "MIT"
+LIC_FILES_CHKSUM = "file://${COREBASE}/LICENSE;md5=3f40d7994397109285ec7b81fdeb3b58"
+
+SRC_URI = "file://rcS.swupdate \
+	"
+
+S = "${WORKDIR}"
+
+do_install () {
+	install -d ${D}/${sysconfdir}
+	install -d ${D}/${sysconfdir}/init.d
+	rm -f ${D}${sysconfdir}/init.d/rcS
+	install -m 755 ${S}/rcS.swupdate ${D}${sysconfdir}/init.d
+}
+
+PACKAGES = "${PN}"
+FILES_${PN} = "/"
+
+PACKAGE_ARCH = "${MACHINE_ARCH}"
+
+CONFFILES_${PN} = ""

+ 99 - 0
recipes-core/initscripts/initscripts-swupdate/rcS.swupdate

@@ -0,0 +1,99 @@
+#!/bin/sh
+
+PATH=/sbin:/bin:/usr/sbin:/usr/bin
+USB=/mnt/card
+
+umask 022
+mount -t proc proc /proc
+mount sysfs /sys -t sysfs
+if [ -e /proc/cpu/alignment ]; then
+   echo "3" > /proc/cpu/alignment
+fi
+mount tmpfs -t tmpfs $TMPDIR -o,size=40k
+
+echo 0 > /proc/sys/kernel/printk
+
+mount_usb() {
+found=0
+for i in /dev/sda?;do
+	if [ $i == "/dev/sda?" ];then
+		break
+	fi
+	mount $i ${USB} 2>/dev/null
+
+	if [ $? != 0 ];then 
+		continue
+	fi
+
+	return 0
+done
+
+# Try to mount a USB without partition table
+	mount /dev/sda  ${USB} 2>/dev/null
+	return $?
+
+}
+
+rotation=0
+if [ -e /etc/rotation ]; then
+	read rotation < /etc/rotation
+fi
+
+
+# wait until the device node is created
+reset
+echo "Checking for application software"
+echo "---------------------------------"
+echo "  "
+
+cp /etc/fw_env.config /tmp/.
+
+while [ 1 ];do
+	echo "Waiting for USB Pen..."
+	sleep 3
+
+	mount_usb
+	if [ $? == 0 ];then
+		break
+	fi
+done
+
+if [ -f ${USB}/software*.img ];then
+	found=1
+	break
+fi
+
+if [ $found == 0 ];then
+	echo "No Software Image found....exiting !"
+fi
+
+
+for file in ${USB}/software*.img;do
+	echo " "
+	echo "Starting Software Update"
+	echo "------------------------"
+	echo Image found : $file
+	echo " "
+	swupdate -i $file -v	
+	if [ $? == 0 ];then
+		echo "SUCCESS !"
+	else
+		echo "FAILURE !"
+	fi
+	sleep 5
+	break
+done
+
+console=`cat /sys/class/tty/console/active`
+
+echo "console is $console"
+
+if [ x$console != "xttyO0" ];then
+	while [ 1 ]; do
+		echo "Please reboot the system !"
+		sleep 90
+		reboot
+	done
+fi
+/bin/sh
+exit 0

+ 13 - 0
recipes-devtools/mtd/mtd-utils_1.5.0.bbappend

@@ -0,0 +1,13 @@
+FILES_${PN}-staticdev += "ubi-utils/libubi.a ${libdir}/*.a"
+
+do_install_append () {
+	install -d ${D}${includedir}/mtd/
+	install -d ${D}${libdir}/
+	install -m 0644 ubi-utils/include/libubi.h ${D}${includedir}/mtd/
+	install -m 0644 include/libmtd.h ${D}${includedir}/mtd/
+	install -m 0644 include/mtd/ubi-media.h ${D}${includedir}/mtd/
+	oe_libinstall -a -C ubi-utils libubi ${D}${libdir}/
+	oe_libinstall -a -C lib libmtd ${D}${libdir}/
+}
+
+BBCLASSEXTEND += "native"

+ 68 - 0
recipes-extended/images/swupdate-image.bb

@@ -0,0 +1,68 @@
+SUMMARY = "Root file system image for MCX board"
+DESCRIPTION = "Root FS includes the following functionality: 				\
+		Busybox: standard for ELDK 5.2 (syslogd removed) 			\
+		mtd-utils: standard for ELDK 5.2 					\
+		base-files: standard script for ELDK 5.2 (/var/log placement changed) 	\
+		tinylogin: standard for ELDK 5.2 					\
+		sysvinit: standard for ELDK 5.2 (bootlogd removed)			\
+		initscripts: modified standard script for ELDK 5.2			\
+		"
+
+
+SRC_URI = "file://rcS.swupdate \
+	"
+
+IMAGE_INSTALL = "base-files \
+		busybox \
+		mtd-utils \
+		libconfig \
+		tinylogin \
+		swupdate \
+		sysvinit \
+		initscripts-swupdate \
+		 "
+
+
+
+LIC_FILES_CHKSUM = "file://${COREBASE}/LICENSE;md5=3f40d7994397109285ec7b81fdeb3b58 \
+                    file://${COREBASE}/meta/COPYING.MIT;md5=3da9cfbcb788c80a0384361b4de20420 \
+		   "
+
+# This variable is triggered to check if sysvinit must be overwritten by a single rcS
+export SYSVINIT = "no"
+
+LICENSE = "MIT"
+
+IMAGE_CLASSES += " image_types_uboot"
+IMAGE_FSTYPES = "ext3.gz.u-boot"
+
+IMAGE_ROOTFS_SIZE = "8192"
+
+inherit image
+
+remove_locale_data_files() {
+	printf "Post processing local %s\n" ${IMAGE_ROOTFS}${libdir}/locale
+	rm -rf ${IMAGE_ROOTFS}${libdir}/locale
+}
+
+fix_inittab_swupdate () {
+	sed -e 's/1\:2345.*/1\:2345:respawn:\/bin\/sh/' \
+		"${IMAGE_ROOTFS}${sysconfdir}/inittab" | \
+		sed -e 's/^z6/#&/' | \
+		 sed -e 's/S:2345.*//' \
+		> "${IMAGE_ROOTFS}${sysconfdir}/inittab.swupdate"
+	rm ${IMAGE_ROOTFS}${sysconfdir}/inittab
+	mv ${IMAGE_ROOTFS}${sysconfdir}/inittab.swupdate ${IMAGE_ROOTFS}${sysconfdir}/inittab
+}
+
+exchange_rcs () {
+	rm ${IMAGE_ROOTFS}${sysconfdir}/init.d/rcS
+	mv ${IMAGE_ROOTFS}${sysconfdir}/init.d/rcS.swupdate \
+		${IMAGE_ROOTFS}${sysconfdir}/init.d/rcS
+}
+	 
+# remove not needed ipkg informations
+ROOTFS_POSTPROCESS_COMMAND += "remove_packaging_data_files ; "
+ROOTFS_POSTPROCESS_COMMAND += "remove_locale_data_files ; "
+ROOTFS_POSTPROCESS_COMMAND += "fix_inittab_swupdate ; "
+ROOTFS_POSTPROCESS_COMMAND += "exchange_rcs ; "

+ 14 - 0
recipes-support/libconfig/libconfig_1.4.9.bb

@@ -0,0 +1,14 @@
+SUMMARY = "C/C++ Configuration File Library"
+DESCRIPTION = "Library for manipulating structured configuration files"
+HOMEPAGE = "http://www.hyperrealm.com/libconfig/"
+SECTION = "libs"
+
+LICENSE = "LGPLv2.1"
+LIC_FILES_CHKSUM = "file://COPYING.LIB;md5=fad9b3332be894bab9bc501572864b29"
+
+SRC_URI = "http://www.hyperrealm.com/${BPN}/${BP}.tar.gz"
+
+inherit autotools pkgconfig
+
+SRC_URI[md5sum] = "b6ee0ce2b3ef844bad7cac2803a90634"
+SRC_URI[sha256sum] = "09c8979252e60193e2969e9b0e1cd597f7820087867989b2f0939ad164473041"

+ 55 - 0
recipes-support/swupdate/swupdate.bb

@@ -0,0 +1,55 @@
+SUMMARY="Image updater for Yocto projects"
+DESCRIPTION = "Application for automatic software update from USB Pen"
+SECTION="swupdate"
+DEPENDS = "mtd-utils libconfig"
+LICENSE = "GPLv2+"
+LIC_FILES_CHKSUM = "file://COPYING;md5=0636e73ff0215e8d672dc4c32c317bb3"
+
+PR = "r0"
+
+inherit cml1 update-rc.d
+
+
+SRCREV = "${AUTOREV}"
+SRC_URI = "git://github.com/sbabic/swupdate.git;protocol=git \
+	   file://defconfig \
+	   file://swupdate \
+	   "
+
+PACKAGES =+ "${PN}-www"
+
+FILES_${PN}-www = "/www/*"
+FILES_${PN} = "${bindir}/* /etc/init.d"
+CONFFILES_${PN} += "${sysconfdir}/init.d/recovery"
+
+S = "${WORKDIR}/git/"
+
+EXTRA_OEMAKE += "V=1 ARCH=${TARGET_ARCH} CROSS_COMPILE=${TARGET_PREFIX} SKIP_STRIP=y"
+
+do_configure () {
+	cp ${WORKDIR}/defconfig ${S}/.config
+	cml1_do_configure
+}
+
+do_install () {
+	install -d ${D}${bindir}/
+	install -m 0755 swupdate ${D}${bindir}/
+
+	install -m 0755 -d ${D}/www
+        install -m 0755 ${S}www/* ${D}/www
+
+	install -d ${D}${sysconfdir}/init.d
+	install -m 755 ${WORKDIR}/swupdate ${D}${sysconfdir}/init.d
+
+}
+
+do_compile() {
+	unset CFLAGS CPPFLAGS CXXFLAGS LDFLAGS
+	oe_runmake swupdate_unstripped
+	cp swupdate_unstripped swupdate
+}
+
+PARALLEL_MAKE = ""
+
+INITSCRIPT_NAME = "swupdate"
+INITSCRIPT_PARAMS = "defaults 70"

+ 77 - 0
recipes-support/swupdate/swupdate/defconfig

@@ -0,0 +1,77 @@
+#
+# Automatically generated make config: don't edit
+# Busybox version: 0.1.0.git
+# Sun Oct 27 15:59:59 2013
+#
+CONFIG_HAVE_DOT_CONFIG=y
+
+#
+# Swupdate Settings
+#
+
+#
+# General Configuration
+#
+CONFIG_SCRIPTS=y
+CONFIG_HW_COMPATIBILITY=y
+CONFIG_HW_COMPATIBILITY_FILE="/etc/hwrevision"
+# CONFIG_FEATURE_SYSLOG is not set
+
+#
+# Build Options
+#
+# CONFIG_STATIC is not set
+CONFIG_CROSS_COMPILER_PREFIX=""
+CONFIG_SYSROOT=""
+CONFIG_EXTRA_CFLAGS=""
+CONFIG_EXTRA_LDFLAGS=""
+CONFIG_EXTRA_LDLIBS=""
+
+#
+# Debugging Options
+#
+# CONFIG_DEBUG is not set
+# CONFIG_DEBUG_PESSIMIZE is not set
+# CONFIG_WERROR is not set
+CONFIG_WEBSERVER=y
+
+#
+# Webserver Features
+#
+CONFIG_MONGOOSE=y
+
+#
+# Mongoose Feature
+#
+CONFIG_MONGOOSELUA=y
+# CONFIG_MONGOOSESQL is not set
+CONFIG_MONGOOSEIPV6=y
+CONFIG_MONGOOSESSL=y
+
+#
+# Archival Features
+#
+CONFIG_CPIO=y
+CONFIG_GUNZIP=y
+
+#
+# Parser Features
+#
+CONFIG_LIBCONFIG=y
+CONFIG_LUAEXTERNAL=y
+# CONFIG_SETSWDESCRIPTION is not set
+CONFIG_SWDESCRIPTION=""
+
+#
+# Image Handlers
+#
+CONFIG_UBIVOL=y
+CONFIG_CFI=y
+CONFIG_RAW=y
+CONFIG_LUASCRIPTHANDLER=y
+CONFIG_UBOOT=y
+
+#
+# LUA Features
+#
+CONFIG_LUA=y

+ 178 - 0
recipes-support/swupdate/swupdate/swupdate

@@ -0,0 +1,178 @@
+#! /bin/sh
+### BEGIN INIT INFO
+# Provides:          swupdate
+# Required-Start:    $local_fs
+# Should-Start:
+# Required-Stop:     $local_fs
+# Should-Stop:
+# Default-Start:     2 3 4 5
+# Default-Stop:      0 1 6
+# Short-Description: Start swupdate application
+### END INIT INFO
+
+# The definition of actions: (From LSB 3.1.0)
+# start         start the service
+# stop          stop the service
+# restart       stop and restart the service if the service is already running,
+#               otherwise start the service
+# try-restart	restart the service if the service is already running
+# reload	cause the configuration of the service to be reloaded without
+#               actually stopping and restarting the service
+# force-reload	cause the configuration to be reloaded if the service supports
+#               this, otherwise restart the service if it is running
+# status	print the current status of the service
+
+# The start, stop, restart, force-reload, and status actions shall be supported
+# by all init scripts; the reload and the try-restart actions are optional
+
+# PATH should only include /usr/* if it runs after the mountnfs.sh script
+PATH=/sbin:/usr/sbin:/bin:/usr/bin
+
+DESC="swupdate"
+NAME="swupdate"
+DAEMON=/usr/bin/swupdate
+DAEMON_ARGS="-document_root /www"
+PIDFILE=/var/run/$NAME.pid
+
+. /etc/init.d/functions || exit 1
+
+# Exit if the package is not installed
+[ -x "$DAEMON" ] || exit 0
+
+# Read configuration variable file if it is present
+[ -r /etc/default/$NAME ] && . /etc/default/$NAME
+
+#
+# Function that starts the daemon/service
+#
+do_start() {
+	local status pid
+
+	status=0
+	pid=`pidofproc $NAME` || status=$?
+	case $status in
+	0)
+		echo "$DESC already running ($pid)."
+		exit 1
+		;;
+	*)
+		echo "Starting $DESC ..."
+		cd /home/root
+# Reset bootcounter
+		echo 0 > /sys/devices/virtual/misc/bootcount/bootcount
+		exec $DAEMON $DAEMON_ARGS >/dev/null 2>&1 &
+		exit 0
+		;;
+	esac
+}
+
+#
+# Function that stops the daemon/service
+#
+do_stop() {
+	local pid status
+
+	status=0
+	pid=`pidofproc $NAME` || status=$?
+	case $status in
+	0)
+		# Exit when fail to stop, the kill would complain when fail
+		kill -s 15 $pid >/dev/null && rm -f $PIDFILE && \
+			echo "Stopped $DESC ($pid)." || exit $?
+		;;
+	*)
+		echo "$DESC is not running; none killed." >&2
+		;;
+	esac
+
+	# Wait for children to finish too if this is a daemon that forks
+	# and if the daemon is only ever run from this initscript.
+	# If the above conditions are not satisfied then add some other code
+	# that waits for the process to drop all resources that could be
+	# needed by services started subsequently.  A last resort is to
+	# sleep for some time.
+	return $status
+}
+
+#
+# Function that sends a SIGHUP to the daemon/service
+#
+do_reload() {
+	local pid status
+
+	status=0
+        # If the daemon can reload its configuration without
+        # restarting (for example, when it is sent a SIGHUP),
+        # then implement that here.
+	pid=`pidofproc $NAME` || status=$?
+	case $status in
+	0)
+		echo "Reloading $DESC ..."
+		kill -s 1 $pid || exit $?
+		;;
+	*)
+		echo "$DESC is not running; none reloaded." >&2
+		;;
+	esac
+	exit $status
+}
+
+
+#
+# Function that shows the daemon/service status
+#
+status_of_proc () {
+	local pid status
+
+	status=0
+	# pidof output null when no program is running, so no "2>/dev/null".
+	pid=`pidofproc $NAME` || status=$?
+	case $status in
+	0)
+		echo "$DESC is running ($pid)."
+		exit 0
+		;;
+	*)
+		echo "$DESC is not running." >&2
+		exit $status
+		;;
+	esac
+}
+
+case "$1" in
+start)
+	do_start
+	;;
+stop)
+	do_stop || exit $?
+	;;
+status)
+	status_of_proc
+	;;
+restart)
+	# Always start the service regardless the status of do_stop
+	do_stop
+	do_start
+	;;
+try-restart|force-reload)
+	# force-reload is the same as reload or try-restart according
+	# to its definition, the reload is not implemented here, so
+	# force-reload is the alias of try-restart here, but it should
+	# be the alias of reload if reload is implemented.
+	#
+	# Only start the service when do_stop succeeds
+	do_stop && do_start
+	;;
+#reload)
+	# If the "reload" action is implemented properly, then let the
+	# force-reload be the alias of reload, and remove it from
+	# try-restart|force-reload)
+	#
+	#do_reload
+	#;;
+*)
+	echo "Usage: $0 {start|stop|status|restart|try-restart|force-reload}" >&2
+	exit 3
+	;;
+esac
+