# Device Tree custoimization

**URL:** https://forum.legato.io/t/device-tree-custoimization/6852
**Category:** Legato Linux distribution (Yocto project)
**Created:** [December 3, 2024, 5:55pm UTC](https://forum.legato.io/t/device-tree-custoimization/6852 "2024-12-03T17:55:04Z")
**Posts on this page:** 18
**Page:** 1

<div class="post-metadata">

### Author: ![upsampled](https://avatars.discourse-cdn.com/v4/letter/u/bc8723/32.png) [@upsampled](https://forum.legato.io/u/upsampled)
#### Post date: [December 3, 2024, 5:55pm UTC](https://forum.legato.io/t/device-tree-custoimization/6852/1 "2024-12-03T17:55:04Z")

</div>

I need to modify the DTS file associated with the WP7702 to indicate that there is a SPI NOR flash connected. What is the ‘main’ DTS file associated with this model? Typically this file is located in `kernel/arch/arm/boot/dts/`. Additional note: I am using the linux-msm recipe associated with the more modern legato releases.

---

<div class="post-metadata">

### Author: ![jyijyi](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.legato.io/jyijyi/32/822_2.png) [@jyijyi](https://forum.legato.io/u/jyijyi)
#### Post date: [December 3, 2024, 6:11pm UTC](https://forum.legato.io/t/device-tree-custoimization/6852/2 "2024-12-03T18:11:21Z")

</div>

for WP76xx, I will look into /kernel/arch/arm/boot/dts/qcom/mdm9607-wp76xx.dtsi

---

<div class="post-metadata">

### Author: ![upsampled](https://avatars.discourse-cdn.com/v4/letter/u/bc8723/32.png) [@upsampled](https://forum.legato.io/u/upsampled)
#### Post date: [December 3, 2024, 7:05pm UTC](https://forum.legato.io/t/device-tree-custoimization/6852/3 "2024-12-03T19:05:35Z")

</div>

Ok, to clarify this for others with questions regarding the kernel:

The kernel is packaged with the SDK and you can find the location of it on your system with:

```auto
$ cat ./build_bin/conf/local.conf | grep LINUX
LINUX_REPO_DIR = "/var/wp77xx/yocto/kernel"

```

The `LINUX_REPO_DIR ` variable is used by the `linux-msm` recipes to point to the source files. This version of the kernel has been patched with the `dts` files i was looking for `kernel/arch/arm/boot/dts/qcom/mdm9206-wp77xx-default.dts `

---

<div class="post-metadata">

### Author: ![upsampled](https://avatars.discourse-cdn.com/v4/letter/u/bc8723/32.png) [@upsampled](https://forum.legato.io/u/upsampled)
#### Post date: [December 3, 2024, 9:40pm UTC](https://forum.legato.io/t/device-tree-custoimization/6852/4 "2024-12-03T21:40:49Z")

</div>

# summary

Ok looks like it is more compilated than I originally thought, all the main dtb files are getting merged into something called a `masterDTB` file via `dtbtool` and put into the final image. **How do I know which of these dtb files are used at boot when they are all present in the boot image?**

# details

The important main dtb files that come out of typical kernel compilation are

```auto
-rw-r--r--. 2 bldr bldr 98830 Dec 3 18:39 mdm9607-cdp.dtb
-rw-r--r--. 2 bldr bldr 98792 Dec 3 18:39 mdm9607-mtp.dtb
-rw-r--r--. 2 bldr bldr 98838 Dec 3 18:39 mdm9607-rcm.dtb
-rw-r--r--. 2 bldr bldr 102253 Dec 3 18:39 mdm9607-wp76xx-default.dtb
-rw-r--r--. 2 bldr bldr 105212 Dec 3 18:39 mdm9607-wp76xx-mangoh-green.dtb
-rw-r--r--. 2 bldr bldr 103286 Dec 3 18:39 mdm9607-wp76xx-mangoh-red.dtb
-rw-r--r--. 2 bldr bldr 103426 Dec 3 18:39 mdm9607-wp76xx-mangoh-yellow.dtb

```

`linux-msm.inc` then turns them into

```auto
-rw-r--r--. 1 bldr bldr 10355910 Dec 3 18:39 dtb-zImage-4.14.253-cdp.dtb
-rw-r--r--. 1 bldr bldr 10355872 Dec 3 18:39 dtb-zImage-4.14.253-mtp.dtb
-rw-r--r--. 1 bldr bldr 10355918 Dec 3 18:39 dtb-zImage-4.14.253-rcm.dtb
-rw-r--r--. 1 bldr bldr 10359333 Dec 3 18:39 dtb-zImage-4.14.253-wp76xx-default.dtb
-rw-r--r--. 1 bldr bldr 10362292 Dec 3 18:39 dtb-zImage-4.14.253-wp76xx-mangoh-green.dtb
-rw-r--r--. 1 bldr bldr 10360366 Dec 3 18:39 dtb-zImage-4.14.253-wp76xx-mangoh-red.dtb
-rw-r--r--. 1 bldr bldr 10360506 Dec 3 18:39 dtb-zImage-4.14.253-wp76xx-mangoh-yellow.dtb

```

one of these sets of dtb files are merged together via the command

```auto
 ${STAGING_BINDIR_NATIVE}/dtbtool \
        ${B}/arch/arm/boot/dts/ \
        -s $page_size \
        -o ${DEPLOYDIR}/$master_dtb_name \
        -p ${B}/scripts/dtc/ \
        -v

```

This is actually run twice to generate two different master dtb files: `masterDTB.2k` and `masterDTB.4k`. These correspond to the `2k` and `4k` page size, boot images that are generated.

Anyhow I need to know which of these dtb files is selected by the bootloader and/or kernel so i know which one to modify.

---

<div class="post-metadata">

### Author: ![jyijyi](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.legato.io/jyijyi/32/822_2.png) [@jyijyi](https://forum.legato.io/u/jyijyi)
#### Post date: [December 4, 2024, 1:14am UTC](https://forum.legato.io/t/device-tree-custoimization/6852/5 "2024-12-04T01:14:58Z")

</div>

are you able to just build the kernel?  
If so, you can add some dummy characters in those dts file and see if it will generate compilation error

BTW, why don’t you work on the kernel first?  
strange that you need to distinguish which file for bootloader and which file for kernel

---

<div class="post-metadata">

### Author: ![upsampled](https://avatars.discourse-cdn.com/v4/letter/u/bc8723/32.png) [@upsampled](https://forum.legato.io/u/upsampled)
#### Post date: [December 4, 2024, 1:53pm UTC](https://forum.legato.io/t/device-tree-custoimization/6852/6 "2024-12-04T13:53:22Z")

</div>

I can build the kernel just fine, I need to modify the Device Tree used by the kernel which selected by the bootloader. Once I know which DTB file/parition is selected, I can patch the associated DTS file.

> If so, you can add some dummy characters in those dts file and see if it will generate compilation error

This still will not tell me which of the DTB files is selected by the bootloader. It will cause a compilation error even for DTB files we don’t use, because you bundle multiple DTB files into the masterDTB.

> strange that you need to distinguish which file for bootloader and which file for kernel

This is not strange at all and something every other Linux SOM expects the final user to modify; as such, this documentation is typically provided in the Support Package. DTS modification are required for many peripherals ( SPI Flash, I2C Real Time Clocks, etc. ).

**To summarize:**

- **I need to modify the DTB file used by the Kernel so support a SPI peripheral**
- **The Legato build environment builds and bundles several DTB files into a MasterDTB file. The bootloader then selects one of them to be used by the kernel.**

**I need to know which DTB/Partition is being selected by the bootloader (which i have very limited insight into).**

---

<div class="post-metadata">

### Author: ![upsampled](https://avatars.discourse-cdn.com/v4/letter/u/bc8723/32.png) [@upsampled](https://forum.legato.io/u/upsampled)
#### Post date: [December 4, 2024, 3:26pm UTC](https://forum.legato.io/t/device-tree-custoimization/6852/8 "2024-12-04T15:26:32Z")

</div>

# Bug

**Upon further investigation, I believe there is an error in your yocto recipe that is preventing WP77XX DTB files from being put into the final deployment image**

## Notes

Using `/proc/device-tree/model` I can see that `mdm9206-wp77xx-default` is the main device tree selected by the bootloader.

```auto
:~# cat /proc/device-tree/model
Sierra Wireless, Inc. MDM WP7xxx series

```

The issue is that I cannot update this file, in addition, this file is not being put into the final image.

The reason for this is is both the WP76XX and WP77XX get put into the same basemachine

```auto
#/meta-swi-wp/meta-swi-wp/conf/machine/swi-mdm9x28-wp.conf
GENERIC_BASEMACHINE = "mdm9x28"

```

which then gives them the variable

```auto
#./meta-swi/meta-swi-mdm9x28/conf/machine/swi-mdm9x28.conf
BASEMACHINE_QCOM = "mdm9607"

```

Finally this variable is used to isolate the dtb files used in the master image

```auto
#./meta-swi/meta-swi-mdm9x28/recipes-kernel/linux-msm/linux-msm.inc 
dtb_files=$(find ${B}/arch/arm/boot/dts -iname "*${BASEMACHINE_QCOM}*.dtb" | awk -F/ '{print $NF}' | awk -F[.][d] '{print $1}')

```

As the dtb files are either prefixed `mdm9607-wp76xx` or `mdm9206-wp77xx`, just the `wp76xx` files are selected.

---

<div class="post-metadata">

### Author: ![jyijyi](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.legato.io/jyijyi/32/822_2.png) [@jyijyi](https://forum.legato.io/u/jyijyi)
#### Post date: [December 4, 2024, 3:26pm UTC](https://forum.legato.io/t/device-tree-custoimization/6852/9 "2024-12-04T15:26:36Z")

</div>

i don’t have much experience in using the SPI bus.  
But i recall I have tried the CAN bus IOT card using SPI bus on mangoh red board:

> **[Cannot find device Can0](https://mangoh.discourse.group/t/cannot-find-device-can0/6280/4)**
>
> your image does not have the can\_iot.ko. BTW, I transfer the .update file to module by scp, and then update by “update /tmp/xxx.update” on module console.

And I did not need to change DTS file for this driver

---

<div class="post-metadata">

### Author: ![upsampled](https://avatars.discourse-cdn.com/v4/letter/u/bc8723/32.png) [@upsampled](https://forum.legato.io/u/upsampled)
#### Post date: [December 4, 2024, 3:46pm UTC](https://forum.legato.io/t/device-tree-custoimization/6852/10 "2024-12-04T15:46:31Z")

</div>

Ok, but for SPI NOR Flash [I have to edit the DTS file](https://www.kernel.org/doc/Documentation/devicetree/bindings/mtd/jedec%2Cspi-nor.txt), so let’s keep the thread on track.

DTS modifications is a standard procedure in Embedded Linux development. Right now it looks like your board support package is not allowing this for at least the WP77XX. I need either documentation explaining how your dev environment does allow for modifications to the relavent DTS/B file or an update that fixes the deficiency.

---

<div class="post-metadata">

### Author: ![jyijyi](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.legato.io/jyijyi/32/822_2.png) [@jyijyi](https://forum.legato.io/u/jyijyi)
#### Post date: [December 4, 2024, 4:24pm UTC](https://forum.legato.io/t/device-tree-custoimization/6852/11 "2024-12-04T16:24:41Z")

</div>

what if you change the file mdm9607-wp76xx.dtsi and build the yocto image, does it take effect for your usage?

---

<div class="post-metadata">

### Author: ![upsampled](https://avatars.discourse-cdn.com/v4/letter/u/bc8723/32.png) [@upsampled](https://forum.legato.io/u/upsampled)
#### Post date: [December 4, 2024, 4:31pm UTC](https://forum.legato.io/t/device-tree-custoimization/6852/12 "2024-12-04T16:31:56Z")

</div>

looking into that now, will report back after the build

---

<div class="post-metadata">

### Author: ![upsampled](https://avatars.discourse-cdn.com/v4/letter/u/bc8723/32.png) [@upsampled](https://forum.legato.io/u/upsampled)
#### Post date: [December 4, 2024, 7:54pm UTC](https://forum.legato.io/t/device-tree-custoimization/6852/13 "2024-12-04T19:54:56Z")

</div>

# Root Cause?

The DTS file is not being pushed because Yocto is specifically not including the `boot-yocto` image in the generated `cwe` output.

I need to know:

1. Why is the code to include the `boot-yocto` image commented out?
2. Can this code be re-enabled and the generated `boot-yocto*cwe` files used?
3. Are there any implications to secure boot as it deals with the same files?

# Procedure

1. Modified `mdm9607-wp76xx-default.dts` by adding a `spi` device and also appended `CDI v1` onto the `model` string
2. Cleaned the bitbake caches with `bitbake -c cleanall linux-msm`
3. rebuilt the entire base image `bitbake mdm9x28-image-minimal`, this should
  - compile the dts to a dtb (`CONFIG_ARCH_MDM9607`)
  - bundle the dtb into a master dtb (`./linux-msm.inc` and `gen_master_dtb`)
  - bundle the master dtb files into an boot-yocto\*.img file (`./linux-msm.inc` and `gen_bootimg`).

Here is the issue, the expectation is that `mdm9x28-image-cwe.inc` (`generate_cwe` and `generate_cwe_pid` specifically) is supposed to use the `boot-yocto` image to generate `boot-yocto-legato*.cwe` and `boot-yocto*.cwe`; however this does not happen because these steps are both commented out:

```auto
#mdm9x28-image-cwe.inc
    done
# echo "Generating CWE package for $TARGET ($PAGE_SIZE, with lk)"
# generate_cwe_pid $PID $PLATFORM $PAGE_SIZE ${DEPLOY_DIR_IMAGE}/boot-yocto${CWE_NAME_EXTRA}_$TARGET.cwe true true true false

# if ["${LEGATO_BUILD}" = "true"]; then
# echo "Generating CWE package for $TARGET ($PAGE_SIZE)"
# generate_cwe_pid $PID $PLATFORM $PAGE_SIZE ${DEPLOY_DIR_IMAGE}/yocto-legato${CWE_NAME_EXTRA}_$TARGET.cwe false true true true

# echo "Generating CWE package for $TARGET ($PAGE_SIZE, with lk, with Legato)"
# generate_cwe_pid $PID $PLATFORM $PAGE_SIZE ${DEPLOY_DIR_IMAGE}/boot-yocto-legato${CWE_NAME_EXTRA}_$TARGET.cwe true true true true
# fi
}

```

# Notes

1. I have confirmed that the modification to the dts is being compiled to the intended dtb file

```auto
yocto/build_bin$ dtc -I dtb -O dts ./tmp/work/swi_mdm9x28_wp-poky-linux-gnueabi/linux-msm/4.14.253-r1/deploy-linux-msm/dtb/qcom/mdm9607-wp76xx-default.dtb 2>&1| grep "\smodel ="
        model = "Sierra Wireless, Inc. MDM WP7xxx series - CDI v1";

```

1. The only reason i stumbled onto this was looking at the Secure boot guide, which only has this vague statement regarding `mdm9x28-image-cwe.inc`

> Package the signed images into CWE images. For details, refer to the following script in the build system  
> output – meta-swi/meta-swi-mdm9x28/recipes-core/images/mdm9x28-image-cwe.inc.

---

<div class="post-metadata">

### Author: ![jyijyi](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.legato.io/jyijyi/32/822_2.png) [@jyijyi](https://forum.legato.io/u/jyijyi)
#### Post date: [December 5, 2024, 1:14am UTC](https://forum.legato.io/t/device-tree-custoimization/6852/14 "2024-12-05T01:14:58Z")

</div>

Do you mean now the yocto.cwe and appboot.cwe have been compiled after typing “make” command and working for your SPI flash?  
If yes, actually you can combine the image by swicwe tool

---

<div class="post-metadata">

### Author: ![upsampled](https://avatars.discourse-cdn.com/v4/letter/u/bc8723/32.png) [@upsampled](https://forum.legato.io/u/upsampled)
#### Post date: [December 5, 2024, 2:33pm UTC](https://forum.legato.io/t/device-tree-custoimization/6852/15 "2024-12-05T14:33:25Z")

</div>

No, per the [last time you actually documented the Yocto system](https://docs.legato.io/15_10/yocto_legato.html), in Release 15.10, the ‘boot’ packages contain the bootloader. It is in these bootloader packages that you also put the DTS file, so without the ability to generate the `boot` packages and install them on the target, I cannot update the DTS file. The `appboot` package seems to mainly be involved with the little kernel ('`lk`) but does not appear to bundle the DTS file.

| packages | | boot\_wp85.cwe | | package with bootloader |
| --- | --- | --- | --- | --- |
| | | boot-yocto\_wp85.cwe | | package with bootloader + yocto (= kernel + rootfs) |
| | | boot-yocto-legato\_wp85.cwe | | package with bootloader + yocto (= kernel + rootfs) + legato |
| | | legato-image.wp85.cwe | | package with legato |
| | | yocto\_wp85.cwe | | package with yocto (= kernel + rootfs) |
| | | yocto-legato\_wp85.cwe | | package with yocto (= kernel + rootfs) + legato |

## Notes

- this information is not in [the latest legato doc](https://docs.legato.io/latest/), this needs to be remedied
- What I am seeing also seems to contradict the [Secure Boot guide](https://source.sierrawireless.com/resources/airprime/application_notes_and_code_samples/airprime_-_wp_series_-customer_secure_boot/#sthash.YHWHVwqJ.dpbs), as that is my next effort. The guide deals heavely with the `boot*cwe` images

---

<div class="post-metadata">

### Author: ![jyijyi](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.legato.io/jyijyi/32/822_2.png) [@jyijyi](https://forum.legato.io/u/jyijyi)
#### Post date: [December 5, 2024, 2:50pm UTC](https://forum.legato.io/t/device-tree-custoimization/6852/16 "2024-12-05T14:50:36Z")

</div>

For WP76xx, I remember if i modify the file /kernel/arch/arm/boot/dts/qcom/mdm9607-wp76xx.dtsi, after that i type “make” command, the yocto image will be including my modification.

I am not quite understand what “boot” package you are referring to…

For secure boot, you can also see this document.  
I tried it in WP76 FW R16 before:

> [@Secure Boot -Generating cwe file](https://forum.legato.io/t/secure-boot-generating-cwe-file/5615/4):
>
> updated version including bootloader/kernel/rootFS/legatoFS authentication in FW R16: [Example on Secure boot implementation for WP76xx (version 7).docx](https://forum.legato.io/uploads/short-url/xnRX0BZEcAtoMaRspewk3BdtCSp.docx) (376.4 KB)

---

<div class="post-metadata">

### Author: ![upsampled](https://avatars.discourse-cdn.com/v4/letter/u/bc8723/32.png) [@upsampled](https://forum.legato.io/u/upsampled)
#### Post date: [December 5, 2024, 3:06pm UTC](https://forum.legato.io/t/device-tree-custoimization/6852/17 "2024-12-05T15:06:43Z")

</div>

> [@jyijyi](#):
>
> I am not quite understand what “boot” package you are referring to…

I have showed two guides, [Customer Secure Boot](https://source.sierrawireless.com/resources/airprime/application_notes_and_code_samples/airprime_-_wp_series_-customer_secure_boot/#sthash.YHWHVwqJ.dpbs) and [Yocto Legato Builds](https://docs.legato.io/15_10/yocto_legato.html) , provided by Legato/Sierra that explain what the `boot*cwe` packages are and also included your own [yocto source](https://github.com/legatoproject/meta-swi/blob/yocto-3.0-ref/meta-swi-mdm9x28/recipes-core/images/mdm9x28-image-cwe.inc#L179) file that seemingly at one point generates them, but then was commented out.

> [@jyijyi](#):
>
> For WP76xx, I remember if i modify the file /kernel/arch/arm/boot/dts/qcom/mdm9607-wp76xx.dtsi, after that i type “make” command", the yocto image will be including my modification.

After `make`, what generated output file are you uploading to the target? I will mimic your process _exactly_ and report back results.

---

<div class="post-metadata">

### Author: ![jyijyi](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.legato.io/jyijyi/32/822_2.png) [@jyijyi](https://forum.legato.io/u/jyijyi)
#### Post date: [December 5, 2024, 3:18pm UTC](https://forum.legato.io/t/device-tree-custoimization/6852/18 "2024-12-05T15:18:45Z")

</div>

> [@upsampled](#):
>
> After `make`, what generated output file are you uploading to the target?

i just download the yocto\_wp76xx.4k.cwe to my WP76 module for testing

---

<div class="post-metadata">

### Author: ![upsampled](https://avatars.discourse-cdn.com/v4/letter/u/bc8723/32.png) [@upsampled](https://forum.legato.io/u/upsampled)
#### Post date: [December 5, 2024, 6:39pm UTC](https://forum.legato.io/t/device-tree-custoimization/6852/19 "2024-12-05T18:39:13Z")

</div>

using `yocto_wp77xx` worked. Please update the mentioned guides, specifically the Secure Boot.
