8.3. Package generator
This section describes the create_package.py
script used to generate test packages for
LwM2M objects implemented in the Anjay demo. These packages simulate firmware and software
updates with configurable behaviors and error conditions.
8.3.1. Overview
The Anjay demo implements several LwM2M objects to facilitate firmware and software management. These objects include:
object 5 — Firmware Update
object 9 — Software Management
object 33629 — Advanced Firmware Update (AFU)
Note
These objects are implemented primarily for testing purposes and are not production-ready. To generate compatible update packages for testing, use the create_package.py script located in the tests/integration/framework directory. If you need help implementing the required callbacks for Objects /5 and /33629, refer to Firmware Update tutorial.
In order to use the objects, you need packages that contain the appropriate metadata. To generate
these packages, run create_package.py
script located in the tests/integration/framework
directory.
8.3.2. Example usage
To generate an example package:
Run one of the following commands:
python ./tests/integration/framework/create_package.py -o ./package -m ANJAY_FW
Note
If persistence is enabled, then if the package execution is successful, upon restarting the demo (which may occur during an update if the package includes the demo), the resource /5/0/5 will be set to the value corresponding to the state Firmware updated successfully.
python ./tests/integration/framework/create_package.py -o ./package -m ANJAY_SW
python ./tests/integration/framework/create_package.py -o ./package -m ANJAY_SW -c 1234
python ./tests/integration/framework/create_package.py -o ./package -m ANJAY_SW -e FailedInstall
python ./tests/integration/framework/create_package.py -o ./package -m ANJAY_SW -e FailureInPerformActivate
python ./tests/integration/framework/create_package.py -o ./package -m ANJAY_APP
Note
If persistence is enabled and persistence file is set by --afu-marker-path
argument,
then if the package execution is successful, upon restarting the demo (which may occur
during an update if the package includes the demo), the resource /33629/0/5 will be set
to the value corresponding to the state Firmware updated successfully.
Provide package content, e.g.:
#!/bin/sh
echo installed
Press Ctrl+D
(EOF) to complete input.
After that, package should exists:
cat ./package | xxd -p
414e4a41595f5357000200000813e38003312e3023212f62696e2f73680a
6563686f20696e7374616c6c65640a
8.3.3. Package generation arguments
To obtain information about each of the available arguments, display the help message by running the following command:
python tests/integration/framework/create_package.py --help
8.3.4. Manipulating the behavior of objects
The behavior of the upgrade/install process in the Demo application can be manipulated using
metadata embedded in the package header. You can trigger specific errors during image generation
by passing the --error
argument to the create_package.py
script.
Likewise, the --crc
and --magic
arguments can be used to trigger an error during
package validation.
8.3.5. Errors description
8.3.5.1. Firmware Update and Advanced Firmware Update errors
Note
In the case of AFU, this description is only valid for the zero instance (magic == AJAY_APP). For other instances, the behavior may differ.
Error name |
Behavior |
---|---|
NoError |
The demo will replace the current process with a new one by
executing the downloaded package during update
( |
OutOfMemory |
The firmware update will fail after the package is
downloaded, during its validation in the |
FailedUpdate |
The firmware update will fail during update
( |
DelayedSuccess |
The demo will replace the current process with a new one by
executing the downloaded package during update
( |
DelayedFailedUpdate |
The demo will replace the current process with a new one by
executing the downloaded package during update
( |
SetSuccessInPerformUpgrade |
The demo will set the result to success by using the
|
SetFailureInPerformUpgrade |
The demo will set the result to Firmware update failed by
using the |
DoNothing |
The demo will return 0 in the |
Defer |
The demo will set the result to deferred by using the
|
8.3.5.2. Software Management errors
Note
To enable the Software Management object, define ANJAY_WITH_MODULE_SW_MGMT
e.g. by running
CMake or ./devconfig
with -DANJAY_WITH_MODULE_SW_MGMT=ON
argument.
Error name |
Behavior |
---|---|
NoError |
The demo will create a child process during installation
( |
FailedInstall |
The software installation will fail during installation
( |
DelayedSuccessInstall |
The demo will replace the current process with a new one
by executing the downloaded package during installation
( |
DelayedFailedInstall |
The demo will replace the current process with a new one
by executing the downloaded package during installation
( |
SuccessInPerformInstall |
The demo will set the result to success by using the
|
SuccessInPerformInstallActivate |
The demo will set the result to success and activation
state to Enable by using the
|
FailureInPerformInstall |
The demo will set the result to Software installation
failure by using the
|
FailureInPerformUninstall |
The software uninstallation will fail in the
|
FailureInPerformActivate |
The software activation will fail in the
|
FailureInPerformDeactivate |
The software deactivation will fail in the
|
FailureInPerformPrepareForUpdate |
The software update preparation will fail in the
|
DoNothing |
The demo will return 0 in the |
8.3.6. Package version
You can set the package version for all objects by using the --version
argument.
However, the version of the Firmware Update and Software Management package must be set to
1.0 (this is due to how these objects have been implemented in the demo and is not a
limitation of the Anjay library itself). In the case of Advanced Firmware Update, the
version can be anything as long as it is shorter than 24 characters.
8.3.7. Removing persistence files
Each object can store its state in a persistence file. To ensure you’re working with an object in its initial state, remove the persistence file. By default, these files are located in the following paths:
Firmware Update —
/tmp/anjay-fw-updated
Software Management —
/tmp/anjay-sw-mgmt
Advanced Firmware Update — by default there is no persistence file
Additionally, you can set the persistence file location using the following arguments:
Firmware Update —
--fw-updated-marker-path
Software Management —
--sw-mgmt-persistence-file
Advanced Firmware Update —
--afu-marker-path