Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d83a151

Browse files
committed
Merge branch 'feature/update_spiffs' into 'master'
Update SPIFFS See merge request sdk/ESP8266_RTOS_SDK!842
2 parents a2cef19 + f6335d9 commit d83a151

Some content is hidden

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

63 files changed

+11413
-975
lines changed

components/bootloader_support/src/flash_partitions.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ esp_err_t esp_partition_table_basic_verify(const esp_partition_info_t *partition
109109
{
110110
int md5_found = 0;
111111
int num_parts;
112-
uint32_t chip_size = flashchip.chip_size;
112+
uint32_t chip_size = g_rom_flashchip.chip_size;
113113
*num_partitions = 0;
114114

115115
for (num_parts = 0; num_parts < ESP_PARTITION_TABLE_MAX_ENTRIES; num_parts++) {

components/esp8266/include/esp8266/rom_functions.h

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@
66

77
#define ROM_FLASH_BUF_DECLARE(__name, __size) uint8_t __name[__size] __attribute__((aligned(4)))
88

9-
typedef struct esp_spi_flash_chip {
10-
uint32_t deviceId;
11-
uint32_t chip_size; // chip size in byte
12-
uint32_t block_size;
13-
uint32_t sector_size;
14-
uint32_t page_size;
15-
uint32_t status_mask;
16-
} esp_spi_flash_chip_t;
9+
typedef struct {
10+
uint32_t device_id;
11+
uint32_t chip_size; // chip size in bytes
12+
uint32_t block_size;
13+
uint32_t sector_size;
14+
uint32_t page_size;
15+
uint32_t status_mask;
16+
} esp_rom_spiflash_chip_t;
1717

18-
extern esp_spi_flash_chip_t flashchip;
18+
extern esp_rom_spiflash_chip_t g_rom_flashchip;
1919

2020
uint32_t Wait_SPI_Idle();
2121

@@ -27,13 +27,13 @@ void system_soft_wdt_feed();
2727

2828
void Cache_Read_Enable_New();
2929

30-
int SPI_page_program(esp_spi_flash_chip_t *chip, uint32_t dst_addr, void *pbuf, uint32_t len);
31-
int SPI_read_data(esp_spi_flash_chip_t *chip, uint32_t dst_addr, void *pbuf, uint32_t len);
32-
int SPI_write_enable(esp_spi_flash_chip_t *chip);
33-
int SPI_sector_erase(esp_spi_flash_chip_t *chip, uint32_t sect_addr);
34-
int SPI_write_status(esp_spi_flash_chip_t *chip, uint32_t status);
35-
int SPI_read_status(esp_spi_flash_chip_t *chip, uint32_t *status);
36-
int Enable_QMode(esp_spi_flash_chip_t *chip);
30+
int SPI_page_program(esp_rom_spiflash_chip_t *chip, uint32_t dst_addr, void *pbuf, uint32_t len);
31+
int SPI_read_data(esp_rom_spiflash_chip_t *chip, uint32_t dst_addr, void *pbuf, uint32_t len);
32+
int SPI_write_enable(esp_rom_spiflash_chip_t *chip);
33+
int SPI_sector_erase(esp_rom_spiflash_chip_t *chip, uint32_t sect_addr);
34+
int SPI_write_status(esp_rom_spiflash_chip_t *chip, uint32_t status);
35+
int SPI_read_status(esp_rom_spiflash_chip_t *chip, uint32_t *status);
36+
int Enable_QMode(esp_rom_spiflash_chip_t *chip);
3737

3838
int SPIWrite(uint32_t addr, const uint8_t *src, uint32_t size);
3939
int SPIRead(uint32_t addr, void *dst, uint32_t size);

components/esp8266/include/esp_libc.h

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include <stddef.h>
3030
#include <stdio.h>
3131
#include <stdarg.h>
32+
#include "rom/ets_sys.h"
3233
#ifndef BOOTLOADER_BUILD
3334
#include "esp_heap_caps.h"
3435
#endif
@@ -60,18 +61,6 @@ int ets_putc(int c);
6061
*/
6162
int ets_vprintf(const char *fmt, va_list ap);
6263

63-
/**
64-
* @brief Printf the strings to uart or other devices, similar with printf, simple than printf.
65-
* Can not print float point data format, or longlong data format.
66-
*
67-
* @param const char *fmt : See printf.
68-
*
69-
* @param ... : See printf.
70-
*
71-
* @return int : the length printed to the output device.
72-
*/
73-
int ets_printf(const char *fmt, ...);
74-
7564
#ifndef os_printf
7665
#define os_printf printf
7766
#endif

components/esp8266/include/rom/ets_sys.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,18 @@ void os_delay_us(uint16_t us);
109109
*/
110110
void ets_delay_us(uint32_t us);
111111

112+
/**
113+
* @brief Printf the strings to uart or other devices, similar with printf, simple than printf.
114+
* Can not print float point data format, or longlong data format.
115+
*
116+
* @param const char *fmt : See printf.
117+
*
118+
* @param ... : See printf.
119+
*
120+
* @return int : the length printed to the output device.
121+
*/
122+
int ets_printf(const char *fmt, ...);
123+
112124
/**
113125
* @brief Register the print output function.
114126
*
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright 2010-2016 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+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#ifndef _ROM_SPI_FLASH_H_
16+
#define _ROM_SPI_FLASH_H_
17+
18+
#include <stdint.h>
19+
#include <stdbool.h>
20+
21+
#include "esp_attr.h"
22+
23+
#include "esp8266/rom_functions.h"
24+
25+
#endif /* _ROM_SPI_FLASH_H_ */

components/spi_flash/include/priv/esp_spi_flash_raw.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,21 +48,21 @@ typedef struct {
4848
uint8_t dummy_bits;
4949
} spi_cmd_t;
5050

51-
bool spi_user_cmd_raw(esp_spi_flash_chip_t *chip, spi_cmd_dir_t mode, spi_cmd_t *p_cmd);
51+
bool spi_user_cmd_raw(esp_rom_spiflash_chip_t *chip, spi_cmd_dir_t mode, spi_cmd_t *p_cmd);
5252

53-
uint32_t spi_flash_get_id_raw(esp_spi_flash_chip_t *chip);
53+
uint32_t spi_flash_get_id_raw(esp_rom_spiflash_chip_t *chip);
5454

55-
esp_err_t spi_flash_enable_qmode_raw(esp_spi_flash_chip_t *chip);
55+
esp_err_t spi_flash_enable_qmode_raw(esp_rom_spiflash_chip_t *chip);
5656

57-
esp_err_t spi_flash_read_status_raw(esp_spi_flash_chip_t *chip, uint32_t *status);
57+
esp_err_t spi_flash_read_status_raw(esp_rom_spiflash_chip_t *chip, uint32_t *status);
5858

59-
esp_err_t spi_flash_write_status_raw(esp_spi_flash_chip_t *chip, uint32_t status_value);
59+
esp_err_t spi_flash_write_status_raw(esp_rom_spiflash_chip_t *chip, uint32_t status_value);
6060

61-
esp_err_t spi_flash_read_raw(esp_spi_flash_chip_t *chip, size_t src_addr, void *dest, size_t size);
61+
esp_err_t spi_flash_read_raw(esp_rom_spiflash_chip_t *chip, size_t src_addr, void *dest, size_t size);
6262

63-
esp_err_t spi_flash_write_raw(esp_spi_flash_chip_t *chip, size_t dest_addr, const void *src, size_t size);
63+
esp_err_t spi_flash_write_raw(esp_rom_spiflash_chip_t *chip, size_t dest_addr, const void *src, size_t size);
6464

65-
esp_err_t spi_flash_erase_sector_raw(esp_spi_flash_chip_t *chip, size_t sec, size_t sec_size);
65+
esp_err_t spi_flash_erase_sector_raw(esp_rom_spiflash_chip_t *chip, size_t sec, size_t sec_size);
6666

6767
void spi_flash_switch_to_qio_raw(void);
6868

components/spi_flash/port/port.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ static uint32_t s_v2_flash_bin_size;
6969
static uint32_t s_v2_flash_size;
7070
static sys_param_t s_sys_param;
7171
static boot_param_t s_boot_param;
72-
static esp_spi_flash_chip_t s_flash_chip = {
72+
static esp_rom_spiflash_chip_t s_flash_chip = {
7373
0x1640ef,
7474
CONFIG_SPI_FLASH_SIZE,
7575
64 * 1024,

components/spi_flash/src/spi_flash.c

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
extern void vPortEnterCritical(void);
6565
extern void vPortExitCritical(void);
6666

67-
esp_spi_flash_chip_t flashchip = {
67+
esp_rom_spiflash_chip_t g_rom_flashchip = {
6868
0x1640ef,
6969
CONFIG_SPI_FLASH_SIZE,
7070
64 * 1024,
@@ -89,7 +89,7 @@ bool spi_user_cmd(spi_cmd_dir_t mode, spi_cmd_t *p_cmd)
8989
FLASH_INTR_LOCK(c_tmp);
9090
FlashIsOnGoing = 1;
9191

92-
ret = spi_user_cmd_raw(&flashchip, mode, p_cmd);
92+
ret = spi_user_cmd_raw(&g_rom_flashchip, mode, p_cmd);
9393

9494
FlashIsOnGoing = 0;
9595
FLASH_INTR_UNLOCK(c_tmp);
@@ -174,7 +174,7 @@ uint32_t spi_flash_get_id(void)
174174

175175
FlashIsOnGoing = 1;
176176

177-
rdid = spi_flash_get_id_raw(&flashchip);
177+
rdid = spi_flash_get_id_raw(&g_rom_flashchip);
178178

179179
FlashIsOnGoing = 0;
180180

@@ -192,7 +192,7 @@ esp_err_t spi_flash_read_status(uint32_t *status)
192192

193193
FlashIsOnGoing = 1;
194194

195-
ret = spi_flash_read_status_raw(&flashchip, status);
195+
ret = spi_flash_read_status_raw(&g_rom_flashchip, status);
196196

197197
FlashIsOnGoing = 0;
198198

@@ -209,7 +209,7 @@ esp_err_t spi_flash_write_status(uint32_t status_value)
209209

210210
FlashIsOnGoing = 1;
211211

212-
spi_flash_write_status_raw(&flashchip, status_value);
212+
spi_flash_write_status_raw(&g_rom_flashchip, status_value);
213213

214214
FlashIsOnGoing = 0;
215215

@@ -436,7 +436,7 @@ void user_spi_flash_dio_to_qio_pre_init(void)
436436
}
437437
//ENBALE FLASH QIO 0X01H+0X00+0X02
438438
} else {
439-
if (spi_flash_enable_qmode_raw(&flashchip) == ESP_OK) {
439+
if (spi_flash_enable_qmode_raw(&g_rom_flashchip) == ESP_OK) {
440440
to_qio = true;
441441
}
442442
}
@@ -452,7 +452,7 @@ esp_err_t spi_flash_erase_sector(size_t sec)
452452

453453
esp_err_t ret;
454454

455-
if (sec >= (flashchip.chip_size / flashchip.sector_size)) {
455+
if (sec >= (g_rom_flashchip.chip_size / g_rom_flashchip.sector_size)) {
456456
return ESP_ERR_FLASH_OP_FAIL;
457457
}
458458

@@ -463,7 +463,7 @@ esp_err_t spi_flash_erase_sector(size_t sec)
463463
FLASH_INTR_LOCK(c_tmp);
464464
FlashIsOnGoing = 1;
465465

466-
ret = spi_flash_erase_sector_raw(&flashchip, sec, flashchip.sector_size);
466+
ret = spi_flash_erase_sector_raw(&g_rom_flashchip, sec, g_rom_flashchip.sector_size);
467467

468468
FlashIsOnGoing = 0;
469469
FLASH_INTR_UNLOCK(c_tmp);
@@ -477,31 +477,31 @@ static esp_err_t spi_flash_program(uint32_t target, uint32_t *src_addr, size_t l
477477
uint32_t pgm_len, pgm_num;
478478
uint8_t i;
479479

480-
page_size = flashchip.page_size;
480+
page_size = g_rom_flashchip.page_size;
481481
pgm_len = page_size - (target % page_size);
482482

483483
if (len < pgm_len) {
484-
if (ESP_OK != spi_flash_write_raw(&flashchip, target, src_addr, len)) {
484+
if (ESP_OK != spi_flash_write_raw(&g_rom_flashchip, target, src_addr, len)) {
485485
return ESP_ERR_FLASH_OP_FAIL;
486486
}
487487
} else {
488-
if (ESP_OK != spi_flash_write_raw(&flashchip, target, src_addr, pgm_len)) {
488+
if (ESP_OK != spi_flash_write_raw(&g_rom_flashchip, target, src_addr, pgm_len)) {
489489
return ESP_ERR_FLASH_OP_FAIL;
490490
}
491491

492492
//whole page program
493493
pgm_num = (len - pgm_len) / page_size;
494494

495495
for (i = 0; i < pgm_num; i++) {
496-
if (ESP_OK != spi_flash_write_raw(&flashchip, target + pgm_len, src_addr + (pgm_len >> 2), page_size)) {
496+
if (ESP_OK != spi_flash_write_raw(&g_rom_flashchip, target + pgm_len, src_addr + (pgm_len >> 2), page_size)) {
497497
return ESP_ERR_FLASH_OP_FAIL;
498498
}
499499

500500
pgm_len += page_size;
501501
}
502502

503503
//remain parts to program
504-
if (ESP_OK != spi_flash_write_raw(&flashchip, target + pgm_len, src_addr + (pgm_len >> 2), len - pgm_len)) {
504+
if (ESP_OK != spi_flash_write_raw(&g_rom_flashchip, target + pgm_len, src_addr + (pgm_len >> 2), len - pgm_len)) {
505505
return ESP_ERR_FLASH_OP_FAIL;
506506
}
507507
}
@@ -556,7 +556,7 @@ esp_err_t spi_flash_write(size_t dest_addr, const void *src, size_t size)
556556
return ESP_ERR_FLASH_OP_FAIL;
557557
}
558558

559-
if ((dest_addr + size) > flashchip.chip_size) {
559+
if ((dest_addr + size) > g_rom_flashchip.chip_size) {
560560
return ESP_ERR_FLASH_OP_FAIL;
561561
}
562562

@@ -619,7 +619,7 @@ static esp_err_t __spi_flash_read(size_t src_addr, void *dest, size_t size)
619619
FLASH_INTR_LOCK(c_tmp);
620620
FlashIsOnGoing = 1;
621621

622-
ret = spi_flash_read_raw(&flashchip, src_addr, dest, size);
622+
ret = spi_flash_read_raw(&g_rom_flashchip, src_addr, dest, size);
623623

624624
FlashIsOnGoing = 0;
625625
FLASH_INTR_UNLOCK(c_tmp);
@@ -779,5 +779,5 @@ uintptr_t spi_flash_cache2phys(const void *cached)
779779

780780
size_t spi_flash_get_chip_size()
781781
{
782-
return flashchip.chip_size;
782+
return g_rom_flashchip.chip_size;
783783
}

components/spi_flash/src/spi_flash_raw.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ void Cache_Read_Enable_2()
3535
}
3636
void Cache_Read_Enable_New(void) __attribute__((alias("Cache_Read_Enable_2")));
3737

38-
uint32_t spi_flash_get_id_raw(esp_spi_flash_chip_t *chip)
38+
uint32_t spi_flash_get_id_raw(esp_rom_spiflash_chip_t *chip)
3939
{
4040
uint32_t rdid = 0;
4141

@@ -54,7 +54,7 @@ uint32_t spi_flash_get_id_raw(esp_spi_flash_chip_t *chip)
5454
return rdid;
5555
}
5656

57-
esp_err_t spi_flash_read_status_raw(esp_spi_flash_chip_t *chip, uint32_t *status)
57+
esp_err_t spi_flash_read_status_raw(esp_rom_spiflash_chip_t *chip, uint32_t *status)
5858
{
5959
esp_err_t ret;
6060

@@ -67,7 +67,7 @@ esp_err_t spi_flash_read_status_raw(esp_spi_flash_chip_t *chip, uint32_t *status
6767
return ret;
6868
}
6969

70-
esp_err_t spi_flash_write_status_raw(esp_spi_flash_chip_t *chip, uint32_t status_value)
70+
esp_err_t spi_flash_write_status_raw(esp_rom_spiflash_chip_t *chip, uint32_t status_value)
7171
{
7272
Cache_Read_Disable_2();
7373

@@ -86,7 +86,7 @@ esp_err_t spi_flash_write_status_raw(esp_spi_flash_chip_t *chip, uint32_t status
8686
return ESP_OK;
8787
}
8888

89-
esp_err_t spi_flash_erase_sector_raw(esp_spi_flash_chip_t *chip, size_t sec, size_t sec_size)
89+
esp_err_t spi_flash_erase_sector_raw(esp_rom_spiflash_chip_t *chip, size_t sec, size_t sec_size)
9090
{
9191
esp_err_t ret = ESP_OK;
9292

@@ -105,7 +105,7 @@ esp_err_t spi_flash_erase_sector_raw(esp_spi_flash_chip_t *chip, size_t sec, siz
105105
return ret;
106106
}
107107

108-
esp_err_t spi_flash_enable_qmode_raw(esp_spi_flash_chip_t *chip)
108+
esp_err_t spi_flash_enable_qmode_raw(esp_rom_spiflash_chip_t *chip)
109109
{
110110
esp_err_t ret;
111111

@@ -120,7 +120,7 @@ esp_err_t spi_flash_enable_qmode_raw(esp_spi_flash_chip_t *chip)
120120
return ret;
121121
}
122122

123-
esp_err_t spi_flash_write_raw(esp_spi_flash_chip_t *chip, size_t dest_addr, const void *src, size_t size)
123+
esp_err_t spi_flash_write_raw(esp_rom_spiflash_chip_t *chip, size_t dest_addr, const void *src, size_t size)
124124
{
125125
esp_err_t ret;
126126

@@ -133,7 +133,7 @@ esp_err_t spi_flash_write_raw(esp_spi_flash_chip_t *chip, size_t dest_addr, cons
133133
return ret;
134134
}
135135

136-
esp_err_t spi_flash_read_raw(esp_spi_flash_chip_t *chip, size_t src_addr, void *dest, size_t size)
136+
esp_err_t spi_flash_read_raw(esp_rom_spiflash_chip_t *chip, size_t src_addr, void *dest, size_t size)
137137
{
138138
esp_err_t ret;
139139

@@ -146,7 +146,7 @@ esp_err_t spi_flash_read_raw(esp_spi_flash_chip_t *chip, size_t src_addr, void *
146146
return ret;
147147
}
148148

149-
bool spi_user_cmd_raw(esp_spi_flash_chip_t *chip, spi_cmd_dir_t mode, spi_cmd_t *p_cmd)
149+
bool spi_user_cmd_raw(esp_rom_spiflash_chip_t *chip, spi_cmd_dir_t mode, spi_cmd_t *p_cmd)
150150
{
151151
int idx = 0;
152152

components/spiffs/CMakeLists.txt

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
1-
set(COMPONENT_ADD_INCLUDEDIRS include include/spiffs)
2-
set(COMPONENT_SRCDIRS library)
1+
if(CONFIG_USING_SPIFFS)
2+
set(COMPONENT_ADD_INCLUDEDIRS "include")
3+
set(COMPONENT_PRIV_INCLUDEDIRS "." "spiffs/src")
4+
set(COMPONENT_SRCS "esp_spiffs.c"
5+
"spiffs_api.c"
6+
"spiffs/src/spiffs_cache.c"
7+
"spiffs/src/spiffs_check.c"
8+
"spiffs/src/spiffs_gc.c"
9+
"spiffs/src/spiffs_hydrogen.c"
10+
"spiffs/src/spiffs_nucleus.c")
11+
endif()
312

4-
set(COMPONENT_REQUIRES freertos)
5-
set(COMPONENT_PRIV_REQUIRES esp8266)
13+
set(COMPONENT_REQUIRES spi_flash)
14+
set(COMPONENT_PRIV_REQUIRES bootloader_support)
615

716
register_component()
17+

0 commit comments

Comments
 (0)