Tuesday, September 16, 2014

Sabayon radeon open-source driver

If you prefer open source drivers on your setup which became necessary after GDM issue with fglrx follow the steps below.
equo install xf86-video-ati
edit sabayon-grub
nano /etc/default/sabayon-grub
make sure the lines below are removed
console = tty1, quiet splash = **** and vga = ****
edit grub
nano /etc/default/grub
make sure nomodeset is not defined anywhere Regenerate grub.cfg
grub2-mkconfig -o /boot/grub/grub.cfg
Edit and make necessary changes on xorg.conf
nano /etc/X11/xorg.conf
add the following lines
Section "Device" VendorName "ATI" Identifier "X700OS" Driver "radeon" EndSection
Change opengl setting if not yet.
eselect opengl set xorg-x11

Monday, March 10, 2014

Crackling audio with Chrome/Chromium any build any version !

I want to say,  I can not believe this is not butter. This issue has been around for more than 3 years at least and still with the latest versions I am having the same issue over and over again. At least there is a simple but annoying solution.

Start chrome with --audio-buffer-size=2048 option. If you do not want to open terminal every time you open the browser you can add this option to the .desktop shortcut.

$ nano /usr/share/applications/google-chrome.desktop

and add the --audio-buffer-size=2048 to the Exec lines.

Exec=/usr/bin/google-chrome-stable --audio-buffer-size=2048 %U
Exec=/usr/bin/google-chrome-stable --audio-buffer-size=2048
Exec=/usr/bin/google-chrome-stable --audio-buffer-size=2048 --incognito

Do not forget to modify the file again when chrome updates. Actually it has a crackling reminder so you wont forget. I do not understand why do I hate chrome this much but still use it. Oh well ...


Remap the buttons of your remote to use with XBMC/MythTV/Media_Player

Because of the Vestel TV that I purchased, I had an airmouse lying around which I did not have any use for it until today. I decided to use it for XBMC. It turned out to be perfect.

First, test your remote mouse/keyboard/device by plugging in to the computer. If it is USB you can check through lsusb devices. As you can see below, in my case,  the dongle of the remote is recognized by the kernel.

$ lsusb
Bus 002 Device 003: ID 4853:4b66  




You can search for the device in 

$ ls /dev/input/by-id/usb-4853_4b66-event-kbd

Your connected device will probably be have a similar name. Next you need the codes of the buttons that you want to remap. For this purpose we use ir-keytable from v4l-utils package.

$ equo install v4l-utils

then try, 

$ ir-keytable -d /dev/input/by-id/usb-4853_4b66-event-kbd -t

The command above will let you to test the buttons. When you hit buttons on your remote, you will see entries similar to the lines shown below.

1394490580.520636: event type EV_MSC(0x04): scancode = 0xc0041
1394490580.520636: event type EV_KEY(0x01) key_down: KEY_ENTER(0x0001)

The scancode (highlighted as green) is what we are looking for. Write down all the scancodes and their actual purpose on the remote. If the list is long, things can get easily mixed up.

Now we want to match the scancodes with their new purposes. For example I want to assign the scancode 0xc0041 to ENTER key. Open up a file preferably named remap.keys.

$ nano remap.keys

add lines with your scancodes and some explanation for debugging purposes. 

scancode 0xc0041 = KEY_ENTER # Actually it was OK button
scancode 0xc0011 = KEY_SPACE # Actually it was P+ button

If you are looking for the word of a key you can run the command below

$ irrecord -l | grep ENTER

or you can list all keys 

$ irrecord -l

Save the file with your scancodes and it is time for magic. 

$ ir-keytable -d /dev/input/by-id/usb-4853_4b66-event-kbd --write=/path/to/remap.keys

Now you can test and enjoy your perfect remote for XBMC. You have to run this command in every boot so it would be a good idea to add it in your .bashrc.


Here is my remote.keys if you have a similar airmouse.

scancode 0xc0041 = KEY_ENTER # OK            # Select in XBMC
scancode 0xc0196 = KEY_MEDIA # WWW       # Open XBMC
scancode 0xc0040 = KEY_ESC      # MENU       # ESC
scancode 0xc009c = KEY_I             # P+              # Info
scancode 0xc00a0 = KEY_S            # SOURCE  # Shutdown Menu
scancode 0xc009d = KEY_SPACE # P-               # Play/Pause
# 0xc0224 # BACK #back is back nothing changed
# Volume buttons are not changed


Sunday, March 9, 2014

Add a custom systemd service

We will write a startup script for mt-daapd in this section. This way, the music server will start at boot and "restart itself if crashes anytime". I guess I am tarting to like systemd. Anyway here is how to do it.

First create a service.

nano /etc/systemd/system/mt-daapd.service

Copy the lines given below and make changes as necessary

[Unit]
Description=Mt-daapd service

[Service]
PIDFile=/var/run/mt-daapd.pid
ExecStart=/usr/local/sbin/mt-daapd -c /usr/local/mt-daapd-svn-1696/contrib/mt-daapd.conf -P /var/run/mt-daapd.pid

Restart=on-abort

[Install]
WantedBy=multi-user.target

We can test the service by just typing

systemctl start mt-daapd.service

Then check the status of the service

systemctl status mt-daapd.service

If everything works as it should enable it at the boot level. It just creates a symbolic link, nothing fancy.

systemctl enable mt-daapd.service

MT-DAAPD with FLAC and OGG support

Serve your music files to MAC, Windows, Linux, Android and Iphone. Basically you can listen to them from any platform . It is a great little application. We will install it with FLAC and OGG support thus we will not use the repository edition but compile it.

Dependencies 

Check the dependencies before you start

equo install dev-db/sqlite  media-libs/libid3tag media-libs/libvorbis media-libs/flac

Download, Compile, Install

Download mt-daapd

wget http://ftp.momo-i.org/pub/other/mt-daapd-svn-1696.tar.gz

or you can download from here

https://drive.google.com/file/d/0ByyLo2VHCtYpQ01ZYVF2VE5MTk0/edit?usp=sharing

then open the tar file and build

tar -xvzf mt-daapd-svn-1696.tar.gz
cd mt-daapd-svn-1696/
./configure --enable-flac --enable-ogg --enable-sqlite3
make
make install

Configuration File

Edit the configuration file

nano /usr/local/mt-daapd-svn-1696/contrib/mt-daapd.conf 

Do not forget to change database to sqlite3 and change passwords in the configuration file.

You can start the server by showing the path to the config

 /usr/local/sbin/mt-daapd -c /usr/local/mt-daapd-svn-1696/contrib/mt-daapd.conf -P /var/run/mt-daapd.pid -f

The -f in the end runs it in the foreground so you can see the errors. After clearing all the warnings and errors you can remove the -f and read my next post about writing a custom service for mt-daapd to start at boot.

You can check the web interface to check if everything works as expected.
http://localhost:3689/

Download TV shows automatically (Flexget + ShowRSS + Yahoo Pipes + Transmission)

In this tutorial, we are going to setup a  system which will download the new episodes of the shows we wanted. We will need Flexget, Transmission installed in our system and a ShowRSS and YahooPipes accounts.

Transmission

Install Transmission. For sabayon you can simply

equo install transmission-gtk 

Setup the transmission web interface. Put a username and password for the web interface and that is it. You can either start transmission as a daemon or as you login autostart. I prefer it to start when I login (to gnome) as a user and, I have autologin for the specific user. Add transmission to the gnome startup by 

"ALT+F2" -> gnome-session-properties. 

This is just a preference but daemon mode is better if you ask me. You can go either route. 

Flexget

We will start with installing Flexget. You have many directions to go at this point but I will cover only the installation without root privileges. It is almost directly from their website but in a compact way.

I assume you have python and virtualenv installed in your system.

virtualenv ~/flexget/
cd ~/flexget
bin/pip install flexget

Now create a very simple task which will download all the torrent files from the rss and put in a folder.

nano ~/.flexget/config.yml

We will generate this rss address using yahoo pipes which is I think the most useful web service I have ever seen. Just make sure that download section in this configuration is the check folder for new torrents folder of transmission. Basically we are sending all the torrent files to transmission check folder.

tasks:
  download:
    rss: http://pipes.yahoo.com/pipes/pipe.info?_id=91234400ce80xxxxxxxxxxxxxxx
    accept_all: yes
    download: /home/bla/bla/Torrent_check_folder/



Then you can run flexget as a deamon or cronjob. In this case I was using cron but the daemon mode just works. You can add the daemon to startup programs

"ALT+F2" -> gnome-session-properties. 

~/flexget/bin/flexget daemon start

ShowRss

Simple. Open up a web browser and go to 

http://showrss.karmorra.info/

open an account and select the shows you want to download. It will generate an RSS address for you that you can test if it is what you wanted. Write down your RSS address for now, we will use it with Yahoo pipes.

Yahoo Pipes

The best service I have ever seen. Basically you can do whatever you want with this service. What I do is I have multiple RSS feeds from torrent servers, I compare, search strings, combine them etc then in the end generate a filtered one link. This one link only includes the torrents I wanted at the specific quality. Use ShowRSS link in here, if you want to combine another torrent server add that as well and generate your RSS address.

