1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- --- a/lib/libubigen.c
- +++ b/lib/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/include/libubigen.h
- +++ b/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
|