Просмотр исходного кода

Merge branch 'master' into thud

This allows to build current SWUpdate version witl oder (even if EOL)
release thud.

Signed-off-by: Stefano Babic <sbabic@denx.de>
Stefano Babic 5 лет назад
Родитель
Сommit
efd819a9c6
39 измененных файлов с 788 добавлено и 466 удалено
  1. 46 2
      classes/swupdate-common.bbclass
  2. 1 1
      classes/swupdate-enc.bbclass
  3. 71 26
      classes/swupdate.bbclass
  4. 1 1
      conf/layer.conf
  5. 0 24
      recipes-bsp/libubootenv/libubootenv_0.1.bb
  6. 30 0
      recipes-bsp/libubootenv/libubootenv_0.3.1.bb
  7. 0 4
      recipes-bsp/u-boot/u-boot-fw-utils%.bbappend
  8. 7 2
      recipes-core/initscripts-swupdate/initscripts-swupdate-usb.bb
  9. 10 5
      recipes-devtools/mtd/mtd-utils_%.bbappend
  10. 0 0
      recipes-extended/cpio/cpio_%.bbappend
  11. 3 9
      recipes-lua/luafilesystem/files/0001-Fix-for-OE.patch
  12. 1 1
      recipes-lua/luafilesystem/luafilesystem_git.bb
  13. 12 6
      recipes-lua/luasocket/files/0001-fix-for-OE.patch
  14. 1 1
      recipes-lua/luasocket/luasocket_git.bb
  15. 29 0
      recipes-lua/swupdate-lualoader/swupdate-lualoader/swupdate_handlers.lua
  16. 20 0
      recipes-lua/swupdate-lualoader/swupdate-lualoader_1.0.bb
  17. 61 37
      recipes-lua/tekui/files/0001-Fix-config-for-OE.patch
  18. 8 10
      recipes-lua/tekui/tekui_1.12.bb
  19. 0 22
      recipes-support/librsync/librsync_2.0.2.bb
  20. 51 0
      recipes-support/swupdate/swupdate-2020.04/0001-Shellscript-stops-before-completing.patch
  21. 107 0
      recipes-support/swupdate/swupdate-2020.04/0001-diskpart-fix-adding-more-as-4-partitions.patch
  22. 31 0
      recipes-support/swupdate/swupdate-2020.04/0001-diskpart-force-kernel-to-reread-partition-table.patch
  23. 0 155
      recipes-support/swupdate/swupdate-legacy.inc
  24. 207 96
      recipes-support/swupdate/swupdate.inc
  25. 1 0
      recipes-support/swupdate/swupdate/10-mongoose-args
  26. 1 0
      recipes-support/swupdate/swupdate/90-start-progress
  27. 22 26
      recipes-support/swupdate/swupdate/defconfig
  28. 2 2
      recipes-support/swupdate/swupdate/swupdate
  29. 4 1
      recipes-support/swupdate/swupdate/swupdate-progress.service
  30. 1 1
      recipes-support/swupdate/swupdate/swupdate-usb.rules
  31. 2 3
      recipes-support/swupdate/swupdate/swupdate.service
  32. 28 0
      recipes-support/swupdate/swupdate/swupdate.sh
  33. 11 0
      recipes-support/swupdate/swupdate/swupdate.socket.tmpl
  34. 0 1
      recipes-support/swupdate/swupdate/tmpfiles-swupdate.conf
  35. 0 4
      recipes-support/swupdate/swupdate_2018.11.bb
  36. 6 0
      recipes-support/swupdate/swupdate_2019.11.bb
  37. 11 0
      recipes-support/swupdate/swupdate_2020.04.bb
  38. 2 2
      recipes-support/swupdate/swupdate_git.bb
  39. 0 24
      recipes-support/swupdate/swupdate_tools.inc

+ 46 - 2
classes/swupdate-common.bbclass

@@ -18,6 +18,36 @@ def swupdate_get_sha256(s, filename):
             m.update(data)
     return m.hexdigest()
 
+def swupdate_extract_keys(keyfile):
+    try:
+        keys = open(keyfile)
+    except IOError:
+        bb.fatal("Failed to open file with keys %s" % (keyfile))
+    lines = keys.read()
+    keys.close()
+    lines = lines.splitlines(True)
+    for line in lines:
+        line = line.replace('\n', '')
+        kv = line.split('=')
+        if kv[0] == 'salt':
+            salt = kv[1]
+        if kv[0] == 'key':
+            key = kv[1]
+        if kv[0] == 'iv' or kv[0] == 'iv ':
+            iv = kv[1]
+    return key,iv,salt
+
+def swupdate_encrypt_file(f, out, key, ivt, salt):
+    cmd = "openssl enc -aes-256-cbc -in '%s' -out '%s' -K '%s' -iv '%s' -S '%s'" % (
+                f,
+                out,
+                key,
+                ivt,
+                salt)
+    if os.system(cmd) != 0:
+        bb.fatal("Failed to encrypt %s" % (f))
+
+
 def swupdate_write_sha256(s, filename, hash):
     write_lines = []
 
@@ -66,6 +96,7 @@ def swupdate_expand_bitbake_variables(d, s):
             f.write(line)
 
 def prepare_sw_description(d, s, list_for_cpio):
+    import shutil
 
     swupdate_expand_bitbake_variables(d, s)
 
@@ -74,6 +105,13 @@ def prepare_sw_description(d, s, list_for_cpio):
             hash = swupdate_get_sha256(s, file)
             swupdate_write_sha256(s, file, hash)
 
+    encrypt = d.getVar('SWUPDATE_ENCRYPT_SWDESC', True)
+    if encrypt:
+        bb.note("Encryption of sw-description")
+        shutil.copyfile(os.path.join(s, 'sw-description'), os.path.join(s, 'sw-description.plain'))
+        key,iv,salt = swupdate_extract_keys(d.getVar('SWUPDATE_AES_FILE', True))
+        swupdate_encrypt_file(os.path.join(s, 'sw-description.plain'), os.path.join(s, 'sw-description'), key, iv, salt)
+
     signing = d.getVar('SWUPDATE_SIGNING', True)
     if signing == "1":
         bb.warn('SWUPDATE_SIGNING = "1" is deprecated, falling back to "RSA". It is advised to set it to "RSA" if using RSA signing.')
@@ -116,11 +154,17 @@ def prepare_sw_description(d, s, list_for_cpio):
                 bb.fatal("SWUPDATE_CMS_KEY isn't set")
             if not os.path.exists(cms_key):
                 bb.fatal("SWUPDATE_CMS_KEY %s doesn't exist" % (cms_key))
-            signcmd = "openssl cms -sign -in '%s' -out '%s' -signer '%s' -inkey '%s' -outform DER -nosmimecap -binary" % (
+            passout = d.getVar('SWUPDATE_PASSWORD_FILE', True)
+            if passout:
+                passout = "-passin file:'%s' " % (passout)
+            else:
+                passout = ""
+            signcmd = "openssl cms -sign -in '%s' -out '%s' -signer '%s' -inkey '%s' %s -outform DER -nosmimecap -binary" % (
                 os.path.join(s, 'sw-description'),
                 os.path.join(s, 'sw-description.sig'),
                 cms_cert,
-                cms_key)
+                cms_key,
+                passout)
             if os.system(signcmd) != 0:
                 bb.fatal("Failed to sign sw-description with %s" % (privkey))
         else:

+ 1 - 1
classes/swupdate-enc.bbclass

@@ -13,7 +13,7 @@ swu_encrypt_file() {
 	key=`cat ${SWUPDATE_AES_FILE} | grep ^key | cut -d '=' -f 2`
 	iv=`cat ${SWUPDATE_AES_FILE} | grep ^iv | cut -d '=' -f 2`
 	salt=`cat ${SWUPDATE_AES_FILE} | grep ^salt | cut -d '=' -f 2`
-	if [ -z ${salt} ] || [ -z ${key} ] || [ -z {iv} ];then
+	if [ -z ${salt} ] || [ -z ${key} ] || [ -z ${iv} ];then
 		bbfatal "SWUPDATE_AES_FILE=$SWUPDATE_AES_FILE does not contain valid keys"
 	fi
 	openssl enc -aes-256-cbc -in ${input} -out ${output} -K ${key} -iv ${iv} -S ${salt}

+ 71 - 26
classes/swupdate.bbclass

@@ -7,11 +7,32 @@
 # in field.
 # See also http://sbabic.github.io/swupdate/
 #
+# To use this class, add swupdate to the inherit clause of the update image bb file.
+# The generated output file is an swu archive ready to be uploaded to a device running
+# 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.
+# Files listed in the SRC_URI variable are added the the swu archive.
+#
+# For each entry in the SWUPDATE_IMAGES variable an image file is searched for in the
+# ${DEPLOY_DIR_IMAGE} folder and added to the swu archive. Different types of entries
+# are supported:
+# * image name(s) and fstype(s):
+#   Example:
+#     SWUPDATE_IMAGES = "core-image-full-cmdline"
+#     SWUPDATE_IMAGES_FSTYPES[core-image-full-cmdline] = ".ext4.gz"
+#   For this example either a file core-image-full-cmdline-${MACHINE}.ext4.gz or a file
+#   core-image-full-cmdline.ext4.gz gets added the swu archive. Optionally the variable
+#   SWUPDATE_IMAGES_NOAPPEND_MACHINE allows to explicitley define if the MACHINE name
+#   must be part of the image file name or not.
+# * image file name(s)
+#   Example:
+#     SWUPDATE_IMAGES = "core-image-full-cmdline.ext4.gz"
+#   If SWUPDATE_IMAGES_FSTYPES is not defined for an entry in SWUPDATE_IMAGES or the
+#   corresponding image files cannot be found in the ${DEPLOY_DIR_IMAGE} folder, an
+#   image file with exactly the name as specified in SWUPDATE_IMAGES is searched for.
+
 inherit swupdate-common.bbclass
+inherit image-artifact-names
 
 S = "${WORKDIR}/${PN}"
 
@@ -74,37 +95,61 @@ python do_swuimage () {
     if d.getVar('SWUPDATE_SIGNING', True):
         list_for_cpio.append('sw-description.sig')
 
+    # Add files listed in SRC_URI to the swu file
     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 ))
