0

I have a custom iMX 6UL board with Barebox (partially) functional. I have on board a Semper s25hs512t Flash being detected (after adding the necessary device id indrivers/mtd/spi-nor/spi-nor.c)

The problem - My board does not have ethernet or removable SD. I need to burn the boot loader/ flash on the s25hs512. I need to format the flash accordingly and copy the files on it.

my dtsi has

&qspi {
        pinctrl-names = "default";
        pinctrl-0 = <&pinctrl_qspi>;
        status = "okay";

        flash0: s25hs512t@0 {
                #address-cells = <1>;
                #size-cells = <1>;
                compatible = "spansion,s25hs512t", "jedec,spi-nor";
                spi-max-frequency = <40000000>;
                spi-rx-bus-width = <4>;
                spi-tx-bus-width = <4>;
                reg = <0>;
                spi-mode = <0>;
                m25p,fast-read;
                status = "okay";

                partition@0 {
                        label = "barebox";
                        reg = <0x00000000 0x00100000>;
                };
                partition@1 {
                        label = "barebox-env";
                        reg = <0x00100000 0x00040000>;
                };
                partition@2 {
                        label = "barebox-of";
                        reg = <0x00140000 0x00040000>;
                };
                partition@3 {
                        label = "kernel";
                        reg = <0x00180000 0x00800000>;
                };
                partition@4 {
                        label = "root";
                        reg = <0x00980000 0x03640000>;
                };

        };
};

on boot barebox detects the flash

Board: Freescale i.MX6 UltraLite Caisteal Board
detected i.MX6 UltraLite revision 1.0
i.MX6 UltraLite unique ID: 241e09d4e317402a
m25p80 s25hs512t@00: s25hs512t (65536 Kbytes).  <=====
imx-esdhc 2194000.mmc@2194000.of: registered as mmc1
rng_self_test: RNG software self-test passed
caam 2140000.crypto@2140000.of: Instantiated RNG4 SH0
caam 2140000.crypto@2140000.of: Instantiated RNG4 SH1
malloc space: 0x8eefcf80 -> 0x9ddf9eff (size 239 MiB)
barebox-environment chosen:environment.of: probe failed: No such file or directory

devinfo shows

         `-- 21e0000.spi@21e0000.of
            `-- s25hs512t@00
               `-- m25p0
                  `-- 0x00000000-0x03ffffff (    64 MiB): /dev/m25p0
                  `-- m25p0.barebox
                     `-- 0x00000000-0x000fffff (     1 MiB): /dev/m25p0.barebox
                  `-- m25p0.barebox-env
                     `-- 0x00000000-0x0003ffff (   256 KiB): /dev/m25p0.barebox-env
                  `-- m25p0.barebox-of
                     `-- 0x00000000-0x0003ffff (   256 KiB): /dev/m25p0.barebox-of
                  `-- m25p0.kernel
                     `-- 0x00000000-0x007fffff (     8 MiB): /dev/m25p0.kernel
                  `-- m25p0.root
                     `-- 0x00000000-0x0363ffff (  54.3 MiB): /dev/m25p0.root

but when I run ubiformat, I am oddly getting this

barebox@Freescale i.MX6 UltraLite Caisteal Board:/ ubiformat /dev/m25p0.barebox -y
ubiformat: m25p0.barebox (nor), size 1048576 bytes (1 MiB), 4 eraseblocks of 262144 bytes (256 KiB), min. I/O size 1 bytes
libscan: scanning eraseblock 3 -- 100 % complete  
ubiformat: 1 eraseblocks are supposedly empty
ubiformat: warning!: 3 of 4 eraseblocks contain non-ubifs data
ubiformat: warning!: only 0 of 4 eraseblocks have valid erase counter
ubiformat: erase counter 0 will be used for all eraseblocks
ubiformat: note, arbitrary erase counter value may be specified using -e option
ubiformat: use erase counter 0 for all eraseblocks
ubiformat: formatting eraseblock 3 -- 100 % complete  
ERROR: m25p80 s25hs512t@00: flash operation timed out
ERROR: m25p0.barebox: error -110 while writing 262144 bytes to PEB 0:0, written 0 bytes
libubigen: error!: cannot write 262144 bytes
ubiformat: error!: cannot write layout volume
ubiformat: Operation not permitted

