OpenWRT系統為嵌入式設備的Linux作業系統,並且擁有龐大的軟件包管理功能。它提供了一個完全可寫的文件系統,可讓夥伴們從應用程序的供應商所提供的清單來配置。並允許使用者來自定義的設備,以適任任何應用程序。對於即將進行開發的夥伴們而言,OpenWRT系統能快速建構應用程序的框架,而無需重新建立該應用程序完整的固件。這也意味著可以進行完全自行定制的能力。
接下來,為夥伴們提供 基於Nuvoton MA35D1 IoT平台上,建構 OpenWRT 的方法,並搭載UVC Camera 來實現 IP CAM 監控的基本應用。
A. 硬件環境 : NuMaker-IoT-MA35D1EVB
主要核心MA35D1 規格如下:
MA35D16F987C with DDR3L (512 MB)
# Dual Cortex-A35 core running up to 800 MHz
# Cortex-M4 processor core running up to 180 MHz
# Real-Time Clock (RTC)
# Ethernet Poart : RGMII x1 and RMIIx1
# USB2.0: Host x1, USB2.0 Host/ Device dual role x1
# SDIO: SD CARD x1
# QSPI : QSPI FLASH
# NAND: NAND Flash
# GPIO/UART/I2C/I2S/ADC...
B. 軟體建置, 建議使用 Ubuntu 20.04-LTS 的設備來架設
1. 安裝 Docker
sudo apt-get update
sudo apt install apt-transport-https ca-certificates curl software-properties-common
sudo apt install build-essential ccache ecj fastjar file g++ gawk gettext git java-propose-classpath libelf-dev libncurses5-dev libncursesw5-dev libssl-dev python python2.7-dev python3 unzip wget python-distutils-extra python3-setuptools python3-dev rsync subversion swig time xsltproc zlib1g-dev libssl-dev device-tree-compiler
pip3 install pycryptodomex pyelftools pyusb usb crypto ecdsa crcmod tqdm pycryptodome
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu focal stable"
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io
git clone https://github.com/OpenNuvoton/MA35D1_Docker_Script.git
./build.sh
./join.sh
2. 新增並更換目錄
mkdir shared/openwrt
cd shared/openwrt
3. 配置git 環境
git config –global user.email sac_test@sacsys.com.tw
git config –global user.name ‘sac_test”
4. 下載 NUVOTON Openwrt 源代碼
sac@90440e70ea26:~/shared/openwrt$ git clone https://github.com/OpenNuvoton/MA35D1_OpenWrt.git
Cloning into 'MA35D1_OpenWrt'...
remote: Enumerating objects: 532695, done.
remote: Counting objects: 100% (61/61), done.
remote: Compressing objects: 100% (39/39), done.
remote: Total 532695 (delta 13), reused 44 (delta 9), pack-reused 532634
Receiving objects: 100% (532695/532695), 196.76 MiB | 1.19 MiB/s, done.
Resolving deltas: 100% (358529/358529), done.
Updating files: 100% (8566/8566), done.
sac@90440e70ea26:~/shared/openwrt$
5. 更新和安裝 OpenWRT原代碼
sac@312bc2ae8ba4:~/shared/openwrt/MA35D1_OpenWrt$ ./scripts/feeds update -a
Updating feed 'packages' from 'https://git.openwrt.org/feed/packages.git^78bcd00c13587571b5c79ed2fc3363aa674aaef7' ...
Create index file './feeds/packages.index'
Checking 'working-make'... ok.
Checking 'case-sensitive-fs'... ok.
Checking 'proper-umask'... ok.
Checking 'gcc'... ok.
Checking 'working-gcc'... ok.
Checking 'g++'... ok.
Checking 'working-g++'... ok.
Checking 'ncurses'... ok.
Checking 'perl-data-dumper'... ok.
Checking 'perl-findbin'... ok.
Checking 'perl-file-copy'... ok.
Checking 'perl-file-compare'... ok.
Checking 'perl-thread-queue'... ok.
sac@312bc2ae8ba4:~/shared/openwrt/MA35D1_OpenWrt$ ./scripts/feeds install -a
Installing package 'freeswitch-mod-bcg729' from telephony
Installing package 'freetdm' from telephony
Installing package 'kamailio' from telephony
Installing package 'libosip2' from telephony
Installing package 'miax' from telephony
Installing package 'pcapsipdump' from telephony
Installing package 'restund' from telephony
Installing package 'rtpengine' from telephony
Installing package 'rtpproxy' from telephony
Installing package 'sipgrep' from telephony
Installing package 'sipp' from telephony
Installing package 'siproxd' from telephony
Installing package 'sngrep' from telephony
Installing package 'yate' from telephony
sac@312bc2ae8ba4:~/shared/openwrt/MA35D1_OpenWrt$
6. 配置並導入預設的內核設定文檔
sac@312bc2ae8ba4:~/shared/openwrt/MA35D1_OpenWrt$ make menuconfig
Collecting package info: done
configuration written to .config
*** End of the configuration.
*** Execute 'make' to start the build or try 'make help'.
sac@312bc2ae8ba4:~/shared/openwrt/MA35D1_OpenWrt$
sac@312bc2ae8ba4:~/shared/openwrt/MA35D1_OpenWrt$ make kernel_menuconfig
"Image/Build" squashfs
"Image/Build" ext4
time: target/linux/prereq#0.33#0.25#0.52
make[1] toolchain/install
make[2] tools/compile
make[3] -C tools/flock compile
make[3] -C tools/xz compile
make[3] -C tools/sed compile
make[3] -C tools/tar compile
make[3] -C tools/patch compile
make[3] -C tools/m4 compile
7. 配置完成開始編譯
sac@312bc2ae8ba4:~/shared/openwrt/MA35D1_OpenWrt$ make
8. 編譯完成後,執行燒錄,值得注意的是需離開 Docker 後才能正確的燒錄成功
user@ubuntu:~/MA35D1/MA35D1_NuWriter$ lsusb
Bus 001 Device 008: ID 0416:5963 Winbond Electronics Corp.
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 004: ID 0e0f:0008 VMware, Inc. VMware Virtual USB Mouse
Bus 002 Device 003: ID 0e0f:0002 VMware, Inc. Virtual USB Hub
Bus 002 Device 002: ID 0e0f:0003 VMware, Inc. Virtual Mouse
Bus 002 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
user@ubuntu:~/MA35D1/MA35D1_NuWriter$ sudo python3 ./nuwriter.py -a ./ddrimg/enc_ddr3_winbond_512mb.bin
Successfully attached 1 device(s)
==== NAND ====
Page per block: 64
Page size: 2048
Block per flash: 4096
Bad block count: 0
Spare size: 64
Is uer config: 0
==== SPI NOR ====
ID: 0
Is uer config: 0
Quad read cmd: 0
Read sts cmd: 0
Write sts cmd: 0
Sts value: 0
Dummy byte: 0
==== eMMC ====
Block: 0
Reserved: 0
==== SPI NAND ====
Is uer config: 0
ID: 15710755
Page size: 2048
Spare size: 64
Quad read cmd: 107
Read sts cmd: 5
Write sts cmd: 1
Sts value: 2
Dummy byte: 1
Block per flash: 4096
Page per block: 64
Successfully get info from 1 device(s)
user@ubuntu:~/MA35D1/MA35D1_NuWriter$ sudo python3 ./nuwriter.py -e nand all
100%|##########
Successfully erased 1 device(s)
user@ubuntu:~/MA35D1/MA35D1_NuWriter$ sudo python3
python3 python3.8 python3.8-config python3-config
user@ubuntu:~/MA35D1/MA35D1_NuWriter$ sudo python3 ./nuwriter.py -w nand ../MA35D1_
MA35D1_Docker_Script/ MA35D1_NuWriter/
user@ubuntu:~/MA35D1/MA35D1_NuWriter$ sudo python3 ./nuwriter.py -w nand ../MA35D1_
MA35D1_Docker_Script/ MA35D1_NuWriter/
user@ubuntu:~/MA35D1/MA35D1_NuWriter$ sudo python3 ./nuwriter.py -w nand /home/user/openwrt/MA35D1_OpenWrt/bin/targets/ma35d1/iot/openwrt-ma35d1-iot-iot-
openwrt-ma35d1-iot-iot-128m-header-nand.bin
openwrt-ma35d1-iot-iot-128m.manifest
openwrt-ma35d1-iot-iot-128m-pack-nand.bin
openwrt-ma35d1-iot-iot-128m-rootfs.tar.gz
openwrt-ma35d1-iot-iot-128m-squashfs-firmware.bin
openwrt-ma35d1-iot-iot-128m-squashfs-sysupgrade.bin
openwrt-ma35d1-iot-iot-128m-uImage
openwrt-ma35d1-iot-iot-512m-header-nand.bin
openwrt-ma35d1-iot-iot-512m.manifest
openwrt-ma35d1-iot-iot-512m-pack-nand.bin
openwrt-ma35d1-iot-iot-512m-rootfs.tar.gz
openwrt-ma35d1-iot-iot-512m-squashfs-firmware.bin
openwrt-ma35d1-iot-iot-512m-squashfs-sysupgrade.bin
openwrt-ma35d1-iot-iot-512m-uImage
user@ubuntu:~/MA35D1/MA35D1_NuWriter$ sudo python3 ./nuwriter.py -w nand /home/user/openwrt/MA35D1_OpenWrt/bin/targets/ma35d1/iot/openwrt-ma35d1-iot-iot-512m-pack-nand.bin
Waiting for unpack Images ...
check pack file crc32 ...
Programming 1/7: 100%|##########
Programming 2/7: 100%|##########
Programming 3/7: 100%|##########
Programming 4/7: 100%|##########
Programming 5/7: 100%|##########
Programming 6/7: 100%|##########
Programming 7/7: 100%|##########
Successfully programmed 1 device(s)
9. 執行到此,夥伴們已經可以看到開機的訊息了對吧?
INFO: ma35d1 config setup
INFO: 1.25V
WARNING: CA-PLL is 800000000 Hz without PSCI setting.
POR: 0x900
INFO: Boot from NAND
INFO: NAND: Size 1024MB, Page 2048, pages per block 64, oob size 64, bit correct 8
NOTICE: BL2: v2.3(release):OpenWrt v2.3-3 (ma35d1-cpu800-wb-512m)
…
…
接下來為了順利執行攝相頭的應用,需額外增設內核的配置,小弟為大家整理出來所需要的清單如下。
CONFIG_PACKAGE_librt=y
CONFIG_PACKAGE_libstdcpp=y
CONFIG_PACKAGE_kmod-input-core=y
CONFIG_PACKAGE_kmod-nls-base=y
CONFIG_PACKAGE_kmod-dma-buf=y
CONFIG_PACKAGE_kmod-usb-core=y
CONFIG_PACKAGE_kmod-usb-ehci=y
CONFIG_PACKAGE_kmod-usb2=y
CONFIG_PACKAGE_kmod-video-core=y
CONFIG_PACKAGE_kmod-video-cpia2=y
CONFIG_PACKAGE_kmod-video-gspca-core=y
CONFIG_PACKAGE_kmod-video-pwc=y
CONFIG_PACKAGE_kmod-video-uvc=y
CONFIG_PACKAGE_kmod-video-videobuf2=y
CONFIG_PACKAGE_libjpeg-turbo=y
CONFIG_PACKAGE_libprotobuf-c=y
CONFIG_PACKAGE_libuuid=y
CONFIG_PACKAGE_libv4l=y
CONFIG_PACKAGE_libzmq-nc=y
CONFIG_PACKAGE_mjpg-streamer=y
CONFIG_MJPG_STREAMER_V4L2=y
CONFIG_PACKAGE_mjpg-streamer-input-file=y
CONFIG_PACKAGE_mjpg-streamer-input-http=y
CONFIG_PACKAGE_mjpg-streamer-input-uvc=y
CONFIG_PACKAGE_mjpg-streamer-output-file=y
CONFIG_PACKAGE_mjpg-streamer-output-http=y
CONFIG_PACKAGE_mjpg-streamer-output-rtsp=y
CONFIG_PACKAGE_mjpg-streamer-output-zmq=y
CONFIG_PACKAGE_mjpg-streamer-www-simple=y
接下來為夥伴們演示 OpenWRT軟路由的基本頁面,在使用 ifconfig -a 得知網關的位址為 192.168.0.175時,我們可以在熟悉的瀏覽器上鍵入 IP 位置,來登入軟路由的管理頁面。
如下圖所示,能得知 Nuvoton MA35D1-IoT的系統信息。
C. 再來為夥伴們演示如何透過軟路由的camera 來實現 IP CAM的應用。
1. 配置攝像頭輸入的資料所期望的分辦率和偵數,也可同時配置輸出串口,本次演練是使用預設的串口 8080,並搭配方便又容易取得的 USB攝像頭。
root@OpenWrt:/# mjpg_streamer -i "input_uvc.so -r HD -f 30 -d /dev/video0" -o "output_http.so"
MJPG Streamer Version.: 2.0
i: Using V4L2 device.: /dev/video0
i: Desired Resolution: 1280 x 720
i: Frames Per Second.: 30
i: Format............: JPEG
i: TV-Norm...........: DEFAULT
root@OpenWrt:/#
root@OpenWrt:/# /etc/init.d/mjpg-streamer enable
root@OpenWrt:/# /etc/init.d/mjpg-streamer start
root@OpenWrt:/#
此時我們已經可以在同一網域下,使用行動裝置或是電腦的瀏覽器來透過網關的IP位址監看串流的影像。
夥伴們一定很好奇,可以遠端查看監控畫面,是否能將攝像頭畫面錄製下來呢?小弟再多新增一個方法讓來錄影
接上SD card
umount /dev/sda1
e2fsck /dev/sda1
mount /dev/sda1 /mnt
mjpg_streamer -i "input_uvc.so -d /dev/video0 " -o "output_http.so -p 8080 -o" -o "output_file12h.so -f /mnt -d 1000"
本次的演練就到此,有興趣的夥伴們,可以一起來探討和研究,謝謝。
►場景應用圖
►產品實體圖
►展示板照片
►方案方塊圖
►核心技術優勢
MA35D1 特色: 1. 核心為 A35與M4的集成,各司其職; 2. 獨立的加密島,系統更加安全; 3. 兩種封裝(LQFP與BGA),依照不同應用,多種選擇; 4. 內涵記憶體(128MB/256MB/512MB),不須外掛,簡化設計; 5. 介面豐富,應用多樣;
►方案規格
處理器(MPU): NUVOTON MA35D1; 網路接口 : 有線網路 RJ45 x2 (RGMII), 無線網路(SDIO WIFI module); 相機規格: 720P @ 30; 作業系統: OpenWRT;