What's the requirement for adding a new device?

Hi, i am a newbie. According to the openwrt official document, one thing need to add is the .dts file. And on openwrt source repository commit record, dts file is a wholely new file. Is this dts file only be done by the hardware developer? If the chip is supported by openwrt(like mt7621dat), can i add this new device by myself?
i've copied another dts file, modified the flash layout, and finished compiling, when i flash to device, here are pieces of log:

[    0.689436] printk: console [ttyS0] enabled
[    0.689436] printk: console [ttyS0] enabled
[    0.705930] printk: bootconsole [early0] disabled
[    0.705930] printk: bootconsole [early0] disabled
[    0.727672] spi-mt7621 1e000b00.spi: sys_freq: 220000000
[    0.740777] spi-nor spi0.0: s25fl064k (8192 Kbytes)
[    0.750582] 4 fixed-partitions partitions found on MTD device spi0.0
[    0.763282] Creating 4 MTD partitions on "spi0.0":
[    0.772832] 0x000000000000-0x000000030000 : "Bootloader"
[    0.784524] 0x000000030000-0x000000040000 : "Config"
[    0.795351] 0x000000040000-0x000000050000 : "Factory"
[    0.807050] 0x000000050000-0x000000800000 : "firmware"
[    0.818692] 2 uimage-fw partitions found on MTD device firmware
[    0.830589] Creating 2 MTD partitions on "firmware":
[    0.840501] 0x000000000000-0x0000002981db : "kernel"
[    0.850392] mtd: partition "kernel" doesn't end on an erase/write block -- force read-only
[    0.867710] 0x0000002981db-0x0000007b0000 : "rootfs"
[    0.877714] mtd: partition "rootfs" doesn't start on an erase/write block boundary -- force read-only
[    0.896901] mtd: device 5 (rootfs) set to be root filesystem
[    0.908463] 1 squashfs-split partitions found on MTD device rootfs
[    0.920863] 0x000000700000-0x0000007b0000 : "rootfs_data"
[    0.974417] mt7530 mdio-bus:1f: MT7530 adapts as multi-chip module
[    0.989016] mtk_soc_eth 1e100000.ethernet: generated random MAC address de:95:d2:a1:e5:cd
[    1.006135] mtk_soc_eth 1e100000.ethernet eth0: mediatek frame engine at 0xbe100000, irq 17
[    1.023630] i2c /dev entries driver
[    1.033057] mt7621-pci 1e140000.pcie: host bridge /pcie@1e140000 ranges:
[    1.046475] mt7621-pci 1e140000.pcie:   No bus range found for /pcie@1e140000, using [bus 00-ff]
[    1.064059] mt7621-pci 1e140000.pcie:      MEM 0x0060000000..0x006fffffff -> 0x0000000000
[    1.080393] mt7621-pci 1e140000.pcie:       IO 0x001e160000..0x001e16ffff -> 0x0000000000
[    1.096851] mt7621-pci 1e140000.pcie: Parsing DT failed
[    1.109766] NET: Registered protocol family 10
[    1.121146] Segment Routing with IPv6
[    1.128655] NET: Registered protocol family 17
[    1.137890] 8021q: 802.1Q VLAN Support v1.8
[    1.149637] mt7530 mdio-bus:1f: MT7530 adapts as multi-chip module
[    1.182949] mt7530 mdio-bus:1f wan (uninitialized): PHY [mt7530-0:00] driver [MediaTek MT7530 PHY] (irq=22)
[    1.204794] mt7530 mdio-bus:1f lan (uninitialized): PHY [mt7530-0:01] driver [MediaTek MT7530 PHY] (irq=23)
[    1.228436] mt7530 mdio-bus:1f: configuring for fixed/rgmii link mode
[    1.245295] DSA: tree 0 setup
[    1.251576] rt2880-pinmux pinctrl: pcie is already enabled
[    1.262621] mt7621-pci 1e140000.pcie: host bridge /pcie@1e140000 ranges:
[    1.275994] mt7621-pci 1e140000.pcie:   No bus range found for /pcie@1e140000, using [bus 00-ff]
[    1.293522] mt7621-pci 1e140000.pcie:      MEM 0x0060000000..0x006fffffff -> 0x0000000000
[    1.309835] mt7621-pci 1e140000.pcie:       IO 0x001e160000..0x001e16ffff -> 0x0000000000
[    1.326215] mt7621-pci-phy 1e149000.pcie-phy: PHY for 0xbe149000 (dual port = 1)
[    1.341375] mt7621-pci-phy 1e14a000.pcie-phy: PHY for 0xbe14a000 (dual port = 0)
[    1.356435] mt7621-pci 1e140000.pcie: failed to parse bus ranges property: -22
[    1.471143] mt7621-pci-phy 1e149000.pcie-phy: Xtal is 40MHz
[    1.482259] mt7621-pci-phy 1e14a000.pcie-phy: Xtal is 40MHz
[    1.593582] mt7621-pci 1e140000.pcie: pcie1 no card, disable it (RST & CLK)
[    1.607449] mt7621-pci 1e140000.pcie: pcie2 no card, disable it (RST & CLK)
[    1.621329] mt7621-pci 1e140000.pcie: PCIE0 enabled
[    1.631052] mt7621-pci 1e140000.pcie: PCI coherence region base: 0x60000000, mask/settings: 0xf0000002
[    1.649769] mt7621-pci 1e140000.pcie: PCI host bridge to bus 0000:00
[    1.662483] pci_bus 0000:00: root bus resource [io  0x1e160000-0x1e16ffff]
[    1.676194] pci_bus 0000:00: root bus resource [mem 0x60000000-0x6fffffff]
[    1.689891] pci_bus 0000:00: root bus resource [bus 00-ff]
[    1.700828] pci_bus 0000:00: root bus resource [mem 0x60000000-0x6fffffff] (bus address [0x00000000-0x0fffffff])
[    1.721146] pci 0000:00:00.0: [0e8d:0801] type 01 class 0x060400
[    1.733143] pci 0000:00:00.0: reg 0x10: [mem 0x00000000-0x7fffffff]
[    1.745635] pci 0000:00:00.0: reg 0x14: initial BAR value 0x00000000 invalid
[    1.759673] pci 0000:00:00.0: reg 0x14: [mem size 0x00010000]
[    1.771191] pci 0000:00:00.0: supports D1
[    1.779180] pci 0000:00:00.0: PME# supported from D0 D1 D3hot
[    1.792180] pci 0000:00:00.0: bridge configuration invalid ([bus 00-00]), reconfiguring
[    1.808437] pci 0000:01:00.0: [14c3:7615] type 00 class 0x000280
[    1.820472] pci 0000:01:00.0: reg 0x10: initial BAR value 0x00000000 invalid
[    1.834529] pci 0000:01:00.0: reg 0x10: [mem size 0x00100000 64bit]
[    1.847183] pci 0000:01:00.0: 2.000 Gb/s available PCIe bandwidth, limited by 2.5 GT/s PCIe x1 link at 0000:00:00.0 (capable of 4.000 Gb/s with 5.0 GT/s PCIe x1 link)
[    1.878281] pci 0000:00:00.0: PCI bridge to [bus 01-ff]
[    1.888721] pci 0000:00:00.0:   bridge window [io  0x0000-0x0fff]
[    1.900863] pci 0000:00:00.0:   bridge window [mem 0x60000000-0x600fffff]
[    1.914391] pci 0000:00:00.0:   bridge window [mem 0x60000000-0x600fffff pref]
[    1.928788] pci_bus 0000:01: busn_res: [bus 01-ff] end is updated to 01
[    1.942011] pci 0000:00:00.0: BAR 0: no space for [mem size 0x80000000]
[    1.955193] pci 0000:00:00.0: BAR 0: failed to assign [mem size 0x80000000]
[    1.969070] pci 0000:00:00.0: BAR 8: assigned [mem 0x60000000-0x600fffff]
[    1.982599] pci 0000:00:00.0: BAR 9: assigned [mem 0x60100000-0x601fffff pref]
[    1.997000] pci 0000:00:00.0: BAR 1: assigned [mem 0x60200000-0x6020ffff]
[    2.010530] pci 0000:00:00.0: BAR 7: assigned [io  0x1e160000-0x1e160fff]
[    2.024065] pci 0000:01:00.0: BAR 0: assigned [mem 0x60000000-0x600fffff 64bit]
[    2.038640] pci 0000:00:00.0: PCI bridge to [bus 01]
[    2.048533] pci 0000:00:00.0:   bridge window [io  0x1e160000-0x1e160fff]
[    2.062068] pci 0000:00:00.0:   bridge window [mem 0x60000000-0x600fffff]
[    2.075594] pci 0000:00:00.0:   bridge window [mem 0x60100000-0x601fffff pref]
[    2.097340] VFS: Mounted root (squashfs filesystem) readonly on device 31:5.
[    2.115529] Freeing unused kernel memory: 1244K
[    2.124617] This architecture does not have kernel memory protection.
[    2.137464] Run /sbin/init as init process
[    2.146278] mt7530 mdio-bus:1f: Link is Up - 1Gbps/Full - flow control rx/tx
[    2.169180] Run /etc/init as init process
[    2.181336] Run /bin/init as init process
[    2.191691] Run /bin/sh as init process


