Samsung Moment
Find Your Forum
  
Welcome, Guest. Please login or register.
Did you miss your activation email?

News: Do you like Samsung Moment?
Advanced search
Scratch-Proof your Samsung Moment        Best Price on Sprint Phones      Screen Protection Latest Ringtone for your mobile
Pages: 1 [2]
Print
Topic: Flashing Custom Content  (Read 6256 times)
zefie
Pro Member
****

Cookies: 29
Posts: 458


View Profile
« Reply #15 on: December 09, 2009, 11:52:32 PM »

btw my download of android eclair failed so.. idk
Logged
peepsalot
Jr. Member
**

Cookies: 8
Posts: 90


View Profile
« Reply #16 on: December 10, 2009, 04:28:22 PM »

btw my download of android eclair failed so.. idk
I did the following and it looks like I got all the code, haven't tried compiling yet:
Code:
mkdir eclair-source && cd eclair-source
repo init -u git://android.git.kernel.org/platform/manifest.git -b eclair
repo sync
Is that what you tried?

someone more proficient than I figure out how to decompress and re compress the zImage without destroying the decompression stub (aka still boot-able when repacked) so that we can hex edit the init.rc
I was looking into this last night.  I found out there is a script in the linux kernel source tree /scripts/extract-ikconfig which is supposed to be able to extract some config info from a zImage.  It doesn't really work for finding that config on our zImage, but I was able to look at the script source to see how it decompresses the data from zImage.  Basically it searches for the offset of the first occurence of hex values "1f 8b 08 00" which is the magic number used to identify .gz files.  In our stock zImage, this occurs at 0x33F0 (13296 in decimal).

If you take the file from that offset forward, then you can decompress it with standard tools.
Code:
dd bs=1 skip=13296 if=zImage of=Image.gz
zcat Image.gz > Image

As for putting it back into a zImage, I'm assuming that everything before the gz chunk is part of the decompression stub, and should not ever require modification.  So hopefully prepending that to a re-archived image would work.

However there is one other snag that I haven't quite figured.  If you notice when you zcat the .gz, it displays a message about "ignoring trailing garbage".  So there is apparently some data at the end of this zImage file, which is not part of the gz archive, and I'm still not sure what that represents.  When I tried re-compressing the unmodified image on my ubuntu box...
Code:
gzip -cn --best Image > Image2.gz
I got a nearly identical file, except for bytes 5 through 8 (representing modified time), and of course the missing trailing garbage that was ignored during extracting the archive.

I don't know if we can just append that trailing data onto the end of our re-compressed file, or if maybe it's some super secret checksum data or something like that which depends on the contents of the rest of the image.


Edit:
I spoke with someone smarter than me on irc, regarding the trailing data (name removed for privacy):
Quote
<xxxxxxxx> peeps: look at arch/arm/boot/compressed/vmlinux.lds.in.  The compressed image is in .text.piggydata, so following are alignment, *(.got), *(.got.plt) and *(.data)
<peepsalot> thank you xxxxxxxx i will check that out
<xxxxxxxx> peeps: you can just ignore it (as gzip does for you)
<peepsalot> ok, i still don't completely understand though.  what are piggydata, got, plt, etc.
<peepsalot> if I modify the uncompressed image and try to piece the zImage back together, how do I know what to put at the end
<xxxxxxxx> peeps: probably you cannot as the offsets are hardcoded in the binary after linking
<xxxxxxxx> you can directly boot the Image
<peepsalot> the problem is i want to flash a modified kernel, and the only tool I have for reflashing at the moment requires that zImage afaik.
<xxxxxxxx> then you need to hack the Makefile not to rebuild Image and recreate a zImage
<xxxxxxxx> probably you need to modify arch/arm/boot/compressed/Makefile

