EMBEDDEDSTUFF.SE

Christians bitbucket space: Now in glorious technicolor

A small collection of a fraction of the stuff I have written through the years.

Most of it is not public. Some of it is. And a little bit of that some is published here.

Why no subversion/git etc?

Well. All of the stuff that I've added so far are so simple that it's just annoying to add them to a versioning system

Im not that intrerested in incremental development either. So.. I'll keep it at loose files for now.

 

httpz.c:

list.h:

libevent.patch:

A small libevent httpd implementation with static upload/download and list functions.

Uses threaded workers with sample work-path callbacks.

Open-ended chunked uploads are provided with the patch against libevent-2.1.8

Uses libevent. Build with: gcc -Wall -o httpz httpz.c -levent -levent_pthreads -lpthread

 

fdtdump.c:

Device tree binary unpacker. Dumps data in dtb files to console. Very simple.

Might be used to build functions to track specific data in dtb files in a bootloader or flashtool for example.

 

pktgun.tar.gz:

A packet gun with simple echo tcp and udp receivers. It was built for extremely simple code in embedded nodes.

The packet itself can be genrated with different parameters and operands to measure the network.

Powerful for simple built-in embedded node analysis.

 

8250_DRTS.patch:

Patch for Linux kernel to enable soft disabling of modem RTS signal when 8250 compatible FIFO and shift register is empty.

This can be used to use RS485 protocols on top of UARTS with timing requirements on fast bus shifts.

It is a busy wait, but there is really no other way of doing this without proper hardware support.

 

fullmtd.patch:

Patch for Linux kernels to enable a full MTD layer device reach.

Normally, you would have mtdX where X would denote the partition number.

If you wanted to flash a sequential image covering multiple partitions, you would have to split the image etc.

This way, the fullmtd partition has the full reach of the flash and you can write a complete image from address 0 to end.

 

libwdog.tar.gz:

Patch for Linux kernels to enable a userland hookable timer routine to kick the watchdog.

The processes calling the watchdog registry commits to kicking the watchdog at the specified interval,

thereby enabling a soft control of userland process activity via the watchdog.

This version only reloads the timer and kills the machine if it expires by using soft machine reset.

Use it to hook your own platform watchdog @ the kick_wdog function.

 

mxc_spi.c

spi_bitbang.c

Driver for Linux kernel to run the iMX25 SPI controller in bitbang mode instead of interrupts.

I rewrote the Freescale driver since it was broken. I used it to do jffs2 over SPI flash on an iMX25 based board.

The driver strips much of the original crap that was there in the driver. It's a shortcut driver just to get things working.

And they did, speed over this driver was really good.

 

modbus-serial-line-discipline.patch

Modbus line discipline driver for the Linux kernel. Make it possible to use modbus with short turnaround time on RS232/RS422/RS485 etc. Uses the 8250_DRTS.patch. Only the lowest layer of crc is implemented here. Includes a swapped crc check for dumb device implementers who don' t know what endian means.

 

ds2406_ds2438_ds2450s.patch

One-wire (w1) drivers for the various chips. ds2406 is a pio sense (light sensor typically), ds2438 has been added an IHI4000 humidity sensor, so that driver reports humidity and the ds2450s reports quad A/D input channels value.

 

lego.c:

lego.h:

Nostalgia. Probably some of the first C code I ever wrote. It's actually beyond ugly but I keep it around for sentimental purposes. :)

It implemets the LEGO Dacta Interface B in Linux. To my knowledge the only implementation in Linux. Maybe someone can rewrite it as a proper API using libevent or something? Should take an hour or two tops.

 

button_detect.c:

Ugly iopoll from userspace. Might be useful to someone.

 

macaddr_calc.c:

A little macaddr incrementer. Converts the mac-addr to an integer and increments it. This might be useful in embedded products with multiple ports that increment a base address. Since converting it to an integer, suffix rollovers are handled correctly.

 

cap.c:

tot_energy.patch:

list.h:

A little program I wrote to capture sound data from a usb-microphone (usb-camera) , encode it as mp3 using lame and send it as a raw tcp packet stream. Can be played with VLC or with netcat + Mplayer. Not all players can handle a raw tcp mp3 stream.

The program also extracts total energy on mp3 frames from lame using the patch and uses it to do sound detection (energy threshold filtering). This can be used for various stuff like burglar detection etc.

The program uses: list.h, alsa, lame and libevent2.

 

miictrl.c:

A small program using standard ioctls to reach Network Interface Cards MII registers.

Much like ethtool or miidiag but in a raw sense. Useful to encode or decode special data to MII registers not normally reachable by standard programs.

 

rawflash.c:

A little dumb program to write an MTD device from stdin using correct erase cycles etc for flash devices.

Ie. rawflash /dev/mtdX < image.

 

resetusb.c:

A little program to reset usb-ports. The program takes the kernel port path (1-1.2.1 for example, listed in dmesg) and uses it to find the parent hub of the current device. It then proceeds to query the hub for port power registers. If it is port power capable, it will cycle the port connected to the device. Otherwise, if it is ganged or not capable, it will issue an old fashioned device_reset, which will do a device detach and reconnect.

The program uses libusb > 1.0.15

 

eth2usb.c:

A little program to pass frames from ethernet to USB devices. It will attach a berkely packet filter to incoming data on UDP or just by mac address. The incoming data will be sent to all devices matching vid:pid presentation in the USB-layer. Observe that the sending of USB frames will need tweaking depending on the target device.

 

wtmptrunc.c:

Ugly program hack to truncate wtmp. It's more or less just a wtmp struct size counter.

 

smsconv.c:

Minor program that can build SMS PDU's to send with AT+CMGS command. Packs 8-bit ASCII into 7-bit packed GSM table for 160 chars / SMS. It can also extract phone numbers from SMS PDU's. That can be used as SMS function filter etc.

It's quite easy to build an SMS functionality around some 3G/4G dongle recieiving and sending SMS's with data.

 

enc.c:

Using OpenSSL crypto lib and the high level EVP functions, encrypt input with aes-256-cbc and a static key + static salt.

 

dec.c:

Using OpenSSL crypto lib and the high level EVP functions, decrypt input with aes-256-cbc and a static key + static salt.

 

openssh.patch:

Patches OpenSSH to enable ugly password on commandline option. This is a security risk since the password becomes visible in the programs argv. It is however practical on embedded stuff.

It also enables local file remove on transfer completion and percentage complete reporting via a socket interface.

 

memtester.patch:

Patch for RedBoot to test memory. Originally a Linux userspace memory tester program that allocated and locked memory to test.

Actually, to be able to test all memory, the memtest code itself should be relocateable so that you can test all memory.

Thats kind of hard under Linux, but in RedBoot it's easier. Well. It's still not relocateable but should be easy to fix.

It automatically tests memory from FREEMEMLO to FREEMEMHIGH declared by the bootloader. It should cover most cases.

It should also be trivial to port to U-boot or similar.

 

cof.tar.gz:

Computer On Fire. A collection ISO cd built using cdshell. It compiles various stuff needed to do lowlevel diagnostics. I haven't updated it in seven years or so.. But all the source is there. Maybe someone can use it for their purposes. Update should be a breeze.

Any user should probably read up on cdshell / isolinux / memdisk etc.

 

stride.c:

A memory backend strider. Strides memory with n2 stride sizes in n2 array sizes. From this data you can derive most memory backend stuff. L1, L2, L3 cache sizes, TLB's, latencies, cache line sizes etc etc.

Granted, you should know a bit about computer architecture to read the results, but it is still useful when measuring embedded systems memory backends when tuning memory controller parameters etc.

Compiles with -lrt.

 

dfree.c:

A little LD_PRELOAD free paranoia program. It hooks *mlock* and free functions. Once started it will register the heap pointer, lock all memory to ram so it can not be swapped out (password security etc). It will also hook the free function and start mtrace if someone wishes to use it. The free function hook will memset all freed segments by asking the malloc implementation for the pointer size.

When the program is terminated, the remaining heap is cleared and memory is unlocked.

Compile with: gcc -Wall -fno-builtin -nostartfiles --shared -fPIC -ldl -o dfree.so dfree.c

Load with: LD_PRELOAD=dfree.so ./myprogram

myprogram must have CAP_IPC_LOCK enabled as an POSIX xattr, or your program will likely crash and burn.

 

boot.c:

flash.c:

image_builder.c:

These files are part of a boot loader redundancy scheme. The redundacy is created around a header which is built by the image builder program in userspace. The flash tool, also in user space, will flash an image onto flash by selecting an broken or valid image with the lowest sequence number. This will create a test boot sequence from which the newly flashed image will have to be validated when booted.

the boot part is a precursor to be implemented in a bootloader etc.

Right now all tools should be buildable in userspace for a full simulation run.

 

"The Need For Speed":

My thesis, regarding the OpenRisc architecture done some 10 years ago.

In conclusion, one could say that the implementation quality of the OR1200 processor from the OR1k architecture was not that good.

I've also been following the community efforts the last ten years and the state, sadly, still seems to be the same.

Anyhow, might be an interesting read for some.

 

"What every programmer should know about memory":

This is an external link to one of the most useful educational papers I have ever read.

Although the majority of it was not new to me, it still is top of my recommendation list.

 

"Netfilter-Packet-Flow":

Not strictly a paper, but a link to a well updated PNG on Netfilter packet flow in the Linux kernel.

Highly informative. This would be one of those: "A picture says a thousand words."

 

 

Copyright © 2015 . All Rights Reserved: christian@embeddedstuff.se