20170921_jeffrey - silenceuncrio/diary GitHub Wiki

0845

review

0900

M300 專案 編譯環境 需要 local configuration file

我們可執行 proenv.sh 來產生該 file - build_small/conf/local.conf

編譯環境 還需要 machine configuration file 和 distribution configuration file

這可由 local.conf 裡的兩個變數來決定

  • MACHINE 變數決定 machine configuration file
  • DISTRO 變數決定 distribution configuration file

執行 proenv.sh 時若不帶任何參數的話

預設的 MACHINE 值 和 DISTRO 值如下

  • MACHINE = m300
  • DISTRO = proscend-m300

對應的 configuration files 為

  • machine configuration file
    • meta-proscend/conf/machine/m300.conf
  • distribution configuration file
    • meta-proscend/conf/distro/proscend-m300.conf

0930

花點時間看看之前自己對於 UBOOT_CONFIG 的理解

1115

盤一下可利用的過去筆記

  • 20160707_jeffrey
    • 修改 M300/fsl-release-bsp/build_small/conf/local.conf 檔案尾部新增一行 - UBOOT_CONFIG = "nand"
    • bitbake u-boot-imx -c compile -vf 會呼叫 u-boot.inc 的 do_compile ()
  • 20160711_jeffrey
    • bitbake u-boot-imx -c compile -vf 的流程 會到達 /fsl-release-bsp/sources/poky/meta/recipes-bsp/u-boot/u-boot.inc
    • UBOOT_CONFIG 沒被定義
      • 需要 configs/mx6ul_14x14_evk_defconfig
    • UBOOT_CONFIG 定義成 "nand"
      • 需要 configs/mx6ul_14x14_evk_nand_defconfig
  • 20160712_jeffrey
    • 當 UBOOT_CONFIG = "nand" 時發生的問題便是 <UBOOT_DIR>/configs/ 目錄下並不存在有 mx6ul_14x14_evk_nand_config
    • 當 UBOOT_CONFIG = "nand" 的時候, 像 CONFIG_SYS_EXTRA_OPTIONS="IMX_CONFIG=board/freescale/mx6ul_14x14_evk/imximage.cfg,MX6UL,SYS_BOOT_NAND" 這樣的敘述, 會讓 compile-time 多了 CONFIG_SYS_BOOT_NAND 這個 flag
    • 根本就沒有幫我 build ubifs 格式的 rootfs
  • 20160713_jeffrey
    • ubifs 跟我們產生的 rootfs 沒有關係
    • 我們的 rootfs 就一個樣 - rootfs_nogpu.tar.bz2
    • 只需要能傳到相對應的 /dev/mtd 去再解壓縮就做完了
  • 20160714_jeffrey
    • bitbake u-boot-imx 是如何被影響
  • 20160715_jeffrey
    • 讓 M300 支援 NAND Flash
  • 20160718_jeffrey
    • BitBake User Manual - Appendix A. Hello World Example
  • 20160719_jeffrey
    • core-image-minimal 是個 recipe
    • *.sdcard image 到底是怎麼 build 出來的

1300

追一下目前的 develop branch compile 的最後幾個流程

Z:\M300_git\M300\build_small\images 這目錄看來

還是有看到 core-image-minimal-m300.sdcard

看一下 build_small\tmp\work\m300-poky-linux-gnueabi\core-image-minimal\1.0-r0\temp 的 log

log.do_rootfs 的最後幾行看來

...
NOTE: Creating symlinks for ext4 image ...
NOTE: Creating symlink: core-image-minimal-m300.ext4 -> core-image-minimal-m300-20170921035323.rootfs.ext4
NOTE: Creating symlinks for tar image ...
NOTE: Creating symlink: core-image-minimal-m300.tar.bz2 -> core-image-minimal-m300-20170921035323.rootfs.tar.bz2
NOTE: Running image creation script for nandflash: /var/m300/build_small/tmp/work/m300-poky-linux-gnueabi/core-image-minimal/1.0-r0/temp/create_image.nandflash ...
...
NOTE: Running image creation script for sdcard: /var/m300/build_small/tmp/work/m300-poky-linux-gnueabi/core-image-minimal/1.0-r0/temp/create_image.sdcard ...

所謂的 rootfs

不管是 ext4 或是 tar.bz2 都產生出來了

  • core-image-minimal-m300-20170921035323.rootfs.ext4
  • core-image-minimal-m300-20170921035323.rootfs.tar.bz2

而且還為了 nandflashsdcard 跑了各自的 image creation script

  • Running image creation script for nandflash
  • Running image creation script for sdcard

image creation script 去搜尋 log.do_rootfs 的話會找到

...
NOTE: Running image creation script for ext4: /var/m300/build_small/tmp/work/m300-poky-linux-gnueabi/core-image-minimal/1.0-r0/temp/create_image.ext4 ...
...
NOTE: Running image creation script for tar: /var/m300/build_small/tmp/work/m300-poky-linux-gnueabi/core-image-minimal/1.0-r0/temp/create_image.tar ...
...
NOTE: Running image creation script for nandflash: /var/m300/build_small/tmp/work/m300-poky-linux-gnueabi/core-image-minimal/1.0-r0/temp/create_image.nandflash ...
...
NOTE: Running image creation script for sdcard: /var/m300/build_small/tmp/work/m300-poky-linux-gnueabi/core-image-minimal/1.0-r0/temp/create_image.sdcard ...
...

1325

追一下 core-image-minimal 這個 recipe

sources/poky/meta/recipes-core/images/core-image-minimal.bb

SUMMARY = "A small image just capable of allowing a device to boot."

IMAGE_INSTALL = "packagegroup-core-boot ${ROOTFS_PKGMANAGE_BOOTSTRAP} ${CORE_IMAGE_EXTRA_INSTALL}"

IMAGE_LINGUAS = " "

LICENSE = "MIT"

inherit core-image

IMAGE_ROOTFS_SIZE ?= "8192"
IMAGE_ROOTFS_EXTRA_SPACE_append = "${@bb.utils.contains("DISTRO_FEATURES", "systemd", " + 4096", "" ,d)}
"

sources/poky/meta/classes/core-image.bbclass

# Common code for generating core reference images
#
# Copyright (C) 2007-2011 Linux Foundation

LIC_FILES_CHKSUM = "file://${COREBASE}/LICENSE;md5=4d92cd373abda3937c2bc47fbc49d690 \
                    file://${COREBASE}/meta/COPYING.MIT;md5=3da9cfbcb788c80a0384361b4de20420"

