Thursday, September 29, 2011

DisplayLink and vgaswitcheroo.

DisplayLink: Just something I wanted to share. The problem with current 'modern' laptops can be, that they don't provide a VGA port, which is often required to connect beamers (the reason why I needed one of those adapters). One way to to solve this, is to use some DisplayLink adapter, which allows to connect display via USB.


But it is hard to find real DisplayLink adapters, it took me two random and one informed transaction to get a supported adapter:LogiLink USB to DVI/VGA/HDMI Multi-Display Adapter (UA0077).

This adapter has quite good support in Fedora after installing the xorg-x11-driver-displaylink package.
$ sudo yum install xorg-x11-driver-displaylink
$ sudo modprobe sisusbvga
Use dmesg to find out about the assigned framebuffer-device (fb). Now the driver is available and the appropriate kernel module loaded but you still need to dump the following file into /etc/X11/xorg.conf.d/
# /etc/X11/xorg.conf.d/displaylink.conf
Section "Device"
        Option       "fbdev"     "/dev/fb2"    # use the device given in dmesg
	Identifier   "DLCard"
	Driver       "displaylink"
EndSection

vgaswitcheroo: Well, I didn't find out much more on the vgaswitcheroo side. I didn't find a way to determin if a monitor is connected to the discrete card, when this card is turned of (it seems that on some setups the integrated card get's "infos" about monitors connected to the discrete card, but not on mine). But I wont continue to poll for a monitor on the discrete card, so I'll just provide some trayicon (or how i's called in the shell slang), which enables the user to switch between the cards.

Wednesday, September 28, 2011

Alliteration - Fedora Fusion


I got my hands on a Lenovo x121e (5051) - an AMD Fusion E-350 powered laptop. So how does Fedora 16 Alpha 15 on that device?

Reasons? Much new things to test: EFI, AMD Fusion E-350, HDMI + VGA. And a quite low price tag at about € 360.
Like Fedora somewhat on the bleeding edge.

What works? Everything I tested so far. Wireless (Atheros), Graphics (ATI Radeon), Harddrive, USB, ...
And all those shiny things worked out of the box (!). No manual intervention needed, so a silent a cautious A+.

What doesn't? I just noticed some graphics glitches in gnome-shell, but maybe those will get fixed until the final release.

EFI: I could boot into Fedora 16 Alpha Live Desktop using the legacy fallback. EFI seems to work, but there are currently issues booting Fedora 16 with EFI, so I went back and use Fedora 15 updates-testing booted via EFI and BTRFS partitions.

Monday, September 26, 2011

qemu and backing images.




Cows cows cows

I always wondered but never really looked up how backing files can be used with qemu. I came back to this when stumbling across  the curl backend which brings http and ftp support to qemu and landed in fedora recently.
The idea is basically to use some master image accessed via http, e.g. residing in some object store, as a backing file for the actual image. This is a quite flexible setup. No need for iscsi or so.
Oh yes, the thing about a backing file is that all reads are happening on the backing file, until a block is written (also know as cow [copy on write]).

It turned out that the magic is happening while creating an image, not when running it:

$ qemu-img create -f qed -o backing_file=http://..../amaster.iso instance.qed 20G
$ sudo qemu-kvm -hda instance.qed

Sadly we can't test this on stock Fedora, as curl is enabled but currently broken in qemu. Maybe this ain't a bug at all or the bug is already fixed upstream (there are some fresh changes to curl), so this can be tested at some near point in the future.
It is also to note, that backing files also integrates well with libvirt.

Friday, September 23, 2011

Poll, no poll, poll.

While working on gswitcheroo I needed a reliable way to determine if a monitor get's connected to the HDMI port of the discrete card. But monitoring the HDMI port when the corresponding discrete card is powered off, doesn't seem to work.
A temporary solution is to power on the discrete card once and again, to see if a some monitor got connected. airlied point out, that maybe the integrated card is able to detect connected monitors. But in the first trial it didn't really work.

What also didn't work, was monitoring status changes of the discrete (radeon) card using udev (using udevadm monitor).  Time for more investigations.

Monday, September 19, 2011

Zyklisch - gswitcheroo is up and quasi working.


Cycle Track
Tonight I had a bit of time and got gswitcheroo in a usable state.
gswitcherd is launched by systemd and gswitcher is launched gnome-session-manager. All fine.

If gswitcherd detects a connected HDMI port on boot it tries to turn on the discrete card (effectively turning off the integrated). Sadly there is currently a bug (or so) in vgaswitcheroo which prevents the successful switching from one to another card between plymouth and gdm. Maybe this will be fixed at some point - or not be needed at all ...

Another problem is about looking up the HDMI status (to automagically detect what card to use). This is just possible if the discrete card is powered on, but this ain't the case when we are using the integrated card. The current solution is to power on the discrete card once and again, to determine the HDMI status.

Beside all problems gswitcher will notify you about a freshly connected monitor and will ask you to log out (and back in).

Sunday, September 18, 2011

Innendrin - A vala binding for TinyCC

Sunday night, best time to write some lines.
TinyCC (aka TCC) is a small but hyper fast C compiler. Unlike other C compilers, it is meant to be self-relying: you do not need an external assembler or linker because TCC does that for you. 
This vapi allows to call tcc from within vala, a small example is given below. I used it in conjunction with genetic programming.

using TCC;
void main(string[] args)
{
	State s = new State();
	s.add_include_path (args[1] + "/include");
	s.add_include_path ("/usr/include/");
	s.set_lib_path (args[1]);
	s.compile_string  ("""
#include <tcclib.h>
void main(int argc, char** argv) {
	printf("Hello %s\n", argv[0]);
}        
""");
	s.run ({"world."});
}

Monday, September 12, 2011

Rollo - gswitcheroo, a small daemon for vgaswitcheroo.

VGA Port
I'm working on a small library/daemo/client which wrap some functionallity of  vgaswitcheroo, a small kernel feature to handle hybrid graphic setups found in some laptops.

The main intention is to allow the user to switch to the required card
Sometimes this switch is required, because just one of the cards is connected to the external output of the laptop - which can be used to connect a beamer.

The current code can be found at https://gitorious.org/valastuff/gswitcheroo.
daemon and client should be working by now, but the installation bits need some work.

My intention is to add some configuration point to gnome-control-center. A first suggestion was to use the "System information" -> Graphics-Tab.
Any suggestions and early adopters?

Friday, September 9, 2011

EFI + KVM?

To test out the EFI support of some distributions (especially Fedora), I tried to get qemu-kvm to use provide an EFI interface. This can be achieved by calling qemu with the -L switch, to use an alternate EFi bios file (like the one from tianocore: OVMF), instead of the default bios.

To get qemu-kvm up and running, try the following on a recent Fedora 15 setup:

mkdir efiboot

cd efiboot

# Get ovmf, a binary providing the efi interface
mkdir ovmf
cd ovmf
wget "http://downloads.sourceforge.net/project/edk2/OVMF/OVMF-X64-r11337-alpha.zip?r=http%3A%2F%2Fsourceforge.net%2Fapps%2Fmediawiki%2Ftianocore%2Findex.php%3Ftitle%3DOVMF&ts=1315395958&use_mirror=dfn"
unzip OVMF-X64-r11337-alpha.zip

cd ..

# Create a seperate folder with all relevant binaries and replace some of them
mkdir qemu
cd qemu
ln -s /usr/share/qemu/* .
ln -s ../ovmf/OVMF.fd efi.bin
ln -s ../ovmf/CirrusLogic5446.rom vgabios-cirrusefi.bin

cd ..

# Create an image and try the distribution in question ...
qemu-img create -f qed a.img 10G
qemu-kvm -L qemu/ -bios efi.bin -m 1024 -hda a.img \
   -cdrom ../Fedora-16-Alpha-x86_64-DVD.iso
# Expecting this to boot, but after the efi boot manager, the booting after grub (?) stalls ...


It turns out that Fedora won't boot on this qemu-kvm setup, instead Ubuntu worked like a charm - but someone already worked on this a couple of years ago.

The Fedora docs mention that the provided efidisk.img should boot on an EFI based system, but this also did not work as expected. Any hints?

Wednesday, September 7, 2011

Brüken bauen - Using vala code from JavaScript

Police bridge

GObject based libraries can be called - thanks GObject introspection - quite easy from javascript (as well as e.g. python).
As vala builds on gobject, all code generated by vala can be introspected - when compiled with a fine selection of compiler switches.

Let's pretend that we have got a small library written in vala and want to use it from gjs - maybe because the that library is wrapping another non-gobject library or doing some heavy calculations.

To build a introspectable library a good practice is, to just use valac to generate the appropriate c-code and handle the build manually - or by using some build system.
When invoking valac it is important to pass the two both of switches --library and --gir. It is also important to specify the GIR name (--gir) in the format NAME-VERSION.gir whereas the library (--library) name expects just NAME-VERSION.

Build
Up to now it's just theory. The following lines guide you trough this process, step by step (testShared.vala is taken from here):
$ ls
testShared.vala

$ valac --ccode --header=testShared.h \
   --gir=TestShared-0.1.gir \
   --library=TestShared-0.1 \
   --pkg=gio-2.0 testShared.vala

$ ls
TestShared-0.1.gir  TestShared-0.1.vapi
testShared.c testShared.h
testShared.vala

$ gcc -fPIC -shared -o libTestShared.so \
   $(pkg-config --libs --cflags gobject-2.0) \
   testShared.c 

$ ls *.so
libTestShared.so
 

Typelib
After building the library we finally need to build the introspection data using g-ir-compiler (part of gobject-introspection-devel):
$ g-ir-compiler --shared-library=libTestShared.so \
   --output=TestShared-0.1.typelib TestShared-0.1.gir
$ ls *.gir *.typelib
TestShared-0.1.gir
TestShared-0.1.typelib

Testing
To finally test our introspectable data, why use gjs. We import the library using the (gjs specific) "imports.gi" keyword:
const TestShared = imports.gi.TestShared;
print('Square of 42: ' + TestShared.square (42));
On the commandline it looks like this:
$ GI_TYPELIB_PATH=. LD_LIBRARY_PATH=. \
   gjs --command="const TestShared = imports.gi.TestShared; \
   print('Square of 42: ' + TestShared.square (42));"
** (gjs:12175): DEBUG: Command line: gjs
** (gjs:12175): DEBUG: Creating new context to eval console script
Square of 42: 1764
$

Done. We managed to call a library function from gjs using GObject introspection. The creation of the (important) typelib should be included in you favorite build tools, one example using cmake can be found (again) here.

Oone final reminder: Not just vala code can be imported, but all gobject based libraries (e.g. libgtop2 for system informations, clutter for fancy UIs and more)

Is there something I forgot? Tell me :)



Monday, September 5, 2011

Interpretieren und Rechnen - Vala binding for libmatheval.

libmatheval is small library of procedures for evaluating mathematical functions.
The appropriate vapi to use this library from vala can be found around the corner.
The usage of libmatheval is quite easy, here an example:
#!/usr/bin/vala --pkg libmatheval
using matheval;
void main ()
{
    var e = Evaluator.create ("x + y^2");
    print("e.evaluate_x:\t%s = %g\t\t| x = 4\n", 
        e.get_string(), e.evaluate_x (4));
}
More functions calls can be found here.

Klein - Elementary things.

Elementary OS always caught or users attention because of it's design principles, which lead to a very aesthetic appearance (including the gtk elementary theme) and some very nice applications like postler.

Anyhow, this time it got my attention because it's favored programming language seems to be vala. Surprise :)

A part of this effort is also to improve the programming experience by providing an - in loose words - integrated development environment - an editor (scratch + vala plugin) and build system (cmake). Nice.