Discussing the nuts and bolts of software development

Wednesday, July 30, 2008

 

Snake On A Phone

For a few years now, my main task at work has been working on the firmware of an IP phone. The phone runs VxWorks on a MIPS32 CPU; the firmware is written in C and C++.

For slightly less time, I've been dabbling in python on my own time. Freedom from explicit typing was a refreshing change, and python's tendency to Just Work was a nice bonus.

It was perhaps inevitable that I would one day try to combine phone and language. (why? because they were both there)

It wasn't obvious that the idea stood a chance. VxWorks is a bit off the OS beaten track, and might not provide all the functionality needed by Python's "core" (not with the same names, anyway). There might be some processor-specific pieces that would rule out MIPS32. And even if I could get something built, would it fit in the 2 or 3 MB of RAM (and even less flash) I could spare?

As it turns out, there was very little to worry about. Python's code is impressively (if perhaps unsurprisingly) portable, only needing a couple of tweaks to its build system and none at all to its source code. There doesn't seem to be anything CPU-dependant; and in the end, adding python to my firmware only cost me 1MB. It took me only a few evenings of tinkering to get a libpython built, linked into my firmware, and loaded on my phone, to the point that I could run this little experiment at the VxWorks shell:


-> Py_Initialize()
value = 42 = 0x2a = '*'
-> PyRun_SimpleString("print 'Hello, World!'\n")
Hello, World!
value = 0 = 0x0


