Trying to build MicroPython for FreeDOS on Ubuntu 15.10

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
berghawkins
Posts: 1
Joined: Mon Mar 28, 2016 10:03 pm

Trying to build MicroPython for FreeDOS on Ubuntu 15.10

Post by berghawkins » Tue Mar 29, 2016 9:39 pm

Hello,

I have been planning to (possibly) run Micropython under FreeDOS on a re-purposed thin client with 64MB flash, 128MB RAM and an Eden 400MHz processor for some embedded work. I am compiling with DJGPP 5.3.0 under Ubuntu 32-bit 15.10.

Problem is, I cannot get to first base!

When I clone the 2 directories found on Github and follow the instructions in "FreeDos port of micropython" I get errors. After some help from one of your contributors, I am down to this error:

Thanks for any help.
=====================================================================================================
Here is the latest output of the compiler:
.
.
.
CC main.c
CC gccollect.c
CC unix_mphal.c
CC input.c
CC file.c
CC modmachine.c
CC modos.c
CC moduselect.c
CC alloc.c
CC coverage.c
CC modtime.c
CC modtermios.c
CC moddos.c
In file included from ../py/mpstate.h:34:0,
from ../py/runtime.h:29,
from moddos.c:9:
moddos.c:169:71: error: initialization from incompatible pointer type [-Werror=incompatible-pointer-types]
static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_dos_settime_obj, 4, 4, mod_dos_settime);
^
../py/obj.h:292:76: note: in definition of macro 'MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN'
{{&mp_type_fun_builtin}, false, n_args_min, n_args_max, .fun.var = fun_name}
^
moddos.c:169:71: note: (near initialization for 'mod_dos_settime_obj.fun.var')
static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_dos_settime_obj, 4, 4, mod_dos_settime);
^
../py/obj.h:292:76: note: in definition of macro 'MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN'
{{&mp_type_fun_builtin}, false, n_args_min, n_args_max, .fun.var = fun_name}
^
cc1: all warnings being treated as errors
../py/mkrules.mk:47: recipe for target 'build-freedos/moddos.o' failed
make[1]: *** [build-freedos/moddos.o] Error 1
make[1]: Leaving directory '/home/berg/Desktop/micropython/micropython-master/unix'
Makefile:179: recipe for target 'freedos' failed
make: *** [freedos] Error 2
cws-combine.sh: line 3: ./exe2coff: cannot execute binary file: Exec format error
cat: micropython_freedos: No such file or directory
======================================================================================
And here is my makefile:

include ../py/mkenv.mk
-include mpconfigport.mk

# define main target
PROG = micropython

# qstr definitions (must come before including py.mk)
QSTR_DEFS = qstrdefsport.h

# OS name, for simple autoconfig
UNAME_S := $(shell uname -s)

# include py core make definitions
include ../py/py.mk

INC += -I.
INC += -I..
INC += -I$(BUILD)

# compiler settings
CWARN = -Wall -Werror
CWARN += -Wpointer-arith -Wuninitialized
CFLAGS = $(INC) $(CWARN) -ansi -std=gnu99 -DUNIX $(CFLAGS_MOD) $(COPT) $(CFLAGS_EXTRA)

# Debugging/Optimization
ifdef DEBUG
CFLAGS += -g
COPT = -O0
else
COPT = -Os #-DNDEBUG
endif

# On OSX, 'gcc' is a symlink to clang unless a real gcc is installed.
# The unix port of micropython on OSX must be compiled with clang,
# while cross-compile ports require gcc, so we test here for OSX and
# if necessary override the value of 'CC' set in py/mkenv.mk
ifeq ($(UNAME_S),Darwin)
CC = clang
# Use clang syntax for map file
LDFLAGS_ARCH = -Wl,-map,$@.map
else
# Use gcc syntax for map file
LDFLAGS_ARCH = -Wl,-Map=$@.map,--cref
endif
LDFLAGS = $(LDFLAGS_MOD) $(LDFLAGS_ARCH) -lm $(LDFLAGS_EXTRA)

