diff mbox series

Enable package update on Yocto

Message ID 20210316030156.1970-1-zakaria.zidouh@smile.fr
State Not Applicable
Headers show
Series Enable package update on Yocto | expand

Commit Message

zazid March 16, 2021, 3:01 a.m. UTC
---
 classes/swupdate-common.bbclass | 44 +++++++++++++++++++++++++++++++++
 classes/swupdate.bbclass        | 16 ++++++++++--
 2 files changed, 58 insertions(+), 2 deletions(-)

Comments

Stefano Babic March 16, 2021, 9:16 a.m. UTC | #1
Hi Zazid,

On 16.03.21 04:01, zazid wrote:
> ---
>   classes/swupdate-common.bbclass | 44 +++++++++++++++++++++++++++++++++
>   classes/swupdate.bbclass        | 16 ++++++++++--
>   2 files changed, 58 insertions(+), 2 deletions(-)
> 
> diff --git a/classes/swupdate-common.bbclass b/classes/swupdate-common.bbclass
> index 578f305..d79c897 100644
> --- a/classes/swupdate-common.bbclass
> +++ b/classes/swupdate-common.bbclass
> @@ -162,3 +162,47 @@ def prepare_sw_description(d, s, list_for_cpio):
>                   bb.fatal("Failed to sign sw-description with %s" % (privkey))
>           else:
>               bb.fatal("Unrecognized SWUPDATE_SIGNING mechanism.");
> +
> +def get_packagesType(d):
> +    if not d.getVar('SWUPDATE_PACKAGES_TYPE'):
> +        return False
> +    packagesType = d.getVar("SWUPDATE_PACKAGES_TYPE")
> +    if packagesType == "ipk":
> +        return "_%s.ipk" %(d.getVar("TUNE_PKGARCH"))
> +    elif packagesType == "rpm":
> +        return ".%s.rpm" %(d.getVar("TUNE_PKGARCH"))
> +    elif packagesType == "tar":
> +        return "tar.gz"
> +    else:
> +        return False
> +

Add all types when they will be implemented, else it is just dead code.

> +def get_packagesPath(d, pkgType):
> +    if pkgType == "tar.gz":
> +        d.setVar("SWU_PKG_DEST" , d.getVar("DEPLOY_DIR_TAR"))
> +        return d.getVar("DEPLOY_DIR_TAR")
> +    else:
> +        pkgDest = d.getVar("DEPLOY_DIR") + "/" + d.getVar("SWUPDATE_PACKAGES_TYPE") + "/" + d.getVar("TUNE_PKGARCH")
> +        d.setVar("SWU_PKG_DEST" , pkgDest)
> +        return pkgDest
> +
> +def add_pratial_packages(d, list_for_cpio):
> +    import io
> +    list_of_packages = d.getVar("SWUPDATE_PACKAGES").split()
> +    packagesType = get_packagesType(d)
> +    if not packagesType:
> +        bb.fatal("SWUPDATE_PACKAGES_TYPE variable is not set properly. Supported types : ipk, rpm, tar")
> +        return False
> +    packages_deploy_dir = get_packagesPath(d, packagesType)
> +    if not os.path.exists("%s" %packages_deploy_dir):
> +        bb.fatal("cannot find any package. Please add package_tar to your PACKAGE_CLASSES variable. %s" %packages_deploy_dir)
> +        return False
> +    for package in list_of_packages:
> +        packages_name = os.popen("find %s -name '%s[-,_][1-9]*%s' " %(packages_deploy_dir,package,packagesType)).read()

See previous comment : this is not how OE retrieve the list of packages. 
Check as do_rootfs works to get the list of package and try to reuse the 
functions provided by OE-Core.

