forked from wolfSSL/wolfssh
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This allows a file on the Linux filesystem to be used as a FATFS file. It also fixes a bug in `port.h` when opening file on a FATFS filesystem.
- Loading branch information
Showing
13 changed files
with
24,134 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
fatfs_image.img |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Compiler and flags | ||
CC = gcc | ||
CFLAGS = -g -Wall -O2 -fPIC | ||
LDFLAGS = -shared | ||
|
||
# Source files | ||
SRCS = ff.c ffunicode.c fatfs_example.c | ||
|
||
# Object files | ||
OBJS = $(SRCS:.c=.o) | ||
|
||
# Target library | ||
TARGET = libfatfs.so | ||
|
||
all: $(TARGET) | ||
|
||
$(TARGET): $(OBJS) | ||
$(CC) $(LDFLAGS) -o $@ $^ | ||
|
||
%.o: %.c | ||
$(CC) $(CFLAGS) -c $< -o $@ | ||
|
||
clean: | ||
rm -f $(OBJS) $(TARGET) | ||
|
||
.PHONY: all clean |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# FATFS Linux Example | ||
|
||
This is a FATFS example that uses a single file on the Linux filesystem as the | ||
FATFS file system. | ||
|
||
## Compiling Library | ||
|
||
To compile the FATFS library simply run `make`. | ||
|
||
## Setup filesystem | ||
|
||
The single file used for FATFS should be generated using: | ||
|
||
```sh | ||
dd if=/dev/zero of=fatfs_image.img bs=1M count=32 | ||
mkdosfs fatfs_image.img | ||
``` | ||
|
||
Note that this file will need to be local to wherever you execute anything using | ||
the library. | ||
|
||
## Compiling wolfSSH and wolfSSL | ||
|
||
### wolfSSL | ||
|
||
```sh | ||
./configure --enable-wolfssh --enable-intelasm --disable-crl --disable-examples --disable-filesystem CFLAGS="-DNO_WOLFSSL_DIR" | ||
``` | ||
|
||
### wolfSSH | ||
|
||
```sh | ||
export LD_LIBRARY_PATH=ide/Linux-FATFS | ||
./configure --enable-sftp CFLAGS="-DWOLFSSH_FATFS -Iide/Linux-FATFS -DSTDIN_FILENO=0 -DPRINTF=printf -lfatfs" | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,229 @@ | ||
/*-----------------------------------------------------------------------*/ | ||
/* Low level disk I/O module SKELETON for FatFs (C)ChaN, 2019 */ | ||
/*-----------------------------------------------------------------------*/ | ||
/* If a working storage control module is available, it should be */ | ||
/* attached to the FatFs via a glue function rather than modifying it. */ | ||
/* This is an example of glue functions to attach various exsisting */ | ||
/* storage control modules to the FatFs module with a defined API. */ | ||
/*-----------------------------------------------------------------------*/ | ||
|
||
#include "ff.h" /* Obtains integer types */ | ||
#include "diskio.h" /* Declarations of disk functions */ | ||
|
||
/* Definitions of physical drive number for each drive */ | ||
#define DEV_RAM 0 /* Example: Map Ramdisk to physical drive 0 */ | ||
#define DEV_MMC 1 /* Example: Map MMC/SD card to physical drive 1 */ | ||
#define DEV_USB 2 /* Example: Map USB MSD to physical drive 2 */ | ||
|
||
|
||
/*-----------------------------------------------------------------------*/ | ||
/* Get Drive Status */ | ||
/*-----------------------------------------------------------------------*/ | ||
|
||
DSTATUS disk_status ( | ||
BYTE pdrv /* Physical drive nmuber to identify the drive */ | ||
) | ||
{ | ||
DSTATUS stat; | ||
int result; | ||
|
||
switch (pdrv) { | ||
case DEV_RAM : | ||
result = RAM_disk_status(); | ||
|
||
// translate the reslut code here | ||
|
||
return stat; | ||
|
||
case DEV_MMC : | ||
result = MMC_disk_status(); | ||
|
||
// translate the reslut code here | ||
|
||
return stat; | ||
|
||
case DEV_USB : | ||
result = USB_disk_status(); | ||
|
||
// translate the reslut code here | ||
|
||
return stat; | ||
} | ||
return STA_NOINIT; | ||
} | ||
|
||
|
||
|
||
/*-----------------------------------------------------------------------*/ | ||
/* Inidialize a Drive */ | ||
/*-----------------------------------------------------------------------*/ | ||
|
||
DSTATUS disk_initialize ( | ||
BYTE pdrv /* Physical drive nmuber to identify the drive */ | ||
) | ||
{ | ||
DSTATUS stat; | ||
int result; | ||
|
||
switch (pdrv) { | ||
case DEV_RAM : | ||
result = RAM_disk_initialize(); | ||
|
||
// translate the reslut code here | ||
|
||
return stat; | ||
|
||
case DEV_MMC : | ||
result = MMC_disk_initialize(); | ||
|
||
// translate the reslut code here | ||
|
||
return stat; | ||
|
||
case DEV_USB : | ||
result = USB_disk_initialize(); | ||
|
||
// translate the reslut code here | ||
|
||
return stat; | ||
} | ||
return STA_NOINIT; | ||
} | ||
|
||
|
||
|
||
/*-----------------------------------------------------------------------*/ | ||
/* Read Sector(s) */ | ||
/*-----------------------------------------------------------------------*/ | ||
|
||
DRESULT disk_read ( | ||
BYTE pdrv, /* Physical drive nmuber to identify the drive */ | ||
BYTE *buff, /* Data buffer to store read data */ | ||
LBA_t sector, /* Start sector in LBA */ | ||
UINT count /* Number of sectors to read */ | ||
) | ||
{ | ||
DRESULT res; | ||
int result; | ||
|
||
switch (pdrv) { | ||
case DEV_RAM : | ||
// translate the arguments here | ||
|
||
result = RAM_disk_read(buff, sector, count); | ||
|
||
// translate the reslut code here | ||
|
||
return res; | ||
|
||
case DEV_MMC : | ||
// translate the arguments here | ||
|
||
result = MMC_disk_read(buff, sector, count); | ||
|
||
// translate the reslut code here | ||
|
||
return res; | ||
|
||
case DEV_USB : | ||
// translate the arguments here | ||
|
||
result = USB_disk_read(buff, sector, count); | ||
|
||
// translate the reslut code here | ||
|
||
return res; | ||
} | ||
|
||
return RES_PARERR; | ||
} | ||
|
||
|
||
|
||
/*-----------------------------------------------------------------------*/ | ||
/* Write Sector(s) */ | ||
/*-----------------------------------------------------------------------*/ | ||
|
||
#if FF_FS_READONLY == 0 | ||
|
||
DRESULT disk_write ( | ||
BYTE pdrv, /* Physical drive nmuber to identify the drive */ | ||
const BYTE *buff, /* Data to be written */ | ||
LBA_t sector, /* Start sector in LBA */ | ||
UINT count /* Number of sectors to write */ | ||
) | ||
{ | ||
DRESULT res; | ||
int result; | ||
|
||
switch (pdrv) { | ||
case DEV_RAM : | ||
// translate the arguments here | ||
|
||
result = RAM_disk_write(buff, sector, count); | ||
|
||
// translate the reslut code here | ||
|
||
return res; | ||
|
||
case DEV_MMC : | ||
// translate the arguments here | ||
|
||
result = MMC_disk_write(buff, sector, count); | ||
|
||
// translate the reslut code here | ||
|
||
return res; | ||
|
||
case DEV_USB : | ||
// translate the arguments here | ||
|
||
result = USB_disk_write(buff, sector, count); | ||
|
||
// translate the reslut code here | ||
|
||
return res; | ||
} | ||
|
||
return RES_PARERR; | ||
} | ||
|
||
#endif | ||
|
||
|
||
/*-----------------------------------------------------------------------*/ | ||
/* Miscellaneous Functions */ | ||
/*-----------------------------------------------------------------------*/ | ||
|
||
DRESULT disk_ioctl ( | ||
BYTE pdrv, /* Physical drive nmuber (0..) */ | ||
BYTE cmd, /* Control code */ | ||
void *buff /* Buffer to send/receive control data */ | ||
) | ||
{ | ||
DRESULT res; | ||
int result; | ||
|
||
switch (pdrv) { | ||
case DEV_RAM : | ||
|
||
// Process of the command for the RAM drive | ||
|
||
return res; | ||
|
||
case DEV_MMC : | ||
|
||
// Process of the command for the MMC/SD card | ||
|
||
return res; | ||
|
||
case DEV_USB : | ||
|
||
// Process of the command the USB drive | ||
|
||
return res; | ||
} | ||
|
||
return RES_PARERR; | ||
} | ||
|
Oops, something went wrong.