flashing openmoko gta-02 with leo2moko firmware

There was an announcement in openmoko community mailing list, called First small steps towards free GSM firmware.

I am very pleased to announce that after many years of searching, I have finally found a copy of TI’s firmware deliverable package for their Leonardo development board, i.e., for their Calypso/Iota/Rita chipset reference platform. It is the package which TI must have given to all of their chipset customers including Nokia, Motorola, Compal, FIC/Openmoko, LG, BenQ and many others, and which was used by all of these companies as the starting point for making their unique proprietary firmwares.

The news are, we don’t only have a firmware source, which can be flashed(though it may be illegal in some countries) but we have also completely free and legal loader tools for flashing that firmware. Before, openmoko users had to use proprietary TI tool for that.

So, I decided to try, and here are my notes on how to build and install leo2moko firmware.

Instead of dealing with crosscompilers, I prefer to build the firmware and loader tools right on device. I use SHR distribution on my GTA-02 Openmoko Neo Freerunner.

==install compiler and dev tools on openmoko==

opkg install gcc
opkg install gcc-symlinks
opkg install libc6-dev
opkg install binutils
opkg install make 
opkg install coreutils

It is good to sync time before building:

/etc/init.d/fsotdld restart

or in newer distributions

systemctl restart fsotdld.service

download the flasher source:

wget ftp://ftp.ifctf.org/pub/GSM/FreeCalypso/loadtools-r1.tar.bz2

Unpack

mkdir loadtools
cd loadtools

tar jxvf ../loadtools-r1.tar.bz2

edit makefile, as suggested in readme, set CFLAGS to

CFLAGS= -O2 -march=armv4t -mtune=arm920t -DGTA0x_AP_BUILD

and

EXTRA_OBJ=gtapower.o

then make it

make
make install

these three binaries are now installed in /usr/local/bin

fc-iram fc-loadtool fc-xram

==build firmware==
skip this step if you want to flash already precompiled firmware

unfortunately it’s impossible to build the firmware with free compiler yet, so we need to use windows only tools from TI. Fortunately, tools are possible to run with wine under GNU/Linux box. The environment heavily relies on traditional Unix tools, ported to windows. It would be much easier to deal just with those tools natively.

So, get these files:

ftp://ftp.ifctf.org/pub/GSM/FreeCalypso/leo2moko-r1.tar.xz – the source
ftp://ftp.ifctf.org/pub/GSM/TI_src/wine/installed-env.tar.xz – build tools
wget ftp://ftp.ifctf.org/pub/GSM/TI_src/wine/nowhine.c

gcc -o nowhine nowhine.c
cp nowhine /usr/local/bin

nowhine is a simple utility which strips unnecessary whining messages from whine. you can use it as wine wrapper.

There is a build script, you will find when unpack tarballs. It will run build process and compile the firmware.

==already precompiled firmware==
wget ftp://ftp.ifctf.org/pub/GSM/FreeCalypso/leo2moko-r1-bin.tar.bz2 — already built firmware.

==flashing==

need to kill some daemons running in the openmoko, before flashing:

killall fsodeviced
killall fsoaudiod
killall fsousaged
killall fsodatad
killall fsonetworkd
killall fsogsmd
killall phonefsod
killall phoneuid
killall frameworkd
s3c24xx-gpio b7=0

fc-loadtool -h gta02 /dev/ttySAC0

You should see a bunch of messages followed by a loadtool> prompt.

when you reach that prompt, enter this command:

flash dump2bin my-flashdump.bin

This is a backup of your current calibration data. It may be necessary if something will go wrong with the flash. Transfer it to pc, back it up.

flash erase 0 0x300000
flash program-m0 gsm-fw.m0

quit

reboot

==imei==
This is also very interesting project, on how to read and write gsm device filesystem.
ftp://ftp.ifctf.org/pub/GSM/FreeCalypso/mpffs-tools-r1.tar.bz2

openmoko firmware screenshot

story about slavery

comment from here by marc :

Media is “the old prophet of doom”. Now we have even more aggressive and dangerous ones – usually all of the closed-source, non-free, non-collaborative internet media, social networking sites and news sites. Boycott the hell out of them and they’ll die natural death.

Once it was all about “the tubes”, now it’s about the TRADE. They feed you with their crap, and you’re paying them with your data, your life and your time. However, can we even call it a TRADE, when it’s not even realized by one of the sides of this harmful “transaction”?

Don’t let them fool you.