> +        if not packages_name:
> +            bb.fatal("SWUPDATE_PACKAGES is not set properly. Package %s not found while building swupdate bundles." %package)
> +            return False
> +        basenames = []
> +        for package_tar in io.StringIO(packages_name):
> +            basenames.append(os.path.basename(package_tar[:-1]))
> +        list_for_cpio.append(max(basenames))
> +    return packages_deploy_dir
> \ No newline at end of file
> diff --git a/classes/swupdate.bbclass b/classes/swupdate.bbclass
> index fe7b6ec..8da338c 100644
> --- a/classes/swupdate.bbclass
> +++ b/classes/swupdate.bbclass
> @@ -32,7 +32,6 @@
>   #   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}"
>   
> @@ -60,7 +59,7 @@ IMGDEPLOYDIR = "${WORKDIR}/deploy-${PN}-swuimage"
>   do_swuimage[dirs] = "${TOPDIR}"
>   do_swuimage[cleandirs] += "${S} ${IMGDEPLOYDIR}"
>   do_swuimage[umask] = "022"
> -SSTATETASKS += "do_swuimage"
> +SSTATETASKS += "do_swuimage do_partial_swuimage"
>   SSTATE_SKIP_CREATION_task-swuimage = '1'
>   do_swuimage[sstate-inputdirs] = "${IMGDEPLOYDIR}"
>   do_swuimage[sstate-outputdirs] = "${DEPLOY_DIR_IMAGE}"
> @@ -164,6 +163,18 @@ python do_swuimage () {
>       os.system("cd " + imgdeploydir + "; " + line)
>   }
>   
> +python do_partial_swuimage () {
> +    if not d.getVar('SWUPDATE_PACKAGES'):
> +        return False
> +    list_for_cpio = ["sw-description"]
> +    packagesPath = add_pratial_packages(d, list_for_cpio)
> +    if not packagesPath:
> +        bb.fatal("ERROR")
> +    line = 'for i in ' + ' '.join(list_for_cpio) + '; do echo $i;done | cpio -ov -H crc >' + os.path.join(d.getVar("DEPLOY_DIR_IMAGE", True),'swupdate-partial.swu')
> +    os.system("cp %s/sw-description %s" %(d.getVar("WORKDIR"), packagesPath))
> +    os.system("cd " + packagesPath + ";" + line)
> +}
> +
>   COMPRESSIONTYPES = ""
>   PACKAGE_ARCH = "${MACHINE_ARCH}"
>   
> @@ -171,3 +182,4 @@ INHIBIT_DEFAULT_DEPS = "1"
>   EXCLUDE_FROM_WORLD = "1"
>   
>   addtask do_swuimage after do_unpack do_prepare_recipe_sysroot before do_build
> +addtask do_partial_swuimage after do_unpack do_prepare_recipe_sysroot before do_swuimage
> 

Best regards,
Stefano Babic
diff mbox series

Patch

diff --git a/classes/swupdate-common.bbclass b/classes/swupdate-common.bbclass
index 578f305..d79c897 100644
--- a/classes/swupdate-common.bbclass
+++ b/classes/swupdate-common.bbclass
@@ -162,3 +162,47 @@  def prepare_sw_description(d, s, list_for_cpio):
                 bb.fatal("Failed to sign sw-description with %s" % (privkey))
         else:
             bb.fatal("Unrecognized SWUPDATE_SIGNING mechanism.");
