Skip to contentSkip to conversation

wic: plugins: rawcopy: support to add offset when writing the raw image

PATCH In review Kevin Hao 3 participants 6 messages Dec 8, 2017 – Dec 11, 2017

lore
Share & tools
lore

Kevin Hao

author
#0 lore raw

PATCH 1/2 wic: plugins: rawcopy: support to add offset when writing the raw image

In some cases we need to skip some reserved sectors when writing a raw image. So add support to set an offset for writing.

---
 scripts/lib/wic/plugins/source/rawcopy.py | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
scripts/lib/wic/plugins/source/rawcopy.py +3 -4
index 424ed26ed6ba..baf991fe8d5d 100644
@@ -53,10 +53,9 @@ class RawCopyPlugin(SourcePlugin):
         src = os.path.join(kernel_dir, source_params['file'])
         dst = os.path.join(cr_workdir, "%s.%s" % (source_params['file'], part.lineno))
 
-        if 'skip' in source_params:
-            sparse_copy(src, dst, skip=int(source_params['skip']))
-        else:
-            sparse_copy(src, dst)
+        skip = 0 if 'skip' not in source_params else int(source_params['skip'])
+        seek = 0 if 'seek' not in source_params else int(source_params['seek'])
+        sparse_copy(src, dst, skip, seek)
 
         # get the size in the right units for kickstart (kB)
         du_cmd = "du -Lbks %s" % dst
Signature · 1 line
2.9.3
author
#1 lore raw

PATCH 2/2 wic: plugins: rawcopy: Add support to download the raw image from a http server

Some firmwares are critical for the basic functions of the board, and may be used by the bootloader. Due to the license issue, we can't integrate it. But we do need it when creating a booting image by using WIC. So add the support for the WIC to download a raw file from http server and write it to a specific part. In order to restrict the downloading behaviour, we introduce a "WKS_ALLOW_DOWNLOAD" variable and only do the downloading when this variable is set.

---
 meta/classes/image_types_wic.bbclass      |  2 +-
 scripts/lib/wic/plugins/source/rawcopy.py | 13 +++++++++++--
 2 files changed, 12 insertions(+), 3 deletions(-)
meta/classes/image_types_wic.bbclass +1 -1
index 222ae004338d..70858ad5d7a1 100644
@@ -3,7 +3,7 @@
 WICVARS ?= "\
            BBLAYERS IMGDEPLOYDIR DEPLOY_DIR_IMAGE FAKEROOTCMD IMAGE_BASENAME IMAGE_BOOT_FILES \
            IMAGE_LINK_NAME IMAGE_ROOTFS INITRAMFS_FSTYPES INITRD INITRD_LIVE ISODIR RECIPE_SYSROOT_NATIVE \
-           ROOTFS_SIZE STAGING_DATADIR STAGING_DIR STAGING_LIBDIR TARGET_SYS"
+           ROOTFS_SIZE STAGING_DATADIR STAGING_DIR STAGING_LIBDIR TARGET_SYS WKS_ALLOW_DOWNLOAD"
 
 WKS_FILE ??= "${IMAGE_BASENAME}.${MACHINE}.wks"
 WKS_FILES ?= "${WKS_FILE} ${IMAGE_BASENAME}.wks"
scripts/lib/wic/plugins/source/rawcopy.py +11 -2
index baf991fe8d5d..808c279aed4c 100644
@@ -50,8 +50,17 @@ class RawCopyPlugin(SourcePlugin):
         if 'file' not in source_params:
             raise WicError("No file specified")
 
-        src = os.path.join(kernel_dir, source_params['file'])
-        dst = os.path.join(cr_workdir, "%s.%s" % (source_params['file'], part.lineno))
+        if source_params['file'].startswith('http://') or source_params['file'].startswith('https://'):
+            # Only download the image from remote site when explicilty requesting so
+            if get_bitbake_var("WKS_ALLOW_DOWNLOAD") != "1":
+                return
+            src = os.path.join(cr_workdir, "%s" % source_params['file'].rsplit('/',1)[-1])
+            dst = "%s.dst" % src
+            download_cmd = "wget -r -O %s %s" %(src, source_params['file'])
+            exec_cmd(download_cmd)
+        else:
+            src = os.path.join(kernel_dir, source_params['file'])
+            dst = os.path.join(cr_workdir, "%s.%s" % (source_params['file'], part.lineno))
 
         skip = 0 if 'skip' not in source_params else int(source_params['skip'])
         seek = 0 if 'seek' not in source_params else int(source_params['seek'])
Signature · 1 line
2.9.3
#2 lore raw

Re: [PATCH 2/2] wic: plugins: rawcopy: Add support to download the raw image from a http server

Quoted 9 lines · Kevin Hao

Some firmwares are critical for the basic functions of the board, and may be used by the bootloader. Due to the license issue, we can't integrate it. But we do need it when creating a booting image by using WIC. So add the support for the WIC to download a raw file from http server and write it to a specific part. In order to restrict the downloading behaviour, we introduce a "WKS_ALLOW_DOWNLOAD" variable and only do the downloading when this variable is set.

