Free (small) partition for storing serial number?

Hello. We are currently adapting our IOT platform for WP77/WP76 and have a few questions:

I am currently looking for a good place to store the unit serial number.
I was contemplating the Legato ‘config’ tool/api, but it seems to fragile as the data are stored on the “userapp” partition (/mnt/flash) which is shared with /home and /legato

Is there a partition in this list that will not be overwitten by a firmware update, where I can create a ubi volume for private use?

root@swi-mdm9x28-wp:~# lsmtd
DEVICE     MAJ:MIN NAME         TYPE    SIZE
mtd0        90:0   sbl          nand      2.5M
mtd1        90:2   mibib        nand      2.5M
mtd2        90:4   backup       nand      6.5M
mtd3        90:6   security     nand        1M
mtd4        90:8   persist      nand        2M
mtd5        90:10  efs2         nand     17.5M
mtd6        90:12  swifota      nand     79.3M
mtd7        90:14  tz           nand      1.5M
mtd8        90:16  devcfg       nand      768K
mtd9        90:18  rpm          nand      768K
mtd10       90:20  modem        nand       32M
└─ubi1     233:0                           31M
  └─ubi1_0 233:1   modem        static   15.3M
mtd11       90:22  aboot        nand        1M
mtd12       90:24  boot         nand       15M
mtd13       90:26  system       nand       30M
└─ubi0     237:0                         29.1M
  ├─ubi0_0 237:1   rootfs       static   26.1M
  ├─ubi0_1 237:2   rootfs_hs    static    248K
  └─ubi0_2 237:3   rootfs_rhs   static    248K
mtd14       90:28  lefwkro      nand      8.8M
└─ubi2     235:0                          8.4M
  ├─ubi2_0 235:1   legato       static    5.1M
  ├─ubi2_1 235:2   legato_hs    static    248K
  └─ubi2_2 235:3   legato_rhs   static    248K
mtd15       90:30  swirw        nand       25M
└─ubi4     234:0                         24.2M
  └─ubi4_0 234:1   swirw_vol0   dynamic  13.1M
mtd16       90:32  userapp      nand      131M
└─ubi3     236:0                        126.9M
  └─ubi3_0 236:1   userapp_vol0 dynamic   115M
mtd17       90:34  reserved     nand     54.5M
mtd18       90:36  slot_2       nand     33.5M
mtd19       90:38  slot_1       nand     33.5M
mtd20       90:40  slot_0       nand     33.5M
root@swi-mdm9x28-wp:~#

why don’t you save the data in /home/root folder?

That is essentially similar to what the "config tool would do.
Because I don’t know when that will be overwritten (part of “userapp” partition)

Can you tell how to reset/initialize the “userapp” partition (/mnt/flash) is there an official way?

Also, can you enlighten me about where all these parts of a firmware update will go?
A map of Type/Product → MTD partition would be really nice :slight_smile:

[fm-w500 swi-linux-src tt86]$ swicwe -P /tmp/WP77xx_Release14.1_GENERIC_GCF_PTCRB.spk
 Type    Size(Exclude Header)    Product         Compress        Version
*SPKG    59170760                Y931            0               9999999_9907618_SWI9X06Y_02.36.06.00_00_GENERIC_001.071_001
*BOOT    412672                  Y931            0               SWI9X06Y_02.36.06.00 000000 CARMD-EV-SIGN01 2020/12/10 15:02:06
 HASH    6480                    9X06            0               SWI9X06Y_02.36.06.00 000000 CARMD-EV-SIGN01 2020/12/10 15:02:06
 SBL1    405392                  9X06            0               SWI9X06Y_02.36.06.00 000000 CARMD-EV-SIGN01 2020/12/10 15:02:06