BusyBox v1.35.0 (2022-04-20 10:37:37 UTC) built-in shell (ash)

/bin/sh: can't access tty; job control turned off
/ # 
[   59.622595] random: crng init done

Anyone can do that, but it needs to work and be accurate. Basically none of these device additions (with very few exceptions) are submitted by the vendor, by far most are contributed by occassional contributors, tinkering on their devices, working to get OpenWrt supported.

While flash/ RAM sizes are the most important aspects, there is more to take care of (LEDs, GPIOs, switch setup, MAC addresses, image recipes, ideally factory images, etc. pp.) - look at the commits adding support for similar devices about what this usually entails.

2 Likes

From your log the mtd definitions are incorrect.

Compare this log to stock and it should give an idea of what’s wrong.

Importantly! Only boot from initramfs images until you get this right! If the definitions are incorrect and the image is flashed you risk over writing wifi calibration data and basically bricking the wireless controllers

3 Likes

ok, i'll be careful. Maybe i need more help, i can't find out where is wrong. here is the stock boot log and my dts file about spi and pcie section.

stock boot log:

[    2.208000] flash manufacture id: ef, device id 40 17
[    2.216000] W25Q64BV(ef 40170000) (8192 Kbytes)
[    2.224000] mtd .name = raspi, .size = 0x00800000 (8M) .erasesize = 0x00010000 (64K) .numeraseregions = 0
[    2.244000] Creating 5 MTD partitions on "raspi":
[    2.256000] 0x000000000000-0x000000800000 : "ALL"
[    2.264000] 0x000000000000-0x000000030000 : "Bootloader"
[    2.276000] 0x000000030000-0x000000040000 : "Config"
[    2.288000] 0x000000040000-0x000000050000 : "Factory"
[    2.300000] 0x000000050000-0x000000800000 : "firmware"
[    2.308000] 0x00000034cd45-0x000000800000 : "rootfs"
[    2.320000] mtd: partition "rootfs" must either start or end on erase block boundary or be smaller than an erase block -- forcing read-only
[    2.344000] mtd: partition "rootfs_data" created automatically, ofs=0x5d0000, len=0x230000
[    2.364000] 0x0000005d0000-0x000000800000 : "rootfs_data"
[    2.376000] register mt_drv
[    2.400000] 
[    2.400000] == pAd = c0181000, size = 7714048, Status=0 ==
[    2.416000] pAd->PciHif.CSRBaseAddress =0xc0080000, csr_addr=0xc0080000!
[    2.428000] RTMPInitPCIeDevice():device_id=0x7615
[    2.436000] mt_pci_chip_cfg(): HWVer=0x8a10, FWVer=0x8a10, pAd->ChipID=0x7615
[    2.452000] mt_pci_chip_cfg(): HIF_SYS_REV=0x76150001
[    2.460000] AP Driver version-5.0.4.0
[    2.468000] RtmpChipOpsHook(223): Not support for HIF_MT yet! MACVersion=0x0
[    2.484000] mt7615_init()-->
[    2.488000] Use the default ePAeLNA bin image!
[    2.496000] Use the default /etc_ro/wlan/MT7615E_EEPROM1.bin bin image!
[    2.512000] <--mt7615_init()
[    2.520000] <-- RTMPAllocTxRxRingMemory, Status=0
[    2.532000] GMAC1_MAC_ADRH -- : 0x0000000c
[    2.540000] GMAC1_MAC_ADRL -- : 0x432880b1
[    2.548000] Ralink APSoC Ethernet Driver Initilization. v3.1  1024 rx/tx descriptors allocated, mtu = 1500!
[    2.568000] GMAC1_MAC_ADRH -- : 0x0000000c
[    2.576000] GMAC1_MAC_ADRL -- : 0x432880c9
[    2.584000] PROC INIT OK!
[    2.588000] i2c /dev entries driver
[    2.596000] nf_conntrack version 0.5.0 (1896 buckets, 7584 max)

