[coreboot-gerrit] New patch to review for filo: 2b9f22a Always use endianness functions from libpayload

Nico Huber (nico.huber@secunet.com) gerrit at coreboot.org
Sun May 26 15:20:18 CEST 2013


Nico Huber (nico.huber at secunet.com) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/3298

-gerrit

commit 2b9f22aabdb93fed51f5d368bae26f9515f3f75d
Author: Nico Huber <nico.huber at secunet.com>
Date:   Sun May 26 14:55:44 2013 +0200

    Always use endianness functions from libpayload
    
    We have endianness functions in libpayload (in <endian.h>) now. Those
    make the filo versions of them obsolete. So always use libpayload's.
    
    Change-Id: I41829c2128b355ccb5096d88df8b669b4e920dfc
    Signed-off-by: Nico Huber <nico.huber at secunet.com>
---
 drivers/ide_new.c            |  21 ++++----
 drivers/ide_new.h            |   5 --
 fs/blockdev.c                |  13 ++---
 fs/eltorito.c                |   7 +--
 fs/fsys_cbfs.c               |   4 +-
 fs/fsys_ext2fs.c             | 125 ++++++++++++++++++++++---------------------
 fs/fsys_reiserfs.c           |   8 ---
 fs/squashfs_fs.h             |   2 -
 include/fs.h                 |   1 -
 main/grub/md5.c              |  16 +++---
 x86/include/arch/byteorder.h |  64 ----------------------
 11 files changed, 94 insertions(+), 172 deletions(-)

diff --git a/drivers/ide_new.c b/drivers/ide_new.c
index cc1fb83..2e0965a 100644
--- a/drivers/ide_new.c
+++ b/drivers/ide_new.c
@@ -17,7 +17,6 @@
 
 #include <libpayload.h>
 #include <config.h>
-#include <arch/byteorder.h>
 
 #include <fs.h>
 #include "ide_new.h"
@@ -676,8 +675,8 @@ ob_ide_atapi_drive_ready(struct ide_drive *drive)
 		return 1;
 	}
 
-	drive->sectors = __be32_to_cpu(cap.lba) + 1;
-	drive->bs = __be32_to_cpu(cap.block_size);
+	drive->sectors = be32toh(cap.lba) + 1;
+	drive->bs = be32toh(cap.block_size);
 	return 0;
 }
 
@@ -864,7 +863,7 @@ ob_ide_fixup_string(unsigned char *s, unsigned int len)
 #ifdef CONFIG_LITTLE_ENDIAN
 	for (p = end ; p != s;) {
 		unsigned short *pp = (unsigned short *) (p -= 2);
-		*pp = __be16_to_cpu(*pp);
+		*pp = be16toh(*pp);
 	}
 #endif
 
@@ -884,13 +883,13 @@ static int
 ob_ide_fixup_id(struct hd_driveid *id)
 {
 	ob_ide_fixup_string(id->model, 40);
-	id->config = __le16_to_cpu(id->config);
-	id->lba_capacity = __le32_to_cpu(id->lba_capacity);
-	id->cyls = __le16_to_cpu(id->cyls);
-	id->heads = __le16_to_cpu(id->heads);
-	id->sectors = __le16_to_cpu(id->sectors);
-	id->command_set_2 = __le16_to_cpu(id->command_set_2);
-	id->cfs_enable_2 = __le16_to_cpu(id->cfs_enable_2);
+	id->config = le16toh(id->config);
+	id->lba_capacity = le32toh(id->lba_capacity);
+	id->cyls = le16toh(id->cyls);
+	id->heads = le16toh(id->heads);
+	id->sectors = le16toh(id->sectors);
+	id->command_set_2 = le16toh(id->command_set_2);
+	id->cfs_enable_2 = le16toh(id->cfs_enable_2);
 
 	return 0;
 }
diff --git a/drivers/ide_new.h b/drivers/ide_new.h
index 742cc42..1956625 100644
--- a/drivers/ide_new.h
+++ b/drivers/ide_new.h
@@ -233,9 +233,4 @@ int ob_ide_init(int driveno);
 #define CONFIG_LITTLE_ENDIAN
 #define CONFIG_IDE_LBA48
 
-#define __be32_to_cpu be32_to_cpu
-#define __be16_to_cpu be16_to_cpu
-#define __le32_to_cpu le32_to_cpu
-#define __le16_to_cpu le16_to_cpu
-
 #endif
diff --git a/fs/blockdev.c b/fs/blockdev.c
index 7dd6c2e..0105712 100644
--- a/fs/blockdev.c
+++ b/fs/blockdev.c
@@ -18,6 +18,7 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
  */
 
