Skip to content

Commit

Permalink
Implement OTA list image generator
Browse files Browse the repository at this point in the history
Add python script to generate OTA list image
Change working directory and add APP_DIRECTORY path
Add generating OTA list image step for upgrade image build
Set vendor id and product id from mbed_app.json level
  • Loading branch information
ATmobica committed Feb 8, 2022
1 parent db49767 commit c181f6a
Show file tree
Hide file tree
Showing 10 changed files with 143 additions and 12 deletions.
6 changes: 6 additions & 0 deletions examples/all-clusters-app/mbed/mbed_app.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@
},
"version-number-str": {
"value": "\"0.1.0\""
},
"vendor-id": {
"value": "9050"
},
"product-id": {
"value": "3"
}
}
}
6 changes: 6 additions & 0 deletions examples/lighting-app/mbed/mbed_app.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@
},
"version-number-str": {
"value": "\"0.1.0\""
},
"vendor-id": {
"value": "9050"
},
"product-id": {
"value": "1"
}
}
}
6 changes: 6 additions & 0 deletions examples/lock-app/mbed/mbed_app.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@
},
"version-number-str": {
"value": "\"0.1.0\""
},
"vendor-id": {
"value": "9050"
},
"product-id": {
"value": "0"
}
}
}
6 changes: 6 additions & 0 deletions examples/ota-requestor-app/mbed/mbed_app.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@
"help": "Name used for BLE advertising.",
"value": "\"MBED-ota-req\""
},
"vendor-id": {
"value": "9050"
},
"product-id": {
"value": "5"
},
"version-number": {
"value": "0"
},
Expand Down
6 changes: 6 additions & 0 deletions examples/pigweed-app/mbed/mbed_app.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@
},
"version-number-str": {
"value": "\"0.1.0\""
},
"vendor-id": {
"value": "9050"
},
"product-id": {
"value": "2"
}
}
}
78 changes: 78 additions & 0 deletions examples/platform/mbed/ota/generate_ota_list_image.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#!/usr/bin/env -S python3

#
# Copyright (c) 2022 Project CHIP Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

##
# @file
# Generates OTA image list file based on Mbed project configuration file (mbed_app.json)
# OTA image list JSON file (see /examples/ota-provider-app/linux/README.md)
#
# Usage: generate_ota_list_image.py <mbed_config_json_file_path> <image_path>

import json
import os
import string
import sys

FILE_NAME = "ota-image-list.json"

FILE_DATA_TEMPLATE = """{
"deviceSoftwareVersionModel": [
{
"vendorId": 0,
"productId": 0,
"softwareVersion": 0,
"softwareVersionString": "",
"cDVersionNumber": 0,
"softwareVersionValid": true,
"minApplicableSoftwareVersion": 0,
"maxApplicableSoftwareVersion": 1000,
"otaURL": ""
}
]
}
"""

def CreateOtaListFile(config, imagePath):
data = json.loads(FILE_DATA_TEMPLATE)

data["deviceSoftwareVersionModel"][0]["vendorId"] = int(config["config"]["vendor-id"]["value"])
data["deviceSoftwareVersionModel"][0]["productId"] = int(config["config"]["product-id"]["value"])
data["deviceSoftwareVersionModel"][0]["softwareVersion"] = int(config["config"]["version-number"]["value"])
data["deviceSoftwareVersionModel"][0]["softwareVersionString"] = config["config"]["version-number-str"]["value"].strip('"\\')
data["deviceSoftwareVersionModel"][0]["otaURL"] = str(imagePath)

output_path = os.path.join(os.path.dirname(imagePath), FILE_NAME)

with open(output_path, 'w') as jsonFile:
json.dump(data, jsonFile)

def main():
if len(sys.argv) != 3:
print('Usage: ' + sys.argv[0] + ' <mbed_config_json_file_path> <image_path>')
exit(1)

config_json_path = sys.argv[1]
image_path = sys.argv[2]
with open(config_json_path, 'r') as json_file:
config = json.loads(json_file.read())

CreateOtaListFile(config, image_path)


if __name__ == "__main__":
main()
6 changes: 6 additions & 0 deletions examples/shell/mbed/mbed_app.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@
},
"version-number-str": {
"value": "\"0.1.0\""
},
"vendor-id": {
"value": "9050"
},
"product-id": {
"value": "4"
}
}
}
19 changes: 11 additions & 8 deletions scripts/examples/mbed_example.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

cd "$(dirname "$0")"/../..
CHIP_ROOT=$PWD
cd "$CHIP_ROOT"/examples

SUPPORTED_TOOLCHAIN=(GCC_ARM ARM)
SUPPORTED_TARGET_BOARD=(CY8CPROTO_062_4343W)
Expand Down Expand Up @@ -110,8 +109,11 @@ set -e # Exit immediately if a command exits with a non-zero status.
# Activate Matter environment
source "$CHIP_ROOT"/scripts/activate.sh

# Application directory setup
APP_DIRECTORY="$CHIP_ROOT"/examples/"$APP"/mbed

# Build directory setup
BUILD_DIRECTORY="$APP"/mbed/build-"$TARGET_BOARD"/"$PROFILE"/
BUILD_DIRECTORY="$APP_DIRECTORY"/build-"$TARGET_BOARD"/"$PROFILE"

# Set bootloader root directory
BOOTLOADER_ROOT_DIRECTORY="$CHIP_ROOT"/examples/platform/mbed/bootloader
Expand Down Expand Up @@ -179,23 +181,23 @@ if [[ "$COMMAND" == *"build"* ]]; then
MBED_OS_POSIX_SOCKET_PATH="$CHIP_ROOT"/third_party/mbed-os-posix-socket/repo

