Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for JetHome JetHub D1/H1 home automation controllers #3176

Merged
merged 7 commits into from Oct 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions config/boards/jethubj100.csc
@@ -0,0 +1,7 @@
# JetHub D1 (j100) Amlogic A113D quad core 512Mb/1Gb RAM SoC, eMMC 8/16Gb
BOARD_NAME="JetHub D1"
BOARDFAMILY="jethub"
BOOTCONFIG="jethub_j100_defconfig"
KERNEL_TARGET="current,edge"
PACKAGE_LIST_BOARD="libubootenv-tool apparmor rfkill bluetooth bluez bluez-tools python3-pip"
DEFAULT_CONSOLE="serial"
7 changes: 7 additions & 0 deletions config/boards/jethubj80.csc
@@ -0,0 +1,7 @@
# JetHub H1 (j80) Amlogic S905w quad core 1Gb RAM SoC, eMMC 8/16Gb
BOARD_NAME="JetHub H1"
BOARDFAMILY="jethub"
BOOTCONFIG="jethub_j80_defconfig"
KERNEL_TARGET="current,edge"
PACKAGE_LIST_BOARD="libubootenv-tool apparmor rfkill bluetooth bluez bluez-tools python3-pip"
DEFAULT_CONSOLE="serial"
87 changes: 87 additions & 0 deletions config/bootscripts/boot-jethub.cmd
@@ -0,0 +1,87 @@
# DO NOT EDIT THIS FILE
#
# Please edit /boot/armbianEnv.txt to set supported parameters
#

setenv load_addr "0x12000000"
setenv kernel_addr_r "0x14000000"
setenv ramdisk_addr_r "0x1A000000"
setenv fdt_addr_r "0x10800000"
setenv overlay_error "false"
# default values
setenv rootdev "/dev/mmcblk0p1"
setenv verbosity "1"
setenv console "serial"
setenv rootfstype "ext4"
setenv docker_optimizations "on"

# Show what uboot default fdtfile is
echo "U-boot default fdtfile: ${fdtfile}"
echo "Current variant: ${variant}"

# legacy kernel values from armbianEnv.txt
if test -e ${devtype} ${devnum} ${prefix}armbianEnv.txt; then
load ${devtype} ${devnum} ${load_addr} ${prefix}armbianEnv.txt
env import -t ${load_addr} ${filesize}
fi

# get PARTUUID of first partition on SD/eMMC it was loaded from
# mmc 0 is always mapped to device u-boot (2016.09+) was loaded from
if test "${devtype}" = "mmc"; then part uuid mmc ${devnum}:1 partuuid; fi

echo "Current fdtfile after armbianEnv: ${fdtfile}"

if test "${console}" = "serial"; then setenv consoleargs "console=ttyAML0,115200n8"; fi

setenv bootargs "root=${rootdev} rootwait rootflags=data=writeback rootfstype=${rootfstype} ${consoleargs} no_console_suspend consoleblank=0 coherent_pool=2M loglevel=${verbosity} fsck.fix=yes fsck.repair=yes net.ifnames=0 ${extraargs} ${extraboardargs}"

if test -n "${board_name}"; then setenv bootargs "${bootargs} board=${board}"; fi

if test -n "${ethaddr}"; then setenv bootargs "${bootargs} mac=${ethaddr}";
else if test -n "${mac}"; then setenv bootargs "${bootargs} mac=${mac}" ; fi
fi

if test -n "${serial}"; then setenv bootargs "${bootargs} serial=${serial}"; fi
if test -n "${usid}"; then setenv bootargs "${bootargs} usid=${usid}"; fi

if test "${docker_optimizations}" = "on"; then setenv bootargs "${bootargs} cgroup_enable=memory swapaccount=1"; fi
echo "Mainline bootargs: ${bootargs}"

load ${devtype} ${devnum} ${ramdisk_addr_r} ${prefix}uInitrd
load ${devtype} ${devnum} ${kernel_addr_r} ${prefix}Image
load ${devtype} ${devnum} ${fdt_addr_r} ${prefix}dtb/${fdtfile}
fdt addr ${fdt_addr_r}
fdt resize 65536
for overlay_file in ${overlays}; do
if load ${devtype} ${devnum} ${load_addr} ${prefix}dtb/amlogic/overlay/${overlay_prefix}-${overlay_file}.dtbo; then
echo "Applying kernel provided DT overlay ${overlay_prefix}-${overlay_file}.dtbo"
fdt apply ${load_addr} || setenv overlay_error "true"
fi
done

