diff --git a/arch/sparc/cpu/leon3/cpu_init.c b/arch/sparc/cpu/leon3/cpu_init.c
index b0c7088..462b4a6 100644
--- a/arch/sparc/cpu/leon3/cpu_init.c
+++ b/arch/sparc/cpu/leon3/cpu_init.c
@@ -19,23 +19,12 @@

 DECLARE_GLOBAL_DATA_PTR;

-/* reset CPU (jump to 0, without reset) */
-void start(void);
-
 /* find & initialize the memory controller */
-int init_memory_ctrl(void);
+static int init_memory_ctrl(void);
+static int init_intr_ctrl(void);

-ambapp_dev_irqmp *irqmp = NULL;
-ambapp_dev_mctrl memctrl;
-ambapp_dev_gptimer *gptimer = NULL;
-unsigned int gptimer_irq = 0;
 int leon3_snooping_avail = 0; /* used by arch/sparc/cpu/leon3/usb_uhci.c */

-struct {
-       gd_t gd_area;
-       bd_t bd;
-} global_data;
-
 /* If CACHE snooping is available in hardware the result will be set
  * to 0x800000, otherwise 0.
  */
@@ -46,6 +35,12 @@ static unsigned int snoop_detect(void)
        return result & 0x00800000;
 }

+void cpu_panic(void)
+{
+       /* TODO: add some logic to print a warning on uart */
+       while (1) ;
+}
+
 /*
  * Breath some life into the CPU...
  *
@@ -60,9 +55,6 @@ static unsigned int snoop_detect(void)

 void cpu_init_f(void)
 {
-       /* these varaiable must not be initialized */
-       ambapp_dev_irqmp *irqmp;
-       ambapp_apbdev apbdev;
        register unsigned int apbmst;

        /* find AMBA APB Master */
@@ -73,33 +65,18 @@ void cpu_init_f(void)
                 * no AHB/APB bridge, something is wrong
                 * ==> jump to start (or hang)
                 */
-               while (1) ;
+               cpu_panic();
        }
+
        /* Init memory controller */
-       if (init_memory_ctrl()) {
-               while (1) ;
-       }
+       if (init_memory_ctrl())
+               cpu_panic();

        /****************************************************
         * From here we can use the main memory and the stack.
         */
-
-       /* Find AMBA APB IRQMP Controller */
-       if (ambapp_apb_first(VENDOR_GAISLER, GAISLER_IRQMP, &apbdev) != 1) {
-               /* no IRQ controller, something is wrong
-                * ==> jump to start (or hang)
-                */
-               while (1) ;
-       }
-       irqmp = (ambapp_dev_irqmp *) apbdev.address;
-
-       /* initialize the IRQMP */
-       irqmp->ilevel = 0xf;    /* all IRQ off */
-       irqmp->iforce = 0;
-       irqmp->ipend = 0;
-       irqmp->iclear = 0xfffe; /* clear all old pending interrupts */
-       irqmp->cpu_mask[0] = 0; /* mask all IRQs on CPU 0 */
-       irqmp->cpu_force[0] = 0;        /* no force IRQ on CPU 0 */
+       if (init_intr_ctrl())
+               cpu_panic();

        /* cache */
        leon3_snooping_avail = snoop_detect();
@@ -136,7 +113,6 @@ int cpu_init_r(void)
                return 1;
        }
        gptimer = (ambapp_dev_gptimer *) apbdev.address;
-       gptimer_irq = apbdev.irq;

        /* initialize prescaler common to all timers to 1MHz */
        gptimer->scalar = gptimer->scalar_reload =
@@ -148,19 +124,19 @@ int cpu_init_r(void)
 #endif

 /* find & setup memory controller */
