From 0d271cef8071d0698246b4b50a610b5ff718af01 Mon Sep 17 00:00:00 2001 From: Ian Pozella Date: Thu, 2 Feb 2017 09:42:04 +0000 Subject: [PATCH] target: add pistachio The Pistachio target is a MIPS interaptiv based SoC developed by Imagination Technologies. It includes blocks for i2c, spi, audio, usb and WiFi. This also adds the base support for the 'Creator Ci40 (marduk)' device which uses the Pistachio SoC to create an IoT hub by including Bluetooth, WiFi and 6lowpan on one board. Additionally 2x Mikrobus ports are available to expand with further RF technologies or add sensors. You can find out more here http://creatordev.io. Note, this commit is just the initial board support hence the following are not expected to work yet: * WiFi * Bluetooth * 6lowpan * Audio * Mikrobus uarts, user leds (clock dependency of 6lowpan chip) The aim of this commit is to essentially have the same level of support that currently exists in the mainline kernel. Signed-off-by: Abhijit Mahajani Signed-off-by: Francois Berder Signed-off-by: Ian Pozella Signed-off-by: Mayank Sirotiya Signed-off-by: Sean Kelly --- package/boot/uboot-envtools/Makefile | 4 ++ package/boot/uboot-envtools/files/pistachio | 28 +++++++++ target/linux/pistachio/Makefile | 27 +++++++++ .../base-files/etc/board.d/02_network | 18 ++++++ target/linux/pistachio/base-files/etc/diag.sh | 31 ++++++++++ .../pistachio/base-files/lib/pistachio.sh | 42 ++++++++++++++ .../lib/preinit/03_preinit_pistachio.sh | 15 +++++ .../base-files/lib/upgrade/platform.sh | 58 +++++++++++++++++++ target/linux/pistachio/image/Makefile | 37 ++++++++++++ target/linux/pistachio/profiles/00-default.mk | 17 ++++++ 10 files changed, 277 insertions(+) create mode 100644 package/boot/uboot-envtools/files/pistachio create mode 100644 target/linux/pistachio/Makefile create mode 100755 target/linux/pistachio/base-files/etc/board.d/02_network create mode 100755 target/linux/pistachio/base-files/etc/diag.sh create mode 100755 target/linux/pistachio/base-files/lib/pistachio.sh create mode 100755 target/linux/pistachio/base-files/lib/preinit/03_preinit_pistachio.sh create mode 100755 target/linux/pistachio/base-files/lib/upgrade/platform.sh create mode 100644 target/linux/pistachio/image/Makefile create mode 100644 target/linux/pistachio/profiles/00-default.mk diff --git a/package/boot/uboot-envtools/Makefile b/package/boot/uboot-envtools/Makefile index 784fc64231..10175b0f77 100644 --- a/package/boot/uboot-envtools/Makefile +++ b/package/boot/uboot-envtools/Makefile @@ -112,6 +112,10 @@ ifneq ($(CONFIG_TARGET_oxnas),) $(INSTALL_DIR) $(1)/etc/uci-defaults $(INSTALL_BIN) ./files/oxnas $(1)/etc/uci-defaults/30_uboot-envtools endif +ifneq ($(CONFIG_TARGET_pistachio),) + $(INSTALL_DIR) $(1)/etc/uci-defaults + $(INSTALL_DATA) ./files/pistachio $(1)/etc/uci-defaults/30_uboot-envtools +endif ifneq ($(CONFIG_TARGET_ramips),) $(INSTALL_DIR) $(1)/etc/uci-defaults $(INSTALL_DATA) ./files/ramips $(1)/etc/uci-defaults/30_uboot-envtools diff --git a/package/boot/uboot-envtools/files/pistachio b/package/boot/uboot-envtools/files/pistachio new file mode 100644 index 0000000000..56bac35804 --- /dev/null +++ b/package/boot/uboot-envtools/files/pistachio @@ -0,0 +1,28 @@ +#!/bin/sh +# +# Copyright (C) 2017 OpenWrt.org +# +# This is free software, licensed under the GNU General Public License v2. +# See /LICENSE for more information. +# + +[ -e /etc/config/ubootenv ] && exit 0 + +touch /etc/config/ubootenv + +. /lib/pistachio.sh +. /lib/uboot-envtools.sh +. /lib/functions.sh + +board=$(pistachio_board_name) + +case "$board" in +marduk) + ubootenv_add_uci_config "/dev/mtd2" "0x0" "0x2000" "0x1000" + ;; +esac + +config_load ubootenv +config_foreach ubootenv_add_app_config ubootenv + +exit 0 diff --git a/target/linux/pistachio/Makefile b/target/linux/pistachio/Makefile new file mode 100644 index 0000000000..630fb56fd3 --- /dev/null +++ b/target/linux/pistachio/Makefile @@ -0,0 +1,27 @@ +# +# Copyright (C) 2017 OpenWrt.org +# +# This is free software, licensed under the GNU General Public License v2. +# See /LICENSE for more information. +# +include $(TOPDIR)/rules.mk + +ARCH:=mipsel +BOARD:=pistachio +BOARDNAME:=MIPS pistachio +FEATURES:=fpu usb usbgadget squashfs targz nand +CPU_TYPE:=24kc +CPU_SUBTYPE:=24kf +MAINTAINER:= + +KERNEL_PATCHVER:=4.9 + +include $(INCLUDE_DIR)/target.mk + +KERNELNAME:=vmlinux dtbs + +DEFAULT_PACKAGES += \ + kmod-gpio-button-hotplug \ + uboot-envtools + +$(eval $(call BuildTarget)) diff --git a/target/linux/pistachio/base-files/etc/board.d/02_network b/target/linux/pistachio/base-files/etc/board.d/02_network new file mode 100755 index 0000000000..e7e0a9a930 --- /dev/null +++ b/target/linux/pistachio/base-files/etc/board.d/02_network @@ -0,0 +1,18 @@ +#!/bin/sh +# +# Copyright (C) 2017 OpenWrt.org +# +# This is free software, licensed under the GNU General Public License v2. +# See /LICENSE for more information. +# + +. /lib/functions/uci-defaults.sh + + +board_config_update + +ucidef_set_interface_lan 'eth0' 'dhcp' + +board_config_flush + +exit 0 diff --git a/target/linux/pistachio/base-files/etc/diag.sh b/target/linux/pistachio/base-files/etc/diag.sh new file mode 100755 index 0000000000..7b556498d6 --- /dev/null +++ b/target/linux/pistachio/base-files/etc/diag.sh @@ -0,0 +1,31 @@ +#!/bin/sh +# +# Copyright (C) 2017 OpenWrt.org +# +# This is free software, licensed under the GNU General Public License v2. +# See /LICENSE for more information. +# + +. /lib/functions/leds.sh +. /lib/pistachio.sh + +status_led="marduk:red:heartbeat" + +set_state() { + + case "$1" in + preinit) + status_led_blink_preinit + ;; + failsafe) + status_led_blink_failsafe + ;; + upgrade | \ + preinit_regular) + status_led_blink_preinit_regular + ;; + done) + status_led_on + ;; + esac +} diff --git a/target/linux/pistachio/base-files/lib/pistachio.sh b/target/linux/pistachio/base-files/lib/pistachio.sh new file mode 100755 index 0000000000..f9a16db3ed --- /dev/null +++ b/target/linux/pistachio/base-files/lib/pistachio.sh @@ -0,0 +1,42 @@ +#!/bin/sh +# +# Copyright (C) 2017 OpenWrt.org +# +# This is free software, licensed under the GNU General Public License v2. +# See /LICENSE for more information. +# + +PISTACHIO_BOARD_NAME= +PISTACHIO_MODEL= + +pistachio_board_detect() { + local machine + local name + + machine=$(cat /proc/device-tree/model) + + case "$machine" in + "IMG Marduk (Creator Ci40)") + name="marduk" + ;; + *) + name="generic" + ;; + esac + + [ -z "$PISTACHIO_BOARD_NAME" ] && PISTACHIO_BOARD_NAME="$name" + [ -z "$PISTACHIO_MODEL" ] && PISTACHIO_MODEL="$machine" + + [ -e "/tmp/sysinfo/" ] || mkdir -p "/tmp/sysinfo/" + + echo "$PISTACHIO_BOARD_NAME" > /tmp/sysinfo/board_name + echo "$PISTACHIO_MODEL" > /tmp/sysinfo/model +} + +pistachio_board_name() { + local name + [ -f /tmp/sysinfo/board_name ] && name=$(cat /tmp/sysinfo/board_name) + [ -z "$name" ] && name="unknown" + + echo "$name" +} diff --git a/target/linux/pistachio/base-files/lib/preinit/03_preinit_pistachio.sh b/target/linux/pistachio/base-files/lib/preinit/03_preinit_pistachio.sh new file mode 100755 index 0000000000..fda420e7d7 --- /dev/null +++ b/target/linux/pistachio/base-files/lib/preinit/03_preinit_pistachio.sh @@ -0,0 +1,15 @@ +#!/bin/sh +# +# Copyright (C) 2017 OpenWrt.org +# +# This is free software, licensed under the GNU General Public License v2. +# See /LICENSE for more information. +# + +do_pistachio() { + . /lib/pistachio.sh + + pistachio_board_detect +} + +boot_hook_add preinit_main do_pistachio diff --git a/target/linux/pistachio/base-files/lib/upgrade/platform.sh b/target/linux/pistachio/base-files/lib/upgrade/platform.sh new file mode 100755 index 0000000000..5a886fbee6 --- /dev/null +++ b/target/linux/pistachio/base-files/lib/upgrade/platform.sh @@ -0,0 +1,58 @@ +#!/bin/sh +# +# Copyright (C) 2017 OpenWrt.org +# +# This is free software, licensed under the GNU General Public License v2. +# See /LICENSE for more information. +# + +. /lib/pistachio.sh + +RAMFS_COPY_BIN="/usr/sbin/fw_printenv /usr/sbin/fw_setenv /bin/mkdir /bin/dmesg /bin/sed /bin/grep" +RAMFS_COPY_DATA="/etc/fw_env.config" +REQUIRE_IMAGE_METADATA=0 + +platform_check_image() +{ + local board=$(pistachio_board_name) + + nand_do_platform_check $board $1 + return $? +} + +platform_pre_upgrade() { + # TODO no need to switch to ramfs with dual partitions in + # fact we don't even want to reboot as part of seamless + # upgrades. Instead just upgrade opposite partition and mark + # the next reboot to boot from that partition. Could just call + # stage2 directly but need to refactor nand_upgrade_success + # for this to work. + # Also the nand functions don't allow url to be used + nand_do_upgrade $1 +} + +platform_nand_pre_upgrade() { + local board=$(pistachio_board_name) + + case "$board" in + marduk) + local boot_partition=$(dmesg | grep "ubi0: attached.*" | sed "s/^.*\(firmware[0-1]\).*/\1/g") + + echo "Current boot partiton $boot_partition (/dev/mtd$(find_mtd_index $boot_partition))" + mkdir -p /var/lock + if [ "$boot_partition" == "firmware0" ]; then + CI_UBIPART="firmware1" + fw_setenv boot_partition 1 || exit 1 + else + CI_UBIPART="firmware0" + fw_setenv boot_partition 0 || exit 1 + fi + echo "Upgrading partition $CI_UBIPART (/dev/mtd$(find_mtd_index $CI_UBIPART))" + ;; + esac +} + +blink_led() { + . /etc/diag.sh; set_state upgrade +} +append sysupgrade_pre_upgrade blink_led diff --git a/target/linux/pistachio/image/Makefile b/target/linux/pistachio/image/Makefile new file mode 100644 index 0000000000..a9c16856a2 --- /dev/null +++ b/target/linux/pistachio/image/Makefile @@ -0,0 +1,37 @@ +# +# Copyright (C) 2017 OpenWrt.org +# +# This is free software, licensed under the GNU General Public License v2. +# See /LICENSE for more information. +# + +include $(TOPDIR)/rules.mk +include $(INCLUDE_DIR)/image.mk + +KERNEL_LOADADDR := 0x80400000 + +define Device/Default + PROFILES := Default + FILESYSTEMS := squashfs + KERNEL_DEPENDS = $$(wildcard $$(DTS_DIR)/$$(DEVICE_DTS).dts) + KERNEL = kernel-bin | gzip | fit gzip $$(DTS_DIR)/$$(DEVICE_DTS).dtb + KERNEL_SUFFIX := -kernel.itb + KERNEL_INSTALL := 1 + KERNEL_IN_UBI := 1 + IMAGES := factory.ubi sysupgrade.tar + IMAGE/factory.ubi := append-ubi + IMAGE/sysupgrade.tar := sysupgrade-tar +endef + +define Device/marduk + DEVICE_DTS := img/pistachio_marduk + BLOCKSIZE := 256KiB + PAGESIZE := 4KiB + DEVICE_TITLE := Creator Ci40 + DEVICE_PACKAGES := kmod-tpm-i2c-infineon +endef + +TARGET_DEVICES += marduk + + +$(eval $(call BuildImage)) diff --git a/target/linux/pistachio/profiles/00-default.mk b/target/linux/pistachio/profiles/00-default.mk new file mode 100644 index 0000000000..f40be3d667 --- /dev/null +++ b/target/linux/pistachio/profiles/00-default.mk @@ -0,0 +1,17 @@ +# +# Copyright (C) 2017 OpenWrt.org +# +# This is free software, licensed under the GNU General Public License v2. +# See /LICENSE for more information. +# + +define Profile/Default + NAME:=Default Profile + PRIORITY:=1 + PACKAGES:= +endef + +define Profile/Default/Description + Default package set compatible with most boards. +endef +$(eval $(call Profile,Default)) -- 2.30.2