Este blog não possui nenhuma afiliação social, empregatícia, financeira ou política a não ser comigo mesmo. As opiniões expressas aqui refletem meu ponto de vista sobre assuntos aleatórios e nada mais. Comentários são mais do que bem vindos, são encorajados, positivos ou não. Até prefiro comentários oposicionistas, afinal um mundo que pensa igual é desprovido de inovação. Portanto, sinta-se em casa. Espero que ler minhas verborréias esporádicas traga-lhe o mesmo prazer que tenho produzindo-as.

[ваκκєr]

P.S. Algumas vezes algo que eu quero expressar não pode ser dito (apenas) com palavras, então vai parar em meu fotolog ao invés de aqui. Confira-o de vez em quando.

quarta-feira, 21 de setembro de 2011

Installing and running Debian armel on an emulated ARM machine on Windows (QEMU)

Why, you ask me? Well, it all begun with Raspberry Pi... If you don't know the amazing, tiny, soon to be the greatest thing to happen to personal computing since... sliced bread?, please, do yourself a favor and click the link.


If you are feeling a little too TL;DR for that, maybe you should skip this post, but since I'm such a nice guy I'm willing to cut you some slack and give you the skinny: The RasPi is soon-to-be a tiny, sub-$50 full-featured computer. It is possible thanks to mobile technology, specially a System-on-a-Chip (SoC) manufactured by Broadcom for use in smartphones. It has a kick-ass graphics processor (capable of running 1080p video, or Quake 3, without heating much above body temperature. Don't take my word for it, click play and enjoy the show):


This amazing GPU is combined in the same package with a handful of on-board RAM (128 or 256MB, depending on version) and an ARM processor. Which is great, except that most of the software we use on a daily basis is built for Windows running on x86, not Linux on ARM. So people are excited about it, but at the same time they don't know if their favorite piece of software is gonna run on this puppy. And people being people (myself included), they don't want to wait until late November to get their hands on one. Therefore, here we are, trying to emulate it, at least well enough to test if we can compile... well, whatever the heck we may want to compile and run on the RasPi.

Full disclosure: You can emulate an ARM1176 on the latest versions of QEMU, but you cannot simply install a run-off-the-mill Linux distro on it, because no distro nowadays ships with compatible kernels. We could go thru all the trouble of cross-compiling one, and installing Debian using it, but we won't. Why? Because most software that runs on the ARM926 we are going to emulate will compile and run just fine on the ARM1176 core in the RasPi. If the emulated architecture were more advanced, like an ARMv7A, it would probably run software incompatible with the Raspberry Pi, like Adobe Flash 10. But since the ARM1176 is the natural replacement to the ARM926, emulating the earlier platform can have no impact other than performance, and that is already going to be puny thanks to being emulated anyways. Sure, you could also argue I'm just being lazy, and you'd not be far from the truth either.

First and foremost, you need to get yourself a copy of QEMU for Windows. I recommend downloading the latest binary from http://lassauge.free.fr/qemu/ (some assembly required, it does not come with required fmod.dll, SDL.dll, mgwz.dll and libusb0.dll, but has links to current versions of the files and/or instructions to roll your own). You can also cut some corners and download your copy from http://homepage3.nifty.com/takeda-toshiya/qemu/ (no longer updated, but has a version 0.13.0 of QEMU good enough for what we are trying here). If you're too lazy to bake your own DLLs, I have put together an easy to use ZIP file with QEMU 0.15 and all needed libraries. You can download it here. Just remember to unzip and/or compile all your QEMU files, including DLLs, to the same folder (hat-tip to obarthelemy @ the Raspberry Pi forums).

Edit: the networking section is under scrutiny in the Raspberry Pi forums. I'll be updating as I get new information from other users; if you can't get it to work, give us a call.

Now you'll need to download OpenVPN, in order to create a network tap. You can go straight ahead and click here. During installation it creates a couple of TAP-Win32 Adapters, one of which you can dispose of. Go to Adapter Settings - here's where to find'em on Windows 7:


- and rename your TAP-Win32 Adapter something single-worded, like TAP32. Now you'll need to manually set your TAP adapter. Right-click your it and select Properties. Once there, de-select all protocols, except the Internet Protocol Version 4 (TCP/IP v4). Click it and then Properties:




Tricky part: you'll need to know your gateway IP address, but I guess if you haven't given up on this tutorial already, you know your local network inside out. Set the IP manually to something within your subnet's range, but not used by any of your machines, as well as put your router's IP as gateway and DNS server. Here's a screenshot, just don't copy it, use your local values instead:


Once you hit OK and are back at the Network Connections windows, hold Control, select both the TAP adapter and the one you use to connect to the internet, right click'em and select Add to Bridge:


You'll get a new adapter type, a MAC Bridge Miniport. You don't need to rename it, but you might also need to manually set it's IP address, Gateway and DNS servers (your mileage with Windows' auto-config may vary). Just follow the steps for the TAP-Win32 adapter and you'll be fine. Okeydokey, network ready. Now you'll need to get acquainted with the Command Prompt. It sits here, inside your Accessories folder:


