Update-even-more: Binwalk has just moved to GitHub.
Update: Second half of this tutorial refers to the binwalk version 1.2.1 only. It appears that with 1.2.2 release, problem with setup.py has been resolved. Diff here.
Firstly, a few dependencies.
There is a package “file” in Slackware but it doesn’t have it’s Python bindings installed. You need to download appropriate source file from here: ftp://ftp.astron.com/pub/file/. Choose version that you have in your system. In my case it is 5.14.
# tar xzf file-5.14.tar.gz # cd file-5.14/python # python setup.py install
At this point you should run something like this without getting an exception:
# python Python 2.7.5 (default, May 29 2013, 02:28:51) [GCC 4.8.0] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import magic >>> magic.MAGIC_NO_CHECK_TEXT 131072 >>>
Next, you may want to get matplotlib working. This is not required to and if you don’t want it you can fall back to regular binwalk install procedure (docs/README in binwalk sources) and quit reading this text. From now on, I assume you want to have fancy plotting option in your binwalk.
There is a bunch of packages to install. My preferred way to do this is by getting them from SlackBuilds. You can also use sbopkg tool, to speed up whole process. Install following packages in order: pysetuptools, six, python_dateutil, pytz, numpy and matplotlib.
Before we proceed there is a test to perform. Switch to non-root user and type:
$ python Python 2.7.5 (default, May 29 2013, 02:28:51) [GCC 4.8.0] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import matplotlib.pyplot >>>
If you don’t get anything more serious than some fontconfig warnings, It’s OK to proceed.
Get binwalk: http://code.google.com/p/binwalk/downloads/list. In my case current version is 1.2.1. Then, type:
# tar xzf binwalk-1.2.1.tar.gz # cd binwalk-1.2.1/src
Now it’s tricky part. You want to have your binwalk installed globally since this is how setup script works, but installer (matplotlib.pyplot, actually) needs X server and you don’t have it in root’s python session. Because you verified that matplotlib.pyplot works on non-root user, where one usually runs software from, you can make little ugly hack to binwalk’s setup.py file. Let’s change the way how installer checks if matplotlib is present. This is a diff of original and modified file in patch format:
@@ -26,6 +26,8 @@
+ import matplotlib
except Exception, e:
print "\n", "*" * WIDTH
By changing method of plotting (to textual) you bypass the need for X server and installation runs smoothly. And app should work great too.
This is it, enjoy your binwalk:)
You may get a warning each time you run binwalk:
Warning: New continuation level 2 is more than one larger than current level 0
If so, update signatures (as root):
# binwalk -u
Be sure to check http://code.google.com/p/binwalk/wiki/Installation for recommendations for other handy tools.
P.S. 3 (new)
Version 1.2.2 installs flawlessly.
I uploaded one of my student projects to GitHub: Canny algrithm implementation. This is popular method of finding edges in the image invented in 80′s: http://en.wikipedia.org/wiki/Canny_edge_detector. What you will find here is extremely naive approach, possibly with bugs and certainly not written with memory consumption issues in mind. But that’s just student project, it served well for its purpose:) Make sure to see README:
Below there is an exmple of each step of algorithm being performed:
Embedded systems gurus always repeated: don’t use floating-point numbers in your firmware! But what if you have processor with a FPU? Well, then you simply can. Do not forget, however, to carefully look at your disassembly file, as always.
So this is what we get with GCC 4.6.2 on Cortex-M3:
float a = 0.123123f; 8000350: 4b21 ldr r3, [pc, #132] ; (80003d8 <main+0xd8>) 8000352: 617b str r3, [r7, #20] float b = 0.123123f; 8000354: 4b20 ldr r3, [pc, #128] ; (80003d8 <main+0xd8>) 8000356: 613b str r3, [r7, #16] float c = 0.0f; 8000358: 4b20 ldr r3, [pc, #128] ; (80003dc <main+0xdc>) 800035a: 60fb str r3, [r7, #12] c = a * b; 800035c: 6978 ldr r0, [r7, #20] 800035e: 6939 ldr r1, [r7, #16] 8000360: f000 f8d6 bl 8000510 <__aeabi_fmul> 8000364: 4603 mov r3, r0 8000366: 60fb str r3, [r7, #12] b = c; 8000368: 68fb ldr r3, [r7, #12] 800036a: 613b str r3, [r7, #16] (...) 08000510 <__aeabi_fmul>: 8000510: f04f 0cff mov.w ip, #255 ; 0xff 8000514: ea1c 52d0 ands.w r2, ip, r0, lsr #23 8000518: bf1e ittt ne 800051a: ea1c 53d1 andsne.w r3, ip, r1, lsr #23 800051e: ea92 0f0c teqne r2, ip 8000522: ea93 0f0c teqne r3, ip 8000526: d06f beq.n 8000608 <__aeabi_fmul+0xf8> 8000528: 441a add r2, r3 800052a: ea80 0c01 eor.w ip, r0, r1 800052e: 0240 lsls r0, r0, #9 8000530: bf18 it ne 8000532: ea5f 2141 movsne.w r1, r1, lsl #9 8000536: d01e beq.n 8000576 <__aeabi_fmul+0x66> 8000538: f04f 6300 mov.w r3, #134217728 ; 0x8000000 800053c: ea43 1050 orr.w r0, r3, r0, lsr #5 8000540: ea43 1151 orr.w r1, r3, r1, lsr #5 8000544: fba0 3101 umull r3, r1, r0, r1 8000548: f00c 4000 and.w r0, ip, #2147483648 ; 0x80000000 800054c: f5b1 0f00 cmp.w r1, #8388608 ; 0x800000 8000550: bf3e ittt cc 8000552: 0049 lslcc r1, r1, #1 8000554: ea41 71d3 orrcc.w r1, r1, r3, lsr #31 8000558: 005b lslcc r3, r3, #1 800055a: ea40 0001 orr.w r0, r0, r1 800055e: f162 027f sbc.w r2, r2, #127 ; 0x7f 8000562: 2afd cmp r2, #253 ; 0xfd 8000564: d81d bhi.n 80005a2 <__aeabi_fmul+0x92> 8000566: f1b3 4f00 cmp.w r3, #2147483648 ; 0x80000000 800056a: eb40 50c2 adc.w r0, r0, r2, lsl #23 800056e: bf08 it eq 8000570: f020 0001 biceq.w r0, r0, #1 8000574: 4770 bx lr 8000576: f090 0f00 teq r0, #0 800057a: f00c 4c00 and.w ip, ip, #2147483648 ; 0x80000000 800057e: bf08 it eq 8000580: 0249 lsleq r1, r1, #9 8000582: ea4c 2050 orr.w r0, ip, r0, lsr #9 8000586: ea40 2051 orr.w r0, r0, r1, lsr #9 800058a: 3a7f subs r2, #127 ; 0x7f 800058c: bfc2 ittt gt 800058e: f1d2 03ff rsbsgt r3, r2, #255 ; 0xff 8000592: ea40 50c2 orrgt.w r0, r0, r2, lsl #23 8000596: 4770 bxgt lr 8000598: f440 0000 orr.w r0, r0, #8388608 ; 0x800000 800059c: f04f 0300 mov.w r3, #0 80005a0: 3a01 subs r2, #1 80005a2: dc5d bgt.n 8000660 <__aeabi_fmul+0x150> 80005a4: f112 0f19 cmn.w r2, #25 80005a8: bfdc itt le 80005aa: f000 4000 andle.w r0, r0, #2147483648 ; 0x80000000 80005ae: 4770 bxle lr 80005b0: f1c2 0200 rsb r2, r2, #0 80005b4: 0041 lsls r1, r0, #1 80005b6: fa21 f102 lsr.w r1, r1, r2 80005ba: f1c2 0220 rsb r2, r2, #32 80005be: fa00 fc02 lsl.w ip, r0, r2 80005c2: ea5f 0031 movs.w r0, r1, rrx 80005c6: f140 0000 adc.w r0, r0, #0 80005ca: ea53 034c orrs.w r3, r3, ip, lsl #1 80005ce: bf08 it eq 80005d0: ea20 70dc biceq.w r0, r0, ip, lsr #31 80005d4: 4770 bx lr 80005d6: f092 0f00 teq r2, #0 80005da: f000 4c00 and.w ip, r0, #2147483648 ; 0x80000000 80005de: bf02 ittt eq 80005e0: 0040 lsleq r0, r0, #1 80005e2: f410 0f00 tsteq.w r0, #8388608 ; 0x800000 80005e6: 3a01 subeq r2, #1 80005e8: d0f9 beq.n 80005de <__aeabi_fmul+0xce> 80005ea: ea40 000c orr.w r0, r0, ip 80005ee: f093 0f00 teq r3, #0 80005f2: f001 4c00 and.w ip, r1, #2147483648 ; 0x80000000 80005f6: bf02 ittt eq 80005f8: 0049 lsleq r1, r1, #1 80005fa: f411 0f00 tsteq.w r1, #8388608 ; 0x800000 80005fe: 3b01 subeq r3, #1 8000600: d0f9 beq.n 80005f6 <__aeabi_fmul+0xe6> 8000602: ea41 010c orr.w r1, r1, ip 8000606: e78f b.n 8000528 <__aeabi_fmul+0x18> 8000608: ea0c 53d1 and.w r3, ip, r1, lsr #23 800060c: ea92 0f0c teq r2, ip 8000610: bf18 it ne 8000612: ea93 0f0c teqne r3, ip 8000616: d00a beq.n 800062e <__aeabi_fmul+0x11e> 8000618: f030 4c00 bics.w ip, r0, #2147483648 ; 0x80000000 800061c: bf18 it ne 800061e: f031 4c00 bicsne.w ip, r1, #2147483648 ; 0x80000000 8000622: d1d8 bne.n 80005d6 <__aeabi_fmul+0xc6> 8000624: ea80 0001 eor.w r0, r0, r1 8000628: f000 4000 and.w r0, r0, #2147483648 ; 0x80000000 800062c: 4770 bx lr 800062e: f090 0f00 teq r0, #0 8000632: bf17 itett ne 8000634: f090 4f00 teqne r0, #2147483648 ; 0x80000000 8000638: 4608 moveq r0, r1 800063a: f091 0f00 teqne r1, #0 800063e: f091 4f00 teqne r1, #2147483648 ; 0x80000000 8000642: d014 beq.n 800066e <__aeabi_fmul+0x15e> 8000644: ea92 0f0c teq r2, ip 8000648: d101 bne.n 800064e <__aeabi_fmul+0x13e> 800064a: 0242 lsls r2, r0, #9 800064c: d10f bne.n 800066e <__aeabi_fmul+0x15e> 800064e: ea93 0f0c teq r3, ip 8000652: d103 bne.n 800065c <__aeabi_fmul+0x14c> 8000654: 024b lsls r3, r1, #9 8000656: bf18 it ne 8000658: 4608 movne r0, r1 800065a: d108 bne.n 800066e <__aeabi_fmul+0x15e> 800065c: ea80 0001 eor.w r0, r0, r1 8000660: f000 4000 and.w r0, r0, #2147483648 ; 0x80000000 8000664: f040 40fe orr.w r0, r0, #2130706432 ; 0x7f000000 8000668: f440 0000 orr.w r0, r0, #8388608 ; 0x800000 800066c: 4770 bx lr 800066e: f040 40fe orr.w r0, r0, #2130706432 ; 0x7f000000 8000672: f440 0040 orr.w r0, r0, #12582912 ; 0xc00000 8000676: 4770 bx lr
And this is output from the same GCC version on Cortex-M4F (compiled with flags -mcpu=cortex-m4 -mthumb -mfloat-abi=hard -mfpu=fpv4-sp-d16 -ffast-math -fsingle-precision-constant):
float a = 0.123123f; 8000410: 4b3c ldr r3, [pc, #240] ; (8000504 ) 8000412: 617b str r3, [r7, #20] float b = 0.123123f; 8000414: 4b3b ldr r3, [pc, #236] ; (8000504 ) 8000416: 613b str r3, [r7, #16] float c = 0.0f; 8000418: 4b3b ldr r3, [pc, #236] ; (8000508 ) 800041a: 60fb str r3, [r7, #12] c = a * b; 800041c: ed97 7a05 vldr s14, [r7, #20] 8000420: edd7 7a04 vldr s15, [r7, #16] 8000424: ee67 7a27 vmul.f32 s15, s14, s15 8000428: edc7 7a03 vstr s15, [r7, #12] b = c; 800042c: 68fb ldr r3, [r7, #12] 800042e: 613b str r3, [r7, #16]
This is the difference, isn’t it?
There is a great aricle (and blog) on solving problems with running VMware on Linux hosts: http://weltall.heliohost.org/wordpress/2012/01/26/vmware-workstation-8-0-2-player-4-0-2-fix-for-linux-kernel-3-2-and-3-3/. What is not said there is that sometimes you are unable even to install Workstation itself. The cause is that installer tries to build modules and it fails to do this, so the installation is reverted and you end up with nothing. The cure, which solved the case for me were following parameters:
# ./VMware-Workstation-Full-8.0.2-591240.x86_64.bundle --console --required --ignore-errors
Thanks to the –ignore-errors, after seeing few ugly Python tracebacks we finally get Installation was successful message. Now just run the patch:
…and VMware is all yours:)
After installation of fresh copy of PostgreSQL database server it is often required to configure proper localization settings. This helps to avoid messages like this:
ERROR: invalid locale name en_GB.utf8
where en_GB.utf8 is setting you want to have. In order to create a database with custom locale there are few steps one has to follow.
The first is to enable all locales you might want to use in PostgreSQL in your system config. On Debian, edit file /etc/locale.gen and uncomment lines with your locales names. In my case it looks like this:
(...) # pl_PL ISO-8859-2 pl_PL.UTF-8 UTF-8 # ps_AF UTF-8 (...)
Then run command locale-gen which will generate system localization files.
# locale-gen Generating locales (this might take a while)... en_US.UTF-8... done pl_PL.UTF-8... done Generation complete.
I have two locales enabled: en_US.UTF-8 and pl_PL.UTF-8. Both of them should be available in PostgreSQL. To check that, switch user to postgres and run SQL console, psql:
# su - postgres $ psql psql (8.4.9) Type "help" for help. postgres=#
Create user (if you haven’t done this yet):
postgres=# CREATE ROLE myuser WITH PASSWORD 'secret' LOGIN; CREATE ROLE postgres=#
Then create database with some extra parameters:
postgres=# CREATE DATABASE mydb WITH OWNER myuser ENCODING 'UTF8' LC_COLLATE 'pl_PL.utf8' LC_CTYPE 'pl_PL.utf8' TEMPLATE template0; CREATE DATABASE postgres=#
Most of this is self-explanatory. Purposes of all parameters are explained in the documentation: CREATE DATABASE. Note, that there is template0 database used as a template. More on this you will find in the manual: Template Databases.
Note: above example was successfully tested also on PostgreSQL 9.1.2.
In my engineer degree work I used CoreMP7-enabled ProASIC3 Development Kit (part number M7A3P-DEV-KIT-SCS). In a time it was launched by Actel (acquired by Microsemi) it was one of the first attempts of creating a SoPC with soft ARM core available for wide market without royalties. This particular kit has M7A3P1000 chip with 484 balls, 1M system gates and can drive internal PLL up to 350 MHz, so it’s pretty powerful. There is 1 MB of on-board RAM and 16 MB of Intel FLASH.
ARM7TDMI-S processor itself is available as a compiled and pre-placed component that can be put into user system design in SmartDesign tool (part of Libero environment). Although one cannot simulate core directly due to the lack of HDL source files, there is a BFM script compiler which produces HDL testbenches simulating transfers over AHB system bus. User writes BFM (TCL-like) scripts as if they were processor read and write operations.
The board provides several ways of programming the device. FPGA configuration is loaded with on-board FlashPro3 programmer. The same tool can be used to program and debug software written for ARM processor via SoftConsole IDE (which is modified Eclipse software). Microsemi’s FlashPro3 debugger has serious limitation, however: it can only debug code running in RAM. It can program FLASH memory using additional application (cliarm.exe console) and on this its functionality ends. Producer didn’t left programmer without choice, there is additional JTAG header on board. It is called RV (RealView) header and can be connected with 20-wire (2×10) flat cable to regular JTAG programmer. This was the reason I installed and configured fresh Eclipse with CodeSourcery G++ Lite (now Mentor Graphics) version 2011.03-42 with GCC 4.5.2 and OpenOCD in version 0.4.0 (2010-02-22-19:05). Maybe in some further post I will discuss how to set up this environment, now let’s look how to connect a programmer to the ARM core.
I use device based on FT2232 (-C, -D, -L) chip, it is similar to Amontec JAGkey. This piece of hardware was designed by Freddie Chopin. It is has a standard JTAG dual-row pin header which easily connects with P3 connector on board:
The tricky part is how to connect the header to ARM processor. On the core side there are following connections:
Note, that UJTAG group refers to the ports that have predefined physical design constraints – they are automatically connected in Designer I/O Attribute Editor. They serve as a JTAG connected to FlashPro3.
As you can see ports in RV_ICE_If group are not one-to-one compatible with pins on board. What you have to do is to make a HDL wrapper that will sort these pins and do some other actions to make things work. In this step extremely helpful was sample project distributed with board. Its sources are present on a CD or in ZIP downloaded from Actel’s website, in folder M7A3P_CDImage.zip/Disk1/Sample Design/. To get that idea look at file Hardware/Source/socTop.v. There is also an example on how to connect memories to CoreMemCtrl module.
Finally, I had to write OpenOCD configuration scripts. Traditionally, they are split in two: one referring to CPU-specific settings and second with settings related to board. Unlike in hard processor cores in CoreMP7 you are the one who designs memory map, so most probably both of these files must be altered before use. Be sure to read the comments!
If you read this you probably already know there’s not much information about designs in Actel/Microsemi devices in the Internet. Producer gives excellent documentation and examples, but that’s all. I am aware that my article hasn’t covered topic even in a small part. This FPGA/ARM7 board is also quite ancient device (odd, isn’t it? 2007 if I recall well…) and I have experience only with this specific one. But it finally worked, so feel free to encourage me to write more:-)
I have been using Slackware since I remember. Well, it wasn’t that long ago but it was one of the first distros I tried to use. It works (like a charm, I can’t deny) on my laptop, PC, VMs and in few other places. Times changed and now I decided to switch to other distro I know and like which is Debian. The question is, how to do this and not to loose any data in /home directory?
On virtual machine with Slackware I have four partitions:
/dev/sda1 – / ext4 (root directory)
/dev/sda2 – swap
/dev/sda3 – LVM PV
/dev/sda4 – LVM PV
As numbers say (and I say), all of them are primary.
Two PVs, sda3 and sda4 are merged into one VG named “user_data” and on this there is one LV named “home” containing /home directory with ext4 filesystem. I know this design is a bit weird but on this machine I used to play with LVM (adding, removing, resizing and more) and this is what has left. What I want to do is to throw away everything except /home directory. The final, satisfactory result will be fresh Debian installation with the same /home content. There is not much to do with partition design in my case, so I won’t be doing strange joining nor splitting.
So this is what to do if you want to save existing LVM partitions while installing Debian.
Start normal installation. Go through first steps, then in “Partition disks” window select manual partitioning method. Installer should properly recognize existence of LVM volumes. There should be two lists of devices on the screen, one starting with “LVM” referring to VG and one entitled “SCSI1″ which is hard disk (virtual in my case). In both there are sublists of devices.
Under “SCSI1″ there are all physical partitions. Since we do not want to change PVs we are interested only in sda1 (#1) for root and sda2 (#2) for swap. In “Partition settings” displayed after selecting #1 choose filesystem type you want in “Use as”, set mount point to “/” and agree on formatting partition. Be sure that bootable flag is set and that’s it. Swap (#2) configuration is straightforward as installer should detect it automatically.
Under “LVM” there are listed all existing LVs. In our example there is only one and we want it to be /home. What we need to do is to select it and setup as a normal partition. Extremely important is to not format it. Make sure the chosen option says “no, keep existing data”.
After that just select “Finish partitioning and write changes to disk” then confirm formatting of partitions #1 and #2. Continue normal installation and after reboot we have what we wanted: /dev/mapper/user_data-home device mounted to /home directory with all data already there.