配置文件的内容格式如下:
# Copyright (c) 2013 Peng Donglin. # # Authors: Peng Donglin <pengdonglin137@163.com> # # this is a config file # # imagenum : the number of images included in output file # output : the file name of update package # # enable : # 0: the corresponding image will not be included in update package # 1: the corresponding image will be included int update package # type : # 0: HEAD_INFO_TYPE_UPDATE_FILE # 1: HEAD_INFO_TYPE_TOOL # 2: HEAD_INFO_TYPE_IVA # filename : the image name which will be deal with # flashoffset : tht offset of corresponding image in /dev/mtdx # flashtype : Nand or Nor # imageorder : the order number of image at the same partition # erase_or_not : 1 erase /dev/mtdx 0 not erase /dev/mtdx # if imageorder is not 0, the erase_or_not must be 0 # reserve : the size of area not to be erased at the end of /dev/mtdx # imagetype : yaffs/jffs2/data/oob_raw/ubi # data : the image which does not have oob area # oob_raw : the image which has oob area, but not yaffs or jffs2, such as sony's spl and sony's uboot # ubi: first of all, copy the image to the memory(/tmp/filename),then use function ubiformat to write the image into /dev/mtdx # mtd : the dev node which the corresponding image will be write in # oob_usr_offset : the offset of oob_usr in oob area # oob_usr_length : the length of oob_usr data < MAIN > output = dvr_img.bin < HEADER > enable = 1 type = 0 filename = u-boot_evb_nandspl_bs.bin.raw flashoffset = 0x0 flashtype = Nand imageorder = 0 erase_or_not = 1 reserve = 0x0 imagetype = oob_raw mtd = /dev/mtd0 blocksize = 128KiB pagesize = 2KiB oobsize = 64 oob_usr_offset = 0 oob_usr_length = 32 < HEADER > enable = 1 type = 0 filename = u-boot_evb_bs.bin.raw flashoffset = 0x0 flashtype = Nand imageorder = 0 erase_or_not = 1 reserve = 0x400000 imagetype = oob_raw mtd = /dev/mtd1 blocksize = 128KiB pagesize = 2KiB oobsize = 64 oob_usr_offset = 0 oob_usr_length = 32 < HEADER > enable = 1 type = 0 filename = ubenv0.bin flashoffset = 0xB00000 flashtype = Nand imageorder = 1 erase_or_not = 0 reserve = 0x0 imagetype = data mtd = /dev/mtd1 blocksize = 128KiB pagesize = 2KiB oobsize = 64 oob_usr_offset = 0 oob_usr_length = 32 < HEADER > enable = 1 type = 0 filename = ubenv1.bin flashoffset = 0xB80000 flashtype = Nand imageorder = 2 erase_or_not = 0 reserve = 0x0 imagetype = data mtd = /dev/mtd1 blocksize = 128KiB pagesize = 2KiB oobsize = 64 oob_usr_offset = 0 oob_usr_length = 32 < HEADER > enable = 1 type = 0 filename = ubifs_fw.ubi flashoffset = 0x0 flashtype = Nand imageorder = 0 erase_or_not = 1 reserve = 0x0 imagetype = ubi mtd = /dev/mtd2 blocksize = 128KiB pagesize = 2KiB oobsize = 64 oob_usr_offset = 0 oob_usr_length = 32 < HEADER > enable = 1 type = 0 filename = ubifs_rootfs.ubi flashoffset = 0x0 flashtype = Nand imageorder = 0 erase_or_not = 1 reserve = 0x0 imagetype = data mtd = /dev/mtd3 blocksize = 128KiB pagesize = 2KiB oobsize = 64 oob_usr_offset = 0 oob_usr_length = 32 < HEADER > enable = 1 type = 0 filename = ubifs_local.ubi flashoffset = 0x0 flashtype = Nand imageorder = 0 erase_or_not = 1 reserve = 0x0 imagetype = data mtd = /dev/mtd5 blocksize = 128KiB pagesize = 2KiB oobsize = 64 oob_usr_offset = 0 oob_usr_length = 32 #note: the header that describes uptool should be placed at the end. < HEADER > enable = 1 type = 1 filename = uptool < END >
解析:
#include <stdio.h> #include <string.h> #include <stdlib.h> #include <fcntl.h> #include <strings.h> #include <unistd.h> #include <sys/types.h> #include <sys/stat.h> #include "mk_dvr_img.h" #define err_msg(fmt, ...) ({ fprintf(stderr, "Error: " fmt " ", ##__VA_ARGS__); -1; }) struct head_info heads[10] ; int heads_count = 0; char update_filename[256] = {0}; static char *appcmd_strim(char *s, const char *skip_str) { char *e = s+strlen(s)-1; while(*s && strchr(skip_str,*s)) {*s++=0;}; while(*e && e>s && strchr(skip_str,*e)) {*e=0;e--;}; return s; } static int get_multiplier(const char *str) { if (!str) return 1; /* Remove spaces before the specifier */ while (*str == ' ' || *str == ' ') str += 1; if (!strcmp(str, "KiB")) return 1024; if (!strcmp(str, "MiB")) return 1024 * 1024; if (!strcmp(str, "GiB")) return 1024 * 1024 * 1024; return -1; } static unsigned int get_bytes(const char *str) { char *endp; unsigned int bytes = (unsigned int)strtoul(str, &endp, 0); if (endp == str || bytes < 0) return err_msg("incorrect amount of bytes: "%s"", str); if (*endp != '