diff --git a/Makefile b/Makefile index 106157265478..700c200914df 100644 --- a/Makefile +++ b/Makefile @@ -21,6 +21,12 @@ STRIP=$(CROSS_PREFIX)strip CPP=cpp PYTHON=python3 +CPP_VERSION := $(shell $(CPP) --version) +ifeq ($(findstring clang,$(CPP_VERSION)),clang) +# The clang version of cpp forces a specific input directory, so directly use clang instead +CPP=clang -E +endif + # Source files src-y = dirs-y = src @@ -65,7 +71,7 @@ $(OUT)%.o: %.c $(OUT)autoconf.h $(OUT)%.ld: %.lds.S $(OUT)autoconf.h @echo " Preprocessing $@" - $(Q)$(CPP) -I$(OUT) -P -MD -MT $@ $< -o $@ + $(Q)$(CPP) -I $(OUT) -P -MD -MT $@ $< -o $@ $(OUT)klipper.elf: $(OBJS_klipper.elf) @echo " Linking $@" @@ -118,7 +124,7 @@ menuconfig: ################ Generic rules # Make definitions -.PHONY : all clean distclean olddefconfig menuconfig create-board-link FORCE +.PHONY : all clean libclean distclean olddefconfig menuconfig create-board-link FORCE .DELETE_ON_ERROR: all: $(target-y) @@ -126,6 +132,11 @@ all: $(target-y) clean: $(Q)rm -rf $(OUT) +libclean: + $(Q)make -C lib/bossac/ clean + $(Q)make -C lib/rp2040_flash/ clean + $(Q)make -C lib/hidflash/ clean + distclean: clean $(Q)rm -f .config .config.old diff --git a/lib/bossac/src/OSXPortFactory.cpp b/lib/bossac/src/OSXPortFactory.cpp new file mode 100644 index 000000000000..bde8459cba5f --- /dev/null +++ b/lib/bossac/src/OSXPortFactory.cpp @@ -0,0 +1,106 @@ +/////////////////////////////////////////////////////////////////////////////// +// BOSSA +// +// Copyright (c) 2011-2018, ShumaTech +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// * Neither the name of the nor the +// names of its contributors may be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +// DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY +// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +/////////////////////////////////////////////////////////////////////////////// +#include "OSXPortFactory.h" +#include "PosixSerialPort.h" + +#include +#include + +#include + +OSXPortFactory::OSXPortFactory() +{ + _dir = opendir("/dev"); +} + +OSXPortFactory::~OSXPortFactory() +{ + if (_dir) + closedir(_dir); +} + +SerialPort::Ptr +OSXPortFactory::create(const std::string& name) +{ + bool isUsb = false; + + if (name.find("usb") != std::string::npos) + isUsb = true; + + return create(name, isUsb); +} + +SerialPort::Ptr +OSXPortFactory::create(const std::string& name, bool isUsb) +{ + PosixSerialPort *p = new PosixSerialPort(name, isUsb); + // Needed to avoid upload errors + p->setAutoFlush(true); + return SerialPort::Ptr(p); +} + +std::string +OSXPortFactory::begin() +{ + if (!_dir) + return end(); + + rewinddir(_dir); + + return next(); +} + +std::string +OSXPortFactory::next() +{ + struct dirent* entry; + + if (!_dir) + return end(); + + while ((entry = readdir(_dir))) + { + if (strncmp("cu.", entry->d_name, sizeof("cu.") - 1) == 0) + return std::string(entry->d_name); + } + + return end(); +} + +std::string +OSXPortFactory::end() +{ + return std::string(); +} + +std::string +OSXPortFactory::def() +{ + return begin(); +} diff --git a/lib/bossac/src/OSXPortFactory.h b/lib/bossac/src/OSXPortFactory.h new file mode 100644 index 000000000000..52b3bfdbcbfb --- /dev/null +++ b/lib/bossac/src/OSXPortFactory.h @@ -0,0 +1,60 @@ +/////////////////////////////////////////////////////////////////////////////// +// BOSSA +// +// Copyright (c) 2011-2018, ShumaTech +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// * Neither the name of the nor the +// names of its contributors may be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +// DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY +// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +/////////////////////////////////////////////////////////////////////////////// +#ifndef _OSXPORTFACTORY_H +#define _OSXPORTFACTORY_H + +class OSXPortFactory; +#include "PortFactory.h" + +#include +#include + +#include + + +class OSXPortFactory : public PortFactoryBase +{ +public: + OSXPortFactory(); + virtual ~OSXPortFactory(); + + virtual std::string begin(); + virtual std::string end(); + virtual std::string next(); + virtual std::string def(); + + virtual SerialPort::Ptr create(const std::string& name); + virtual SerialPort::Ptr create(const std::string& name, bool isUsb); + +private: + std::string _empty; + DIR* _dir; +}; + +#endif // _OSXPORTFACTORY_H \ No newline at end of file diff --git a/scripts/dev-install-macos.sh b/scripts/dev-install-macos.sh new file mode 100644 index 000000000000..5db8a3d9966f --- /dev/null +++ b/scripts/dev-install-macos.sh @@ -0,0 +1,47 @@ +#!/bin/bash +# This script installs the necessary build tools for the MCU code on MacOS +# Unlike other install scripts, it does not install the klippy host + +# Step 1: Install system packages +install_packages() +{ + PKGLIST="" + TAPLIST="osx-cross/homebrew-avr osx-cross/homebrew-arm" + # AVR chip installation and building + PKGLIST="${PKGLIST} avrdude avr-gcc" + # ARM chip installation and building + PKGLIST="${PKGLIST} stm32flash wxwidgets arm-gcc-bin" + + # Tap necessary package repos + report_status "Tapping formula repositories..." + for TAP in $TAPLIST + do + brew tap $TAP + done + brew update + + # Install desired packages + report_status "Installing packages..." + brew install ${PKGLIST} +} + +# Helper functions +report_status() +{ + echo -e "\n\n###### $1" +} + +verify_ready() +{ + if [ "$EUID" -eq 0 ]; then + echo "This script must not run as root" + exit -1 + fi +} + +# Force script to exit if an error occurs +set -e + +# Run installation steps defined above +verify_ready +install_packages diff --git a/scripts/flash_usb.py b/scripts/flash_usb.py index e43c457c5cff..ee233653b284 100755 --- a/scripts/flash_usb.py +++ b/scripts/flash_usb.py @@ -28,6 +28,13 @@ def enter_bootloader(device): def translate_serial_to_tty(device): ttyname = os.path.realpath(device) if not os.path.exists('/dev/serial/by-path/'): + if os.path.basename(ttyname).startswith("tty."): + fname = (os.path.dirname(ttyname) + "/cu." + + os.path.basename(ttyname).split(".", 1)[1]) + if os.path.exists(fname): + return ttyname, fname + elif os.path.basename(ttyname).startswith("cu."): + return ttyname, ttyname raise error("Unable to find serial 'by-path' folder") for fname in os.listdir('/dev/serial/by-path/'): fname = '/dev/serial/by-path/' + fname