How to detect Endianess and Filesystem with Python3 - python-3.x

I'm theorizing of a project where my python script
looks at filesystem(s) on the machine running the script
but also reports back on the filesystem(s) of devices
that it mounts, thumb drives, mobile devices, etc.
Is anyone aware of the a BIF in python3 that would looks at endianness and filesystem.
Finally, I want to make a loop that looks at what storage devices are mounted, but I'm not sure how/whre to access that on OSX or Linux (fstab on linux?) and see what is currently mounted and if that changes. If Fstab was the correct file, would I constantly sort through it or should I just periodically open it and compare it against a file object?
I'm still very new at programming, so please pardon any newbie oversights.
Thanks

For the endianness of the platform:
>>> import sys
>>> print(sys.byteorder)
little

You can get quite a lot of information about the platform from the [platform][1] module. Endianess is from sys.byteorder though.
For lists of devices things become more platform-dependent though. There are various modules that give you USB access that can give you USB device lists, but nothing to list harddisk for example. Otherwise I don't know of anything platform-independent.

Related

how to get Linux kernel 3.18 rc4 main line to use oom_score_adj lib

Not sure if this is two question, but I wanted to start with both here in case they are related. I use a Linux PXE and grub for dos boot in various ways. I have used the same file system adding a few scripts here and there but mostly updating the kernel for new hardware. Starting with kernel 3.12.xxx and the latest 3.18 rc4 main line I am getting "oom_adj" deprecated and some wait_for_sysfs errors. My Linux skill level is somewhat basic out of ignorance mostly. I have goggled and learned a lot, so just because I use a term it does not mean I know what I am saying :-)
Background:
I started by remastering P.I.N.G from windowsdream. http://www.windowsdream.com/ping.html This is a cool ISO that will backup and restore hard drive images to a share. It's basically a big Pearl script that uses Linux commands to create shares, save partition, clear and make them back. So I started with that and made a intrd.gz file system. So I imagine a lot of my issues could be out of date lib's, my udev rules need to be updated, or my kernel make file (.config) is wrong. Also, sometimes, not always, my mouse USB will cycle though disconnects/re-connects. It seems to very from boot to boot. This boot may do it and the next boot will not. I will attache some screen shots and my .config file. BTW, P.I.N.G was based on Linux From Scratch (LFS).
Questions:
The open ended question is how to fix it?
Are the following questions related?
Is there setting in the .config to switch from oom_adj to oom_score_adj?
Is the /proc/2000 a lib issue?
Is the waiting_for_sysfs udev rules issues?
For the USB disconnecting/re-connecting, I read somewhere that Intel question something about some timing and some cheaper hardware may have pushed the spec a little. I can not find it any more. I did find something in the .config about using uHCI, but I saw somewhere about xHCI. I assume it has something to do with USB 2.0 vs USB 3.0, but I am not sure. Also, is this USB 1?
Any thoughts?
Looks like there are too many lines for the .config, I don't see how to attach it. If anyone wants to see it, let me know either how to post it or send it to them.

How can I get edge events via GPIO on Linux without a busy-loop?

I'm working an a system with embedded Linux (Kernel 2.6.31).
It is a AT91SAM9G20 chip inside, and some of the Pins are forwarded to the outside.
Now I want to use them as GPIO Inputs.
I read the gpio.txt documentation about using the GPIOs via filesystem, and that works very well 'til here. I connected some switches to the gpio-pins and I can see the result in /sys/class/gpio/gpioX/value. But now I'd like to react on a change without busy-waiting in a loop. (i.e echo "Switch1 was pressed").
I guess I need interrupts here, but I couldn't find out how to use them without writing my own kernel driver. I'm relatively new to Linux and C (I normally program in Java), so I'd like to handle the Interrupts via sysfs too. But my problem is, that there is no "edge"-file in my GPIO directory (I guess because this is only since Kernel version 2.6.33+). Is that right? Instead of "edge" I've got a uevent file in there, which is not described in gpio.txt.
In the gpio.txt documentation there was a Standard Kernel Driver mentioned: "gpio_keys". Is it possible to use this for my problem?
I guess it would be better to work with this driver than allowing a userspace program to manipulate kernel tasks.
I found a lot of codesnippets for writing my own driver, but I wasn't even able to find out which of the 600 gpio.h files to include, and how to refer to the library (cross compiler couldn't find the gpio.h file).
Sorry for newbie questions, I hope you could give me some advices.
Thanks in advance
See this for an example on how to do that. Basically, the thing you're missing is the usage of the select or poll system calls.

Linux - mounting a user space file system(mimicking one :-) ) as a FileSystem

