<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>i.MX ProcessorsのトピックRe: i.MX8M Mini secure boot Yocto bbappend</title>
    <link>https://community.nxp.com/t5/i-MX-Processors/i-MX8M-Mini-secure-boot-Yocto-bbappend/m-p/1530331#M195797</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.nxp.com/t5/user/viewprofilepage/user-id/140851"&gt;@craigmcqueenir&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;As far as I know, there is no ready-made solution for building secure boot in Yocto. Apologies for that.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;You can have a try to apply for Prosupport from the link:&amp;nbsp;&lt;A href="https://www.nxp.com/support/support/nxp-engineering-services/professional-engineering-services:PROFESSIONAL-ENGINEERING-SERVICES" target="_blank"&gt;Professional Engineering Services | NXP Semiconductors&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Best regards&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Harvey&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Best regards&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Harvey&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 29 Sep 2022 10:19:46 GMT</pubDate>
    <dc:creator>Harvey021</dc:creator>
    <dc:date>2022-09-29T10:19:46Z</dc:date>
    <item>
      <title>i.MX8M Mini secure boot Yocto bbappend</title>
      <link>https://community.nxp.com/t5/i-MX-Processors/i-MX8M-Mini-secure-boot-Yocto-bbappend/m-p/1529870#M195764</link>
      <description>&lt;P&gt;I am working on a system based on i.MX8M Mini, Yocto kirkstone, U-Boot v2021.04. It is derived from the imx8mm machine.&lt;/P&gt;&lt;P&gt;I have a complete working system, but I want to enable secure boot for U-Boot etc.&lt;/P&gt;&lt;P&gt;I've been following the instructions in the document &lt;A href="https://source.codeaurora.org/external/imx/uboot-imx/tree/doc/imx/habv4/guides/mx8m_secure_boot.txt?h=lf_v2021.04&amp;amp;id=f7b43f8b4c1e4e3ee6c6ff2fe9c61b2092e8b96b" target="_self" rel="nofollow noopener noreferrer"&gt;doc/imx/habv4/guides/mx8m_secure_boot.txt&lt;/A&gt; in the &lt;A href="https://source.codeaurora.org/external/imx/uboot-imx/commit/?h=lf_v2021.04&amp;amp;id=f7b43f8b4c1e4e3ee6c6ff2fe9c61b2092e8b96b" target="_self" rel="nofollow noopener noreferrer"&gt;U-Boot v2021.04 source code&lt;/A&gt;, but I want to automate the process in Yocto, rather than doing it manually.&lt;/P&gt;&lt;P&gt;In case anyone is interested, I'm sharing what I have done in an &lt;STRONG&gt;imx-boot_%.bbappend&lt;/STRONG&gt; file.&lt;/P&gt;&lt;P&gt;As in my other recent question &lt;A href="https://community.nxp.com/t5/i-MX-Processors/i-MX8M-Mini-secure-boot-HAB-errors/m-p/1529599" target="_self"&gt;i.MX8M Mini secure boot HAB errors&lt;/A&gt;, I was getting HAB errors. Now I think I have resolved the remaining issues, and my U-Boot build is being successfully verified, with my edits to this post.&lt;/P&gt;&lt;P&gt;Note though that I've commented a "hack" that is specific to the imx8mm that I'm using—as noted in the code. This is to work around issues with the way the &lt;STRONG&gt;print_fit_hab.sh&lt;/STRONG&gt; calculates the block values, versus the way the build pads the various binary files.&lt;/P&gt;&lt;P&gt;I've tested this with &lt;A href="https://github.com/Freescale/meta-freescale.git" target="_self"&gt;&lt;STRONG&gt;meta-freescale&lt;/STRONG&gt;&lt;/A&gt; branch &lt;STRONG&gt;kirkstone&lt;/STRONG&gt; commit 2e785f257ad98581b684f0e32f6d4bb96faefb10, which in the&amp;nbsp;&lt;STRONG&gt;imx-boot&lt;/STRONG&gt; recipe uses &lt;A href="https://source.codeaurora.org/external/imx/imx-mkimage.git" target="_self"&gt;&lt;STRONG&gt;imx-mkimage&lt;/STRONG&gt;&lt;/A&gt; branch &lt;STRONG&gt;lf-5.15.5_1.0.0&lt;/STRONG&gt; commit 22346a32a88aa752d4bad8f2ed1eb641e18849dc.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;imx-boot_%.bbappend&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;FILESEXTRAPATHS:prepend := "${THISDIR}/files:"