This does not make much sense.

It does not allow to be downloaded? so build system can download it and use it as a normal artifact. Adding another source way seems controversial.

Signature · 3 lines
Otavio Salvador                             O.S. Systems
http://www.ossystems.com.br        http://code.ossystems.com.br
Mobile: +55 (53) 9981-7854            Mobile: +1 (347) 903-9750
author
#3 lore raw

Re: [PATCH 2/2] wic: plugins: rawcopy: Add support to download the raw image from a http server

Quoted 9 lines · Otavio Salvador
Quoted 8 lines · Kevin Hao

Some firmwares are critical for the basic functions of the board, and may be used by the bootloader. Due to the license issue, we can't integrate it. But we do need it when creating a booting image by using WIC. So add the support for the WIC to download a raw file from http server and write it to a specific part. In order to restrict the downloading behaviour, we introduce a "WKS_ALLOW_DOWNLOAD" variable and only do the downloading when this variable is set.

Quoted 6 lines
Quoted 1 line

This does not make much sense.

It does not allow to be downloaded? so build system can download it and use it as a normal artifact.

In some cases, it doesn't make sense to do so. Because:
a) These firmwares are just raw binary files, they don't need any build or process. They are only useful when we try to create a bootable image.
b) There firmwares may be licensed under a proprietary license. We may not integrate them to a fully open source build system. But we do want to provide an easy way for the customer to build a bootable image.

Thanks,
Kevin

Quoted 7 lines

Adding another source way seems
controversial.

Signature · 3 lines
Otavio Salvador                             O.S. Systems
http://www.ossystems.com.br        http://code.ossystems.com.br
Mobile: +55 (53) 9981-7854            Mobile: +1 (347) 903-9750
#4 lore raw

Re: [PATCH 2/2] wic: plugins: rawcopy: Add support to download the raw image from a http server

Quoted 12 lines · Kevin Hao
Quoted 11 lines · Otavio Salvador
Quoted 9 lines · Kevin Hao

Some firmwares are critical for the basic functions of the board, and may be used by the bootloader. Due to the license issue, we can't integrate it. But we do need it when creating a booting image by using WIC. So add the support for the WIC to download a raw file from http server and write it to a specific part. In order to restrict the downloading behaviour, we introduce a "WKS_ALLOW_DOWNLOAD" variable and only do the downloading when this variable is set.

Quoted 8 lines
Quoted 4 lines

This does not make much sense.

It does not allow to be downloaded? so build system can download it and use it as a normal artifact.

In some cases, it doesn't make sense to do so. Because:
a) These firmwares are just raw binary files, they don't need any build or process. They are only useful when we try to create a bootable image.

In any case, keep them on the download cache is a good thing as it avoids build issues due network instability and avoids as well undesired file content changes.

Quoted 3 lines

b) There firmwares may be licensed under a proprietary license. We may not integrate them to a fully open source build system. But we do want to provide an easy way for the customer to build a bootable image.

Sure and I agree, but this is what layers are for.

Signature · 3 lines
Otavio Salvador                             O.S. Systems
http://www.ossystems.com.br        http://code.ossystems.com.br
Mobile: +55 (53) 9981-7854            Mobile: +1 (347) 903-9750
#5 lore raw

Re: [PATCH 2/2] wic: plugins: rawcopy: Add support to download the raw image from a http server

Quoted 26 lines · Otavio Salvador
Quoted 12 lines · Kevin Hao
Quoted 11 lines · Otavio Salvador
Quoted 9 lines · Kevin Hao

Some firmwares are critical for the basic functions of the board, and may be used by the bootloader. Due to the license issue, we can't integrate it. But we do need it when creating a booting image by using WIC. So add the support for the WIC to download a raw file from http server and write it to a specific part. In order to restrict the downloading behaviour, we introduce a "WKS_ALLOW_DOWNLOAD" variable and only do the downloading when this variable is set.

Quoted 8 lines
Quoted 4 lines

This does not make much sense.

It does not allow to be downloaded? so build system can download it and use it as a normal artifact.

In some cases, it doesn't make sense to do so. Because:
a) These firmwares are just raw binary files, they don't need any build or process. They are only useful when we try to create a bootable image.

In any case, keep them on the download cache is a good thing as it avoids build issues due network instability and avoids as well undesired file content changes.

Quoted 6 lines
Quoted 3 lines

b) There firmwares may be licensed under a proprietary license. We may not integrate them to a fully open source build system. But we do want to provide an easy way for the customer to build a bootable image.

Sure and I agree, but this is what layers are for.

I agree with Otavio here. Images built with OE / Bitbake should list all their sources in SRC_URIs.

Our (internal) releases includes images with all the sources needed to build the final target images, and we have had issues before with make systems pulling in sources in do_configure.

I don't personally think do_image_wic is any different than do_configure in this regard.

// Martin