ifeq ($(MICROPY_FORCE_32BIT),1)
# Note: you may need to install i386 versions of dependency packages,
# starting with linux-libc-dev:i386
ifeq ($(MICROPY_PY_FFI),1)
ifeq ($(UNAME_S),Linux)
CFLAGS_MOD += -I/usr/include/i686-linux-gnu
endif
endif
endif

ifeq ($(MICROPY_USE_READLINE),1)
INC += -I../lib/mp-readline
CFLAGS_MOD += -DMICROPY_USE_READLINE=1
LIB_SRC_C_EXTRA += mp-readline/readline.c
endif
ifeq ($(MICROPY_USE_READLINE),2)
CFLAGS_MOD += -DMICROPY_USE_READLINE=2
LDFLAGS_MOD += -lreadline
# the following is needed for BSD
#LDFLAGS_MOD += -ltermcap
endif
ifeq ($(MICROPY_PY_TIME),1)
CFLAGS_MOD += -DMICROPY_PY_TIME=1
SRC_MOD += modtime.c
endif
ifeq ($(MICROPY_PY_TERMIOS),1)
CFLAGS_MOD += -DMICROPY_PY_TERMIOS=1
SRC_MOD += modtermios.c
endif
ifeq ($(MICROPY_PY_SOCKET),1)
CFLAGS_MOD += -DMICROPY_PY_SOCKET=1
SRC_MOD += modsocket.c
endif

ifeq ($(MICROPY_PY_FFI),1)

ifeq ($(MICROPY_STANDALONE),1)
LIBFFI_CFLAGS_MOD := -I$(shell ls -1d ../lib/libffi/build_dir/out/lib/libffi-*/include)
ifeq ($(MICROPY_FORCE_32BIT),1)
LIBFFI_LDFLAGS_MOD = ../lib/libffi/build_dir/out/lib32/libffi.a
else
LIBFFI_LDFLAGS_MOD = ../lib/libffi/build_dir/out/lib/libffi.a
endif
else
LIBFFI_CFLAGS_MOD := $(shell pkg-config --cflags libffi)
LIBFFI_LDFLAGS_MOD := $(shell pkg-config --libs libffi)
endif

ifeq ($(UNAME_S),Linux)
LIBFFI_LDFLAGS_MOD += -ldl
endif

CFLAGS_MOD += $(LIBFFI_CFLAGS_MOD) -DMICROPY_PY_FFI=1
LDFLAGS_MOD += $(LIBFFI_LDFLAGS_MOD)
SRC_MOD += modffi.c
endif

ifeq ($(MICROPY_PY_JNI),1)
# Path for 64-bit OpenJDK, should be adjusted for other JDKs
CFLAGS_MOD += -I/usr/lib/jvm/java-7-openjdk-amd64/include -DMICROPY_PY_JNI=1
SRC_MOD += modjni.c
endif

ifeq ($(MICROPY_PY_MODDOS), 1)
SRC_MOD += moddos.c
endif

# source files
SRC_C = \
main.c \
gccollect.c \
unix_mphal.c \
input.c \
file.c \
modmachine.c \
modos.c \
moduselect.c \
alloc.c \
coverage.c \
$(SRC_MOD)

# Include builtin package manager in the standard build (and coverage)
ifeq ($(PROG),micropython)
SRC_C += $(BUILD)/_frozen_upip.c
else ifeq ($(PROG),micropython_coverage)
SRC_C += $(BUILD)/_frozen_upip.c
else ifeq ($(PROG), micropython_freedos)
SRC_C += $(BUILD)/_frozen_upip.c
endif

LIB_SRC_C = $(addprefix lib/,\
$(LIB_SRC_C_EXTRA) \
utils/printf.c \
)

OBJ = $(PY_O)
OBJ += $(addprefix $(BUILD)/, $(SRC_C:.c=.o))
OBJ += $(addprefix $(BUILD)/, $(LIB_SRC_C:.c=.o))

include ../py/mkrules.mk

.PHONY: test

test: $(PROG) ../tests/run-tests
$(eval DIRNAME=$(notdir $(CURDIR)))
cd ../tests && MICROPY_MICROPYTHON=../$(DIRNAME)/$(PROG) ./run-tests

