yocto machine class解析之flashlayout-stm32mp

news2024/11/22 23:18:23

yocto machine class解析之flashlayout-stm32mp

上一篇文章中我们详细介绍了st-partitions-image class。里面根据配置生成了许多的分区镜像以及分区镜像的一些参数设置。本章节介绍的flashlayout class就会根据上面生成的这些参数来生成特定的.tsv刷机文件供ST的刷机工具使用。

flashlayout介绍

本小节先介绍一些flashlayout tsv文件的格式和说明,方便后续分析具体的实现过程,下面是
build-openstlinuxeglfs-fsmp1a/tmp-glibc/deploy/images/fsmp1a/flashlayout_fs-mp1a-qt/trusted/目录下的
FlashLayout_sdcard_stm32mp157a-fsmp1a-trusted.tsv文件:
在这里插入图片描述

  • Opt: 选项字段可以设置为"-“()、“P”(烧写)、“D”(删除)或"E”(不更新) “PE”(不更新)“PD”(删除并更新)
  • Id: 会根据这个 id 来决定烧写分区
  • Name: 分区名字
  • Type: 指定烧写的类型,仅 uboot 使用。
  • IP:指定烧写的设备类型与编号,比如 emmc0、 emmc1、 nand0 等, 如果 opt 为‘-’ ,那么此字段就为 none
  • Offset:分区的起始位置,表示需要偏移的字节数。
  • Binary: 要烧录的文件

flashlayout-stm32mp class分析

下面我们来详细分析flashlayout-stm32mp class的具体实现,flashlayout-stm32mp文件非常长,一点点过把。

介绍

flashlayout的刷机文件可以通过静态设置也可以通过动态生成,使用ENABLE_FLASHLAYOUT_DEFAULT变量来控制。

  • 如果设置为静态设置的话需要自己先改好一个falshlayout tsv文件,然后设置这个文件的路径到变量FLASHLAYOUT_DEFAULT_SRC,然后一起打包到deploy的生成镜像里面。

  • 动态生成的话需要配置一系列变量,其中tsv文件命名格式所需变量如下:
    <FLASHLAYOUT_BASENAME>[<FLASHLAYOUT_CONFIG_LABEL>][<FLASHLAYOUT_TYPE_LABEL>-FLASHLAYOUT_BOOTSCHEME_LABEL].<FLASHLAYOUT_SUFFIX>
    其中FLASHLAYOUT_BASENAME 默认是 ‘FlashLayout’,FLASHLAYOUT_SUFFIX默认是’tsv’,改写下上面的格式:
    FlashLayout[<FLASHLAYOUT_CONFIG_LABEL>][<FLASHLAYOUT_TYPE_LABEL>-FLASHLAYOUT_BOOTSCHEME_LABEL].tsv
    如上面展示的FlashLayout_sdcard_stm32mp157a-fsmp1a-trusted.tsv可以看到:
    FLASHLAYOUT_CONFIG_LABEL:sdcard
    FLASHLAYOUT_TYPE_LABEL:stm32mp157a
    FLASHLAYOUT_BOOTSCHEME_LABEL:trusted

  • tsv文件所需格式变量:
    <FLASHLAYOUT_PARTITION_ENABLE>(Opt)
    <FLASHLAYOUT_PARTITION_ID>(Id)
    <FLASHLAYOUT_PARTITION_LABEL>(Name)
    <FLASHLAYOUT_PARTITION_TYPE>(Type)
    <FLASHLAYOUT_PARTITION_DEVICE>(IP)
    <FLASHLAYOUT_PARTITION_OFFSET>(Offset)
    <FLASHLAYOUT_PARTITION_BIN2LOAD>(Binary)
    <FLASHLAYOUT_PARTITION_SIZE>: 上面FLASHLAYOUT_PARTITION_OFFSET本来应该手动指定,但是如果配置了FLASHLAYOUT_PARTITION_SIZE这个变量则可以根据分区镜像的大小结合DEVICE_ALIGNMENT_SIZE_指定特定的对齐大小来自动计算下一个分区的OFFSET( 就是本分区的FLASHLAYOUT_PARTITION_DEVICE)

