# Yocto 构建时手动下载资源

在编译过程中，碰到下载错误，或是下载慢的时候，可以使用手动下载方式加速下载。

下载资源分为两种，一种是直接下载压缩包文件，另一种是下载 git 仓库。



## 手动下载压缩包文件

![download_error_tar](file:///Users/lihm/workroom/Misc/assets/download_error_tar.png?lastModify=1612188420)

> 此图片为 tar.gz 压缩包文件下载失败

从错误信息可以看到下载路径。但当下载慢的时候，是无法显示下载路径的，还是必须要从 bb 文件中查找。

下载错误的包为 `xfce4-panel` ，后面为版本号。

1. 查找下载地址

   ```bash
   # 在 build 目录下，如 thead-build/ice-base-xfce
   bitbake -e xfce4-panel | grep ^SRC_URI
   SRC_URI="http://archive.xfce.org/src/xfce/xfce4-panel/4.16/xfce4-panel-4.16.0.tar.bz2      file://0001-windowmenu-do-not-display-desktop-icon-when-no-windo.patch     file://0002-use-lxdm-to-replace-dm-tool.patch "
   ```

2. 下载文件

   当下载的资源为压缩包时，下载目录就在 downloads 目录下，这时候就可以使用多线程下载工具下载文件，文件名就为原始文件名。

   ```basj
   axel -n 16 http://archive.xfce.org/src/xfce/xfce4-panel/4.16/xfce4-panel-4.16.0.tar.bz2
   
   ./downloads$ ll xfce4-
   xfce4-dev-tools-4.16.0.tar.bz2       xfce4-notifyd-0.6.2.tar.bz2.done     xfce4-session-4.16.0.tar.bz2.done    xfce4-terminal-0.8.10.tar.bz2
   xfce4-dev-tools-4.16.0.tar.bz2.done  xfce4-panel-4.16.0.tar.bz2           xfce4-settings-4.16.0.tar.bz2        xfce4-terminal-0.8.10.tar.bz2.done
   xfce4-notifyd-0.6.2.tar.bz2          xfce4-session-4.16.0.tar.bz2         xfce4-settings-4.16.0.tar.bz2.done
   ```

3. 添加 xxx.done 文件

   可以看到下载完成后，都会有一个 `.done` 文件表明下载成功。

   ```bash
   touch xfce4-panel-4.16.0.tar.bz2.done
   
   ll xfce4-panel-4.16.0.tar.bz2*
   ./downloads$ ll xfce4-panel-4.16.0.tar.bz2*
   -rw-r--r-- 1 koumei.lhm users 1382354 Feb  1 22:19 xfce4-panel-4.16.0.tar.bz2
   -rw-r--r-- 1 koumei.lhm users       0 Feb  1 22:21 xfce4-panel-4.16.0.tar.bz2.done
   ```

4. 验证

   至此下载就完成了，可以执行 `bitbake xfce4-panel -cdo_fetch` 查看是否下载成功

   ```bash
   ~/git_repo/yocto-work/riscv_yocto/thead-build/ice-base-xfce$ bitbake xfce4-panel -cdo_fetch
   Loading cache: 100% |##################################################################################################################################################################| Time: 0:00:00
   Loaded 3754 entries from dependency cache.
   Parsing recipes: 100% |################################################################################################################################################################| Time: 0:00:00
   Parsing of 2530 .bb files complete (2529 cached, 1 parsed). 3755 targets, 207 skipped, 0 masked, 0 errors.
   NOTE: Resolving any missing task queue dependencies
   
   Build Configuration:
   BB_VERSION           = "1.48.0"
   BUILD_SYS            = "x86_64-linux"
   NATIVELSBSTRING      = "universal"
   TARGET_SYS           = "riscv64-oe-linux"
   MACHINE              = "ice"
   DISTRO               = "nodistro"
   DISTRO_VERSION       = "nodistro.0"
   TUNE_FEATURES        = "riscv64"
   EXTERNAL_TOOLCHAIN   = "/home/public/host"
   EXTERNAL_TARGET_SYS  = "riscv64-linux"
   GCC_VERSION          = "8.1.0"
   meta                 = "HEAD:499b74d0934f5f088facfe04477a14a22b52e2d5"
   meta-oe
   meta-python
   meta-multimedia
   meta-networking      = "HEAD:4453ac5cc0d8412e8f7ece5f79987809a8c4ddf3"
   meta-external-toolchain = "HEAD:f9d1b7a1ec75241c0d61bd9c29a28048e6376ef8"
   meta-riscv           = "HEAD:58bcdf7f8e3f116d0fbd406cde991fe09ffac71a"
   meta-gnome
   meta-xfce
   meta-filesystems
   meta-webserver       = "HEAD:4453ac5cc0d8412e8f7ece5f79987809a8c4ddf3"
   
   Initialising tasks: 100% |#############################################################################################################################################################| Time: 0:00:00
   Sstate summary: Wanted 0 Found 0 Missed 0 Current 0 (0% match, 0% complete)
   NOTE: No setscene tasks
   NOTE: Executing Tasks
   NOTE: Tasks Summary: Attempted 1 tasks of which 0 didn't need to be rerun and all succeeded.
   NOTE: Writing buildhistory
   NOTE: Writing buildhistory took: 0 seconds
   ```



## 手动下载 git 仓库

![download_error_git](assets/download_error_git.png)

> 此图片为 git 仓库下载失败

下载错误的包为 `asciidoc-native` ，后面为版本号。

1. 查找下载地址

   ```bash
   ~/git_repo/yocto-work/riscv_yocto/thead-build/ice-base-xfce$ bitbake -e asciidoc-native | grep ^SRC_URI
   SRC_URI="git://github.com/asciidoc/asciidoc-py3;protocol=https            file://auto-catalogs.patch"
   ```

   地址为 `git://xxxx;protocol=https` 就是 git 仓库，下载地址为 `https://github.com/asciidoc/asciidoc-py3`  ，有的地址后面还会指定 `branch` ，下载的时候也同样要加上 `-b BRANCH`。  

2. 下载仓库

   ```bash
   ~/git_repo/yocto-work/riscv_yocto/thead-build/ice-base-xfce$ cd ../downloads/git2/
   
   git clone --bare https://github.com/asciidoc/asciidoc-py3
   # 如果指定 BRANCH
   # git clone --bare https://github.com/asciidoc/asciidoc-py3 -b BRANCH
   
   # 下载下来的仓库目录为 asciidoc-py3.git
   # 根据仓库地址更改仓库目录，把全路径中的 "/" 替换为 "."
   mv asciidoc-py3.git github.com.asciidoc.asciidoc-py3
   ```

3. 添加 xxx.done 文件

   每个仓库目录都会有一个 `.done` 文件表明下载成功。

   ```bash
   touch github.com.asciidoc.asciidoc-py3.done
   ```

4. 验证

   至此下载就完成了，可以执行 `bitbake asciidoc-native -cdo_fetch` 查看是否下载成功。

   ```bash
   ~/git_repo/yocto-work/riscv_yocto/thead-build/ice-base-xfce$ bitbake asciidoc-native -cdo_fetch
   Loading cache: 100% |##################################################################################################################################################################| Time: 0:00:00
   Loaded 3754 entries from dependency cache.
   Parsing recipes: 100% |################################################################################################################################################################| Time: 0:00:00
   Parsing of 2530 .bb files complete (2529 cached, 1 parsed). 3755 targets, 207 skipped, 0 masked, 0 errors.
   NOTE: Resolving any missing task queue dependencies
   
   Build Configuration:
   BB_VERSION           = "1.48.0"
   BUILD_SYS            = "x86_64-linux"
   NATIVELSBSTRING      = "universal"
   TARGET_SYS           = "riscv64-oe-linux"
   MACHINE              = "ice"
   DISTRO               = "nodistro"
   DISTRO_VERSION       = "nodistro.0"
   TUNE_FEATURES        = "riscv64"
   EXTERNAL_TOOLCHAIN   = "/home/public/host"
   EXTERNAL_TARGET_SYS  = "riscv64-linux"
   GCC_VERSION          = "8.1.0"
   meta                 = "HEAD:499b74d0934f5f088facfe04477a14a22b52e2d5"
   meta-oe
   meta-python
   meta-multimedia
   meta-networking      = "HEAD:4453ac5cc0d8412e8f7ece5f79987809a8c4ddf3"
   meta-external-toolchain = "HEAD:f9d1b7a1ec75241c0d61bd9c29a28048e6376ef8"
   meta-riscv           = "HEAD:58bcdf7f8e3f116d0fbd406cde991fe09ffac71a"
   meta-gnome
   meta-xfce
   meta-filesystems
   meta-webserver       = "HEAD:4453ac5cc0d8412e8f7ece5f79987809a8c4ddf3"
   
   Initialising tasks: 100% |#############################################################################################################################################################| Time: 0:00:00
   Sstate summary: Wanted 0 Found 0 Missed 0 Current 0 (0% match, 0% complete)
   NOTE: No setscene tasks
   NOTE: Executing Tasks
   NOTE: Tasks Summary: Attempted 1 tasks of which 0 didn't need to be rerun and all succeeded.
   NOTE: Writing buildhistory
   NOTE: Writing buildhistory took: 0 seconds
   ```

   

