From 6a00113de8b9060a7227bcfa79b3786e3e592a33 Mon Sep 17 00:00:00 2001 From: Stefan Reinauer Date: Thu, 13 Jul 2017 02:20:27 +0200 Subject: Rename __attribute__((packed)) --> __packed Also unify __attribute__ ((..)) to __attribute__((..)) and handle ((__packed__)) like ((packed)) Change-Id: Ie60a51c3fa92b5009724a5b7c2932e361bf3490c Signed-off-by: Stefan Reinauer Reviewed-on: https://review.coreboot.org/15921 Tested-by: build bot (Jenkins) Reviewed-by: Aaron Durbin --- util/cbfstool/cbfs.h | 27 +++++++++++---------------- util/cbfstool/compiler.h | 28 ++++++++++++++++++++++++++++ util/cbfstool/fit.c | 7 ++++--- util/cbfstool/flashmap/fmap.h | 6 +++--- util/cbfstool/ifwitool.c | 19 ++++++++++--------- util/cbfstool/linux.h | 2 +- util/cbfstool/lz4/lib/lz4.c | 2 +- util/cbfstool/lz4/lib/xxhash.c | 2 +- util/cbmem/Makefile | 2 +- util/cbmem/compiler.h | 28 ++++++++++++++++++++++++++++ 10 files changed, 88 insertions(+), 35 deletions(-) create mode 100644 util/cbfstool/compiler.h create mode 100644 util/cbmem/compiler.h (limited to 'util') diff --git a/util/cbfstool/cbfs.h b/util/cbfstool/cbfs.h index 451ef9fd8b..f7b5f917e7 100644 --- a/util/cbfstool/cbfs.h +++ b/util/cbfstool/cbfs.h @@ -18,6 +18,7 @@ #include "common.h" #include +#include #include @@ -36,12 +37,6 @@ #define makemagic(b3, b2, b1, b0)\ (((b3)<<24) | ((b2) << 16) | ((b1) << 8) | (b0)) -#if defined(__WIN32) || defined(__WIN64) -#define __PACKED __attribute__((gcc_struct, packed)) -#else -#define __PACKED __attribute__((packed)) -#endif - /* To make CBFS more friendly to ROM, fill -1 (0xFF) instead of zero. */ #define CBFS_CONTENT_DEFAULT_VALUE (-1) @@ -65,7 +60,7 @@ struct cbfs_header { uint32_t offset; uint32_t architecture; /* Version 2 */ uint32_t pad[1]; -} __PACKED; +} __packed; #define CBFS_ARCHITECTURE_UNKNOWN 0xFFFFFFFF #define CBFS_ARCHITECTURE_X86 0x00000001 @@ -87,7 +82,7 @@ struct cbfs_file { /* length of header incl. variable data */ uint32_t offset; char filename[]; -} __PACKED; +} __packed; #if defined __GNUC__ && (__GNUC__ * 100 + __GNUC_MINOR__) >= 406 _Static_assert(sizeof(struct cbfs_file) == 24, "cbfs_file size mismatch"); @@ -101,7 +96,7 @@ struct cbfs_file_attribute { /* len covers the whole structure, incl. tag and len */ uint32_t len; uint8_t data[0]; -} __PACKED; +} __packed; /* Depending on how the header was initialized, it may be backed with 0x00 or * 0xff. Support both. */ @@ -118,7 +113,7 @@ struct cbfs_file_attr_compression { /* whole file compression format. 0 if no compression. */ uint32_t compression; uint32_t decompressed_size; -} __PACKED; +} __packed; struct cbfs_file_attr_hash { uint32_t tag; @@ -126,19 +121,19 @@ struct cbfs_file_attr_hash { uint32_t hash_type; /* hash_data is len - sizeof(struct) bytes */ uint8_t hash_data[]; -} __PACKED; +} __packed; struct cbfs_file_attr_position { uint32_t tag; uint32_t len; uint32_t position; -} __PACKED; +} __packed; struct cbfs_file_attr_align { uint32_t tag; uint32_t len; uint32_t alignment; -} __PACKED; +} __packed; struct cbfs_stage { uint32_t compression; @@ -146,7 +141,7 @@ struct cbfs_stage { uint64_t load; uint32_t len; uint32_t memlen; -} __PACKED; +} __packed; #define PAYLOAD_SEGMENT_CODE makemagic('C', 'O', 'D', 'E') #define PAYLOAD_SEGMENT_DATA makemagic('D', 'A', 'T', 'A') @@ -161,11 +156,11 @@ struct cbfs_payload_segment { uint64_t load_addr; uint32_t len; uint32_t mem_len; -} __PACKED; +} __packed; struct cbfs_payload { struct cbfs_payload_segment segments; -} __PACKED; +} __packed; /** These are standard component types for well known components (i.e - those that coreboot needs to consume. diff --git a/util/cbfstool/compiler.h b/util/cbfstool/compiler.h new file mode 100644 index 0000000000..f218725086 --- /dev/null +++ b/util/cbfstool/compiler.h @@ -0,0 +1,28 @@ +/* + * This file is part of the coreboot project. + * + * Copyright 2017 Google Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#ifndef __COMPILER_H__ +#define __COMPILER_H__ + +#if defined(__WIN32) || defined(__WIN64) +#define __packed __attribute__((gcc_struct, packed)) +#else +#define __packed __attribute__((packed)) +#endif + +#define __aligned(x) __attribute__((aligned(x))) +#define __always_unused __attribute__((unused)) + +#endif diff --git a/util/cbfstool/fit.c b/util/cbfstool/fit.c index 6de311c75d..e3e6c32a6f 100644 --- a/util/cbfstool/fit.c +++ b/util/cbfstool/fit.c @@ -17,6 +17,7 @@ #include #include #include +#include #include "fit.h" @@ -37,12 +38,12 @@ struct fit_entry { uint16_t version; uint8_t type_checksum_valid; uint8_t checksum; -} __attribute__ ((packed)); +} __packed; struct fit_table { struct fit_entry header; struct fit_entry entries[]; -} __attribute__ ((packed)); +} __packed; struct microcode_header { uint32_t version; @@ -55,7 +56,7 @@ struct microcode_header { uint32_t data_size; uint32_t total_size; uint8_t reserved[12]; -} __attribute__ ((packed)); +} __packed; struct microcode_entry { int offset; diff --git a/util/cbfstool/flashmap/fmap.h b/util/cbfstool/flashmap/fmap.h index 30ceb29247..017d332ef9 100644 --- a/util/cbfstool/flashmap/fmap.h +++ b/util/cbfstool/flashmap/fmap.h @@ -37,7 +37,7 @@ #define FLASHMAP_LIB_FMAP_H__ #include - +#include #include #define FMAP_SIGNATURE "__FMAP__" @@ -58,7 +58,7 @@ struct fmap_area { uint32_t size; /* size in bytes */ uint8_t name[FMAP_STRLEN]; /* descriptive name */ uint16_t flags; /* flags for this area */ -} __attribute__((packed)); +} __packed; struct fmap { uint8_t signature[8]; /* "__FMAP__" (0x5F5F464D41505F5F) */ @@ -70,7 +70,7 @@ struct fmap { uint16_t nareas; /* number of areas described by fmap_areas[] below */ struct fmap_area areas[]; -} __attribute__((packed)); +} __packed; /* * fmap_find - find FMAP signature in a binary image diff --git a/util/cbfstool/ifwitool.c b/util/cbfstool/ifwitool.c index 32d09ca6c8..c427339a48 100644 --- a/util/cbfstool/ifwitool.c +++ b/util/cbfstool/ifwitool.c @@ -17,6 +17,7 @@ #include #include #include +#include #include "common.h" @@ -59,7 +60,7 @@ struct bpdt_header { uint32_t ifwi_version; /* Version of FIT tool used to create IFWI. */ uint64_t fit_tool_version; -} __attribute__((packed)); +} __packed; #define BPDT_HEADER_SIZE (sizeof(struct bpdt_header)) struct bpdt_entry { @@ -71,14 +72,14 @@ struct bpdt_entry { uint32_t offset; /* Size in bytes of sub-partition. */ uint32_t size; -} __attribute__((packed)); +} __packed; #define BPDT_ENTRY_SIZE (sizeof(struct bpdt_entry)) struct bpdt { struct bpdt_header h; /* In practice, this could be an array of 0 to n entries. */ struct bpdt_entry e[0]; -} __attribute__((packed)); +} __packed; static inline size_t get_bpdt_size(struct bpdt_header *h) { @@ -107,7 +108,7 @@ struct subpart_dir_header { uint8_t checksum; /* ASCII short name of sub-partition. */ uint8_t name[4]; -} __attribute__((packed)); +} __packed; #define SUBPART_DIR_HEADER_SIZE \ (sizeof(struct subpart_dir_header)) #define SUBPART_DIR_MARKER 0x44504324 @@ -124,7 +125,7 @@ struct subpart_dir_entry { uint32_t length; /* Must be zero. */ uint32_t rsvd; -} __attribute__((packed)); +} __packed; #define SUBPART_DIR_ENTRY_SIZE \ (sizeof(struct subpart_dir_entry)) @@ -132,7 +133,7 @@ struct subpart_dir { struct subpart_dir_header h; /* In practice, this could be an array of 0 to n entries. */ struct subpart_dir_entry e[0]; -} __attribute__((packed)); +} __packed; static inline size_t subpart_dir_size(struct subpart_dir_header *h) { @@ -158,7 +159,7 @@ struct manifest_header { uint8_t public_key[256]; uint32_t exponent; uint8_t signature[256]; -} __attribute__((packed)); +} __packed; #define DWORD_SIZE 4 #define MANIFEST_HDR_SIZE (sizeof(struct manifest_header)) @@ -171,7 +172,7 @@ struct module { uint16_t hash_size; uint32_t metadata_size; uint8_t metadata_hash[32]; -} __attribute__((packed)); +} __packed; #define MODULE_SIZE (sizeof(struct module)) @@ -183,7 +184,7 @@ struct signed_pkg_info_ext { uint8_t bitmap[16]; uint32_t svn; uint8_t rsvd[16]; -} __attribute__((packed)); +} __packed; #define SIGNED_PKG_INFO_EXT_TYPE 0x15 #define SIGNED_PKG_INFO_EXT_SIZE \ diff --git a/util/cbfstool/linux.h b/util/cbfstool/linux.h index 2fd2d4d32a..249c7d7d54 100644 --- a/util/cbfstool/linux.h +++ b/util/cbfstool/linux.h @@ -89,7 +89,7 @@ struct linux_header { /* 2.10+ */ u64 pref_address; /* 0x258 */ u32 init_size; /* 0x260 */ -} __attribute__ ((packed)); +} __packed; /* Paramters passed to 32-bit part of Linux * This is another view of the structure above.. */ diff --git a/util/cbfstool/lz4/lib/lz4.c b/util/cbfstool/lz4/lib/lz4.c index 8512452b3d..9c9a9a0d00 100644 --- a/util/cbfstool/lz4/lib/lz4.c +++ b/util/cbfstool/lz4/lib/lz4.c @@ -176,7 +176,7 @@ static void LZ4_write16(void* memPtr, U16 value) { *(U16*)memPtr = value; } /* __pack instructions are safer, but compiler specific, hence potentially problematic for some compilers */ /* currently only defined for gcc and icc */ -typedef union { U16 u16; U32 u32; size_t uArch; } __attribute__((packed)) unalign; +typedef union { U16 u16; U32 u32; size_t uArch; } __packed unalign; static U16 LZ4_read16(const void* ptr) { return ((const unalign*)ptr)->u16; } static U32 LZ4_read32(const void* ptr) { return ((const unalign*)ptr)->u32; } diff --git a/util/cbfstool/lz4/lib/xxhash.c b/util/cbfstool/lz4/lib/xxhash.c index 511d9941a2..ed9f8ed2e9 100644 --- a/util/cbfstool/lz4/lib/xxhash.c +++ b/util/cbfstool/lz4/lib/xxhash.c @@ -146,7 +146,7 @@ static U64 XXH_read64(const void* memPtr) { return *(const U64*) memPtr; } /* __pack instructions are safer, but compiler specific, hence potentially problematic for some compilers */ /* currently only defined for gcc and icc */ -typedef union { U32 u32; U64 u64; } __attribute__((packed)) unalign; +typedef union { U32 u32; U64 u64; } __packed unalign; static U32 XXH_read32(const void* ptr) { return ((const unalign*)ptr)->u32; } static U64 XXH_read64(const void* ptr) { return ((const unalign*)ptr)->u64; } diff --git a/util/cbmem/Makefile b/util/cbmem/Makefile index e773a40f16..694cac7110 100644 --- a/util/cbmem/Makefile +++ b/util/cbmem/Makefile @@ -20,7 +20,7 @@ INSTALL ?= /usr/bin/install PREFIX ?= /usr/local CFLAGS ?= -O2 CFLAGS += -Wall -Werror -CPPFLAGS += -I $(ROOT)/commonlib/include +CPPFLAGS += -I . -I $(ROOT)/commonlib/include OBJS = $(PROGRAM).o diff --git a/util/cbmem/compiler.h b/util/cbmem/compiler.h new file mode 100644 index 0000000000..f218725086 --- /dev/null +++ b/util/cbmem/compiler.h @@ -0,0 +1,28 @@ +/* + * This file is part of the coreboot project. + * + * Copyright 2017 Google Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#ifndef __COMPILER_H__ +#define __COMPILER_H__ + +#if defined(__WIN32) || defined(__WIN64) +#define __packed __attribute__((gcc_struct, packed)) +#else +#define __packed __attribute__((packed)) +#endif + +#define __aligned(x) __attribute__((aligned(x))) +#define __always_unused __attribute__((unused)) + +#endif -- cgit v1.2.3