Message ID | 20180713084217.15852-2-raphael.freudiger@siemens.com |
---|---|
State | Changes Requested |
Headers | show |
Series | [meta-swupdate,v3,1/2] swupdate_class: split out common python functionality | expand |
Hi Raphael, Am 13.07.2018 um 10:42 schrieb Raphael Freudiger: > Signed-off-by: Raphael Freudiger <raphael.freudiger@siemens.com> > --- > classes/image_types_swupdate.bbclass | 65 ++++++++++++++++++++++++++++++++++++ > 1 file changed, 65 insertions(+) > create mode 100644 classes/image_types_swupdate.bbclass > > diff --git a/classes/image_types_swupdate.bbclass b/classes/image_types_swupdate.bbclass > new file mode 100644 > index 0000000..7179535 > --- /dev/null > +++ b/classes/image_types_swupdate.bbclass > @@ -0,0 +1,65 @@ > +# Define swupdate image type that can be used in images. > +# > +# Example Usage: > +# > +# IMAGE_CLASSES += "image_types_swupdate" > +# IMAGE_FSTYPES += "swu" > +# IMAGE_TYPEDEP_swu = "ext4.gz" > +# SWUPDATE_FILES += "${PN}-${MACHINE}.ext4.gz" > +inherit swupdate-common > + > + > +IMAGE_CMD_swu () { > + cd ${S} > + files="sw-description ${SWUPDATE_FILES}" > + if [ -n "${SWUPDATE_SIGNING}" ] > + then > + files="sw-description.sig ${files}" > + fi > + > + for i in ${files} > + do > + echo $i > + done | cpio -ov -H crc > ${IMGDEPLOYDIR}/${IMAGE_NAME}${IMAGE_NAME_SUFFIX}.swu > +} > + > +python do_prepare_swupdate() { > + import shutil > + s = d.getVar('S', True) > + workdir = d.getVar('WORKDIR', True) > + deploydir = d.getVar('DEPLOY_DIR_IMAGE', True) > + imgdeploydir = d.getVar('IMGDEPLOYDIR', True) > + > + > + swupdate_files = (d.getVar('SWUPDATE_FILES', True) or '').split() > + > + list_for_cpio = [] > + > + for file in swupdate_files: > + imagename = os.path.basename(file) > + src = os.path.join(workdir, imagename) > + if not os.path.exists(src): > + src = os.path.join(deploydir, imagename) > + if not os.path.exists(src): > + src = os.path.join(imgdeploydir, imagename) > + if not os.path.exists(src): > + bb.fatal("File %s does not exist in any of the directories %s, %s or %s." > + % (imagename, workdir, deploydir, imgdeploydir)) Please don't try different directories because this could lead to different results or hide misbehavior. Best regards Stefan
Hi Raphael, On 13/07/2018 20:05, Stefan Herbrechtsmeier wrote: > Hi Raphael, > > Am 13.07.2018 um 10:42 schrieb Raphael Freudiger: >> Signed-off-by: Raphael Freudiger <raphael.freudiger@siemens.com> >> --- >> classes/image_types_swupdate.bbclass | 65 >> ++++++++++++++++++++++++++++++++++++ >> 1 file changed, 65 insertions(+) >> create mode 100644 classes/image_types_swupdate.bbclass >> >> diff --git a/classes/image_types_swupdate.bbclass >> b/classes/image_types_swupdate.bbclass >> new file mode 100644 >> index 0000000..7179535 >> --- /dev/null >> +++ b/classes/image_types_swupdate.bbclass >> @@ -0,0 +1,65 @@ >> +# Define swupdate image type that can be used in images. >> +# >> +# Example Usage: >> +# >> +# IMAGE_CLASSES += "image_types_swupdate" >> +# IMAGE_FSTYPES += "swu" >> +# IMAGE_TYPEDEP_swu = "ext4.gz" >> +# SWUPDATE_FILES += "${PN}-${MACHINE}.ext4.gz" >> +inherit swupdate-common >> + >> + >> +IMAGE_CMD_swu () { >> + cd ${S} >> + files="sw-description ${SWUPDATE_FILES}" >> + if [ -n "${SWUPDATE_SIGNING}" ] >> + then >> + files="sw-description.sig ${files}" >> + fi >> + >> + for i in ${files} >> + do >> + echo $i >> + done | cpio -ov -H crc > >> ${IMGDEPLOYDIR}/${IMAGE_NAME}${IMAGE_NAME_SUFFIX}.swu >> +} >> + >> +python do_prepare_swupdate() { >> + import shutil >> + s = d.getVar('S', True) >> + workdir = d.getVar('WORKDIR', True) >> + deploydir = d.getVar('DEPLOY_DIR_IMAGE', True) >> + imgdeploydir = d.getVar('IMGDEPLOYDIR', True) >> + >> + >> + swupdate_files = (d.getVar('SWUPDATE_FILES', True) or '').split() >> + >> + list_for_cpio = [] >> + >> + for file in swupdate_files: >> + imagename = os.path.basename(file) >> + src = os.path.join(workdir, imagename) >> + if not os.path.exists(src): >> + src = os.path.join(deploydir, imagename) >> + if not os.path.exists(src): >> + src = os.path.join(imgdeploydir, imagename) >> + if not os.path.exists(src): >> + bb.fatal("File %s does not exist in any of the >> directories %s, %s or %s." >> + % (imagename, workdir, deploydir, imgdeploydir)) > Please don't try different directories because this could lead to > different results or hide misbehavior. I think Stefan is right - just to imagine what is happening if the same file is in more as one directory. And I do not know how if it works from "workdir": this assumes that image was fetched, but do_fetch() is generally disabled in case of an image. IMHO it is better to get an error else to figure out what happens after a successful build, but without the expected results. Up now, images should be put into DEPLOY_DIR_IMAGE - or do you have found a race condition and build failed ? I can imagine that after do_rootfs() the image is in IMGDEPLOYDIR, but not yet in DEPLOY_DIR_IMAGE. Best regards, Stefano Babic
diff --git a/classes/image_types_swupdate.bbclass b/classes/image_types_swupdate.bbclass new file mode 100644 index 0000000..7179535 --- /dev/null +++ b/classes/image_types_swupdate.bbclass @@ -0,0 +1,65 @@ +# Define swupdate image type that can be used in images. +# +# Example Usage: +# +# IMAGE_CLASSES += "image_types_swupdate" +# IMAGE_FSTYPES += "swu" +# IMAGE_TYPEDEP_swu = "ext4.gz" +# SWUPDATE_FILES += "${PN}-${MACHINE}.ext4.gz" +inherit swupdate-common + + +IMAGE_CMD_swu () { + cd ${S} + files="sw-description ${SWUPDATE_FILES}" + if [ -n "${SWUPDATE_SIGNING}" ] + then + files="sw-description.sig ${files}" + fi + + for i in ${files} + do + echo $i + done | cpio -ov -H crc > ${IMGDEPLOYDIR}/${IMAGE_NAME}${IMAGE_NAME_SUFFIX}.swu +} + +python do_prepare_swupdate() { + import shutil + s = d.getVar('S', True) + workdir = d.getVar('WORKDIR', True) + deploydir = d.getVar('DEPLOY_DIR_IMAGE', True) + imgdeploydir = d.getVar('IMGDEPLOYDIR', True) + + + swupdate_files = (d.getVar('SWUPDATE_FILES', True) or '').split() + + list_for_cpio = [] + + for file in swupdate_files: + imagename = os.path.basename(file) + src = os.path.join(workdir, imagename) + if not os.path.exists(src): + src = os.path.join(deploydir, imagename) + if not os.path.exists(src): + src = os.path.join(imgdeploydir, imagename) + if not os.path.exists(src): + bb.fatal("File %s does not exist in any of the directories %s, %s or %s." + % (imagename, workdir, deploydir, imgdeploydir)) + dst = os.path.join(s, imagename) + shutil.copyfile(src, dst) + list_for_cpio.append(imagename) + + prepare_sw_description(d, s, list_for_cpio) +} + +# The image type needs an additional preparation task, but it should only be executed when needed. +# Check that swu is in the IMAGE_FSTYPES before adding the task. +python () { + fstypes = (d.getVar('IMAGE_FSTYPES', True) or '').split() + dep = (d.getVar('IMAGE_TYPEDEP_swu', True) or '').split() + if 'swu' in fstypes: + # make sure dependencies are build before the preparation + after = ['do_rootfs'] + after += ['do_image_%s' % typ.split('.')[0] for typ in dep] + bb.build.addtask('do_prepare_swupdate', 'do_image_swu', ' '.join(after), d) +}
Signed-off-by: Raphael Freudiger <raphael.freudiger@siemens.com> --- classes/image_types_swupdate.bbclass | 65 ++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 classes/image_types_swupdate.bbclass