You can always just type CMD on the Start menu and hit Enter, and you'll get one of the little buggers (don't you love Windows 7?). Now navigate to the folder where you put your QEMU installations and run

qemu-img create -f raw hda.img imagesize

where imagesize is the size of the disk you wish to create for your emulated device. It accepts the format number+suffix, as in 256M for 256 megabytes or 2G for gigabytes, etc. for some reason, my qemu-img refused to accept 8G as an argument, so I entered 8096M instead. Go figure (it seems crundy @ the RasPi forums had the same problem with 4G. I recommend you always use 1024M instead of 1G when trying to make gigabyte-sized disks). You now have a virtual hard-drive where you're gonna install Debian. To do it, you'll need two things: a kernel and an initrd. The kernel, as the name implies, is the core of the Linux operating system. The initrd is the initial ramdisk, a file containing information the kernel expects to find inside your computer's memory in order to find bootable devices, etc. When doing a networked install, the initrd contains the basic installer software, which will, in turn, download the rest of the Linux distribution from the internet. The latest stable Debian distribution for ARM can be found at http://ftp.debian.org/debian/dists/stable/main/installer-armel/current/images/versatile/netboot/.Just point your browser there get initrd.gz and vmlinuz-2.6.32-5-versatile. Now you have your hard dirk image, kernel and initrd. Time to start having fun! (not). On your Command Prompt window, type


qemu-system-arm -L . -kernel vmlinuz-2.6.32-5-versatile -initrd initrd.gz -hda hda.img -m 256 -M versatilepb -net nic -net tap,ifname=networkname -append "desktop=lxde"