I have a piece of C code which with a chunk of memory(static array) can mimic file operations (It has APIs similar to fopen/fclose etc). So, any code that is compiled with this mimicking FileSystem can use these APIs as a FileSystem for all their needs :)
But I was wondering, if its possible somehow to register these APIs with Linux system/mouning this File system, and hence enabling any client to use this FS by using normal FileSystem calls (without any need of statically linking it with the My_FileSystem).
While searching for a solution, I came across this idea of making my_FileSystem as a Driver!!! =>
Is it possible to compile my code as a device driver (with the memory chunk in the driver) and mount this File_system # say "/mnt/MyFs", and divert FileSystem calls like USB drivers do? (If this can be done, can you please explain how its done or point me to somewhere I can read about this).
I don't want to add these as new System calls and recompile the kernel (And making life of ppl wanting to use this difficult).
This is mainly for embedded systems running Linux... But other suggestions are also welcome. :)
Thank You,
MicroKernel :)
Look at FUSE (Filesystem in Userspace), especially on examples. Its quite easy...
Take a look at tmpfs and ramfs. These already ship with Linux and do all that you're trying to do and more. I don't think either of them would be too expensive for an embedded system.
I would consider PlasticFS, but that will work reliably only if everything uses system C library (i.e. no statically linked binaries).

Hardware recognition in user space Linux

I want to be able to inspect my Linux machine hardware in C.
How do I get the information that appear in dmesg in C ?
For example, for keyboard the message is input: AT Translated Set 2 keyboard as /devices/platform/i8042/serio0/input/input0
I want to get in my program the label, AT Translated Set 2, and the path, /devices/platform/i8042/serio0/input/input0.
Any idea how to do so ?
amit
You can also look at the contents of files in /proc.
/proc/version, /proc/ioports, /proc/iomem, /proc/meminfo, and others have a lot of information in them.
The files under /proc/bus have additional information about the system's hardware devices.
I'd also recommend looking at the source code for usbutils and pciutils for example code to get the output from the lsusb and lspci commands respectively.
It uses the klogctl call.
Best thing is to read the source code yourself, it can be downloaded here: util-linux
You would want to use libhal, and connect to the hal daemon. If HAL isn't there, look for a mounted sysfs partition. Check out /sys/devices, or work backwards through /sys/bus.
If neither HAL nor sysfs is available, reconsider your approach or restrict your scope.

ARM linux and cross toolchain issue

I have a problem probably with my arm toolchain but maybe there's something other that I do wrong. I have Chinese made dev board qq2440 using Samsung s3c2440 ARM9 uC. I'm using Ubuntu x86 with native gcc(4.3.3) and cross-compile version arm-unknown-linux-uclibc-gcc (crosstool-NG-1.3.2) 4.3.2
I followed tutorials from http://blog.leshak.ru/english/pages/how-to-install-u-boot-linux-2629-rootfsjffs2-busybox-1132-into-nand-qq2440/
and used Leshak's kernel patches for that board. Problem is that his binaries work perfectly and mine don't...
I communicate with my board over RS232 (serial port) and I have serial terminal configured on target Linux. I use Leshak's uboot image. To configure my kernel I use following command line:
qq2440> setenv bootargs 'noinitrd root=/dev/mtdblock2 rootfstype=jffs2 rw console=ttySAC0,115200'
For target I use vanilla Linux sources version 2.6.29, with patches created by Leshak. I don't honestly believe that this will ever be supported officially by Linux as it's not mainstream product.
My kernel image starts booting up, but it probably changes bandwidth (or CPU frequency) to some non standard value (tried all standard ones already). Instead of dots indicating loading kernel into memory I've got only trash instead. Unfortunately it doesn't probably finish the boot process as the network interface nor file system don't come up. So I figured out that it panics somewhere in the middle.
Any ideas what should I do next?
Thanks & regards,
Chris
There are a lot of different things that could be going on here.
It sounds like you are talking about a serial port, and that it appears to be giving garbage once control is passed to the kernel from uboot. Am I understanding that correctly?
Look into specifying the baud rate, parity, etc. for the serial console on the kernel commandline.
Oh, and IIRC, there was some 'early_printk' thing in the ARM Linux tree that might help you debug serial console problems. (But I'll warn you -- it's been a couple years since I dealt with that so my memory is fuzzy.)
Double-check that the memory address layout (the locations of all the various devices) matches what your board has. (I think this is probably not the issue, but wanted to mention it for completeness.)
You say that you have a binary kernel that works correctly; compare the kernel config of that kernel to the config you are using for building your kernel. Investigate every difference, particularly any specific to ARM.
You may want to double-check the endianness of your toolchain vs what your board is expecting. Some of the ARM / XScale processors can be configured to big-endian or little-endian in software, so it might be worth double-checking.
Just enable the debug build of the kernel[while building the uImage] so that you get a more clearer picture of the scenario [Just would make your boot up somewhat slow since all the printk's would be enabled].
Can you check whether you are passing the correct parameters to the UART ie. Serial Port Name, it's baud rate etc This would be provided by the board manufacturer-Samsung
WRT the network instead of DHCP can you just assign a static ip address to your system as it might be possible that the DHCP process is still not ON.
Also a better option would be to use NFS but yeah, it depends on your choice and the purpose of your application. To use NFS, your network should be UP & running and your filesystem should be shared.
As retracile has already pointed out "Endianness" could be a point to look into !!!
You can refer this link which might help you out since it is specific to S3C2440
Hope this helps.
-hjsblogger
I had a similar problem at one point when I omitted --send-cmd from picocom. this is the command I issue to picocom for serial uBoot comms with the mini2440.
picocom -b 115200 /dev/ttyS0 --send-cmd "sx -vv"

Resources