+
+def get_packagesType(d):
+    if not d.getVar('SWUPDATE_PACKAGES_TYPE'):
+        return False
+    packagesType = d.getVar("SWUPDATE_PACKAGES_TYPE")
+    if packagesType == "ipk":
+        return "_%s.ipk" %(d.getVar("TUNE_PKGARCH"))
+    elif packagesType == "rpm":
+        return ".%s.rpm" %(d.getVar("TUNE_PKGARCH")) 
+    elif packagesType == "tar":
+        return "tar.gz"
+    else:
+        return False
+
+def get_packagesPath(d, pkgType):
+    if pkgType == "tar.gz":
+        d.setVar("SWU_PKG_DEST" , d.getVar("DEPLOY_DIR_TAR"))
+        return d.getVar("DEPLOY_DIR_TAR")
+    else:
+        pkgDest = d.getVar("DEPLOY_DIR") + "/" + d.getVar("SWUPDATE_PACKAGES_TYPE") + "/" + d.getVar("TUNE_PKGARCH")
+        d.setVar("SWU_PKG_DEST" , pkgDest)
+        return pkgDest
+
+def add_pratial_packages(d, list_for_cpio):
+    import io
+    list_of_packages = d.getVar("SWUPDATE_PACKAGES").split()
+    packagesType = get_packagesType(d)
+    if not packagesType:
+        bb.fatal("SWUPDATE_PACKAGES_TYPE variable is not set properly. Supported types : ipk, rpm, tar")
+        return False
+    packages_deploy_dir = get_packagesPath(d, packagesType)
+    if not os.path.exists("%s" %packages_deploy_dir):
+        bb.fatal("cannot find any package. Please add package_tar to your PACKAGE_CLASSES variable. %s" %packages_deploy_dir)
+        return False
+    for package in list_of_packages:
+        packages_name = os.popen("find %s -name '%s[-,_][1-9]*%s' " %(packages_deploy_dir,package,packagesType)).read()
+        if not packages_name:
+            bb.fatal("SWUPDATE_PACKAGES is not set properly. Package %s not found while building swupdate bundles." %package)
+            return False
+        basenames = []
+        for package_tar in io.StringIO(packages_name):
+            basenames.append(os.path.basename(package_tar[:-1]))
+        list_for_cpio.append(max(basenames))
+    return packages_deploy_dir
\ No newline at end of file
diff --git a/classes/swupdate.bbclass b/classes/swupdate.bbclass
index fe7b6ec..8da338c 100644
--- a/classes/swupdate.bbclass
+++ b/classes/swupdate.bbclass
@@ -32,7 +32,6 @@ 
 #   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}"
 
@@ -60,7 +59,7 @@  IMGDEPLOYDIR = "${WORKDIR}/deploy-${PN}-swuimage"
 do_swuimage[dirs] = "${TOPDIR}"
 do_swuimage[cleandirs] += "${S} ${IMGDEPLOYDIR}"
 do_swuimage[umask] = "022"
-SSTATETASKS += "do_swuimage"
+SSTATETASKS += "do_swuimage do_partial_swuimage"
 SSTATE_SKIP_CREATION_task-swuimage = '1'
 do_swuimage[sstate-inputdirs] = "${IMGDEPLOYDIR}"
 do_swuimage[sstate-outputdirs] = "${DEPLOY_DIR_IMAGE}"
@@ -164,6 +163,18 @@  python do_swuimage () {
     os.system("cd " + imgdeploydir + "; " + line)
 }
 
+python do_partial_swuimage () {
+    if not d.getVar('SWUPDATE_PACKAGES'):
+        return False
+    list_for_cpio = ["sw-description"]
+    packagesPath = add_pratial_packages(d, list_for_cpio)
+    if not packagesPath:
+        bb.fatal("ERROR")
+    line = 'for i in ' + ' '.join(list_for_cpio) + '; do echo $i;done | cpio -ov -H crc >' + os.path.join(d.getVar("DEPLOY_DIR_IMAGE", True),'swupdate-partial.swu')
+    os.system("cp %s/sw-description %s" %(d.getVar("WORKDIR"), packagesPath))
+    os.system("cd " + packagesPath + ";" + line)
+}
+
 COMPRESSIONTYPES = ""
 PACKAGE_ARCH = "${MACHINE_ARCH}"
 
@@ -171,3 +182,4 @@  INHIBIT_DEFAULT_DEPS = "1"
 EXCLUDE_FROM_WORLD = "1"
 
 addtask do_swuimage after do_unpack do_prepare_recipe_sysroot before do_build
+addtask do_partial_swuimage after do_unpack do_prepare_recipe_sysroot before do_swuimage