for overlay_file in ${user_overlays}; do
if load ${devtype} ${devnum} ${load_addr} ${prefix}overlay-user/${overlay_file}.dtbo; then
echo "Applying user provided DT overlay ${overlay_file}.dtbo"
fdt apply ${load_addr} || setenv overlay_error "true"
fi
done

if test "${overlay_error}" = "true"; then
echo "Error applying DT overlays, restoring original DT"
load ${devtype} ${devnum} ${fdt_addr_r} ${prefix}dtb/${fdtfile}
else
if load ${devtype} ${devnum} ${load_addr} ${prefix}dtb/amlogic/overlay/${overlay_prefix}-fixup.scr; then
echo "Applying kernel provided DT fixup script (${overlay_prefix}-fixup.scr)"
source ${load_addr}
fi
if test -e ${devtype} ${devnum} ${prefix}fixup.scr; then
load ${devtype} ${devnum} ${load_addr} ${prefix}fixup.scr
echo "Applying user provided fixup script (fixup.scr)"
source ${load_addr}
fi
fi

booti ${kernel_addr_r} ${ramdisk_addr_r} ${fdt_addr_r}

# Recompile with:
# mkimage -C none -A arm -T script -d /boot/boot.cmd /boot/boot.scr
2 changes: 1 addition & 1 deletion config/kernel/linux-meson64-current.config
Expand Up @@ -4149,7 +4149,7 @@ CONFIG_GPIO_GW_PLD=m
CONFIG_GPIO_MAX7300=m
CONFIG_GPIO_MAX732X=m
CONFIG_GPIO_PCA953X=m
# CONFIG_GPIO_PCA953X_IRQ is not set
CONFIG_GPIO_PCA953X_IRQ=y
CONFIG_GPIO_PCA9570=m
CONFIG_GPIO_PCF857X=m
CONFIG_GPIO_TPIC2810=m
Expand Down
2 changes: 1 addition & 1 deletion config/kernel/linux-meson64-edge.config
Expand Up @@ -4247,7 +4247,7 @@ CONFIG_GPIO_GW_PLD=m
CONFIG_GPIO_MAX7300=m
CONFIG_GPIO_MAX732X=m
CONFIG_GPIO_PCA953X=m
# CONFIG_GPIO_PCA953X_IRQ is not set
CONFIG_GPIO_PCA953X_IRQ=y
CONFIG_GPIO_PCA9570=m
CONFIG_GPIO_PCF857X=m
CONFIG_GPIO_TPIC2810=m
Expand Down
2 changes: 2 additions & 0 deletions config/sources/families/README.md
Expand Up @@ -15,3 +15,5 @@
| Allwinner sun9i : sunxi                             | virtual : qemu-virtual                           |
|| zynq : zynq |
|| jetson-nano : jetson-nano |
|| jethubj80 : meson64 |
|| jethubj100 : meson64 |
48 changes: 48 additions & 0 deletions config/sources/families/include/meson64_common.inc
Expand Up @@ -90,6 +90,54 @@ uboot_gxl_postprocess()
--bl33 bl33.bin.enc
}

# this helper function includes postprocess for s400 and its variants.
# $1 PATH for uboot blob repo
# $2 dir name in uboot blob repo
uboot_axg_postprocess_ng()
{
mv u-boot.bin bl33.bin

$1/blx_fix.sh $1/$2/bl30.bin \
$1/$2/zero_tmp \
$1/$2/bl30_zero.bin \
$1/$2/bl301.bin \
$1/$2/bl301_zero.bin \
$1/$2/bl30_new.bin bl30

python3 $1/acs_tool.py $1/$2/bl2.bin \
$1/$2/bl2_acs.bin \
$1/$2/acs.bin 0

$1/blx_fix.sh $1/$2/bl2_acs.bin \
$1/$2/zero_tmp \
$1/$2/bl2_zero.bin \
$1/$2/bl21.bin \
$1/$2/bl21_zero.bin \
$1/$2/bl2_new.bin bl2

$PKG_PREFIX$1/$2/aml_encrypt_axg --bl3sig --input $1/$2/bl30_new.bin \
--output bl30_new.bin.enc \
--level v3 --type bl30

$PKG_PREFIX$1/$2/aml_encrypt_axg --bl3sig --input $1/$2/bl31.img \
--output bl31.img.enc \
--level v3 --type bl31

$PKG_PREFIX$1/$2/aml_encrypt_axg --bl3sig --input bl33.bin --compress lz4 \
--output bl33.bin.enc \
--level v3 --type bl33

$PKG_PREFIX$1/$2/aml_encrypt_axg --bl2sig --input $1/$2/bl2_new.bin \
--output bl2.n.bin.sig

$PKG_PREFIX$1/$2/aml_encrypt_axg --bootmk \
--output u-boot.bin \
--bl2 bl2.n.bin.sig \
--bl30 bl30_new.bin.enc \
--bl31 bl31.img.enc \
--bl33 bl33.bin.enc --level v3
}

