Displaying a system’s DMI information

Linux has a very handy function, dmidecode, that can be used to display useful information about the hardware configuration of a system. The more general purpose command hardinfo displays some of the same information but not all.

Basic usage is:

sudo dmidecode

The output can be made more specific using one of the options described here. In my case, I wanted to know what the part number of the DRAM fitted to a system was while the system was running and without literally looking at the part. This command selects the memory information:

sudo dmidecode -t memory

Ignoring the annoying SIG32 signal when debugging SPDK apps in QtCreator

Well I don’t know if I am doing something wrong but, every time I close down an app using SPDK being debugged via QtCreator, SIG32 gets trapped and pauses execution rather than cleaning up and exiting. It’s easy to suppress the pop-up window but I couldn’t work out how to avoid trapping the signal entirely. Fortunately I found this post which has the solution.

Basically, you open up the Options window and select Debugger. Then select the GDB tab. Within that, there’s a window for Additional Startup Commands. Within that window, add the line:

handle SIG32 pass nostop noprint

Then press Apply and Ok. From now on, the app won’t get hung up if this signal is generated on exit.

Forcing a specific Linux kernel at boot time

Another problem I had with the irdma driver build mentioned in the previous post is that it would not build with the default kernel in my Ubuntu 20.04 install (5.11.0). However, I knew it would build using 5.4.0 which was present but not automatically selected. The trick is to get grub to default to the desired version. To do this, first list /boot/grub/grub.cfg and find the appropriate string for the desired version. In my case, this was:

Ubuntu, with Linux 5.4.0-42-generic

Then, edit /etc/default/grub and change the GRUB_DEFAULT line to this:

GRUB_DEFAULT="Advanced options for Ubuntu>Ubuntu, with Linux 5.4.0-42-generic"

Finally, run:

sudo update-grub

to activate the new default option and then reboot.

Solving a kernel module signing issue

I am currently working on getting an E810 100G ethernet NIC working and had a bit of trouble building the irdma driver due to a signing problem:

At main.c:160:
- SSL error:02001002:system library:fopen:No such file or directory: ../crypto/bio/bss_file.c:69
- SSL error:2006D080:BIO routines:BIO_new_file:no such file: ../crypto/bio/bss_file.c:76
sign-file: certs/signing_key.pem: No such file or directory

After some research, I came across the solution here, which seemed to work for me. Specifically the solution is (reproduced here just in case I can’t find the original again!):

cd /lib/modules/$(uname -r)/build/certs

sudo tee x509.genkey > /dev/null << 'EOF'
[ req ]
default_bits = 4096
distinguished_name = req_distinguished_name
prompt = no
string_mask = utf8only
x509_extensions = myexts
[ req_distinguished_name ]
CN = Modules
[ myexts ]
basicConstraints=critical,CA:FALSE
keyUsage=digitalSignature
subjectKeyIdentifier=hash
authorityKeyIdentifier=keyid
EOF

sudo openssl req -new -nodes -utf8 -sha512 -days 36500 -batch -x509 -config x509.genkey -outform DER -out signing_key.x509 -keyout signing_key.pem

Debugging DPDK and SPDK applications in QtCreator: the root issue

There doesn’t seem to be any easy way to get SPDK and DPDK to work without root permission (ok, there is a way but this technique works for these and other things). Not impossible to deal with when running code but it does present a problem when debugging with QtCreator (or any other IDE that directly calls the debugger). There is a trick that allows gdb to be run with root permission without requiring a password (largely as described here).

sudo visudo

and add this line at the bottom of the file:

<username> ALL=(root) NOPASSWD:/usr/bin/gdb

where <username> is the appropriate user name. Now all that’s needed is to call sudo gdb instead of gdb. This can be done by creating a simple executable script called sudo-gdb containing:

#!/bin/bash
sudo gdb $@

QtCreator then needs to know to use this version of the debugger. Go to Tools -> Options and select Kits. Select the Debugger tab and click on Add. Enter the full path to the new script. Then click on the Kits tab and select the new debugger in the Debugger drop-down and then click on Ok.