#
# --------------------
# Static configuration
# --------------------
# Set ENABLE_FLASHLAYOUT_DEFAULT to '1'.
# Configure FLASHLAYOUT_DEFAULT_SRC with the static flashlayout file locations.
#
# Configuration example (machine file or local.conf):
#   ENABLE_FLASHLAYOUT_DEFAULT = "1"
#   FLASHLAYOUT_DEFAULT_SRC = "files/flashlayouts/FlashLayout_sdcard_stm32mp157c-ev1_sample.tsv"
#
# ---------------------
# Dynamic configuration
# ---------------------
# Set ENABLE_FLASHLAYOUT_DEFAULT to '0'.
# In order to automatically generate flashlayout files as well formated TSV file
# there are some variables to configure.
#
# Naming:
#   <FLASHLAYOUT_BASENAME>[_<FLASHLAYOUT_CONFIG_LABEL>][_<FLASHLAYOUT_TYPE_LABEL>-FLASHLAYOUT_BOOTSCHEME_LABEL].<FLASHLAYOUT_SUFFIX>
#
#   FLASHLAYOUT_BASENAME
#       Default to 'FlashLayout'
#   FLASHLAYOUT_CONFIG_LABEL
#       Set from FLASHLAYOUT_CONFIG_LABELS list (without any '_' in config labels)
#   FLASHLAYOUT_TYPE_LABEL
#       Set from FLASHLAYOUT_TYPE_LABELS list
#   FLASHLAYOUT_BOOTSCHEME_LABEL
#       Set from FLASHLAYOUT_BOOTSCHEME_LABELS list (without any '_' in bootscheme labels)
# Note that both are appended only when FLASHLAYOUT_TYPE_LABELS and FLASHLAYOUT_BOOTSCHEME_LABELS contain more than two labels.
#   FLASHLAYOUT_SUFFIX
#       Default to 'tsv'
#
# File content structure:
#   Opt     Id      Name    Type    IP      Offset  Binary
#   <FLASHLAYOUT_PARTITION_ENABLE>
#           <FLASHLAYOUT_PARTITION_ID>
#                   <FLASHLAYOUT_PARTITION_LABEL>
#                           <FLASHLAYOUT_PARTITION_TYPE>
#                                   <FLASHLAYOUT_PARTITION_DEVICE>
#                                           <FLASHLAYOUT_PARTITION_OFFSET>
#                                                   <FLASHLAYOUT_PARTITION_BIN2LOAD>
#
# Specific configuration:
#   FLASHLAYOUT_PARTITION_SIZE
#       If configured, it allows to compute the next offset to apply in
#       flashlayout file for the following partition.
#       Note that according to the device in use for the partition a specific
#       alignment size can be specified through DEVICE_ALIGNMENT_SIZE_<device>
#       var where <device> is the current FLASHLAYOUT_PARTITION_DEVICE
#
# Note that override is manage for 'FLASHLAYOUT_PARTITION_LABELS' list with:
#   - <bootscheme-label> from FLASHLAYOUT_BOOTSCHEME_LABELS' list
#   - <config-label> from 'FLASHLAYOUT_CONFIG_LABELS' list
# Priority assignment is:
#   It means the 'FLASHLAYOUT_PARTITION_LABELS' value can be overriden by setting:
#   FLASHLAYOUT_PARTITION_LABELS_<bootscheme-label>_<config-label>
#   FLASHLAYOUT_PARTITION_LABELS_<bootscheme-label>
#   FLASHLAYOUT_PARTITION_LABELS_<config-label>
#   FLASHLAYOUT_PARTITION_LABELS
#
# Another override mechanism is also implemented for all other partition variables:
#   FLASHLAYOUT_PARTITION_ENABLE
#   FLASHLAYOUT_PARTITION_ID
#   FLASHLAYOUT_PARTITION_TYPE
#   FLASHLAYOUT_PARTITION_DEVICE
#   FLASHLAYOUT_PARTITION_OFFSET
#   FLASHLAYOUT_PARTITION_BIN2LOAD
# We can override these variable with:
#   - <config-label> from 'FLASHLAYOUT_CONFIG_LABELS' list
#   - <bootscheme-label> from 'FLASHLAYOUT_BOOTSCHEME_LABELS' list
#   - <partition-label> from 'FLASHLAYOUT_PARTITION_LABELS' list
# Priority assignment is:
#   FLASHLAYOUT_PARTITION_xxx_<bootscheme-label>_<config-label>_<partition-label>
#   FLASHLAYOUT_PARTITION_xxx_<bootscheme-label>_<config-label>
#   FLASHLAYOUT_PARTITION_xxx_<bootscheme-label>_<partition-label>
#   FLASHLAYOUT_PARTITION_xxx_<bootscheme-label>
#   FLASHLAYOUT_PARTITION_xxx_<config-label>_<partition-label>
#   FLASHLAYOUT_PARTITION_xxx_<config-label>
#   FLASHLAYOUT_PARTITION_xxx_<partition-label>
#   FLASHLAYOUT_PARTITION_xxx
# -----------------------------------------------------------------------------

变量定义

上面介绍部分大概对生成flashlayout tsv文件有了一定了解,下面看看相关的变量初始化定义:


# Configure flashlayout file generation
ENABLE_FLASHLAYOUT_CONFIG ??= "1"
# Configure direct use of flashlayout file without automatic file generation
ENABLE_FLASHLAYOUT_DEFAULT ??= "0"
# Configure path for provided flashlayout file
FLASHLAYOUT_DEFAULT_SRC ??= ""
# Configure flashlayout file name default format
FLASHLAYOUT_BASENAME ??= "FlashLayout"
FLASHLAYOUT_SUFFIX   ??= "tsv"
# Configure flashlayout file generation for stm32wrapper4dbg
ENABLE_FLASHLAYOUT_CONFIG_WRAPPER4DBG ??= "0"

# Configure folders for flashlayout file generation
FLASHLAYOUT_DEPLOYDIR ?= "${DEPLOY_DIR}/images/${MACHINE}"
FLASHLAYOUT_TOPDIR ?= "${WORKDIR}/flashlayout-destdir/"
FLASHLAYOUT_SUBDIR ?= "flashlayout_${PN}"
FLASHLAYOUT_DESTDIR = "${FLASHLAYOUT_TOPDIR}/${FLASHLAYOUT_SUBDIR}"

# Init bootscheme and config labels
FLASHLAYOUT_BOOTSCHEME_LABELS ??= ""
FLASHLAYOUT_CONFIG_LABELS ??= ""
# Init partition image list (used to configure partitions)
FLASHLAYOUT_PARTITION_IMAGES ??= ""
# Init partition and type labels
#   Note: possible override with bootscheme and/or config
FLASHLAYOUT_PARTITION_LABELS   ??= ""
FLASHLAYOUT_TYPE_LABELS ??= ""
# Init flashlayout partition vars
#   Note: possible override with bootscheme and/or config and/or partition
FLASHLAYOUT_PARTITION_ENABLE ??= ""
FLASHLAYOUT_PARTITION_ID ??= ""
FLASHLAYOUT_PARTITION_TYPE ??= ""
FLASHLAYOUT_PARTITION_DEVICE ??= ""
FLASHLAYOUT_PARTITION_OFFSET ??= ""
FLASHLAYOUT_PARTITION_BIN2LOAD ??= ""
FLASHLAYOUT_PARTITION_SIZE ??= ""
FLASHLAYOUT_PARTITION_REPLACE_PATTERNS ??= ""