# IMAGE_FEATURES control content of the core reference images
#
# By default we install packagegroup-core-boot and packagegroup-base-extended packages;
# this gives us working (console only) rootfs.
#
# Available IMAGE_FEATURES:
#
# - x11                 - X server
# - x11-base            - X server with minimal environment
# - x11-sato            - OpenedHand Sato environment
# - tools-debug         - debugging tools
# - eclipse-debug       - Eclipse remote debugging support
# - tools-profile       - profiling tools
# - tools-testapps      - tools usable to make some device tests
# - tools-sdk           - SDK (C/C++ compiler, autotools, etc.)
# - nfs-server          - NFS server
# - nfs-client          - NFS client
# - ssh-server-dropbear - SSH server (dropbear)
# - ssh-server-openssh  - SSH server (openssh)
# - qt4-pkgs            - Qt4/X11 and demo applications
# - hwcodecs            - Install hardware acceleration codecs
# - package-management  - installs package management tools and preserves the package manager database
# - debug-tweaks        - makes an image suitable for development, e.g. allowing passwordless root login
s
# - dev-pkgs            - development packages (headers, etc.) for all installed packages in the rootfs
# - dbg-pkgs            - debug symbol packages for all installed packages in the rootfs
# - doc-pkgs            - documentation packages for all installed packages in the rootfs
# - ptest-pkgs          - ptest packages for all ptest-enabled recipes
# - read-only-rootfs    - tweaks an image to support read-only rootfs
#
FEATURE_PACKAGES_x11 = "packagegroup-core-x11"
FEATURE_PACKAGES_x11-base = "packagegroup-core-x11-base"
FEATURE_PACKAGES_x11-sato = "packagegroup-core-x11-sato"
FEATURE_PACKAGES_tools-debug = "packagegroup-core-tools-debug"
FEATURE_PACKAGES_eclipse-debug = "packagegroup-core-eclipse-debug"
FEATURE_PACKAGES_tools-profile = "packagegroup-core-tools-profile"
FEATURE_PACKAGES_tools-testapps = "packagegroup-core-tools-testapps"
FEATURE_PACKAGES_tools-sdk = "packagegroup-core-sdk packagegroup-core-standalone-sdk-target"
FEATURE_PACKAGES_nfs-server = "packagegroup-core-nfs-server"
FEATURE_PACKAGES_nfs-client = "packagegroup-core-nfs-client"
FEATURE_PACKAGES_ssh-server-dropbear = "packagegroup-core-ssh-dropbear"
FEATURE_PACKAGES_ssh-server-openssh = "packagegroup-core-ssh-openssh"
FEATURE_PACKAGES_qt4-pkgs = "packagegroup-core-qt-demoapps"
FEATURE_PACKAGES_hwcodecs = "${MACHINE_HWCODECS}"


# IMAGE_FEATURES_REPLACES_foo = 'bar1 bar2'
# Including image feature foo would replace the image features bar1 and bar2
IMAGE_FEATURES_REPLACES_ssh-server-openssh = "ssh-server-dropbear"

# IMAGE_FEATURES_CONFLICTS_foo = 'bar1 bar2'
# An error exception would be raised if both image features foo and bar1(or bar2) are included

MACHINE_HWCODECS ??= ""

CORE_IMAGE_BASE_INSTALL = '\
    packagegroup-core-boot \
    packagegroup-base-extended \
    \
    ${CORE_IMAGE_EXTRA_INSTALL} \
    '

CORE_IMAGE_EXTRA_INSTALL ?= ""

IMAGE_INSTALL ?= "${CORE_IMAGE_BASE_INSTALL}"

inherit image

sources/poky/meta/classes/image.bbclass

inherit rootfs_${IMAGE_PKGTYPE}

inherit populate_sdk_ext

TOOLCHAIN_TARGET_TASK += "${PACKAGE_INSTALL}"
TOOLCHAIN_TARGET_TASK_ATTEMPTONLY += "${PACKAGE_INSTALL_ATTEMPTONLY}"
POPULATE_SDK_POST_TARGET_COMMAND += "rootfs_sysroot_relativelinks; "

inherit gzipnative

LICENSE = "MIT"
PACKAGES = ""
DEPENDS += "${MLPREFIX}qemuwrapper-cross ${MLPREFIX}depmodwrapper-cross"
RDEPENDS += "${PACKAGE_INSTALL} ${LINGUAS_INSTALL}"
RRECOMMENDS += "${PACKAGE_INSTALL_ATTEMPTONLY}"

INHIBIT_DEFAULT_DEPS = "1"

TESTIMAGECLASS = "${@base_conditional('TEST_IMAGE', '1', 'testimage-auto', '', d)}"
inherit ${TESTIMAGECLASS}

# IMAGE_FEATURES may contain any available package group
IMAGE_FEATURES ?= ""
IMAGE_FEATURES[type] = "list"
IMAGE_FEATURES[validitems] += "debug-tweaks read-only-rootfs empty-root-password allow-empty-password po
st-install-logging"

# Generate companion debugfs?
IMAGE_GEN_DEBUGFS ?= "0"

# rootfs bootstrap install
ROOTFS_BOOTSTRAP_INSTALL = "${@bb.utils.contains("IMAGE_FEATURES", "package-management", "", "${ROOTFS_P
KGMANAGE_BOOTSTRAP}",d)}"

# packages to install from features
FEATURE_INSTALL = "${@' '.join(oe.packagegroup.required_packages(oe.data.typed_value('IMAGE_FEATURES', d
), d))}"
FEATURE_INSTALL[vardepvalue] = "${FEATURE_INSTALL}"
FEATURE_INSTALL_OPTIONAL = "${@' '.join(oe.packagegroup.optional_packages(oe.data.typed_value('IMAGE_FEA
TURES', d), d))}"
FEATURE_INSTALL_OPTIONAL[vardepvalue] = "${FEATURE_INSTALL_OPTIONAL}"

# Define some very basic feature package groups
FEATURE_PACKAGES_package-management = "${ROOTFS_PKGMANAGE}"
SPLASH ?= "psplash"
FEATURE_PACKAGES_splash = "${SPLASH}"

IMAGE_INSTALL_COMPLEMENTARY = '${@complementary_globs("IMAGE_FEATURES", d)}'

