Support TCC building, added two packed struct alignment tests

This commit is contained in:
DataHoarder 2021-01-06 08:01:01 +01:00
parent 32123658e9
commit e8dcaa3af3
6 changed files with 84 additions and 13 deletions

View file

@ -13,7 +13,7 @@ local Pipeline(image, version, arch, depinstall, extra) = {
commands: [
depinstall+" make gcc "+extra,
"make clean",
"make CC=gcc"
"make CC=gcc all"
]
},
{
@ -22,8 +22,17 @@ local Pipeline(image, version, arch, depinstall, extra) = {
commands: [
depinstall+" make clang "+extra,
"make clean",
"make CC=clang"
"make CC=clang all"
]
},
{
name: "build-tcc",
image: image+":"+version,
commands: [
depinstall+" make tcc "+extra,
"make clean",
"make CC=tcc all"
]
}
]
};

1
.gitignore vendored
View file

@ -1,4 +1,5 @@
/fm10k-dump
/fm10k-flash
/test-runner
*.o
/.idea

View file

@ -7,25 +7,33 @@ else
CFLAGS += -Og
endif
default: all
default: fm10k-dump fm10k-flash
all: fm10k-dump fm10k-flash
all: fm10k-dump fm10k-flash test
fm10k.o: src/fm10k.c
$(CC) -c src/fm10k.c -o src/fm10k.o $(CFLAGS)
test: run_test
fm10k-dump.o: src/fm10k-dump.c
$(CC) -c src/fm10k-dump.c -o src/fm10k-dump.o $(CFLAGS)
fm10k-dump: fm10k-dump.o fm10k.o
src/%.o: src/%.c
@$(CC) $(CFLAGS) -c $< $(INC) -o $@
fm10k-dump: src/fm10k-dump.o src/fm10k.o
$(CC) src/fm10k-dump.o src/fm10k.o -o fm10k-dump $(CFLAGS)
fm10k-flash.o: src/fm10k-flash.c
$(CC) -c src/fm10k-flash.c -o src/fm10k-flash.o $(CFLAGS)
fm10k-flash: fm10k-flash.o fm10k.o
fm10k-flash: src/fm10k-flash.o src/fm10k.o
$(CC) src/fm10k-flash.o src/fm10k.o -o fm10k-flash $(CFLAGS)
test-runner: src/test.o src/fm10k.o
$(CC) src/test.o src/fm10k.o -o test-runner $(CFLAGS)
run_test: test-runner
./test-runner
clean:
-rm -f fm10k-dump
-rm -f fm10k-flash
-rm -f test-runner
-rm -f src/*.o

View file

@ -3,7 +3,7 @@
Utility that allows dumping/flashing the SPI Flash Non-Volatile Memory of the FM10000 family of cards.
## Requirements
* GCC >= 4.4.0 or clang
* GCC >= 4.4.0, TCC, or clang
* make
* Only one FM10K device installed on hardware.
* A management resource (BAR4) must be exposed, check bifurcation settings if needed.
@ -11,7 +11,7 @@ Utility that allows dumping/flashing the SPI Flash Non-Volatile Memory of the FM
## Compilation
* `$ make clean && make`
* You can specify whether to use gcc or clang this way: `$ make CC=gcc` / `$ make CC=clang`
* You can specify whether to use gcc/clang/tcc this way: `$ make CC=gcc` / `$ make CC=clang` / `$ make CC=tcc`
* Two executables named `./fm10k-dump` and `./fm10k-flash` should now exist.
## fm10k-dump usage example

View file

@ -54,7 +54,7 @@
#define FM10K_SPI_HEADER_COMMAND_READ_MANUFACTURER_INFORMATION 0x9F
/* Test for GCC >= 4.4.0, see https://gcc.gnu.org/gcc-4.4/changes.html : Packed bit-fields of type char were not properly bit-packed on many targets prior to GCC 4.4 */
#if __GNUC__ > 4 || (__GNUC__ == 4 && (__GNUC_MINOR__ >= 4)) || __clang__
#if __GNUC__ > 4 || (__GNUC__ == 4 && (__GNUC_MINOR__ >= 4)) || __clang__ || __TINYC__
typedef union {
uint32_t value;

53
src/test.c Normal file
View file

@ -0,0 +1,53 @@
/*****************************************************************************
* File: test.c
* Creation Date: January 06, 2021
* Description: Runs several platform alignment tests
* Compile: make test-bin
* Usage: ./test
*
* Copyright (c) 2020, FM10K-Documentation Contributors
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the copyright holders nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#include "fm10k.h"
#include <stdio.h>
#define TEST(have, expected, i) if(have != expected){ printf("[TEST %u] FAIL: " i "\n", ++tests, have, expected); ++testsFailed; }else { printf("[TEST %u] PASS: " i "\n", ++tests, have, expected);}
int main(int argc, char **argv) {
uint32_t tests = 0;
uint32_t testsFailed = 0;
{
SPI_CTRL s;
TEST((uint32_t)sizeof(s.fields), (uint32_t)sizeof(s.value), "SPI_CTRL packed misalignment. size struct %u, size value %u");
}
{
SPI_COMMAND_READ_MANUFACTURER_RESULT s;
TEST((uint32_t)sizeof(s.fields), (uint32_t)sizeof(s.value), "SPI_COMMAND_READ_MANUFACTURER_RESULT packed misalignment. size struct %u, size value %u");
}
printf("\nTests run, failed %u/%u\n", testsFailed, tests);
return testsFailed > 0 ? 1 : 0;
}