可以看到ENABLE_FLASHLAYOUT_DEFAULT ??= “0” 即默认使用动态生成flashlayout文件,同时初始化了一系列介绍部分提及到的变量,还可以看到配置了默认flashlayout 的存储路径是“${DEPLOY_DIR}/images/${MACHINE}”下面
工作路径是“${WORKDIR}/flashlayout-destdir/flashlayout_${PN}”,如下所示:

在这里插入图片描述

匿名函数分析

下面开始分析出现的第一个函数。
可以看到这个函数似曾相识,在上一篇分析st-partitions-image class中的匿名函数也长的类似,同样用到了PARTITIONS_CONFIG 变量,这个变量的具体内容参考上一节st-partitions-image直接复制过来:
PARTITIONS_CONFIG=" bootfs vendorfs rootfs userfs"
//PARTITIONS_CONFIG[xxxfs] 字段含义
// “ S T M 32 M P X X F S I M A G E , {STM32MP_XXFS_IMAGE}, STM32MPXXFSIMAGE,{STM32MP_XXFS_LABEL}, S T M 32 M P X X F S M O U N T P O I N T , {STM32MP_XXFS_MOUNTPOINT}, STM32MPXXFSMOUNTPOINT,{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”

总结下面函数干的事情就是先找到所有do_image_complete 的task,然后过滤掉initrd ramfs bootfs vendorfs rootfs userfs 这几个,
添加一个do_create_flashlayout_config task,执行时机在 do_build 和 do_image_complete中间,执行do_create_flashlayout_config之前还要先执行flashlayout_partition_image_config函数
do_create_flashlayout_config[prefuncs] = flashlayout_partition_image_config


python __anonymous () {
    # -----------------------------------------------------------------------------
    # Make sure to add the flashlayout file creation after ROOTFS build
    # So we should identify image ROOTFS build and only the ROOTFS (for now)
    # As we know that PARTITIONS may be built as part of ROOTFS build, let's
    # avoid amending the partition images
    # -----------------------------------------------------------------------------
    if d.getVar('ENABLE_FLASHLAYOUT_CONFIG') == "1":
        # Gather all current tasks
        tasks = filter(lambda k: d.getVarFlag(k, "task", True), d.keys())
        for task in tasks:
            # Check that we are dealing with image recipe
            if task == 'do_image_complete':
                # Init current image name
                current_image_name = d.getVar('PN') or ""
                # Init RAMFS image if any
                initramfs = d.getVar('INITRAMFS_IMAGE') or ""
                # Init INITRD image if any
                initrd = d.getVar('INITRD_IMAGE') or ""
                # Init partition list from PARTITIONS_CONFIG
                image_partitions = []
                # Append image_partitions list with all configured partition images:

                partitionsconfigflags = d.getVarFlags('PARTITIONS_CONFIG')
                # The "doc" varflag is special, we don't want to see it here
                partitionsconfigflags.pop('doc', None)
                partitionsconfig = (d.getVar('PARTITIONS_CONFIG') or "").split()
                if len(partitionsconfig) > 0:
                    for config in partitionsconfig:
                        for f, v in partitionsconfigflags.items():
                            if config == f:
                                items = v.split(',')
                                # Make sure about PARTITIONS_CONFIG contents
                                if items[0] and len(items) > 5:
                                    bb.fatal('[PARTITIONS_CONFIG] Only image,label,mountpoint,size,type can be specified!')
                                # Make sure that we're dealing with partition image and not rootfs image
                                if len(items) > 2 and items[2]:
                                    # Mount point is available, so we're dealing with partition image
                                    # Append image to image_partitions list
                                    image_partitions.append(d.expand(items[0]))
                                break

                # We need to clearly identify ROOTFS build, not InitRAMFS/initRD one (if any), not partition one either
                if current_image_name not in image_partitions and current_image_name != initramfs and current_image_name != initrd:
                    # We add the flashlayout file creation task just after the do_image_complete for ROOTFS build
                    bb.build.addtask('do_create_flashlayout_config', 'do_build', 'do_image_complete', d)
                    # We add also the function that feeds the FLASHLAYOUT_PARTITION_* vars from PARTITIONS_CONFIG
                    d.appendVarFlag('do_create_flashlayout_config', 'prefuncs', ' flashlayout_partition_image_config')
}

do_create_flashlayout_config任务

上面知道每个image的bb都添加了一个do_create_flashlayout_config 任务和flashlayout_partition_image_config函数,那么下面的重点自然就是这两部分了。先从flashlayout_partition_image_config开始

flashlayout_partition_image_config

flashlayout_partition_image_config同样用到了PARTITIONS_CONFIG变量
以PARTITIONS_CONFIG[bootfs] ?= “st-image-bootfs,boot,/boot,65536,System” 为例, 实际做事如下:
FLASHLAYOUT_PARTITION_IMAGES +=boot
FLASHLAYOUT_PARTITION_BIN2LOAD_boot = st-image-bootfs + "-${DISTRO}-${MACHINE}.ext4
FLASHLAYOUT_PARTITION_SIZE_boot = 65536
FLASHLAYOUT_PARTITION_TYPE_boot = System
FLASHLAYOUT_PARTITION_ID_boot = $part_id
part_id 区分bin(从4开始)还是其他(从33开始)动态自增

