Merge pull request #231 from femtofox/main

Update new-working
This commit is contained in:
noon92 2025-01-21 13:13:55 +02:00 • committed by GitHub
commit bf3dd91089
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
15 changed files with 359 additions and 42 deletions

View file

@ -53,7 +53,12 @@ echo "femtofox" | tee /etc/hostname > /dev/null
echo "Configuring autostart of systemd services..."
systemctl enable button
systemctl enable meshtasticd
systemctl enable femto-runonce.service
systemctl enable femto-usb-config-tool.service
systemctl enable femto-boot-complete.service
systemctl enable wifi-mesh-control
systemctl disable NetworkManager
systemctl disable NetworkManager-dispatcher
systemctl disable NetworkManager-wait-online

View file

@ -4,14 +4,12 @@
#/etc/init.d/S50usbdevice start
#run only on first boot
if [ -e "/etc/.firstboot" ]; then
/usr/local/bin/femto-runonce.sh
fi
#if [ -e "/etc/.firstboot" ]; then
# /usr/local/bin/femto-runonce.sh
#fi
luckfox-config load
systemctl restart meshtasticd #TEMPORARY bugfix
# try enable RTC
echo 'ds1307 0x68' | sudo tee /sys/class/i2c-adapter/i2c-3/new_device > /dev/null 2>&1
@ -25,21 +23,21 @@ echo 34 > /sys/class/gpio/export && echo out > /sys/class/gpio/gpio34/direction
#(sleep 5 && cpufreq-set -u 408000 && echo "Boot complete, setting CPU frequency to 408mhz.") &
# run USB automount and config tool
/usr/local/bin/femto-usb-config-tool.sh
#/usr/local/bin/femto-usb-config-tool.sh
# boot complete
(
echo "Disabling ACT LED..."
echo "none" > /sys/class/leds/work/trigger &
sleep 1
# blink successful boot code
for i in $(seq 1 5); do
echo 1 > /sys/class/gpio/gpio34/value;
sleep 0.5;
echo 0 > /sys/class/gpio/gpio34/value;
sleep 0.5;
done
) &
#(
# echo "Disabling ACT LED..."
# echo "none" > /sys/class/leds/work/trigger &
# sleep 1
#
# # blink successful boot code
# for i in $(seq 1 5); do
# echo 1 > /sys/class/gpio/gpio34/value;
# sleep 0.5;
# echo 0 > /sys/class/gpio/gpio34/value;
# sleep 0.5;
# done
#) &
exit 0

View file

@ -3,7 +3,7 @@
<service-group>
<name>Meshtastic</name>
<service protocol="ipv4">
<type>_meshtastic._tcp</type>
<port>4403</port>
<type>_http._tcp</type>
<port>80</port>
</service>
</service-group>
</service-group>

View file

@ -0,0 +1,14 @@
[Unit]
Description=Boot Complete
After=serial-getty@ttyFIQ0.service
DefaultDependencies=no
[Service]
ExecStart=/usr/local/bin/femto-boot-complete.sh
Type=oneshot
Restart=no
StandardOutput=journal+console
StandardError=journal+console
[Install]
WantedBy=default.target

View file

@ -0,0 +1,16 @@
[Unit]
Description=Foxbuntu First Boot
After=meshtasticd.service
Before=serial-getty@ttyFIQ0.service
DefaultDependencies=no
[Service]
ExecStart=/usr/local/bin/femto-runonce.sh
Type=oneshot
Restart=no
StandardOutput=journal+console
StandardError=journal+console
[Install]
WantedBy=default.target

View file

@ -0,0 +1,16 @@
[Unit]
Description=Foxbuntu USB Configuration Tool
After=meshtasticd.service
Before=serial-getty@ttyFIQ0.service
DefaultDependencies=no
[Service]
ExecStart=/usr/local/bin/femto-usb-config-tool.sh
Type=oneshot
Restart=no
StandardOutput=journal+console
StandardError=journal+console
[Install]
WantedBy=default.target

View file

@ -1,3 +1,9 @@
[Service]
ExecStartPost=/bin/sh -c 'renice -n -20 -p $(pgrep meshtasticd)'
ExecStart=
ExecStart=/bin/sh -c '/usr/sbin/meshtasticd -h $(sed -n "/Serial/ s/^.*: \(.*\)$/\U\1/p" /proc/cpuinfo | bc | tail -c 9)'
Nice=-20
[Unit]
After=rc-local.service
Wants=rc-local.service
After=network-online.target

View file

@ -1,6 +1,7 @@
[Unit]
Description=Meshtastic control of wifi
After=network.target
After=meshtasticd.service
Requires=meshtasticd.service
[Service]
ExecStart=/usr/local/bin/wifi-mesh-control.sh

