Create a non erasable and writable partition on flash memory

Hello guys, i have a ZBT-WE1326 router with MT7621 cpu and 16MB of flash. I want to create another partition (512kb) on the flash apart from (u-boot, u-boot env, factory, firmware). The highlighting feature about this partition is that it should be mountable for reading and writing to text files. I want to store some text in a text file in that mounted partition. Also the data stored on it should not erased on firstboot. So far i am able to create that partition successfully by modifying its dts file . It's mountable and i can create a text file and store some text on that file too. I have derived some space from rootfs_data partition and i mount the partition as jffs2. So its obvious that after firstboot my partition which is sharing some space from rootfs_data is also getting erased. But the partition gets erased after performing a firstboot which i don't intend. Can anyone help me achieve the same?

1 Like

Have you got a link to github so we can see what you have done so far?

yes here is my bootlog

Starting kernel ...

[    0.000000] Linux version 4.14.71 (pratik@ubuntu) (gcc version 7.3.0 (OpenWrt                                                                                                                                         GCC 7.3.0 r8122-4f277eb)) #0 SMP Mon Sep 24 06:36:10 2018
[    0.000000] SoC Type: MediaTek MT7621 ver:1 eco:3
[    0.000000] bootconsole [early0] enabled
[    0.000000] CPU0 revision is: 0001992f (MIPS 1004Kc)
[    0.000000] MIPS: machine is ZBT-WE1326
[    0.000000] Determined physical RAM map:
[    0.000000]  memory: 1c000000 @ 00000000 (usable)
[    0.000000]  memory: 04000000 @ 20000000 (usable)
[    0.000000] Initrd not found or empty - disabling initrd
[    0.000000] VPE topology {2,2} total 4
[    0.000000] Primary instruction cache 32kB, VIPT, 4-way, linesize 32 bytes.
[    0.000000] Primary data cache 32kB, 4-way, PIPT, no aliases, linesize 32 byt                                                                                                                                        es
[    0.000000] MIPS secondary cache 256kB, 8-way, linesize 32 bytes.
[    0.000000] Zone ranges:
[    0.000000]   Normal   [mem 0x0000000000000000-0x000000000fffffff]
[    0.000000]   HighMem  [mem 0x0000000010000000-0x0000000023ffffff]
[    0.000000] Movable zone start for each node
[    0.000000] Early memory node ranges
[    0.000000]   node   0: [mem 0x0000000000000000-0x000000001bffffff]
[    0.000000]   node   0: [mem 0x0000000020000000-0x0000000023ffffff]
[    0.000000] Initmem setup node 0 [mem 0x0000000000000000-0x0000000023ffffff]
[    0.000000] random: get_random_bytes called from start_kernel+0x90/0x4a4 with                                                                                                                                         crng_init=0
[    0.000000] percpu: Embedded 14 pages/cpu @8148f000 s26192 r8192 d22960 u5734                                                                                                                                        4
[    0.000000] Built 1 zonelists, mobility grouping on.  Total pages: 130560
[    0.000000] Kernel command line: console=ttyS0,115200 rootfstype=squashfs,jff                                                                                                                                        s2
[    0.000000] PID hash table entries: 1024 (order: 0, 4096 bytes)
[    0.000000] Dentry cache hash table entries: 32768 (order: 5, 131072 bytes)
[    0.000000] Inode-cache hash table entries: 16384 (order: 4, 65536 bytes)
[    0.000000] Writing ErrCtl register=00010860
[    0.000000] Readback ErrCtl register=00010860
[    0.000000] Memory: 512988K/524288K available (4426K kernel code, 233K rwdata                                                                                                                                        , 988K rodata, 228K init, 276K bss, 11300K reserved, 0K cma-reserved, 262144K hi                                                                                                                                        ghmem)
[    0.000000] SLUB: HWalign=32, Order=0-3, MinObjects=0, CPUs=4, Nodes=1
[    0.000000] Hierarchical RCU implementation.
[    0.000000] NR_IRQS: 256
[    0.000000] clocksource: GIC: mask: 0xffffffffffffffff max_cycles: 0xcaf478ab                                                                                                                                        b4, max_idle_ns: 440795247997 ns
[    0.000000] clocksource: MIPS: mask: 0xffffffff max_cycles: 0xffffffff, max_i                                                                                                                                        dle_ns: 4343773742 ns
[    0.000010] sched_clock: 32 bits at 440MHz, resolution 2ns, wraps every 48806                                                                                                                                        45118ns
[    0.007819] Calibrating delay loop... 586.13 BogoMIPS (lpj=2930688)
[    0.073975] pid_max: default: 32768 minimum: 301
[    0.078746] Mount-cache hash table entries: 1024 (order: 0, 4096 bytes)
[    0.085254] Mountpoint-cache hash table entries: 1024 (order: 0, 4096 bytes)
[    0.094087] Hierarchical SRCU implementation.
[    0.099240] smp: Bringing up secondary CPUs ...
[    0.105286] Primary instruction cache 32kB, VIPT, 4-way, linesize 32 bytes.
[    0.105297] Primary data cache 32kB, 4-way, PIPT, no aliases, linesize 32 byt                                                                                                                                        es
[    0.105310] MIPS secondary cache 256kB, 8-way, linesize 32 bytes.
[    0.105456] CPU1 revision is: 0001992f (MIPS 1004Kc)
[    0.163978] Synchronize counters for CPU 1: done.
[    0.205163] Primary instruction cache 32kB, VIPT, 4-way, linesize 32 bytes.
[    0.205172] Primary data cache 32kB, 4-way, PIPT, no aliases, linesize 32 byt                                                                                                                                        es
[    0.205182] MIPS secondary cache 256kB, 8-way, linesize 32 bytes.
[    0.205255] CPU2 revision is: 0001992f (MIPS 1004Kc)
[    0.255024] Synchronize counters for CPU 2: done.
[    0.286317] Primary instruction cache 32kB, VIPT, 4-way, linesize 32 bytes.
[    0.286324] Primary data cache 32kB, 4-way, PIPT, no aliases, linesize 32 byt                                                                                                                                        es
[    0.286332] MIPS secondary cache 256kB, 8-way, linesize 32 bytes.
[    0.286413] CPU3 revision is: 0001992f (MIPS 1004Kc)
[    0.340209] Synchronize counters for CPU 3: done.
[    0.370075] smp: Brought up 1 node, 4 CPUs
[    0.377646] clocksource: jiffies: mask: 0xffffffff max_cycles: 0xffffffff, ma                                                                                                                                        x_idle_ns: 19112604462750000 ns
[    0.387440] futex hash table entries: 1024 (order: 3, 32768 bytes)
[    0.393761] pinctrl core: initialized pinctrl subsystem
[    0.400368] NET: Registered protocol family 16
[    0.414776] pull PCIe RST: RALINK_RSTCTRL = 0
[    0.719473] release PCIe RST: RALINK_RSTCTRL = 7000000
[    0.724521] ***** Xtal 40MHz *****
[    0.727877] release PCIe RST: RALINK_RSTCTRL = 7000000
[    0.732975] Port 0 N_FTS = 1b102800
[    0.736442] Port 1 N_FTS = 1b102800
[    0.739889] Port 2 N_FTS = 1b102800
[    1.894980] PCIE0 no card, disable it(RST&CLK)
[    1.899340]  -> 10207f2
[    1.901745] PCIE1 enabled
[    1.904332] PCIE2 enabled
[    1.906937] PCI host bridge /pcie@1e140000 ranges:
[    1.911710]  MEM 0x0000000060000000..0x000000006fffffff
[    1.916865]   IO 0x000000001e160000..0x000000001e16ffff
[    1.922070] PCI coherence region base: 0xbfbf8000, mask/settings: 0x60000000
[    1.938699] mt7621_gpio 1e000600.gpio: registering 32 gpios
[    1.944581] mt7621_gpio 1e000600.gpio: registering 32 gpios
[    1.950341] mt7621_gpio 1e000600.gpio: registering 32 gpios
[    1.957649] PCI host bridge to bus 0000:00
[    1.961684] pci_bus 0000:00: root bus resource [mem 0x60000000-0x6fffffff]
[    1.968539] pci_bus 0000:00: root bus resource [io  0xffffffff]
[    1.974370] pci_bus 0000:00: root bus resource [??? 0x00000000 flags 0x0]
[    1.981128] pci_bus 0000:00: No busn resource found for root bus, will use [b                                                                                                                                        us 00-ff]
[    1.989818] pci 0000:00:00.0: bridge configuration invalid ([bus 00-00]), rec                                                                                                                                        onfiguring
[    1.997748] pci 0000:00:01.0: bridge configuration invalid ([bus 00-00]), rec                                                                                                                                        onfiguring
[    2.007014] pci 0000:00:00.0: BAR 0: no space for [mem size 0x80000000]
[    2.013563] pci 0000:00:00.0: BAR 0: failed to assign [mem size 0x80000000]
[    2.020439] pci 0000:00:01.0: BAR 0: no space for [mem size 0x80000000]
[    2.027020] pci 0000:00:01.0: BAR 0: failed to assign [mem size 0x80000000]
[    2.033922] pci 0000:00:00.0: BAR 8: assigned [mem 0x60000000-0x600fffff]
[    2.040679] pci 0000:00:00.0: BAR 9: assigned [mem 0x60100000-0x601fffff pref                                                                                                                                        ]
[    2.047831] pci 0000:00:01.0: BAR 8: assigned [mem 0x60200000-0x602fffff]
[    2.054583] pci 0000:00:00.0: BAR 1: assigned [mem 0x60300000-0x6030ffff]
[    2.061308] pci 0000:00:01.0: BAR 1: assigned [mem 0x60310000-0x6031ffff]
[    2.068077] pci 0000:01:00.0: BAR 0: assigned [mem 0x60000000-0x600fffff 64bi                                                                                                                                        t]
[    2.075318] pci 0000:01:00.0: BAR 6: assigned [mem 0x60100000-0x6010ffff pref                                                                                                                                        ]
[    2.082495] pci 0000:00:00.0: PCI bridge to [bus 01]
[    2.087402] pci 0000:00:00.0:   bridge window [mem 0x60000000-0x600fffff]
[    2.094152] pci 0000:00:00.0:   bridge window [mem 0x60100000-0x601fffff pref                                                                                                                                        ]
[    2.101313] pci 0000:02:00.0: BAR 0: assigned [mem 0x60200000-0x602fffff]
[    2.108067] pci 0000:00:01.0: PCI bridge to [bus 02]
[    2.112970] pci 0000:00:01.0:   bridge window [mem 0x60200000-0x602fffff]
[    2.121243] clocksource: Switched to clocksource GIC
[    2.127745] NET: Registered protocol family 2
[    2.132788] TCP established hash table entries: 2048 (order: 1, 8192 bytes)
[    2.139673] TCP bind hash table entries: 2048 (order: 2, 16384 bytes)
[    2.146119] TCP: Hash tables configured (established 2048 bind 2048)
[    2.152539] UDP hash table entries: 256 (order: 1, 8192 bytes)
[    2.158307] UDP-Lite hash table entries: 256 (order: 1, 8192 bytes)
[    2.164803] NET: Registered protocol family 1
[    2.401181] 4 CPUs re-calibrate udelay(lpj = 2924544)
[    2.407739] Crashlog allocated RAM at address 0x3f00000
[    2.413082] workingset: timestamp_bits=30 max_order=17 bucket_order=0
[    2.425903] squashfs: version 4.0 (2009/01/31) Phillip Lougher
[    2.431674] jffs2: version 2.2 (NAND) (SUMMARY) (LZMA) (RTIME) (CMODE_PRIORIT                                                                                                                                        Y) (c) 2001-2006 Red Hat, Inc.
[    2.442933] random: fast init done
[    2.448103] bounce: pool size: 64 pages
[    2.452012] io scheduler noop registered
[    2.455837] io scheduler deadline registered (default)
[    2.461949] Serial: 8250/16550 driver, 3 ports, IRQ sharing disabled
[    2.469581] console [ttyS0] disabled
[    2.473281] 1e000c00.uartlite: ttyS0 at MMIO 0x1e000c00 (irq = 18, base_baud                                                                                                                                         = 3125000) is a 16550A
[    2.482272] console [ttyS0] enabled
[    2.482272] console [ttyS0] enabled
[    2.489125] bootconsole [early0] disabled
[    2.489125] bootconsole [early0] disabled
[    2.497796] cacheinfo: Unable to detect cache hierarchy for CPU 0
[    2.504724] MediaTek Nand driver init, version v2.1 Fix AHB virt2phys error
[    2.512131] spi-mt7621 1e000b00.spi: sys_freq: 50000000
[    2.528440] m25p80 spi0.0: w25q128 (16384 Kbytes)
[    2.533222] 5 fixed-partitions partitions found on MTD device spi0.0
[    2.539543] Creating 5 MTD partitions on "spi0.0":
[    2.544343] 0x000000000000-0x000000030000 : "u-boot"
[    2.550450] 0x000000030000-0x000000040000 : "u-boot-env"
[    2.556873] 0x000000040000-0x000000050000 : "factory"
[    2.563032] 0x000000050000-0x000001000000 : "firmware"
[    2.606774] 2 uimage-fw partitions found on MTD device firmware
[    2.612723] 0x000000050000-0x00000021b31c : "kernel"
[    2.618779] 0x00000021b31c-0x000001000000 : "rootfs"
[    2.624835] mtd: device 5 (rootfs) set to be root filesystem
[    2.630595] 1 squashfs-split partitions found on MTD device rootfs
[    2.636802] 0x000000440000-0x000001000000 : "rootfs_data"
[    2.643278] 0x000000fb0000-0x000001000000 : "sim"
[    2.649781] libphy: Fixed MDIO Bus: probed
[    2.723242] libphy: mdio: probed
[    4.126114] mtk_soc_eth 1e100000.ethernet: loaded mt7530 driver
[    4.132823] mtk_soc_eth 1e100000.ethernet eth0: mediatek frame engine at 0xbe                                                                                                                                        100000, irq 21
[    4.143753] NET: Registered protocol family 10
[    4.149608] Segment Routing with IPv6
[    4.153407] NET: Registered protocol family 17
[    4.157885] 8021q: 802.1Q VLAN Support v1.8
[    4.164702] hctosys: unable to open rtc device (rtc0)
[    4.176057] VFS: Mounted root (squashfs filesystem) readonly on device 31:5.
[    4.183664] Freeing unused kernel memory: 228K
[    4.188097] This architecture does not have kernel memory protection.
[    4.336808] mtk_soc_eth 1e100000.ethernet eth0: port 4 link up
[    4.365597] mtk_soc_eth 1e100000.ethernet eth0: port 0 link up
[    4.545762] random: crng init done
[    4.713303] init: Console is alive
[    4.716940] init: - watchdog -
[    5.569329] kmodloader: loading kernel modules from /etc/modules-boot.d/*
[    5.681411] usbcore: registered new interface driver usbfs
[    5.686984] usbcore: registered new interface driver hub
[    5.692454] usbcore: registered new device driver usb
[    5.707595] xhci-mtk 1e1c0000.xhci: 1e1c0000.xhci supply vbus not found, usin                                                                                                                                        g dummy regulator
[    5.716329] xhci-mtk 1e1c0000.xhci: 1e1c0000.xhci supply vusb33 not found, us                                                                                                                                        ing dummy regulator
[    5.725316] xhci-mtk 1e1c0000.xhci: xHCI Host Controller
[    5.730637] xhci-mtk 1e1c0000.xhci: new USB bus registered, assigned bus numb                                                                                                                                        er 1
[    5.741390] xhci-mtk 1e1c0000.xhci: hcc params 0x01401198 hci version 0x96 qu                                                                                                                                        irks 0x00210010
[    5.749871] xhci-mtk 1e1c0000.xhci: irq 20, io mem 0x1e1c0000
[    5.756691] hub 1-0:1.0: USB hub found
[    5.760535] hub 1-0:1.0: 2 ports detected
[    5.765269] xhci-mtk 1e1c0000.xhci: xHCI Host Controller
[    5.770591] xhci-mtk 1e1c0000.xhci: new USB bus registered, assigned bus numb                                                                                                                                        er 2
[    5.778106] xhci-mtk 1e1c0000.xhci: Host supports USB 3.0  SuperSpeed
[    5.784738] usb usb2: We don't know the algorithms for LPM for this host, dis                                                                                                                                        abling LPM.
[    5.793733] hub 2-0:1.0: USB hub found
[    5.797549] hub 2-0:1.0: 1 port detected
[    5.864710] kmodloader: done loading kernel modules from /etc/modules-boot.d/                                                                                                                                        *
[    5.891543] init: - preinit -
[    6.696769] mtk_soc_eth 1e100000.ethernet: PPE started
Press the [f] key and hit [enter] to enter failsafe mode
Press the [1], [2], [3] or [4] key and hit [enter] to select the debug level
▒[    9.930745] jffs2: notice: (446) jffs2_build_xattr_subsystem: complete building xattr subsystem, 1 of xdatum (0 unchecked, 1 orphan) and 1 of xref (1 dead, 0 orphan) found.
[    9.947977] mount_root: switching to jffs2 overlay
[    9.970081] overlayfs: upper fs does not support tmpfile.
[    9.980776] urandom-seed: Seeding with /etc/urandom.seed
[   10.068173] mtk_soc_eth 1e100000.ethernet: 0x100 = 0x6060000c, 0x10c = 0x80818
[   10.083268] procd: - early -
[   10.086250] procd: - watchdog -
[   10.781401] procd: - watchdog -
[   10.784864] procd: - ubus -
[   10.843345] procd: - init -
Please press Enter to activate this console.
▒[   11.132166] kmodloader: loading kernel modules from /etc/modules.d/*
[   11.142595] ip6_tables: (C) 2000-2006 Netfilter Core Team
[   11.155964] Loading modules backported from Linux version wt-2017-11-01-0-gfe248fc2c180
[   11.164079] Backport generated by backports.git v4.14-rc2-1-31-g86cf0e5d
[   11.172792] ip_tables: (C) 2000-2006 Netfilter Core Team
[   11.185072] nf_conntrack version 0.5.0 (8192 buckets, 32768 max)
[   11.228619] xt_time: kernel timezone is -0000
[   11.294002] bus=0x1, slot = 0x0, irq=0xff
[   11.298055] PCI: Enabling device 0000:00:00.0 (0004 -> 0006)
[   11.303951] mt76x2e 0000:01:00.0: ASIC revision: 76120044
[   11.335356] mt76x2e 0000:01:00.0: ROM patch build: 20141115060606a
[   11.341273] usb 1-2: new high-speed USB device number 2 using xhci-mtk
[   11.351876] mt76x2e 0000:01:00.0: Firmware Version: 0.0.00
[   11.357357] mt76x2e 0000:01:00.0: Build: 1
[   11.361455] mt76x2e 0000:01:00.0: Build Time: 201507311614____
[   11.381309] mt76x2e 0000:01:00.0: Firmware running!
[   11.396980] PPP generic driver version 2.4.2
[   11.402809] NET: Registered protocol family 24
[   11.410370] kmodloader: done loading kernel modules from /etc/modules.d/*

and here is my device tree file content

/dts-v1/;

#include "mt7621.dtsi"

#include <dt-bindings/gpio/gpio.h>
#include <dt-bindings/input/input.h>

/ {
	compatible = "zbtlink,zbt-we1326", "mediatek,mt7621-soc";
	model = "ZBT-WE1326";

	chosen {
		bootargs = "console=ttyS0,115200";
	};

	memory@0 {
		device_type = "memory";
		reg = <0x0 0x1c000000>, <0x20000000 0x4000000>;
	};

	gpio-keys-polled {
		compatible = "gpio-keys-polled";
		poll-interval = <20>;

		reset {
			label = "reset";
			gpios = <&gpio0 18 GPIO_ACTIVE_LOW>;
			linux,code = <KEY_RESTART>;
		};
	};
};

&pinctrl {
	state_default: pinctrl0 {
		gpio {
			ralink,group = "wdt";
			ralink,function = "gpio";
		};
	};
};

&spi0 {
	status = "okay";

	m25p80@0 {
		compatible = "jedec,spi-nor";
		reg = <0>;
		spi-max-frequency = <10000000>;
		m25p,chunked-io = <32>;

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

			partition@0 {
				label = "u-boot";
				reg = <0x0 0x30000>;
				read-only;
			
			};

			partition@30000 {
				label = "u-boot-env";
				reg = <0x30000 0x10000>;
				read-only;
				
			};		 


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

			partition@50000 {
				label = "firmware";
				reg = <0x50000 0xfb0000>;
			};


			partition@60000 {
				label = "sim";
				reg = <0xfb0000 0x50000>;
		
			};

		};

	};

};

&ethernet {
	mtd-mac-address = <&factory 0xe000>;
};

&pcie {
	status = "okay";
};

&pcie0 {
	mt76@0,0 {
		reg = <0x0000 0 0 0 0>;
		mediatek,mtd-eeprom = <&factory 0x8000>;
		ieee80211-freq-limit = <5000000 6000000>;
	};
};

&pcie1 {
	mt76@0,0 {
		reg = <0x0000 0 0 0 0>;
		mediatek,mtd-eeprom = <&factory 0x0000>;
		ieee80211-freq-limit = <2400000 2500000>;
	};
};

&sdhci {
	status = "okay";
};

The issue is that you need to reduce the size of the firmware partition and fix the definition of the sim partition.

Try this:

/dts-v1/;

#include "mt7621.dtsi"

#include <dt-bindings/gpio/gpio.h>
#include <dt-bindings/input/input.h>

/ {
	compatible = "zbtlink,zbt-we1326", "mediatek,mt7621-soc";
	model = "ZBT-WE1326";

	chosen {
		bootargs = "console=ttyS0,115200";
	};

	memory@0 {
		device_type = "memory";
		reg = <0x0 0x1c000000>, <0x20000000 0x4000000>;
	};

	gpio-keys-polled {
		compatible = "gpio-keys-polled";
		poll-interval = <20>;

		reset {
			label = "reset";
			gpios = <&gpio0 18 GPIO_ACTIVE_LOW>;
			linux,code = <KEY_RESTART>;
		};
	};
};

&pinctrl {
	state_default: pinctrl0 {
		gpio {
			ralink,group = "wdt";
			ralink,function = "gpio";
		};
	};
};

&spi0 {
	status = "okay";

	m25p80@0 {
		compatible = "jedec,spi-nor";
		reg = <0>;
		spi-max-frequency = <10000000>;
		m25p,chunked-io = <32>;

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

			partition@0 {
				label = "u-boot";
				reg = <0x0 0x30000>;
				read-only;
			
			};

			partition@30000 {
				label = "u-boot-env";
				reg = <0x30000 0x10000>;
				read-only;
				
			};		 


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

			partition@50000 {
				label = "firmware";
				reg = <0x50000 0xf60000>;
			};


			partition@fb0000 {
				label = "sim";
				reg = <0xfb0000 0x50000>;
		
			};

		};

	};

};

&ethernet {
	mtd-mac-address = <&factory 0xe000>;
};

&pcie {
	status = "okay";
};

&pcie0 {
	mt76@0,0 {
		reg = <0x0000 0 0 0 0>;
		mediatek,mtd-eeprom = <&factory 0x8000>;
		ieee80211-freq-limit = <5000000 6000000>;
	};
};

&pcie1 {
	mt76@0,0 {
		reg = <0x0000 0 0 0 0>;
		mediatek,mtd-eeprom = <&factory 0x0000>;
		ieee80211-freq-limit = <2400000 2500000>;
	};
};

&sdhci {
	status = "okay";
};

You may also need to adjust your targets makefile.

Can you be specific what Makefile needs to be adjusted? also with the DTS you provided, i have added the screenshots of what i am getting. The "sim" partition is getting formed on /dev/mtdblock7. It's mountable and after mounting it i can see two directories - upper and work. The partition still gets erased after firstboot!sim sim1

0xfb0000 is equal to 16MB (16449536). How big is your flash? If it is only 16MB you'll need to adjust it so your final partition starts and ends before 0xfb0000.

How are you reading the SIM data? I want to do this, virtualize some SIM cards onto their own partitions and use software to switch SIMs instead of using hardware GPIO.

So far i have modified my DTS source like this :-

/dts-v1/;

#include "mt7621.dtsi"

#include <dt-bindings/gpio/gpio.h>
#include <dt-bindings/input/input.h>

/ {
	compatible = "zbtlink,zbt-we1326", "mediatek,mt7621-soc";
	model = "ZBT-WE1326";

	chosen {
		bootargs = "console=ttyS0,115200";
	};

	memory@0 {
		device_type = "memory";
		reg = <0x0 0x1c000000>, <0x20000000 0x4000000>;
	};

	gpio-keys-polled {
		compatible = "gpio-keys-polled";
		poll-interval = <20>;

		reset {
			label = "reset";
			gpios = <&gpio0 18 GPIO_ACTIVE_LOW>;
			linux,code = <KEY_RESTART>;
		};
	};
};

&pinctrl {
	state_default: pinctrl0 {
		gpio {
			ralink,group = "wdt";
			ralink,function = "gpio";
		};
	};
};

&spi0 {
	status = "okay";

	m25p80@0 {
		compatible = "jedec,spi-nor";
		reg = <0>;
		spi-max-frequency = <10000000>;
		m25p,chunked-io = <32>;

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

			partition@0 {
				label = "u-boot";
				reg = <0x0 0x30000>;
				read-only;
			};

			partition@30000 {
				label = "u-boot-env";
				reg = <0x30000 0x10000>;
				read-only;
			};

			factory: partition@40000 {
				label = "factory";
				reg = <0x40000 0x10000>;
				read-only;
			};
			
			partition@50000{
				label = "my_partition";
				reg = <0x50000 0x50000>;
						
			};

			partition@a0000 {
				compatible = "denx,uimage";
				label = "firmware";
				reg = <0xa0000 0xf60000>;
			};
				
		};
	};
};

&ethernet {
	mtd-mac-address = <&factory 0xe000>;
};

&pcie {
	status = "okay";
};

&pcie0 {
	mt76@0,0 {
		reg = <0x0000 0 0 0 0>;
		mediatek,mtd-eeprom = <&factory 0x8000>;
		ieee80211-freq-limit = <5000000 6000000>;
	};
};

&pcie1 {
	mt76@0,0 {
		reg = <0x0000 0 0 0 0>;
		mediatek,mtd-eeprom = <&factory 0x0000>;
		ieee80211-freq-limit = <2400000 2500000>;
	};
};

&sdhci {
	status = "okay";
};

So instead of creating a partition after "firmware/rootfs_data" partition, i added it after the "factory" partition (my_partition) of 320kb and re-arranged the reg values of the firmware partition to 16mb of flash. Now, i can see my_partition in the bootlogs appearing just after the factory partition as intended. But as expected, it is causing a kernel panic as the kernel/firmware partition's address has changed due to addition of my partition between factory and firmware partitions, So it can't find the root filesystem to mount now. So how do i make the build system know the new address of kernel? Apart from DTS what more sources need to be changed? Here is the current bootlog :-

Press Reset button enter upgrade mode!
## Booting image at bc050000 ...
   Image Name:   MIPS OpenWrt Linux-4.14.88
   Image Type:   MIPS Linux Kernel Image (lzma compressed)
   Data Size:    1896099 Bytes =  1.8 MB
   Load Address: 80001000
   Entry Point:  80001000
   Verifying Checksum ... OK
   Uncompressing Kernel Image ... OK
No initrd
## Transferring control to Linux (at address 80001000) ...
## Giving linux memsize in MB, 512

Starting kernel ...

[    0.000000] Linux version 4.14.88 (pratik@ubuntu) (gcc version 7.4.0 (OpenWrt GCC 7.4.0 r8810-09004e6)) #0 SMP Mon Dec 17 22:21:40 2018
[    0.000000] SoC Type: MediaTek MT7621 ver:1 eco:3
[    0.000000] bootconsole [early0] enabled
[    0.000000] CPU0 revision is: 0001992f (MIPS 1004Kc)
[    0.000000] MIPS: machine is ZBT-WE1326
[    0.000000] Determined physical RAM map:
[    0.000000]  memory: 1c000000 @ 00000000 (usable)
[    0.000000]  memory: 04000000 @ 20000000 (usable)
[    0.000000] Initrd not found or empty - disabling initrd
[    0.000000] VPE topology {2,2} total 4
[    0.000000] Primary instruction cache 32kB, VIPT, 4-way, linesize 32 bytes.
[    0.000000] Primary data cache 32kB, 4-way, PIPT, no aliases, linesize 32 bytes
[    0.000000] MIPS secondary cache 256kB, 8-way, linesize 32 bytes.
[    0.000000] Zone ranges:
[    0.000000]   Normal   [mem 0x0000000000000000-0x000000000fffffff]
[    0.000000]   HighMem  [mem 0x0000000010000000-0x0000000023ffffff]
[    0.000000] Movable zone start for each node
[    0.000000] Early memory node ranges
[    0.000000]   node   0: [mem 0x0000000000000000-0x000000001bffffff]
[    0.000000]   node   0: [mem 0x0000000020000000-0x0000000023ffffff]
[    0.000000] Initmem setup node 0 [mem 0x0000000000000000-0x0000000023ffffff]
[    0.000000] random: get_random_bytes called from start_kernel+0x90/0x4a4 with crng_init=0
[    0.000000] percpu: Embedded 14 pages/cpu @8148f000 s26192 r8192 d22960 u57344
[    0.000000] Built 1 zonelists, mobility grouping on.  Total pages: 130560
[    0.000000] Kernel command line: console=ttyS0,115200 rootfstype=squashfs,jffs2
[    0.000000] PID hash table entries: 1024 (order: 0, 4096 bytes)
[    0.000000] Dentry cache hash table entries: 32768 (order: 5, 131072 bytes)
[    0.000000] Inode-cache hash table entries: 16384 (order: 4, 65536 bytes)
[    0.000000] Writing ErrCtl register=00011060
[    0.000000] Readback ErrCtl register=00011060
[    0.000000] Memory: 512952K/524288K available (4470K kernel code, 229K rwdata, 996K rodata, 244K init, 248K bss, 11336K reserved, 0K cma-reserved, 262144K highmem)
[    0.000000] SLUB: HWalign=32, Order=0-3, MinObjects=0, CPUs=4, Nodes=1
[    0.000000] Hierarchical RCU implementation.
[    0.000000] NR_IRQS: 256
[    0.000000] CPU Clock: 880MHz
[    0.000000] clocksource: GIC: mask: 0xffffffffffffffff max_cycles: 0xcaf478abb4, max_idle_ns: 440795247997 ns
[    0.000000] clocksource: MIPS: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 4343773742 ns
[    0.000010] sched_clock: 32 bits at 440MHz, resolution 2ns, wraps every 4880645118ns
[    0.007830] Calibrating delay loop... 586.13 BogoMIPS (lpj=2930688)
[    0.073992] pid_max: default: 32768 minimum: 301
[    0.078774] Mount-cache hash table entries: 1024 (order: 0, 4096 bytes)
[    0.085282] Mountpoint-cache hash table entries: 1024 (order: 0, 4096 bytes)
[    0.094248] Hierarchical SRCU implementation.
[    0.099458] smp: Bringing up secondary CPUs ...
[    0.105553] Primary instruction cache 32kB, VIPT, 4-way, linesize 32 bytes.
[    0.105562] Primary data cache 32kB, 4-way, PIPT, no aliases, linesize 32 bytes
[    0.105576] MIPS secondary cache 256kB, 8-way, linesize 32 bytes.
[    0.105725] CPU1 revision is: 0001992f (MIPS 1004Kc)
[    0.164244] Synchronize counters for CPU 1: done.
[    0.218448] Primary instruction cache 32kB, VIPT, 4-way, linesize 32 bytes.
[    0.218457] Primary data cache 32kB, 4-way, PIPT, no aliases, linesize 32 bytes
[    0.218467] MIPS secondary cache 256kB, 8-way, linesize 32 bytes.
[    0.218542] CPU2 revision is: 0001992f (MIPS 1004Kc)
[    0.255582] Synchronize counters for CPU 2: done.
[    0.286894] Primary instruction cache 32kB, VIPT, 4-way, linesize 32 bytes.
[    0.286901] Primary data cache 32kB, 4-way, PIPT, no aliases, linesize 32 bytes
[    0.286910] MIPS secondary cache 256kB, 8-way, linesize 32 bytes.
[    0.286990] CPU3 revision is: 0001992f (MIPS 1004Kc)
[    0.340764] Synchronize counters for CPU 3: done.
[    0.370626] smp: Brought up 1 node, 4 CPUs
[    0.378215] clocksource: jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 19112604462750000 ns
[    0.388012] futex hash table entries: 1024 (order: 3, 32768 bytes)
[    0.394332] pinctrl core: initialized pinctrl subsystem
[    0.401016] NET: Registered protocol family 16
[    0.416419] pull PCIe RST: RALINK_RSTCTRL = 0
[    0.721095] release PCIe RST: RALINK_RSTCTRL = 7000000
[    0.726143] ***** Xtal 40MHz *****
[    0.729499] release PCIe RST: RALINK_RSTCTRL = 7000000
[    0.734596] Port 0 N_FTS = 1b102800
[    0.738064] Port 1 N_FTS = 1b105000
[    0.741510] Port 2 N_FTS = 1b105000
[    1.896620] PCIE0 no card, disable it(RST&CLK)
[    1.900981]  -> 10207f2
[    1.903385] PCIE1 enabled
[    1.905973] PCIE2 enabled
[    1.908578] PCI host bridge /pcie@1e140000 ranges:
[    1.913354]  MEM 0x0000000060000000..0x000000006fffffff
[    1.918506]   IO 0x000000001e160000..0x000000001e16ffff
[    1.923709] PCI coherence region base: 0xbfbf8000, mask/settings: 0x60000000
[    1.939965] mt7621_gpio 1e000600.gpio: registering 32 gpios
[    1.945821] mt7621_gpio 1e000600.gpio: registering 32 gpios
[    1.951538] mt7621_gpio 1e000600.gpio: registering 32 gpios
[    1.958712] PCI host bridge to bus 0000:00
[    1.962755] pci_bus 0000:00: root bus resource [mem 0x60000000-0x6fffffff]
[    1.969580] pci_bus 0000:00: root bus resource [io  0xffffffff]
[    1.975434] pci_bus 0000:00: root bus resource [??? 0x00000000 flags 0x0]
[    1.982196] pci_bus 0000:00: No busn resource found for root bus, will use [bus 00-ff]
[    1.992030] pci 0000:00:00.0: BAR 0: no space for [mem size 0x80000000]
[    1.998563] pci 0000:00:00.0: BAR 0: failed to assign [mem size 0x80000000]
[    2.005463] pci 0000:00:01.0: BAR 0: no space for [mem size 0x80000000]
[    2.012037] pci 0000:00:01.0: BAR 0: failed to assign [mem size 0x80000000]
[    2.018938] pci 0000:00:00.0: BAR 8: assigned [mem 0x60000000-0x600fffff]
[    2.025693] pci 0000:00:00.0: BAR 9: assigned [mem 0x60100000-0x601fffff pref]
[    2.032842] pci 0000:00:01.0: BAR 8: assigned [mem 0x60200000-0x602fffff]
[    2.039598] pci 0000:00:00.0: BAR 1: assigned [mem 0x60300000-0x6030ffff]
[    2.046335] pci 0000:00:01.0: BAR 1: assigned [mem 0x60310000-0x6031ffff]
[    2.053090] pci 0000:01:00.0: BAR 0: assigned [mem 0x60000000-0x600fffff 64bit]
[    2.060334] pci 0000:01:00.0: BAR 6: assigned [mem 0x60100000-0x6010ffff pref]
[    2.067508] pci 0000:00:00.0: PCI bridge to [bus 01]
[    2.072416] pci 0000:00:00.0:   bridge window [mem 0x60000000-0x600fffff]
[    2.079168] pci 0000:00:00.0:   bridge window [mem 0x60100000-0x601fffff pref]
[    2.086337] pci 0000:02:00.0: BAR 0: assigned [mem 0x60200000-0x602fffff]
[    2.093084] pci 0000:00:01.0: PCI bridge to [bus 02]
[    2.097992] pci 0000:00:01.0:   bridge window [mem 0x60200000-0x602fffff]
[    2.106249] clocksource: Switched to clocksource GIC
[    2.112818] NET: Registered protocol family 2
[    2.117838] TCP established hash table entries: 2048 (order: 1, 8192 bytes)
[    2.124722] TCP bind hash table entries: 2048 (order: 2, 16384 bytes)
[    2.131160] TCP: Hash tables configured (established 2048 bind 2048)
[    2.137585] UDP hash table entries: 256 (order: 1, 8192 bytes)
[    2.143352] UDP-Lite hash table entries: 256 (order: 1, 8192 bytes)
[    2.149835] NET: Registered protocol family 1
[    2.386195] 4 CPUs re-calibrate udelay(lpj = 2924544)
[    2.392815] Crashlog allocated RAM at address 0x3f00000
[    2.398474] workingset: timestamp_bits=30 max_order=17 bucket_order=0
[    2.412407] squashfs: version 4.0 (2009/01/31) Phillip Lougher
[    2.418212] jffs2: version 2.2 (NAND) (SUMMARY) (LZMA) (RTIME) (CMODE_PRIORITY) (c) 2001-2006 Red Hat, Inc.
[    2.430993] random: fast init done
[    2.435017] bounce: pool size: 64 pages
[    2.438859] io scheduler noop registered
[    2.442688] io scheduler deadline registered (default)
[    2.448868] Serial: 8250/16550 driver, 3 ports, IRQ sharing disabled
[    2.456635] console [ttyS0] disabled
[    2.460180] 1e000c00.uartlite: ttyS0 at MMIO 0x1e000c00 (irq = 18, base_baud = 3125000) is a 16550A
[    2.469237] console [ttyS0] enabled
[    2.469237] console [ttyS0] enabled
[    2.476094] bootconsole [early0] disabled
[    2.476094] bootconsole [early0] disabled
[    2.484891] cacheinfo: Unable to detect cache hierarchy for CPU 0
[    2.491848] MediaTek Nand driver init, version v2.1 Fix AHB virt2phys error
[    2.499239] spi-mt7621 1e000b00.spi: sys_freq: 220000000
[    2.515666] m25p80 spi0.0: w25q128 (16384 Kbytes)
[    2.520431] 5 fixed-partitions partitions found on MTD device spi0.0
[    2.526765] Creating 5 MTD partitions on "spi0.0":
[    2.531544] 0x000000000000-0x000000030000 : "u-boot"
[    2.537519] 0x000000030000-0x000000040000 : "u-boot-env"
[    2.543854] 0x000000040000-0x000000050000 : "factory"
[    2.550012] 0x000000050000-0x0000000a0000 : "my_partition"
[    2.556661] 0x0000000a0000-0x000001000000 : "firmware"
[    2.594353] libphy: Fixed MDIO Bus: probed
[    2.668277] libphy: mdio: probed
[    4.071181] mtk_soc_eth 1e100000.ethernet: loaded mt7530 driver
[    4.077912] mtk_soc_eth 1e100000.ethernet eth0: mediatek frame engine at 0xbe100000, irq 21
[    4.088826] NET: Registered protocol family 10
[    4.094698] Segment Routing with IPv6
[    4.098516] NET: Registered protocol family 17
[    4.102985] 8021q: 802.1Q VLAN Support v1.8
[    4.109857] hctosys: unable to open rtc device (rtc0)
[    4.115732] VFS: Cannot open root device "(null)" or unknown-block(0,0): error -6
[    4.123240] Please append a correct "root=" boot option; here are the available partitions:
[    4.131584] 1f00             192 mtdblock0
[    4.131591]  (driver?)
[    4.138110] 1f01              64 mtdblock1
[    4.138116]  (driver?)
[    4.144616] 1f02              64 mtdblock2
[    4.144620]  (driver?)
[    4.151135] 1f03             320 mtdblock3
[    4.151141]  (driver?)
[    4.157655] 1f04           15744 mtdblock4
[    4.157660]  (driver?)
[    4.164161] Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(0,0)
[    4.174083] Rebooting in 1 seconds..

Line too be noted here is that, "Please append a correct "root=" boot option; here are the available partitions:". I even added root = /dev/mtdblock4/5/6 in the DTS in bootargs section. But still no luck

I don't know how to do what you asked, would be interested to know how to do that; but one small thing to try if you're stuck. If you think that is the problem you can verify that is so by starting the firmware partition at the usual location and just putting your custom partitions after it.

Yes, i had the exact same thinking when i started off with this task. The Partition created after the "firmware" partition works fine. Like in my first post. But since it borrows space from the firmware partition, anything you store in that partition gets erased on firstboot which i don't intend. The partition should be such that it shouldn't be erasable on firstboot that's why i tried to create it after "factory" partition. This won't allow the firstboot to touch my partition. Hence anything stored in that new partition won't get erased.

Can anyone help?

Done! Solved it using this thread https://www.olimex.com/forum/index.php?topic=5447.0

1 Like

Like @biangbiangmian and @escalion suggested, i created my partition after the firmware partition and adjusted the size of firmware partition. Next i had to make the new partition auto-mountable by putting the following code in openwrt/package/system/fstools/files/fstab.default

if [ ! -f /etc/config/fstab ] 
then

	if [ -f /dev/mtdblock7 ]
		echo "Formatage du block MTD7 en jffs2 (no skip bad blocks)"
                mtd erase /dev/mtd7
	then
		echo "ERROR : mtdblock7 not FOUND"
	fi


	echo "Detection des block"
	block detect > /etc/config/fstab 
	
	echo "ecriture du montage SOLDIOM"
	   
	echo " " >> /etc/config/fstab
	echo "##SOLIDOM external Mount" >> /etc/config/fstab
	
uci add fstab mount
uci set fstab.@mount[-1].target='/mnt/data'
uci set fstab.@mount[-1].device='/dev/mtdblock7'
uci set fstab.@mount[-1].label='my_partition'
uci set fstab.@mount[-1].fstype='jffs2'
uci set fstab.@mount[-1].options='rw,noatime'
uci set fstab.@mount[-1].enabled='1'

uci commit fstab

else
   echo "FSTAB already in config"
fi

exit 0

This helps to automount the partition by putting entries in /etc/config/fstab. Now if i create any file in the mounted partition in /mnt/data/, the file content remains untouched after reboot and firstboot as firstboot script touches and erases only the "rootfs_data" partition

1 Like

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.