PARTITIONS_CONFIG里面的其他镜像以此类推,那么下面这个图里还没有确定的就是P mmc0 0x00284400这几个部分了,
在这里插入图片描述继续看do_create_flashlayout_config任务


python flashlayout_partition_image_config() {
    """
    Set the different flashlayout partition vars for the configure partition
    images.
    Based on PARTITIONS_CONFIG, feed:
        FLASHLAYOUT_PARTITION_IMAGES
        FLASHLAYOUT_PARTITION_ID_
        FLASHLAYOUT_PARTITION_TYPE_
        FLASHLAYOUT_PARTITION_SIZE_
        FLASHLAYOUT_PARTITION_BIN2LOAD_
    """

    partitionsconfigflags = d.getVarFlags('PARTITIONS_CONFIG')
    # The "doc" varflag is special, we don't want to see it here
    partitionsconfigflags.pop('doc', None)
    partitionsconfig = (d.getVar('PARTITIONS_CONFIG') or "").split()

    if len(partitionsconfig) > 0:
        # Init default partition id for binary type and other
        id_bin = 4
        id_oth = 33
        for config in partitionsconfig:
            for f, v in partitionsconfigflags.items():
                if config == f:
                    items = v.split(',')
                    # Make sure about PARTITIONS_CONFIG contents
                    if items[0] and len(items) > 5:
                        bb.fatal('[PARTITIONS_CONFIG] Only image,label,mountpoint,size,type can be specified!')
                    if items[1]:
                        bb.debug(1, "Appending %s to FLASHLAYOUT_PARTITION_IMAGES." % items[1])
                        d.appendVar('FLASHLAYOUT_PARTITION_IMAGES', ' ' + items[1])
                    else:
                        bb.fatal('[PARTITIONS_CONFIG] Missing image label setting')
                    # Init flashlayout label
                    fl_label = d.expand(items[1])
                    if items[2] == '':
                        # There is no mountpoint specified, so we apply rootfs image format
                        bb.debug(1, "Set FLASHLAYOUT_PARTITION_BIN2LOAD_%s to %s." % (fl_label, items[0] + "-${MACHINE}.ext4"))
                        d.setVar('FLASHLAYOUT_PARTITION_BIN2LOAD_%s' % fl_label, items[0] + "-${MACHINE}.ext4")
                    else:
                        bb.debug(1, "Set FLASHLAYOUT_PARTITION_BIN2LOAD_%s to %s." % (fl_label, items[0] + "-${DISTRO}-${MACHINE}.ext4"))
                        d.setVar('FLASHLAYOUT_PARTITION_BIN2LOAD_%s' % fl_label, items[0] + "-${DISTRO}-${MACHINE}.ext4")
                    if items[3]:
                        bb.debug(1, "Set FLASHLAYOUT_PARTITION_SIZE_%s to %s." % (fl_label, items[3]))
                        d.setVar('FLASHLAYOUT_PARTITION_SIZE_%s' % fl_label, items[3])
                    else:
                        bb.fatal('[PARTITIONS_CONFIG] Missing PARTITION_SIZE setting for % label' % fl_label)
                    if items[4]:
                        bb.debug(1, "Set FLASHLAYOUT_PARTITION_TYPE_%s to %s." % (fl_label, items[4]))
                        d.setVar('FLASHLAYOUT_PARTITION_TYPE_%s' % fl_label, items[4])
                        # Compute partition id according to type set
                        if items[4] == 'Binary':
                            part_id = '0x{0:0{1}X}'.format(id_bin, 2)
                            id_bin = id_bin + 1
                        else:
                            part_id = '0x{0:0{1}X}'.format(id_oth, 2)
                            id_oth = id_oth + 1
                        bb.debug(1, "Set FLASHLAYOUT_PARTITION_ID_%s to %s." % (fl_label, part_id))
                        d.setVar('FLASHLAYOUT_PARTITION_ID_%s' % fl_label, "%s" % part_id)
                    else:
                        bb.fatal('[PARTITIONS_CONFIG] Missing PARTITION_TYPE setting for % label' % fl_label)
                    break
}

do_create_flashlayout_config

在分析do_create_flashlayout_config task具体任务之前先看一下跟task相关的一些设置:

python do_create_flashlayout_config() {
}

do_create_flashlayout_config[dirs] = "${FLASHLAYOUT_DESTDIR}"

FLASHLAYOUT_DEPEND_TASKS ?= ""
do_create_flashlayout_config[depends] += "${FLASHLAYOUT_DEPEND_TASKS}"

SSTATETASKS += "do_create_flashlayout_config"
do_create_flashlayout_config[cleandirs] = "${FLASHLAYOUT_TOPDIR}"
do_create_flashlayout_config[sstate-inputdirs] = "${FLASHLAYOUT_TOPDIR}"
do_create_flashlayout_config[sstate-outputdirs] = "${FLASHLAYOUT_DEPLOYDIR}/"


FLASHLAYOUT_LABELS_VARS = "CONFIG_LABELS PARTITION_LABELS TYPE_LABELS"
FLASHLAYOUT_LABELS_OVERRIDES = "${@' '.join('%s %s %s_%s' % (b, c, b, c) for b in d.getVar('FLASHLAYOUT_BOOTSCHEME_LABELS').split() for c in d.getVar('FLASHLAYOUT_CONFIG_LABELS').split())}"
do_create_flashlayout_config[vardeps] += "${@' '.join(['FLASHLAYOUT_%s_%s' % (v, o) for v in d.getVar('FLASHLAYOUT_LABELS_VARS').split() for o in d.getVar('FLASHLAYOUT_LABELS_OVERRIDES').split()])}"