# install micropython in /usr/local/bin
TARGET = micropython
PREFIX = $(DESTDIR)/usr/local
BINDIR = $(PREFIX)/bin
PIPSRC = ../tools/pip-micropython
PIPTARGET = pip-micropython

install: micropython
install -D $(TARGET) $(BINDIR)/$(TARGET)
install -D $(PIPSRC) $(BINDIR)/$(PIPTARGET)

# uninstall micropython
uninstall:
-rm $(BINDIR)/$(TARGET)
-rm $(BINDIR)/$(PIPTARGET)

# build synthetically fast interpreter for benchmarking
fast:
$(MAKE) COPT="-O2 -DNDEBUG -fno-crossjumping" CFLAGS_EXTRA='-DMP_CONFIGFILE="<mpconfigport_fast.h>"' BUILD=build-fast PROG=micropython_fast

# build a minimal interpreter
minimal:
$(MAKE) COPT="-Os -DNDEBUG" CFLAGS_EXTRA='-DMP_CONFIGFILE="<mpconfigport_minimal.h>"' BUILD=build-minimal PROG=micropython_minimal MICROPY_PY_TIME=0 MICROPY_PY_TERMIOS=0 MICROPY_PY_SOCKET=0 MICROPY_PY_FFI=0 MICROPY_USE_READLINE=0

freedos:
$(MAKE) \
CC=i586-pc-msdosdjgpp-gcc \
STRIP=i586-pc-msdosdjgpp-strip \
SIZE=i586-pc-msdosdjgpp-size \
CFLAGS_EXTRA='-DMP_CONFIGFILE="<mpconfigport_freedos.h>" -DMICROPY_NLR_SETJMP -Dtgamma=gamma -DMICROPY_EMIT_X86=0 -DMICROPY_NO_ALLOCA=1 -DMICROPY_PY_USELECT=0' \
BUILD=build-freedos \
PROG=micropython_freedos \
MICROPY_PY_SOCKET=0 \
MICROPY_PY_FFI=0 \
MICROPY_PY_JNI=0 \
MICROPY_PY_MODDOS=1

# build an interpreter for coverage testing and do the testing
coverage:
$(MAKE) COPT="-O0" CFLAGS_EXTRA='-fprofile-arcs -ftest-coverage -Wdouble-promotion -Wformat -Wmissing-declarations -Wmissing-prototypes -Wold-style-definition -Wpointer-arith -Wshadow -Wsign-compare -Wuninitialized -Wunused-parameter -DMICROPY_UNIX_COVERAGE' LDFLAGS_EXTRA='-fprofile-arcs -ftest-coverage' BUILD=build-coverage PROG=micropython_coverage

coverage_test: coverage
$(eval DIRNAME=$(notdir $(CURDIR)))
cd ../tests && MICROPY_MICROPYTHON=../$(DIRNAME)/micropython_coverage ./run-tests
cd ../tests && MICROPY_MICROPYTHON=../$(DIRNAME)/micropython_coverage ./run-tests --emit native
gcov -o build-coverage/py ../py/*.c
gcov -o build-coverage/extmod ../extmod/*.c

$(BUILD)/_frozen_upip.c: $(BUILD)/frozen_upip/upip.py
../tools/make-frozen.py $(dir $^) > $@

# Select latest upip version available
UPIP_TARBALL := $(shell ls -1 -v ../tools/micropython-upip-*.tar.gz | tail -n1)

$(BUILD)/frozen_upip/upip.py: $(UPIP_TARBALL)
$(ECHO) "MISC Preparing upip as frozen module"
$(Q)rm -rf $(BUILD)/micropython-upip-*
$(Q)tar -C $(BUILD) -xz -f $^
$(Q)rm -rf $(dir $@)
$(Q)mkdir -p $(dir $@)
$(Q)cp $(BUILD)/micropython-upip-*/upip*.py $(dir $@)


# Value of configure's --host= option (required for cross-compilation).
# Deduce it from CROSS_COMPILE by default, but can be overriden.
ifneq ($(CROSS_COMPILE),)
CROSS_COMPILE_HOST = --host=$(patsubst %-,%,$(CROSS_COMPILE))
else
CROSS_COMPILE_HOST =
endif

deplibs: libffi axtls

