aboutsummaryrefslogtreecommitdiffstats
path: root/tools/mtd-utils/patches/200-libubigen-add-ubigen_write_terminator-function.patch
blob: 90c951500f41f4b8e30dd62258e8e68fbabb58d1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
--- 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
@@ -187,6 +187,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