West工具完全指南

West工具完全指南:Zephyr RTOS开发的瑞士军刀

引言

在Zephyr RTOS开发中,west是一个不可或缺的工具。它不仅是项目管理工具,更是整个Zephyr开发工作流的核心枢纽。本文将深入介绍west工具的定义、发展历程、安装配置方法以及常用命令,帮助开发者快速掌握这个强大的工具。


一、West是什么?

1.1 定义与定位

West 是Zephyr RTOS官方提供的多仓库管理工具构建系统前端。它基于Python开发,提供了统一的命令行接口,简化了Zephyr项目的初始化、构建和管理流程。

1.2 核心价值

特性 说明
多仓库管理 管理Zephyr生态的多个Git仓库
统一命令接口 提供build、flash、debug等统一命令
项目模板 支持快速创建新项目
配置管理 灵活的配置系统
扩展插件 支持自定义命令扩展

1.3 West在Zephyr生态中的位置

#mermaid-svg-QEhU7N951vbeD3qj{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-QEhU7N951vbeD3qj .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-QEhU7N951vbeD3qj .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-QEhU7N951vbeD3qj .error-icon{fill:#552222;}#mermaid-svg-QEhU7N951vbeD3qj .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-QEhU7N951vbeD3qj .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-QEhU7N951vbeD3qj .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-QEhU7N951vbeD3qj .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-QEhU7N951vbeD3qj .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-QEhU7N951vbeD3qj .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-QEhU7N951vbeD3qj .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-QEhU7N951vbeD3qj .marker{fill:#333333;stroke:#333333;}#mermaid-svg-QEhU7N951vbeD3qj .marker.cross{stroke:#333333;}#mermaid-svg-QEhU7N951vbeD3qj svg{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-QEhU7N951vbeD3qj p{margin:0;}#mermaid-svg-QEhU7N951vbeD3qj .label{font-family:"trebuchet ms",verdana,arial,sans-serif;color:#333;}#mermaid-svg-QEhU7N951vbeD3qj .cluster-label text{fill:#333;}#mermaid-svg-QEhU7N951vbeD3qj .cluster-label span{color:#333;}#mermaid-svg-QEhU7N951vbeD3qj .cluster-label span p{background-color:transparent;}#mermaid-svg-QEhU7N951vbeD3qj .label text,#mermaid-svg-QEhU7N951vbeD3qj span{fill:#333;color:#333;}#mermaid-svg-QEhU7N951vbeD3qj .node rect,#mermaid-svg-QEhU7N951vbeD3qj .node circle,#mermaid-svg-QEhU7N951vbeD3qj .node ellipse,#mermaid-svg-QEhU7N951vbeD3qj .node polygon,#mermaid-svg-QEhU7N951vbeD3qj .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-QEhU7N951vbeD3qj .rough-node .label text,#mermaid-svg-QEhU7N951vbeD3qj .node .label text,#mermaid-svg-QEhU7N951vbeD3qj .image-shape .label,#mermaid-svg-QEhU7N951vbeD3qj .icon-shape .label{text-anchor:middle;}#mermaid-svg-QEhU7N951vbeD3qj .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#mermaid-svg-QEhU7N951vbeD3qj .rough-node .label,#mermaid-svg-QEhU7N951vbeD3qj .node .label,#mermaid-svg-QEhU7N951vbeD3qj .image-shape .label,#mermaid-svg-QEhU7N951vbeD3qj .icon-shape .label{text-align:center;}#mermaid-svg-QEhU7N951vbeD3qj .node.clickable{cursor:pointer;}#mermaid-svg-QEhU7N951vbeD3qj .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#mermaid-svg-QEhU7N951vbeD3qj .arrowheadPath{fill:#333333;}#mermaid-svg-QEhU7N951vbeD3qj .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-QEhU7N951vbeD3qj .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-QEhU7N951vbeD3qj .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-QEhU7N951vbeD3qj .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#mermaid-svg-QEhU7N951vbeD3qj .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-QEhU7N951vbeD3qj .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#mermaid-svg-QEhU7N951vbeD3qj .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-QEhU7N951vbeD3qj .cluster text{fill:#333;}#mermaid-svg-QEhU7N951vbeD3qj .cluster span{color:#333;}#mermaid-svg-QEhU7N951vbeD3qj div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-QEhU7N951vbeD3qj .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#mermaid-svg-QEhU7N951vbeD3qj rect.text{fill:none;stroke-width:0;}#mermaid-svg-QEhU7N951vbeD3qj .icon-shape,#mermaid-svg-QEhU7N951vbeD3qj .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-QEhU7N951vbeD3qj .icon-shape p,#mermaid-svg-QEhU7N951vbeD3qj .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#mermaid-svg-QEhU7N951vbeD3qj .icon-shape .label rect,#mermaid-svg-QEhU7N951vbeD3qj .image-shape .label rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-QEhU7N951vbeD3qj .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#mermaid-svg-QEhU7N951vbeD3qj .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#mermaid-svg-QEhU7N951vbeD3qj :root{--mermaid-font-family:"trebuchet ms",verdana,arial,sans-serif;} 开发者
West工具
Zephyr核心仓库
应用代码
模块仓库
SDK工具链
内核代码
设备驱动
协议栈
交叉编译器
调试工具
仿真工具


