2
0

200-libubigen-add-ubigen_write_terminator-function.patch 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. --- a/ubi-utils/libubigen.c
  2. +++ b/ubi-utils/libubigen.c
  3. @@ -122,8 +122,9 @@ int ubigen_add_volume(const struct ubige
  4. return 0;
  5. }
  6. -void ubigen_init_ec_hdr(const struct ubigen_info *ui,
  7. - struct ubi_ec_hdr *hdr, long long ec)
  8. +static void __ubigen_init_ec_hdr(const struct ubigen_info *ui,
  9. + struct ubi_ec_hdr *hdr, long long ec,
  10. + int eof)
  11. {
  12. uint32_t crc;
  13. @@ -136,10 +137,22 @@ void ubigen_init_ec_hdr(const struct ubi
  14. hdr->data_offset = cpu_to_be32(ui->data_offs);
  15. hdr->image_seq = cpu_to_be32(ui->image_seq);
  16. + if (eof) {
  17. + hdr->padding1[0] = 'E';
  18. + hdr->padding1[1] = 'O';
  19. + hdr->padding1[2] = 'F';
  20. + }
  21. +
  22. crc = mtd_crc32(UBI_CRC32_INIT, hdr, UBI_EC_HDR_SIZE_CRC);
  23. hdr->hdr_crc = cpu_to_be32(crc);
  24. }
  25. +void ubigen_init_ec_hdr(const struct ubigen_info *ui,
  26. + struct ubi_ec_hdr *hdr, long long ec)
  27. +{
  28. + __ubigen_init_ec_hdr(ui, hdr, ec, 0);
  29. +}
  30. +
  31. void ubigen_init_vid_hdr(const struct ubigen_info *ui,
  32. const struct ubigen_vol_info *vi,
  33. struct ubi_vid_hdr *hdr, int lnum,
  34. @@ -307,6 +320,39 @@ int ubigen_write_layout_vol(const struct
  35. }
  36. free(outbuf);
  37. + return 0;
  38. +
  39. +out_free:
  40. + free(outbuf);
  41. + return -1;
  42. +}
  43. +
  44. +int ubigen_write_eof_markers(const struct ubigen_info *ui, long long ec,
  45. + int count, int out_fd)
  46. +{
  47. + char *outbuf;
  48. + int peb_size = ui->peb_size;
  49. +
  50. + outbuf = malloc(peb_size);
  51. + if (!outbuf) {
  52. + sys_errmsg("cannot allocate %d bytes of memory", peb_size);
  53. + return -1;
  54. + }
  55. +
  56. + memset(outbuf, 0xFF, peb_size);
  57. + __ubigen_init_ec_hdr(ui, (struct ubi_ec_hdr *)outbuf, ec, 1);
  58. +
  59. + while (count) {
  60. + if (write(out_fd, outbuf, peb_size) != peb_size) {
  61. + sys_errmsg("cannot write %d bytes to the output file",
  62. + peb_size);
  63. + goto out_free;
  64. + }
  65. +
  66. + count--;
  67. + }
  68. +
  69. + free(outbuf);
  70. return 0;
  71. out_free:
  72. --- a/ubi-utils/include/libubigen.h
  73. +++ b/ubi-utils/include/libubigen.h
  74. @@ -188,6 +188,9 @@ int ubigen_write_layout_vol(const struct
  75. long long ec1, long long ec2,
  76. struct ubi_vtbl_record *vtbl, int fd);
  77. +int ubigen_write_eof_markers(const struct ubigen_info *ui, long long ec,
  78. + int count, int out_fd);
  79. +
  80. #ifdef __cplusplus
  81. }
  82. #endif