Merge pull request #165 from noon92/main

Pull from main
This commit is contained in:
noon92 2025-01-09 14:40:04 +02:00 • committed by GitHub
commit 83f146f70f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 106 additions and 59 deletions

View file

@ -13,7 +13,7 @@ The Luckfox Pico Mini is the postage stamp sized heart of the Femtofox - a compa
- How to order - coming soon
- DIY instructions - coming soon
- [Networking](#networking)
- [USB configuration tool](usbconfig.md)
- [USB configuration tool](usb_config.md)
### Features
* Tiny size (63x54mm for the Kitchen Sink Edition, 65x30mm for the Smol Edition). Roughly equivalent to a Raspberry Pi and Pi Zero.
@ -77,3 +77,6 @@ In Meshtasticd's config.yaml we use GPIO bank 1, and subtract 32 from the pin nu
> [!NOTE]
> The information on this page is given without warranty or guarantee. Links to vendors of products are for informational purposes only.
> Meshtastic® is a registered trademark of Meshtastic LLC. Meshtastic software components are released under various licenses, see GitHub for details. No warranty is provided - use at your own risk.
<!--stackedit_data:
eyJoaXN0b3J5IjpbLTgwNzY2MTI2NV19
-->

View file

@ -27,7 +27,7 @@ ln -sf /usr/share/zoneinfo/UTC /etc/localtime
echo "Installing packages..."
apt update
DEBIAN_FRONTEND=noninteractive apt install -y --option Dpkg::Options::="--force-confold" linux-firmware wireless-tools git python3.10-venv libgpiod-dev libyaml-cpp-dev libbluetooth-dev openssl libssl-dev libulfius-dev liborcania-dev evtest screen avahi-daemon protobuf-compiler telnet fonts-noto-color-emoji ninja-build chrony qrencode
DEBIAN_FRONTEND=noninteractive apt install -y --option Dpkg::Options::="--force-confold" linux-firmware wireless-tools git python3.10-venv libgpiod-dev libyaml-cpp-dev libbluetooth-dev openssl libssl-dev libulfius-dev liborcania-dev evtest screen avahi-daemon protobuf-compiler telnet fonts-noto-color-emoji ninja-build chrony qrencode software-properties-common python-is-python3 python3.10-venv
if [[ $? -eq 2 ]]; then echo "Error, step failed..."; fi
DEBIAN_FRONTEND=noninteractive apt upgrade -y --option Dpkg::Options::="--force-confold"
@ -37,7 +37,7 @@ DEBIAN_FRONTEND=noninteractive apt install -y --option Dpkg::Options::="--force-
echo "Installing dependencies for meshing-around and meshtastic cli..."
#pip config set global.extra-index-url https://www.piwheels.org/simple
pip3 install requests pyephem pytap2 meshtastic pypubsub geopy maidenhead beautifulsoup4 dadjokes schedule wikipedia googlesearch-python
if [[ $? -eq 2 ]]; then echo "Error, step failed..."; fi
@ -93,4 +93,4 @@ usermod -a -G dialout femto
echo "Cleaning up chroot..."
apt clean && rm -rf /var/lib/apt/lists/* && rm -rf /tmp/* && rm -rf /var/tmp/* && find /var/log -type f -exec truncate -s 0 {} + && : > /root/.bash_history && history -c
exit
exit

View file

@ -2,7 +2,6 @@
################ TODO ################
# Add more error handling
# Address potential issues in comments
# Package selection with curses
# Switch chroot packages install
# Modify DTS etc to enable SPI1
@ -39,18 +38,10 @@ install_prerequisites() {
apt install -y git ssh make gcc gcc-multilib g++-multilib module-assistant expect g++ gawk texinfo libssl-dev bison flex fakeroot cmake unzip gperf autoconf device-tree-compiler libncurses5-dev pkg-config bc python-is-python3 passwd openssl openssh-server openssh-client vim file cpio rsync qemu-user-static binfmt-support dialog
}
#clone_repos() {
# echo "Cloning repos..."
# cd /home/${sudoer}/
# git clone https://github.com/LuckfoxTECH/luckfox-pico.git
# git clone https://github.com/noon92/femtofox.git
#}
clone_repos() {
echo "Cloning repos..."
cd /home/${sudoer}/ || return 1 # Ensure we successfully change the directory
cd /home/${sudoer}/ || return 1
# Helper function to retry cloning a repo
clone_with_retries() {
local repo_url="$1"
local retries=3
@ -70,11 +61,10 @@ clone_repos() {
fi
}
# Clone both repos
clone_with_retries "https://github.com/LuckfoxTECH/luckfox-pico.git" || return 1
clone_with_retries "https://github.com/noon92/femtofox.git" || return 1
return 0 # Indicate success if all repos cloned
return 0
}
build_env() {
@ -108,20 +98,17 @@ sync_foxbuntu_changes() {
SOURCE_DIR=/home/${sudoer}/femtofox/foxbuntu
DEST_DIR=/home/${sudoer}/luckfox-pico
# Ensure the source is updated
cd "$SOURCE_DIR" || exit
git pull
# Get a list of all Git-tracked files in the source
cd "$SOURCE_DIR" || exit
git ls-files > /tmp/source_files.txt
echo "Merging in Foxbuntu modifications..."
rsync -aHAXv --progress --keep-dirlinks --itemize-changes /home/${sudoer}/femtofox/foxbuntu/sysdrv/ /home/${sudoer}/luckfox-pico/sysdrv/
rsync -aHAXv --progress --keep-dirlinks --itemize-changes /home/${sudoer}/femtofox/foxbuntu/project/ /home/${sudoer}/luckfox-pico/project/
rsync -aHAXv --progress --keep-dirlinks --itemize-changes /home/${sudoer}/femtofox/foxbuntu/output/image/ /home/${sudoer}/luckfox-pico/output/image/
# Remove files in the destination that are no longer in the source repository
rsync -aHAXv --progress --keep-dirlinks --itemize-changes /home/${sudoer}/femtofox/foxbuntu/output/image/ /home/${sudoer}/luckfox-pico/output/image/
while read -r file; do
src_file="$SOURCE_DIR/$file"
dest_file="$DEST_DIR/$file"
@ -132,10 +119,9 @@ sync_foxbuntu_changes() {
fi
done < /tmp/source_files.txt
# Clean up
rm /tmp/source_files.txt
echo "Synchronization complete."
echo "Synchronization complete."
}
build_kernelconfig() {
@ -199,6 +185,29 @@ modify_chroot() {
create_image
}
rebuild_chroot() {
chroot_script=${CHROOT_SCRIPT:-/home/${sudoer}/femtofox/environment-setup/femtofox.chroot}
if [[ ! -f $chroot_script ]]; then
echo "Error: Chroot script $chroot_script not found."
exit 1
fi
echo "Press any key to wipe and rebuild chroot..."
read -n 1 -s -r
cd /home/${sudoer}/luckfox-pico
./build.sh clean rootfs
cd /home/${sudoer}/
rsync -aHAXv --progress --keep-dirlinks --itemize-changes /home/${sudoer}/femtofox/foxbuntu/sysdrv/ /home/${sudoer}/luckfox-pico/sysdrv/
rsync -aHAXv --progress --keep-dirlinks --itemize-changes /home/${sudoer}/femtofox/foxbuntu/project/ /home/${sudoer}/luckfox-pico/project/
build_rootfs
rsync -aHAXv --progress --keep-dirlinks --itemize-changes /home/${sudoer}/femtofox/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/ /home/${sudoer}/luckfox-pico/sysdrv/out/rootfs_uclibc_rv1106/
build_firmware
install_rootfs
build_rootfs
build_firmware
create_image
}
inject_chroot() {
chroot_script=${CHROOT_SCRIPT:-/home/${sudoer}/femtofox/environment-setup/femtofox.chroot}
if [[ ! -f $chroot_script ]]; then
@ -227,10 +236,11 @@ inject_chroot() {
build_rootfs
build_firmware
create_image
}
update_image() {
build_env
echo "Updating repo..."
cd /home/${sudoer}/femtofox
git pull
@ -265,9 +275,7 @@ install_rootfs() {
mount --bind /sys /home/${sudoer}/luckfox-pico/sysdrv/out/rootfs_uclibc_rv1106/sys
mount --bind /dev /home/${sudoer}/luckfox-pico/sysdrv/out/rootfs_uclibc_rv1106/dev
mount --bind /dev/pts /home/${sudoer}/luckfox-pico/sysdrv/out/rootfs_uclibc_rv1106/dev/pts
chroot /home/${sudoer}/luckfox-pico/sysdrv/out/rootfs_uclibc_rv1106 /tmp/chroot_script.sh
umount /home/${sudoer}/luckfox-pico/sysdrv/out/rootfs_uclibc_rv1106/dev/pts
umount /home/${sudoer}/luckfox-pico/sysdrv/out/rootfs_uclibc_rv1106/proc
umount /home/${sudoer}/luckfox-pico/sysdrv/out/rootfs_uclibc_rv1106/sys
@ -302,7 +310,6 @@ create_image() {
sdk_install() {
echo "Installing Foxbuntu SDK Disk Image Builder..."
# get the luckfox build environment
if [ -d /home/${sudoer}/femtofox ]; then
echo "WARNING: ~/femtofox exists, this script will DESTROY and recreate it."
echo "Press Ctrl+C to cancel, or Enter to continue."
@ -348,13 +355,24 @@ usage() {
echo "To install the development environment use the arg 'sdk_install' and is intended to be run ONCE only."
echo "To modify the chroot and build an updated image use the arg 'modify_chroot'."
echo "To modify the kernel and build an updated image use the arg 'modify_kernel'."
echo "other args: build_env sync_foxbuntu_changes build_kernelconfig install_rootfs build_rootfs build_uboot build_firmware create_image"
echo "To specify a custom chroot script use the arg '--chroot-script /full/path/to/custom.chroot'"
echo "other args: rebuild_chroot inject_chroot build_env sync_foxbuntu_changes build_kernelconfig install_rootfs build_rootfs build_uboot build_firmware create_image"
echo "Example: sudo ~/foxbunto_env_setup.sh sdk_install"
echo "Example: sudo ~/foxbunto_env_setup.sh modify_chroot"
echo "Example: sudo ~/foxbunto_env_setup.sh --chroot-script /home/user/custom.chroot"
exit 0
}
################### MENU SYSTEM ###################
if [[ "${1}" == "--chroot-script" ]]; then
CHROOT_SCRIPT=${2}
echo "CHROOT_SCRIPT is set to '${CHROOT_SCRIPT}'"
echo "Press any key to continue..."
read -n 1 -s -r
shift 2 # Remove --chroot-script and its argument from the arguments list
fi
if [[ "${1}" =~ ^(-h|--help|h|help)$ ]]; then
usage
elif [[ -z ${1} ]]; then
@ -370,16 +388,15 @@ elif [[ -z ${1} ]]; then
1 "Get Image Updates" \
2 "Modify Kernel Menu" \
3 "Enter and Modify Chroot" \
4 "Inject Chroot Script" \
5 "Manual Build Environment" \
6 "Manual Build U-Boot" \
7 "Manual Build RootFS" \
8 "Manual Build Firmware" \
9 "Manual Create Final Image" \
"" "" \
10 "SDK Install (Run this first.)" \
"" "" \
11 "Exit" \
4 "Rebuild Chroot" \
5 "Inject Chroot Script (CAUTION)" \
6 "Manual Build Environment" \
7 "Manual Build U-Boot" \
8 "Manual Build RootFS" \
9 "Manual Build Firmware" \
10 "Manual Create Final Image" \
11 "SDK Install (Run this first.)" \
12 "Exit" \
2>&1 >/dev/tty)
clear
@ -388,25 +405,22 @@ elif [[ -z ${1} ]]; then
1) update_image ;;
2) modify_kernel ;;
3) modify_chroot ;;
4) inject_chroot ;;
5) build_env ;;
6) build_uboot ;;
7) build_rootfs ;;
8) build_firmware ;;
9) create_image ;;
10) sdk_install ;;
11) echo "Exiting..."; break ;;
4) rebuild_chroot ;;
5) inject_chroot ;;
6) build_env ;;
7) build_uboot ;;
8) build_rootfs ;;
9) build_firmware ;;
10) create_image ;;
11) sdk_install ;;
12) echo "Exiting..."; break ;;
*) echo "Invalid option, please try again." ;;
esac
# Pause after executing a command
echo "Menu selection completed. Press any key to return to the menu."
read -n 1 -s -r
done
else
if [[ "${1}" == "--chroot-script" ]]; then
CHROOT_SCRIPT=${2}
fi
if declare -f "${1}" > /dev/null; then
"${1}"
else

View file

@ -71,6 +71,14 @@ fi
wpa_supplicant_conf="/etc/wpa_supplicant/wpa_supplicant.conf"
usb_config="/tmp/femtofox-config.txt"
# Check if the mounted USB drive contains a file femtofox-config.log
if [ -f "$mount_point/femtofox-config.log" ]; then
log_message "femtofox-config.log found on USB drive."
log_exists=true
else
log_exists=false
fi
# Check if the mounted USB drive contains a file femtofox-config.txt
if [ -f "$mount_point/femtofox-config.txt" ]; then
log_message "femtofox-config.txt found on USB drive."
@ -87,9 +95,14 @@ if [ -f "$mount_point/femtofox-config.txt" ]; then
update_wifi="false"
wifi_command="femto-network-config.sh"
meshtastic_security_command="femto-meshtasticd-config.sh"
dont_run_if_log_exists=""
# Escape and read the fields from the USB config file if they exist
while IFS='=' read -r key value; do
# Skip lines starting with #
if [[ "$key" =~ ^# ]]; then
continue
fi
value=$(echo "$value" | tr -d '"')
case "$key" in
wifi_ssid) wifi_ssid=$(escape_sed "$value") ;;
@ -100,9 +113,18 @@ if [ -f "$mount_point/femtofox-config.txt" ]; then
meshtastic_url) meshtastic_url=$(escape_sed "$value") ;;
meshtastic_legacy_admin) meshtastic_legacy_admin=$(escape_sed "$value") ;;
meshtastic_admin_key) meshtastic_admin_key=$(escape_sed "$value") ;;
dont_run_if_log_exists) dont_run_if_log_exists=$(escape_sed "$value") ;;
esac
done < <(grep -E '^(wifi_ssid|wifi_psk|wifi_country|meshtastic_lora_radio|timezone|meshtastic_url|meshtastic_legacy_admin|meshtastic_admin_key)=' "$usb_config")
done < <(grep -E '^(wifi_ssid|wifi_psk|wifi_country|meshtastic_lora_radio|timezone|meshtastic_url|meshtastic_legacy_admin|meshtastic_admin_key|dont_run_if_log_exists)=' "$usb_config")
# Check if the log exits and if the dont_run_if_log_exists line is set in the script
if $log_exists && [[ $dont_run_if_log_exists = "true" ]]; then
log_message "\`dont_run_if_log_exists\` is set to \"true\" and log exists, ignoring."
for _ in {1..2}; do #boot code
blink "1.5" && sleep 0.5
done
exit_script 1
fi
# Update wpa_supplicant.conf with the new values, if specified
if [[ -n "$wifi_country" ]]; then

View file

@ -17,6 +17,12 @@ get_mobile_wifi_state() {
set_mobile_wifi_state() {
local state="$1"
local meshtastic_output
if [[ "$(meshtastic --host 127.0.0.1 --get network.wifi_enabled 2>&1 | grep -i refused)" ]] || [[ ! "$(meshtastic --host 127.0.0.1 --get network.wifi_enabled)" ]]; then
log "Error connecting to MeshtasticD. Aborting."
exit 2
fi
if [[ "$state" == "up" ]]; then
meshtastic_output=$(meshtastic --host 127.0.0.1 --set network.wifi_enabled true 2>&1)
else

View file

@ -1,6 +1,6 @@
## USB Configuration Tool
To configure some Femtofox settings such as wifi, you can insert a USB flash drive containing a configuration file. The system will automatically recognize, mount and implement the settings you specify.
To configure some Femtofox settings such as wifi, you can insert a USB flash drive containing a configuration file. On boot, the system will automatically recognize, mount and implement the settings you specify. The tool can also be run from the `femto-config` tool, in the `Utilities` menu.
Configurable settings are:
- Wifi SSID
@ -27,11 +27,12 @@ meshtastic_lora_radio="ebyte-e22-900m30s"
meshtastic_url="https://meshtastic.org/e/#CgMSAQESCAgBOAFAA0gB"
meshtastic_admin_key="T/b8EGvi/Nqi6GyGefJt/jOQr+5uWHHZuBavkNcUwWQ="
meshtastic_legacy_admin="true"
dont_run_if_log_exists="true"
```
> [!NOTE]
> Enter as many or as few settings as you like.
>
> For `wifi_country`, insert your country's two letter code (such as US or IN) in capital letters.
> For `wifi_country`, insert your country's [ISO/IEC alpha2 two letter country code](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2#Officially_assigned_code_elements) (such as US, GB, DE, IN, etc.) in capital letters.
>
> Use a timezone as it appears in [the tz database](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones).
>
@ -52,8 +53,8 @@ meshtastic_legacy_admin="true"
>
> Clearing the `meshtastic_admin_key` list: The admin key list can contain up to three keys - *if more are added they will be ignored*. The USB configuration tool supports clearing the admin key list, after which you will need to re-add your admin key/s in a second operation. To clear the admin key list, enter `meshtastic_admin_key="clear"`.
> [!CAUTION]
> Attempting to set wifi settings via USB configuration tool without a wifi adapter connected will lead to a 5 minute hang while the configuration tool runs - either disconnect and reconnect power or wait the full 5 minutes to to recover.
> [!NOTE]
> `dont_run_if_log_exists="true"` will prevent the USB configuration tool from working if there's a log present on the USB drive, indicating it has already been run. There is also an LED boot code for this, described below.
**To apply your configuration, reboot the Femtofox with the USB drive plugged in. No other USB drives can be plugged in at the same time.**
A log (`femtofox-config.log`) is saved to `/home/femto` and the USB drive (except on NTFS, which is read only).
@ -64,14 +65,15 @@ When the Femtofox is finished booting, it will blink its User LED (see below) in
| LED blink pattern | Meaning | Possible causes | Solutions |
|--|--|--|--|
|<center>⚠️<br>________________<br>1 very long blink, lasting 5 seconds| Failed to mount USB drive. Ignoring.| <li>Invalid filesystem<li>Corrupted partition table<li>Defective USB drive<li>Defective USB OTG adapter | <li>Use a supported partition (FAT32, exFAT, NTFS, ext4)<li>Repair partition table<li>Try another USB drive<li>Try another USB OTG adapter |
|<center>⚠️<br>\_\_\_\_\_&nbsp;&nbsp;\_\_\_\_\_<br>2 long blinks, each lasting 1.5 seconds | femtofox-config.txt is configured to skip if log exists. | USB drive mounted successfully but femtofox-config.txt contains `dont_run_if_log_exists="true"` and a log is present on the USB drive. Ignoring. | Remove log from USB drive or remove `dont_run_if_log_exists` line from femtofox-config.txt |
|<center>⚠️<br>\_\_\_\_\_&nbsp;&nbsp;\_\_\_\_\_&nbsp;&nbsp;\_\_\_\_\_<br>3 long blinks, each lasting 1.5 seconds | USB drive mounted successfully but femtofox-config.txt was not found. Ignoring.| Config file missing. | Create configuration file as described above. |
|<center>⚠️<br>\_\_\_\_\_&nbsp;&nbsp;\_\_\_\_\_&nbsp;&nbsp;\_\_\_\_\_&nbsp;&nbsp;\_\_\_\_\_&nbsp;&nbsp;\_\_\_\_\_<br>5 long blinks, each lasting 1.5 seconds | USB drive mounted successfully and femtofox-config.txt was found but did not contain readable configuration data. Ignoring.| Configuration file improperly formatted or contains no data. | Check configuration file contents as described above. |
|<center>⚠️<br>\_\_\_&nbsp;&nbsp;\_\_\_&nbsp;&nbsp;\_&nbsp;&nbsp;\_&nbsp;&nbsp;\_\_\_&nbsp;&nbsp;\_\_\_&nbsp;&nbsp;\_&nbsp;&nbsp;\_<br>2 long blinks, each lasting 1 seconds, then 2 short blinks, each lasting 1/4 of a second. Repeats twice | Error while trying to implement a Meshtastic setting after 3 attempts. Some settings may have been implemented successfully.| <li>The error may be transient.<li>Configuration file may contain improper data. | <li>Try again.<li>Check configuration file contents as described above.<li>Check the log.<br><br>This pattern may flash before other patterns. The pattern will repeat once for each failed setting.|
|<center>⚠️<br>\_\_\_&nbsp;&nbsp;\_\_\_&nbsp;&nbsp;\_&nbsp;&nbsp;\_&nbsp;&nbsp;\_\_\_&nbsp;&nbsp;\_\_\_&nbsp;&nbsp;\_&nbsp;&nbsp;\_<br>2 long blinks, each lasting 1 second, then 2 short blinks, each lasting 1/4 of a second. Repeats twice | Error while trying to implement a Meshtastic setting after 3 attempts. Some settings may have been implemented successfully.| <li>The error may be transient.<li>Configuration file may contain improper data. | <li>Try again.<li>Check configuration file contents as described above.<li>Check the log.<br><br>This pattern may flash before other patterns. The pattern will repeat once for each failed setting.|
|<center>✅<br>. . . . . . . . . .<br>10 very fast blinks, each lasting 1/8th of a second | USB drive mounted successfully, and femtofox-config.txt was found and contained configuration data which was sent for deployment. Any affected services will now restart. You can disconnect the USB drive. | This does not mean that the information in the config file is correct - only that it was readable.<br>Note that the "success" boot code will flash if at least one setting is successfully read - even if the setting was not implemented successfully.|
|<center>✅<br>\_\_&nbsp;&nbsp;\_\_&nbsp;&nbsp;\_\_&nbsp;&nbsp;\_\_&nbsp;&nbsp;\_\_<br>5 medium blinks, each lasting 0.5 seconds | Boot complete. Appears on every successful boot and always appears last.| | |
> [!NOTE]
> Boot codes can appear in sequence - for example: one long (4 second) blink, followed by 5 medium (half second) blinks means the USB drive failed to mount, and that the boot sequence is complete.
<!--stackedit_data:
eyJoaXN0b3J5IjpbLTE3MTQ4NTcxNTddfQ==
eyJoaXN0b3J5IjpbLTE3MzAwMTU5Nl19
-->