二、发展历史

2.1 演进历程

时间节点 版本 重要更新
2018年 West 0.1 初始版本,基本仓库管理功能
2019年 West 0.5 集成build命令
2020年 West 0.7 支持多配置文件
2021年 West 0.10 引入插件系统
2022年 West 1.0 稳定版本发布
2023年 West 1.2 增强调试支持

2.2 发展时间线

#mermaid-svg-awpMKOTzJESVy5R1{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-awpMKOTzJESVy5R1 .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-awpMKOTzJESVy5R1 .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-awpMKOTzJESVy5R1 .error-icon{fill:#552222;}#mermaid-svg-awpMKOTzJESVy5R1 .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-awpMKOTzJESVy5R1 .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-awpMKOTzJESVy5R1 .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-awpMKOTzJESVy5R1 .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-awpMKOTzJESVy5R1 .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-awpMKOTzJESVy5R1 .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-awpMKOTzJESVy5R1 .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-awpMKOTzJESVy5R1 .marker{fill:#333333;stroke:#333333;}#mermaid-svg-awpMKOTzJESVy5R1 .marker.cross{stroke:#333333;}#mermaid-svg-awpMKOTzJESVy5R1 svg{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-awpMKOTzJESVy5R1 p{margin:0;}#mermaid-svg-awpMKOTzJESVy5R1 .edge{stroke-width:3;}#mermaid-svg-awpMKOTzJESVy5R1 .section--1 rect,#mermaid-svg-awpMKOTzJESVy5R1 .section--1 path,#mermaid-svg-awpMKOTzJESVy5R1 .section--1 circle,#mermaid-svg-awpMKOTzJESVy5R1 .section--1 path{fill:hsl(240, 100%, 76.2745098039%);}#mermaid-svg-awpMKOTzJESVy5R1 .section--1 text{fill:#ffffff;}#mermaid-svg-awpMKOTzJESVy5R1 .node-icon--1{font-size:40px;color:#ffffff;}#mermaid-svg-awpMKOTzJESVy5R1 .section-edge--1{stroke:hsl(240, 100%, 76.2745098039%);}#mermaid-svg-awpMKOTzJESVy5R1 .edge-depth--1{stroke-width:17;}#mermaid-svg-awpMKOTzJESVy5R1 .section--1 line{stroke:hsl(60, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-awpMKOTzJESVy5R1 .lineWrapper line{stroke:#ffffff;}#mermaid-svg-awpMKOTzJESVy5R1 .disabled,#mermaid-svg-awpMKOTzJESVy5R1 .disabled circle,#mermaid-svg-awpMKOTzJESVy5R1 .disabled text{fill:lightgray;}#mermaid-svg-awpMKOTzJESVy5R1 .disabled text{fill:#efefef;}#mermaid-svg-awpMKOTzJESVy5R1 .section-0 rect,#mermaid-svg-awpMKOTzJESVy5R1 .section-0 path,#mermaid-svg-awpMKOTzJESVy5R1 .section-0 circle,#mermaid-svg-awpMKOTzJESVy5R1 .section-0 path{fill:hsl(60, 100%, 73.5294117647%);}#mermaid-svg-awpMKOTzJESVy5R1 .section-0 text{fill:black;}#mermaid-svg-awpMKOTzJESVy5R1 .node-icon-0{font-size:40px;color:black;}#mermaid-svg-awpMKOTzJESVy5R1 .section-edge-0{stroke:hsl(60, 100%, 73.5294117647%);}#mermaid-svg-awpMKOTzJESVy5R1 .edge-depth-0{stroke-width:14;}#mermaid-svg-awpMKOTzJESVy5R1 .section-0 line{stroke:hsl(240, 100%, 83.5294117647%);stroke-width:3;}#mermaid-svg-awpMKOTzJESVy5R1 .lineWrapper line{stroke:black;}#mermaid-svg-awpMKOTzJESVy5R1 .disabled,#mermaid-svg-awpMKOTzJESVy5R1 .disabled circle,#mermaid-svg-awpMKOTzJESVy5R1 .disabled text{fill:lightgray;}#mermaid-svg-awpMKOTzJESVy5R1 .disabled text{fill:#efefef;}#mermaid-svg-awpMKOTzJESVy5R1 .section-1 rect,#mermaid-svg-awpMKOTzJESVy5R1 .section-1 path,#mermaid-svg-awpMKOTzJESVy5R1 .section-1 circle,#mermaid-svg-awpMKOTzJESVy5R1 .section-1 path{fill:hsl(80, 100%, 76.2745098039%);}#mermaid-svg-awpMKOTzJESVy5R1 .section-1 text{fill:black;}#mermaid-svg-awpMKOTzJESVy5R1 .node-icon-1{font-size:40px;color:black;}#mermaid-svg-awpMKOTzJESVy5R1 .section-edge-1{stroke:hsl(80, 100%, 76.2745098039%);}#mermaid-svg-awpMKOTzJESVy5R1 .edge-depth-1{stroke-width:11;}#mermaid-svg-awpMKOTzJESVy5R1 .section-1 line{stroke:hsl(260, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-awpMKOTzJESVy5R1 .lineWrapper line{stroke:black;}#mermaid-svg-awpMKOTzJESVy5R1 .disabled,#mermaid-svg-awpMKOTzJESVy5R1 .disabled circle,#mermaid-svg-awpMKOTzJESVy5R1 .disabled text{fill:lightgray;}#mermaid-svg-awpMKOTzJESVy5R1 .disabled text{fill:#efefef;}#mermaid-svg-awpMKOTzJESVy5R1 .section-2 rect,#mermaid-svg-awpMKOTzJESVy5R1 .section-2 path,#mermaid-svg-awpMKOTzJESVy5R1 .section-2 circle,#mermaid-svg-awpMKOTzJESVy5R1 .section-2 path{fill:hsl(270, 100%, 76.2745098039%);}#mermaid-svg-awpMKOTzJESVy5R1 .section-2 text{fill:#ffffff;}#mermaid-svg-awpMKOTzJESVy5R1 .node-icon-2{font-size:40px;color:#ffffff;}#mermaid-svg-awpMKOTzJESVy5R1 .section-edge-2{stroke:hsl(270, 100%, 76.2745098039%);}#mermaid-svg-awpMKOTzJESVy5R1 .edge-depth-2{stroke-width:8;}#mermaid-svg-awpMKOTzJESVy5R1 .section-2 line{stroke:hsl(90, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-awpMKOTzJESVy5R1 .lineWrapper line{stroke:#ffffff;}#mermaid-svg-awpMKOTzJESVy5R1 .disabled,#mermaid-svg-awpMKOTzJESVy5R1 .disabled circle,#mermaid-svg-awpMKOTzJESVy5R1 .disabled text{fill:lightgray;}#mermaid-svg-awpMKOTzJESVy5R1 .disabled text{fill:#efefef;}#mermaid-svg-awpMKOTzJESVy5R1 .section-3 rect,#mermaid-svg-awpMKOTzJESVy5R1 .section-3 path,#mermaid-svg-awpMKOTzJESVy5R1 .section-3 circle,#mermaid-svg-awpMKOTzJESVy5R1 .section-3 path{fill:hsl(300, 100%, 76.2745098039%);}#mermaid-svg-awpMKOTzJESVy5R1 .section-3 text{fill:black;}#mermaid-svg-awpMKOTzJESVy5R1 .node-icon-3{font-size:40px;color:black;}#mermaid-svg-awpMKOTzJESVy5R1 .section-edge-3{stroke:hsl(300, 100%, 76.2745098039%);}#mermaid-svg-awpMKOTzJESVy5R1 .edge-depth-3{stroke-width:5;}#mermaid-svg-awpMKOTzJESVy5R1 .section-3 line{stroke:hsl(120, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-awpMKOTzJESVy5R1 .lineWrapper line{stroke:black;}#mermaid-svg-awpMKOTzJESVy5R1 .disabled,#mermaid-svg-awpMKOTzJESVy5R1 .disabled circle,#mermaid-svg-awpMKOTzJESVy5R1 .disabled text{fill:lightgray;}#mermaid-svg-awpMKOTzJESVy5R1 .disabled text{fill:#efefef;}#mermaid-svg-awpMKOTzJESVy5R1 .section-4 rect,#mermaid-svg-awpMKOTzJESVy5R1 .section-4 path,#mermaid-svg-awpMKOTzJESVy5R1 .section-4 circle,#mermaid-svg-awpMKOTzJESVy5R1 .section-4 path{fill:hsl(330, 100%, 76.2745098039%);}#mermaid-svg-awpMKOTzJESVy5R1 .section-4 text{fill:black;}#mermaid-svg-awpMKOTzJESVy5R1 .node-icon-4{font-size:40px;color:black;}#mermaid-svg-awpMKOTzJESVy5R1 .section-edge-4{stroke:hsl(330, 100%, 76.2745098039%);}#mermaid-svg-awpMKOTzJESVy5R1 .edge-depth-4{stroke-width:2;}#mermaid-svg-awpMKOTzJESVy5R1 .section-4 line{stroke:hsl(150, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-awpMKOTzJESVy5R1 .lineWrapper line{stroke:black;}#mermaid-svg-awpMKOTzJESVy5R1 .disabled,#mermaid-svg-awpMKOTzJESVy5R1 .disabled circle,#mermaid-svg-awpMKOTzJESVy5R1 .disabled text{fill:lightgray;}#mermaid-svg-awpMKOTzJESVy5R1 .disabled text{fill:#efefef;}#mermaid-svg-awpMKOTzJESVy5R1 .section-5 rect,#mermaid-svg-awpMKOTzJESVy5R1 .section-5 path,#mermaid-svg-awpMKOTzJESVy5R1 .section-5 circle,#mermaid-svg-awpMKOTzJESVy5R1 .section-5 path{fill:hsl(0, 100%, 76.2745098039%);}#mermaid-svg-awpMKOTzJESVy5R1 .section-5 text{fill:black;}#mermaid-svg-awpMKOTzJESVy5R1 .node-icon-5{font-size:40px;color:black;}#mermaid-svg-awpMKOTzJESVy5R1 .section-edge-5{stroke:hsl(0, 100%, 76.2745098039%);}#mermaid-svg-awpMKOTzJESVy5R1 .edge-depth-5{stroke-width:-1;}#mermaid-svg-awpMKOTzJESVy5R1 .section-5 line{stroke:hsl(180, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-awpMKOTzJESVy5R1 .lineWrapper line{stroke:black;}#mermaid-svg-awpMKOTzJESVy5R1 .disabled,#mermaid-svg-awpMKOTzJESVy5R1 .disabled circle,#mermaid-svg-awpMKOTzJESVy5R1 .disabled text{fill:lightgray;}#mermaid-svg-awpMKOTzJESVy5R1 .disabled text{fill:#efefef;}#mermaid-svg-awpMKOTzJESVy5R1 .section-6 rect,#mermaid-svg-awpMKOTzJESVy5R1 .section-6 path,#mermaid-svg-awpMKOTzJESVy5R1 .section-6 circle,#mermaid-svg-awpMKOTzJESVy5R1 .section-6 path{fill:hsl(30, 100%, 76.2745098039%);}#mermaid-svg-awpMKOTzJESVy5R1 .section-6 text{fill:black;}#mermaid-svg-awpMKOTzJESVy5R1 .node-icon-6{font-size:40px;color:black;}#mermaid-svg-awpMKOTzJESVy5R1 .section-edge-6{stroke:hsl(30, 100%, 76.2745098039%);}#mermaid-svg-awpMKOTzJESVy5R1 .edge-depth-6{stroke-width:-4;}#mermaid-svg-awpMKOTzJESVy5R1 .section-6 line{stroke:hsl(210, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-awpMKOTzJESVy5R1 .lineWrapper line{stroke:black;}#mermaid-svg-awpMKOTzJESVy5R1 .disabled,#mermaid-svg-awpMKOTzJESVy5R1 .disabled circle,#mermaid-svg-awpMKOTzJESVy5R1 .disabled text{fill:lightgray;}#mermaid-svg-awpMKOTzJESVy5R1 .disabled text{fill:#efefef;}#mermaid-svg-awpMKOTzJESVy5R1 .section-7 rect,#mermaid-svg-awpMKOTzJESVy5R1 .section-7 path,#mermaid-svg-awpMKOTzJESVy5R1 .section-7 circle,#mermaid-svg-awpMKOTzJESVy5R1 .section-7 path{fill:hsl(90, 100%, 76.2745098039%);}#mermaid-svg-awpMKOTzJESVy5R1 .section-7 text{fill:black;}#mermaid-svg-awpMKOTzJESVy5R1 .node-icon-7{font-size:40px;color:black;}#mermaid-svg-awpMKOTzJESVy5R1 .section-edge-7{stroke:hsl(90, 100%, 76.2745098039%);}#mermaid-svg-awpMKOTzJESVy5R1 .edge-depth-7{stroke-width:-7;}#mermaid-svg-awpMKOTzJESVy5R1 .section-7 line{stroke:hsl(270, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-awpMKOTzJESVy5R1 .lineWrapper line{stroke:black;}#mermaid-svg-awpMKOTzJESVy5R1 .disabled,#mermaid-svg-awpMKOTzJESVy5R1 .disabled circle,#mermaid-svg-awpMKOTzJESVy5R1 .disabled text{fill:lightgray;}#mermaid-svg-awpMKOTzJESVy5R1 .disabled text{fill:#efefef;}#mermaid-svg-awpMKOTzJESVy5R1 .section-8 rect,#mermaid-svg-awpMKOTzJESVy5R1 .section-8 path,#mermaid-svg-awpMKOTzJESVy5R1 .section-8 circle,#mermaid-svg-awpMKOTzJESVy5R1 .section-8 path{fill:hsl(150, 100%, 76.2745098039%);}#mermaid-svg-awpMKOTzJESVy5R1 .section-8 text{fill:black;}#mermaid-svg-awpMKOTzJESVy5R1 .node-icon-8{font-size:40px;color:black;}#mermaid-svg-awpMKOTzJESVy5R1 .section-edge-8{stroke:hsl(150, 100%, 76.2745098039%);}#mermaid-svg-awpMKOTzJESVy5R1 .edge-depth-8{stroke-width:-10;}#mermaid-svg-awpMKOTzJESVy5R1 .section-8 line{stroke:hsl(330, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-awpMKOTzJESVy5R1 .lineWrapper line{stroke:black;}#mermaid-svg-awpMKOTzJESVy5R1 .disabled,#mermaid-svg-awpMKOTzJESVy5R1 .disabled circle,#mermaid-svg-awpMKOTzJESVy5R1 .disabled text{fill:lightgray;}#mermaid-svg-awpMKOTzJESVy5R1 .disabled text{fill:#efefef;}#mermaid-svg-awpMKOTzJESVy5R1 .section-9 rect,#mermaid-svg-awpMKOTzJESVy5R1 .section-9 path,#mermaid-svg-awpMKOTzJESVy5R1 .section-9 circle,#mermaid-svg-awpMKOTzJESVy5R1 .section-9 path{fill:hsl(180, 100%, 76.2745098039%);}#mermaid-svg-awpMKOTzJESVy5R1 .section-9 text{fill:black;}#mermaid-svg-awpMKOTzJESVy5R1 .node-icon-9{font-size:40px;color:black;}#mermaid-svg-awpMKOTzJESVy5R1 .section-edge-9{stroke:hsl(180, 100%, 76.2745098039%);}#mermaid-svg-awpMKOTzJESVy5R1 .edge-depth-9{stroke-width:-13;}#mermaid-svg-awpMKOTzJESVy5R1 .section-9 line{stroke:hsl(0, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-awpMKOTzJESVy5R1 .lineWrapper line{stroke:black;}#mermaid-svg-awpMKOTzJESVy5R1 .disabled,#mermaid-svg-awpMKOTzJESVy5R1 .disabled circle,#mermaid-svg-awpMKOTzJESVy5R1 .disabled text{fill:lightgray;}#mermaid-svg-awpMKOTzJESVy5R1 .disabled text{fill:#efefef;}#mermaid-svg-awpMKOTzJESVy5R1 .section-10 rect,#mermaid-svg-awpMKOTzJESVy5R1 .section-10 path,#mermaid-svg-awpMKOTzJESVy5R1 .section-10 circle,#mermaid-svg-awpMKOTzJESVy5R1 .section-10 path{fill:hsl(210, 100%, 76.2745098039%);}#mermaid-svg-awpMKOTzJESVy5R1 .section-10 text{fill:black;}#mermaid-svg-awpMKOTzJESVy5R1 .node-icon-10{font-size:40px;color:black;}#mermaid-svg-awpMKOTzJESVy5R1 .section-edge-10{stroke:hsl(210, 100%, 76.2745098039%);}#mermaid-svg-awpMKOTzJESVy5R1 .edge-depth-10{stroke-width:-16;}#mermaid-svg-awpMKOTzJESVy5R1 .section-10 line{stroke:hsl(30, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-awpMKOTzJESVy5R1 .lineWrapper line{stroke:black;}#mermaid-svg-awpMKOTzJESVy5R1 .disabled,#mermaid-svg-awpMKOTzJESVy5R1 .disabled circle,#mermaid-svg-awpMKOTzJESVy5R1 .disabled text{fill:lightgray;}#mermaid-svg-awpMKOTzJESVy5R1 .disabled text{fill:#efefef;}#mermaid-svg-awpMKOTzJESVy5R1 .section-root rect,#mermaid-svg-awpMKOTzJESVy5R1 .section-root path,#mermaid-svg-awpMKOTzJESVy5R1 .section-root circle{fill:hsl(240, 100%, 46.2745098039%);}#mermaid-svg-awpMKOTzJESVy5R1 .section-root text{fill:#ffffff;}#mermaid-svg-awpMKOTzJESVy5R1 .icon-container{height:100%;display:flex;justify-content:center;align-items:center;}#mermaid-svg-awpMKOTzJESVy5R1 .edge{fill:none;}#mermaid-svg-awpMKOTzJESVy5R1 .eventWrapper{filter:brightness(120%);}#mermaid-svg-awpMKOTzJESVy5R1 :root{--mermaid-font-family:"trebuchet ms",verdana,arial,sans-serif;} 起步阶段 2018 West 0.1发布 2019 集成build命令 发展阶段 2020 多配置支持 2021 插件系统 成熟阶段 2022 1.0稳定版 2023 增强调试 West工具发展时间线


