Index: /tt-loader/Makefile
===================================================================
--- /tt-loader/Makefile	(revision 15)
+++ /tt-loader/Makefile	(revision 16)
@@ -5,5 +5,5 @@
 LDFLAGS = -g $(LIBS)
 APP_NAME = tt-loader
-APP_VERSION = 0.2.1
+APP_VERSION = 0.2.2
 
 # Adapt this to your system
@@ -30,7 +30,12 @@
 pkg: 2nd
 	rm -f $(APP_NAME)-$(APP_VERSION).tar.gz
-	tar czf $(APP_NAME)-$(APP_VERSION).tar.gz Makefile *.c COPYING README \
-		CMD-SYNTAX commands.txt write-splash.txt FlashWriteNAND.txt \
-		tt-loader.sh 2nd/arm.ld 2nd/*.h 2nd/*.c 2nd/Makefile 2nd/start.S 2nd/2nd.bin
+	mkdir -p $(APP_NAME)-$(APP_VERSION)/2nd
+	cp -a Makefile *.c COPYING README CMD-SYNTAX start-kernel.txt \
+		commands.txt write-splash.txt FlashWriteNAND.txt tt-loader.sh \
+		$(APP_NAME)-$(APP_VERSION)
+	cp -a 2nd/arm.ld 2nd/*.h 2nd/*.c 2nd/Makefile 2nd/start.S 2nd/2nd.bin \
+		$(APP_NAME)-$(APP_VERSION)/2nd
+	tar czf $(APP_NAME)-$(APP_VERSION).tar.gz $(APP_NAME)-$(APP_VERSION)
+	rm -rf $(APP_NAME)-$(APP_VERSION)
 
 %.dis: %.bin
Index: /tt-loader/commands.txt
===================================================================
--- /tt-loader/commands.txt	(revision 15)
+++ /tt-loader/commands.txt	(revision 16)
@@ -453,4 +453,29 @@
 end
 /////////////////////////////////////////////////////////////////// READNAND END
+
+/////////////////////////////////////////////////////////////////// KERNEL
+# Booting TT with modified hosted u-boot
+a 0x20010000
+f x-load.bin
+
+// Call a sub from x-load.bin: TT BoardInit (should only work with TT)
+a 0x20010da4
+c
+
+// Load updated u-boot.bin
+a 0x10280000
+f u-boot-updated.bin
+
+a 0x11800000
+f uImage.bin
+
+// Send u-boot start address and boot there, u-boot "bootcmd" must has
+// fixed to not download kernel from NAND but always boot the kernel
+// loaded at 0x11800000 address in RAM
+a 0x10280000
+b
+
+end
+/////////////////////////////////////////////////////////////////// KERNEL END
 
 /////////////////////////////////////////////////////////////////// U-BOOT
Index: /tt-loader/main.c
===================================================================
--- /tt-loader/main.c	(revision 15)
+++ /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 ;
 }
Index: /tt-loader/start-kernel.txt
===================================================================
--- /tt-loader/start-kernel.txt	(revision 16)
+++ /tt-loader/start-kernel.txt	(revision 16)
@@ -0,0 +1,29 @@
+/////////////////////////////////////////////////////////////////// KERNEL
+# Booting TT with modified hosted u-boot
+a 0x20010000
+f x-load.bin
+
+// Call a sub from x-load.bin: TT BoardInit (should only work with TT)
+a 0x20010da4
+c
+
+
+// Uncomment to send an address to dump from, then dump some memory blocks
+//a 0x20000000
+//M;M;M;M;M;M;M;M;M;M;M;M;M;M;M;M
+
+// Load updated u-boot.bin
+a 0x10280000
+f u-boot-updated.bin
+
+a 0x11800000
+f uImage.bin
+
+// Send u-boot start address and boot there, u-boot "bootcmd" must has
+// fixed to not download kernel from NAND but always boot the kernel
+// loaded at 0x11800000 address in RAM
+a 0x10280000
+b
+
+end
+/////////////////////////////////////////////////////////////////// KERNEL END
