Using the SD card as a removable storage: add SPI flash ?

Started by ggilles, July 23, 2013, 05:43:44 pm

Previous topic - Next topic

ggilles

Hello,

in my project, I would like to use the SD card as a removable storage. Therefore, I need to move the OS on an external storage.

My initial thought is to use a simple SPI flash connected on SPI2. For now, I have successfully connected a sst25vf016b SPI flash, and I can read/write to it when booting from the SD card. I would switch to a larger flash later (I got that one at hand).

My problem now is booting from SPI flash.

Note: I am using buildroot.

Basically, when booting from SD card, the SD card has two partitions: the first gets the linux bootstream file, and the second gets the root filesystem. In the end, setting up the SD card is as simple as:
dd if=imx233_olinuxino_dev_linux.sb of=/dev/sdb1
dd if=rootfs.ext2 of=/dev/sdb2

Now, I wonder how I should copy those 2 files in flash.

As a simple test, I tried simply copying the bootstream file at the start of my current flash, then adjust the boot jumpers and reboot, and it hangs after the battery voltage measurement.

Reading this thread:
https://community.freescale.com/thread/301137#309681
it appears that adding some information in the device tree could be enough.

I am thinking of something along the lines of:
partition@0 {
label = "bootstream";
reg = <0x00000000 0x00200000>;
read-only;
};

partition@1 {
label = "rootfs";
reg = <0x00200000 0x00600000>;
};


This leads to question 1:
   Will this be enough to boot from flash on SPI2 or is there anything else to change in the kernel?


One particular thing which worries me with this SPI flash is that it is small capacity (8 Mbytes), so I will need to be extra carefull about space.

So here is my question 2:
   Is this SPI flash worth it or is there any better solution worth consideration?


Thanks a lot.

-- Gilles

jlumme

I chose to use u-boot (just get the imx branch) for the loader, since it felt easier to comprehend than those bootlets.
I'm currently booting from SPI flash (sst25vf064b) without problems.

I designated my partitions in dts file in similar fashion as you describe, under my SPI bus definition. And u-boot is written to the beginning of the flash, but I currently use external tool to write it (& kernel) to the flash.
Kernel will need support for the chosen flash filesystem, but that seems pretty much it (if you supply parameters such as rootfs to it correctly)

There is some talk in u-boot mailing list in May that there were some issues with initialization code for the chip, and it affects the stability - but I haven't been affected yet (however, my development phase is still pretty much testing and re-writing/flashing).

Anyway, sorry if I veered a bit off-topic with u-boot, and not really giving you answer for how to use bootlets

ggilles

jlumme,
thank you for this answer, I will try u-boot then.

Could you share your u-boot uEnv.txt file to get me started with this?

One thing which is not clear to me is why I need to change the device tree file when using u-boot. It seems that u-boot could supply the necessary bootargs to the kernel.

Is there something I missed here?

jlumme

ggilles, I can send you it with PM once I get home today, I don't have it available right now.

Sorry, maybe I was a little bit unclear there. Of course u-boot doesn't need know anything about the device tree.
It is only for the kernel, so that it can mount rootfs, and other mount points properly (this is of course if you're planning to have those in the flash as well, and not on that microsd).

ggilles

jlumme, I managed to get u-boot working on the SD card. Also, I successfully interfaced a s25fl256s SPI flash, which mean I now have 32Mbytes available for u-boot + kernel + rootfs. I guess it won't be a lot of work now to make the complete system boot from flash.

I understand that by modifying the device tree I will be able to boot the kernel from flash.

However, it seems that I will have to provide a customized uEnv.txt for u-boot to boot the kernel from flash. Therefore, I was wondering if I could simply define the proper command line arguments inside that uEnv.txt to boot the kernel from flash, thus avoiding the need for 2 changes.