三、安装方法

3.1 环境要求

依赖 版本要求
Python >= 3.8
Git >= 2.20
pip >= 19.0

3.2 使用pip安装

bash 复制代码
# 安装最新稳定版
pip install west

# 安装指定版本
pip install west==1.2.0

# 安装开发版
pip install git+https://github.com/zephyrproject-rtos/west.git

3.3 验证安装

bash 复制代码
# 查看版本
west --version

# 输出示例
West version: v1.2.0

3.4 升级West

bash 复制代码
# 升级到最新版本
pip install --upgrade west

四、配置指南

4.1 初始化Zephyr项目

bash 复制代码
# 创建项目目录
mkdir zephyrproject && cd zephyrproject

# 初始化West项目
west init -m https://github.com/zephyrproject-rtos/zephyr --mr main .

# 更新所有模块
west update

4.2 配置文件结构

复制代码
zephyrproject/
├── .west/
│   ├── config            # West配置文件
│   └── manifest.xml      # 仓库清单
├── zephyr/               # Zephyr核心代码
├── modules/              # 外部模块
└── tools/                # 工具脚本

4.3 West配置文件

配置文件位置~/.west/config.west/config

ini 复制代码
# .west/config 示例内容
[west]
  manifest = .west/manifest.xml
  revision = main

