Skip to main content

Sugar, the XO laptop, and One Laptop per Child

Virtualizing, using, and developing for Sugar

M. Tim Jones, Consultant Engineer, Emulex
M. Tim Jones
M. Tim Jones is an embedded software engineer and the author of GNU/Linux Application Programming, AI Application Programming (now in its second edition), and BSD Sockets Programming from a Multilanguage Perspective. His engineering background ranges from the development of kernels for geosynchronous spacecraft to embedded systems architecture and networking protocols development. Tim is a Consultant Engineer for Emulex Corp. in Longmont, Colorado.

Summary:  One Laptop per Child (OLPC) is an organization whose mission is to develop a low-cost laptop (USD100) with accompanying software to spread computer literacy to children around the world. Because the device targets children, it must provide a novel user interface and applications that allow children to experiment with tools for expression and learning. The operating system for the OLPC is a port of the Linux® kernel but with a unique interface called Sugar. In this article, learn about the Sugar human interface, see how to virtualize an OLPC laptop on a standard PC using QEMU, and take a tour of Sugar and the OLPC capabilities.

Date:  24 Apr 2007
Level:  Intermediate
Activity:  6760 views

A short introduction to OLPC

The OLPC initiative is a spinoff of the Massachusetts Institute of Technology Media Lab whose goal is to help educate underprivileged children around the world. The design of the laptop, as you'll soon see, is developed with this purpose clearly in mind.

Listen to our interview with OLPC visionary, Walter Bender

In this 20-minute podcast, the OLPC President of Software and Content lead, Walter Bender, chats about the initiative to get connected laptops into the hands of the children of developing nations. Hear the vision, challenges faced, and progress to date.

The OLPC was founded by Nicholas Negroponte. Because the OLPC uses GNU/Linux as its core operating system, it includes a large number of open source developers from around the world. In February 2007, the second beta machine was deployed to launch countries. Figure 1 is a photograph of the second beta machine taken by Mike McGregor (used under the Creative Commons License).


Figure 1. OLPC XO laptop
Figure 1. OLPC XO laptop

XO laptop hardware

Considering its USD100 price tag and the fact that the XO laptop is intended to be used around the world in drastically different environments, the physical design of the laptop is extremely important. Specifically, it must be both durable and power efficient.

The laptop must be moisture resistant, including a rubber membrane keyboard and touchpad. It must also be shock resistant, which is why no spinning media exists. It uses a flash device for mass storage (1024MB NAND flash).

The AMD Geode LX processor was selected due to its feature integration (graphics processor) and low power requirements (1.3W is typical at 433MHz). A number of important peripherals are also included, such as a 7.5-inch dual-mode thin film transistor (TFT) display, a 640x480 resolution video camera, an Analog Devices stereo sound chip, and even an 802.11b/g compatible wireless Ethernet chipset from Marvel. The wireless device enables mesh networking between laptops for information sharing and cooperation.

Finally, a fully enclosed battery pack provides between 16.5 and 22 watt-hours of operation (depending upon cell technology). Because batteries are expendable, power management is critical. A minimum of 2,000 charge/discharge cycles are required. The XO laptop can also use other power sources, such as solar panels or car batteries.

XO laptop software

What's most interesting about the XO laptop is the operating system and graphical environment. The OLPC initiative partnered with Red Hat Software to develop these components. The Linux 2.6 kernel and GNU software make up the operating system, but the graphical interface is called Sugar. It is a simplified graphical interface designed for children and the small screen provided by the XO laptop.

Application development is innovative as well. Applications, or activities as they're called in the XO laptop, are Python programs using GTK+. I'll discuss Sugar and Python programming for the XO laptop later in this article.

Fundamental design

The designers carefully considered the audience of the XO laptop, ultimately defining a key set of eleven design principles. Rather than assuming more is better, they tailored the laptop to the needs of children in the context of learning (and not in the context of power-hungry video games). Core design principles include simplicity, usability, and reliability. Recoverability is another interesting principle being explored. This encompasses not only backup of work, but also providing children with an intuitive way to fall back to a known system state. This enables experimentation by allowing children to push the boundaries of their understanding of the XO laptop. For more information about the core design principles, see the Resources section.

As you can see, the design of the XO laptop is revolutionary from its physical design to its user interface.

Virtualizing the XO laptop

