Skip to content

Commit

Permalink
Merge pull request #15 from kasitoru/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
kasitoru authored Nov 12, 2023
2 parents 33f9093 + 71f551f commit 7252bc0
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 33 deletions.
51 changes: 24 additions & 27 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
BRANCH := main
BRANCH := main

ZLIB_VERSION := 1.2.13
OPENSSL_VERSION := 1.1.1s
CURL_VERSION := 7.87.0
ZLIB_VERSION := 1.3
OPENSSL_VERSION := 1.1.1w
CURL_VERSION := 8.4.0

TEMPORARY_DIR := temp
TEMPORARY_DIR := temp

FIRMWARE_SRC := firmware
FIRMWARE_DIR := $(TEMPORARY_DIR)/firmware
FIRMWARE_FILE := demo_hlc6.bin
FIRMWARE_SRC := firmware
FIRMWARE_DIR := $(TEMPORARY_DIR)/firmware
FIRMWARE_FILE := demo_hlc6.bin

CROSS_COMPILE := arm-himix100-linux
CCFLAGS := -march=armv7-a -mfpu=neon-vfpv4 -funsafe-math-optimizations
LDPATH := /opt/hisi-linux/x86-arm/arm-himix100-linux/target/usr/app/lib
CROSS_COMPILE := arm-himix100-linux
CCFLAGS := -march=armv7-a -mfpu=neon-vfpv4 -funsafe-math-optimizations
LDPATH := /opt/hisi-linux/x86-arm/arm-himix100-linux/target/usr/app/lib

.SILENT:
all: mkdirs install-libs application web curl chmod pack
Expand All @@ -22,44 +22,41 @@ application:
make -C "$(TEMPORARY_DIR)/application" CROSS_COMPILE="$(CROSS_COMPILE)-" CCFLAGS="$(CCFLAGS)" LDPATH="$(LDPATH)"
cp -f $(TEMPORARY_DIR)/application/bin/mjsxj02hl $(FIRMWARE_DIR)/app/bin
cp -f $(TEMPORARY_DIR)/application/bin/ipctool $(FIRMWARE_DIR)/rootfs/bin
cp -arf $(TEMPORARY_DIR)/application/lib/. $(FIRMWARE_DIR)/app/lib
cp -rf $(TEMPORARY_DIR)/application/lib/. $(FIRMWARE_DIR)/app/lib

web:
git clone --branch "$(BRANCH)" "https://github.com/kasitoru/mjsxj02hl_web" "$(TEMPORARY_DIR)/web"
make -C "$(TEMPORARY_DIR)/web" CROSS_COMPILE="$(CROSS_COMPILE)-" CCFLAGS="$(CCFLAGS)"
cp -arf $(TEMPORARY_DIR)/web/bin/. $(FIRMWARE_DIR)/app/bin
cp -arf $(TEMPORARY_DIR)/web/lib/. $(FIRMWARE_DIR)/app/lib
cp -arf $(TEMPORARY_DIR)/web/share/. $(FIRMWARE_DIR)/app/share
cp -arf $(TEMPORARY_DIR)/web/www/. $(FIRMWARE_DIR)/app/www
cp -rf $(TEMPORARY_DIR)/web/bin/. $(FIRMWARE_DIR)/app/bin
cp -rf $(TEMPORARY_DIR)/web/lib/. $(FIRMWARE_DIR)/app/lib
cp -rf $(TEMPORARY_DIR)/web/share/. $(FIRMWARE_DIR)/app/share
cp -rf $(TEMPORARY_DIR)/web/www/. $(FIRMWARE_DIR)/app/www

zlib:
wget -O "$(TEMPORARY_DIR)/zlib-$(ZLIB_VERSION).tar.gz" "http://www.zlib.net/zlib-$(ZLIB_VERSION).tar.gz"
wget -O "$(TEMPORARY_DIR)/zlib-$(ZLIB_VERSION).tar.gz" "https://www.zlib.net/fossils/zlib-$(ZLIB_VERSION).tar.gz"
tar -xf $(TEMPORARY_DIR)/zlib-$(ZLIB_VERSION).tar.gz -C $(TEMPORARY_DIR) && mv $(TEMPORARY_DIR)/zlib-$(ZLIB_VERSION) $(TEMPORARY_DIR)/zlib
cd $(TEMPORARY_DIR)/zlib && CROSS_PREFIX="$(CROSS_COMPILE)-" CFLAGS="$(CCFLAGS)" ./configure
make -C "$(TEMPORARY_DIR)/zlib"
cp -fP $(TEMPORARY_DIR)/zlib/libz.so* $(FIRMWARE_DIR)/rootfs/thirdlib
cp -fP $(TEMPORARY_DIR)/zlib/libz.so* $(LDPATH)