SRC_URI:append = "file://crts file://keys file://csf_fit.txt.template file://csf_spl.txt.template"

# libpcre-native for pcregrep-native
# imx-mkimage for print_fit_hab.sh script -- not needed in DEPENDS because imx-boot includes it directly.
# imx-cst-native for code signing
DEPENDS:append = " libpcre-native imx-cst-native"

do_compile:append () {
    # Extract ATF_LOAD_ADDR from output of mkimage in temp/log.do_compile
    # (Testing has verified the symlink temp/log.do_compile points to the current log file even while do_compile is in-progress)
    ATF_LOAD_ADDR=$(cat "${T}/log.do_compile" | pcregrep -o1 'ATF_LOAD_ADDR=(\w*)')
    bbnote "ATF_LOAD_ADDR: ${ATF_LOAD_ADDR}"
    TEE_LOAD_ADDR=$(cat "${T}/log.do_compile" | pcregrep -o1 'TEE_LOAD_ADDR=(\w*)')
    bbnote "TEE_LOAD_ADDR: ${TEE_LOAD_ADDR}"

    # Extract SPL CSF offset from output of mkimage in temp/log.do_compile
    SPL_CSF_OFFSET=$(cat "${T}/log.do_compile" | pcregrep -o1 '^[[:blank:]]*csf_off[[:blank:]]*(\w*)')
    bbnote "SPL_CSF_OFFSET: ${SPL_CSF_OFFSET}"

    # Extract FIT CSF offset from output of mkimage in temp/log.do_compile
    FIT_CSF_OFFSET=$(cat "${T}/log.do_compile" | pcregrep -o1 '^[[:blank:]]*sld_csf_off[[:blank:]]*(\w*)')
    bbnote "FIT_CSF_OFFSET: ${FIT_CSF_OFFSET}"

    # Extract spl hab block values from output of mkimage in temp/log.do_compile
    SPL_HAB_BLOCK=$(cat "${T}/log.do_compile" | pcregrep -o1 '^[[:blank:]]*spl hab block:[[:blank:]]*(.*)$')
    bbnote "spl hab block: ${SPL_HAB_BLOCK}"

    # Extract sld hab block values from output of mkimage in temp/log.do_compile
    SLD_HAB_BLOCK=$(cat "${T}/log.do_compile" | pcregrep -o1 '^[[:blank:]]*sld hab block:[[:blank:]]*(.*)$')
    bbnote "sld hab block: ${SLD_HAB_BLOCK}"

    # Extract more fit address values using print_fit_hab.sh script
    bbnote print_fit_hab.sh
    # Hack for padding of DTB like the iMX8M soc.mak does it (unfortunately soc.mak deletes the padded DTB when it's done).
    # TODO: Clean up this hack.
    cp ${BOOT_STAGING}/${UBOOT_DTB_NAME} ${BOOT_STAGING}/${UBOOT_DTB_NAME}.pad
    scripts/pad_image.sh ${BOOT_STAGING}/u-boot-nodtb.bin ${BOOT_STAGING}/${UBOOT_DTB_NAME}.pad
    if ${DEPLOY_OPTEE}; then
        export BL32=${BOOT_STAGING}/tee.bin
    fi
    FIT_HAB=$(VERSION=v1 \
        BL31=${BOOT_STAGING}/bl31.bin \
        BL33=${BOOT_STAGING}/u-boot-nodtb.bin \
        ATF_LOAD_ADDR=${ATF_LOAD_ADDR} \
        TEE_LOAD_ADDR=${TEE_LOAD_ADDR} \
        ${S}/iMX8M/print_fit_hab.sh \
        0x60000 ${BOOT_STAGING}/${UBOOT_DTB_NAME}.pad)
    echo "${FIT_HAB}"

    for target in ${IMXBOOT_TARGETS}; do
        # Use code-signing tool to sign the flash.bin
        # First, SPL
        cp ${WORKDIR}/csf_spl.txt.template csf_spl.txt
        echo "    Blocks = ${SPL_HAB_BLOCK} \"${BOOT_CONFIG_MACHINE}-${target}\"" &amp;gt;&amp;gt; csf_spl.txt
        cst -i csf_spl.txt -o csf_spl.bin
        # Second, FIT
        cp ${WORKDIR}/csf_fit.txt.template csf_fit.txt
        echo "    Blocks = \\" &amp;gt;&amp;gt; csf_fit.txt
        LINE_OUT="${SLD_HAB_BLOCK} \"${BOOT_CONFIG_MACHINE}-${target}\""
        while read -r LINE_IN; do
            if [ -n "${LINE_OUT}" ]; then
                echo "        ${LINE_OUT}, \\" &amp;gt;&amp;gt; csf_fit.txt
            fi
            LINE_OUT=
            if [ -n "${LINE_IN}" ]; then
                LINE_OUT="${LINE_IN} \"${BOOT_CONFIG_MACHINE}-${target}\""
            fi
        done &amp;lt;&amp;lt;EOF
${FIT_HAB}
EOF
        echo "        ${LINE_OUT}" &amp;gt;&amp;gt; csf_fit.txt
        cst -i csf_fit.txt -o csf_fit.bin

        # Insert the signature blocks into the flash.bin
        # First make a copy of the flash.bin
        cp ${BOOT_CONFIG_MACHINE}-${target} ${BOOT_CONFIG_MACHINE}-${target}-signed
        # Insert csf_spl.bin in signed flash.bin at SPL_CSF_OFFSET offset
        SPL_CSF_OFFSET_DEC=$(printf "%d" ${SPL_CSF_OFFSET})
        dd if=csf_spl.bin of=${BOOT_CONFIG_MACHINE}-${target}-signed seek=${SPL_CSF_OFFSET_DEC} bs=1 conv=notrunc
        # Insert csf_fit.bin in signed flash.bin at FIT_CSF_OFFSET offset
        FIT_CSF_OFFSET_DEC=$(printf "%d" ${FIT_CSF_OFFSET})
        dd if=csf_fit.bin of=${BOOT_CONFIG_MACHINE}-${target}-signed seek=${FIT_CSF_OFFSET_DEC} bs=1 conv=notrunc
    done
}

