(2014-07-09) N900 - How to Set it up in 2014 plus an all in one FM Transmitter script

Is the N900 still relevant today? Maybe; maybe not. But other than the K750i (of which I've gone through 3 or 4 in a 5 year period; due to theft and dropping it in really bad places like the toilet), it's my most memorable phone.

The UK firmware has dissapeared from Nokia's site. You can download the UK PR 1.3 (I don't have 1.3.1) from my backups here: https://edgley.org/n900/RX-51_2009SE_20.2010.36-2.203.1_PR_COMBINED_203_ARM.bin.gz

The FM Transmission stuff is at the bottom of the post (under the "Update:" tag).

There isn't that much relevant information today about the N900; I'd imagine because it's 6 years old. But Maemo, the default OS for the N900 (and several other devices), does still have an active community. And with a little bit of help from their forums and wiki, I've come up with a pretty decent solution that works for me.

One of the key things I really wanted to do was repartition the eMMC (the internal storage). By default the N900 has an unusal layout; with a 256MB NAND storage for the root partition, 2GB for /home, /opt and /home/opt, 27GB for /home/user/MyDocs formatted as VFAT and 768MB of SWAP. Any external memory cards also has to be formatted as FAT32 for it to be recognised by the Camera / Media Player / File Manager applications (it still works fine as EXT3/4 for all other intents and purposes though).

I'm sure this works fine for most casual users, but who really wants a 27GB VFAT partition?

So, after getting myself reaquainted with the interface and quirks, I took a look at repartitioning. The internal NAND obviously can't be changed, so you are stuck with 256MB as /. However, you can create as many extra partitions as you like for /var, /usr, /opt etc etc.

I decided to keep the same layout mostly, except the 27GB VFAT is reduced to 4GB, the 2GB /opt ext3 partition is increased to 20GB and the SWAP was increased to around 5GB (I just used everything that was left).

Disclaimer: Backup anything and everything you need before doing this. I'm not going to suggest it later on and will assume you are intelligent enough to know to do this and / or you don't care about the data

So; to do this, you need to install "backupmenu" from the repos on to the phone ( http://maemo.org/packages/view/backupmenu/ ). If the phone is booted into the OS, the internal memory is not exposed via USB. I wont go in to detail on how to install applications, you should hopefully be able to do that already.

Once installed, reboot the phone and open the keyboard while o nthe Nokia splash screen. Select the "backup menu" option from the main menu and then press "w" to enable USB access. Plug the USB cable in to your computer and you should be able to access the partitions.

Open up your favourite partitioning tool (be it gparted, fdisk or whatever) and get to work.

The primary points to note are that you should align to MB and not blocks or cylinders; you should also make sure that at least 512 bytes are free at the start of the disk. The most important thing though is to make the VFAT partition the first partition in the table. It doesn't have to be at the start of the disk (though if you are not sure, it's the easiest way).

So, the final partitions would look like this:

----		free space	512B
partition 1	VFAT		4GB
partition 2	linux (ext3)	20GB
partition 3	linux-swap	5~GB

That's the simplelist solution and should work for pretty much everyone. Feel free to change the ext3 partition around and create news ones etc. Partition 3 should be swap just for ease on first setup (you will run into "out of memory" issues if there is no swap) and the first ext3 partition will be used as /opt so make sure it's at least 2GB (to match the original layout).

Once the partitions have been written, unplug the phone and turn it off.

Next, we need to install the latest Nokia binary. You can get this from here: http://wiki.maemo.org/Maemo_UK_variant_firmware -- the non UK variant page doesn't seem to load (just 404's). You can then follow the instructions to flash your phone on your system on this page: http://wiki.maemo.org/Updating_the_firmware.

Firmware also avaliable here https://edgley.org/n900/RX-51_2009SE_20.2010.36-2.203.1_PR_COMBINED_203_ARM.bin.gz

You can also obtain the flasher from here https://edgley.org/n900/flasher-3.5.deb.gz -- I haven't repackaged it; but you can just extract usr/bin/flasher-3.5 and run it manually if you want.

Once done and you're booted in to your system, you'll want to install 'sudser' from the Application Manager.

After enduring the pain of the standard Application Manager, you'll want to update to the Community SSU; this doesn't require a reflash but the instructions are a bit convoluted. You'll want to follow them pretty closely here: http://wiki.maemo.org/Community_SSU#Installation -- the cssu-thumb extra may be worth doing if you are up to it.

The final important part it to install the power kernel by running the following on your phones terminal:

sudo apt-get install kernel-power-settings linux-kernel-power-headers