openssl: zlib
wget -O "$(TEMPORARY_DIR)/openssl-$(OPENSSL_VERSION).tar.gz" "https://www.openssl.org/source/openssl-$(OPENSSL_VERSION).tar.gz"
tar -xf $(TEMPORARY_DIR)/openssl-$(OPENSSL_VERSION).tar.gz -C $(TEMPORARY_DIR) && mv $(TEMPORARY_DIR)/openssl-$(OPENSSL_VERSION) $(TEMPORARY_DIR)/openssl
cd $(TEMPORARY_DIR)/openssl && ./Configure linux-armv4 shared zlib no-hw no-afalgeng no-async no-aria no-asm no-autoerrinit no-autoload-config no-bf no-blake2 no-camellia no-capieng no-cast no-chacha no-cmac no-cms no-comp no-ct no-deprecated no-dgram no-dso no-dtls no-dynamic-engine no-ec no-ec2m no-ecdh no-ecdsa no-err no-filenames no-gost no-makedepend no-mdc2 no-multiblock no-pinshared no-ocb no-poly1305 no-posix-io no-psk no-rc2 no-rc4 no-rdrand no-rfc3779 no-rmd160 no-scrypt no-seed no-siphash no-sm2 no-sm3 no-sm4 no-srtp no-sse2 no-ssl no-static-engine no-tests no-threads no-ts no-whirlpool no-idea no-srp
make -C "$(TEMPORARY_DIR)/openssl" CROSS_COMPILE="$(CROSS_COMPILE)-" CFLAGS="$(CCFLAGS)" LDFLAGS="-L$(LDPATH)"
make -C "$(TEMPORARY_DIR)/openssl" CROSS_COMPILE="$(CROSS_COMPILE)-" CFLAGS="$(CCFLAGS)"
cp -fP $(TEMPORARY_DIR)/openssl/libcrypto.so* $(FIRMWARE_DIR)/rootfs/thirdlib
cp -fP $(TEMPORARY_DIR)/openssl/libssl.so* $(FIRMWARE_DIR)/rootfs/thirdlib
cp -fP $(TEMPORARY_DIR)/openssl/libcrypto.so* $(LDPATH)
cp -fP $(TEMPORARY_DIR)/openssl/libssl.so* $(LDPATH)
ln -fs ./ $(TEMPORARY_DIR)/openssl/lib

curl: openssl zlib
curl: zlib openssl
wget -O "$(FIRMWARE_DIR)/rootfs/usr/local/cacert.pem" "https://curl.haxx.se/ca/cacert.pem"
wget -O "$(TEMPORARY_DIR)/curl-$(CURL_VERSION).tar.gz" "https://curl.se/download/curl-$(CURL_VERSION).tar.gz"
tar -xf $(TEMPORARY_DIR)/curl-$(CURL_VERSION).tar.gz -C $(TEMPORARY_DIR) && mv $(TEMPORARY_DIR)/curl-$(CURL_VERSION) $(TEMPORARY_DIR)/curl
cd $(TEMPORARY_DIR)/curl && ./configure --host="$(CROSS_COMPILE)" CC="$(CROSS_COMPILE)-gcc" CFLAGS="$(CCFLAGS)" LDFLAGS="-L$(LDPATH)" --enable-shared --disable-static --disable-manual --disable-libcurl-option --with-openssl --with-zlib --disable-ipv6 --disable-dict --disable-file --disable-ftp --disable-gopher --disable-imap --disable-mqtt --disable-pop3 --disable-smtp --disable-telnet --disable-tftp --disable-smb --with-ca-bundle=/usr/local/cacert.pem
cd $(TEMPORARY_DIR)/curl && ./configure --host="$(CROSS_COMPILE)" CC="$(CROSS_COMPILE)-gcc" CFLAGS="$(CCFLAGS)" LDFLAGS="-Wl,-rpath-link $(CURDIR)/$(TEMPORARY_DIR)/openssl" --enable-shared --disable-static --disable-manual --disable-libcurl-option --with-openssl=$(CURDIR)/$(TEMPORARY_DIR)/openssl --with-zlib=$(CURDIR)/$(TEMPORARY_DIR)/zlib --disable-ipv6 --disable-dict --disable-file --disable-ftp --disable-gopher --disable-imap --disable-mqtt --disable-pop3 --disable-smtp --disable-telnet --disable-tftp --disable-smb --with-ca-bundle=/usr/local/cacert.pem
make -C "$(TEMPORARY_DIR)/curl"
cp -f $(TEMPORARY_DIR)/curl/src/.libs/curl $(FIRMWARE_DIR)/rootfs/bin
ln -fs ../../bin/curl $(FIRMWARE_DIR)/rootfs/usr/bin/curl
cp -fP $(TEMPORARY_DIR)/curl/lib/.libs/libcurl.so* $(FIRMWARE_DIR)/rootfs/thirdlib
cp -fP $(TEMPORARY_DIR)/curl/lib/.libs/libcurl.so* $(LDPATH)

