Index: trunk/boot/tsar_mips32/boot.c
===================================================================
--- trunk/boot/tsar_mips32/boot.c	(revision 562)
+++ trunk/boot/tsar_mips32/boot.c	(revision 572)
@@ -2,5 +2,6 @@
  * boot.c - TSAR bootloader implementation.
  * 
- * Authors :   Alain Greiner / Vu Son  (2016)
+ * Authors :   Vu Son  (2016)
+ *             Alain Greiner (2016, 2017,2018)
  *
  * Copyright (c) UPMC Sorbonne Universites
@@ -55,9 +56,9 @@
  *      - activate all other cores in the same cluster (CPi).               *
  *      - wait local CPi completion reports on a local barrier.             *
- *      - report completion to bscpu on the global barrier.                 *
+ *      - report completion  on the global barrier.                         *
  *                                                                          *
  * 3) The boot-loader third phase is executed in parallel by all cores.     *
- *    After passing the global barrier the bscpu:                           *
- *      - activates the CPi of cluster(0),                                  *
+ *    In each cluster (i) the CP0                                           *
+ *      - activates the other cores of cluster(i),                          *
  *      - blocks on the local barrier waiting for all local CPi to report   *
  *        completion on the local barrier,                                  *
@@ -65,6 +66,5 @@
  *        address 0x0, (erasing the preloader code).                        *
  *                                                                          *
- * 4) All cores have finished the boot phase, they jump to the kern_init()  *
- *    function (maybe not at the same time).                                *
+ * 4) All cores jump to kern_init() (maybe not at the same time).           *
  ****************************************************************************/
 
@@ -77,6 +77,4 @@
 #include <arch_info.h>
 #include <boot_info.h>
-
-#include <cluster_info.h>
 
 #include <boot_utils.h>
@@ -84,5 +82,4 @@
 #include <boot_bdv_driver.h>
 #include <boot_hba_driver.h>
-#include <boot_spi_driver.h>
 #include <boot_tty_driver.h>
 
@@ -117,15 +114,18 @@
 uint32_t                        kernel_entry;    // kernel entry point
 
-// address used by the WTI to activate remote CP0s
-
-// Functions called by boot_entry.S must be externs.
+// Functions called by boot_entry.S 
+
 extern void boot_entry( void );    // boot_loader entry point
 extern void boot_loader( lid_t lid, cxy_t cxy );
 
+
+#if DEBUG_BOOT_INFO
 /*********************************************************************************
- * This function returns the printable string for each device type
+ * This debug function returns the printable string for each device type.
  ********************************************************************************/
