瀏覽代碼

Add systemd swupdate mechanism for usb media

In case of using swupdate with systemd this add the possibility of
updating a device automatically when inserting an usb media containing
a valid update artifact:

 -swupdate-usb.rules: trigger swupdate-usb@ service by passing device name as argument

 -swupdate-progress.service: start progress tool that monitor update status
                             and reboot the device if update is succesful

 -swupdate-usb@.service: mount the media device, pass the update artficat if existing
                         on usb media via client tool. In case of failure the media is umounted

Note that swupdate-usb@.service unit has a require dependency on swupdate-progress.service
which means the the latter is started first.

Signed-off-by: Ayoub Zaki <ayoub.zaki@embexus.com>
Ayoub Zaki 8 年之前
父節點
當前提交
942b6a654a

+ 12 - 0
recipes-support/swupdate/swupdate.inc

@@ -11,6 +11,9 @@ 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 \
      "
 
 SRCREV = "${AUTOREV}"
@@ -118,9 +121,18 @@ do_install () {
 
   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"

+ 7 - 0
recipes-support/swupdate/swupdate/swupdate-progress.service

@@ -0,0 +1,7 @@
+[Unit]
+Description=swupdate progress service
+Requires=swupdate.service
+
+[Service]
+Type=forking
+ExecStart=/usr/bin/swupdate-progress -r -w

+ 2 - 0
recipes-support/swupdate/swupdate/swupdate-usb.rules

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

+ 8 - 0
recipes-support/swupdate/swupdate/swupdate-usb@.service

@@ -0,0 +1,8 @@
+[Unit]
+Description=usb media swupdate service
+Requires=swupdate-progress.service
+
+[Service]
+ExecStartPre=/bin/mount /dev/%I /mnt
+ExecStart=/bin/sh -c "swupdate-client -v /mnt/*.swu"
+ExecStopPost=/bin/umount /mnt