+        if (filename != 'sw-description') and (os.path.isfile(local)):
+            encrypted = (d.getVarFlag("SWUPDATE_IMAGES_ENCRYPTED", filename, True) or "")
+            key,iv,salt = swupdate_extract_keys(d.getVar('SWUPDATE_AES_FILE', True))
+            dst = os.path.join(s, "%s" % filename )
+            if encrypted == '1':
+                bb.note("Encryption requested for %s" %(filename))
+                swupdate_encrypt_file(local, dst, key, iv, salt)
+            else:
+                shutil.copyfile(local, dst)
             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
+    def add_image_to_swu(deploydir, imagename, s, encrypt):
+        src = os.path.join(deploydir, imagename)
+        if not os.path.isfile(src):
+            return False
+        target_imagename = os.path.basename(imagename)  # allow images in subfolders of DEPLOY_DIR_IMAGE
+        dst = os.path.join(s, target_imagename)
+        if encrypt == '1':
+            key,iv,salt = swupdate_extract_keys(d.getVar('SWUPDATE_AES_FILE', True))
+            bb.note("Encryption requested for %s" %(imagename))
+            swupdate_encrypt_file(src, dst, key, iv, salt)
+        else:
+            shutil.copyfile(src, dst)
+        list_for_cpio.append(target_imagename)
+        return True
+
+    # Search for images listed in SWUPDATE_IMAGES in the DEPLOY directory.
     deploydir = d.getVar('DEPLOY_DIR_IMAGE', True)
     imgdeploydir = d.getVar('IMGDEPLOYDIR', 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)
+        encrypted = (d.getVarFlag("SWUPDATE_IMAGES_ENCRYPTED", image, True) or "")
+        if fstypes:
+            noappend_machine = d.getVarFlag("SWUPDATE_IMAGES_NOAPPEND_MACHINE", image, True)
+            if noappend_machine == False:  # Search for a file explicitely with MACHINE
+                imagebases = [ image + '-' + d.getVar('MACHINE', True) ]
+            elif noappend_machine == True:  # Search for a file explicitely without MACHINE
+                imagebases = [ image ]
+            else:  # None, means auto mode. Just try to find an image file with MACHINE or without MACHINE
+                imagebases = [ image + '-' + d.getVar('MACHINE', True), image ]
+            for fstype in fstypes:
+                image_found = False
+                for imagebase in imagebases:
+                    image_found = add_image_to_swu(deploydir, imagebase + fstype, s, encrypted)
+                    if image_found:
+                        break
+                if not image_found:
+                    bb.fatal("swupdate cannot find image file: %s" % os.path.join(deploydir, imagebase + fstype))
+        else:  # Allow also complete entries like "image.ext4.gz" in SWUPDATE_IMAGES
+            if not add_image_to_swu(deploydir, image, s):
+                bb.fatal("swupdate cannot find %s image file" % image)
 
     prepare_sw_description(d, s, list_for_cpio)
 
@@ -121,4 +166,4 @@ PACKAGE_ARCH = "${MACHINE_ARCH}"
 INHIBIT_DEFAULT_DEPS = "1"
 EXCLUDE_FROM_WORLD = "1"
 
-addtask do_swuimage after do_unpack after do_prepare_recipe_sysroot before do_build
+addtask do_swuimage after do_unpack do_prepare_recipe_sysroot before do_build

+ 1 - 1
conf/layer.conf

@@ -9,6 +9,6 @@ BBFILE_COLLECTIONS += "swupdate"
 BBFILE_PATTERN_swupdate := "^${LAYERDIR}/"
 BBFILE_PRIORITY_swupdate = "6"
 
-LAYERSERIES_COMPAT_swupdate = "rocko sumo thud"
+LAYERSERIES_COMPAT_swupdate = "thud dunfell gatesgarth hardknott"
 
 LAYERDEPENDS_swupdate = "openembedded-layer"

+ 0 - 24
recipes-bsp/libubootenv/libubootenv_0.1.bb

@@ -1,24 +0,0 @@
-SUMMARY = "U-Boot libraries and tools to acces environment"
-DEPENDS += "mtd-utils"
-
-DESCRIPTION = "This package contains tools and libraries to read \
-and modify U-Boot environment"
-
-HOMEPAGE = "https://github.com/sbabic/libubootenv"
-LICENSE = "LGPL-2.1"
-LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/LGPL-2.1;md5=1a6d268fd218675ffea8be556788b780"
-SECTION = "libs"
-
-SRC_URI = "git://github.com/sbabic/libubootenv;protocol=https"
-SRCREV = "c1d89d574d830e1a366d6db0898c5cd2c47eb3d3"
-
-S = "${WORKDIR}/git"
-
-inherit cmake
-
-PACKAGE_ARCH = "${MACHINE_ARCH}"
-
-PROVIDES += "u-boot-fw-utils"
-RPROVIDES_${PN} += "u-boot-fw-utils"
-
-BBCLASSEXTEND = "cross"

+ 30 - 0
recipes-bsp/libubootenv/libubootenv_0.3.1.bb

@@ -0,0 +1,30 @@
+SUMMARY = "U-Boot libraries and tools to access environment"
+
+DESCRIPTION = "This package contains tools and libraries to read \
+and modify U-Boot environment. \
+It provides a hardware-independent replacement for fw_printenv/setenv utilities \
+provided by U-Boot"
+
+HOMEPAGE = "https://github.com/sbabic/libubootenv"
+LICENSE = "LGPL-2.1"
+LIC_FILES_CHKSUM = "file://Licenses/lgpl-2.1.txt;md5=4fbd65380cdd255951079008b364516c"
+SECTION = "libs"
+
+SRC_URI = "git://github.com/sbabic/libubootenv;protocol=https"
+SRCREV = "824551ac77bab1d0f7ae34d7a7c77b155240e754"
+
+S = "${WORKDIR}/git"
+
+inherit uboot-config cmake lib_package
+
+EXTRA_OECMAKE = "-DCMAKE_BUILD_TYPE=Release"
+
+DEPENDS = "zlib"
+PROVIDES += "u-boot-fw-utils"
+RPROVIDES_${PN}-bin += "u-boot-fw-utils"
+
+PACKAGE_ARCH = "${MACHINE_ARCH}"
+
+RRECOMMENDS_${PN}-bin_append_class-target = " u-boot-default-env"
+
+BBCLASSEXTEND = "native"

+ 0 - 4
recipes-bsp/u-boot/u-boot-fw-utils%.bbappend

@@ -1,4 +0,0 @@
-do_install_append() {
-    install -d ${D}${libdir}
-    install -m 644  ${S}/tools/env/lib.a ${D}${libdir}/libubootenv.a
-}

+ 7 - 2
recipes-core/initscripts-swupdate/initscripts-swupdate-usb.bb

@@ -11,15 +11,20 @@ RPROVIDES_${PN} += "virtual/initscripts-swupdate"
 
 S = "${WORKDIR}"
 
+inherit allarch update-alternatives
+
 do_install () {
 	install -d ${D}/${sysconfdir}/init.d
 	install -d ${D}${base_sbindir}
 	install -m 755 ${S}/rcS.swupdate ${D}${base_sbindir}/init
 }
 
+ALTERNATIVE_PRIORITY = "300"
+ALTERNATIVE_${PN} = "init"
+ALTERNATIVE_LINK_NAME[init] = "${base_sbindir}/init"
+ALTERNATIVE_PRIORITY[init] = "60"
+
 PACKAGES = "${PN}"
 FILES_${PN} = "/"
 
-inherit allarch
-
 CONFFILES_${PN} = ""

+ 10 - 5
recipes-devtools/mtd/mtd-utils_%.bbappend

@@ -1,13 +1,18 @@
+FILESEXTRAPATHS_prepend := "${THISDIR}/files:"
+
 FILES_${PN}-staticdev += "ubi-utils/libubi.a ${libdir}/*.a"
 
 do_install_append () {
 	install -d ${D}${includedir}/mtd/
 	install -d ${D}${libdir}/
-	install -m 0644 ${S}/include/libubi.h ${D}${includedir}/mtd/
-	install -m 0644 ${S}/include/libmtd.h ${D}${includedir}/mtd/
-	install -m 0644 ${S}/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}/
+	install -m 0644 ${S}/include/libubi.h ${D}${includedir}
+	install -m 0644 ${S}/include/libmtd.h ${D}${includedir}
+	install -m 0644 ${S}/include/libscan.h ${D}${includedir}
+	install -m 0644 ${S}/include/libubigen.h ${D}${includedir}
+	ln -s ../libubi.h ${D}${includedir}/mtd/libubi.h
+	ln -s ../libmtd.h ${D}${includedir}/mtd/libmtd.h
+	ln -s ../libscan.h ${D}${includedir}/mtd/libscan.h
+	ln -s ../libubigen.h ${D}${includedir}/mtd/libubigen.h
 	oe_libinstall -a libubi ${D}${libdir}/
 	oe_libinstall -a libmtd ${D}${libdir}/
 }

+ 0 - 0
recipes-extended/cpio/cpio_2.12.bbappend → recipes-extended/cpio/cpio_%.bbappend


+ 3 - 9
recipes-lua/luafilesystem/files/0001-Fix-for-OE.patch

@@ -9,8 +9,6 @@ Signed-off-by: Kas User <kas@example.com>
  config   | 14 +++++++-------
  2 files changed, 8 insertions(+), 8 deletions(-)
 
-diff --git a/Makefile b/Makefile
-index dfc1a8a..a521db7 100644
 --- a/Makefile
 +++ b/Makefile
 @@ -12,7 +12,7 @@ OBJS= src/$T.o
@@ -22,8 +20,6 @@ index dfc1a8a..a521db7 100644
  
  test: lib
  	LUA_CPATH=./src/?.so lua tests/test.lua
-diff --git a/config b/config
-index 2fc9a78..fd73f4a 100644
 --- a/config
 +++ b/config
 @@ -1,25 +1,25 @@
@@ -31,12 +27,13 @@ index 2fc9a78..fd73f4a 100644
  
  # Default installation prefix
 -PREFIX=/usr/local
+-
 +PREFIX ?= /usr/local
- 
++BASELIB ?= /lib
  # System's libraries directory (where binary libraries are installed)
 -LUA_LIBDIR= $(PREFIX)/lib/lua/5.1
 +LUAVER ?= `pkg-config --modversion lua | cut -d'.' -f1,2`
-+LUA_LIBDIR = $(PREFIX)/lib/lua/$(LUAVER)
++LUA_LIBDIR = $(PREFIX)$(BASELIB)/lua/$(LUAVER)
  
  # Lua includes directory
  LUA_INC += -I$(PREFIX)/include