[zephyr]
  board = qemu_x86
  build-dir = build

4.4 环境变量配置

bash 复制代码
# Linux/macOS - 添加到 ~/.bashrc
export ZEPHYR_BASE=$HOME/zephyrproject/zephyr
export PATH=$HOME/.local/bin:$PATH

# Windows - PowerShell
$env:ZEPHYR_BASE = "$HOME/zephyrproject/zephyr"
$env:PATH += ";$HOME/.local/bin"

五、核心命令详解

5.1 项目管理命令

5.1.1 west init

作用:初始化Zephyr项目

bash 复制代码
# 基本用法
west init <project_dir>

# 指定manifest仓库
west init -m https://github.com/zephyrproject-rtos/zephyr .

# 指定分支
west init -m https://github.com/zephyrproject-rtos/zephyr --mr v3.5.0 .
5.1.2 west update

作用:更新所有仓库

bash 复制代码
# 更新所有模块
west update

# 更新指定模块
west update zephyr

# 强制更新
west update --force
5.1.3 west list

作用:列出所有仓库

bash 复制代码
# 列出所有模块
west list

# 详细信息
west list -v

# 输出格式
west list --format "{name} {revision}"

5.2 构建命令

5.2.1 west build

作用:编译项目

bash 复制代码
# 基本用法
west build -b <board> <app_dir>

