一、准备环境 系统环境:ubuntu-18.04.4-server-amd64
APT:
1 2 sudo apt-get install -y lib32ncurses5 lib32ncursesw5-dev lib32z1 sudo apt-get install -y make u-boot-tools qemu qemu-user-static tclsh unzip
格式化工具:HPUSBDisk v2.0.6 格式化卷标:boot
拷贝顺序
MLO
u-boot.img
uImage
ubi.img
二、准备文件
~/gcc-linaro-arm-linux-gnueabihf-4.7-2013.03-20130313_linux.tar.bz2
~/u-boot-nand-v6-2017-10-11.tar.gz
~/IOT-BOX-V6-kernel-2017-11-01.tar.gz
~/IOT-BOX-V6-rootfs.tar.gz
~/ready/.config
~/ready/timeconst.pl
三、配置交叉编译环境
注:普通用户和root用户都要配置1 2 3 4 sudo tar jxvf gcc-linaro-arm-linux-gnueabihf-4.7-2013.03-20130313_linux.tar.bz2 -C /opt vi ~/.bashrc export PATH=/opt/gcc-linaro-arm-linux-gnueabihf-4.7-2013.03-20130313_linux/bin:$PATH source ~/.bashrc
四、固件生成 4.1、准备
4.2、Build U-Boot 1 2 3 4 5 6 7 tar zxvf u-boot-nand-v6-2017-10-11.tar.gz cd ./u-boot-2013.01.01-psp06.00.00.00 ./build.sh cp -rf ./am335/MLO ../output/ cp -rf ./am335/u-boot.img ../output/ cd .. sudo rm -rf ./u-boot-2013.01.01-psp06.00.00.00
4.3、Build Kernel 1 2 3 4 5 6 7 8 tar zxvf IOT-BOX-V6-kernel-2017-11-01.tar.gz cd ./linux-3.2.0-psp04.06.00.11 cp -rf ../ready/.config ./ cp -rf ../ready/timeconst.pl ./kernel/ ./build.sh cp -rf ./uImage ../output/ cd .. sudo rm -rf ./linux-3.2.0-psp04.06.00.11
4.4、Build Root File System 1 2 3 4 5 6 7 8 9 10 11 sudo tar zxvf IOT-BOX-V6-rootfs.tar.gz sudo cp /usr/bin/qemu-arm-static ./rootfs/rootfs/usr/bin/ ./ms.sh -m ./rootfs/rootfs/ # 文件系统配置(见下一章节) ./ms.sh -u ./rootfs/rootfs/ cd ./rootfs sudo ./mkfs.ubifs -F -q -r ./rootfs/ -m 2048 -e 126976 -c 2047 -o ubifs.img sudo ./ubinize -o ubi.img -m 2048 -p 128KiB ubinize.cfg cp -rf ./ubi.img ../output/ cd .. sudo rm -rf ./rootfs
五、文件系统配置 5.1、文本文件 hostapd.conf
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 ##### hostapd configuration file ############################################## interface=wlan0 logger_syslog=-1 logger_syslog_level=2 logger_stdout=-1 logger_stdout_level=2 dump_file=/tmp/hostapd.dump ctrl_interface=/var/run/hostapd ctrl_interface_group=0 ##### IEEE 802.11 related configuration ####################################### ssid=HT-Link hw_mode=g channel=6 beacon_int=100 dtim_period=2 max_num_sta=255 rts_threshold=2347 fragm_threshold=2346 macaddr_acl=0 auth_algs=3 ignore_broadcast_ssid=0 wmm_enabled=1 wmm_ac_bk_cwmin=4 wmm_ac_bk_cwmax=10 wmm_ac_bk_aifs=7 wmm_ac_bk_txop_limit=0 wmm_ac_bk_acm=0 wmm_ac_be_aifs=3 wmm_ac_be_cwmin=4 wmm_ac_be_cwmax=10 wmm_ac_be_txop_limit=0 wmm_ac_be_acm=0 wmm_ac_vi_aifs=2 wmm_ac_vi_cwmin=3 wmm_ac_vi_cwmax=4 wmm_ac_vi_txop_limit=94 wmm_ac_vi_acm=0 wmm_ac_vo_aifs=2 wmm_ac_vo_cwmin=2 wmm_ac_vo_cwmax=3 wmm_ac_vo_txop_limit=47 wmm_ac_vo_acm=0 ##### IEEE 802.11n related configuration ###################################### ht_capab=[SHORT-GI-20][SHORT-GI-40][HT40] ##### IEEE 802.1X-2004 related configuration ################################## eapol_key_index_workaround=0 ##### Integrated EAP server ################################################### eap_server=0 ##### RADIUS client configuration ############################################# own_ip_addr=127.0.0.1 ##### WPA/IEEE 802.11i configuration ########################################## wpa=2 wpa_passphrase=12345678 wpa_key_mgmt=WPA-PSK wpa_pairwise=CCMP
udhcpd_wlan0.conf
1 2 3 4 5 6 7 interface wlan0 option subnet 255.255.255.0 opt router 192.168.5.1 opt dns 114.114.114.114 114.114.115.115 start 192.168.5.100 end 192.168.5.199 max_leases 100
check_update.sh
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 # shellcheck shell=sh UpdateNum=`ls /media/card | grep "htbox_update.tar.gz" | wc -l` if [ $UpdateNum -eq 1 ]; then rm -rf /home/WebOnBoard mv /media/card/htbox_update.tar.gz /home/ dd if=htbox_update.tar.gz |openssl des3 -d -k [email protected] | tar zxf - fi AutoRunNum=`ls /home/WebOnBoard | grep "antorun.sh" | wc -l` if [ $AutoRunNum -eq 1 ]; then /home/WebOnBoard/autorun.sh rm /home/WebOnBoard/autorun.sh fi sleep 5 if [ $UpdateNum -eq 1 ]; then reboot exit 0 fi if [ $AutoRunNum -eq 1 ]; then reboot exit 0 fi
sztenv
1 2 3 4 5 6 7 8 9 10 11 12 #!/bin/sh cd /home/WebOnBoard ./auto_start.sh & #ntpdate 0.pool.ntp.org #if [ "$?" == 0 ] #then # hwclock -w #else # reboot #fi
interfaces
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 # /etc/network/interfaces -- configuration file for ifup(8), ifdown(8) # The loopback interface auto lo iface lo inet loopback iface eth0 inet dhcp iface eth1 inet static address 192.168.3.1 netmask 255.255.255.0 gateway 192.168.3.1 iface wlan0 inet static address 192.168.5.1 netmask 255.255.255.0 gateway 192.168.5.1 iface br-vpn inet static address 192.168.3.1 netmask 255.255.255.0 gateway 192.168.3.1
inittab
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 # /etc/inittab: init(8) configuration. # $Id: inittab,v 1.91 2002/01/25 13:35:21 miquels Exp $ # The default runlevel. id:5:initdefault: # Boot-time system configuration/initialization script. # This is run first except when booting in emergency (-b) mode. si::sysinit:/etc/init.d/rcS # What to do in single-user mode. ~~:S:wait:/sbin/sulogin # /etc/init.d executes the S and K scripts upon change # of runlevel. # # Runlevel 0 is halt. # Runlevel 1 is single-user. # Runlevels 2-5 are multi-user. # Runlevel 6 is reboot. l0:0:wait:/etc/init.d/rc 0 l1:1:wait:/etc/init.d/rc 1 l2:2:wait:/etc/init.d/rc 2 l3:3:wait:/etc/init.d/rc 3 l4:4:wait:/etc/init.d/rc 4 l5:5:wait:/etc/init.d/rc 5 l6:6:wait:/etc/init.d/rc 6 # Normally not reached, but fallthrough in case of emergency. z6:6:respawn:/sbin/sulogin #S:2345:respawn:/sbin/getty -I root 115200 ttyO0 usr:2345:respawn:/bin/login # /sbin/getty invocations for the runlevels. # # The "id" field MUST be the same as the last # characters of the device (after "tty"). # # Format: # <id>:<runlevels>:<action>:<process> # #1:2345:respawn:/sbin/getty 38400 tty1
5.2、删除不必要的内容 1 2 3 4 5 # 删除网页服务 rm -rf /etc/rc5.d/S20boa # 删除默认4G程序 rm -rf /etc/quectel-CM rm -rf /etc/yiyuan_4g
5.3、恢复4G程序 1 2 cp quectel-CM /etc/ cp yiyuan_4g /usr/bin/
5.4、新增GPIO程序 - 使能Wi-Fi模块用 1 2 cp gpio_test /usr/bin/ cp gpio_test_new /usr/bin/
5.5、加载Wi-Fi模块、程序、配置文件 1 2 3 4 5 cp 8188eu.ko /lib/modules/3.2.0/ cp hostapd /usr/bin/ cp hostapd.conf /etc/ cp udhcpd*.conf /etc/ touch /var/lib/misc/udhcpd.leases
5.6、创建net转发 1 echo "net.ipv4.ip_forward=0" >> /etc/sysctl.conf
5.7、SD卡插入相关 1 2 3 4 5 6 7 cp check_update.sh /etc/init.d/ mkdir -p /media/card echo "SUBSYSTEM==\"block\", ACTION==\"add\" RUN+=\"/etc/udev/scripts/mount.sh\"" >> /etc/udev/rules.d/automount.rules echo "SUBSYSTEM==\"block\", ACTION==\"remove\" RUN+=\"/etc/udev/scripts/mount.sh\"" >> /etc/udev/rules.d/automount.rules echo "SUBSYSTEM==\"block\", ACTION==\"add\" RUN+=\"/etc/init.d/check_update.sh\"" >> /etc/udev/rules.d/automount.rules echo "/dev/mmcblk0p1 /media/card auto defaults,sync 0 0" >> /etc/fstab
5.8、系统相关 1 2 3 4 5 6 7 8 9 # 自启动文件 cp sztenv /etc/init.d/ # 网络相关 cp interfaces /etc/network/ # 用户相关 cp inittab /etc/ # 记得修改root密码 passwd root
5.9、库配置 sshd.sh
1 2 3 4 5 6 7 8 9 10 11 12 #!/bin/sh case "$1" in start) echo -n "Starting SSHD" /usr/local/sbin/sshd echo . ;; *) echo "Uasges: ./sshd.sh {star}t" exit 1 esac
5.9.1、删除残余库 1 2 3 4 5 6 7 8 # rm openssl rm -rf /usr/lib/libssl* /lib/libcrypto* # rm zlib rm -rf /usr/lib/libz* # rm curl rm -rf /usr/bin/curl /usr/lib/libcurl* # rm sqlite3 rm -rf /usr/sbin/sqlite* /usr/lib/libsqlite*
5.9.2、导入openssl库 1 2 3 4 5 6 7 8 9 cp openssl /usr/bin/ cp libssl.so.1.0.0 /usr/lib/ cd /usr/lib/ ln -s libssl.so.1.0.0 libssl.so cp libcrypto.so.1.0.0 /lib/ cd /lib/ ln -s libcrypto.so.1.0.0 libcrypto.so
5.9.3、导入系统自带其他库 1 2 3 tar zxvf zlib-1.2.11.tar.gz -C /usr/ tar zxvf curl-7.65.1.tar.gz -C /usr/ tar zxvf sqlite-3.28.tar.gz -C /usr/
5.9.4、导入openssh 1 2 3 4 5 6 7 8 9 mkdir -p /usr/local tar zxvf openssh-8.0p1.tar.gz -C /usr/local/ mkdir -p /var/run/ mkdir -p /var/empty/ echo "sshd:*:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin" >> /etc/passwd echo "sshd:*:74:" >> /etc/group cp sshd.sh /etc/init.d/ cd /etc/rc5.d/ ln -s ../init.d/sshd.sh S99sshd.sh
5.9.5、导入其他库 1 2 3 4 5 6 7 8 9 tar zxvf openvpn-2.3.18.tar.gz -C /usr/ tar zxvf jq-1.5.tar.gz -C /usr/ tar zxvf bridge-utils-1.5.tar.gz -C /usr/ tar zxvf ntp-4.2.8p13.tar.gz -C /usr/ tar zxvf bzip2-1.0.6.tar.gz -C /usr/ tar zxvf gdbm-1.18.1.tar.gz -C /usr/ tar zxvf readline-8.0.tar.gz -C /usr/
5.9.6、导入采集用库 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 tar zxvf paho.mqtt.c-1.3.1.tar.gz -C /usr/ cp libcjson.so.1.7.12 /usr/lib/ cp libcjson_utils.so.1.7.12 /usr/lib/ cp libmodbus.so.5.1.0 /usr/lib/ cp libsnap7.so /usr/lib/ cp libstdc++.so.6.0.17 /usr/lib/ cd /usr/lib/ ln -s libcjson.so.1.7.12 libcjson.so.1 ln -s libcjson.so.1 libcjson.so ln -s libcjson_utils.so.1.7.12 libcjson_utils.so.1 ln -s libcjson_utils.so.1 libcjson_utils.so ln -s libmodbus.so.5.1.0 libmodbus.so.5 ln -s libmodbus.so.5 libmodbus.so ln -s libstdc++.so.6.0.17 libstdc++.so.6
5.9.7、导入python /root/.pip/pip.conf
1 2 3 4 [global] index-url = http://pypi.douban.com/simple [install] trusted-host=pypi.douban.com
1 2 3 4 5 6 7 8 9 10 tar zxvf python-2.7.16.tar.gz -C /usr/ mkdir -p /root/.cache mkdir -p /root/.pip vi /root/.pip/pip.conf curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py python get-pip.py pip install flask-appconfig flask-bootstrap flask-debug flask-nav flask-wtf flask-sqlalchemy gunicorn pyserial python-can pip install six wsgiref python-dateutil pytz enum34 trollius futures pycparser ipaddress ipython rm -rf /root/.cache/pip rm -rf /home/cooky