Zephyr-WEST工具

目录

1 介绍

1)manifest

2)config file

2 安装

3 west init

1)用法

2)执行结果

4 west update

5 west list

6 west manifest

7 west config

1)选择配置文件

2)列出选项

3)删除

4)修改配置项

8 west topdir

9 扩展命令

1)west-commands.yml



1 介绍

  • 同时该工具也支持插件化,允许用户自己编写west的扩展功能
  • 在使用west命令之前,需要先了解几个关联的内容:manifest,config

1)manifest

  • west作为一种多仓库模式,肯定需要一个清单表管理。使用YAML格式的文件manifest就作为这个清单表。

  • 典型的manifest内容如下,主要包括几个子节:remotes,projects,self
manifest:
  remotes:
      # 指定url-base,用于工程从该url fetch
 
  projects:
    # 各个子仓库清单
    
  self:
    # configuration related to the manifest repository itself,
    # i.e. the repository containing west.yml
  • remotes

        指定一个base-url,用于工程从该url fetch

  remotes:
    - name: upstream
      url-base: https://github.com/zephyrproject-rtos
  • projects

        记录了子仓库的信息,指明了有哪些子仓库,各子仓库需要的版本,以及下载到项目的哪个路径

  projects:
      # 子仓库名称,即url-base/name
    - name: canopennode
      # 版本
      revision: 1052dae561497bef901f931ef75e117c9224aecd
      # 保存至project/path
      path: modules/lib/canopennode
      
    - name: civetweb
      revision: 094aeb41bb93e9199d24d665ee43e9e05d6d7b1c
      path: modules/lib/civetweb
  • self

        管理west的扩展命令,当执行west扩展命令时,会通过该子段的内容,关联到zephyr/scripts/west-commnad.yml

  self:
    path: zephyr
    west-commands: scripts/west-commands.yml
    import: submanifests

        接着看zephyr/scripts/west-commnad.yml的内容,显然

        执行west completion时,最终会执行python脚本scripts/west_commnads/completion.py

west-commands:
  - file: scripts/west_commands/completion.py
    commands:
      - name: completion
        class: Completion
        help: display shell completion scripts
  - file: scripts/west_commands/boards.py
    commands:
      - name: boards
        class: Boards
        help: display information about supported boards

2)config file

  • west的配置,我们需要知道配置文件(编写语法,配置项),以及如何配置
  • 有三种类型配置文件,各自作用范围不同,其优先级按下面顺序依次提高:

        System:该配置下的修改作用于所有登录用户

                对于Linux平台,配置文件在 /etc/westconfig

       Global(per user):该配置下的修改作用于具体的一个登录用户

                所有平台路径在~/.westconfig

        Local:作用于当前workspace

                该配置文件在workspace/.west/config(west init命令执行时自动生成的)

2.1)配置文件语法

  • 语法类似ini文件,一个简单示例如下:

        PS:如果使用命令表示即manifest.path,zephyr.base等

[manifest]
path = zephyr        
file = west.yml

[zephyr]
base = zephyr

2.2)哪些配置项

2.3)如何修改

        使用west config命令,具体见后续命令介绍

2 安装

  • Linux下安装
pip3 install --user -U west
  • Windows和macOS下安装
pip3 install -U west

3 west init

1)用法

west init [-m URL] [--mr REVISION] [--mf FILE] [directory]

2)执行结果

  • 一般典型用法如下
west init -m https://github.com/zephyrproject-rtos/zephyr --mr v2.5.0 zephyrproject
  • 该命令自动完成如下操作:
  1. 创建工程路径zephyrproject,同时在该文件夹下生成.west和.west/config
  2. https://github.com/zephyrproject-rtos/zephyr clone仓库至zephyrproject/zephyr
  3. Check out 版本v2.5.0          
  4. 在.west/config中设置manifest.path和manifest.file(关于manifest的使用后面会提到)     

  • 这样一个基本的workspace就准备就绪了,后面就可以使用west update更新其他子仓库代码

