Skip to content

Commit d23b9c8

Browse files
committed
Add information about build config to --version output
Closes igrr/mkspiffs#32
1 parent b4fc1f3 commit d23b9c8

File tree

5 files changed

+87
-4
lines changed

5 files changed

+87
-4
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ script:
1212
- make dist
1313
# Build configuration with SPIFFS_USE_MAGIC_LENGTH=0 (legacy version)
1414
- make clean
15-
- make dist BUILD_CONFIG_NAME="-no_magic_length" CFLAGS="-DSPIFFS_USE_MAGIC_LENGTH=0 -DSPIFFS_ALIGNED_OBJECT_INDEX_TABLES=1"
15+
- make dist BUILD_CONFIG_NAME="-no_magic_length" CPPFLAGS="-DSPIFFS_USE_MAGIC_LENGTH=0 -DSPIFFS_ALIGNED_OBJECT_INDEX_TABLES=1"
1616

1717
notifications:
1818
email:

Makefile

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
BUILD_CONFIG_NAME ?=
2-
31
ifeq ($(OS),Windows_NT)
42
TARGET_OS := WINDOWS
53
DIST_SUFFIX := windows
@@ -37,6 +35,8 @@ else
3735
endif
3836

3937
VERSION ?= $(shell git describe --always)
38+
SPIFFS_VERSION := $(shell git -C spiffs describe --tags || echo "unknown")
39+
BUILD_CONFIG_NAME ?= -generic
4040

4141
OBJ := main.o \
4242
spiffs/src/spiffs_cache.o \
@@ -47,10 +47,19 @@ OBJ := main.o \
4747

4848
INCLUDES := -Itclap -Iinclude -Ispiffs/src -I.
4949

50+
override CPPFLAGS := \
51+
$(INCLUDES) \
52+
-D $(TARGET_OS) \
53+
-D VERSION=\"$(VERSION)\" \
54+
-D SPIFFS_VERSION=\"$(SPIFFS_VERSION)\" \
55+
-D "BUILD_CONFIG=\"$(CPPFLAGS)\"" \
56+
-D BUILD_CONFIG_NAME=\"$(BUILD_CONFIG_NAME)\" \
57+
-D __NO_INLINE__ \
58+
$(CPPFLAGS)
59+
5060
override CFLAGS := -std=gnu99 -Os -Wall $(TARGET_CFLAGS) $(CFLAGS)
5161
override CXXFLAGS := -std=gnu++11 -Os -Wall $(TARGET_CXXFLAGS) $(CXXFLAGS)
5262
override LDFLAGS := $(TARGET_LDFLAGS) $(LDFLAGS)
53-
override CPPFLAGS := $(INCLUDES) -D$(TARGET_OS) -DVERSION=\"$(VERSION)\" -D__NO_INLINE__ $(CPPFLAGS)
5463

5564
DIST_NAME := mkspiffs-$(VERSION)$(BUILD_CONFIG_NAME)-$(DIST_SUFFIX)
5665
DIST_DIR := $(DIST_NAME)

