summaryrefslogtreecommitdiffstats
path: root/patches/genimage-5/0001-image-flash-actually-write-the-image-and-support-par.patch
blob: d6aca3bf5d3c6668ebb2b4856b2c5b3b53ad503e (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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
From 3ee54067eece5d8f14bfbcab1cb4f2e717775920 Mon Sep 17 00:00:00 2001
From: Jan Luebbe <jlu@pengutronix.de>
Date: Wed, 1 May 2013 23:55:46 +0200
Subject: [PATCH] image-flash: actually write the image and support partition offsets

Signed-off-by: Jan Luebbe <jlu@pengutronix.de>
Signed-off-by: Michael Olbrich <m.olbrich@pengutronix.de>
---
 image-flash.c |   57 +++++++++++++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 51 insertions(+), 6 deletions(-)

diff --git a/image-flash.c b/image-flash.c
index 2939db7..f56cfa7 100644
--- a/image-flash.c
+++ b/image-flash.c
@@ -33,20 +33,37 @@ struct flash_image {
 static int flash_generate(struct image *image)
 {
 	struct partition *part;
-	struct stat s;
-	int ret;
-	const char *buf;
+	enum pad_mode mode = MODE_OVERWRITE;
+	const char *outfile = imageoutfile(image);
 
 	list_for_each_entry(part, &image->partitions, list) {
 		struct image *child;
+		const char *infile;
+		struct stat s;
+		int ret;
+
+		image_log(image, 1, "writing image partition '%s' (0x%llx@0x%llx)\n",
+			part->name, part->size, part->offset);
+
+		ret = pad_file(NULL, outfile, part->offset, 0xFF, mode);
+		if (ret) {
+			image_error(image, "failed to pad image to size %lld\n",
+					part->offset);
+			return ret;
+		}
+		mode = MODE_APPEND;
+
+		if (!part->image)
+			continue;
 
 		child = image_get(part->image);
 		if (!child) {
 			image_error(image, "could not find %s\n", part->name);
 			return -EINVAL;
 		}
-		buf = imageoutfile(child);
-		ret = stat(buf, &s);
+		infile = imageoutfile(child);
+
+		ret = stat(infile, &s);
 		if (ret)
 			return -errno;
 
@@ -55,6 +72,13 @@ static int flash_generate(struct image *image)
 					child->file, part->name, (long long)s.st_size, part->size);
 			return -EINVAL;
 		}
+
+		ret = pad_file(infile, outfile, part->size, 0xFF, mode);
+		if (ret) {
+			image_error(image, "failed to write image partition '%s'\n",
+					part->name);
+			return ret;
+		}
 	}
 
 	return 0;
@@ -88,8 +112,29 @@ static int flash_setup(struct image *image, cfg_t *cfg)
 				goto err_exceed;
 			part->size = flashsize - partsize;
 		}
+		if (part->size % image->flash_type->pebsize) {
+			image_error(image, "part %s size (%lld) must be a "
+					"multiple of erase block size (%i bytes)\n",
+					part->name, part->size, image->flash_type->pebsize);
+			return -EINVAL;
+		}
+		if (part->offset % image->flash_type->pebsize) {
+			image_error(image, "part %s offset (%lld) must be a"
+					"multiple of erase block size (%i bytes)\n",
+					part->name, part->offset, image->flash_type->pebsize);
+			return -EINVAL;
+		}
+		if (part->offset) {
+			if (partsize > part->offset) {
+				image_error(image, "part %s overlaps with previous partition\n",
+					part->name);
+				return -EINVAL;
+			}
+		} else {
+			part->offset = partsize;
+		}
 
-		partsize += part->size;
+		partsize = part->offset + part->size;
 	}
 
 	if (partsize > flashsize) {
-- 
1.7.2.5