-static const char * device_type_str( boot_device_types_t dev_type ) {
-    switch (dev_type) {
+static char * device_type_str( enum device_types_e dev_type ) 
+{
+    switch ( dev_type ) 
+    {
         case DEV_TYPE_RAM_SCL: return "RAM_SCL";
         case DEV_TYPE_ROM_SCL: return "ROM_SCL";
@@ -148,4 +148,5 @@
     }
 }
+#endif
 
 /************************************************************************************
@@ -160,6 +161,6 @@
     {
         boot_printf("\n[BOOT ERROR]: boot_archinfo_load(): "
-                    "<%s> file not found\n",
-                    ARCHINFO_PATHNAME);
+        "<%s> file not found\n",
+        ARCHINFO_PATHNAME);
         boot_exit();
     }
@@ -168,6 +169,6 @@
     {
         boot_printf("\n[BOOT_ERROR]: boot_archinfo_load(): "
-                    "<%s> file signature should be %x\n",
-                    ARCHINFO_PATHNAME, ARCHINFO_SIGNATURE);
+        "<%s> file signature should be %x\n",
+        ARCHINFO_PATHNAME, ARCHINFO_SIGNATURE);
         boot_exit();
     }
@@ -175,5 +176,5 @@
 #if DEBUG_BOOT_INFO
 boot_printf("\n[BOOT INFO] in %s : file %s loaded at address = %x\n",
-            __FUNCTION__ , ARCHINFO_PATHNAME , ARCHINFO_BASE );
+__FUNCTION__ , ARCHINFO_PATHNAME , ARCHINFO_BASE );
 #endif
 
@@ -204,5 +205,5 @@
 #if DEBUG_BOOT_ELF 
 boot_printf("\n[BOOT INFO] %s enters for file %s at cycle %d\n",
-            __FUNCTION__ , KERNEL_PATHNAME , boot_get_proctime() );
+__FUNCTION__ , KERNEL_PATHNAME , boot_get_proctime() );
 #endif
 
@@ -261,6 +262,6 @@
 #if DEBUG_BOOT_ELF 
 boot_printf("\n[BOOT INFO] in %s for file %s : found loadable segment\n"
-            "   base = %x / size = %x\n",
-            __FUNCTION__ , KERNEL_PATHNAME , seg_paddr , seg_memsz );
+"   base = %x / size = %x\n",
+__FUNCTION__ , KERNEL_PATHNAME , seg_paddr , seg_memsz );
 #endif
 
@@ -282,6 +283,6 @@
                 {
                     boot_printf("\n[BOOT_ERROR] in %s for file %s :\n"
-                                "   two kcode segments found\n",
-                                __FUNCTION__ , KERNEL_PATHNAME );
+                    "   two kcode segments found\n",
+                    __FUNCTION__ , KERNEL_PATHNAME );
                     boot_exit();
                 } 
@@ -296,6 +297,6 @@
                 {
                     boot_printf("\n[BOOT_ERROR] in %s for file %s :\n"
-                                "   two kentry segments found\n",
-                                __FUNCTION__ , KERNEL_PATHNAME );
+                    "   two kentry segments found\n",
+                    __FUNCTION__ , KERNEL_PATHNAME );
                     boot_exit();
                 } 
@@ -310,6 +311,6 @@
                 {
                     boot_printf("\n[BOOT_ERROR] in %s for file %s :\n"
-                                "   two loadable kdata segments found\n",
-                                __FUNCTION__ , KERNEL_PATHNAME );
+                    "   two kdata segments found\n",
+                    __FUNCTION__ , KERNEL_PATHNAME );
                     boot_exit();
                 } 
@@ -326,5 +327,5 @@
     {
         boot_printf("\n[BOOT_ERROR] in %s for file %s : seg_kcode not found\n",
-                    __FUNCTION__ , KERNEL_PATHNAME );
+        __FUNCTION__ , KERNEL_PATHNAME );
         boot_exit();
     }
@@ -332,5 +333,5 @@
     {
         boot_printf("\n[BOOT_ERROR] in %s for file %s : seg_kentry not found\n",
-                    __FUNCTION__ , KERNEL_PATHNAME );
+        __FUNCTION__ , KERNEL_PATHNAME );
         boot_exit();
     }
@@ -338,5 +339,5 @@
     {
         boot_printf("\n[BOOT_ERROR] in %s for file %s : seg_kdata not found\n",
-                    __FUNCTION__ , KERNEL_PATHNAME );
+        __FUNCTION__ , KERNEL_PATHNAME );
         boot_exit();
     }
@@ -346,5 +347,5 @@
     {
         boot_printf("\n[BOOT_ERROR] in %s for file %s : seg_kentry too large\n",
-                    __FUNCTION__ , KERNEL_PATHNAME );
+        __FUNCTION__ , KERNEL_PATHNAME );
         boot_exit();
     }
@@ -353,5 +354,5 @@
     {
         boot_printf("\n[BOOT_ERROR] in %s for file %s : seg_kcode + seg_kdata too large\n",
-                    __FUNCTION__ , KERNEL_PATHNAME );
+        __FUNCTION__ , KERNEL_PATHNAME );
     }
 
@@ -361,5 +362,5 @@
 #if DEBUG_BOOT_ELF 
 boot_printf("\n[BOOT INFO] %s completed for file %s at cycle %d\n",
-            __FUNCTION__ , KERNEL_PATHNAME , boot_get_proctime() );
+__FUNCTION__ , KERNEL_PATHNAME , boot_get_proctime() );
 #endif
 
@@ -382,5 +383,5 @@
     archinfo_cluster_t * cluster; 
     archinfo_cluster_t * my_cluster = NULL;   // target cluster
-    archinfo_cluster_t * io_cluster = NULL;   // cluster containing ext. peripherals
+    archinfo_cluster_t * io_cluster = NULL;   // external peripherals cluster 
 
     archinfo_core_t    * core;
@@ -416,15 +417,6 @@
     boot_info->kentry_size = seg_kentry_size;
 
-    /* Initialize all clusters as empty for now */
-    int x, y;
-    for ( x = 0; x < CONFIG_MAX_CLUSTERS_X; x++)
-    {
-        for ( x = 0; x < CONFIG_MAX_CLUSTERS_X; x++)
-        {
-            boot_info->cluster_info[x][y] = 0x0;
-        }
-    }
-
-    // loop on arch_info clusters to get relevant pointers
+    // loop on arch_info clusters to build cluster_info[][] array
+    // and get io_cluster and my_cluster pointers 
     for (cluster =  cluster_base;
          cluster < &cluster_base[header->x_size * header->y_size];
@@ -433,13 +425,8 @@
         int x = cluster->cxy >> Y_WIDTH;
         int y = cluster->cxy & ((1 << Y_WIDTH) - 1);
-
-        if( cluster->cxy  == cxy )            my_cluster = cluster;
-        if( cluster->cxy  == header->io_cxy ) {
-            io_cluster = cluster;
-            boot_info->cluster_info[x][y] |= CINFO_IS_IO;
-        }
-        if ( cluster->cores > 0 ) {
-            boot_info->cluster_info[x][y] |= CINFO_ACTIVE;
-        }
+        boot_info->cluster_info[x][y] = (uint8_t)cluster->cores;
+
+        if( cluster->cxy == cxy )            my_cluster = cluster;
+        if( cluster->cxy == header->io_cxy ) io_cluster = cluster;
     }
 
@@ -447,5 +434,5 @@
     {
         boot_printf("\n[ERROR] in %s : cannot found cluster %x in arch_info\n",
-                    __FUNCTION__ , cxy );
+        __FUNCTION__ , cxy );
         boot_exit();
     }
@@ -454,5 +441,5 @@
     {
         boot_printf("\n[ERROR] in %s : cannot found io_cluster %x in arch_info\n",
-                    __FUNCTION__ , header->io_cxy );
+        __FUNCTION__ , cxy );
         boot_exit();
     }
