Zephyr实战篇之west工具软件

1.简介

首先,让我们来看看West是什么?

West是Zephyr项目提供的一款命令行工具,也被Zephyr官网称作”瑞士军刀“,可扩展的命令行工具,负责Zephyr工作区管理,管理不同的仓库,下载所有Zephyr源码以及其他依赖包配置工作区,通过调用其他工具,来实现工程的构建,烧写以及调试,支持添加自定义扩展指令。

2.边学边做

安装west也很方便,可以直接通过pip进行安装:

pip3 install --user -U west  

初始化完成之后,我们的工作区就会出现两个新的文件夹,一个是.west,里面是west的配置信息,另一个是zephyr,这里面包含了完整的zephyr代码。

可能有朋友要问了,既然说west内部集成了git的功能,来实现代码的管理,我怎么没看到你指定代码地址和代码版本号呢?别急,马上给大家解密。

west init默认使用https://github.com/zephyrproject-rtos/zephy 作为zephyr代码仓库地址,同时也可以通过-m来手动指定,使用--mr来指定所需版本,例如:

west init -m https://github.com/zephyrproject-rtos/zephyr --mr v2.6.0 

当然,只是下载zephyr的完整代码是不够的,zephyr依赖于很多的其他模块,例如驱动的SDK代码或者说hal层,这个是各大半导体厂商所定义的,这些都是单独管理的。通过执行west update,可以将这些模块全部下载到本地。这样一来,工作区中就会增加一些新的文件夹,看起来就像:

total 32  
drwxrwxr-x  8 jobs jobs 4096 Aug  8 09:12 ./  
drwxr-xr-x 11 jobs jobs 4096 Aug  7 09:44 ../  
drwxrwxr-x  3 jobs jobs 4096 Aug  8 09:12 bootloader/  
drwxrwxr-x  9 jobs jobs 4096 Aug  8 09:15 modules/  
drwxrwxr-x  4 jobs jobs 4096 Aug  8 09:12 tools/  
drwxrwxr-x  6 jobs jobs 4096 Aug  7 09:21 .venv/  
drwxrwxr-x  2 jobs jobs 4096 Aug  7 10:45 .west/  
drwxrwxr-x 23 jobs jobs 4096 Aug  7 10:45 zephyr/  

至此,全部代码才算是完整的被下载下来。通过执行west list还可以显示当前所有的外部代码仓库信息:

manifest     zephyr                       HEAD                                     N/A  
acpica       modules/lib/acpica           f16a0b4d0f0edd7b78a332fcf507be2187fac21e https://github.com/zephyrproject-rtos/acpica  
canopennode  modules/lib/canopennode      dec12fa3f0d790cafa8414a4c2930ea71ab72ffd https://github.com/zephyrproject-rtos/canopennode  
chre         modules/lib/chre             b7955c27e50485b7dafdc3888d7d6afdc2ac6d96 https://github.com/zephyrproject-rtos/chre  
cmsis        modules/hal/cmsis            74981bf893e8b10931464b9945e2143d99a3f0a3 https://github.com/zephyrproject-rtos/cmsis  
edtt         tools/edtt                   64e5105ad82390164fb73fc654be3f73a608209a https://github.com/zephyrproject-rtos/edtt  
fatfs        modules/fs/fatfs             427159bf95ea49b7680facffaa29ad506b42709b https://github.com/zephyrproject-rtos/fatfs  
hal_altera   modules/hal/altera           0d225ddd314379b32355a00fb669eacf911e750d https://github.com/zephyrproject-rtos/hal_altera  
hal_ambiq    modules/hal/ambiq            c8203b6fc752e51fb3cb1e98441f392cc4493623 https://github.com/zephyrproject-rtos/hal_ambiq  
hal_atmel    modules/hal/atmel            5ab43007eda3f380c125f957f03638d2e8d1144d https://github.com/zephyrproject-rtos/hal_atmel  
hal_espressif modules/hal/espressif        ae1bd648a1ac701672c46b6ff4eadfa716937ce3 https://github.com/zephyrproject-rtos/hal_espressif  
hal_ethos_u  modules/hal/ethos_u          90ada2ea5681b2a2722a10d2898eac34c2510791 https://github.com/zephyrproject-rtos/hal_ethos_u  
hal_gigadevice modules/hal/gigadevice       2994b7dde8b0b0fa9b9c0ccb13474b6a486cddc3 https://github.com/zephyrproject-rtos/hal_gigadevice  
hal_infineon modules/hal/infineon         0bebc14d8bd1a249ee7fbc70b37db6f01f72544f https://github.com/zephyrproject-rtos/hal_infineon  
hal_intel    modules/hal/intel            b04f13d58bd7b5b9349d6fc2e248679ce1b5579d https://github.com/zephyrproject-rtos/hal_intel  
hal_microchip modules/hal/microchip        5d079f1683a00b801373bbbbf5d181d4e33b30d5 https://github.com/zephyrproject-rtos/hal_microchip  
(还有不少呢!篇幅限制,贴了少量)  

