Olimex Support Forum

OLinuXino Android / Linux boards and System On Modules => iMX233 => Topic started by: jGrey on August 20, 2014, 06:57:36 pm

Title: Newbie question: can iMx233 Olinuxino-Micro boot from USB?
Post by: jGrey on August 20, 2014, 06:57:36 pm
Hi Experts:

I'm new to this forum and I have a question as stated in the subject. I tried many times but no luck so far. To partition my 2GB
USB stick, I tried to use DISKPART in windows 7, or did use fdsik on the board. Then use the command line:

   [root@alarm ~]# dd bs=4M if=/dev/mmcblk0 of=/dev/sda conv=notrunc

to copy the Linux image from the SD card. It looks like that the copy is OK, when I check the contents in the USB, as if everything
is copied. But it did not boot. The error message on the screen was 0x80502004, meaning that "USB device not configured".

I also did in other way when I boot my windows 7 machine as a Linux machine, the did partition the USB on that Linux machine and downloaded some other images, such as ArchLinuxARM-olinuxino-latest.img.gz, Linux-alarm-2.6.35-6-ARCH.img, etc. then copy to the USB bu using command dd.

I tried to use USB writer to directly write the img to USB, again, not working. >:(

Anything fundamentally wrong? Your feedback is highly appreciated!!
Title: Re: Newbie question: can iMx233 Olinuxino-Micro boot from USB?
Post by: jaycarlson on August 20, 2014, 10:17:05 pm
The imx233 will not boot from a USB mass storage device. The "USB boot" mode is just a special HID mode the device will start up into.

The imx233 can boot from MicroSD, SPI flash, or NAND flash. The easiest (read: default) method is to boot off the MicroSD card.
Title: Re: Newbie question: can iMx233 Olinuxino-Micro boot from USB?
Post by: lambda on August 20, 2014, 10:57:25 pm
If you want to boot from usb-storage you need to install u-boot on your SD-Card.
Once the system has booted, you can remove the SD-Card to use the slot for other things - e.g. writing more bootable SD-Cards.

HTH,
Harald
Title: Re: Newbie question: can iMx233 Olinuxino-Micro boot from USB?
Post by: jGrey on August 21, 2014, 03:10:16 pm
Thanks a lot lambda and jaycarlson. But can you further explain why that imx233 can not boot from USB, i mean, can you put a couple of more lines?

Then, what is the simpliest way to boot from any other device other than that microSD?

Thank you for your advice.
Title: Re: Newbie question: can iMx233 Olinuxino-Micro boot from USB?
Post by: mbergmann on August 21, 2014, 03:40:26 pm
The boot mode of the i.MX233 is selected either through external resistors or via OTP eFuse bit programming. If your device is fused to a boot mode you can not change it anymore. If the mode is selected via resistors you have to solder to choose another mode.

You can find the boot modes in the reference manual chapter 35. In short the are:

- USB slave boot mode.
- I2C from EEPROM.
- SPI boots from flash memory.
- SD/MMC boots from cards.
- JTAG_WAIT -- Waits for JTAG debugger connection.

The USB slave mode is to load software into the SoC via tools like sb_loader, not for booting from a USB device.

If you want to boot from a USB device you have to boot from one of the devices described above, initialize the i.MX 233 SoC and then boot manually from your USB device. So you have to use some kind of bootloader like the u-boot bootloader recommended above.

Kind Regards

Mike
Title: Re: Newbie question: can iMx233 Olinuxino-Micro boot from USB?
Post by: jGrey on August 21, 2014, 05:09:49 pm
Hi Mike and lambda,

Thanks for the info you provided. I did use solder to select boot mode, i.e., when D03~D00 is 1001, booting
from micro ASD; and D03~D00 = 0000, from USB. That was printed on the open source schematic. Actually, I have
two iMX233 olinuXino-Micro boards, and one is still using default mode to boot, while the other one is trying
using different mode to boot.

Now, what lambda's input is quite interesting. She says that I should be able to remove the SD-Card to use the slot for other things. Great! Can you explain a little more? What are the steps I should do?

Thanks.
Title: Re: Newbie question: can iMx233 Olinuxino-Micro boot from USB?
Post by: lambda on August 22, 2014, 01:38:56 am
Hi jGrey,

I'm using openwrt for my imx233 work so the following description is somewhat openwrt specific, but the general idea schould work with any linux distribution. Maybe you find some useful files at
http://downloads.openwrt.org/snapshots/trunk/mxs/

First you need to prepare a SD-Card with u-boot. This is pretty much the same as installing a kernel: Instead of a linux kernel you might use the file from
http://downloads.openwrt.org/snapshots/trunk/mxs/uboot-mxs-mx23_olinuxino.sb
or any other u-boot image you compile yourself.

Note: It is perfectly possible to install u-boot and a linux distribution (as fallback if no usb device is detected) on the same SD-Card - just create enough partitions. U-boot is scriptable with a shell like syntax, which allows for arbitrarily complex setups.

If you are not yet familiar with u-boot, it might be a good idea to attach a serial console and look around a bit at the u-boot prompt and maybe try to boot from the same SD-Card first. Also if you change any u-boot settings, you can save your changes from this prompt.

The next thing I did, was perparing the usb stick. u-boot supports FAT and extX filesystems, so we have pretty much freedom how we partition the stick. My personal convention is, that the first partition is FAT and contains a u-boot script file with instructions how to actually load a kernel. (My main purpose of this setup is testing various kernels and the FAT partition holds many kernels, which I can select by renaming
files.) The second partition holdes the root filesystem (ext4).

The tricky part with openwrt was to get a kernel with usb support compiled in (otherwise the kernel won't be able to mount the root filesystem). The precompiled kernel from openwrt won't work. u-boot needs the kernel to be in uImage format. If all you have is zImage, then you will find my instructions in some other thread in this forum useful. Also don't forget to include a device tree blob as well - the kernel won't boot without it.

If you believe you have everything in place, then attach the serial console, enter u-boot and try to load your kernel manually (took me several attempts). After that try to permanently store your manual steps in the u-boot configuration (will be on some unused part of the SD-Card). That's pretty much it - the general idea anyway.

I think you will be able to figure out the specifics as you go along. If you really get stuck somewhere, then feel free to ask again.

HTH,
Harald
Title: Re: Newbie question: can iMx233 Olinuxino-Micro boot from USB?
Post by: jGrey on August 26, 2014, 07:30:17 pm
Hello lambda,

Thank you very much for your input. As I said that I'm a newbie in this area, and I'm taking some time to
digest the ideas you guys provided. Then I have a few questions.

The first question is that how the u-boot works, and where does it located. I guess it resides in the first
partition and it will be executed firstly in the booting process? So we have to load this part firstly,
then add the linux kernel. It sounds like that we'll be working on a blank SD card. Am I right? Can we work
on the current SD card?

The current micro SD card has the linux image and it boots up when the power in turned on. Then, part of the
linux image will be moved to the RAM and the system runs from there, even the SD card is removed, the system
will still be functional. I don't know if it's functioning 100%, or just very limited? My question is, at
this moment, what we can do if a second SD card is inserted. To read/write/edit the second SD card? How?
What is the difference between the SD card with or without the u-boot part? My understanding on your first
reply dated as 8/20 is that, if we have a micro SD card with the u-boot AND linux kernel, booting up, then
we might be able to write to the second, third, ... micro SD cards. Please advice.

Thanks a lot for your time and input.


we may remove it and use the slot to do more. That is what I'm very much interested!
Title: Re: Newbie question: can iMx233 Olinuxino-Micro boot from USB?
Post by: JohnS on August 26, 2014, 08:05:46 pm
Such things are usually on linux-sunxi.org and will apply quite a lot for iMX

uboot has its own site...

John
Title: Re: Newbie question: can iMx233 Olinuxino-Micro boot from USB?
Post by: mbergmann on August 27, 2014, 10:13:22 am
Hi jGrey,

have you read Christian Janns blog entry about u-boot on i.MX233?

http://www.jann.cc/2013/02/07/u_boot_for_the_imx233_olinuxino.html

Mike
Title: Re: Newbie question: can iMx233 Olinuxino-Micro boot from USB?
Post by: lambda on August 27, 2014, 02:59:54 pm
Quote from: jGrey on August 26, 2014, 07:30:17 pm
The first question is that how the u-boot works, and where does it located. I guess it resides in the first
partition and it will be executed firstly in the booting process? So we have to load this part firstly,
then add the linux kernel. It sounds like that we'll be working on a blank SD card. Am I right? Can we work
on the current SD card?


Yes, preparing a SD card with uboot is very similar to preparing a SD card with a linux kernel.

In the traditional way you have a linux.sb file (the kernel) and a rootfs image.
You put the linux.sb file on the first partition and the rootfs image on the second.

In the uboot way you have an uboot.sb file (the boot loader), an uImage file (the linux kernel) and a rootfs image.
You put the uboot.sb file on the first partition like you did with the linux.sb file in the past, so that imx233 finds it at boot time. Then you put the uImage and the rootfs image whereever you want: Can be on USB storage, can be on additional partitions, you can put the uImage inside the rootfs or you can even put it on some network device, if your uboot has network support.

Quote
The current micro SD card has the linux image and it boots up when the power in turned on. Then, part of the
linux image will be moved to the RAM and the system runs from there, even the SD card is removed, the system
will still be functional. I don't know if it's functioning 100%, or just very limited? My question is, at
this moment, what we can do if a second SD card is inserted.


There is a difference between kernel and rootfs:
The kernel will be copied to RAM by uboot entirely. Once the kernel is in RAM you can safely remove the device where it was stored. In theory you could even do that without uboot if you crafted a clever enough linux.sb file.

The rootfs OTOH needs to be constantly available. (You could load it into a RAM disk, but with only 64MB of RAM available, that would necessarily be a limited system.) So if you want to use the micro SD slot for something else, you must not put the rootfs on the SD card and you need a kernel with all necessary drivers, to access the rootfs at boot time, compiled in.

Quote
To read/write/edit the second SD card? How?
What is the difference between the SD card with or without the u-boot part? My understanding on your first
reply dated as 8/20 is that, if we have a micro SD card with the u-boot AND linux kernel, booting up, then
we might be able to write to the second, third, ... micro SD cards. Please advice.


From linux, the SD card looks just like any other block device: You can use the usual tools (fdisk, mkfs, dd, mount, ...) to work on it. Of course you can use them on the SD card you booted from. The only difficulty is, that if you want to insert a second, third, etc. SD card, you have to move the rootfs somewhere else first.

HTH,
Harald