@@ -59,6 +56,3 @@ index 2fc9a78..fd73f4a 100644
 +CFLAGS += $(WARN) $(INCS) ${LUA_INC}
  
  # $Id: config,v 1.21 2007/10/27 22:42:32 carregal Exp $
--- 
-2.7.4
-

+ 1 - 1
recipes-lua/luafilesystem/luafilesystem_git.bb

@@ -15,7 +15,7 @@ inherit pkgconfig
 
 S = "${WORKDIR}/git"
 
-EXTRA_OEMAKE = 'PREFIX=${D}/usr CROSS_COMPILE=${TARGET_PREFIX} CC="${CC} -fpic" LDFLAGS="${LDFLAGS}"'
+EXTRA_OEMAKE = 'PREFIX=${D}/usr BASELIB=${base_libdir} CROSS_COMPILE=${TARGET_PREFIX} CC="${CC} -fpic" LDFLAGS="${LDFLAGS}"'
 
 # NOTE: this is a Makefile-only piece of software, so we cannot generate much of the
 # recipe automatically - you will need to examine the Makefile yourself and ensure

+ 12 - 6
recipes-lua/luasocket/files/0001-fix-for-OE.patch

@@ -8,11 +8,9 @@ Signed-off-by: Kas User <kas@example.com>
  makefile | 4 +++-
  1 file changed, 3 insertions(+), 1 deletion(-)
 
-diff --git a/makefile b/makefile
-index cc15b4e..632fb73 100644
 --- a/makefile
 +++ b/makefile
-@@ -14,8 +14,10 @@ PLATS= macosx linux win32 mingw freebsd solaris
+@@ -14,8 +14,10 @@ PLATS= macosx linux win32 mingw freebsd
  
  all: $(PLAT)
  
@@ -24,6 +22,14 @@ index cc15b4e..632fb73 100644
  
  print:
  	$(MAKE) -C src $@
--- 
-2.7.4
-
+--- a/src/makefile
++++ b/src/makefile
+@@ -50,7 +50,7 @@ LDIR_macosx?=share/lua/$(LUAV)
+ LUAINC_linux_base?=/usr/include
+ LUAINC_linux?=$(LUAINC_linux_base)/lua/$(LUAV)
+ LUAPREFIX_linux?=/usr/local
+-CDIR_linux?=lib/lua/$(LUAV)
++CDIR_linux?=$(BASELIB)/lua/$(LUAV)
+ LDIR_linux?=share/lua/$(LUAV)
+ 
+ # LUAINC_freebsd:

+ 1 - 1
recipes-lua/luasocket/luasocket_git.bb

@@ -17,7 +17,7 @@ S = "${WORKDIR}/git"
 
 FILES_${PN} = "${libdir} ${datadir}/lua" 
 
-EXTRA_OEMAKE = 'DESTDIR=${D} PREFIX=/usr CC="${CC}" LD="${CC}" MYLDFLAGS="${LDFLAGS}"'
+EXTRA_OEMAKE = 'DESTDIR=${D} BASELIB=${base_libdir} PREFIX=/usr CC="${CC}" LD="${CC}" MYLDFLAGS="${LDFLAGS}"'
 
 inherit pkgconfig
 

+ 29 - 0
recipes-lua/swupdate-lualoader/swupdate-lualoader/swupdate_handlers.lua

@@ -0,0 +1,29 @@
+-- Copyright 2020 Joshua Watt <JPEWhacker@gmail.com>
+--
+-- 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.
+
+local lfs = require("lfs")
+
+local path = "@libdir@/swupdate/lua-handlers"
+for file in lfs.dir(path) do
+    if file:match("^.*%.lua") then
+        dofile(path .. "/" .. file)
+    end
+end
+

+ 20 - 0
recipes-lua/swupdate-lualoader/swupdate-lualoader_1.0.bb

@@ -0,0 +1,20 @@
+SUMMARY = "Loader for swupdate"
+LICENSE = "MIT"
+SECTION = ""
+DEPENDS = "lua"
+LIC_FILES_CHKSUM = "file://${WORKDIR}/swupdate_handlers.lua;md5=354cf4af377edd962d2e8d78085d3ed7;beginline=1;endline=19"
+
+SRC_URI = "file://swupdate_handlers.lua"
+
+inherit pkgconfig
+
+do_install() {
+    LUAVER=$(pkg-config --modversion lua | grep -o '^[0-9]\+\.[0-9]\+')
+    install -D -m 0644 ${WORKDIR}/swupdate_handlers.lua ${D}${libdir}/lua/$LUAVER/swupdate_handlers.lua
+    sed -e 's,@libdir@,${libdir},g' \
+        -i ${D}${libdir}/lua/$LUAVER/swupdate_handlers.lua
+
+}
+
+RDEPENDS_${PN} = "luafilesystem"
+FILES_${PN} = "${libdir}/lua"

+ 61 - 37
recipes-lua/tekui/files/0001-Fix-config-for-OE.patch

@@ -1,15 +1,15 @@
-From 54b0fc6c15cd4b9dcc9a5a9a39e6be2398128eb8 Mon Sep 17 00:00:00 2001
-From: Kas User <kas@example.com>
-Date: Mon, 7 May 2018 10:51:03 +0200
+From fdb15577a039f059871af318361c5d53de0e22e9 Mon Sep 17 00:00:00 2001
+From: Stefano Babic <sbabic@denx.de>
+Date: Fri, 12 Oct 2018 12:00:50 +0200
 Subject: [PATCH] Fix config for OE
 
-Signed-off-by: Kas User <kas@example.com>
+Signed-off-by: Stefano Babic <sbabic@denx.de>
 ---
- config | 31 +++++++++++++++++--------------
- 1 file changed, 17 insertions(+), 14 deletions(-)
+ config | 54 +++++++++++++++++++++---------------------------------
+ 1 file changed, 21 insertions(+), 33 deletions(-)
 
 diff --git a/config b/config
-index 8664568..31e65a2 100644
+index 63c980a..b7e0b8f 100644
 --- a/config
 +++ b/config
 @@ -27,7 +27,7 @@ DISPLAY_DRIVER ?= x11
@@ -21,18 +21,7 @@ index 8664568..31e65a2 100644
  
  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  # For Windows using MinGW:
-@@ -117,8 +117,8 @@ TEKUI_LIBS =
- PNG_DIR = $(PREFIX)
- PNG_INCDIR = $(PNG_DIR)/include
- PNG_LIBDIR = $(PNG_DIR)/lib
--# TEKUI_DEFS += -DENABLE_PNG -I$(PNG_INCDIR)
--# TEKUI_LIBS += -L$(PNG_LIBDIR) -lpng # $(CC_LD_RT)$(PNG_LIBDIR)
-+TEKUI_DEFS += -DENABLE_PNG -I$(PNG_INCDIR)
-+TEKUI_LIBS += -L$(PNG_LIBDIR) -lpng # $(CC_LD_RT)$(PNG_LIBDIR)
- 
- TEKLIB_DEFS = -DENABLE_LAZY_SINGLETON
- 
-@@ -129,13 +129,14 @@ TEKLIB_DEFS = -DENABLE_LAZY_SINGLETON
+@@ -127,14 +127,15 @@ TEKLIB_DEFS = -DENABLE_LAZY_SINGLETON
  #------------------------------------------------------------------------------
  
  PREFIX ?= /usr/local
@@ -41,16 +30,18 @@ index 8664568..31e65a2 100644
  
  LUA_DIR = $(PREFIX)
  LUA_INCDIR = $(LUA_DIR)/include
--LUA_DEFS = -I$(LUA_INCDIR) -I/usr/include/lua$(LUAVER)
-+#LUA_DEFS = -I$(LUA_INCDIR) -I/usr/include/lua$(LUAVER)
+-LUA_DEFS = -I$(LUA_INCDIR)
++#LUA_DEFS = -I$(LUA_INCDIR)
+ # other known paths - better comment out what is inappropriate:
+-LUA_DEFS += -I/usr/include/lua$(LUAVER)
+-LUA_DEFS += -I/usr/local/include/lua51
++#LUA_DEFS += -I/usr/include/lua$(LUAVER)
++#LUA_DEFS += -I/usr/local/include/lua51
 +LUA_DEFS = `pkg-config --cflags lua` #$(LUA_DIR)/include
- # some known paths in distributions and toolchains:
--LUA_DEFS += -I/usr/local/include/lua51 -I/usr/include/lua5.1
-+#LUA_DEFS += -I/usr/local/include/lua51 -I/usr/include/lua5.1
  
  LUA_LIB = $(PREFIX)/lib/lua/$(LUAVER)
  LUA_SHARE = $(PREFIX)/share/lua/$(LUAVER)
-@@ -146,11 +147,13 @@ SYS_LUA_SHARE = $(PREFIX)/share/lua/$(LUAVER)
+@@ -145,11 +146,15 @@ SYS_LUA_SHARE = $(PREFIX)/share/lua/$(LUAVER)
  # Libraries:
  #------------------------------------------------------------------------------
  
@@ -62,40 +53,73 @@ index 8664568..31e65a2 100644
 +#FREETYPE_DIR = $(PREFIX)
 +#FREETYPE_INCDIR = $(FREETYPE_DIR)/include
 +#FREETYPE_LIBDIR = $(FREETYPE_DIR)/lib
-+FREETYPE_INCDIR = `pkg-config --cflags freetype2`
 +#FREETYPE_LIBS = -L$(FREETYPE_LIBDIR) -lfreetype # $(CC_LD_RT)$(FREETYPE_LIBDIR)
++#FREETYPE_DEFS = -I$(FREETYPE_INCDIR)/freetype2 `freetype-config --cflags`
++
++FREETYPE_INCDIR = `pkg-config --cflags freetype2`
 +FREETYPE_LIBS = `pkg-config --libs freetype2`
 +FREETYPE_DEFS = $(FREETYPE_INCDIR)
  
  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  # X11 defines and libraries:
