核心只有一条 git 配置:url.<镜像前缀>.insteadOf <官方前缀>。
git config --global url."https://www.zephyrrtos.cn:3000/zephyrrtos_china/".insteadOf "https://github.com/zephyrproject-rtos/"
git 在访问任何 https://github.com/zephyrproject-rtos/… 时,会自动改写为镜像地址——
包括你自己敲的 git clone、工程里写死的 URL。
west 拉取模块也是调用 git,因此 west init / west update 无需任何额外配置;
manifest 里的 remote 保持官方地址即可。
镜像侧定期执行 west update 后把 zephyr 与各模块
push --mirror 到 Gitea 组织,模块清单以 west list 为准。
zephyrrtos_china 需要账号访问。
先在 zephyrrtos.cn 申请账号(见 如何加入),并在账号里配置公钥或访问令牌。
也可以直接下载 zephyr_cn_setup.sh 一次跑完(下面就是它的步骤)。
sudo apt install --no-install-recommends git cmake ninja-build gperf \ ccache dfu-util device-tree-compiler wget python3-dev python3-venv python3-tk \ xz-utils file make gcc gcc-multilib g++-multilib libsdl2-dev libmagic1
python3 -m venv ~/zephyrproject/.venv source ~/zephyrproject/.venv/bin/activate pip install west
git config --global url."https://www.zephyrrtos.cn:3000/zephyrrtos_china/".insteadOf "https://github.com/zephyrproject-rtos/" git config --global --get-regexp 'url\..*\.insteadOf' # 确认已写入
cd ~/zephyrproject west init . west update # 走国内镜像,模块会一次性拉齐
git clone https://www.zephyrrtos.cn:3000/zephyrrtos_china/zephyr_sdkSDK 体量大,走镜像比直连 GitHub Releases 稳定得多。
source ~/zephyrproject/.venv/bin/activate cd ~/zephyrproject/zephyr west build -b <your_board> samples/hello_world
| 只想用一次(不动全局) | git clone https://www.zephyrrtos.cn:3000/zephyrrtos_china/zephyr.git |
|---|---|
| 只对当前仓库改远端 | git remote set-url origin https://www.zephyrrtos.cn:3000/zephyrrtos_china/zephyr.git |
| 只对当前工作区生效 | 把重定向命令里的 --global 换成 --local(在工程根目录执行) |
| 恢复官方源 | git config --global --unset url."https://www.zephyrrtos.cn:3000/zephyrrtos_china/".insteadOf |
| 临时绕过镜像 | 单次命令用 -c url."https://github.com/zephyrproject-rtos/".insteadOf="",或直接写官方地址克隆 |
git credential / SSH key / 访问令牌等方式;
把口令拼进 URL(例如 https://user:password@host/…)会随 git 记录、日志与截图一起泄露。
| 403 / 401 认证失败 | 镜像需登录:确认账号存在、公钥或令牌已配置;检查 git config --global --get-regexp url 里的地址无误。 |
|---|---|
| 仍从 GitHub 拉取 | 确认重定向已写入(--get-regexp),且命令是在配置生效后执行;子模块可能带独立配置。 |
| 某个模块 404 | 该模块可能尚未同步到镜像。用 west list 看模块与实际 URL,并把缺失模块反馈给我们。 |
west update 中断 | 直接重跑即可(git 支持断点续传);必要时 west update --narrow -o=--depth=1 浅克隆加速。 |
| 端口与协议 | 镜像地址使用 https://www.zephyrrtos.cn:3000(HTTPS,含 www 与裸域两种写法均可解析)。 |