def check_image_features(d):
    valid_features = (d.getVarFlag('IMAGE_FEATURES', 'validitems', True) or "").split()
    valid_features += d.getVarFlags('COMPLEMENTARY_GLOB').keys()
    for var in d:
       if var.startswith("PACKAGE_GROUP_"):
           bb.warn("PACKAGE_GROUP is deprecated, please use FEATURE_PACKAGES instead")
           valid_features.append(var[14:])
       elif var.startswith("FEATURE_PACKAGES_"):
           valid_features.append(var[17:])
    valid_features.sort()

    features = set(oe.data.typed_value('IMAGE_FEATURES', d))
    for feature in features:
        if feature not in valid_features:
            if bb.utils.contains('EXTRA_IMAGE_FEATURES', feature, True, False, d):
                raise bb.parse.SkipRecipe("'%s' in IMAGE_FEATURES (added via EXTRA_IMAGE_FEATURES) is no
t a valid image feature. Valid features: %s" % (feature, ' '.join(valid_features)))
            else:
                raise bb.parse.SkipRecipe("'%s' in IMAGE_FEATURES is not a valid image feature. Valid fe
atures: %s" % (feature, ' '.join(valid_features)))

IMAGE_INSTALL ?= ""
IMAGE_INSTALL[type] = "list"
export PACKAGE_INSTALL ?= "${IMAGE_INSTALL} ${ROOTFS_BOOTSTRAP_INSTALL} ${FEATURE_INSTALL}"
PACKAGE_INSTALL_ATTEMPTONLY ?= "${FEATURE_INSTALL_OPTIONAL}"

# Images are generally built explicitly, do not need to be part of world.
EXCLUDE_FROM_WORLD = "1"

USE_DEVFS ?= "1"
USE_DEPMOD ?= "1"

PID = "${@os.getpid()}"

PACKAGE_ARCH = "${MACHINE_ARCH}"

LDCONFIGDEPEND ?= "ldconfig-native:do_populate_sysroot"
LDCONFIGDEPEND_libc-uclibc = ""
LDCONFIGDEPEND_libc-musl = ""

# This is needed to have depmod data in PKGDATA_DIR,
# but if you're building small initramfs image
# e.g. to include it in your kernel, you probably
# don't want this dependency, which is causing dependency loop
KERNELDEPMODDEPEND ?= "virtual/kernel:do_packagedata"

do_rootfs[depends] += " \                                                                     [427/1803]
    makedevs-native:do_populate_sysroot virtual/fakeroot-native:do_populate_sysroot ${LDCONFIGDEPEND} \
    virtual/update-alternatives-native:do_populate_sysroot update-rc.d-native:do_populate_sysroot \
    ${KERNELDEPMODDEPEND} \
"
do_rootfs[recrdeptask] += "do_packagedata"

def command_variables(d):
    return ['ROOTFS_POSTPROCESS_COMMAND','ROOTFS_PREPROCESS_COMMAND','ROOTFS_POSTINSTALL_COMMAND','OPKG_
PREPROCESS_COMMANDS','OPKG_POSTPROCESS_COMMANDS','IMAGE_POSTPROCESS_COMMAND',
            'IMAGE_PREPROCESS_COMMAND','ROOTFS_POSTPROCESS_COMMAND','POPULATE_SDK_POST_HOST_COMMAND','PO
PULATE_SDK_POST_TARGET_COMMAND','SDK_POSTPROCESS_COMMAND','RPM_PREPROCESS_COMMANDS',
            'RPM_POSTPROCESS_COMMANDS']

python () {
    variables = command_variables(d)
    for var in variables:
        if d.getVar(var, False):
            d.setVarFlag(var, 'func', '1')
}

def fstype_variables(d):
    import oe.image

    image = oe.image.Image(d)
    alltypes, fstype_groups, cimages = image._get_image_types()
    fstype_vars = set()
    for fstype_group in fstype_groups:
        for fstype in fstype_group:
            fstype_vars.add('IMAGE_CMD_' + fstype)
            if fstype in cimages:
                for ctype in cimages[fstype]:
                    fstype_vars.add('COMPRESS_CMD_' + ctype)

    return sorted(fstype_vars)

def rootfs_variables(d):
    from oe.rootfs import variable_depends
    variables = ['IMAGE_DEVICE_TABLES','BUILD_IMAGES_FROM_FEEDS','IMAGE_TYPES_MASKED','IMAGE_ROOTFS_ALIG
NMENT','IMAGE_OVERHEAD_FACTOR','IMAGE_ROOTFS_SIZE','IMAGE_ROOTFS_EXTRA_SPACE',
                 'IMAGE_ROOTFS_MAXSIZE','IMAGE_NAME','IMAGE_LINK_NAME','IMAGE_MANIFEST','DEPLOY_DIR_IMAG
E','RM_OLD_IMAGE','IMAGE_FSTYPES','IMAGE_INSTALL_COMPLEMENTARY','IMAGE_LINGUAS','SDK_OS',
                 'SDK_OUTPUT','SDKPATHNATIVE','SDKTARGETSYSROOT','SDK_DIR','SDK_VENDOR','SDKIMAGE_INSTAL
L_COMPLEMENTARY','SDK_PACKAGE_ARCHS','SDK_OUTPUT','SDKTARGETSYSROOT','MULTILIBRE_ALLOW_REP',
                 'MULTILIB_TEMP_ROOTFS','MULTILIB_VARIANTS','MULTILIBS','ALL_MULTILIB_PACKAGE_ARCHS','MU
LTILIB_GLOBAL_VARIANTS','BAD_RECOMMENDATIONS','NO_RECOMMENDATIONS','PACKAGE_ARCHS',
                 'PACKAGE_CLASSES','TARGET_VENDOR','TARGET_VENDOR','TARGET_ARCH','TARGET_OS','OVERRIDES'
,'BBEXTENDVARIANT','FEED_DEPLOYDIR_BASE_URI','INTERCEPT_DIR','USE_DEVFS',
                 'COMPRESSIONTYPES', 'IMAGE_GEN_DEBUGFS']
    variables.extend(fstype_variables(d))                                                     [378/1803]
    variables.extend(command_variables(d))
    variables.extend(variable_depends(d))
    return " ".join(variables)

do_rootfs[vardeps] += "${@rootfs_variables(d)}"

do_build[depends] += "virtual/kernel:do_deploy"

def build_live(d):
    if bb.utils.contains("IMAGE_FSTYPES", "live", "live", "0", d) == "0": # live is not set but hob migh
t set iso or hddimg
        d.setVar('NOISO', bb.utils.contains('IMAGE_FSTYPES', "iso", "0", "1", d))
        d.setVar('NOHDD', bb.utils.contains('IMAGE_FSTYPES', "hddimg", "0", "1", d))
        if d.getVar('NOISO', True) == "0" or d.getVar('NOHDD', True) == "0":
            return "image-live"
        return ""
    return "image-live"

IMAGE_TYPE_live = "${@build_live(d)}"
inherit ${IMAGE_TYPE_live}

IMAGE_TYPE_vm = '${@bb.utils.contains_any("IMAGE_FSTYPES", ["vmdk", "vdi", "qcow2", "hdddirect"], "image
-vm", "", d)}'
inherit ${IMAGE_TYPE_vm}

python () {
    deps = " " + imagetypes_getdepends(d)
    d.appendVarFlag('do_rootfs', 'depends', deps)

    deps = ""
    for dep in (d.getVar('EXTRA_IMAGEDEPENDS', True) or "").split():
        deps += " %s:do_populate_sysroot" % dep
    d.appendVarFlag('do_build', 'depends', deps)

    #process IMAGE_FEATURES, we must do this before runtime_mapping_rename
    #Check for replaces image features
    features = set(oe.data.typed_value('IMAGE_FEATURES', d))
    remain_features = features.copy()
    for feature in features:
        replaces = set((d.getVar("IMAGE_FEATURES_REPLACES_%s" % feature, True) or "").split())
        remain_features -= replaces

    #Check for conflict image features
    for feature in remain_features:
        conflicts = set((d.getVar("IMAGE_FEATURES_CONFLICTS_%s" % feature, True) or "").split())
        temp = conflicts & remain_features
        if temp:
            bb.fatal("%s contains conflicting IMAGE_FEATURES %s %s" % (d.getVar('PN', True), f[330/1803]
'.join(list(temp))))

    d.setVar('IMAGE_FEATURES', ' '.join(list(remain_features)))

    check_image_features(d)
    initramfs_image = d.getVar('INITRAMFS_IMAGE', True) or ""
    if initramfs_image != "":
        d.appendVarFlag('do_build', 'depends', " %s:do_bundle_initramfs" %  d.getVar('PN', True))
        d.appendVarFlag('do_bundle_initramfs', 'depends', " %s:do_rootfs" % initramfs_image)
}

IMAGE_CLASSES += "image_types"
inherit ${IMAGE_CLASSES}

IMAGE_POSTPROCESS_COMMAND ?= ""

# Zap the root password if debug-tweaks feature is not enabled
ROOTFS_POSTPROCESS_COMMAND += '${@bb.utils.contains_any("IMAGE_FEATURES", [ 'debug-tweaks', 'empty-root-
password' ], "", "zap_empty_root_password ; ",d)}'

# Allow dropbear/openssh to accept logins from accounts with an empty password string if debug-tweaks is
 enabled
ROOTFS_POSTPROCESS_COMMAND += '${@bb.utils.contains_any("IMAGE_FEATURES", [ 'debug-tweaks', 'allow-empty
-password' ], "ssh_allow_empty_password; ", "",d)}'

# Enable postinst logging if debug-tweaks is enabled
ROOTFS_POSTPROCESS_COMMAND += '${@bb.utils.contains_any("IMAGE_FEATURES", [ 'debug-tweaks', 'post-instal
l-logging' ], "postinst_enable_logging; ", "",d)}'

# Create /etc/timestamp during image construction to give a reasonably sane default time setting
ROOTFS_POSTPROCESS_COMMAND += "rootfs_update_timestamp ; "

# Tweak the mount options for rootfs in /etc/fstab if read-only-rootfs is enabled
ROOTFS_POSTPROCESS_COMMAND += '${@bb.utils.contains("IMAGE_FEATURES", "read-only-rootfs", "read_only_roo
tfs_hook; ", "",d)}'

# Write manifest
IMAGE_MANIFEST = "${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.rootfs.manifest"
ROOTFS_POSTUNINSTALL_COMMAND =+ "write_image_manifest ; "
# Set default postinst log file
POSTINST_LOGFILE ?= "${localstatedir}/log/postinstall.log"
# Set default target for systemd images
SYSTEMD_DEFAULT_TARGET ?= '${@bb.utils.contains("IMAGE_FEATURES", "x11-base", "graphical.target", "multi
-user.target", d)}'
ROOTFS_POSTPROCESS_COMMAND += '${@bb.utils.contains("DISTRO_FEATURES", "systemd", "set_systemd_default_t
arget; ", "", d)}'

ROOTFS_POSTPROCESS_COMMAND += 'empty_var_volatile;'

# some default locales
IMAGE_LINGUAS ?= "de-de fr-fr en-gb"

LINGUAS_INSTALL ?= "${@" ".join(map(lambda s: "locale-base-%s" % s, d.getVar('IMAGE_LINGUAS', True).spli
t()))}"

# Prefer image, but use the fallback files for lookups if the image ones
# aren't yet available.
PSEUDO_PASSWD = "${IMAGE_ROOTFS}:${STAGING_DIR_NATIVE}"

do_rootfs[dirs] = "${TOPDIR}"
do_rootfs[lockfiles] += "${IMAGE_ROOTFS}.lock"
do_rootfs[cleandirs] += "${S}"

# Must call real_do_rootfs() from inside here, rather than as a separate
# task, so that we have a single fakeroot context for the whole process.
do_rootfs[umask] = "022"

# A hook function to support read-only-rootfs IMAGE_FEATURES
read_only_rootfs_hook () {
        # Tweak the mount option and fs_passno for rootfs in fstab
        sed -i -e '/^[#[:space:]]*\/dev\/root/{s/defaults/ro/;s/\([[:space:]]*[[:digit:]]\)\([[:space:]]
*\)[[:digit:]]$/\1\20/}' ${IMAGE_ROOTFS}/etc/fstab

        # If we're using openssh and the /etc/ssh directory has no pre-generated keys,
        # we should configure openssh to use the configuration file /etc/ssh/sshd_config_readonly
        # and the keys under /var/run/ssh.
        if [ -d ${IMAGE_ROOTFS}/etc/ssh ]; then
                if [ -e ${IMAGE_ROOTFS}/etc/ssh/ssh_host_rsa_key ]; then
                        echo "SYSCONFDIR=/etc/ssh" >> ${IMAGE_ROOTFS}/etc/default/ssh
                        echo "SSHD_OPTS=" >> ${IMAGE_ROOTFS}/etc/default/ssh
                else
                        echo "SYSCONFDIR=/var/run/ssh" >> ${IMAGE_ROOTFS}/etc/default/ssh
                        echo "SSHD_OPTS='-f /etc/ssh/sshd_config_readonly'" >> ${IMAGE_ROOTFS}/etc/defau