4 west update

  • 进入workspace后,直接输入该命令
  • 该命令自动完成如下操作:
  1. 通过.west/config文件中的manifest配置,获取到manifest文件,即workspace/zephyr/下的west.yml文件
  2. 依据west.yml内容来决定,获取哪些子仓库,从哪个URL获取,获取什么版本,保持至workspace下的哪个路径        

        PS:以下图wets.yml红色标记的projects/canopennode为例,即从https://github.com/zephyrproject-rtos/canopennode获取对应版本的子仓库,并保存至workspace/path

  • 默认url-base是从github访问,子仓库代码比较庞大,执行west update容易失败,可以修改此处的url-bae为国内的镜像。

5 west list

  • 输出manifest中每个项目的信息

6 west manifest

  • 用于管理manifest文件,命令后需加上具体的动作和参数

1)--resolve

输出详细的manifest的项目信息,类似west list命令,相比输出的信息更为详细

2)--validate

验证manifest是否有效,无效会输出错误信息

3)--path

输出manifest的绝对路径

7 west config

  • 在前面已经了解west配置的相关信息,这里介绍如果通过命令修改

1)选择配置文件

        --system/global/local

  • 通过该选项,选择具体操作的配置文件。
  • 如果未设置该选项,默认写是local,默认读是从3个配置文件按优先级读取

2)列出选项

        -l && --list

  • 列出所有配置选项
conor@Conor:/mnt/c/00-conor/02-study/07-zephyr/zephyrproject$ west config --list
manifest.path=zephyr
manifest.file=west.yml
zephyr.base=zephyr

3)删除

  • west config -d --global

        删除global配置文件中的指定项

  • west config -D

        删除所有配置文件中的指定项

4)修改配置项

  • west config --global

        修改global配置文件中指定项的值

8 west topdir

  • 输出workspace顶层路径

9 扩展命令

  • 前面有提到,west是插件化的命令工具,除了上述几个内置命令,同时扩展命令当然也支持用户新增自己需要的命令

1)west-commands.yml

  • 在前面章节"介绍/manifest"中已经提到"self"子段,其子段关联到/zephyr/scripts/west-commands.yml文件,该文件管理着所有的扩展命令

截取一部分该文件中的内容,如下执行west boards命令时,最终会执行scripts/west_commands/boards.py

west-commands:
  - file: scripts/west_commands/completion.py
    commands:
      - name: completion
        class: Completion
        help: display shell completion scripts
  - file: scripts/west_commands/boards.py
    commands:
      - name: boards
        class: Boards
        help: display information about supported boards

PS C:\ncs\led_test> west build --build-dir build_debug -- -DCMAKE_VERBOSE_MAKEFILE=ON WARNING: This looks like a fresh build and BOARD is unknown; so it probably won't work. To fix, use --board=<your-board>. Note: to silence the above message, run 'west config build.board_warn false' -- west build: generating a build system Loading Zephyr module(s) (Zephyr base): sysbuild_default -- Found Python3: C:/ncs/toolchains/b620d30767/opt/bin/python.exe (found suitable version "3.12.4", minimum required is "3.8") found components: Interpreter -- Cache files will be written to: C:/ncs/v2.9.0/zephyr/.cache -- Found west (found suitable version "1.2.0", minimum required is "0.14.0") CMake Error at C:/ncs/v2.9.0/zephyr/cmake/modules/extensions.cmake:3457 (message): BOARD is not being defined on the CMake command-line, in the environment or by the app. Call Stack (most recent call first): C:/ncs/v2.9.0/zephyr/cmake/modules/boards.cmake:61 (zephyr_check_cache) cmake/modules/sysbuild_default.cmake:15 (include) C:/ncs/v2.9.0/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:75 (include) C:/ncs/v2.9.0/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:92 (include_boilerplate) C:/ncs/v2.9.0/zephyr/share/sysbuild-package/cmake/SysbuildConfig.cmake:8 (include) template/CMakeLists.txt:10 (find_package) -- Configuring incomplete, errors occurred! See also "C:/ncs/led_test/build_debug/CMakeFiles/CMakeOutput.log". FATAL ERROR: command exited with status 1: 'C:\ncs\toolchains\b620d30767\opt\bin\cmake.EXE' -DWEST_PYTHON=C:/ncs/toolchains/b620d30767/opt/bin/python.exe '-BC:\ncs\led_test\build_debug' -GNinja -DCMAKE_VERBOSE_MAKEFILE=ON '-SC:\ncs\v2.9.0\zephyr\share\sysbuild' '-DAPP_DIR:PATH=C:\ncs\led_test' 给出解决方法
最新发布
03-28
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值