@@ -178,8 +178,11 @@ int Loader::fastLoadImageHelper(const uint8_t *image, int imageSize, LoadType lo
178
178
179
179
/* generate a loader image */
180
180
loaderImage = generateInitialLoaderImage (packetID, fastLoaderBaudRate, &loaderImageSize);
181
- if (!loaderImage)
181
+ if (!loaderImage) {
182
+ message (" generateInitialLoaderImage failed" );
183
+ nerror (ERROR_INTERNAL_CODE_ERROR);
182
184
return -1 ;
185
+ }
183
186
184
187
/* load the second-stage loader using the Propeller ROM protocol */
185
188
message (" Delivering second-stage loader" );
@@ -200,6 +203,7 @@ int Loader::fastLoadImageHelper(const uint8_t *image, int imageSize, LoadType lo
200
203
/* open the transparent serial connection that will be used for the second-stage loader */
201
204
if (m_connection->connect () != 0 ) {
202
205
message (" Failed to connect to target" );
206
+ nerror (ERROR_COMMUNICATION_LOST);
203
207
return -1 ;
204
208
}
205
209
@@ -212,7 +216,7 @@ int Loader::fastLoadImageHelper(const uint8_t *image, int imageSize, LoadType lo
212
216
if ((size = remaining) > m_connection->maxDataSize ())
213
217
size = m_connection->maxDataSize ();
214
218
if ((sts = transmitPacket (packetID, image, size, &result)) != 0 )
215
- return sts ;
219
+ return - 2 ;
216
220
if (result != packetID - 1 ) {
217
221
message (" Unexpected response: expected %d, received %d" , packetID - 1 , result);
218
222
return -2 ;
@@ -244,7 +248,7 @@ int Loader::fastLoadImageHelper(const uint8_t *image, int imageSize, LoadType lo
244
248
return sts;
245
249
if (result != -checksum) {
246
250
nmessage (ERROR_RAM_CHECKSUM_FAILED);
247
- return -2 ;
251
+ return -1 ;
248
252
}
249
253
packetID = -checksum;
250
254
@@ -254,7 +258,7 @@ int Loader::fastLoadImageHelper(const uint8_t *image, int imageSize, LoadType lo
254
258
return sts;
255
259
if (result != -checksum*2 ) {
256
260
nmessage (ERROR_EEPROM_CHECKSUM_FAILED);
257
- return -2 ;
261
+ return -1 ;
258
262
}
259
263
packetID = -checksum*2 ;
260
264
}
@@ -266,7 +270,7 @@ int Loader::fastLoadImageHelper(const uint8_t *image, int imageSize, LoadType lo
266
270
return sts;
267
271
if (result != packetID - 1 ) {
268
272
message (" ReadyToLaunch failed: expected %08x, got %08x" , packetID - 1 , result);
269
- return -2 ;
273
+ return -1 ;
270
274
}
271
275
--packetID;
272
276
@@ -291,8 +295,10 @@ int Loader::transmitPacket(int id, const uint8_t *payload, int payloadSize, int
291
295
int32_t tag, rtag;
292
296
293
297
/* build the packet to transmit */
294
- if (!(packet = (uint8_t *)malloc (packetSize)))
298
+ if (!(packet = (uint8_t *)malloc (packetSize))) {
299
+ nmessage (ERROR_INSUFFICIENT_MEMORY);
295
300
return -1 ;
301
+ }
296
302
setLong (&packet[0 ], id);
297
303
memcpy (&packet[8 ], payload, payloadSize);
298
304
@@ -309,7 +315,7 @@ int Loader::transmitPacket(int id, const uint8_t *payload, int payloadSize, int
309
315
setLong (&packet[4 ], tag);
310
316
// printf("transmit packet %d - tag %08x, size %d\n", id, tag, packetSize);
311
317
if (m_connection->sendData (packet, packetSize) != packetSize) {
312
- message ( " transmitPacket %d failed - sendData " , id );
318
+ nmessage (ERROR_INTERNAL_CODE_ERROR );
313
319
free (packet);
314
320
return -1 ;
315
321
}
@@ -344,6 +350,6 @@ int Loader::transmitPacket(int id, const uint8_t *payload, int payloadSize, int
344
350
345
351
/* return timeout */
346
352
message (" transmitPacket %d failed - timeout" , id);
347
- return -2 ;
353
+ return -1 ;
348
354
}
349
355
0 commit comments