+#include <endian.h>
 #include <libpayload.h>
 #include <libpayload-config.h>
 #if defined(CONFIG_LIBPAYLOAD_STORAGE) && defined(CONFIG_STORAGE)
@@ -88,8 +89,8 @@ static int open_pc_partition(int part, unsigned long *start_p,
 			printf("Partition %d does not exist.\n", part + 1);
 			return 0;
 		}
-		*start_p = cpu_to_le32(*(u32 *) (p->start_sect));
-		*length_p = cpu_to_le32(*(u32 *) (p->nr_sects));
+		*start_p = htole32(*(u32 *) (p->start_sect));
+		*length_p = htole32(*(u32 *) (p->nr_sects));
 		return 1;
 	} else {
 		/* Extended partition */
@@ -108,7 +109,7 @@ static int open_pc_partition(int part, unsigned long *start_p,
 		}
 		debug("Extended partition at %d.\n", i + 1);
 		/* Visit each logical partition labels */
-		ext_start = cpu_to_le32(*(u32 *) (p[i].start_sect));
+		ext_start = htole32(*(u32 *) (p[i].start_sect));
 		cur_table = ext_start;
 		cur_part = 4;
 		for (;;) {
@@ -127,8 +128,8 @@ static int open_pc_partition(int part, unsigned long *start_p,
 					printf("Partition %d is empty.\n", part + 1);
 					return 0;
 				}
-				*start_p = cur_table + cpu_to_le32(*(u32 *) (p->start_sect));
-				*length_p = cpu_to_le32(*(u32 *) (p->nr_sects));
+				*start_p = cur_table + htole32(*(u32 *) (p->start_sect));
+				*length_p = htole32(*(u32 *) (p->nr_sects));
 				return 1;
 			}
 			/* Second entry is link to next partition */
@@ -136,7 +137,7 @@ static int open_pc_partition(int part, unsigned long *start_p,
 				debug("no link\n");
 				break;
 			}
-			cur_table = ext_start + cpu_to_le32(*(u32 *) (p[1].start_sect));
+			cur_table = ext_start + htole32(*(u32 *) (p[1].start_sect));
 
 			cur_part++;
 		}
diff --git a/fs/eltorito.c b/fs/eltorito.c
index 82d14d5..4a6d0b0 100644
--- a/fs/eltorito.c
+++ b/fs/eltorito.c
@@ -15,6 +15,7 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
  */
 
+#include <endian.h>
 #include <libpayload.h>
 #include <config.h>
 #include <fs.h>
@@ -100,7 +101,7 @@ int open_eltorito_image(int part, unsigned long *offset_p,
 	return 0;
     }
 
-    cat_offset = le32_to_cpu(*(u32*)boot_record.catalog_offset);
+    cat_offset = le32toh(*(u32*)boot_record.catalog_offset);
     debug("El-Torito boot catalog at sector %u\n", cat_offset);
     if (!devread(cat_offset<<2, 0, 2048, catalog))
 	return 0;
@@ -115,7 +116,7 @@ int open_eltorito_image(int part, unsigned long *offset_p,
     /* All words must sum up to zero */
     sum = 0;
     for (i = 0; i < sizeof(*ve); i += 2)
-	sum += le16_to_cpu(catalog[i]);
+	sum += le16toh(catalog[i]);
     sum &= 0xffff;
     if (sum != 0) {
 	printf("El Torito boot catalog verify failed\n");
@@ -153,7 +154,7 @@ int open_eltorito_image(int part, unsigned long *offset_p,
 	printf("Disc uses hard disk emulation - not supported\n");
 	return 0;
     }
-    *offset_p = le32_to_cpu(*(u32*)(de->start_sector)) << 2;
+    *offset_p = le32toh(*(u32*)(de->start_sector)) << 2;
     debug("offset=%#lx length=%#lx\n", *offset_p, *length_p);
 
     return 1;
diff --git a/fs/fsys_cbfs.c b/fs/fsys_cbfs.c
index 5c389e9..fef3090 100644
--- a/fs/fsys_cbfs.c
+++ b/fs/fsys_cbfs.c
@@ -59,8 +59,8 @@ cbfs_dir (char *dirname)
   }
 
   filepos = 0;
-  filemax = ntohl(file->len);
-  fileptr = (void*)file+ntohl(file->offset);
+  filemax = be32toh(file->len);
+  fileptr = (void*)file+be32toh(file->offset);
   return 1;
 }
 
