You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

94 lines
6.2 KiB

8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
  1. \subsection{Build infrastructure and automatic deployment}
  2. The CI system, which is based on \textit{drone} \cite{drone} allows to execute commands, whenever a new version is published into the \textit{Git} repository.
  3. A corresponding \textit{drone} configuration called \texttt{.drone.yml} exists beside the source code (Listing~\ref{lst:drone}).
  4. Within this configuration file, settings relevant to the build process are provided to the build environment.
  5. First, the \texttt{CONFIG=maglab} option lets the build system use an additional configuration file (\texttt{Configurion.mk.maglab}), which is stored inside the framework repository and provides environment specific information, such as the WiFi SSID.
  6. To keep secrets like the WiFi password unexposed, it is not written down in the configuration file.
  7. Instead, to include secrets into a build process while allowing to keep the configuration public, \textit{drone} allows to encrypt these with a repository specific key.
  8. Using this method, the password is stored as \texttt{.drone.sec} file inside the repository from where it is injected into the build environment.
  9. Also noticeable in Listing~\ref{lst:drone} is the firmware version, which is configured to be the first 8 letters of the \textit{Git} commit hash uniquely identifying a version of the source code.
  10. \begin{lstlisting}[language=,
  11. caption={The \textit{drone} configuration for the \textit{ESPer} project.},
  12. label=lst:drone, basicstyle=\ttfamily\scriptsize]
  13. build:
  14. image: maglab/sming
  15. environment:
  16. - CONFIG=maglab
  17. - WIFI_PWD=$$WIFI_PWD
  18. - VERSION=$${COMMIT:0:8}
  19. commands:
  20. - make clean
  21. - make
  22. publish:
  23. sftp:
  24. host: eddie.maglab.space
  25. username: esper
  26. files:
  27. - dist/*
  28. destination_path: './'
  29. when:
  30. branch: master
  31. \end{lstlisting}
  32. For deployment, only the master branch is considered.
  33. After a successful build, all distribution files (the firmware image and meta-information files) of all device types are copied to the repository server, where they are served by a HTTP server.
  34. The configuration file (\texttt{Configurion.mk.maglab}) references this repository server as the source for updates.
  35. Support for multiple devices of different type is implemented in both, the \textit{ESPer} framework itself and the build system.
  36. The framework keeps control over the application life-cycle.
  37. It ensures that device unspecific code is executed at the right time and provides an API for device specific functionality.
  38. For this, a simple interface is specified by the framework, which must be implemented by each device.
  39. A single function \texttt{Device* getDevice()} must be defined exactly once in each device specific folder.
  40. To implement this interface, a static instance of \texttt{Device} is created and returned.
  41. Each \texttt{Device} is populated with device specific \texttt{Feature} instances.
  42. While the \texttt{Feature}-API leverages common run time polymorphism to share functionality between features, the initial \texttt{Device} creation uses compile time polymorphism, which reduces the need for memory management and increases performance by avoiding virtual function tables.
  43. Listing~\ref{lst:create_device_socket} shows the complete device specific code used for a simple power socket, which is mainly confined to the device type and its capabilities (i.e., the number of GPIO pins).
  44. \begin{lstlisting}[caption={Device specific code for a socket driver.},
  45. label=lst:create_device_socket, basicstyle=\ttfamily\scriptsize]
  46. #include "Device.h"
  47. #include "features/Socket.h"
  48. Device device:
  49. constexpr const char NAME[] = "socket";
  50. constexpr const uint16_t GPIO = 12;
  51. OnOffFeature<NAME, GPIO, false, 1> socket(&device);
  52. Device* getDevice() {
  53. return &device;
  54. }
  55. \end{lstlisting}
  56. The actual compilation of the source code is mainly controlled using two \textit{Makefiles}.
  57. The first one is a helper \textit{Makefile} built to accept a parameter for device type identifiers called \texttt{DEVICE}, and to create its whole output inside a subdirectory specific to the device type.
  58. In addition, the primary \textit{Makefile} scans a project subdirectory and uses each directory in there as a container for device specific code.
  59. For each of these directories, the helper \textit{Makefile} is called and the subdirectories name is used as the value of the \texttt{DEVICE} parameter.
  60. By splitting the build and recompiling the framework each time before intermixing it with the device specific code, the device type identifier can be used inside the shared framework code.
  61. While building a devices firmware, the meta-information file used during updates is also created and stored beside the firmware image.
  62. For development, each device can be build separately by using the device type identifier as \textit{Makefile} target.
  63. In addition, the suffix \texttt{/flash} can be used to flash a specific firmware to the device.
  64. While building the firmware images for a device, the build environment provides some constants which are baked into the resulting firmware image.
  65. Beside the environmental configuration like the \textit{WiFi} credentials, \textit{MQTT} topics and other configurable tweaks, the current device and version identifiers are provided as compile time constants.
  66. In addition, the public key used to verify firmware signatures during updates is derived from the private key and provided as an linker object which is linked into each firmware image (~\ref{lst:public_key_object}).
  67. This allows to use all the information inside the code without any overhead while being configurable during build time.
  68. \begin{lstlisting}[caption={Creating the linker object containing the public key.},
  69. label=lst:public_key_object, basicstyle=\ttfamily\scriptsize]
  70. update_key_pub.bin:
  71. echo -n "$(UPDATE_KEY)" | \
  72. ecdsakeygen -p | \
  73. xxd -r -p > "$@"
  74. update_key_pub.o: update_key_pub.bin
  75. $(OBJCOPY) -I binary $< \
  76. -B xtensa \
  77. -O elf32-xtensa-le $@
  78. \end{lstlisting}
  79. The build process will create the two firmware images, one for each ROM slot, and the meta-information file.
  80. To create the meta-information file, the current version identifier is written to the \texttt{.version} file.
  81. After the build, the signatures for both firmware images are created and attached to the file.