kubiko / imx-gadget

1 stars 5 forks source link

Compilation Error in part: u-boot from override-build #3

Open unklstewy opened 6 months ago

unklstewy commented 6 months ago

@kubiko

RE: source: https://git.launchpad.net/~ondrak/+git/u-boot source-type: git source-tag: lf-6.1.36-2.1.0-uc source-depth: 1 /RE:

When attempting to build the 22/imx8mp-evk branch of the repo I am encountering errors with the "u-boot" part from the override-build scriptlet.

The error occurs in the snapcraft operations when attempting to build this part.

2024-01-11 18:02:04.140 :: HOSTCC tools/lib/fdtdec_common.o
2024-01-11 18:02:04.145 :: HOSTCC tools/lib/fdtdec.o
2024-01-11 18:02:04.162 :: In file included from ./tools/../boot/image-fit-sig.c:22,
2024-01-11 18:02:04.162 :: from tools/boot/image-fit-sig.c:1:
2024-01-11 18:02:04.162 :: ./arch/arm/include/asm/mach-imx/hab.h:22:28: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘attribute’ before ‘{’ token
2024-01-11 18:02:04.162 :: 22 | struct packed ivt_header {
2024-01-11 18:02:04.162 :: | ^
2024-01-11 18:02:04.162 :: ./arch/arm/include/asm/mach-imx/hab.h:29:20: error: field ‘hdr’ has incomplete type
2024-01-11 18:02:04.162 :: 29 | struct ivt_header hdr; / IVT header above /
2024-01-11 18:02:04.162 :: | ^~~
2024-01-11 18:02:04.162 :: ./arch/arm/include/asm/mach-imx/hab.h:39:25: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘
attribute’ before ‘{’ token
2024-01-11 18:02:04.162 :: 39 | struct
packed hab_hdr {
2024-01-11 18:02:04.162 :: | ^
2024-01-11 18:02:04.162 :: ./arch/arm/include/asm/mach-imx/hab.h:46:25: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘attribute’ before ‘{’ token
2024-01-11 18:02:04.163 :: 46 | struct packed evt_def {
2024-01-11 18:02:04.163 :: | ^
2024-01-11 18:02:04.163 :: HOSTCC tools/boot/image.o
2024-01-11 18:02:04.164 :: HOSTCC tools/boot/image-host.o
2024-01-11 18:02:04.164 :: HOSTCC tools/lib/md5.o
2024-01-11 18:02:04.167 :: make[1]: [scripts/Makefile.host:112: tools/boot/image-fit-sig.o] Error 1
2024-01-11 18:02:04.167 :: make[1]:
Waiting for unfinished jobs....
2024-01-11 18:02:04.171 :: In file included from ./tools/../boot/bootm.c:37,
2024-01-11 18:02:04.172 :: from tools/boot/bootm.c:1:
2024-01-11 18:02:04.172 :: ./arch/arm/include/asm/mach-imx/hab.h:22:28: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘attribute’ before ‘{’ token
2024-01-11 18:02:04.172 :: 22 | struct packed ivt_header {
2024-01-11 18:02:04.172 :: | ^
2024-01-11 18:02:04.172 :: ./arch/arm/include/asm/mach-imx/hab.h:29:20: error: field ‘hdr’ has incomplete type
2024-01-11 18:02:04.172 :: 29 | struct ivt_header hdr; / IVT header above /
2024-01-11 18:02:04.172 :: | ^~~
2024-01-11 18:02:04.172 :: ./arch/arm/include/asm/mach-imx/hab.h:39:25: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘
attribute’ before ‘{’ token
2024-01-11 18:02:04.172 :: 39 | struct
packed hab_hdr {
2024-01-11 18:02:04.172 :: | ^
2024-01-11 18:02:04.172 :: ./arch/arm/include/asm/mach-imx/hab.h:46:25: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘
attribute’ before ‘{’ token
2024-01-11 18:02:04.172 :: 46 | struct
packed evt_def {
2024-01-11 18:02:04.172 :: | ^
2024-01-11 18:02:04.174 :: make[1]: [scripts/Makefile.host:112: tools/boot/bootm.o] Error 1
2024-01-11 18:02:04.318 :: make:
[Makefile:1848: tools] Error 2
2024-01-11 18:02:04.499 'override-build' in part 'u-boot' failed with code 2. Review the scriptlet and make sure it's correct.

I am not sure if this is introduced with any changes you have made, or if it is native to "u-boot" source branch. I have been able to build the imx8mm-evk branch with a modification to the optee-client part. ( I had to compile separately and create a dump folder structure.) Once that was working there no issues with the rest of the build. I ran into the same error with the imx8mp-evk config and optee-client as well. I made that change, but can't complete the compilation for the "u-boot" part now.

We are attempting to build a test ubuntu-core image and gadget+kernel for our custom imx8mp board that is based closely on the evk reference design.

Any hints on what I am doing wrong would appreciated.

-Casey A. / unklstewy

unklstewy commented 6 months ago

Attached: complete build log snapcraft-20240111-182451.631566.log

-Casey

unklstewy commented 6 months ago

Attached: modified snap/snapcraft.yaml - Changes made to: parts: ... optee-client:

name: imx8mp-evk
summary: NXP i.MX8M Plus EVK support package
description: |
 Support files for booting i.MX8M Plus EVK board

version: 22-1-6.1.36-2.1.0
type: gadget

base: core22

architectures:
  - build-on: [amd64, arm64]
    build-for: arm64

confinement: strict
grade: stable

environment:
  LD_LIBRARY_PATH: ${SNAP}/usr/lib/${CRAFT_ARCH_TRIPLET_BUILD_FOR}
  PATH: ${SNAP}/bin:${PATH}

apps:
  tee-supplicant:
    command: usr/sbin/tee-supplicant --fs-parent-path $SNAP_SAVE_DATA/optee-fs --ta-dir $SNAP_COMMON/lib/optee_armtz --plugin-path $SNAP_COMMON/usr/lib/tee-supplicant/plugins
    install-mode: disable
    daemon: simple
    plugs:
      - network-bind
      - tee

  p11-kit-servers:
    command: usr/bin/p11-kit-servers start
    stop-command: usr/bin/p11-kit-servers stop
    daemon: forking
    install-mode: disable
    plugs:
      - tee
    slots:
      - pkcs11-optee-slot-0
      - pkcs11-optee-slot-1
      - pkcs11-optee-slot-2

  p11tool-optee:
    command: usr/bin/p11tool --provider $SNAP/usr/lib/aarch64-linux-gnu/libckteec.so
    plugs:
      - home
      - tee
      - pkcs11

  pkcs11-tool-optee:
    command: usr/bin/pkcs11-tool --module $SNAP/usr/lib/aarch64-linux-gnu/libckteec.so
    plugs:
      - home
      - tee
      - pkcs11

parts:
  arm-trusted-firmware:
    plugin: nil
    source: https://github.com/nxp-imx/imx-atf.git
    source-type: git
    source-tag: lf-6.1.36-2.1.0
    source-depth: 1
    build-environment:
      - PLAT: "imx8mp"
      - CROSS_COMPILE: "${CRAFT_ARCH_TRIPLET_BUILD_FOR}-"
    override-build: |
      make \
        PLAT=${PLAT} \
        BUILD_BASE=${CRAFT_PART_BUILD}/build \
        bl31 \
        -j$(nproc)
      make \
        PLAT=${PLAT} \
        BUILD_BASE=${CRAFT_PART_BUILD}/build-optee \
        SPD=opteed \
        bl31 \
        -j$(nproc)
      cp ${CRAFT_PART_BUILD}/build/${PLAT}/release/bl31.bin \
         ${CRAFT_PART_INSTALL}/bl31-${PLAT}.bin
      cp ${CRAFT_PART_BUILD}/build-optee/${PLAT}/release/bl31.bin \
         ${CRAFT_PART_INSTALL}/bl31-${PLAT}.bin-optee
    prime:
      - -*

  optee-keys:
    plugin: dump
    source: https://git.launchpad.net/~ondrak/+git/dev-keys
    source-type: git
    source-branch: ta-keys
    organize:
      '*': ta-keys/
    prime:
      - -*

  optee-os:
    after:
      - optee-fde
      - optee-keys
    plugin: nil
    source: https://github.com/nxp-imx/imx-optee-os.git
    source-type: git
    source-tag: lf-6.1.36-2.1.0
    source-depth: 1
    build-environment:
      - ARCH: "arm"
      - CROSS_COMPILE: "${CRAFT_ARCH_TRIPLET_BUILD_FOR}-"
      - CROSS_COMPILE_core: "${CRAFT_ARCH_TRIPLET_BUILD_FOR}-"
      - CROSS_COMPILE_ta_arm64: "${CRAFT_ARCH_TRIPLET_BUILD_FOR}-"
      - CFG_ARM64_core: "y"
      - CFG_USER_TA_TARGETS: "ta_arm64"
      - CFG_TEE_CORE_LOG_LEVEL: "1"
      - CFG_TEE_TA_LOG_LEVEL: "1"
      - CFG_TEE_BENCHMARK: "n"
      - CFG_TEE_CORE_DEBUG: "n"
      - CFG_TEE_BENCHMARK: "n"
      - CFG_TEE_RAM_VA_SIZE: "0x00280000"
      - CFG_CORE_HEAP_SIZE: "0x00100000"
      - DEBUG: "1"
      - TA_PUBLIC_KEY: "${CRAFT_STAGE}/ta-keys/ta_public.pem"
      - PLATFORM: "imx"
      - PLATFORM_FLAVOR: "mx8mpevk"
    override-build: |
      # add optee-fde TA
      cp -r ${CRAFT_STAGE}/optee-fde/ta/fde_key_handler ${CRAFT_PART_BUILD}/ta/
      export OPTEE_VERSION=$(head -1 CHANGELOG.md  | sed 's/# OP-TEE - version \(.*\) (.*/\1/g')-imx
      make O=${CRAFT_PART_BUILD}/out -j$(nproc)
      # build again with early TAs
      make O=${CRAFT_PART_BUILD}/out -j$(nproc) \
         CFG_EARLY_TA=y \
         EARLY_TA_PATHS="out/ta/pkcs11/fd02c9da-306c-48c7-a49c-bbd827ae86ee.stripped.elf \
                 out/ta/trusted_keys/f04a0fe7-1f5d-4b9b-abf7-619b85b4ce8c.stripped.elf \
                 out/ta/fde_key_handler/fd1b2a86-3668-11eb-adc1-0242ac120002.stripped.elf"
      ${CRAFT_ARCH_TRIPLET_BUILD_FOR}-objcopy \
         -O binary \
         ${CRAFT_PART_BUILD}/out/core/tee.elf \
         ${CRAFT_PART_INSTALL}/tee.bin
    prime:
      - -*
  optee-client:
    plugin: dump
    source: optee_client_arm64
    stage:
      - usr/sbin
      - usr/lib/*
      - usr/include/*

  optee-fde:
    plugin: dump
    source: https://git.launchpad.net/~ondrak/+git/optee-uc-fde
    source-type: git
    source-branch: master
    organize:
      '*': optee-fde/
    prime:
      - -*

  pub-signing-key:
    plugin: dump
    source: https://git.launchpad.net/~ondrak/+git/dev-keys
    source-type: git
    source-branch: master
    stage:
      - u-boot-pubkey.dtsi
    prime:
      - -*

  u-boot:
    after:
      - pub-signing-key
      - flash-script
    plugin: nil
    source: https://git.launchpad.net/~ondrak/+git/u-boot
    source-type: git
    source-tag: lf-6.1.36-2.1.0-uc
    source-depth: 1
    build-environment:
      - CROSS_COMPILE: "${CRAFT_ARCH_TRIPLET_BUILD_FOR}-"
      - CC: "${CRAFT_ARCH_TRIPLET_BUILD_FOR}--gcc"
    override-build: |
      # export CFLAGS="-E"
      # copy in place dtsi with pub part of kernel signing key
      cp ${CRAFT_STAGE}/u-boot-pubkey.dtsi \
         ${CRAFT_PART_BUILD}/arch/arm/dts/u-boot-pubkey.dtsi
      # update mmc_seed_part and mmc_boot_part from uc.lst
      mmc_seed_part="$(grep mmc_seed_part ${CRAFT_STAGE}/blobs/uc.lst | sed -e 's/^# //')"
      mmc_boot_part="$(grep mmc_boot_part ${CRAFT_STAGE}/blobs/uc.lst | sed -e 's/^# //')"
      sed -i \
         -e 's/mmc_seed_part=\(.*\)\\0"/'"${mmc_seed_part}"'\\0"/g' \
         -e 's/mmc_boot_part=\(.*\)\\0"/'"${mmc_boot_part}"'\\0"/g' \
         ${CRAFT_PART_BUILD}/include/configs/*.h
      # Add GIT revision to the local version
      head=$(git rev-parse --verify --short HEAD 2> /dev/null)
      imx_version=$(git describe --tags | cut -c 4-)
      printf "%s%s%s" "-${imx_version}" "+g" "${head}" > .scmversion
      make imx8mp_evk_config
      sed -i 's/CONFIG_BOOTARGS=.*/CONFIG_BOOTARGS="dangerous fde_helper=enabled"/g' .config
      make -j$(nproc)
      cp u-boot.bin ${CRAFT_PART_INSTALL}/u-boot.bin
      cp spl/u-boot-spl.bin ${CRAFT_PART_INSTALL}/u-boot-spl.bin
      mkdir -p ${CRAFT_PART_INSTALL}/imx-boot-tools
      cp u-boot-nodtb.bin ${CRAFT_PART_INSTALL}/imx-boot-tools
      cp u-boot.dtb \
         ${CRAFT_PART_INSTALL}/imx-boot-tools/imx8mp-evk.dtb
      # copy tools/mkimage tool for imx-boot stage
      cp tools/mkimage ${CRAFT_PART_INSTALL}
      tools/mkenvimage -r -s 4096 -o ${CRAFT_PART_INSTALL}/boot.sel - < /dev/null
      touch ${CRAFT_PART_INSTALL}/uboot.conf
    prime:
      - boot.sel
      - uboot.conf

  imx-firmware:
    plugin: nil
    override-pull: |
      # latest firmware version can be found in
      # https://github.com/nxp-imx/meta-imx/ -b <relevant release> in SCR-<release version>.txt
      firmware_version="8.21"
      wget https://www.nxp.com/lgfiles/NMG/MAD/YOCTO/firmware-imx-${firmware_version}.bin \
        -O firmware-imx.bin
    override-build: |
      chmod +x firmware-imx.bin
      ./firmware-imx.bin --force --auto-accept
      cp -r firmware-imx-*/firmware ${CRAFT_PART_INSTALL}
    prime:
      - -*

  imx-boot:
    after:
      - arm-trusted-firmware
      - imx-firmware
      - optee-os
      - u-boot
    plugin: nil
    source: https://github.com/nxp-imx/imx-mkimage.git
    source-type: git
    source-tag: lf-6.1.36-2.1.0
    source-depth: 1
    override-build: |
      platform="imx8mp"
      # firmware files
      for ddr_firmware in lpddr4_pmu_train_1d_imem_202006.bin lpddr4_pmu_train_1d_dmem_202006.bin lpddr4_pmu_train_2d_imem_202006.bin lpddr4_pmu_train_2d_dmem_202006.bin; do
        cp ${CRAFT_STAGE}/firmware/ddr/synopsys/${ddr_firmware} iMX8M
      done
      cp ${CRAFT_STAGE}/firmware/hdmi/cadence/signed_dp_imx8m.bin iMX8M
      cp ${CRAFT_STAGE}/firmware/hdmi/cadence/signed_hdmi_imx8m.bin iMX8M
      # atf
      cp ${CRAFT_STAGE}/bl31-${platform}.bin-optee iMX8M/bl31.bin
      # optee
      cp ${CRAFT_STAGE}/tee.bin iMX8M
      # u-boot
      cp ${CRAFT_STAGE}/u-boot.bin iMX8M
      cp ${CRAFT_STAGE}/u-boot-spl.bin iMX8M
      cp ${CRAFT_STAGE}/imx-boot-tools/u-boot-nodtb.bin iMX8M
      cp ${CRAFT_STAGE}/imx-boot-tools/${platform}-evk.dtb iMX8M
      # setup link to mkimage_uboot
      ln -sf ${CRAFT_STAGE}/mkimage iMX8M/mkimage_uboot
      make SOC=iMX8MP flash_evk
      cp iMX8M/flash.bin ${CRAFT_PART_INSTALL}/
    organize:
      flash.bin: blobs/imx-boot.bin

  flash-script: # uuu flash script
    plugin: nil
    override-build: |
      # get seed offset and size from gadget yaml
      convert_size() {
      case $1 in
        (0)  seed_size="0" ;;
        (*G | *g) echo $(expr $(echo $1 | sed -e 's/G//g' -e 's/g//g') \* 1024 \* 1024 \* 1024) ;;
        (*M | *m) echo $(expr $(echo $1 | sed -e 's/M//g' -e 's/m//g') \* 1024 \* 1024) ;;
        (*K | *k) echo $(expr $(echo $1 | sed -e 's/K//g' -e 's/k//g') \* 1024) ;;
        (*) echo ${1} ;;
      esac
      }

      # read all the partitions before ubuntu-boot and include those in the created part table
      # additionally calculate part number for seed and boot, we need those for u-boot build
      gpt_partitions="uuid_disk=\${uuid_gpt_disk}"
      part_number=0
      # this is good opportunity to validate offset of the partitions, if defined
      # it saves us from failed boot
      # default 1st partition offset is 1MB, unless defined otherwise
      partition_offset=0
      unset mmc_boot_part mmc_seed_part
      for p in $(yq eval '.volumes.[].structure.[].name' ${CRAFT_PROJECT_DIR}/gadget.yaml)
      do
      # ignore bare structures
      if [ "${p}" != "null" ]; then
        part_number=$((part_number+1))
        # only read till ubuntu-boot partition
        if [ "${p}" == "ubuntu-boot" ]; then
        mmc_boot_part="${part_number}"
        fi
        if [ "${p}" == "ubuntu-seed" ]; then
        mmc_seed_part="${part_number}"
        fi

        # include partitions in the list
        export p=${p}
        p_offset=$(yq eval '.volumes.[].structure.[] | select(.name == env(p)) | .offset' ${CRAFT_PROJECT_DIR}/gadget.yaml)
        p_size=$(yq eval '.volumes.[].structure.[] | select(.name == env(p)) | .size' ${CRAFT_PROJECT_DIR}/gadget.yaml)
        p_type=$(yq eval '.volumes.[].structure.[] | select(.name == env(p)) | .type' ${CRAFT_PROJECT_DIR}/gadget.yaml)
        p_size=$(convert_size ${p_size})
        gpt_partitions="${gpt_partitions};name=${p},size=${p_size},start=${p_offset},type=${p_type}"
        if [ "${partition_offset}" == "0" ]; then
        # first partion, if there no offset defined, use default 1MB (1048576)
        if [ -n "${p_offset}" ]; then
          partition_offset=${p_offset}
        else
          partition_offset=1048576
        fi
        fi
        if [ "${p_offset}" != "${partition_offset}" ]; then
        echo "Unexpected offset for partition ${p}, defined: ${p_offset}, expected: ${partition_offset}"
        exit 1
        else
        echo "Validated offset for partition ${p}, offset: ${p_offset}"
        fi
        # calculate next offset
        partition_offset=$((partition_offset+p_size))
        unset p
      fi
      done

      cat << EOF > ${CRAFT_PART_INSTALL}/uc.lst
      uuu_version 1.4.69

      # This command will be run when i.MX6/7 i.MX8MM, i.MX8MQ
      SDP: boot -f imx-boot.bin

      # This command will be run when ROM support stream mode
      # i.MX8QXP, i.MX8QM
      SDPS: boot -f imx-boot.bin

      # These commands will be run when use SPL and will be skipped if no spl
      # SDPU will be deprecated. please use SDPV instead of SDPU
      # {
      SDPU: delay 1000
      SDPU: write -f imx-boot.bin -offset 0x57c00
      SDPU: jump
      # }

      # These commands will be run when use SPL and will be skipped if no spl
      # if (SPL support SDPV)
      # {
      SDPV: delay 1000
      SDPV: write -f imx-boot.bin -skipspl
      SDPV: jump
      # }

      # use fastboot to write bootloader
      FB: ucmd setenv fastboot_dev mmc
      FB: ucmd setenv mmcdev \${emmc_dev}
      FB: ucmd mmc dev \${emmc_dev}
      FB: flash bootloader  imx-boot.bin

      # create new partition table
      # boot critical partition number (used for u-boot build config)
      # mmc_boot_part=${mmc_boot_part}
      # mmc_seed_part=${mmc_seed_part}
      FB: ucmd setenv partitions '${gpt_partitions}'
      FB: ucmd gpt write mmc \${emmc_dev} \${partitions}

      # force re-read partition table
      FB: ucmd setenv mmcdev \${emmc_dev}
      FB: ucmd setenv fastboot_dev mmc

      # Flashing partitions, use timeout 20s
      FB: ucmd echo "If ubuntu-seed partition does not exist, powercycle the device"
      FB[-t 20000]: flash ubuntu-seed ubuntu-seed.img
      FB: done
      EOF
    organize:
      uc.lst: blobs/
    build-snaps:
      - yq

  p11-kit-helpers:
    plugin: nil
    override-build: |
      install -D -m 755 \
      ${CRAFT_PROJECT_DIR}/p11-kit-servers \
      ${CRAFT_PART_INSTALL}/usr/bin/p11-kit-servers
      install -D -m 755 \
      ${CRAFT_PROJECT_DIR}/p11tool \
      ${CRAFT_PART_INSTALL}/usr/bin/p11tool
      install -D -m 755 \
      ${CRAFT_PROJECT_DIR}/pkcs11-tool \
      ${CRAFT_PART_INSTALL}/usr/bin/pkcs11-tool

build-packages:
  - bison
  - build-essential
  - device-tree-compiler
  - flex
  - libxml2-dev
  - libssl-dev
  - python3
  - python3-cryptography
  - python3-pyelftools
  - python3-pycryptodome
  - wget
  - zlib1g-dev
  - on amd64:
    - gcc-aarch64-linux-gnu
  - on arm64:
    - gcc

slots:
  tee-plugins:
    interface: content
    write:
      - $SNAP_COMMON/usr/lib/tee-supplicant/plugins
  tee-tas:
    interface: content
    write:
      - $SNAP_COMMON/lib/optee_armtz
  pkcs11-optee-slot-0:
    interface: pkcs11
    pkcs11-socket: /run/p11-kit/optee-slot-0
  pkcs11-optee-slot-1:
    interface: pkcs11
    pkcs11-socket: /run/p11-kit/optee-slot-1
  pkcs11-optee-slot-2:
    interface: pkcs11
    pkcs11-socket: /run/p11-kit/optee-slot-2