commit 29ce635570a0a6868a5094f57e3ce904d4be9030 Author: ScottW514 Date: Wed Apr 15 17:09:41 2020 -0400 Add files via upload diff --git a/BUILD.md b/BUILD.md new file mode 100644 index 0000000..ecd2aeb --- /dev/null +++ b/BUILD.md @@ -0,0 +1,51 @@ +# Build +Instructions are for a Linux environment supported by Yocto. + +To get the build OpenGlow/ForgeFIRM you need to have `repo` installed: + +## Install the `repo` utility: + +```console +mkdir ~/bin +curl http://commondatastorage.googleapis.com/git-repo-downloads/repo > ~/bin/repo +chmod a+x ~/bin/repo +PATH=${PATH}:~/bin +``` +Add the following to the end of ```~/.bashrc``` to permanently add ```repo``` to your path: +```console +export PATH=~/bin:$PATH +``` +## Download the BSP source: + +```console +mkdir forgefirm +cd forgefirm +repo init -u https://github.com/ScottW514/forgefirm.git -b master -m default.xml +repo sync +``` + +At the end of the commands you have all meta packages you need to build the basic firmware images. + +## Build the OpenGlow/ForgeFIRM image for factory control boards +First time environment setup: +```console +(in forgefirm directory) +MACHINE=glowforge DISTRO=forgefirm . setup-environment build +bitbake forgefirm-image +``` +Subsequent builds: +```console +(in forgefirm directory) +. setup-environment build +bitbake forgefirm-image +``` + +## Bootable Image: +The bootable image can be found in ```forgefirm/build/tmp/deploy/images/```. + +It can be written directly to an SDCARD: +```console +(in forgefirm/build directory) +cd tmp/deploy/images/glowforge +sudo zcat forgefirm-image-glowforge.wic.gz | dd of=/dev/sdX bs=1M +``` diff --git a/COPYING.MIT b/COPYING.MIT new file mode 100644 index 0000000..f7fc5fb --- /dev/null +++ b/COPYING.MIT @@ -0,0 +1,20 @@ +Copyright 2018-2020 +Scott Wiederhold + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is furnished +to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..976aef1 --- /dev/null +++ b/LICENSE @@ -0,0 +1,9 @@ +All metadata is MIT licensed unless otherwise stated. Source code and binaries +included in tree for individual recipes are under the LICENSE stated in +the associated recipe (.bb file) unless otherwise stated. + +See: +COPYING.MIT (MIT) + +License information for any other files is either explicitly stated +or defaults to GPL version 2. diff --git a/README.md b/README.md new file mode 100644 index 0000000..8755478 --- /dev/null +++ b/README.md @@ -0,0 +1,15 @@ +# OpenGlow/ForgeFIRM Firmware for Glowforge +This repository contains opensource firmware for Glowforge brand CNC lasers. + +* [Latest Release](https://github.com/ScottW514/forgefirm/releases) +* [Installation Instructions](https://community.openglow.org/t/dual-boot-install-of-openglow-on-factory-flash/697) +* [Build Instructions](https://github.com/ScottW514/meta-forgefirm/blob/master/BUILD.md) +* [Community Support](https://community.openglow.org) + +# Roadmap +* Base image that supports all Glowforge hardware (complete) +* Support Glowforge web service - Python implementation (mostly complete) +* REST API w/ G-Code support (in progress) +* Browser-based GUI (pending) + +This project is for experimental purposes only, and is not supported or endorsed by Glowforge. diff --git a/base/conf/forgefirm-bblayers.conf b/base/conf/forgefirm-bblayers.conf new file mode 100644 index 0000000..1dda159 --- /dev/null +++ b/base/conf/forgefirm-bblayers.conf @@ -0,0 +1,23 @@ +POKY_BBLAYERS_CONF_VERSION = "2" + +BBPATH = "${TOPDIR}" +BSPDIR := "${@os.path.abspath(os.path.dirname(d.getVar('FILE', True)) + '/../..')}" + +BBFILES ?= "" +BBLAYERS = " \ + ${BSPDIR}/sources/poky/meta \ + ${BSPDIR}/sources/poky/meta-poky \ + \ + ${BSPDIR}/sources/meta-openembedded/meta-oe \ + \ + ${BSPDIR}/sources/meta-freescale \ + ${BSPDIR}/sources/meta-freescale-distro \ + \ + ${BSPDIR}/sources/meta-openembedded/meta-python \ + ${BSPDIR}/sources/meta-openembedded/meta-networking \ + \ + ${BSPDIR}/sources/meta-openglow/meta-openglow-core \ + ${BSPDIR}/sources/meta-openglow/meta-glowforge-bsp \ + \ + ${BSPDIR}/sources/forgefirm/meta-forgefirm \ +" diff --git a/default.xml b/default.xml new file mode 100644 index 0000000..8e0a906 --- /dev/null +++ b/default.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/scripts/ffboot b/scripts/ffboot new file mode 100644 index 0000000..6af2c2b --- /dev/null +++ b/scripts/ffboot @@ -0,0 +1,91 @@ +#!/bin/sh +# (C) Copyright 2020 +# Scott Wiederhold, s.e.wiederhold@gmail.com +# https://community.openglow.org +# SPDX-License-Identifier: MIT +# +# This program sets the bootloader to the requested image and reboots + +usage () { + cat <] [-n] + -s: SDCARD OpenGlow/ForgeFIRM + -e[]: eMMC + 1: Factory image 1 + 2: Factory image 2 + 4: OpenGlow/ForgeFIRM image + Default: + When run from OpenGlow/ForgeFIRM: Factory image with most recent firmwmare + When run from Factory : Factory image 1 + -n: No reboot +END +} + +REBOOT=1 + +if [ $# -gt 2 ]; then + usage + exit 2 +fi + +if [ $# -gt 1 ]; then + if [ $2 = "-n" ]; then + REBOOT=0 + else + usage + exit 2 + fi +fi + +case "$1" in + -s) + MMCDEV=0 + MMCPART=1 + ;; + -e) + MMCDEV=1 + MMCPART=1 + if [ -d "/factory" ]; then + V1=$(cat /factory/img1/etc/version) + V2=$(cat /factory/img2/etc/version) + if [ $V2 -gt $V1 ]; then + MMCPART=2 + fi + fi + ;; + -e1) + MMCDEV=1 + MMCPART=1 + ;; + -e2) + MMCDEV=1 + MMCPART=2 + ;; + -e4) + MMCDEV=1 + MMCPART=4 + ;; + *) + usage + exit 2 +esac + +if [ -d "/factory" ]; then + FWCONFIG="/etc/fw_env.config" +else + FWCONFIG="/etc/fw_env_mmcblk2.config" +fi + +MMCROOT="/dev/mmcblk"$(($MMCDEV + 1))"p"$MMCPART + +echo "Setting to boot from $MMCROOT" +fw_setenv -c $FWCONFIG mmcdev $MMCDEV +fw_setenv -c $FWCONFIG mmcpart $MMCPART +fw_setenv -c $FWCONFIG mmcroot $MMCROOT + +if [ $REBOOT -gt 0 ]; then + echo "Rebooting..." + reboot +fi + +exit 0 diff --git a/scripts/install-forgefirm.sh b/scripts/install-forgefirm.sh new file mode 100644 index 0000000..5e425e7 --- /dev/null +++ b/scripts/install-forgefirm.sh @@ -0,0 +1,158 @@ +#!/bin/sh +# (C) Copyright 2020 +# Scott Wiederhold, s.e.wiederhold@gmail.com +# https://community.openglow.org +# SPDX-License-Identifier: MIT +# +# This program makes a partition on the built-in eMMC flash storage on +# the factory Glowforge, and installs the latest copy of OpenGlow/ForgeFIRM. + +LIGHTRED="\033[1;31m" +RED="\033[31m" +GREEN="\033[32m" +YELLOW="\033[1;33m" +BRIGHT="\033[1;39m" +RESET="\033[0m" +ASTERISK="${LIGHTRED}✺${RESET}" + +stop_gf_services () { + echo -n -e "${ASTERISK}Stopping Glowforge services" + sv stop /sv/glowforge 2>&1 >/dev/null; echo -n "." + sv stop /sv/glowforge/log 2>&1 >/dev/null; echo -n "." + sv stop /sv/glowforge-datalogger 2>&1 >/dev/null; echo -n "." + sv stop /sv/glowforge-datalogger/log 2>&1 >/dev/null; echo -n "." + sv stop /sv/glowforge-updater 2>&1 >/dev/null; echo -n "." + sv stop /sv/glowforge-updater/log 2>&1 >/dev/null; echo -n "." + sv stop /sv/bugeggs 2>&1 >/dev/null; echo -n "." + sv stop /sv/bugeggs/log 2>&1 >/dev/null; echo "." +} + +echo +echo -e "${LIGHTRED} ✺┈┈┈┈┈┈${RESET}" +echo -e "${BRIGHT}Open${RESET}Glow ForgeFIRM Installation Tool" +echo + +if [ -d "/factory" ]; then + echo -e "${YELLOW}!! This script must be ran from the factory firmware !!${RESET}" + exit 2 +fi + +if [ -d "/ogtmp" ]; then + # We're resuming after reboot + echo -e "${BRIGHT}Starting Stage 2:${RESET}" + + echo 0 > /proc/sys/kernel/printk + stop_gf_services + + echo -n -e "${ASTERISK}Restoring /data files" + mount -o remount,rw / + rm -rf /data/etc; echo -n "." + mv /ogtmp/etc /data/; echo -n "." + mv /ogtmp/data_pipe.bin /data/; echo -n "." + mv /ogtmp/dropbear_rsa_host_key /data/; echo -n "." + rm -rf /ogtmp; echo "." + + echo -n -e "${ASTERISK}Restarting network services." + /etc/init.d/networking restart 2>&1 >/dev/null + for VAR in 1 2 3 4 5; do + sleep 2 + echo -n "." + done + echo + + echo -e "${ASTERISK}Downloading latest OpenGlow/ForgeFIRM image:" + curl -L https://github.com/ScottW514/forgefirm/releases/latest/download/forgefirm-image-glowforge.wic.gz --output /data/forgefirm-image-glowforge.wic.gz + curl -L https://raw.githubusercontent.com/ScottW514/meta-openglow/master/scripts/ffboot --output /data/ffboot + chmod +x /data/ffboot + echo + + echo -e "${ASTERISK}Writing OpenGlow/ForegFIRM image to flash:" + zcat /data/forgefirm-image-glowforge.wic.gz | dd of=/dev/mmcblk2p4 skip=2 + mkdir /data/mnt + mount /dev/mmcblk2p4 /data/mnt + sed -i 's/mmcblk1p1/mmcblk2p4/g' /data/mnt/boot/uEnv.txt + umount /data/mnt + rm -rf /data/mnt + rm -f /data/forgefirm-image-glowforge.wic.gz + + echo 5 > /proc/sys/kernel/printk + + echo -e "${BRIGHT}Stage 2 Complete!${RESET}" + echo + read -n1 -p "Press any key to reboot into OpenGlow/ForgeFIRM..." continue + /data/ffboot -e4 +else + # We're starting fresh + echo -e "${LIGHTRED}!!!!!!!!!!!!!!!! WARNING !!!!!!!!!!!!!!!!${RESET}" + echo -e "${YELLOW} THIS IS EXPERIMENTAL SOFTWARE!${RESET}" + echo -e "The installation and/or use of this software may" + echo -e "result in damage to your device and/or property," + echo -e "loss of warranty, and severe bodily injury and/or" + echo -e "death. This software is not affiliated with or" + echo -e "endorsed by Glowforge. ${BRIGHT}USE IT AT YOUR OWN RISK!${RESET}" + echo -e "${LIGHTRED}!!!!!!!!!!!!!!!! WARNING !!!!!!!!!!!!!!!!${RESET}" + echo + read -p "Are you sure you want to continue [N/y]? " continue + echo + if [ "$continue" != "y" ]; then + echo "Wise choice. Exiting without changes." + exit 0 + fi + echo -e "${BRIGHT}Starting Stage 1:${RESET}" + + echo 0 > /proc/sys/kernel/printk + stop_gf_services + + echo -n -e "${ASTERISK}Backing up critical files on /data partition" + mount -o remount,rw /; echo -n "." + mkdir /ogtmp; echo -n "." + cp -R /data/etc /ogtmp/; echo -n "." + cp /data/data_pipe.bin /ogtmp/; echo -n "." + cp /data/dropbear_rsa_host_key /ogtmp/; echo "." + + echo -e "${ASTERISK}Creating partitions (ignore fdisk warning):" + umount -l /dev/mmcblk2p3 + sed -e 's/\s*\([\+0-9a-zA-Z]*\).*/\1/' << EOF | fdisk /dev/mmcblk2 2>&1 >/dev/null + o # Removing existing partitions + n # New partition + p # Primary partition + 1 # Creating new /data partition + 129 # Start at the end of partition 2 + 6528 # 2GB /data parttion + n # New partition + p # Primary partition + 2 # Creating new /data partition + 6529 # Start at the end of partition 2 + 12928 # 2GB /data parttion + n # New partition + p # Primary partition + 3 # Creating new /data partition + 12929 # Start at the end of partition 2 + +2048M # 2GB /data parttion + n # New partition for OpenGlow + p # Primary partition (Will automatically select 4) + 75430 # Start at the end of partition 3 + # default, Use remaining space + w # write the partition table +EOF + + # We need to clear the original partition of filesystem data + # This way the Glowforge will properly recreate the /data partition + # on the next reboot. + dd if=/dev/zero of=/dev/mmcblk2p3 bs=4096 count=4096 2>&1 >/dev/null + + echo -e "${BRIGHT}Completed Stage 1${RESET}" + echo + echo -e "The device needs to reboot." + echo -e "After the device has rebooted, run this script" + echo -e "to continue the installation process." + echo + echo 5 > /proc/sys/kernel/printk + read -n1 -p "Press any key to reboot..." continue + echo + echo "Rebooting..." + reboot +fi + +echo +exit 0 diff --git a/scripts/setup-environment b/scripts/setup-environment new file mode 100644 index 0000000..7035c00 --- /dev/null +++ b/scripts/setup-environment @@ -0,0 +1,271 @@ +#!/bin/sh +# -*- mode: shell-script; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- +# +# Copyright (C) 2012, 2013, 2016 O.S. Systems Software LTDA. +# Authored-by: Otavio Salvador +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 2 as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +# +# Add options for the script +# Copyright (C) 2013 Freescale Semiconductor, Inc. + +CWD=`pwd` +PROGNAME="setup-environment" +PACKAGE_CLASSES=${PACKAGE_CLASSES:-package_rpm} + +usage() +{ + echo -e " +Usage: MACHINE= DISTRO= source $PROGNAME +Usage: source $PROGNAME + machine name + distro name + build directory + +The first usage is for creating a new build directory. In this case, the +script creates the build directory , configures it for the +specified and , and prepares the calling shell for running +bitbake on the build directory. + +The second usage is for using an existing build directory. In this case, +the script prepares the calling shell for running bitbake on the build +directory . The build directory configuration is unchanged. +" + + ls sources/meta-openglow/meta-*/conf/machine/*.conf > /dev/null 2>&1 + ls sources/forgefirm/meta-*/conf/distro/*.conf > /dev/null 2>&1 + if [ $? -eq 0 ]; then + echo -e " +Supported machines: `echo; ls sources/meta-openglow/meta-*/conf/machine/*.conf \ +| sed s/\.conf//g | sed -r 's/^.+\///' | xargs -I% echo -e "\t%"` + +Supported distros: `echo; ls sources/forgefirm/meta-*/conf/distro/*.conf \ +| sed s/\.conf//g | sed -r 's/^.+\///' | xargs -I% echo -e "\t%"` + +Examples: + +- To create a new Yocto build directory: + $ MACHINE=glowforge DISTRO=forgefirm source $PROGNAME build + +- To use an existing Yocto build directory: + $ . $PROGNAME build +" + fi +} + +clean_up() +{ + unset EULA LIST_MACHINES VALID_MACHINE + unset CWD TEMPLATES SHORTOPTS LONGOPTS ARGS PROGNAME + unset generated_config updated + unset MACHINE SDKMACHINE DISTRO OEROOT +} + +# get command line options +SHORTOPTS="h" +LONGOPTS="help" + +ARGS=$(getopt --options $SHORTOPTS \ + --longoptions $LONGOPTS --name $PROGNAME -- "$@" ) +# Print the usage menu if invalid options are specified +if [ $? != 0 -o $# -lt 1 ]; then + usage && clean_up + return 1 +fi + +eval set -- "$ARGS" +while true; +do + case $1 in + -h|--help) + usage + clean_up + return 0 + ;; + --) + shift + break + ;; + esac +done + +if [ "$(whoami)" = "root" ]; then + echo "ERROR: do not use the BSP as root. Exiting..." +fi + +if [ ! -e $1/conf/local.conf.sample ]; then + build_dir_setup_enabled="true" +else + build_dir_setup_enabled="false" +fi + +if [ "$build_dir_setup_enabled" = "true" ] && [ -z "$MACHINE" ]; then + usage + echo -e "ERROR: You must set MACHINE when creating a new build directory." + clean_up + return 1 +fi + +if [ -z "$SDKMACHINE" ]; then + SDKMACHINE='i686' +fi + +if [ "$build_dir_setup_enabled" = "true" ] && [ -z "$DISTRO" ]; then + usage + echo -e "ERROR: You must set DISTRO when creating a new build directory." + clean_up + return 1 +fi + +OEROOT=$PWD/sources/poky +if [ -e $PWD/sources/oe-core ]; then + OEROOT=$PWD/sources/oe-core +fi + +. $OEROOT/oe-init-build-env $CWD/$1 > /dev/null + +# if conf/local.conf not generated, no need to go further +if [ ! -e conf/local.conf ]; then + clean_up && return 1 +fi + +# Clean up PATH, because if it includes tokens to current directories somehow, +# wrong binaries can be used instead of the expected ones during task execution +export PATH="`echo $PATH | sed 's/\(:.\|:\)*:/:/g;s/^.\?://;s/:.\?$//'`" + +generated_config= +if [ "$build_dir_setup_enabled" = "true" ]; then + mv conf/local.conf conf/local.conf.sample + + # Generate the local.conf based on the Yocto defaults + TEMPLATES=$CWD/base/conf + grep -v '^#\|^$' conf/local.conf.sample > conf/local.conf + cat >> conf/local.conf <> conf/local.conf +elif [ -n "$EULA_ACCEPTED" ]; then + # The FSL EULA has been accepted once, so ACCEPT_FSL_EULA is set + # in local.conf. No need to do anything. + : +else + # THE FSL EULA is not set as accepted in local.conf, and EULA is + # not set in the environment, so we need to ask user if he/she + # accepts the FSL EULA: + cat <> conf/local.conf + ;; + n|N) + echo "EULA has not been accepted." + ;; + *) + REPLY= + ;; + esac + done +fi + +cat <' + +Current available targets are: + forgefirm-image (for Glowforge factory control boards) + +EOF + +if [ -n "$generated_config" ]; then + cat <