-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #787 from wolfSSL/devin/1740666408-add-fatfs-test-…
…action FATFS improvements, test and Linux example
- Loading branch information
Showing
10 changed files
with
720 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,178 @@ | ||
name: Test FATFS Support | ||
|
||
on: | ||
push: | ||
branches: [ master ] | ||
pull_request: | ||
branches: [ master ] | ||
workflow_dispatch: | ||
|
||
jobs: | ||
get-fatfs: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Set up cache key | ||
id: cache-key | ||
run: echo "CACHE_KEY=ff15a-cache" >> $GITHUB_ENV | ||
|
||
- name: Download FF15a.zip | ||
id: download | ||
run: | | ||
wget http://elm-chan.org/fsw/ff/arc/ff15a.zip -O ff15a.zip | ||
- name: Cache the downloaded ZIP file | ||
uses: actions/cache@v4 | ||
with: | ||
path: ./ff15a.zip | ||
key: ${{ env.CACHE_KEY }} | ||
restore-keys: | | ||
${{ env.CACHE_KEY }} | ||
test-fatfs: | ||
needs: get-fatfs | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
|
||
- name: Checking cache for FATFS | ||
uses: actions/cache@v4 | ||
with: | ||
path: ./ff15a.zip | ||
key: ff15a-cache | ||
fail-on-cache-miss: true | ||
|
||
- name: Install dependencies | ||
run: | | ||
sudo apt-get update | ||
sudo apt-get install -y build-essential autoconf automake libtool pkg-config openssh-server dosfstools | ||
- name: Clone wolfSSL | ||
run: | | ||
cd .. | ||
git clone https://github.com/wolfSSL/wolfssl.git | ||
cd wolfssl | ||
./autogen.sh | ||
- name: Configure and build wolfSSL | ||
run: | | ||
cd ../wolfssl | ||
./configure --enable-wolfssh --enable-intelasm --disable-crl --disable-examples --disable-filesystem CFLAGS="-DNO_WOLFSSL_DIR" | ||
make | ||
sudo make install | ||
sudo ldconfig | ||
- name: Compile FATFS library | ||
run: | | ||
cd ide/Linux-FATFS | ||
unzip ../../ff15a.zip | ||
cp ffconf.h source/ | ||
make | ||
- name: Configure and build wolfSSH with FATFS | ||
run: | | ||
./autogen.sh | ||
export LD_LIBRARY_PATH=$(pwd)/ide/Linux-FATFS | ||
./configure --enable-sftp CFLAGS="-DWOLFSSH_FATFS -Iide/Linux-FATFS/source -DSTDIN_FILENO=0 -DPRINTF=printf" LDFLAGS="-Lide/Linux-FATFS -lfatfs" | ||
make | ||
- name: Create test file | ||
run: | | ||
dd if=/dev/urandom of=test_file.bin bs=1M count=1 | ||
- name: Setup SSH server | ||
run: | | ||
sudo mkdir -p /run/sshd | ||
sudo /usr/sbin/sshd | ||
mkdir -p ~/.ssh | ||
ssh-keygen -t rsa -f ~/.ssh/id_rsa -N "" | ||
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys | ||
chmod 600 ~/.ssh/authorized_keys | ||
echo "Host localhost" > ~/.ssh/config | ||
echo " StrictHostKeyChecking no" >> ~/.ssh/config | ||
echo " UserKnownHostsFile=/dev/null" >> ~/.ssh/config | ||
chmod 600 ~/.ssh/config | ||
- name: Install expect | ||
run: | | ||
sudo apt-get update | ||
sudo apt-get install -y expect | ||
- name: Run wolfsftp client to get file | ||
run: | | ||
# Export the library path | ||
export LD_LIBRARY_PATH=$(pwd)/ide/Linux-FATFS | ||
# Get the full path to the test file | ||
TEST_FILE_PATH=$(pwd)/test_file.bin | ||
# Change to the sftpclient directory | ||
cd examples/sftpclient | ||
# Create the FATFS image file directly in the sftpclient directory | ||
dd if=/dev/zero of=fatfs_image.img bs=1M count=32 | ||
mkdosfs fatfs_image.img | ||
# Create a test user with a known password and add to the same group as the runner | ||
sudo useradd -m testuser | ||
echo "testuser:password123" | sudo chpasswd | ||
sudo usermod -aG $(id -gn) testuser | ||
# Make the test file accessible to testuser | ||
chmod 644 ${TEST_FILE_PATH} | ||
sudo chown testuser:$(id -gn) ${TEST_FILE_PATH} | ||
# Configure SSH server to allow SFTP access | ||
sudo sed -i 's/^#Subsystem\s\+sftp.*/Subsystem sftp \/usr\/lib\/openssh\/sftp-server/' /etc/ssh/sshd_config | ||
sudo service ssh restart || sudo /etc/init.d/ssh restart || sudo /usr/sbin/sshd -t && sudo kill -HUP $(pgrep -f sshd) | ||
# Create expect script to automate the wolfsftp client interaction | ||
cat > /tmp/sftp_test.exp << EOF | ||
#!/usr/bin/expect -f | ||
set timeout 60 | ||
spawn ./wolfsftp -N -h localhost -p 22 -u testuser | ||
expect "Password:" | ||
send "password123\r" | ||
expect "wolfSSH sftp>" | ||
send "get ${TEST_FILE_PATH} test_file.bin\r" | ||
expect "wolfSSH sftp>" | ||
send "exit\r" | ||
expect eof | ||
EOF | ||
chmod +x /tmp/sftp_test.exp | ||
# Run the expect script | ||
/tmp/sftp_test.exp | ||
- name: Verify file in FATFS image | ||
run: | | ||
cd examples/sftpclient | ||
sudo mkdir -p /mnt/fatfs | ||
LOOPDEV=$(sudo losetup -f) | ||
sudo losetup $LOOPDEV fatfs_image.img | ||
sudo mount $LOOPDEV /mnt/fatfs | ||
if [ -f /mnt/fatfs/test_file.bin ]; then | ||
echo "File exists in FATFS image!" | ||
ls -la /mnt/fatfs/ | ||
# Verify file contents match | ||
if cmp -s ../../test_file.bin /mnt/fatfs/test_file.bin; then | ||
echo "File contents match! FATFS test PASSED." | ||
sudo umount /mnt/fatfs | ||
sudo losetup -d $LOOPDEV | ||
exit 0 | ||
else | ||
echo "File contents do not match! FATFS test FAILED." | ||
sudo umount /mnt/fatfs | ||
sudo losetup -d $LOOPDEV | ||
exit 1 | ||
fi | ||
else | ||
echo "File does not exist in FATFS image! FATFS test FAILED." | ||
ls -la /mnt/fatfs/ | ||
sudo umount /mnt/fatfs | ||
sudo losetup -d $LOOPDEV | ||
exit 1 | ||
fi |
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 -Isource | ||
LDFLAGS = -shared | ||
|
||
# Source files | ||
SRCS = source/ff.c source/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,49 @@ | ||
# FATFS Linux Example | ||
|
||
This is a FATFS example that uses a single file on the Linux filesystem as the | ||
FATFS file system. | ||
|
||
## Obtaining FATFS | ||
|
||
You can download the source code from | ||
[The FATFS download site](http://elm-chan.org/fsw/ff/archives.html). Extract it | ||
into this directory. | ||
|
||
The example has been tested against FATFS 0.15a | ||
|
||
## Compiling Library | ||
|
||
First copy the config file into the correct place: | ||
|
||
```sh | ||
cp ffconf.h source/ | ||
``` | ||
|
||
Then 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 | ||
LD_LIBRARY_PATH=ide/Linux-FATFS ./configure --enable-sftp CFLAGS="-DWOLFSSH_FATFS -Iide/Linux-FATFS/source -DSTDIN_FILENO=0 -DPRINTF=printf" LDFLAGS="-Lide/Linux-FATFS -lfatfs" | ||
``` | ||
|
Oops, something went wrong.