Building device drivers for an embedded python VM

Cesar Lopez clopez at
Tue Mar 7 18:37:07 CET 2000

    Hi, I'm working in Building device drivers for an embedded python VM
as my final project of my Computers Science career. I´m working with an
SH-1 Hitachi Evaluation Board, and with an embedded python VM library,
that other guy recompile to run pythons programs in it.

    I´m  building a method that allows pythons programs access to the
devices tha we have connected in our embedded system. First a want
design a little driver that allow us light on/off a green led that it is
connected to our system. I have build the driver in C, I tested it and
works properly. Then I have build an external module for my python VM,
that I have installed in a Linux machine. This led-module call to my
modify C driver and only print on/off when I call led.Setup(1) or
    To build the interface between C/Python I have used SWIG to generate
the wrap file.
To compile this ledmodule as static I have use I´ve
built a develop directory, I´ve copied this file in it,
I´ ve created a Setup file and I´ve insert led.c, led_wrap.c and led.h
source code, too.



led led.c led_wrap.c

    With my Linux machine all works properly, but when I try to build
the same using the embedded python version I´ve some problems compiling.

Here is the code of my led driver.


        int Setup(int state); // state = 1 --> ON ; state = 0 --> OFF
int _state;
// Defining communication with the device, Port, Adress, configuration
registers and so  on ...
#define PBIOR (*(volatile short int *) (0x5ffffc6))
#define PBCR1 (*(volatile short int *) (0x5ffffcc))
#define PBCR2 (*(volatile short int *) (0x5ffffce))
#define PBDR (*(volatile short int *) (0x5ffffc2))

#include "led.h"

Setup(int state)
PBIOR |= 0x8000;      // Set the bit for output
PBCR1 &= ~0xc000;     // Make it a normal I/0

        switch (state){
            case 1:{
              PBDR |= 0x8000; // Set the LED on
            //    printf("on\n");
                _state=1; // to read the state of the led
                return 0;
            case 0:{
              PBDR &= 0x0000; // Set the LED off
            //    printf("off\n");
                return 0;
            default: return 1;  // Error: Invalid code
            } //switch

To generate the wrap file I use swig: swig -python led.i

%module led
#include "led.h"
extern int Setup(int state);
extern int _state;

Do you know if I need include in led.i the port device defines that I´ve
included in led.h?, How can I do it?

After I have get the led_wrap.c file, I want to build a new embedded
python library that runs in my embedded system with the led device
driver include in it. So that I do the same like I did with my python
Linux VM. I have built a develop directory, I´ve copy the same files.
And I run:

make -f Makefile VERSION=1.5

In /home/cesar/Python-1.5.1-raul  I´ve a copy of the embedded python
source and develope code that Raul Parra develop.

This make command gen some files like: sedscript, Makefile.pre, Makefile
and config.c ....

I modify the Makefile to use the sh-hms-gcc compiler and sh-hms-ranlib.
I deleted some libraries references like -lsocket -lieee -ldl ......
  Finally to try to get the static link I run "make python"  and then
the first time I got an error similar like this: "python.o unrecogniced
type code"  to solve it I have recompile /Modules/python.c  with
sh-hms-gcc and install int in (prefix)/lib/python1.5/config

But Now when I run "make python" again I get this error

bash-2.02$ make python
sh-hms-gcc     \
config.o lib.a
/home/cesar/Python-1.5.1-raul/lib/python1.5/config/libpython1.5.a \
              -lm -lgcc \
         -o python
undefined reference to `Py_Main'
config.o(.data+0xc):config.c: undefined reference to `initregex'
config.o(.data+0x14):config.c: undefined reference to `initpcre'
config.o(.data+0x1c):config.c: undefined reference to `initposix'
config.o(.data+0x24):config.c: undefined reference to `initsignal'
config.o(.data+0x2c):config.c: undefined reference to `initarray'
config.o(.data+0x34):config.c: undefined reference to `initcmath'
config.o(.data+0x3c):config.c: undefined reference to `initmath'
config.o(.data+0x44):config.c: undefined reference to `initstrop'
config.o(.data+0x4c):config.c: undefined reference to `initstruct'
config.o(.data+0x54):config.c: undefined reference to `inittime'
config.o(.data+0x5c):config.c: undefined reference to `initoperator'
config.o(.data+0x64):config.c: undefined reference to `initfcntl'
config.o(.data+0x6c):config.c: undefined reference to `initpwd'
config.o(.data+0x74):config.c: undefined reference to `initgrp'
config.o(.data+0x7c):config.c: undefined reference to `initselect'
config.o(.data+0x84):config.c: undefined reference to `initsocket'
config.o(.data+0x8c):config.c: undefined reference to `initerrno'
config.o(.data+0x94):config.c: undefined reference to `initmd5'
config.o(.data+0x9c):config.c: undefined reference to `initrotor'
config.o(.data+0xa4):config.c: undefined reference to `initbinascii'
config.o(.data+0xac):config.c: undefined reference to `initparser'
config.o(.data+0xb4):config.c: undefined reference to `initcStringIO'
config.o(.data+0xbc):config.c: undefined reference to `initcPickle'
make: *** [python] Error 1

So if someone of you are working in somethin similar, or now how to
compile corectly a new version of python for other architecture, when
you have a previous installed one. Please help me!!

Best Regards.

    Cesar Lopez Saenz.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the Python-list mailing list