-@@ -170,7 +173,7 @@ XFT_DIR = $(X11_DIR)
- XFT_INCDIR = $(XFT_DIR)/include
- XFT_LIBDIR = $(XFT_DIR)/lib
- XFT_LIBS = -L$(XFT_LIBDIR) -lXft # $(CC_LD_RT)$(XFT_LIBDIR)
--XFT_DEFS = -I$(XFT_INCDIR) -DENABLE_XFT
-+XFT_DEFS = -I$(XFT_INCDIR) # -DENABLE_XFT
- 
+@@ -174,7 +179,8 @@ XFT_DEFS = -I$(XFT_INCDIR) -DENABLE_XFT
  FONTCONFIG_DIR = $(PREFIX)
  FONTCONFIG_INCDIR = $(FONTCONFIG_DIR)/include
-@@ -254,7 +257,7 @@ LUAARCH = -m64 # -m32 for 32bit, -m64 for 64bit architecture
+ FONTCONFIG_LIBDIR = $(FONTCONFIG_DIR)/lib
+-FONTCONFIG_LIBS = -L$(FONTCONFIG_LIBDIR) -lfontconfig # $(CC_LD_RT)$(FONTCONFIG_LIBDIR)
++#FONTCONFIG_LIBS = -L$(FONTCONFIG_LIBDIR) -lfontconfig # $(CC_LD_RT)$(FONTCONFIG_LIBDIR)
++FONTCONFIG_LIBS = -L$(FONTCONFIG_LIBDIR) # -lfontconfig $(CC_LD_RT)$(FONTCONFIG_LIBDIR)
+ FONTCONFIG_DEFS = -I$(FONTCONFIG_INCDIR)
+ 
+ # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+@@ -237,7 +243,7 @@ MODDIR = $(BINDIR)/mod
+ #------------------------------------------------------------------------------
+ 
+ DEBUG = -DTDEBUG=5 -g # TDEBUG: the lower, the more verbose. 5 = WARN
+-WARN = -Wall -Wextra -Wno-unused-parameter -Wno-unused-function -Wno-long-long -Wno-unused-value
++WARN = -Wall -Wextra -Wno-unused-parameter -Wno-unused-function -Wno-long-long # -Wno-unused-value
+ OPT = -O2 -fno-strict-aliasing
+ INCL = -I. -Iinclude -I$(INCDIR)
+ LIBCFLAGS = $(DEBUG) $(WARN) $(OPT) $(INCL) $(EXTRADEFS) $(CPPFLAGS) $(CFLAGS)
+@@ -250,7 +256,8 @@ BINCFLAGS = $(DEBUG) $(WARN) $(OPT) $(INCL) $(EXTRADEFS) $(LDFLAGS)
  # Build tools:
  #------------------------------------------------------------------------------
  
 -AR = $(CROSS_COMPILE)ar rcu
++#AR = $(CROSS_COMPILE)ar rcu
 +AR = ar rcu
  RM = rm -f
  RMDIR = rm -rf
  MKDIR = mkdir -p
-@@ -262,7 +265,7 @@ ECHO = echo
+@@ -258,27 +265,8 @@ ECHO = echo
  INSTALL_B = install
  INSTALL_F = install
  INSTALL_D = install -d
 -INSTALL_S = install -s
-+INSTALL_S = install 
+-STRIP = $(CROSS_COMPILE)strip
++INSTALL_S = install
+ 
+-#------------------------------------------------------------------------------
+-# Lua/tekUI standalone executable: not needed by default, only for 'make tools'
+-#------------------------------------------------------------------------------
+-
+-# Lua distribution path:
+-LUADISTDIR = $(BASEDIR)/../lua-5.1.5
+-# Linux:
+-LUAEXE_DEFS = $(X11_DEFS) $(TEKUI_DEFS) -DLUA_USE_LINUX
+-LUAEXE_LIBS = $(X11_LIBS) -lreadline -lm -ldl -pthread
+-# Mac OS X:
+-# LUAEXE_DEFS = $(X11_DEFS) $(TEKUI_DEFS) -DLUA_USE_MACOSX
+-# LUAEXE_LIBS = $(X11_LIBS) -lreadline
+-# Windows:
+-# LUAEXE_DEFS = $(TEKUI_DEFS)
+-# LUAEXE_LIBS = $(WIN_LIBS)
+-# FreeBSD:
+-# LUAEXE_DEFS = $(X11_DEFS) $(TEKUI_DEFS) -DLUA_USE_LINUX
+-# LUAEXE_LIBS = -Wl,-E $(X11_LIBS) -lreadline -lm -pthread
  
  #------------------------------------------------------------------------------
  # Predefined targets:
 -- 
-2.7.4
+2.17.1
 

+ 8 - 10
recipes-lua/tekui/tekui_1.12.bb

@@ -12,20 +12,18 @@
 #   doc/copyright.html
 #   src/display_rawfb/vnc/COPYING
 LICENSE = "MIT"
-LIC_FILES_CHKSUM = "file://COPYRIGHT;md5=f8640872a50cd4ee663b8fb2f603b854 \
-                    file://tek/ui/font/COPYRIGHT.TXT;md5=27d7484b1e18d0ee4ce538644a3f04be \
-                    file://doc/copyright.html;md5=e0ef847c1e1b62ee80317a79b7cd99de \
-                    file://src/display_rawfb/vnc/COPYING;md5=361b6b837cad26c6900a926b62aada5f"
+LIC_FILES_CHKSUM = "file://COPYRIGHT;md5=a12f233f3497ee1f8a18dddfde5a7fc3"
 
-SRC_URI = "http://tekui.neoscientists.org/releases/tekui-1.12-r1.tgz \
-           file://0001-Fix-config-for-OE.patch \
+SRC_URI = " \
+	git://github.com/sbabic/tekUI.git;protocol=https;branch=tekui-devel \
+        file://0001-Fix-config-for-OE.patch \
 	"
-SRC_URI[md5sum] = "cf67e1aa5583ee22e5f63ad2b297e2c9"
-SRC_URI[sha256sum] = "d3130a9403e05b8322e47b5e8c0716f5ccf2956ecae6e1268b05085a774b0894"
+
+SRCREV = "b0a20f57e47548099e443d54fc6fb33666543b72"
 
 PR = "r1"
 
-S = "${WORKDIR}/${PN}-${PV}-${PR}"
+S = "${WORKDIR}/git"
 
 PACKAGES += "${PN}-examples"
 FILES_${PN} = "${libdir} ${datadir}/lua" 
@@ -39,7 +37,7 @@ DEPENDS = "libx11 readline lua freetype libpng fontconfig"
 DEPENDS = "lua freetype libpng fontconfig"
 RDEPENDS_${PN} += "lua"
 
-EXTRA_OEMAKE = 'PREFIX=${D}/usr DISPLAY_DRIVER=rawfb CROSS_COMPILE=${TARGET_PREFIX} CC="${CC} -fpic"'
+EXTRA_OEMAKE = 'PREFIX=${D}/usr BASELIB=${base_libdir} DISPLAY_DRIVER=rawfb CROSS_COMPILE=${TARGET_PREFIX} CC="${CC} -fpic"'
 
 do_compile () {
 	oe_runmake all

+ 0 - 22
recipes-support/librsync/librsync_2.0.2.bb

@@ -1,22 +0,0 @@
-SUMMARY = "librsync is a library for calculating and applying network deltas, \
-with an interface designed to ease integration into diverse network applications."
-HOMEPAGE = "http://librsync.sourceforge.net"
-
-SECTION = "libs"
-
-LICENSE = "LGPLv2.1"
-LIC_FILES_CHKSUM = "file://COPYING;md5=d8045f3b8f929c1cb29a1e3fd737b499 \
-                    file://debian/copyright;md5=365dc7c8a0d1b88cfc01021bcc5d2a30"
-
-SRC_URI = "git://github.com/librsync/librsync.git;protocol=https"
-
-PV = "2.0.2+git${SRCPV}"
-SRCREV = "dfba8988ef12d6a2f96dc16e608923a9a5d6371d"
-
-S = "${WORKDIR}/git"
-
-DEPENDS = "bzip2 zlib"
-inherit cmake
-
-# Specify any options you want to pass to cmake using EXTRA_OECMAKE:
-EXTRA_OECMAKE = ""

+ 51 - 0
recipes-support/swupdate/swupdate-2020.04/0001-Shellscript-stops-before-completing.patch

@@ -0,0 +1,51 @@
+From 1078af97a5ac5c3091c8e601b836cd69a7aab7fc Mon Sep 17 00:00:00 2001
+From: Stefano Babic <sbabic@denx.de>
+Date: Tue, 16 Jun 2020 10:29:55 +0200
+Subject: [PATCH] Shellscript stops before completing
+
+Commit 8fb94d7 reworks the way shell script are called, redirecting
+stdout and stderr to SWUpdate. A shell script runs then in a child
+process. Under some circumstances, SWUpdate closes the forked process
+before the child process completes.
+
+Be sure that the child process has terminated before to go on.
+
+Signed-off-by: Stefano Babic <sbabic@denx.de>
+Reported-by: Piotr Piwko <piotr.piwko@gmail.com>
+Tested-by: Piotr Piwko <piotr.piwko@gmail.com>
+---
+ core/pctl.c | 4 ++--
+ 1 file changed, 2 insertions(+), 2 deletions(-)
+
+diff --git a/core/pctl.c b/core/pctl.c
+index 8b1c667..01ad540 100644
+--- a/core/pctl.c
++++ b/core/pctl.c
+@@ -263,6 +263,7 @@ int run_system_cmd(const char *cmd)
+ 		}
+ 	} else {
+ 		int fds[2];
++		pid_t w;
+ 
+ 		close(stdoutpipe[PIPE_WRITE]);
+ 		close(stderrpipe[PIPE_WRITE]);
+@@ -276,7 +277,6 @@ int run_system_cmd(const char *cmd)
+ 		 * and from stderr (of the child process) as ERROR
+ 		 */
+ 		do {
+-			pid_t w;
+ 			int n1 = 0;
+ 			struct timeval tv;
+ 			fd_set readfds;
+@@ -373,7 +373,7 @@ int run_system_cmd(const char *cmd)
+ 					}
+ 				}
+ 			} while (ret > 0 && n1 > 0);
+-		} while (!WIFEXITED(wstatus));
++		} while (w != process_id);
+ 
+ 		close(stdoutpipe[PIPE_READ]);
+ 		close(stderrpipe[PIPE_READ]);
+-- 
+2.25.1
+

+ 107 - 0
recipes-support/swupdate/swupdate-2020.04/0001-diskpart-fix-adding-more-as-4-partitions.patch

