

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 設定建置、刷新和測試設定
<a name="cfg-dt-ud"></a>

若要讓 IDT for FreeRTOS 自動在您的主機板上建置和刷新測試，您必須設定 IDT 來執行硬體的建置和刷新命令。您可以在位於 `config` 資料夾的 `userdata.json` 範本檔案中配置建置和刷新命令設定。

# 配置設定以測試裝置
<a name="config-settings-device"></a>

您可以在 `configs/userdata.json` 檔案中進行建置、刷新和測試設定。我們透過在 中載入用戶端和伺服器憑證和金鑰來支援 Echo Server 組態`customPath`。如需詳細資訊，請參閱 *FreeRTOS 移植指南*中的[設定 echo 伺服器](https://docs.aws.amazon.com/freertos/latest/portingguide/afr-echo-server.html)。下列 JSON 範例示範如何設定 IDT for FreeRTOS 來測試多個裝置：

```
{
    "sourcePath": "/absolute-path-to/freertos",
    "vendorPath": "{{testData.sourcePath}}/vendors/vendor-name/boards/board-name",
    // ***********The sdkConfiguration block below is needed if you are not using the default, unmodified FreeRTOS repo. 
    // In other words, if you are using the default, unmodified FreeRTOS repo then remove this block***************
    "sdkConfiguration": {
        "name": "sdk-name",
        "version": "sdk-version",
        "path": "/absolute-path-to/sdk"
    },
    "buildTool": {
        "name": "your-build-tool-name",
        "version": "your-build-tool-version",
        "command": [
            "{{config.idtRootPath}}/relative-path-to/build-parallel.sh {{testData.sourcePath}} {{enableTests}}"
        ]
    },
    "flashTool": {
        "name": "your-flash-tool-name",
        "version": "your-flash-tool-version",
        "command": [
            "/{{config.idtRootPath}}/relative-path-to/flash-parallel.sh {{testData.sourcePath}} {{device.connectivity.serialPort}} {{buildImageName}}"
        ],
        "buildImageInfo" : {
            "testsImageName": "tests-image-name",
            "demosImageName": "demos-image-name"
        }
    },
    "testStartDelayms": 0,
    "clientWifiConfig": {
        "wifiSSID": "ssid",
        "wifiPassword": "password",
        "wifiSecurityType": "eWiFiSecurityOpen | eWiFiSecurityWEP | eWiFiSecurityWPA | eWiFiSecurityWPA2 | eWiFiSecurityWPA3"
    },
    "testWifiConfig": {
        "wifiSSID": "ssid",
        "wifiPassword": "password",
        "wifiSecurityType": "eWiFiSecurityOpen | eWiFiSecurityWEP | eWiFiSecurityWPA | eWiFiSecurityWPA2 | eWiFiSecurityWPA3"
    },
    //**********
    //This section is used to start echo server based on server certificate generation method,
    //When certificateGenerationMethod is set as Automatic specify the eccCurveFormat to generate certifcate and key based on curve format,
    //When certificateGenerationMethod is set as Custom specify the certificatePath and PrivateKeyPath to be used to start echo server
    //**********
    "echoServerCertificateConfiguration": {
      "certificateGenerationMethod": "Automatic | Custom",
      "customPath": {
          "clientCertificatePath":"/path/to/clientCertificate",
          "clientPrivateKeyPath": "/path/to/clientPrivateKey",
          "serverCertificatePath":"/path/to/serverCertificate",
          "serverPrivateKeyPath": "/path/to/serverPrivateKey"
      },
    "eccCurveFormat": "P224 | P256 | P384 | P521"
    },
    "echoServerConfiguration": {
        "securePortForSecureSocket": 33333, // Secure tcp port used by SecureSocket test. Default value is 33333. Ensure that the port configured isn't blocked by the firewall or your corporate network
        "insecurePortForSecureSocket": 33334, // Insecure tcp port used by SecureSocket test. Default value is 33334. Ensure that the port configured isn't blocked by the firewall or your corporate network
        "insecurePortForWiFi": 33335 // Insecure tcp port used by Wi-Fi test. Default value is 33335. Ensure that the port configured isn't blocked by the firewall or your corporate network
    },
    "otaConfiguration": {
        "otaFirmwareFilePath": "{{testData.sourcePath}}/relative-path-to/ota-image-generated-in-build-process",
        "deviceFirmwareFileName": "ota-image-name-on-device",
        "otaDemoConfigFilePath": "{{testData.sourcePath}}/relative-path-to/ota-demo-config-header-file",
        "codeSigningConfiguration": {
            "signingMethod": "AWS | Custom",
            "signerHashingAlgorithm": "SHA1 | SHA256",
            "signerSigningAlgorithm": "RSA | ECDSA",
            "signerCertificate": "arn:partition:service:region:account-id:resource:qualifier | /absolute-path-to/signer-certificate-file",
            "signerCertificateFileName": "signerCertificate-file-name",
            "compileSignerCertificate": boolean,
            // ***********Use signerPlatform if you choose aws for signingMethod***************
            "signerPlatform": "AmazonFreeRTOS-Default | AmazonFreeRTOS-TI-CC3220SF",
            "untrustedSignerCertificate": "arn:partition:service:region:account-id:resourcetype:resource:qualifier",
            // ***********Use signCommand if you choose custom for signingMethod***************
            "signCommand": [
                "/absolute-path-to/sign.sh {{inputImageFilePath}} {{outputSignatureFilePath}}"
            ]
        }
    },
    // ***********Remove the section below if you're not configuring CMake***************
    "cmakeConfiguration": {
        "boardName": "board-name",
        "vendorName": "vendor-name",
        "compilerName": "compiler-name",
        "frToolchainPath": "/path/to/freertos/toolchain",
        "cmakeToolchainPath": "/path/to/cmake/toolchain"
    },
    "freertosFileConfiguration": {
        "required": [
            {
                "configName": "pkcs11Config",
                "filePath": "{{testData.sourcePath}}/vendors/vendor-name/boards/board-name/aws_tests/config_files/core_pkcs11_config.h"
            },
            {
                "configName": "pkcs11TestConfig",
                "filePath": "{{testData.sourcePath}}/vendors/vendor-name/boards/board-name/aws_tests/config_files/iot_test_pkcs11_config.h"
            }
        ],
        "optional": [
            {
                "configName": "otaAgentTestsConfig",
                "filePath": "{{testData.sourcePath}}/vendors/vendor-name/boards/board-name/aws_tests/config_files/ota_config.h"
            },
            {
                "configName": "otaAgentDemosConfig",
                "filePath": "{{testData.sourcePath}}/vendors/vendor-name/boards/board-name/aws_demos/config_files/ota_config.h"
            },
            {
                "configName": "otaDemosConfig",
                "filePath": "{{testData.sourcePath}}/vendors/vendor-name/boards/board-name/aws_demos/config_files/ota_demo_config.h"
            }
        ]
    }
}
```

以下列出 `userdata.json` 中使用的屬性：

**`sourcePath`**  
移植的 FreeRTOS 原始程式碼根目錄的路徑。對於使用 SDK 進行平行測試，`sourcePath`可以使用`{{userData.sdkConfiguration.path}}`預留位置設定 。例如：  

```
{ "sourcePath":"{{userData.sdkConfiguration.path}}/freertos" }
```

**`vendorPath`**  
廠商特定 FreeRTOS 程式碼的路徑。針對序列測試，`vendorPath` 可設定為絕對路徑。例如：  

```
{ "vendorPath":"C:/path-to-freertos/vendors/espressif/boards/esp32" }
```
針對平行測試，可使用 `{{testData.sourcePath}}` 預留位置設定 `vendorPath`。例如：  

```
{ "vendorPath":"{{testData.sourcePath}}/vendors/espressif/boards/esp32" }
```
只有在在沒有 SDK 的情況下執行時，才需要 `vendorPath`變數，否則可以將其移除。  
在沒有 SDK 的情況下平行執行測試時，必須在 `vendorPath`、`buildTool`、 `flashTool`欄位中使用`{{testData.sourcePath}}`預留位置。使用單一裝置執行測試時，必須在 `vendorPath`、`buildTool`、`flashTool` 欄位中使用絕對路徑。使用 SDK 執行 時，必須在 `sourcePath`、 `buildTool`和 `flashTool`命令中使用`{{sdkPath}}`預留位置。

**`sdkConfiguration`**  
如果您正在限定 FreeRTOS，且對檔案和資料夾結構所做的任何修改超過移植所需的修改，則需要在此區塊中設定 SDK 資訊。如果您不符合 SDK 內移植 FreeRTOS 的資格，則應完全省略此區塊。    
**`sdkConfiguration.name`**  
您搭配 FreeRTOS 使用的 SDK 名稱。如果您不是使用 SDK，則應該省略整個`sdkConfiguration`區塊。  
**`sdkConfiguration.version`**  
您搭配 FreeRTOS 使用的 SDK 版本。如果您不是使用 SDK，則應該省略整個`sdkConfiguration`區塊。  
**`sdkConfiguration.path`**  
包含 FreeRTOS 程式碼之 SDK 目錄的絕對路徑。如果您不是使用 SDK，則應該省略整個`sdkConfiguration`區塊。

**`buildTool`**  
建置指令碼的完整路徑 (.bat 或 .sh)，其中包含用來建立來源碼的命令。組建命令中對原始程式碼路徑的所有參考都必須取代為 AWS IoT Device Tester 變數，`{{testdata.sourcePath}}`而 SDK 路徑的參考應該取代為 `{{sdkPath}}`。使用`{{config.idtRootPath}}`預留位置來參考絕對或相對 IDT 路徑。

**`testStartDelayms`**  
指定 FreeRTOS 測試執行器在開始執行測試之前等待多少毫秒。如果待測裝置在 IDT 因網路或其他延遲而有機會連線和開始記錄之前，就開始輸出重要的測試資訊，這會很有用。允許的值上限為 30000 毫秒 (30 秒）。此值僅適用於 FreeRTOS 測試群組，不適用於未使用 FreeRTOS 測試執行器的其他測試群組，例如 OTA 測試。

**`flashTool`**  
包含用於裝置的刷入命令之刷入指令碼 (.sh 或 .bat) 的完整路徑。所有對 flash 命令中原始碼路徑的參考都必須取代為 IDT for FreeRTOS 變數`{{testdata.sourcePath}}`，而所有對 SDK 路徑的參考都必須取代為 IDT for FreeRTOS 變數 `{{sdkPath}}`。使用`{{config.idtRootPath}}`預留位置來參考絕對或相對 IDT 路徑。    
**`buildImageInfo`**    
**`testsImageName`**  
從 `freertos-source/tests` 資料夾建置測試時，建置命令產生的檔案名稱。  
**`demosImageName`**  
從 `freertos-source/demos` 資料夾建置測試時，建置命令產生的檔案名稱。

**`clientWifiConfig`**  
用戶端 Wi-Fi 組態。Wi-Fi 程式庫測試需要 MCU 主機板，以連接到兩個存取點。(兩個存取點可以是相同的。) 此屬性會設定第一個存取點的 Wi-Fi 設定。某些 Wi-Fi 測試案例希望存取點有一些安全保障，因此並未開放使用。請確定兩個存取點與執行 IDT 的主機電腦位於相同的子網路上。    
**`wifi_ssid`**  
Wi-Fi SSID。  
**`wifi_password`**  
Wi-Fi 密碼。  
**`wifiSecurityType`**  
使用的 Wi-Fi 安全性類型。其中一個值：  
+ `eWiFiSecurityOpen`
+ `eWiFiSecurityWEP`
+ `eWiFiSecurityWPA`
+ `eWiFiSecurityWPA2`
+ `eWiFiSecurityWPA3`
即使主機板不支援 Wi-Fi，您仍需在 `device.json` 檔案中加入 `clientWifiConfig` 區段，但可以省略這些屬性的值。

**`testWifiConfig`**  
測試 Wi-Fi 組態。Wi-Fi 程式庫測試需要 MCU 主機板，以連接到兩個存取點。(兩個存取點可以是相同的。) 此屬性會設定第二個存取點的 Wi-Fi 設定。某些 Wi-Fi 測試案例希望存取點有一些安全保障，因此並未開放使用。請確定兩個存取點與執行 IDT 的主機電腦位於相同的子網路上。    
**`wifiSSID`**  
Wi-Fi SSID。  
**`wifiPassword`**  
Wi-Fi 密碼。  
**`wifiSecurityType`**  
使用的 Wi-Fi 安全性類型。其中一個值：  
+ `eWiFiSecurityOpen`
+ `eWiFiSecurityWEP`
+ `eWiFiSecurityWPA`
+ `eWiFiSecurityWPA2`
+ `eWiFiSecurityWPA3`
即使主機板不支援 Wi-Fi，您仍需在 `device.json` 檔案中加入 `testWifiConfig` 區段，但可以省略這些屬性的值。

**`echoServerCertificateConfiguration`**  
用於安全通訊端測試的可設定 echo 伺服器憑證產生預留位置。此欄位為必填。    
**`certificateGenerationMethod`**  
指定是自動產生還是手動提供伺服器憑證。  
**`customPath`**  
如果 `certificateGenerationMethod`是「自訂」，`privateKeyPath`則需要 `certificatePath`和 。    
**`certificatePath`**  
指定伺服器憑證的 filepath。  
**`privateKeyPath`**  
指定私有金鑰的檔案路徑。  
**`eccCurveFormat`**  
指定主機板支援的曲線格式。在 中`PKCS11`將 設定為 "ecc" 時為必要`device.json`。有效值為「P224」、「P256」、「P384」或「P521」。

**`echoServerConfiguration`**  
適用於 WiFi 和安全通訊端測試的可設定 echo 伺服器連接埠。此欄位為選用欄位。    
**`securePortForSecureSocket`**  
用於設定具有 TLS 的 echo 伺服器連接埠，以供安全通訊端測試之用。預設值為 33333。請確定防火牆或您公司的網路未封鎖設定的連接埠。  
**`insecurePortForSecureSocket`**  
用於設定不具有 TLS 的 echo 伺服器連接埠，以供安全通訊端測試之用。測試中使用的預設值為 33334。請確定防火牆或您公司的網路未封鎖設定的連接埠。  
**`insecurePortForWiFi`**  
用於設定無 TLS 的 echo 伺服器連接埠，以供 WiFi 測試之用。測試中使用的預設值為 33335。請確定防火牆或您公司的網路未封鎖設定的連接埠。

**`otaConfiguration`**  
OTA 組態。[選用]    
**`otaFirmwareFilePath`**  
建置之後建立的 OTA 映像的完整路徑。例如 `{{testData.sourcePath}}/relative-path/to/ota/image/from/source/root`。  
**`deviceFirmwareFileName`**  
MCU 裝置上 OTA 韌體所在的完整檔案路徑。有些裝置不使用此欄位，但您仍必須提供值。  
**`otaDemoConfigFilePath`**  
`aws_demo_config.h` 的完整路徑，位於 `afr-source/vendors/vendor/boards/board/aws_demos/config_files/` 內。這些檔案包含在 FreeRTOS 提供的移植程式碼範本中。  
**`codeSigningConfiguration`**  
程式碼簽章組態。  
**`signingMethod`**  
程式碼簽章方法。可能的值為 `AWS` 或 `Custom`。  
對於北京和寧夏區域，請使用 `Custom`。這些區域不支援`AWS`程式碼簽署。  
**`signerHashingAlgorithm`**  
裝置上支援的雜湊演算法。可能的值為 `SHA1` 或 `SHA256`。  
**`signerSigningAlgorithm`**  
裝置上支援的簽署演算法。可能的值為 `RSA` 或 `ECDSA`。  
**`signerCertificate`**  
用於 OTA 的信任憑證。  
對於 AWS 程式碼簽署方法，請針對上傳至 的信任憑證使用 Amazon Resource Name (ARN) AWS Certificate Manager。  
對於自訂程式碼簽署方法，請使用簽署者憑證檔案的絕對路徑。  
如需建立信任憑證的詳細資訊，請參閱 [建立程式碼簽署憑證](ota-code-sign-cert.md)。  
**`signerCertificateFileName`**  
裝置上的程式碼簽署憑證檔案名稱。此值必須符合您在執行 `aws acm import-certificate`命令時提供的檔案名稱。  
如需詳細資訊，請參閱[建立程式碼簽署憑證](ota-code-sign-cert.md)。  
**`compileSignerCertificate`**  
`true` 如果未佈建或刷新程式碼簽署者簽章驗證憑證，則設定為 ，因此必須將其編譯至專案。 會 AWS IoT Device Tester 擷取信任的憑證並將其編譯至 `aws_codesigner_certifiate.h`。  
**`untrustedSignerCertificate`**  
某些 OTA 測試中使用的第二個憑證的 ARN 或檔案路徑，做為不受信任的憑證。如需建立憑證的詳細資訊，請參閱[建立程式碼簽署憑證](https://docs.aws.amazon.com/freertos/latest/userguide/ota-code-sign-cert.html)。  
**`signerPlatform`**  
 AWS Code Signer 在建立 OTA 更新任務時所使用的簽署和雜湊演算法。目前，此欄位的可能值為 `AmazonFreeRTOS-TI-CC3220SF` 和 `AmazonFreeRTOS-Default`。  
+ 如果是 `SHA1` 和 `RSA` 則選擇 `AmazonFreeRTOS-TI-CC3220SF`。
+ 如果是 `SHA256` 和 `ECDSA` 則選擇 `AmazonFreeRTOS-Default`。
如果您的組態需要 `SHA256` \$1 `RSA` 或 `SHA1` \$1 `ECDSA`，請聯絡我們以取得進一步支援。  
如果您針對 `signingMethod` 選擇 `Custom`，請設定 `signCommand`。  
**`signCommand`**  
用於執行自訂程式碼簽署的命令。您可以在 `/configs/script_templates` 目錄中找到範本。  
命令中需要 `{{inputImageFilePath}}` 和 `{{outputSignatureFilePath}}` 兩個預留位置。`{{inputImageFilePath}}` 是由 IDT 建立要簽署之影像的檔案路徑。`{{outputSignatureFilePath}}` 是將由指令碼產生簽章的檔案路徑。

**`cmakeConfiguration`**  
CMake 組態 [選用]  
您需要提供主機板名稱、廠商名稱，以及 `frToolchainPath` 或 `compilerName`，才能執行 CMake 測試案例。`cmakeToolchainPath` 如果您有 CMake 工具鏈的自訂路徑，您也可以提供 。  
**`boardName`**  
待測主機板的名稱。主機板名稱應與 `path/to/afr/source/code/vendors/vendor/boards/board` 下的資料夾名稱相同。  
**`vendorName`**  
待測主機板的廠商名稱。廠商應與 `path/to/afr/source/code/vendors/vendor` 下的資料夾名稱相同。  
**`compilerName`**  
編譯器的名稱。  
**`frToolchainPath`**  
編譯器工具鏈的完整路徑。  
**`cmakeToolchainPath` **  
CMake 工具鏈的完整路徑。此為選用欄位。

**`freertosFileConfiguration`**  
IDT 在執行測試之前修改的 FreeRTOS 檔案組態。    
**`required`**  
本節會指定您已移動其組態檔案的必要測試，例如 PKCS11、TLS 等。    
**`configName`**  
正在設定的測試名稱。  
**`filePath`**  
`freertos` 儲存庫中組態檔案的絕對路徑。使用 `{{testData.sourcePath}}`變數來定義路徑。  
**`optional`**  
本節指定您已移動其組態檔案的選用測試，例如 OTA、WiFi 等。    
**`configName`**  
正在設定的測試名稱。  
**`filePath`**  
`freertos` 儲存庫中組態檔案的絕對路徑。使用 `{{testData.sourcePath}}`變數來定義路徑。

**注意**  
您需要提供主機板名稱、廠商名稱，以及 `afrToolchainPath` 或 `compilerName`，才能執行 CMake 測試案例。如果您有 CMake 工具鏈的自訂路徑，也可以提供 `cmakeToolchainPath`。

# IDT for FreeRTOS 變數
<a name="dt-vars"></a>

建置程式碼和刷新裝置的命令可能需要連線或裝置的其他資訊，才能成功執行。 AWS IoT Device Tester 可讓您參考刷新中的裝置資訊，並使用 [JsonPath](https://goessner.net/articles/JsonPath/) 建置命令。透過使用簡單的 JsonPath 運算式，您可以擷取 `device.json` 檔案中指定的必要資訊。

## 路徑變數
<a name="path-variables-frq"></a>

IDT for FreeRTOS 定義下列路徑變數，可用於命令列和組態檔案：

**`{{testData.sourcePath}}`**  
展開至原始程式碼路徑。如果您使用此變數，則必須同時在快閃和建置命令中使用。

**`{{sdkPath}}`**  
在組建和快閃記憶體命令中使用`userData.sdkConfiguration.path`時， 會擴展至 中的值。

**`{{device.connectivity.serialPort}}`**  
展開至序列埠。

**`{{device.identifiers[?(@.name == 'serialNo')].value[0]}}`**  
展開至裝置的序號。

**`{{enableTests}}`**  
指出建置是否用於測試 (值 1) 或示範 (值 0) 的整數值。

**`{{buildImageName}}`**  
檔案名稱使用建置命令產生的映像建置。

**`{{otaCodeSignerPemFile}}`**  
OTA 程式碼簽署者的 PEM 檔案。

**`{{config.idtRootPath}}`**  
展開至 AWS IoT Device Tester 根路徑。當組建和快閃記憶體命令使用時，此變數會取代 IDT 的絕對路徑。