That should be it; a final reboot should put you onto the better kernel (has a few nice fixes for battery longevity and overclocking ability).

Everything after this is optional and will change depending on your needs. The commands listed worked for me and I'm not going to take responsibility for what happens to your phone.

I wasn't done after all of the above though. I still had to get the system to how I like it. First things first, lets install some more applications and set up our passwords:

sudo su
apt-get install bash4 vim htop openssh-client openssh-server
passwd user

The openssh-server will prompt to change the root password by itself, and the passwd user command will allow you to change the SSH password for user@.

Once done, lets set up our hostname and symlink bash to how we'd expect it to run (ie #!/bin/bash):

echo "flintlock" > /etc/hostname
hostname flintlock
ln -s /bin/bash4 /bin/bash
mkdir /usr/share/applications/hildon.old

The mkdir command easily allows you to remove menu items without actually deleting files (incase you want them back at some point).

I was then pretty vicious with the menu item removal:

mv {browser,camera-ui,chess_startup,filemanager,hildon-application-manager,htop,maemoblocks,mahjong_startup,nokia-maps,osso-backup,osso_calculator,osso_lmarbles,osso_notes,osso_pdfviewer,osso_rss_feed_reader,osso_sketch,ovi,user-guide,vim,worldclock,mediaplayer,calendar}.desktop ../hildon.old/

Now comes the fun bit; removing all the crap:

apt-get remove adobe-flashplayer amazon-installer ap-installer as-config-applet-0 as-daemon-0 camel-as-provider-0 camelisync ezitext-czech ezitext-danish ezitext-dutch ezitext-* \
facebook-installer foreca-installer google-search-widget hildon-welcome hildon-welcome-default-logo libezitext modest-nokiamessaging-plugin-l10n-* modest-providers-data \ 
nokiamessaging osso-startup-wizard osso-tutorial-l10n-* ovi-promotion-widget rtcom-accounts-plugin-gtalk rtcom-accounts-plugin-nokiachat sharing-rtcom sharing-service-flickr \
sharing-service-ovi skyhost-bin skyhost-vengine status-area-applet-activesync-0 telepathy-spirit tutorial-home-applet dtg-installer osso-accounts-plugin-skype rtcom-abook-skype-plugin

Note that this will reduce functionality of the email client and remove sharing options from images etc.

And we replace them with just a handful of new applications. First we need to configure the repos:

## Nokia Main
deb https://downloads.maemo.nokia.com/fremantle/ssu/apps/ ./  
deb https://downloads.maemo.nokia.com/fremantle/ssu/002 ./  
deb https://downloads.maemo.nokia.com/fremantle1.2/ovi/ ./

## Fremantle Extras
deb http://repository.maemo.org/extras/ fremantle free non-free
deb-src http://repository.maemo.org/extras/ fremantle free

## Fremantle Extras-Testing
deb http://repository.maemo.org/extras-testing/ fremantle free non-free
deb-src http://repository.maemo.org/extras-testing/ fremantle free

## Fremantle Extras-Devel
deb http://repository.maemo.org/extras-devel/ fremantle free non-free
deb-src http://repository.maemo.org/extras-devel/ fremantle free

## Community SSU (testing)
deb http://repository.maemo.org/community-testing/ fremantle free non-free
deb-src http://repository.maemo.org/community-testing/ fremantle free non-free

## Ruskies
deb https://repo.codemages.net/ opt/" > /etc/apt/sources.list.d/repos.list
mv /etc/apt/sources.list.d/hildon-application-manager.list /etc/apt/sources.list.d/hildon-application-manager.list.disabled

apt-get update
apt-get upgrade

Now we can install what we want:

apt-get install less rsync binutils2.22 busybox-power dnsutils host whois qcpufreq fennec tmux screen mplayer backupmenu openvpn

I then configured bash, vim and tmux.

/home/user/.profile:

case $- in
	*i*) exec bash $@ ;;
esac

/home/user/.bashrc:

# ~/.bashrc
[[ $- != *i* ]] && return
umask 022
clear
cd ~
export EDITOR="vim -p"
export LANG="en_GB.UTF-8"
export DISPLAY=":0"
export PATH="/bin:/usr/bin:~/bin"
export HISTFILE="/dev/null"
export HISTCONTROL="ignoreboth"
export LESSHISTFILE="/dev/null"
export LESS_TERMCAP_mb=$'\E[01;31m'
export LESS_TERMCAP_md=$'\E[01;31m'
export LESS_TERMCAP_me=$'\E[0m'
export LESS_TERMCAP_se=$'\E[0m'
export LESS_TERMCAP_so=$'\E[01;44;33m'
export LESS_TERMCAP_ue=$'\E[0m'
export LESS_TERMCAP_us=$'\E[01;32m'