FLASHLAYOUT_PARTITION_VARS = "ENABLE ID TYPE DEVICE OFFSET BIN2LOAD SIZE REPLACE_PATTERNS"
FLASHLAYOUT_PARTITION_CONFIGURED = "${@" ".join(map(lambda o: "%s" % d.getVar("FLASHLAYOUT_PARTITION_LABELS_%s" % o), d.getVar('FLASHLAYOUT_LABELS_OVERRIDES').split()))}"
FLASHLAYOUT_PARTITION_OVERRIDES = "${@' '.join('%s %s %s_%s' % (o, p, o, p) for o in d.getVar('FLASHLAYOUT_LABELS_OVERRIDES').split() for p in d.getVar('FLASHLAYOUT_PARTITION_CONFIGURED').split())}"
do_create_flashlayout_config[vardeps] += "${@' '.join(['FLASHLAYOUT_PARTITION_%s_%s' % (v, o) for v in d.getVar('FLASHLAYOUT_PARTITION_VARS').split() for o in d.getVar('FLASHLAYOUT_PARTITION_OVERRIDES').split()])}"

FLASHLAYOUT_DEVICE_VARS = "ALIGNMENT_SIZE BOARD_ENABLE START_OFFSET"
FLASHLAYOUT_PARTITION_DEVICE_CONFIGURED = "${@" ".join(map(lambda p: "%s" % d.getVar("DEVICE_%s" % p), d.getVar('DEVICE_STORAGE_NAMES').split()))}"
do_create_flashlayout_config[vardeps] += "${@' '.join(['DEVICE_%s_%s' % (v, o) for v in d.getVar('FLASHLAYOUT_DEVICE_VARS').split() for o in d.getVar('FLASHLAYOUT_PARTITION_DEVICE_CONFIGURED').split()])}"

指定do_create_flashlayout_config 任务的

  • 工作路径为“${WORKDIR}/flashlayout-destdir/flashlayout_${PN}”
  • depends依赖(暂时为空)
  • SSTATETASKS 添加上do_create_flashlayout_config任务,同时指定共享状态的工作路径。
  • 设置do_create_flashlayout_config会用到的环境变量依赖列表

下面分析具体的do_create_flashlayout_config任务主体函数