Has anyone successfully compiled the Samsung kernel source?  As I understand it doesn't include the needed filesystem drivers, but is it possible to compile at all?  I'd be interested to see what the output image looks like.  I will probably give it a try later.  Maybe we can find a way to build from the source we have, and then patch in that binary driver from the recovery image kernel somehow.
« Last Edit: December 10, 2009, 05:07:27 PM by peepsalot » Logged
Decepticrock
Newbie
*

Cookies: 0
Posts: 41



View Profile
« Reply #17 on: December 10, 2009, 09:39:32 PM »

I just finished compiling it.  Had to generate a file called "initrd.arm.initramfs_list" so that's the only thing that might differ from the stock kernel.  But I have a zImage now.  It's attached.

I should add that the only modification I made to the kernel makefile was to set the cross-compiler for the ARM arch.

Why the hell is it half the size of the one in CJ05?

* zImage (1800.85 KB - downloaded 13 times.)
« Last Edit: December 10, 2009, 11:59:27 PM by Decepticrock » Logged
Decepticrock
Newbie
*

Cookies: 0
Posts: 41



View Profile
« Reply #18 on: December 11, 2009, 12:17:14 AM »

Oh snap I just realized it built an Image file which is twice the size of the zImage.
Logged
peepsalot
Jr. Member
**

Cookies: 8
Posts: 90


View Profile
« Reply #19 on: December 11, 2009, 12:23:57 AM »

Oh snap I just realized it built an Image file which is twice the size of the zImage.
The one you built is half the size of the one from the recovery image.  

I'm still struggling getting my toolchain set up properly.  Care to comment on what you did?

Edit: Oh I misunderstood you; of course the zImage is half the size of the Image, that's because zImage is compressed with gzip.  But yeah, it's still half the size of the recovery one.
« Last Edit: December 11, 2009, 12:38:09 AM by peepsalot » Logged
Decepticrock
Newbie
*

Cookies: 0
Posts: 41



View Profile
« Reply #20 on: December 11, 2009, 01:19:15 AM »

For toolchain just export the path to its bin dir via /etc/environment and then edit the cross compiler option in the kernel sources makefile.
Also I had to move the kernel source directory to /root/android_kernel or something.  Then there's an sh script int the kernel scripts dir to create that initrd file I was talking about.

I'm posting all this from my phone so excuse the formatting please.

As far as the image is concerned, could the zImage file from CJ05 actually just be the Image file renamed as zImage?

Edit:  Okay so no it's not a renamed Image file.  I wonder what all Samsung left out to make up for the missing 1.8 meg.
« Last Edit: December 11, 2009, 11:01:48 AM by Decepticrock » Logged
zefie
Pro Member
****

Cookies: 29
Posts: 458


View Profile
« Reply #21 on: December 11, 2009, 01:24:27 PM »

Edit:  Okay so no it's not a renamed Image file.  I wonder what all Samsung left out to make up for the missing 1.8 meg.

The ramdisk, including /sbin/recovery, is probably making up for the missing 1.8mb.
Logged
feld
Newbie
*

Cookies: 0
Posts: 10


View Profile
« Reply #22 on: December 11, 2009, 01:35:30 PM »

Our first goal should be to flash a modified version of the CJ05 rom. Hex edit one byte, doesn't matter, just change something so the checksum fails. We need to figure out said checksum.

In my bootloader info thread I discovered that the bootloader in /dev/bml2 is some kind of bootloader/firmware that appears to do the flashing/partitioning/etc and also does checksumming (god bless `strings`!!). It should be possible to dissect this with a hex editor... like the good old days of hacking PS2 games... force it to continue anyway on a checksum fail! after that we should be home free to flash whatever image we want on there! Smiley Smiley
Logged
Decepticrock
Newbie
*

Cookies: 0
Posts: 41



View Profile
« Reply #23 on: December 11, 2009, 01:59:56 PM »

That would make for a very merry chrismas assuming someone can get the drivers worked in okay.
Logged
peepsalot
Jr. Member
**

Cookies: 8
Posts: 90


