This commit is contained in:
RobinVdB8
2023-11-20 13:58:44 +01:00
7 changed files with 39 additions and 21 deletions

View File

@@ -6,6 +6,7 @@
- [Style Guide](#style-guide)
- [Editor Configuration](#editor-configuration)
- [Commit Messages Conventions](#commit-messages-conventions)
- [Writing File System Data to QSPI Flash](#writing-file-system-data-to-qspi-flash)
- [Documentation](#documentation)
## Used Libs, Compiler and Apps
@@ -52,6 +53,10 @@ Implement access right management
The body of a commit message may be used to explain the what and why of a commit.
## Writing File System Data to QSPI Flash
Please read the [llfs.md](./docs/llfs.md#enabling-the-external-loader-in-stm32cubeide) document for instructions
on how to enable the external loader in STM32CubeIDE.
## Documentation
Documentation is placed in the [docs](docs) folder.
If your part needs documentation (e.g. how to use tcp cmd interface), add a markdown file in the above-mentioned folder.

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 76 KiB

View File

@@ -24,6 +24,7 @@ restricting operations solely to read functions.
- [Reading a file](#reading-a-file)
- [Getting the number of files](#getting-the-number-of-files)
- [Using the POSIX file functions](#using-the-posix-file-functions)
- [Enabling the external loader in STM32CubeIDE](#enabling-the-external-loader-in-stm32cubeide)
## Initialization
Before using the llfs API, or the file related POSIX (fopen, fgetc, ...) functions, the filesystem must be initialized by calling `llfs_init()`.
@@ -161,3 +162,16 @@ The following functions are tested and working, but other functions might also w
- `rewind`
- `fstat`
- `fileno`
## Enabling the external loader in STM32CubeIDE
In order to write the file system data to the QSPI flash, the external loader must be enabled in STM32CubeIDE.
This can be done by opening the debug configuration:
![screenshot of step 1](img/ext_loader_step_1.png)
Then, in the `Debugger` tab:
3. Enable the `External Loader`
4. Click the `Scan` button
5. Select the correct loader: `N25Q128A_STM32F746G-DISCO, 0x90000000 ...`
![screenshot of step 2](img/ext_loader_step_2.png)

View File

@@ -7,7 +7,7 @@ The llfs filesystem is a flat filesystem, meaning that it does not support direc
The mkllfs utilit can be used to generate the `llfs_data.c` file. The `llfs_data.c` file from a directory with files.
A pre-compiled version can be download: [mkllfs.exe](https://github.com/Sani7/2023-Webservices_And_Applications/releases/tag/v0.2.0)
A pre-compiled version can be download: [mkllfs.exe](https://github.com/Sani7/2023-Webservices_And_Applications/releases/tag/v0.2.1)
## Usage
The mkllfs utility can be used as follows:

View File

@@ -1,7 +1,7 @@
/**
* @file main.c
* @brief Converts files to a C file that can be used by llfs (linked list file system).
* @version 0.2.0
* @version 0.2.1
* @author Lorenz C.
*/
@@ -10,7 +10,7 @@
#include <string.h>
#include "tinydir.h"
#define VERSION "0.2.0"
#define VERSION "0.2.1"
#define LLFS_VERSION "0.1.1"
#define MAX_PATH_LEN 256
@@ -125,7 +125,7 @@ int main(int argc, char** argv) {
// Make the last file the root file of the llfs
fprintf(out_file, "\n");
fprintf(out_file, "const struct llfs_data_file *llfs_root = &%s;\n", prev_llfs_name);
fprintf(out_file, "const struct llfs_data_file *llfs_root =%s%s;\n", (strcmp(prev_llfs_name, "NULL") == 0 ? " " : " &"), prev_llfs_name);
// Print the number of files
printf("Successfully converted %d files.\r\n", file_count);

View File

@@ -10,8 +10,8 @@
#include <stdio.h>
#include <string.h>
#define LOGGER_LEVEL_WARN
#include "llfs.h"
#include "log.h"
#include "llfs.h"
/**
* @brief The maximum number of files that can be opened concurrently using the POSIX API
@@ -20,8 +20,8 @@
extern struct llfs_data_file* llfs_root;
const char* TAG = "llfs";
size_t file_count = 0;
FILE* file_table[POSIX_MAX_FILES];
static size_t file_count = 0; // Cache for the number of files in the filesystem
static FILE* file_table[POSIX_MAX_FILES];
static int new_file_table_entry(void);
static int free_file_table_entry(int file_id);
@@ -41,6 +41,14 @@ int8_t llfs_init(void) {
file_table[STDOUT_FILENO] = stdout;
file_table[STDERR_FILENO] = stderr;
// Calculate the number of files in the filesystem and cache it
const struct llfs_data_file* file = llfs_root;
file_count = 0;
while (file != NULL) {
file_count++;
file = file->next;
}
return 0;
}
@@ -57,7 +65,7 @@ size_t llfs_file_list(llfs_file_t* file_list, size_t max_files, char* filter) {
}
// Iterate over all files in the filesystem
while (file != NULL && file_count < max_files) {
while (file != NULL && count < max_files) {
// Filter out files with a filename that does not match the filter
if (filter != NULL) {
if (!file_ext_cmp(file->name, filter)) {
@@ -130,13 +138,6 @@ llfs_file_t* llfs_next_file(void** mem, char* filter) {
}
size_t llfs_file_count(void) {
if (file_count == 0) {
const struct llfs_data_file* file = llfs_root;
while (file != NULL) {
file_count++;
file = file->next;
}
}
return file_count;
}
@@ -218,7 +219,7 @@ int _close(int file_id) {
* @param len
* @return
*/
int _read(int file_id, char* ptr, int len) {
size_t _read(int file_id, char* ptr, int len) {
FILE* stream;
llfs_file_t* llfs_file;
size_t bytes_read;
@@ -256,7 +257,7 @@ int _read(int file_id, char* ptr, int len) {
memcpy(ptr, llfs_file->data + stream->_offset, bytes_read);
stream->_offset += (off_t)bytes_read;
return (int)bytes_read;
return bytes_read;
}
/**
@@ -281,7 +282,7 @@ int isatty(int file) {
* @param dir
* @return
*/
int _lseek(int file, int ptr, int dir) {
off_t _lseek(int file, int ptr, int dir) {
FILE* stream;
if (file == STDIN_FILENO || file == STDOUT_FILENO || file == STDERR_FILENO) {
@@ -310,7 +311,7 @@ int _lseek(int file, int ptr, int dir) {
return -1;
}
return 0;
return stream->_offset;
}
/**
@@ -409,8 +410,6 @@ static FILE* file_id_to_stream(int file_id) {
return file_table[file_id];
}
/**
* @brief Check if a filename ends with a given extension
*