my dts file about spi section:

 &spi0 {
         status = "okay";
 
         flash@0 {
                 compatible = "jedec,spi-nor";
                 reg = <0>;
                 spi-max-frequency = <80000000>;
                 m25p,fast-read;
 
                 partitions {
                         compatible = "fixed-partitions";
                         #address-cells = <1>;
                         #size-cells = <1>;
 
                         partition@0 {
                                 label = "Bootloader";
                                 reg = <0x0 0x30000>;
                                 read-only;
                         };
 
                         partition@30000 {
                                 label = "Config";
                                 reg = <0x30000 0x10000>;
                                 read-only;
                         };
 
                         /* range 0x40000 to 0x50000 is empty in vendor
                          * firmware, so we do not use it either
                          */

                         factory: partition@40000 {
                                 label = "Factory";
                                 reg = <0x40000 0x10000>;
                                 read-only;
                         };
 
                         partition@50000 {
                                 compatible = "denx,uimage";
                                 label = "firmware";
                                 reg = <0x50000 0x7B0000>;
                         };

                 };
         };
 };
 
 &pcie {
         status = "okay";
 };
 
 &pcie0 {
         wifi@0,0 {
                 compatible = "mediatek,mt76";
                 reg = <0x0000 0 0 0 0>;
                 mediatek,mtd-eeprom = <&factory 0x0>;
         };
 };