lt/ssh
                fi
        fi

        # Also tweak the key location for dropbear in the same way.
        if [ -d ${IMAGE_ROOTFS}/etc/dropbear ]; then
                if [ -e ${IMAGE_ROOTFS}/etc/dropbear/dropbear_rsa_host_key ]; then
                        echo "DROPBEAR_RSAKEY_DIR=/etc/dropbear" >> ${IMAGE_ROOTFS}/etc/default/dropbear
                else
                        echo "DROPBEAR_RSAKEY_DIR=/var/lib/dropbear" >> ${IMAGE_ROOTFS}/etc/default/drop
bear
                fi
        fi


        if ${@bb.utils.contains("DISTRO_FEATURES", "sysvinit", "true", "false", d)}; then     [231/1803]
                # Change the value of ROOTFS_READ_ONLY in /etc/default/rcS to yes
                if [ -e ${IMAGE_ROOTFS}/etc/default/rcS ]; then
                        sed -i 's/ROOTFS_READ_ONLY=no/ROOTFS_READ_ONLY=yes/' ${IMAGE_ROOTFS}/etc/default
/rcS
                fi
                # Run populate-volatile.sh at rootfs time to set up basic files
                # and directories to support read-only rootfs.
                if [ -x ${IMAGE_ROOTFS}/etc/init.d/populate-volatile.sh ]; then
                        ${IMAGE_ROOTFS}/etc/init.d/populate-volatile.sh
                fi
        fi

        if ${@bb.utils.contains("DISTRO_FEATURES", "systemd", "true", "false", d)}; then
            # Update user database files so that services don't fail for a read-only systemd system
            for conffile in ${IMAGE_ROOTFS}/usr/lib/sysusers.d/systemd.conf ${IMAGE_ROOTFS}/usr/lib/sysu
sers.d/systemd-remote.conf; do
                [ -e $conffile ] || continue
                grep -v "^#" $conffile | sed -e '/^$/d' | while read type name id comment; do
                    if [ "$type" = "u" ]; then
                        useradd_params=""
                        [ "$id" != "-" ] && useradd_params="$useradd_params --uid $id"
                        [ "$comment" != "-" ] && useradd_params="$useradd_params --comment $comment"
                        useradd_params="$useradd_params --system $name"
                        eval useradd --root ${IMAGE_ROOTFS} $useradd_params || true
                    elif [ "$type" = "g" ]; then
                        groupadd_params=""
                        [ "$id" != "-" ] && groupadd_params="$groupadd_params --gid $id"
                        groupadd_params="$groupadd_params --system $name"
                        eval groupadd --root ${IMAGE_ROOTFS} $groupadd_params || true
                    fi
                done
            done
        fi
}

PACKAGE_EXCLUDE ??= ""
PACKAGE_EXCLUDE[type] = "list"

