How to add NOR flash driver in Ubunut-core image

I am looking to add driver for a NOR flash connected to my CPU. Any pointers on how to go about it?

I already have an image that boots Ubuntu core 18 with kernel, gadget and core snaps and has drivers (not added by me) for network, usb, tpm, eMMC etc.

Is this a kernel driver? Kernel drivers typically will go in the kernel snap for Ubuntu Core devices.

Yes, this is supposed to be a kernel driver. Is there a CONFIG that I should look for in defconfig that will enable this driver. Or is there more to be done to get /dev/mtd seen?

If it’s not in the default ubuntu kernel snap, you will need to rebuild your kernel snap to include and load this driver.

Thx, @ijohnson. Would it be possible to give some more details on how to achieve that?

if you use a standard ubuntu kernel from the store you can file a bug at:

to get the respective driver enabled.

I have a custom kernel. Thanks anyway for the link. Will use it in future if required.

well, in your custom kernel make sure to have all the necessary CONFIG_MTD_* options enabled (_BLOCK,_BLKDEV, _PARTITIONS,_WHATEVER) plus the right one for the actual hardware driver … if you have some BSP kernel to look at, i’d grep for CONFIG_MTD in the defconfig for the board …

1 Like

Thanks @ogra. This is helpful.

After enabling whatever I could w.r.t config, I do see mtd now.

iotadmin@localhost:~$ sudo mount -t jffs2 /dev/mtdblock1 /mnt/sflash
mount: /mnt/sflash: can’t read superblock on /dev/mtdblock1.
iotadmin@localhost:~$ ls -l /dev/ | grep mtd
crw------- 1 root root 90, 0 Feb 21 11:50 mtd0
crw------- 1 root root 90, 1 Feb 21 11:50 mtd0ro
crw------- 1 root root 90, 2 Feb 21 11:50 mtd1
crw------- 1 root root 90, 3 Feb 21 11:50 mtd1ro
brw-rw---- 1 root disk 31, 0 Feb 21 11:50 mtdblock0
brw-rw---- 1 root disk 31, 1 Feb 21 11:50 mtdblock1
iotadmin@localhost:~$ cat /proc/mtd
dev: size erasesize name
mtd0: 01000000 00001000 “BIOS”
mtd1: 00400000 00001000 “PDR”

But mounting fails:

(classic)iotadmin@localhost:~$ sudo mount -t jffs2 /dev/mtdblock1 /mnt/sflash
mount: /mnt/sflash: can’t read superblock on /dev/mtdblock1.

well, do you have jffs2 enabled (cat /proc/filesystems) and does the disk contain a valid jffs2 image ?

(note that Ubuntu Core does not support booting from mtd disks or flash filesystems currently (this requires some non-trivial changes in the auto-rollback bootloader handling), you will only be able to use this disk as additional device under /media or /mnt)

Yes, jffs2 is enabled
iotadmin@localhost:~$ cat /proc/filesystems | grep jffs2
nodev jffs2

But, maybe a valid jffs2 image is not installed on the SPI NOR flash (/dev/mtdblock1). Any way to validate / install ? I tried mkfs but could not see mkfs.jffs2 on my device.

Understood about UC. Plan is to use it to hold some certs and logs.

you will likely need mtd-utils to write to the disk: