Archive for the ‘ Linux ’ Category

Updating your BIOS without Windows or a USB stick

On some of the new lab machines I made, I noticed the CPU clock did not drop when idle. This is usually due to a motherboard not having support for a new CPU, and can be fixed by doing a BIOS update. The really old way of doing this using a floppy disk. This really is not an option, but writing a CD or a USB stick can be as much hassle. Here is a dead easy set of steps to update your BIOS on a Fedora system. The following should be done as root.

yum install syslinux
cp /usr/share/syslinux/memdisk /boot/
wget -O /boot/floppy.img.gz http://www.fdos.org/bootdisks/autogen/FDSTD.288.gz
gunzip /boot/floppy.img.gz

Now edit /etc/grub.conf and add the following lines at the bottom

title Floppy Image
    root (hd0,0)            # Or whatever the other entries use
    kernel /boot/memdisk
    initrd /boot/floppy.img

Of cause the floppy image does not yet contain the flash program or data. To get these you will need to look up your motherboard at the manufacturers website and click on support. Then find the latest BIOS data file. These will be either in a ZIP or an archive EXE. If it is an EXE then usualy you can extract their content without having to resort to Windows. Try using unzip, unrar (available from RPMFusion) and 7za (available in the p7zip package). Gigabyte for example use both rar and 7zip based executables. Once you have extracted it, you should have a flash file (the file extensions on these are completely random) and a flashing program (something like FLASHSPI.EXE or AWDFLASH.EXE). To copy these to the floppy image execute the following:

mkdir /mnt/floppyimage
mount -o loop /boot/floppy.img /mnt/floppyimage
cp {your flash and executable files} /mnt/floppyimage/
umount /mnt/floppyimage/

What you have now is a FreeDOS floppy disk image which can be booted by selecting it in the grub boot menu. Remember the grub menu is now hidden, so keep any key pressed during the boot reach it. Once it has booted (you can press F5 to bypass executing autoexec.bat) simply run the program as instructed by the motherboar website:

flashprog.exe flashfile.123

Happy flashing!

Will’s TV box

Will and Sophie got married last April and the gift list they had was, lets say “disagreeable” (a £30 gravy boat is silly). Luckily Sooty and I had a policy of giving gifts on the first anniversary (should they last that long). I wanted for years to make Will a TV/server box, so this seemed like the perfect opportunity.

Ebuyer had the MSI Media Live bare-bone systems for £120 which is reasonable for a sleek case. Andrew bought one of these a couple months earlier, when I pointed them out, and he had no problems. There were also positive reports about these by MythTV users.

The Athlon X2 issue

Here there was a bit of pain. I ordered an AMD Athlon 5000+ to go into it (it was on the supported CPU list). I plugged it in, and no response. So I take the whole machine to Andrew’s house, try the 5000 in his machine and again nothing, while his 4400 works in mine. Grrrr I think, borked CPU. Got an RMA, CPU was picked up, a replacement arrives a week later. Exactly the same problem. Then I start reading into this more.

Apparently there are two CPUs which have the exact same name (AMD Athlon 5000+ AM2). The newer version is in fact a low end Phenom based CPU which has two cores disabled. This is the only Phenom based chip which goes under the name Athlon X2, so had I picked any other chip in that range, I would have been fine. Most new boards will support Phenoms, but this one does not (even witha BIOS update). So I ordered a 5400 and kept the 5000 to upgrade my own machine (a painfully slow Athlon 1700). On the positive side, that part can be overclocked rather well and one of the cores can be unlocked with a good motherboard.

The machine

The actual box is fine, nothing amazing, but just works. The other parts were: a 1.5TB Samsung F2 disk (I didn’t test the speed but the F3 we have in the office is incredible), 2GB of RAM, a Hauppauge dual DVB-T receiver and the KeySonic wireless keyboard/touch-pad. The keyboard was so good, Andrew decided to buy one for himself to replace the Apple bluetooth keyboard and mouse he was using until that point. Its nice to see the Linux bluetooth support is very smooth. The other day Will took over an hour to bind his new Apple mouse with his Mac laptop. In the mean time I managed to sense the device from the other end of the room and bind with it within seconds.

As an always on machine, it is important to look at the power consumption. The rule of thumb is 1Watt is £1 per year (more like a $1 at the moment). This makes it easy to calculate how much you will save should you go for a lower power part. The TPD (Thermal Design Point) is roughly double to triple the average power consumption. The second thing to look for is the clock scaling. The 5000 I took for my machine scales from 2.2GHz, down to 800MHz (where it spends most of it’s time). This is a very good range compared to my Core2, at work, which scales from 3GHz to 2GHz. The added advantage of having a low power system, is the fans will rarely spin up to their higher speed. Andrew’s machine, which is practically identical, pulls 63W when idle.

The on board video card has a HDMI output, which is connected to the digital audio on the sound card. This is quite common nowadays in on-board cards, but I have also seen ATI cards which have a digital only sound chip on the card for HDMI audio. One shame is that MythTV doesn’t play well with pulseaudio and likes to grab the digital ALSA output. Apparently this is annoying when you want to pause TV and play a YouTube video. I recommend ignoring the digital output as that connects to the television and thatwill probably have awful speakers. Instead use the 7.1 analogue audio system already in the machine and attach it to some reasonable speakers.

Fedora and MythTV

Fedora was happily running on the machine detecting all the devices (although the DVB card requires some extra firmware which is well documented). MythTV has improved in the setup area greatly and installing the Rpmfusion MythTV packages did practically all the work for me. The first TV box I made for myself took about three days to get properly going. The remote was fairly easy too as the new remote control configuration tool works reasonably well and saves you having to search for the appropriate set-up file. One down side of the remote is the ugly windows logo on the middle button. This is easy to change using a torx head screwdriver and a plastic spudger. Andrew has a Fedora logo one, and Will’s one has a Tux.

For a machine that is only used to record and watch TV, 1GB is usually enough, but since the machine will be on all the time it can also be used as a server. On mine I run MySQL, DHCPd, DNS, MLDonkey, Apache, Ping proxy, DNS proxy, Squid (with passive redirection) and a VNC desktop I can log into. Will additionally has a DAAP server and VMware Widnows session just to run something called SoulSeek.  These can chew though another GB.

So far it has been 4 weeks since they started using the machine. No major complaints yet apart from the DVD menu system being a bit poor (I recommend you don’t play DVDs and just rip them to the hard disk). The statistics of my machine are a testament to how useful it is (Number of shows: 1436,  Number of episodes: 11218).

A couple cute Linux games

I spent Christmas writing lectures and I thought I deserved a little break. As a reward I had a brief look though some commercial games available on Linux. I am not all that keen to support closed source development, but the game side of the open source world is sadly relatively weak, and I am pro supporting publishers who develop with Linux in mind. Traditionally, closed source games were a pain to install and would break after updating the kernel or libc (as I found recently when trying to play some). This seems no longer the case. I have gone though maybe 20 demos and all worked out the box on Fedora 12. Here are the two that really stood out.

Machinarium

This is a game by Amanita Design who have been making some fantastic things with flash for years now. One of the best things I have seen from them is a very short game they made for The Polyphonic Spree (who are amazing in their own right) where it became a different way to experience their album.

Machinarium is a much longer and fuller game with vast amounts of detail. You play as a cute little robot who has been discarded in a pile of junk.

The scenery of every screen is fantastically detailed with layered moving foregrounds and animated background characters.

The body of the game is a puzzle adventure. These are often frustrating as you spend hours of your time trying to rub every object against every other object to make anything happen. The puzzles here are, on the whole, rather logical. You rarely have more than four items in your inventory and the game has a fantastic hint system. There are two types of hints, the hint icon simply repeats the obvious stuff you should have noticed. The second hint system gives you a cheat sheet for that screen, only if you pass a level of a mini game. The mini-game is a last resort thing but the cheat sheet is a hand drawn scribble notes explaining the solution in an incredibly cute way. When the robot gets a bit bored he starts day dreaming, giving a short entertaining animation.

Having said that, there were some weird dead ends I ended up getting into. At one point, I needed an oil drum which was offered in a shop. The shop owner asked for moeny, so I spent ages wondering around looking for sources of cash. The actual solution (SPOILER ALERT: of throwing a swarm of flies into his eyes and stealing the drum) was somewhat bizarre.

For $20 (£12.40 in the UK) you get about 4 hours of game-play. If you like this game, you should also try Samorost (Free) and Samorost 2 ($5).

Aquaria

This is not the first time I played Aquaria. It was an addiction of mine a couple years ago, before I removed my Windows installation. This is one of the most engrossing games I have ever played. On the face of it, you basically swim around and solve the mystery Aquiaria. The game is part puzzle mystery, part atmospheric escapism and part arcade shoot-em-up and one of my favourite games of all time.

The swimming comes very naturally and it is a pleasurable experience just to have a bit of a swim though the environment. As the game progresses, you attain more powers, which open up more of the vast map to explore. Unfortunately this was ruined somewhat by one of the final powers, the power to get a boyfriend. I liked Niaja (the main character in the game), she is strong, determined and has kick ass moves. Yet then she falls in love with the most pathetic guy who follows her around, occasionally throwing a fire bolt at some harmless fish and uselessly getting stuck flapping around on every piece of rock you go past. Then he manages to get himself captured and I could never get past the final boss to free him. This is possibly because I suspected the final scene would be them swimming hand in hand towards the sunset while I was screaming at the monitor “NOOOOOOO! You can do so much better! He is not the only fishman in the sea!” (well actually he is, but that’s not the point).

So, as I mentioned earlier, the game can be very hard at points. This can frustrate you if you can’t get past some stage. The second issue is the enormity of the map. The game is sandboxish, which allows you a bit of freedom to the order in which you attain your powers. On the other hand, you can spend quite a while swimming around looking for areas you have not explored.

It is a shame that many people will snub this game for it’s girly overtones. Cookery and collecting recipes features heavily which I found a bit bizarre at first become compelling after a while as you collect ingredients to attain special temporary attributes. I was completely trapped by this game for weeks and enjoyed it immensely.

Aquaria still has not been released for Linux, but the beta has. The free beta version is of the full game with no restrictions (although the site says this is only until mid February 2010), and I have not seen any bugs yet. There is a solid month worth of game-play here and even when the game becomes final, it is easily worth the £13.54 that the Windows and MacOS versions are selling for. I should also mention that the game does use a lot of open source elements. There is a heavy use of ogg/png and the lua scripting language.

Very cold indeed and some bits and bobs

The cold

It has been somewhat cold recently here in the UK. Woke up today to find that I couldn’t see outside.

That is frost, but on the inside of the window. I am currently sleeping under two duvets and getting up is not pleasant experience.

Even what looks like condensation at the top of the window was completely frozen. Would be nice to have double glazing.

More fedora icing

I forgot to post the sprinkled sugar cupcakes I made a few months ago for the release. These were made using a paper cut-out template and then dusted. I should have made more blue icing sugar. I found the best way to make it was using a small resealable plastic bag. Add the icing sugar and a little blue dye. Then squish the lumps with your fingers until it is dry and fine.

Take that GDM!

It is a shame, but at the university there is somewhat strong resistance to the concept of a graphical login. Here is what the students see when they come to log into a machine. It will look even more silly on high resolution monitors with KMS graphics where the ASCII art occupies a small section in the upper left.

Plymouth theming guide (part 4)

This the final part of the theming guide. As I mentioned in the last post, you already know everything you need to write your themes. In this post I will show a couple themes I wrote to explore the system and some fancy high level aspects of the scripting language. You don’t need to know these, they are just a cute method to solve a problem that others may find useful.

Themes

To install these themes, extract them to /usr/share/plymouth/themes and run the appropriate plymouth-set-default-theme line.

Vizta

A very simple theme matching what the Vista theme does. It has just 30 lines of custom code.

http://brej.org/blog/wp-content/uploads/2009/12/vizta

source

Dandelion

This theme has the target of stressing the system. A couple months ago it was running at about 3 fps, now my machine hits 30 fps and spends some time idle.

http://brej.org/blog/wp-content/uploads/2009/12/dandelion

source

Inheritance

When I first proposed doing a scripting system Ray said “If you do this, I guess I’d recommend you keep it very simple”. I agreed, so what I aimed to do was to implement all the features with the minimum space. The solution I came up was to kill several birds with one stone. The stone being an inheritance system.

The important operation for inheritance is the single bar (“|“), inherit operator. Think of it as a very lazy OR function. As an example take the statement:

A = B | C;

This creates a new object (A) which is an inheritance of B and C. A now gains all the properties of B and, as a fall-back, C. There are three ways of using inheritance objects.

Direct

Consider the following statement:

A = "Seven" | 7;
B = String(A).CharAt(2);
C = 80 + A;

So A is an inheritance of the string “Seven” and the number 7. This means when in situations where a string is preferred, it will act as a string, and when the a number is preferred, it will act as a number. The value in B will be the third character in the string (“v”), and the value in C will be the number 87.

This kind of inheritance is used to allow native C objects (images, sprites etc.) to be able to be used as hashes to find appropriate functions to call. An object is created which inherits from the native object and the object template hash (which holds all the functions). The constructor function is also connected to the template using an inheritance. Thus you can treat it as a function, or as a hash of functions and it will adopt the appropriate behaviour.

text_image = Image.Text("string"); # Treat Image as a hash
png_image = Image("filename.png"); # Treat Image as a function

Hashed

Hashes are the main containers in the system. When an object inherits from two hashes, accessing the inner elements will trigger a crawl through all hashes for that element.

A.a = "a";
A.b = "b";   # A: a="a", b="b"
B.b = "B";
B.c = "C";   # B: b="B", c="c"
C = A | B;   # C: a="a", b="b", c="c"

When accessing the elements within C, the system looks within A, then B (also within any object they inherit from). Thus, elements within B can be overridden by A. This is very much like the __proto__ in Mozilla JavaScript.

Functional

Just like hashes, when functions are inherited, the system goes through them in the inheritance sequence, executing each one and moving onto the next if it has failed.

Fib = fun (v) {if (v <= 2) return 1; else fail;}
    | fun (v) {if (FibCache[v]) return FibCache[v]; else fail;}
    | fun (v) {return FibCache[v] = Fib(v-1) + Fib(v-2);};

If you have ever programmed the ML languages, you will already be somewhat familiar with this. In those, you can put constants in the function variable decelerations and functions which do not match these to the passed parameters, fail. Here, at any point in the function, you can choose to fail. The system then tries to execute the next function in the inheritance.

Plymouth theming guide (part 3)

Now the basics have been covered in part 2 of this guide, we can now tackle some more advanced tasks. This part is for beginners to intermediate. If you have never programmed, then this will be a rough introduction to the field and thus you may need to ask for help about some confusing aspects.

Until now, all the examples have been simple assignments and there hasn’t been much “programming”. At the end of the last part, the background image needed to be scaled without distorting the aspect ratio. If the image is wider than the screen, then the image needs to be scaled up to the height of the screen and let the sides hang over the edges. If the image is taller than the screen, the image should be scaled to the screen width and allow the top and bottom to go beyond the edge of the screen.

scale_ratio

You can get the screen ratio using the Window.GetWidth and Window.GetHeight functions introduced in the previous part. The ratio is height to width. The greater the number, the taller the proportions.

screen_ratio = Window.GetHeight() / Window.GetWidth();

GetWidth and GetHeight functions also work on images.

flower_image_ratio = flower_image.GetHeight() / flower_image.GetWidth();

To create the scaled image, the scale factor needs to be determined. If the screen is tall, we make the scale factor such that the image will be the same hight as the screen, and allow it to dangle off the edges. For a wide screen, make the image match the width and allow the top and bottom to go beyond the edges. The scale factor can then be used to scale the image width and height.

if (screen_ratio > flower_image_ratio)
  {  # Screen ratio is taller than image ratio, we will match the screen height
     scale_factor =  Window.GetHeight() / flower_image.GetHeight();
  }
else
  {  # Screen ratio is wider than image ratio, we will match the screen width
     scale_factor =  Window.GetWidth() / flower_image.GetWidth();
  }
scaled_flower_image = flower_image.Scale(flower_image.GetWidth()  * scale_factor,
                                         flower_image.GetHeight() * scale_factor);
flower_sprite = Sprite(scaled_flower_image); # Create the a sprite using the scaled image

Now the image is scaled to the correct width and height, it needs to be placed in the centre of the screen.

flower_sprite.SetX(Window.GetWidth()  / 2 - scaled_flower_image.GetWidth()  / 2); # Place in the centre 
flower_sprite.SetY(Window.GetHeight() / 2 - scaled_flower_image.GetHeight() / 2);
flower_sprite.SetZ(-10000); # Place right at the back

mytheme_placed

If everything went right, your code should look like this:

flower_image = Image("flower.png");

screen_ratio = Window.GetHeight() / Window.GetWidth();
flower_image_ratio = flower_image.GetHeight() / flower_image.GetWidth();

if (screen_ratio > flower_image_ratio)
  {  # Screen ratio is taller than image ratio, we will match the screen height
     scale_factor =  Window.GetHeight() / flower_image.GetHeight();
  }
else
  {  # Screen ratio is wider than image ratio, we will match the screen width
     scale_factor =  Window.GetWidth() / flower_image.GetWidth();
  }

scaled_flower_image = flower_image.Scale(flower_image.GetWidth()  * scale_factor,
                                         flower_image.GetHeight() * scale_factor);
flower_sprite = Sprite(scaled_flower_image); # Create the a sprite using the scaled image

flower_sprite.SetX(Window.GetWidth()  / 2 - scaled_flower_image.GetWidth () / 2); # Place in the centre
flower_sprite.SetY(Window.GetHeight() / 2 - scaled_flower_image.GetHeight() / 2);
flower_sprite.SetZ(-10000); # Place right at the back

If you wish for your background to match the one in your desktop, copy it to the theme directory and edit the script to load the image of that filename. Only PNG files are allowed.

mytheme_constantine

Finally to install your theme into the ramdisk, so it is loaded when your computer starts, add –rebuild-initrd to the plymouth-set-default-theme command. Do be careful not to install a theme which deadlocks. Make sure you have a backup kernel or initrd image if all goes wrong

plymouth-set-default-theme mytheme --rebuild-initrd

Animation

Start by making a new sprite with an image of a butterfly:

butterfly_image = Image("butterfly0.png");
butterfly_sprite = Sprite(butterfly_image);

animation_step1

At the bottom of the block of code you are editing, there is a function named refresh_callback. This is called 50 times a second (unless the system is busy) just before refreshing the screen. Within the function, you can move the sprites around and these movements will be updated on the screen. Take a look at this example:

progress = 0;
fun refresh_callback ()
  {
    progress++;
    butterfly_sprite.SetX(progress);
  }

animation_step2

At every refresh, the butterfly will be moved one pixel to the right. To make the butterfly flap it’s wings, several frames are needed. Instead just loading one image, this requires an array of images to be loaded. Replace the original two lines that loaded the butterfly image and created the sprite, with these:

for (i = 0; i < 4; i++)
  butterfly_images[i] = Image("butterfly" + i + ".png");
butterfly_sprite = Sprite();

You can append strings to numbers to create the four filenames. Secondly, if a sprite has not been attached to an image, it will simply be empty until one is set. Adding the following line into therefresh_callback function should rotate through the 4 butterfly frames. Because the progress is divided by 6 in order to slow the animation to one frame every 6 refreshes, we use a Math library function to round down a number to an integer.

butterfly_sprite.SetImage(butterfly_images[Math.Int(progress / 6) % 4]);

animation_step3

There are some other math functions available, sin and cos are often useful. Replace the SetX line with the following to make the butterfly go around in a circle around the centre of the screen.

theta = progress / 100;
butterfly_sprite.SetX(Window.GetWidth() / 2 + Math.Sin(theta) * 200);
butterfly_sprite.SetY(Window.GetHeight() / 2 - Math.Cos(theta) * 200);

animation_step4

Now the butterfly looks a little weird pointing the wrong way as it is going around in a circle. We need to rotate the butterfly image so it is flying forward. Add .Rotate(theta) to the image while setting it to the sprite. This creates a new image which is rotated by the angle theta.

butterfly_sprite.SetImage(butterfly_images[Math.Int(progress / 5) % 4].Rotate(theta));

animation_step5

If you have reached this point, you should now have all the knowledge you need to start creating your own themes. For a full list of available functions and script syntax take a look at the freedesktop plymouth script wiki. Good luck, have fun and make some nice splash screens.

Plymouth theming guide (part 2)

The first part of guide showed how to set up the system to be able to view plymouth themes and make simple adjustments to ones that are already present. This part will show how to make a custom theme, without delving down to the level of writing C.

One of my targets for this year was to add a simple way of designing themes without having to worry about many low level aspects (redrawing parts of the screen, keeping pointers to all elements to free them etc). The scripting language allows the designer to get stuck into the design, while the system is already optimised to take care of and minimise the areas to be refreshed. It is now quite stable and this is the method used by Mandriva for their default themes.

The following walk-though will show you how to make a small example splash. This part should be very easy and even if you have never programmed before, you should have no problems. First download and install the template:

wget -O /tmp/mytheme.tar.gz http://brej.org/blog/wp-content/uploads/2009/12/mytheme.tar.gz
cd /usr/share/plymouth/themes/
tar xzf /tmp/mytheme.tar.gz

Now the theme is installed, and you already have a system set up like explained in part 1, you can switch to it:

plymouth-set-default-theme mytheme

and then test it:

plymouthd --debug --debug-file=/tmp/plymouth-debug-out ; plymouth --show-splash ; for ((I=0;I<10;I++)); do sleep 1 ; plymouth --update=event$I ; done ; plymouth --quit

mytheme_template

Notice this time some debug information is generated and the file /tmp/plymouth-debug-out contains more. The debug information is useful to find any syntax errors in your script. It is a good idea to keep a text editor with this file open and revert to saved after every execution to watch for any errors. A syntax error contains the line and column number of the expression like so:

Parser error "/usr/share/plymouth/themes/mytheme/mytheme.script" L:8 C:42 : Expected ';' after an expression

In the mytheme directory there is a file named mytheme.script. Open this using your favourite text editor. At the top of the example script, there are some lines which create the theme, and below this are sections which control the password dialogue, progress bar etc. You should leave things below the dialogue line alone for now.

Lines starting with # are comments, so lets skip to the first two executed lines:

flower_image = Image("flower.png");
flower_sprite = Sprite(flower_image);

In the mytheme directory, you will notice some images. One of these is flower.png (from Nicu CC-BY-SA), which the first line loads. The loaded image is assigned to flower_image, which can then be used by sprites. A sprite is an image with a position on the screen. The second line creates a sprite using the flower image. By default this is placed at X=0, Y=0, which is the top left of the screen. To change the position of the sprite use the SetX and SetY functions on the sprite. Adding the following line will move the sprite to 100 pixels to the right.

flower_sprite.SetX(100);

mytheme_setx

In a similar way, setting the Y position will move the image down the screen.

flower_sprite.SetY(400);

mytheme_sety

Notice there is no problem if the sprite runs off the edge of the screen. Also notice how the progress bar is on top of the flower sprite. The sprites have a defined order of which is on top. To demonstrate this, lets add another sprite. You can reuse the flower image and place it overlapping with the original flower sprite.

other_flower_sprite = Sprite(flower_image);
other_flower_sprite.SetX(-100);
other_flower_sprite.SetY(200);

mytheme_overlap

Negative coordinates are acceptable. The new sprite will be placed on top of the previous one. To override this, each sprite has a Z value. The higher the Z value, the higher up the stack the sprite is (drawn on top of others). To place the original flower sprite on top you set its Z value to be higher. The default Z value is 0, and you can set it using SetZ.

flower_sprite.SetZ(10);

mytheme_setz

Now not only is the original the sprite above the other, it is also above the progress bar, which also has the Z value set to 0. In general, wallpapers should have Z set to high negative values to force them to the very back and the password dialogue has a Z value of 10000 to place it on top of any theme components. Thus, make sure you don’t place any sprites higher than 10000, otherwise you may find it difficult to type in your password.

Lets take the sprite back to the background and reposition it. Often you want to set X, Y and Z at the same time. This can be done using the SetPosition function.

flower_sprite.SetPosition(0, 0, -10000);

mytheme_setposition

As well as the X, Y and Z values, the sprite also has opacity. The default setting of 1 makes the sprite solid. Values between 0 and 1 make the sprite partly transparent. This can be set using SetOpacity.

other_flower_sprite.SetOpacity(0.3);

mytheme_setopacity

Setting this to 0 will make the sprite invisible. This should return the display the original setup.

other_flower_sprite.SetOpacity(0);

mytheme_template

The image of the flowers is very nice, but it is the wrong shape and size. You could distribute an image for every possible screen resolution, but this would be terribly space consuming. Instead you can scale the image to suit your needs. A new scaled image can be created using Scale and to change the image the sprite is showing, use SetImage.

resized_flower_image = flower_image.Scale(640, 480);
flower_sprite.SetImage(resized_flower_image);

mytheme_scale

Here the image is scaled to 640×480, but this is not the screen resolution. For now, assume there is only one monitor connected (I will explain more about this later). To get the width and height of the screen, use Window.GetWidth() and Window.GetHeight(). You can use these to scale the image to the screen dimensions.

screen_width = Window.GetWidth();
screen_height = Window.GetHeight();
resized_flower_image = flower_image.Scale(screen_width, screen_height);
flower_sprite.SetImage(resized_flower_image);

mytheme_fullscreen

Now the image is scaled to cover the whole screen, but is the wrong aspect ratio (although that is difficult to see in this example). Correcting this will require some programming which will be shown in the next part of the guide.

Plymouth theming guide (part 1)

Judging by the many forum postings and articles, many people do enjoy a nice boot splash and there is a real desire to customise their spin or even the individual machine to their preferred theme. In this guide I will try and show you how to make your own custom splash, walking though the process of viewing, changing and installing. Even if you are a Linux novice, you should be able to follow the steps without much trouble. This guide assumes a Fedora system, although there should be very few changes between the different installations.

Set-up

Obviously you can view plymouth running by turning on your computer, but that does get rather tiresome if you wish to test frequently. Without restarting your machine, there are three sensible methods of testing plymouth: using a  victim machine, using a virtual victim machine or using the X11 plugin.

Victim machine

This is the easiest method, although it does require a second physical machine to work with.

If you do not have a KMS compatible system, then you will need to add vga=0x318 to your kernel line. This pushes the console to a VESA graphical mode. The 0x318 actually stipulates 1024x768x32bit mode. To see all the modes and find one most suitable for you, add vga=askme and a list will appear (don’t forget the 0x).

SSH into the machine as root (yes you do need to be root). The splash will be tested on tty1, but tty1 has two problems: there is an X session running on it and if you quit that, getty will start and capture keyboard events. To turn off getty on tty1, edit /etc/event.d/tty1 an comment out all the start and stop lines with a hash.

