C3000 Device Specifics

From OESF

(Difference between revisions)
Jump to: navigation, search

Line 1:

Line 1:

- 

Line 12:

Line 11:

== The traditional Zaurus layout ==
== The traditional Zaurus layout ==
- 
Traditional Zaurus models using NAND flash for user storage tend to use a set of independently mounted NAND regions to produce a software distribution layout that when running a Sharp ROM (or derivative) allow return to a default state by zeroing and reinitializing some of these regions.
Traditional Zaurus models using NAND flash for user storage tend to use a set of independently mounted NAND regions to produce a software distribution layout that when running a Sharp ROM (or derivative) allow return to a default state by zeroing and reinitializing some of these regions.

Line 27:

Line 25:

== The SL-C3000 layout ==
== The SL-C3000 layout ==
- 
The SL-C3000 differs slightly from the traditional Zaurus models that have adequate space available within NAND flash to maintain user data, user installed applications and the Qtopia environment.
The SL-C3000 differs slightly from the traditional Zaurus models that have adequate space available within NAND flash to maintain user data, user installed applications and the Qtopia environment.

Line 98:

Line 95:

== Doing a better job for /home ? is it possible. ==
== Doing a better job for /home ? is it possible. ==
- 
I had been thinking along the lines of moving /home to a hdd location by the use of mount bind points such that /home/root/etc and other such locations could be bound back to flash regions whilst /home itself resided upon the hdd.
I had been thinking along the lines of moving /home to a hdd location by the use of mount bind points such that /home/root/etc and other such locations could be bound back to flash regions whilst /home itself resided upon the hdd.

Line 112:

Line 108:

== Zeroing an SL-C3000 ==
== Zeroing an SL-C3000 ==
- 
To return an SL-C3000 back to factory settings simply remove the power and battery, reinsert the battery, plug in the mains cable and ensure that the battery cover lock is in the locked position then perform the following steps.
To return an SL-C3000 back to factory settings simply remove the power and battery, reinsert the battery, plug in the mains cable and ensure that the battery cover lock is in the locked position then perform the following steps.

Line 130:

Line 125:

== Examining the flashing process ==
== Examining the flashing process ==
- 
Firstly it's important to understand that the flashing process is a shell script that runs from /bin/sh under Linux.
Firstly it's important to understand that the flashing process is a shell script that runs from /bin/sh under Linux.

Line 155:

Line 149:

We shall examine now the installer script from the Sharp ROM 1.11JP and make some comments. (actually it's slightly modified to correct a bug in the original). I have inserted some comments to make this more readable... denoted by ##.
We shall examine now the installer script from the Sharp ROM 1.11JP and make some comments. (actually it's slightly modified to correct a bug in the original). I have inserted some comments to make this more readable... denoted by ##.
 +
<code>
#!/bin/sh
#!/bin/sh

Line 607:

Line 602:

exit 0
exit 0
 +
</code>
Now following script completion the system shall restart. Please note that the default Sharp script shown does NOT erase the /home, /hdd2 or /hdd3 areas.
Now following script completion the system shall restart. Please note that the default Sharp script shown does NOT erase the /home, /hdd2 or /hdd3 areas.

Line 612:

Line 608:

== Preparing a Kernel for use with the Sharp Installer ==
== Preparing a Kernel for use with the Sharp Installer ==
- 
I'm not going to talk you through building a custom Kernel. If you need that kind of help you probably shouldn't be thinking of prepping a Kernel for flashing.
I'm not going to talk you through building a custom Kernel. If you need that kind of help you probably shouldn't be thinking of prepping a Kernel for flashing.

Line 625:

Line 620:

== Creation of a new initrd for the SL-C3000 ==
== Creation of a new initrd for the SL-C3000 ==
- 
The initrd on the SL-C3000 is simply a jffs2 image. It is, however, shipped with a 16 byte version header so here's how to successfully extract an image to work from....
The initrd on the SL-C3000 is simply a jffs2 image. It is, however, shipped with a 16 byte version header so here's how to successfully extract an image to work from....
 +
<code>
modprobe mtdcore
modprobe mtdcore
modprobe jffs2
modprobe jffs2

Line 649:

Line 644:

rmmod mtd_blkdevs
rmmod mtd_blkdevs
rmmod mtdcore
rmmod mtdcore
 +
</code>
This will create you a nice initrd tar file that you can extract and work with.
This will create you a nice initrd tar file that you can extract and work with.

Line 658:

Line 654:

A WORD OF WARNING when repacking the home structure into a new .home_default.tar... the version of tar built into the Sharp ROM is roughly equivalent to version 1.12 of GNU tar, particularly with respect to the format of device files stored in the tar. Since the /dev directory is stored within the initrd it is absolutely CRITICAL that you repack the .home_default.tar in the right format. If you type 'tar –version' this will get you the version number back. If its a later version of tar than 1.12 you need the following format for the tar command...
A WORD OF WARNING when repacking the home structure into a new .home_default.tar... the version of tar built into the Sharp ROM is roughly equivalent to version 1.12 of GNU tar, particularly with respect to the format of device files stored in the tar. Since the /dev directory is stored within the initrd it is absolutely CRITICAL that you repack the .home_default.tar in the right format. If you type 'tar –version' this will get you the version number back. If its a later version of tar than 1.12 you need the following format for the tar command...
-
tar -c –format=oldgnu -f .home_default.tar home/
+
<code>tar -c –format=oldgnu -f .home_default.tar home/</code>
Be sure to run the command from a directory containing nothing else but the home directory structure as this will all get expanded to the Z following a 'device zero' condition.
Be sure to run the command from a directory containing nothing else but the home directory structure as this will all get expanded to the Z following a 'device zero' condition.

Line 672:

Line 668:

...and finally concatenate as follows...
...and finally concatenate as follows...
-
cat initrdheader initrd.jffs2 > initrd.bin
+
<code>cat initrdheader initrd.jffs2 > initrd.bin</code>
This will produce an initrd.bin that is compatible with the installer shown in this paper.
This will produce an initrd.bin that is compatible with the installer shown in this paper.

Line 678:

Line 674:

== Prior to flashing ==
== Prior to flashing ==
- 
Please remember the installer shown in this document is 'fixed'. Using the original Sharp installer with custom kernels tends to brick the devices (remember that nice part of the script that erases the Kernel flash area).
Please remember the installer shown in this document is 'fixed'. Using the original Sharp installer with custom kernels tends to brick the devices (remember that nice part of the script that erases the Kernel flash area).

Line 686:

Line 681:

To modify this script you need a copy of a utility called endecsh which you can probably google for but here's the source in case you want to build it.
To modify this script you need a copy of a utility called endecsh which you can probably google for but here's the source in case you want to build it.
 +
<code>
/*
/*
* Encode Decode shell script Ver 0.1
* Encode Decode shell script Ver 0.1

Line 798:

Line 794:

return 0;
return 0;
}
}
 +
</code>

Revision as of 13:09, 5 April 2005


Contents

Device Description

The SL-C3000 is the first attempt by Sharp to introduce a hard disk drive to the Zaurus range in the form of a 4Gb Hitachi Microdrive.

In placing the 4Gb Microdrive in the unit Sharp have also significantly reduced the amount of NAND flash memory present within the unit to 16Mb which still has some major significance in the operation of the software distribution on the Zaurus.

I'll mention one more thing here because I may not mention it later. If you shutdown -h the SL-C3000 it does NOT power down (or look like it) like the previous models did. The screen will stay on and the device will freeze. To completely drop the device following shutdown you should open the battery compartment and push the recessed reset switch that sits on the side of the battery compartment nearest the centre of the unit – you don't need to remove the battery to do this.


The traditional Zaurus layout

Traditional Zaurus models using NAND flash for user storage tend to use a set of independently mounted NAND regions to produce a software distribution layout that when running a Sharp ROM (or derivative) allow return to a default state by zeroing and reinitializing some of these regions.

Typically the NAND based models have a read only file system carrying a more or less static distribution of the OS, GUI and toolsets which is based upon a jffs2 file system and provides the root mount point for the Linux distribution. The actual files that are targeted at the distribution are kept in directories with names similar to '/usr/bin.rom, /usr/sbin.rom' such that they don't clash with regions typically associated with user modification (equivalent /usr/bin, usr/sbin). The user modification regions that are somewhat scattered across a standard Linux distribution are symbolic links within the root file system that redirect access to areas within the /home part of the file system which is mounted as a read/write area. Typically /usr/bin on the root file system will be a symbolic link pointing at /home/root/usr/bin and within the /home/root/usr/bin directory a set of symbolic links are present for each utility that is present within /usr/bin.rom.

This mechanism allows the root file system to be mounted as read only so that integrity may be preserved (against user changes) whilst allowing the flexibility of user changes to take place within the file system mounted on /home only.

The 'device zero' process or factory erase will wipe the /home partition and the startup scripts of the Zaurus are configured to unpack from the root file system a default set of symbolic links such that the device may be reinitalized to the factory state.

Note that we haven't discussed many of the symbolic links off the root file system, just understand that on a more or less traditional Zaurus configuration if you can write to an area of flash then it will be stored upon the /home directory so that your changes may be purged on device zero.


The SL-C3000 layout

The SL-C3000 differs slightly from the traditional Zaurus models that have adequate space available within NAND flash to maintain user data, user installed applications and the Qtopia environment.

In fact the flash memory on the SL-C3000 is so small that Sharp haven't even bothered trying to place the main operating environment into it.

Instead the distribution layout works as follows.

There is a read only flash region corresponding to the region on the traditional Zaurus. It is only 5Mb in size, whereas on a traditional Zaurus ROM this partition could be up to 50Mb!

There is a /home region of read write flash used to maintain configuration data that may need to be present before the hard drive is available or whilst the hard drive is suspended (i.e. device wakes with critically low power and suspends immediately – this operation should not need to resume the HDD). This region is only 4Mb in size and is a precious resource that should be used sparingly.

The hard drive is presented as a CF device in Slot 1 of the two slot controller with the user CF slot being slot 0 (equivalent to traditional Zaurus).

The user boot environment is entirely dependent upon having a working hard disk image because as previously mentioned the NAND flash is too small to accommodate the Qtopia environment.

Traditional disk partitioning is therefore as follows.

/dev/hda1, mounted as /hdd1 (read only) - default raw size ~100Mb and default ext3 - Sharp ROM uses about 50Mb of this - giving approximately 50Mb of EASY expansion for ROMs without reformatting. - this replaces all those /usr/QtPaltmop.rom type locations with... /hdd1/usr/QtPalmtop.rom, /hdd1/usr/QtPalmtop/bin.rom...sbin.rom etc.

/dev/hda2, mounted as /hdd2 (read write) - default raw size ~400Mb and default ext3 - This is where your user installed apps go - 400Mb of uncompressed space amply replaces the compressed jffs2 that you get on the flash models. /home/zaurus/Application is symbolically linked to /hdd2/Applications using this partition for traditional Qtopia application data.

/dev/hda3, mounted as /hdd3 (read write) - default raw size ~3.3Gb and default to vfat - /home/zaurus/Documents is symlinked to /hdd3/Documents and is the default location for the Samba home share etc..

There are some good things about this configuration and some bad things.

The good things are that basically everything needed to recreate the environment may be stored on the first hdd partition and a reasonable amount of effort has been made to ensure that user data goes onto the 3rd or 2nd partitions.

The bad thing related to this configuration is that if you are building up an environment for use and trying to apply traditional Zaurus applications which are widely used on the other models then you need to be extremely careful as to where these applications install their files.

For example a 'well behaved' application installation for the Zaurus will place all files somewhere downward of /opt/QtPalmtop. This is fine on the SL-C3000 because this region is actually symbolic linked into /hdd2/QtPalmtop.

Badly behaved applications (from the perspective of this environment) may place data into other read/write areas that aren't symbolically linked to the hdd i.e. /home or even /home/zaurus which actually lives in the /home flash partition.

None of these issues are terminal, they can all be worked around, however, a regular user installing some applications without the knowledge of how to adapt the install to the 3000 may have some difficulty.

Some examples of problem applications and resolutions are...

One version of apache-php places the entire install within /home/www. This install is 5Mb in size and because it goes to /home/www it misses the HDD completely and attempts to install in flash – which it doesn't – it fails mid way leaving all the space eaten up on flash. This can be overcome by pre-creating a link to a directory on the HDD. I suggest that /hdd2 locations are good candidates for this kind of activity.. i.e. mkdir /hdd2/www && ln -s /hdd2/www /home/www. If you do this prior to installation then the package will expand across the link and onto the hdd. ScummVM has a looming issue for some users in that the default location for storing saved game files is in ~ or the home directory. For the user 'zaurus' the home directory is in flash. Users using scummvm should change the settings so that saved game files go into /home/zaurus/Documents which is symbolic linked onto partition 3 of the hdd (the big one).

Basically if you do get an application installed. Run it a few times, particularly try saving things and then check if there's anything going into ~.

The device zero process on the SL-C3000 rebuilds the environment to factory state (or ROM install state) in a similar manner to the traditional Zaurus. However, instead of handling just flash, this process now recovers the hdd layout to a factory state too (as long as /hdd1 is intact and that /hdd2 and /hdd3 are partitioned).

The device zero process now performs the following sequence.

/home (on /dev/mtdblock3), /hdd2 (/dev/hda2) and /hdd3 (/dev/hda3) are all unmounted and formatted.

The file systems are then all remounted in those respective locations.

/hdd1/.sys/hdimage2.tgz is a tarball which is extracted at the root level, it contains /hdd2 layout including all symbolic links that point into /hdd1/usr/bin.rom, /hdd2/usr/sbin.rom, /hdd2/usr/QtPalmtop.rom etc. along with a basic structure for /hdd3.

/root/.home_default.tar (from the read only flash location) is then extracted at root. This contains the flash based elements used to populate the /home directory structure on mtdblock3.

At this stage the device is in the factory shipped (or ROM install) state.


Doing a better job for /home ? is it possible.

I had been thinking along the lines of moving /home to a hdd location by the use of mount bind points such that /home/root/etc and other such locations could be bound back to flash regions whilst /home itself resided upon the hdd.

This idea, unfortunately, could lead to stability issues so was abandoned.

The main area of concern for moving /home is the availability of the subordinate locations whilst the hdd is in suspend mode because a critically low condition has special handling code that the kernel executes to immediately place the device back into suspension (without even displaying anything on the screen)... if you want to see this in action run your Z until flat, try to power it on a few times when it's showing completely flat, charge it then go into terminal and look at the kernel ring buffer using dmesg. You will see the emergency suspend stuff logged in there.

Even with mount bind placing the critical regions in flash we have to realise that they are still subordinate to /home and that inode traversal from /home to those subordinate locations (finding the bind point) will potentially trigger a required read of /home which will in turn attempt to use the hdd – not as efficient as maintaining the /home in flash.

We will have to be more inventive to find a better solution for /home in the future.


Zeroing an SL-C3000

To return an SL-C3000 back to factory settings simply remove the power and battery, reinsert the battery, plug in the mains cable and ensure that the battery cover lock is in the locked position then perform the following steps.

Hold down the OK button and keeping it held press the power button.

You will get a Japanese menu.

Select option 3.

You get another Japanese Menu.

Select option 1 – do NOT select option 2 unless you want a good 1hr wait (extensive erase writing /dev/zero over whole disk – did it once, it's not that exciting).

The device will ask you to confirm (in Japanese), hit Y and the device will reboot and recover to the factory/ROM default state.


Examining the flashing process

Firstly it's important to understand that the flashing process is a shell script that runs from /bin/sh under Linux.

You may ask how a flashing process works if the Linux is screwed. The answer is that there are two copies of Linux in flash on all clamshell units.

If you want to check this out then use the D+B device reset and the device will boot into a console of the version of Linux used for flashing and you can get at the utilities in /sbin (tested on SL-C3000 and on SL-C860) :-). (actually you don't get to see quite everything, you get an ext2 initrd mounted rw and I can't find the OK menu stuff in this image).

Reliably entering the D+B (emergency Linux) or maintenance menus (D+M) can be achieved as follows.

Remove power and battery. Ensure the battery lock is in the unlocked position. Hold down key combinarion (D+B or D+M). Whilst holding down the key combination insert the battery and slide the battery lock to the locked position.

Note (and I have tested this). If your fingers slip and you release the keys in between making contact with the battery and moving the slide lock then the device will go into a normal boot sequence so if you feel any sort of 'wobble' whilst doing this remove the battery again completely and then reinsert – it seems the firmware detection kicks in as soon as the battery contact is made.

The updater.sh script is decoded using the tool /sbin/decsh which is only present in this recovery position.

Basically following boot using the OK menus (OK held on device start) the updater.sh is passed through /sbin/decsh and into /bin/sh for execution.

The script then makes use of several other utilities present in /sbin which you really shouldn't mess about with unless you really understand them.

We shall examine now the installer script from the Sharp ROM 1.11JP and make some comments. (actually it's slightly modified to correct a bug in the original). I have inserted some comments to make this more readable... denoted by ##.

  1. !/bin/sh
    1. Script is called with location of files as arg[1]

DATAPATH=$1

    1. Define a temporary path

TMPPATH=/tmp/update

    1. These two file names are used by the script as storage locations
    2. when the original distribution files are chopped up.
    3. TMPDATA will end up with the actual data to be used whilst
    4. TMPHEAD contains a 16 byte version header stripped from the file.

TMPDATA=$TMPPATH/tmpdata.bin TMPHEAD=$TMPPATH/tmphead.bin

    1. Config flags, set to 1 will inhibit processing of that file type

WFLG_KERNEL=0 WFLG_INITRD=0 WFLG_MVERSION=0 WFLG_HDD=0

    1. Survey the mtd partitions from the /proc file system.

RO_MTD_LINE=`cat /proc/mtd | grep "root" | tail -n 1` if [ "$RO_MTD_LINE" = "" ]; then

   RO_MTD_LINE=`cat /proc/mtd | grep "\<NAND\>.*\<2\>" | tail -n 1`

fi RO_MTD_NO=`echo $RO_MTD_LINE | cut -d: -f1 | cut -dd -f2` RO_MTD_SIZE_HEX=`echo $RO_MTD_LINE | cut -d" " -f2` RO_MTD=/dev/mtd$RO_MTD_NO RO_MTDBLK=/dev/mtdblock$RO_MTD_NO RO_MTD_SIZE=`dc 0x$RO_MTD_SIZE_HEX 1024 /`

RW_MTD_LINE=`cat /proc/mtd | grep "home" | tail -n 1` if [ "$RW_MTD_LINE" = "" ]; then

   RW_MTD_LINE=`cat /proc/mtd | grep "\<NAND\>.*\<2\>" | tail -n 1`

fi RW_MTD_NO=`echo $RW_MTD_LINE | cut -d: -f1 | cut -dd -f2` RW_MTD_SIZE_HEX=`echo $RW_MTD_LINE | cut -d" " -f2` RW_MTD=/dev/mtd$RW_MTD_NO RW_MTDBLK=/dev/mtdblock$RW_MTD_NO RW_MTD_SIZE=`dc 0x$RW_MTD_SIZE_HEX 1024 /`

LOGOCAL_MTD=/dev/mtd1

    1. We exit this block with the important variables RO_MTD, RO_MTDBLK,
    2. RW_MTD, RW_MTDBLK and LOGOCAL_MTD
    1. Defines addresses for the Version and Master version blocks in
    2. flash.

VERBLOCK=0x48000 MVRBLOCK=0x70000

RESULT=0

Cleanup(){ rm -f $VTMPNAME > /dev/null 2>&1 rm -f $MTMPNAME > /dev/null 2>&1 rm $CTRLPATH/* > /dev/null 2>&1 rm $DATAPATH/* > /dev/null 2>&1 exit $1 } trap 'Cleanup 1' 1 15 trap 2 3

get_dev_pcmcia() { while read SOCKET CLASS DRIVER INSTANCE DEVS MAJOR MINOR; do

   echo $DEVS

done } get_dev_pcmcia_slot() {

   grep "^$1" /var/lib/pcmcia/stab | get_dev_pcmcia

} sleep 1 IDE1=`get_dev_pcmcia_slot 1` if [ "$IDE1" = "" ]; then

   echo "Error!! There is no HDD. Now retrying..."
   while [ "$IDE1" = "" ]; do

IDE1=`get_dev_pcmcia_slot 1`

   done
   echo "Found HDD!!"

fi

    1. You should be able to work this out!
  1. LINUXFMT=ext2

LINUXFMT=ext3 MKE2FSOPT= if [ "$LINUXFMT" = "ext3" ]; then MKE2FSOPT=-j fi

    1. Actually don't know what writerominfo does but I suspect
    2. That it surveys some existing information.
      1. Check model ###

/sbin/writerominfo MODEL=`cat /proc/deviceinfo/product` if [ "$MODEL" != "SL-C3000" ] then echo 'MODEL:'$MODEL echo 'ERROR:Invalid model!' echo 'Please reset' while true do done fi

mkdir -p $TMPPATH > /dev/null 2>&1

cd $DATAPATH/

    1. Main loop cycles through all files on the distribution source
    2. it's actually quite useful since you can omit certain files
    3. to omit certain operations when developing.

for TARGETFILE in zImage.bin zimage.bin ZIMAGE.BIN initrd.bin INITRD.BIN mversion.bin MVERSION.BIN do if [ -e $TARGETFILE ] then rm -f $TMPPATH/*.bin > /dev/null 2>&1 DATASIZE=`wc -c $TARGETFILE` DATASIZE=`echo $DATASIZE | cut -d' ' -f1`

    1. DATASIZE now contains the actual file size

#echo $TARGETFILE':'$DATASIZE'bytes' TARGETTYPE=Invalid

    1. Setting the target type allows the particular type of programming
    2. operation dependent upon the type of file – this bit deals with
    3. all the likely permutations of file name.
    4. Also note that this only deals with NAND type images.
    5. hdimage1 is handled later on!

case "$TARGETFILE" in zImage.bin) TARGETTYPE=Kernel;; zimage.bin) TARGETTYPE=Kernel;; ZIMAGE.BIN) TARGETTYPE=Kernel;; initrd.bin) TARGETTYPE=RoFs;; INITRD.BIN) TARGETTYPE=RoFs;; mversion.bin) TARGETTYPE=MasterVer;; MVERSION.BIN) TARGETTYPE=MasterVer;; *) continue ;; esac

case "$TARGETTYPE" in Kernel) if [ $WFLG_KERNEL != 0 ] then continue fi

    1. OK I'll discuss the main highlights once.
    2. WFLG_KERNEL = 1 is set so that the script understands
    3. that the kernel write operation is complete in case it
    4. encounters another variation of the file name on another
    5. loop.
    6. ISLOGICAL = 1 means that a raw nandlogical operation is performed
    7. rather than a nandcp. nandlogical is used to write non-filesystem
    8. type blocks to the flash.
    9. MODULEID = 5 identifies the flash block for the main Kernel
    10. MODULESIZE = 0x13C000 defines the UPPER LIMIT on the size
    11. ADDR = `dc 0xE0000` evaluates the start address to decimal
    12. ISFORMATTED = 1 is used to say that the block doesn't need erasing
    13. DATAPOS = 0 says that the data starts right at the beginning of
    14. the file.
    15. ONESIZE = 524288 is used as a block size for programming and
    16. percent display during the programming portion of the script.

WFLG_KERNEL=1 echo 'kernel' ISLOGICAL=1 MODULEID=5 MODULESIZE=0x13C000 ADDR=`dc 0xE0000` ISFORMATTED=1 DATAPOS=0 ONESIZE=524288

    1. HDTOP is set to be 16 bytes off the end of the file..

HDTOP=`expr $DATASIZE – 16`

    1. The version information is chopped out of the file and stored in
    2. the $TMPHEAD location – 16 bytes long (-s 16).

/sbin/bcut -a $HDTOP -s 16 -o $TMPHEAD $TARGETFILE ;; RoFs) if [ $WFLG_INITRD != 0 ] then continue fi WFLG_INITRD=1 echo 'RO file system' ISLOGICAL=0 MODULEID=6 MODULESIZE=0x500000 ADDR=0 ISFORMATTED=0 TARGET_MTD=$RO_MTD

    1. Since the data starts AFTER the version information on the
    2. initrd.bin file we bcut at 0 (no -a parameter)

DATAPOS=16 ONESIZE=1048576 /sbin/bcut -s 16 -o $TMPHEAD $TARGETFILE ;; MasterVer)

    1. Master version block is simple, we just do all the ops in the
    2. case statement. note the use of nandlogical because this is not
    3. a file system.
    4. verchg is used to manipulate the version information based upon
    5. the contents of the version information supplied.
    6. Note that the script reads the block, modifies it and then writes

if [ $WFLG_MVERSION != 0 ] then continue fi WFLG_MVERSION=1 echo 'Master version' MTMPNAME=$TMPPATH'/mtmp'`date '+%s'`'.tmp' /sbin/nandlogical $LOGOCAL_MTD READ $MVRBLOCK 0x4000 $MTMPNAME > /dev/null 2>&1 /sbin/verchg -m $MTMPNAME $TARGETFILE 0 0 > /dev/null 2>&1 /sbin/nandlogical $LOGOCAL_MTD WRITE $MVRBLOCK 0x4000 $MTMPNAME > /dev/null 2>&1 rm -f $MTMPNAME > /dev/null 2>&1 echo 'Success!'

    1. Note this is important... not break but continue..
    2. this loops back to the beginning of the for loop.
    3. This is why the mversion stuff never enters the NAND
    4. programming loop later.

continue ;; *) continue ;; esac

    1. Typically only formats file system type blocks, the Kernel block
    2. doesn't get this (refer back)

#format? if [ $ISFORMATTED = 0 ] then echo -n 'Flash erasing...' /sbin/eraseall $TARGET_MTD 2> /dev/null > /dev/null #/sbin/eraseall $TARGET_MTD 2 echo 'done' ISFORMATTED=1 fi

    1. Display % indicator and calculate the programming step

echo echo '0% 100%' PROGSTEP=`expr $DATASIZE / $ONESIZE + 1` PROGSTEP=`expr 28 / $PROGSTEP` if [ $PROGSTEP = 0 ] then PROGSTEP=1 fi

    1. Update the version block and master version block based upon
    2. the information provided in the image.

#00 means header information VTMPNAME=$TMPPATH'/vtmp'`date '+%s'`'.tmp' MTMPNAME=$TMPPATH'/mtmp'`date '+%s'`'.tmp' /sbin/nandlogical $LOGOCAL_MTD READ $VERBLOCK 0x4000 $VTMPNAME > /dev/null 2>&1 /sbin/nandlogical $LOGOCAL_MTD READ $MVRBLOCK 0x4000 $MTMPNAME > /dev/null 2>&1

#echo 'found header' /sbin/verchg -v $VTMPNAME $TMPHEAD $MODULEID $MODULESIZE > /dev/null 2>&1 /sbin/verchg -m $MTMPNAME $TMPHEAD $MODULEID $MODULESIZE > /dev/null 2>&1

#loop

    1. Cycle through the programming loop./

while [ $DATAPOS -lt $DATASIZE ] do #data create

    1. Cut a chunk into the $TMPDATA path...

bcut -a $DATAPOS -s $ONESIZE -o $TMPDATA $TARGETFILE

    1. Get the size of the cut data

TMPSIZE=`wc -c $TMPDATA` TMPSIZE=`echo $TMPSIZE | cut -d' ' -f1`

    1. Get the next DATAPOS for the next loop through.

DATAPOS=`expr $DATAPOS + $TMPSIZE`

#handle data file #echo 'ADDR='$ADDR #echo 'SIZE='$TMPSIZE

    1. Use nandcp for file system type images (initrd)

if [ $ISLOGICAL = 0 ] then next_addr=`/sbin/nandcp -a $ADDR $TMPDATA $TARGET_MTD 2>/dev/null | fgrep "mtd address" | cut -d- -f2 | cut -d\( -f1` if [ "$next_addr" = "" ]; then echo "ERROR:flash write" rm $TMPDATA > /dev/null 2>&1 RESULT=3 break; fi ADDR=$next_addr else

    1. Use nandlogical for other types of operations (including Kernel)

## Bug in Sharp bit ## original line... ## /sbin/nandlogical $LOGOCAL_MTD WRITE $ADDR $DATASIZE $TMPDATA > /dev/null 2>&1 ## didn't use correctly determined block size ## cause problems for other kernels /sbin/nandlogical $LOGOCAL_MTD WRITE $ADDR $TMPSIZE $TMPDATA > /dev/null 2>&1 ADDR=`expr $ADDR + $TMPSIZE` fi

rm $TMPDATA > /dev/null 2>&1

    1. Rudimentary % display in dots

#progress SPNUM=0 while [ $SPNUM -lt $PROGSTEP ] do echo -n '.' SPNUM=`expr $SPNUM + 1` done done

    1. NAND programming loop has finished

echo

  1. finish

rm -f $TMPPATH/*.bin > /dev/null 2>&1

    1. On error we blow the kernel away!! - just to brick the Z safely

if [ $RESULT = 0 ] then /sbin/nandlogical $LOGOCAL_MTD WRITE $VERBLOCK 0x4000 $VTMPNAME > /dev/null 2>&1 /sbin/nandlogical $LOGOCAL_MTD WRITE $MVRBLOCK 0x4000 $MTMPNAME > /dev/null 2>&1

rm -f $VTMPNAME > /dev/null 2>&1 rm -f $MTMPNAME > /dev/null 2>&1 echo 'Success!' else echo 'Error!' exit $RESULT fi fi done

    1. Now we deal with the HD image !

HDD1FILE=hdimage1.tgz

    1. HDD image

for TARGETFILE in hdimage1.tgz HDIMAGE1.TGZ do if [ -e $TARGETFILE ]; then if [ $WFLG_HDD != 0 ] then continue fi WFLG_HDD=1 echo echo 'HDD RO file system'

    1. Make doubly sure the hdd1 partition isn't mounted by checking
    2. for the telltale NotAvailable file which normally gets overmounted
    3. by the HDD.

if [ ! -f /hdd1/NotAvailable ]; then umount /hdd1 fi

    1. Format....

echo 'Now formatting...' mke2fs $MKE2FSOPT /dev/${IDE1}1 2> /dev/null > /dev/null e2fsck -p /dev/${IDE1}1 > /dev/null if [ "$?" != "0" ]; then echo "Error!" exit "$?" fi

    1. Mount...

mount -t $LINUXFMT -o noatime /dev/${IDE1}1 /hdd1 if [ "$?" != "0" ]; then echo "Error!" exit "$?" fi

cd / echo 'Now extracting...'

    1. Expand and extract using pipe rather than the tmp location.
    2. we may not have much space free in /tmp.

gzip -dc $DATAPATH/$HDD1FILE | tar xf - if [ "$?" != "0" ]; then echo "Error!" exit "$?" fi

    1. Yes, well judge your own conclusions what Sharp are doing here!

# delete java if no java model if [ ! -f /root/.java ]; then rm -rf /hdd1/usr/QtPalmtop.rom/j2me fi

    1. Update version stuff

## write check sum ORGFILE=$DATAPATH/mversion.bin if [ ! -f $ORGFILE ]; then ORGFILE=$DATAPATH/MVERSION.BIN fi MTMPNAME=$TMPPATH'/mtmp'`date '+%s'`'.tmp' /sbin/nandlogical $LOGOCAL_MTD READ $MVRBLOCK 0x4000 $MTMPNAME > /dev/null 2>&1 /sbin/verchg_hdd $MTMPNAME $ORGFILE 9 > /dev/null 2>&1 /sbin/nandlogical $LOGOCAL_MTD WRITE $MVRBLOCK 0x4000 $MTMPNAME > /dev/null 2>&1 rm -f $MTMPNAME > /dev/null 2>&1

    1. Remount file system prior to restart !

echo 'Success!' # remount as RO umount /hdd1 mount -t $LINUXFMT -o ro,noatime /dev/${IDE1}1 /hdd1 fi done

exit 0

Now following script completion the system shall restart. Please note that the default Sharp script shown does NOT erase the /home, /hdd2 or /hdd3 areas.


Preparing a Kernel for use with the Sharp Installer

I'm not going to talk you through building a custom Kernel. If you need that kind of help you probably shouldn't be thinking of prepping a Kernel for flashing.

Basically the approach that I have taken is simply to strip the last 16 bytes off the end of the Sharp Kernel image from the Sharp 1.11JP ROM as follows..

tail -c 16 zImage.bin-sharprom > kerneltail cat zImage.bin-mykernel kerneltail > zImage-prepped

This is really enough to get the ball rolling.


Creation of a new initrd for the SL-C3000

The initrd on the SL-C3000 is simply a jffs2 image. It is, however, shipped with a 16 byte version header so here's how to successfully extract an image to work from....

modprobe mtdcore modprobe jffs2 modprobe mtdram total_size=5120 erase_size=16 modprobe mtdchar mknod /dev/mtdblock0 b 31 0 modprobe mtdblock losetup -o 16 /dev/loop0 ./initrd.bin dd if=/dev/loop0 of=/dev/mtdblock0 losetup -d /dev/loop0 mount -t jffs2 /dev/mtdblock0 /mymountpoint cd /mymountpoint tar -cf ~/myinitrd.tar * cd rmmod mtdblock rmmod mtdram rmmod jffs2 rmmod mtdchar rmmod mtdpart rmmod mtd_blkdevs rmmod mtdcore

This will create you a nice initrd tar file that you can extract and work with.

Remember there are multiple permission sets in the initrd so you have to extract/work with the initrd whilst logged in as root.

You should also then probably extract root/.home_default.tar from the initrd as this is the seed for the /home partition and since /lib/modules is actually linked to /home/root/modules then you will have to add symbolic links to that if you add modules to the initrd.

A WORD OF WARNING when repacking the home structure into a new .home_default.tar... the version of tar built into the Sharp ROM is roughly equivalent to version 1.12 of GNU tar, particularly with respect to the format of device files stored in the tar. Since the /dev directory is stored within the initrd it is absolutely CRITICAL that you repack the .home_default.tar in the right format. If you type 'tar –version' this will get you the version number back. If its a later version of tar than 1.12 you need the following format for the tar command...

tar -c –format=oldgnu -f .home_default.tar home/

Be sure to run the command from a directory containing nothing else but the home directory structure as this will all get expanded to the Z following a 'device zero' condition.

Now, assuming that you have finished working with the initrd in a structure in a directory called initrd you need to get hold of mkfs.jffs2 (get this from the SL-C860 root image if you like off the Sharp developer site... Sharp didn't yet post the SL-C3000 image which is why we had to extract it.) and use the following command to build the jffs2 image.

mkfs.jffs2 -o initrd.jffs2 -e16k -r initrd

You then need to exract the version information from the Sharp initrd.bin....

head -c 16 sharp-initrd.bin > initrdheader

...and finally concatenate as follows...

cat initrdheader initrd.jffs2 > initrd.bin

This will produce an initrd.bin that is compatible with the installer shown in this paper.


Prior to flashing

Please remember the installer shown in this document is 'fixed'. Using the original Sharp installer with custom kernels tends to brick the devices (remember that nice part of the script that erases the Kernel flash area).

You MUST modify the installer in line with the modification shown around the nandflash area in the script otherwise the flaw in the original Sharp installer will assert itself.. seems to kick in if you have a Kernel even slightly bigger than the original (nice one Sharp).

To modify this script you need a copy of a utility called endecsh which you can probably google for but here's the source in case you want to build it.

/*

* Encode Decode shell script Ver 0.1
*----------------------------------------------------------------------------
* Copyright 2003 T.Yamashita
*
* This program is a no guarantee.
* This program is free software; you can redistribute it and/or modify
* it under the terms of version 2 of the GNU General Public License as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
*/
  1. include <stdio.h>
  2. include <string.h>

unsigned char enctable[256]={ 0x84,0x26,0xa7,0x29,0x10,0xba,0x1d,0xa4,0x15,0x0a,0x2f,0x74,0x0d,0x0e,0xdc,0xd2, 0x14,0x40,0xbc,0xb1,0x45,0x16,0x17,0x54,0xd9,0x0c,0x96,0xb2,0x8b,0xb4,0xc3,0x1b, 0x41,0x22,0x13,0x24,0xa1,0x38,0x27,0x44,0x19,0x34,0x81,0x36,0xed,0x2e,0x0b,0xc7, 0xac,0xc9,0x23,0x2a,0x35,0x2c,0xb6,0x6c,0x79,0xee,0x71,0x6d,0xd1,0x48,0x3b,0xe2, 0x5f,0x42,0x37,0xcd,0xd0,0x90,0xa5,0x88,0x85,0x7c,0x00,0xcb,0x4d,0x4e,0x82,0xfb, 0x80,0x51,0x97,0xb9,0xdd,0x56,0x93,0x7a,0x61,0x5a,0x5b,0x5c,0xf8,0x5e,0xf9,0x28, 0xf0,0xe9,0x03,0xb0,0x60,0xec,0x39,0xca,0x73,0xa8,0x6b,0x12,0x31,0xe4,0x30,0x25, 0xe7,0xc0,0x9d,0x6e,0x3e,0x50,0x77,0x02,0xbd,0x58,0x7f,0xd8,0x0f,0x9c,0x92,0x4b, 0x49,0xf1,0x57,0x1a,0xaf,0xeb,0x87,0x3c,0x70,0xf2,0xf7,0x8c,0x8d,0x8e,0xb7,0xbe, 0x91,0x1c,0x8f,0x94,0x89,0x7e,0x7d,0x98,0x09,0x9a,0x6f,0xc8,0x9f,0x9e,0xc4,0xfc, 0x8a,0xa2,0xa3,0x68,0xc5,0xa6,0x53,0xd7,0xe1,0xaa,0xd4,0x64,0x2d,0x69,0x66,0xb5, 0x04,0xfd,0xb3,0x43,0x3d,0x9b,0x2b,0xb8,0x5d,0x18,0xad,0xbb,0x99,0x20,0xbf,0xc1, 0x65,0x46,0xf3,0xce,0x33,0x63,0x21,0x76,0x52,0x3a,0x4f,0xcc,0xe5,0x47,0xcf,0x4c, 0xda,0x08,0xd3,0xab,0xd5,0x4a,0xae,0x86,0x06,0xfa,0xdb,0x83,0x59,0x7b,0xdf,0xe0, 0x11,0x72,0xe3,0x05,0xc2,0xc6,0xa9,0xe8,0x1f,0xea,0x6a,0x67,0x75,0xd6,0xef,0x95, 0x55,0xde,0x3f,0xf4,0xf5,0xf6,0x07,0x01,0xe6,0x78,0x1e,0xa0,0x32,0xfe,0xff,0x62 };

unsigned char dectable[256]={ 0x4a,0xf7,0x77,0x62,0xb0,0xe3,0xd8,0xf6,0xd1,0x98,0x09,0x2e,0x19,0x0c,0x0d,0x7c, 0x04,0xe0,0x6b,0x22,0x10,0x08,0x15,0x16,0xb9,0x28,0x83,0x1f,0x91,0x06,0xfa,0xe8, 0xbd,0xc6,0x21,0x32,0x23,0x6f,0x01,0x26,0x5f,0x03,0x33,0xb6,0x35,0xac,0x2d,0x0a, 0x6e,0x6c,0xfc,0xc4,0x29,0x34,0x2b,0x42,0x25,0x66,0xc9,0x3e,0x87,0xb4,0x74,0xf2, 0x11,0x20,0x41,0xb3,0x27,0x14,0xc1,0xcd,0x3d,0x80,0xd5,0x7f,0xcf,0x4c,0x4d,0xca, 0x75,0x51,0xc8,0xa6,0x17,0xf0,0x55,0x82,0x79,0xdc,0x59,0x5a,0x5b,0xb8,0x5d,0x40, 0x64,0x58,0xff,0xc5,0xab,0xc0,0xae,0xeb,0xa3,0xad,0xea,0x6a,0x37,0x3b,0x73,0x9a, 0x88,0x3a,0xe1,0x68,0x0b,0xec,0xc7,0x76,0xf9,0x38,0x57,0xdd,0x49,0x96,0x95,0x7a, 0x50,0x2a,0x4e,0xdb,0x00,0x48,0xd7,0x86,0x47,0x94,0xa0,0x1c,0x8b,0x8c,0x8d,0x92, 0x45,0x90,0x7e,0x56,0x93,0xef,0x1a,0x52,0x97,0xbc,0x99,0xb5,0x7d,0x72,0x9d,0x9c, 0xfb,0x24,0xa1,0xa2,0x07,0x46,0xa5,0x02,0x69,0xe6,0xa9,0xd3,0x30,0xba,0xd6,0x84, 0x63,0x13,0x1b,0xb2,0x1d,0xaf,0x36,0x8e,0xb7,0x53,0x05,0xbb,0x12,0x78,0x8f,0xbe, 0x71,0xbf,0xe4,0x1e,0x9e,0xa4,0xe5,0x2f,0x9b,0x31,0x67,0x4b,0xcb,0x43,0xc3,0xce, 0x44,0x3c,0x0f,0xd2,0xaa,0xd4,0xed,0xa7,0x7b,0x18,0xd0,0xda,0x0e,0x54,0xf1,0xde, 0xdf,0xa8,0x3f,0xe2,0x6d,0xcc,0xf8,0x70,0xe7,0x61,0xe9,0x85,0x65,0x2c,0x39,0xee, 0x60,0x81,0x89,0xc2,0xf3,0xf4,0xf5,0x8a,0x5c,0x5e,0xd9,0x4f,0x9f,0xb1,0xfd,0xfe };

void convert(unsigned char *table,FILE *ifp,FILE *ofp) { unsigned char rb[16],wb[16]; unsigned int read_cnt; int i;

do { read_cnt = fread(rb,1,16,ifp); if (read_cnt == 0) break; for (i = 0;i < read_cnt;i++) { wb[i] = table[rb[i]]; } fwrite(wb,1,read_cnt,ofp); } while (1); } int main(int argc, char* argv[]) { FILE *ifp,*ofp;

if (argc != 4) { printf("Encode\nendecsh -e source-file dest-file\nDecode\nendecsh -d source-file dest-file\n"); return 0; }

ifp = fopen(argv[2],"rb"); if (ifp == NULL) { printf("%s file not found.\n",argv[2]); return 0; }

ofp = fopen(argv[3],"wb"); if (ofp == NULL) { fclose(ifp); printf("Can't open %s file.\n",argv[3]); return 0; }

if (strcmp(argv[1],"-e") == 0 || strcmp(argv[1],"-E") == 0) { printf("Encode..."); convert(enctable,ifp,ofp); printf("OK.\n"); } else if (strcmp(argv[1],"-d") == 0 || strcmp(argv[1],"-D") == 0) { printf("Decode..."); convert(dectable,ifp,ofp); printf("OK.\n"); } else { printf("unknown option '%s'\n",argv[1]); }

fclose(ifp); fclose(ofp);

return 0; }

Personal tools