@@ -463,5 +450,5 @@
 #if DEBUG_BOOT_INFO
 boot_printf("\n[BOOT INFO] %s : external peripherals at cycle %d\n",
-            __FUNCTION__ , boot_get_proctime() );
+__FUNCTION__ , boot_get_proctime() );
 #endif
 
@@ -474,5 +461,5 @@
         {
             boot_printf("\n[ERROR] in %s : too much external devices in arch_info\n",
-                        __FUNCTION__ );
+            __FUNCTION__ );
             boot_exit();
         }
@@ -501,6 +488,5 @@
 #if DEBUG_BOOT_INFO
 boot_printf("  - %s : base = %l / size = %l / channels = %d / irqs = %d\n",
-            device_type_str( device->type ) , device->base , device->size ,
-            device->channels , device->irqs );   
+device_type_str(device->type), device->base, device->size, device->channels, device->irqs );
 #endif
         }
@@ -525,5 +511,5 @@
 #if DEBUG_BOOT_INFO
 boot_printf("    . irq_port = %d / source = %s / channel = %d / is_rx = %d\n",
-            irq->port , device_type_str( irq->dev_type ) , irq->channel , irq->is_rx );
+irq->port , device_type_str( irq->dev_type ) , irq->channel , irq->is_rx );
 #endif
             }
@@ -554,5 +540,5 @@
 #if DEBUG_BOOT_INFO
 boot_printf("  - core_gid = %x : cxy = %x / lid = %d\n", 
-            core->gid , core->cxy , core->lid );
+core->gid , core->cxy , core->lid );
 #endif
         core_id++;
@@ -566,5 +552,6 @@
 
 #if DEBUG_BOOT_INFO
-boot_printf("\n[BOOT INFO] %s : internal peripherals in cluster %x\n", __FUNCTION__ , cxy );
+boot_printf("\n[BOOT INFO] %s : internal peripherals in cluster %x\n",
+__FUNCTION__ , cxy );
 #endif
 
@@ -615,6 +602,6 @@
 #if DEBUG_BOOT_INFO
 boot_printf("  - %s : base = %l / size = %l / channels = %d / irqs = %d\n",
-            device_type_str( device->type ) , device->base , device->size ,
-            device->channels , device->irqs );   
+device_type_str( device->type ) , device->base , device->size ,
+device->channels , device->irqs );   
 #endif
 
