element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Members
    Members
    • Benefits of Membership
    • Achievement Levels
    • Members Area
    • Personal Blogs
    • Feedback and Support
    • What's New on element14
  • Learn
    Learn
    • Learning Center
    • eBooks
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Dev Tools
    • Manufacturers
    • Raspberry Pi
    • RoadTests & Reviews
    • Avnet Boards Community
    • Product Groups
  • Store
    Store
    • Visit Your Store
    • Choose Another Store
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
RIoTboard
  • Products
  • Dev Tools
  • Single-Board Computers
  • RIoTboard
  • More
  • Cancel
RIoTboard
Blog Linux on the RIoTBoard Part 5: SDCard Image
  • Blog
  • Forum
  • Documents
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
RIoTboard requires membership for participation - click to join
Blog Post Actions
  • Subscribe by email
  • More
  • Cancel
  • Share
  • Subscribe by email
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: radiatortwo
  • Date Created: 19 Sep 2014 10:43 AM Date Created
  • Views 1046 views
  • Likes 1 like
  • Comments 16 comments
Related
Recommended

Linux on the RIoTBoard Part 5: SDCard Image

radiatortwo
radiatortwo
19 Sep 2014

This series of blog posts contains the following parts:

1. The bootloader U-Boot

2. The Kernel

3. Debian Root File System

4. Flashing with MFGTool in Windows

5. Creating an SDCard image (This part)


Part 5: SDCard Image


This is the last part of this series.

Here we will create an image that we can use to flash directly on an SDCard we then can boot from.


This is for those who don´t use Windows with MFGTool, but wan´t to use Linux to flash our created system.


There are different methods to achieve this.

One is creating an image from an already flashed system on the RIoTBoard onto an SDCard.

Not really an option since we then would need our system already flashed, which we don´t have.


The second method would be that we use an SDCard reader that´s connected to our building system.

And then do the same steps as MFGTool would do to flash it in Windows.


The other one is, that we create a virtual image file on our building system and mount it as a virtual disk.

And then also do the same steps as MFGTool would do to flash it in Windows.


Since both methods are almost the same and virtual machines often have problems with USB passthrough or like me having no physical access to the building system at all, we´re doing the third method here.


If you have an SDCard reader connected to your build system, you can skip to Step 5.


So let´s get started.


What you need are the previously created files.

- u-boot.imx

- boot.scr

- linux-kernel.tgz

- oneiric.tgz


Step 1:

These additional packages are not essential for this. But they make it a lot easier to create the image.

 

apt-get install qemu-utils kpartx

 

Step 2:

Choose a place where to store the image file.

Since all the files we need for this are stored in one folder let´s do it there.

 

cd /home/riotboard/linux/output

 

Now we will create the image file.

You could use dd for this, but with the qemu-tools it´s a bit easier.


But what size should the file be?

Most 4 GB SDCards have about 3.7 GB of usable space.

So that should be the size right?

Well but what if we want to actually copy the image from our SDCard onto the RIoTBoards eMMC?

Looking at that it only has 3.6 GB of usable space.


So we will create an image file with 3600 MB.

 

 

qemu-img create sdcard.img 3600M

 

So if we now do this...

 

ls -lh sdcard.img


... we see the file is exactly 3.6 GB in size.

-rw-r--r-- 1 root root 3,6G Sep 18 23:21 sdcard.img


Step 3:

Now we need to partition the file.

Looking at our script we are using in MFGTool we find a simple little command that does the trick.


sfdisk --force -uM sdcard.img << EOF
10,,83
EOF

 

Step 4:

Now that we have a file we can use, we need to format the partition inside.

But how? It´s still only a file.

Well that is done through a mapping of a loopback device onto a specific part of the file.

Normally we would do this manually by executing something like "losetup -o 32256 --sizelimit 5160448 /dev/loop1 sdcard.img".

But then you would have to calculate that offset and the sizelimit for every partition you created.

And if you´re using several partitions that can be a real pain in the ass.

 

Luckily I´ve found a little tool that does that for us completely automatic.

And that´s kpartx.

All we have to do is this.

 

kpartx -av sdcard.img

 

After execution you see a line like this.

add map loop0p1 (253:0): 0 7148925 linear /dev/loop0 16065

If we had more than one partition we´d see more lines. One for every partition.

The interesting part here now is the mapping loop0p1.

 

Step 5:

We now have our device and will format and then mount it.

(If using an SDCard reader, replace /dev/mapper/loop0p1 with your device /dev/sdb or whatever it is recognized with from this point on.)

 

mkfs.ext4 -j /dev/mapper/loop0p1
mkdir -p /mnt/sdcard
mount -t ext4 /dev/mapper/loop0p1 /mnt/sdcard

 

Step 6:

Now that the partition is mounted we can extract our file system, as well as the kernel and the modules.

Also we copy the bootscript into place.

 

tar --numeric-owner -C /mnt/sdcard -zxvf oneiric.tgz
tar --numeric-owner -C /mnt/sdcard -zxvf linux-kernel.tgz
cp boot.scr /mnt/sdcard/boot.scr

 

Step 7:

Unmount the partition and then remove the loopback mapping again with kpartx.

 

umount /mnt/sdcard
kpartx -dv sdcard.img

 

Step 8:

Now we need to integrate u-boot into the file.

That can be done with dd. But if we do it just like in MFGTool we will only overwrite the file and all the stuff we´ve done so far would be gone.

So we have to do it like this.

 

dd if=u-boot.imx of=sdcard.img bs=512 seek=2 conv=notrunc

 

With "conv=notrunc" at the end, we tell dd to only overwrite the beginning of the file and leave the rest as is.

 

Let´s check if that worked.

 

ls -lh sdcard.img

 

If everything went right, the image file should still be 3.6 GB in size.

-rw-r--r-- 1 root root 3,6G Sep 18 23:52 sdcard.img

 

Now the image is done and ready to flash onto an SDCard.

 

Of course if we want to copy or download it we don´t want such a big file.

So let´s pack it into a zip file.

 

zip RiotboardLinux3.17SD.zip sdcard.img

 

And that´s it.

You now can flash the file with dd like this onto an SDCard.

 

dd if=sdcard.img of=/dev/sdb bs=4K

 

Or with Windows you can use a tool like Win32 Disk Imager to write it onto your SDCard.

 

Then put the SDCard in your RiotBoard.

Set the Dip Switches to 2,4,5,7 Off rest On for a normal SDCard or for the Micro SDCard to 2,4,5,8 Off rest On.

 

And that´s it for this series.

Hope you enjoyed this and are now able to create your own Linux system for the RIoTBoard.

  • Sign in to reply
  • tusharp
    tusharp over 6 years ago in reply to Former Member

    try yocto based image

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Former Member
    Former Member over 6 years ago

    hi

    can u pls tell why my HDMI not working with riotboard booting with sdcard.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Former Member
    Former Member over 7 years ago in reply to radiatortwo

    Can you help me out on configuration u-boot at step 1 of the tutorial?

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • radiatortwo
    radiatortwo over 7 years ago in reply to Former Member

    Unfortunately the server is no more. With all it´s data...

     

    I´d have to recreate the image. But this would take some more time because some stuff has changed.

     

    I also don´t have a RioTBoard I could use to test it right now and don´t plan to buy another one.


    I´d suggest you go through the tutorial yourself. If you need help just ask. I´ll try to help.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Former Member
    Former Member over 7 years ago

    Hello Otto,

     

    First i want to thank you for this great tutorial. I tried to download your image but the radisserver seems to be down. Could you reupload it somewhere please?

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
>
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2023 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • Facebook
  • Twitter
  • linkedin
  • YouTube