blog2i2j / firmware-mod-kit

Automatically exported from code.google.com/p/firmware-mod-kit
0 stars 0 forks source link

Unable to extract cramfs.img with cramfsck or uncramfs. #2

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
When I try to extract the cramfs image  I got following error:
"
./cramfsck  -v -x /root/tmp /root/IMAGGINI_CRAMFS/cramfs.2.img 
./cramfsck: unsupported filesystem features
"

The cramfs image is based on a openrg firmware of  BCM96358 broadcom plaform.

file cmd output:

file cramfs.2.img

cramfs.2.img: Linux Compressed ROM File System data, little endian size
1376256 version #2 sorted_dirs CRC 0xe514a6b4, edition 0, 85 blocks, 30 files.

The uncramfs command gives "uncompress error":

./uncramfs  /root/tmp /root/IMAGGINI_CRAMFS/cramfs.2.img 
[Volume size: 0x150000]
[Volume serial: b4a614e500000000550000001e000000]
[Volume name: Compressed]

/root/tmp: File exists
drwxr-xr-x 1020/120           16(16)      /

/:
drwxr-xr-x 1020/120           20(20)      lib

/lib:
drwxr-xr-x 1020/120          732(732)     modules

/lib/modules:
Uncompression failed-rw-r--r-- 1020/120         9160(2344116) bcm53xx_mod.o
Uncompression failed-rw-r--r-- 1020/120       628452(21000700
bcm963xx_adsl_mod.o
Uncompression failed-rw-r--r-- 1020/120        22124(-1519611
bcm963xx_atm_mod.o
Uncompression failed-rw-r--r-- 1020/120        99508(-1958960
bcm963xx_atmapi_mod.o
Uncompression failed-rw-r--r-- 1020/120        22752(-1519649
bcm963xx_br2684_mod.o
Uncompression failed-rw-r--r-- 1020/120        41944(19738572
bcm963xx_eth_mod.o
Uncompression failed-rw-r--r-- 1020/120        21560(-1519671
bcm963xx_jdsp_mod.o
Uncompression failed-rw-r--r-- 1020/120         3360(1384)    bcm_vdsl_mod.o
Uncompression failed-rw-r--r-- 1020/120         8036(53656177 be_pppoa_mod.o
Uncompression failed-rw-r--r-- 1020/120         7196(53655890 btn.o
Uncompression failed-rw-r--r-- 1020/120       734660(-1976173 dspdd_mod.o
Uncompression failed-rw-r--r-- 1020/120       851900(-1578481 endpointdd_mod.o
Uncompression failed-rw-r--r-- 1020/120        37892(99333825 igmp_proxy_mod.o
Uncompression failed-rw-r--r-- 1020/120         3928(1422)    jtimer.o
Uncompression failed-rw-r--r-- 1020/120         5580(53614190 log_chardev.o
Uncompression failed-rw-r--r-- 1020/120       499380(62128140 one_module.o
Uncompression failed-rw-r--r-- 1020/120        12548(-1859023 phone_mod.o
Uncompression failed-rw-r--r-- 1020/120        18788(13965768 pppoe_relay.o
Uncompression failed-rw-r--r-- 1020/120         2808(1034)    qos_ingress.o
Uncompression failed-rw-r--r-- 1020/120        10668(1838416)
rg_auth1x_pktfil.o
Uncompression failed-rw-r--r-- 1020/120         8516(1283848) rg_dhcp_pktfil.o
Uncompression failed-rw-r--r-- 1020/120         2656(936)     rg_ipv4.o
Uncompression failed-rw-r--r-- 1020/120         5520(53597077 rg_pppoe_relay.o
Uncompression failed-rw-r--r-- 1020/120        19980(13964082 rtp.o
Uncompression failed-rw-r--r-- 1020/120         4232(53596146 tcp_mss.o
Uncompression failed-rw-r--r-- 1020/120         3820(1428)    vnet_mod.o
Uncompression failed-rw-r--r-- 1020/120      1233220(16881115 wl.o

[Summary:]
[Total uncompressed size:      4320956]
[Total compressed size:      1186721213]
[Number of entries:                 30]
[Number of files compressed:        15]
[Number of files expanded:          15]

Original issue reported on code.google.com by drpepppp...@gmail.com on 19 Aug 2008 at 3:29

Attachments:

GoogleCodeExporter commented 9 years ago
If the vendor distributed the GPL sources for the firmware in question, check 
their
tools to see which version of cramfs is being used, and if its been modified or 
not.
It may be a different version or utilize a different compression algorithm.

Original comment by jeremy.collake@gmail.com on 19 Aug 2008 at 4:00

GoogleCodeExporter commented 9 years ago
Hi, I find all file referd to cramfs from sdk kit.

I' attached it.

At the first look  the compression looks like gzip but ther's also lzma option.

I compare the default cramfs super-block and the openrg-version.

I found some differences:

1]default cramfs :

#ifndef _CRAMFS_FS_SB
#define _CRAMFS_FS_SB

/*
* cramfs super-block data in memory
*/
struct cramfs_sb_info {
                        unsigned long magic;
                        unsigned long size;
                        unsigned long blocks;
                        unsigned long files;
                        unsigned long flags;
};

static inline struct cramfs_sb_info *CRAMFS_SB(struct super_block *sb)
{
        return sb->s_fs_info;
}

#endif

struct cramfs_info {
        __u32 crc;
        __u32 edition;
        __u32 blocks;
        __u32 files;
};

/*
* Superblock information at the beginning of the FS.
*/
struct cramfs_super {
        __u32 magic;                    /* 0x28cd3d45 - random number */
        __u32 size;                     /* length in bytes */
        __u32 flags;                    /* feature flags */
        __u32 future;                   /* reserved for future use */
        __u8 signature[16];             /* "Compressed ROMFS" */
        struct cramfs_info fsid;        /* unique filesystem info */
        __u8 name[16];                  /* user-defined name */
        struct cramfs_inode root;       /* root inode data */
};

/*
* Feature flags
*
* 0x00000000 - 0x000000ff: features that work for all past kernels
* 0x00000100 - 0xffffffff: features that don't work for past kernels
*/
#define CRAMFS_FLAG_FSID_VERSION_2      0x00000001      /* fsid version #2 */
#define CRAMFS_FLAG_SORTED_DIRS         0x00000002      /* sorted dirs */
#define CRAMFS_FLAG_HOLES               0x00000100      /* support for holes */
#define CRAMFS_FLAG_WRONG_SIGNATURE     0x00000200      /* reserved */
#define CRAMFS_FLAG_SHIFTED_ROOT_OFFSET 0x00000400      /* shifted root fs */

/*
/*
* Valid values in super.flags.  Currently we refuse to mount
* if (flags & ~CRAMFS_SUPPORTED_FLAGS).  Maybe that should be
* changed to test super.future instead.
*/
#define CRAMFS_SUPPORTED_FLAGS  ( 0x000000ff \
                                | CRAMFS_FLAG_HOLES \
                                | CRAMFS_FLAG_WRONG_SIGNATURE \
                                | CRAMFS_FLAG_SHIFTED_ROOT_OFFSET )

2]openrg-cramfs super-block

/*
* cramfs super-block data in memory
*/
struct cramfs_sb_info {
                        unsigned long magic;
                        unsigned long size;
                        unsigned long blocks;
                        unsigned long files;
                        unsigned long flags;
                        unsigned long sub_type;
                        void *uncomp_buffer;
                        int uncomp_blk_offset;
                        int uncomp_blk_data_size;
};

static inline struct cramfs_sb_info *CRAMFS_SB(struct super_block *sb)
{
        return sb->s_fs_info;
}

#endif

struct cramfs_info {
        u32 crc;
        u32 edition;
        u32 blocks;
        u32 files;
};

/*
* Superblock information at the beginning of the FS.
*/
struct cramfs_super {
        u32 magic;                      /* 0x28cd3d45 - random number */
        u32 size;                       /* length in bytes */
        u32 flags;                      /* feature flags */
        u32 future;                     /* reserved for future use */
        u8 signature[16];               /* "Compressed ROMFS" */
        struct cramfs_info fsid;        /* unique filesystem info */
        u8 name[16];                    /* user-defined name */
        struct cramfs_inode root;       /* root inode data */
};

/*
* Feature flags
*
* 0x00000000 - 0x000000ff: features that work for all past kernels
* 0x00000100 - 0xffffffff: features that don't work for past kernels
*/
#define CRAMFS_FLAG_FSID_VERSION_2      0x00000001      /* fsid version #2 */
#define CRAMFS_FLAG_SORTED_DIRS         0x00000002      /* sorted dirs */
#define CRAMFS_FLAG_HOLES               0x00000100      /* support for holes */
#define CRAMFS_FLAG_WRONG_SIGNATURE     0x00000200      /* reserved */
#define CRAMFS_FLAG_SHIFTED_ROOT_OFFSET 0x00000400      /* shifted root fs */
#define CRAMFS_FLAG_BLKSZ_MASK          0x00003800      /* Block size mask */
#define CRAMFS_FLAG_COMP_METHOD_MASK    0x0000C000      /* Compression method
                                                         * mask */

#define CRAMFS_FLAG_BLKSZ_SHIFT 11
#define CRAMFS_FLAG_COMP_METHOD_SHIFT 14

#define CRAMFS_FLAG_COMP_METHOD_NONE 0
#define CRAMFS_FLAG_COMP_METHOD_GZIP 1
#define CRAMFS_FLAG_COMP_METHOD_LZMA 2

/*
* Valid values in super.flags.  Currently we refuse to mount
* if (flags & ~CRAMFS_SUPPORTED_FLAGS).  Maybe that should be
* changed to test super.future instead.
*/
#define CRAMFS_SUPPORTED_FLAGS  ( 0x000000ff \
                                | CRAMFS_FLAG_HOLES \
                                | CRAMFS_FLAG_WRONG_SIGNATURE \
                                | CRAMFS_FLAG_SHIFTED_ROOT_OFFSET \
                                | CRAMFS_FLAG_BLKSZ_MASK \
                                | CRAMFS_FLAG_COMP_METHOD_MASK)

It seams that differ for the following flags:

#define CRAMFS_FLAG_BLKSZ_MASK          0x00003800      /* Block size mask */
#define CRAMFS_FLAG_COMP_METHOD_MASK    0x0000C000      /* Compression method * 
mask */

Original comment by drpepppp...@gmail.com on 19 Aug 2008 at 4:50

GoogleCodeExporter commented 9 years ago
The sdk files.

Original comment by drpepppp...@gmail.com on 19 Aug 2008 at 4:51

Attachments:

GoogleCodeExporter commented 9 years ago
Thanks for the update. I'm sorry it has taken me so long to notice your 
changes. If 
and when I get a chance, I'll work on adding support for these type of cramfs 
images.  
From what you've provided, it should be easy to add in the support. If anyone 
gets to 
it before I do, feel free to submit patches and I'll get them added on in.

Original comment by jeremy.collake@gmail.com on 11 Sep 2008 at 5:43

GoogleCodeExporter commented 9 years ago
Hello, I get the same problem on another openrg firmware. Did you make an 
update to
your tool yet ?

Original comment by vincent....@gmail.com on 15 Feb 2009 at 10:04

GoogleCodeExporter commented 9 years ago
Same problem here.

Original comment by zibree on 1 May 2009 at 12:12

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
I am able to extract files from an openrg LZA-cramfs with the latest SVN code, 
but
all these files contain are zeros. It seems that the LZMA decompression does 
not work.

Original comment by zot...@gmx.net on 28 Jun 2009 at 12:18

GoogleCodeExporter commented 9 years ago
I downloaded the GPL part of an openRG router 
(http://broadband.adbglobal.com/web/support-area/gpl-code/default.page) and 
found that the compression algorithm is based on an old lzma sdk, modified by 
Jungo/OpenRG team.

I created an lzma-uncramfs program, based on cramfs, implementing this 
compression algorithnm and able to extract files from the openrg cramfs image; 
I attach this program with the modified lzma sdk needed to compile it.

Original comment by digiampi...@gmail.com on 23 Feb 2011 at 2:59

Attachments:

GoogleCodeExporter commented 9 years ago
Thanks digiampietro, added this to FMK!

Original comment by heffne...@gmail.com on 5 Sep 2011 at 3:45