From ca0a67624b6f38b0a6c86171950b5c2c6507f2ce Mon Sep 17 00:00:00 2001 From: Aaron Durbin Date: Tue, 15 Dec 2015 17:49:12 -0600 Subject: commonlib: Prepare code to be included in cbfstool builds. Some of the files need to be adjusted so that they can be used both in cbfstool as well as coreboot proper. For coreboot, add a file such that proper types can be included from both the tools and coreboot. The other chanes are to accomodate stricter checking in cbfstool. BUG=chrome-os-partner:48412 BUG=chromium:445938 BRANCH=None TEST=Built on glados including tools. Booted. Change-Id: I771c6675c64b8837f775427721dd3300a8fa1bc0 Signed-off-by: Aaron Durbin Reviewed-on: https://review.coreboot.org/12784 Tested-by: build bot (Jenkins) Reviewed-by: Martin Roth Reviewed-by: Patrick Georgi --- src/commonlib/include/commonlib/helpers.h | 6 ++++++ src/commonlib/include/commonlib/region.h | 1 + src/commonlib/mem_pool.c | 2 +- src/commonlib/region.c | 20 +++++++++++--------- 4 files changed, 19 insertions(+), 10 deletions(-) (limited to 'src/commonlib') diff --git a/src/commonlib/include/commonlib/helpers.h b/src/commonlib/include/commonlib/helpers.h index 0e337c9ce7..646a66f30d 100644 --- a/src/commonlib/include/commonlib/helpers.h +++ b/src/commonlib/include/commonlib/helpers.h @@ -2,7 +2,9 @@ #define COMMONLIB_HELPERS_H /* This file is for helpers for both coreboot firmware and its utilities. */ +#ifndef ARRAY_SIZE #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0])) +#endif #define ALIGN(x,a) __ALIGN_MASK(x,(__typeof__(x))(a)-1UL) #define __ALIGN_MASK(x,mask) (((x)+(mask))&~(mask)) @@ -54,4 +56,8 @@ const __typeof__( ((type *)0)->member ) *__mptr = (ptr); \ (type *)( (char *)__mptr - offsetof(type,member) );}) +#ifndef __unused +#define __unused __attribute__((unused)) +#endif + #endif /* COMMONLIB_HELPERS_H */ diff --git a/src/commonlib/include/commonlib/region.h b/src/commonlib/include/commonlib/region.h index 35d48ade85..a13c66c316 100644 --- a/src/commonlib/include/commonlib/region.h +++ b/src/commonlib/include/commonlib/region.h @@ -16,6 +16,7 @@ #ifndef _REGION_H_ #define _REGION_H_ +#include #include #include #include diff --git a/src/commonlib/mem_pool.c b/src/commonlib/mem_pool.c index e42e9cb3d5..cb3e726f25 100644 --- a/src/commonlib/mem_pool.c +++ b/src/commonlib/mem_pool.c @@ -13,8 +13,8 @@ * GNU General Public License for more details. */ +#include #include -#include void *mem_pool_alloc(struct mem_pool *mp, size_t sz) { diff --git a/src/commonlib/region.c b/src/commonlib/region.c index 2cd273a883..bfc5fc8471 100644 --- a/src/commonlib/region.c +++ b/src/commonlib/region.c @@ -13,6 +13,7 @@ * GNU General Public License for more details. */ +#include #include #include @@ -133,16 +134,17 @@ void mem_region_device_init(struct mem_region_device *mdev, void *base, } static void *mdev_mmap(const struct region_device *rd, size_t offset, - size_t size) + size_t size __unused) { const struct mem_region_device *mdev; - mdev = container_of(rd, typeof(*mdev), rdev); + mdev = container_of(rd, __typeof__(*mdev), rdev); return &mdev->base[offset]; } -static int mdev_munmap(const struct region_device *rd, void *mapping) +static int mdev_munmap(const struct region_device * rd __unused, + void *mapping __unused) { return 0; } @@ -152,7 +154,7 @@ static ssize_t mdev_readat(const struct region_device *rd, void *b, { const struct mem_region_device *mdev; - mdev = container_of(rd, typeof(*mdev), rdev); + mdev = container_of(rd, __typeof__(*mdev), rdev); memcpy(b, &mdev->base[offset], size); @@ -177,7 +179,7 @@ void *mmap_helper_rdev_mmap(const struct region_device *rd, size_t offset, struct mmap_helper_region_device *mdev; void *mapping; - mdev = container_of((void *)rd, typeof(*mdev), rdev); + mdev = container_of((void *)rd, __typeof__(*mdev), rdev); mapping = mem_pool_alloc(&mdev->pool, size); @@ -196,7 +198,7 @@ int mmap_helper_rdev_munmap(const struct region_device *rd, void *mapping) { struct mmap_helper_region_device *mdev; - mdev = container_of((void *)rd, typeof(*mdev), rdev); + mdev = container_of((void *)rd, __typeof__(*mdev), rdev); mem_pool_free(&mdev->pool, mapping); @@ -212,7 +214,7 @@ static void *xlate_mmap(const struct region_device *rd, size_t offset, .size = size, }; - xldev = container_of(rd, typeof(*xldev), rdev); + xldev = container_of(rd, __typeof__(*xldev), rdev); if (!is_subregion(&xldev->sub_region, &req)) return NULL; @@ -226,7 +228,7 @@ static int xlate_munmap(const struct region_device *rd, void *mapping) { const struct xlate_region_device *xldev; - xldev = container_of(rd, typeof(*xldev), rdev); + xldev = container_of(rd, __typeof__(*xldev), rdev); return rdev_munmap(xldev->access_dev, mapping); } @@ -240,7 +242,7 @@ static ssize_t xlate_readat(const struct region_device *rd, void *b, }; const struct xlate_region_device *xldev; - xldev = container_of(rd, typeof(*xldev), rdev); + xldev = container_of(rd, __typeof__(*xldev), rdev); if (!is_subregion(&xldev->sub_region, &req)) return -1; -- cgit v1.2.3