python do_create_flashlayout_config() {
    import re
    import shutil

    # We check first if it is requested to generate any flashlayout files
    if d.getVar("ENABLE_FLASHLAYOUT_CONFIG") != "1":
        bb.note('ENABLE_FLASHLAYOUT_CONFIG not enabled')
        return

    # Create destination folder for flashlayout files
    bb.utils.remove(d.getVar('FLASHLAYOUT_DESTDIR'), recurse=True)
    bb.utils.mkdirhier(d.getVar('FLASHLAYOUT_DESTDIR'))

    # We check if user as define a static flashlayout file to use instead of dynamic generation
    if d.getVar("ENABLE_FLASHLAYOUT_DEFAULT") == "1":
        bb.note('ENABLE_FLASHLAYOUT_DEFAULT enabled')
        flashlayout_src = d.getVar("FLASHLAYOUT_DEFAULT_SRC")
        if not flashlayout_src:
            bb.fatal("FLASHLAYOUT_DEFAULT_SRC not defined, please set a proper value")
        if not flashlayout_src.strip():
            bb.fatal("No static flashlayout file configured, nothing to do")
        for fl_src in flashlayout_src.split():
            found, f = flashlayout_search(d, fl_src)
            if found:
                flashlayout_staticname=os.path.basename(f)
                flashlayout_file = os.path.join(d.getVar('FLASHLAYOUT_DESTDIR'), flashlayout_staticname)
                shutil.copy2(f, flashlayout_file)
                bb.note('Copy %s to output file %s' % (f, flashlayout_file))
            else:
                bb.fatal("Configure static file: %s not found" % fl_src)
        return

    # Set bootschemes for partition var override configuration
    bootschemes = d.getVar('FLASHLAYOUT_BOOTSCHEME_LABELS')
    if not bootschemes:
        bb.fatal("FLASHLAYOUT_BOOTSCHEME_LABELS not defined, nothing to do")
    if not bootschemes.strip():
        bb.fatal("No bootschemes, nothing to do")
    # Make sure there is no '_' in FLASHLAYOUT_BOOTSCHEME_LABELS
    for bootscheme in bootschemes.split():
        if re.match('.*_.*', bootscheme):
            bb.fatal("Please remove all '_' for bootschemes defined in FLASHLAYOUT_BOOTSCHEME_LABELS")
    bb.note('FLASHLAYOUT_BOOTSCHEME_LABELS: %s' % bootschemes)

    for bootscheme in bootschemes.split():
        bb.note('*** Loop for bootscheme label: %s' % bootscheme)
        # Get the different flashlayout config label
        configs = expand_var('FLASHLAYOUT_CONFIG_LABELS', bootscheme, '', '', d)
        # Make sure there is no '_' in FLASHLAYOUT_CONFIG_LABELS
        for config in configs.split():
            if re.match('.*_.*', config):
                bb.fatal("Please remove all '_' for configs defined in FLASHLAYOUT_CONFIG_LABELS")
        bb.note('FLASHLAYOUT_CONFIG_LABELS: %s' % configs)

        if configs.strip() == 'none':
            bb.note("FLASHLAYOUT_CONFIG_LABELS is none, so no flashlayout file to generate.")
            continue
        # Create bootscheme subfolder for flashlayout files
        flashlayout_subfolder_path = os.path.join(d.getVar('FLASHLAYOUT_DESTDIR'), bootscheme)
        bb.utils.mkdirhier(flashlayout_subfolder_path)

        for config in configs.split():
            bb.note('*** Loop for config label: %s' % config)
            # Set labeltypes list
            labeltypes = expand_var('FLASHLAYOUT_TYPE_LABELS', bootscheme, config, '', d)
            bb.note('FLASHLAYOUT_TYPE_LABELS: %s' % labeltypes)
            if labeltypes.strip() == 'none':
                bb.note("FLASHLAYOUT_TYPE_LABELS is none, so no flashlayout file to generate.")
                continue
            for labeltype in labeltypes.split():
                bb.note('*** Loop for label type: %s' % labeltype)
                # Init current label
                current_label = labeltype
                # Init flashlayout file name
                if config == 'none':
                    config_append = ''
                else:
                    config_append = '_' + config
                if len(labeltypes.split()) < 2 and len(bootschemes.split()) < 2:
                    labeltype_append = ''
                else:
                    labeltype_append = '_' + labeltype + '-' + bootscheme
                flashlayout_file = os.path.join(flashlayout_subfolder_path, d.expand("${FLASHLAYOUT_BASENAME}%s%s.${FLASHLAYOUT_SUFFIX}" % (config_append, labeltype_append)))
                # Get the partition list to write in flashlayout file
                partitions = expand_var('FLASHLAYOUT_PARTITION_LABELS', bootscheme, config, '', d)
                bb.note('FLASHLAYOUT_PARTITION_LABELS: %s' % partitions)
                if partitions == 'none':
                    bb.note("FLASHLAYOUT_PARTITION_LABELS is none, so no flashlayout file to generate.")
                    continue
                # Generate flashlayout file for labeltype
                try:
                    with open(flashlayout_file, 'w') as fl_file:
                        # Write to flashlayout file the first line header
                        fl_file.write('#Opt\tId\tName\tType\tIP\tOffset\tBinary\n')
                        # Init partition next offset to 'none'
                        partition_nextoffset = "none"
                        # Init partition previous device to 'none'
                        partition_prevdevice = "none"
                        for partition in partitions.split():
                            bb.note('*** Loop for partition: %s' % partition)
                            # Init partition settings
                            partition_enable = expand_var('FLASHLAYOUT_PARTITION_ENABLE', bootscheme, config, partition, d)
                            partition_id = expand_var('FLASHLAYOUT_PARTITION_ID', bootscheme, config, partition, d)
                            partition_name = partition
                            partition_type = expand_var('FLASHLAYOUT_PARTITION_TYPE', bootscheme, config, partition, d)
                            partition_device = get_device(bootscheme, config, partition, d)
                            # Reset partition_nextoffset to 'none' in case partition device has changed
                            if partition_device != partition_prevdevice:
                                partition_nextoffset = "none"
                            # Save partition current device to previous one for next loop
                            partition_prevdevice = partition_device
                            # Get partition offset
                            partition_offset, partition_nextoffset = get_offset(partition_nextoffset, partition_device, bootscheme, config, partition, d)
                            # Get binary name
                            partition_bin2load = get_binaryname(labeltype, bootscheme, config, partition, d)
                            # Be verbose in log file
                            bb.note('>>> Layout inputs: %s' % fl_file.name)
                            bb.note('>>> FLASHLAYOUT_PARTITION_ENABLE:      %s' % partition_enable)
                            bb.note('>>> FLASHLAYOUT_PARTITION_ID:          %s' % partition_id)
                            bb.note('>>> FLASHLAYOUT_PARTITION_LABEL:       %s' % partition_name)
                            bb.note('>>> FLASHLAYOUT_PARTITION_TYPE:        %s' % partition_type)
                            bb.note('>>> FLASHLAYOUT_PARTITION_DEVICE:      %s' % partition_device)
                            bb.note('>>> FLASHLAYOUT_PARTITION_OFFSET:      %s' % partition_offset)
                            bb.note('>>> FLASHLAYOUT_PARTITION_BIN2LOAD:    %s' % partition_bin2load)
                            bb.note('>>> done')
                            # Get the supported labels for current storage device
                            partition_device_alias = d.getVar('DEVICE_%s' % partition_device) or ""
                            partition_type_supported_labels = d.getVar('DEVICE_BOARD_ENABLE_%s' % partition_device_alias) or "none"
                            # Check if partition type is supported for the current label
                            if partition_device != 'none' and current_label not in partition_type_supported_labels.split():
                                bb.note('>>> FLASHLAYOUT_PARTITION_DEVICE (%s, alias %s) is not supported for current label (%s): partition %s not appended in flashlayout file' % (partition_device, partition_device_alias, current_label, partition_name))
                                bb.note('>>> DEVICE_BOARD_ENABLE_%s: %s' % (partition_device_alias, partition_type_supported_labels))
                                continue
                            # Write to flashlayout file the partition configuration
                            fl_file.write('%s\t%s\t%s\t%s\t%s\t%s\t%s\n' %
                                         (partition_enable, partition_id, partition_name, partition_type, partition_device, partition_offset, partition_bin2load))
                except OSError:
                    bb.fatal('Unable to open %s' % (fl_file))

                if d.getVar("ENABLE_FLASHLAYOUT_CONFIG_WRAPPER4DBG") == "1":
                    bb.note('*** Loop for flashlayout for the wrapper for debug %s' % labeltype)

                    tmp_flashlayout_file = os.path.join(flashlayout_subfolder_path, "flashlayout.tmp")
                    debug_flashlayout = False

                    try:
                        with open(flashlayout_file, 'r') as fl_file:
                            try:
                                with open(tmp_flashlayout_file, 'w') as debug_fl_file:
                                    for line in fl_file:
                                        if re.match('^.*/tf-a.*$', line) :
                                            line_tmp = re.sub(r'(.*)/',r'\1/debug/debug-', line)
                                            filename = re.sub(r'.*[\t ](.*)$',r'\1', line_tmp).strip()
                                            if os.path.isfile(os.path.join(d.getVar('DEPLOY_DIR_IMAGE'), filename)):
                                                line = line_tmp
                                                debug_flashlayout = True

                                        debug_fl_file.write('%s' % (line))
                            except OSError:
                                bb.fatal('Unable to open %s' % (debug_fl_file))
                    except OSError:
                        bb.fatal('Unable to open %s' % (fl_file))
                    if debug_flashlayout:
                        flashlayout_wrapper4dbg_subfolder_path = os.path.join(d.getVar('FLASHLAYOUT_DESTDIR'), bootscheme, "debug")
                        bb.utils.mkdirhier(flashlayout_wrapper4dbg_subfolder_path)
                        # Wrapper4dbg output filename
                        debug_flashlayout_file = os.path.join(flashlayout_wrapper4dbg_subfolder_path,d.expand("debug-${FLASHLAYOUT_BASENAME}%s%s.${FLASHLAYOUT_SUFFIX}" % (config_append, labeltype_append)))
                        bb.note(">>> Update tf-a in %s" %  (debug_flashlayout_file))
                        os.rename(tmp_flashlayout_file, debug_flashlayout_file)
                    else:
                        os.remove(tmp_flashlayout_file)
}

