[Android Q&A, Help & Troubleshooting] andrewavp:
unpack and repack

### uImage original size: 3593374 ###
### Binwalk ouput for original uImage ##
DECIMAL HEX DESCRIPTION
-------------------------------------------------------------------------------------------------------
0 0x0 uImage header, header size: 64 bytes, header CRC: 0x534C30CF, created: Tue Nov 8 06:05:02 2011, image size: 3593310 bytes, Data Address: 0xFFFFFFFF, Entry Point: 0x0, data CRC: 0x672C70AA, OS: Linux, CPU: ARM, image type: Firmware Image, compression type: none, image name: LK:ZT280_H1_2n
64 0x40 uImage header, header size: 64 bytes, header CRC: 0xC6DD4500, created: Tue Nov 8 06:05:02 2011, image size: 3593246 bytes, Data Address: 0x80008000, Entry Point: 0x80008000, data CRC: 0x58A04739, OS: Linux, CPU: ARM, image type: OS Kernel Image, compression type: lzma, image name: Linux-2.6.34
128 0x80 LZMA compressed data, properties: 0x5D, dictionary size: 8388608 bytes, uncompressed size: 9980736 bytes

### Remove 2 uImage headers ###
dd if=uImage of=zImage-lzma bs=1 skip=128

### Uncompress lzma kernel ###
### Compressed size: 3593246 ###
### Uncompressed size: 9980736 ###
dd if=zImage-lzma bs=1 | lzcat > zImage

### Find start of cpio ###
grep -a -b -m 1 --only-matching '070701' zImage
167936:070701
168052:070701

### Find end of cpio ###
grep -a -b -m 1 --only-matching 'TRAILER!!!' zImage
1765826:TRAILER!!!

### Add 11 to the above # to include trailer and extract cpio from kernel ###
dd if=zImage bs=1 skip=167936 count=1765837 of=initramfs_orig.cpio

### Explode the cpio ###
mkdir cpio_orig
cd cpio_orig/
cpio -v -i --no-absolute-filenames < ../initramfs_orig.cpio

### Make changes to initramfs ###

### Create new cpio ###
(cd cpio_orig; find . | cpio -o -H newc | gzip) > ../initramfs.cpio

### Write beginning of original zImage up to start of cpio to a new file ###
dd if=zImage bs=1 count=167936 of=/tmp/zImage

### Add new cpio/initramfs to the new file ###
dd if=initramfs.cpio bs=1 seek=167936 of=/tmp/zImage

### Write ending of original zImage to new file ###
### Seek below should be size of first part (167936) + size of original initramfs (1765837) ###
dd if=zImage bs=1 seek=1933773 skip=1765826 of=/tmp/zImage

### lzma compress the new zImage ###
### Uncompressed size: 9026566 ###
### Compressed size: 3808279 (larger than original zImage compressed size!?) ###
lzma -9 /tmp/zImage

### Add uImage headers to new file ###
### or should this be replaced by using the mkimage command? ###
dd if=uImage of=/tmp/uImage bs=1 count=128

### Add compressed zimage to new uImage ###
### New uImage size: 3808407 ###
dd if=/tmp/zImage.lzma bs=1 seek=128 of=/tmp/uImage

### binwalk output for new uImage ###
DECIMAL HEX DESCRIPTION
-------------------------------------------------------------------------------------------------------
0 0x0 uImage header, header size: 64 bytes, header CRC: 0x534C30CF, created: Tue Nov 8
06:05:02 2011, image size: 3593310 bytes, Data Address: 0xFFFFFFFF, Entry Point: 0x0, data CRC: 0x672C70AA, OS:
Linux, CPU: ARM, image type: Firmware Image, compression type: none, image name: LK:ZT280_H1_2n
64 0x40 uImage header, header size: 64 bytes, header CRC: 0xC6DD4500, created: Tue Nov 8
06:05:02 2011, image size: 3593246 bytes, Data Address: 0x80008000, Entry Point: 0x80008000, data CRC: 0x58A0473
9, OS: Linux, CPU: ARM, image type: OS Kernel Image, compression type: lzma, image name: Linux-2.6.34
128 0x80 LZMA compressed data, properties: 0x5D, dictionary size: 33554432 bytes, uncompre
ssed size: 9026566 bytes
248589 0x3CB0D gzip compressed data, was "\255\344\016\015!\232|.\333\017s\250\3577\366{\241\240
\005`v\321\324\2238\307DX\241l&\003k\330\203b\030\230!\245x\366\021?\211s\214\254\253\327w\354\222C\230\015\303=
64\2126", has comment, from Z-System, comment, encrypted, last modified: Sun Jan 14 00:12:51 2024