Skip to main content
Explorer
May 7, 2025
Solved

"How to create your own machine" in wiki and hits optee CFG_DRAM_SIZE bug

  • May 7, 2025
  • 5 replies
  • 1128 views

Following the instructions here: https://wiki.st.com/stm32mpu/index.php/How_to_create_your_own_machine

And then making a trivial devicetree modification (enabling I2C5 output) fails to build on a fresh yocto install (via the "distribution package").  I'm beginning to port code from a DK2 to a custom board, and creating a transitional package.

The build slams right into the `flavorlist` mess in the optee make confs (specifically workspace/sources/optee-os-stm32mp/core/arch/arm/plat-stm32mp1/conf.mk) , ignoring the `CUBEMX_BOARD_DDR_SIZE = "512"` variables or anything else..

Very frustrating to see all these hardcoded filenames when yocto is very aware of the actual device tree in use at buildtime... looks like maybe the intended `CFG_EXT_DTS` escape hatch is broken?

Lots of previous posts have hit this problem, but on custom hardware, and with more significant DT changes.  I didn't touch the RAM or anything else other than have a default DK2 template MX project and then enable/"okay" I2C5.

    This topic has been closed for replies.
    Best answer by mmichala

    Hello @0xedbea4 
    I had similar issue:
    1. I used STM32MP135F-DK board, opened it's project in CubeMX (via Board Selector) and generated Device Tree.

    2. Then, during Yocto build, there was this CFG_DRAM_SIZE bug (missmatch).

    As far as I understand it, optee sets CFG_DRAM_SIZE basing on DT name. And for unknown DT names (like mine, because it was generated from CubeMX) its sets default CFG_DRAM_SIZE to 1 GB. STM32MP135F-DK uses 512 MB and that value is defined in it's DT. So there is a missmatch and CFG_DRAM_SIZE bug occurs.

    3. To fix it, I created a patch for optee, to set default CFG_DRAM_SIZE to 512 MB instead of 1 GB for unknown DT names. The patch is:

    diff --git a/conf.mk.orginal b/conf.mk
    index 2600f51..ec1e0e6 100644
    --- a/core/arch/arm/plat-stm32mp1/conf.mk
    +++ b/core/arch/arm/plat-stm32mp1/conf.mk
    @@ -291,7 +291,7 @@ CFG_DRAM_SIZE ?= 0x20000000
     endif
     
     CFG_DRAM_BASE ?= 0xc0000000
    -CFG_DRAM_SIZE ?= 0x40000000
    +CFG_DRAM_SIZE ?= 0x20000000
     ifeq ($(CFG_STM32MP15)-$(CFG_WITH_PAGER),y-y)
     CFG_TZSRAM_START ?= 0x2ffc0000
     CFG_TZSRAM_SIZE ?= 0x00040000

    To apply it, I simply created a 

    recipes-bsp/optee-os-stm32mp/optee-os-stm32mp_%.bbappend file like this:

    FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"
    
    SRC_URI:append := " \
    	file://0001-fixed-CFG_DRAM_SIZE-in-conf-mk.patch \
    "

     

    5 replies

    mmichalaAnswer
    Explorer
    May 8, 2025

    Hello @0xedbea4 
    I had similar issue:
    1. I used STM32MP135F-DK board, opened it's project in CubeMX (via Board Selector) and generated Device Tree.

    2. Then, during Yocto build, there was this CFG_DRAM_SIZE bug (missmatch).

    As far as I understand it, optee sets CFG_DRAM_SIZE basing on DT name. And for unknown DT names (like mine, because it was generated from CubeMX) its sets default CFG_DRAM_SIZE to 1 GB. STM32MP135F-DK uses 512 MB and that value is defined in it's DT. So there is a missmatch and CFG_DRAM_SIZE bug occurs.

    3. To fix it, I created a patch for optee, to set default CFG_DRAM_SIZE to 512 MB instead of 1 GB for unknown DT names. The patch is:

    diff --git a/conf.mk.orginal b/conf.mk
    index 2600f51..ec1e0e6 100644
    --- a/core/arch/arm/plat-stm32mp1/conf.mk
    +++ b/core/arch/arm/plat-stm32mp1/conf.mk
    @@ -291,7 +291,7 @@ CFG_DRAM_SIZE ?= 0x20000000
     endif
     
     CFG_DRAM_BASE ?= 0xc0000000
    -CFG_DRAM_SIZE ?= 0x40000000
    +CFG_DRAM_SIZE ?= 0x20000000
     ifeq ($(CFG_STM32MP15)-$(CFG_WITH_PAGER),y-y)
     CFG_TZSRAM_START ?= 0x2ffc0000
     CFG_TZSRAM_SIZE ?= 0x00040000

    To apply it, I simply created a 

    recipes-bsp/optee-os-stm32mp/optee-os-stm32mp_%.bbappend file like this:

    FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"
    
    SRC_URI:append := " \
    	file://0001-fixed-CFG_DRAM_SIZE-in-conf-mk.patch \
    "

     

    0xedbea4Author
    Explorer
    May 8, 2025

    I was thinking something similar.  Many thanks for sharing your work!

    Cheers

    0xedbea4Author
    Explorer
    May 8, 2025

    There's an existing "./layers/meta-st/meta-st-stm32mp-addons/recipes-security/optee/optee-os-stm32mp_%.bbappend" in my dist-package project.  It is clearly TRYING to pick up the CUBEMX_BOARD_DDR_SIZE variable and setup the optee "conf.mk" file and definitely applied by bitbake correctly:

    $ bitbatke-layers show-appends
    ...
    === Matched appended recipes ===
    optee-os-stm32mp_4.0.0.bb:
     .../dist-package/layers/meta-st/meta-st-stm32mp-addons/recipes-security/optee/optee-os-stm32mp_%.bbappend
    
    OUTPUT EDITED TO COMPLY WITH NDA

    STM this file is not doing it's job.

    # Configure recipe for CubeMX
    inherit cubemx-stm32mp
    
    python () {
     soc_package = (d.getVar('CUBEMX_SOC_PACKAGE') or "").split()
     if len(soc_package) > 1:
     bb.fatal('The CUBEMX_SOC_PACKAGE is initialized to: %s ! This var should only contains ONE package version' % soc_package)
    
     ddr_size = d.getVar('CUBEMX_BOARD_DDR_SIZE')
     if ddr_size is not None:
     size = int(ddr_size) * 1024 * 1024
     d.setVar('CUBEMX_BOARD_DDR_SIZE_HEXA', "0x%x" % size)
     else:
     d.setVar('CUBEMX_BOARD_DDR_SIZE_HEXA', "")
    }
    
    # manage paramater value
    # DVFS OFF
    CUBEMX_SOC_DVFS_OFF_option = "\
     ${@bb.utils.contains('CUBEMX_SOC_DVFS_OFF', '1', 'CFG_STM32MP1_CPU_OPP=n FG_SCMI_MSG_PERF_DOMAIN=n', '', d)} \
     "
    
    EXTRA_OEMAKE += "${CUBEMX_SOC_PACKAGE_option} ${CUBEMX_BOARD_DDR_SIZE_option} ${CUBEMX_SOC_DVFS_OFF_option}"
    
    # for generating external dt Makefile
    SOC_OPTEE_CONFIG_SUPPORTED = "MP13 MP15 MP25 MP23"
    
    ST_OPTEE_EXPORT_TA_REF_BOARD:stm32mpcommonmx = "${CUBEMX_DTB}.dts"
    ST_OPTEE_EXPORT_TA_OEMAKE_EXTRA = ""
    # ------------------------------------------------
    # Generate optee conf for usage of EXTERNAL DT with cubemx devicetree
    # ------------------------------------------------
    autogenerate_conf_for_external_dt_cubemx() {
     [ "${ENABLE_CUBEMX_DTB}" -ne 1 ] && return;
     if [ -e "${STAGING_EXTDT_DIR}/${EXTDT_DIR_OPTEE}/conf.mk" ]; then
     [ "${CUBEMX_EXTDT_FORCE_MK}" -ne 1 ] && return
     fi
     echo "# SPDX-License-Identifier: BSD-2-Clause" > ${WORKDIR}/conf.external_dt
     echo "" >> ${WORKDIR}/conf.external_dt
    
     dtb=$(echo ${STM32MP_DEVICETREE} | tr ' ' '\n' | uniq | tr '\n' ' ')
     for supported in ${SOC_OPTEE_CONFIG_SUPPORTED}; do
     echo "# ${supported} boards" >> ${WORKDIR}/conf.external_dt
     for soc in ${STM32MP_SOC_NAME}; do
     soc_maj=$(echo ${soc} | awk '{print toupper($0)}')
     [ "$(echo ${soc_maj} | grep -c ${supported})" -ne 1 ] && continue
     dtb_by_soc=""
     for devicetree in ${dtb}; do
     [ "$(echo ${devicetree} | grep -c ${soc})" -eq 1 ] && dtb_by_soc="${dtb_by_soc} ${devicetree}.dts"
     done
     echo "flavor_dts_file-${supported}-CUBEMX = ${dtb_by_soc}" >> ${WORKDIR}/conf.external_dt
    
     # add platform specific: package (with crypto or not), ddr size, HUK for mp15
     if ${@bb.utils.contains_any('CUBEMX_SOC_PACKAGE',[ 'C', 'F' ],'true','false',d)}; then
     echo "flavorlist-no_cryp = \$(flavor_dts_file-${supported}-CUBEMX)" >> ${WORKDIR}/conf.external_dt
     fi
     case ${CUBEMX_BOARD_DDR_SIZE} in
     512)
     echo "flavorlist-512M = \$(flavor_dts_file-${supported}-CUBEMX)" >> ${WORKDIR}/conf.external_dt
     ;;
     1024)
     echo "flavorlist-1G = \$(flavor_dts_file-${supported}-CUBEMX)" >> ${WORKDIR}/conf.external_dt
     ;;
     *)
     ;;
     esac
     if ${@bb.utils.contains('MACHINE_FEATURES','m33td','true','false',d)}; then
     echo "flavorlist-M33-TDCID = \$(flavor_dts_file-${supported}-CUBEMX)" >> ${WORKDIR}/conf.external_dt
     fi
    
     echo "flavorlist-${supported} += \$(flavor_dts_file-${supported}-CUBEMX)" >> ${WORKDIR}/conf.external_dt
     done
     echo "" >> ${WORKDIR}/conf.external_dt
     done
     echo "" >> ${WORKDIR}/conf.external_dt
    
     cp -f ${WORKDIR}/conf.external_dt ${STAGING_EXTDT_DIR}/${EXTDT_DIR_OPTEE}/conf.mk
    
    }
    python() {
     machine_overrides = d.getVar('MACHINEOVERRIDES').split(':')
     if "stm32mpcommonmx" in machine_overrides:
     d.appendVarFlag('do_configure', 'prefuncs', ' autogenerate_conf_for_external_dt_cubemx')
    }

     

    0xedbea4Author
    Explorer
    May 8, 2025

    A bit more detail since I've gotta stand this board up:

    The bbappend file above DOES successfully manipulate CFG_DRAM_SIZE in the file ./dist-package/build-openstlinuxweston-stm32mp15-XXXXXXXX-mx/workspace/sources/optee-os-stm32mp/oe-workdir/build/opteemin-stm32mp157f-evon001-mx/conf.mk 

    this is not the part of the optee build failing...  the "export-ta" target (which I know absolutely nothing about) is failing, becuase the variable is NOT set there by the configure script

    from ./build-openstlinuxweston-stm32mp15-XXXXXXXXXXXX-mx/workspace/sources/optee-os-stm32mp/oe-workdir/build/export-ta/conf.mk

     

    CFG_DRAM_BASE=0xc0000000
    CFG_DRAM_SIZE=0x40000000
    CFG_DRIVERS_ADC=y

     

    bitbake do_compile fails:

    ```
    .../dist-package/build-openstlinuxweston-stm32mp15-evon001-mx/tmp-glibc/work/stm32mp15_XXXXXXXXX_mx-ostl-linux-gnueabi/optee-os-stm32mp/4.0.0-stm32mp-r1/build/export-ta/core/tee-raw.bin
    | Wrong CFG_DRAM_SIZE 1024MBytes, in device-tree: 512MBytes
    | make: *** [core/arch/arm/plat-stm32mp1/link.mk:17: check_build_variables] Error 1
    ```

    0xedbea4Author
    Explorer
    May 8, 2025

    ooff yeah I'm not messing with the "export-ta" [Trusted Application] stuff on the oe/yocto level... 

    what does work is too modify line 30744 of `./layers/meta-st/meta-st-stm32mp/recipes-security/optee/optee-os/0001-4.0.0-stm32mp-r1.patch`

    0xedbea4_0-1746731817253.png

    to the correct RAM size (0x20000000)