Yes, I should probably do it with the permissions trick and I will. One day.

Adding a password protected share to Ubuntu

This is one of those posts that helps me remember how to do something I knew how to do once but would inevitably forget how to do again one millisecond later. In this case it is how to configure a directory that is shared on the network but only to registered users.

First off, create a new group for the users (I will use the group name sharegroup as an example):

sudo addgroup sharegroup

Then add yourself to the group:

sudo usermod -aG sharegroup $USER

Add any other users to the group in the same way.

Now it is time to prepare the directory to be shared. Create (or choose) the directory and share it using the local network share option from the GUI. Alternatively, edit /etc/samba/smb.conf directly by adding something like this at the bottom:

[<sharename>]
  path = <full path to shared directory>
  writeable = yes
  guest ok = no
  read only = no
  browsable = yes
  create mask = 0770
  directory mask = 0770
  valid users = @sharegroup

and then restart samba:

sudo systemctl restart smbd

Then the directory group ownership must be set to the new group. Set the directory as current and enter:

sudo chgrp -R sharegroup *
sudo chgrp sharegroup .

Be very careful any time using the -R option with sudo as it is easy to completely mess up the OS! Generally it is best to start in the directory that’s being modified. That way, there’s less chance of making unintentional modifications.

Now change the permissions to allow group members to operate on files properly:

sudo chmod -R g+rw *
sudo chmod g+rw .

Then the users must be added to samba – for example:

sudo smbpasswd -a $USER

This will ask for a password to be used to access the share. That’s it!

Sending and receiving binary data using JSON encoding, Python and MQTT

I really like using JSON encoding as a way of transferring messages between processes as it is machine and language independent. Plus, it is very well suited to stream processing networks (such as rt-ai Edge) as arbitrary fields can be added to existing JSON messages and passed along. Contrast this with compiled IDLs which typically have no flexibility whatsoever.

One problem though is that binary data cannot be included in JSON messages directly. Typically base64 encoding is used to convert binary data into text. However, this is inefficient, especially in a stream processing network where base64 decoding and encoding might have to be done several times.

There are a variety of modifications to JSON around but it is very simple to just add binary data on to the end of a JSON message to form a complete message that can be transferred via MQTT for example.

In Python, an MQTT message can be published like this:

    import json
    import struct
    ...
    def publish(topic, jsonData, binData = None):
        jsonDump = json.dumps(jsonData)
        jsonString = struct.pack('>I', len(jsonDump)) + jsonDump + binData
        MQTTClient.publish(topic, jsonString)
        ...

Here, jsonData contains the normal JSON message text, binData contains the binary data to be sent along with it. To receive the message, use something like this:

    import json
    import struct
    ...
    def onMessage(client, userdata, message):
        jsonLength = struct.unpack('>I', message.payload[0:4])[0]
        jsonData = json.loads(message.payload[4:4+jsonLength])
        binData = message.payload[4+jsonLength:]
        ...

Configuring WiFi adaptors on Linux via the command line

EdimaxHardly an original post but there are so many variants around that, when I need to do this and have (as usual) forgotten how to do it, I can’t find anything that works! So here is my variant…

Add an entry for wlan0  to the /etc/network/interfaces file:

auto wlan0
iface wlan0 inet dhcp
wpa-conf /etc/wpa_supplicant.conf

Then, create /etc/wpa_supplicant.conf to use WPA encryption (this link  has examples of other modes):

ctrl_interface=/var/run/wpa_supplicant
ap_scan=1
fast_reauth=1
network={
         ssid="your_ssid"
         scan_ssid=1
         key_mgmt=WPA-PSK
         psk="your_passphrase"      
}

 That’s it for DHCP. To use a static IP address, change the /etc/network/interfaces entry (with the appropriate customizations) to be:

auto wlan0
iface wlan0 inet static
    address 192.168.2.3
    netmask 255.255.255.0
    gateway 192.168.2.1 
wpa-conf /etc/wpa_supplicant.conf