where networkname is the name of your TAP-Win32 adapter (you DO remember it, don't you?) and -append "desktop=lxde" is optional. If you leave it out, you'll get the default Gnome desktop (assuming you install a desktop environment, a part we'll be getting into soon). Adding the desktop boot parameter allows you to choose an alternate desktop environment, in this case LXDE, the Lightweight  X11 Desktop Environment, which, the RasPi team informs us, is what we'll probably get with their boot images. It does help tons (pun intended) to replace Gnome with LXDE when everything runs so damn slow (no one said emulation was easy). Once you hit enter, assuming you did everything right (be sure to have all required files in the same folder), you'll be greeted with a new window:


Soon you'll see the Debian installer window. Select your local language, keyboard layout, country etc. according to your geographical location and preferred settings. The options are mostly idiot-proof, so when in doubt, just let the installer guide you. Unless you really do use a Domain on Windows, keep that field blank. Your Workgroup won't work, even if that's what the installer recommends (thanks again, obarthelemy!). Once the software selection screen comes up, be sure to select whatever packets you believe you'll need (including a graphical desktop environment, unless you're comfortable enough with Linux to leave that out). Don't go hitting Enter like I did the first time, the key you use to select packets is the space bar (duh!).


Now sit tight for what will be, depending on your connection, quite a long time. When the installer is finally done, it will warn you that no boot loader was installed. What it means is that you cannot simply reboot the Virtual Machine to load your freshly installed Linux. Wait for it to finish up and restart, then hit Control+Alt+2 to go to the QEMU console. This is where you can issue commands directly to the emulator. Simply type q and hit Enter to close QEMU (or you can just hit the big, red, X-button Your call). Now you'll need a new initrd (remember, the other one contains the installer payload, not the directions to boot your media). If we were running Linux, we could mount our virtual hard disk and copy the initrd from /root. Fortunately for us Windows users, we can also download one from http://people.debian.org/~aurel32/qemu/armel/. Go there, fetch yourself initrd.img-2.6.32-5-versatile and copy it to the QEMU folder. Now I recommend you open Notepad and make this new command into a batch file, otherwise you'll need to type this mouthful every time you want to run your emulated Linux box. Make sure to turn Word Wrap off in the Format menu and type
@qemu-system-arm.exe -L . -kernel vmlinuz-2.6.32-5-versatile -initrd initrd.img-2.6.32-5-versatile -hda hda.img -k en-us -m 256 -M versatilepb -net nic -net tap,ifname=networkname -append "root=/dev/sda1"
where networkname is the name of your TAP-Win32 adapter (repeat myself much?). Now save it to the QEMU folder with the .BAT extension. To run the Virtual Machine, just double click the .BAT file and off we go. The system will boot mostly like the installer, but (depending on whether you installed a desktop environment) will go to a login screen (Gnome shown below). Type the name and password you've set up during installation and voilá! Linux on ARM!

...now, if you're too damn lazy to go thru the entire installation process, I have a treat for you: downloadable images! All you need is to install a Torrent client, then click here for LXDE or here for Gnome. Alternately, you can download them via RapidShare: click here for LXDE or here for Gnome. Just copy the files to your QEMU folder and double-click the corresponding .BAT file, you remiss indolent!


Thanks go to Francisco Benitez's great tutorial for installing Debian on QEMU, which I've adapted for Windows and updated, and to Ken's tutorial on Windows networking for QEMU. This page wouldn't exist if it wasn't for these and other great resources I found online.

segunda-feira, 12 de setembro de 2011

Boicote aos produtos da Ambev, atualização

Aqui em casa, não se consome mais nada da Ambev. Se você não sabe porque, role o browser pra baixo ou clique nesse link. O que quer dizer que eu, viciado em Pepsi Twist Light, sou obrigado a beber Coca Zero. É; foda. Mas a gente vai levando, o refrigerante é mais caro, cerveja é quase impossível de comprar sem patrocinar algum rodeio (só micro-cervejarias e importações independentes; já mencionei que tudo ficou mais caro?). Como eu já disse; foda. Mas foda mesmo é abrir garrafa de Coca Zero... PQP, Coca Cola Company, vocês não podiam ter projetado uma tampa pior? Talvez com uns espinhos e lâminas? Ô tampinha filha de uma rapariga... Olha o que a última fez com a minha mão:


Design nota zero, Coca Cola.

P.S. Pra quem tá se perguntando, sim, eu voltei a fazer a famosa "água de balde", 60% Coca Zero e 40% Schweppes Citrus Light. Continua mais gostosa que Pepsi Twist Light, mas custa mais caro.

domingo, 11 de setembro de 2011

Foursquare: meu primeiro special

Ok, assim parece que eu sou um n00b brincando de usar redes sociais, mas veja bem: sou usuário de Fourquare desde que arrumei um celular com Android, em julho de 2010. Na época a coisa nas redes sociais de geolocação era tão desértica que, sem brincadeira, existia UM local registrado pra dar check-in no Gowalla na cidade onde eu comprei o celular (a nunca-saudosa São José do Hell Preto). Até hoje eu tenho uma enorme dificuldade de encontrar estabelecimentos realmente explorando o potencial do Foursquare (sim, eu desisti do Gowalla de lá pra cá). E isso nos leva à minha visita de hoje à tarde à Leroy Merlin (prêmio especial por usar três crases na mesma frase vai para... moi!). Estávamos lá, eu e a Cau, na fila para pagar por duas lâminas de serra tico-tico (e mais trocentas coisas que pegamos no caminho do caixa, será que nunca vamos conseguir ir na Leroy e comprar  o que fomos buscar?) quando decidimos fazer o check-in nosso de cada dia... E surge o aviso de que o Foursquare tem um special na Leroy, como mostra o screenshot a seguir:
...será? Só ir no Balcão de Atendimento e pegar meus brindes? Fomos lá, tiramos uma senha e esperamos nossa vez. A mocinha, como previsto, não fazia a menor idéia do que se tratava o assunto. Mas diga-se em favor dela, era cheia de atitude e jogo de cintura: saiu de trás do balcão e nos levou até outro balcão, esse intitulado Balcão de Apoio e... voilá! espressos e ecobags pra mim e pra Cau!



Isso mudou minha impressão sobre a Leroy Merlin? Não sei dizer, afinal minha opinião deles já é das melhores. Mas com certeza me senti bem atendido e parte de algo (não deveria ser esse o objetivo de uma rede social, integrar?).

Notas 10 pro Foursquare e pra Leroy. E fica aqui meu convite pros amigos que tem smartphone darem um pulo na Leroy tomar um cafezinho por conta e, quem sabe, comprar aquela lâmpada que queimou semana retrasada e você ainda não trocou porque não para nunca pra nada, sacumé, né?