Building device drivers for an embedded python VM

Cesar Lopez clopez at abo.fi
Tue Mar 7 12:37:07 EST 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
led.Setup(0).
    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 Makefile.pre.in. I´ve
built a develop directory, I´ve copied this Makefile.pre.in file in it,
I´ ve created a Setup file and I´ve insert led.c, led_wrap.c and led.h
source code, too.

//Setup

*static*

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.

//led.h

        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))

//led.c
#include "led.h"

int
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");
                _state=0;
                return 0;
                }
            default: return 1;  // Error: Invalid code
            } //switch
}

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

//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.pre.in Makefile VERSION=1.5
installdir=/home/cesar/Python-1.5.1-raul

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     \
         /home/cesar/Python-1.5.1-raul/lib/python1.5/config/python.o
config.o lib.a
/home/cesar/Python-1.5.1-raul/lib/python1.5/config/libpython1.5.a \
              -lm -lgcc \
         -o python
/home/cesar/Python-1.5.1-raul/lib/python1.5/config/python.o(.text+0x28):python.c:
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: <http://mail.python.org/pipermail/python-list/attachments/20000307/fdacfee0/attachment.html>


More information about the Python-list mailing list