Skip to content

Commit 7db8819

Browse files
committed
new prj
0 parents  commit 7db8819

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+20267
-0
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
mkfatfs
2+
mkfatfs.exe
3+
*.o
4+
*.a

Makefile

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
#CFLAGS ?= -std=gnu99 -Os -Wall
2+
#CXXFLAGS ?= -std=gnu++11 -Os -Wall
3+
4+
IDF_MODIFIED_DIR = idf/modified
5+
IDF_INCLUDES += -I $(IDF_MODIFIED_DIR)
6+
IDF_INCLUDES += -I $(IDF_MODIFIED_DIR)/driver/include
7+
IDF_INCLUDES += -I $(IDF_MODIFIED_DIR)/fatfs/src
8+
IDF_INCLUDES += -I $(IDF_MODIFIED_DIR)/freertos/include
9+
IDF_INCLUDES += -I $(IDF_MODIFIED_DIR)/log/include
10+
IDF_INCLUDES += -I $(IDF_MODIFIED_DIR)/newlib/include
11+
IDF_INCLUDES += -I $(IDF_MODIFIED_DIR)/vfs/include
12+
IDF_INCLUDES += -I $(IDF_MODIFIED_DIR)/vfs/include/sys
13+
IDF_INCLUDES += -I $(IDF_MODIFIED_DIR)/wear_levelling/include
14+
15+
IDF_ORIG_DIR = idf/orig
16+
IDF_INCLUDES += -I $(IDF_ORIG_DIR)
17+
IDF_INCLUDES += -I $(IDF_ORIG_DIR)/driver/include
18+
IDF_INCLUDES += -I $(IDF_ORIG_DIR)/driver/include/driver
19+
IDF_INCLUDES += -I $(IDF_ORIG_DIR)/esp32/include
20+
IDF_INCLUDES += -I $(IDF_ORIG_DIR)/fatfs/src
21+
IDF_INCLUDES += -I $(IDF_ORIG_DIR)/sdmmc/include
22+
IDF_INCLUDES += -I $(IDF_ORIG_DIR)/spi_flash/include
23+
IDF_INCLUDES += -I $(IDF_ORIG_DIR)/wear_levelling/private_include
24+
# OS = 1
25+
ifdef OS
26+
ifeq ($(OS),Windows_NT)
27+
OS_IS_WIN = 1
28+
endif
29+
endif
30+
31+
ifdef OS_IS_WIN
32+
TARGET_OS := WINDOWS
33+
DIST_SUFFIX := windows
34+
ARCHIVE_CMD := 7z a
35+
ARCHIVE_EXTENSION := zip
36+
TARGET := mkfatfs.exe
37+
CC=gcc.exe
38+
CXX=g++.exe
39+
#MVA TARGET_CFLAGS := -mno-ms-bitfields
40+
CPATH := $(COMPONENT_INCLUDES)
41+
#TARGET_CFLAGS := -mno-ms-bitfields -std=gnu99 -Os -Wall -I $(COMPONENT_INCLUDES) -Itclap -Ifatfs -I. -D$(TARGET_OS)
42+
TARGET_CFLAGS := -mno-ms-bitfields -std=gnu99 -Os -Wall -Itclap -Ifatfs -I. -D$(TARGET_OS) $(IDF_INCLUDES)
43+
TARGET_CXXFLAGS := -std=gnu++11 -Os -Wall -Itclap -Ifatfs -I. -D$(TARGET_OS) $(IDF_INCLUDES)
44+
TARGET_LDFLAGS := -Wl,-static -static-libgcc
45+
46+
else
47+
UNAME_S := $(shell uname -s)
48+
ifeq ($(UNAME_S),Linux)
49+
TARGET_OS := LINUX
50+
UNAME_P := $(shell uname -p)
51+
ifeq ($(UNAME_P),x86_64)
52+
DIST_SUFFIX := linux64
53+
endif
54+
ifneq ($(filter %86,$(UNAME_P)),)
55+
DIST_SUFFIX := linux32
56+
endif
57+
CC=gcc
58+
CXX=g++
59+
TARGET_CFLAGS = -std=gnu99 -Os -Wall -Itclap -Ifatfs -I. -D$(TARGET_OS) -DVERSION=\"$(VERSION)\" -D__NO_INLINE__ $(IDF_INCLUDES)
60+
TARGET_CXXFLAGS = -std=gnu++11 -Os -Wall -Itclap -Ifatfs -I. -D$(TARGET_OS) -DVERSION=\"$(VERSION)\" -D__NO_INLINE__ $(IDF_INCLUDES)
61+
TARGET_LDFLAGS =
62+
endif
63+
ifeq ($(UNAME_S),Darwin)
64+
TARGET_OS := OSX
65+
DIST_SUFFIX := osx
66+
CC=clang
67+
CXX=clang++
68+
TARGET_CFLAGS = -std=gnu99 -Os -Wall -Itclap -Ifatfs -I. -D$(TARGET_OS) -DVERSION=\"$(VERSION)\" -D__NO_INLINE__ -mmacosx-version-min=10.7 -arch x86_64 $(IDF_INCLUDES)
69+
TARGET_CXXFLAGS = -std=gnu++11 -Os -Wall -Itclap -Ifatfs -I. -D$(TARGET_OS) -DVERSION=\"$(VERSION)\" -D__NO_INLINE__ -mmacosx-version-min=10.7 -arch x86_64 -stdlib=libc++ $(IDF_INCLUDES)
70+
TARGET_LDFLAGS = -arch x86_64 -stdlib=libc++
71+
endif
72+
ARCHIVE_CMD := tar czf
73+
ARCHIVE_EXTENSION := tar.gz
74+
TARGET := mkfatfs
75+
endif
76+
77+
OBJ := main.o \
78+
fatfs/fatfs.o \
79+
fatfs/ccsbcs.o \
80+
fatfs/crc.o \
81+
fatfs/FatPartition.o \
82+
$(IDF_MODIFIED_DIR)/fatfs/src/ff.o \
83+
$(IDF_MODIFIED_DIR)/fatfs/src/vfs_fat.o \
84+
$(IDF_MODIFIED_DIR)/freertos/include/freertos/semphr.o \
85+
$(IDF_MODIFIED_DIR)/newlib/include/sys/lock.o \
86+
$(IDF_MODIFIED_DIR)/newlib/include/sys/idf_reent.o \
87+
$(IDF_MODIFIED_DIR)/newlib/include/sys/errno.o \
88+
$(IDF_MODIFIED_DIR)/spi_flash/partition.o \
89+
$(IDF_MODIFIED_DIR)/vfs/vfs.o \
90+
$(IDF_MODIFIED_DIR)/wear_levelling/wear_levelling.o \
91+
$(IDF_ORIG_DIR)/fatfs/src/diskio.o \
92+
$(IDF_ORIG_DIR)/fatfs/src/diskio_spiflash.o \
93+
$(IDF_ORIG_DIR)/fatfs/src/option/syscall.o \
94+
$(IDF_ORIG_DIR)/wear_levelling/crc32.o \
95+
$(IDF_ORIG_DIR)/wear_levelling/WL_Flash.o \
96+
$(IDF_ORIG_DIR)/wear_levelling/WL_Ext_Perf.o \
97+
$(IDF_ORIG_DIR)/wear_levelling/WL_Ext_Safe.o \
98+
99+
100+
VERSION ?= $(shell git describe --always)
101+
102+
.PHONY: all clean
103+
104+
all: $(TARGET)
105+
106+
$(TARGET):
107+
@echo "Building mkfatfs ..."
108+
$(CXX) $(TARGET_CXXFLAGS) -c main.cpp -o main.o
109+
$(CC) $(TARGET_CFLAGS) -c fatfs/fatfs.c -o fatfs/fatfs.o
110+
$(CC) $(TARGET_CFLAGS) -c fatfs/ccsbcs.c -o fatfs/ccsbcs.o
111+
$(CXX) $(TARGET_CXXFLAGS) -c fatfs/crc.cpp -o fatfs/crc.o
112+
$(CXX) $(TARGET_CXXFLAGS) -c fatfs/FatPartition.cpp -o fatfs/FatPartition.o
113+
$(CC) $(TARGET_CFLAGS) -c $(IDF_MODIFIED_DIR)/fatfs/src/ff.c -o $(IDF_MODIFIED_DIR)/fatfs/src/ff.o
114+
$(CC) $(TARGET_CFLAGS) -c $(IDF_MODIFIED_DIR)/fatfs/src/vfs_fat.c -o $(IDF_MODIFIED_DIR)/fatfs/src/vfs_fat.o
115+
$(CC) $(TARGET_CFLAGS) -c $(IDF_MODIFIED_DIR)/freertos/include/freertos/semphr.c -o $(IDF_MODIFIED_DIR)/freertos/include/freertos/semphr.o
116+
$(CC) $(TARGET_CFLAGS) -c $(IDF_MODIFIED_DIR)/newlib/include/sys/lock.c -o $(IDF_MODIFIED_DIR)/newlib/include/sys/lock.o
117+
$(CC) $(TARGET_CFLAGS) -c $(IDF_MODIFIED_DIR)/newlib/include/sys/idf_reent.c -o $(IDF_MODIFIED_DIR)/newlib/include/sys/idf_reent.o
118+
$(CC) $(TARGET_CFLAGS) -c $(IDF_MODIFIED_DIR)/newlib/include/sys/errno.c -o $(IDF_MODIFIED_DIR)/newlib/include/sys/errno.o
119+
$(CC) $(TARGET_CFLAGS) -c $(IDF_MODIFIED_DIR)/spi_flash/partition.c -o $(IDF_MODIFIED_DIR)/spi_flash/partition.o
120+
$(CC) $(TARGET_CFLAGS) -c $(IDF_MODIFIED_DIR)/vfs/vfs.c -o $(IDF_MODIFIED_DIR)/vfs/vfs.o
121+
$(CXX) $(TARGET_CXXFLAGS) -c $(IDF_MODIFIED_DIR)/wear_levelling/wear_levelling.cpp -o $(IDF_MODIFIED_DIR)/wear_levelling/wear_levelling.o
122+
$(CC) $(TARGET_CFLAGS) -c $(IDF_ORIG_DIR)/fatfs/src/diskio.c -o $(IDF_ORIG_DIR)/fatfs/src/diskio.o
123+
$(CC) $(TARGET_CFLAGS) -c $(IDF_ORIG_DIR)/fatfs/src/diskio_spiflash.c -o $(IDF_ORIG_DIR)/fatfs/src/diskio_spiflash.o
124+
$(CC) $(TARGET_CFLAGS) -c $(IDF_ORIG_DIR)/fatfs/src/option/syscall.c -o $(IDF_ORIG_DIR)/fatfs/src/option/syscall.o
125+
$(CXX) $(TARGET_CXXFLAGS) -c $(IDF_ORIG_DIR)/wear_levelling/crc32.cpp -o $(IDF_ORIG_DIR)/wear_levelling/crc32.o
126+
$(CXX) $(TARGET_CXXFLAGS) -c $(IDF_ORIG_DIR)/wear_levelling/WL_Flash.cpp -o $(IDF_ORIG_DIR)/wear_levelling/WL_Flash.o
127+
$(CXX) $(TARGET_CXXFLAGS) -c $(IDF_ORIG_DIR)/wear_levelling/WL_Ext_Perf.cpp -o $(IDF_ORIG_DIR)/wear_levelling/WL_Ext_Perf.o
128+
$(CXX) $(TARGET_CXXFLAGS) -c $(IDF_ORIG_DIR)/wear_levelling/WL_Ext_Safe.cpp -o $(IDF_ORIG_DIR)/wear_levelling/WL_Ext_Safe.o
129+
$(CXX) $(TARGET_CFLAGS) -o $(TARGET) $(OBJ) $(TARGET_LDFLAGS)
130+
131+
132+
133+
clean:
134+
@rm -f *.o
135+
@rm -f fatfs/*.o
136+
@rm -f $(IDF_MODIFIED_DIR)/fatfs/src/*.o
137+
@rm -f $(IDF_MODIFIED_DIR)/freertos/include/freertos/*.o
138+
@rm -f $(IDF_MODIFIED_DIR)/newlib/include/sys/*.o
139+
@rm -f $(IDF_MODIFIED_DIR)/spi_flash/*.o
140+
@rm -f $(IDF_MODIFIED_DIR)/vfs/*.o
141+
@rm -f $(IDF_MODIFIED_DIR)/wear_levelling/*.o
142+
@rm -f $(IDF_ORIG_DIR)/fatfs/src/*.o
143+
@rm -f $(IDF_ORIG_DIR)/fatfs/src/option/*.o
144+
@rm -f $(IDF_ORIG_DIR)/wear_levelling/*.o
145+
@rm -f $(TARGET)

README.md

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# mkfatfs
2+
Tool to build and unpack [FATFS](https://github.com/jkearins/ESP32_mkfatfs) images.
3+
4+
5+
## Usage
6+
7+
```
8+
9+
mkfatfs {-c <pack_dir>|-u <dest_dir>|-l|-i} [-d <0-5>] [-b <number>]
10+
[-p <number>] [-s <number>] [--] [--version] [-h]
11+
<image_file>
12+
13+
14+
Where:
15+
16+
-c <pack_dir>, --create <pack_dir>
17+
(OR required) create fatfs image from a directory
18+
-- OR --
19+
-u <dest_dir>, --unpack <dest_dir>
20+
(OR required) unpack fatfs image to a directory
21+
-- OR --
22+
-l, --list
23+
(OR required) list files in fatfs image
24+
-- OR --
25+
-i, --visualize
26+
(OR required) visualize fatfs image
27+
28+
29+
-d <0-5>, --debug <0-5>
30+
Debug level. 0 means no debug output.
31+
32+
-b <number>, --block <number>
33+
fs block size, in bytes
34+
35+
-p <number>, --page <number>
36+
fs page size, in bytes
37+
38+
-s <number>, --size <number>
39+
fs image size, in bytes
40+
41+
--, --ignore_rest
42+
Ignores the rest of the labeled arguments following this flag.
43+
44+
--version
45+
Displays version information and exits.
46+
47+
-h, --help
48+
Displays usage information and exits.
49+
50+
<image_file>
51+
(required) fatfs image file
52+
53+
54+
```
55+
## Build
56+
57+
You need gcc (≥4.8) or clang(≥600.0.57), and make. On Windows, use MinGW.
58+
59+
Run:
60+
```bash
61+
$ make dist
62+
```
63+
64+
## License
65+
66+
MIT
67+
68+
## To do
69+
70+
- [ ] Flag -u is not released yet
71+
- [ ] Flag -l is not released yet
72+
- [ ] Flag -i is not released yet
73+
- [ ] Add more debug output and print FATFS debug output
74+
- [ ] Error handling
75+
- [ ] Determine the image size automatically when opening a file
76+
- [ ] Code cleanup

fatfs/FatPartition.cpp

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
// Copyright 2015-2017 Espressif Systems (Shanghai) PTE LTD
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
// http://www.apache.org/licenses/LICENSE-2.0
7+
//
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
14+
#include <cstring> // memset/memcpy
15+
#include "esp_log.h"
16+
#include "FatPartition.h"
17+
18+
static const char *TAG = "FatPartition";
19+
20+
std::vector<uint8_t> g_flashmem;
21+
22+
23+
FatPartition::FatPartition(const esp_partition_t *partition)
24+
{
25+
this->partition = partition;
26+
}
27+
28+
size_t FatPartition::chip_size()
29+
{
30+
return this->partition->size;
31+
}
32+
33+
esp_err_t FatPartition::erase_sector(size_t sector)
34+
{
35+
esp_err_t result = ESP_OK;
36+
result = erase_range(sector * SPI_FLASH_SEC_SIZE, SPI_FLASH_SEC_SIZE);
37+
return result;
38+
}
39+
40+
esp_err_t FatPartition::erase_range(size_t start_address, size_t size)
41+
{
42+
esp_err_t result = ESP_FAIL;
43+
if (g_flashmem.size() >= (start_address + size)) {
44+
result = ESP_OK;
45+
memset(&g_flashmem[0] + start_address, 0xff, size);
46+
}
47+
if (result == ESP_OK) {
48+
//The z portion is a length specifier which says the argument will be size_t in length.
49+
ESP_LOGV(TAG, "erase_range - start_address=0x%08zx, size=0x%08zx, result=0x%08x", start_address, size, result);
50+
} else {
51+
ESP_LOGE(TAG, "erase_range - start_address=0x%08zx, size=0x%08zx, result=0x%08x", start_address, size, result);
52+
}
53+
return result;
54+
}
55+
56+
esp_err_t FatPartition::write(size_t dest_addr, const void *src, size_t size)
57+
{
58+
esp_err_t result = ESP_FAIL;
59+
if (g_flashmem.size() >= (dest_addr + size)) {
60+
result = ESP_OK;
61+
memcpy(&g_flashmem[0] + dest_addr, src, size);
62+
}
63+
return result;
64+
}
65+
66+
esp_err_t FatPartition::read(size_t src_addr, void *dest, size_t size)
67+
{
68+
esp_err_t result = ESP_FAIL;
69+
if (g_flashmem.size() >= (src_addr + size)) {
70+
result = ESP_OK;
71+
memcpy(dest, &g_flashmem[0] + src_addr, size);
72+
}
73+
return result;
74+
}
75+
76+
size_t FatPartition::sector_size()
77+
{
78+
ESP_LOGI(TAG, "%s() returns sector_size=%d", __func__, SPI_FLASH_SEC_SIZE);
79+
return SPI_FLASH_SEC_SIZE;
80+
}
81+
82+
FatPartition::~FatPartition()
83+
{
84+
85+
}

fatfs/FatPartition.h

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#pragma once
2+
3+
#include <vector>
4+
#include "esp_err.h"
5+
#include "esp_partition.h"
6+
#include "Flash_Access.h"
7+
8+
extern std::vector<uint8_t> g_flashmem;
9+
10+
/**
11+
* @brief This class is used to access partition. Class implements Flash_Access interface
12+
*
13+
*/
14+
class FatPartition : public Flash_Access
15+
{
16+
17+
public:
18+
FatPartition(const esp_partition_t *partition);
19+
20+
virtual size_t chip_size();
21+
22+
virtual esp_err_t erase_sector(size_t sector);
23+
virtual esp_err_t erase_range(size_t start_address, size_t size);
24+
25+
virtual esp_err_t write(size_t dest_addr, const void *src, size_t size);
26+
virtual esp_err_t read(size_t src_addr, void *dest, size_t size);
27+
28+
virtual size_t sector_size();
29+
30+
virtual ~FatPartition();
31+
protected:
32+
const esp_partition_t *partition;
33+
34+
};
35+
36+

0 commit comments

Comments
 (0)