chmod:
# all
Expand Down Expand Up @@ -115,7 +112,7 @@ endif
echo $(FIRMWARE_VERB) > $(FIRMWARE_DIR)/app/share/.version

install-libs:
-cp -arf $(FIRMWARE_DIR)/app/lib/. $(LDPATH)
-cp -arf $(FIRMWARE_DIR)/rootfs/lib/. $(LDPATH)
-cp -arf $(FIRMWARE_DIR)/rootfs/thirdlib/. $(LDPATH)
-cp -rf $(FIRMWARE_DIR)/app/lib/. $(LDPATH)
-cp -rf $(FIRMWARE_DIR)/rootfs/lib/. $(LDPATH)
-cp -rf $(FIRMWARE_DIR)/rootfs/thirdlib/. $(LDPATH)

25 changes: 22 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,35 @@ Build tools for mjsxj02hl firmware

**Attention! This firmware is no longer supported by the author. We recommend using [OpenIPC](https://github.com/OpenIPC/device-mjsxj02hl).**

## Preparation

## Dependencies
1. Install dependencies:

```bash
sudo apt install u-boot-tools dbus
pip install click
sudo apt install git cmake lib32z1 lib32stdc++6 u-boot-tools dbus python3-pip dos2unix
pip3 install click
```

2. Install Hi3518Ev300 toolchain:

```bash
tar -zxf arm-himix100-linux.tgz
cd arm-himix100-linux
sudo ./arm-himix100-linux.install
sudo mkdir -p /opt/hisi-linux/x86-arm/arm-himix100-linux/target/usr/app/lib
sudo chmod 777 /opt/hisi-linux/x86-arm/arm-himix100-linux/target/usr/app/lib
gnome-session-quit
```

## Usage

Clone the repository:

```bash
git clone https://github.com/kasitoru/mjsxj02hl_firmware
cd mjsxj02hl_firmware
```

### Build firmware:
```bash
make FIRMWARE_VER=x.y.z
Expand Down
22 changes: 20 additions & 2 deletions firmware/app/bin/init_app.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,23 @@ fi

# Create empty configuration file if it is missing
if [ ! -f /usr/app/share/mjsxj02hl.conf ]; then
echo "Create empty configuration file..."
touch /usr/app/share/mjsxj02hl.conf
chmod 644 /usr/app/share/mjsxj02hl.conf
fi

# Create default run.sh file if it is missing
if [ ! -f /configs/run.sh ]; then
echo "reate default run.sh file..."
touch /configs/run.sh
echo "#"'!'"/bin/sh" >> /configs/run.sh
echo >> /configs/run.sh
echo "# Launching the watchdog" >> /configs/run.sh
echo "watchdog.sh &" >> /configs/run.sh
echo >> /configs/run.sh
chmod 755 /configs/run.sh
fi

# Connect to Wi-Fi
ifconfig wlan0 up
if [ -f /etc/wpa_supplicant.conf ]; then
Expand Down Expand Up @@ -76,9 +89,14 @@ tcpsvd -vE 0.0.0.0 21 ftpd -w / &
echo "Starting main application..."
mjsxj02hl &

# Execute run.sh from configs
if [ -f /configs/run.sh ]; then
echo "Execute /configs/run.sh script..."
/configs/run.sh &
fi

# Execute run.sh from sd-card
if [ -f /mnt/mmc/run.sh ]; then
echo "Execute /mnt/mmc/run.sh script..."
/mnt/mmc/run.sh
/mnt/mmc/run.sh &
fi

33 changes: 33 additions & 0 deletions firmware/app/bin/watchdog.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/sh

GATEWAY=${1:-"192.168.1.1"}

errors=0
while true; do
# Network connection
if ! ping -c 1 $GATEWAY &> /dev/null; then
echo "Reconnecting to an Access Point..."
killall udhcpc wpa_supplicant
ifconfig wlan0 down
ifconfig wlan0 up
wpa_supplicant -B -D nl80211 -i wlan0 -c /etc/wpa_supplicant.conf
udhcpc -b -i wlan0
errors=$((errors+1))
else
errors=0
fi
# Main application
if ! killall -0 mjsxj02hl &> /dev/null; then
echo "Restarting main application..."
mjsxj02hl &
errors=$((errors+1))
else
errors=0
fi
# Reboot if there are many errors
if [ $errors -ge 5 ]; then
echo "Too many errors! Rebooting the device..."
reboot
fi
sleep 10
done
2 changes: 1 addition & 1 deletion packer.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
# coding=utf-8

import os
Expand Down

0 comments on commit 7252bc0

Please sign in to comment.