X-Git-Url: https://git.archive.openwrt.org/?a=blobdiff_plain;f=tools%2Fmtd-utils%2Fpatches%2F200-libubigen-add-ubigen_write_terminator-function.patch;fp=tools%2Fmtd-utils%2Fpatches%2F200-libubigen-add-ubigen_write_terminator-function.patch;h=8bd642fbc8566faffae1680bc0608bcb341128ac;hb=8124ffd8d20791a2710bc5cb7afdd16cd58ff99c;hp=0000000000000000000000000000000000000000;hpb=65e8ac294b9be6270e42c1321a74752542a84a77;p=15.05%2Fopenwrt.git diff --git a/tools/mtd-utils/patches/200-libubigen-add-ubigen_write_terminator-function.patch b/tools/mtd-utils/patches/200-libubigen-add-ubigen_write_terminator-function.patch new file mode 100644 index 0000000000..8bd642fbc8 --- /dev/null +++ b/tools/mtd-utils/patches/200-libubigen-add-ubigen_write_terminator-function.patch @@ -0,0 +1,89 @@ +--- a/ubi-utils/src/libubigen.c ++++ b/ubi-utils/src/libubigen.c +@@ -122,8 +122,9 @@ int ubigen_add_volume(const struct ubige + return 0; + } + +-void ubigen_init_ec_hdr(const struct ubigen_info *ui, +- struct ubi_ec_hdr *hdr, long long ec) ++static void __ubigen_init_ec_hdr(const struct ubigen_info *ui, ++ struct ubi_ec_hdr *hdr, long long ec, ++ int eof) + { + uint32_t crc; + +@@ -136,10 +137,22 @@ void ubigen_init_ec_hdr(const struct ubi + hdr->data_offset = cpu_to_be32(ui->data_offs); + hdr->image_seq = cpu_to_be32(ui->image_seq); + ++ if (eof) { ++ hdr->padding1[0] = 'E'; ++ hdr->padding1[1] = 'O'; ++ hdr->padding1[2] = 'F'; ++ } ++ + crc = mtd_crc32(UBI_CRC32_INIT, hdr, UBI_EC_HDR_SIZE_CRC); + hdr->hdr_crc = cpu_to_be32(crc); + } + ++void ubigen_init_ec_hdr(const struct ubigen_info *ui, ++ struct ubi_ec_hdr *hdr, long long ec) ++{ ++ __ubigen_init_ec_hdr(ui, hdr, ec, 0); ++} ++ + void ubigen_init_vid_hdr(const struct ubigen_info *ui, + const struct ubigen_vol_info *vi, + struct ubi_vid_hdr *hdr, int lnum, +@@ -307,6 +320,39 @@ int ubigen_write_layout_vol(const struct + } + + free(outbuf); ++ return 0; ++ ++out_free: ++ free(outbuf); ++ return -1; ++} ++ ++int ubigen_write_eof_markers(const struct ubigen_info *ui, long long ec, ++ int count, int out_fd) ++{ ++ char *outbuf; ++ int peb_size = ui->peb_size; ++ ++ outbuf = malloc(peb_size); ++ if (!outbuf) { ++ sys_errmsg("cannot allocate %d bytes of memory", peb_size); ++ return -1; ++ } ++ ++ memset(outbuf, 0xFF, peb_size); ++ __ubigen_init_ec_hdr(ui, (struct ubi_ec_hdr *)outbuf, ec, 1); ++ ++ while (count) { ++ if (write(out_fd, outbuf, peb_size) != peb_size) { ++ sys_errmsg("cannot write %d bytes to the output file", ++ peb_size); ++ goto out_free; ++ } ++ ++ count--; ++ } ++ ++ free(outbuf); + return 0; + + out_free: +--- a/ubi-utils/include/libubigen.h ++++ b/ubi-utils/include/libubigen.h +@@ -188,6 +188,9 @@ int ubigen_write_layout_vol(const struct + long long ec1, long long ec2, + struct ubi_vtbl_record *vtbl, int fd); + ++int ubigen_write_eof_markers(const struct ubigen_info *ui, long long ec, ++ int count, int out_fd); ++ + #ifdef __cplusplus + } + #endif