View Profile
« Reply #24 on: December 12, 2009, 03:00:34 PM »

Ok, I've been hard at work trying to recreate the initramfs in our custom compiled kernel.

The initramfs is stored as a cpio file embedded in the gunzipped Image file.  Here is what you can do to extract the files, assuming you have already gunzip'ed Image out of zImage from following my above post:
Code:
dd ibs=1 skip=121088 count=3632640 if=Image of=Image.cpio
mkdir initramfs && cd initramfs
cpio --quiet --no-absolute-filenames -ivF ../Image.cpio
So we now know all the files that are included in it, and we have their data.

When the zImage gets built, it uses scripts/gen_initramfs_list.sh to create the initramfs.img file.  Apparently the Samsung kernel was originally built using a initrd.arm.initramfs_list file which is text listing out all the files to include in the initramfs including permissions,etc.  However, if you run
Code:
scripts/gen_initramfs_list.sh -h
You will see that you have the option of just passing in an already created .cpio file instead of a list file. This is the route I took to try to test my build for now.  Edited .config in the top kernel source directory so that CONFIG_INITRAMFS_SOURCE is set to the path of my Image.cpio

A better solution would be to completely recreate the initrd.arm.initramfs_list file which I think we can do with a little work.  This would allow us to easily modify the individual files in this cpio archive.
There are a couple good references which should help understand what we need to do:

Quote from: SPH-M900_OpenSource/linux-2.6.27/Documentation/filesystems/ramfs-rootfs-initramfs.txt
The config option CONFIG_INITRAMFS_SOURCE (for some reason buried under
devices->block devices in menuconfig, and living in usr/Kconfig) can be used
to specify a source for the initramfs archive, which will automatically be
incorporated into the resulting binary.  This option can point to an existing
gzipped cpio archive, a directory containing files to be archived, or a text
file specification such as the following example:

  dir /dev 755 0 0
  nod /dev/console 644 0 0 c 5 1
  nod /dev/loop0 644 0 0 b 7 0
  dir /bin 755 1000 1000
  slink /bin/sh busybox 777 0 0
  file /bin/busybox initramfs/busybox 755 0 0
  dir /proc 755 0 0
  dir /sys 755 0 0
  dir /mnt 755 0 0
  file /init initramfs/init.sh 755 0 0

Run "usr/gen_init_cpio" (after the kernel build) to get a usage message
documenting the above file format.

As the last line in that snippet says, rung usr/gen_init_cpio for more info about the format of the list file which we need to create:

Quote from: usr/gen_init_cpio
Usage:
   ./gen_init_cpio <cpio_list>

<cpio_list> is a file containing newline separated entries that
describe the files to be included in the initramfs archive:

# a comment
file <name> <location> <mode> <uid> <gid> [<hard links>]
dir <name> <mode> <uid> <gid>
nod <name> <mode> <uid> <gid> <dev_type> <maj> <min>
slink <name> <target> <mode> <uid> <gid>
pipe <name> <mode> <uid> <gid>
sock <name> <mode> <uid> <gid>

<name>       name of the file/dir/nod/etc in the archive
<location>   location of the file in the current filesystem
<target>     link target
<mode>       mode/permissions of the file
<uid>        user id (0=root)
<gid>        group id (0=root)
<dev_type>   device type (b=block, c=character)
<maj>        major number of nod
<min>        minor number of nod
<hard links> space separated list of other links to file

example:
# A simple initramfs
dir /dev 0755 0 0
nod /dev/console 0600 0 0 c 5 1
dir /root 0700 0 0
dir /sbin 0755 0 0
file /sbin/kinit /usr/src/klibc/kinit/kinit 0755 0 0

There's no tool that I've found that can regenerate this list file from a cpio archive.  The closest thing to it would be getting cpio to list out the files:
Code:
cpio --quiet -tvnF Image.cpio > initrd.arm.initramfs_list
I've attached the output of this command, and as you can see it's not in the proper format: file modes are in the wrong format, link information is absent, device node IDs are not included, etc.

