summarylogtreecommitdiffstats
path: root/110-wrt350nv2_support.patch
blob: eea7cc4d000de8029000a263bdbee8fcb7451b07 (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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
--- a/nslu2_image.cc
+++ b/nslu2_image.cc
@@ -54,28 +54,44 @@ namespace NSLU2Image {
 				int &address, int &length) {
 			address = image.tellg();
 			length = buffer_length;
-			if (address+length > NSLU2Protocol::FlashSize)
-				length = NSLU2Protocol::FlashSize-address;
+			if (address+length > EndAddress)
+				length = EndAddress-address;
 			if (length > 0)
 				SafeRead(&image, buffer, length, "image (read)");
 		}
 
+		virtual void GetBoundaries(int &start, int &end)
+		{
+			start = BaseAddress;
+			end = EndAddress;
+		}
+
 		/* Rewind to the start of the image (or the Kernel if not
 		 * doing a complete reprogram).
 		 */
 		virtual void Rewind(void) {
-			SafeSeek(&image, reprogram ? 0 : NSLU2Protocol::BaseAddress,
+			SafeSeek(&image, reprogram ? 0 : BaseAddress,
 					"image (seek)");
 		}
 
 	private:
+		int BaseAddress;
+		int EndAddress;
+
 		/* Validate that this really is an image file. */
 		void Validate(const char *i) {
 			char signature[8];
 
 			SafeSeek(&image, -8, i, std::ios::end);
 			SafeRead(&image, signature, 8, i);
-			if (memcmp(signature, "eRcOmM", 6) != 0)
+
+			if (memcmp(signature, "eRcOmM", 6) == 0) {
+				BaseAddress = NSLU2Protocol::BaseAddress;
+				EndAddress = NSLU2Protocol::FlashSize;
+			} else if (memcmp(signature + 1, "sErCoMm", 7) == 0) {
+				BaseAddress = 0;
+				EndAddress = NSLU2Protocol::FlashSize - 0x40000;
+			} else
 				throw NSLU2Image::FileError(DataError, i, 0);
 		}
 
@@ -93,6 +109,12 @@ namespace NSLU2Image {
 		virtual ~SynthesiseImage() {
 		}
 
+		void GetBoundaries(int &start, int &end)
+		{
+			start = NSLU2Protocol::BaseAddress;
+			end = NSLU2Protocol::FlashSize;
+		}
+
 		/* Get the next block of bytes, returns an address and length, false if
 		 * there is a problem.
 		 */
--- a/nslu2_image.h
+++ b/nslu2_image.h
@@ -35,6 +35,8 @@ namespace NSLU2Image {
 		virtual ~Image() {
 		}
 
+		virtual void GetBoundaries(int &start, int &end) = 0;
+
 		/* Get the next block of bytes, returns an address and length.
 		 */
 		virtual void GetBytes(char *buffer, size_t buffer_length,
--- a/nslu2_upgrade.cc
+++ b/nslu2_upgrade.cc
@@ -95,7 +95,7 @@ namespace NSLU2Upgrade {
 
 	class RealDoUpgrade : public DoUpgrade {
 	public:
-		RealDoUpgrade(Wire *w, Progress *p, bool r) :
+		RealDoUpgrade(Wire *w, Progress *p, bool r, int start, int end) :
 			wire(w), progress(p), sequenceError(-1), reprogram(r),
 			lastType(NSLU2Protocol::InvalidType) {
 			if (reprogram) {
@@ -105,6 +105,8 @@ namespace NSLU2Upgrade {
 				NSLU2Protocol::UpgradeStartPacket packet(seq);
 				wire->Send(packet.PacketBuffer(), packet.PacketLength());
 			}
+			BaseAddress = start;
+			EndAddress = end;
 		}
 
 		virtual ~RealDoUpgrade() {
@@ -205,8 +207,8 @@ namespace NSLU2Upgrade {
 
 	};
 
-	DoUpgrade *DoUpgrade::MakeDoUpgrade(Wire *wire, Progress *progress, bool reprogram) {
-		return new RealDoUpgrade(wire, progress, reprogram);
+	DoUpgrade *DoUpgrade::MakeDoUpgrade(Wire *wire, Progress *progress, bool reprogram, int start, int end) {
+		return new RealDoUpgrade(wire, progress, reprogram, start, end);
 	}
 };
 
@@ -421,13 +423,18 @@ void NSLU2Upgrade::RealDoUpgrade::Upgrad
 	/* Simple upgrade programs only the addresses beyound BaseAddress,
 	 * reprogram overwrites the whole flash.
 	 */
-	if (!reprogram && address < NSLU2Protocol::BaseAddress) {
+	if (!reprogram && address < BaseAddress) {
 		length += address;
-		if (length <= NSLU2Protocol::BaseAddress)
+		if (length <= BaseAddress)
 			return; /* nothing to do. */
-		address = NSLU2Protocol::BaseAddress;
+		address = BaseAddress;
 		length -= address;
 	}
+	if (!reprogram && address + length > EndAddress) {
+		if (address >= EndAddress)
+			return; /* nothing to do. */
+		length -= EndAddress - address;
+	}
 
 #if 1
 	/* Skip blocks of 255 valued bytes - the erase clears the flash to this
@@ -495,11 +502,11 @@ void NSLU2Upgrade::RealDoUpgrade::Verify
 		Finish();
 
 	/* Verify never verifies anything below BaseAddress. */
-	if (address < NSLU2Protocol::BaseAddress) {
+	if (address < BaseAddress) {
 		length += address;
-		if (length <= NSLU2Protocol::BaseAddress)
+		if (length <= BaseAddress)
 			return; /* nothing to do. */
-		address = NSLU2Protocol::BaseAddress;
+		address = BaseAddress;
 		length -= address;
 	}
 
--- a/nslu2_upgrade.h
+++ b/nslu2_upgrade.h
@@ -206,6 +206,8 @@ namespace NSLU2Upgrade {
 
 	class DoUpgrade {
 	public:
+		int BaseAddress;
+		int EndAddress;
 		virtual ~DoUpgrade() {
 		}
 
@@ -228,7 +230,7 @@ namespace NSLU2Upgrade {
 		virtual void Reboot(void) = 0;
 			/* Reboot the NSLU2. */
 
-		static DoUpgrade *MakeDoUpgrade(Wire *wire, Progress *progress, bool reprogram);
+		static DoUpgrade *MakeDoUpgrade(Wire *wire, Progress *progress, bool reprogram, int start, int end);
 			/* Instantiate a real DoUpgrade, returns NULL if the object
 			 * cannot be instantiated.
 			 *
--- a/upslug2.cc
+++ b/upslug2.cc
@@ -21,8 +21,8 @@
 
 class ProgressBar : public UpSlug2::CharacterProgressBar<80> {
 public:
-	ProgressBar(bool reprogram, const unsigned char *t) :
-		UpSlug2::CharacterProgressBar<80>(reprogram, 64),
+	ProgressBar(bool reprogram, const unsigned char *t, int start, int end) :
+		UpSlug2::CharacterProgressBar<80>(reprogram, 64, start, end),
 		target(t), displayed(false), ticker(0) {
 	}
 
@@ -95,7 +95,7 @@ private:
 			else if (seen == -1) {
 				seen = 0;
 				if (!reprogram)
-					sent -= NSLU2Protocol::BaseAddress;
+					sent -= NSLU2Protocol::FlashSize - (EndAddress - BaseAddress);
 			} else
 				sent -= seen;
 
@@ -423,7 +423,7 @@ int main(int argc, char **argv) {
 { 0,                                                            0,                 0,  0  }
 	};
 
-	do switch (getopt_long(argc, argv, "he:d:t:f:vUni:Ck:r:R:j:p:P:T:F:E:", options, 0)) {
+	do switch (getopt_long(argc, argv, "he:d:t:f:vUni:Ck:r:R:j:op:P:T:F:E:", options, 0)) {
 	case  -1: if (optind < argc) {
 			  std::fprintf(stderr, "%s: unrecognised option\n", argv[optind]);
 			  std::exit(1);
@@ -523,16 +523,22 @@ done:
 
 		if (mac && got_kernel) {
 			Pointer<NSLU2Upgrade::Wire> wire(NSLU2Upgrade::Wire::MakeWire(device, fromMac, mac, euid));
-			ProgressBar progress(reprogram, mac);
+			int BaseAddress = NSLU2Protocol::BaseAddress;
+			int EndAddress = NSLU2Protocol::FlashSize;
 
 			if (full_image) { /* complete image. */
 				/* The full image case allows a complete reprogram. */
+				NSLU2Image::Image *image_p;
 				Pointer<NSLU2Image::Image> image(
 						NSLU2Image::Image::MakeImage(
 							reprogram, full_image));
+				image_p = image.p;
+				image_p->GetBoundaries(BaseAddress, EndAddress);
+				ProgressBar progress(reprogram, mac, BaseAddress, EndAddress);
 				Pointer<NSLU2Upgrade::DoUpgrade> upgrade(
 					NSLU2Upgrade::DoUpgrade::MakeDoUpgrade(
-						wire.p, &progress, reprogram));
+						wire.p, &progress, reprogram,
+						BaseAddress, EndAddress));
 				progress.FirstDisplay();
 				Upgrade(upgrade.p, image.p, no_upgrade, no_verify);
 				progress.EndDisplay();
@@ -551,9 +557,11 @@ done:
 							fis_payload,
 							product_id, protocol_id,
 							firmware_version, extra_version));
+				ProgressBar progress(reprogram, mac, BaseAddress, EndAddress);
 				Pointer<NSLU2Upgrade::DoUpgrade> upgrade(
 					NSLU2Upgrade::DoUpgrade::MakeDoUpgrade(
-						wire.p, &progress, false));
+						wire.p, &progress, false,
+						BaseAddress, EndAddress));
 				progress.FirstDisplay();
 				Upgrade(upgrade.p, image.p, no_upgrade, no_verify);
 				progress.EndDisplay();
--- a/upslug2_progress.h
+++ b/upslug2_progress.h
@@ -161,15 +161,19 @@ namespace UpSlug2 {
 			Timedout,   /* *: timeout on a sent packet for this address. */
 			NumberOfStates
 		} Status;
-		
+		int BaseAddress;
+		int EndAddress;
+
 		/* reprogram says whether this is a full reprogram (the entire
 		 * flash will be erased) or not (the leading, RedBoot, SysConf
 		 * partitions are not erased).
 		 * resolution should be about 6 for a command line (character)
 		 * progress bar and 8 for a GUI (pixel) progress bar.
 		 */
-		ProgressBar(bool r) :
+		ProgressBar(bool r, int start, int end) :
 			reprogram(r), timeout(false), retransmit(false), status(Init) {
+			BaseAddress = start;
+			EndAddress = end;
 		}
 
 		/* lowWaterMark..(highWaterMark-1) bytes are in state 'st',
@@ -179,8 +183,8 @@ namespace UpSlug2 {
 			/* These initial settings cover the majority of cases
 			 * correctly.
 			 */
-			lowWaterMark = reprogram ? 0 : NSLU2Protocol::BaseAddress;
-			highWaterMark = status >= st ? NSLU2Protocol::FlashSize-1 : 0;
+			lowWaterMark = reprogram ? 0 : BaseAddress;
+			highWaterMark = status >= st ? EndAddress-1 : 0;
 			switch (st) {
 			case Init:
 				/* Everything has an initial value... */
@@ -286,9 +290,9 @@ namespace UpSlug2 {
 	 */
 	template <int characters> class CharacterProgressBar : public ProgressBar {
 	public:
-		CharacterProgressBar(bool reprogram, int n, const char ind[NumberOfStates] = 0) :
+		CharacterProgressBar(bool reprogram, int n, int start, int end, const char ind[NumberOfStates] = 0) :
 			numberOfCharacters(n > characters || n < 1 ? characters : n),
-			ProgressBar(reprogram) {
+			ProgressBar(reprogram, start, end) {
 			if (ind)
 				std::memcpy(indicators, ind, NumberOfStates);
 			else