While getting an XO laptop is a slim possibility (unless you're willing to make the minimum million quantity order), you can experiment with the XO laptop using the QEMU PC emulator. QEMU is an open source emulator that emulates an entire PC (processor, display, network, disk, and so on). Using QEMU, you can boot an OLPC XO image on another operating system (such as GNU/Linux, Microsoft® Windows®, or Mac OS® X).

The first step is to download the QEMU package for your particular host (see the Resources section for QEMU download information). After you download and install QEMU, the next step is to download an OLPC XO image. You can grab the latest image from Red Hat (see the Resources section for the link).

After you install the QEMU and OLPC XO images on the host operating system, boot the OLPC laptop with the following command:

# ./qemu -L . -hda olpc.img -M pc

The -L . option specifies the directory for the BIOS, VGA BIOS, and keymaps. The -hda option specifies the image to boot. This image contains not only the Linux kernel image and root file system but also the boot sector that is used to launch Linux. Finally, the -M pc option specifies the machine to emulate (in this case, a standard PC).

After you run this command, a window displays showing the boot process. The first thing you'll see is the loader screen (in this case, GRUB, as shown in Figure 2).


Figure 2. GNU GRUB boot screen from the OLPC image
Figure 2. GNU GRUB boot screen from the OLPC image

Select OLPC for qemu stdout target. The typical Linux kernel boot process then occurs, as shown in Figure 3.


Figure 3. Linux Kernel boot messages from the OLPC image
Figure 3. Linux Kernel boot messages from the OLPC image

Along with the kernel messages emitted, the time for the boot process is also shown. This is quite fast considering that it's being emulated. When this process completes, you'll end with the Sugar user interface.


A first look at Sugar

Sugar is the novel user interface provided by the XO laptop. Because screen size is at a minimum, frames were chosen over the more traditional windows-style interface. Start with a look at the Sugar desktop (Figure 4), which appears after the OLPC laptop boots. In this figure, there are five sections that are important to Sugar. In addition to the inside of the frame, each side of the perimeter of the frame has a specific meaning in the organization of the interface.


Figure 4. The Sugar desktop showing the Home mode
Figure 4. The Sugar desktop showing the Home mode

The inside of the frame is called the Current view. This is either the Home mode (as shown in Figure 4), or the current activity. Note here that a number of activities have been started.

The top of the frame is defined as Places and contains a number of icons that are important in the production laptop but are not used here. The four icons in the upper left-hand corner are zoom buttons that allow the user to transition the desktop between the Activity, Home, Group, and Neighborhood views. Any active programs are also available here (currently there are none).

The left side of the frame is defined as Objects and is the equivalent of the clipboard in modern operating systems.

The right side of the frame is referred to as People. It contains the other laptops that are currently engaged in an activity with the user.

Finally, the bottom of the frame is called Actions. You can think of it as the launcher for activities. Note that a number of activities are shown in Figure 4. You can start the activities by clicking them. For example, if you start the Sugar Web browser (based upon Mozilla), it appears as shown in Figure 5. The Actions section also includes any notifications or invitations from other users. For example, if another XO laptop user wants to collaborate on an activity, the invitation appears here.


Figure 5. Browsing the Web with Sugar
Figure 5. Browsing the Web with Sugar

Note that if you want to enable networking with the XO laptop, you have to take a couple of additional steps. I'll cover these in the next section. Check out the QEMU documentation that's packaged with the QEMU distribution. One option is to run a VPN solution on the host operating system (such as OpenVPN). See the Resources section for more details.


Developing with Sugar

Now that you have the XO laptop image booted, look at some of the details for navigating Sugar from a development perspective. First, when the QEMU window is in focus, it owns the mouse and keyboard and all events are directed to it. If you need to navigate away from Sugar back to the host, use the Ctrl-Alt key combination. To navigate back to Sugar, simply click anywhere in the QEMU emulator window. Some of the other key sequences are shown in Table 1.


Table 1. Control key sequences for Sugar
SequenceAction
Ctrl-AltNavigate back to the host operating system
Ctrl-Alt-F1XO Linux login
Ctrl-Alt-F3Return to the Sugar desktop
Alt-0Show the developer's console

The developer's console is actually a collection of four different windows controlled by tabs. Figure 6 shows the console navigated to the terminal window. This is a regular Linux terminal, so commands like vi will work here for code development.


Figure 6. The developer's console with the terminal window
Figure 6. The developer's console with the terminal window

The terminal window is a simple bash shell. Note that you can enable networking here, as shown in Listing 1.


Listing 1. Enabling Internet Protocol (IP) networking in the terminal window
[olpc@xo-12-34-56 /]$ su -
-bash-3.1# ifup eth0

Determining IP information for eth0... done.
-bash-3.1# ifconfig
eth0      Link encap:Ethernet  HWaddr 34.59.00.12.34.56
          inet addr:10.0.2.15  Bcast:10.0.2.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500 Metric:1
          RX packets:4 errors:0 dropped:0 overruns:0 frame:0
          TX packets:28 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:1350 (1.3KiB)   TX bytes:7866 (7.6KiB)
          Interrupt:11 Base address:0xc100

lo        Link encap:Local Loopback
          inet addr:127.0.0.1 Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16346  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)