其他一些版本管理相关的指令还有:

West diff类似于git diff

West status类似于git status

要注意的是,这几个指令的作用范围是所有代码仓库,包括zephyr自己以及其所依赖的外部代码。

那么zephyr或者说west是怎么知道需要下载哪些外部代码呢?这全都要感谢一个叫做west.yaml的文件,他藏在zephyr源码根目录下,长这个样子:

manifest:  
  defaults:  
    remote: upstream  
  
  remotes:  
    - name: upstream  
      url-base: https://github.com/zephyrproject-rtos  
    - name: babblesim  
      url-base: https://github.com/BabbleSim  
  
  group-filter: [-babblesim]  
  
  #  
  # Please add items below based on alphabetical order  
  projects:  
    - name: acpica  
      revision: f16a0b4d0f0edd7b78a332fcf507be2187fac21e  
      path: modules/lib/acpica  
    - name: bsim  
      repo-path: babblesim-manifest  
      revision: 384a091445c57b44ac8cbd18ebd245b47c71db94  
      path: tools/bsim  
      groups:  
        - babblesim  

其中最重要的就是这个manifest,他主要指定要下载的各个代码仓库的名称,路径和版本,由四个sub-section构成,包括default,remotes,projects和self。

其中remotes和projects是必须的,remotes指定远端地址,projects是各个子仓库的地址和版本。

举个简单的例子,比如这个canopennode,当我们执行west update时候,west会将remotes中定义的url-base和projects中的name结合为https://github.com/zephyrproject-rtos/canopennode,并下载版本为f167efe85c8c7de886f1bc47f9173cfb8a346bb5的代码到modules/lib/canopennode中。当然,也可以在remotes中指定多个url-base。

有了代码,就到了我们的代码编译下载调试阶段了。当然,我们强烈建议大家使用west来进行这个工作,如果实在不想用的话,使用原始命令行也是可以的,我们来看个例子,首先是使用west来编译代码:

west build -b mimxrt1060_evk samples/hello_world  

实现同样的功能如果不使用west呢?就要用以下这组命令:

cd samples/hello_world  
mkdir build  
cd build  
cmake -DBOARD=mimxrt1060_evk ..  
make -j  

类似的还有烧写和调试:

west flash 等同于  make flash

west debug  等同于  make debug

west debugserver   等同于 make debugserver

信息查看, 比如打印一些rom和ram占用情况:

west build -t rom_report  等同于  make rom_report

west build -t ram_report  等同于  make ram_report

查看当前所支持的所有板子:

west boards  

那么,以上就是被冠以“瑞士军刀“之名的west工具的简单介绍,也是我们在日常开发中,出现频率最高的west指令。

充分利用好west工具可以让我们的开发达到事半功倍的效果。最直观的方面就是,我们需要敲的指令数好像变少了

参考链接:

Zephyr实战篇之west工具软件-电子产品世界论坛

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值