other comments good too (:

#comment #media #cite #quote #internet #social #trade #slavery #freedom
#քաղվածք #մեկնաբանություն #մեջբերում #համացանց #առեւտուր #ստրկություն #ազատություն

story about Soviet Georgia

I would like to make some quotes from the book I am reading now.

scaled_full_b985fa950328bba494cf

On publishing this book, I did not consider its relevance in today’s current political climate, rather, I naively believed that after the USSR disintegration, the Soviet past of Georgia would become nothing but a bitter memory. I was wrong. As it turned out, the past can come back to haunt you, especially if we ourselves cannot move from it.

The space pioneer superpower failed to produce such a simple piece of clothing as jeans. What can be more innocent than a pair of jeans? But because they couldn’t produce them, they just banned them.
The banned jeans became sweeter than the forbidden fruit.

In those days every pair of jeans was believed to be American, and as the Soviet propaganda was particularly set to destroying American values, many thought the happiness lay where jeans were abundant.
There was a grain of truth in such a belief because the Soviet state denied its citizens the basic civil rights, the right of property among them. One could truly be free only in one’s grave or rather, the authorities stopped worrying about your freedom and rights when you were safely put under the earth…. … There might have been other reasons, but the fact is that a grave was the only property people owed. Such political attitude marked the start of altering Georgian taste for the worse. For centuries, the traditional Georgian graveyards were simple and modest, while in the Soviet times the graves became ovely decorated, adorned with marble tables and benches, statues, bikes and even cars. The Soviet Georgians were confident in one thing only – the grave belonged to them, so they were taken care of and zealosly protected. People built and decorated them as they’d do if they had real estate property. The authorities turned a blind eye to the graveyard eccentricities. The Soviet regime principles didn’t extend to the Georgian graveyards.

The Georgian authorities demonstrated more respect to the dead than to the living. However, there was one prerequisite for a guaranteed grave – one had to die ones’ natural death. If one was executed for crime, the dead convict would certainly be buried but he or she wouldn’t have a proper grave. Starting from 1920s, thousands of executed convicts found their eternal resting place in various unmarked stretches of land across the country. Very often the diggers assigned to the job of preparing a deep hole (not a grave) weren’t able to identify with certainty the places, especially that there were no landmarks to guide them and the work was usually done in the small hours, in complete darkness.

When the men opened the coffin lid, Gega’s mother turned away, waiting for their reaction. The men, deeply stunned, looked at the corpse which was difficult to identify due to the lapsed time. But it was Natia Megrelishvili who said with conviction: ‘This isn’t Gega. This is Soso, it’s his jeans, there’s the sun drawn on them.’ The others looked at the open coffin again and only now discovered the deceased was wearing the jeans, unaffected by the time and the soil. The jeans looked new and there was a shining sun drawn above the right knee.

In the 1960′s and 70′s they didn’t execute professors and scientists anymore, but in return for their lives, they forced them to cooperate with the Soviet authorities. Most of them did cooperate with the government, since otherwise none of them would have been able to travel abroad and attend a single scientific conference. Such cooperation with authorities, at first glance, was nothing special, and sometimes nothing was requested in return for their foreign trips, but this was only at first glance. In reality the main thing was taken away from them – freedom of speech and the right to have their own opinion. They couldn’t express their political views openly and had to support the government in all crucial cases (in every single one, for that matter). That’s what really happened – together with the Soviet government most Soviet scientists obediently created one big Soviet lie. Of course there also were exceptions – those who didn’t want privileges, apartments and cars given by the government (or the government didn’t with to encourage them). But there were very few of them – mostly they sat in the kitchens of their council flats. They would work, eat and drink and express negative opinions regarding the Soviet #regime only there, in the safety of their tiny kitchens. True, some – including academics – were in jail (and not kitchen), but those were known as dissidents.

Thanks to his provincial zeal, in the beginning of the 1970′s, Shevarnadze became the top person in Soviet Georgia (after beating his local competitors) and very soon, very easily, managed to charm the Soviet Georgian intelligentsia. However, the latter was more an “accomplishment” of the Soviet intelligentsia rather than that of the First Secretary, since for dozens of years, the intellectual abilities of the Soviet intelligentsia had also been deteriorating (alongside the morals).

und so weiter

story about left shift

I was tinkering with Ofront, making changes here and there in order to run it on x86_64.
By doing this I met a strange warning issued by gcc when it was compiling Console.c file.

Console.c: In function ‘Console_Int’:
Console.c:57:2: warning: left shift count >= width of type [enabled by default]

So, Console.c is generated from Console.Mod. And the Int function of Console module writes integer to the console.
This is how it looks:

  PROCEDURE Int*(i, n: LONGINT);
    VAR s: ARRAY 32 OF CHAR; i1, k: LONGINT;
  BEGIN
    IF i = SYSTEM.LSH(LONG(LONG(1)), SIZE(LONGINT)*8 - 1) THEN
      IF SIZE(LONGINT) = 8 THEN s := "8085774586302733229"; k := 19
      ELSE s := "8463847412"; k := 10
      END
    ELSE
      i1 := ABS(i);
      s[0] := CHR(i1 MOD 10 + ORD("0")); i1 := i1 DIV 10; k := 1;
      WHILE i1 > 0 DO s[k] := CHR(i1 MOD 10 + ORD("0")); i1 := i1 DIV 10; INC(k) END
    END ;
    IF i < 0 THEN s[k] := "-"; INC(k) END ;
    WHILE n > k DO Char(" "); DEC(n) END ;
    WHILE k > 0 DO  DEC(k); Char(s[k]) END
  END Int;

The error is issued in the line:

    IF i = SYSTEM.LSH(LONG(LONG(1)), SIZE(LONGINT)*8 - 1) THEN

which is translated as following in case of x86_64:

if (i == __LSHL(1, 63, LONGINT)) {

On x86 it gets translated as:

if (i == __LSHL(1, 31, LONGINT)) {

Okay, and it does not issue an error on 32 bit platform, Why?

Probably, need to look into how the _LSHL macro is written. That’s in SYSTEM.h

#define __LSHL(x, n, t) ((t)((unsigned)(x)<<(n)))

Okay, what do we see. It casts the number as unsigned, then shifts it. Obviously, the cast is necessary in order to use the sign bit.

Now let's swerve to the question why do they to do this?
And what special in this "8085774586302733229" number? Or in this: "8463847412"? If you fed this number to the Worlfram alpha saas, it does not give a clue.
The clue gives the lower part of the script, it writes the number from right to left.

WHILE k > 0 DO  DEC(k); Char(s[k]) END

Let's reverse this number and look at it as binary.

noch@SAL9000 ~ $ echo 'obase=2; 2147483648' | bc
10000000000000000000000000000000

wow. This is it. We would get it by shifting 1 to the left.
But why do they shift it?
What is LONGINT on 32 bit platform? It is a number in range from -2^31 .. 2^31 -1.
And the number 2147483648 is 2^31.
So they do it in order to be able to print the number 2^31! Only for that!
Obviously, in case of x86_64 that's the number 9,223,372,036,854,775,808

Okay, let's tinker further. We want to be able to print it, why not?

So why C compiler (I use gcc) does not issue
the warning in case of 32 bits but issues in case of 64?

Because of the macro, probably. Let's write a simple C text to check.

#include "stdio.h"
#define __LSHL(x, n, t) ((t)((unsigned)(x)<<(n)))

int main()
{
   long i;
   printf("%lu\n",sizeof(long));

   i=__LSHL(1, sizeof(long)*8-1, long);

   printf ("%lu\n",i);
return 0;

}

Then,

$ gcc -o test0 test0.c
test0.c: In function ‘main’:
test0.c:9:4: warning: left shift count >= width of type [enabled by default]

The problem is in the cast. If we do (unsigned) then it casts it to unsigned int, not unsigned long.
Let's change the macro to

#define __LSHL(x, n, t) ((t)((unsigned t)(x)<<(n)))

Now it compiles without warnings and run.

$ gcc -o test0 test0.c
$ ./test0
8
9223372036854775808

However, compiler fails to compile it when we make the same change in SYSTEM.h

Console.c: In function ‘Console_Int’:
Console.c:56:11: error: expected ‘)’ before ‘LONGINT’

Why?
Let's emulate the case exactly. We need to add LONGINT typedef

#include "stdio.h"
typedef long LONGINT;
#define __LSHL(x, n, t) ((t)((unsigned t)(x)<<(n)))

int main()
{
   long i;
   printf("%lu\n",sizeof(LONGINT));

   i=__LSHL(1, sizeof(LONGINT)*8-1, LONGINT);

   printf ("%lu\n",i);
return 0;

}

It does not compile!

noch@SAL9000 /tmp $ gcc -o test1 test1.c
test1.c: In function ‘main’:
test1.c:10:6: error: expected ‘)’ before ‘LONGINT’

We clearly see that in the macro there are three arguments which _LSHL expects but for some strange reason gcc expects the closing parentheses after the second argument.
However we can compile it with g++ - it understands this typedef issue

noch@SAL9000 /tmp $ cp test1.c test1.cpp
noch@SAL9000 /tmp $ g++ -o test1 test1.cpp
noch@SAL9000 /tmp $ ./test1
8
9223372036854775808
noch@SAL9000 /tmp $

Okay. What can be done here?
We can do

typedef unsigned long ULONGINT;

and then change macro like this:

#define __LSHL(x, n, t) ((t)((ULONGINT)(x)<<(n)))

So the file looks like

#include "stdio.h"
typedef long LONGINT;
typedef unsigned long ULONGINT;
#define __LSHL(x, n, t) ((t)((ULONGINT)(x)<<(n)))
//#define __LSHL(x, n, t) ((t)((unsigned t)(x)<<(n)))

int main()
{
   long i;
   printf("%lu\n",sizeof(LONGINT));

   i=__LSHL(1, sizeof(LONGINT)*8-1, LONGINT);

   printf ("%lu\n",i);
return 0;

}

now, and it compiles

$ gcc -o test test.c
$ ./test
8
9223372036854775808

But this is not what we want.
The good solution would be to replace a macro with a function, which can be debugged, and which won't give such an error. But it is not possible to pass a type as an argument in plain C without a macro. It may be possible by using templates, in C++, but we use C.
May be there is a need to change Ofront in a way it would generate a different function call.
Another solution is to use define instead of typedef.

#include "stdio.h"
//typedef long LONGINT;
#define LONGINT long

//typedef unsigned long ULONGINT;
//#define __LSHL(x, n, t) ((t)((ULONGINT)(x)<<(n)))
#define __LSHL(x, n, t) ((t)((unsigned t)(x)<<(n)))

int main()
{
   long i;
   printf("%lu\n",sizeof(LONGINT));

   i=__LSHL(1, sizeof(LONGINT)*8-1, LONGINT);

   printf ("%lu\n",i);
return 0;

}

Test runs

$ gcc -o test test.c
$ ./test
8
9223372036854775808

For now the solution is to replace typedef with define in SYSTEM.h and use (unsigned t) cast in the macro.

und so weiter

story about one death

657996CC-5DC6-423E-BB5C-C7B1B1CA0B96_w443_r1

Today, many years ago a dictator named Stalin died.

As House once said, almost dying changes nothing. Dying changes everything.

So this allowed us to stop devastation of the Sevan lake, it allowed us to free some political prisoners, such as Mahari (though it was too late to help Charents), it allowed us to get rid of the huge Stalin monument over the Yerevan,
monument-to-stalin---yerevan---1962

it allowed us to have our 60ies, to speak about armenian genocide, and build a memorial where we can bring flowers and not be arrested, to have new, interesting architecture, like openhall, or a seagull for which Khrushchev punished Zarobian, it allowed us to breath a little more free, fresh air, it allowed some short change.
When it is someone’s birthday, people say – how cool that you’d born, and when people like Stalin die, it’s time to say – how cool that you died, thank you for that, it’s possibly the best thing you could do, and it was very nice for Armenia.

openhall

ruben17-1

seagull

und so weiter

story about smell of money

spent several months programming in Java. Contrary to its authors prediction, it did not grow on me. I did not find any new insights – for the first time in my life programming in a new language did not bring me new insights. It keeps all the stuff that I never use in C++ – inheritance, virtuals – OO gook – and removes the stuff that I find useful. It might be successful – after all, MS DOS was – and it might be a profitable thing for all your readers to learn Java, but it has no intellectual value whatsoever. Look at their implementation of hash tables. Look at the sorting routines that come with their “cool” sorting applet. Try to use AWT. The best way to judge a language is to look at the code written by its proponents. “Radix enim omnium malorum est cupiditas” – and Java is clearly an example of a money oriented programming (MOP). As the chief proponent of Java at SGI told me: “Alex, you have to go where the money is.” But I do not particularly want to go where the money is – it usually does not smell nice there.

source

und so weiter

story about pencil marks

I have eventually found this book, second hand, obviously.

I have learned about it first because Creenshaw in his compiler book advised it as one of the best compiler books ever.

POINTER TO syntax appeared first in Modula.
Apparently the former owner of the book tried to translate the text from Pascal to Modula, or may be to Oberon.


There is no BEGIN in WHILE loops since Modula.
Modula and Oberon also don’t have the FUNCTION keyword, they have only PROCEDUREs (:

und so weiter

quote about debugging

from Wirth’s interview

well, of course, if the world was ideal I would gladly recommend learn the basic concepts properly and then do programming with Oberon. But I’m fully aware that the world is not that simple. Programmers nowadays are faced with very difficult task and they cannot afford to build system from scratch. They have to use many tools that exist already and interface their new programs with them, and that’s where the problem is. This interface is not even properly and fully specified. Any many work comes with that. It is quite well known that if 5% percent going to programming is much, the rest is going to debugging. And that’s precular, it’s not science, not even engineering, it’s just trying.

und so weiter

quote about old design

The libc is certainly not a good guide:

* Buffer overruns are not ruled out by design: gets, sscanf etc.
* Interface inconsistencies: gets vs fgets, fgets vs fscanf (note
the position of the file stream parameter)
* Bad interfaces like that of getchar() whose return code
can be a character or an error code
* Particularly bad buffering system which
– ignores the block structure of underlying file systems, and
– does not support bidirectional buffering
* No provisions exist such that independent libraries can cooperate
with each other in
– signal handling,
– setting up alarms, and
– tracking childs.

(Please note that I do not want to bash Ritchie, Kernighan etc. The
libc is history and should be taken as such… It is time to abandon
C and the libc and it does not help to place other systems on top of this historic relic.)

source
und so weiter

story about prokhanov’s interview

prokhanov

Russian version of the “Yerevan” magazine, first issue of 2013 year, published interview with the Russian writer Prokhanov about the Eurasian Union.
He states, that he cannot imagine Russia other than an empire and does not conceal that he considers the Eurasian Union as a new implementation of this empire. This guy’s cynicism is is pinning.
I am quoting:

Eurasian area with it’s ethnicities is a colossal resource. The area by itself is already a resource. And combining these squares into one creates colossal wealth.

Undoubtedly, area is resource. If it weren’t resource, Azerbaijan would give up Artsakh long time ago. Also, when US spreads democracy the question rises – for whom? And the same question rises now – wealth for whom? The answer follows.

When the Soviet Union collapsed, Russia lost uranium mines of Kazakhstan, cotton of the Uzbekistan… It is obvious that there is a huge economical potential in this project.

Okay, Russia wants free uranium, and other resources. Then – wealth is for Russia.
Upon the whole Prokhanov observes both USSR and Eurasian Union as different forms of Russian Empire.

Russian history – is the history of empires, and Russian tragedies always connected with their disappearance. At least, four great empires (including the last one, Red empire) were demolished, and as a result Russia suffered colossal losses.

Wow, so sincere.
Then, may be empires shell not live by definition? May be they have to die naturally with time?
Isn’t it enough to make the same mistakes, Messrs Russian imperialists?
May you understand that it won’t bring the future closer?

Let’s continue. Prokhanov observes Eurasian Union as it is in reality, not as it is described in advertisements. People get deceived by the “customs union” expression. Though the real Eurasian Union is the new reincarnation of Russian Empire, not the customs union of independent states. This customs union could be created on the basis of Union of Independent States. However Eurasian Union is one whole state.

We already have conceived union state between Russia and Belarus, it has difficulties, but the gene is found.

Meanwhile Prokhanov expresses what kind of state it will be.

The civilization product – it’s not only technologies of the future, it’s also ideas of the future. And these ideas, ideologies already today are the most precious possessions – in Eurasian areas may become an alternative to the dying models, such as western liberal model.

Obviosly, my comment is that those are not ideas of the future, but of the past. New ideas are spoken in the Occupy movement, for example, but definitely not in Russia.
And despite the fact that the answer to the next question – doesn’t it mean, that this is a reestablishment of the USSR, he answers – no, USSR cannot be recovered, he also means that this is just another way to create a new Russian Empire, Russian Empire reloaded, the new one, not the old.
109281_600
And I agree, Soviet Union at least was Soviet to some extent, and they were trying to support some provinces, meanwhile working on the assimilation of the native population, and changing demographic composition (simply – by settling Russians, the main and base ethnicity of the empire in republics). So the new union won’t even support republics, it will have the same cruel capitalistic model, and the goal is to soak up resources from those republics. We see widespread pillages in Russia, but it’s not enough for them, they need more, cause they are fat and hungry.

And we just “elected” our new president. President, who got this title after not really clear events. President, who thanked Russian leaders for support after those not really clear events. President, who presents the regime, which copy-pastes Russian Federation movements, president who recently signed a paper related to that Eurasian Union, and what now? We have to wait with gladness until he makes another sign, by which Republic of Armenia will formally acknowledge it’s failure, then will be painted out with red or pink color on the map becoming a part of the stupid big state.
108964_600
photo from here
Why Russian language Yerevan magazine prints this interview remains an open question for me. Then, may be it’s not surprising that in the previous issue there were photos of the prime minister with combine, then president at the exhibition, and so on.

Congratulations, gentlemen. Congratulations. Everything is excellent, let’s enjoy festal fireworks.

und so weiter