Skip to content

[BUG] Cmake runs initially without CONFIG vars set #3617

Closed

Description

@cujomalainey

Describe the bug
When we build SOF for some reason the initial call to cmake does not include any configs. You can see the travis log below that make *defconfig is not called till after the first call to cmake. This is causing problems with refactoring as some of the variables are resolving to null and causing bugs.

Assuming there is a reason for this initial no config call, then we are calling into areas without configs like arch/xtensa which need those configs to run properly, which means we should be returning. Maybe we are just missing a check at the top of arch/xtensa to return if a xtensa config is not set?

To Reproduce
run xtensa-build-all.sh with a message to long your platform config. notice empty line in first run.

Reproduction Rate
How often does the issue happen ? i.e. 1/10 (once in ten attempts), 1/1000 or all the time.
100%

Expected behavior
Cmake should not run without the config

Impact
Blocks refactoring for fuzzer

Environment

  1. Branch name and commit hash of the 2 repositories: sof (firmware/topology) and linux (kernel driver).
  2. Name of the topology file
    • Topology: N/A
  3. Name of the platform(s) on which the bug is observed.
    • Platform: N/A

Screenshots or console output

$ ./scripts/docker-run.sh ./scripts/xtensa-build-all.sh -r $PLATFORM
Build in build_tgl_gcc
+ cmake -DTOOLCHAIN=xtensa-cnl-elf -DROOT_DIR=/home/sof/work/sof.git/../xtensa-root/xtensa-cnl-elf -DMEU_OPENSSL= '' -DRIMAGE_PRIVATE_KEY=/home/sof/work/sof.git/keys/otc_private_key_3k.pem ..
-- Preparing Xtensa toolchain
-- The C compiler identification is GNU 9.2.0
-- The ASM compiler identification is GNU
-- Found assembler: /home/sof/work/xtensa-cnl-elf/bin/xtensa-cnl-elf-gcc
-- Linking git pre-commit hook
-- Linking git post-commit hook
-- Found Git: /usr/bin/git (found version "2.17.1") 
-- GIT_TAG / GIT_LOG_HASH : v1.5-rc1-898-ge7a339bd4cc7 / e7a339bd4
-- Source content hash: f770dbfc
-- Generating /home/sof/work/sof.git/build_tgl_gcc/generated/include/version.h
-- Found PythonInterp: /usr/bin/python3 (found suitable version "3.6.9", minimum required is "3.0") 
-- Configuring done
-- Generating done
-- Build files have been written to: /home/sof/work/sof.git/build_tgl_gcc
+ make tgplp_defconfig
Scanning dependencies of target tgplp_defconfig
Applying olddefconfig with tgplp_defconfig
Using existing configuration '.config' as base
Configuration written to '.config'
Built target tgplp_defconfig
-- Preparing Xtensa toolchain
-- GIT_TAG / GIT_LOG_HASH : v1.5-rc1-898-ge7a339bd4cc7 / e7a339bd4
-- Source content hash: f770dbfc
-- Up-to-date /home/sof/work/sof.git/build_tgl_gcc/generated/include/version.h
-- Configuring done
-- Generating done
-- Build files have been written to: /home/sof/work/sof.git/build_tgl_gcc
Scanning dependencies of target overrideconfig
Using existing configuration '.config' as base
Configuration written to '.config'
Built target overrideconfig
-- Preparing Xtensa toolchain
-- GIT_TAG / GIT_LOG_HASH : v1.5-rc1-898-ge7a339bd4cc7 / e7a339bd4
-- Source content hash: f770dbfc
-- Up-to-date /home/sof/work/sof.git/build_tgl_gcc/generated/include/version.h
-- Configuring done
-- Generating done
-- Build files have been written to: /home/sof/work/sof.git/build_tgl_gcc
Scanning dependencies of target genconfig