diff --git a/fs/fsys_ext2fs.c b/fs/fsys_ext2fs.c
index 987dceb..51b3faf 100644
--- a/fs/fsys_ext2fs.c
+++ b/fs/fsys_ext2fs.c
@@ -17,6 +17,7 @@
  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
 
+#include <endian.h>
 #include "filesys.h"
 
 static int mapblock1, mapblock2;
@@ -364,7 +365,7 @@ struct ext4_extent_header
 #define EXT2_INODES_PER_BLOCK(s)       (EXT2_BLOCK_SIZE(s)/EXT2_INODE_SIZE(s))
 
 /* linux/ext2_fs.h */
-#define EXT2_BLOCK_SIZE_BITS(s)        (le32_to_cpu((s)->s_log_block_size) + 10)
+#define EXT2_BLOCK_SIZE_BITS(s)        (le32toh((s)->s_log_block_size) + 10)
 /* kind of from ext2/super.c */
 #define EXT2_BLOCK_SIZE(s)	(1 << EXT2_BLOCK_SIZE_BITS(s))
 /* linux/ext2fs.h */
@@ -393,47 +394,47 @@ void
 dump_super(struct ext2_super_block *s)
 {
     printf(" superblock 0x%p:\n", s);
-    printf("  inodes=%d\n", le32_to_cpu(s->s_inodes_count));
-    printf("  blocks=%d\n", le32_to_cpu(s->s_blocks_count));
-    printf("  reserved=%d\n", le32_to_cpu(s->s_r_blocks_count));
-    printf("  i_free=%d\n", le32_to_cpu(s->s_free_inodes_count));
-    printf("  b_free=%d\n", le32_to_cpu(s->s_free_blocks_count));
-    printf("  first=%d\n", le32_to_cpu(s->s_first_data_block));
-    printf("  log_b_size=%d, b_size=%d\n", le32_to_cpu(s->s_log_block_size), EXT2_BLOCK_SIZE(s));
-    printf("  inode_size=%d\n", le32_to_cpu(EXT2_INODE_SIZE(s)));
-    printf("  (obsoleted) log_f_size=%d\n", le32_to_cpu(s->s_obso_log_frag_size));
-    printf("  bpg=%d\n", le32_to_cpu(s->s_blocks_per_group));
-    printf("  (obsoleted) fpg=%d\n", le32_to_cpu(s->s_obso_frags_per_group));
-    printf("  ipg=%d\n", le32_to_cpu(s->s_inodes_per_group));
+    printf("  inodes=%d\n", le32toh(s->s_inodes_count));
+    printf("  blocks=%d\n", le32toh(s->s_blocks_count));
+    printf("  reserved=%d\n", le32toh(s->s_r_blocks_count));
+    printf("  i_free=%d\n", le32toh(s->s_free_inodes_count));
+    printf("  b_free=%d\n", le32toh(s->s_free_blocks_count));
+    printf("  first=%d\n", le32toh(s->s_first_data_block));
+    printf("  log_b_size=%d, b_size=%d\n", le32toh(s->s_log_block_size), EXT2_BLOCK_SIZE(s));
+    printf("  inode_size=%d\n", le32toh(EXT2_INODE_SIZE(s)));
+    printf("  (obsoleted) log_f_size=%d\n", le32toh(s->s_obso_log_frag_size));
+    printf("  bpg=%d\n", le32toh(s->s_blocks_per_group));
+    printf("  (obsoleted) fpg=%d\n", le32toh(s->s_obso_frags_per_group));
+    printf("  ipg=%d\n", le32toh(s->s_inodes_per_group));
 }
 
 void
 dump_group_desc(struct ext4_group_desc *g)
 {
     printf(" group_desc 0x%p:\n", g);
-    printf("  b_bmap block=%d\n", le32_to_cpu(g->bg_block_bitmap));
-    printf("  i_bmap block=%d\n", le32_to_cpu(g->bg_inode_bitmap));
-    printf("  i_tab block=%d\n", le32_to_cpu(g->bg_inode_table));
-    printf("  free_blks=%d\n", le16_to_cpu(g->bg_free_blocks_count));
-    printf("  free_inodes=%d\n", le16_to_cpu(g->bg_free_inodes_count));
-    printf("  used_dirs=%d\n", le16_to_cpu(g->bg_used_dirs_count));
+    printf("  b_bmap block=%d\n", le32toh(g->bg_block_bitmap));
+    printf("  i_bmap block=%d\n", le32toh(g->bg_inode_bitmap));
+    printf("  i_tab block=%d\n", le32toh(g->bg_inode_table));
+    printf("  free_blks=%d\n", le16toh(g->bg_free_blocks_count));
+    printf("  free_inodes=%d\n", le16toh(g->bg_free_inodes_count));
+    printf("  used_dirs=%d\n", le16toh(g->bg_used_dirs_count));
 }
 
 void
 dump_inode(struct ext2_inode *i)
 {
     printf(" inode 0x%p:\n", i);
-    printf("  mode=%o\n", le16_to_cpu(i->i_mode));
-    printf("  uid=%d\n", le16_to_cpu(i->i_uid));
-    printf("  gid=%d\n", le16_to_cpu(i->i_gid));
-    printf("  size=%d\n", le32_to_cpu(i->i_size));
-    printf("  atime=%d\n", le32_to_cpu(i->i_atime));
-    printf("  ctime=%d\n", le32_to_cpu(i->i_ctime));
-    printf("  mtime=%d\n", le32_to_cpu(i->i_mtime));
-    printf("  dtime=%d\n", le32_to_cpu(i->i_dtime));
-    printf("  links=%d\n", le16_to_cpu(i->i_links_count));
-    printf("  blocks=%d\n", le32_to_cpu(i->i_blocks));
-    printf("  flags=%d\n", le32_to_cpu(i->i_flags));
+    printf("  mode=%o\n", le16toh(i->i_mode));
+    printf("  uid=%d\n", le16toh(i->i_uid));
+    printf("  gid=%d\n", le16toh(i->i_gid));
+    printf("  size=%d\n", le32toh(i->i_size));
+    printf("  atime=%d\n", le32toh(i->i_atime));
+    printf("  ctime=%d\n", le32toh(i->i_ctime));
+    printf("  mtime=%d\n", le32toh(i->i_mtime));
+    printf("  dtime=%d\n", le32toh(i->i_dtime));
+    printf("  links=%d\n", le16toh(i->i_links_count));
+    printf("  blocks=%d\n", le32toh(i->i_blocks));
+    printf("  flags=%d\n", le32toh(i->i_flags));
 }
 
 void 