# 编译hello_world示例
west build -b qemu_x86 samples/hello_world

# 指定构建目录
west build -b qemu_x86 samples/hello_world -d build_hello

# 传递CMake参数
west build -b qemu_x86 -- -DCONFIG_DEBUG=y

# 清理构建
west build -t clean

# 重新构建
west build -b qemu_x86 --pristine
5.2.2 west flash

作用:烧录固件到目标板

bash 复制代码
# 烧录到开发板
west flash

# 指定烧录器
west flash --runner jlink

# 指定设备
west flash --dt-flash=0x08000000
5.2.3 west run

作用:启动仿真

bash 复制代码
# 运行仿真
west build -b qemu_x86 -t run

# 使用Renode仿真
west build -b nrf52840dk_nrf52840 -t run --runner=renode

5.3 调试命令

5.3.1 west debug

作用:启动调试会话

bash 复制代码
# 启动GDB调试
west debug

# 指定调试器
west debug --runner jlink

# 附加到运行中的程序
west debug --attach
5.3.2 west debugserver

作用:启动调试服务器

bash 复制代码
# 启动OpenOCD服务器
west debugserver

# 启动J-Link服务器
west debugserver --runner jlink

5.4 辅助命令

5.4.1 west status

作用:查看仓库状态

bash 复制代码
# 查看所有仓库状态
west status

