Commit 0c5b4ac8 authored by David Mondou's avatar David Mondou

Initial check in.

parents
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.
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
------------------
This layer depends on:
URI: git://github.com/openembedded/meta-openembedded.git
subdirectory: meta-oe
Image hashing
-------------
During creation of the update file, occurrences of @IMAGE (where IMAGE is an
image filename) are replaced with the sha256 hash of the image.
SWU image signing
------------
To enable signing:
Set SWUPDATE_SIGNING = "1"
Set SWUPDATE_PRIVATE_KEY to the full path of private key file
sw-description is signed with the private key and the signature is writen to
sw-description.sig which is included in the SWU file.
Encrypted private keys are not currently supported since a secure
mechanism must exist to provide the passphrase.
Maintainer
----------
Stefano Babic <sbabic@denx.de>
Submitting patches
------------------
You can submit your patches (or post questions reagarding
this layer to the swupdate Mailing List:
swupdate@googlegroups.com
When creating patches, please use something like:
git format-patch -s --subject-prefix='meta-swupdate][PATCH' <revision range>
Please use 'git send- email' to send the generated patches to the ML
to bypass changes from your mailer.
# Copyright (C) 2015 Stefano Babic <sbabic@denx.de>
#
# Some parts from the patch class
#
# swupdate allows to generate a compound image for the
# in the "swupdate" format, used for updating the targets
# in field.
# See also http://sbabic.github.io/swupdate/
#
#
# To use, add swupdate to the inherit clause and set
# set the images (all of them must be found in deploy directory)
# that are part of the compound image.
S = "${WORKDIR}/${PN}"
DEPENDS += "${@ 'openssl-native' if d.getVar('SWUPDATE_SIGNING', True) == '1' else ''}"
IMAGE_DEPENDS ?= ""
def swupdate_is_hash_needed(s, filename):
with open(os.path.join(s, "sw-description"), 'r') as f:
for line in f:
if line.find("@%s" % (filename)) != -1:
return True
return False
def swupdate_get_sha256(s, filename):
import hashlib
m = hashlib.sha256()
with open(os.path.join(s, filename), 'rb') as f:
while True:
data = f.read(1024)
if not data:
break
m.update(data)
return m.hexdigest()
def swupdate_write_sha256(s, filename, hash):
write_lines = []
with open(os.path.join(s, "sw-description"), 'r') as f:
for line in f:
write_lines.append(line.replace("@%s" % (filename), hash))
with open(os.path.join(s, "sw-description"), 'w+') as f:
for line in write_lines:
f.write(line)
def swupdate_getdepends(d):
def adddep(depstr, deps):
for i in (depstr or "").split():
if i not in deps:
deps.append(i)
deps = []
images = (d.getVar('IMAGE_DEPENDS', True) or "").split()
for image in images:
adddep(image , deps)
depstr = ""
for dep in deps:
depstr += " " + dep + ":do_build"
return depstr
do_swuimage[dirs] = "${TOPDIR}"
do_swuimage[cleandirs] += "${S}"
do_swuimage[umask] = "022"
do_configure[noexec] = "1"
do_compile[noexec] = "1"
do_install[noexec] = "1"
do_package[noexec] = "1"
do_package_qa[noexec] = "1"
do_packagedata[noexec] = "1"
do_package_write_ipk[noexec] = "1"
do_package_write_deb[noexec] = "1"
do_package_write_rpm[noexec] = "1"
python () {
deps = " " + swupdate_getdepends(d)
d.appendVarFlag('do_swuimage', 'depends', deps)
}
do_install () {
}
do_createlink () {
cd ${DEPLOY_DIR_IMAGE}
ln -sf ${IMAGE_NAME}.swu ${IMAGE_LINK_NAME}.swu
}
python do_swuimage () {
import shutil
workdir = d.getVar('WORKDIR', True)
images = (d.getVar('SWUPDATE_IMAGES', True) or "").split()
s = d.getVar('S', True)
shutil.copyfile(os.path.join(workdir, "sw-description"), os.path.join(s, "sw-description"))
fetch = bb.fetch2.Fetch([], d)
list_for_cpio = ["sw-description"]
if d.getVar('SWUPDATE_SIGNING', True) == '1':
list_for_cpio.append('sw-description.sig')
for url in fetch.urls:
local = fetch.localpath(url)
filename = os.path.basename(local)
if (filename != 'sw-description'):
shutil.copyfile(local, os.path.join(s, "%s" % filename ))
list_for_cpio.append(filename)
# SWUPDATE_IMAGES refers to images in the DEPLOY directory
# If they are not there, additional file can be added
# by fetching from URLs
deploydir = d.getVar('DEPLOY_DIR_IMAGE', True)
for image in images:
fstypes = (d.getVarFlag("SWUPDATE_IMAGES_FSTYPES", image, True) or "").split()
if not fstypes:
fstypes = [""]
for fstype in fstypes:
appendmachine = d.getVarFlag("SWUPDATE_IMAGES_NOAPPEND_MACHINE", image, True)
if appendmachine == None:
imagebase = image + '-' + d.getVar('MACHINE', True)
else:
imagebase = image
imagename = imagebase + fstype
src = os.path.join(deploydir, "%s" % imagename)
dst = os.path.join(s, "%s" % imagename)
shutil.copyfile(src, dst)
list_for_cpio.append(imagename)
for file in list_for_cpio:
if file != 'sw-description' and swupdate_is_hash_needed(s, file):
hash = swupdate_get_sha256(s, file)
swupdate_write_sha256(s, file, hash)
if d.getVar('SWUPDATE_SIGNING', True) == '1':
privkey = d.getVar('SWUPDATE_PRIVATE_KEY', True)
if not privkey:
bb.fatal("SWUPDATE_PRIVATE_KEY isn't set")
if not os.path.exists(privkey):
bb.fatal("SWUPDATE_PRIVATE_KEY %s doesn't exist" % (privkey))
passout = d.getVar('SWUPDATE_PASSWORD_FILE', True)
if passout:
passout = "-passin file:'%s' " % (passout)
else:
passout = ""
signcmd = "openssl dgst -sha256 -sign '%s' %s -out '%s' '%s'" % (
privkey,
passout,
os.path.join(s, 'sw-description.sig'),
os.path.join(s, 'sw-description'))
if os.system(signcmd) != 0:
bb.fatal("Failed to sign sw-description with %s" % (privkey))
line = 'for i in ' + ' '.join(list_for_cpio) + '; do echo $i;done | cpio -ov -H crc >' + os.path.join(deploydir,d.getVar('IMAGE_NAME', True) + '.swu')
os.system("cd " + s + ";" + line)
}
COMPRESSIONTYPES = ""
PACKAGE_ARCH = "${MACHINE_ARCH}"
addtask do_swuimage after do_unpack before do_install
addtask do_createlink after do_swuimage before do_install
# 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"
# LUA is retrieved from meta-oe
LAYERDEPENDS_swupdate-layer = "oe"
From e6850fcf6273b2068c5ae659bbacd8c7f664fd26 Mon Sep 17 00:00:00 2001
From: Stefano Babic <sbabic@denx.de>
Date: Mon, 22 Jun 2015 14:58:24 +0200
Subject: [PATCH] Allow fw env tools to be available as library
Signed-off-by: Stefano Babic <sbabic@denx.de>
---
tools/env/Makefile | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/tools/env/Makefile b/tools/env/Makefile
index 40164f7..38ad118 100644
--- a/tools/env/Makefile
+++ b/tools/env/Makefile
@@ -23,10 +23,12 @@ endif
always := fw_printenv
hostprogs-y := fw_printenv
-fw_printenv-objs := fw_env.o fw_env_main.o \
+lib-y += fw_env.o \
crc32.o ctype.o linux_string.o \
env_attr.o env_flags.o aes.o
+fw_printenv-objs := fw_env_main.o $(lib-y)
+
quiet_cmd_crosstools_strip = STRIP $^
cmd_crosstools_strip = $(STRIP) $^; touch $@
--
1.9.1
FILESEXTRAPATHS_prepend := "${THISDIR}/files:"
do_install_append() {
install -d ${D}${libdir}
install -m 644 ${S}/tools/env/lib.a ${D}${libdir}/libubootenv.a
}
SUMMARY = "Different startup scripts"
SECTION = "base"
PR = "r0"
LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://${COREBASE}/LICENSE;md5=4d92cd373abda3937c2bc47fbc49d690"
SRC_URI = "file://rcS.swupdate \
"
S = "${WORKDIR}"
do_install () {
install -d ${D}/${sysconfdir}/init.d
install -d ${D}${base_sbindir}
install -m 755 ${S}/rcS.swupdate ${D}${base_sbindir}/init
}
PACKAGES = "${PN}"
FILES_${PN} = "/"
PACKAGE_ARCH = "${MACHINE_ARCH}"
CONFFILES_${PN} = ""
#!/bin/sh
PATH=/sbin:/bin:/usr/sbin:/usr/bin
USB=/mnt
umask 022
mount -t proc proc /proc
mount sysfs /sys -t sysfs
if [ -e /proc/cpu/alignment ]; then
echo "3" > /proc/cpu/alignment
fi
echo 0 > /proc/sys/kernel/printk
echo 100 > /sys/class/backlight/pwm-backlight/brightness
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
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
echo " "
echo "Starting Software Update"
echo "------------------------"
swupdate -i "${USB}/*.swu" -v
if [ $? == 0 ];then
echo "SUCCESS !"
else
echo "FAILURE !"
fi
while [ 1 ]; do
echo "Please reboot the system !"
sleep 90
reboot
done
exit 0
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"
# Copyright (C) 2015 Unknown User <unknow@user.org>
# Released under the MIT license (see COPYING.MIT for the terms)
DESCRIPTION = "Example Compound image for beaglebone "
SECTION = ""
# Note: sw-description is mandatory
SRC_URI_beaglebone = "file://sw-description \
"
inherit swupdate
LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://${COREBASE}/LICENSE;md5=4d92cd373abda3937c2bc47fbc49d690 \
file://${COREBASE}/meta/COPYING.MIT;md5=3da9cfbcb788c80a0384361b4de20420"
# IMAGE_DEPENDS: list of Yocto images that contains a root filesystem
# it will be ensured they are built before creating swupdate image
IMAGE_DEPENDS = ""
# SWUPDATE_IMAGES: list of images that will be part of the compound image
# the list can have any binaries - images must be in the DEPLOY directory
SWUPDATE_IMAGES = " \
core-image-full-cmdline \
"
# Images can have multiple formats - define which image must be
# taken to be put in the compound image
SWUPDATE_IMAGES_FSTYPES[core-image-full-cmdline] = ".ext3"
COMPATIBLE = "beaglebone"
software =
{
version = "0.1.0";
hardware-compatibility: [ "revC"];
images: (
{
filename = "core-image-full-cmdline-beaglebone.ext3";
device = "/dev/mmcblk1p2";
type = "raw";
}
);
}
SUMMARY = "Root filesystem for swuupdate as rescue system"
DESCRIPTION = "Root FS to start swupdate in rescue mode \
"
IMAGE_INSTALL = "base-files \
base-passwd \
busybox \
mtd-utils \
mtd-utils-ubifs \
libconfig \
swupdate \
swupdate-www \
${@bb.utils.contains('SWUPDATE_INIT', 'tiny', 'initscripts-swupdate', 'initscripts sysvinit', d)} \
util-linux-sfdisk \
"
USE_DEVFS = "1"
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/.*getty.*//' \
> "${IMAGE_ROOTFS}${sysconfdir}/inittab.swupdate"
rm ${IMAGE_ROOTFS}${sysconfdir}/inittab
mv ${IMAGE_ROOTFS}${sysconfdir}/inittab.swupdate ${IMAGE_ROOTFS}${sysconfdir}/inittab
}
# remove not needed ipkg informations
ROOTFS_POSTPROCESS_COMMAND += "remove_locale_data_files ; "
ROOTFS_POSTPROCESS_COMMAND += "${@bb.utils.contains('SWUPDATE_INIT', 'tiny', 'fix_inittab_swupdate', '', d)}"
SUMMARY="Image updater for Yocto projects"
DESCRIPTION = "Application for automatic software update from USB Pen"
SECTION="swupdate"
DEPENDS = "libconfig openssl gnutls"
LICENSE = "GPLv2+"
LIC_FILES_CHKSUM = "file://COPYING;md5=0636e73ff0215e8d672dc4c32c317bb3"
inherit cml1 update-rc.d systemd
SRC_URI = "git://github.com/sbabic/swupdate.git;protocol=git \
file://defconfig \
file://swupdate \
file://swupdate.service \
"
SRCREV = "${AUTOREV}"
PACKAGES =+ "${PN}-www"
FILES_${PN}-www = "/www/*"
FILES_${PN}-dev = "${includedir}"
FILES_${PN}-staticdev = "${libdir}"
FILES_${PN} = "${bindir}/* /etc"
S = "${WORKDIR}/git/"
EXTRA_OEMAKE += "V=1 ARCH=${TARGET_ARCH} CROSS_COMPILE=${TARGET_PREFIX} SKIP_STRIP=y"
python () {
try:
defconfig = bb.fetch2.localpath('file://defconfig', d)
except bb.fetch2.FetchError:
return
try:
configfile = open(defconfig)
except IOError:
return
features = configfile.readlines()
configfile.close()
if 'CONFIG_REMOTE_HANDLER=y\n' in features:
depends = d.getVar('DEPENDS', False)
d.setVar('DEPENDS', depends + ' zeromq')
if 'CONFIG_JSON=y\n' in features:
depends = d.getVar('DEPENDS', False)
d.setVar('DEPENDS', depends + ' json-c')
if 'CONFIG_ARCHIVE=y\n' in features:
depends = d.getVar('DEPENDS', False)
d.setVar('DEPENDS', depends + ' libarchive')
if 'CONFIG_LUA=y\n' in features:
depends = d.getVar('DEPENDS', False)
d.setVar('DEPENDS', depends + ' lua')
if 'CONFIG_UBOOT=y\n' in features:
depends = d.getVar('DEPENDS', False)
d.setVar('DEPENDS', depends + ' u-boot-fw-utils')
if 'CONFIG_DOWNLOAD=y\n' in features or 'CONFIG_SURICATTA=y\n' in features:
depends = d.getVar('DEPENDS', False)
d.setVar('DEPENDS', depends + ' curl')
if 'CONFIG_MTD=y\n' in features:
depends = d.getVar('DEPENDS', False)
d.setVar('DEPENDS', depends + ' mtd-utils')
}
do_configure () {
cp ${WORKDIR}/defconfig ${S}/.config
cml1_do_configure
}
do_compile() {
unset CFLAGS CPPFLAGS CXXFLAGS LDFLAGS
oe_runmake swupdate_unstripped
cp swupdate_unstripped swupdate
if [ "${@bb.utils.vercmp_string('${PV}', '2016.07')}" = "1" ]; then
oe_runmake progress_unstripped
cp progress_unstripped progress
fi
}
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}${libdir}/
install -d ${D}${includedir}/
install -m 0644 ${S}include/network_ipc.h ${D}${includedir}
install -m 0755 ${S}ipc/lib.a ${D}${libdir}/libswupdate.a
install -d ${D}${sysconfdir}/init.d
install -m 755 ${WORKDIR}/swupdate ${D}${sysconfdir}/init.d
install -d ${D}${systemd_unitdir}/system
install -m 644 ${WORKDIR}/swupdate.service ${D}${systemd_unitdir}/system
}
INITSCRIPT_NAME = "swupdate"
INITSCRIPT_PARAMS = "defaults 70"
SYSTEMD_SERVICE_${PN} = "swupdate.service"
#
# Automatically generated file; DO NOT EDIT.
# Swupdate Configuration