1.前言
针对海思falsh为emmc时,我们需要制作ext4文件系统,需要用到海思自带make_ext4fs制作文件系统,下面把该工具源码和使用分析一下。
2.源码分析
2.1 用法
static void usage(char *path)
{
fprintf(stderr, "%s [ -l <len> ] [ -j <journal size> ] [ -b <block_size> ]\n", basename(path));
fprintf(stderr, " [ -g <blocks per group> ] [ -i <inodes> ] [ -I <inode size> ]\n");
fprintf(stderr, " [ -L <label> ] [ -f ] [ -a <android mountpoint> ]\n");
fprintf(stderr, " [ -S file_contexts ]\n");
fprintf(stderr, " [ -z | -s ] [ -t ] [ -w ] [ -c ] [ -J ]\n");
fprintf(stderr, " <filename> [<directory>]\n");
}
-l 指定文件大小;
-s 稀疏格式,压缩文件大小。
2.2 源码
/* Write the filesystem image to a file */
void write_ext4_image(int fd, int gz, int sparse, int crc, int wipe)
{
int ret = 0;
/* дһ��ϡ��ͷ */
struct output_file *out = open_output_fd(fd, gz, sparse,
count_sparse_chunks(), crc, wipe);
if (!out)
return;
for_each_data_block(ext4_write_data_block, ext4_write_data_file, ext4_write_fill_block, out);
pad_output_file(out, info.len);
close_output_file(out);
}
该函数参数里面sparse 是由 make_ext4fs -s传入的。
ext4稀疏头文件定义
typedef struct sparse_header {
__le32 magic; /* 0xed26ff3a */
__le16 major_version; /* (0x1) - reject images with higher major versions */
__le16 minor_version; /* (0x0) - allow images with higer minor versions */
__le16 file_hdr_sz; /* 28 bytes for first revision of the file format */
__le16 chunk_hdr_sz; /* 12 bytes for first revision of the file format */
__le32 blk_sz; /* block size in bytes, must be a multiple of 4 (4096) */
__le32 total_blks; /* total blocks in the non-sparse output image */
__le32 total_chunks; /* total chunks in the sparse input image */
__le32 image_checksum; /* CRC32 checksum of the original data, counting "don't care" */
/* as 0. Standard 802.3 polynomial, use a Public Domain */
/* table implementation */
} sparse_header_t;
#define SPARSE_HEADER_MAGIC 0xed26ff3a
#define CHUNK_TYPE_RAW 0xCAC1
#define CHUNK_TYPE_FILL 0xCAC2
#define CHUNK_TYPE_DONT_CARE 0xCAC3
#define CHUNK_TYPE_CRC32 0xCAC4
typedef struct chunk_header {
__le16 chunk_type; /* 0xCAC1 -> raw; 0xCAC2 -> fill; 0xCAC3 -> don't care */
__le16 reserved1;
__le32 chunk_sz; /* in blocks in output image */
__le32 total_sz; /* in bytes of chunk input file including chunk header and data */
} chunk_header_t;
主要函数:
struct output_file *open_output_fd(int fd, int gz, int sparse,
int chunks, int crc, int wipe)
void for_each_data_block(data_block_callback_t data_func,
data_block_file_callback_t file_func,
data_block_fill_callback_t fill_func, void *priv)
void pad_output_file(struct output_file *out, u64 len)
void close_output_file(struct output_file *out)
3.工具使用
make_ext4fs [-s] -l size filename [<directory>]
make_ext4fs -s -l 30M ${VERSION}/${app} ${APP_DST_PATH}
4.参数加-s与否区别
- 文件大小区别
[pc@localhost smp_image_glibc]$ du -sh *
30M STM_APP_T19111203 #不带-s
6.7M STM_APP_T19111204 #带-s
- 文件结构标志区别
是否带有0xed26ff3a