Mixed content partition

Hello,

I'm trying to add support for DIR-815 B1. I found the partition layout but i'm having trouble making sense of it. It seems that u-boot-env and wifi eeprom are located on the same partition mtd4, labeled as "devdata" in the stock firmware. Here is the start of the partition

00000000  16 23 3d 79 62 6f 6f 74  63 6d 64 3d 74 66 74 70  |.#=ybootcmd=tftp|
00000010  00 62 6f 6f 74 64 65 6c  61 79 3d 31 00 62 61 75  |.bootdelay=1.bau|
00000020  64 72 61 74 65 3d 35 37  36 30 30 00 65 74 68 61  |drate=57600.etha|
00000030  64 64 72 3d 39 30 3a 39  34 3a 65 34 3a 33 35 3a  |ddr=90:94:e4:35:|
00000040  39 63 3a 65 63 00 69 70  61 64 64 72 3d 31 39 32  |9c:ec.ipaddr=192|
00000050  2e 31 36 38 2e 30 2e 31  00 73 65 72 76 65 72 69  |.168.0.1.serveri|
00000060  70 3d 31 39 32 2e 31 36  38 2e 30 2e 32 35 34 00  |p=192.168.0.254.|
00000070  72 61 6d 61 72 67 73 3d  73 65 74 65 6e 76 20 62  |ramargs=setenv b|
00000080  6f 6f 74 61 72 67 73 20  72 6f 6f 74 3d 2f 64 65  |ootargs root=/de|
00000090  76 2f 72 61 6d 20 72 77  00 61 64 64 69 70 3d 73  |v/ram rw.addip=s|
000000a0  65 74 65 6e 76 20 62 6f  6f 74 61 72 67 73 20 24  |etenv bootargs $|
000000b0  28 62 6f 6f 74 61 72 67  73 29 20 69 70 3d 24 28  |(bootargs) ip=$(|
000000c0  69 70 61 64 64 72 29 3a  24 28 73 65 72 76 65 72  |ipaddr):$(server|
000000d0  69 70 29 3a 24 28 67 61  74 65 77 61 79 69 70 29  |ip):$(gatewayip)|
000000e0  3a 24 28 6e 65 74 6d 61  73 6b 29 3a 24 28 68 6f  |:$(netmask):$(ho|
000000f0  73 74 6e 61 6d 65 29 3a  24 28 6e 65 74 64 65 76  |stname):$(netdev|
00000100  29 3a 6f 66 66 00 61 64  64 6d 69 73 63 3d 73 65  |):off.addmisc=se|
00000110  74 65 6e 76 20 62 6f 6f  74 61 72 67 73 20 24 28  |tenv bootargs $(|
00000120  62 6f 6f 74 61 72 67 73  29 20 63 6f 6e 73 6f 6c  |bootargs) consol|
00000130  65 3d 74 74 79 53 30 2c  24 28 62 61 75 64 72 61  |e=ttyS0,$(baudra|
00000140  74 65 29 20 65 74 68 61  64 64 72 3d 24 28 65 74  |te) ethaddr=$(et|
00000150  68 61 64 64 72 29 20 70  61 6e 69 63 3d 31 00 66  |haddr) panic=1.f|

which i think is u-boot-env data. Further down there is this

000002c0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00003ff0  00 00 00 00 00 00 00 00  00 00 00 00 ff ff ff ff  |................|
00004000  52 33 00 01 00 0c 43 30  50 58 ff ff ff ff ff ff  |R3....C0PX......|
00004010  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
00004020  ff ff ff ff ff ff ff ff  00 0c 43 30 50 77 00 0c  |..........C0Pw..|
00004030  43 30 50 66 22 0c 04 20  ff ff 1e 01 55 77 a8 aa  |C0Pf".. ....Uw..|
00004040  8c 88 22 ff 0c 00 00 00  00 00 00 00 00 00 ff ff  |..".............|
00004050  81 81 10 10 10 11 11 11  11 12 12 12 12 13 13 13  |................|
00004060  12 12 12 13 13 13 13 14  14 14 14 15 15 15 08 00  |................|
00004070  00 00 00 00 00 f0 ff 81  ff ff ff ff ff ff ff ff  |................|
00004080  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|

I verified that starting at 0x4000 is the wifi EEPROM.

How do i represent this in the dts partition layout? If i assign mtd4 to be u-boot-env, i worry that the wifi EEPROM may be wiped during UBoot update (or something). If, on the other hand, i assign mtd4 to be factory then where do i point u-boot-env?

In case anyone has information on this, there is also a partition labeled "devconf" in the stock firmware, which appears to contains 0x119f bytes of unintelligible binary data starting with what looks to be a magic signature ED FC CF DE.

Split it into two partitions in your dts

1 Like

With most routers you never need to update/write to the uboot-env area. It is usually marked read-only in DTS. (Dual firmware systems are the exception)

From that perspective, keeping that as one partition might also work.

4000 bytes is not a typical erase block size, so having that early part as writable partition might be problematic. Are you sure that there is not a copy of that at 40000 like you wrote two weeks ago in Porting to DIR 815 B1 - #8 by dgen

Ps. A 32 MB ram device will pretty likely not be accepted to the main OpenWrt. Too small for the current code.

1 Like

Thank you, both approaches make sense. I didn't realize i could change the partition layout (relative to the stock firmware) in the dts. I was thinking there might be some special partition markers; but i guess flash is just a raw byte store so can be sliced and diced anyway you like.

@hnyman I have seen the 4/32 device warning. I have a personal interest in getting this working because i'm loath to throw away working equipment. In a setup where firewall-ing and routing is handled by a dedicated pfSense box, these old routers are perfect as wifi APs. Putting OpenWrt on them opens up additional features, like VLANs, that allow construction of more secure home networks. Given how many of these devices are still around it seems a shame to send them all to the garbage dumps. There is already more than enough trash in the world.

1 Like

That is almost right, but to my knowledge, the write operations are done via whole flash erase blocks, so having a writable block partially read-only might be really problematic (in style of filling the read-only part accidentally with garbage in a write operation targeting the smaller read-write art of the block).

OpenWrt can have kernel ending at mid-block and read-only rootfs starting immediately, but to my knowlege the read-write part always starts at a block start.

Erase blocks have usually been 64 kB (0x10000) in old routers, so 0x4000 would be 1/4 of a block.