mirror of
https://github.com/sipeed/NanoKVM.git
synced 2026-09-11 00:22:56 -05:00
Add the kvmapp installation package.
This commit is contained in:
91
kvmapp/jpg_stream/S95nanokvm
Executable file
91
kvmapp/jpg_stream/S95nanokvm
Executable file
@@ -0,0 +1,91 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
# nanokvm Rev2.1
|
||||||
|
|
||||||
|
case "$1" in
|
||||||
|
start)
|
||||||
|
echo -n kvm > /boot/hostname.prefix
|
||||||
|
cp /mnt/data/sensor_cfg.ini.LT /mnt/data/sensor_cfg.ini
|
||||||
|
|
||||||
|
str_value=$(cat /sys/class/cvi-base/base_uid | awk '{print $2}')
|
||||||
|
first_uint=$(echo $str_value | cut -d'_' -f1)
|
||||||
|
second_uint=$(echo $str_value | cut -d'_' -f2)
|
||||||
|
result="$first_uint$second_uint"
|
||||||
|
echo $result > /device_key
|
||||||
|
|
||||||
|
# if [ ! -e /etc/kvm/hw ]
|
||||||
|
# then
|
||||||
|
|
||||||
|
# fi
|
||||||
|
|
||||||
|
# echo 504 > /sys/class/gpio/export # pwr led
|
||||||
|
# echo 505 > /sys/class/gpio/export # hdd led
|
||||||
|
# echo 503 > /sys/class/gpio/export # pwr key
|
||||||
|
# echo 507 > /sys/class/gpio/export # rst key
|
||||||
|
|
||||||
|
# echo in > /sys/class/gpio/gpio504/direction # pwr led
|
||||||
|
# echo in > /sys/class/gpio/gpio505/direction # hdd led
|
||||||
|
# echo out > /sys/class/gpio/gpio503/direction # pwr key
|
||||||
|
# echo out > /sys/class/gpio/gpio507/direction # rst key
|
||||||
|
|
||||||
|
iptables -A INPUT -i eth0 -p tcp --dport 80 -m state --state NEW,ESTABLISHED -j ACCEPT
|
||||||
|
iptables -A OUTPUT -o eth0 -p tcp --sport 80 -m state --state ESTABLISHED -j ACCEPT
|
||||||
|
iptables -A OUTPUT -o eth0 -p tcp --dport 22 -m state --state NEW,ESTABLISHED -j ACCEPT
|
||||||
|
iptables -A INPUT -i eth0 -p tcp --sport 22 -m state --state ESTABLISHED -j ACCEPT
|
||||||
|
iptables -A OUTPUT -o eth0 -p tcp --sport 8000 -m state --state ESTABLISHED -j DROP
|
||||||
|
|
||||||
|
cp -r /kvmapp/kvm_system /tmp/
|
||||||
|
/tmp/kvm_system/kvm_system &
|
||||||
|
|
||||||
|
# if [ -e /kvmapp/kvm_stream ]
|
||||||
|
# then
|
||||||
|
# cp -r /kvmapp/kvm_stream /tmp/
|
||||||
|
# /tmp/kvm_stream/kvm_stream &
|
||||||
|
# fi
|
||||||
|
|
||||||
|
cp -r /kvmapp/server /tmp/
|
||||||
|
/tmp/server/NanoKVM-Server &
|
||||||
|
;;
|
||||||
|
stop)
|
||||||
|
killall kvm_system
|
||||||
|
# killall kvm_stream
|
||||||
|
killall NanoKVM-Server
|
||||||
|
rm -r /tmp/kvm_system
|
||||||
|
# rm -r /tmp/kvm_stream
|
||||||
|
rm -r /tmp/server
|
||||||
|
echo "OK"
|
||||||
|
;;
|
||||||
|
# restart_stream)
|
||||||
|
# killall kvm_stream
|
||||||
|
# rm -r /tmp/kvm_stream
|
||||||
|
# if [ -e /kvmapp/kvm_stream ]
|
||||||
|
# then
|
||||||
|
# cp -r /kvmapp/kvm_stream /tmp/
|
||||||
|
# /tmp/kvm_stream/kvm_stream &
|
||||||
|
# echo "OK"
|
||||||
|
# fi
|
||||||
|
# ;;
|
||||||
|
restart)
|
||||||
|
killall kvm_system
|
||||||
|
# killall kvm_stream
|
||||||
|
killall NanoKVM-Server
|
||||||
|
rm -r /tmp/kvm_system
|
||||||
|
# rm -r /tmp/kvm_stream
|
||||||
|
rm -r /tmp/server
|
||||||
|
|
||||||
|
cp -r /kvmapp/kvm_system /tmp/
|
||||||
|
/tmp/kvm_system/kvm_system &
|
||||||
|
|
||||||
|
# if [ -e /kvmapp/kvm_stream ]
|
||||||
|
# then
|
||||||
|
# cp -r /kvmapp/kvm_stream /tmp/
|
||||||
|
# /tmp/kvm_stream/kvm_stream &
|
||||||
|
# fi
|
||||||
|
|
||||||
|
cp -r /kvmapp/server /tmp/
|
||||||
|
/tmp/server/NanoKVM-Server &
|
||||||
|
|
||||||
|
sync
|
||||||
|
|
||||||
|
echo "OK"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
5
kvmapp/jpg_stream/jpg_stream
Executable file
5
kvmapp/jpg_stream/jpg_stream
Executable file
@@ -0,0 +1,5 @@
|
|||||||
|
rm /etc/init.d/S95webkvm
|
||||||
|
cp /kvmapp/jpg_stream/S95nanokvm /etc/init.d/
|
||||||
|
cp /kvmapp/jpg_stream/dl_lib/libmaixcam_lib.so /kvmapp/kvm_system/dl_lib
|
||||||
|
rm -r /kvmapp/jpg_stream
|
||||||
|
/etc/init.d/S95nanokvm restart
|
||||||
0
kvmapp/kvm_new_app
Normal file
0
kvmapp/kvm_new_app
Normal file
0
kvmapp/kvm_system/kvm_stream
Executable file
0
kvmapp/kvm_system/kvm_stream
Executable file
BIN
kvmapp/kvm_system/kvm_system
Executable file
BIN
kvmapp/kvm_system/kvm_system
Executable file
Binary file not shown.
42
kvmapp/system/init.d/S01fs
Executable file
42
kvmapp/system/init.d/S01fs
Executable file
@@ -0,0 +1,42 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
if [ "$1" = "start" ]
|
||||||
|
then
|
||||||
|
# use all sdcard free space for data
|
||||||
|
parted -s /dev/mmcblk0 "resizepart 2 -0"
|
||||||
|
echo "yes
|
||||||
|
8192MB
|
||||||
|
" | parted ---pretend-input-tty /dev/mmcblk0 "resizepart 2 8192MB"
|
||||||
|
# resize data filesystem
|
||||||
|
(resize2fs /dev/mmcblk0p2) &
|
||||||
|
|
||||||
|
|
||||||
|
. /etc/profile
|
||||||
|
printf "mounting filesystem : "
|
||||||
|
mkdir -p /boot
|
||||||
|
mount -t vfat /dev/mmcblk0p1 /boot
|
||||||
|
mount -t configfs configfs /sys/kernel/config
|
||||||
|
mount -t debugfs debugfs /sys/kernel/debug
|
||||||
|
|
||||||
|
if [ -e /boot/usb.disk0 ]
|
||||||
|
then
|
||||||
|
if [ ! -e /etc/kvm.disk0 ]
|
||||||
|
then
|
||||||
|
touch /etc/kvm.disk0
|
||||||
|
# use all sdcard free space for data
|
||||||
|
parted -s /dev/mmcblk0 "mkpart primary 8193MB 100%"
|
||||||
|
sleep 1
|
||||||
|
# resize data filesystem
|
||||||
|
(mkfs.exfat /dev/mmcblk0p3) &
|
||||||
|
sleep 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -e /dev/mmcblk0p3 ]
|
||||||
|
then
|
||||||
|
mkdir -p /data
|
||||||
|
mount /dev/mmcblk0p3 /data
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "OK"
|
||||||
|
fi
|
||||||
139
kvmapp/system/init.d/S03usbdev
Executable file
139
kvmapp/system/init.d/S03usbdev
Executable file
@@ -0,0 +1,139 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
# kvmhwd Rev2.0
|
||||||
|
|
||||||
|
start_usb_dev(){
|
||||||
|
. /etc/profile
|
||||||
|
echo "usb mode: device"
|
||||||
|
cd /sys/kernel/config/usb_gadget
|
||||||
|
|
||||||
|
mkdir g0
|
||||||
|
cd g0
|
||||||
|
|
||||||
|
echo 0x3346 > idVendor
|
||||||
|
echo 0x1009 > idProduct
|
||||||
|
mkdir strings/0x409
|
||||||
|
echo '0123456789ABCDEF' > strings/0x409/serialnumber
|
||||||
|
echo 'sipeed' > strings/0x409/manufacturer
|
||||||
|
echo 'NanoKVM' > strings/0x409/product
|
||||||
|
|
||||||
|
mkdir configs/c.1
|
||||||
|
echo 0xE0 > configs/c.1/bmAttributes
|
||||||
|
echo 120 > configs/c.1/MaxPower
|
||||||
|
mkdir configs/c.1/strings/0x409
|
||||||
|
echo "NanoKVM" > configs/c.1/strings/0x409/configuration
|
||||||
|
|
||||||
|
if [ -e /boot/usb.ncm ]
|
||||||
|
then
|
||||||
|
mkdir functions/ncm.usb0
|
||||||
|
ln -s functions/ncm.usb0 configs/c.1/
|
||||||
|
else
|
||||||
|
if [ -e /boot/usb.rndis0 ]
|
||||||
|
then
|
||||||
|
mkdir functions/rndis.usb0
|
||||||
|
ln -s functions/rndis.usb0 configs/c.1/
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ ! -e /boot/disable_hid ]
|
||||||
|
then
|
||||||
|
# keyboard
|
||||||
|
mkdir functions/hid.GS0
|
||||||
|
if [ -e /boot/BIOS ]
|
||||||
|
then
|
||||||
|
echo 1 > functions/hid.GS0/subclass
|
||||||
|
fi
|
||||||
|
if [ ! -e /boot/usb.notwakeup ]
|
||||||
|
then
|
||||||
|
echo 1 > functions/hid.GS0/wakeup_on_write
|
||||||
|
fi
|
||||||
|
echo 1 > functions/hid.GS0/protocol
|
||||||
|
echo 6 > functions/hid.GS0/report_length
|
||||||
|
echo -ne \\x05\\x01\\x09\\x06\\xa1\\x01\\x05\\x07\\x19\\xe0\\x29\\xe7\\x15\\x00\\x25\\x01\\x75\\x01\\x95\\x08\\x81\\x02\\x95\\x01\\x75\\x08\\x81\\x03\\x95\\x05\\x75\\x01\\x05\\x08\\x19\\x01\\x29\\x05\\x91\\x02\\x95\\x01\\x75\\x03\\x91\\x03\\x95\\x06\\x75\\x08\\x15\\x00\\x25\\x65\\x05\\x07\\x19\\x00\\x29\\x65\\x81\\x00\\xc0 > functions/hid.GS0/report_desc
|
||||||
|
ln -s functions/hid.GS0 configs/c.1
|
||||||
|
|
||||||
|
# mouse
|
||||||
|
mkdir functions/hid.GS1
|
||||||
|
if [ -e /boot/BIOS ]
|
||||||
|
then
|
||||||
|
echo 1 > functions/hid.GS1/subclass
|
||||||
|
fi
|
||||||
|
if [ ! -e /boot/usb.notwakeup ]
|
||||||
|
then
|
||||||
|
echo 1 > functions/hid.GS1/wakeup_on_write
|
||||||
|
fi
|
||||||
|
echo 2 > functions/hid.GS1/protocol
|
||||||
|
echo -ne \\x34 > functions/hid.GS1/report_length
|
||||||
|
echo -ne \\x5\\x1\\x9\\x2\\xa1\\x1\\x9\\x1\\xa1\\x0\\x5\\x9\\x19\\x1\\x29\\x3\\x15\\x0\\x25\\x1\\x95\\x3\\x75\\x1\\x81\\x2\\x95\\x1\\x75\\x5\\x81\\x3\\x5\\x1\\x9\\x30\\x9\\x31\\x9\\x38\\x15\\x81\\x25\\x7f\\x75\\x8\\x95\\x3\\x81\\x6\\xc0\\xc0 > functions/hid.GS1/report_desc
|
||||||
|
ln -s functions/hid.GS1 configs/c.1
|
||||||
|
|
||||||
|
# touchpad
|
||||||
|
mkdir functions/hid.GS2
|
||||||
|
if [ -e /boot/BIOS ]
|
||||||
|
then
|
||||||
|
echo 1 > functions/hid.GS2/subclass
|
||||||
|
fi
|
||||||
|
if [ ! -e /boot/usb.notwakeup ]
|
||||||
|
then
|
||||||
|
echo 1 > functions/hid.GS2/wakeup_on_write
|
||||||
|
fi
|
||||||
|
echo 2 > functions/hid.GS2/protocol
|
||||||
|
echo 6 > functions/hid.GS2/report_length
|
||||||
|
echo -ne \\x05\\x01\\x09\\x02\\xa1\\x01\\x09\\x01\\xa1\\x00\\x05\\x09\\x19\\x01\\x29\\x03\\x15\\x00\\x25\\x01\\x95\\x03\\x75\\x01\\x81\\x02\\x95\\x01\\x75\\x05\\x81\\x01\\x05\\x01\\x09\\x30\\x09\\x31\\x15\\x00\\x26\\xff\\x7f\\x35\\x00\\x46\\xff\\x7f\\x75\\x10\\x95\\x02\\x81\\x02\\x05\\x01\\x09\\x38\\x15\\x81\\x25\\x7f\\x35\\x00\\x45\\x00\\x75\\x08\\x95\\x01\\x81\\x06\\xc0\\xc0 > functions/hid.GS2/report_desc
|
||||||
|
ln -s functions/hid.GS2 configs/c.1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -e /boot/usb.disk0 ]
|
||||||
|
then
|
||||||
|
mkdir functions/mass_storage.disk0
|
||||||
|
ln -s functions/mass_storage.disk0 configs/c.1/
|
||||||
|
echo 1 > functions/mass_storage.disk0/lun.0/removable
|
||||||
|
if [ -e /boot/usb.disk0.ro ]
|
||||||
|
then
|
||||||
|
echo 1 > functions/mass_storage.disk0/lun.0/ro
|
||||||
|
echo 0 > functions/mass_storage.disk0/lun.0/cdrom
|
||||||
|
fi
|
||||||
|
disk=$(cat /boot/usb.disk0)
|
||||||
|
if [ -z "${disk}" ]
|
||||||
|
then
|
||||||
|
# if [ ! -e /mnt/usbdisk.img ]
|
||||||
|
# then
|
||||||
|
# fallocate -l 8G /mnt/usbdisk.img
|
||||||
|
# mkfs.vfat /mnt/usbdisk.img
|
||||||
|
# fi
|
||||||
|
echo /dev/mmcblk0p3 > functions/mass_storage.disk0/lun.0/file
|
||||||
|
else
|
||||||
|
cat /boot/usb.disk0 > functions/mass_storage.disk0/lun.0/file
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
ls /sys/class/udc/ | cat > UDC
|
||||||
|
echo device > /proc/cviusb/otg_role
|
||||||
|
}
|
||||||
|
|
||||||
|
start_usb_host(){
|
||||||
|
echo '' > /sys/kernel/config/usb_gadget/g0/UDC
|
||||||
|
echo host > /proc/cviusb/otg_role
|
||||||
|
}
|
||||||
|
|
||||||
|
restart_usb_dev(){
|
||||||
|
echo > /sys/kernel/config/usb_gadget/g0/UDC
|
||||||
|
sleep 1
|
||||||
|
ls /sys/class/udc/ | cat > /sys/kernel/config/usb_gadget/g0/UDC
|
||||||
|
echo "USB Restart OK!"
|
||||||
|
}
|
||||||
|
|
||||||
|
case "$1" in
|
||||||
|
start)
|
||||||
|
start_usb_dev
|
||||||
|
;;
|
||||||
|
restart)
|
||||||
|
restart_usb_dev
|
||||||
|
;;
|
||||||
|
stop)
|
||||||
|
start_usb_host
|
||||||
|
;;
|
||||||
|
stop_start)
|
||||||
|
start_usb_host
|
||||||
|
start_usb_dev
|
||||||
|
;;
|
||||||
|
esac
|
||||||
209
kvmapp/system/init.d/S15kvmhwd
Executable file
209
kvmapp/system/init.d/S15kvmhwd
Executable file
@@ -0,0 +1,209 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
# kvmhwd Rev2.3
|
||||||
|
|
||||||
|
Alpha_OLED_RST_Pin=371
|
||||||
|
Beta_OLED_RST_Pin=502
|
||||||
|
Beta_OLED_SCL=595
|
||||||
|
Beta_OLED_SDA=507
|
||||||
|
WiFi_EN_Pin=506
|
||||||
|
Alpha_PWR_LED_Pin=504
|
||||||
|
Alpha_HDD_LED_Pin=505
|
||||||
|
Alpha_PWR_KEY_Pin=503
|
||||||
|
Alpha_RST_KEY_Pin=507
|
||||||
|
Beta_PWR_LED_Pin=504
|
||||||
|
Beta_PWR_KEY_Pin=503
|
||||||
|
Beta_RST_KEY_Pin=505
|
||||||
|
PCIe_HDMI_RST_Pin=451
|
||||||
|
|
||||||
|
init_alpha_hw(){
|
||||||
|
devmem 0x030010D0 32 0x2 # I2C1_SCL
|
||||||
|
devmem 0x030010DC 32 0x2 # I2C1_SDA
|
||||||
|
devmem 0x030010D4 32 0x3 # OLED_RST
|
||||||
|
devmem 0x0300103C 32 0x3 # GPIOA15
|
||||||
|
devmem 0x03001050 32 0x3 # GPIOA22
|
||||||
|
devmem 0x0300105C 32 0x3 # GPIOA23
|
||||||
|
devmem 0x03001060 32 0x3 # GPIOA24
|
||||||
|
devmem 0x03001054 32 0x3 # GPIOA25
|
||||||
|
devmem 0x03001058 32 0x3 # GPIOA27
|
||||||
|
|
||||||
|
devmem 0x03001068 32 0x6 # GPIOA 18 UART1 RX
|
||||||
|
devmem 0x03001064 32 0x6 # GPIOA 19 UART1 TX
|
||||||
|
devmem 0x03001070 32 0x2 # GPIOA 28 UART2 TX
|
||||||
|
devmem 0x03001074 32 0x2 # GPIOA 29 UART2 RX
|
||||||
|
|
||||||
|
echo ${Alpha_OLED_RST_Pin} > /sys/class/gpio/export # OLED_RST
|
||||||
|
echo out > /sys/class/gpio/gpio${Alpha_OLED_RST_Pin}/direction
|
||||||
|
echo 1 > /sys/class/gpio/gpio${Alpha_OLED_RST_Pin}/value
|
||||||
|
|
||||||
|
echo ${Alpha_PWR_LED_Pin} > /sys/class/gpio/export # pwr led
|
||||||
|
echo ${Alpha_HDD_LED_Pin} > /sys/class/gpio/export # hdd led
|
||||||
|
echo ${Alpha_PWR_KEY_Pin} > /sys/class/gpio/export # pwr key
|
||||||
|
echo ${Alpha_RST_KEY_Pin} > /sys/class/gpio/export # rst key
|
||||||
|
|
||||||
|
echo in > /sys/class/gpio/gpio${Alpha_PWR_LED_Pin}/direction # pwr led
|
||||||
|
echo in > /sys/class/gpio/gpio${Alpha_HDD_LED_Pin}/direction # hdd led
|
||||||
|
echo out > /sys/class/gpio/gpio${Alpha_PWR_KEY_Pin}/direction # pwr key
|
||||||
|
echo out > /sys/class/gpio/gpio${Alpha_RST_KEY_Pin}/direction # rst key
|
||||||
|
|
||||||
|
rmmod /mnt/system/ko/i2c-gpio.ko
|
||||||
|
rmmod /mnt/system/ko/i2c-algo-bit.ko
|
||||||
|
|
||||||
|
# rm /etc/init.d/S25wifimod
|
||||||
|
# rm /etc/init.d/S30wifi
|
||||||
|
}
|
||||||
|
|
||||||
|
init_beta_pcie_hw(){
|
||||||
|
devmem 0x0300103C 32 0x3 # GPIOA15
|
||||||
|
devmem 0x03001050 32 0x3 # GPIOA22
|
||||||
|
devmem 0x0300105C 32 0x3 # GPIOA23
|
||||||
|
devmem 0x03001060 32 0x3 # GPIOA24
|
||||||
|
devmem 0x03001054 32 0x3 # GPIOA25
|
||||||
|
devmem 0x03001058 32 0x3 # GPIOA27
|
||||||
|
|
||||||
|
devmem 0x030010E4 32 0x0 # SDIO CLK
|
||||||
|
devmem 0x030010E0 32 0x0 # SDIO CMD
|
||||||
|
devmem 0x030010DC 32 0x0 # SDIO D0
|
||||||
|
devmem 0x030010D8 32 0x0 # SDIO D1
|
||||||
|
devmem 0x030010D4 32 0x0 # SDIO D2
|
||||||
|
devmem 0x030010D0 32 0x0 # SDIO D3
|
||||||
|
|
||||||
|
devmem 0x03001068 32 0x6 # GPIOA 18 UART1 RX
|
||||||
|
devmem 0x03001064 32 0x6 # GPIOA 19 UART1 TX
|
||||||
|
devmem 0x03001070 32 0x2 # GPIOA 28 UART2 TX
|
||||||
|
devmem 0x03001074 32 0x2 # GPIOA 29 UART2 RX
|
||||||
|
|
||||||
|
echo ${Beta_OLED_RST_Pin} > /sys/class/gpio/export # Beta OLED_RST
|
||||||
|
echo out > /sys/class/gpio/gpio${Beta_OLED_RST_Pin}/direction
|
||||||
|
echo 1 > /sys/class/gpio/gpio${Beta_OLED_RST_Pin}/value
|
||||||
|
|
||||||
|
echo ${Beta_PWR_LED_Pin} > /sys/class/gpio/export # pwr led
|
||||||
|
echo ${Beta_PWR_KEY_Pin} > /sys/class/gpio/export # pwr key
|
||||||
|
echo ${Beta_RST_KEY_Pin} > /sys/class/gpio/export # rst key
|
||||||
|
echo ${PCIe_HDMI_RST_Pin} > /sys/class/gpio/export # hdmi rst key
|
||||||
|
|
||||||
|
echo in > /sys/class/gpio/gpio${Beta_PWR_LED_Pin}/direction # pwr led
|
||||||
|
echo out > /sys/class/gpio/gpio${Beta_PWR_KEY_Pin}/direction # pwr key
|
||||||
|
echo out > /sys/class/gpio/gpio${Beta_RST_KEY_Pin}/direction # rst key
|
||||||
|
echo out > /sys/class/gpio/gpio${PCIe_HDMI_RST_Pin}/direction # rst key
|
||||||
|
|
||||||
|
echo 1 > /sys/class/gpio/gpio${PCIe_HDMI_RST_Pin}/value # rst key
|
||||||
|
|
||||||
|
rmmod /mnt/system/ko/i2c-gpio.ko
|
||||||
|
rmmod /mnt/system/ko/i2c-algo-bit.ko
|
||||||
|
insmod /mnt/system/ko/i2c-algo-bit.ko
|
||||||
|
insmod /mnt/system/ko/i2c-gpio.ko
|
||||||
|
}
|
||||||
|
|
||||||
|
kvm_hw_detect(){
|
||||||
|
if [ ! -e /etc/kvm/hdmi_version ]
|
||||||
|
then
|
||||||
|
rm /etc/kvm/hw
|
||||||
|
fi
|
||||||
|
if [ -e /etc/kvm/hw ]
|
||||||
|
then
|
||||||
|
echo "/etc/kvm/hw exist"
|
||||||
|
else
|
||||||
|
echo "/etc/kvm/hw not exist"
|
||||||
|
if [ -d "/etc/kvm/" ]
|
||||||
|
then
|
||||||
|
echo "/etc/kvm/ exist"
|
||||||
|
else
|
||||||
|
mkdir /etc/kvm/
|
||||||
|
fi
|
||||||
|
devmem 0x0300104C 32 0x3 # GPIOA26 / WiFi_EN
|
||||||
|
echo ${WiFi_EN_Pin} > /sys/class/gpio/export # WiFi_EN
|
||||||
|
echo out > /sys/class/gpio/gpio${WiFi_EN_Pin}/direction
|
||||||
|
echo 0 > /sys/class/gpio/gpio${WiFi_EN_Pin}/value
|
||||||
|
|
||||||
|
devmem 0x0300103C 32 0x3 # GPIOA15
|
||||||
|
devmem 0x03001050 32 0x3 # GPIOA22
|
||||||
|
devmem 0x0300105C 32 0x3 # GPIOA23
|
||||||
|
devmem 0x03001060 32 0x3 # GPIOA24
|
||||||
|
devmem 0x03001054 32 0x3 # GPIOA25
|
||||||
|
devmem 0x03001058 32 0x3 # GPIOA27
|
||||||
|
|
||||||
|
devmem 0x030010D0 32 0x2 # I2C1_SCL
|
||||||
|
devmem 0x030010DC 32 0x2 # I2C1_SDA
|
||||||
|
devmem 0x030010D4 32 0x3 # OLED_RST
|
||||||
|
echo ${Alpha_OLED_RST_Pin} > /sys/class/gpio/export # OLED_RST
|
||||||
|
echo out > /sys/class/gpio/gpio${Alpha_OLED_RST_Pin}/direction
|
||||||
|
echo 1 > /sys/class/gpio/gpio${Alpha_OLED_RST_Pin}/value
|
||||||
|
|
||||||
|
kvm_tmp=$(i2cdetect -ry 1 0x3d 0x3d | grep 3d)
|
||||||
|
if [ -n "$kvm_tmp" ]
|
||||||
|
then
|
||||||
|
# alpha hw
|
||||||
|
echo "alpha" > /etc/kvm/hw
|
||||||
|
else
|
||||||
|
# beta/pcie hw
|
||||||
|
echo ${Alpha_OLED_RST_Pin} > /sys/class/gpio/unexport # OLED_RST
|
||||||
|
echo ${Beta_OLED_RST_Pin} > /sys/class/gpio/export # Beta_OLED_RST_Pin
|
||||||
|
echo out > /sys/class/gpio/gpio${Beta_OLED_RST_Pin}/direction
|
||||||
|
echo 1 > /sys/class/gpio/gpio${Beta_OLED_RST_Pin}/value
|
||||||
|
|
||||||
|
rmmod /mnt/system/ko/i2c-gpio.ko
|
||||||
|
rmmod /mnt/system/ko/i2c-algo-bit.ko
|
||||||
|
insmod /mnt/system/ko/i2c-algo-bit.ko
|
||||||
|
insmod /mnt/system/ko/i2c-gpio.ko
|
||||||
|
|
||||||
|
kvm_tmp=$(i2cdetect -ry 4 0x2c 0x2c | grep 2c)
|
||||||
|
if [ -n "$kvm_tmp" ]
|
||||||
|
then
|
||||||
|
echo "c" > /etc/kvm/hdmi_version
|
||||||
|
else
|
||||||
|
echo "u" > /etc/kvm/hdmi_version
|
||||||
|
fi
|
||||||
|
|
||||||
|
kvm_tmp=$(i2cdetect -ry 5 0x3c 0x3c | grep 3c)
|
||||||
|
if [ -n "$kvm_tmp" ]
|
||||||
|
then
|
||||||
|
echo "pcie" > /etc/kvm/hw
|
||||||
|
sync
|
||||||
|
reboot
|
||||||
|
else
|
||||||
|
echo "beta" > /etc/kvm/hw
|
||||||
|
# rm /etc/init.d/S25wifimod
|
||||||
|
# rm /etc/init.d/S30wifi
|
||||||
|
sync
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo 1 > /sys/class/gpio/gpio${WiFi_EN_Pin}/value
|
||||||
|
echo ${WiFi_EN_Pin} > /sys/class/gpio/unexport # WiFi_EN
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
sync
|
||||||
|
}
|
||||||
|
|
||||||
|
kvm_hw_init(){
|
||||||
|
FIND_FILE="/etc/kvm/hw"
|
||||||
|
if [ `grep -c "alpha" $FIND_FILE` -ne '0' ]
|
||||||
|
then
|
||||||
|
echo "hw = alpha!"
|
||||||
|
init_alpha_hw
|
||||||
|
fi
|
||||||
|
if [ `grep -c "beta" $FIND_FILE` -ne '0' ]
|
||||||
|
then
|
||||||
|
echo "hw = beta!"
|
||||||
|
init_beta_pcie_hw
|
||||||
|
fi
|
||||||
|
if [ `grep -c "pcie" $FIND_FILE` -ne '0' ]
|
||||||
|
then
|
||||||
|
echo "hw = pcie!"
|
||||||
|
init_beta_pcie_hw
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
case "$1" in
|
||||||
|
start)
|
||||||
|
kvm_hw_detect
|
||||||
|
kvm_hw_init
|
||||||
|
;;
|
||||||
|
re-detect)
|
||||||
|
rm /etc/kvm/hw
|
||||||
|
kvm_hw_detect
|
||||||
|
kvm_hw_init
|
||||||
|
;;
|
||||||
|
re-init)
|
||||||
|
kvm_hw_init
|
||||||
|
;;
|
||||||
|
esac
|
||||||
115
kvmapp/system/init.d/S30eth
Executable file
115
kvmapp/system/init.d/S30eth
Executable file
@@ -0,0 +1,115 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
. /etc/profile
|
||||||
|
|
||||||
|
# /boot/eth.nodhcp for example
|
||||||
|
# ipaddr/net gw[optional]
|
||||||
|
# 192.168.0.101/24 192.168.0.1
|
||||||
|
# 192.168.3.116/22
|
||||||
|
|
||||||
|
RESERVE_INET="192.168.0.1/24"
|
||||||
|
|
||||||
|
start() {
|
||||||
|
printf "start ethernet: "
|
||||||
|
if [ -e /boot/eth.nodhcp ]
|
||||||
|
then
|
||||||
|
[ -e /boot/eth.nodhcp ] &&
|
||||||
|
cat /boot/eth.nodhcp | while read inet gw
|
||||||
|
do
|
||||||
|
addr=${inet%/*}
|
||||||
|
netid=${inet#*/}
|
||||||
|
[ -z $gw ] &&
|
||||||
|
gw=$( echo $addr| ( IFS='.' read a b c d; echo $((
|
||||||
|
(((((($a<<8)+$b)<<8)+$c)<<8)+$d)
|
||||||
|
& (((1<<$netid)-1)<<(32-$netid))
|
||||||
|
))
|
||||||
|
)) &&
|
||||||
|
gw=$(($gw>>24&0xff)).$(($gw>>16&0xff)).$(($gw>>8&0xff)).$((1+( $gw>>0&0xff )))
|
||||||
|
|
||||||
|
arping -Dqc2 -Ieth0 $addr || continue
|
||||||
|
ip a add $inet brd + dev eth0
|
||||||
|
ip r add default via $gw dev eth0
|
||||||
|
cat > /etc/resolve.conf << EOF
|
||||||
|
nameserver $gw
|
||||||
|
nameserver 8.8.8.8
|
||||||
|
nameserver 114.114.114.114
|
||||||
|
EOF
|
||||||
|
break
|
||||||
|
done &&
|
||||||
|
ip a show dev eth0|grep inet || (
|
||||||
|
udhcpc -i eth0 -t 3 -T 1 -A 5 -b -p /run/udhcpc.eth0.pid &>/dev/null
|
||||||
|
ip a show dev eth0|grep inet
|
||||||
|
) || (
|
||||||
|
# failed to apply dynamic addr, need a available static addr to visit the LAN
|
||||||
|
inet=$RESERVE_INET
|
||||||
|
addr=${inet%/*}
|
||||||
|
ip a add $inet brd + dev eth0
|
||||||
|
) || exit 1
|
||||||
|
else
|
||||||
|
(udhcpc -i eth0 -t 10 -T 1 -A 5 -b -p /run/udhcpc.eth0.pid) &
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "OK"
|
||||||
|
}
|
||||||
|
stop() {
|
||||||
|
[[ ! -e "/run/udhcpc.eth0.pid" ]] && echo "udhcpc is not running..." && exit 1
|
||||||
|
kill `cat /run/udhcpc.eth0.pid`
|
||||||
|
rm /run/udhcpc.eth0.pid
|
||||||
|
}
|
||||||
|
|
||||||
|
case "$1" in
|
||||||
|
start)
|
||||||
|
start
|
||||||
|
;;
|
||||||
|
stop)
|
||||||
|
stop
|
||||||
|
;;
|
||||||
|
restart|reload)
|
||||||
|
$0 stop
|
||||||
|
$0 start
|
||||||
|
;;
|
||||||
|
doc)
|
||||||
|
cat <<EOF
|
||||||
|
If you want to set your own static ip address
|
||||||
|
rather then fetch it by dhcp.
|
||||||
|
Then you need to create a file \`/boot/eth.nodhcp\`,
|
||||||
|
and edit it following the format below:
|
||||||
|
\`addr/netid gw[optional]\` in one line
|
||||||
|
for example (support muti definations, checks with arp):
|
||||||
|
1. 192.168.0.101/24 192.168.0.1
|
||||||
|
2. 192.168.3.116/22
|
||||||
|
Delete this file if you change to use dhcp default.
|
||||||
|
ATTENTION: If all the STATIC address you set in the file is
|
||||||
|
already in use on this LAN checked with arp, then none
|
||||||
|
of them will be yours. And it will trigger dhcp, try to
|
||||||
|
fetch DYNAMIC one. If it's also failed, your address will
|
||||||
|
be the REVERSE one, 192.168.0.1/24. Just to be sure that
|
||||||
|
you can visit your NanoKVM device through eth to fix some
|
||||||
|
problems by ssh, unless you must disassemble it and modify
|
||||||
|
or rewrite the TFCard once again.
|
||||||
|
EOF
|
||||||
|
echo ""
|
||||||
|
cat <<EOF
|
||||||
|
如果您想自行设置静态 ip 地址而不是使用 dhcp 来获取它。
|
||||||
|
|
||||||
|
那么您需要新建一个文件 \`/boot/eth.nodhcp\`,然后按照以下格式编辑它:
|
||||||
|
\`addr/netid gw[optional]\` 在一行内
|
||||||
|
示例(支持多个预设,会通过 arp 检查是否占用):
|
||||||
|
1. 192.168.0.101/24 192.168.0.1
|
||||||
|
2. 192.168.3.116/22
|
||||||
|
|
||||||
|
如果您想改回默认 dhcp 获取 ip 地址的方式,删除该文件后即可恢复。
|
||||||
|
|
||||||
|
注意:如果您预设的所有静态 ip 地址都被 arp 检测到已占用,则不会成功设置。
|
||||||
|
此时会触发 dhcp 尝试获取 ip 地址,如果仍失败,那么最终会强制设置成
|
||||||
|
192.168.90.1/24。这是为了保证您的 NanoKVM 设备总是能有一个可用的
|
||||||
|
ip 地址,方便您通过局域网 ssh 连接设备进行一些修复,否则您可能需要
|
||||||
|
拆开外壳以手动修改 TF 卡或重新烧卡。
|
||||||
|
|
||||||
|
|
||||||
|
EOF
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "Usage: $0 {start|stop|restart}"
|
||||||
|
exit 1
|
||||||
|
esac
|
||||||
175
kvmapp/system/init.d/S30wifi
Executable file
175
kvmapp/system/init.d/S30wifi
Executable file
@@ -0,0 +1,175 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
. /etc/profile
|
||||||
|
|
||||||
|
gen_hostapd_conf() {
|
||||||
|
ssid="${1}"
|
||||||
|
pass="${2}"
|
||||||
|
echo "ctrl_interface=/var/run/hostapd"
|
||||||
|
echo "ctrl_interface_group=0"
|
||||||
|
echo "ssid=${ssid}"
|
||||||
|
echo "hw_mode=g"
|
||||||
|
echo "channel=1"
|
||||||
|
echo "beacon_int=100"
|
||||||
|
echo "dtim_period=2"
|
||||||
|
echo "max_num_sta=255"
|
||||||
|
echo "rts_threshold=-1"
|
||||||
|
echo "fragm_threshold=-1"
|
||||||
|
echo "macaddr_acl=0"
|
||||||
|
echo "auth_algs=3"
|
||||||
|
echo "wpa=2"
|
||||||
|
echo "wpa_passphrase=${pass}"
|
||||||
|
echo "ieee80211n=1"
|
||||||
|
}
|
||||||
|
|
||||||
|
gen_udhcpd_conf() {
|
||||||
|
interface=${1}
|
||||||
|
ipv4_prefix=${2}
|
||||||
|
echo "start ${ipv4_prefix}.100"
|
||||||
|
echo "end ${ipv4_prefix}.200"
|
||||||
|
echo "interface ${interface}"
|
||||||
|
echo "pidfile /var/run/udhcpd.${interface}.pid"
|
||||||
|
echo "lease_file /var/lib/misc/udhcpd.${interface}.leases"
|
||||||
|
echo "option subnet 255.255.255.0"
|
||||||
|
echo "option lease 864000"
|
||||||
|
}
|
||||||
|
|
||||||
|
gen_dnsmasq_conf() {
|
||||||
|
ipv4_prefix=${1}
|
||||||
|
echo "bind-interfaces"
|
||||||
|
echo "interface=wlan0"
|
||||||
|
echo "address=/config.kvm/${ipv4_prefix}.1"
|
||||||
|
echo "no-hosts"
|
||||||
|
echo "dhcp-range=${ipv4_prefix}.2,${ipv4_prefix}.254"
|
||||||
|
echo "dhcp-option=6,${ipv4_prefix}.1"
|
||||||
|
echo "dhcp-option=3,${ipv4_prefix}.1"
|
||||||
|
echo "dhcp-authoritative"
|
||||||
|
}
|
||||||
|
|
||||||
|
start() {
|
||||||
|
echo "wifi mode: sta"
|
||||||
|
ssid=""
|
||||||
|
pass=""
|
||||||
|
if [ -e /boot/wifi.ssid ] && [ -e /boot/wifi.pass ]; then
|
||||||
|
echo "Updating WiFi credentials from /boot to /etc/kvm/"
|
||||||
|
|
||||||
|
rm -f /etc/kvm/wifi.ssid /etc/kvm/wifi.pass
|
||||||
|
|
||||||
|
mv /boot/wifi.ssid /etc/kvm/wifi.ssid
|
||||||
|
mv /boot/wifi.pass /etc/kvm/wifi.pass
|
||||||
|
|
||||||
|
chown root:root /etc/kvm/wifi.ssid /etc/kvm/wifi.pass
|
||||||
|
chmod 644 /etc/kvm/wifi.ssid /etc/kvm/wifi.pass
|
||||||
|
fi
|
||||||
|
if [ -e /etc/kvm/wifi.ssid ]
|
||||||
|
then
|
||||||
|
ssid=`cat /etc/kvm/wifi.ssid`
|
||||||
|
fi
|
||||||
|
if [ -e /etc/kvm/wifi.pass ]
|
||||||
|
then
|
||||||
|
pass=`cat /etc/kvm/wifi.pass`
|
||||||
|
fi
|
||||||
|
echo "ctrl_interface=/var/run/wpa_supplicant" > /etc/wpa_supplicant.conf
|
||||||
|
wpa_passphrase "$ssid" "$pass" >> /etc/wpa_supplicant.conf
|
||||||
|
wpa_supplicant -B -i wlan0 -c /etc/wpa_supplicant.conf
|
||||||
|
if [ ! -e /boot/wifi.nodhcp ]
|
||||||
|
then
|
||||||
|
(udhcpc -i wlan0 -t 10 -T 1 -A 5 -b -p /run/udhcpc.wlan0.pid) &
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
ap_start() {
|
||||||
|
echo "wifi mode: ap"
|
||||||
|
id2=$(printf "%d" 0x$(sha512sum /sys/class/cvi-base/base_uid | head -c 2))
|
||||||
|
id3=$(printf "%d" 0x$(sha512sum /sys/class/cvi-base/base_uid | head -c 4 | tail -c 2))
|
||||||
|
if [ "$id2" = "$id3" ]
|
||||||
|
then
|
||||||
|
id2=$((id2 + 1))
|
||||||
|
fi
|
||||||
|
if [ "$id2" -ge 255 ]
|
||||||
|
then
|
||||||
|
id2=253
|
||||||
|
fi
|
||||||
|
if [ "$id3" -ge 255 ]
|
||||||
|
then
|
||||||
|
id3=254
|
||||||
|
fi
|
||||||
|
ssid=""
|
||||||
|
pass=""
|
||||||
|
if [ -e /kvmapp/kvm/ap.ssid ]
|
||||||
|
then
|
||||||
|
ssid=`cat /kvmapp/kvm/ap.ssid`
|
||||||
|
fi
|
||||||
|
if [ -e /kvmapp/kvm/ap.pass ]
|
||||||
|
then
|
||||||
|
pass=`cat /kvmapp/kvm/ap.pass`
|
||||||
|
fi
|
||||||
|
gen_hostapd_conf "$ssid" "$pass" > /etc/hostapd.conf
|
||||||
|
ipv4_prefix=10.$id3.$id2
|
||||||
|
if [ ! -e /etc/udhcpd.wlan0.conf ]
|
||||||
|
then
|
||||||
|
gen_udhcpd_conf wlan0 "${ipv4_prefix}" > /etc/udhcpd.wlan0.conf
|
||||||
|
fi
|
||||||
|
# gen_dnsmasq_conf "${ipv4_prefix}" > /etc/dnsmasq.conf
|
||||||
|
|
||||||
|
# iptables --policy INPUT ACCEPT
|
||||||
|
# iptables --policy FORWARD ACCEPT
|
||||||
|
# iptables --policy OUTPUT ACCEPT
|
||||||
|
# iptables -F
|
||||||
|
# iptables -t nat -F
|
||||||
|
# iptables -t nat -A PREROUTING -i wlan0 -p udp --dport 53 -j DNAT --to ${ipv4_prefix}.1
|
||||||
|
|
||||||
|
ifconfig wlan0 up
|
||||||
|
ip route del default || true
|
||||||
|
ip add flush dev wlan0
|
||||||
|
ip addr add $ipv4_prefix.1/24 dev wlan0
|
||||||
|
# dnsmasq --pid-file=/tmp/dnsmasq.run -C /etc/dnsmasq.conf
|
||||||
|
hostapd -B -i wlan0 /etc/hostapd.conf
|
||||||
|
udhcpd -S /etc/udhcpd.wlan0.conf
|
||||||
|
}
|
||||||
|
|
||||||
|
stop() {
|
||||||
|
ps -ef|grep hostapd|grep -v grep|awk '{print $1}'|xargs kill -2 || true
|
||||||
|
ps -ef|grep "udhcpd -S /etc/udhcpd.wlan0.conf" |grep -v grep|awk '{print $1}'|xargs kill -2 || true
|
||||||
|
killall wpa_supplicant || true
|
||||||
|
if [ -e /run/udhcpc.wlan0.pid ]
|
||||||
|
then
|
||||||
|
kill `cat /run/udhcpc.wlan0.pid` || true
|
||||||
|
rm -f /run/udhcpc.wlan0.pid
|
||||||
|
fi
|
||||||
|
if [ -e /var/run/udhcpd.wlan0.pid ]
|
||||||
|
then
|
||||||
|
kill `cat /var/run/udhcpd.wlan0.pid` || true
|
||||||
|
rm -f /var/run/udhcpd.wlan0.pid
|
||||||
|
fi
|
||||||
|
if [ -e /tmp/dnsmasq.run ]
|
||||||
|
then
|
||||||
|
kill `cat /tmp/dnsmasq.run` || true
|
||||||
|
rm -f /tmp/dnsmasq.run
|
||||||
|
fi
|
||||||
|
# if [ -e /etc/wpa_supplicant.conf]
|
||||||
|
# then
|
||||||
|
# echo > /etc/wpa_supplicant.conf
|
||||||
|
# fi
|
||||||
|
airmon-ng stop wlan0mon || true
|
||||||
|
}
|
||||||
|
|
||||||
|
restart() {
|
||||||
|
stop
|
||||||
|
start
|
||||||
|
}
|
||||||
|
|
||||||
|
if [ "${1}" = "start" ]
|
||||||
|
then
|
||||||
|
start
|
||||||
|
elif [ "${1}" = "stop" ]
|
||||||
|
then
|
||||||
|
stop
|
||||||
|
elif [ "${1}" = "ap" ]
|
||||||
|
then
|
||||||
|
stop
|
||||||
|
ap_start
|
||||||
|
elif [ "${1}" = "restart" ]
|
||||||
|
then
|
||||||
|
restart
|
||||||
|
fi
|
||||||
49
kvmapp/system/init.d/S50ssdpd
Executable file
49
kvmapp/system/init.d/S50ssdpd
Executable file
@@ -0,0 +1,49 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
DAEMON=ssdpd
|
||||||
|
PIDFILE=/var/run/$DAEMON.pid
|
||||||
|
CFGFILE=/etc/default/$DAEMON
|
||||||
|
|
||||||
|
DAEMON_ARGS=""
|
||||||
|
|
||||||
|
# Read configuration variable file if it is present
|
||||||
|
# shellcheck source=/dev/null
|
||||||
|
[ -r "$CFGFILE" ] && . "$CFGFILE"
|
||||||
|
|
||||||
|
# shellcheck disable=SC2086
|
||||||
|
start() {
|
||||||
|
printf 'Starting %s: ' "$DAEMON"
|
||||||
|
if start-stop-daemon -S -q -p "$PIDFILE" -x "$DAEMON" -- $DAEMON_ARGS; then
|
||||||
|
echo "OK"
|
||||||
|
else
|
||||||
|
echo "FAIL"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
stop() {
|
||||||
|
printf 'Stopping %s: ' "$DAEMON"
|
||||||
|
if start-stop-daemon -K -q -p "$PIDFILE" -x "$DAEMON"; then
|
||||||
|
echo "OK"
|
||||||
|
else
|
||||||
|
echo "FAIL"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
restart() {
|
||||||
|
stop
|
||||||
|
start
|
||||||
|
}
|
||||||
|
|
||||||
|
case "$1" in
|
||||||
|
start|stop|restart)
|
||||||
|
"$1"
|
||||||
|
;;
|
||||||
|
reload)
|
||||||
|
restart
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "Usage: $0 {start|stop|restart|reload}"
|
||||||
|
exit 1
|
||||||
|
esac
|
||||||
|
|
||||||
|
exit $?
|
||||||
69
kvmapp/system/init.d/S50sshd
Executable file
69
kvmapp/system/init.d/S50sshd
Executable file
@@ -0,0 +1,69 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
#
|
||||||
|
# sshd Starts sshd.
|
||||||
|
#
|
||||||
|
|
||||||
|
# Make sure the ssh-keygen progam exists
|
||||||
|
[ -f /usr/bin/ssh-keygen ] || exit 0
|
||||||
|
|
||||||
|
umask 077
|
||||||
|
|
||||||
|
startssh() {
|
||||||
|
/usr/bin/ssh-keygen -A
|
||||||
|
|
||||||
|
printf "Starting sshd: "
|
||||||
|
/usr/sbin/sshd
|
||||||
|
touch /var/lock/sshd
|
||||||
|
echo "OK"
|
||||||
|
}
|
||||||
|
start() {
|
||||||
|
# Create any missing keys
|
||||||
|
if [ -e /etc/kvm/ssh_stop ]
|
||||||
|
then
|
||||||
|
if [ -e /boot/start_ssh_once ]
|
||||||
|
then
|
||||||
|
rm /boot/start_ssh_once
|
||||||
|
startssh
|
||||||
|
else
|
||||||
|
echo "SSH does not start"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
startssh
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
stop() {
|
||||||
|
printf "Stopping sshd: "
|
||||||
|
killall sshd
|
||||||
|
rm -f /var/lock/sshd
|
||||||
|
echo "OK"
|
||||||
|
}
|
||||||
|
restart() {
|
||||||
|
stop
|
||||||
|
start
|
||||||
|
}
|
||||||
|
|
||||||
|
case "$1" in
|
||||||
|
start)
|
||||||
|
start
|
||||||
|
;;
|
||||||
|
stop)
|
||||||
|
stop
|
||||||
|
;;
|
||||||
|
restart|reload)
|
||||||
|
restart
|
||||||
|
;;
|
||||||
|
permanent_on)
|
||||||
|
rm /etc/kvm/ssh_stop
|
||||||
|
start
|
||||||
|
;;
|
||||||
|
permanent_off)
|
||||||
|
touch /etc/kvm/ssh_stop
|
||||||
|
stop
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "Usage: $0 {start|stop|restart|permanent_on|permanent_off}"
|
||||||
|
exit 1
|
||||||
|
esac
|
||||||
|
|
||||||
|
exit $?
|
||||||
|
|
||||||
50
kvmapp/system/init.d/S95nanokvm
Executable file
50
kvmapp/system/init.d/S95nanokvm
Executable file
@@ -0,0 +1,50 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
# nanokvm Rev3.0
|
||||||
|
|
||||||
|
case "$1" in
|
||||||
|
start)
|
||||||
|
echo -n kvm > /boot/hostname.prefix
|
||||||
|
cp /mnt/data/sensor_cfg.ini.LT /mnt/data/sensor_cfg.ini
|
||||||
|
|
||||||
|
str_value=$(cat /sys/class/cvi-base/base_uid | awk '{print $2}')
|
||||||
|
first_uint=$(echo $str_value | cut -d'_' -f1)
|
||||||
|
second_uint=$(echo $str_value | cut -d'_' -f2)
|
||||||
|
result="$first_uint$second_uint"
|
||||||
|
echo $result > /device_key
|
||||||
|
|
||||||
|
iptables -A INPUT -i eth0 -p tcp --dport 80 -m state --state NEW,ESTABLISHED -j ACCEPT
|
||||||
|
iptables -A OUTPUT -o eth0 -p tcp --sport 80 -m state --state ESTABLISHED -j ACCEPT
|
||||||
|
iptables -A OUTPUT -o eth0 -p tcp --dport 22 -m state --state NEW,ESTABLISHED -j ACCEPT
|
||||||
|
iptables -A INPUT -i eth0 -p tcp --sport 22 -m state --state ESTABLISHED -j ACCEPT
|
||||||
|
iptables -A OUTPUT -o eth0 -p tcp --sport 8000 -m state --state ESTABLISHED -j DROP
|
||||||
|
|
||||||
|
cp -r /kvmapp/kvm_system /tmp/
|
||||||
|
/tmp/kvm_system/kvm_system &
|
||||||
|
|
||||||
|
cp -r /kvmapp/server /tmp/
|
||||||
|
/tmp/server/NanoKVM-Server &
|
||||||
|
;;
|
||||||
|
stop)
|
||||||
|
killall kvm_system
|
||||||
|
killall NanoKVM-Server
|
||||||
|
rm -r /tmp/kvm_system
|
||||||
|
rm -r /tmp/server
|
||||||
|
echo "OK"
|
||||||
|
;;
|
||||||
|
restart)
|
||||||
|
killall kvm_system
|
||||||
|
killall NanoKVM-Server
|
||||||
|
rm -r /tmp/kvm_system
|
||||||
|
rm -r /tmp/server
|
||||||
|
|
||||||
|
cp -r /kvmapp/kvm_system /tmp/
|
||||||
|
/tmp/kvm_system/kvm_system &
|
||||||
|
|
||||||
|
cp -r /kvmapp/server /tmp/
|
||||||
|
/tmp/server/NanoKVM-Server &
|
||||||
|
|
||||||
|
sync
|
||||||
|
|
||||||
|
echo "OK"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
114
kvmapp/system/init.d/S98tailscaled
Executable file
114
kvmapp/system/init.d/S98tailscaled
Executable file
@@ -0,0 +1,114 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
DAEMON="tailscaled"
|
||||||
|
PIDFILE="/var/run/$DAEMON.pid"
|
||||||
|
|
||||||
|
# Set the port to listen on for incoming VPN packets.
|
||||||
|
# Remote nodes will automatically be informed about the new port number,
|
||||||
|
# but you might want to configure this in order to set external firewall
|
||||||
|
# settings.
|
||||||
|
PORT="41641"
|
||||||
|
|
||||||
|
# Extra flags you might want to pass to tailscaled.
|
||||||
|
FLAGS=""
|
||||||
|
|
||||||
|
# You need tailscaled at /usr/sbin to server, and tailscale at /usr/bin to operate
|
||||||
|
# STATIC version needed. Download page at https://pkgs.tailscale.com/stable/#static
|
||||||
|
PKG_URL_LATEST="https://pkgs.tailscale.com/stable/tailscale_latest_riscv64.tgz"
|
||||||
|
[ ! -x /usr/sbin/$DAEMON ] &&
|
||||||
|
echo "/usr/sbin/$DAEMON not found, please download it from $PKG_URL_LATEST" &&
|
||||||
|
echo "Then unpack it, copy $DAEMON to /usr/sbin and copy tailscale to /usr/bin" &&
|
||||||
|
exit 1
|
||||||
|
VERSION=$(/usr/sbin/$DAEMON --version|sed -n '1p'|xargs echo -n)
|
||||||
|
|
||||||
|
[ -x /usr/bin/tailscale ] || echo "/usr/bin/tailscale not found, your installation of tailscale may be broken"
|
||||||
|
|
||||||
|
# just for those need forwarding
|
||||||
|
[ ! -f /etc/sysctl.d/99-tailscale.conf ] &&
|
||||||
|
mkdir -p /etc/sysctl.d/ &&
|
||||||
|
echo "missing /etc/sysctl.d/99-tailscale.conf, try make it below:" &&
|
||||||
|
(tee /etc/sysctl.d/99-tailscale.conf <<EOF
|
||||||
|
net.ipv4.ip_forward = 1
|
||||||
|
net.ipv6.conf.all.forwarding = 1
|
||||||
|
EOF
|
||||||
|
) &&
|
||||||
|
echo "if this message repeats showing, please look at $0 if you need forwarding"
|
||||||
|
|
||||||
|
case "$1" in
|
||||||
|
start)
|
||||||
|
tailscale set --accept-dns=false
|
||||||
|
if [ -f /etc/kvm/GOMEMLIMIT ]; then
|
||||||
|
value=$(cat /etc/kvm/GOMEMLIMIT)
|
||||||
|
export GOMEMLIMIT="${value}MiB"
|
||||||
|
else
|
||||||
|
export GOMEMLIMIT=1024MiB
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "GOMEMLIMIT set to ${GOMEMLIMIT}"
|
||||||
|
printf "Starting $DAEMON[$VERSION]: "
|
||||||
|
start-stop-daemon -S -bmq -p "$PIDFILE" -x "/usr/sbin/$DAEMON" -- \
|
||||||
|
--state=/var/lib/tailscale/tailscaled.state \
|
||||||
|
--socket=/var/run/tailscale/tailscaled.sock \
|
||||||
|
--port=${PORT} \
|
||||||
|
$FLAGS
|
||||||
|
[ $? = 0 ] && echo "OK" || echo "FAIL"
|
||||||
|
;;
|
||||||
|
stop)
|
||||||
|
printf "Stopping $DAEMON: "
|
||||||
|
start-stop-daemon -K -p "$PIDFILE"
|
||||||
|
[ $? = 0 ] && (echo "OK"; rm -f "$PIDFILE") || echo "FAIL"
|
||||||
|
printf "cleaning tailscaled: "
|
||||||
|
/usr/sbin/$DAEMON --cleanup &>/dev/null
|
||||||
|
[ $? = 0 ] && echo "OK" || echo "FAIL"
|
||||||
|
;;
|
||||||
|
restart|reload)
|
||||||
|
$0 stop
|
||||||
|
$0 start
|
||||||
|
;;
|
||||||
|
doc)
|
||||||
|
cat <<EOF
|
||||||
|
To use tailscale, you need to meet these conditions below:
|
||||||
|
1. Both tailscale and tailscaled were installed.
|
||||||
|
2. At least one tailscale's account were registered.
|
||||||
|
(https://login.tailscale.com/start)
|
||||||
|
3. Your NanoKVM device must keep online.
|
||||||
|
|
||||||
|
Then, follow the steps below:
|
||||||
|
1. Login in https://login.tailscale.com on your PC
|
||||||
|
to enter into yout admin console.
|
||||||
|
2. Run 'tailscale login' on your device, and copy the link showed
|
||||||
|
to open on your PC, and confirm the auth.
|
||||||
|
3. Congratulations, your NanoKVM device is now on the tailnet, try to
|
||||||
|
visit it from all your device which on the same tailnet.
|
||||||
|
4. run 'tailscale set --webclient' and manage your device
|
||||||
|
on the web interface from localnet and tailenet.
|
||||||
|
|
||||||
|
Added: no more action to be repeat after your device reboot.
|
||||||
|
EOF
|
||||||
|
echo ""
|
||||||
|
cat <<EOF
|
||||||
|
为了正常使用 tailscale, 你需要满足以下几个条件:
|
||||||
|
1. tailscale 和 tailscaled 这两个静态链接的二进制程序
|
||||||
|
都已经正确安装在系统上。
|
||||||
|
2. 至少注册一个 tailscale 的帐号才能使用其服务。
|
||||||
|
(https://login.tailscale.com/start)
|
||||||
|
3. 你的 NanoKVM 设备必须保持在线。
|
||||||
|
|
||||||
|
然后,跟着以下步骤操作:
|
||||||
|
1. 在你的电脑上登录 https://login.tailscale.com 以进入控制台。
|
||||||
|
2. 在你的 NanoKVM ssh 终端上执行 'tailscale login', 然后复制
|
||||||
|
出现的链接到浏览器上,登录并通过验证。
|
||||||
|
3. 祝贺,你的 NanoKVM 现在已经加入了 tailnet 然后你可以从任意
|
||||||
|
同样已加入同一 tailnet 的设备去访问你的 NanoKVM。
|
||||||
|
4. 执行 'tailscale set --webclient' 然后你就可以从 '局域网' 和
|
||||||
|
'tailnet' 来访问特定网页,用来管理你的设备。
|
||||||
|
|
||||||
|
补充: 不需要重复上面的操作,哪怕你的设备重启过。
|
||||||
|
EOF
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "Usage: $0 {start|stop|restart}"
|
||||||
|
exit 1
|
||||||
|
esac
|
||||||
|
|
||||||
|
exit 0
|
||||||
BIN
kvmapp/system/ko/soph_mipi_rx.ko
Normal file
BIN
kvmapp/system/ko/soph_mipi_rx.ko
Normal file
Binary file not shown.
126
kvmapp/system/update-nanokvm.py
Executable file
126
kvmapp/system/update-nanokvm.py
Executable file
@@ -0,0 +1,126 @@
|
|||||||
|
import os
|
||||||
|
import shutil
|
||||||
|
import time
|
||||||
|
import zipfile
|
||||||
|
|
||||||
|
import requests
|
||||||
|
|
||||||
|
temporary = "/root/.kvm-cache/"
|
||||||
|
|
||||||
|
|
||||||
|
def mkdir():
|
||||||
|
is_exists = os.path.exists(temporary)
|
||||||
|
if is_exists:
|
||||||
|
shutil.rmtree(temporary)
|
||||||
|
os.mkdir(temporary)
|
||||||
|
print(f"create temporary directory {temporary}")
|
||||||
|
|
||||||
|
|
||||||
|
def read(file):
|
||||||
|
with open(file, "r") as f:
|
||||||
|
content = f.read()
|
||||||
|
return content.replace("\n", "")
|
||||||
|
|
||||||
|
|
||||||
|
def download_firmware():
|
||||||
|
print("download firmware...")
|
||||||
|
|
||||||
|
now = int(time.time())
|
||||||
|
url = f"https://cdn.sipeed.com/nanokvm/latest.zip?n={now}"
|
||||||
|
print(f"download from {url}")
|
||||||
|
|
||||||
|
response = requests.get(url)
|
||||||
|
|
||||||
|
if response.status_code != 200:
|
||||||
|
raise Exception(f"download firmware failed, status: {response.status_code}")
|
||||||
|
|
||||||
|
content_type = response.headers.get("content-type")
|
||||||
|
if content_type != "application/zip":
|
||||||
|
raise Exception(f"download firmware failed, content_type: {content_type}")
|
||||||
|
|
||||||
|
zip_file = f"{temporary}/latest.zip"
|
||||||
|
with open(zip_file, "wb") as f:
|
||||||
|
for chunk in response.iter_content(chunk_size=1024):
|
||||||
|
f.write(chunk)
|
||||||
|
|
||||||
|
with zipfile.ZipFile(zip_file, "r") as f:
|
||||||
|
f.extractall(temporary)
|
||||||
|
|
||||||
|
print("download firmware done")
|
||||||
|
|
||||||
|
|
||||||
|
def download_lib():
|
||||||
|
print("download lib...")
|
||||||
|
|
||||||
|
device_key = read("/device_key")
|
||||||
|
|
||||||
|
url = f"https://maixvision.sipeed.com/api/v1/nanokvm/encryption?uid={device_key}"
|
||||||
|
headers = {"token": "MaixVision2024"}
|
||||||
|
response = requests.get(url, headers=headers, stream=True)
|
||||||
|
|
||||||
|
if response.status_code != 200:
|
||||||
|
raise Exception(f"download lib failed, status: {response.status_code}")
|
||||||
|
|
||||||
|
content_type = response.headers.get("content-type")
|
||||||
|
if content_type != "application/octet-stream":
|
||||||
|
raise Exception(f"download lib failed, content_type: {content_type}")
|
||||||
|
|
||||||
|
lib_file = f"{temporary}/libmaixcam_lib.so"
|
||||||
|
with open(lib_file, "wb") as f:
|
||||||
|
f.write(response.content)
|
||||||
|
|
||||||
|
lib_dir = f"{temporary}/latest/kvm_system/dl_lib/"
|
||||||
|
shutil.copy(lib_file, lib_dir)
|
||||||
|
|
||||||
|
print("download lib done")
|
||||||
|
|
||||||
|
|
||||||
|
def update():
|
||||||
|
backup_dir = "/root/old"
|
||||||
|
firmware_dir = "/kvmapp"
|
||||||
|
|
||||||
|
if os.path.exists(backup_dir):
|
||||||
|
shutil.rmtree(backup_dir)
|
||||||
|
|
||||||
|
if os.path.exists(firmware_dir):
|
||||||
|
shutil.move(firmware_dir, backup_dir)
|
||||||
|
|
||||||
|
shutil.move(f"{temporary}/latest", firmware_dir)
|
||||||
|
|
||||||
|
|
||||||
|
def change_permissions():
|
||||||
|
for root, dirs, files in os.walk("/kvmapp"):
|
||||||
|
os.chmod(root, 0o755)
|
||||||
|
|
||||||
|
for file in files:
|
||||||
|
file_path = os.path.join(root, file)
|
||||||
|
os.chmod(file_path, 0o755)
|
||||||
|
|
||||||
|
print("change permissions done")
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
try:
|
||||||
|
print("stop service...")
|
||||||
|
os.system("/etc/init.d/S95nanokvm stop")
|
||||||
|
|
||||||
|
print("start update......")
|
||||||
|
|
||||||
|
mkdir()
|
||||||
|
download_firmware()
|
||||||
|
# download_lib()
|
||||||
|
update()
|
||||||
|
change_permissions()
|
||||||
|
|
||||||
|
version = read("/kvmapp/version")
|
||||||
|
print(f"update to {version} success.")
|
||||||
|
print("restart service\nthe nanokvm will reboot")
|
||||||
|
except Exception as e:
|
||||||
|
print(f"update failed\n{e}")
|
||||||
|
finally:
|
||||||
|
shutil.rmtree(temporary)
|
||||||
|
os.system("/etc/init.d/S95nanokvm restart")
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
Reference in New Issue
Block a user