Use this yahoo pipes RSS address at Flexget configuration given above.

All set. You have a full automatic torrent machine which can be controlled online.
Bon appetit.

PS. There are many ways to do this job. Someone may argue with me that this Pipes is unnecessary as flexget can combine and filter RSS too. However, flexget runs on my computer and I do not want to put stress on my guys if I can get it done free.


References
1) http://flexget.com/
2) http://www.transmissionbt.com/
3) http://showrss.karmorra.info/‎
4) http://pipes.yahoo.com

Mount USB HDD by uuid on boot automatically

To find the UUID of the external hdd

ls -lah /dev/disk/by-uuid/

You will find the UUID of the drive by that command. Then add a similar line like given below by changing the UUID of your partition to the /etc/fstab

nano /etc/fstab

UUID=4886310c-6381-4dcfe2eb4c85d /home/USER/MOUNT/LOCATION   ext3  defaults    0 0

Also to hide the icons of the mounted drives from Desktop, from dconf

org.gnome.nautilus.desktop 
uncheck "volumes_visible"

Create custom shortcut in Gnome Shell

You can create a custom shortcut in Gnome Shell or on your Desktop as described below. Replace uppercase parts as necessary.

If you want to add the shortcut in Apps

cd /home/USER_DIRECTORY/.local/share/applications

or if you want it on your Desktop

cd ~/Desktop

then;

nano APPNAME.desktop

add the lines below

[Desktop Entry]
Version=1.0
Encoding=UTF-8
Name=My custom App
Comment=Some comments pls.
Exec=/path/to/executable
Icon=/path/to/icon
Type=Application
Terminal=False
Categories=Development;Or;Something;Else;

Now you should be able to see your shortcut with logo.


Compile XBMC with crystalhd support

Some distros offer XBMC binaries build without crystalhd support thus we have to do it on our own. Here is a copy paste solution for you.

equo install cmake app-arch/xz-utils automake swig icedtea

Download XBMC from git repository

cd /usr/local
git clone git://github.com/xbmc/xbmc.git
git checkout Eden
then,

cd xbmc

Install dependencies in your distribution, or install the xbmc from the repository which will pull all (hopefully)  dependencies. I needed yasm only.

equo install yasm

As usual,

./bootstrap

Make changes in the configuration below as you please

./configure --enable-crystalhd --enable-vaapi --enable-openmax--disable-joystick --enable-rtmp --enable-libmp3lame --enable-airplay --enable-libbluray --enable-libvorbisenc --enable-pulse --enable-udev --disable-goom --enable-neon --enable-vaapi --disable-hal --disable-ccache --disable-optimizations --enable-gl --disable-debug --enable-mid --disable-webserver --disable-pvr --disable-mysql 

make -j4


You can either;

make install

or you can create a shortcut with the path and use like that without installing.
Bon appetit.


CrystalHD drivers for Linux

Preperation:
Install the required build tools first.

equo install autoconf


1) Get the source. Get the driver source code from the git repository.

git clone git://git.linuxtv.org/jarod/crystalhd.git

2) Fix the source. You can apply it by going into the main crystalhd source directory and doing

Download the patch from
https://drive.google.com/file/d/0ByyLo2VHCtYpOC1rT0d0NFZ1VHc/edit?usp=sharing
patch -p0 < devinitFix.patch

3) Compile driver, install libraries, and load driver.

Use make command to compile driver. If you have multiple core processor then use the "-j2" or "-j4" option (2 or 4 is the number of cores). This will speed up the make process.

cd crystalhd/driver/linux
autoconf
./configure
make -j2
sudo make install

Install the libraries.

cd ../../linux_lib/libcrystalhd/
make -j2
sudo make install

4) Load the driver.

sudo modprobe crystalhd

5) Make it autoload at startup

nano /etc/modules-load.d/crystalhd.conf 

and add

# Load crystalhd.ko at boot
crystalhd

6) Reboot your system, then check if 'crystalhd' is listed in the output of the following commands.

lsmod
dmesg | grep crystalhd

7) Although the latest flash (11.1.102.55-1) supports crystalhd out of the box it won't be enabled until you edit /etc/adobe/mms.cfg so that it has:

EnableLinuxHWVideoDecode=1
OverrideGPUValidation=true


Install ATI drivers for Sabayon (HD5000 and newer ATI cards)

Just follow the command and it will make sense. I hope :) I suggest you to kill X (if you are upgrading) from TTY and follow the rest.