do_deploy:append () {
    for target in ${IMXBOOT_TARGETS}; do
        install -m 0644 ${S}/${BOOT_CONFIG_MACHINE}-${target}-signed ${DEPLOYDIR}
    done
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 03 Oct 2022 12:30:08 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-Processors/i-MX8M-Mini-secure-boot-Yocto-bbappend/m-p/1529870#M195764</guid>
      <dc:creator>craigmcqueenir</dc:creator>
      <dc:date>2022-10-03T12:30:08Z</dc:date>
    </item>
    <item>
      <title>Re: i.MX8M Mini secure boot Yocto bbappend</title>
      <link>https://community.nxp.com/t5/i-MX-Processors/i-MX8M-Mini-secure-boot-Yocto-bbappend/m-p/1530331#M195797</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.nxp.com/t5/user/viewprofilepage/user-id/140851"&gt;@craigmcqueenir&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;As far as I know, there is no ready-made solution for building secure boot in Yocto. Apologies for that.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;You can have a try to apply for Prosupport from the link:&amp;nbsp;&lt;A href="https://www.nxp.com/support/support/nxp-engineering-services/professional-engineering-services:PROFESSIONAL-ENGINEERING-SERVICES" target="_blank"&gt;Professional Engineering Services | NXP Semiconductors&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Best regards&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Harvey&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Best regards&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Harvey&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Sep 2022 10:19:46 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-Processors/i-MX8M-Mini-secure-boot-Yocto-bbappend/m-p/1530331#M195797</guid>
      <dc:creator>Harvey021</dc:creator>
      <dc:date>2022-09-29T10:19:46Z</dc:date>
    </item>
  </channel>
</rss>