# install-exec-recursive & install-data-am targets are used to avoid building
# docs and depending on makeinfo
libffi:
cd ../lib/libffi; git clean -d -x -f
cd ../lib/libffi; ./autogen.sh
mkdir -p ../lib/libffi/build_dir; cd ../lib/libffi/build_dir; \
../configure $(CROSS_COMPILE_HOST) --prefix=$$PWD/out CC="$(CC)" CXX="$(CXX)" LD="$(LD)"; \
make install-exec-recursive; make -C include install-data-am

axtls:
cd ../lib/axtls; cp config/upyconfig config/.config
cd ../lib/axtls; make oldconfig -B
cd ../lib/axtls; make clean
cd ../lib/axtls; make all CC="$(CC)" LD="$(LD)"
========================================================================
I have made one change to the source:
In mpconfigport_freedos.h

I changed MP_QSTR_machine
to
MP_QSTR_umachine
==============================================================
And one change to build_freedos.sh:
changed 5.2.0
to 5.3.0

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: Trying to build MicroPython for FreeDOS on Ubuntu 15.10

Post by dhylands » Wed Mar 30, 2016 6:20 am

I created a freedos branch in my repository that builds:
https://github.com/dhylands/micropython/tree/freedos

The patch was fairly small:
https://github.com/dhylands/micropython ... 39d2e58d74

but not suitable for merging into master.

The unix build currently can't be built with FatFs disabled.

pohmelie
Posts: 55
Joined: Mon Nov 23, 2015 6:31 pm

Re: Trying to build MicroPython for FreeDOS on Ubuntu 15.10

Post by pohmelie » Sat Apr 02, 2016 11:59 am

berghawkins, you should not use https://github.com/pohmelie/micropython-freedos cause micropython is fast growing and lots of changes was made for last 4 months. I will update this repo later (after async/await will be aplied/rejected). Just use unix build with micropython target, as dhylands said.

dhylands, maybe create issue for this? Or should I try to create switching for makefile for those modules?

pohmelie
Posts: 55
Joined: Mon Nov 23, 2015 6:31 pm

Re: Trying to build MicroPython for FreeDOS on Ubuntu 15.10

Post by pohmelie » Sat Apr 02, 2016 1:33 pm

dhylands, what do you think about this patch?
https://github.com/pohmelie/micropython ... e9a8265c8d

pohmelie
Posts: 55
Joined: Mon Nov 23, 2015 6:31 pm

Re: Trying to build MicroPython for FreeDOS on Ubuntu 15.10

Post by pohmelie » Sat Apr 02, 2016 1:40 pm

Also, I've found that "make clean" does not remove build-freedos directory and micropython-freedos binaries. And there is not target for "clean" in makefile.

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: Trying to build MicroPython for FreeDOS on Ubuntu 15.10

Post by dhylands » Sat Apr 02, 2016 2:19 pm

pohmelie wrote:Also, I've found that "make clean" does not remove build-freedos directory and micropython-freedos binaries. And there is not target for "clean" in makefile.
The clean target is actually in py/mkrules.mk

We probably need to add some dependencies on clean so that other build directories get removed as well.

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: Trying to build MicroPython for FreeDOS on Ubuntu 15.10

Post by dhylands » Sat Apr 02, 2016 2:30 pm

pohmelie wrote:dhylands, what do you think about this patch?
https://github.com/pohmelie/micropython ... e9a8265c8d
That looks reasonable to me (on my phone)

pohmelie
Posts: 55
Joined: Mon Nov 23, 2015 6:31 pm

Re: Trying to build MicroPython for FreeDOS on Ubuntu 15.10

Post by pohmelie » Sat Apr 02, 2016 3:07 pm

dhylands wrote:That looks reasonable to me (on my phone)
Ok, I'm ended with pull right now. https://github.com/micropython/micropython/pull/1956
dhylands wrote:The clean target is actually in py/mkrules.mk

We probably need to add some dependencies on clean so that other build directories get removed as well.
Hm, I see removing of $(PROG) and $(BUILD), but unix makefile have proper values for freedos

Code: Select all

BUILD=build-freedos \
PROG=micropython_freedos \
So… don't get why this does not work as is :?

Post Reply