들어가면서
요번에 USB로 안드로이드 전체 업데이트 구현하다가
알게된 sparse file format 관련하여 몇 자 적어봅니다.
안드로이드 system.img가 sparse format으로 되어 있더군요...
몰랐던 내용이라 구글링하면서 작업했는데
갱! 장! 히! 간단하여 소개 합니다.
개요
sparse file에 관한 설명이된 그림입니다.
요지는 빈공간을 header로 때워서 압축하는 방식입니다.
(0x00이 얼만큼 있는지를 chunk header로 표현한다고 보시면 됩니다.)
위 그림에서 Logical file size에서 physical file size로 바뀌면서 회색 부분이 사라진게 보입니다.
저 공간 만큼 압축되는 것입니다.
파일 구조
sparse file은 대략 아래와 같은 구조 입니다.
[sparse header] [chunk header] [data] [chunk header] [data] [chunk header] [chunk header]
파일의 가장앞에 sparse header가 나옵니다.
파일에 대한 대략적인 정보를 가지고 있습니다.
헤더에 대한 자세한 내용은 뒤에서....
그리고 chunk header가 나오기 시작합니다.
chunk header에서는 data가 있는지? 빈공간인지?를 구분할 수 있습니다.
헤더
[sparse header]
typedef struct _SH {
unsigned int magic; /* magic number */
unsigned short major_version; /* (0x1) - reject images with higher major versions */
unsigned short minor_version; /* (0x0) - allow images with higer minor versions */
unsigned short file_hdr_sz; /* 28 bytes for first revision of the file format */ sparse header size
unsigned short chunk_hdr_sz; /* 12 bytes for first revision of the file format */ chunk header size
unsigned int blk_sz; /* block size in bytes, must be a multiple of 4 (4096) */ data 1 block size
unsigned int total_blks; /* total blocks in the non-sparse output image */
unsigned int total_chunks; /* total chunks in the sparse input image */
unsigned int image_checksum; /* CRC32 checksum of the original data, counting "don't care" */
} SH;
[chunk header]
typedef struct _CH {
unsigned short chunk_type; /* 0xCAC1 -> raw; 0xCAC2 -> fill; 0xCAC3 -> don't care */
unsigned short reserved1; /* not use */
unsigned int chunk_sz; /* data count (total data = chunk_hdr_sz * chunk_sz */
unsigned int total_sz; /* head + total data */
} CH;
최초에 file_hdr_sz 를 읽은 후, sparse header를 파싱합니다.
이후 chunk header를 파싱하기 시작하는데,
chunk header에 chunk_type이 가장 중요합니다.
#define CHUNK_TYPE_RAW 0xCAC1 <--- data
#define CHUNK_TYPE_FILL 0xCAC2 <--- data
#define CHUNK_TYPE_DONT_CARE 0xCAC3 <--- skip
#define CHUNK_TYPE_CRC32 0xCAC4
CHUNK_TYPE_RAW와 CHUNK_TYPE_FILL의 경우 데이터 이며, sparse header에 blk_sz에 적힌 크기로 chunk header에 chunk_sz 갯수 만큼 데이터임을 나냅니다.
CHUNK_TYPE_DONT_CARE의 경우 skip에 대한 표기이며, sparse header에 blk_sz에 적힌 크기로 chunk header에 chunk_sz 갯수 만큼 빈공간임을 나타냅니다.
흐름도
파일 끝의 경우 파일 사이즈나 chunk 갯수로 판별 가능합니다.
몇 일전에 작성한 업무일지 인데,
그림 좀 추가해서 공유합니다.
출처는 구글링과 fastboot 코드......
구우럼 이만 ( _ _)
'코스웨어 > 졸업생' 카테고리의 다른 글
Valgrind 써보세요 (5) | 2015.05.27 |
---|---|
15년 기수 여러분, 선배에게 물어보세요 (12) | 2015.05.22 |
나쁜 개발자가 되는 18가지 방법 (5) | 2015.05.21 |
지금부터 (9) | 2015.04.30 |
[정보공유] 라이브러리 빌드에 관한글 (5) | 2015.03.27 |
[정보공유] 사운들리 (9) | 2015.03.24 |
[토론 in] 전역변수는 왜 쓰면 안될까? (12) | 2015.03.17 |
서울에 주쌤교도가 있다합니다 (12) | 2015.03.17 |