if [[ "$TYPE" == "boot" || "$TYPE" == "upgrade" ]]; then
ln -sfTr "$MBED_MCU_BOOT_PATH"/boot/mbed "$APP"/mbed/mcuboot
ln -sfTr "$MBED_MCU_BOOT_PATH"/boot/mbed "$APP_DIRECTORY"/mcuboot
fi

# Generate config file for selected target, toolchain and hardware
mbed-tools configure -t "$TOOLCHAIN" -m "$TARGET_BOARD" -p "$APP"/mbed/ -o "$BUILD_DIRECTORY" --mbed-os-path "$MBED_OS_PATH"
mbed-tools configure -t "$TOOLCHAIN" -m "$TARGET_BOARD" -p "$APP_DIRECTORY" -o "$BUILD_DIRECTORY" --mbed-os-path "$MBED_OS_PATH"

# Remove old artifacts to force linking
rm -rf "$BUILD_DIRECTORY/chip-"*

# Build application
cmake -S "$APP/mbed" -B "$BUILD_DIRECTORY" -GNinja -DCMAKE_BUILD_TYPE="$PROFILE" -DMBED_OS_PATH="$MBED_OS_PATH" -DMBED_OS_POSIX_SOCKET_PATH="$MBED_OS_POSIX_SOCKET_PATH" -DMBED_MCU_BOOT_PATH="$MBED_MCU_BOOT_PATH" -DMBED_APP_TYPE="$TYPE"
cmake -S "$APP_DIRECTORY" -B "$BUILD_DIRECTORY" -GNinja -DCMAKE_BUILD_TYPE="$PROFILE" -DMBED_OS_PATH="$MBED_OS_PATH" -DMBED_OS_POSIX_SOCKET_PATH="$MBED_OS_POSIX_SOCKET_PATH" -DMBED_MCU_BOOT_PATH="$MBED_MCU_BOOT_PATH" -DMBED_APP_TYPE="$TYPE"
cmake --build "$BUILD_DIRECTORY"

if [[ "$TYPE" == "boot" || "$TYPE" == "upgrade" ]]; then
APP_VERSION=$(jq '.config."version-number-str".value' "$APP"/mbed/mbed_app.json | tr -d '\\"')
HEADER_SIZE=$(jq '.target_overrides.'\""$TARGET_BOARD"\"'."mcuboot.header-size"' "$APP"/mbed/mbed_app.json | tr -d \")
SLOT_SIZE=$(jq '.target_overrides.'\""$TARGET_BOARD"\"'."mcuboot.slot-size"' "$APP"/mbed/mbed_app.json | tr -d \")
APP_VERSION=$(jq '.config."version-number-str".value' "$APP_DIRECTORY"/mbed_app.json | tr -d '\\"')
HEADER_SIZE=$(jq '.target_overrides.'\""$TARGET_BOARD"\"'."mcuboot.header-size"' "$APP_DIRECTORY"/mbed_app.json | tr -d \")
SLOT_SIZE=$(jq '.target_overrides.'\""$TARGET_BOARD"\"'."mcuboot.slot-size"' "$APP_DIRECTORY"/mbed_app.json | tr -d \")

if [[ "$TYPE" == "boot" ]]; then
# Signed the primary application
Expand All @@ -211,6 +213,7 @@ if [[ "$COMMAND" == *"build"* ]]; then
"$BUILD_DIRECTORY"/chip-mbed-"$APP"-example.hex "$BUILD_DIRECTORY"/chip-mbed-"$APP"-example-signed.hex
# Convert hex image to raw binary file
arm-none-eabi-objcopy -I ihex -O binary "$BUILD_DIRECTORY"/chip-mbed-"$APP"-example-signed.hex "$BUILD_DIRECTORY"/chip-mbed-"$APP"-example.bin
python "$CHIP_ROOT"/examples/platform/mbed/ota/generate_ota_list_image.py "$APP_DIRECTORY"/mbed_app.json "$BUILD_DIRECTORY"/chip-mbed-"$APP"-example.bin
fi
fi
fi
Expand Down
16 changes: 12 additions & 4 deletions src/platform/mbed/CHIPDevicePlatformConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,23 @@

#ifndef CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE
#define CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE 1
#endif
#endif // CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE

#ifndef CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION
#ifndef CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION_STRING
#define CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION_STRING MBED_CONF_APP_VERSION_NUMBER_STR
#endif
#endif // CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION_STRING

#ifndef CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION
#define CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION MBED_CONF_APP_VERSION_NUMBER
#endif
#endif // CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION

#ifndef CHIP_DEVICE_CONFIG_DEVICE_VENDOR_ID
#define CHIP_DEVICE_CONFIG_DEVICE_VENDOR_ID MBED_CONF_APP_VENDOR_ID
#endif // CHIP_DEVICE_CONFIG_DEVICE_VENDOR_ID

#ifndef CHIP_DEVICE_CONFIG_DEVICE_PRODUCT_ID
#define CHIP_DEVICE_CONFIG_DEVICE_PRODUCT_ID MBED_CONF_APP_PRODUCT_ID
#endif // CHIP_DEVICE_CONFIG_DEVICE_PRODUCT_ID

// ========== Platform-specific Configuration Overrides =========

Expand Down
6 changes: 6 additions & 0 deletions src/test_driver/mbed/unit_tests/mbed_app.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@
},
"version-number-str": {
"value": "\"0.1.0\""
},
"vendor-id": {
"value": "9050"
},
"product-id": {
"value": "100"
}
}
}

0 comments on commit c181f6a

Please sign in to comment.