@@ -637,5 +624,5 @@
 #if DEBUG_BOOT_INFO
 boot_printf("    . irq_port = %d / source = %s / channel = %d / is_rx = %d\n",
-            irq->port , device_type_str( irq->dev_type ) , irq->channel , irq->is_rx );
+irq->port , device_type_str( irq->dev_type ) , irq->channel , irq->is_rx );
 #endif
 
@@ -656,5 +643,5 @@
                  (end >> CONFIG_PPM_PAGE_SHIFT) : (end >> CONFIG_PPM_PAGE_SHIFT) + 1;
 
-    // no reserved sones for TSAR architecture
+    // no reserved zones for TSAR architecture
     boot_info->rsvd_nr = 0;
 
@@ -738,5 +725,5 @@
 #if DEBUG_BOOT_WAKUP
 boot_printf("\n[BOOT] core[%x,0] activated at cycle %d\n",
-            cluster->cxy , boot_get_proctime );
+cluster->cxy , boot_get_proctime );
 #endif
 
@@ -767,5 +754,5 @@
 #if DEBUG_BOOT_WAKUP
 boot_printf("\n[BOOT] core[%x,%d] activated at cycle %d\n",
-             boot_info->cxy , core_id , boot_get_proctime() );
+boot_info->cxy , core_id , boot_get_proctime() );
 #endif
         // send an IPI 
@@ -801,5 +788,5 @@
             else if (USE_IOC_HBA) boot_hba_init();
             // else if (USE_IOC_SDC) boot_sdc_init();
-            else if (USE_IOC_SPI) boot_spi_init();
+            // else if (USE_IOC_SPI) boot_spi_init();
             else if (!USE_IOC_RDK)
             {
@@ -816,8 +803,11 @@
 
             boot_printf("\n[BOOT] core[%x,%d] loaded kernel at cycle %d\n",
-                        cxy , lid , boot_get_proctime() );
+            cxy , lid , boot_get_proctime() );
 
             // Load the arch_info.bin file into memory.
             boot_archinfo_load();
+
+            boot_printf("\n[BOOT] core[%x,%d] loaded arch_info at cycle %d\n",
+            cxy , lid , boot_get_proctime() );
 
             // Get local boot_info_t structure base address.
@@ -827,4 +817,7 @@
             // Initialize local boot_info_t structure.
             boot_info_init( boot_info , cxy );
+
+            boot_printf("\n[BOOT] core[%x,%d] initialised boot_info at cycle %d\n",
+            cxy , lid , boot_get_proctime() );
 
             // check boot_info signature
@@ -832,11 +825,8 @@
             {
                 boot_printf("\n[BOOT ERROR] in %s reported by core[%x,%d]\n"
-                            "  illegal boot_info signature / should be %x\n",
-                            __FUNCTION__ , cxy , lid , BOOT_INFO_SIGNATURE );
+                "  illegal boot_info signature / should be %x\n",
+                __FUNCTION__ , cxy , lid , BOOT_INFO_SIGNATURE );
                 boot_exit();
             }
-
-            boot_printf("\n[BOOT] core[%x,%d] loaded arch_info at cycle %d\n",
-                        cxy , lid , boot_get_proctime() );
 
             // Check core information.
@@ -881,5 +871,5 @@
             // from now, it is safe to refer to the boot code global variables 
             boot_printf("\n[BOOT] core[%x,%d] replicated boot code at cycle %d\n",
-                        cxy , lid , boot_get_proctime() );
+            cxy , lid , boot_get_proctime() );
 
 			// switch to the INSTRUCTION local memory space, to avoid contention.
@@ -892,5 +882,5 @@
 
             boot_printf("\n[BOOT] core[%x,%d] replicated arch_info at cycle %d\n",
-                        cxy , lid , boot_get_proctime() );
+            cxy , lid , boot_get_proctime() );
 
             // Copy the kcode segment into local memory 
@@ -910,5 +900,5 @@
 
             boot_printf("\n[BOOT] core[%x,%d] replicated kernel code at cycle %d\n",
-                        cxy , lid , boot_get_proctime() );
+            cxy , lid , boot_get_proctime() );
 
             // Get local boot_info_t structure base address.
@@ -917,4 +907,7 @@
             // Initialize local boot_info_t structure.
             boot_info_init( boot_info , cxy );
+
+            boot_printf("\n[BOOT] core[%x,%d] initialised boot_info at cycle %d\n",
+            cxy , lid , boot_get_proctime() );
 
             // Check core information.
