Skip to content

Commit

Permalink
Scripts to expose the Trussed store via FUSE
Browse files Browse the repository at this point in the history
  • Loading branch information
nickray committed Feb 26, 2021
1 parent 8cc33a9 commit fe27e01
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ solo-bee.code-workspace
ref/
memory.x
solo-state.bin
bee.littlefs2
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,8 @@ bacon:
run-dev:
make -C $(RUNNER) run-dev

mount-fs:
scripts/fuse-bee

umount-fs:
scripts/defuse-bee
10 changes: 10 additions & 0 deletions scripts/defuse-bee
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/bash -xe

# load variable
state=/tmp/bee-mount.state
source ${state}

# unmount
umount ${mount}
sudo losetup -d ${loop_device}
rm ${state}
49 changes: 49 additions & 0 deletions scripts/fuse-bee
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/usr/bin/bash -xe

# Prerequisites:
#
# - lpc55: install via `cargo install lpc55-host`
# - lfs: install via `yay -S littlefs2-fuse`
# - the bee needs to be in ROM bootloader
# - the mountpoint has to exist

fs=./bee.littlefs2
fs_offset=$((512 * 1024)) # 512K, start of 3rd PRINCE section
expected_fs_size=$((239 * 512)) # 119.5K, or 239 flash pages
mount=/mnt/bee
state=/tmp/bee-mount.state

# check no previous mount
if test -f $state; then
set +x
echo
echo "File ${state} exists, this may indicate a mount already exists."
echo "Clean up (scripts/defuse-bee), then try again."
echo
exit 1
fi

if [[ ! -d $mount ]]; then
set +x
echo
echo "Mountpoint ${mount} does not exist."
echo "Create it and make it user accessible (chown ${USER} ${mount})."
echo
exit 1
fi

# fetch the FS dump
lpc55 read-memory --output-file ${fs} ${fs_offset} ${expected_fs_size}
fs_size=$(stat -c%s ${fs})
if (( ${fs_size} != ${expected_fs_size} )); then
exit 1
fi

# mount it
sudo modprobe loop
loop_device=$(sudo losetup --find --show ${fs}) # block size default is our 512B
sudo chmod a+rw ${loop_device}
# mkdir -p ${mount}
lfs ${loop_device} ${mount}
printf "loop_device=${loop_device}\nmount=${mount}" > ${state}
tree -h ${mount}

0 comments on commit fe27e01

Please sign in to comment.