Dts file, how to write it

So under the "target/xxx/dts/" folder of the OpenWRT source code, there are alot of hardware configuration file for each type of the router. Anyone have experience writing that file? Espeically in the spi memory partition section, how is one to decide what is the "starting" "reg" value for a memory? This one is a working example for a 256Mbits "Winbond" W25Q256FV. But I don't see from the documentation as to how you derive the 0x40000? The reason I ask is because I am doing it for another memory chip W25Q64BV

    flash@0 {
        compatible = "jedec,spi-nor";
        reg = <0>;
        spi-max-frequency = <50000000>;

        partitions {
            compatible = "fixed-partitions";
            #address-cells = <1>;
            #size-cells = <1>;

            partition@0 {
                label = "u-boot";
                reg = <0x0 0x40000>;

            factory: partition@40000 {
                label = "factory";
                reg = <0x40000 0x10000>;

            partition@50000 {
                compatible = "denx,uimage";
                label = "firmware";
                reg = <0x50000 0xf70000>;

            /* Those next partitions for downgrade support */
            partition@fc0000 {
                label = "config2";
                reg = <0xfc0000 0x10000>;

            partition@fd0000 {
                label = "config";
                reg = <0xfd0000 0x10000>;

            partition@fe0000 {
                label = "nvram2";
                reg = <0xfe0000 0x10000>;

            partition@ff0000 {
                label = "nvram";
                reg = <0xff0000 0x10000>;

These are the partition offsets, they depend on the software not the hardware. The offsets need to match the expectations of the bootloader. In your case, the boot loader starts at 0 and its partition size is 0x40000. At this offset, the next partition starts.

The memory chip itself is auto-detectes by its JEDEC ID.

Hello Andy,

thank you very much for the explanation! I have a working custom firmware for one of our router. The router is using MediaTek 7621. But now, I need to make the firmware work on another model of ours which is using MediaTek 7628. I've looked at the physical board on the router, the memory (RAM) and the Flash memory are both the exact same between the 7621 and 7628. So I thought I could simply (in the Make MenuConfig) choose sub-type of MediatTek 7628 and recompile. The compilation went through fine, but when I burn the firmare onto 7628, it doesn't work. So then the only thing I thought would be different would be the dts file? Originally I simply copy the dts file from the 7621 folder onto 7628 folder.

Any thought as to why this method not working? Or is there anything I've missed that I needed to do when switching chip?

Thank you for any input!

You cannot just copy a dts from one target to another without changing quite a bit of the details. MT7621 is not the same as MT7628 - you will have to fix all your peripherals, not just the partition map. There's a ton of examples in the source tree. And since it's your board - get in touch with the hardware engineers and ask them for all the details, then fix the dts.