View file

@ -0,0 +1,15 @@
#!/bin/bash
echo "Boot complete"
echo "Disabling ACT LED..."
echo "none" > /sys/class/leds/work/trigger &
sleep 1
# blink successful boot code
for i in $(seq 1 5); do
echo 1 > /sys/class/gpio/gpio34/value;
sleep 0.5;
echo 0 > /sys/class/gpio/gpio34/value;
sleep 0.5;
done
exit 0

View file

@ -155,7 +155,7 @@ done
if [ "$updated_wifi" = true ]; then
ip link set wlan0 up
systemctl restart wpa_supplicant
#systemctl restart wpa_supplicant
wpa_cli -i wlan0 reconfigure # <-------- add watch for FAIL response, error out
timeout 30s dhclient -v
#timeout 30s dhclient -v
fi

View file

@ -5,13 +5,16 @@ log_message() {
}
if [ ! -e "/etc/.firstboot" ]; then
who | grep -q . || exit 0
# prevents weirdness over tty
export NCURSES_NO_UTF8_ACS=1
export TERM=xterm-256color
export LANG=C.UTF-8
dialog --title "Femtofox run once utility" --yesno "\
This does not appear to be this system's first boot.\n\
Re-running this script will restore RTC support, set the Meshtastic nodeid and eth0 MAC address to be derivative of the CPU serial number, set the Meshtastic wifi status to \`enabled\` and then reboot.\n\
Re-running this script will resize the filesystem to fit the SD card, allocate a swap file, add RTC support, add terminal type to .bashrc, set the eth0 MAC address to be derivative of the CPU serial number and then reboot.\n\
\n\
Re-running this script after first boot should not cause any harm, but may not work as expected.\n\
\n\
@ -21,6 +24,9 @@ Proceed?" 14 60
fi
fi
# Disable LED to prevent boot codes from showing during this boot
echo 34 > /sys/class/gpio/unexport
# Perform filesystem resize
log_message "Resizing filesystem. This can take up to 10 minutes, depending on microSD card size and speed"
sudo resize2fs /dev/mmcblk1p5
@ -28,13 +34,13 @@ fi
sudo resize2fs /dev/mmcblk1p7
# allocate swap file
if [ ! -f /etc/.filesystem_swap ]; then # check if swap file already exists
if [ ! -f /swapfile ]; then # check if swap file already exists
sudo fallocate -l 1G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile > /dev/null
sudo swapon /swapfile > /dev/null
echo '/swapfile none swap sw 0 0' | tee -a /etc/fstab > /dev/null
touch /etc/.filesystem_swap
# touch /etc/.filesystem_swap # no longer used
log_message "Swap file allocated."
else
log_message "Swap file already allocated, skipping."
@ -61,9 +67,7 @@ fi
lines="export NCURSES_NO_UTF8_ACS=1
export TERM=xterm-256color
export LANG=C.UTF-8"
# Check if the lines are already in .bashrc
if ! grep -Fxq "$lines" /home/femto/.bashrc; then
if ! grep -Fxq "$lines" /home/femto/.bashrc; then # Check if the lines are already in .bashrc
echo "$lines" >> /home/femto/.bashrc
echo "Added TERM, LANG and NCURSES_NO_UTF8_ACS to .bashrc"
else
@ -71,16 +75,16 @@ else
fi
# set meshtastic nodeid to derivative of CPU serial number (unique to this board)
seed=$(sed -n '/Serial/ s/^.*: \(.*\)$/\U\1/p' /proc/cpuinfo | bc | tail -c 9)
#seed=$(sed -n '/Serial/ s/^.*: \(.*\)$/\U\1/p' /proc/cpuinfo | bc | tail -c 9)
#seed=$((0x$(awk '/Serial/ {print $3}' /proc/cpuinfo) & 0x3B9AC9FF)) #alternate method for generating seed - not in use
sed -i "s|^ExecStart=/usr/sbin/meshtasticd.*|ExecStart=/usr/sbin/meshtasticd -h $seed|" /usr/lib/systemd/system/meshtasticd.service
log_message "Using Luckfox CPU S/N to generate nodeid for Meshtastic."
systemctl daemon-reload
systemctl enable meshtasticd
systemctl restart meshtasticd
#sed -i "s|^ExecStart=/usr/sbin/meshtasticd.*|ExecStart=/usr/sbin/meshtasticd -h $seed|" /usr/lib/systemd/system/meshtasticd.service
#log_message "Using Luckfox CPU S/N to generate nodeid for Meshtastic."
#systemctl daemon-reload
#systemctl enable meshtasticd
#systemctl restart meshtasticd
# remove first boot flag
rm /etc/.firstboot
log_message "Removing first boot flag and rebooting in 5 seconds..."
sleep 5
reboot
reboot