alias l='ls -hl'
alias ll='ls -hla'
alias grep='grep'
alias vim='vim -p'
alias less='less -R'
alias ..='cd ..'
alias ~='cd ~'

PS1="[\[\e[0;34m\]\W\[\033[0m\]]$ "

/home/user/.vimrc:

set number                      " line numbering enabled by default
set encoding=utf-8              " unicode support
set fileencodings=utf-8
set fileformats=unix,dos,mac    " support all file formats in this order
set backspace=indent,eol,start  " fix backspace issues
filetype plugin indent on       " file type specific indenting

" status bar text
set statusline=%F%m%r%h%w\ [%l,%c]\ [%L,%p%%]

" colours
set background=dark
colorscheme koehler
highlight clear SignColumn
hi StatusLine ctermbg=240 ctermfg=11
hi TabLine ctermbg=black guibg=black
hi TabLineFill ctermbg=black guibg=black
hi TabLineSel ctermbg=darkgray guibg=darkgray ctermfg=lightblue guifg=lightblue

" keybindings
" toggle line numbers with F12
map <F12> :set number!<BAR>:set number?<CR>
" toggle line warpping with F10
map <F10> :set wrap!<BAR>:set wrap?<CR>
" select all ctrl+a
map <C-a> ggVGG
" new tab ctrl+t
map <C-t> :tabnew<CR>
" next tab
map <C-l> :tabn<CR>
" previous tab
map <C-h> :tabp<CR>

" command bindings
:command WQ wq
:command Wq wq
:command W w
:command Q q

/home/user/.tmux.conf:

# use 256 term for pretty colors
set -g default-terminal "screen-256color"

# increase scroll-back history
set -g history-limit 1000

# use vim key bindings
setw -g mode-keys vi

# disable mouse
setw -g mode-mouse off

# decrease command delay (increases vim responsiveness)
set -sg escape-time 1

# increase repeat time for repeatable commands
set -g repeat-time 1000

# start window index at 1
set -g base-index 1

# start pane index at 1
setw -g pane-base-index 1

# highlight window when it has new activity
setw -g monitor-activity on
set -g visual-activity on

# re-number windows when one is closed
set -g renumber-windows on

# enable UTF-8 support in status bar
set -g status-utf8 on

# set refresh interval for status bar
set -g status-interval 30

# center the status bar
set -g status-justify left

# show session, window, pane in left status bar
set -g status-left-length 40
set -g status-left '#[fg=green]#S#[fg=white] #I:#P#[default]'

# show hostname, date, time, and battery in right status bar
set-option -g status-right '#[fg=green]#H#[default] %m/%d/%y %H:%M'

# color status bar
set -g status-bg colour235
set -g status-fg white

# highlight current window
set-window-option -g window-status-current-fg black
set-window-option -g window-status-current-bg green

# set color of active pane
set -g pane-border-fg colour235
set -g pane-border-bg black
set -g pane-active-border-fg green
set -g pane-active-border-bg black

# force a reload of the config file
unbind r
bind r source-file ~/.tmux.conf \; display "Reloaded!"

# prefix
unbind C-b
set -g prefix C-f
bind C-f send-prefix

You can then close X-Terminal and restart to see the new changes -- it works best with white on black colours set up in X-Terminal itself.

Finally, I created a file called "system-tweaks" in my home directory with the following contents:

#!/bin/bash

## If you do not understand what these values are changing, do not modify them.
## If you have any worries about stability, performance, battery etc. over the stock n900, do not run this script

(( UID != 0 )) && echo "You need to be root to run this script!" && exit

echo "Tweaking system config for better performance -- battery life may be affected..."

## eMMC / Paging tweaks
echo 30 > /proc/sys/vm/swappiness
echo 0 > /proc/sys/vm/page-cluster
echo 1 > /proc/sys/vm/oom_kill_allocating_task
echo 1 > /proc/sys/vm/laptop_mode

## RAM tweaks
echo 0 > /proc/sys/vm/dirty_expire_centisecs
echo 0 > /proc/sys/vm/dirty_writeback_centisecs
echo 60 > /proc/sys/vm/dirty_background_ratio
echo 90 > /proc/sys/vm/dirty_ratio