-int init_memory_ctrl()
+static int init_memory_ctrl()
 {
-       register ambapp_dev_mctrl *mctrl;
-       register ambapp_dev_sdctrl *sdctrl;
-       register ambapp_dev_ddrspa *ddrspa;
-       register ambapp_dev_ddr2spa *ddr2spa;
        register ahbctrl_pp_dev *ahb;
        register unsigned int base;
        register int not_found_mctrl = -1;

+#if defined(CONFIG_SYS_GRLIB_MEMCFG1) && \
+    defined(CONFIG_SYS_GRLIB_MEMCFG2) && \
+    defined(CONFIG_SYS_GRLIB_MEMCFG3)
        /* find ESA Memory controller */
        base = ambapp_apb_next_nomem(VENDOR_ESA, ESA_MCTRL, 0);
        if (base) {
+               register ambapp_dev_mctrl *mctrl = (ambapp_dev_mctrl *) base;
                mctrl = (ambapp_dev_mctrl *) base;

                /* config MCTRL memory controller */
@@ -169,11 +145,15 @@ int init_memory_ctrl()
                mctrl->mcfg3 = CONFIG_SYS_GRLIB_MEMCFG3;
                not_found_mctrl = 0;
        }
+#endif

+#if defined(CONFIG_SYS_GRLIB_FT_MEMCFG1) && \
+    defined(CONFIG_SYS_GRLIB_FT_MEMCFG2) && \
+    defined(CONFIG_SYS_GRLIB_FT_MEMCFG3)
        /* find Gaisler Fault Tolerant Memory controller */
        base = ambapp_apb_next_nomem(VENDOR_GAISLER, GAISLER_FTMCTRL, 0);
        if (base) {
-               mctrl = (ambapp_dev_mctrl *) base;
+               register ambapp_dev_mctrl *mctrl = (ambapp_dev_mctrl *) base;

                /* config MCTRL memory controller */
                mctrl->mcfg1 = CONFIG_SYS_GRLIB_FT_MEMCFG1 | (mctrl->mcfg1 & 0x300);
@@ -181,40 +161,73 @@ int init_memory_ctrl()
                mctrl->mcfg3 = CONFIG_SYS_GRLIB_FT_MEMCFG3;
                not_found_mctrl = 0;
        }
+#endif

+#if defined(CONFIG_SYS_GRLIB_SDRAM)
        /* find SDRAM controller */
        base = ambapp_apb_next_nomem(VENDOR_GAISLER, GAISLER_SDCTRL, 0);
        if (base) {
-               sdctrl = (ambapp_dev_sdctrl *) base;
+               register ambapp_dev_sdctrl *sdctrl = (ambapp_dev_sdctrl *) base;

                /* config memory controller */
                sdctrl->sdcfg = CONFIG_SYS_GRLIB_SDRAM;
                not_found_mctrl = 0;
        }
+#endif

+#if defined(CONFIG_SYS_GRLIB_DDR2_CFG1) && \
+    defined(CONFIG_SYS_GRLIB_DDR2_CFG3)
        ahb = ambapp_ahb_next_nomem(VENDOR_GAISLER, GAISLER_DDR2SPA, 1, 0);
        if (ahb) {
-               ddr2spa = (ambapp_dev_ddr2spa *) ambapp_ahb_get_info(ahb, 1);
+               register ambapp_dev_ddr2spa *ddr2spa =
+                               (ambapp_dev_ddr2spa *) ambapp_ahb_get_info(ahb, 1);

                /* Config DDR2 memory controller */
                ddr2spa->cfg1 = CONFIG_SYS_GRLIB_DDR2_CFG1;
                ddr2spa->cfg3 = CONFIG_SYS_GRLIB_DDR2_CFG3;
                not_found_mctrl = 0;
        }
+#endif

+#if defined(CONFIG_SYS_GRLIB_DDR_CFG)
        ahb = ambapp_ahb_next_nomem(VENDOR_GAISLER, GAISLER_DDRSPA, 1, 0);
        if (ahb) {
-               ddrspa = (ambapp_dev_ddrspa *) ambapp_ahb_get_info(ahb, 1);
+               register ambapp_dev_ddrspa *ddrspa =
+                               (ambapp_dev_ddrspa *) ambapp_ahb_get_info(ahb, 1);

                /* Config DDR memory controller */
                ddrspa->ctrl = CONFIG_SYS_GRLIB_DDR_CFG;
                not_found_mctrl = 0;
        }
+#endif

        /* failed to find any memory controller */
        return not_found_mctrl;
 }

+static int init_intr_ctrl(void)
+{
+       ambapp_apbdev apbdev;
+       ambapp_dev_irqmp *irqmp;
+
+       /* look for AMBA APB IRQMP controller... */
+       if (ambapp_apb_first(VENDOR_GAISLER, GAISLER_IRQMP, &apbdev) != 1)
+               return -1; /* no IRQ controller */
+
+       /* found irqmp, let's init .. */
+       irqmp = (ambapp_dev_irqmp *) apbdev.address;
+
+       /* initialize the IRQMP */
+       irqmp->ilevel = 0xf;    /* all IRQ off */
+       irqmp->iforce = 0;
+       irqmp->ipend = 0;
+       irqmp->iclear = 0xfffe; /* clear all old pending interrupts */
+       irqmp->cpu_mask[0] = 0; /* mask all IRQs on CPU 0 */
+       irqmp->cpu_force[0] = 0;        /* no force IRQ on CPU 0 */
+
+       return 0;
+}
+
 #ifndef CONFIG_SYS_GENERIC_BOARD

 /* Uses Timer 0 to get accurate
@@ -278,6 +291,7 @@ static ambapp_dev_gptimer_element *tmr = NULL;

 int timer_init(void)
 {
+       ambapp_dev_gptimer *gptimer;
        ambapp_apbdev apbdev;

        if (ambapp_apb_first(VENDOR_GAISLER, GAISLER_GPTIMER, &apbdev) != 1) {
@@ -285,7 +299,6 @@ int timer_init(void)
                return 1;
        }
        gptimer = (ambapp_dev_gptimer *) apbdev.address;
-       gptimer_irq = apbdev.irq;

        /* initialize prescaler common to all timers to 1MHz */
        gptimer->scalar = gptimer->scalar_reload =
diff --git a/arch/sparc/cpu/leon3/interrupts.c b/arch/sparc/cpu/leon3/interrupts.c
index 20e295c..369fcb6 100644
--- a/arch/sparc/cpu/leon3/interrupts.c
+++ b/arch/sparc/cpu/leon3/interrupts.c
@@ -33,8 +33,10 @@ struct irq_action {
        unsigned int count;
 };

-extern ambapp_dev_irqmp *irqmp;
+ambapp_dev_irqmp *irqmp = NULL;
+#ifndef CONFIG_SYS_GENERIC_BOARD
 extern ambapp_dev_gptimer *gptimer;
+#endif

 static struct irq_action irq_handlers[NR_IRQS] = { {0}, };
 static int spurious_irq_cnt = 0;