View file

@ -1,4 +1,11 @@
#!/bin/bash
if [ -e "/etc/.firstboot" ]; then
echo "First boot, skipping USB Configuration Tool."
logger "First boot, skipping USB Configuration Tool."
exit 0
fi
mount_point="/mnt/usb" # Set the mount point
# Function to log to screen, syslog and logfile to be saved to usb drive
@ -8,6 +15,12 @@ log_message() {
echo "$(date +"%Y-%m-%d %H:%M:%S") $1" >> /tmp/femtofox-config.log
}
if [ -e "/etc/.firstboot" ]; then
echo "First boot, skipping USB Configuration Tool."
logger "First boot, skipping USB Configuration Tool."
exit 0
fi
exit_script() {
if [ ! -z "$usb_path" ]; then #if usb path is populated
if ! df -T /mnt/usb 2>/dev/null | grep -qw 'ntfs'; then
@ -146,7 +159,8 @@ if [ -f "$mount_point/femtofox-config.txt" ]; then
if [[ -n "$wifi_psk" ]]; then
# Update the psk in the network block
wifi_command="$wifi_command -p \"$wifi_psk\""
log_message "Updating Wi-Fi PSK in wpa_supplicant.conf to \`$wifi_psk\`."
#log_message "Updating Wi-Fi PSK in wpa_supplicant.conf to \`$wifi_psk\`."
log_message "Updating Wi-Fi PSK in wpa_supplicant.conf to *HIDDEN*."
found_config="true"
update_wifi="true"
fi

View file

@ -67,8 +67,8 @@ monitor_changes() {
while true; do
PID=$(ps -C meshtasticd -o pid= | tr -d ' ')
if [[ -n "$PID" ]] && sudo lsof /dev/spidev0.0 | grep -q "$PID"; then
#if sudo lsof /dev/spidev0.0 | grep -q "meshtasticd"; then
#if [[ -n "$PID" ]] && sudo lsof /dev/spidev0.0 | grep -q "$PID"; then
if [[ -n "$PID" ]] && sudo lsof /dev/spidev0.0 | grep -q "$PID" && [[ -d /sys/class/net/wlan0 ]]; then
local current_mobile_state current_wlan_state
current_mobile_state=$(get_mobile_wifi_state)
current_wlan_state=$(cat /sys/class/net/wlan0/operstate)

View file

@ -0,0 +1,147 @@
// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
/*
* Copyright (c) 2022 Rockchip Electronics Co., Ltd.
*/
/dts-v1/;
#include "rv1106.dtsi"
#include "rv1106-luckfox-pico-ultra-ipc.dtsi"
#include <dt-bindings/input/input.h>
#include <dt-bindings/display/media-bus-format.h>
/ {
model = "Luckfox Pico Ultra W";
compatible = "rockchip,rv1103g-38x38-ipc-v10", "rockchip,rv1106g3";
restart-poweroff {
compatible = "restart-poweroff";
};
sdio_pwrseq: sdio-pwrseq {
compatible = "mmc-pwrseq-simple";
pinctrl-names = "default";
reset-gpios = <&gpio1 RK_PA2 GPIO_ACTIVE_LOW>;
};
wireless_bluetooth: wireless-bluetooth {
compatible = "bluetooth-platdata";
uart_rts_gpios = <&gpio0 RK_PA5 GPIO_ACTIVE_LOW>;
pinctrl-names = "default", "rts_gpio";
pinctrl-0 = <&uart1m0_rtsn>;
pinctrl-1 = <&uart1_gpios>;
BT,wake_gpio = <&gpio0 RK_PA2 GPIO_ACTIVE_HIGH>;
BT,wake_host_irq = <&gpio1 RK_PA2 GPIO_ACTIVE_HIGH>;
status = "okay";
};
};
/**********CRU**********/
//&cru {
// assigned-clocks =
// <&cru PLL_GPLL>, <&cru PLL_CPLL>,
// <&cru ARMCLK>,
// <&cru ACLK_PERI_ROOT>, <&cru HCLK_PERI_ROOT>,
// <&cru PCLK_PERI_ROOT>, <&cru ACLK_BUS_ROOT>,
// <&cru PCLK_TOP_ROOT>, <&cru PCLK_PMU_ROOT>,
// <&cru HCLK_PMU_ROOT>, <&cru CLK_500M_SRC>;
// assigned-clock-rates =
// <1188000000>, <700000000>,
// <1104000000>,
// <400000000>, <200000000>,
// <100000000>, <300000000>,
// <100000000>, <100000000>,
// <200000000>, <700000000>;
//};
/**********NPU**********/
//&npu {
// assigned-clock-rates = <700000000>;
//};
/**********EMMC**********/
&emmc {
bus-width = <8>;
cap-mmc-highspeed;
non-removable;
// mmc-hs200-1_8v;
rockchip,default-sample-phase = <90>;
no-sdio;
no-sd;
memory-region-ecsd = <&mmc_ecsd>;
post-power-on-delay-ms = <0>;
status = "okay";
};
&fiq_debugger {
rockchip,irq-mode-enable = <1>;
status = "okay";
};
/**********SDIO-WIFI**********/
&sdmmc {
max-frequency = <50000000>;
bus-width = <4>;
cap-sd-highspeed;
cap-sdio-irq;
keep-power-in-suspend;
non-removable;
rockchip,default-sample-phase = <90>;
// no-sd;
// no-mmc;
supports-sdio;
mmc-pwrseq = <&sdio_pwrseq>;
pinctrl-names = "default";
pinctrl-0 = <&sdmmc0_clk &sdmmc0_cmd &sdmmc0_bus4 &sdmmc0_det>;
status = "okay";
};
&pinctrl{
sdmmc0{
sdmmc0_det: sdmmc0-det {
rockchip,pins =
/* sdmmc0_det */
<3 RK_PA1 1 &pcfg_pull_down>;
};
};
};
/**********ETH**********/
&gmac {
status = "okay";
};
/**********USB**********/
&usbdrd_dwc3 {
status = "okay";
dr_mode = "host";
#dr_mode = "host";
};
/**********RTC**********/
&rtc {
status = "okay";
};
/**********BT**********/
&uart1 {
status = "okay";
pinctrl-names = "default";
pinctrl-0 = <&uart1m0_xfer &uart1m0_ctsn>;
};
&pinctrl {
wireless-bluetooth {
uart1_gpios: uart1-gpios {
rockchip,pins = <0 RK_PA5 RK_FUNC_GPIO &pcfg_pull_none>;
};
};
};
/**********SPI**********/
&spi0 {
status = "okay";
spidev@0 {
spi-max-frequency = <50000000>;
};
};

View file

@ -0,0 +1,81 @@
// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
/*
* Copyright (c) 2022 Rockchip Electronics Co., Ltd.
*/
/dts-v1/;
#include "rv1106.dtsi"
#include "rv1106-luckfox-pico-ultra-ipc.dtsi"
#include <dt-bindings/input/input.h>
#include <dt-bindings/display/media-bus-format.h>
/ {
model = "Luckfox Pico Ultra";
compatible = "rockchip,rv1103g-38x38-ipc-v10", "rockchip,rv1106g3";
};
/**********CRU**********/
//&cru {
// assigned-clocks =
// <&cru PLL_GPLL>, <&cru PLL_CPLL>,
// <&cru ARMCLK>,
// <&cru ACLK_PERI_ROOT>, <&cru HCLK_PERI_ROOT>,
// <&cru PCLK_PERI_ROOT>, <&cru ACLK_BUS_ROOT>,
// <&cru PCLK_TOP_ROOT>, <&cru PCLK_PMU_ROOT>,
// <&cru HCLK_PMU_ROOT>, <&cru CLK_500M_SRC>;
// assigned-clock-rates =
// <1188000000>, <700000000>,
// <1104000000>,
// <400000000>, <200000000>,
// <100000000>, <300000000>,
// <100000000>, <100000000>,
// <200000000>, <700000000>;
//};
/**********NPU**********/
//&npu {
// assigned-clock-rates = <700000000>;
//};
/**********EMMC**********/
&emmc {
bus-width = <8>;
cap-mmc-highspeed;
non-removable;
// mmc-hs200-1_8v;
rockchip,default-sample-phase = <90>;
no-sdio;
no-sd;
memory-region-ecsd = <&mmc_ecsd>;
post-power-on-delay-ms = <0>;
status = "okay";
};
&fiq_debugger {
rockchip,irq-mode-enable = <1>;
status = "okay";
};
/**********ETH**********/
&gmac {
status = "okay";
};
/**********USB**********/
&usbdrd_dwc3 {
status = "okay";
dr_mode = "host";
};
/**********RTC**********/
&rtc {
status = "okay";
};
/**********SPI**********/
&spi0 {
status = "okay";
spidev@0 {
spi-max-frequency = <50000000>;
};
};