Modfying RSMedia root filesystems

4 posts / 0 new
Last post
Helibot's picture
Modfying RSMedia root filesystems

Hi All,

   In another thread  I promised to give some instructions on how to modify the files in the root file system for RSMedia. So here we go.....

In RSMedia the linux root file system (/) and the default file system(/mnt/default) consist of CRAMFS file system image files. These image files can be reprogrammed by the firmware upgrade process.  But if we can modify the image file used for the upgrade then we can change the files in the robots linux filesystem. So this allows us todo all sorts of changes. For example changing the boot sequence, adding new programs , changing existing programs ,adding libraries....almost anything actually!!!.


**If you flash the root file system with a bad image you can stop the robot from booting**
But if you follow the instructions below then you can experiment with the /mnt/default  partition (which will not stop he robot from booting). Once you have mastered that then you can try the system / root image.

Here is a bit of background on CRAMFS:-

The CRAMFS is a special linux filesystem type. It is a bit like a zip file where files are all stored compressed. So the file system is really just one big image file that contains a lot of smaller compressed files. The files in the CRAMFS cannot be modified. It is a read only file system.
BUT you can extract out the files from the big image file, modify them, then make a new big image file.
For RSMedia the big image file is flashed into /dev/nand1 or /dev/nand2

When RSMedia boots it opens the big image file and creates a virtual filesystem at /mnt/default (for nand2) and /  (for nand1)

 What are the dangers with changing the files:-
1) If you are modifying the /dev/nand1 (or root filesystem files) and we modify the wrong files you could stop the robot from booting. (but you can recover with the serial hack)
2) If we add too many files then you can make the image file bigger than the available space.

 What you need to change the files:

  1. A linux system with CRAMFS support installed.
    The Ubuntu VM version works well. (Details for setup are in the RSMedia Dev Kit see here) The instructions below are for using this linux distribution. 
    The Redhat 7.3 VM will work also (but the commands below will be slightly different.)
  2. A copy of the CRAMFS image  - you can get this from the original firmware files (see here for RSM V2 or here for RSM V1)
  3. The RSmedia serial hack is recommended but not required.


The instructions below are for reprogramming the /dev/nand2 ara (which maps to /mnt/default/ when the robot is booted).
ou should do this because if you muck it up the robot will still boot to linux OK!!.
Once you know how to change this section OK , then try the /dev/nand1 area (the / file system).

How to reprogram the default filesystem.
(These instructions are written for rebuilding the /mnt/default files for the RSMV2)
(For RSMV1 replace “rfs_default_V2.cramfs”  with “rfs_default.cramfs” in the instructions below)

  1. Copy the rfs_default_V2.cramfs from the RSMV2 Original firmware archive into the linux  home directory. 
  2. We need to command 'cramfsck' on the linux machine. Run this to check if its installed:-
    If it says not found/not installed then you need to install the cramfsprogs package.
    For Ubuntu VM the command to install it is :-
    #sudo apt-get install cramfsprogs
    (You will need internet access for it to install successfully)
  3. Now we use the cramfsk command to extract all the files:-
    #sudo rm –rf cramfs_rsm
    #sudo cramfsck -x cramfs_rsm rfs_default_V2.cramfs
    (root password is ‘user’ if you get asked)
    (We have to use 'sudo' because we need to extract the files as root user because we need root permissions to make some of the special files.)

    You may get a warning like “file extends past end of filesystem.” But don’t worry,  this is OK.
    You should not see any other errors.
    If you do ls cramfs_rsm you will see all the files from the image file are now real files in the directory cramfs_rsm

  4. Now (just as a test) we will use the mkcramfs command to rebuild the extracted files into a new cramfs image file.
    #cd ~
    #sudo rm -f rfs_new.cramfs
    #sudo mkcramfs cramfs_rsm rfs_new.cramfs

    We haven’t changed any files yet so the new file system image we have created (rfs_new.cramfs ) should be close in size to the original file (rfs_default_V2.cramfs).
    New file should be approx 9646080 bytes. (Original size was 10485760)

    If the new file is much smaller (ie less than 9.5Mb) then something has gone wrong and you shouldn’t continue.

  5. Now is the time to modify any files in ~/cramfs_rsm/
    Use any commands to add/copy/modify files that you want to change
    For my test I modified the splash screen pic in Personalities/RSMedia/Pictures. This is used if the robot boots without an SDCard.
    Initially make sure the changes you make are only small, there are limits to how much we can add to the file system. See below for details
    Now we repeat step 4 (but this time we will be including the files we changed in step 5.)
    So use the same command again to rebuild the new cramfs image file.
    #cd ~
    #sudo rm -f rfs_new.cramfs
    #sudo mkcramfs cramfs_rsm rfs_new.cramfs
    The size of the file may now differ from the original. We need to check it is not too big.
    For RSMV1 and RSMV2  the  it should be less than 10485760 bytes. (So it can grow by 835584 bytes)
  7. Now finally you can copy the new rfs_new.cramfs to the SDCard rsupdate directory as file rfs_default_V2.cramfs.
    And boot from the SDCard with it setup todo the ‘original firmware reflashing’ (see here for RSM V2 or here for RSM V1).

    When completed it should replace the /mnt/default with your newly created version
    (BTW You can rename/delete the other .cramfs files in the rsudpate directory it does not get programmed by the script)

 During step 7 the flash should work but it will report a checksum error.