Any way ahead from this?

PS : Update Thanks for help from @TrentP - I am focusing only on formatting the larger partitions so that I can write the kernel and root partition. but I have not been able to mount the ubi partition. I get the following issue (Readonly filesystem)

barebox@Freescale i.MX6 UltraLite Caisteal Board:/ erase /dev/m25p0.kernel 

barebox@Freescale i.MX6 UltraLite Caisteal Board:/ ubiattach /dev/m25p0.kernel 
NOTICE: ubi0: scanning is finished
NOTICE: ubi0: empty MTD device detected
NOTICE: ubi0: registering /dev/m25p0.kernel.ubi
NOTICE: ubi0: attached mtd0 (name "m25p0.kernel", size 8 MiB) to ubi0
NOTICE: ubi0: PEB size: 262144 bytes (256 KiB), LEB size: 262016 bytes
NOTICE: ubi0: min./max. I/O unit sizes: 1/256, sub-page size 1
NOTICE: ubi0: VID header offset: 64 (aligned 64), data offset: 128
NOTICE: ubi0: good PEBs: 32, bad PEBs: 0, corrupted PEBs: 0
NOTICE: ubi0: user volume: 0, internal volumes: 1, max. volumes count: 128
NOTICE: ubi0: max/mean erase counter: 1/0, WL threshold: 65536, image sequence number: 1700878141
NOTICE: ubi0: available PEBs: 28, total reserved PEBs: 4, PEBs reserved for bad PEB handling: 0

barebox@Freescale i.MX6 UltraLite Caisteal Board:/ ubimkvol /dev/m25p0.kernel.ubi kernel 0
NOTICE: ubi0: registering kernel as /dev/m25p0.kernel.ubi.kernel


barebox@Freescale i.MX6 UltraLite Caisteal Board:/ mount -t ubifs /dev/m25p0.kernel.ubi.kernel  /mnt/kernel/
ERROR: UBIFS error (ubi0:0): 9de5a2d5: can't format empty UBI volume: read-only mount
ERROR: ubifs ubifs0: probe failed: Read-only file system
mount: Invalid argument

If I use ubiformat I get this

barebox@Freescale i.MX6 UltraLite Caisteal Board:/ ubiformat /dev/m25p0.kernel -y
ubiformat: m25p0.kernel (nor), size 8388608 bytes (8 MiB), 32 eraseblocks of 262144 bytes (256 KiB), min. I/O size 1 bytes
libscan: scanning eraseblock 31 -- 100 % complete  
ubiformat: warning!: 32 of 32 eraseblocks contain non-ubifs data
ubiformat: warning!: only 0 of 32 eraseblocks have valid erase counter
ubiformat: erase counter 0 will be used for all eraseblocks
ubiformat: note, arbitrary erase counter value may be specified using -e option
ubiformat: use erase counter 0 for all eraseblocks
ubiformat: formatting eraseblock 31 -- 100 % complete  
barebox@Freescale i.MX6 UltraLite Caisteal Board:/ ubiattach /dev/m25p0.kernel 
NOTICE: ubi0: scanning is finished
ERROR: ubi0 error: ubi_read_volume_table: the layout volume was not found
ERROR: ubi0 error: ubi_attach_mtd_dev: failed to attach mtd0, error -22
failed to attach: Invalid argument

devinfo

Parent: m25p0.kernel
Parameters:
  available_pebs: 0 (type: uint32)
  bad_peb_count: 0 (type: uint32)
  good_peb_count: 32 (type: uint32)
  leb_size: 262016 (type: uint32)
  max_erase_counter: 2 (type: uint32)
  mean_erase_counter: 0 (type: uint32)
  min_io_size: 1 (type: uint32)
  peb_size: 262144 (type: uint32)
  reserved_pebs: 32 (type: uint32) <=== why all PEBs are reserved?
  sub_page_size: 1 (type: uint32)
  vid_header_offset: 64 (type: uint32)