*MODM    17755900                Y931            0               SWI9X06Y_02.36.06.00 000000 CARMD-EV-SIGN01 2020/12/10 15:02:06
 HASH    6560                    9X06            0               SWI9X06Y_02.36.06.00 000000 CARMD-EV-SIGN01 2020/12/10 15:02:06
 TZON    551644                  9X06            0               SWI9X06Y_02.36.06.00 000000 CARMD-EV-SIGN01 2020/12/10 15:02:06
 QRPM    156736                  9X06            0               SWI9X06Y_02.36.06.00 000000 CARMD-EV-SIGN01 2020/12/10 15:02:06
 DSP2    17039360                9X06            0               SWI9X06Y_02.36.06.00 000000 CARMD-EV-SIGN01 2020/12/10 15:02:06
*FILE    11104                   Y931            0               9999999_9907618_SWI9X06Y_02.36.06.00_00_GENERIC_001.071_001
*APPL    34435084                Y931            0               SWI9X06Y_02.36.07.00 000000 CARMD-EV-SIGN01 2021/01/25 14:07:17
 HASH    6560                    9X06            0               SWI9X06Y_02.36.07.00 000000 CARMD-EV-SIGN01 2021/01/25 14:07:17
 APBL    569366                  9X06            0               SWI9X06Y_02.36.07.00 000000 CARMD-EV-SIGN01 2021/01/25 14:07:17
 SYST    24117248                Y931            0               SWI9X06Y_02.36.07.00 000000 CARMD-EV-SIGN01 2021/01/25 14:07:17
 APPS    9740310                 9X06            0               SWI9X06Y_02.36.07.00 000000 CARMD-EV-SIGN01 2021/01/25 14:07:17
*APPL    6554000                 Y921            0               19.11.5 1b82efb jenkins 2021/02/09 02:59:19
 USER    6553600                 9X28            0               19.11.5 1b82efb jenkins 2021/02/09 02:59:19

Cheers /Flemming

To reset userapp partition, you need to downgrade to R12 first

And will any of the parts of the official SPK above overwrite the “userapp” partition in mtd16?
Is there a map of spk/cwe parts to mtd partitions?

do you mean this?

root@swi-mdm9x28-wp:~# more /proc/mtd
dev: size erasesize name
mtd0: 00280000 00040000 “sbl”
mtd1: 00280000 00040000 “mibib”
mtd2: 00680000 00040000 “backup”
mtd3: 00100000 00040000 “security”
mtd4: 00200000 00040000 “persist”
mtd5: 01180000 00040000 “efs2”
mtd6: 05040000 00040000 “swifota”
mtd7: 00100000 00040000 “tz”
mtd8: 00080000 00040000 “rpm”
mtd9: 02080000 00040000 “modem”
mtd10: 00100000 00040000 “aboot”
mtd11: 00f00000 00040000 “boot”
mtd12: 01e00000 00040000 “system”
mtd13: 008c0000 00040000 “lefwkro”
mtd14: 01900000 00040000 “swirw”
mtd15: 08300000 00040000 “userapp”
mtd16: 03680000 00040000 “reserved”
mtd17: 02180000 00040000 “slot_2”
mtd18: 02180000 00040000 “slot_1”
mtd19: 02180000 00040000 “slot_0”

No. I knew full well about that one.

What I mean is:

If i flash the “WP77xx_Release14.1_GENERIC_GCF_PTCRB.spk” file above as described here,
which mtd partitions (as in /proc/mtd like you said) will be overwritten?

Didn’t swicwe above already show that?

No it does not.
This is exactly what i have been asking for all along!
What part of the cwe or spk file is flashed to which partition:

For example: For the line in the “swicwe -P” output that says:

 APPS    9740310                 9X06            0               SWI9X06Y_02.36.07.00 000000 CARMD-EV-SIGN01 2021/01/25 14:07:17

Which mtd partition is that part flashed to? mtd1? mtd7? or something else?
I would have loved to be able to find this information with Google, or in the source code on GitHub, or in the documentation, but I can not.

Please advise.

It is just the TYPE, not partition name.
I believe the yocto.cwe will be flashed to “system” partition, and legato.cwe will be flashed to “lefwkro” partition.

Yes, true. That is exactly why I asked the question. (Which is still unanswered btw)