Activity

  1. lgirdwood commented on Nov 18, 2020

    @lgirdwood
    Member

    @jajanusz @marc-hb any inputs here ?

  2. marc-hb commented on Nov 18, 2020

    @marc-hb
    Collaborator

    I often invoke cmake and make/ninja directly (not the least when... fixing them) and from a (lack of) user friendliness perspective I always found the intermediate and extra defconfig step super annoying. Meta-build systems that build entire system images/distributions are very likely incompatible with such an intermediate step.

    Just for the record this extra defconfig step is official and documented:
    https://thesofproject.github.io/latest/getting_started/build-guide/build-from-scratch.html#incremental-builds

    What's even more annoying is I found no way to clean the build directory without losing my .config! Must be saved and restored every time, really painful.

    So before even looking at the details of the specific issues listed by @cujomalainey I would absolutely love if the defconfig step were integrated in the CMake step. This is what Zephyr does BTW: https://docs.zephyrproject.org/2.3.0/guides/kconfig/setting.html#setting-symbols-in-configuration-files

    Note this would of course require passing config information at cmake time, either with cmake -Dsomething=aplconfig or by switching to a source directory with some desired .conf files. Zephyr supports the combination of both.

    @jajanusz was the current design a conscious choice or just the easiest way for you to implement it at the time?

    cc: kconfig master @plbossart , @xiulipan

  3. cujomalainey commented on Nov 18, 2020

    @cujomalainey
    ContributorAuthor

    Ditto to marc. I think that would prevent my issues I am seeing. Right now all I am trying to do is add a linker script to the host build and I tried extracting sof_add_ld_script (name might not be exact, going off memory) from xtensa so I could share it with the host and it broke because a bunch of vars were evaluating to nothing causing arg count failures due to missing configs.

  4. xiulipan commented on Nov 19, 2020

    @xiulipan
    Contributor

    @marc-hb I think this issue is not related with kconfig, it is totally a cmake config issue. I think we can include the make tgplp_defconfig in cmake stage.

  5. marc-hb commented on Nov 19, 2020

    @marc-hb
    Collaborator

    I think this issue is not related with kconfig

    The .config file is a kconfig file so it's not clear what you meant here.

    I just checked and as expected make foo_defconfig VERBOSE=1 invokes scripts/kconfig/olddefconfig.py

  6. cujomalainey commented on Nov 20, 2020

    @cujomalainey
    ContributorAuthor

    just an fyi, tried adding a return else case to the platform select in arch/xtensa/cmakelist and it doesnt work.

    ./scripts/xtensa-build-all.sh: line 182: type: xtensa-bxt-elf-gcc: not found
    Build in build_apl_gcc
    + cmake -DTOOLCHAIN=xtensa-apl-elf -DROOT_DIR=/home/sof/work/sof.git/../xtensa-root/xtensa-apl-elf -DMEU_OPENSSL= '' '' ..
    -- Preparing Xtensa toolchain
    -- The C compiler identification is GNU 9.2.0
    -- The ASM compiler identification is GNU
    -- Found assembler: /home/sof/work/xtensa-apl-elf/bin/xtensa-apl-elf-gcc
    -- Found Git: /usr/bin/git (found version "2.17.1") 
    -- GIT_TAG / GIT_LOG_HASH : v1.5-rc1-917-gcc5db3e1b476 / cc5db3e1b476
    -- Source content hash: dd56d502
    -- Generating /home/sof/work/sof.git/build_apl_gcc/generated/include/version.h
    -- Found PythonInterp: /usr/bin/python3 (found suitable version "3.6.9", minimum required is "3.0") 
    -- Configuring done
    -- Generating done
    CMake Warning:
      Manually-specified variables were not used by the project:
    
        MEU_OPENSSL
        ROOT_DIR
    
    
    -- Build files have been written to: /home/sof/work/sof.git/build_apl_gcc
    + make apollolake_defconfig
    Scanning dependencies of target apollolake_defconfig
    [100%] Applying olddefconfig with apollolake_defconfig
    Using existing configuration '.config' as base
    Configuration written to '.config'
    [100%] Built target apollolake_defconfig
    make: *** No rule to make target 'bin'.  Stop.
    
  7. cujomalainey commented on Dec 28, 2020

    @cujomalainey
    ContributorAuthor

    @slawblauciak can we bump this to a P1/P2? This is blocking oss-fuzz from covering a large part of the firmware and also I think making integration of future testbench tools harder for @ShriramShastry

  8. added this to the v1.7 milestone on Jan 4, 2021
  9. added
    P1Blocker bugs or important features
    and removed
    P3Low-impact bugs or features
    on Jan 4, 2021
  10. lgirdwood commented on Jan 12, 2021

    @lgirdwood
    Member

    @mwasko can we assign someone to fix for v1.7 final. I don't think this will block the first RC.

  11. mwasko commented on Jan 25, 2021

    @mwasko
    Contributor

    @bkokoszx please take a look

  12. 6 remaining items

  13. bkokoszx commented on Jan 27, 2021

    @bkokoszx
    Collaborator

    @marc-hb Thanks, feel free to ask if you need any help.

    @cujomalainey
    Thanks, but I have one additional question. :) I understand that in the "first" round of CMake the .config file is not created yet. We do not have defined any CONFIG_* defines at that stage yet. After make *_defconfig (e.g. make tgplp_defconfig) there is "second" round of cmake and at that stage we have CONFIG_* defines defined.

    I do not fully understand why you need those defines necessarily at the first stage. Do you want to make it just more readable or e.g. add some function which take specific CONFIG_* (and it case when it is empty string it causes the error)?

  14. cujomalainey commented on Jan 27, 2021

    @cujomalainey
    ContributorAuthor

    Not quite, I would argue the first stage should not even run.

    What I am trying to do is refactor the build system so it is more friendly to x86 test builds, currently I need to be able to link in ld scripts. If I modify the ld script function right now to take in paths based on config values (which its currently accessing globally) it causes breakages in the first step even though function isn't even relevant for kconfig generation.

    If we remove this double step process I think we can clean up a lot of code.

  15. ktrzcinx commented on Jan 27, 2021

    @ktrzcinx
    Member

    @cujomalainey if(DEFINED CONFIG_VAR_NAME) or if(CONFIG_VAR_NAME) wouldn't solve your problem ?

  16. lgirdwood commented on Jan 27, 2021

    @lgirdwood
    Member

    Thank you @marc-hb - I guess you are the cmake "Maintainer" now.

  17. cujomalainey commented on Jan 27, 2021

    @cujomalainey
    ContributorAuthor

    @ktrzcinx that sounds more like treating the symptom than the problem. Likely I could add that but it would likely litter the repo with them

  18. marc-hb commented on Apr 30, 2021

    @marc-hb
    Collaborator

    @cujomalainey is there anything left to do here, if not can this be closed?

  19. cujomalainey commented on Apr 30, 2021

    @cujomalainey
    ContributorAuthor

    yes i think we are done here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

P1Blocker bugs or important featuresbugSomething isn't working as expected

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions