[U-Boot-Users] Little Endian Flash

Ed Okerson eokerson at texasconnect.net
Thu Mar 4 05:06:47 CET 2004


The attached patch fixes CFI flash writes for little endian systems.

Ed Okerson
-------------- next part --------------
*** cfi_flash.c.new	2004-02-23 15:54:51.000000000 -0800
--- cfi_flash.c	2004-03-03 13:08:15.610768328 -0800
***************
*** 724,741 ****
--- 724,765 ----
   */
  static void flash_add_byte (flash_info_t * info, cfiword_t * cword, uchar c)
  {
+ #if defined(__LITTLE_ENDIAN)
+ 	unsigned short	w;
+ 	unsigned int	l;
+ 	unsigned long long ll;
+ #endif
+ 
  	switch (info->portwidth) {
  	case FLASH_CFI_8BIT:
  		cword->c = c;
  		break;
  	case FLASH_CFI_16BIT:
+ #if defined(__LITTLE_ENDIAN)
+ 		w = c;
+ 		w <<= 8;
+ 		cword->w = (cword->w >> 8) | w;
+ #else
  		cword->w = (cword->w << 8) | c;
+ #endif
  		break;
  	case FLASH_CFI_32BIT:
+ #if defined(__LITTLE_ENDIAN)
+ 		l = c;
+ 		l <<= 24;
+ 		cword->l = (cword->l >> 8) | l;
+ #else
  		cword->l = (cword->l << 8) | c;
+ #endif
  		break;
  	case FLASH_CFI_64BIT:
+ #if defined(__LITTLE_ENDIAN)
+ 		ll = c;
+ 		ll <<= 56;
+ 		cword->ll = (cword->ll >> 8) | ll;
+ #else
  		cword->ll = (cword->ll << 8) | c;
+ #endif
  		break;
  	}
  }


More information about the U-Boot mailing list