@@ -473,7 +474,7 @@ ext2fs_mount (void)
       || part_length < (SBLOCK + (sizeof (struct ext2_super_block) / DEV_BSIZE))
       || !devread (SBLOCK, 0, sizeof (struct ext2_super_block),
 		   (char *) SUPERBLOCK)
-      || le16_to_cpu(SUPERBLOCK->s_magic) != EXT2_SUPER_MAGIC)
+      || le16toh(SUPERBLOCK->s_magic) != EXT2_SUPER_MAGIC)
       retval = 0;
 
   return retval;
@@ -509,9 +510,9 @@ ext2fs_block_map (int logical_block)
   if (logical_block < EXT2_NDIR_BLOCKS)
     {
 #ifdef E2DEBUG
-      printf ("ext2fs_block_map: returning %d\n", le32_to_cpu(INODE->i_block[logical_block]));
+      printf ("ext2fs_block_map: returning %d\n", le32toh(INODE->i_block[logical_block]));
 #endif /* E2DEBUG */
-      return le32_to_cpu(INODE->i_block[logical_block]);
+      return le32toh(INODE->i_block[logical_block]);
     }
   /* else */
   logical_block -= EXT2_NDIR_BLOCKS;
@@ -519,13 +520,13 @@ ext2fs_block_map (int logical_block)
   if (logical_block < EXT2_ADDR_PER_BLOCK (SUPERBLOCK))
     {
       if (mapblock1 != 1
-	  && !ext2_rdfsb (le32_to_cpu(INODE->i_block[EXT2_IND_BLOCK]), DATABLOCK1))
+	  && !ext2_rdfsb (le32toh(INODE->i_block[EXT2_IND_BLOCK]), DATABLOCK1))
 	{
 	  errnum = ERR_FSYS_CORRUPT;
 	  return -1;
 	}
       mapblock1 = 1;
-      return le32_to_cpu(((__u32 *) DATABLOCK1)[logical_block]);
+      return le32toh(((__u32 *) DATABLOCK1)[logical_block]);
     }
   /* else */
   logical_block -= EXT2_ADDR_PER_BLOCK (SUPERBLOCK);