@@ -0,0 +1,107 @@
+From 9b8b498550d4571233fbee6476521c98bc397485 Mon Sep 17 00:00:00 2001
+From: Stefano Babic <sbabic@denx.de>
+Date: Wed, 29 Jul 2020 12:57:59 +0200
+Subject: [PATCH] diskpart: fix adding more as 4 partitions
+
+Signed-off-by: Stefano Babic <sbabic@denx.de>
+---
+ handlers/diskpart_handler.c | 41 +++++++++++++++++++++++++++----------
+ 1 file changed, 30 insertions(+), 11 deletions(-)
+
+diff --git a/handlers/diskpart_handler.c b/handlers/diskpart_handler.c
+index 372412b..be570ca 100644
+--- a/handlers/diskpart_handler.c
++++ b/handlers/diskpart_handler.c
+@@ -21,6 +21,11 @@
+ 
+ void diskpart_handler(void);
+ 
++/*
++ * This is taken from libfdisk to declare if a field is not set
++ */
++#define LIBFDISK_INIT_UNDEF(_x)	((__typeof__(_x)) -1)
++
+ /**
+  * Keys for the properties field in sw-description
+  */
+@@ -71,16 +76,23 @@ static int diskpart_set_partition(struct fdisk_context *cxt,
+ 	unsigned long sector_size = fdisk_get_sector_size(cxt);
+ 	struct fdisk_label *lb;
+ 	struct fdisk_parttype *parttype = NULL;
+-	int ret;
++	int ret = 0;
+ 
+ 	lb = fdisk_get_label(cxt, NULL);
+ 
+ 	if (!sector_size)
+ 		sector_size = 1;
+-	ret = fdisk_partition_set_partno(pa, part->partno) ||
+-	      fdisk_partition_set_size(pa, part->size / sector_size) ||
+-	      fdisk_partition_set_name(pa, part->name) ||
+-	      fdisk_partition_set_start(pa, part->start);
++	fdisk_partition_unset_partno(pa);
++	fdisk_partition_unset_size(pa);
++	fdisk_partition_unset_start(pa);
++	if (part->start != LIBFDISK_INIT_UNDEF(part->start))
++		ret = fdisk_partition_set_start(pa, part->start);
++	if (part->partno != LIBFDISK_INIT_UNDEF(part->partno))
++		ret |= fdisk_partition_set_partno(pa, part->partno);
++	if (strlen(part->name))
++	      ret |= fdisk_partition_set_name(pa, part->name);
++	if (part->size != LIBFDISK_INIT_UNDEF(part->size))
++	      ret |= fdisk_partition_set_size(pa, part->size / sector_size);
+ 
+ 	/*
+ 	 * GPT uses strings instead of hex code for partition type
+@@ -150,6 +162,10 @@ static int diskpart(struct img_type *img,
+ 		}
+ 		elem = LIST_FIRST(parts);
+ 
++		part->partno = LIBFDISK_INIT_UNDEF(part->partno);
++		part->start = LIBFDISK_INIT_UNDEF(part->start);
++		part->size = LIBFDISK_INIT_UNDEF(part->size);
++
+ 		part->partno = strtoul(entry->key  + strlen("partition-"), NULL, 10);
+ 		while (elem) {
+ 			char *equal = index(elem->value, '=');
+@@ -179,10 +195,10 @@ static int diskpart(struct img_type *img,
+ 		}
+ 
+ 		TRACE("partition-%zu:%s size %" PRIu64 " start %zu type %s",
+-			part->partno,
+-			part->name,
+-			part->size,
+-			part->start,
++			part->partno != LIBFDISK_INIT_UNDEF(part->partno) ? part->partno : 0,
++			strlen(part->name) ? part->name : "UNDEF NAME",
++			part->size != LIBFDISK_INIT_UNDEF(part->size) ? part->size : 0,
++			part->start!= LIBFDISK_INIT_UNDEF(part->start) ? part->start : 0,
+ 			part->type);
+ 
+ 		/*
+@@ -253,10 +269,12 @@ static int diskpart(struct img_type *img,
+ 			if (ret) {
+ 				WARN("I cannot set all partition's parameters");
+ 			}
+-			if (fdisk_add_partition(cxt, newpa, &partno) < 0) {
+-				ERROR("I cannot add partition %zu(%s)", part->partno, part->name);
++			if ((ret = fdisk_add_partition(cxt, newpa, &partno)) < 0) {
++				ERROR("I cannot add partition %zu(%s): %d", part->partno, part->name, ret);
+ 			}
+ 			fdisk_unref_partition(newpa);
++			if (ret < 0)
++				goto handler_exit;
+ 		} else {
+ 			ret = diskpart_set_partition(cxt, pa, part);
+ 			if (ret) {
+@@ -267,6 +285,7 @@ static int diskpart(struct img_type *img,
+ 			}
+ 			fdisk_unref_partition(pa);
+ 		}
++		fdisk_reset_partition(pa);
+ 		i++;
+ 	}
+ 
+-- 
+2.25.1
+

+ 31 - 0
recipes-support/swupdate/swupdate-2020.04/0001-diskpart-force-kernel-to-reread-partition-table.patch

@@ -0,0 +1,31 @@
+From e3a6b120ff88f6dc34570002de97754b607966ec Mon Sep 17 00:00:00 2001
+From: Stefano Babic <sbabic@denx.de>
+Date: Tue, 9 Jun 2020 13:58:06 +0000
+Subject: [PATCH] diskpart: force kernel to reread partition table
+
+After writing a partition table to disk, the kernel should be informed
+(like the partconf tool does), else it is not possible to install images
+in the new created partitions.
+
+Signed-off-by: Stefano Babic <sbabic@denx.de>
+---
+ handlers/diskpart_handler.c | 3 ++-
+ 1 file changed, 2 insertions(+), 1 deletion(-)
+
+diff --git a/handlers/diskpart_handler.c b/handlers/diskpart_handler.c
+index 16adc17..372412b 100644
+--- a/handlers/diskpart_handler.c
++++ b/handlers/diskpart_handler.c
+@@ -273,7 +273,8 @@ static int diskpart(struct img_type *img,
+ 	/*
+ 	 * Everything done, write into disk
+ 	 */
+-	ret = fdisk_write_disklabel(cxt);
++	ret = fdisk_write_disklabel(cxt) |
++		fdisk_reread_partition_table(cxt);
+ 
+ handler_exit:
+ 	if (fdisk_deassign_device(cxt, 0))
+-- 
+2.25.1
+

+ 0 - 155
recipes-support/swupdate/swupdate-legacy.inc

@@ -1,155 +0,0 @@
-SUMMARY="Image updater for Yocto projects"
-DESCRIPTION = "Application for automatic software update from USB Pen"
-SECTION="swupdate"
-DEPENDS = "libconfig"
-LICENSE = "GPLv2+"
-LIC_FILES_CHKSUM = "file://COPYING;md5=0636e73ff0215e8d672dc4c32c317bb3"
-
-inherit cml1 update-rc.d systemd pkgconfig
-
-SRC_URI = "git://github.com/sbabic/swupdate.git;protocol=https \
-     file://defconfig \
-     file://swupdate \
-     file://swupdate.service \
-     file://swupdate-usb.rules \
-     file://swupdate-usb@.service \
-     file://swupdate-progress.service \
-     "
-
-INSANE_SKIP_${PN} = "ldflags"
-PACKAGES =+ "${PN}-www"
-
-FILES_${PN}-www = "/www/*"
-
-S = "${WORKDIR}/git/"
-
-EXTRA_OEMAKE += " HOSTCC="${BUILD_CC}" HOSTCXX="${BUILD_CXX}" V=1 ARCH=${TARGET_ARCH} CROSS_COMPILE=${TARGET_PREFIX} SKIP_STRIP=y"
-
-DEPENDS += "kern-tools-native"
-
-# returns all the elements from the src uri that are .cfg files
-def find_cfgs(d):
-    return [s for s in src_patches(d, True) if s.endswith('.cfg')]
-
-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_ENCRYPTED_IMAGES=y\n' in features or 'CONFIG_MONGOOSESSL=y\n' in features or 'CONFIG_HASH_VERIFY=y\n' in features or 'CONFIG_SURICATTA_SSL=y\n' in features:
-        depends = d.getVar('DEPENDS', False)
-        d.setVar('DEPENDS', depends + ' openssl')
-
-    if 'CONFIG_JSON=y\n' in features:
-        depends = d.getVar('DEPENDS', False)
-        d.setVar('DEPENDS', depends + ' json-c')
-
-    if 'CONFIG_SYSTEMD=y\n' in features:
-        depends = d.getVar('DEPENDS', False)
-        d.setVar('DEPENDS', depends + ' systemd')
-
-    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')
-
-    if 'CONFIG_CFI=y\n' in features:
-        depends = d.getVar('DEPENDS', False)
-        d.setVar('DEPENDS', depends + ' mtd-utils')
-
-    if 'CONFIG_UBIVOL=y\n' in features:
-        depends = d.getVar('DEPENDS', False)
-        d.setVar('DEPENDS', depends + ' mtd-utils')
-
-    if 'CONFIG_UCFWHANDLER=y\n' in features:
-        depends = d.getVar('DEPENDS', False)
-        d.setVar('DEPENDS', depends + ' libgpiod')
-
-    if 'CONFIG_MONGOOSE_WEB_API_V2=y\n' in features:
-        d.setVar('SWUPDATE_WWW', 'webapp')
-
-    if 'CONFIG_BOOTLOADER_EBG=y\n' in features:
-        depends = d.getVar('DEPENDS', False)
-        d.setVar('DEPENDS', depends + ' efibootguard')
-}
-
-do_configure () {
-  cp ${WORKDIR}/defconfig ${S}/.config
-  merge_config.sh -m .config ${@" ".join(find_cfgs(d))}
-  cml1_do_configure
-}
-
-do_compile() {
-  unset LDFLAGS
-  oe_runmake swupdate_unstripped progress_unstripped
-  cp swupdate_unstripped swupdate
-  cp progress_unstripped progress
-
-}
-
-do_install () {
-  install -d ${D}${bindir}/
-  install -m 0755 swupdate ${D}${bindir}/
-
-  install -m 0755 -d ${D}/www
-  if [ -d ${S}/web-app ];then
-	cp -R --no-dereference --preserve=mode,links -v ${S}/examples/www/v2/* ${D}/www
-  else
-	install -m 0755 ${S}/www/* ${D}/www
-  fi
-
-  install -d ${D}${libdir}/
-  install -d ${D}${includedir}/
-  install -m 0644 ${S}/include/network_ipc.h ${D}${includedir}
-  install -m 0644 ${S}/include/swupdate_status.h ${D}${includedir}
-  install -m 0644 ${S}/include/progress_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
-  install -m 644 ${WORKDIR}/swupdate-usb@.service ${D}${systemd_unitdir}/system
-  install -m 644 ${WORKDIR}/swupdate-progress.service ${D}${systemd_unitdir}/system
-
-
-  if ${@bb.utils.contains('DISTRO_FEATURES','systemd','true','false',d)}; then
-    install -d ${D}${sysconfdir}/udev/rules.d
-    install -m 0644 ${WORKDIR}/swupdate-usb.rules ${D}${sysconfdir}/udev/rules.d/
-  fi
-}
-
-INITSCRIPT_NAME = "swupdate"
-INITSCRIPT_PARAMS = "defaults 70"
-
-SYSTEMD_SERVICE_${PN} = "swupdate.service"
-SYSTEMD_SERVICE_${PN} += "swupdate-usb@.service swupdate-progress.service"

+ 207 - 96
recipes-support/swupdate/swupdate.inc

@@ -1,40 +1,94 @@
 SUMMARY="Image updater for Yocto projects"
 DESCRIPTION = "Application for automatic software update from USB Pen"
 SECTION="swupdate"
-DEPENDS = "libconfig"
-LICENSE = "GPLv2+"
-LIC_FILES_CHKSUM = "file://COPYING;md5=0636e73ff0215e8d672dc4c32c317bb3"
+DEPENDS += "libconfig"
+
+# SWUpdate licensing is described in the following pages:
+# https://sbabic.github.io/swupdate/licensing.html
+# rst form: file://doc/source/licensing.rst
+LICENSE = "GPLv2+ & LGPLv2+ & MIT"
+LICENSE_${PN}-lua = "LGPLv2+"
+LICENSE_${PN}-www = "MIT"
+LIC_FILES_CHKSUM = "file://COPYING;md5=0636e73ff0215e8d672dc4c32c317bb3 \
+                    file://Licenses/lgpl-2.1.txt;md5=4fbd65380cdd255951079008b364516c \
+                    file://Licenses/mit.txt;md5=838c366f69b72c5df05c96dff79b35f2 \
+                    file://Licenses/Exceptions;md5=5f205fe7a7f2b056b4fa42603fe2d63a"
 
 inherit cml1 update-rc.d systemd pkgconfig
 
 SRC_URI = "git://github.com/sbabic/swupdate.git;protocol=https \
-     file://defconfig \
-     file://swupdate \
-     file://swupdate.service \
-     file://swupdate-usb.rules \
-     file://swupdate-usb@.service \
-     file://swupdate-progress.service \
-     file://systemd-tmpfiles-swupdate.conf \
-     "
-
-INSANE_SKIP_${PN} = "ldflags"
-PACKAGES =+ "${PN}-www ${PN}-lua"
-
+    file://defconfig \
+    file://swupdate \
+    file://swupdate.sh \
+    file://swupdate.service \
+    file://swupdate.socket.tmpl \
+    file://swupdate-usb.rules \
+    file://swupdate-usb@.service \
+    file://swupdate-progress.service \
+    file://tmpfiles-swupdate.conf \
+    file://10-mongoose-args \
+    file://90-start-progress \
+"
+
+LTOEXTRA += "-flto-partition=none"
+
+PACKAGES =+ " \
+    ${PN}-client \
+    ${PN}-lua \
+    ${PN}-progress \
+    ${PN}-tools \
+    ${PN}-tools-hawkbit \
+    ${PN}-usb \
+    ${PN}-www \
+"
+
+# tools is now an empty meta package for backward compatibility
+ALLOW_EMPTY_${PN}-tools = "1"
+
+FILES_${PN}-client = "${bindir}/swupdate-client"
 FILES_${PN}-lua += "${libdir}/lua/"
-FILES_${PN}-www = "/www/*"
-FILES_${PN} += "${libdir}/tmpfiles.d"
-
-S = "${WORKDIR}/git/"
-
-EXTRA_OEMAKE += " HOSTCC="${BUILD_CC}" HOSTCXX="${BUILD_CXX}" LD="${CC}" DESTDIR="${D}" V=1 ARCH=${TARGET_ARCH} CROSS_COMPILE=${TARGET_PREFIX} SKIP_STRIP=y"
+FILES_${PN}-progress = " \
+    ${bindir}/swupdate-progress \
+    ${systemd_system_unitdir}/swupdate-progress.service \
+    ${libdir}/swupdate/conf.d/90-start-progress \
+"
+FILES_${PN}-usb = " \
+    ${sysconfdir}/udev/rules.d/swupdate-usb.rules \
+    ${systemd_system_unitdir}/swupdate-usb@.service \
+"
+FILES_${PN}-tools-hawkbit = " \
+    ${bindir}/swupdate-hawkbitcfg \
+    ${bindir}/swupdate-sendtohawkbit \
+"
+FILES_${PN} += " \
+    ${libdir}/tmpfiles.d \
+    ${libdir}/swupdate/* \
+    ${systemd_system_unitdir}/swupdate.socket \
+    ${systemd_system_unitdir}/swupdate.service \
+    ${sysconfdir}/init.d/* \
+"
+FILES_${PN}-www = " \
+    ${libdir}/swupdate/conf.d/*mongoose* \
+    /www/* \
+"
+
+RDEPENDS_${PN}-usb += "${PN}-client"
+
+# The tools package is deprecated, it is an empty meta package for backward compatibility
+RDEPENDS_${PN}-tools += "${PN}-client ${PN}-progress ${PN}-tools-hawkbit \
+    ${@bb.utils.contains('DISTRO_FEATURES','systemd','${PN}-usb','',d)} \
+"
+
+S = "${WORKDIR}/git"
+B = "${WORKDIR}/build"
+
+EXTRA_OEMAKE += " O=${B} HOSTCC="${BUILD_CC}" HOSTCXX="${BUILD_CXX}" LD="${CC}" DESTDIR="${D}" LIBDIR="${libdir}" V=1 ARCH=${TARGET_ARCH} CROSS_COMPILE=${TARGET_PREFIX} SKIP_STRIP=y"
 
 DEPENDS += "kern-tools-native"
 
-# returns all the elements from the src uri that are .cfg files
-def find_cfgs(d):
-    return [s for s in src_patches(d, True) if s.endswith('.cfg')]
-
 python () {
+    import re
+
     try:
         defconfig = bb.fetch2.localpath('file://defconfig', d)
     except bb.fetch2.FetchError:
@@ -45,113 +99,170 @@ python () {
     except IOError:
         return
 
-    features = configfile.readlines()
+    features = configfile.read()
     configfile.close()
 
+    for current_fragment in find_cfgs(d):
+        try:
+            fragment_fd = open(current_fragment)
+        except IOError:
+            continue
+
+        fragment = fragment_fd.read()
+        fragment_fd.close()
+
+        fragment_search = re.findall('^(?:# )?(CONFIG_[a-zA-Z0-9_]*)[= ].*\n?', fragment, re.MULTILINE)
+
+        for feature in fragment_search:
+            features = re.sub("^(?:# )?" + feature + "[= ].*\n?", "", features, flags=re.MULTILINE)
+
+        features = features + fragment
+
+    features = features.splitlines(True)
+
+
+    depends = d.getVar('DEPENDS', False)
+
     if 'CONFIG_REMOTE_HANDLER=y\n' in features:
-        depends = d.getVar('DEPENDS', False)
-        d.setVar('DEPENDS', depends + ' zeromq')
+        depends += ' zeromq'
 
-    if 'CONFIG_ENCRYPTED_IMAGES=y\n' in features or 'CONFIG_MONGOOSESSL=y\n' in features or 'CONFIG_HASH_VERIFY=y\n' in features or 'CONFIG_SURICATTA_SSL=y\n' in features:
-        depends = d.getVar('DEPENDS', False)
-        d.setVar('DEPENDS', depends + ' openssl')
+    if 'CONFIG_SSL_IMPL_OPENSSL=y\n' in features:
+        depends += ' openssl'
+    elif 'CONFIG_SSL_IMPL_MBEDTLS=y\n' in features:
+        depends += ' mbedtls'
+    elif 'CONFIG_SSL_IMPL_WOLFSSL=y\n' in features:
+        depends += ' wolfssl'
 
     if 'CONFIG_JSON=y\n' in features:
-        depends = d.getVar('DEPENDS', False)
-        d.setVar('DEPENDS', depends + ' json-c')
+        depends += ' json-c'
 
     if 'CONFIG_SYSTEMD=y\n' in features:
-        depends = d.getVar('DEPENDS', False)
-        d.setVar('DEPENDS', depends + ' systemd')
+        depends += ' systemd'
 
     if 'CONFIG_ARCHIVE=y\n' in features:
-        depends = d.getVar('DEPENDS', False)
-        d.setVar('DEPENDS', depends + ' libarchive')
+        depends += ' libarchive'
 
     if 'CONFIG_LUA=y\n' in features:
-        depends = d.getVar('DEPENDS', False)
-        d.setVar('DEPENDS', depends + ' lua')
+        depends += ' lua'
 
     if 'CONFIG_UBOOT=y\n' in features:
-        depends = d.getVar('DEPENDS', False)
-        d.setVar('DEPENDS', depends + ' u-boot-fw-utils')
+        depends += ' libubootenv'
 
     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')
-
-    if 'CONFIG_CFI=y\n' in features:
-        depends = d.getVar('DEPENDS', False)
-        d.setVar('DEPENDS', depends + ' mtd-utils')
+        depends += ' curl'
 
-    if 'CONFIG_UBIVOL=y\n' in features:
-        depends = d.getVar('DEPENDS', False)
-        d.setVar('DEPENDS', depends + ' mtd-utils')
+    if 'CONFIG_MTD=y\n' in features or 'CONFIG_CFI=y\n' in features or 'CONFIG_UBIVOL=y\n' in features:
+        depends += ' mtd-utils'
 
     if 'CONFIG_UCFWHANDLER=y\n' in features:
-        depends = d.getVar('DEPENDS', False)
-        d.setVar('DEPENDS', depends + ' libgpiod')
+        depends += ' libgpiod'
+
+    if 'CONFIG_SWUFORWARDER_HANDLER=y\n' in features:
+        depends += ' curl libwebsockets uriparser'
 
     if 'CONFIG_RDIFFHANDLER=y\n' in features:
-        depends = d.getVar('DEPENDS', False)
-        d.setVar('DEPENDS', depends + ' librsync')
+        depends += ' librsync'
+
+    if 'CONFIG_BOOTLOADER_EBG=y\n' in features:
+        depends += ' efibootguard'
+
+    if 'CONFIG_ZSTD=y\n' in features:
+        depends += ' zstd'
+
+    if 'CONFIG_DISKPART=y\n' in features:
+        depends += ' util-linux'
+
+    d.setVar('DEPENDS', depends)
+
+    if 'CONFIG_MONGOOSE=y\n' in features:
+        d.setVar('SWUPDATE_MONGOOSE', 'true')
+    else:
+        d.setVar('SWUPDATE_MONGOOSE', 'false')
 
     if 'CONFIG_MONGOOSE_WEB_API_V2=y\n' in features:
         d.setVar('SWUPDATE_WWW', 'webapp')
 
-    if 'CONFIG_BOOTLOADER_EBG=y\n' in features:
-        depends = d.getVar('DEPENDS', False)
-        d.setVar('DEPENDS', depends + ' efibootguard')
+    # Values not used here might be used in a bbappend
+    d.setVar('SWUPDATE_SOCKET_CTRL_PATH', '/tmp/sockinstctrl')
+    d.setVar('SWUPDATE_SOCKET_PROGRESS_PATH', '/tmp/swupdateprog')
+    d.setVar('SWUPDATE_HW_COMPATIBILITY_FILE', '/etc/hwrevision')
+    d.setVar('SWUPDATE_SW_VERSIONS_FILE', '/etc/sw-versions')
+    for feature in features:
+        if feature.startswith('CONFIG_SOCKET_CTRL_PATH='):
+            ctrl_path = feature.split('=')[1].strip()
+            d.setVar('SWUPDATE_SOCKET_CTRL_PATH', ctrl_path)
+        elif feature.startswith('CONFIG_SOCKET_PROGRESS_PATH='):
+            prog_path = feature.split('=')[1].strip()
+            d.setVar('SWUPDATE_SOCKET_PROGRESS_PATH', prog_path)
+        elif feature.startswith('CONFIG_HW_COMPATIBILITY_FILE='):
+            hwrev_file = feature.split('=')[1].strip()
+            d.setVar('SWUPDATE_HW_COMPATIBILITY_FILE', hwrev_file)
+        elif feature.startswith('CONFIG_SW_VERSIONS_FILE='):
+            swver_file = feature.split('=')[1].strip()
+            d.setVar('SWUPDATE_SW_VERSIONS_FILE', swver_file)
 }
 
 do_configure () {
-  cp ${WORKDIR}/defconfig ${S}/.config
-  merge_config.sh -m .config ${@" ".join(find_cfgs(d))}
-  cml1_do_configure
+    cat > ${WORKDIR}/.config <<HEREDOC
+CONFIG_EXTRA_CFLAGS="${CFLAGS}"
+CONFIG_EXTRA_LDFLAGS="${LDFLAGS}"
+HEREDOC
+    cat ${WORKDIR}/defconfig >> ${WORKDIR}/.config
+
+    merge_config.sh -O ${B} -m ${WORKDIR}/.config ${@" ".join(find_cfgs(d))}
+    (cd ${S} && cml1_do_configure)
 }
 
 do_compile() {
-  unset LDFLAGS
-  oe_runmake swupdate_unstripped progress_unstripped
-  cp swupdate_unstripped swupdate
-  cp progress_unstripped progress
-
+    unset LDFLAGS
+    (cd ${S} && oe_runmake)
 }
 
 do_install () {
-
-  oe_runmake install
-
-  install -m 0755 -d ${D}/www
-  if [ -d ${S}/web-app ];then
-	cp -R --no-dereference --preserve=mode,links -v ${S}/examples/www/v2/* ${D}/www
-  else
-	install -m 0755 ${S}/www/* ${D}/www
-  fi
-
-  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
-  install -m 644 ${WORKDIR}/swupdate-usb@.service ${D}${systemd_unitdir}/system
-  install -m 644 ${WORKDIR}/swupdate-progress.service ${D}${systemd_unitdir}/system
-
-
-  if ${@bb.utils.contains('DISTRO_FEATURES','systemd','true','false',d)}; then
-    install -d ${D}${libdir}/tmpfiles.d
-    install -m 0644 ${WORKDIR}/systemd-tmpfiles-swupdate.conf ${D}${libdir}/tmpfiles.d/swupdate.conf
-    install -d ${D}${sysconfdir}/udev/rules.d
-    install -m 0644 ${WORKDIR}/swupdate-usb.rules ${D}${sysconfdir}/udev/rules.d/
-  fi
+    (cd ${S} && oe_runmake install)
+
+    install -m 0755 -d ${D}/www
+    if [ -d ${S}/web-app ];then
+        cp -R --no-dereference --preserve=mode,links -v ${S}/examples/www/v2/* ${D}/www
+    else
+        install -m 0755 ${S}/www/* ${D}/www
+    fi
+
+    install -d ${D}${sysconfdir}/init.d
+    install -m 755 ${WORKDIR}/swupdate ${D}${sysconfdir}/init.d
+
+    # shell based configuration loader allows to place code snippets into this folder
+    install -d ${D}${libdir}/swupdate/conf.d
+    install -m 755 ${WORKDIR}/swupdate.sh ${D}${libdir}/swupdate
+    sed -i 's#@LIBDIR@#${libdir}#g' ${D}${libdir}/swupdate/swupdate.sh
+    if ${SWUPDATE_MONGOOSE}; then
+        install -m 644 ${WORKDIR}/10-mongoose-args ${D}${libdir}/swupdate/conf.d/
+    fi
+    install -d ${D}${systemd_unitdir}/system
+    install -m 644 ${WORKDIR}/swupdate.service ${D}${systemd_system_unitdir}
+    sed -i 's#@LIBDIR@#${libdir}#' ${D}${systemd_system_unitdir}/swupdate.service
+    install -m 644 ${WORKDIR}/swupdate.socket.tmpl ${D}${systemd_system_unitdir}/swupdate.socket
+    sed -e "s,@@SWUPDATE_SOCKET_CTRL_PATH@@,${SWUPDATE_SOCKET_CTRL_PATH},g" \
+        -e "s,@@SWUPDATE_SOCKET_PROGRESS_PATH@@,${SWUPDATE_SOCKET_PROGRESS_PATH},g" \
+        -i ${D}${systemd_system_unitdir}/swupdate.socket
+    install -m 644 ${WORKDIR}/swupdate-usb@.service ${D}${systemd_system_unitdir}
+    install -m 644 ${WORKDIR}/swupdate-progress.service ${D}${systemd_system_unitdir}
+
+    if ${@bb.utils.contains('DISTRO_FEATURES','systemd','true','false',d)}; then
+        install -d ${D}${libdir}/tmpfiles.d
+        install -m 0644 ${WORKDIR}/tmpfiles-swupdate.conf ${D}${libdir}/tmpfiles.d/swupdate.conf
+        install -d ${D}${sysconfdir}/udev/rules.d
+        install -m 0644 ${WORKDIR}/swupdate-usb.rules ${D}${sysconfdir}/udev/rules.d/
+    else
+        # in case of systemd there is a service file, for sysv init we need to start it as well
+        install -m 0644 ${WORKDIR}/90-start-progress ${D}${libdir}/swupdate/conf.d/
+    fi
 }
 
 INITSCRIPT_NAME = "swupdate"
 INITSCRIPT_PARAMS = "defaults 70"
 
-SYSTEMD_SERVICE_${PN} = "swupdate.service"
-SYSTEMD_SERVICE_${PN} += "swupdate-usb@.service swupdate-progress.service"
+SYSTEMD_PACKAGES = "${PN} ${PN}-progress ${PN}-usb"
+SYSTEMD_SERVICE_${PN} = "swupdate.service swupdate.socket"
+SYSTEMD_SERVICE_${PN}-progress = "swupdate-progress.service"
+SYSTEMD_SERVICE_${PN}-usb = "swupdate-usb@.service"

+ 1 - 0
recipes-support/swupdate/swupdate/10-mongoose-args

@@ -0,0 +1 @@
+SWUPDATE_WEBSERVER_ARGS="-r /www ${SWUPDATE_MONGOOSE_EXTRA_ARGS:--p 8080}"

+ 1 - 0
recipes-support/swupdate/swupdate/90-start-progress

@@ -0,0 +1 @@
+exec /usr/bin/swupdate-progress -w -r &

+ 22 - 26
recipes-support/swupdate/swupdate/defconfig

@@ -11,10 +11,21 @@ CONFIG_HAVE_DOT_CONFIG=y
 #
 # General Configuration
 #
+# CONFIG_CURL is not set
+# CONFIG_CURL_SSL is not set
+# CONFIG_SYSTEMD is not set
+CONFIG_DEFAULT_CONFIG_FILE="/etc/swupdate.cfg"
 CONFIG_SCRIPTS=y
 CONFIG_HW_COMPATIBILITY=y
 CONFIG_HW_COMPATIBILITY_FILE="/etc/hwrevision"
 CONFIG_SW_VERSIONS_FILE="/etc/sw-versions"
+
+#
+# Socket Paths
+#
+CONFIG_SOCKET_CTRL_PATH=""
+CONFIG_SOCKET_PROGRESS_PATH=""
+CONFIG_SOCKET_REMOTE_HANDLER_DIRECTORY="/tmp/"
 CONFIG_MTD=y
 CONFIG_LUA=y
 CONFIG_LUAPKG="lua"
@@ -25,8 +36,6 @@ CONFIG_LUAPKG="lua"
 #
 CONFIG_CROSS_COMPILE=""
 CONFIG_SYSROOT=""
-CONFIG_EXTRA_CFLAGS=""
-CONFIG_EXTRA_LDFLAGS=""
 CONFIG_EXTRA_LDLIBS=""
 
 #
@@ -35,44 +44,26 @@ CONFIG_EXTRA_LDLIBS=""
 # CONFIG_DEBUG is not set
 # CONFIG_WERROR is not set
 # CONFIG_NOCLEANUP is not set
-# CONFIG_BOOTLOADER is not set
+# CONFIG_BOOTLOADER_EBG is not set
 CONFIG_UBOOT=y
 # CONFIG_BOOTLOADER_NONE is not set
 # CONFIG_BOOTLOADER_GRUB is not set
 CONFIG_UBOOT_FWENV="/etc/fw_env.config"
+CONFIG_UBOOT_DEFAULTENV="/etc/u-boot-initial-env"
+# CONFIG_SSL_IMPL_NONE is not set
+CONFIG_SSL_IMPL_OPENSSL=y
+# CONFIG_SSL_IMPL_MBEDTLS is not set
 # CONFIG_DOWNLOAD is not set
 # CONFIG_HASH_VERIFY is not set
 # CONFIG_SIGNED_IMAGES is not set
 # CONFIG_ENCRYPTED_IMAGES is not set
 # CONFIG_SURICATTA is not set
-
-#
-# Suricatta
-#
-
-#
-# Server
-#
-# CONFIG_SURICATTA_HAWKBIT is not set
-CONFIG_SURICATTA_SERVER_NONE=y
 CONFIG_WEBSERVER=y
-
-#
-# Webserver Features
-#
 CONFIG_MONGOOSE=y
-
-#
-# Mongoose Feature
-#
-CONFIG_MONGOOSELUA=y
 CONFIG_MONGOOSEIPV6=y
 CONFIG_MONGOOSESSL=y
-
-#
-# Archival Features
-#
 CONFIG_GUNZIP=y
+# CONFIG_ZSTD is not set
 
 #
 # Parser Features
@@ -89,10 +80,15 @@ CONFIG_PARSERROOT=""
 # CONFIG_UBIVOL is not set
 CONFIG_CFI=y
 # CONFIG_CFIHAMMING1 is not set
+# CONFIG_DISKPART is not set
 CONFIG_RAW=y
+# CONFIG_RDIFFHANDLER is not set
 CONFIG_LUASCRIPTHANDLER=y
 CONFIG_SHELLSCRIPTHANDLER=y
 # CONFIG_HANDLER_IN_LUA is not set
 # CONFIG_ARCHIVE is not set
 # CONFIG_REMOTE_HANDLER is not set
+# CONFIG_SWUFORWARDER_HANDLER is not set
 # CONFIG_BOOTLOADERHANDLER is not set
+# CONFIG_SSBLSWITCH is not set
+# CONFIG_UCFWHANDLER is not set

+ 2 - 2
recipes-support/swupdate/swupdate/swupdate

@@ -30,7 +30,7 @@ PATH=/sbin:/usr/sbin:/bin:/usr/bin
 
 DESC="swupdate"
 NAME="swupdate"
-DAEMON=/usr/bin/swupdate
+DAEMON=/usr/lib/swupdate/swupdate.sh
 PIDFILE=/var/run/$NAME.pid
 
 . /etc/init.d/functions || exit 1
@@ -57,7 +57,7 @@ do_start() {
 	*)
 		echo "Starting $DESC ..."
 		cd /home/root
-		exec $DAEMON -v -w "-r /www" $SWUPDATE_EXTRA_ARGS &
+		exec $DAEMON &
 		exit 0
 		;;
 	esac

+ 4 - 1
recipes-support/swupdate/swupdate/swupdate-progress.service

@@ -1,6 +1,9 @@
 [Unit]
 Description=swupdate progress service
-Requires=swupdate.service
+After=swupdate.service
 
 [Service]
 ExecStart=/usr/bin/swupdate-progress -r -w
+
+[Install]
+WantedBy=swupdate.service

+ 1 - 1
recipes-support/swupdate/swupdate/swupdate-usb.rules

@@ -1,2 +1,2 @@
-ACTION=="add", KERNEL=="sd*", SUBSYSTEM=="block", ENV{ID_FS_USAGE}=="filesystem", TAG+="systemd", ENV{SYSTEMD_WANTS}+="swupdate-usb@%k.service"
+ACTION=="add", KERNEL=="sd*", SUBSYSTEM=="block", ENV{ID_BUS}=="usb", ENV{ID_FS_USAGE}=="filesystem", TAG+="systemd", ENV{SYSTEMD_WANTS}+="swupdate-usb@%k.service"
 

+ 2 - 3
recipes-support/swupdate/swupdate/swupdate.service

@@ -4,9 +4,8 @@ Documentation=https://github.com/sbabic/swupdate
 Documentation=https://sbabic.github.io/swupdate
 
 [Service]
-ExecStartPre=-/usr/bin/swupdate-env
-EnvironmentFile=-/tmp/swupdate.env
-ExecStart=/usr/bin/swupdate -v -w "-r /www" $SWUPDATE_EXTRA_ARGS
+ExecStart=@LIBDIR@/swupdate/swupdate.sh
+KillMode=mixed
 
 [Install]
 WantedBy=multi-user.target

+ 28 - 0
recipes-support/swupdate/swupdate/swupdate.sh

@@ -0,0 +1,28 @@
+#!/bin/sh
+
+# Override these variables in sourced script(s) located
+# in /usr/lib/swupdate/conf.d or /etc/swupdate/conf.d
+SWUPDATE_ARGS="-v ${SWUPDATE_EXTRA_ARGS}"
+SWUPDATE_WEBSERVER_ARGS=""
+SWUPDATE_SURICATTA_ARGS=""
+
+# source all files from /etc/swupdate/conf.d and /usr/lib/swupdate/conf.d/
+# A file found in /etc replaces the same file in /usr
+for f in `(test -d @LIBDIR@/swupdate/conf.d/ && ls -1 @LIBDIR@/swupdate/conf.d/; test -d /etc/swupdate/conf.d && ls -1 /etc/swupdate/conf.d) | sort -u`; do
+  if [ -f /etc/swupdate/conf.d/$f ]; then
+    . /etc/swupdate/conf.d/$f
+  else
+    . @LIBDIR@/swupdate/conf.d/$f
+  fi
+done
+
+#  handle variable escaping in a simmple way. Use exec to forward open filedescriptors from systemd open.
+if [ "$SWUPDATE_WEBSERVER_ARGS" != "" -a  "$SWUPDATE_SURICATTA_ARGS" != "" ]; then
+  exec /usr/bin/swupdate $SWUPDATE_ARGS -w "$SWUPDATE_WEBSERVER_ARGS" -u "$SWUPDATE_SURICATTA_ARGS"
+elif [ "$SWUPDATE_WEBSERVER_ARGS" != "" ]; then
+  exec /usr/bin/swupdate $SWUPDATE_ARGS -w "$SWUPDATE_WEBSERVER_ARGS"
+elif [ "$SWUPDATE_SURICATTA_ARGS" != "" ]; then
+  exec /usr/bin/swupdate $SWUPDATE_ARGS -u "$SWUPDATE_SURICATTA_ARGS"
+else
+  exec /usr/bin/swupdate $SWUPDATE_ARGS
+fi

+ 11 - 0
recipes-support/swupdate/swupdate/swupdate.socket.tmpl

@@ -0,0 +1,11 @@
+[Unit]
+Description=SWUpdate socket listener
+Documentation=https://github.com/sbabic/swupdate
+Documentation=https://sbabic.github.io/swupdate
+
+[Socket]
+ListenStream=@@SWUPDATE_SOCKET_CTRL_PATH@@
+ListenStream=@@SWUPDATE_SOCKET_PROGRESS_PATH@@
+
+[Install]
+WantedBy=sockets.target

+ 0 - 1
recipes-support/swupdate/swupdate/systemd-tmpfiles-swupdate.conf → recipes-support/swupdate/swupdate/tmpfiles-swupdate.conf

@@ -1,3 +1,2 @@
 X /tmp/datadst
 X /tmp/scripts
-X /tmp/swupdate.env

+ 0 - 4
recipes-support/swupdate/swupdate_2018.11.bb

@@ -1,4 +0,0 @@
-require swupdate-legacy.inc
-require swupdate_tools.inc
-
-SRCREV = "e83730c4ec30134cdf56a2fd1d62a3767ade8133"

+ 6 - 0
recipes-support/swupdate/swupdate_2019.11.bb

@@ -0,0 +1,6 @@
+require swupdate.inc
+
+SRCREV = "5de3bc30a203ee218f9ebbe256b42e26cf06c74f"
+
+# Building out of tree is broken in this version
+B = "${S}"

+ 11 - 0
recipes-support/swupdate/swupdate_2020.04.bb

@@ -0,0 +1,11 @@
+require swupdate.inc
+
+SRCREV = "1a6dfbb5a0be978ac1a159758e278ab4d44167e2"
+
+SRC_URI += "file://0001-diskpart-force-kernel-to-reread-partition-table.patch \
+	    file://0001-Shellscript-stops-before-completing.patch \
+	    file://0001-diskpart-fix-adding-more-as-4-partitions.patch \
+	    "
+
+# Building out of tree is broken in this version
+B = "${S}"

+ 2 - 2
recipes-support/swupdate/swupdate_git.bb

@@ -1,6 +1,6 @@
 require swupdate.inc
-require swupdate_tools.inc
 
 DEFAULT_PREFERENCE = "-1"
 
-SRCREV ?= "f8a0f105d11e1278b35b3a7230656e7af76ac04b"
+SRCREV ?= "bd2685eab2bb91107928d653cae55f2430d5a52b"
+PV = "2020.04+git${SRCPV}"

+ 0 - 24
recipes-support/swupdate/swupdate_tools.inc

@@ -1,24 +0,0 @@
-PACKAGES =+ "${PN}-tools"
-
-INSANE_SKIP_${PN}-tools = "ldflags"
-
-FILES_${PN}-tools = "${bindir}/swupdate-client \
-                    ${bindir}/swupdate-progress \
-                    ${bindir}/swupdate-hawkbitcfg \
-                    ${bindir}/swupdate-sendtohawkbit"
-
-do_compile() {
-  unset LDFLAGS
-
-  oe_runmake
-  cp swupdate_unstripped swupdate
-}
-
-do_install_append () {
-
-  install -m 0755 tools/client_unstripped ${D}${bindir}/swupdate-client
-  install -m 0755 tools/progress_unstripped ${D}${bindir}/swupdate-progress
-  install -m 0755 tools/hawkbitcfg_unstripped ${D}${bindir}/swupdate-hawkbitcfg
-  install -m 0755 tools/sendtohawkbit_unstripped ${D}${bindir}/swupdate-sendtohawkbit
-
-}