函数非常长,大概有170行,重点总结一下实际做的事:

  1. 如果使能了静态flashlayout生成则做一些检查,然后将自定义的flashlayout tsv文件拷贝到工作路径下
  2. 定义了一系列函数初始化变量、获取device的名字、计算offset等函数,然后根据BOOTSCHEME_LABELS 划分子目录,创建文件、写入每一行的具体内容,最终做一些校验。

do_create_flashlayout_config 任务里面非常繁杂,但是大概浏览一遍能差不多明白创建流程,这个class留了几个变量是被inc文件设置的,比如:
FLASHLAYOUT_DEPEND_TASKS
FLASHLAYOUT_BOOTSCHEME_LABELS
FLASHLAYOUT_CONFIG_LABELS

这些其实都在 machine/conf/inc st-machine-flashlayout-stm32mp.inc里面做了详细的配置。

总结:通过对st-partitions-image 还有flashlayout-stm32mp两个class的分析,STM32MP1创建分区和刷机文件好像变得越来越清晰,是时候该动起来创建自己的分区了,详见下一篇文章!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/59226.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

Bootstrap5 容器

我们可以使用以下两个容器类&#xff1a; .container 类用于固定宽度并支持响应式布局的容器。.container-fluid 类用于 100% 宽度&#xff0c;占据全部视口&#xff08;viewport&#xff09;的容器。固定宽度 .container 类用于创建固定宽度的响应式页面。 注意&#xff1a…

[node文件的上传和下载]一.node实现文件上传;二、Express实现文件下载;三、遍历下载文件夹下的文件,拼接成一个下载的url,传递到前端

目录 一.node实现文件上传 1.FormData对象&#xff1a;以对象的方式来表示页面中的表单&#xff0c;又称为表单对象。以key:value的方式来保存数据&#xff0c;XMLHttpRequest对象可以轻松的将表单对象发送到服务器端 &#xff08;1&#xff09;是一个构造函数&#xff1a;ne…

LabVIEW在应用程序和接口中使用LabVIEW类和接口

LabVIEW在应用程序和接口中使用LabVIEW类和接口 LabVIEW类和接口是用户定义的数据类型。LabVIEW类和接口开发人员创建并发布这些数据类型。LabVIEW类或接口用户无需了解如何创建LabVIEW类或接口&#xff0c;但必须了解应用程序中通过类或接口定义的数据类型应当如何使用&#…

通过java代码实现对json字符串的格式美化(完整版)

一、前言 之前转载过一篇文章&#xff0c;也是有关于通过java代码实现对json字符串的格式美化&#xff0c;但是那篇文章的实现还不够完善&#xff0c;比如其对字符串中出现特殊字符时&#xff0c;会出现转换失败。因此博主本人也是闲暇时在那份代码的基础上做了完善和补充。好…

[附源码]计算机毕业设计校园租赁系统Springboot程序

项目运行 环境配置&#xff1a; Jdk1.8 Tomcat7.0 Mysql HBuilderX&#xff08;Webstorm也行&#xff09; Eclispe&#xff08;IntelliJ IDEA,Eclispe,MyEclispe,Sts都支持&#xff09;。 项目技术&#xff1a; SSM mybatis Maven Vue 等等组成&#xff0c;B/S模式 M…

Tomcat服务器的简介以及安装

文章目录1.概念1.1 什么是Web服务器&#xff1f;1.2 静态资源和动态资源1.3 常用服务器产品2. Tomcat的安装2.1 下载2.2 解压安装2.3 Tomcat的目录结构2.4 Tomcat服务器的启动和关闭2.5 tomcat启动失败的原因2.5.1 查看报错原因2.5.2 错误原因2.5.2.1 查看JAVA_HOME配置是正确2…

ESP32——WEB服务程序移植(基于示例restful_server)

一、简介 将ESP32——WEB服务程序测试项目移植到一个现有项目中&#xff0c;现有项目包括基于固定IP的WIFI连接、OTA升级、Websocket等功能。 二、移植 2.1 参考restful_server项目下分区表文件partitions_example.csv修改项目分区 因模块采用ESP32-WROVER-E(4MB)&#xff…

