日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

yocto machine class解析之st-partitions-image

發(fā)布時間:2024/3/26 编程问答 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 yocto machine class解析之st-partitions-image 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

yocto machine class解析之st-partitions-image

stm32mp157 yocto的meta-st-stm32mp layer中提供了幾個class,后續(xù)幾篇文章重點分析這些class文件:
第一篇就從st-partitions-image.bbclass 開始,st所有創(chuàng)建image的bb文件都會引用st-partitions-image,包括bootfs userfs vendorfs等image的bb 文件。這個class會在image編譯以后生成分區(qū)鏡像。

ENABLE_PARTITIONS_IMAGE ?= "1"PARTITIONS_CONFIG ??= "" PARTITIONS_IMAGE ??= "" PARTITIONS_MOUNTPOINT ??= ""python __anonymous () {# We check first if it is requested to generate any partition imagesif d.getVar('ENABLE_PARTITIONS_IMAGE') != "1":bb.note('ENABLE_PARTITIONS_IMAGE not enabled')return# -----------------------------------------------------------------------------# Update the partition configuration set by user# -----------------------------------------------------------------------------partitionsconfigflags = d.getVarFlags('PARTITIONS_CONFIG')# The "doc" varflag is special, we don't want to see it herepartitionsconfigflags.pop('doc', None)partitionsconfig = (d.getVar('PARTITIONS_CONFIG') or "").split()# Init image_summary_listimage_summary_list = ''if len(partitionsconfig) > 0:for config in partitionsconfig:for f, v in partitionsconfigflags.items():if config == f:items = v.split(',')if items[0]:if len(items) > 5:raise bb.parse.SkipRecipe('Only image,label,mountpoint,size,type can be specified!')# Make sure that we're dealing with partition image and not rootfs imageif len(items) > 2 and items[2]:# Mount point available, so we're dealing with partition image# PARTITIONS_IMAGE appendingbb.debug(1, "Appending '%s' to PARTITIONS_IMAGE." % items[0])d.appendVar('PARTITIONS_IMAGE', ' ' + items[0])# PARTITIONS_MOUNTPOINT appendingbb.debug(1, "Appending '%s' to PARTITIONS_MOUNTPOINT." % items[2])d.appendVar('PARTITIONS_MOUNTPOINT', ' ' + items[2])# Update IMAGE vars for each partition imageif items[1]:bb.debug(1, "Set UBI_VOLNAME to %s for %s partition image." % (items[1], items[0]))d.setVar('UBI_VOLNAME_pn-%s' % d.expand(items[0]), items[1])if d.expand(items[1])[-2:] != 'fs':bb.debug(1, "Set IMAGE_NAME_SUFFIX to '.%sfs' for %s partition image." % (items[1], items[0]))d.setVar('IMAGE_NAME_SUFFIX_pn-%s' % d.expand(items[0]), '.' + items[1] + 'fs')else:bb.debug(1, "Set IMAGE_NAME_SUFFIX to '.%s' for %s partition image." % (items[1], items[0]))d.setVar('IMAGE_NAME_SUFFIX_pn-%s' % d.expand(items[0]), '.' + items[1])else:bb.fatal('[PARTITIONS_CONFIG] Missing label setting for %s image' % items[0])if items[2]:bb.debug(1, "Set IMAGE_PARTITION_MOUNTPOINT to %s for %s partition image." % (items[2], items[0]))d.setVar('IMAGE_PARTITION_MOUNTPOINT_pn-%s' % d.expand(items[0]), items[2])if items[3]:bb.debug(1, "Set IMAGE_ROOTFS_SIZE to %s for %s partition image." % (items[3], items[0]))d.setVar('IMAGE_ROOTFS_SIZE_pn-%s' % d.expand(items[0]), items[3])else:bb.fatal('[PARTITIONS_CONFIG] Missing size setting for %s image' % items[0])# Manage IMAGE_SUMMARY_LIST configuration according to PARTITION_CONFIG setif d.getVar('ENABLE_IMAGE_LICENSE_SUMMARY') == "1":if not items[2]:# Set '/' as default mountpoint for rootfs in IMAGE_SUMMARY_LISTitems[2] = '/'image_summary_list += items[0] + ':' + items[2] + ';'# Manage multiubi volume list STM32MP_UBI_VOLUMEif bb.utils.contains('IMAGE_FSTYPES', 'stmultiubi', True, False, d) and d.getVar('ENABLE_MULTIVOLUME_UBI') == "1":bb.debug(1, "Appending '%s' image with %s size to STM32MP_UBI_VOLUME." % (items[0], items[3]))d.appendVar('STM32MP_UBI_VOLUME', ' ' + items[0] + ':' + items[3])else:bb.fatal('[PARTITIONS_CONFIG] Missing image setting')break# Reset IMAGE_LIST_SUMMARY with computed partition configurationif d.getVar('ENABLE_IMAGE_LICENSE_SUMMARY') == "1":bb.debug(1, "Set IMAGE_SUMMARY_LIST with configuration: %s." % image_summary_list)d.setVar('IMAGE_SUMMARY_LIST', image_summary_list)# Init partition list from PARTITIONS_IMAGEimage_partitions = (d.getVar('PARTITIONS_IMAGE') or "").split()# -----------------------------------------------------------------------------# Make sure to append the partition build to current image target# -----------------------------------------------------------------------------if len(image_partitions) > 0:# Gather all current taskstasks = filter(lambda k: d.getVarFlag(k, "task", True), d.keys())for task in tasks:# Check that we are dealing with image recipeif task == 'do_image_complete':# Init current image namecurrent_image_name = d.getVar('PN') or ""# Init RAMFS image if anyinitramfs = d.getVar('INITRAMFS_IMAGE') or ""# Init INITRD image if anyinitrd = d.getVar('INITRD_IMAGE') or ""# We need to append partition images generation only to image# that are not one of the defined partitions and not the InitRAMFS image.# Without this check we would create circular dependencyif current_image_name not in image_partitions and current_image_name != initramfs and current_image_name != initrd:for partition in image_partitions:bb.debug(1, "Appending %s image build to 'do_image_complete' depends tasks." % partition)d.appendVarFlag('do_image_complete', 'depends', ' %s:do_image_complete' % partition)bb.debug(1, "Appending 'image_rootfs_image_clean_task' to IMAGE_PREPROCESS_COMMAND.")d.appendVar('IMAGE_PREPROCESS_COMMAND', 'image_rootfs_image_clean_task;')# Manage multiubi volume build enable for current imageif bb.utils.contains('IMAGE_FSTYPES', 'stmultiubi', True, False, d) and d.getVar('ENABLE_MULTIVOLUME_UBI') == "1":bb.debug(1, "Appending 'st_multivolume_ubifs' to IMAGE_POSTPROCESS_COMMAND.")d.appendVar('IMAGE_POSTPROCESS_COMMAND', 'st_multivolume_ubifs;') }image_rootfs_image_clean_task() {bbnote "PARTITIONS_IMAGE"bbnote ">>> ${PARTITIONS_IMAGE}"bbnote "PARTITIONS_MOUNTPOINT"bbnote ">>> ${PARTITIONS_MOUNTPOINT}"unset i jfor img in ${PARTITIONS_IMAGE}; doi=$(expr $i + 1);for part in ${PARTITIONS_MOUNTPOINT}; doj=$(expr $j + 1);if [ $j -eq $i ]; thenbbnote "Expecting to clean folder:"bbnote ">>> ${IMAGE_ROOTFS}/$part"if [ -d ${IMAGE_ROOTFS}/$part ]; thenrm -rf ${IMAGE_ROOTFS}/$part/*bbnote ">>> DONE"elsebbnote ">>> NOT DONE : $part folder doesn't exist in image rootfs"fifidoneunset jdoneunset i }

st-partitions-image.bbclass 整個文件看起來比較長,其實里面大部分都是調(diào)試日志。 總共有幾部分組成:

  • 重要的三個變量
    ENABLE_PARTITIONS_IMAGE:用來控制是否使能生成分區(qū)鏡像,在鏡像bb文件中可以覆蓋此變量控制該class的功能
    PARTITIONS_CONFIG:設(shè)置的分區(qū)配置
    PARTITIONS_IMAGE:分區(qū)鏡像的名字
    PARTITIONS_MOUNTPOINT:分區(qū)鏡像的掛載點

  • 一個匿名函數(shù)
    以PARTITIONS_CONFIG 為輸入,PARTITIONS_IMAGE 和PARTITIONS_MOUNTPOINT 為輸出
    通過bitbake -e fs-mp1a-qt可以先看一下最終的變量值:

  • PARTITIONS_CONFIG=" bootfs vendorfs rootfs userfs" //PARTITIONS_CONFIG[xxxfs] 字段含義 // "${STM32MP_XXFS_IMAGE},${STM32MP_XXFS_LABEL},${STM32MP_XXFS_MOUNTPOINT},${XXFS_PARTITION_SIZE},System"PARTITIONS_CONFIG[bootfs] ?= "st-image-bootfs,boot,/boot,65536,System" PARTITIONS_CONFIG[vendorfs] ?= "st-image-vendorfs,vendorfs,/vendor,16384,FileSystem" PARTITIONS_CONFIG[rootfs] ?= "fs-mp1a-qt-openstlinux-eglfs,rootfs,1253376,FileSystem" PARTITIONS_CONFIG[userfs] ?= "st-image-userfs,userfs,/usr/local,131072,FileSystem"PARTITIONS_IMAGE=" st-image-bootfs st-image-vendorfs st-image-userfs" PARTITIONS_MOUNTPOINT=" /boot /vendor /usr/local"

    下面詳細(xì)分析python __anonymous是怎么處理的:
    輸入變量PARTITIONS_CONFIG:
    PARTITIONS_CONFIG=" bootfs vendorfs rootfs userfs"
    PARTITIONS_CONFIG[bootfs] ?= “st-image-bootfs,boot,/boot,65536,System”
    PARTITIONS_CONFIG[vendorfs] ?= “st-image-vendorfs,vendorfs,/vendor,16384,FileSystem”
    PARTITIONS_CONFIG[rootfs] ?= “fs-mp1a-qt-openstlinux-eglfs,rootfs,1253376,FileSystem”
    PARTITIONS_CONFIG[userfs] ?= “st-image-userfs,userfs,/usr/local,131072,FileSystem”

    partitionsconfigflags:
    bootfs “st-image-bootfs,boot,/boot,65536,System”
    vendorfs “st-image-vendorfs,vendorfs,/vendor,16384,FileSystem”
    rootfs “fs-mp1a-qt-openstlinux-eglfs,rootfs,1253376,FileSystem”
    userfs “st-image-userfs,userfs,/usr/local,131072,FileSystem”

    partitionsconfig:
    bootfs vendorfs rootfs userfs

    for config in partitionsconfig:for f, v in partitionsconfigflags.items():if config == f:items = v.split(',')

    上面這段判斷可以知道(以第一個bootfs為例) items= {st-image-bootfs boot /boot 65536 System }

    if len(items) > 2 and items[2]:# Mount point available, so we're dealing with partition image# PARTITIONS_IMAGE appendingbb.debug(1, "Appending '%s' to PARTITIONS_IMAGE." % items[0])d.appendVar('PARTITIONS_IMAGE', ' ' + items[0])# PARTITIONS_MOUNTPOINT appendingbb.debug(1, "Appending '%s' to PARTITIONS_MOUNTPOINT." % items[2])d.appendVar('PARTITIONS_MOUNTPOINT', ' ' + items[2])

    如果items大于2且items[2]存在,則
    PARTITIONS_IMAGE += items[0] //items[0] = st-image-bootfs
    PARTITIONS_MOUNTPOINT += items[2] //items[2] = /boot

    如此循環(huán)下來:
    PARTITIONS_IMAGE =" st-image-bootfs st-image-vendorfs fs-mp1a-qt-openstlinux-eglfs st-image-userfs"
    PARTITIONS_MOUNTPOINT=" /boot /vendor rootfs /usr/local"

    這里PARTITIONS_MOUNTPOINT 和我們通過實際bitbake -e看到的環(huán)境變量對不上,我們接著往下分析

    # Update IMAGE vars for each partition imageif items[1]:bb.debug(1, "Set UBI_VOLNAME to %s for %s partition image." % (items[1], items[0]))d.setVar('UBI_VOLNAME_pn-%s' % d.expand(items[0]), items[1])if d.expand(items[1])[-2:] != 'fs':bb.debug(1, "Set IMAGE_NAME_SUFFIX to '.%sfs' for %s partition image." % (items[1], items[0]))d.setVar('IMAGE_NAME_SUFFIX_pn-%s' % d.expand(items[0]), '.' + items[1] + 'fs')else:bb.debug(1, "Set IMAGE_NAME_SUFFIX to '.%s' for %s partition image." % (items[1], items[0]))d.setVar('IMAGE_NAME_SUFFIX_pn-%s' % d.expand(items[0]), '.' + items[1])else:bb.fatal('[PARTITIONS_CONFIG] Missing label setting for %s image' % items[0])if items[2]:bb.debug(1, "Set IMAGE_PARTITION_MOUNTPOINT to %s for %s partition image." % (items[2], items[0]))d.setVar('IMAGE_PARTITION_MOUNTPOINT_pn-%s' % d.expand(items[0]), items[2])if items[3]:bb.debug(1, "Set IMAGE_ROOTFS_SIZE to %s for %s partition image." % (items[3], items[0]))d.setVar('IMAGE_ROOTFS_SIZE_pn-%s' % d.expand(items[0]), items[3])else:bb.fatal('[PARTITIONS_CONFIG] Missing size setting for %s image' % items[0])
    • 如果items[1]存在(以第一個bootfs為例)
      UBI_VOLNAME_pn-st-image-bootfs=/boot
    • 如果items[1]的最后2位不是fs結(jié)尾則手動添加fs結(jié)尾以后設(shè)置IMAGE_NAME_SUFFIX_pn變量
      IMAGE_NAME_SUFFIX_pn-st-image-bootfs=.boot
    • 如果items[2]存在
      IMAGE_PARTITION_MOUNTPOINT_pn-st-image-bootfs=/boot
    • 如果items[3]存在
      IMAGE_ROOTFS_SIZE_pn-st-image-bootfs=65536
    # Manage IMAGE_SUMMARY_LIST configuration according to PARTITION_CONFIG setif d.getVar('ENABLE_IMAGE_LICENSE_SUMMARY') == "1":if not items[2]:# Set '/' as default mountpoint for rootfs in IMAGE_SUMMARY_LISTitems[2] = '/'image_summary_list += items[0] + ':' + items[2] + ';'# Manage multiubi volume list STM32MP_UBI_VOLUMEif bb.utils.contains('IMAGE_FSTYPES', 'stmultiubi', True, False, d) and d.getVar('ENABLE_MULTIVOLUME_UBI') == "1":bb.debug(1, "Appending '%s' image with %s size to STM32MP_UBI_VOLUME." % (items[0], items[3]))d.appendVar('STM32MP_UBI_VOLUME', ' ' + items[0] + ':' + items[3])# Reset IMAGE_LIST_SUMMARY with computed partition configurationif d.getVar('ENABLE_IMAGE_LICENSE_SUMMARY') == "1":bb.debug(1, "Set IMAGE_SUMMARY_LIST with configuration: %s." % image_summary_list)d.setVar('IMAGE_SUMMARY_LIST', image_summary_list)
    • 如果環(huán)境變量ENABLE_IMAGE_LICENSE_SUMMARY被設(shè)置
      image_summary_list += st-image-bootfs:/boot;
      循環(huán)下來image_summary_list=“st-image-bootfs:/boot;st-image-vendorfs:/vendor;fs-mp1a-qt-openstlinux-eglfs:rootfs;st-image-userfs:/usr/local;”
      IMAGE_SUMMARY_LIST = image_summary_list

    • 如果IMAGE_FSTYPES 中包含stmultiubi類型且ENABLE_MULTIVOLUME_UBI變量被設(shè)置
      STM32MP_UBI_VOLUME +=" st-image-bootfs:65536"
      循環(huán)下來STM32MP_UBI_VOLUME=" st-image-bootfs:65536 st-image-vendorfs:16384 fs-mp1a-qt-openstlinux-eglfs:1253376 st-image-userfs:131072"

    這里循環(huán)結(jié)束,總結(jié)一下設(shè)置了哪些變量:
    PARTITIONS_IMAGE =" st-image-bootfs st-image-vendorfs fs-mp1a-qt-openstlinux-eglfs st-image-userfs"
    PARTITIONS_MOUNTPOINT=" /boot /vendor rootfs /usr/local"

    UBI_VOLNAME_pn-st-image-bootfs=/boot IMAGE_NAME_SUFFIX_pn-st-image-bootfs=.boot IMAGE_PARTITION_MOUNTPOINT_pn-st-image-bootfs=/boot IMAGE_ROOTFS_SIZE_pn-st-image-bootfs=65536

    IMAGE_SUMMARY_LIST=“st-image-bootfs:/boot;st-image-vendorfs:/vendor;fs-mp1a-qt-openstlinux-eglfs:rootfs;st-image-userfs:/usr/local;”
    STM32MP_UBI_VOLUME=" st-image-bootfs:65536 st-image-vendorfs:16384 fs-mp1a-qt-openstlinux-eglfs:1253376 st-image-userfs:131072"

    繼續(xù)分析

    image_partitions = (d.getVar('PARTITIONS_IMAGE') or "").split()if len(image_partitions) > 0:# Gather all current taskstasks = filter(lambda k: d.getVarFlag(k, "task", True), d.keys())for task in tasks:# Check that we are dealing with image recipeif task == 'do_image_complete':# Init current image namecurrent_image_name = d.getVar('PN') or ""# Init RAMFS image if anyinitramfs = d.getVar('INITRAMFS_IMAGE') or ""# Init INITRD image if anyinitrd = d.getVar('INITRD_IMAGE') or ""# We need to append partition images generation only to image# that are not one of the defined partitions and not the InitRAMFS image.# Without this check we would create circular dependencyif current_image_name not in image_partitions and current_image_name != initramfs and current_image_name != initrd:for partition in image_partitions:bb.debug(1, "Appending %s image build to 'do_image_complete' depends tasks." % partition)d.appendVarFlag('do_image_complete', 'depends', ' %s:do_image_complete' % partition)bb.debug(1, "Appending 'image_rootfs_image_clean_task' to IMAGE_PREPROCESS_COMMAND.")d.appendVar('IMAGE_PREPROCESS_COMMAND', 'image_rootfs_image_clean_task;')# Manage multiubi volume build enable for current imageif bb.utils.contains('IMAGE_FSTYPES', 'stmultiubi', True, False, d) and d.getVar('ENABLE_MULTIVOLUME_UBI') == "1":bb.debug(1, "Appending 'st_multivolume_ubifs' to IMAGE_POSTPROCESS_COMMAND.")d.appendVar('IMAGE_POSTPROCESS_COMMAND', 'st_multivolume_ubifs;')

    image_partitions = [“st-image-bootfs”, “st-image-vendorfs”, “fs-mp1a-qt-openstlinux-eglfs”, “st-image-userfs” ]
    找到所有非initramfs 、initrd和 image_partitions中包含的image 的 do_image_complete的task,設(shè)置他們的依賴:
    do_image_complete[depends] = st-image-bootfs:do_image_complete
    do_image_complete[depends] = st-image-vendorfs:do_image_complete
    do_image_complete[depends] = fs-mp1a-qt-openstlinux-eglfs:do_image_complete
    do_image_complete[depends] = st-image-userfs:do_image_complete
    IMAGE_POSTPROCESS_COMMAND+=st_multivolume_ubifs
    到這里,可以看到所有的iamge 菜譜生成進(jìn)行必須先等image_partitions 中的鏡像生成以后才可以生成。

    這部分分析結(jié)束,還有個疑問:bitbake中的變量里面沒有rootfs相關(guān)的設(shè)置,但是分析下來是有的,這里等后續(xù)image生成流程都分析完了在回頭看看是不是那里過濾掉了。
    PARTITIONS_IMAGE=" st-image-bootfs st-image-vendorfs st-image-userfs"
    PARTITIONS_MOUNTPOINT=" /boot /vendor /usr/local"

    PARTITIONS_IMAGE =" st-image-bootfs st-image-vendorfs fs-mp1a-qt-openstlinux-eglfs st-image-userfs"
    PARTITIONS_MOUNTPOINT=" /boot /vendor rootfs /usr/local"

  • 一個 task
    image_rootfs_image_clean_task
  • 最后還生名了一個task,里面比較簡單:

    for img in ${PARTITIONS_IMAGE}; doi=$(expr $i + 1);for part in ${PARTITIONS_MOUNTPOINT}; doj=$(expr $j + 1);if [ $j -eq $i ]; thenbbnote "Expecting to clean folder:"bbnote ">>> ${IMAGE_ROOTFS}/$part"if [ -d ${IMAGE_ROOTFS}/$part ]; thenrm -rf ${IMAGE_ROOTFS}/$part/*bbnote ">>> DONE"elsebbnote ">>> NOT DONE : $part folder doesn't exist in image rootfs"fifidoneunset jdone

    最終效果就是把tmp-glibc/work/fsmp1a-ostl-linux-gnueabi/fs-mp1a-qt/1.0-r0/rootfs/boot/*刪除(以bootfs為例)

    DONE

    總結(jié)

    以上是生活随笔為你收集整理的yocto machine class解析之st-partitions-image的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。