# this helper function includes postprocess for u200 and its variants.
# $1 PATH for uboot blob repo
# $2 family g12a or g12b
Expand Down
183 changes: 183 additions & 0 deletions config/sources/families/jethub.conf
@@ -0,0 +1,183 @@
source "${BASH_SOURCE%/*}/include/meson64_common.inc"

CPUMIN=100000
GOVERNOR=conservative
BOOTBRANCH="tag:v2021.10"
BOOTPATCHDIR=${BOOTPATCHDIR:-"u-boot-jethub"}
BOOTSCRIPT="boot-jethub.cmd:boot.cmd"

if [[ $BOARD == jethubj80 ]]; then
CPUMAX=1200000
fi

uboot_custom_postprocess() {
if [[ $BOARD == jethubj80 ]]; then
uboot_gxl_postprocess_ng "$SRC/cache/sources/amlogic-boot-fip/jethub-j80"
elif [[ $BOARD == jethubj100 ]]; then
uboot_axg_postprocess_ng "$SRC/cache/sources/amlogic-boot-fip/jethub-j100"
fi
}

write_uboot_platform() {
local unable_install_uboot="Unable to install U-Boot."
local method=0

if [[ "$2" == *mmcblk* ]]; then
local mmcblk_prefix
mmcblk_prefix=$(echo "$2" | grep -Po "mmcblk\d")
logger "${FUNCNAME[0]}(): mmcblk_prefix = $mmcblk_prefix"

if [[ -n "$mmcblk_prefix" ]]; then
local mmc_boot=${mmcblk_prefix}boot
local of_boot0=/dev/${mmc_boot}0
local of_boot1=/dev/${mmc_boot}1
if [[ -e $of_boot0 ]]; then
method=1
logger "${FUNCNAME[0]}(): use install in boot emmc partitions"
fi
else
logger "${FUNCNAME[0]}(): mmcblk_prefix is empty. $unable_install_uboot"
return 1
fi
else
logger "${FUNCNAME[0]}(): use standart u-boot install."
fi

dd if="$1/u-boot.bin" of="$2" bs=1 count=442 conv=fsync >/dev/null 2>&1
dd if="$1/u-boot.bin" of="$2" bs=512 skip=1 seek=1 conv=fsync >/dev/null 2>&1

if [[ $method == 1 ]]; then
logger "${FUNCNAME[0]}(): of_boot0 = $of_boot0"
logger "${FUNCNAME[0]}(): of_boot1 = $of_boot1"

# unset force-read-only flag
echo 0 >"/sys/block/${mmc_boot}0/force_ro"
echo 0 >"/sys/block/${mmc_boot}1/force_ro"
logger "${FUNCNAME[0]}(): /sys/block/${mmc_boot}0/force_ro value after unsetting read-only flag: $(<"/sys/block/${mmc_boot}0/force_ro")"
logger "${FUNCNAME[0]}(): /sys/block/${mmc_boot}1/force_ro value after unsetting read-only flag: $(<"/sys/block/${mmc_boot}1/force_ro")"

local uboot_name=u-boot.bin
local uboot_size_in_kbytes=$(($(stat --printf "%s" "$1/$uboot_name") / 1024))
local uboot_offset=1 # 512 bytes in dd
logger "${FUNCNAME[0]}(): uboot_size_in_kbytes = $uboot_size_in_kbytes"
logger "${FUNCNAME[0]}(): uboot_offset = $uboot_offset"
dd if="$1/u-boot.bin" of="$of_boot0" bs=512 skip=1 conv=fsync >/dev/null 2>&1
dd if="$1/u-boot.bin" of="$of_boot1" bs=512 skip=1 conv=fsync >/dev/null 2>&1
fi

logger "${FUNCNAME[0]}(): u-boot successfulley installed"
}

