Skip to content

Commit

Permalink
Merge pull request #317 from mithro/upy
Browse files Browse the repository at this point in the history
Adding support for building MicroPython inside tree
  • Loading branch information
mithro committed Mar 31, 2017
2 parents 65c7dd3 + cdb3e4c commit e4d5f3d
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -7,3 +7,4 @@ build
*~
*.png
third_party/qemu-litex
third_party/micropython
4 changes: 2 additions & 2 deletions firmware/fx2.c
Expand Up @@ -127,9 +127,9 @@ void fx2_reboot(enum fx2_fw_version fw)

void fx2_debug(void) {
wprintf("Possible FX2 Firmware:\r\n");
wprintf(" [%s] usbjtag (%02X) (IXO USB JTAG Mode)\r\n", fx2_fw_active == FX2FW_USBJTAG ? "*" : " ", FX2_MBFW_USBJTAG_END);
wprintf(" [%s] usbjtag (%02X) (IXO USB JTAG Mode)\r\n", fx2_fw_active == FX2FW_USBJTAG ? "*" : " ", (unsigned int)FX2_MBFW_USBJTAG_END);
#ifdef ENCODER_BASE
wprintf(" [%s] hdmi2usb (%02X) (HDMI2USB Video Capture Mode)\r\n", fx2_fw_active == FX2FW_HDMI2USB ? "*" : " ", FX2_MBFW_HDMI2USB_END);
wprintf(" [%s] hdmi2usb (%02X) (HDMI2USB Video Capture Mode)\r\n", fx2_fw_active == FX2FW_HDMI2USB ? "*" : " ", (unsigned int)FX2_MBFW_HDMI2USB_END);
#endif
}

Expand Down
81 changes: 81 additions & 0 deletions scripts/build-micropython.sh
@@ -0,0 +1,81 @@
#!/bin/bash

if [ "`whoami`" = "root" ]
then
echo "Running the script as root is not permitted"
exit 1
fi

CALLED=$_
[[ "${BASH_SOURCE[0]}" != "${0}" ]] && SOURCED=1 || SOURCED=0

SCRIPT_SRC=$(realpath ${BASH_SOURCE[0]})
SCRIPT_DIR=$(dirname $SCRIPT_SRC)
TOP_DIR=$(realpath $SCRIPT_DIR/..)

if [ $SOURCED = 1 ]; then
echo "You must run this script, rather then try to source it."
echo "$SCRIPT_SRC"
return
fi

if [ -z "$PLATFORM" ]; then
echo "Please set PLATFORM"
exit 1
fi
if [ -z "$TARGET" ]; then
echo "Please set TARGET"
exit 1
fi
if [ -z "$CPU" ]; then
echo "Please set CPU"
exit 1
fi

set -x
set -e

# Install a toolchain with the newlib standard library
if ! $CPU-elf-newlib-gcc --version > /dev/null 2>&1; then
conda install gcc-$CPU-elf-newlib
fi

# Get micropython is needed
MPY_SRC_DIR=$TOP_DIR/third_party/micropython
if [ ! -d "$MPY_SRC_DIR" ]; then
(
cd $(dirname $MPY_SRC_DIR)
git clone https://github.com/upy-fpga/micropython.git
cd $MPY_SRC_DIR
git submodule update --init
)
fi

# Generate the bios and local firmware
TARGET_BUILD_DIR=$(realpath build)/${PLATFORM}_${TARGET}_${CPU}/
if [ ! -d $TARGET_BUILD_DIR/software/include/generated ]; then
make firmware
fi

# Setup the micropython build directory
TARGET_MPY_BUILD_DIR=$TARGET_BUILD_DIR/software/micropython
if [ ! -e "$TARGET_MPY_BUILD_DIR/generated" ]; then
mkdir -p $TARGET_MPY_BUILD_DIR
(
cd $TARGET_MPY_BUILD_DIR
ln -s $(realpath $PWD/../../software/include/generated) $TARGET_MPY_BUILD_DIR/generated
)
fi

# Build micropython
OLD_DIR=$PWD
cd $TARGET_MPY_BUILD_DIR
export CROSS_COMPILE=$CPU-elf-newlib-
export BUILDINC_DIRECTORY=$TARGET_BUILD_DIR/software/include
export BUILD=$TARGET_MPY_BUILD_DIR
make -C ../../../../third_party/micropython/litex/
cd $OLD_DIR

# Generate a firmware image suitable for flashing.
python -m litex.soc.tools.mkmscimg -f $TARGET_MPY_BUILD_DIR/firmware.bin -o $TARGET_MPY_BUILD_DIR/firmware.fbi
/usr/bin/env python mkimage.py --output-file=$TARGET_BUILD_DIR/micropython.bin --override-firmware=$TARGET_MPY_BUILD_DIR/firmware.fbi
4 changes: 2 additions & 2 deletions scripts/download-env.sh
Expand Up @@ -202,9 +202,9 @@ check_exists flterm
)
check_version ${CPU}-elf-ld $BINUTILS_VERSION

# gcc+binutils for the target
# gcc for the target
(
conda install gcc-${CPU}-elf=$GCC_VERSION
conda install gcc-${CPU}-elf-nostdc=$GCC_VERSION
)
check_version ${CPU}-elf-gcc $GCC_VERSION

Expand Down
4 changes: 2 additions & 2 deletions scripts/settings.sh
Expand Up @@ -14,8 +14,8 @@ HDMI2USB_MODESWITCH_VERSION=0.0.0
HEXFILE_VERSION=0.1

# Conda package versions
BINUTILS_VERSION=2.26
GCC_VERSION=4.9.3
BINUTILS_VERSION=2.28
GCC_VERSION=5.4.0
SDCC_VERSION=3.5.0
OPENOCD_VERSION=0.10.0-dev

Expand Down

0 comments on commit e4d5f3d

Please sign in to comment.