aboutsummaryrefslogtreecommitdiffstats
path: root/target/linux/socfpga/base-files
diff options
context:
space:
mode:
authorLuka Perkov <luka@openwrt.org>2016-05-10 22:52:00 +0000
committerLuka Perkov <luka@openwrt.org>2016-06-19 19:35:42 +0200
commit9ccd1da444ff320abf069322b6063d7d041cdd20 (patch)
tree6e4bf314ba8e2ae7ffd68f166a46977aad676ec8 /target/linux/socfpga/base-files
parentc3d9ae93fd2cfb51ae3e843487edad81545afca4 (diff)
downloadmaster-187ad058-9ccd1da444ff320abf069322b6063d7d041cdd20.tar.gz
master-187ad058-9ccd1da444ff320abf069322b6063d7d041cdd20.tar.bz2
master-187ad058-9ccd1da444ff320abf069322b6063d7d041cdd20.zip
target: socfpga: Add Altera SoCFPGA support
This patch adds support for the Altera SoCFPGA target. Both generic target and Terasic SoCkit boards are supported. Signed-off-by: Marek Vasut <marex@denx.de> git-svn-id: svn://svn.openwrt.org/openwrt/trunk@49367 3c298f89-4303-0410-b956-a3cf2f4a3e73
Diffstat (limited to 'target/linux/socfpga/base-files')
-rw-r--r--target/linux/socfpga/base-files/etc/fw_env.config3
-rwxr-xr-xtarget/linux/socfpga/base-files/etc/init.d/sockit_vtcon15
-rw-r--r--target/linux/socfpga/base-files/etc/uci-defaults/01_leds22
-rw-r--r--target/linux/socfpga/base-files/etc/uci-defaults/02_network25
-rw-r--r--target/linux/socfpga/base-files/lib/preinit/03_socfpga_detect9
-rw-r--r--target/linux/socfpga/base-files/lib/preinit/79_move_config18
-rwxr-xr-xtarget/linux/socfpga/base-files/lib/socfpga.sh48
-rwxr-xr-xtarget/linux/socfpga/base-files/lib/upgrade/platform.sh37
-rw-r--r--target/linux/socfpga/base-files/lib/upgrade/sockit.sh88
9 files changed, 265 insertions, 0 deletions
diff --git a/target/linux/socfpga/base-files/etc/fw_env.config b/target/linux/socfpga/base-files/etc/fw_env.config
new file mode 100644
index 0000000000..f6fe3f9bea
--- /dev/null
+++ b/target/linux/socfpga/base-files/etc/fw_env.config
@@ -0,0 +1,3 @@
+# MTD device name Device offset Env. size Flash sector size
+/dev/mtd1 0x0 0x1000 0x10000
+/dev/mtd2 0x0 0x1000 0x10000
diff --git a/target/linux/socfpga/base-files/etc/init.d/sockit_vtcon b/target/linux/socfpga/base-files/etc/init.d/sockit_vtcon
new file mode 100755
index 0000000000..6555f5b348
--- /dev/null
+++ b/target/linux/socfpga/base-files/etc/init.d/sockit_vtcon
@@ -0,0 +1,15 @@
+#!/bin/sh /etc/rc.common
+
+START=99
+
+start() {
+ . /lib/socfpga.sh
+
+ local board=$(socfpga_board_name)
+
+ # Print something nice on the VTcon (the SPI LCD)
+ if [ "${board}" = "socfpga-sockit" ] ; then
+ echo "OpenWRT" > /dev/tty0
+ uci show network.lan.ipaddr > /dev/tty0
+ fi
+}
diff --git a/target/linux/socfpga/base-files/etc/uci-defaults/01_leds b/target/linux/socfpga/base-files/etc/uci-defaults/01_leds
new file mode 100644
index 0000000000..a04de3b40e
--- /dev/null
+++ b/target/linux/socfpga/base-files/etc/uci-defaults/01_leds
@@ -0,0 +1,22 @@
+#!/bin/sh
+#
+# Copyright (C) 2015 OpenWrt.org
+#
+
+. /lib/functions/uci-defaults.sh
+. /lib/socfpga.sh
+
+board=$(socfpga_board_name)
+
+case "$board" in
+"socfpga-sockit")
+ ucidef_set_led_netdev "lan" "LAN" "hps:blue:led0" "eth0"
+ ucidef_set_led_mmc "mmc" "MMC" "hps:blue:led1" "mmc0"
+ ucidef_set_led_default "health" "health" "hps:blue:led2" "1"
+ ucidef_set_led_default "fault" "fault" "hps:blue:led3" "1"
+ ;;
+esac
+
+ucidef_commit_leds
+
+exit 0
diff --git a/target/linux/socfpga/base-files/etc/uci-defaults/02_network b/target/linux/socfpga/base-files/etc/uci-defaults/02_network
new file mode 100644
index 0000000000..479e8202f7
--- /dev/null
+++ b/target/linux/socfpga/base-files/etc/uci-defaults/02_network
@@ -0,0 +1,25 @@
+#!/bin/sh
+#
+# Copyright (C) 2015 OpenWrt.org
+#
+
+[ -e /etc/config/network ] && exit 0
+
+touch /etc/config/network
+
+. /lib/functions/uci-defaults.sh
+. /lib/socfpga.sh
+
+board=$(socfpga_board_name)
+
+ucidef_set_interface_loopback
+
+case "$board" in
+"socfpga-sockit")
+ ucidef_set_interface_lan 'eth0'
+ ;;
+esac
+
+uci commit network
+
+exit 0
diff --git a/target/linux/socfpga/base-files/lib/preinit/03_socfpga_detect b/target/linux/socfpga/base-files/lib/preinit/03_socfpga_detect
new file mode 100644
index 0000000000..fc2f20a31f
--- /dev/null
+++ b/target/linux/socfpga/base-files/lib/preinit/03_socfpga_detect
@@ -0,0 +1,9 @@
+#!/bin/sh
+
+do_socfpga_detect() {
+ . /lib/socfpga.sh
+
+ socfpga_board_detect
+}
+
+boot_hook_add preinit_main do_socfpga_detect
diff --git a/target/linux/socfpga/base-files/lib/preinit/79_move_config b/target/linux/socfpga/base-files/lib/preinit/79_move_config
new file mode 100644
index 0000000000..89f62d52f1
--- /dev/null
+++ b/target/linux/socfpga/base-files/lib/preinit/79_move_config
@@ -0,0 +1,18 @@
+#!/bin/sh
+# Copyright (C) 2015 OpenWrt.org
+
+move_config() {
+ . /lib/socfpga.sh
+ . /lib/upgrade/sockit.sh
+
+ local board=$(socfpga_board_name)
+
+ # Restore configuration
+ if [ "${board}" = "socfpga-sockit" ] ; then
+ mount -o rw,noatime "$CFGPART" /mnt
+ [ -e "/mnt/sysupgrade.tgz" ] && mv -f /mnt/sysupgrade.tgz /
+ umount /mnt
+ fi
+}
+
+boot_hook_add preinit_mount_root move_config
diff --git a/target/linux/socfpga/base-files/lib/socfpga.sh b/target/linux/socfpga/base-files/lib/socfpga.sh
new file mode 100755
index 0000000000..26735ac2d4
--- /dev/null
+++ b/target/linux/socfpga/base-files/lib/socfpga.sh
@@ -0,0 +1,48 @@
+#!/bin/sh
+#
+# Copyright (C) 2010-2013 OpenWrt.org
+#
+
+SOCFPGA_BOARD_NAME=
+SOCFPGA_MODEL=
+
+socfpga_board_detect() {
+ local machine
+ local name
+
+ machine=$(cat /proc/device-tree/model)
+
+ case "$machine" in
+ "Terasic SoCkit")
+ name="socfpga-sockit"
+ ;;
+ *)
+ name="generic"
+ ;;
+ esac
+
+ [ -z "$SOCFPGA_BOARD_NAME" ] && SOCFPGA_BOARD_NAME="$name"
+ [ -z "$SOCFPGA_MODEL" ] && SOCFPGA_MODEL="$machine"
+
+ [ -e "/tmp/sysinfo/" ] || mkdir -p "/tmp/sysinfo/"
+
+ echo "$SOCFPGA_BOARD_NAME" > /tmp/sysinfo/board_name
+ echo "$SOCFPGA_MODEL" > /tmp/sysinfo/model
+}
+
+socfpga_board_name() {
+ local name
+
+ [ -f /tmp/sysinfo/board_name ] || socfpga_board_detect
+ [ -f /tmp/sysinfo/board_name ] && name=$(cat /tmp/sysinfo/board_name)
+
+ # Name is too generic, use model
+ if [ "$name" = "altr,socfpga-cyclone5" ] ; then
+ socfpga_board_detect
+ name=$(cat /tmp/sysinfo/board_name)
+ fi
+
+ [ -z "$name" ] && name="unknown"
+
+ echo "$name"
+}
diff --git a/target/linux/socfpga/base-files/lib/upgrade/platform.sh b/target/linux/socfpga/base-files/lib/upgrade/platform.sh
new file mode 100755
index 0000000000..d65e11ebda
--- /dev/null
+++ b/target/linux/socfpga/base-files/lib/upgrade/platform.sh
@@ -0,0 +1,37 @@
+#
+# Copyright (C) 2014 OpenWrt.org
+#
+
+. /lib/socfpga.sh
+
+RAMFS_COPY_BIN="/bin/mkdir /bin/touch /bin/mknod"
+RAMFS_COPY_DATA=/lib/socfpga.sh
+
+platform_check_image() {
+ local board=$(socfpga_board_name)
+
+ [ "$#" -gt 1 ] && return 1
+
+ case "$board" in
+ "socfpga-sockit")
+ platform_do_check_sockit "$ARGV"
+ return 0;
+ ;;
+ esac
+
+ echo "Sysupgrade is not yet supported on $board."
+ return 1
+}
+
+platform_do_upgrade() {
+ local board=$(socfpga_board_name)
+
+ case "$board" in
+ "socfpga-sockit")
+ platform_do_upgrade_sockit "$ARGV"
+ ;;
+ *)
+ default_do_upgrade "$ARGV"
+ ;;
+ esac
+}
diff --git a/target/linux/socfpga/base-files/lib/upgrade/sockit.sh b/target/linux/socfpga/base-files/lib/upgrade/sockit.sh
new file mode 100644
index 0000000000..e9268cf6d2
--- /dev/null
+++ b/target/linux/socfpga/base-files/lib/upgrade/sockit.sh
@@ -0,0 +1,88 @@
+#
+# Copyright (C) 2014-2015 OpenWrt.org
+#
+
+BOOTPART=/dev/mmcblk0p2
+CFGPART=/dev/mmcblk0p3
+
+identify_magic() {
+ local magic=$1
+ case "$magic" in
+ "55424923")
+ echo "ubi"
+ ;;
+ "31181006")
+ echo "ubifs"
+ ;;
+ "68737173")
+ echo "squashfs"
+ ;;
+ "d00dfeed")
+ echo "fit"
+ ;;
+ "00000000")
+ echo "ext4"
+ ;;
+ "4349"*)
+ echo "combined"
+ ;;
+ *)
+ echo "unknown $magic"
+ ;;
+ esac
+}
+
+get_magic_long_tar() {
+ ( tar xf $1 $2 -O | dd bs=4 count=1 | hexdump -v -n 4 -e '1/1 "%02x"') 2> /dev/null
+}
+
+identify_tar() {
+ identify_magic $(get_magic_long_tar "$1" "$2")
+}
+
+platform_do_check_sockit() {
+ local board=$(socfpga_board_name)
+ local magic_long="$(get_magic_long "$1")"
+ echo "magic = $magic_long"
+
+ if [ "$magic_long" = "73797375" ] ; then
+ local rootfs_type="$(identify_tar "$1" sysupgrade-$board/root)"
+ if [ "$rootfs_type" = "ubifs" ] ; then
+ nand_do_platform_check $board $1
+ return 0;
+ fi
+ [ "$rootfs_type" = "ext4" ] && return 0
+
+ echo "Unknown rootfs type $rootfs_type !"
+ fi
+
+ return 1
+}
+
+platform_do_upgrade_sockit() {
+ local board=$(socfpga_board_name)
+ local magic_long="$(get_magic_long "$1")"
+ echo "magic = $magic_long"
+
+ if [ "$magic_long" = "73797375" ] ; then
+ local rootfs_type="$(identify_tar "$1" sysupgrade-$board/root)"
+ if [ "$rootfs_type" = "ext4" ] ; then
+ sync
+ tar xf "$1" sysupgrade-$board/root -O | \
+ dd of="$BOOTPART" bs=512 conv=fsync
+ return 0
+ fi
+
+ echo "Unknown rootfs type $rootfs_type !"
+ fi
+
+ return 1
+}
+
+platform_copy_config() {
+ if [ -b "$CFGPART" ]; then
+ mount -o rw,noatime "$CFGPART" /mnt
+ cp -af "$CONF_TAR" /mnt/
+ umount /mnt
+ fi
+}