## CPU tweaks
echo 50 > /sys/devices/system/cpu/cpu0/cpufreq/ondemand/up_threshold 
echo 150000 > /sys/devices/system/cpu/cpu0/cpufreq/ondemand/sampling_rate
echo 8 > /proc/sys/kernel/pty/max
echo 1024 > /proc/sys/kernel/threads-max
echo 8192 > /proc/sys/fs/file-max
echo 100 > /proc/sys/vm/swappiness
echo 5 > /proc/sys/vm/page-cluster
echo 500 > /proc/sys/vm/dirty_expire_centisecs
echo 65536 > /proc/sys/net/core/rmem_default
echo 16384 > /proc/sys/net/core/wmem_default

## Kernel tweaks
echo 0 > /proc/sys/kernel/sysrq
echo "/what/me/worry" > /proc/sys/kernel/core_pattern
echo 1 > /proc/sys/kernel/panic
echo 1 > /proc/sys/kernel/panic_on_oops

## Network tweaks
echo 0 > /proc/sys/net/ipv4/tcp_timestamps
echo 1 > /proc/sys/net/ipv4/tcp_no_metrics_save

echo "Done!"

It should be fairly self explanitory, but these values are primarily for how I use the phone, if you find it's not running how you like it, you'll want to look up each of the variables.

And that should be it! Your N900 should now be running much snappier and has the ability to be a fully fledged Linux machine (I'm even running nginx on it)!

If you have any issues; the Maemo forums are a good place to go: http://talk.maemo.org/

Update:

Something you may not realise (and I didn't really appeciate it when I first realised) is the N900 has an FM transmitter. That means you can play all sounds via your stereo system (primarily used in cars) to play your music. This is actually a really awesome solution for me as I have a stock VW Bose stereo with no USB or AUX ports (well, it probably has one on the back, but I can't be bothered to take my dash apart for that). I'm aware this is not new technology and people have used all sorts of adapters for their phones over the years. However, the N900 has it built in. No sketchy third party adapters.

I made a nice little script that will turn the transmitter on, setup a station name / description, boost the signal power (to a safe level) and play my music. If you followed the above instructions, you should have everything needed to run this script. Just make sure you *don't* run it as root.

/home/user/bin/fmt:

#!/bin/bash
MEDIA_DIR="/media/mmc1/music"           ## Directory to play from
STATION_NAME="N900"                     ## Name of the station
STATION_DESC="Your Library"             ## Description of the station
STATION_FREQ="107900"                   ## Frequency (in KHz) to transmit on
STATION_BOST="118"                      ## Power level to boost transmitter to

## Check we are not being run as root
[[ ${UID} == 0 ]] && echo "This script canot be run as root!" && exit

## Setup
echo "Starting '${STATION_NAME} - ${STATION_DESC}' on '${STATION_FREQ}'..."
sudo fmtx_client -s "${STATION_NAME}" -t "${STATION_DESC}" -p1 &>/dev/null
echo "Transmitter active."
sudo su -c "echo ${STATION_BOST} > /sys/class/i2c-adapter/i2c-2/2-0063/power_level"
echo "Transmitter strength boosted to '${STATION_BOST}'"

## Get music files to play
echo "Opening library '${MEDIA_DIR}'..."
cd ${MEDIA_DIR}
for SONG in *; do
	[[ ${SONG:(-3)} != "mp3" ]] && continue
	TITLE=${SONG:0:$(( ${#SONG} - 4 ))}
	echo "Playing ${TITLE}..."
	sudo fmtx_client -s "${TITLE}" &>/dev/null
	mplayer "${MEDIA_DIR}/${SONG}" &>/dev/null
done
echo "Library contains no more items. Stopping..."
sudo fmtx_client -p0 &>/dev/null
echo "FM Transmission closed."
echo "Press any key to quit..."
read -n 1 DUMMY

The media directory should contain all your mp3's, don't use sub folders (for now). 118 for the power boost is deemed "safe" and works okay for me. You may not need to change this. I haven't yet tested the station name change when the song changes, but I found that the station updates every 20 or so seconds on my head unit anyway so I can't see why it wouldn't work. It also gives a nice non-verbose output to the console. I'll probably make it a bit more advanced in the future, with shuffle and prevent it from stopping until a sigterm is intercepted (or something).

Also, if you want to run this from a menu item, you can create the .desktop file like this:

/usr/share/applications/hildon/fmt.desktop:

[Desktop Entry]
Encoding=UTF-8
Name=FMT
GenericName=FM Transmitter App
Exec=osso-xterm "/home/user/bin/fmt"
Icon=terminal
X-Osso-Type=application/x-executable
X-HildonDesk-ShowInToolbar=false
Terminal=true
Type=Application
StartupNotify=true

It has the standard X-Term icon, but that can be changed pretty easily.