python rootfs_process_ignore() {
    excl_pkgs = d.getVar("PACKAGE_EXCLUDE", True).split()
    inst_pkgs = d.getVar("PACKAGE_INSTALL", True).split()
    inst_attempt_pkgs = d.getVar("PACKAGE_INSTALL_ATTEMPTONLY", True).split()

    d.setVar('PACKAGE_INSTALL_ORIG', ' '.join(inst_pkgs))
    d.setVar('PACKAGE_INSTALL_ATTEMPTONLY', ' '.join(inst_attempt_pkgs))

    for pkg in excl_pkgs:
        if pkg in inst_pkgs:
            bb.warn("Package %s, set to be excluded, is in %s PACKAGE_INSTALL (%s).  It will be removed
from the list." % (pkg, d.getVar('PN', True), inst_pkgs))                                     [181/1803]
            inst_pkgs.remove(pkg)

        if pkg in inst_attempt_pkgs:
            bb.warn("Package %s, set to be excluded, is in %s PACKAGE_INSTALL_ATTEMPTONLY (%s).  It will
 be removed from the list." % (pkg, d.getVar('PN', True), inst_pkgs))
            inst_attempt_pkgs.remove(pkg)

    d.setVar("PACKAGE_INSTALL", ' '.join(inst_pkgs))
    d.setVar("PACKAGE_INSTALL_ATTEMPTONLY", ' '.join(inst_attempt_pkgs))
}
do_rootfs[prefuncs] += "rootfs_process_ignore"

# We have to delay the runtime_mapping_rename until just before rootfs runs
# otherwise, the multilib renaming could step in and squash any fixups that
# may have occurred.
python rootfs_runtime_mapping() {
    pn = d.getVar('PN', True)
    runtime_mapping_rename("PACKAGE_INSTALL", pn, d)
    runtime_mapping_rename("PACKAGE_INSTALL_ATTEMPTONLY", pn, d)
    runtime_mapping_rename("BAD_RECOMMENDATIONS", pn, d)
}
do_rootfs[prefuncs] += "rootfs_runtime_mapping"

fakeroot python do_rootfs () {
    from oe.rootfs import create_rootfs
    from oe.image import create_image
    from oe.manifest import create_manifest

    # generate the initial manifest
    create_manifest(d)

    # generate rootfs
    create_rootfs(d)

    # generate final images
    create_image(d)
}

insert_feed_uris () {

        echo "Building feeds for [${DISTRO}].."

        for line in ${FEED_URIS}
        do
                # strip leading and trailing spaces/tabs, then split into name and uri
                line_clean="`echo "$line"|sed 's/^[ \t]*//;s/[ \t]*$//'`"
                feed_name="`echo "$line_clean" | sed -n 's/\(.*\)##\(.*\)/\1/p'`"
                feed_uri="`echo "$line_clean" | sed -n 's/\(.*\)##\(.*\)/\2/p'`"

                echo "Added $feed_name feed with URL $feed_uri"



                # insert new feed-sources
                echo "src/gz $feed_name $feed_uri" >> ${IMAGE_ROOTFS}/etc/opkg/${feed_name}-feed.conf
        done
}

MULTILIBRE_ALLOW_REP =. "${base_bindir}|${base_sbindir}|${bindir}|${sbindir}|${libexecdir}|${sysconfdir}
|${nonarch_base_libdir}/udev|/lib/modules/[^/]*/modules.*|"
MULTILIB_CHECK_FILE = "${WORKDIR}/multilib_check.py"
MULTILIB_TEMP_ROOTFS = "${WORKDIR}/multilib"

# This function is intended to disallow empty root password if 'debug-tweaks' is not in IMAGE_FEATURES.
zap_empty_root_password () {
        if [ -e ${IMAGE_ROOTFS}/etc/shadow ]; then
                sed -i 's%^root::%root:*:%' ${IMAGE_ROOTFS}/etc/shadow
        fi
        if [ -e ${IMAGE_ROOTFS}/etc/passwd ]; then
                sed -i 's%^root::%root:*:%' ${IMAGE_ROOTFS}/etc/passwd
        fi
}

# allow dropbear/openssh to accept root logins and logins from accounts with an empty password string
ssh_allow_empty_password () {
        if [ -e ${IMAGE_ROOTFS}${sysconfdir}/ssh/sshd_config ]; then
                sed -i 's/^[#[:space:]]*PermitRootLogin.*/PermitRootLogin yes/' ${IMAGE_ROOTFS}${sysconf
dir}/ssh/sshd_config
                sed -i 's/^[#[:space:]]*PermitEmptyPasswords.*/PermitEmptyPasswords yes/' ${IMAGE_ROOTFS
}${sysconfdir}/ssh/sshd_config
        fi

        if [ -e ${IMAGE_ROOTFS}${sbindir}/dropbear ] ; then
                if grep -q DROPBEAR_EXTRA_ARGS ${IMAGE_ROOTFS}${sysconfdir}/default/dropbear 2>/dev/null
 ; then
                        if ! grep -q "DROPBEAR_EXTRA_ARGS=.*-B" ${IMAGE_ROOTFS}${sysconfdir}/default/dro
pbear ; then
                                sed -i 's/^DROPBEAR_EXTRA_ARGS="*\([^"]*\)"*/DROPBEAR_EXTRA_ARGS="\1 -B"
/' ${IMAGE_ROOTFS}${sysconfdir}/default/dropbear
                        fi
                else
                        printf '\nDROPBEAR_EXTRA_ARGS="-B"\n' >> ${IMAGE_ROOTFS}${sysconfdir}/default/dr
opbear
                fi
        fi

        if [ -d ${IMAGE_ROOTFS}${sysconfdir}/pam.d ] ; then
                sed -i 's/nullok_secure/nullok/' ${IMAGE_ROOTFS}${sysconfdir}/pam.d/*
        fi
}

# Disable DNS lookups, the SSH_DISABLE_DNS_LOOKUP can be overridden to allow
# distros to choose not to take this change                                                    [80/1803]
SSH_DISABLE_DNS_LOOKUP ?= " ssh_disable_dns_lookup ; "
ROOTFS_POSTPROCESS_COMMAND_append_qemuall = "${SSH_DISABLE_DNS_LOOKUP}"
ssh_disable_dns_lookup () {
        if [ -e ${IMAGE_ROOTFS}${sysconfdir}/ssh/sshd_config ]; then
                sed -i -e 's:#UseDNS yes:UseDNS no:' ${IMAGE_ROOTFS}${sysconfdir}/ssh/sshd_config
        fi
}

# Enable postinst logging if debug-tweaks is enabled
postinst_enable_logging () {
        mkdir -p ${IMAGE_ROOTFS}${sysconfdir}/default
        echo "POSTINST_LOGGING=1" >> ${IMAGE_ROOTFS}${sysconfdir}/default/postinst
        echo "LOGFILE=${POSTINST_LOGFILE}" >> ${IMAGE_ROOTFS}${sysconfdir}/default/postinst
}

# Modify systemd default target
set_systemd_default_target () {
        if [ -d ${IMAGE_ROOTFS}${sysconfdir}/systemd/system -a -e ${IMAGE_ROOTFS}${systemd_unitdir}/syst
em/${SYSTEMD_DEFAULT_TARGET} ]; then
                ln -sf ${systemd_unitdir}/system/${SYSTEMD_DEFAULT_TARGET} ${IMAGE_ROOTFS}${sysconfdir}/
systemd/system/default.target
        fi
}

# If /var/volatile is not empty, we have seen problems where programs such as the
# journal make assumptions based on the contents of /var/volatile. The journal
# would then write to /var/volatile before it was mounted, thus hiding the
# items previously written.
#
# This change is to attempt to fix those types of issues in a way that doesn't
# affect users that may not be using /var/volatile.
empty_var_volatile () {
        if [ -e ${IMAGE_ROOTFS}/etc/fstab ]; then
                match=`awk '$1 !~ "#" && $2 ~ /\/var\/volatile/{print $2}' ${IMAGE_ROOTFS}/etc/fstab 2>
/dev/null`
                if [ -n "$match" ]; then
                        find ${IMAGE_ROOTFS}/var/volatile -mindepth 1 -delete
                fi
        fi
}

# Turn any symbolic /sbin/init link into a file
remove_init_link () {
        if [ -h ${IMAGE_ROOTFS}/sbin/init ]; then
                LINKFILE=${IMAGE_ROOTFS}`readlink ${IMAGE_ROOTFS}/sbin/init`
                rm ${IMAGE_ROOTFS}/sbin/init
                cp $LINKFILE ${IMAGE_ROOTFS}/sbin/init
        fi
}



make_zimage_symlink_relative () {
        if [ -L ${IMAGE_ROOTFS}/boot/zImage ]; then
                (cd ${IMAGE_ROOTFS}/boot/ && for i in `ls zImage-* | sort`; do ln -sf $i zImage; done)
        fi
}

python write_image_manifest () {
    from oe.rootfs import image_list_installed_packages
    with open(d.getVar('IMAGE_MANIFEST', True), 'w+') as image_manifest:
        image_manifest.write(image_list_installed_packages(d, 'ver'))
        image_manifest.write("\n")
}

# Can be use to create /etc/timestamp during image construction to give a reasonably
# sane default time setting
rootfs_update_timestamp () {
        date -u +%4Y%2m%2d%2H%2M%2S >${IMAGE_ROOTFS}/etc/timestamp
}

# Prevent X from being started
rootfs_no_x_startup () {
        if [ -f ${IMAGE_ROOTFS}/etc/init.d/xserver-nodm ]; then
                chmod a-x ${IMAGE_ROOTFS}/etc/init.d/xserver-nodm
        fi
}

rootfs_trim_schemas () {
        for schema in ${IMAGE_ROOTFS}/etc/gconf/schemas/*.schemas
        do
                # Need this in case no files exist
                if [ -e $schema ]; then
                        oe-trim-schemas $schema > $schema.new
                        mv $schema.new $schema
                fi
        done
}

rootfs_check_host_user_contaminated () {
        contaminated="${WORKDIR}/host-user-contaminated.txt"
        HOST_USER_UID="$(PSEUDO_UNLOAD=1 id -u)"
        HOST_USER_GID="$(PSEUDO_UNLOAD=1 id -g)"

        find "${IMAGE_ROOTFS}" -wholename "${IMAGE_ROOTFS}/home" -prune \
            -user "$HOST_USER_UID" -o -group "$HOST_USER_GID" >"$contaminated"

        if [ -s "$contaminated" ]; then
                echo "WARNING: Paths in the rootfs are owned by the same user or group as the user runni
ng bitbake. See the logfile for the specific paths."
                cat "$contaminated" | sed "s,^,  ,"
        fi
}

# Make any absolute links in a sysroot relative
rootfs_sysroot_relativelinks () {
        sysroot-relativelinks.py ${SDK_OUTPUT}/${SDKTARGETSYSROOT}
}

do_fetch[noexec] = "1"
do_unpack[noexec] = "1"
do_patch[noexec] = "1"
do_configure[noexec] = "1"
do_compile[noexec] = "1"
do_install[noexec] = "1"
do_populate_sysroot[noexec] = "1"
do_package[noexec] = "1"
do_package_qa[noexec] = "1"
do_packagedata[noexec] = "1"
do_package_write_ipk[noexec] = "1"
do_package_write_deb[noexec] = "1"
do_package_write_rpm[noexec] = "1"

addtask rootfs before do_build
# Allow the kernel to be repacked with the initramfs and boot image file as a single file
do_bundle_initramfs[depends] += "virtual/kernel:do_bundle_initramfs"
do_bundle_initramfs[nostamp] = "1"
do_bundle_initramfs[noexec] = "1"
do_bundle_initramfs () {
        :
}
addtask bundle_initramfs after do_rootfs

1420

參考 BitBake User Manual - 3.6. Tasks

addtask 來看 sources/poky/meta/classes/image.bbclass

...
addtask rootfs before do_build
...
addtask bundle_initramfs after do_rootfs

先做的 task 是 do_rootfs

do_rootfs 來看 sources/poky/meta/classes/image.bbclass

...
do_rootfs[depends] += " \
    makedevs-native:do_populate_sysroot virtual/fakeroot-native:do_populate_sysroot ${LDCONFIGDEPEND} \
    virtual/update-alternatives-native:do_populate_sysroot update-rc.d-native:do_populate_sysroot \
    ${KERNELDEPMODDEPEND} \
"
do_rootfs[recrdeptask] += "do_packagedata"
...
do_rootfs[vardeps] += "${@rootfs_variables(d)}"
...
do_rootfs[dirs] = "${TOPDIR}"
do_rootfs[lockfiles] += "${IMAGE_ROOTFS}.lock"
do_rootfs[cleandirs] += "${S}"
...
do_rootfs[umask] = "022"
...
do_rootfs[prefuncs] += "rootfs_process_ignore"
...
do_rootfs[prefuncs] += "rootfs_runtime_mapping"
...
fakeroot python do_rootfs () {
    from oe.rootfs import create_rootfs
    from oe.image import create_image
    from oe.manifest import create_manifest

    # generate the initial manifest
    create_manifest(d)

    # generate rootfs
    create_rootfs(d)

    # generate final images
    create_image(d)
}

BitBake User Manual - 3.7. Variable Flags 可以了解什麼是

  • do_rootfs[depends]
  • do_rootfs[recrdeptask]
  • do_rootfs[vardeps]
  • do_rootfs[dirs]
  • do_rootfs[lockfiles]
  • do_rootfs[cleandirs]
  • do_rootfs[umask]
  • do_rootfs[prefuncs]

其中 do_rootfs[prefuncs] 會影響 task 的執行順序

do_rootfs[prefuncs] += "rootfs_process_ignore"
...
do_rootfs[prefuncs] += "rootfs_runtime_mapping"

會發現整個 log.do_rootfs 的內容就做了這三件事

  • rootfs_process_ignore
  • rootfs_runtime_mapping
  • do_rootfs
DEBUG: Executing python function rootfs_process_ignore
DEBUG: Python function rootfs_process_ignore finished
DEBUG: Executing python function rootfs_runtime_mapping
DEBUG: Python function rootfs_runtime_mapping finished
DEBUG: Executing python function do_rootfs
...
DEBUG: Python function do_rootfs finished

1440

專注在 sources/poky/meta/classes/image.bbclassfakeroot python do_rootfs ()

fakeroot python do_rootfs () {
    from oe.rootfs import create_rootfs
    from oe.image import create_image
    from oe.manifest import create_manifest

    # generate the initial manifest
    create_manifest(d)

    # generate rootfs
    create_rootfs(d)

    # generate final images
    create_image(d)
}

配合 21.5.5. Image Generation 會發現

The do_rootfs task creates the root filesystem (file and directory structure) for an image.

do_rootfs 做了三件事

  • generate the initial manifest
    • create_manifest(d)
    • source code 在 sources/poky/meta/lib/oe/manifest.py
  • generate rootfs
    • create_rootfs(d)
    • source code 在 sources/poky/meta/lib/oe/rootfs.py
  • generate final images
    • create_image(d)
    • source code 在 sources/poky/meta/lib/oe/image.py

create_manifest(d) 所在的 manifest.py 沒使用到 bb.note()

所以沒在 log.do_rootfs 的內容發現相關的 log

1500

create_rootfs(d)log.do_rootfs 的內容從 15 行開始

...
NOTE: ###### Generate rootfs #######
...

1515

create_image(d) 在 在 log.do_rootfs 的內容從 279 行開始

...
NOTE: ###### Generate images #######
...
NOTE: The image creation groups are: [['ext4', 'tar'], ['nandflash', 'sdcard']]
...
NOTE: Running image creation script for ext4: /var/m300/build_small/tmp/work/m300-poky-linux-gnueabi/core-image-minimal/1.0-r0/temp/create_image.ext4 ...
...
NOTE: Running image creation script for tar: /var/m300/build_small/tmp/work/m300-poky-linux-gnueabi/core-image-minimal/1.0-r0/temp/create_image.tar ...
...
NOTE: Running image creation script for nandflash: /var/m300/build_small/tmp/work/m300-poky-linux-gnueabi/core-image-minimal/1.0-r0/temp/create_image.nandflash ...
...
NOTE: Running image creation script for sdcard: /var/m300/build_small/tmp/work/m300-poky-linux-gnueabi/core-image-minimal/1.0-r0/temp/create_image.sdcard ...
...

1540

這些 image creation script 是怎麼跑出來的可以參考 IMAGE_CMD

Specifies the command to create the image file for a specific image type, which corresponds to the value set set in IMAGE_FSTYPES, (e.g. ext3, btrfs, and so forth). When setting this variable, you should use an override for the associated type. Here is an example:

IMAGE_CMD_jffs2 = "mkfs.jffs2 --root=${IMAGE_ROOTFS} \
   --faketime --output=${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.rootfs.jffs2 \
   ${EXTRA_IMAGECMD}"

You typically do not need to set this variable unless you are adding support for a new image type. For more examples on how to set this variable, see the image_types class file, which is meta/classes/image_types.bbclass.

1555

先看 create_image.ext4 這個 image creation script

這個 script 產生的由來要看到 sources/poky/meta/classes/image_types.bbclass

...
oe_mkext234fs () {
	fstype=$1
	extra_imagecmd=""

	if [ $# -gt 1 ]; then
		shift
		extra_imagecmd=$@
	fi

	# If generating an empty image the size of the sparse block should be large
	# enough to allocate an ext4 filesystem using 4096 bytes per inode, this is
	# about 60K, so dd needs a minimum count of 60, with bs=1024 (bytes per IO)
	eval local COUNT=\"0\"
	eval local MIN_COUNT=\"60\"
	if [ $ROOTFS_SIZE -lt $MIN_COUNT ]; then
		eval COUNT=\"$MIN_COUNT\"
	fi
	# Create a sparse image block
	dd if=/dev/zero of=${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.rootfs.$fstype seek=$ROOTFS_SIZE count=$COUNT bs=1024
	mkfs.$fstype -F $extra_imagecmd ${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.rootfs.$fstype -d ${IMAGE_ROOTFS}
}
...
IMAGE_CMD_ext4 = "oe_mkext234fs ext4 ${EXTRA_IMAGECMD}"
...
EXTRA_IMAGECMD_ext4 ?= "-i 4096"
...

1605

再來看 create_image.tar 這個 image creation script

一樣看到 sources/poky/meta/classes/image_types.bbclass

...
IMAGE_CMD_TAR ?= "tar"
IMAGE_CMD_tar = "${IMAGE_CMD_TAR} -cvf ${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.rootfs.tar -C ${IMAGE_ROOTFS} ."
...

1610

看到 create_image.nandflash 這個 image creation script

這個 script 產生的由來要參考 meta-proscend/classes/image_types_proscend.bbclass

...
NANDFLASH_GENERATION_COMMAND_mx6ul = "generate_imx_nandflash"
...
generate_imx_nandflash () {
    # clean up
    rm -rf ${FIRMWARE_DIR}
    rm -f `readlink ${DEPLOY_DIR_IMAGE}/${NANDFLASH}`
    rm -f ${DEPLOY_DIR_IMAGE}/${NANDFLASH}

    mkdir -p ${FIRMWARE_DIR}
    case "${IMAGE_BOOTLOADER}" in
        imx-bootlets)
            bberror "The imx-bootlets is not supported for i.MX based machines"
            exit 1
            ;;
        u-boot)
            cp ${DEPLOY_DIR_IMAGE}/u-boot-${MACHINE}.${UBOOT_SUFFIX_NANDFLASH} ${FIRMWARE_DIR}
            ;;
        barebox)
            bberror "The imx-bootlets is not supported for i.MX based machines"
            exit 1
            ;;
        "")
            ;;
        *)
            bberror "Unknown IMAGE_BOOTLOADER value"
            exit 1
            ;;
    esac

    if [ -z "${NANDFLASH_ROOTFS_NAME}" ]; then
        bberror "NANDFLASH_ROOTFS_NAME is not defined. To use nandflash image from Proscend it needs to be defined."
        exit 1
    fi

    # Encrypt rootfs using triple DES in CBC mode with password(2wsx#EDC)
    echo "Encrypt rootfs using triple DES in CBC mode with password(2wsx#EDC)"
    openssl des3 -salt -in ${NANDFLASH_ROOTFS} -out ${FIRMWARE_DIR}/${NANDFLASH_ROOTFS_NAME}.enc -k 2wsx#EDC
    #cp ${NANDFLASH_ROOTFS} ${FIRMWARE_DIR}/${NANDFLASH_ROOTFS_NAME}
    if [ $? != 0 ]; then
        bberror "NANDFLASH_ROOTFS is not found. To use nandflash image from Proscend it needs to be generated."
        exit 1
    fi

    # Copy device tree file
    if test -n "${KERNEL_DEVICETREE}"; then
        for DTS_FILE in ${KERNEL_DEVICETREE}; do
            DTS_BASE_NAME=`basename ${DTS_FILE} | awk -F "." '{print $1}'`
            if [ -e "${DEPLOY_DIR_IMAGE}/${KERNEL_IMAGETYPE}-${DTS_BASE_NAME}.dtb" ]; then
                cp "${DEPLOY_DIR_IMAGE}/${KERNEL_IMAGETYPE}-${DTS_BASE_NAME}.dtb" ${FIRMWARE_DIR}
            else
                bbfatal "${DTS_FILE} does not exist."
            fi
        done
    fi

    if [ -e "${DEPLOY_DIR_IMAGE}/${KERNEL_IMAGETYPE}-${MACHINE}.bin" ]; then
        cp "${DEPLOY_DIR_IMAGE}/${KERNEL_IMAGETYPE}-${MACHINE}.bin" ${FIRMWARE_DIR}/zImage
    fi

    # Encrypt proscend MCSV file using triple DES in CBC mode with password(2wsx#EDC)
    if [ -e "${DEPLOY_DIR_IMAGE}/mcsv" ]
    then
        openssl des3 -salt -in ${DEPLOY_DIR_IMAGE}/mcsv -out ${DEPLOY_DIR_IMAGE}/mcsv.enc -k 2wsx#EDC
        # Copy encryped MCSV - mcsv.enc
        cp ${DEPLOY_DIR_IMAGE}/mcsv.enc ${FIRMWARE_DIR}
    else
        bberror "MCSV is not found. To use nandflash image from Proscend it needs to be generated."
        exit 1
    fi

    # Print MD5 checksums for all images in the firmware folder into file `firmware.md5`
    cd ${FIRMWARE_DIR}
    md5sum * > firmware.md5
    cd -

    # Encrypt firmware_patch.sh file using triple DES in CBC mode with password(2wsx#EDC)
    if [ -e "${DEPLOY_DIR_IMAGE}/firmware_patch.sh" ]
    then
        openssl des3 -salt -in ${DEPLOY_DIR_IMAGE}/firmware_patch.sh -out ${DEPLOY_DIR_IMAGE}/firmware_patch.enc -k 2wsx#EDC
        # Copy encryped firmware_patch.sh - firmware_patch.enc
        cp ${DEPLOY_DIR_IMAGE}/firmware_patch.enc ${FIRMWARE_DIR}
    else
        bberror "firmware_patch.sh is not found. To use nandflash image from Proscend it needs to be generated."
        exit 1
    fi



    filename=$(date "+${MACHINE}_%Y%m%d%H%M%S.img")
    cd ${DEPLOY_DIR_IMAGE}
    tar -cf ${filename} firmware
    ln -s ${filename} ${NANDFLASH}
    cd -
}
...
IMAGE_CMD_nandflash () {
    if [ -z "${NANDFLASH_ROOTFS}" ]; then
        bberror "NANDFLASH_ROOTFS is undefined. To use nandflash image from Proscend it needs to be defined."
        exit 1
    fi

    ${NANDFLASH_GENERATION_COMMAND}
}

1620

最後來看 create_image.sdcard 這個 image creation script

這個 script 產生的由來要參考 meta-fsl-arm/classes/image_types_fsl.bbclass

...
SDCARD_GENERATION_COMMAND_mx6ul = "generate_imx_sdcard"
...
#
# Generate the boot image with the boot scripts and required Device Tree
# files
_generate_boot_image() {
	local boot_part=$1

	# Create boot partition image
	BOOT_BLOCKS=$(LC_ALL=C parted -s ${SDCARD} unit b print \
	                  | awk "/ $boot_part / { print substr(\$4, 1, length(\$4 -1)) / 1024 }")

	# mkdosfs will sometimes use FAT16 when it is not appropriate,
	# resulting in a boot failure from SYSLINUX. Use FAT32 for
	# images larger than 512MB, otherwise let mkdosfs decide.
	if [ $(expr $BOOT_BLOCKS / 1024) -gt 512 ]; then
		FATSIZE="-F 32"
	fi

	rm -f ${WORKDIR}/boot.img
	mkfs.vfat -n "${BOOTDD_VOLUME_ID}" -S 512 ${FATSIZE} -C ${WORKDIR}/boot.img $BOOT_BLOCKS

	mcopy -i ${WORKDIR}/boot.img -s ${DEPLOY_DIR_IMAGE}/${KERNEL_IMAGETYPE}-${MACHINE}.bin ::/${KERNEL_IMAGETYPE}

	# Copy boot scripts
	for item in ${BOOT_SCRIPTS}; do
		src=`echo $item | awk -F':' '{ print $1 }'`
		dst=`echo $item | awk -F':' '{ print $2 }'`

		mcopy -i ${WORKDIR}/boot.img -s ${DEPLOY_DIR_IMAGE}/$src ::/$dst
	done

	# Copy device tree file
	if test -n "${KERNEL_DEVICETREE}"; then
		for DTS_FILE in ${KERNEL_DEVICETREE}; do
			DTS_BASE_NAME=`basename ${DTS_FILE} | awk -F "." '{print $1}'`
			if [ -e "${DEPLOY_DIR_IMAGE}/${KERNEL_IMAGETYPE}-${DTS_BASE_NAME}.dtb" ]; then
				kernel_bin="`readlink ${DEPLOY_DIR_IMAGE}/${KERNEL_IMAGETYPE}-${MACHINE}.bin`"
				kernel_bin_for_dtb="`readlink ${DEPLOY_DIR_IMAGE}/${KERNEL_IMAGETYPE}-${DTS_BASE_NAME}.dtb | sed "s,$DTS_BASE_NAME,${MACHINE},g;s,\.dtb$,.bin,g"`"
				if [ $kernel_bin = $kernel_bin_for_dtb ]; then
					mcopy -i ${WORKDIR}/boot.img -s ${DEPLOY_DIR_IMAGE}/${KERNEL_IMAGETYPE}-${DTS_BASE_NAME}.dtb ::/${DTS_BASE_NAME}.dtb
				fi
			else
				bbfatal "${DTS_FILE} does not exist."
			fi
		done
	fi
}
...
#
# Create an image that can by written onto a SD card using dd for use
# with i.MX SoC family
#
# External variables needed:
#   ${SDCARD_ROOTFS}    - the rootfs image to incorporate
#   ${IMAGE_BOOTLOADER} - bootloader to use {u-boot, barebox}
#
# The disk layout used is:
#
#    0                      -> IMAGE_ROOTFS_ALIGNMENT         - reserved to bootloader (not partitioned)
#    IMAGE_ROOTFS_ALIGNMENT -> BOOT_SPACE                     - kernel and other data
#    BOOT_SPACE             -> SDIMG_SIZE                     - rootfs
#
#                                                     Default Free space = 1.3x
#                                                     Use IMAGE_OVERHEAD_FACTOR to add more space
#                                                     <--------->
#            4MiB               8MiB           SDIMG_ROOTFS                    4MiB
# <-----------------------> <----------> <----------------------> <------------------------------>
#  ------------------------ ------------ ------------------------ -------------------------------
# | IMAGE_ROOTFS_ALIGNMENT | BOOT_SPACE | ROOTFS_SIZE            |     IMAGE_ROOTFS_ALIGNMENT    |
#  ------------------------ ------------ ------------------------ -------------------------------
# ^                        ^            ^                        ^                               ^
# |                        |            |                        |                               |
# 0                      4096     4MiB +  8MiB       4MiB +  8Mib + SDIMG_ROOTFS   4MiB +  8MiB + SDIMG_ROOTFS + 4MiB
generate_imx_sdcard () {
	# Create partition table
	parted -s ${SDCARD} mklabel msdos
	parted -s ${SDCARD} unit KiB mkpart primary fat32 ${IMAGE_ROOTFS_ALIGNMENT} $(expr ${IMAGE_ROOTFS_ALIGNMENT} \+ ${BOOT_SPACE_ALIGNED})
	parted -s ${SDCARD} unit KiB mkpart primary $(expr  ${IMAGE_ROOTFS_ALIGNMENT} \+ ${BOOT_SPACE_ALIGNED}) $(expr ${IMAGE_ROOTFS_ALIGNMENT} \+ ${BOOT_SPACE_ALIGNED} \+ $ROOTFS_SIZE)
	parted ${SDCARD} print

	# Burn bootloader
	case "${IMAGE_BOOTLOADER}" in
		imx-bootlets)
		bberror "The imx-bootlets is not supported for i.MX based machines"
		exit 1
		;;
		u-boot)
		if [ -n "${SPL_BINARY}" ]; then
			dd if=${DEPLOY_DIR_IMAGE}/${SPL_BINARY} of=${SDCARD} conv=notrunc seek=2 bs=512
			dd if=${DEPLOY_DIR_IMAGE}/u-boot-${MACHINE}.${UBOOT_SUFFIX_SDCARD} of=${SDCARD} conv=notrunc seek=69 bs=1K
		else
			dd if=${DEPLOY_DIR_IMAGE}/u-boot-${MACHINE}.${UBOOT_SUFFIX_SDCARD} of=${SDCARD} conv=notrunc seek=2 bs=512
		fi
		;;
		barebox)
		dd if=${DEPLOY_DIR_IMAGE}/barebox-${MACHINE}.bin of=${SDCARD} conv=notrunc seek=1 skip=1 bs=512
		dd if=${DEPLOY_DIR_IMAGE}/bareboxenv-${MACHINE}.bin of=${SDCARD} conv=notrunc seek=1 bs=512k
		;;
		"")
		;;
		*)
		bberror "Unknown IMAGE_BOOTLOADER value"
		exit 1
		;;
	esac

	_generate_boot_image 1

	# Burn Partition
	dd if=${WORKDIR}/boot.img of=${SDCARD} conv=notrunc,fsync seek=1 bs=$(expr ${IMAGE_ROOTFS_ALIGNMENT} \* 1024)
	dd if=${SDCARD_ROOTFS} of=${SDCARD} conv=notrunc,fsync seek=1 bs=$(expr ${BOOT_SPACE_ALIGNED} \* 1024 + ${IMAGE_ROOTFS_ALIGNMENT} \* 1024)
}
...
IMAGE_CMD_sdcard () {
	if [ -z "${SDCARD_ROOTFS}" ]; then
		bberror "SDCARD_ROOTFS is undefined. To use sdcard image from Freescale's BSP it needs to be defined."
		exit 1
	fi

	# Align boot partition and calculate total SD card image size
	BOOT_SPACE_ALIGNED=$(expr ${BOOT_SPACE} + ${IMAGE_ROOTFS_ALIGNMENT} - 1)
	BOOT_SPACE_ALIGNED=$(expr ${BOOT_SPACE_ALIGNED} - ${BOOT_SPACE_ALIGNED} % ${IMAGE_ROOTFS_ALIGNMENT})
	SDCARD_SIZE=$(expr ${IMAGE_ROOTFS_ALIGNMENT} + ${BOOT_SPACE_ALIGNED} + $ROOTFS_SIZE + ${IMAGE_ROOTFS_ALIGNMENT})

	# Initialize a sparse file
	dd if=/dev/zero of=${SDCARD} bs=1 count=0 seek=$(expr 1024 \* ${SDCARD_SIZE})

	${SDCARD_GENERATION_COMMAND}
}
⚠️ **GitHub.com Fallback** ⚠️