So we either need to manually convert this file into the proper format, or write a program to extract this data directly from the cpio file and automatically generate the full list file.  I'm going to start working on the latter.

* initrd.arm.initramfs_list (6.41 KB - downloaded 22 times.)
« Last Edit: December 12, 2009, 03:14:02 PM by peepsalot » Logged
peepsalot
Jr. Member
**

Cookies: 8
Posts: 90


View Profile
« Reply #25 on: December 12, 2009, 09:54:39 PM »

Ok, I wrote something to grab the data out of Image.cpio and write out a cpio list file.

Find a place you want to extract the files, and use
Code:
cpio --quiet --no-absolute-filenames --preserve-modification-time -ivF Image.cpio
to extract them

Then compile and run list_initramfs_gen.c , using the Image.cpio file as first parameter, and the path to where you extracted the files from Image.cpio as the second parameter (no trailing "/"). Redirect output to a file and double check that the output looks sane.

Once you have created your .list file, just change your .config to make use of it.

Edit: updated the source code to fix some incompatibility issues. 
You can get the Image.cpio and latest list_initramfs_gen.c from glitch77's file repo.

Here is an example of what the output from list_initramfs_gen.c should look like.
http://alerttheinternet.com/android/example_initrd.arm.initramfs_list
You'll still need to make your own so that local paths are correct.
« Last Edit: December 13, 2009, 05:42:51 PM by peepsalot » Logged
Pages: 1 [2]
Print
Jump to:  

Got a new phone? Find the forum here


Related Topics
Subject Started by Replies Views Last post
New info on filesystem, flashing, and the future
Rooting
glitch77 8 7427 Last post December 17, 2009, 05:26:45 PM
by orangesunshine
Rooting/Flashing Procedure for Complete n00bs « 1 2 3 »
Rooting
petrafan007 43 7310 Last post January 09, 2010, 09:03:23 PM
by cnstarz
Flashing leaked version of android 2.1, root, and other goodies
Android 2.1 Discussions
RedBullZ 7 5703 Last post April 11, 2010, 11:07:30 PM
by lovinlissa1984
Flashing Moment to Boost Mobile
How To....
momenthead 0 6481 Last post May 21, 2011, 07:44:24 PM
by momenthead
Android market and content filter issue
Android 2.1 Discussions
Airmack 2 9029 Last post August 04, 2011, 09:02:36 PM
by Airmack




Galaxy S3 | Galaxy Note | Galaxy Nexus | Kindle Fire | Atrix 4G | Motorola Xoom | Windows Phone 7
Nokia Lumia | Tech Support Forum | Top Hosts | Samsung Galaxy Tab | Samsung Galaxy S2 | Samsung Galaxy S | Samsung Wave
HTC Evo 3D | HTC Evo 4G | HTC Incredible | HTC Incredible 2 | HTC Incredible S | HTC Thunderbolt
Motorola Droid Razr
| HTC Desire | HTC Desire HD | HTC Desire Z | HTC Desire S | HTC Wildfire
Motorola Droid | Galaxy Indulge | Nokia N8 | Droid Charge | Droid X | Droid X2 | Droid 2| Droid 3 | Fascinate
HTC Sensation | HTC Flyer | LG Revolution | Asus Transformer | Xperia Play | iPhone 4 | Nexus S | Droid Bionic
HTC One | HTC Wildfire S | HTC Droid Eris


This is an Un-Official fan based Website. The views expressed on this website are solely those of the proprietor, or contributors to the site, and do not necessarily reflect the views or opinions of the parties it covers, and is not affiliated with, endorsed or sponsored by parties involved.
If you have a problem with any of the content posted on this website, please contact "mobile@vssupportqueue.com"
Term of Use | Privacy Policy | BlackRain 2006 by, Crip



Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Sitemap