Moving to 2.6.0 from 2.3.0 problem with VERSION

Hi,

I am moving to version 2.6.0 of the SDK and toolchain.  I am developing on windows 11 pro.  Our cMakeLists.txt file creates a version file in our conf directory version.conf.  I am trying to change it to use the APP_ROOT/VERSION file.  I have taken out all of the previous code that created that version file and now having it create the VERSION file per docs Here.  

Here is my CMakeLists.txt

#
# Copyright (c) 2019 Nordic Semiconductor
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#
cmake_minimum_required(VERSION 3.20.0)

set(version_major 0)
set(version_minor 0)
set(version_patch 0)
set(version_commit 0)


# Determine the build type
if (NOT BUILD_TYPE)
  set(BUILD_TYPE debug)
elseif(BUILD_TYPE STREQUAL "release")
  add_compile_definitions( BUILD_TYPE_RELEASE )
else()
  message( FATAL_ERROR "Unknown build type: ${BUILD_TYPE}" )
endif()

# Print out build type
message(STATUS "Build type: ${BUILD_TYPE}")

# Get the version from Git
find_package(Git QUIET)
if(GIT_FOUND)
  execute_process(
    COMMAND git describe --tags --long
    WORKING_DIRECTORY                ${CMAKE_CURRENT_SOURCE_DIR}
    OUTPUT_VARIABLE                  version
    OUTPUT_STRIP_TRAILING_WHITESPACE
    ERROR_STRIP_TRAILING_WHITESPACE
    ERROR_VARIABLE                   stderr
    RESULT_VARIABLE                  return_code
  )
  if(return_code)
    message(STATUS "git describe failed: ${stderr}; ${KERNEL_VERSION_STRING} will be used instead")
  elseif(CMAKE_VERBOSE_MAKEFILE)
    message(STATUS "git describe stderr: ${stderr}")
  endif()
endif()

if(version)
  string(REGEX REPLACE "^([0-9]+).*$" "\\1" version_major ${version})
  string(REGEX REPLACE "^[0-9]+\.([0-9]+).*$" "\\1" version_minor "${version}")
  string(REGEX REPLACE "^[0-9]+\.[0-9]+\.([0-9]+).*$" "\\1" version_patch "${version}")
  string(REGEX REPLACE "^[0-9]+\.[0-9]+\.[0-9]+-([0-9]+)-.*$" "\\1" version_commit "${version}")
  string(REGEX REPLACE "^[0-9]+\.[0-9]+\.[0-9]+-[0-9]+-(.*)$" "\\1" version_hash "${version}")

  
  # VERSION file
  file(WRITE VERSION "VERSION_MAJOR=${version_major}\n")
  file(APPEND VERSION "VERSION_MINOR=${version_minor}\n")
  file(APPEND VERSION "PATCHLEVEL=${version_patch}\n")
  file(APPEND VERSION "VERSION_TWEAK=${version_commit}\n")
  message(STATUS "Version: ${version_major}.${version_minor}.${version_patch}-${version_commit}-${version_hash}")
else()
   # VERSION file
   file(WRITE VERSION "VERSION_MAJOR=${version_major}\n")
   file(APPEND VERSION "VERSION_MINOR=${version_minor}\n")
   file(APPEND VERSION "PATCHLEVEL=${version_patch}\n")
   file(APPEND VERSION "VERSION_TWEAK=${version_commit}\n")

  message(STATUS "Version: ${version_major}.${version_minor}.${version_patch}-${version_commit}-${version_hash}")

endif()

# Define configuration files.
list(APPEND CONF_FILE
  ${CMAKE_CURRENT_SOURCE_DIR}/conf/prj.conf
  ${CMAKE_CURRENT_SOURCE_DIR}/conf/prj-${BUILD_TYPE}.conf
  ${CMAKE_CURRENT_SOURCE_DIR}/VERSION
)

find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(xxxxxx_xxxxxxxxxx2)

