Skip to content

Commit

Permalink
[Issue-62]: add dt overlay package
Browse files Browse the repository at this point in the history
Signed-off-by: Jaymin Patel <jem.patel@gmail.com>
  • Loading branch information
jempatel committed Sep 11, 2023
1 parent 21a6543 commit 8139af2
Show file tree
Hide file tree
Showing 3 changed files with 142 additions and 0 deletions.
73 changes: 73 additions & 0 deletions onion-dt-overlay/Makefile
@@ -0,0 +1,73 @@

# Copyright (C) 2023 Onion Corporation
#
# This is free software, licensed under the GNU General Public License v2.
# See /LICENSE for more information.
#

include $(TOPDIR)/rules.mk
include $(INCLUDE_DIR)/kernel.mk

PKG_NAME:=onion-dt-overlay
PKG_VERSION:=1.0
PKG_RELEASE:=1
KERNEL_BUILD_DIR ?= $(BUILD_DIR)/linux-$(BOARD)$(if $(SUBTARGET),_$(SUBTARGET))
LINUX_DIR ?= $(KERNEL_BUILD_DIR)/linux-$(LINUX_VERSION)
DTC=$(LINUX_DIR)/scripts/dtc/dtc

include $(INCLUDE_DIR)/package.mk

define Package/onion-dt-overlay/default
TITLE:=onion-dt-overlay
SECTION:=onion
CATEGORY:=Onion
SUBMENU:=Utilities
TITLE:=Onion DT Overlay
endef

define Package/onion-dt-overlay
$(Package/onion-dt-overlay/default)
endef

define Package/onion-dt-overlay/description
Onion DT Overlay
endef

define Build/Prepare
rm -rf $(PKG_BUILD_DIR)
mkdir -p $(PKG_BUILD_DIR)
$(CP) src $(PKG_BUILD_DIR)
endef

define Build/Compile
true
endef

define Package/onion-dt-overlay/install
true
endef

define BuildDtbo

define Package/onion-dt-overlay-$(1)
$(Package/onion-dt-overlay/default)
TITLE+= ($(1) DTBO)
DEPENDS+=onion-dt-overlay $(2)
endef

define Package/onion-dt-overlay-$(1)/description
$(3)
endef

define Package/onion-dt-overlay-$(1)/install
$(INSTALL_DIR) $$(1)/lib/firmware/device-tree/overlays/
$(DTC) -b 0 -@ -O dtb $(PKG_BUILD_DIR)/src/$(1).dts -o $(PKG_BUILD_DIR)/src/$(1).dtbo
$(INSTALL_DATA) $(PKG_BUILD_DIR)/src/$(1).dtbo $$(1)/lib/firmware/device-tree/overlays/$(1).dtbo
endef

$$(eval $$(call BuildPackage,onion-dt-overlay-$(1)))

endef

$(eval $(call BuildPackage,onion-dt-overlay))
$(eval $(call BuildDtbo,sw-spi,,Provides SW SPI))
38 changes: 38 additions & 0 deletions onion-dt-overlay/README.md
@@ -0,0 +1,38 @@
## Device Tree Runtime Overlay

onion-dt-overlay provides device tree runtime overlay without rebuilding firmware image giving flexibility to the user for easy customization of device tree.

### Add custom device tree package.

Onion Omega2 package onion-dt-overlay has a wrapper to build a device tree overlay package. Here are the steps that can be performed to add a custom device tree overlay.

1. Add a custom `.dts` file into the `src` directory. Make sure the file extension is `.dts` only.
2. Edit Makefile and add a new line after the last line

```bash
$(eval $(call BuildDtbo,<dtbo src file without ext>,<list of dependency packages>,<package description>))
```
### Example Dtbo

Assume, the user wants to add a custom device tree runtime overlay package named `example`.
- Create a file `src/example.dts`
- Edit the Makefile of the onion-dt-overlay package and add a new line after the last line that looks like

```bash
$(eval $(call BuildDtbo,example,,Example DTBO))
```

It will create a new package named `onion-dt-overlay-example`.

- After package is compiled and installed on omega2, it will install a `dtbo` file on location `/lib/firmware/device-tree/overlays/example.dtbo`.
- reboot omega2.

### Validate Runtime Dtbo

- The status of `dtbo` can be check from a file `/sys/kernel/config/device-tree/overlays/<dtbo>/status`
- In the case of `example.dtbo`, If would show its `status` as `applied`

```bash
# cat /sys/kernel/config/device-tree/overlays/example/status
applied
```
31 changes: 31 additions & 0 deletions onion-dt-overlay/src/sw-spi.dts
@@ -0,0 +1,31 @@
/dts-v1/;
/plugin/;
/ {
fragment@0 {
target-path = "/";
__overlay__ {
sw-spi {
compatible = "spi-gpio";
#address-cells = <0x1>;
#size-cells = <0x0>;
sck-gpios = <&gpio 11 0>;
mosi-gpios = <&gpio 5 0>;
miso-gpios = <&gpio 4 0>;
cs-gpios = <&gpio 23 0>;
num-chipselects = <1>;

spi-max-frequency = <100000>;
spi-cs-high;

/* clients */
spidev@0 {
compatible = "linux,spidev";
reg = <0>;
spi-max-frequency = <10000000>;
};

};

};
};
};

0 comments on commit 8139af2

Please sign in to comment.