|
| 1 | +--- |
| 2 | +title: "Create a Device Overlay File" |
| 3 | +layout: default |
| 4 | +parent: Adding Board Support |
| 5 | +nav_order: 0 |
| 6 | +--- |
| 7 | + |
| 8 | +# Create a Device Overlay File |
| 9 | + |
| 10 | +The Ocre runtime, built on the Zephyr RTOS, requires proper configuration of your board's components and memory layout. This guide will walk you through creating a device overlay file. |
| 11 | + |
| 12 | +--- |
| 13 | + |
| 14 | +## What is a Device Overlay File? |
| 15 | + |
| 16 | +In Zephyr, each board has a default [Device Tree Source](https://docs.zephyrproject.org/latest/build/dts/intro-scope-purpose.html) (`.dts`) file that defines its hardware configuration, including memory mappings, peripherals, and bus configurations. An *overlay* file (`.overlay`)allows you to extend or modify this default configuration without changing the original source files. |
| 17 | + |
| 18 | +For Ocre, proper overlay configuration is crucial for: |
| 19 | +- Defining flash memory partitions for the boot-loader and containers |
| 20 | +- Configuring board-specific hardware features |
| 21 | +- Ensuring correct memory allocation for the runtime |
| 22 | + |
| 23 | +--- |
| 24 | + |
| 25 | +## Creating Your Overlay File |
| 26 | +Creating a device overlay file involves configuring your board's flash memory partitions, hardware peripherals, and possibly the filesystem for the Ocre Runtime to function properly. You'll need to understand your board's memory layout and hardware capabilities, as well as any additional modules you might need for networking support. Below you'll find requirements, examples, and step-by-step instructions to create your overlay. |
| 27 | + |
| 28 | +### Prerequisites |
| 29 | +Before creating your overlay file: |
| 30 | + |
| 31 | +- Check out Zephyrs [Introduction to Devicetree](https://docs.zephyrproject.org/latest/build/dts/intro.html) guide. |
| 32 | +- Locate your boards (Zephyr) **name**, as found in the Zephyr [Supported Boards](https://docs.zephyrproject.org/3.7.0/boards/index.html) guide. (e.g. `nucleo_h563zi`) |
| 33 | +- Review your boards `.dts` file as found in the Zephyr source (`zephyr/boards/manufacturer/board_name/board_name.dts`). |
| 34 | +- Review your board's technical documentation |
| 35 | + |
| 36 | +{: .highlight} |
| 37 | +The `board_name.dts` file provides a foundational reference for your board's hardware configuration but may not describe all available peripherals, hardware features, or supported options. Zephyr's Device Tree support is an evolving process and may not fully align with your board's latest specifications or capabilities. Use the `.dts` file as a baseline, but cross-reference with your board's datasheet and hardware documentation to ensure accuracy and completeness in your overlay file. |
| 38 | + |
| 39 | + |
| 40 | +### Partition Layout Requirements |
| 41 | +Ocre uses MCUBoot as a boot-loader, therefore it requires setting up the flash partitions accordingly. (See the [MCUboot docs](https://docs.mcuboot.com/readme-zephyr.html) for full details.) |
| 42 | + |
| 43 | +| Partition | Size (min) | Description | |
| 44 | +|----------|----------|----------| |
| 45 | +| `boot_partition` | 32k | MCUboot boot-loader | |
| 46 | +| `slot0_partition` | 256k | Primary slot for image 0 | |
| 47 | +| `slot1_partition` | 256k | Secondary slot for image 0 | |
| 48 | +| `storage_partition` | 8k | Storage for custom Zephyr functions | |
| 49 | +| `user_data` | Remaining memory | Storage for Ocre container definitions and images | |
| 50 | + |
| 51 | +{: .note} |
| 52 | +Not all boards will require you to define *all* the above partitions in the `.overlay` file, as their `.dts` file may already define them. Please refer to your boards `.dts` file beforehand and only define (or modify) partitions if they're needed. |
| 53 | + |
| 54 | +### Additional Device Tree Configurations |
| 55 | + |
| 56 | +Beyond flash partitions, your board may require additional device tree configurations depending on its hardware and requirements. |
| 57 | + |
| 58 | +Common configurations include: |
| 59 | + |
| 60 | +- **File System Support**: Configure file system tables via `fstab` nodes for container storage |
| 61 | +- **Chosen Nodes**: Specify system-wide defaults like console, shell, and flash devices |
| 62 | +- **Hardware Peripherals**: Enable and configure communication interfaces like: |
| 63 | + - Ethernet modules (like the *enc28j60* example below) |
| 64 | + - WiFi modules (such as esp32 or other wireless adapters) |
| 65 | + - Serial interfaces and other board-specific peripherals |
| 66 | + |
| 67 | +{: .note} |
| 68 | +These configurations vary by board. If your board lacks built-in networking capabilities, you'll need to add support for an external ethernet or WiFi module as Ocre requires internet connectivity for container management. |
| 69 | + |
| 70 | +### Example Overlay File |
| 71 | +Here's a sample overlay for STMicroelectronics `B-U585I-IOT02A` board: |
| 72 | + |
| 73 | +``` |
| 74 | +&spi1 { |
| 75 | + enc28j60: ethernet@0 { |
| 76 | + status = "okay"; |
| 77 | + reg = <0>; |
| 78 | + compatible = "microchip,enc28j60"; |
| 79 | + int-gpios = <&gpioc 1 GPIO_ACTIVE_LOW>; |
| 80 | + spi-max-frequency = <10000000>; |
| 81 | + local-mac-address = [ 00 80 00 01 02 03 ]; |
| 82 | + full-duplex; |
| 83 | + }; |
| 84 | +}; |
| 85 | +
|
| 86 | +&flash0 { |
| 87 | + partitions { |
| 88 | + user_data_partition: partition@100000 { |
| 89 | + label = "user_data"; |
| 90 | + reg = <0x00100000 DT_SIZE_K(256)>; |
| 91 | + }; |
| 92 | + }; |
| 93 | +}; |
| 94 | +``` |
| 95 | + |
| 96 | +As mentioned in the previous section, many boards already have some partitions defined in their `.dts` file. This board only needed an additional `user_data_partition` definition in its overlay as the other required partitions were defined in its base [DTS file](https://github.com/zephyrproject-rtos/zephyr/blob/main/boards/st/b_u585i_iot02a/b_u585i_iot02a.dts). |
| 97 | + |
| 98 | +You also may have noticed that this board also has an added configuration for the *enc28j60* ethernet controller as that board does not have an onboard ethernet or Wifi device. |
| 99 | + |
| 100 | +### Steps |
| 101 | + |
| 102 | +Creating an overlay file will most likely take a bit of iteration as each board and requirements are unique. Also, depending on which options, devices, and peripheral you place in the overlay you may require additional configuration options to get your build to work so please see [**Creating a Device Config**](../config) to do that. |
| 103 | + |
| 104 | +1. Create a blank file named `board_name.overlay` (replacing `board_name` with your boards name) in the *top-level* `boards` directory (`application/boards`). |
| 105 | +2. Add the required partition layout to your overlay file, while referencing the [**Partition Layout Requirements**](#partition-layout-requirements) section and [**Example Overlay File**](#example-overlay-file) example above. |
| 106 | +3. Save your overlay file. |
| 107 | +4. Attempt to build the Ocre runtime following the [**Building and Flashing Ocre to Your Board**](../ocre-runtime) guide. |
| 108 | +5. Most likely you will encounter errors, address them in the overlay (or in the [**config**](../config)) and try to build again. |
| 109 | + |
| 110 | +--- |
| 111 | + |
| 112 | +## Next Steps |
| 113 | +If your board builds successfully, congratulations! Continue to the [**Contributing Board Support**](../contributing) page to figure out how to get your board added to the official Ocre repos. |
| 114 | + |
| 115 | +If you weren't successful by simply creating an overlay, then see the [**Create a Device Config**](../config) to add necessary configuration options for your board. |
0 commit comments