@@ -178,8 +178,11 @@ int Loader::fastLoadImageHelper(const uint8_t *image, int imageSize, LoadType lo
178178
179179 /* generate a loader image */
180180 loaderImage = generateInitialLoaderImage (packetID, fastLoaderBaudRate, &loaderImageSize);
181- if (!loaderImage)
181+ if (!loaderImage) {
182+ message (" generateInitialLoaderImage failed" );
183+ nerror (ERROR_INTERNAL_CODE_ERROR);
182184 return -1 ;
185+ }
183186
184187 /* load the second-stage loader using the Propeller ROM protocol */
185188 message (" Delivering second-stage loader" );
@@ -200,6 +203,7 @@ int Loader::fastLoadImageHelper(const uint8_t *image, int imageSize, LoadType lo
200203 /* open the transparent serial connection that will be used for the second-stage loader */
201204 if (m_connection->connect () != 0 ) {
202205 message (" Failed to connect to target" );
206+ nerror (ERROR_COMMUNICATION_LOST);
203207 return -1 ;
204208 }
205209
@@ -212,7 +216,7 @@ int Loader::fastLoadImageHelper(const uint8_t *image, int imageSize, LoadType lo
212216 if ((size = remaining) > m_connection->maxDataSize ())
213217 size = m_connection->maxDataSize ();
214218 if ((sts = transmitPacket (packetID, image, size, &result)) != 0 )
215- return sts ;
219+ return - 2 ;
216220 if (result != packetID - 1 ) {
217221 message (" Unexpected response: expected %d, received %d" , packetID - 1 , result);
218222 return -2 ;
@@ -244,7 +248,7 @@ int Loader::fastLoadImageHelper(const uint8_t *image, int imageSize, LoadType lo
244248 return sts;
245249 if (result != -checksum) {
246250 nmessage (ERROR_RAM_CHECKSUM_FAILED);
247- return -2 ;
251+ return -1 ;
248252 }
249253 packetID = -checksum;
250254
@@ -254,7 +258,7 @@ int Loader::fastLoadImageHelper(const uint8_t *image, int imageSize, LoadType lo
254258 return sts;
255259 if (result != -checksum*2 ) {
256260 nmessage (ERROR_EEPROM_CHECKSUM_FAILED);
257- return -2 ;
261+ return -1 ;
258262 }
259263 packetID = -checksum*2 ;
260264 }
@@ -266,7 +270,7 @@ int Loader::fastLoadImageHelper(const uint8_t *image, int imageSize, LoadType lo
266270 return sts;
267271 if (result != packetID - 1 ) {
268272 message (" ReadyToLaunch failed: expected %08x, got %08x" , packetID - 1 , result);
269- return -2 ;
273+ return -1 ;
270274 }
271275 --packetID;
272276
@@ -291,8 +295,10 @@ int Loader::transmitPacket(int id, const uint8_t *payload, int payloadSize, int
291295 int32_t tag, rtag;
292296
293297 /* build the packet to transmit */
294- if (!(packet = (uint8_t *)malloc (packetSize)))
298+ if (!(packet = (uint8_t *)malloc (packetSize))) {
299+ nmessage (ERROR_INSUFFICIENT_MEMORY);
295300 return -1 ;
301+ }
296302 setLong (&packet[0 ], id);
297303 memcpy (&packet[8 ], payload, payloadSize);
298304
@@ -309,7 +315,7 @@ int Loader::transmitPacket(int id, const uint8_t *payload, int payloadSize, int
309315 setLong (&packet[4 ], tag);
310316 // printf("transmit packet %d - tag %08x, size %d\n", id, tag, packetSize);
311317 if (m_connection->sendData (packet, packetSize) != packetSize) {
312- message ( " transmitPacket %d failed - sendData " , id );
318+ nmessage (ERROR_INTERNAL_CODE_ERROR );
313319 free (packet);
314320 return -1 ;
315321 }
@@ -344,6 +350,6 @@ int Loader::transmitPacket(int id, const uint8_t *payload, int payloadSize, int
344350
345351 /* return timeout */
346352 message (" transmitPacket %d failed - timeout" , id);
347- return -2 ;
353+ return -1 ;
348354}
349355
0 commit comments