diff --git a/meta-iot2000-bsp/README.md b/meta-iot2000-bsp/README.md index c4ed2fec..4f1c0e1d 100644 --- a/meta-iot2000-bsp/README.md +++ b/meta-iot2000-bsp/README.md @@ -61,8 +61,8 @@ $ source poky/oe-init-build-env iot2000-build ## Configure: ```diff ---- conf/bblayers.conf.old -+++ conf/bblayers.conf +--- iot2000-build/conf/bblayers.conf.old ++++ iot2000-build/conf/bblayers.conf @@ -9,4 +9,6 @@ /home/build/poky/meta \ /home/build/poky/meta-poky \ @@ -73,8 +73,8 @@ $ source poky/oe-init-build-env iot2000-build ``` ```diff ---- conf/local.conf.old -+++ conf/local.conf +--- iot2000-build/conf/local.conf.old ++++ iot2000-build/conf/local.conf @@ -34,7 +34,7 @@ #MACHINE ?= "edgerouter" # @@ -93,7 +93,7 @@ $ bitbake core-image-minimal ``` -Booting the Image +Booting the Image from SD card ================= Under Linux, insert an unused SD card. Assuming the SD card takes device @@ -107,3 +107,25 @@ If you want to ssh into the system, you can use the root terminal to ifconfig the IP address and use that to ssh in. The root password is empty, so to log in type 'root' for the user name and hit 'Enter' at the Password prompt and you should be in. + + +Booting the Image from USB stick +================= + +Under Linux, insert an unused USB stick. Assuming the USB stcik takes device +/dev/sda, use dd to copy the image to it. For example: + +```shell +$ sudo dd if=tmp/deploy/images/iot2000/core-image-minimal-iot2000.wic of=/dev/sda bs=4M oflag=sync +``` + +In addition, you have to change the boot config. On the first partition, navigate to the folder loader/entries, open the file boot.conf and change the following: + +```diff +--- loader/entries/boot.conf.old ++++ loader/entries/boot.conf +title boot +linux /bzImage +-options LABEL=Boot root=/dev/mmcblk0p2 console=ttyS1,115200n8 reboot=efi,warm rw LABEL=boot debugshell=5 ++options LABEL=Boot root=/dev/sda2 console=ttyS1,115200n8 reboot=efi,warm rw LABEL=boot debugshell=5 rootdelay=1 +``` diff --git a/meta-iot2000-bsp/conf/layer.conf b/meta-iot2000-bsp/conf/layer.conf index 29a1a4cb..550c07c7 100644 --- a/meta-iot2000-bsp/conf/layer.conf +++ b/meta-iot2000-bsp/conf/layer.conf @@ -11,3 +11,5 @@ BBFILE_PRIORITY_iot2000-bsp = "6" IOT2000_MIT_LICENSE = "${LAYERDIR}/COPYING.MIT" IOT2000_GPLv2_LICENSE = "${LAYERDIR}/COPYING.GPLv2" + +PACKAGE_CLASSES = "package_ipk" diff --git a/meta-iot2000-bsp/recipes-kernel/linux/files/0007-serial-8250_pci-Add-support-for-accessing-red-LED-vi.patch b/meta-iot2000-bsp/recipes-kernel/linux/files/0007-serial-8250_pci-Add-support-for-accessing-red-LED-vi.patch new file mode 100644 index 00000000..6d30b396 --- /dev/null +++ b/meta-iot2000-bsp/recipes-kernel/linux/files/0007-serial-8250_pci-Add-support-for-accessing-red-LED-vi.patch @@ -0,0 +1,127 @@ +From 403bfe046b658799a8735cf890da21f8e42280bc Mon Sep 17 00:00:00 2001 +From: Frank Ehlis +Date: Thu, 29 Sep 2016 14:48:52 +0200 +Subject: [PATCH] serial: 8250_pci: Add support for accessing red LED via ledfs + +The LED-init was moved past pci_default_setup() so that +port.membase is valid when saving it to our private data. + +Signed-off-by: Frank Ehlis +--- + drivers/tty/serial/8250/8250_pci.c | 72 +++++++++++++++++++++++++++++++++++++- + 1 file changed, 71 insertions(+), 1 deletion(-) + +diff --git a/drivers/tty/serial/8250/8250_pci.c b/drivers/tty/serial/8250/8250_pci.c +index 34baa78..829e9fc 100644 +--- a/drivers/tty/serial/8250/8250_pci.c ++++ b/drivers/tty/serial/8250/8250_pci.c +@@ -23,6 +23,7 @@ + #include + #include + #include ++#include + + #include + #include +@@ -1806,6 +1807,12 @@ xr17v35x_has_slave(struct serial_private *priv) + + /* IOT2000 MPIOs 8..15 */ + #define IOT2000_UARTS_ENABLE 0x03 ++#define IOT2000_UART_LED_RED 0x04 ++ ++#define IOT2000_UART_LEDFS_NAME "mpio_uart_led:red:user" ++static struct iot2000_serial_private { ++ u8 __iomem *membase; ++}iot2000_priv; + + static int pci_iot2000_rs485_config(struct uart_port *port, + struct serial_rs485 *rs485) +@@ -1851,11 +1858,47 @@ static int pci_iot2000_rs485_config(struct uart_port *port, + return 0; + } + ++static void ++iot2000_brightness_set(struct led_classdev *cdev, ++ enum led_brightness brightness) ++{ ++ u8 __iomem *p = iot2000_priv.membase; ++ u8 value; ++ ++ if ( iot2000_priv.membase == NULL ) ++ return; ++ ++ value = readb(p + UART_EXAR_MPIOLVL_15_8); ++ if (brightness == LED_OFF) ++ value &= ~IOT2000_UART_LED_RED; ++ else ++ value |= IOT2000_UART_LED_RED; ++ ++ writeb(value, p + UART_EXAR_MPIOLVL_15_8); ++} ++ ++static enum led_brightness ++iot2000_brightness_get(struct led_classdev *cdev) ++{ ++ u8 __iomem *p = iot2000_priv.membase; ++ u8 value; ++ ++ if ( iot2000_priv.membase == NULL ) ++ return LED_OFF; ++ ++ value = readb(p + UART_EXAR_MPIOLVL_15_8); ++ if (value & IOT2000_UART_LED_RED) ++ return 1; ++ ++ return LED_OFF; ++} ++ + static int + pci_xr17v35x_setup(struct serial_private *priv, + const struct pciserial_board *board, + struct uart_8250_port *port, int idx) + { ++ int ret; + bool is_iot2000; + u8 __iomem *p; + +@@ -1901,9 +1944,36 @@ pci_xr17v35x_setup(struct serial_private *priv, + writeb(UART_FCTR_EXAR_TRGD, p + UART_EXAR_FCTR); + writeb(128, p + UART_EXAR_TXTRG); + writeb(128, p + UART_EXAR_RXTRG); ++ + iounmap(p); + +- return pci_default_setup(priv, board, port, idx); ++ ret = pci_default_setup(priv, board, port, idx); ++ ++ /* on IOT2000, register the red LED attached to the MPIO */ ++ if (is_iot2000 && (ret == 0) && (idx == 0)) { ++ int err; ++ struct led_classdev *led; ++ char *name; ++ size_t namesz = strlen(IOT2000_UART_LEDFS_NAME) + 1; ++ ++ led = kzalloc(sizeof(*led) + namesz, GFP_KERNEL); ++ if (led) ++ { ++ name = (void*)&led[1]; ++ snprintf(name, namesz, "%s", IOT2000_UART_LEDFS_NAME); ++ iot2000_priv.membase = port->port.membase; ++ led->name = name; ++ led->max_brightness = 1; ++ led->brightness_set = iot2000_brightness_set; ++ led->brightness_get = iot2000_brightness_get; ++ led->default_trigger = name; ++ err = led_classdev_register((struct device *) ++ port->port.dev, led); ++ printk("IOT2000: Registered Led with err=%d\n", err); ++ } ++ } ++ ++ return ret; + } + + #define PCI_DEVICE_ID_COMMTECH_4222PCI335 0x0004 +-- +2.1.4 + diff --git a/meta-iot2000-bsp/recipes-kernel/linux/files/iot2000.cfg b/meta-iot2000-bsp/recipes-kernel/linux/files/iot2000.cfg index 30c28d83..aa077235 100644 --- a/meta-iot2000-bsp/recipes-kernel/linux/files/iot2000.cfg +++ b/meta-iot2000-bsp/recipes-kernel/linux/files/iot2000.cfg @@ -34,3 +34,6 @@ CONFIG_IE6XX_WDT=y CONFIG_IP_NF_NAT=y +CONFIG_R8712U=y +CONFIG_RTL8XXXU=y +CONFIG_RTL8192CU=y diff --git a/meta-iot2000-bsp/recipes-kernel/linux/linux-yocto_4.4.bbappend b/meta-iot2000-bsp/recipes-kernel/linux/linux-yocto_4.4.bbappend index a83da2e7..9dd5926d 100644 --- a/meta-iot2000-bsp/recipes-kernel/linux/linux-yocto_4.4.bbappend +++ b/meta-iot2000-bsp/recipes-kernel/linux/linux-yocto_4.4.bbappend @@ -7,6 +7,7 @@ SRC_URI += " \ file://0004-serial-8250_pci-Fix-EXAR-feature-control-register-co.patch \ file://0005-serial-8250_pci-Add-support-for-IOT2000-platform.patch \ file://0006-x86-efi-Add-capsule-update-driver-for-Intel-Quark.patch \ + file://0007-serial-8250_pci-Add-support-for-accessing-red-LED-vi.patch \ file://iot2000.cfg" LINUX_VERSION_iot2000 = "${LINUX_VERSION_INTEL_COMMON}" diff --git a/meta-iot2000-bsp/recipes-tools/setledcolor/files/setledcolor.py b/meta-iot2000-bsp/recipes-tools/setledcolor/files/setledcolor.py new file mode 100644 index 00000000..fd39d480 --- /dev/null +++ b/meta-iot2000-bsp/recipes-tools/setledcolor/files/setledcolor.py @@ -0,0 +1,50 @@ +#!/usr/bin/python + + +import mraa +import sys +import os + +def redled(state): + redLedFile = "/sys/class/leds/mpio_uart_led:red:user/brightness" + if(not os.path.isfile(redledFile)): + print("Red LED not available") + return + file = open(redLedFile,'w') + if(1==state): + file.write("1") + else: + file.write("0") + file.close() + +def greenled(state): + ledpin = mraa.Gpio(13) + ledpin.dir(mraa.DIR_OUT) + if(1==state): + ledpin.write(1) + else: + ledpin.write(0) + +if(len(sys.argv)<2): + print("Usage: " + sys.argv[0] + " color") + print("color:") + print("0\t\tout") + print("1\t\tgreen") + print("2\t\tred") + print("3\t\torange") + sys.exit() + +x = int(sys.argv[1]) + +if(x%2 == 0): + greenled(0) +else: + greenled(1) + +if(x/2 == 0): + redled(0) +else: + redled(1) + + + diff --git a/meta-iot2000-bsp/recipes-tools/setledcolor/setledcolor_0.1.bb b/meta-iot2000-bsp/recipes-tools/setledcolor/setledcolor_0.1.bb new file mode 100644 index 00000000..85dfb675 --- /dev/null +++ b/meta-iot2000-bsp/recipes-tools/setledcolor/setledcolor_0.1.bb @@ -0,0 +1,17 @@ +DESCRIPTION = "This installs a small python script to handle the led color for the SIMATIC IOT2040" +LICENSE = "MIT" +LIC_FILES_CHKSUM = "file://${IOT2000_MIT_LICENSE};md5=838c366f69b72c5df05c96dff79b35f2" + +SRC_URI = "file://setledcolor.py" + +S = "${WORKDIR}" + +FILES_${PN} += "${sysconfdir}/setledcolor/setledcolor.py \ + ${bindir}/setledcolor" + +do_install() { + install -d ${D}${sysconfdir}/setledcolor + install -d ${D}${bindir} + install -m 755 ${WORKDIR}/setledcolor.py ${D}${sysconfdir}/setledcolor/ + ln -sf /etc/setledcolor/setledcolor.py ${D}${bindir}/setledcolor +} diff --git a/meta-iot2000-example/README.md b/meta-iot2000-example/README.md index db778105..8e5b2b92 100644 --- a/meta-iot2000-example/README.md +++ b/meta-iot2000-example/README.md @@ -61,8 +61,8 @@ environment. ## Configure: ```diff ---- conf/bblayers.conf.old -+++ conf/bblayers.conf +--- iot2000-build/conf/bblayers.conf.old ++++ iot2000-build/conf/bblayers.conf @@ -9,4 +9,10 @@ /home/build/poky/meta \ /home/build/poky/meta-poky \ @@ -79,6 +79,26 @@ environment. This replaces the changes to conf/bblayers.conf documented in ()[../meta-iot2000-bsp/README.md]. The changes to conf/local.conf are the same. +## The opkg package manager: + +If you want to use the opkg package manager, we highly recommend changing the following line in the local.conf: + +```diff +--- iot2000-build/conf/local.conf.old ++++ iot2000-build/conf/local.conf +@@ -120,7 +120,7 @@ +# - 'package_rpm' for rpm style packages +# E.g.: PACKAGE_CLASSES ?= "package_rpm package_deb package_ipk" +# We default to rpm: +-PACKAGE_CLASSES ?= "package_rpm" ++PACKAGE_CLASSES ?= "package_ipk" + +# +# SDK target architecture +``` + +This configures yocto to use the ipk format to build the image itself, so opkg knows which packages are already installed. + ## Create Example Image: ```shell diff --git a/meta-iot2000-example/recipes-core/firmware/firmware-nonfree.bb b/meta-iot2000-example/recipes-core/firmware/firmware-nonfree.bb new file mode 100644 index 00000000..2dba0b81 --- /dev/null +++ b/meta-iot2000-example/recipes-core/firmware/firmware-nonfree.bb @@ -0,0 +1,18 @@ +DESCRIPTION = "includes the firmware files for broadcom and realtek wifi devices" +LICENSE = "MIT" +LIC_FILES_CHKSUM = "file://${IOT2000_MIT_LICENSE};md5=838c366f69b72c5df05c96dff79b35f2" + +SRC_URI = "git://git.kernel.org/pub/scm/linux/kernel/git/firmware/linux-firmware.git" +SRCREV = "a179db97914da5e650c21ba8f9b0bae04a0f8a41" +S = "${WORKDIR}" +INSTDIR = "/lib/firmware/" + +FILES_${PN} = "${INSTDIR}*" + +do_install() { + install -d ${D}${INSTDIR} + install -d ${D}${INSTDIR}brcm/ + install -d ${D}${INSTDIR}rtlwifi/ + cp -R ${S}/git/brcm/* ${D}${INSTDIR}brcm/ + cp -R ${S}/git/rtlwifi/* ${D}${INSTDIR}rtlwifi/ +} diff --git a/meta-iot2000-example/recipes-core/images/iot2000-example-image.inc b/meta-iot2000-example/recipes-core/images/iot2000-example-image.inc index 257ef327..258cff0a 100644 --- a/meta-iot2000-example/recipes-core/images/iot2000-example-image.inc +++ b/meta-iot2000-example/recipes-core/images/iot2000-example-image.inc @@ -16,16 +16,22 @@ IMAGE_FEATURES += " tools-sdk" IMAGE_INSTALL_append = " switchmode" IMAGE_INSTALL_append = " opkg" IMAGE_INSTALL_append = " imageversionfile" +IMAGE_INSTALL_append = " modules-load-entries" IMAGE_INSTALL_append = " dmidecode" IMAGE_INSTALL_append = " openssh" IMAGE_INSTALL_append = " screen minicom" IMAGE_INSTALL_append = " mraa upm" IMAGE_INSTALL_append = " parted e2fsprogs dosfstools" -IMAGE_INSTALL_append = " nodejs" +IMAGE_INSTALL_append = " nodejs nodejs-npm" +IMAGE_INSTALL_append = " node-red node-red-dashboard node-mraa node-red-node-intel-gpio" IMAGE_INSTALL_append = " curl" IMAGE_INSTALL_append = " pciutils" IMAGE_INSTALL_append = " iptables" IMAGE_INSTALL_append = " cmake" -IMAGE_INSTALL_append = " nano" -IMAGE_INSTALL_append = " iw wpa-supplicant" +IMAGE_INSTALL_append = " nano tree" +IMAGE_INSTALL_append = " iw wpa-supplicant wireless-tools" IMAGE_INSTALL_append = " galileo-target" +IMAGE_INSTALL_append = " firmware-nonfree" +IMAGE_INSTALL_append = " iot2000setup" +IMAGE_INSTALL_append = " sqlite3" +IMAGE_INSTALL_append = " i2c-tools" diff --git a/meta-iot2000-example/recipes-example/busybox/busybox_1.24.1.bbappend b/meta-iot2000-example/recipes-example/busybox/busybox_1.24.1.bbappend index 5ea7c00c..60d7a479 100644 --- a/meta-iot2000-example/recipes-example/busybox/busybox_1.24.1.bbappend +++ b/meta-iot2000-example/recipes-example/busybox/busybox_1.24.1.bbappend @@ -4,3 +4,4 @@ FILESEXTRAPATHS_prepend := "${THISDIR}/files:" SRC_URI_append = " file://arp.cfg" +SRC_URI_append = " file://lsusb.cfg" diff --git a/meta-iot2000-example/recipes-example/busybox/files/lsusb.cfg b/meta-iot2000-example/recipes-example/busybox/files/lsusb.cfg new file mode 100644 index 00000000..346ce044 --- /dev/null +++ b/meta-iot2000-example/recipes-example/busybox/files/lsusb.cfg @@ -0,0 +1 @@ +CONFIG_LSUSB=y \ No newline at end of file diff --git a/meta-iot2000-example/recipes-example/e2fsprogs/e2fsprogs_%.bbappend b/meta-iot2000-example/recipes-example/e2fsprogs/e2fsprogs_%.bbappend new file mode 100644 index 00000000..34c98821 --- /dev/null +++ b/meta-iot2000-example/recipes-example/e2fsprogs/e2fsprogs_%.bbappend @@ -0,0 +1,4 @@ +#This recipe adds "resize2fs" as dependencie so it will be installed with the +#default package + +RDEPENDS_e2fsprogs += " e2fsprogs-resize2fs" diff --git a/meta-iot2000-example/recipes-example/iot2000setup/files/expandfs.sh b/meta-iot2000-example/recipes-example/iot2000setup/files/expandfs.sh new file mode 100755 index 00000000..ec72c133 --- /dev/null +++ b/meta-iot2000-example/recipes-example/iot2000setup/files/expandfs.sh @@ -0,0 +1,38 @@ +#!/bin/sh + +DEVICE_TYPE=$(mount | head -n1 | cut -f 1 -d ' ' | cut -f 3 -d / | head -c 1) # returns 's' for boot from USB, 'm' for boot from SD + +if [ $DEVICE_TYPE == "s" ] + then + ROOT_PARTITION="/dev/sda2" + ROOT_DEVICE="/dev/sda" + PART_NUMBER=2 + elif [ $DEVICE_TYPE=="m" ] + then + ROOT_PARTITION="/dev/mmcblk0p2" + ROOT_DEVICE="/dev/mmcblk0" + PART_NUMBER=2 + else + echo "Cannot determine boot device." + exit +fi + +START_BLOCK=$(parted $ROOT_DEVICE -ms unit s p | grep "^2" | cut -f 2 -d: | rev | cut -c 2- | rev) + + +fdisk $ROOT_DEVICE <"] + + if (device == "IOT2020"): + deviceIsIot2020 = True + + # Enable serial mode setting if device is IOT2040 + if (not deviceIsIot2020): + menuItems.append("Set Serial Mode") + if (wifiEnabled and wifiInterfaceConfigured): + menuItems.append("Configure WLAN") + + action, selection = ListboxChoiceWindow( + gscreen, + title, "", + menuItems, + [('Quit', 'quit', 'ESC')]) + + if (action == 'quit'): + gscreen.finish() + if (networkConfigurationChanged == True): + print(chr(27) + "[2J") # Clear console + print("\033[1;34mRestarting network services...\033[0m\n") + subprocess.call("/etc/init.d/networking restart", shell=True) + if (wifiEnabled): + subprocess.call("/sbin/ifdown wlan0", shell=True) + subprocess.call("/sbin/ifup wlan0", shell=True) + + exit() + + if selection == 0: + changeRootPassword() + elif selection == 1: + changeHostName() + elif selection == 2: + expandFileSystem() + elif selection == 3: + configureNetworkInterfaces() + elif selection == 4: + configureOpkgRepository() + elif selection == 5: + removeUnusedPackages() + elif selection == 6: + advancedOptions() + elif selection == 7: + if (not deviceIsIot2020): + configureSerial() + elif (wifiEnabled and wifiInterfaceConfigured): + configureWLAN() + elif selection == 8: + configureWLAN() + +def changeNodeRedAutoStart(status): + if (status == "on"): + fileName = "/etc/init.d/launch_node-red.sh" + initFile = open(fileName, 'w') + initFile.write("#!/bin/sh\n" + "/usr/bin/node /usr/lib/node_modules/node-red/red >/dev/null &") + initFile.close() + + st = os.stat(fileName) + os.chmod(fileName, st.st_mode | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH) + subprocess.call("update-rc.d launch_node-red.sh defaults", shell=True, stdout=open(os.devnull, 'wb')) + elif (status == "off"): + subprocess.call("update-rc.d launch_node-red.sh remove", shell=True, stdout=open(os.devnull, 'wb')) + os.remove("/etc/init.d/launch_node-red.sh") + +def changeSshServerSetting(status): + if (status == "on"): + subprocess.call("update-rc.d -f sshd defaults", shell=True, stdout=open(os.devnull, 'wb')) + subprocess.call("/etc/init.d/sshd start", shell=True, stdout=open(os.devnull, 'wb')) + elif (status == "off"): + subprocess.call("/etc/init.d/sshd stop", shell=True, stdout=open(os.devnull, 'wb')) + subprocess.call("update-rc.d -f sshd remove", shell=True, stdout=open(os.devnull, 'wb')) + +def advancedOptions(): + task = subprocess.Popen("/etc/init.d/sshd status", stdout=subprocess.PIPE, shell=True) + taskReturn = task.stdout.read().lstrip().rstrip() + sshEnabled = "running" in taskReturn + + noderedAutostartEnabled = os.path.isfile("/etc/init.d/launch_node-red.sh") + + bb = ButtonBar(gscreen, [("Done", "done", "ESC")]) + ct = CheckboxTree(height = 7, scroll = 1,width=40) + + ct.append("Auto Start node-red", selected=noderedAutostartEnabled) + ct.append("SSH Server Enabled", selected=sshEnabled) + + g = GridForm(gscreen, "Advanced Options", 1, 4) + g.add(ct, 0, 1) + g.add(bb, 0, 3, growx = 1) + result = g.runOnce() + selectedOptions = ct.getSelection() + + noderedAutostartEnabledNew = "Auto Start node-red" in selectedOptions + sshEnabledNew = "SSH Server Enabled" in selectedOptions + + if (noderedAutostartEnabled != noderedAutostartEnabledNew): + if ("Auto Start node-red" in selectedOptions): + changeNodeRedAutoStart("on") + else: + changeNodeRedAutoStart("off") + + if (sshEnabled != sshEnabledNew): + if ("SSH Server Enabled" in selectedOptions): + changeSshServerSetting("on") + else: + changeSshServerSetting("off") + + displayStartScreen() + +def changeRootPassword(): + gscreen.finish() + print(chr(27) + "[2J") # Clear console + + subprocess.call(["passwd", "root"]) + displayStartScreen() + +def removeUnusedPackages(): + ### Edit here ### + packageList = ["galileo-target", "nodejs"] # Contains all potential + # candidates for removal + ### + + bb = ButtonBar(gscreen, (("Ok", "ok"), ("Cancel", "cancel"))) + ct = CheckboxTree(height = 10, scroll = 1,width=40) + + # Iterate through list of removal candidates and check if they are + # actually installed. + task = subprocess.Popen("/usr/bin/opkg list-installed", stdout=subprocess.PIPE, shell=True) + installedPackages = task.stdout.read() + + numberOfRemovablePackages = 0 + for package in packageList: + if (package in installedPackages): + ct.append(package) + numberOfRemovablePackages += 1 + + g = GridForm(gscreen, "Select Packages to Remove", 1, 4) + l = Label("Use 'Space' to select the packages you want to remove.") + g.add(l, 0, 0, growy=1, growx=1, padding=(1,1,1,1)) + g.add(ct, 0, 1) + g.add(bb, 0, 3, growx = 1) + result = g.runOnce() + + removeList = '' + if (bb.buttonPressed(result) == "ok" and numberOfRemovablePackages > 0): + # Build list of selected packages + selectedPackages = ct.getSelection() + for package in selectedPackages: + removeList = removeList + package + '* ' + + ret = ButtonChoiceWindow( + gscreen, + "Remove Packages", + "Are you sure you want to remove the following packages: \n\n" + removeList, + buttons=[("OK", "ok"), ("Cancel", "cancel", "ESC")], + width=40) + + if (ret == "ok"): + removeList = "/usr/bin/opkg --force-removal-of-dependent-packages remove " + removeList + gscreen.finish() + print(chr(27) + "[2J") # Clear console + print("\033[1;34mRemoving selected packages...\033[0m\n") + subprocess.call(removeList, shell=True) + + displayStartScreen() + + +def getSerialModeForPort(port): + fileName = "/etc/init.d/set_serial_mode_" + port + ".sh" + + if (os.path.isfile(fileName)): + lines = [line.rstrip('\n') for line in open(fileName)] + selectedMode = lines[1].split()[2] + + if selectedMode == "rs232": + return 0 + elif selectedMode == "rs485": + return 1 + elif selectedMode == "rs422": + return 2 + return 0 + +def configureSerial(): + portAction, portSelection = ListboxChoiceWindow( + gscreen, + "Configure Serial Mode", "Select the serial port you want to configure and press 'Enter'.", + ["X30", "X31"], + [('Cancel', 'cancel', 'ESC')]) + if (portSelection == 0): + portName = "X30" + else: + portName = "X31" + + currentMode = getSerialModeForPort(portName) + + if (portAction != "cancel"): + modes = ["RS232", "RS485", "RS422"] + + modeAction, modeSelection = ListboxChoiceWindow( + gscreen, + "Configure Serial Mode", "Select a mode.", + modes, + [('Cancel', 'cancel', 'ESC')], default=currentMode) + + if (modeAction != "cancel"): + persistentReturn = ButtonChoiceWindow( + gscreen, + "Configure Serial Mode", + "Do you want to make your changes persistent? (Mode setting will be kept after reboot.) ", + buttons=[("Yes", "yes"), ("No", "no", "ESC")], + width=40) + switchTool = '/usr/bin/switchserialmode' + + if (portSelection == 0): + switchDeviceArg = '/dev/ttyS2' + else: + switchDeviceArg = '/dev/ttyS3' + + switchModeArg = modes[modeSelection].lower() + switchCommand = switchTool + " " + switchDeviceArg + " " + switchModeArg + subprocess.Popen([switchTool, switchDeviceArg, switchModeArg], stdout=open(os.devnull, 'wb')) + + if (persistentReturn == "yes"): + fileName = "set_serial_mode_" + portName + ".sh" + filePath = "/etc/init.d/" + fileName + initFile = open(fileName, 'w') + initFile.write("#!/bin/sh\n" + switchCommand) + initFile.close() + + st = os.stat(fileName) + os.chmod(fileName, st.st_mode | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH) + subprocess.call("update-rc.d " + fileName + " defaults", shell=True, stdout=open(os.devnull, 'wb')) + + + displayStartScreen() + +def changeHostName(): + currentHostName = subprocess.check_output("hostname") + + ret = EntryWindow( + gscreen, + "Change Host Name", + "", + [("Host Name:", currentHostName)], + 1, + 70, 50, + [('OK'), ('Cancel', 'cancel', 'ESC')], + None) + + if (ret[0] == "ok"): + subprocess.Popen(["hostname", ret[1][0].rstrip()], stdout=open(os.devnull, 'wb')) + + displayStartScreen() + +def configureOpkgRepository(): + ret = EntryWindow( + gscreen, + "Configure OPKG Repository", + "", + [("Host Address:", "")], + 1, + 70, 50, + ['OK', ('Cancel', 'cancel', 'ESC')], + None) + + fileTemplate = '''src/gz all http://[host]/ipk/all +src/gz i586-nlp-32 http://[host]/ipk/i586-nlp-32 +src/gz i586-nlp-32-intel-common http://[host]/ipk/i586-nlp-32-intel-common +src/gz iot2000 http://[host]/ipk/iot2000 +''' + if (ret[0] == "ok"): + opkgConfig = fileTemplate.replace("[host]", ret[1][0].rstrip()) + fileName = "/etc/opkg/iot2000.conf" + + opkgFile = open(fileName, 'w') + opkgFile.write(opkgConfig) + opkgFile.close() + + displayStartScreen() + + +def configureWLAN(): + global networkConfigurationChanged + + ret = EntryWindow( + gscreen, + "Configure WLAN", + "", + [("Type:", "WPA-PSK"), ("SSID:", ""), ("Key:", "")], + 1, + 70, 50, + ['OK', ('Cancel', 'cancel', 'ESC')], + None) + + fileTemplate = '''ctrl_interface=/var/run/wpa_supplicant +ctrl_interface_group=0 +update_config=1 + +network={ + key_mgmt=[type] + ssid="[ssid]" + psk="[passwd]" +}''' + + if (ret[0] == "ok"): + wpaConfig = fileTemplate.replace("[type]", ret[1][0].rstrip()).replace("[ssid]", ret[1][1].rstrip()).replace("[passwd]", ret[1][2].rstrip()) + + fileName = "/etc/wpa_supplicant.conf" + + backupFileName = "/etc/wpa_supplicant.conf.bak" + copyfile(fileName, backupFileName) + + wpaFile = open(fileName, 'w') + wpaFile.write(wpaConfig) + wpaFile.close() + + rv = ButtonChoiceWindow( + gscreen, + "Configure WLAN", + "Your WLAN configuration has been changed. A backup of the old configuration can be found at: " + backupFileName, + buttons=["OK"], + width=40) + + networkConfigurationChanged = 1 + + displayStartScreen() + +def getNetworkInterfaceConfiguration(interface): + lines = [line.rstrip('\n') for line in open('/etc/network/interfaces')] + for lineNumber in range(0, len(lines)-1): + searchString = "auto " + interface + + if (searchString in lines[lineNumber]): + splitLine = lines[lineNumber].split() + + while (splitLine[0] != "iface"): + lineNumber += 1 + splitLine = lines[lineNumber].split() + + mode = splitLine[3] + + if (mode == "dhcp"): + return "dhcp" + if (mode == "static"): + while (splitLine[0] != "address"): + lineNumber += 1 + splitLine = lines[lineNumber].split() + return splitLine[1] + + lineNumber += 1 + + return "dhcp" + +def configureNetworkInterfaces(): + global networkConfigurationChanged + global wifiEnabled + global deviceIsIot2020 + + if deviceIsIot2020: + interfaces = ([('eth0', getNetworkInterfaceConfiguration('eth0'))]) + else: + interfaces = ([('eth0', getNetworkInterfaceConfiguration('eth0')) , ('eth1', getNetworkInterfaceConfiguration('eth1'))]) + + if wifiEnabled: + interfaces.append(('wlan0', getNetworkInterfaceConfiguration('wlan0'))) + + ret = EntryWindow( + gscreen, + "Configure Network Interfaces", + "Specify IP addresses for network interfaces, enter 'dhcp' to obtain address by DHCP.", + interfaces, + 1, + 70, 50, + ['OK', ('Cancel', 'cancel', 'ESC')], + None) + + interfacesConfig = """# /etc/network/interfaces -- configuration file for ifup(8), ifdown(8) + +# The loopback interface +auto lo +iface lo inet loopback + +# Wired interfaces +""" + dhcpTemplate = """auto [interfaceName] +iface [interfaceName] inet dhcp + +""" + staticTemplate = """auto [interfaceName] +iface [interfaceName] inet static + address [ip] + netmask 255.255.255.0 + +""" + + wirelessDhcpTemplate = """allow-hotplug wlan0 +auto wlan0 +iface wlan0 inet dhcp + wpa-conf /etc/wpa_supplicant.conf + +""" + wirelessStaticTemplate = """allow-hotplug wlan0 +auto wlan0 +iface wlan0 inet static + address [ip] + netmask 255.255.255.0 + wpa-conf /etc/wpa_supplicant.conf + +""" + + i = 0 + for interface in interfaces: + if (interface[0] == "wlan0"): + if (ret[1][i] == "dhcp"): + interfacesConfig = interfacesConfig + wirelessDhcpTemplate.replace("[interfaceName]", interface[0]) + else: + interfacesConfig = interfacesConfig + wirelessStaticTemplate.replace("[interfaceName]", interface[0]).replace("[ip]", ret[1][i]) + else: + if (ret[1][i] == "dhcp"): + interfacesConfig = interfacesConfig + dhcpTemplate.replace("[interfaceName]", interface[0]) + else: + interfacesConfig = interfacesConfig + staticTemplate.replace("[interfaceName]", interface[0]).replace("[ip]", ret[1][i]) + i += 1 + + if (ret[0] == "ok"): + fileName = "/etc/network/interfaces" + backupFileName = "/etc/network/interfaces.bak" + copyfile(fileName, backupFileName) + interfacesFile = open(fileName, 'w') + interfacesFile.write(interfacesConfig) + interfacesFile.close() + + networkConfigurationChanged = 1 + rv = ButtonChoiceWindow( + gscreen, + "Configure Network Interfaces", + "Your network interfaces have been reconfigured. A backup of the old configuration can be found at: " + backupFileName, + buttons=["OK"], + width=40) + + displayStartScreen() + + +def expandFileSystem(): + subprocess.call("/etc/iot2000setup/expandfs.sh", stdout=open(os.devnull, 'wb')) + task = subprocess.Popen("df -h | grep '/dev/root' | awk '{print $2}'", stdout=subprocess.PIPE, shell=True) + newPartitionSize = task.stdout.read().lstrip().rstrip() + + rv = ButtonChoiceWindow( + gscreen, + "Expand File System", + "Successfully expanded file system. New partition size is " + newPartitionSize + ".", + buttons=["OK"], + width=40) + + displayStartScreen() + +displayStartScreen() + diff --git a/meta-iot2000-example/recipes-example/iot2000setup/iot2000setup_1.0.bb b/meta-iot2000-example/recipes-example/iot2000setup/iot2000setup_1.0.bb new file mode 100644 index 00000000..46eec02a --- /dev/null +++ b/meta-iot2000-example/recipes-example/iot2000setup/iot2000setup_1.0.bb @@ -0,0 +1,23 @@ +SUMMARY = "Copy iot2000setup files to file system" +LICENSE = "MIT" +LIC_FILES_CHKSUM = "file://${IOT2000_MIT_LICENSE};md5=838c366f69b72c5df05c96dff79b35f2" + +SRC_URI = "file://expandfs.sh file://iot2000setup.py" + +FILES_${PN} += " \ + ${sysconfdir}/iot2000setup/expandfs.sh \ + ${sysconfdir}/iot2000setup/iot2000setup.py \ + ${bindir}/iot2000setup \ +" + +RDEPENDS_${PN} += " libnewt-python" + +do_install() { + install -d ${D}${sysconfdir}/iot2000setup + install -d ${D}${bindir} + install -m 0755 ${WORKDIR}/expandfs.sh ${D}${sysconfdir}/iot2000setup/expandfs.sh + install -m 0755 ${WORKDIR}/iot2000setup.py ${D}${sysconfdir}/iot2000setup/iot2000setup.py + ln -sf /etc/iot2000setup/iot2000setup.py ${D}${bindir}/iot2000setup +} + + diff --git a/meta-iot2000-example/recipes-example/modules/files/i2c-dev.conf b/meta-iot2000-example/recipes-example/modules/files/i2c-dev.conf new file mode 100644 index 00000000..0cdf71fd --- /dev/null +++ b/meta-iot2000-example/recipes-example/modules/files/i2c-dev.conf @@ -0,0 +1 @@ +i2c-dev diff --git a/meta-iot2000-example/recipes-example/modules/modules-load-entries_1.0.bb b/meta-iot2000-example/recipes-example/modules/modules-load-entries_1.0.bb new file mode 100644 index 00000000..9c8583e0 --- /dev/null +++ b/meta-iot2000-example/recipes-example/modules/modules-load-entries_1.0.bb @@ -0,0 +1,9 @@ +LICENSE = "MIT" +LIC_FILES_CHKSUM = "file://${IOT2000_MIT_LICENSE};md5=838c366f69b72c5df05c96dff79b35f2" + +SRC_URI = "file://i2c-dev.conf" + +do_install() { + install -d ${D}/etc/modules-load.d/ + install -m 0444 ${WORKDIR}/i2c-dev.conf ${D}/etc/modules-load.d/ +} \ No newline at end of file diff --git a/meta-iot2000-example/recipes-example/mraa/files/0001-Include-support-for-SIMATIC-IOT2000-platform.patch b/meta-iot2000-example/recipes-example/mraa/files/0001-Include-support-for-SIMATIC-IOT2000-platform.patch deleted file mode 100644 index b6e1c88e..00000000 --- a/meta-iot2000-example/recipes-example/mraa/files/0001-Include-support-for-SIMATIC-IOT2000-platform.patch +++ /dev/null @@ -1,28 +0,0 @@ -From d689c5e35246dd7ee060023a80fff79bf244e1f9 Mon Sep 17 00:00:00 2001 -From: Sascha Weisenberger -Date: Mon, 1 Aug 2016 10:35:36 +0100 -Subject: [PATCH] Include support for SIMATIC IOT2000 platform - ---- - src/x86/x86.c | 5 ++++- - 1 file changed, 4 insertions(+), 1 deletion(-) - -diff --git a/src/x86/x86.c b/src/x86/x86.c -index b3a0ae5..288a46c 100644 ---- a/src/x86/x86.c -+++ b/src/x86/x86.c -@@ -51,7 +51,10 @@ mraa_x86_platform() - FILE* fh = fopen("/sys/devices/virtual/dmi/id/board_name", "r"); - if (fh != NULL) { - if (getline(&line, &len, fh) != -1) { -- if (strncmp(line, "GalileoGen2", 11) == 0) { -+ if (strncmp(line, "SIMATIC IOT2000", 15) == 0) { -+ platform_type = MRAA_INTEL_GALILEO_GEN2; -+ plat = mraa_intel_galileo_gen2(); -+ } else if (strncmp(line, "GalileoGen2", 11) == 0) { - platform_type = MRAA_INTEL_GALILEO_GEN2; - plat = mraa_intel_galileo_gen2(); - } else if (strncmp(line, "BODEGA BAY", 10) == 0) { --- -2.1.4 - diff --git a/meta-iot2000-example/recipes-example/mraa/files/0002-intel_galileo_rev_g.c-use-pincmd-to-set-OUT_HIGH-ins.patch b/meta-iot2000-example/recipes-example/mraa/files/0002-intel_galileo_rev_g.c-use-pincmd-to-set-OUT_HIGH-ins.patch deleted file mode 100644 index 2b07f639..00000000 --- a/meta-iot2000-example/recipes-example/mraa/files/0002-intel_galileo_rev_g.c-use-pincmd-to-set-OUT_HIGH-ins.patch +++ /dev/null @@ -1,69 +0,0 @@ -From 8ec4fcb3339e1d81390e456b7b052744e4af7c4d Mon Sep 17 00:00:00 2001 -From: Brendan Le Foll -Date: Fri, 2 Sep 2016 12:00:28 +0100 -Subject: [PATCH] intel_galileo_rev_g.c: use pincmd to set OUT_HIGH instead of - value - -The i/o expander looses connection as soon as direction is set so use direction -OUT_HIGH instead of setting value after direction. Closes #573 - -Signed-off-by: Brendan Le Foll ---- - src/x86/intel_galileo_rev_g.c | 16 ++++++++-------- - 1 file changed, 8 insertions(+), 8 deletions(-) - -diff --git a/src/x86/intel_galileo_rev_g.c b/src/x86/intel_galileo_rev_g.c -index d0fe8d0..35533c0 100644 ---- a/src/x86/intel_galileo_rev_g.c -+++ b/src/x86/intel_galileo_rev_g.c -@@ -808,9 +808,9 @@ mraa_intel_galileo_gen2() - b->pins[18].aio.mux[0].pincmd = PINCMD_SET_DIRECTION; - b->pins[18].aio.mux[0].pin = 57; - b->pins[18].aio.mux[0].value = MRAA_GPIO_IN; -- b->pins[18].aio.mux[1].pincmd = PINCMD_SET_OUT_VALUE; -+ b->pins[18].aio.mux[1].pincmd = PINCMD_SET_DIRECTION; - b->pins[18].aio.mux[1].pin = 60; -- b->pins[18].aio.mux[1].value = 1; -+ b->pins[18].aio.mux[1].value = MRAA_GPIO_OUT_HIGH; - b->pins[18].aio.mux[2].pincmd = PINCMD_SET_VALUE; - b->pins[18].aio.mux[2].pin = 78; - b->pins[18].aio.mux[2].value = 0; -@@ -819,9 +819,9 @@ mraa_intel_galileo_gen2() - b->pins[18].gpio.mux[0].pincmd = PINCMD_SET_DIRECTION; - b->pins[18].gpio.mux[0].pin = 57; - b->pins[18].gpio.mux[0].value = MRAA_GPIO_IN; -- b->pins[18].gpio.mux[1].pincmd = PINCMD_SET_OUT_VALUE; -+ b->pins[18].gpio.mux[1].pincmd = PINCMD_SET_DIRECTION; - b->pins[18].gpio.mux[1].pin = 60; -- b->pins[18].gpio.mux[1].value = 1; -+ b->pins[18].gpio.mux[1].value = MRAA_GPIO_OUT_HIGH; - b->pins[18].gpio.mux[2].pincmd = PINCMD_SET_VALUE; - b->pins[18].gpio.mux[2].pin = 78; - b->pins[18].gpio.mux[2].value = 1; -@@ -845,9 +845,9 @@ mraa_intel_galileo_gen2() - b->pins[19].aio.mux[0].pincmd = PINCMD_SET_DIRECTION; - b->pins[19].aio.mux[0].pin = 59; - b->pins[19].aio.mux[0].value = MRAA_GPIO_IN; -- b->pins[19].aio.mux[1].pincmd = PINCMD_SET_OUT_VALUE; -+ b->pins[19].aio.mux[1].pincmd = PINCMD_SET_DIRECTION; - b->pins[19].aio.mux[1].pin = 60; -- b->pins[19].aio.mux[1].value = 1; -+ b->pins[19].aio.mux[1].value = MRAA_GPIO_OUT_HIGH; - b->pins[19].aio.mux[2].pincmd = PINCMD_SET_VALUE; - b->pins[19].aio.mux[2].pin = 79; - b->pins[19].aio.mux[2].value = 0; -@@ -856,9 +856,9 @@ mraa_intel_galileo_gen2() - b->pins[19].gpio.mux[0].pincmd = PINCMD_SET_DIRECTION; - b->pins[19].gpio.mux[0].pin = 59; - b->pins[19].gpio.mux[0].value = MRAA_GPIO_IN; -- b->pins[19].gpio.mux[1].pincmd = PINCMD_SET_OUT_VALUE; -+ b->pins[19].gpio.mux[1].pincmd = PINCMD_SET_DIRECTION; - b->pins[19].gpio.mux[1].pin = 60; -- b->pins[19].gpio.mux[1].value = 1; -+ b->pins[19].gpio.mux[1].value = MRAA_GPIO_OUT_HIGH; - b->pins[19].gpio.mux[2].pincmd = PINCMD_SET_VALUE; - b->pins[19].gpio.mux[2].pin = 79; - b->pins[19].gpio.mux[2].value = 1; --- -2.1.4 - diff --git a/meta-iot2000-example/recipes-example/mraa/mraa_%.bbappend b/meta-iot2000-example/recipes-example/mraa/mraa_%.bbappend index fff7fbe4..9424c5cc 100644 --- a/meta-iot2000-example/recipes-example/mraa/mraa_%.bbappend +++ b/meta-iot2000-example/recipes-example/mraa/mraa_%.bbappend @@ -1,9 +1,22 @@ -#This patch will include the SIMATIC IOT2000 as a known board that is similar to Galileo Gen 2 +#This .bbappend file will set the mraa version to 1.5.1, where the SIMATIC +#IOT2000 board name is already included. #Also the missing "meta-java" from Intel caused trouble so we use "java2" here -FILESEXTRAPATHS_prepend := "${THISDIR}/files:" +PV="1.5.1" -SRC_URI_append = " file://0001-Include-support-for-SIMATIC-IOT2000-platform.patch \ - file://0002-intel_galileo_rev_g.c-use-pincmd-to-set-OUT_HIGH-ins.patch" +SRC_URI = "git://github.com/intel-iot-devkit/mraa.git" +SRCREV="6f9b470d8d25e2c8ba1586cd9d707b870ab30010" -RDEPENDS_${PN}-java = "java2-runtime" \ No newline at end of file +RDEPENDS_${PN}-java = "java2-runtime" + +#include node-mraa so the lib can be used by node-red +PROVIDES = "node-mraa" + +#The mraa project has some trouble installing the module in the right place, so here is an workaround. +#PYTHON_SITEPACKAGES_DIR contains "dist-packages", I really don't know why... + +FILES_python-${PN} = "${PYTHON_SITEPACKAGES_DIR}/../site-packages" +do_install_append(){ + install -d ${D}/usr/lib/python2.7/site-packages/ + cp ${D}/usr/lib/python2.7/dist-packages/* ${D}/usr/lib/python2.7/site-packages +} diff --git a/meta-iot2000-example/recipes-example/mraa/upm_%.bbappend b/meta-iot2000-example/recipes-example/mraa/upm_%.bbappend index cce6fc19..110085d4 100644 --- a/meta-iot2000-example/recipes-example/mraa/upm_%.bbappend +++ b/meta-iot2000-example/recipes-example/mraa/upm_%.bbappend @@ -1,3 +1,9 @@ #The missing "meta-java" from Intel caused trouble so we use "java2" here +#Also we upgrade to version 1.0.1 to fit the mraa version + +PV="1.0.1" + +SRC_URI = "git://github.com/intel-iot-devkit/upm.git" +SRCREV="a2698fd560c9fa7917de33a65601bea50d218481" RDEPENDS_${PN}-java = "java2-runtime mraa-java" \ No newline at end of file diff --git a/meta-iot2000-example/recipes-internal/imageversionfile/files/image-release b/meta-iot2000-example/recipes-internal/imageversionfile/files/image-release index 9ccd83b7..7446d891 100644 --- a/meta-iot2000-example/recipes-internal/imageversionfile/files/image-release +++ b/meta-iot2000-example/recipes-internal/imageversionfile/files/image-release @@ -1 +1 @@ -IMAGE_RELEASE="V2.1.0" +IMAGE_RELEASE="V2.1.2"