# 查看指定仓库
west status zephyr
5.4.2 west diff

作用:显示代码差异

bash 复制代码
# 显示所有仓库差异
west diff

# 显示指定仓库差异
west diff zephyr

# 显示暂存区差异
west diff --cached
5.4.3 west help

作用:显示帮助信息

bash 复制代码
# 显示所有命令
west help

# 显示特定命令帮助
west help build

# 显示命令选项
west build --help

六、高级配置

6.1 Manifest文件详解

Manifest文件定义了项目包含的所有仓库:

xml 复制代码
<!-- .west/manifest.xml 示例 -->
<manifest>
  <defaults>
    <remote name="origin" url-base="https://github.com/zephyrproject-rtos"/>
  </defaults>
  
  <project name="zephyr" revision="main">
    <path name="zephyr"/>
    <submodule name="hal/stm32"/>
  </project>
  
  <project name="mcuboot" revision="main" path="modules/bootloader/mcuboot"/>
  
  <project name="tinycbor" revision="v0.6.0" path="modules/lib/tinycbor"/>
</manifest>

6.2 自定义命令扩展

创建自定义West命令

python 复制代码
# my_extension.py
from west.commands import WestCommand

class MyCommand(WestCommand):
    def __init__(self):
        super().__init__(
            'mycmd',
            '自定义命令',
            '执行自定义操作'
        )
    
    def do_add_parser(self, parser_adder):
        parser = parser_adder.add_parser(self.name, help=self.help)
        parser.add_argument('arg', help='参数')
        return parser
    
    def run(self, args, unknown_args):
        print(f'执行自定义命令,参数: {args.arg}')

