Thomas Heijligen has uploaded this change for review. ( https://review.coreboot.org/c/flashrom/+/62899 )
Change subject: Endian conversion: move to platform.h and platform/endian*.c ......................................................................
Endian conversion: move to platform.h and platform/endian*.c
Starting to move the platform dependent code to platform/ and provide the abstraction through the platform.h header.
Change-Id: I35640282d451960f2a329ae24339ec05dbae6d30 Signed-off-by: Thomas Heijligen thomas.heijligen@secunet.com --- M Makefile D hwaccess_endian_big.c M hwaccess_physmap.c M meson.build R platform.h R platform/endian.c R platform/endian_big.c C platform/endian_little.c 8 files changed, 32 insertions(+), 116 deletions(-)
git pull ssh://review.coreboot.org:29418/flashrom refs/changes/99/62899/1
diff --git a/Makefile b/Makefile index 08549eb..1321c11 100644 --- a/Makefile +++ b/Makefile @@ -371,14 +371,14 @@ # Library code.
LIB_OBJS = libflashrom.o layout.o flashrom.o udelay.o programmer.o programmer_table.o \ - helpers.o ich_descriptors.o fmap.o hwaccess.o + helpers.o ich_descriptors.o fmap.o + +LIB_OBJS += platform/endian.o platform/endian_$(ENDIAN).o
ifeq ($(ENDIAN), little) -LIB_OBJS += hwaccess_endian_little.o FEATURE_FLAGS += -D'__FLASHROM_LITTLE_ENDIAN__=1' endif ifeq ($(ENDIAN), big) -LIB_OBJS += hwaccess_endian_big.o FEATURE_FLAGS += -D'__FLASHROM_BIG_ENDIAN__=1' endif
@@ -978,7 +978,8 @@ # This includes all frontends and libflashrom. # We don't use EXEC_SUFFIX here because we want to clean everything. clean: - rm -f $(PROGRAM) $(PROGRAM).exe libflashrom.a $(filter-out Makefile.d, $(wildcard *.d *.o)) $(PROGRAM).8 $(PROGRAM).8.html $(BUILD_DETAILS_FILE) + rm -f $(PROGRAM) $(PROGRAM).exe libflashrom.a $(filter-out Makefile.d, $(wildcard *.d *.o platform/*.d platform/*.o)) \ + $(PROGRAM).8 $(PROGRAM).8.html $(BUILD_DETAILS_FILE) @+$(MAKE) -C util/ich_descriptors_tool/ clean
install: $(PROGRAM)$(EXEC_SUFFIX) $(PROGRAM).8 diff --git a/hwaccess_endian_big.c b/hwaccess_endian_big.c deleted file mode 100644 index fd122dc..0000000 --- a/hwaccess_endian_big.c +++ /dev/null @@ -1,85 +0,0 @@ -#include "hwaccess.h" - -/* convert cpu native endian to little endian */ -uint8_t cpu_to_le8 (const uint8_t value) -{ - return swap8(value); -} - -uint16_t cpu_to_le16(const uint16_t value) -{ - return swap16(value); -} - -uint32_t cpu_to_le32(const uint32_t value) -{ - return swap32(value); -} - -uint64_t cpu_to_le64(const uint64_t value) -{ - return swap64(value); -} - -/* convert cpu native endian to big endian */ -uint8_t cpu_to_be8 (const uint8_t value) -{ - return value; -} - -uint16_t cpu_to_be16(const uint16_t value) -{ - return value; -} - -uint32_t cpu_to_be32(const uint32_t value) -{ - return value; -} - -uint64_t cpu_to_be64(const uint64_t value) -{ - return value; -} - -/* convert little endian to cpu native endian */ -uint8_t le_to_cpu8 (const uint8_t value) -{ - return swap8(value); -} - -uint16_t le_to_cpu16(const uint16_t value) -{ - return swap16(value); -} - -uint32_t le_to_cpu32(const uint32_t value) -{ - return swap32(value); -} - -uint64_t le_to_cpu64(const uint64_t value) -{ - return swap64(value); -} - -/* convert big endian to cpu native endian */ -uint8_t be_to_cpu8 (const uint8_t value) -{ - return value; -} - -uint16_t be_to_cpu16(const uint16_t value) -{ - return value; -} - -uint32_t be_to_cpu32(const uint32_t value) -{ - return value; -} - -uint64_t be_to_cpu64(const uint64_t value) -{ - return value; -} diff --git a/hwaccess_physmap.c b/hwaccess_physmap.c index b1b9c64..428893d 100644 --- a/hwaccess_physmap.c +++ b/hwaccess_physmap.c @@ -24,7 +24,7 @@ #include <string.h> #include <errno.h> #include "flash.h" -#include "hwaccess.h" +#include "platform.h" #include "hwaccess_physmap.h"
#if !defined(__DJGPP__) && !defined(__LIBPAYLOAD__) diff --git a/meson.build b/meson.build index 5275bd2..906a4ec 100644 --- a/meson.build +++ b/meson.build @@ -135,13 +135,13 @@ add_project_arguments('-DHAVE_UTSNAME=1', language : 'c') endif
-srcs += 'hwaccess.c' +srcs += 'platform/endian.c' if host_machine.endian() == 'little' - srcs += 'hwaccess_endian_little.c' + srcs += 'platform/endian_little.c' add_project_arguments('-D__FLASHROM_LITTLE_ENDIAN__=1', language : 'c') endif if host_machine.endian() == 'big' - srcs += 'hwaccess_endian_big.c' + srcs += 'platform/endian_big.c' add_project_arguments('-D__FLASHROM_BIG_ENDIAN__=1', language : 'c') endif
diff --git a/hwaccess.h b/platform.h similarity index 91% rename from hwaccess.h rename to platform.h index 4c330c4..6c26ff9 100644 --- a/hwaccess.h +++ b/platform.h @@ -16,11 +16,11 @@ */
/* - * Header file for hardware access and OS abstraction. Included from flash.h. + * Header file for platform abstraction. */
-#ifndef __HWACCESS_H__ -#define __HWACCESS_H__ 1 +#ifndef __PLATFORM_H__ +#define __PLATFORM_H__ 1
#include <stdint.h>
@@ -54,4 +54,4 @@ uint32_t be_to_cpu32(const uint32_t value); uint64_t be_to_cpu64(const uint64_t value);
-#endif /* !__HWACCESS_H__ */ +#endif /* !__PLATFORM_H__ */ diff --git a/hwaccess.c b/platform/endian.c similarity index 96% rename from hwaccess.c rename to platform/endian.c index 39f4133..8f38abb 100644 --- a/hwaccess.c +++ b/platform/endian.c @@ -1,4 +1,4 @@ -#include "hwaccess.h" +#include "../platform.h"
uint8_t swap8 (const uint8_t value) { diff --git a/hwaccess_endian_little.c b/platform/endian_big.c similarity index 97% rename from hwaccess_endian_little.c rename to platform/endian_big.c index 4446ce2..28e6e0b 100644 --- a/hwaccess_endian_little.c +++ b/platform/endian_big.c @@ -1,85 +1,85 @@ -#include "hwaccess.h" +#include "../platform.h"
/* convert cpu native endian to little endian */ uint8_t cpu_to_le8 (const uint8_t value) { - return value; + return swap8(value); }
uint16_t cpu_to_le16(const uint16_t value) { - return value; + return swap16(value); }
uint32_t cpu_to_le32(const uint32_t value) { - return value; + return swap32(value); }
uint64_t cpu_to_le64(const uint64_t value) { - return value; + return swap64(value); }
/* convert cpu native endian to big endian */ uint8_t cpu_to_be8 (const uint8_t value) { - return swap8(value); + return value; }
uint16_t cpu_to_be16(const uint16_t value) { - return swap16(value); + return value; }
uint32_t cpu_to_be32(const uint32_t value) { - return swap32(value); + return value; }
uint64_t cpu_to_be64(const uint64_t value) { - return swap64(value); + return value; }
/* convert little endian to cpu native endian */ uint8_t le_to_cpu8 (const uint8_t value) { - return value; + return swap8(value); }
uint16_t le_to_cpu16(const uint16_t value) { - return value; + return swap16(value); }
uint32_t le_to_cpu32(const uint32_t value) { - return value; + return swap32(value); }
uint64_t le_to_cpu64(const uint64_t value) { - return value; + return swap64(value); }
/* convert big endian to cpu native endian */ uint8_t be_to_cpu8 (const uint8_t value) { - return swap8(value); + return value; }
uint16_t be_to_cpu16(const uint16_t value) { - return swap16(value); + return value; }
uint32_t be_to_cpu32(const uint32_t value) { - return swap32(value); + return value; }
uint64_t be_to_cpu64(const uint64_t value) { - return swap64(value); + return value; } diff --git a/hwaccess_endian_little.c b/platform/endian_little.c similarity index 97% copy from hwaccess_endian_little.c copy to platform/endian_little.c index 4446ce2..6331ee3 100644 --- a/hwaccess_endian_little.c +++ b/platform/endian_little.c @@ -1,4 +1,4 @@ -#include "hwaccess.h" +#include "../platform.h"
/* convert cpu native endian to little endian */ uint8_t cpu_to_le8 (const uint8_t value)