@@ -534,13 +535,13 @@ ext2fs_block_map (int logical_block)
     {
       int bnum;
       if (mapblock1 != 2
-	  && !ext2_rdfsb (le32_to_cpu(INODE->i_block[EXT2_DIND_BLOCK]), DATABLOCK1))
+	  && !ext2_rdfsb (le32toh(INODE->i_block[EXT2_DIND_BLOCK]), DATABLOCK1))
 	{
 	  errnum = ERR_FSYS_CORRUPT;
 	  return -1;
 	}
       mapblock1 = 2;
-      if ((bnum = le32_to_cpu(((__u32 *) DATABLOCK1)
+      if ((bnum = le32toh(((__u32 *) DATABLOCK1)
 		   [logical_block >> EXT2_ADDR_PER_BLOCK_BITS (SUPERBLOCK)]))
 	  != mapblock2
 	  && !ext2_rdfsb (bnum, DATABLOCK2))
@@ -549,20 +550,20 @@ ext2fs_block_map (int logical_block)
 	  return -1;
 	}
       mapblock2 = bnum;
-      return le32_to_cpu(((__u32 *) DATABLOCK2)
+      return le32toh(((__u32 *) DATABLOCK2)
 	[logical_block & (EXT2_ADDR_PER_BLOCK (SUPERBLOCK) - 1)]);
     }
   /* else */
   mapblock2 = -1;
   logical_block -= (1 << (EXT2_ADDR_PER_BLOCK_BITS (SUPERBLOCK) * 2));
   if (mapblock1 != 3
-      && !ext2_rdfsb (le32_to_cpu(INODE->i_block[EXT2_TIND_BLOCK]), DATABLOCK1))
+      && !ext2_rdfsb (le32toh(INODE->i_block[EXT2_TIND_BLOCK]), DATABLOCK1))
     {
       errnum = ERR_FSYS_CORRUPT;
       return -1;
     }
   mapblock1 = 3;
-  if (!ext2_rdfsb (le32_to_cpu(((__u32 *) DATABLOCK1)
+  if (!ext2_rdfsb (le32toh(((__u32 *) DATABLOCK1)
 		   [logical_block >> (EXT2_ADDR_PER_BLOCK_BITS (SUPERBLOCK)
 				      * 2)]),
 		   DATABLOCK2))
@@ -570,7 +571,7 @@ ext2fs_block_map (int logical_block)
       errnum = ERR_FSYS_CORRUPT;
       return -1;
     }
-  if (!ext2_rdfsb (le32_to_cpu(((__u32 *) DATABLOCK2)
+  if (!ext2_rdfsb (le32toh(((__u32 *) DATABLOCK2)
 		   [(logical_block >> EXT2_ADDR_PER_BLOCK_BITS (SUPERBLOCK))
 		    & (EXT2_ADDR_PER_BLOCK (SUPERBLOCK) - 1)]),
 		   DATABLOCK2))
@@ -578,7 +579,7 @@ ext2fs_block_map (int logical_block)
       errnum = ERR_FSYS_CORRUPT;
       return -1;
     }
-  return le32_to_cpu(((__u32 *) DATABLOCK2)
+  return le32toh(((__u32 *) DATABLOCK2)
     [logical_block & (EXT2_ADDR_PER_BLOCK (SUPERBLOCK) - 1)]);
 }
 
@@ -786,8 +787,8 @@ static inline
 int ext2_is_fast_symlink (void)
 {
   int ea_blocks;
-  ea_blocks = le32_to_cpu(INODE->i_file_acl) ? EXT2_BLOCK_SIZE (SUPERBLOCK) / DEV_BSIZE : 0;
-  return le32_to_cpu(INODE->i_blocks) == ea_blocks;
+  ea_blocks = le32toh(INODE->i_file_acl) ? EXT2_BLOCK_SIZE (SUPERBLOCK) / DEV_BSIZE : 0;
+  return le32toh(INODE->i_blocks) == ea_blocks;
 }
 
 /* preconditions: ext2fs_mount already executed, therefore supblk in buffer
@@ -841,16 +842,16 @@ ext2fs_dir (char *dirname)
 #endif /* E2DEBUG */
 
       /* look up an inode */
-      group_id = (current_ino - 1) / le32_to_cpu(SUPERBLOCK->s_inodes_per_group);
+      group_id = (current_ino - 1) / le32toh(SUPERBLOCK->s_inodes_per_group);
       group_desc = group_id >> log2 (EXT2_DESC_PER_BLOCK (SUPERBLOCK));
       desc = group_id & (EXT2_DESC_PER_BLOCK (SUPERBLOCK) - 1);
 #ifdef E2DEBUG
-      printf ("ext2fs_dir: ipg=%d, dpb=%d\n", le32_to_cpu(SUPERBLOCK->s_inodes_per_group),
+      printf ("ext2fs_dir: ipg=%d, dpb=%d\n", le32toh(SUPERBLOCK->s_inodes_per_group),
 	      EXT2_DESC_PER_BLOCK (SUPERBLOCK));
       printf ("ext2fs_dir: group_id=%d group_desc=%d desc=%d\n", group_id, group_desc, desc);
 #endif /* E2DEBUG */
       if (!ext2_rdfsb (
-			(WHICH_SUPER + group_desc + le32_to_cpu(SUPERBLOCK->s_first_data_block)),
+			(WHICH_SUPER + group_desc + le32toh(SUPERBLOCK->s_first_data_block)),
 			(char*) GROUP_DESC))
 	{
 	  return 0;
@@ -869,12 +870,12 @@ ext2fs_dir (char *dirname)
 	  return -1;
         }
       ino_blk = ext4_gdp->bg_inode_table + 
-	(((current_ino - 1) % le32_to_cpu(SUPERBLOCK->s_inodes_per_group))
+	(((current_ino - 1) % le32toh(SUPERBLOCK->s_inodes_per_group))
 	 >> log2 (EXT2_INODES_PER_BLOCK (SUPERBLOCK)));
 #ifdef E2DEBUG
       printf ("ext2fs_dir: itab_blk=%d, i_in_grp=%d, log2=%lu\n",
-	 le32_to_cpu(ext4_gdp[desc].bg_inode_table),
-	 ((current_ino - 1) % le32_to_cpu(SUPERBLOCK->s_inodes_per_group)),
+	 le32toh(ext4_gdp[desc].bg_inode_table),
+	 ((current_ino - 1) % le32toh(SUPERBLOCK->s_inodes_per_group)),
 	 log2 (EXT2_INODES_PER_BLOCK (SUPERBLOCK)));
       printf ("ext2fs_dir: inode table fsblock=%d\n", ino_blk);
 #endif /* E2DEBUG */
@@ -909,7 +910,7 @@ ext2fs_dir (char *dirname)
 #endif /* E2DEBUG */
 
       /* If we've got a symbolic link, then chase it. */
-      if (S_ISLNK (le16_to_cpu(INODE->i_mode)))
+      if (S_ISLNK (le16toh(INODE->i_mode)))
 	{
 	  int len;
 	  if (++link_count > MAX_LINK_COUNT)
@@ -924,7 +925,7 @@ ext2fs_dir (char *dirname)
 	    len++;
 
 	  /* Get the symlink size. */
-	  filemax = le32_to_cpu(INODE->i_size);
+	  filemax = le32toh(INODE->i_size);
 	  if (filemax + len > sizeof (linkbuf) - 2)
 	    {
 	      errnum = ERR_FILELENGTH;
@@ -984,7 +985,7 @@ ext2fs_dir (char *dirname)
       /* if end of filename, INODE points to the file's inode */
       if (!*dirname || isspace (*dirname))
 	{
-	  if (!S_ISREG (le16_to_cpu(INODE->i_mode)))
+	  if (!S_ISREG (le16toh(INODE->i_mode)))
 	    {
 	      errnum = ERR_BAD_FILETYPE;
 	      return 0;
@@ -997,7 +998,7 @@ ext2fs_dir (char *dirname)
 		  return 0;
 	    }
 
-	  filemax = le32_to_cpu(INODE->i_size);
+	  filemax = le32toh(INODE->i_size);
 	  return 1;
 	}
 
@@ -1009,7 +1010,7 @@ ext2fs_dir (char *dirname)
 	dirname++;
 
       /* if this isn't a directory of sufficient size to hold our file, abort */
-      if (!(le32_to_cpu(INODE->i_size)) || !S_ISDIR (le16_to_cpu(INODE->i_mode)))
+      if (!(le32toh(INODE->i_size)) || !S_ISDIR (le16toh(INODE->i_mode)))
 	{
 	  errnum = ERR_BAD_FILETYPE;
 	  return 0;
@@ -1033,7 +1034,7 @@ ext2fs_dir (char *dirname)
 
 	  /* if our location/byte offset into the directory exceeds the size,
 	     give up */
-	  if (loc >= le32_to_cpu(INODE->i_size))
+	  if (loc >= le32toh(INODE->i_size))
 	    {
 	      if (print_possibilities < 0)
 		{
@@ -1080,17 +1081,17 @@ ext2fs_dir (char *dirname)
 	  off = loc & (EXT2_BLOCK_SIZE (SUPERBLOCK) - 1);
 	  dp = (struct ext2_dir_entry *) (DATABLOCK2 + off);
 	  /* advance loc prematurely to next on-disk directory entry  */
-	  loc += le16_to_cpu(dp->rec_len);
+	  loc += le16toh(dp->rec_len);
 
 	  /* NOTE: ext2fs filenames are NOT null-terminated */
 
 #ifdef E2DEBUG
-	  printf ("ext2fs_dir: directory entry ino=%d\n", le32_to_cpu(dp->inode));
-	  if (le32_to_cpu(dp->inode))
+	  printf ("ext2fs_dir: directory entry ino=%d\n", le32toh(dp->inode));
+	  if (le32toh(dp->inode))
 	    printf ("entry=%s\n", dp->name);
 #endif /* E2DEBUG */
 
-	  if (le32_to_cpu(dp->inode))
+	  if (le32toh(dp->inode))
 	    {
 	      int saved_c = dp->name[dp->name_len];
 
@@ -1111,9 +1112,9 @@ ext2fs_dir (char *dirname)
 	    }
 
 	}
-      while (!le32_to_cpu(dp->inode) || (str_chk || (print_possibilities && ch != '/')));
+      while (!le32toh(dp->inode) || (str_chk || (print_possibilities && ch != '/')));
 
-      current_ino = le32_to_cpu(dp->inode);
+      current_ino = le32toh(dp->inode);
       *(dirname = rest) = ch;
     }
   /* never get here */
diff --git a/fs/fsys_reiserfs.c b/fs/fsys_reiserfs.c
index 74594f0..d3de6be 100644
--- a/fs/fsys_reiserfs.c
+++ b/fs/fsys_reiserfs.c
@@ -38,14 +38,6 @@ typedef unsigned long long __u64;
 /* linux/posix_type.h */
 typedef long linux_off_t;
 
-/* linux/little_endian.h */
-#define __cpu_to_le64(x) ((__u64) (x))
-#define __le64_to_cpu(x) ((__u64) (x))
-#define __cpu_to_le32(x) ((__u32) (x))
-#define __le32_to_cpu(x) ((__u32) (x))
-#define __cpu_to_le16(x) ((__u16) (x))
-#define __le16_to_cpu(x) ((__u16) (x))
-
 /* include/linux/reiser_fs.h */
 /* This is the new super block of a journaling reiserfs system */
 struct reiserfs_super_block
diff --git a/fs/squashfs_fs.h b/fs/squashfs_fs.h
index d4ba9b3..d561edb 100644
--- a/fs/squashfs_fs.h
+++ b/fs/squashfs_fs.h
@@ -849,8 +849,6 @@ struct squashfs_fragment_entry_2 {
  * architectures
  */
 
-#include <arch/byteorder.h>
-
 #ifdef __BIG_ENDIAN
 	/* convert from little endian to big endian */
 #define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, \
diff --git a/include/fs.h b/include/fs.h
index 3138ab5..c91ace7 100644
--- a/include/fs.h
+++ b/include/fs.h
@@ -20,7 +20,6 @@
 #define FS_H
 
 #include <libpayload.h>
-#include <arch/byteorder.h>
 typedef uint64_t sector_t;
 
 #define DEV_SECTOR_BITS		9
diff --git a/main/grub/md5.c b/main/grub/md5.c
index ff344fc..1987714 100644
--- a/main/grub/md5.c
+++ b/main/grub/md5.c
@@ -41,8 +41,8 @@
 
 #ifdef USE_MD5
 
-#define cpu_to_le32(x) (x)
-#define le32_to_cpu(x) cpu_to_le32(x)
+#define htole32(x) (x)
+#define le32toh(x) htole32(x)
 typedef unsigned int UINT4;
 
 /* F, G, H and I are basic MD5 functions.
@@ -103,7 +103,7 @@ static void md5_transform(const unsigned char block[64])
 
 	/* Round 1 */
 	for (i = 0; i < 16; i++) {
-		tmp = a + F(b, c, d) + le32_to_cpu(x[i]) + T[i];
+		tmp = a + F(b, c, d) + le32toh(x[i]) + T[i];
 		tmp = ROTATE_LEFT(tmp, s1[i & 3]);
 		tmp += b;
 		a = d;
@@ -113,7 +113,7 @@ static void md5_transform(const unsigned char block[64])
 	}
 	/* Round 2 */
 	for (i = 0, j = 1; i < 16; i++, j += 5) {
-		tmp = a + G(b, c, d) + le32_to_cpu(x[j & 15]) + T[i + 16];
+		tmp = a + G(b, c, d) + le32toh(x[j & 15]) + T[i + 16];
 		tmp = ROTATE_LEFT(tmp, s2[i & 3]);
 		tmp += b;
 		a = d;
@@ -123,7 +123,7 @@ static void md5_transform(const unsigned char block[64])
 	}
 	/* Round 3 */
 	for (i = 0, j = 5; i < 16; i++, j += 3) {
-		tmp = a + H(b, c, d) + le32_to_cpu(x[j & 15]) + T[i + 32];
+		tmp = a + H(b, c, d) + le32toh(x[j & 15]) + T[i + 32];
 		tmp = ROTATE_LEFT(tmp, s3[i & 3]);
 		tmp += b;
 		a = d;
@@ -133,7 +133,7 @@ static void md5_transform(const unsigned char block[64])
 	}
 	/* Round 4 */
 	for (i = 0, j = 0; i < 16; i++, j += 7) {
-		tmp = a + I(b, c, d) + le32_to_cpu(x[j & 15]) + T[i + 48];
+		tmp = a + I(b, c, d) + le32toh(x[j & 15]) + T[i + 48];
 		tmp = ROTATE_LEFT(tmp, s4[i & 3]);
 		tmp += b;
 		a = d;
@@ -189,12 +189,12 @@ static unsigned char *md5_final()
 		buflen = 0;
 	}
 
-	*(UINT4 *) (buffer + 56) = cpu_to_le32(8 * length);
+	*(UINT4 *) (buffer + 56) = htole32(8 * length);
 	*(UINT4 *) (buffer + 60) = 0;
 	md5_transform(buffer);
 
 	for (i = 0; i < 4; i++)
-		state[i] = cpu_to_le32(state[i]);
+		state[i] = htole32(state[i]);
 	return (unsigned char *) state;
 }
 
diff --git a/x86/include/arch/byteorder.h b/x86/include/arch/byteorder.h
deleted file mode 100644
index afaebfa..0000000
--- a/x86/include/arch/byteorder.h
+++ /dev/null
@@ -1,64 +0,0 @@
-#ifndef ARCH_ENDIAN_H
-#define ARCH_ENDIAN_H
-
-static inline u16 __i386_bswap_16(u16 x)
-{
-	__asm__("xchgb %b0,%h0\n\t"
-		: "=q" (x)
-		: "0" (x));
-	return x;
-}
-
-static inline u32 __i386_bswap_32(u32 x)
-{
-	__asm__("xchgb %b0,%h0\n\t"
-		"rorl $16,%0\n\t"
-		"xchgb %b0,%h0"
-		: "=q" (x)
-		: "0" (x));
-	return x;
-}
-
-
-#define __bswap_constant_16(x) \
-	((u16)((((u16)(x) & 0x00ff) << 8) | \
-		(((u16)(x) & 0xff00) >> 8)))
-
-#define __bswap_constant_32(x) \
-	((u32)((((u32)(x) & 0x000000ffU) << 24) | \
-		(((u32)(x) & 0x0000ff00U) <<  8) | \
-		(((u32)(x) & 0x00ff0000U) >>  8) | \
-		(((u32)(x) & 0xff000000U) >> 24)))
-
-#define __bswap_16(x) \
-	((u16)(__builtin_constant_p(x) ? \
-	__bswap_constant_16(x) : \
-	__i386_bswap_16(x)))
-
-
-#define __bswap_32(x) \
-	((u32)(__builtin_constant_p(x) ? \
-	__bswap_constant_32(x) : \
-	__i386_bswap_32(x)))
-
-
-#define __BYTE_ORDER __LITTLE_ENDIAN
-
-#define le32_to_cpup(x) (*(u32 *)(x))
-#define cpu_to_le16p(x) (*(u16*)(x))
-
-#define ntohl(x)        __bswap_32(x)
-#define htonl(x)        __bswap_32(x)
-#define ntohs(x)        __bswap_16(x)
-#define htons(x)        __bswap_16(x)
-#define cpu_to_le32(x)  (x)
-#define cpu_to_le16(x)  (x)
-#define cpu_to_be32(x)  __bswap_32(x)
-#define cpu_to_be16(x)  __bswap_16(x)
-#define le32_to_cpu(x)  (x)
-#define le16_to_cpu(x)  (x)
-#define be32_to_cpu(x)  __bswap_32(x)
-#define be16_to_cpu(x)  __bswap_16(x)
-
-#endif /* ARCH_ENDIAN_H */
-



More information about the coreboot-gerrit mailing list