#start on stopped rc2
#start on stopped rc3
#start on stopped rc4

#stop on runlevel 0
#stop on runlevel 1
#stop on runlevel 6

Then drop to init level 3, which kills X and brings you to an empty console, by running init 3. Now install all the themes you wish to try out:

yum install plymouth\*

This is how to do this in Fedora, you should know the way to do this in your distro already.

Virtual victim machine

The alternate to using a physical machine is to use a virtual one. Both VMWare and QEmu work very well. You will have to do an OS install on the virtual machine. These do not yet support KMS (support is coming soon apparently), so you will need to add the vga parameter on the kernel line. The setup is exactly the same as  one for a physical victim machine.

X11 plugin

This method allows you to execute plymouth within X. This is the preferred testing method BUT it can crash your X if you accidentally pick a text theme. It also does require you to compile your own version of plymouth to get the x11 renderer. As root get the latest git checkout:

git clone git://anongit.freedesktop.org/plymouth

Next configure and compile it:

> cd plymouth
> ./autogen.sh --prefix=/usr/ --with-system-root-install
> make
> make install

Now it is installed, make sure you have the DISPLAY set correctly so even if you run as root, it can connect to your X session and display the windows.

plymouth-x11

When you run it using the directions below, you will notice you get two screens which allows you to test the behaviour of a two monitor setup.

Viewing

Now you have the system set up, you can manually execute plymouth to examine a theme. First, as root, start the plymouth daemon (plymouthd lives in /sbin/ so make sure you have that in your path):

> plymouthd

Now it is executing, you can control it using the plymouth program. To show the splash run:

> plymouth --show-splash

This should display the splash.

plymouth_charge

To quit, execute

> plymouth quit

The splash should then quit and the terminal return to its text mode. You may have noticed the progress did not advance very quickly. The progress is estimated using events, based on the event arrival time of the previous boot. To show the splash for 10 seconds and watch the progress moving execute the following one-liner:

> plymouthd; plymouth --show-splash ; for ((I=0; I<10; I++)); do plymouth --update=test$I ; sleep 1; done; plymouth quit

There are several themes installed on your system. To get the full list run:

> plymouth-set-default-theme --list

To change to any of these themes replace –list with the theme name e.g.:

> plymouth-set-default-theme spinfinity

Now you can examine any theme you wish. But what if you don’t like any of them?

Theme editing

It is important to understand the difference between a theme and a plugin. A theme uses a plugin and stipulates some parameters the plugins uses. This information is stored in the directories under /usr/share/plymouth/themes/. Each directory has a .plymouth file which describes the theme, stating the plugin it uses and any parameters the plugin allows to be set. To create a new theme, simply copy an entire directory to a new name, rename the .plymouth file to the new name, and update its contents. In addion, you can now also change the images that your new custom theme uses.

This is sufficient if you wish to recycle one of the already present plugins. For more customisability you can write your own plugin in C which is, to be honest, not very easy. The much simpler alternative is to use the script plugin and write a script to describe the theme, and that is what I shall be describing in the next post.

For the hate of APE tags

APE tags are yet another method of tagging media files with metadata. Ever wondered how your MP3 player knows the title and the artist of a song? Well it is through the use of tags implanted within the file, making sure the player does not try to play the information. The three most popular MP3 tag types are:

  1. ID3v1 – the original tagging format form 1993 using a fixed field block with a title, artist and album. All in iso-8859-1, so you probably could still correctly spell Röyksopp and Sigur Rós, but you will have problems adding the artist 峰厚介 – 市川秀男 – 日野元彦 – 植松孝夫 – 池田芳夫 – 稲葉国光 playing track ジンジャーブレッド・ボーイ, both due to the characters used and the 30 character limit in each field.
  2. ID3v2 – came in 1998 with the solution of using flexible and definable fields and allowing the tag to be places at the start of the file. The flexibility allowed apps to keep any kind of information they liked within the file. Everything from the maximum volume of the track to album artwork.
  3. APE – was implemented in parallel with ID3v2 and solves the same issues and the format is even more versatile.

ID3v2 is the most common tag format in MP3 files “in the wild” and most taggers will add an ID3v1 tag from the ID3v2 tag data just to cover both bases. APE, although not as common due to its flexibility, is the preferred tag format in many applications. Rhythmbox for example looks for an APE tag, then an ID3v2 and at a last resort tries an ID3v1. The problem is that most Linux tagging tools, and players which allow you to edit the tags, only write ID3 tags. This creates a bizarre situation where you change the tag of a song in Rhythmbox, the value in the field changes, the ID3 tag is updated in the file, Rhythmbox notices an updated file, it re-reads the file APE tags, changes the field back to it’s original value.