equo update --force
equo remove ati-drivers
echo "blacklist radeon" >> /etc/modprobe.d/blacklist.conf

Edit /etc/default/grub

GRUB_CMDLINE_LINUX="nomodeset" 

Remove the old drivers. Do not worry you will still get the console if something goes wrong.

equo remove  xf86-video-ati
equo remove --configfiles xf86-video-ati

equo remove linux-sabayon
equo remove sabayon-sources
equo remove ati-drivers

equo install =sys-kernel/linux-sabayon-3.13.5
equo install =sys-kernel/sabayon-sources-3.13.5
equo install =x11-drivers/ati-drivers-13.12#3.13.0-sabayon amdcccle

eselect bzimage set kernel-genkernel-x86_64-3.13.0-sabayon
eselect kernel set linux-3.13.0-sabayon
eselect opencl set amd
eselect opengl set ati

For the initial configuration of the drivers

/opt/bin/aticonfig --initial

or to update your already decent xorg.conf if you like it, but are switching to the proprietary drivers: 

/opt/bin/aticonfig --initial --input=/etc/X11/xorg.conf

Then reboot, and open amdcccle for configuration. 

/opt/bin/amdcccle

Reduce the stress on SSD

If you have an SSD, you better do some adjustments to increase the lifetime of your harddrive.

1) Mounting your partitions with trim support.

/dev/sda1       /               ext4                  defaults,relatime,noatime,discard            0 1 
/dev/sda2       /               ext4                  defaults,relatime,noatime,discard            0 1 


2) Use your ram for temp files.

tmpfs             /tmp        tmpfs                  noatime,nodiratime,size=6G           0 0 


 3) If you are running gentoo (sabayon) on desktop, many programs, using X windows systems (like: chromium, firefox, skype) are making frequent disk I/O every few seconds to cache. Default cache dir is ~/.cache, which is on hard drive.

Edit 
/etc/env.d/30xdg-data-local and add line: 
XDG_CACHE_HOME="/tmp/.cache" 

Reboot

TEST TRIM

Now it is time to test trim on SSD. As root,

su
dd if=/dev/urandom of=tempfile count=100 bs=512k oflag=direct

Check the starting LBA address of the file:

hdparm --fibmap tempfile

Read the first address of the file, note that you need to put the first LBA in place of [ADDRESS]:

hdparm --read-sector [ADDRESS] /dev/sdX

Now remove the file and synchronize the filesystem:

rm tempfile
sync

Use the same command to re-read the LBA:

hdparm --read-sector [ADDRESS] /dev/sdX

If TRIM is properly working the result of the last command should be a bunch of zeros. If the output is not zeros, then something could be wrong with your kernel/Ext4 configuration and TRIM may not be working.

References
1) https://wiki.gentoo.org/wiki/SSD

Vestel PF9090 EDID resolution fix for Linux

First is first. I am not to be liable for direct, indirect or consequential damages or for any loss of revenue.
If you have just installed Linux on your htpc and your resolution is way off, you may suspect from many things. In my case, it was the EDID information coming from the TV. The resolution was there as 1920x1080 but the dimensions of the 47" tv was recognized as 1".

So how do we fix it. Get ready for a multi platform journey. Check the recognized dimensions and resolution with
xrandr -q
or
xdpyinfo
First we need to get the edid file from the TV. I may suggest two routes at this point.

 1) Use your Xorg log to find the EDID information. It would be similar to the hex strings given below. Clean the info in the beginning of each line, make it a single line hex info and convert it to a binary string. I had problems doing this thus I followed the second route.

 [ 14.784] (II) fglrx(0): 00ffffffffffff0058b3003700000000 
 [ 14.784] (II) fglrx(0): 0117010380683c780a6837a454489a25
 [ 14.784] (II) fglrx(0): 0f4a4c3fef8001010101010101010101
 [ 14.784] (II) fglrx(0): 010101010101011d8018711c1620582c
 [ 14.784] (II) fglrx(0): 250010584200009e011d007251d01e20
 [ 14.784] (II) fglrx(0): 6e28550010584200001e000000fc0034
 [ 14.784] (II) fglrx(0): 37575f4c43445f54560a2020000000fd
 [ 14.784] (II) fglrx(0): 00313d0f2e08000a2020202020200137 

 2) Nvidia can download EDID file in binary format. Just connect a laptop with an Nvidia graphics card to the TV, open up the Nvidia driver menu that you make adjustments and download the EDID binary file. No hassle. Now you have the EDID binary file. Next you need to make some fixes on the file. There are two great Windoz programs dedicated to this work. I wish there were Linux alternatives but all you can get is read-edid and hex editor for this job which requires too much time to waste. The windows programs for this job is;
