]> www.infradead.org Git - users/rw/ppcboot.git/commitdiff
* Add status LED support for ICU862 board
authorwdenk <wdenk>
Sun, 11 Nov 2001 23:55:57 +0000 (23:55 +0000)
committerwdenk <wdenk>
Sun, 11 Nov 2001 23:55:57 +0000 (23:55 +0000)
  add PCMCIA / IDE support for ICU862 board

* Fix endianess bug in bmp_logo
  Patch by Erik Theisen, 7 Nov 2001

* Add appropriate error message for unaligned flash writes (CU824)

* Fix initialization sequence: must initialize PCI before "devices"
  on some boards

12 files changed:
CHANGELOG
common/board.c
common/cmd_ide.c
common/cmd_mem.c
common/cmd_pcmcia.c
common/flash.c
include/config_CU824.h
include/config_ICU862.h
include/pcmcia.h
include/status_led.h
include/version.h
tools/bmp_logo.c

index 1b21e087ef2e2cdab0300e585f3f1847524a2401..5e4c1b045c8a9ed3f69a9d384cee5c10bb485616 100644 (file)
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -52,6 +52,21 @@ To do:
 * "last user address" is set even if bootp is used without parameters
   (and it uses default address).
 
+======================================================================
+Modifications for 1.1.1:
+======================================================================
+
+* Add  status LED  support for ICU862 board
+  add PCMCIA / IDE support for ICU862 board
+
+* Fix endianess bug in bmp_logo
+  Patch by Erik Theisen, 7 Nov 2001
+
+* Add appropriate error message for unaligned flash writes (CU824)
+
+* Fix initialization sequence: must initialize PCI before "devices"
+  on some boards
+
 ======================================================================
 Modifications for 1.1.0:
 ======================================================================
index f9a6b0fbdb0f8bf0b907be85318eaf5597018b8d..c318b73011ed82b81092f499b3d1b273f9274363 100644 (file)
@@ -665,7 +665,14 @@ void    board_init_r  (bd_t *bd, ulong dest_addr)
     watchdog_reset ();
 #endif /* CONFIG_WATCHDOG */
 
-/** leave this here (after malloc() end environment are working) **/
+#ifdef CONFIG_PCI
+    /*
+     * Do pci configuration
+     */
+    pci_init(bd);
+#endif
+
+/** leave this here (after malloc(), environment and PCI are working) **/
     /* Initialize devices */
     devices_init (bd, reloc_off);
 
@@ -761,14 +768,6 @@ void    board_init_r  (bd_t *bd, ulong dest_addr)
     watchdog_reset ();
 #endif /* CONFIG_WATCHDOG */
 
-    /* Initialize other board modules */
-#ifdef CONFIG_PCI
-    /*
-     * Do pci configuration
-     */
-    pci_init(bd);
-#endif
-
 #if (CONFIG_COMMANDS & CFG_CMD_IDE)
 # if defined(CONFIG_WATCHDOG)
     watchdog_reset ();
index c04b8097d36bc91586d553de10779b57dc34c97f..1415ebf531bc64197bb86e0b0d0f7a85de593d5b 100644 (file)
@@ -533,6 +533,7 @@ void ide_init (bd_t *bd)
 #ifndef CONFIG_ATAPI /* ATAPI Devices do not set DRDY */
                } else  if ((c & ATA_STAT_READY) == 0) {
                        puts ("not available  ");
+                       PRINTF ("Status = 0x%02X ", c);
 #endif
                } else {
                        puts ("OK ");
index b5d206258b64941036d3086b90875549fa87b7ec..c6ab662a457a7dc3e2a355e1a0b62ba0b8a782fa 100644 (file)
@@ -312,6 +312,8 @@ int do_mem_cp    (cmd_tbl_t *cmdtp, bd_t *bd, int flag, int argc, char *argv[])
                        return 1;
                case 8: printf ("Outside available Flash\n");
                        return 1;
+               case 16:printf ("Size must be aligned (multiple of 8?)\n");
+                       return 1;
                default:
                        printf ("%s[%d] FIXME: rc=%d\n",__FILE__,__LINE__,rc);
                        return 1;
index 902d41b9e674b090f98c47826c3fdf4831654da4..e3be73b8983cbd7c01a11e255015258f7bab450b 100644 (file)
@@ -1050,6 +1050,275 @@ static int hardware_disable(int slot)
 #endif /* CFG_CMD_PCMCIA */
 #endif /* CONFIG_GTH */
 
+/* ---------------------------------------------------------------------------- */
+/* ICU862 Boards by Cambridge Broadband Ltd.                                   */
+/* ---------------------------------------------------------------------------- */
+
+#if defined(CONFIG_ICU862)
+
+#define PCMCIA_BOARD_MSG "ICU862"
+
+static void cfg_port_B (void);
+
+static int hardware_enable(int slot)
+{
+       volatile immap_t        *immap;
+       volatile cpm8xx_t       *cp;
+       volatile pcmconf8xx_t   *pcmp;
+       volatile sysconf8xx_t   *sysp;
+       uint reg, pipr, mask;
+       int i;
+
+       PCMCIA_DEBUG ("hardware_enable: " PCMCIA_BOARD_MSG " Slot %c\n", 'A'+slot);
+
+       udelay(10000);
+
+       immap = (immap_t *)CFG_IMMR;
+       sysp  = (sysconf8xx_t *)(&(((immap_t *)CFG_IMMR)->im_siu_conf));
+       pcmp  = (pcmconf8xx_t *)(&(((immap_t *)CFG_IMMR)->im_pcmcia));
+       cp    = (cpm8xx_t *)(&(((immap_t *)CFG_IMMR)->im_cpm));
+
+       /* Configure Port B for TPS2205 PC-Card Power-Interface Switch */
+       cfg_port_B ();
+
+       /*
+        * Configure SIUMCR to enable PCMCIA port B
+        * (VFLS[0:1] are not used for debugging, we connect FRZ# instead)
+        */
+       sysp->sc_siumcr &= ~SIUMCR_DBGC11;      /* set DBGC to 00 */
+
+       /* clear interrupt state, and disable interrupts */
+       pcmp->pcmc_pscr =  PCMCIA_MASK(_slot_);
+       pcmp->pcmc_per &= ~PCMCIA_MASK(_slot_);
+
+       /* disable interrupts & DMA */
+       PCMCIA_PGCRX(_slot_) = 0;
+
+       /*
+        * Disable PCMCIA buffers (isolate the interface)
+        * and assert RESET signal
+        */
+       PCMCIA_DEBUG ("Disable PCMCIA buffers and assert RESET\n");
+       reg  =  PCMCIA_PGCRX(_slot_);
+       reg |=  __MY_PCMCIA_GCRX_CXRESET;       /* active high */
+       reg |=  __MY_PCMCIA_GCRX_CXOE;          /* active low  */
+       PCMCIA_PGCRX(_slot_) = reg;
+       udelay(500);
+
+       /*
+        * Make sure there is a card in the slot, then configure the interface.
+        */
+       udelay(10000);
+       PCMCIA_DEBUG ("[%d] %s: PIPR(%p)=0x%x\n",
+               __LINE__,__FUNCTION__,
+               &(pcmp->pcmc_pipr),pcmp->pcmc_pipr);
+       if (pcmp->pcmc_pipr & 0x00001800) {
+               printf ("   No Card found\n");
+               return (1);
+       }
+
+       /*
+        * Power On: Set VAVCC to 3.3V or 5V, set VAVPP to Hi-Z
+        */
+       mask = PCMCIA_VS1(slot) | PCMCIA_VS2(slot);
+       pipr = pcmp->pcmc_pipr;
+       PCMCIA_DEBUG ("PIPR: 0x%x ==> VS1=o%s, VS2=o%s\n",
+               pipr,
+               (reg&PCMCIA_VS1(slot))?"n":"ff",
+               (reg&PCMCIA_VS2(slot))?"n":"ff");
+
+       reg  = cp->cp_pbdat;
+       if ((pipr & mask) == mask) {
+               reg |=  (TPS2205_VPP_PGM | TPS2205_VPP_VCC |    /* VAVPP => Hi-Z */
+                        TPS2205_VCC3);                         /* 3V off       */
+               reg &= ~(TPS2205_VCC5);                         /* 5V on        */
+               puts (" 5.0V card found: ");
+       } else {
+               reg |=  (TPS2205_VPP_PGM | TPS2205_VPP_VCC |    /* VAVPP => Hi-Z */
+                        TPS2205_VCC5);                         /* 5V off       */
+               reg &= ~(TPS2205_VCC3);                         /* 3V on        */
+               puts (" 3.3V card found: ");
+       }
+
+       PCMCIA_DEBUG ("\nPB DAT: %08x -> 3.3V %s 5.0V %s VPP_PGM %s VPP_VCC %s\n",
+               reg,
+               (reg & TPS2205_VCC3)    ? "off" : "on",
+               (reg & TPS2205_VCC5)    ? "off" : "on",
+               (reg & TPS2205_VPP_PGM) ? "off" : "on", 
+               (reg & TPS2205_VPP_VCC) ? "off" : "on" );
+
+       cp->cp_pbdat = reg;
+
+       /*  Wait 500 ms; use this to check for over-current */
+       for (i=0; i<5000; ++i) {
+               if ((cp->cp_pbdat & TPS2205_OC) == 0) {
+                       printf ("   *** Overcurrent - Safety shutdown ***\n");
+                       cp->cp_pbdat &= ~(TPS2205_SHDN);
+                       return (1);
+               }
+               udelay (100);
+       }
+
+       PCMCIA_DEBUG ("Enable PCMCIA buffers and stop RESET\n");
+       reg  =  PCMCIA_PGCRX(_slot_);
+       reg &= ~__MY_PCMCIA_GCRX_CXRESET;       /* active high */
+       reg &= ~__MY_PCMCIA_GCRX_CXOE;          /* active low  */
+       PCMCIA_PGCRX(_slot_) = reg;
+
+       udelay(250000); /* some cards need >150 ms to come up :-( */
+
+       PCMCIA_DEBUG ("# hardware_enable done\n");
+
+       return (0);
+}
+
+
+
+#if (CONFIG_COMMANDS & CFG_CMD_PCMCIA)
+static int hardware_disable(int slot)
+{
+       volatile immap_t        *immap;
+       volatile cpm8xx_t       *cp;
+       volatile pcmconf8xx_t   *pcmp;
+       u_long reg;
+
+       PCMCIA_DEBUG ("hardware_disable: " PCMCIA_BOARD_MSG " Slot %c\n", 'A'+slot);
+
+       immap = (immap_t *)CFG_IMMR;
+       cp    = (cpm8xx_t *)(&(((immap_t *)CFG_IMMR)->im_cpm));
+       pcmp  = (pcmconf8xx_t *)(&(((immap_t *)CFG_IMMR)->im_pcmcia));
+
+       /* Shut down */
+       cp->cp_pbdat &= ~(TPS2205_SHDN);
+
+       /* Configure PCMCIA General Control Register */
+       PCMCIA_PGCRX(_slot_) = 0;
+
+       PCMCIA_DEBUG ("Disable PCMCIA buffers and assert RESET\n");
+       reg  =  PCMCIA_PGCRX(_slot_);
+       reg |= __MY_PCMCIA_GCRX_CXRESET;        /* active high */
+       reg |= __MY_PCMCIA_GCRX_CXOE;           /* active low  */
+       PCMCIA_PGCRX(_slot_) = reg;
+
+       udelay(10000);
+
+       return (0);
+}
+#endif /* CFG_CMD_PCMCIA */
+
+
+
+static int voltage_set(int slot, int vcc, int vpp)
+{
+       volatile immap_t        *immap;
+       volatile cpm8xx_t       *cp;
+       volatile pcmconf8xx_t   *pcmp;
+       u_long reg;
+
+       PCMCIA_DEBUG ("voltage_set: "   \
+               PCMCIA_BOARD_MSG        \
+               " Slot %c, Vcc=%d.%d, Vpp=%d.%d\n",
+               'A'+slot, vcc/10, vcc%10, vpp/10, vcc%10);
+
+       immap = (immap_t *)CFG_IMMR;
+       cp    = (cpm8xx_t *)(&(((immap_t *)CFG_IMMR)->im_cpm));
+       pcmp  = (pcmconf8xx_t *)(&(((immap_t *)CFG_IMMR)->im_pcmcia));
+       /*
+        * Disable PCMCIA buffers (isolate the interface)
+        * and assert RESET signal
+        */
+       PCMCIA_DEBUG ("Disable PCMCIA buffers and assert RESET\n");
+       reg  =  PCMCIA_PGCRX(_slot_);
+       reg |=  __MY_PCMCIA_GCRX_CXRESET;       /* active high */
+       reg |=  __MY_PCMCIA_GCRX_CXOE;          /* active low  */
+       PCMCIA_PGCRX(_slot_) = reg;
+       udelay(500);
+
+       /*
+        * Configure Port C pins for
+        * 5 Volts Enable and 3 Volts enable,
+        * Turn all power pins to Hi-Z
+        */
+       PCMCIA_DEBUG ("PCMCIA power OFF\n");
+       cfg_port_B ();  /* Enables switch, but all in Hi-Z */
+
+       reg  = cp->cp_pbdat;
+
+       switch(vcc) {
+       case  0:                        break;  /* Switch off           */
+       case 33: reg &= ~TPS2205_VCC3;  break;  /* Switch on 3.3V       */
+       case 50: reg &= ~TPS2205_VCC5;  break;  /* Switch on 5.0V       */
+       default:                        goto done;
+       }
+
+       /* Checking supported voltages */
+
+       PCMCIA_DEBUG ("PIPR: 0x%x --> %s\n",
+               pcmp->pcmc_pipr,
+               (pcmp->pcmc_pipr & 0x00008000) ? "only 5 V" : "can do 3.3V");
+
+       cp->cp_pbdat = reg;
+
+#ifdef DEBUG
+    {
+       char *s;
+
+       if ((reg & TPS2205_VCC3) == 0) {
+               s = "at 3.3V";
+       } else if ((reg & TPS2205_VCC5) == 0) {
+               s = "at 5.0V";
+       } else {
+               s = "down";
+       }
+       printf ("PCMCIA powered %s\n", s);
+    }
+#endif
+
+done:
+       PCMCIA_DEBUG ("Enable PCMCIA buffers and stop RESET\n");
+       reg  =  PCMCIA_PGCRX(_slot_);
+       reg &= ~__MY_PCMCIA_GCRX_CXRESET;       /* active high */
+       reg &= ~__MY_PCMCIA_GCRX_CXOE;          /* active low  */
+       PCMCIA_PGCRX(_slot_) = reg;
+       udelay(500);
+
+       PCMCIA_DEBUG ("voltage_set: " PCMCIA_BOARD_MSG " Slot %c, DONE\n",
+               slot+'A');
+       return (0);
+}
+
+static void cfg_port_B (void)
+{
+       volatile immap_t        *immap;
+       volatile cpm8xx_t       *cp;
+       uint reg;
+
+       immap = (immap_t *)CFG_IMMR;
+       cp    = (cpm8xx_t *)(&(((immap_t *)CFG_IMMR)->im_cpm));
+
+       /*
+        * Configure Port B for TPS2205 PC-Card Power-Interface Switch
+        *
+        * Switch off all voltages, assert shutdown
+        */
+       reg  = cp->cp_pbdat;
+       reg |=  (TPS2205_VPP_PGM | TPS2205_VPP_VCC |    /* VAVPP => Hi-Z */
+                TPS2205_VCC3    | TPS2205_VCC5    |    /* VAVCC => Hi-Z */
+                TPS2205_SHDN);                         /* enable switch */
+       cp->cp_pbdat = reg;
+
+       cp->cp_pbpar &= ~(TPS2205_INPUTS | TPS2205_OUTPUTS);
+
+       reg = cp->cp_pbdir & ~(TPS2205_INPUTS);
+       cp->cp_pbdir = reg | TPS2205_OUTPUTS;
+
+       PCMCIA_DEBUG ("Set Port B: PAR: %08x DIR: %08x DAT: %08x\n",
+               cp->cp_pbpar, cp->cp_pbdir, cp->cp_pbdat);
+}
+
+#endif /* ICU862 */
+
+
 /* ---------------------------------------------------------------------------- */
 /* End of Board Specific Stuff                                                 */
 /* ---------------------------------------------------------------------------- */
index 6ff7305c037b5c3dea7545451b60fac44f3df1f7..d64356f6a6285b5cba39a48bdcb92eb418757c91 100644 (file)
@@ -33,7 +33,8 @@ extern flash_info_t  flash_info[CFG_MAX_FLASH_BANKS]; /* info for FLASH chips */
 /*-----------------------------------------------------------------------
  * Set protection status for monitor sectors
  *
- * The monitor always occupies the _first_ part of the _first_ Flash bank.
+ * The monitor is always located in the _first_ Flash bank.
+ * If necessary you have to map the second bank at lower addresses.
  */
 void
 flash_protect (int flag, ulong from, ulong to, flash_info_t *info)
index 1e8d8830faeb3656ffbc9bcc1ef3f5f4ee8f7a5f..7f02619136f705ce10cfa79e6e984645463abb8e 100644 (file)
@@ -72,7 +72,7 @@
  */
 #define CFG_PBSIZE     (CFG_CBSIZE + sizeof(CFG_PROMPT) + 16)
 
-#define CFG_MAXARGS    8               /* Max number of command args   */
+#define        CFG_MAXARGS     16              /* max number of command args   */
 #define CFG_BARGSIZE   CFG_CBSIZE      /* Boot Argument Buffer Size    */
 #define CFG_LOAD_ADDR  0x00100000      /* Default load address         */
 
index 33ea5a367b51b163c27044e1eae0c31369522938..2cd20b6a2bb989868b2447a296ac1a1132f43cd6 100644 (file)
@@ -74,6 +74,8 @@
 
 #undef CONFIG_WATCHDOG                 /* watchdog disabled            */
 
+#define        CONFIG_STATUS_LED       1       /* Status LED enabled           */
+
 #define CONFIG_BOOTP_MASK      (CONFIG_BOOTP_DEFAULT | CONFIG_BOOTP_BOOTFILESIZE)
 
 #undef CONFIG_SCC1_ENET                /* disable SCC1 ethernet */
 #undef CFG_DISCOVER_PHY
 #endif
 
+#define CONFIG_MAC_PARTITION
+#define CONFIG_DOS_PARTITION
+
+#define        CONFIG_RTC_MPC8xx               /* use internal RTC of MPC8xx   */
+
+#define CONFIG_COMMANDS              ( CONFIG_CMD_DFL  | \
+                               CFG_CMD_ASKENV  | \
+                               CFG_CMD_DHCP    | \
+                               CFG_CMD_IDE     | \
+                               CFG_CMD_DATE    )
+
 /* this must be included AFTER the definition of CONFIG_COMMANDS (if any) */
 #include <cmd_confdefs.h>
 
 /* +0x09C4 => DRQP = 10 (IDMA requests have lowest priority) */
 #define CFG_RCCR 0x0020
 
+/*-----------------------------------------------------------------------
+ * PCMCIA stuff
+ *-----------------------------------------------------------------------
+ */
+#define CFG_PCMCIA_MEM_ADDR    (0xE0000000)
+#define CFG_PCMCIA_MEM_SIZE    ( 64 << 20 )
+#define CFG_PCMCIA_DMA_ADDR    (0xE4000000)
+#define CFG_PCMCIA_DMA_SIZE    ( 64 << 20 )
+#define CFG_PCMCIA_ATTRB_ADDR  (0xE8000000)
+#define CFG_PCMCIA_ATTRB_SIZE  ( 64 << 20 )
+#define CFG_PCMCIA_IO_ADDR     (0xEC000000)
+#define CFG_PCMCIA_IO_SIZE     ( 64 << 20 )
+
+/*-----------------------------------------------------------------------
+ * PCMCIA Power Switch
+ *
+ * The ICU862 uses a TPS2205 PC-Card Power-Interface Switch to
+ * control the voltages on the PCMCIA slot which is connected to Port B
+ *-----------------------------------------------------------------------
+ */
+                       /* Output pins */
+#define TPS2205_VCC5   0x00008000      /* PB.16:  5V Voltage Control   */
+#define TPS2205_VCC3   0x00004000      /* PB.17:  3V Voltage Control   */
+#define TPS2205_VPP_PGM        0x00002000      /* PB.18: PGM Voltage Control   */
+#define TPS2205_VPP_VCC        0x00001000      /* PB.19: VPP Voltage Control   */
+#define TPS2205_SHDN   0x00000200      /* PB.22: Shutdown              */
+#define TPS2205_OUTPUTS ( TPS2205_VCC5    | TPS2205_VCC3    | \
+                         TPS2205_VPP_PGM | TPS2205_VPP_VCC | \
+                         TPS2205_SHDN)
+
+                       /* Input pins */
+#define TPS2205_OC     0x00000100      /* PB.23: Over-Current          */
+#define TPS2205_INPUTS ( TPS2205_OC )
+
+/*-----------------------------------------------------------------------
+ * IDE/ATA stuff (Supports IDE harddisk on PCMCIA Adapter)
+ *-----------------------------------------------------------------------
+ */
+
+#define        CONFIG_IDE_PCCARD       1       /* Use IDE with PC Card Adapter */
+
+#undef CONFIG_IDE_PCMCIA               /* Direct IDE    not supported  */
+#undef CONFIG_IDE_LED                  /* LED   for ide not supported  */
+#undef CONFIG_IDE_RESET                /* reset for ide not supported  */
+
+#define CFG_IDE_MAXBUS         1       /* max. 1 IDE bus               */
+#define CFG_IDE_MAXDEVICE      1       /* max. 1 drive per IDE bus     */
+
+#define CFG_ATA_IDE0_OFFSET    0x0000
+
+#define CFG_ATA_BASE_ADDR      CFG_PCMCIA_MEM_ADDR
+
+/* Offset for data I/O                 */
+#define CFG_ATA_DATA_OFFSET    (CFG_PCMCIA_MEM_SIZE + 0x320)
+
+/* Offset for normal register accesses */
+#define CFG_ATA_REG_OFFSET     (2 * CFG_PCMCIA_MEM_SIZE + 0x320)
+
+/* Offset for alternate registers      */
+#define CFG_ATA_ALT_OFFSET     0x0100
+
+
  /*-----------------------------------------------------------------------
  *
  *-----------------------------------------------------------------------
index 7798567d727efc1626649b30e24165327eba6337..719f769a3bd895c81947469c22063221f6bdf696 100644 (file)
@@ -57,6 +57,8 @@
 # define CONFIG_PCMCIA_SLOT_A
 #elif defined(CONFIG_LWMON)            /* The LWMON use SLOT_B         */
 # define CONFIG_PCMCIA_SLOT_B
+#elif defined(CONFIG_ICU862)           /* The ICU862 use SLOT_B        */
+# define CONFIG_PCMCIA_SLOT_B
 #else
 # error "PCMCIA Slot not configured"
 #endif
index f56507de4da18338cf9a954cb2ed97e8c1c63eff..1211d0d91bc8d225f6ff5709f61ec20f7516e05d 100644 (file)
@@ -174,6 +174,25 @@ void status_led_set  (int led, int state);
 
 # define STATUS_LED_BOOT       0               /* LED 0 used for boot status */
 
+/*****  ICU862   ********************************************************/
+#elif defined(CONFIG_ICU862)
+
+# define STATUS_LED_PAR                im_ioport.iop_papar
+# define STATUS_LED_DIR                im_ioport.iop_padir
+# define STATUS_LED_ODR                im_ioport.iop_paodr
+# define STATUS_LED_DAT                im_ioport.iop_padat
+
+# define STATUS_LED_BIT                0x4000          /* LED 0 is on PA.1 */
+# define STATUS_LED_PERIOD     (CFG_HZ / 2)
+# define STATUS_LED_STATE      STATUS_LED_BLINKING
+# define STATUS_LED_BIT1       0x1000          /* LED 1 is on PA.3 */
+# define STATUS_LED_PERIOD1    (CFG_HZ)
+# define STATUS_LED_STATE1     STATUS_LED_OFF
+
+# define STATUS_LED_ACTIVE     1               /* LED on for bit == 1  */
+
+# define STATUS_LED_BOOT       0               /* LED 0 used for boot status */
+
 /************************************************************************/
 #else
 # error Status LED configuration missing
index 77b56a8b093aed277a1fcd5e0956062ec459cbe1..6b0f5759452a4e3e2f6f679b51ac0a674a9516fe 100644 (file)
@@ -24,6 +24,6 @@
 #ifndef        __VERSION_H__
 #define        __VERSION_H__
 
-#define        PPCBOOT_VERSION "PPCBoot 1.1.0"
+#define        PPCBOOT_VERSION "PPCBoot 1.1.1"
 
 #endif /* __VERSION_H__ */
index 9ded4b0bfdf43c9ed16b3354730cfe57932feaea..2039522511fed6c6cd8f8c5d1ac6eced4c67552c 100755 (executable)
@@ -12,6 +12,20 @@ typedef struct bitmap_s {            /* bitmap description */
 
 #define DEFAULT_CMAP_SIZE      16      /* size of default color map    */
 
+/*
+ * Neutralize little endians.
+ */
+ushort le_short(ushort x)
+{
+    ushort val;
+    uchar *p = (uchar *)(&x);
+    
+    val =  (*p++ & 0xff) << 0;
+    val |= (*p & 0xff) << 8;
+    
+    return val;
+}
+
 void skip_bytes (FILE *fp, int n)
 {
        while (n-- > 0)
@@ -53,6 +67,13 @@ int main (int argc, char *argv[])
        fread (&n_colors, sizeof (ushort), 1, fp);
        skip_bytes (fp, 6);
 
+       /*
+        * Repair endianess.
+        */
+       b->width = le_short(b->width);
+       b->height = le_short(b->height);
+       n_colors = le_short(n_colors);
+       
        /* assume we are working with an 8-bit file */
        if ((n_colors == 0) || (n_colors > 256 - DEFAULT_CMAP_SIZE)) {
                /* reserve DEFAULT_CMAP_SIZE color map entries for default map */