How to kill APE tags?

This is something I have struggled over for several years. There are pieces of Linux software which can edit APE tags, but I found these get confused by the presence of an ID3 tag. For ages, I would remove the ID3 tag from a file, remove the APE tag, then re-insert the ID3 information. This was both clumsy and dangerous as my hacky shell scripts would often do disastrous things with tags that have escaping characters (If you are in a band, release a song named \” rm -Rf *; ).

The pain lasted until the other day, when I looked around and found py-ApeTag. Wow, it just works (that’s my favourite type of working). It removes the APE tags even when obscured by other tags and worked even in cases where I gave up trying to use other software to remove the tag and went by hand with hexedit to damaging the field names so they would not conflict. Applied it to my entire music collection without a single fault. Thank you Jeremy Evans!

How to use

To install, as root, download my altered version of the py-ApeTag module to some bin directory and make it executable.

su
wget http://brej.org/blog/wp-content/uploads/2009/11/ApeTag -O/usr/bin/ApeTag
chmod a+x /usr/bin/ApeTag

To run, execute ApeTag with the filenames of the files you wish to view the APE tag of.

ApeTag *.mp3

Now that you can see the tags, you can remove them. You can apply this to files with no tag and it will not touch them.

ApeTag --delete *.mp3

To apply to all files in your library.

find -name \*.mp3  -exec ApeTag {} \;

Fedora icing

The Fedora 12 release is coming up and I wanted to make some special icing for cupcakes for the release day. This is my first time working with icing sugar so it is mainly based on guess work.

Instructions

In all steps, make sure everything is very dry. Icing sugar sticks to anything with the slightest moisture.

Sift the icing sugar. It occupies a lot of volume but here is only about 200 grams.

icing1

My flat mate calls the bits around the edges of the bowl “making a mess”. I call it “preparing the surface”.

icing2

Drop one teaspoon of water into the sugar and work into the mixture with a fork. Don’t use your hands as it will stick. Keep adding tiny amounts of water, eventually a drop at a time until the mixture is blended.

icing3

Once it is all in one lump, and it is not too sticky, you can finish kneading it with your hands. Remember the surface should be very dry. The sugar on the surface is just there to mop up any moisture. If it is too crumbly, make a pit in the middle of the ball, add a drop, close it up and hope it doesn’t reach the outside before blending. If you put it on the outside it will stick to everything.

icing4

Take three quarters to a separate ball. In a bowl, blend about 2ml of blue icing dye and more sugar, until it has a similar consistency to your original ball. you may have to repeat the process to make it more blue.

icing5

Take a piece of the two balls, and blend together.

icing7

To get a good in between blue I needed to use two parts white to one part blue.

icing8

Now all the balls are finished, onto the shaping. Here is an example with the white. You can see my rolling pin in the background. Don’t use it, it messes things up.

icing9

Instead roll out to make an icing sausage.

icing10

Then use a flat edge to press it down into a rectangle. I used my clever. Use the same flat edge to pat the sides into a neat rectangle. It needs to be longer than the one shown.

icing11

Cut a piece off the end for the cross . You can see how it forms the Fedora f. You also need: cylinder (like one below) cut it into four, two dark blue strips same size as the white one, a two thirds length light blue strip and some left over dark blue icing.

icing12

Two of the cylinder slices need to have their corners rounded to make tear drop shapes. Time is of the essence here as you don’t want parts to dry out while you are making others. Start with the tear drops and curl the white around them. Add the small white and light blue strips. Add the two remaining cylinder slices and smooth them to the infinity symbol. Finally, surround the whole thing with the two blue strips (if it was one strip it would crumble).

icing13

While it is still warm, you can start stretching it. Start by squeezing the whole thing between your hands from all sides until it becomes sufficiently long to roll. Then start rolling it very slowly, evenly and gently (this is not dough, no long starch and protein strings). Here I cut it into two as I wanted two different sizes. Once it is the desired size, form a small strip with the left over blue and continue rolling back and forth without destroying the ridge.

icing15

Don’t do what I did and cut them straight away. Put the whole roll in the fridge for 10 minutes to let it firm up. The ones at the ends will be somewhat malformed.

icing16

You can see that they become misshapen if you cut while it is still soft, but they are easy to reshape. Don’t leave them on the work surface, get them onto some tin foil and into an warm oven to dry out. An hour at 50 degrees Celsius made them sufficiently crumbly to make them not stick together in a storage box.

icing17

These will last forever so long as they don’t get wet. You can have them in their crumbly state stuck into ice-cream, or add a few drops of vanilla essence which will make them soft on top of a cupcake.

icing18