Index: tt-loader/main.c
===================================================================
--- tt-loader/main.c	(revision 13)
+++ tt-loader/main.c	(revision 16)
@@ -66,5 +66,4 @@
 static double ticks ;
 
-#define log1(X)		fprintf(stderr, "%9.3f: "X,((double)times(NULL)-btime)/ticks)
 #define log2(X,Y) 	fprintf(stderr, "%9.3f: "X,((double)times(NULL)-btime)/ticks,(Y))
 #define log3(X,Y,Z)	fprintf(stderr, "%9.3f: "X,((double)times(NULL)-btime)/ticks,(Y),(Z))
@@ -78,4 +77,15 @@
 # define le32_to_cpu(x)	bswap_32 (x)
 #endif
+
+static inline double chrono ()
+{
+	return ((double)times(NULL)-btime)/ticks ;
+}
+
+static inline void log1 ( const char *msg )
+{
+	fprintf(stderr, "%9.3f: ", chrono());
+	return (void)fprintf(stderr, msg);
+}
 
 static inline unsigned round_up (unsigned v, unsigned d)
@@ -248,15 +258,29 @@
 	for (;;)
 	{
-		err= usb_set_configuration (handle, 1);
+		err= -usb_set_configuration (handle, 1);
 		if (err == 0)
 			break;
-		
-		if (err == -ENODEV)
+
+// TODO: l'erreur ENODEV est peut-être juste un problème temporaire dans le noyau
+// et peut réclamer de ré-essayer, y compris plus tard dans le code
+		if (err == ENODEV)
 		{
-			log1("OMAP error, retrying\n");
+			log1("OMAP error, aborting\n");
 			return 1;
 		}
+		else if (err == EPERM)
+		{
+			log1("USB error, you don't have rights to open OMAP device, aborting\n");
+			return 1;
+		}
+		else if (err == ETIME)
+		{
+			log1("OMAP error, you need to reboot your OMAP device, aborting\n");
+			return 1;
+		}
+		else
+			log2("OMAP error %d, retrying\n",err);
 		
-		sleep (1);
+		usleep (100000);
 	}
 	
@@ -814,5 +838,5 @@
 									log1("Asking boot\n");
 									// Quit now witout error set
-									loop = err = -10 ;
+									loop = err = 0 ;
 									cmd = cmdfile.size ;
 									res = 1 ;
@@ -839,5 +863,5 @@
 								{
 									log2("Can't read mach id '%s'\n",&cmdp[cmd]);
-									loop = 0 ; // Just quit on error
+									loop = -10 ; // Just quit on error
 									break ;
 								}
@@ -845,5 +869,5 @@
 									log1("Asking kernel to boot\n");
 									// Quit now witout error set
-									loop = err = -10 ;
+									loop = err = 0 ;
 									cmd = cmdfile.size ;
 									res = 1 ;
@@ -919,5 +943,5 @@
 int main (int argc, char *argv[])
 {
-	int	size;
+	int	size, err=-1;
 	btime = (double) times(NULL);
 	ticks = (double) sysconf(_SC_CLK_TCK) / 1000 ;
@@ -925,5 +949,5 @@
 	if (argc < NUM_ARGS)
 	{
-		log2("Usage: %s <2nd_boot_file> <command_file>\n", argv[ARG_PROGNAME]);
+		fprintf(stderr, "Usage: %s <2nd_boot_file> <command_file>\n", argv[ARG_PROGNAME]);
 		return 1;
 	}
@@ -931,5 +955,5 @@
 	memset (buffer, 0, 128);
 	
-	u_int32_t	*p= (u_int32_t *) buffer;
+	u_int32_t *p= (u_int32_t *) buffer;
 	p[0x00]= cpu_to_le32 (0xf0030002);
 	
@@ -1003,27 +1027,48 @@
 	{
 		log1("Searching OMAP730-USB connection...\n");
-		struct usb_bus	*bus;
-		for (bus= usb_get_busses (); bus; bus= bus->next)
+		while ( chrono() < 30000 )
 		{
-			struct usb_device	*dev;
+			struct usb_bus	*bus;
+			for (bus= usb_get_busses (); bus; bus= bus->next)
+			{
+				struct usb_device	*dev;
+							
+				for (dev= bus->devices; dev; dev= dev->next)
+				{
+					usb_dev_handle	*handle;
+					if (dev->descriptor.idVendor == OMAP_VENDOR  &&
+						dev->descriptor.idProduct == OMAP_PRODUCT  &&
+						(handle= usb_open (dev)) != NULL)
+					{
+						log1("Found OMAP730-USB connection\n");
+						int res= process (handle);
+// TODO Ajouter la déconnexion de la device avec une option pour la garder (cas de renvoi de console)
+						usb_close (handle);
+						if (res == 0) {
+							log1("OMAP730-USB connection processed\n");
+							err = 0 ;
+							break ;
+							
+						} else {
+							log1("OMAP730-USB processing failed\n");
+							err = 1 ;
+							break ;
+						}
+					}
+				}
+				if ( err >= 0 )
+					break ;
+			}
 			
-			for (dev= bus->devices; dev; dev= dev->next)
-			{
-				usb_dev_handle	*handle;
-				if (dev->descriptor.idVendor == OMAP_VENDOR  &&
-					dev->descriptor.idProduct == OMAP_PRODUCT  &&
-					(handle= usb_open (dev)) != NULL)
-				{
-					log1("Found OMAP730-USB connection\n");
-					int res= process (handle);
-					usb_close (handle);
-					if (res == 0) {
-						log1("OMAP730-USB connection processed\n");
-						return 0 ;
-					} else
-						log1("OMAP730-USB processing failed\n");
-				}
-			}
+			if ( err >= 0 )
+				break ;
+			
+			while ( ! usb_find_devices() && chrono() < 5000 )
+				usleep(10000);
 		}
+		
+		if (err<0)
+			log1("Time-out: No OMAP-730 found\n");
+	
 		
 	} else {
@@ -1034,6 +1079,5 @@
 	if (cmdfile.content!=NULL)
 		free((void *)cmdfile.content);
-	
-	log1("No target connection found\n");
+
 	return 1 ;
 }