磨金石教育摄影技能干货分享|乡愁摄影作品欣赏——传统建筑篇

俗话说“一方水土养一方人”&#xff0c;不同的山川地域与气候环境早就不同的地域文化。我国幅员广阔&#xff0c;南北东西跨度极大&#xff0c;因此气候环境与地理环境差异很大。在民俗文化上面也呈现出多元化风格。 这种多元化的文化风格清晰的体现在各地的建筑形式上。重庆的…

Java【String】【StringBuilder】【StringBuffer】你都会用吗

文章目录前言一、常用的方法1、字符串构造2、字符串比较3、字符串查找4、字符串转化5、字符串替换6、字符串分割7、字符串截取二、字符串的不可变性三、StringBuilder、StringBuffer总结前言 在校招和笔试过程中&#xff0c;字符串是相当频繁被问到的话题&#xff0c;在之前的…

iMazing兼容Win和Mac2023免费版iOS设备管理器

iMazing是一款ios设备管理软件&#xff0c;该软件支持对基于iOS系统的设备进行数据传输与备份&#xff0c;用户可以将包括&#xff1a;照片、音乐、铃声、视频、电子书及通讯录等在内的众多信息在Windows/Mac电脑中传输/备份/管理。 软件备份是指将一部手机上的重要信息和资料&…

Pytorch -> ONNX -> TensorRT 模型转换与部署

系统环境&#xff1a; Ubuntu 18.04Cuda 11.3Cudnn 8.4.1 1 、Pytorch -> ONNX 网上相关流程很多&#xff0c;我就不重复了 可以参考Pytorch分类模型转onnx以及onnx模型推理 或者直接看Pytorch官方怎么干的。 ONNX Github onnxruntime调用onnx模型推理时有一个provider…

HTML5期末大作业:基于HTML+CSS+JavaScript茶文化中国水墨风格绿色茶叶销售(5页) 学生网页设计作业源码

&#x1f389;精彩专栏推荐 &#x1f4ad;文末获取联系 ✍️ 作者简介: 一个热爱把逻辑思维转变为代码的技术博主 &#x1f482; 作者主页: 【主页——&#x1f680;获取更多优质源码】 &#x1f393; web前端期末大作业&#xff1a; 【&#x1f4da;毕设项目精品实战案例 (10…

用coding向你最爱的人说圣诞快乐

&#x1f384;&#x1f384;&#x1f384;圣诞节即将到来&#xff0c;今天让我们用编码的方式向你最爱的人表达圣诞节快乐。 圣诞节的起源 圣诞节源自古罗马人迎接新年的农神节&#xff0c;与基督教本无关系。在基督教盛行罗马帝国后&#xff0c;教廷将这种民俗节日纳入基督教体…

DenseNet的基本思想

之前的文章介绍过残差网络的基本思想&#xff1a;残差网络的思想就是将网络学习的映射从X到Y转为学习从X到Y-X的差&#xff0c;然后把学习到的残差信息加到原来的输出上即可。即便在某些极端情况下&#xff0c;这个残差为0&#xff0c;那么网络就是一个X到Y的恒等映射。其示意图…

Java基础类型和运算符

文章目录变量与常量变量的命名规则常量final 关键字修饰的常量字面常量基本类型整型基本整型变量 int长整型 long短整型 short比特型 byte浮点数 float和double关于3*0.10.3三种特殊的double字符型 char布尔类型 boolean类型转换隐式类型提升强制类型转换运算符算数运算符基本四…

vue中打印插件vue-print-nb(二)-实例之两种方法——安包之设置一个id和绑定一个对象 下载print.js之ref设置锚点

vue中打印插件vue-print-nb(二)-实例之两种方法——安包之设置一个id和绑定一个对象 & 下载print.js之ref设置锚点 第一种方法 方式1、设置一个id ① 给要打印的部分设置一个 id ② 在打印按钮中添加 v-print"#id名" 1、安装vue-print-nb插件 npm install v…

Firefly RK3399 PC pro Android 10下载验证

一.Android 源码以及image 1.Android 10代码链接&#xff1a; 百度网盘 请输入提取码 密码&#xff1a;1234 下载后检查md5值&#xff0c;检查下载是否正确&#xff1a; fb41fcdc48b1cf90ecac4a5bb8fafc7a Firefly-RK3399_Android10.0_git_20211222.7z.001 82d665fb54fb412…

Flutter ー Authentication 认证

Flutter ー Authentication 认证 原文 https://medium.com/simbu/flutter-authentication-adb8df7cf673 前言 如果我相信我知道你是谁那我就能让你查看你的个人 应用 application 资料。 身份验证可能是应用程序必须处理的最大的交叉问题。 将它作为一个特性添加到 DigestableP…

HashMap JDK1.7与1.8的区别

结构 首先HashMap在1.7中是以数组链表的形式存在的, 而HashMap在1.8中则是以数组链表红黑树构成的, 当一个节点的链表长度超过8并且数组长度超过64时会将链表转换为红黑树, 初始化 初始容量大小介绍 说到数组就不得不提HashMap里面的成员变量DEFAULT_INITIAL_CAPACITY也就是…

Mysql进阶学习(八)DDL语言+数据类型和DTL语言

Mysql进阶学习&#xff08;八&#xff09;DDL语言与DTL语言DDL语言1、简介&#xff1a;1.1、库的管理1.1.1、库的创建1.1.2、库的修改1.1.3、库的删除1.2、表的管理1.2.1.表的创建 ★1.2.2.表的修改1.2.3.表的删除1.2.4.表的复制测试案例1. 创建表dept12. 将表departments中的数…