离线版nrfutil工具安装方法

简介

nrfutil是Nordic提供的命令行工具集。支持以下功能:

  • 基于Jlink的固件烧录、读取、flash擦除、recover
  • 基于MCUBOOT的固件升级(DFU)
  • 基于nRF5 bootloader的固件升级(DFU)
  • 其他功能(Trace,工具更新...)

它采用包管理器的形式,可以在线检查各个工具的最新版本,并更新。
下载地址:https://www.nordicsemi.com/Products/Development-tools/nrf-util

地址里除了nrfutil本身的下载链接,还有一些依赖软件的链接,以及软件的说明。一定要仔细阅读。
下载完毕后可以添加到PATH环境变量,方便使用。

首次运行

下载好nrfutil的可执行文件,以及它的各种依赖软件后,就可以运行(为了方便使用,记得添加到PATH环境变量)。
如果你的电脑可以魔法上网,那么可以直接运行成功。
首次运行时,会连接到raw.githubusercontent.com去获取最新的工具软件列表,然后下载对应操作系统的工具。但我们知道,这个网站在国内是裸连不了的,运行会报以下错误:

nrfutil.exe
Error: Failed to bootstrap core functionality before executing command.

HTTP request to default bootstrap resource

  https://raw.githubusercontent.com/NordicSemiconductor/nrfutil-package-index/master/bootstrap.json

failed.

Please check that your internet connection is functioning. If you use a proxy, please try the --detect-proxy flag or
manually set the appropriate HTTP_PROXY-style environment variable(s).

To use a custom bootstrap config, set NRFUTIL_BOOTSTRAP_CONFIG_URL. To bootstrap directly from a nrfutil-core package
tarball, set NRFUTIL_BOOTSTRAP_TARBALL_PATH.

通过阅读输出日志,我们可以知道。如果我们想设置自己的工具软件列表,需要设置NRFUTIL_BOOTSTRAP_CONFIG_URL环境变量。我们先用一台可以魔法上网的电脑访问一下日志中提到的无法访问的网址,可以看到这个Json文件的内容:

{
    "nrfutil_core_tarball_urls": {
        "aarch64-apple-darwin": "https://developer.nordicsemi.com/.pc-tools/nrfutil/nrfutil-aarch64-apple-darwin-7.6.0.tar.gz",
        "x86_64-apple-darwin": "https://developer.nordicsemi.com/.pc-tools/nrfutil/nrfutil-x86_64-apple-darwin-7.6.0.tar.gz",
        "x86_64-pc-windows-msvc": "https://developer.nordicsemi.com/.pc-tools/nrfutil/nrfutil-x86_64-pc-windows-msvc-7.6.0.tar.gz",
        "x86_64-unknown-linux-gnu": "https://developer.nordicsemi.com/.pc-tools/nrfutil/nrfutil-x86_64-unknown-linux-gnu-7.6.0.tar.gz"
    }
}

原来是记录了各个操作系统平台下,最新版的工具压缩包(tarball)下载地址。那么这里我们可以根据链接,下载自己操作系统对应的压缩包,存放到电脑本地。
然后,根据日志的提示,我们直接设置NRFUTIL_BOOTSTRAP_TARBALL_PATH临时环境变量,将其设置为压缩包在本地的绝对地址

PS C:\software> $env:NRFUTIL_BOOTSTRAP_TARBALL_PATH="C:\Software\nrfutil-x86_64-pc-windows-msvc-7.6.0.tar.gz"

PS C:\software> .\nrfutil.exe
nrfutil

Usage:
    nrfutil [+MODIFIER] [OPTIONS] [SUBCOMMAND]

Options:
      --log-level <LOG_LEVEL>    Set the maximum log level [env: NRFUTIL_LOG=] [possible values: off, error, warn, info,
                                 debug, trace]
      --log-output <LOG_OUTPUT>  Set log output type: --log-output=stdout --log-output=file ... [possible values: file,
                                 stdout]
      --json                     Print output in a JSON Lines format
      --json-pretty              Print output as formatted JSON
      --skip-overhead            Skip all message overhead when in JSON output mode, outputting only the data part of
                                 "info" messages and ignoring the rest
      --changelog                Print the latest changelog entry
      --changelog-full           Print the full changelog
  -V, --version
      --help-extended            Show comprehensive documentation
      --license                  Show license information for in-built dependencies
      --detect-proxy             Invoke libproxy's 'proxy' utility program to retrieve proxy server info and use it
  -h, --help                     Print help (see more with '--help')


Built-in nrfutil commands (see installed commands with `list`):
  help             Show comprehensive documentation
  install          Download and install nrfutil commands
  upgrade          Upgrade nrfutil commands to the latest version
  uninstall        Uninstall nrfutil commands [aliases: remove]
  prepare-offline  Prepare local package and resource repositories for offline installs of nrfutil commands
  search           Search for installable nrfutil commands in the package index
  list             List installed nrfutil commands
  self-upgrade     Upgrades the nrfutil core functionality to the latest version

然后就可以看到nrfutil可以正常运行了。

注意:

  • Windows平台请使用powershell,而非cmd。其他平台请使用对应的设置临时环境变量的方法。
  • 只有第一次运行时才需要设置这个环境变量。第一次运行成功后,会在${HOME}/.nrfutil隐藏文件夹内保存这些信息:
    image
    后续都可以直接执行nrfutil,不需要网络和这个临时环境变量。

安装子命令

查看有哪些子命令可安装(需网络)

PS C:\> nrfutil search
Command           Installed Latest Status
ble-sniffer       0.12.0    0.12.0 Installed
completion        1.4.0     1.4.0  Installed
device            2.1.1     2.1.1  Installed
npm               0.3.0     0.3.0  Installed
nrf5sdk-tools     1.0.1     1.0.1  Installed
toolchain-manager 0.14.1    0.14.1 Installed
trace             2.1.0     2.1.0  Installed

安装想要的子命令(需网络)

nrfutil install nrf5sdk-tools

工具包离线导出与导入

在首次安装之后,我们可以用能连网的电脑下载、更新一些新的工具。这些工具就存放在用户目录的.nrfutil中。如果想拷贝到不能连网的电脑中,就可以导出到U盘,再从U盘导入到电脑里。
导出到U盘:

nrfutil prepare-offline E:/nrfutils

从U盘安装想要的子命令

nrfutil install nrf5sdk-tools --from-offline E:/nrfutils

具体请参考:https://docs.nordicsemi.com/bundle/nrfutil/page/guides/getting_started.html#installing-nrf-util-when-offline

其他推荐阅读

nrfutil博客:https://devzone.nordicsemi.com/nordic/nordic-blog/b/blog/posts/nrf-util-unified-command-line-utility
nrfutil文档:https://docs.nordicsemi.com/bundle/nrfutil/page/README.html

posted @ 2023-11-09 11:53  jayant97  阅读(677)  评论(0编辑  收藏  举报