6.3 多项目管理

工作区配置

bash 复制代码
# 创建工作区
west init -m https://github.com/myorg/myproject workspace

# 添加本地项目
west add /path/to/my/project --name myapp

# 查看工作区配置
west config --list

七、常见问题与解决方案

7.1 West命令找不到

问题

复制代码
command not found: west

解决方案

bash 复制代码
# 检查PATH环境变量
echo $PATH | grep .local/bin

# 添加到PATH
export PATH=$HOME/.local/bin:$PATH

# 永久添加(Linux/macOS)
echo 'export PATH=$HOME/.local/bin:$PATH' >> ~/.bashrc

7.2 无法初始化项目

问题

复制代码
west init: error: cannot find manifest repository

解决方案

bash 复制代码
# 检查网络连接
ping github.com

# 使用HTTPS协议
west init -m https://github.com/zephyrproject-rtos/zephyr .

# 检查Git版本
git --version

7.3 构建失败

问题

复制代码
CMake Error: Could not find toolchain

解决方案

bash 复制代码
# 检查SDK安装
ls $ZEPHYR_SDK_INSTALL_DIR

# 重新运行setup.sh
cd $ZEPHYR_SDK_INSTALL_DIR
./setup.sh

# 检查环境变量
echo $ZEPHYR_TOOLCHAIN_VARIANT