This is because we did not change the expected checksum value (Called a ‘md5’ value)

Optionally you can use a program called ‘winmd5’ to make new checksum then copy the checksum into the file rfs_default.md5 in the rsupdate directory.

Note that  the numbers at the end of the line in  rfs_default.md5 is the size in bytes of the .cramfs file  – So you ALSO need to set that as well or it will also cause the checksum to fail.

How to reprogram the root filesystem.
If the above worked OK for you then you can try and reprogram the root file system. This is more dangerous because if it doesn’t work then the robot wont boot into linux again.

For RSM V2 repeat the above process but use “rfs_system_V2.cramfs” instead of “rfs_default_V2.cramfs” in the steps 1 AND 3 AND 7 above.
For RSM V1 repeat the above process but use “rfs_system.cramfs” instead of “rfs_default_V2.cramfs” in the steps 1 AND 3 AND 7 above.

Maximum sizes for default and system files for RSMV1 and RSMV2
I think I have worked out the maximum sizes for RSMV1 and RSMV2.
For the rsm_default.cramfs file (for both  RSMV1 and V2 ) the max size should be less than 10485760 bytes. So it can grow by 835584 bytes (ie 816 K – so that is actually quite big!!)

For the rsm_system_V2.cramfs (for RSMV2 only) the max size should be less than 7864320 bytes. So it can grow by 372736 bytes (ie 364 K – so that is actually quite big!!)

For the rsm_system.cramfs (for RSMV1 only) the max size should be less than 7340032 bytes. So it can grow by only 16384 bytes (ie 16 K – which is actually quite small – so be careful!!)

If you have problems
If you flash the default area (from rfs_default_V2.cramfs) and something goes wrong then you should be able to just use the original rfs_default_V2.cramfs with the firmware update script to recover.

If you flash the system/root area (from rfs_system_v2.cramfs) and something goes wrong then its likely the robot wont boot , you will likely need to use the serial hack and the bootloader to reflash the system/root file (BTW this can be achieved by following step 7 (and only step 7) in the “upgrade RSMV1 to RSMV2 firmware “ instructions.

So thats it....lots of info ... hope its works Ok for you!!.
Soon I hope create an image that will include more porgrams into the robot (like a better editor , the webs webserver, webpages and telnet server) . At startup it will run RSMAppmenu first, load the PPP drivers immediately and starts the Web server and Telnet client, then one of the menu options will be to start the original Wowwee UI and run the normal robot functions. 


ElectronicsGenius's picture


erikduop's picture

If you like ROBOTC and you like Arduino or you like ROBOTC and you have no idea what Arduino is............




VLC Player Download

ElectronicsGenius's picture

yea Helibot, you don't know squat! :P