comment_default_rsyslog_rules() {
local conf_file="$SDCARD/etc/rsyslog.d/50-default.conf"

local rule_file_arr=(/var/log/syslog /var/log/auth.log /var/log/kern.log /var/log/mail.log /var/log/mail.err)

rule_file_escaped_arr=("${rule_file_arr[@]}")
for ((i = 0;i < ${#rule_file_escaped_arr[*]}; i++)); do
rule_file_escaped_arr[$i]="${rule_file_arr[$i]//\//\\/}";
done

for ((i = 0;i < ${#rule_file_escaped_arr[*]}; i++)); do
rule_file_escaped="${rule_file_escaped_arr[$i]}"
regexp="^[^#][^ \t]+[ \t]+.?${rule_file_escaped}.*$"
if grep -Pq "$regexp" "$conf_file"; then
sed -i -E -e "s/$regexp/#\0/g" "$conf_file" || {
echo "sed 's/$regexp/#\0/g' $conf_file failed"
return 1
}
else
echo "grep '$regexp' $conf_file failed"
return 2
fi
done
}

buildjethomecmds () {
local toolchain
JETHOME_USE_GCC="> 9.0"
JETHOME_COMPILER="aarch64-none-linux-gnu-"
# build aarch64 in amd64
if [[ $(dpkg --print-architecture) == amd64 ]]; then

toolchain=$(find_toolchain "$JETHOME_COMPILER" "$JETHOME_USE_GCC")
[[ -z $toolchain ]] && exit_with_error "Could not find required toolchain" "${JETHOME_COMPILER}gcc $JETHOME_USE_GCC"
fi

display_alert "Compiler version" "${JETHOME_COMPILER}gcc $(eval env PATH="${toolchain}:${PATH}" "${JETHOME_COMPILER}gcc" -dumpversion)" "info"

local gpp="${JETHOME_COMPILER}g++"
local gpp_options="-Os -s -Wall -Wextra -std=c++17 -I$SRC/packages/bsp/jethub"
local gcc="${JETHOME_COMPILER}gcc"

env PATH="${toolchain}:${PATH}" "$gpp" $gpp_options "$SRC/packages/bsp/jethub/jethub_get_cmdline_key.cpp" -o "$destination/usr/bin/jethub_get_cmdline_key" || exit_with_error "Unable to compile jethub_get_cmdline_key.cpp"
env PATH="${toolchain}:${PATH}" "$gpp" $gpp_options "$SRC/packages/bsp/jethub/jethub_get_cmdline_key_cpuid.cpp" -o "$destination/usr/bin/jethub_get_cpuid" || exit_with_error "Unable to compile jethub_get_cmdline_key_cpuid.cpp"

if [[ $BOARD == jethubj80 ]]; then
# Bluetooth
install -m 755 "$SRC/packages/blobs/bt/hciattach/rtk_hciattach_$ARCH" "$destination/usr/bin/rtk_hciattach" || exit_with_error "Unable to install rtk_hciattach"

cp "$SRC/packages/bsp/jethub/$BOARD/bluetooth/jethub-rtk-hciattach.service" "$destination/lib/systemd/system/" || exit_with_error "Unable to copy jethub-rtk-hciattach.service"

install -m 755 "$SRC/packages/bsp/jethub/$BOARD/bluetooth/jethub-rtk-hciattach-starter" "$destination/usr/lib/armbian/" || exit_with_error "Unable to install jethub-rtk-hciattach-starter"

# Board eth led setup
env PATH="${toolchain}:${PATH}" "$gcc" "$SRC/packages/bsp/jethub/$BOARD/jethub_set_eth_leds.c" -o "$destination/usr/sbin/jethub_set-eth_leds" || exit_with_error "Unable to compile jethub_set_eth_leds.c"
# Board identifiers
env PATH="${toolchain}:${PATH}" "$gpp" $gpp_options "$SRC/packages/bsp/jethub/$BOARD/jethub_get_efuse_raw_key.cpp" -o "$destination/usr/bin/jethub_get_efuse_raw_key" || exit_with_error "Unable to compile jethub_get_efuse_raw_key.cpp"
env PATH="${toolchain}:${PATH}" "$gpp" $gpp_options "$SRC/packages/bsp/jethub/$BOARD/jethub_get_efuse_key_mac.cpp" -o "$destination/usr/bin/jethub_get_mac" || exit_with_error "Unable to compile jethub_get_efuse_key_mac.cpp"
env PATH="${toolchain}:${PATH}" "$gpp" $gpp_options "$SRC/packages/bsp/jethub/$BOARD/jethub_get_efuse_key_serial.cpp" -o "$destination/usr/bin/jethub_get_serial" || exit_with_error "Unable to compile jethub_get_efuse_key_serial.cpp"
env PATH="${toolchain}:${PATH}" "$gpp" $gpp_options "$SRC/packages/bsp/jethub/$BOARD/jethub_get_efuse_key_usid.cpp" -o "$destination/usr/bin/jethub_get_usid" || exit_with_error "Unable to compile jethub_get_efuse_key_usid.cpp"
elif [[ $BOARD == jethubj100 ]]; then
# Board identifiers
env PATH="${toolchain}:${PATH}" "$gpp" $gpp_options "$SRC/packages/bsp/jethub/$BOARD/jethub_get_cmdline_key_mac.cpp" -o "$destination/usr/bin/jethub_get_mac" || exit_with_error "Unable to compile jethub_get_cmdline_key_mac.cpp"

# Wifi & Bluetooth
mkdir -p --mode=755 "$destination/lib/firmware/" || exit_with_error "Unable to mkdir firmware"
mkdir --mode=775 "$destination/lib/firmware/brcm/" || exit_with_error "Unable to mkdir brcm"
cp -P "$SRC"/packages/bsp/jethub/"$BOARD"/{BCM4345C0.hcd,'brcmfmac43455-sdio.jethome,j100.txt'} "$destination/lib/firmware/brcm/" || "Unable to copy brcm firmware symlinks"
else
exit_with_error "Unexpected board \"$BOARD\""
fi
}

family_tweaks() {
# Log rotation
comment_default_rsyslog_rules || exit_with_error "Unable to comment default rsyslog rules"

# Hardware init
chroot "${SDCARD}" /bin/bash -c "systemctl --no-reload enable jethub-initer.service >/dev/null 2>&1"

# pip3 packages
chroot "${SDCARD}" /bin/bash -c "pip3 install pyserial intelhex python-magic" >>"${DEST}"/debug/install.log 2>&1

# Hostapd
chroot "${SDCARD}" /bin/bash -c "systemctl --no-reload disable hostapd.service >/dev/null 2>&1"

if [[ "$BOARD" == jethubj80 ]]; then
# Bluetooth
chroot "${SDCARD}" /bin/bash -c "systemctl --no-reload enable jethub-rtk-hciattach.service >/dev/null 2>&1"
fi
}

family_tweaks_bsp() {
# build jethub_get_cmdline_key jethub_get_cpuid
buildjethomecmds

# Log rotation
mkdir -p --mode=755 "$destination/etc/rsyslog.d" || exit_with_error "Unable to mkdir /etc/rsyslog.d"
cp "$SRC/packages/bsp/jethub/60-jethub-logs-rotate.conf" "$destination/etc/rsyslog.d/" || exit_with_error "Unable to copy 60-jethub-logs-rotate.conf"
cp "$SRC/packages/bsp/jethub/jethub-remove-log-file.sh" "$destination/usr/lib/armbian/" || exit_with_error "Unable to copy jethub-remove-log-file.sh"

# Hardware init
cp "$SRC/packages/bsp/jethub/jethub-initer.service" "$destination/lib/systemd/system/" || exit_with_error "Unable to copy jethub-initer.service"
cp "$SRC/packages/bsp/jethub/${BOARD}/jethub-init" "$destination/usr/lib/armbian/" || exit_with_error "Unable to copy jethub-init"

if [[ "$BOARD" == jethubj80 ]]; then
# Ethernet LED setup
cp "$SRC/packages/bsp/jethub/$BOARD/05-jethub_set_eth_leds.rules" "$destination/etc/udev/rules.d/"
fi

mkdir -p "$destination/etc/udev/rules.d"
mkdir -p "$destination/usr/local/bin"
}
13 changes: 13 additions & 0 deletions config/targets-cli-beta.conf
Expand Up @@ -6,6 +6,19 @@
helios64 edge impish cli beta yes


# JetHub H1 (j80)
jethubj80 current focal cli beta yes
jethubj80 edge focal cli beta yes
jethubj80 current hirsute cli beta yes
jethubj80 edge hirsute cli beta yes

# JetHub D1 (j100)
jethubj100 current focal cli beta yes
jethubj100 edge focal cli beta yes
jethubj100 current hirsute cli beta yes
jethubj100 edge hirsute cli beta yes


# Jetson Nano
jetson-nano edge impish cli beta yes

Expand Down