Posts

Showing posts with the label Linux

Linux: Translate virtual to physical addresses in user space

Image
Each memory allocated in a process use a special address system called virtual address. This is a special address used inside the process space. However, sometime, could be necessary to know the real physical address in system memory for different purposes in user space. Here a short snippet showing how to do.

Access PCI device registry from Linux user space

Image
In case you need to modify registry of some PCI devices from Linux user space you can easily do by access to the /proc/bus/pci path where all PCI devices found on the system are listed.

Qt Tips and Tricks: Qt Creator for develop Android app using Gradle and proxy problem

Image
Qt Creator recently introduced a new way for develop android application. Basically is now possible to select use Gradle instead of apache-ant for final APK creation. Gradle is going to be the new "standard" than the choice of Qt team look perfectly reasonable. However if you are developing in a network under a proxy you could experiment some problem using Gradle.

Linux Snippet: include a static library inside another static library

Image
The linux static library format .a is basically only an archive of compiled object files. If you are developing a linux static library that use external functions coming from another static library you need to release both libraries (your library just developed and the second library you get functions from) for allow the final executable to compile correctly.

Linux tool: convert binary file to C/C++ source code array

Image
In case you are programming under Linux and have a binary file that want "import" inside your C/C++ code is there an useful linux utility tool called xxd able to make such conversion in a very easy way. This tool is usually installed by default in all major linux distributions.

Make Input/Output operations from Linux user space

Image
Input/Output operation are made with special x86 instructions. This mean this interface exist only in x86 systems and is not available in ARM platforms. The operation consist in send or receive data to/from special "registry" called port and is frequently used for a lot of common tasks.

Clear console screen in Windows and Linux

Image
In case of develop of a console mode application it could be quite frequently to clear all the console screen for prepare new output. Here some examples of codes for clear screen in both operating systems.

Set console cursor position in Windows and Linux

Image
In console mode the typical need for set cursor position would be to "update" data in the same fixed position creating a refresh effect. This requirement need to set the cursor in the same point every time and start print characters. Each new print will overwrite the old data and this will create the dynamic update effect.

Get console screen size in Windows and Linux

Image
Console application in both operating systems Windows and Linux measure the screen size using the number of columns and lines instead of use pixels. This because console mode allow only characters output inside the ASCII range and each character block have a fixed width and height size.

Disable terminal echo in Linux

Image
Very short code snippet to disable/enable the terminal echo in Linux. If, as example, in your tool you need user to insert a password and don't want show it in the typing terminal you simply can disable echo. Once echo disabled your tool will receive keyboard input but the letters will not be showed on the screen.

Detect arrow keys pressure under Linux

Image
Manage pressure of keyboard arrow keys under Linux is not a very easy task. This because, contrary to other keys having a specific unique code, the pressure of one of the arrow keys return not a single scancode but a sequence of three codes.

Check if any key is pressed in Linux

Image
In case you would to know if a key (any key) is pressed in Windows it exist a very useful function called _kbhit() . Linux doesn't have a similar function but is possible to easily reproduce using a few lines of code. Nothing new since this kind of code is possible to find in many places around, it's just to give my little contribution by providing a ready made function to simply copy and past in your code.

Access physical memory from Linux user space

Image
If you want to find a way for access physical memory in Linux there are only two solutions. The first is to develop a module running in kernel space with the correct privileges to access physical memory and the second is to use a special devices called " /dev/mem ". If your purpose is only to read or write some small parts of physical memory from user space this device is the right solution for you. Basically you can manage it as a file with additional use of some special functions required for get a pointer to the memory address your are interested to work in.

Install Oracle JDK 6 in Linux for Android compilation

Image
Latest distribution of Linux doesn't "officially" support the Oracle JDK 6 package anymore in their repositories. However product like Android still require this package for allow compilation. This mean we need to manually download and install it. The procedure is quite simple but need some steps to follow.

Install Yum Extender into CentOS 6

Image
Since Yum Extender is no more maintained in CentOS repository there are a lot of posts asking for this problem and, as usual, a lot of partial or incomplete replies. Just to avoid wasting time follow the few command lines to use for install this tool.

Access GPIO from Linux user space

Image
GPIO mean "General Purpose Input/Output" and is a special pin present in some chip that can be set as input or output and used to move a signal high or low (in output mode) or to get the signal current status (in input mode). Usually these pin are directly managed by kernel modules but there are an easy way to manage these pins also from user space.

Compile a Linux module consisting of multiple source files

Image
Certainly a lot of you know very well how to make this action but since I’m not very expert in makefile syntax I spend some time to figure out to to compile a Linux module consisting of multiple source files. Just to avoid the same waste of time to others who, like me, have no big experience in this sector I’ll post a short explanation about how to get this result.

Subversion commit and ignored files

Image
Just a quick note for provide a solution to a problem that, sometimes, can happen during a subversion commit operation. Subversion, frequently abbreviated as SVN, is a software versioning and revision control system distributed under an open source license. I will not explain here how to use subversion since if you know them you surely already know how to use it. On the contrary, if you don't know it probably you don't need them. Anyway if you make a commit operation of a large number of files containing also binary file like precompiled libraries and so on keep attention since is possible (especially under Linux) that some type of file are automatically included in a special list of ignored files. This mean these files ignored by subversion will not be added to the commit without give you any advise of that.

Get time in milliseconds on Windows and Linux

Image
Please note that in this case the time expressed in milliseconds is not a conversion of the system time but is a number of milliseconds elapsed by a specific time in the past different according to operating system used. This value is useful if you want to calculate a timeout based to millisecods unit.