README.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,45 @@ Run:
6161
$ make dist
6262
```
6363

64+
## SPIFFS configuration
65+
66+
Some SPIFFS options which are set at mkspiffs build time affect the format of the generated filesystem image. Make sure such options are set to the same values when builing mkspiffs and when building the application which uses SPIFFS.
67+
68+
These options include:
69+
70+
- SPIFFS_OBJ_NAME_LEN
71+
- SPIFFS_OBJ_META_LEN
72+
- SPIFFS_USE_MAGIC
73+
- SPIFFS_USE_MAGIC_LENGTH
74+
- SPIFFS_ALIGNED_OBJECT_INDEX_TABLES
75+
- possibly others
76+
77+
To see the default values of these options, check `include/spiffs_config.h` file in this repository.
78+
79+
To override some options at build time, pass extra `CPPFLAGS` to `make`. You can also set `BUILD_CONFIG_NAME` variable to distinguish the built binary:
80+
81+
```bash
82+
$ make clean
83+
$ make dist CPPFLAGS="-DSPIFFS_OBJ_META_LEN=4" BUILD_CONFIG_NAME=-custom
84+
```
85+
86+
To check which options were set when building mkspiffs, use `--version` command:
87+
88+
```
89+
$ mkspiffs --version
90+
mkspiffs ver. 0.2.2
91+
Build configuration name: custom
92+
SPIFFS ver. 0.3.7-5-gf5e26c4
93+
Extra build flags: -DSPIFFS_OBJ_META_LEN=4
94+
SPIFFS configuration:
95+
SPIFFS_OBJ_NAME_LEN: 32
96+
SPIFFS_OBJ_META_LEN: 4
97+
SPIFFS_USE_MAGIC: 1
98+
SPIFFS_USE_MAGIC_LENGTH: 1
99+
SPIFFS_ALIGNED_OBJECT_INDEX_TABLES: 0
100+
```
101+
102+
64103
### Build status
65104

66105
Linux | Windows

include/spiffs_config.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,9 @@ typedef uint8_t u8_t;
125125
// Object name maximum length. Note that this length include the
126126
// zero-termination character, meaning maximum string of characters
127127
// can at most be SPIFFS_OBJ_NAME_LEN - 1.
128+
#ifndef SPIFFS_OBJ_NAME_LEN
128129
#define SPIFFS_OBJ_NAME_LEN (32)
130+
#endif
129131

130132
// Maximum length of the metadata associated with an object.
131133
// Setting to non-zero value enables metadata-related API but also
@@ -137,7 +139,9 @@ typedef uint8_t u8_t;
137139
// This is derived from following:
138140
// logical_page_size - (SPIFFS_OBJ_NAME_LEN + sizeof(spiffs_page_header) +
139141
// spiffs_object_ix_header fields + at least some LUT entries)
142+
#ifndef SPIFFS_OBJ_META_LEN
140143
#define SPIFFS_OBJ_META_LEN (0)
144+
#endif
141145

142146
// Size of buffer allocated on stack used when copying data.
143147
// Lower value generates more read/writes. No meaning having it bigger

main.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -535,8 +535,39 @@ int actionVisualize() {
535535
return 0;
536536
}
537537

538+
#define PRINT_INT_MACRO(def_name) \
539+
std::cout << " " # def_name ": " << def_name << std::endl;
540+
541+
class CustomOutput : public TCLAP::StdOutput
542+
{
543+
public:
544+
virtual void version(TCLAP::CmdLineInterface& c)
545+
{
546+
std::cout << "mkspiffs ver. " VERSION << std::endl;
547+
const char* configName = BUILD_CONFIG_NAME;
548+
if (configName[0] == '-') configName += 1;
549+
std::cout << "Build configuration name: " << configName << std::endl;
550+
std::cout << "SPIFFS ver. " SPIFFS_VERSION << std::endl;
551+
const char* buildConfig = BUILD_CONFIG;
552+
std::cout << "Extra build flags: " << (strlen(buildConfig) ? buildConfig : "(none)") << std::endl;
553+
std::cout << "SPIFFS configuration:" << std::endl;
554+
PRINT_INT_MACRO(SPIFFS_OBJ_NAME_LEN);
555+
PRINT_INT_MACRO(SPIFFS_OBJ_META_LEN);
556+
PRINT_INT_MACRO(SPIFFS_USE_MAGIC);
557+
#if SPIFFS_USE_MAGIC == 1
558+
PRINT_INT_MACRO(SPIFFS_USE_MAGIC_LENGTH);
559+
#endif
560+
PRINT_INT_MACRO(SPIFFS_ALIGNED_OBJECT_INDEX_TABLES);
561+
}
562+
};
563+
564+
#undef PRINT_INT_MACRO
565+
538566
void processArgs(int argc, const char** argv) {
539567
TCLAP::CmdLine cmd("", ' ', VERSION);
568+
CustomOutput output;
569+
cmd.setOutput(&output);
570+
540571
TCLAP::ValueArg<std::string> packArg( "c", "create", "create spiffs image from a directory", true, "", "pack_dir");
541572
TCLAP::ValueArg<std::string> unpackArg( "u", "unpack", "unpack spiffs image to a directory", true, "", "dest_dir");
542573
TCLAP::SwitchArg listArg( "l", "list", "list files in spiffs image", false);

0 commit comments

Comments
 (0)