EDID_Converter.exe
and
Phoenix.exe
Change the binary EDID file to Phoenix format with EDID_converter as Phoenix cannot read binary.

Then open the converted EDID file on Phoenix. You can see all the information from EDID, make the changes as you wish. For my case, 47"(~120 cm) inch tv with 16:9 aspect ratio should have dimensions in cm similar to this.
sqrt((16*x)**2 + (9*x)**2)=120
x = 120/ sqrt((16)**2 + (9)**2) = 6.5368
Height = 9*x = 58.83 cm
Width = 16*x = 104.590 cm
You can round off them as you wish or adjust for your TV size and here is the calculation to do that.

Next thing, using Phoenix and this values, edit your EDID file and save (You can change anything about your TV so just be careful, you have been warned).  Save the file in Phoenix format and again use the EDID_converter to convert the file back to binary. Almost there.

Now we have a new, modified EDID file. You can just send it(re-program) to TV if you can and make everything permanent but this is not what we are going to do as I do not want to deal with it.

For ati catalyst drivers in linux, you can use this EDID file instead of the one sent by TV. So where are we gonna put this file and what should be the name. First open TTY1 screen (CTRL+ALT+1) and kill X (systemctl stop gdm). Then trace catalyst.
systemctl stop gdm equo install strace strace -e "trace=open" X -retro 2> xtrace.log
after the strace command return back to TTY1 (CTRL+ALT+1) and kill the X (CTRL+C). Look at the xtrace.log file that you have just created. You should see something like
open("/proc/ati/major", O_RDONLY) = 15 open("/dev/ati/card0", O_RDWR) = 15 open("/sys/bus/pci/devices/0000:01:00.0/config", O_RDONLY|O_CLOEXEC) = 16 open("/sys/bus/pci/devices/0000:01:00.0/config", O_WRONLY|O_CLOEXEC) = 16 open("/sys/bus/pci/devices/0000:01:00.0/resource2", O_RDWR|O_CLOEXEC) = 16 open("/usr/lib/xorg/modules/libfb.so", O_RDONLY|O_CLOEXEC) = 16 open("/etc/ati/amdpcsdb", O_WRONLY|O_CREAT|O_TRUNC, 0666) = 16 open("/etc/ati/DFP3.edid", O_RDONLY) = -1 ENOENT (No such file or directory) open("/etc/ati/dfp3.edid", O_RDONLY) = -1 ENOENT (No such file or directory) open("/etc/ati/DFP3.edid", O_RDONLY) = -1 ENOENT (No such file or directory) open("/etc/ati/dfp3.edid", O_RDONLY) = -1 ENOENT (No such file or directory) open("/proc/mtrr", O_RDWR) = 16 Loading extension ATIFGLRXDRI open("/proc/ati/major", O_RDONLY) = 16
in my case it was DFP2 (the paste above is taken from reference 1).

So put the modified EDID file to /etc/ati/DFP2.edid. To be on the safe side

cp modifiedEDID.bin /etc/ati/DFP1.edid 
cp modifiedEDID.bin /etc/ati/DFP2.edid 
cp modifiedEDID.bin /etc/ati/DFP3.edid 
cp modifiedEDID.bin /etc/ati/DFP4.edid 

That is it, reboot or restart X to see a nice resolution.

Edit: HDMI sound issues

I recognized that the conversion and phoenix just deal with the video section of the .edid files. If you use the route described above you will probably miss the sound through HDMI.

The solution for that I found was Monitor Asset Manager (4). I used the original (binary) version of edid file that I dumped from the TV with this program and generated the monitor.inf file. Then, through the program, I used the modded (from Phoenix) dat file and combined with the monitor.inf through the program.

Open up Monitor Asset Program
File>Open>Modded_Edid.dat
File>Edit>Append CEA extension Block>Select the inf file you generated
Append save a new binary file and you are done.

I suspect you can do everything described here with just the Monitor Asset Manager without the need of other Phoenix and edid file converter but I am not going to dig into that right now. 

I tried and got back my HDMI output, it is your turn now :)

References
1)http://hotcashew.com/2013/08/fixing-invalid-edid-in-linux-wit-fglrx/
2)http://sathyasays.com/2008/10/26/how-to-tackle-screen-resolution-problems-in-linux/
3)http://linuxtidbits.wordpress.com/2011/12/22/display-size-dpi-and-text-size-an-interesting-diy/
4)http://www.entechtaiwan.com/util/moninfo.shtm