Creating and installing an activity

Now that you have a basic understanding of Sugar and how to get the developer's console up, you can write a simple activity (Sugar application) and then install it to make it available on the Sugar desktop. First, you need to be root and navigate to the activities directory from the developer's console terminal window, as shown in Listing 2.


Listing 2. Moving to the development directory
[olpc@xo-12-34-56 /]$ su -
-bash-3.1# cd /usr/share/activities
-bash-3.1#

If you run an ls command in this directory, you'll see a number of directories that contain the Python source for Sugar applications. You're going to put your activity here as well, so create the two directories that are needed, as shown in Listing 3.


Listing 3. Setting up the activity development directory
-bash-3.1# mkdir TestActivity.activity
-bash-3.1# cd TestActivity.activity
-bash-3.1# mkdir activity
-bash-3.1# cp ../Web.activity/setup.py .

As part of the setup, you need a standard file called setup.py. You copy this from an existing activity, as shown above. Next, you need to create four files that are used to implement and describe an activity. The first is your activity source file, which is a Python script. This is shown in Listing 4 and is named TestActivity.py. This file will be located in the TestActivity.activity directory. This Python activity creates two methods. The first, click, is a callback function that is called when the button is clicked. The __init__ function is called when the bundle is started. This function simply creates a button using GTK and adds it to the current view.


Listing 4. Source for the new activity
# Source for TestActivity.py
import logging
from sugar.activity import activity
import sys, os
import gtk

class TestActivity(activity.Activity):

	def click(self, widget, data=None):
		logging.info('Button clicked')

	def __init__(self, handle):
		activity.Activity.__init__(self, handle)

		self.button1 = gtk.Button('Button1')
		self.button1.connect("clicked", self.click, None)

		self.add(self,button1)
		self.button1.show()

Next, you create a manifest file called MANIFEST. It contains a single line, the source files that make up the activity (TestActivity.py). If you run an ls command in your directory (TestActivity.activity), you see the listing output shown in Listing 5.


Listing 5. Checking the contents of the development directory
-bash-3.1# ls
MANIFEST  TestActivity.py  activity  setup.py
-bash-3.1# cat MANIFEST
TestActivity.py
-bash-3.1# 

Now you go into the activity subdirectory and add your icon and information file. The icon file defines the image that's used for the activity. It's an SVG file and is shown in Listing 6 (activity-TestActivity.svg).


Listing 6. Source for the activity icon file
<xml version="1.0" encoding="UTF-8"?>
<DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" 
  "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd" [
  <ENTITY fill_color "#FFFFFF">
  <ENTITY stroke_color "#000000">
]>
<svg xmlns="http://www.w3.org/2000/svg" width="50" height="50">
  <rect x="6" y="19" width="10" height="10" 
   style="fill:&fill_color;;stroke:&stroke_color;;stroke-width:2"/>
  <rect x="21" y="5" width="10" height="10" 
   style="fill:&fill_color;;stroke:&stroke_color;;stroke-width:2"/>
<svg>

Finally, you need to create an activity information file (activity.info). This file describes your activity bundle, as shown in Listing 7.


Listing 7. The activity information file (activity.info)
[Activity]
name = TestActivity
service_name = com.test.TestActivity
class = TestActivity.TestActivity
activity-version = 1
icon = activity-TestActivity
show_launcher = yes

To check file placement, run an ls command in the TestActivity.activity subdirectory. You should see three files and a directory at the TestActivity.activity level and two files in the activity subdirectory, as shown in Listing 8.


Listing 8. Checking more of the development directory
-bash-3.1# ls
MANIFEST  TestActivity.py  activity  setup.py

activity:
activity-TestActivity.svg  activity.info

Now that your files are in place, you can build the activity bundle. For this you use the bundle builder, which is provided by the setup.py file. The following command installs and makes a distribution of the activity to share:

-bash-3.1# ./setup.py dev
-bash-3.1# ./setup.py dist

After you restart Sugar, you can use the activity on the current XO laptop. To install the .xo file (an archive file, like a Java Archive, or JAR, file), use the following command:

-bash-3.1# sugar-install-bundle TestActivity-0.xo

To use the activity, go back to the Sugar desktop. You can do this by clicking the X in the upper right corner of the developer's console. When the Sugar desktop is visible, click the activity on the Action frame (bottom of the desktop). The icon appears as two small squares that are in a diagonal. If you place the mouse cursor over this icon, a menu bar that says TestActivity appears. Click the icon, and you see the activity loaded into the current view of the frame (the icon is displayed in the Home frame). A short time later, the activity starts and the entire frame becomes a large GTK button. Clicking the button flashes the frame (indicating that the button was depressed). You can go to the developer's console now to look at the TestActivity log and see the message emitted by the button click.