(the VxWorks shell being a peculiar animal that allows calling C functions by name, in this case giving me access to Python's C Extension API for a near-REPL experience)


For my purposes, that's enough; I know it can work, and that's all I wanted. I don't expect to ever go further than this. But as little as it is, publishing how I got there might help someone get started on a real project; so here goes:

Porting python in 10 easy* steps



*for a suitable definition of easy


  1. As far as embedding Python in an existing application (or firmware) is concerned, Python's own documentation should give you most of what you need
  2. You'll need a cross-compiling toolchain, i.e. a compiler that can be used on one platform (e.g. x86) and produces executables for use on a different platform (e.g. MIPS32). GCC is your best bet; it's what will make python's build system happiest, and there's lots of resources on getting a GCC cross-compiler working on the web, though it looks a bit daunting to me. I was fortunate in that, since I was already set up to build firmwares, I already had all the needed tools; I would guess that most people engaging on a similar project would be in the same position.

  3. In addition to the compiler (and assembler, linker, etc), you'll want to have a Unix-like environment to run Python's configure script and makefiles. If you're on Windows, cygwin will serve nicely.

  4. The 'configure' script needs some tweaking: it contains a few uses of AC_TRY_RUN, which will fail when cross-compiling.
    • If you have a working 'autoconf', the simplest is to edit the 'configure.in' file. You can either remove the AC_TRY_RUN tests altogether or replace them by the newer, more cross-compiler-friendly AC_RUN_IFELSE. Then run 'autoconf' to regenerate the 'configure' script.
    • If you don't (as I didn't), you can brace yourself and go edit the 'configure' script directly. Running the script produces error messages that gives something to search for. The fix is actually simple: just remove the calls to 'exit' to allow the error to get ignored.


  5. The makefile also needs tweaking: just like 'configure', at some point it tries to compile and run a program. This appears to be in order to autogenerate some source files, which fortunately are already provided in the source distribution; so it's safe to disable this step. The simplest way:
    • open "Makefile.pre.in"
    • find the place where "$(PGEN)" shows up AFTER a ':'
    • remove "$(PGEN)"

    (this will only prevent the executable from getting built. The makefile will still attempt to run it, but it's written so that the resulting failure is ignored)

  6. The configure script and makefile try to guess at the name of tools to use; you can give them a hint with environment variables. In my case I needed to set CC (the C Compiler) and AR (the "archiver", ie. what creates static libraries)

  7. If you need to specify special command-line options to the compiler, environment variables can also be used. Annoyingly, 'configure' and the makefiles use different variable; you'll want to set CFLAGS and BASECFLAGS to the same thing.

  8. Finally you'll be ready to run the 'configure' script. You need to give it the special options --build and --host to tell it you're cross-compiling, something like:

    $ ./configure --build=win32 --host=vxworks


    (win32 and vxworks were a wild guess that happened to work for me. I got the impression the specific values didn't particularly matter)

  9. You can then run 'make' to compile everything. If, like me, all you need is a static library, this will do it:

    $ make libpython2.5.a


  10. There's a good chance some files under Modules/ will fail to compile (in my case, posixmodule.c). The file Module/Setup specifies (in a rather well-documented way) which Python modules (written in C) should be built into the python library; comment out the failing one, and re-run 'make'. I only had to disable posixmodule and pwdmodule; YMMV.


And for me, that was it; nothing else needed manual intervention. If you run into more troubles (e.g. trying to build the actual python.exe), I'm afraid you're on your own.

My next step was to figure out how to integrate the python library into my firmware; you'll have to figure out the corresponding steps for your own firmware/embedded application/whatever. Start with the 'embedding' link for how to access python code from your code.

If you want to be able to load python source files with 'import', pay particular attention to what that page says about PYTHONHOME; as for me, I put a putenv(PYHONHOME=/whatever") before the Py_Initialize call, letting me import /whatever/python2.5/*.py files (and possibly, though I haven't tried, .py files contained in a /whatever/python2.5/libpython2.5.zip)

Happy cross-compiling!

Labels: , , ,


Comments:
dongtam
mu private
tim phong tro
http://nhatroso.com/
nhac san cuc manh
tổng đài tư vấn luật
http://dichvu.tuvanphapluattructuyen.com/
văn phòng luật
tổng đài tư vấn luật
dịch vụ thành lập công ty
http://we-cooking.com/
chém gió
trung tâm ngoại ngữ.

- Hừ.

Hoàng Vũ hừ lạnh một tiếng, thân thể sau đó lui lại rồi nói:

- Các ngươi cẩn thận.

- Xoẹt xoẹt.

Ba đạo thân ảnh chuyển động, ngay sau đó bốn thanh niên hán tử đánh về phía bốn người của Thần Hoàng Tộc, cường hãn công kích của bọn họ ngưng tụ.

- Ầm ầm.

Một luồng khí tức nổ ra, quang mang công kích chạm vào nhHoàng Quang, ngươi đi đối phó với hai nữ nhân kia trước đi.

Nhất tinh Đấu Thánh vừa bị Hoàng Vũ đánh liền cười nói.

- Xoẹt.

Lão nhân kia không hề do dự mà đánh về phía Thượng Quan Uyển Nhi và

 
Hey! You should check this out to find the best tips for a young writers!
 
Thank You SO Much For This Lovely Post. By The Way You Can Check Out Quickbooks Support If You face Any Problem Regarding Quickbooks Software or Application.

 
Snake on a phone is the game played by most of the people around 8-10 years back. It was created on Java for Symbian phones. Whereas, it was also developed by the game developers in python for smartphone users. It was fun playing that game. My son still plays that game on my phone when I get busy in my essay help online.
 
The information above is good here is viewmypaycheck for all the tax related query to check your tax slab just visit the link viewmypaycheck
 
Try to create a paper about something that you are aware of. Thus, you will not encounter any serious difficulties during the writing process. Do not pick any complex subjects and
buy 3000 word essay.
 
Its a great pleasure reading your post.Its full of information I am looking for and I love to post a comment that "The content of your post is awesome" Great work.
Renegade Racing For PC
 
Quickbooks is one of the advanced accounting software that offers multiple accounting features to manage your business data conveniently. This software allows users to create a backup file and restore the data. With quickbooks data transfer, you can easily and quickly send the data from one pc to another.
 
QuickBooks tool applications is one of the best application that can be used in removal of errors from Quickbooks. It can remove most of the error that might occur in Quickbooks very easily and with minimum time.
 
Quickbooks update improve the performance of the software .
Also,make it more productive and fix the common and complicated errors automatically.
You must update Quickbooks version whenever a new feature is released.
for more information on Quickbooks update visit our site
https://updateerror.co/update-quickbooks/

 
Quickbooks Error Support solves all Quickbooks errors related problems, so if you are facing any problems relating to QB errors, head to QB errors for technical assistance.

 

Thank you so much for sharing all this wonderful information !!!! It is so appreciated!! You have good humor in your blogs. So much helpful and easy to read!
Python training in Pune

 
Thanks for sharing this with your audience and Python geeks, Visit us for Python Training in Pune
 
This blog is what I was looking for. This piece of content will really help me. Thanks for sharing it.polymer door Suppliers
 
When you access your QuickBooks company files or the database connection verification fails, the quickbooks error 6129 is likely to appear on your screen. As a result, you are unable to access your company's files in QuickBooks. Furthermore, the network that your QuickBooks is using will be unable to locate the server or your device that stores the file.
 
You can contact us at Write an Essay For Me in any part of the world as we deliver to native and non-native speakers of English language alike.
 
Quickbooks error 15106 is the most common symptom of this issue. With its numerous significant and beneficial features, this software has never failed to astound its users. However, QB tool has various limitations and restrictions, one of which being QB error 15106. There is no such thing as an unsolvable problem with QuickBooks, and Error 15106 is one of them.
 
Quickbooks is accounting software. Generally, QuickBooks Error 15227 appears if your computer is unstable or essential files do not respond to your commands or go missing.
 
QuickBooks is often regarded as error-free software, but there are a few glitches that can cause problems for users. QuickBooks database server manager network diagnostics error can appear on the computer screen when upgrading and running QuickBooks in multi-user mode. When accessing the company register, users can experience errors such as Error H202 and other network connection errors. If you’ve made a similar error, don’t worry; we’ve got you covered with this post. The user can find it difficult to deal with QBDBSM network diagnostics errors.
 
A debt of gratitude is in information for Sharing data this data is extremely useful and helpful for me and different people. I like your work.


 
This article is an appealing wealth of useful informative that is interesting and well-written. I commend your hard work on this and thank you for this information.

This article is an appealing wealth of useful informative that is interesting and well-written. I commend your hard work on this and thank you for this information.
 
Fast-growing consumer demand driven by the advent of digital solutions led to the replacement of critical machines with technology-driven smart solutions. Now, the US as well as the world is witnessing the next stage of such intelligent solutions in the form of Automation!

More than a trend, Automation has become a need of the hour for many firms across the global countries including the US.

Many firms are looking at it as a critical driver of trending technology solutions they deploy on board.

One such technology trend that gave due attention to Automation is DevOps, which eventually became popular as ‘DevOps Automation’.
 
Are you looking for Mobile app development company. Appcul will be the best choice for you. Here we provide different type of technology service in mobile and web applications. Also our budget range is that you can easily afford.

 
This comment has been removed by the author.
 
The information is pretty good and impressed me a lot. This article is quite in-depth and gives a good overview of the topic. The Windows stop code Windows stop code is a kernel error code generated when the program attempts to access invalid memory locations. It is not an operating system error and does not indicate a serious defect in the operating system itself. Instead, it can be caused by bugs in the software application or drivers that cause the application to misbehave.
 
The information is pretty good and impressed me a lot. This article is quite in-depth and gives a good overview of the topic.Windows blue screen of death bsod is a message displayed on an error screen when an application, either in the foreground or background, encounters an uncorrectable hardware or software error.
 
The information is pretty good and impressed me a lot. This article is quite in-depth and gives a good overview of the topic. The DLL file is a dynamic link library, which extends the capabilities of an application by providing additional methods and functions that can be called from DLL files. DLL files include support functions for system calls and API calls, as well as interface definitions for external modules.


 
The information is pretty good and impressed me a lot. This article is quite in-depth and gives a good overview of the topic.This is a great ssd card to use with your computer. It has a fast read speed and writes speed, which helps it perform well on your computer

 
This is a comparison between the Samsung 970 EVO PLUS and the Samsung 980 PRO. We will compare both devices by their display, storage and overall performance. Please let us know what you think in the comments section below or on social media!

 
Intel X570 chipset is a new Intel chipset with the best performance, features, added security and expandability for AI and automotive applications.

 
The Blue Screen of Death (BSOD) pops up when Windows encounters a critical error. When it comes toBSODs, we've got some facts and opinions that'll help get you through it and back on your feet again.

 
For the most reliable system performance, this SSD card SSD card is your best choice. Pleasing to look, convenient to use and reliable in performance, it gives you what you want from your PC!

 
For the most reliable system performance, this SSD card is your best choice. Pleasing to look at, convenient to use, and reliable in performance, it gives you what you want from your PC!

 
Your DLL file is one of the two types of files that are used in Apple computers. The other type is a Dynamic Link Library or DLL. Each DLL file contains definitions for functions or procedures which can be called at runtime. An executable Program can only use DLL files that have been loaded into memory by the operating system prior to being started.

 
In the range of high-end boards, the X570 chipset is designed for highest performance in gaming and content creation, with a focus on connectivity and expansion with multiple PCI-e 3.0 lanes

 
The information is pretty good and impressed me a lot. This article is quite in-depth and gives a good overview of the topic STOP Codes are codes specific to the Intel 286 and 386 processors that tell you what problems your PC is having. If you see one of these codes on your screen, write down the message shown to you by Windows. Most of these messages contain a name for the problem.
 
The information is pretty good and impressed me a lot. This article is quite in-depth and gives a good overview of the topic. Computer blue screen of death ( BSOD) is a graphical error message displayed on the personal computers when an unrecoverable system error occurs. Also referred to as STOP message or system crash, the error message appears as a STOP code along with a hexadecimal number that describes the cause of the crash. The acronym "BSOD," which stands for "Blue Screen Of Death," is used commonly amongst computer professionals.

 
The information is pretty good and impressed me a lot. This article is quite in-depth and gives a good overview of the topic. A fast, reliable and highly versatile storage solution for your mobile devices. The Samsung SSD cards provide high capacity, extreme portability and enhanced durability to both consumers and professionals alike.

 
The information is pretty good and impressed me a lot. This article is quite in-depth and gives a good overview of the topic. samsung 970 Evo Plus provides high performance and reliability in cost effective design. Based on the fourth generation of V-NAND flash memory, it delivers ultra-fast sequential read speed of up to 3200 MB/s and sequential write speeds at up to 2700 MB/s.

 
This comment has been removed by the author.
 
The information is pretty good and impressed me a lot. This article is quite in-depth and gives a good overview of the topic. How to Watch Parasite on Netflix? No Problem. For those who don’t know, the content will be checked by our VPN software before you see it. You won’t see any restrictions when connecting with VPNS. With VPNS and Netflix, you won’t have any problems streaming quality videos.

 
The information is pretty good and impressed me a lot. This article is quite in-depth and gives a good overview of the topic.Top Sites To Watch Free Movies & TV Shows: You can watch all kinds of free movies, features and documentary shows on these websites.

 
The information is pretty good and impressed me a lot. This article is quite in-depth and gives a good overview of the topic. It’s true that security has advanced even more in the past years, but new threats keep emerging on the market. From viruses and malware to cyber-attacks and data theft, these cyber security software are designed to protect your company against cyber threats.

 
The information is pretty good and impressed me a lot. This article is quite in-depth and gives a good overview of the topic. In the search for a way to lose weight, which is better: a bike or treadmill? Researchers looked at both exercise programs and decided that the small difference between the two forms of exercise didn't merit taking the effort and money out of finding a way to exercise.

 
The information is pretty good and impressed me a lot. This article is quite in-depth and gives a good overview of the topic. Road bikes are fun to ride, and good road bike start at under $1000. They get a lot of undeserved flack for being too heavy, but you can find lightweight models that are still durable and will last a long time. If you’re looking for your first road bike or upgrading from the old clunker in the garage, a good road bike under $1000 will serve you well for years to come.

 
The information is pretty good and impressed me a lot. This article is quite in-depth and gives a good overview of the topic. The full suspension mountain bike is an amazing piece of equipment. This bike model can give you the experience of riding a normal bicycle. However, with more stiffness, the bike will have a more snappy feeling when pedaling making the ride easier on your knees and elbows.
 
The information is pretty good and impressed me a lot. This article is quite in-depth and gives a good overview of the topic. All the great advantages of a stationary bike and none of the monotony. You will be able to vary both resistance and speed to find the most effective workout. This bike provides you with a complete fitness experience all year round, even if you live in a small apartment or are unable to maintain a gym membership.
 
The information is pretty good and impressed me a lot. This article is quite in-depth and gives a good overview of the topic. Inmotion V5 Electric Unicycle is one of the most popular unicycles in Amazon, with high quality and amazing features! Unicycle riding has become more and more popular over the past few years, but many people wanted to do it but the recoil of their shoulder was hard to control. Inmotion V5 solves that problem by removing the chain of your bicycle and replacing it with an electric current driven pedal system on a specially developed drive unit resting comfortably in between your feet.
 
Your post highlighted the benefits of using online dating apps and websites to find potential partners. I agree that they can be a great way to connect with like-minded individuals. Also check bicupid

 
I found your discussion on the different types of dating sites and apps to be very insightful. It's important to choose a platform that aligns with your values and dating goals. Also read


 
I really love reading posts on your blog if you want to know about betting apps you can check my website too you will find the latest and updated content there.

Visit:best betting apps
betting app
 
About ek mukhi rudraksha, you can check here-
click here
click here
click here
click here
click here
 
Suppose you are planning for distance education and you want to know about the Dr. Br Ambedkar distance education MBA fees. so you can directly connect with the admission procedure team. You will get the details from them easily
 
Thanks for this valuable information. I write blogs on aviator games. If you are interested in aviator games then you must check here.
 
With our modern transparent aligners—the unique approach to teeth straightening—discover the orthodontics of the future. The inconvenience of traditional braces can be avoided with these discrete and pleasant invisible braces, which provide a flawless smile. With our cutting edge clear aligner technology, which is intended to provide efficient and nearly invisible teeth straightening, you can enjoy the confidence that comes with having a beautifully aligned smile.
 
Post a Comment



<< Home

This page is powered by Blogger. Isn't yours?