7.4 烧录失败

问题

复制代码
Error: cannot find J-Link

解决方案

bash 复制代码
# 检查J-Link安装
which JLinkExe

# 安装J-Link驱动
sudo apt install libusb-1.0-0-dev

# 检查USB连接
lsusb | grep J-Link

八、实践示例

8.1 创建并运行第一个项目

bash 复制代码
# 1. 创建项目目录
mkdir myfirstapp && cd myfirstapp

# 2. 初始化West项目
west init -m https://github.com/zephyrproject-rtos/zephyr --mr main .

# 3. 更新模块
west update

# 4. 编译示例
west build -b qemu_x86 samples/hello_world

# 5. 运行仿真
west build -t run

8.2 创建自定义应用

bash 复制代码
# 1. 创建应用目录
mkdir -p apps/myapp/src

# 2. 创建main.c
cat > apps/myapp/src/main.c << EOF
#include <zephyr/kernel.h>
#include <zephyr/logging/log.h>

LOG_MODULE_REGISTER(app);

void main(void) {
    LOG_INF("Hello from my custom app!");
    while (1) {
        k_msleep(1000);
        LOG_INF("Running...");
    }
}
EOF

# 3. 创建CMakeLists.txt
cat > apps/myapp/CMakeLists.txt << EOF
cmake_minimum_required(VERSION 3.20.0)
find_package(Zephyr REQUIRED HINTS \$ENV{ZEPHYR_BASE})
project(myapp)
target_sources(app PRIVATE src/main.c)
EOF

# 4. 创建prj.conf
cat > apps/myapp/prj.conf << EOF
CONFIG_LOG=y
EOF

# 5. 编译运行
west build -b qemu_x86 apps/myapp -t run

九、West命令速查表

命令 功能 示例
west init 初始化项目 west init .
west update 更新模块 west update
west build 编译项目 west build -b qemu_x86
west flash 烧录固件 west flash
west run 运行仿真 west build -t run
west debug 调试程序 west debug
west list 列出仓库 west list
west status 查看状态 west status
west diff 显示差异 west diff
west help 显示帮助 west help

结束语

West工具是Zephyr RTOS开发的核心工具,它简化了项目管理、构建和调试流程。通过本文的介绍,相信您已经掌握了West的基本使用方法和高级配置技巧。

West的设计理念是提供统一的命令接口,让开发者专注于应用开发而非工具配置。随着Zephyr生态的不断发展,West也在持续进化,为开发者提供更强大的功能。


参考资料

相关推荐
ScilogyHunter3 小时前
Zephyr SDK 完全指南
zephyr
Molesidy1 天前
【Embedded Development】【Zephyr】【Windows】基于STM32的Zephyr移植
stm32·led·zephyr
IAR Systems1 天前
使用IAR Arm工具链开发和调试Zephyr RTOS
arm开发·嵌入式·iar·zephyr
mftang19 天前
Zephyr RTOS 中k_mutex(互斥锁)功能介绍
互斥锁·zephyr·zephyr rtos·k_mutex
fitpolo20 天前
蓝牙低功耗基3-蓝牙低功耗中的数据交4
zephyr
嵌入式学习和实践1 个月前
Zephyr 实时系统下 W25Q128 + LittleFS 文件系统实战指南
zephyr·lfs文件系统·w25q128
mftang1 个月前
Zephyr RTOS 下 BLE 主动扫描和被动扫描详解
被动扫描·蓝牙协议栈·zephyr·主动扫描
mftang1 个月前
Zephyr RTOS中bt_conn_le_create 函数用法详细介绍
zephyr·ble central
mftang2 个月前
Zephyr RTOS 中 BT_CONN_CB_DEFINE 详解
zephyr·central·peripheral·注册回调