e.g This legato cwe will be flashed to “lefwkro” partition.
What is the relationship to storing serial number?

owner@CNHKG-EX-001367:~/Yocto/tools/swicwe_1.14/linux64$ ./swicwe -P /home/owner/LEAF/swi-wp76_4.6.0/leaf-data/current/wp76-legato-image/legato.cwe
Type Size(Exclude Header) Product Compress Version
*APPL 6554000 Y921 0 19.11.0 7584797a6 jenkins 2020/01/16 02:00:20
USER 6553600 9X28 0 19.11.0 7584797a6 jenkins 2020/01/16 02:00:20

The relationship is from trying to figure out which partitions are touched by a firmware update.

I knew already that a legato.cwe would overwrite the “lefwkro” parition.
And a linux-SWI*.cwe would overwrite the “system” partition etc. etc.

What I still do not know are which partitions are overwritten by a combined firmware SPK file like the one downloaded from here which combines many .cwe files into one.

If I store the serial number somewhere on the “userapp” partition (ie. somewhere in the /mnt/flash tree) I also still don’t know when that will disappear!

What happens if the userapp partition is completely botched? How can one recover it to a usable state?

Suppose something (accidentally) does a ‘rm -rf /mnt/flash/*’ :thinking:
How can the module recover from that? and regain a usable /legato for instance?
And anything stored in /home or anywhre on the userapp partition will surely be gone!

i remember storing in /home/root will not gone when you flash new FW.
You can do some testing on that

In case others google their way to here:
I finally managed to crack this challenge …

The solution was to create extra ufs partitions in the “system” (mtd13) mtd partition with my data.
This way, all can be restored, even if (when) /mnt/flash (“userapp” mtd16) is trashed or cleared.

Incidentally, /home/root lives on the “userapp” partition and will be lost if it is cleared.

Here is my solution from “mdm9x28-image-minimal.bbappend” that adds two extra partitions:

# Spiffy: We can append to the create_ubinize_config() method
create_ubinize_config_append() {

    if [[ -s ${dm_root_hash_path} && -f /tmp/amplex-image.tar.bz2 ]]; then
        echo >> $cfg_path
        echo \[amplex_tbz\] >> $cfg_path
        echo mode=ubi >> $cfg_path
        echo image="/tmp/amplex-image.tar.bz2" >> $cfg_path
        echo vol_id=3 >> $cfg_path
        echo vol_type=static >> $cfg_path
        echo vol_name=amplex_tbz >> $cfg_path
        echo vol_alignment=1 >> $cfg_path
    fi

    if [[ -s ${dm_root_hash_path} && -f /tmp/amplex-param.conf ]]; then
        echo >> $cfg_path
        echo \[amplex_param\] >> $cfg_path
        echo mode=ubi >> $cfg_path
        echo image="/tmp/amplex-param.conf" >> $cfg_path
        echo vol_id=4 >> $cfg_path
        echo vol_type=static >> $cfg_path
        echo vol_name=amplex_param >> $cfg_path
        echo vol_alignment=1 >> $cfg_path
    fi

And the result on the target:

> lsmtd
...
mtd11       90:22  aboot        nand        1M
mtd12       90:24  boot         nand       15M
mtd13       90:26  system       nand       30M
└─ubi0     237:0                         29.1M
  ├─ubi0_0 237:1   rootfs       static   24.9M
  ├─ubi0_1 237:2   rootfs_hs    static    248K
  ├─ubi0_2 237:3   rootfs_rhs   static    248K
  ├─ubi0_3 237:4   amplex_tbz   static    992K
  └─ubi0_4 237:5   amplex_param static    248K
mtd14       90:28  lefwkro      nand      8.8M
└─ubi2     235:0                          8.4M
  ├─ubi2_0 235:1   legato       static    5.1M
  ├─ubi2_1 235:2   legato_hs    static    248K
  └─ubi2_2 235:3   legato_rhs   static    248K
...

> cat /dev/ubi0_4
# Amplex config
serial_0 = 2004042042
1 Like