To exit the activity, place the mouse cursor in any corner of the frame. This makes the frame periphery visible again. Now go to the top of the frame, place the mouse cursor over the TestActivity icon, and a menu bar appears. Now press the item called Close and the activity stops. This is not extremely exciting, but you can certainly go on to do a lot more interesting things with Python and GTK.


Going further

Although the XO laptop is still in active development, the operating system and Sugar interface are stable and usable. The OLPC initiative maintains an active wiki site with a considerable amount of documentation and technical detail. The wiki pages are a great place to learn more about this interesting project, including how to get involved.


Resources

Learn

  • Listen to our 20-minute interview with OLPC visionary, Walter Bender. In this developerWorks podcast, he describes the OLPC vision, challenges faced, and progress to date.

  • The main page for the OLPC provides information on the project, its history and goals, and how things are going so far.

  • To learn more about the hardware specification for the OLPC, check out the wiki Hardware Specification. This explores not only the current state of the hardware design but also the innovations that have been applied to the XO.

  • A core set of design principles were defined for the XO laptop and the Sugar interface. This page details the principles and how they apply.

  • While it's not here yet, a development environment for Sugar activities is under development. It's called Develop and is a Python integrated development environment (IDE) for the XO laptop (an activity for developing activities).

  • The graphical environment for Sugar is written in PyGTK, a GUI toolkit.

  • For a more detailed look at the Sugar interface, this wiki page provides a great introduction to its design and use.

  • In the developerWorks Linux zone, find more resources for Linux developers.

  • Stay current with developerWorks technical events and Webcasts.

Get products and technologies

  • QEMU is an open source processor emulator that can emulate an entire PC, including its peripheral devices like the disk, display, network, and so on. You must download and install this package to emulate the XO laptop.

  • You can download an OLPC XO image from this Red Hat site. The image contains not only the Linux kernel and root file system but also the typical boot sector used by GRUB and LILO.

  • OpenVPN allows an emulated operating system to use the networking hardware of the underlying host operating system.

  • Activities for Sugar are written in the Python object-oriented scripting language.

  • With IBM trial software, available for download directly from developerWorks, build your next development project on Linux.

Discuss

About the author

M. Tim Jones

M. Tim Jones is an embedded software engineer and the author of GNU/Linux Application Programming, AI Application Programming (now in its second edition), and BSD Sockets Programming from a Multilanguage Perspective. His engineering background ranges from the development of kernels for geosynchronous spacecraft to embedded systems architecture and networking protocols development. Tim is a Consultant Engineer for Emulex Corp. in Longmont, Colorado.

Comments (Undergoing maintenance)



Trademarks  |  My developerWorks terms and conditions

Help: Update or add to My dW interests

What's this?

This little timesaver lets you update your My developerWorks profile with just one click! The general subject of this content (AIX and UNIX, Information Management, Lotus, Rational, Tivoli, WebSphere, Java, Linux, Open source, SOA and Web services, Web development, or XML) will be added to the interests section of your profile, if it's not there already. You only need to be logged in to My developerWorks.

And what's the point of adding your interests to your profile? That's how you find other users with the same interests as yours, and see what they're reading and contributing to the community. Your interests also help us recommend relevant developerWorks content to you.

View your My developerWorks profile

Return from help

Help: Remove from My dW interests

What's this?

Removing this interest does not alter your profile, but rather removes this piece of content from a list of all content for which you've indicated interest. In a future enhancement to My developerWorks, you'll be able to see a record of that content.

View your My developerWorks profile

Return from help

static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=Linux, Open source
ArticleID=211855
ArticleTitle=Sugar, the XO laptop, and One Laptop per Child
publish-date=04242007
author1-email=mtj@mtjones.com
author1-email-cc=tomyoung@us.ibm.com

My developerWorks community

Tags

Help
Use the search field to find all types of content in My developerWorks with that tag.

Use the slider bar to see more or fewer tags.

Popular tags shows the top tags for this particular content zone (for example, Java technology, Linux, WebSphere).

My tags shows your tags for this particular content zone (for example, Java technology, Linux, WebSphere).

Use the search field to find all types of content in My developerWorks with that tag. Popular tags shows the top tags for this particular content zone (for example, Java technology, Linux, WebSphere). My tags shows your tags for this particular content zone (for example, Java technology, Linux, WebSphere).

Rate a product. Write a review.

Special offers