Any suggestions on what I am doing wrong. I know its something ridiculously simple. just unknown to me

Ian Abbott
  • 15,083
  • 19
  • 33
Harkirat
  • 72
  • 8

1 Answers1

2

You aren't supposed to use ubiformat on the barebox partition. It's too small. That's why it fails.

UBI is a Linux layer for putting UBI filesystems into NAND or NOR flash. The iMX6UL CPU boot ROM does not understand UBI. It can't boot something in a UBI formatted partition. It's for the root filesystem in the root partition.

Read section 8 of the iMX6UL reference manual, especially §8.6 about QuadSPI booting. This will tell you what you must put into flash to make it bootable.

Also look at the barebox_update command, which can be used to flash the bootloader from Barebox. The board needs to support it and I don't know about your board. The code is in various imx6_bbu_* functions. I'm not sure if qspi is supported, as I only see eMMC/SD,eMMC boot, NAND, and I2C/SPI. The qspi interface isn't the same as a serial EEPROM on one of the eCSPI controllers (again, see RM §8!). But perhaps it would work with an appropriate header already on the image.

TrentP
  • 4,240
  • 24
  • 35
  • Firstly Thanks. Second am in the deep end of the pool here. I understand what you are saying but I am not sure on way ahead. I understood earlier that we can write a single image file using ubiformat - and had planned to used that write the barebox image (with config header) file to that partition. By what you say, I cannot do that? for the barebox_update do you have a suggested reference source which has a good (and tested) implementation. Still worried how to do it on QSPI. Also any suggestions how to build a barebox image with config header as a single file? – Harkirat Sep 01 '21 at 07:15
  • 1
    Barebox and Linux can load images or mount a filesystem from UBI. The iMX6 ROM can not use UBI in any way. It is the ROM which must load the bootloader. You can write to flash with `cp` or `memcyp`. I haven't used qspi booting on iMX. You should be able to find a guide that explains how to create an image. – TrentP Sep 01 '21 at 08:21
  • Thanks ... getting the sense of the issue. I'll work on that. Back to the original issue though. I get the same error when running ubiformat on the m25p0.root partition. so size doesn't seem to be the issue. that's 54 MB – Harkirat Sep 01 '21 at 09:11
  • I checked again, some freak failure. second time it worked. But I have not been able to mount it yes. I am getting weird combination of errors. I have amended my post accordingly. If you could have a look – Harkirat Sep 01 '21 at 16:48
  • 2
    You need to make volumes with `ubimkvol` and if you want a filesystem then you need to have created a ubifs image and write it with `ubiupdatevol`. The ubifs code in Barebox is read-only. – TrentP Sep 01 '21 at 17:41
  • Thank you. I think I zeroed down to that also. so I should create a ubifs volume, transfer it to the board write it to volume (/dev/m25p0.root.ubi.root) and then mount it. I will have to test that because I still don't know how to transfer the file without ethernet (maybe use usb/dfu, not figured it out yet). Why is ubiattach failing after ubiformat but succeeding after erase??? and why are all PEBs reserved? – Harkirat Sep 01 '21 at 17:55
  • Making a volume reserves the PEBs, so when you made a volume of size 0 it should reserve all the PEBs. It does seem like you have some kind of problem with your flash not working correctly. I believe when you attach after erasing flash, UBI uses a format-on-demand mode that waits until a volume is used. Barebox's ubifs support is read-only, so it doesn't work. I don't see any reason why the format and attach example should have failed, unless you did something between to corrupt flash that is omitted. – TrentP Sep 02 '21 at 04:21
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/236670/discussion-between-harkirat-and-trentp). – Harkirat Sep 02 '21 at 06:36