FILE(GLOB app_sources src/*.c)
target_sources(app PRIVATE ${app_sources})

Here is what is created in the application root for VERSION:

VERSION_MAJOR=2
VERSION_MINOR=0
PATCHLEVEL=0
VERSION_TWEAK=1

I am getting the following errors and cant seem to figure out why:

-- west build: generating a build system
-- Build type: debug
-- Version: 2.0.0-1-gd81431d
-- Application: xxxxxxxxxx
-- CMake version: 3.21.0

NOTE: After more testing these errors seemed to go away after i put spaces after the = in my version file.
CMake Error at C:/ncs/v2.6.0/zephyr/cmake/modules/version.cmake:76 (math):
math cannot parse the expression: "( << 16) + ( << 8) + ()": syntax error,
unexpected exp_SHIFTLEFT (4).
Call Stack (most recent call first):
C:/ncs/v2.6.0/zephyr/share/zephyr-package/cmake/ZephyrConfigVersion.cmake:59 (include)
CMakeLists.txt:96 (find_package)


CMake Error at C:/ncs/v2.6.0/zephyr/cmake/modules/version.cmake:77 (math):
math cannot parse the expression: "( << 24) + ( << 16) + ( << 8) + ()":
syntax error, unexpected exp_SHIFTLEFT (4).
Call Stack (most recent call first):
C:/ncs/v2.6.0/zephyr/share/zephyr-package/cmake/ZephyrConfigVersion.cmake:59 (include)
CMakeLists.txt:96 (find_package)


Loading Zephyr default modules (Zephyr base (cached)).
-- Cache files will be written to: C:/ncs/v2.6.0/zephyr/.cache
-- Zephyr version: 3.5.99 (C:/ncs/v2.6.0/zephyr)
CMake Error at C:/ncs/v2.6.0/zephyr/cmake/modules/version.cmake:76 (math):
math cannot parse the expression: "( << 16) + ( << 8) + ()": syntax error,
unexpected exp_SHIFTLEFT (4).
Call Stack (most recent call first):
C:/ncs/v2.6.0/zephyr/cmake/modules/zephyr_default.cmake:129 (include)
C:/ncs/v2.6.0/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:66 (include)
C:/ncs/v2.6.0/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:97 (include_boilerplate)
CMakeLists.txt:96 (find_package)


CMake Error at C:/ncs/v2.6.0/zephyr/cmake/modules/version.cmake:77 (math):
math cannot parse the expression: "( << 24) + ( << 16) + ( << 8) + ()":
syntax error, unexpected exp_SHIFTLEFT (4).
Call Stack (most recent call first):
C:/ncs/v2.6.0/zephyr/cmake/modules/zephyr_default.cmake:129 (include)
C:/ncs/v2.6.0/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:66 (include)
C:/ncs/v2.6.0/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:97 (include_boilerplate)
CMakeLists.txt:96 (find_package)

NOTE: Even though the abobe went away the following still exist and the compile stops with:


error: Aborting due to Kconfig warnings

CMake Error at C:/ncs/v2.6.0/zephyr/cmake/modules/kconfig.cmake:358 (message):
command failed with return code: 1
Call Stack (most recent call first):
C:/ncs/v2.6.0/nrf/cmake/modules/kconfig.cmake:29 (include)
C:/ncs/v2.6.0/zephyr/cmake/modules/zephyr_default.cmake:129 (include)
C:/ncs/v2.6.0/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:66 (include)
C:/ncs/v2.6.0/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:92 (include_boilerplate)
CMakeLists.txt:96 (find_package)

xxxxxxxxxxxx/VERSION:1: warning: ignoring malformed line 'VERSION_MAJOR = 2'

xxxxxxxxxxxx/VERSION:2: warning: ignoring malformed line 'VERSION_MINOR = 0'

xxxxxxxxxxxx/VERSION:3: warning: ignoring malformed line 'PATCHLEVEL = 0'

xxxxxxxxxxxx/VERSION:4: warning: ignoring malformed line 'VERSION_TWEAK = 1'

error: Aborting due to Kconfig warnings

The errors seem to suggest that the temporary convenience variables in version.cmake are not being created but i have no way to figure out why.  Additionally the error on line 77 on the version.cmake looks to be setting kernel version not project version, that happens later in the file.

What am I doing wrong here?

Brian

Parents
  • Hi Brian,

    The correct way is with a space character before and after the equal sign.

    Could you please try to remove the build directory completely and build again from the beginning?

    Please also:
    - Check if you are on the correct toolchain version.
    - Check if there are any invisible invalid character in the VERSION file.
    - Try building the Peripheral UART sample with your current setup, to see if the same issue happened.

    If none of that works, could you please share the full build log with less of the file path redacted? I would like to see the relative path of the files within the project, at least.

    Hieu

  • Hi Hieu,

    Yes I am on the correct toolchain version 2.6.0, sdk 2.6.0. There are spaces before and after the '=' sign. I deleted the build directories, no change. the only invisible characters in the file are the carriage return and line feed produced by the \n in the cmake file.

    I will work on building the Peripheral UART.

    I cant seem to attach any code or anything right now, the website is telling me there is an error wen i try to upload a file or insert code to this reply.

  • Hi Brian,

    For adding code, please try to use the Insert > Code menu option.

    For files, usually I just drag a file and drop into the edit box. But you could try using the Insert > Image/video/file menu option too.

    Please do check if Peripheral UART work.

  • Hi, I did, ive done it before, the website is saying an error occurred and wont let me.  

    I built peripheral sample and the basic build works, when i add the versioning it gives the same error.  HOWEVER:

    I have a section in the CMakeLists.txt file

    # Define configuration files.
    list(APPEND CONF_FILE
      ${CMAKE_CURRENT_SOURCE_DIR}/conf/prj.conf
      ${CMAKE_CURRENT_SOURCE_DIR}/conf/prj-${BUILD_TYPE}.conf
      #${CMAKE_CURRENT_SOURCE_DIR}/conf/version.conf
      #${CMAKE_CURRENT_SOURCE_DIR}/VERSION
    )

    That appends all the the conf files together.  With the old versioning method this was fine.  Now its not.  After commenting out the append for VERSION it now compiles.  Now the last question which is what brought me to this new way of doing things.  We used to use 

    CONFIG_MCUBOOT_IMAGE_VERSION="1.0.21+1"
    and that no longer works and i am now sing the VERSION file.  Am I to assume that MCUBOOT will automatically pick up the version file and use the version it contains?  If so, Thank you and you can close this ticket, otherwise, what should I do for MCUBOOT versioning.
    Brian
  • Hi Brian,

    Application version management using the VERSION file was introduced in NCS v2.6.0. To my experience, you do not need to include the file via CMakeLists.txt like that. The build system is setup to automatically detect and take in the file.

    Also, VERSION is not a Kconfig file, so when you include it into CONF_FILE like you showed, the build system will try to interpret it as a Kconfig file and caused the "ignoring malformed line" warnings.
    Your mention of those warnings in your opening post makes sense now.

    finkbr said:
    CONFIG_MCUBOOT_IMAGE_VERSION="1.0.21+1"
    and that no longer works and i am now sing the VERSION file.

    If you want to use Kconfig, technically it still works. The NCS specific Kconfig is just removed in to unify the versioning solution with Zephyr's, and the Kconfig you should use is now CONFIG_MCUBOOT_IMGTOOL_SIGN_VERSION instead. 

    But VERSION file is the preferred way.

    finkbr said:
    Am I to assume that MCUBOOT will automatically pick up the version file and use the version it contains?

    I inadvertently answered it first already, but yes.

    finkbr said:
    If so, Thank you and you can close this ticket, otherwise, what should I do for MCUBOOT versioning.

    Alright. Good to know everything is clear now. I will close the ticket then Slight smile

    Hieu

Reply
  • Hi Brian,

    Application version management using the VERSION file was introduced in NCS v2.6.0. To my experience, you do not need to include the file via CMakeLists.txt like that. The build system is setup to automatically detect and take in the file.

    Also, VERSION is not a Kconfig file, so when you include it into CONF_FILE like you showed, the build system will try to interpret it as a Kconfig file and caused the "ignoring malformed line" warnings.
    Your mention of those warnings in your opening post makes sense now.

    finkbr said:
    CONFIG_MCUBOOT_IMAGE_VERSION="1.0.21+1"
    and that no longer works and i am now sing the VERSION file.

    If you want to use Kconfig, technically it still works. The NCS specific Kconfig is just removed in to unify the versioning solution with Zephyr's, and the Kconfig you should use is now CONFIG_MCUBOOT_IMGTOOL_SIGN_VERSION instead. 

    But VERSION file is the preferred way.

    finkbr said:
    Am I to assume that MCUBOOT will automatically pick up the version file and use the version it contains?

    I inadvertently answered it first already, but yes.

    finkbr said:
    If so, Thank you and you can close this ticket, otherwise, what should I do for MCUBOOT versioning.

    Alright. Good to know everything is clear now. I will close the ticket then Slight smile

    Hieu

Children
No Data
Related