Ttimgextract

From OpenTom

Jump to: navigation, search

ttimgextract

A tool to extract the ttsystem images into their components.


this tool extracts the parts into the place where the to-be-dissected file is. this can cause a full flash card if you happen to dissect the file with something along the line :

~/ttimgextract /mnt/ttsystem

the filesystem mounted on /mnt now will hold the dissected parts.

(maybe something to change tonight)

Detailed usage of the tool:

get it:

  wget http://svn.opentom.org/opentom/trunk/ttimgextract/ttimgextract.c

build:

  gcc -o ttimgextract ttimgextract.c

run:

  ./ttimgextract ttsystem

decompress:

  gunzip < ttsystem.0 > ttsystem.cpio

list archive:

  cpio -t -v < ./ttsystem.cpio

Note that the current ttimgextract version in the svn repository does not work on machines with the reverse byte order, such as PowerPC.

Alternative method

An alternative (very trivial) method to extract the ramdisk image instead of using ttimgextract is as follows:


1. copy ttsystem from the TTGO and perform the following command:


od -l -j4 -N4 ttsystem


the output of this command produces the size of the gzip file ramdisk.cpio.gz (CPIO format). Alternatively, open ttsystem with an hexadecimal editor, extract 4 bytes at position 4 following the ‘TTBL’ initial string; swap them and convert the result to a decimal number (unsigned long).


2. e.g., use the following command to extract the filesystem archive:


dd if=ttsystem bs=1 skip=12 count=<size> | gzip -d | cpio -id


where <size> is the returned number from the previous od command.


tar can also be used if supporting cpio gzip:

dd if=ttsystem bs=1 skip=12 count=<size> | bsdtar -tf -

Alternatively, open ttsystem with an hexadecimal editor, extract <size> bytes at position 12, save the result as ramdisk.cpio.gz; unzip this file to ramdisk.cpio and read/extract its content through cpio.

Notice that commands od, dd, gzip and cpio are needed (for the related Windows porting, e.g., check http://www.cygwin.com or http://gnuwin32.sourceforge.net or many other sites).


Example.

od -l -j4 -N4 ttsystem
0000004     2655011
0000010


The value 2655011 is the size of the ramdisk image.

Consequently, the following command produces the list of files included in the ramdisk image:


dd if=ttsystem bs=1 skip=12 count=2655011 | gzip -d | cpio –idt


bin
bin/[
bin/apnd
bin/ar
bin/ash
bin/basename
…
sbin/syslogd
sys
tmp
var
var/log
var/run
var/tmp
11026 blocks

With cygwin, the following shell script will extract all the files included in the ./ttsystem package to the current directory:

set -- `od -l -j4 -N4 ttsystem`
dd if=ttsystem bs=1 skip=12 count=$2 | gzip -d | cpio -id

Note: this methods have been tested with TTGO version 5 formats. Version 4 should use a different package format.

If you are lazy and you do not want to fiddle with man pages so that you can extract ro a specific location here is a more flexible script to do the job:

#!/bin/sh
CWD=$(pwd)
ORGTTIMAGE=${1:-"${CWD}/ttsystem"}
OUTPUT_DIR=${2:-"${CWD}/ttsystem_root"}
NAME=$(basename $0)

usage ()
{ [ "$*" != "" ] && echo $*
  cat << EOF

Usage:
$NAME [ttsystem image path] [extract directory]

If [ttsystem image path] is not specified ./ttsystem_root will be used.
If [extract directory] is not specified ./ttsystem_root will be used.

[extract directory] must not exist before running this script.
EOF
  exit 1
}

[ "$1" = "-h" ] && usage
[ ! -r $ORGTTIMAGE ] && usage "Error: No ttsystem found"
if [ -d $OUTPUT_DIR ]
then
  cat << EOF
Directory $OUTPUT_DIR already exists ...
Please remove it before running this or change destination directory.
EOF
  exit 1
else
  mkdir -p $OUTPUT_DIR
fi

IMAGE_SIZE=$(od -l -j4 -N4 $ORGTTIMAGE |head -1 |awk '{print $NF}')
cd $OUTPUT_DIR
dd if=$ORGTTIMAGE bs=1 skip=12 count=$IMAGE_SIZE |gunzip -c | cpio -id
Personal tools